Merge with trunk arithmetic
authorLubomir Nerad <lubomir.nerad@oracle.com>
Wed, 27 Feb 2013 11:24:58 +0100
brancharithmetic
changeset 77442bc1e89134d
parent 755 5652acd48509
parent 773 406faa8bc64f
child 778 6f8683517f1f
Merge with trunk
core/pom.xml
core/src/main/java/org/apidesign/bck2brwsr/core/ExtraJavaScript.java
core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptBody.java
core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptOnly.java
core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptPrototype.java
core/src/main/java/org/apidesign/bck2brwsr/core/impl/JavaScriptProcesor.java
emul/compact/pom.xml
emul/compact/src/main/assembly/rt.xml
emul/compact/src/main/java/java/beans/ChangeListenerMap.java
emul/compact/src/main/java/java/beans/IndexedPropertyChangeEvent.java
emul/compact/src/main/java/java/beans/PropertyChangeEvent.java
emul/compact/src/main/java/java/beans/PropertyChangeListener.java
emul/compact/src/main/java/java/beans/PropertyChangeListenerProxy.java
emul/compact/src/main/java/java/beans/PropertyChangeSupport.java
emul/compact/src/main/java/java/beans/PropertyVetoException.java
emul/compact/src/main/java/java/beans/VetoableChangeListener.java
emul/compact/src/main/java/java/beans/VetoableChangeListenerProxy.java
emul/compact/src/main/java/java/beans/VetoableChangeSupport.java
emul/compact/src/main/java/java/io/Bits.java
emul/compact/src/main/java/java/io/BufferedOutputStream.java
emul/compact/src/main/java/java/io/BufferedReader.java
emul/compact/src/main/java/java/io/ByteArrayOutputStream.java
emul/compact/src/main/java/java/io/DataOutput.java
emul/compact/src/main/java/java/io/DataOutputStream.java
emul/compact/src/main/java/java/io/Externalizable.java
emul/compact/src/main/java/java/io/FilterOutputStream.java
emul/compact/src/main/java/java/io/Flushable.java
emul/compact/src/main/java/java/io/InputStreamReader.java
emul/compact/src/main/java/java/io/InvalidClassException.java
emul/compact/src/main/java/java/io/InvalidObjectException.java
emul/compact/src/main/java/java/io/NotActiveException.java
emul/compact/src/main/java/java/io/NotSerializableException.java
emul/compact/src/main/java/java/io/ObjectInput.java
emul/compact/src/main/java/java/io/ObjectInputStream.java
emul/compact/src/main/java/java/io/ObjectInputValidation.java
emul/compact/src/main/java/java/io/ObjectOutput.java
emul/compact/src/main/java/java/io/ObjectOutputStream.java
emul/compact/src/main/java/java/io/ObjectStreamClass.java
emul/compact/src/main/java/java/io/ObjectStreamConstants.java
emul/compact/src/main/java/java/io/ObjectStreamException.java
emul/compact/src/main/java/java/io/ObjectStreamField.java
emul/compact/src/main/java/java/io/OptionalDataException.java
emul/compact/src/main/java/java/io/OutputStream.java
emul/compact/src/main/java/java/io/Reader.java
emul/compact/src/main/java/java/io/StreamCorruptedException.java
emul/compact/src/main/java/java/io/WriteAbortedException.java
emul/compact/src/main/java/java/lang/AbstractMethodError.java
emul/compact/src/main/java/java/lang/Cloneable.java
emul/compact/src/main/java/java/lang/IncompatibleClassChangeError.java
emul/compact/src/main/java/java/lang/InternalError.java
emul/compact/src/main/java/java/lang/Iterable.java
emul/compact/src/main/java/java/lang/NoSuchFieldError.java
emul/compact/src/main/java/java/lang/Readable.java
emul/compact/src/main/java/java/lang/SafeVarargs.java
emul/compact/src/main/java/java/lang/SuppressWarnings.java
emul/compact/src/main/java/java/lang/System.java
emul/compact/src/main/java/java/lang/ref/PhantomReference.java
emul/compact/src/main/java/java/lang/ref/Reference.java
emul/compact/src/main/java/java/lang/ref/ReferenceQueue.java
emul/compact/src/main/java/java/lang/ref/SoftReference.java
emul/compact/src/main/java/java/lang/ref/WeakReference.java
emul/compact/src/main/java/java/lang/ref/package.html
emul/compact/src/main/java/java/util/AbstractCollection.java
emul/compact/src/main/java/java/util/AbstractList.java
emul/compact/src/main/java/java/util/AbstractMap.java
emul/compact/src/main/java/java/util/AbstractQueue.java
emul/compact/src/main/java/java/util/AbstractSequentialList.java
emul/compact/src/main/java/java/util/AbstractSet.java
emul/compact/src/main/java/java/util/ArrayDeque.java
emul/compact/src/main/java/java/util/ArrayList.java
emul/compact/src/main/java/java/util/Arrays.java
emul/compact/src/main/java/java/util/Collection.java
emul/compact/src/main/java/java/util/Collections.java
emul/compact/src/main/java/java/util/ComparableTimSort.java
emul/compact/src/main/java/java/util/ConcurrentModificationException.java
emul/compact/src/main/java/java/util/Deque.java
emul/compact/src/main/java/java/util/Dictionary.java
emul/compact/src/main/java/java/util/DualPivotQuicksort.java
emul/compact/src/main/java/java/util/EmptyStackException.java
emul/compact/src/main/java/java/util/EventListener.java
emul/compact/src/main/java/java/util/EventListenerProxy.java
emul/compact/src/main/java/java/util/EventObject.java
emul/compact/src/main/java/java/util/HashMap.java
emul/compact/src/main/java/java/util/HashSet.java
emul/compact/src/main/java/java/util/Hashtable.java
emul/compact/src/main/java/java/util/Iterator.java
emul/compact/src/main/java/java/util/LinkedHashMap.java
emul/compact/src/main/java/java/util/LinkedList.java
emul/compact/src/main/java/java/util/List.java
emul/compact/src/main/java/java/util/ListIterator.java
emul/compact/src/main/java/java/util/Map.java
emul/compact/src/main/java/java/util/Objects.java
emul/compact/src/main/java/java/util/PriorityQueue.java
emul/compact/src/main/java/java/util/Queue.java
emul/compact/src/main/java/java/util/Random.java
emul/compact/src/main/java/java/util/RandomAccess.java
emul/compact/src/main/java/java/util/ServiceConfigurationError.java
emul/compact/src/main/java/java/util/ServiceLoader.java
emul/compact/src/main/java/java/util/Set.java
emul/compact/src/main/java/java/util/SortedMap.java
emul/compact/src/main/java/java/util/SortedSet.java
emul/compact/src/main/java/java/util/Stack.java
emul/compact/src/main/java/java/util/StringTokenizer.java
emul/compact/src/main/java/java/util/TimSort.java
emul/compact/src/main/java/java/util/Vector.java
emul/compact/src/main/java/java/util/concurrent/Callable.java
emul/compact/src/main/java/java/util/concurrent/TimeUnit.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/RandomTest.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ServiceLoaderTest.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipArchive.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java
emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipVsJzLibTest.java
emul/compact/src/test/resources/org/apidesign/bck2brwsr/compact/tck/demo.static.calculator-0.3-SNAPSHOT.jar
emul/mini/pom.xml
emul/mini/src/main/java/java/io/ByteArrayInputStream.java
emul/mini/src/main/java/java/io/Closeable.java
emul/mini/src/main/java/java/io/DataInput.java
emul/mini/src/main/java/java/io/DataInputStream.java
emul/mini/src/main/java/java/io/EOFException.java
emul/mini/src/main/java/java/io/FilterInputStream.java
emul/mini/src/main/java/java/io/IOException.java
emul/mini/src/main/java/java/io/InputStream.java
emul/mini/src/main/java/java/io/PushbackInputStream.java
emul/mini/src/main/java/java/io/Serializable.java
emul/mini/src/main/java/java/io/UTFDataFormatException.java
emul/mini/src/main/java/java/io/UnsupportedEncodingException.java
emul/mini/src/main/java/java/lang/AbstractStringBuilder.java
emul/mini/src/main/java/java/lang/Appendable.java
emul/mini/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
emul/mini/src/main/java/java/lang/ArrayStoreException.java
emul/mini/src/main/java/java/lang/AssertionError.java
emul/mini/src/main/java/java/lang/AutoCloseable.java
emul/mini/src/main/java/java/lang/Boolean.java
emul/mini/src/main/java/java/lang/Byte.java
emul/mini/src/main/java/java/lang/CharSequence.java
emul/mini/src/main/java/java/lang/Character.java
emul/mini/src/main/java/java/lang/Class.java
emul/mini/src/main/java/java/lang/ClassCastException.java
emul/mini/src/main/java/java/lang/ClassFormatError.java
emul/mini/src/main/java/java/lang/ClassLoader.java
emul/mini/src/main/java/java/lang/ClassNotFoundException.java
emul/mini/src/main/java/java/lang/CloneNotSupportedException.java
emul/mini/src/main/java/java/lang/Cloneable.java
emul/mini/src/main/java/java/lang/Comparable.java
emul/mini/src/main/java/java/lang/Deprecated.java
emul/mini/src/main/java/java/lang/Double.java
emul/mini/src/main/java/java/lang/Enum.java
emul/mini/src/main/java/java/lang/Error.java
emul/mini/src/main/java/java/lang/Exception.java
emul/mini/src/main/java/java/lang/Float.java
emul/mini/src/main/java/java/lang/IllegalAccessError.java
emul/mini/src/main/java/java/lang/IllegalAccessException.java
emul/mini/src/main/java/java/lang/IllegalArgumentException.java
emul/mini/src/main/java/java/lang/IllegalStateException.java
emul/mini/src/main/java/java/lang/IncompatibleClassChangeError.java
emul/mini/src/main/java/java/lang/IndexOutOfBoundsException.java
emul/mini/src/main/java/java/lang/InstantiationException.java
emul/mini/src/main/java/java/lang/Integer.java
emul/mini/src/main/java/java/lang/InterruptedException.java
emul/mini/src/main/java/java/lang/LinkageError.java
emul/mini/src/main/java/java/lang/Long.java
emul/mini/src/main/java/java/lang/Math.java
emul/mini/src/main/java/java/lang/NegativeArraySizeException.java
emul/mini/src/main/java/java/lang/NoSuchMethodException.java
emul/mini/src/main/java/java/lang/NullPointerException.java
emul/mini/src/main/java/java/lang/Number.java
emul/mini/src/main/java/java/lang/NumberFormatException.java
emul/mini/src/main/java/java/lang/Object.java
emul/mini/src/main/java/java/lang/OutOfMemoryError.java
emul/mini/src/main/java/java/lang/Override.java
emul/mini/src/main/java/java/lang/ReflectiveOperationException.java
emul/mini/src/main/java/java/lang/Runnable.java
emul/mini/src/main/java/java/lang/RuntimeException.java
emul/mini/src/main/java/java/lang/SecurityException.java
emul/mini/src/main/java/java/lang/Short.java
emul/mini/src/main/java/java/lang/StackTraceElement.java
emul/mini/src/main/java/java/lang/String.java
emul/mini/src/main/java/java/lang/StringBuffer.java
emul/mini/src/main/java/java/lang/StringBuilder.java
emul/mini/src/main/java/java/lang/StringIndexOutOfBoundsException.java
emul/mini/src/main/java/java/lang/Throwable.java
emul/mini/src/main/java/java/lang/VirtualMachineError.java
emul/mini/src/main/java/java/lang/Void.java
emul/mini/src/main/java/java/lang/annotation/Annotation.java
emul/mini/src/main/java/java/lang/annotation/Documented.java
emul/mini/src/main/java/java/lang/annotation/ElementType.java
emul/mini/src/main/java/java/lang/annotation/Retention.java
emul/mini/src/main/java/java/lang/annotation/RetentionPolicy.java
emul/mini/src/main/java/java/lang/annotation/Target.java
emul/mini/src/main/java/java/lang/annotation/UnsupportedOperationException.java
emul/mini/src/main/java/java/lang/reflect/AccessibleObject.java
emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java
emul/mini/src/main/java/java/lang/reflect/Array.java
emul/mini/src/main/java/java/lang/reflect/Constructor.java
emul/mini/src/main/java/java/lang/reflect/Field.java
emul/mini/src/main/java/java/lang/reflect/GenericDeclaration.java
emul/mini/src/main/java/java/lang/reflect/InvocationHandler.java
emul/mini/src/main/java/java/lang/reflect/InvocationTargetException.java
emul/mini/src/main/java/java/lang/reflect/Member.java
emul/mini/src/main/java/java/lang/reflect/Method.java
emul/mini/src/main/java/java/lang/reflect/Modifier.java
emul/mini/src/main/java/java/lang/reflect/Proxy.java
emul/mini/src/main/java/java/lang/reflect/Type.java
emul/mini/src/main/java/java/lang/reflect/TypeVariable.java
emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java
emul/mini/src/main/java/java/lang/reflect/package-info.java
emul/mini/src/main/java/java/net/MalformedURLException.java
emul/mini/src/main/java/java/net/URL.java
emul/mini/src/main/java/java/net/URLStreamHandler.java
emul/mini/src/main/java/java/util/Comparator.java
emul/mini/src/main/java/java/util/Enumeration.java
emul/mini/src/main/java/java/util/NoSuchElementException.java
emul/mini/src/main/java/java/util/zip/Adler32.java
emul/mini/src/main/java/java/util/zip/CRC32.java
emul/mini/src/main/java/java/util/zip/Checksum.java
emul/mini/src/main/java/java/util/zip/DataFormatException.java
emul/mini/src/main/java/java/util/zip/Inflater.java
emul/mini/src/main/java/java/util/zip/InflaterInputStream.java
emul/mini/src/main/java/java/util/zip/ZStreamRef.java
emul/mini/src/main/java/java/util/zip/ZipConstants.java
emul/mini/src/main/java/java/util/zip/ZipEntry.java
emul/mini/src/main/java/java/util/zip/ZipException.java
emul/mini/src/main/java/java/util/zip/ZipInputStream.java
emul/mini/src/main/java/java/util/zip/package.html
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/ManifestInputStream.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/AnnotationImpl.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/MethodImpl.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/TypeProvider.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflate.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java
emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java
emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js
emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js
emul/mini/src/test/java/org/apidesign/bck2brwsr/emul/reflect/MethodImplTest.java
emul/pom.xml
javap/pom.xml
javap/src/main/java/org/apidesign/javap/AnnotationParser.java
javap/src/main/java/org/apidesign/javap/AttrData.java
javap/src/main/java/org/apidesign/javap/CPX.java
javap/src/main/java/org/apidesign/javap/CPX2.java
javap/src/main/java/org/apidesign/javap/ClassData.java
javap/src/main/java/org/apidesign/javap/Constants.java
javap/src/main/java/org/apidesign/javap/FieldData.java
javap/src/main/java/org/apidesign/javap/Hashtable.java
javap/src/main/java/org/apidesign/javap/InnerClassData.java
javap/src/main/java/org/apidesign/javap/LineNumData.java
javap/src/main/java/org/apidesign/javap/LocVarData.java
javap/src/main/java/org/apidesign/javap/MethodData.java
javap/src/main/java/org/apidesign/javap/RuntimeConstants.java
javap/src/main/java/org/apidesign/javap/StackMapData.java
javap/src/main/java/org/apidesign/javap/StackMapIterator.java
javap/src/main/java/org/apidesign/javap/StackMapTableData.java
javap/src/main/java/org/apidesign/javap/TrapData.java
javap/src/main/java/org/apidesign/javap/TrapDataIterator.java
javap/src/main/java/org/apidesign/javap/TypeArray.java
javap/src/main/java/org/apidesign/javap/Vector.java
launcher/pom.xml
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java
launcher/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java
launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml
mojo/pom.xml
mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java
mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java
mojo/src/main/resources/META-INF/maven/archetype-metadata.xml
mojo/src/main/resources/archetype-resources/bck2brwsr-assembly.xml
mojo/src/main/resources/archetype-resources/nbactions.xml
mojo/src/main/resources/archetype-resources/pom.xml
mojo/src/main/resources/archetype-resources/src/main/java/App.java
mojo/src/main/resources/archetype-resources/src/main/resources/index.html
mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java
mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java
mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java
vm/pom.xml
vm/src/main/assembly/bck2brwsr.xml
vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java
vm/src/main/java/org/apidesign/vm4brwsr/Main.java
vm/src/main/java/org/apidesign/vm4brwsr/ParseMan.java
vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java
vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java
vm/src/main/java/org/apidesign/vm4brwsr/VM.java
vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java
vm/src/main/java/org/apidesign/vm4brwsr/VarType.java
vm/src/main/java/org/apidesign/vm4brwsr/Variable.java
vm/src/main/java/org/apidesign/vm4brwsr/Zips.java
vm/src/test/java/org/apidesign/vm4brwsr/Array.java
vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java
vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java
vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java
vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java
vm/src/test/java/org/apidesign/vm4brwsr/Classes.java
vm/src/test/java/org/apidesign/vm4brwsr/ClassesMarker.java
vm/src/test/java/org/apidesign/vm4brwsr/ClassesNamer.java
vm/src/test/java/org/apidesign/vm4brwsr/Exceptions.java
vm/src/test/java/org/apidesign/vm4brwsr/ExceptionsTest.java
vm/src/test/java/org/apidesign/vm4brwsr/GetByte.java
vm/src/test/java/org/apidesign/vm4brwsr/Instance.java
vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java
vm/src/test/java/org/apidesign/vm4brwsr/InstanceSubTest.java
vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java
vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java
vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java
vm/src/test/java/org/apidesign/vm4brwsr/Script.java
vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java
vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java
vm/src/test/java/org/apidesign/vm4brwsr/StaticUse.java
vm/src/test/java/org/apidesign/vm4brwsr/StringArrayTest.java
vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java
vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java
vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java
vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java
vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java
vm/src/test/java/org/apidesign/vm4brwsr/VMinVM.java
vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java
vm/src/test/resources/org/apidesign/vm4brwsr/ko.js
vmtest/pom.xml
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Http.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/GenerateZip.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/GenerateZipProcessor.java
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/AssertionTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ByteArithmeticTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CloneTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareByteArrayTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareHashTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceA.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceB.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java
vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/CRC32Test.java
vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipEntryTest.java
vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java
vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/0xfe
vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/Resources.txt
     1.1 --- a/core/pom.xml	Mon Feb 25 19:00:08 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,46 +0,0 @@
     1.4 -<?xml version="1.0"?>
     1.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"
     1.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     1.7 -  <modelVersion>4.0.0</modelVersion>
     1.8 -  <parent>
     1.9 -    <groupId>org.apidesign</groupId>
    1.10 -    <artifactId>bck2brwsr</artifactId>
    1.11 -    <version>0.3-SNAPSHOT</version>
    1.12 -  </parent>
    1.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
    1.14 -  <artifactId>core</artifactId>
    1.15 -  <version>0.3-SNAPSHOT</version>
    1.16 -  <name>Core JS Annotations</name>
    1.17 -  <url>http://maven.apache.org</url>
    1.18 -    <build>
    1.19 -        <plugins>
    1.20 -            <plugin>
    1.21 -                <groupId>org.apache.maven.plugins</groupId>
    1.22 -                <artifactId>maven-compiler-plugin</artifactId>
    1.23 -                <version>2.3.2</version>
    1.24 -                <configuration>
    1.25 -                    <source>1.7</source>
    1.26 -                    <target>1.7</target>
    1.27 -                </configuration>
    1.28 -            </plugin>
    1.29 -        </plugins>
    1.30 -    </build>
    1.31 -    <properties>
    1.32 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    1.33 -  </properties>
    1.34 -  <dependencies>
    1.35 -    <dependency>
    1.36 -      <groupId>junit</groupId>
    1.37 -      <artifactId>junit</artifactId>
    1.38 -      <version>3.8.1</version>
    1.39 -      <scope>test</scope>
    1.40 -    </dependency>
    1.41 -    <dependency>
    1.42 -      <groupId>org.netbeans.api</groupId>
    1.43 -      <artifactId>org-openide-util-lookup</artifactId>
    1.44 -      <scope>provided</scope>
    1.45 -    </dependency>
    1.46 -  </dependencies>
    1.47 -    <description>Contains esential annotations for associating JavaScript code with
    1.48 -methods and classes.</description>
    1.49 -</project>
     2.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/ExtraJavaScript.java	Mon Feb 25 19:00:08 2013 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,36 +0,0 @@
     2.4 -/**
     2.5 - * Back 2 Browser Bytecode Translator
     2.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.7 - *
     2.8 - * This program is free software: you can redistribute it and/or modify
     2.9 - * it under the terms of the GNU General Public License as published by
    2.10 - * the Free Software Foundation, version 2 of the License.
    2.11 - *
    2.12 - * This program is distributed in the hope that it will be useful,
    2.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 - * GNU General Public License for more details.
    2.16 - *
    2.17 - * You should have received a copy of the GNU General Public License
    2.18 - * along with this program. Look for COPYING file in the top folder.
    2.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    2.20 - */
    2.21 -package org.apidesign.bck2brwsr.core;
    2.22 -
    2.23 -import java.lang.annotation.ElementType;
    2.24 -import java.lang.annotation.Retention;
    2.25 -import java.lang.annotation.RetentionPolicy;
    2.26 -import java.lang.annotation.Target;
    2.27 -
    2.28 -/**
    2.29 - *
    2.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.31 - */
    2.32 -@Retention(RetentionPolicy.CLASS)
    2.33 -@Target(ElementType.TYPE)
    2.34 -public @interface ExtraJavaScript {
    2.35 -    /** location of a script to load */
    2.36 -    String resource();
    2.37 -    /** should the class file still be processed or not? */
    2.38 -    boolean processByteCode() default true;
    2.39 -}
     3.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptBody.java	Mon Feb 25 19:00:08 2013 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,51 +0,0 @@
     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.bck2brwsr.core;
    3.22 -
    3.23 -import java.lang.annotation.ElementType;
    3.24 -import java.lang.annotation.Retention;
    3.25 -import java.lang.annotation.RetentionPolicy;
    3.26 -import java.lang.annotation.Target;
    3.27 -
    3.28 -/** Put this method on a method in case it should have a special
    3.29 - * body in the <em>JavaScript</em>.
    3.30 - *
    3.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    3.32 - */
    3.33 -@Retention(RetentionPolicy.CLASS)
    3.34 -@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
    3.35 -public @interface JavaScriptBody {
    3.36 -    /** Names of parameters for the method. 
    3.37 -     * 
    3.38 -     * <!--
    3.39 -     * If not specified
    3.40 -     * it will be <code>arg0, arg1, arg2</code>. In case of
    3.41 -     * instance methods, the <code>arg0</code> is reference
    3.42 -     * to <code>this</code>.
    3.43 -     * -->
    3.44 -     * 
    3.45 -     * @return array of the names of parameters for the method
    3.46 -     *    in JavaScript
    3.47 -     */
    3.48 -    public String[] args();
    3.49 -    
    3.50 -    /** The actual body of the method in JavaScript. This string will be
    3.51 -     * put into generated header (ends with '{') and footer (ends with '}').
    3.52 -     */
    3.53 -    public String body();
    3.54 -}
     4.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptOnly.java	Mon Feb 25 19:00:08 2013 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,37 +0,0 @@
     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.bck2brwsr.core;
    4.22 -
    4.23 -import java.lang.annotation.ElementType;
    4.24 -import java.lang.annotation.Retention;
    4.25 -import java.lang.annotation.RetentionPolicy;
    4.26 -import java.lang.annotation.Target;
    4.27 -
    4.28 -/** Don't include given field or method in generated JavaScript. Rather
    4.29 - * generate completely independent JavaScript code.
    4.30 - *
    4.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    4.32 - */
    4.33 -@Retention(RetentionPolicy.CLASS)
    4.34 -@Target({ ElementType.METHOD, ElementType.FIELD })
    4.35 -public @interface JavaScriptOnly {
    4.36 -    /** name of the variable to assign given value to */
    4.37 -    String name() default "";
    4.38 -    /** value to assign to given field */
    4.39 -    String value() default "";
    4.40 -}
     5.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptPrototype.java	Mon Feb 25 19:00:08 2013 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,44 +0,0 @@
     5.4 -/**
     5.5 - * Back 2 Browser Bytecode Translator
     5.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.7 - *
     5.8 - * This program is free software: you can redistribute it and/or modify
     5.9 - * it under the terms of the GNU General Public License as published by
    5.10 - * the Free Software Foundation, version 2 of the License.
    5.11 - *
    5.12 - * This program is distributed in the hope that it will be useful,
    5.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 - * GNU General Public License for more details.
    5.16 - *
    5.17 - * You should have received a copy of the GNU General Public License
    5.18 - * along with this program. Look for COPYING file in the top folder.
    5.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    5.20 - */
    5.21 -package org.apidesign.bck2brwsr.core;
    5.22 -
    5.23 -import java.lang.annotation.ElementType;
    5.24 -import java.lang.annotation.Retention;
    5.25 -import java.lang.annotation.RetentionPolicy;
    5.26 -import java.lang.annotation.Target;
    5.27 -
    5.28 -/** Controls how JavaScript inheritance should be handled.
    5.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    5.30 - */
    5.31 -@Retention(RetentionPolicy.CLASS)
    5.32 -@Target({ ElementType.TYPE })
    5.33 -public @interface JavaScriptPrototype {
    5.34 -    /** Expression that identifies the function where all methods
    5.35 -     * should be added into. If this attribute is unspecified
    5.36 -     * all methods are added to the same object specified by
    5.37 -     * {@link #prototype()}.
    5.38 -     * 
    5.39 -     * @return name of function to contain methods found in given class
    5.40 -     */
    5.41 -    String container() default "";
    5.42 -    /** Expression that defines the way to construct prototype for this
    5.43 -     * class.
    5.44 -     * @return expression to construct prototype
    5.45 -     */
    5.46 -    String prototype();
    5.47 -}
     6.1 --- a/core/src/main/java/org/apidesign/bck2brwsr/core/impl/JavaScriptProcesor.java	Mon Feb 25 19:00:08 2013 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,94 +0,0 @@
     6.4 -/**
     6.5 - * Back 2 Browser Bytecode Translator
     6.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 - *
     6.8 - * This program is free software: you can redistribute it and/or modify
     6.9 - * it under the terms of the GNU General Public License as published by
    6.10 - * the Free Software Foundation, version 2 of the License.
    6.11 - *
    6.12 - * This program is distributed in the hope that it will be useful,
    6.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 - * GNU General Public License for more details.
    6.16 - *
    6.17 - * You should have received a copy of the GNU General Public License
    6.18 - * along with this program. Look for COPYING file in the top folder.
    6.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    6.20 - */
    6.21 -package org.apidesign.bck2brwsr.core.impl;
    6.22 -
    6.23 -import java.util.Collections;
    6.24 -import java.util.HashSet;
    6.25 -import java.util.List;
    6.26 -import java.util.Set;
    6.27 -import javax.annotation.processing.AbstractProcessor;
    6.28 -import javax.annotation.processing.Completion;
    6.29 -import javax.annotation.processing.Completions;
    6.30 -import javax.annotation.processing.Processor;
    6.31 -import javax.annotation.processing.RoundEnvironment;
    6.32 -import javax.lang.model.element.AnnotationMirror;
    6.33 -import javax.lang.model.element.Element;
    6.34 -import javax.lang.model.element.ElementKind;
    6.35 -import javax.lang.model.element.ExecutableElement;
    6.36 -import javax.lang.model.element.TypeElement;
    6.37 -import javax.lang.model.element.VariableElement;
    6.38 -import javax.tools.Diagnostic;
    6.39 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
    6.40 -import org.openide.util.lookup.ServiceProvider;
    6.41 -
    6.42 -/**
    6.43 - *
    6.44 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    6.45 - */
    6.46 -@ServiceProvider(service = Processor.class)
    6.47 -public final class JavaScriptProcesor extends AbstractProcessor {
    6.48 -    @Override
    6.49 -    public Set<String> getSupportedAnnotationTypes() {
    6.50 -        Set<String> set = new HashSet<>();
    6.51 -        set.add(JavaScriptBody.class.getName());
    6.52 -        return set;
    6.53 -    }
    6.54 -    
    6.55 -    @Override
    6.56 -    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    6.57 -        for (Element e : roundEnv.getElementsAnnotatedWith(JavaScriptBody.class)) {
    6.58 -            if (e.getKind() != ElementKind.METHOD && e.getKind() != ElementKind.CONSTRUCTOR) {
    6.59 -                continue;
    6.60 -            }
    6.61 -            ExecutableElement ee = (ExecutableElement)e;
    6.62 -            List<? extends VariableElement> params = ee.getParameters();
    6.63 -            
    6.64 -            JavaScriptBody jsb = e.getAnnotation(JavaScriptBody.class);
    6.65 -            if (jsb == null) {
    6.66 -                continue;
    6.67 -            }
    6.68 -            String[] arr = jsb.args();
    6.69 -            if (params.size() != arr.length) {
    6.70 -                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Number of args arguments does not match real arguments!", e);
    6.71 -            }
    6.72 -        }
    6.73 -        return true;
    6.74 -    }
    6.75 -
    6.76 -    @Override
    6.77 -    public Iterable<? extends Completion> getCompletions(Element e, 
    6.78 -        AnnotationMirror annotation, ExecutableElement member, String userText
    6.79 -    ) {
    6.80 -        StringBuilder sb = new StringBuilder();
    6.81 -        if (e.getKind() == ElementKind.METHOD && member.getSimpleName().contentEquals("args")) {
    6.82 -            ExecutableElement ee = (ExecutableElement) e;
    6.83 -            String sep = "";
    6.84 -            sb.append("{ ");
    6.85 -            for (VariableElement ve : ee.getParameters()) {
    6.86 -                sb.append(sep).append('"').append(ve.getSimpleName())
    6.87 -                    .append('"');
    6.88 -                sep = ", ";
    6.89 -            }
    6.90 -            sb.append(" }");
    6.91 -            return Collections.nCopies(1, Completions.of(sb.toString()));
    6.92 -        }
    6.93 -        return null;
    6.94 -    }
    6.95 -
    6.96 -    
    6.97 -}
     7.1 --- a/emul/compact/pom.xml	Mon Feb 25 19:00:08 2013 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,72 +0,0 @@
     7.4 -<?xml version="1.0"?>
     7.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"
     7.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     7.7 -  <modelVersion>4.0.0</modelVersion>
     7.8 -  <parent>
     7.9 -    <groupId>org.apidesign.bck2brwsr</groupId>
    7.10 -    <artifactId>emul.pom</artifactId>
    7.11 -    <version>0.3-SNAPSHOT</version>
    7.12 -  </parent>
    7.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
    7.14 -  <artifactId>emul</artifactId>
    7.15 -  <version>0.3-SNAPSHOT</version>
    7.16 -  <name>Bck2Brwsr API Profile</name>
    7.17 -  <url>http://maven.apache.org</url>
    7.18 -  <properties>
    7.19 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    7.20 -  </properties>
    7.21 -  <dependencies>
    7.22 -    <dependency>
    7.23 -      <groupId>${project.groupId}</groupId>
    7.24 -      <artifactId>emul.mini</artifactId>
    7.25 -      <version>${project.version}</version>
    7.26 -      <scope>provided</scope>
    7.27 -    </dependency>
    7.28 -    <dependency>
    7.29 -      <groupId>${project.groupId}</groupId>
    7.30 -      <artifactId>vmtest</artifactId>
    7.31 -      <version>${project.version}</version>
    7.32 -      <scope>test</scope>
    7.33 -    </dependency>
    7.34 -    <dependency>
    7.35 -      <groupId>org.netbeans.api</groupId>
    7.36 -      <artifactId>org-openide-util-lookup</artifactId>
    7.37 -      <scope>test</scope>
    7.38 -    </dependency>
    7.39 -  </dependencies>
    7.40 -  <build>
    7.41 -      <plugins>
    7.42 -          <plugin>
    7.43 -              <groupId>org.apache.maven.plugins</groupId>
    7.44 -              <artifactId>maven-compiler-plugin</artifactId>
    7.45 -              <version>2.5.1</version>
    7.46 -              <configuration>
    7.47 -                  <compilerArguments>
    7.48 -                      <bootclasspath>netbeans.ignore.jdk.bootclasspath</bootclasspath>
    7.49 -                  </compilerArguments>
    7.50 -                 <source>1.7</source>
    7.51 -                 <target>1.7</target>
    7.52 -              </configuration>
    7.53 -          </plugin>
    7.54 -         <plugin>
    7.55 -            <artifactId>maven-assembly-plugin</artifactId>
    7.56 -                <version>2.4</version>
    7.57 -                <executions>
    7.58 -                    <execution>
    7.59 -                        <id>rt</id>
    7.60 -                        <phase>package</phase>
    7.61 -                        <goals>
    7.62 -                            <goal>single</goal>
    7.63 -                        </goals>
    7.64 -                        <configuration>
    7.65 -                            <descriptors>
    7.66 -                                <descriptor>src/main/assembly/rt.xml</descriptor>
    7.67 -                            </descriptors>
    7.68 -                            <finalName>bck2brwsr-${project.version}</finalName>
    7.69 -                        </configuration>
    7.70 -                    </execution>
    7.71 -                </executions>                
    7.72 -            </plugin>      
    7.73 -      </plugins>
    7.74 -  </build>
    7.75 -</project>
     8.1 --- a/emul/compact/src/main/assembly/rt.xml	Mon Feb 25 19:00:08 2013 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,26 +0,0 @@
     8.4 -<?xml version="1.0"?>
     8.5 -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
     8.6 -  <id>rt</id>
     8.7 -  <formats>
     8.8 -    <format>jar</format>
     8.9 -  </formats>
    8.10 -  <includeBaseDirectory>false</includeBaseDirectory>
    8.11 -  <dependencySets>
    8.12 -    <dependencySet>
    8.13 -      <useProjectArtifact>true</useProjectArtifact>
    8.14 -      <unpack>true</unpack>
    8.15 -      <scope>provided</scope>
    8.16 -      <unpackOptions>
    8.17 -        <excludes>
    8.18 -          <exclude>META-INF/maven/**</exclude>
    8.19 -        </excludes>
    8.20 -      </unpackOptions>
    8.21 -    </dependencySet>
    8.22 -  </dependencySets>
    8.23 -  <fileSets>
    8.24 -    <fileSet>
    8.25 -      <directory>${project.build.outputDirectory}</directory>
    8.26 -      <outputDirectory>/</outputDirectory>
    8.27 -    </fileSet>
    8.28 -  </fileSets>
    8.29 -</assembly>
    8.30 \ No newline at end of file
     9.1 --- a/emul/compact/src/main/java/java/beans/ChangeListenerMap.java	Mon Feb 25 19:00:08 2013 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,248 +0,0 @@
     9.4 -/*
     9.5 - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
     9.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 - *
     9.8 - * This code is free software; you can redistribute it and/or modify it
     9.9 - * under the terms of the GNU General Public License version 2 only, as
    9.10 - * published by the Free Software Foundation.  Oracle designates this
    9.11 - * particular file as subject to the "Classpath" exception as provided
    9.12 - * by Oracle in the LICENSE file that accompanied this code.
    9.13 - *
    9.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    9.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.17 - * version 2 for more details (a copy is included in the LICENSE file that
    9.18 - * accompanied this code).
    9.19 - *
    9.20 - * You should have received a copy of the GNU General Public License version
    9.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    9.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.23 - *
    9.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.25 - * or visit www.oracle.com if you need additional information or have any
    9.26 - * questions.
    9.27 - */
    9.28 -package java.beans;
    9.29 -
    9.30 -import java.util.ArrayList;
    9.31 -import java.util.Collections;
    9.32 -import java.util.EventListener;
    9.33 -import java.util.EventListenerProxy;
    9.34 -import java.util.HashMap;
    9.35 -import java.util.List;
    9.36 -import java.util.Map;
    9.37 -import java.util.Map.Entry;
    9.38 -import java.util.Set;
    9.39 -import org.apidesign.bck2brwsr.emul.lang.System;
    9.40 -
    9.41 -/**
    9.42 - * This is an abstract class that provides base functionality
    9.43 - * for the {@link PropertyChangeSupport PropertyChangeSupport} class
    9.44 - * and the {@link VetoableChangeSupport VetoableChangeSupport} class.
    9.45 - *
    9.46 - * @see PropertyChangeListenerMap
    9.47 - * @see VetoableChangeListenerMap
    9.48 - *
    9.49 - * @author Sergey A. Malenkov
    9.50 - */
    9.51 -abstract class ChangeListenerMap<L extends EventListener> {
    9.52 -    private Map<String, L[]> map;
    9.53 -
    9.54 -    /**
    9.55 -     * Creates an array of listeners.
    9.56 -     * This method can be optimized by using
    9.57 -     * the same instance of the empty array
    9.58 -     * when {@code length} is equal to {@code 0}.
    9.59 -     *
    9.60 -     * @param length  the array length
    9.61 -     * @return        an array with specified length
    9.62 -     */
    9.63 -    protected abstract L[] newArray(int length);
    9.64 -
    9.65 -    /**
    9.66 -     * Creates a proxy listener for the specified property.
    9.67 -     *
    9.68 -     * @param name      the name of the property to listen on
    9.69 -     * @param listener  the listener to process events
    9.70 -     * @return          a proxy listener
    9.71 -     */
    9.72 -    protected abstract L newProxy(String name, L listener);
    9.73 -
    9.74 -    /**
    9.75 -     * Adds a listener to the list of listeners for the specified property.
    9.76 -     * This listener is called as many times as it was added.
    9.77 -     *
    9.78 -     * @param name      the name of the property to listen on
    9.79 -     * @param listener  the listener to process events
    9.80 -     */
    9.81 -    public final synchronized void add(String name, L listener) {
    9.82 -        if (this.map == null) {
    9.83 -            this.map = new HashMap<String, L[]>();
    9.84 -        }
    9.85 -        L[] array = this.map.get(name);
    9.86 -        int size = (array != null)
    9.87 -                ? array.length
    9.88 -                : 0;
    9.89 -
    9.90 -        L[] clone = newArray(size + 1);
    9.91 -        clone[size] = listener;
    9.92 -        if (array != null) {
    9.93 -            System.arraycopy(array, 0, clone, 0, size);
    9.94 -        }
    9.95 -        this.map.put(name, clone);
    9.96 -    }
    9.97 -
    9.98 -    /**
    9.99 -     * Removes a listener from the list of listeners for the specified property.
   9.100 -     * If the listener was added more than once to the same event source,
   9.101 -     * this listener will be notified one less time after being removed.
   9.102 -     *
   9.103 -     * @param name      the name of the property to listen on
   9.104 -     * @param listener  the listener to process events
   9.105 -     */
   9.106 -    public final synchronized void remove(String name, L listener) {
   9.107 -        if (this.map != null) {
   9.108 -            L[] array = this.map.get(name);
   9.109 -            if (array != null) {
   9.110 -                for (int i = 0; i < array.length; i++) {
   9.111 -                    if (listener.equals(array[i])) {
   9.112 -                        int size = array.length - 1;
   9.113 -                        if (size > 0) {
   9.114 -                            L[] clone = newArray(size);
   9.115 -                            System.arraycopy(array, 0, clone, 0, i);
   9.116 -                            System.arraycopy(array, i + 1, clone, i, size - i);
   9.117 -                            this.map.put(name, clone);
   9.118 -                        }
   9.119 -                        else {
   9.120 -                            this.map.remove(name);
   9.121 -                            if (this.map.isEmpty()) {
   9.122 -                                this.map = null;
   9.123 -                            }
   9.124 -                        }
   9.125 -                        break;
   9.126 -                    }
   9.127 -                }
   9.128 -            }
   9.129 -        }
   9.130 -    }
   9.131 -
   9.132 -    /**
   9.133 -     * Returns the list of listeners for the specified property.
   9.134 -     *
   9.135 -     * @param name  the name of the property
   9.136 -     * @return      the corresponding list of listeners
   9.137 -     */
   9.138 -    public final synchronized L[] get(String name) {
   9.139 -        return (this.map != null)
   9.140 -                ? this.map.get(name)
   9.141 -                : null;
   9.142 -    }
   9.143 -
   9.144 -    /**
   9.145 -     * Sets new list of listeners for the specified property.
   9.146 -     *
   9.147 -     * @param name       the name of the property
   9.148 -     * @param listeners  new list of listeners
   9.149 -     */
   9.150 -    public final void set(String name, L[] listeners) {
   9.151 -        if (listeners != null) {
   9.152 -            if (this.map == null) {
   9.153 -                this.map = new HashMap<String, L[]>();
   9.154 -            }
   9.155 -            this.map.put(name, listeners);
   9.156 -        }
   9.157 -        else if (this.map != null) {
   9.158 -            this.map.remove(name);
   9.159 -            if (this.map.isEmpty()) {
   9.160 -                this.map = null;
   9.161 -            }
   9.162 -        }
   9.163 -    }
   9.164 -
   9.165 -    /**
   9.166 -     * Returns all listeners in the map.
   9.167 -     *
   9.168 -     * @return an array of all listeners
   9.169 -     */
   9.170 -    public final synchronized L[] getListeners() {
   9.171 -        if (this.map == null) {
   9.172 -            return newArray(0);
   9.173 -        }
   9.174 -        List<L> list = new ArrayList<L>();
   9.175 -
   9.176 -        L[] listeners = this.map.get(null);
   9.177 -        if (listeners != null) {
   9.178 -            for (L listener : listeners) {
   9.179 -                list.add(listener);
   9.180 -            }
   9.181 -        }
   9.182 -        for (Entry<String, L[]> entry : this.map.entrySet()) {
   9.183 -            String name = entry.getKey();
   9.184 -            if (name != null) {
   9.185 -                for (L listener : entry.getValue()) {
   9.186 -                    list.add(newProxy(name, listener));
   9.187 -                }
   9.188 -            }
   9.189 -        }
   9.190 -        return list.toArray(newArray(list.size()));
   9.191 -    }
   9.192 -
   9.193 -    /**
   9.194 -     * Returns listeners that have been associated with the named property.
   9.195 -     *
   9.196 -     * @param name  the name of the property
   9.197 -     * @return an array of listeners for the named property
   9.198 -     */
   9.199 -    public final L[] getListeners(String name) {
   9.200 -        if (name != null) {
   9.201 -            L[] listeners = get(name);
   9.202 -            if (listeners != null) {
   9.203 -                return listeners.clone();
   9.204 -            }
   9.205 -        }
   9.206 -        return newArray(0);
   9.207 -    }
   9.208 -
   9.209 -    /**
   9.210 -     * Indicates whether the map contains
   9.211 -     * at least one listener to be notified.
   9.212 -     *
   9.213 -     * @param name  the name of the property
   9.214 -     * @return      {@code true} if at least one listener exists or
   9.215 -     *              {@code false} otherwise
   9.216 -     */
   9.217 -    public final synchronized boolean hasListeners(String name) {
   9.218 -        if (this.map == null) {
   9.219 -            return false;
   9.220 -        }
   9.221 -        L[] array = this.map.get(null);
   9.222 -        return (array != null) || ((name != null) && (null != this.map.get(name)));
   9.223 -    }
   9.224 -
   9.225 -    /**
   9.226 -     * Returns a set of entries from the map.
   9.227 -     * Each entry is a pair consisted of the property name
   9.228 -     * and the corresponding list of listeners.
   9.229 -     *
   9.230 -     * @return a set of entries from the map
   9.231 -     */
   9.232 -    public final Set<Entry<String, L[]>> getEntries() {
   9.233 -        return (this.map != null)
   9.234 -                ? this.map.entrySet()
   9.235 -                : Collections.<Entry<String, L[]>>emptySet();
   9.236 -    }
   9.237 -
   9.238 -    /**
   9.239 -     * Extracts a real listener from the proxy listener.
   9.240 -     * It is necessary because default proxy class is not serializable.
   9.241 -     *
   9.242 -     * @return a real listener
   9.243 -     */
   9.244 -    public final L extract(L listener) {
   9.245 -        while (listener instanceof EventListenerProxy) {
   9.246 -            EventListenerProxy<L> proxy = (EventListenerProxy<L>) listener;
   9.247 -            listener = proxy.getListener();
   9.248 -        }
   9.249 -        return listener;
   9.250 -    }
   9.251 -}
    10.1 --- a/emul/compact/src/main/java/java/beans/IndexedPropertyChangeEvent.java	Mon Feb 25 19:00:08 2013 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,78 +0,0 @@
    10.4 -/*
    10.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
    10.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 - *
    10.8 - * This code is free software; you can redistribute it and/or modify it
    10.9 - * under the terms of the GNU General Public License version 2 only, as
   10.10 - * published by the Free Software Foundation.  Oracle designates this
   10.11 - * particular file as subject to the "Classpath" exception as provided
   10.12 - * by Oracle in the LICENSE file that accompanied this code.
   10.13 - *
   10.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   10.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.17 - * version 2 for more details (a copy is included in the LICENSE file that
   10.18 - * accompanied this code).
   10.19 - *
   10.20 - * You should have received a copy of the GNU General Public License version
   10.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   10.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.23 - *
   10.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.25 - * or visit www.oracle.com if you need additional information or have any
   10.26 - * questions.
   10.27 - */
   10.28 -package java.beans;
   10.29 -
   10.30 -/**
   10.31 - * An "IndexedPropertyChange" event gets delivered whenever a component that
   10.32 - * conforms to the JavaBeans&trade; specification (a "bean") changes a bound
   10.33 - * indexed property. This class is an extension of <code>PropertyChangeEvent</code>
   10.34 - * but contains the index of the property that has changed.
   10.35 - * <P>
   10.36 - * Null values may be provided for the old and the new values if their
   10.37 - * true values are not known.
   10.38 - * <P>
   10.39 - * An event source may send a null object as the name to indicate that an
   10.40 - * arbitrary set of if its properties have changed.  In this case the
   10.41 - * old and new values should also be null.
   10.42 - *
   10.43 - * @since 1.5
   10.44 - * @author Mark Davidson
   10.45 - */
   10.46 -public class IndexedPropertyChangeEvent extends PropertyChangeEvent {
   10.47 -    private static final long serialVersionUID = -320227448495806870L;
   10.48 -
   10.49 -    private int index;
   10.50 -
   10.51 -    /**
   10.52 -     * Constructs a new <code>IndexedPropertyChangeEvent</code> object.
   10.53 -     *
   10.54 -     * @param source  The bean that fired the event.
   10.55 -     * @param propertyName  The programmatic name of the property that
   10.56 -     *             was changed.
   10.57 -     * @param oldValue      The old value of the property.
   10.58 -     * @param newValue      The new value of the property.
   10.59 -     * @param index index of the property element that was changed.
   10.60 -     */
   10.61 -    public IndexedPropertyChangeEvent(Object source, String propertyName,
   10.62 -                                      Object oldValue, Object newValue,
   10.63 -                                      int index) {
   10.64 -        super (source, propertyName, oldValue, newValue);
   10.65 -        this.index = index;
   10.66 -    }
   10.67 -
   10.68 -    /**
   10.69 -     * Gets the index of the property that was changed.
   10.70 -     *
   10.71 -     * @return The index specifying the property element that was
   10.72 -     *         changed.
   10.73 -     */
   10.74 -    public int getIndex() {
   10.75 -        return index;
   10.76 -    }
   10.77 -
   10.78 -    void appendTo(StringBuilder sb) {
   10.79 -        sb.append("; index=").append(getIndex());
   10.80 -    }
   10.81 -}
    11.1 --- a/emul/compact/src/main/java/java/beans/PropertyChangeEvent.java	Mon Feb 25 19:00:08 2013 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,164 +0,0 @@
    11.4 -/*
    11.5 - * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
    11.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 - *
    11.8 - * This code is free software; you can redistribute it and/or modify it
    11.9 - * under the terms of the GNU General Public License version 2 only, as
   11.10 - * published by the Free Software Foundation.  Oracle designates this
   11.11 - * particular file as subject to the "Classpath" exception as provided
   11.12 - * by Oracle in the LICENSE file that accompanied this code.
   11.13 - *
   11.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   11.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.17 - * version 2 for more details (a copy is included in the LICENSE file that
   11.18 - * accompanied this code).
   11.19 - *
   11.20 - * You should have received a copy of the GNU General Public License version
   11.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   11.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.23 - *
   11.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.25 - * or visit www.oracle.com if you need additional information or have any
   11.26 - * questions.
   11.27 - */
   11.28 -
   11.29 -package java.beans;
   11.30 -
   11.31 -/**
   11.32 - * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
   11.33 - * or "constrained" property.  A PropertyChangeEvent object is sent as an
   11.34 - * argument to the PropertyChangeListener and VetoableChangeListener methods.
   11.35 - * <P>
   11.36 - * Normally PropertyChangeEvents are accompanied by the name and the old
   11.37 - * and new value of the changed property.  If the new value is a primitive
   11.38 - * type (such as int or boolean) it must be wrapped as the
   11.39 - * corresponding java.lang.* Object type (such as Integer or Boolean).
   11.40 - * <P>
   11.41 - * Null values may be provided for the old and the new values if their
   11.42 - * true values are not known.
   11.43 - * <P>
   11.44 - * An event source may send a null object as the name to indicate that an
   11.45 - * arbitrary set of if its properties have changed.  In this case the
   11.46 - * old and new values should also be null.
   11.47 - */
   11.48 -
   11.49 -public class PropertyChangeEvent extends java.util.EventObject {
   11.50 -    private static final long serialVersionUID = 7042693688939648123L;
   11.51 -
   11.52 -    /**
   11.53 -     * Constructs a new <code>PropertyChangeEvent</code>.
   11.54 -     *
   11.55 -     * @param source  The bean that fired the event.
   11.56 -     * @param propertyName  The programmatic name of the property
   11.57 -     *          that was changed.
   11.58 -     * @param oldValue  The old value of the property.
   11.59 -     * @param newValue  The new value of the property.
   11.60 -     */
   11.61 -    public PropertyChangeEvent(Object source, String propertyName,
   11.62 -                                     Object oldValue, Object newValue) {
   11.63 -        super(source);
   11.64 -        this.propertyName = propertyName;
   11.65 -        this.newValue = newValue;
   11.66 -        this.oldValue = oldValue;
   11.67 -    }
   11.68 -
   11.69 -    /**
   11.70 -     * Gets the programmatic name of the property that was changed.
   11.71 -     *
   11.72 -     * @return  The programmatic name of the property that was changed.
   11.73 -     *          May be null if multiple properties have changed.
   11.74 -     */
   11.75 -    public String getPropertyName() {
   11.76 -        return propertyName;
   11.77 -    }
   11.78 -
   11.79 -    /**
   11.80 -     * Gets the new value for the property, expressed as an Object.
   11.81 -     *
   11.82 -     * @return  The new value for the property, expressed as an Object.
   11.83 -     *          May be null if multiple properties have changed.
   11.84 -     */
   11.85 -    public Object getNewValue() {
   11.86 -        return newValue;
   11.87 -    }
   11.88 -
   11.89 -    /**
   11.90 -     * Gets the old value for the property, expressed as an Object.
   11.91 -     *
   11.92 -     * @return  The old value for the property, expressed as an Object.
   11.93 -     *          May be null if multiple properties have changed.
   11.94 -     */
   11.95 -    public Object getOldValue() {
   11.96 -        return oldValue;
   11.97 -    }
   11.98 -
   11.99 -    /**
  11.100 -     * Sets the propagationId object for the event.
  11.101 -     *
  11.102 -     * @param propagationId  The propagationId object for the event.
  11.103 -     */
  11.104 -    public void setPropagationId(Object propagationId) {
  11.105 -        this.propagationId = propagationId;
  11.106 -    }
  11.107 -
  11.108 -    /**
  11.109 -     * The "propagationId" field is reserved for future use.  In Beans 1.0
  11.110 -     * the sole requirement is that if a listener catches a PropertyChangeEvent
  11.111 -     * and then fires a PropertyChangeEvent of its own, then it should
  11.112 -     * make sure that it propagates the propagationId field from its
  11.113 -     * incoming event to its outgoing event.
  11.114 -     *
  11.115 -     * @return the propagationId object associated with a bound/constrained
  11.116 -     *          property update.
  11.117 -     */
  11.118 -    public Object getPropagationId() {
  11.119 -        return propagationId;
  11.120 -    }
  11.121 -
  11.122 -    /**
  11.123 -     * name of the property that changed.  May be null, if not known.
  11.124 -     * @serial
  11.125 -     */
  11.126 -    private String propertyName;
  11.127 -
  11.128 -    /**
  11.129 -     * New value for property.  May be null if not known.
  11.130 -     * @serial
  11.131 -     */
  11.132 -    private Object newValue;
  11.133 -
  11.134 -    /**
  11.135 -     * Previous value for property.  May be null if not known.
  11.136 -     * @serial
  11.137 -     */
  11.138 -    private Object oldValue;
  11.139 -
  11.140 -    /**
  11.141 -     * Propagation ID.  May be null.
  11.142 -     * @serial
  11.143 -     * @see #getPropagationId
  11.144 -     */
  11.145 -    private Object propagationId;
  11.146 -
  11.147 -    /**
  11.148 -     * Returns a string representation of the object.
  11.149 -     *
  11.150 -     * @return a string representation of the object
  11.151 -     *
  11.152 -     * @since 1.7
  11.153 -     */
  11.154 -    public String toString() {
  11.155 -        StringBuilder sb = new StringBuilder(getClass().getName());
  11.156 -        sb.append("[propertyName=").append(getPropertyName());
  11.157 -        appendTo(sb);
  11.158 -        sb.append("; oldValue=").append(getOldValue());
  11.159 -        sb.append("; newValue=").append(getNewValue());
  11.160 -        sb.append("; propagationId=").append(getPropagationId());
  11.161 -        sb.append("; source=").append(getSource());
  11.162 -        return sb.append("]").toString();
  11.163 -    }
  11.164 -
  11.165 -    void appendTo(StringBuilder sb) {
  11.166 -    }
  11.167 -}
    12.1 --- a/emul/compact/src/main/java/java/beans/PropertyChangeListener.java	Mon Feb 25 19:00:08 2013 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,44 +0,0 @@
    12.4 -/*
    12.5 - * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved.
    12.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 - *
    12.8 - * This code is free software; you can redistribute it and/or modify it
    12.9 - * under the terms of the GNU General Public License version 2 only, as
   12.10 - * published by the Free Software Foundation.  Oracle designates this
   12.11 - * particular file as subject to the "Classpath" exception as provided
   12.12 - * by Oracle in the LICENSE file that accompanied this code.
   12.13 - *
   12.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   12.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.17 - * version 2 for more details (a copy is included in the LICENSE file that
   12.18 - * accompanied this code).
   12.19 - *
   12.20 - * You should have received a copy of the GNU General Public License version
   12.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   12.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.23 - *
   12.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.25 - * or visit www.oracle.com if you need additional information or have any
   12.26 - * questions.
   12.27 - */
   12.28 -
   12.29 -package java.beans;
   12.30 -
   12.31 -/**
   12.32 - * A "PropertyChange" event gets fired whenever a bean changes a "bound"
   12.33 - * property.  You can register a PropertyChangeListener with a source
   12.34 - * bean so as to be notified of any bound property updates.
   12.35 - */
   12.36 -
   12.37 -public interface PropertyChangeListener extends java.util.EventListener {
   12.38 -
   12.39 -    /**
   12.40 -     * This method gets called when a bound property is changed.
   12.41 -     * @param evt A PropertyChangeEvent object describing the event source
   12.42 -     *          and the property that has changed.
   12.43 -     */
   12.44 -
   12.45 -    void propertyChange(PropertyChangeEvent evt);
   12.46 -
   12.47 -}
    13.1 --- a/emul/compact/src/main/java/java/beans/PropertyChangeListenerProxy.java	Mon Feb 25 19:00:08 2013 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,81 +0,0 @@
    13.4 -/*
    13.5 - * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
    13.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 - *
    13.8 - * This code is free software; you can redistribute it and/or modify it
    13.9 - * under the terms of the GNU General Public License version 2 only, as
   13.10 - * published by the Free Software Foundation.  Oracle designates this
   13.11 - * particular file as subject to the "Classpath" exception as provided
   13.12 - * by Oracle in the LICENSE file that accompanied this code.
   13.13 - *
   13.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   13.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.17 - * version 2 for more details (a copy is included in the LICENSE file that
   13.18 - * accompanied this code).
   13.19 - *
   13.20 - * You should have received a copy of the GNU General Public License version
   13.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   13.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.23 - *
   13.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.25 - * or visit www.oracle.com if you need additional information or have any
   13.26 - * questions.
   13.27 - */
   13.28 -
   13.29 -package java.beans;
   13.30 -
   13.31 -import java.util.EventListenerProxy;
   13.32 -
   13.33 -/**
   13.34 - * A class which extends the {@code EventListenerProxy}
   13.35 - * specifically for adding a {@code PropertyChangeListener}
   13.36 - * with a "bound" property.
   13.37 - * Instances of this class can be added
   13.38 - * as {@code PropertyChangeListener}s to a bean
   13.39 - * which supports firing property change events.
   13.40 - * <p>
   13.41 - * If the object has a {@code getPropertyChangeListeners} method
   13.42 - * then the array returned could be a mixture of {@code PropertyChangeListener}
   13.43 - * and {@code PropertyChangeListenerProxy} objects.
   13.44 - *
   13.45 - * @see java.util.EventListenerProxy
   13.46 - * @see PropertyChangeSupport#getPropertyChangeListeners
   13.47 - * @since 1.4
   13.48 - */
   13.49 -public class PropertyChangeListenerProxy
   13.50 -        extends EventListenerProxy<PropertyChangeListener>
   13.51 -        implements PropertyChangeListener {
   13.52 -
   13.53 -    private final String propertyName;
   13.54 -
   13.55 -    /**
   13.56 -     * Constructor which binds the {@code PropertyChangeListener}
   13.57 -     * to a specific property.
   13.58 -     *
   13.59 -     * @param propertyName  the name of the property to listen on
   13.60 -     * @param listener      the listener object
   13.61 -     */
   13.62 -    public PropertyChangeListenerProxy(String propertyName, PropertyChangeListener listener) {
   13.63 -        super(listener);
   13.64 -        this.propertyName = propertyName;
   13.65 -    }
   13.66 -
   13.67 -    /**
   13.68 -     * Forwards the property change event to the listener delegate.
   13.69 -     *
   13.70 -     * @param event  the property change event
   13.71 -     */
   13.72 -    public void propertyChange(PropertyChangeEvent event) {
   13.73 -        getListener().propertyChange(event);
   13.74 -    }
   13.75 -
   13.76 -    /**
   13.77 -     * Returns the name of the named property associated with the listener.
   13.78 -     *
   13.79 -     * @return the name of the named property associated with the listener
   13.80 -     */
   13.81 -    public String getPropertyName() {
   13.82 -        return this.propertyName;
   13.83 -    }
   13.84 -}
    14.1 --- a/emul/compact/src/main/java/java/beans/PropertyChangeSupport.java	Mon Feb 25 19:00:08 2013 +0100
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,536 +0,0 @@
    14.4 -/*
    14.5 - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
    14.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.7 - *
    14.8 - * This code is free software; you can redistribute it and/or modify it
    14.9 - * under the terms of the GNU General Public License version 2 only, as
   14.10 - * published by the Free Software Foundation.  Oracle designates this
   14.11 - * particular file as subject to the "Classpath" exception as provided
   14.12 - * by Oracle in the LICENSE file that accompanied this code.
   14.13 - *
   14.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   14.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14.17 - * version 2 for more details (a copy is included in the LICENSE file that
   14.18 - * accompanied this code).
   14.19 - *
   14.20 - * You should have received a copy of the GNU General Public License version
   14.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   14.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   14.23 - *
   14.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   14.25 - * or visit www.oracle.com if you need additional information or have any
   14.26 - * questions.
   14.27 - */
   14.28 -package java.beans;
   14.29 -
   14.30 -import java.io.Serializable;
   14.31 -import java.io.ObjectStreamField;
   14.32 -import java.io.ObjectOutputStream;
   14.33 -import java.io.ObjectInputStream;
   14.34 -import java.io.IOException;
   14.35 -import java.util.Hashtable;
   14.36 -import java.util.Map.Entry;
   14.37 -
   14.38 -/**
   14.39 - * This is a utility class that can be used by beans that support bound
   14.40 - * properties.  It manages a list of listeners and dispatches
   14.41 - * {@link PropertyChangeEvent}s to them.  You can use an instance of this class
   14.42 - * as a member field of your bean and delegate these types of work to it.
   14.43 - * The {@link PropertyChangeListener} can be registered for all properties
   14.44 - * or for a property specified by name.
   14.45 - * <p>
   14.46 - * Here is an example of {@code PropertyChangeSupport} usage that follows
   14.47 - * the rules and recommendations laid out in the JavaBeans&trade; specification:
   14.48 - * <pre>
   14.49 - * public class MyBean {
   14.50 - *     private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
   14.51 - *
   14.52 - *     public void addPropertyChangeListener(PropertyChangeListener listener) {
   14.53 - *         this.pcs.addPropertyChangeListener(listener);
   14.54 - *     }
   14.55 - *
   14.56 - *     public void removePropertyChangeListener(PropertyChangeListener listener) {
   14.57 - *         this.pcs.removePropertyChangeListener(listener);
   14.58 - *     }
   14.59 - *
   14.60 - *     private String value;
   14.61 - *
   14.62 - *     public String getValue() {
   14.63 - *         return this.value;
   14.64 - *     }
   14.65 - *
   14.66 - *     public void setValue(String newValue) {
   14.67 - *         String oldValue = this.value;
   14.68 - *         this.value = newValue;
   14.69 - *         this.pcs.firePropertyChange("value", oldValue, newValue);
   14.70 - *     }
   14.71 - *
   14.72 - *     [...]
   14.73 - * }
   14.74 - * </pre>
   14.75 - * <p>
   14.76 - * A {@code PropertyChangeSupport} instance is thread-safe.
   14.77 - * <p>
   14.78 - * This class is serializable.  When it is serialized it will save
   14.79 - * (and restore) any listeners that are themselves serializable.  Any
   14.80 - * non-serializable listeners will be skipped during serialization.
   14.81 - *
   14.82 - * @see VetoableChangeSupport
   14.83 - */
   14.84 -public class PropertyChangeSupport implements Serializable {
   14.85 -    private PropertyChangeListenerMap map = new PropertyChangeListenerMap();
   14.86 -
   14.87 -    /**
   14.88 -     * Constructs a <code>PropertyChangeSupport</code> object.
   14.89 -     *
   14.90 -     * @param sourceBean  The bean to be given as the source for any events.
   14.91 -     */
   14.92 -    public PropertyChangeSupport(Object sourceBean) {
   14.93 -        if (sourceBean == null) {
   14.94 -            throw new NullPointerException();
   14.95 -        }
   14.96 -        source = sourceBean;
   14.97 -    }
   14.98 -
   14.99 -    /**
  14.100 -     * Add a PropertyChangeListener to the listener list.
  14.101 -     * The listener is registered for all properties.
  14.102 -     * The same listener object may be added more than once, and will be called
  14.103 -     * as many times as it is added.
  14.104 -     * If <code>listener</code> is null, no exception is thrown and no action
  14.105 -     * is taken.
  14.106 -     *
  14.107 -     * @param listener  The PropertyChangeListener to be added
  14.108 -     */
  14.109 -    public void addPropertyChangeListener(PropertyChangeListener listener) {
  14.110 -        if (listener == null) {
  14.111 -            return;
  14.112 -        }
  14.113 -        if (listener instanceof PropertyChangeListenerProxy) {
  14.114 -            PropertyChangeListenerProxy proxy =
  14.115 -                   (PropertyChangeListenerProxy)listener;
  14.116 -            // Call two argument add method.
  14.117 -            addPropertyChangeListener(proxy.getPropertyName(),
  14.118 -                                      proxy.getListener());
  14.119 -        } else {
  14.120 -            this.map.add(null, listener);
  14.121 -        }
  14.122 -    }
  14.123 -
  14.124 -    /**
  14.125 -     * Remove a PropertyChangeListener from the listener list.
  14.126 -     * This removes a PropertyChangeListener that was registered
  14.127 -     * for all properties.
  14.128 -     * If <code>listener</code> was added more than once to the same event
  14.129 -     * source, it will be notified one less time after being removed.
  14.130 -     * If <code>listener</code> is null, or was never added, no exception is
  14.131 -     * thrown and no action is taken.
  14.132 -     *
  14.133 -     * @param listener  The PropertyChangeListener to be removed
  14.134 -     */
  14.135 -    public void removePropertyChangeListener(PropertyChangeListener listener) {
  14.136 -        if (listener == null) {
  14.137 -            return;
  14.138 -        }
  14.139 -        if (listener instanceof PropertyChangeListenerProxy) {
  14.140 -            PropertyChangeListenerProxy proxy =
  14.141 -                    (PropertyChangeListenerProxy)listener;
  14.142 -            // Call two argument remove method.
  14.143 -            removePropertyChangeListener(proxy.getPropertyName(),
  14.144 -                                         proxy.getListener());
  14.145 -        } else {
  14.146 -            this.map.remove(null, listener);
  14.147 -        }
  14.148 -    }
  14.149 -
  14.150 -    /**
  14.151 -     * Returns an array of all the listeners that were added to the
  14.152 -     * PropertyChangeSupport object with addPropertyChangeListener().
  14.153 -     * <p>
  14.154 -     * If some listeners have been added with a named property, then
  14.155 -     * the returned array will be a mixture of PropertyChangeListeners
  14.156 -     * and <code>PropertyChangeListenerProxy</code>s. If the calling
  14.157 -     * method is interested in distinguishing the listeners then it must
  14.158 -     * test each element to see if it's a
  14.159 -     * <code>PropertyChangeListenerProxy</code>, perform the cast, and examine
  14.160 -     * the parameter.
  14.161 -     *
  14.162 -     * <pre>
  14.163 -     * PropertyChangeListener[] listeners = bean.getPropertyChangeListeners();
  14.164 -     * for (int i = 0; i < listeners.length; i++) {
  14.165 -     *   if (listeners[i] instanceof PropertyChangeListenerProxy) {
  14.166 -     *     PropertyChangeListenerProxy proxy =
  14.167 -     *                    (PropertyChangeListenerProxy)listeners[i];
  14.168 -     *     if (proxy.getPropertyName().equals("foo")) {
  14.169 -     *       // proxy is a PropertyChangeListener which was associated
  14.170 -     *       // with the property named "foo"
  14.171 -     *     }
  14.172 -     *   }
  14.173 -     * }
  14.174 -     *</pre>
  14.175 -     *
  14.176 -     * @see PropertyChangeListenerProxy
  14.177 -     * @return all of the <code>PropertyChangeListeners</code> added or an
  14.178 -     *         empty array if no listeners have been added
  14.179 -     * @since 1.4
  14.180 -     */
  14.181 -    public PropertyChangeListener[] getPropertyChangeListeners() {
  14.182 -        return this.map.getListeners();
  14.183 -    }
  14.184 -
  14.185 -    /**
  14.186 -     * Add a PropertyChangeListener for a specific property.  The listener
  14.187 -     * will be invoked only when a call on firePropertyChange names that
  14.188 -     * specific property.
  14.189 -     * The same listener object may be added more than once.  For each
  14.190 -     * property,  the listener will be invoked the number of times it was added
  14.191 -     * for that property.
  14.192 -     * If <code>propertyName</code> or <code>listener</code> is null, no
  14.193 -     * exception is thrown and no action is taken.
  14.194 -     *
  14.195 -     * @param propertyName  The name of the property to listen on.
  14.196 -     * @param listener  The PropertyChangeListener to be added
  14.197 -     */
  14.198 -    public void addPropertyChangeListener(
  14.199 -                String propertyName,
  14.200 -                PropertyChangeListener listener) {
  14.201 -        if (listener == null || propertyName == null) {
  14.202 -            return;
  14.203 -        }
  14.204 -        listener = this.map.extract(listener);
  14.205 -        if (listener != null) {
  14.206 -            this.map.add(propertyName, listener);
  14.207 -        }
  14.208 -    }
  14.209 -
  14.210 -    /**
  14.211 -     * Remove a PropertyChangeListener for a specific property.
  14.212 -     * If <code>listener</code> was added more than once to the same event
  14.213 -     * source for the specified property, it will be notified one less time
  14.214 -     * after being removed.
  14.215 -     * If <code>propertyName</code> is null,  no exception is thrown and no
  14.216 -     * action is taken.
  14.217 -     * If <code>listener</code> is null, or was never added for the specified
  14.218 -     * property, no exception is thrown and no action is taken.
  14.219 -     *
  14.220 -     * @param propertyName  The name of the property that was listened on.
  14.221 -     * @param listener  The PropertyChangeListener to be removed
  14.222 -     */
  14.223 -    public void removePropertyChangeListener(
  14.224 -                String propertyName,
  14.225 -                PropertyChangeListener listener) {
  14.226 -        if (listener == null || propertyName == null) {
  14.227 -            return;
  14.228 -        }
  14.229 -        listener = this.map.extract(listener);
  14.230 -        if (listener != null) {
  14.231 -            this.map.remove(propertyName, listener);
  14.232 -        }
  14.233 -    }
  14.234 -
  14.235 -    /**
  14.236 -     * Returns an array of all the listeners which have been associated
  14.237 -     * with the named property.
  14.238 -     *
  14.239 -     * @param propertyName  The name of the property being listened to
  14.240 -     * @return all of the <code>PropertyChangeListeners</code> associated with
  14.241 -     *         the named property.  If no such listeners have been added,
  14.242 -     *         or if <code>propertyName</code> is null, an empty array is
  14.243 -     *         returned.
  14.244 -     * @since 1.4
  14.245 -     */
  14.246 -    public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
  14.247 -        return this.map.getListeners(propertyName);
  14.248 -    }
  14.249 -
  14.250 -    /**
  14.251 -     * Reports a bound property update to listeners
  14.252 -     * that have been registered to track updates of
  14.253 -     * all properties or a property with the specified name.
  14.254 -     * <p>
  14.255 -     * No event is fired if old and new values are equal and non-null.
  14.256 -     * <p>
  14.257 -     * This is merely a convenience wrapper around the more general
  14.258 -     * {@link #firePropertyChange(PropertyChangeEvent)} method.
  14.259 -     *
  14.260 -     * @param propertyName  the programmatic name of the property that was changed
  14.261 -     * @param oldValue      the old value of the property
  14.262 -     * @param newValue      the new value of the property
  14.263 -     */
  14.264 -    public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
  14.265 -        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
  14.266 -            firePropertyChange(new PropertyChangeEvent(this.source, propertyName, oldValue, newValue));
  14.267 -        }
  14.268 -    }
  14.269 -
  14.270 -    /**
  14.271 -     * Reports an integer bound property update to listeners
  14.272 -     * that have been registered to track updates of
  14.273 -     * all properties or a property with the specified name.
  14.274 -     * <p>
  14.275 -     * No event is fired if old and new values are equal.
  14.276 -     * <p>
  14.277 -     * This is merely a convenience wrapper around the more general
  14.278 -     * {@link #firePropertyChange(String, Object, Object)}  method.
  14.279 -     *
  14.280 -     * @param propertyName  the programmatic name of the property that was changed
  14.281 -     * @param oldValue      the old value of the property
  14.282 -     * @param newValue      the new value of the property
  14.283 -     */
  14.284 -    public void firePropertyChange(String propertyName, int oldValue, int newValue) {
  14.285 -        if (oldValue != newValue) {
  14.286 -            firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
  14.287 -        }
  14.288 -    }
  14.289 -
  14.290 -    /**
  14.291 -     * Reports a boolean bound property update to listeners
  14.292 -     * that have been registered to track updates of
  14.293 -     * all properties or a property with the specified name.
  14.294 -     * <p>
  14.295 -     * No event is fired if old and new values are equal.
  14.296 -     * <p>
  14.297 -     * This is merely a convenience wrapper around the more general
  14.298 -     * {@link #firePropertyChange(String, Object, Object)}  method.
  14.299 -     *
  14.300 -     * @param propertyName  the programmatic name of the property that was changed
  14.301 -     * @param oldValue      the old value of the property
  14.302 -     * @param newValue      the new value of the property
  14.303 -     */
  14.304 -    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
  14.305 -        if (oldValue != newValue) {
  14.306 -            firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
  14.307 -        }
  14.308 -    }
  14.309 -
  14.310 -    /**
  14.311 -     * Fires a property change event to listeners
  14.312 -     * that have been registered to track updates of
  14.313 -     * all properties or a property with the specified name.
  14.314 -     * <p>
  14.315 -     * No event is fired if the given event's old and new values are equal and non-null.
  14.316 -     *
  14.317 -     * @param event  the {@code PropertyChangeEvent} to be fired
  14.318 -     */
  14.319 -    public void firePropertyChange(PropertyChangeEvent event) {
  14.320 -        Object oldValue = event.getOldValue();
  14.321 -        Object newValue = event.getNewValue();
  14.322 -        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
  14.323 -            String name = event.getPropertyName();
  14.324 -
  14.325 -            PropertyChangeListener[] common = this.map.get(null);
  14.326 -            PropertyChangeListener[] named = (name != null)
  14.327 -                        ? this.map.get(name)
  14.328 -                        : null;
  14.329 -
  14.330 -            fire(common, event);
  14.331 -            fire(named, event);
  14.332 -        }
  14.333 -    }
  14.334 -
  14.335 -    private static void fire(PropertyChangeListener[] listeners, PropertyChangeEvent event) {
  14.336 -        if (listeners != null) {
  14.337 -            for (PropertyChangeListener listener : listeners) {
  14.338 -                listener.propertyChange(event);
  14.339 -            }
  14.340 -        }
  14.341 -    }
  14.342 -
  14.343 -    /**
  14.344 -     * Reports a bound indexed property update to listeners
  14.345 -     * that have been registered to track updates of
  14.346 -     * all properties or a property with the specified name.
  14.347 -     * <p>
  14.348 -     * No event is fired if old and new values are equal and non-null.
  14.349 -     * <p>
  14.350 -     * This is merely a convenience wrapper around the more general
  14.351 -     * {@link #firePropertyChange(PropertyChangeEvent)} method.
  14.352 -     *
  14.353 -     * @param propertyName  the programmatic name of the property that was changed
  14.354 -     * @param index         the index of the property element that was changed
  14.355 -     * @param oldValue      the old value of the property
  14.356 -     * @param newValue      the new value of the property
  14.357 -     * @since 1.5
  14.358 -     */
  14.359 -    public void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) {
  14.360 -        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
  14.361 -            firePropertyChange(new IndexedPropertyChangeEvent(source, propertyName, oldValue, newValue, index));
  14.362 -        }
  14.363 -    }
  14.364 -
  14.365 -    /**
  14.366 -     * Reports an integer bound indexed property update to listeners
  14.367 -     * that have been registered to track updates of
  14.368 -     * all properties or a property with the specified name.
  14.369 -     * <p>
  14.370 -     * No event is fired if old and new values are equal.
  14.371 -     * <p>
  14.372 -     * This is merely a convenience wrapper around the more general
  14.373 -     * {@link #fireIndexedPropertyChange(String, int, Object, Object)} method.
  14.374 -     *
  14.375 -     * @param propertyName  the programmatic name of the property that was changed
  14.376 -     * @param index         the index of the property element that was changed
  14.377 -     * @param oldValue      the old value of the property
  14.378 -     * @param newValue      the new value of the property
  14.379 -     * @since 1.5
  14.380 -     */
  14.381 -    public void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue) {
  14.382 -        if (oldValue != newValue) {
  14.383 -            fireIndexedPropertyChange(propertyName, index, Integer.valueOf(oldValue), Integer.valueOf(newValue));
  14.384 -        }
  14.385 -    }
  14.386 -
  14.387 -    /**
  14.388 -     * Reports a boolean bound indexed property update to listeners
  14.389 -     * that have been registered to track updates of
  14.390 -     * all properties or a property with the specified name.
  14.391 -     * <p>
  14.392 -     * No event is fired if old and new values are equal.
  14.393 -     * <p>
  14.394 -     * This is merely a convenience wrapper around the more general
  14.395 -     * {@link #fireIndexedPropertyChange(String, int, Object, Object)} method.
  14.396 -     *
  14.397 -     * @param propertyName  the programmatic name of the property that was changed
  14.398 -     * @param index         the index of the property element that was changed
  14.399 -     * @param oldValue      the old value of the property
  14.400 -     * @param newValue      the new value of the property
  14.401 -     * @since 1.5
  14.402 -     */
  14.403 -    public void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue) {
  14.404 -        if (oldValue != newValue) {
  14.405 -            fireIndexedPropertyChange(propertyName, index, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
  14.406 -        }
  14.407 -    }
  14.408 -
  14.409 -    /**
  14.410 -     * Check if there are any listeners for a specific property, including
  14.411 -     * those registered on all properties.  If <code>propertyName</code>
  14.412 -     * is null, only check for listeners registered on all properties.
  14.413 -     *
  14.414 -     * @param propertyName  the property name.
  14.415 -     * @return true if there are one or more listeners for the given property
  14.416 -     */
  14.417 -    public boolean hasListeners(String propertyName) {
  14.418 -        return this.map.hasListeners(propertyName);
  14.419 -    }
  14.420 -
  14.421 -    /**
  14.422 -     * @serialData Null terminated list of <code>PropertyChangeListeners</code>.
  14.423 -     * <p>
  14.424 -     * At serialization time we skip non-serializable listeners and
  14.425 -     * only serialize the serializable listeners.
  14.426 -     */
  14.427 -    private void writeObject(ObjectOutputStream s) throws IOException {
  14.428 -        Hashtable<String, PropertyChangeSupport> children = null;
  14.429 -        PropertyChangeListener[] listeners = null;
  14.430 -        synchronized (this.map) {
  14.431 -            for (Entry<String, PropertyChangeListener[]> entry : this.map.getEntries()) {
  14.432 -                String property = entry.getKey();
  14.433 -                if (property == null) {
  14.434 -                    listeners = entry.getValue();
  14.435 -                } else {
  14.436 -                    if (children == null) {
  14.437 -                        children = new Hashtable<String, PropertyChangeSupport>();
  14.438 -                    }
  14.439 -                    PropertyChangeSupport pcs = new PropertyChangeSupport(this.source);
  14.440 -                    pcs.map.set(null, entry.getValue());
  14.441 -                    children.put(property, pcs);
  14.442 -                }
  14.443 -            }
  14.444 -        }
  14.445 -        ObjectOutputStream.PutField fields = s.putFields();
  14.446 -        fields.put("children", children);
  14.447 -        fields.put("source", this.source);
  14.448 -        fields.put("propertyChangeSupportSerializedDataVersion", 2);
  14.449 -        s.writeFields();
  14.450 -
  14.451 -        if (listeners != null) {
  14.452 -            for (PropertyChangeListener l : listeners) {
  14.453 -                if (l instanceof Serializable) {
  14.454 -                    s.writeObject(l);
  14.455 -                }
  14.456 -            }
  14.457 -        }
  14.458 -        s.writeObject(null);
  14.459 -    }
  14.460 -
  14.461 -    private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
  14.462 -        this.map = new PropertyChangeListenerMap();
  14.463 -
  14.464 -        ObjectInputStream.GetField fields = s.readFields();
  14.465 -
  14.466 -        Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
  14.467 -        this.source = fields.get("source", null);
  14.468 -        fields.get("propertyChangeSupportSerializedDataVersion", 2);
  14.469 -
  14.470 -        Object listenerOrNull;
  14.471 -        while (null != (listenerOrNull = s.readObject())) {
  14.472 -            this.map.add(null, (PropertyChangeListener)listenerOrNull);
  14.473 -        }
  14.474 -        if (children != null) {
  14.475 -            for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
  14.476 -                for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
  14.477 -                    this.map.add(entry.getKey(), listener);
  14.478 -                }
  14.479 -            }
  14.480 -        }
  14.481 -    }
  14.482 -
  14.483 -    /**
  14.484 -     * The object to be provided as the "source" for any generated events.
  14.485 -     */
  14.486 -    private Object source;
  14.487 -
  14.488 -    /**
  14.489 -     * @serialField children                                   Hashtable
  14.490 -     * @serialField source                                     Object
  14.491 -     * @serialField propertyChangeSupportSerializedDataVersion int
  14.492 -     */
  14.493 -    private static final ObjectStreamField[] serialPersistentFields = {
  14.494 -            new ObjectStreamField("children", Hashtable.class),
  14.495 -            new ObjectStreamField("source", Object.class),
  14.496 -            new ObjectStreamField("propertyChangeSupportSerializedDataVersion", Integer.TYPE)
  14.497 -    };
  14.498 -
  14.499 -    /**
  14.500 -     * Serialization version ID, so we're compatible with JDK 1.1
  14.501 -     */
  14.502 -    static final long serialVersionUID = 6401253773779951803L;
  14.503 -
  14.504 -    /**
  14.505 -     * This is a {@link ChangeListenerMap ChangeListenerMap} implementation
  14.506 -     * that works with {@link PropertyChangeListener PropertyChangeListener} objects.
  14.507 -     */
  14.508 -    private static final class PropertyChangeListenerMap extends ChangeListenerMap<PropertyChangeListener> {
  14.509 -        private static final PropertyChangeListener[] EMPTY = {};
  14.510 -
  14.511 -        /**
  14.512 -         * Creates an array of {@link PropertyChangeListener PropertyChangeListener} objects.
  14.513 -         * This method uses the same instance of the empty array
  14.514 -         * when {@code length} equals {@code 0}.
  14.515 -         *
  14.516 -         * @param length  the array length
  14.517 -         * @return        an array with specified length
  14.518 -         */
  14.519 -        @Override
  14.520 -        protected PropertyChangeListener[] newArray(int length) {
  14.521 -            return (0 < length)
  14.522 -                    ? new PropertyChangeListener[length]
  14.523 -                    : EMPTY;
  14.524 -        }
  14.525 -
  14.526 -        /**
  14.527 -         * Creates a {@link PropertyChangeListenerProxy PropertyChangeListenerProxy}
  14.528 -         * object for the specified property.
  14.529 -         *
  14.530 -         * @param name      the name of the property to listen on
  14.531 -         * @param listener  the listener to process events
  14.532 -         * @return          a {@code PropertyChangeListenerProxy} object
  14.533 -         */
  14.534 -        @Override
  14.535 -        protected PropertyChangeListener newProxy(String name, PropertyChangeListener listener) {
  14.536 -            return new PropertyChangeListenerProxy(name, listener);
  14.537 -        }
  14.538 -    }
  14.539 -}
    15.1 --- a/emul/compact/src/main/java/java/beans/PropertyVetoException.java	Mon Feb 25 19:00:08 2013 +0100
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,64 +0,0 @@
    15.4 -/*
    15.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
    15.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 - *
    15.8 - * This code is free software; you can redistribute it and/or modify it
    15.9 - * under the terms of the GNU General Public License version 2 only, as
   15.10 - * published by the Free Software Foundation.  Oracle designates this
   15.11 - * particular file as subject to the "Classpath" exception as provided
   15.12 - * by Oracle in the LICENSE file that accompanied this code.
   15.13 - *
   15.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   15.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.17 - * version 2 for more details (a copy is included in the LICENSE file that
   15.18 - * accompanied this code).
   15.19 - *
   15.20 - * You should have received a copy of the GNU General Public License version
   15.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   15.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.23 - *
   15.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   15.25 - * or visit www.oracle.com if you need additional information or have any
   15.26 - * questions.
   15.27 - */
   15.28 -
   15.29 -package java.beans;
   15.30 -
   15.31 -
   15.32 -/**
   15.33 - * A PropertyVetoException is thrown when a proposed change to a
   15.34 - * property represents an unacceptable value.
   15.35 - */
   15.36 -
   15.37 -public
   15.38 -class PropertyVetoException extends Exception {
   15.39 -    private static final long serialVersionUID = 129596057694162164L;
   15.40 -
   15.41 -    /**
   15.42 -     * Constructs a <code>PropertyVetoException</code> with a
   15.43 -     * detailed message.
   15.44 -     *
   15.45 -     * @param mess Descriptive message
   15.46 -     * @param evt A PropertyChangeEvent describing the vetoed change.
   15.47 -     */
   15.48 -    public PropertyVetoException(String mess, PropertyChangeEvent evt) {
   15.49 -        super(mess);
   15.50 -        this.evt = evt;
   15.51 -    }
   15.52 -
   15.53 -     /**
   15.54 -     * Gets the vetoed <code>PropertyChangeEvent</code>.
   15.55 -     *
   15.56 -     * @return A PropertyChangeEvent describing the vetoed change.
   15.57 -     */
   15.58 -    public PropertyChangeEvent getPropertyChangeEvent() {
   15.59 -        return evt;
   15.60 -    }
   15.61 -
   15.62 -    /**
   15.63 -     * A PropertyChangeEvent describing the vetoed change.
   15.64 -     * @serial
   15.65 -     */
   15.66 -    private PropertyChangeEvent evt;
   15.67 -}
    16.1 --- a/emul/compact/src/main/java/java/beans/VetoableChangeListener.java	Mon Feb 25 19:00:08 2013 +0100
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,44 +0,0 @@
    16.4 -/*
    16.5 - * Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved.
    16.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 - *
    16.8 - * This code is free software; you can redistribute it and/or modify it
    16.9 - * under the terms of the GNU General Public License version 2 only, as
   16.10 - * published by the Free Software Foundation.  Oracle designates this
   16.11 - * particular file as subject to the "Classpath" exception as provided
   16.12 - * by Oracle in the LICENSE file that accompanied this code.
   16.13 - *
   16.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   16.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.17 - * version 2 for more details (a copy is included in the LICENSE file that
   16.18 - * accompanied this code).
   16.19 - *
   16.20 - * You should have received a copy of the GNU General Public License version
   16.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   16.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.23 - *
   16.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.25 - * or visit www.oracle.com if you need additional information or have any
   16.26 - * questions.
   16.27 - */
   16.28 -
   16.29 -package java.beans;
   16.30 -
   16.31 -/**
   16.32 - * A VetoableChange event gets fired whenever a bean changes a "constrained"
   16.33 - * property.  You can register a VetoableChangeListener with a source bean
   16.34 - * so as to be notified of any constrained property updates.
   16.35 - */
   16.36 -public interface VetoableChangeListener extends java.util.EventListener {
   16.37 -    /**
   16.38 -     * This method gets called when a constrained property is changed.
   16.39 -     *
   16.40 -     * @param     evt a <code>PropertyChangeEvent</code> object describing the
   16.41 -     *                event source and the property that has changed.
   16.42 -     * @exception PropertyVetoException if the recipient wishes the property
   16.43 -     *              change to be rolled back.
   16.44 -     */
   16.45 -    void vetoableChange(PropertyChangeEvent evt)
   16.46 -                                throws PropertyVetoException;
   16.47 -}
    17.1 --- a/emul/compact/src/main/java/java/beans/VetoableChangeListenerProxy.java	Mon Feb 25 19:00:08 2013 +0100
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,84 +0,0 @@
    17.4 -/*
    17.5 - * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
    17.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 - *
    17.8 - * This code is free software; you can redistribute it and/or modify it
    17.9 - * under the terms of the GNU General Public License version 2 only, as
   17.10 - * published by the Free Software Foundation.  Oracle designates this
   17.11 - * particular file as subject to the "Classpath" exception as provided
   17.12 - * by Oracle in the LICENSE file that accompanied this code.
   17.13 - *
   17.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   17.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.17 - * version 2 for more details (a copy is included in the LICENSE file that
   17.18 - * accompanied this code).
   17.19 - *
   17.20 - * You should have received a copy of the GNU General Public License version
   17.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   17.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.23 - *
   17.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.25 - * or visit www.oracle.com if you need additional information or have any
   17.26 - * questions.
   17.27 - */
   17.28 -
   17.29 -package java.beans;
   17.30 -
   17.31 -import java.util.EventListenerProxy;
   17.32 -
   17.33 -/**
   17.34 - * A class which extends the {@code EventListenerProxy}
   17.35 - * specifically for adding a {@code VetoableChangeListener}
   17.36 - * with a "constrained" property.
   17.37 - * Instances of this class can be added
   17.38 - * as {@code VetoableChangeListener}s to a bean
   17.39 - * which supports firing vetoable change events.
   17.40 - * <p>
   17.41 - * If the object has a {@code getVetoableChangeListeners} method
   17.42 - * then the array returned could be a mixture of {@code VetoableChangeListener}
   17.43 - * and {@code VetoableChangeListenerProxy} objects.
   17.44 - *
   17.45 - * @see java.util.EventListenerProxy
   17.46 - * @see VetoableChangeSupport#getVetoableChangeListeners
   17.47 - * @since 1.4
   17.48 - */
   17.49 -public class VetoableChangeListenerProxy
   17.50 -        extends EventListenerProxy<VetoableChangeListener>
   17.51 -        implements VetoableChangeListener {
   17.52 -
   17.53 -    private final String propertyName;
   17.54 -
   17.55 -    /**
   17.56 -     * Constructor which binds the {@code VetoableChangeListener}
   17.57 -     * to a specific property.
   17.58 -     *
   17.59 -     * @param propertyName  the name of the property to listen on
   17.60 -     * @param listener      the listener object
   17.61 -     */
   17.62 -    public VetoableChangeListenerProxy(String propertyName, VetoableChangeListener listener) {
   17.63 -        super(listener);
   17.64 -        this.propertyName = propertyName;
   17.65 -    }
   17.66 -
   17.67 -    /**
   17.68 -    * Forwards the property change event to the listener delegate.
   17.69 -    *
   17.70 -    * @param event  the property change event
   17.71 -    *
   17.72 -    * @exception PropertyVetoException if the recipient wishes the property
   17.73 -    *                                  change to be rolled back
   17.74 -    */
   17.75 -    public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException{
   17.76 -        getListener().vetoableChange(event);
   17.77 -    }
   17.78 -
   17.79 -    /**
   17.80 -     * Returns the name of the named property associated with the listener.
   17.81 -     *
   17.82 -     * @return the name of the named property associated with the listener
   17.83 -     */
   17.84 -    public String getPropertyName() {
   17.85 -        return this.propertyName;
   17.86 -    }
   17.87 -}
    18.1 --- a/emul/compact/src/main/java/java/beans/VetoableChangeSupport.java	Mon Feb 25 19:00:08 2013 +0100
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,526 +0,0 @@
    18.4 -/*
    18.5 - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
    18.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 - *
    18.8 - * This code is free software; you can redistribute it and/or modify it
    18.9 - * under the terms of the GNU General Public License version 2 only, as
   18.10 - * published by the Free Software Foundation.  Oracle designates this
   18.11 - * particular file as subject to the "Classpath" exception as provided
   18.12 - * by Oracle in the LICENSE file that accompanied this code.
   18.13 - *
   18.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   18.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.17 - * version 2 for more details (a copy is included in the LICENSE file that
   18.18 - * accompanied this code).
   18.19 - *
   18.20 - * You should have received a copy of the GNU General Public License version
   18.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   18.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.23 - *
   18.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   18.25 - * or visit www.oracle.com if you need additional information or have any
   18.26 - * questions.
   18.27 - */
   18.28 -package java.beans;
   18.29 -
   18.30 -import java.io.Serializable;
   18.31 -import java.io.ObjectStreamField;
   18.32 -import java.io.ObjectOutputStream;
   18.33 -import java.io.ObjectInputStream;
   18.34 -import java.io.IOException;
   18.35 -import java.util.Hashtable;
   18.36 -import java.util.Map.Entry;
   18.37 -import org.apidesign.bck2brwsr.emul.lang.System;
   18.38 -
   18.39 -/**
   18.40 - * This is a utility class that can be used by beans that support constrained
   18.41 - * properties.  It manages a list of listeners and dispatches
   18.42 - * {@link PropertyChangeEvent}s to them.  You can use an instance of this class
   18.43 - * as a member field of your bean and delegate these types of work to it.
   18.44 - * The {@link VetoableChangeListener} can be registered for all properties
   18.45 - * or for a property specified by name.
   18.46 - * <p>
   18.47 - * Here is an example of {@code VetoableChangeSupport} usage that follows
   18.48 - * the rules and recommendations laid out in the JavaBeans&trade; specification:
   18.49 - * <pre>
   18.50 - * public class MyBean {
   18.51 - *     private final VetoableChangeSupport vcs = new VetoableChangeSupport(this);
   18.52 - *
   18.53 - *     public void addVetoableChangeListener(VetoableChangeListener listener) {
   18.54 - *         this.vcs.addVetoableChangeListener(listener);
   18.55 - *     }
   18.56 - *
   18.57 - *     public void removeVetoableChangeListener(VetoableChangeListener listener) {
   18.58 - *         this.vcs.removeVetoableChangeListener(listener);
   18.59 - *     }
   18.60 - *
   18.61 - *     private String value;
   18.62 - *
   18.63 - *     public String getValue() {
   18.64 - *         return this.value;
   18.65 - *     }
   18.66 - *
   18.67 - *     public void setValue(String newValue) throws PropertyVetoException {
   18.68 - *         String oldValue = this.value;
   18.69 - *         this.vcs.fireVetoableChange("value", oldValue, newValue);
   18.70 - *         this.value = newValue;
   18.71 - *     }
   18.72 - *
   18.73 - *     [...]
   18.74 - * }
   18.75 - * </pre>
   18.76 - * <p>
   18.77 - * A {@code VetoableChangeSupport} instance is thread-safe.
   18.78 - * <p>
   18.79 - * This class is serializable.  When it is serialized it will save
   18.80 - * (and restore) any listeners that are themselves serializable.  Any
   18.81 - * non-serializable listeners will be skipped during serialization.
   18.82 - *
   18.83 - * @see PropertyChangeSupport
   18.84 - */
   18.85 -public class VetoableChangeSupport implements Serializable {
   18.86 -    private VetoableChangeListenerMap map = new VetoableChangeListenerMap();
   18.87 -
   18.88 -    /**
   18.89 -     * Constructs a <code>VetoableChangeSupport</code> object.
   18.90 -     *
   18.91 -     * @param sourceBean  The bean to be given as the source for any events.
   18.92 -     */
   18.93 -    public VetoableChangeSupport(Object sourceBean) {
   18.94 -        if (sourceBean == null) {
   18.95 -            throw new NullPointerException();
   18.96 -        }
   18.97 -        source = sourceBean;
   18.98 -    }
   18.99 -
  18.100 -    /**
  18.101 -     * Add a VetoableChangeListener to the listener list.
  18.102 -     * The listener is registered for all properties.
  18.103 -     * The same listener object may be added more than once, and will be called
  18.104 -     * as many times as it is added.
  18.105 -     * If <code>listener</code> is null, no exception is thrown and no action
  18.106 -     * is taken.
  18.107 -     *
  18.108 -     * @param listener  The VetoableChangeListener to be added
  18.109 -     */
  18.110 -    public void addVetoableChangeListener(VetoableChangeListener listener) {
  18.111 -        if (listener == null) {
  18.112 -            return;
  18.113 -        }
  18.114 -        if (listener instanceof VetoableChangeListenerProxy) {
  18.115 -            VetoableChangeListenerProxy proxy =
  18.116 -                    (VetoableChangeListenerProxy)listener;
  18.117 -            // Call two argument add method.
  18.118 -            addVetoableChangeListener(proxy.getPropertyName(),
  18.119 -                                      proxy.getListener());
  18.120 -        } else {
  18.121 -            this.map.add(null, listener);
  18.122 -        }
  18.123 -    }
  18.124 -
  18.125 -    /**
  18.126 -     * Remove a VetoableChangeListener from the listener list.
  18.127 -     * This removes a VetoableChangeListener that was registered
  18.128 -     * for all properties.
  18.129 -     * If <code>listener</code> was added more than once to the same event
  18.130 -     * source, it will be notified one less time after being removed.
  18.131 -     * If <code>listener</code> is null, or was never added, no exception is
  18.132 -     * thrown and no action is taken.
  18.133 -     *
  18.134 -     * @param listener  The VetoableChangeListener to be removed
  18.135 -     */
  18.136 -    public void removeVetoableChangeListener(VetoableChangeListener listener) {
  18.137 -        if (listener == null) {
  18.138 -            return;
  18.139 -        }
  18.140 -        if (listener instanceof VetoableChangeListenerProxy) {
  18.141 -            VetoableChangeListenerProxy proxy =
  18.142 -                    (VetoableChangeListenerProxy)listener;
  18.143 -            // Call two argument remove method.
  18.144 -            removeVetoableChangeListener(proxy.getPropertyName(),
  18.145 -                                         proxy.getListener());
  18.146 -        } else {
  18.147 -            this.map.remove(null, listener);
  18.148 -        }
  18.149 -    }
  18.150 -
  18.151 -    /**
  18.152 -     * Returns an array of all the listeners that were added to the
  18.153 -     * VetoableChangeSupport object with addVetoableChangeListener().
  18.154 -     * <p>
  18.155 -     * If some listeners have been added with a named property, then
  18.156 -     * the returned array will be a mixture of VetoableChangeListeners
  18.157 -     * and <code>VetoableChangeListenerProxy</code>s. If the calling
  18.158 -     * method is interested in distinguishing the listeners then it must
  18.159 -     * test each element to see if it's a
  18.160 -     * <code>VetoableChangeListenerProxy</code>, perform the cast, and examine
  18.161 -     * the parameter.
  18.162 -     *
  18.163 -     * <pre>
  18.164 -     * VetoableChangeListener[] listeners = bean.getVetoableChangeListeners();
  18.165 -     * for (int i = 0; i < listeners.length; i++) {
  18.166 -     *        if (listeners[i] instanceof VetoableChangeListenerProxy) {
  18.167 -     *     VetoableChangeListenerProxy proxy =
  18.168 -     *                    (VetoableChangeListenerProxy)listeners[i];
  18.169 -     *     if (proxy.getPropertyName().equals("foo")) {
  18.170 -     *       // proxy is a VetoableChangeListener which was associated
  18.171 -     *       // with the property named "foo"
  18.172 -     *     }
  18.173 -     *   }
  18.174 -     * }
  18.175 -     *</pre>
  18.176 -     *
  18.177 -     * @see VetoableChangeListenerProxy
  18.178 -     * @return all of the <code>VetoableChangeListeners</code> added or an
  18.179 -     *         empty array if no listeners have been added
  18.180 -     * @since 1.4
  18.181 -     */
  18.182 -    public VetoableChangeListener[] getVetoableChangeListeners(){
  18.183 -        return this.map.getListeners();
  18.184 -    }
  18.185 -
  18.186 -    /**
  18.187 -     * Add a VetoableChangeListener for a specific property.  The listener
  18.188 -     * will be invoked only when a call on fireVetoableChange names that
  18.189 -     * specific property.
  18.190 -     * The same listener object may be added more than once.  For each
  18.191 -     * property,  the listener will be invoked the number of times it was added
  18.192 -     * for that property.
  18.193 -     * If <code>propertyName</code> or <code>listener</code> is null, no
  18.194 -     * exception is thrown and no action is taken.
  18.195 -     *
  18.196 -     * @param propertyName  The name of the property to listen on.
  18.197 -     * @param listener  The VetoableChangeListener to be added
  18.198 -     */
  18.199 -    public void addVetoableChangeListener(
  18.200 -                                String propertyName,
  18.201 -                VetoableChangeListener listener) {
  18.202 -        if (listener == null || propertyName == null) {
  18.203 -            return;
  18.204 -        }
  18.205 -        listener = this.map.extract(listener);
  18.206 -        if (listener != null) {
  18.207 -            this.map.add(propertyName, listener);
  18.208 -        }
  18.209 -    }
  18.210 -
  18.211 -    /**
  18.212 -     * Remove a VetoableChangeListener for a specific property.
  18.213 -     * If <code>listener</code> was added more than once to the same event
  18.214 -     * source for the specified property, it will be notified one less time
  18.215 -     * after being removed.
  18.216 -     * If <code>propertyName</code> is null, no exception is thrown and no
  18.217 -     * action is taken.
  18.218 -     * If <code>listener</code> is null, or was never added for the specified
  18.219 -     * property, no exception is thrown and no action is taken.
  18.220 -     *
  18.221 -     * @param propertyName  The name of the property that was listened on.
  18.222 -     * @param listener  The VetoableChangeListener to be removed
  18.223 -     */
  18.224 -    public void removeVetoableChangeListener(
  18.225 -                                String propertyName,
  18.226 -                VetoableChangeListener listener) {
  18.227 -        if (listener == null || propertyName == null) {
  18.228 -            return;
  18.229 -        }
  18.230 -        listener = this.map.extract(listener);
  18.231 -        if (listener != null) {
  18.232 -            this.map.remove(propertyName, listener);
  18.233 -        }
  18.234 -    }
  18.235 -
  18.236 -    /**
  18.237 -     * Returns an array of all the listeners which have been associated
  18.238 -     * with the named property.
  18.239 -     *
  18.240 -     * @param propertyName  The name of the property being listened to
  18.241 -     * @return all the <code>VetoableChangeListeners</code> associated with
  18.242 -     *         the named property.  If no such listeners have been added,
  18.243 -     *         or if <code>propertyName</code> is null, an empty array is
  18.244 -     *         returned.
  18.245 -     * @since 1.4
  18.246 -     */
  18.247 -    public VetoableChangeListener[] getVetoableChangeListeners(String propertyName) {
  18.248 -        return this.map.getListeners(propertyName);
  18.249 -    }
  18.250 -
  18.251 -    /**
  18.252 -     * Reports a constrained property update to listeners
  18.253 -     * that have been registered to track updates of
  18.254 -     * all properties or a property with the specified name.
  18.255 -     * <p>
  18.256 -     * Any listener can throw a {@code PropertyVetoException} to veto the update.
  18.257 -     * If one of the listeners vetoes the update, this method passes
  18.258 -     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
  18.259 -     * to all listeners that already confirmed this update
  18.260 -     * and throws the {@code PropertyVetoException} again.
  18.261 -     * <p>
  18.262 -     * No event is fired if old and new values are equal and non-null.
  18.263 -     * <p>
  18.264 -     * This is merely a convenience wrapper around the more general
  18.265 -     * {@link #fireVetoableChange(PropertyChangeEvent)} method.
  18.266 -     *
  18.267 -     * @param propertyName  the programmatic name of the property that is about to change
  18.268 -     * @param oldValue      the old value of the property
  18.269 -     * @param newValue      the new value of the property
  18.270 -     * @throws PropertyVetoException if one of listeners vetoes the property update
  18.271 -     */
  18.272 -    public void fireVetoableChange(String propertyName, Object oldValue, Object newValue)
  18.273 -            throws PropertyVetoException {
  18.274 -        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
  18.275 -            fireVetoableChange(new PropertyChangeEvent(this.source, propertyName, oldValue, newValue));
  18.276 -        }
  18.277 -    }
  18.278 -
  18.279 -    /**
  18.280 -     * Reports an integer constrained property update to listeners
  18.281 -     * that have been registered to track updates of
  18.282 -     * all properties or a property with the specified name.
  18.283 -     * <p>
  18.284 -     * Any listener can throw a {@code PropertyVetoException} to veto the update.
  18.285 -     * If one of the listeners vetoes the update, this method passes
  18.286 -     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
  18.287 -     * to all listeners that already confirmed this update
  18.288 -     * and throws the {@code PropertyVetoException} again.
  18.289 -     * <p>
  18.290 -     * No event is fired if old and new values are equal.
  18.291 -     * <p>
  18.292 -     * This is merely a convenience wrapper around the more general
  18.293 -     * {@link #fireVetoableChange(String, Object, Object)} method.
  18.294 -     *
  18.295 -     * @param propertyName  the programmatic name of the property that is about to change
  18.296 -     * @param oldValue      the old value of the property
  18.297 -     * @param newValue      the new value of the property
  18.298 -     * @throws PropertyVetoException if one of listeners vetoes the property update
  18.299 -     */
  18.300 -    public void fireVetoableChange(String propertyName, int oldValue, int newValue)
  18.301 -            throws PropertyVetoException {
  18.302 -        if (oldValue != newValue) {
  18.303 -            fireVetoableChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
  18.304 -        }
  18.305 -    }
  18.306 -
  18.307 -    /**
  18.308 -     * Reports a boolean constrained property update to listeners
  18.309 -     * that have been registered to track updates of
  18.310 -     * all properties or a property with the specified name.
  18.311 -     * <p>
  18.312 -     * Any listener can throw a {@code PropertyVetoException} to veto the update.
  18.313 -     * If one of the listeners vetoes the update, this method passes
  18.314 -     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
  18.315 -     * to all listeners that already confirmed this update
  18.316 -     * and throws the {@code PropertyVetoException} again.
  18.317 -     * <p>
  18.318 -     * No event is fired if old and new values are equal.
  18.319 -     * <p>
  18.320 -     * This is merely a convenience wrapper around the more general
  18.321 -     * {@link #fireVetoableChange(String, Object, Object)} method.
  18.322 -     *
  18.323 -     * @param propertyName  the programmatic name of the property that is about to change
  18.324 -     * @param oldValue      the old value of the property
  18.325 -     * @param newValue      the new value of the property
  18.326 -     * @throws PropertyVetoException if one of listeners vetoes the property update
  18.327 -     */
  18.328 -    public void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue)
  18.329 -            throws PropertyVetoException {
  18.330 -        if (oldValue != newValue) {
  18.331 -            fireVetoableChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
  18.332 -        }
  18.333 -    }
  18.334 -
  18.335 -    /**
  18.336 -     * Fires a property change event to listeners
  18.337 -     * that have been registered to track updates of
  18.338 -     * all properties or a property with the specified name.
  18.339 -     * <p>
  18.340 -     * Any listener can throw a {@code PropertyVetoException} to veto the update.
  18.341 -     * If one of the listeners vetoes the update, this method passes
  18.342 -     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
  18.343 -     * to all listeners that already confirmed this update
  18.344 -     * and throws the {@code PropertyVetoException} again.
  18.345 -     * <p>
  18.346 -     * No event is fired if the given event's old and new values are equal and non-null.
  18.347 -     *
  18.348 -     * @param event  the {@code PropertyChangeEvent} to be fired
  18.349 -     * @throws PropertyVetoException if one of listeners vetoes the property update
  18.350 -     */
  18.351 -    public void fireVetoableChange(PropertyChangeEvent event)
  18.352 -            throws PropertyVetoException {
  18.353 -        Object oldValue = event.getOldValue();
  18.354 -        Object newValue = event.getNewValue();
  18.355 -        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
  18.356 -            String name = event.getPropertyName();
  18.357 -
  18.358 -            VetoableChangeListener[] common = this.map.get(null);
  18.359 -            VetoableChangeListener[] named = (name != null)
  18.360 -                        ? this.map.get(name)
  18.361 -                        : null;
  18.362 -
  18.363 -            VetoableChangeListener[] listeners;
  18.364 -            if (common == null) {
  18.365 -                listeners = named;
  18.366 -            }
  18.367 -            else if (named == null) {
  18.368 -                listeners = common;
  18.369 -            }
  18.370 -            else {
  18.371 -                listeners = new VetoableChangeListener[common.length + named.length];
  18.372 -                System.arraycopy(common, 0, listeners, 0, common.length);
  18.373 -                System.arraycopy(named, 0, listeners, common.length, named.length);
  18.374 -            }
  18.375 -            if (listeners != null) {
  18.376 -                int current = 0;
  18.377 -                try {
  18.378 -                    while (current < listeners.length) {
  18.379 -                        listeners[current].vetoableChange(event);
  18.380 -                        current++;
  18.381 -                    }
  18.382 -                }
  18.383 -                catch (PropertyVetoException veto) {
  18.384 -                    event = new PropertyChangeEvent(this.source, name, newValue, oldValue);
  18.385 -                    for (int i = 0; i < current; i++) {
  18.386 -                        try {
  18.387 -                            listeners[i].vetoableChange(event);
  18.388 -                        }
  18.389 -                        catch (PropertyVetoException exception) {
  18.390 -                            // ignore exceptions that occur during rolling back
  18.391 -                        }
  18.392 -                    }
  18.393 -                    throw veto; // rethrow the veto exception
  18.394 -                }
  18.395 -            }
  18.396 -        }
  18.397 -    }
  18.398 -
  18.399 -    /**
  18.400 -     * Check if there are any listeners for a specific property, including
  18.401 -     * those registered on all properties.  If <code>propertyName</code>
  18.402 -     * is null, only check for listeners registered on all properties.
  18.403 -     *
  18.404 -     * @param propertyName  the property name.
  18.405 -     * @return true if there are one or more listeners for the given property
  18.406 -     */
  18.407 -    public boolean hasListeners(String propertyName) {
  18.408 -        return this.map.hasListeners(propertyName);
  18.409 -    }
  18.410 -
  18.411 -    /**
  18.412 -     * @serialData Null terminated list of <code>VetoableChangeListeners</code>.
  18.413 -     * <p>
  18.414 -     * At serialization time we skip non-serializable listeners and
  18.415 -     * only serialize the serializable listeners.
  18.416 -     */
  18.417 -    private void writeObject(ObjectOutputStream s) throws IOException {
  18.418 -        Hashtable<String, VetoableChangeSupport> children = null;
  18.419 -        VetoableChangeListener[] listeners = null;
  18.420 -        synchronized (this.map) {
  18.421 -            for (Entry<String, VetoableChangeListener[]> entry : this.map.getEntries()) {
  18.422 -                String property = entry.getKey();
  18.423 -                if (property == null) {
  18.424 -                    listeners = entry.getValue();
  18.425 -                } else {
  18.426 -                    if (children == null) {
  18.427 -                        children = new Hashtable<String, VetoableChangeSupport>();
  18.428 -                    }
  18.429 -                    VetoableChangeSupport vcs = new VetoableChangeSupport(this.source);
  18.430 -                    vcs.map.set(null, entry.getValue());
  18.431 -                    children.put(property, vcs);
  18.432 -                }
  18.433 -            }
  18.434 -        }
  18.435 -        ObjectOutputStream.PutField fields = s.putFields();
  18.436 -        fields.put("children", children);
  18.437 -        fields.put("source", this.source);
  18.438 -        fields.put("vetoableChangeSupportSerializedDataVersion", 2);
  18.439 -        s.writeFields();
  18.440 -
  18.441 -        if (listeners != null) {
  18.442 -            for (VetoableChangeListener l : listeners) {
  18.443 -                if (l instanceof Serializable) {
  18.444 -                    s.writeObject(l);
  18.445 -                }
  18.446 -            }
  18.447 -        }
  18.448 -        s.writeObject(null);
  18.449 -    }
  18.450 -
  18.451 -    private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
  18.452 -        this.map = new VetoableChangeListenerMap();
  18.453 -
  18.454 -        ObjectInputStream.GetField fields = s.readFields();
  18.455 -
  18.456 -        Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>) fields.get("children", null);
  18.457 -        this.source = fields.get("source", null);
  18.458 -        fields.get("vetoableChangeSupportSerializedDataVersion", 2);
  18.459 -
  18.460 -        Object listenerOrNull;
  18.461 -        while (null != (listenerOrNull = s.readObject())) {
  18.462 -            this.map.add(null, (VetoableChangeListener)listenerOrNull);
  18.463 -        }
  18.464 -        if (children != null) {
  18.465 -            for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
  18.466 -                for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
  18.467 -                    this.map.add(entry.getKey(), listener);
  18.468 -                }
  18.469 -            }
  18.470 -        }
  18.471 -    }
  18.472 -
  18.473 -    /**
  18.474 -     * The object to be provided as the "source" for any generated events.
  18.475 -     */
  18.476 -    private Object source;
  18.477 -
  18.478 -    /**
  18.479 -     * @serialField children                                   Hashtable
  18.480 -     * @serialField source                                     Object
  18.481 -     * @serialField vetoableChangeSupportSerializedDataVersion int
  18.482 -     */
  18.483 -    private static final ObjectStreamField[] serialPersistentFields = {
  18.484 -            new ObjectStreamField("children", Hashtable.class),
  18.485 -            new ObjectStreamField("source", Object.class),
  18.486 -            new ObjectStreamField("vetoableChangeSupportSerializedDataVersion", Integer.TYPE)
  18.487 -    };
  18.488 -
  18.489 -    /**
  18.490 -     * Serialization version ID, so we're compatible with JDK 1.1
  18.491 -     */
  18.492 -    static final long serialVersionUID = -5090210921595982017L;
  18.493 -
  18.494 -    /**
  18.495 -     * This is a {@link ChangeListenerMap ChangeListenerMap} implementation
  18.496 -     * that works with {@link VetoableChangeListener VetoableChangeListener} objects.
  18.497 -     */
  18.498 -    private static final class VetoableChangeListenerMap extends ChangeListenerMap<VetoableChangeListener> {
  18.499 -        private static final VetoableChangeListener[] EMPTY = {};
  18.500 -
  18.501 -        /**
  18.502 -         * Creates an array of {@link VetoableChangeListener VetoableChangeListener} objects.
  18.503 -         * This method uses the same instance of the empty array
  18.504 -         * when {@code length} equals {@code 0}.
  18.505 -         *
  18.506 -         * @param length  the array length
  18.507 -         * @return        an array with specified length
  18.508 -         */
  18.509 -        @Override
  18.510 -        protected VetoableChangeListener[] newArray(int length) {
  18.511 -            return (0 < length)
  18.512 -                    ? new VetoableChangeListener[length]
  18.513 -                    : EMPTY;
  18.514 -        }
  18.515 -
  18.516 -        /**
  18.517 -         * Creates a {@link VetoableChangeListenerProxy VetoableChangeListenerProxy}
  18.518 -         * object for the specified property.
  18.519 -         *
  18.520 -         * @param name      the name of the property to listen on
  18.521 -         * @param listener  the listener to process events
  18.522 -         * @return          a {@code VetoableChangeListenerProxy} object
  18.523 -         */
  18.524 -        @Override
  18.525 -        protected VetoableChangeListener newProxy(String name, VetoableChangeListener listener) {
  18.526 -            return new VetoableChangeListenerProxy(name, listener);
  18.527 -        }
  18.528 -    }
  18.529 -}
    19.1 --- a/emul/compact/src/main/java/java/io/Bits.java	Mon Feb 25 19:00:08 2013 +0100
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,123 +0,0 @@
    19.4 -/*
    19.5 - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
    19.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    19.7 - *
    19.8 - * This code is free software; you can redistribute it and/or modify it
    19.9 - * under the terms of the GNU General Public License version 2 only, as
   19.10 - * published by the Free Software Foundation.  Oracle designates this
   19.11 - * particular file as subject to the "Classpath" exception as provided
   19.12 - * by Oracle in the LICENSE file that accompanied this code.
   19.13 - *
   19.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   19.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   19.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   19.17 - * version 2 for more details (a copy is included in the LICENSE file that
   19.18 - * accompanied this code).
   19.19 - *
   19.20 - * You should have received a copy of the GNU General Public License version
   19.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   19.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   19.23 - *
   19.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   19.25 - * or visit www.oracle.com if you need additional information or have any
   19.26 - * questions.
   19.27 - */
   19.28 -
   19.29 -package java.io;
   19.30 -
   19.31 -/**
   19.32 - * Utility methods for packing/unpacking primitive values in/out of byte arrays
   19.33 - * using big-endian byte ordering.
   19.34 - */
   19.35 -class Bits {
   19.36 -
   19.37 -    /*
   19.38 -     * Methods for unpacking primitive values from byte arrays starting at
   19.39 -     * given offsets.
   19.40 -     */
   19.41 -
   19.42 -    static boolean getBoolean(byte[] b, int off) {
   19.43 -        return b[off] != 0;
   19.44 -    }
   19.45 -
   19.46 -    static char getChar(byte[] b, int off) {
   19.47 -        return (char) ((b[off + 1] & 0xFF) +
   19.48 -                       (b[off] << 8));
   19.49 -    }
   19.50 -
   19.51 -    static short getShort(byte[] b, int off) {
   19.52 -        return (short) ((b[off + 1] & 0xFF) +
   19.53 -                        (b[off] << 8));
   19.54 -    }
   19.55 -
   19.56 -    static int getInt(byte[] b, int off) {
   19.57 -        return ((b[off + 3] & 0xFF)      ) +
   19.58 -               ((b[off + 2] & 0xFF) <<  8) +
   19.59 -               ((b[off + 1] & 0xFF) << 16) +
   19.60 -               ((b[off    ]       ) << 24);
   19.61 -    }
   19.62 -
   19.63 -    static float getFloat(byte[] b, int off) {
   19.64 -        return Float.intBitsToFloat(getInt(b, off));
   19.65 -    }
   19.66 -
   19.67 -    static long getLong(byte[] b, int off) {
   19.68 -        return ((b[off + 7] & 0xFFL)      ) +
   19.69 -               ((b[off + 6] & 0xFFL) <<  8) +
   19.70 -               ((b[off + 5] & 0xFFL) << 16) +
   19.71 -               ((b[off + 4] & 0xFFL) << 24) +
   19.72 -               ((b[off + 3] & 0xFFL) << 32) +
   19.73 -               ((b[off + 2] & 0xFFL) << 40) +
   19.74 -               ((b[off + 1] & 0xFFL) << 48) +
   19.75 -               (((long) b[off])      << 56);
   19.76 -    }
   19.77 -
   19.78 -    static double getDouble(byte[] b, int off) {
   19.79 -        return Double.longBitsToDouble(getLong(b, off));
   19.80 -    }
   19.81 -
   19.82 -    /*
   19.83 -     * Methods for packing primitive values into byte arrays starting at given
   19.84 -     * offsets.
   19.85 -     */
   19.86 -
   19.87 -    static void putBoolean(byte[] b, int off, boolean val) {
   19.88 -        b[off] = (byte) (val ? 1 : 0);
   19.89 -    }
   19.90 -
   19.91 -    static void putChar(byte[] b, int off, char val) {
   19.92 -        b[off + 1] = (byte) (val      );
   19.93 -        b[off    ] = (byte) (val >>> 8);
   19.94 -    }
   19.95 -
   19.96 -    static void putShort(byte[] b, int off, short val) {
   19.97 -        b[off + 1] = (byte) (val      );
   19.98 -        b[off    ] = (byte) (val >>> 8);
   19.99 -    }
  19.100 -
  19.101 -    static void putInt(byte[] b, int off, int val) {
  19.102 -        b[off + 3] = (byte) (val       );
  19.103 -        b[off + 2] = (byte) (val >>>  8);
  19.104 -        b[off + 1] = (byte) (val >>> 16);
  19.105 -        b[off    ] = (byte) (val >>> 24);
  19.106 -    }
  19.107 -
  19.108 -    static void putFloat(byte[] b, int off, float val) {
  19.109 -        putInt(b, off,  Float.floatToIntBits(val));
  19.110 -    }
  19.111 -
  19.112 -    static void putLong(byte[] b, int off, long val) {
  19.113 -        b[off + 7] = (byte) (val       );
  19.114 -        b[off + 6] = (byte) (val >>>  8);
  19.115 -        b[off + 5] = (byte) (val >>> 16);
  19.116 -        b[off + 4] = (byte) (val >>> 24);
  19.117 -        b[off + 3] = (byte) (val >>> 32);
  19.118 -        b[off + 2] = (byte) (val >>> 40);
  19.119 -        b[off + 1] = (byte) (val >>> 48);
  19.120 -        b[off    ] = (byte) (val >>> 56);
  19.121 -    }
  19.122 -
  19.123 -    static void putDouble(byte[] b, int off, double val) {
  19.124 -        putLong(b, off, Double.doubleToLongBits(val));
  19.125 -    }
  19.126 -}
    20.1 --- a/emul/compact/src/main/java/java/io/BufferedOutputStream.java	Mon Feb 25 19:00:08 2013 +0100
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,143 +0,0 @@
    20.4 -/*
    20.5 - * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
    20.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    20.7 - *
    20.8 - * This code is free software; you can redistribute it and/or modify it
    20.9 - * under the terms of the GNU General Public License version 2 only, as
   20.10 - * published by the Free Software Foundation.  Oracle designates this
   20.11 - * particular file as subject to the "Classpath" exception as provided
   20.12 - * by Oracle in the LICENSE file that accompanied this code.
   20.13 - *
   20.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   20.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   20.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   20.17 - * version 2 for more details (a copy is included in the LICENSE file that
   20.18 - * accompanied this code).
   20.19 - *
   20.20 - * You should have received a copy of the GNU General Public License version
   20.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   20.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20.23 - *
   20.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20.25 - * or visit www.oracle.com if you need additional information or have any
   20.26 - * questions.
   20.27 - */
   20.28 -
   20.29 -package java.io;
   20.30 -
   20.31 -/**
   20.32 - * The class implements a buffered output stream. By setting up such
   20.33 - * an output stream, an application can write bytes to the underlying
   20.34 - * output stream without necessarily causing a call to the underlying
   20.35 - * system for each byte written.
   20.36 - *
   20.37 - * @author  Arthur van Hoff
   20.38 - * @since   JDK1.0
   20.39 - */
   20.40 -public
   20.41 -class BufferedOutputStream extends FilterOutputStream {
   20.42 -    /**
   20.43 -     * The internal buffer where data is stored.
   20.44 -     */
   20.45 -    protected byte buf[];
   20.46 -
   20.47 -    /**
   20.48 -     * The number of valid bytes in the buffer. This value is always
   20.49 -     * in the range <tt>0</tt> through <tt>buf.length</tt>; elements
   20.50 -     * <tt>buf[0]</tt> through <tt>buf[count-1]</tt> contain valid
   20.51 -     * byte data.
   20.52 -     */
   20.53 -    protected int count;
   20.54 -
   20.55 -    /**
   20.56 -     * Creates a new buffered output stream to write data to the
   20.57 -     * specified underlying output stream.
   20.58 -     *
   20.59 -     * @param   out   the underlying output stream.
   20.60 -     */
   20.61 -    public BufferedOutputStream(OutputStream out) {
   20.62 -        this(out, 8192);
   20.63 -    }
   20.64 -
   20.65 -    /**
   20.66 -     * Creates a new buffered output stream to write data to the
   20.67 -     * specified underlying output stream with the specified buffer
   20.68 -     * size.
   20.69 -     *
   20.70 -     * @param   out    the underlying output stream.
   20.71 -     * @param   size   the buffer size.
   20.72 -     * @exception IllegalArgumentException if size &lt;= 0.
   20.73 -     */
   20.74 -    public BufferedOutputStream(OutputStream out, int size) {
   20.75 -        super(out);
   20.76 -        if (size <= 0) {
   20.77 -            throw new IllegalArgumentException("Buffer size <= 0");
   20.78 -        }
   20.79 -        buf = new byte[size];
   20.80 -    }
   20.81 -
   20.82 -    /** Flush the internal buffer */
   20.83 -    private void flushBuffer() throws IOException {
   20.84 -        if (count > 0) {
   20.85 -            out.write(buf, 0, count);
   20.86 -            count = 0;
   20.87 -        }
   20.88 -    }
   20.89 -
   20.90 -    /**
   20.91 -     * Writes the specified byte to this buffered output stream.
   20.92 -     *
   20.93 -     * @param      b   the byte to be written.
   20.94 -     * @exception  IOException  if an I/O error occurs.
   20.95 -     */
   20.96 -    public synchronized void write(int b) throws IOException {
   20.97 -        if (count >= buf.length) {
   20.98 -            flushBuffer();
   20.99 -        }
  20.100 -        buf[count++] = (byte)b;
  20.101 -    }
  20.102 -
  20.103 -    /**
  20.104 -     * Writes <code>len</code> bytes from the specified byte array
  20.105 -     * starting at offset <code>off</code> to this buffered output stream.
  20.106 -     *
  20.107 -     * <p> Ordinarily this method stores bytes from the given array into this
  20.108 -     * stream's buffer, flushing the buffer to the underlying output stream as
  20.109 -     * needed.  If the requested length is at least as large as this stream's
  20.110 -     * buffer, however, then this method will flush the buffer and write the
  20.111 -     * bytes directly to the underlying output stream.  Thus redundant
  20.112 -     * <code>BufferedOutputStream</code>s will not copy data unnecessarily.
  20.113 -     *
  20.114 -     * @param      b     the data.
  20.115 -     * @param      off   the start offset in the data.
  20.116 -     * @param      len   the number of bytes to write.
  20.117 -     * @exception  IOException  if an I/O error occurs.
  20.118 -     */
  20.119 -    public synchronized void write(byte b[], int off, int len) throws IOException {
  20.120 -        if (len >= buf.length) {
  20.121 -            /* If the request length exceeds the size of the output buffer,
  20.122 -               flush the output buffer and then write the data directly.
  20.123 -               In this way buffered streams will cascade harmlessly. */
  20.124 -            flushBuffer();
  20.125 -            out.write(b, off, len);
  20.126 -            return;
  20.127 -        }
  20.128 -        if (len > buf.length - count) {
  20.129 -            flushBuffer();
  20.130 -        }
  20.131 -        System.arraycopy(b, off, buf, count, len);
  20.132 -        count += len;
  20.133 -    }
  20.134 -
  20.135 -    /**
  20.136 -     * Flushes this buffered output stream. This forces any buffered
  20.137 -     * output bytes to be written out to the underlying output stream.
  20.138 -     *
  20.139 -     * @exception  IOException  if an I/O error occurs.
  20.140 -     * @see        java.io.FilterOutputStream#out
  20.141 -     */
  20.142 -    public synchronized void flush() throws IOException {
  20.143 -        flushBuffer();
  20.144 -        out.flush();
  20.145 -    }
  20.146 -}
    21.1 --- a/emul/compact/src/main/java/java/io/BufferedReader.java	Mon Feb 25 19:00:08 2013 +0100
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,523 +0,0 @@
    21.4 -/*
    21.5 - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
    21.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    21.7 - *
    21.8 - * This code is free software; you can redistribute it and/or modify it
    21.9 - * under the terms of the GNU General Public License version 2 only, as
   21.10 - * published by the Free Software Foundation.  Oracle designates this
   21.11 - * particular file as subject to the "Classpath" exception as provided
   21.12 - * by Oracle in the LICENSE file that accompanied this code.
   21.13 - *
   21.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   21.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   21.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   21.17 - * version 2 for more details (a copy is included in the LICENSE file that
   21.18 - * accompanied this code).
   21.19 - *
   21.20 - * You should have received a copy of the GNU General Public License version
   21.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   21.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   21.23 - *
   21.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   21.25 - * or visit www.oracle.com if you need additional information or have any
   21.26 - * questions.
   21.27 - */
   21.28 -
   21.29 -package java.io;
   21.30 -
   21.31 -
   21.32 -
   21.33 -/**
   21.34 - * Reads text from a character-input stream, buffering characters so as to
   21.35 - * provide for the efficient reading of characters, arrays, and lines.
   21.36 - *
   21.37 - * <p> The buffer size may be specified, or the default size may be used.  The
   21.38 - * default is large enough for most purposes.
   21.39 - *
   21.40 - * <p> In general, each read request made of a Reader causes a corresponding
   21.41 - * read request to be made of the underlying character or byte stream.  It is
   21.42 - * therefore advisable to wrap a BufferedReader around any Reader whose read()
   21.43 - * operations may be costly, such as FileReaders and InputStreamReaders.  For
   21.44 - * example,
   21.45 - *
   21.46 - * <pre>
   21.47 - * BufferedReader in
   21.48 - *   = new BufferedReader(new FileReader("foo.in"));
   21.49 - * </pre>
   21.50 - *
   21.51 - * will buffer the input from the specified file.  Without buffering, each
   21.52 - * invocation of read() or readLine() could cause bytes to be read from the
   21.53 - * file, converted into characters, and then returned, which can be very
   21.54 - * inefficient.
   21.55 - *
   21.56 - * <p> Programs that use DataInputStreams for textual input can be localized by
   21.57 - * replacing each DataInputStream with an appropriate BufferedReader.
   21.58 - *
   21.59 - * @see FileReader
   21.60 - * @see InputStreamReader
   21.61 - * @see java.nio.file.Files#newBufferedReader
   21.62 - *
   21.63 - * @author      Mark Reinhold
   21.64 - * @since       JDK1.1
   21.65 - */
   21.66 -
   21.67 -public class BufferedReader extends Reader {
   21.68 -
   21.69 -    private Reader in;
   21.70 -
   21.71 -    private char cb[];
   21.72 -    private int nChars, nextChar;
   21.73 -
   21.74 -    private static final int INVALIDATED = -2;
   21.75 -    private static final int UNMARKED = -1;
   21.76 -    private int markedChar = UNMARKED;
   21.77 -    private int readAheadLimit = 0; /* Valid only when markedChar > 0 */
   21.78 -
   21.79 -    /** If the next character is a line feed, skip it */
   21.80 -    private boolean skipLF = false;
   21.81 -
   21.82 -    /** The skipLF flag when the mark was set */
   21.83 -    private boolean markedSkipLF = false;
   21.84 -
   21.85 -    private static int defaultCharBufferSize = 8192;
   21.86 -    private static int defaultExpectedLineLength = 80;
   21.87 -
   21.88 -    /**
   21.89 -     * Creates a buffering character-input stream that uses an input buffer of
   21.90 -     * the specified size.
   21.91 -     *
   21.92 -     * @param  in   A Reader
   21.93 -     * @param  sz   Input-buffer size
   21.94 -     *
   21.95 -     * @exception  IllegalArgumentException  If sz is <= 0
   21.96 -     */
   21.97 -    public BufferedReader(Reader in, int sz) {
   21.98 -        super(in);
   21.99 -        if (sz <= 0)
  21.100 -            throw new IllegalArgumentException("Buffer size <= 0");
  21.101 -        this.in = in;
  21.102 -        cb = new char[sz];
  21.103 -        nextChar = nChars = 0;
  21.104 -    }
  21.105 -
  21.106 -    /**
  21.107 -     * Creates a buffering character-input stream that uses a default-sized
  21.108 -     * input buffer.
  21.109 -     *
  21.110 -     * @param  in   A Reader
  21.111 -     */
  21.112 -    public BufferedReader(Reader in) {
  21.113 -        this(in, defaultCharBufferSize);
  21.114 -    }
  21.115 -
  21.116 -    /** Checks to make sure that the stream has not been closed */
  21.117 -    private void ensureOpen() throws IOException {
  21.118 -        if (in == null)
  21.119 -            throw new IOException("Stream closed");
  21.120 -    }
  21.121 -
  21.122 -    /**
  21.123 -     * Fills the input buffer, taking the mark into account if it is valid.
  21.124 -     */
  21.125 -    private void fill() throws IOException {
  21.126 -        int dst;
  21.127 -        if (markedChar <= UNMARKED) {
  21.128 -            /* No mark */
  21.129 -            dst = 0;
  21.130 -        } else {
  21.131 -            /* Marked */
  21.132 -            int delta = nextChar - markedChar;
  21.133 -            if (delta >= readAheadLimit) {
  21.134 -                /* Gone past read-ahead limit: Invalidate mark */
  21.135 -                markedChar = INVALIDATED;
  21.136 -                readAheadLimit = 0;
  21.137 -                dst = 0;
  21.138 -            } else {
  21.139 -                if (readAheadLimit <= cb.length) {
  21.140 -                    /* Shuffle in the current buffer */
  21.141 -                    System.arraycopy(cb, markedChar, cb, 0, delta);
  21.142 -                    markedChar = 0;
  21.143 -                    dst = delta;
  21.144 -                } else {
  21.145 -                    /* Reallocate buffer to accommodate read-ahead limit */
  21.146 -                    char ncb[] = new char[readAheadLimit];
  21.147 -                    System.arraycopy(cb, markedChar, ncb, 0, delta);
  21.148 -                    cb = ncb;
  21.149 -                    markedChar = 0;
  21.150 -                    dst = delta;
  21.151 -                }
  21.152 -                nextChar = nChars = delta;
  21.153 -            }
  21.154 -        }
  21.155 -
  21.156 -        int n;
  21.157 -        do {
  21.158 -            n = in.read(cb, dst, cb.length - dst);
  21.159 -        } while (n == 0);
  21.160 -        if (n > 0) {
  21.161 -            nChars = dst + n;
  21.162 -            nextChar = dst;
  21.163 -        }
  21.164 -    }
  21.165 -
  21.166 -    /**
  21.167 -     * Reads a single character.
  21.168 -     *
  21.169 -     * @return The character read, as an integer in the range
  21.170 -     *         0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the
  21.171 -     *         end of the stream has been reached
  21.172 -     * @exception  IOException  If an I/O error occurs
  21.173 -     */
  21.174 -    public int read() throws IOException {
  21.175 -        synchronized (lock) {
  21.176 -            ensureOpen();
  21.177 -            for (;;) {
  21.178 -                if (nextChar >= nChars) {
  21.179 -                    fill();
  21.180 -                    if (nextChar >= nChars)
  21.181 -                        return -1;
  21.182 -                }
  21.183 -                if (skipLF) {
  21.184 -                    skipLF = false;
  21.185 -                    if (cb[nextChar] == '\n') {
  21.186 -                        nextChar++;
  21.187 -                        continue;
  21.188 -                    }
  21.189 -                }
  21.190 -                return cb[nextChar++];
  21.191 -            }
  21.192 -        }
  21.193 -    }
  21.194 -
  21.195 -    /**
  21.196 -     * Reads characters into a portion of an array, reading from the underlying
  21.197 -     * stream if necessary.
  21.198 -     */
  21.199 -    private int read1(char[] cbuf, int off, int len) throws IOException {
  21.200 -        if (nextChar >= nChars) {
  21.201 -            /* If the requested length is at least as large as the buffer, and
  21.202 -               if there is no mark/reset activity, and if line feeds are not
  21.203 -               being skipped, do not bother to copy the characters into the
  21.204 -               local buffer.  In this way buffered streams will cascade
  21.205 -               harmlessly. */
  21.206 -            if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {
  21.207 -                return in.read(cbuf, off, len);
  21.208 -            }
  21.209 -            fill();
  21.210 -        }
  21.211 -        if (nextChar >= nChars) return -1;
  21.212 -        if (skipLF) {
  21.213 -            skipLF = false;
  21.214 -            if (cb[nextChar] == '\n') {
  21.215 -                nextChar++;
  21.216 -                if (nextChar >= nChars)
  21.217 -                    fill();
  21.218 -                if (nextChar >= nChars)
  21.219 -                    return -1;
  21.220 -            }
  21.221 -        }
  21.222 -        int n = Math.min(len, nChars - nextChar);
  21.223 -        System.arraycopy(cb, nextChar, cbuf, off, n);
  21.224 -        nextChar += n;
  21.225 -        return n;
  21.226 -    }
  21.227 -
  21.228 -    /**
  21.229 -     * Reads characters into a portion of an array.
  21.230 -     *
  21.231 -     * <p> This method implements the general contract of the corresponding
  21.232 -     * <code>{@link Reader#read(char[], int, int) read}</code> method of the
  21.233 -     * <code>{@link Reader}</code> class.  As an additional convenience, it
  21.234 -     * attempts to read as many characters as possible by repeatedly invoking
  21.235 -     * the <code>read</code> method of the underlying stream.  This iterated
  21.236 -     * <code>read</code> continues until one of the following conditions becomes
  21.237 -     * true: <ul>
  21.238 -     *
  21.239 -     *   <li> The specified number of characters have been read,
  21.240 -     *
  21.241 -     *   <li> The <code>read</code> method of the underlying stream returns
  21.242 -     *   <code>-1</code>, indicating end-of-file, or
  21.243 -     *
  21.244 -     *   <li> The <code>ready</code> method of the underlying stream
  21.245 -     *   returns <code>false</code>, indicating that further input requests
  21.246 -     *   would block.
  21.247 -     *
  21.248 -     * </ul> If the first <code>read</code> on the underlying stream returns
  21.249 -     * <code>-1</code> to indicate end-of-file then this method returns
  21.250 -     * <code>-1</code>.  Otherwise this method returns the number of characters
  21.251 -     * actually read.
  21.252 -     *
  21.253 -     * <p> Subclasses of this class are encouraged, but not required, to
  21.254 -     * attempt to read as many characters as possible in the same fashion.
  21.255 -     *
  21.256 -     * <p> Ordinarily this method takes characters from this stream's character
  21.257 -     * buffer, filling it from the underlying stream as necessary.  If,
  21.258 -     * however, the buffer is empty, the mark is not valid, and the requested
  21.259 -     * length is at least as large as the buffer, then this method will read
  21.260 -     * characters directly from the underlying stream into the given array.
  21.261 -     * Thus redundant <code>BufferedReader</code>s will not copy data
  21.262 -     * unnecessarily.
  21.263 -     *
  21.264 -     * @param      cbuf  Destination buffer
  21.265 -     * @param      off   Offset at which to start storing characters
  21.266 -     * @param      len   Maximum number of characters to read
  21.267 -     *
  21.268 -     * @return     The number of characters read, or -1 if the end of the
  21.269 -     *             stream has been reached
  21.270 -     *
  21.271 -     * @exception  IOException  If an I/O error occurs
  21.272 -     */
  21.273 -    public int read(char cbuf[], int off, int len) throws IOException {
  21.274 -        synchronized (lock) {
  21.275 -            ensureOpen();
  21.276 -            if ((off < 0) || (off > cbuf.length) || (len < 0) ||
  21.277 -                ((off + len) > cbuf.length) || ((off + len) < 0)) {
  21.278 -                throw new IndexOutOfBoundsException();
  21.279 -            } else if (len == 0) {
  21.280 -                return 0;
  21.281 -            }
  21.282 -
  21.283 -            int n = read1(cbuf, off, len);
  21.284 -            if (n <= 0) return n;
  21.285 -            while ((n < len) && in.ready()) {
  21.286 -                int n1 = read1(cbuf, off + n, len - n);
  21.287 -                if (n1 <= 0) break;
  21.288 -                n += n1;
  21.289 -            }
  21.290 -            return n;
  21.291 -        }
  21.292 -    }
  21.293 -
  21.294 -    /**
  21.295 -     * Reads a line of text.  A line is considered to be terminated by any one
  21.296 -     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
  21.297 -     * followed immediately by a linefeed.
  21.298 -     *
  21.299 -     * @param      ignoreLF  If true, the next '\n' will be skipped
  21.300 -     *
  21.301 -     * @return     A String containing the contents of the line, not including
  21.302 -     *             any line-termination characters, or null if the end of the
  21.303 -     *             stream has been reached
  21.304 -     *
  21.305 -     * @see        java.io.LineNumberReader#readLine()
  21.306 -     *
  21.307 -     * @exception  IOException  If an I/O error occurs
  21.308 -     */
  21.309 -    String readLine(boolean ignoreLF) throws IOException {
  21.310 -        StringBuffer s = null;
  21.311 -        int startChar;
  21.312 -
  21.313 -        synchronized (lock) {
  21.314 -            ensureOpen();
  21.315 -            boolean omitLF = ignoreLF || skipLF;
  21.316 -
  21.317 -        bufferLoop:
  21.318 -            for (;;) {
  21.319 -
  21.320 -                if (nextChar >= nChars)
  21.321 -                    fill();
  21.322 -                if (nextChar >= nChars) { /* EOF */
  21.323 -                    if (s != null && s.length() > 0)
  21.324 -                        return s.toString();
  21.325 -                    else
  21.326 -                        return null;
  21.327 -                }
  21.328 -                boolean eol = false;
  21.329 -                char c = 0;
  21.330 -                int i;
  21.331 -
  21.332 -                /* Skip a leftover '\n', if necessary */
  21.333 -                if (omitLF && (cb[nextChar] == '\n'))
  21.334 -                    nextChar++;
  21.335 -                skipLF = false;
  21.336 -                omitLF = false;
  21.337 -
  21.338 -            charLoop:
  21.339 -                for (i = nextChar; i < nChars; i++) {
  21.340 -                    c = cb[i];
  21.341 -                    if ((c == '\n') || (c == '\r')) {
  21.342 -                        eol = true;
  21.343 -                        break charLoop;
  21.344 -                    }
  21.345 -                }
  21.346 -
  21.347 -                startChar = nextChar;
  21.348 -                nextChar = i;
  21.349 -
  21.350 -                if (eol) {
  21.351 -                    String str;
  21.352 -                    if (s == null) {
  21.353 -                        str = new String(cb, startChar, i - startChar);
  21.354 -                    } else {
  21.355 -                        s.append(cb, startChar, i - startChar);
  21.356 -                        str = s.toString();
  21.357 -                    }
  21.358 -                    nextChar++;
  21.359 -                    if (c == '\r') {
  21.360 -                        skipLF = true;
  21.361 -                    }
  21.362 -                    return str;
  21.363 -                }
  21.364 -
  21.365 -                if (s == null)
  21.366 -                    s = new StringBuffer(defaultExpectedLineLength);
  21.367 -                s.append(cb, startChar, i - startChar);
  21.368 -            }
  21.369 -        }
  21.370 -    }
  21.371 -
  21.372 -    /**
  21.373 -     * Reads a line of text.  A line is considered to be terminated by any one
  21.374 -     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
  21.375 -     * followed immediately by a linefeed.
  21.376 -     *
  21.377 -     * @return     A String containing the contents of the line, not including
  21.378 -     *             any line-termination characters, or null if the end of the
  21.379 -     *             stream has been reached
  21.380 -     *
  21.381 -     * @exception  IOException  If an I/O error occurs
  21.382 -     *
  21.383 -     * @see java.nio.file.Files#readAllLines
  21.384 -     */
  21.385 -    public String readLine() throws IOException {
  21.386 -        return readLine(false);
  21.387 -    }
  21.388 -
  21.389 -    /**
  21.390 -     * Skips characters.
  21.391 -     *
  21.392 -     * @param  n  The number of characters to skip
  21.393 -     *
  21.394 -     * @return    The number of characters actually skipped
  21.395 -     *
  21.396 -     * @exception  IllegalArgumentException  If <code>n</code> is negative.
  21.397 -     * @exception  IOException  If an I/O error occurs
  21.398 -     */
  21.399 -    public long skip(long n) throws IOException {
  21.400 -        if (n < 0L) {
  21.401 -            throw new IllegalArgumentException("skip value is negative");
  21.402 -        }
  21.403 -        synchronized (lock) {
  21.404 -            ensureOpen();
  21.405 -            long r = n;
  21.406 -            while (r > 0) {
  21.407 -                if (nextChar >= nChars)
  21.408 -                    fill();
  21.409 -                if (nextChar >= nChars) /* EOF */
  21.410 -                    break;
  21.411 -                if (skipLF) {
  21.412 -                    skipLF = false;
  21.413 -                    if (cb[nextChar] == '\n') {
  21.414 -                        nextChar++;
  21.415 -                    }
  21.416 -                }
  21.417 -                long d = nChars - nextChar;
  21.418 -                if (r <= d) {
  21.419 -                    nextChar += r;
  21.420 -                    r = 0;
  21.421 -                    break;
  21.422 -                }
  21.423 -                else {
  21.424 -                    r -= d;
  21.425 -                    nextChar = nChars;
  21.426 -                }
  21.427 -            }
  21.428 -            return n - r;
  21.429 -        }
  21.430 -    }
  21.431 -
  21.432 -    /**
  21.433 -     * Tells whether this stream is ready to be read.  A buffered character
  21.434 -     * stream is ready if the buffer is not empty, or if the underlying
  21.435 -     * character stream is ready.
  21.436 -     *
  21.437 -     * @exception  IOException  If an I/O error occurs
  21.438 -     */
  21.439 -    public boolean ready() throws IOException {
  21.440 -        synchronized (lock) {
  21.441 -            ensureOpen();
  21.442 -
  21.443 -            /*
  21.444 -             * If newline needs to be skipped and the next char to be read
  21.445 -             * is a newline character, then just skip it right away.
  21.446 -             */
  21.447 -            if (skipLF) {
  21.448 -                /* Note that in.ready() will return true if and only if the next
  21.449 -                 * read on the stream will not block.
  21.450 -                 */
  21.451 -                if (nextChar >= nChars && in.ready()) {
  21.452 -                    fill();
  21.453 -                }
  21.454 -                if (nextChar < nChars) {
  21.455 -                    if (cb[nextChar] == '\n')
  21.456 -                        nextChar++;
  21.457 -                    skipLF = false;
  21.458 -                }
  21.459 -            }
  21.460 -            return (nextChar < nChars) || in.ready();
  21.461 -        }
  21.462 -    }
  21.463 -
  21.464 -    /**
  21.465 -     * Tells whether this stream supports the mark() operation, which it does.
  21.466 -     */
  21.467 -    public boolean markSupported() {
  21.468 -        return true;
  21.469 -    }
  21.470 -
  21.471 -    /**
  21.472 -     * Marks the present position in the stream.  Subsequent calls to reset()
  21.473 -     * will attempt to reposition the stream to this point.
  21.474 -     *
  21.475 -     * @param readAheadLimit   Limit on the number of characters that may be
  21.476 -     *                         read while still preserving the mark. An attempt
  21.477 -     *                         to reset the stream after reading characters
  21.478 -     *                         up to this limit or beyond may fail.
  21.479 -     *                         A limit value larger than the size of the input
  21.480 -     *                         buffer will cause a new buffer to be allocated
  21.481 -     *                         whose size is no smaller than limit.
  21.482 -     *                         Therefore large values should be used with care.
  21.483 -     *
  21.484 -     * @exception  IllegalArgumentException  If readAheadLimit is < 0
  21.485 -     * @exception  IOException  If an I/O error occurs
  21.486 -     */
  21.487 -    public void mark(int readAheadLimit) throws IOException {
  21.488 -        if (readAheadLimit < 0) {
  21.489 -            throw new IllegalArgumentException("Read-ahead limit < 0");
  21.490 -        }
  21.491 -        synchronized (lock) {
  21.492 -            ensureOpen();
  21.493 -            this.readAheadLimit = readAheadLimit;
  21.494 -            markedChar = nextChar;
  21.495 -            markedSkipLF = skipLF;
  21.496 -        }
  21.497 -    }
  21.498 -
  21.499 -    /**
  21.500 -     * Resets the stream to the most recent mark.
  21.501 -     *
  21.502 -     * @exception  IOException  If the stream has never been marked,
  21.503 -     *                          or if the mark has been invalidated
  21.504 -     */
  21.505 -    public void reset() throws IOException {
  21.506 -        synchronized (lock) {
  21.507 -            ensureOpen();
  21.508 -            if (markedChar < 0)
  21.509 -                throw new IOException((markedChar == INVALIDATED)
  21.510 -                                      ? "Mark invalid"
  21.511 -                                      : "Stream not marked");
  21.512 -            nextChar = markedChar;
  21.513 -            skipLF = markedSkipLF;
  21.514 -        }
  21.515 -    }
  21.516 -
  21.517 -    public void close() throws IOException {
  21.518 -        synchronized (lock) {
  21.519 -            if (in == null)
  21.520 -                return;
  21.521 -            in.close();
  21.522 -            in = null;
  21.523 -            cb = null;
  21.524 -        }
  21.525 -    }
  21.526 -}
    22.1 --- a/emul/compact/src/main/java/java/io/ByteArrayOutputStream.java	Mon Feb 25 19:00:08 2013 +0100
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,272 +0,0 @@
    22.4 -/*
    22.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
    22.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    22.7 - *
    22.8 - * This code is free software; you can redistribute it and/or modify it
    22.9 - * under the terms of the GNU General Public License version 2 only, as
   22.10 - * published by the Free Software Foundation.  Oracle designates this
   22.11 - * particular file as subject to the "Classpath" exception as provided
   22.12 - * by Oracle in the LICENSE file that accompanied this code.
   22.13 - *
   22.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   22.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   22.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   22.17 - * version 2 for more details (a copy is included in the LICENSE file that
   22.18 - * accompanied this code).
   22.19 - *
   22.20 - * You should have received a copy of the GNU General Public License version
   22.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   22.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   22.23 - *
   22.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22.25 - * or visit www.oracle.com if you need additional information or have any
   22.26 - * questions.
   22.27 - */
   22.28 -
   22.29 -package java.io;
   22.30 -
   22.31 -import java.util.Arrays;
   22.32 -
   22.33 -/**
   22.34 - * This class implements an output stream in which the data is
   22.35 - * written into a byte array. The buffer automatically grows as data
   22.36 - * is written to it.
   22.37 - * The data can be retrieved using <code>toByteArray()</code> and
   22.38 - * <code>toString()</code>.
   22.39 - * <p>
   22.40 - * Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
   22.41 - * this class can be called after the stream has been closed without
   22.42 - * generating an <tt>IOException</tt>.
   22.43 - *
   22.44 - * @author  Arthur van Hoff
   22.45 - * @since   JDK1.0
   22.46 - */
   22.47 -
   22.48 -public class ByteArrayOutputStream extends OutputStream {
   22.49 -
   22.50 -    /**
   22.51 -     * The buffer where data is stored.
   22.52 -     */
   22.53 -    protected byte buf[];
   22.54 -
   22.55 -    /**
   22.56 -     * The number of valid bytes in the buffer.
   22.57 -     */
   22.58 -    protected int count;
   22.59 -
   22.60 -    /**
   22.61 -     * Creates a new byte array output stream. The buffer capacity is
   22.62 -     * initially 32 bytes, though its size increases if necessary.
   22.63 -     */
   22.64 -    public ByteArrayOutputStream() {
   22.65 -        this(32);
   22.66 -    }
   22.67 -
   22.68 -    /**
   22.69 -     * Creates a new byte array output stream, with a buffer capacity of
   22.70 -     * the specified size, in bytes.
   22.71 -     *
   22.72 -     * @param   size   the initial size.
   22.73 -     * @exception  IllegalArgumentException if size is negative.
   22.74 -     */
   22.75 -    public ByteArrayOutputStream(int size) {
   22.76 -        if (size < 0) {
   22.77 -            throw new IllegalArgumentException("Negative initial size: "
   22.78 -                                               + size);
   22.79 -        }
   22.80 -        buf = new byte[size];
   22.81 -    }
   22.82 -
   22.83 -    /**
   22.84 -     * Increases the capacity if necessary to ensure that it can hold
   22.85 -     * at least the number of elements specified by the minimum
   22.86 -     * capacity argument.
   22.87 -     *
   22.88 -     * @param minCapacity the desired minimum capacity
   22.89 -     * @throws OutOfMemoryError if {@code minCapacity < 0}.  This is
   22.90 -     * interpreted as a request for the unsatisfiably large capacity
   22.91 -     * {@code (long) Integer.MAX_VALUE + (minCapacity - Integer.MAX_VALUE)}.
   22.92 -     */
   22.93 -    private void ensureCapacity(int minCapacity) {
   22.94 -        // overflow-conscious code
   22.95 -        if (minCapacity - buf.length > 0)
   22.96 -            grow(minCapacity);
   22.97 -    }
   22.98 -
   22.99 -    /**
  22.100 -     * Increases the capacity to ensure that it can hold at least the
  22.101 -     * number of elements specified by the minimum capacity argument.
  22.102 -     *
  22.103 -     * @param minCapacity the desired minimum capacity
  22.104 -     */
  22.105 -    private void grow(int minCapacity) {
  22.106 -        // overflow-conscious code
  22.107 -        int oldCapacity = buf.length;
  22.108 -        int newCapacity = oldCapacity << 1;
  22.109 -        if (newCapacity - minCapacity < 0)
  22.110 -            newCapacity = minCapacity;
  22.111 -        if (newCapacity < 0) {
  22.112 -            if (minCapacity < 0) // overflow
  22.113 -                throw new OutOfMemoryError();
  22.114 -            newCapacity = Integer.MAX_VALUE;
  22.115 -        }
  22.116 -        buf = Arrays.copyOf(buf, newCapacity);
  22.117 -    }
  22.118 -
  22.119 -    /**
  22.120 -     * Writes the specified byte to this byte array output stream.
  22.121 -     *
  22.122 -     * @param   b   the byte to be written.
  22.123 -     */
  22.124 -    public synchronized void write(int b) {
  22.125 -        ensureCapacity(count + 1);
  22.126 -        buf[count] = (byte) b;
  22.127 -        count += 1;
  22.128 -    }
  22.129 -
  22.130 -    /**
  22.131 -     * Writes <code>len</code> bytes from the specified byte array
  22.132 -     * starting at offset <code>off</code> to this byte array output stream.
  22.133 -     *
  22.134 -     * @param   b     the data.
  22.135 -     * @param   off   the start offset in the data.
  22.136 -     * @param   len   the number of bytes to write.
  22.137 -     */
  22.138 -    public synchronized void write(byte b[], int off, int len) {
  22.139 -        if ((off < 0) || (off > b.length) || (len < 0) ||
  22.140 -            ((off + len) - b.length > 0)) {
  22.141 -            throw new IndexOutOfBoundsException();
  22.142 -        }
  22.143 -        ensureCapacity(count + len);
  22.144 -        System.arraycopy(b, off, buf, count, len);
  22.145 -        count += len;
  22.146 -    }
  22.147 -
  22.148 -    /**
  22.149 -     * Writes the complete contents of this byte array output stream to
  22.150 -     * the specified output stream argument, as if by calling the output
  22.151 -     * stream's write method using <code>out.write(buf, 0, count)</code>.
  22.152 -     *
  22.153 -     * @param      out   the output stream to which to write the data.
  22.154 -     * @exception  IOException  if an I/O error occurs.
  22.155 -     */
  22.156 -    public synchronized void writeTo(OutputStream out) throws IOException {
  22.157 -        out.write(buf, 0, count);
  22.158 -    }
  22.159 -
  22.160 -    /**
  22.161 -     * Resets the <code>count</code> field of this byte array output
  22.162 -     * stream to zero, so that all currently accumulated output in the
  22.163 -     * output stream is discarded. The output stream can be used again,
  22.164 -     * reusing the already allocated buffer space.
  22.165 -     *
  22.166 -     * @see     java.io.ByteArrayInputStream#count
  22.167 -     */
  22.168 -    public synchronized void reset() {
  22.169 -        count = 0;
  22.170 -    }
  22.171 -
  22.172 -    /**
  22.173 -     * Creates a newly allocated byte array. Its size is the current
  22.174 -     * size of this output stream and the valid contents of the buffer
  22.175 -     * have been copied into it.
  22.176 -     *
  22.177 -     * @return  the current contents of this output stream, as a byte array.
  22.178 -     * @see     java.io.ByteArrayOutputStream#size()
  22.179 -     */
  22.180 -    public synchronized byte toByteArray()[] {
  22.181 -        return Arrays.copyOf(buf, count);
  22.182 -    }
  22.183 -
  22.184 -    /**
  22.185 -     * Returns the current size of the buffer.
  22.186 -     *
  22.187 -     * @return  the value of the <code>count</code> field, which is the number
  22.188 -     *          of valid bytes in this output stream.
  22.189 -     * @see     java.io.ByteArrayOutputStream#count
  22.190 -     */
  22.191 -    public synchronized int size() {
  22.192 -        return count;
  22.193 -    }
  22.194 -
  22.195 -    /**
  22.196 -     * Converts the buffer's contents into a string decoding bytes using the
  22.197 -     * platform's default character set. The length of the new <tt>String</tt>
  22.198 -     * is a function of the character set, and hence may not be equal to the
  22.199 -     * size of the buffer.
  22.200 -     *
  22.201 -     * <p> This method always replaces malformed-input and unmappable-character
  22.202 -     * sequences with the default replacement string for the platform's
  22.203 -     * default character set. The {@linkplain java.nio.charset.CharsetDecoder}
  22.204 -     * class should be used when more control over the decoding process is
  22.205 -     * required.
  22.206 -     *
  22.207 -     * @return String decoded from the buffer's contents.
  22.208 -     * @since  JDK1.1
  22.209 -     */
  22.210 -    public synchronized String toString() {
  22.211 -        return new String(buf, 0, count);
  22.212 -    }
  22.213 -
  22.214 -    /**
  22.215 -     * Converts the buffer's contents into a string by decoding the bytes using
  22.216 -     * the specified {@link java.nio.charset.Charset charsetName}. The length of
  22.217 -     * the new <tt>String</tt> is a function of the charset, and hence may not be
  22.218 -     * equal to the length of the byte array.
  22.219 -     *
  22.220 -     * <p> This method always replaces malformed-input and unmappable-character
  22.221 -     * sequences with this charset's default replacement string. The {@link
  22.222 -     * java.nio.charset.CharsetDecoder} class should be used when more control
  22.223 -     * over the decoding process is required.
  22.224 -     *
  22.225 -     * @param  charsetName  the name of a supported
  22.226 -     *              {@linkplain java.nio.charset.Charset </code>charset<code>}
  22.227 -     * @return String decoded from the buffer's contents.
  22.228 -     * @exception  UnsupportedEncodingException
  22.229 -     *             If the named charset is not supported
  22.230 -     * @since   JDK1.1
  22.231 -     */
  22.232 -    public synchronized String toString(String charsetName)
  22.233 -        throws UnsupportedEncodingException
  22.234 -    {
  22.235 -        return new String(buf, 0, count, charsetName);
  22.236 -    }
  22.237 -
  22.238 -    /**
  22.239 -     * Creates a newly allocated string. Its size is the current size of
  22.240 -     * the output stream and the valid contents of the buffer have been
  22.241 -     * copied into it. Each character <i>c</i> in the resulting string is
  22.242 -     * constructed from the corresponding element <i>b</i> in the byte
  22.243 -     * array such that:
  22.244 -     * <blockquote><pre>
  22.245 -     *     c == (char)(((hibyte &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
  22.246 -     * </pre></blockquote>
  22.247 -     *
  22.248 -     * @deprecated This method does not properly convert bytes into characters.
  22.249 -     * As of JDK&nbsp;1.1, the preferred way to do this is via the
  22.250 -     * <code>toString(String enc)</code> method, which takes an encoding-name
  22.251 -     * argument, or the <code>toString()</code> method, which uses the
  22.252 -     * platform's default character encoding.
  22.253 -     *
  22.254 -     * @param      hibyte    the high byte of each resulting Unicode character.
  22.255 -     * @return     the current contents of the output stream, as a string.
  22.256 -     * @see        java.io.ByteArrayOutputStream#size()
  22.257 -     * @see        java.io.ByteArrayOutputStream#toString(String)
  22.258 -     * @see        java.io.ByteArrayOutputStream#toString()
  22.259 -     */
  22.260 -    @Deprecated
  22.261 -    public synchronized String toString(int hibyte) {
  22.262 -        return new String(buf, hibyte, 0, count);
  22.263 -    }
  22.264 -
  22.265 -    /**
  22.266 -     * Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
  22.267 -     * this class can be called after the stream has been closed without
  22.268 -     * generating an <tt>IOException</tt>.
  22.269 -     * <p>
  22.270 -     *
  22.271 -     */
  22.272 -    public void close() throws IOException {
  22.273 -    }
  22.274 -
  22.275 -}
    23.1 --- a/emul/compact/src/main/java/java/io/DataOutput.java	Mon Feb 25 19:00:08 2013 +0100
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,354 +0,0 @@
    23.4 -/*
    23.5 - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
    23.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 - *
    23.8 - * This code is free software; you can redistribute it and/or modify it
    23.9 - * under the terms of the GNU General Public License version 2 only, as
   23.10 - * published by the Free Software Foundation.  Oracle designates this
   23.11 - * particular file as subject to the "Classpath" exception as provided
   23.12 - * by Oracle in the LICENSE file that accompanied this code.
   23.13 - *
   23.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   23.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.17 - * version 2 for more details (a copy is included in the LICENSE file that
   23.18 - * accompanied this code).
   23.19 - *
   23.20 - * You should have received a copy of the GNU General Public License version
   23.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   23.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.23 - *
   23.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   23.25 - * or visit www.oracle.com if you need additional information or have any
   23.26 - * questions.
   23.27 - */
   23.28 -
   23.29 -package java.io;
   23.30 -
   23.31 -/**
   23.32 - * The <code>DataOutput</code> interface provides
   23.33 - * for converting data from any of the Java
   23.34 - * primitive types to a series of bytes and
   23.35 - * writing these bytes to a binary stream.
   23.36 - * There is  also a facility for converting
   23.37 - * a <code>String</code> into
   23.38 - * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
   23.39 - * format and writing the resulting series
   23.40 - * of bytes.
   23.41 - * <p>
   23.42 - * For all the methods in this interface that
   23.43 - * write bytes, it is generally true that if
   23.44 - * a byte cannot be written for any reason,
   23.45 - * an <code>IOException</code> is thrown.
   23.46 - *
   23.47 - * @author  Frank Yellin
   23.48 - * @see     java.io.DataInput
   23.49 - * @see     java.io.DataOutputStream
   23.50 - * @since   JDK1.0
   23.51 - */
   23.52 -public
   23.53 -interface DataOutput {
   23.54 -    /**
   23.55 -     * Writes to the output stream the eight
   23.56 -     * low-order bits of the argument <code>b</code>.
   23.57 -     * The 24 high-order  bits of <code>b</code>
   23.58 -     * are ignored.
   23.59 -     *
   23.60 -     * @param      b   the byte to be written.
   23.61 -     * @throws     IOException  if an I/O error occurs.
   23.62 -     */
   23.63 -    void write(int b) throws IOException;
   23.64 -
   23.65 -    /**
   23.66 -     * Writes to the output stream all the bytes in array <code>b</code>.
   23.67 -     * If <code>b</code> is <code>null</code>,
   23.68 -     * a <code>NullPointerException</code> is thrown.
   23.69 -     * If <code>b.length</code> is zero, then
   23.70 -     * no bytes are written. Otherwise, the byte
   23.71 -     * <code>b[0]</code> is written first, then
   23.72 -     * <code>b[1]</code>, and so on; the last byte
   23.73 -     * written is <code>b[b.length-1]</code>.
   23.74 -     *
   23.75 -     * @param      b   the data.
   23.76 -     * @throws     IOException  if an I/O error occurs.
   23.77 -     */
   23.78 -    void write(byte b[]) throws IOException;
   23.79 -
   23.80 -    /**
   23.81 -     * Writes <code>len</code> bytes from array
   23.82 -     * <code>b</code>, in order,  to
   23.83 -     * the output stream.  If <code>b</code>
   23.84 -     * is <code>null</code>, a <code>NullPointerException</code>
   23.85 -     * is thrown.  If <code>off</code> is negative,
   23.86 -     * or <code>len</code> is negative, or <code>off+len</code>
   23.87 -     * is greater than the length of the array
   23.88 -     * <code>b</code>, then an <code>IndexOutOfBoundsException</code>
   23.89 -     * is thrown.  If <code>len</code> is zero,
   23.90 -     * then no bytes are written. Otherwise, the
   23.91 -     * byte <code>b[off]</code> is written first,
   23.92 -     * then <code>b[off+1]</code>, and so on; the
   23.93 -     * last byte written is <code>b[off+len-1]</code>.
   23.94 -     *
   23.95 -     * @param      b     the data.
   23.96 -     * @param      off   the start offset in the data.
   23.97 -     * @param      len   the number of bytes to write.
   23.98 -     * @throws     IOException  if an I/O error occurs.
   23.99 -     */
  23.100 -    void write(byte b[], int off, int len) throws IOException;
  23.101 -
  23.102 -    /**
  23.103 -     * Writes a <code>boolean</code> value to this output stream.
  23.104 -     * If the argument <code>v</code>
  23.105 -     * is <code>true</code>, the value <code>(byte)1</code>
  23.106 -     * is written; if <code>v</code> is <code>false</code>,
  23.107 -     * the  value <code>(byte)0</code> is written.
  23.108 -     * The byte written by this method may
  23.109 -     * be read by the <code>readBoolean</code>
  23.110 -     * method of interface <code>DataInput</code>,
  23.111 -     * which will then return a <code>boolean</code>
  23.112 -     * equal to <code>v</code>.
  23.113 -     *
  23.114 -     * @param      v   the boolean to be written.
  23.115 -     * @throws     IOException  if an I/O error occurs.
  23.116 -     */
  23.117 -    void writeBoolean(boolean v) throws IOException;
  23.118 -
  23.119 -    /**
  23.120 -     * Writes to the output stream the eight low-
  23.121 -     * order bits of the argument <code>v</code>.
  23.122 -     * The 24 high-order bits of <code>v</code>
  23.123 -     * are ignored. (This means  that <code>writeByte</code>
  23.124 -     * does exactly the same thing as <code>write</code>
  23.125 -     * for an integer argument.) The byte written
  23.126 -     * by this method may be read by the <code>readByte</code>
  23.127 -     * method of interface <code>DataInput</code>,
  23.128 -     * which will then return a <code>byte</code>
  23.129 -     * equal to <code>(byte)v</code>.
  23.130 -     *
  23.131 -     * @param      v   the byte value to be written.
  23.132 -     * @throws     IOException  if an I/O error occurs.
  23.133 -     */
  23.134 -    void writeByte(int v) throws IOException;
  23.135 -
  23.136 -    /**
  23.137 -     * Writes two bytes to the output
  23.138 -     * stream to represent the value of the argument.
  23.139 -     * The byte values to be written, in the  order
  23.140 -     * shown, are: <p>
  23.141 -     * <pre><code>
  23.142 -     * (byte)(0xff &amp; (v &gt;&gt; 8))
  23.143 -     * (byte)(0xff &amp; v)
  23.144 -     * </code> </pre> <p>
  23.145 -     * The bytes written by this method may be
  23.146 -     * read by the <code>readShort</code> method
  23.147 -     * of interface <code>DataInput</code> , which
  23.148 -     * will then return a <code>short</code> equal
  23.149 -     * to <code>(short)v</code>.
  23.150 -     *
  23.151 -     * @param      v   the <code>short</code> value to be written.
  23.152 -     * @throws     IOException  if an I/O error occurs.
  23.153 -     */
  23.154 -    void writeShort(int v) throws IOException;
  23.155 -
  23.156 -    /**
  23.157 -     * Writes a <code>char</code> value, which
  23.158 -     * is comprised of two bytes, to the
  23.159 -     * output stream.
  23.160 -     * The byte values to be written, in the  order
  23.161 -     * shown, are:
  23.162 -     * <p><pre><code>
  23.163 -     * (byte)(0xff &amp; (v &gt;&gt; 8))
  23.164 -     * (byte)(0xff &amp; v)
  23.165 -     * </code></pre><p>
  23.166 -     * The bytes written by this method may be
  23.167 -     * read by the <code>readChar</code> method
  23.168 -     * of interface <code>DataInput</code> , which
  23.169 -     * will then return a <code>char</code> equal
  23.170 -     * to <code>(char)v</code>.
  23.171 -     *
  23.172 -     * @param      v   the <code>char</code> value to be written.
  23.173 -     * @throws     IOException  if an I/O error occurs.
  23.174 -     */
  23.175 -    void writeChar(int v) throws IOException;
  23.176 -
  23.177 -    /**
  23.178 -     * Writes an <code>int</code> value, which is
  23.179 -     * comprised of four bytes, to the output stream.
  23.180 -     * The byte values to be written, in the  order
  23.181 -     * shown, are:
  23.182 -     * <p><pre><code>
  23.183 -     * (byte)(0xff &amp; (v &gt;&gt; 24))
  23.184 -     * (byte)(0xff &amp; (v &gt;&gt; 16))
  23.185 -     * (byte)(0xff &amp; (v &gt;&gt; &#32; &#32;8))
  23.186 -     * (byte)(0xff &amp; v)
  23.187 -     * </code></pre><p>
  23.188 -     * The bytes written by this method may be read
  23.189 -     * by the <code>readInt</code> method of interface
  23.190 -     * <code>DataInput</code> , which will then
  23.191 -     * return an <code>int</code> equal to <code>v</code>.
  23.192 -     *
  23.193 -     * @param      v   the <code>int</code> value to be written.
  23.194 -     * @throws     IOException  if an I/O error occurs.
  23.195 -     */
  23.196 -    void writeInt(int v) throws IOException;
  23.197 -
  23.198 -    /**
  23.199 -     * Writes a <code>long</code> value, which is
  23.200 -     * comprised of eight bytes, to the output stream.
  23.201 -     * The byte values to be written, in the  order
  23.202 -     * shown, are:
  23.203 -     * <p><pre><code>
  23.204 -     * (byte)(0xff &amp; (v &gt;&gt; 56))
  23.205 -     * (byte)(0xff &amp; (v &gt;&gt; 48))
  23.206 -     * (byte)(0xff &amp; (v &gt;&gt; 40))
  23.207 -     * (byte)(0xff &amp; (v &gt;&gt; 32))
  23.208 -     * (byte)(0xff &amp; (v &gt;&gt; 24))
  23.209 -     * (byte)(0xff &amp; (v &gt;&gt; 16))
  23.210 -     * (byte)(0xff &amp; (v &gt;&gt;  8))
  23.211 -     * (byte)(0xff &amp; v)
  23.212 -     * </code></pre><p>
  23.213 -     * The bytes written by this method may be
  23.214 -     * read by the <code>readLong</code> method
  23.215 -     * of interface <code>DataInput</code> , which
  23.216 -     * will then return a <code>long</code> equal
  23.217 -     * to <code>v</code>.
  23.218 -     *
  23.219 -     * @param      v   the <code>long</code> value to be written.
  23.220 -     * @throws     IOException  if an I/O error occurs.
  23.221 -     */
  23.222 -    void writeLong(long v) throws IOException;
  23.223 -
  23.224 -    /**
  23.225 -     * Writes a <code>float</code> value,
  23.226 -     * which is comprised of four bytes, to the output stream.
  23.227 -     * It does this as if it first converts this
  23.228 -     * <code>float</code> value to an <code>int</code>
  23.229 -     * in exactly the manner of the <code>Float.floatToIntBits</code>
  23.230 -     * method  and then writes the <code>int</code>
  23.231 -     * value in exactly the manner of the  <code>writeInt</code>
  23.232 -     * method.  The bytes written by this method
  23.233 -     * may be read by the <code>readFloat</code>
  23.234 -     * method of interface <code>DataInput</code>,
  23.235 -     * which will then return a <code>float</code>
  23.236 -     * equal to <code>v</code>.
  23.237 -     *
  23.238 -     * @param      v   the <code>float</code> value to be written.
  23.239 -     * @throws     IOException  if an I/O error occurs.
  23.240 -     */
  23.241 -    void writeFloat(float v) throws IOException;
  23.242 -
  23.243 -    /**
  23.244 -     * Writes a <code>double</code> value,
  23.245 -     * which is comprised of eight bytes, to the output stream.
  23.246 -     * It does this as if it first converts this
  23.247 -     * <code>double</code> value to a <code>long</code>
  23.248 -     * in exactly the manner of the <code>Double.doubleToLongBits</code>
  23.249 -     * method  and then writes the <code>long</code>
  23.250 -     * value in exactly the manner of the  <code>writeLong</code>
  23.251 -     * method. The bytes written by this method
  23.252 -     * may be read by the <code>readDouble</code>
  23.253 -     * method of interface <code>DataInput</code>,
  23.254 -     * which will then return a <code>double</code>
  23.255 -     * equal to <code>v</code>.
  23.256 -     *
  23.257 -     * @param      v   the <code>double</code> value to be written.
  23.258 -     * @throws     IOException  if an I/O error occurs.
  23.259 -     */
  23.260 -    void writeDouble(double v) throws IOException;
  23.261 -
  23.262 -    /**
  23.263 -     * Writes a string to the output stream.
  23.264 -     * For every character in the string
  23.265 -     * <code>s</code>,  taken in order, one byte
  23.266 -     * is written to the output stream.  If
  23.267 -     * <code>s</code> is <code>null</code>, a <code>NullPointerException</code>
  23.268 -     * is thrown.<p>  If <code>s.length</code>
  23.269 -     * is zero, then no bytes are written. Otherwise,
  23.270 -     * the character <code>s[0]</code> is written
  23.271 -     * first, then <code>s[1]</code>, and so on;
  23.272 -     * the last character written is <code>s[s.length-1]</code>.
  23.273 -     * For each character, one byte is written,
  23.274 -     * the low-order byte, in exactly the manner
  23.275 -     * of the <code>writeByte</code> method . The
  23.276 -     * high-order eight bits of each character
  23.277 -     * in the string are ignored.
  23.278 -     *
  23.279 -     * @param      s   the string of bytes to be written.
  23.280 -     * @throws     IOException  if an I/O error occurs.
  23.281 -     */
  23.282 -    void writeBytes(String s) throws IOException;
  23.283 -
  23.284 -    /**
  23.285 -     * Writes every character in the string <code>s</code>,
  23.286 -     * to the output stream, in order,
  23.287 -     * two bytes per character. If <code>s</code>
  23.288 -     * is <code>null</code>, a <code>NullPointerException</code>
  23.289 -     * is thrown.  If <code>s.length</code>
  23.290 -     * is zero, then no characters are written.
  23.291 -     * Otherwise, the character <code>s[0]</code>
  23.292 -     * is written first, then <code>s[1]</code>,
  23.293 -     * and so on; the last character written is
  23.294 -     * <code>s[s.length-1]</code>. For each character,
  23.295 -     * two bytes are actually written, high-order
  23.296 -     * byte first, in exactly the manner of the
  23.297 -     * <code>writeChar</code> method.
  23.298 -     *
  23.299 -     * @param      s   the string value to be written.
  23.300 -     * @throws     IOException  if an I/O error occurs.
  23.301 -     */
  23.302 -    void writeChars(String s) throws IOException;
  23.303 -
  23.304 -    /**
  23.305 -     * Writes two bytes of length information
  23.306 -     * to the output stream, followed
  23.307 -     * by the
  23.308 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  23.309 -     * representation
  23.310 -     * of  every character in the string <code>s</code>.
  23.311 -     * If <code>s</code> is <code>null</code>,
  23.312 -     * a <code>NullPointerException</code> is thrown.
  23.313 -     * Each character in the string <code>s</code>
  23.314 -     * is converted to a group of one, two, or
  23.315 -     * three bytes, depending on the value of the
  23.316 -     * character.<p>
  23.317 -     * If a character <code>c</code>
  23.318 -     * is in the range <code>&#92;u0001</code> through
  23.319 -     * <code>&#92;u007f</code>, it is represented
  23.320 -     * by one byte:<p>
  23.321 -     * <pre>(byte)c </pre>  <p>
  23.322 -     * If a character <code>c</code> is <code>&#92;u0000</code>
  23.323 -     * or is in the range <code>&#92;u0080</code>
  23.324 -     * through <code>&#92;u07ff</code>, then it is
  23.325 -     * represented by two bytes, to be written
  23.326 -     * in the order shown:<p> <pre><code>
  23.327 -     * (byte)(0xc0 | (0x1f &amp; (c &gt;&gt; 6)))
  23.328 -     * (byte)(0x80 | (0x3f &amp; c))
  23.329 -     *  </code></pre>  <p> If a character
  23.330 -     * <code>c</code> is in the range <code>&#92;u0800</code>
  23.331 -     * through <code>uffff</code>, then it is
  23.332 -     * represented by three bytes, to be written
  23.333 -     * in the order shown:<p> <pre><code>
  23.334 -     * (byte)(0xe0 | (0x0f &amp; (c &gt;&gt; 12)))
  23.335 -     * (byte)(0x80 | (0x3f &amp; (c &gt;&gt;  6)))
  23.336 -     * (byte)(0x80 | (0x3f &amp; c))
  23.337 -     *  </code></pre>  <p> First,
  23.338 -     * the total number of bytes needed to represent
  23.339 -     * all the characters of <code>s</code> is
  23.340 -     * calculated. If this number is larger than
  23.341 -     * <code>65535</code>, then a <code>UTFDataFormatException</code>
  23.342 -     * is thrown. Otherwise, this length is written
  23.343 -     * to the output stream in exactly the manner
  23.344 -     * of the <code>writeShort</code> method;
  23.345 -     * after this, the one-, two-, or three-byte
  23.346 -     * representation of each character in the
  23.347 -     * string <code>s</code> is written.<p>  The
  23.348 -     * bytes written by this method may be read
  23.349 -     * by the <code>readUTF</code> method of interface
  23.350 -     * <code>DataInput</code> , which will then
  23.351 -     * return a <code>String</code> equal to <code>s</code>.
  23.352 -     *
  23.353 -     * @param      s   the string value to be written.
  23.354 -     * @throws     IOException  if an I/O error occurs.
  23.355 -     */
  23.356 -    void writeUTF(String s) throws IOException;
  23.357 -}
    24.1 --- a/emul/compact/src/main/java/java/io/DataOutputStream.java	Mon Feb 25 19:00:08 2013 +0100
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,416 +0,0 @@
    24.4 -/*
    24.5 - * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
    24.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    24.7 - *
    24.8 - * This code is free software; you can redistribute it and/or modify it
    24.9 - * under the terms of the GNU General Public License version 2 only, as
   24.10 - * published by the Free Software Foundation.  Oracle designates this
   24.11 - * particular file as subject to the "Classpath" exception as provided
   24.12 - * by Oracle in the LICENSE file that accompanied this code.
   24.13 - *
   24.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   24.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   24.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   24.17 - * version 2 for more details (a copy is included in the LICENSE file that
   24.18 - * accompanied this code).
   24.19 - *
   24.20 - * You should have received a copy of the GNU General Public License version
   24.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   24.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   24.23 - *
   24.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   24.25 - * or visit www.oracle.com if you need additional information or have any
   24.26 - * questions.
   24.27 - */
   24.28 -
   24.29 -package java.io;
   24.30 -
   24.31 -/**
   24.32 - * A data output stream lets an application write primitive Java data
   24.33 - * types to an output stream in a portable way. An application can
   24.34 - * then use a data input stream to read the data back in.
   24.35 - *
   24.36 - * @author  unascribed
   24.37 - * @see     java.io.DataInputStream
   24.38 - * @since   JDK1.0
   24.39 - */
   24.40 -public
   24.41 -class DataOutputStream extends FilterOutputStream implements DataOutput {
   24.42 -    /**
   24.43 -     * The number of bytes written to the data output stream so far.
   24.44 -     * If this counter overflows, it will be wrapped to Integer.MAX_VALUE.
   24.45 -     */
   24.46 -    protected int written;
   24.47 -
   24.48 -    /**
   24.49 -     * bytearr is initialized on demand by writeUTF
   24.50 -     */
   24.51 -    private byte[] bytearr = null;
   24.52 -
   24.53 -    /**
   24.54 -     * Creates a new data output stream to write data to the specified
   24.55 -     * underlying output stream. The counter <code>written</code> is
   24.56 -     * set to zero.
   24.57 -     *
   24.58 -     * @param   out   the underlying output stream, to be saved for later
   24.59 -     *                use.
   24.60 -     * @see     java.io.FilterOutputStream#out
   24.61 -     */
   24.62 -    public DataOutputStream(OutputStream out) {
   24.63 -        super(out);
   24.64 -    }
   24.65 -
   24.66 -    /**
   24.67 -     * Increases the written counter by the specified value
   24.68 -     * until it reaches Integer.MAX_VALUE.
   24.69 -     */
   24.70 -    private void incCount(int value) {
   24.71 -        int temp = written + value;
   24.72 -        if (temp < 0) {
   24.73 -            temp = Integer.MAX_VALUE;
   24.74 -        }
   24.75 -        written = temp;
   24.76 -    }
   24.77 -
   24.78 -    /**
   24.79 -     * Writes the specified byte (the low eight bits of the argument
   24.80 -     * <code>b</code>) to the underlying output stream. If no exception
   24.81 -     * is thrown, the counter <code>written</code> is incremented by
   24.82 -     * <code>1</code>.
   24.83 -     * <p>
   24.84 -     * Implements the <code>write</code> method of <code>OutputStream</code>.
   24.85 -     *
   24.86 -     * @param      b   the <code>byte</code> to be written.
   24.87 -     * @exception  IOException  if an I/O error occurs.
   24.88 -     * @see        java.io.FilterOutputStream#out
   24.89 -     */
   24.90 -    public synchronized void write(int b) throws IOException {
   24.91 -        out.write(b);
   24.92 -        incCount(1);
   24.93 -    }
   24.94 -
   24.95 -    /**
   24.96 -     * Writes <code>len</code> bytes from the specified byte array
   24.97 -     * starting at offset <code>off</code> to the underlying output stream.
   24.98 -     * If no exception is thrown, the counter <code>written</code> is
   24.99 -     * incremented by <code>len</code>.
  24.100 -     *
  24.101 -     * @param      b     the data.
  24.102 -     * @param      off   the start offset in the data.
  24.103 -     * @param      len   the number of bytes to write.
  24.104 -     * @exception  IOException  if an I/O error occurs.
  24.105 -     * @see        java.io.FilterOutputStream#out
  24.106 -     */
  24.107 -    public synchronized void write(byte b[], int off, int len)
  24.108 -        throws IOException
  24.109 -    {
  24.110 -        out.write(b, off, len);
  24.111 -        incCount(len);
  24.112 -    }
  24.113 -
  24.114 -    /**
  24.115 -     * Flushes this data output stream. This forces any buffered output
  24.116 -     * bytes to be written out to the stream.
  24.117 -     * <p>
  24.118 -     * The <code>flush</code> method of <code>DataOutputStream</code>
  24.119 -     * calls the <code>flush</code> method of its underlying output stream.
  24.120 -     *
  24.121 -     * @exception  IOException  if an I/O error occurs.
  24.122 -     * @see        java.io.FilterOutputStream#out
  24.123 -     * @see        java.io.OutputStream#flush()
  24.124 -     */
  24.125 -    public void flush() throws IOException {
  24.126 -        out.flush();
  24.127 -    }
  24.128 -
  24.129 -    /**
  24.130 -     * Writes a <code>boolean</code> to the underlying output stream as
  24.131 -     * a 1-byte value. The value <code>true</code> is written out as the
  24.132 -     * value <code>(byte)1</code>; the value <code>false</code> is
  24.133 -     * written out as the value <code>(byte)0</code>. If no exception is
  24.134 -     * thrown, the counter <code>written</code> is incremented by
  24.135 -     * <code>1</code>.
  24.136 -     *
  24.137 -     * @param      v   a <code>boolean</code> value to be written.
  24.138 -     * @exception  IOException  if an I/O error occurs.
  24.139 -     * @see        java.io.FilterOutputStream#out
  24.140 -     */
  24.141 -    public final void writeBoolean(boolean v) throws IOException {
  24.142 -        out.write(v ? 1 : 0);
  24.143 -        incCount(1);
  24.144 -    }
  24.145 -
  24.146 -    /**
  24.147 -     * Writes out a <code>byte</code> to the underlying output stream as
  24.148 -     * a 1-byte value. If no exception is thrown, the counter
  24.149 -     * <code>written</code> is incremented by <code>1</code>.
  24.150 -     *
  24.151 -     * @param      v   a <code>byte</code> value to be written.
  24.152 -     * @exception  IOException  if an I/O error occurs.
  24.153 -     * @see        java.io.FilterOutputStream#out
  24.154 -     */
  24.155 -    public final void writeByte(int v) throws IOException {
  24.156 -        out.write(v);
  24.157 -        incCount(1);
  24.158 -    }
  24.159 -
  24.160 -    /**
  24.161 -     * Writes a <code>short</code> to the underlying output stream as two
  24.162 -     * bytes, high byte first. If no exception is thrown, the counter
  24.163 -     * <code>written</code> is incremented by <code>2</code>.
  24.164 -     *
  24.165 -     * @param      v   a <code>short</code> to be written.
  24.166 -     * @exception  IOException  if an I/O error occurs.
  24.167 -     * @see        java.io.FilterOutputStream#out
  24.168 -     */
  24.169 -    public final void writeShort(int v) throws IOException {
  24.170 -        out.write((v >>> 8) & 0xFF);
  24.171 -        out.write((v >>> 0) & 0xFF);
  24.172 -        incCount(2);
  24.173 -    }
  24.174 -
  24.175 -    /**
  24.176 -     * Writes a <code>char</code> to the underlying output stream as a
  24.177 -     * 2-byte value, high byte first. If no exception is thrown, the
  24.178 -     * counter <code>written</code> is incremented by <code>2</code>.
  24.179 -     *
  24.180 -     * @param      v   a <code>char</code> value to be written.
  24.181 -     * @exception  IOException  if an I/O error occurs.
  24.182 -     * @see        java.io.FilterOutputStream#out
  24.183 -     */
  24.184 -    public final void writeChar(int v) throws IOException {
  24.185 -        out.write((v >>> 8) & 0xFF);
  24.186 -        out.write((v >>> 0) & 0xFF);
  24.187 -        incCount(2);
  24.188 -    }
  24.189 -
  24.190 -    /**
  24.191 -     * Writes an <code>int</code> to the underlying output stream as four
  24.192 -     * bytes, high byte first. If no exception is thrown, the counter
  24.193 -     * <code>written</code> is incremented by <code>4</code>.
  24.194 -     *
  24.195 -     * @param      v   an <code>int</code> to be written.
  24.196 -     * @exception  IOException  if an I/O error occurs.
  24.197 -     * @see        java.io.FilterOutputStream#out
  24.198 -     */
  24.199 -    public final void writeInt(int v) throws IOException {
  24.200 -        out.write((v >>> 24) & 0xFF);
  24.201 -        out.write((v >>> 16) & 0xFF);
  24.202 -        out.write((v >>>  8) & 0xFF);
  24.203 -        out.write((v >>>  0) & 0xFF);
  24.204 -        incCount(4);
  24.205 -    }
  24.206 -
  24.207 -    private byte writeBuffer[] = new byte[8];
  24.208 -
  24.209 -    /**
  24.210 -     * Writes a <code>long</code> to the underlying output stream as eight
  24.211 -     * bytes, high byte first. In no exception is thrown, the counter
  24.212 -     * <code>written</code> is incremented by <code>8</code>.
  24.213 -     *
  24.214 -     * @param      v   a <code>long</code> to be written.
  24.215 -     * @exception  IOException  if an I/O error occurs.
  24.216 -     * @see        java.io.FilterOutputStream#out
  24.217 -     */
  24.218 -    public final void writeLong(long v) throws IOException {
  24.219 -        writeBuffer[0] = (byte)(v >>> 56);
  24.220 -        writeBuffer[1] = (byte)(v >>> 48);
  24.221 -        writeBuffer[2] = (byte)(v >>> 40);
  24.222 -        writeBuffer[3] = (byte)(v >>> 32);
  24.223 -        writeBuffer[4] = (byte)(v >>> 24);
  24.224 -        writeBuffer[5] = (byte)(v >>> 16);
  24.225 -        writeBuffer[6] = (byte)(v >>>  8);
  24.226 -        writeBuffer[7] = (byte)(v >>>  0);
  24.227 -        out.write(writeBuffer, 0, 8);
  24.228 -        incCount(8);
  24.229 -    }
  24.230 -
  24.231 -    /**
  24.232 -     * Converts the float argument to an <code>int</code> using the
  24.233 -     * <code>floatToIntBits</code> method in class <code>Float</code>,
  24.234 -     * and then writes that <code>int</code> value to the underlying
  24.235 -     * output stream as a 4-byte quantity, high byte first. If no
  24.236 -     * exception is thrown, the counter <code>written</code> is
  24.237 -     * incremented by <code>4</code>.
  24.238 -     *
  24.239 -     * @param      v   a <code>float</code> value to be written.
  24.240 -     * @exception  IOException  if an I/O error occurs.
  24.241 -     * @see        java.io.FilterOutputStream#out
  24.242 -     * @see        java.lang.Float#floatToIntBits(float)
  24.243 -     */
  24.244 -    public final void writeFloat(float v) throws IOException {
  24.245 -        writeInt(Float.floatToIntBits(v));
  24.246 -    }
  24.247 -
  24.248 -    /**
  24.249 -     * Converts the double argument to a <code>long</code> using the
  24.250 -     * <code>doubleToLongBits</code> method in class <code>Double</code>,
  24.251 -     * and then writes that <code>long</code> value to the underlying
  24.252 -     * output stream as an 8-byte quantity, high byte first. If no
  24.253 -     * exception is thrown, the counter <code>written</code> is
  24.254 -     * incremented by <code>8</code>.
  24.255 -     *
  24.256 -     * @param      v   a <code>double</code> value to be written.
  24.257 -     * @exception  IOException  if an I/O error occurs.
  24.258 -     * @see        java.io.FilterOutputStream#out
  24.259 -     * @see        java.lang.Double#doubleToLongBits(double)
  24.260 -     */
  24.261 -    public final void writeDouble(double v) throws IOException {
  24.262 -        writeLong(Double.doubleToLongBits(v));
  24.263 -    }
  24.264 -
  24.265 -    /**
  24.266 -     * Writes out the string to the underlying output stream as a
  24.267 -     * sequence of bytes. Each character in the string is written out, in
  24.268 -     * sequence, by discarding its high eight bits. If no exception is
  24.269 -     * thrown, the counter <code>written</code> is incremented by the
  24.270 -     * length of <code>s</code>.
  24.271 -     *
  24.272 -     * @param      s   a string of bytes to be written.
  24.273 -     * @exception  IOException  if an I/O error occurs.
  24.274 -     * @see        java.io.FilterOutputStream#out
  24.275 -     */
  24.276 -    public final void writeBytes(String s) throws IOException {
  24.277 -        int len = s.length();
  24.278 -        for (int i = 0 ; i < len ; i++) {
  24.279 -            out.write((byte)s.charAt(i));
  24.280 -        }
  24.281 -        incCount(len);
  24.282 -    }
  24.283 -
  24.284 -    /**
  24.285 -     * Writes a string to the underlying output stream as a sequence of
  24.286 -     * characters. Each character is written to the data output stream as
  24.287 -     * if by the <code>writeChar</code> method. If no exception is
  24.288 -     * thrown, the counter <code>written</code> is incremented by twice
  24.289 -     * the length of <code>s</code>.
  24.290 -     *
  24.291 -     * @param      s   a <code>String</code> value to be written.
  24.292 -     * @exception  IOException  if an I/O error occurs.
  24.293 -     * @see        java.io.DataOutputStream#writeChar(int)
  24.294 -     * @see        java.io.FilterOutputStream#out
  24.295 -     */
  24.296 -    public final void writeChars(String s) throws IOException {
  24.297 -        int len = s.length();
  24.298 -        for (int i = 0 ; i < len ; i++) {
  24.299 -            int v = s.charAt(i);
  24.300 -            out.write((v >>> 8) & 0xFF);
  24.301 -            out.write((v >>> 0) & 0xFF);
  24.302 -        }
  24.303 -        incCount(len * 2);
  24.304 -    }
  24.305 -
  24.306 -    /**
  24.307 -     * Writes a string to the underlying output stream using
  24.308 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  24.309 -     * encoding in a machine-independent manner.
  24.310 -     * <p>
  24.311 -     * First, two bytes are written to the output stream as if by the
  24.312 -     * <code>writeShort</code> method giving the number of bytes to
  24.313 -     * follow. This value is the number of bytes actually written out,
  24.314 -     * not the length of the string. Following the length, each character
  24.315 -     * of the string is output, in sequence, using the modified UTF-8 encoding
  24.316 -     * for the character. If no exception is thrown, the counter
  24.317 -     * <code>written</code> is incremented by the total number of
  24.318 -     * bytes written to the output stream. This will be at least two
  24.319 -     * plus the length of <code>str</code>, and at most two plus
  24.320 -     * thrice the length of <code>str</code>.
  24.321 -     *
  24.322 -     * @param      str   a string to be written.
  24.323 -     * @exception  IOException  if an I/O error occurs.
  24.324 -     */
  24.325 -    public final void writeUTF(String str) throws IOException {
  24.326 -        writeUTF(str, this);
  24.327 -    }
  24.328 -
  24.329 -    /**
  24.330 -     * Writes a string to the specified DataOutput using
  24.331 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  24.332 -     * encoding in a machine-independent manner.
  24.333 -     * <p>
  24.334 -     * First, two bytes are written to out as if by the <code>writeShort</code>
  24.335 -     * method giving the number of bytes to follow. This value is the number of
  24.336 -     * bytes actually written out, not the length of the string. Following the
  24.337 -     * length, each character of the string is output, in sequence, using the
  24.338 -     * modified UTF-8 encoding for the character. If no exception is thrown, the
  24.339 -     * counter <code>written</code> is incremented by the total number of
  24.340 -     * bytes written to the output stream. This will be at least two
  24.341 -     * plus the length of <code>str</code>, and at most two plus
  24.342 -     * thrice the length of <code>str</code>.
  24.343 -     *
  24.344 -     * @param      str   a string to be written.
  24.345 -     * @param      out   destination to write to
  24.346 -     * @return     The number of bytes written out.
  24.347 -     * @exception  IOException  if an I/O error occurs.
  24.348 -     */
  24.349 -    static int writeUTF(String str, DataOutput out) throws IOException {
  24.350 -        int strlen = str.length();
  24.351 -        int utflen = 0;
  24.352 -        int c, count = 0;
  24.353 -
  24.354 -        /* use charAt instead of copying String to char array */
  24.355 -        for (int i = 0; i < strlen; i++) {
  24.356 -            c = str.charAt(i);
  24.357 -            if ((c >= 0x0001) && (c <= 0x007F)) {
  24.358 -                utflen++;
  24.359 -            } else if (c > 0x07FF) {
  24.360 -                utflen += 3;
  24.361 -            } else {
  24.362 -                utflen += 2;
  24.363 -            }
  24.364 -        }
  24.365 -
  24.366 -        if (utflen > 65535)
  24.367 -            throw new UTFDataFormatException(
  24.368 -                "encoded string too long: " + utflen + " bytes");
  24.369 -
  24.370 -        byte[] bytearr = null;
  24.371 -        if (out instanceof DataOutputStream) {
  24.372 -            DataOutputStream dos = (DataOutputStream)out;
  24.373 -            if(dos.bytearr == null || (dos.bytearr.length < (utflen+2)))
  24.374 -                dos.bytearr = new byte[(utflen*2) + 2];
  24.375 -            bytearr = dos.bytearr;
  24.376 -        } else {
  24.377 -            bytearr = new byte[utflen+2];
  24.378 -        }
  24.379 -
  24.380 -        bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
  24.381 -        bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
  24.382 -
  24.383 -        int i=0;
  24.384 -        for (i=0; i<strlen; i++) {
  24.385 -           c = str.charAt(i);
  24.386 -           if (!((c >= 0x0001) && (c <= 0x007F))) break;
  24.387 -           bytearr[count++] = (byte) c;
  24.388 -        }
  24.389 -
  24.390 -        for (;i < strlen; i++){
  24.391 -            c = str.charAt(i);
  24.392 -            if ((c >= 0x0001) && (c <= 0x007F)) {
  24.393 -                bytearr[count++] = (byte) c;
  24.394 -
  24.395 -            } else if (c > 0x07FF) {
  24.396 -                bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
  24.397 -                bytearr[count++] = (byte) (0x80 | ((c >>  6) & 0x3F));
  24.398 -                bytearr[count++] = (byte) (0x80 | ((c >>  0) & 0x3F));
  24.399 -            } else {
  24.400 -                bytearr[count++] = (byte) (0xC0 | ((c >>  6) & 0x1F));
  24.401 -                bytearr[count++] = (byte) (0x80 | ((c >>  0) & 0x3F));
  24.402 -            }
  24.403 -        }
  24.404 -        out.write(bytearr, 0, utflen+2);
  24.405 -        return utflen + 2;
  24.406 -    }
  24.407 -
  24.408 -    /**
  24.409 -     * Returns the current value of the counter <code>written</code>,
  24.410 -     * the number of bytes written to this data output stream so far.
  24.411 -     * If the counter overflows, it will be wrapped to Integer.MAX_VALUE.
  24.412 -     *
  24.413 -     * @return  the value of the <code>written</code> field.
  24.414 -     * @see     java.io.DataOutputStream#written
  24.415 -     */
  24.416 -    public final int size() {
  24.417 -        return written;
  24.418 -    }
  24.419 -}
    25.1 --- a/emul/compact/src/main/java/java/io/Externalizable.java	Mon Feb 25 19:00:08 2013 +0100
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,97 +0,0 @@
    25.4 -/*
    25.5 - * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
    25.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    25.7 - *
    25.8 - * This code is free software; you can redistribute it and/or modify it
    25.9 - * under the terms of the GNU General Public License version 2 only, as
   25.10 - * published by the Free Software Foundation.  Oracle designates this
   25.11 - * particular file as subject to the "Classpath" exception as provided
   25.12 - * by Oracle in the LICENSE file that accompanied this code.
   25.13 - *
   25.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   25.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   25.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   25.17 - * version 2 for more details (a copy is included in the LICENSE file that
   25.18 - * accompanied this code).
   25.19 - *
   25.20 - * You should have received a copy of the GNU General Public License version
   25.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   25.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   25.23 - *
   25.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   25.25 - * or visit www.oracle.com if you need additional information or have any
   25.26 - * questions.
   25.27 - */
   25.28 -
   25.29 -package java.io;
   25.30 -
   25.31 -import java.io.ObjectOutput;
   25.32 -import java.io.ObjectInput;
   25.33 -
   25.34 -/**
   25.35 - * Only the identity of the class of an Externalizable instance is
   25.36 - * written in the serialization stream and it is the responsibility
   25.37 - * of the class to save and restore the contents of its instances.
   25.38 - *
   25.39 - * The writeExternal and readExternal methods of the Externalizable
   25.40 - * interface are implemented by a class to give the class complete
   25.41 - * control over the format and contents of the stream for an object
   25.42 - * and its supertypes. These methods must explicitly
   25.43 - * coordinate with the supertype to save its state. These methods supersede
   25.44 - * customized implementations of writeObject and readObject methods.<br>
   25.45 - *
   25.46 - * Object Serialization uses the Serializable and Externalizable
   25.47 - * interfaces.  Object persistence mechanisms can use them as well.  Each
   25.48 - * object to be stored is tested for the Externalizable interface. If
   25.49 - * the object supports Externalizable, the writeExternal method is called. If the
   25.50 - * object does not support Externalizable and does implement
   25.51 - * Serializable, the object is saved using
   25.52 - * ObjectOutputStream. <br> When an Externalizable object is
   25.53 - * reconstructed, an instance is created using the public no-arg
   25.54 - * constructor, then the readExternal method called.  Serializable
   25.55 - * objects are restored by reading them from an ObjectInputStream.<br>
   25.56 - *
   25.57 - * An Externalizable instance can designate a substitution object via
   25.58 - * the writeReplace and readResolve methods documented in the Serializable
   25.59 - * interface.<br>
   25.60 - *
   25.61 - * @author  unascribed
   25.62 - * @see java.io.ObjectOutputStream
   25.63 - * @see java.io.ObjectInputStream
   25.64 - * @see java.io.ObjectOutput
   25.65 - * @see java.io.ObjectInput
   25.66 - * @see java.io.Serializable
   25.67 - * @since   JDK1.1
   25.68 - */
   25.69 -public interface Externalizable extends java.io.Serializable {
   25.70 -    /**
   25.71 -     * The object implements the writeExternal method to save its contents
   25.72 -     * by calling the methods of DataOutput for its primitive values or
   25.73 -     * calling the writeObject method of ObjectOutput for objects, strings,
   25.74 -     * and arrays.
   25.75 -     *
   25.76 -     * @serialData Overriding methods should use this tag to describe
   25.77 -     *             the data layout of this Externalizable object.
   25.78 -     *             List the sequence of element types and, if possible,
   25.79 -     *             relate the element to a public/protected field and/or
   25.80 -     *             method of this Externalizable class.
   25.81 -     *
   25.82 -     * @param out the stream to write the object to
   25.83 -     * @exception IOException Includes any I/O exceptions that may occur
   25.84 -     */
   25.85 -    void writeExternal(ObjectOutput out) throws IOException;
   25.86 -
   25.87 -    /**
   25.88 -     * The object implements the readExternal method to restore its
   25.89 -     * contents by calling the methods of DataInput for primitive
   25.90 -     * types and readObject for objects, strings and arrays.  The
   25.91 -     * readExternal method must read the values in the same sequence
   25.92 -     * and with the same types as were written by writeExternal.
   25.93 -     *
   25.94 -     * @param in the stream to read data from in order to restore the object
   25.95 -     * @exception IOException if I/O errors occur
   25.96 -     * @exception ClassNotFoundException If the class for an object being
   25.97 -     *              restored cannot be found.
   25.98 -     */
   25.99 -    void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
  25.100 -}
    26.1 --- a/emul/compact/src/main/java/java/io/FilterOutputStream.java	Mon Feb 25 19:00:08 2013 +0100
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,162 +0,0 @@
    26.4 -/*
    26.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
    26.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    26.7 - *
    26.8 - * This code is free software; you can redistribute it and/or modify it
    26.9 - * under the terms of the GNU General Public License version 2 only, as
   26.10 - * published by the Free Software Foundation.  Oracle designates this
   26.11 - * particular file as subject to the "Classpath" exception as provided
   26.12 - * by Oracle in the LICENSE file that accompanied this code.
   26.13 - *
   26.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   26.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   26.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   26.17 - * version 2 for more details (a copy is included in the LICENSE file that
   26.18 - * accompanied this code).
   26.19 - *
   26.20 - * You should have received a copy of the GNU General Public License version
   26.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   26.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   26.23 - *
   26.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   26.25 - * or visit www.oracle.com if you need additional information or have any
   26.26 - * questions.
   26.27 - */
   26.28 -
   26.29 -package java.io;
   26.30 -
   26.31 -/**
   26.32 - * This class is the superclass of all classes that filter output
   26.33 - * streams. These streams sit on top of an already existing output
   26.34 - * stream (the <i>underlying</i> output stream) which it uses as its
   26.35 - * basic sink of data, but possibly transforming the data along the
   26.36 - * way or providing additional functionality.
   26.37 - * <p>
   26.38 - * The class <code>FilterOutputStream</code> itself simply overrides
   26.39 - * all methods of <code>OutputStream</code> with versions that pass
   26.40 - * all requests to the underlying output stream. Subclasses of
   26.41 - * <code>FilterOutputStream</code> may further override some of these
   26.42 - * methods as well as provide additional methods and fields.
   26.43 - *
   26.44 - * @author  Jonathan Payne
   26.45 - * @since   JDK1.0
   26.46 - */
   26.47 -public
   26.48 -class FilterOutputStream extends OutputStream {
   26.49 -    /**
   26.50 -     * The underlying output stream to be filtered.
   26.51 -     */
   26.52 -    protected OutputStream out;
   26.53 -
   26.54 -    /**
   26.55 -     * Creates an output stream filter built on top of the specified
   26.56 -     * underlying output stream.
   26.57 -     *
   26.58 -     * @param   out   the underlying output stream to be assigned to
   26.59 -     *                the field <tt>this.out</tt> for later use, or
   26.60 -     *                <code>null</code> if this instance is to be
   26.61 -     *                created without an underlying stream.
   26.62 -     */
   26.63 -    public FilterOutputStream(OutputStream out) {
   26.64 -        this.out = out;
   26.65 -    }
   26.66 -
   26.67 -    /**
   26.68 -     * Writes the specified <code>byte</code> to this output stream.
   26.69 -     * <p>
   26.70 -     * The <code>write</code> method of <code>FilterOutputStream</code>
   26.71 -     * calls the <code>write</code> method of its underlying output stream,
   26.72 -     * that is, it performs <tt>out.write(b)</tt>.
   26.73 -     * <p>
   26.74 -     * Implements the abstract <tt>write</tt> method of <tt>OutputStream</tt>.
   26.75 -     *
   26.76 -     * @param      b   the <code>byte</code>.
   26.77 -     * @exception  IOException  if an I/O error occurs.
   26.78 -     */
   26.79 -    public void write(int b) throws IOException {
   26.80 -        out.write(b);
   26.81 -    }
   26.82 -
   26.83 -    /**
   26.84 -     * Writes <code>b.length</code> bytes to this output stream.
   26.85 -     * <p>
   26.86 -     * The <code>write</code> method of <code>FilterOutputStream</code>
   26.87 -     * calls its <code>write</code> method of three arguments with the
   26.88 -     * arguments <code>b</code>, <code>0</code>, and
   26.89 -     * <code>b.length</code>.
   26.90 -     * <p>
   26.91 -     * Note that this method does not call the one-argument
   26.92 -     * <code>write</code> method of its underlying stream with the single
   26.93 -     * argument <code>b</code>.
   26.94 -     *
   26.95 -     * @param      b   the data to be written.
   26.96 -     * @exception  IOException  if an I/O error occurs.
   26.97 -     * @see        java.io.FilterOutputStream#write(byte[], int, int)
   26.98 -     */
   26.99 -    public void write(byte b[]) throws IOException {
  26.100 -        write(b, 0, b.length);
  26.101 -    }
  26.102 -
  26.103 -    /**
  26.104 -     * Writes <code>len</code> bytes from the specified
  26.105 -     * <code>byte</code> array starting at offset <code>off</code> to
  26.106 -     * this output stream.
  26.107 -     * <p>
  26.108 -     * The <code>write</code> method of <code>FilterOutputStream</code>
  26.109 -     * calls the <code>write</code> method of one argument on each
  26.110 -     * <code>byte</code> to output.
  26.111 -     * <p>
  26.112 -     * Note that this method does not call the <code>write</code> method
  26.113 -     * of its underlying input stream with the same arguments. Subclasses
  26.114 -     * of <code>FilterOutputStream</code> should provide a more efficient
  26.115 -     * implementation of this method.
  26.116 -     *
  26.117 -     * @param      b     the data.
  26.118 -     * @param      off   the start offset in the data.
  26.119 -     * @param      len   the number of bytes to write.
  26.120 -     * @exception  IOException  if an I/O error occurs.
  26.121 -     * @see        java.io.FilterOutputStream#write(int)
  26.122 -     */
  26.123 -    public void write(byte b[], int off, int len) throws IOException {
  26.124 -        if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
  26.125 -            throw new IndexOutOfBoundsException();
  26.126 -
  26.127 -        for (int i = 0 ; i < len ; i++) {
  26.128 -            write(b[off + i]);
  26.129 -        }
  26.130 -    }
  26.131 -
  26.132 -    /**
  26.133 -     * Flushes this output stream and forces any buffered output bytes
  26.134 -     * to be written out to the stream.
  26.135 -     * <p>
  26.136 -     * The <code>flush</code> method of <code>FilterOutputStream</code>
  26.137 -     * calls the <code>flush</code> method of its underlying output stream.
  26.138 -     *
  26.139 -     * @exception  IOException  if an I/O error occurs.
  26.140 -     * @see        java.io.FilterOutputStream#out
  26.141 -     */
  26.142 -    public void flush() throws IOException {
  26.143 -        out.flush();
  26.144 -    }
  26.145 -
  26.146 -    /**
  26.147 -     * Closes this output stream and releases any system resources
  26.148 -     * associated with the stream.
  26.149 -     * <p>
  26.150 -     * The <code>close</code> method of <code>FilterOutputStream</code>
  26.151 -     * calls its <code>flush</code> method, and then calls the
  26.152 -     * <code>close</code> method of its underlying output stream.
  26.153 -     *
  26.154 -     * @exception  IOException  if an I/O error occurs.
  26.155 -     * @see        java.io.FilterOutputStream#flush()
  26.156 -     * @see        java.io.FilterOutputStream#out
  26.157 -     */
  26.158 -    public void close() throws IOException {
  26.159 -        try {
  26.160 -          flush();
  26.161 -        } catch (IOException ignored) {
  26.162 -        }
  26.163 -        out.close();
  26.164 -    }
  26.165 -}
    27.1 --- a/emul/compact/src/main/java/java/io/Flushable.java	Mon Feb 25 19:00:08 2013 +0100
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,47 +0,0 @@
    27.4 -/*
    27.5 - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
    27.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.7 - *
    27.8 - * This code is free software; you can redistribute it and/or modify it
    27.9 - * under the terms of the GNU General Public License version 2 only, as
   27.10 - * published by the Free Software Foundation.  Oracle designates this
   27.11 - * particular file as subject to the "Classpath" exception as provided
   27.12 - * by Oracle in the LICENSE file that accompanied this code.
   27.13 - *
   27.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   27.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   27.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   27.17 - * version 2 for more details (a copy is included in the LICENSE file that
   27.18 - * accompanied this code).
   27.19 - *
   27.20 - * You should have received a copy of the GNU General Public License version
   27.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   27.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   27.23 - *
   27.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   27.25 - * or visit www.oracle.com if you need additional information or have any
   27.26 - * questions.
   27.27 - */
   27.28 -
   27.29 -package java.io;
   27.30 -
   27.31 -import java.io.IOException;
   27.32 -
   27.33 -/**
   27.34 - * A <tt>Flushable</tt> is a destination of data that can be flushed.  The
   27.35 - * flush method is invoked to write any buffered output to the underlying
   27.36 - * stream.
   27.37 - *
   27.38 - * @since 1.5
   27.39 - */
   27.40 -
   27.41 -public interface Flushable {
   27.42 -
   27.43 -    /**
   27.44 -     * Flushes this stream by writing any buffered output to the underlying
   27.45 -     * stream.
   27.46 -     *
   27.47 -     * @throws IOException If an I/O error occurs
   27.48 -     */
   27.49 -    void flush() throws IOException;
   27.50 -}
    28.1 --- a/emul/compact/src/main/java/java/io/InputStreamReader.java	Mon Feb 25 19:00:08 2013 +0100
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,230 +0,0 @@
    28.4 -/*
    28.5 - * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
    28.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 - *
    28.8 - * This code is free software; you can redistribute it and/or modify it
    28.9 - * under the terms of the GNU General Public License version 2 only, as
   28.10 - * published by the Free Software Foundation.  Oracle designates this
   28.11 - * particular file as subject to the "Classpath" exception as provided
   28.12 - * by Oracle in the LICENSE file that accompanied this code.
   28.13 - *
   28.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   28.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.17 - * version 2 for more details (a copy is included in the LICENSE file that
   28.18 - * accompanied this code).
   28.19 - *
   28.20 - * You should have received a copy of the GNU General Public License version
   28.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   28.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.23 - *
   28.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   28.25 - * or visit www.oracle.com if you need additional information or have any
   28.26 - * questions.
   28.27 - */
   28.28 -
   28.29 -package java.io;
   28.30 -
   28.31 -
   28.32 -/**
   28.33 - * An InputStreamReader is a bridge from byte streams to character streams: It
   28.34 - * reads bytes and decodes them into characters using a specified {@link
   28.35 - * java.nio.charset.Charset <code>charset</code>}.  The charset that it uses
   28.36 - * may be specified by name or may be given explicitly, or the platform's
   28.37 - * default charset may be accepted.
   28.38 - *
   28.39 - * <p> Each invocation of one of an InputStreamReader's read() methods may
   28.40 - * cause one or more bytes to be read from the underlying byte-input stream.
   28.41 - * To enable the efficient conversion of bytes to characters, more bytes may
   28.42 - * be read ahead from the underlying stream than are necessary to satisfy the
   28.43 - * current read operation.
   28.44 - *
   28.45 - * <p> For top efficiency, consider wrapping an InputStreamReader within a
   28.46 - * BufferedReader.  For example:
   28.47 - *
   28.48 - * <pre>
   28.49 - * BufferedReader in
   28.50 - *   = new BufferedReader(new InputStreamReader(System.in));
   28.51 - * </pre>
   28.52 - *
   28.53 - * @see BufferedReader
   28.54 - * @see InputStream
   28.55 - * @see java.nio.charset.Charset
   28.56 - *
   28.57 - * @author      Mark Reinhold
   28.58 - * @since       JDK1.1
   28.59 - */
   28.60 -
   28.61 -public class InputStreamReader extends Reader {
   28.62 -
   28.63 -    /**
   28.64 -     * Creates an InputStreamReader that uses the default charset.
   28.65 -     *
   28.66 -     * @param  in   An InputStream
   28.67 -     */
   28.68 -    public InputStreamReader(InputStream in) {
   28.69 -        super(in);
   28.70 -    }
   28.71 -
   28.72 -    /**
   28.73 -     * Creates an InputStreamReader that uses the named charset.
   28.74 -     *
   28.75 -     * @param  in
   28.76 -     *         An InputStream
   28.77 -     *
   28.78 -     * @param  charsetName
   28.79 -     *         The name of a supported
   28.80 -     *         {@link java.nio.charset.Charset </code>charset<code>}
   28.81 -     *
   28.82 -     * @exception  UnsupportedEncodingException
   28.83 -     *             If the named charset is not supported
   28.84 -     */
   28.85 -    public InputStreamReader(InputStream in, String charsetName)
   28.86 -        throws UnsupportedEncodingException
   28.87 -    {
   28.88 -        super(in);
   28.89 -        if (!charsetName.toUpperCase().equals("UTF-8")) {
   28.90 -            throw new UnsupportedEncodingException(charsetName);
   28.91 -        }
   28.92 -    }
   28.93 -
   28.94 -    /**
   28.95 -     * Creates an InputStreamReader that uses the given charset. </p>
   28.96 -     *
   28.97 -     * @param  in       An InputStream
   28.98 -     * @param  cs       A charset
   28.99 -     *
  28.100 -     * @since 1.4
  28.101 -     * @spec JSR-51
  28.102 -     */
  28.103 -/* XXX:
  28.104 -    public InputStreamReader(InputStream in, Charset cs) {
  28.105 -        super(in);
  28.106 -        if (cs == null)
  28.107 -            throw new NullPointerException("charset");
  28.108 -        sd = StreamDecoder.forInputStreamReader(in, this, cs);
  28.109 -    }
  28.110 -*/
  28.111 -    /**
  28.112 -     * Creates an InputStreamReader that uses the given charset decoder.  </p>
  28.113 -     *
  28.114 -     * @param  in       An InputStream
  28.115 -     * @param  dec      A charset decoder
  28.116 -     *
  28.117 -     * @since 1.4
  28.118 -     * @spec JSR-51
  28.119 -     */
  28.120 -/* XXX:
  28.121 -    public InputStreamReader(InputStream in, CharsetDecoder dec) {
  28.122 -        super(in);
  28.123 -        if (dec == null)
  28.124 -            throw new NullPointerException("charset decoder");
  28.125 -        sd = StreamDecoder.forInputStreamReader(in, this, dec);
  28.126 -    }
  28.127 -*/
  28.128 -    
  28.129 -    /**
  28.130 -     * Returns the name of the character encoding being used by this stream.
  28.131 -     *
  28.132 -     * <p> If the encoding has an historical name then that name is returned;
  28.133 -     * otherwise the encoding's canonical name is returned.
  28.134 -     *
  28.135 -     * <p> If this instance was created with the {@link
  28.136 -     * #InputStreamReader(InputStream, String)} constructor then the returned
  28.137 -     * name, being unique for the encoding, may differ from the name passed to
  28.138 -     * the constructor. This method will return <code>null</code> if the
  28.139 -     * stream has been closed.
  28.140 -     * </p>
  28.141 -     * @return The historical name of this encoding, or
  28.142 -     *         <code>null</code> if the stream has been closed
  28.143 -     *
  28.144 -     * @see java.nio.charset.Charset
  28.145 -     *
  28.146 -     * @revised 1.4
  28.147 -     * @spec JSR-51
  28.148 -     */
  28.149 -    public String getEncoding() {
  28.150 -        return "UTF-8";
  28.151 -    }
  28.152 -
  28.153 -    /**
  28.154 -     * Reads a single character.
  28.155 -     *
  28.156 -     * @return The character read, or -1 if the end of the stream has been
  28.157 -     *         reached
  28.158 -     *
  28.159 -     * @exception  IOException  If an I/O error occurs
  28.160 -     */
  28.161 -    public int read() throws IOException {
  28.162 -        final InputStream is = (InputStream)lock;
  28.163 -        int c = is.read();
  28.164 -        if (c == -1) {
  28.165 -            return -1;
  28.166 -        }
  28.167 -        c = (int) c & 0xff;
  28.168 -        switch (c >> 4) {
  28.169 -            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  28.170 -                /* 0xxxxxxx*/
  28.171 -                return c;
  28.172 -            case 12: case 13: {
  28.173 -                /* 110x xxxx   10xx xxxx*/
  28.174 -                int char2 = (int) is.read();
  28.175 -                if ((char2 & 0xC0) != 0x80)
  28.176 -                    throw new UTFDataFormatException("malformed input");
  28.177 -                return (((c & 0x1F) << 6) | (char2 & 0x3F));
  28.178 -            }
  28.179 -            case 14: {
  28.180 -                /* 1110 xxxx  10xx xxxx  10xx xxxx */
  28.181 -                int char2 = is.read();
  28.182 -                int char3 = is.read();
  28.183 -                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
  28.184 -                    throw new UTFDataFormatException("malformed input");
  28.185 -                return (((c    & 0x0F) << 12) |
  28.186 -                       ((char2 & 0x3F) << 6)  |
  28.187 -                       ((char3 & 0x3F) << 0));
  28.188 -            }
  28.189 -            default:
  28.190 -                /* 10xx xxxx,  1111 xxxx */
  28.191 -                throw new UTFDataFormatException("malformed input");
  28.192 -        }
  28.193 -    }
  28.194 -    
  28.195 -    /**
  28.196 -     * Reads characters into a portion of an array.
  28.197 -     *
  28.198 -     * @param      cbuf     Destination buffer
  28.199 -     * @param      offset   Offset at which to start storing characters
  28.200 -     * @param      length   Maximum number of characters to read
  28.201 -     *
  28.202 -     * @return     The number of characters read, or -1 if the end of the
  28.203 -     *             stream has been reached
  28.204 -     *
  28.205 -     * @exception  IOException  If an I/O error occurs
  28.206 -     */
  28.207 -    public int read(char cbuf[], int offset, int length) throws IOException {
  28.208 -        for (int i = 0; i < length; i++) {
  28.209 -            int ch = read();
  28.210 -            if (ch == -1) {
  28.211 -                if (i == 0) return -1;
  28.212 -                return i;
  28.213 -            }
  28.214 -            cbuf[offset++] = (char) ch;
  28.215 -        }
  28.216 -        return length;
  28.217 -    }
  28.218 -
  28.219 -    /**
  28.220 -     * Tells whether this stream is ready to be read.  An InputStreamReader is
  28.221 -     * ready if its input buffer is not empty, or if bytes are available to be
  28.222 -     * read from the underlying byte stream.
  28.223 -     *
  28.224 -     * @exception  IOException  If an I/O error occurs
  28.225 -     */
  28.226 -    public boolean ready() throws IOException {
  28.227 -        return ((InputStream)lock).available() > 0;
  28.228 -    }
  28.229 -
  28.230 -    public void close() throws IOException {
  28.231 -        ((InputStream)lock).close();
  28.232 -    }
  28.233 -}
    29.1 --- a/emul/compact/src/main/java/java/io/InvalidClassException.java	Mon Feb 25 19:00:08 2013 +0100
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,81 +0,0 @@
    29.4 -/*
    29.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
    29.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    29.7 - *
    29.8 - * This code is free software; you can redistribute it and/or modify it
    29.9 - * under the terms of the GNU General Public License version 2 only, as
   29.10 - * published by the Free Software Foundation.  Oracle designates this
   29.11 - * particular file as subject to the "Classpath" exception as provided
   29.12 - * by Oracle in the LICENSE file that accompanied this code.
   29.13 - *
   29.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   29.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   29.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   29.17 - * version 2 for more details (a copy is included in the LICENSE file that
   29.18 - * accompanied this code).
   29.19 - *
   29.20 - * You should have received a copy of the GNU General Public License version
   29.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   29.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   29.23 - *
   29.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   29.25 - * or visit www.oracle.com if you need additional information or have any
   29.26 - * questions.
   29.27 - */
   29.28 -
   29.29 -package java.io;
   29.30 -
   29.31 -/**
   29.32 - * Thrown when the Serialization runtime detects one of the following
   29.33 - * problems with a Class.
   29.34 - * <UL>
   29.35 - * <LI> The serial version of the class does not match that of the class
   29.36 - *      descriptor read from the stream
   29.37 - * <LI> The class contains unknown datatypes
   29.38 - * <LI> The class does not have an accessible no-arg constructor
   29.39 - * </UL>
   29.40 - *
   29.41 - * @author  unascribed
   29.42 - * @since   JDK1.1
   29.43 - */
   29.44 -public class InvalidClassException extends ObjectStreamException {
   29.45 -
   29.46 -    private static final long serialVersionUID = -4333316296251054416L;
   29.47 -
   29.48 -    /**
   29.49 -     * Name of the invalid class.
   29.50 -     *
   29.51 -     * @serial Name of the invalid class.
   29.52 -     */
   29.53 -    public String classname;
   29.54 -
   29.55 -    /**
   29.56 -     * Report an InvalidClassException for the reason specified.
   29.57 -     *
   29.58 -     * @param reason  String describing the reason for the exception.
   29.59 -     */
   29.60 -    public InvalidClassException(String reason) {
   29.61 -        super(reason);
   29.62 -    }
   29.63 -
   29.64 -    /**
   29.65 -     * Constructs an InvalidClassException object.
   29.66 -     *
   29.67 -     * @param cname   a String naming the invalid class.
   29.68 -     * @param reason  a String describing the reason for the exception.
   29.69 -     */
   29.70 -    public InvalidClassException(String cname, String reason) {
   29.71 -        super(reason);
   29.72 -        classname = cname;
   29.73 -    }
   29.74 -
   29.75 -    /**
   29.76 -     * Produce the message and include the classname, if present.
   29.77 -     */
   29.78 -    public String getMessage() {
   29.79 -        if (classname == null)
   29.80 -            return super.getMessage();
   29.81 -        else
   29.82 -            return classname + "; " + super.getMessage();
   29.83 -    }
   29.84 -}
    30.1 --- a/emul/compact/src/main/java/java/io/InvalidObjectException.java	Mon Feb 25 19:00:08 2013 +0100
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,51 +0,0 @@
    30.4 -/*
    30.5 - * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
    30.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.7 - *
    30.8 - * This code is free software; you can redistribute it and/or modify it
    30.9 - * under the terms of the GNU General Public License version 2 only, as
   30.10 - * published by the Free Software Foundation.  Oracle designates this
   30.11 - * particular file as subject to the "Classpath" exception as provided
   30.12 - * by Oracle in the LICENSE file that accompanied this code.
   30.13 - *
   30.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   30.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   30.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   30.17 - * version 2 for more details (a copy is included in the LICENSE file that
   30.18 - * accompanied this code).
   30.19 - *
   30.20 - * You should have received a copy of the GNU General Public License version
   30.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   30.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   30.23 - *
   30.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   30.25 - * or visit www.oracle.com if you need additional information or have any
   30.26 - * questions.
   30.27 - */
   30.28 -
   30.29 -package java.io;
   30.30 -
   30.31 -/**
   30.32 - * Indicates that one or more deserialized objects failed validation
   30.33 - * tests.  The argument should provide the reason for the failure.
   30.34 - *
   30.35 - * @see ObjectInputValidation
   30.36 - * @since JDK1.1
   30.37 - *
   30.38 - * @author  unascribed
   30.39 - * @since   JDK1.1
   30.40 - */
   30.41 -public class InvalidObjectException extends ObjectStreamException {
   30.42 -
   30.43 -    private static final long serialVersionUID = 3233174318281839583L;
   30.44 -
   30.45 -    /**
   30.46 -     * Constructs an <code>InvalidObjectException</code>.
   30.47 -     * @param reason Detailed message explaining the reason for the failure.
   30.48 -     *
   30.49 -     * @see ObjectInputValidation
   30.50 -     */
   30.51 -    public  InvalidObjectException(String reason) {
   30.52 -        super(reason);
   30.53 -    }
   30.54 -}
    31.1 --- a/emul/compact/src/main/java/java/io/NotActiveException.java	Mon Feb 25 19:00:08 2013 +0100
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,53 +0,0 @@
    31.4 -/*
    31.5 - * Copyright (c) 1996, 2005, 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 - * Thrown when serialization or deserialization is not active.
   31.33 - *
   31.34 - * @author  unascribed
   31.35 - * @since   JDK1.1
   31.36 - */
   31.37 -public class NotActiveException extends ObjectStreamException {
   31.38 -
   31.39 -    private static final long serialVersionUID = -3893467273049808895L;
   31.40 -
   31.41 -    /**
   31.42 -     * Constructor to create a new NotActiveException with the reason given.
   31.43 -     *
   31.44 -     * @param reason  a String describing the reason for the exception.
   31.45 -     */
   31.46 -    public NotActiveException(String reason) {
   31.47 -        super(reason);
   31.48 -    }
   31.49 -
   31.50 -    /**
   31.51 -     * Constructor to create a new NotActiveException without a reason.
   31.52 -     */
   31.53 -    public NotActiveException() {
   31.54 -        super();
   31.55 -    }
   31.56 -}
    32.1 --- a/emul/compact/src/main/java/java/io/NotSerializableException.java	Mon Feb 25 19:00:08 2013 +0100
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,55 +0,0 @@
    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 - * Thrown when an instance is required to have a Serializable interface.
   32.33 - * The serialization runtime or the class of the instance can throw
   32.34 - * this exception. The argument should be the name of the class.
   32.35 - *
   32.36 - * @author  unascribed
   32.37 - * @since   JDK1.1
   32.38 - */
   32.39 -public class NotSerializableException extends ObjectStreamException {
   32.40 -
   32.41 -    private static final long serialVersionUID = 2906642554793891381L;
   32.42 -
   32.43 -    /**
   32.44 -     * Constructs a NotSerializableException object with message string.
   32.45 -     *
   32.46 -     * @param classname Class of the instance being serialized/deserialized.
   32.47 -     */
   32.48 -    public NotSerializableException(String classname) {
   32.49 -        super(classname);
   32.50 -    }
   32.51 -
   32.52 -    /**
   32.53 -     *  Constructs a NotSerializableException object.
   32.54 -     */
   32.55 -    public NotSerializableException() {
   32.56 -        super();
   32.57 -    }
   32.58 -}
    33.1 --- a/emul/compact/src/main/java/java/io/ObjectInput.java	Mon Feb 25 19:00:08 2013 +0100
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,107 +0,0 @@
    33.4 -/*
    33.5 - * Copyright (c) 1996, 2010, 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 - * ObjectInput extends the DataInput interface to include the reading of
   33.33 - * objects. DataInput includes methods for the input of primitive types,
   33.34 - * ObjectInput extends that interface to include objects, arrays, and Strings.
   33.35 - *
   33.36 - * @author  unascribed
   33.37 - * @see java.io.InputStream
   33.38 - * @see java.io.ObjectOutputStream
   33.39 - * @see java.io.ObjectInputStream
   33.40 - * @since   JDK1.1
   33.41 - */
   33.42 -public interface ObjectInput extends DataInput, AutoCloseable {
   33.43 -    /**
   33.44 -     * Read and return an object. The class that implements this interface
   33.45 -     * defines where the object is "read" from.
   33.46 -     *
   33.47 -     * @return the object read from the stream
   33.48 -     * @exception java.lang.ClassNotFoundException If the class of a serialized
   33.49 -     *      object cannot be found.
   33.50 -     * @exception IOException If any of the usual Input/Output
   33.51 -     * related exceptions occur.
   33.52 -     */
   33.53 -    public Object readObject()
   33.54 -        throws ClassNotFoundException, IOException;
   33.55 -
   33.56 -    /**
   33.57 -     * Reads a byte of data. This method will block if no input is
   33.58 -     * available.
   33.59 -     * @return  the byte read, or -1 if the end of the
   33.60 -     *          stream is reached.
   33.61 -     * @exception IOException If an I/O error has occurred.
   33.62 -     */
   33.63 -    public int read() throws IOException;
   33.64 -
   33.65 -    /**
   33.66 -     * Reads into an array of bytes.  This method will
   33.67 -     * block until some input is available.
   33.68 -     * @param b the buffer into which the data is read
   33.69 -     * @return  the actual number of bytes read, -1 is
   33.70 -     *          returned when the end of the stream is reached.
   33.71 -     * @exception IOException If an I/O error has occurred.
   33.72 -     */
   33.73 -    public int read(byte b[]) throws IOException;
   33.74 -
   33.75 -    /**
   33.76 -     * Reads into an array of bytes.  This method will
   33.77 -     * block until some input is available.
   33.78 -     * @param b the buffer into which the data is read
   33.79 -     * @param off the start offset of the data
   33.80 -     * @param len the maximum number of bytes read
   33.81 -     * @return  the actual number of bytes read, -1 is
   33.82 -     *          returned when the end of the stream is reached.
   33.83 -     * @exception IOException If an I/O error has occurred.
   33.84 -     */
   33.85 -    public int read(byte b[], int off, int len) throws IOException;
   33.86 -
   33.87 -    /**
   33.88 -     * Skips n bytes of input.
   33.89 -     * @param n the number of bytes to be skipped
   33.90 -     * @return  the actual number of bytes skipped.
   33.91 -     * @exception IOException If an I/O error has occurred.
   33.92 -     */
   33.93 -    public long skip(long n) throws IOException;
   33.94 -
   33.95 -    /**
   33.96 -     * Returns the number of bytes that can be read
   33.97 -     * without blocking.
   33.98 -     * @return the number of available bytes.
   33.99 -     * @exception IOException If an I/O error has occurred.
  33.100 -     */
  33.101 -    public int available() throws IOException;
  33.102 -
  33.103 -    /**
  33.104 -     * Closes the input stream. Must be called
  33.105 -     * to release any resources associated with
  33.106 -     * the stream.
  33.107 -     * @exception IOException If an I/O error has occurred.
  33.108 -     */
  33.109 -    public void close() throws IOException;
  33.110 -}
    34.1 --- a/emul/compact/src/main/java/java/io/ObjectInputStream.java	Mon Feb 25 19:00:08 2013 +0100
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,3357 +0,0 @@
    34.4 -/*
    34.5 - * Copyright (c) 1996, 2010, 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.io;
   34.30 -
   34.31 -import java.lang.reflect.Array;
   34.32 -import java.lang.reflect.Modifier;
   34.33 -import java.lang.reflect.Proxy;
   34.34 -import java.util.Arrays;
   34.35 -import java.util.HashMap;
   34.36 -import org.apidesign.bck2brwsr.emul.lang.System;
   34.37 -
   34.38 -/**
   34.39 - * An ObjectInputStream deserializes primitive data and objects previously
   34.40 - * written using an ObjectOutputStream.
   34.41 - *
   34.42 - * <p>ObjectOutputStream and ObjectInputStream can provide an application with
   34.43 - * persistent storage for graphs of objects when used with a FileOutputStream
   34.44 - * and FileInputStream respectively.  ObjectInputStream is used to recover
   34.45 - * those objects previously serialized. Other uses include passing objects
   34.46 - * between hosts using a socket stream or for marshaling and unmarshaling
   34.47 - * arguments and parameters in a remote communication system.
   34.48 - *
   34.49 - * <p>ObjectInputStream ensures that the types of all objects in the graph
   34.50 - * created from the stream match the classes present in the Java Virtual
   34.51 - * Machine.  Classes are loaded as required using the standard mechanisms.
   34.52 - *
   34.53 - * <p>Only objects that support the java.io.Serializable or
   34.54 - * java.io.Externalizable interface can be read from streams.
   34.55 - *
   34.56 - * <p>The method <code>readObject</code> is used to read an object from the
   34.57 - * stream.  Java's safe casting should be used to get the desired type.  In
   34.58 - * Java, strings and arrays are objects and are treated as objects during
   34.59 - * serialization. When read they need to be cast to the expected type.
   34.60 - *
   34.61 - * <p>Primitive data types can be read from the stream using the appropriate
   34.62 - * method on DataInput.
   34.63 - *
   34.64 - * <p>The default deserialization mechanism for objects restores the contents
   34.65 - * of each field to the value and type it had when it was written.  Fields
   34.66 - * declared as transient or static are ignored by the deserialization process.
   34.67 - * References to other objects cause those objects to be read from the stream
   34.68 - * as necessary.  Graphs of objects are restored correctly using a reference
   34.69 - * sharing mechanism.  New objects are always allocated when deserializing,
   34.70 - * which prevents existing objects from being overwritten.
   34.71 - *
   34.72 - * <p>Reading an object is analogous to running the constructors of a new
   34.73 - * object.  Memory is allocated for the object and initialized to zero (NULL).
   34.74 - * No-arg constructors are invoked for the non-serializable classes and then
   34.75 - * the fields of the serializable classes are restored from the stream starting
   34.76 - * with the serializable class closest to java.lang.object and finishing with
   34.77 - * the object's most specific class.
   34.78 - *
   34.79 - * <p>For example to read from a stream as written by the example in
   34.80 - * ObjectOutputStream:
   34.81 - * <br>
   34.82 - * <pre>
   34.83 - *      FileInputStream fis = new FileInputStream("t.tmp");
   34.84 - *      ObjectInputStream ois = new ObjectInputStream(fis);
   34.85 - *
   34.86 - *      int i = ois.readInt();
   34.87 - *      String today = (String) ois.readObject();
   34.88 - *      Date date = (Date) ois.readObject();
   34.89 - *
   34.90 - *      ois.close();
   34.91 - * </pre>
   34.92 - *
   34.93 - * <p>Classes control how they are serialized by implementing either the
   34.94 - * java.io.Serializable or java.io.Externalizable interfaces.
   34.95 - *
   34.96 - * <p>Implementing the Serializable interface allows object serialization to
   34.97 - * save and restore the entire state of the object and it allows classes to
   34.98 - * evolve between the time the stream is written and the time it is read.  It
   34.99 - * automatically traverses references between objects, saving and restoring
  34.100 - * entire graphs.
  34.101 - *
  34.102 - * <p>Serializable classes that require special handling during the
  34.103 - * serialization and deserialization process should implement the following
  34.104 - * methods:<p>
  34.105 - *
  34.106 - * <pre>
  34.107 - * private void writeObject(java.io.ObjectOutputStream stream)
  34.108 - *     throws IOException;
  34.109 - * private void readObject(java.io.ObjectInputStream stream)
  34.110 - *     throws IOException, ClassNotFoundException;
  34.111 - * private void readObjectNoData()
  34.112 - *     throws ObjectStreamException;
  34.113 - * </pre>
  34.114 - *
  34.115 - * <p>The readObject method is responsible for reading and restoring the state
  34.116 - * of the object for its particular class using data written to the stream by
  34.117 - * the corresponding writeObject method.  The method does not need to concern
  34.118 - * itself with the state belonging to its superclasses or subclasses.  State is
  34.119 - * restored by reading data from the ObjectInputStream for the individual
  34.120 - * fields and making assignments to the appropriate fields of the object.
  34.121 - * Reading primitive data types is supported by DataInput.
  34.122 - *
  34.123 - * <p>Any attempt to read object data which exceeds the boundaries of the
  34.124 - * custom data written by the corresponding writeObject method will cause an
  34.125 - * OptionalDataException to be thrown with an eof field value of true.
  34.126 - * Non-object reads which exceed the end of the allotted data will reflect the
  34.127 - * end of data in the same way that they would indicate the end of the stream:
  34.128 - * bytewise reads will return -1 as the byte read or number of bytes read, and
  34.129 - * primitive reads will throw EOFExceptions.  If there is no corresponding
  34.130 - * writeObject method, then the end of default serialized data marks the end of
  34.131 - * the allotted data.
  34.132 - *
  34.133 - * <p>Primitive and object read calls issued from within a readExternal method
  34.134 - * behave in the same manner--if the stream is already positioned at the end of
  34.135 - * data written by the corresponding writeExternal method, object reads will
  34.136 - * throw OptionalDataExceptions with eof set to true, bytewise reads will
  34.137 - * return -1, and primitive reads will throw EOFExceptions.  Note that this
  34.138 - * behavior does not hold for streams written with the old
  34.139 - * <code>ObjectStreamConstants.PROTOCOL_VERSION_1</code> protocol, in which the
  34.140 - * end of data written by writeExternal methods is not demarcated, and hence
  34.141 - * cannot be detected.
  34.142 - *
  34.143 - * <p>The readObjectNoData method is responsible for initializing the state of
  34.144 - * the object for its particular class in the event that the serialization
  34.145 - * stream does not list the given class as a superclass of the object being
  34.146 - * deserialized.  This may occur in cases where the receiving party uses a
  34.147 - * different version of the deserialized instance's class than the sending
  34.148 - * party, and the receiver's version extends classes that are not extended by
  34.149 - * the sender's version.  This may also occur if the serialization stream has
  34.150 - * been tampered; hence, readObjectNoData is useful for initializing
  34.151 - * deserialized objects properly despite a "hostile" or incomplete source
  34.152 - * stream.
  34.153 - *
  34.154 - * <p>Serialization does not read or assign values to the fields of any object
  34.155 - * that does not implement the java.io.Serializable interface.  Subclasses of
  34.156 - * Objects that are not serializable can be serializable. In this case the
  34.157 - * non-serializable class must have a no-arg constructor to allow its fields to
  34.158 - * be initialized.  In this case it is the responsibility of the subclass to
  34.159 - * save and restore the state of the non-serializable class. It is frequently
  34.160 - * the case that the fields of that class are accessible (public, package, or
  34.161 - * protected) or that there are get and set methods that can be used to restore
  34.162 - * the state.
  34.163 - *
  34.164 - * <p>Any exception that occurs while deserializing an object will be caught by
  34.165 - * the ObjectInputStream and abort the reading process.
  34.166 - *
  34.167 - * <p>Implementing the Externalizable interface allows the object to assume
  34.168 - * complete control over the contents and format of the object's serialized
  34.169 - * form.  The methods of the Externalizable interface, writeExternal and
  34.170 - * readExternal, are called to save and restore the objects state.  When
  34.171 - * implemented by a class they can write and read their own state using all of
  34.172 - * the methods of ObjectOutput and ObjectInput.  It is the responsibility of
  34.173 - * the objects to handle any versioning that occurs.
  34.174 - *
  34.175 - * <p>Enum constants are deserialized differently than ordinary serializable or
  34.176 - * externalizable objects.  The serialized form of an enum constant consists
  34.177 - * solely of its name; field values of the constant are not transmitted.  To
  34.178 - * deserialize an enum constant, ObjectInputStream reads the constant name from
  34.179 - * the stream; the deserialized constant is then obtained by calling the static
  34.180 - * method <code>Enum.valueOf(Class, String)</code> with the enum constant's
  34.181 - * base type and the received constant name as arguments.  Like other
  34.182 - * serializable or externalizable objects, enum constants can function as the
  34.183 - * targets of back references appearing subsequently in the serialization
  34.184 - * stream.  The process by which enum constants are deserialized cannot be
  34.185 - * customized: any class-specific readObject, readObjectNoData, and readResolve
  34.186 - * methods defined by enum types are ignored during deserialization.
  34.187 - * Similarly, any serialPersistentFields or serialVersionUID field declarations
  34.188 - * are also ignored--all enum types have a fixed serialVersionUID of 0L.
  34.189 - *
  34.190 - * @author      Mike Warres
  34.191 - * @author      Roger Riggs
  34.192 - * @see java.io.DataInput
  34.193 - * @see java.io.ObjectOutputStream
  34.194 - * @see java.io.Serializable
  34.195 - * @see <a href="../../../platform/serialization/spec/input.html"> Object Serialization Specification, Section 3, Object Input Classes</a>
  34.196 - * @since   JDK1.1
  34.197 - */
  34.198 -public class ObjectInputStream
  34.199 -    extends InputStream implements ObjectInput, ObjectStreamConstants
  34.200 -{
  34.201 -    /** handle value representing null */
  34.202 -    private static final int NULL_HANDLE = -1;
  34.203 -
  34.204 -    /** marker for unshared objects in internal handle table */
  34.205 -    private static final Object unsharedMarker = new Object();
  34.206 -
  34.207 -    /** table mapping primitive type names to corresponding class objects */
  34.208 -    private static final HashMap<String, Class<?>> primClasses
  34.209 -        = new HashMap<>(8, 1.0F);
  34.210 -    static {
  34.211 -        primClasses.put("boolean", boolean.class);
  34.212 -        primClasses.put("byte", byte.class);
  34.213 -        primClasses.put("char", char.class);
  34.214 -        primClasses.put("short", short.class);
  34.215 -        primClasses.put("int", int.class);
  34.216 -        primClasses.put("long", long.class);
  34.217 -        primClasses.put("float", float.class);
  34.218 -        primClasses.put("double", double.class);
  34.219 -        primClasses.put("void", void.class);
  34.220 -    }
  34.221 -
  34.222 -    /** filter stream for handling block data conversion */
  34.223 -    private final BlockDataInputStream bin;
  34.224 -    /** validation callback list */
  34.225 -    private final ValidationList vlist;
  34.226 -    /** recursion depth */
  34.227 -    private int depth;
  34.228 -    /** whether stream is closed */
  34.229 -    private boolean closed;
  34.230 -
  34.231 -    /** wire handle -> obj/exception map */
  34.232 -    private final HandleTable handles;
  34.233 -    /** scratch field for passing handle values up/down call stack */
  34.234 -    private int passHandle = NULL_HANDLE;
  34.235 -    /** flag set when at end of field value block with no TC_ENDBLOCKDATA */
  34.236 -    private boolean defaultDataEnd = false;
  34.237 -
  34.238 -    /** buffer for reading primitive field values */
  34.239 -    private byte[] primVals;
  34.240 -
  34.241 -    /** if true, invoke readObjectOverride() instead of readObject() */
  34.242 -    private final boolean enableOverride;
  34.243 -    /** if true, invoke resolveObject() */
  34.244 -    private boolean enableResolve;
  34.245 -
  34.246 -    /**
  34.247 -     * Context during upcalls to class-defined readObject methods; holds
  34.248 -     * object currently being deserialized and descriptor for current class.
  34.249 -     * Null when not during readObject upcall.
  34.250 -     */
  34.251 -    private Object curContext;
  34.252 -
  34.253 -    /**
  34.254 -     * Creates an ObjectInputStream that reads from the specified InputStream.
  34.255 -     * A serialization stream header is read from the stream and verified.
  34.256 -     * This constructor will block until the corresponding ObjectOutputStream
  34.257 -     * has written and flushed the header.
  34.258 -     *
  34.259 -     * <p>If a security manager is installed, this constructor will check for
  34.260 -     * the "enableSubclassImplementation" SerializablePermission when invoked
  34.261 -     * directly or indirectly by the constructor of a subclass which overrides
  34.262 -     * the ObjectInputStream.readFields or ObjectInputStream.readUnshared
  34.263 -     * methods.
  34.264 -     *
  34.265 -     * @param   in input stream to read from
  34.266 -     * @throws  StreamCorruptedException if the stream header is incorrect
  34.267 -     * @throws  IOException if an I/O error occurs while reading stream header
  34.268 -     * @throws  SecurityException if untrusted subclass illegally overrides
  34.269 -     *          security-sensitive methods
  34.270 -     * @throws  NullPointerException if <code>in</code> is <code>null</code>
  34.271 -     * @see     ObjectInputStream#ObjectInputStream()
  34.272 -     * @see     ObjectInputStream#readFields()
  34.273 -     * @see     ObjectOutputStream#ObjectOutputStream(OutputStream)
  34.274 -     */
  34.275 -    public ObjectInputStream(InputStream in) throws IOException {
  34.276 -        verifySubclass();
  34.277 -        bin = new BlockDataInputStream(in);
  34.278 -        handles = new HandleTable(10);
  34.279 -        vlist = new ValidationList();
  34.280 -        enableOverride = false;
  34.281 -        readStreamHeader();
  34.282 -        bin.setBlockDataMode(true);
  34.283 -    }
  34.284 -
  34.285 -    /**
  34.286 -     * Provide a way for subclasses that are completely reimplementing
  34.287 -     * ObjectInputStream to not have to allocate private data just used by this
  34.288 -     * implementation of ObjectInputStream.
  34.289 -     *
  34.290 -     * <p>If there is a security manager installed, this method first calls the
  34.291 -     * security manager's <code>checkPermission</code> method with the
  34.292 -     * <code>SerializablePermission("enableSubclassImplementation")</code>
  34.293 -     * permission to ensure it's ok to enable subclassing.
  34.294 -     *
  34.295 -     * @throws  SecurityException if a security manager exists and its
  34.296 -     *          <code>checkPermission</code> method denies enabling
  34.297 -     *          subclassing.
  34.298 -     * @see SecurityManager#checkPermission
  34.299 -     * @see java.io.SerializablePermission
  34.300 -     */
  34.301 -    protected ObjectInputStream() throws IOException, SecurityException {
  34.302 -        throw new SecurityException();
  34.303 -    }
  34.304 -
  34.305 -    /**
  34.306 -     * Read an object from the ObjectInputStream.  The class of the object, the
  34.307 -     * signature of the class, and the values of the non-transient and
  34.308 -     * non-static fields of the class and all of its supertypes are read.
  34.309 -     * Default deserializing for a class can be overriden using the writeObject
  34.310 -     * and readObject methods.  Objects referenced by this object are read
  34.311 -     * transitively so that a complete equivalent graph of objects is
  34.312 -     * reconstructed by readObject.
  34.313 -     *
  34.314 -     * <p>The root object is completely restored when all of its fields and the
  34.315 -     * objects it references are completely restored.  At this point the object
  34.316 -     * validation callbacks are executed in order based on their registered
  34.317 -     * priorities. The callbacks are registered by objects (in the readObject
  34.318 -     * special methods) as they are individually restored.
  34.319 -     *
  34.320 -     * <p>Exceptions are thrown for problems with the InputStream and for
  34.321 -     * classes that should not be deserialized.  All exceptions are fatal to
  34.322 -     * the InputStream and leave it in an indeterminate state; it is up to the
  34.323 -     * caller to ignore or recover the stream state.
  34.324 -     *
  34.325 -     * @throws  ClassNotFoundException Class of a serialized object cannot be
  34.326 -     *          found.
  34.327 -     * @throws  InvalidClassException Something is wrong with a class used by
  34.328 -     *          serialization.
  34.329 -     * @throws  StreamCorruptedException Control information in the
  34.330 -     *          stream is inconsistent.
  34.331 -     * @throws  OptionalDataException Primitive data was found in the
  34.332 -     *          stream instead of objects.
  34.333 -     * @throws  IOException Any of the usual Input/Output related exceptions.
  34.334 -     */
  34.335 -    public final Object readObject()
  34.336 -        throws IOException, ClassNotFoundException
  34.337 -    {
  34.338 -        throw new IOException();
  34.339 -    }
  34.340 -
  34.341 -    /**
  34.342 -     * This method is called by trusted subclasses of ObjectOutputStream that
  34.343 -     * constructed ObjectOutputStream using the protected no-arg constructor.
  34.344 -     * The subclass is expected to provide an override method with the modifier
  34.345 -     * "final".
  34.346 -     *
  34.347 -     * @return  the Object read from the stream.
  34.348 -     * @throws  ClassNotFoundException Class definition of a serialized object
  34.349 -     *          cannot be found.
  34.350 -     * @throws  OptionalDataException Primitive data was found in the stream
  34.351 -     *          instead of objects.
  34.352 -     * @throws  IOException if I/O errors occurred while reading from the
  34.353 -     *          underlying stream
  34.354 -     * @see #ObjectInputStream()
  34.355 -     * @see #readObject()
  34.356 -     * @since 1.2
  34.357 -     */
  34.358 -    protected Object readObjectOverride()
  34.359 -        throws IOException, ClassNotFoundException
  34.360 -    {
  34.361 -        return null;
  34.362 -    }
  34.363 -
  34.364 -    /**
  34.365 -     * Reads an "unshared" object from the ObjectInputStream.  This method is
  34.366 -     * identical to readObject, except that it prevents subsequent calls to
  34.367 -     * readObject and readUnshared from returning additional references to the
  34.368 -     * deserialized instance obtained via this call.  Specifically:
  34.369 -     * <ul>
  34.370 -     *   <li>If readUnshared is called to deserialize a back-reference (the
  34.371 -     *       stream representation of an object which has been written
  34.372 -     *       previously to the stream), an ObjectStreamException will be
  34.373 -     *       thrown.
  34.374 -     *
  34.375 -     *   <li>If readUnshared returns successfully, then any subsequent attempts
  34.376 -     *       to deserialize back-references to the stream handle deserialized
  34.377 -     *       by readUnshared will cause an ObjectStreamException to be thrown.
  34.378 -     * </ul>
  34.379 -     * Deserializing an object via readUnshared invalidates the stream handle
  34.380 -     * associated with the returned object.  Note that this in itself does not
  34.381 -     * always guarantee that the reference returned by readUnshared is unique;
  34.382 -     * the deserialized object may define a readResolve method which returns an
  34.383 -     * object visible to other parties, or readUnshared may return a Class
  34.384 -     * object or enum constant obtainable elsewhere in the stream or through
  34.385 -     * external means. If the deserialized object defines a readResolve method
  34.386 -     * and the invocation of that method returns an array, then readUnshared
  34.387 -     * returns a shallow clone of that array; this guarantees that the returned
  34.388 -     * array object is unique and cannot be obtained a second time from an
  34.389 -     * invocation of readObject or readUnshared on the ObjectInputStream,
  34.390 -     * even if the underlying data stream has been manipulated.
  34.391 -     *
  34.392 -     * <p>ObjectInputStream subclasses which override this method can only be
  34.393 -     * constructed in security contexts possessing the
  34.394 -     * "enableSubclassImplementation" SerializablePermission; any attempt to
  34.395 -     * instantiate such a subclass without this permission will cause a
  34.396 -     * SecurityException to be thrown.
  34.397 -     *
  34.398 -     * @return  reference to deserialized object
  34.399 -     * @throws  ClassNotFoundException if class of an object to deserialize
  34.400 -     *          cannot be found
  34.401 -     * @throws  StreamCorruptedException if control information in the stream
  34.402 -     *          is inconsistent
  34.403 -     * @throws  ObjectStreamException if object to deserialize has already
  34.404 -     *          appeared in stream
  34.405 -     * @throws  OptionalDataException if primitive data is next in stream
  34.406 -     * @throws  IOException if an I/O error occurs during deserialization
  34.407 -     * @since   1.4
  34.408 -     */
  34.409 -    public Object readUnshared() throws IOException, ClassNotFoundException {
  34.410 -        // if nested read, passHandle contains handle of enclosing object
  34.411 -        int outerHandle = passHandle;
  34.412 -        try {
  34.413 -            Object obj = readObject0(true);
  34.414 -            handles.markDependency(outerHandle, passHandle);
  34.415 -            ClassNotFoundException ex = handles.lookupException(passHandle);
  34.416 -            if (ex != null) {
  34.417 -                throw ex;
  34.418 -            }
  34.419 -            if (depth == 0) {
  34.420 -                vlist.doCallbacks();
  34.421 -            }
  34.422 -            return obj;
  34.423 -        } finally {
  34.424 -            passHandle = outerHandle;
  34.425 -            if (closed && depth == 0) {
  34.426 -                clear();
  34.427 -            }
  34.428 -        }
  34.429 -    }
  34.430 -
  34.431 -    /**
  34.432 -     * Read the non-static and non-transient fields of the current class from
  34.433 -     * this stream.  This may only be called from the readObject method of the
  34.434 -     * class being deserialized. It will throw the NotActiveException if it is
  34.435 -     * called otherwise.
  34.436 -     *
  34.437 -     * @throws  ClassNotFoundException if the class of a serialized object
  34.438 -     *          could not be found.
  34.439 -     * @throws  IOException if an I/O error occurs.
  34.440 -     * @throws  NotActiveException if the stream is not currently reading
  34.441 -     *          objects.
  34.442 -     */
  34.443 -    public void defaultReadObject()
  34.444 -        throws IOException, ClassNotFoundException
  34.445 -    {
  34.446 -        if (curContext == null) {
  34.447 -            throw new NotActiveException("not in call to readObject");
  34.448 -        }
  34.449 -        Object curObj = null; // curContext.getObj();
  34.450 -        ObjectStreamClass curDesc = null; // curContext.getDesc();
  34.451 -        bin.setBlockDataMode(false);
  34.452 -        defaultReadFields(curObj, curDesc);
  34.453 -        bin.setBlockDataMode(true);
  34.454 -        if (!curDesc.hasWriteObjectData()) {
  34.455 -            /*
  34.456 -             * Fix for 4360508: since stream does not contain terminating
  34.457 -             * TC_ENDBLOCKDATA tag, set flag so that reading code elsewhere
  34.458 -             * knows to simulate end-of-custom-data behavior.
  34.459 -             */
  34.460 -            defaultDataEnd = true;
  34.461 -        }
  34.462 -        ClassNotFoundException ex = handles.lookupException(passHandle);
  34.463 -        if (ex != null) {
  34.464 -            throw ex;
  34.465 -        }
  34.466 -    }
  34.467 -
  34.468 -    /**
  34.469 -     * Reads the persistent fields from the stream and makes them available by
  34.470 -     * name.
  34.471 -     *
  34.472 -     * @return  the <code>GetField</code> object representing the persistent
  34.473 -     *          fields of the object being deserialized
  34.474 -     * @throws  ClassNotFoundException if the class of a serialized object
  34.475 -     *          could not be found.
  34.476 -     * @throws  IOException if an I/O error occurs.
  34.477 -     * @throws  NotActiveException if the stream is not currently reading
  34.478 -     *          objects.
  34.479 -     * @since 1.2
  34.480 -     */
  34.481 -    public ObjectInputStream.GetField readFields()
  34.482 -        throws IOException, ClassNotFoundException
  34.483 -    {
  34.484 -        if (curContext == null) {
  34.485 -            throw new NotActiveException("not in call to readObject");
  34.486 -        }
  34.487 -        Object curObj = null; // curContext.getObj();
  34.488 -        ObjectStreamClass curDesc = null; // curContext.getDesc();
  34.489 -        bin.setBlockDataMode(false);
  34.490 -        GetFieldImpl getField = new GetFieldImpl(curDesc);
  34.491 -        getField.readFields();
  34.492 -        bin.setBlockDataMode(true);
  34.493 -        if (!curDesc.hasWriteObjectData()) {
  34.494 -            /*
  34.495 -             * Fix for 4360508: since stream does not contain terminating
  34.496 -             * TC_ENDBLOCKDATA tag, set flag so that reading code elsewhere
  34.497 -             * knows to simulate end-of-custom-data behavior.
  34.498 -             */
  34.499 -            defaultDataEnd = true;
  34.500 -        }
  34.501 -
  34.502 -        return getField;
  34.503 -    }
  34.504 -
  34.505 -    /**
  34.506 -     * Register an object to be validated before the graph is returned.  While
  34.507 -     * similar to resolveObject these validations are called after the entire
  34.508 -     * graph has been reconstituted.  Typically, a readObject method will
  34.509 -     * register the object with the stream so that when all of the objects are
  34.510 -     * restored a final set of validations can be performed.
  34.511 -     *
  34.512 -     * @param   obj the object to receive the validation callback.
  34.513 -     * @param   prio controls the order of callbacks;zero is a good default.
  34.514 -     *          Use higher numbers to be called back earlier, lower numbers for
  34.515 -     *          later callbacks. Within a priority, callbacks are processed in
  34.516 -     *          no particular order.
  34.517 -     * @throws  NotActiveException The stream is not currently reading objects
  34.518 -     *          so it is invalid to register a callback.
  34.519 -     * @throws  InvalidObjectException The validation object is null.
  34.520 -     */
  34.521 -    public void registerValidation(ObjectInputValidation obj, int prio)
  34.522 -        throws NotActiveException, InvalidObjectException
  34.523 -    {
  34.524 -        if (depth == 0) {
  34.525 -            throw new NotActiveException("stream inactive");
  34.526 -        }
  34.527 -        vlist.register(obj, prio);
  34.528 -    }
  34.529 -
  34.530 -    /**
  34.531 -     * Load the local class equivalent of the specified stream class
  34.532 -     * description.  Subclasses may implement this method to allow classes to
  34.533 -     * be fetched from an alternate source.
  34.534 -     *
  34.535 -     * <p>The corresponding method in <code>ObjectOutputStream</code> is
  34.536 -     * <code>annotateClass</code>.  This method will be invoked only once for
  34.537 -     * each unique class in the stream.  This method can be implemented by
  34.538 -     * subclasses to use an alternate loading mechanism but must return a
  34.539 -     * <code>Class</code> object. Once returned, if the class is not an array
  34.540 -     * class, its serialVersionUID is compared to the serialVersionUID of the
  34.541 -     * serialized class, and if there is a mismatch, the deserialization fails
  34.542 -     * and an {@link InvalidClassException} is thrown.
  34.543 -     *
  34.544 -     * <p>The default implementation of this method in
  34.545 -     * <code>ObjectInputStream</code> returns the result of calling
  34.546 -     * <pre>
  34.547 -     *     Class.forName(desc.getName(), false, loader)
  34.548 -     * </pre>
  34.549 -     * where <code>loader</code> is determined as follows: if there is a
  34.550 -     * method on the current thread's stack whose declaring class was
  34.551 -     * defined by a user-defined class loader (and was not a generated to
  34.552 -     * implement reflective invocations), then <code>loader</code> is class
  34.553 -     * loader corresponding to the closest such method to the currently
  34.554 -     * executing frame; otherwise, <code>loader</code> is
  34.555 -     * <code>null</code>. If this call results in a
  34.556 -     * <code>ClassNotFoundException</code> and the name of the passed
  34.557 -     * <code>ObjectStreamClass</code> instance is the Java language keyword
  34.558 -     * for a primitive type or void, then the <code>Class</code> object
  34.559 -     * representing that primitive type or void will be returned
  34.560 -     * (e.g., an <code>ObjectStreamClass</code> with the name
  34.561 -     * <code>"int"</code> will be resolved to <code>Integer.TYPE</code>).
  34.562 -     * Otherwise, the <code>ClassNotFoundException</code> will be thrown to
  34.563 -     * the caller of this method.
  34.564 -     *
  34.565 -     * @param   desc an instance of class <code>ObjectStreamClass</code>
  34.566 -     * @return  a <code>Class</code> object corresponding to <code>desc</code>
  34.567 -     * @throws  IOException any of the usual Input/Output exceptions.
  34.568 -     * @throws  ClassNotFoundException if class of a serialized object cannot
  34.569 -     *          be found.
  34.570 -     */
  34.571 -    protected Class<?> resolveClass(ObjectStreamClass desc)
  34.572 -        throws IOException, ClassNotFoundException
  34.573 -    {
  34.574 -        String name = desc.getName();
  34.575 -        try {
  34.576 -            return Class.forName(name, false, latestUserDefinedLoader());
  34.577 -        } catch (ClassNotFoundException ex) {
  34.578 -            Class<?> cl = primClasses.get(name);
  34.579 -            if (cl != null) {
  34.580 -                return cl;
  34.581 -            } else {
  34.582 -                throw ex;
  34.583 -            }
  34.584 -        }
  34.585 -    }
  34.586 -
  34.587 -    /**
  34.588 -     * Returns a proxy class that implements the interfaces named in a proxy
  34.589 -     * class descriptor; subclasses may implement this method to read custom
  34.590 -     * data from the stream along with the descriptors for dynamic proxy
  34.591 -     * classes, allowing them to use an alternate loading mechanism for the
  34.592 -     * interfaces and the proxy class.
  34.593 -     *
  34.594 -     * <p>This method is called exactly once for each unique proxy class
  34.595 -     * descriptor in the stream.
  34.596 -     *
  34.597 -     * <p>The corresponding method in <code>ObjectOutputStream</code> is
  34.598 -     * <code>annotateProxyClass</code>.  For a given subclass of
  34.599 -     * <code>ObjectInputStream</code> that overrides this method, the
  34.600 -     * <code>annotateProxyClass</code> method in the corresponding subclass of
  34.601 -     * <code>ObjectOutputStream</code> must write any data or objects read by
  34.602 -     * this method.
  34.603 -     *
  34.604 -     * <p>The default implementation of this method in
  34.605 -     * <code>ObjectInputStream</code> returns the result of calling
  34.606 -     * <code>Proxy.getProxyClass</code> with the list of <code>Class</code>
  34.607 -     * objects for the interfaces that are named in the <code>interfaces</code>
  34.608 -     * parameter.  The <code>Class</code> object for each interface name
  34.609 -     * <code>i</code> is the value returned by calling
  34.610 -     * <pre>
  34.611 -     *     Class.forName(i, false, loader)
  34.612 -     * </pre>
  34.613 -     * where <code>loader</code> is that of the first non-<code>null</code>
  34.614 -     * class loader up the execution stack, or <code>null</code> if no
  34.615 -     * non-<code>null</code> class loaders are on the stack (the same class
  34.616 -     * loader choice used by the <code>resolveClass</code> method).  Unless any
  34.617 -     * of the resolved interfaces are non-public, this same value of
  34.618 -     * <code>loader</code> is also the class loader passed to
  34.619 -     * <code>Proxy.getProxyClass</code>; if non-public interfaces are present,
  34.620 -     * their class loader is passed instead (if more than one non-public
  34.621 -     * interface class loader is encountered, an
  34.622 -     * <code>IllegalAccessError</code> is thrown).
  34.623 -     * If <code>Proxy.getProxyClass</code> throws an
  34.624 -     * <code>IllegalArgumentException</code>, <code>resolveProxyClass</code>
  34.625 -     * will throw a <code>ClassNotFoundException</code> containing the
  34.626 -     * <code>IllegalArgumentException</code>.
  34.627 -     *
  34.628 -     * @param interfaces the list of interface names that were
  34.629 -     *                deserialized in the proxy class descriptor
  34.630 -     * @return  a proxy class for the specified interfaces
  34.631 -     * @throws        IOException any exception thrown by the underlying
  34.632 -     *                <code>InputStream</code>
  34.633 -     * @throws        ClassNotFoundException if the proxy class or any of the
  34.634 -     *                named interfaces could not be found
  34.635 -     * @see ObjectOutputStream#annotateProxyClass(Class)
  34.636 -     * @since 1.3
  34.637 -     */
  34.638 -    protected Class<?> resolveProxyClass(String[] interfaces)
  34.639 -        throws IOException, ClassNotFoundException
  34.640 -    {
  34.641 -        ClassLoader latestLoader = latestUserDefinedLoader();
  34.642 -        ClassLoader nonPublicLoader = null;
  34.643 -        boolean hasNonPublicInterface = false;
  34.644 -
  34.645 -        // define proxy in class loader of non-public interface(s), if any
  34.646 -        Class[] classObjs = new Class[interfaces.length];
  34.647 -        for (int i = 0; i < interfaces.length; i++) {
  34.648 -            Class cl = Class.forName(interfaces[i], false, latestLoader);
  34.649 -            if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
  34.650 -                if (hasNonPublicInterface) {
  34.651 -                    if (nonPublicLoader != cl.getClassLoader()) {
  34.652 -                        throw new IllegalAccessError(
  34.653 -                            "conflicting non-public interface class loaders");
  34.654 -                    }
  34.655 -                } else {
  34.656 -                    nonPublicLoader = cl.getClassLoader();
  34.657 -                    hasNonPublicInterface = true;
  34.658 -                }
  34.659 -            }
  34.660 -            classObjs[i] = cl;
  34.661 -        }
  34.662 -        try {
  34.663 -            return Proxy.getProxyClass(
  34.664 -                hasNonPublicInterface ? nonPublicLoader : latestLoader,
  34.665 -                classObjs);
  34.666 -        } catch (IllegalArgumentException e) {
  34.667 -            throw new ClassNotFoundException(null, e);
  34.668 -        }
  34.669 -    }
  34.670 -
  34.671 -    /**
  34.672 -     * This method will allow trusted subclasses of ObjectInputStream to
  34.673 -     * substitute one object for another during deserialization. Replacing
  34.674 -     * objects is disabled until enableResolveObject is called. The
  34.675 -     * enableResolveObject method checks that the stream requesting to resolve
  34.676 -     * object can be trusted. Every reference to serializable objects is passed
  34.677 -     * to resolveObject.  To insure that the private state of objects is not
  34.678 -     * unintentionally exposed only trusted streams may use resolveObject.
  34.679 -     *
  34.680 -     * <p>This method is called after an object has been read but before it is
  34.681 -     * returned from readObject.  The default resolveObject method just returns
  34.682 -     * the same object.
  34.683 -     *
  34.684 -     * <p>When a subclass is replacing objects it must insure that the
  34.685 -     * substituted object is compatible with every field where the reference
  34.686 -     * will be stored.  Objects whose type is not a subclass of the type of the
  34.687 -     * field or array element abort the serialization by raising an exception
  34.688 -     * and the object is not be stored.
  34.689 -     *
  34.690 -     * <p>This method is called only once when each object is first
  34.691 -     * encountered.  All subsequent references to the object will be redirected
  34.692 -     * to the new object.
  34.693 -     *
  34.694 -     * @param   obj object to be substituted
  34.695 -     * @return  the substituted object
  34.696 -     * @throws  IOException Any of the usual Input/Output exceptions.
  34.697 -     */
  34.698 -    protected Object resolveObject(Object obj) throws IOException {
  34.699 -        return obj;
  34.700 -    }
  34.701 -
  34.702 -    /**
  34.703 -     * Enable the stream to allow objects read from the stream to be replaced.
  34.704 -     * When enabled, the resolveObject method is called for every object being
  34.705 -     * deserialized.
  34.706 -     *
  34.707 -     * <p>If <i>enable</i> is true, and there is a security manager installed,
  34.708 -     * this method first calls the security manager's
  34.709 -     * <code>checkPermission</code> method with the
  34.710 -     * <code>SerializablePermission("enableSubstitution")</code> permission to
  34.711 -     * ensure it's ok to enable the stream to allow objects read from the
  34.712 -     * stream to be replaced.
  34.713 -     *
  34.714 -     * @param   enable true for enabling use of <code>resolveObject</code> for
  34.715 -     *          every object being deserialized
  34.716 -     * @return  the previous setting before this method was invoked
  34.717 -     * @throws  SecurityException if a security manager exists and its
  34.718 -     *          <code>checkPermission</code> method denies enabling the stream
  34.719 -     *          to allow objects read from the stream to be replaced.
  34.720 -     * @see SecurityManager#checkPermission
  34.721 -     * @see java.io.SerializablePermission
  34.722 -     */
  34.723 -    protected boolean enableResolveObject(boolean enable)
  34.724 -        throws SecurityException
  34.725 -    {
  34.726 -        throw new SecurityException();
  34.727 -    }
  34.728 -
  34.729 -    /**
  34.730 -     * The readStreamHeader method is provided to allow subclasses to read and
  34.731 -     * verify their own stream headers. It reads and verifies the magic number
  34.732 -     * and version number.
  34.733 -     *
  34.734 -     * @throws  IOException if there are I/O errors while reading from the
  34.735 -     *          underlying <code>InputStream</code>
  34.736 -     * @throws  StreamCorruptedException if control information in the stream
  34.737 -     *          is inconsistent
  34.738 -     */
  34.739 -    protected void readStreamHeader()
  34.740 -        throws IOException, StreamCorruptedException
  34.741 -    {
  34.742 -        short s0 = bin.readShort();
  34.743 -        short s1 = bin.readShort();
  34.744 -        if (s0 != STREAM_MAGIC || s1 != STREAM_VERSION) {
  34.745 -            throw new StreamCorruptedException(
  34.746 -                String.format("invalid stream header: %04X%04X", s0, s1));
  34.747 -        }
  34.748 -    }
  34.749 -
  34.750 -    /**
  34.751 -     * Read a class descriptor from the serialization stream.  This method is
  34.752 -     * called when the ObjectInputStream expects a class descriptor as the next
  34.753 -     * item in the serialization stream.  Subclasses of ObjectInputStream may
  34.754 -     * override this method to read in class descriptors that have been written
  34.755 -     * in non-standard formats (by subclasses of ObjectOutputStream which have
  34.756 -     * overridden the <code>writeClassDescriptor</code> method).  By default,
  34.757 -     * this method reads class descriptors according to the format defined in
  34.758 -     * the Object Serialization specification.
  34.759 -     *
  34.760 -     * @return  the class descriptor read
  34.761 -     * @throws  IOException If an I/O error has occurred.
  34.762 -     * @throws  ClassNotFoundException If the Class of a serialized object used
  34.763 -     *          in the class descriptor representation cannot be found
  34.764 -     * @see java.io.ObjectOutputStream#writeClassDescriptor(java.io.ObjectStreamClass)
  34.765 -     * @since 1.3
  34.766 -     */
  34.767 -    protected ObjectStreamClass readClassDescriptor()
  34.768 -        throws IOException, ClassNotFoundException
  34.769 -    {
  34.770 -        ObjectStreamClass desc = new ObjectStreamClass();
  34.771 -        desc.readNonProxy(this);
  34.772 -        return desc;
  34.773 -    }
  34.774 -
  34.775 -    /**
  34.776 -     * Reads a byte of data. This method will block if no input is available.
  34.777 -     *
  34.778 -     * @return  the byte read, or -1 if the end of the stream is reached.
  34.779 -     * @throws  IOException If an I/O error has occurred.
  34.780 -     */
  34.781 -    public int read() throws IOException {
  34.782 -        return bin.read();
  34.783 -    }
  34.784 -
  34.785 -    /**
  34.786 -     * Reads into an array of bytes.  This method will block until some input
  34.787 -     * is available. Consider using java.io.DataInputStream.readFully to read
  34.788 -     * exactly 'length' bytes.
  34.789 -     *
  34.790 -     * @param   buf the buffer into which the data is read
  34.791 -     * @param   off the start offset of the data
  34.792 -     * @param   len the maximum number of bytes read
  34.793 -     * @return  the actual number of bytes read, -1 is returned when the end of
  34.794 -     *          the stream is reached.
  34.795 -     * @throws  IOException If an I/O error has occurred.
  34.796 -     * @see java.io.DataInputStream#readFully(byte[],int,int)
  34.797 -     */
  34.798 -    public int read(byte[] buf, int off, int len) throws IOException {
  34.799 -        if (buf == null) {
  34.800 -            throw new NullPointerException();
  34.801 -        }
  34.802 -        int endoff = off + len;
  34.803 -        if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
  34.804 -            throw new IndexOutOfBoundsException();
  34.805 -        }
  34.806 -        return bin.read(buf, off, len, false);
  34.807 -    }
  34.808 -
  34.809 -    /**
  34.810 -     * Returns the number of bytes that can be read without blocking.
  34.811 -     *
  34.812 -     * @return  the number of available bytes.
  34.813 -     * @throws  IOException if there are I/O errors while reading from the
  34.814 -     *          underlying <code>InputStream</code>
  34.815 -     */
  34.816 -    public int available() throws IOException {
  34.817 -        return bin.available();
  34.818 -    }
  34.819 -
  34.820 -    /**
  34.821 -     * Closes the input stream. Must be called to release any resources
  34.822 -     * associated with the stream.
  34.823 -     *
  34.824 -     * @throws  IOException If an I/O error has occurred.
  34.825 -     */
  34.826 -    public void close() throws IOException {
  34.827 -        /*
  34.828 -         * Even if stream already closed, propagate redundant close to
  34.829 -         * underlying stream to stay consistent with previous implementations.
  34.830 -         */
  34.831 -        closed = true;
  34.832 -        if (depth == 0) {
  34.833 -            clear();
  34.834 -        }
  34.835 -        bin.close();
  34.836 -    }
  34.837 -
  34.838 -    /**
  34.839 -     * Reads in a boolean.
  34.840 -     *
  34.841 -     * @return  the boolean read.
  34.842 -     * @throws  EOFException If end of file is reached.
  34.843 -     * @throws  IOException If other I/O error has occurred.
  34.844 -     */
  34.845 -    public boolean readBoolean() throws IOException {
  34.846 -        return bin.readBoolean();
  34.847 -    }
  34.848 -
  34.849 -    /**
  34.850 -     * Reads an 8 bit byte.
  34.851 -     *
  34.852 -     * @return  the 8 bit byte read.
  34.853 -     * @throws  EOFException If end of file is reached.
  34.854 -     * @throws  IOException If other I/O error has occurred.
  34.855 -     */
  34.856 -    public byte readByte() throws IOException  {
  34.857 -        return bin.readByte();
  34.858 -    }
  34.859 -
  34.860 -    /**
  34.861 -     * Reads an unsigned 8 bit byte.
  34.862 -     *
  34.863 -     * @return  the 8 bit byte read.
  34.864 -     * @throws  EOFException If end of file is reached.
  34.865 -     * @throws  IOException If other I/O error has occurred.
  34.866 -     */
  34.867 -    public int readUnsignedByte()  throws IOException {
  34.868 -        return bin.readUnsignedByte();
  34.869 -    }
  34.870 -
  34.871 -    /**
  34.872 -     * Reads a 16 bit char.
  34.873 -     *
  34.874 -     * @return  the 16 bit char read.
  34.875 -     * @throws  EOFException If end of file is reached.
  34.876 -     * @throws  IOException If other I/O error has occurred.
  34.877 -     */
  34.878 -    public char readChar()  throws IOException {
  34.879 -        return bin.readChar();
  34.880 -    }
  34.881 -
  34.882 -    /**
  34.883 -     * Reads a 16 bit short.
  34.884 -     *
  34.885 -     * @return  the 16 bit short read.
  34.886 -     * @throws  EOFException If end of file is reached.
  34.887 -     * @throws  IOException If other I/O error has occurred.
  34.888 -     */
  34.889 -    public short readShort()  throws IOException {
  34.890 -        return bin.readShort();
  34.891 -    }
  34.892 -
  34.893 -    /**
  34.894 -     * Reads an unsigned 16 bit short.
  34.895 -     *
  34.896 -     * @return  the 16 bit short read.
  34.897 -     * @throws  EOFException If end of file is reached.
  34.898 -     * @throws  IOException If other I/O error has occurred.
  34.899 -     */
  34.900 -    public int readUnsignedShort() throws IOException {
  34.901 -        return bin.readUnsignedShort();
  34.902 -    }
  34.903 -
  34.904 -    /**
  34.905 -     * Reads a 32 bit int.
  34.906 -     *
  34.907 -     * @return  the 32 bit integer read.
  34.908 -     * @throws  EOFException If end of file is reached.
  34.909 -     * @throws  IOException If other I/O error has occurred.
  34.910 -     */
  34.911 -    public int readInt()  throws IOException {
  34.912 -        return bin.readInt();
  34.913 -    }
  34.914 -
  34.915 -    /**
  34.916 -     * Reads a 64 bit long.
  34.917 -     *
  34.918 -     * @return  the read 64 bit long.
  34.919 -     * @throws  EOFException If end of file is reached.
  34.920 -     * @throws  IOException If other I/O error has occurred.
  34.921 -     */
  34.922 -    public long readLong()  throws IOException {
  34.923 -        return bin.readLong();
  34.924 -    }
  34.925 -
  34.926 -    /**
  34.927 -     * Reads a 32 bit float.
  34.928 -     *
  34.929 -     * @return  the 32 bit float read.
  34.930 -     * @throws  EOFException If end of file is reached.
  34.931 -     * @throws  IOException If other I/O error has occurred.
  34.932 -     */
  34.933 -    public float readFloat() throws IOException {
  34.934 -        return bin.readFloat();
  34.935 -    }
  34.936 -
  34.937 -    /**
  34.938 -     * Reads a 64 bit double.
  34.939 -     *
  34.940 -     * @return  the 64 bit double read.
  34.941 -     * @throws  EOFException If end of file is reached.
  34.942 -     * @throws  IOException If other I/O error has occurred.
  34.943 -     */
  34.944 -    public double readDouble() throws IOException {
  34.945 -        return bin.readDouble();
  34.946 -    }
  34.947 -
  34.948 -    /**
  34.949 -     * Reads bytes, blocking until all bytes are read.
  34.950 -     *
  34.951 -     * @param   buf the buffer into which the data is read
  34.952 -     * @throws  EOFException If end of file is reached.
  34.953 -     * @throws  IOException If other I/O error has occurred.
  34.954 -     */
  34.955 -    public void readFully(byte[] buf) throws IOException {
  34.956 -        bin.readFully(buf, 0, buf.length, false);
  34.957 -    }
  34.958 -
  34.959 -    /**
  34.960 -     * Reads bytes, blocking until all bytes are read.
  34.961 -     *
  34.962 -     * @param   buf the buffer into which the data is read
  34.963 -     * @param   off the start offset of the data
  34.964 -     * @param   len the maximum number of bytes to read
  34.965 -     * @throws  EOFException If end of file is reached.
  34.966 -     * @throws  IOException If other I/O error has occurred.
  34.967 -     */
  34.968 -    public void readFully(byte[] buf, int off, int len) throws IOException {
  34.969 -        int endoff = off + len;
  34.970 -        if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
  34.971 -            throw new IndexOutOfBoundsException();
  34.972 -        }
  34.973 -        bin.readFully(buf, off, len, false);
  34.974 -    }
  34.975 -
  34.976 -    /**
  34.977 -     * Skips bytes.
  34.978 -     *
  34.979 -     * @param   len the number of bytes to be skipped
  34.980 -     * @return  the actual number of bytes skipped.
  34.981 -     * @throws  IOException If an I/O error has occurred.
  34.982 -     */
  34.983 -    public int skipBytes(int len) throws IOException {
  34.984 -        return bin.skipBytes(len);
  34.985 -    }
  34.986 -
  34.987 -    /**
  34.988 -     * Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
  34.989 -     *
  34.990 -     * @return  a String copy of the line.
  34.991 -     * @throws  IOException if there are I/O errors while reading from the
  34.992 -     *          underlying <code>InputStream</code>
  34.993 -     * @deprecated This method does not properly convert bytes to characters.
  34.994 -     *          see DataInputStream for the details and alternatives.
  34.995 -     */
  34.996 -    @Deprecated
  34.997 -    public String readLine() throws IOException {
  34.998 -        return bin.readLine();
  34.999 -    }
 34.1000 -
 34.1001 -    /**
 34.1002 -     * Reads a String in
 34.1003 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
 34.1004 -     * format.
 34.1005 -     *
 34.1006 -     * @return  the String.
 34.1007 -     * @throws  IOException if there are I/O errors while reading from the
 34.1008 -     *          underlying <code>InputStream</code>
 34.1009 -     * @throws  UTFDataFormatException if read bytes do not represent a valid
 34.1010 -     *          modified UTF-8 encoding of a string
 34.1011 -     */
 34.1012 -    public String readUTF() throws IOException {
 34.1013 -        return bin.readUTF();
 34.1014 -    }
 34.1015 -
 34.1016 -    /**
 34.1017 -     * Provide access to the persistent fields read from the input stream.
 34.1018 -     */
 34.1019 -    public static abstract class GetField {
 34.1020 -
 34.1021 -        /**
 34.1022 -         * Get the ObjectStreamClass that describes the fields in the stream.
 34.1023 -         *
 34.1024 -         * @return  the descriptor class that describes the serializable fields
 34.1025 -         */
 34.1026 -        public abstract ObjectStreamClass getObjectStreamClass();
 34.1027 -
 34.1028 -        /**
 34.1029 -         * Return true if the named field is defaulted and has no value in this
 34.1030 -         * stream.
 34.1031 -         *
 34.1032 -         * @param  name the name of the field
 34.1033 -         * @return true, if and only if the named field is defaulted
 34.1034 -         * @throws IOException if there are I/O errors while reading from
 34.1035 -         *         the underlying <code>InputStream</code>
 34.1036 -         * @throws IllegalArgumentException if <code>name</code> does not
 34.1037 -         *         correspond to a serializable field
 34.1038 -         */
 34.1039 -        public abstract boolean defaulted(String name) throws IOException;
 34.1040 -
 34.1041 -        /**
 34.1042 -         * Get the value of the named boolean field from the persistent field.
 34.1043 -         *
 34.1044 -         * @param  name the name of the field
 34.1045 -         * @param  val the default value to use if <code>name</code> does not
 34.1046 -         *         have a value
 34.1047 -         * @return the value of the named <code>boolean</code> field
 34.1048 -         * @throws IOException if there are I/O errors while reading from the
 34.1049 -         *         underlying <code>InputStream</code>
 34.1050 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1051 -         *         not serializable or if the field type is incorrect
 34.1052 -         */
 34.1053 -        public abstract boolean get(String name, boolean val)
 34.1054 -            throws IOException;
 34.1055 -
 34.1056 -        /**
 34.1057 -         * Get the value of the named byte field from the persistent field.
 34.1058 -         *
 34.1059 -         * @param  name the name of the field
 34.1060 -         * @param  val the default value to use if <code>name</code> does not
 34.1061 -         *         have a value
 34.1062 -         * @return the value of the named <code>byte</code> field
 34.1063 -         * @throws IOException if there are I/O errors while reading from the
 34.1064 -         *         underlying <code>InputStream</code>
 34.1065 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1066 -         *         not serializable or if the field type is incorrect
 34.1067 -         */
 34.1068 -        public abstract byte get(String name, byte val) throws IOException;
 34.1069 -
 34.1070 -        /**
 34.1071 -         * Get the value of the named char field from the persistent field.
 34.1072 -         *
 34.1073 -         * @param  name the name of the field
 34.1074 -         * @param  val the default value to use if <code>name</code> does not
 34.1075 -         *         have a value
 34.1076 -         * @return the value of the named <code>char</code> field
 34.1077 -         * @throws IOException if there are I/O errors while reading from the
 34.1078 -         *         underlying <code>InputStream</code>
 34.1079 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1080 -         *         not serializable or if the field type is incorrect
 34.1081 -         */
 34.1082 -        public abstract char get(String name, char val) throws IOException;
 34.1083 -
 34.1084 -        /**
 34.1085 -         * Get the value of the named short field from the persistent field.
 34.1086 -         *
 34.1087 -         * @param  name the name of the field
 34.1088 -         * @param  val the default value to use if <code>name</code> does not
 34.1089 -         *         have a value
 34.1090 -         * @return the value of the named <code>short</code> field
 34.1091 -         * @throws IOException if there are I/O errors while reading from the
 34.1092 -         *         underlying <code>InputStream</code>
 34.1093 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1094 -         *         not serializable or if the field type is incorrect
 34.1095 -         */
 34.1096 -        public abstract short get(String name, short val) throws IOException;
 34.1097 -
 34.1098 -        /**
 34.1099 -         * Get the value of the named int field from the persistent field.
 34.1100 -         *
 34.1101 -         * @param  name the name of the field
 34.1102 -         * @param  val the default value to use if <code>name</code> does not
 34.1103 -         *         have a value
 34.1104 -         * @return the value of the named <code>int</code> field
 34.1105 -         * @throws IOException if there are I/O errors while reading from the
 34.1106 -         *         underlying <code>InputStream</code>
 34.1107 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1108 -         *         not serializable or if the field type is incorrect
 34.1109 -         */
 34.1110 -        public abstract int get(String name, int val) throws IOException;
 34.1111 -
 34.1112 -        /**
 34.1113 -         * Get the value of the named long field from the persistent field.
 34.1114 -         *
 34.1115 -         * @param  name the name of the field
 34.1116 -         * @param  val the default value to use if <code>name</code> does not
 34.1117 -         *         have a value
 34.1118 -         * @return the value of the named <code>long</code> field
 34.1119 -         * @throws IOException if there are I/O errors while reading from the
 34.1120 -         *         underlying <code>InputStream</code>
 34.1121 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1122 -         *         not serializable or if the field type is incorrect
 34.1123 -         */
 34.1124 -        public abstract long get(String name, long val) throws IOException;
 34.1125 -
 34.1126 -        /**
 34.1127 -         * Get the value of the named float field from the persistent field.
 34.1128 -         *
 34.1129 -         * @param  name the name of the field
 34.1130 -         * @param  val the default value to use if <code>name</code> does not
 34.1131 -         *         have a value
 34.1132 -         * @return the value of the named <code>float</code> field
 34.1133 -         * @throws IOException if there are I/O errors while reading from the
 34.1134 -         *         underlying <code>InputStream</code>
 34.1135 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1136 -         *         not serializable or if the field type is incorrect
 34.1137 -         */
 34.1138 -        public abstract float get(String name, float val) throws IOException;
 34.1139 -
 34.1140 -        /**
 34.1141 -         * Get the value of the named double field from the persistent field.
 34.1142 -         *
 34.1143 -         * @param  name the name of the field
 34.1144 -         * @param  val the default value to use if <code>name</code> does not
 34.1145 -         *         have a value
 34.1146 -         * @return the value of the named <code>double</code> field
 34.1147 -         * @throws IOException if there are I/O errors while reading from the
 34.1148 -         *         underlying <code>InputStream</code>
 34.1149 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1150 -         *         not serializable or if the field type is incorrect
 34.1151 -         */
 34.1152 -        public abstract double get(String name, double val) throws IOException;
 34.1153 -
 34.1154 -        /**
 34.1155 -         * Get the value of the named Object field from the persistent field.
 34.1156 -         *
 34.1157 -         * @param  name the name of the field
 34.1158 -         * @param  val the default value to use if <code>name</code> does not
 34.1159 -         *         have a value
 34.1160 -         * @return the value of the named <code>Object</code> field
 34.1161 -         * @throws IOException if there are I/O errors while reading from the
 34.1162 -         *         underlying <code>InputStream</code>
 34.1163 -         * @throws IllegalArgumentException if type of <code>name</code> is
 34.1164 -         *         not serializable or if the field type is incorrect
 34.1165 -         */
 34.1166 -        public abstract Object get(String name, Object val) throws IOException;
 34.1167 -    }
 34.1168 -
 34.1169 -    /**
 34.1170 -     * Verifies that this (possibly subclass) instance can be constructed
 34.1171 -     * without violating security constraints: the subclass must not override
 34.1172 -     * security-sensitive non-final methods, or else the
 34.1173 -     * "enableSubclassImplementation" SerializablePermission is checked.
 34.1174 -     */
 34.1175 -    private void verifySubclass() {
 34.1176 -        Class cl = getClass();
 34.1177 -        if (cl == ObjectInputStream.class) {
 34.1178 -            return;
 34.1179 -        }
 34.1180 -        throw new SecurityException();
 34.1181 -    }
 34.1182 -
 34.1183 -    /**
 34.1184 -     * Clears internal data structures.
 34.1185 -     */
 34.1186 -    private void clear() {
 34.1187 -        handles.clear();
 34.1188 -        vlist.clear();
 34.1189 -    }
 34.1190 -
 34.1191 -    /**
 34.1192 -     * Underlying readObject implementation.
 34.1193 -     */
 34.1194 -    private Object readObject0(boolean unshared) throws IOException {
 34.1195 -        boolean oldMode = bin.getBlockDataMode();
 34.1196 -        if (oldMode) {
 34.1197 -            int remain = bin.currentBlockRemaining();
 34.1198 -            if (remain > 0) {
 34.1199 -                throw new OptionalDataException(remain);
 34.1200 -            } else if (defaultDataEnd) {
 34.1201 -                /*
 34.1202 -                 * Fix for 4360508: stream is currently at the end of a field
 34.1203 -                 * value block written via default serialization; since there
 34.1204 -                 * is no terminating TC_ENDBLOCKDATA tag, simulate
 34.1205 -                 * end-of-custom-data behavior explicitly.
 34.1206 -                 */
 34.1207 -                throw new OptionalDataException(true);
 34.1208 -            }
 34.1209 -            bin.setBlockDataMode(false);
 34.1210 -        }
 34.1211 -
 34.1212 -        byte tc;
 34.1213 -        while ((tc = bin.peekByte()) == TC_RESET) {
 34.1214 -            bin.readByte();
 34.1215 -            handleReset();
 34.1216 -        }
 34.1217 -
 34.1218 -        depth++;
 34.1219 -        try {
 34.1220 -            switch (tc) {
 34.1221 -                case TC_NULL:
 34.1222 -                    return readNull();
 34.1223 -
 34.1224 -                case TC_REFERENCE:
 34.1225 -                    return readHandle(unshared);
 34.1226 -
 34.1227 -                case TC_CLASS:
 34.1228 -                    return readClass(unshared);
 34.1229 -
 34.1230 -                case TC_CLASSDESC:
 34.1231 -                case TC_PROXYCLASSDESC:
 34.1232 -                    return readClassDesc(unshared);
 34.1233 -
 34.1234 -                case TC_STRING:
 34.1235 -                case TC_LONGSTRING:
 34.1236 -                    return checkResolve(readString(unshared));
 34.1237 -
 34.1238 -                case TC_ARRAY:
 34.1239 -                    return checkResolve(readArray(unshared));
 34.1240 -
 34.1241 -                case TC_ENUM:
 34.1242 -                    return checkResolve(readEnum(unshared));
 34.1243 -
 34.1244 -                case TC_OBJECT:
 34.1245 -                    return checkResolve(readOrdinaryObject(unshared));
 34.1246 -
 34.1247 -                case TC_EXCEPTION:
 34.1248 -                    IOException ex = readFatalException();
 34.1249 -                    throw new WriteAbortedException("writing aborted", ex);
 34.1250 -
 34.1251 -                case TC_BLOCKDATA:
 34.1252 -                case TC_BLOCKDATALONG:
 34.1253 -                    if (oldMode) {
 34.1254 -                        bin.setBlockDataMode(true);
 34.1255 -                        bin.peek();             // force header read
 34.1256 -                        throw new OptionalDataException(
 34.1257 -                            bin.currentBlockRemaining());
 34.1258 -                    } else {
 34.1259 -                        throw new StreamCorruptedException(
 34.1260 -                            "unexpected block data");
 34.1261 -                    }
 34.1262 -
 34.1263 -                case TC_ENDBLOCKDATA:
 34.1264 -                    if (oldMode) {
 34.1265 -                        throw new OptionalDataException(true);
 34.1266 -                    } else {
 34.1267 -                        throw new StreamCorruptedException(
 34.1268 -                            "unexpected end of block data");
 34.1269 -                    }
 34.1270 -
 34.1271 -                default:
 34.1272 -                    throw new StreamCorruptedException(
 34.1273 -                        String.format("invalid type code: %02X", tc));
 34.1274 -            }
 34.1275 -        } finally {
 34.1276 -            depth--;
 34.1277 -            bin.setBlockDataMode(oldMode);
 34.1278 -        }
 34.1279 -    }
 34.1280 -
 34.1281 -    /**
 34.1282 -     * If resolveObject has been enabled and given object does not have an
 34.1283 -     * exception associated with it, calls resolveObject to determine
 34.1284 -     * replacement for object, and updates handle table accordingly.  Returns
 34.1285 -     * replacement object, or echoes provided object if no replacement
 34.1286 -     * occurred.  Expects that passHandle is set to given object's handle prior
 34.1287 -     * to calling this method.
 34.1288 -     */
 34.1289 -    private Object checkResolve(Object obj) throws IOException {
 34.1290 -        if (!enableResolve || handles.lookupException(passHandle) != null) {
 34.1291 -            return obj;
 34.1292 -        }
 34.1293 -        Object rep = resolveObject(obj);
 34.1294 -        if (rep != obj) {
 34.1295 -            handles.setObject(passHandle, rep);
 34.1296 -        }
 34.1297 -        return rep;
 34.1298 -    }
 34.1299 -
 34.1300 -    /**
 34.1301 -     * Reads string without allowing it to be replaced in stream.  Called from
 34.1302 -     * within ObjectStreamClass.read().
 34.1303 -     */
 34.1304 -    String readTypeString() throws IOException {
 34.1305 -        int oldHandle = passHandle;
 34.1306 -        try {
 34.1307 -            byte tc = bin.peekByte();
 34.1308 -            switch (tc) {
 34.1309 -                case TC_NULL:
 34.1310 -                    return (String) readNull();
 34.1311 -
 34.1312 -                case TC_REFERENCE:
 34.1313 -                    return (String) readHandle(false);
 34.1314 -
 34.1315 -                case TC_STRING:
 34.1316 -                case TC_LONGSTRING:
 34.1317 -                    return readString(false);
 34.1318 -
 34.1319 -                default:
 34.1320 -                    throw new StreamCorruptedException(
 34.1321 -                        String.format("invalid type code: %02X", tc));
 34.1322 -            }
 34.1323 -        } finally {
 34.1324 -            passHandle = oldHandle;
 34.1325 -        }
 34.1326 -    }
 34.1327 -
 34.1328 -    /**
 34.1329 -     * Reads in null code, sets passHandle to NULL_HANDLE and returns null.
 34.1330 -     */
 34.1331 -    private Object readNull() throws IOException {
 34.1332 -        if (bin.readByte() != TC_NULL) {
 34.1333 -            throw new InternalError();
 34.1334 -        }
 34.1335 -        passHandle = NULL_HANDLE;
 34.1336 -        return null;
 34.1337 -    }
 34.1338 -
 34.1339 -    /**
 34.1340 -     * Reads in object handle, sets passHandle to the read handle, and returns
 34.1341 -     * object associated with the handle.
 34.1342 -     */
 34.1343 -    private Object readHandle(boolean unshared) throws IOException {
 34.1344 -        if (bin.readByte() != TC_REFERENCE) {
 34.1345 -            throw new InternalError();
 34.1346 -        }
 34.1347 -        passHandle = bin.readInt() - baseWireHandle;
 34.1348 -        if (passHandle < 0 || passHandle >= handles.size()) {
 34.1349 -            throw new StreamCorruptedException(
 34.1350 -                String.format("invalid handle value: %08X", passHandle +
 34.1351 -                baseWireHandle));
 34.1352 -        }
 34.1353 -        if (unshared) {
 34.1354 -            // REMIND: what type of exception to throw here?
 34.1355 -            throw new InvalidObjectException(
 34.1356 -                "cannot read back reference as unshared");
 34.1357 -        }
 34.1358 -
 34.1359 -        Object obj = handles.lookupObject(passHandle);
 34.1360 -        if (obj == unsharedMarker) {
 34.1361 -            // REMIND: what type of exception to throw here?
 34.1362 -            throw new InvalidObjectException(
 34.1363 -                "cannot read back reference to unshared object");
 34.1364 -        }
 34.1365 -        return obj;
 34.1366 -    }
 34.1367 -
 34.1368 -    /**
 34.1369 -     * Reads in and returns class object.  Sets passHandle to class object's
 34.1370 -     * assigned handle.  Returns null if class is unresolvable (in which case a
 34.1371 -     * ClassNotFoundException will be associated with the class' handle in the
 34.1372 -     * handle table).
 34.1373 -     */
 34.1374 -    private Class readClass(boolean unshared) throws IOException {
 34.1375 -        if (bin.readByte() != TC_CLASS) {
 34.1376 -            throw new InternalError();
 34.1377 -        }
 34.1378 -        ObjectStreamClass desc = readClassDesc(false);
 34.1379 -        Class cl = desc.forClass();
 34.1380 -        passHandle = handles.assign(unshared ? unsharedMarker : cl);
 34.1381 -
 34.1382 -        ClassNotFoundException resolveEx = desc.getResolveException();
 34.1383 -        if (resolveEx != null) {
 34.1384 -            handles.markException(passHandle, resolveEx);
 34.1385 -        }
 34.1386 -
 34.1387 -        handles.finish(passHandle);
 34.1388 -        return cl;
 34.1389 -    }
 34.1390 -
 34.1391 -    /**
 34.1392 -     * Reads in and returns (possibly null) class descriptor.  Sets passHandle
 34.1393 -     * to class descriptor's assigned handle.  If class descriptor cannot be
 34.1394 -     * resolved to a class in the local VM, a ClassNotFoundException is
 34.1395 -     * associated with the class descriptor's handle.
 34.1396 -     */
 34.1397 -    private ObjectStreamClass readClassDesc(boolean unshared)
 34.1398 -        throws IOException
 34.1399 -    {
 34.1400 -        byte tc = bin.peekByte();
 34.1401 -        switch (tc) {
 34.1402 -            case TC_NULL:
 34.1403 -                return (ObjectStreamClass) readNull();
 34.1404 -
 34.1405 -            case TC_REFERENCE:
 34.1406 -                return (ObjectStreamClass) readHandle(unshared);
 34.1407 -
 34.1408 -            case TC_PROXYCLASSDESC:
 34.1409 -                return readProxyDesc(unshared);
 34.1410 -
 34.1411 -            case TC_CLASSDESC:
 34.1412 -                return readNonProxyDesc(unshared);
 34.1413 -
 34.1414 -            default:
 34.1415 -                throw new StreamCorruptedException(
 34.1416 -                    String.format("invalid type code: %02X", tc));
 34.1417 -        }
 34.1418 -    }
 34.1419 -
 34.1420 -    /**
 34.1421 -     * Reads in and returns class descriptor for a dynamic proxy class.  Sets
 34.1422 -     * passHandle to proxy class descriptor's assigned handle.  If proxy class
 34.1423 -     * descriptor cannot be resolved to a class in the local VM, a
 34.1424 -     * ClassNotFoundException is associated with the descriptor's handle.
 34.1425 -     */
 34.1426 -    private ObjectStreamClass readProxyDesc(boolean unshared)
 34.1427 -        throws IOException
 34.1428 -    {
 34.1429 -        if (bin.readByte() != TC_PROXYCLASSDESC) {
 34.1430 -            throw new InternalError();
 34.1431 -        }
 34.1432 -
 34.1433 -        ObjectStreamClass desc = new ObjectStreamClass();
 34.1434 -        int descHandle = handles.assign(unshared ? unsharedMarker : desc);
 34.1435 -        passHandle = NULL_HANDLE;
 34.1436 -
 34.1437 -        int numIfaces = bin.readInt();
 34.1438 -        String[] ifaces = new String[numIfaces];
 34.1439 -        for (int i = 0; i < numIfaces; i++) {
 34.1440 -            ifaces[i] = bin.readUTF();
 34.1441 -        }
 34.1442 -
 34.1443 -        Class cl = null;
 34.1444 -        ClassNotFoundException resolveEx = null;
 34.1445 -        bin.setBlockDataMode(true);
 34.1446 -        try {
 34.1447 -            if ((cl = resolveProxyClass(ifaces)) == null) {
 34.1448 -                resolveEx = new ClassNotFoundException("null class");
 34.1449 -            }
 34.1450 -        } catch (ClassNotFoundException ex) {
 34.1451 -            resolveEx = ex;
 34.1452 -        }
 34.1453 -        skipCustomData();
 34.1454 -
 34.1455 -        desc.initProxy(cl, resolveEx, readClassDesc(false));
 34.1456 -
 34.1457 -        handles.finish(descHandle);
 34.1458 -        passHandle = descHandle;
 34.1459 -        return desc;
 34.1460 -    }
 34.1461 -
 34.1462 -    /**
 34.1463 -     * Reads in and returns class descriptor for a class that is not a dynamic
 34.1464 -     * proxy class.  Sets passHandle to class descriptor's assigned handle.  If
 34.1465 -     * class descriptor cannot be resolved to a class in the local VM, a
 34.1466 -     * ClassNotFoundException is associated with the descriptor's handle.
 34.1467 -     */
 34.1468 -    private ObjectStreamClass readNonProxyDesc(boolean unshared)
 34.1469 -        throws IOException
 34.1470 -    {
 34.1471 -        if (bin.readByte() != TC_CLASSDESC) {
 34.1472 -            throw new InternalError();
 34.1473 -        }
 34.1474 -
 34.1475 -        ObjectStreamClass desc = new ObjectStreamClass();
 34.1476 -        int descHandle = handles.assign(unshared ? unsharedMarker : desc);
 34.1477 -        passHandle = NULL_HANDLE;
 34.1478 -
 34.1479 -        ObjectStreamClass readDesc = null;
 34.1480 -        try {
 34.1481 -            readDesc = readClassDescriptor();
 34.1482 -        } catch (ClassNotFoundException ex) {
 34.1483 -            throw (IOException) new InvalidClassException(
 34.1484 -                "failed to read class descriptor").initCause(ex);
 34.1485 -        }
 34.1486 -
 34.1487 -        Class cl = null;
 34.1488 -        ClassNotFoundException resolveEx = null;
 34.1489 -        bin.setBlockDataMode(true);
 34.1490 -        try {
 34.1491 -            if ((cl = resolveClass(readDesc)) == null) {
 34.1492 -                resolveEx = new ClassNotFoundException("null class");
 34.1493 -            }
 34.1494 -        } catch (ClassNotFoundException ex) {
 34.1495 -            resolveEx = ex;
 34.1496 -        }
 34.1497 -        skipCustomData();
 34.1498 -
 34.1499 -        desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false));
 34.1500 -
 34.1501 -        handles.finish(descHandle);
 34.1502 -        passHandle = descHandle;
 34.1503 -        return desc;
 34.1504 -    }
 34.1505 -
 34.1506 -    /**
 34.1507 -     * Reads in and returns new string.  Sets passHandle to new string's
 34.1508 -     * assigned handle.
 34.1509 -     */
 34.1510 -    private String readString(boolean unshared) throws IOException {
 34.1511 -        String str;
 34.1512 -        byte tc = bin.readByte();
 34.1513 -        switch (tc) {
 34.1514 -            case TC_STRING:
 34.1515 -                str = bin.readUTF();
 34.1516 -                break;
 34.1517 -
 34.1518 -            case TC_LONGSTRING:
 34.1519 -                str = bin.readLongUTF();
 34.1520 -                break;
 34.1521 -
 34.1522 -            default:
 34.1523 -                throw new StreamCorruptedException(
 34.1524 -                    String.format("invalid type code: %02X", tc));
 34.1525 -        }
 34.1526 -        passHandle = handles.assign(unshared ? unsharedMarker : str);
 34.1527 -        handles.finish(passHandle);
 34.1528 -        return str;
 34.1529 -    }
 34.1530 -
 34.1531 -    /**
 34.1532 -     * Reads in and returns array object, or null if array class is
 34.1533 -     * unresolvable.  Sets passHandle to array's assigned handle.
 34.1534 -     */
 34.1535 -    private Object readArray(boolean unshared) throws IOException {
 34.1536 -        if (bin.readByte() != TC_ARRAY) {
 34.1537 -            throw new InternalError();
 34.1538 -        }
 34.1539 -
 34.1540 -        ObjectStreamClass desc = readClassDesc(false);
 34.1541 -        int len = bin.readInt();
 34.1542 -
 34.1543 -        Object array = null;
 34.1544 -        Class cl, ccl = null;
 34.1545 -        if ((cl = desc.forClass()) != null) {
 34.1546 -            ccl = cl.getComponentType();
 34.1547 -            array = Array.newInstance(ccl, len);
 34.1548 -        }
 34.1549 -
 34.1550 -        int arrayHandle = handles.assign(unshared ? unsharedMarker : array);
 34.1551 -        ClassNotFoundException resolveEx = desc.getResolveException();
 34.1552 -        if (resolveEx != null) {
 34.1553 -            handles.markException(arrayHandle, resolveEx);
 34.1554 -        }
 34.1555 -
 34.1556 -        if (ccl == null) {
 34.1557 -            for (int i = 0; i < len; i++) {
 34.1558 -                readObject0(false);
 34.1559 -            }
 34.1560 -        } else if (ccl.isPrimitive()) {
 34.1561 -            if (ccl == Integer.TYPE) {
 34.1562 -                bin.readInts((int[]) array, 0, len);
 34.1563 -            } else if (ccl == Byte.TYPE) {
 34.1564 -                bin.readFully((byte[]) array, 0, len, true);
 34.1565 -            } else if (ccl == Long.TYPE) {
 34.1566 -                bin.readLongs((long[]) array, 0, len);
 34.1567 -            } else if (ccl == Float.TYPE) {
 34.1568 -                bin.readFloats((float[]) array, 0, len);
 34.1569 -            } else if (ccl == Double.TYPE) {
 34.1570 -                bin.readDoubles((double[]) array, 0, len);
 34.1571 -            } else if (ccl == Short.TYPE) {
 34.1572 -                bin.readShorts((short[]) array, 0, len);
 34.1573 -            } else if (ccl == Character.TYPE) {
 34.1574 -                bin.readChars((char[]) array, 0, len);
 34.1575 -            } else if (ccl == Boolean.TYPE) {
 34.1576 -                bin.readBooleans((boolean[]) array, 0, len);
 34.1577 -            } else {
 34.1578 -                throw new InternalError();
 34.1579 -            }
 34.1580 -        } else {
 34.1581 -            Object[] oa = (Object[]) array;
 34.1582 -            for (int i = 0; i < len; i++) {
 34.1583 -                oa[i] = readObject0(false);
 34.1584 -                handles.markDependency(arrayHandle, passHandle);
 34.1585 -            }
 34.1586 -        }
 34.1587 -
 34.1588 -        handles.finish(arrayHandle);
 34.1589 -        passHandle = arrayHandle;
 34.1590 -        return array;
 34.1591 -    }
 34.1592 -
 34.1593 -    /**
 34.1594 -     * Reads in and returns enum constant, or null if enum type is
 34.1595 -     * unresolvable.  Sets passHandle to enum constant's assigned handle.
 34.1596 -     */
 34.1597 -    private Enum readEnum(boolean unshared) throws IOException {
 34.1598 -        if (bin.readByte() != TC_ENUM) {
 34.1599 -            throw new InternalError();
 34.1600 -        }
 34.1601 -
 34.1602 -        ObjectStreamClass desc = readClassDesc(false);
 34.1603 -        if (!desc.isEnum()) {
 34.1604 -            throw new InvalidClassException("non-enum class: " + desc);
 34.1605 -        }
 34.1606 -
 34.1607 -        int enumHandle = handles.assign(unshared ? unsharedMarker : null);
 34.1608 -        ClassNotFoundException resolveEx = desc.getResolveException();
 34.1609 -        if (resolveEx != null) {
 34.1610 -            handles.markException(enumHandle, resolveEx);
 34.1611 -        }
 34.1612 -
 34.1613 -        String name = readString(false);
 34.1614 -        Enum en = null;
 34.1615 -        Class cl = desc.forClass();
 34.1616 -        if (cl != null) {
 34.1617 -            try {
 34.1618 -                en = Enum.valueOf(cl, name);
 34.1619 -            } catch (IllegalArgumentException ex) {
 34.1620 -                throw (IOException) new InvalidObjectException(
 34.1621 -                    "enum constant " + name + " does not exist in " +
 34.1622 -                    cl).initCause(ex);
 34.1623 -            }
 34.1624 -            if (!unshared) {
 34.1625 -                handles.setObject(enumHandle, en);
 34.1626 -            }
 34.1627 -        }
 34.1628 -
 34.1629 -        handles.finish(enumHandle);
 34.1630 -        passHandle = enumHandle;
 34.1631 -        return en;
 34.1632 -    }
 34.1633 -
 34.1634 -    /**
 34.1635 -     * Reads and returns "ordinary" (i.e., not a String, Class,
 34.1636 -     * ObjectStreamClass, array, or enum constant) object, or null if object's
 34.1637 -     * class is unresolvable (in which case a ClassNotFoundException will be
 34.1638 -     * associated with object's handle).  Sets passHandle to object's assigned
 34.1639 -     * handle.
 34.1640 -     */
 34.1641 -    private Object readOrdinaryObject(boolean unshared)
 34.1642 -        throws IOException
 34.1643 -    {
 34.1644 -        if (bin.readByte() != TC_OBJECT) {
 34.1645 -            throw new InternalError();
 34.1646 -        }
 34.1647 -
 34.1648 -        ObjectStreamClass desc = readClassDesc(false);
 34.1649 -        desc.checkDeserialize();
 34.1650 -
 34.1651 -        Object obj;
 34.1652 -        try {
 34.1653 -            obj = desc.isInstantiable() ? desc.newInstance() : null;
 34.1654 -        } catch (Exception ex) {
 34.1655 -            throw (IOException) new InvalidClassException(
 34.1656 -                desc.forClass().getName(),
 34.1657 -                "unable to create instance").initCause(ex);
 34.1658 -        }
 34.1659 -
 34.1660 -        passHandle = handles.assign(unshared ? unsharedMarker : obj);
 34.1661 -        ClassNotFoundException resolveEx = desc.getResolveException();
 34.1662 -        if (resolveEx != null) {
 34.1663 -            handles.markException(passHandle, resolveEx);
 34.1664 -        }
 34.1665 -
 34.1666 -        if (desc.isExternalizable()) {
 34.1667 -            readExternalData((Externalizable) obj, desc);
 34.1668 -        } else {
 34.1669 -            readSerialData(obj, desc);
 34.1670 -        }
 34.1671 -
 34.1672 -        handles.finish(passHandle);
 34.1673 -
 34.1674 -        if (obj != null &&
 34.1675 -            handles.lookupException(passHandle) == null &&
 34.1676 -            desc.hasReadResolveMethod())
 34.1677 -        {
 34.1678 -            Object rep = desc.invokeReadResolve(obj);
 34.1679 -            if (unshared && rep.getClass().isArray()) {
 34.1680 -                rep = cloneArray(rep);
 34.1681 -            }
 34.1682 -            if (rep != obj) {
 34.1683 -                handles.setObject(passHandle, obj = rep);
 34.1684 -            }
 34.1685 -        }
 34.1686 -
 34.1687 -        return obj;
 34.1688 -    }
 34.1689 -
 34.1690 -    /**
 34.1691 -     * If obj is non-null, reads externalizable data by invoking readExternal()
 34.1692 -     * method of obj; otherwise, attempts to skip over externalizable data.
 34.1693 -     * Expects that passHandle is set to obj's handle before this method is
 34.1694 -     * called.
 34.1695 -     */
 34.1696 -    private void readExternalData(Externalizable obj, ObjectStreamClass desc)
 34.1697 -        throws IOException
 34.1698 -    {
 34.1699 -        Object oldContext = curContext;
 34.1700 -        curContext = null;
 34.1701 -        try {
 34.1702 -            boolean blocked = desc.hasBlockExternalData();
 34.1703 -            if (blocked) {
 34.1704 -                bin.setBlockDataMode(true);
 34.1705 -            }
 34.1706 -            if (obj != null) {
 34.1707 -                try {
 34.1708 -                    obj.readExternal(this);
 34.1709 -                } catch (ClassNotFoundException ex) {
 34.1710 -                    /*
 34.1711 -                     * In most cases, the handle table has already propagated
 34.1712 -                     * a CNFException to passHandle at this point; this mark
 34.1713 -                     * call is included to address cases where the readExternal
 34.1714 -                     * method has cons'ed and thrown a new CNFException of its
 34.1715 -                     * own.
 34.1716 -                     */
 34.1717 -                     handles.markException(passHandle, ex);
 34.1718 -                }
 34.1719 -            }
 34.1720 -            if (blocked) {
 34.1721 -                skipCustomData();
 34.1722 -            }
 34.1723 -        } finally {
 34.1724 -            curContext = oldContext;
 34.1725 -        }
 34.1726 -        /*
 34.1727 -         * At this point, if the externalizable data was not written in
 34.1728 -         * block-data form and either the externalizable class doesn't exist
 34.1729 -         * locally (i.e., obj == null) or readExternal() just threw a
 34.1730 -         * CNFException, then the stream is probably in an inconsistent state,
 34.1731 -         * since some (or all) of the externalizable data may not have been
 34.1732 -         * consumed.  Since there's no "correct" action to take in this case,
 34.1733 -         * we mimic the behavior of past serialization implementations and
 34.1734 -         * blindly hope that the stream is in sync; if it isn't and additional
 34.1735 -         * externalizable data remains in the stream, a subsequent read will
 34.1736 -         * most likely throw a StreamCorruptedException.
 34.1737 -         */
 34.1738 -    }
 34.1739 -
 34.1740 -    /**
 34.1741 -     * Reads (or attempts to skip, if obj is null or is tagged with a
 34.1742 -     * ClassNotFoundException) instance data for each serializable class of
 34.1743 -     * object in stream, from superclass to subclass.  Expects that passHandle
 34.1744 -     * is set to obj's handle before this method is called.
 34.1745 -     */
 34.1746 -    private void readSerialData(Object obj, ObjectStreamClass desc)
 34.1747 -        throws IOException
 34.1748 -    {
 34.1749 -        ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
 34.1750 -        for (int i = 0; i < slots.length; i++) {
 34.1751 -            ObjectStreamClass slotDesc = slots[i].desc;
 34.1752 -
 34.1753 -            if (slots[i].hasData) {
 34.1754 -                if (obj != null &&
 34.1755 -                    slotDesc.hasReadObjectMethod() &&
 34.1756 -                    handles.lookupException(passHandle) == null)
 34.1757 -                {
 34.1758 -                    Object oldContext = curContext;
 34.1759 -
 34.1760 -                    try {
 34.1761 -                        curContext = null; //new SerialCallbackContext(obj, slotDesc);
 34.1762 -
 34.1763 -                        bin.setBlockDataMode(true);
 34.1764 -                        slotDesc.invokeReadObject(obj, this);
 34.1765 -                    } catch (ClassNotFoundException ex) {
 34.1766 -                        /*
 34.1767 -                         * In most cases, the handle table has already
 34.1768 -                         * propagated a CNFException to passHandle at this
 34.1769 -                         * point; this mark call is included to address cases
 34.1770 -                         * where the custom readObject method has cons'ed and
 34.1771 -                         * thrown a new CNFException of its own.
 34.1772 -                         */
 34.1773 -                        handles.markException(passHandle, ex);
 34.1774 -                    } finally {
 34.1775 -                        //curContext.setUsed();
 34.1776 -                        curContext = oldContext;
 34.1777 -                    }
 34.1778 -
 34.1779 -                    /*
 34.1780 -                     * defaultDataEnd may have been set indirectly by custom
 34.1781 -                     * readObject() method when calling defaultReadObject() or
 34.1782 -                     * readFields(); clear it to restore normal read behavior.
 34.1783 -                     */
 34.1784 -                    defaultDataEnd = false;
 34.1785 -                } else {
 34.1786 -                    defaultReadFields(obj, slotDesc);
 34.1787 -                }
 34.1788 -                if (slotDesc.hasWriteObjectData()) {
 34.1789 -                    skipCustomData();
 34.1790 -                } else {
 34.1791 -                    bin.setBlockDataMode(false);
 34.1792 -                }
 34.1793 -            } else {
 34.1794 -                if (obj != null &&
 34.1795 -                    slotDesc.hasReadObjectNoDataMethod() &&
 34.1796 -                    handles.lookupException(passHandle) == null)
 34.1797 -                {
 34.1798 -                    slotDesc.invokeReadObjectNoData(obj);
 34.1799 -                }
 34.1800 -            }
 34.1801 -        }
 34.1802 -    }
 34.1803 -
 34.1804 -    /**
 34.1805 -     * Skips over all block data and objects until TC_ENDBLOCKDATA is
 34.1806 -     * encountered.
 34.1807 -     */
 34.1808 -    private void skipCustomData() throws IOException {
 34.1809 -        int oldHandle = passHandle;
 34.1810 -        for (;;) {
 34.1811 -            if (bin.getBlockDataMode()) {
 34.1812 -                bin.skipBlockData();
 34.1813 -                bin.setBlockDataMode(false);
 34.1814 -            }
 34.1815 -            switch (bin.peekByte()) {
 34.1816 -                case TC_BLOCKDATA:
 34.1817 -                case TC_BLOCKDATALONG:
 34.1818 -                    bin.setBlockDataMode(true);
 34.1819 -                    break;
 34.1820 -
 34.1821 -                case TC_ENDBLOCKDATA:
 34.1822 -                    bin.readByte();
 34.1823 -                    passHandle = oldHandle;
 34.1824 -                    return;
 34.1825 -
 34.1826 -                default:
 34.1827 -                    readObject0(false);
 34.1828 -                    break;
 34.1829 -            }
 34.1830 -        }
 34.1831 -    }
 34.1832 -
 34.1833 -    /**
 34.1834 -     * Reads in values of serializable fields declared by given class
 34.1835 -     * descriptor.  If obj is non-null, sets field values in obj.  Expects that
 34.1836 -     * passHandle is set to obj's handle before this method is called.
 34.1837 -     */
 34.1838 -    private void defaultReadFields(Object obj, ObjectStreamClass desc)
 34.1839 -        throws IOException
 34.1840 -    {
 34.1841 -        // REMIND: is isInstance check necessary?
 34.1842 -        Class cl = desc.forClass();
 34.1843 -        if (cl != null && obj != null && !cl.isInstance(obj)) {
 34.1844 -            throw new ClassCastException();
 34.1845 -        }
 34.1846 -
 34.1847 -        int primDataSize = desc.getPrimDataSize();
 34.1848 -        if (primVals == null || primVals.length < primDataSize) {
 34.1849 -            primVals = new byte[primDataSize];
 34.1850 -        }
 34.1851 -        bin.readFully(primVals, 0, primDataSize, false);
 34.1852 -        if (obj != null) {
 34.1853 -            desc.setPrimFieldValues(obj, primVals);
 34.1854 -        }
 34.1855 -
 34.1856 -        int objHandle = passHandle;
 34.1857 -        ObjectStreamField[] fields = desc.getFields(false);
 34.1858 -        Object[] objVals = new Object[desc.getNumObjFields()];
 34.1859 -        int numPrimFields = fields.length - objVals.length;
 34.1860 -        for (int i = 0; i < objVals.length; i++) {
 34.1861 -            ObjectStreamField f = fields[numPrimFields + i];
 34.1862 -            objVals[i] = readObject0(f.isUnshared());
 34.1863 -            if (f.getField() != null) {
 34.1864 -                handles.markDependency(objHandle, passHandle);
 34.1865 -            }
 34.1866 -        }
 34.1867 -        if (obj != null) {
 34.1868 -            desc.setObjFieldValues(obj, objVals);
 34.1869 -        }
 34.1870 -        passHandle = objHandle;
 34.1871 -    }
 34.1872 -
 34.1873 -    /**
 34.1874 -     * Reads in and returns IOException that caused serialization to abort.
 34.1875 -     * All stream state is discarded prior to reading in fatal exception.  Sets
 34.1876 -     * passHandle to fatal exception's handle.
 34.1877 -     */
 34.1878 -    private IOException readFatalException() throws IOException {
 34.1879 -        if (bin.readByte() != TC_EXCEPTION) {
 34.1880 -            throw new InternalError();
 34.1881 -        }
 34.1882 -        clear();
 34.1883 -        return (IOException) readObject0(false);
 34.1884 -    }
 34.1885 -
 34.1886 -    /**
 34.1887 -     * If recursion depth is 0, clears internal data structures; otherwise,
 34.1888 -     * throws a StreamCorruptedException.  This method is called when a
 34.1889 -     * TC_RESET typecode is encountered.
 34.1890 -     */
 34.1891 -    private void handleReset() throws StreamCorruptedException {
 34.1892 -        if (depth > 0) {
 34.1893 -            throw new StreamCorruptedException(
 34.1894 -                "unexpected reset; recursion depth: " + depth);
 34.1895 -        }
 34.1896 -        clear();
 34.1897 -    }
 34.1898 -
 34.1899 -    /**
 34.1900 -     * Converts specified span of bytes into float values.
 34.1901 -     */
 34.1902 -    // REMIND: remove once hotspot inlines Float.intBitsToFloat
 34.1903 -    private static native void bytesToFloats(byte[] src, int srcpos,
 34.1904 -                                             float[] dst, int dstpos,
 34.1905 -                                             int nfloats);
 34.1906 -
 34.1907 -    /**
 34.1908 -     * Converts specified span of bytes into double values.
 34.1909 -     */
 34.1910 -    // REMIND: remove once hotspot inlines Double.longBitsToDouble
 34.1911 -    private static native void bytesToDoubles(byte[] src, int srcpos,
 34.1912 -                                              double[] dst, int dstpos,
 34.1913 -                                              int ndoubles);
 34.1914 -
 34.1915 -    /**
 34.1916 -     * Returns the first non-null class loader (not counting class loaders of
 34.1917 -     * generated reflection implementation classes) up the execution stack, or
 34.1918 -     * null if only code from the null class loader is on the stack.  This
 34.1919 -     * method is also called via reflection by the following RMI-IIOP class:
 34.1920 -     *
 34.1921 -     *     com.sun.corba.se.internal.util.JDKClassLoader
 34.1922 -     *
 34.1923 -     * This method should not be removed or its signature changed without
 34.1924 -     * corresponding modifications to the above class.
 34.1925 -     */
 34.1926 -    // REMIND: change name to something more accurate?
 34.1927 -    private static native ClassLoader latestUserDefinedLoader();
 34.1928 -
 34.1929 -    /**
 34.1930 -     * Default GetField implementation.
 34.1931 -     */
 34.1932 -    private class GetFieldImpl extends GetField {
 34.1933 -
 34.1934 -        /** class descriptor describing serializable fields */
 34.1935 -        private final ObjectStreamClass desc;
 34.1936 -        /** primitive field values */
 34.1937 -        private final byte[] primVals;
 34.1938 -        /** object field values */
 34.1939 -        private final Object[] objVals;
 34.1940 -        /** object field value handles */
 34.1941 -        private final int[] objHandles;
 34.1942 -
 34.1943 -        /**
 34.1944 -         * Creates GetFieldImpl object for reading fields defined in given
 34.1945 -         * class descriptor.
 34.1946 -         */
 34.1947 -        GetFieldImpl(ObjectStreamClass desc) {
 34.1948 -            this.desc = desc;
 34.1949 -            primVals = new byte[desc.getPrimDataSize()];
 34.1950 -            objVals = new Object[desc.getNumObjFields()];
 34.1951 -            objHandles = new int[objVals.length];
 34.1952 -        }
 34.1953 -
 34.1954 -        public ObjectStreamClass getObjectStreamClass() {
 34.1955 -            return desc;
 34.1956 -        }
 34.1957 -
 34.1958 -        public boolean defaulted(String name) throws IOException {
 34.1959 -            return (getFieldOffset(name, null) < 0);
 34.1960 -        }
 34.1961 -
 34.1962 -        public boolean get(String name, boolean val) throws IOException {
 34.1963 -            int off = getFieldOffset(name, Boolean.TYPE);
 34.1964 -            return (off >= 0) ? Bits.getBoolean(primVals, off) : val;
 34.1965 -        }
 34.1966 -
 34.1967 -        public byte get(String name, byte val) throws IOException {
 34.1968 -            int off = getFieldOffset(name, Byte.TYPE);
 34.1969 -            return (off >= 0) ? primVals[off] : val;
 34.1970 -        }
 34.1971 -
 34.1972 -        public char get(String name, char val) throws IOException {
 34.1973 -            int off = getFieldOffset(name, Character.TYPE);
 34.1974 -            return (off >= 0) ? Bits.getChar(primVals, off) : val;
 34.1975 -        }
 34.1976 -
 34.1977 -        public short get(String name, short val) throws IOException {
 34.1978 -            int off = getFieldOffset(name, Short.TYPE);
 34.1979 -            return (off >= 0) ? Bits.getShort(primVals, off) : val;
 34.1980 -        }
 34.1981 -
 34.1982 -        public int get(String name, int val) throws IOException {
 34.1983 -            int off = getFieldOffset(name, Integer.TYPE);
 34.1984 -            return (off >= 0) ? Bits.getInt(primVals, off) : val;
 34.1985 -        }
 34.1986 -
 34.1987 -        public float get(String name, float val) throws IOException {
 34.1988 -            int off = getFieldOffset(name, Float.TYPE);
 34.1989 -            return (off >= 0) ? Bits.getFloat(primVals, off) : val;
 34.1990 -        }
 34.1991 -
 34.1992 -        public long get(String name, long val) throws IOException {
 34.1993 -            int off = getFieldOffset(name, Long.TYPE);
 34.1994 -            return (off >= 0) ? Bits.getLong(primVals, off) : val;
 34.1995 -        }
 34.1996 -
 34.1997 -        public double get(String name, double val) throws IOException {
 34.1998 -            int off = getFieldOffset(name, Double.TYPE);
 34.1999 -            return (off >= 0) ? Bits.getDouble(primVals, off) : val;
 34.2000 -        }
 34.2001 -
 34.2002 -        public Object get(String name, Object val) throws IOException {
 34.2003 -            int off = getFieldOffset(name, Object.class);
 34.2004 -            if (off >= 0) {
 34.2005 -                int objHandle = objHandles[off];
 34.2006 -                handles.markDependency(passHandle, objHandle);
 34.2007 -                return (handles.lookupException(objHandle) == null) ?
 34.2008 -                    objVals[off] : null;
 34.2009 -            } else {
 34.2010 -                return val;
 34.2011 -            }
 34.2012 -        }
 34.2013 -
 34.2014 -        /**
 34.2015 -         * Reads primitive and object field values from stream.
 34.2016 -         */
 34.2017 -        void readFields() throws IOException {
 34.2018 -            bin.readFully(primVals, 0, primVals.length, false);
 34.2019 -
 34.2020 -            int oldHandle = passHandle;
 34.2021 -            ObjectStreamField[] fields = desc.getFields(false);
 34.2022 -            int numPrimFields = fields.length - objVals.length;
 34.2023 -            for (int i = 0; i < objVals.length; i++) {
 34.2024 -                objVals[i] =
 34.2025 -                    readObject0(fields[numPrimFields + i].isUnshared());
 34.2026 -                objHandles[i] = passHandle;
 34.2027 -            }
 34.2028 -            passHandle = oldHandle;
 34.2029 -        }
 34.2030 -
 34.2031 -        /**
 34.2032 -         * Returns offset of field with given name and type.  A specified type
 34.2033 -         * of null matches all types, Object.class matches all non-primitive
 34.2034 -         * types, and any other non-null type matches assignable types only.
 34.2035 -         * If no matching field is found in the (incoming) class
 34.2036 -         * descriptor but a matching field is present in the associated local
 34.2037 -         * class descriptor, returns -1.  Throws IllegalArgumentException if
 34.2038 -         * neither incoming nor local class descriptor contains a match.
 34.2039 -         */
 34.2040 -        private int getFieldOffset(String name, Class type) {
 34.2041 -            ObjectStreamField field = desc.getField(name, type);
 34.2042 -            if (field != null) {
 34.2043 -                return field.getOffset();
 34.2044 -            } else if (desc.getLocalDesc().getField(name, type) != null) {
 34.2045 -                return -1;
 34.2046 -            } else {
 34.2047 -                throw new IllegalArgumentException("no such field " + name +
 34.2048 -                                                   " with type " + type);
 34.2049 -            }
 34.2050 -        }
 34.2051 -    }
 34.2052 -
 34.2053 -    /**
 34.2054 -     * Prioritized list of callbacks to be performed once object graph has been
 34.2055 -     * completely deserialized.
 34.2056 -     */
 34.2057 -    private static class ValidationList {
 34.2058 -
 34.2059 -
 34.2060 -        /**
 34.2061 -         * Creates new (empty) ValidationList.
 34.2062 -         */
 34.2063 -        ValidationList() {
 34.2064 -        }
 34.2065 -
 34.2066 -        /**
 34.2067 -         * Registers callback.  Throws InvalidObjectException if callback
 34.2068 -         * object is null.
 34.2069 -         */
 34.2070 -        void register(ObjectInputValidation obj, int priority)
 34.2071 -            throws InvalidObjectException
 34.2072 -        {
 34.2073 -            if (obj == null) {
 34.2074 -                throw new InvalidObjectException("null callback");
 34.2075 -            }
 34.2076 -            throw new InvalidObjectException("Does not work.");
 34.2077 -        }
 34.2078 -
 34.2079 -        /**
 34.2080 -         * Invokes all registered callbacks and clears the callback list.
 34.2081 -         * Callbacks with higher priorities are called first; those with equal
 34.2082 -         * priorities may be called in any order.  If any of the callbacks
 34.2083 -         * throws an InvalidObjectException, the callback process is terminated
 34.2084 -         * and the exception propagated upwards.
 34.2085 -         */
 34.2086 -        void doCallbacks() throws InvalidObjectException {
 34.2087 -        }
 34.2088 -
 34.2089 -        /**
 34.2090 -         * Resets the callback list to its initial (empty) state.
 34.2091 -         */
 34.2092 -        public void clear() {
 34.2093 -        }
 34.2094 -    }
 34.2095 -
 34.2096 -    /**
 34.2097 -     * Input stream supporting single-byte peek operations.
 34.2098 -     */
 34.2099 -    private static class PeekInputStream extends InputStream {
 34.2100 -
 34.2101 -        /** underlying stream */
 34.2102 -        private final InputStream in;
 34.2103 -        /** peeked byte */
 34.2104 -        private int peekb = -1;
 34.2105 -
 34.2106 -        /**
 34.2107 -         * Creates new PeekInputStream on top of given underlying stream.
 34.2108 -         */
 34.2109 -        PeekInputStream(InputStream in) {
 34.2110 -            this.in = in;
 34.2111 -        }
 34.2112 -
 34.2113 -        /**
 34.2114 -         * Peeks at next byte value in stream.  Similar to read(), except
 34.2115 -         * that it does not consume the read value.
 34.2116 -         */
 34.2117 -        int peek() throws IOException {
 34.2118 -            return (peekb >= 0) ? peekb : (peekb = in.read());
 34.2119 -        }
 34.2120 -
 34.2121 -        public int read() throws IOException {
 34.2122 -            if (peekb >= 0) {
 34.2123 -                int v = peekb;
 34.2124 -                peekb = -1;
 34.2125 -                return v;
 34.2126 -            } else {
 34.2127 -                return in.read();
 34.2128 -            }
 34.2129 -        }
 34.2130 -
 34.2131 -        public int read(byte[] b, int off, int len) throws IOException {
 34.2132 -            if (len == 0) {
 34.2133 -                return 0;
 34.2134 -            } else if (peekb < 0) {
 34.2135 -                return in.read(b, off, len);
 34.2136 -            } else {
 34.2137 -                b[off++] = (byte) peekb;
 34.2138 -                len--;
 34.2139 -                peekb = -1;
 34.2140 -                int n = in.read(b, off, len);
 34.2141 -                return (n >= 0) ? (n + 1) : 1;
 34.2142 -            }
 34.2143 -        }
 34.2144 -
 34.2145 -        void readFully(byte[] b, int off, int len) throws IOException {
 34.2146 -            int n = 0;
 34.2147 -            while (n < len) {
 34.2148 -                int count = read(b, off + n, len - n);
 34.2149 -                if (count < 0) {
 34.2150 -                    throw new EOFException();
 34.2151 -                }
 34.2152 -                n += count;
 34.2153 -            }
 34.2154 -        }
 34.2155 -
 34.2156 -        public long skip(long n) throws IOException {
 34.2157 -            if (n <= 0) {
 34.2158 -                return 0;
 34.2159 -            }
 34.2160 -            int skipped = 0;
 34.2161 -            if (peekb >= 0) {
 34.2162 -                peekb = -1;
 34.2163 -                skipped++;
 34.2164 -                n--;
 34.2165 -            }
 34.2166 -            return skipped + skip(n);
 34.2167 -        }
 34.2168 -
 34.2169 -        public int available() throws IOException {
 34.2170 -            return in.available() + ((peekb >= 0) ? 1 : 0);
 34.2171 -        }
 34.2172 -
 34.2173 -        public void close() throws IOException {
 34.2174 -            in.close();
 34.2175 -        }
 34.2176 -    }
 34.2177 -
 34.2178 -    /**
 34.2179 -     * Input stream with two modes: in default mode, inputs data written in the
 34.2180 -     * same format as DataOutputStream; in "block data" mode, inputs data
 34.2181 -     * bracketed by block data markers (see object serialization specification
 34.2182 -     * for details).  Buffering depends on block data mode: when in default
 34.2183 -     * mode, no data is buffered in advance; when in block data mode, all data
 34.2184 -     * for the current data block is read in at once (and buffered).
 34.2185 -     */
 34.2186 -    private class BlockDataInputStream
 34.2187 -        extends InputStream implements DataInput
 34.2188 -    {
 34.2189 -        /** maximum data block length */
 34.2190 -        private static final int MAX_BLOCK_SIZE = 1024;
 34.2191 -        /** maximum data block header length */
 34.2192 -        private static final int MAX_HEADER_SIZE = 5;
 34.2193 -        /** (tunable) length of char buffer (for reading strings) */
 34.2194 -        private static final int CHAR_BUF_SIZE = 256;
 34.2195 -        /** readBlockHeader() return value indicating header read may block */
 34.2196 -        private static final int HEADER_BLOCKED = -2;
 34.2197 -
 34.2198 -        /** buffer for reading general/block data */
 34.2199 -        private final byte[] buf = new byte[MAX_BLOCK_SIZE];
 34.2200 -        /** buffer for reading block data headers */
 34.2201 -        private final byte[] hbuf = new byte[MAX_HEADER_SIZE];
 34.2202 -        /** char buffer for fast string reads */
 34.2203 -        private final char[] cbuf = new char[CHAR_BUF_SIZE];
 34.2204 -
 34.2205 -        /** block data mode */
 34.2206 -        private boolean blkmode = false;
 34.2207 -
 34.2208 -        // block data state fields; values meaningful only when blkmode true
 34.2209 -        /** current offset into buf */
 34.2210 -        private int pos = 0;
 34.2211 -        /** end offset of valid data in buf, or -1 if no more block data */
 34.2212 -        private int end = -1;
 34.2213 -        /** number of bytes in current block yet to be read from stream */
 34.2214 -        private int unread = 0;
 34.2215 -
 34.2216 -        /** underlying stream (wrapped in peekable filter stream) */
 34.2217 -        private final PeekInputStream in;
 34.2218 -        /** loopback stream (for data reads that span data blocks) */
 34.2219 -        private final DataInputStream din;
 34.2220 -
 34.2221 -        /**
 34.2222 -         * Creates new BlockDataInputStream on top of given underlying stream.
 34.2223 -         * Block data mode is turned off by default.
 34.2224 -         */
 34.2225 -        BlockDataInputStream(InputStream in) {
 34.2226 -            this.in = new PeekInputStream(in);
 34.2227 -            din = new DataInputStream(this);
 34.2228 -        }
 34.2229 -
 34.2230 -        /**
 34.2231 -         * Sets block data mode to the given mode (true == on, false == off)
 34.2232 -         * and returns the previous mode value.  If the new mode is the same as
 34.2233 -         * the old mode, no action is taken.  Throws IllegalStateException if
 34.2234 -         * block data mode is being switched from on to off while unconsumed
 34.2235 -         * block data is still present in the stream.
 34.2236 -         */
 34.2237 -        boolean setBlockDataMode(boolean newmode) throws IOException {
 34.2238 -            if (blkmode == newmode) {
 34.2239 -                return blkmode;
 34.2240 -            }
 34.2241 -            if (newmode) {
 34.2242 -                pos = 0;
 34.2243 -                end = 0;
 34.2244 -                unread = 0;
 34.2245 -            } else if (pos < end) {
 34.2246 -                throw new IllegalStateException("unread block data");
 34.2247 -            }
 34.2248 -            blkmode = newmode;
 34.2249 -            return !blkmode;
 34.2250 -        }
 34.2251 -
 34.2252 -        /**
 34.2253 -         * Returns true if the stream is currently in block data mode, false
 34.2254 -         * otherwise.
 34.2255 -         */
 34.2256 -        boolean getBlockDataMode() {
 34.2257 -            return blkmode;
 34.2258 -        }
 34.2259 -
 34.2260 -        /**
 34.2261 -         * If in block data mode, skips to the end of the current group of data
 34.2262 -         * blocks (but does not unset block data mode).  If not in block data
 34.2263 -         * mode, throws an IllegalStateException.
 34.2264 -         */
 34.2265 -        void skipBlockData() throws IOException {
 34.2266 -            if (!blkmode) {
 34.2267 -                throw new IllegalStateException("not in block data mode");
 34.2268 -            }
 34.2269 -            while (end >= 0) {
 34.2270 -                refill();
 34.2271 -            }
 34.2272 -        }
 34.2273 -
 34.2274 -        /**
 34.2275 -         * Attempts to read in the next block data header (if any).  If
 34.2276 -         * canBlock is false and a full header cannot be read without possibly
 34.2277 -         * blocking, returns HEADER_BLOCKED, else if the next element in the
 34.2278 -         * stream is a block data header, returns the block data length
 34.2279 -         * specified by the header, else returns -1.
 34.2280 -         */
 34.2281 -        private int readBlockHeader(boolean canBlock) throws IOException {
 34.2282 -            if (defaultDataEnd) {
 34.2283 -                /*
 34.2284 -                 * Fix for 4360508: stream is currently at the end of a field
 34.2285 -                 * value block written via default serialization; since there
 34.2286 -                 * is no terminating TC_ENDBLOCKDATA tag, simulate
 34.2287 -                 * end-of-custom-data behavior explicitly.
 34.2288 -                 */
 34.2289 -                return -1;
 34.2290 -            }
 34.2291 -            try {
 34.2292 -                for (;;) {
 34.2293 -                    int avail = canBlock ? Integer.MAX_VALUE : in.available();
 34.2294 -                    if (avail == 0) {
 34.2295 -                        return HEADER_BLOCKED;
 34.2296 -                    }
 34.2297 -
 34.2298 -                    int tc = in.peek();
 34.2299 -                    switch (tc) {
 34.2300 -                        case TC_BLOCKDATA:
 34.2301 -                            if (avail < 2) {
 34.2302 -                                return HEADER_BLOCKED;
 34.2303 -                            }
 34.2304 -                            in.readFully(hbuf, 0, 2);
 34.2305 -                            return hbuf[1] & 0xFF;
 34.2306 -
 34.2307 -                        case TC_BLOCKDATALONG:
 34.2308 -                            if (avail < 5) {
 34.2309 -                                return HEADER_BLOCKED;
 34.2310 -                            }
 34.2311 -                            in.readFully(hbuf, 0, 5);
 34.2312 -                            int len = Bits.getInt(hbuf, 1);
 34.2313 -                            if (len < 0) {
 34.2314 -                                throw new StreamCorruptedException(
 34.2315 -                                    "illegal block data header length: " +
 34.2316 -                                    len);
 34.2317 -                            }
 34.2318 -                            return len;
 34.2319 -
 34.2320 -                        /*
 34.2321 -                         * TC_RESETs may occur in between data blocks.
 34.2322 -                         * Unfortunately, this case must be parsed at a lower
 34.2323 -                         * level than other typecodes, since primitive data
 34.2324 -                         * reads may span data blocks separated by a TC_RESET.
 34.2325 -                         */
 34.2326 -                        case TC_RESET:
 34.2327 -                            in.read();
 34.2328 -                            handleReset();
 34.2329 -                            break;
 34.2330 -
 34.2331 -                        default:
 34.2332 -                            if (tc >= 0 && (tc < TC_BASE || tc > TC_MAX)) {
 34.2333 -                                throw new StreamCorruptedException(
 34.2334 -                                    String.format("invalid type code: %02X",
 34.2335 -                                    tc));
 34.2336 -                            }
 34.2337 -                            return -1;
 34.2338 -                    }
 34.2339 -                }
 34.2340 -            } catch (EOFException ex) {
 34.2341 -                throw new StreamCorruptedException(
 34.2342 -                    "unexpected EOF while reading block data header");
 34.2343 -            }
 34.2344 -        }
 34.2345 -
 34.2346 -        /**
 34.2347 -         * Refills internal buffer buf with block data.  Any data in buf at the
 34.2348 -         * time of the call is considered consumed.  Sets the pos, end, and
 34.2349 -         * unread fields to reflect the new amount of available block data; if
 34.2350 -         * the next element in the stream is not a data block, sets pos and
 34.2351 -         * unread to 0 and end to -1.
 34.2352 -         */
 34.2353 -        private void refill() throws IOException {
 34.2354 -            try {
 34.2355 -                do {
 34.2356 -                    pos = 0;
 34.2357 -                    if (unread > 0) {
 34.2358 -                        int n =
 34.2359 -                            in.read(buf, 0, Math.min(unread, MAX_BLOCK_SIZE));
 34.2360 -                        if (n >= 0) {
 34.2361 -                            end = n;
 34.2362 -                            unread -= n;
 34.2363 -                        } else {
 34.2364 -                            throw new StreamCorruptedException(
 34.2365 -                                "unexpected EOF in middle of data block");
 34.2366 -                        }
 34.2367 -                    } else {
 34.2368 -                        int n = readBlockHeader(true);
 34.2369 -                        if (n >= 0) {
 34.2370 -                            end = 0;
 34.2371 -                            unread = n;
 34.2372 -                        } else {
 34.2373 -                            end = -1;
 34.2374 -                            unread = 0;
 34.2375 -                        }
 34.2376 -                    }
 34.2377 -                } while (pos == end);
 34.2378 -            } catch (IOException ex) {
 34.2379 -                pos = 0;
 34.2380 -                end = -1;
 34.2381 -                unread = 0;
 34.2382 -                throw ex;
 34.2383 -            }
 34.2384 -        }
 34.2385 -
 34.2386 -        /**
 34.2387 -         * If in block data mode, returns the number of unconsumed bytes
 34.2388 -         * remaining in the current data block.  If not in block data mode,
 34.2389 -         * throws an IllegalStateException.
 34.2390 -         */
 34.2391 -        int currentBlockRemaining() {
 34.2392 -            if (blkmode) {
 34.2393 -                return (end >= 0) ? (end - pos) + unread : 0;
 34.2394 -            } else {
 34.2395 -                throw new IllegalStateException();
 34.2396 -            }
 34.2397 -        }
 34.2398 -
 34.2399 -        /**
 34.2400 -         * Peeks at (but does not consume) and returns the next byte value in
 34.2401 -         * the stream, or -1 if the end of the stream/block data (if in block
 34.2402 -         * data mode) has been reached.
 34.2403 -         */
 34.2404 -        int peek() throws IOException {
 34.2405 -            if (blkmode) {
 34.2406 -                if (pos == end) {
 34.2407 -                    refill();
 34.2408 -                }
 34.2409 -                return (end >= 0) ? (buf[pos] & 0xFF) : -1;
 34.2410 -            } else {
 34.2411 -                return in.peek();
 34.2412 -            }
 34.2413 -        }
 34.2414 -
 34.2415 -        /**
 34.2416 -         * Peeks at (but does not consume) and returns the next byte value in
 34.2417 -         * the stream, or throws EOFException if end of stream/block data has
 34.2418 -         * been reached.
 34.2419 -         */
 34.2420 -        byte peekByte() throws IOException {
 34.2421 -            int val = peek();
 34.2422 -            if (val < 0) {
 34.2423 -                throw new EOFException();
 34.2424 -            }
 34.2425 -            return (byte) val;
 34.2426 -        }
 34.2427 -
 34.2428 -
 34.2429 -        /* ----------------- generic input stream methods ------------------ */
 34.2430 -        /*
 34.2431 -         * The following methods are equivalent to their counterparts in
 34.2432 -         * InputStream, except that they interpret data block boundaries and
 34.2433 -         * read the requested data from within data blocks when in block data
 34.2434 -         * mode.
 34.2435 -         */
 34.2436 -
 34.2437 -        public int read() throws IOException {
 34.2438 -            if (blkmode) {
 34.2439 -                if (pos == end) {
 34.2440 -                    refill();
 34.2441 -                }
 34.2442 -                return (end >= 0) ? (buf[pos++] & 0xFF) : -1;
 34.2443 -            } else {
 34.2444 -                return in.read();
 34.2445 -            }
 34.2446 -        }
 34.2447 -
 34.2448 -        public int read(byte[] b, int off, int len) throws IOException {
 34.2449 -            return read(b, off, len, false);
 34.2450 -        }
 34.2451 -
 34.2452 -        public long skip(long len) throws IOException {
 34.2453 -            long remain = len;
 34.2454 -            while (remain > 0) {
 34.2455 -                if (blkmode) {
 34.2456 -                    if (pos == end) {
 34.2457 -                        refill();
 34.2458 -                    }
 34.2459 -                    if (end < 0) {
 34.2460 -                        break;
 34.2461 -                    }
 34.2462 -                    int nread = (int) Math.min(remain, end - pos);
 34.2463 -                    remain -= nread;
 34.2464 -                    pos += nread;
 34.2465 -                } else {
 34.2466 -                    int nread = (int) Math.min(remain, MAX_BLOCK_SIZE);
 34.2467 -                    if ((nread = in.read(buf, 0, nread)) < 0) {
 34.2468 -                        break;
 34.2469 -                    }
 34.2470 -                    remain -= nread;
 34.2471 -                }
 34.2472 -            }
 34.2473 -            return len - remain;
 34.2474 -        }
 34.2475 -
 34.2476 -        public int available() throws IOException {
 34.2477 -            if (blkmode) {
 34.2478 -                if ((pos == end) && (unread == 0)) {
 34.2479 -                    int n;
 34.2480 -                    while ((n = readBlockHeader(false)) == 0) ;
 34.2481 -                    switch (n) {
 34.2482 -                        case HEADER_BLOCKED:
 34.2483 -                            break;
 34.2484 -
 34.2485 -                        case -1:
 34.2486 -                            pos = 0;
 34.2487 -                            end = -1;
 34.2488 -                            break;
 34.2489 -
 34.2490 -                        default:
 34.2491 -                            pos = 0;
 34.2492 -                            end = 0;
 34.2493 -                            unread = n;
 34.2494 -                            break;
 34.2495 -                    }
 34.2496 -                }
 34.2497 -                // avoid unnecessary call to in.available() if possible
 34.2498 -                int unreadAvail = (unread > 0) ?
 34.2499 -                    Math.min(in.available(), unread) : 0;
 34.2500 -                return (end >= 0) ? (end - pos) + unreadAvail : 0;
 34.2501 -            } else {
 34.2502 -                return in.available();
 34.2503 -            }
 34.2504 -        }
 34.2505 -
 34.2506 -        public void close() throws IOException {
 34.2507 -            if (blkmode) {
 34.2508 -                pos = 0;
 34.2509 -                end = -1;
 34.2510 -                unread = 0;
 34.2511 -            }
 34.2512 -            in.close();
 34.2513 -        }
 34.2514 -
 34.2515 -        /**
 34.2516 -         * Attempts to read len bytes into byte array b at offset off.  Returns
 34.2517 -         * the number of bytes read, or -1 if the end of stream/block data has
 34.2518 -         * been reached.  If copy is true, reads values into an intermediate
 34.2519 -         * buffer before copying them to b (to avoid exposing a reference to
 34.2520 -         * b).
 34.2521 -         */
 34.2522 -        int read(byte[] b, int off, int len, boolean copy) throws IOException {
 34.2523 -            if (len == 0) {
 34.2524 -                return 0;
 34.2525 -            } else if (blkmode) {
 34.2526 -                if (pos == end) {
 34.2527 -                    refill();
 34.2528 -                }
 34.2529 -                if (end < 0) {
 34.2530 -                    return -1;
 34.2531 -                }
 34.2532 -                int nread = Math.min(len, end - pos);
 34.2533 -                System.arraycopy(buf, pos, b, off, nread);
 34.2534 -                pos += nread;
 34.2535 -                return nread;
 34.2536 -            } else if (copy) {
 34.2537 -                int nread = in.read(buf, 0, Math.min(len, MAX_BLOCK_SIZE));
 34.2538 -                if (nread > 0) {
 34.2539 -                    System.arraycopy(buf, 0, b, off, nread);
 34.2540 -                }
 34.2541 -                return nread;
 34.2542 -            } else {
 34.2543 -                return in.read(b, off, len);
 34.2544 -            }
 34.2545 -        }
 34.2546 -
 34.2547 -        /* ----------------- primitive data input methods ------------------ */
 34.2548 -        /*
 34.2549 -         * The following methods are equivalent to their counterparts in
 34.2550 -         * DataInputStream, except that they interpret data block boundaries
 34.2551 -         * and read the requested data from within data blocks when in block
 34.2552 -         * data mode.
 34.2553 -         */
 34.2554 -
 34.2555 -        public void readFully(byte[] b) throws IOException {
 34.2556 -            readFully(b, 0, b.length, false);
 34.2557 -        }
 34.2558 -
 34.2559 -        public void readFully(byte[] b, int off, int len) throws IOException {
 34.2560 -            readFully(b, off, len, false);
 34.2561 -        }
 34.2562 -
 34.2563 -        public void readFully(byte[] b, int off, int len, boolean copy)
 34.2564 -            throws IOException
 34.2565 -        {
 34.2566 -            while (len > 0) {
 34.2567 -                int n = read(b, off, len, copy);
 34.2568 -                if (n < 0) {
 34.2569 -                    throw new EOFException();
 34.2570 -                }
 34.2571 -                off += n;
 34.2572 -                len -= n;
 34.2573 -            }
 34.2574 -        }
 34.2575 -
 34.2576 -        public int skipBytes(int n) throws IOException {
 34.2577 -            return din.skipBytes(n);
 34.2578 -        }
 34.2579 -
 34.2580 -        public boolean readBoolean() throws IOException {
 34.2581 -            int v = read();
 34.2582 -            if (v < 0) {
 34.2583 -                throw new EOFException();
 34.2584 -            }
 34.2585 -            return (v != 0);
 34.2586 -        }
 34.2587 -
 34.2588 -        public byte readByte() throws IOException {
 34.2589 -            int v = read();
 34.2590 -            if (v < 0) {
 34.2591 -                throw new EOFException();
 34.2592 -            }
 34.2593 -            return (byte) v;
 34.2594 -        }
 34.2595 -
 34.2596 -        public int readUnsignedByte() throws IOException {
 34.2597 -            int v = read();
 34.2598 -            if (v < 0) {
 34.2599 -                throw new EOFException();
 34.2600 -            }
 34.2601 -            return v;
 34.2602 -        }
 34.2603 -
 34.2604 -        public char readChar() throws IOException {
 34.2605 -            if (!blkmode) {
 34.2606 -                pos = 0;
 34.2607 -                in.readFully(buf, 0, 2);
 34.2608 -            } else if (end - pos < 2) {
 34.2609 -                return din.readChar();
 34.2610 -            }
 34.2611 -            char v = Bits.getChar(buf, pos);
 34.2612 -            pos += 2;
 34.2613 -            return v;
 34.2614 -        }
 34.2615 -
 34.2616 -        public short readShort() throws IOException {
 34.2617 -            if (!blkmode) {
 34.2618 -                pos = 0;
 34.2619 -                in.readFully(buf, 0, 2);
 34.2620 -            } else if (end - pos < 2) {
 34.2621 -                return din.readShort();
 34.2622 -            }
 34.2623 -            short v = Bits.getShort(buf, pos);
 34.2624 -            pos += 2;
 34.2625 -            return v;
 34.2626 -        }
 34.2627 -
 34.2628 -        public int readUnsignedShort() throws IOException {
 34.2629 -            if (!blkmode) {
 34.2630 -                pos = 0;
 34.2631 -                in.readFully(buf, 0, 2);
 34.2632 -            } else if (end - pos < 2) {
 34.2633 -                return din.readUnsignedShort();
 34.2634 -            }
 34.2635 -            int v = Bits.getShort(buf, pos) & 0xFFFF;
 34.2636 -            pos += 2;
 34.2637 -            return v;
 34.2638 -        }
 34.2639 -
 34.2640 -        public int readInt() throws IOException {
 34.2641 -            if (!blkmode) {
 34.2642 -                pos = 0;
 34.2643 -                in.readFully(buf, 0, 4);
 34.2644 -            } else if (end - pos < 4) {
 34.2645 -                return din.readInt();
 34.2646 -            }
 34.2647 -            int v = Bits.getInt(buf, pos);
 34.2648 -            pos += 4;
 34.2649 -            return v;
 34.2650 -        }
 34.2651 -
 34.2652 -        public float readFloat() throws IOException {
 34.2653 -            if (!blkmode) {
 34.2654 -                pos = 0;
 34.2655 -                in.readFully(buf, 0, 4);
 34.2656 -            } else if (end - pos < 4) {
 34.2657 -                return din.readFloat();
 34.2658 -            }
 34.2659 -            float v = Bits.getFloat(buf, pos);
 34.2660 -            pos += 4;
 34.2661 -            return v;
 34.2662 -        }
 34.2663 -
 34.2664 -        public long readLong() throws IOException {
 34.2665 -            if (!blkmode) {
 34.2666 -                pos = 0;
 34.2667 -                in.readFully(buf, 0, 8);
 34.2668 -            } else if (end - pos < 8) {
 34.2669 -                return din.readLong();
 34.2670 -            }
 34.2671 -            long v = Bits.getLong(buf, pos);
 34.2672 -            pos += 8;
 34.2673 -            return v;
 34.2674 -        }
 34.2675 -
 34.2676 -        public double readDouble() throws IOException {
 34.2677 -            if (!blkmode) {
 34.2678 -                pos = 0;
 34.2679 -                in.readFully(buf, 0, 8);
 34.2680 -            } else if (end - pos < 8) {
 34.2681 -                return din.readDouble();
 34.2682 -            }
 34.2683 -            double v = Bits.getDouble(buf, pos);
 34.2684 -            pos += 8;
 34.2685 -            return v;
 34.2686 -        }
 34.2687 -
 34.2688 -        public String readUTF() throws IOException {
 34.2689 -            return readUTFBody(readUnsignedShort());
 34.2690 -        }
 34.2691 -
 34.2692 -        public String readLine() throws IOException {
 34.2693 -            return din.readLine();      // deprecated, not worth optimizing
 34.2694 -        }
 34.2695 -
 34.2696 -        /* -------------- primitive data array input methods --------------- */
 34.2697 -        /*
 34.2698 -         * The following methods read in spans of primitive data values.
 34.2699 -         * Though equivalent to calling the corresponding primitive read
 34.2700 -         * methods repeatedly, these methods are optimized for reading groups
 34.2701 -         * of primitive data values more efficiently.
 34.2702 -         */
 34.2703 -
 34.2704 -        void readBooleans(boolean[] v, int off, int len) throws IOException {
 34.2705 -            int stop, endoff = off + len;
 34.2706 -            while (off < endoff) {
 34.2707 -                if (!blkmode) {
 34.2708 -                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE);
 34.2709 -                    in.readFully(buf, 0, span);
 34.2710 -                    stop = off + span;
 34.2711 -                    pos = 0;
 34.2712 -                } else if (end - pos < 1) {
 34.2713 -                    v[off++] = din.readBoolean();
 34.2714 -                    continue;
 34.2715 -                } else {
 34.2716 -                    stop = Math.min(endoff, off + end - pos);
 34.2717 -                }
 34.2718 -
 34.2719 -                while (off < stop) {
 34.2720 -                    v[off++] = Bits.getBoolean(buf, pos++);
 34.2721 -                }
 34.2722 -            }
 34.2723 -        }
 34.2724 -
 34.2725 -        void readChars(char[] v, int off, int len) throws IOException {
 34.2726 -            int stop, endoff = off + len;
 34.2727 -            while (off < endoff) {
 34.2728 -                if (!blkmode) {
 34.2729 -                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 1);
 34.2730 -                    in.readFully(buf, 0, span << 1);
 34.2731 -                    stop = off + span;
 34.2732 -                    pos = 0;
 34.2733 -                } else if (end - pos < 2) {
 34.2734 -                    v[off++] = din.readChar();
 34.2735 -                    continue;
 34.2736 -                } else {
 34.2737 -                    stop = Math.min(endoff, off + ((end - pos) >> 1));
 34.2738 -                }
 34.2739 -
 34.2740 -                while (off < stop) {
 34.2741 -                    v[off++] = Bits.getChar(buf, pos);
 34.2742 -                    pos += 2;
 34.2743 -                }
 34.2744 -            }
 34.2745 -        }
 34.2746 -
 34.2747 -        void readShorts(short[] v, int off, int len) throws IOException {
 34.2748 -            int stop, endoff = off + len;
 34.2749 -            while (off < endoff) {
 34.2750 -                if (!blkmode) {
 34.2751 -                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 1);
 34.2752 -                    in.readFully(buf, 0, span << 1);
 34.2753 -                    stop = off + span;
 34.2754 -                    pos = 0;
 34.2755 -                } else if (end - pos < 2) {
 34.2756 -                    v[off++] = din.readShort();
 34.2757 -                    continue;
 34.2758 -                } else {
 34.2759 -                    stop = Math.min(endoff, off + ((end - pos) >> 1));
 34.2760 -                }
 34.2761 -
 34.2762 -                while (off < stop) {
 34.2763 -                    v[off++] = Bits.getShort(buf, pos);
 34.2764 -                    pos += 2;
 34.2765 -                }
 34.2766 -            }
 34.2767 -        }
 34.2768 -
 34.2769 -        void readInts(int[] v, int off, int len) throws IOException {
 34.2770 -            int stop, endoff = off + len;
 34.2771 -            while (off < endoff) {
 34.2772 -                if (!blkmode) {
 34.2773 -                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
 34.2774 -                    in.readFully(buf, 0, span << 2);
 34.2775 -                    stop = off + span;
 34.2776 -                    pos = 0;
 34.2777 -                } else if (end - pos < 4) {
 34.2778 -                    v[off++] = din.readInt();
 34.2779 -                    continue;
 34.2780 -                } else {
 34.2781 -                    stop = Math.min(endoff, off + ((end - pos) >> 2));
 34.2782 -                }
 34.2783 -
 34.2784 -                while (off < stop) {
 34.2785 -                    v[off++] = Bits.getInt(buf, pos);
 34.2786 -                    pos += 4;
 34.2787 -                }
 34.2788 -            }
 34.2789 -        }
 34.2790 -
 34.2791 -        void readFloats(float[] v, int off, int len) throws IOException {
 34.2792 -            int span, endoff = off + len;
 34.2793 -            while (off < endoff) {
 34.2794 -                if (!blkmode) {
 34.2795 -                    span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
 34.2796 -                    in.readFully(buf, 0, span << 2);
 34.2797 -                    pos = 0;
 34.2798 -                } else if (end - pos < 4) {
 34.2799 -                    v[off++] = din.readFloat();
 34.2800 -                    continue;
 34.2801 -                } else {
 34.2802 -                    span = Math.min(endoff - off, ((end - pos) >> 2));
 34.2803 -                }
 34.2804 -
 34.2805 -                bytesToFloats(buf, pos, v, off, span);
 34.2806 -                off += span;
 34.2807 -                pos += span << 2;
 34.2808 -            }
 34.2809 -        }
 34.2810 -
 34.2811 -        void readLongs(long[] v, int off, int len) throws IOException {
 34.2812 -            int stop, endoff = off + len;
 34.2813 -            while (off < endoff) {
 34.2814 -                if (!blkmode) {
 34.2815 -                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
 34.2816 -                    in.readFully(buf, 0, span << 3);
 34.2817 -                    stop = off + span;
 34.2818 -                    pos = 0;
 34.2819 -                } else if (end - pos < 8) {
 34.2820 -                    v[off++] = din.readLong();
 34.2821 -                    continue;
 34.2822 -                } else {
 34.2823 -                    stop = Math.min(endoff, off + ((end - pos) >> 3));
 34.2824 -                }
 34.2825 -
 34.2826 -                while (off < stop) {
 34.2827 -                    v[off++] = Bits.getLong(buf, pos);
 34.2828 -                    pos += 8;
 34.2829 -                }
 34.2830 -            }
 34.2831 -        }
 34.2832 -
 34.2833 -        void readDoubles(double[] v, int off, int len) throws IOException {
 34.2834 -            int span, endoff = off + len;
 34.2835 -            while (off < endoff) {
 34.2836 -                if (!blkmode) {
 34.2837 -                    span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
 34.2838 -                    in.readFully(buf, 0, span << 3);
 34.2839 -                    pos = 0;
 34.2840 -                } else if (end - pos < 8) {
 34.2841 -                    v[off++] = din.readDouble();
 34.2842 -                    continue;
 34.2843 -                } else {
 34.2844 -                    span = Math.min(endoff - off, ((end - pos) >> 3));
 34.2845 -                }
 34.2846 -
 34.2847 -                bytesToDoubles(buf, pos, v, off, span);
 34.2848 -                off += span;
 34.2849 -                pos += span << 3;
 34.2850 -            }
 34.2851 -        }
 34.2852 -
 34.2853 -        /**
 34.2854 -         * Reads in string written in "long" UTF format.  "Long" UTF format is
 34.2855 -         * identical to standard UTF, except that it uses an 8 byte header
 34.2856 -         * (instead of the standard 2 bytes) to convey the UTF encoding length.
 34.2857 -         */
 34.2858 -        String readLongUTF() throws IOException {
 34.2859 -            return readUTFBody(readLong());
 34.2860 -        }
 34.2861 -
 34.2862 -        /**
 34.2863 -         * Reads in the "body" (i.e., the UTF representation minus the 2-byte
 34.2864 -         * or 8-byte length header) of a UTF encoding, which occupies the next
 34.2865 -         * utflen bytes.
 34.2866 -         */
 34.2867 -        private String readUTFBody(long utflen) throws IOException {
 34.2868 -            StringBuilder sbuf = new StringBuilder();
 34.2869 -            if (!blkmode) {
 34.2870 -                end = pos = 0;
 34.2871 -            }
 34.2872 -
 34.2873 -            while (utflen > 0) {
 34.2874 -                int avail = end - pos;
 34.2875 -                if (avail >= 3 || (long) avail == utflen) {
 34.2876 -                    utflen -= readUTFSpan(sbuf, utflen);
 34.2877 -                } else {
 34.2878 -                    if (blkmode) {
 34.2879 -                        // near block boundary, read one byte at a time
 34.2880 -                        utflen -= readUTFChar(sbuf, utflen);
 34.2881 -                    } else {
 34.2882 -                        // shift and refill buffer manually
 34.2883 -                        if (avail > 0) {
 34.2884 -                            System.arraycopy(buf, pos, buf, 0, avail);
 34.2885 -                        }
 34.2886 -                        pos = 0;
 34.2887 -                        end = (int) Math.min(MAX_BLOCK_SIZE, utflen);
 34.2888 -                        in.readFully(buf, avail, end - avail);
 34.2889 -                    }
 34.2890 -                }
 34.2891 -            }
 34.2892 -
 34.2893 -            return sbuf.toString();
 34.2894 -        }
 34.2895 -
 34.2896 -        /**
 34.2897 -         * Reads span of UTF-encoded characters out of internal buffer
 34.2898 -         * (starting at offset pos and ending at or before offset end),
 34.2899 -         * consuming no more than utflen bytes.  Appends read characters to
 34.2900 -         * sbuf.  Returns the number of bytes consumed.
 34.2901 -         */
 34.2902 -        private long readUTFSpan(StringBuilder sbuf, long utflen)
 34.2903 -            throws IOException
 34.2904 -        {
 34.2905 -            int cpos = 0;
 34.2906 -            int start = pos;
 34.2907 -            int avail = Math.min(end - pos, CHAR_BUF_SIZE);
 34.2908 -            // stop short of last char unless all of utf bytes in buffer
 34.2909 -            int stop = pos + ((utflen > avail) ? avail - 2 : (int) utflen);
 34.2910 -            boolean outOfBounds = false;
 34.2911 -
 34.2912 -            try {
 34.2913 -                while (pos < stop) {
 34.2914 -                    int b1, b2, b3;
 34.2915 -                    b1 = buf[pos++] & 0xFF;
 34.2916 -                    switch (b1 >> 4) {
 34.2917 -                        case 0:
 34.2918 -                        case 1:
 34.2919 -                        case 2:
 34.2920 -                        case 3:
 34.2921 -                        case 4:
 34.2922 -                        case 5:
 34.2923 -                        case 6:
 34.2924 -                        case 7:   // 1 byte format: 0xxxxxxx
 34.2925 -                            cbuf[cpos++] = (char) b1;
 34.2926 -                            break;
 34.2927 -
 34.2928 -                        case 12:
 34.2929 -                        case 13:  // 2 byte format: 110xxxxx 10xxxxxx
 34.2930 -                            b2 = buf[pos++];
 34.2931 -                            if ((b2 & 0xC0) != 0x80) {
 34.2932 -                                throw new UTFDataFormatException();
 34.2933 -                            }
 34.2934 -                            cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) |
 34.2935 -                                                   ((b2 & 0x3F) << 0));
 34.2936 -                            break;
 34.2937 -
 34.2938 -                        case 14:  // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
 34.2939 -                            b3 = buf[pos + 1];
 34.2940 -                            b2 = buf[pos + 0];
 34.2941 -                            pos += 2;
 34.2942 -                            if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
 34.2943 -                                throw new UTFDataFormatException();
 34.2944 -                            }
 34.2945 -                            cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) |
 34.2946 -                                                   ((b2 & 0x3F) << 6) |
 34.2947 -                                                   ((b3 & 0x3F) << 0));
 34.2948 -                            break;
 34.2949 -
 34.2950 -                        default:  // 10xx xxxx, 1111 xxxx
 34.2951 -                            throw new UTFDataFormatException();
 34.2952 -                    }
 34.2953 -                }
 34.2954 -            } catch (ArrayIndexOutOfBoundsException ex) {
 34.2955 -                outOfBounds = true;
 34.2956 -            } finally {
 34.2957 -                if (outOfBounds || (pos - start) > utflen) {
 34.2958 -                    /*
 34.2959 -                     * Fix for 4450867: if a malformed utf char causes the
 34.2960 -                     * conversion loop to scan past the expected end of the utf
 34.2961 -                     * string, only consume the expected number of utf bytes.
 34.2962 -                     */
 34.2963 -                    pos = start + (int) utflen;
 34.2964 -                    throw new UTFDataFormatException();
 34.2965 -                }
 34.2966 -            }
 34.2967 -
 34.2968 -            sbuf.append(cbuf, 0, cpos);
 34.2969 -            return pos - start;
 34.2970 -        }
 34.2971 -
 34.2972 -        /**
 34.2973 -         * Reads in single UTF-encoded character one byte at a time, appends
 34.2974 -         * the character to sbuf, and returns the number of bytes consumed.
 34.2975 -         * This method is used when reading in UTF strings written in block
 34.2976 -         * data mode to handle UTF-encoded characters which (potentially)
 34.2977 -         * straddle block-data boundaries.
 34.2978 -         */
 34.2979 -        private int readUTFChar(StringBuilder sbuf, long utflen)
 34.2980 -            throws IOException
 34.2981 -        {
 34.2982 -            int b1, b2, b3;
 34.2983 -            b1 = readByte() & 0xFF;
 34.2984 -            switch (b1 >> 4) {
 34.2985 -                case 0:
 34.2986 -                case 1:
 34.2987 -                case 2:
 34.2988 -                case 3:
 34.2989 -                case 4:
 34.2990 -                case 5:
 34.2991 -                case 6:
 34.2992 -                case 7:     // 1 byte format: 0xxxxxxx
 34.2993 -                    sbuf.append((char) b1);
 34.2994 -                    return 1;
 34.2995 -
 34.2996 -                case 12:
 34.2997 -                case 13:    // 2 byte format: 110xxxxx 10xxxxxx
 34.2998 -                    if (utflen < 2) {
 34.2999 -                        throw new UTFDataFormatException();
 34.3000 -                    }
 34.3001 -                    b2 = readByte();
 34.3002 -                    if ((b2 & 0xC0) != 0x80) {
 34.3003 -                        throw new UTFDataFormatException();
 34.3004 -                    }
 34.3005 -                    sbuf.append((char) (((b1 & 0x1F) << 6) |
 34.3006 -                                        ((b2 & 0x3F) << 0)));
 34.3007 -                    return 2;
 34.3008 -
 34.3009 -                case 14:    // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
 34.3010 -                    if (utflen < 3) {
 34.3011 -                        if (utflen == 2) {
 34.3012 -                            readByte();         // consume remaining byte
 34.3013 -                        }
 34.3014 -                        throw new UTFDataFormatException();
 34.3015 -                    }
 34.3016 -                    b2 = readByte();
 34.3017 -                    b3 = readByte();
 34.3018 -                    if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
 34.3019 -                        throw new UTFDataFormatException();
 34.3020 -                    }
 34.3021 -                    sbuf.append((char) (((b1 & 0x0F) << 12) |
 34.3022 -                                        ((b2 & 0x3F) << 6) |
 34.3023 -                                        ((b3 & 0x3F) << 0)));
 34.3024 -                    return 3;
 34.3025 -
 34.3026 -                default:   // 10xx xxxx, 1111 xxxx
 34.3027 -                    throw new UTFDataFormatException();
 34.3028 -            }
 34.3029 -        }
 34.3030 -    }
 34.3031 -
 34.3032 -    /**
 34.3033 -     * Unsynchronized table which tracks wire handle to object mappings, as
 34.3034 -     * well as ClassNotFoundExceptions associated with deserialized objects.
 34.3035 -     * This class implements an exception-propagation algorithm for
 34.3036 -     * determining which objects should have ClassNotFoundExceptions associated
 34.3037 -     * with them, taking into account cycles and discontinuities (e.g., skipped
 34.3038 -     * fields) in the object graph.
 34.3039 -     *
 34.3040 -     * <p>General use of the table is as follows: during deserialization, a
 34.3041 -     * given object is first assigned a handle by calling the assign method.
 34.3042 -     * This method leaves the assigned handle in an "open" state, wherein
 34.3043 -     * dependencies on the exception status of other handles can be registered
 34.3044 -     * by calling the markDependency method, or an exception can be directly
 34.3045 -     * associated with the handle by calling markException.  When a handle is
 34.3046 -     * tagged with an exception, the HandleTable assumes responsibility for
 34.3047 -     * propagating the exception to any other objects which depend
 34.3048 -     * (transitively) on the exception-tagged object.
 34.3049 -     *
 34.3050 -     * <p>Once all exception information/dependencies for the handle have been
 34.3051 -     * registered, the handle should be "closed" by calling the finish method
 34.3052 -     * on it.  The act of finishing a handle allows the exception propagation
 34.3053 -     * algorithm to aggressively prune dependency links, lessening the
 34.3054 -     * performance/memory impact of exception tracking.
 34.3055 -     *
 34.3056 -     * <p>Note that the exception propagation algorithm used depends on handles
 34.3057 -     * being assigned/finished in LIFO order; however, for simplicity as well
 34.3058 -     * as memory conservation, it does not enforce this constraint.
 34.3059 -     */
 34.3060 -    // REMIND: add full description of exception propagation algorithm?
 34.3061 -    private static class HandleTable {
 34.3062 -
 34.3063 -        /* status codes indicating whether object has associated exception */
 34.3064 -        private static final byte STATUS_OK = 1;
 34.3065 -        private static final byte STATUS_UNKNOWN = 2;
 34.3066 -        private static final byte STATUS_EXCEPTION = 3;
 34.3067 -
 34.3068 -        /** array mapping handle -> object status */
 34.3069 -        byte[] status;
 34.3070 -        /** array mapping handle -> object/exception (depending on status) */
 34.3071 -        Object[] entries;
 34.3072 -        /** array mapping handle -> list of dependent handles (if any) */
 34.3073 -        HandleList[] deps;
 34.3074 -        /** lowest unresolved dependency */
 34.3075 -        int lowDep = -1;
 34.3076 -        /** number of handles in table */
 34.3077 -        int size = 0;
 34.3078 -
 34.3079 -        /**
 34.3080 -         * Creates handle table with the given initial capacity.
 34.3081 -         */
 34.3082 -        HandleTable(int initialCapacity) {
 34.3083 -            status = new byte[initialCapacity];
 34.3084 -            entries = new Object[initialCapacity];
 34.3085 -            deps = new HandleList[initialCapacity];
 34.3086 -        }
 34.3087 -
 34.3088 -        /**
 34.3089 -         * Assigns next available handle to given object, and returns assigned
 34.3090 -         * handle.  Once object has been completely deserialized (and all
 34.3091 -         * dependencies on other objects identified), the handle should be
 34.3092 -         * "closed" by passing it to finish().
 34.3093 -         */
 34.3094 -        int assign(Object obj) {
 34.3095 -            if (size >= entries.length) {
 34.3096 -                grow();
 34.3097 -            }
 34.3098 -            status[size] = STATUS_UNKNOWN;
 34.3099 -            entries[size] = obj;
 34.3100 -            return size++;
 34.3101 -        }
 34.3102 -
 34.3103 -        /**
 34.3104 -         * Registers a dependency (in exception status) of one handle on
 34.3105 -         * another.  The dependent handle must be "open" (i.e., assigned, but
 34.3106 -         * not finished yet).  No action is taken if either dependent or target
 34.3107 -         * handle is NULL_HANDLE.
 34.3108 -         */
 34.3109 -        void markDependency(int dependent, int target) {
 34.3110 -            if (dependent == NULL_HANDLE || target == NULL_HANDLE) {
 34.3111 -                return;
 34.3112 -            }
 34.3113 -            switch (status[dependent]) {
 34.3114 -
 34.3115 -                case STATUS_UNKNOWN:
 34.3116 -                    switch (status[target]) {
 34.3117 -                        case STATUS_OK:
 34.3118 -                            // ignore dependencies on objs with no exception
 34.3119 -                            break;
 34.3120 -
 34.3121 -                        case STATUS_EXCEPTION:
 34.3122 -                            // eagerly propagate exception
 34.3123 -                            markException(dependent,
 34.3124 -                                (ClassNotFoundException) entries[target]);
 34.3125 -                            break;
 34.3126 -
 34.3127 -                        case STATUS_UNKNOWN:
 34.3128 -                            // add to dependency list of target
 34.3129 -                            if (deps[target] == null) {
 34.3130 -                                deps[target] = new HandleList();
 34.3131 -                            }
 34.3132 -                            deps[target].add(dependent);
 34.3133 -
 34.3134 -                            // remember lowest unresolved target seen
 34.3135 -                            if (lowDep < 0 || lowDep > target) {
 34.3136 -                                lowDep = target;
 34.3137 -                            }
 34.3138 -                            break;
 34.3139 -
 34.3140 -                        default:
 34.3141 -                            throw new InternalError();
 34.3142 -                    }
 34.3143 -                    break;
 34.3144 -
 34.3145 -                case STATUS_EXCEPTION:
 34.3146 -                    break;
 34.3147 -
 34.3148 -                default:
 34.3149 -                    throw new InternalError();
 34.3150 -            }
 34.3151 -        }
 34.3152 -
 34.3153 -        /**
 34.3154 -         * Associates a ClassNotFoundException (if one not already associated)
 34.3155 -         * with the currently active handle and propagates it to other
 34.3156 -         * referencing objects as appropriate.  The specified handle must be
 34.3157 -         * "open" (i.e., assigned, but not finished yet).
 34.3158 -         */
 34.3159 -        void markException(int handle, ClassNotFoundException ex) {
 34.3160 -            switch (status[handle]) {
 34.3161 -                case STATUS_UNKNOWN:
 34.3162 -                    status[handle] = STATUS_EXCEPTION;
 34.3163 -                    entries[handle] = ex;
 34.3164 -
 34.3165 -                    // propagate exception to dependents
 34.3166 -                    HandleList dlist = deps[handle];
 34.3167 -                    if (dlist != null) {
 34.3168 -                        int ndeps = dlist.size();
 34.3169 -                        for (int i = 0; i < ndeps; i++) {
 34.3170 -                            markException(dlist.get(i), ex);
 34.3171 -                        }
 34.3172 -                        deps[handle] = null;
 34.3173 -                    }
 34.3174 -                    break;
 34.3175 -
 34.3176 -                case STATUS_EXCEPTION:
 34.3177 -                    break;
 34.3178 -
 34.3179 -                default:
 34.3180 -                    throw new InternalError();
 34.3181 -            }
 34.3182 -        }
 34.3183 -
 34.3184 -        /**
 34.3185 -         * Marks given handle as finished, meaning that no new dependencies
 34.3186 -         * will be marked for handle.  Calls to the assign and finish methods
 34.3187 -         * must occur in LIFO order.
 34.3188 -         */
 34.3189 -        void finish(int handle) {
 34.3190 -            int end;
 34.3191 -            if (lowDep < 0) {
 34.3192 -                // no pending unknowns, only resolve current handle
 34.3193 -                end = handle + 1;
 34.3194 -            } else if (lowDep >= handle) {
 34.3195 -                // pending unknowns now clearable, resolve all upward handles
 34.3196 -                end = size;
 34.3197 -                lowDep = -1;
 34.3198 -            } else {
 34.3199 -                // unresolved backrefs present, can't resolve anything yet
 34.3200 -                return;
 34.3201 -            }
 34.3202 -
 34.3203 -            // change STATUS_UNKNOWN -> STATUS_OK in selected span of handles
 34.3204 -            for (int i = handle; i < end; i++) {
 34.3205 -                switch (status[i]) {
 34.3206 -                    case STATUS_UNKNOWN:
 34.3207 -                        status[i] = STATUS_OK;
 34.3208 -                        deps[i] = null;
 34.3209 -                        break;
 34.3210 -
 34.3211 -                    case STATUS_OK:
 34.3212 -                    case STATUS_EXCEPTION:
 34.3213 -                        break;
 34.3214 -
 34.3215 -                    default:
 34.3216 -                        throw new InternalError();
 34.3217 -                }
 34.3218 -            }
 34.3219 -        }
 34.3220 -
 34.3221 -        /**
 34.3222 -         * Assigns a new object to the given handle.  The object previously
 34.3223 -         * associated with the handle is forgotten.  This method has no effect
 34.3224 -         * if the given handle already has an exception associated with it.
 34.3225 -         * This method may be called at any time after the handle is assigned.
 34.3226 -         */
 34.3227 -        void setObject(int handle, Object obj) {
 34.3228 -            switch (status[handle]) {
 34.3229 -                case STATUS_UNKNOWN:
 34.3230 -                case STATUS_OK:
 34.3231 -                    entries[handle] = obj;
 34.3232 -                    break;
 34.3233 -
 34.3234 -                case STATUS_EXCEPTION:
 34.3235 -                    break;
 34.3236 -
 34.3237 -                default:
 34.3238 -                    throw new InternalError();
 34.3239 -            }
 34.3240 -        }
 34.3241 -
 34.3242 -        /**
 34.3243 -         * Looks up and returns object associated with the given handle.
 34.3244 -         * Returns null if the given handle is NULL_HANDLE, or if it has an
 34.3245 -         * associated ClassNotFoundException.
 34.3246 -         */
 34.3247 -        Object lookupObject(int handle) {
 34.3248 -            return (handle != NULL_HANDLE &&
 34.3249 -                    status[handle] != STATUS_EXCEPTION) ?
 34.3250 -                entries[handle] : null;
 34.3251 -        }
 34.3252 -
 34.3253 -        /**
 34.3254 -         * Looks up and returns ClassNotFoundException associated with the
 34.3255 -         * given handle.  Returns null if the given handle is NULL_HANDLE, or
 34.3256 -         * if there is no ClassNotFoundException associated with the handle.
 34.3257 -         */
 34.3258 -        ClassNotFoundException lookupException(int handle) {
 34.3259 -            return (handle != NULL_HANDLE &&
 34.3260 -                    status[handle] == STATUS_EXCEPTION) ?
 34.3261 -                (ClassNotFoundException) entries[handle] : null;
 34.3262 -        }
 34.3263 -
 34.3264 -        /**
 34.3265 -         * Resets table to its initial state.
 34.3266 -         */
 34.3267 -        void clear() {
 34.3268 -            Arrays.fill(status, 0, size, (byte) 0);
 34.3269 -            Arrays.fill(entries, 0, size, null);
 34.3270 -            Arrays.fill(deps, 0, size, null);
 34.3271 -            lowDep = -1;
 34.3272 -            size = 0;
 34.3273 -        }
 34.3274 -
 34.3275 -        /**
 34.3276 -         * Returns number of handles registered in table.
 34.3277 -         */
 34.3278 -        int size() {
 34.3279 -            return size;
 34.3280 -        }
 34.3281 -
 34.3282 -        /**
 34.3283 -         * Expands capacity of internal arrays.
 34.3284 -         */
 34.3285 -        private void grow() {
 34.3286 -            int newCapacity = (entries.length << 1) + 1;
 34.3287 -
 34.3288 -            byte[] newStatus = new byte[newCapacity];
 34.3289 -            Object[] newEntries = new Object[newCapacity];
 34.3290 -            HandleList[] newDeps = new HandleList[newCapacity];
 34.3291 -
 34.3292 -            System.arraycopy(status, 0, newStatus, 0, size);
 34.3293 -            System.arraycopy(entries, 0, newEntries, 0, size);
 34.3294 -            System.arraycopy(deps, 0, newDeps, 0, size);
 34.3295 -
 34.3296 -            status = newStatus;
 34.3297 -            entries = newEntries;
 34.3298 -            deps = newDeps;
 34.3299 -        }
 34.3300 -
 34.3301 -        /**
 34.3302 -         * Simple growable list of (integer) handles.
 34.3303 -         */
 34.3304 -        private static class HandleList {
 34.3305 -            private int[] list = new int[4];
 34.3306 -            private int size = 0;
 34.3307 -
 34.3308 -            public HandleList() {
 34.3309 -            }
 34.3310 -
 34.3311 -            public void add(int handle) {
 34.3312 -                if (size >= list.length) {
 34.3313 -                    int[] newList = new int[list.length << 1];
 34.3314 -                    System.arraycopy(list, 0, newList, 0, list.length);
 34.3315 -                    list = newList;
 34.3316 -                }
 34.3317 -                list[size++] = handle;
 34.3318 -            }
 34.3319 -
 34.3320 -            public int get(int index) {
 34.3321 -                if (index >= size) {
 34.3322 -                    throw new ArrayIndexOutOfBoundsException();
 34.3323 -                }
 34.3324 -                return list[index];
 34.3325 -            }
 34.3326 -
 34.3327 -            public int size() {
 34.3328 -                return size;
 34.3329 -            }
 34.3330 -        }
 34.3331 -    }
 34.3332 -
 34.3333 -    /**
 34.3334 -     * Method for cloning arrays in case of using unsharing reading
 34.3335 -     */
 34.3336 -    private static Object cloneArray(Object array) {
 34.3337 -        if (array instanceof Object[]) {
 34.3338 -            return ((Object[]) array).clone();
 34.3339 -        } else if (array instanceof boolean[]) {
 34.3340 -            return ((boolean[]) array).clone();
 34.3341 -        } else if (array instanceof byte[]) {
 34.3342 -            return ((byte[]) array).clone();
 34.3343 -        } else if (array instanceof char[]) {
 34.3344 -            return ((char[]) array).clone();
 34.3345 -        } else if (array instanceof double[]) {
 34.3346 -            return ((double[]) array).clone();
 34.3347 -        } else if (array instanceof float[]) {
 34.3348 -            return ((float[]) array).clone();
 34.3349 -        } else if (array instanceof int[]) {
 34.3350 -            return ((int[]) array).clone();
 34.3351 -        } else if (array instanceof long[]) {
 34.3352 -            return ((long[]) array).clone();
 34.3353 -        } else if (array instanceof short[]) {
 34.3354 -            return ((short[]) array).clone();
 34.3355 -        } else {
 34.3356 -            throw new AssertionError();
 34.3357 -        }
 34.3358 -    }
 34.3359 -
 34.3360 -}
    35.1 --- a/emul/compact/src/main/java/java/io/ObjectInputValidation.java	Mon Feb 25 19:00:08 2013 +0100
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,45 +0,0 @@
    35.4 -/*
    35.5 - * Copyright (c) 1996, 1999, 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.io;
   35.30 -
   35.31 -/**
   35.32 - * Callback interface to allow validation of objects within a graph.
   35.33 - * Allows an object to be called when a complete graph of objects has
   35.34 - * been deserialized.
   35.35 - *
   35.36 - * @author  unascribed
   35.37 - * @see     ObjectInputStream
   35.38 - * @see     ObjectInputStream#registerValidation(java.io.ObjectInputValidation, int)
   35.39 - * @since   JDK1.1
   35.40 - */
   35.41 -public interface ObjectInputValidation {
   35.42 -    /**
   35.43 -     * Validates the object.
   35.44 -     *
   35.45 -     * @exception InvalidObjectException If the object cannot validate itself.
   35.46 -     */
   35.47 -    public void validateObject() throws InvalidObjectException;
   35.48 -}
    36.1 --- a/emul/compact/src/main/java/java/io/ObjectOutput.java	Mon Feb 25 19:00:08 2013 +0100
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,90 +0,0 @@
    36.4 -/*
    36.5 - * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
    36.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.7 - *
    36.8 - * This code is free software; you can redistribute it and/or modify it
    36.9 - * under the terms of the GNU General Public License version 2 only, as
   36.10 - * published by the Free Software Foundation.  Oracle designates this
   36.11 - * particular file as subject to the "Classpath" exception as provided
   36.12 - * by Oracle in the LICENSE file that accompanied this code.
   36.13 - *
   36.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   36.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   36.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   36.17 - * version 2 for more details (a copy is included in the LICENSE file that
   36.18 - * accompanied this code).
   36.19 - *
   36.20 - * You should have received a copy of the GNU General Public License version
   36.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   36.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   36.23 - *
   36.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   36.25 - * or visit www.oracle.com if you need additional information or have any
   36.26 - * questions.
   36.27 - */
   36.28 -
   36.29 -package java.io;
   36.30 -
   36.31 -/**
   36.32 - * ObjectOutput extends the DataOutput interface to include writing of objects.
   36.33 - * DataOutput includes methods for output of primitive types, ObjectOutput
   36.34 - * extends that interface to include objects, arrays, and Strings.
   36.35 - *
   36.36 - * @author  unascribed
   36.37 - * @see java.io.InputStream
   36.38 - * @see java.io.ObjectOutputStream
   36.39 - * @see java.io.ObjectInputStream
   36.40 - * @since   JDK1.1
   36.41 - */
   36.42 -public interface ObjectOutput extends DataOutput, AutoCloseable {
   36.43 -    /**
   36.44 -     * Write an object to the underlying storage or stream.  The
   36.45 -     * class that implements this interface defines how the object is
   36.46 -     * written.
   36.47 -     *
   36.48 -     * @param obj the object to be written
   36.49 -     * @exception IOException Any of the usual Input/Output related exceptions.
   36.50 -     */
   36.51 -    public void writeObject(Object obj)
   36.52 -      throws IOException;
   36.53 -
   36.54 -    /**
   36.55 -     * Writes a byte. This method will block until the byte is actually
   36.56 -     * written.
   36.57 -     * @param b the byte
   36.58 -     * @exception IOException If an I/O error has occurred.
   36.59 -     */
   36.60 -    public void write(int b) throws IOException;
   36.61 -
   36.62 -    /**
   36.63 -     * Writes an array of bytes. This method will block until the bytes
   36.64 -     * are actually written.
   36.65 -     * @param b the data to be written
   36.66 -     * @exception IOException If an I/O error has occurred.
   36.67 -     */
   36.68 -    public void write(byte b[]) throws IOException;
   36.69 -
   36.70 -    /**
   36.71 -     * Writes a sub array of bytes.
   36.72 -     * @param b the data to be written
   36.73 -     * @param off       the start offset in the data
   36.74 -     * @param len       the number of bytes that are written
   36.75 -     * @exception IOException If an I/O error has occurred.
   36.76 -     */
   36.77 -    public void write(byte b[], int off, int len) throws IOException;
   36.78 -
   36.79 -    /**
   36.80 -     * Flushes the stream. This will write any buffered
   36.81 -     * output bytes.
   36.82 -     * @exception IOException If an I/O error has occurred.
   36.83 -     */
   36.84 -    public void flush() throws IOException;
   36.85 -
   36.86 -    /**
   36.87 -     * Closes the stream. This method must be called
   36.88 -     * to release any resources associated with the
   36.89 -     * stream.
   36.90 -     * @exception IOException If an I/O error has occurred.
   36.91 -     */
   36.92 -    public void close() throws IOException;
   36.93 -}
    37.1 --- a/emul/compact/src/main/java/java/io/ObjectOutputStream.java	Mon Feb 25 19:00:08 2013 +0100
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,2369 +0,0 @@
    37.4 -/*
    37.5 - * Copyright (c) 1996, 2010, 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.io;
   37.30 -
   37.31 -import java.util.ArrayList;
   37.32 -import java.util.Arrays;
   37.33 -import java.util.List;
   37.34 -import org.apidesign.bck2brwsr.emul.lang.System;
   37.35 -
   37.36 -/**
   37.37 - * An ObjectOutputStream writes primitive data types and graphs of Java objects
   37.38 - * to an OutputStream.  The objects can be read (reconstituted) using an
   37.39 - * ObjectInputStream.  Persistent storage of objects can be accomplished by
   37.40 - * using a file for the stream.  If the stream is a network socket stream, the
   37.41 - * objects can be reconstituted on another host or in another process.
   37.42 - *
   37.43 - * <p>Only objects that support the java.io.Serializable interface can be
   37.44 - * written to streams.  The class of each serializable object is encoded
   37.45 - * including the class name and signature of the class, the values of the
   37.46 - * object's fields and arrays, and the closure of any other objects referenced
   37.47 - * from the initial objects.
   37.48 - *
   37.49 - * <p>The method writeObject is used to write an object to the stream.  Any
   37.50 - * object, including Strings and arrays, is written with writeObject. Multiple
   37.51 - * objects or primitives can be written to the stream.  The objects must be
   37.52 - * read back from the corresponding ObjectInputstream with the same types and
   37.53 - * in the same order as they were written.
   37.54 - *
   37.55 - * <p>Primitive data types can also be written to the stream using the
   37.56 - * appropriate methods from DataOutput. Strings can also be written using the
   37.57 - * writeUTF method.
   37.58 - *
   37.59 - * <p>The default serialization mechanism for an object writes the class of the
   37.60 - * object, the class signature, and the values of all non-transient and
   37.61 - * non-static fields.  References to other objects (except in transient or
   37.62 - * static fields) cause those objects to be written also. Multiple references
   37.63 - * to a single object are encoded using a reference sharing mechanism so that
   37.64 - * graphs of objects can be restored to the same shape as when the original was
   37.65 - * written.
   37.66 - *
   37.67 - * <p>For example to write an object that can be read by the example in
   37.68 - * ObjectInputStream:
   37.69 - * <br>
   37.70 - * <pre>
   37.71 - *      FileOutputStream fos = new FileOutputStream("t.tmp");
   37.72 - *      ObjectOutputStream oos = new ObjectOutputStream(fos);
   37.73 - *
   37.74 - *      oos.writeInt(12345);
   37.75 - *      oos.writeObject("Today");
   37.76 - *      oos.writeObject(new Date());
   37.77 - *
   37.78 - *      oos.close();
   37.79 - * </pre>
   37.80 - *
   37.81 - * <p>Classes that require special handling during the serialization and
   37.82 - * deserialization process must implement special methods with these exact
   37.83 - * signatures:
   37.84 - * <br>
   37.85 - * <pre>
   37.86 - * private void readObject(java.io.ObjectInputStream stream)
   37.87 - *     throws IOException, ClassNotFoundException;
   37.88 - * private void writeObject(java.io.ObjectOutputStream stream)
   37.89 - *     throws IOException
   37.90 - * private void readObjectNoData()
   37.91 - *     throws ObjectStreamException;
   37.92 - * </pre>
   37.93 - *
   37.94 - * <p>The writeObject method is responsible for writing the state of the object
   37.95 - * for its particular class so that the corresponding readObject method can
   37.96 - * restore it.  The method does not need to concern itself with the state
   37.97 - * belonging to the object's superclasses or subclasses.  State is saved by
   37.98 - * writing the individual fields to the ObjectOutputStream using the
   37.99 - * writeObject method or by using the methods for primitive data types
  37.100 - * supported by DataOutput.
  37.101 - *
  37.102 - * <p>Serialization does not write out the fields of any object that does not
  37.103 - * implement the java.io.Serializable interface.  Subclasses of Objects that
  37.104 - * are not serializable can be serializable. In this case the non-serializable
  37.105 - * class must have a no-arg constructor to allow its fields to be initialized.
  37.106 - * In this case it is the responsibility of the subclass to save and restore
  37.107 - * the state of the non-serializable class. It is frequently the case that the
  37.108 - * fields of that class are accessible (public, package, or protected) or that
  37.109 - * there are get and set methods that can be used to restore the state.
  37.110 - *
  37.111 - * <p>Serialization of an object can be prevented by implementing writeObject
  37.112 - * and readObject methods that throw the NotSerializableException.  The
  37.113 - * exception will be caught by the ObjectOutputStream and abort the
  37.114 - * serialization process.
  37.115 - *
  37.116 - * <p>Implementing the Externalizable interface allows the object to assume
  37.117 - * complete control over the contents and format of the object's serialized
  37.118 - * form.  The methods of the Externalizable interface, writeExternal and
  37.119 - * readExternal, are called to save and restore the objects state.  When
  37.120 - * implemented by a class they can write and read their own state using all of
  37.121 - * the methods of ObjectOutput and ObjectInput.  It is the responsibility of
  37.122 - * the objects to handle any versioning that occurs.
  37.123 - *
  37.124 - * <p>Enum constants are serialized differently than ordinary serializable or
  37.125 - * externalizable objects.  The serialized form of an enum constant consists
  37.126 - * solely of its name; field values of the constant are not transmitted.  To
  37.127 - * serialize an enum constant, ObjectOutputStream writes the string returned by
  37.128 - * the constant's name method.  Like other serializable or externalizable
  37.129 - * objects, enum constants can function as the targets of back references
  37.130 - * appearing subsequently in the serialization stream.  The process by which
  37.131 - * enum constants are serialized cannot be customized; any class-specific
  37.132 - * writeObject and writeReplace methods defined by enum types are ignored
  37.133 - * during serialization.  Similarly, any serialPersistentFields or
  37.134 - * serialVersionUID field declarations are also ignored--all enum types have a
  37.135 - * fixed serialVersionUID of 0L.
  37.136 - *
  37.137 - * <p>Primitive data, excluding serializable fields and externalizable data, is
  37.138 - * written to the ObjectOutputStream in block-data records. A block data record
  37.139 - * is composed of a header and data. The block data header consists of a marker
  37.140 - * and the number of bytes to follow the header.  Consecutive primitive data
  37.141 - * writes are merged into one block-data record.  The blocking factor used for
  37.142 - * a block-data record will be 1024 bytes.  Each block-data record will be
  37.143 - * filled up to 1024 bytes, or be written whenever there is a termination of
  37.144 - * block-data mode.  Calls to the ObjectOutputStream methods writeObject,
  37.145 - * defaultWriteObject and writeFields initially terminate any existing
  37.146 - * block-data record.
  37.147 - *
  37.148 - * @author      Mike Warres
  37.149 - * @author      Roger Riggs
  37.150 - * @see java.io.DataOutput
  37.151 - * @see java.io.ObjectInputStream
  37.152 - * @see java.io.Serializable
  37.153 - * @see java.io.Externalizable
  37.154 - * @see <a href="../../../platform/serialization/spec/output.html">Object Serialization Specification, Section 2, Object Output Classes</a>
  37.155 - * @since       JDK1.1
  37.156 - */
  37.157 -public class ObjectOutputStream
  37.158 -    extends OutputStream implements ObjectOutput, ObjectStreamConstants
  37.159 -{
  37.160 -    /** filter stream for handling block data conversion */
  37.161 -    private final BlockDataOutputStream bout;
  37.162 -    /** obj -> wire handle map */
  37.163 -    private final HandleTable handles;
  37.164 -    /** obj -> replacement obj map */
  37.165 -    private final ReplaceTable subs;
  37.166 -    /** stream protocol version */
  37.167 -    private int protocol = PROTOCOL_VERSION_2;
  37.168 -    /** recursion depth */
  37.169 -    private int depth;
  37.170 -
  37.171 -    /** buffer for writing primitive field values */
  37.172 -    private byte[] primVals;
  37.173 -
  37.174 -    /** if true, invoke writeObjectOverride() instead of writeObject() */
  37.175 -    private final boolean enableOverride;
  37.176 -    /** if true, invoke replaceObject() */
  37.177 -    private boolean enableReplace;
  37.178 -
  37.179 -    // values below valid only during upcalls to writeObject()/writeExternal()
  37.180 -    /**
  37.181 -     * Context during upcalls to class-defined writeObject methods; holds
  37.182 -     * object currently being serialized and descriptor for current class.
  37.183 -     * Null when not during writeObject upcall.
  37.184 -     */
  37.185 -    private Object curContext;
  37.186 -    /** current PutField object */
  37.187 -    private PutFieldImpl curPut;
  37.188 -
  37.189 -    /** custom storage for debug trace info */
  37.190 -    private final DebugTraceInfoStack debugInfoStack;
  37.191 -
  37.192 -    /**
  37.193 -     * value of "sun.io.serialization.extendedDebugInfo" property,
  37.194 -     * as true or false for extended information about exception's place
  37.195 -     */
  37.196 -    private static final boolean extendedDebugInfo = false;
  37.197 -
  37.198 -    /**
  37.199 -     * Creates an ObjectOutputStream that writes to the specified OutputStream.
  37.200 -     * This constructor writes the serialization stream header to the
  37.201 -     * underlying stream; callers may wish to flush the stream immediately to
  37.202 -     * ensure that constructors for receiving ObjectInputStreams will not block
  37.203 -     * when reading the header.
  37.204 -     *
  37.205 -     * <p>If a security manager is installed, this constructor will check for
  37.206 -     * the "enableSubclassImplementation" SerializablePermission when invoked
  37.207 -     * directly or indirectly by the constructor of a subclass which overrides
  37.208 -     * the ObjectOutputStream.putFields or ObjectOutputStream.writeUnshared
  37.209 -     * methods.
  37.210 -     *
  37.211 -     * @param   out output stream to write to
  37.212 -     * @throws  IOException if an I/O error occurs while writing stream header
  37.213 -     * @throws  SecurityException if untrusted subclass illegally overrides
  37.214 -     *          security-sensitive methods
  37.215 -     * @throws  NullPointerException if <code>out</code> is <code>null</code>
  37.216 -     * @since   1.4
  37.217 -     * @see     ObjectOutputStream#ObjectOutputStream()
  37.218 -     * @see     ObjectOutputStream#putFields()
  37.219 -     * @see     ObjectInputStream#ObjectInputStream(InputStream)
  37.220 -     */
  37.221 -    public ObjectOutputStream(OutputStream out) throws IOException {
  37.222 -        verifySubclass();
  37.223 -        bout = new BlockDataOutputStream(out);
  37.224 -        handles = new HandleTable(10, (float) 3.00);
  37.225 -        subs = new ReplaceTable(10, (float) 3.00);
  37.226 -        enableOverride = false;
  37.227 -        writeStreamHeader();
  37.228 -        bout.setBlockDataMode(true);
  37.229 -        if (extendedDebugInfo) {
  37.230 -            debugInfoStack = new DebugTraceInfoStack();
  37.231 -        } else {
  37.232 -            debugInfoStack = null;
  37.233 -        }
  37.234 -    }
  37.235 -
  37.236 -    /**
  37.237 -     * Provide a way for subclasses that are completely reimplementing
  37.238 -     * ObjectOutputStream to not have to allocate private data just used by
  37.239 -     * this implementation of ObjectOutputStream.
  37.240 -     *
  37.241 -     * <p>If there is a security manager installed, this method first calls the
  37.242 -     * security manager's <code>checkPermission</code> method with a
  37.243 -     * <code>SerializablePermission("enableSubclassImplementation")</code>
  37.244 -     * permission to ensure it's ok to enable subclassing.
  37.245 -     *
  37.246 -     * @throws  SecurityException if a security manager exists and its
  37.247 -     *          <code>checkPermission</code> method denies enabling
  37.248 -     *          subclassing.
  37.249 -     * @see SecurityManager#checkPermission
  37.250 -     * @see java.io.SerializablePermission
  37.251 -     */
  37.252 -    protected ObjectOutputStream() throws IOException, SecurityException {
  37.253 -        throw new SecurityException();
  37.254 -    }
  37.255 -
  37.256 -    /**
  37.257 -     * Specify stream protocol version to use when writing the stream.
  37.258 -     *
  37.259 -     * <p>This routine provides a hook to enable the current version of
  37.260 -     * Serialization to write in a format that is backwards compatible to a
  37.261 -     * previous version of the stream format.
  37.262 -     *
  37.263 -     * <p>Every effort will be made to avoid introducing additional
  37.264 -     * backwards incompatibilities; however, sometimes there is no
  37.265 -     * other alternative.
  37.266 -     *
  37.267 -     * @param   version use ProtocolVersion from java.io.ObjectStreamConstants.
  37.268 -     * @throws  IllegalStateException if called after any objects
  37.269 -     *          have been serialized.
  37.270 -     * @throws  IllegalArgumentException if invalid version is passed in.
  37.271 -     * @throws  IOException if I/O errors occur
  37.272 -     * @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_1
  37.273 -     * @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_2
  37.274 -     * @since   1.2
  37.275 -     */
  37.276 -    public void useProtocolVersion(int version) throws IOException {
  37.277 -        if (handles.size() != 0) {
  37.278 -            // REMIND: implement better check for pristine stream?
  37.279 -            throw new IllegalStateException("stream non-empty");
  37.280 -        }
  37.281 -        switch (version) {
  37.282 -            case PROTOCOL_VERSION_1:
  37.283 -            case PROTOCOL_VERSION_2:
  37.284 -                protocol = version;
  37.285 -                break;
  37.286 -
  37.287 -            default:
  37.288 -                throw new IllegalArgumentException(
  37.289 -                    "unknown version: " + version);
  37.290 -        }
  37.291 -    }
  37.292 -
  37.293 -    /**
  37.294 -     * Write the specified object to the ObjectOutputStream.  The class of the
  37.295 -     * object, the signature of the class, and the values of the non-transient
  37.296 -     * and non-static fields of the class and all of its supertypes are
  37.297 -     * written.  Default serialization for a class can be overridden using the
  37.298 -     * writeObject and the readObject methods.  Objects referenced by this
  37.299 -     * object are written transitively so that a complete equivalent graph of
  37.300 -     * objects can be reconstructed by an ObjectInputStream.
  37.301 -     *
  37.302 -     * <p>Exceptions are thrown for problems with the OutputStream and for
  37.303 -     * classes that should not be serialized.  All exceptions are fatal to the
  37.304 -     * OutputStream, which is left in an indeterminate state, and it is up to
  37.305 -     * the caller to ignore or recover the stream state.
  37.306 -     *
  37.307 -     * @throws  InvalidClassException Something is wrong with a class used by
  37.308 -     *          serialization.
  37.309 -     * @throws  NotSerializableException Some object to be serialized does not
  37.310 -     *          implement the java.io.Serializable interface.
  37.311 -     * @throws  IOException Any exception thrown by the underlying
  37.312 -     *          OutputStream.
  37.313 -     */
  37.314 -    public final void writeObject(Object obj) throws IOException {
  37.315 -        if (enableOverride) {
  37.316 -            writeObjectOverride(obj);
  37.317 -            return;
  37.318 -        }
  37.319 -        try {
  37.320 -            writeObject0(obj, false);
  37.321 -        } catch (IOException ex) {
  37.322 -            if (depth == 0) {
  37.323 -                writeFatalException(ex);
  37.324 -            }
  37.325 -            throw ex;
  37.326 -        }
  37.327 -    }
  37.328 -
  37.329 -    /**
  37.330 -     * Method used by subclasses to override the default writeObject method.
  37.331 -     * This method is called by trusted subclasses of ObjectInputStream that
  37.332 -     * constructed ObjectInputStream using the protected no-arg constructor.
  37.333 -     * The subclass is expected to provide an override method with the modifier
  37.334 -     * "final".
  37.335 -     *
  37.336 -     * @param   obj object to be written to the underlying stream
  37.337 -     * @throws  IOException if there are I/O errors while writing to the
  37.338 -     *          underlying stream
  37.339 -     * @see #ObjectOutputStream()
  37.340 -     * @see #writeObject(Object)
  37.341 -     * @since 1.2
  37.342 -     */
  37.343 -    protected void writeObjectOverride(Object obj) throws IOException {
  37.344 -    }
  37.345 -
  37.346 -    /**
  37.347 -     * Writes an "unshared" object to the ObjectOutputStream.  This method is
  37.348 -     * identical to writeObject, except that it always writes the given object
  37.349 -     * as a new, unique object in the stream (as opposed to a back-reference
  37.350 -     * pointing to a previously serialized instance).  Specifically:
  37.351 -     * <ul>
  37.352 -     *   <li>An object written via writeUnshared is always serialized in the
  37.353 -     *       same manner as a newly appearing object (an object that has not
  37.354 -     *       been written to the stream yet), regardless of whether or not the
  37.355 -     *       object has been written previously.
  37.356 -     *
  37.357 -     *   <li>If writeObject is used to write an object that has been previously
  37.358 -     *       written with writeUnshared, the previous writeUnshared operation
  37.359 -     *       is treated as if it were a write of a separate object.  In other
  37.360 -     *       words, ObjectOutputStream will never generate back-references to
  37.361 -     *       object data written by calls to writeUnshared.
  37.362 -     * </ul>
  37.363 -     * While writing an object via writeUnshared does not in itself guarantee a
  37.364 -     * unique reference to the object when it is deserialized, it allows a
  37.365 -     * single object to be defined multiple times in a stream, so that multiple
  37.366 -     * calls to readUnshared by the receiver will not conflict.  Note that the
  37.367 -     * rules described above only apply to the base-level object written with
  37.368 -     * writeUnshared, and not to any transitively referenced sub-objects in the
  37.369 -     * object graph to be serialized.
  37.370 -     *
  37.371 -     * <p>ObjectOutputStream subclasses which override this method can only be
  37.372 -     * constructed in security contexts possessing the
  37.373 -     * "enableSubclassImplementation" SerializablePermission; any attempt to
  37.374 -     * instantiate such a subclass without this permission will cause a
  37.375 -     * SecurityException to be thrown.
  37.376 -     *
  37.377 -     * @param   obj object to write to stream
  37.378 -     * @throws  NotSerializableException if an object in the graph to be
  37.379 -     *          serialized does not implement the Serializable interface
  37.380 -     * @throws  InvalidClassException if a problem exists with the class of an
  37.381 -     *          object to be serialized
  37.382 -     * @throws  IOException if an I/O error occurs during serialization
  37.383 -     * @since 1.4
  37.384 -     */
  37.385 -    public void writeUnshared(Object obj) throws IOException {
  37.386 -        try {
  37.387 -            writeObject0(obj, true);
  37.388 -        } catch (IOException ex) {
  37.389 -            if (depth == 0) {
  37.390 -                writeFatalException(ex);
  37.391 -            }
  37.392 -            throw ex;
  37.393 -        }
  37.394 -    }
  37.395 -
  37.396 -    /**
  37.397 -     * Write the non-static and non-transient fields of the current class to
  37.398 -     * this stream.  This may only be called from the writeObject method of the
  37.399 -     * class being serialized. It will throw the NotActiveException if it is
  37.400 -     * called otherwise.
  37.401 -     *
  37.402 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.403 -     *          <code>OutputStream</code>
  37.404 -     */
  37.405 -    public void defaultWriteObject() throws IOException {
  37.406 -        if ( curContext == null ) {
  37.407 -            throw new NotActiveException("not in call to writeObject");
  37.408 -        }
  37.409 -        Object curObj = null; // curContext.getObj();
  37.410 -        ObjectStreamClass curDesc = null; // curContext.getDesc();
  37.411 -        bout.setBlockDataMode(false);
  37.412 -        defaultWriteFields(curObj, curDesc);
  37.413 -        bout.setBlockDataMode(true);
  37.414 -    }
  37.415 -
  37.416 -    /**
  37.417 -     * Retrieve the object used to buffer persistent fields to be written to
  37.418 -     * the stream.  The fields will be written to the stream when writeFields
  37.419 -     * method is called.
  37.420 -     *
  37.421 -     * @return  an instance of the class Putfield that holds the serializable
  37.422 -     *          fields
  37.423 -     * @throws  IOException if I/O errors occur
  37.424 -     * @since 1.2
  37.425 -     */
  37.426 -    public ObjectOutputStream.PutField putFields() throws IOException {
  37.427 -        if (curPut == null) {
  37.428 -            if (curContext == null) {
  37.429 -                throw new NotActiveException("not in call to writeObject");
  37.430 -            }
  37.431 -            Object curObj = null; // curContext.getObj();
  37.432 -            ObjectStreamClass curDesc = null; // curContext.getDesc();
  37.433 -            curPut = new PutFieldImpl(curDesc);
  37.434 -        }
  37.435 -        return curPut;
  37.436 -    }
  37.437 -
  37.438 -    /**
  37.439 -     * Write the buffered fields to the stream.
  37.440 -     *
  37.441 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.442 -     *          stream
  37.443 -     * @throws  NotActiveException Called when a classes writeObject method was
  37.444 -     *          not called to write the state of the object.
  37.445 -     * @since 1.2
  37.446 -     */
  37.447 -    public void writeFields() throws IOException {
  37.448 -        if (curPut == null) {
  37.449 -            throw new NotActiveException("no current PutField object");
  37.450 -        }
  37.451 -        bout.setBlockDataMode(false);
  37.452 -        curPut.writeFields();
  37.453 -        bout.setBlockDataMode(true);
  37.454 -    }
  37.455 -
  37.456 -    /**
  37.457 -     * Reset will disregard the state of any objects already written to the
  37.458 -     * stream.  The state is reset to be the same as a new ObjectOutputStream.
  37.459 -     * The current point in the stream is marked as reset so the corresponding
  37.460 -     * ObjectInputStream will be reset at the same point.  Objects previously
  37.461 -     * written to the stream will not be refered to as already being in the
  37.462 -     * stream.  They will be written to the stream again.
  37.463 -     *
  37.464 -     * @throws  IOException if reset() is invoked while serializing an object.
  37.465 -     */
  37.466 -    public void reset() throws IOException {
  37.467 -        if (depth != 0) {
  37.468 -            throw new IOException("stream active");
  37.469 -        }
  37.470 -        bout.setBlockDataMode(false);
  37.471 -        bout.writeByte(TC_RESET);
  37.472 -        clear();
  37.473 -        bout.setBlockDataMode(true);
  37.474 -    }
  37.475 -
  37.476 -    /**
  37.477 -     * Subclasses may implement this method to allow class data to be stored in
  37.478 -     * the stream. By default this method does nothing.  The corresponding
  37.479 -     * method in ObjectInputStream is resolveClass.  This method is called
  37.480 -     * exactly once for each unique class in the stream.  The class name and
  37.481 -     * signature will have already been written to the stream.  This method may
  37.482 -     * make free use of the ObjectOutputStream to save any representation of
  37.483 -     * the class it deems suitable (for example, the bytes of the class file).
  37.484 -     * The resolveClass method in the corresponding subclass of
  37.485 -     * ObjectInputStream must read and use any data or objects written by
  37.486 -     * annotateClass.
  37.487 -     *
  37.488 -     * @param   cl the class to annotate custom data for
  37.489 -     * @throws  IOException Any exception thrown by the underlying
  37.490 -     *          OutputStream.
  37.491 -     */
  37.492 -    protected void annotateClass(Class<?> cl) throws IOException {
  37.493 -    }
  37.494 -
  37.495 -    /**
  37.496 -     * Subclasses may implement this method to store custom data in the stream
  37.497 -     * along with descriptors for dynamic proxy classes.
  37.498 -     *
  37.499 -     * <p>This method is called exactly once for each unique proxy class
  37.500 -     * descriptor in the stream.  The default implementation of this method in
  37.501 -     * <code>ObjectOutputStream</code> does nothing.
  37.502 -     *
  37.503 -     * <p>The corresponding method in <code>ObjectInputStream</code> is
  37.504 -     * <code>resolveProxyClass</code>.  For a given subclass of
  37.505 -     * <code>ObjectOutputStream</code> that overrides this method, the
  37.506 -     * <code>resolveProxyClass</code> method in the corresponding subclass of
  37.507 -     * <code>ObjectInputStream</code> must read any data or objects written by
  37.508 -     * <code>annotateProxyClass</code>.
  37.509 -     *
  37.510 -     * @param   cl the proxy class to annotate custom data for
  37.511 -     * @throws  IOException any exception thrown by the underlying
  37.512 -     *          <code>OutputStream</code>
  37.513 -     * @see ObjectInputStream#resolveProxyClass(String[])
  37.514 -     * @since   1.3
  37.515 -     */
  37.516 -    protected void annotateProxyClass(Class<?> cl) throws IOException {
  37.517 -    }
  37.518 -
  37.519 -    /**
  37.520 -     * This method will allow trusted subclasses of ObjectOutputStream to
  37.521 -     * substitute one object for another during serialization. Replacing
  37.522 -     * objects is disabled until enableReplaceObject is called. The
  37.523 -     * enableReplaceObject method checks that the stream requesting to do
  37.524 -     * replacement can be trusted.  The first occurrence of each object written
  37.525 -     * into the serialization stream is passed to replaceObject.  Subsequent
  37.526 -     * references to the object are replaced by the object returned by the
  37.527 -     * original call to replaceObject.  To ensure that the private state of
  37.528 -     * objects is not unintentionally exposed, only trusted streams may use
  37.529 -     * replaceObject.
  37.530 -     *
  37.531 -     * <p>The ObjectOutputStream.writeObject method takes a parameter of type
  37.532 -     * Object (as opposed to type Serializable) to allow for cases where
  37.533 -     * non-serializable objects are replaced by serializable ones.
  37.534 -     *
  37.535 -     * <p>When a subclass is replacing objects it must insure that either a
  37.536 -     * complementary substitution must be made during deserialization or that
  37.537 -     * the substituted object is compatible with every field where the
  37.538 -     * reference will be stored.  Objects whose type is not a subclass of the
  37.539 -     * type of the field or array element abort the serialization by raising an
  37.540 -     * exception and the object is not be stored.
  37.541 -     *
  37.542 -     * <p>This method is called only once when each object is first
  37.543 -     * encountered.  All subsequent references to the object will be redirected
  37.544 -     * to the new object. This method should return the object to be
  37.545 -     * substituted or the original object.
  37.546 -     *
  37.547 -     * <p>Null can be returned as the object to be substituted, but may cause
  37.548 -     * NullReferenceException in classes that contain references to the
  37.549 -     * original object since they may be expecting an object instead of
  37.550 -     * null.
  37.551 -     *
  37.552 -     * @param   obj the object to be replaced
  37.553 -     * @return  the alternate object that replaced the specified one
  37.554 -     * @throws  IOException Any exception thrown by the underlying
  37.555 -     *          OutputStream.
  37.556 -     */
  37.557 -    protected Object replaceObject(Object obj) throws IOException {
  37.558 -        return obj;
  37.559 -    }
  37.560 -
  37.561 -    /**
  37.562 -     * Enable the stream to do replacement of objects in the stream.  When
  37.563 -     * enabled, the replaceObject method is called for every object being
  37.564 -     * serialized.
  37.565 -     *
  37.566 -     * <p>If <code>enable</code> is true, and there is a security manager
  37.567 -     * installed, this method first calls the security manager's
  37.568 -     * <code>checkPermission</code> method with a
  37.569 -     * <code>SerializablePermission("enableSubstitution")</code> permission to
  37.570 -     * ensure it's ok to enable the stream to do replacement of objects in the
  37.571 -     * stream.
  37.572 -     *
  37.573 -     * @param   enable boolean parameter to enable replacement of objects
  37.574 -     * @return  the previous setting before this method was invoked
  37.575 -     * @throws  SecurityException if a security manager exists and its
  37.576 -     *          <code>checkPermission</code> method denies enabling the stream
  37.577 -     *          to do replacement of objects in the stream.
  37.578 -     * @see SecurityManager#checkPermission
  37.579 -     * @see java.io.SerializablePermission
  37.580 -     */
  37.581 -    protected boolean enableReplaceObject(boolean enable)
  37.582 -        throws SecurityException
  37.583 -    {
  37.584 -        throw new SecurityException();
  37.585 -    }
  37.586 -
  37.587 -    /**
  37.588 -     * The writeStreamHeader method is provided so subclasses can append or
  37.589 -     * prepend their own header to the stream.  It writes the magic number and
  37.590 -     * version to the stream.
  37.591 -     *
  37.592 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.593 -     *          stream
  37.594 -     */
  37.595 -    protected void writeStreamHeader() throws IOException {
  37.596 -        bout.writeShort(STREAM_MAGIC);
  37.597 -        bout.writeShort(STREAM_VERSION);
  37.598 -    }
  37.599 -
  37.600 -    /**
  37.601 -     * Write the specified class descriptor to the ObjectOutputStream.  Class
  37.602 -     * descriptors are used to identify the classes of objects written to the
  37.603 -     * stream.  Subclasses of ObjectOutputStream may override this method to
  37.604 -     * customize the way in which class descriptors are written to the
  37.605 -     * serialization stream.  The corresponding method in ObjectInputStream,
  37.606 -     * <code>readClassDescriptor</code>, should then be overridden to
  37.607 -     * reconstitute the class descriptor from its custom stream representation.
  37.608 -     * By default, this method writes class descriptors according to the format
  37.609 -     * defined in the Object Serialization specification.
  37.610 -     *
  37.611 -     * <p>Note that this method will only be called if the ObjectOutputStream
  37.612 -     * is not using the old serialization stream format (set by calling
  37.613 -     * ObjectOutputStream's <code>useProtocolVersion</code> method).  If this
  37.614 -     * serialization stream is using the old format
  37.615 -     * (<code>PROTOCOL_VERSION_1</code>), the class descriptor will be written
  37.616 -     * internally in a manner that cannot be overridden or customized.
  37.617 -     *
  37.618 -     * @param   desc class descriptor to write to the stream
  37.619 -     * @throws  IOException If an I/O error has occurred.
  37.620 -     * @see java.io.ObjectInputStream#readClassDescriptor()
  37.621 -     * @see #useProtocolVersion(int)
  37.622 -     * @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_1
  37.623 -     * @since 1.3
  37.624 -     */
  37.625 -    protected void writeClassDescriptor(ObjectStreamClass desc)
  37.626 -        throws IOException
  37.627 -    {
  37.628 -        desc.writeNonProxy(this);
  37.629 -    }
  37.630 -
  37.631 -    /**
  37.632 -     * Writes a byte. This method will block until the byte is actually
  37.633 -     * written.
  37.634 -     *
  37.635 -     * @param   val the byte to be written to the stream
  37.636 -     * @throws  IOException If an I/O error has occurred.
  37.637 -     */
  37.638 -    public void write(int val) throws IOException {
  37.639 -        bout.write(val);
  37.640 -    }
  37.641 -
  37.642 -    /**
  37.643 -     * Writes an array of bytes. This method will block until the bytes are
  37.644 -     * actually written.
  37.645 -     *
  37.646 -     * @param   buf the data to be written
  37.647 -     * @throws  IOException If an I/O error has occurred.
  37.648 -     */
  37.649 -    public void write(byte[] buf) throws IOException {
  37.650 -        bout.write(buf, 0, buf.length, false);
  37.651 -    }
  37.652 -
  37.653 -    /**
  37.654 -     * Writes a sub array of bytes.
  37.655 -     *
  37.656 -     * @param   buf the data to be written
  37.657 -     * @param   off the start offset in the data
  37.658 -     * @param   len the number of bytes that are written
  37.659 -     * @throws  IOException If an I/O error has occurred.
  37.660 -     */
  37.661 -    public void write(byte[] buf, int off, int len) throws IOException {
  37.662 -        if (buf == null) {
  37.663 -            throw new NullPointerException();
  37.664 -        }
  37.665 -        int endoff = off + len;
  37.666 -        if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
  37.667 -            throw new IndexOutOfBoundsException();
  37.668 -        }
  37.669 -        bout.write(buf, off, len, false);
  37.670 -    }
  37.671 -
  37.672 -    /**
  37.673 -     * Flushes the stream. This will write any buffered output bytes and flush
  37.674 -     * through to the underlying stream.
  37.675 -     *
  37.676 -     * @throws  IOException If an I/O error has occurred.
  37.677 -     */
  37.678 -    public void flush() throws IOException {
  37.679 -        bout.flush();
  37.680 -    }
  37.681 -
  37.682 -    /**
  37.683 -     * Drain any buffered data in ObjectOutputStream.  Similar to flush but
  37.684 -     * does not propagate the flush to the underlying stream.
  37.685 -     *
  37.686 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.687 -     *          stream
  37.688 -     */
  37.689 -    protected void drain() throws IOException {
  37.690 -        bout.drain();
  37.691 -    }
  37.692 -
  37.693 -    /**
  37.694 -     * Closes the stream. This method must be called to release any resources
  37.695 -     * associated with the stream.
  37.696 -     *
  37.697 -     * @throws  IOException If an I/O error has occurred.
  37.698 -     */
  37.699 -    public void close() throws IOException {
  37.700 -        flush();
  37.701 -        clear();
  37.702 -        bout.close();
  37.703 -    }
  37.704 -
  37.705 -    /**
  37.706 -     * Writes a boolean.
  37.707 -     *
  37.708 -     * @param   val the boolean to be written
  37.709 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.710 -     *          stream
  37.711 -     */
  37.712 -    public void writeBoolean(boolean val) throws IOException {
  37.713 -        bout.writeBoolean(val);
  37.714 -    }
  37.715 -
  37.716 -    /**
  37.717 -     * Writes an 8 bit byte.
  37.718 -     *
  37.719 -     * @param   val the byte value to be written
  37.720 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.721 -     *          stream
  37.722 -     */
  37.723 -    public void writeByte(int val) throws IOException  {
  37.724 -        bout.writeByte(val);
  37.725 -    }
  37.726 -
  37.727 -    /**
  37.728 -     * Writes a 16 bit short.
  37.729 -     *
  37.730 -     * @param   val the short value to be written
  37.731 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.732 -     *          stream
  37.733 -     */
  37.734 -    public void writeShort(int val)  throws IOException {
  37.735 -        bout.writeShort(val);
  37.736 -    }
  37.737 -
  37.738 -    /**
  37.739 -     * Writes a 16 bit char.
  37.740 -     *
  37.741 -     * @param   val the char value to be written
  37.742 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.743 -     *          stream
  37.744 -     */
  37.745 -    public void writeChar(int val)  throws IOException {
  37.746 -        bout.writeChar(val);
  37.747 -    }
  37.748 -
  37.749 -    /**
  37.750 -     * Writes a 32 bit int.
  37.751 -     *
  37.752 -     * @param   val the integer value to be written
  37.753 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.754 -     *          stream
  37.755 -     */
  37.756 -    public void writeInt(int val)  throws IOException {
  37.757 -        bout.writeInt(val);
  37.758 -    }
  37.759 -
  37.760 -    /**
  37.761 -     * Writes a 64 bit long.
  37.762 -     *
  37.763 -     * @param   val the long value to be written
  37.764 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.765 -     *          stream
  37.766 -     */
  37.767 -    public void writeLong(long val)  throws IOException {
  37.768 -        bout.writeLong(val);
  37.769 -    }
  37.770 -
  37.771 -    /**
  37.772 -     * Writes a 32 bit float.
  37.773 -     *
  37.774 -     * @param   val the float value to be written
  37.775 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.776 -     *          stream
  37.777 -     */
  37.778 -    public void writeFloat(float val) throws IOException {
  37.779 -        bout.writeFloat(val);
  37.780 -    }
  37.781 -
  37.782 -    /**
  37.783 -     * Writes a 64 bit double.
  37.784 -     *
  37.785 -     * @param   val the double value to be written
  37.786 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.787 -     *          stream
  37.788 -     */
  37.789 -    public void writeDouble(double val) throws IOException {
  37.790 -        bout.writeDouble(val);
  37.791 -    }
  37.792 -
  37.793 -    /**
  37.794 -     * Writes a String as a sequence of bytes.
  37.795 -     *
  37.796 -     * @param   str the String of bytes to be written
  37.797 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.798 -     *          stream
  37.799 -     */
  37.800 -    public void writeBytes(String str) throws IOException {
  37.801 -        bout.writeBytes(str);
  37.802 -    }
  37.803 -
  37.804 -    /**
  37.805 -     * Writes a String as a sequence of chars.
  37.806 -     *
  37.807 -     * @param   str the String of chars to be written
  37.808 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.809 -     *          stream
  37.810 -     */
  37.811 -    public void writeChars(String str) throws IOException {
  37.812 -        bout.writeChars(str);
  37.813 -    }
  37.814 -
  37.815 -    /**
  37.816 -     * Primitive data write of this String in
  37.817 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  37.818 -     * format.  Note that there is a
  37.819 -     * significant difference between writing a String into the stream as
  37.820 -     * primitive data or as an Object. A String instance written by writeObject
  37.821 -     * is written into the stream as a String initially. Future writeObject()
  37.822 -     * calls write references to the string into the stream.
  37.823 -     *
  37.824 -     * @param   str the String to be written
  37.825 -     * @throws  IOException if I/O errors occur while writing to the underlying
  37.826 -     *          stream
  37.827 -     */
  37.828 -    public void writeUTF(String str) throws IOException {
  37.829 -        bout.writeUTF(str);
  37.830 -    }
  37.831 -
  37.832 -    /**
  37.833 -     * Provide programmatic access to the persistent fields to be written
  37.834 -     * to ObjectOutput.
  37.835 -     *
  37.836 -     * @since 1.2
  37.837 -     */
  37.838 -    public static abstract class PutField {
  37.839 -
  37.840 -        /**
  37.841 -         * Put the value of the named boolean field into the persistent field.
  37.842 -         *
  37.843 -         * @param  name the name of the serializable field
  37.844 -         * @param  val the value to assign to the field
  37.845 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.846 -         * match the name of a serializable field for the class whose fields
  37.847 -         * are being written, or if the type of the named field is not
  37.848 -         * <code>boolean</code>
  37.849 -         */
  37.850 -        public abstract void put(String name, boolean val);
  37.851 -
  37.852 -        /**
  37.853 -         * Put the value of the named byte field into the persistent field.
  37.854 -         *
  37.855 -         * @param  name the name of the serializable field
  37.856 -         * @param  val the value to assign to the field
  37.857 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.858 -         * match the name of a serializable field for the class whose fields
  37.859 -         * are being written, or if the type of the named field is not
  37.860 -         * <code>byte</code>
  37.861 -         */
  37.862 -        public abstract void put(String name, byte val);
  37.863 -
  37.864 -        /**
  37.865 -         * Put the value of the named char field into the persistent field.
  37.866 -         *
  37.867 -         * @param  name the name of the serializable field
  37.868 -         * @param  val the value to assign to the field
  37.869 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.870 -         * match the name of a serializable field for the class whose fields
  37.871 -         * are being written, or if the type of the named field is not
  37.872 -         * <code>char</code>
  37.873 -         */
  37.874 -        public abstract void put(String name, char val);
  37.875 -
  37.876 -        /**
  37.877 -         * Put the value of the named short field into the persistent field.
  37.878 -         *
  37.879 -         * @param  name the name of the serializable field
  37.880 -         * @param  val the value to assign to the field
  37.881 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.882 -         * match the name of a serializable field for the class whose fields
  37.883 -         * are being written, or if the type of the named field is not
  37.884 -         * <code>short</code>
  37.885 -         */
  37.886 -        public abstract void put(String name, short val);
  37.887 -
  37.888 -        /**
  37.889 -         * Put the value of the named int field into the persistent field.
  37.890 -         *
  37.891 -         * @param  name the name of the serializable field
  37.892 -         * @param  val the value to assign to the field
  37.893 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.894 -         * match the name of a serializable field for the class whose fields
  37.895 -         * are being written, or if the type of the named field is not
  37.896 -         * <code>int</code>
  37.897 -         */
  37.898 -        public abstract void put(String name, int val);
  37.899 -
  37.900 -        /**
  37.901 -         * Put the value of the named long field into the persistent field.
  37.902 -         *
  37.903 -         * @param  name the name of the serializable field
  37.904 -         * @param  val the value to assign to the field
  37.905 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.906 -         * match the name of a serializable field for the class whose fields
  37.907 -         * are being written, or if the type of the named field is not
  37.908 -         * <code>long</code>
  37.909 -         */
  37.910 -        public abstract void put(String name, long val);
  37.911 -
  37.912 -        /**
  37.913 -         * Put the value of the named float field into the persistent field.
  37.914 -         *
  37.915 -         * @param  name the name of the serializable field
  37.916 -         * @param  val the value to assign to the field
  37.917 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.918 -         * match the name of a serializable field for the class whose fields
  37.919 -         * are being written, or if the type of the named field is not
  37.920 -         * <code>float</code>
  37.921 -         */
  37.922 -        public abstract void put(String name, float val);
  37.923 -
  37.924 -        /**
  37.925 -         * Put the value of the named double field into the persistent field.
  37.926 -         *
  37.927 -         * @param  name the name of the serializable field
  37.928 -         * @param  val the value to assign to the field
  37.929 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.930 -         * match the name of a serializable field for the class whose fields
  37.931 -         * are being written, or if the type of the named field is not
  37.932 -         * <code>double</code>
  37.933 -         */
  37.934 -        public abstract void put(String name, double val);
  37.935 -
  37.936 -        /**
  37.937 -         * Put the value of the named Object field into the persistent field.
  37.938 -         *
  37.939 -         * @param  name the name of the serializable field
  37.940 -         * @param  val the value to assign to the field
  37.941 -         *         (which may be <code>null</code>)
  37.942 -         * @throws IllegalArgumentException if <code>name</code> does not
  37.943 -         * match the name of a serializable field for the class whose fields
  37.944 -         * are being written, or if the type of the named field is not a
  37.945 -         * reference type
  37.946 -         */
  37.947 -        public abstract void put(String name, Object val);
  37.948 -
  37.949 -        /**
  37.950 -         * Write the data and fields to the specified ObjectOutput stream,
  37.951 -         * which must be the same stream that produced this
  37.952 -         * <code>PutField</code> object.
  37.953 -         *
  37.954 -         * @param  out the stream to write the data and fields to
  37.955 -         * @throws IOException if I/O errors occur while writing to the
  37.956 -         *         underlying stream
  37.957 -         * @throws IllegalArgumentException if the specified stream is not
  37.958 -         *         the same stream that produced this <code>PutField</code>
  37.959 -         *         object
  37.960 -         * @deprecated This method does not write the values contained by this
  37.961 -         *         <code>PutField</code> object in a proper format, and may
  37.962 -         *         result in corruption of the serialization stream.  The
  37.963 -         *         correct way to write <code>PutField</code> data is by
  37.964 -         *         calling the {@link java.io.ObjectOutputStream#writeFields()}
  37.965 -         *         method.
  37.966 -         */
  37.967 -        @Deprecated
  37.968 -        public abstract void write(ObjectOutput out) throws IOException;
  37.969 -    }
  37.970 -
  37.971 -
  37.972 -    /**
  37.973 -     * Returns protocol version in use.
  37.974 -     */
  37.975 -    int getProtocolVersion() {
  37.976 -        return protocol;
  37.977 -    }
  37.978 -
  37.979 -    /**
  37.980 -     * Writes string without allowing it to be replaced in stream.  Used by
  37.981 -     * ObjectStreamClass to write class descriptor type strings.
  37.982 -     */
  37.983 -    void writeTypeString(String str) throws IOException {
  37.984 -        int handle;
  37.985 -        if (str == null) {
  37.986 -            writeNull();
  37.987 -        } else if ((handle = handles.lookup(str)) != -1) {
  37.988 -            writeHandle(handle);
  37.989 -        } else {
  37.990 -            writeString(str, false);
  37.991 -        }
  37.992 -    }
  37.993 -
  37.994 -    /**
  37.995 -     * Verifies that this (possibly subclass) instance can be constructed
  37.996 -     * without violating security constraints: the subclass must not override
  37.997 -     * security-sensitive non-final methods, or else the
  37.998 -     * "enableSubclassImplementation" SerializablePermission is checked.
  37.999 -     */
 37.1000 -    private void verifySubclass() {
 37.1001 -        Class cl = getClass();
 37.1002 -        if (cl == ObjectOutputStream.class) {
 37.1003 -            return;
 37.1004 -        }
 37.1005 -        throw new SecurityException();
 37.1006 -    }
 37.1007 -
 37.1008 -    /**
 37.1009 -     * Clears internal data structures.
 37.1010 -     */
 37.1011 -    private void clear() {
 37.1012 -        subs.clear();
 37.1013 -        handles.clear();
 37.1014 -    }
 37.1015 -
 37.1016 -    /**
 37.1017 -     * Underlying writeObject/writeUnshared implementation.
 37.1018 -     */
 37.1019 -    private void writeObject0(Object obj, boolean unshared)
 37.1020 -        throws IOException
 37.1021 -    {
 37.1022 -        boolean oldMode = bout.setBlockDataMode(false);
 37.1023 -        depth++;
 37.1024 -        try {
 37.1025 -            // handle previously written and non-replaceable objects
 37.1026 -            int h;
 37.1027 -            if ((obj = subs.lookup(obj)) == null) {
 37.1028 -                writeNull();
 37.1029 -                return;
 37.1030 -            } else if (!unshared && (h = handles.lookup(obj)) != -1) {
 37.1031 -                writeHandle(h);
 37.1032 -                return;
 37.1033 -            } else if (obj instanceof Class) {
 37.1034 -                writeClass((Class) obj, unshared);
 37.1035 -                return;
 37.1036 -            } else if (obj instanceof ObjectStreamClass) {
 37.1037 -                writeClassDesc((ObjectStreamClass) obj, unshared);
 37.1038 -                return;
 37.1039 -            }
 37.1040 -
 37.1041 -            // check for replacement object
 37.1042 -            Object orig = obj;
 37.1043 -            Class cl = obj.getClass();
 37.1044 -            ObjectStreamClass desc;
 37.1045 -            for (;;) {
 37.1046 -                // REMIND: skip this check for strings/arrays?
 37.1047 -                Class repCl;
 37.1048 -                desc = ObjectStreamClass.lookup(cl, true);
 37.1049 -                if (!desc.hasWriteReplaceMethod() ||
 37.1050 -                    (obj = desc.invokeWriteReplace(obj)) == null ||
 37.1051 -                    (repCl = obj.getClass()) == cl)
 37.1052 -                {
 37.1053 -                    break;
 37.1054 -                }
 37.1055 -                cl = repCl;
 37.1056 -            }
 37.1057 -            if (enableReplace) {
 37.1058 -                Object rep = replaceObject(obj);
 37.1059 -                if (rep != obj && rep != null) {
 37.1060 -                    cl = rep.getClass();
 37.1061 -                    desc = ObjectStreamClass.lookup(cl, true);
 37.1062 -                }
 37.1063 -                obj = rep;
 37.1064 -            }
 37.1065 -
 37.1066 -            // if object replaced, run through original checks a second time
 37.1067 -            if (obj != orig) {
 37.1068 -                subs.assign(orig, obj);
 37.1069 -                if (obj == null) {
 37.1070 -                    writeNull();
 37.1071 -                    return;
 37.1072 -                } else if (!unshared && (h = handles.lookup(obj)) != -1) {
 37.1073 -                    writeHandle(h);
 37.1074 -                    return;
 37.1075 -                } else if (obj instanceof Class) {
 37.1076 -                    writeClass((Class) obj, unshared);
 37.1077 -                    return;
 37.1078 -                } else if (obj instanceof ObjectStreamClass) {
 37.1079 -                    writeClassDesc((ObjectStreamClass) obj, unshared);
 37.1080 -                    return;
 37.1081 -                }
 37.1082 -            }
 37.1083 -
 37.1084 -            // remaining cases
 37.1085 -            if (obj instanceof String) {
 37.1086 -                writeString((String) obj, unshared);
 37.1087 -            } else if (cl.isArray()) {
 37.1088 -                writeArray(obj, desc, unshared);
 37.1089 -            } else if (obj instanceof Enum) {
 37.1090 -                writeEnum((Enum) obj, desc, unshared);
 37.1091 -            } else if (obj instanceof Serializable) {
 37.1092 -                writeOrdinaryObject(obj, desc, unshared);
 37.1093 -            } else {
 37.1094 -                if (extendedDebugInfo) {
 37.1095 -                    throw new NotSerializableException(
 37.1096 -                        cl.getName() + "\n" + debugInfoStack.toString());
 37.1097 -                } else {
 37.1098 -                    throw new NotSerializableException(cl.getName());
 37.1099 -                }
 37.1100 -            }
 37.1101 -        } finally {
 37.1102 -            depth--;
 37.1103 -            bout.setBlockDataMode(oldMode);
 37.1104 -        }
 37.1105 -    }
 37.1106 -
 37.1107 -    /**
 37.1108 -     * Writes null code to stream.
 37.1109 -     */
 37.1110 -    private void writeNull() throws IOException {
 37.1111 -        bout.writeByte(TC_NULL);
 37.1112 -    }
 37.1113 -
 37.1114 -    /**
 37.1115 -     * Writes given object handle to stream.
 37.1116 -     */
 37.1117 -    private void writeHandle(int handle) throws IOException {
 37.1118 -        bout.writeByte(TC_REFERENCE);
 37.1119 -        bout.writeInt(baseWireHandle + handle);
 37.1120 -    }
 37.1121 -
 37.1122 -    /**
 37.1123 -     * Writes representation of given class to stream.
 37.1124 -     */
 37.1125 -    private void writeClass(Class cl, boolean unshared) throws IOException {
 37.1126 -        bout.writeByte(TC_CLASS);
 37.1127 -        writeClassDesc(ObjectStreamClass.lookup(cl, true), false);
 37.1128 -        handles.assign(unshared ? null : cl);
 37.1129 -    }
 37.1130 -
 37.1131 -    /**
 37.1132 -     * Writes representation of given class descriptor to stream.
 37.1133 -     */
 37.1134 -    private void writeClassDesc(ObjectStreamClass desc, boolean unshared)
 37.1135 -        throws IOException
 37.1136 -    {
 37.1137 -        int handle;
 37.1138 -        if (desc == null) {
 37.1139 -            writeNull();
 37.1140 -        } else if (!unshared && (handle = handles.lookup(desc)) != -1) {
 37.1141 -            writeHandle(handle);
 37.1142 -        } else if (desc.isProxy()) {
 37.1143 -            writeProxyDesc(desc, unshared);
 37.1144 -        } else {
 37.1145 -            writeNonProxyDesc(desc, unshared);
 37.1146 -        }
 37.1147 -    }
 37.1148 -
 37.1149 -    /**
 37.1150 -     * Writes class descriptor representing a dynamic proxy class to stream.
 37.1151 -     */
 37.1152 -    private void writeProxyDesc(ObjectStreamClass desc, boolean unshared)
 37.1153 -        throws IOException
 37.1154 -    {
 37.1155 -        bout.writeByte(TC_PROXYCLASSDESC);
 37.1156 -        handles.assign(unshared ? null : desc);
 37.1157 -
 37.1158 -        Class cl = desc.forClass();
 37.1159 -        Class[] ifaces = cl.getInterfaces();
 37.1160 -        bout.writeInt(ifaces.length);
 37.1161 -        for (int i = 0; i < ifaces.length; i++) {
 37.1162 -            bout.writeUTF(ifaces[i].getName());
 37.1163 -        }
 37.1164 -
 37.1165 -        bout.setBlockDataMode(true);
 37.1166 -        annotateProxyClass(cl);
 37.1167 -        bout.setBlockDataMode(false);
 37.1168 -        bout.writeByte(TC_ENDBLOCKDATA);
 37.1169 -
 37.1170 -        writeClassDesc(desc.getSuperDesc(), false);
 37.1171 -    }
 37.1172 -
 37.1173 -    /**
 37.1174 -     * Writes class descriptor representing a standard (i.e., not a dynamic
 37.1175 -     * proxy) class to stream.
 37.1176 -     */
 37.1177 -    private void writeNonProxyDesc(ObjectStreamClass desc, boolean unshared)
 37.1178 -        throws IOException
 37.1179 -    {
 37.1180 -        bout.writeByte(TC_CLASSDESC);
 37.1181 -        handles.assign(unshared ? null : desc);
 37.1182 -
 37.1183 -        if (protocol == PROTOCOL_VERSION_1) {
 37.1184 -            // do not invoke class descriptor write hook with old protocol
 37.1185 -            desc.writeNonProxy(this);
 37.1186 -        } else {
 37.1187 -            writeClassDescriptor(desc);
 37.1188 -        }
 37.1189 -
 37.1190 -        Class cl = desc.forClass();
 37.1191 -        bout.setBlockDataMode(true);
 37.1192 -        annotateClass(cl);
 37.1193 -        bout.setBlockDataMode(false);
 37.1194 -        bout.writeByte(TC_ENDBLOCKDATA);
 37.1195 -
 37.1196 -        writeClassDesc(desc.getSuperDesc(), false);
 37.1197 -    }
 37.1198 -
 37.1199 -    /**
 37.1200 -     * Writes given string to stream, using standard or long UTF format
 37.1201 -     * depending on string length.
 37.1202 -     */
 37.1203 -    private void writeString(String str, boolean unshared) throws IOException {
 37.1204 -        handles.assign(unshared ? null : str);
 37.1205 -        long utflen = bout.getUTFLength(str);
 37.1206 -        if (utflen <= 0xFFFF) {
 37.1207 -            bout.writeByte(TC_STRING);
 37.1208 -            bout.writeUTF(str, utflen);
 37.1209 -        } else {
 37.1210 -            bout.writeByte(TC_LONGSTRING);
 37.1211 -            bout.writeLongUTF(str, utflen);
 37.1212 -        }
 37.1213 -    }
 37.1214 -
 37.1215 -    /**
 37.1216 -     * Writes given array object to stream.
 37.1217 -     */
 37.1218 -    private void writeArray(Object array,
 37.1219 -                            ObjectStreamClass desc,
 37.1220 -                            boolean unshared)
 37.1221 -        throws IOException
 37.1222 -    {
 37.1223 -        bout.writeByte(TC_ARRAY);
 37.1224 -        writeClassDesc(desc, false);
 37.1225 -        handles.assign(unshared ? null : array);
 37.1226 -
 37.1227 -        Class ccl = desc.forClass().getComponentType();
 37.1228 -        if (ccl.isPrimitive()) {
 37.1229 -            if (ccl == Integer.TYPE) {
 37.1230 -                int[] ia = (int[]) array;
 37.1231 -                bout.writeInt(ia.length);
 37.1232 -                bout.writeInts(ia, 0, ia.length);
 37.1233 -            } else if (ccl == Byte.TYPE) {
 37.1234 -                byte[] ba = (byte[]) array;
 37.1235 -                bout.writeInt(ba.length);
 37.1236 -                bout.write(ba, 0, ba.length, true);
 37.1237 -            } else if (ccl == Long.TYPE) {
 37.1238 -                long[] ja = (long[]) array;
 37.1239 -                bout.writeInt(ja.length);
 37.1240 -                bout.writeLongs(ja, 0, ja.length);
 37.1241 -            } else if (ccl == Float.TYPE) {
 37.1242 -                float[] fa = (float[]) array;
 37.1243 -                bout.writeInt(fa.length);
 37.1244 -                bout.writeFloats(fa, 0, fa.length);
 37.1245 -            } else if (ccl == Double.TYPE) {
 37.1246 -                double[] da = (double[]) array;
 37.1247 -                bout.writeInt(da.length);
 37.1248 -                bout.writeDoubles(da, 0, da.length);
 37.1249 -            } else if (ccl == Short.TYPE) {
 37.1250 -                short[] sa = (short[]) array;
 37.1251 -                bout.writeInt(sa.length);
 37.1252 -                bout.writeShorts(sa, 0, sa.length);
 37.1253 -            } else if (ccl == Character.TYPE) {
 37.1254 -                char[] ca = (char[]) array;
 37.1255 -                bout.writeInt(ca.length);
 37.1256 -                bout.writeChars(ca, 0, ca.length);
 37.1257 -            } else if (ccl == Boolean.TYPE) {
 37.1258 -                boolean[] za = (boolean[]) array;
 37.1259 -                bout.writeInt(za.length);
 37.1260 -                bout.writeBooleans(za, 0, za.length);
 37.1261 -            } else {
 37.1262 -                throw new InternalError();
 37.1263 -            }
 37.1264 -        } else {
 37.1265 -            Object[] objs = (Object[]) array;
 37.1266 -            int len = objs.length;
 37.1267 -            bout.writeInt(len);
 37.1268 -            if (extendedDebugInfo) {
 37.1269 -                debugInfoStack.push(
 37.1270 -                    "array (class \"" + array.getClass().getName() +
 37.1271 -                    "\", size: " + len  + ")");
 37.1272 -            }
 37.1273 -            try {
 37.1274 -                for (int i = 0; i < len; i++) {
 37.1275 -                    if (extendedDebugInfo) {
 37.1276 -                        debugInfoStack.push(
 37.1277 -                            "element of array (index: " + i + ")");
 37.1278 -                    }
 37.1279 -                    try {
 37.1280 -                        writeObject0(objs[i], false);
 37.1281 -                    } finally {
 37.1282 -                        if (extendedDebugInfo) {
 37.1283 -                            debugInfoStack.pop();
 37.1284 -                        }
 37.1285 -                    }
 37.1286 -                }
 37.1287 -            } finally {
 37.1288 -                if (extendedDebugInfo) {
 37.1289 -                    debugInfoStack.pop();
 37.1290 -                }
 37.1291 -            }
 37.1292 -        }
 37.1293 -    }
 37.1294 -
 37.1295 -    /**
 37.1296 -     * Writes given enum constant to stream.
 37.1297 -     */
 37.1298 -    private void writeEnum(Enum en,
 37.1299 -                           ObjectStreamClass desc,
 37.1300 -                           boolean unshared)
 37.1301 -        throws IOException
 37.1302 -    {
 37.1303 -        bout.writeByte(TC_ENUM);
 37.1304 -        ObjectStreamClass sdesc = desc.getSuperDesc();
 37.1305 -        writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false);
 37.1306 -        handles.assign(unshared ? null : en);
 37.1307 -        writeString(en.name(), false);
 37.1308 -    }
 37.1309 -
 37.1310 -    /**
 37.1311 -     * Writes representation of a "ordinary" (i.e., not a String, Class,
 37.1312 -     * ObjectStreamClass, array, or enum constant) serializable object to the
 37.1313 -     * stream.
 37.1314 -     */
 37.1315 -    private void writeOrdinaryObject(Object obj,
 37.1316 -                                     ObjectStreamClass desc,
 37.1317 -                                     boolean unshared)
 37.1318 -        throws IOException
 37.1319 -    {
 37.1320 -        if (extendedDebugInfo) {
 37.1321 -            debugInfoStack.push(
 37.1322 -                (depth == 1 ? "root " : "") + "object (class \"" +
 37.1323 -                obj.getClass().getName() + "\", " + obj.toString() + ")");
 37.1324 -        }
 37.1325 -        try {
 37.1326 -            desc.checkSerialize();
 37.1327 -
 37.1328 -            bout.writeByte(TC_OBJECT);
 37.1329 -            writeClassDesc(desc, false);
 37.1330 -            handles.assign(unshared ? null : obj);
 37.1331 -            if (desc.isExternalizable() && !desc.isProxy()) {
 37.1332 -                writeExternalData((Externalizable) obj);
 37.1333 -            } else {
 37.1334 -                writeSerialData(obj, desc);
 37.1335 -            }
 37.1336 -        } finally {
 37.1337 -            if (extendedDebugInfo) {
 37.1338 -                debugInfoStack.pop();
 37.1339 -            }
 37.1340 -        }
 37.1341 -    }
 37.1342 -
 37.1343 -    /**
 37.1344 -     * Writes externalizable data of given object by invoking its
 37.1345 -     * writeExternal() method.
 37.1346 -     */
 37.1347 -    private void writeExternalData(Externalizable obj) throws IOException {
 37.1348 -        PutFieldImpl oldPut = curPut;
 37.1349 -        curPut = null;
 37.1350 -
 37.1351 -        if (extendedDebugInfo) {
 37.1352 -            debugInfoStack.push("writeExternal data");
 37.1353 -        }
 37.1354 -        Object oldContext = curContext;
 37.1355 -        try {
 37.1356 -            curContext = null;
 37.1357 -            if (protocol == PROTOCOL_VERSION_1) {
 37.1358 -                obj.writeExternal(this);
 37.1359 -            } else {
 37.1360 -                bout.setBlockDataMode(true);
 37.1361 -                obj.writeExternal(this);
 37.1362 -                bout.setBlockDataMode(false);
 37.1363 -                bout.writeByte(TC_ENDBLOCKDATA);
 37.1364 -            }
 37.1365 -        } finally {
 37.1366 -            curContext = oldContext;
 37.1367 -            if (extendedDebugInfo) {
 37.1368 -                debugInfoStack.pop();
 37.1369 -            }
 37.1370 -        }
 37.1371 -
 37.1372 -        curPut = oldPut;
 37.1373 -    }
 37.1374 -
 37.1375 -    /**
 37.1376 -     * Writes instance data for each serializable class of given object, from
 37.1377 -     * superclass to subclass.
 37.1378 -     */
 37.1379 -    private void writeSerialData(Object obj, ObjectStreamClass desc)
 37.1380 -        throws IOException
 37.1381 -    {
 37.1382 -        ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
 37.1383 -        for (int i = 0; i < slots.length; i++) {
 37.1384 -            ObjectStreamClass slotDesc = slots[i].desc;
 37.1385 -            if (slotDesc.hasWriteObjectMethod()) {
 37.1386 -                PutFieldImpl oldPut = curPut;
 37.1387 -                curPut = null;
 37.1388 -                Object oldContext = curContext;
 37.1389 -
 37.1390 -                if (extendedDebugInfo) {
 37.1391 -                    debugInfoStack.push(
 37.1392 -                        "custom writeObject data (class \"" +
 37.1393 -                        slotDesc.getName() + "\")");
 37.1394 -                }
 37.1395 -                try {
 37.1396 -                    curContext = new Object(); //new SerialCallbackContext(obj, slotDesc);
 37.1397 -                    bout.setBlockDataMode(true);
 37.1398 -                    slotDesc.invokeWriteObject(obj, this);
 37.1399 -                    bout.setBlockDataMode(false);
 37.1400 -                    bout.writeByte(TC_ENDBLOCKDATA);
 37.1401 -                } finally {
 37.1402 -                    //curContext.setUsed();
 37.1403 -                    curContext = oldContext;
 37.1404 -                    if (extendedDebugInfo) {
 37.1405 -                        debugInfoStack.pop();
 37.1406 -                    }
 37.1407 -                }
 37.1408 -
 37.1409 -                curPut = oldPut;
 37.1410 -            } else {
 37.1411 -                defaultWriteFields(obj, slotDesc);
 37.1412 -            }
 37.1413 -        }
 37.1414 -    }
 37.1415 -
 37.1416 -    /**
 37.1417 -     * Fetches and writes values of serializable fields of given object to
 37.1418 -     * stream.  The given class descriptor specifies which field values to
 37.1419 -     * write, and in which order they should be written.
 37.1420 -     */
 37.1421 -    private void defaultWriteFields(Object obj, ObjectStreamClass desc)
 37.1422 -        throws IOException
 37.1423 -    {
 37.1424 -        // REMIND: perform conservative isInstance check here?
 37.1425 -        desc.checkDefaultSerialize();
 37.1426 -
 37.1427 -        int primDataSize = desc.getPrimDataSize();
 37.1428 -        if (primVals == null || primVals.length < primDataSize) {
 37.1429 -            primVals = new byte[primDataSize];
 37.1430 -        }
 37.1431 -        desc.getPrimFieldValues(obj, primVals);
 37.1432 -        bout.write(primVals, 0, primDataSize, false);
 37.1433 -
 37.1434 -        ObjectStreamField[] fields = desc.getFields(false);
 37.1435 -        Object[] objVals = new Object[desc.getNumObjFields()];
 37.1436 -        int numPrimFields = fields.length - objVals.length;
 37.1437 -        desc.getObjFieldValues(obj, objVals);
 37.1438 -        for (int i = 0; i < objVals.length; i++) {
 37.1439 -            if (extendedDebugInfo) {
 37.1440 -                debugInfoStack.push(
 37.1441 -                    "field (class \"" + desc.getName() + "\", name: \"" +
 37.1442 -                    fields[numPrimFields + i].getName() + "\", type: \"" +
 37.1443 -                    fields[numPrimFields + i].getType() + "\")");
 37.1444 -            }
 37.1445 -            try {
 37.1446 -                writeObject0(objVals[i],
 37.1447 -                             fields[numPrimFields + i].isUnshared());
 37.1448 -            } finally {
 37.1449 -                if (extendedDebugInfo) {
 37.1450 -                    debugInfoStack.pop();
 37.1451 -                }
 37.1452 -            }
 37.1453 -        }
 37.1454 -    }
 37.1455 -
 37.1456 -    /**
 37.1457 -     * Attempts to write to stream fatal IOException that has caused
 37.1458 -     * serialization to abort.
 37.1459 -     */
 37.1460 -    private void writeFatalException(IOException ex) throws IOException {
 37.1461 -        /*
 37.1462 -         * Note: the serialization specification states that if a second
 37.1463 -         * IOException occurs while attempting to serialize the original fatal
 37.1464 -         * exception to the stream, then a StreamCorruptedException should be
 37.1465 -         * thrown (section 2.1).  However, due to a bug in previous
 37.1466 -         * implementations of serialization, StreamCorruptedExceptions were
 37.1467 -         * rarely (if ever) actually thrown--the "root" exceptions from
 37.1468 -         * underlying streams were thrown instead.  This historical behavior is
 37.1469 -         * followed here for consistency.
 37.1470 -         */
 37.1471 -        clear();
 37.1472 -        boolean oldMode = bout.setBlockDataMode(false);
 37.1473 -        try {
 37.1474 -            bout.writeByte(TC_EXCEPTION);
 37.1475 -            writeObject0(ex, false);
 37.1476 -            clear();
 37.1477 -        } finally {
 37.1478 -            bout.setBlockDataMode(oldMode);
 37.1479 -        }
 37.1480 -    }
 37.1481 -
 37.1482 -    /**
 37.1483 -     * Converts specified span of float values into byte values.
 37.1484 -     */
 37.1485 -    // REMIND: remove once hotspot inlines Float.floatToIntBits
 37.1486 -    private static native void floatsToBytes(float[] src, int srcpos,
 37.1487 -                                             byte[] dst, int dstpos,
 37.1488 -                                             int nfloats);
 37.1489 -
 37.1490 -    /**
 37.1491 -     * Converts specified span of double values into byte values.
 37.1492 -     */
 37.1493 -    // REMIND: remove once hotspot inlines Double.doubleToLongBits
 37.1494 -    private static native void doublesToBytes(double[] src, int srcpos,
 37.1495 -                                              byte[] dst, int dstpos,
 37.1496 -                                              int ndoubles);
 37.1497 -
 37.1498 -    /**
 37.1499 -     * Default PutField implementation.
 37.1500 -     */
 37.1501 -    private class PutFieldImpl extends PutField {
 37.1502 -
 37.1503 -        /** class descriptor describing serializable fields */
 37.1504 -        private final ObjectStreamClass desc;
 37.1505 -        /** primitive field values */
 37.1506 -        private final byte[] primVals;
 37.1507 -        /** object field values */
 37.1508 -        private final Object[] objVals;
 37.1509 -
 37.1510 -        /**
 37.1511 -         * Creates PutFieldImpl object for writing fields defined in given
 37.1512 -         * class descriptor.
 37.1513 -         */
 37.1514 -        PutFieldImpl(ObjectStreamClass desc) {
 37.1515 -            this.desc = desc;
 37.1516 -            primVals = new byte[desc.getPrimDataSize()];
 37.1517 -            objVals = new Object[desc.getNumObjFields()];
 37.1518 -        }
 37.1519 -
 37.1520 -        public void put(String name, boolean val) {
 37.1521 -            Bits.putBoolean(primVals, getFieldOffset(name, Boolean.TYPE), val);
 37.1522 -        }
 37.1523 -
 37.1524 -        public void put(String name, byte val) {
 37.1525 -            primVals[getFieldOffset(name, Byte.TYPE)] = val;
 37.1526 -        }
 37.1527 -
 37.1528 -        public void put(String name, char val) {
 37.1529 -            Bits.putChar(primVals, getFieldOffset(name, Character.TYPE), val);
 37.1530 -        }
 37.1531 -
 37.1532 -        public void put(String name, short val) {
 37.1533 -            Bits.putShort(primVals, getFieldOffset(name, Short.TYPE), val);
 37.1534 -        }
 37.1535 -
 37.1536 -        public void put(String name, int val) {
 37.1537 -            Bits.putInt(primVals, getFieldOffset(name, Integer.TYPE), val);
 37.1538 -        }
 37.1539 -
 37.1540 -        public void put(String name, float val) {
 37.1541 -            Bits.putFloat(primVals, getFieldOffset(name, Float.TYPE), val);
 37.1542 -        }
 37.1543 -
 37.1544 -        public void put(String name, long val) {
 37.1545 -            Bits.putLong(primVals, getFieldOffset(name, Long.TYPE), val);
 37.1546 -        }
 37.1547 -
 37.1548 -        public void put(String name, double val) {
 37.1549 -            Bits.putDouble(primVals, getFieldOffset(name, Double.TYPE), val);
 37.1550 -        }
 37.1551 -
 37.1552 -        public void put(String name, Object val) {
 37.1553 -            objVals[getFieldOffset(name, Object.class)] = val;
 37.1554 -        }
 37.1555 -
 37.1556 -        // deprecated in ObjectOutputStream.PutField
 37.1557 -        public void write(ObjectOutput out) throws IOException {
 37.1558 -            /*
 37.1559 -             * Applications should *not* use this method to write PutField
 37.1560 -             * data, as it will lead to stream corruption if the PutField
 37.1561 -             * object writes any primitive data (since block data mode is not
 37.1562 -             * unset/set properly, as is done in OOS.writeFields()).  This
 37.1563 -             * broken implementation is being retained solely for behavioral
 37.1564 -             * compatibility, in order to support applications which use
 37.1565 -             * OOS.PutField.write() for writing only non-primitive data.
 37.1566 -             *
 37.1567 -             * Serialization of unshared objects is not implemented here since
 37.1568 -             * it is not necessary for backwards compatibility; also, unshared
 37.1569 -             * semantics may not be supported by the given ObjectOutput
 37.1570 -             * instance.  Applications which write unshared objects using the
 37.1571 -             * PutField API must use OOS.writeFields().
 37.1572 -             */
 37.1573 -            if (ObjectOutputStream.this != out) {
 37.1574 -                throw new IllegalArgumentException("wrong stream");
 37.1575 -            }
 37.1576 -            out.write(primVals, 0, primVals.length);
 37.1577 -
 37.1578 -            ObjectStreamField[] fields = desc.getFields(false);
 37.1579 -            int numPrimFields = fields.length - objVals.length;
 37.1580 -            // REMIND: warn if numPrimFields > 0?
 37.1581 -            for (int i = 0; i < objVals.length; i++) {
 37.1582 -                if (fields[numPrimFields + i].isUnshared()) {
 37.1583 -                    throw new IOException("cannot write unshared object");
 37.1584 -                }
 37.1585 -                out.writeObject(objVals[i]);
 37.1586 -            }
 37.1587 -        }
 37.1588 -
 37.1589 -        /**
 37.1590 -         * Writes buffered primitive data and object fields to stream.
 37.1591 -         */
 37.1592 -        void writeFields() throws IOException {
 37.1593 -            bout.write(primVals, 0, primVals.length, false);
 37.1594 -
 37.1595 -            ObjectStreamField[] fields = desc.getFields(false);
 37.1596 -            int numPrimFields = fields.length - objVals.length;
 37.1597 -            for (int i = 0; i < objVals.length; i++) {
 37.1598 -                if (extendedDebugInfo) {
 37.1599 -                    debugInfoStack.push(
 37.1600 -                        "field (class \"" + desc.getName() + "\", name: \"" +
 37.1601 -                        fields[numPrimFields + i].getName() + "\", type: \"" +
 37.1602 -                        fields[numPrimFields + i].getType() + "\")");
 37.1603 -                }
 37.1604 -                try {
 37.1605 -                    writeObject0(objVals[i],
 37.1606 -                                 fields[numPrimFields + i].isUnshared());
 37.1607 -                } finally {
 37.1608 -                    if (extendedDebugInfo) {
 37.1609 -                        debugInfoStack.pop();
 37.1610 -                    }
 37.1611 -                }
 37.1612 -            }
 37.1613 -        }
 37.1614 -
 37.1615 -        /**
 37.1616 -         * Returns offset of field with given name and type.  A specified type
 37.1617 -         * of null matches all types, Object.class matches all non-primitive
 37.1618 -         * types, and any other non-null type matches assignable types only.
 37.1619 -         * Throws IllegalArgumentException if no matching field found.
 37.1620 -         */
 37.1621 -        private int getFieldOffset(String name, Class type) {
 37.1622 -            ObjectStreamField field = desc.getField(name, type);
 37.1623 -            if (field == null) {
 37.1624 -                throw new IllegalArgumentException("no such field " + name +
 37.1625 -                                                   " with type " + type);
 37.1626 -            }
 37.1627 -            return field.getOffset();
 37.1628 -        }
 37.1629 -    }
 37.1630 -
 37.1631 -    /**
 37.1632 -     * Buffered output stream with two modes: in default mode, outputs data in
 37.1633 -     * same format as DataOutputStream; in "block data" mode, outputs data
 37.1634 -     * bracketed by block data markers (see object serialization specification
 37.1635 -     * for details).
 37.1636 -     */
 37.1637 -    private static class BlockDataOutputStream
 37.1638 -        extends OutputStream implements DataOutput
 37.1639 -    {
 37.1640 -        /** maximum data block length */
 37.1641 -        private static final int MAX_BLOCK_SIZE = 1024;
 37.1642 -        /** maximum data block header length */
 37.1643 -        private static final int MAX_HEADER_SIZE = 5;
 37.1644 -        /** (tunable) length of char buffer (for writing strings) */
 37.1645 -        private static final int CHAR_BUF_SIZE = 256;
 37.1646 -
 37.1647 -        /** buffer for writing general/block data */
 37.1648 -        private final byte[] buf = new byte[MAX_BLOCK_SIZE];
 37.1649 -        /** buffer for writing block data headers */
 37.1650 -        private final byte[] hbuf = new byte[MAX_HEADER_SIZE];
 37.1651 -        /** char buffer for fast string writes */
 37.1652 -        private final char[] cbuf = new char[CHAR_BUF_SIZE];
 37.1653 -
 37.1654 -        /** block data mode */
 37.1655 -        private boolean blkmode = false;
 37.1656 -        /** current offset into buf */
 37.1657 -        private int pos = 0;
 37.1658 -
 37.1659 -        /** underlying output stream */
 37.1660 -        private final OutputStream out;
 37.1661 -        /** loopback stream (for data writes that span data blocks) */
 37.1662 -        private final DataOutputStream dout;
 37.1663 -
 37.1664 -        /**
 37.1665 -         * Creates new BlockDataOutputStream on top of given underlying stream.
 37.1666 -         * Block data mode is turned off by default.
 37.1667 -         */
 37.1668 -        BlockDataOutputStream(OutputStream out) {
 37.1669 -            this.out = out;
 37.1670 -            dout = new DataOutputStream(this);
 37.1671 -        }
 37.1672 -
 37.1673 -        /**
 37.1674 -         * Sets block data mode to the given mode (true == on, false == off)
 37.1675 -         * and returns the previous mode value.  If the new mode is the same as
 37.1676 -         * the old mode, no action is taken.  If the new mode differs from the
 37.1677 -         * old mode, any buffered data is flushed before switching to the new
 37.1678 -         * mode.
 37.1679 -         */
 37.1680 -        boolean setBlockDataMode(boolean mode) throws IOException {
 37.1681 -            if (blkmode == mode) {
 37.1682 -                return blkmode;
 37.1683 -            }
 37.1684 -            drain();
 37.1685 -            blkmode = mode;
 37.1686 -            return !blkmode;
 37.1687 -        }
 37.1688 -
 37.1689 -        /**
 37.1690 -         * Returns true if the stream is currently in block data mode, false
 37.1691 -         * otherwise.
 37.1692 -         */
 37.1693 -        boolean getBlockDataMode() {
 37.1694 -            return blkmode;
 37.1695 -        }
 37.1696 -
 37.1697 -        /* ----------------- generic output stream methods ----------------- */
 37.1698 -        /*
 37.1699 -         * The following methods are equivalent to their counterparts in
 37.1700 -         * OutputStream, except that they partition written data into data
 37.1701 -         * blocks when in block data mode.
 37.1702 -         */
 37.1703 -
 37.1704 -        public void write(int b) throws IOException {
 37.1705 -            if (pos >= MAX_BLOCK_SIZE) {
 37.1706 -                drain();
 37.1707 -            }
 37.1708 -            buf[pos++] = (byte) b;
 37.1709 -        }
 37.1710 -
 37.1711 -        public void write(byte[] b) throws IOException {
 37.1712 -            write(b, 0, b.length, false);
 37.1713 -        }
 37.1714 -
 37.1715 -        public void write(byte[] b, int off, int len) throws IOException {
 37.1716 -            write(b, off, len, false);
 37.1717 -        }
 37.1718 -
 37.1719 -        public void flush() throws IOException {
 37.1720 -            drain();
 37.1721 -            out.flush();
 37.1722 -        }
 37.1723 -
 37.1724 -        public void close() throws IOException {
 37.1725 -            flush();
 37.1726 -            out.close();
 37.1727 -        }
 37.1728 -
 37.1729 -        /**
 37.1730 -         * Writes specified span of byte values from given array.  If copy is
 37.1731 -         * true, copies the values to an intermediate buffer before writing
 37.1732 -         * them to underlying stream (to avoid exposing a reference to the
 37.1733 -         * original byte array).
 37.1734 -         */
 37.1735 -        void write(byte[] b, int off, int len, boolean copy)
 37.1736 -            throws IOException
 37.1737 -        {
 37.1738 -            if (!(copy || blkmode)) {           // write directly
 37.1739 -                drain();
 37.1740 -                out.write(b, off, len);
 37.1741 -                return;
 37.1742 -            }
 37.1743 -
 37.1744 -            while (len > 0) {
 37.1745 -                if (pos >= MAX_BLOCK_SIZE) {
 37.1746 -                    drain();
 37.1747 -                }
 37.1748 -                if (len >= MAX_BLOCK_SIZE && !copy && pos == 0) {
 37.1749 -                    // avoid unnecessary copy
 37.1750 -                    writeBlockHeader(MAX_BLOCK_SIZE);
 37.1751 -                    out.write(b, off, MAX_BLOCK_SIZE);
 37.1752 -                    off += MAX_BLOCK_SIZE;
 37.1753 -                    len -= MAX_BLOCK_SIZE;
 37.1754 -                } else {
 37.1755 -                    int wlen = Math.min(len, MAX_BLOCK_SIZE - pos);
 37.1756 -                    System.arraycopy(b, off, buf, pos, wlen);
 37.1757 -                    pos += wlen;
 37.1758 -                    off += wlen;
 37.1759 -                    len -= wlen;
 37.1760 -                }
 37.1761 -            }
 37.1762 -        }
 37.1763 -
 37.1764 -        /**
 37.1765 -         * Writes all buffered data from this stream to the underlying stream,
 37.1766 -         * but does not flush underlying stream.
 37.1767 -         */
 37.1768 -        void drain() throws IOException {
 37.1769 -            if (pos == 0) {
 37.1770 -                return;
 37.1771 -            }
 37.1772 -            if (blkmode) {
 37.1773 -                writeBlockHeader(pos);
 37.1774 -            }
 37.1775 -            out.write(buf, 0, pos);
 37.1776 -            pos = 0;
 37.1777 -        }
 37.1778 -
 37.1779 -        /**
 37.1780 -         * Writes block data header.  Data blocks shorter than 256 bytes are
 37.1781 -         * prefixed with a 2-byte header; all others start with a 5-byte
 37.1782 -         * header.
 37.1783 -         */
 37.1784 -        private void writeBlockHeader(int len) throws IOException {
 37.1785 -            if (len <= 0xFF) {
 37.1786 -                hbuf[0] = TC_BLOCKDATA;
 37.1787 -                hbuf[1] = (byte) len;
 37.1788 -                out.write(hbuf, 0, 2);
 37.1789 -            } else {
 37.1790 -                hbuf[0] = TC_BLOCKDATALONG;
 37.1791 -                Bits.putInt(hbuf, 1, len);
 37.1792 -                out.write(hbuf, 0, 5);
 37.1793 -            }
 37.1794 -        }
 37.1795 -
 37.1796 -
 37.1797 -        /* ----------------- primitive data output methods ----------------- */
 37.1798 -        /*
 37.1799 -         * The following methods are equivalent to their counterparts in
 37.1800 -         * DataOutputStream, except that they partition written data into data
 37.1801 -         * blocks when in block data mode.
 37.1802 -         */
 37.1803 -
 37.1804 -        public void writeBoolean(boolean v) throws IOException {
 37.1805 -            if (pos >= MAX_BLOCK_SIZE) {
 37.1806 -                drain();
 37.1807 -            }
 37.1808 -            Bits.putBoolean(buf, pos++, v);
 37.1809 -        }
 37.1810 -
 37.1811 -        public void writeByte(int v) throws IOException {
 37.1812 -            if (pos >= MAX_BLOCK_SIZE) {
 37.1813 -                drain();
 37.1814 -            }
 37.1815 -            buf[pos++] = (byte) v;
 37.1816 -        }
 37.1817 -
 37.1818 -        public void writeChar(int v) throws IOException {
 37.1819 -            if (pos + 2 <= MAX_BLOCK_SIZE) {
 37.1820 -                Bits.putChar(buf, pos, (char) v);
 37.1821 -                pos += 2;
 37.1822 -            } else {
 37.1823 -                dout.writeChar(v);
 37.1824 -            }
 37.1825 -        }
 37.1826 -
 37.1827 -        public void writeShort(int v) throws IOException {
 37.1828 -            if (pos + 2 <= MAX_BLOCK_SIZE) {
 37.1829 -                Bits.putShort(buf, pos, (short) v);
 37.1830 -                pos += 2;
 37.1831 -            } else {
 37.1832 -                dout.writeShort(v);
 37.1833 -            }
 37.1834 -        }
 37.1835 -
 37.1836 -        public void writeInt(int v) throws IOException {
 37.1837 -            if (pos + 4 <= MAX_BLOCK_SIZE) {
 37.1838 -                Bits.putInt(buf, pos, v);
 37.1839 -                pos += 4;
 37.1840 -            } else {
 37.1841 -                dout.writeInt(v);
 37.1842 -            }
 37.1843 -        }
 37.1844 -
 37.1845 -        public void writeFloat(float v) throws IOException {
 37.1846 -            if (pos + 4 <= MAX_BLOCK_SIZE) {
 37.1847 -                Bits.putFloat(buf, pos, v);
 37.1848 -                pos += 4;
 37.1849 -            } else {
 37.1850 -                dout.writeFloat(v);
 37.1851 -            }
 37.1852 -        }
 37.1853 -
 37.1854 -        public void writeLong(long v) throws IOException {
 37.1855 -            if (pos + 8 <= MAX_BLOCK_SIZE) {
 37.1856 -                Bits.putLong(buf, pos, v);
 37.1857 -                pos += 8;
 37.1858 -            } else {
 37.1859 -                dout.writeLong(v);
 37.1860 -            }
 37.1861 -        }
 37.1862 -
 37.1863 -        public void writeDouble(double v) throws IOException {
 37.1864 -            if (pos + 8 <= MAX_BLOCK_SIZE) {
 37.1865 -                Bits.putDouble(buf, pos, v);
 37.1866 -                pos += 8;
 37.1867 -            } else {
 37.1868 -                dout.writeDouble(v);
 37.1869 -            }
 37.1870 -        }
 37.1871 -
 37.1872 -        public void writeBytes(String s) throws IOException {
 37.1873 -            int endoff = s.length();
 37.1874 -            int cpos = 0;
 37.1875 -            int csize = 0;
 37.1876 -            for (int off = 0; off < endoff; ) {
 37.1877 -                if (cpos >= csize) {
 37.1878 -                    cpos = 0;
 37.1879 -                    csize = Math.min(endoff - off, CHAR_BUF_SIZE);
 37.1880 -                    s.getChars(off, off + csize, cbuf, 0);
 37.1881 -                }
 37.1882 -                if (pos >= MAX_BLOCK_SIZE) {
 37.1883 -                    drain();
 37.1884 -                }
 37.1885 -                int n = Math.min(csize - cpos, MAX_BLOCK_SIZE - pos);
 37.1886 -                int stop = pos + n;
 37.1887 -                while (pos < stop) {
 37.1888 -                    buf[pos++] = (byte) cbuf[cpos++];
 37.1889 -                }
 37.1890 -                off += n;
 37.1891 -            }
 37.1892 -        }
 37.1893 -
 37.1894 -        public void writeChars(String s) throws IOException {
 37.1895 -            int endoff = s.length();
 37.1896 -            for (int off = 0; off < endoff; ) {
 37.1897 -                int csize = Math.min(endoff - off, CHAR_BUF_SIZE);
 37.1898 -                s.getChars(off, off + csize, cbuf, 0);
 37.1899 -                writeChars(cbuf, 0, csize);
 37.1900 -                off += csize;
 37.1901 -            }
 37.1902 -        }
 37.1903 -
 37.1904 -        public void writeUTF(String s) throws IOException {
 37.1905 -            writeUTF(s, getUTFLength(s));
 37.1906 -        }
 37.1907 -
 37.1908 -
 37.1909 -        /* -------------- primitive data array output methods -------------- */
 37.1910 -        /*
 37.1911 -         * The following methods write out spans of primitive data values.
 37.1912 -         * Though equivalent to calling the corresponding primitive write
 37.1913 -         * methods repeatedly, these methods are optimized for writing groups
 37.1914 -         * of primitive data values more efficiently.
 37.1915 -         */
 37.1916 -
 37.1917 -        void writeBooleans(boolean[] v, int off, int len) throws IOException {
 37.1918 -            int endoff = off + len;
 37.1919 -            while (off < endoff) {
 37.1920 -                if (pos >= MAX_BLOCK_SIZE) {
 37.1921 -                    drain();
 37.1922 -                }
 37.1923 -                int stop = Math.min(endoff, off + (MAX_BLOCK_SIZE - pos));
 37.1924 -                while (off < stop) {
 37.1925 -                    Bits.putBoolean(buf, pos++, v[off++]);
 37.1926 -                }
 37.1927 -            }
 37.1928 -        }
 37.1929 -
 37.1930 -        void writeChars(char[] v, int off, int len) throws IOException {
 37.1931 -            int limit = MAX_BLOCK_SIZE - 2;
 37.1932 -            int endoff = off + len;
 37.1933 -            while (off < endoff) {
 37.1934 -                if (pos <= limit) {
 37.1935 -                    int avail = (MAX_BLOCK_SIZE - pos) >> 1;
 37.1936 -                    int stop = Math.min(endoff, off + avail);
 37.1937 -                    while (off < stop) {
 37.1938 -                        Bits.putChar(buf, pos, v[off++]);
 37.1939 -                        pos += 2;
 37.1940 -                    }
 37.1941 -                } else {
 37.1942 -                    dout.writeChar(v[off++]);
 37.1943 -                }
 37.1944 -            }
 37.1945 -        }
 37.1946 -
 37.1947 -        void writeShorts(short[] v, int off, int len) throws IOException {
 37.1948 -            int limit = MAX_BLOCK_SIZE - 2;
 37.1949 -            int endoff = off + len;
 37.1950 -            while (off < endoff) {
 37.1951 -                if (pos <= limit) {
 37.1952 -                    int avail = (MAX_BLOCK_SIZE - pos) >> 1;
 37.1953 -                    int stop = Math.min(endoff, off + avail);
 37.1954 -                    while (off < stop) {
 37.1955 -                        Bits.putShort(buf, pos, v[off++]);
 37.1956 -                        pos += 2;
 37.1957 -                    }
 37.1958 -                } else {
 37.1959 -                    dout.writeShort(v[off++]);
 37.1960 -                }
 37.1961 -            }
 37.1962 -        }
 37.1963 -
 37.1964 -        void writeInts(int[] v, int off, int len) throws IOException {
 37.1965 -            int limit = MAX_BLOCK_SIZE - 4;
 37.1966 -            int endoff = off + len;
 37.1967 -            while (off < endoff) {
 37.1968 -                if (pos <= limit) {
 37.1969 -                    int avail = (MAX_BLOCK_SIZE - pos) >> 2;
 37.1970 -                    int stop = Math.min(endoff, off + avail);
 37.1971 -                    while (off < stop) {
 37.1972 -                        Bits.putInt(buf, pos, v[off++]);
 37.1973 -                        pos += 4;
 37.1974 -                    }
 37.1975 -                } else {
 37.1976 -                    dout.writeInt(v[off++]);
 37.1977 -                }
 37.1978 -            }
 37.1979 -        }
 37.1980 -
 37.1981 -        void writeFloats(float[] v, int off, int len) throws IOException {
 37.1982 -            int limit = MAX_BLOCK_SIZE - 4;
 37.1983 -            int endoff = off + len;
 37.1984 -            while (off < endoff) {
 37.1985 -                if (pos <= limit) {
 37.1986 -                    int avail = (MAX_BLOCK_SIZE - pos) >> 2;
 37.1987 -                    int chunklen = Math.min(endoff - off, avail);
 37.1988 -                    floatsToBytes(v, off, buf, pos, chunklen);
 37.1989 -                    off += chunklen;
 37.1990 -                    pos += chunklen << 2;
 37.1991 -                } else {
 37.1992 -                    dout.writeFloat(v[off++]);
 37.1993 -                }
 37.1994 -            }
 37.1995 -        }
 37.1996 -
 37.1997 -        void writeLongs(long[] v, int off, int len) throws IOException {
 37.1998 -            int limit = MAX_BLOCK_SIZE - 8;
 37.1999 -            int endoff = off + len;
 37.2000 -            while (off < endoff) {
 37.2001 -                if (pos <= limit) {
 37.2002 -                    int avail = (MAX_BLOCK_SIZE - pos) >> 3;
 37.2003 -                    int stop = Math.min(endoff, off + avail);
 37.2004 -                    while (off < stop) {
 37.2005 -                        Bits.putLong(buf, pos, v[off++]);
 37.2006 -                        pos += 8;
 37.2007 -                    }
 37.2008 -                } else {
 37.2009 -                    dout.writeLong(v[off++]);
 37.2010 -                }
 37.2011 -            }
 37.2012 -        }
 37.2013 -
 37.2014 -        void writeDoubles(double[] v, int off, int len) throws IOException {
 37.2015 -            int limit = MAX_BLOCK_SIZE - 8;
 37.2016 -            int endoff = off + len;
 37.2017 -            while (off < endoff) {
 37.2018 -                if (pos <= limit) {
 37.2019 -                    int avail = (MAX_BLOCK_SIZE - pos) >> 3;
 37.2020 -                    int chunklen = Math.min(endoff - off, avail);
 37.2021 -                    doublesToBytes(v, off, buf, pos, chunklen);
 37.2022 -                    off += chunklen;
 37.2023 -                    pos += chunklen << 3;
 37.2024 -                } else {
 37.2025 -                    dout.writeDouble(v[off++]);
 37.2026 -                }
 37.2027 -            }
 37.2028 -        }
 37.2029 -
 37.2030 -        /**
 37.2031 -         * Returns the length in bytes of the UTF encoding of the given string.
 37.2032 -         */
 37.2033 -        long getUTFLength(String s) {
 37.2034 -            int len = s.length();
 37.2035 -            long utflen = 0;
 37.2036 -            for (int off = 0; off < len; ) {
 37.2037 -                int csize = Math.min(len - off, CHAR_BUF_SIZE);
 37.2038 -                s.getChars(off, off + csize, cbuf, 0);
 37.2039 -                for (int cpos = 0; cpos < csize; cpos++) {
 37.2040 -                    char c = cbuf[cpos];
 37.2041 -                    if (c >= 0x0001 && c <= 0x007F) {
 37.2042 -                        utflen++;
 37.2043 -                    } else if (c > 0x07FF) {
 37.2044 -                        utflen += 3;
 37.2045 -                    } else {
 37.2046 -                        utflen += 2;
 37.2047 -                    }
 37.2048 -                }
 37.2049 -                off += csize;
 37.2050 -            }
 37.2051 -            return utflen;
 37.2052 -        }
 37.2053 -
 37.2054 -        /**
 37.2055 -         * Writes the given string in UTF format.  This method is used in
 37.2056 -         * situations where the UTF encoding length of the string is already
 37.2057 -         * known; specifying it explicitly avoids a prescan of the string to
 37.2058 -         * determine its UTF length.
 37.2059 -         */
 37.2060 -        void writeUTF(String s, long utflen) throws IOException {
 37.2061 -            if (utflen > 0xFFFFL) {
 37.2062 -                throw new UTFDataFormatException();
 37.2063 -            }
 37.2064 -            writeShort((int) utflen);
 37.2065 -            if (utflen == (long) s.length()) {
 37.2066 -                writeBytes(s);
 37.2067 -            } else {
 37.2068 -                writeUTFBody(s);
 37.2069 -            }
 37.2070 -        }
 37.2071 -
 37.2072 -        /**
 37.2073 -         * Writes given string in "long" UTF format.  "Long" UTF format is
 37.2074 -         * identical to standard UTF, except that it uses an 8 byte header
 37.2075 -         * (instead of the standard 2 bytes) to convey the UTF encoding length.
 37.2076 -         */
 37.2077 -        void writeLongUTF(String s) throws IOException {
 37.2078 -            writeLongUTF(s, getUTFLength(s));
 37.2079 -        }
 37.2080 -
 37.2081 -        /**
 37.2082 -         * Writes given string in "long" UTF format, where the UTF encoding
 37.2083 -         * length of the string is already known.
 37.2084 -         */
 37.2085 -        void writeLongUTF(String s, long utflen) throws IOException {
 37.2086 -            writeLong(utflen);
 37.2087 -            if (utflen == (long) s.length()) {
 37.2088 -                writeBytes(s);
 37.2089 -            } else {
 37.2090 -                writeUTFBody(s);
 37.2091 -            }
 37.2092 -        }
 37.2093 -
 37.2094 -        /**
 37.2095 -         * Writes the "body" (i.e., the UTF representation minus the 2-byte or
 37.2096 -         * 8-byte length header) of the UTF encoding for the given string.
 37.2097 -         */
 37.2098 -        private void writeUTFBody(String s) throws IOException {
 37.2099 -            int limit = MAX_BLOCK_SIZE - 3;
 37.2100 -            int len = s.length();
 37.2101 -            for (int off = 0; off < len; ) {
 37.2102 -                int csize = Math.min(len - off, CHAR_BUF_SIZE);
 37.2103 -                s.getChars(off, off + csize, cbuf, 0);
 37.2104 -                for (int cpos = 0; cpos < csize; cpos++) {
 37.2105 -                    char c = cbuf[cpos];
 37.2106 -                    if (pos <= limit) {
 37.2107 -                        if (c <= 0x007F && c != 0) {
 37.2108 -                            buf[pos++] = (byte) c;
 37.2109 -                        } else if (c > 0x07FF) {
 37.2110 -                            buf[pos + 2] = (byte) (0x80 | ((c >> 0) & 0x3F));
 37.2111 -                            buf[pos + 1] = (byte) (0x80 | ((c >> 6) & 0x3F));
 37.2112 -                            buf[pos + 0] = (byte) (0xE0 | ((c >> 12) & 0x0F));
 37.2113 -                            pos += 3;
 37.2114 -                        } else {
 37.2115 -                            buf[pos + 1] = (byte) (0x80 | ((c >> 0) & 0x3F));
 37.2116 -                            buf[pos + 0] = (byte) (0xC0 | ((c >> 6) & 0x1F));
 37.2117 -                            pos += 2;
 37.2118 -                        }
 37.2119 -                    } else {    // write one byte at a time to normalize block
 37.2120 -                        if (c <= 0x007F && c != 0) {
 37.2121 -                            write(c);
 37.2122 -                        } else if (c > 0x07FF) {
 37.2123 -                            write(0xE0 | ((c >> 12) & 0x0F));
 37.2124 -                            write(0x80 | ((c >> 6) & 0x3F));
 37.2125 -                            write(0x80 | ((c >> 0) & 0x3F));
 37.2126 -                        } else {
 37.2127 -                            write(0xC0 | ((c >> 6) & 0x1F));
 37.2128 -                            write(0x80 | ((c >> 0) & 0x3F));
 37.2129 -                        }
 37.2130 -                    }
 37.2131 -                }
 37.2132 -                off += csize;
 37.2133 -            }
 37.2134 -        }
 37.2135 -    }
 37.2136 -
 37.2137 -    /**
 37.2138 -     * Lightweight identity hash table which maps objects to integer handles,
 37.2139 -     * assigned in ascending order.
 37.2140 -     */
 37.2141 -    private static class HandleTable {
 37.2142 -
 37.2143 -        /* number of mappings in table/next available handle */
 37.2144 -        private int size;
 37.2145 -        /* size threshold determining when to expand hash spine */
 37.2146 -        private int threshold;
 37.2147 -        /* factor for computing size threshold */
 37.2148 -        private final float loadFactor;
 37.2149 -        /* maps hash value -> candidate handle value */
 37.2150 -        private int[] spine;
 37.2151 -        /* maps handle value -> next candidate handle value */
 37.2152 -        private int[] next;
 37.2153 -        /* maps handle value -> associated object */
 37.2154 -        private Object[] objs;
 37.2155 -
 37.2156 -        /**
 37.2157 -         * Creates new HandleTable with given capacity and load factor.
 37.2158 -         */
 37.2159 -        HandleTable(int initialCapacity, float loadFactor) {
 37.2160 -            this.loadFactor = loadFactor;
 37.2161 -            spine = new int[initialCapacity];
 37.2162 -            next = new int[initialCapacity];
 37.2163 -            objs = new Object[initialCapacity];
 37.2164 -            threshold = (int) (initialCapacity * loadFactor);
 37.2165 -            clear();
 37.2166 -        }
 37.2167 -
 37.2168 -        /**
 37.2169 -         * Assigns next available handle to given object, and returns handle
 37.2170 -         * value.  Handles are assigned in ascending order starting at 0.
 37.2171 -         */
 37.2172 -        int assign(Object obj) {
 37.2173 -            if (size >= next.length) {
 37.2174 -                growEntries();
 37.2175 -            }
 37.2176 -            if (size >= threshold) {
 37.2177 -                growSpine();
 37.2178 -            }
 37.2179 -            insert(obj, size);
 37.2180 -            return size++;
 37.2181 -        }
 37.2182 -
 37.2183 -        /**
 37.2184 -         * Looks up and returns handle associated with given object, or -1 if
 37.2185 -         * no mapping found.
 37.2186 -         */
 37.2187 -        int lookup(Object obj) {
 37.2188 -            if (size == 0) {
 37.2189 -                return -1;
 37.2190 -            }
 37.2191 -            int index = hash(obj) % spine.length;
 37.2192 -            for (int i = spine[index]; i >= 0; i = next[i]) {
 37.2193 -                if (objs[i] == obj) {
 37.2194 -                    return i;
 37.2195 -                }
 37.2196 -            }
 37.2197 -            return -1;
 37.2198 -        }
 37.2199 -
 37.2200 -        /**
 37.2201 -         * Resets table to its initial (empty) state.
 37.2202 -         */
 37.2203 -        void clear() {
 37.2204 -            Arrays.fill(spine, -1);
 37.2205 -            Arrays.fill(objs, 0, size, null);
 37.2206 -            size = 0;
 37.2207 -        }
 37.2208 -
 37.2209 -        /**
 37.2210 -         * Returns the number of mappings currently in table.
 37.2211 -         */
 37.2212 -        int size() {
 37.2213 -            return size;
 37.2214 -        }
 37.2215 -
 37.2216 -        /**
 37.2217 -         * Inserts mapping object -> handle mapping into table.  Assumes table
 37.2218 -         * is large enough to accommodate new mapping.
 37.2219 -         */
 37.2220 -        private void insert(Object obj, int handle) {
 37.2221 -            int index = hash(obj) % spine.length;
 37.2222 -            objs[handle] = obj;
 37.2223 -            next[handle] = spine[index];
 37.2224 -            spine[index] = handle;
 37.2225 -        }
 37.2226 -
 37.2227 -        /**
 37.2228 -         * Expands the hash "spine" -- equivalent to increasing the number of
 37.2229 -         * buckets in a conventional hash table.
 37.2230 -         */
 37.2231 -        private void growSpine() {
 37.2232 -            spine = new int[(spine.length << 1) + 1];
 37.2233 -            threshold = (int) (spine.length * loadFactor);
 37.2234 -            Arrays.fill(spine, -1);
 37.2235 -            for (int i = 0; i < size; i++) {
 37.2236 -                insert(objs[i], i);
 37.2237 -            }
 37.2238 -        }
 37.2239 -
 37.2240 -        /**
 37.2241 -         * Increases hash table capacity by lengthening entry arrays.
 37.2242 -         */
 37.2243 -        private void growEntries() {
 37.2244 -            int newLength = (next.length << 1) + 1;
 37.2245 -            int[] newNext = new int[newLength];
 37.2246 -            System.arraycopy(next, 0, newNext, 0, size);
 37.2247 -            next = newNext;
 37.2248 -
 37.2249 -            Object[] newObjs = new Object[newLength];
 37.2250 -            System.arraycopy(objs, 0, newObjs, 0, size);
 37.2251 -            objs = newObjs;
 37.2252 -        }
 37.2253 -
 37.2254 -        /**
 37.2255 -         * Returns hash value for given object.
 37.2256 -         */
 37.2257 -        private int hash(Object obj) {
 37.2258 -            return System.identityHashCode(obj) & 0x7FFFFFFF;
 37.2259 -        }
 37.2260 -    }
 37.2261 -
 37.2262 -    /**
 37.2263 -     * Lightweight identity hash table which maps objects to replacement
 37.2264 -     * objects.
 37.2265 -     */
 37.2266 -    private static class ReplaceTable {
 37.2267 -
 37.2268 -        /* maps object -> index */
 37.2269 -        private final HandleTable htab;
 37.2270 -        /* maps index -> replacement object */
 37.2271 -        private Object[] reps;
 37.2272 -
 37.2273 -        /**
 37.2274 -         * Creates new ReplaceTable with given capacity and load factor.
 37.2275 -         */
 37.2276 -        ReplaceTable(int initialCapacity, float loadFactor) {
 37.2277 -            htab = new HandleTable(initialCapacity, loadFactor);
 37.2278 -            reps = new Object[initialCapacity];
 37.2279 -        }
 37.2280 -
 37.2281 -        /**
 37.2282 -         * Enters mapping from object to replacement object.
 37.2283 -         */
 37.2284 -        void assign(Object obj, Object rep) {
 37.2285 -            int index = htab.assign(obj);
 37.2286 -            while (index >= reps.length) {
 37.2287 -                grow();
 37.2288 -            }
 37.2289 -            reps[index] = rep;
 37.2290 -        }
 37.2291 -
 37.2292 -        /**
 37.2293 -         * Looks up and returns replacement for given object.  If no
 37.2294 -         * replacement is found, returns the lookup object itself.
 37.2295 -         */
 37.2296 -        Object lookup(Object obj) {
 37.2297 -            int index = htab.lookup(obj);
 37.2298 -            return (index >= 0) ? reps[index] : obj;
 37.2299 -        }
 37.2300 -
 37.2301 -        /**
 37.2302 -         * Resets table to its initial (empty) state.
 37.2303 -         */
 37.2304 -        void clear() {
 37.2305 -            Arrays.fill(reps, 0, htab.size(), null);
 37.2306 -            htab.clear();
 37.2307 -        }
 37.2308 -
 37.2309 -        /**
 37.2310 -         * Returns the number of mappings currently in table.
 37.2311 -         */
 37.2312 -        int size() {
 37.2313 -            return htab.size();
 37.2314 -        }
 37.2315 -
 37.2316 -        /**
 37.2317 -         * Increases table capacity.
 37.2318 -         */
 37.2319 -        private void grow() {
 37.2320 -            Object[] newReps = new Object[(reps.length << 1) + 1];
 37.2321 -            System.arraycopy(reps, 0, newReps, 0, reps.length);
 37.2322 -            reps = newReps;
 37.2323 -        }
 37.2324 -    }
 37.2325 -
 37.2326 -    /**
 37.2327 -     * Stack to keep debug information about the state of the
 37.2328 -     * serialization process, for embedding in exception messages.
 37.2329 -     */
 37.2330 -    private static class DebugTraceInfoStack {
 37.2331 -        private final List<String> stack;
 37.2332 -
 37.2333 -        DebugTraceInfoStack() {
 37.2334 -            stack = new ArrayList<>();
 37.2335 -        }
 37.2336 -
 37.2337 -        /**
 37.2338 -         * Removes all of the elements from enclosed list.
 37.2339 -         */
 37.2340 -        void clear() {
 37.2341 -            stack.clear();
 37.2342 -        }
 37.2343 -
 37.2344 -        /**
 37.2345 -         * Removes the object at the top of enclosed list.
 37.2346 -         */
 37.2347 -        void pop() {
 37.2348 -            stack.remove(stack.size()-1);
 37.2349 -        }
 37.2350 -
 37.2351 -        /**
 37.2352 -         * Pushes a String onto the top of enclosed list.
 37.2353 -         */
 37.2354 -        void push(String entry) {
 37.2355 -            stack.add("\t- " + entry);
 37.2356 -        }
 37.2357 -
 37.2358 -        /**
 37.2359 -         * Returns a string representation of this object
 37.2360 -         */
 37.2361 -        public String toString() {
 37.2362 -            StringBuilder buffer = new StringBuilder();
 37.2363 -            if (!stack.isEmpty()) {
 37.2364 -                for(int i = stack.size(); i > 0; i-- ) {
 37.2365 -                    buffer.append(stack.get(i-1) + ((i != 1) ? "\n" : ""));
 37.2366 -                }
 37.2367 -            }
 37.2368 -            return buffer.toString();
 37.2369 -        }
 37.2370 -    }
 37.2371 -
 37.2372 -}
    38.1 --- a/emul/compact/src/main/java/java/io/ObjectStreamClass.java	Mon Feb 25 19:00:08 2013 +0100
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,1396 +0,0 @@
    38.4 -/*
    38.5 - * Copyright (c) 1996, 2011, 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.io;
   38.30 -
   38.31 -import java.lang.ref.Reference;
   38.32 -import java.lang.ref.ReferenceQueue;
   38.33 -import java.lang.ref.SoftReference;
   38.34 -import java.lang.ref.WeakReference;
   38.35 -import java.lang.reflect.Constructor;
   38.36 -import java.lang.reflect.Field;
   38.37 -import java.lang.reflect.InvocationTargetException;
   38.38 -import java.lang.reflect.Member;
   38.39 -import java.lang.reflect.Method;
   38.40 -import java.lang.reflect.Modifier;
   38.41 -import java.lang.reflect.Proxy;
   38.42 -import java.util.ArrayList;
   38.43 -import java.util.Arrays;
   38.44 -import java.util.Collections;
   38.45 -import java.util.Comparator;
   38.46 -import java.util.HashSet;
   38.47 -import java.util.Set;
   38.48 -
   38.49 -/**
   38.50 - * Serialization's descriptor for classes.  It contains the name and
   38.51 - * serialVersionUID of the class.  The ObjectStreamClass for a specific class
   38.52 - * loaded in this Java VM can be found/created using the lookup method.
   38.53 - *
   38.54 - * <p>The algorithm to compute the SerialVersionUID is described in
   38.55 - * <a href="../../../platform/serialization/spec/class.html#4100">Object
   38.56 - * Serialization Specification, Section 4.6, Stream Unique Identifiers</a>.
   38.57 - *
   38.58 - * @author      Mike Warres
   38.59 - * @author      Roger Riggs
   38.60 - * @see ObjectStreamField
   38.61 - * @see <a href="../../../platform/serialization/spec/class.html">Object Serialization Specification, Section 4, Class Descriptors</a>
   38.62 - * @since   JDK1.1
   38.63 - */
   38.64 -public class ObjectStreamClass implements Serializable {
   38.65 -
   38.66 -    /** serialPersistentFields value indicating no serializable fields */
   38.67 -    public static final ObjectStreamField[] NO_FIELDS =
   38.68 -        new ObjectStreamField[0];
   38.69 -
   38.70 -    private static final long serialVersionUID = -6120832682080437368L;
   38.71 -    private static final ObjectStreamField[] serialPersistentFields =
   38.72 -        NO_FIELDS;
   38.73 -
   38.74 -
   38.75 -    /** class associated with this descriptor (if any) */
   38.76 -    private Class<?> cl;
   38.77 -    /** name of class represented by this descriptor */
   38.78 -    private String name;
   38.79 -    /** serialVersionUID of represented class (null if not computed yet) */
   38.80 -    private volatile Long suid;
   38.81 -
   38.82 -    /** true if represents dynamic proxy class */
   38.83 -    private boolean isProxy;
   38.84 -    /** true if represents enum type */
   38.85 -    private boolean isEnum;
   38.86 -    /** true if represented class implements Serializable */
   38.87 -    private boolean serializable;
   38.88 -    /** true if represented class implements Externalizable */
   38.89 -    private boolean externalizable;
   38.90 -    /** true if desc has data written by class-defined writeObject method */
   38.91 -    private boolean hasWriteObjectData;
   38.92 -    /**
   38.93 -     * true if desc has externalizable data written in block data format; this
   38.94 -     * must be true by default to accommodate ObjectInputStream subclasses which
   38.95 -     * override readClassDescriptor() to return class descriptors obtained from
   38.96 -     * ObjectStreamClass.lookup() (see 4461737)
   38.97 -     */
   38.98 -    private boolean hasBlockExternalData = true;
   38.99 -
  38.100 -    /** exception (if any) thrown while attempting to resolve class */
  38.101 -    private ClassNotFoundException resolveEx;
  38.102 -    /** exception (if any) to throw if non-enum deserialization attempted */
  38.103 -    private InvalidClassException deserializeEx;
  38.104 -    /** exception (if any) to throw if non-enum serialization attempted */
  38.105 -    private InvalidClassException serializeEx;
  38.106 -    /** exception (if any) to throw if default serialization attempted */
  38.107 -    private InvalidClassException defaultSerializeEx;
  38.108 -
  38.109 -    /** serializable fields */
  38.110 -    private ObjectStreamField[] fields;
  38.111 -    /** aggregate marshalled size of primitive fields */
  38.112 -    private int primDataSize;
  38.113 -    /** number of non-primitive fields */
  38.114 -    private int numObjFields;
  38.115 -    /** reflector for setting/getting serializable field values */
  38.116 -//    private FieldReflector fieldRefl;
  38.117 -    /** data layout of serialized objects described by this class desc */
  38.118 -    private volatile ClassDataSlot[] dataLayout;
  38.119 -
  38.120 -    /** serialization-appropriate constructor, or null if none */
  38.121 -    private Constructor cons;
  38.122 -    /** class-defined writeObject method, or null if none */
  38.123 -    private Method writeObjectMethod;
  38.124 -    /** class-defined readObject method, or null if none */
  38.125 -    private Method readObjectMethod;
  38.126 -    /** class-defined readObjectNoData method, or null if none */
  38.127 -    private Method readObjectNoDataMethod;
  38.128 -    /** class-defined writeReplace method, or null if none */
  38.129 -    private Method writeReplaceMethod;
  38.130 -    /** class-defined readResolve method, or null if none */
  38.131 -    private Method readResolveMethod;
  38.132 -
  38.133 -    /** local class descriptor for represented class (may point to self) */
  38.134 -    private ObjectStreamClass localDesc;
  38.135 -    /** superclass descriptor appearing in stream */
  38.136 -    private ObjectStreamClass superDesc;
  38.137 -
  38.138 -    /**
  38.139 -     * Initializes native code.
  38.140 -     */
  38.141 -    private static native void initNative();
  38.142 -    static {
  38.143 -        initNative();
  38.144 -    }
  38.145 -
  38.146 -    /**
  38.147 -     * Find the descriptor for a class that can be serialized.  Creates an
  38.148 -     * ObjectStreamClass instance if one does not exist yet for class. Null is
  38.149 -     * returned if the specified class does not implement java.io.Serializable
  38.150 -     * or java.io.Externalizable.
  38.151 -     *
  38.152 -     * @param   cl class for which to get the descriptor
  38.153 -     * @return  the class descriptor for the specified class
  38.154 -     */
  38.155 -    public static ObjectStreamClass lookup(Class<?> cl) {
  38.156 -        return lookup(cl, false);
  38.157 -    }
  38.158 -
  38.159 -    /**
  38.160 -     * Returns the descriptor for any class, regardless of whether it
  38.161 -     * implements {@link Serializable}.
  38.162 -     *
  38.163 -     * @param        cl class for which to get the descriptor
  38.164 -     * @return       the class descriptor for the specified class
  38.165 -     * @since 1.6
  38.166 -     */
  38.167 -    public static ObjectStreamClass lookupAny(Class<?> cl) {
  38.168 -        return lookup(cl, true);
  38.169 -    }
  38.170 -
  38.171 -    /**
  38.172 -     * Returns the name of the class described by this descriptor.
  38.173 -     * This method returns the name of the class in the format that
  38.174 -     * is used by the {@link Class#getName} method.
  38.175 -     *
  38.176 -     * @return a string representing the name of the class
  38.177 -     */
  38.178 -    public String getName() {
  38.179 -        return name;
  38.180 -    }
  38.181 -
  38.182 -    /**
  38.183 -     * Return the serialVersionUID for this class.  The serialVersionUID
  38.184 -     * defines a set of classes all with the same name that have evolved from a
  38.185 -     * common root class and agree to be serialized and deserialized using a
  38.186 -     * common format.  NonSerializable classes have a serialVersionUID of 0L.
  38.187 -     *
  38.188 -     * @return  the SUID of the class described by this descriptor
  38.189 -     */
  38.190 -    public long getSerialVersionUID() {
  38.191 -        // REMIND: synchronize instead of relying on volatile?
  38.192 -        if (suid == null) {
  38.193 -            return computeDefaultSUID(cl);
  38.194 -        }
  38.195 -        return suid.longValue();
  38.196 -    }
  38.197 -
  38.198 -    /**
  38.199 -     * Return the class in the local VM that this version is mapped to.  Null
  38.200 -     * is returned if there is no corresponding local class.
  38.201 -     *
  38.202 -     * @return  the <code>Class</code> instance that this descriptor represents
  38.203 -     */
  38.204 -    public Class<?> forClass() {
  38.205 -        return cl;
  38.206 -    }
  38.207 -
  38.208 -    /**
  38.209 -     * Return an array of the fields of this serializable class.
  38.210 -     *
  38.211 -     * @return  an array containing an element for each persistent field of
  38.212 -     *          this class. Returns an array of length zero if there are no
  38.213 -     *          fields.
  38.214 -     * @since 1.2
  38.215 -     */
  38.216 -    public ObjectStreamField[] getFields() {
  38.217 -        return getFields(true);
  38.218 -    }
  38.219 -
  38.220 -    /**
  38.221 -     * Get the field of this class by name.
  38.222 -     *
  38.223 -     * @param   name the name of the data field to look for
  38.224 -     * @return  The ObjectStreamField object of the named field or null if
  38.225 -     *          there is no such named field.
  38.226 -     */
  38.227 -    public ObjectStreamField getField(String name) {
  38.228 -        return getField(name, null);
  38.229 -    }
  38.230 -
  38.231 -    /**
  38.232 -     * Return a string describing this ObjectStreamClass.
  38.233 -     */
  38.234 -    public String toString() {
  38.235 -        return name + ": static final long serialVersionUID = " +
  38.236 -            getSerialVersionUID() + "L;";
  38.237 -    }
  38.238 -
  38.239 -    /**
  38.240 -     * Looks up and returns class descriptor for given class, or null if class
  38.241 -     * is non-serializable and "all" is set to false.
  38.242 -     *
  38.243 -     * @param   cl class to look up
  38.244 -     * @param   all if true, return descriptors for all classes; if false, only
  38.245 -     *          return descriptors for serializable classes
  38.246 -     */
  38.247 -    static ObjectStreamClass lookup(Class<?> cl, boolean all) {
  38.248 -        if (!(all || Serializable.class.isAssignableFrom(cl))) {
  38.249 -            return null;
  38.250 -        }
  38.251 -        Object entry = null;
  38.252 -        EntryFuture future = null;
  38.253 -        if (entry == null) {
  38.254 -            EntryFuture newEntry = new EntryFuture();
  38.255 -            Reference<?> newRef = new SoftReference<>(newEntry);
  38.256 -            if (entry == null) {
  38.257 -                future = newEntry;
  38.258 -            }
  38.259 -        }
  38.260 -
  38.261 -        if (entry instanceof ObjectStreamClass) {  // check common case first
  38.262 -            return (ObjectStreamClass) entry;
  38.263 -        }
  38.264 -        if (entry instanceof EntryFuture) {
  38.265 -            future = (EntryFuture) entry;
  38.266 -            if (true) {
  38.267 -                /*
  38.268 -                 * Handle nested call situation described by 4803747: waiting
  38.269 -                 * for future value to be set by a lookup() call further up the
  38.270 -                 * stack will result in deadlock, so calculate and set the
  38.271 -                 * future value here instead.
  38.272 -                 */
  38.273 -                entry = null;
  38.274 -            } else {
  38.275 -                entry = future.get();
  38.276 -            }
  38.277 -        }
  38.278 -        if (entry == null) {
  38.279 -            try {
  38.280 -                entry = new ObjectStreamClass(cl);
  38.281 -            } catch (Throwable th) {
  38.282 -                entry = th;
  38.283 -            }
  38.284 -            // nested lookup call already set future
  38.285 -            entry = future.get();
  38.286 -        }
  38.287 -
  38.288 -        if (entry instanceof ObjectStreamClass) {
  38.289 -            return (ObjectStreamClass) entry;
  38.290 -        } else if (entry instanceof RuntimeException) {
  38.291 -            throw (RuntimeException) entry;
  38.292 -        } else if (entry instanceof Error) {
  38.293 -            throw (Error) entry;
  38.294 -        } else {
  38.295 -            throw new InternalError("unexpected entry: " + entry);
  38.296 -        }
  38.297 -    }
  38.298 -
  38.299 -    /**
  38.300 -     * Placeholder used in class descriptor and field reflector lookup tables
  38.301 -     * for an entry in the process of being initialized.  (Internal) callers
  38.302 -     * which receive an EntryFuture belonging to another thread as the result
  38.303 -     * of a lookup should call the get() method of the EntryFuture; this will
  38.304 -     * return the actual entry once it is ready for use and has been set().  To
  38.305 -     * conserve objects, EntryFutures synchronize on themselves.
  38.306 -     */
  38.307 -    private static class EntryFuture {
  38.308 -
  38.309 -        private static final Object unset = new Object();
  38.310 -        private Object entry = unset;
  38.311 -
  38.312 -        /**
  38.313 -         * Attempts to set the value contained by this EntryFuture.  If the
  38.314 -         * EntryFuture's value has not been set already, then the value is
  38.315 -         * saved, any callers blocked in the get() method are notified, and
  38.316 -         * true is returned.  If the value has already been set, then no saving
  38.317 -         * or notification occurs, and false is returned.
  38.318 -         */
  38.319 -        synchronized boolean set(Object entry) {
  38.320 -            if (this.entry != unset) {
  38.321 -                return false;
  38.322 -            }
  38.323 -            this.entry = entry;
  38.324 -            notifyAll();
  38.325 -            return true;
  38.326 -        }
  38.327 -
  38.328 -        /**
  38.329 -         * Returns the value contained by this EntryFuture, blocking if
  38.330 -         * necessary until a value is set.
  38.331 -         */
  38.332 -        synchronized Object get() {
  38.333 -            boolean interrupted = false;
  38.334 -            while (entry == unset) {
  38.335 -                try {
  38.336 -                    wait();
  38.337 -                } catch (InterruptedException ex) {
  38.338 -                    interrupted = true;
  38.339 -                }
  38.340 -            }
  38.341 -            return entry;
  38.342 -        }
  38.343 -    }
  38.344 -
  38.345 -    /**
  38.346 -     * Creates local class descriptor representing given class.
  38.347 -     */
  38.348 -    private ObjectStreamClass(final Class<?> cl) {
  38.349 -        this.cl = cl;
  38.350 -        name = cl.getName();
  38.351 -        isProxy = Proxy.isProxyClass(cl);
  38.352 -        isEnum = Enum.class.isAssignableFrom(cl);
  38.353 -        serializable = Serializable.class.isAssignableFrom(cl);
  38.354 -        externalizable = Externalizable.class.isAssignableFrom(cl);
  38.355 -
  38.356 -        Class<?> superCl = cl.getSuperclass();
  38.357 -        superDesc = (superCl != null) ? lookup(superCl, false) : null;
  38.358 -        localDesc = this;
  38.359 -
  38.360 -        suid = Long.valueOf(0);
  38.361 -        fields = NO_FIELDS;
  38.362 -
  38.363 -
  38.364 -        if (deserializeEx == null) {
  38.365 -            if (isEnum) {
  38.366 -                deserializeEx = new InvalidClassException(name, "enum type");
  38.367 -            } else if (cons == null) {
  38.368 -                deserializeEx = new InvalidClassException(
  38.369 -                    name, "no valid constructor");
  38.370 -            }
  38.371 -        }
  38.372 -        for (int i = 0; i < fields.length; i++) {
  38.373 -            if (fields[i].getField() == null) {
  38.374 -                defaultSerializeEx = new InvalidClassException(
  38.375 -                    name, "unmatched serializable field(s) declared");
  38.376 -            }
  38.377 -        }
  38.378 -    }
  38.379 -
  38.380 -    /**
  38.381 -     * Creates blank class descriptor which should be initialized via a
  38.382 -     * subsequent call to initProxy(), initNonProxy() or readNonProxy().
  38.383 -     */
  38.384 -    ObjectStreamClass() {
  38.385 -    }
  38.386 -
  38.387 -    /**
  38.388 -     * Initializes class descriptor representing a proxy class.
  38.389 -     */
  38.390 -    void initProxy(Class<?> cl,
  38.391 -                   ClassNotFoundException resolveEx,
  38.392 -                   ObjectStreamClass superDesc)
  38.393 -        throws InvalidClassException
  38.394 -    {
  38.395 -        this.cl = cl;
  38.396 -        this.resolveEx = resolveEx;
  38.397 -        this.superDesc = superDesc;
  38.398 -        isProxy = true;
  38.399 -        serializable = true;
  38.400 -        suid = Long.valueOf(0);
  38.401 -        fields = NO_FIELDS;
  38.402 -
  38.403 -        if (cl != null) {
  38.404 -            localDesc = lookup(cl, true);
  38.405 -            if (!localDesc.isProxy) {
  38.406 -                throw new InvalidClassException(
  38.407 -                    "cannot bind proxy descriptor to a non-proxy class");
  38.408 -            }
  38.409 -            name = localDesc.name;
  38.410 -            externalizable = localDesc.externalizable;
  38.411 -            cons = localDesc.cons;
  38.412 -            writeReplaceMethod = localDesc.writeReplaceMethod;
  38.413 -            readResolveMethod = localDesc.readResolveMethod;
  38.414 -            deserializeEx = localDesc.deserializeEx;
  38.415 -        }
  38.416 -    }
  38.417 -
  38.418 -    /**
  38.419 -     * Initializes class descriptor representing a non-proxy class.
  38.420 -     */
  38.421 -    void initNonProxy(ObjectStreamClass model,
  38.422 -                      Class<?> cl,
  38.423 -                      ClassNotFoundException resolveEx,
  38.424 -                      ObjectStreamClass superDesc)
  38.425 -        throws InvalidClassException
  38.426 -    {
  38.427 -        this.cl = cl;
  38.428 -        this.resolveEx = resolveEx;
  38.429 -        this.superDesc = superDesc;
  38.430 -        name = model.name;
  38.431 -        suid = Long.valueOf(model.getSerialVersionUID());
  38.432 -        isProxy = false;
  38.433 -        isEnum = model.isEnum;
  38.434 -        serializable = model.serializable;
  38.435 -        externalizable = model.externalizable;
  38.436 -        hasBlockExternalData = model.hasBlockExternalData;
  38.437 -        hasWriteObjectData = model.hasWriteObjectData;
  38.438 -        fields = model.fields;
  38.439 -        primDataSize = model.primDataSize;
  38.440 -        numObjFields = model.numObjFields;
  38.441 -
  38.442 -        if (cl != null) {
  38.443 -            localDesc = lookup(cl, true);
  38.444 -            if (localDesc.isProxy) {
  38.445 -                throw new InvalidClassException(
  38.446 -                    "cannot bind non-proxy descriptor to a proxy class");
  38.447 -            }
  38.448 -            if (isEnum != localDesc.isEnum) {
  38.449 -                throw new InvalidClassException(isEnum ?
  38.450 -                    "cannot bind enum descriptor to a non-enum class" :
  38.451 -                    "cannot bind non-enum descriptor to an enum class");
  38.452 -            }
  38.453 -
  38.454 -            if (serializable == localDesc.serializable &&
  38.455 -                !cl.isArray() &&
  38.456 -                suid.longValue() != localDesc.getSerialVersionUID())
  38.457 -            {
  38.458 -                throw new InvalidClassException(localDesc.name,
  38.459 -                    "local class incompatible: " +
  38.460 -                    "stream classdesc serialVersionUID = " + suid +
  38.461 -                    ", local class serialVersionUID = " +
  38.462 -                    localDesc.getSerialVersionUID());
  38.463 -            }
  38.464 -
  38.465 -            if (!classNamesEqual(name, localDesc.name)) {
  38.466 -                throw new InvalidClassException(localDesc.name,
  38.467 -                    "local class name incompatible with stream class " +
  38.468 -                    "name \"" + name + "\"");
  38.469 -            }
  38.470 -
  38.471 -            if (!isEnum) {
  38.472 -                if ((serializable == localDesc.serializable) &&
  38.473 -                    (externalizable != localDesc.externalizable))
  38.474 -                {
  38.475 -                    throw new InvalidClassException(localDesc.name,
  38.476 -                        "Serializable incompatible with Externalizable");
  38.477 -                }
  38.478 -
  38.479 -                if ((serializable != localDesc.serializable) ||
  38.480 -                    (externalizable != localDesc.externalizable) ||
  38.481 -                    !(serializable || externalizable))
  38.482 -                {
  38.483 -                    deserializeEx = new InvalidClassException(localDesc.name,
  38.484 -                        "class invalid for deserialization");
  38.485 -                }
  38.486 -            }
  38.487 -
  38.488 -            cons = localDesc.cons;
  38.489 -            writeObjectMethod = localDesc.writeObjectMethod;
  38.490 -            readObjectMethod = localDesc.readObjectMethod;
  38.491 -            readObjectNoDataMethod = localDesc.readObjectNoDataMethod;
  38.492 -            writeReplaceMethod = localDesc.writeReplaceMethod;
  38.493 -            readResolveMethod = localDesc.readResolveMethod;
  38.494 -            if (deserializeEx == null) {
  38.495 -                deserializeEx = localDesc.deserializeEx;
  38.496 -            }
  38.497 -        }
  38.498 -        // reassign to matched fields so as to reflect local unshared settings
  38.499 -        fields = null;
  38.500 -    }
  38.501 -
  38.502 -    /**
  38.503 -     * Reads non-proxy class descriptor information from given input stream.
  38.504 -     * The resulting class descriptor is not fully functional; it can only be
  38.505 -     * used as input to the ObjectInputStream.resolveClass() and
  38.506 -     * ObjectStreamClass.initNonProxy() methods.
  38.507 -     */
  38.508 -    void readNonProxy(ObjectInputStream in)
  38.509 -        throws IOException, ClassNotFoundException
  38.510 -    {
  38.511 -        name = in.readUTF();
  38.512 -        suid = Long.valueOf(in.readLong());
  38.513 -        isProxy = false;
  38.514 -
  38.515 -        byte flags = in.readByte();
  38.516 -        hasWriteObjectData =
  38.517 -            ((flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0);
  38.518 -        hasBlockExternalData =
  38.519 -            ((flags & ObjectStreamConstants.SC_BLOCK_DATA) != 0);
  38.520 -        externalizable =
  38.521 -            ((flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0);
  38.522 -        boolean sflag =
  38.523 -            ((flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0);
  38.524 -        if (externalizable && sflag) {
  38.525 -            throw new InvalidClassException(
  38.526 -                name, "serializable and externalizable flags conflict");
  38.527 -        }
  38.528 -        serializable = externalizable || sflag;
  38.529 -        isEnum = ((flags & ObjectStreamConstants.SC_ENUM) != 0);
  38.530 -        if (isEnum && suid.longValue() != 0L) {
  38.531 -            throw new InvalidClassException(name,
  38.532 -                "enum descriptor has non-zero serialVersionUID: " + suid);
  38.533 -        }
  38.534 -
  38.535 -        int numFields = in.readShort();
  38.536 -        if (isEnum && numFields != 0) {
  38.537 -            throw new InvalidClassException(name,
  38.538 -                "enum descriptor has non-zero field count: " + numFields);
  38.539 -        }
  38.540 -        fields = (numFields > 0) ?
  38.541 -            new ObjectStreamField[numFields] : NO_FIELDS;
  38.542 -        for (int i = 0; i < numFields; i++) {
  38.543 -            char tcode = (char) in.readByte();
  38.544 -            String fname = in.readUTF();
  38.545 -            String signature = ((tcode == 'L') || (tcode == '[')) ?
  38.546 -                in.readTypeString() : new String(new char[] { tcode });
  38.547 -            try {
  38.548 -                fields[i] = new ObjectStreamField(fname, signature, false);
  38.549 -            } catch (RuntimeException e) {
  38.550 -                throw (IOException) new InvalidClassException(name,
  38.551 -                    "invalid descriptor for field " + fname).initCause(e);
  38.552 -            }
  38.553 -        }
  38.554 -        computeFieldOffsets();
  38.555 -    }
  38.556 -
  38.557 -    /**
  38.558 -     * Writes non-proxy class descriptor information to given output stream.
  38.559 -     */
  38.560 -    void writeNonProxy(ObjectOutputStream out) throws IOException {
  38.561 -        out.writeUTF(name);
  38.562 -        out.writeLong(getSerialVersionUID());
  38.563 -
  38.564 -        byte flags = 0;
  38.565 -        if (externalizable) {
  38.566 -            flags |= ObjectStreamConstants.SC_EXTERNALIZABLE;
  38.567 -            int protocol = out.getProtocolVersion();
  38.568 -            if (protocol != ObjectStreamConstants.PROTOCOL_VERSION_1) {
  38.569 -                flags |= ObjectStreamConstants.SC_BLOCK_DATA;
  38.570 -            }
  38.571 -        } else if (serializable) {
  38.572 -            flags |= ObjectStreamConstants.SC_SERIALIZABLE;
  38.573 -        }
  38.574 -        if (hasWriteObjectData) {
  38.575 -            flags |= ObjectStreamConstants.SC_WRITE_METHOD;
  38.576 -        }
  38.577 -        if (isEnum) {
  38.578 -            flags |= ObjectStreamConstants.SC_ENUM;
  38.579 -        }
  38.580 -        out.writeByte(flags);
  38.581 -
  38.582 -        out.writeShort(fields.length);
  38.583 -        for (int i = 0; i < fields.length; i++) {
  38.584 -            ObjectStreamField f = fields[i];
  38.585 -            out.writeByte(f.getTypeCode());
  38.586 -            out.writeUTF(f.getName());
  38.587 -            if (!f.isPrimitive()) {
  38.588 -                out.writeTypeString(f.getTypeString());
  38.589 -            }
  38.590 -        }
  38.591 -    }
  38.592 -
  38.593 -    /**
  38.594 -     * Returns ClassNotFoundException (if any) thrown while attempting to
  38.595 -     * resolve local class corresponding to this class descriptor.
  38.596 -     */
  38.597 -    ClassNotFoundException getResolveException() {
  38.598 -        return resolveEx;
  38.599 -    }
  38.600 -
  38.601 -    /**
  38.602 -     * Throws an InvalidClassException if object instances referencing this
  38.603 -     * class descriptor should not be allowed to deserialize.  This method does
  38.604 -     * not apply to deserialization of enum constants.
  38.605 -     */
  38.606 -    void checkDeserialize() throws InvalidClassException {
  38.607 -        if (deserializeEx != null) {
  38.608 -            InvalidClassException ice =
  38.609 -                new InvalidClassException(deserializeEx.classname,
  38.610 -                                          deserializeEx.getMessage());
  38.611 -            ice.initCause(deserializeEx);
  38.612 -            throw ice;
  38.613 -        }
  38.614 -    }
  38.615 -
  38.616 -    /**
  38.617 -     * Throws an InvalidClassException if objects whose class is represented by
  38.618 -     * this descriptor should not be allowed to serialize.  This method does
  38.619 -     * not apply to serialization of enum constants.
  38.620 -     */
  38.621 -    void checkSerialize() throws InvalidClassException {
  38.622 -        if (serializeEx != null) {
  38.623 -            InvalidClassException ice =
  38.624 -                new InvalidClassException(serializeEx.classname,
  38.625 -                                          serializeEx.getMessage());
  38.626 -            ice.initCause(serializeEx);
  38.627 -            throw ice;
  38.628 -        }
  38.629 -    }
  38.630 -
  38.631 -    /**
  38.632 -     * Throws an InvalidClassException if objects whose class is represented by
  38.633 -     * this descriptor should not be permitted to use default serialization
  38.634 -     * (e.g., if the class declares serializable fields that do not correspond
  38.635 -     * to actual fields, and hence must use the GetField API).  This method
  38.636 -     * does not apply to deserialization of enum constants.
  38.637 -     */
  38.638 -    void checkDefaultSerialize() throws InvalidClassException {
  38.639 -        if (defaultSerializeEx != null) {
  38.640 -            InvalidClassException ice =
  38.641 -                new InvalidClassException(defaultSerializeEx.classname,
  38.642 -                                          defaultSerializeEx.getMessage());
  38.643 -            ice.initCause(defaultSerializeEx);
  38.644 -            throw ice;
  38.645 -        }
  38.646 -    }
  38.647 -
  38.648 -    /**
  38.649 -     * Returns superclass descriptor.  Note that on the receiving side, the
  38.650 -     * superclass descriptor may be bound to a class that is not a superclass
  38.651 -     * of the subclass descriptor's bound class.
  38.652 -     */
  38.653 -    ObjectStreamClass getSuperDesc() {
  38.654 -        return superDesc;
  38.655 -    }
  38.656 -
  38.657 -    /**
  38.658 -     * Returns the "local" class descriptor for the class associated with this
  38.659 -     * class descriptor (i.e., the result of
  38.660 -     * ObjectStreamClass.lookup(this.forClass())) or null if there is no class
  38.661 -     * associated with this descriptor.
  38.662 -     */
  38.663 -    ObjectStreamClass getLocalDesc() {
  38.664 -        return localDesc;
  38.665 -    }
  38.666 -
  38.667 -    /**
  38.668 -     * Returns arrays of ObjectStreamFields representing the serializable
  38.669 -     * fields of the represented class.  If copy is true, a clone of this class
  38.670 -     * descriptor's field array is returned, otherwise the array itself is
  38.671 -     * returned.
  38.672 -     */
  38.673 -    ObjectStreamField[] getFields(boolean copy) {
  38.674 -        return copy ? fields.clone() : fields;
  38.675 -    }
  38.676 -
  38.677 -    /**
  38.678 -     * Looks up a serializable field of the represented class by name and type.
  38.679 -     * A specified type of null matches all types, Object.class matches all
  38.680 -     * non-primitive types, and any other non-null type matches assignable
  38.681 -     * types only.  Returns matching field, or null if no match found.
  38.682 -     */
  38.683 -    ObjectStreamField getField(String name, Class<?> type) {
  38.684 -        for (int i = 0; i < fields.length; i++) {
  38.685 -            ObjectStreamField f = fields[i];
  38.686 -            if (f.getName().equals(name)) {
  38.687 -                if (type == null ||
  38.688 -                    (type == Object.class && !f.isPrimitive()))
  38.689 -                {
  38.690 -                    return f;
  38.691 -                }
  38.692 -                Class<?> ftype = f.getType();
  38.693 -                if (ftype != null && type.isAssignableFrom(ftype)) {
  38.694 -                    return f;
  38.695 -                }
  38.696 -            }
  38.697 -        }
  38.698 -        return null;
  38.699 -    }
  38.700 -
  38.701 -    /**
  38.702 -     * Returns true if class descriptor represents a dynamic proxy class, false
  38.703 -     * otherwise.
  38.704 -     */
  38.705 -    boolean isProxy() {
  38.706 -        return isProxy;
  38.707 -    }
  38.708 -
  38.709 -    /**
  38.710 -     * Returns true if class descriptor represents an enum type, false
  38.711 -     * otherwise.
  38.712 -     */
  38.713 -    boolean isEnum() {
  38.714 -        return isEnum;
  38.715 -    }
  38.716 -
  38.717 -    /**
  38.718 -     * Returns true if represented class implements Externalizable, false
  38.719 -     * otherwise.
  38.720 -     */
  38.721 -    boolean isExternalizable() {
  38.722 -        return externalizable;
  38.723 -    }
  38.724 -
  38.725 -    /**
  38.726 -     * Returns true if represented class implements Serializable, false
  38.727 -     * otherwise.
  38.728 -     */
  38.729 -    boolean isSerializable() {
  38.730 -        return serializable;
  38.731 -    }
  38.732 -
  38.733 -    /**
  38.734 -     * Returns true if class descriptor represents externalizable class that
  38.735 -     * has written its data in 1.2 (block data) format, false otherwise.
  38.736 -     */
  38.737 -    boolean hasBlockExternalData() {
  38.738 -        return hasBlockExternalData;
  38.739 -    }
  38.740 -
  38.741 -    /**
  38.742 -     * Returns true if class descriptor represents serializable (but not
  38.743 -     * externalizable) class which has written its data via a custom
  38.744 -     * writeObject() method, false otherwise.
  38.745 -     */
  38.746 -    boolean hasWriteObjectData() {
  38.747 -        return hasWriteObjectData;
  38.748 -    }
  38.749 -
  38.750 -    /**
  38.751 -     * Returns true if represented class is serializable/externalizable and can
  38.752 -     * be instantiated by the serialization runtime--i.e., if it is
  38.753 -     * externalizable and defines a public no-arg constructor, or if it is
  38.754 -     * non-externalizable and its first non-serializable superclass defines an
  38.755 -     * accessible no-arg constructor.  Otherwise, returns false.
  38.756 -     */
  38.757 -    boolean isInstantiable() {
  38.758 -        return (cons != null);
  38.759 -    }
  38.760 -
  38.761 -    /**
  38.762 -     * Returns true if represented class is serializable (but not
  38.763 -     * externalizable) and defines a conformant writeObject method.  Otherwise,
  38.764 -     * returns false.
  38.765 -     */
  38.766 -    boolean hasWriteObjectMethod() {
  38.767 -        return (writeObjectMethod != null);
  38.768 -    }
  38.769 -
  38.770 -    /**
  38.771 -     * Returns true if represented class is serializable (but not
  38.772 -     * externalizable) and defines a conformant readObject method.  Otherwise,
  38.773 -     * returns false.
  38.774 -     */
  38.775 -    boolean hasReadObjectMethod() {
  38.776 -        return (readObjectMethod != null);
  38.777 -    }
  38.778 -
  38.779 -    /**
  38.780 -     * Returns true if represented class is serializable (but not
  38.781 -     * externalizable) and defines a conformant readObjectNoData method.
  38.782 -     * Otherwise, returns false.
  38.783 -     */
  38.784 -    boolean hasReadObjectNoDataMethod() {
  38.785 -        return (readObjectNoDataMethod != null);
  38.786 -    }
  38.787 -
  38.788 -    /**
  38.789 -     * Returns true if represented class is serializable or externalizable and
  38.790 -     * defines a conformant writeReplace method.  Otherwise, returns false.
  38.791 -     */
  38.792 -    boolean hasWriteReplaceMethod() {
  38.793 -        return (writeReplaceMethod != null);
  38.794 -    }
  38.795 -
  38.796 -    /**
  38.797 -     * Returns true if represented class is serializable or externalizable and
  38.798 -     * defines a conformant readResolve method.  Otherwise, returns false.
  38.799 -     */
  38.800 -    boolean hasReadResolveMethod() {
  38.801 -        return (readResolveMethod != null);
  38.802 -    }
  38.803 -
  38.804 -    /**
  38.805 -     * Creates a new instance of the represented class.  If the class is
  38.806 -     * externalizable, invokes its public no-arg constructor; otherwise, if the
  38.807 -     * class is serializable, invokes the no-arg constructor of the first
  38.808 -     * non-serializable superclass.  Throws UnsupportedOperationException if
  38.809 -     * this class descriptor is not associated with a class, if the associated
  38.810 -     * class is non-serializable or if the appropriate no-arg constructor is
  38.811 -     * inaccessible/unavailable.
  38.812 -     */
  38.813 -    Object newInstance()
  38.814 -        throws InstantiationException, InvocationTargetException,
  38.815 -               UnsupportedOperationException
  38.816 -    {
  38.817 -        if (cons != null) {
  38.818 -            try {
  38.819 -                return cons.newInstance();
  38.820 -            } catch (IllegalAccessException ex) {
  38.821 -                // should not occur, as access checks have been suppressed
  38.822 -                throw new InternalError();
  38.823 -            }
  38.824 -        } else {
  38.825 -            throw new UnsupportedOperationException();
  38.826 -        }
  38.827 -    }
  38.828 -
  38.829 -    /**
  38.830 -     * Invokes the writeObject method of the represented serializable class.
  38.831 -     * Throws UnsupportedOperationException if this class descriptor is not
  38.832 -     * associated with a class, or if the class is externalizable,
  38.833 -     * non-serializable or does not define writeObject.
  38.834 -     */
  38.835 -    void invokeWriteObject(Object obj, ObjectOutputStream out)
  38.836 -        throws IOException, UnsupportedOperationException
  38.837 -    {
  38.838 -        if (writeObjectMethod != null) {
  38.839 -            try {
  38.840 -                writeObjectMethod.invoke(obj, new Object[]{ out });
  38.841 -            } catch (InvocationTargetException ex) {
  38.842 -                Throwable th = ex.getTargetException();
  38.843 -                if (th instanceof IOException) {
  38.844 -                    throw (IOException) th;
  38.845 -                } else {
  38.846 -                    throwMiscException(th);
  38.847 -                }
  38.848 -            } catch (IllegalAccessException ex) {
  38.849 -                // should not occur, as access checks have been suppressed
  38.850 -                throw new InternalError();
  38.851 -            }
  38.852 -        } else {
  38.853 -            throw new UnsupportedOperationException();
  38.854 -        }
  38.855 -    }
  38.856 -
  38.857 -    /**
  38.858 -     * Invokes the readObject method of the represented serializable class.
  38.859 -     * Throws UnsupportedOperationException if this class descriptor is not
  38.860 -     * associated with a class, or if the class is externalizable,
  38.861 -     * non-serializable or does not define readObject.
  38.862 -     */
  38.863 -    void invokeReadObject(Object obj, ObjectInputStream in)
  38.864 -        throws ClassNotFoundException, IOException,
  38.865 -               UnsupportedOperationException
  38.866 -    {
  38.867 -        if (readObjectMethod != null) {
  38.868 -            try {
  38.869 -                readObjectMethod.invoke(obj, new Object[]{ in });
  38.870 -            } catch (InvocationTargetException ex) {
  38.871 -                Throwable th = ex.getTargetException();
  38.872 -                if (th instanceof ClassNotFoundException) {
  38.873 -                    throw (ClassNotFoundException) th;
  38.874 -                } else if (th instanceof IOException) {
  38.875 -                    throw (IOException) th;
  38.876 -                } else {
  38.877 -                    throwMiscException(th);
  38.878 -                }
  38.879 -            } catch (IllegalAccessException ex) {
  38.880 -                // should not occur, as access checks have been suppressed
  38.881 -                throw new InternalError();
  38.882 -            }
  38.883 -        } else {
  38.884 -            throw new UnsupportedOperationException();
  38.885 -        }
  38.886 -    }
  38.887 -
  38.888 -    /**
  38.889 -     * Invokes the readObjectNoData method of the represented serializable
  38.890 -     * class.  Throws UnsupportedOperationException if this class descriptor is
  38.891 -     * not associated with a class, or if the class is externalizable,
  38.892 -     * non-serializable or does not define readObjectNoData.
  38.893 -     */
  38.894 -    void invokeReadObjectNoData(Object obj)
  38.895 -        throws IOException, UnsupportedOperationException
  38.896 -    {
  38.897 -        if (readObjectNoDataMethod != null) {
  38.898 -            try {
  38.899 -                readObjectNoDataMethod.invoke(obj, (Object[]) null);
  38.900 -            } catch (InvocationTargetException ex) {
  38.901 -                Throwable th = ex.getTargetException();
  38.902 -                if (th instanceof ObjectStreamException) {
  38.903 -                    throw (ObjectStreamException) th;
  38.904 -                } else {
  38.905 -                    throwMiscException(th);
  38.906 -                }
  38.907 -            } catch (IllegalAccessException ex) {
  38.908 -                // should not occur, as access checks have been suppressed
  38.909 -                throw new InternalError();
  38.910 -            }
  38.911 -        } else {
  38.912 -            throw new UnsupportedOperationException();
  38.913 -        }
  38.914 -    }
  38.915 -
  38.916 -    /**
  38.917 -     * Invokes the writeReplace method of the represented serializable class and
  38.918 -     * returns the result.  Throws UnsupportedOperationException if this class
  38.919 -     * descriptor is not associated with a class, or if the class is
  38.920 -     * non-serializable or does not define writeReplace.
  38.921 -     */
  38.922 -    Object invokeWriteReplace(Object obj)
  38.923 -        throws IOException, UnsupportedOperationException
  38.924 -    {
  38.925 -        if (writeReplaceMethod != null) {
  38.926 -            try {
  38.927 -                return writeReplaceMethod.invoke(obj, (Object[]) null);
  38.928 -            } catch (InvocationTargetException ex) {
  38.929 -                Throwable th = ex.getTargetException();
  38.930 -                if (th instanceof ObjectStreamException) {
  38.931 -                    throw (ObjectStreamException) th;
  38.932 -                } else {
  38.933 -                    throwMiscException(th);
  38.934 -                    throw new InternalError();  // never reached
  38.935 -                }
  38.936 -            } catch (IllegalAccessException ex) {
  38.937 -                // should not occur, as access checks have been suppressed
  38.938 -                throw new InternalError();
  38.939 -            }
  38.940 -        } else {
  38.941 -            throw new UnsupportedOperationException();
  38.942 -        }
  38.943 -    }
  38.944 -
  38.945 -    /**
  38.946 -     * Invokes the readResolve method of the represented serializable class and
  38.947 -     * returns the result.  Throws UnsupportedOperationException if this class
  38.948 -     * descriptor is not associated with a class, or if the class is
  38.949 -     * non-serializable or does not define readResolve.
  38.950 -     */
  38.951 -    Object invokeReadResolve(Object obj)
  38.952 -        throws IOException, UnsupportedOperationException
  38.953 -    {
  38.954 -        if (readResolveMethod != null) {
  38.955 -            try {
  38.956 -                return readResolveMethod.invoke(obj, (Object[]) null);
  38.957 -            } catch (InvocationTargetException ex) {
  38.958 -                Throwable th = ex.getTargetException();
  38.959 -                if (th instanceof ObjectStreamException) {
  38.960 -                    throw (ObjectStreamException) th;
  38.961 -                } else {
  38.962 -                    throwMiscException(th);
  38.963 -                    throw new InternalError();  // never reached
  38.964 -                }
  38.965 -            } catch (IllegalAccessException ex) {
  38.966 -                // should not occur, as access checks have been suppressed
  38.967 -                throw new InternalError();
  38.968 -            }
  38.969 -        } else {
  38.970 -            throw new UnsupportedOperationException();
  38.971 -        }
  38.972 -    }
  38.973 -
  38.974 -    /**
  38.975 -     * Class representing the portion of an object's serialized form allotted
  38.976 -     * to data described by a given class descriptor.  If "hasData" is false,
  38.977 -     * the object's serialized form does not contain data associated with the
  38.978 -     * class descriptor.
  38.979 -     */
  38.980 -    static class ClassDataSlot {
  38.981 -
  38.982 -        /** class descriptor "occupying" this slot */
  38.983 -        final ObjectStreamClass desc;
  38.984 -        /** true if serialized form includes data for this slot's descriptor */
  38.985 -        final boolean hasData;
  38.986 -
  38.987 -        ClassDataSlot(ObjectStreamClass desc, boolean hasData) {
  38.988 -            this.desc = desc;
  38.989 -            this.hasData = hasData;
  38.990 -        }
  38.991 -    }
  38.992 -
  38.993 -    /**
  38.994 -     * Returns array of ClassDataSlot instances representing the data layout
  38.995 -     * (including superclass data) for serialized objects described by this
  38.996 -     * class descriptor.  ClassDataSlots are ordered by inheritance with those
  38.997 -     * containing "higher" superclasses appearing first.  The final
  38.998 -     * ClassDataSlot contains a reference to this descriptor.
  38.999 -     */
 38.1000 -    ClassDataSlot[] getClassDataLayout() throws InvalidClassException {
 38.1001 -        // REMIND: synchronize instead of relying on volatile?
 38.1002 -        if (dataLayout == null) {
 38.1003 -            dataLayout = getClassDataLayout0();
 38.1004 -        }
 38.1005 -        return dataLayout;
 38.1006 -    }
 38.1007 -
 38.1008 -    private ClassDataSlot[] getClassDataLayout0()
 38.1009 -        throws InvalidClassException
 38.1010 -    {
 38.1011 -        ArrayList<ClassDataSlot> slots = new ArrayList<>();
 38.1012 -        Class<?> start = cl, end = cl;
 38.1013 -
 38.1014 -        // locate closest non-serializable superclass
 38.1015 -        while (end != null && Serializable.class.isAssignableFrom(end)) {
 38.1016 -            end = end.getSuperclass();
 38.1017 -        }
 38.1018 -
 38.1019 -        for (ObjectStreamClass d = this; d != null; d = d.superDesc) {
 38.1020 -
 38.1021 -            // search up inheritance hierarchy for class with matching name
 38.1022 -            String searchName = (d.cl != null) ? d.cl.getName() : d.name;
 38.1023 -            Class<?> match = null;
 38.1024 -            for (Class<?> c = start; c != end; c = c.getSuperclass()) {
 38.1025 -                if (searchName.equals(c.getName())) {
 38.1026 -                    match = c;
 38.1027 -                    break;
 38.1028 -                }
 38.1029 -            }
 38.1030 -
 38.1031 -            // add "no data" slot for each unmatched class below match
 38.1032 -            if (match != null) {
 38.1033 -                for (Class<?> c = start; c != match; c = c.getSuperclass()) {
 38.1034 -                    slots.add(new ClassDataSlot(
 38.1035 -                        ObjectStreamClass.lookup(c, true), false));
 38.1036 -                }
 38.1037 -                start = match.getSuperclass();
 38.1038 -            }
 38.1039 -
 38.1040 -            // record descriptor/class pairing
 38.1041 -            slots.add(new ClassDataSlot(d.getVariantFor(match), true));
 38.1042 -        }
 38.1043 -
 38.1044 -        // add "no data" slot for any leftover unmatched classes
 38.1045 -        for (Class<?> c = start; c != end; c = c.getSuperclass()) {
 38.1046 -            slots.add(new ClassDataSlot(
 38.1047 -                ObjectStreamClass.lookup(c, true), false));
 38.1048 -        }
 38.1049 -
 38.1050 -        // order slots from superclass -> subclass
 38.1051 -        Collections.reverse(slots);
 38.1052 -        return slots.toArray(new ClassDataSlot[slots.size()]);
 38.1053 -    }
 38.1054 -
 38.1055 -    /**
 38.1056 -     * Returns aggregate size (in bytes) of marshalled primitive field values
 38.1057 -     * for represented class.
 38.1058 -     */
 38.1059 -    int getPrimDataSize() {
 38.1060 -        return primDataSize;
 38.1061 -    }
 38.1062 -
 38.1063 -    /**
 38.1064 -     * Returns number of non-primitive serializable fields of represented
 38.1065 -     * class.
 38.1066 -     */
 38.1067 -    int getNumObjFields() {
 38.1068 -        return numObjFields;
 38.1069 -    }
 38.1070 -
 38.1071 -    /**
 38.1072 -     * Fetches the serializable primitive field values of object obj and
 38.1073 -     * marshals them into byte array buf starting at offset 0.  It is the
 38.1074 -     * responsibility of the caller to ensure that obj is of the proper type if
 38.1075 -     * non-null.
 38.1076 -     */
 38.1077 -    void getPrimFieldValues(Object obj, byte[] buf) {
 38.1078 -    }
 38.1079 -
 38.1080 -    /**
 38.1081 -     * Sets the serializable primitive fields of object obj using values
 38.1082 -     * unmarshalled from byte array buf starting at offset 0.  It is the
 38.1083 -     * responsibility of the caller to ensure that obj is of the proper type if
 38.1084 -     * non-null.
 38.1085 -     */
 38.1086 -    void setPrimFieldValues(Object obj, byte[] buf) {
 38.1087 -    }
 38.1088 -
 38.1089 -    /**
 38.1090 -     * Fetches the serializable object field values of object obj and stores
 38.1091 -     * them in array vals starting at offset 0.  It is the responsibility of
 38.1092 -     * the caller to ensure that obj is of the proper type if non-null.
 38.1093 -     */
 38.1094 -    void getObjFieldValues(Object obj, Object[] vals) {
 38.1095 -    }
 38.1096 -
 38.1097 -    /**
 38.1098 -     * Sets the serializable object fields of object obj using values from
 38.1099 -     * array vals starting at offset 0.  It is the responsibility of the caller
 38.1100 -     * to ensure that obj is of the proper type if non-null.
 38.1101 -     */
 38.1102 -    void setObjFieldValues(Object obj, Object[] vals) {
 38.1103 -    }
 38.1104 -
 38.1105 -    /**
 38.1106 -     * Calculates and sets serializable field offsets, as well as primitive
 38.1107 -     * data size and object field count totals.  Throws InvalidClassException
 38.1108 -     * if fields are illegally ordered.
 38.1109 -     */
 38.1110 -    private void computeFieldOffsets() throws InvalidClassException {
 38.1111 -        primDataSize = 0;
 38.1112 -        numObjFields = 0;
 38.1113 -        int firstObjIndex = -1;
 38.1114 -
 38.1115 -        for (int i = 0; i < fields.length; i++) {
 38.1116 -            ObjectStreamField f = fields[i];
 38.1117 -            switch (f.getTypeCode()) {
 38.1118 -                case 'Z':
 38.1119 -                case 'B':
 38.1120 -                    f.setOffset(primDataSize++);
 38.1121 -                    break;
 38.1122 -
 38.1123 -                case 'C':
 38.1124 -                case 'S':
 38.1125 -                    f.setOffset(primDataSize);
 38.1126 -                    primDataSize += 2;
 38.1127 -                    break;
 38.1128 -
 38.1129 -                case 'I':
 38.1130 -                case 'F':
 38.1131 -                    f.setOffset(primDataSize);
 38.1132 -                    primDataSize += 4;
 38.1133 -                    break;
 38.1134 -
 38.1135 -                case 'J':
 38.1136 -                case 'D':
 38.1137 -                    f.setOffset(primDataSize);
 38.1138 -                    primDataSize += 8;
 38.1139 -                    break;
 38.1140 -
 38.1141 -                case '[':
 38.1142 -                case 'L':
 38.1143 -                    f.setOffset(numObjFields++);
 38.1144 -                    if (firstObjIndex == -1) {
 38.1145 -                        firstObjIndex = i;
 38.1146 -                    }
 38.1147 -                    break;
 38.1148 -
 38.1149 -                default:
 38.1150 -                    throw new InternalError();
 38.1151 -            }
 38.1152 -        }
 38.1153 -        if (firstObjIndex != -1 &&
 38.1154 -            firstObjIndex + numObjFields != fields.length)
 38.1155 -        {
 38.1156 -            throw new InvalidClassException(name, "illegal field order");
 38.1157 -        }
 38.1158 -    }
 38.1159 -
 38.1160 -    /**
 38.1161 -     * If given class is the same as the class associated with this class
 38.1162 -     * descriptor, returns reference to this class descriptor.  Otherwise,
 38.1163 -     * returns variant of this class descriptor bound to given class.
 38.1164 -     */
 38.1165 -    private ObjectStreamClass getVariantFor(Class<?> cl)
 38.1166 -        throws InvalidClassException
 38.1167 -    {
 38.1168 -        if (this.cl == cl) {
 38.1169 -            return this;
 38.1170 -        }
 38.1171 -        ObjectStreamClass desc = new ObjectStreamClass();
 38.1172 -        if (isProxy) {
 38.1173 -            desc.initProxy(cl, null, superDesc);
 38.1174 -        } else {
 38.1175 -            desc.initNonProxy(this, cl, null, superDesc);
 38.1176 -        }
 38.1177 -        return desc;
 38.1178 -    }
 38.1179 -
 38.1180 -    /**
 38.1181 -     * Returns public no-arg constructor of given class, or null if none found.
 38.1182 -     * Access checks are disabled on the returned constructor (if any), since
 38.1183 -     * the defining class may still be non-public.
 38.1184 -     */
 38.1185 -    private static Constructor getExternalizableConstructor(Class<?> cl) {
 38.1186 -        throw new SecurityException();
 38.1187 -    }
 38.1188 -
 38.1189 -    /**
 38.1190 -     * Returns subclass-accessible no-arg constructor of first non-serializable
 38.1191 -     * superclass, or null if none found.  Access checks are disabled on the
 38.1192 -     * returned constructor (if any).
 38.1193 -     */
 38.1194 -    private static Constructor getSerializableConstructor(Class<?> cl) {
 38.1195 -        Class<?> initCl = cl;
 38.1196 -        while (Serializable.class.isAssignableFrom(initCl)) {
 38.1197 -            if ((initCl = initCl.getSuperclass()) == null) {
 38.1198 -                return null;
 38.1199 -            }
 38.1200 -        }
 38.1201 -        throw new SecurityException();
 38.1202 -    }
 38.1203 -
 38.1204 -    /**
 38.1205 -     * Returns non-static, non-abstract method with given signature provided it
 38.1206 -     * is defined by or accessible (via inheritance) by the given class, or
 38.1207 -     * null if no match found.  Access checks are disabled on the returned
 38.1208 -     * method (if any).
 38.1209 -     */
 38.1210 -    private static Method getInheritableMethod(Class<?> cl, String name,
 38.1211 -                                               Class<?>[] argTypes,
 38.1212 -                                               Class<?> returnType)
 38.1213 -    {
 38.1214 -        throw new SecurityException();
 38.1215 -    }
 38.1216 -
 38.1217 -    /**
 38.1218 -     * Returns non-static private method with given signature defined by given
 38.1219 -     * class, or null if none found.  Access checks are disabled on the
 38.1220 -     * returned method (if any).
 38.1221 -     */
 38.1222 -    private static Method getPrivateMethod(Class<?> cl, String name,
 38.1223 -                                           Class<?>[] argTypes,
 38.1224 -                                           Class<?> returnType)
 38.1225 -    {
 38.1226 -        throw new SecurityException();
 38.1227 -    }
 38.1228 -
 38.1229 -    /**
 38.1230 -     * Returns true if classes are defined in the same runtime package, false
 38.1231 -     * otherwise.
 38.1232 -     */
 38.1233 -    private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
 38.1234 -        return (cl1.getClassLoader() == cl2.getClassLoader() &&
 38.1235 -                getPackageName(cl1).equals(getPackageName(cl2)));
 38.1236 -    }
 38.1237 -
 38.1238 -    /**
 38.1239 -     * Returns package name of given class.
 38.1240 -     */
 38.1241 -    private static String getPackageName(Class<?> cl) {
 38.1242 -        String s = cl.getName();
 38.1243 -        int i = s.lastIndexOf('[');
 38.1244 -        if (i >= 0) {
 38.1245 -            s = s.substring(i + 2);
 38.1246 -        }
 38.1247 -        i = s.lastIndexOf('.');
 38.1248 -        return (i >= 0) ? s.substring(0, i) : "";
 38.1249 -    }
 38.1250 -
 38.1251 -    /**
 38.1252 -     * Compares class names for equality, ignoring package names.  Returns true
 38.1253 -     * if class names equal, false otherwise.
 38.1254 -     */
 38.1255 -    private static boolean classNamesEqual(String name1, String name2) {
 38.1256 -        name1 = name1.substring(name1.lastIndexOf('.') + 1);
 38.1257 -        name2 = name2.substring(name2.lastIndexOf('.') + 1);
 38.1258 -        return name1.equals(name2);
 38.1259 -    }
 38.1260 -
 38.1261 -    /**
 38.1262 -     * Returns JVM type signature for given class.
 38.1263 -     */
 38.1264 -    private static String getClassSignature(Class<?> cl) {
 38.1265 -        StringBuilder sbuf = new StringBuilder();
 38.1266 -        while (cl.isArray()) {
 38.1267 -            sbuf.append('[');
 38.1268 -            cl = cl.getComponentType();
 38.1269 -        }
 38.1270 -        if (cl.isPrimitive()) {
 38.1271 -            if (cl == Integer.TYPE) {
 38.1272 -                sbuf.append('I');
 38.1273 -            } else if (cl == Byte.TYPE) {
 38.1274 -                sbuf.append('B');
 38.1275 -            } else if (cl == Long.TYPE) {
 38.1276 -                sbuf.append('J');
 38.1277 -            } else if (cl == Float.TYPE) {
 38.1278 -                sbuf.append('F');
 38.1279 -            } else if (cl == Double.TYPE) {
 38.1280 -                sbuf.append('D');
 38.1281 -            } else if (cl == Short.TYPE) {
 38.1282 -                sbuf.append('S');
 38.1283 -            } else if (cl == Character.TYPE) {
 38.1284 -                sbuf.append('C');
 38.1285 -            } else if (cl == Boolean.TYPE) {
 38.1286 -                sbuf.append('Z');
 38.1287 -            } else if (cl == Void.TYPE) {
 38.1288 -                sbuf.append('V');
 38.1289 -            } else {
 38.1290 -                throw new InternalError();
 38.1291 -            }
 38.1292 -        } else {
 38.1293 -            sbuf.append('L' + cl.getName().replace('.', '/') + ';');
 38.1294 -        }
 38.1295 -        return sbuf.toString();
 38.1296 -    }
 38.1297 -
 38.1298 -    /**
 38.1299 -     * Returns JVM type signature for given list of parameters and return type.
 38.1300 -     */
 38.1301 -    private static String getMethodSignature(Class<?>[] paramTypes,
 38.1302 -                                             Class<?> retType)
 38.1303 -    {
 38.1304 -        StringBuilder sbuf = new StringBuilder();
 38.1305 -        sbuf.append('(');
 38.1306 -        for (int i = 0; i < paramTypes.length; i++) {
 38.1307 -            sbuf.append(getClassSignature(paramTypes[i]));
 38.1308 -        }
 38.1309 -        sbuf.append(')');
 38.1310 -        sbuf.append(getClassSignature(retType));
 38.1311 -        return sbuf.toString();
 38.1312 -    }
 38.1313 -
 38.1314 -    /**
 38.1315 -     * Convenience method for throwing an exception that is either a
 38.1316 -     * RuntimeException, Error, or of some unexpected type (in which case it is
 38.1317 -     * wrapped inside an IOException).
 38.1318 -     */
 38.1319 -    private static void throwMiscException(Throwable th) throws IOException {
 38.1320 -        if (th instanceof RuntimeException) {
 38.1321 -            throw (RuntimeException) th;
 38.1322 -        } else if (th instanceof Error) {
 38.1323 -            throw (Error) th;
 38.1324 -        } else {
 38.1325 -            IOException ex = new IOException("unexpected exception type");
 38.1326 -            ex.initCause(th);
 38.1327 -            throw ex;
 38.1328 -        }
 38.1329 -    }
 38.1330 -
 38.1331 -    /**
 38.1332 -     * Returns ObjectStreamField array describing the serializable fields of
 38.1333 -     * the given class.  Serializable fields backed by an actual field of the
 38.1334 -     * class are represented by ObjectStreamFields with corresponding non-null
 38.1335 -     * Field objects.  Throws InvalidClassException if the (explicitly
 38.1336 -     * declared) serializable fields are invalid.
 38.1337 -     */
 38.1338 -    private static ObjectStreamField[] getSerialFields(Class<?> cl)
 38.1339 -        throws InvalidClassException
 38.1340 -    {
 38.1341 -        ObjectStreamField[] fields;
 38.1342 -        if (Serializable.class.isAssignableFrom(cl) &&
 38.1343 -            !Externalizable.class.isAssignableFrom(cl) &&
 38.1344 -            !Proxy.isProxyClass(cl) &&
 38.1345 -            !cl.isInterface())
 38.1346 -        {
 38.1347 -            if ((fields = getDeclaredSerialFields(cl)) == null) {
 38.1348 -                fields = getDefaultSerialFields(cl);
 38.1349 -            }
 38.1350 -            Arrays.sort(fields);
 38.1351 -        } else {
 38.1352 -            fields = NO_FIELDS;
 38.1353 -        }
 38.1354 -        return fields;
 38.1355 -    }
 38.1356 -
 38.1357 -    /**
 38.1358 -     * Returns serializable fields of given class as defined explicitly by a
 38.1359 -     * "serialPersistentFields" field, or null if no appropriate
 38.1360 -     * "serialPersistentFields" field is defined.  Serializable fields backed
 38.1361 -     * by an actual field of the class are represented by ObjectStreamFields
 38.1362 -     * with corresponding non-null Field objects.  For compatibility with past
 38.1363 -     * releases, a "serialPersistentFields" field with a null value is
 38.1364 -     * considered equivalent to not declaring "serialPersistentFields".  Throws
 38.1365 -     * InvalidClassException if the declared serializable fields are
 38.1366 -     * invalid--e.g., if multiple fields share the same name.
 38.1367 -     */
 38.1368 -    private static ObjectStreamField[] getDeclaredSerialFields(Class<?> cl)
 38.1369 -        throws InvalidClassException
 38.1370 -    {
 38.1371 -        throw new SecurityException();
 38.1372 -    }
 38.1373 -
 38.1374 -    /**
 38.1375 -     * Returns array of ObjectStreamFields corresponding to all non-static
 38.1376 -     * non-transient fields declared by given class.  Each ObjectStreamField
 38.1377 -     * contains a Field object for the field it represents.  If no default
 38.1378 -     * serializable fields exist, NO_FIELDS is returned.
 38.1379 -     */
 38.1380 -    private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) {
 38.1381 -        throw new SecurityException();
 38.1382 -    }
 38.1383 -
 38.1384 -    /**
 38.1385 -     * Returns explicit serial version UID value declared by given class, or
 38.1386 -     * null if none.
 38.1387 -     */
 38.1388 -    private static Long getDeclaredSUID(Class<?> cl) {
 38.1389 -        return null;
 38.1390 -    }
 38.1391 -
 38.1392 -    /**
 38.1393 -     * Computes the default serial version UID value for the given class.
 38.1394 -     */
 38.1395 -    private static long computeDefaultSUID(Class<?> cl) {
 38.1396 -        throw new SecurityException();
 38.1397 -    }
 38.1398 -
 38.1399 -}
    39.1 --- a/emul/compact/src/main/java/java/io/ObjectStreamConstants.java	Mon Feb 25 19:00:08 2013 +0100
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,215 +0,0 @@
    39.4 -/*
    39.5 - * Copyright (c) 1996, 2006, 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.io;
   39.30 -
   39.31 -/**
   39.32 - * Constants written into the Object Serialization Stream.
   39.33 - *
   39.34 - * @author  unascribed
   39.35 - * @since JDK 1.1
   39.36 - */
   39.37 -public interface ObjectStreamConstants {
   39.38 -
   39.39 -    /**
   39.40 -     * Magic number that is written to the stream header.
   39.41 -     */
   39.42 -    final static short STREAM_MAGIC = (short)0xaced;
   39.43 -
   39.44 -    /**
   39.45 -     * Version number that is written to the stream header.
   39.46 -     */
   39.47 -    final static short STREAM_VERSION = 5;
   39.48 -
   39.49 -    /* Each item in the stream is preceded by a tag
   39.50 -     */
   39.51 -
   39.52 -    /**
   39.53 -     * First tag value.
   39.54 -     */
   39.55 -    final static byte TC_BASE = 0x70;
   39.56 -
   39.57 -    /**
   39.58 -     * Null object reference.
   39.59 -     */
   39.60 -    final static byte TC_NULL =         (byte)0x70;
   39.61 -
   39.62 -    /**
   39.63 -     * Reference to an object already written into the stream.
   39.64 -     */
   39.65 -    final static byte TC_REFERENCE =    (byte)0x71;
   39.66 -
   39.67 -    /**
   39.68 -     * new Class Descriptor.
   39.69 -     */
   39.70 -    final static byte TC_CLASSDESC =    (byte)0x72;
   39.71 -
   39.72 -    /**
   39.73 -     * new Object.
   39.74 -     */
   39.75 -    final static byte TC_OBJECT =       (byte)0x73;
   39.76 -
   39.77 -    /**
   39.78 -     * new String.
   39.79 -     */
   39.80 -    final static byte TC_STRING =       (byte)0x74;
   39.81 -
   39.82 -    /**
   39.83 -     * new Array.
   39.84 -     */
   39.85 -    final static byte TC_ARRAY =        (byte)0x75;
   39.86 -
   39.87 -    /**
   39.88 -     * Reference to Class.
   39.89 -     */
   39.90 -    final static byte TC_CLASS =        (byte)0x76;
   39.91 -
   39.92 -    /**
   39.93 -     * Block of optional data. Byte following tag indicates number
   39.94 -     * of bytes in this block data.
   39.95 -     */
   39.96 -    final static byte TC_BLOCKDATA =    (byte)0x77;
   39.97 -
   39.98 -    /**
   39.99 -     * End of optional block data blocks for an object.
  39.100 -     */
  39.101 -    final static byte TC_ENDBLOCKDATA = (byte)0x78;
  39.102 -
  39.103 -    /**
  39.104 -     * Reset stream context. All handles written into stream are reset.
  39.105 -     */
  39.106 -    final static byte TC_RESET =        (byte)0x79;
  39.107 -
  39.108 -    /**
  39.109 -     * long Block data. The long following the tag indicates the
  39.110 -     * number of bytes in this block data.
  39.111 -     */
  39.112 -    final static byte TC_BLOCKDATALONG= (byte)0x7A;
  39.113 -
  39.114 -    /**
  39.115 -     * Exception during write.
  39.116 -     */
  39.117 -    final static byte TC_EXCEPTION =    (byte)0x7B;
  39.118 -
  39.119 -    /**
  39.120 -     * Long string.
  39.121 -     */
  39.122 -    final static byte TC_LONGSTRING =   (byte)0x7C;
  39.123 -
  39.124 -    /**
  39.125 -     * new Proxy Class Descriptor.
  39.126 -     */
  39.127 -    final static byte TC_PROXYCLASSDESC =       (byte)0x7D;
  39.128 -
  39.129 -    /**
  39.130 -     * new Enum constant.
  39.131 -     * @since 1.5
  39.132 -     */
  39.133 -    final static byte TC_ENUM =         (byte)0x7E;
  39.134 -
  39.135 -    /**
  39.136 -     * Last tag value.
  39.137 -     */
  39.138 -    final static byte TC_MAX =          (byte)0x7E;
  39.139 -
  39.140 -    /**
  39.141 -     * First wire handle to be assigned.
  39.142 -     */
  39.143 -    final static int baseWireHandle = 0x7e0000;
  39.144 -
  39.145 -
  39.146 -    /******************************************************/
  39.147 -    /* Bit masks for ObjectStreamClass flag.*/
  39.148 -
  39.149 -    /**
  39.150 -     * Bit mask for ObjectStreamClass flag. Indicates a Serializable class
  39.151 -     * defines its own writeObject method.
  39.152 -     */
  39.153 -    final static byte SC_WRITE_METHOD = 0x01;
  39.154 -
  39.155 -    /**
  39.156 -     * Bit mask for ObjectStreamClass flag. Indicates Externalizable data
  39.157 -     * written in Block Data mode.
  39.158 -     * Added for PROTOCOL_VERSION_2.
  39.159 -     *
  39.160 -     * @see #PROTOCOL_VERSION_2
  39.161 -     * @since 1.2
  39.162 -     */
  39.163 -    final static byte SC_BLOCK_DATA = 0x08;
  39.164 -
  39.165 -    /**
  39.166 -     * Bit mask for ObjectStreamClass flag. Indicates class is Serializable.
  39.167 -     */
  39.168 -    final static byte SC_SERIALIZABLE = 0x02;
  39.169 -
  39.170 -    /**
  39.171 -     * Bit mask for ObjectStreamClass flag. Indicates class is Externalizable.
  39.172 -     */
  39.173 -    final static byte SC_EXTERNALIZABLE = 0x04;
  39.174 -
  39.175 -    /**
  39.176 -     * Bit mask for ObjectStreamClass flag. Indicates class is an enum type.
  39.177 -     * @since 1.5
  39.178 -     */
  39.179 -    final static byte SC_ENUM = 0x10;
  39.180 -
  39.181 -
  39.182 -    /* *******************************************************************/
  39.183 -    /* Security permissions */
  39.184 -
  39.185 -   /**
  39.186 -    * A Stream Protocol Version. <p>
  39.187 -    *
  39.188 -    * All externalizable data is written in JDK 1.1 external data
  39.189 -    * format after calling this method. This version is needed to write
  39.190 -    * streams containing Externalizable data that can be read by
  39.191 -    * pre-JDK 1.1.6 JVMs.
  39.192 -    *
  39.193 -    * @see java.io.ObjectOutputStream#useProtocolVersion(int)
  39.194 -    * @since 1.2
  39.195 -    */
  39.196 -    public final static int PROTOCOL_VERSION_1 = 1;
  39.197 -
  39.198 -
  39.199 -   /**
  39.200 -    * A Stream Protocol Version. <p>
  39.201 -    *
  39.202 -    * This protocol is written by JVM 1.2.
  39.203 -    *
  39.204 -    * Externalizable data is written in block data mode and is
  39.205 -    * terminated with TC_ENDBLOCKDATA. Externalizable classdescriptor
  39.206 -    * flags has SC_BLOCK_DATA enabled. JVM 1.1.6 and greater can
  39.207 -    * read this format change.
  39.208 -    *
  39.209 -    * Enables writing a nonSerializable class descriptor into the
  39.210 -    * stream. The serialVersionUID of a nonSerializable class is
  39.211 -    * set to 0L.
  39.212 -    *
  39.213 -    * @see java.io.ObjectOutputStream#useProtocolVersion(int)
  39.214 -    * @see #SC_BLOCK_DATA
  39.215 -    * @since 1.2
  39.216 -    */
  39.217 -    public final static int PROTOCOL_VERSION_2 = 2;
  39.218 -}
    40.1 --- a/emul/compact/src/main/java/java/io/ObjectStreamException.java	Mon Feb 25 19:00:08 2013 +0100
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,53 +0,0 @@
    40.4 -/*
    40.5 - * Copyright (c) 1996, 2005, 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.io;
   40.30 -
   40.31 -/**
   40.32 - * Superclass of all exceptions specific to Object Stream classes.
   40.33 - *
   40.34 - * @author  unascribed
   40.35 - * @since   JDK1.1
   40.36 - */
   40.37 -public abstract class ObjectStreamException extends IOException {
   40.38 -
   40.39 -    private static final long serialVersionUID = 7260898174833392607L;
   40.40 -
   40.41 -    /**
   40.42 -     * Create an ObjectStreamException with the specified argument.
   40.43 -     *
   40.44 -     * @param classname the detailed message for the exception
   40.45 -     */
   40.46 -    protected ObjectStreamException(String classname) {
   40.47 -        super(classname);
   40.48 -    }
   40.49 -
   40.50 -    /**
   40.51 -     * Create an ObjectStreamException.
   40.52 -     */
   40.53 -    protected ObjectStreamException() {
   40.54 -        super();
   40.55 -    }
   40.56 -}
    41.1 --- a/emul/compact/src/main/java/java/io/ObjectStreamField.java	Mon Feb 25 19:00:08 2013 +0100
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,314 +0,0 @@
    41.4 -/*
    41.5 - * Copyright (c) 1996, 2006, 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.io;
   41.30 -
   41.31 -import java.lang.reflect.Field;
   41.32 -
   41.33 -/**
   41.34 - * A description of a Serializable field from a Serializable class.  An array
   41.35 - * of ObjectStreamFields is used to declare the Serializable fields of a class.
   41.36 - *
   41.37 - * @author      Mike Warres
   41.38 - * @author      Roger Riggs
   41.39 - * @see ObjectStreamClass
   41.40 - * @since 1.2
   41.41 - */
   41.42 -public class ObjectStreamField
   41.43 -    implements Comparable<Object>
   41.44 -{
   41.45 -
   41.46 -    /** field name */
   41.47 -    private final String name;
   41.48 -    /** canonical JVM signature of field type */
   41.49 -    private final String signature;
   41.50 -    /** field type (Object.class if unknown non-primitive type) */
   41.51 -    private final Class<?> type;
   41.52 -    /** whether or not to (de)serialize field values as unshared */
   41.53 -    private final boolean unshared;
   41.54 -    /** corresponding reflective field object, if any */
   41.55 -    private final Field field;
   41.56 -    /** offset of field value in enclosing field group */
   41.57 -    private int offset = 0;
   41.58 -
   41.59 -    /**
   41.60 -     * Create a Serializable field with the specified type.  This field should
   41.61 -     * be documented with a <code>serialField</code> tag.
   41.62 -     *
   41.63 -     * @param   name the name of the serializable field
   41.64 -     * @param   type the <code>Class</code> object of the serializable field
   41.65 -     */
   41.66 -    public ObjectStreamField(String name, Class<?> type) {
   41.67 -        this(name, type, false);
   41.68 -    }
   41.69 -
   41.70 -    /**
   41.71 -     * Creates an ObjectStreamField representing a serializable field with the
   41.72 -     * given name and type.  If unshared is false, values of the represented
   41.73 -     * field are serialized and deserialized in the default manner--if the
   41.74 -     * field is non-primitive, object values are serialized and deserialized as
   41.75 -     * if they had been written and read by calls to writeObject and
   41.76 -     * readObject.  If unshared is true, values of the represented field are
   41.77 -     * serialized and deserialized as if they had been written and read by
   41.78 -     * calls to writeUnshared and readUnshared.
   41.79 -     *
   41.80 -     * @param   name field name
   41.81 -     * @param   type field type
   41.82 -     * @param   unshared if false, write/read field values in the same manner
   41.83 -     *          as writeObject/readObject; if true, write/read in the same
   41.84 -     *          manner as writeUnshared/readUnshared
   41.85 -     * @since   1.4
   41.86 -     */
   41.87 -    public ObjectStreamField(String name, Class<?> type, boolean unshared) {
   41.88 -        if (name == null) {
   41.89 -            throw new NullPointerException();
   41.90 -        }
   41.91 -        this.name = name;
   41.92 -        this.type = type;
   41.93 -        this.unshared = unshared;
   41.94 -        signature = getClassSignature(type).intern();
   41.95 -        field = null;
   41.96 -    }
   41.97 -
   41.98 -    /**
   41.99 -     * Creates an ObjectStreamField representing a field with the given name,
  41.100 -     * signature and unshared setting.
  41.101 -     */
  41.102 -    ObjectStreamField(String name, String signature, boolean unshared) {
  41.103 -        if (name == null) {
  41.104 -            throw new NullPointerException();
  41.105 -        }
  41.106 -        this.name = name;
  41.107 -        this.signature = signature.intern();
  41.108 -        this.unshared = unshared;
  41.109 -        field = null;
  41.110 -
  41.111 -        switch (signature.charAt(0)) {
  41.112 -            case 'Z': type = Boolean.TYPE; break;
  41.113 -            case 'B': type = Byte.TYPE; break;
  41.114 -            case 'C': type = Character.TYPE; break;
  41.115 -            case 'S': type = Short.TYPE; break;
  41.116 -            case 'I': type = Integer.TYPE; break;
  41.117 -            case 'J': type = Long.TYPE; break;
  41.118 -            case 'F': type = Float.TYPE; break;
  41.119 -            case 'D': type = Double.TYPE; break;
  41.120 -            case 'L':
  41.121 -            case '[': type = Object.class; break;
  41.122 -            default: throw new IllegalArgumentException("illegal signature");
  41.123 -        }
  41.124 -    }
  41.125 -
  41.126 -    /**
  41.127 -     * Creates an ObjectStreamField representing the given field with the
  41.128 -     * specified unshared setting.  For compatibility with the behavior of
  41.129 -     * earlier serialization implementations, a "showType" parameter is
  41.130 -     * necessary to govern whether or not a getType() call on this
  41.131 -     * ObjectStreamField (if non-primitive) will return Object.class (as
  41.132 -     * opposed to a more specific reference type).
  41.133 -     */
  41.134 -    ObjectStreamField(Field field, boolean unshared, boolean showType) {
  41.135 -        this.field = field;
  41.136 -        this.unshared = unshared;
  41.137 -        name = field.getName();
  41.138 -        Class<?> ftype = field.getType();
  41.139 -        type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
  41.140 -        signature = getClassSignature(ftype).intern();
  41.141 -    }
  41.142 -
  41.143 -    /**
  41.144 -     * Get the name of this field.
  41.145 -     *
  41.146 -     * @return  a <code>String</code> representing the name of the serializable
  41.147 -     *          field
  41.148 -     */
  41.149 -    public String getName() {
  41.150 -        return name;
  41.151 -    }
  41.152 -
  41.153 -    /**
  41.154 -     * Get the type of the field.  If the type is non-primitive and this
  41.155 -     * <code>ObjectStreamField</code> was obtained from a deserialized {@link
  41.156 -     * ObjectStreamClass} instance, then <code>Object.class</code> is returned.
  41.157 -     * Otherwise, the <code>Class</code> object for the type of the field is
  41.158 -     * returned.
  41.159 -     *
  41.160 -     * @return  a <code>Class</code> object representing the type of the
  41.161 -     *          serializable field
  41.162 -     */
  41.163 -    public Class<?> getType() {
  41.164 -        return type;
  41.165 -    }
  41.166 -
  41.167 -    /**
  41.168 -     * Returns character encoding of field type.  The encoding is as follows:
  41.169 -     * <blockquote><pre>
  41.170 -     * B            byte
  41.171 -     * C            char
  41.172 -     * D            double
  41.173 -     * F            float
  41.174 -     * I            int
  41.175 -     * J            long
  41.176 -     * L            class or interface
  41.177 -     * S            short
  41.178 -     * Z            boolean
  41.179 -     * [            array
  41.180 -     * </pre></blockquote>
  41.181 -     *
  41.182 -     * @return  the typecode of the serializable field
  41.183 -     */
  41.184 -    // REMIND: deprecate?
  41.185 -    public char getTypeCode() {
  41.186 -        return signature.charAt(0);
  41.187 -    }
  41.188 -
  41.189 -    /**
  41.190 -     * Return the JVM type signature.
  41.191 -     *
  41.192 -     * @return  null if this field has a primitive type.
  41.193 -     */
  41.194 -    // REMIND: deprecate?
  41.195 -    public String getTypeString() {
  41.196 -        return isPrimitive() ? null : signature;
  41.197 -    }
  41.198 -
  41.199 -    /**
  41.200 -     * Offset of field within instance data.
  41.201 -     *
  41.202 -     * @return  the offset of this field
  41.203 -     * @see #setOffset
  41.204 -     */
  41.205 -    // REMIND: deprecate?
  41.206 -    public int getOffset() {
  41.207 -        return offset;
  41.208 -    }
  41.209 -
  41.210 -    /**
  41.211 -     * Offset within instance data.
  41.212 -     *
  41.213 -     * @param   offset the offset of the field
  41.214 -     * @see #getOffset
  41.215 -     */
  41.216 -    // REMIND: deprecate?
  41.217 -    protected void setOffset(int offset) {
  41.218 -        this.offset = offset;
  41.219 -    }
  41.220 -
  41.221 -    /**
  41.222 -     * Return true if this field has a primitive type.
  41.223 -     *
  41.224 -     * @return  true if and only if this field corresponds to a primitive type
  41.225 -     */
  41.226 -    // REMIND: deprecate?
  41.227 -    public boolean isPrimitive() {
  41.228 -        char tcode = signature.charAt(0);
  41.229 -        return ((tcode != 'L') && (tcode != '['));
  41.230 -    }
  41.231 -
  41.232 -    /**
  41.233 -     * Returns boolean value indicating whether or not the serializable field
  41.234 -     * represented by this ObjectStreamField instance is unshared.
  41.235 -     *
  41.236 -     * @since 1.4
  41.237 -     */
  41.238 -    public boolean isUnshared() {
  41.239 -        return unshared;
  41.240 -    }
  41.241 -
  41.242 -    /**
  41.243 -     * Compare this field with another <code>ObjectStreamField</code>.  Return
  41.244 -     * -1 if this is smaller, 0 if equal, 1 if greater.  Types that are
  41.245 -     * primitives are "smaller" than object types.  If equal, the field names
  41.246 -     * are compared.
  41.247 -     */
  41.248 -    // REMIND: deprecate?
  41.249 -    public int compareTo(Object obj) {
  41.250 -        ObjectStreamField other = (ObjectStreamField) obj;
  41.251 -        boolean isPrim = isPrimitive();
  41.252 -        if (isPrim != other.isPrimitive()) {
  41.253 -            return isPrim ? -1 : 1;
  41.254 -        }
  41.255 -        return name.compareTo(other.name);
  41.256 -    }
  41.257 -
  41.258 -    /**
  41.259 -     * Return a string that describes this field.
  41.260 -     */
  41.261 -    public String toString() {
  41.262 -        return signature + ' ' + name;
  41.263 -    }
  41.264 -
  41.265 -    /**
  41.266 -     * Returns field represented by this ObjectStreamField, or null if
  41.267 -     * ObjectStreamField is not associated with an actual field.
  41.268 -     */
  41.269 -    Field getField() {
  41.270 -        return field;
  41.271 -    }
  41.272 -
  41.273 -    /**
  41.274 -     * Returns JVM type signature of field (similar to getTypeString, except
  41.275 -     * that signature strings are returned for primitive fields as well).
  41.276 -     */
  41.277 -    String getSignature() {
  41.278 -        return signature;
  41.279 -    }
  41.280 -
  41.281 -    /**
  41.282 -     * Returns JVM type signature for given class.
  41.283 -     */
  41.284 -    private static String getClassSignature(Class<?> cl) {
  41.285 -        StringBuilder sbuf = new StringBuilder();
  41.286 -        while (cl.isArray()) {
  41.287 -            sbuf.append('[');
  41.288 -            cl = cl.getComponentType();
  41.289 -        }
  41.290 -        if (cl.isPrimitive()) {
  41.291 -            if (cl == Integer.TYPE) {
  41.292 -                sbuf.append('I');
  41.293 -            } else if (cl == Byte.TYPE) {
  41.294 -                sbuf.append('B');
  41.295 -            } else if (cl == Long.TYPE) {
  41.296 -                sbuf.append('J');
  41.297 -            } else if (cl == Float.TYPE) {
  41.298 -                sbuf.append('F');
  41.299 -            } else if (cl == Double.TYPE) {
  41.300 -                sbuf.append('D');
  41.301 -            } else if (cl == Short.TYPE) {
  41.302 -                sbuf.append('S');
  41.303 -            } else if (cl == Character.TYPE) {
  41.304 -                sbuf.append('C');
  41.305 -            } else if (cl == Boolean.TYPE) {
  41.306 -                sbuf.append('Z');
  41.307 -            } else if (cl == Void.TYPE) {
  41.308 -                sbuf.append('V');
  41.309 -            } else {
  41.310 -                throw new InternalError();
  41.311 -            }
  41.312 -        } else {
  41.313 -            sbuf.append('L' + cl.getName().replace('.', '/') + ';');
  41.314 -        }
  41.315 -        return sbuf.toString();
  41.316 -    }
  41.317 -}
    42.1 --- a/emul/compact/src/main/java/java/io/OptionalDataException.java	Mon Feb 25 19:00:08 2013 +0100
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,83 +0,0 @@
    42.4 -/*
    42.5 - * Copyright (c) 1996, 2005, 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 -package java.io;
   42.29 -
   42.30 -/**
   42.31 - * Exception indicating the failure of an object read operation due to
   42.32 - * unread primitive data, or the end of data belonging to a serialized
   42.33 - * object in the stream.  This exception may be thrown in two cases:
   42.34 - *
   42.35 - * <ul>
   42.36 - *   <li>An attempt was made to read an object when the next element in the
   42.37 - *       stream is primitive data.  In this case, the OptionalDataException's
   42.38 - *       length field is set to the number of bytes of primitive data
   42.39 - *       immediately readable from the stream, and the eof field is set to
   42.40 - *       false.
   42.41 - *
   42.42 - *   <li>An attempt was made to read past the end of data consumable by a
   42.43 - *       class-defined readObject or readExternal method.  In this case, the
   42.44 - *       OptionalDataException's eof field is set to true, and the length field
   42.45 - *       is set to 0.
   42.46 - * </ul>
   42.47 - *
   42.48 - * @author  unascribed
   42.49 - * @since   JDK1.1
   42.50 - */
   42.51 -public class OptionalDataException extends ObjectStreamException {
   42.52 -
   42.53 -    private static final long serialVersionUID = -8011121865681257820L;
   42.54 -
   42.55 -    /*
   42.56 -     * Create an <code>OptionalDataException</code> with a length.
   42.57 -     */
   42.58 -    OptionalDataException(int len) {
   42.59 -        eof = false;
   42.60 -        length = len;
   42.61 -    }
   42.62 -
   42.63 -    /*
   42.64 -     * Create an <code>OptionalDataException</code> signifying no
   42.65 -     * more primitive data is available.
   42.66 -     */
   42.67 -    OptionalDataException(boolean end) {
   42.68 -        length = 0;
   42.69 -        eof = end;
   42.70 -    }
   42.71 -
   42.72 -    /**
   42.73 -     * The number of bytes of primitive data available to be read
   42.74 -     * in the current buffer.
   42.75 -     *
   42.76 -     * @serial
   42.77 -     */
   42.78 -    public int length;
   42.79 -
   42.80 -    /**
   42.81 -     * True if there is no more data in the buffered part of the stream.
   42.82 -     *
   42.83 -     * @serial
   42.84 -     */
   42.85 -    public boolean eof;
   42.86 -}
    43.1 --- a/emul/compact/src/main/java/java/io/OutputStream.java	Mon Feb 25 19:00:08 2013 +0100
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,154 +0,0 @@
    43.4 -/*
    43.5 - * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
    43.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    43.7 - *
    43.8 - * This code is free software; you can redistribute it and/or modify it
    43.9 - * under the terms of the GNU General Public License version 2 only, as
   43.10 - * published by the Free Software Foundation.  Oracle designates this
   43.11 - * particular file as subject to the "Classpath" exception as provided
   43.12 - * by Oracle in the LICENSE file that accompanied this code.
   43.13 - *
   43.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   43.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   43.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   43.17 - * version 2 for more details (a copy is included in the LICENSE file that
   43.18 - * accompanied this code).
   43.19 - *
   43.20 - * You should have received a copy of the GNU General Public License version
   43.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   43.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   43.23 - *
   43.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   43.25 - * or visit www.oracle.com if you need additional information or have any
   43.26 - * questions.
   43.27 - */
   43.28 -
   43.29 -package java.io;
   43.30 -
   43.31 -/**
   43.32 - * This abstract class is the superclass of all classes representing
   43.33 - * an output stream of bytes. An output stream accepts output bytes
   43.34 - * and sends them to some sink.
   43.35 - * <p>
   43.36 - * Applications that need to define a subclass of
   43.37 - * <code>OutputStream</code> must always provide at least a method
   43.38 - * that writes one byte of output.
   43.39 - *
   43.40 - * @author  Arthur van Hoff
   43.41 - * @see     java.io.BufferedOutputStream
   43.42 - * @see     java.io.ByteArrayOutputStream
   43.43 - * @see     java.io.DataOutputStream
   43.44 - * @see     java.io.FilterOutputStream
   43.45 - * @see     java.io.InputStream
   43.46 - * @see     java.io.OutputStream#write(int)
   43.47 - * @since   JDK1.0
   43.48 - */
   43.49 -public abstract class OutputStream implements Closeable, Flushable {
   43.50 -    /**
   43.51 -     * Writes the specified byte to this output stream. The general
   43.52 -     * contract for <code>write</code> is that one byte is written
   43.53 -     * to the output stream. The byte to be written is the eight
   43.54 -     * low-order bits of the argument <code>b</code>. The 24
   43.55 -     * high-order bits of <code>b</code> are ignored.
   43.56 -     * <p>
   43.57 -     * Subclasses of <code>OutputStream</code> must provide an
   43.58 -     * implementation for this method.
   43.59 -     *
   43.60 -     * @param      b   the <code>byte</code>.
   43.61 -     * @exception  IOException  if an I/O error occurs. In particular,
   43.62 -     *             an <code>IOException</code> may be thrown if the
   43.63 -     *             output stream has been closed.
   43.64 -     */
   43.65 -    public abstract void write(int b) throws IOException;
   43.66 -
   43.67 -    /**
   43.68 -     * Writes <code>b.length</code> bytes from the specified byte array
   43.69 -     * to this output stream. The general contract for <code>write(b)</code>
   43.70 -     * is that it should have exactly the same effect as the call
   43.71 -     * <code>write(b, 0, b.length)</code>.
   43.72 -     *
   43.73 -     * @param      b   the data.
   43.74 -     * @exception  IOException  if an I/O error occurs.
   43.75 -     * @see        java.io.OutputStream#write(byte[], int, int)
   43.76 -     */
   43.77 -    public void write(byte b[]) throws IOException {
   43.78 -        write(b, 0, b.length);
   43.79 -    }
   43.80 -
   43.81 -    /**
   43.82 -     * Writes <code>len</code> bytes from the specified byte array
   43.83 -     * starting at offset <code>off</code> to this output stream.
   43.84 -     * The general contract for <code>write(b, off, len)</code> is that
   43.85 -     * some of the bytes in the array <code>b</code> are written to the
   43.86 -     * output stream in order; element <code>b[off]</code> is the first
   43.87 -     * byte written and <code>b[off+len-1]</code> is the last byte written
   43.88 -     * by this operation.
   43.89 -     * <p>
   43.90 -     * The <code>write</code> method of <code>OutputStream</code> calls
   43.91 -     * the write method of one argument on each of the bytes to be
   43.92 -     * written out. Subclasses are encouraged to override this method and
   43.93 -     * provide a more efficient implementation.
   43.94 -     * <p>
   43.95 -     * If <code>b</code> is <code>null</code>, a
   43.96 -     * <code>NullPointerException</code> is thrown.
   43.97 -     * <p>
   43.98 -     * If <code>off</code> is negative, or <code>len</code> is negative, or
   43.99 -     * <code>off+len</code> is greater than the length of the array
  43.100 -     * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
  43.101 -     *
  43.102 -     * @param      b     the data.
  43.103 -     * @param      off   the start offset in the data.
  43.104 -     * @param      len   the number of bytes to write.
  43.105 -     * @exception  IOException  if an I/O error occurs. In particular,
  43.106 -     *             an <code>IOException</code> is thrown if the output
  43.107 -     *             stream is closed.
  43.108 -     */
  43.109 -    public void write(byte b[], int off, int len) throws IOException {
  43.110 -        if (b == null) {
  43.111 -            throw new NullPointerException();
  43.112 -        } else if ((off < 0) || (off > b.length) || (len < 0) ||
  43.113 -                   ((off + len) > b.length) || ((off + len) < 0)) {
  43.114 -            throw new IndexOutOfBoundsException();
  43.115 -        } else if (len == 0) {
  43.116 -            return;
  43.117 -        }
  43.118 -        for (int i = 0 ; i < len ; i++) {
  43.119 -            write(b[off + i]);
  43.120 -        }
  43.121 -    }
  43.122 -
  43.123 -    /**
  43.124 -     * Flushes this output stream and forces any buffered output bytes
  43.125 -     * to be written out. The general contract of <code>flush</code> is
  43.126 -     * that calling it is an indication that, if any bytes previously
  43.127 -     * written have been buffered by the implementation of the output
  43.128 -     * stream, such bytes should immediately be written to their
  43.129 -     * intended destination.
  43.130 -     * <p>
  43.131 -     * If the intended destination of this stream is an abstraction provided by
  43.132 -     * the underlying operating system, for example a file, then flushing the
  43.133 -     * stream guarantees only that bytes previously written to the stream are
  43.134 -     * passed to the operating system for writing; it does not guarantee that
  43.135 -     * they are actually written to a physical device such as a disk drive.
  43.136 -     * <p>
  43.137 -     * The <code>flush</code> method of <code>OutputStream</code> does nothing.
  43.138 -     *
  43.139 -     * @exception  IOException  if an I/O error occurs.
  43.140 -     */
  43.141 -    public void flush() throws IOException {
  43.142 -    }
  43.143 -
  43.144 -    /**
  43.145 -     * Closes this output stream and releases any system resources
  43.146 -     * associated with this stream. The general contract of <code>close</code>
  43.147 -     * is that it closes the output stream. A closed stream cannot perform
  43.148 -     * output operations and cannot be reopened.
  43.149 -     * <p>
  43.150 -     * The <code>close</code> method of <code>OutputStream</code> does nothing.
  43.151 -     *
  43.152 -     * @exception  IOException  if an I/O error occurs.
  43.153 -     */
  43.154 -    public void close() throws IOException {
  43.155 -    }
  43.156 -
  43.157 -}
    44.1 --- a/emul/compact/src/main/java/java/io/Reader.java	Mon Feb 25 19:00:08 2013 +0100
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,262 +0,0 @@
    44.4 -/*
    44.5 - * Copyright (c) 1996, 2006, 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.io;
   44.30 -
   44.31 -
   44.32 -/**
   44.33 - * Abstract class for reading character streams.  The only methods that a
   44.34 - * subclass must implement are read(char[], int, int) and close().  Most
   44.35 - * subclasses, however, will override some of the methods defined here in order
   44.36 - * to provide higher efficiency, additional functionality, or both.
   44.37 - *
   44.38 - *
   44.39 - * @see BufferedReader
   44.40 - * @see   LineNumberReader
   44.41 - * @see CharArrayReader
   44.42 - * @see InputStreamReader
   44.43 - * @see   FileReader
   44.44 - * @see FilterReader
   44.45 - * @see   PushbackReader
   44.46 - * @see PipedReader
   44.47 - * @see StringReader
   44.48 - * @see Writer
   44.49 - *
   44.50 - * @author      Mark Reinhold
   44.51 - * @since       JDK1.1
   44.52 - */
   44.53 -
   44.54 -public abstract class Reader implements Readable, Closeable {
   44.55 -
   44.56 -    /**
   44.57 -     * The object used to synchronize operations on this stream.  For
   44.58 -     * efficiency, a character-stream object may use an object other than
   44.59 -     * itself to protect critical sections.  A subclass should therefore use
   44.60 -     * the object in this field rather than <tt>this</tt> or a synchronized
   44.61 -     * method.
   44.62 -     */
   44.63 -    protected Object lock;
   44.64 -
   44.65 -    /**
   44.66 -     * Creates a new character-stream reader whose critical sections will
   44.67 -     * synchronize on the reader itself.
   44.68 -     */
   44.69 -    protected Reader() {
   44.70 -        this.lock = this;
   44.71 -    }
   44.72 -
   44.73 -    /**
   44.74 -     * Creates a new character-stream reader whose critical sections will
   44.75 -     * synchronize on the given object.
   44.76 -     *
   44.77 -     * @param lock  The Object to synchronize on.
   44.78 -     */
   44.79 -    protected Reader(Object lock) {
   44.80 -        if (lock == null) {
   44.81 -            throw new NullPointerException();
   44.82 -        }
   44.83 -        this.lock = lock;
   44.84 -    }
   44.85 -
   44.86 -    /**
   44.87 -     * Attempts to read characters into the specified character buffer.
   44.88 -     * The buffer is used as a repository of characters as-is: the only
   44.89 -     * changes made are the results of a put operation. No flipping or
   44.90 -     * rewinding of the buffer is performed.
   44.91 -     *
   44.92 -     * @param target the buffer to read characters into
   44.93 -     * @return The number of characters added to the buffer, or
   44.94 -     *         -1 if this source of characters is at its end
   44.95 -     * @throws IOException if an I/O error occurs
   44.96 -     * @throws NullPointerException if target is null
   44.97 -     * @throws ReadOnlyBufferException if target is a read only buffer
   44.98 -     * @since 1.5
   44.99 -     */
  44.100 -//    public int read(java.nio.CharBuffer target) throws IOException {
  44.101 -//        int len = target.remaining();
  44.102 -//        char[] cbuf = new char[len];
  44.103 -//        int n = read(cbuf, 0, len);
  44.104 -//        if (n > 0)
  44.105 -//            target.put(cbuf, 0, n);
  44.106 -//        return n;
  44.107 -//    }
  44.108 -
  44.109 -    /**
  44.110 -     * Reads a single character.  This method will block until a character is
  44.111 -     * available, an I/O error occurs, or the end of the stream is reached.
  44.112 -     *
  44.113 -     * <p> Subclasses that intend to support efficient single-character input
  44.114 -     * should override this method.
  44.115 -     *
  44.116 -     * @return     The character read, as an integer in the range 0 to 65535
  44.117 -     *             (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has
  44.118 -     *             been reached
  44.119 -     *
  44.120 -     * @exception  IOException  If an I/O error occurs
  44.121 -     */
  44.122 -    public int read() throws IOException {
  44.123 -        char cb[] = new char[1];
  44.124 -        if (read(cb, 0, 1) == -1)
  44.125 -            return -1;
  44.126 -        else
  44.127 -            return cb[0];
  44.128 -    }
  44.129 -
  44.130 -    /**
  44.131 -     * Reads characters into an array.  This method will block until some input
  44.132 -     * is available, an I/O error occurs, or the end of the stream is reached.
  44.133 -     *
  44.134 -     * @param       cbuf  Destination buffer
  44.135 -     *
  44.136 -     * @return      The number of characters read, or -1
  44.137 -     *              if the end of the stream
  44.138 -     *              has been reached
  44.139 -     *
  44.140 -     * @exception   IOException  If an I/O error occurs
  44.141 -     */
  44.142 -    public int read(char cbuf[]) throws IOException {
  44.143 -        return read(cbuf, 0, cbuf.length);
  44.144 -    }
  44.145 -
  44.146 -    /**
  44.147 -     * Reads characters into a portion of an array.  This method will block
  44.148 -     * until some input is available, an I/O error occurs, or the end of the
  44.149 -     * stream is reached.
  44.150 -     *
  44.151 -     * @param      cbuf  Destination buffer
  44.152 -     * @param      off   Offset at which to start storing characters
  44.153 -     * @param      len   Maximum number of characters to read
  44.154 -     *
  44.155 -     * @return     The number of characters read, or -1 if the end of the
  44.156 -     *             stream has been reached
  44.157 -     *
  44.158 -     * @exception  IOException  If an I/O error occurs
  44.159 -     */
  44.160 -    abstract public int read(char cbuf[], int off, int len) throws IOException;
  44.161 -
  44.162 -    /** Maximum skip-buffer size */
  44.163 -    private static final int maxSkipBufferSize = 8192;
  44.164 -
  44.165 -    /** Skip buffer, null until allocated */
  44.166 -    private char skipBuffer[] = null;
  44.167 -
  44.168 -    /**
  44.169 -     * Skips characters.  This method will block until some characters are
  44.170 -     * available, an I/O error occurs, or the end of the stream is reached.
  44.171 -     *
  44.172 -     * @param  n  The number of characters to skip
  44.173 -     *
  44.174 -     * @return    The number of characters actually skipped
  44.175 -     *
  44.176 -     * @exception  IllegalArgumentException  If <code>n</code> is negative.
  44.177 -     * @exception  IOException  If an I/O error occurs
  44.178 -     */
  44.179 -    public long skip(long n) throws IOException {
  44.180 -        if (n < 0L)
  44.181 -            throw new IllegalArgumentException("skip value is negative");
  44.182 -        int nn = (int) Math.min(n, maxSkipBufferSize);
  44.183 -        synchronized (lock) {
  44.184 -            if ((skipBuffer == null) || (skipBuffer.length < nn))
  44.185 -                skipBuffer = new char[nn];
  44.186 -            long r = n;
  44.187 -            while (r > 0) {
  44.188 -                int nc = read(skipBuffer, 0, (int)Math.min(r, nn));
  44.189 -                if (nc == -1)
  44.190 -                    break;
  44.191 -                r -= nc;
  44.192 -            }
  44.193 -            return n - r;
  44.194 -        }
  44.195 -    }
  44.196 -
  44.197 -    /**
  44.198 -     * Tells whether this stream is ready to be read.
  44.199 -     *
  44.200 -     * @return True if the next read() is guaranteed not to block for input,
  44.201 -     * false otherwise.  Note that returning false does not guarantee that the
  44.202 -     * next read will block.
  44.203 -     *
  44.204 -     * @exception  IOException  If an I/O error occurs
  44.205 -     */
  44.206 -    public boolean ready() throws IOException {
  44.207 -        return false;
  44.208 -    }
  44.209 -
  44.210 -    /**
  44.211 -     * Tells whether this stream supports the mark() operation. The default
  44.212 -     * implementation always returns false. Subclasses should override this
  44.213 -     * method.
  44.214 -     *
  44.215 -     * @return true if and only if this stream supports the mark operation.
  44.216 -     */
  44.217 -    public boolean markSupported() {
  44.218 -        return false;
  44.219 -    }
  44.220 -
  44.221 -    /**
  44.222 -     * Marks the present position in the stream.  Subsequent calls to reset()
  44.223 -     * will attempt to reposition the stream to this point.  Not all
  44.224 -     * character-input streams support the mark() operation.
  44.225 -     *
  44.226 -     * @param  readAheadLimit  Limit on the number of characters that may be
  44.227 -     *                         read while still preserving the mark.  After
  44.228 -     *                         reading this many characters, attempting to
  44.229 -     *                         reset the stream may fail.
  44.230 -     *
  44.231 -     * @exception  IOException  If the stream does not support mark(),
  44.232 -     *                          or if some other I/O error occurs
  44.233 -     */
  44.234 -    public void mark(int readAheadLimit) throws IOException {
  44.235 -        throw new IOException("mark() not supported");
  44.236 -    }
  44.237 -
  44.238 -    /**
  44.239 -     * Resets the stream.  If the stream has been marked, then attempt to
  44.240 -     * reposition it at the mark.  If the stream has not been marked, then
  44.241 -     * attempt to reset it in some way appropriate to the particular stream,
  44.242 -     * for example by repositioning it to its starting point.  Not all
  44.243 -     * character-input streams support the reset() operation, and some support
  44.244 -     * reset() without supporting mark().
  44.245 -     *
  44.246 -     * @exception  IOException  If the stream has not been marked,
  44.247 -     *                          or if the mark has been invalidated,
  44.248 -     *                          or if the stream does not support reset(),
  44.249 -     *                          or if some other I/O error occurs
  44.250 -     */
  44.251 -    public void reset() throws IOException {
  44.252 -        throw new IOException("reset() not supported");
  44.253 -    }
  44.254 -
  44.255 -    /**
  44.256 -     * Closes the stream and releases any system resources associated with
  44.257 -     * it.  Once the stream has been closed, further read(), ready(),
  44.258 -     * mark(), reset(), or skip() invocations will throw an IOException.
  44.259 -     * Closing a previously closed stream has no effect.
  44.260 -     *
  44.261 -     * @exception  IOException  If an I/O error occurs
  44.262 -     */
  44.263 -     abstract public void close() throws IOException;
  44.264 -
  44.265 -}
    45.1 --- a/emul/compact/src/main/java/java/io/StreamCorruptedException.java	Mon Feb 25 19:00:08 2013 +0100
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,54 +0,0 @@
    45.4 -/*
    45.5 - * Copyright (c) 1996, 2005, 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.io;
   45.30 -
   45.31 -/**
   45.32 - * Thrown when control information that was read from an object stream
   45.33 - * violates internal consistency checks.
   45.34 - *
   45.35 - * @author  unascribed
   45.36 - * @since   JDK1.1
   45.37 - */
   45.38 -public class StreamCorruptedException extends ObjectStreamException {
   45.39 -
   45.40 -    private static final long serialVersionUID = 8983558202217591746L;
   45.41 -
   45.42 -    /**
   45.43 -     * Create a StreamCorruptedException and list a reason why thrown.
   45.44 -     *
   45.45 -     * @param reason  String describing the reason for the exception.
   45.46 -     */
   45.47 -    public StreamCorruptedException(String reason) {
   45.48 -        super(reason);
   45.49 -    }
   45.50 -
   45.51 -    /**
   45.52 -     * Create a StreamCorruptedException and list no reason why thrown.
   45.53 -     */
   45.54 -    public StreamCorruptedException() {
   45.55 -        super();
   45.56 -    }
   45.57 -}
    46.1 --- a/emul/compact/src/main/java/java/io/WriteAbortedException.java	Mon Feb 25 19:00:08 2013 +0100
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,93 +0,0 @@
    46.4 -/*
    46.5 - * Copyright (c) 1996, 2005, 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.io;
   46.30 -
   46.31 -/**
   46.32 - * Signals that one of the ObjectStreamExceptions was thrown during a
   46.33 - * write operation.  Thrown during a read operation when one of the
   46.34 - * ObjectStreamExceptions was thrown during a write operation.  The
   46.35 - * exception that terminated the write can be found in the detail
   46.36 - * field. The stream is reset to it's initial state and all references
   46.37 - * to objects already deserialized are discarded.
   46.38 - *
   46.39 - * <p>As of release 1.4, this exception has been retrofitted to conform to
   46.40 - * the general purpose exception-chaining mechanism.  The "exception causing
   46.41 - * the abort" that is provided at construction time and
   46.42 - * accessed via the public {@link #detail} field is now known as the
   46.43 - * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
   46.44 - * method, as well as the aforementioned "legacy field."
   46.45 - *
   46.46 - * @author  unascribed
   46.47 - * @since   JDK1.1
   46.48 - */
   46.49 -public class WriteAbortedException extends ObjectStreamException {
   46.50 -    private static final long serialVersionUID = -3326426625597282442L;
   46.51 -
   46.52 -    /**
   46.53 -     * Exception that was caught while writing the ObjectStream.
   46.54 -     *
   46.55 -     * <p>This field predates the general-purpose exception chaining facility.
   46.56 -     * The {@link Throwable#getCause()} method is now the preferred means of
   46.57 -     * obtaining this information.
   46.58 -     *
   46.59 -     * @serial
   46.60 -     */
   46.61 -    public Exception detail;
   46.62 -
   46.63 -    /**
   46.64 -     * Constructs a WriteAbortedException with a string describing
   46.65 -     * the exception and the exception causing the abort.
   46.66 -     * @param s   String describing the exception.
   46.67 -     * @param ex  Exception causing the abort.
   46.68 -     */
   46.69 -    public WriteAbortedException(String s, Exception ex) {
   46.70 -        super(s);
   46.71 -        initCause(null);  // Disallow subsequent initCause
   46.72 -        detail = ex;
   46.73 -    }
   46.74 -
   46.75 -    /**
   46.76 -     * Produce the message and include the message from the nested
   46.77 -     * exception, if there is one.
   46.78 -     */
   46.79 -    public String getMessage() {
   46.80 -        if (detail == null)
   46.81 -            return super.getMessage();
   46.82 -        else
   46.83 -            return super.getMessage() + "; " + detail.toString();
   46.84 -    }
   46.85 -
   46.86 -    /**
   46.87 -     * Returns the exception that terminated the operation (the <i>cause</i>).
   46.88 -     *
   46.89 -     * @return  the exception that terminated the operation (the <i>cause</i>),
   46.90 -     *          which may be null.
   46.91 -     * @since   1.4
   46.92 -     */
   46.93 -    public Throwable getCause() {
   46.94 -        return detail;
   46.95 -    }
   46.96 -}
    47.1 --- a/emul/compact/src/main/java/java/lang/AbstractMethodError.java	Mon Feb 25 19:00:08 2013 +0100
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,58 +0,0 @@
    47.4 -/*
    47.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
    47.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    47.7 - *
    47.8 - * This code is free software; you can redistribute it and/or modify it
    47.9 - * under the terms of the GNU General Public License version 2 only, as
   47.10 - * published by the Free Software Foundation.  Oracle designates this
   47.11 - * particular file as subject to the "Classpath" exception as provided
   47.12 - * by Oracle in the LICENSE file that accompanied this code.
   47.13 - *
   47.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   47.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   47.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   47.17 - * version 2 for more details (a copy is included in the LICENSE file that
   47.18 - * accompanied this code).
   47.19 - *
   47.20 - * You should have received a copy of the GNU General Public License version
   47.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   47.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   47.23 - *
   47.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   47.25 - * or visit www.oracle.com if you need additional information or have any
   47.26 - * questions.
   47.27 - */
   47.28 -
   47.29 -package java.lang;
   47.30 -
   47.31 -/**
   47.32 - * Thrown when an application tries to call an abstract method.
   47.33 - * Normally, this error is caught by the compiler; this error can
   47.34 - * only occur at run time if the definition of some class has
   47.35 - * incompatibly changed since the currently executing method was last
   47.36 - * compiled.
   47.37 - *
   47.38 - * @author  unascribed
   47.39 - * @since   JDK1.0
   47.40 - */
   47.41 -public
   47.42 -class AbstractMethodError extends IncompatibleClassChangeError {
   47.43 -    private static final long serialVersionUID = -1654391082989018462L;
   47.44 -
   47.45 -    /**
   47.46 -     * Constructs an <code>AbstractMethodError</code> with no detail  message.
   47.47 -     */
   47.48 -    public AbstractMethodError() {
   47.49 -        super();
   47.50 -    }
   47.51 -
   47.52 -    /**
   47.53 -     * Constructs an <code>AbstractMethodError</code> with the specified
   47.54 -     * detail message.
   47.55 -     *
   47.56 -     * @param   s   the detail message.
   47.57 -     */
   47.58 -    public AbstractMethodError(String s) {
   47.59 -        super(s);
   47.60 -    }
   47.61 -}
    48.1 --- a/emul/compact/src/main/java/java/lang/Cloneable.java	Mon Feb 25 19:00:08 2013 +0100
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,54 +0,0 @@
    48.4 -/*
    48.5 - * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
    48.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    48.7 - *
    48.8 - * This code is free software; you can redistribute it and/or modify it
    48.9 - * under the terms of the GNU General Public License version 2 only, as
   48.10 - * published by the Free Software Foundation.  Oracle designates this
   48.11 - * particular file as subject to the "Classpath" exception as provided
   48.12 - * by Oracle in the LICENSE file that accompanied this code.
   48.13 - *
   48.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   48.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   48.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   48.17 - * version 2 for more details (a copy is included in the LICENSE file that
   48.18 - * accompanied this code).
   48.19 - *
   48.20 - * You should have received a copy of the GNU General Public License version
   48.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   48.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   48.23 - *
   48.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   48.25 - * or visit www.oracle.com if you need additional information or have any
   48.26 - * questions.
   48.27 - */
   48.28 -
   48.29 -package java.lang;
   48.30 -
   48.31 -/**
   48.32 - * A class implements the <code>Cloneable</code> interface to
   48.33 - * indicate to the {@link java.lang.Object#clone()} method that it
   48.34 - * is legal for that method to make a
   48.35 - * field-for-field copy of instances of that class.
   48.36 - * <p>
   48.37 - * Invoking Object's clone method on an instance that does not implement the
   48.38 - * <code>Cloneable</code> interface results in the exception
   48.39 - * <code>CloneNotSupportedException</code> being thrown.
   48.40 - * <p>
   48.41 - * By convention, classes that implement this interface should override
   48.42 - * <tt>Object.clone</tt> (which is protected) with a public method.
   48.43 - * See {@link java.lang.Object#clone()} for details on overriding this
   48.44 - * method.
   48.45 - * <p>
   48.46 - * Note that this interface does <i>not</i> contain the <tt>clone</tt> method.
   48.47 - * Therefore, it is not possible to clone an object merely by virtue of the
   48.48 - * fact that it implements this interface.  Even if the clone method is invoked
   48.49 - * reflectively, there is no guarantee that it will succeed.
   48.50 - *
   48.51 - * @author  unascribed
   48.52 - * @see     java.lang.CloneNotSupportedException
   48.53 - * @see     java.lang.Object#clone()
   48.54 - * @since   JDK1.0
   48.55 - */
   48.56 -public interface Cloneable {
   48.57 -}
    49.1 --- a/emul/compact/src/main/java/java/lang/IncompatibleClassChangeError.java	Mon Feb 25 19:00:08 2013 +0100
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,57 +0,0 @@
    49.4 -/*
    49.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
    49.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    49.7 - *
    49.8 - * This code is free software; you can redistribute it and/or modify it
    49.9 - * under the terms of the GNU General Public License version 2 only, as
   49.10 - * published by the Free Software Foundation.  Oracle designates this
   49.11 - * particular file as subject to the "Classpath" exception as provided
   49.12 - * by Oracle in the LICENSE file that accompanied this code.
   49.13 - *
   49.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   49.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   49.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   49.17 - * version 2 for more details (a copy is included in the LICENSE file that
   49.18 - * accompanied this code).
   49.19 - *
   49.20 - * You should have received a copy of the GNU General Public License version
   49.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   49.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   49.23 - *
   49.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   49.25 - * or visit www.oracle.com if you need additional information or have any
   49.26 - * questions.
   49.27 - */
   49.28 -
   49.29 -package java.lang;
   49.30 -
   49.31 -/**
   49.32 - * Thrown when an incompatible class change has occurred to some class
   49.33 - * definition. The definition of some class, on which the currently
   49.34 - * executing method depends, has since changed.
   49.35 - *
   49.36 - * @author  unascribed
   49.37 - * @since   JDK1.0
   49.38 - */
   49.39 -public
   49.40 -class IncompatibleClassChangeError extends LinkageError {
   49.41 -    private static final long serialVersionUID = -4914975503642802119L;
   49.42 -
   49.43 -    /**
   49.44 -     * Constructs an <code>IncompatibleClassChangeError</code> with no
   49.45 -     * detail message.
   49.46 -     */
   49.47 -    public IncompatibleClassChangeError () {
   49.48 -        super();
   49.49 -    }
   49.50 -
   49.51 -    /**
   49.52 -     * Constructs an <code>IncompatibleClassChangeError</code> with the
   49.53 -     * specified detail message.
   49.54 -     *
   49.55 -     * @param   s   the detail message.
   49.56 -     */
   49.57 -    public IncompatibleClassChangeError(String s) {
   49.58 -        super(s);
   49.59 -    }
   49.60 -}
    50.1 --- a/emul/compact/src/main/java/java/lang/InternalError.java	Mon Feb 25 19:00:08 2013 +0100
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,55 +0,0 @@
    50.4 -/*
    50.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
    50.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    50.7 - *
    50.8 - * This code is free software; you can redistribute it and/or modify it
    50.9 - * under the terms of the GNU General Public License version 2 only, as
   50.10 - * published by the Free Software Foundation.  Oracle designates this
   50.11 - * particular file as subject to the "Classpath" exception as provided
   50.12 - * by Oracle in the LICENSE file that accompanied this code.
   50.13 - *
   50.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   50.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   50.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   50.17 - * version 2 for more details (a copy is included in the LICENSE file that
   50.18 - * accompanied this code).
   50.19 - *
   50.20 - * You should have received a copy of the GNU General Public License version
   50.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   50.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   50.23 - *
   50.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   50.25 - * or visit www.oracle.com if you need additional information or have any
   50.26 - * questions.
   50.27 - */
   50.28 -
   50.29 -package java.lang;
   50.30 -
   50.31 -/**
   50.32 - * Thrown to indicate some unexpected internal error has occurred in
   50.33 - * the Java Virtual Machine.
   50.34 - *
   50.35 - * @author  unascribed
   50.36 - * @since   JDK1.0
   50.37 - */
   50.38 -public
   50.39 -class InternalError extends VirtualMachineError {
   50.40 -    private static final long serialVersionUID = -9062593416125562365L;
   50.41 -
   50.42 -    /**
   50.43 -     * Constructs an <code>InternalError</code> with no detail message.
   50.44 -     */
   50.45 -    public InternalError() {
   50.46 -        super();
   50.47 -    }
   50.48 -
   50.49 -    /**
   50.50 -     * Constructs an <code>InternalError</code> with the specified
   50.51 -     * detail message.
   50.52 -     *
   50.53 -     * @param   s   the detail message.
   50.54 -     */
   50.55 -    public InternalError(String s) {
   50.56 -        super(s);
   50.57 -    }
   50.58 -}
    51.1 --- a/emul/compact/src/main/java/java/lang/Iterable.java	Mon Feb 25 19:00:08 2013 +0100
    51.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.3 @@ -1,46 +0,0 @@
    51.4 -/*
    51.5 - * Copyright (c) 2003, 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.lang;
   51.30 -
   51.31 -import java.util.Iterator;
   51.32 -
   51.33 -/**
   51.34 - * Implementing this interface allows an object to be the target of
   51.35 - * the "foreach" statement.
   51.36 - *
   51.37 - * @param <T> the type of elements returned by the iterator
   51.38 - *
   51.39 - * @since 1.5
   51.40 - */
   51.41 -public interface Iterable<T> {
   51.42 -
   51.43 -    /**
   51.44 -     * Returns an iterator over a set of elements of type T.
   51.45 -     *
   51.46 -     * @return an Iterator.
   51.47 -     */
   51.48 -    Iterator<T> iterator();
   51.49 -}
    52.1 --- a/emul/compact/src/main/java/java/lang/NoSuchFieldError.java	Mon Feb 25 19:00:08 2013 +0100
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,59 +0,0 @@
    52.4 -/*
    52.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
    52.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    52.7 - *
    52.8 - * This code is free software; you can redistribute it and/or modify it
    52.9 - * under the terms of the GNU General Public License version 2 only, as
   52.10 - * published by the Free Software Foundation.  Oracle designates this
   52.11 - * particular file as subject to the "Classpath" exception as provided
   52.12 - * by Oracle in the LICENSE file that accompanied this code.
   52.13 - *
   52.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   52.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   52.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   52.17 - * version 2 for more details (a copy is included in the LICENSE file that
   52.18 - * accompanied this code).
   52.19 - *
   52.20 - * You should have received a copy of the GNU General Public License version
   52.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   52.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   52.23 - *
   52.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   52.25 - * or visit www.oracle.com if you need additional information or have any
   52.26 - * questions.
   52.27 - */
   52.28 -
   52.29 -package java.lang;
   52.30 -
   52.31 -/**
   52.32 - * Thrown if an application tries to access or modify a specified
   52.33 - * field of an object, and that object no longer has that field.
   52.34 - * <p>
   52.35 - * Normally, this error is caught by the compiler; this error can
   52.36 - * only occur at run time if the definition of a class has
   52.37 - * incompatibly changed.
   52.38 - *
   52.39 - * @author  unascribed
   52.40 - * @since   JDK1.0
   52.41 - */
   52.42 -public
   52.43 -class NoSuchFieldError extends IncompatibleClassChangeError {
   52.44 -    private static final long serialVersionUID = -3456430195886129035L;
   52.45 -
   52.46 -    /**
   52.47 -     * Constructs a <code>NoSuchFieldError</code> with no detail message.
   52.48 -     */
   52.49 -    public NoSuchFieldError() {
   52.50 -        super();
   52.51 -    }
   52.52 -
   52.53 -    /**
   52.54 -     * Constructs a <code>NoSuchFieldError</code> with the specified
   52.55 -     * detail message.
   52.56 -     *
   52.57 -     * @param   s   the detail message.
   52.58 -     */
   52.59 -    public NoSuchFieldError(String s) {
   52.60 -        super(s);
   52.61 -    }
   52.62 -}
    53.1 --- a/emul/compact/src/main/java/java/lang/Readable.java	Mon Feb 25 19:00:08 2013 +0100
    53.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.3 @@ -1,55 +0,0 @@
    53.4 -/*
    53.5 - * Copyright (c) 2003, 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.lang;
   53.30 -
   53.31 -import java.io.IOException;
   53.32 -
   53.33 -/**
   53.34 - * A <tt>Readable</tt> is a source of characters. Characters from
   53.35 - * a <tt>Readable</tt> are made available to callers of the read
   53.36 - * method via a {@link java.nio.CharBuffer CharBuffer}.
   53.37 - *
   53.38 - * @since 1.5
   53.39 - */
   53.40 -
   53.41 -public interface Readable {
   53.42 -
   53.43 -    /**
   53.44 -     * Attempts to read characters into the specified character buffer.
   53.45 -     * The buffer is used as a repository of characters as-is: the only
   53.46 -     * changes made are the results of a put operation. No flipping or
   53.47 -     * rewinding of the buffer is performed.
   53.48 -     *
   53.49 -     * @param cb the buffer to read characters into
   53.50 -     * @return The number of {@code char} values added to the buffer,
   53.51 -     *                 or -1 if this source of characters is at its end
   53.52 -     * @throws IOException if an I/O error occurs
   53.53 -     * @throws NullPointerException if cb is null
   53.54 -     * @throws java.nio.ReadOnlyBufferException if cb is a read only buffer
   53.55 -     */
   53.56 -// XXX:    public int read(java.nio.CharBuffer cb) throws IOException;
   53.57 -
   53.58 -}
    54.1 --- a/emul/compact/src/main/java/java/lang/SafeVarargs.java	Mon Feb 25 19:00:08 2013 +0100
    54.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.3 @@ -1,91 +0,0 @@
    54.4 -/*
    54.5 - * Copyright (c) 2010, 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.lang;
   54.30 -
   54.31 -import java.lang.annotation.*;
   54.32 -
   54.33 -/**
   54.34 - * A programmer assertion that the body of the annotated method or
   54.35 - * constructor does not perform potentially unsafe operations on its
   54.36 - * varargs parameter.  Applying this annotation to a method or
   54.37 - * constructor suppresses unchecked warnings about a
   54.38 - * <i>non-reifiable</i> variable arity (vararg) type and suppresses
   54.39 - * unchecked warnings about parameterized array creation at call
   54.40 - * sites.
   54.41 - *
   54.42 - * <p> In addition to the usage restrictions imposed by its {@link
   54.43 - * Target @Target} meta-annotation, compilers are required to implement
   54.44 - * additional usage restrictions on this annotation type; it is a
   54.45 - * compile-time error if a method or constructor declaration is
   54.46 - * annotated with a {@code @SafeVarargs} annotation, and either:
   54.47 - * <ul>
   54.48 - * <li>  the declaration is a fixed arity method or constructor
   54.49 - *
   54.50 - * <li> the declaration is a variable arity method that is neither
   54.51 - * {@code static} nor {@code final}.
   54.52 - *
   54.53 - * </ul>
   54.54 - *
   54.55 - * <p> Compilers are encouraged to issue warnings when this annotation
   54.56 - * type is applied to a method or constructor declaration where:
   54.57 - *
   54.58 - * <ul>
   54.59 - *
   54.60 - * <li> The variable arity parameter has a reifiable element type,
   54.61 - * which includes primitive types, {@code Object}, and {@code String}.
   54.62 - * (The unchecked warnings this annotation type suppresses already do
   54.63 - * not occur for a reifiable element type.)
   54.64 - *
   54.65 - * <li> The body of the method or constructor declaration performs
   54.66 - * potentially unsafe operations, such as an assignment to an element
   54.67 - * of the variable arity parameter's array that generates an unchecked
   54.68 - * warning.  Some unsafe operations do not trigger an unchecked
   54.69 - * warning.  For example, the aliasing in
   54.70 - *
   54.71 - * <blockquote><pre>
   54.72 - * &#64;SafeVarargs // Not actually safe!
   54.73 - * static void m(List&lt;String&gt;... stringLists) {
   54.74 - *   Object[] array = stringLists;
   54.75 - *   List&lt;Integer&gt; tmpList = Arrays.asList(42);
   54.76 - *   array[0] = tmpList; // Semantically invalid, but compiles without warnings
   54.77 - *   String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime!
   54.78 - * }
   54.79 - * </pre></blockquote>
   54.80 - *
   54.81 - * leads to a {@code ClassCastException} at runtime.
   54.82 - *
   54.83 - * <p>Future versions of the platform may mandate compiler errors for
   54.84 - * such unsafe operations.
   54.85 - *
   54.86 - * </ul>
   54.87 - *
   54.88 - * @jls 4.7 Reifiable Types
   54.89 - * @jls 8.4.1 Formal Parameters
   54.90 - */
   54.91 -@Documented
   54.92 -@Retention(RetentionPolicy.RUNTIME)
   54.93 -@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
   54.94 -public @interface SafeVarargs {}
    55.1 --- a/emul/compact/src/main/java/java/lang/SuppressWarnings.java	Mon Feb 25 19:00:08 2013 +0100
    55.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.3 @@ -1,64 +0,0 @@
    55.4 -/*
    55.5 - * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
    55.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    55.7 - *
    55.8 - * This code is free software; you can redistribute it and/or modify it
    55.9 - * under the terms of the GNU General Public License version 2 only, as
   55.10 - * published by the Free Software Foundation.  Oracle designates this
   55.11 - * particular file as subject to the "Classpath" exception as provided
   55.12 - * by Oracle in the LICENSE file that accompanied this code.
   55.13 - *
   55.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   55.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   55.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   55.17 - * version 2 for more details (a copy is included in the LICENSE file that
   55.18 - * accompanied this code).
   55.19 - *
   55.20 - * You should have received a copy of the GNU General Public License version
   55.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   55.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   55.23 - *
   55.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   55.25 - * or visit www.oracle.com if you need additional information or have any
   55.26 - * questions.
   55.27 - */
   55.28 -
   55.29 -package java.lang;
   55.30 -
   55.31 -import java.lang.annotation.*;
   55.32 -import static java.lang.annotation.ElementType.*;
   55.33 -
   55.34 -/**
   55.35 - * Indicates that the named compiler warnings should be suppressed in the
   55.36 - * annotated element (and in all program elements contained in the annotated
   55.37 - * element).  Note that the set of warnings suppressed in a given element is
   55.38 - * a superset of the warnings suppressed in all containing elements.  For
   55.39 - * example, if you annotate a class to suppress one warning and annotate a
   55.40 - * method to suppress another, both warnings will be suppressed in the method.
   55.41 - *
   55.42 - * <p>As a matter of style, programmers should always use this annotation
   55.43 - * on the most deeply nested element where it is effective.  If you want to
   55.44 - * suppress a warning in a particular method, you should annotate that
   55.45 - * method rather than its class.
   55.46 - *
   55.47 - * @since 1.5
   55.48 - * @author Josh Bloch
   55.49 - */
   55.50 -@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
   55.51 -@Retention(RetentionPolicy.SOURCE)
   55.52 -public @interface SuppressWarnings {
   55.53 -    /**
   55.54 -     * The set of warnings that are to be suppressed by the compiler in the
   55.55 -     * annotated element.  Duplicate names are permitted.  The second and
   55.56 -     * successive occurrences of a name are ignored.  The presence of
   55.57 -     * unrecognized warning names is <i>not</i> an error: Compilers must
   55.58 -     * ignore any warning names they do not recognize.  They are, however,
   55.59 -     * free to emit a warning if an annotation contains an unrecognized
   55.60 -     * warning name.
   55.61 -     *
   55.62 -     * <p>Compiler vendors should document the warning names they support in
   55.63 -     * conjunction with this annotation type. They are encouraged to cooperate
   55.64 -     * to ensure that the same names work across multiple compilers.
   55.65 -     */
   55.66 -    String[] value();
   55.67 -}
    56.1 --- a/emul/compact/src/main/java/java/lang/System.java	Mon Feb 25 19:00:08 2013 +0100
    56.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.3 @@ -1,36 +0,0 @@
    56.4 -/**
    56.5 - * Back 2 Browser Bytecode Translator
    56.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    56.7 - *
    56.8 - * This program is free software: you can redistribute it and/or modify
    56.9 - * it under the terms of the GNU General Public License as published by
   56.10 - * the Free Software Foundation, version 2 of the License.
   56.11 - *
   56.12 - * This program is distributed in the hope that it will be useful,
   56.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   56.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   56.15 - * GNU General Public License for more details.
   56.16 - *
   56.17 - * You should have received a copy of the GNU General Public License
   56.18 - * along with this program. Look for COPYING file in the top folder.
   56.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   56.20 - */
   56.21 -package java.lang;
   56.22 -
   56.23 -/** Poor man's re-implementation of most important System methods.
   56.24 - *
   56.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   56.26 - */
   56.27 -public class System {
   56.28 -    private System() {
   56.29 -    }
   56.30 -    
   56.31 -    public static void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count) {
   56.32 -        org.apidesign.bck2brwsr.emul.lang.System.arraycopy(value, srcBegin, dst, dstBegin, count);
   56.33 -    }
   56.34 -    
   56.35 -    public static long currentTimeMillis() {
   56.36 -        return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
   56.37 -    }
   56.38 -    
   56.39 -}
    57.1 --- a/emul/compact/src/main/java/java/lang/ref/PhantomReference.java	Mon Feb 25 19:00:08 2013 +0100
    57.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.3 @@ -1,83 +0,0 @@
    57.4 -/*
    57.5 - * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
    57.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    57.7 - *
    57.8 - * This code is free software; you can redistribute it and/or modify it
    57.9 - * under the terms of the GNU General Public License version 2 only, as
   57.10 - * published by the Free Software Foundation.  Oracle designates this
   57.11 - * particular file as subject to the "Classpath" exception as provided
   57.12 - * by Oracle in the LICENSE file that accompanied this code.
   57.13 - *
   57.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   57.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   57.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   57.17 - * version 2 for more details (a copy is included in the LICENSE file that
   57.18 - * accompanied this code).
   57.19 - *
   57.20 - * You should have received a copy of the GNU General Public License version
   57.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   57.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   57.23 - *
   57.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   57.25 - * or visit www.oracle.com if you need additional information or have any
   57.26 - * questions.
   57.27 - */
   57.28 -
   57.29 -package java.lang.ref;
   57.30 -
   57.31 -
   57.32 -/**
   57.33 - * Phantom reference objects, which are enqueued after the collector
   57.34 - * determines that their referents may otherwise be reclaimed.  Phantom
   57.35 - * references are most often used for scheduling pre-mortem cleanup actions in
   57.36 - * a more flexible way than is possible with the Java finalization mechanism.
   57.37 - *
   57.38 - * <p> If the garbage collector determines at a certain point in time that the
   57.39 - * referent of a phantom reference is <a
   57.40 - * href="package-summary.html#reachability">phantom reachable</a>, then at that
   57.41 - * time or at some later time it will enqueue the reference.
   57.42 - *
   57.43 - * <p> In order to ensure that a reclaimable object remains so, the referent of
   57.44 - * a phantom reference may not be retrieved: The <code>get</code> method of a
   57.45 - * phantom reference always returns <code>null</code>.
   57.46 - *
   57.47 - * <p> Unlike soft and weak references, phantom references are not
   57.48 - * automatically cleared by the garbage collector as they are enqueued.  An
   57.49 - * object that is reachable via phantom references will remain so until all
   57.50 - * such references are cleared or themselves become unreachable.
   57.51 - *
   57.52 - * @author   Mark Reinhold
   57.53 - * @since    1.2
   57.54 - */
   57.55 -
   57.56 -public class PhantomReference<T> extends Reference<T> {
   57.57 -
   57.58 -    /**
   57.59 -     * Returns this reference object's referent.  Because the referent of a
   57.60 -     * phantom reference is always inaccessible, this method always returns
   57.61 -     * <code>null</code>.
   57.62 -     *
   57.63 -     * @return  <code>null</code>
   57.64 -     */
   57.65 -    public T get() {
   57.66 -        return null;
   57.67 -    }
   57.68 -
   57.69 -    /**
   57.70 -     * Creates a new phantom reference that refers to the given object and
   57.71 -     * is registered with the given queue.
   57.72 -     *
   57.73 -     * <p> It is possible to create a phantom reference with a <tt>null</tt>
   57.74 -     * queue, but such a reference is completely useless: Its <tt>get</tt>
   57.75 -     * method will always return null and, since it does not have a queue, it
   57.76 -     * will never be enqueued.
   57.77 -     *
   57.78 -     * @param referent the object the new phantom reference will refer to
   57.79 -     * @param q the queue with which the reference is to be registered,
   57.80 -     *          or <tt>null</tt> if registration is not required
   57.81 -     */
   57.82 -    public PhantomReference(T referent, ReferenceQueue<? super T> q) {
   57.83 -        super(referent, q);
   57.84 -    }
   57.85 -
   57.86 -}
    58.1 --- a/emul/compact/src/main/java/java/lang/ref/Reference.java	Mon Feb 25 19:00:08 2013 +0100
    58.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.3 @@ -1,185 +0,0 @@
    58.4 -/*
    58.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
    58.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    58.7 - *
    58.8 - * This code is free software; you can redistribute it and/or modify it
    58.9 - * under the terms of the GNU General Public License version 2 only, as
   58.10 - * published by the Free Software Foundation.  Oracle designates this
   58.11 - * particular file as subject to the "Classpath" exception as provided
   58.12 - * by Oracle in the LICENSE file that accompanied this code.
   58.13 - *
   58.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   58.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   58.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   58.17 - * version 2 for more details (a copy is included in the LICENSE file that
   58.18 - * accompanied this code).
   58.19 - *
   58.20 - * You should have received a copy of the GNU General Public License version
   58.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   58.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   58.23 - *
   58.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   58.25 - * or visit www.oracle.com if you need additional information or have any
   58.26 - * questions.
   58.27 - */
   58.28 -
   58.29 -package java.lang.ref;
   58.30 -
   58.31 -
   58.32 -/**
   58.33 - * Abstract base class for reference objects.  This class defines the
   58.34 - * operations common to all reference objects.  Because reference objects are
   58.35 - * implemented in close cooperation with the garbage collector, this class may
   58.36 - * not be subclassed directly.
   58.37 - *
   58.38 - * @author   Mark Reinhold
   58.39 - * @since    1.2
   58.40 - */
   58.41 -
   58.42 -public abstract class Reference<T> {
   58.43 -
   58.44 -    /* A Reference instance is in one of four possible internal states:
   58.45 -     *
   58.46 -     *     Active: Subject to special treatment by the garbage collector.  Some
   58.47 -     *     time after the collector detects that the reachability of the
   58.48 -     *     referent has changed to the appropriate state, it changes the
   58.49 -     *     instance's state to either Pending or Inactive, depending upon
   58.50 -     *     whether or not the instance was registered with a queue when it was
   58.51 -     *     created.  In the former case it also adds the instance to the
   58.52 -     *     pending-Reference list.  Newly-created instances are Active.
   58.53 -     *
   58.54 -     *     Pending: An element of the pending-Reference list, waiting to be
   58.55 -     *     enqueued by the Reference-handler thread.  Unregistered instances
   58.56 -     *     are never in this state.
   58.57 -     *
   58.58 -     *     Enqueued: An element of the queue with which the instance was
   58.59 -     *     registered when it was created.  When an instance is removed from
   58.60 -     *     its ReferenceQueue, it is made Inactive.  Unregistered instances are
   58.61 -     *     never in this state.
   58.62 -     *
   58.63 -     *     Inactive: Nothing more to do.  Once an instance becomes Inactive its
   58.64 -     *     state will never change again.
   58.65 -     *
   58.66 -     * The state is encoded in the queue and next fields as follows:
   58.67 -     *
   58.68 -     *     Active: queue = ReferenceQueue with which instance is registered, or
   58.69 -     *     ReferenceQueue.NULL if it was not registered with a queue; next =
   58.70 -     *     null.
   58.71 -     *
   58.72 -     *     Pending: queue = ReferenceQueue with which instance is registered;
   58.73 -     *     next = Following instance in queue, or this if at end of list.
   58.74 -     *
   58.75 -     *     Enqueued: queue = ReferenceQueue.ENQUEUED; next = Following instance
   58.76 -     *     in queue, or this if at end of list.
   58.77 -     *
   58.78 -     *     Inactive: queue = ReferenceQueue.NULL; next = this.
   58.79 -     *
   58.80 -     * With this scheme the collector need only examine the next field in order
   58.81 -     * to determine whether a Reference instance requires special treatment: If
   58.82 -     * the next field is null then the instance is active; if it is non-null,
   58.83 -     * then the collector should treat the instance normally.
   58.84 -     *
   58.85 -     * To ensure that concurrent collector can discover active Reference
   58.86 -     * objects without interfering with application threads that may apply
   58.87 -     * the enqueue() method to those objects, collectors should link
   58.88 -     * discovered objects through the discovered field.
   58.89 -     */
   58.90 -
   58.91 -    private T referent;         /* Treated specially by GC */
   58.92 -
   58.93 -    ReferenceQueue<? super T> queue;
   58.94 -
   58.95 -    Reference next;
   58.96 -    transient private Reference<T> discovered;  /* used by VM */
   58.97 -
   58.98 -
   58.99 -    /* Object used to synchronize with the garbage collector.  The collector
  58.100 -     * must acquire this lock at the beginning of each collection cycle.  It is
  58.101 -     * therefore critical that any code holding this lock complete as quickly
  58.102 -     * as possible, allocate no new objects, and avoid calling user code.
  58.103 -     */
  58.104 -    static private class Lock { };
  58.105 -    private static Lock lock = new Lock();
  58.106 -
  58.107 -
  58.108 -    /* List of References waiting to be enqueued.  The collector adds
  58.109 -     * References to this list, while the Reference-handler thread removes
  58.110 -     * them.  This list is protected by the above lock object.
  58.111 -     */
  58.112 -    private static Reference pending = null;
  58.113 -
  58.114 -
  58.115 -
  58.116 -    /* -- Referent accessor and setters -- */
  58.117 -
  58.118 -    /**
  58.119 -     * Returns this reference object's referent.  If this reference object has
  58.120 -     * been cleared, either by the program or by the garbage collector, then
  58.121 -     * this method returns <code>null</code>.
  58.122 -     *
  58.123 -     * @return   The object to which this reference refers, or
  58.124 -     *           <code>null</code> if this reference object has been cleared
  58.125 -     */
  58.126 -    public T get() {
  58.127 -        return this.referent;
  58.128 -    }
  58.129 -
  58.130 -    /**
  58.131 -     * Clears this reference object.  Invoking this method will not cause this
  58.132 -     * object to be enqueued.
  58.133 -     *
  58.134 -     * <p> This method is invoked only by Java code; when the garbage collector
  58.135 -     * clears references it does so directly, without invoking this method.
  58.136 -     */
  58.137 -    public void clear() {
  58.138 -        this.referent = null;
  58.139 -    }
  58.140 -
  58.141 -
  58.142 -    /* -- Queue operations -- */
  58.143 -
  58.144 -    /**
  58.145 -     * Tells whether or not this reference object has been enqueued, either by
  58.146 -     * the program or by the garbage collector.  If this reference object was
  58.147 -     * not registered with a queue when it was created, then this method will
  58.148 -     * always return <code>false</code>.
  58.149 -     *
  58.150 -     * @return   <code>true</code> if and only if this reference object has
  58.151 -     *           been enqueued
  58.152 -     */
  58.153 -    public boolean isEnqueued() {
  58.154 -        /* In terms of the internal states, this predicate actually tests
  58.155 -           whether the instance is either Pending or Enqueued */
  58.156 -        synchronized (this) {
  58.157 -            return (this.queue != ReferenceQueue.NULL) && (this.next != null);
  58.158 -        }
  58.159 -    }
  58.160 -
  58.161 -    /**
  58.162 -     * Adds this reference object to the queue with which it is registered,
  58.163 -     * if any.
  58.164 -     *
  58.165 -     * <p> This method is invoked only by Java code; when the garbage collector
  58.166 -     * enqueues references it does so directly, without invoking this method.
  58.167 -     *
  58.168 -     * @return   <code>true</code> if this reference object was successfully
  58.169 -     *           enqueued; <code>false</code> if it was already enqueued or if
  58.170 -     *           it was not registered with a queue when it was created
  58.171 -     */
  58.172 -    public boolean enqueue() {
  58.173 -        return this.queue.enqueue(this);
  58.174 -    }
  58.175 -
  58.176 -
  58.177 -    /* -- Constructors -- */
  58.178 -
  58.179 -    Reference(T referent) {
  58.180 -        this(referent, null);
  58.181 -    }
  58.182 -
  58.183 -    Reference(T referent, ReferenceQueue<? super T> queue) {
  58.184 -        this.referent = referent;
  58.185 -        this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
  58.186 -    }
  58.187 -
  58.188 -}
    59.1 --- a/emul/compact/src/main/java/java/lang/ref/ReferenceQueue.java	Mon Feb 25 19:00:08 2013 +0100
    59.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.3 @@ -1,148 +0,0 @@
    59.4 -/*
    59.5 - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
    59.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    59.7 - *
    59.8 - * This code is free software; you can redistribute it and/or modify it
    59.9 - * under the terms of the GNU General Public License version 2 only, as
   59.10 - * published by the Free Software Foundation.  Oracle designates this
   59.11 - * particular file as subject to the "Classpath" exception as provided
   59.12 - * by Oracle in the LICENSE file that accompanied this code.
   59.13 - *
   59.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   59.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   59.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   59.17 - * version 2 for more details (a copy is included in the LICENSE file that
   59.18 - * accompanied this code).
   59.19 - *
   59.20 - * You should have received a copy of the GNU General Public License version
   59.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   59.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   59.23 - *
   59.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   59.25 - * or visit www.oracle.com if you need additional information or have any
   59.26 - * questions.
   59.27 - */
   59.28 -
   59.29 -package java.lang.ref;
   59.30 -
   59.31 -/**
   59.32 - * Reference queues, to which registered reference objects are appended by the
   59.33 - * garbage collector after the appropriate reachability changes are detected.
   59.34 - *
   59.35 - * @author   Mark Reinhold
   59.36 - * @since    1.2
   59.37 - */
   59.38 -
   59.39 -public class ReferenceQueue<T> {
   59.40 -
   59.41 -    /**
   59.42 -     * Constructs a new reference-object queue.
   59.43 -     */
   59.44 -    public ReferenceQueue() { }
   59.45 -
   59.46 -    private static class Null extends ReferenceQueue {
   59.47 -        boolean enqueue(Reference r) {
   59.48 -            return false;
   59.49 -        }
   59.50 -    }
   59.51 -
   59.52 -    static ReferenceQueue NULL = new Null();
   59.53 -    static ReferenceQueue ENQUEUED = new Null();
   59.54 -
   59.55 -    static private class Lock { };
   59.56 -    private Lock lock = new Lock();
   59.57 -    private volatile Reference<? extends T> head = null;
   59.58 -    private long queueLength = 0;
   59.59 -
   59.60 -    boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */
   59.61 -        synchronized (r) {
   59.62 -            if (r.queue == ENQUEUED) return false;
   59.63 -            synchronized (lock) {
   59.64 -                r.queue = ENQUEUED;
   59.65 -                r.next = (head == null) ? r : head;
   59.66 -                head = r;
   59.67 -                queueLength++;
   59.68 -                lock.notifyAll();
   59.69 -                return true;
   59.70 -            }
   59.71 -        }
   59.72 -    }
   59.73 -
   59.74 -    private Reference<? extends T> reallyPoll() {       /* Must hold lock */
   59.75 -        if (head != null) {
   59.76 -            Reference<? extends T> r = head;
   59.77 -            head = (r.next == r) ? null : r.next;
   59.78 -            r.queue = NULL;
   59.79 -            r.next = r;
   59.80 -            queueLength--;
   59.81 -            return r;
   59.82 -        }
   59.83 -        return null;
   59.84 -    }
   59.85 -
   59.86 -    /**
   59.87 -     * Polls this queue to see if a reference object is available.  If one is
   59.88 -     * available without further delay then it is removed from the queue and
   59.89 -     * returned.  Otherwise this method immediately returns <tt>null</tt>.
   59.90 -     *
   59.91 -     * @return  A reference object, if one was immediately available,
   59.92 -     *          otherwise <code>null</code>
   59.93 -     */
   59.94 -    public Reference<? extends T> poll() {
   59.95 -        if (head == null)
   59.96 -            return null;
   59.97 -        synchronized (lock) {
   59.98 -            return reallyPoll();
   59.99 -        }
  59.100 -    }
  59.101 -
  59.102 -    /**
  59.103 -     * Removes the next reference object in this queue, blocking until either
  59.104 -     * one becomes available or the given timeout period expires.
  59.105 -     *
  59.106 -     * <p> This method does not offer real-time guarantees: It schedules the
  59.107 -     * timeout as if by invoking the {@link Object#wait(long)} method.
  59.108 -     *
  59.109 -     * @param  timeout  If positive, block for up to <code>timeout</code>
  59.110 -     *                  milliseconds while waiting for a reference to be
  59.111 -     *                  added to this queue.  If zero, block indefinitely.
  59.112 -     *
  59.113 -     * @return  A reference object, if one was available within the specified
  59.114 -     *          timeout period, otherwise <code>null</code>
  59.115 -     *
  59.116 -     * @throws  IllegalArgumentException
  59.117 -     *          If the value of the timeout argument is negative
  59.118 -     *
  59.119 -     * @throws  InterruptedException
  59.120 -     *          If the timeout wait is interrupted
  59.121 -     */
  59.122 -    public Reference<? extends T> remove(long timeout)
  59.123 -        throws IllegalArgumentException, InterruptedException
  59.124 -    {
  59.125 -        if (timeout < 0) {
  59.126 -            throw new IllegalArgumentException("Negative timeout value");
  59.127 -        }
  59.128 -        synchronized (lock) {
  59.129 -            Reference<? extends T> r = reallyPoll();
  59.130 -            if (r != null) return r;
  59.131 -            for (;;) {
  59.132 -                lock.wait(timeout);
  59.133 -                r = reallyPoll();
  59.134 -                if (r != null) return r;
  59.135 -                if (timeout != 0) return null;
  59.136 -            }
  59.137 -        }
  59.138 -    }
  59.139 -
  59.140 -    /**
  59.141 -     * Removes the next reference object in this queue, blocking until one
  59.142 -     * becomes available.
  59.143 -     *
  59.144 -     * @return A reference object, blocking until one becomes available
  59.145 -     * @throws  InterruptedException  If the wait is interrupted
  59.146 -     */
  59.147 -    public Reference<? extends T> remove() throws InterruptedException {
  59.148 -        return remove(0);
  59.149 -    }
  59.150 -
  59.151 -}
    60.1 --- a/emul/compact/src/main/java/java/lang/ref/SoftReference.java	Mon Feb 25 19:00:08 2013 +0100
    60.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.3 @@ -1,118 +0,0 @@
    60.4 -/*
    60.5 - * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
    60.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    60.7 - *
    60.8 - * This code is free software; you can redistribute it and/or modify it
    60.9 - * under the terms of the GNU General Public License version 2 only, as
   60.10 - * published by the Free Software Foundation.  Oracle designates this
   60.11 - * particular file as subject to the "Classpath" exception as provided
   60.12 - * by Oracle in the LICENSE file that accompanied this code.
   60.13 - *
   60.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   60.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   60.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   60.17 - * version 2 for more details (a copy is included in the LICENSE file that
   60.18 - * accompanied this code).
   60.19 - *
   60.20 - * You should have received a copy of the GNU General Public License version
   60.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   60.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   60.23 - *
   60.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   60.25 - * or visit www.oracle.com if you need additional information or have any
   60.26 - * questions.
   60.27 - */
   60.28 -
   60.29 -package java.lang.ref;
   60.30 -
   60.31 -
   60.32 -/**
   60.33 - * Soft reference objects, which are cleared at the discretion of the garbage
   60.34 - * collector in response to memory demand.  Soft references are most often used
   60.35 - * to implement memory-sensitive caches.
   60.36 - *
   60.37 - * <p> Suppose that the garbage collector determines at a certain point in time
   60.38 - * that an object is <a href="package-summary.html#reachability">softly
   60.39 - * reachable</a>.  At that time it may choose to clear atomically all soft
   60.40 - * references to that object and all soft references to any other
   60.41 - * softly-reachable objects from which that object is reachable through a chain
   60.42 - * of strong references.  At the same time or at some later time it will
   60.43 - * enqueue those newly-cleared soft references that are registered with
   60.44 - * reference queues.
   60.45 - *
   60.46 - * <p> All soft references to softly-reachable objects are guaranteed to have
   60.47 - * been cleared before the virtual machine throws an
   60.48 - * <code>OutOfMemoryError</code>.  Otherwise no constraints are placed upon the
   60.49 - * time at which a soft reference will be cleared or the order in which a set
   60.50 - * of such references to different objects will be cleared.  Virtual machine
   60.51 - * implementations are, however, encouraged to bias against clearing
   60.52 - * recently-created or recently-used soft references.
   60.53 - *
   60.54 - * <p> Direct instances of this class may be used to implement simple caches;
   60.55 - * this class or derived subclasses may also be used in larger data structures
   60.56 - * to implement more sophisticated caches.  As long as the referent of a soft
   60.57 - * reference is strongly reachable, that is, is actually in use, the soft
   60.58 - * reference will not be cleared.  Thus a sophisticated cache can, for example,
   60.59 - * prevent its most recently used entries from being discarded by keeping
   60.60 - * strong referents to those entries, leaving the remaining entries to be
   60.61 - * discarded at the discretion of the garbage collector.
   60.62 - *
   60.63 - * @author   Mark Reinhold
   60.64 - * @since    1.2
   60.65 - */
   60.66 -
   60.67 -public class SoftReference<T> extends Reference<T> {
   60.68 -
   60.69 -    /**
   60.70 -     * Timestamp clock, updated by the garbage collector
   60.71 -     */
   60.72 -    static private long clock;
   60.73 -
   60.74 -    /**
   60.75 -     * Timestamp updated by each invocation of the get method.  The VM may use
   60.76 -     * this field when selecting soft references to be cleared, but it is not
   60.77 -     * required to do so.
   60.78 -     */
   60.79 -    private long timestamp;
   60.80 -
   60.81 -    /**
   60.82 -     * Creates a new soft reference that refers to the given object.  The new
   60.83 -     * reference is not registered with any queue.
   60.84 -     *
   60.85 -     * @param referent object the new soft reference will refer to
   60.86 -     */
   60.87 -    public SoftReference(T referent) {
   60.88 -        super(referent);
   60.89 -        this.timestamp = clock;
   60.90 -    }
   60.91 -
   60.92 -    /**
   60.93 -     * Creates a new soft reference that refers to the given object and is
   60.94 -     * registered with the given queue.
   60.95 -     *
   60.96 -     * @param referent object the new soft reference will refer to
   60.97 -     * @param q the queue with which the reference is to be registered,
   60.98 -     *          or <tt>null</tt> if registration is not required
   60.99 -     *
  60.100 -     */
  60.101 -    public SoftReference(T referent, ReferenceQueue<? super T> q) {
  60.102 -        super(referent, q);
  60.103 -        this.timestamp = clock;
  60.104 -    }
  60.105 -
  60.106 -    /**
  60.107 -     * Returns this reference object's referent.  If this reference object has
  60.108 -     * been cleared, either by the program or by the garbage collector, then
  60.109 -     * this method returns <code>null</code>.
  60.110 -     *
  60.111 -     * @return   The object to which this reference refers, or
  60.112 -     *           <code>null</code> if this reference object has been cleared
  60.113 -     */
  60.114 -    public T get() {
  60.115 -        T o = super.get();
  60.116 -        if (o != null && this.timestamp != clock)
  60.117 -            this.timestamp = clock;
  60.118 -        return o;
  60.119 -    }
  60.120 -
  60.121 -}
    61.1 --- a/emul/compact/src/main/java/java/lang/ref/WeakReference.java	Mon Feb 25 19:00:08 2013 +0100
    61.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.3 @@ -1,72 +0,0 @@
    61.4 -/*
    61.5 - * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
    61.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    61.7 - *
    61.8 - * This code is free software; you can redistribute it and/or modify it
    61.9 - * under the terms of the GNU General Public License version 2 only, as
   61.10 - * published by the Free Software Foundation.  Oracle designates this
   61.11 - * particular file as subject to the "Classpath" exception as provided
   61.12 - * by Oracle in the LICENSE file that accompanied this code.
   61.13 - *
   61.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   61.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   61.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   61.17 - * version 2 for more details (a copy is included in the LICENSE file that
   61.18 - * accompanied this code).
   61.19 - *
   61.20 - * You should have received a copy of the GNU General Public License version
   61.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   61.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   61.23 - *
   61.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   61.25 - * or visit www.oracle.com if you need additional information or have any
   61.26 - * questions.
   61.27 - */
   61.28 -
   61.29 -package java.lang.ref;
   61.30 -
   61.31 -
   61.32 -/**
   61.33 - * Weak reference objects, which do not prevent their referents from being
   61.34 - * made finalizable, finalized, and then reclaimed.  Weak references are most
   61.35 - * often used to implement canonicalizing mappings.
   61.36 - *
   61.37 - * <p> Suppose that the garbage collector determines at a certain point in time
   61.38 - * that an object is <a href="package-summary.html#reachability">weakly
   61.39 - * reachable</a>.  At that time it will atomically clear all weak references to
   61.40 - * that object and all weak references to any other weakly-reachable objects
   61.41 - * from which that object is reachable through a chain of strong and soft
   61.42 - * references.  At the same time it will declare all of the formerly
   61.43 - * weakly-reachable objects to be finalizable.  At the same time or at some
   61.44 - * later time it will enqueue those newly-cleared weak references that are
   61.45 - * registered with reference queues.
   61.46 - *
   61.47 - * @author   Mark Reinhold
   61.48 - * @since    1.2
   61.49 - */
   61.50 -
   61.51 -public class WeakReference<T> extends Reference<T> {
   61.52 -
   61.53 -    /**
   61.54 -     * Creates a new weak reference that refers to the given object.  The new
   61.55 -     * reference is not registered with any queue.
   61.56 -     *
   61.57 -     * @param referent object the new weak reference will refer to
   61.58 -     */
   61.59 -    public WeakReference(T referent) {
   61.60 -        super(referent);
   61.61 -    }
   61.62 -
   61.63 -    /**
   61.64 -     * Creates a new weak reference that refers to the given object and is
   61.65 -     * registered with the given queue.
   61.66 -     *
   61.67 -     * @param referent object the new weak reference will refer to
   61.68 -     * @param q the queue with which the reference is to be registered,
   61.69 -     *          or <tt>null</tt> if registration is not required
   61.70 -     */
   61.71 -    public WeakReference(T referent, ReferenceQueue<? super T> q) {
   61.72 -        super(referent, q);
   61.73 -    }
   61.74 -
   61.75 -}
    62.1 --- a/emul/compact/src/main/java/java/lang/ref/package.html	Mon Feb 25 19:00:08 2013 +0100
    62.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.3 @@ -1,147 +0,0 @@
    62.4 -<!--
    62.5 - Copyright (c) 1998, 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 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
   62.30 -<html>
   62.31 -<body bgcolor="white">
   62.32 -
   62.33 -
   62.34 -Provides reference-object classes, which support a limited degree of
   62.35 -interaction with the garbage collector.  A program may use a reference object
   62.36 -to maintain a reference to some other object in such a way that the latter
   62.37 -object may still be reclaimed by the collector.  A program may also arrange to
   62.38 -be notified some time after the collector has determined that the reachability
   62.39 -of a given object has changed.
   62.40 -
   62.41 -
   62.42 -<h2>Package Specification</h2>
   62.43 -
   62.44 -A <em>reference object</em> encapsulates a reference to some other object so
   62.45 -that the reference itself may be examined and manipulated like any other
   62.46 -object.  Three types of reference objects are provided, each weaker than the
   62.47 -last: <em>soft</em>, <em>weak</em>, and <em>phantom</em>.  Each type
   62.48 -corresponds to a different level of reachability, as defined below.  Soft
   62.49 -references are for implementing memory-sensitive caches, weak references are
   62.50 -for implementing canonicalizing mappings that do not prevent their keys (or
   62.51 -values) from being reclaimed, and phantom references are for scheduling
   62.52 -pre-mortem cleanup actions in a more flexible way than is possible with the
   62.53 -Java finalization mechanism.
   62.54 -
   62.55 -<p> Each reference-object type is implemented by a subclass of the abstract
   62.56 -base <code>{@link java.lang.ref.Reference}</code> class.  An instance of one of
   62.57 -these subclasses encapsulates a single reference to a particular object, called
   62.58 -the <em>referent</em>.  Every reference object provides methods for getting and
   62.59 -clearing the reference.  Aside from the clearing operation reference objects
   62.60 -are otherwise immutable, so no <code>set</code> operation is provided.  A
   62.61 -program may further subclass these subclasses, adding whatever fields and
   62.62 -methods are required for its purposes, or it may use these subclasses without
   62.63 -change.
   62.64 -
   62.65 -
   62.66 -<h3>Notification</h3>
   62.67 -
   62.68 -A program may request to be notified of changes in an object's reachability by
   62.69 -<em>registering</em> an appropriate reference object with a <em>reference
   62.70 -queue</em> at the time the reference object is created.  Some time after the
   62.71 -garbage collector determines that the reachability of the referent has changed
   62.72 -to the value corresponding to the type of the reference, it will add the
   62.73 -reference to the associated queue.  At this point, the reference is considered
   62.74 -to be <em>enqueued</em>.  The program may remove references from a queue either
   62.75 -by polling or by blocking until a reference becomes available.  Reference
   62.76 -queues are implemented by the <code>{@link java.lang.ref.ReferenceQueue}</code>
   62.77 -class.
   62.78 -
   62.79 -<p> The relationship between a registered reference object and its queue is
   62.80 -one-sided.  That is, a queue does not keep track of the references that are
   62.81 -registered with it.  If a registered reference becomes unreachable itself, then
   62.82 -it will never be enqueued.  It is the responsibility of the program using
   62.83 -reference objects to ensure that the objects remain reachable for as long as
   62.84 -the program is interested in their referents.
   62.85 -
   62.86 -<p> While some programs will choose to dedicate a thread to removing reference
   62.87 -objects from one or more queues and processing them, this is by no means
   62.88 -necessary.  A tactic that often works well is to examine a reference queue in
   62.89 -the course of performing some other fairly-frequent action.  For example, a
   62.90 -hashtable that uses weak references to implement weak keys could poll its
   62.91 -reference queue each time the table is accessed.  This is how the <code>{@link
   62.92 -java.util.WeakHashMap}</code> class works.  Because the <code>{@link
   62.93 -java.lang.ref.ReferenceQueue#poll ReferenceQueue.poll}</code> method simply
   62.94 -checks an internal data structure, this check will add little overhead to the
   62.95 -hashtable access methods.
   62.96 -
   62.97 -
   62.98 -<h3>Automatically-cleared references</h3>
   62.99 -
  62.100 -Soft and weak references are automatically cleared by the collector before
  62.101 -being added to the queues with which they are registered, if any.  Therefore
  62.102 -soft and weak references need not be registered with a queue in order to be
  62.103 -useful, while phantom references do.  An object that is reachable via phantom
  62.104 -references will remain so until all such references are cleared or themselves
  62.105 -become unreachable.
  62.106 -
  62.107 -
  62.108 -<a name="reachability"></a>
  62.109 -<h3>Reachability</h3>
  62.110 -
  62.111 -Going from strongest to weakest, the different levels of reachability reflect
  62.112 -the life cycle of an object.  They are operationally defined as follows:
  62.113 -
  62.114 -<ul>
  62.115 -
  62.116 -<li> An object is <em>strongly reachable</em> if it can be reached by some
  62.117 -thread without traversing any reference objects.  A newly-created object is
  62.118 -strongly reachable by the thread that created it.
  62.119 -
  62.120 -<li> An object is <em>softly reachable</em> if it is not strongly reachable but
  62.121 -can be reached by traversing a soft reference.
  62.122 -
  62.123 -<li> An object is <em>weakly reachable</em> if it is neither strongly nor
  62.124 -softly reachable but can be reached by traversing a weak reference.  When the
  62.125 -weak references to a weakly-reachable object are cleared, the object becomes
  62.126 -eligible for finalization.
  62.127 -
  62.128 -<li> An object is <em>phantom reachable</em> if it is neither strongly, softly,
  62.129 -nor weakly reachable, it has been finalized, and some phantom reference refers
  62.130 -to it.
  62.131 -
  62.132 -<li> Finally, an object is <em>unreachable</em>, and therefore eligible for
  62.133 -reclamation, when it is not reachable in any of the above ways.
  62.134 -
  62.135 -</ul>
  62.136 -
  62.137 -
  62.138 -@author	  Mark Reinhold
  62.139 -@since	  1.2
  62.140 -
  62.141 -<!--
  62.142 -<h2>Related Documentation</h2>
  62.143 -
  62.144 -For overviews, tutorials, examples, guides, and tool documentation, please see:
  62.145 -<ul>
  62.146 -  <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
  62.147 -</ul>
  62.148 --->
  62.149 -</body>
  62.150 -</html>
    63.1 --- a/emul/compact/src/main/java/java/util/AbstractCollection.java	Mon Feb 25 19:00:08 2013 +0100
    63.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.3 @@ -1,457 +0,0 @@
    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 -
   63.31 -/**
   63.32 - * This class provides a skeletal implementation of the <tt>Collection</tt>
   63.33 - * interface, to minimize the effort required to implement this interface. <p>
   63.34 - *
   63.35 - * To implement an unmodifiable collection, the programmer needs only to
   63.36 - * extend this class and provide implementations for the <tt>iterator</tt> and
   63.37 - * <tt>size</tt> methods.  (The iterator returned by the <tt>iterator</tt>
   63.38 - * method must implement <tt>hasNext</tt> and <tt>next</tt>.)<p>
   63.39 - *
   63.40 - * To implement a modifiable collection, the programmer must additionally
   63.41 - * override this class's <tt>add</tt> method (which otherwise throws an
   63.42 - * <tt>UnsupportedOperationException</tt>), and the iterator returned by the
   63.43 - * <tt>iterator</tt> method must additionally implement its <tt>remove</tt>
   63.44 - * method.<p>
   63.45 - *
   63.46 - * The programmer should generally provide a void (no argument) and
   63.47 - * <tt>Collection</tt> constructor, as per the recommendation in the
   63.48 - * <tt>Collection</tt> interface specification.<p>
   63.49 - *
   63.50 - * The documentation for each non-abstract method in this class describes its
   63.51 - * implementation in detail.  Each of these methods may be overridden if
   63.52 - * the collection being implemented admits a more efficient implementation.<p>
   63.53 - *
   63.54 - * This class is a member of the
   63.55 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   63.56 - * Java Collections Framework</a>.
   63.57 - *
   63.58 - * @author  Josh Bloch
   63.59 - * @author  Neal Gafter
   63.60 - * @see Collection
   63.61 - * @since 1.2
   63.62 - */
   63.63 -
   63.64 -public abstract class AbstractCollection<E> implements Collection<E> {
   63.65 -    /**
   63.66 -     * Sole constructor.  (For invocation by subclass constructors, typically
   63.67 -     * implicit.)
   63.68 -     */
   63.69 -    protected AbstractCollection() {
   63.70 -    }
   63.71 -
   63.72 -    // Query Operations
   63.73 -
   63.74 -    /**
   63.75 -     * Returns an iterator over the elements contained in this collection.
   63.76 -     *
   63.77 -     * @return an iterator over the elements contained in this collection
   63.78 -     */
   63.79 -    public abstract Iterator<E> iterator();
   63.80 -
   63.81 -    public abstract int size();
   63.82 -
   63.83 -    /**
   63.84 -     * {@inheritDoc}
   63.85 -     *
   63.86 -     * <p>This implementation returns <tt>size() == 0</tt>.
   63.87 -     */
   63.88 -    public boolean isEmpty() {
   63.89 -        return size() == 0;
   63.90 -    }
   63.91 -
   63.92 -    /**
   63.93 -     * {@inheritDoc}
   63.94 -     *
   63.95 -     * <p>This implementation iterates over the elements in the collection,
   63.96 -     * checking each element in turn for equality with the specified element.
   63.97 -     *
   63.98 -     * @throws ClassCastException   {@inheritDoc}
   63.99 -     * @throws NullPointerException {@inheritDoc}
  63.100 -     */
  63.101 -    public boolean contains(Object o) {
  63.102 -        Iterator<E> it = iterator();
  63.103 -        if (o==null) {
  63.104 -            while (it.hasNext())
  63.105 -                if (it.next()==null)
  63.106 -                    return true;
  63.107 -        } else {
  63.108 -            while (it.hasNext())
  63.109 -                if (o.equals(it.next()))
  63.110 -                    return true;
  63.111 -        }
  63.112 -        return false;
  63.113 -    }
  63.114 -
  63.115 -    /**
  63.116 -     * {@inheritDoc}
  63.117 -     *
  63.118 -     * <p>This implementation returns an array containing all the elements
  63.119 -     * returned by this collection's iterator, in the same order, stored in
  63.120 -     * consecutive elements of the array, starting with index {@code 0}.
  63.121 -     * The length of the returned array is equal to the number of elements
  63.122 -     * returned by the iterator, even if the size of this collection changes
  63.123 -     * during iteration, as might happen if the collection permits
  63.124 -     * concurrent modification during iteration.  The {@code size} method is
  63.125 -     * called only as an optimization hint; the correct result is returned
  63.126 -     * even if the iterator returns a different number of elements.
  63.127 -     *
  63.128 -     * <p>This method is equivalent to:
  63.129 -     *
  63.130 -     *  <pre> {@code
  63.131 -     * List<E> list = new ArrayList<E>(size());
  63.132 -     * for (E e : this)
  63.133 -     *     list.add(e);
  63.134 -     * return list.toArray();
  63.135 -     * }</pre>
  63.136 -     */
  63.137 -    public Object[] toArray() {
  63.138 -        // Estimate size of array; be prepared to see more or fewer elements
  63.139 -        Object[] r = new Object[size()];
  63.140 -        Iterator<E> it = iterator();
  63.141 -        for (int i = 0; i < r.length; i++) {
  63.142 -            if (! it.hasNext()) // fewer elements than expected
  63.143 -                return Arrays.copyOf(r, i);
  63.144 -            r[i] = it.next();
  63.145 -        }
  63.146 -        return it.hasNext() ? finishToArray(r, it) : r;
  63.147 -    }
  63.148 -
  63.149 -    /**
  63.150 -     * {@inheritDoc}
  63.151 -     *
  63.152 -     * <p>This implementation returns an array containing all the elements
  63.153 -     * returned by this collection's iterator in the same order, stored in
  63.154 -     * consecutive elements of the array, starting with index {@code 0}.
  63.155 -     * If the number of elements returned by the iterator is too large to
  63.156 -     * fit into the specified array, then the elements are returned in a
  63.157 -     * newly allocated array with length equal to the number of elements
  63.158 -     * returned by the iterator, even if the size of this collection
  63.159 -     * changes during iteration, as might happen if the collection permits
  63.160 -     * concurrent modification during iteration.  The {@code size} method is
  63.161 -     * called only as an optimization hint; the correct result is returned
  63.162 -     * even if the iterator returns a different number of elements.
  63.163 -     *
  63.164 -     * <p>This method is equivalent to:
  63.165 -     *
  63.166 -     *  <pre> {@code
  63.167 -     * List<E> list = new ArrayList<E>(size());
  63.168 -     * for (E e : this)
  63.169 -     *     list.add(e);
  63.170 -     * return list.toArray(a);
  63.171 -     * }</pre>
  63.172 -     *
  63.173 -     * @throws ArrayStoreException  {@inheritDoc}
  63.174 -     * @throws NullPointerException {@inheritDoc}
  63.175 -     */
  63.176 -    public <T> T[] toArray(T[] a) {
  63.177 -        // Estimate size of array; be prepared to see more or fewer elements
  63.178 -        int size = size();
  63.179 -        T[] r = a.length >= size ? a :
  63.180 -                  (T[])java.lang.reflect.Array
  63.181 -                  .newInstance(a.getClass().getComponentType(), size);
  63.182 -        Iterator<E> it = iterator();
  63.183 -
  63.184 -        for (int i = 0; i < r.length; i++) {
  63.185 -            if (! it.hasNext()) { // fewer elements than expected
  63.186 -                if (a != r)
  63.187 -                    return Arrays.copyOf(r, i);
  63.188 -                r[i] = null; // null-terminate
  63.189 -                return r;
  63.190 -            }
  63.191 -            r[i] = (T)it.next();
  63.192 -        }
  63.193 -        return it.hasNext() ? finishToArray(r, it) : r;
  63.194 -    }
  63.195 -
  63.196 -    /**
  63.197 -     * The maximum size of array to allocate.
  63.198 -     * Some VMs reserve some header words in an array.
  63.199 -     * Attempts to allocate larger arrays may result in
  63.200 -     * OutOfMemoryError: Requested array size exceeds VM limit
  63.201 -     */
  63.202 -    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  63.203 -
  63.204 -    /**
  63.205 -     * Reallocates the array being used within toArray when the iterator
  63.206 -     * returned more elements than expected, and finishes filling it from
  63.207 -     * the iterator.
  63.208 -     *
  63.209 -     * @param r the array, replete with previously stored elements
  63.210 -     * @param it the in-progress iterator over this collection
  63.211 -     * @return array containing the elements in the given array, plus any
  63.212 -     *         further elements returned by the iterator, trimmed to size
  63.213 -     */
  63.214 -    private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
  63.215 -        int i = r.length;
  63.216 -        while (it.hasNext()) {
  63.217 -            int cap = r.length;
  63.218 -            if (i == cap) {
  63.219 -                int newCap = cap + (cap >> 1) + 1;
  63.220 -                // overflow-conscious code
  63.221 -                if (newCap - MAX_ARRAY_SIZE > 0)
  63.222 -                    newCap = hugeCapacity(cap + 1);
  63.223 -                r = Arrays.copyOf(r, newCap);
  63.224 -            }
  63.225 -            r[i++] = (T)it.next();
  63.226 -        }
  63.227 -        // trim if overallocated
  63.228 -        return (i == r.length) ? r : Arrays.copyOf(r, i);
  63.229 -    }
  63.230 -
  63.231 -    private static int hugeCapacity(int minCapacity) {
  63.232 -        if (minCapacity < 0) // overflow
  63.233 -            throw new OutOfMemoryError
  63.234 -                ("Required array size too large");
  63.235 -        return (minCapacity > MAX_ARRAY_SIZE) ?
  63.236 -            Integer.MAX_VALUE :
  63.237 -            MAX_ARRAY_SIZE;
  63.238 -    }
  63.239 -
  63.240 -    // Modification Operations
  63.241 -
  63.242 -    /**
  63.243 -     * {@inheritDoc}
  63.244 -     *
  63.245 -     * <p>This implementation always throws an
  63.246 -     * <tt>UnsupportedOperationException</tt>.
  63.247 -     *
  63.248 -     * @throws UnsupportedOperationException {@inheritDoc}
  63.249 -     * @throws ClassCastException            {@inheritDoc}
  63.250 -     * @throws NullPointerException          {@inheritDoc}
  63.251 -     * @throws IllegalArgumentException      {@inheritDoc}
  63.252 -     * @throws IllegalStateException         {@inheritDoc}
  63.253 -     */
  63.254 -    public boolean add(E e) {
  63.255 -        throw new UnsupportedOperationException();
  63.256 -    }
  63.257 -
  63.258 -    /**
  63.259 -     * {@inheritDoc}
  63.260 -     *
  63.261 -     * <p>This implementation iterates over the collection looking for the
  63.262 -     * specified element.  If it finds the element, it removes the element
  63.263 -     * from the collection using the iterator's remove method.
  63.264 -     *
  63.265 -     * <p>Note that this implementation throws an
  63.266 -     * <tt>UnsupportedOperationException</tt> if the iterator returned by this
  63.267 -     * collection's iterator method does not implement the <tt>remove</tt>
  63.268 -     * method and this collection contains the specified object.
  63.269 -     *
  63.270 -     * @throws UnsupportedOperationException {@inheritDoc}
  63.271 -     * @throws ClassCastException            {@inheritDoc}
  63.272 -     * @throws NullPointerException          {@inheritDoc}
  63.273 -     */
  63.274 -    public boolean remove(Object o) {
  63.275 -        Iterator<E> it = iterator();
  63.276 -        if (o==null) {
  63.277 -            while (it.hasNext()) {
  63.278 -                if (it.next()==null) {
  63.279 -                    it.remove();
  63.280 -                    return true;
  63.281 -                }
  63.282 -            }
  63.283 -        } else {
  63.284 -            while (it.hasNext()) {
  63.285 -                if (o.equals(it.next())) {
  63.286 -                    it.remove();
  63.287 -                    return true;
  63.288 -                }
  63.289 -            }
  63.290 -        }
  63.291 -        return false;
  63.292 -    }
  63.293 -
  63.294 -
  63.295 -    // Bulk Operations
  63.296 -
  63.297 -    /**
  63.298 -     * {@inheritDoc}
  63.299 -     *
  63.300 -     * <p>This implementation iterates over the specified collection,
  63.301 -     * checking each element returned by the iterator in turn to see
  63.302 -     * if it's contained in this collection.  If all elements are so
  63.303 -     * contained <tt>true</tt> is returned, otherwise <tt>false</tt>.
  63.304 -     *
  63.305 -     * @throws ClassCastException            {@inheritDoc}
  63.306 -     * @throws NullPointerException          {@inheritDoc}
  63.307 -     * @see #contains(Object)
  63.308 -     */
  63.309 -    public boolean containsAll(Collection<?> c) {
  63.310 -        for (Object e : c)
  63.311 -            if (!contains(e))
  63.312 -                return false;
  63.313 -        return true;
  63.314 -    }
  63.315 -
  63.316 -    /**
  63.317 -     * {@inheritDoc}
  63.318 -     *
  63.319 -     * <p>This implementation iterates over the specified collection, and adds
  63.320 -     * each object returned by the iterator to this collection, in turn.
  63.321 -     *
  63.322 -     * <p>Note that this implementation will throw an
  63.323 -     * <tt>UnsupportedOperationException</tt> unless <tt>add</tt> is
  63.324 -     * overridden (assuming the specified collection is non-empty).
  63.325 -     *
  63.326 -     * @throws UnsupportedOperationException {@inheritDoc}
  63.327 -     * @throws ClassCastException            {@inheritDoc}
  63.328 -     * @throws NullPointerException          {@inheritDoc}
  63.329 -     * @throws IllegalArgumentException      {@inheritDoc}
  63.330 -     * @throws IllegalStateException         {@inheritDoc}
  63.331 -     *
  63.332 -     * @see #add(Object)
  63.333 -     */
  63.334 -    public boolean addAll(Collection<? extends E> c) {
  63.335 -        boolean modified = false;
  63.336 -        for (E e : c)
  63.337 -            if (add(e))
  63.338 -                modified = true;
  63.339 -        return modified;
  63.340 -    }
  63.341 -
  63.342 -    /**
  63.343 -     * {@inheritDoc}
  63.344 -     *
  63.345 -     * <p>This implementation iterates over this collection, checking each
  63.346 -     * element returned by the iterator in turn to see if it's contained
  63.347 -     * in the specified collection.  If it's so contained, it's removed from
  63.348 -     * this collection with the iterator's <tt>remove</tt> method.
  63.349 -     *
  63.350 -     * <p>Note that this implementation will throw an
  63.351 -     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
  63.352 -     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
  63.353 -     * and this collection contains one or more elements in common with the
  63.354 -     * specified collection.
  63.355 -     *
  63.356 -     * @throws UnsupportedOperationException {@inheritDoc}
  63.357 -     * @throws ClassCastException            {@inheritDoc}
  63.358 -     * @throws NullPointerException          {@inheritDoc}
  63.359 -     *
  63.360 -     * @see #remove(Object)
  63.361 -     * @see #contains(Object)
  63.362 -     */
  63.363 -    public boolean removeAll(Collection<?> c) {
  63.364 -        boolean modified = false;
  63.365 -        Iterator<?> it = iterator();
  63.366 -        while (it.hasNext()) {
  63.367 -            if (c.contains(it.next())) {
  63.368 -                it.remove();
  63.369 -                modified = true;
  63.370 -            }
  63.371 -        }
  63.372 -        return modified;
  63.373 -    }
  63.374 -
  63.375 -    /**
  63.376 -     * {@inheritDoc}
  63.377 -     *
  63.378 -     * <p>This implementation iterates over this collection, checking each
  63.379 -     * element returned by the iterator in turn to see if it's contained
  63.380 -     * in the specified collection.  If it's not so contained, it's removed
  63.381 -     * from this collection with the iterator's <tt>remove</tt> method.
  63.382 -     *
  63.383 -     * <p>Note that this implementation will throw an
  63.384 -     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
  63.385 -     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
  63.386 -     * and this collection contains one or more elements not present in the
  63.387 -     * specified collection.
  63.388 -     *
  63.389 -     * @throws UnsupportedOperationException {@inheritDoc}
  63.390 -     * @throws ClassCastException            {@inheritDoc}
  63.391 -     * @throws NullPointerException          {@inheritDoc}
  63.392 -     *
  63.393 -     * @see #remove(Object)
  63.394 -     * @see #contains(Object)
  63.395 -     */
  63.396 -    public boolean retainAll(Collection<?> c) {
  63.397 -        boolean modified = false;
  63.398 -        Iterator<E> it = iterator();
  63.399 -        while (it.hasNext()) {
  63.400 -            if (!c.contains(it.next())) {
  63.401 -                it.remove();
  63.402 -                modified = true;
  63.403 -            }
  63.404 -        }
  63.405 -        return modified;
  63.406 -    }
  63.407 -
  63.408 -    /**
  63.409 -     * {@inheritDoc}
  63.410 -     *
  63.411 -     * <p>This implementation iterates over this collection, removing each
  63.412 -     * element using the <tt>Iterator.remove</tt> operation.  Most
  63.413 -     * implementations will probably choose to override this method for
  63.414 -     * efficiency.
  63.415 -     *
  63.416 -     * <p>Note that this implementation will throw an
  63.417 -     * <tt>UnsupportedOperationException</tt> if the iterator returned by this
  63.418 -     * collection's <tt>iterator</tt> method does not implement the
  63.419 -     * <tt>remove</tt> method and this collection is non-empty.
  63.420 -     *
  63.421 -     * @throws UnsupportedOperationException {@inheritDoc}
  63.422 -     */
  63.423 -    public void clear() {
  63.424 -        Iterator<E> it = iterator();
  63.425 -        while (it.hasNext()) {
  63.426 -            it.next();
  63.427 -            it.remove();
  63.428 -        }
  63.429 -    }
  63.430 -
  63.431 -
  63.432 -    //  String conversion
  63.433 -
  63.434 -    /**
  63.435 -     * Returns a string representation of this collection.  The string
  63.436 -     * representation consists of a list of the collection's elements in the
  63.437 -     * order they are returned by its iterator, enclosed in square brackets
  63.438 -     * (<tt>"[]"</tt>).  Adjacent elements are separated by the characters
  63.439 -     * <tt>", "</tt> (comma and space).  Elements are converted to strings as
  63.440 -     * by {@link String#valueOf(Object)}.
  63.441 -     *
  63.442 -     * @return a string representation of this collection
  63.443 -     */
  63.444 -    public String toString() {
  63.445 -        Iterator<E> it = iterator();
  63.446 -        if (! it.hasNext())
  63.447 -            return "[]";
  63.448 -
  63.449 -        StringBuilder sb = new StringBuilder();
  63.450 -        sb.append('[');
  63.451 -        for (;;) {
  63.452 -            E e = it.next();
  63.453 -            sb.append(e == this ? "(this Collection)" : e);
  63.454 -            if (! it.hasNext())
  63.455 -                return sb.append(']').toString();
  63.456 -            sb.append(',').append(' ');
  63.457 -        }
  63.458 -    }
  63.459 -
  63.460 -}
    64.1 --- a/emul/compact/src/main/java/java/util/AbstractList.java	Mon Feb 25 19:00:08 2013 +0100
    64.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.3 @@ -1,781 +0,0 @@
    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 provides a skeletal implementation of the {@link List}
   64.33 - * interface to minimize the effort required to implement this interface
   64.34 - * backed by a "random access" data store (such as an array).  For sequential
   64.35 - * access data (such as a linked list), {@link AbstractSequentialList} should
   64.36 - * be used in preference to this class.
   64.37 - *
   64.38 - * <p>To implement an unmodifiable list, the programmer needs only to extend
   64.39 - * this class and provide implementations for the {@link #get(int)} and
   64.40 - * {@link List#size() size()} methods.
   64.41 - *
   64.42 - * <p>To implement a modifiable list, the programmer must additionally
   64.43 - * override the {@link #set(int, Object) set(int, E)} method (which otherwise
   64.44 - * throws an {@code UnsupportedOperationException}).  If the list is
   64.45 - * variable-size the programmer must additionally override the
   64.46 - * {@link #add(int, Object) add(int, E)} and {@link #remove(int)} methods.
   64.47 - *
   64.48 - * <p>The programmer should generally provide a void (no argument) and collection
   64.49 - * constructor, as per the recommendation in the {@link Collection} interface
   64.50 - * specification.
   64.51 - *
   64.52 - * <p>Unlike the other abstract collection implementations, the programmer does
   64.53 - * <i>not</i> have to provide an iterator implementation; the iterator and
   64.54 - * list iterator are implemented by this class, on top of the "random access"
   64.55 - * methods:
   64.56 - * {@link #get(int)},
   64.57 - * {@link #set(int, Object) set(int, E)},
   64.58 - * {@link #add(int, Object) add(int, E)} and
   64.59 - * {@link #remove(int)}.
   64.60 - *
   64.61 - * <p>The documentation for each non-abstract method in this class describes its
   64.62 - * implementation in detail.  Each of these methods may be overridden if the
   64.63 - * collection being implemented admits a more efficient implementation.
   64.64 - *
   64.65 - * <p>This class is a member of the
   64.66 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   64.67 - * Java Collections Framework</a>.
   64.68 - *
   64.69 - * @author  Josh Bloch
   64.70 - * @author  Neal Gafter
   64.71 - * @since 1.2
   64.72 - */
   64.73 -
   64.74 -public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> {
   64.75 -    /**
   64.76 -     * Sole constructor.  (For invocation by subclass constructors, typically
   64.77 -     * implicit.)
   64.78 -     */
   64.79 -    protected AbstractList() {
   64.80 -    }
   64.81 -
   64.82 -    /**
   64.83 -     * Appends the specified element to the end of this list (optional
   64.84 -     * operation).
   64.85 -     *
   64.86 -     * <p>Lists that support this operation may place limitations on what
   64.87 -     * elements may be added to this list.  In particular, some
   64.88 -     * lists will refuse to add null elements, and others will impose
   64.89 -     * restrictions on the type of elements that may be added.  List
   64.90 -     * classes should clearly specify in their documentation any restrictions
   64.91 -     * on what elements may be added.
   64.92 -     *
   64.93 -     * <p>This implementation calls {@code add(size(), e)}.
   64.94 -     *
   64.95 -     * <p>Note that this implementation throws an
   64.96 -     * {@code UnsupportedOperationException} unless
   64.97 -     * {@link #add(int, Object) add(int, E)} is overridden.
   64.98 -     *
   64.99 -     * @param e element to be appended to this list
  64.100 -     * @return {@code true} (as specified by {@link Collection#add})
  64.101 -     * @throws UnsupportedOperationException if the {@code add} operation
  64.102 -     *         is not supported by this list
  64.103 -     * @throws ClassCastException if the class of the specified element
  64.104 -     *         prevents it from being added to this list
  64.105 -     * @throws NullPointerException if the specified element is null and this
  64.106 -     *         list does not permit null elements
  64.107 -     * @throws IllegalArgumentException if some property of this element
  64.108 -     *         prevents it from being added to this list
  64.109 -     */
  64.110 -    public boolean add(E e) {
  64.111 -        add(size(), e);
  64.112 -        return true;
  64.113 -    }
  64.114 -
  64.115 -    /**
  64.116 -     * {@inheritDoc}
  64.117 -     *
  64.118 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  64.119 -     */
  64.120 -    abstract public E get(int index);
  64.121 -
  64.122 -    /**
  64.123 -     * {@inheritDoc}
  64.124 -     *
  64.125 -     * <p>This implementation always throws an
  64.126 -     * {@code UnsupportedOperationException}.
  64.127 -     *
  64.128 -     * @throws UnsupportedOperationException {@inheritDoc}
  64.129 -     * @throws ClassCastException            {@inheritDoc}
  64.130 -     * @throws NullPointerException          {@inheritDoc}
  64.131 -     * @throws IllegalArgumentException      {@inheritDoc}
  64.132 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  64.133 -     */
  64.134 -    public E set(int index, E element) {
  64.135 -        throw new UnsupportedOperationException();
  64.136 -    }
  64.137 -
  64.138 -    /**
  64.139 -     * {@inheritDoc}
  64.140 -     *
  64.141 -     * <p>This implementation always throws an
  64.142 -     * {@code UnsupportedOperationException}.
  64.143 -     *
  64.144 -     * @throws UnsupportedOperationException {@inheritDoc}
  64.145 -     * @throws ClassCastException            {@inheritDoc}
  64.146 -     * @throws NullPointerException          {@inheritDoc}
  64.147 -     * @throws IllegalArgumentException      {@inheritDoc}
  64.148 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  64.149 -     */
  64.150 -    public void add(int index, E element) {
  64.151 -        throw new UnsupportedOperationException();
  64.152 -    }
  64.153 -
  64.154 -    /**
  64.155 -     * {@inheritDoc}
  64.156 -     *
  64.157 -     * <p>This implementation always throws an
  64.158 -     * {@code UnsupportedOperationException}.
  64.159 -     *
  64.160 -     * @throws UnsupportedOperationException {@inheritDoc}
  64.161 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  64.162 -     */
  64.163 -    public E remove(int index) {
  64.164 -        throw new UnsupportedOperationException();
  64.165 -    }
  64.166 -
  64.167 -
  64.168 -    // Search Operations
  64.169 -
  64.170 -    /**
  64.171 -     * {@inheritDoc}
  64.172 -     *
  64.173 -     * <p>This implementation first gets a list iterator (with
  64.174 -     * {@code listIterator()}).  Then, it iterates over the list until the
  64.175 -     * specified element is found or the end of the list is reached.
  64.176 -     *
  64.177 -     * @throws ClassCastException   {@inheritDoc}
  64.178 -     * @throws NullPointerException {@inheritDoc}
  64.179 -     */
  64.180 -    public int indexOf(Object o) {
  64.181 -        ListIterator<E> it = listIterator();
  64.182 -        if (o==null) {
  64.183 -            while (it.hasNext())
  64.184 -                if (it.next()==null)
  64.185 -                    return it.previousIndex();
  64.186 -        } else {
  64.187 -            while (it.hasNext())
  64.188 -                if (o.equals(it.next()))
  64.189 -                    return it.previousIndex();
  64.190 -        }
  64.191 -        return -1;
  64.192 -    }
  64.193 -
  64.194 -    /**
  64.195 -     * {@inheritDoc}
  64.196 -     *
  64.197 -     * <p>This implementation first gets a list iterator that points to the end
  64.198 -     * of the list (with {@code listIterator(size())}).  Then, it iterates
  64.199 -     * backwards over the list until the specified element is found, or the
  64.200 -     * beginning of the list is reached.
  64.201 -     *
  64.202 -     * @throws ClassCastException   {@inheritDoc}
  64.203 -     * @throws NullPointerException {@inheritDoc}
  64.204 -     */
  64.205 -    public int lastIndexOf(Object o) {
  64.206 -        ListIterator<E> it = listIterator(size());
  64.207 -        if (o==null) {
  64.208 -            while (it.hasPrevious())
  64.209 -                if (it.previous()==null)
  64.210 -                    return it.nextIndex();
  64.211 -        } else {
  64.212 -            while (it.hasPrevious())
  64.213 -                if (o.equals(it.previous()))
  64.214 -                    return it.nextIndex();
  64.215 -        }
  64.216 -        return -1;
  64.217 -    }
  64.218 -
  64.219 -
  64.220 -    // Bulk Operations
  64.221 -
  64.222 -    /**
  64.223 -     * Removes all of the elements from this list (optional operation).
  64.224 -     * The list will be empty after this call returns.
  64.225 -     *
  64.226 -     * <p>This implementation calls {@code removeRange(0, size())}.
  64.227 -     *
  64.228 -     * <p>Note that this implementation throws an
  64.229 -     * {@code UnsupportedOperationException} unless {@code remove(int
  64.230 -     * index)} or {@code removeRange(int fromIndex, int toIndex)} is
  64.231 -     * overridden.
  64.232 -     *
  64.233 -     * @throws UnsupportedOperationException if the {@code clear} operation
  64.234 -     *         is not supported by this list
  64.235 -     */
  64.236 -    public void clear() {
  64.237 -        removeRange(0, size());
  64.238 -    }
  64.239 -
  64.240 -    /**
  64.241 -     * {@inheritDoc}
  64.242 -     *
  64.243 -     * <p>This implementation gets an iterator over the specified collection
  64.244 -     * and iterates over it, inserting the elements obtained from the
  64.245 -     * iterator into this list at the appropriate position, one at a time,
  64.246 -     * using {@code add(int, E)}.
  64.247 -     * Many implementations will override this method for efficiency.
  64.248 -     *
  64.249 -     * <p>Note that this implementation throws an
  64.250 -     * {@code UnsupportedOperationException} unless
  64.251 -     * {@link #add(int, Object) add(int, E)} is overridden.
  64.252 -     *
  64.253 -     * @throws UnsupportedOperationException {@inheritDoc}
  64.254 -     * @throws ClassCastException            {@inheritDoc}
  64.255 -     * @throws NullPointerException          {@inheritDoc}
  64.256 -     * @throws IllegalArgumentException      {@inheritDoc}
  64.257 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  64.258 -     */
  64.259 -    public boolean addAll(int index, Collection<? extends E> c) {
  64.260 -        rangeCheckForAdd(index);
  64.261 -        boolean modified = false;
  64.262 -        for (E e : c) {
  64.263 -            add(index++, e);
  64.264 -            modified = true;
  64.265 -        }
  64.266 -        return modified;
  64.267 -    }
  64.268 -
  64.269 -
  64.270 -    // Iterators
  64.271 -
  64.272 -    /**
  64.273 -     * Returns an iterator over the elements in this list in proper sequence.
  64.274 -     *
  64.275 -     * <p>This implementation returns a straightforward implementation of the
  64.276 -     * iterator interface, relying on the backing list's {@code size()},
  64.277 -     * {@code get(int)}, and {@code remove(int)} methods.
  64.278 -     *
  64.279 -     * <p>Note that the iterator returned by this method will throw an
  64.280 -     * {@link UnsupportedOperationException} in response to its
  64.281 -     * {@code remove} method unless the list's {@code remove(int)} method is
  64.282 -     * overridden.
  64.283 -     *
  64.284 -     * <p>This implementation can be made to throw runtime exceptions in the
  64.285 -     * face of concurrent modification, as described in the specification
  64.286 -     * for the (protected) {@link #modCount} field.
  64.287 -     *
  64.288 -     * @return an iterator over the elements in this list in proper sequence
  64.289 -     */
  64.290 -    public Iterator<E> iterator() {
  64.291 -        return new Itr();
  64.292 -    }
  64.293 -
  64.294 -    /**
  64.295 -     * {@inheritDoc}
  64.296 -     *
  64.297 -     * <p>This implementation returns {@code listIterator(0)}.
  64.298 -     *
  64.299 -     * @see #listIterator(int)
  64.300 -     */
  64.301 -    public ListIterator<E> listIterator() {
  64.302 -        return listIterator(0);
  64.303 -    }
  64.304 -
  64.305 -    /**
  64.306 -     * {@inheritDoc}
  64.307 -     *
  64.308 -     * <p>This implementation returns a straightforward implementation of the
  64.309 -     * {@code ListIterator} interface that extends the implementation of the
  64.310 -     * {@code Iterator} interface returned by the {@code iterator()} method.
  64.311 -     * The {@code ListIterator} implementation relies on the backing list's
  64.312 -     * {@code get(int)}, {@code set(int, E)}, {@code add(int, E)}
  64.313 -     * and {@code remove(int)} methods.
  64.314 -     *
  64.315 -     * <p>Note that the list iterator returned by this implementation will
  64.316 -     * throw an {@link UnsupportedOperationException} in response to its
  64.317 -     * {@code remove}, {@code set} and {@code add} methods unless the
  64.318 -     * list's {@code remove(int)}, {@code set(int, E)}, and
  64.319 -     * {@code add(int, E)} methods are overridden.
  64.320 -     *
  64.321 -     * <p>This implementation can be made to throw runtime exceptions in the
  64.322 -     * face of concurrent modification, as described in the specification for
  64.323 -     * the (protected) {@link #modCount} field.
  64.324 -     *
  64.325 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  64.326 -     */
  64.327 -    public ListIterator<E> listIterator(final int index) {
  64.328 -        rangeCheckForAdd(index);
  64.329 -
  64.330 -        return new ListItr(index);
  64.331 -    }
  64.332 -
  64.333 -    private class Itr implements Iterator<E> {
  64.334 -        /**
  64.335 -         * Index of element to be returned by subsequent call to next.
  64.336 -         */
  64.337 -        int cursor = 0;
  64.338 -
  64.339 -        /**
  64.340 -         * Index of element returned by most recent call to next or
  64.341 -         * previous.  Reset to -1 if this element is deleted by a call
  64.342 -         * to remove.
  64.343 -         */
  64.344 -        int lastRet = -1;
  64.345 -
  64.346 -        /**
  64.347 -         * The modCount value that the iterator believes that the backing
  64.348 -         * List should have.  If this expectation is violated, the iterator
  64.349 -         * has detected concurrent modification.
  64.350 -         */
  64.351 -        int expectedModCount = modCount;
  64.352 -
  64.353 -        public boolean hasNext() {
  64.354 -            return cursor != size();
  64.355 -        }
  64.356 -
  64.357 -        public E next() {
  64.358 -            checkForComodification();
  64.359 -            try {
  64.360 -                int i = cursor;
  64.361 -                E next = get(i);
  64.362 -                lastRet = i;
  64.363 -                cursor = i + 1;
  64.364 -                return next;
  64.365 -            } catch (IndexOutOfBoundsException e) {
  64.366 -                checkForComodification();
  64.367 -                throw new NoSuchElementException();
  64.368 -            }
  64.369 -        }
  64.370 -
  64.371 -        public void remove() {
  64.372 -            if (lastRet < 0)
  64.373 -                throw new IllegalStateException();
  64.374 -            checkForComodification();
  64.375 -
  64.376 -            try {
  64.377 -                AbstractList.this.remove(lastRet);
  64.378 -                if (lastRet < cursor)
  64.379 -                    cursor--;
  64.380 -                lastRet = -1;
  64.381 -                expectedModCount = modCount;
  64.382 -            } catch (IndexOutOfBoundsException e) {
  64.383 -                throw new ConcurrentModificationException();
  64.384 -            }
  64.385 -        }
  64.386 -
  64.387 -        final void checkForComodification() {
  64.388 -            if (modCount != expectedModCount)
  64.389 -                throw new ConcurrentModificationException();
  64.390 -        }
  64.391 -    }
  64.392 -
  64.393 -    private class ListItr extends Itr implements ListIterator<E> {
  64.394 -        ListItr(int index) {
  64.395 -            cursor = index;
  64.396 -        }
  64.397 -
  64.398 -        public boolean hasPrevious() {
  64.399 -            return cursor != 0;
  64.400 -        }
  64.401 -
  64.402 -        public E previous() {
  64.403 -            checkForComodification();
  64.404 -            try {
  64.405 -                int i = cursor - 1;
  64.406 -                E previous = get(i);
  64.407 -                lastRet = cursor = i;
  64.408 -                return previous;
  64.409 -            } catch (IndexOutOfBoundsException e) {
  64.410 -                checkForComodification();
  64.411 -                throw new NoSuchElementException();
  64.412 -            }
  64.413 -        }
  64.414 -
  64.415 -        public int nextIndex() {
  64.416 -            return cursor;
  64.417 -        }
  64.418 -
  64.419 -        public int previousIndex() {
  64.420 -            return cursor-1;
  64.421 -        }
  64.422 -
  64.423 -        public void set(E e) {
  64.424 -            if (lastRet < 0)
  64.425 -                throw new IllegalStateException();
  64.426 -            checkForComodification();
  64.427 -
  64.428 -            try {
  64.429 -                AbstractList.this.set(lastRet, e);
  64.430 -                expectedModCount = modCount;
  64.431 -            } catch (IndexOutOfBoundsException ex) {
  64.432 -                throw new ConcurrentModificationException();
  64.433 -            }
  64.434 -        }
  64.435 -
  64.436 -        public void add(E e) {
  64.437 -            checkForComodification();
  64.438 -
  64.439 -            try {
  64.440 -                int i = cursor;
  64.441 -                AbstractList.this.add(i, e);
  64.442 -                lastRet = -1;
  64.443 -                cursor = i + 1;
  64.444 -                expectedModCount = modCount;
  64.445 -            } catch (IndexOutOfBoundsException ex) {
  64.446 -                throw new ConcurrentModificationException();
  64.447 -            }
  64.448 -        }
  64.449 -    }
  64.450 -
  64.451 -    /**
  64.452 -     * {@inheritDoc}
  64.453 -     *
  64.454 -     * <p>This implementation returns a list that subclasses
  64.455 -     * {@code AbstractList}.  The subclass stores, in private fields, the
  64.456 -     * offset of the subList within the backing list, the size of the subList
  64.457 -     * (which can change over its lifetime), and the expected
  64.458 -     * {@code modCount} value of the backing list.  There are two variants
  64.459 -     * of the subclass, one of which implements {@code RandomAccess}.
  64.460 -     * If this list implements {@code RandomAccess} the returned list will
  64.461 -     * be an instance of the subclass that implements {@code RandomAccess}.
  64.462 -     *
  64.463 -     * <p>The subclass's {@code set(int, E)}, {@code get(int)},
  64.464 -     * {@code add(int, E)}, {@code remove(int)}, {@code addAll(int,
  64.465 -     * Collection)} and {@code removeRange(int, int)} methods all
  64.466 -     * delegate to the corresponding methods on the backing abstract list,
  64.467 -     * after bounds-checking the index and adjusting for the offset.  The
  64.468 -     * {@code addAll(Collection c)} method merely returns {@code addAll(size,
  64.469 -     * c)}.
  64.470 -     *
  64.471 -     * <p>The {@code listIterator(int)} method returns a "wrapper object"
  64.472 -     * over a list iterator on the backing list, which is created with the
  64.473 -     * corresponding method on the backing list.  The {@code iterator} method
  64.474 -     * merely returns {@code listIterator()}, and the {@code size} method
  64.475 -     * merely returns the subclass's {@code size} field.
  64.476 -     *
  64.477 -     * <p>All methods first check to see if the actual {@code modCount} of
  64.478 -     * the backing list is equal to its expected value, and throw a
  64.479 -     * {@code ConcurrentModificationException} if it is not.
  64.480 -     *
  64.481 -     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
  64.482 -     *         {@code (fromIndex < 0 || toIndex > size)}
  64.483 -     * @throws IllegalArgumentException if the endpoint indices are out of order
  64.484 -     *         {@code (fromIndex > toIndex)}
  64.485 -     */
  64.486 -    public List<E> subList(int fromIndex, int toIndex) {
  64.487 -        return (this instanceof RandomAccess ?
  64.488 -                new RandomAccessSubList<>(this, fromIndex, toIndex) :
  64.489 -                new SubList<>(this, fromIndex, toIndex));
  64.490 -    }
  64.491 -
  64.492 -    // Comparison and hashing
  64.493 -
  64.494 -    /**
  64.495 -     * Compares the specified object with this list for equality.  Returns
  64.496 -     * {@code true} if and only if the specified object is also a list, both
  64.497 -     * lists have the same size, and all corresponding pairs of elements in
  64.498 -     * the two lists are <i>equal</i>.  (Two elements {@code e1} and
  64.499 -     * {@code e2} are <i>equal</i> if {@code (e1==null ? e2==null :
  64.500 -     * e1.equals(e2))}.)  In other words, two lists are defined to be
  64.501 -     * equal if they contain the same elements in the same order.<p>
  64.502 -     *
  64.503 -     * This implementation first checks if the specified object is this
  64.504 -     * list. If so, it returns {@code true}; if not, it checks if the
  64.505 -     * specified object is a list. If not, it returns {@code false}; if so,
  64.506 -     * it iterates over both lists, comparing corresponding pairs of elements.
  64.507 -     * If any comparison returns {@code false}, this method returns
  64.508 -     * {@code false}.  If either iterator runs out of elements before the
  64.509 -     * other it returns {@code false} (as the lists are of unequal length);
  64.510 -     * otherwise it returns {@code true} when the iterations complete.
  64.511 -     *
  64.512 -     * @param o the object to be compared for equality with this list
  64.513 -     * @return {@code true} if the specified object is equal to this list
  64.514 -     */
  64.515 -    public boolean equals(Object o) {
  64.516 -        if (o == this)
  64.517 -            return true;
  64.518 -        if (!(o instanceof List))
  64.519 -            return false;
  64.520 -
  64.521 -        ListIterator<E> e1 = listIterator();
  64.522 -        ListIterator e2 = ((List) o).listIterator();
  64.523 -        while (e1.hasNext() && e2.hasNext()) {
  64.524 -            E o1 = e1.next();
  64.525 -            Object o2 = e2.next();
  64.526 -            if (!(o1==null ? o2==null : o1.equals(o2)))
  64.527 -                return false;
  64.528 -        }
  64.529 -        return !(e1.hasNext() || e2.hasNext());
  64.530 -    }
  64.531 -
  64.532 -    /**
  64.533 -     * Returns the hash code value for this list.
  64.534 -     *
  64.535 -     * <p>This implementation uses exactly the code that is used to define the
  64.536 -     * list hash function in the documentation for the {@link List#hashCode}
  64.537 -     * method.
  64.538 -     *
  64.539 -     * @return the hash code value for this list
  64.540 -     */
  64.541 -    public int hashCode() {
  64.542 -        int hashCode = 1;
  64.543 -        for (E e : this)
  64.544 -            hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
  64.545 -        return hashCode;
  64.546 -    }
  64.547 -
  64.548 -    /**
  64.549 -     * Removes from this list all of the elements whose index is between
  64.550 -     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
  64.551 -     * Shifts any succeeding elements to the left (reduces their index).
  64.552 -     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
  64.553 -     * (If {@code toIndex==fromIndex}, this operation has no effect.)
  64.554 -     *
  64.555 -     * <p>This method is called by the {@code clear} operation on this list
  64.556 -     * and its subLists.  Overriding this method to take advantage of
  64.557 -     * the internals of the list implementation can <i>substantially</i>
  64.558 -     * improve the performance of the {@code clear} operation on this list
  64.559 -     * and its subLists.
  64.560 -     *
  64.561 -     * <p>This implementation gets a list iterator positioned before
  64.562 -     * {@code fromIndex}, and repeatedly calls {@code ListIterator.next}
  64.563 -     * followed by {@code ListIterator.remove} until the entire range has
  64.564 -     * been removed.  <b>Note: if {@code ListIterator.remove} requires linear
  64.565 -     * time, this implementation requires quadratic time.</b>
  64.566 -     *
  64.567 -     * @param fromIndex index of first element to be removed
  64.568 -     * @param toIndex index after last element to be removed
  64.569 -     */
  64.570 -    protected void removeRange(int fromIndex, int toIndex) {
  64.571 -        ListIterator<E> it = listIterator(fromIndex);
  64.572 -        for (int i=0, n=toIndex-fromIndex; i<n; i++) {
  64.573 -            it.next();
  64.574 -            it.remove();
  64.575 -        }
  64.576 -    }
  64.577 -
  64.578 -    /**
  64.579 -     * The number of times this list has been <i>structurally modified</i>.
  64.580 -     * Structural modifications are those that change the size of the
  64.581 -     * list, or otherwise perturb it in such a fashion that iterations in
  64.582 -     * progress may yield incorrect results.
  64.583 -     *
  64.584 -     * <p>This field is used by the iterator and list iterator implementation
  64.585 -     * returned by the {@code iterator} and {@code listIterator} methods.
  64.586 -     * If the value of this field changes unexpectedly, the iterator (or list
  64.587 -     * iterator) will throw a {@code ConcurrentModificationException} in
  64.588 -     * response to the {@code next}, {@code remove}, {@code previous},
  64.589 -     * {@code set} or {@code add} operations.  This provides
  64.590 -     * <i>fail-fast</i> behavior, rather than non-deterministic behavior in
  64.591 -     * the face of concurrent modification during iteration.
  64.592 -     *
  64.593 -     * <p><b>Use of this field by subclasses is optional.</b> If a subclass
  64.594 -     * wishes to provide fail-fast iterators (and list iterators), then it
  64.595 -     * merely has to increment this field in its {@code add(int, E)} and
  64.596 -     * {@code remove(int)} methods (and any other methods that it overrides
  64.597 -     * that result in structural modifications to the list).  A single call to
  64.598 -     * {@code add(int, E)} or {@code remove(int)} must add no more than
  64.599 -     * one to this field, or the iterators (and list iterators) will throw
  64.600 -     * bogus {@code ConcurrentModificationExceptions}.  If an implementation
  64.601 -     * does not wish to provide fail-fast iterators, this field may be
  64.602 -     * ignored.
  64.603 -     */
  64.604 -    protected transient int modCount = 0;
  64.605 -
  64.606 -    private void rangeCheckForAdd(int index) {
  64.607 -        if (index < 0 || index > size())
  64.608 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  64.609 -    }
  64.610 -
  64.611 -    private String outOfBoundsMsg(int index) {
  64.612 -        return "Index: "+index+", Size: "+size();
  64.613 -    }
  64.614 -}
  64.615 -
  64.616 -class SubList<E> extends AbstractList<E> {
  64.617 -    private final AbstractList<E> l;
  64.618 -    private final int offset;
  64.619 -    private int size;
  64.620 -
  64.621 -    SubList(AbstractList<E> list, int fromIndex, int toIndex) {
  64.622 -        if (fromIndex < 0)
  64.623 -            throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
  64.624 -        if (toIndex > list.size())
  64.625 -            throw new IndexOutOfBoundsException("toIndex = " + toIndex);
  64.626 -        if (fromIndex > toIndex)
  64.627 -            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  64.628 -                                               ") > toIndex(" + toIndex + ")");
  64.629 -        l = list;
  64.630 -        offset = fromIndex;
  64.631 -        size = toIndex - fromIndex;
  64.632 -        this.modCount = l.modCount;
  64.633 -    }
  64.634 -
  64.635 -    public E set(int index, E element) {
  64.636 -        rangeCheck(index);
  64.637 -        checkForComodification();
  64.638 -        return l.set(index+offset, element);
  64.639 -    }
  64.640 -
  64.641 -    public E get(int index) {
  64.642 -        rangeCheck(index);
  64.643 -        checkForComodification();
  64.644 -        return l.get(index+offset);
  64.645 -    }
  64.646 -
  64.647 -    public int size() {
  64.648 -        checkForComodification();
  64.649 -        return size;
  64.650 -    }
  64.651 -
  64.652 -    public void add(int index, E element) {
  64.653 -        rangeCheckForAdd(index);
  64.654 -        checkForComodification();
  64.655 -        l.add(index+offset, element);
  64.656 -        this.modCount = l.modCount;
  64.657 -        size++;
  64.658 -    }
  64.659 -
  64.660 -    public E remove(int index) {
  64.661 -        rangeCheck(index);
  64.662 -        checkForComodification();
  64.663 -        E result = l.remove(index+offset);
  64.664 -        this.modCount = l.modCount;
  64.665 -        size--;
  64.666 -        return result;
  64.667 -    }
  64.668 -
  64.669 -    protected void removeRange(int fromIndex, int toIndex) {
  64.670 -        checkForComodification();
  64.671 -        l.removeRange(fromIndex+offset, toIndex+offset);
  64.672 -        this.modCount = l.modCount;
  64.673 -        size -= (toIndex-fromIndex);
  64.674 -    }
  64.675 -
  64.676 -    public boolean addAll(Collection<? extends E> c) {
  64.677 -        return addAll(size, c);
  64.678 -    }
  64.679 -
  64.680 -    public boolean addAll(int index, Collection<? extends E> c) {
  64.681 -        rangeCheckForAdd(index);
  64.682 -        int cSize = c.size();
  64.683 -        if (cSize==0)
  64.684 -            return false;
  64.685 -
  64.686 -        checkForComodification();
  64.687 -        l.addAll(offset+index, c);
  64.688 -        this.modCount = l.modCount;
  64.689 -        size += cSize;
  64.690 -        return true;
  64.691 -    }
  64.692 -
  64.693 -    public Iterator<E> iterator() {
  64.694 -        return listIterator();
  64.695 -    }
  64.696 -
  64.697 -    public ListIterator<E> listIterator(final int index) {
  64.698 -        checkForComodification();
  64.699 -        rangeCheckForAdd(index);
  64.700 -
  64.701 -        return new ListIterator<E>() {
  64.702 -            private final ListIterator<E> i = l.listIterator(index+offset);
  64.703 -
  64.704 -            public boolean hasNext() {
  64.705 -                return nextIndex() < size;
  64.706 -            }
  64.707 -
  64.708 -            public E next() {
  64.709 -                if (hasNext())
  64.710 -                    return i.next();
  64.711 -                else
  64.712 -                    throw new NoSuchElementException();
  64.713 -            }
  64.714 -
  64.715 -            public boolean hasPrevious() {
  64.716 -                return previousIndex() >= 0;
  64.717 -            }
  64.718 -
  64.719 -            public E previous() {
  64.720 -                if (hasPrevious())
  64.721 -                    return i.previous();
  64.722 -                else
  64.723 -                    throw new NoSuchElementException();
  64.724 -            }
  64.725 -
  64.726 -            public int nextIndex() {
  64.727 -                return i.nextIndex() - offset;
  64.728 -            }
  64.729 -
  64.730 -            public int previousIndex() {
  64.731 -                return i.previousIndex() - offset;
  64.732 -            }
  64.733 -
  64.734 -            public void remove() {
  64.735 -                i.remove();
  64.736 -                SubList.this.modCount = l.modCount;
  64.737 -                size--;
  64.738 -            }
  64.739 -
  64.740 -            public void set(E e) {
  64.741 -                i.set(e);
  64.742 -            }
  64.743 -
  64.744 -            public void add(E e) {
  64.745 -                i.add(e);
  64.746 -                SubList.this.modCount = l.modCount;
  64.747 -                size++;
  64.748 -            }
  64.749 -        };
  64.750 -    }
  64.751 -
  64.752 -    public List<E> subList(int fromIndex, int toIndex) {
  64.753 -        return new SubList<>(this, fromIndex, toIndex);
  64.754 -    }
  64.755 -
  64.756 -    private void rangeCheck(int index) {
  64.757 -        if (index < 0 || index >= size)
  64.758 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  64.759 -    }
  64.760 -
  64.761 -    private void rangeCheckForAdd(int index) {
  64.762 -        if (index < 0 || index > size)
  64.763 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  64.764 -    }
  64.765 -
  64.766 -    private String outOfBoundsMsg(int index) {
  64.767 -        return "Index: "+index+", Size: "+size;
  64.768 -    }
  64.769 -
  64.770 -    private void checkForComodification() {
  64.771 -        if (this.modCount != l.modCount)
  64.772 -            throw new ConcurrentModificationException();
  64.773 -    }
  64.774 -}
  64.775 -
  64.776 -class RandomAccessSubList<E> extends SubList<E> implements RandomAccess {
  64.777 -    RandomAccessSubList(AbstractList<E> list, int fromIndex, int toIndex) {
  64.778 -        super(list, fromIndex, toIndex);
  64.779 -    }
  64.780 -
  64.781 -    public List<E> subList(int fromIndex, int toIndex) {
  64.782 -        return new RandomAccessSubList<>(this, fromIndex, toIndex);
  64.783 -    }
  64.784 -}
    65.1 --- a/emul/compact/src/main/java/java/util/AbstractMap.java	Mon Feb 25 19:00:08 2013 +0100
    65.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.3 @@ -1,822 +0,0 @@
    65.4 -/*
    65.5 - * Copyright (c) 1997, 2010, 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.util.Map.Entry;
   65.31 -
   65.32 -/**
   65.33 - * This class provides a skeletal implementation of the <tt>Map</tt>
   65.34 - * interface, to minimize the effort required to implement this interface.
   65.35 - *
   65.36 - * <p>To implement an unmodifiable map, the programmer needs only to extend this
   65.37 - * class and provide an implementation for the <tt>entrySet</tt> method, which
   65.38 - * returns a set-view of the map's mappings.  Typically, the returned set
   65.39 - * will, in turn, be implemented atop <tt>AbstractSet</tt>.  This set should
   65.40 - * not support the <tt>add</tt> or <tt>remove</tt> methods, and its iterator
   65.41 - * should not support the <tt>remove</tt> method.
   65.42 - *
   65.43 - * <p>To implement a modifiable map, the programmer must additionally override
   65.44 - * this class's <tt>put</tt> method (which otherwise throws an
   65.45 - * <tt>UnsupportedOperationException</tt>), and the iterator returned by
   65.46 - * <tt>entrySet().iterator()</tt> must additionally implement its
   65.47 - * <tt>remove</tt> method.
   65.48 - *
   65.49 - * <p>The programmer should generally provide a void (no argument) and map
   65.50 - * constructor, as per the recommendation in the <tt>Map</tt> interface
   65.51 - * specification.
   65.52 - *
   65.53 - * <p>The documentation for each non-abstract method in this class describes its
   65.54 - * implementation in detail.  Each of these methods may be overridden if the
   65.55 - * map being implemented admits a more efficient implementation.
   65.56 - *
   65.57 - * <p>This class is a member of the
   65.58 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   65.59 - * Java Collections Framework</a>.
   65.60 - *
   65.61 - * @param <K> the type of keys maintained by this map
   65.62 - * @param <V> the type of mapped values
   65.63 - *
   65.64 - * @author  Josh Bloch
   65.65 - * @author  Neal Gafter
   65.66 - * @see Map
   65.67 - * @see Collection
   65.68 - * @since 1.2
   65.69 - */
   65.70 -
   65.71 -public abstract class AbstractMap<K,V> implements Map<K,V> {
   65.72 -    /**
   65.73 -     * Sole constructor.  (For invocation by subclass constructors, typically
   65.74 -     * implicit.)
   65.75 -     */
   65.76 -    protected AbstractMap() {
   65.77 -    }
   65.78 -
   65.79 -    // Query Operations
   65.80 -
   65.81 -    /**
   65.82 -     * {@inheritDoc}
   65.83 -     *
   65.84 -     * <p>This implementation returns <tt>entrySet().size()</tt>.
   65.85 -     */
   65.86 -    public int size() {
   65.87 -        return entrySet().size();
   65.88 -    }
   65.89 -
   65.90 -    /**
   65.91 -     * {@inheritDoc}
   65.92 -     *
   65.93 -     * <p>This implementation returns <tt>size() == 0</tt>.
   65.94 -     */
   65.95 -    public boolean isEmpty() {
   65.96 -        return size() == 0;
   65.97 -    }
   65.98 -
   65.99 -    /**
  65.100 -     * {@inheritDoc}
  65.101 -     *
  65.102 -     * <p>This implementation iterates over <tt>entrySet()</tt> searching
  65.103 -     * for an entry with the specified value.  If such an entry is found,
  65.104 -     * <tt>true</tt> is returned.  If the iteration terminates without
  65.105 -     * finding such an entry, <tt>false</tt> is returned.  Note that this
  65.106 -     * implementation requires linear time in the size of the map.
  65.107 -     *
  65.108 -     * @throws ClassCastException   {@inheritDoc}
  65.109 -     * @throws NullPointerException {@inheritDoc}
  65.110 -     */
  65.111 -    public boolean containsValue(Object value) {
  65.112 -        Iterator<Entry<K,V>> i = entrySet().iterator();
  65.113 -        if (value==null) {
  65.114 -            while (i.hasNext()) {
  65.115 -                Entry<K,V> e = i.next();
  65.116 -                if (e.getValue()==null)
  65.117 -                    return true;
  65.118 -            }
  65.119 -        } else {
  65.120 -            while (i.hasNext()) {
  65.121 -                Entry<K,V> e = i.next();
  65.122 -                if (value.equals(e.getValue()))
  65.123 -                    return true;
  65.124 -            }
  65.125 -        }
  65.126 -        return false;
  65.127 -    }
  65.128 -
  65.129 -    /**
  65.130 -     * {@inheritDoc}
  65.131 -     *
  65.132 -     * <p>This implementation iterates over <tt>entrySet()</tt> searching
  65.133 -     * for an entry with the specified key.  If such an entry is found,
  65.134 -     * <tt>true</tt> is returned.  If the iteration terminates without
  65.135 -     * finding such an entry, <tt>false</tt> is returned.  Note that this
  65.136 -     * implementation requires linear time in the size of the map; many
  65.137 -     * implementations will override this method.
  65.138 -     *
  65.139 -     * @throws ClassCastException   {@inheritDoc}
  65.140 -     * @throws NullPointerException {@inheritDoc}
  65.141 -     */
  65.142 -    public boolean containsKey(Object key) {
  65.143 -        Iterator<Map.Entry<K,V>> i = entrySet().iterator();
  65.144 -        if (key==null) {
  65.145 -            while (i.hasNext()) {
  65.146 -                Entry<K,V> e = i.next();
  65.147 -                if (e.getKey()==null)
  65.148 -                    return true;
  65.149 -            }
  65.150 -        } else {
  65.151 -            while (i.hasNext()) {
  65.152 -                Entry<K,V> e = i.next();
  65.153 -                if (key.equals(e.getKey()))
  65.154 -                    return true;
  65.155 -            }
  65.156 -        }
  65.157 -        return false;
  65.158 -    }
  65.159 -
  65.160 -    /**
  65.161 -     * {@inheritDoc}
  65.162 -     *
  65.163 -     * <p>This implementation iterates over <tt>entrySet()</tt> searching
  65.164 -     * for an entry with the specified key.  If such an entry is found,
  65.165 -     * the entry's value is returned.  If the iteration terminates without
  65.166 -     * finding such an entry, <tt>null</tt> is returned.  Note that this
  65.167 -     * implementation requires linear time in the size of the map; many
  65.168 -     * implementations will override this method.
  65.169 -     *
  65.170 -     * @throws ClassCastException            {@inheritDoc}
  65.171 -     * @throws NullPointerException          {@inheritDoc}
  65.172 -     */
  65.173 -    public V get(Object key) {
  65.174 -        Iterator<Entry<K,V>> i = entrySet().iterator();
  65.175 -        if (key==null) {
  65.176 -            while (i.hasNext()) {
  65.177 -                Entry<K,V> e = i.next();
  65.178 -                if (e.getKey()==null)
  65.179 -                    return e.getValue();
  65.180 -            }
  65.181 -        } else {
  65.182 -            while (i.hasNext()) {
  65.183 -                Entry<K,V> e = i.next();
  65.184 -                if (key.equals(e.getKey()))
  65.185 -                    return e.getValue();
  65.186 -            }
  65.187 -        }
  65.188 -        return null;
  65.189 -    }
  65.190 -
  65.191 -
  65.192 -    // Modification Operations
  65.193 -
  65.194 -    /**
  65.195 -     * {@inheritDoc}
  65.196 -     *
  65.197 -     * <p>This implementation always throws an
  65.198 -     * <tt>UnsupportedOperationException</tt>.
  65.199 -     *
  65.200 -     * @throws UnsupportedOperationException {@inheritDoc}
  65.201 -     * @throws ClassCastException            {@inheritDoc}
  65.202 -     * @throws NullPointerException          {@inheritDoc}
  65.203 -     * @throws IllegalArgumentException      {@inheritDoc}
  65.204 -     */
  65.205 -    public V put(K key, V value) {
  65.206 -        throw new UnsupportedOperationException();
  65.207 -    }
  65.208 -
  65.209 -    /**
  65.210 -     * {@inheritDoc}
  65.211 -     *
  65.212 -     * <p>This implementation iterates over <tt>entrySet()</tt> searching for an
  65.213 -     * entry with the specified key.  If such an entry is found, its value is
  65.214 -     * obtained with its <tt>getValue</tt> operation, the entry is removed
  65.215 -     * from the collection (and the backing map) with the iterator's
  65.216 -     * <tt>remove</tt> operation, and the saved value is returned.  If the
  65.217 -     * iteration terminates without finding such an entry, <tt>null</tt> is
  65.218 -     * returned.  Note that this implementation requires linear time in the
  65.219 -     * size of the map; many implementations will override this method.
  65.220 -     *
  65.221 -     * <p>Note that this implementation throws an
  65.222 -     * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
  65.223 -     * iterator does not support the <tt>remove</tt> method and this map
  65.224 -     * contains a mapping for the specified key.
  65.225 -     *
  65.226 -     * @throws UnsupportedOperationException {@inheritDoc}
  65.227 -     * @throws ClassCastException            {@inheritDoc}
  65.228 -     * @throws NullPointerException          {@inheritDoc}
  65.229 -     */
  65.230 -    public V remove(Object key) {
  65.231 -        Iterator<Entry<K,V>> i = entrySet().iterator();
  65.232 -        Entry<K,V> correctEntry = null;
  65.233 -        if (key==null) {
  65.234 -            while (correctEntry==null && i.hasNext()) {
  65.235 -                Entry<K,V> e = i.next();
  65.236 -                if (e.getKey()==null)
  65.237 -                    correctEntry = e;
  65.238 -            }
  65.239 -        } else {
  65.240 -            while (correctEntry==null && i.hasNext()) {
  65.241 -                Entry<K,V> e = i.next();
  65.242 -                if (key.equals(e.getKey()))
  65.243 -                    correctEntry = e;
  65.244 -            }
  65.245 -        }
  65.246 -
  65.247 -        V oldValue = null;
  65.248 -        if (correctEntry !=null) {
  65.249 -            oldValue = correctEntry.getValue();
  65.250 -            i.remove();
  65.251 -        }
  65.252 -        return oldValue;
  65.253 -    }
  65.254 -
  65.255 -
  65.256 -    // Bulk Operations
  65.257 -
  65.258 -    /**
  65.259 -     * {@inheritDoc}
  65.260 -     *
  65.261 -     * <p>This implementation iterates over the specified map's
  65.262 -     * <tt>entrySet()</tt> collection, and calls this map's <tt>put</tt>
  65.263 -     * operation once for each entry returned by the iteration.
  65.264 -     *
  65.265 -     * <p>Note that this implementation throws an
  65.266 -     * <tt>UnsupportedOperationException</tt> if this map does not support
  65.267 -     * the <tt>put</tt> operation and the specified map is nonempty.
  65.268 -     *
  65.269 -     * @throws UnsupportedOperationException {@inheritDoc}
  65.270 -     * @throws ClassCastException            {@inheritDoc}
  65.271 -     * @throws NullPointerException          {@inheritDoc}
  65.272 -     * @throws IllegalArgumentException      {@inheritDoc}
  65.273 -     */
  65.274 -    public void putAll(Map<? extends K, ? extends V> m) {
  65.275 -        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
  65.276 -            put(e.getKey(), e.getValue());
  65.277 -    }
  65.278 -
  65.279 -    /**
  65.280 -     * {@inheritDoc}
  65.281 -     *
  65.282 -     * <p>This implementation calls <tt>entrySet().clear()</tt>.
  65.283 -     *
  65.284 -     * <p>Note that this implementation throws an
  65.285 -     * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
  65.286 -     * does not support the <tt>clear</tt> operation.
  65.287 -     *
  65.288 -     * @throws UnsupportedOperationException {@inheritDoc}
  65.289 -     */
  65.290 -    public void clear() {
  65.291 -        entrySet().clear();
  65.292 -    }
  65.293 -
  65.294 -
  65.295 -    // Views
  65.296 -
  65.297 -    /**
  65.298 -     * Each of these fields are initialized to contain an instance of the
  65.299 -     * appropriate view the first time this view is requested.  The views are
  65.300 -     * stateless, so there's no reason to create more than one of each.
  65.301 -     */
  65.302 -    transient volatile Set<K>        keySet = null;
  65.303 -    transient volatile Collection<V> values = null;
  65.304 -
  65.305 -    /**
  65.306 -     * {@inheritDoc}
  65.307 -     *
  65.308 -     * <p>This implementation returns a set that subclasses {@link AbstractSet}.
  65.309 -     * The subclass's iterator method returns a "wrapper object" over this
  65.310 -     * map's <tt>entrySet()</tt> iterator.  The <tt>size</tt> method
  65.311 -     * delegates to this map's <tt>size</tt> method and the
  65.312 -     * <tt>contains</tt> method delegates to this map's
  65.313 -     * <tt>containsKey</tt> method.
  65.314 -     *
  65.315 -     * <p>The set is created the first time this method is called,
  65.316 -     * and returned in response to all subsequent calls.  No synchronization
  65.317 -     * is performed, so there is a slight chance that multiple calls to this
  65.318 -     * method will not all return the same set.
  65.319 -     */
  65.320 -    public Set<K> keySet() {
  65.321 -        if (keySet == null) {
  65.322 -            keySet = new AbstractSet<K>() {
  65.323 -                public Iterator<K> iterator() {
  65.324 -                    return new Iterator<K>() {
  65.325 -                        private Iterator<Entry<K,V>> i = entrySet().iterator();
  65.326 -
  65.327 -                        public boolean hasNext() {
  65.328 -                            return i.hasNext();
  65.329 -                        }
  65.330 -
  65.331 -                        public K next() {
  65.332 -                            return i.next().getKey();
  65.333 -                        }
  65.334 -
  65.335 -                        public void remove() {
  65.336 -                            i.remove();
  65.337 -                        }
  65.338 -                    };
  65.339 -                }
  65.340 -
  65.341 -                public int size() {
  65.342 -                    return AbstractMap.this.size();
  65.343 -                }
  65.344 -
  65.345 -                public boolean isEmpty() {
  65.346 -                    return AbstractMap.this.isEmpty();
  65.347 -                }
  65.348 -
  65.349 -                public void clear() {
  65.350 -                    AbstractMap.this.clear();
  65.351 -                }
  65.352 -
  65.353 -                public boolean contains(Object k) {
  65.354 -                    return AbstractMap.this.containsKey(k);
  65.355 -                }
  65.356 -            };
  65.357 -        }
  65.358 -        return keySet;
  65.359 -    }
  65.360 -
  65.361 -    /**
  65.362 -     * {@inheritDoc}
  65.363 -     *
  65.364 -     * <p>This implementation returns a collection that subclasses {@link
  65.365 -     * AbstractCollection}.  The subclass's iterator method returns a
  65.366 -     * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
  65.367 -     * The <tt>size</tt> method delegates to this map's <tt>size</tt>
  65.368 -     * method and the <tt>contains</tt> method delegates to this map's
  65.369 -     * <tt>containsValue</tt> method.
  65.370 -     *
  65.371 -     * <p>The collection is created the first time this method is called, and
  65.372 -     * returned in response to all subsequent calls.  No synchronization is
  65.373 -     * performed, so there is a slight chance that multiple calls to this
  65.374 -     * method will not all return the same collection.
  65.375 -     */
  65.376 -    public Collection<V> values() {
  65.377 -        if (values == null) {
  65.378 -            values = new AbstractCollection<V>() {
  65.379 -                public Iterator<V> iterator() {
  65.380 -                    return new Iterator<V>() {
  65.381 -                        private Iterator<Entry<K,V>> i = entrySet().iterator();
  65.382 -
  65.383 -                        public boolean hasNext() {
  65.384 -                            return i.hasNext();
  65.385 -                        }
  65.386 -
  65.387 -                        public V next() {
  65.388 -                            return i.next().getValue();
  65.389 -                        }
  65.390 -
  65.391 -                        public void remove() {
  65.392 -                            i.remove();
  65.393 -                        }
  65.394 -                    };
  65.395 -                }
  65.396 -
  65.397 -                public int size() {
  65.398 -                    return AbstractMap.this.size();
  65.399 -                }
  65.400 -
  65.401 -                public boolean isEmpty() {
  65.402 -                    return AbstractMap.this.isEmpty();
  65.403 -                }
  65.404 -
  65.405 -                public void clear() {
  65.406 -                    AbstractMap.this.clear();
  65.407 -                }
  65.408 -
  65.409 -                public boolean contains(Object v) {
  65.410 -                    return AbstractMap.this.containsValue(v);
  65.411 -                }
  65.412 -            };
  65.413 -        }
  65.414 -        return values;
  65.415 -    }
  65.416 -
  65.417 -    public abstract Set<Entry<K,V>> entrySet();
  65.418 -
  65.419 -
  65.420 -    // Comparison and hashing
  65.421 -
  65.422 -    /**
  65.423 -     * Compares the specified object with this map for equality.  Returns
  65.424 -     * <tt>true</tt> if the given object is also a map and the two maps
  65.425 -     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
  65.426 -     * <tt>m2</tt> represent the same mappings if
  65.427 -     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
  65.428 -     * <tt>equals</tt> method works properly across different implementations
  65.429 -     * of the <tt>Map</tt> interface.
  65.430 -     *
  65.431 -     * <p>This implementation first checks if the specified object is this map;
  65.432 -     * if so it returns <tt>true</tt>.  Then, it checks if the specified
  65.433 -     * object is a map whose size is identical to the size of this map; if
  65.434 -     * not, it returns <tt>false</tt>.  If so, it iterates over this map's
  65.435 -     * <tt>entrySet</tt> collection, and checks that the specified map
  65.436 -     * contains each mapping that this map contains.  If the specified map
  65.437 -     * fails to contain such a mapping, <tt>false</tt> is returned.  If the
  65.438 -     * iteration completes, <tt>true</tt> is returned.
  65.439 -     *
  65.440 -     * @param o object to be compared for equality with this map
  65.441 -     * @return <tt>true</tt> if the specified object is equal to this map
  65.442 -     */
  65.443 -    public boolean equals(Object o) {
  65.444 -        if (o == this)
  65.445 -            return true;
  65.446 -
  65.447 -        if (!(o instanceof Map))
  65.448 -            return false;
  65.449 -        Map<K,V> m = (Map<K,V>) o;
  65.450 -        if (m.size() != size())
  65.451 -            return false;
  65.452 -
  65.453 -        try {
  65.454 -            Iterator<Entry<K,V>> i = entrySet().iterator();
  65.455 -            while (i.hasNext()) {
  65.456 -                Entry<K,V> e = i.next();
  65.457 -                K key = e.getKey();
  65.458 -                V value = e.getValue();
  65.459 -                if (value == null) {
  65.460 -                    if (!(m.get(key)==null && m.containsKey(key)))
  65.461 -                        return false;
  65.462 -                } else {
  65.463 -                    if (!value.equals(m.get(key)))
  65.464 -                        return false;
  65.465 -                }
  65.466 -            }
  65.467 -        } catch (ClassCastException unused) {
  65.468 -            return false;
  65.469 -        } catch (NullPointerException unused) {
  65.470 -            return false;
  65.471 -        }
  65.472 -
  65.473 -        return true;
  65.474 -    }
  65.475 -
  65.476 -    /**
  65.477 -     * Returns the hash code value for this map.  The hash code of a map is
  65.478 -     * defined to be the sum of the hash codes of each entry in the map's
  65.479 -     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
  65.480 -     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
  65.481 -     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
  65.482 -     * {@link Object#hashCode}.
  65.483 -     *
  65.484 -     * <p>This implementation iterates over <tt>entrySet()</tt>, calling
  65.485 -     * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
  65.486 -     * set, and adding up the results.
  65.487 -     *
  65.488 -     * @return the hash code value for this map
  65.489 -     * @see Map.Entry#hashCode()
  65.490 -     * @see Object#equals(Object)
  65.491 -     * @see Set#equals(Object)
  65.492 -     */
  65.493 -    public int hashCode() {
  65.494 -        int h = 0;
  65.495 -        Iterator<Entry<K,V>> i = entrySet().iterator();
  65.496 -        while (i.hasNext())
  65.497 -            h += i.next().hashCode();
  65.498 -        return h;
  65.499 -    }
  65.500 -
  65.501 -    /**
  65.502 -     * Returns a string representation of this map.  The string representation
  65.503 -     * consists of a list of key-value mappings in the order returned by the
  65.504 -     * map's <tt>entrySet</tt> view's iterator, enclosed in braces
  65.505 -     * (<tt>"{}"</tt>).  Adjacent mappings are separated by the characters
  65.506 -     * <tt>", "</tt> (comma and space).  Each key-value mapping is rendered as
  65.507 -     * the key followed by an equals sign (<tt>"="</tt>) followed by the
  65.508 -     * associated value.  Keys and values are converted to strings as by
  65.509 -     * {@link String#valueOf(Object)}.
  65.510 -     *
  65.511 -     * @return a string representation of this map
  65.512 -     */
  65.513 -    public String toString() {
  65.514 -        Iterator<Entry<K,V>> i = entrySet().iterator();
  65.515 -        if (! i.hasNext())
  65.516 -            return "{}";
  65.517 -
  65.518 -        StringBuilder sb = new StringBuilder();
  65.519 -        sb.append('{');
  65.520 -        for (;;) {
  65.521 -            Entry<K,V> e = i.next();
  65.522 -            K key = e.getKey();
  65.523 -            V value = e.getValue();
  65.524 -            sb.append(key   == this ? "(this Map)" : key);
  65.525 -            sb.append('=');
  65.526 -            sb.append(value == this ? "(this Map)" : value);
  65.527 -            if (! i.hasNext())
  65.528 -                return sb.append('}').toString();
  65.529 -            sb.append(',').append(' ');
  65.530 -        }
  65.531 -    }
  65.532 -
  65.533 -    /**
  65.534 -     * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
  65.535 -     * and values themselves are not cloned.
  65.536 -     *
  65.537 -     * @return a shallow copy of this map
  65.538 -     */
  65.539 -    protected Object clone() throws CloneNotSupportedException {
  65.540 -        AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
  65.541 -        result.keySet = null;
  65.542 -        result.values = null;
  65.543 -        return result;
  65.544 -    }
  65.545 -
  65.546 -    /**
  65.547 -     * Utility method for SimpleEntry and SimpleImmutableEntry.
  65.548 -     * Test for equality, checking for nulls.
  65.549 -     */
  65.550 -    private static boolean eq(Object o1, Object o2) {
  65.551 -        return o1 == null ? o2 == null : o1.equals(o2);
  65.552 -    }
  65.553 -
  65.554 -    // Implementation Note: SimpleEntry and SimpleImmutableEntry
  65.555 -    // are distinct unrelated classes, even though they share
  65.556 -    // some code. Since you can't add or subtract final-ness
  65.557 -    // of a field in a subclass, they can't share representations,
  65.558 -    // and the amount of duplicated code is too small to warrant
  65.559 -    // exposing a common abstract class.
  65.560 -
  65.561 -
  65.562 -    /**
  65.563 -     * An Entry maintaining a key and a value.  The value may be
  65.564 -     * changed using the <tt>setValue</tt> method.  This class
  65.565 -     * facilitates the process of building custom map
  65.566 -     * implementations. For example, it may be convenient to return
  65.567 -     * arrays of <tt>SimpleEntry</tt> instances in method
  65.568 -     * <tt>Map.entrySet().toArray</tt>.
  65.569 -     *
  65.570 -     * @since 1.6
  65.571 -     */
  65.572 -    public static class SimpleEntry<K,V>
  65.573 -        implements Entry<K,V>, java.io.Serializable
  65.574 -    {
  65.575 -        private static final long serialVersionUID = -8499721149061103585L;
  65.576 -
  65.577 -        private final K key;
  65.578 -        private V value;
  65.579 -
  65.580 -        /**
  65.581 -         * Creates an entry representing a mapping from the specified
  65.582 -         * key to the specified value.
  65.583 -         *
  65.584 -         * @param key the key represented by this entry
  65.585 -         * @param value the value represented by this entry
  65.586 -         */
  65.587 -        public SimpleEntry(K key, V value) {
  65.588 -            this.key   = key;
  65.589 -            this.value = value;
  65.590 -        }
  65.591 -
  65.592 -        /**
  65.593 -         * Creates an entry representing the same mapping as the
  65.594 -         * specified entry.
  65.595 -         *
  65.596 -         * @param entry the entry to copy
  65.597 -         */
  65.598 -        public SimpleEntry(Entry<? extends K, ? extends V> entry) {
  65.599 -            this.key   = entry.getKey();
  65.600 -            this.value = entry.getValue();
  65.601 -        }
  65.602 -
  65.603 -        /**
  65.604 -         * Returns the key corresponding to this entry.
  65.605 -         *
  65.606 -         * @return the key corresponding to this entry
  65.607 -         */
  65.608 -        public K getKey() {
  65.609 -            return key;
  65.610 -        }
  65.611 -
  65.612 -        /**
  65.613 -         * Returns the value corresponding to this entry.
  65.614 -         *
  65.615 -         * @return the value corresponding to this entry
  65.616 -         */
  65.617 -        public V getValue() {
  65.618 -            return value;
  65.619 -        }
  65.620 -
  65.621 -        /**
  65.622 -         * Replaces the value corresponding to this entry with the specified
  65.623 -         * value.
  65.624 -         *
  65.625 -         * @param value new value to be stored in this entry
  65.626 -         * @return the old value corresponding to the entry
  65.627 -         */
  65.628 -        public V setValue(V value) {
  65.629 -            V oldValue = this.value;
  65.630 -            this.value = value;
  65.631 -            return oldValue;
  65.632 -        }
  65.633 -
  65.634 -        /**
  65.635 -         * Compares the specified object with this entry for equality.
  65.636 -         * Returns {@code true} if the given object is also a map entry and
  65.637 -         * the two entries represent the same mapping.  More formally, two
  65.638 -         * entries {@code e1} and {@code e2} represent the same mapping
  65.639 -         * if<pre>
  65.640 -         *   (e1.getKey()==null ?
  65.641 -         *    e2.getKey()==null :
  65.642 -         *    e1.getKey().equals(e2.getKey()))
  65.643 -         *   &amp;&amp;
  65.644 -         *   (e1.getValue()==null ?
  65.645 -         *    e2.getValue()==null :
  65.646 -         *    e1.getValue().equals(e2.getValue()))</pre>
  65.647 -         * This ensures that the {@code equals} method works properly across
  65.648 -         * different implementations of the {@code Map.Entry} interface.
  65.649 -         *
  65.650 -         * @param o object to be compared for equality with this map entry
  65.651 -         * @return {@code true} if the specified object is equal to this map
  65.652 -         *         entry
  65.653 -         * @see    #hashCode
  65.654 -         */
  65.655 -        public boolean equals(Object o) {
  65.656 -            if (!(o instanceof Map.Entry))
  65.657 -                return false;
  65.658 -            Map.Entry e = (Map.Entry)o;
  65.659 -            return eq(key, e.getKey()) && eq(value, e.getValue());
  65.660 -        }
  65.661 -
  65.662 -        /**
  65.663 -         * Returns the hash code value for this map entry.  The hash code
  65.664 -         * of a map entry {@code e} is defined to be: <pre>
  65.665 -         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
  65.666 -         *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
  65.667 -         * This ensures that {@code e1.equals(e2)} implies that
  65.668 -         * {@code e1.hashCode()==e2.hashCode()} for any two Entries
  65.669 -         * {@code e1} and {@code e2}, as required by the general
  65.670 -         * contract of {@link Object#hashCode}.
  65.671 -         *
  65.672 -         * @return the hash code value for this map entry
  65.673 -         * @see    #equals
  65.674 -         */
  65.675 -        public int hashCode() {
  65.676 -            return (key   == null ? 0 :   key.hashCode()) ^
  65.677 -                   (value == null ? 0 : value.hashCode());
  65.678 -        }
  65.679 -
  65.680 -        /**
  65.681 -         * Returns a String representation of this map entry.  This
  65.682 -         * implementation returns the string representation of this
  65.683 -         * entry's key followed by the equals character ("<tt>=</tt>")
  65.684 -         * followed by the string representation of this entry's value.
  65.685 -         *
  65.686 -         * @return a String representation of this map entry
  65.687 -         */
  65.688 -        public String toString() {
  65.689 -            return key + "=" + value;
  65.690 -        }
  65.691 -
  65.692 -    }
  65.693 -
  65.694 -    /**
  65.695 -     * An Entry maintaining an immutable key and value.  This class
  65.696 -     * does not support method <tt>setValue</tt>.  This class may be
  65.697 -     * convenient in methods that return thread-safe snapshots of
  65.698 -     * key-value mappings.
  65.699 -     *
  65.700 -     * @since 1.6
  65.701 -     */
  65.702 -    public static class SimpleImmutableEntry<K,V>
  65.703 -        implements Entry<K,V>, java.io.Serializable
  65.704 -    {
  65.705 -        private static final long serialVersionUID = 7138329143949025153L;
  65.706 -
  65.707 -        private final K key;
  65.708 -        private final V value;
  65.709 -
  65.710 -        /**
  65.711 -         * Creates an entry representing a mapping from the specified
  65.712 -         * key to the specified value.
  65.713 -         *
  65.714 -         * @param key the key represented by this entry
  65.715 -         * @param value the value represented by this entry
  65.716 -         */
  65.717 -        public SimpleImmutableEntry(K key, V value) {
  65.718 -            this.key   = key;
  65.719 -            this.value = value;
  65.720 -        }
  65.721 -
  65.722 -        /**
  65.723 -         * Creates an entry representing the same mapping as the
  65.724 -         * specified entry.
  65.725 -         *
  65.726 -         * @param entry the entry to copy
  65.727 -         */
  65.728 -        public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) {
  65.729 -            this.key   = entry.getKey();
  65.730 -            this.value = entry.getValue();
  65.731 -        }
  65.732 -
  65.733 -        /**
  65.734 -         * Returns the key corresponding to this entry.
  65.735 -         *
  65.736 -         * @return the key corresponding to this entry
  65.737 -         */
  65.738 -        public K getKey() {
  65.739 -            return key;
  65.740 -        }
  65.741 -
  65.742 -        /**
  65.743 -         * Returns the value corresponding to this entry.
  65.744 -         *
  65.745 -         * @return the value corresponding to this entry
  65.746 -         */
  65.747 -        public V getValue() {
  65.748 -            return value;
  65.749 -        }
  65.750 -
  65.751 -        /**
  65.752 -         * Replaces the value corresponding to this entry with the specified
  65.753 -         * value (optional operation).  This implementation simply throws
  65.754 -         * <tt>UnsupportedOperationException</tt>, as this class implements
  65.755 -         * an <i>immutable</i> map entry.
  65.756 -         *
  65.757 -         * @param value new value to be stored in this entry
  65.758 -         * @return (Does not return)
  65.759 -         * @throws UnsupportedOperationException always
  65.760 -         */
  65.761 -        public V setValue(V value) {
  65.762 -            throw new UnsupportedOperationException();
  65.763 -        }
  65.764 -
  65.765 -        /**
  65.766 -         * Compares the specified object with this entry for equality.
  65.767 -         * Returns {@code true} if the given object is also a map entry and
  65.768 -         * the two entries represent the same mapping.  More formally, two
  65.769 -         * entries {@code e1} and {@code e2} represent the same mapping
  65.770 -         * if<pre>
  65.771 -         *   (e1.getKey()==null ?
  65.772 -         *    e2.getKey()==null :
  65.773 -         *    e1.getKey().equals(e2.getKey()))
  65.774 -         *   &amp;&amp;
  65.775 -         *   (e1.getValue()==null ?
  65.776 -         *    e2.getValue()==null :
  65.777 -         *    e1.getValue().equals(e2.getValue()))</pre>
  65.778 -         * This ensures that the {@code equals} method works properly across
  65.779 -         * different implementations of the {@code Map.Entry} interface.
  65.780 -         *
  65.781 -         * @param o object to be compared for equality with this map entry
  65.782 -         * @return {@code true} if the specified object is equal to this map
  65.783 -         *         entry
  65.784 -         * @see    #hashCode
  65.785 -         */
  65.786 -        public boolean equals(Object o) {
  65.787 -            if (!(o instanceof Map.Entry))
  65.788 -                return false;
  65.789 -            Map.Entry e = (Map.Entry)o;
  65.790 -            return eq(key, e.getKey()) && eq(value, e.getValue());
  65.791 -        }
  65.792 -
  65.793 -        /**
  65.794 -         * Returns the hash code value for this map entry.  The hash code
  65.795 -         * of a map entry {@code e} is defined to be: <pre>
  65.796 -         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
  65.797 -         *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
  65.798 -         * This ensures that {@code e1.equals(e2)} implies that
  65.799 -         * {@code e1.hashCode()==e2.hashCode()} for any two Entries
  65.800 -         * {@code e1} and {@code e2}, as required by the general
  65.801 -         * contract of {@link Object#hashCode}.
  65.802 -         *
  65.803 -         * @return the hash code value for this map entry
  65.804 -         * @see    #equals
  65.805 -         */
  65.806 -        public int hashCode() {
  65.807 -            return (key   == null ? 0 :   key.hashCode()) ^
  65.808 -                   (value == null ? 0 : value.hashCode());
  65.809 -        }
  65.810 -
  65.811 -        /**
  65.812 -         * Returns a String representation of this map entry.  This
  65.813 -         * implementation returns the string representation of this
  65.814 -         * entry's key followed by the equals character ("<tt>=</tt>")
  65.815 -         * followed by the string representation of this entry's value.
  65.816 -         *
  65.817 -         * @return a String representation of this map entry
  65.818 -         */
  65.819 -        public String toString() {
  65.820 -            return key + "=" + value;
  65.821 -        }
  65.822 -
  65.823 -    }
  65.824 -
  65.825 -}
    66.1 --- a/emul/compact/src/main/java/java/util/AbstractQueue.java	Mon Feb 25 19:00:08 2013 +0100
    66.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.3 @@ -1,192 +0,0 @@
    66.4 -/*
    66.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    66.6 - *
    66.7 - * This code is free software; you can redistribute it and/or modify it
    66.8 - * under the terms of the GNU General Public License version 2 only, as
    66.9 - * published by the Free Software Foundation.  Oracle designates this
   66.10 - * particular file as subject to the "Classpath" exception as provided
   66.11 - * by Oracle in the LICENSE file that accompanied this code.
   66.12 - *
   66.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
   66.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   66.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   66.16 - * version 2 for more details (a copy is included in the LICENSE file that
   66.17 - * accompanied this code).
   66.18 - *
   66.19 - * You should have received a copy of the GNU General Public License version
   66.20 - * 2 along with this work; if not, write to the Free Software Foundation,
   66.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   66.22 - *
   66.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   66.24 - * or visit www.oracle.com if you need additional information or have any
   66.25 - * questions.
   66.26 - */
   66.27 -
   66.28 -/*
   66.29 - * This file is available under and governed by the GNU General Public
   66.30 - * License version 2 only, as published by the Free Software Foundation.
   66.31 - * However, the following notice accompanied the original version of this
   66.32 - * file:
   66.33 - *
   66.34 - * Written by Doug Lea with assistance from members of JCP JSR-166
   66.35 - * Expert Group and released to the public domain, as explained at
   66.36 - * http://creativecommons.org/publicdomain/zero/1.0/
   66.37 - */
   66.38 -
   66.39 -package java.util;
   66.40 -
   66.41 -/**
   66.42 - * This class provides skeletal implementations of some {@link Queue}
   66.43 - * operations. The implementations in this class are appropriate when
   66.44 - * the base implementation does <em>not</em> allow <tt>null</tt>
   66.45 - * elements.  Methods {@link #add add}, {@link #remove remove}, and
   66.46 - * {@link #element element} are based on {@link #offer offer}, {@link
   66.47 - * #poll poll}, and {@link #peek peek}, respectively, but throw
   66.48 - * exceptions instead of indicating failure via <tt>false</tt> or
   66.49 - * <tt>null</tt> returns.
   66.50 - *
   66.51 - * <p>A <tt>Queue</tt> implementation that extends this class must
   66.52 - * minimally define a method {@link Queue#offer} which does not permit
   66.53 - * insertion of <tt>null</tt> elements, along with methods {@link
   66.54 - * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and
   66.55 - * {@link Collection#iterator}.  Typically, additional methods will be
   66.56 - * overridden as well.  If these requirements cannot be met, consider
   66.57 - * instead subclassing {@link AbstractCollection}.
   66.58 - *
   66.59 - * <p>This class is a member of the
   66.60 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   66.61 - * Java Collections Framework</a>.
   66.62 - *
   66.63 - * @since 1.5
   66.64 - * @author Doug Lea
   66.65 - * @param <E> the type of elements held in this collection
   66.66 - */
   66.67 -public abstract class AbstractQueue<E>
   66.68 -    extends AbstractCollection<E>
   66.69 -    implements Queue<E> {
   66.70 -
   66.71 -    /**
   66.72 -     * Constructor for use by subclasses.
   66.73 -     */
   66.74 -    protected AbstractQueue() {
   66.75 -    }
   66.76 -
   66.77 -    /**
   66.78 -     * Inserts the specified element into this queue if it is possible to do so
   66.79 -     * immediately without violating capacity restrictions, returning
   66.80 -     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
   66.81 -     * if no space is currently available.
   66.82 -     *
   66.83 -     * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds,
   66.84 -     * else throws an <tt>IllegalStateException</tt>.
   66.85 -     *
   66.86 -     * @param e the element to add
   66.87 -     * @return <tt>true</tt> (as specified by {@link Collection#add})
   66.88 -     * @throws IllegalStateException if the element cannot be added at this
   66.89 -     *         time due to capacity restrictions
   66.90 -     * @throws ClassCastException if the class of the specified element
   66.91 -     *         prevents it from being added to this queue
   66.92 -     * @throws NullPointerException if the specified element is null and
   66.93 -     *         this queue does not permit null elements
   66.94 -     * @throws IllegalArgumentException if some property of this element
   66.95 -     *         prevents it from being added to this queue
   66.96 -     */
   66.97 -    public boolean add(E e) {
   66.98 -        if (offer(e))
   66.99 -            return true;
  66.100 -        else
  66.101 -            throw new IllegalStateException("Queue full");
  66.102 -    }
  66.103 -
  66.104 -    /**
  66.105 -     * Retrieves and removes the head of this queue.  This method differs
  66.106 -     * from {@link #poll poll} only in that it throws an exception if this
  66.107 -     * queue is empty.
  66.108 -     *
  66.109 -     * <p>This implementation returns the result of <tt>poll</tt>
  66.110 -     * unless the queue is empty.
  66.111 -     *
  66.112 -     * @return the head of this queue
  66.113 -     * @throws NoSuchElementException if this queue is empty
  66.114 -     */
  66.115 -    public E remove() {
  66.116 -        E x = poll();
  66.117 -        if (x != null)
  66.118 -            return x;
  66.119 -        else
  66.120 -            throw new NoSuchElementException();
  66.121 -    }
  66.122 -
  66.123 -    /**
  66.124 -     * Retrieves, but does not remove, the head of this queue.  This method
  66.125 -     * differs from {@link #peek peek} only in that it throws an exception if
  66.126 -     * this queue is empty.
  66.127 -     *
  66.128 -     * <p>This implementation returns the result of <tt>peek</tt>
  66.129 -     * unless the queue is empty.
  66.130 -     *
  66.131 -     * @return the head of this queue
  66.132 -     * @throws NoSuchElementException if this queue is empty
  66.133 -     */
  66.134 -    public E element() {
  66.135 -        E x = peek();
  66.136 -        if (x != null)
  66.137 -            return x;
  66.138 -        else
  66.139 -            throw new NoSuchElementException();
  66.140 -    }
  66.141 -
  66.142 -    /**
  66.143 -     * Removes all of the elements from this queue.
  66.144 -     * The queue will be empty after this call returns.
  66.145 -     *
  66.146 -     * <p>This implementation repeatedly invokes {@link #poll poll} until it
  66.147 -     * returns <tt>null</tt>.
  66.148 -     */
  66.149 -    public void clear() {
  66.150 -        while (poll() != null)
  66.151 -            ;
  66.152 -    }
  66.153 -
  66.154 -    /**
  66.155 -     * Adds all of the elements in the specified collection to this
  66.156 -     * queue.  Attempts to addAll of a queue to itself result in
  66.157 -     * <tt>IllegalArgumentException</tt>. Further, the behavior of
  66.158 -     * this operation is undefined if the specified collection is
  66.159 -     * modified while the operation is in progress.
  66.160 -     *
  66.161 -     * <p>This implementation iterates over the specified collection,
  66.162 -     * and adds each element returned by the iterator to this
  66.163 -     * queue, in turn.  A runtime exception encountered while
  66.164 -     * trying to add an element (including, in particular, a
  66.165 -     * <tt>null</tt> element) may result in only some of the elements
  66.166 -     * having been successfully added when the associated exception is
  66.167 -     * thrown.
  66.168 -     *
  66.169 -     * @param c collection containing elements to be added to this queue
  66.170 -     * @return <tt>true</tt> if this queue changed as a result of the call
  66.171 -     * @throws ClassCastException if the class of an element of the specified
  66.172 -     *         collection prevents it from being added to this queue
  66.173 -     * @throws NullPointerException if the specified collection contains a
  66.174 -     *         null element and this queue does not permit null elements,
  66.175 -     *         or if the specified collection is null
  66.176 -     * @throws IllegalArgumentException if some property of an element of the
  66.177 -     *         specified collection prevents it from being added to this
  66.178 -     *         queue, or if the specified collection is this queue
  66.179 -     * @throws IllegalStateException if not all the elements can be added at
  66.180 -     *         this time due to insertion restrictions
  66.181 -     * @see #add(Object)
  66.182 -     */
  66.183 -    public boolean addAll(Collection<? extends E> c) {
  66.184 -        if (c == null)
  66.185 -            throw new NullPointerException();
  66.186 -        if (c == this)
  66.187 -            throw new IllegalArgumentException();
  66.188 -        boolean modified = false;
  66.189 -        for (E e : c)
  66.190 -            if (add(e))
  66.191 -                modified = true;
  66.192 -        return modified;
  66.193 -    }
  66.194 -
  66.195 -}
    67.1 --- a/emul/compact/src/main/java/java/util/AbstractSequentialList.java	Mon Feb 25 19:00:08 2013 +0100
    67.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.3 @@ -1,253 +0,0 @@
    67.4 -/*
    67.5 - * Copyright (c) 1997, 2006, 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 -
   67.31 -/**
   67.32 - * This class provides a skeletal implementation of the <tt>List</tt>
   67.33 - * interface to minimize the effort required to implement this interface
   67.34 - * backed by a "sequential access" data store (such as a linked list).  For
   67.35 - * random access data (such as an array), <tt>AbstractList</tt> should be used
   67.36 - * in preference to this class.<p>
   67.37 - *
   67.38 - * This class is the opposite of the <tt>AbstractList</tt> class in the sense
   67.39 - * that it implements the "random access" methods (<tt>get(int index)</tt>,
   67.40 - * <tt>set(int index, E element)</tt>, <tt>add(int index, E element)</tt> and
   67.41 - * <tt>remove(int index)</tt>) on top of the list's list iterator, instead of
   67.42 - * the other way around.<p>
   67.43 - *
   67.44 - * To implement a list the programmer needs only to extend this class and
   67.45 - * provide implementations for the <tt>listIterator</tt> and <tt>size</tt>
   67.46 - * methods.  For an unmodifiable list, the programmer need only implement the
   67.47 - * list iterator's <tt>hasNext</tt>, <tt>next</tt>, <tt>hasPrevious</tt>,
   67.48 - * <tt>previous</tt> and <tt>index</tt> methods.<p>
   67.49 - *
   67.50 - * For a modifiable list the programmer should additionally implement the list
   67.51 - * iterator's <tt>set</tt> method.  For a variable-size list the programmer
   67.52 - * should additionally implement the list iterator's <tt>remove</tt> and
   67.53 - * <tt>add</tt> methods.<p>
   67.54 - *
   67.55 - * The programmer should generally provide a void (no argument) and collection
   67.56 - * constructor, as per the recommendation in the <tt>Collection</tt> interface
   67.57 - * specification.<p>
   67.58 - *
   67.59 - * This class is a member of the
   67.60 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   67.61 - * Java Collections Framework</a>.
   67.62 - *
   67.63 - * @author  Josh Bloch
   67.64 - * @author  Neal Gafter
   67.65 - * @see Collection
   67.66 - * @see List
   67.67 - * @see AbstractList
   67.68 - * @see AbstractCollection
   67.69 - * @since 1.2
   67.70 - */
   67.71 -
   67.72 -public abstract class AbstractSequentialList<E> extends AbstractList<E> {
   67.73 -    /**
   67.74 -     * Sole constructor.  (For invocation by subclass constructors, typically
   67.75 -     * implicit.)
   67.76 -     */
   67.77 -    protected AbstractSequentialList() {
   67.78 -    }
   67.79 -
   67.80 -    /**
   67.81 -     * Returns the element at the specified position in this list.
   67.82 -     *
   67.83 -     * <p>This implementation first gets a list iterator pointing to the
   67.84 -     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
   67.85 -     * the element using <tt>ListIterator.next</tt> and returns it.
   67.86 -     *
   67.87 -     * @throws IndexOutOfBoundsException {@inheritDoc}
   67.88 -     */
   67.89 -    public E get(int index) {
   67.90 -        try {
   67.91 -            return listIterator(index).next();
   67.92 -        } catch (NoSuchElementException exc) {
   67.93 -            throw new IndexOutOfBoundsException("Index: "+index);
   67.94 -        }
   67.95 -    }
   67.96 -
   67.97 -    /**
   67.98 -     * Replaces the element at the specified position in this list with the
   67.99 -     * specified element (optional operation).
  67.100 -     *
  67.101 -     * <p>This implementation first gets a list iterator pointing to the
  67.102 -     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
  67.103 -     * the current element using <tt>ListIterator.next</tt> and replaces it
  67.104 -     * with <tt>ListIterator.set</tt>.
  67.105 -     *
  67.106 -     * <p>Note that this implementation will throw an
  67.107 -     * <tt>UnsupportedOperationException</tt> if the list iterator does not
  67.108 -     * implement the <tt>set</tt> operation.
  67.109 -     *
  67.110 -     * @throws UnsupportedOperationException {@inheritDoc}
  67.111 -     * @throws ClassCastException            {@inheritDoc}
  67.112 -     * @throws NullPointerException          {@inheritDoc}
  67.113 -     * @throws IllegalArgumentException      {@inheritDoc}
  67.114 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  67.115 -     */
  67.116 -    public E set(int index, E element) {
  67.117 -        try {
  67.118 -            ListIterator<E> e = listIterator(index);
  67.119 -            E oldVal = e.next();
  67.120 -            e.set(element);
  67.121 -            return oldVal;
  67.122 -        } catch (NoSuchElementException exc) {
  67.123 -            throw new IndexOutOfBoundsException("Index: "+index);
  67.124 -        }
  67.125 -    }
  67.126 -
  67.127 -    /**
  67.128 -     * Inserts the specified element at the specified position in this list
  67.129 -     * (optional operation).  Shifts the element currently at that position
  67.130 -     * (if any) and any subsequent elements to the right (adds one to their
  67.131 -     * indices).
  67.132 -     *
  67.133 -     * <p>This implementation first gets a list iterator pointing to the
  67.134 -     * indexed element (with <tt>listIterator(index)</tt>).  Then, it
  67.135 -     * inserts the specified element with <tt>ListIterator.add</tt>.
  67.136 -     *
  67.137 -     * <p>Note that this implementation will throw an
  67.138 -     * <tt>UnsupportedOperationException</tt> if the list iterator does not
  67.139 -     * implement the <tt>add</tt> operation.
  67.140 -     *
  67.141 -     * @throws UnsupportedOperationException {@inheritDoc}
  67.142 -     * @throws ClassCastException            {@inheritDoc}
  67.143 -     * @throws NullPointerException          {@inheritDoc}
  67.144 -     * @throws IllegalArgumentException      {@inheritDoc}
  67.145 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  67.146 -     */
  67.147 -    public void add(int index, E element) {
  67.148 -        try {
  67.149 -            listIterator(index).add(element);
  67.150 -        } catch (NoSuchElementException exc) {
  67.151 -            throw new IndexOutOfBoundsException("Index: "+index);
  67.152 -        }
  67.153 -    }
  67.154 -
  67.155 -    /**
  67.156 -     * Removes the element at the specified position in this list (optional
  67.157 -     * operation).  Shifts any subsequent elements to the left (subtracts one
  67.158 -     * from their indices).  Returns the element that was removed from the
  67.159 -     * list.
  67.160 -     *
  67.161 -     * <p>This implementation first gets a list iterator pointing to the
  67.162 -     * indexed element (with <tt>listIterator(index)</tt>).  Then, it removes
  67.163 -     * the element with <tt>ListIterator.remove</tt>.
  67.164 -     *
  67.165 -     * <p>Note that this implementation will throw an
  67.166 -     * <tt>UnsupportedOperationException</tt> if the list iterator does not
  67.167 -     * implement the <tt>remove</tt> operation.
  67.168 -     *
  67.169 -     * @throws UnsupportedOperationException {@inheritDoc}
  67.170 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  67.171 -     */
  67.172 -    public E remove(int index) {
  67.173 -        try {
  67.174 -            ListIterator<E> e = listIterator(index);
  67.175 -            E outCast = e.next();
  67.176 -            e.remove();
  67.177 -            return outCast;
  67.178 -        } catch (NoSuchElementException exc) {
  67.179 -            throw new IndexOutOfBoundsException("Index: "+index);
  67.180 -        }
  67.181 -    }
  67.182 -
  67.183 -
  67.184 -    // Bulk Operations
  67.185 -
  67.186 -    /**
  67.187 -     * Inserts all of the elements in the specified collection into this
  67.188 -     * list at the specified position (optional operation).  Shifts the
  67.189 -     * element currently at that position (if any) and any subsequent
  67.190 -     * elements to the right (increases their indices).  The new elements
  67.191 -     * will appear in this list in the order that they are returned by the
  67.192 -     * specified collection's iterator.  The behavior of this operation is
  67.193 -     * undefined if the specified collection is modified while the
  67.194 -     * operation is in progress.  (Note that this will occur if the specified
  67.195 -     * collection is this list, and it's nonempty.)
  67.196 -     *
  67.197 -     * <p>This implementation gets an iterator over the specified collection and
  67.198 -     * a list iterator over this list pointing to the indexed element (with
  67.199 -     * <tt>listIterator(index)</tt>).  Then, it iterates over the specified
  67.200 -     * collection, inserting the elements obtained from the iterator into this
  67.201 -     * list, one at a time, using <tt>ListIterator.add</tt> followed by
  67.202 -     * <tt>ListIterator.next</tt> (to skip over the added element).
  67.203 -     *
  67.204 -     * <p>Note that this implementation will throw an
  67.205 -     * <tt>UnsupportedOperationException</tt> if the list iterator returned by
  67.206 -     * the <tt>listIterator</tt> method does not implement the <tt>add</tt>
  67.207 -     * operation.
  67.208 -     *
  67.209 -     * @throws UnsupportedOperationException {@inheritDoc}
  67.210 -     * @throws ClassCastException            {@inheritDoc}
  67.211 -     * @throws NullPointerException          {@inheritDoc}
  67.212 -     * @throws IllegalArgumentException      {@inheritDoc}
  67.213 -     * @throws IndexOutOfBoundsException     {@inheritDoc}
  67.214 -     */
  67.215 -    public boolean addAll(int index, Collection<? extends E> c) {
  67.216 -        try {
  67.217 -            boolean modified = false;
  67.218 -            ListIterator<E> e1 = listIterator(index);
  67.219 -            Iterator<? extends E> e2 = c.iterator();
  67.220 -            while (e2.hasNext()) {
  67.221 -                e1.add(e2.next());
  67.222 -                modified = true;
  67.223 -            }
  67.224 -            return modified;
  67.225 -        } catch (NoSuchElementException exc) {
  67.226 -            throw new IndexOutOfBoundsException("Index: "+index);
  67.227 -        }
  67.228 -    }
  67.229 -
  67.230 -
  67.231 -    // Iterators
  67.232 -
  67.233 -    /**
  67.234 -     * Returns an iterator over the elements in this list (in proper
  67.235 -     * sequence).<p>
  67.236 -     *
  67.237 -     * This implementation merely returns a list iterator over the list.
  67.238 -     *
  67.239 -     * @return an iterator over the elements in this list (in proper sequence)
  67.240 -     */
  67.241 -    public Iterator<E> iterator() {
  67.242 -        return listIterator();
  67.243 -    }
  67.244 -
  67.245 -    /**
  67.246 -     * Returns a list iterator over the elements in this list (in proper
  67.247 -     * sequence).
  67.248 -     *
  67.249 -     * @param  index index of first element to be returned from the list
  67.250 -     *         iterator (by a call to the <code>next</code> method)
  67.251 -     * @return a list iterator over the elements in this list (in proper
  67.252 -     *         sequence)
  67.253 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  67.254 -     */
  67.255 -    public abstract ListIterator<E> listIterator(int index);
  67.256 -}
    68.1 --- a/emul/compact/src/main/java/java/util/AbstractSet.java	Mon Feb 25 19:00:08 2013 +0100
    68.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.3 @@ -1,185 +0,0 @@
    68.4 -/*
    68.5 - * Copyright (c) 1997, 2006, 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 - * This class provides a skeletal implementation of the <tt>Set</tt>
   68.33 - * interface to minimize the effort required to implement this
   68.34 - * interface. <p>
   68.35 - *
   68.36 - * The process of implementing a set by extending this class is identical
   68.37 - * to that of implementing a Collection by extending AbstractCollection,
   68.38 - * except that all of the methods and constructors in subclasses of this
   68.39 - * class must obey the additional constraints imposed by the <tt>Set</tt>
   68.40 - * interface (for instance, the add method must not permit addition of
   68.41 - * multiple instances of an object to a set).<p>
   68.42 - *
   68.43 - * Note that this class does not override any of the implementations from
   68.44 - * the <tt>AbstractCollection</tt> class.  It merely adds implementations
   68.45 - * for <tt>equals</tt> and <tt>hashCode</tt>.<p>
   68.46 - *
   68.47 - * This class is a member of the
   68.48 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   68.49 - * Java Collections Framework</a>.
   68.50 - *
   68.51 - * @param <E> the type of elements maintained by this set
   68.52 - *
   68.53 - * @author  Josh Bloch
   68.54 - * @author  Neal Gafter
   68.55 - * @see Collection
   68.56 - * @see AbstractCollection
   68.57 - * @see Set
   68.58 - * @since 1.2
   68.59 - */
   68.60 -
   68.61 -public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E> {
   68.62 -    /**
   68.63 -     * Sole constructor.  (For invocation by subclass constructors, typically
   68.64 -     * implicit.)
   68.65 -     */
   68.66 -    protected AbstractSet() {
   68.67 -    }
   68.68 -
   68.69 -    // Comparison and hashing
   68.70 -
   68.71 -    /**
   68.72 -     * Compares the specified object with this set for equality.  Returns
   68.73 -     * <tt>true</tt> if the given object is also a set, the two sets have
   68.74 -     * the same size, and every member of the given set is contained in
   68.75 -     * this set.  This ensures that the <tt>equals</tt> method works
   68.76 -     * properly across different implementations of the <tt>Set</tt>
   68.77 -     * interface.<p>
   68.78 -     *
   68.79 -     * This implementation first checks if the specified object is this
   68.80 -     * set; if so it returns <tt>true</tt>.  Then, it checks if the
   68.81 -     * specified object is a set whose size is identical to the size of
   68.82 -     * this set; if not, it returns false.  If so, it returns
   68.83 -     * <tt>containsAll((Collection) o)</tt>.
   68.84 -     *
   68.85 -     * @param o object to be compared for equality with this set
   68.86 -     * @return <tt>true</tt> if the specified object is equal to this set
   68.87 -     */
   68.88 -    public boolean equals(Object o) {
   68.89 -        if (o == this)
   68.90 -            return true;
   68.91 -
   68.92 -        if (!(o instanceof Set))
   68.93 -            return false;
   68.94 -        Collection c = (Collection) o;
   68.95 -        if (c.size() != size())
   68.96 -            return false;
   68.97 -        try {
   68.98 -            return containsAll(c);
   68.99 -        } catch (ClassCastException unused)   {
  68.100 -            return false;
  68.101 -        } catch (NullPointerException unused) {
  68.102 -            return false;
  68.103 -        }
  68.104 -    }
  68.105 -
  68.106 -    /**
  68.107 -     * Returns the hash code value for this set.  The hash code of a set is
  68.108 -     * defined to be the sum of the hash codes of the elements in the set,
  68.109 -     * where the hash code of a <tt>null</tt> element is defined to be zero.
  68.110 -     * This ensures that <tt>s1.equals(s2)</tt> implies that
  68.111 -     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
  68.112 -     * and <tt>s2</tt>, as required by the general contract of
  68.113 -     * {@link Object#hashCode}.
  68.114 -     *
  68.115 -     * <p>This implementation iterates over the set, calling the
  68.116 -     * <tt>hashCode</tt> method on each element in the set, and adding up
  68.117 -     * the results.
  68.118 -     *
  68.119 -     * @return the hash code value for this set
  68.120 -     * @see Object#equals(Object)
  68.121 -     * @see Set#equals(Object)
  68.122 -     */
  68.123 -    public int hashCode() {
  68.124 -        int h = 0;
  68.125 -        Iterator<E> i = iterator();
  68.126 -        while (i.hasNext()) {
  68.127 -            E obj = i.next();
  68.128 -            if (obj != null)
  68.129 -                h += obj.hashCode();
  68.130 -        }
  68.131 -        return h;
  68.132 -    }
  68.133 -
  68.134 -    /**
  68.135 -     * Removes from this set all of its elements that are contained in the
  68.136 -     * specified collection (optional operation).  If the specified
  68.137 -     * collection is also a set, this operation effectively modifies this
  68.138 -     * set so that its value is the <i>asymmetric set difference</i> of
  68.139 -     * the two sets.
  68.140 -     *
  68.141 -     * <p>This implementation determines which is the smaller of this set
  68.142 -     * and the specified collection, by invoking the <tt>size</tt>
  68.143 -     * method on each.  If this set has fewer elements, then the
  68.144 -     * implementation iterates over this set, checking each element
  68.145 -     * returned by the iterator in turn to see if it is contained in
  68.146 -     * the specified collection.  If it is so contained, it is removed
  68.147 -     * from this set with the iterator's <tt>remove</tt> method.  If
  68.148 -     * the specified collection has fewer elements, then the
  68.149 -     * implementation iterates over the specified collection, removing
  68.150 -     * from this set each element returned by the iterator, using this
  68.151 -     * set's <tt>remove</tt> method.
  68.152 -     *
  68.153 -     * <p>Note that this implementation will throw an
  68.154 -     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
  68.155 -     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method.
  68.156 -     *
  68.157 -     * @param  c collection containing elements to be removed from this set
  68.158 -     * @return <tt>true</tt> if this set changed as a result of the call
  68.159 -     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
  68.160 -     *         is not supported by this set
  68.161 -     * @throws ClassCastException if the class of an element of this set
  68.162 -     *         is incompatible with the specified collection
  68.163 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  68.164 -     * @throws NullPointerException if this set contains a null element and the
  68.165 -     *         specified collection does not permit null elements
  68.166 -     * (<a href="Collection.html#optional-restrictions">optional</a>),
  68.167 -     *         or if the specified collection is null
  68.168 -     * @see #remove(Object)
  68.169 -     * @see #contains(Object)
  68.170 -     */
  68.171 -    public boolean removeAll(Collection<?> c) {
  68.172 -        boolean modified = false;
  68.173 -
  68.174 -        if (size() > c.size()) {
  68.175 -            for (Iterator<?> i = c.iterator(); i.hasNext(); )
  68.176 -                modified |= remove(i.next());
  68.177 -        } else {
  68.178 -            for (Iterator<?> i = iterator(); i.hasNext(); ) {
  68.179 -                if (c.contains(i.next())) {
  68.180 -                    i.remove();
  68.181 -                    modified = true;
  68.182 -                }
  68.183 -            }
  68.184 -        }
  68.185 -        return modified;
  68.186 -    }
  68.187 -
  68.188 -}
    69.1 --- a/emul/compact/src/main/java/java/util/ArrayDeque.java	Mon Feb 25 19:00:08 2013 +0100
    69.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.3 @@ -1,830 +0,0 @@
    69.4 -/*
    69.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    69.6 - *
    69.7 - * This code is free software; you can redistribute it and/or modify it
    69.8 - * under the terms of the GNU General Public License version 2 only, as
    69.9 - * published by the Free Software Foundation.  Oracle designates this
   69.10 - * particular file as subject to the "Classpath" exception as provided
   69.11 - * by Oracle in the LICENSE file that accompanied this code.
   69.12 - *
   69.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
   69.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   69.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   69.16 - * version 2 for more details (a copy is included in the LICENSE file that
   69.17 - * accompanied this code).
   69.18 - *
   69.19 - * You should have received a copy of the GNU General Public License version
   69.20 - * 2 along with this work; if not, write to the Free Software Foundation,
   69.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   69.22 - *
   69.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   69.24 - * or visit www.oracle.com if you need additional information or have any
   69.25 - * questions.
   69.26 - */
   69.27 -
   69.28 -/*
   69.29 - * This file is available under and governed by the GNU General Public
   69.30 - * License version 2 only, as published by the Free Software Foundation.
   69.31 - * However, the following notice accompanied the original version of this
   69.32 - * file:
   69.33 - *
   69.34 - * Written by Josh Bloch of Google Inc. and released to the public domain,
   69.35 - * as explained at http://creativecommons.org/publicdomain/zero/1.0/.
   69.36 - */
   69.37 -
   69.38 -package java.util;
   69.39 -import java.io.*;
   69.40 -
   69.41 -/**
   69.42 - * Resizable-array implementation of the {@link Deque} interface.  Array
   69.43 - * deques have no capacity restrictions; they grow as necessary to support
   69.44 - * usage.  They are not thread-safe; in the absence of external
   69.45 - * synchronization, they do not support concurrent access by multiple threads.
   69.46 - * Null elements are prohibited.  This class is likely to be faster than
   69.47 - * {@link Stack} when used as a stack, and faster than {@link LinkedList}
   69.48 - * when used as a queue.
   69.49 - *
   69.50 - * <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
   69.51 - * Exceptions include {@link #remove(Object) remove}, {@link
   69.52 - * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
   69.53 - * removeLastOccurrence}, {@link #contains contains}, {@link #iterator
   69.54 - * iterator.remove()}, and the bulk operations, all of which run in linear
   69.55 - * time.
   69.56 - *
   69.57 - * <p>The iterators returned by this class's <tt>iterator</tt> method are
   69.58 - * <i>fail-fast</i>: If the deque is modified at any time after the iterator
   69.59 - * is created, in any way except through the iterator's own <tt>remove</tt>
   69.60 - * method, the iterator will generally throw a {@link
   69.61 - * ConcurrentModificationException}.  Thus, in the face of concurrent
   69.62 - * modification, the iterator fails quickly and cleanly, rather than risking
   69.63 - * arbitrary, non-deterministic behavior at an undetermined time in the
   69.64 - * future.
   69.65 - *
   69.66 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   69.67 - * as it is, generally speaking, impossible to make any hard guarantees in the
   69.68 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
   69.69 - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
   69.70 - * Therefore, it would be wrong to write a program that depended on this
   69.71 - * exception for its correctness: <i>the fail-fast behavior of iterators
   69.72 - * should be used only to detect bugs.</i>
   69.73 - *
   69.74 - * <p>This class and its iterator implement all of the
   69.75 - * <em>optional</em> methods of the {@link Collection} and {@link
   69.76 - * Iterator} interfaces.
   69.77 - *
   69.78 - * <p>This class is a member of the
   69.79 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   69.80 - * Java Collections Framework</a>.
   69.81 - *
   69.82 - * @author  Josh Bloch and Doug Lea
   69.83 - * @since   1.6
   69.84 - * @param <E> the type of elements held in this collection
   69.85 - */
   69.86 -public class ArrayDeque<E> extends AbstractCollection<E>
   69.87 -                           implements Deque<E>, Cloneable, Serializable
   69.88 -{
   69.89 -    /**
   69.90 -     * The array in which the elements of the deque are stored.
   69.91 -     * The capacity of the deque is the length of this array, which is
   69.92 -     * always a power of two. The array is never allowed to become
   69.93 -     * full, except transiently within an addX method where it is
   69.94 -     * resized (see doubleCapacity) immediately upon becoming full,
   69.95 -     * thus avoiding head and tail wrapping around to equal each
   69.96 -     * other.  We also guarantee that all array cells not holding
   69.97 -     * deque elements are always null.
   69.98 -     */
   69.99 -    private transient E[] elements;
  69.100 -
  69.101 -    /**
  69.102 -     * The index of the element at the head of the deque (which is the
  69.103 -     * element that would be removed by remove() or pop()); or an
  69.104 -     * arbitrary number equal to tail if the deque is empty.
  69.105 -     */
  69.106 -    private transient int head;
  69.107 -
  69.108 -    /**
  69.109 -     * The index at which the next element would be added to the tail
  69.110 -     * of the deque (via addLast(E), add(E), or push(E)).
  69.111 -     */
  69.112 -    private transient int tail;
  69.113 -
  69.114 -    /**
  69.115 -     * The minimum capacity that we'll use for a newly created deque.
  69.116 -     * Must be a power of 2.
  69.117 -     */
  69.118 -    private static final int MIN_INITIAL_CAPACITY = 8;
  69.119 -
  69.120 -    // ******  Array allocation and resizing utilities ******
  69.121 -
  69.122 -    /**
  69.123 -     * Allocate empty array to hold the given number of elements.
  69.124 -     *
  69.125 -     * @param numElements  the number of elements to hold
  69.126 -     */
  69.127 -    private void allocateElements(int numElements) {
  69.128 -        int initialCapacity = MIN_INITIAL_CAPACITY;
  69.129 -        // Find the best power of two to hold elements.
  69.130 -        // Tests "<=" because arrays aren't kept full.
  69.131 -        if (numElements >= initialCapacity) {
  69.132 -            initialCapacity = numElements;
  69.133 -            initialCapacity |= (initialCapacity >>>  1);
  69.134 -            initialCapacity |= (initialCapacity >>>  2);
  69.135 -            initialCapacity |= (initialCapacity >>>  4);
  69.136 -            initialCapacity |= (initialCapacity >>>  8);
  69.137 -            initialCapacity |= (initialCapacity >>> 16);
  69.138 -            initialCapacity++;
  69.139 -
  69.140 -            if (initialCapacity < 0)   // Too many elements, must back off
  69.141 -                initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
  69.142 -        }
  69.143 -        elements = (E[]) new Object[initialCapacity];
  69.144 -    }
  69.145 -
  69.146 -    /**
  69.147 -     * Double the capacity of this deque.  Call only when full, i.e.,
  69.148 -     * when head and tail have wrapped around to become equal.
  69.149 -     */
  69.150 -    private void doubleCapacity() {
  69.151 -        assert head == tail;
  69.152 -        int p = head;
  69.153 -        int n = elements.length;
  69.154 -        int r = n - p; // number of elements to the right of p
  69.155 -        int newCapacity = n << 1;
  69.156 -        if (newCapacity < 0)
  69.157 -            throw new IllegalStateException("Sorry, deque too big");
  69.158 -        Object[] a = new Object[newCapacity];
  69.159 -        System.arraycopy(elements, p, a, 0, r);
  69.160 -        System.arraycopy(elements, 0, a, r, p);
  69.161 -        elements = (E[])a;
  69.162 -        head = 0;
  69.163 -        tail = n;
  69.164 -    }
  69.165 -
  69.166 -    /**
  69.167 -     * Copies the elements from our element array into the specified array,
  69.168 -     * in order (from first to last element in the deque).  It is assumed
  69.169 -     * that the array is large enough to hold all elements in the deque.
  69.170 -     *
  69.171 -     * @return its argument
  69.172 -     */
  69.173 -    private <T> T[] copyElements(T[] a) {
  69.174 -        if (head < tail) {
  69.175 -            System.arraycopy(elements, head, a, 0, size());
  69.176 -        } else if (head > tail) {
  69.177 -            int headPortionLen = elements.length - head;
  69.178 -            System.arraycopy(elements, head, a, 0, headPortionLen);
  69.179 -            System.arraycopy(elements, 0, a, headPortionLen, tail);
  69.180 -        }
  69.181 -        return a;
  69.182 -    }
  69.183 -
  69.184 -    /**
  69.185 -     * Constructs an empty array deque with an initial capacity
  69.186 -     * sufficient to hold 16 elements.
  69.187 -     */
  69.188 -    public ArrayDeque() {
  69.189 -        elements = (E[]) new Object[16];
  69.190 -    }
  69.191 -
  69.192 -    /**
  69.193 -     * Constructs an empty array deque with an initial capacity
  69.194 -     * sufficient to hold the specified number of elements.
  69.195 -     *
  69.196 -     * @param numElements  lower bound on initial capacity of the deque
  69.197 -     */
  69.198 -    public ArrayDeque(int numElements) {
  69.199 -        allocateElements(numElements);
  69.200 -    }
  69.201 -
  69.202 -    /**
  69.203 -     * Constructs a deque containing the elements of the specified
  69.204 -     * collection, in the order they are returned by the collection's
  69.205 -     * iterator.  (The first element returned by the collection's
  69.206 -     * iterator becomes the first element, or <i>front</i> of the
  69.207 -     * deque.)
  69.208 -     *
  69.209 -     * @param c the collection whose elements are to be placed into the deque
  69.210 -     * @throws NullPointerException if the specified collection is null
  69.211 -     */
  69.212 -    public ArrayDeque(Collection<? extends E> c) {
  69.213 -        allocateElements(c.size());
  69.214 -        addAll(c);
  69.215 -    }
  69.216 -
  69.217 -    // The main insertion and extraction methods are addFirst,
  69.218 -    // addLast, pollFirst, pollLast. The other methods are defined in
  69.219 -    // terms of these.
  69.220 -
  69.221 -    /**
  69.222 -     * Inserts the specified element at the front of this deque.
  69.223 -     *
  69.224 -     * @param e the element to add
  69.225 -     * @throws NullPointerException if the specified element is null
  69.226 -     */
  69.227 -    public void addFirst(E e) {
  69.228 -        if (e == null)
  69.229 -            throw new NullPointerException();
  69.230 -        elements[head = (head - 1) & (elements.length - 1)] = e;
  69.231 -        if (head == tail)
  69.232 -            doubleCapacity();
  69.233 -    }
  69.234 -
  69.235 -    /**
  69.236 -     * Inserts the specified element at the end of this deque.
  69.237 -     *
  69.238 -     * <p>This method is equivalent to {@link #add}.
  69.239 -     *
  69.240 -     * @param e the element to add
  69.241 -     * @throws NullPointerException if the specified element is null
  69.242 -     */
  69.243 -    public void addLast(E e) {
  69.244 -        if (e == null)
  69.245 -            throw new NullPointerException();
  69.246 -        elements[tail] = e;
  69.247 -        if ( (tail = (tail + 1) & (elements.length - 1)) == head)
  69.248 -            doubleCapacity();
  69.249 -    }
  69.250 -
  69.251 -    /**
  69.252 -     * Inserts the specified element at the front of this deque.
  69.253 -     *
  69.254 -     * @param e the element to add
  69.255 -     * @return <tt>true</tt> (as specified by {@link Deque#offerFirst})
  69.256 -     * @throws NullPointerException if the specified element is null
  69.257 -     */
  69.258 -    public boolean offerFirst(E e) {
  69.259 -        addFirst(e);
  69.260 -        return true;
  69.261 -    }
  69.262 -
  69.263 -    /**
  69.264 -     * Inserts the specified element at the end of this deque.
  69.265 -     *
  69.266 -     * @param e the element to add
  69.267 -     * @return <tt>true</tt> (as specified by {@link Deque#offerLast})
  69.268 -     * @throws NullPointerException if the specified element is null
  69.269 -     */
  69.270 -    public boolean offerLast(E e) {
  69.271 -        addLast(e);
  69.272 -        return true;
  69.273 -    }
  69.274 -
  69.275 -    /**
  69.276 -     * @throws NoSuchElementException {@inheritDoc}
  69.277 -     */
  69.278 -    public E removeFirst() {
  69.279 -        E x = pollFirst();
  69.280 -        if (x == null)
  69.281 -            throw new NoSuchElementException();
  69.282 -        return x;
  69.283 -    }
  69.284 -
  69.285 -    /**
  69.286 -     * @throws NoSuchElementException {@inheritDoc}
  69.287 -     */
  69.288 -    public E removeLast() {
  69.289 -        E x = pollLast();
  69.290 -        if (x == null)
  69.291 -            throw new NoSuchElementException();
  69.292 -        return x;
  69.293 -    }
  69.294 -
  69.295 -    public E pollFirst() {
  69.296 -        int h = head;
  69.297 -        E result = elements[h]; // Element is null if deque empty
  69.298 -        if (result == null)
  69.299 -            return null;
  69.300 -        elements[h] = null;     // Must null out slot
  69.301 -        head = (h + 1) & (elements.length - 1);
  69.302 -        return result;
  69.303 -    }
  69.304 -
  69.305 -    public E pollLast() {
  69.306 -        int t = (tail - 1) & (elements.length - 1);
  69.307 -        E result = elements[t];
  69.308 -        if (result == null)
  69.309 -            return null;
  69.310 -        elements[t] = null;
  69.311 -        tail = t;
  69.312 -        return result;
  69.313 -    }
  69.314 -
  69.315 -    /**
  69.316 -     * @throws NoSuchElementException {@inheritDoc}
  69.317 -     */
  69.318 -    public E getFirst() {
  69.319 -        E x = elements[head];
  69.320 -        if (x == null)
  69.321 -            throw new NoSuchElementException();
  69.322 -        return x;
  69.323 -    }
  69.324 -
  69.325 -    /**
  69.326 -     * @throws NoSuchElementException {@inheritDoc}
  69.327 -     */
  69.328 -    public E getLast() {
  69.329 -        E x = elements[(tail - 1) & (elements.length - 1)];
  69.330 -        if (x == null)
  69.331 -            throw new NoSuchElementException();
  69.332 -        return x;
  69.333 -    }
  69.334 -
  69.335 -    public E peekFirst() {
  69.336 -        return elements[head]; // elements[head] is null if deque empty
  69.337 -    }
  69.338 -
  69.339 -    public E peekLast() {
  69.340 -        return elements[(tail - 1) & (elements.length - 1)];
  69.341 -    }
  69.342 -
  69.343 -    /**
  69.344 -     * Removes the first occurrence of the specified element in this
  69.345 -     * deque (when traversing the deque from head to tail).
  69.346 -     * If the deque does not contain the element, it is unchanged.
  69.347 -     * More formally, removes the first element <tt>e</tt> such that
  69.348 -     * <tt>o.equals(e)</tt> (if such an element exists).
  69.349 -     * Returns <tt>true</tt> if this deque contained the specified element
  69.350 -     * (or equivalently, if this deque changed as a result of the call).
  69.351 -     *
  69.352 -     * @param o element to be removed from this deque, if present
  69.353 -     * @return <tt>true</tt> if the deque contained the specified element
  69.354 -     */
  69.355 -    public boolean removeFirstOccurrence(Object o) {
  69.356 -        if (o == null)
  69.357 -            return false;
  69.358 -        int mask = elements.length - 1;
  69.359 -        int i = head;
  69.360 -        E x;
  69.361 -        while ( (x = elements[i]) != null) {
  69.362 -            if (o.equals(x)) {
  69.363 -                delete(i);
  69.364 -                return true;
  69.365 -            }
  69.366 -            i = (i + 1) & mask;
  69.367 -        }
  69.368 -        return false;
  69.369 -    }
  69.370 -
  69.371 -    /**
  69.372 -     * Removes the last occurrence of the specified element in this
  69.373 -     * deque (when traversing the deque from head to tail).
  69.374 -     * If the deque does not contain the element, it is unchanged.
  69.375 -     * More formally, removes the last element <tt>e</tt> such that
  69.376 -     * <tt>o.equals(e)</tt> (if such an element exists).
  69.377 -     * Returns <tt>true</tt> if this deque contained the specified element
  69.378 -     * (or equivalently, if this deque changed as a result of the call).
  69.379 -     *
  69.380 -     * @param o element to be removed from this deque, if present
  69.381 -     * @return <tt>true</tt> if the deque contained the specified element
  69.382 -     */
  69.383 -    public boolean removeLastOccurrence(Object o) {
  69.384 -        if (o == null)
  69.385 -            return false;
  69.386 -        int mask = elements.length - 1;
  69.387 -        int i = (tail - 1) & mask;
  69.388 -        E x;
  69.389 -        while ( (x = elements[i]) != null) {
  69.390 -            if (o.equals(x)) {
  69.391 -                delete(i);
  69.392 -                return true;
  69.393 -            }
  69.394 -            i = (i - 1) & mask;
  69.395 -        }
  69.396 -        return false;
  69.397 -    }
  69.398 -
  69.399 -    // *** Queue methods ***
  69.400 -
  69.401 -    /**
  69.402 -     * Inserts the specified element at the end of this deque.
  69.403 -     *
  69.404 -     * <p>This method is equivalent to {@link #addLast}.
  69.405 -     *
  69.406 -     * @param e the element to add
  69.407 -     * @return <tt>true</tt> (as specified by {@link Collection#add})
  69.408 -     * @throws NullPointerException if the specified element is null
  69.409 -     */
  69.410 -    public boolean add(E e) {
  69.411 -        addLast(e);
  69.412 -        return true;
  69.413 -    }
  69.414 -
  69.415 -    /**
  69.416 -     * Inserts the specified element at the end of this deque.
  69.417 -     *
  69.418 -     * <p>This method is equivalent to {@link #offerLast}.
  69.419 -     *
  69.420 -     * @param e the element to add
  69.421 -     * @return <tt>true</tt> (as specified by {@link Queue#offer})
  69.422 -     * @throws NullPointerException if the specified element is null
  69.423 -     */
  69.424 -    public boolean offer(E e) {
  69.425 -        return offerLast(e);
  69.426 -    }
  69.427 -
  69.428 -    /**
  69.429 -     * Retrieves and removes the head of the queue represented by this deque.
  69.430 -     *
  69.431 -     * This method differs from {@link #poll poll} only in that it throws an
  69.432 -     * exception if this deque is empty.
  69.433 -     *
  69.434 -     * <p>This method is equivalent to {@link #removeFirst}.
  69.435 -     *
  69.436 -     * @return the head of the queue represented by this deque
  69.437 -     * @throws NoSuchElementException {@inheritDoc}
  69.438 -     */
  69.439 -    public E remove() {
  69.440 -        return removeFirst();
  69.441 -    }
  69.442 -
  69.443 -    /**
  69.444 -     * Retrieves and removes the head of the queue represented by this deque
  69.445 -     * (in other words, the first element of this deque), or returns
  69.446 -     * <tt>null</tt> if this deque is empty.
  69.447 -     *
  69.448 -     * <p>This method is equivalent to {@link #pollFirst}.
  69.449 -     *
  69.450 -     * @return the head of the queue represented by this deque, or
  69.451 -     *         <tt>null</tt> if this deque is empty
  69.452 -     */
  69.453 -    public E poll() {
  69.454 -        return pollFirst();
  69.455 -    }
  69.456 -
  69.457 -    /**
  69.458 -     * Retrieves, but does not remove, the head of the queue represented by
  69.459 -     * this deque.  This method differs from {@link #peek peek} only in
  69.460 -     * that it throws an exception if this deque is empty.
  69.461 -     *
  69.462 -     * <p>This method is equivalent to {@link #getFirst}.
  69.463 -     *
  69.464 -     * @return the head of the queue represented by this deque
  69.465 -     * @throws NoSuchElementException {@inheritDoc}
  69.466 -     */
  69.467 -    public E element() {
  69.468 -        return getFirst();
  69.469 -    }
  69.470 -
  69.471 -    /**
  69.472 -     * Retrieves, but does not remove, the head of the queue represented by
  69.473 -     * this deque, or returns <tt>null</tt> if this deque is empty.
  69.474 -     *
  69.475 -     * <p>This method is equivalent to {@link #peekFirst}.
  69.476 -     *
  69.477 -     * @return the head of the queue represented by this deque, or
  69.478 -     *         <tt>null</tt> if this deque is empty
  69.479 -     */
  69.480 -    public E peek() {
  69.481 -        return peekFirst();
  69.482 -    }
  69.483 -
  69.484 -    // *** Stack methods ***
  69.485 -
  69.486 -    /**
  69.487 -     * Pushes an element onto the stack represented by this deque.  In other
  69.488 -     * words, inserts the element at the front of this deque.
  69.489 -     *
  69.490 -     * <p>This method is equivalent to {@link #addFirst}.
  69.491 -     *
  69.492 -     * @param e the element to push
  69.493 -     * @throws NullPointerException if the specified element is null
  69.494 -     */
  69.495 -    public void push(E e) {
  69.496 -        addFirst(e);
  69.497 -    }
  69.498 -
  69.499 -    /**
  69.500 -     * Pops an element from the stack represented by this deque.  In other
  69.501 -     * words, removes and returns the first element of this deque.
  69.502 -     *
  69.503 -     * <p>This method is equivalent to {@link #removeFirst()}.
  69.504 -     *
  69.505 -     * @return the element at the front of this deque (which is the top
  69.506 -     *         of the stack represented by this deque)
  69.507 -     * @throws NoSuchElementException {@inheritDoc}
  69.508 -     */
  69.509 -    public E pop() {
  69.510 -        return removeFirst();
  69.511 -    }
  69.512 -
  69.513 -    private void checkInvariants() {
  69.514 -        assert elements[tail] == null;
  69.515 -        assert head == tail ? elements[head] == null :
  69.516 -            (elements[head] != null &&
  69.517 -             elements[(tail - 1) & (elements.length - 1)] != null);
  69.518 -        assert elements[(head - 1) & (elements.length - 1)] == null;
  69.519 -    }
  69.520 -
  69.521 -    /**
  69.522 -     * Removes the element at the specified position in the elements array,
  69.523 -     * adjusting head and tail as necessary.  This can result in motion of
  69.524 -     * elements backwards or forwards in the array.
  69.525 -     *
  69.526 -     * <p>This method is called delete rather than remove to emphasize
  69.527 -     * that its semantics differ from those of {@link List#remove(int)}.
  69.528 -     *
  69.529 -     * @return true if elements moved backwards
  69.530 -     */
  69.531 -    private boolean delete(int i) {
  69.532 -        checkInvariants();
  69.533 -        final E[] elements = this.elements;
  69.534 -        final int mask = elements.length - 1;
  69.535 -        final int h = head;
  69.536 -        final int t = tail;
  69.537 -        final int front = (i - h) & mask;
  69.538 -        final int back  = (t - i) & mask;
  69.539 -
  69.540 -        // Invariant: head <= i < tail mod circularity
  69.541 -        if (front >= ((t - h) & mask))
  69.542 -            throw new ConcurrentModificationException();
  69.543 -
  69.544 -        // Optimize for least element motion
  69.545 -        if (front < back) {
  69.546 -            if (h <= i) {
  69.547 -                System.arraycopy(elements, h, elements, h + 1, front);
  69.548 -            } else { // Wrap around
  69.549 -                System.arraycopy(elements, 0, elements, 1, i);
  69.550 -                elements[0] = elements[mask];
  69.551 -                System.arraycopy(elements, h, elements, h + 1, mask - h);
  69.552 -            }
  69.553 -            elements[h] = null;
  69.554 -            head = (h + 1) & mask;
  69.555 -            return false;
  69.556 -        } else {
  69.557 -            if (i < t) { // Copy the null tail as well
  69.558 -                System.arraycopy(elements, i + 1, elements, i, back);
  69.559 -                tail = t - 1;
  69.560 -            } else { // Wrap around
  69.561 -                System.arraycopy(elements, i + 1, elements, i, mask - i);
  69.562 -                elements[mask] = elements[0];
  69.563 -                System.arraycopy(elements, 1, elements, 0, t);
  69.564 -                tail = (t - 1) & mask;
  69.565 -            }
  69.566 -            return true;
  69.567 -        }
  69.568 -    }
  69.569 -
  69.570 -    // *** Collection Methods ***
  69.571 -
  69.572 -    /**
  69.573 -     * Returns the number of elements in this deque.
  69.574 -     *
  69.575 -     * @return the number of elements in this deque
  69.576 -     */
  69.577 -    public int size() {
  69.578 -        return (tail - head) & (elements.length - 1);
  69.579 -    }
  69.580 -
  69.581 -    /**
  69.582 -     * Returns <tt>true</tt> if this deque contains no elements.
  69.583 -     *
  69.584 -     * @return <tt>true</tt> if this deque contains no elements
  69.585 -     */
  69.586 -    public boolean isEmpty() {
  69.587 -        return head == tail;
  69.588 -    }
  69.589 -
  69.590 -    /**
  69.591 -     * Returns an iterator over the elements in this deque.  The elements
  69.592 -     * will be ordered from first (head) to last (tail).  This is the same
  69.593 -     * order that elements would be dequeued (via successive calls to
  69.594 -     * {@link #remove} or popped (via successive calls to {@link #pop}).
  69.595 -     *
  69.596 -     * @return an iterator over the elements in this deque
  69.597 -     */
  69.598 -    public Iterator<E> iterator() {
  69.599 -        return new DeqIterator();
  69.600 -    }
  69.601 -
  69.602 -    public Iterator<E> descendingIterator() {
  69.603 -        return new DescendingIterator();
  69.604 -    }
  69.605 -
  69.606 -    private class DeqIterator implements Iterator<E> {
  69.607 -        /**
  69.608 -         * Index of element to be returned by subsequent call to next.
  69.609 -         */
  69.610 -        private int cursor = head;
  69.611 -
  69.612 -        /**
  69.613 -         * Tail recorded at construction (also in remove), to stop
  69.614 -         * iterator and also to check for comodification.
  69.615 -         */
  69.616 -        private int fence = tail;
  69.617 -
  69.618 -        /**
  69.619 -         * Index of element returned by most recent call to next.
  69.620 -         * Reset to -1 if element is deleted by a call to remove.
  69.621 -         */
  69.622 -        private int lastRet = -1;
  69.623 -
  69.624 -        public boolean hasNext() {
  69.625 -            return cursor != fence;
  69.626 -        }
  69.627 -
  69.628 -        public E next() {
  69.629 -            if (cursor == fence)
  69.630 -                throw new NoSuchElementException();
  69.631 -            E result = elements[cursor];
  69.632 -            // This check doesn't catch all possible comodifications,
  69.633 -            // but does catch the ones that corrupt traversal
  69.634 -            if (tail != fence || result == null)
  69.635 -                throw new ConcurrentModificationException();
  69.636 -            lastRet = cursor;
  69.637 -            cursor = (cursor + 1) & (elements.length - 1);
  69.638 -            return result;
  69.639 -        }
  69.640 -
  69.641 -        public void remove() {
  69.642 -            if (lastRet < 0)
  69.643 -                throw new IllegalStateException();
  69.644 -            if (delete(lastRet)) { // if left-shifted, undo increment in next()
  69.645 -                cursor = (cursor - 1) & (elements.length - 1);
  69.646 -                fence = tail;
  69.647 -            }
  69.648 -            lastRet = -1;
  69.649 -        }
  69.650 -    }
  69.651 -
  69.652 -    private class DescendingIterator implements Iterator<E> {
  69.653 -        /*
  69.654 -         * This class is nearly a mirror-image of DeqIterator, using
  69.655 -         * tail instead of head for initial cursor, and head instead of
  69.656 -         * tail for fence.
  69.657 -         */
  69.658 -        private int cursor = tail;
  69.659 -        private int fence = head;
  69.660 -        private int lastRet = -1;
  69.661 -
  69.662 -        public boolean hasNext() {
  69.663 -            return cursor != fence;
  69.664 -        }
  69.665 -
  69.666 -        public E next() {
  69.667 -            if (cursor == fence)
  69.668 -                throw new NoSuchElementException();
  69.669 -            cursor = (cursor - 1) & (elements.length - 1);
  69.670 -            E result = elements[cursor];
  69.671 -            if (head != fence || result == null)
  69.672 -                throw new ConcurrentModificationException();
  69.673 -            lastRet = cursor;
  69.674 -            return result;
  69.675 -        }
  69.676 -
  69.677 -        public void remove() {
  69.678 -            if (lastRet < 0)
  69.679 -                throw new IllegalStateException();
  69.680 -            if (!delete(lastRet)) {
  69.681 -                cursor = (cursor + 1) & (elements.length - 1);
  69.682 -                fence = head;
  69.683 -            }
  69.684 -            lastRet = -1;
  69.685 -        }
  69.686 -    }
  69.687 -
  69.688 -    /**
  69.689 -     * Returns <tt>true</tt> if this deque contains the specified element.
  69.690 -     * More formally, returns <tt>true</tt> if and only if this deque contains
  69.691 -     * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
  69.692 -     *
  69.693 -     * @param o object to be checked for containment in this deque
  69.694 -     * @return <tt>true</tt> if this deque contains the specified element
  69.695 -     */
  69.696 -    public boolean contains(Object o) {
  69.697 -        if (o == null)
  69.698 -            return false;
  69.699 -        int mask = elements.length - 1;
  69.700 -        int i = head;
  69.701 -        E x;
  69.702 -        while ( (x = elements[i]) != null) {
  69.703 -            if (o.equals(x))
  69.704 -                return true;
  69.705 -            i = (i + 1) & mask;
  69.706 -        }
  69.707 -        return false;
  69.708 -    }
  69.709 -
  69.710 -    /**
  69.711 -     * Removes a single instance of the specified element from this deque.
  69.712 -     * If the deque does not contain the element, it is unchanged.
  69.713 -     * More formally, removes the first element <tt>e</tt> such that
  69.714 -     * <tt>o.equals(e)</tt> (if such an element exists).
  69.715 -     * Returns <tt>true</tt> if this deque contained the specified element
  69.716 -     * (or equivalently, if this deque changed as a result of the call).
  69.717 -     *
  69.718 -     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
  69.719 -     *
  69.720 -     * @param o element to be removed from this deque, if present
  69.721 -     * @return <tt>true</tt> if this deque contained the specified element
  69.722 -     */
  69.723 -    public boolean remove(Object o) {
  69.724 -        return removeFirstOccurrence(o);
  69.725 -    }
  69.726 -
  69.727 -    /**
  69.728 -     * Removes all of the elements from this deque.
  69.729 -     * The deque will be empty after this call returns.
  69.730 -     */
  69.731 -    public void clear() {
  69.732 -        int h = head;
  69.733 -        int t = tail;
  69.734 -        if (h != t) { // clear all cells
  69.735 -            head = tail = 0;
  69.736 -            int i = h;
  69.737 -            int mask = elements.length - 1;
  69.738 -            do {
  69.739 -                elements[i] = null;
  69.740 -                i = (i + 1) & mask;
  69.741 -            } while (i != t);
  69.742 -        }
  69.743 -    }
  69.744 -
  69.745 -    /**
  69.746 -     * Returns an array containing all of the elements in this deque
  69.747 -     * in proper sequence (from first to last element).
  69.748 -     *
  69.749 -     * <p>The returned array will be "safe" in that no references to it are
  69.750 -     * maintained by this deque.  (In other words, this method must allocate
  69.751 -     * a new array).  The caller is thus free to modify the returned array.
  69.752 -     *
  69.753 -     * <p>This method acts as bridge between array-based and collection-based
  69.754 -     * APIs.
  69.755 -     *
  69.756 -     * @return an array containing all of the elements in this deque
  69.757 -     */
  69.758 -    public Object[] toArray() {
  69.759 -        return copyElements(new Object[size()]);
  69.760 -    }
  69.761 -
  69.762 -    /**
  69.763 -     * Returns an array containing all of the elements in this deque in
  69.764 -     * proper sequence (from first to last element); the runtime type of the
  69.765 -     * returned array is that of the specified array.  If the deque fits in
  69.766 -     * the specified array, it is returned therein.  Otherwise, a new array
  69.767 -     * is allocated with the runtime type of the specified array and the
  69.768 -     * size of this deque.
  69.769 -     *
  69.770 -     * <p>If this deque fits in the specified array with room to spare
  69.771 -     * (i.e., the array has more elements than this deque), the element in
  69.772 -     * the array immediately following the end of the deque is set to
  69.773 -     * <tt>null</tt>.
  69.774 -     *
  69.775 -     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  69.776 -     * array-based and collection-based APIs.  Further, this method allows
  69.777 -     * precise control over the runtime type of the output array, and may,
  69.778 -     * under certain circumstances, be used to save allocation costs.
  69.779 -     *
  69.780 -     * <p>Suppose <tt>x</tt> is a deque known to contain only strings.
  69.781 -     * The following code can be used to dump the deque into a newly
  69.782 -     * allocated array of <tt>String</tt>:
  69.783 -     *
  69.784 -     * <pre>
  69.785 -     *     String[] y = x.toArray(new String[0]);</pre>
  69.786 -     *
  69.787 -     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  69.788 -     * <tt>toArray()</tt>.
  69.789 -     *
  69.790 -     * @param a the array into which the elements of the deque are to
  69.791 -     *          be stored, if it is big enough; otherwise, a new array of the
  69.792 -     *          same runtime type is allocated for this purpose
  69.793 -     * @return an array containing all of the elements in this deque
  69.794 -     * @throws ArrayStoreException if the runtime type of the specified array
  69.795 -     *         is not a supertype of the runtime type of every element in
  69.796 -     *         this deque
  69.797 -     * @throws NullPointerException if the specified array is null
  69.798 -     */
  69.799 -    public <T> T[] toArray(T[] a) {
  69.800 -        int size = size();
  69.801 -        if (a.length < size)
  69.802 -            a = (T[])java.lang.reflect.Array.newInstance(
  69.803 -                    a.getClass().getComponentType(), size);
  69.804 -        copyElements(a);
  69.805 -        if (a.length > size)
  69.806 -            a[size] = null;
  69.807 -        return a;
  69.808 -    }
  69.809 -
  69.810 -    // *** Object methods ***
  69.811 -
  69.812 -    /**
  69.813 -     * Returns a copy of this deque.
  69.814 -     *
  69.815 -     * @return a copy of this deque
  69.816 -     */
  69.817 -    public ArrayDeque<E> clone() {
  69.818 -        try {
  69.819 -            ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
  69.820 -            result.elements = Arrays.copyOf(elements, elements.length);
  69.821 -            return result;
  69.822 -
  69.823 -        } catch (CloneNotSupportedException e) {
  69.824 -            throw new AssertionError();
  69.825 -        }
  69.826 -    }
  69.827 -
  69.828 -    /**
  69.829 -     * Appease the serialization gods.
  69.830 -     */
  69.831 -    private static final long serialVersionUID = 2340985798034038923L;
  69.832 -
  69.833 -}
    70.1 --- a/emul/compact/src/main/java/java/util/ArrayList.java	Mon Feb 25 19:00:08 2013 +0100
    70.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.3 @@ -1,1088 +0,0 @@
    70.4 -/*
    70.5 - * Copyright (c) 1997, 2010, 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 -/**
   70.33 - * Resizable-array implementation of the <tt>List</tt> interface.  Implements
   70.34 - * all optional list operations, and permits all elements, including
   70.35 - * <tt>null</tt>.  In addition to implementing the <tt>List</tt> interface,
   70.36 - * this class provides methods to manipulate the size of the array that is
   70.37 - * used internally to store the list.  (This class is roughly equivalent to
   70.38 - * <tt>Vector</tt>, except that it is unsynchronized.)
   70.39 - *
   70.40 - * <p>The <tt>size</tt>, <tt>isEmpty</tt>, <tt>get</tt>, <tt>set</tt>,
   70.41 - * <tt>iterator</tt>, and <tt>listIterator</tt> operations run in constant
   70.42 - * time.  The <tt>add</tt> operation runs in <i>amortized constant time</i>,
   70.43 - * that is, adding n elements requires O(n) time.  All of the other operations
   70.44 - * run in linear time (roughly speaking).  The constant factor is low compared
   70.45 - * to that for the <tt>LinkedList</tt> implementation.
   70.46 - *
   70.47 - * <p>Each <tt>ArrayList</tt> instance has a <i>capacity</i>.  The capacity is
   70.48 - * the size of the array used to store the elements in the list.  It is always
   70.49 - * at least as large as the list size.  As elements are added to an ArrayList,
   70.50 - * its capacity grows automatically.  The details of the growth policy are not
   70.51 - * specified beyond the fact that adding an element has constant amortized
   70.52 - * time cost.
   70.53 - *
   70.54 - * <p>An application can increase the capacity of an <tt>ArrayList</tt> instance
   70.55 - * before adding a large number of elements using the <tt>ensureCapacity</tt>
   70.56 - * operation.  This may reduce the amount of incremental reallocation.
   70.57 - *
   70.58 - * <p><strong>Note that this implementation is not synchronized.</strong>
   70.59 - * If multiple threads access an <tt>ArrayList</tt> instance concurrently,
   70.60 - * and at least one of the threads modifies the list structurally, it
   70.61 - * <i>must</i> be synchronized externally.  (A structural modification is
   70.62 - * any operation that adds or deletes one or more elements, or explicitly
   70.63 - * resizes the backing array; merely setting the value of an element is not
   70.64 - * a structural modification.)  This is typically accomplished by
   70.65 - * synchronizing on some object that naturally encapsulates the list.
   70.66 - *
   70.67 - * If no such object exists, the list should be "wrapped" using the
   70.68 - * {@link Collections#synchronizedList Collections.synchronizedList}
   70.69 - * method.  This is best done at creation time, to prevent accidental
   70.70 - * unsynchronized access to the list:<pre>
   70.71 - *   List list = Collections.synchronizedList(new ArrayList(...));</pre>
   70.72 - *
   70.73 - * <p><a name="fail-fast"/>
   70.74 - * The iterators returned by this class's {@link #iterator() iterator} and
   70.75 - * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
   70.76 - * if the list is structurally modified at any time after the iterator is
   70.77 - * created, in any way except through the iterator's own
   70.78 - * {@link ListIterator#remove() remove} or
   70.79 - * {@link ListIterator#add(Object) add} methods, the iterator will throw a
   70.80 - * {@link ConcurrentModificationException}.  Thus, in the face of
   70.81 - * concurrent modification, the iterator fails quickly and cleanly, rather
   70.82 - * than risking arbitrary, non-deterministic behavior at an undetermined
   70.83 - * time in the future.
   70.84 - *
   70.85 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   70.86 - * as it is, generally speaking, impossible to make any hard guarantees in the
   70.87 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
   70.88 - * throw {@code ConcurrentModificationException} on a best-effort basis.
   70.89 - * Therefore, it would be wrong to write a program that depended on this
   70.90 - * exception for its correctness:  <i>the fail-fast behavior of iterators
   70.91 - * should be used only to detect bugs.</i>
   70.92 - *
   70.93 - * <p>This class is a member of the
   70.94 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   70.95 - * Java Collections Framework</a>.
   70.96 - *
   70.97 - * @author  Josh Bloch
   70.98 - * @author  Neal Gafter
   70.99 - * @see     Collection
  70.100 - * @see     List
  70.101 - * @see     LinkedList
  70.102 - * @see     Vector
  70.103 - * @since   1.2
  70.104 - */
  70.105 -
  70.106 -public class ArrayList<E> extends AbstractList<E>
  70.107 -        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
  70.108 -{
  70.109 -    private static final long serialVersionUID = 8683452581122892189L;
  70.110 -
  70.111 -    /**
  70.112 -     * The array buffer into which the elements of the ArrayList are stored.
  70.113 -     * The capacity of the ArrayList is the length of this array buffer.
  70.114 -     */
  70.115 -    private transient Object[] elementData;
  70.116 -
  70.117 -    /**
  70.118 -     * The size of the ArrayList (the number of elements it contains).
  70.119 -     *
  70.120 -     * @serial
  70.121 -     */
  70.122 -    private int size;
  70.123 -
  70.124 -    /**
  70.125 -     * Constructs an empty list with the specified initial capacity.
  70.126 -     *
  70.127 -     * @param  initialCapacity  the initial capacity of the list
  70.128 -     * @throws IllegalArgumentException if the specified initial capacity
  70.129 -     *         is negative
  70.130 -     */
  70.131 -    public ArrayList(int initialCapacity) {
  70.132 -        super();
  70.133 -        if (initialCapacity < 0)
  70.134 -            throw new IllegalArgumentException("Illegal Capacity: "+
  70.135 -                                               initialCapacity);
  70.136 -        this.elementData = new Object[initialCapacity];
  70.137 -    }
  70.138 -
  70.139 -    /**
  70.140 -     * Constructs an empty list with an initial capacity of ten.
  70.141 -     */
  70.142 -    public ArrayList() {
  70.143 -        this(10);
  70.144 -    }
  70.145 -
  70.146 -    /**
  70.147 -     * Constructs a list containing the elements of the specified
  70.148 -     * collection, in the order they are returned by the collection's
  70.149 -     * iterator.
  70.150 -     *
  70.151 -     * @param c the collection whose elements are to be placed into this list
  70.152 -     * @throws NullPointerException if the specified collection is null
  70.153 -     */
  70.154 -    public ArrayList(Collection<? extends E> c) {
  70.155 -        elementData = c.toArray();
  70.156 -        size = elementData.length;
  70.157 -        // c.toArray might (incorrectly) not return Object[] (see 6260652)
  70.158 -        if (elementData.getClass() != Object[].class)
  70.159 -            elementData = Arrays.copyOf(elementData, size, Object[].class);
  70.160 -    }
  70.161 -
  70.162 -    /**
  70.163 -     * Trims the capacity of this <tt>ArrayList</tt> instance to be the
  70.164 -     * list's current size.  An application can use this operation to minimize
  70.165 -     * the storage of an <tt>ArrayList</tt> instance.
  70.166 -     */
  70.167 -    public void trimToSize() {
  70.168 -        modCount++;
  70.169 -        int oldCapacity = elementData.length;
  70.170 -        if (size < oldCapacity) {
  70.171 -            elementData = Arrays.copyOf(elementData, size);
  70.172 -        }
  70.173 -    }
  70.174 -
  70.175 -    /**
  70.176 -     * Increases the capacity of this <tt>ArrayList</tt> instance, if
  70.177 -     * necessary, to ensure that it can hold at least the number of elements
  70.178 -     * specified by the minimum capacity argument.
  70.179 -     *
  70.180 -     * @param   minCapacity   the desired minimum capacity
  70.181 -     */
  70.182 -    public void ensureCapacity(int minCapacity) {
  70.183 -        if (minCapacity > 0)
  70.184 -            ensureCapacityInternal(minCapacity);
  70.185 -    }
  70.186 -
  70.187 -    private void ensureCapacityInternal(int minCapacity) {
  70.188 -        modCount++;
  70.189 -        // overflow-conscious code
  70.190 -        if (minCapacity - elementData.length > 0)
  70.191 -            grow(minCapacity);
  70.192 -    }
  70.193 -
  70.194 -    /**
  70.195 -     * The maximum size of array to allocate.
  70.196 -     * Some VMs reserve some header words in an array.
  70.197 -     * Attempts to allocate larger arrays may result in
  70.198 -     * OutOfMemoryError: Requested array size exceeds VM limit
  70.199 -     */
  70.200 -    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  70.201 -
  70.202 -    /**
  70.203 -     * Increases the capacity to ensure that it can hold at least the
  70.204 -     * number of elements specified by the minimum capacity argument.
  70.205 -     *
  70.206 -     * @param minCapacity the desired minimum capacity
  70.207 -     */
  70.208 -    private void grow(int minCapacity) {
  70.209 -        // overflow-conscious code
  70.210 -        int oldCapacity = elementData.length;
  70.211 -        int newCapacity = oldCapacity + (oldCapacity >> 1);
  70.212 -        if (newCapacity - minCapacity < 0)
  70.213 -            newCapacity = minCapacity;
  70.214 -        if (newCapacity - MAX_ARRAY_SIZE > 0)
  70.215 -            newCapacity = hugeCapacity(minCapacity);
  70.216 -        // minCapacity is usually close to size, so this is a win:
  70.217 -        elementData = Arrays.copyOf(elementData, newCapacity);
  70.218 -    }
  70.219 -
  70.220 -    private static int hugeCapacity(int minCapacity) {
  70.221 -        if (minCapacity < 0) // overflow
  70.222 -            throw new OutOfMemoryError();
  70.223 -        return (minCapacity > MAX_ARRAY_SIZE) ?
  70.224 -            Integer.MAX_VALUE :
  70.225 -            MAX_ARRAY_SIZE;
  70.226 -    }
  70.227 -
  70.228 -    /**
  70.229 -     * Returns the number of elements in this list.
  70.230 -     *
  70.231 -     * @return the number of elements in this list
  70.232 -     */
  70.233 -    public int size() {
  70.234 -        return size;
  70.235 -    }
  70.236 -
  70.237 -    /**
  70.238 -     * Returns <tt>true</tt> if this list contains no elements.
  70.239 -     *
  70.240 -     * @return <tt>true</tt> if this list contains no elements
  70.241 -     */
  70.242 -    public boolean isEmpty() {
  70.243 -        return size == 0;
  70.244 -    }
  70.245 -
  70.246 -    /**
  70.247 -     * Returns <tt>true</tt> if this list contains the specified element.
  70.248 -     * More formally, returns <tt>true</tt> if and only if this list contains
  70.249 -     * at least one element <tt>e</tt> such that
  70.250 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  70.251 -     *
  70.252 -     * @param o element whose presence in this list is to be tested
  70.253 -     * @return <tt>true</tt> if this list contains the specified element
  70.254 -     */
  70.255 -    public boolean contains(Object o) {
  70.256 -        return indexOf(o) >= 0;
  70.257 -    }
  70.258 -
  70.259 -    /**
  70.260 -     * Returns the index of the first occurrence of the specified element
  70.261 -     * in this list, or -1 if this list does not contain the element.
  70.262 -     * More formally, returns the lowest index <tt>i</tt> such that
  70.263 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  70.264 -     * or -1 if there is no such index.
  70.265 -     */
  70.266 -    public int indexOf(Object o) {
  70.267 -        if (o == null) {
  70.268 -            for (int i = 0; i < size; i++)
  70.269 -                if (elementData[i]==null)
  70.270 -                    return i;
  70.271 -        } else {
  70.272 -            for (int i = 0; i < size; i++)
  70.273 -                if (o.equals(elementData[i]))
  70.274 -                    return i;
  70.275 -        }
  70.276 -        return -1;
  70.277 -    }
  70.278 -
  70.279 -    /**
  70.280 -     * Returns the index of the last occurrence of the specified element
  70.281 -     * in this list, or -1 if this list does not contain the element.
  70.282 -     * More formally, returns the highest index <tt>i</tt> such that
  70.283 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  70.284 -     * or -1 if there is no such index.
  70.285 -     */
  70.286 -    public int lastIndexOf(Object o) {
  70.287 -        if (o == null) {
  70.288 -            for (int i = size-1; i >= 0; i--)
  70.289 -                if (elementData[i]==null)
  70.290 -                    return i;
  70.291 -        } else {
  70.292 -            for (int i = size-1; i >= 0; i--)
  70.293 -                if (o.equals(elementData[i]))
  70.294 -                    return i;
  70.295 -        }
  70.296 -        return -1;
  70.297 -    }
  70.298 -
  70.299 -    /**
  70.300 -     * Returns a shallow copy of this <tt>ArrayList</tt> instance.  (The
  70.301 -     * elements themselves are not copied.)
  70.302 -     *
  70.303 -     * @return a clone of this <tt>ArrayList</tt> instance
  70.304 -     */
  70.305 -    public Object clone() {
  70.306 -        try {
  70.307 -            @SuppressWarnings("unchecked")
  70.308 -                ArrayList<E> v = (ArrayList<E>) super.clone();
  70.309 -            v.elementData = Arrays.copyOf(elementData, size);
  70.310 -            v.modCount = 0;
  70.311 -            return v;
  70.312 -        } catch (CloneNotSupportedException e) {
  70.313 -            // this shouldn't happen, since we are Cloneable
  70.314 -            throw new InternalError();
  70.315 -        }
  70.316 -    }
  70.317 -
  70.318 -    /**
  70.319 -     * Returns an array containing all of the elements in this list
  70.320 -     * in proper sequence (from first to last element).
  70.321 -     *
  70.322 -     * <p>The returned array will be "safe" in that no references to it are
  70.323 -     * maintained by this list.  (In other words, this method must allocate
  70.324 -     * a new array).  The caller is thus free to modify the returned array.
  70.325 -     *
  70.326 -     * <p>This method acts as bridge between array-based and collection-based
  70.327 -     * APIs.
  70.328 -     *
  70.329 -     * @return an array containing all of the elements in this list in
  70.330 -     *         proper sequence
  70.331 -     */
  70.332 -    public Object[] toArray() {
  70.333 -        return Arrays.copyOf(elementData, size);
  70.334 -    }
  70.335 -
  70.336 -    /**
  70.337 -     * Returns an array containing all of the elements in this list in proper
  70.338 -     * sequence (from first to last element); the runtime type of the returned
  70.339 -     * array is that of the specified array.  If the list fits in the
  70.340 -     * specified array, it is returned therein.  Otherwise, a new array is
  70.341 -     * allocated with the runtime type of the specified array and the size of
  70.342 -     * this list.
  70.343 -     *
  70.344 -     * <p>If the list fits in the specified array with room to spare
  70.345 -     * (i.e., the array has more elements than the list), the element in
  70.346 -     * the array immediately following the end of the collection is set to
  70.347 -     * <tt>null</tt>.  (This is useful in determining the length of the
  70.348 -     * list <i>only</i> if the caller knows that the list does not contain
  70.349 -     * any null elements.)
  70.350 -     *
  70.351 -     * @param a the array into which the elements of the list are to
  70.352 -     *          be stored, if it is big enough; otherwise, a new array of the
  70.353 -     *          same runtime type is allocated for this purpose.
  70.354 -     * @return an array containing the elements of the list
  70.355 -     * @throws ArrayStoreException if the runtime type of the specified array
  70.356 -     *         is not a supertype of the runtime type of every element in
  70.357 -     *         this list
  70.358 -     * @throws NullPointerException if the specified array is null
  70.359 -     */
  70.360 -    @SuppressWarnings("unchecked")
  70.361 -    public <T> T[] toArray(T[] a) {
  70.362 -        if (a.length < size)
  70.363 -            // Make a new array of a's runtime type, but my contents:
  70.364 -            return (T[]) Arrays.copyOf(elementData, size, a.getClass());
  70.365 -        System.arraycopy(elementData, 0, a, 0, size);
  70.366 -        if (a.length > size)
  70.367 -            a[size] = null;
  70.368 -        return a;
  70.369 -    }
  70.370 -
  70.371 -    // Positional Access Operations
  70.372 -
  70.373 -    @SuppressWarnings("unchecked")
  70.374 -    E elementData(int index) {
  70.375 -        return (E) elementData[index];
  70.376 -    }
  70.377 -
  70.378 -    /**
  70.379 -     * Returns the element at the specified position in this list.
  70.380 -     *
  70.381 -     * @param  index index of the element to return
  70.382 -     * @return the element at the specified position in this list
  70.383 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.384 -     */
  70.385 -    public E get(int index) {
  70.386 -        rangeCheck(index);
  70.387 -
  70.388 -        return elementData(index);
  70.389 -    }
  70.390 -
  70.391 -    /**
  70.392 -     * Replaces the element at the specified position in this list with
  70.393 -     * the specified element.
  70.394 -     *
  70.395 -     * @param index index of the element to replace
  70.396 -     * @param element element to be stored at the specified position
  70.397 -     * @return the element previously at the specified position
  70.398 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.399 -     */
  70.400 -    public E set(int index, E element) {
  70.401 -        rangeCheck(index);
  70.402 -
  70.403 -        E oldValue = elementData(index);
  70.404 -        elementData[index] = element;
  70.405 -        return oldValue;
  70.406 -    }
  70.407 -
  70.408 -    /**
  70.409 -     * Appends the specified element to the end of this list.
  70.410 -     *
  70.411 -     * @param e element to be appended to this list
  70.412 -     * @return <tt>true</tt> (as specified by {@link Collection#add})
  70.413 -     */
  70.414 -    public boolean add(E e) {
  70.415 -        ensureCapacityInternal(size + 1);  // Increments modCount!!
  70.416 -        elementData[size++] = e;
  70.417 -        return true;
  70.418 -    }
  70.419 -
  70.420 -    /**
  70.421 -     * Inserts the specified element at the specified position in this
  70.422 -     * list. Shifts the element currently at that position (if any) and
  70.423 -     * any subsequent elements to the right (adds one to their indices).
  70.424 -     *
  70.425 -     * @param index index at which the specified element is to be inserted
  70.426 -     * @param element element to be inserted
  70.427 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.428 -     */
  70.429 -    public void add(int index, E element) {
  70.430 -        rangeCheckForAdd(index);
  70.431 -
  70.432 -        ensureCapacityInternal(size + 1);  // Increments modCount!!
  70.433 -        System.arraycopy(elementData, index, elementData, index + 1,
  70.434 -                         size - index);
  70.435 -        elementData[index] = element;
  70.436 -        size++;
  70.437 -    }
  70.438 -
  70.439 -    /**
  70.440 -     * Removes the element at the specified position in this list.
  70.441 -     * Shifts any subsequent elements to the left (subtracts one from their
  70.442 -     * indices).
  70.443 -     *
  70.444 -     * @param index the index of the element to be removed
  70.445 -     * @return the element that was removed from the list
  70.446 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.447 -     */
  70.448 -    public E remove(int index) {
  70.449 -        rangeCheck(index);
  70.450 -
  70.451 -        modCount++;
  70.452 -        E oldValue = elementData(index);
  70.453 -
  70.454 -        int numMoved = size - index - 1;
  70.455 -        if (numMoved > 0)
  70.456 -            System.arraycopy(elementData, index+1, elementData, index,
  70.457 -                             numMoved);
  70.458 -        elementData[--size] = null; // Let gc do its work
  70.459 -
  70.460 -        return oldValue;
  70.461 -    }
  70.462 -
  70.463 -    /**
  70.464 -     * Removes the first occurrence of the specified element from this list,
  70.465 -     * if it is present.  If the list does not contain the element, it is
  70.466 -     * unchanged.  More formally, removes the element with the lowest index
  70.467 -     * <tt>i</tt> such that
  70.468 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
  70.469 -     * (if such an element exists).  Returns <tt>true</tt> if this list
  70.470 -     * contained the specified element (or equivalently, if this list
  70.471 -     * changed as a result of the call).
  70.472 -     *
  70.473 -     * @param o element to be removed from this list, if present
  70.474 -     * @return <tt>true</tt> if this list contained the specified element
  70.475 -     */
  70.476 -    public boolean remove(Object o) {
  70.477 -        if (o == null) {
  70.478 -            for (int index = 0; index < size; index++)
  70.479 -                if (elementData[index] == null) {
  70.480 -                    fastRemove(index);
  70.481 -                    return true;
  70.482 -                }
  70.483 -        } else {
  70.484 -            for (int index = 0; index < size; index++)
  70.485 -                if (o.equals(elementData[index])) {
  70.486 -                    fastRemove(index);
  70.487 -                    return true;
  70.488 -                }
  70.489 -        }
  70.490 -        return false;
  70.491 -    }
  70.492 -
  70.493 -    /*
  70.494 -     * Private remove method that skips bounds checking and does not
  70.495 -     * return the value removed.
  70.496 -     */
  70.497 -    private void fastRemove(int index) {
  70.498 -        modCount++;
  70.499 -        int numMoved = size - index - 1;
  70.500 -        if (numMoved > 0)
  70.501 -            System.arraycopy(elementData, index+1, elementData, index,
  70.502 -                             numMoved);
  70.503 -        elementData[--size] = null; // Let gc do its work
  70.504 -    }
  70.505 -
  70.506 -    /**
  70.507 -     * Removes all of the elements from this list.  The list will
  70.508 -     * be empty after this call returns.
  70.509 -     */
  70.510 -    public void clear() {
  70.511 -        modCount++;
  70.512 -
  70.513 -        // Let gc do its work
  70.514 -        for (int i = 0; i < size; i++)
  70.515 -            elementData[i] = null;
  70.516 -
  70.517 -        size = 0;
  70.518 -    }
  70.519 -
  70.520 -    /**
  70.521 -     * Appends all of the elements in the specified collection to the end of
  70.522 -     * this list, in the order that they are returned by the
  70.523 -     * specified collection's Iterator.  The behavior of this operation is
  70.524 -     * undefined if the specified collection is modified while the operation
  70.525 -     * is in progress.  (This implies that the behavior of this call is
  70.526 -     * undefined if the specified collection is this list, and this
  70.527 -     * list is nonempty.)
  70.528 -     *
  70.529 -     * @param c collection containing elements to be added to this list
  70.530 -     * @return <tt>true</tt> if this list changed as a result of the call
  70.531 -     * @throws NullPointerException if the specified collection is null
  70.532 -     */
  70.533 -    public boolean addAll(Collection<? extends E> c) {
  70.534 -        Object[] a = c.toArray();
  70.535 -        int numNew = a.length;
  70.536 -        ensureCapacityInternal(size + numNew);  // Increments modCount
  70.537 -        System.arraycopy(a, 0, elementData, size, numNew);
  70.538 -        size += numNew;
  70.539 -        return numNew != 0;
  70.540 -    }
  70.541 -
  70.542 -    /**
  70.543 -     * Inserts all of the elements in the specified collection into this
  70.544 -     * list, starting at the specified position.  Shifts the element
  70.545 -     * currently at that position (if any) and any subsequent elements to
  70.546 -     * the right (increases their indices).  The new elements will appear
  70.547 -     * in the list in the order that they are returned by the
  70.548 -     * specified collection's iterator.
  70.549 -     *
  70.550 -     * @param index index at which to insert the first element from the
  70.551 -     *              specified collection
  70.552 -     * @param c collection containing elements to be added to this list
  70.553 -     * @return <tt>true</tt> if this list changed as a result of the call
  70.554 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.555 -     * @throws NullPointerException if the specified collection is null
  70.556 -     */
  70.557 -    public boolean addAll(int index, Collection<? extends E> c) {
  70.558 -        rangeCheckForAdd(index);
  70.559 -
  70.560 -        Object[] a = c.toArray();
  70.561 -        int numNew = a.length;
  70.562 -        ensureCapacityInternal(size + numNew);  // Increments modCount
  70.563 -
  70.564 -        int numMoved = size - index;
  70.565 -        if (numMoved > 0)
  70.566 -            System.arraycopy(elementData, index, elementData, index + numNew,
  70.567 -                             numMoved);
  70.568 -
  70.569 -        System.arraycopy(a, 0, elementData, index, numNew);
  70.570 -        size += numNew;
  70.571 -        return numNew != 0;
  70.572 -    }
  70.573 -
  70.574 -    /**
  70.575 -     * Removes from this list all of the elements whose index is between
  70.576 -     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
  70.577 -     * Shifts any succeeding elements to the left (reduces their index).
  70.578 -     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
  70.579 -     * (If {@code toIndex==fromIndex}, this operation has no effect.)
  70.580 -     *
  70.581 -     * @throws IndexOutOfBoundsException if {@code fromIndex} or
  70.582 -     *         {@code toIndex} is out of range
  70.583 -     *         ({@code fromIndex < 0 ||
  70.584 -     *          fromIndex >= size() ||
  70.585 -     *          toIndex > size() ||
  70.586 -     *          toIndex < fromIndex})
  70.587 -     */
  70.588 -    protected void removeRange(int fromIndex, int toIndex) {
  70.589 -        modCount++;
  70.590 -        int numMoved = size - toIndex;
  70.591 -        System.arraycopy(elementData, toIndex, elementData, fromIndex,
  70.592 -                         numMoved);
  70.593 -
  70.594 -        // Let gc do its work
  70.595 -        int newSize = size - (toIndex-fromIndex);
  70.596 -        while (size != newSize)
  70.597 -            elementData[--size] = null;
  70.598 -    }
  70.599 -
  70.600 -    /**
  70.601 -     * Checks if the given index is in range.  If not, throws an appropriate
  70.602 -     * runtime exception.  This method does *not* check if the index is
  70.603 -     * negative: It is always used immediately prior to an array access,
  70.604 -     * which throws an ArrayIndexOutOfBoundsException if index is negative.
  70.605 -     */
  70.606 -    private void rangeCheck(int index) {
  70.607 -        if (index >= size)
  70.608 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  70.609 -    }
  70.610 -
  70.611 -    /**
  70.612 -     * A version of rangeCheck used by add and addAll.
  70.613 -     */
  70.614 -    private void rangeCheckForAdd(int index) {
  70.615 -        if (index > size || index < 0)
  70.616 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  70.617 -    }
  70.618 -
  70.619 -    /**
  70.620 -     * Constructs an IndexOutOfBoundsException detail message.
  70.621 -     * Of the many possible refactorings of the error handling code,
  70.622 -     * this "outlining" performs best with both server and client VMs.
  70.623 -     */
  70.624 -    private String outOfBoundsMsg(int index) {
  70.625 -        return "Index: "+index+", Size: "+size;
  70.626 -    }
  70.627 -
  70.628 -    /**
  70.629 -     * Removes from this list all of its elements that are contained in the
  70.630 -     * specified collection.
  70.631 -     *
  70.632 -     * @param c collection containing elements to be removed from this list
  70.633 -     * @return {@code true} if this list changed as a result of the call
  70.634 -     * @throws ClassCastException if the class of an element of this list
  70.635 -     *         is incompatible with the specified collection
  70.636 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  70.637 -     * @throws NullPointerException if this list contains a null element and the
  70.638 -     *         specified collection does not permit null elements
  70.639 -     * (<a href="Collection.html#optional-restrictions">optional</a>),
  70.640 -     *         or if the specified collection is null
  70.641 -     * @see Collection#contains(Object)
  70.642 -     */
  70.643 -    public boolean removeAll(Collection<?> c) {
  70.644 -        return batchRemove(c, false);
  70.645 -    }
  70.646 -
  70.647 -    /**
  70.648 -     * Retains only the elements in this list that are contained in the
  70.649 -     * specified collection.  In other words, removes from this list all
  70.650 -     * of its elements that are not contained in the specified collection.
  70.651 -     *
  70.652 -     * @param c collection containing elements to be retained in this list
  70.653 -     * @return {@code true} if this list changed as a result of the call
  70.654 -     * @throws ClassCastException if the class of an element of this list
  70.655 -     *         is incompatible with the specified collection
  70.656 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  70.657 -     * @throws NullPointerException if this list contains a null element and the
  70.658 -     *         specified collection does not permit null elements
  70.659 -     * (<a href="Collection.html#optional-restrictions">optional</a>),
  70.660 -     *         or if the specified collection is null
  70.661 -     * @see Collection#contains(Object)
  70.662 -     */
  70.663 -    public boolean retainAll(Collection<?> c) {
  70.664 -        return batchRemove(c, true);
  70.665 -    }
  70.666 -
  70.667 -    private boolean batchRemove(Collection<?> c, boolean complement) {
  70.668 -        final Object[] elementData = this.elementData;
  70.669 -        int r = 0, w = 0;
  70.670 -        boolean modified = false;
  70.671 -        try {
  70.672 -            for (; r < size; r++)
  70.673 -                if (c.contains(elementData[r]) == complement)
  70.674 -                    elementData[w++] = elementData[r];
  70.675 -        } finally {
  70.676 -            // Preserve behavioral compatibility with AbstractCollection,
  70.677 -            // even if c.contains() throws.
  70.678 -            if (r != size) {
  70.679 -                System.arraycopy(elementData, r,
  70.680 -                                 elementData, w,
  70.681 -                                 size - r);
  70.682 -                w += size - r;
  70.683 -            }
  70.684 -            if (w != size) {
  70.685 -                for (int i = w; i < size; i++)
  70.686 -                    elementData[i] = null;
  70.687 -                modCount += size - w;
  70.688 -                size = w;
  70.689 -                modified = true;
  70.690 -            }
  70.691 -        }
  70.692 -        return modified;
  70.693 -    }
  70.694 -
  70.695 -    /**
  70.696 -     * Returns a list iterator over the elements in this list (in proper
  70.697 -     * sequence), starting at the specified position in the list.
  70.698 -     * The specified index indicates the first element that would be
  70.699 -     * returned by an initial call to {@link ListIterator#next next}.
  70.700 -     * An initial call to {@link ListIterator#previous previous} would
  70.701 -     * return the element with the specified index minus one.
  70.702 -     *
  70.703 -     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
  70.704 -     *
  70.705 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.706 -     */
  70.707 -    public ListIterator<E> listIterator(int index) {
  70.708 -        if (index < 0 || index > size)
  70.709 -            throw new IndexOutOfBoundsException("Index: "+index);
  70.710 -        return new ListItr(index);
  70.711 -    }
  70.712 -
  70.713 -    /**
  70.714 -     * Returns a list iterator over the elements in this list (in proper
  70.715 -     * sequence).
  70.716 -     *
  70.717 -     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
  70.718 -     *
  70.719 -     * @see #listIterator(int)
  70.720 -     */
  70.721 -    public ListIterator<E> listIterator() {
  70.722 -        return new ListItr(0);
  70.723 -    }
  70.724 -
  70.725 -    /**
  70.726 -     * Returns an iterator over the elements in this list in proper sequence.
  70.727 -     *
  70.728 -     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
  70.729 -     *
  70.730 -     * @return an iterator over the elements in this list in proper sequence
  70.731 -     */
  70.732 -    public Iterator<E> iterator() {
  70.733 -        return new Itr();
  70.734 -    }
  70.735 -
  70.736 -    /**
  70.737 -     * An optimized version of AbstractList.Itr
  70.738 -     */
  70.739 -    private class Itr implements Iterator<E> {
  70.740 -        int cursor;       // index of next element to return
  70.741 -        int lastRet = -1; // index of last element returned; -1 if no such
  70.742 -        int expectedModCount = modCount;
  70.743 -
  70.744 -        public boolean hasNext() {
  70.745 -            return cursor != size;
  70.746 -        }
  70.747 -
  70.748 -        @SuppressWarnings("unchecked")
  70.749 -        public E next() {
  70.750 -            checkForComodification();
  70.751 -            int i = cursor;
  70.752 -            if (i >= size)
  70.753 -                throw new NoSuchElementException();
  70.754 -            Object[] elementData = ArrayList.this.elementData;
  70.755 -            if (i >= elementData.length)
  70.756 -                throw new ConcurrentModificationException();
  70.757 -            cursor = i + 1;
  70.758 -            return (E) elementData[lastRet = i];
  70.759 -        }
  70.760 -
  70.761 -        public void remove() {
  70.762 -            if (lastRet < 0)
  70.763 -                throw new IllegalStateException();
  70.764 -            checkForComodification();
  70.765 -
  70.766 -            try {
  70.767 -                ArrayList.this.remove(lastRet);
  70.768 -                cursor = lastRet;
  70.769 -                lastRet = -1;
  70.770 -                expectedModCount = modCount;
  70.771 -            } catch (IndexOutOfBoundsException ex) {
  70.772 -                throw new ConcurrentModificationException();
  70.773 -            }
  70.774 -        }
  70.775 -
  70.776 -        final void checkForComodification() {
  70.777 -            if (modCount != expectedModCount)
  70.778 -                throw new ConcurrentModificationException();
  70.779 -        }
  70.780 -    }
  70.781 -
  70.782 -    /**
  70.783 -     * An optimized version of AbstractList.ListItr
  70.784 -     */
  70.785 -    private class ListItr extends Itr implements ListIterator<E> {
  70.786 -        ListItr(int index) {
  70.787 -            super();
  70.788 -            cursor = index;
  70.789 -        }
  70.790 -
  70.791 -        public boolean hasPrevious() {
  70.792 -            return cursor != 0;
  70.793 -        }
  70.794 -
  70.795 -        public int nextIndex() {
  70.796 -            return cursor;
  70.797 -        }
  70.798 -
  70.799 -        public int previousIndex() {
  70.800 -            return cursor - 1;
  70.801 -        }
  70.802 -
  70.803 -        @SuppressWarnings("unchecked")
  70.804 -        public E previous() {
  70.805 -            checkForComodification();
  70.806 -            int i = cursor - 1;
  70.807 -            if (i < 0)
  70.808 -                throw new NoSuchElementException();
  70.809 -            Object[] elementData = ArrayList.this.elementData;
  70.810 -            if (i >= elementData.length)
  70.811 -                throw new ConcurrentModificationException();
  70.812 -            cursor = i;
  70.813 -            return (E) elementData[lastRet = i];
  70.814 -        }
  70.815 -
  70.816 -        public void set(E e) {
  70.817 -            if (lastRet < 0)
  70.818 -                throw new IllegalStateException();
  70.819 -            checkForComodification();
  70.820 -
  70.821 -            try {
  70.822 -                ArrayList.this.set(lastRet, e);
  70.823 -            } catch (IndexOutOfBoundsException ex) {
  70.824 -                throw new ConcurrentModificationException();
  70.825 -            }
  70.826 -        }
  70.827 -
  70.828 -        public void add(E e) {
  70.829 -            checkForComodification();
  70.830 -
  70.831 -            try {
  70.832 -                int i = cursor;
  70.833 -                ArrayList.this.add(i, e);
  70.834 -                cursor = i + 1;
  70.835 -                lastRet = -1;
  70.836 -                expectedModCount = modCount;
  70.837 -            } catch (IndexOutOfBoundsException ex) {
  70.838 -                throw new ConcurrentModificationException();
  70.839 -            }
  70.840 -        }
  70.841 -    }
  70.842 -
  70.843 -    /**
  70.844 -     * Returns a view of the portion of this list between the specified
  70.845 -     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.  (If
  70.846 -     * {@code fromIndex} and {@code toIndex} are equal, the returned list is
  70.847 -     * empty.)  The returned list is backed by this list, so non-structural
  70.848 -     * changes in the returned list are reflected in this list, and vice-versa.
  70.849 -     * The returned list supports all of the optional list operations.
  70.850 -     *
  70.851 -     * <p>This method eliminates the need for explicit range operations (of
  70.852 -     * the sort that commonly exist for arrays).  Any operation that expects
  70.853 -     * a list can be used as a range operation by passing a subList view
  70.854 -     * instead of a whole list.  For example, the following idiom
  70.855 -     * removes a range of elements from a list:
  70.856 -     * <pre>
  70.857 -     *      list.subList(from, to).clear();
  70.858 -     * </pre>
  70.859 -     * Similar idioms may be constructed for {@link #indexOf(Object)} and
  70.860 -     * {@link #lastIndexOf(Object)}, and all of the algorithms in the
  70.861 -     * {@link Collections} class can be applied to a subList.
  70.862 -     *
  70.863 -     * <p>The semantics of the list returned by this method become undefined if
  70.864 -     * the backing list (i.e., this list) is <i>structurally modified</i> in
  70.865 -     * any way other than via the returned list.  (Structural modifications are
  70.866 -     * those that change the size of this list, or otherwise perturb it in such
  70.867 -     * a fashion that iterations in progress may yield incorrect results.)
  70.868 -     *
  70.869 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  70.870 -     * @throws IllegalArgumentException {@inheritDoc}
  70.871 -     */
  70.872 -    public List<E> subList(int fromIndex, int toIndex) {
  70.873 -        subListRangeCheck(fromIndex, toIndex, size);
  70.874 -        return new SubList(this, 0, fromIndex, toIndex);
  70.875 -    }
  70.876 -
  70.877 -    static void subListRangeCheck(int fromIndex, int toIndex, int size) {
  70.878 -        if (fromIndex < 0)
  70.879 -            throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
  70.880 -        if (toIndex > size)
  70.881 -            throw new IndexOutOfBoundsException("toIndex = " + toIndex);
  70.882 -        if (fromIndex > toIndex)
  70.883 -            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  70.884 -                                               ") > toIndex(" + toIndex + ")");
  70.885 -    }
  70.886 -
  70.887 -    private class SubList extends AbstractList<E> implements RandomAccess {
  70.888 -        private final AbstractList<E> parent;
  70.889 -        private final int parentOffset;
  70.890 -        private final int offset;
  70.891 -        int size;
  70.892 -
  70.893 -        SubList(AbstractList<E> parent,
  70.894 -                int offset, int fromIndex, int toIndex) {
  70.895 -            this.parent = parent;
  70.896 -            this.parentOffset = fromIndex;
  70.897 -            this.offset = offset + fromIndex;
  70.898 -            this.size = toIndex - fromIndex;
  70.899 -            this.modCount = ArrayList.this.modCount;
  70.900 -        }
  70.901 -
  70.902 -        public E set(int index, E e) {
  70.903 -            rangeCheck(index);
  70.904 -            checkForComodification();
  70.905 -            E oldValue = ArrayList.this.elementData(offset + index);
  70.906 -            ArrayList.this.elementData[offset + index] = e;
  70.907 -            return oldValue;
  70.908 -        }
  70.909 -
  70.910 -        public E get(int index) {
  70.911 -            rangeCheck(index);
  70.912 -            checkForComodification();
  70.913 -            return ArrayList.this.elementData(offset + index);
  70.914 -        }
  70.915 -
  70.916 -        public int size() {
  70.917 -            checkForComodification();
  70.918 -            return this.size;
  70.919 -        }
  70.920 -
  70.921 -        public void add(int index, E e) {
  70.922 -            rangeCheckForAdd(index);
  70.923 -            checkForComodification();
  70.924 -            parent.add(parentOffset + index, e);
  70.925 -            this.modCount = parent.modCount;
  70.926 -            this.size++;
  70.927 -        }
  70.928 -
  70.929 -        public E remove(int index) {
  70.930 -            rangeCheck(index);
  70.931 -            checkForComodification();
  70.932 -            E result = parent.remove(parentOffset + index);
  70.933 -            this.modCount = parent.modCount;
  70.934 -            this.size--;
  70.935 -            return result;
  70.936 -        }
  70.937 -
  70.938 -        protected void removeRange(int fromIndex, int toIndex) {
  70.939 -            checkForComodification();
  70.940 -            parent.removeRange(parentOffset + fromIndex,
  70.941 -                               parentOffset + toIndex);
  70.942 -            this.modCount = parent.modCount;
  70.943 -            this.size -= toIndex - fromIndex;
  70.944 -        }
  70.945 -
  70.946 -        public boolean addAll(Collection<? extends E> c) {
  70.947 -            return addAll(this.size, c);
  70.948 -        }
  70.949 -
  70.950 -        public boolean addAll(int index, Collection<? extends E> c) {
  70.951 -            rangeCheckForAdd(index);
  70.952 -            int cSize = c.size();
  70.953 -            if (cSize==0)
  70.954 -                return false;
  70.955 -
  70.956 -            checkForComodification();
  70.957 -            parent.addAll(parentOffset + index, c);
  70.958 -            this.modCount = parent.modCount;
  70.959 -            this.size += cSize;
  70.960 -            return true;
  70.961 -        }
  70.962 -
  70.963 -        public Iterator<E> iterator() {
  70.964 -            return listIterator();
  70.965 -        }
  70.966 -
  70.967 -        public ListIterator<E> listIterator(final int index) {
  70.968 -            checkForComodification();
  70.969 -            rangeCheckForAdd(index);
  70.970 -            final int offset = this.offset;
  70.971 -
  70.972 -            return new ListIterator<E>() {
  70.973 -                int cursor = index;
  70.974 -                int lastRet = -1;
  70.975 -                int expectedModCount = ArrayList.this.modCount;
  70.976 -
  70.977 -                public boolean hasNext() {
  70.978 -                    return cursor != SubList.this.size;
  70.979 -                }
  70.980 -
  70.981 -                @SuppressWarnings("unchecked")
  70.982 -                public E next() {
  70.983 -                    checkForComodification();
  70.984 -                    int i = cursor;
  70.985 -                    if (i >= SubList.this.size)
  70.986 -                        throw new NoSuchElementException();
  70.987 -                    Object[] elementData = ArrayList.this.elementData;
  70.988 -                    if (offset + i >= elementData.length)
  70.989 -                        throw new ConcurrentModificationException();
  70.990 -                    cursor = i + 1;
  70.991 -                    return (E) elementData[offset + (lastRet = i)];
  70.992 -                }
  70.993 -
  70.994 -                public boolean hasPrevious() {
  70.995 -                    return cursor != 0;
  70.996 -                }
  70.997 -
  70.998 -                @SuppressWarnings("unchecked")
  70.999 -                public E previous() {
 70.1000 -                    checkForComodification();
 70.1001 -                    int i = cursor - 1;
 70.1002 -                    if (i < 0)
 70.1003 -                        throw new NoSuchElementException();
 70.1004 -                    Object[] elementData = ArrayList.this.elementData;
 70.1005 -                    if (offset + i >= elementData.length)
 70.1006 -                        throw new ConcurrentModificationException();
 70.1007 -                    cursor = i;
 70.1008 -                    return (E) elementData[offset + (lastRet = i)];
 70.1009 -                }
 70.1010 -
 70.1011 -                public int nextIndex() {
 70.1012 -                    return cursor;
 70.1013 -                }
 70.1014 -
 70.1015 -                public int previousIndex() {
 70.1016 -                    return cursor - 1;
 70.1017 -                }
 70.1018 -
 70.1019 -                public void remove() {
 70.1020 -                    if (lastRet < 0)
 70.1021 -                        throw new IllegalStateException();
 70.1022 -                    checkForComodification();
 70.1023 -
 70.1024 -                    try {
 70.1025 -                        SubList.this.remove(lastRet);
 70.1026 -                        cursor = lastRet;
 70.1027 -                        lastRet = -1;
 70.1028 -                        expectedModCount = ArrayList.this.modCount;
 70.1029 -                    } catch (IndexOutOfBoundsException ex) {
 70.1030 -                        throw new ConcurrentModificationException();
 70.1031 -                    }
 70.1032 -                }
 70.1033 -
 70.1034 -                public void set(E e) {
 70.1035 -                    if (lastRet < 0)
 70.1036 -                        throw new IllegalStateException();
 70.1037 -                    checkForComodification();
 70.1038 -
 70.1039 -                    try {
 70.1040 -                        ArrayList.this.set(offset + lastRet, e);
 70.1041 -                    } catch (IndexOutOfBoundsException ex) {
 70.1042 -                        throw new ConcurrentModificationException();
 70.1043 -                    }
 70.1044 -                }
 70.1045 -
 70.1046 -                public void add(E e) {
 70.1047 -                    checkForComodification();
 70.1048 -
 70.1049 -                    try {
 70.1050 -                        int i = cursor;
 70.1051 -                        SubList.this.add(i, e);
 70.1052 -                        cursor = i + 1;
 70.1053 -                        lastRet = -1;
 70.1054 -                        expectedModCount = ArrayList.this.modCount;
 70.1055 -                    } catch (IndexOutOfBoundsException ex) {
 70.1056 -                        throw new ConcurrentModificationException();
 70.1057 -                    }
 70.1058 -                }
 70.1059 -
 70.1060 -                final void checkForComodification() {
 70.1061 -                    if (expectedModCount != ArrayList.this.modCount)
 70.1062 -                        throw new ConcurrentModificationException();
 70.1063 -                }
 70.1064 -            };
 70.1065 -        }
 70.1066 -
 70.1067 -        public List<E> subList(int fromIndex, int toIndex) {
 70.1068 -            subListRangeCheck(fromIndex, toIndex, size);
 70.1069 -            return new SubList(this, offset, fromIndex, toIndex);
 70.1070 -        }
 70.1071 -
 70.1072 -        private void rangeCheck(int index) {
 70.1073 -            if (index < 0 || index >= this.size)
 70.1074 -                throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 70.1075 -        }
 70.1076 -
 70.1077 -        private void rangeCheckForAdd(int index) {
 70.1078 -            if (index < 0 || index > this.size)
 70.1079 -                throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 70.1080 -        }
 70.1081 -
 70.1082 -        private String outOfBoundsMsg(int index) {
 70.1083 -            return "Index: "+index+", Size: "+this.size;
 70.1084 -        }
 70.1085 -
 70.1086 -        private void checkForComodification() {
 70.1087 -            if (ArrayList.this.modCount != this.modCount)
 70.1088 -                throw new ConcurrentModificationException();
 70.1089 -        }
 70.1090 -    }
 70.1091 -}
    71.1 --- a/emul/compact/src/main/java/java/util/Arrays.java	Mon Feb 25 19:00:08 2013 +0100
    71.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.3 @@ -1,3670 +0,0 @@
    71.4 -/*
    71.5 - * Copyright (c) 1997, 2011, 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 -import java.lang.reflect.*;
   71.32 -
   71.33 -/**
   71.34 - * This class contains various methods for manipulating arrays (such as
   71.35 - * sorting and searching). This class also contains a static factory
   71.36 - * that allows arrays to be viewed as lists.
   71.37 - *
   71.38 - * <p>The methods in this class all throw a {@code NullPointerException},
   71.39 - * if the specified array reference is null, except where noted.
   71.40 - *
   71.41 - * <p>The documentation for the methods contained in this class includes
   71.42 - * briefs description of the <i>implementations</i>. Such descriptions should
   71.43 - * be regarded as <i>implementation notes</i>, rather than parts of the
   71.44 - * <i>specification</i>. Implementors should feel free to substitute other
   71.45 - * algorithms, so long as the specification itself is adhered to. (For
   71.46 - * example, the algorithm used by {@code sort(Object[])} does not have to be
   71.47 - * a MergeSort, but it does have to be <i>stable</i>.)
   71.48 - *
   71.49 - * <p>This class is a member of the
   71.50 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   71.51 - * Java Collections Framework</a>.
   71.52 - *
   71.53 - * @author Josh Bloch
   71.54 - * @author Neal Gafter
   71.55 - * @author John Rose
   71.56 - * @since  1.2
   71.57 - */
   71.58 -public class Arrays {
   71.59 -
   71.60 -    // Suppresses default constructor, ensuring non-instantiability.
   71.61 -    private Arrays() {}
   71.62 -
   71.63 -    /*
   71.64 -     * Sorting of primitive type arrays.
   71.65 -     */
   71.66 -
   71.67 -    /**
   71.68 -     * Sorts the specified array into ascending numerical order.
   71.69 -     *
   71.70 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
   71.71 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
   71.72 -     * offers O(n log(n)) performance on many data sets that cause other
   71.73 -     * quicksorts to degrade to quadratic performance, and is typically
   71.74 -     * faster than traditional (one-pivot) Quicksort implementations.
   71.75 -     *
   71.76 -     * @param a the array to be sorted
   71.77 -     */
   71.78 -    public static void sort(int[] a) {
   71.79 -        DualPivotQuicksort.sort(a);
   71.80 -    }
   71.81 -
   71.82 -    /**
   71.83 -     * Sorts the specified range of the array into ascending order. The range
   71.84 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
   71.85 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
   71.86 -     * the range to be sorted is empty.
   71.87 -     *
   71.88 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
   71.89 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
   71.90 -     * offers O(n log(n)) performance on many data sets that cause other
   71.91 -     * quicksorts to degrade to quadratic performance, and is typically
   71.92 -     * faster than traditional (one-pivot) Quicksort implementations.
   71.93 -     *
   71.94 -     * @param a the array to be sorted
   71.95 -     * @param fromIndex the index of the first element, inclusive, to be sorted
   71.96 -     * @param toIndex the index of the last element, exclusive, to be sorted
   71.97 -     *
   71.98 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
   71.99 -     * @throws ArrayIndexOutOfBoundsException
  71.100 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.101 -     */
  71.102 -    public static void sort(int[] a, int fromIndex, int toIndex) {
  71.103 -        rangeCheck(a.length, fromIndex, toIndex);
  71.104 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.105 -    }
  71.106 -
  71.107 -    /**
  71.108 -     * Sorts the specified array into ascending numerical order.
  71.109 -     *
  71.110 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.111 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.112 -     * offers O(n log(n)) performance on many data sets that cause other
  71.113 -     * quicksorts to degrade to quadratic performance, and is typically
  71.114 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.115 -     *
  71.116 -     * @param a the array to be sorted
  71.117 -     */
  71.118 -    public static void sort(long[] a) {
  71.119 -        DualPivotQuicksort.sort(a);
  71.120 -    }
  71.121 -
  71.122 -    /**
  71.123 -     * Sorts the specified range of the array into ascending order. The range
  71.124 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  71.125 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  71.126 -     * the range to be sorted is empty.
  71.127 -     *
  71.128 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.129 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.130 -     * offers O(n log(n)) performance on many data sets that cause other
  71.131 -     * quicksorts to degrade to quadratic performance, and is typically
  71.132 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.133 -     *
  71.134 -     * @param a the array to be sorted
  71.135 -     * @param fromIndex the index of the first element, inclusive, to be sorted
  71.136 -     * @param toIndex the index of the last element, exclusive, to be sorted
  71.137 -     *
  71.138 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  71.139 -     * @throws ArrayIndexOutOfBoundsException
  71.140 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.141 -     */
  71.142 -    public static void sort(long[] a, int fromIndex, int toIndex) {
  71.143 -        rangeCheck(a.length, fromIndex, toIndex);
  71.144 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.145 -    }
  71.146 -
  71.147 -    /**
  71.148 -     * Sorts the specified array into ascending numerical order.
  71.149 -     *
  71.150 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.151 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.152 -     * offers O(n log(n)) performance on many data sets that cause other
  71.153 -     * quicksorts to degrade to quadratic performance, and is typically
  71.154 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.155 -     *
  71.156 -     * @param a the array to be sorted
  71.157 -     */
  71.158 -    public static void sort(short[] a) {
  71.159 -        DualPivotQuicksort.sort(a);
  71.160 -    }
  71.161 -
  71.162 -    /**
  71.163 -     * Sorts the specified range of the array into ascending order. The range
  71.164 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  71.165 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  71.166 -     * the range to be sorted is empty.
  71.167 -     *
  71.168 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.169 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.170 -     * offers O(n log(n)) performance on many data sets that cause other
  71.171 -     * quicksorts to degrade to quadratic performance, and is typically
  71.172 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.173 -     *
  71.174 -     * @param a the array to be sorted
  71.175 -     * @param fromIndex the index of the first element, inclusive, to be sorted
  71.176 -     * @param toIndex the index of the last element, exclusive, to be sorted
  71.177 -     *
  71.178 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  71.179 -     * @throws ArrayIndexOutOfBoundsException
  71.180 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.181 -     */
  71.182 -    public static void sort(short[] a, int fromIndex, int toIndex) {
  71.183 -        rangeCheck(a.length, fromIndex, toIndex);
  71.184 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.185 -    }
  71.186 -
  71.187 -    /**
  71.188 -     * Sorts the specified array into ascending numerical order.
  71.189 -     *
  71.190 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.191 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.192 -     * offers O(n log(n)) performance on many data sets that cause other
  71.193 -     * quicksorts to degrade to quadratic performance, and is typically
  71.194 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.195 -     *
  71.196 -     * @param a the array to be sorted
  71.197 -     */
  71.198 -    public static void sort(char[] a) {
  71.199 -        DualPivotQuicksort.sort(a);
  71.200 -    }
  71.201 -
  71.202 -    /**
  71.203 -     * Sorts the specified range of the array into ascending order. The range
  71.204 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  71.205 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  71.206 -     * the range to be sorted is empty.
  71.207 -     *
  71.208 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.209 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.210 -     * offers O(n log(n)) performance on many data sets that cause other
  71.211 -     * quicksorts to degrade to quadratic performance, and is typically
  71.212 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.213 -     *
  71.214 -     * @param a the array to be sorted
  71.215 -     * @param fromIndex the index of the first element, inclusive, to be sorted
  71.216 -     * @param toIndex the index of the last element, exclusive, to be sorted
  71.217 -     *
  71.218 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  71.219 -     * @throws ArrayIndexOutOfBoundsException
  71.220 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.221 -     */
  71.222 -    public static void sort(char[] a, int fromIndex, int toIndex) {
  71.223 -        rangeCheck(a.length, fromIndex, toIndex);
  71.224 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.225 -    }
  71.226 -
  71.227 -    /**
  71.228 -     * Sorts the specified array into ascending numerical order.
  71.229 -     *
  71.230 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.231 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.232 -     * offers O(n log(n)) performance on many data sets that cause other
  71.233 -     * quicksorts to degrade to quadratic performance, and is typically
  71.234 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.235 -     *
  71.236 -     * @param a the array to be sorted
  71.237 -     */
  71.238 -    public static void sort(byte[] a) {
  71.239 -        DualPivotQuicksort.sort(a);
  71.240 -    }
  71.241 -
  71.242 -    /**
  71.243 -     * Sorts the specified range of the array into ascending order. The range
  71.244 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  71.245 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  71.246 -     * the range to be sorted is empty.
  71.247 -     *
  71.248 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.249 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.250 -     * offers O(n log(n)) performance on many data sets that cause other
  71.251 -     * quicksorts to degrade to quadratic performance, and is typically
  71.252 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.253 -     *
  71.254 -     * @param a the array to be sorted
  71.255 -     * @param fromIndex the index of the first element, inclusive, to be sorted
  71.256 -     * @param toIndex the index of the last element, exclusive, to be sorted
  71.257 -     *
  71.258 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  71.259 -     * @throws ArrayIndexOutOfBoundsException
  71.260 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.261 -     */
  71.262 -    public static void sort(byte[] a, int fromIndex, int toIndex) {
  71.263 -        rangeCheck(a.length, fromIndex, toIndex);
  71.264 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.265 -    }
  71.266 -
  71.267 -    /**
  71.268 -     * Sorts the specified array into ascending numerical order.
  71.269 -     *
  71.270 -     * <p>The {@code <} relation does not provide a total order on all float
  71.271 -     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
  71.272 -     * value compares neither less than, greater than, nor equal to any value,
  71.273 -     * even itself. This method uses the total order imposed by the method
  71.274 -     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
  71.275 -     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
  71.276 -     * other value and all {@code Float.NaN} values are considered equal.
  71.277 -     *
  71.278 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.279 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.280 -     * offers O(n log(n)) performance on many data sets that cause other
  71.281 -     * quicksorts to degrade to quadratic performance, and is typically
  71.282 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.283 -     *
  71.284 -     * @param a the array to be sorted
  71.285 -     */
  71.286 -    public static void sort(float[] a) {
  71.287 -        DualPivotQuicksort.sort(a);
  71.288 -    }
  71.289 -
  71.290 -    /**
  71.291 -     * Sorts the specified range of the array into ascending order. The range
  71.292 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  71.293 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  71.294 -     * the range to be sorted is empty.
  71.295 -     *
  71.296 -     * <p>The {@code <} relation does not provide a total order on all float
  71.297 -     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
  71.298 -     * value compares neither less than, greater than, nor equal to any value,
  71.299 -     * even itself. This method uses the total order imposed by the method
  71.300 -     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
  71.301 -     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
  71.302 -     * other value and all {@code Float.NaN} values are considered equal.
  71.303 -     *
  71.304 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.305 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.306 -     * offers O(n log(n)) performance on many data sets that cause other
  71.307 -     * quicksorts to degrade to quadratic performance, and is typically
  71.308 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.309 -     *
  71.310 -     * @param a the array to be sorted
  71.311 -     * @param fromIndex the index of the first element, inclusive, to be sorted
  71.312 -     * @param toIndex the index of the last element, exclusive, to be sorted
  71.313 -     *
  71.314 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  71.315 -     * @throws ArrayIndexOutOfBoundsException
  71.316 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.317 -     */
  71.318 -    public static void sort(float[] a, int fromIndex, int toIndex) {
  71.319 -        rangeCheck(a.length, fromIndex, toIndex);
  71.320 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.321 -    }
  71.322 -
  71.323 -    /**
  71.324 -     * Sorts the specified array into ascending numerical order.
  71.325 -     *
  71.326 -     * <p>The {@code <} relation does not provide a total order on all double
  71.327 -     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
  71.328 -     * value compares neither less than, greater than, nor equal to any value,
  71.329 -     * even itself. This method uses the total order imposed by the method
  71.330 -     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
  71.331 -     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
  71.332 -     * other value and all {@code Double.NaN} values are considered equal.
  71.333 -     *
  71.334 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.335 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.336 -     * offers O(n log(n)) performance on many data sets that cause other
  71.337 -     * quicksorts to degrade to quadratic performance, and is typically
  71.338 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.339 -     *
  71.340 -     * @param a the array to be sorted
  71.341 -     */
  71.342 -    public static void sort(double[] a) {
  71.343 -        DualPivotQuicksort.sort(a);
  71.344 -    }
  71.345 -
  71.346 -    /**
  71.347 -     * Sorts the specified range of the array into ascending order. The range
  71.348 -     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  71.349 -     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  71.350 -     * the range to be sorted is empty.
  71.351 -     *
  71.352 -     * <p>The {@code <} relation does not provide a total order on all double
  71.353 -     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
  71.354 -     * value compares neither less than, greater than, nor equal to any value,
  71.355 -     * even itself. This method uses the total order imposed by the method
  71.356 -     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
  71.357 -     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
  71.358 -     * other value and all {@code Double.NaN} values are considered equal.
  71.359 -     *
  71.360 -     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  71.361 -     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  71.362 -     * offers O(n log(n)) performance on many data sets that cause other
  71.363 -     * quicksorts to degrade to quadratic performance, and is typically
  71.364 -     * faster than traditional (one-pivot) Quicksort implementations.
  71.365 -     *
  71.366 -     * @param a the array to be sorted
  71.367 -     * @param fromIndex the index of the first element, inclusive, to be sorted
  71.368 -     * @param toIndex the index of the last element, exclusive, to be sorted
  71.369 -     *
  71.370 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  71.371 -     * @throws ArrayIndexOutOfBoundsException
  71.372 -     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
  71.373 -     */
  71.374 -    public static void sort(double[] a, int fromIndex, int toIndex) {
  71.375 -        rangeCheck(a.length, fromIndex, toIndex);
  71.376 -        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
  71.377 -    }
  71.378 -
  71.379 -    /*
  71.380 -     * Sorting of complex type arrays.
  71.381 -     */
  71.382 -
  71.383 -    /**
  71.384 -     * Old merge sort implementation can be selected (for
  71.385 -     * compatibility with broken comparators) using a system property.
  71.386 -     * Cannot be a static boolean in the enclosing class due to
  71.387 -     * circular dependencies. To be removed in a future release.
  71.388 -     */
  71.389 -    static final class LegacyMergeSort {
  71.390 -        private static final boolean userRequested = false;
  71.391 -    }
  71.392 -
  71.393 -    /*
  71.394 -     * If this platform has an optimizing VM, check whether ComparableTimSort
  71.395 -     * offers any performance benefit over TimSort in conjunction with a
  71.396 -     * comparator that returns:
  71.397 -     *    {@code ((Comparable)first).compareTo(Second)}.
  71.398 -     * If not, you are better off deleting ComparableTimSort to
  71.399 -     * eliminate the code duplication.  In other words, the commented
  71.400 -     * out code below is the preferable implementation for sorting
  71.401 -     * arrays of Comparables if it offers sufficient performance.
  71.402 -     */
  71.403 -
  71.404 -//    /**
  71.405 -//     * A comparator that implements the natural ordering of a group of
  71.406 -//     * mutually comparable elements.  Using this comparator saves us
  71.407 -//     * from duplicating most of the code in this file (one version for
  71.408 -//     * Comparables, one for explicit Comparators).
  71.409 -//     */
  71.410 -//    private static final Comparator<Object> NATURAL_ORDER =
  71.411 -//            new Comparator<Object>() {
  71.412 -//        @SuppressWarnings("unchecked")
  71.413 -//        public int compare(Object first, Object second) {
  71.414 -//            return ((Comparable<Object>)first).compareTo(second);
  71.415 -//        }
  71.416 -//    };
  71.417 -//
  71.418 -//    public static void sort(Object[] a) {
  71.419 -//        sort(a, 0, a.length, NATURAL_ORDER);
  71.420 -//    }
  71.421 -//
  71.422 -//    public static void sort(Object[] a, int fromIndex, int toIndex) {
  71.423 -//        sort(a, fromIndex, toIndex, NATURAL_ORDER);
  71.424 -//    }
  71.425 -
  71.426 -    /**
  71.427 -     * Sorts the specified array of objects into ascending order, according
  71.428 -     * to the {@linkplain Comparable natural ordering} of its elements.
  71.429 -     * All elements in the array must implement the {@link Comparable}
  71.430 -     * interface.  Furthermore, all elements in the array must be
  71.431 -     * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)} must
  71.432 -     * not throw a {@code ClassCastException} for any elements {@code e1}
  71.433 -     * and {@code e2} in the array).
  71.434 -     *
  71.435 -     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  71.436 -     * not be reordered as a result of the sort.
  71.437 -     *
  71.438 -     * <p>Implementation note: This implementation is a stable, adaptive,
  71.439 -     * iterative mergesort that requires far fewer than n lg(n) comparisons
  71.440 -     * when the input array is partially sorted, while offering the
  71.441 -     * performance of a traditional mergesort when the input array is
  71.442 -     * randomly ordered.  If the input array is nearly sorted, the
  71.443 -     * implementation requires approximately n comparisons.  Temporary
  71.444 -     * storage requirements vary from a small constant for nearly sorted
  71.445 -     * input arrays to n/2 object references for randomly ordered input
  71.446 -     * arrays.
  71.447 -     *
  71.448 -     * <p>The implementation takes equal advantage of ascending and
  71.449 -     * descending order in its input array, and can take advantage of
  71.450 -     * ascending and descending order in different parts of the the same
  71.451 -     * input array.  It is well-suited to merging two or more sorted arrays:
  71.452 -     * simply concatenate the arrays and sort the resulting array.
  71.453 -     *
  71.454 -     * <p>The implementation was adapted from Tim Peters's list sort for Python
  71.455 -     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  71.456 -     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  71.457 -     * Sorting and Information Theoretic Complexity", in Proceedings of the
  71.458 -     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  71.459 -     * January 1993.
  71.460 -     *
  71.461 -     * @param a the array to be sorted
  71.462 -     * @throws ClassCastException if the array contains elements that are not
  71.463 -     *         <i>mutually comparable</i> (for example, strings and integers)
  71.464 -     * @throws IllegalArgumentException (optional) if the natural
  71.465 -     *         ordering of the array elements is found to violate the
  71.466 -     *         {@link Comparable} contract
  71.467 -     */
  71.468 -    public static void sort(Object[] a) {
  71.469 -        if (LegacyMergeSort.userRequested)
  71.470 -            legacyMergeSort(a);
  71.471 -        else
  71.472 -            ComparableTimSort.sort(a);
  71.473 -    }
  71.474 -
  71.475 -    /** To be removed in a future release. */
  71.476 -    private static void legacyMergeSort(Object[] a) {
  71.477 -        Object[] aux = a.clone();
  71.478 -        mergeSort(aux, a, 0, a.length, 0);
  71.479 -    }
  71.480 -
  71.481 -    /**
  71.482 -     * Sorts the specified range of the specified array of objects into
  71.483 -     * ascending order, according to the
  71.484 -     * {@linkplain Comparable natural ordering} of its
  71.485 -     * elements.  The range to be sorted extends from index
  71.486 -     * {@code fromIndex}, inclusive, to index {@code toIndex}, exclusive.
  71.487 -     * (If {@code fromIndex==toIndex}, the range to be sorted is empty.)  All
  71.488 -     * elements in this range must implement the {@link Comparable}
  71.489 -     * interface.  Furthermore, all elements in this range must be <i>mutually
  71.490 -     * comparable</i> (that is, {@code e1.compareTo(e2)} must not throw a
  71.491 -     * {@code ClassCastException} for any elements {@code e1} and
  71.492 -     * {@code e2} in the array).
  71.493 -     *
  71.494 -     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  71.495 -     * not be reordered as a result of the sort.
  71.496 -     *
  71.497 -     * <p>Implementation note: This implementation is a stable, adaptive,
  71.498 -     * iterative mergesort that requires far fewer than n lg(n) comparisons
  71.499 -     * when the input array is partially sorted, while offering the
  71.500 -     * performance of a traditional mergesort when the input array is
  71.501 -     * randomly ordered.  If the input array is nearly sorted, the
  71.502 -     * implementation requires approximately n comparisons.  Temporary
  71.503 -     * storage requirements vary from a small constant for nearly sorted
  71.504 -     * input arrays to n/2 object references for randomly ordered input
  71.505 -     * arrays.
  71.506 -     *
  71.507 -     * <p>The implementation takes equal advantage of ascending and
  71.508 -     * descending order in its input array, and can take advantage of
  71.509 -     * ascending and descending order in different parts of the the same
  71.510 -     * input array.  It is well-suited to merging two or more sorted arrays:
  71.511 -     * simply concatenate the arrays and sort the resulting array.
  71.512 -     *
  71.513 -     * <p>The implementation was adapted from Tim Peters's list sort for Python
  71.514 -     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  71.515 -     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  71.516 -     * Sorting and Information Theoretic Complexity", in Proceedings of the
  71.517 -     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  71.518 -     * January 1993.
  71.519 -     *
  71.520 -     * @param a the array to be sorted
  71.521 -     * @param fromIndex the index of the first element (inclusive) to be
  71.522 -     *        sorted
  71.523 -     * @param toIndex the index of the last element (exclusive) to be sorted
  71.524 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
  71.525 -     *         (optional) if the natural ordering of the array elements is
  71.526 -     *         found to violate the {@link Comparable} contract
  71.527 -     * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
  71.528 -     *         {@code toIndex > a.length}
  71.529 -     * @throws ClassCastException if the array contains elements that are
  71.530 -     *         not <i>mutually comparable</i> (for example, strings and
  71.531 -     *         integers).
  71.532 -     */
  71.533 -    public static void sort(Object[] a, int fromIndex, int toIndex) {
  71.534 -        if (LegacyMergeSort.userRequested)
  71.535 -            legacyMergeSort(a, fromIndex, toIndex);
  71.536 -        else
  71.537 -            ComparableTimSort.sort(a, fromIndex, toIndex);
  71.538 -    }
  71.539 -
  71.540 -    /** To be removed in a future release. */
  71.541 -    private static void legacyMergeSort(Object[] a,
  71.542 -                                        int fromIndex, int toIndex) {
  71.543 -        rangeCheck(a.length, fromIndex, toIndex);
  71.544 -        Object[] aux = copyOfRange(a, fromIndex, toIndex);
  71.545 -        mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
  71.546 -    }
  71.547 -
  71.548 -    /**
  71.549 -     * Tuning parameter: list size at or below which insertion sort will be
  71.550 -     * used in preference to mergesort.
  71.551 -     * To be removed in a future release.
  71.552 -     */
  71.553 -    private static final int INSERTIONSORT_THRESHOLD = 7;
  71.554 -
  71.555 -    /**
  71.556 -     * Src is the source array that starts at index 0
  71.557 -     * Dest is the (possibly larger) array destination with a possible offset
  71.558 -     * low is the index in dest to start sorting
  71.559 -     * high is the end index in dest to end sorting
  71.560 -     * off is the offset to generate corresponding low, high in src
  71.561 -     * To be removed in a future release.
  71.562 -     */
  71.563 -    private static void mergeSort(Object[] src,
  71.564 -                                  Object[] dest,
  71.565 -                                  int low,
  71.566 -                                  int high,
  71.567 -                                  int off) {
  71.568 -        int length = high - low;
  71.569 -
  71.570 -        // Insertion sort on smallest arrays
  71.571 -        if (length < INSERTIONSORT_THRESHOLD) {
  71.572 -            for (int i=low; i<high; i++)
  71.573 -                for (int j=i; j>low &&
  71.574 -                         ((Comparable) dest[j-1]).compareTo(dest[j])>0; j--)
  71.575 -                    swap(dest, j, j-1);
  71.576 -            return;
  71.577 -        }
  71.578 -
  71.579 -        // Recursively sort halves of dest into src
  71.580 -        int destLow  = low;
  71.581 -        int destHigh = high;
  71.582 -        low  += off;
  71.583 -        high += off;
  71.584 -        int mid = (low + high) >>> 1;
  71.585 -        mergeSort(dest, src, low, mid, -off);
  71.586 -        mergeSort(dest, src, mid, high, -off);
  71.587 -
  71.588 -        // If list is already sorted, just copy from src to dest.  This is an
  71.589 -        // optimization that results in faster sorts for nearly ordered lists.
  71.590 -        if (((Comparable)src[mid-1]).compareTo(src[mid]) <= 0) {
  71.591 -            System.arraycopy(src, low, dest, destLow, length);
  71.592 -            return;
  71.593 -        }
  71.594 -
  71.595 -        // Merge sorted halves (now in src) into dest
  71.596 -        for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
  71.597 -            if (q >= high || p < mid && ((Comparable)src[p]).compareTo(src[q])<=0)
  71.598 -                dest[i] = src[p++];
  71.599 -            else
  71.600 -                dest[i] = src[q++];
  71.601 -        }
  71.602 -    }
  71.603 -
  71.604 -    /**
  71.605 -     * Swaps x[a] with x[b].
  71.606 -     */
  71.607 -    private static void swap(Object[] x, int a, int b) {
  71.608 -        Object t = x[a];
  71.609 -        x[a] = x[b];
  71.610 -        x[b] = t;
  71.611 -    }
  71.612 -
  71.613 -    /**
  71.614 -     * Sorts the specified array of objects according to the order induced by
  71.615 -     * the specified comparator.  All elements in the array must be
  71.616 -     * <i>mutually comparable</i> by the specified comparator (that is,
  71.617 -     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
  71.618 -     * for any elements {@code e1} and {@code e2} in the array).
  71.619 -     *
  71.620 -     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  71.621 -     * not be reordered as a result of the sort.
  71.622 -     *
  71.623 -     * <p>Implementation note: This implementation is a stable, adaptive,
  71.624 -     * iterative mergesort that requires far fewer than n lg(n) comparisons
  71.625 -     * when the input array is partially sorted, while offering the
  71.626 -     * performance of a traditional mergesort when the input array is
  71.627 -     * randomly ordered.  If the input array is nearly sorted, the
  71.628 -     * implementation requires approximately n comparisons.  Temporary
  71.629 -     * storage requirements vary from a small constant for nearly sorted
  71.630 -     * input arrays to n/2 object references for randomly ordered input
  71.631 -     * arrays.
  71.632 -     *
  71.633 -     * <p>The implementation takes equal advantage of ascending and
  71.634 -     * descending order in its input array, and can take advantage of
  71.635 -     * ascending and descending order in different parts of the the same
  71.636 -     * input array.  It is well-suited to merging two or more sorted arrays:
  71.637 -     * simply concatenate the arrays and sort the resulting array.
  71.638 -     *
  71.639 -     * <p>The implementation was adapted from Tim Peters's list sort for Python
  71.640 -     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  71.641 -     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  71.642 -     * Sorting and Information Theoretic Complexity", in Proceedings of the
  71.643 -     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  71.644 -     * January 1993.
  71.645 -     *
  71.646 -     * @param a the array to be sorted
  71.647 -     * @param c the comparator to determine the order of the array.  A
  71.648 -     *        {@code null} value indicates that the elements'
  71.649 -     *        {@linkplain Comparable natural ordering} should be used.
  71.650 -     * @throws ClassCastException if the array contains elements that are
  71.651 -     *         not <i>mutually comparable</i> using the specified comparator
  71.652 -     * @throws IllegalArgumentException (optional) if the comparator is
  71.653 -     *         found to violate the {@link Comparator} contract
  71.654 -     */
  71.655 -    public static <T> void sort(T[] a, Comparator<? super T> c) {
  71.656 -        if (LegacyMergeSort.userRequested)
  71.657 -            legacyMergeSort(a, c);
  71.658 -        else
  71.659 -            TimSort.sort(a, c);
  71.660 -    }
  71.661 -
  71.662 -    /** To be removed in a future release. */
  71.663 -    private static <T> void legacyMergeSort(T[] a, Comparator<? super T> c) {
  71.664 -        T[] aux = a.clone();
  71.665 -        if (c==null)
  71.666 -            mergeSort(aux, a, 0, a.length, 0);
  71.667 -        else
  71.668 -            mergeSort(aux, a, 0, a.length, 0, c);
  71.669 -    }
  71.670 -
  71.671 -    /**
  71.672 -     * Sorts the specified range of the specified array of objects according
  71.673 -     * to the order induced by the specified comparator.  The range to be
  71.674 -     * sorted extends from index {@code fromIndex}, inclusive, to index
  71.675 -     * {@code toIndex}, exclusive.  (If {@code fromIndex==toIndex}, the
  71.676 -     * range to be sorted is empty.)  All elements in the range must be
  71.677 -     * <i>mutually comparable</i> by the specified comparator (that is,
  71.678 -     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
  71.679 -     * for any elements {@code e1} and {@code e2} in the range).
  71.680 -     *
  71.681 -     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  71.682 -     * not be reordered as a result of the sort.
  71.683 -     *
  71.684 -     * <p>Implementation note: This implementation is a stable, adaptive,
  71.685 -     * iterative mergesort that requires far fewer than n lg(n) comparisons
  71.686 -     * when the input array is partially sorted, while offering the
  71.687 -     * performance of a traditional mergesort when the input array is
  71.688 -     * randomly ordered.  If the input array is nearly sorted, the
  71.689 -     * implementation requires approximately n comparisons.  Temporary
  71.690 -     * storage requirements vary from a small constant for nearly sorted
  71.691 -     * input arrays to n/2 object references for randomly ordered input
  71.692 -     * arrays.
  71.693 -     *
  71.694 -     * <p>The implementation takes equal advantage of ascending and
  71.695 -     * descending order in its input array, and can take advantage of
  71.696 -     * ascending and descending order in different parts of the the same
  71.697 -     * input array.  It is well-suited to merging two or more sorted arrays:
  71.698 -     * simply concatenate the arrays and sort the resulting array.
  71.699 -     *
  71.700 -     * <p>The implementation was adapted from Tim Peters's list sort for Python
  71.701 -     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  71.702 -     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  71.703 -     * Sorting and Information Theoretic Complexity", in Proceedings of the
  71.704 -     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  71.705 -     * January 1993.
  71.706 -     *
  71.707 -     * @param a the array to be sorted
  71.708 -     * @param fromIndex the index of the first element (inclusive) to be
  71.709 -     *        sorted
  71.710 -     * @param toIndex the index of the last element (exclusive) to be sorted
  71.711 -     * @param c the comparator to determine the order of the array.  A
  71.712 -     *        {@code null} value indicates that the elements'
  71.713 -     *        {@linkplain Comparable natural ordering} should be used.
  71.714 -     * @throws ClassCastException if the array contains elements that are not
  71.715 -     *         <i>mutually comparable</i> using the specified comparator.
  71.716 -     * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
  71.717 -     *         (optional) if the comparator is found to violate the
  71.718 -     *         {@link Comparator} contract
  71.719 -     * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
  71.720 -     *         {@code toIndex > a.length}
  71.721 -     */
  71.722 -    public static <T> void sort(T[] a, int fromIndex, int toIndex,
  71.723 -                                Comparator<? super T> c) {
  71.724 -        if (LegacyMergeSort.userRequested)
  71.725 -            legacyMergeSort(a, fromIndex, toIndex, c);
  71.726 -        else
  71.727 -            TimSort.sort(a, fromIndex, toIndex, c);
  71.728 -    }
  71.729 -
  71.730 -    /** To be removed in a future release. */
  71.731 -    private static <T> void legacyMergeSort(T[] a, int fromIndex, int toIndex,
  71.732 -                                            Comparator<? super T> c) {
  71.733 -        rangeCheck(a.length, fromIndex, toIndex);
  71.734 -        T[] aux = copyOfRange(a, fromIndex, toIndex);
  71.735 -        if (c==null)
  71.736 -            mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
  71.737 -        else
  71.738 -            mergeSort(aux, a, fromIndex, toIndex, -fromIndex, c);
  71.739 -    }
  71.740 -
  71.741 -    /**
  71.742 -     * Src is the source array that starts at index 0
  71.743 -     * Dest is the (possibly larger) array destination with a possible offset
  71.744 -     * low is the index in dest to start sorting
  71.745 -     * high is the end index in dest to end sorting
  71.746 -     * off is the offset into src corresponding to low in dest
  71.747 -     * To be removed in a future release.
  71.748 -     */
  71.749 -    private static void mergeSort(Object[] src,
  71.750 -                                  Object[] dest,
  71.751 -                                  int low, int high, int off,
  71.752 -                                  Comparator c) {
  71.753 -        int length = high - low;
  71.754 -
  71.755 -        // Insertion sort on smallest arrays
  71.756 -        if (length < INSERTIONSORT_THRESHOLD) {
  71.757 -            for (int i=low; i<high; i++)
  71.758 -                for (int j=i; j>low && c.compare(dest[j-1], dest[j])>0; j--)
  71.759 -                    swap(dest, j, j-1);
  71.760 -            return;
  71.761 -        }
  71.762 -
  71.763 -        // Recursively sort halves of dest into src
  71.764 -        int destLow  = low;
  71.765 -        int destHigh = high;
  71.766 -        low  += off;
  71.767 -        high += off;
  71.768 -        int mid = (low + high) >>> 1;
  71.769 -        mergeSort(dest, src, low, mid, -off, c);
  71.770 -        mergeSort(dest, src, mid, high, -off, c);
  71.771 -
  71.772 -        // If list is already sorted, just copy from src to dest.  This is an
  71.773 -        // optimization that results in faster sorts for nearly ordered lists.
  71.774 -        if (c.compare(src[mid-1], src[mid]) <= 0) {
  71.775 -           System.arraycopy(src, low, dest, destLow, length);
  71.776 -           return;
  71.777 -        }
  71.778 -
  71.779 -        // Merge sorted halves (now in src) into dest
  71.780 -        for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
  71.781 -            if (q >= high || p < mid && c.compare(src[p], src[q]) <= 0)
  71.782 -                dest[i] = src[p++];
  71.783 -            else
  71.784 -                dest[i] = src[q++];
  71.785 -        }
  71.786 -    }
  71.787 -
  71.788 -    /**
  71.789 -     * Checks that {@code fromIndex} and {@code toIndex} are in
  71.790 -     * the range and throws an appropriate exception, if they aren't.
  71.791 -     */
  71.792 -    private static void rangeCheck(int length, int fromIndex, int toIndex) {
  71.793 -        if (fromIndex > toIndex) {
  71.794 -            throw new IllegalArgumentException(
  71.795 -                "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
  71.796 -        }
  71.797 -        if (fromIndex < 0) {
  71.798 -            throw new ArrayIndexOutOfBoundsException(fromIndex);
  71.799 -        }
  71.800 -        if (toIndex > length) {
  71.801 -            throw new ArrayIndexOutOfBoundsException(toIndex);
  71.802 -        }
  71.803 -    }
  71.804 -
  71.805 -    // Searching
  71.806 -
  71.807 -    /**
  71.808 -     * Searches the specified array of longs for the specified value using the
  71.809 -     * binary search algorithm.  The array must be sorted (as
  71.810 -     * by the {@link #sort(long[])} method) prior to making this call.  If it
  71.811 -     * is not sorted, the results are undefined.  If the array contains
  71.812 -     * multiple elements with the specified value, there is no guarantee which
  71.813 -     * one will be found.
  71.814 -     *
  71.815 -     * @param a the array to be searched
  71.816 -     * @param key the value to be searched for
  71.817 -     * @return index of the search key, if it is contained in the array;
  71.818 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  71.819 -     *         <i>insertion point</i> is defined as the point at which the
  71.820 -     *         key would be inserted into the array: the index of the first
  71.821 -     *         element greater than the key, or <tt>a.length</tt> if all
  71.822 -     *         elements in the array are less than the specified key.  Note
  71.823 -     *         that this guarantees that the return value will be &gt;= 0 if
  71.824 -     *         and only if the key is found.
  71.825 -     */
  71.826 -    public static int binarySearch(long[] a, long key) {
  71.827 -        return binarySearch0(a, 0, a.length, key);
  71.828 -    }
  71.829 -
  71.830 -    /**
  71.831 -     * Searches a range of
  71.832 -     * the specified array of longs for the specified value using the
  71.833 -     * binary search algorithm.
  71.834 -     * The range must be sorted (as
  71.835 -     * by the {@link #sort(long[], int, int)} method)
  71.836 -     * prior to making this call.  If it
  71.837 -     * is not sorted, the results are undefined.  If the range contains
  71.838 -     * multiple elements with the specified value, there is no guarantee which
  71.839 -     * one will be found.
  71.840 -     *
  71.841 -     * @param a the array to be searched
  71.842 -     * @param fromIndex the index of the first element (inclusive) to be
  71.843 -     *          searched
  71.844 -     * @param toIndex the index of the last element (exclusive) to be searched
  71.845 -     * @param key the value to be searched for
  71.846 -     * @return index of the search key, if it is contained in the array
  71.847 -     *         within the specified range;
  71.848 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  71.849 -     *         <i>insertion point</i> is defined as the point at which the
  71.850 -     *         key would be inserted into the array: the index of the first
  71.851 -     *         element in the range greater than the key,
  71.852 -     *         or <tt>toIndex</tt> if all
  71.853 -     *         elements in the range are less than the specified key.  Note
  71.854 -     *         that this guarantees that the return value will be &gt;= 0 if
  71.855 -     *         and only if the key is found.
  71.856 -     * @throws IllegalArgumentException
  71.857 -     *         if {@code fromIndex > toIndex}
  71.858 -     * @throws ArrayIndexOutOfBoundsException
  71.859 -     *         if {@code fromIndex < 0 or toIndex > a.length}
  71.860 -     * @since 1.6
  71.861 -     */
  71.862 -    public static int binarySearch(long[] a, int fromIndex, int toIndex,
  71.863 -                                   long key) {
  71.864 -        rangeCheck(a.length, fromIndex, toIndex);
  71.865 -        return binarySearch0(a, fromIndex, toIndex, key);
  71.866 -    }
  71.867 -
  71.868 -    // Like public version, but without range checks.
  71.869 -    private static int binarySearch0(long[] a, int fromIndex, int toIndex,
  71.870 -                                     long key) {
  71.871 -        int low = fromIndex;
  71.872 -        int high = toIndex - 1;
  71.873 -
  71.874 -        while (low <= high) {
  71.875 -            int mid = (low + high) >>> 1;
  71.876 -            long midVal = a[mid];
  71.877 -
  71.878 -            if (midVal < key)
  71.879 -                low = mid + 1;
  71.880 -            else if (midVal > key)
  71.881 -                high = mid - 1;
  71.882 -            else
  71.883 -                return mid; // key found
  71.884 -        }
  71.885 -        return -(low + 1);  // key not found.
  71.886 -    }
  71.887 -
  71.888 -    /**
  71.889 -     * Searches the specified array of ints for the specified value using the
  71.890 -     * binary search algorithm.  The array must be sorted (as
  71.891 -     * by the {@link #sort(int[])} method) prior to making this call.  If it
  71.892 -     * is not sorted, the results are undefined.  If the array contains
  71.893 -     * multiple elements with the specified value, there is no guarantee which
  71.894 -     * one will be found.
  71.895 -     *
  71.896 -     * @param a the array to be searched
  71.897 -     * @param key the value to be searched for
  71.898 -     * @return index of the search key, if it is contained in the array;
  71.899 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  71.900 -     *         <i>insertion point</i> is defined as the point at which the
  71.901 -     *         key would be inserted into the array: the index of the first
  71.902 -     *         element greater than the key, or <tt>a.length</tt> if all
  71.903 -     *         elements in the array are less than the specified key.  Note
  71.904 -     *         that this guarantees that the return value will be &gt;= 0 if
  71.905 -     *         and only if the key is found.
  71.906 -     */
  71.907 -    public static int binarySearch(int[] a, int key) {
  71.908 -        return binarySearch0(a, 0, a.length, key);
  71.909 -    }
  71.910 -
  71.911 -    /**
  71.912 -     * Searches a range of
  71.913 -     * the specified array of ints for the specified value using the
  71.914 -     * binary search algorithm.
  71.915 -     * The range must be sorted (as
  71.916 -     * by the {@link #sort(int[], int, int)} method)
  71.917 -     * prior to making this call.  If it
  71.918 -     * is not sorted, the results are undefined.  If the range contains
  71.919 -     * multiple elements with the specified value, there is no guarantee which
  71.920 -     * one will be found.
  71.921 -     *
  71.922 -     * @param a the array to be searched
  71.923 -     * @param fromIndex the index of the first element (inclusive) to be
  71.924 -     *          searched
  71.925 -     * @param toIndex the index of the last element (exclusive) to be searched
  71.926 -     * @param key the value to be searched for
  71.927 -     * @return index of the search key, if it is contained in the array
  71.928 -     *         within the specified range;
  71.929 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  71.930 -     *         <i>insertion point</i> is defined as the point at which the
  71.931 -     *         key would be inserted into the array: the index of the first
  71.932 -     *         element in the range greater than the key,
  71.933 -     *         or <tt>toIndex</tt> if all
  71.934 -     *         elements in the range are less than the specified key.  Note
  71.935 -     *         that this guarantees that the return value will be &gt;= 0 if
  71.936 -     *         and only if the key is found.
  71.937 -     * @throws IllegalArgumentException
  71.938 -     *         if {@code fromIndex > toIndex}
  71.939 -     * @throws ArrayIndexOutOfBoundsException
  71.940 -     *         if {@code fromIndex < 0 or toIndex > a.length}
  71.941 -     * @since 1.6
  71.942 -     */
  71.943 -    public static int binarySearch(int[] a, int fromIndex, int toIndex,
  71.944 -                                   int key) {
  71.945 -        rangeCheck(a.length, fromIndex, toIndex);
  71.946 -        return binarySearch0(a, fromIndex, toIndex, key);
  71.947 -    }
  71.948 -
  71.949 -    // Like public version, but without range checks.
  71.950 -    private static int binarySearch0(int[] a, int fromIndex, int toIndex,
  71.951 -                                     int key) {
  71.952 -        int low = fromIndex;
  71.953 -        int high = toIndex - 1;
  71.954 -
  71.955 -        while (low <= high) {
  71.956 -            int mid = (low + high) >>> 1;
  71.957 -            int midVal = a[mid];
  71.958 -
  71.959 -            if (midVal < key)
  71.960 -                low = mid + 1;
  71.961 -            else if (midVal > key)
  71.962 -                high = mid - 1;
  71.963 -            else
  71.964 -                return mid; // key found
  71.965 -        }
  71.966 -        return -(low + 1);  // key not found.
  71.967 -    }
  71.968 -
  71.969 -    /**
  71.970 -     * Searches the specified array of shorts for the specified value using
  71.971 -     * the binary search algorithm.  The array must be sorted
  71.972 -     * (as by the {@link #sort(short[])} method) prior to making this call.  If
  71.973 -     * it is not sorted, the results are undefined.  If the array contains
  71.974 -     * multiple elements with the specified value, there is no guarantee which
  71.975 -     * one will be found.
  71.976 -     *
  71.977 -     * @param a the array to be searched
  71.978 -     * @param key the value to be searched for
  71.979 -     * @return index of the search key, if it is contained in the array;
  71.980 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  71.981 -     *         <i>insertion point</i> is defined as the point at which the
  71.982 -     *         key would be inserted into the array: the index of the first
  71.983 -     *         element greater than the key, or <tt>a.length</tt> if all
  71.984 -     *         elements in the array are less than the specified key.  Note
  71.985 -     *         that this guarantees that the return value will be &gt;= 0 if
  71.986 -     *         and only if the key is found.
  71.987 -     */
  71.988 -    public static int binarySearch(short[] a, short key) {
  71.989 -        return binarySearch0(a, 0, a.length, key);
  71.990 -    }
  71.991 -
  71.992 -    /**
  71.993 -     * Searches a range of
  71.994 -     * the specified array of shorts for the specified value using
  71.995 -     * the binary search algorithm.
  71.996 -     * The range must be sorted
  71.997 -     * (as by the {@link #sort(short[], int, int)} method)
  71.998 -     * prior to making this call.  If
  71.999 -     * it is not sorted, the results are undefined.  If the range contains
 71.1000 -     * multiple elements with the specified value, there is no guarantee which
 71.1001 -     * one will be found.
 71.1002 -     *
 71.1003 -     * @param a the array to be searched
 71.1004 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1005 -     *          searched
 71.1006 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1007 -     * @param key the value to be searched for
 71.1008 -     * @return index of the search key, if it is contained in the array
 71.1009 -     *         within the specified range;
 71.1010 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1011 -     *         <i>insertion point</i> is defined as the point at which the
 71.1012 -     *         key would be inserted into the array: the index of the first
 71.1013 -     *         element in the range greater than the key,
 71.1014 -     *         or <tt>toIndex</tt> if all
 71.1015 -     *         elements in the range are less than the specified key.  Note
 71.1016 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1017 -     *         and only if the key is found.
 71.1018 -     * @throws IllegalArgumentException
 71.1019 -     *         if {@code fromIndex > toIndex}
 71.1020 -     * @throws ArrayIndexOutOfBoundsException
 71.1021 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1022 -     * @since 1.6
 71.1023 -     */
 71.1024 -    public static int binarySearch(short[] a, int fromIndex, int toIndex,
 71.1025 -                                   short key) {
 71.1026 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1027 -        return binarySearch0(a, fromIndex, toIndex, key);
 71.1028 -    }
 71.1029 -
 71.1030 -    // Like public version, but without range checks.
 71.1031 -    private static int binarySearch0(short[] a, int fromIndex, int toIndex,
 71.1032 -                                     short key) {
 71.1033 -        int low = fromIndex;
 71.1034 -        int high = toIndex - 1;
 71.1035 -
 71.1036 -        while (low <= high) {
 71.1037 -            int mid = (low + high) >>> 1;
 71.1038 -            short midVal = a[mid];
 71.1039 -
 71.1040 -            if (midVal < key)
 71.1041 -                low = mid + 1;
 71.1042 -            else if (midVal > key)
 71.1043 -                high = mid - 1;
 71.1044 -            else
 71.1045 -                return mid; // key found
 71.1046 -        }
 71.1047 -        return -(low + 1);  // key not found.
 71.1048 -    }
 71.1049 -
 71.1050 -    /**
 71.1051 -     * Searches the specified array of chars for the specified value using the
 71.1052 -     * binary search algorithm.  The array must be sorted (as
 71.1053 -     * by the {@link #sort(char[])} method) prior to making this call.  If it
 71.1054 -     * is not sorted, the results are undefined.  If the array contains
 71.1055 -     * multiple elements with the specified value, there is no guarantee which
 71.1056 -     * one will be found.
 71.1057 -     *
 71.1058 -     * @param a the array to be searched
 71.1059 -     * @param key the value to be searched for
 71.1060 -     * @return index of the search key, if it is contained in the array;
 71.1061 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1062 -     *         <i>insertion point</i> is defined as the point at which the
 71.1063 -     *         key would be inserted into the array: the index of the first
 71.1064 -     *         element greater than the key, or <tt>a.length</tt> if all
 71.1065 -     *         elements in the array are less than the specified key.  Note
 71.1066 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1067 -     *         and only if the key is found.
 71.1068 -     */
 71.1069 -    public static int binarySearch(char[] a, char key) {
 71.1070 -        return binarySearch0(a, 0, a.length, key);
 71.1071 -    }
 71.1072 -
 71.1073 -    /**
 71.1074 -     * Searches a range of
 71.1075 -     * the specified array of chars for the specified value using the
 71.1076 -     * binary search algorithm.
 71.1077 -     * The range must be sorted (as
 71.1078 -     * by the {@link #sort(char[], int, int)} method)
 71.1079 -     * prior to making this call.  If it
 71.1080 -     * is not sorted, the results are undefined.  If the range contains
 71.1081 -     * multiple elements with the specified value, there is no guarantee which
 71.1082 -     * one will be found.
 71.1083 -     *
 71.1084 -     * @param a the array to be searched
 71.1085 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1086 -     *          searched
 71.1087 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1088 -     * @param key the value to be searched for
 71.1089 -     * @return index of the search key, if it is contained in the array
 71.1090 -     *         within the specified range;
 71.1091 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1092 -     *         <i>insertion point</i> is defined as the point at which the
 71.1093 -     *         key would be inserted into the array: the index of the first
 71.1094 -     *         element in the range greater than the key,
 71.1095 -     *         or <tt>toIndex</tt> if all
 71.1096 -     *         elements in the range are less than the specified key.  Note
 71.1097 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1098 -     *         and only if the key is found.
 71.1099 -     * @throws IllegalArgumentException
 71.1100 -     *         if {@code fromIndex > toIndex}
 71.1101 -     * @throws ArrayIndexOutOfBoundsException
 71.1102 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1103 -     * @since 1.6
 71.1104 -     */
 71.1105 -    public static int binarySearch(char[] a, int fromIndex, int toIndex,
 71.1106 -                                   char key) {
 71.1107 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1108 -        return binarySearch0(a, fromIndex, toIndex, key);
 71.1109 -    }
 71.1110 -
 71.1111 -    // Like public version, but without range checks.
 71.1112 -    private static int binarySearch0(char[] a, int fromIndex, int toIndex,
 71.1113 -                                     char key) {
 71.1114 -        int low = fromIndex;
 71.1115 -        int high = toIndex - 1;
 71.1116 -
 71.1117 -        while (low <= high) {
 71.1118 -            int mid = (low + high) >>> 1;
 71.1119 -            char midVal = a[mid];
 71.1120 -
 71.1121 -            if (midVal < key)
 71.1122 -                low = mid + 1;
 71.1123 -            else if (midVal > key)
 71.1124 -                high = mid - 1;
 71.1125 -            else
 71.1126 -                return mid; // key found
 71.1127 -        }
 71.1128 -        return -(low + 1);  // key not found.
 71.1129 -    }
 71.1130 -
 71.1131 -    /**
 71.1132 -     * Searches the specified array of bytes for the specified value using the
 71.1133 -     * binary search algorithm.  The array must be sorted (as
 71.1134 -     * by the {@link #sort(byte[])} method) prior to making this call.  If it
 71.1135 -     * is not sorted, the results are undefined.  If the array contains
 71.1136 -     * multiple elements with the specified value, there is no guarantee which
 71.1137 -     * one will be found.
 71.1138 -     *
 71.1139 -     * @param a the array to be searched
 71.1140 -     * @param key the value to be searched for
 71.1141 -     * @return index of the search key, if it is contained in the array;
 71.1142 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1143 -     *         <i>insertion point</i> is defined as the point at which the
 71.1144 -     *         key would be inserted into the array: the index of the first
 71.1145 -     *         element greater than the key, or <tt>a.length</tt> if all
 71.1146 -     *         elements in the array are less than the specified key.  Note
 71.1147 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1148 -     *         and only if the key is found.
 71.1149 -     */
 71.1150 -    public static int binarySearch(byte[] a, byte key) {
 71.1151 -        return binarySearch0(a, 0, a.length, key);
 71.1152 -    }
 71.1153 -
 71.1154 -    /**
 71.1155 -     * Searches a range of
 71.1156 -     * the specified array of bytes for the specified value using the
 71.1157 -     * binary search algorithm.
 71.1158 -     * The range must be sorted (as
 71.1159 -     * by the {@link #sort(byte[], int, int)} method)
 71.1160 -     * prior to making this call.  If it
 71.1161 -     * is not sorted, the results are undefined.  If the range contains
 71.1162 -     * multiple elements with the specified value, there is no guarantee which
 71.1163 -     * one will be found.
 71.1164 -     *
 71.1165 -     * @param a the array to be searched
 71.1166 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1167 -     *          searched
 71.1168 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1169 -     * @param key the value to be searched for
 71.1170 -     * @return index of the search key, if it is contained in the array
 71.1171 -     *         within the specified range;
 71.1172 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1173 -     *         <i>insertion point</i> is defined as the point at which the
 71.1174 -     *         key would be inserted into the array: the index of the first
 71.1175 -     *         element in the range greater than the key,
 71.1176 -     *         or <tt>toIndex</tt> if all
 71.1177 -     *         elements in the range are less than the specified key.  Note
 71.1178 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1179 -     *         and only if the key is found.
 71.1180 -     * @throws IllegalArgumentException
 71.1181 -     *         if {@code fromIndex > toIndex}
 71.1182 -     * @throws ArrayIndexOutOfBoundsException
 71.1183 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1184 -     * @since 1.6
 71.1185 -     */
 71.1186 -    public static int binarySearch(byte[] a, int fromIndex, int toIndex,
 71.1187 -                                   byte key) {
 71.1188 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1189 -        return binarySearch0(a, fromIndex, toIndex, key);
 71.1190 -    }
 71.1191 -
 71.1192 -    // Like public version, but without range checks.
 71.1193 -    private static int binarySearch0(byte[] a, int fromIndex, int toIndex,
 71.1194 -                                     byte key) {
 71.1195 -        int low = fromIndex;
 71.1196 -        int high = toIndex - 1;
 71.1197 -
 71.1198 -        while (low <= high) {
 71.1199 -            int mid = (low + high) >>> 1;
 71.1200 -            byte midVal = a[mid];
 71.1201 -
 71.1202 -            if (midVal < key)
 71.1203 -                low = mid + 1;
 71.1204 -            else if (midVal > key)
 71.1205 -                high = mid - 1;
 71.1206 -            else
 71.1207 -                return mid; // key found
 71.1208 -        }
 71.1209 -        return -(low + 1);  // key not found.
 71.1210 -    }
 71.1211 -
 71.1212 -    /**
 71.1213 -     * Searches the specified array of doubles for the specified value using
 71.1214 -     * the binary search algorithm.  The array must be sorted
 71.1215 -     * (as by the {@link #sort(double[])} method) prior to making this call.
 71.1216 -     * If it is not sorted, the results are undefined.  If the array contains
 71.1217 -     * multiple elements with the specified value, there is no guarantee which
 71.1218 -     * one will be found.  This method considers all NaN values to be
 71.1219 -     * equivalent and equal.
 71.1220 -     *
 71.1221 -     * @param a the array to be searched
 71.1222 -     * @param key the value to be searched for
 71.1223 -     * @return index of the search key, if it is contained in the array;
 71.1224 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1225 -     *         <i>insertion point</i> is defined as the point at which the
 71.1226 -     *         key would be inserted into the array: the index of the first
 71.1227 -     *         element greater than the key, or <tt>a.length</tt> if all
 71.1228 -     *         elements in the array are less than the specified key.  Note
 71.1229 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1230 -     *         and only if the key is found.
 71.1231 -     */
 71.1232 -    public static int binarySearch(double[] a, double key) {
 71.1233 -        return binarySearch0(a, 0, a.length, key);
 71.1234 -    }
 71.1235 -
 71.1236 -    /**
 71.1237 -     * Searches a range of
 71.1238 -     * the specified array of doubles for the specified value using
 71.1239 -     * the binary search algorithm.
 71.1240 -     * The range must be sorted
 71.1241 -     * (as by the {@link #sort(double[], int, int)} method)
 71.1242 -     * prior to making this call.
 71.1243 -     * If it is not sorted, the results are undefined.  If the range contains
 71.1244 -     * multiple elements with the specified value, there is no guarantee which
 71.1245 -     * one will be found.  This method considers all NaN values to be
 71.1246 -     * equivalent and equal.
 71.1247 -     *
 71.1248 -     * @param a the array to be searched
 71.1249 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1250 -     *          searched
 71.1251 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1252 -     * @param key the value to be searched for
 71.1253 -     * @return index of the search key, if it is contained in the array
 71.1254 -     *         within the specified range;
 71.1255 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1256 -     *         <i>insertion point</i> is defined as the point at which the
 71.1257 -     *         key would be inserted into the array: the index of the first
 71.1258 -     *         element in the range greater than the key,
 71.1259 -     *         or <tt>toIndex</tt> if all
 71.1260 -     *         elements in the range are less than the specified key.  Note
 71.1261 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1262 -     *         and only if the key is found.
 71.1263 -     * @throws IllegalArgumentException
 71.1264 -     *         if {@code fromIndex > toIndex}
 71.1265 -     * @throws ArrayIndexOutOfBoundsException
 71.1266 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1267 -     * @since 1.6
 71.1268 -     */
 71.1269 -    public static int binarySearch(double[] a, int fromIndex, int toIndex,
 71.1270 -                                   double key) {
 71.1271 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1272 -        return binarySearch0(a, fromIndex, toIndex, key);
 71.1273 -    }
 71.1274 -
 71.1275 -    // Like public version, but without range checks.
 71.1276 -    private static int binarySearch0(double[] a, int fromIndex, int toIndex,
 71.1277 -                                     double key) {
 71.1278 -        int low = fromIndex;
 71.1279 -        int high = toIndex - 1;
 71.1280 -
 71.1281 -        while (low <= high) {
 71.1282 -            int mid = (low + high) >>> 1;
 71.1283 -            double midVal = a[mid];
 71.1284 -
 71.1285 -            if (midVal < key)
 71.1286 -                low = mid + 1;  // Neither val is NaN, thisVal is smaller
 71.1287 -            else if (midVal > key)
 71.1288 -                high = mid - 1; // Neither val is NaN, thisVal is larger
 71.1289 -            else {
 71.1290 -                long midBits = Double.doubleToLongBits(midVal);
 71.1291 -                long keyBits = Double.doubleToLongBits(key);
 71.1292 -                if (midBits == keyBits)     // Values are equal
 71.1293 -                    return mid;             // Key found
 71.1294 -                else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
 71.1295 -                    low = mid + 1;
 71.1296 -                else                        // (0.0, -0.0) or (NaN, !NaN)
 71.1297 -                    high = mid - 1;
 71.1298 -            }
 71.1299 -        }
 71.1300 -        return -(low + 1);  // key not found.
 71.1301 -    }
 71.1302 -
 71.1303 -    /**
 71.1304 -     * Searches the specified array of floats for the specified value using
 71.1305 -     * the binary search algorithm. The array must be sorted
 71.1306 -     * (as by the {@link #sort(float[])} method) prior to making this call. If
 71.1307 -     * it is not sorted, the results are undefined. If the array contains
 71.1308 -     * multiple elements with the specified value, there is no guarantee which
 71.1309 -     * one will be found. This method considers all NaN values to be
 71.1310 -     * equivalent and equal.
 71.1311 -     *
 71.1312 -     * @param a the array to be searched
 71.1313 -     * @param key the value to be searched for
 71.1314 -     * @return index of the search key, if it is contained in the array;
 71.1315 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The
 71.1316 -     *         <i>insertion point</i> is defined as the point at which the
 71.1317 -     *         key would be inserted into the array: the index of the first
 71.1318 -     *         element greater than the key, or <tt>a.length</tt> if all
 71.1319 -     *         elements in the array are less than the specified key. Note
 71.1320 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1321 -     *         and only if the key is found.
 71.1322 -     */
 71.1323 -    public static int binarySearch(float[] a, float key) {
 71.1324 -        return binarySearch0(a, 0, a.length, key);
 71.1325 -    }
 71.1326 -
 71.1327 -    /**
 71.1328 -     * Searches a range of
 71.1329 -     * the specified array of floats for the specified value using
 71.1330 -     * the binary search algorithm.
 71.1331 -     * The range must be sorted
 71.1332 -     * (as by the {@link #sort(float[], int, int)} method)
 71.1333 -     * prior to making this call. If
 71.1334 -     * it is not sorted, the results are undefined. If the range contains
 71.1335 -     * multiple elements with the specified value, there is no guarantee which
 71.1336 -     * one will be found. This method considers all NaN values to be
 71.1337 -     * equivalent and equal.
 71.1338 -     *
 71.1339 -     * @param a the array to be searched
 71.1340 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1341 -     *          searched
 71.1342 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1343 -     * @param key the value to be searched for
 71.1344 -     * @return index of the search key, if it is contained in the array
 71.1345 -     *         within the specified range;
 71.1346 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The
 71.1347 -     *         <i>insertion point</i> is defined as the point at which the
 71.1348 -     *         key would be inserted into the array: the index of the first
 71.1349 -     *         element in the range greater than the key,
 71.1350 -     *         or <tt>toIndex</tt> if all
 71.1351 -     *         elements in the range are less than the specified key. Note
 71.1352 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1353 -     *         and only if the key is found.
 71.1354 -     * @throws IllegalArgumentException
 71.1355 -     *         if {@code fromIndex > toIndex}
 71.1356 -     * @throws ArrayIndexOutOfBoundsException
 71.1357 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1358 -     * @since 1.6
 71.1359 -     */
 71.1360 -    public static int binarySearch(float[] a, int fromIndex, int toIndex,
 71.1361 -                                   float key) {
 71.1362 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1363 -        return binarySearch0(a, fromIndex, toIndex, key);
 71.1364 -    }
 71.1365 -
 71.1366 -    // Like public version, but without range checks.
 71.1367 -    private static int binarySearch0(float[] a, int fromIndex, int toIndex,
 71.1368 -                                     float key) {
 71.1369 -        int low = fromIndex;
 71.1370 -        int high = toIndex - 1;
 71.1371 -
 71.1372 -        while (low <= high) {
 71.1373 -            int mid = (low + high) >>> 1;
 71.1374 -            float midVal = a[mid];
 71.1375 -
 71.1376 -            if (midVal < key)
 71.1377 -                low = mid + 1;  // Neither val is NaN, thisVal is smaller
 71.1378 -            else if (midVal > key)
 71.1379 -                high = mid - 1; // Neither val is NaN, thisVal is larger
 71.1380 -            else {
 71.1381 -                int midBits = Float.floatToIntBits(midVal);
 71.1382 -                int keyBits = Float.floatToIntBits(key);
 71.1383 -                if (midBits == keyBits)     // Values are equal
 71.1384 -                    return mid;             // Key found
 71.1385 -                else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
 71.1386 -                    low = mid + 1;
 71.1387 -                else                        // (0.0, -0.0) or (NaN, !NaN)
 71.1388 -                    high = mid - 1;
 71.1389 -            }
 71.1390 -        }
 71.1391 -        return -(low + 1);  // key not found.
 71.1392 -    }
 71.1393 -
 71.1394 -    /**
 71.1395 -     * Searches the specified array for the specified object using the binary
 71.1396 -     * search algorithm. The array must be sorted into ascending order
 71.1397 -     * according to the
 71.1398 -     * {@linkplain Comparable natural ordering}
 71.1399 -     * of its elements (as by the
 71.1400 -     * {@link #sort(Object[])} method) prior to making this call.
 71.1401 -     * If it is not sorted, the results are undefined.
 71.1402 -     * (If the array contains elements that are not mutually comparable (for
 71.1403 -     * example, strings and integers), it <i>cannot</i> be sorted according
 71.1404 -     * to the natural ordering of its elements, hence results are undefined.)
 71.1405 -     * If the array contains multiple
 71.1406 -     * elements equal to the specified object, there is no guarantee which
 71.1407 -     * one will be found.
 71.1408 -     *
 71.1409 -     * @param a the array to be searched
 71.1410 -     * @param key the value to be searched for
 71.1411 -     * @return index of the search key, if it is contained in the array;
 71.1412 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1413 -     *         <i>insertion point</i> is defined as the point at which the
 71.1414 -     *         key would be inserted into the array: the index of the first
 71.1415 -     *         element greater than the key, or <tt>a.length</tt> if all
 71.1416 -     *         elements in the array are less than the specified key.  Note
 71.1417 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1418 -     *         and only if the key is found.
 71.1419 -     * @throws ClassCastException if the search key is not comparable to the
 71.1420 -     *         elements of the array.
 71.1421 -     */
 71.1422 -    public static int binarySearch(Object[] a, Object key) {
 71.1423 -        return binarySearch0(a, 0, a.length, key);
 71.1424 -    }
 71.1425 -
 71.1426 -    /**
 71.1427 -     * Searches a range of
 71.1428 -     * the specified array for the specified object using the binary
 71.1429 -     * search algorithm.
 71.1430 -     * The range must be sorted into ascending order
 71.1431 -     * according to the
 71.1432 -     * {@linkplain Comparable natural ordering}
 71.1433 -     * of its elements (as by the
 71.1434 -     * {@link #sort(Object[], int, int)} method) prior to making this
 71.1435 -     * call.  If it is not sorted, the results are undefined.
 71.1436 -     * (If the range contains elements that are not mutually comparable (for
 71.1437 -     * example, strings and integers), it <i>cannot</i> be sorted according
 71.1438 -     * to the natural ordering of its elements, hence results are undefined.)
 71.1439 -     * If the range contains multiple
 71.1440 -     * elements equal to the specified object, there is no guarantee which
 71.1441 -     * one will be found.
 71.1442 -     *
 71.1443 -     * @param a the array to be searched
 71.1444 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1445 -     *          searched
 71.1446 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1447 -     * @param key the value to be searched for
 71.1448 -     * @return index of the search key, if it is contained in the array
 71.1449 -     *         within the specified range;
 71.1450 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1451 -     *         <i>insertion point</i> is defined as the point at which the
 71.1452 -     *         key would be inserted into the array: the index of the first
 71.1453 -     *         element in the range greater than the key,
 71.1454 -     *         or <tt>toIndex</tt> if all
 71.1455 -     *         elements in the range are less than the specified key.  Note
 71.1456 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1457 -     *         and only if the key is found.
 71.1458 -     * @throws ClassCastException if the search key is not comparable to the
 71.1459 -     *         elements of the array within the specified range.
 71.1460 -     * @throws IllegalArgumentException
 71.1461 -     *         if {@code fromIndex > toIndex}
 71.1462 -     * @throws ArrayIndexOutOfBoundsException
 71.1463 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1464 -     * @since 1.6
 71.1465 -     */
 71.1466 -    public static int binarySearch(Object[] a, int fromIndex, int toIndex,
 71.1467 -                                   Object key) {
 71.1468 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1469 -        return binarySearch0(a, fromIndex, toIndex, key);
 71.1470 -    }
 71.1471 -
 71.1472 -    // Like public version, but without range checks.
 71.1473 -    private static int binarySearch0(Object[] a, int fromIndex, int toIndex,
 71.1474 -                                     Object key) {
 71.1475 -        int low = fromIndex;
 71.1476 -        int high = toIndex - 1;
 71.1477 -
 71.1478 -        while (low <= high) {
 71.1479 -            int mid = (low + high) >>> 1;
 71.1480 -            Comparable midVal = (Comparable)a[mid];
 71.1481 -            int cmp = midVal.compareTo(key);
 71.1482 -
 71.1483 -            if (cmp < 0)
 71.1484 -                low = mid + 1;
 71.1485 -            else if (cmp > 0)
 71.1486 -                high = mid - 1;
 71.1487 -            else
 71.1488 -                return mid; // key found
 71.1489 -        }
 71.1490 -        return -(low + 1);  // key not found.
 71.1491 -    }
 71.1492 -
 71.1493 -    /**
 71.1494 -     * Searches the specified array for the specified object using the binary
 71.1495 -     * search algorithm.  The array must be sorted into ascending order
 71.1496 -     * according to the specified comparator (as by the
 71.1497 -     * {@link #sort(Object[], Comparator) sort(T[], Comparator)}
 71.1498 -     * method) prior to making this call.  If it is
 71.1499 -     * not sorted, the results are undefined.
 71.1500 -     * If the array contains multiple
 71.1501 -     * elements equal to the specified object, there is no guarantee which one
 71.1502 -     * will be found.
 71.1503 -     *
 71.1504 -     * @param a the array to be searched
 71.1505 -     * @param key the value to be searched for
 71.1506 -     * @param c the comparator by which the array is ordered.  A
 71.1507 -     *        <tt>null</tt> value indicates that the elements'
 71.1508 -     *        {@linkplain Comparable natural ordering} should be used.
 71.1509 -     * @return index of the search key, if it is contained in the array;
 71.1510 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1511 -     *         <i>insertion point</i> is defined as the point at which the
 71.1512 -     *         key would be inserted into the array: the index of the first
 71.1513 -     *         element greater than the key, or <tt>a.length</tt> if all
 71.1514 -     *         elements in the array are less than the specified key.  Note
 71.1515 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1516 -     *         and only if the key is found.
 71.1517 -     * @throws ClassCastException if the array contains elements that are not
 71.1518 -     *         <i>mutually comparable</i> using the specified comparator,
 71.1519 -     *         or the search key is not comparable to the
 71.1520 -     *         elements of the array using this comparator.
 71.1521 -     */
 71.1522 -    public static <T> int binarySearch(T[] a, T key, Comparator<? super T> c) {
 71.1523 -        return binarySearch0(a, 0, a.length, key, c);
 71.1524 -    }
 71.1525 -
 71.1526 -    /**
 71.1527 -     * Searches a range of
 71.1528 -     * the specified array for the specified object using the binary
 71.1529 -     * search algorithm.
 71.1530 -     * The range must be sorted into ascending order
 71.1531 -     * according to the specified comparator (as by the
 71.1532 -     * {@link #sort(Object[], int, int, Comparator)
 71.1533 -     * sort(T[], int, int, Comparator)}
 71.1534 -     * method) prior to making this call.
 71.1535 -     * If it is not sorted, the results are undefined.
 71.1536 -     * If the range contains multiple elements equal to the specified object,
 71.1537 -     * there is no guarantee which one will be found.
 71.1538 -     *
 71.1539 -     * @param a the array to be searched
 71.1540 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1541 -     *          searched
 71.1542 -     * @param toIndex the index of the last element (exclusive) to be searched
 71.1543 -     * @param key the value to be searched for
 71.1544 -     * @param c the comparator by which the array is ordered.  A
 71.1545 -     *        <tt>null</tt> value indicates that the elements'
 71.1546 -     *        {@linkplain Comparable natural ordering} should be used.
 71.1547 -     * @return index of the search key, if it is contained in the array
 71.1548 -     *         within the specified range;
 71.1549 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 71.1550 -     *         <i>insertion point</i> is defined as the point at which the
 71.1551 -     *         key would be inserted into the array: the index of the first
 71.1552 -     *         element in the range greater than the key,
 71.1553 -     *         or <tt>toIndex</tt> if all
 71.1554 -     *         elements in the range are less than the specified key.  Note
 71.1555 -     *         that this guarantees that the return value will be &gt;= 0 if
 71.1556 -     *         and only if the key is found.
 71.1557 -     * @throws ClassCastException if the range contains elements that are not
 71.1558 -     *         <i>mutually comparable</i> using the specified comparator,
 71.1559 -     *         or the search key is not comparable to the
 71.1560 -     *         elements in the range using this comparator.
 71.1561 -     * @throws IllegalArgumentException
 71.1562 -     *         if {@code fromIndex > toIndex}
 71.1563 -     * @throws ArrayIndexOutOfBoundsException
 71.1564 -     *         if {@code fromIndex < 0 or toIndex > a.length}
 71.1565 -     * @since 1.6
 71.1566 -     */
 71.1567 -    public static <T> int binarySearch(T[] a, int fromIndex, int toIndex,
 71.1568 -                                       T key, Comparator<? super T> c) {
 71.1569 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1570 -        return binarySearch0(a, fromIndex, toIndex, key, c);
 71.1571 -    }
 71.1572 -
 71.1573 -    // Like public version, but without range checks.
 71.1574 -    private static <T> int binarySearch0(T[] a, int fromIndex, int toIndex,
 71.1575 -                                         T key, Comparator<? super T> c) {
 71.1576 -        if (c == null) {
 71.1577 -            return binarySearch0(a, fromIndex, toIndex, key);
 71.1578 -        }
 71.1579 -        int low = fromIndex;
 71.1580 -        int high = toIndex - 1;
 71.1581 -
 71.1582 -        while (low <= high) {
 71.1583 -            int mid = (low + high) >>> 1;
 71.1584 -            T midVal = a[mid];
 71.1585 -            int cmp = c.compare(midVal, key);
 71.1586 -            if (cmp < 0)
 71.1587 -                low = mid + 1;
 71.1588 -            else if (cmp > 0)
 71.1589 -                high = mid - 1;
 71.1590 -            else
 71.1591 -                return mid; // key found
 71.1592 -        }
 71.1593 -        return -(low + 1);  // key not found.
 71.1594 -    }
 71.1595 -
 71.1596 -    // Equality Testing
 71.1597 -
 71.1598 -    /**
 71.1599 -     * Returns <tt>true</tt> if the two specified arrays of longs are
 71.1600 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1601 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1602 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1603 -     * are equal if they contain the same elements in the same order.  Also,
 71.1604 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1605 -     *
 71.1606 -     * @param a one array to be tested for equality
 71.1607 -     * @param a2 the other array to be tested for equality
 71.1608 -     * @return <tt>true</tt> if the two arrays are equal
 71.1609 -     */
 71.1610 -    public static boolean equals(long[] a, long[] a2) {
 71.1611 -        if (a==a2)
 71.1612 -            return true;
 71.1613 -        if (a==null || a2==null)
 71.1614 -            return false;
 71.1615 -
 71.1616 -        int length = a.length;
 71.1617 -        if (a2.length != length)
 71.1618 -            return false;
 71.1619 -
 71.1620 -        for (int i=0; i<length; i++)
 71.1621 -            if (a[i] != a2[i])
 71.1622 -                return false;
 71.1623 -
 71.1624 -        return true;
 71.1625 -    }
 71.1626 -
 71.1627 -    /**
 71.1628 -     * Returns <tt>true</tt> if the two specified arrays of ints are
 71.1629 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1630 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1631 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1632 -     * are equal if they contain the same elements in the same order.  Also,
 71.1633 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1634 -     *
 71.1635 -     * @param a one array to be tested for equality
 71.1636 -     * @param a2 the other array to be tested for equality
 71.1637 -     * @return <tt>true</tt> if the two arrays are equal
 71.1638 -     */
 71.1639 -    public static boolean equals(int[] a, int[] a2) {
 71.1640 -        if (a==a2)
 71.1641 -            return true;
 71.1642 -        if (a==null || a2==null)
 71.1643 -            return false;
 71.1644 -
 71.1645 -        int length = a.length;
 71.1646 -        if (a2.length != length)
 71.1647 -            return false;
 71.1648 -
 71.1649 -        for (int i=0; i<length; i++)
 71.1650 -            if (a[i] != a2[i])
 71.1651 -                return false;
 71.1652 -
 71.1653 -        return true;
 71.1654 -    }
 71.1655 -
 71.1656 -    /**
 71.1657 -     * Returns <tt>true</tt> if the two specified arrays of shorts are
 71.1658 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1659 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1660 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1661 -     * are equal if they contain the same elements in the same order.  Also,
 71.1662 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1663 -     *
 71.1664 -     * @param a one array to be tested for equality
 71.1665 -     * @param a2 the other array to be tested for equality
 71.1666 -     * @return <tt>true</tt> if the two arrays are equal
 71.1667 -     */
 71.1668 -    public static boolean equals(short[] a, short a2[]) {
 71.1669 -        if (a==a2)
 71.1670 -            return true;
 71.1671 -        if (a==null || a2==null)
 71.1672 -            return false;
 71.1673 -
 71.1674 -        int length = a.length;
 71.1675 -        if (a2.length != length)
 71.1676 -            return false;
 71.1677 -
 71.1678 -        for (int i=0; i<length; i++)
 71.1679 -            if (a[i] != a2[i])
 71.1680 -                return false;
 71.1681 -
 71.1682 -        return true;
 71.1683 -    }
 71.1684 -
 71.1685 -    /**
 71.1686 -     * Returns <tt>true</tt> if the two specified arrays of chars are
 71.1687 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1688 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1689 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1690 -     * are equal if they contain the same elements in the same order.  Also,
 71.1691 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1692 -     *
 71.1693 -     * @param a one array to be tested for equality
 71.1694 -     * @param a2 the other array to be tested for equality
 71.1695 -     * @return <tt>true</tt> if the two arrays are equal
 71.1696 -     */
 71.1697 -    public static boolean equals(char[] a, char[] a2) {
 71.1698 -        if (a==a2)
 71.1699 -            return true;
 71.1700 -        if (a==null || a2==null)
 71.1701 -            return false;
 71.1702 -
 71.1703 -        int length = a.length;
 71.1704 -        if (a2.length != length)
 71.1705 -            return false;
 71.1706 -
 71.1707 -        for (int i=0; i<length; i++)
 71.1708 -            if (a[i] != a2[i])
 71.1709 -                return false;
 71.1710 -
 71.1711 -        return true;
 71.1712 -    }
 71.1713 -
 71.1714 -    /**
 71.1715 -     * Returns <tt>true</tt> if the two specified arrays of bytes are
 71.1716 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1717 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1718 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1719 -     * are equal if they contain the same elements in the same order.  Also,
 71.1720 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1721 -     *
 71.1722 -     * @param a one array to be tested for equality
 71.1723 -     * @param a2 the other array to be tested for equality
 71.1724 -     * @return <tt>true</tt> if the two arrays are equal
 71.1725 -     */
 71.1726 -    public static boolean equals(byte[] a, byte[] a2) {
 71.1727 -        if (a==a2)
 71.1728 -            return true;
 71.1729 -        if (a==null || a2==null)
 71.1730 -            return false;
 71.1731 -
 71.1732 -        int length = a.length;
 71.1733 -        if (a2.length != length)
 71.1734 -            return false;
 71.1735 -
 71.1736 -        for (int i=0; i<length; i++)
 71.1737 -            if (a[i] != a2[i])
 71.1738 -                return false;
 71.1739 -
 71.1740 -        return true;
 71.1741 -    }
 71.1742 -
 71.1743 -    /**
 71.1744 -     * Returns <tt>true</tt> if the two specified arrays of booleans are
 71.1745 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1746 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1747 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1748 -     * are equal if they contain the same elements in the same order.  Also,
 71.1749 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1750 -     *
 71.1751 -     * @param a one array to be tested for equality
 71.1752 -     * @param a2 the other array to be tested for equality
 71.1753 -     * @return <tt>true</tt> if the two arrays are equal
 71.1754 -     */
 71.1755 -    public static boolean equals(boolean[] a, boolean[] a2) {
 71.1756 -        if (a==a2)
 71.1757 -            return true;
 71.1758 -        if (a==null || a2==null)
 71.1759 -            return false;
 71.1760 -
 71.1761 -        int length = a.length;
 71.1762 -        if (a2.length != length)
 71.1763 -            return false;
 71.1764 -
 71.1765 -        for (int i=0; i<length; i++)
 71.1766 -            if (a[i] != a2[i])
 71.1767 -                return false;
 71.1768 -
 71.1769 -        return true;
 71.1770 -    }
 71.1771 -
 71.1772 -    /**
 71.1773 -     * Returns <tt>true</tt> if the two specified arrays of doubles are
 71.1774 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1775 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1776 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1777 -     * are equal if they contain the same elements in the same order.  Also,
 71.1778 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1779 -     *
 71.1780 -     * Two doubles <tt>d1</tt> and <tt>d2</tt> are considered equal if:
 71.1781 -     * <pre>    <tt>new Double(d1).equals(new Double(d2))</tt></pre>
 71.1782 -     * (Unlike the <tt>==</tt> operator, this method considers
 71.1783 -     * <tt>NaN</tt> equals to itself, and 0.0d unequal to -0.0d.)
 71.1784 -     *
 71.1785 -     * @param a one array to be tested for equality
 71.1786 -     * @param a2 the other array to be tested for equality
 71.1787 -     * @return <tt>true</tt> if the two arrays are equal
 71.1788 -     * @see Double#equals(Object)
 71.1789 -     */
 71.1790 -    public static boolean equals(double[] a, double[] a2) {
 71.1791 -        if (a==a2)
 71.1792 -            return true;
 71.1793 -        if (a==null || a2==null)
 71.1794 -            return false;
 71.1795 -
 71.1796 -        int length = a.length;
 71.1797 -        if (a2.length != length)
 71.1798 -            return false;
 71.1799 -
 71.1800 -        for (int i=0; i<length; i++)
 71.1801 -            if (Double.doubleToLongBits(a[i])!=Double.doubleToLongBits(a2[i]))
 71.1802 -                return false;
 71.1803 -
 71.1804 -        return true;
 71.1805 -    }
 71.1806 -
 71.1807 -    /**
 71.1808 -     * Returns <tt>true</tt> if the two specified arrays of floats are
 71.1809 -     * <i>equal</i> to one another.  Two arrays are considered equal if both
 71.1810 -     * arrays contain the same number of elements, and all corresponding pairs
 71.1811 -     * of elements in the two arrays are equal.  In other words, two arrays
 71.1812 -     * are equal if they contain the same elements in the same order.  Also,
 71.1813 -     * two array references are considered equal if both are <tt>null</tt>.<p>
 71.1814 -     *
 71.1815 -     * Two floats <tt>f1</tt> and <tt>f2</tt> are considered equal if:
 71.1816 -     * <pre>    <tt>new Float(f1).equals(new Float(f2))</tt></pre>
 71.1817 -     * (Unlike the <tt>==</tt> operator, this method considers
 71.1818 -     * <tt>NaN</tt> equals to itself, and 0.0f unequal to -0.0f.)
 71.1819 -     *
 71.1820 -     * @param a one array to be tested for equality
 71.1821 -     * @param a2 the other array to be tested for equality
 71.1822 -     * @return <tt>true</tt> if the two arrays are equal
 71.1823 -     * @see Float#equals(Object)
 71.1824 -     */
 71.1825 -    public static boolean equals(float[] a, float[] a2) {
 71.1826 -        if (a==a2)
 71.1827 -            return true;
 71.1828 -        if (a==null || a2==null)
 71.1829 -            return false;
 71.1830 -
 71.1831 -        int length = a.length;
 71.1832 -        if (a2.length != length)
 71.1833 -            return false;
 71.1834 -
 71.1835 -        for (int i=0; i<length; i++)
 71.1836 -            if (Float.floatToIntBits(a[i])!=Float.floatToIntBits(a2[i]))
 71.1837 -                return false;
 71.1838 -
 71.1839 -        return true;
 71.1840 -    }
 71.1841 -
 71.1842 -    /**
 71.1843 -     * Returns <tt>true</tt> if the two specified arrays of Objects are
 71.1844 -     * <i>equal</i> to one another.  The two arrays are considered equal if
 71.1845 -     * both arrays contain the same number of elements, and all corresponding
 71.1846 -     * pairs of elements in the two arrays are equal.  Two objects <tt>e1</tt>
 71.1847 -     * and <tt>e2</tt> are considered <i>equal</i> if <tt>(e1==null ? e2==null
 71.1848 -     * : e1.equals(e2))</tt>.  In other words, the two arrays are equal if
 71.1849 -     * they contain the same elements in the same order.  Also, two array
 71.1850 -     * references are considered equal if both are <tt>null</tt>.<p>
 71.1851 -     *
 71.1852 -     * @param a one array to be tested for equality
 71.1853 -     * @param a2 the other array to be tested for equality
 71.1854 -     * @return <tt>true</tt> if the two arrays are equal
 71.1855 -     */
 71.1856 -    public static boolean equals(Object[] a, Object[] a2) {
 71.1857 -        if (a==a2)
 71.1858 -            return true;
 71.1859 -        if (a==null || a2==null)
 71.1860 -            return false;
 71.1861 -
 71.1862 -        int length = a.length;
 71.1863 -        if (a2.length != length)
 71.1864 -            return false;
 71.1865 -
 71.1866 -        for (int i=0; i<length; i++) {
 71.1867 -            Object o1 = a[i];
 71.1868 -            Object o2 = a2[i];
 71.1869 -            if (!(o1==null ? o2==null : o1.equals(o2)))
 71.1870 -                return false;
 71.1871 -        }
 71.1872 -
 71.1873 -        return true;
 71.1874 -    }
 71.1875 -
 71.1876 -    // Filling
 71.1877 -
 71.1878 -    /**
 71.1879 -     * Assigns the specified long value to each element of the specified array
 71.1880 -     * of longs.
 71.1881 -     *
 71.1882 -     * @param a the array to be filled
 71.1883 -     * @param val the value to be stored in all elements of the array
 71.1884 -     */
 71.1885 -    public static void fill(long[] a, long val) {
 71.1886 -        for (int i = 0, len = a.length; i < len; i++)
 71.1887 -            a[i] = val;
 71.1888 -    }
 71.1889 -
 71.1890 -    /**
 71.1891 -     * Assigns the specified long value to each element of the specified
 71.1892 -     * range of the specified array of longs.  The range to be filled
 71.1893 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.1894 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.1895 -     * range to be filled is empty.)
 71.1896 -     *
 71.1897 -     * @param a the array to be filled
 71.1898 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1899 -     *        filled with the specified value
 71.1900 -     * @param toIndex the index of the last element (exclusive) to be
 71.1901 -     *        filled with the specified value
 71.1902 -     * @param val the value to be stored in all elements of the array
 71.1903 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.1904 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.1905 -     *         <tt>toIndex &gt; a.length</tt>
 71.1906 -     */
 71.1907 -    public static void fill(long[] a, int fromIndex, int toIndex, long val) {
 71.1908 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1909 -        for (int i = fromIndex; i < toIndex; i++)
 71.1910 -            a[i] = val;
 71.1911 -    }
 71.1912 -
 71.1913 -    /**
 71.1914 -     * Assigns the specified int value to each element of the specified array
 71.1915 -     * of ints.
 71.1916 -     *
 71.1917 -     * @param a the array to be filled
 71.1918 -     * @param val the value to be stored in all elements of the array
 71.1919 -     */
 71.1920 -    public static void fill(int[] a, int val) {
 71.1921 -        for (int i = 0, len = a.length; i < len; i++)
 71.1922 -            a[i] = val;
 71.1923 -    }
 71.1924 -
 71.1925 -    /**
 71.1926 -     * Assigns the specified int value to each element of the specified
 71.1927 -     * range of the specified array of ints.  The range to be filled
 71.1928 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.1929 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.1930 -     * range to be filled is empty.)
 71.1931 -     *
 71.1932 -     * @param a the array to be filled
 71.1933 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1934 -     *        filled with the specified value
 71.1935 -     * @param toIndex the index of the last element (exclusive) to be
 71.1936 -     *        filled with the specified value
 71.1937 -     * @param val the value to be stored in all elements of the array
 71.1938 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.1939 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.1940 -     *         <tt>toIndex &gt; a.length</tt>
 71.1941 -     */
 71.1942 -    public static void fill(int[] a, int fromIndex, int toIndex, int val) {
 71.1943 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1944 -        for (int i = fromIndex; i < toIndex; i++)
 71.1945 -            a[i] = val;
 71.1946 -    }
 71.1947 -
 71.1948 -    /**
 71.1949 -     * Assigns the specified short value to each element of the specified array
 71.1950 -     * of shorts.
 71.1951 -     *
 71.1952 -     * @param a the array to be filled
 71.1953 -     * @param val the value to be stored in all elements of the array
 71.1954 -     */
 71.1955 -    public static void fill(short[] a, short val) {
 71.1956 -        for (int i = 0, len = a.length; i < len; i++)
 71.1957 -            a[i] = val;
 71.1958 -    }
 71.1959 -
 71.1960 -    /**
 71.1961 -     * Assigns the specified short value to each element of the specified
 71.1962 -     * range of the specified array of shorts.  The range to be filled
 71.1963 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.1964 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.1965 -     * range to be filled is empty.)
 71.1966 -     *
 71.1967 -     * @param a the array to be filled
 71.1968 -     * @param fromIndex the index of the first element (inclusive) to be
 71.1969 -     *        filled with the specified value
 71.1970 -     * @param toIndex the index of the last element (exclusive) to be
 71.1971 -     *        filled with the specified value
 71.1972 -     * @param val the value to be stored in all elements of the array
 71.1973 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.1974 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.1975 -     *         <tt>toIndex &gt; a.length</tt>
 71.1976 -     */
 71.1977 -    public static void fill(short[] a, int fromIndex, int toIndex, short val) {
 71.1978 -        rangeCheck(a.length, fromIndex, toIndex);
 71.1979 -        for (int i = fromIndex; i < toIndex; i++)
 71.1980 -            a[i] = val;
 71.1981 -    }
 71.1982 -
 71.1983 -    /**
 71.1984 -     * Assigns the specified char value to each element of the specified array
 71.1985 -     * of chars.
 71.1986 -     *
 71.1987 -     * @param a the array to be filled
 71.1988 -     * @param val the value to be stored in all elements of the array
 71.1989 -     */
 71.1990 -    public static void fill(char[] a, char val) {
 71.1991 -        for (int i = 0, len = a.length; i < len; i++)
 71.1992 -            a[i] = val;
 71.1993 -    }
 71.1994 -
 71.1995 -    /**
 71.1996 -     * Assigns the specified char value to each element of the specified
 71.1997 -     * range of the specified array of chars.  The range to be filled
 71.1998 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.1999 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.2000 -     * range to be filled is empty.)
 71.2001 -     *
 71.2002 -     * @param a the array to be filled
 71.2003 -     * @param fromIndex the index of the first element (inclusive) to be
 71.2004 -     *        filled with the specified value
 71.2005 -     * @param toIndex the index of the last element (exclusive) to be
 71.2006 -     *        filled with the specified value
 71.2007 -     * @param val the value to be stored in all elements of the array
 71.2008 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.2009 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.2010 -     *         <tt>toIndex &gt; a.length</tt>
 71.2011 -     */
 71.2012 -    public static void fill(char[] a, int fromIndex, int toIndex, char val) {
 71.2013 -        rangeCheck(a.length, fromIndex, toIndex);
 71.2014 -        for (int i = fromIndex; i < toIndex; i++)
 71.2015 -            a[i] = val;
 71.2016 -    }
 71.2017 -
 71.2018 -    /**
 71.2019 -     * Assigns the specified byte value to each element of the specified array
 71.2020 -     * of bytes.
 71.2021 -     *
 71.2022 -     * @param a the array to be filled
 71.2023 -     * @param val the value to be stored in all elements of the array
 71.2024 -     */
 71.2025 -    public static void fill(byte[] a, byte val) {
 71.2026 -        for (int i = 0, len = a.length; i < len; i++)
 71.2027 -            a[i] = val;
 71.2028 -    }
 71.2029 -
 71.2030 -    /**
 71.2031 -     * Assigns the specified byte value to each element of the specified
 71.2032 -     * range of the specified array of bytes.  The range to be filled
 71.2033 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.2034 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.2035 -     * range to be filled is empty.)
 71.2036 -     *
 71.2037 -     * @param a the array to be filled
 71.2038 -     * @param fromIndex the index of the first element (inclusive) to be
 71.2039 -     *        filled with the specified value
 71.2040 -     * @param toIndex the index of the last element (exclusive) to be
 71.2041 -     *        filled with the specified value
 71.2042 -     * @param val the value to be stored in all elements of the array
 71.2043 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.2044 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.2045 -     *         <tt>toIndex &gt; a.length</tt>
 71.2046 -     */
 71.2047 -    public static void fill(byte[] a, int fromIndex, int toIndex, byte val) {
 71.2048 -        rangeCheck(a.length, fromIndex, toIndex);
 71.2049 -        for (int i = fromIndex; i < toIndex; i++)
 71.2050 -            a[i] = val;
 71.2051 -    }
 71.2052 -
 71.2053 -    /**
 71.2054 -     * Assigns the specified boolean value to each element of the specified
 71.2055 -     * array of booleans.
 71.2056 -     *
 71.2057 -     * @param a the array to be filled
 71.2058 -     * @param val the value to be stored in all elements of the array
 71.2059 -     */
 71.2060 -    public static void fill(boolean[] a, boolean val) {
 71.2061 -        for (int i = 0, len = a.length; i < len; i++)
 71.2062 -            a[i] = val;
 71.2063 -    }
 71.2064 -
 71.2065 -    /**
 71.2066 -     * Assigns the specified boolean value to each element of the specified
 71.2067 -     * range of the specified array of booleans.  The range to be filled
 71.2068 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.2069 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.2070 -     * range to be filled is empty.)
 71.2071 -     *
 71.2072 -     * @param a the array to be filled
 71.2073 -     * @param fromIndex the index of the first element (inclusive) to be
 71.2074 -     *        filled with the specified value
 71.2075 -     * @param toIndex the index of the last element (exclusive) to be
 71.2076 -     *        filled with the specified value
 71.2077 -     * @param val the value to be stored in all elements of the array
 71.2078 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.2079 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.2080 -     *         <tt>toIndex &gt; a.length</tt>
 71.2081 -     */
 71.2082 -    public static void fill(boolean[] a, int fromIndex, int toIndex,
 71.2083 -                            boolean val) {
 71.2084 -        rangeCheck(a.length, fromIndex, toIndex);
 71.2085 -        for (int i = fromIndex; i < toIndex; i++)
 71.2086 -            a[i] = val;
 71.2087 -    }
 71.2088 -
 71.2089 -    /**
 71.2090 -     * Assigns the specified double value to each element of the specified
 71.2091 -     * array of doubles.
 71.2092 -     *
 71.2093 -     * @param a the array to be filled
 71.2094 -     * @param val the value to be stored in all elements of the array
 71.2095 -     */
 71.2096 -    public static void fill(double[] a, double val) {
 71.2097 -        for (int i = 0, len = a.length; i < len; i++)
 71.2098 -            a[i] = val;
 71.2099 -    }
 71.2100 -
 71.2101 -    /**
 71.2102 -     * Assigns the specified double value to each element of the specified
 71.2103 -     * range of the specified array of doubles.  The range to be filled
 71.2104 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.2105 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.2106 -     * range to be filled is empty.)
 71.2107 -     *
 71.2108 -     * @param a the array to be filled
 71.2109 -     * @param fromIndex the index of the first element (inclusive) to be
 71.2110 -     *        filled with the specified value
 71.2111 -     * @param toIndex the index of the last element (exclusive) to be
 71.2112 -     *        filled with the specified value
 71.2113 -     * @param val the value to be stored in all elements of the array
 71.2114 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.2115 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.2116 -     *         <tt>toIndex &gt; a.length</tt>
 71.2117 -     */
 71.2118 -    public static void fill(double[] a, int fromIndex, int toIndex,double val){
 71.2119 -        rangeCheck(a.length, fromIndex, toIndex);
 71.2120 -        for (int i = fromIndex; i < toIndex; i++)
 71.2121 -            a[i] = val;
 71.2122 -    }
 71.2123 -
 71.2124 -    /**
 71.2125 -     * Assigns the specified float value to each element of the specified array
 71.2126 -     * of floats.
 71.2127 -     *
 71.2128 -     * @param a the array to be filled
 71.2129 -     * @param val the value to be stored in all elements of the array
 71.2130 -     */
 71.2131 -    public static void fill(float[] a, float val) {
 71.2132 -        for (int i = 0, len = a.length; i < len; i++)
 71.2133 -            a[i] = val;
 71.2134 -    }
 71.2135 -
 71.2136 -    /**
 71.2137 -     * Assigns the specified float value to each element of the specified
 71.2138 -     * range of the specified array of floats.  The range to be filled
 71.2139 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.2140 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.2141 -     * range to be filled is empty.)
 71.2142 -     *
 71.2143 -     * @param a the array to be filled
 71.2144 -     * @param fromIndex the index of the first element (inclusive) to be
 71.2145 -     *        filled with the specified value
 71.2146 -     * @param toIndex the index of the last element (exclusive) to be
 71.2147 -     *        filled with the specified value
 71.2148 -     * @param val the value to be stored in all elements of the array
 71.2149 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.2150 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.2151 -     *         <tt>toIndex &gt; a.length</tt>
 71.2152 -     */
 71.2153 -    public static void fill(float[] a, int fromIndex, int toIndex, float val) {
 71.2154 -        rangeCheck(a.length, fromIndex, toIndex);
 71.2155 -        for (int i = fromIndex; i < toIndex; i++)
 71.2156 -            a[i] = val;
 71.2157 -    }
 71.2158 -
 71.2159 -    /**
 71.2160 -     * Assigns the specified Object reference to each element of the specified
 71.2161 -     * array of Objects.
 71.2162 -     *
 71.2163 -     * @param a the array to be filled
 71.2164 -     * @param val the value to be stored in all elements of the array
 71.2165 -     * @throws ArrayStoreException if the specified value is not of a
 71.2166 -     *         runtime type that can be stored in the specified array
 71.2167 -     */
 71.2168 -    public static void fill(Object[] a, Object val) {
 71.2169 -        for (int i = 0, len = a.length; i < len; i++)
 71.2170 -            a[i] = val;
 71.2171 -    }
 71.2172 -
 71.2173 -    /**
 71.2174 -     * Assigns the specified Object reference to each element of the specified
 71.2175 -     * range of the specified array of Objects.  The range to be filled
 71.2176 -     * extends from index <tt>fromIndex</tt>, inclusive, to index
 71.2177 -     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
 71.2178 -     * range to be filled is empty.)
 71.2179 -     *
 71.2180 -     * @param a the array to be filled
 71.2181 -     * @param fromIndex the index of the first element (inclusive) to be
 71.2182 -     *        filled with the specified value
 71.2183 -     * @param toIndex the index of the last element (exclusive) to be
 71.2184 -     *        filled with the specified value
 71.2185 -     * @param val the value to be stored in all elements of the array
 71.2186 -     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
 71.2187 -     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
 71.2188 -     *         <tt>toIndex &gt; a.length</tt>
 71.2189 -     * @throws ArrayStoreException if the specified value is not of a
 71.2190 -     *         runtime type that can be stored in the specified array
 71.2191 -     */
 71.2192 -    public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
 71.2193 -        rangeCheck(a.length, fromIndex, toIndex);
 71.2194 -        for (int i = fromIndex; i < toIndex; i++)
 71.2195 -            a[i] = val;
 71.2196 -    }
 71.2197 -
 71.2198 -    // Cloning
 71.2199 -
 71.2200 -    /**
 71.2201 -     * Copies the specified array, truncating or padding with nulls (if necessary)
 71.2202 -     * so the copy has the specified length.  For all indices that are
 71.2203 -     * valid in both the original array and the copy, the two arrays will
 71.2204 -     * contain identical values.  For any indices that are valid in the
 71.2205 -     * copy but not the original, the copy will contain <tt>null</tt>.
 71.2206 -     * Such indices will exist if and only if the specified length
 71.2207 -     * is greater than that of the original array.
 71.2208 -     * The resulting array is of exactly the same class as the original array.
 71.2209 -     *
 71.2210 -     * @param original the array to be copied
 71.2211 -     * @param newLength the length of the copy to be returned
 71.2212 -     * @return a copy of the original array, truncated or padded with nulls
 71.2213 -     *     to obtain the specified length
 71.2214 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2215 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2216 -     * @since 1.6
 71.2217 -     */
 71.2218 -    public static <T> T[] copyOf(T[] original, int newLength) {
 71.2219 -        return (T[]) copyOf(original, newLength, original.getClass());
 71.2220 -    }
 71.2221 -
 71.2222 -    /**
 71.2223 -     * Copies the specified array, truncating or padding with nulls (if necessary)
 71.2224 -     * so the copy has the specified length.  For all indices that are
 71.2225 -     * valid in both the original array and the copy, the two arrays will
 71.2226 -     * contain identical values.  For any indices that are valid in the
 71.2227 -     * copy but not the original, the copy will contain <tt>null</tt>.
 71.2228 -     * Such indices will exist if and only if the specified length
 71.2229 -     * is greater than that of the original array.
 71.2230 -     * The resulting array is of the class <tt>newType</tt>.
 71.2231 -     *
 71.2232 -     * @param original the array to be copied
 71.2233 -     * @param newLength the length of the copy to be returned
 71.2234 -     * @param newType the class of the copy to be returned
 71.2235 -     * @return a copy of the original array, truncated or padded with nulls
 71.2236 -     *     to obtain the specified length
 71.2237 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2238 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2239 -     * @throws ArrayStoreException if an element copied from
 71.2240 -     *     <tt>original</tt> is not of a runtime type that can be stored in
 71.2241 -     *     an array of class <tt>newType</tt>
 71.2242 -     * @since 1.6
 71.2243 -     */
 71.2244 -    public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
 71.2245 -        T[] copy = ((Object)newType == (Object)Object[].class)
 71.2246 -            ? (T[]) new Object[newLength]
 71.2247 -            : (T[]) Array.newInstance(newType.getComponentType(), newLength);
 71.2248 -        System.arraycopy(original, 0, copy, 0,
 71.2249 -                         Math.min(original.length, newLength));
 71.2250 -        return copy;
 71.2251 -    }
 71.2252 -
 71.2253 -    /**
 71.2254 -     * Copies the specified array, truncating or padding with zeros (if necessary)
 71.2255 -     * so the copy has the specified length.  For all indices that are
 71.2256 -     * valid in both the original array and the copy, the two arrays will
 71.2257 -     * contain identical values.  For any indices that are valid in the
 71.2258 -     * copy but not the original, the copy will contain <tt>(byte)0</tt>.
 71.2259 -     * Such indices will exist if and only if the specified length
 71.2260 -     * is greater than that of the original array.
 71.2261 -     *
 71.2262 -     * @param original the array to be copied
 71.2263 -     * @param newLength the length of the copy to be returned
 71.2264 -     * @return a copy of the original array, truncated or padded with zeros
 71.2265 -     *     to obtain the specified length
 71.2266 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2267 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2268 -     * @since 1.6
 71.2269 -     */
 71.2270 -    public static byte[] copyOf(byte[] original, int newLength) {
 71.2271 -        byte[] copy = new byte[newLength];
 71.2272 -        System.arraycopy(original, 0, copy, 0,
 71.2273 -                         Math.min(original.length, newLength));
 71.2274 -        return copy;
 71.2275 -    }
 71.2276 -
 71.2277 -    /**
 71.2278 -     * Copies the specified array, truncating or padding with zeros (if necessary)
 71.2279 -     * so the copy has the specified length.  For all indices that are
 71.2280 -     * valid in both the original array and the copy, the two arrays will
 71.2281 -     * contain identical values.  For any indices that are valid in the
 71.2282 -     * copy but not the original, the copy will contain <tt>(short)0</tt>.
 71.2283 -     * Such indices will exist if and only if the specified length
 71.2284 -     * is greater than that of the original array.
 71.2285 -     *
 71.2286 -     * @param original the array to be copied
 71.2287 -     * @param newLength the length of the copy to be returned
 71.2288 -     * @return a copy of the original array, truncated or padded with zeros
 71.2289 -     *     to obtain the specified length
 71.2290 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2291 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2292 -     * @since 1.6
 71.2293 -     */
 71.2294 -    public static short[] copyOf(short[] original, int newLength) {
 71.2295 -        short[] copy = new short[newLength];
 71.2296 -        System.arraycopy(original, 0, copy, 0,
 71.2297 -                         Math.min(original.length, newLength));
 71.2298 -        return copy;
 71.2299 -    }
 71.2300 -
 71.2301 -    /**
 71.2302 -     * Copies the specified array, truncating or padding with zeros (if necessary)
 71.2303 -     * so the copy has the specified length.  For all indices that are
 71.2304 -     * valid in both the original array and the copy, the two arrays will
 71.2305 -     * contain identical values.  For any indices that are valid in the
 71.2306 -     * copy but not the original, the copy will contain <tt>0</tt>.
 71.2307 -     * Such indices will exist if and only if the specified length
 71.2308 -     * is greater than that of the original array.
 71.2309 -     *
 71.2310 -     * @param original the array to be copied
 71.2311 -     * @param newLength the length of the copy to be returned
 71.2312 -     * @return a copy of the original array, truncated or padded with zeros
 71.2313 -     *     to obtain the specified length
 71.2314 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2315 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2316 -     * @since 1.6
 71.2317 -     */
 71.2318 -    public static int[] copyOf(int[] original, int newLength) {
 71.2319 -        int[] copy = new int[newLength];
 71.2320 -        System.arraycopy(original, 0, copy, 0,
 71.2321 -                         Math.min(original.length, newLength));
 71.2322 -        return copy;
 71.2323 -    }
 71.2324 -
 71.2325 -    /**
 71.2326 -     * Copies the specified array, truncating or padding with zeros (if necessary)
 71.2327 -     * so the copy has the specified length.  For all indices that are
 71.2328 -     * valid in both the original array and the copy, the two arrays will
 71.2329 -     * contain identical values.  For any indices that are valid in the
 71.2330 -     * copy but not the original, the copy will contain <tt>0L</tt>.
 71.2331 -     * Such indices will exist if and only if the specified length
 71.2332 -     * is greater than that of the original array.
 71.2333 -     *
 71.2334 -     * @param original the array to be copied
 71.2335 -     * @param newLength the length of the copy to be returned
 71.2336 -     * @return a copy of the original array, truncated or padded with zeros
 71.2337 -     *     to obtain the specified length
 71.2338 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2339 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2340 -     * @since 1.6
 71.2341 -     */
 71.2342 -    public static long[] copyOf(long[] original, int newLength) {
 71.2343 -        long[] copy = new long[newLength];
 71.2344 -        System.arraycopy(original, 0, copy, 0,
 71.2345 -                         Math.min(original.length, newLength));
 71.2346 -        return copy;
 71.2347 -    }
 71.2348 -
 71.2349 -    /**
 71.2350 -     * Copies the specified array, truncating or padding with null characters (if necessary)
 71.2351 -     * so the copy has the specified length.  For all indices that are valid
 71.2352 -     * in both the original array and the copy, the two arrays will contain
 71.2353 -     * identical values.  For any indices that are valid in the copy but not
 71.2354 -     * the original, the copy will contain <tt>'\\u000'</tt>.  Such indices
 71.2355 -     * will exist if and only if the specified length is greater than that of
 71.2356 -     * the original array.
 71.2357 -     *
 71.2358 -     * @param original the array to be copied
 71.2359 -     * @param newLength the length of the copy to be returned
 71.2360 -     * @return a copy of the original array, truncated or padded with null characters
 71.2361 -     *     to obtain the specified length
 71.2362 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2363 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2364 -     * @since 1.6
 71.2365 -     */
 71.2366 -    public static char[] copyOf(char[] original, int newLength) {
 71.2367 -        char[] copy = new char[newLength];
 71.2368 -        System.arraycopy(original, 0, copy, 0,
 71.2369 -                         Math.min(original.length, newLength));
 71.2370 -        return copy;
 71.2371 -    }
 71.2372 -
 71.2373 -    /**
 71.2374 -     * Copies the specified array, truncating or padding with zeros (if necessary)
 71.2375 -     * so the copy has the specified length.  For all indices that are
 71.2376 -     * valid in both the original array and the copy, the two arrays will
 71.2377 -     * contain identical values.  For any indices that are valid in the
 71.2378 -     * copy but not the original, the copy will contain <tt>0f</tt>.
 71.2379 -     * Such indices will exist if and only if the specified length
 71.2380 -     * is greater than that of the original array.
 71.2381 -     *
 71.2382 -     * @param original the array to be copied
 71.2383 -     * @param newLength the length of the copy to be returned
 71.2384 -     * @return a copy of the original array, truncated or padded with zeros
 71.2385 -     *     to obtain the specified length
 71.2386 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2387 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2388 -     * @since 1.6
 71.2389 -     */
 71.2390 -    public static float[] copyOf(float[] original, int newLength) {
 71.2391 -        float[] copy = new float[newLength];
 71.2392 -        System.arraycopy(original, 0, copy, 0,
 71.2393 -                         Math.min(original.length, newLength));
 71.2394 -        return copy;
 71.2395 -    }
 71.2396 -
 71.2397 -    /**
 71.2398 -     * Copies the specified array, truncating or padding with zeros (if necessary)
 71.2399 -     * so the copy has the specified length.  For all indices that are
 71.2400 -     * valid in both the original array and the copy, the two arrays will
 71.2401 -     * contain identical values.  For any indices that are valid in the
 71.2402 -     * copy but not the original, the copy will contain <tt>0d</tt>.
 71.2403 -     * Such indices will exist if and only if the specified length
 71.2404 -     * is greater than that of the original array.
 71.2405 -     *
 71.2406 -     * @param original the array to be copied
 71.2407 -     * @param newLength the length of the copy to be returned
 71.2408 -     * @return a copy of the original array, truncated or padded with zeros
 71.2409 -     *     to obtain the specified length
 71.2410 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2411 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2412 -     * @since 1.6
 71.2413 -     */
 71.2414 -    public static double[] copyOf(double[] original, int newLength) {
 71.2415 -        double[] copy = new double[newLength];
 71.2416 -        System.arraycopy(original, 0, copy, 0,
 71.2417 -                         Math.min(original.length, newLength));
 71.2418 -        return copy;
 71.2419 -    }
 71.2420 -
 71.2421 -    /**
 71.2422 -     * Copies the specified array, truncating or padding with <tt>false</tt> (if necessary)
 71.2423 -     * so the copy has the specified length.  For all indices that are
 71.2424 -     * valid in both the original array and the copy, the two arrays will
 71.2425 -     * contain identical values.  For any indices that are valid in the
 71.2426 -     * copy but not the original, the copy will contain <tt>false</tt>.
 71.2427 -     * Such indices will exist if and only if the specified length
 71.2428 -     * is greater than that of the original array.
 71.2429 -     *
 71.2430 -     * @param original the array to be copied
 71.2431 -     * @param newLength the length of the copy to be returned
 71.2432 -     * @return a copy of the original array, truncated or padded with false elements
 71.2433 -     *     to obtain the specified length
 71.2434 -     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
 71.2435 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2436 -     * @since 1.6
 71.2437 -     */
 71.2438 -    public static boolean[] copyOf(boolean[] original, int newLength) {
 71.2439 -        boolean[] copy = new boolean[newLength];
 71.2440 -        System.arraycopy(original, 0, copy, 0,
 71.2441 -                         Math.min(original.length, newLength));
 71.2442 -        return copy;
 71.2443 -    }
 71.2444 -
 71.2445 -    /**
 71.2446 -     * Copies the specified range of the specified array into a new array.
 71.2447 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2448 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2449 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2450 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2451 -     * Values from subsequent elements in the original array are placed into
 71.2452 -     * subsequent elements in the copy.  The final index of the range
 71.2453 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2454 -     * may be greater than <tt>original.length</tt>, in which case
 71.2455 -     * <tt>null</tt> is placed in all elements of the copy whose index is
 71.2456 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2457 -     * of the returned array will be <tt>to - from</tt>.
 71.2458 -     * <p>
 71.2459 -     * The resulting array is of exactly the same class as the original array.
 71.2460 -     *
 71.2461 -     * @param original the array from which a range is to be copied
 71.2462 -     * @param from the initial index of the range to be copied, inclusive
 71.2463 -     * @param to the final index of the range to be copied, exclusive.
 71.2464 -     *     (This index may lie outside the array.)
 71.2465 -     * @return a new array containing the specified range from the original array,
 71.2466 -     *     truncated or padded with nulls to obtain the required length
 71.2467 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2468 -     *     or {@code from > original.length}
 71.2469 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2470 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2471 -     * @since 1.6
 71.2472 -     */
 71.2473 -    public static <T> T[] copyOfRange(T[] original, int from, int to) {
 71.2474 -        return copyOfRange(original, from, to, (Class<T[]>) original.getClass());
 71.2475 -    }
 71.2476 -
 71.2477 -    /**
 71.2478 -     * Copies the specified range of the specified array into a new array.
 71.2479 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2480 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2481 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2482 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2483 -     * Values from subsequent elements in the original array are placed into
 71.2484 -     * subsequent elements in the copy.  The final index of the range
 71.2485 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2486 -     * may be greater than <tt>original.length</tt>, in which case
 71.2487 -     * <tt>null</tt> is placed in all elements of the copy whose index is
 71.2488 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2489 -     * of the returned array will be <tt>to - from</tt>.
 71.2490 -     * The resulting array is of the class <tt>newType</tt>.
 71.2491 -     *
 71.2492 -     * @param original the array from which a range is to be copied
 71.2493 -     * @param from the initial index of the range to be copied, inclusive
 71.2494 -     * @param to the final index of the range to be copied, exclusive.
 71.2495 -     *     (This index may lie outside the array.)
 71.2496 -     * @param newType the class of the copy to be returned
 71.2497 -     * @return a new array containing the specified range from the original array,
 71.2498 -     *     truncated or padded with nulls to obtain the required length
 71.2499 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2500 -     *     or {@code from > original.length}
 71.2501 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2502 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2503 -     * @throws ArrayStoreException if an element copied from
 71.2504 -     *     <tt>original</tt> is not of a runtime type that can be stored in
 71.2505 -     *     an array of class <tt>newType</tt>.
 71.2506 -     * @since 1.6
 71.2507 -     */
 71.2508 -    public static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType) {
 71.2509 -        int newLength = to - from;
 71.2510 -        if (newLength < 0)
 71.2511 -            throw new IllegalArgumentException(from + " > " + to);
 71.2512 -        T[] copy = ((Object)newType == (Object)Object[].class)
 71.2513 -            ? (T[]) new Object[newLength]
 71.2514 -            : (T[]) Array.newInstance(newType.getComponentType(), newLength);
 71.2515 -        System.arraycopy(original, from, copy, 0,
 71.2516 -                         Math.min(original.length - from, newLength));
 71.2517 -        return copy;
 71.2518 -    }
 71.2519 -
 71.2520 -    /**
 71.2521 -     * Copies the specified range of the specified array into a new array.
 71.2522 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2523 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2524 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2525 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2526 -     * Values from subsequent elements in the original array are placed into
 71.2527 -     * subsequent elements in the copy.  The final index of the range
 71.2528 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2529 -     * may be greater than <tt>original.length</tt>, in which case
 71.2530 -     * <tt>(byte)0</tt> is placed in all elements of the copy whose index is
 71.2531 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2532 -     * of the returned array will be <tt>to - from</tt>.
 71.2533 -     *
 71.2534 -     * @param original the array from which a range is to be copied
 71.2535 -     * @param from the initial index of the range to be copied, inclusive
 71.2536 -     * @param to the final index of the range to be copied, exclusive.
 71.2537 -     *     (This index may lie outside the array.)
 71.2538 -     * @return a new array containing the specified range from the original array,
 71.2539 -     *     truncated or padded with zeros to obtain the required length
 71.2540 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2541 -     *     or {@code from > original.length}
 71.2542 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2543 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2544 -     * @since 1.6
 71.2545 -     */
 71.2546 -    public static byte[] copyOfRange(byte[] original, int from, int to) {
 71.2547 -        int newLength = to - from;
 71.2548 -        if (newLength < 0)
 71.2549 -            throw new IllegalArgumentException(from + " > " + to);
 71.2550 -        byte[] copy = new byte[newLength];
 71.2551 -        System.arraycopy(original, from, copy, 0,
 71.2552 -                         Math.min(original.length - from, newLength));
 71.2553 -        return copy;
 71.2554 -    }
 71.2555 -
 71.2556 -    /**
 71.2557 -     * Copies the specified range of the specified array into a new array.
 71.2558 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2559 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2560 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2561 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2562 -     * Values from subsequent elements in the original array are placed into
 71.2563 -     * subsequent elements in the copy.  The final index of the range
 71.2564 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2565 -     * may be greater than <tt>original.length</tt>, in which case
 71.2566 -     * <tt>(short)0</tt> is placed in all elements of the copy whose index is
 71.2567 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2568 -     * of the returned array will be <tt>to - from</tt>.
 71.2569 -     *
 71.2570 -     * @param original the array from which a range is to be copied
 71.2571 -     * @param from the initial index of the range to be copied, inclusive
 71.2572 -     * @param to the final index of the range to be copied, exclusive.
 71.2573 -     *     (This index may lie outside the array.)
 71.2574 -     * @return a new array containing the specified range from the original array,
 71.2575 -     *     truncated or padded with zeros to obtain the required length
 71.2576 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2577 -     *     or {@code from > original.length}
 71.2578 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2579 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2580 -     * @since 1.6
 71.2581 -     */
 71.2582 -    public static short[] copyOfRange(short[] original, int from, int to) {
 71.2583 -        int newLength = to - from;
 71.2584 -        if (newLength < 0)
 71.2585 -            throw new IllegalArgumentException(from + " > " + to);
 71.2586 -        short[] copy = new short[newLength];
 71.2587 -        System.arraycopy(original, from, copy, 0,
 71.2588 -                         Math.min(original.length - from, newLength));
 71.2589 -        return copy;
 71.2590 -    }
 71.2591 -
 71.2592 -    /**
 71.2593 -     * Copies the specified range of the specified array into a new array.
 71.2594 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2595 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2596 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2597 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2598 -     * Values from subsequent elements in the original array are placed into
 71.2599 -     * subsequent elements in the copy.  The final index of the range
 71.2600 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2601 -     * may be greater than <tt>original.length</tt>, in which case
 71.2602 -     * <tt>0</tt> is placed in all elements of the copy whose index is
 71.2603 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2604 -     * of the returned array will be <tt>to - from</tt>.
 71.2605 -     *
 71.2606 -     * @param original the array from which a range is to be copied
 71.2607 -     * @param from the initial index of the range to be copied, inclusive
 71.2608 -     * @param to the final index of the range to be copied, exclusive.
 71.2609 -     *     (This index may lie outside the array.)
 71.2610 -     * @return a new array containing the specified range from the original array,
 71.2611 -     *     truncated or padded with zeros to obtain the required length
 71.2612 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2613 -     *     or {@code from > original.length}
 71.2614 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2615 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2616 -     * @since 1.6
 71.2617 -     */
 71.2618 -    public static int[] copyOfRange(int[] original, int from, int to) {
 71.2619 -        int newLength = to - from;
 71.2620 -        if (newLength < 0)
 71.2621 -            throw new IllegalArgumentException(from + " > " + to);
 71.2622 -        int[] copy = new int[newLength];
 71.2623 -        System.arraycopy(original, from, copy, 0,
 71.2624 -                         Math.min(original.length - from, newLength));
 71.2625 -        return copy;
 71.2626 -    }
 71.2627 -
 71.2628 -    /**
 71.2629 -     * Copies the specified range of the specified array into a new array.
 71.2630 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2631 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2632 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2633 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2634 -     * Values from subsequent elements in the original array are placed into
 71.2635 -     * subsequent elements in the copy.  The final index of the range
 71.2636 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2637 -     * may be greater than <tt>original.length</tt>, in which case
 71.2638 -     * <tt>0L</tt> is placed in all elements of the copy whose index is
 71.2639 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2640 -     * of the returned array will be <tt>to - from</tt>.
 71.2641 -     *
 71.2642 -     * @param original the array from which a range is to be copied
 71.2643 -     * @param from the initial index of the range to be copied, inclusive
 71.2644 -     * @param to the final index of the range to be copied, exclusive.
 71.2645 -     *     (This index may lie outside the array.)
 71.2646 -     * @return a new array containing the specified range from the original array,
 71.2647 -     *     truncated or padded with zeros to obtain the required length
 71.2648 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2649 -     *     or {@code from > original.length}
 71.2650 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2651 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2652 -     * @since 1.6
 71.2653 -     */
 71.2654 -    public static long[] copyOfRange(long[] original, int from, int to) {
 71.2655 -        int newLength = to - from;
 71.2656 -        if (newLength < 0)
 71.2657 -            throw new IllegalArgumentException(from + " > " + to);
 71.2658 -        long[] copy = new long[newLength];
 71.2659 -        System.arraycopy(original, from, copy, 0,
 71.2660 -                         Math.min(original.length - from, newLength));
 71.2661 -        return copy;
 71.2662 -    }
 71.2663 -
 71.2664 -    /**
 71.2665 -     * Copies the specified range of the specified array into a new array.
 71.2666 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2667 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2668 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2669 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2670 -     * Values from subsequent elements in the original array are placed into
 71.2671 -     * subsequent elements in the copy.  The final index of the range
 71.2672 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2673 -     * may be greater than <tt>original.length</tt>, in which case
 71.2674 -     * <tt>'\\u000'</tt> is placed in all elements of the copy whose index is
 71.2675 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2676 -     * of the returned array will be <tt>to - from</tt>.
 71.2677 -     *
 71.2678 -     * @param original the array from which a range is to be copied
 71.2679 -     * @param from the initial index of the range to be copied, inclusive
 71.2680 -     * @param to the final index of the range to be copied, exclusive.
 71.2681 -     *     (This index may lie outside the array.)
 71.2682 -     * @return a new array containing the specified range from the original array,
 71.2683 -     *     truncated or padded with null characters to obtain the required length
 71.2684 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2685 -     *     or {@code from > original.length}
 71.2686 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2687 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2688 -     * @since 1.6
 71.2689 -     */
 71.2690 -    public static char[] copyOfRange(char[] original, int from, int to) {
 71.2691 -        int newLength = to - from;
 71.2692 -        if (newLength < 0)
 71.2693 -            throw new IllegalArgumentException(from + " > " + to);
 71.2694 -        char[] copy = new char[newLength];
 71.2695 -        System.arraycopy(original, from, copy, 0,
 71.2696 -                         Math.min(original.length - from, newLength));
 71.2697 -        return copy;
 71.2698 -    }
 71.2699 -
 71.2700 -    /**
 71.2701 -     * Copies the specified range of the specified array into a new array.
 71.2702 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2703 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2704 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2705 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2706 -     * Values from subsequent elements in the original array are placed into
 71.2707 -     * subsequent elements in the copy.  The final index of the range
 71.2708 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2709 -     * may be greater than <tt>original.length</tt>, in which case
 71.2710 -     * <tt>0f</tt> is placed in all elements of the copy whose index is
 71.2711 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2712 -     * of the returned array will be <tt>to - from</tt>.
 71.2713 -     *
 71.2714 -     * @param original the array from which a range is to be copied
 71.2715 -     * @param from the initial index of the range to be copied, inclusive
 71.2716 -     * @param to the final index of the range to be copied, exclusive.
 71.2717 -     *     (This index may lie outside the array.)
 71.2718 -     * @return a new array containing the specified range from the original array,
 71.2719 -     *     truncated or padded with zeros to obtain the required length
 71.2720 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2721 -     *     or {@code from > original.length}
 71.2722 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2723 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2724 -     * @since 1.6
 71.2725 -     */
 71.2726 -    public static float[] copyOfRange(float[] original, int from, int to) {
 71.2727 -        int newLength = to - from;
 71.2728 -        if (newLength < 0)
 71.2729 -            throw new IllegalArgumentException(from + " > " + to);
 71.2730 -        float[] copy = new float[newLength];
 71.2731 -        System.arraycopy(original, from, copy, 0,
 71.2732 -                         Math.min(original.length - from, newLength));
 71.2733 -        return copy;
 71.2734 -    }
 71.2735 -
 71.2736 -    /**
 71.2737 -     * Copies the specified range of the specified array into a new array.
 71.2738 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2739 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2740 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2741 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2742 -     * Values from subsequent elements in the original array are placed into
 71.2743 -     * subsequent elements in the copy.  The final index of the range
 71.2744 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2745 -     * may be greater than <tt>original.length</tt>, in which case
 71.2746 -     * <tt>0d</tt> is placed in all elements of the copy whose index is
 71.2747 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2748 -     * of the returned array will be <tt>to - from</tt>.
 71.2749 -     *
 71.2750 -     * @param original the array from which a range is to be copied
 71.2751 -     * @param from the initial index of the range to be copied, inclusive
 71.2752 -     * @param to the final index of the range to be copied, exclusive.
 71.2753 -     *     (This index may lie outside the array.)
 71.2754 -     * @return a new array containing the specified range from the original array,
 71.2755 -     *     truncated or padded with zeros to obtain the required length
 71.2756 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2757 -     *     or {@code from > original.length}
 71.2758 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2759 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2760 -     * @since 1.6
 71.2761 -     */
 71.2762 -    public static double[] copyOfRange(double[] original, int from, int to) {
 71.2763 -        int newLength = to - from;
 71.2764 -        if (newLength < 0)
 71.2765 -            throw new IllegalArgumentException(from + " > " + to);
 71.2766 -        double[] copy = new double[newLength];
 71.2767 -        System.arraycopy(original, from, copy, 0,
 71.2768 -                         Math.min(original.length - from, newLength));
 71.2769 -        return copy;
 71.2770 -    }
 71.2771 -
 71.2772 -    /**
 71.2773 -     * Copies the specified range of the specified array into a new array.
 71.2774 -     * The initial index of the range (<tt>from</tt>) must lie between zero
 71.2775 -     * and <tt>original.length</tt>, inclusive.  The value at
 71.2776 -     * <tt>original[from]</tt> is placed into the initial element of the copy
 71.2777 -     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
 71.2778 -     * Values from subsequent elements in the original array are placed into
 71.2779 -     * subsequent elements in the copy.  The final index of the range
 71.2780 -     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
 71.2781 -     * may be greater than <tt>original.length</tt>, in which case
 71.2782 -     * <tt>false</tt> is placed in all elements of the copy whose index is
 71.2783 -     * greater than or equal to <tt>original.length - from</tt>.  The length
 71.2784 -     * of the returned array will be <tt>to - from</tt>.
 71.2785 -     *
 71.2786 -     * @param original the array from which a range is to be copied
 71.2787 -     * @param from the initial index of the range to be copied, inclusive
 71.2788 -     * @param to the final index of the range to be copied, exclusive.
 71.2789 -     *     (This index may lie outside the array.)
 71.2790 -     * @return a new array containing the specified range from the original array,
 71.2791 -     *     truncated or padded with false elements to obtain the required length
 71.2792 -     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
 71.2793 -     *     or {@code from > original.length}
 71.2794 -     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
 71.2795 -     * @throws NullPointerException if <tt>original</tt> is null
 71.2796 -     * @since 1.6
 71.2797 -     */
 71.2798 -    public static boolean[] copyOfRange(boolean[] original, int from, int to) {
 71.2799 -        int newLength = to - from;
 71.2800 -        if (newLength < 0)
 71.2801 -            throw new IllegalArgumentException(from + " > " + to);
 71.2802 -        boolean[] copy = new boolean[newLength];
 71.2803 -        System.arraycopy(original, from, copy, 0,
 71.2804 -                         Math.min(original.length - from, newLength));
 71.2805 -        return copy;
 71.2806 -    }
 71.2807 -
 71.2808 -    // Misc
 71.2809 -
 71.2810 -    /**
 71.2811 -     * Returns a fixed-size list backed by the specified array.  (Changes to
 71.2812 -     * the returned list "write through" to the array.)  This method acts
 71.2813 -     * as bridge between array-based and collection-based APIs, in
 71.2814 -     * combination with {@link Collection#toArray}.  The returned list is
 71.2815 -     * serializable and implements {@link RandomAccess}.
 71.2816 -     *
 71.2817 -     * <p>This method also provides a convenient way to create a fixed-size
 71.2818 -     * list initialized to contain several elements:
 71.2819 -     * <pre>
 71.2820 -     *     List&lt;String&gt; stooges = Arrays.asList("Larry", "Moe", "Curly");
 71.2821 -     * </pre>
 71.2822 -     *
 71.2823 -     * @param a the array by which the list will be backed
 71.2824 -     * @return a list view of the specified array
 71.2825 -     */
 71.2826 -    @SafeVarargs
 71.2827 -    public static <T> List<T> asList(T... a) {
 71.2828 -        return new ArrayList<>(a);
 71.2829 -    }
 71.2830 -
 71.2831 -    /**
 71.2832 -     * @serial include
 71.2833 -     */
 71.2834 -    private static class ArrayList<E> extends AbstractList<E>
 71.2835 -        implements RandomAccess, java.io.Serializable
 71.2836 -    {
 71.2837 -        private static final long serialVersionUID = -2764017481108945198L;
 71.2838 -        private final E[] a;
 71.2839 -
 71.2840 -        ArrayList(E[] array) {
 71.2841 -            if (array==null)
 71.2842 -                throw new NullPointerException();
 71.2843 -            a = array;
 71.2844 -        }
 71.2845 -
 71.2846 -        public int size() {
 71.2847 -            return a.length;
 71.2848 -        }
 71.2849 -
 71.2850 -        public Object[] toArray() {
 71.2851 -            return a.clone();
 71.2852 -        }
 71.2853 -
 71.2854 -        public <T> T[] toArray(T[] a) {
 71.2855 -            int size = size();
 71.2856 -            if (a.length < size)
 71.2857 -                return Arrays.copyOf(this.a, size,
 71.2858 -                                     (Class<? extends T[]>) a.getClass());
 71.2859 -            System.arraycopy(this.a, 0, a, 0, size);
 71.2860 -            if (a.length > size)
 71.2861 -                a[size] = null;
 71.2862 -            return a;
 71.2863 -        }
 71.2864 -
 71.2865 -        public E get(int index) {
 71.2866 -            return a[index];
 71.2867 -        }
 71.2868 -
 71.2869 -        public E set(int index, E element) {
 71.2870 -            E oldValue = a[index];
 71.2871 -            a[index] = element;
 71.2872 -            return oldValue;
 71.2873 -        }
 71.2874 -
 71.2875 -        public int indexOf(Object o) {
 71.2876 -            if (o==null) {
 71.2877 -                for (int i=0; i<a.length; i++)
 71.2878 -                    if (a[i]==null)
 71.2879 -                        return i;
 71.2880 -            } else {
 71.2881 -                for (int i=0; i<a.length; i++)
 71.2882 -                    if (o.equals(a[i]))
 71.2883 -                        return i;
 71.2884 -            }
 71.2885 -            return -1;
 71.2886 -        }
 71.2887 -
 71.2888 -        public boolean contains(Object o) {
 71.2889 -            return indexOf(o) != -1;
 71.2890 -        }
 71.2891 -    }
 71.2892 -
 71.2893 -    /**
 71.2894 -     * Returns a hash code based on the contents of the specified array.
 71.2895 -     * For any two <tt>long</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.2896 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.2897 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.2898 -     *
 71.2899 -     * <p>The value returned by this method is the same value that would be
 71.2900 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.2901 -     * method on a {@link List} containing a sequence of {@link Long}
 71.2902 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.2903 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.2904 -     *
 71.2905 -     * @param a the array whose hash value to compute
 71.2906 -     * @return a content-based hash code for <tt>a</tt>
 71.2907 -     * @since 1.5
 71.2908 -     */
 71.2909 -    public static int hashCode(long a[]) {
 71.2910 -        if (a == null)
 71.2911 -            return 0;
 71.2912 -
 71.2913 -        int result = 1;
 71.2914 -        for (long element : a) {
 71.2915 -            int elementHash = (int)(element ^ (element >>> 32));
 71.2916 -            result = 31 * result + elementHash;
 71.2917 -        }
 71.2918 -
 71.2919 -        return result;
 71.2920 -    }
 71.2921 -
 71.2922 -    /**
 71.2923 -     * Returns a hash code based on the contents of the specified array.
 71.2924 -     * For any two non-null <tt>int</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.2925 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.2926 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.2927 -     *
 71.2928 -     * <p>The value returned by this method is the same value that would be
 71.2929 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.2930 -     * method on a {@link List} containing a sequence of {@link Integer}
 71.2931 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.2932 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.2933 -     *
 71.2934 -     * @param a the array whose hash value to compute
 71.2935 -     * @return a content-based hash code for <tt>a</tt>
 71.2936 -     * @since 1.5
 71.2937 -     */
 71.2938 -    public static int hashCode(int a[]) {
 71.2939 -        if (a == null)
 71.2940 -            return 0;
 71.2941 -
 71.2942 -        int result = 1;
 71.2943 -        for (int element : a)
 71.2944 -            result = 31 * result + element;
 71.2945 -
 71.2946 -        return result;
 71.2947 -    }
 71.2948 -
 71.2949 -    /**
 71.2950 -     * Returns a hash code based on the contents of the specified array.
 71.2951 -     * For any two <tt>short</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.2952 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.2953 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.2954 -     *
 71.2955 -     * <p>The value returned by this method is the same value that would be
 71.2956 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.2957 -     * method on a {@link List} containing a sequence of {@link Short}
 71.2958 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.2959 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.2960 -     *
 71.2961 -     * @param a the array whose hash value to compute
 71.2962 -     * @return a content-based hash code for <tt>a</tt>
 71.2963 -     * @since 1.5
 71.2964 -     */
 71.2965 -    public static int hashCode(short a[]) {
 71.2966 -        if (a == null)
 71.2967 -            return 0;
 71.2968 -
 71.2969 -        int result = 1;
 71.2970 -        for (short element : a)
 71.2971 -            result = 31 * result + element;
 71.2972 -
 71.2973 -        return result;
 71.2974 -    }
 71.2975 -
 71.2976 -    /**
 71.2977 -     * Returns a hash code based on the contents of the specified array.
 71.2978 -     * For any two <tt>char</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.2979 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.2980 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.2981 -     *
 71.2982 -     * <p>The value returned by this method is the same value that would be
 71.2983 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.2984 -     * method on a {@link List} containing a sequence of {@link Character}
 71.2985 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.2986 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.2987 -     *
 71.2988 -     * @param a the array whose hash value to compute
 71.2989 -     * @return a content-based hash code for <tt>a</tt>
 71.2990 -     * @since 1.5
 71.2991 -     */
 71.2992 -    public static int hashCode(char a[]) {
 71.2993 -        if (a == null)
 71.2994 -            return 0;
 71.2995 -
 71.2996 -        int result = 1;
 71.2997 -        for (char element : a)
 71.2998 -            result = 31 * result + element;
 71.2999 -
 71.3000 -        return result;
 71.3001 -    }
 71.3002 -
 71.3003 -    /**
 71.3004 -     * Returns a hash code based on the contents of the specified array.
 71.3005 -     * For any two <tt>byte</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.3006 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.3007 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.3008 -     *
 71.3009 -     * <p>The value returned by this method is the same value that would be
 71.3010 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.3011 -     * method on a {@link List} containing a sequence of {@link Byte}
 71.3012 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.3013 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.3014 -     *
 71.3015 -     * @param a the array whose hash value to compute
 71.3016 -     * @return a content-based hash code for <tt>a</tt>
 71.3017 -     * @since 1.5
 71.3018 -     */
 71.3019 -    public static int hashCode(byte a[]) {
 71.3020 -        if (a == null)
 71.3021 -            return 0;
 71.3022 -
 71.3023 -        int result = 1;
 71.3024 -        for (byte element : a)
 71.3025 -            result = 31 * result + element;
 71.3026 -
 71.3027 -        return result;
 71.3028 -    }
 71.3029 -
 71.3030 -    /**
 71.3031 -     * Returns a hash code based on the contents of the specified array.
 71.3032 -     * For any two <tt>boolean</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.3033 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.3034 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.3035 -     *
 71.3036 -     * <p>The value returned by this method is the same value that would be
 71.3037 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.3038 -     * method on a {@link List} containing a sequence of {@link Boolean}
 71.3039 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.3040 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.3041 -     *
 71.3042 -     * @param a the array whose hash value to compute
 71.3043 -     * @return a content-based hash code for <tt>a</tt>
 71.3044 -     * @since 1.5
 71.3045 -     */
 71.3046 -    public static int hashCode(boolean a[]) {
 71.3047 -        if (a == null)
 71.3048 -            return 0;
 71.3049 -
 71.3050 -        int result = 1;
 71.3051 -        for (boolean element : a)
 71.3052 -            result = 31 * result + (element ? 1231 : 1237);
 71.3053 -
 71.3054 -        return result;
 71.3055 -    }
 71.3056 -
 71.3057 -    /**
 71.3058 -     * Returns a hash code based on the contents of the specified array.
 71.3059 -     * For any two <tt>float</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.3060 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.3061 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.3062 -     *
 71.3063 -     * <p>The value returned by this method is the same value that would be
 71.3064 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.3065 -     * method on a {@link List} containing a sequence of {@link Float}
 71.3066 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.3067 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.3068 -     *
 71.3069 -     * @param a the array whose hash value to compute
 71.3070 -     * @return a content-based hash code for <tt>a</tt>
 71.3071 -     * @since 1.5
 71.3072 -     */
 71.3073 -    public static int hashCode(float a[]) {
 71.3074 -        if (a == null)
 71.3075 -            return 0;
 71.3076 -
 71.3077 -        int result = 1;
 71.3078 -        for (float element : a)
 71.3079 -            result = 31 * result + Float.floatToIntBits(element);
 71.3080 -
 71.3081 -        return result;
 71.3082 -    }
 71.3083 -
 71.3084 -    /**
 71.3085 -     * Returns a hash code based on the contents of the specified array.
 71.3086 -     * For any two <tt>double</tt> arrays <tt>a</tt> and <tt>b</tt>
 71.3087 -     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.3088 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.3089 -     *
 71.3090 -     * <p>The value returned by this method is the same value that would be
 71.3091 -     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
 71.3092 -     * method on a {@link List} containing a sequence of {@link Double}
 71.3093 -     * instances representing the elements of <tt>a</tt> in the same order.
 71.3094 -     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
 71.3095 -     *
 71.3096 -     * @param a the array whose hash value to compute
 71.3097 -     * @return a content-based hash code for <tt>a</tt>
 71.3098 -     * @since 1.5
 71.3099 -     */
 71.3100 -    public static int hashCode(double a[]) {
 71.3101 -        if (a == null)
 71.3102 -            return 0;
 71.3103 -
 71.3104 -        int result = 1;
 71.3105 -        for (double element : a) {
 71.3106 -            long bits = Double.doubleToLongBits(element);
 71.3107 -            result = 31 * result + (int)(bits ^ (bits >>> 32));
 71.3108 -        }
 71.3109 -        return result;
 71.3110 -    }
 71.3111 -
 71.3112 -    /**
 71.3113 -     * Returns a hash code based on the contents of the specified array.  If
 71.3114 -     * the array contains other arrays as elements, the hash code is based on
 71.3115 -     * their identities rather than their contents.  It is therefore
 71.3116 -     * acceptable to invoke this method on an array that contains itself as an
 71.3117 -     * element,  either directly or indirectly through one or more levels of
 71.3118 -     * arrays.
 71.3119 -     *
 71.3120 -     * <p>For any two arrays <tt>a</tt> and <tt>b</tt> such that
 71.3121 -     * <tt>Arrays.equals(a, b)</tt>, it is also the case that
 71.3122 -     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
 71.3123 -     *
 71.3124 -     * <p>The value returned by this method is equal to the value that would
 71.3125 -     * be returned by <tt>Arrays.asList(a).hashCode()</tt>, unless <tt>a</tt>
 71.3126 -     * is <tt>null</tt>, in which case <tt>0</tt> is returned.
 71.3127 -     *
 71.3128 -     * @param a the array whose content-based hash code to compute
 71.3129 -     * @return a content-based hash code for <tt>a</tt>
 71.3130 -     * @see #deepHashCode(Object[])
 71.3131 -     * @since 1.5
 71.3132 -     */
 71.3133 -    public static int hashCode(Object a[]) {
 71.3134 -        if (a == null)
 71.3135 -            return 0;
 71.3136 -
 71.3137 -        int result = 1;
 71.3138 -
 71.3139 -        for (Object element : a)
 71.3140 -            result = 31 * result + (element == null ? 0 : element.hashCode());
 71.3141 -
 71.3142 -        return result;
 71.3143 -    }
 71.3144 -
 71.3145 -    /**
 71.3146 -     * Returns a hash code based on the "deep contents" of the specified
 71.3147 -     * array.  If the array contains other arrays as elements, the
 71.3148 -     * hash code is based on their contents and so on, ad infinitum.
 71.3149 -     * It is therefore unacceptable to invoke this method on an array that
 71.3150 -     * contains itself as an element, either directly or indirectly through
 71.3151 -     * one or more levels of arrays.  The behavior of such an invocation is
 71.3152 -     * undefined.
 71.3153 -     *
 71.3154 -     * <p>For any two arrays <tt>a</tt> and <tt>b</tt> such that
 71.3155 -     * <tt>Arrays.deepEquals(a, b)</tt>, it is also the case that
 71.3156 -     * <tt>Arrays.deepHashCode(a) == Arrays.deepHashCode(b)</tt>.
 71.3157 -     *
 71.3158 -     * <p>The computation of the value returned by this method is similar to
 71.3159 -     * that of the value returned by {@link List#hashCode()} on a list
 71.3160 -     * containing the same elements as <tt>a</tt> in the same order, with one
 71.3161 -     * difference: If an element <tt>e</tt> of <tt>a</tt> is itself an array,
 71.3162 -     * its hash code is computed not by calling <tt>e.hashCode()</tt>, but as
 71.3163 -     * by calling the appropriate overloading of <tt>Arrays.hashCode(e)</tt>
 71.3164 -     * if <tt>e</tt> is an array of a primitive type, or as by calling
 71.3165 -     * <tt>Arrays.deepHashCode(e)</tt> recursively if <tt>e</tt> is an array
 71.3166 -     * of a reference type.  If <tt>a</tt> is <tt>null</tt>, this method
 71.3167 -     * returns 0.
 71.3168 -     *
 71.3169 -     * @param a the array whose deep-content-based hash code to compute
 71.3170 -     * @return a deep-content-based hash code for <tt>a</tt>
 71.3171 -     * @see #hashCode(Object[])
 71.3172 -     * @since 1.5
 71.3173 -     */
 71.3174 -    public static int deepHashCode(Object a[]) {
 71.3175 -        if (a == null)
 71.3176 -            return 0;
 71.3177 -
 71.3178 -        int result = 1;
 71.3179 -
 71.3180 -        for (Object element : a) {
 71.3181 -            int elementHash = 0;
 71.3182 -            if (element instanceof Object[])
 71.3183 -                elementHash = deepHashCode((Object[]) element);
 71.3184 -            else if (element instanceof byte[])
 71.3185 -                elementHash = hashCode((byte[]) element);
 71.3186 -            else if (element instanceof short[])
 71.3187 -                elementHash = hashCode((short[]) element);
 71.3188 -            else if (element instanceof int[])
 71.3189 -                elementHash = hashCode((int[]) element);
 71.3190 -            else if (element instanceof long[])
 71.3191 -                elementHash = hashCode((long[]) element);
 71.3192 -            else if (element instanceof char[])
 71.3193 -                elementHash = hashCode((char[]) element);
 71.3194 -            else if (element instanceof float[])
 71.3195 -                elementHash = hashCode((float[]) element);
 71.3196 -            else if (element instanceof double[])
 71.3197 -                elementHash = hashCode((double[]) element);
 71.3198 -            else if (element instanceof boolean[])
 71.3199 -                elementHash = hashCode((boolean[]) element);
 71.3200 -            else if (element != null)
 71.3201 -                elementHash = element.hashCode();
 71.3202 -
 71.3203 -            result = 31 * result + elementHash;
 71.3204 -        }
 71.3205 -
 71.3206 -        return result;
 71.3207 -    }
 71.3208 -
 71.3209 -    /**
 71.3210 -     * Returns <tt>true</tt> if the two specified arrays are <i>deeply
 71.3211 -     * equal</i> to one another.  Unlike the {@link #equals(Object[],Object[])}
 71.3212 -     * method, this method is appropriate for use with nested arrays of
 71.3213 -     * arbitrary depth.
 71.3214 -     *
 71.3215 -     * <p>Two array references are considered deeply equal if both
 71.3216 -     * are <tt>null</tt>, or if they refer to arrays that contain the same
 71.3217 -     * number of elements and all corresponding pairs of elements in the two
 71.3218 -     * arrays are deeply equal.
 71.3219 -     *
 71.3220 -     * <p>Two possibly <tt>null</tt> elements <tt>e1</tt> and <tt>e2</tt> are
 71.3221 -     * deeply equal if any of the following conditions hold:
 71.3222 -     * <ul>
 71.3223 -     *    <li> <tt>e1</tt> and <tt>e2</tt> are both arrays of object reference
 71.3224 -     *         types, and <tt>Arrays.deepEquals(e1, e2) would return true</tt>
 71.3225 -     *    <li> <tt>e1</tt> and <tt>e2</tt> are arrays of the same primitive
 71.3226 -     *         type, and the appropriate overloading of
 71.3227 -     *         <tt>Arrays.equals(e1, e2)</tt> would return true.
 71.3228 -     *    <li> <tt>e1 == e2</tt>
 71.3229 -     *    <li> <tt>e1.equals(e2)</tt> would return true.
 71.3230 -     * </ul>
 71.3231 -     * Note that this definition permits <tt>null</tt> elements at any depth.
 71.3232 -     *
 71.3233 -     * <p>If either of the specified arrays contain themselves as elements
 71.3234 -     * either directly or indirectly through one or more levels of arrays,
 71.3235 -     * the behavior of this method is undefined.
 71.3236 -     *
 71.3237 -     * @param a1 one array to be tested for equality
 71.3238 -     * @param a2 the other array to be tested for equality
 71.3239 -     * @return <tt>true</tt> if the two arrays are equal
 71.3240 -     * @see #equals(Object[],Object[])
 71.3241 -     * @see Objects#deepEquals(Object, Object)
 71.3242 -     * @since 1.5
 71.3243 -     */
 71.3244 -    public static boolean deepEquals(Object[] a1, Object[] a2) {
 71.3245 -        if (a1 == a2)
 71.3246 -            return true;
 71.3247 -        if (a1 == null || a2==null)
 71.3248 -            return false;
 71.3249 -        int length = a1.length;
 71.3250 -        if (a2.length != length)
 71.3251 -            return false;
 71.3252 -
 71.3253 -        for (int i = 0; i < length; i++) {
 71.3254 -            Object e1 = a1[i];
 71.3255 -            Object e2 = a2[i];
 71.3256 -
 71.3257 -            if (e1 == e2)
 71.3258 -                continue;
 71.3259 -            if (e1 == null)
 71.3260 -                return false;
 71.3261 -
 71.3262 -            // Figure out whether the two elements are equal
 71.3263 -            boolean eq = deepEquals0(e1, e2);
 71.3264 -
 71.3265 -            if (!eq)
 71.3266 -                return false;
 71.3267 -        }
 71.3268 -        return true;
 71.3269 -    }
 71.3270 -
 71.3271 -    static boolean deepEquals0(Object e1, Object e2) {
 71.3272 -        assert e1 != null;
 71.3273 -        boolean eq;
 71.3274 -        if (e1 instanceof Object[] && e2 instanceof Object[])
 71.3275 -            eq = deepEquals ((Object[]) e1, (Object[]) e2);
 71.3276 -        else if (e1 instanceof byte[] && e2 instanceof byte[])
 71.3277 -            eq = equals((byte[]) e1, (byte[]) e2);
 71.3278 -        else if (e1 instanceof short[] && e2 instanceof short[])
 71.3279 -            eq = equals((short[]) e1, (short[]) e2);
 71.3280 -        else if (e1 instanceof int[] && e2 instanceof int[])
 71.3281 -            eq = equals((int[]) e1, (int[]) e2);
 71.3282 -        else if (e1 instanceof long[] && e2 instanceof long[])
 71.3283 -            eq = equals((long[]) e1, (long[]) e2);
 71.3284 -        else if (e1 instanceof char[] && e2 instanceof char[])
 71.3285 -            eq = equals((char[]) e1, (char[]) e2);
 71.3286 -        else if (e1 instanceof float[] && e2 instanceof float[])
 71.3287 -            eq = equals((float[]) e1, (float[]) e2);
 71.3288 -        else if (e1 instanceof double[] && e2 instanceof double[])
 71.3289 -            eq = equals((double[]) e1, (double[]) e2);
 71.3290 -        else if (e1 instanceof boolean[] && e2 instanceof boolean[])
 71.3291 -            eq = equals((boolean[]) e1, (boolean[]) e2);
 71.3292 -        else
 71.3293 -            eq = e1.equals(e2);
 71.3294 -        return eq;
 71.3295 -    }
 71.3296 -
 71.3297 -    /**
 71.3298 -     * Returns a string representation of the contents of the specified array.
 71.3299 -     * The string representation consists of a list of the array's elements,
 71.3300 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3301 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3302 -     * space).  Elements are converted to strings as by
 71.3303 -     * <tt>String.valueOf(long)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 71.3304 -     * is <tt>null</tt>.
 71.3305 -     *
 71.3306 -     * @param a the array whose string representation to return
 71.3307 -     * @return a string representation of <tt>a</tt>
 71.3308 -     * @since 1.5
 71.3309 -     */
 71.3310 -    public static String toString(long[] a) {
 71.3311 -        if (a == null)
 71.3312 -            return "null";
 71.3313 -        int iMax = a.length - 1;
 71.3314 -        if (iMax == -1)
 71.3315 -            return "[]";
 71.3316 -
 71.3317 -        StringBuilder b = new StringBuilder();
 71.3318 -        b.append('[');
 71.3319 -        for (int i = 0; ; i++) {
 71.3320 -            b.append(a[i]);
 71.3321 -            if (i == iMax)
 71.3322 -                return b.append(']').toString();
 71.3323 -            b.append(", ");
 71.3324 -        }
 71.3325 -    }
 71.3326 -
 71.3327 -    /**
 71.3328 -     * Returns a string representation of the contents of the specified array.
 71.3329 -     * The string representation consists of a list of the array's elements,
 71.3330 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3331 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3332 -     * space).  Elements are converted to strings as by
 71.3333 -     * <tt>String.valueOf(int)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt> is
 71.3334 -     * <tt>null</tt>.
 71.3335 -     *
 71.3336 -     * @param a the array whose string representation to return
 71.3337 -     * @return a string representation of <tt>a</tt>
 71.3338 -     * @since 1.5
 71.3339 -     */
 71.3340 -    public static String toString(int[] a) {
 71.3341 -        if (a == null)
 71.3342 -            return "null";
 71.3343 -        int iMax = a.length - 1;
 71.3344 -        if (iMax == -1)
 71.3345 -            return "[]";
 71.3346 -
 71.3347 -        StringBuilder b = new StringBuilder();
 71.3348 -        b.append('[');
 71.3349 -        for (int i = 0; ; i++) {
 71.3350 -            b.append(a[i]);
 71.3351 -            if (i == iMax)
 71.3352 -                return b.append(']').toString();
 71.3353 -            b.append(", ");
 71.3354 -        }
 71.3355 -    }
 71.3356 -
 71.3357 -    /**
 71.3358 -     * Returns a string representation of the contents of the specified array.
 71.3359 -     * The string representation consists of a list of the array's elements,
 71.3360 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3361 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3362 -     * space).  Elements are converted to strings as by
 71.3363 -     * <tt>String.valueOf(short)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 71.3364 -     * is <tt>null</tt>.
 71.3365 -     *
 71.3366 -     * @param a the array whose string representation to return
 71.3367 -     * @return a string representation of <tt>a</tt>
 71.3368 -     * @since 1.5
 71.3369 -     */
 71.3370 -    public static String toString(short[] a) {
 71.3371 -        if (a == null)
 71.3372 -            return "null";
 71.3373 -        int iMax = a.length - 1;
 71.3374 -        if (iMax == -1)
 71.3375 -            return "[]";
 71.3376 -
 71.3377 -        StringBuilder b = new StringBuilder();
 71.3378 -        b.append('[');
 71.3379 -        for (int i = 0; ; i++) {
 71.3380 -            b.append(a[i]);
 71.3381 -            if (i == iMax)
 71.3382 -                return b.append(']').toString();
 71.3383 -            b.append(", ");
 71.3384 -        }
 71.3385 -    }
 71.3386 -
 71.3387 -    /**
 71.3388 -     * Returns a string representation of the contents of the specified array.
 71.3389 -     * The string representation consists of a list of the array's elements,
 71.3390 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3391 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3392 -     * space).  Elements are converted to strings as by
 71.3393 -     * <tt>String.valueOf(char)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 71.3394 -     * is <tt>null</tt>.
 71.3395 -     *
 71.3396 -     * @param a the array whose string representation to return
 71.3397 -     * @return a string representation of <tt>a</tt>
 71.3398 -     * @since 1.5
 71.3399 -     */
 71.3400 -    public static String toString(char[] a) {
 71.3401 -        if (a == null)
 71.3402 -            return "null";
 71.3403 -        int iMax = a.length - 1;
 71.3404 -        if (iMax == -1)
 71.3405 -            return "[]";
 71.3406 -
 71.3407 -        StringBuilder b = new StringBuilder();
 71.3408 -        b.append('[');
 71.3409 -        for (int i = 0; ; i++) {
 71.3410 -            b.append(a[i]);
 71.3411 -            if (i == iMax)
 71.3412 -                return b.append(']').toString();
 71.3413 -            b.append(", ");
 71.3414 -        }
 71.3415 -    }
 71.3416 -
 71.3417 -    /**
 71.3418 -     * Returns a string representation of the contents of the specified array.
 71.3419 -     * The string representation consists of a list of the array's elements,
 71.3420 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements
 71.3421 -     * are separated by the characters <tt>", "</tt> (a comma followed
 71.3422 -     * by a space).  Elements are converted to strings as by
 71.3423 -     * <tt>String.valueOf(byte)</tt>.  Returns <tt>"null"</tt> if
 71.3424 -     * <tt>a</tt> is <tt>null</tt>.
 71.3425 -     *
 71.3426 -     * @param a the array whose string representation to return
 71.3427 -     * @return a string representation of <tt>a</tt>
 71.3428 -     * @since 1.5
 71.3429 -     */
 71.3430 -    public static String toString(byte[] a) {
 71.3431 -        if (a == null)
 71.3432 -            return "null";
 71.3433 -        int iMax = a.length - 1;
 71.3434 -        if (iMax == -1)
 71.3435 -            return "[]";
 71.3436 -
 71.3437 -        StringBuilder b = new StringBuilder();
 71.3438 -        b.append('[');
 71.3439 -        for (int i = 0; ; i++) {
 71.3440 -            b.append(a[i]);
 71.3441 -            if (i == iMax)
 71.3442 -                return b.append(']').toString();
 71.3443 -            b.append(", ");
 71.3444 -        }
 71.3445 -    }
 71.3446 -
 71.3447 -    /**
 71.3448 -     * Returns a string representation of the contents of the specified array.
 71.3449 -     * The string representation consists of a list of the array's elements,
 71.3450 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3451 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3452 -     * space).  Elements are converted to strings as by
 71.3453 -     * <tt>String.valueOf(boolean)</tt>.  Returns <tt>"null"</tt> if
 71.3454 -     * <tt>a</tt> is <tt>null</tt>.
 71.3455 -     *
 71.3456 -     * @param a the array whose string representation to return
 71.3457 -     * @return a string representation of <tt>a</tt>
 71.3458 -     * @since 1.5
 71.3459 -     */
 71.3460 -    public static String toString(boolean[] a) {
 71.3461 -        if (a == null)
 71.3462 -            return "null";
 71.3463 -        int iMax = a.length - 1;
 71.3464 -        if (iMax == -1)
 71.3465 -            return "[]";
 71.3466 -
 71.3467 -        StringBuilder b = new StringBuilder();
 71.3468 -        b.append('[');
 71.3469 -        for (int i = 0; ; i++) {
 71.3470 -            b.append(a[i]);
 71.3471 -            if (i == iMax)
 71.3472 -                return b.append(']').toString();
 71.3473 -            b.append(", ");
 71.3474 -        }
 71.3475 -    }
 71.3476 -
 71.3477 -    /**
 71.3478 -     * Returns a string representation of the contents of the specified array.
 71.3479 -     * The string representation consists of a list of the array's elements,
 71.3480 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3481 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3482 -     * space).  Elements are converted to strings as by
 71.3483 -     * <tt>String.valueOf(float)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 71.3484 -     * is <tt>null</tt>.
 71.3485 -     *
 71.3486 -     * @param a the array whose string representation to return
 71.3487 -     * @return a string representation of <tt>a</tt>
 71.3488 -     * @since 1.5
 71.3489 -     */
 71.3490 -    public static String toString(float[] a) {
 71.3491 -        if (a == null)
 71.3492 -            return "null";
 71.3493 -
 71.3494 -        int iMax = a.length - 1;
 71.3495 -        if (iMax == -1)
 71.3496 -            return "[]";
 71.3497 -
 71.3498 -        StringBuilder b = new StringBuilder();
 71.3499 -        b.append('[');
 71.3500 -        for (int i = 0; ; i++) {
 71.3501 -            b.append(a[i]);
 71.3502 -            if (i == iMax)
 71.3503 -                return b.append(']').toString();
 71.3504 -            b.append(", ");
 71.3505 -        }
 71.3506 -    }
 71.3507 -
 71.3508 -    /**
 71.3509 -     * Returns a string representation of the contents of the specified array.
 71.3510 -     * The string representation consists of a list of the array's elements,
 71.3511 -     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
 71.3512 -     * separated by the characters <tt>", "</tt> (a comma followed by a
 71.3513 -     * space).  Elements are converted to strings as by
 71.3514 -     * <tt>String.valueOf(double)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
 71.3515 -     * is <tt>null</tt>.
 71.3516 -     *
 71.3517 -     * @param a the array whose string representation to return
 71.3518 -     * @return a string representation of <tt>a</tt>
 71.3519 -     * @since 1.5
 71.3520 -     */
 71.3521 -    public static String toString(double[] a) {
 71.3522 -        if (a == null)
 71.3523 -            return "null";
 71.3524 -        int iMax = a.length - 1;
 71.3525 -        if (iMax == -1)
 71.3526 -            return "[]";
 71.3527 -
 71.3528 -        StringBuilder b = new StringBuilder();
 71.3529 -        b.append('[');
 71.3530 -        for (int i = 0; ; i++) {
 71.3531 -            b.append(a[i]);
 71.3532 -            if (i == iMax)
 71.3533 -                return b.append(']').toString();
 71.3534 -            b.append(", ");
 71.3535 -        }
 71.3536 -    }
 71.3537 -
 71.3538 -    /**
 71.3539 -     * Returns a string representation of the contents of the specified array.
 71.3540 -     * If the array contains other arrays as elements, they are converted to
 71.3541 -     * strings by the {@link Object#toString} method inherited from
 71.3542 -     * <tt>Object</tt>, which describes their <i>identities</i> rather than
 71.3543 -     * their contents.
 71.3544 -     *
 71.3545 -     * <p>The value returned by this method is equal to the value that would
 71.3546 -     * be returned by <tt>Arrays.asList(a).toString()</tt>, unless <tt>a</tt>
 71.3547 -     * is <tt>null</tt>, in which case <tt>"null"</tt> is returned.
 71.3548 -     *
 71.3549 -     * @param a the array whose string representation to return
 71.3550 -     * @return a string representation of <tt>a</tt>
 71.3551 -     * @see #deepToString(Object[])
 71.3552 -     * @since 1.5
 71.3553 -     */
 71.3554 -    public static String toString(Object[] a) {
 71.3555 -        if (a == null)
 71.3556 -            return "null";
 71.3557 -
 71.3558 -        int iMax = a.length - 1;
 71.3559 -        if (iMax == -1)
 71.3560 -            return "[]";
 71.3561 -
 71.3562 -        StringBuilder b = new StringBuilder();
 71.3563 -        b.append('[');
 71.3564 -        for (int i = 0; ; i++) {
 71.3565 -            b.append(String.valueOf(a[i]));
 71.3566 -            if (i == iMax)
 71.3567 -                return b.append(']').toString();
 71.3568 -            b.append(", ");
 71.3569 -        }
 71.3570 -    }
 71.3571 -
 71.3572 -    /**
 71.3573 -     * Returns a string representation of the "deep contents" of the specified
 71.3574 -     * array.  If the array contains other arrays as elements, the string
 71.3575 -     * representation contains their contents and so on.  This method is
 71.3576 -     * designed for converting multidimensional arrays to strings.
 71.3577 -     *
 71.3578 -     * <p>The string representation consists of a list of the array's
 71.3579 -     * elements, enclosed in square brackets (<tt>"[]"</tt>).  Adjacent
 71.3580 -     * elements are separated by the characters <tt>", "</tt> (a comma
 71.3581 -     * followed by a space).  Elements are converted to strings as by
 71.3582 -     * <tt>String.valueOf(Object)</tt>, unless they are themselves
 71.3583 -     * arrays.
 71.3584 -     *
 71.3585 -     * <p>If an element <tt>e</tt> is an array of a primitive type, it is
 71.3586 -     * converted to a string as by invoking the appropriate overloading of
 71.3587 -     * <tt>Arrays.toString(e)</tt>.  If an element <tt>e</tt> is an array of a
 71.3588 -     * reference type, it is converted to a string as by invoking
 71.3589 -     * this method recursively.
 71.3590 -     *
 71.3591 -     * <p>To avoid infinite recursion, if the specified array contains itself
 71.3592 -     * as an element, or contains an indirect reference to itself through one
 71.3593 -     * or more levels of arrays, the self-reference is converted to the string
 71.3594 -     * <tt>"[...]"</tt>.  For example, an array containing only a reference
 71.3595 -     * to itself would be rendered as <tt>"[[...]]"</tt>.
 71.3596 -     *
 71.3597 -     * <p>This method returns <tt>"null"</tt> if the specified array
 71.3598 -     * is <tt>null</tt>.
 71.3599 -     *
 71.3600 -     * @param a the array whose string representation to return
 71.3601 -     * @return a string representation of <tt>a</tt>
 71.3602 -     * @see #toString(Object[])
 71.3603 -     * @since 1.5
 71.3604 -     */
 71.3605 -    public static String deepToString(Object[] a) {
 71.3606 -        if (a == null)
 71.3607 -            return "null";
 71.3608 -
 71.3609 -        int bufLen = 20 * a.length;
 71.3610 -        if (a.length != 0 && bufLen <= 0)
 71.3611 -            bufLen = Integer.MAX_VALUE;
 71.3612 -        StringBuilder buf = new StringBuilder(bufLen);
 71.3613 -        deepToString(a, buf, new HashSet<Object[]>());
 71.3614 -        return buf.toString();
 71.3615 -    }
 71.3616 -
 71.3617 -    private static void deepToString(Object[] a, StringBuilder buf,
 71.3618 -                                     Set<Object[]> dejaVu) {
 71.3619 -        if (a == null) {
 71.3620 -            buf.append("null");
 71.3621 -            return;
 71.3622 -        }
 71.3623 -        int iMax = a.length - 1;
 71.3624 -        if (iMax == -1) {
 71.3625 -            buf.append("[]");
 71.3626 -            return;
 71.3627 -        }
 71.3628 -
 71.3629 -        dejaVu.add(a);
 71.3630 -        buf.append('[');
 71.3631 -        for (int i = 0; ; i++) {
 71.3632 -
 71.3633 -            Object element = a[i];
 71.3634 -            if (element == null) {
 71.3635 -                buf.append("null");
 71.3636 -            } else {
 71.3637 -                Class eClass = element.getClass();
 71.3638 -
 71.3639 -                if (eClass.isArray()) {
 71.3640 -                    if (eClass == byte[].class)
 71.3641 -                        buf.append(toString((byte[]) element));
 71.3642 -                    else if (eClass == short[].class)
 71.3643 -                        buf.append(toString((short[]) element));
 71.3644 -                    else if (eClass == int[].class)
 71.3645 -                        buf.append(toString((int[]) element));
 71.3646 -                    else if (eClass == long[].class)
 71.3647 -                        buf.append(toString((long[]) element));
 71.3648 -                    else if (eClass == char[].class)
 71.3649 -                        buf.append(toString((char[]) element));
 71.3650 -                    else if (eClass == float[].class)
 71.3651 -                        buf.append(toString((float[]) element));
 71.3652 -                    else if (eClass == double[].class)
 71.3653 -                        buf.append(toString((double[]) element));
 71.3654 -                    else if (eClass == boolean[].class)
 71.3655 -                        buf.append(toString((boolean[]) element));
 71.3656 -                    else { // element is an array of object references
 71.3657 -                        if (dejaVu.contains(element))
 71.3658 -                            buf.append("[...]");
 71.3659 -                        else
 71.3660 -                            deepToString((Object[])element, buf, dejaVu);
 71.3661 -                    }
 71.3662 -                } else {  // element is non-null and not an array
 71.3663 -                    buf.append(element.toString());
 71.3664 -                }
 71.3665 -            }
 71.3666 -            if (i == iMax)
 71.3667 -                break;
 71.3668 -            buf.append(", ");
 71.3669 -        }
 71.3670 -        buf.append(']');
 71.3671 -        dejaVu.remove(a);
 71.3672 -    }
 71.3673 -}
    72.1 --- a/emul/compact/src/main/java/java/util/Collection.java	Mon Feb 25 19:00:08 2013 +0100
    72.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.3 @@ -1,456 +0,0 @@
    72.4 -/*
    72.5 - * Copyright (c) 1997, 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 - * The root interface in the <i>collection hierarchy</i>.  A collection
   72.33 - * represents a group of objects, known as its <i>elements</i>.  Some
   72.34 - * collections allow duplicate elements and others do not.  Some are ordered
   72.35 - * and others unordered.  The JDK does not provide any <i>direct</i>
   72.36 - * implementations of this interface: it provides implementations of more
   72.37 - * specific subinterfaces like <tt>Set</tt> and <tt>List</tt>.  This interface
   72.38 - * is typically used to pass collections around and manipulate them where
   72.39 - * maximum generality is desired.
   72.40 - *
   72.41 - * <p><i>Bags</i> or <i>multisets</i> (unordered collections that may contain
   72.42 - * duplicate elements) should implement this interface directly.
   72.43 - *
   72.44 - * <p>All general-purpose <tt>Collection</tt> implementation classes (which
   72.45 - * typically implement <tt>Collection</tt> indirectly through one of its
   72.46 - * subinterfaces) should provide two "standard" constructors: a void (no
   72.47 - * arguments) constructor, which creates an empty collection, and a
   72.48 - * constructor with a single argument of type <tt>Collection</tt>, which
   72.49 - * creates a new collection with the same elements as its argument.  In
   72.50 - * effect, the latter constructor allows the user to copy any collection,
   72.51 - * producing an equivalent collection of the desired implementation type.
   72.52 - * There is no way to enforce this convention (as interfaces cannot contain
   72.53 - * constructors) but all of the general-purpose <tt>Collection</tt>
   72.54 - * implementations in the Java platform libraries comply.
   72.55 - *
   72.56 - * <p>The "destructive" methods contained in this interface, that is, the
   72.57 - * methods that modify the collection on which they operate, are specified to
   72.58 - * throw <tt>UnsupportedOperationException</tt> if this collection does not
   72.59 - * support the operation.  If this is the case, these methods may, but are not
   72.60 - * required to, throw an <tt>UnsupportedOperationException</tt> if the
   72.61 - * invocation would have no effect on the collection.  For example, invoking
   72.62 - * the {@link #addAll(Collection)} method on an unmodifiable collection may,
   72.63 - * but is not required to, throw the exception if the collection to be added
   72.64 - * is empty.
   72.65 - *
   72.66 - * <p><a name="optional-restrictions"/>
   72.67 - * Some collection implementations have restrictions on the elements that
   72.68 - * they may contain.  For example, some implementations prohibit null elements,
   72.69 - * and some have restrictions on the types of their elements.  Attempting to
   72.70 - * add an ineligible element throws an unchecked exception, typically
   72.71 - * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
   72.72 - * to query the presence of an ineligible element may throw an exception,
   72.73 - * or it may simply return false; some implementations will exhibit the former
   72.74 - * behavior and some will exhibit the latter.  More generally, attempting an
   72.75 - * operation on an ineligible element whose completion would not result in
   72.76 - * the insertion of an ineligible element into the collection may throw an
   72.77 - * exception or it may succeed, at the option of the implementation.
   72.78 - * Such exceptions are marked as "optional" in the specification for this
   72.79 - * interface.
   72.80 - *
   72.81 - * <p>It is up to each collection to determine its own synchronization
   72.82 - * policy.  In the absence of a stronger guarantee by the
   72.83 - * implementation, undefined behavior may result from the invocation
   72.84 - * of any method on a collection that is being mutated by another
   72.85 - * thread; this includes direct invocations, passing the collection to
   72.86 - * a method that might perform invocations, and using an existing
   72.87 - * iterator to examine the collection.
   72.88 - *
   72.89 - * <p>Many methods in Collections Framework interfaces are defined in
   72.90 - * terms of the {@link Object#equals(Object) equals} method.  For example,
   72.91 - * the specification for the {@link #contains(Object) contains(Object o)}
   72.92 - * method says: "returns <tt>true</tt> if and only if this collection
   72.93 - * contains at least one element <tt>e</tt> such that
   72.94 - * <tt>(o==null ? e==null : o.equals(e))</tt>."  This specification should
   72.95 - * <i>not</i> be construed to imply that invoking <tt>Collection.contains</tt>
   72.96 - * with a non-null argument <tt>o</tt> will cause <tt>o.equals(e)</tt> to be
   72.97 - * invoked for any element <tt>e</tt>.  Implementations are free to implement
   72.98 - * optimizations whereby the <tt>equals</tt> invocation is avoided, for
   72.99 - * example, by first comparing the hash codes of the two elements.  (The
  72.100 - * {@link Object#hashCode()} specification guarantees that two objects with
  72.101 - * unequal hash codes cannot be equal.)  More generally, implementations of
  72.102 - * the various Collections Framework interfaces are free to take advantage of
  72.103 - * the specified behavior of underlying {@link Object} methods wherever the
  72.104 - * implementor deems it appropriate.
  72.105 - *
  72.106 - * <p>This interface is a member of the
  72.107 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  72.108 - * Java Collections Framework</a>.
  72.109 - *
  72.110 - * @param <E> the type of elements in this collection
  72.111 - *
  72.112 - * @author  Josh Bloch
  72.113 - * @author  Neal Gafter
  72.114 - * @see     Set
  72.115 - * @see     List
  72.116 - * @see     Map
  72.117 - * @see     SortedSet
  72.118 - * @see     SortedMap
  72.119 - * @see     HashSet
  72.120 - * @see     TreeSet
  72.121 - * @see     ArrayList
  72.122 - * @see     LinkedList
  72.123 - * @see     Vector
  72.124 - * @see     Collections
  72.125 - * @see     Arrays
  72.126 - * @see     AbstractCollection
  72.127 - * @since 1.2
  72.128 - */
  72.129 -
  72.130 -public interface Collection<E> extends Iterable<E> {
  72.131 -    // Query Operations
  72.132 -
  72.133 -    /**
  72.134 -     * Returns the number of elements in this collection.  If this collection
  72.135 -     * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
  72.136 -     * <tt>Integer.MAX_VALUE</tt>.
  72.137 -     *
  72.138 -     * @return the number of elements in this collection
  72.139 -     */
  72.140 -    int size();
  72.141 -
  72.142 -    /**
  72.143 -     * Returns <tt>true</tt> if this collection contains no elements.
  72.144 -     *
  72.145 -     * @return <tt>true</tt> if this collection contains no elements
  72.146 -     */
  72.147 -    boolean isEmpty();
  72.148 -
  72.149 -    /**
  72.150 -     * Returns <tt>true</tt> if this collection contains the specified element.
  72.151 -     * More formally, returns <tt>true</tt> if and only if this collection
  72.152 -     * contains at least one element <tt>e</tt> such that
  72.153 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  72.154 -     *
  72.155 -     * @param o element whose presence in this collection is to be tested
  72.156 -     * @return <tt>true</tt> if this collection contains the specified
  72.157 -     *         element
  72.158 -     * @throws ClassCastException if the type of the specified element
  72.159 -     *         is incompatible with this collection
  72.160 -     *         (<a href="#optional-restrictions">optional</a>)
  72.161 -     * @throws NullPointerException if the specified element is null and this
  72.162 -     *         collection does not permit null elements
  72.163 -     *         (<a href="#optional-restrictions">optional</a>)
  72.164 -     */
  72.165 -    boolean contains(Object o);
  72.166 -
  72.167 -    /**
  72.168 -     * Returns an iterator over the elements in this collection.  There are no
  72.169 -     * guarantees concerning the order in which the elements are returned
  72.170 -     * (unless this collection is an instance of some class that provides a
  72.171 -     * guarantee).
  72.172 -     *
  72.173 -     * @return an <tt>Iterator</tt> over the elements in this collection
  72.174 -     */
  72.175 -    Iterator<E> iterator();
  72.176 -
  72.177 -    /**
  72.178 -     * Returns an array containing all of the elements in this collection.
  72.179 -     * If this collection makes any guarantees as to what order its elements
  72.180 -     * are returned by its iterator, this method must return the elements in
  72.181 -     * the same order.
  72.182 -     *
  72.183 -     * <p>The returned array will be "safe" in that no references to it are
  72.184 -     * maintained by this collection.  (In other words, this method must
  72.185 -     * allocate a new array even if this collection is backed by an array).
  72.186 -     * The caller is thus free to modify the returned array.
  72.187 -     *
  72.188 -     * <p>This method acts as bridge between array-based and collection-based
  72.189 -     * APIs.
  72.190 -     *
  72.191 -     * @return an array containing all of the elements in this collection
  72.192 -     */
  72.193 -    Object[] toArray();
  72.194 -
  72.195 -    /**
  72.196 -     * Returns an array containing all of the elements in this collection;
  72.197 -     * the runtime type of the returned array is that of the specified array.
  72.198 -     * If the collection fits in the specified array, it is returned therein.
  72.199 -     * Otherwise, a new array is allocated with the runtime type of the
  72.200 -     * specified array and the size of this collection.
  72.201 -     *
  72.202 -     * <p>If this collection fits in the specified array with room to spare
  72.203 -     * (i.e., the array has more elements than this collection), the element
  72.204 -     * in the array immediately following the end of the collection is set to
  72.205 -     * <tt>null</tt>.  (This is useful in determining the length of this
  72.206 -     * collection <i>only</i> if the caller knows that this collection does
  72.207 -     * not contain any <tt>null</tt> elements.)
  72.208 -     *
  72.209 -     * <p>If this collection makes any guarantees as to what order its elements
  72.210 -     * are returned by its iterator, this method must return the elements in
  72.211 -     * the same order.
  72.212 -     *
  72.213 -     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  72.214 -     * array-based and collection-based APIs.  Further, this method allows
  72.215 -     * precise control over the runtime type of the output array, and may,
  72.216 -     * under certain circumstances, be used to save allocation costs.
  72.217 -     *
  72.218 -     * <p>Suppose <tt>x</tt> is a collection known to contain only strings.
  72.219 -     * The following code can be used to dump the collection into a newly
  72.220 -     * allocated array of <tt>String</tt>:
  72.221 -     *
  72.222 -     * <pre>
  72.223 -     *     String[] y = x.toArray(new String[0]);</pre>
  72.224 -     *
  72.225 -     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  72.226 -     * <tt>toArray()</tt>.
  72.227 -     *
  72.228 -     * @param a the array into which the elements of this collection are to be
  72.229 -     *        stored, if it is big enough; otherwise, a new array of the same
  72.230 -     *        runtime type is allocated for this purpose.
  72.231 -     * @return an array containing all of the elements in this collection
  72.232 -     * @throws ArrayStoreException if the runtime type of the specified array
  72.233 -     *         is not a supertype of the runtime type of every element in
  72.234 -     *         this collection
  72.235 -     * @throws NullPointerException if the specified array is null
  72.236 -     */
  72.237 -    <T> T[] toArray(T[] a);
  72.238 -
  72.239 -    // Modification Operations
  72.240 -
  72.241 -    /**
  72.242 -     * Ensures that this collection contains the specified element (optional
  72.243 -     * operation).  Returns <tt>true</tt> if this collection changed as a
  72.244 -     * result of the call.  (Returns <tt>false</tt> if this collection does
  72.245 -     * not permit duplicates and already contains the specified element.)<p>
  72.246 -     *
  72.247 -     * Collections that support this operation may place limitations on what
  72.248 -     * elements may be added to this collection.  In particular, some
  72.249 -     * collections will refuse to add <tt>null</tt> elements, and others will
  72.250 -     * impose restrictions on the type of elements that may be added.
  72.251 -     * Collection classes should clearly specify in their documentation any
  72.252 -     * restrictions on what elements may be added.<p>
  72.253 -     *
  72.254 -     * If a collection refuses to add a particular element for any reason
  72.255 -     * other than that it already contains the element, it <i>must</i> throw
  72.256 -     * an exception (rather than returning <tt>false</tt>).  This preserves
  72.257 -     * the invariant that a collection always contains the specified element
  72.258 -     * after this call returns.
  72.259 -     *
  72.260 -     * @param e element whose presence in this collection is to be ensured
  72.261 -     * @return <tt>true</tt> if this collection changed as a result of the
  72.262 -     *         call
  72.263 -     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  72.264 -     *         is not supported by this collection
  72.265 -     * @throws ClassCastException if the class of the specified element
  72.266 -     *         prevents it from being added to this collection
  72.267 -     * @throws NullPointerException if the specified element is null and this
  72.268 -     *         collection does not permit null elements
  72.269 -     * @throws IllegalArgumentException if some property of the element
  72.270 -     *         prevents it from being added to this collection
  72.271 -     * @throws IllegalStateException if the element cannot be added at this
  72.272 -     *         time due to insertion restrictions
  72.273 -     */
  72.274 -    boolean add(E e);
  72.275 -
  72.276 -    /**
  72.277 -     * Removes a single instance of the specified element from this
  72.278 -     * collection, if it is present (optional operation).  More formally,
  72.279 -     * removes an element <tt>e</tt> such that
  72.280 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
  72.281 -     * this collection contains one or more such elements.  Returns
  72.282 -     * <tt>true</tt> if this collection contained the specified element (or
  72.283 -     * equivalently, if this collection changed as a result of the call).
  72.284 -     *
  72.285 -     * @param o element to be removed from this collection, if present
  72.286 -     * @return <tt>true</tt> if an element was removed as a result of this call
  72.287 -     * @throws ClassCastException if the type of the specified element
  72.288 -     *         is incompatible with this collection
  72.289 -     *         (<a href="#optional-restrictions">optional</a>)
  72.290 -     * @throws NullPointerException if the specified element is null and this
  72.291 -     *         collection does not permit null elements
  72.292 -     *         (<a href="#optional-restrictions">optional</a>)
  72.293 -     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  72.294 -     *         is not supported by this collection
  72.295 -     */
  72.296 -    boolean remove(Object o);
  72.297 -
  72.298 -
  72.299 -    // Bulk Operations
  72.300 -
  72.301 -    /**
  72.302 -     * Returns <tt>true</tt> if this collection contains all of the elements
  72.303 -     * in the specified collection.
  72.304 -     *
  72.305 -     * @param  c collection to be checked for containment in this collection
  72.306 -     * @return <tt>true</tt> if this collection contains all of the elements
  72.307 -     *         in the specified collection
  72.308 -     * @throws ClassCastException if the types of one or more elements
  72.309 -     *         in the specified collection are incompatible with this
  72.310 -     *         collection
  72.311 -     *         (<a href="#optional-restrictions">optional</a>)
  72.312 -     * @throws NullPointerException if the specified collection contains one
  72.313 -     *         or more null elements and this collection does not permit null
  72.314 -     *         elements
  72.315 -     *         (<a href="#optional-restrictions">optional</a>),
  72.316 -     *         or if the specified collection is null.
  72.317 -     * @see    #contains(Object)
  72.318 -     */
  72.319 -    boolean containsAll(Collection<?> c);
  72.320 -
  72.321 -    /**
  72.322 -     * Adds all of the elements in the specified collection to this collection
  72.323 -     * (optional operation).  The behavior of this operation is undefined if
  72.324 -     * the specified collection is modified while the operation is in progress.
  72.325 -     * (This implies that the behavior of this call is undefined if the
  72.326 -     * specified collection is this collection, and this collection is
  72.327 -     * nonempty.)
  72.328 -     *
  72.329 -     * @param c collection containing elements to be added to this collection
  72.330 -     * @return <tt>true</tt> if this collection changed as a result of the call
  72.331 -     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  72.332 -     *         is not supported by this collection
  72.333 -     * @throws ClassCastException if the class of an element of the specified
  72.334 -     *         collection prevents it from being added to this collection
  72.335 -     * @throws NullPointerException if the specified collection contains a
  72.336 -     *         null element and this collection does not permit null elements,
  72.337 -     *         or if the specified collection is null
  72.338 -     * @throws IllegalArgumentException if some property of an element of the
  72.339 -     *         specified collection prevents it from being added to this
  72.340 -     *         collection
  72.341 -     * @throws IllegalStateException if not all the elements can be added at
  72.342 -     *         this time due to insertion restrictions
  72.343 -     * @see #add(Object)
  72.344 -     */
  72.345 -    boolean addAll(Collection<? extends E> c);
  72.346 -
  72.347 -    /**
  72.348 -     * Removes all of this collection's elements that are also contained in the
  72.349 -     * specified collection (optional operation).  After this call returns,
  72.350 -     * this collection will contain no elements in common with the specified
  72.351 -     * collection.
  72.352 -     *
  72.353 -     * @param c collection containing elements to be removed from this collection
  72.354 -     * @return <tt>true</tt> if this collection changed as a result of the
  72.355 -     *         call
  72.356 -     * @throws UnsupportedOperationException if the <tt>removeAll</tt> method
  72.357 -     *         is not supported by this collection
  72.358 -     * @throws ClassCastException if the types of one or more elements
  72.359 -     *         in this collection are incompatible with the specified
  72.360 -     *         collection
  72.361 -     *         (<a href="#optional-restrictions">optional</a>)
  72.362 -     * @throws NullPointerException if this collection contains one or more
  72.363 -     *         null elements and the specified collection does not support
  72.364 -     *         null elements
  72.365 -     *         (<a href="#optional-restrictions">optional</a>),
  72.366 -     *         or if the specified collection is null
  72.367 -     * @see #remove(Object)
  72.368 -     * @see #contains(Object)
  72.369 -     */
  72.370 -    boolean removeAll(Collection<?> c);
  72.371 -
  72.372 -    /**
  72.373 -     * Retains only the elements in this collection that are contained in the
  72.374 -     * specified collection (optional operation).  In other words, removes from
  72.375 -     * this collection all of its elements that are not contained in the
  72.376 -     * specified collection.
  72.377 -     *
  72.378 -     * @param c collection containing elements to be retained in this collection
  72.379 -     * @return <tt>true</tt> if this collection changed as a result of the call
  72.380 -     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
  72.381 -     *         is not supported by this collection
  72.382 -     * @throws ClassCastException if the types of one or more elements
  72.383 -     *         in this collection are incompatible with the specified
  72.384 -     *         collection
  72.385 -     *         (<a href="#optional-restrictions">optional</a>)
  72.386 -     * @throws NullPointerException if this collection contains one or more
  72.387 -     *         null elements and the specified collection does not permit null
  72.388 -     *         elements
  72.389 -     *         (<a href="#optional-restrictions">optional</a>),
  72.390 -     *         or if the specified collection is null
  72.391 -     * @see #remove(Object)
  72.392 -     * @see #contains(Object)
  72.393 -     */
  72.394 -    boolean retainAll(Collection<?> c);
  72.395 -
  72.396 -    /**
  72.397 -     * Removes all of the elements from this collection (optional operation).
  72.398 -     * The collection will be empty after this method returns.
  72.399 -     *
  72.400 -     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
  72.401 -     *         is not supported by this collection
  72.402 -     */
  72.403 -    void clear();
  72.404 -
  72.405 -
  72.406 -    // Comparison and hashing
  72.407 -
  72.408 -    /**
  72.409 -     * Compares the specified object with this collection for equality. <p>
  72.410 -     *
  72.411 -     * While the <tt>Collection</tt> interface adds no stipulations to the
  72.412 -     * general contract for the <tt>Object.equals</tt>, programmers who
  72.413 -     * implement the <tt>Collection</tt> interface "directly" (in other words,
  72.414 -     * create a class that is a <tt>Collection</tt> but is not a <tt>Set</tt>
  72.415 -     * or a <tt>List</tt>) must exercise care if they choose to override the
  72.416 -     * <tt>Object.equals</tt>.  It is not necessary to do so, and the simplest
  72.417 -     * course of action is to rely on <tt>Object</tt>'s implementation, but
  72.418 -     * the implementor may wish to implement a "value comparison" in place of
  72.419 -     * the default "reference comparison."  (The <tt>List</tt> and
  72.420 -     * <tt>Set</tt> interfaces mandate such value comparisons.)<p>
  72.421 -     *
  72.422 -     * The general contract for the <tt>Object.equals</tt> method states that
  72.423 -     * equals must be symmetric (in other words, <tt>a.equals(b)</tt> if and
  72.424 -     * only if <tt>b.equals(a)</tt>).  The contracts for <tt>List.equals</tt>
  72.425 -     * and <tt>Set.equals</tt> state that lists are only equal to other lists,
  72.426 -     * and sets to other sets.  Thus, a custom <tt>equals</tt> method for a
  72.427 -     * collection class that implements neither the <tt>List</tt> nor
  72.428 -     * <tt>Set</tt> interface must return <tt>false</tt> when this collection
  72.429 -     * is compared to any list or set.  (By the same logic, it is not possible
  72.430 -     * to write a class that correctly implements both the <tt>Set</tt> and
  72.431 -     * <tt>List</tt> interfaces.)
  72.432 -     *
  72.433 -     * @param o object to be compared for equality with this collection
  72.434 -     * @return <tt>true</tt> if the specified object is equal to this
  72.435 -     * collection
  72.436 -     *
  72.437 -     * @see Object#equals(Object)
  72.438 -     * @see Set#equals(Object)
  72.439 -     * @see List#equals(Object)
  72.440 -     */
  72.441 -    boolean equals(Object o);
  72.442 -
  72.443 -    /**
  72.444 -     * Returns the hash code value for this collection.  While the
  72.445 -     * <tt>Collection</tt> interface adds no stipulations to the general
  72.446 -     * contract for the <tt>Object.hashCode</tt> method, programmers should
  72.447 -     * take note that any class that overrides the <tt>Object.equals</tt>
  72.448 -     * method must also override the <tt>Object.hashCode</tt> method in order
  72.449 -     * to satisfy the general contract for the <tt>Object.hashCode</tt> method.
  72.450 -     * In particular, <tt>c1.equals(c2)</tt> implies that
  72.451 -     * <tt>c1.hashCode()==c2.hashCode()</tt>.
  72.452 -     *
  72.453 -     * @return the hash code value for this collection
  72.454 -     *
  72.455 -     * @see Object#hashCode()
  72.456 -     * @see Object#equals(Object)
  72.457 -     */
  72.458 -    int hashCode();
  72.459 -}
    73.1 --- a/emul/compact/src/main/java/java/util/Collections.java	Mon Feb 25 19:00:08 2013 +0100
    73.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.3 @@ -1,3953 +0,0 @@
    73.4 -/*
    73.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
    73.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    73.7 - *
    73.8 - * This code is free software; you can redistribute it and/or modify it
    73.9 - * under the terms of the GNU General Public License version 2 only, as
   73.10 - * published by the Free Software Foundation.  Oracle designates this
   73.11 - * particular file as subject to the "Classpath" exception as provided
   73.12 - * by Oracle in the LICENSE file that accompanied this code.
   73.13 - *
   73.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   73.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   73.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   73.17 - * version 2 for more details (a copy is included in the LICENSE file that
   73.18 - * accompanied this code).
   73.19 - *
   73.20 - * You should have received a copy of the GNU General Public License version
   73.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   73.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   73.23 - *
   73.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   73.25 - * or visit www.oracle.com if you need additional information or have any
   73.26 - * questions.
   73.27 - */
   73.28 -
   73.29 -package java.util;
   73.30 -import java.io.Serializable;
   73.31 -import java.io.IOException;
   73.32 -import java.lang.reflect.Array;
   73.33 -
   73.34 -/**
   73.35 - * This class consists exclusively of static methods that operate on or return
   73.36 - * collections.  It contains polymorphic algorithms that operate on
   73.37 - * collections, "wrappers", which return a new collection backed by a
   73.38 - * specified collection, and a few other odds and ends.
   73.39 - *
   73.40 - * <p>The methods of this class all throw a <tt>NullPointerException</tt>
   73.41 - * if the collections or class objects provided to them are null.
   73.42 - *
   73.43 - * <p>The documentation for the polymorphic algorithms contained in this class
   73.44 - * generally includes a brief description of the <i>implementation</i>.  Such
   73.45 - * descriptions should be regarded as <i>implementation notes</i>, rather than
   73.46 - * parts of the <i>specification</i>.  Implementors should feel free to
   73.47 - * substitute other algorithms, so long as the specification itself is adhered
   73.48 - * to.  (For example, the algorithm used by <tt>sort</tt> does not have to be
   73.49 - * a mergesort, but it does have to be <i>stable</i>.)
   73.50 - *
   73.51 - * <p>The "destructive" algorithms contained in this class, that is, the
   73.52 - * algorithms that modify the collection on which they operate, are specified
   73.53 - * to throw <tt>UnsupportedOperationException</tt> if the collection does not
   73.54 - * support the appropriate mutation primitive(s), such as the <tt>set</tt>
   73.55 - * method.  These algorithms may, but are not required to, throw this
   73.56 - * exception if an invocation would have no effect on the collection.  For
   73.57 - * example, invoking the <tt>sort</tt> method on an unmodifiable list that is
   73.58 - * already sorted may or may not throw <tt>UnsupportedOperationException</tt>.
   73.59 - *
   73.60 - * <p>This class is a member of the
   73.61 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   73.62 - * Java Collections Framework</a>.
   73.63 - *
   73.64 - * @author  Josh Bloch
   73.65 - * @author  Neal Gafter
   73.66 - * @see     Collection
   73.67 - * @see     Set
   73.68 - * @see     List
   73.69 - * @see     Map
   73.70 - * @since   1.2
   73.71 - */
   73.72 -
   73.73 -public class Collections {
   73.74 -    // Suppresses default constructor, ensuring non-instantiability.
   73.75 -    private Collections() {
   73.76 -    }
   73.77 -
   73.78 -    // Algorithms
   73.79 -
   73.80 -    /*
   73.81 -     * Tuning parameters for algorithms - Many of the List algorithms have
   73.82 -     * two implementations, one of which is appropriate for RandomAccess
   73.83 -     * lists, the other for "sequential."  Often, the random access variant
   73.84 -     * yields better performance on small sequential access lists.  The
   73.85 -     * tuning parameters below determine the cutoff point for what constitutes
   73.86 -     * a "small" sequential access list for each algorithm.  The values below
   73.87 -     * were empirically determined to work well for LinkedList. Hopefully
   73.88 -     * they should be reasonable for other sequential access List
   73.89 -     * implementations.  Those doing performance work on this code would
   73.90 -     * do well to validate the values of these parameters from time to time.
   73.91 -     * (The first word of each tuning parameter name is the algorithm to which
   73.92 -     * it applies.)
   73.93 -     */
   73.94 -    private static final int BINARYSEARCH_THRESHOLD   = 5000;
   73.95 -    private static final int REVERSE_THRESHOLD        =   18;
   73.96 -    private static final int SHUFFLE_THRESHOLD        =    5;
   73.97 -    private static final int FILL_THRESHOLD           =   25;
   73.98 -    private static final int ROTATE_THRESHOLD         =  100;
   73.99 -    private static final int COPY_THRESHOLD           =   10;
  73.100 -    private static final int REPLACEALL_THRESHOLD     =   11;
  73.101 -    private static final int INDEXOFSUBLIST_THRESHOLD =   35;
  73.102 -
  73.103 -    /**
  73.104 -     * Sorts the specified list into ascending order, according to the
  73.105 -     * {@linkplain Comparable natural ordering} of its elements.
  73.106 -     * All elements in the list must implement the {@link Comparable}
  73.107 -     * interface.  Furthermore, all elements in the list must be
  73.108 -     * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)}
  73.109 -     * must not throw a {@code ClassCastException} for any elements
  73.110 -     * {@code e1} and {@code e2} in the list).
  73.111 -     *
  73.112 -     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  73.113 -     * not be reordered as a result of the sort.
  73.114 -     *
  73.115 -     * <p>The specified list must be modifiable, but need not be resizable.
  73.116 -     *
  73.117 -     * <p>Implementation note: This implementation is a stable, adaptive,
  73.118 -     * iterative mergesort that requires far fewer than n lg(n) comparisons
  73.119 -     * when the input array is partially sorted, while offering the
  73.120 -     * performance of a traditional mergesort when the input array is
  73.121 -     * randomly ordered.  If the input array is nearly sorted, the
  73.122 -     * implementation requires approximately n comparisons.  Temporary
  73.123 -     * storage requirements vary from a small constant for nearly sorted
  73.124 -     * input arrays to n/2 object references for randomly ordered input
  73.125 -     * arrays.
  73.126 -     *
  73.127 -     * <p>The implementation takes equal advantage of ascending and
  73.128 -     * descending order in its input array, and can take advantage of
  73.129 -     * ascending and descending order in different parts of the same
  73.130 -     * input array.  It is well-suited to merging two or more sorted arrays:
  73.131 -     * simply concatenate the arrays and sort the resulting array.
  73.132 -     *
  73.133 -     * <p>The implementation was adapted from Tim Peters's list sort for Python
  73.134 -     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  73.135 -     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  73.136 -     * Sorting and Information Theoretic Complexity", in Proceedings of the
  73.137 -     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  73.138 -     * January 1993.
  73.139 -     *
  73.140 -     * <p>This implementation dumps the specified list into an array, sorts
  73.141 -     * the array, and iterates over the list resetting each element
  73.142 -     * from the corresponding position in the array.  This avoids the
  73.143 -     * n<sup>2</sup> log(n) performance that would result from attempting
  73.144 -     * to sort a linked list in place.
  73.145 -     *
  73.146 -     * @param  list the list to be sorted.
  73.147 -     * @throws ClassCastException if the list contains elements that are not
  73.148 -     *         <i>mutually comparable</i> (for example, strings and integers).
  73.149 -     * @throws UnsupportedOperationException if the specified list's
  73.150 -     *         list-iterator does not support the {@code set} operation.
  73.151 -     * @throws IllegalArgumentException (optional) if the implementation
  73.152 -     *         detects that the natural ordering of the list elements is
  73.153 -     *         found to violate the {@link Comparable} contract
  73.154 -     */
  73.155 -    public static <T extends Comparable<? super T>> void sort(List<T> list) {
  73.156 -        Object[] a = list.toArray();
  73.157 -        Arrays.sort(a);
  73.158 -        ListIterator<T> i = list.listIterator();
  73.159 -        for (int j=0; j<a.length; j++) {
  73.160 -            i.next();
  73.161 -            i.set((T)a[j]);
  73.162 -        }
  73.163 -    }
  73.164 -
  73.165 -    /**
  73.166 -     * Sorts the specified list according to the order induced by the
  73.167 -     * specified comparator.  All elements in the list must be <i>mutually
  73.168 -     * comparable</i> using the specified comparator (that is,
  73.169 -     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
  73.170 -     * for any elements {@code e1} and {@code e2} in the list).
  73.171 -     *
  73.172 -     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
  73.173 -     * not be reordered as a result of the sort.
  73.174 -     *
  73.175 -     * <p>The specified list must be modifiable, but need not be resizable.
  73.176 -     *
  73.177 -     * <p>Implementation note: This implementation is a stable, adaptive,
  73.178 -     * iterative mergesort that requires far fewer than n lg(n) comparisons
  73.179 -     * when the input array is partially sorted, while offering the
  73.180 -     * performance of a traditional mergesort when the input array is
  73.181 -     * randomly ordered.  If the input array is nearly sorted, the
  73.182 -     * implementation requires approximately n comparisons.  Temporary
  73.183 -     * storage requirements vary from a small constant for nearly sorted
  73.184 -     * input arrays to n/2 object references for randomly ordered input
  73.185 -     * arrays.
  73.186 -     *
  73.187 -     * <p>The implementation takes equal advantage of ascending and
  73.188 -     * descending order in its input array, and can take advantage of
  73.189 -     * ascending and descending order in different parts of the same
  73.190 -     * input array.  It is well-suited to merging two or more sorted arrays:
  73.191 -     * simply concatenate the arrays and sort the resulting array.
  73.192 -     *
  73.193 -     * <p>The implementation was adapted from Tim Peters's list sort for Python
  73.194 -     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
  73.195 -     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
  73.196 -     * Sorting and Information Theoretic Complexity", in Proceedings of the
  73.197 -     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
  73.198 -     * January 1993.
  73.199 -     *
  73.200 -     * <p>This implementation dumps the specified list into an array, sorts
  73.201 -     * the array, and iterates over the list resetting each element
  73.202 -     * from the corresponding position in the array.  This avoids the
  73.203 -     * n<sup>2</sup> log(n) performance that would result from attempting
  73.204 -     * to sort a linked list in place.
  73.205 -     *
  73.206 -     * @param  list the list to be sorted.
  73.207 -     * @param  c the comparator to determine the order of the list.  A
  73.208 -     *        {@code null} value indicates that the elements' <i>natural
  73.209 -     *        ordering</i> should be used.
  73.210 -     * @throws ClassCastException if the list contains elements that are not
  73.211 -     *         <i>mutually comparable</i> using the specified comparator.
  73.212 -     * @throws UnsupportedOperationException if the specified list's
  73.213 -     *         list-iterator does not support the {@code set} operation.
  73.214 -     * @throws IllegalArgumentException (optional) if the comparator is
  73.215 -     *         found to violate the {@link Comparator} contract
  73.216 -     */
  73.217 -    public static <T> void sort(List<T> list, Comparator<? super T> c) {
  73.218 -        Object[] a = list.toArray();
  73.219 -        Arrays.sort(a, (Comparator)c);
  73.220 -        ListIterator i = list.listIterator();
  73.221 -        for (int j=0; j<a.length; j++) {
  73.222 -            i.next();
  73.223 -            i.set(a[j]);
  73.224 -        }
  73.225 -    }
  73.226 -
  73.227 -
  73.228 -    /**
  73.229 -     * Searches the specified list for the specified object using the binary
  73.230 -     * search algorithm.  The list must be sorted into ascending order
  73.231 -     * according to the {@linkplain Comparable natural ordering} of its
  73.232 -     * elements (as by the {@link #sort(List)} method) prior to making this
  73.233 -     * call.  If it is not sorted, the results are undefined.  If the list
  73.234 -     * contains multiple elements equal to the specified object, there is no
  73.235 -     * guarantee which one will be found.
  73.236 -     *
  73.237 -     * <p>This method runs in log(n) time for a "random access" list (which
  73.238 -     * provides near-constant-time positional access).  If the specified list
  73.239 -     * does not implement the {@link RandomAccess} interface and is large,
  73.240 -     * this method will do an iterator-based binary search that performs
  73.241 -     * O(n) link traversals and O(log n) element comparisons.
  73.242 -     *
  73.243 -     * @param  list the list to be searched.
  73.244 -     * @param  key the key to be searched for.
  73.245 -     * @return the index of the search key, if it is contained in the list;
  73.246 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  73.247 -     *         <i>insertion point</i> is defined as the point at which the
  73.248 -     *         key would be inserted into the list: the index of the first
  73.249 -     *         element greater than the key, or <tt>list.size()</tt> if all
  73.250 -     *         elements in the list are less than the specified key.  Note
  73.251 -     *         that this guarantees that the return value will be &gt;= 0 if
  73.252 -     *         and only if the key is found.
  73.253 -     * @throws ClassCastException if the list contains elements that are not
  73.254 -     *         <i>mutually comparable</i> (for example, strings and
  73.255 -     *         integers), or the search key is not mutually comparable
  73.256 -     *         with the elements of the list.
  73.257 -     */
  73.258 -    public static <T>
  73.259 -    int binarySearch(List<? extends Comparable<? super T>> list, T key) {
  73.260 -        if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
  73.261 -            return Collections.indexedBinarySearch(list, key);
  73.262 -        else
  73.263 -            return Collections.iteratorBinarySearch(list, key);
  73.264 -    }
  73.265 -
  73.266 -    private static <T>
  73.267 -    int indexedBinarySearch(List<? extends Comparable<? super T>> list, T key)
  73.268 -    {
  73.269 -        int low = 0;
  73.270 -        int high = list.size()-1;
  73.271 -
  73.272 -        while (low <= high) {
  73.273 -            int mid = (low + high) >>> 1;
  73.274 -            Comparable<? super T> midVal = list.get(mid);
  73.275 -            int cmp = midVal.compareTo(key);
  73.276 -
  73.277 -            if (cmp < 0)
  73.278 -                low = mid + 1;
  73.279 -            else if (cmp > 0)
  73.280 -                high = mid - 1;
  73.281 -            else
  73.282 -                return mid; // key found
  73.283 -        }
  73.284 -        return -(low + 1);  // key not found
  73.285 -    }
  73.286 -
  73.287 -    private static <T>
  73.288 -    int iteratorBinarySearch(List<? extends Comparable<? super T>> list, T key)
  73.289 -    {
  73.290 -        int low = 0;
  73.291 -        int high = list.size()-1;
  73.292 -        ListIterator<? extends Comparable<? super T>> i = list.listIterator();
  73.293 -
  73.294 -        while (low <= high) {
  73.295 -            int mid = (low + high) >>> 1;
  73.296 -            Comparable<? super T> midVal = get(i, mid);
  73.297 -            int cmp = midVal.compareTo(key);
  73.298 -
  73.299 -            if (cmp < 0)
  73.300 -                low = mid + 1;
  73.301 -            else if (cmp > 0)
  73.302 -                high = mid - 1;
  73.303 -            else
  73.304 -                return mid; // key found
  73.305 -        }
  73.306 -        return -(low + 1);  // key not found
  73.307 -    }
  73.308 -
  73.309 -    /**
  73.310 -     * Gets the ith element from the given list by repositioning the specified
  73.311 -     * list listIterator.
  73.312 -     */
  73.313 -    private static <T> T get(ListIterator<? extends T> i, int index) {
  73.314 -        T obj = null;
  73.315 -        int pos = i.nextIndex();
  73.316 -        if (pos <= index) {
  73.317 -            do {
  73.318 -                obj = i.next();
  73.319 -            } while (pos++ < index);
  73.320 -        } else {
  73.321 -            do {
  73.322 -                obj = i.previous();
  73.323 -            } while (--pos > index);
  73.324 -        }
  73.325 -        return obj;
  73.326 -    }
  73.327 -
  73.328 -    /**
  73.329 -     * Searches the specified list for the specified object using the binary
  73.330 -     * search algorithm.  The list must be sorted into ascending order
  73.331 -     * according to the specified comparator (as by the
  73.332 -     * {@link #sort(List, Comparator) sort(List, Comparator)}
  73.333 -     * method), prior to making this call.  If it is
  73.334 -     * not sorted, the results are undefined.  If the list contains multiple
  73.335 -     * elements equal to the specified object, there is no guarantee which one
  73.336 -     * will be found.
  73.337 -     *
  73.338 -     * <p>This method runs in log(n) time for a "random access" list (which
  73.339 -     * provides near-constant-time positional access).  If the specified list
  73.340 -     * does not implement the {@link RandomAccess} interface and is large,
  73.341 -     * this method will do an iterator-based binary search that performs
  73.342 -     * O(n) link traversals and O(log n) element comparisons.
  73.343 -     *
  73.344 -     * @param  list the list to be searched.
  73.345 -     * @param  key the key to be searched for.
  73.346 -     * @param  c the comparator by which the list is ordered.
  73.347 -     *         A <tt>null</tt> value indicates that the elements'
  73.348 -     *         {@linkplain Comparable natural ordering} should be used.
  73.349 -     * @return the index of the search key, if it is contained in the list;
  73.350 -     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
  73.351 -     *         <i>insertion point</i> is defined as the point at which the
  73.352 -     *         key would be inserted into the list: the index of the first
  73.353 -     *         element greater than the key, or <tt>list.size()</tt> if all
  73.354 -     *         elements in the list are less than the specified key.  Note
  73.355 -     *         that this guarantees that the return value will be &gt;= 0 if
  73.356 -     *         and only if the key is found.
  73.357 -     * @throws ClassCastException if the list contains elements that are not
  73.358 -     *         <i>mutually comparable</i> using the specified comparator,
  73.359 -     *         or the search key is not mutually comparable with the
  73.360 -     *         elements of the list using this comparator.
  73.361 -     */
  73.362 -    public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) {
  73.363 -        if (c==null)
  73.364 -            return binarySearch((List) list, key);
  73.365 -
  73.366 -        if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
  73.367 -            return Collections.indexedBinarySearch(list, key, c);
  73.368 -        else
  73.369 -            return Collections.iteratorBinarySearch(list, key, c);
  73.370 -    }
  73.371 -
  73.372 -    private static <T> int indexedBinarySearch(List<? extends T> l, T key, Comparator<? super T> c) {
  73.373 -        int low = 0;
  73.374 -        int high = l.size()-1;
  73.375 -
  73.376 -        while (low <= high) {
  73.377 -            int mid = (low + high) >>> 1;
  73.378 -            T midVal = l.get(mid);
  73.379 -            int cmp = c.compare(midVal, key);
  73.380 -
  73.381 -            if (cmp < 0)
  73.382 -                low = mid + 1;
  73.383 -            else if (cmp > 0)
  73.384 -                high = mid - 1;
  73.385 -            else
  73.386 -                return mid; // key found
  73.387 -        }
  73.388 -        return -(low + 1);  // key not found
  73.389 -    }
  73.390 -
  73.391 -    private static <T> int iteratorBinarySearch(List<? extends T> l, T key, Comparator<? super T> c) {
  73.392 -        int low = 0;
  73.393 -        int high = l.size()-1;
  73.394 -        ListIterator<? extends T> i = l.listIterator();
  73.395 -
  73.396 -        while (low <= high) {
  73.397 -            int mid = (low + high) >>> 1;
  73.398 -            T midVal = get(i, mid);
  73.399 -            int cmp = c.compare(midVal, key);
  73.400 -
  73.401 -            if (cmp < 0)
  73.402 -                low = mid + 1;
  73.403 -            else if (cmp > 0)
  73.404 -                high = mid - 1;
  73.405 -            else
  73.406 -                return mid; // key found
  73.407 -        }
  73.408 -        return -(low + 1);  // key not found
  73.409 -    }
  73.410 -
  73.411 -    private interface SelfComparable extends Comparable<SelfComparable> {}
  73.412 -
  73.413 -
  73.414 -    /**
  73.415 -     * Reverses the order of the elements in the specified list.<p>
  73.416 -     *
  73.417 -     * This method runs in linear time.
  73.418 -     *
  73.419 -     * @param  list the list whose elements are to be reversed.
  73.420 -     * @throws UnsupportedOperationException if the specified list or
  73.421 -     *         its list-iterator does not support the <tt>set</tt> operation.
  73.422 -     */
  73.423 -    public static void reverse(List<?> list) {
  73.424 -        int size = list.size();
  73.425 -        if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
  73.426 -            for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--)
  73.427 -                swap(list, i, j);
  73.428 -        } else {
  73.429 -            ListIterator fwd = list.listIterator();
  73.430 -            ListIterator rev = list.listIterator(size);
  73.431 -            for (int i=0, mid=list.size()>>1; i<mid; i++) {
  73.432 -                Object tmp = fwd.next();
  73.433 -                fwd.set(rev.previous());
  73.434 -                rev.set(tmp);
  73.435 -            }
  73.436 -        }
  73.437 -    }
  73.438 -
  73.439 -    /**
  73.440 -     * Randomly permutes the specified list using a default source of
  73.441 -     * randomness.  All permutations occur with approximately equal
  73.442 -     * likelihood.<p>
  73.443 -     *
  73.444 -     * The hedge "approximately" is used in the foregoing description because
  73.445 -     * default source of randomness is only approximately an unbiased source
  73.446 -     * of independently chosen bits. If it were a perfect source of randomly
  73.447 -     * chosen bits, then the algorithm would choose permutations with perfect
  73.448 -     * uniformity.<p>
  73.449 -     *
  73.450 -     * This implementation traverses the list backwards, from the last element
  73.451 -     * up to the second, repeatedly swapping a randomly selected element into
  73.452 -     * the "current position".  Elements are randomly selected from the
  73.453 -     * portion of the list that runs from the first element to the current
  73.454 -     * position, inclusive.<p>
  73.455 -     *
  73.456 -     * This method runs in linear time.  If the specified list does not
  73.457 -     * implement the {@link RandomAccess} interface and is large, this
  73.458 -     * implementation dumps the specified list into an array before shuffling
  73.459 -     * it, and dumps the shuffled array back into the list.  This avoids the
  73.460 -     * quadratic behavior that would result from shuffling a "sequential
  73.461 -     * access" list in place.
  73.462 -     *
  73.463 -     * @param  list the list to be shuffled.
  73.464 -     * @throws UnsupportedOperationException if the specified list or
  73.465 -     *         its list-iterator does not support the <tt>set</tt> operation.
  73.466 -     */
  73.467 -    public static void shuffle(List<?> list) {
  73.468 -        Random rnd = r;
  73.469 -        if (rnd == null)
  73.470 -            r = rnd = new Random();
  73.471 -        shuffle(list, rnd);
  73.472 -    }
  73.473 -    private static Random r;
  73.474 -
  73.475 -    /**
  73.476 -     * Randomly permute the specified list using the specified source of
  73.477 -     * randomness.  All permutations occur with equal likelihood
  73.478 -     * assuming that the source of randomness is fair.<p>
  73.479 -     *
  73.480 -     * This implementation traverses the list backwards, from the last element
  73.481 -     * up to the second, repeatedly swapping a randomly selected element into
  73.482 -     * the "current position".  Elements are randomly selected from the
  73.483 -     * portion of the list that runs from the first element to the current
  73.484 -     * position, inclusive.<p>
  73.485 -     *
  73.486 -     * This method runs in linear time.  If the specified list does not
  73.487 -     * implement the {@link RandomAccess} interface and is large, this
  73.488 -     * implementation dumps the specified list into an array before shuffling
  73.489 -     * it, and dumps the shuffled array back into the list.  This avoids the
  73.490 -     * quadratic behavior that would result from shuffling a "sequential
  73.491 -     * access" list in place.
  73.492 -     *
  73.493 -     * @param  list the list to be shuffled.
  73.494 -     * @param  rnd the source of randomness to use to shuffle the list.
  73.495 -     * @throws UnsupportedOperationException if the specified list or its
  73.496 -     *         list-iterator does not support the <tt>set</tt> operation.
  73.497 -     */
  73.498 -    public static void shuffle(List<?> list, Random rnd) {
  73.499 -        int size = list.size();
  73.500 -        if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
  73.501 -            for (int i=size; i>1; i--)
  73.502 -                swap(list, i-1, rnd.nextInt(i));
  73.503 -        } else {
  73.504 -            Object arr[] = list.toArray();
  73.505 -
  73.506 -            // Shuffle array
  73.507 -            for (int i=size; i>1; i--)
  73.508 -                swap(arr, i-1, rnd.nextInt(i));
  73.509 -
  73.510 -            // Dump array back into list
  73.511 -            ListIterator it = list.listIterator();
  73.512 -            for (int i=0; i<arr.length; i++) {
  73.513 -                it.next();
  73.514 -                it.set(arr[i]);
  73.515 -            }
  73.516 -        }
  73.517 -    }
  73.518 -
  73.519 -    /**
  73.520 -     * Swaps the elements at the specified positions in the specified list.
  73.521 -     * (If the specified positions are equal, invoking this method leaves
  73.522 -     * the list unchanged.)
  73.523 -     *
  73.524 -     * @param list The list in which to swap elements.
  73.525 -     * @param i the index of one element to be swapped.
  73.526 -     * @param j the index of the other element to be swapped.
  73.527 -     * @throws IndexOutOfBoundsException if either <tt>i</tt> or <tt>j</tt>
  73.528 -     *         is out of range (i &lt; 0 || i &gt;= list.size()
  73.529 -     *         || j &lt; 0 || j &gt;= list.size()).
  73.530 -     * @since 1.4
  73.531 -     */
  73.532 -    public static void swap(List<?> list, int i, int j) {
  73.533 -        final List l = list;
  73.534 -        l.set(i, l.set(j, l.get(i)));
  73.535 -    }
  73.536 -
  73.537 -    /**
  73.538 -     * Swaps the two specified elements in the specified array.
  73.539 -     */
  73.540 -    private static void swap(Object[] arr, int i, int j) {
  73.541 -        Object tmp = arr[i];
  73.542 -        arr[i] = arr[j];
  73.543 -        arr[j] = tmp;
  73.544 -    }
  73.545 -
  73.546 -    /**
  73.547 -     * Replaces all of the elements of the specified list with the specified
  73.548 -     * element. <p>
  73.549 -     *
  73.550 -     * This method runs in linear time.
  73.551 -     *
  73.552 -     * @param  list the list to be filled with the specified element.
  73.553 -     * @param  obj The element with which to fill the specified list.
  73.554 -     * @throws UnsupportedOperationException if the specified list or its
  73.555 -     *         list-iterator does not support the <tt>set</tt> operation.
  73.556 -     */
  73.557 -    public static <T> void fill(List<? super T> list, T obj) {
  73.558 -        int size = list.size();
  73.559 -
  73.560 -        if (size < FILL_THRESHOLD || list instanceof RandomAccess) {
  73.561 -            for (int i=0; i<size; i++)
  73.562 -                list.set(i, obj);
  73.563 -        } else {
  73.564 -            ListIterator<? super T> itr = list.listIterator();
  73.565 -            for (int i=0; i<size; i++) {
  73.566 -                itr.next();
  73.567 -                itr.set(obj);
  73.568 -            }
  73.569 -        }
  73.570 -    }
  73.571 -
  73.572 -    /**
  73.573 -     * Copies all of the elements from one list into another.  After the
  73.574 -     * operation, the index of each copied element in the destination list
  73.575 -     * will be identical to its index in the source list.  The destination
  73.576 -     * list must be at least as long as the source list.  If it is longer, the
  73.577 -     * remaining elements in the destination list are unaffected. <p>
  73.578 -     *
  73.579 -     * This method runs in linear time.
  73.580 -     *
  73.581 -     * @param  dest The destination list.
  73.582 -     * @param  src The source list.
  73.583 -     * @throws IndexOutOfBoundsException if the destination list is too small
  73.584 -     *         to contain the entire source List.
  73.585 -     * @throws UnsupportedOperationException if the destination list's
  73.586 -     *         list-iterator does not support the <tt>set</tt> operation.
  73.587 -     */
  73.588 -    public static <T> void copy(List<? super T> dest, List<? extends T> src) {
  73.589 -        int srcSize = src.size();
  73.590 -        if (srcSize > dest.size())
  73.591 -            throw new IndexOutOfBoundsException("Source does not fit in dest");
  73.592 -
  73.593 -        if (srcSize < COPY_THRESHOLD ||
  73.594 -            (src instanceof RandomAccess && dest instanceof RandomAccess)) {
  73.595 -            for (int i=0; i<srcSize; i++)
  73.596 -                dest.set(i, src.get(i));
  73.597 -        } else {
  73.598 -            ListIterator<? super T> di=dest.listIterator();
  73.599 -            ListIterator<? extends T> si=src.listIterator();
  73.600 -            for (int i=0; i<srcSize; i++) {
  73.601 -                di.next();
  73.602 -                di.set(si.next());
  73.603 -            }
  73.604 -        }
  73.605 -    }
  73.606 -
  73.607 -    /**
  73.608 -     * Returns the minimum element of the given collection, according to the
  73.609 -     * <i>natural ordering</i> of its elements.  All elements in the
  73.610 -     * collection must implement the <tt>Comparable</tt> interface.
  73.611 -     * Furthermore, all elements in the collection must be <i>mutually
  73.612 -     * comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
  73.613 -     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  73.614 -     * <tt>e2</tt> in the collection).<p>
  73.615 -     *
  73.616 -     * This method iterates over the entire collection, hence it requires
  73.617 -     * time proportional to the size of the collection.
  73.618 -     *
  73.619 -     * @param  coll the collection whose minimum element is to be determined.
  73.620 -     * @return the minimum element of the given collection, according
  73.621 -     *         to the <i>natural ordering</i> of its elements.
  73.622 -     * @throws ClassCastException if the collection contains elements that are
  73.623 -     *         not <i>mutually comparable</i> (for example, strings and
  73.624 -     *         integers).
  73.625 -     * @throws NoSuchElementException if the collection is empty.
  73.626 -     * @see Comparable
  73.627 -     */
  73.628 -    public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {
  73.629 -        Iterator<? extends T> i = coll.iterator();
  73.630 -        T candidate = i.next();
  73.631 -
  73.632 -        while (i.hasNext()) {
  73.633 -            T next = i.next();
  73.634 -            if (next.compareTo(candidate) < 0)
  73.635 -                candidate = next;
  73.636 -        }
  73.637 -        return candidate;
  73.638 -    }
  73.639 -
  73.640 -    /**
  73.641 -     * Returns the minimum element of the given collection, according to the
  73.642 -     * order induced by the specified comparator.  All elements in the
  73.643 -     * collection must be <i>mutually comparable</i> by the specified
  73.644 -     * comparator (that is, <tt>comp.compare(e1, e2)</tt> must not throw a
  73.645 -     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  73.646 -     * <tt>e2</tt> in the collection).<p>
  73.647 -     *
  73.648 -     * This method iterates over the entire collection, hence it requires
  73.649 -     * time proportional to the size of the collection.
  73.650 -     *
  73.651 -     * @param  coll the collection whose minimum element is to be determined.
  73.652 -     * @param  comp the comparator with which to determine the minimum element.
  73.653 -     *         A <tt>null</tt> value indicates that the elements' <i>natural
  73.654 -     *         ordering</i> should be used.
  73.655 -     * @return the minimum element of the given collection, according
  73.656 -     *         to the specified comparator.
  73.657 -     * @throws ClassCastException if the collection contains elements that are
  73.658 -     *         not <i>mutually comparable</i> using the specified comparator.
  73.659 -     * @throws NoSuchElementException if the collection is empty.
  73.660 -     * @see Comparable
  73.661 -     */
  73.662 -    public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
  73.663 -        if (comp==null)
  73.664 -            return (T)min((Collection<SelfComparable>) (Collection) coll);
  73.665 -
  73.666 -        Iterator<? extends T> i = coll.iterator();
  73.667 -        T candidate = i.next();
  73.668 -
  73.669 -        while (i.hasNext()) {
  73.670 -            T next = i.next();
  73.671 -            if (comp.compare(next, candidate) < 0)
  73.672 -                candidate = next;
  73.673 -        }
  73.674 -        return candidate;
  73.675 -    }
  73.676 -
  73.677 -    /**
  73.678 -     * Returns the maximum element of the given collection, according to the
  73.679 -     * <i>natural ordering</i> of its elements.  All elements in the
  73.680 -     * collection must implement the <tt>Comparable</tt> interface.
  73.681 -     * Furthermore, all elements in the collection must be <i>mutually
  73.682 -     * comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
  73.683 -     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  73.684 -     * <tt>e2</tt> in the collection).<p>
  73.685 -     *
  73.686 -     * This method iterates over the entire collection, hence it requires
  73.687 -     * time proportional to the size of the collection.
  73.688 -     *
  73.689 -     * @param  coll the collection whose maximum element is to be determined.
  73.690 -     * @return the maximum element of the given collection, according
  73.691 -     *         to the <i>natural ordering</i> of its elements.
  73.692 -     * @throws ClassCastException if the collection contains elements that are
  73.693 -     *         not <i>mutually comparable</i> (for example, strings and
  73.694 -     *         integers).
  73.695 -     * @throws NoSuchElementException if the collection is empty.
  73.696 -     * @see Comparable
  73.697 -     */
  73.698 -    public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {
  73.699 -        Iterator<? extends T> i = coll.iterator();
  73.700 -        T candidate = i.next();
  73.701 -
  73.702 -        while (i.hasNext()) {
  73.703 -            T next = i.next();
  73.704 -            if (next.compareTo(candidate) > 0)
  73.705 -                candidate = next;
  73.706 -        }
  73.707 -        return candidate;
  73.708 -    }
  73.709 -
  73.710 -    /**
  73.711 -     * Returns the maximum element of the given collection, according to the
  73.712 -     * order induced by the specified comparator.  All elements in the
  73.713 -     * collection must be <i>mutually comparable</i> by the specified
  73.714 -     * comparator (that is, <tt>comp.compare(e1, e2)</tt> must not throw a
  73.715 -     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
  73.716 -     * <tt>e2</tt> in the collection).<p>
  73.717 -     *
  73.718 -     * This method iterates over the entire collection, hence it requires
  73.719 -     * time proportional to the size of the collection.
  73.720 -     *
  73.721 -     * @param  coll the collection whose maximum element is to be determined.
  73.722 -     * @param  comp the comparator with which to determine the maximum element.
  73.723 -     *         A <tt>null</tt> value indicates that the elements' <i>natural
  73.724 -     *        ordering</i> should be used.
  73.725 -     * @return the maximum element of the given collection, according
  73.726 -     *         to the specified comparator.
  73.727 -     * @throws ClassCastException if the collection contains elements that are
  73.728 -     *         not <i>mutually comparable</i> using the specified comparator.
  73.729 -     * @throws NoSuchElementException if the collection is empty.
  73.730 -     * @see Comparable
  73.731 -     */
  73.732 -    public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
  73.733 -        if (comp==null)
  73.734 -            return (T)max((Collection<SelfComparable>) (Collection) coll);
  73.735 -
  73.736 -        Iterator<? extends T> i = coll.iterator();
  73.737 -        T candidate = i.next();
  73.738 -
  73.739 -        while (i.hasNext()) {
  73.740 -            T next = i.next();
  73.741 -            if (comp.compare(next, candidate) > 0)
  73.742 -                candidate = next;
  73.743 -        }
  73.744 -        return candidate;
  73.745 -    }
  73.746 -
  73.747 -    /**
  73.748 -     * Rotates the elements in the specified list by the specified distance.
  73.749 -     * After calling this method, the element at index <tt>i</tt> will be
  73.750 -     * the element previously at index <tt>(i - distance)</tt> mod
  73.751 -     * <tt>list.size()</tt>, for all values of <tt>i</tt> between <tt>0</tt>
  73.752 -     * and <tt>list.size()-1</tt>, inclusive.  (This method has no effect on
  73.753 -     * the size of the list.)
  73.754 -     *
  73.755 -     * <p>For example, suppose <tt>list</tt> comprises<tt> [t, a, n, k, s]</tt>.
  73.756 -     * After invoking <tt>Collections.rotate(list, 1)</tt> (or
  73.757 -     * <tt>Collections.rotate(list, -4)</tt>), <tt>list</tt> will comprise
  73.758 -     * <tt>[s, t, a, n, k]</tt>.
  73.759 -     *
  73.760 -     * <p>Note that this method can usefully be applied to sublists to
  73.761 -     * move one or more elements within a list while preserving the
  73.762 -     * order of the remaining elements.  For example, the following idiom
  73.763 -     * moves the element at index <tt>j</tt> forward to position
  73.764 -     * <tt>k</tt> (which must be greater than or equal to <tt>j</tt>):
  73.765 -     * <pre>
  73.766 -     *     Collections.rotate(list.subList(j, k+1), -1);
  73.767 -     * </pre>
  73.768 -     * To make this concrete, suppose <tt>list</tt> comprises
  73.769 -     * <tt>[a, b, c, d, e]</tt>.  To move the element at index <tt>1</tt>
  73.770 -     * (<tt>b</tt>) forward two positions, perform the following invocation:
  73.771 -     * <pre>
  73.772 -     *     Collections.rotate(l.subList(1, 4), -1);
  73.773 -     * </pre>
  73.774 -     * The resulting list is <tt>[a, c, d, b, e]</tt>.
  73.775 -     *
  73.776 -     * <p>To move more than one element forward, increase the absolute value
  73.777 -     * of the rotation distance.  To move elements backward, use a positive
  73.778 -     * shift distance.
  73.779 -     *
  73.780 -     * <p>If the specified list is small or implements the {@link
  73.781 -     * RandomAccess} interface, this implementation exchanges the first
  73.782 -     * element into the location it should go, and then repeatedly exchanges
  73.783 -     * the displaced element into the location it should go until a displaced
  73.784 -     * element is swapped into the first element.  If necessary, the process
  73.785 -     * is repeated on the second and successive elements, until the rotation
  73.786 -     * is complete.  If the specified list is large and doesn't implement the
  73.787 -     * <tt>RandomAccess</tt> interface, this implementation breaks the
  73.788 -     * list into two sublist views around index <tt>-distance mod size</tt>.
  73.789 -     * Then the {@link #reverse(List)} method is invoked on each sublist view,
  73.790 -     * and finally it is invoked on the entire list.  For a more complete
  73.791 -     * description of both algorithms, see Section 2.3 of Jon Bentley's
  73.792 -     * <i>Programming Pearls</i> (Addison-Wesley, 1986).
  73.793 -     *
  73.794 -     * @param list the list to be rotated.
  73.795 -     * @param distance the distance to rotate the list.  There are no
  73.796 -     *        constraints on this value; it may be zero, negative, or
  73.797 -     *        greater than <tt>list.size()</tt>.
  73.798 -     * @throws UnsupportedOperationException if the specified list or
  73.799 -     *         its list-iterator does not support the <tt>set</tt> operation.
  73.800 -     * @since 1.4
  73.801 -     */
  73.802 -    public static void rotate(List<?> list, int distance) {
  73.803 -        if (list instanceof RandomAccess || list.size() < ROTATE_THRESHOLD)
  73.804 -            rotate1(list, distance);
  73.805 -        else
  73.806 -            rotate2(list, distance);
  73.807 -    }
  73.808 -
  73.809 -    private static <T> void rotate1(List<T> list, int distance) {
  73.810 -        int size = list.size();
  73.811 -        if (size == 0)
  73.812 -            return;
  73.813 -        distance = distance % size;
  73.814 -        if (distance < 0)
  73.815 -            distance += size;
  73.816 -        if (distance == 0)
  73.817 -            return;
  73.818 -
  73.819 -        for (int cycleStart = 0, nMoved = 0; nMoved != size; cycleStart++) {
  73.820 -            T displaced = list.get(cycleStart);
  73.821 -            int i = cycleStart;
  73.822 -            do {
  73.823 -                i += distance;
  73.824 -                if (i >= size)
  73.825 -                    i -= size;
  73.826 -                displaced = list.set(i, displaced);
  73.827 -                nMoved ++;
  73.828 -            } while (i != cycleStart);
  73.829 -        }
  73.830 -    }
  73.831 -
  73.832 -    private static void rotate2(List<?> list, int distance) {
  73.833 -        int size = list.size();
  73.834 -        if (size == 0)
  73.835 -            return;
  73.836 -        int mid =  -distance % size;
  73.837 -        if (mid < 0)
  73.838 -            mid += size;
  73.839 -        if (mid == 0)
  73.840 -            return;
  73.841 -
  73.842 -        reverse(list.subList(0, mid));
  73.843 -        reverse(list.subList(mid, size));
  73.844 -        reverse(list);
  73.845 -    }
  73.846 -
  73.847 -    /**
  73.848 -     * Replaces all occurrences of one specified value in a list with another.
  73.849 -     * More formally, replaces with <tt>newVal</tt> each element <tt>e</tt>
  73.850 -     * in <tt>list</tt> such that
  73.851 -     * <tt>(oldVal==null ? e==null : oldVal.equals(e))</tt>.
  73.852 -     * (This method has no effect on the size of the list.)
  73.853 -     *
  73.854 -     * @param list the list in which replacement is to occur.
  73.855 -     * @param oldVal the old value to be replaced.
  73.856 -     * @param newVal the new value with which <tt>oldVal</tt> is to be
  73.857 -     *        replaced.
  73.858 -     * @return <tt>true</tt> if <tt>list</tt> contained one or more elements
  73.859 -     *         <tt>e</tt> such that
  73.860 -     *         <tt>(oldVal==null ?  e==null : oldVal.equals(e))</tt>.
  73.861 -     * @throws UnsupportedOperationException if the specified list or
  73.862 -     *         its list-iterator does not support the <tt>set</tt> operation.
  73.863 -     * @since  1.4
  73.864 -     */
  73.865 -    public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) {
  73.866 -        boolean result = false;
  73.867 -        int size = list.size();
  73.868 -        if (size < REPLACEALL_THRESHOLD || list instanceof RandomAccess) {
  73.869 -            if (oldVal==null) {
  73.870 -                for (int i=0; i<size; i++) {
  73.871 -                    if (list.get(i)==null) {
  73.872 -                        list.set(i, newVal);
  73.873 -                        result = true;
  73.874 -                    }
  73.875 -                }
  73.876 -            } else {
  73.877 -                for (int i=0; i<size; i++) {
  73.878 -                    if (oldVal.equals(list.get(i))) {
  73.879 -                        list.set(i, newVal);
  73.880 -                        result = true;
  73.881 -                    }
  73.882 -                }
  73.883 -            }
  73.884 -        } else {
  73.885 -            ListIterator<T> itr=list.listIterator();
  73.886 -            if (oldVal==null) {
  73.887 -                for (int i=0; i<size; i++) {
  73.888 -                    if (itr.next()==null) {
  73.889 -                        itr.set(newVal);
  73.890 -                        result = true;
  73.891 -                    }
  73.892 -                }
  73.893 -            } else {
  73.894 -                for (int i=0; i<size; i++) {
  73.895 -                    if (oldVal.equals(itr.next())) {
  73.896 -                        itr.set(newVal);
  73.897 -                        result = true;
  73.898 -                    }
  73.899 -                }
  73.900 -            }
  73.901 -        }
  73.902 -        return result;
  73.903 -    }
  73.904 -
  73.905 -    /**
  73.906 -     * Returns the starting position of the first occurrence of the specified
  73.907 -     * target list within the specified source list, or -1 if there is no
  73.908 -     * such occurrence.  More formally, returns the lowest index <tt>i</tt>
  73.909 -     * such that <tt>source.subList(i, i+target.size()).equals(target)</tt>,
  73.910 -     * or -1 if there is no such index.  (Returns -1 if
  73.911 -     * <tt>target.size() > source.size()</tt>.)
  73.912 -     *
  73.913 -     * <p>This implementation uses the "brute force" technique of scanning
  73.914 -     * over the source list, looking for a match with the target at each
  73.915 -     * location in turn.
  73.916 -     *
  73.917 -     * @param source the list in which to search for the first occurrence
  73.918 -     *        of <tt>target</tt>.
  73.919 -     * @param target the list to search for as a subList of <tt>source</tt>.
  73.920 -     * @return the starting position of the first occurrence of the specified
  73.921 -     *         target list within the specified source list, or -1 if there
  73.922 -     *         is no such occurrence.
  73.923 -     * @since  1.4
  73.924 -     */
  73.925 -    public static int indexOfSubList(List<?> source, List<?> target) {
  73.926 -        int sourceSize = source.size();
  73.927 -        int targetSize = target.size();
  73.928 -        int maxCandidate = sourceSize - targetSize;
  73.929 -
  73.930 -        if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
  73.931 -            (source instanceof RandomAccess&&target instanceof RandomAccess)) {
  73.932 -        nextCand:
  73.933 -            for (int candidate = 0; candidate <= maxCandidate; candidate++) {
  73.934 -                for (int i=0, j=candidate; i<targetSize; i++, j++)
  73.935 -                    if (!eq(target.get(i), source.get(j)))
  73.936 -                        continue nextCand;  // Element mismatch, try next cand
  73.937 -                return candidate;  // All elements of candidate matched target
  73.938 -            }
  73.939 -        } else {  // Iterator version of above algorithm
  73.940 -            ListIterator<?> si = source.listIterator();
  73.941 -        nextCand:
  73.942 -            for (int candidate = 0; candidate <= maxCandidate; candidate++) {
  73.943 -                ListIterator<?> ti = target.listIterator();
  73.944 -                for (int i=0; i<targetSize; i++) {
  73.945 -                    if (!eq(ti.next(), si.next())) {
  73.946 -                        // Back up source iterator to next candidate
  73.947 -                        for (int j=0; j<i; j++)
  73.948 -                            si.previous();
  73.949 -                        continue nextCand;
  73.950 -                    }
  73.951 -                }
  73.952 -                return candidate;
  73.953 -            }
  73.954 -        }
  73.955 -        return -1;  // No candidate matched the target
  73.956 -    }
  73.957 -
  73.958 -    /**
  73.959 -     * Returns the starting position of the last occurrence of the specified
  73.960 -     * target list within the specified source list, or -1 if there is no such
  73.961 -     * occurrence.  More formally, returns the highest index <tt>i</tt>
  73.962 -     * such that <tt>source.subList(i, i+target.size()).equals(target)</tt>,
  73.963 -     * or -1 if there is no such index.  (Returns -1 if
  73.964 -     * <tt>target.size() > source.size()</tt>.)
  73.965 -     *
  73.966 -     * <p>This implementation uses the "brute force" technique of iterating
  73.967 -     * over the source list, looking for a match with the target at each
  73.968 -     * location in turn.
  73.969 -     *
  73.970 -     * @param source the list in which to search for the last occurrence
  73.971 -     *        of <tt>target</tt>.
  73.972 -     * @param target the list to search for as a subList of <tt>source</tt>.
  73.973 -     * @return the starting position of the last occurrence of the specified
  73.974 -     *         target list within the specified source list, or -1 if there
  73.975 -     *         is no such occurrence.
  73.976 -     * @since  1.4
  73.977 -     */
  73.978 -    public static int lastIndexOfSubList(List<?> source, List<?> target) {
  73.979 -        int sourceSize = source.size();
  73.980 -        int targetSize = target.size();
  73.981 -        int maxCandidate = sourceSize - targetSize;
  73.982 -
  73.983 -        if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
  73.984 -            source instanceof RandomAccess) {   // Index access version
  73.985 -        nextCand:
  73.986 -            for (int candidate = maxCandidate; candidate >= 0; candidate--) {
  73.987 -                for (int i=0, j=candidate; i<targetSize; i++, j++)
  73.988 -                    if (!eq(target.get(i), source.get(j)))
  73.989 -                        continue nextCand;  // Element mismatch, try next cand
  73.990 -                return candidate;  // All elements of candidate matched target
  73.991 -            }
  73.992 -        } else {  // Iterator version of above algorithm
  73.993 -            if (maxCandidate < 0)
  73.994 -                return -1;
  73.995 -            ListIterator<?> si = source.listIterator(maxCandidate);
  73.996 -        nextCand:
  73.997 -            for (int candidate = maxCandidate; candidate >= 0; candidate--) {
  73.998 -                ListIterator<?> ti = target.listIterator();
  73.999 -                for (int i=0; i<targetSize; i++) {
 73.1000 -                    if (!eq(ti.next(), si.next())) {
 73.1001 -                        if (candidate != 0) {
 73.1002 -                            // Back up source iterator to next candidate
 73.1003 -                            for (int j=0; j<=i+1; j++)
 73.1004 -                                si.previous();
 73.1005 -                        }
 73.1006 -                        continue nextCand;
 73.1007 -                    }
 73.1008 -                }
 73.1009 -                return candidate;
 73.1010 -            }
 73.1011 -        }
 73.1012 -        return -1;  // No candidate matched the target
 73.1013 -    }
 73.1014 -
 73.1015 -
 73.1016 -    // Unmodifiable Wrappers
 73.1017 -
 73.1018 -    /**
 73.1019 -     * Returns an unmodifiable view of the specified collection.  This method
 73.1020 -     * allows modules to provide users with "read-only" access to internal
 73.1021 -     * collections.  Query operations on the returned collection "read through"
 73.1022 -     * to the specified collection, and attempts to modify the returned
 73.1023 -     * collection, whether direct or via its iterator, result in an
 73.1024 -     * <tt>UnsupportedOperationException</tt>.<p>
 73.1025 -     *
 73.1026 -     * The returned collection does <i>not</i> pass the hashCode and equals
 73.1027 -     * operations through to the backing collection, but relies on
 73.1028 -     * <tt>Object</tt>'s <tt>equals</tt> and <tt>hashCode</tt> methods.  This
 73.1029 -     * is necessary to preserve the contracts of these operations in the case
 73.1030 -     * that the backing collection is a set or a list.<p>
 73.1031 -     *
 73.1032 -     * The returned collection will be serializable if the specified collection
 73.1033 -     * is serializable.
 73.1034 -     *
 73.1035 -     * @param  c the collection for which an unmodifiable view is to be
 73.1036 -     *         returned.
 73.1037 -     * @return an unmodifiable view of the specified collection.
 73.1038 -     */
 73.1039 -    public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) {
 73.1040 -        return new UnmodifiableCollection<>(c);
 73.1041 -    }
 73.1042 -
 73.1043 -    /**
 73.1044 -     * @serial include
 73.1045 -     */
 73.1046 -    static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
 73.1047 -        private static final long serialVersionUID = 1820017752578914078L;
 73.1048 -
 73.1049 -        final Collection<? extends E> c;
 73.1050 -
 73.1051 -        UnmodifiableCollection(Collection<? extends E> c) {
 73.1052 -            if (c==null)
 73.1053 -                throw new NullPointerException();
 73.1054 -            this.c = c;
 73.1055 -        }
 73.1056 -
 73.1057 -        public int size()                   {return c.size();}
 73.1058 -        public boolean isEmpty()            {return c.isEmpty();}
 73.1059 -        public boolean contains(Object o)   {return c.contains(o);}
 73.1060 -        public Object[] toArray()           {return c.toArray();}
 73.1061 -        public <T> T[] toArray(T[] a)       {return c.toArray(a);}
 73.1062 -        public String toString()            {return c.toString();}
 73.1063 -
 73.1064 -        public Iterator<E> iterator() {
 73.1065 -            return new Iterator<E>() {
 73.1066 -                private final Iterator<? extends E> i = c.iterator();
 73.1067 -
 73.1068 -                public boolean hasNext() {return i.hasNext();}
 73.1069 -                public E next()          {return i.next();}
 73.1070 -                public void remove() {
 73.1071 -                    throw new UnsupportedOperationException();
 73.1072 -                }
 73.1073 -            };
 73.1074 -        }
 73.1075 -
 73.1076 -        public boolean add(E e) {
 73.1077 -            throw new UnsupportedOperationException();
 73.1078 -        }
 73.1079 -        public boolean remove(Object o) {
 73.1080 -            throw new UnsupportedOperationException();
 73.1081 -        }
 73.1082 -
 73.1083 -        public boolean containsAll(Collection<?> coll) {
 73.1084 -            return c.containsAll(coll);
 73.1085 -        }
 73.1086 -        public boolean addAll(Collection<? extends E> coll) {
 73.1087 -            throw new UnsupportedOperationException();
 73.1088 -        }
 73.1089 -        public boolean removeAll(Collection<?> coll) {
 73.1090 -            throw new UnsupportedOperationException();
 73.1091 -        }
 73.1092 -        public boolean retainAll(Collection<?> coll) {
 73.1093 -            throw new UnsupportedOperationException();
 73.1094 -        }
 73.1095 -        public void clear() {
 73.1096 -            throw new UnsupportedOperationException();
 73.1097 -        }
 73.1098 -    }
 73.1099 -
 73.1100 -    /**
 73.1101 -     * Returns an unmodifiable view of the specified set.  This method allows
 73.1102 -     * modules to provide users with "read-only" access to internal sets.
 73.1103 -     * Query operations on the returned set "read through" to the specified
 73.1104 -     * set, and attempts to modify the returned set, whether direct or via its
 73.1105 -     * iterator, result in an <tt>UnsupportedOperationException</tt>.<p>
 73.1106 -     *
 73.1107 -     * The returned set will be serializable if the specified set
 73.1108 -     * is serializable.
 73.1109 -     *
 73.1110 -     * @param  s the set for which an unmodifiable view is to be returned.
 73.1111 -     * @return an unmodifiable view of the specified set.
 73.1112 -     */
 73.1113 -    public static <T> Set<T> unmodifiableSet(Set<? extends T> s) {
 73.1114 -        return new UnmodifiableSet<>(s);
 73.1115 -    }
 73.1116 -
 73.1117 -    /**
 73.1118 -     * @serial include
 73.1119 -     */
 73.1120 -    static class UnmodifiableSet<E> extends UnmodifiableCollection<E>
 73.1121 -                                 implements Set<E>, Serializable {
 73.1122 -        private static final long serialVersionUID = -9215047833775013803L;
 73.1123 -
 73.1124 -        UnmodifiableSet(Set<? extends E> s)     {super(s);}
 73.1125 -        public boolean equals(Object o) {return o == this || c.equals(o);}
 73.1126 -        public int hashCode()           {return c.hashCode();}
 73.1127 -    }
 73.1128 -
 73.1129 -    /**
 73.1130 -     * Returns an unmodifiable view of the specified sorted set.  This method
 73.1131 -     * allows modules to provide users with "read-only" access to internal
 73.1132 -     * sorted sets.  Query operations on the returned sorted set "read
 73.1133 -     * through" to the specified sorted set.  Attempts to modify the returned
 73.1134 -     * sorted set, whether direct, via its iterator, or via its
 73.1135 -     * <tt>subSet</tt>, <tt>headSet</tt>, or <tt>tailSet</tt> views, result in
 73.1136 -     * an <tt>UnsupportedOperationException</tt>.<p>
 73.1137 -     *
 73.1138 -     * The returned sorted set will be serializable if the specified sorted set
 73.1139 -     * is serializable.
 73.1140 -     *
 73.1141 -     * @param s the sorted set for which an unmodifiable view is to be
 73.1142 -     *        returned.
 73.1143 -     * @return an unmodifiable view of the specified sorted set.
 73.1144 -     */
 73.1145 -    public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) {
 73.1146 -        return new UnmodifiableSortedSet<>(s);
 73.1147 -    }
 73.1148 -
 73.1149 -    /**
 73.1150 -     * @serial include
 73.1151 -     */
 73.1152 -    static class UnmodifiableSortedSet<E>
 73.1153 -                             extends UnmodifiableSet<E>
 73.1154 -                             implements SortedSet<E>, Serializable {
 73.1155 -        private static final long serialVersionUID = -4929149591599911165L;
 73.1156 -        private final SortedSet<E> ss;
 73.1157 -
 73.1158 -        UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
 73.1159 -
 73.1160 -        public Comparator<? super E> comparator() {return ss.comparator();}
 73.1161 -
 73.1162 -        public SortedSet<E> subSet(E fromElement, E toElement) {
 73.1163 -            return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement));
 73.1164 -        }
 73.1165 -        public SortedSet<E> headSet(E toElement) {
 73.1166 -            return new UnmodifiableSortedSet<>(ss.headSet(toElement));
 73.1167 -        }
 73.1168 -        public SortedSet<E> tailSet(E fromElement) {
 73.1169 -            return new UnmodifiableSortedSet<>(ss.tailSet(fromElement));
 73.1170 -        }
 73.1171 -
 73.1172 -        public E first()                   {return ss.first();}
 73.1173 -        public E last()                    {return ss.last();}
 73.1174 -    }
 73.1175 -
 73.1176 -    /**
 73.1177 -     * Returns an unmodifiable view of the specified list.  This method allows
 73.1178 -     * modules to provide users with "read-only" access to internal
 73.1179 -     * lists.  Query operations on the returned list "read through" to the
 73.1180 -     * specified list, and attempts to modify the returned list, whether
 73.1181 -     * direct or via its iterator, result in an
 73.1182 -     * <tt>UnsupportedOperationException</tt>.<p>
 73.1183 -     *
 73.1184 -     * The returned list will be serializable if the specified list
 73.1185 -     * is serializable. Similarly, the returned list will implement
 73.1186 -     * {@link RandomAccess} if the specified list does.
 73.1187 -     *
 73.1188 -     * @param  list the list for which an unmodifiable view is to be returned.
 73.1189 -     * @return an unmodifiable view of the specified list.
 73.1190 -     */
 73.1191 -    public static <T> List<T> unmodifiableList(List<? extends T> list) {
 73.1192 -        return (list instanceof RandomAccess ?
 73.1193 -                new UnmodifiableRandomAccessList<>(list) :
 73.1194 -                new UnmodifiableList<>(list));
 73.1195 -    }
 73.1196 -
 73.1197 -    /**
 73.1198 -     * @serial include
 73.1199 -     */
 73.1200 -    static class UnmodifiableList<E> extends UnmodifiableCollection<E>
 73.1201 -                                  implements List<E> {
 73.1202 -        private static final long serialVersionUID = -283967356065247728L;
 73.1203 -        final List<? extends E> list;
 73.1204 -
 73.1205 -        UnmodifiableList(List<? extends E> list) {
 73.1206 -            super(list);
 73.1207 -            this.list = list;
 73.1208 -        }
 73.1209 -
 73.1210 -        public boolean equals(Object o) {return o == this || list.equals(o);}
 73.1211 -        public int hashCode()           {return list.hashCode();}
 73.1212 -
 73.1213 -        public E get(int index) {return list.get(index);}
 73.1214 -        public E set(int index, E element) {
 73.1215 -            throw new UnsupportedOperationException();
 73.1216 -        }
 73.1217 -        public void add(int index, E element) {
 73.1218 -            throw new UnsupportedOperationException();
 73.1219 -        }
 73.1220 -        public E remove(int index) {
 73.1221 -            throw new UnsupportedOperationException();
 73.1222 -        }
 73.1223 -        public int indexOf(Object o)            {return list.indexOf(o);}
 73.1224 -        public int lastIndexOf(Object o)        {return list.lastIndexOf(o);}
 73.1225 -        public boolean addAll(int index, Collection<? extends E> c) {
 73.1226 -            throw new UnsupportedOperationException();
 73.1227 -        }
 73.1228 -        public ListIterator<E> listIterator()   {return listIterator(0);}
 73.1229 -
 73.1230 -        public ListIterator<E> listIterator(final int index) {
 73.1231 -            return new ListIterator<E>() {
 73.1232 -                private final ListIterator<? extends E> i
 73.1233 -                    = list.listIterator(index);
 73.1234 -
 73.1235 -                public boolean hasNext()     {return i.hasNext();}
 73.1236 -                public E next()              {return i.next();}
 73.1237 -                public boolean hasPrevious() {return i.hasPrevious();}
 73.1238 -                public E previous()          {return i.previous();}
 73.1239 -                public int nextIndex()       {return i.nextIndex();}
 73.1240 -                public int previousIndex()   {return i.previousIndex();}
 73.1241 -
 73.1242 -                public void remove() {
 73.1243 -                    throw new UnsupportedOperationException();
 73.1244 -                }
 73.1245 -                public void set(E e) {
 73.1246 -                    throw new UnsupportedOperationException();
 73.1247 -                }
 73.1248 -                public void add(E e) {
 73.1249 -                    throw new UnsupportedOperationException();
 73.1250 -                }
 73.1251 -            };
 73.1252 -        }
 73.1253 -
 73.1254 -        public List<E> subList(int fromIndex, int toIndex) {
 73.1255 -            return new UnmodifiableList<>(list.subList(fromIndex, toIndex));
 73.1256 -        }
 73.1257 -
 73.1258 -        /**
 73.1259 -         * UnmodifiableRandomAccessList instances are serialized as
 73.1260 -         * UnmodifiableList instances to allow them to be deserialized
 73.1261 -         * in pre-1.4 JREs (which do not have UnmodifiableRandomAccessList).
 73.1262 -         * This method inverts the transformation.  As a beneficial
 73.1263 -         * side-effect, it also grafts the RandomAccess marker onto
 73.1264 -         * UnmodifiableList instances that were serialized in pre-1.4 JREs.
 73.1265 -         *
 73.1266 -         * Note: Unfortunately, UnmodifiableRandomAccessList instances
 73.1267 -         * serialized in 1.4.1 and deserialized in 1.4 will become
 73.1268 -         * UnmodifiableList instances, as this method was missing in 1.4.
 73.1269 -         */
 73.1270 -        private Object readResolve() {
 73.1271 -            return (list instanceof RandomAccess
 73.1272 -                    ? new UnmodifiableRandomAccessList<>(list)
 73.1273 -                    : this);
 73.1274 -        }
 73.1275 -    }
 73.1276 -
 73.1277 -    /**
 73.1278 -     * @serial include
 73.1279 -     */
 73.1280 -    static class UnmodifiableRandomAccessList<E> extends UnmodifiableList<E>
 73.1281 -                                              implements RandomAccess
 73.1282 -    {
 73.1283 -        UnmodifiableRandomAccessList(List<? extends E> list) {
 73.1284 -            super(list);
 73.1285 -        }
 73.1286 -
 73.1287 -        public List<E> subList(int fromIndex, int toIndex) {
 73.1288 -            return new UnmodifiableRandomAccessList<>(
 73.1289 -                list.subList(fromIndex, toIndex));
 73.1290 -        }
 73.1291 -
 73.1292 -        private static final long serialVersionUID = -2542308836966382001L;
 73.1293 -
 73.1294 -        /**
 73.1295 -         * Allows instances to be deserialized in pre-1.4 JREs (which do
 73.1296 -         * not have UnmodifiableRandomAccessList).  UnmodifiableList has
 73.1297 -         * a readResolve method that inverts this transformation upon
 73.1298 -         * deserialization.
 73.1299 -         */
 73.1300 -        private Object writeReplace() {
 73.1301 -            return new UnmodifiableList<>(list);
 73.1302 -        }
 73.1303 -    }
 73.1304 -
 73.1305 -    /**
 73.1306 -     * Returns an unmodifiable view of the specified map.  This method
 73.1307 -     * allows modules to provide users with "read-only" access to internal
 73.1308 -     * maps.  Query operations on the returned map "read through"
 73.1309 -     * to the specified map, and attempts to modify the returned
 73.1310 -     * map, whether direct or via its collection views, result in an
 73.1311 -     * <tt>UnsupportedOperationException</tt>.<p>
 73.1312 -     *
 73.1313 -     * The returned map will be serializable if the specified map
 73.1314 -     * is serializable.
 73.1315 -     *
 73.1316 -     * @param  m the map for which an unmodifiable view is to be returned.
 73.1317 -     * @return an unmodifiable view of the specified map.
 73.1318 -     */
 73.1319 -    public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m) {
 73.1320 -        return new UnmodifiableMap<>(m);
 73.1321 -    }
 73.1322 -
 73.1323 -    /**
 73.1324 -     * @serial include
 73.1325 -     */
 73.1326 -    private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
 73.1327 -        private static final long serialVersionUID = -1034234728574286014L;
 73.1328 -
 73.1329 -        private final Map<? extends K, ? extends V> m;
 73.1330 -
 73.1331 -        UnmodifiableMap(Map<? extends K, ? extends V> m) {
 73.1332 -            if (m==null)
 73.1333 -                throw new NullPointerException();
 73.1334 -            this.m = m;
 73.1335 -        }
 73.1336 -
 73.1337 -        public int size()                        {return m.size();}
 73.1338 -        public boolean isEmpty()                 {return m.isEmpty();}
 73.1339 -        public boolean containsKey(Object key)   {return m.containsKey(key);}
 73.1340 -        public boolean containsValue(Object val) {return m.containsValue(val);}
 73.1341 -        public V get(Object key)                 {return m.get(key);}
 73.1342 -
 73.1343 -        public V put(K key, V value) {
 73.1344 -            throw new UnsupportedOperationException();
 73.1345 -        }
 73.1346 -        public V remove(Object key) {
 73.1347 -            throw new UnsupportedOperationException();
 73.1348 -        }
 73.1349 -        public void putAll(Map<? extends K, ? extends V> m) {
 73.1350 -            throw new UnsupportedOperationException();
 73.1351 -        }
 73.1352 -        public void clear() {
 73.1353 -            throw new UnsupportedOperationException();
 73.1354 -        }
 73.1355 -
 73.1356 -        private transient Set<K> keySet = null;
 73.1357 -        private transient Set<Map.Entry<K,V>> entrySet = null;
 73.1358 -        private transient Collection<V> values = null;
 73.1359 -
 73.1360 -        public Set<K> keySet() {
 73.1361 -            if (keySet==null)
 73.1362 -                keySet = unmodifiableSet(m.keySet());
 73.1363 -            return keySet;
 73.1364 -        }
 73.1365 -
 73.1366 -        public Set<Map.Entry<K,V>> entrySet() {
 73.1367 -            if (entrySet==null)
 73.1368 -                entrySet = new UnmodifiableEntrySet<>(m.entrySet());
 73.1369 -            return entrySet;
 73.1370 -        }
 73.1371 -
 73.1372 -        public Collection<V> values() {
 73.1373 -            if (values==null)
 73.1374 -                values = unmodifiableCollection(m.values());
 73.1375 -            return values;
 73.1376 -        }
 73.1377 -
 73.1378 -        public boolean equals(Object o) {return o == this || m.equals(o);}
 73.1379 -        public int hashCode()           {return m.hashCode();}
 73.1380 -        public String toString()        {return m.toString();}
 73.1381 -
 73.1382 -        /**
 73.1383 -         * We need this class in addition to UnmodifiableSet as
 73.1384 -         * Map.Entries themselves permit modification of the backing Map
 73.1385 -         * via their setValue operation.  This class is subtle: there are
 73.1386 -         * many possible attacks that must be thwarted.
 73.1387 -         *
 73.1388 -         * @serial include
 73.1389 -         */
 73.1390 -        static class UnmodifiableEntrySet<K,V>
 73.1391 -            extends UnmodifiableSet<Map.Entry<K,V>> {
 73.1392 -            private static final long serialVersionUID = 7854390611657943733L;
 73.1393 -
 73.1394 -            UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
 73.1395 -                super((Set)s);
 73.1396 -            }
 73.1397 -            public Iterator<Map.Entry<K,V>> iterator() {
 73.1398 -                return new Iterator<Map.Entry<K,V>>() {
 73.1399 -                    private final Iterator<? extends Map.Entry<? extends K, ? extends V>> i = c.iterator();
 73.1400 -
 73.1401 -                    public boolean hasNext() {
 73.1402 -                        return i.hasNext();
 73.1403 -                    }
 73.1404 -                    public Map.Entry<K,V> next() {
 73.1405 -                        return new UnmodifiableEntry<>(i.next());
 73.1406 -                    }
 73.1407 -                    public void remove() {
 73.1408 -                        throw new UnsupportedOperationException();
 73.1409 -                    }
 73.1410 -                };
 73.1411 -            }
 73.1412 -
 73.1413 -            public Object[] toArray() {
 73.1414 -                Object[] a = c.toArray();
 73.1415 -                for (int i=0; i<a.length; i++)
 73.1416 -                    a[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)a[i]);
 73.1417 -                return a;
 73.1418 -            }
 73.1419 -
 73.1420 -            public <T> T[] toArray(T[] a) {
 73.1421 -                // We don't pass a to c.toArray, to avoid window of
 73.1422 -                // vulnerability wherein an unscrupulous multithreaded client
 73.1423 -                // could get his hands on raw (unwrapped) Entries from c.
 73.1424 -                Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
 73.1425 -
 73.1426 -                for (int i=0; i<arr.length; i++)
 73.1427 -                    arr[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)arr[i]);
 73.1428 -
 73.1429 -                if (arr.length > a.length)
 73.1430 -                    return (T[])arr;
 73.1431 -
 73.1432 -                System.arraycopy(arr, 0, a, 0, arr.length);
 73.1433 -                if (a.length > arr.length)
 73.1434 -                    a[arr.length] = null;
 73.1435 -                return a;
 73.1436 -            }
 73.1437 -
 73.1438 -            /**
 73.1439 -             * This method is overridden to protect the backing set against
 73.1440 -             * an object with a nefarious equals function that senses
 73.1441 -             * that the equality-candidate is Map.Entry and calls its
 73.1442 -             * setValue method.
 73.1443 -             */
 73.1444 -            public boolean contains(Object o) {
 73.1445 -                if (!(o instanceof Map.Entry))
 73.1446 -                    return false;
 73.1447 -                return c.contains(
 73.1448 -                    new UnmodifiableEntry<>((Map.Entry<?,?>) o));
 73.1449 -            }
 73.1450 -
 73.1451 -            /**
 73.1452 -             * The next two methods are overridden to protect against
 73.1453 -             * an unscrupulous List whose contains(Object o) method senses
 73.1454 -             * when o is a Map.Entry, and calls o.setValue.
 73.1455 -             */
 73.1456 -            public boolean containsAll(Collection<?> coll) {
 73.1457 -                for (Object e : coll) {
 73.1458 -                    if (!contains(e)) // Invokes safe contains() above
 73.1459 -                        return false;
 73.1460 -                }
 73.1461 -                return true;
 73.1462 -            }
 73.1463 -            public boolean equals(Object o) {
 73.1464 -                if (o == this)
 73.1465 -                    return true;
 73.1466 -
 73.1467 -                if (!(o instanceof Set))
 73.1468 -                    return false;
 73.1469 -                Set s = (Set) o;
 73.1470 -                if (s.size() != c.size())
 73.1471 -                    return false;
 73.1472 -                return containsAll(s); // Invokes safe containsAll() above
 73.1473 -            }
 73.1474 -
 73.1475 -            /**
 73.1476 -             * This "wrapper class" serves two purposes: it prevents
 73.1477 -             * the client from modifying the backing Map, by short-circuiting
 73.1478 -             * the setValue method, and it protects the backing Map against
 73.1479 -             * an ill-behaved Map.Entry that attempts to modify another
 73.1480 -             * Map Entry when asked to perform an equality check.
 73.1481 -             */
 73.1482 -            private static class UnmodifiableEntry<K,V> implements Map.Entry<K,V> {
 73.1483 -                private Map.Entry<? extends K, ? extends V> e;
 73.1484 -
 73.1485 -                UnmodifiableEntry(Map.Entry<? extends K, ? extends V> e) {this.e = e;}
 73.1486 -
 73.1487 -                public K getKey()        {return e.getKey();}
 73.1488 -                public V getValue()      {return e.getValue();}
 73.1489 -                public V setValue(V value) {
 73.1490 -                    throw new UnsupportedOperationException();
 73.1491 -                }
 73.1492 -                public int hashCode()    {return e.hashCode();}
 73.1493 -                public boolean equals(Object o) {
 73.1494 -                    if (!(o instanceof Map.Entry))
 73.1495 -                        return false;
 73.1496 -                    Map.Entry t = (Map.Entry)o;
 73.1497 -                    return eq(e.getKey(),   t.getKey()) &&
 73.1498 -                           eq(e.getValue(), t.getValue());
 73.1499 -                }
 73.1500 -                public String toString() {return e.toString();}
 73.1501 -            }
 73.1502 -        }
 73.1503 -    }
 73.1504 -
 73.1505 -    /**
 73.1506 -     * Returns an unmodifiable view of the specified sorted map.  This method
 73.1507 -     * allows modules to provide users with "read-only" access to internal
 73.1508 -     * sorted maps.  Query operations on the returned sorted map "read through"
 73.1509 -     * to the specified sorted map.  Attempts to modify the returned
 73.1510 -     * sorted map, whether direct, via its collection views, or via its
 73.1511 -     * <tt>subMap</tt>, <tt>headMap</tt>, or <tt>tailMap</tt> views, result in
 73.1512 -     * an <tt>UnsupportedOperationException</tt>.<p>
 73.1513 -     *
 73.1514 -     * The returned sorted map will be serializable if the specified sorted map
 73.1515 -     * is serializable.
 73.1516 -     *
 73.1517 -     * @param m the sorted map for which an unmodifiable view is to be
 73.1518 -     *        returned.
 73.1519 -     * @return an unmodifiable view of the specified sorted map.
 73.1520 -     */
 73.1521 -    public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K, ? extends V> m) {
 73.1522 -        return new UnmodifiableSortedMap<>(m);
 73.1523 -    }
 73.1524 -
 73.1525 -    /**
 73.1526 -     * @serial include
 73.1527 -     */
 73.1528 -    static class UnmodifiableSortedMap<K,V>
 73.1529 -          extends UnmodifiableMap<K,V>
 73.1530 -          implements SortedMap<K,V>, Serializable {
 73.1531 -        private static final long serialVersionUID = -8806743815996713206L;
 73.1532 -
 73.1533 -        private final SortedMap<K, ? extends V> sm;
 73.1534 -
 73.1535 -        UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m;}
 73.1536 -
 73.1537 -        public Comparator<? super K> comparator() {return sm.comparator();}
 73.1538 -
 73.1539 -        public SortedMap<K,V> subMap(K fromKey, K toKey) {
 73.1540 -            return new UnmodifiableSortedMap<>(sm.subMap(fromKey, toKey));
 73.1541 -        }
 73.1542 -        public SortedMap<K,V> headMap(K toKey) {
 73.1543 -            return new UnmodifiableSortedMap<>(sm.headMap(toKey));
 73.1544 -        }
 73.1545 -        public SortedMap<K,V> tailMap(K fromKey) {
 73.1546 -            return new UnmodifiableSortedMap<>(sm.tailMap(fromKey));
 73.1547 -        }
 73.1548 -
 73.1549 -        public K firstKey()           {return sm.firstKey();}
 73.1550 -        public K lastKey()            {return sm.lastKey();}
 73.1551 -    }
 73.1552 -
 73.1553 -
 73.1554 -    // Synch Wrappers
 73.1555 -
 73.1556 -    /**
 73.1557 -     * Returns a synchronized (thread-safe) collection backed by the specified
 73.1558 -     * collection.  In order to guarantee serial access, it is critical that
 73.1559 -     * <strong>all</strong> access to the backing collection is accomplished
 73.1560 -     * through the returned collection.<p>
 73.1561 -     *
 73.1562 -     * It is imperative that the user manually synchronize on the returned
 73.1563 -     * collection when iterating over it:
 73.1564 -     * <pre>
 73.1565 -     *  Collection c = Collections.synchronizedCollection(myCollection);
 73.1566 -     *     ...
 73.1567 -     *  synchronized (c) {
 73.1568 -     *      Iterator i = c.iterator(); // Must be in the synchronized block
 73.1569 -     *      while (i.hasNext())
 73.1570 -     *         foo(i.next());
 73.1571 -     *  }
 73.1572 -     * </pre>
 73.1573 -     * Failure to follow this advice may result in non-deterministic behavior.
 73.1574 -     *
 73.1575 -     * <p>The returned collection does <i>not</i> pass the <tt>hashCode</tt>
 73.1576 -     * and <tt>equals</tt> operations through to the backing collection, but
 73.1577 -     * relies on <tt>Object</tt>'s equals and hashCode methods.  This is
 73.1578 -     * necessary to preserve the contracts of these operations in the case
 73.1579 -     * that the backing collection is a set or a list.<p>
 73.1580 -     *
 73.1581 -     * The returned collection will be serializable if the specified collection
 73.1582 -     * is serializable.
 73.1583 -     *
 73.1584 -     * @param  c the collection to be "wrapped" in a synchronized collection.
 73.1585 -     * @return a synchronized view of the specified collection.
 73.1586 -     */
 73.1587 -    public static <T> Collection<T> synchronizedCollection(Collection<T> c) {
 73.1588 -        return new SynchronizedCollection<>(c);
 73.1589 -    }
 73.1590 -
 73.1591 -    static <T> Collection<T> synchronizedCollection(Collection<T> c, Object mutex) {
 73.1592 -        return new SynchronizedCollection<>(c, mutex);
 73.1593 -    }
 73.1594 -
 73.1595 -    /**
 73.1596 -     * @serial include
 73.1597 -     */
 73.1598 -    static class SynchronizedCollection<E> implements Collection<E>, Serializable {
 73.1599 -        private static final long serialVersionUID = 3053995032091335093L;
 73.1600 -
 73.1601 -        final Collection<E> c;  // Backing Collection
 73.1602 -        final Object mutex;     // Object on which to synchronize
 73.1603 -
 73.1604 -        SynchronizedCollection(Collection<E> c) {
 73.1605 -            if (c==null)
 73.1606 -                throw new NullPointerException();
 73.1607 -            this.c = c;
 73.1608 -            mutex = this;
 73.1609 -        }
 73.1610 -        SynchronizedCollection(Collection<E> c, Object mutex) {
 73.1611 -            this.c = c;
 73.1612 -            this.mutex = mutex;
 73.1613 -        }
 73.1614 -
 73.1615 -        public int size() {
 73.1616 -            synchronized (mutex) {return c.size();}
 73.1617 -        }
 73.1618 -        public boolean isEmpty() {
 73.1619 -            synchronized (mutex) {return c.isEmpty();}
 73.1620 -        }
 73.1621 -        public boolean contains(Object o) {
 73.1622 -            synchronized (mutex) {return c.contains(o);}
 73.1623 -        }
 73.1624 -        public Object[] toArray() {
 73.1625 -            synchronized (mutex) {return c.toArray();}
 73.1626 -        }
 73.1627 -        public <T> T[] toArray(T[] a) {
 73.1628 -            synchronized (mutex) {return c.toArray(a);}
 73.1629 -        }
 73.1630 -
 73.1631 -        public Iterator<E> iterator() {
 73.1632 -            return c.iterator(); // Must be manually synched by user!
 73.1633 -        }
 73.1634 -
 73.1635 -        public boolean add(E e) {
 73.1636 -            synchronized (mutex) {return c.add(e);}
 73.1637 -        }
 73.1638 -        public boolean remove(Object o) {
 73.1639 -            synchronized (mutex) {return c.remove(o);}
 73.1640 -        }
 73.1641 -
 73.1642 -        public boolean containsAll(Collection<?> coll) {
 73.1643 -            synchronized (mutex) {return c.containsAll(coll);}
 73.1644 -        }
 73.1645 -        public boolean addAll(Collection<? extends E> coll) {
 73.1646 -            synchronized (mutex) {return c.addAll(coll);}
 73.1647 -        }
 73.1648 -        public boolean removeAll(Collection<?> coll) {
 73.1649 -            synchronized (mutex) {return c.removeAll(coll);}
 73.1650 -        }
 73.1651 -        public boolean retainAll(Collection<?> coll) {
 73.1652 -            synchronized (mutex) {return c.retainAll(coll);}
 73.1653 -        }
 73.1654 -        public void clear() {
 73.1655 -            synchronized (mutex) {c.clear();}
 73.1656 -        }
 73.1657 -        public String toString() {
 73.1658 -            synchronized (mutex) {return c.toString();}
 73.1659 -        }
 73.1660 -    }
 73.1661 -
 73.1662 -    /**
 73.1663 -     * Returns a synchronized (thread-safe) set backed by the specified
 73.1664 -     * set.  In order to guarantee serial access, it is critical that
 73.1665 -     * <strong>all</strong> access to the backing set is accomplished
 73.1666 -     * through the returned set.<p>
 73.1667 -     *
 73.1668 -     * It is imperative that the user manually synchronize on the returned
 73.1669 -     * set when iterating over it:
 73.1670 -     * <pre>
 73.1671 -     *  Set s = Collections.synchronizedSet(new HashSet());
 73.1672 -     *      ...
 73.1673 -     *  synchronized (s) {
 73.1674 -     *      Iterator i = s.iterator(); // Must be in the synchronized block
 73.1675 -     *      while (i.hasNext())
 73.1676 -     *          foo(i.next());
 73.1677 -     *  }
 73.1678 -     * </pre>
 73.1679 -     * Failure to follow this advice may result in non-deterministic behavior.
 73.1680 -     *
 73.1681 -     * <p>The returned set will be serializable if the specified set is
 73.1682 -     * serializable.
 73.1683 -     *
 73.1684 -     * @param  s the set to be "wrapped" in a synchronized set.
 73.1685 -     * @return a synchronized view of the specified set.
 73.1686 -     */
 73.1687 -    public static <T> Set<T> synchronizedSet(Set<T> s) {
 73.1688 -        return new SynchronizedSet<>(s);
 73.1689 -    }
 73.1690 -
 73.1691 -    static <T> Set<T> synchronizedSet(Set<T> s, Object mutex) {
 73.1692 -        return new SynchronizedSet<>(s, mutex);
 73.1693 -    }
 73.1694 -
 73.1695 -    /**
 73.1696 -     * @serial include
 73.1697 -     */
 73.1698 -    static class SynchronizedSet<E>
 73.1699 -          extends SynchronizedCollection<E>
 73.1700 -          implements Set<E> {
 73.1701 -        private static final long serialVersionUID = 487447009682186044L;
 73.1702 -
 73.1703 -        SynchronizedSet(Set<E> s) {
 73.1704 -            super(s);
 73.1705 -        }
 73.1706 -        SynchronizedSet(Set<E> s, Object mutex) {
 73.1707 -            super(s, mutex);
 73.1708 -        }
 73.1709 -
 73.1710 -        public boolean equals(Object o) {
 73.1711 -            synchronized (mutex) {return c.equals(o);}
 73.1712 -        }
 73.1713 -        public int hashCode() {
 73.1714 -            synchronized (mutex) {return c.hashCode();}
 73.1715 -        }
 73.1716 -    }
 73.1717 -
 73.1718 -    /**
 73.1719 -     * Returns a synchronized (thread-safe) sorted set backed by the specified
 73.1720 -     * sorted set.  In order to guarantee serial access, it is critical that
 73.1721 -     * <strong>all</strong> access to the backing sorted set is accomplished
 73.1722 -     * through the returned sorted set (or its views).<p>
 73.1723 -     *
 73.1724 -     * It is imperative that the user manually synchronize on the returned
 73.1725 -     * sorted set when iterating over it or any of its <tt>subSet</tt>,
 73.1726 -     * <tt>headSet</tt>, or <tt>tailSet</tt> views.
 73.1727 -     * <pre>
 73.1728 -     *  SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
 73.1729 -     *      ...
 73.1730 -     *  synchronized (s) {
 73.1731 -     *      Iterator i = s.iterator(); // Must be in the synchronized block
 73.1732 -     *      while (i.hasNext())
 73.1733 -     *          foo(i.next());
 73.1734 -     *  }
 73.1735 -     * </pre>
 73.1736 -     * or:
 73.1737 -     * <pre>
 73.1738 -     *  SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
 73.1739 -     *  SortedSet s2 = s.headSet(foo);
 73.1740 -     *      ...
 73.1741 -     *  synchronized (s) {  // Note: s, not s2!!!
 73.1742 -     *      Iterator i = s2.iterator(); // Must be in the synchronized block
 73.1743 -     *      while (i.hasNext())
 73.1744 -     *          foo(i.next());
 73.1745 -     *  }
 73.1746 -     * </pre>
 73.1747 -     * Failure to follow this advice may result in non-deterministic behavior.
 73.1748 -     *
 73.1749 -     * <p>The returned sorted set will be serializable if the specified
 73.1750 -     * sorted set is serializable.
 73.1751 -     *
 73.1752 -     * @param  s the sorted set to be "wrapped" in a synchronized sorted set.
 73.1753 -     * @return a synchronized view of the specified sorted set.
 73.1754 -     */
 73.1755 -    public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s) {
 73.1756 -        return new SynchronizedSortedSet<>(s);
 73.1757 -    }
 73.1758 -
 73.1759 -    /**
 73.1760 -     * @serial include
 73.1761 -     */
 73.1762 -    static class SynchronizedSortedSet<E>
 73.1763 -        extends SynchronizedSet<E>
 73.1764 -        implements SortedSet<E>
 73.1765 -    {
 73.1766 -        private static final long serialVersionUID = 8695801310862127406L;
 73.1767 -
 73.1768 -        private final SortedSet<E> ss;
 73.1769 -
 73.1770 -        SynchronizedSortedSet(SortedSet<E> s) {
 73.1771 -            super(s);
 73.1772 -            ss = s;
 73.1773 -        }
 73.1774 -        SynchronizedSortedSet(SortedSet<E> s, Object mutex) {
 73.1775 -            super(s, mutex);
 73.1776 -            ss = s;
 73.1777 -        }
 73.1778 -
 73.1779 -        public Comparator<? super E> comparator() {
 73.1780 -            synchronized (mutex) {return ss.comparator();}
 73.1781 -        }
 73.1782 -
 73.1783 -        public SortedSet<E> subSet(E fromElement, E toElement) {
 73.1784 -            synchronized (mutex) {
 73.1785 -                return new SynchronizedSortedSet<>(
 73.1786 -                    ss.subSet(fromElement, toElement), mutex);
 73.1787 -            }
 73.1788 -        }
 73.1789 -        public SortedSet<E> headSet(E toElement) {
 73.1790 -            synchronized (mutex) {
 73.1791 -                return new SynchronizedSortedSet<>(ss.headSet(toElement), mutex);
 73.1792 -            }
 73.1793 -        }
 73.1794 -        public SortedSet<E> tailSet(E fromElement) {
 73.1795 -            synchronized (mutex) {
 73.1796 -               return new SynchronizedSortedSet<>(ss.tailSet(fromElement),mutex);
 73.1797 -            }
 73.1798 -        }
 73.1799 -
 73.1800 -        public E first() {
 73.1801 -            synchronized (mutex) {return ss.first();}
 73.1802 -        }
 73.1803 -        public E last() {
 73.1804 -            synchronized (mutex) {return ss.last();}
 73.1805 -        }
 73.1806 -    }
 73.1807 -
 73.1808 -    /**
 73.1809 -     * Returns a synchronized (thread-safe) list backed by the specified
 73.1810 -     * list.  In order to guarantee serial access, it is critical that
 73.1811 -     * <strong>all</strong> access to the backing list is accomplished
 73.1812 -     * through the returned list.<p>
 73.1813 -     *
 73.1814 -     * It is imperative that the user manually synchronize on the returned
 73.1815 -     * list when iterating over it:
 73.1816 -     * <pre>
 73.1817 -     *  List list = Collections.synchronizedList(new ArrayList());
 73.1818 -     *      ...
 73.1819 -     *  synchronized (list) {
 73.1820 -     *      Iterator i = list.iterator(); // Must be in synchronized block
 73.1821 -     *      while (i.hasNext())
 73.1822 -     *          foo(i.next());
 73.1823 -     *  }
 73.1824 -     * </pre>
 73.1825 -     * Failure to follow this advice may result in non-deterministic behavior.
 73.1826 -     *
 73.1827 -     * <p>The returned list will be serializable if the specified list is
 73.1828 -     * serializable.
 73.1829 -     *
 73.1830 -     * @param  list the list to be "wrapped" in a synchronized list.
 73.1831 -     * @return a synchronized view of the specified list.
 73.1832 -     */
 73.1833 -    public static <T> List<T> synchronizedList(List<T> list) {
 73.1834 -        return (list instanceof RandomAccess ?
 73.1835 -                new SynchronizedRandomAccessList<>(list) :
 73.1836 -                new SynchronizedList<>(list));
 73.1837 -    }
 73.1838 -
 73.1839 -    static <T> List<T> synchronizedList(List<T> list, Object mutex) {
 73.1840 -        return (list instanceof RandomAccess ?
 73.1841 -                new SynchronizedRandomAccessList<>(list, mutex) :
 73.1842 -                new SynchronizedList<>(list, mutex));
 73.1843 -    }
 73.1844 -
 73.1845 -    /**
 73.1846 -     * @serial include
 73.1847 -     */
 73.1848 -    static class SynchronizedList<E>
 73.1849 -        extends SynchronizedCollection<E>
 73.1850 -        implements List<E> {
 73.1851 -        private static final long serialVersionUID = -7754090372962971524L;
 73.1852 -
 73.1853 -        final List<E> list;
 73.1854 -
 73.1855 -        SynchronizedList(List<E> list) {
 73.1856 -            super(list);
 73.1857 -            this.list = list;
 73.1858 -        }
 73.1859 -        SynchronizedList(List<E> list, Object mutex) {
 73.1860 -            super(list, mutex);
 73.1861 -            this.list = list;
 73.1862 -        }
 73.1863 -
 73.1864 -        public boolean equals(Object o) {
 73.1865 -            synchronized (mutex) {return list.equals(o);}
 73.1866 -        }
 73.1867 -        public int hashCode() {
 73.1868 -            synchronized (mutex) {return list.hashCode();}
 73.1869 -        }
 73.1870 -
 73.1871 -        public E get(int index) {
 73.1872 -            synchronized (mutex) {return list.get(index);}
 73.1873 -        }
 73.1874 -        public E set(int index, E element) {
 73.1875 -            synchronized (mutex) {return list.set(index, element);}
 73.1876 -        }
 73.1877 -        public void add(int index, E element) {
 73.1878 -            synchronized (mutex) {list.add(index, element);}
 73.1879 -        }
 73.1880 -        public E remove(int index) {
 73.1881 -            synchronized (mutex) {return list.remove(index);}
 73.1882 -        }
 73.1883 -
 73.1884 -        public int indexOf(Object o) {
 73.1885 -            synchronized (mutex) {return list.indexOf(o);}
 73.1886 -        }
 73.1887 -        public int lastIndexOf(Object o) {
 73.1888 -            synchronized (mutex) {return list.lastIndexOf(o);}
 73.1889 -        }
 73.1890 -
 73.1891 -        public boolean addAll(int index, Collection<? extends E> c) {
 73.1892 -            synchronized (mutex) {return list.addAll(index, c);}
 73.1893 -        }
 73.1894 -
 73.1895 -        public ListIterator<E> listIterator() {
 73.1896 -            return list.listIterator(); // Must be manually synched by user
 73.1897 -        }
 73.1898 -
 73.1899 -        public ListIterator<E> listIterator(int index) {
 73.1900 -            return list.listIterator(index); // Must be manually synched by user
 73.1901 -        }
 73.1902 -
 73.1903 -        public List<E> subList(int fromIndex, int toIndex) {
 73.1904 -            synchronized (mutex) {
 73.1905 -                return new SynchronizedList<>(list.subList(fromIndex, toIndex),
 73.1906 -                                            mutex);
 73.1907 -            }
 73.1908 -        }
 73.1909 -
 73.1910 -        /**
 73.1911 -         * SynchronizedRandomAccessList instances are serialized as
 73.1912 -         * SynchronizedList instances to allow them to be deserialized
 73.1913 -         * in pre-1.4 JREs (which do not have SynchronizedRandomAccessList).
 73.1914 -         * This method inverts the transformation.  As a beneficial
 73.1915 -         * side-effect, it also grafts the RandomAccess marker onto
 73.1916 -         * SynchronizedList instances that were serialized in pre-1.4 JREs.
 73.1917 -         *
 73.1918 -         * Note: Unfortunately, SynchronizedRandomAccessList instances
 73.1919 -         * serialized in 1.4.1 and deserialized in 1.4 will become
 73.1920 -         * SynchronizedList instances, as this method was missing in 1.4.
 73.1921 -         */
 73.1922 -        private Object readResolve() {
 73.1923 -            return (list instanceof RandomAccess
 73.1924 -                    ? new SynchronizedRandomAccessList<>(list)
 73.1925 -                    : this);
 73.1926 -        }
 73.1927 -    }
 73.1928 -
 73.1929 -    /**
 73.1930 -     * @serial include
 73.1931 -     */
 73.1932 -    static class SynchronizedRandomAccessList<E>
 73.1933 -        extends SynchronizedList<E>
 73.1934 -        implements RandomAccess {
 73.1935 -
 73.1936 -        SynchronizedRandomAccessList(List<E> list) {
 73.1937 -            super(list);
 73.1938 -        }
 73.1939 -
 73.1940 -        SynchronizedRandomAccessList(List<E> list, Object mutex) {
 73.1941 -            super(list, mutex);
 73.1942 -        }
 73.1943 -
 73.1944 -        public List<E> subList(int fromIndex, int toIndex) {
 73.1945 -            synchronized (mutex) {
 73.1946 -                return new SynchronizedRandomAccessList<>(
 73.1947 -                    list.subList(fromIndex, toIndex), mutex);
 73.1948 -            }
 73.1949 -        }
 73.1950 -
 73.1951 -        private static final long serialVersionUID = 1530674583602358482L;
 73.1952 -
 73.1953 -        /**
 73.1954 -         * Allows instances to be deserialized in pre-1.4 JREs (which do
 73.1955 -         * not have SynchronizedRandomAccessList).  SynchronizedList has
 73.1956 -         * a readResolve method that inverts this transformation upon
 73.1957 -         * deserialization.
 73.1958 -         */
 73.1959 -        private Object writeReplace() {
 73.1960 -            return new SynchronizedList<>(list);
 73.1961 -        }
 73.1962 -    }
 73.1963 -
 73.1964 -    /**
 73.1965 -     * Returns a synchronized (thread-safe) map backed by the specified
 73.1966 -     * map.  In order to guarantee serial access, it is critical that
 73.1967 -     * <strong>all</strong> access to the backing map is accomplished
 73.1968 -     * through the returned map.<p>
 73.1969 -     *
 73.1970 -     * It is imperative that the user manually synchronize on the returned
 73.1971 -     * map when iterating over any of its collection views:
 73.1972 -     * <pre>
 73.1973 -     *  Map m = Collections.synchronizedMap(new HashMap());
 73.1974 -     *      ...
 73.1975 -     *  Set s = m.keySet();  // Needn't be in synchronized block
 73.1976 -     *      ...
 73.1977 -     *  synchronized (m) {  // Synchronizing on m, not s!
 73.1978 -     *      Iterator i = s.iterator(); // Must be in synchronized block
 73.1979 -     *      while (i.hasNext())
 73.1980 -     *          foo(i.next());
 73.1981 -     *  }
 73.1982 -     * </pre>
 73.1983 -     * Failure to follow this advice may result in non-deterministic behavior.
 73.1984 -     *
 73.1985 -     * <p>The returned map will be serializable if the specified map is
 73.1986 -     * serializable.
 73.1987 -     *
 73.1988 -     * @param  m the map to be "wrapped" in a synchronized map.
 73.1989 -     * @return a synchronized view of the specified map.
 73.1990 -     */
 73.1991 -    public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) {
 73.1992 -        return new SynchronizedMap<>(m);
 73.1993 -    }
 73.1994 -
 73.1995 -    /**
 73.1996 -     * @serial include
 73.1997 -     */
 73.1998 -    private static class SynchronizedMap<K,V>
 73.1999 -        implements Map<K,V>, Serializable {
 73.2000 -        private static final long serialVersionUID = 1978198479659022715L;
 73.2001 -
 73.2002 -        private final Map<K,V> m;     // Backing Map
 73.2003 -        final Object      mutex;        // Object on which to synchronize
 73.2004 -
 73.2005 -        SynchronizedMap(Map<K,V> m) {
 73.2006 -            if (m==null)
 73.2007 -                throw new NullPointerException();
 73.2008 -            this.m = m;
 73.2009 -            mutex = this;
 73.2010 -        }
 73.2011 -
 73.2012 -        SynchronizedMap(Map<K,V> m, Object mutex) {
 73.2013 -            this.m = m;
 73.2014 -            this.mutex = mutex;
 73.2015 -        }
 73.2016 -
 73.2017 -        public int size() {
 73.2018 -            synchronized (mutex) {return m.size();}
 73.2019 -        }
 73.2020 -        public boolean isEmpty() {
 73.2021 -            synchronized (mutex) {return m.isEmpty();}
 73.2022 -        }
 73.2023 -        public boolean containsKey(Object key) {
 73.2024 -            synchronized (mutex) {return m.containsKey(key);}
 73.2025 -        }
 73.2026 -        public boolean containsValue(Object value) {
 73.2027 -            synchronized (mutex) {return m.containsValue(value);}
 73.2028 -        }
 73.2029 -        public V get(Object key) {
 73.2030 -            synchronized (mutex) {return m.get(key);}
 73.2031 -        }
 73.2032 -
 73.2033 -        public V put(K key, V value) {
 73.2034 -            synchronized (mutex) {return m.put(key, value);}
 73.2035 -        }
 73.2036 -        public V remove(Object key) {
 73.2037 -            synchronized (mutex) {return m.remove(key);}
 73.2038 -        }
 73.2039 -        public void putAll(Map<? extends K, ? extends V> map) {
 73.2040 -            synchronized (mutex) {m.putAll(map);}
 73.2041 -        }
 73.2042 -        public void clear() {
 73.2043 -            synchronized (mutex) {m.clear();}
 73.2044 -        }
 73.2045 -
 73.2046 -        private transient Set<K> keySet = null;
 73.2047 -        private transient Set<Map.Entry<K,V>> entrySet = null;
 73.2048 -        private transient Collection<V> values = null;
 73.2049 -
 73.2050 -        public Set<K> keySet() {
 73.2051 -            synchronized (mutex) {
 73.2052 -                if (keySet==null)
 73.2053 -                    keySet = new SynchronizedSet<>(m.keySet(), mutex);
 73.2054 -                return keySet;
 73.2055 -            }
 73.2056 -        }
 73.2057 -
 73.2058 -        public Set<Map.Entry<K,V>> entrySet() {
 73.2059 -            synchronized (mutex) {
 73.2060 -                if (entrySet==null)
 73.2061 -                    entrySet = new SynchronizedSet<>(m.entrySet(), mutex);
 73.2062 -                return entrySet;
 73.2063 -            }
 73.2064 -        }
 73.2065 -
 73.2066 -        public Collection<V> values() {
 73.2067 -            synchronized (mutex) {
 73.2068 -                if (values==null)
 73.2069 -                    values = new SynchronizedCollection<>(m.values(), mutex);
 73.2070 -                return values;
 73.2071 -            }
 73.2072 -        }
 73.2073 -
 73.2074 -        public boolean equals(Object o) {
 73.2075 -            synchronized (mutex) {return m.equals(o);}
 73.2076 -        }
 73.2077 -        public int hashCode() {
 73.2078 -            synchronized (mutex) {return m.hashCode();}
 73.2079 -        }
 73.2080 -        public String toString() {
 73.2081 -            synchronized (mutex) {return m.toString();}
 73.2082 -        }
 73.2083 -    }
 73.2084 -
 73.2085 -    /**
 73.2086 -     * Returns a synchronized (thread-safe) sorted map backed by the specified
 73.2087 -     * sorted map.  In order to guarantee serial access, it is critical that
 73.2088 -     * <strong>all</strong> access to the backing sorted map is accomplished
 73.2089 -     * through the returned sorted map (or its views).<p>
 73.2090 -     *
 73.2091 -     * It is imperative that the user manually synchronize on the returned
 73.2092 -     * sorted map when iterating over any of its collection views, or the
 73.2093 -     * collections views of any of its <tt>subMap</tt>, <tt>headMap</tt> or
 73.2094 -     * <tt>tailMap</tt> views.
 73.2095 -     * <pre>
 73.2096 -     *  SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
 73.2097 -     *      ...
 73.2098 -     *  Set s = m.keySet();  // Needn't be in synchronized block
 73.2099 -     *      ...
 73.2100 -     *  synchronized (m) {  // Synchronizing on m, not s!
 73.2101 -     *      Iterator i = s.iterator(); // Must be in synchronized block
 73.2102 -     *      while (i.hasNext())
 73.2103 -     *          foo(i.next());
 73.2104 -     *  }
 73.2105 -     * </pre>
 73.2106 -     * or:
 73.2107 -     * <pre>
 73.2108 -     *  SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
 73.2109 -     *  SortedMap m2 = m.subMap(foo, bar);
 73.2110 -     *      ...
 73.2111 -     *  Set s2 = m2.keySet();  // Needn't be in synchronized block
 73.2112 -     *      ...
 73.2113 -     *  synchronized (m) {  // Synchronizing on m, not m2 or s2!
 73.2114 -     *      Iterator i = s.iterator(); // Must be in synchronized block
 73.2115 -     *      while (i.hasNext())
 73.2116 -     *          foo(i.next());
 73.2117 -     *  }
 73.2118 -     * </pre>
 73.2119 -     * Failure to follow this advice may result in non-deterministic behavior.
 73.2120 -     *
 73.2121 -     * <p>The returned sorted map will be serializable if the specified
 73.2122 -     * sorted map is serializable.
 73.2123 -     *
 73.2124 -     * @param  m the sorted map to be "wrapped" in a synchronized sorted map.
 73.2125 -     * @return a synchronized view of the specified sorted map.
 73.2126 -     */
 73.2127 -    public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m) {
 73.2128 -        return new SynchronizedSortedMap<>(m);
 73.2129 -    }
 73.2130 -
 73.2131 -
 73.2132 -    /**
 73.2133 -     * @serial include
 73.2134 -     */
 73.2135 -    static class SynchronizedSortedMap<K,V>
 73.2136 -        extends SynchronizedMap<K,V>
 73.2137 -        implements SortedMap<K,V>
 73.2138 -    {
 73.2139 -        private static final long serialVersionUID = -8798146769416483793L;
 73.2140 -
 73.2141 -        private final SortedMap<K,V> sm;
 73.2142 -
 73.2143 -        SynchronizedSortedMap(SortedMap<K,V> m) {
 73.2144 -            super(m);
 73.2145 -            sm = m;
 73.2146 -        }
 73.2147 -        SynchronizedSortedMap(SortedMap<K,V> m, Object mutex) {
 73.2148 -            super(m, mutex);
 73.2149 -            sm = m;
 73.2150 -        }
 73.2151 -
 73.2152 -        public Comparator<? super K> comparator() {
 73.2153 -            synchronized (mutex) {return sm.comparator();}
 73.2154 -        }
 73.2155 -
 73.2156 -        public SortedMap<K,V> subMap(K fromKey, K toKey) {
 73.2157 -            synchronized (mutex) {
 73.2158 -                return new SynchronizedSortedMap<>(
 73.2159 -                    sm.subMap(fromKey, toKey), mutex);
 73.2160 -            }
 73.2161 -        }
 73.2162 -        public SortedMap<K,V> headMap(K toKey) {
 73.2163 -            synchronized (mutex) {
 73.2164 -                return new SynchronizedSortedMap<>(sm.headMap(toKey), mutex);
 73.2165 -            }
 73.2166 -        }
 73.2167 -        public SortedMap<K,V> tailMap(K fromKey) {
 73.2168 -            synchronized (mutex) {
 73.2169 -               return new SynchronizedSortedMap<>(sm.tailMap(fromKey),mutex);
 73.2170 -            }
 73.2171 -        }
 73.2172 -
 73.2173 -        public K firstKey() {
 73.2174 -            synchronized (mutex) {return sm.firstKey();}
 73.2175 -        }
 73.2176 -        public K lastKey() {
 73.2177 -            synchronized (mutex) {return sm.lastKey();}
 73.2178 -        }
 73.2179 -    }
 73.2180 -
 73.2181 -    // Dynamically typesafe collection wrappers
 73.2182 -
 73.2183 -    /**
 73.2184 -     * Returns a dynamically typesafe view of the specified collection.
 73.2185 -     * Any attempt to insert an element of the wrong type will result in an
 73.2186 -     * immediate {@link ClassCastException}.  Assuming a collection
 73.2187 -     * contains no incorrectly typed elements prior to the time a
 73.2188 -     * dynamically typesafe view is generated, and that all subsequent
 73.2189 -     * access to the collection takes place through the view, it is
 73.2190 -     * <i>guaranteed</i> that the collection cannot contain an incorrectly
 73.2191 -     * typed element.
 73.2192 -     *
 73.2193 -     * <p>The generics mechanism in the language provides compile-time
 73.2194 -     * (static) type checking, but it is possible to defeat this mechanism
 73.2195 -     * with unchecked casts.  Usually this is not a problem, as the compiler
 73.2196 -     * issues warnings on all such unchecked operations.  There are, however,
 73.2197 -     * times when static type checking alone is not sufficient.  For example,
 73.2198 -     * suppose a collection is passed to a third-party library and it is
 73.2199 -     * imperative that the library code not corrupt the collection by
 73.2200 -     * inserting an element of the wrong type.
 73.2201 -     *
 73.2202 -     * <p>Another use of dynamically typesafe views is debugging.  Suppose a
 73.2203 -     * program fails with a {@code ClassCastException}, indicating that an
 73.2204 -     * incorrectly typed element was put into a parameterized collection.
 73.2205 -     * Unfortunately, the exception can occur at any time after the erroneous
 73.2206 -     * element is inserted, so it typically provides little or no information
 73.2207 -     * as to the real source of the problem.  If the problem is reproducible,
 73.2208 -     * one can quickly determine its source by temporarily modifying the
 73.2209 -     * program to wrap the collection with a dynamically typesafe view.
 73.2210 -     * For example, this declaration:
 73.2211 -     *  <pre> {@code
 73.2212 -     *     Collection<String> c = new HashSet<String>();
 73.2213 -     * }</pre>
 73.2214 -     * may be replaced temporarily by this one:
 73.2215 -     *  <pre> {@code
 73.2216 -     *     Collection<String> c = Collections.checkedCollection(
 73.2217 -     *         new HashSet<String>(), String.class);
 73.2218 -     * }</pre>
 73.2219 -     * Running the program again will cause it to fail at the point where
 73.2220 -     * an incorrectly typed element is inserted into the collection, clearly
 73.2221 -     * identifying the source of the problem.  Once the problem is fixed, the
 73.2222 -     * modified declaration may be reverted back to the original.
 73.2223 -     *
 73.2224 -     * <p>The returned collection does <i>not</i> pass the hashCode and equals
 73.2225 -     * operations through to the backing collection, but relies on
 73.2226 -     * {@code Object}'s {@code equals} and {@code hashCode} methods.  This
 73.2227 -     * is necessary to preserve the contracts of these operations in the case
 73.2228 -     * that the backing collection is a set or a list.
 73.2229 -     *
 73.2230 -     * <p>The returned collection will be serializable if the specified
 73.2231 -     * collection is serializable.
 73.2232 -     *
 73.2233 -     * <p>Since {@code null} is considered to be a value of any reference
 73.2234 -     * type, the returned collection permits insertion of null elements
 73.2235 -     * whenever the backing collection does.
 73.2236 -     *
 73.2237 -     * @param c the collection for which a dynamically typesafe view is to be
 73.2238 -     *          returned
 73.2239 -     * @param type the type of element that {@code c} is permitted to hold
 73.2240 -     * @return a dynamically typesafe view of the specified collection
 73.2241 -     * @since 1.5
 73.2242 -     */
 73.2243 -    public static <E> Collection<E> checkedCollection(Collection<E> c,
 73.2244 -                                                      Class<E> type) {
 73.2245 -        return new CheckedCollection<>(c, type);
 73.2246 -    }
 73.2247 -
 73.2248 -    @SuppressWarnings("unchecked")
 73.2249 -    static <T> T[] zeroLengthArray(Class<T> type) {
 73.2250 -        return (T[]) Array.newInstance(type, 0);
 73.2251 -    }
 73.2252 -
 73.2253 -    /**
 73.2254 -     * @serial include
 73.2255 -     */
 73.2256 -    static class CheckedCollection<E> implements Collection<E>, Serializable {
 73.2257 -        private static final long serialVersionUID = 1578914078182001775L;
 73.2258 -
 73.2259 -        final Collection<E> c;
 73.2260 -        final Class<E> type;
 73.2261 -
 73.2262 -        void typeCheck(Object o) {
 73.2263 -            if (o != null && !type.isInstance(o))
 73.2264 -                throw new ClassCastException(badElementMsg(o));
 73.2265 -        }
 73.2266 -
 73.2267 -        private String badElementMsg(Object o) {
 73.2268 -            return "Attempt to insert " + o.getClass() +
 73.2269 -                " element into collection with element type " + type;
 73.2270 -        }
 73.2271 -
 73.2272 -        CheckedCollection(Collection<E> c, Class<E> type) {
 73.2273 -            if (c==null || type == null)
 73.2274 -                throw new NullPointerException();
 73.2275 -            this.c = c;
 73.2276 -            this.type = type;
 73.2277 -        }
 73.2278 -
 73.2279 -        public int size()                 { return c.size(); }
 73.2280 -        public boolean isEmpty()          { return c.isEmpty(); }
 73.2281 -        public boolean contains(Object o) { return c.contains(o); }
 73.2282 -        public Object[] toArray()         { return c.toArray(); }
 73.2283 -        public <T> T[] toArray(T[] a)     { return c.toArray(a); }
 73.2284 -        public String toString()          { return c.toString(); }
 73.2285 -        public boolean remove(Object o)   { return c.remove(o); }
 73.2286 -        public void clear()               {        c.clear(); }
 73.2287 -
 73.2288 -        public boolean containsAll(Collection<?> coll) {
 73.2289 -            return c.containsAll(coll);
 73.2290 -        }
 73.2291 -        public boolean removeAll(Collection<?> coll) {
 73.2292 -            return c.removeAll(coll);
 73.2293 -        }
 73.2294 -        public boolean retainAll(Collection<?> coll) {
 73.2295 -            return c.retainAll(coll);
 73.2296 -        }
 73.2297 -
 73.2298 -        public Iterator<E> iterator() {
 73.2299 -            final Iterator<E> it = c.iterator();
 73.2300 -            return new Iterator<E>() {
 73.2301 -                public boolean hasNext() { return it.hasNext(); }
 73.2302 -                public E next()          { return it.next(); }
 73.2303 -                public void remove()     {        it.remove(); }};
 73.2304 -        }
 73.2305 -
 73.2306 -        public boolean add(E e) {
 73.2307 -            typeCheck(e);
 73.2308 -            return c.add(e);
 73.2309 -        }
 73.2310 -
 73.2311 -        private E[] zeroLengthElementArray = null; // Lazily initialized
 73.2312 -
 73.2313 -        private E[] zeroLengthElementArray() {
 73.2314 -            return zeroLengthElementArray != null ? zeroLengthElementArray :
 73.2315 -                (zeroLengthElementArray = zeroLengthArray(type));
 73.2316 -        }
 73.2317 -
 73.2318 -        @SuppressWarnings("unchecked")
 73.2319 -        Collection<E> checkedCopyOf(Collection<? extends E> coll) {
 73.2320 -            Object[] a = null;
 73.2321 -            try {
 73.2322 -                E[] z = zeroLengthElementArray();
 73.2323 -                a = coll.toArray(z);
 73.2324 -                // Defend against coll violating the toArray contract
 73.2325 -                if (a.getClass() != z.getClass())
 73.2326 -                    a = Arrays.copyOf(a, a.length, z.getClass());
 73.2327 -            } catch (ArrayStoreException ignore) {
 73.2328 -                // To get better and consistent diagnostics,
 73.2329 -                // we call typeCheck explicitly on each element.
 73.2330 -                // We call clone() to defend against coll retaining a
 73.2331 -                // reference to the returned array and storing a bad
 73.2332 -                // element into it after it has been type checked.
 73.2333 -                a = coll.toArray().clone();
 73.2334 -                for (Object o : a)
 73.2335 -                    typeCheck(o);
 73.2336 -            }
 73.2337 -            // A slight abuse of the type system, but safe here.
 73.2338 -            return (Collection<E>) Arrays.asList(a);
 73.2339 -        }
 73.2340 -
 73.2341 -        public boolean addAll(Collection<? extends E> coll) {
 73.2342 -            // Doing things this way insulates us from concurrent changes
 73.2343 -            // in the contents of coll and provides all-or-nothing
 73.2344 -            // semantics (which we wouldn't get if we type-checked each
 73.2345 -            // element as we added it)
 73.2346 -            return c.addAll(checkedCopyOf(coll));
 73.2347 -        }
 73.2348 -    }
 73.2349 -
 73.2350 -    /**
 73.2351 -     * Returns a dynamically typesafe view of the specified set.
 73.2352 -     * Any attempt to insert an element of the wrong type will result in
 73.2353 -     * an immediate {@link ClassCastException}.  Assuming a set contains
 73.2354 -     * no incorrectly typed elements prior to the time a dynamically typesafe
 73.2355 -     * view is generated, and that all subsequent access to the set
 73.2356 -     * takes place through the view, it is <i>guaranteed</i> that the
 73.2357 -     * set cannot contain an incorrectly typed element.
 73.2358 -     *
 73.2359 -     * <p>A discussion of the use of dynamically typesafe views may be
 73.2360 -     * found in the documentation for the {@link #checkedCollection
 73.2361 -     * checkedCollection} method.
 73.2362 -     *
 73.2363 -     * <p>The returned set will be serializable if the specified set is
 73.2364 -     * serializable.
 73.2365 -     *
 73.2366 -     * <p>Since {@code null} is considered to be a value of any reference
 73.2367 -     * type, the returned set permits insertion of null elements whenever
 73.2368 -     * the backing set does.
 73.2369 -     *
 73.2370 -     * @param s the set for which a dynamically typesafe view is to be
 73.2371 -     *          returned
 73.2372 -     * @param type the type of element that {@code s} is permitted to hold
 73.2373 -     * @return a dynamically typesafe view of the specified set
 73.2374 -     * @since 1.5
 73.2375 -     */
 73.2376 -    public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) {
 73.2377 -        return new CheckedSet<>(s, type);
 73.2378 -    }
 73.2379 -
 73.2380 -    /**
 73.2381 -     * @serial include
 73.2382 -     */
 73.2383 -    static class CheckedSet<E> extends CheckedCollection<E>
 73.2384 -                                 implements Set<E>, Serializable
 73.2385 -    {
 73.2386 -        private static final long serialVersionUID = 4694047833775013803L;
 73.2387 -
 73.2388 -        CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); }
 73.2389 -
 73.2390 -        public boolean equals(Object o) { return o == this || c.equals(o); }
 73.2391 -        public int hashCode()           { return c.hashCode(); }
 73.2392 -    }
 73.2393 -
 73.2394 -    /**
 73.2395 -     * Returns a dynamically typesafe view of the specified sorted set.
 73.2396 -     * Any attempt to insert an element of the wrong type will result in an
 73.2397 -     * immediate {@link ClassCastException}.  Assuming a sorted set
 73.2398 -     * contains no incorrectly typed elements prior to the time a
 73.2399 -     * dynamically typesafe view is generated, and that all subsequent
 73.2400 -     * access to the sorted set takes place through the view, it is
 73.2401 -     * <i>guaranteed</i> that the sorted set cannot contain an incorrectly
 73.2402 -     * typed element.
 73.2403 -     *
 73.2404 -     * <p>A discussion of the use of dynamically typesafe views may be
 73.2405 -     * found in the documentation for the {@link #checkedCollection
 73.2406 -     * checkedCollection} method.
 73.2407 -     *
 73.2408 -     * <p>The returned sorted set will be serializable if the specified sorted
 73.2409 -     * set is serializable.
 73.2410 -     *
 73.2411 -     * <p>Since {@code null} is considered to be a value of any reference
 73.2412 -     * type, the returned sorted set permits insertion of null elements
 73.2413 -     * whenever the backing sorted set does.
 73.2414 -     *
 73.2415 -     * @param s the sorted set for which a dynamically typesafe view is to be
 73.2416 -     *          returned
 73.2417 -     * @param type the type of element that {@code s} is permitted to hold
 73.2418 -     * @return a dynamically typesafe view of the specified sorted set
 73.2419 -     * @since 1.5
 73.2420 -     */
 73.2421 -    public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s,
 73.2422 -                                                    Class<E> type) {
 73.2423 -        return new CheckedSortedSet<>(s, type);
 73.2424 -    }
 73.2425 -
 73.2426 -    /**
 73.2427 -     * @serial include
 73.2428 -     */
 73.2429 -    static class CheckedSortedSet<E> extends CheckedSet<E>
 73.2430 -        implements SortedSet<E>, Serializable
 73.2431 -    {
 73.2432 -        private static final long serialVersionUID = 1599911165492914959L;
 73.2433 -        private final SortedSet<E> ss;
 73.2434 -
 73.2435 -        CheckedSortedSet(SortedSet<E> s, Class<E> type) {
 73.2436 -            super(s, type);
 73.2437 -            ss = s;
 73.2438 -        }
 73.2439 -
 73.2440 -        public Comparator<? super E> comparator() { return ss.comparator(); }
 73.2441 -        public E first()                   { return ss.first(); }
 73.2442 -        public E last()                    { return ss.last(); }
 73.2443 -
 73.2444 -        public SortedSet<E> subSet(E fromElement, E toElement) {
 73.2445 -            return checkedSortedSet(ss.subSet(fromElement,toElement), type);
 73.2446 -        }
 73.2447 -        public SortedSet<E> headSet(E toElement) {
 73.2448 -            return checkedSortedSet(ss.headSet(toElement), type);
 73.2449 -        }
 73.2450 -        public SortedSet<E> tailSet(E fromElement) {
 73.2451 -            return checkedSortedSet(ss.tailSet(fromElement), type);
 73.2452 -        }
 73.2453 -    }
 73.2454 -
 73.2455 -    /**
 73.2456 -     * Returns a dynamically typesafe view of the specified list.
 73.2457 -     * Any attempt to insert an element of the wrong type will result in
 73.2458 -     * an immediate {@link ClassCastException}.  Assuming a list contains
 73.2459 -     * no incorrectly typed elements prior to the time a dynamically typesafe
 73.2460 -     * view is generated, and that all subsequent access to the list
 73.2461 -     * takes place through the view, it is <i>guaranteed</i> that the
 73.2462 -     * list cannot contain an incorrectly typed element.
 73.2463 -     *
 73.2464 -     * <p>A discussion of the use of dynamically typesafe views may be
 73.2465 -     * found in the documentation for the {@link #checkedCollection
 73.2466 -     * checkedCollection} method.
 73.2467 -     *
 73.2468 -     * <p>The returned list will be serializable if the specified list
 73.2469 -     * is serializable.
 73.2470 -     *
 73.2471 -     * <p>Since {@code null} is considered to be a value of any reference
 73.2472 -     * type, the returned list permits insertion of null elements whenever
 73.2473 -     * the backing list does.
 73.2474 -     *
 73.2475 -     * @param list the list for which a dynamically typesafe view is to be
 73.2476 -     *             returned
 73.2477 -     * @param type the type of element that {@code list} is permitted to hold
 73.2478 -     * @return a dynamically typesafe view of the specified list
 73.2479 -     * @since 1.5
 73.2480 -     */
 73.2481 -    public static <E> List<E> checkedList(List<E> list, Class<E> type) {
 73.2482 -        return (list instanceof RandomAccess ?
 73.2483 -                new CheckedRandomAccessList<>(list, type) :
 73.2484 -                new CheckedList<>(list, type));
 73.2485 -    }
 73.2486 -
 73.2487 -    /**
 73.2488 -     * @serial include
 73.2489 -     */
 73.2490 -    static class CheckedList<E>
 73.2491 -        extends CheckedCollection<E>
 73.2492 -        implements List<E>
 73.2493 -    {
 73.2494 -        private static final long serialVersionUID = 65247728283967356L;
 73.2495 -        final List<E> list;
 73.2496 -
 73.2497 -        CheckedList(List<E> list, Class<E> type) {
 73.2498 -            super(list, type);
 73.2499 -            this.list = list;
 73.2500 -        }
 73.2501 -
 73.2502 -        public boolean equals(Object o)  { return o == this || list.equals(o); }
 73.2503 -        public int hashCode()            { return list.hashCode(); }
 73.2504 -        public E get(int index)          { return list.get(index); }
 73.2505 -        public E remove(int index)       { return list.remove(index); }
 73.2506 -        public int indexOf(Object o)     { return list.indexOf(o); }
 73.2507 -        public int lastIndexOf(Object o) { return list.lastIndexOf(o); }
 73.2508 -
 73.2509 -        public E set(int index, E element) {
 73.2510 -            typeCheck(element);
 73.2511 -            return list.set(index, element);
 73.2512 -        }
 73.2513 -
 73.2514 -        public void add(int index, E element) {
 73.2515 -            typeCheck(element);
 73.2516 -            list.add(index, element);
 73.2517 -        }
 73.2518 -
 73.2519 -        public boolean addAll(int index, Collection<? extends E> c) {
 73.2520 -            return list.addAll(index, checkedCopyOf(c));
 73.2521 -        }
 73.2522 -        public ListIterator<E> listIterator()   { return listIterator(0); }
 73.2523 -
 73.2524 -        public ListIterator<E> listIterator(final int index) {
 73.2525 -            final ListIterator<E> i = list.listIterator(index);
 73.2526 -
 73.2527 -            return new ListIterator<E>() {
 73.2528 -                public boolean hasNext()     { return i.hasNext(); }
 73.2529 -                public E next()              { return i.next(); }
 73.2530 -                public boolean hasPrevious() { return i.hasPrevious(); }
 73.2531 -                public E previous()          { return i.previous(); }
 73.2532 -                public int nextIndex()       { return i.nextIndex(); }
 73.2533 -                public int previousIndex()   { return i.previousIndex(); }
 73.2534 -                public void remove()         {        i.remove(); }
 73.2535 -
 73.2536 -                public void set(E e) {
 73.2537 -                    typeCheck(e);
 73.2538 -                    i.set(e);
 73.2539 -                }
 73.2540 -
 73.2541 -                public void add(E e) {
 73.2542 -                    typeCheck(e);
 73.2543 -                    i.add(e);
 73.2544 -                }
 73.2545 -            };
 73.2546 -        }
 73.2547 -
 73.2548 -        public List<E> subList(int fromIndex, int toIndex) {
 73.2549 -            return new CheckedList<>(list.subList(fromIndex, toIndex), type);
 73.2550 -        }
 73.2551 -    }
 73.2552 -
 73.2553 -    /**
 73.2554 -     * @serial include
 73.2555 -     */
 73.2556 -    static class CheckedRandomAccessList<E> extends CheckedList<E>
 73.2557 -                                            implements RandomAccess
 73.2558 -    {
 73.2559 -        private static final long serialVersionUID = 1638200125423088369L;
 73.2560 -
 73.2561 -        CheckedRandomAccessList(List<E> list, Class<E> type) {
 73.2562 -            super(list, type);
 73.2563 -        }
 73.2564 -
 73.2565 -        public List<E> subList(int fromIndex, int toIndex) {
 73.2566 -            return new CheckedRandomAccessList<>(
 73.2567 -                list.subList(fromIndex, toIndex), type);
 73.2568 -        }
 73.2569 -    }
 73.2570 -
 73.2571 -    /**
 73.2572 -     * Returns a dynamically typesafe view of the specified map.
 73.2573 -     * Any attempt to insert a mapping whose key or value have the wrong
 73.2574 -     * type will result in an immediate {@link ClassCastException}.
 73.2575 -     * Similarly, any attempt to modify the value currently associated with
 73.2576 -     * a key will result in an immediate {@link ClassCastException},
 73.2577 -     * whether the modification is attempted directly through the map
 73.2578 -     * itself, or through a {@link Map.Entry} instance obtained from the
 73.2579 -     * map's {@link Map#entrySet() entry set} view.
 73.2580 -     *
 73.2581 -     * <p>Assuming a map contains no incorrectly typed keys or values
 73.2582 -     * prior to the time a dynamically typesafe view is generated, and
 73.2583 -     * that all subsequent access to the map takes place through the view
 73.2584 -     * (or one of its collection views), it is <i>guaranteed</i> that the
 73.2585 -     * map cannot contain an incorrectly typed key or value.
 73.2586 -     *
 73.2587 -     * <p>A discussion of the use of dynamically typesafe views may be
 73.2588 -     * found in the documentation for the {@link #checkedCollection
 73.2589 -     * checkedCollection} method.
 73.2590 -     *
 73.2591 -     * <p>The returned map will be serializable if the specified map is
 73.2592 -     * serializable.
 73.2593 -     *
 73.2594 -     * <p>Since {@code null} is considered to be a value of any reference
 73.2595 -     * type, the returned map permits insertion of null keys or values
 73.2596 -     * whenever the backing map does.
 73.2597 -     *
 73.2598 -     * @param m the map for which a dynamically typesafe view is to be
 73.2599 -     *          returned
 73.2600 -     * @param keyType the type of key that {@code m} is permitted to hold
 73.2601 -     * @param valueType the type of value that {@code m} is permitted to hold
 73.2602 -     * @return a dynamically typesafe view of the specified map
 73.2603 -     * @since 1.5
 73.2604 -     */
 73.2605 -    public static <K, V> Map<K, V> checkedMap(Map<K, V> m,
 73.2606 -                                              Class<K> keyType,
 73.2607 -                                              Class<V> valueType) {
 73.2608 -        return new CheckedMap<>(m, keyType, valueType);
 73.2609 -    }
 73.2610 -
 73.2611 -
 73.2612 -    /**
 73.2613 -     * @serial include
 73.2614 -     */
 73.2615 -    private static class CheckedMap<K,V>
 73.2616 -        implements Map<K,V>, Serializable
 73.2617 -    {
 73.2618 -        private static final long serialVersionUID = 5742860141034234728L;
 73.2619 -
 73.2620 -        private final Map<K, V> m;
 73.2621 -        final Class<K> keyType;
 73.2622 -        final Class<V> valueType;
 73.2623 -
 73.2624 -        private void typeCheck(Object key, Object value) {
 73.2625 -            if (key != null && !keyType.isInstance(key))
 73.2626 -                throw new ClassCastException(badKeyMsg(key));
 73.2627 -
 73.2628 -            if (value != null && !valueType.isInstance(value))
 73.2629 -                throw new ClassCastException(badValueMsg(value));
 73.2630 -        }
 73.2631 -
 73.2632 -        private String badKeyMsg(Object key) {
 73.2633 -            return "Attempt to insert " + key.getClass() +
 73.2634 -                " key into map with key type " + keyType;
 73.2635 -        }
 73.2636 -
 73.2637 -        private String badValueMsg(Object value) {
 73.2638 -            return "Attempt to insert " + value.getClass() +
 73.2639 -                " value into map with value type " + valueType;
 73.2640 -        }
 73.2641 -
 73.2642 -        CheckedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType) {
 73.2643 -            if (m == null || keyType == null || valueType == null)
 73.2644 -                throw new NullPointerException();
 73.2645 -            this.m = m;
 73.2646 -            this.keyType = keyType;
 73.2647 -            this.valueType = valueType;
 73.2648 -        }
 73.2649 -
 73.2650 -        public int size()                      { return m.size(); }
 73.2651 -        public boolean isEmpty()               { return m.isEmpty(); }
 73.2652 -        public boolean containsKey(Object key) { return m.containsKey(key); }
 73.2653 -        public boolean containsValue(Object v) { return m.containsValue(v); }
 73.2654 -        public V get(Object key)               { return m.get(key); }
 73.2655 -        public V remove(Object key)            { return m.remove(key); }
 73.2656 -        public void clear()                    { m.clear(); }
 73.2657 -        public Set<K> keySet()                 { return m.keySet(); }
 73.2658 -        public Collection<V> values()          { return m.values(); }
 73.2659 -        public boolean equals(Object o)        { return o == this || m.equals(o); }
 73.2660 -        public int hashCode()                  { return m.hashCode(); }
 73.2661 -        public String toString()               { return m.toString(); }
 73.2662 -
 73.2663 -        public V put(K key, V value) {
 73.2664 -            typeCheck(key, value);
 73.2665 -            return m.put(key, value);
 73.2666 -        }
 73.2667 -
 73.2668 -        @SuppressWarnings("unchecked")
 73.2669 -        public void putAll(Map<? extends K, ? extends V> t) {
 73.2670 -            // Satisfy the following goals:
 73.2671 -            // - good diagnostics in case of type mismatch
 73.2672 -            // - all-or-nothing semantics
 73.2673 -            // - protection from malicious t
 73.2674 -            // - correct behavior if t is a concurrent map
 73.2675 -            Object[] entries = t.entrySet().toArray();
 73.2676 -            List<Map.Entry<K,V>> checked = new ArrayList<>(entries.length);
 73.2677 -            for (Object o : entries) {
 73.2678 -                Map.Entry<?,?> e = (Map.Entry<?,?>) o;
 73.2679 -                Object k = e.getKey();
 73.2680 -                Object v = e.getValue();
 73.2681 -                typeCheck(k, v);
 73.2682 -                checked.add(
 73.2683 -                    new AbstractMap.SimpleImmutableEntry<>((K) k, (V) v));
 73.2684 -            }
 73.2685 -            for (Map.Entry<K,V> e : checked)
 73.2686 -                m.put(e.getKey(), e.getValue());
 73.2687 -        }
 73.2688 -
 73.2689 -        private transient Set<Map.Entry<K,V>> entrySet = null;
 73.2690 -
 73.2691 -        public Set<Map.Entry<K,V>> entrySet() {
 73.2692 -            if (entrySet==null)
 73.2693 -                entrySet = new CheckedEntrySet<>(m.entrySet(), valueType);
 73.2694 -            return entrySet;
 73.2695 -        }
 73.2696 -
 73.2697 -        /**
 73.2698 -         * We need this class in addition to CheckedSet as Map.Entry permits
 73.2699 -         * modification of the backing Map via the setValue operation.  This
 73.2700 -         * class is subtle: there are many possible attacks that must be
 73.2701 -         * thwarted.
 73.2702 -         *
 73.2703 -         * @serial exclude
 73.2704 -         */
 73.2705 -        static class CheckedEntrySet<K,V> implements Set<Map.Entry<K,V>> {
 73.2706 -            private final Set<Map.Entry<K,V>> s;
 73.2707 -            private final Class<V> valueType;
 73.2708 -
 73.2709 -            CheckedEntrySet(Set<Map.Entry<K, V>> s, Class<V> valueType) {
 73.2710 -                this.s = s;
 73.2711 -                this.valueType = valueType;
 73.2712 -            }
 73.2713 -
 73.2714 -            public int size()        { return s.size(); }
 73.2715 -            public boolean isEmpty() { return s.isEmpty(); }
 73.2716 -            public String toString() { return s.toString(); }
 73.2717 -            public int hashCode()    { return s.hashCode(); }
 73.2718 -            public void clear()      {        s.clear(); }
 73.2719 -
 73.2720 -            public boolean add(Map.Entry<K, V> e) {
 73.2721 -                throw new UnsupportedOperationException();
 73.2722 -            }
 73.2723 -            public boolean addAll(Collection<? extends Map.Entry<K, V>> coll) {
 73.2724 -                throw new UnsupportedOperationException();
 73.2725 -            }
 73.2726 -
 73.2727 -            public Iterator<Map.Entry<K,V>> iterator() {
 73.2728 -                final Iterator<Map.Entry<K, V>> i = s.iterator();
 73.2729 -                final Class<V> valueType = this.valueType;
 73.2730 -
 73.2731 -                return new Iterator<Map.Entry<K,V>>() {
 73.2732 -                    public boolean hasNext() { return i.hasNext(); }
 73.2733 -                    public void remove()     { i.remove(); }
 73.2734 -
 73.2735 -                    public Map.Entry<K,V> next() {
 73.2736 -                        return checkedEntry(i.next(), valueType);
 73.2737 -                    }
 73.2738 -                };
 73.2739 -            }
 73.2740 -
 73.2741 -            @SuppressWarnings("unchecked")
 73.2742 -            public Object[] toArray() {
 73.2743 -                Object[] source = s.toArray();
 73.2744 -
 73.2745 -                /*
 73.2746 -                 * Ensure that we don't get an ArrayStoreException even if
 73.2747 -                 * s.toArray returns an array of something other than Object
 73.2748 -                 */
 73.2749 -                Object[] dest = (CheckedEntry.class.isInstance(
 73.2750 -                    source.getClass().getComponentType()) ? source :
 73.2751 -                                 new Object[source.length]);
 73.2752 -
 73.2753 -                for (int i = 0; i < source.length; i++)
 73.2754 -                    dest[i] = checkedEntry((Map.Entry<K,V>)source[i],
 73.2755 -                                           valueType);
 73.2756 -                return dest;
 73.2757 -            }
 73.2758 -
 73.2759 -            @SuppressWarnings("unchecked")
 73.2760 -            public <T> T[] toArray(T[] a) {
 73.2761 -                // We don't pass a to s.toArray, to avoid window of
 73.2762 -                // vulnerability wherein an unscrupulous multithreaded client
 73.2763 -                // could get his hands on raw (unwrapped) Entries from s.
 73.2764 -                T[] arr = s.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
 73.2765 -
 73.2766 -                for (int i=0; i<arr.length; i++)
 73.2767 -                    arr[i] = (T) checkedEntry((Map.Entry<K,V>)arr[i],
 73.2768 -                                              valueType);
 73.2769 -                if (arr.length > a.length)
 73.2770 -                    return arr;
 73.2771 -
 73.2772 -                System.arraycopy(arr, 0, a, 0, arr.length);
 73.2773 -                if (a.length > arr.length)
 73.2774 -                    a[arr.length] = null;
 73.2775 -                return a;
 73.2776 -            }
 73.2777 -
 73.2778 -            /**
 73.2779 -             * This method is overridden to protect the backing set against
 73.2780 -             * an object with a nefarious equals function that senses
 73.2781 -             * that the equality-candidate is Map.Entry and calls its
 73.2782 -             * setValue method.
 73.2783 -             */
 73.2784 -            public boolean contains(Object o) {
 73.2785 -                if (!(o instanceof Map.Entry))
 73.2786 -                    return false;
 73.2787 -                Map.Entry<?,?> e = (Map.Entry<?,?>) o;
 73.2788 -                return s.contains(
 73.2789 -                    (e instanceof CheckedEntry) ? e : checkedEntry(e, valueType));
 73.2790 -            }
 73.2791 -
 73.2792 -            /**
 73.2793 -             * The bulk collection methods are overridden to protect
 73.2794 -             * against an unscrupulous collection whose contains(Object o)
 73.2795 -             * method senses when o is a Map.Entry, and calls o.setValue.
 73.2796 -             */
 73.2797 -            public boolean containsAll(Collection<?> c) {
 73.2798 -                for (Object o : c)
 73.2799 -                    if (!contains(o)) // Invokes safe contains() above
 73.2800 -                        return false;
 73.2801 -                return true;
 73.2802 -            }
 73.2803 -
 73.2804 -            public boolean remove(Object o) {
 73.2805 -                if (!(o instanceof Map.Entry))
 73.2806 -                    return false;
 73.2807 -                return s.remove(new AbstractMap.SimpleImmutableEntry
 73.2808 -                                <>((Map.Entry<?,?>)o));
 73.2809 -            }
 73.2810 -
 73.2811 -            public boolean removeAll(Collection<?> c) {
 73.2812 -                return batchRemove(c, false);
 73.2813 -            }
 73.2814 -            public boolean retainAll(Collection<?> c) {
 73.2815 -                return batchRemove(c, true);
 73.2816 -            }
 73.2817 -            private boolean batchRemove(Collection<?> c, boolean complement) {
 73.2818 -                boolean modified = false;
 73.2819 -                Iterator<Map.Entry<K,V>> it = iterator();
 73.2820 -                while (it.hasNext()) {
 73.2821 -                    if (c.contains(it.next()) != complement) {
 73.2822 -                        it.remove();
 73.2823 -                        modified = true;
 73.2824 -                    }
 73.2825 -                }
 73.2826 -                return modified;
 73.2827 -            }
 73.2828 -
 73.2829 -            public boolean equals(Object o) {
 73.2830 -                if (o == this)
 73.2831 -                    return true;
 73.2832 -                if (!(o instanceof Set))
 73.2833 -                    return false;
 73.2834 -                Set<?> that = (Set<?>) o;
 73.2835 -                return that.size() == s.size()
 73.2836 -                    && containsAll(that); // Invokes safe containsAll() above
 73.2837 -            }
 73.2838 -
 73.2839 -            static <K,V,T> CheckedEntry<K,V,T> checkedEntry(Map.Entry<K,V> e,
 73.2840 -                                                            Class<T> valueType) {
 73.2841 -                return new CheckedEntry<>(e, valueType);
 73.2842 -            }
 73.2843 -
 73.2844 -            /**
 73.2845 -             * This "wrapper class" serves two purposes: it prevents
 73.2846 -             * the client from modifying the backing Map, by short-circuiting
 73.2847 -             * the setValue method, and it protects the backing Map against
 73.2848 -             * an ill-behaved Map.Entry that attempts to modify another
 73.2849 -             * Map.Entry when asked to perform an equality check.
 73.2850 -             */
 73.2851 -            private static class CheckedEntry<K,V,T> implements Map.Entry<K,V> {
 73.2852 -                private final Map.Entry<K, V> e;
 73.2853 -                private final Class<T> valueType;
 73.2854 -
 73.2855 -                CheckedEntry(Map.Entry<K, V> e, Class<T> valueType) {
 73.2856 -                    this.e = e;
 73.2857 -                    this.valueType = valueType;
 73.2858 -                }
 73.2859 -
 73.2860 -                public K getKey()        { return e.getKey(); }
 73.2861 -                public V getValue()      { return e.getValue(); }
 73.2862 -                public int hashCode()    { return e.hashCode(); }
 73.2863 -                public String toString() { return e.toString(); }
 73.2864 -
 73.2865 -                public V setValue(V value) {
 73.2866 -                    if (value != null && !valueType.isInstance(value))
 73.2867 -                        throw new ClassCastException(badValueMsg(value));
 73.2868 -                    return e.setValue(value);
 73.2869 -                }
 73.2870 -
 73.2871 -                private String badValueMsg(Object value) {
 73.2872 -                    return "Attempt to insert " + value.getClass() +
 73.2873 -                        " value into map with value type " + valueType;
 73.2874 -                }
 73.2875 -
 73.2876 -                public boolean equals(Object o) {
 73.2877 -                    if (o == this)
 73.2878 -                        return true;
 73.2879 -                    if (!(o instanceof Map.Entry))
 73.2880 -                        return false;
 73.2881 -                    return e.equals(new AbstractMap.SimpleImmutableEntry
 73.2882 -                                    <>((Map.Entry<?,?>)o));
 73.2883 -                }
 73.2884 -            }
 73.2885 -        }
 73.2886 -    }
 73.2887 -
 73.2888 -    /**
 73.2889 -     * Returns a dynamically typesafe view of the specified sorted map.
 73.2890 -     * Any attempt to insert a mapping whose key or value have the wrong
 73.2891 -     * type will result in an immediate {@link ClassCastException}.
 73.2892 -     * Similarly, any attempt to modify the value currently associated with
 73.2893 -     * a key will result in an immediate {@link ClassCastException},
 73.2894 -     * whether the modification is attempted directly through the map
 73.2895 -     * itself, or through a {@link Map.Entry} instance obtained from the
 73.2896 -     * map's {@link Map#entrySet() entry set} view.
 73.2897 -     *
 73.2898 -     * <p>Assuming a map contains no incorrectly typed keys or values
 73.2899 -     * prior to the time a dynamically typesafe view is generated, and
 73.2900 -     * that all subsequent access to the map takes place through the view
 73.2901 -     * (or one of its collection views), it is <i>guaranteed</i> that the
 73.2902 -     * map cannot contain an incorrectly typed key or value.
 73.2903 -     *
 73.2904 -     * <p>A discussion of the use of dynamically typesafe views may be
 73.2905 -     * found in the documentation for the {@link #checkedCollection
 73.2906 -     * checkedCollection} method.
 73.2907 -     *
 73.2908 -     * <p>The returned map will be serializable if the specified map is
 73.2909 -     * serializable.
 73.2910 -     *
 73.2911 -     * <p>Since {@code null} is considered to be a value of any reference
 73.2912 -     * type, the returned map permits insertion of null keys or values
 73.2913 -     * whenever the backing map does.
 73.2914 -     *
 73.2915 -     * @param m the map for which a dynamically typesafe view is to be
 73.2916 -     *          returned
 73.2917 -     * @param keyType the type of key that {@code m} is permitted to hold
 73.2918 -     * @param valueType the type of value that {@code m} is permitted to hold
 73.2919 -     * @return a dynamically typesafe view of the specified map
 73.2920 -     * @since 1.5
 73.2921 -     */
 73.2922 -    public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K, V> m,
 73.2923 -                                                        Class<K> keyType,
 73.2924 -                                                        Class<V> valueType) {
 73.2925 -        return new CheckedSortedMap<>(m, keyType, valueType);
 73.2926 -    }
 73.2927 -
 73.2928 -    /**
 73.2929 -     * @serial include
 73.2930 -     */
 73.2931 -    static class CheckedSortedMap<K,V> extends CheckedMap<K,V>
 73.2932 -        implements SortedMap<K,V>, Serializable
 73.2933 -    {
 73.2934 -        private static final long serialVersionUID = 1599671320688067438L;
 73.2935 -
 73.2936 -        private final SortedMap<K, V> sm;
 73.2937 -
 73.2938 -        CheckedSortedMap(SortedMap<K, V> m,
 73.2939 -                         Class<K> keyType, Class<V> valueType) {
 73.2940 -            super(m, keyType, valueType);
 73.2941 -            sm = m;
 73.2942 -        }
 73.2943 -
 73.2944 -        public Comparator<? super K> comparator() { return sm.comparator(); }
 73.2945 -        public K firstKey()                       { return sm.firstKey(); }
 73.2946 -        public K lastKey()                        { return sm.lastKey(); }
 73.2947 -
 73.2948 -        public SortedMap<K,V> subMap(K fromKey, K toKey) {
 73.2949 -            return checkedSortedMap(sm.subMap(fromKey, toKey),
 73.2950 -                                    keyType, valueType);
 73.2951 -        }
 73.2952 -        public SortedMap<K,V> headMap(K toKey) {
 73.2953 -            return checkedSortedMap(sm.headMap(toKey), keyType, valueType);
 73.2954 -        }
 73.2955 -        public SortedMap<K,V> tailMap(K fromKey) {
 73.2956 -            return checkedSortedMap(sm.tailMap(fromKey), keyType, valueType);
 73.2957 -        }
 73.2958 -    }
 73.2959 -
 73.2960 -    // Empty collections
 73.2961 -
 73.2962 -    /**
 73.2963 -     * Returns an iterator that has no elements.  More precisely,
 73.2964 -     *
 73.2965 -     * <ul compact>
 73.2966 -     *
 73.2967 -     * <li>{@link Iterator#hasNext hasNext} always returns {@code
 73.2968 -     * false}.
 73.2969 -     *
 73.2970 -     * <li>{@link Iterator#next next} always throws {@link
 73.2971 -     * NoSuchElementException}.
 73.2972 -     *
 73.2973 -     * <li>{@link Iterator#remove remove} always throws {@link
 73.2974 -     * IllegalStateException}.
 73.2975 -     *
 73.2976 -     * </ul>
 73.2977 -     *
 73.2978 -     * <p>Implementations of this method are permitted, but not
 73.2979 -     * required, to return the same object from multiple invocations.
 73.2980 -     *
 73.2981 -     * @return an empty iterator
 73.2982 -     * @since 1.7
 73.2983 -     */
 73.2984 -    @SuppressWarnings("unchecked")
 73.2985 -    public static <T> Iterator<T> emptyIterator() {
 73.2986 -        return (Iterator<T>) EmptyIterator.EMPTY_ITERATOR;
 73.2987 -    }
 73.2988 -
 73.2989 -    private static class EmptyIterator<E> implements Iterator<E> {
 73.2990 -        static final EmptyIterator<Object> EMPTY_ITERATOR
 73.2991 -            = new EmptyIterator<>();
 73.2992 -
 73.2993 -        public boolean hasNext() { return false; }
 73.2994 -        public E next() { throw new NoSuchElementException(); }
 73.2995 -        public void remove() { throw new IllegalStateException(); }
 73.2996 -    }
 73.2997 -
 73.2998 -    /**
 73.2999 -     * Returns a list iterator that has no elements.  More precisely,
 73.3000 -     *
 73.3001 -     * <ul compact>
 73.3002 -     *
 73.3003 -     * <li>{@link Iterator#hasNext hasNext} and {@link
 73.3004 -     * ListIterator#hasPrevious hasPrevious} always return {@code
 73.3005 -     * false}.
 73.3006 -     *
 73.3007 -     * <li>{@link Iterator#next next} and {@link ListIterator#previous
 73.3008 -     * previous} always throw {@link NoSuchElementException}.
 73.3009 -     *
 73.3010 -     * <li>{@link Iterator#remove remove} and {@link ListIterator#set
 73.3011 -     * set} always throw {@link IllegalStateException}.
 73.3012 -     *
 73.3013 -     * <li>{@link ListIterator#add add} always throws {@link
 73.3014 -     * UnsupportedOperationException}.
 73.3015 -     *
 73.3016 -     * <li>{@link ListIterator#nextIndex nextIndex} always returns
 73.3017 -     * {@code 0} .
 73.3018 -     *
 73.3019 -     * <li>{@link ListIterator#previousIndex previousIndex} always
 73.3020 -     * returns {@code -1}.
 73.3021 -     *
 73.3022 -     * </ul>
 73.3023 -     *
 73.3024 -     * <p>Implementations of this method are permitted, but not
 73.3025 -     * required, to return the same object from multiple invocations.
 73.3026 -     *
 73.3027 -     * @return an empty list iterator
 73.3028 -     * @since 1.7
 73.3029 -     */
 73.3030 -    @SuppressWarnings("unchecked")
 73.3031 -    public static <T> ListIterator<T> emptyListIterator() {
 73.3032 -        return (ListIterator<T>) EmptyListIterator.EMPTY_ITERATOR;
 73.3033 -    }
 73.3034 -
 73.3035 -    private static class EmptyListIterator<E>
 73.3036 -        extends EmptyIterator<E>
 73.3037 -        implements ListIterator<E>
 73.3038 -    {
 73.3039 -        static final EmptyListIterator<Object> EMPTY_ITERATOR
 73.3040 -            = new EmptyListIterator<>();
 73.3041 -
 73.3042 -        public boolean hasPrevious() { return false; }
 73.3043 -        public E previous() { throw new NoSuchElementException(); }
 73.3044 -        public int nextIndex()     { return 0; }
 73.3045 -        public int previousIndex() { return -1; }
 73.3046 -        public void set(E e) { throw new IllegalStateException(); }
 73.3047 -        public void add(E e) { throw new UnsupportedOperationException(); }
 73.3048 -    }
 73.3049 -
 73.3050 -    /**
 73.3051 -     * Returns an enumeration that has no elements.  More precisely,
 73.3052 -     *
 73.3053 -     * <ul compact>
 73.3054 -     *
 73.3055 -     * <li>{@link Enumeration#hasMoreElements hasMoreElements} always
 73.3056 -     * returns {@code false}.
 73.3057 -     *
 73.3058 -     * <li> {@link Enumeration#nextElement nextElement} always throws
 73.3059 -     * {@link NoSuchElementException}.
 73.3060 -     *
 73.3061 -     * </ul>
 73.3062 -     *
 73.3063 -     * <p>Implementations of this method are permitted, but not
 73.3064 -     * required, to return the same object from multiple invocations.
 73.3065 -     *
 73.3066 -     * @return an empty enumeration
 73.3067 -     * @since 1.7
 73.3068 -     */
 73.3069 -    @SuppressWarnings("unchecked")
 73.3070 -    public static <T> Enumeration<T> emptyEnumeration() {
 73.3071 -        return (Enumeration<T>) EmptyEnumeration.EMPTY_ENUMERATION;
 73.3072 -    }
 73.3073 -
 73.3074 -    private static class EmptyEnumeration<E> implements Enumeration<E> {
 73.3075 -        static final EmptyEnumeration<Object> EMPTY_ENUMERATION
 73.3076 -            = new EmptyEnumeration<>();
 73.3077 -
 73.3078 -        public boolean hasMoreElements() { return false; }
 73.3079 -        public E nextElement() { throw new NoSuchElementException(); }
 73.3080 -    }
 73.3081 -
 73.3082 -    /**
 73.3083 -     * The empty set (immutable).  This set is serializable.
 73.3084 -     *
 73.3085 -     * @see #emptySet()
 73.3086 -     */
 73.3087 -    @SuppressWarnings("unchecked")
 73.3088 -    public static final Set EMPTY_SET = new EmptySet<>();
 73.3089 -
 73.3090 -    /**
 73.3091 -     * Returns the empty set (immutable).  This set is serializable.
 73.3092 -     * Unlike the like-named field, this method is parameterized.
 73.3093 -     *
 73.3094 -     * <p>This example illustrates the type-safe way to obtain an empty set:
 73.3095 -     * <pre>
 73.3096 -     *     Set&lt;String&gt; s = Collections.emptySet();
 73.3097 -     * </pre>
 73.3098 -     * Implementation note:  Implementations of this method need not
 73.3099 -     * create a separate <tt>Set</tt> object for each call.   Using this
 73.3100 -     * method is likely to have comparable cost to using the like-named
 73.3101 -     * field.  (Unlike this method, the field does not provide type safety.)
 73.3102 -     *
 73.3103 -     * @see #EMPTY_SET
 73.3104 -     * @since 1.5
 73.3105 -     */
 73.3106 -    @SuppressWarnings("unchecked")
 73.3107 -    public static final <T> Set<T> emptySet() {
 73.3108 -        return (Set<T>) EMPTY_SET;
 73.3109 -    }
 73.3110 -
 73.3111 -    /**
 73.3112 -     * @serial include
 73.3113 -     */
 73.3114 -    private static class EmptySet<E>
 73.3115 -        extends AbstractSet<E>
 73.3116 -        implements Serializable
 73.3117 -    {
 73.3118 -        private static final long serialVersionUID = 1582296315990362920L;
 73.3119 -
 73.3120 -        public Iterator<E> iterator() { return emptyIterator(); }
 73.3121 -
 73.3122 -        public int size() {return 0;}
 73.3123 -        public boolean isEmpty() {return true;}
 73.3124 -
 73.3125 -        public boolean contains(Object obj) {return false;}
 73.3126 -        public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
 73.3127 -
 73.3128 -        public Object[] toArray() { return new Object[0]; }
 73.3129 -
 73.3130 -        public <T> T[] toArray(T[] a) {
 73.3131 -            if (a.length > 0)
 73.3132 -                a[0] = null;
 73.3133 -            return a;
 73.3134 -        }
 73.3135 -
 73.3136 -        // Preserves singleton property
 73.3137 -        private Object readResolve() {
 73.3138 -            return EMPTY_SET;
 73.3139 -        }
 73.3140 -    }
 73.3141 -
 73.3142 -    /**
 73.3143 -     * The empty list (immutable).  This list is serializable.
 73.3144 -     *
 73.3145 -     * @see #emptyList()
 73.3146 -     */
 73.3147 -    @SuppressWarnings("unchecked")
 73.3148 -    public static final List EMPTY_LIST = new EmptyList<>();
 73.3149 -
 73.3150 -    /**
 73.3151 -     * Returns the empty list (immutable).  This list is serializable.
 73.3152 -     *
 73.3153 -     * <p>This example illustrates the type-safe way to obtain an empty list:
 73.3154 -     * <pre>
 73.3155 -     *     List&lt;String&gt; s = Collections.emptyList();
 73.3156 -     * </pre>
 73.3157 -     * Implementation note:  Implementations of this method need not
 73.3158 -     * create a separate <tt>List</tt> object for each call.   Using this
 73.3159 -     * method is likely to have comparable cost to using the like-named
 73.3160 -     * field.  (Unlike this method, the field does not provide type safety.)
 73.3161 -     *
 73.3162 -     * @see #EMPTY_LIST
 73.3163 -     * @since 1.5
 73.3164 -     */
 73.3165 -    @SuppressWarnings("unchecked")
 73.3166 -    public static final <T> List<T> emptyList() {
 73.3167 -        return (List<T>) EMPTY_LIST;
 73.3168 -    }
 73.3169 -
 73.3170 -    /**
 73.3171 -     * @serial include
 73.3172 -     */
 73.3173 -    private static class EmptyList<E>
 73.3174 -        extends AbstractList<E>
 73.3175 -        implements RandomAccess, Serializable {
 73.3176 -        private static final long serialVersionUID = 8842843931221139166L;
 73.3177 -
 73.3178 -        public Iterator<E> iterator() {
 73.3179 -            return emptyIterator();
 73.3180 -        }
 73.3181 -        public ListIterator<E> listIterator() {
 73.3182 -            return emptyListIterator();
 73.3183 -        }
 73.3184 -
 73.3185 -        public int size() {return 0;}
 73.3186 -        public boolean isEmpty() {return true;}
 73.3187 -
 73.3188 -        public boolean contains(Object obj) {return false;}
 73.3189 -        public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
 73.3190 -
 73.3191 -        public Object[] toArray() { return new Object[0]; }
 73.3192 -
 73.3193 -        public <T> T[] toArray(T[] a) {
 73.3194 -            if (a.length > 0)
 73.3195 -                a[0] = null;
 73.3196 -            return a;
 73.3197 -        }
 73.3198 -
 73.3199 -        public E get(int index) {
 73.3200 -            throw new IndexOutOfBoundsException("Index: "+index);
 73.3201 -        }
 73.3202 -
 73.3203 -        public boolean equals(Object o) {
 73.3204 -            return (o instanceof List) && ((List<?>)o).isEmpty();
 73.3205 -        }
 73.3206 -
 73.3207 -        public int hashCode() { return 1; }
 73.3208 -
 73.3209 -        // Preserves singleton property
 73.3210 -        private Object readResolve() {
 73.3211 -            return EMPTY_LIST;
 73.3212 -        }
 73.3213 -    }
 73.3214 -
 73.3215 -    /**
 73.3216 -     * The empty map (immutable).  This map is serializable.
 73.3217 -     *
 73.3218 -     * @see #emptyMap()
 73.3219 -     * @since 1.3
 73.3220 -     */
 73.3221 -    @SuppressWarnings("unchecked")
 73.3222 -    public static final Map EMPTY_MAP = new EmptyMap<>();
 73.3223 -
 73.3224 -    /**
 73.3225 -     * Returns the empty map (immutable).  This map is serializable.
 73.3226 -     *
 73.3227 -     * <p>This example illustrates the type-safe way to obtain an empty set:
 73.3228 -     * <pre>
 73.3229 -     *     Map&lt;String, Date&gt; s = Collections.emptyMap();
 73.3230 -     * </pre>
 73.3231 -     * Implementation note:  Implementations of this method need not
 73.3232 -     * create a separate <tt>Map</tt> object for each call.   Using this
 73.3233 -     * method is likely to have comparable cost to using the like-named
 73.3234 -     * field.  (Unlike this method, the field does not provide type safety.)
 73.3235 -     *
 73.3236 -     * @see #EMPTY_MAP
 73.3237 -     * @since 1.5
 73.3238 -     */
 73.3239 -    @SuppressWarnings("unchecked")
 73.3240 -    public static final <K,V> Map<K,V> emptyMap() {
 73.3241 -        return (Map<K,V>) EMPTY_MAP;
 73.3242 -    }
 73.3243 -
 73.3244 -    /**
 73.3245 -     * @serial include
 73.3246 -     */
 73.3247 -    private static class EmptyMap<K,V>
 73.3248 -        extends AbstractMap<K,V>
 73.3249 -        implements Serializable
 73.3250 -    {
 73.3251 -        private static final long serialVersionUID = 6428348081105594320L;
 73.3252 -
 73.3253 -        public int size()                          {return 0;}
 73.3254 -        public boolean isEmpty()                   {return true;}
 73.3255 -        public boolean containsKey(Object key)     {return false;}
 73.3256 -        public boolean containsValue(Object value) {return false;}
 73.3257 -        public V get(Object key)                   {return null;}
 73.3258 -        public Set<K> keySet()                     {return emptySet();}
 73.3259 -        public Collection<V> values()              {return emptySet();}
 73.3260 -        public Set<Map.Entry<K,V>> entrySet()      {return emptySet();}
 73.3261 -
 73.3262 -        public boolean equals(Object o) {
 73.3263 -            return (o instanceof Map) && ((Map<?,?>)o).isEmpty();
 73.3264 -        }
 73.3265 -
 73.3266 -        public int hashCode()                      {return 0;}
 73.3267 -
 73.3268 -        // Preserves singleton property
 73.3269 -        private Object readResolve() {
 73.3270 -            return EMPTY_MAP;
 73.3271 -        }
 73.3272 -    }
 73.3273 -
 73.3274 -    // Singleton collections
 73.3275 -
 73.3276 -    /**
 73.3277 -     * Returns an immutable set containing only the specified object.
 73.3278 -     * The returned set is serializable.
 73.3279 -     *
 73.3280 -     * @param o the sole object to be stored in the returned set.
 73.3281 -     * @return an immutable set containing only the specified object.
 73.3282 -     */
 73.3283 -    public static <T> Set<T> singleton(T o) {
 73.3284 -        return new SingletonSet<>(o);
 73.3285 -    }
 73.3286 -
 73.3287 -    static <E> Iterator<E> singletonIterator(final E e) {
 73.3288 -        return new Iterator<E>() {
 73.3289 -            private boolean hasNext = true;
 73.3290 -            public boolean hasNext() {
 73.3291 -                return hasNext;
 73.3292 -            }
 73.3293 -            public E next() {
 73.3294 -                if (hasNext) {
 73.3295 -                    hasNext = false;
 73.3296 -                    return e;
 73.3297 -                }
 73.3298 -                throw new NoSuchElementException();
 73.3299 -            }
 73.3300 -            public void remove() {
 73.3301 -                throw new UnsupportedOperationException();
 73.3302 -            }
 73.3303 -        };
 73.3304 -    }
 73.3305 -
 73.3306 -    /**
 73.3307 -     * @serial include
 73.3308 -     */
 73.3309 -    private static class SingletonSet<E>
 73.3310 -        extends AbstractSet<E>
 73.3311 -        implements Serializable
 73.3312 -    {
 73.3313 -        private static final long serialVersionUID = 3193687207550431679L;
 73.3314 -
 73.3315 -        private final E element;
 73.3316 -
 73.3317 -        SingletonSet(E e) {element = e;}
 73.3318 -
 73.3319 -        public Iterator<E> iterator() {
 73.3320 -            return singletonIterator(element);
 73.3321 -        }
 73.3322 -
 73.3323 -        public int size() {return 1;}
 73.3324 -
 73.3325 -        public boolean contains(Object o) {return eq(o, element);}
 73.3326 -    }
 73.3327 -
 73.3328 -    /**
 73.3329 -     * Returns an immutable list containing only the specified object.
 73.3330 -     * The returned list is serializable.
 73.3331 -     *
 73.3332 -     * @param o the sole object to be stored in the returned list.
 73.3333 -     * @return an immutable list containing only the specified object.
 73.3334 -     * @since 1.3
 73.3335 -     */
 73.3336 -    public static <T> List<T> singletonList(T o) {
 73.3337 -        return new SingletonList<>(o);
 73.3338 -    }
 73.3339 -
 73.3340 -    /**
 73.3341 -     * @serial include
 73.3342 -     */
 73.3343 -    private static class SingletonList<E>
 73.3344 -        extends AbstractList<E>
 73.3345 -        implements RandomAccess, Serializable {
 73.3346 -
 73.3347 -        private static final long serialVersionUID = 3093736618740652951L;
 73.3348 -
 73.3349 -        private final E element;
 73.3350 -
 73.3351 -        SingletonList(E obj)                {element = obj;}
 73.3352 -
 73.3353 -        public Iterator<E> iterator() {
 73.3354 -            return singletonIterator(element);
 73.3355 -        }
 73.3356 -
 73.3357 -        public int size()                   {return 1;}
 73.3358 -
 73.3359 -        public boolean contains(Object obj) {return eq(obj, element);}
 73.3360 -
 73.3361 -        public E get(int index) {
 73.3362 -            if (index != 0)
 73.3363 -              throw new IndexOutOfBoundsException("Index: "+index+", Size: 1");
 73.3364 -            return element;
 73.3365 -        }
 73.3366 -    }
 73.3367 -
 73.3368 -    /**
 73.3369 -     * Returns an immutable map, mapping only the specified key to the
 73.3370 -     * specified value.  The returned map is serializable.
 73.3371 -     *
 73.3372 -     * @param key the sole key to be stored in the returned map.
 73.3373 -     * @param value the value to which the returned map maps <tt>key</tt>.
 73.3374 -     * @return an immutable map containing only the specified key-value
 73.3375 -     *         mapping.
 73.3376 -     * @since 1.3
 73.3377 -     */
 73.3378 -    public static <K,V> Map<K,V> singletonMap(K key, V value) {
 73.3379 -        return new SingletonMap<>(key, value);
 73.3380 -    }
 73.3381 -
 73.3382 -    /**
 73.3383 -     * @serial include
 73.3384 -     */
 73.3385 -    private static class SingletonMap<K,V>
 73.3386 -          extends AbstractMap<K,V>
 73.3387 -          implements Serializable {
 73.3388 -        private static final long serialVersionUID = -6979724477215052911L;
 73.3389 -
 73.3390 -        private final K k;
 73.3391 -        private final V v;
 73.3392 -
 73.3393 -        SingletonMap(K key, V value) {
 73.3394 -            k = key;
 73.3395 -            v = value;
 73.3396 -        }
 73.3397 -
 73.3398 -        public int size()                          {return 1;}
 73.3399 -
 73.3400 -        public boolean isEmpty()                   {return false;}
 73.3401 -
 73.3402 -        public boolean containsKey(Object key)     {return eq(key, k);}
 73.3403 -
 73.3404 -        public boolean containsValue(Object value) {return eq(value, v);}
 73.3405 -
 73.3406 -        public V get(Object key)                   {return (eq(key, k) ? v : null);}
 73.3407 -
 73.3408 -        private transient Set<K> keySet = null;
 73.3409 -        private transient Set<Map.Entry<K,V>> entrySet = null;
 73.3410 -        private transient Collection<V> values = null;
 73.3411 -
 73.3412 -        public Set<K> keySet() {
 73.3413 -            if (keySet==null)
 73.3414 -                keySet = singleton(k);
 73.3415 -            return keySet;
 73.3416 -        }
 73.3417 -
 73.3418 -        public Set<Map.Entry<K,V>> entrySet() {
 73.3419 -            if (entrySet==null)
 73.3420 -                entrySet = Collections.<Map.Entry<K,V>>singleton(
 73.3421 -                    new SimpleImmutableEntry<>(k, v));
 73.3422 -            return entrySet;
 73.3423 -        }
 73.3424 -
 73.3425 -        public Collection<V> values() {
 73.3426 -            if (values==null)
 73.3427 -                values = singleton(v);
 73.3428 -            return values;
 73.3429 -        }
 73.3430 -
 73.3431 -    }
 73.3432 -
 73.3433 -    // Miscellaneous
 73.3434 -
 73.3435 -    /**
 73.3436 -     * Returns an immutable list consisting of <tt>n</tt> copies of the
 73.3437 -     * specified object.  The newly allocated data object is tiny (it contains
 73.3438 -     * a single reference to the data object).  This method is useful in
 73.3439 -     * combination with the <tt>List.addAll</tt> method to grow lists.
 73.3440 -     * The returned list is serializable.
 73.3441 -     *
 73.3442 -     * @param  n the number of elements in the returned list.
 73.3443 -     * @param  o the element to appear repeatedly in the returned list.
 73.3444 -     * @return an immutable list consisting of <tt>n</tt> copies of the
 73.3445 -     *         specified object.
 73.3446 -     * @throws IllegalArgumentException if {@code n < 0}
 73.3447 -     * @see    List#addAll(Collection)
 73.3448 -     * @see    List#addAll(int, Collection)
 73.3449 -     */
 73.3450 -    public static <T> List<T> nCopies(int n, T o) {
 73.3451 -        if (n < 0)
 73.3452 -            throw new IllegalArgumentException("List length = " + n);
 73.3453 -        return new CopiesList<>(n, o);
 73.3454 -    }
 73.3455 -
 73.3456 -    /**
 73.3457 -     * @serial include
 73.3458 -     */
 73.3459 -    private static class CopiesList<E>
 73.3460 -        extends AbstractList<E>
 73.3461 -        implements RandomAccess, Serializable
 73.3462 -    {
 73.3463 -        private static final long serialVersionUID = 2739099268398711800L;
 73.3464 -
 73.3465 -        final int n;
 73.3466 -        final E element;
 73.3467 -
 73.3468 -        CopiesList(int n, E e) {
 73.3469 -            assert n >= 0;
 73.3470 -            this.n = n;
 73.3471 -            element = e;
 73.3472 -        }
 73.3473 -
 73.3474 -        public int size() {
 73.3475 -            return n;
 73.3476 -        }
 73.3477 -
 73.3478 -        public boolean contains(Object obj) {
 73.3479 -            return n != 0 && eq(obj, element);
 73.3480 -        }
 73.3481 -
 73.3482 -        public int indexOf(Object o) {
 73.3483 -            return contains(o) ? 0 : -1;
 73.3484 -        }
 73.3485 -
 73.3486 -        public int lastIndexOf(Object o) {
 73.3487 -            return contains(o) ? n - 1 : -1;
 73.3488 -        }
 73.3489 -
 73.3490 -        public E get(int index) {
 73.3491 -            if (index < 0 || index >= n)
 73.3492 -                throw new IndexOutOfBoundsException("Index: "+index+
 73.3493 -                                                    ", Size: "+n);
 73.3494 -            return element;
 73.3495 -        }
 73.3496 -
 73.3497 -        public Object[] toArray() {
 73.3498 -            final Object[] a = new Object[n];
 73.3499 -            if (element != null)
 73.3500 -                Arrays.fill(a, 0, n, element);
 73.3501 -            return a;
 73.3502 -        }
 73.3503 -
 73.3504 -        public <T> T[] toArray(T[] a) {
 73.3505 -            final int n = this.n;
 73.3506 -            if (a.length < n) {
 73.3507 -                a = (T[])java.lang.reflect.Array
 73.3508 -                    .newInstance(a.getClass().getComponentType(), n);
 73.3509 -                if (element != null)
 73.3510 -                    Arrays.fill(a, 0, n, element);
 73.3511 -            } else {
 73.3512 -                Arrays.fill(a, 0, n, element);
 73.3513 -                if (a.length > n)
 73.3514 -                    a[n] = null;
 73.3515 -            }
 73.3516 -            return a;
 73.3517 -        }
 73.3518 -
 73.3519 -        public List<E> subList(int fromIndex, int toIndex) {
 73.3520 -            if (fromIndex < 0)
 73.3521 -                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
 73.3522 -            if (toIndex > n)
 73.3523 -                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
 73.3524 -            if (fromIndex > toIndex)
 73.3525 -                throw new IllegalArgumentException("fromIndex(" + fromIndex +
 73.3526 -                                                   ") > toIndex(" + toIndex + ")");
 73.3527 -            return new CopiesList<>(toIndex - fromIndex, element);
 73.3528 -        }
 73.3529 -    }
 73.3530 -
 73.3531 -    /**
 73.3532 -     * Returns a comparator that imposes the reverse of the <em>natural
 73.3533 -     * ordering</em> on a collection of objects that implement the
 73.3534 -     * {@code Comparable} interface.  (The natural ordering is the ordering
 73.3535 -     * imposed by the objects' own {@code compareTo} method.)  This enables a
 73.3536 -     * simple idiom for sorting (or maintaining) collections (or arrays) of
 73.3537 -     * objects that implement the {@code Comparable} interface in
 73.3538 -     * reverse-natural-order.  For example, suppose {@code a} is an array of
 73.3539 -     * strings. Then: <pre>
 73.3540 -     *          Arrays.sort(a, Collections.reverseOrder());
 73.3541 -     * </pre> sorts the array in reverse-lexicographic (alphabetical) order.<p>
 73.3542 -     *
 73.3543 -     * The returned comparator is serializable.
 73.3544 -     *
 73.3545 -     * @return A comparator that imposes the reverse of the <i>natural
 73.3546 -     *         ordering</i> on a collection of objects that implement
 73.3547 -     *         the <tt>Comparable</tt> interface.
 73.3548 -     * @see Comparable
 73.3549 -     */
 73.3550 -    public static <T> Comparator<T> reverseOrder() {
 73.3551 -        return (Comparator<T>) ReverseComparator.REVERSE_ORDER;
 73.3552 -    }
 73.3553 -
 73.3554 -    /**
 73.3555 -     * @serial include
 73.3556 -     */
 73.3557 -    private static class ReverseComparator
 73.3558 -        implements Comparator<Comparable<Object>>, Serializable {
 73.3559 -
 73.3560 -        private static final long serialVersionUID = 7207038068494060240L;
 73.3561 -
 73.3562 -        static final ReverseComparator REVERSE_ORDER
 73.3563 -            = new ReverseComparator();
 73.3564 -
 73.3565 -        public int compare(Comparable<Object> c1, Comparable<Object> c2) {
 73.3566 -            return c2.compareTo(c1);
 73.3567 -        }
 73.3568 -
 73.3569 -        private Object readResolve() { return reverseOrder(); }
 73.3570 -    }
 73.3571 -
 73.3572 -    /**
 73.3573 -     * Returns a comparator that imposes the reverse ordering of the specified
 73.3574 -     * comparator.  If the specified comparator is {@code null}, this method is
 73.3575 -     * equivalent to {@link #reverseOrder()} (in other words, it returns a
 73.3576 -     * comparator that imposes the reverse of the <em>natural ordering</em> on
 73.3577 -     * a collection of objects that implement the Comparable interface).
 73.3578 -     *
 73.3579 -     * <p>The returned comparator is serializable (assuming the specified
 73.3580 -     * comparator is also serializable or {@code null}).
 73.3581 -     *
 73.3582 -     * @param cmp a comparator who's ordering is to be reversed by the returned
 73.3583 -     * comparator or {@code null}
 73.3584 -     * @return A comparator that imposes the reverse ordering of the
 73.3585 -     *         specified comparator.
 73.3586 -     * @since 1.5
 73.3587 -     */
 73.3588 -    public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
 73.3589 -        if (cmp == null)
 73.3590 -            return reverseOrder();
 73.3591 -
 73.3592 -        if (cmp instanceof ReverseComparator2)
 73.3593 -            return ((ReverseComparator2<T>)cmp).cmp;
 73.3594 -
 73.3595 -        return new ReverseComparator2<>(cmp);
 73.3596 -    }
 73.3597 -
 73.3598 -    /**
 73.3599 -     * @serial include
 73.3600 -     */
 73.3601 -    private static class ReverseComparator2<T> implements Comparator<T>,
 73.3602 -        Serializable
 73.3603 -    {
 73.3604 -        private static final long serialVersionUID = 4374092139857L;
 73.3605 -
 73.3606 -        /**
 73.3607 -         * The comparator specified in the static factory.  This will never
 73.3608 -         * be null, as the static factory returns a ReverseComparator
 73.3609 -         * instance if its argument is null.
 73.3610 -         *
 73.3611 -         * @serial
 73.3612 -         */
 73.3613 -        final Comparator<T> cmp;
 73.3614 -
 73.3615 -        ReverseComparator2(Comparator<T> cmp) {
 73.3616 -            assert cmp != null;
 73.3617 -            this.cmp = cmp;
 73.3618 -        }
 73.3619 -
 73.3620 -        public int compare(T t1, T t2) {
 73.3621 -            return cmp.compare(t2, t1);
 73.3622 -        }
 73.3623 -
 73.3624 -        public boolean equals(Object o) {
 73.3625 -            return (o == this) ||
 73.3626 -                (o instanceof ReverseComparator2 &&
 73.3627 -                 cmp.equals(((ReverseComparator2)o).cmp));
 73.3628 -        }
 73.3629 -
 73.3630 -        public int hashCode() {
 73.3631 -            return cmp.hashCode() ^ Integer.MIN_VALUE;
 73.3632 -        }
 73.3633 -    }
 73.3634 -
 73.3635 -    /**
 73.3636 -     * Returns an enumeration over the specified collection.  This provides
 73.3637 -     * interoperability with legacy APIs that require an enumeration
 73.3638 -     * as input.
 73.3639 -     *
 73.3640 -     * @param c the collection for which an enumeration is to be returned.
 73.3641 -     * @return an enumeration over the specified collection.
 73.3642 -     * @see Enumeration
 73.3643 -     */
 73.3644 -    public static <T> Enumeration<T> enumeration(final Collection<T> c) {
 73.3645 -        return new Enumeration<T>() {
 73.3646 -            private final Iterator<T> i = c.iterator();
 73.3647 -
 73.3648 -            public boolean hasMoreElements() {
 73.3649 -                return i.hasNext();
 73.3650 -            }
 73.3651 -
 73.3652 -            public T nextElement() {
 73.3653 -                return i.next();
 73.3654 -            }
 73.3655 -        };
 73.3656 -    }
 73.3657 -
 73.3658 -    /**
 73.3659 -     * Returns an array list containing the elements returned by the
 73.3660 -     * specified enumeration in the order they are returned by the
 73.3661 -     * enumeration.  This method provides interoperability between
 73.3662 -     * legacy APIs that return enumerations and new APIs that require
 73.3663 -     * collections.
 73.3664 -     *
 73.3665 -     * @param e enumeration providing elements for the returned
 73.3666 -     *          array list
 73.3667 -     * @return an array list containing the elements returned
 73.3668 -     *         by the specified enumeration.
 73.3669 -     * @since 1.4
 73.3670 -     * @see Enumeration
 73.3671 -     * @see ArrayList
 73.3672 -     */
 73.3673 -    public static <T> ArrayList<T> list(Enumeration<T> e) {
 73.3674 -        ArrayList<T> l = new ArrayList<>();
 73.3675 -        while (e.hasMoreElements())
 73.3676 -            l.add(e.nextElement());
 73.3677 -        return l;
 73.3678 -    }
 73.3679 -
 73.3680 -    /**
 73.3681 -     * Returns true if the specified arguments are equal, or both null.
 73.3682 -     */
 73.3683 -    static boolean eq(Object o1, Object o2) {
 73.3684 -        return o1==null ? o2==null : o1.equals(o2);
 73.3685 -    }
 73.3686 -
 73.3687 -    /**
 73.3688 -     * Returns the number of elements in the specified collection equal to the
 73.3689 -     * specified object.  More formally, returns the number of elements
 73.3690 -     * <tt>e</tt> in the collection such that
 73.3691 -     * <tt>(o == null ? e == null : o.equals(e))</tt>.
 73.3692 -     *
 73.3693 -     * @param c the collection in which to determine the frequency
 73.3694 -     *     of <tt>o</tt>
 73.3695 -     * @param o the object whose frequency is to be determined
 73.3696 -     * @throws NullPointerException if <tt>c</tt> is null
 73.3697 -     * @since 1.5
 73.3698 -     */
 73.3699 -    public static int frequency(Collection<?> c, Object o) {
 73.3700 -        int result = 0;
 73.3701 -        if (o == null) {
 73.3702 -            for (Object e : c)
 73.3703 -                if (e == null)
 73.3704 -                    result++;
 73.3705 -        } else {
 73.3706 -            for (Object e : c)
 73.3707 -                if (o.equals(e))
 73.3708 -                    result++;
 73.3709 -        }
 73.3710 -        return result;
 73.3711 -    }
 73.3712 -
 73.3713 -    /**
 73.3714 -     * Returns {@code true} if the two specified collections have no
 73.3715 -     * elements in common.
 73.3716 -     *
 73.3717 -     * <p>Care must be exercised if this method is used on collections that
 73.3718 -     * do not comply with the general contract for {@code Collection}.
 73.3719 -     * Implementations may elect to iterate over either collection and test
 73.3720 -     * for containment in the other collection (or to perform any equivalent
 73.3721 -     * computation).  If either collection uses a nonstandard equality test
 73.3722 -     * (as does a {@link SortedSet} whose ordering is not <em>compatible with
 73.3723 -     * equals</em>, or the key set of an {@link IdentityHashMap}), both
 73.3724 -     * collections must use the same nonstandard equality test, or the
 73.3725 -     * result of this method is undefined.
 73.3726 -     *
 73.3727 -     * <p>Care must also be exercised when using collections that have
 73.3728 -     * restrictions on the elements that they may contain. Collection
 73.3729 -     * implementations are allowed to throw exceptions for any operation
 73.3730 -     * involving elements they deem ineligible. For absolute safety the
 73.3731 -     * specified collections should contain only elements which are
 73.3732 -     * eligible elements for both collections.
 73.3733 -     *
 73.3734 -     * <p>Note that it is permissible to pass the same collection in both
 73.3735 -     * parameters, in which case the method will return {@code true} if and
 73.3736 -     * only if the collection is empty.
 73.3737 -     *
 73.3738 -     * @param c1 a collection
 73.3739 -     * @param c2 a collection
 73.3740 -     * @return {@code true} if the two specified collections have no
 73.3741 -     * elements in common.
 73.3742 -     * @throws NullPointerException if either collection is {@code null}.
 73.3743 -     * @throws NullPointerException if one collection contains a {@code null}
 73.3744 -     * element and {@code null} is not an eligible element for the other collection.
 73.3745 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
 73.3746 -     * @throws ClassCastException if one collection contains an element that is
 73.3747 -     * of a type which is ineligible for the other collection.
 73.3748 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
 73.3749 -     * @since 1.5
 73.3750 -     */
 73.3751 -    public static boolean disjoint(Collection<?> c1, Collection<?> c2) {
 73.3752 -        // The collection to be used for contains(). Preference is given to
 73.3753 -        // the collection who's contains() has lower O() complexity.
 73.3754 -        Collection<?> contains = c2;
 73.3755 -        // The collection to be iterated. If the collections' contains() impl
 73.3756 -        // are of different O() complexity, the collection with slower
 73.3757 -        // contains() will be used for iteration. For collections who's
 73.3758 -        // contains() are of the same complexity then best performance is
 73.3759 -        // achieved by iterating the smaller collection.
 73.3760 -        Collection<?> iterate = c1;
 73.3761 -
 73.3762 -        // Performance optimization cases. The heuristics:
 73.3763 -        //   1. Generally iterate over c1.
 73.3764 -        //   2. If c1 is a Set then iterate over c2.
 73.3765 -        //   3. If either collection is empty then result is always true.
 73.3766 -        //   4. Iterate over the smaller Collection.
 73.3767 -        if (c1 instanceof Set) {
 73.3768 -            // Use c1 for contains as a Set's contains() is expected to perform
 73.3769 -            // better than O(N/2)
 73.3770 -            iterate = c2;
 73.3771 -            contains = c1;
 73.3772 -        } else if (!(c2 instanceof Set)) {
 73.3773 -            // Both are mere Collections. Iterate over smaller collection.
 73.3774 -            // Example: If c1 contains 3 elements and c2 contains 50 elements and
 73.3775 -            // assuming contains() requires ceiling(N/2) comparisons then
 73.3776 -            // checking for all c1 elements in c2 would require 75 comparisons
 73.3777 -            // (3 * ceiling(50/2)) vs. checking all c2 elements in c1 requiring
 73.3778 -            // 100 comparisons (50 * ceiling(3/2)).
 73.3779 -            int c1size = c1.size();
 73.3780 -            int c2size = c2.size();
 73.3781 -            if (c1size == 0 || c2size == 0) {
 73.3782 -                // At least one collection is empty. Nothing will match.
 73.3783 -                return true;
 73.3784 -            }
 73.3785 -
 73.3786 -            if (c1size > c2size) {
 73.3787 -                iterate = c2;
 73.3788 -                contains = c1;
 73.3789 -            }
 73.3790 -        }
 73.3791 -
 73.3792 -        for (Object e : iterate) {
 73.3793 -            if (contains.contains(e)) {
 73.3794 -               // Found a common element. Collections are not disjoint.
 73.3795 -                return false;
 73.3796 -            }
 73.3797 -        }
 73.3798 -
 73.3799 -        // No common elements were found.
 73.3800 -        return true;
 73.3801 -    }
 73.3802 -
 73.3803 -    /**
 73.3804 -     * Adds all of the specified elements to the specified collection.
 73.3805 -     * Elements to be added may be specified individually or as an array.
 73.3806 -     * The behavior of this convenience method is identical to that of
 73.3807 -     * <tt>c.addAll(Arrays.asList(elements))</tt>, but this method is likely
 73.3808 -     * to run significantly faster under most implementations.
 73.3809 -     *
 73.3810 -     * <p>When elements are specified individually, this method provides a
 73.3811 -     * convenient way to add a few elements to an existing collection:
 73.3812 -     * <pre>
 73.3813 -     *     Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
 73.3814 -     * </pre>
 73.3815 -     *
 73.3816 -     * @param c the collection into which <tt>elements</tt> are to be inserted
 73.3817 -     * @param elements the elements to insert into <tt>c</tt>
 73.3818 -     * @return <tt>true</tt> if the collection changed as a result of the call
 73.3819 -     * @throws UnsupportedOperationException if <tt>c</tt> does not support
 73.3820 -     *         the <tt>add</tt> operation
 73.3821 -     * @throws NullPointerException if <tt>elements</tt> contains one or more
 73.3822 -     *         null values and <tt>c</tt> does not permit null elements, or
 73.3823 -     *         if <tt>c</tt> or <tt>elements</tt> are <tt>null</tt>
 73.3824 -     * @throws IllegalArgumentException if some property of a value in
 73.3825 -     *         <tt>elements</tt> prevents it from being added to <tt>c</tt>
 73.3826 -     * @see Collection#addAll(Collection)
 73.3827 -     * @since 1.5
 73.3828 -     */
 73.3829 -    @SafeVarargs
 73.3830 -    public static <T> boolean addAll(Collection<? super T> c, T... elements) {
 73.3831 -        boolean result = false;
 73.3832 -        for (T element : elements)
 73.3833 -            result |= c.add(element);
 73.3834 -        return result;
 73.3835 -    }
 73.3836 -
 73.3837 -    /**
 73.3838 -     * Returns a set backed by the specified map.  The resulting set displays
 73.3839 -     * the same ordering, concurrency, and performance characteristics as the
 73.3840 -     * backing map.  In essence, this factory method provides a {@link Set}
 73.3841 -     * implementation corresponding to any {@link Map} implementation.  There
 73.3842 -     * is no need to use this method on a {@link Map} implementation that
 73.3843 -     * already has a corresponding {@link Set} implementation (such as {@link
 73.3844 -     * HashMap} or {@link TreeMap}).
 73.3845 -     *
 73.3846 -     * <p>Each method invocation on the set returned by this method results in
 73.3847 -     * exactly one method invocation on the backing map or its <tt>keySet</tt>
 73.3848 -     * view, with one exception.  The <tt>addAll</tt> method is implemented
 73.3849 -     * as a sequence of <tt>put</tt> invocations on the backing map.
 73.3850 -     *
 73.3851 -     * <p>The specified map must be empty at the time this method is invoked,
 73.3852 -     * and should not be accessed directly after this method returns.  These
 73.3853 -     * conditions are ensured if the map is created empty, passed directly
 73.3854 -     * to this method, and no reference to the map is retained, as illustrated
 73.3855 -     * in the following code fragment:
 73.3856 -     * <pre>
 73.3857 -     *    Set&lt;Object&gt; weakHashSet = Collections.newSetFromMap(
 73.3858 -     *        new WeakHashMap&lt;Object, Boolean&gt;());
 73.3859 -     * </pre>
 73.3860 -     *
 73.3861 -     * @param map the backing map
 73.3862 -     * @return the set backed by the map
 73.3863 -     * @throws IllegalArgumentException if <tt>map</tt> is not empty
 73.3864 -     * @since 1.6
 73.3865 -     */
 73.3866 -    public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) {
 73.3867 -        return new SetFromMap<>(map);
 73.3868 -    }
 73.3869 -
 73.3870 -    /**
 73.3871 -     * @serial include
 73.3872 -     */
 73.3873 -    private static class SetFromMap<E> extends AbstractSet<E>
 73.3874 -        implements Set<E>, Serializable
 73.3875 -    {
 73.3876 -        private final Map<E, Boolean> m;  // The backing map
 73.3877 -        private transient Set<E> s;       // Its keySet
 73.3878 -
 73.3879 -        SetFromMap(Map<E, Boolean> map) {
 73.3880 -            if (!map.isEmpty())
 73.3881 -                throw new IllegalArgumentException("Map is non-empty");
 73.3882 -            m = map;
 73.3883 -            s = map.keySet();
 73.3884 -        }
 73.3885 -
 73.3886 -        public void clear()               {        m.clear(); }
 73.3887 -        public int size()                 { return m.size(); }
 73.3888 -        public boolean isEmpty()          { return m.isEmpty(); }
 73.3889 -        public boolean contains(Object o) { return m.containsKey(o); }
 73.3890 -        public boolean remove(Object o)   { return m.remove(o) != null; }
 73.3891 -        public boolean add(E e) { return m.put(e, Boolean.TRUE) == null; }
 73.3892 -        public Iterator<E> iterator()     { return s.iterator(); }
 73.3893 -        public Object[] toArray()         { return s.toArray(); }
 73.3894 -        public <T> T[] toArray(T[] a)     { return s.toArray(a); }
 73.3895 -        public String toString()          { return s.toString(); }
 73.3896 -        public int hashCode()             { return s.hashCode(); }
 73.3897 -        public boolean equals(Object o)   { return o == this || s.equals(o); }
 73.3898 -        public boolean containsAll(Collection<?> c) {return s.containsAll(c);}
 73.3899 -        public boolean removeAll(Collection<?> c)   {return s.removeAll(c);}
 73.3900 -        public boolean retainAll(Collection<?> c)   {return s.retainAll(c);}
 73.3901 -        // addAll is the only inherited implementation
 73.3902 -
 73.3903 -        private static final long serialVersionUID = 2454657854757543876L;
 73.3904 -
 73.3905 -    }
 73.3906 -
 73.3907 -    /**
 73.3908 -     * Returns a view of a {@link Deque} as a Last-in-first-out (Lifo)
 73.3909 -     * {@link Queue}. Method <tt>add</tt> is mapped to <tt>push</tt>,
 73.3910 -     * <tt>remove</tt> is mapped to <tt>pop</tt> and so on. This
 73.3911 -     * view can be useful when you would like to use a method
 73.3912 -     * requiring a <tt>Queue</tt> but you need Lifo ordering.
 73.3913 -     *
 73.3914 -     * <p>Each method invocation on the queue returned by this method
 73.3915 -     * results in exactly one method invocation on the backing deque, with
 73.3916 -     * one exception.  The {@link Queue#addAll addAll} method is
 73.3917 -     * implemented as a sequence of {@link Deque#addFirst addFirst}
 73.3918 -     * invocations on the backing deque.
 73.3919 -     *
 73.3920 -     * @param deque the deque
 73.3921 -     * @return the queue
 73.3922 -     * @since  1.6
 73.3923 -     */
 73.3924 -    public static <T> Queue<T> asLifoQueue(Deque<T> deque) {
 73.3925 -        return new AsLIFOQueue<>(deque);
 73.3926 -    }
 73.3927 -
 73.3928 -    /**
 73.3929 -     * @serial include
 73.3930 -     */
 73.3931 -    static class AsLIFOQueue<E> extends AbstractQueue<E>
 73.3932 -        implements Queue<E>, Serializable {
 73.3933 -        private static final long serialVersionUID = 1802017725587941708L;
 73.3934 -        private final Deque<E> q;
 73.3935 -        AsLIFOQueue(Deque<E> q)           { this.q = q; }
 73.3936 -        public boolean add(E e)           { q.addFirst(e); return true; }
 73.3937 -        public boolean offer(E e)         { return q.offerFirst(e); }
 73.3938 -        public E poll()                   { return q.pollFirst(); }
 73.3939 -        public E remove()                 { return q.removeFirst(); }
 73.3940 -        public E peek()                   { return q.peekFirst(); }
 73.3941 -        public E element()                { return q.getFirst(); }
 73.3942 -        public void clear()               {        q.clear(); }
 73.3943 -        public int size()                 { return q.size(); }
 73.3944 -        public boolean isEmpty()          { return q.isEmpty(); }
 73.3945 -        public boolean contains(Object o) { return q.contains(o); }
 73.3946 -        public boolean remove(Object o)   { return q.remove(o); }
 73.3947 -        public Iterator<E> iterator()     { return q.iterator(); }
 73.3948 -        public Object[] toArray()         { return q.toArray(); }
 73.3949 -        public <T> T[] toArray(T[] a)     { return q.toArray(a); }
 73.3950 -        public String toString()          { return q.toString(); }
 73.3951 -        public boolean containsAll(Collection<?> c) {return q.containsAll(c);}
 73.3952 -        public boolean removeAll(Collection<?> c)   {return q.removeAll(c);}
 73.3953 -        public boolean retainAll(Collection<?> c)   {return q.retainAll(c);}
 73.3954 -        // We use inherited addAll; forwarding addAll would be wrong
 73.3955 -    }
 73.3956 -}
    74.1 --- a/emul/compact/src/main/java/java/util/ComparableTimSort.java	Mon Feb 25 19:00:08 2013 +0100
    74.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.3 @@ -1,896 +0,0 @@
    74.4 -/*
    74.5 - * Copyright 2009 Google Inc.  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 -
   74.32 -/**
   74.33 - * This is a near duplicate of {@link TimSort}, modified for use with
   74.34 - * arrays of objects that implement {@link Comparable}, instead of using
   74.35 - * explicit comparators.
   74.36 - *
   74.37 - * <p>If you are using an optimizing VM, you may find that ComparableTimSort
   74.38 - * offers no performance benefit over TimSort in conjunction with a
   74.39 - * comparator that simply returns {@code ((Comparable)first).compareTo(Second)}.
   74.40 - * If this is the case, you are better off deleting ComparableTimSort to
   74.41 - * eliminate the code duplication.  (See Arrays.java for details.)
   74.42 - *
   74.43 - * @author Josh Bloch
   74.44 - */
   74.45 -class ComparableTimSort {
   74.46 -    /**
   74.47 -     * This is the minimum sized sequence that will be merged.  Shorter
   74.48 -     * sequences will be lengthened by calling binarySort.  If the entire
   74.49 -     * array is less than this length, no merges will be performed.
   74.50 -     *
   74.51 -     * This constant should be a power of two.  It was 64 in Tim Peter's C
   74.52 -     * implementation, but 32 was empirically determined to work better in
   74.53 -     * this implementation.  In the unlikely event that you set this constant
   74.54 -     * to be a number that's not a power of two, you'll need to change the
   74.55 -     * {@link #minRunLength} computation.
   74.56 -     *
   74.57 -     * If you decrease this constant, you must change the stackLen
   74.58 -     * computation in the TimSort constructor, or you risk an
   74.59 -     * ArrayOutOfBounds exception.  See listsort.txt for a discussion
   74.60 -     * of the minimum stack length required as a function of the length
   74.61 -     * of the array being sorted and the minimum merge sequence length.
   74.62 -     */
   74.63 -    private static final int MIN_MERGE = 32;
   74.64 -
   74.65 -    /**
   74.66 -     * The array being sorted.
   74.67 -     */
   74.68 -    private final Object[] a;
   74.69 -
   74.70 -    /**
   74.71 -     * When we get into galloping mode, we stay there until both runs win less
   74.72 -     * often than MIN_GALLOP consecutive times.
   74.73 -     */
   74.74 -    private static final int  MIN_GALLOP = 7;
   74.75 -
   74.76 -    /**
   74.77 -     * This controls when we get *into* galloping mode.  It is initialized
   74.78 -     * to MIN_GALLOP.  The mergeLo and mergeHi methods nudge it higher for
   74.79 -     * random data, and lower for highly structured data.
   74.80 -     */
   74.81 -    private int minGallop = MIN_GALLOP;
   74.82 -
   74.83 -    /**
   74.84 -     * Maximum initial size of tmp array, which is used for merging.  The array
   74.85 -     * can grow to accommodate demand.
   74.86 -     *
   74.87 -     * Unlike Tim's original C version, we do not allocate this much storage
   74.88 -     * when sorting smaller arrays.  This change was required for performance.
   74.89 -     */
   74.90 -    private static final int INITIAL_TMP_STORAGE_LENGTH = 256;
   74.91 -
   74.92 -    /**
   74.93 -     * Temp storage for merges.
   74.94 -     */
   74.95 -    private Object[] tmp;
   74.96 -
   74.97 -    /**
   74.98 -     * A stack of pending runs yet to be merged.  Run i starts at
   74.99 -     * address base[i] and extends for len[i] elements.  It's always
  74.100 -     * true (so long as the indices are in bounds) that:
  74.101 -     *
  74.102 -     *     runBase[i] + runLen[i] == runBase[i + 1]
  74.103 -     *
  74.104 -     * so we could cut the storage for this, but it's a minor amount,
  74.105 -     * and keeping all the info explicit simplifies the code.
  74.106 -     */
  74.107 -    private int stackSize = 0;  // Number of pending runs on stack
  74.108 -    private final int[] runBase;
  74.109 -    private final int[] runLen;
  74.110 -
  74.111 -    /**
  74.112 -     * Creates a TimSort instance to maintain the state of an ongoing sort.
  74.113 -     *
  74.114 -     * @param a the array to be sorted
  74.115 -     */
  74.116 -    private ComparableTimSort(Object[] a) {
  74.117 -        this.a = a;
  74.118 -
  74.119 -        // Allocate temp storage (which may be increased later if necessary)
  74.120 -        int len = a.length;
  74.121 -        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
  74.122 -        Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
  74.123 -                                       len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
  74.124 -        tmp = newArray;
  74.125 -
  74.126 -        /*
  74.127 -         * Allocate runs-to-be-merged stack (which cannot be expanded).  The
  74.128 -         * stack length requirements are described in listsort.txt.  The C
  74.129 -         * version always uses the same stack length (85), but this was
  74.130 -         * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
  74.131 -         * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
  74.132 -         * large) stack lengths for smaller arrays.  The "magic numbers" in the
  74.133 -         * computation below must be changed if MIN_MERGE is decreased.  See
  74.134 -         * the MIN_MERGE declaration above for more information.
  74.135 -         */
  74.136 -        int stackLen = (len <    120  ?  5 :
  74.137 -                        len <   1542  ? 10 :
  74.138 -                        len < 119151  ? 19 : 40);
  74.139 -        runBase = new int[stackLen];
  74.140 -        runLen = new int[stackLen];
  74.141 -    }
  74.142 -
  74.143 -    /*
  74.144 -     * The next two methods (which are package private and static) constitute
  74.145 -     * the entire API of this class.  Each of these methods obeys the contract
  74.146 -     * of the public method with the same signature in java.util.Arrays.
  74.147 -     */
  74.148 -
  74.149 -    static void sort(Object[] a) {
  74.150 -          sort(a, 0, a.length);
  74.151 -    }
  74.152 -
  74.153 -    static void sort(Object[] a, int lo, int hi) {
  74.154 -        rangeCheck(a.length, lo, hi);
  74.155 -        int nRemaining  = hi - lo;
  74.156 -        if (nRemaining < 2)
  74.157 -            return;  // Arrays of size 0 and 1 are always sorted
  74.158 -
  74.159 -        // If array is small, do a "mini-TimSort" with no merges
  74.160 -        if (nRemaining < MIN_MERGE) {
  74.161 -            int initRunLen = countRunAndMakeAscending(a, lo, hi);
  74.162 -            binarySort(a, lo, hi, lo + initRunLen);
  74.163 -            return;
  74.164 -        }
  74.165 -
  74.166 -        /**
  74.167 -         * March over the array once, left to right, finding natural runs,
  74.168 -         * extending short natural runs to minRun elements, and merging runs
  74.169 -         * to maintain stack invariant.
  74.170 -         */
  74.171 -        ComparableTimSort ts = new ComparableTimSort(a);
  74.172 -        int minRun = minRunLength(nRemaining);
  74.173 -        do {
  74.174 -            // Identify next run
  74.175 -            int runLen = countRunAndMakeAscending(a, lo, hi);
  74.176 -
  74.177 -            // If run is short, extend to min(minRun, nRemaining)
  74.178 -            if (runLen < minRun) {
  74.179 -                int force = nRemaining <= minRun ? nRemaining : minRun;
  74.180 -                binarySort(a, lo, lo + force, lo + runLen);
  74.181 -                runLen = force;
  74.182 -            }
  74.183 -
  74.184 -            // Push run onto pending-run stack, and maybe merge
  74.185 -            ts.pushRun(lo, runLen);
  74.186 -            ts.mergeCollapse();
  74.187 -
  74.188 -            // Advance to find next run
  74.189 -            lo += runLen;
  74.190 -            nRemaining -= runLen;
  74.191 -        } while (nRemaining != 0);
  74.192 -
  74.193 -        // Merge all remaining runs to complete sort
  74.194 -        assert lo == hi;
  74.195 -        ts.mergeForceCollapse();
  74.196 -        assert ts.stackSize == 1;
  74.197 -    }
  74.198 -
  74.199 -    /**
  74.200 -     * Sorts the specified portion of the specified array using a binary
  74.201 -     * insertion sort.  This is the best method for sorting small numbers
  74.202 -     * of elements.  It requires O(n log n) compares, but O(n^2) data
  74.203 -     * movement (worst case).
  74.204 -     *
  74.205 -     * If the initial part of the specified range is already sorted,
  74.206 -     * this method can take advantage of it: the method assumes that the
  74.207 -     * elements from index {@code lo}, inclusive, to {@code start},
  74.208 -     * exclusive are already sorted.
  74.209 -     *
  74.210 -     * @param a the array in which a range is to be sorted
  74.211 -     * @param lo the index of the first element in the range to be sorted
  74.212 -     * @param hi the index after the last element in the range to be sorted
  74.213 -     * @param start the index of the first element in the range that is
  74.214 -     *        not already known to be sorted ({@code lo <= start <= hi})
  74.215 -     */
  74.216 -    @SuppressWarnings("fallthrough")
  74.217 -    private static void binarySort(Object[] a, int lo, int hi, int start) {
  74.218 -        assert lo <= start && start <= hi;
  74.219 -        if (start == lo)
  74.220 -            start++;
  74.221 -        for ( ; start < hi; start++) {
  74.222 -            @SuppressWarnings("unchecked")
  74.223 -            Comparable<Object> pivot = (Comparable) a[start];
  74.224 -
  74.225 -            // Set left (and right) to the index where a[start] (pivot) belongs
  74.226 -            int left = lo;
  74.227 -            int right = start;
  74.228 -            assert left <= right;
  74.229 -            /*
  74.230 -             * Invariants:
  74.231 -             *   pivot >= all in [lo, left).
  74.232 -             *   pivot <  all in [right, start).
  74.233 -             */
  74.234 -            while (left < right) {
  74.235 -                int mid = (left + right) >>> 1;
  74.236 -                if (pivot.compareTo(a[mid]) < 0)
  74.237 -                    right = mid;
  74.238 -                else
  74.239 -                    left = mid + 1;
  74.240 -            }
  74.241 -            assert left == right;
  74.242 -
  74.243 -            /*
  74.244 -             * The invariants still hold: pivot >= all in [lo, left) and
  74.245 -             * pivot < all in [left, start), so pivot belongs at left.  Note
  74.246 -             * that if there are elements equal to pivot, left points to the
  74.247 -             * first slot after them -- that's why this sort is stable.
  74.248 -             * Slide elements over to make room for pivot.
  74.249 -             */
  74.250 -            int n = start - left;  // The number of elements to move
  74.251 -            // Switch is just an optimization for arraycopy in default case
  74.252 -            switch (n) {
  74.253 -                case 2:  a[left + 2] = a[left + 1];
  74.254 -                case 1:  a[left + 1] = a[left];
  74.255 -                         break;
  74.256 -                default: System.arraycopy(a, left, a, left + 1, n);
  74.257 -            }
  74.258 -            a[left] = pivot;
  74.259 -        }
  74.260 -    }
  74.261 -
  74.262 -    /**
  74.263 -     * Returns the length of the run beginning at the specified position in
  74.264 -     * the specified array and reverses the run if it is descending (ensuring
  74.265 -     * that the run will always be ascending when the method returns).
  74.266 -     *
  74.267 -     * A run is the longest ascending sequence with:
  74.268 -     *
  74.269 -     *    a[lo] <= a[lo + 1] <= a[lo + 2] <= ...
  74.270 -     *
  74.271 -     * or the longest descending sequence with:
  74.272 -     *
  74.273 -     *    a[lo] >  a[lo + 1] >  a[lo + 2] >  ...
  74.274 -     *
  74.275 -     * For its intended use in a stable mergesort, the strictness of the
  74.276 -     * definition of "descending" is needed so that the call can safely
  74.277 -     * reverse a descending sequence without violating stability.
  74.278 -     *
  74.279 -     * @param a the array in which a run is to be counted and possibly reversed
  74.280 -     * @param lo index of the first element in the run
  74.281 -     * @param hi index after the last element that may be contained in the run.
  74.282 -              It is required that {@code lo < hi}.
  74.283 -     * @return  the length of the run beginning at the specified position in
  74.284 -     *          the specified array
  74.285 -     */
  74.286 -    @SuppressWarnings("unchecked")
  74.287 -    private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
  74.288 -        assert lo < hi;
  74.289 -        int runHi = lo + 1;
  74.290 -        if (runHi == hi)
  74.291 -            return 1;
  74.292 -
  74.293 -        // Find end of run, and reverse range if descending
  74.294 -        if (((Comparable) a[runHi++]).compareTo(a[lo]) < 0) { // Descending
  74.295 -            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0)
  74.296 -                runHi++;
  74.297 -            reverseRange(a, lo, runHi);
  74.298 -        } else {                              // Ascending
  74.299 -            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) >= 0)
  74.300 -                runHi++;
  74.301 -        }
  74.302 -
  74.303 -        return runHi - lo;
  74.304 -    }
  74.305 -
  74.306 -    /**
  74.307 -     * Reverse the specified range of the specified array.
  74.308 -     *
  74.309 -     * @param a the array in which a range is to be reversed
  74.310 -     * @param lo the index of the first element in the range to be reversed
  74.311 -     * @param hi the index after the last element in the range to be reversed
  74.312 -     */
  74.313 -    private static void reverseRange(Object[] a, int lo, int hi) {
  74.314 -        hi--;
  74.315 -        while (lo < hi) {
  74.316 -            Object t = a[lo];
  74.317 -            a[lo++] = a[hi];
  74.318 -            a[hi--] = t;
  74.319 -        }
  74.320 -    }
  74.321 -
  74.322 -    /**
  74.323 -     * Returns the minimum acceptable run length for an array of the specified
  74.324 -     * length. Natural runs shorter than this will be extended with
  74.325 -     * {@link #binarySort}.
  74.326 -     *
  74.327 -     * Roughly speaking, the computation is:
  74.328 -     *
  74.329 -     *  If n < MIN_MERGE, return n (it's too small to bother with fancy stuff).
  74.330 -     *  Else if n is an exact power of 2, return MIN_MERGE/2.
  74.331 -     *  Else return an int k, MIN_MERGE/2 <= k <= MIN_MERGE, such that n/k
  74.332 -     *   is close to, but strictly less than, an exact power of 2.
  74.333 -     *
  74.334 -     * For the rationale, see listsort.txt.
  74.335 -     *
  74.336 -     * @param n the length of the array to be sorted
  74.337 -     * @return the length of the minimum run to be merged
  74.338 -     */
  74.339 -    private static int minRunLength(int n) {
  74.340 -        assert n >= 0;
  74.341 -        int r = 0;      // Becomes 1 if any 1 bits are shifted off
  74.342 -        while (n >= MIN_MERGE) {
  74.343 -            r |= (n & 1);
  74.344 -            n >>= 1;
  74.345 -        }
  74.346 -        return n + r;
  74.347 -    }
  74.348 -
  74.349 -    /**
  74.350 -     * Pushes the specified run onto the pending-run stack.
  74.351 -     *
  74.352 -     * @param runBase index of the first element in the run
  74.353 -     * @param runLen  the number of elements in the run
  74.354 -     */
  74.355 -    private void pushRun(int runBase, int runLen) {
  74.356 -        this.runBase[stackSize] = runBase;
  74.357 -        this.runLen[stackSize] = runLen;
  74.358 -        stackSize++;
  74.359 -    }
  74.360 -
  74.361 -    /**
  74.362 -     * Examines the stack of runs waiting to be merged and merges adjacent runs
  74.363 -     * until the stack invariants are reestablished:
  74.364 -     *
  74.365 -     *     1. runLen[i - 3] > runLen[i - 2] + runLen[i - 1]
  74.366 -     *     2. runLen[i - 2] > runLen[i - 1]
  74.367 -     *
  74.368 -     * This method is called each time a new run is pushed onto the stack,
  74.369 -     * so the invariants are guaranteed to hold for i < stackSize upon
  74.370 -     * entry to the method.
  74.371 -     */
  74.372 -    private void mergeCollapse() {
  74.373 -        while (stackSize > 1) {
  74.374 -            int n = stackSize - 2;
  74.375 -            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
  74.376 -                if (runLen[n - 1] < runLen[n + 1])
  74.377 -                    n--;
  74.378 -                mergeAt(n);
  74.379 -            } else if (runLen[n] <= runLen[n + 1]) {
  74.380 -                mergeAt(n);
  74.381 -            } else {
  74.382 -                break; // Invariant is established
  74.383 -            }
  74.384 -        }
  74.385 -    }
  74.386 -
  74.387 -    /**
  74.388 -     * Merges all runs on the stack until only one remains.  This method is
  74.389 -     * called once, to complete the sort.
  74.390 -     */
  74.391 -    private void mergeForceCollapse() {
  74.392 -        while (stackSize > 1) {
  74.393 -            int n = stackSize - 2;
  74.394 -            if (n > 0 && runLen[n - 1] < runLen[n + 1])
  74.395 -                n--;
  74.396 -            mergeAt(n);
  74.397 -        }
  74.398 -    }
  74.399 -
  74.400 -    /**
  74.401 -     * Merges the two runs at stack indices i and i+1.  Run i must be
  74.402 -     * the penultimate or antepenultimate run on the stack.  In other words,
  74.403 -     * i must be equal to stackSize-2 or stackSize-3.
  74.404 -     *
  74.405 -     * @param i stack index of the first of the two runs to merge
  74.406 -     */
  74.407 -    @SuppressWarnings("unchecked")
  74.408 -    private void mergeAt(int i) {
  74.409 -        assert stackSize >= 2;
  74.410 -        assert i >= 0;
  74.411 -        assert i == stackSize - 2 || i == stackSize - 3;
  74.412 -
  74.413 -        int base1 = runBase[i];
  74.414 -        int len1 = runLen[i];
  74.415 -        int base2 = runBase[i + 1];
  74.416 -        int len2 = runLen[i + 1];
  74.417 -        assert len1 > 0 && len2 > 0;
  74.418 -        assert base1 + len1 == base2;
  74.419 -
  74.420 -        /*
  74.421 -         * Record the length of the combined runs; if i is the 3rd-last
  74.422 -         * run now, also slide over the last run (which isn't involved
  74.423 -         * in this merge).  The current run (i+1) goes away in any case.
  74.424 -         */
  74.425 -        runLen[i] = len1 + len2;
  74.426 -        if (i == stackSize - 3) {
  74.427 -            runBase[i + 1] = runBase[i + 2];
  74.428 -            runLen[i + 1] = runLen[i + 2];
  74.429 -        }
  74.430 -        stackSize--;
  74.431 -
  74.432 -        /*
  74.433 -         * Find where the first element of run2 goes in run1. Prior elements
  74.434 -         * in run1 can be ignored (because they're already in place).
  74.435 -         */
  74.436 -        int k = gallopRight((Comparable<Object>) a[base2], a, base1, len1, 0);
  74.437 -        assert k >= 0;
  74.438 -        base1 += k;
  74.439 -        len1 -= k;
  74.440 -        if (len1 == 0)
  74.441 -            return;
  74.442 -
  74.443 -        /*
  74.444 -         * Find where the last element of run1 goes in run2. Subsequent elements
  74.445 -         * in run2 can be ignored (because they're already in place).
  74.446 -         */
  74.447 -        len2 = gallopLeft((Comparable<Object>) a[base1 + len1 - 1], a,
  74.448 -                base2, len2, len2 - 1);
  74.449 -        assert len2 >= 0;
  74.450 -        if (len2 == 0)
  74.451 -            return;
  74.452 -
  74.453 -        // Merge remaining runs, using tmp array with min(len1, len2) elements
  74.454 -        if (len1 <= len2)
  74.455 -            mergeLo(base1, len1, base2, len2);
  74.456 -        else
  74.457 -            mergeHi(base1, len1, base2, len2);
  74.458 -    }
  74.459 -
  74.460 -    /**
  74.461 -     * Locates the position at which to insert the specified key into the
  74.462 -     * specified sorted range; if the range contains an element equal to key,
  74.463 -     * returns the index of the leftmost equal element.
  74.464 -     *
  74.465 -     * @param key the key whose insertion point to search for
  74.466 -     * @param a the array in which to search
  74.467 -     * @param base the index of the first element in the range
  74.468 -     * @param len the length of the range; must be > 0
  74.469 -     * @param hint the index at which to begin the search, 0 <= hint < n.
  74.470 -     *     The closer hint is to the result, the faster this method will run.
  74.471 -     * @return the int k,  0 <= k <= n such that a[b + k - 1] < key <= a[b + k],
  74.472 -     *    pretending that a[b - 1] is minus infinity and a[b + n] is infinity.
  74.473 -     *    In other words, key belongs at index b + k; or in other words,
  74.474 -     *    the first k elements of a should precede key, and the last n - k
  74.475 -     *    should follow it.
  74.476 -     */
  74.477 -    private static int gallopLeft(Comparable<Object> key, Object[] a,
  74.478 -            int base, int len, int hint) {
  74.479 -        assert len > 0 && hint >= 0 && hint < len;
  74.480 -
  74.481 -        int lastOfs = 0;
  74.482 -        int ofs = 1;
  74.483 -        if (key.compareTo(a[base + hint]) > 0) {
  74.484 -            // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs]
  74.485 -            int maxOfs = len - hint;
  74.486 -            while (ofs < maxOfs && key.compareTo(a[base + hint + ofs]) > 0) {
  74.487 -                lastOfs = ofs;
  74.488 -                ofs = (ofs << 1) + 1;
  74.489 -                if (ofs <= 0)   // int overflow
  74.490 -                    ofs = maxOfs;
  74.491 -            }
  74.492 -            if (ofs > maxOfs)
  74.493 -                ofs = maxOfs;
  74.494 -
  74.495 -            // Make offsets relative to base
  74.496 -            lastOfs += hint;
  74.497 -            ofs += hint;
  74.498 -        } else { // key <= a[base + hint]
  74.499 -            // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs]
  74.500 -            final int maxOfs = hint + 1;
  74.501 -            while (ofs < maxOfs && key.compareTo(a[base + hint - ofs]) <= 0) {
  74.502 -                lastOfs = ofs;
  74.503 -                ofs = (ofs << 1) + 1;
  74.504 -                if (ofs <= 0)   // int overflow
  74.505 -                    ofs = maxOfs;
  74.506 -            }
  74.507 -            if (ofs > maxOfs)
  74.508 -                ofs = maxOfs;
  74.509 -
  74.510 -            // Make offsets relative to base
  74.511 -            int tmp = lastOfs;
  74.512 -            lastOfs = hint - ofs;
  74.513 -            ofs = hint - tmp;
  74.514 -        }
  74.515 -        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
  74.516 -
  74.517 -        /*
  74.518 -         * Now a[base+lastOfs] < key <= a[base+ofs], so key belongs somewhere
  74.519 -         * to the right of lastOfs but no farther right than ofs.  Do a binary
  74.520 -         * search, with invariant a[base + lastOfs - 1] < key <= a[base + ofs].
  74.521 -         */
  74.522 -        lastOfs++;
  74.523 -        while (lastOfs < ofs) {
  74.524 -            int m = lastOfs + ((ofs - lastOfs) >>> 1);
  74.525 -
  74.526 -            if (key.compareTo(a[base + m]) > 0)
  74.527 -                lastOfs = m + 1;  // a[base + m] < key
  74.528 -            else
  74.529 -                ofs = m;          // key <= a[base + m]
  74.530 -        }
  74.531 -        assert lastOfs == ofs;    // so a[base + ofs - 1] < key <= a[base + ofs]
  74.532 -        return ofs;
  74.533 -    }
  74.534 -
  74.535 -    /**
  74.536 -     * Like gallopLeft, except that if the range contains an element equal to
  74.537 -     * key, gallopRight returns the index after the rightmost equal element.
  74.538 -     *
  74.539 -     * @param key the key whose insertion point to search for
  74.540 -     * @param a the array in which to search
  74.541 -     * @param base the index of the first element in the range
  74.542 -     * @param len the length of the range; must be > 0
  74.543 -     * @param hint the index at which to begin the search, 0 <= hint < n.
  74.544 -     *     The closer hint is to the result, the faster this method will run.
  74.545 -     * @return the int k,  0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
  74.546 -     */
  74.547 -    private static int gallopRight(Comparable<Object> key, Object[] a,
  74.548 -            int base, int len, int hint) {
  74.549 -        assert len > 0 && hint >= 0 && hint < len;
  74.550 -
  74.551 -        int ofs = 1;
  74.552 -        int lastOfs = 0;
  74.553 -        if (key.compareTo(a[base + hint]) < 0) {
  74.554 -            // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs]
  74.555 -            int maxOfs = hint + 1;
  74.556 -            while (ofs < maxOfs && key.compareTo(a[base + hint - ofs]) < 0) {
  74.557 -                lastOfs = ofs;
  74.558 -                ofs = (ofs << 1) + 1;
  74.559 -                if (ofs <= 0)   // int overflow
  74.560 -                    ofs = maxOfs;
  74.561 -            }
  74.562 -            if (ofs > maxOfs)
  74.563 -                ofs = maxOfs;
  74.564 -
  74.565 -            // Make offsets relative to b
  74.566 -            int tmp = lastOfs;
  74.567 -            lastOfs = hint - ofs;
  74.568 -            ofs = hint - tmp;
  74.569 -        } else { // a[b + hint] <= key
  74.570 -            // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs]
  74.571 -            int maxOfs = len - hint;
  74.572 -            while (ofs < maxOfs && key.compareTo(a[base + hint + ofs]) >= 0) {
  74.573 -                lastOfs = ofs;
  74.574 -                ofs = (ofs << 1) + 1;
  74.575 -                if (ofs <= 0)   // int overflow
  74.576 -                    ofs = maxOfs;
  74.577 -            }
  74.578 -            if (ofs > maxOfs)
  74.579 -                ofs = maxOfs;
  74.580 -
  74.581 -            // Make offsets relative to b
  74.582 -            lastOfs += hint;
  74.583 -            ofs += hint;
  74.584 -        }
  74.585 -        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
  74.586 -
  74.587 -        /*
  74.588 -         * Now a[b + lastOfs] <= key < a[b + ofs], so key belongs somewhere to
  74.589 -         * the right of lastOfs but no farther right than ofs.  Do a binary
  74.590 -         * search, with invariant a[b + lastOfs - 1] <= key < a[b + ofs].
  74.591 -         */
  74.592 -        lastOfs++;
  74.593 -        while (lastOfs < ofs) {
  74.594 -            int m = lastOfs + ((ofs - lastOfs) >>> 1);
  74.595 -
  74.596 -            if (key.compareTo(a[base + m]) < 0)
  74.597 -                ofs = m;          // key < a[b + m]
  74.598 -            else
  74.599 -                lastOfs = m + 1;  // a[b + m] <= key
  74.600 -        }
  74.601 -        assert lastOfs == ofs;    // so a[b + ofs - 1] <= key < a[b + ofs]
  74.602 -        return ofs;
  74.603 -    }
  74.604 -
  74.605 -    /**
  74.606 -     * Merges two adjacent runs in place, in a stable fashion.  The first
  74.607 -     * element of the first run must be greater than the first element of the
  74.608 -     * second run (a[base1] > a[base2]), and the last element of the first run
  74.609 -     * (a[base1 + len1-1]) must be greater than all elements of the second run.
  74.610 -     *
  74.611 -     * For performance, this method should be called only when len1 <= len2;
  74.612 -     * its twin, mergeHi should be called if len1 >= len2.  (Either method
  74.613 -     * may be called if len1 == len2.)
  74.614 -     *
  74.615 -     * @param base1 index of first element in first run to be merged
  74.616 -     * @param len1  length of first run to be merged (must be > 0)
  74.617 -     * @param base2 index of first element in second run to be merged
  74.618 -     *        (must be aBase + aLen)
  74.619 -     * @param len2  length of second run to be merged (must be > 0)
  74.620 -     */
  74.621 -    @SuppressWarnings("unchecked")
  74.622 -    private void mergeLo(int base1, int len1, int base2, int len2) {
  74.623 -        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
  74.624 -
  74.625 -        // Copy first run into temp array
  74.626 -        Object[] a = this.a; // For performance
  74.627 -        Object[] tmp = ensureCapacity(len1);
  74.628 -        System.arraycopy(a, base1, tmp, 0, len1);
  74.629 -
  74.630 -        int cursor1 = 0;       // Indexes into tmp array
  74.631 -        int cursor2 = base2;   // Indexes int a
  74.632 -        int dest = base1;      // Indexes int a
  74.633 -
  74.634 -        // Move first element of second run and deal with degenerate cases
  74.635 -        a[dest++] = a[cursor2++];
  74.636 -        if (--len2 == 0) {
  74.637 -            System.arraycopy(tmp, cursor1, a, dest, len1);
  74.638 -            return;
  74.639 -        }
  74.640 -        if (len1 == 1) {
  74.641 -            System.arraycopy(a, cursor2, a, dest, len2);
  74.642 -            a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
  74.643 -            return;
  74.644 -        }
  74.645 -
  74.646 -        int minGallop = this.minGallop;  // Use local variable for performance
  74.647 -    outer:
  74.648 -        while (true) {
  74.649 -            int count1 = 0; // Number of times in a row that first run won
  74.650 -            int count2 = 0; // Number of times in a row that second run won
  74.651 -
  74.652 -            /*
  74.653 -             * Do the straightforward thing until (if ever) one run starts
  74.654 -             * winning consistently.
  74.655 -             */
  74.656 -            do {
  74.657 -                assert len1 > 1 && len2 > 0;
  74.658 -                if (((Comparable) a[cursor2]).compareTo(tmp[cursor1]) < 0) {
  74.659 -                    a[dest++] = a[cursor2++];
  74.660 -                    count2++;
  74.661 -                    count1 = 0;
  74.662 -                    if (--len2 == 0)
  74.663 -                        break outer;
  74.664 -                } else {
  74.665 -                    a[dest++] = tmp[cursor1++];
  74.666 -                    count1++;
  74.667 -                    count2 = 0;
  74.668 -                    if (--len1 == 1)
  74.669 -                        break outer;
  74.670 -                }
  74.671 -            } while ((count1 | count2) < minGallop);
  74.672 -
  74.673 -            /*
  74.674 -             * One run is winning so consistently that galloping may be a
  74.675 -             * huge win. So try that, and continue galloping until (if ever)
  74.676 -             * neither run appears to be winning consistently anymore.
  74.677 -             */
  74.678 -            do {
  74.679 -                assert len1 > 1 && len2 > 0;
  74.680 -                count1 = gallopRight((Comparable) a[cursor2], tmp, cursor1, len1, 0);
  74.681 -                if (count1 != 0) {
  74.682 -                    System.arraycopy(tmp, cursor1, a, dest, count1);
  74.683 -                    dest += count1;
  74.684 -                    cursor1 += count1;
  74.685 -                    len1 -= count1;
  74.686 -                    if (len1 <= 1)  // len1 == 1 || len1 == 0
  74.687 -                        break outer;
  74.688 -                }
  74.689 -                a[dest++] = a[cursor2++];
  74.690 -                if (--len2 == 0)
  74.691 -                    break outer;
  74.692 -
  74.693 -                count2 = gallopLeft((Comparable) tmp[cursor1], a, cursor2, len2, 0);
  74.694 -                if (count2 != 0) {
  74.695 -                    System.arraycopy(a, cursor2, a, dest, count2);
  74.696 -                    dest += count2;
  74.697 -                    cursor2 += count2;
  74.698 -                    len2 -= count2;
  74.699 -                    if (len2 == 0)
  74.700 -                        break outer;
  74.701 -                }
  74.702 -                a[dest++] = tmp[cursor1++];
  74.703 -                if (--len1 == 1)
  74.704 -                    break outer;
  74.705 -                minGallop--;
  74.706 -            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
  74.707 -            if (minGallop < 0)
  74.708 -                minGallop = 0;
  74.709 -            minGallop += 2;  // Penalize for leaving gallop mode
  74.710 -        }  // End of "outer" loop
  74.711 -        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
  74.712 -
  74.713 -        if (len1 == 1) {
  74.714 -            assert len2 > 0;
  74.715 -            System.arraycopy(a, cursor2, a, dest, len2);
  74.716 -            a[dest + len2] = tmp[cursor1]; //  Last elt of run 1 to end of merge
  74.717 -        } else if (len1 == 0) {
  74.718 -            throw new IllegalArgumentException(
  74.719 -                "Comparison method violates its general contract!");
  74.720 -        } else {
  74.721 -            assert len2 == 0;
  74.722 -            assert len1 > 1;
  74.723 -            System.arraycopy(tmp, cursor1, a, dest, len1);
  74.724 -        }
  74.725 -    }
  74.726 -
  74.727 -    /**
  74.728 -     * Like mergeLo, except that this method should be called only if
  74.729 -     * len1 >= len2; mergeLo should be called if len1 <= len2.  (Either method
  74.730 -     * may be called if len1 == len2.)
  74.731 -     *
  74.732 -     * @param base1 index of first element in first run to be merged
  74.733 -     * @param len1  length of first run to be merged (must be > 0)
  74.734 -     * @param base2 index of first element in second run to be merged
  74.735 -     *        (must be aBase + aLen)
  74.736 -     * @param len2  length of second run to be merged (must be > 0)
  74.737 -     */
  74.738 -    @SuppressWarnings("unchecked")
  74.739 -    private void mergeHi(int base1, int len1, int base2, int len2) {
  74.740 -        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
  74.741 -
  74.742 -        // Copy second run into temp array
  74.743 -        Object[] a = this.a; // For performance
  74.744 -        Object[] tmp = ensureCapacity(len2);
  74.745 -        System.arraycopy(a, base2, tmp, 0, len2);
  74.746 -
  74.747 -        int cursor1 = base1 + len1 - 1;  // Indexes into a
  74.748 -        int cursor2 = len2 - 1;          // Indexes into tmp array
  74.749 -        int dest = base2 + len2 - 1;     // Indexes into a
  74.750 -
  74.751 -        // Move last element of first run and deal with degenerate cases
  74.752 -        a[dest--] = a[cursor1--];
  74.753 -        if (--len1 == 0) {
  74.754 -            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
  74.755 -            return;
  74.756 -        }
  74.757 -        if (len2 == 1) {
  74.758 -            dest -= len1;
  74.759 -            cursor1 -= len1;
  74.760 -            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
  74.761 -            a[dest] = tmp[cursor2];
  74.762 -            return;
  74.763 -        }
  74.764 -
  74.765 -        int minGallop = this.minGallop;  // Use local variable for performance
  74.766 -    outer:
  74.767 -        while (true) {
  74.768 -            int count1 = 0; // Number of times in a row that first run won
  74.769 -            int count2 = 0; // Number of times in a row that second run won
  74.770 -
  74.771 -            /*
  74.772 -             * Do the straightforward thing until (if ever) one run
  74.773 -             * appears to win consistently.
  74.774 -             */
  74.775 -            do {
  74.776 -                assert len1 > 0 && len2 > 1;
  74.777 -                if (((Comparable) tmp[cursor2]).compareTo(a[cursor1]) < 0) {
  74.778 -                    a[dest--] = a[cursor1--];
  74.779 -                    count1++;
  74.780 -                    count2 = 0;
  74.781 -                    if (--len1 == 0)
  74.782 -                        break outer;
  74.783 -                } else {
  74.784 -                    a[dest--] = tmp[cursor2--];
  74.785 -                    count2++;
  74.786 -                    count1 = 0;
  74.787 -                    if (--len2 == 1)
  74.788 -                        break outer;
  74.789 -                }
  74.790 -            } while ((count1 | count2) < minGallop);
  74.791 -
  74.792 -            /*
  74.793 -             * One run is winning so consistently that galloping may be a
  74.794 -             * huge win. So try that, and continue galloping until (if ever)
  74.795 -             * neither run appears to be winning consistently anymore.
  74.796 -             */
  74.797 -            do {
  74.798 -                assert len1 > 0 && len2 > 1;
  74.799 -                count1 = len1 - gallopRight((Comparable) tmp[cursor2], a, base1, len1, len1 - 1);
  74.800 -                if (count1 != 0) {
  74.801 -                    dest -= count1;
  74.802 -                    cursor1 -= count1;
  74.803 -                    len1 -= count1;
  74.804 -                    System.arraycopy(a, cursor1 + 1, a, dest + 1, count1);
  74.805 -                    if (len1 == 0)
  74.806 -                        break outer;
  74.807 -                }
  74.808 -                a[dest--] = tmp[cursor2--];
  74.809 -                if (--len2 == 1)
  74.810 -                    break outer;
  74.811 -
  74.812 -                count2 = len2 - gallopLeft((Comparable) a[cursor1], tmp, 0, len2, len2 - 1);
  74.813 -                if (count2 != 0) {
  74.814 -                    dest -= count2;
  74.815 -                    cursor2 -= count2;
  74.816 -                    len2 -= count2;
  74.817 -                    System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
  74.818 -                    if (len2 <= 1)
  74.819 -                        break outer; // len2 == 1 || len2 == 0
  74.820 -                }
  74.821 -                a[dest--] = a[cursor1--];
  74.822 -                if (--len1 == 0)
  74.823 -                    break outer;
  74.824 -                minGallop--;
  74.825 -            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
  74.826 -            if (minGallop < 0)
  74.827 -                minGallop = 0;
  74.828 -            minGallop += 2;  // Penalize for leaving gallop mode
  74.829 -        }  // End of "outer" loop
  74.830 -        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
  74.831 -
  74.832 -        if (len2 == 1) {
  74.833 -            assert len1 > 0;
  74.834 -            dest -= len1;
  74.835 -            cursor1 -= len1;
  74.836 -            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
  74.837 -            a[dest] = tmp[cursor2];  // Move first elt of run2 to front of merge
  74.838 -        } else if (len2 == 0) {
  74.839 -            throw new IllegalArgumentException(
  74.840 -                "Comparison method violates its general contract!");
  74.841 -        } else {
  74.842 -            assert len1 == 0;
  74.843 -            assert len2 > 0;
  74.844 -            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
  74.845 -        }
  74.846 -    }
  74.847 -
  74.848 -    /**
  74.849 -     * Ensures that the external array tmp has at least the specified
  74.850 -     * number of elements, increasing its size if necessary.  The size
  74.851 -     * increases exponentially to ensure amortized linear time complexity.
  74.852 -     *
  74.853 -     * @param minCapacity the minimum required capacity of the tmp array
  74.854 -     * @return tmp, whether or not it grew
  74.855 -     */
  74.856 -    private Object[]  ensureCapacity(int minCapacity) {
  74.857 -        if (tmp.length < minCapacity) {
  74.858 -            // Compute smallest power of 2 > minCapacity
  74.859 -            int newSize = minCapacity;
  74.860 -            newSize |= newSize >> 1;
  74.861 -            newSize |= newSize >> 2;
  74.862 -            newSize |= newSize >> 4;
  74.863 -            newSize |= newSize >> 8;
  74.864 -            newSize |= newSize >> 16;
  74.865 -            newSize++;
  74.866 -
  74.867 -            if (newSize < 0) // Not bloody likely!
  74.868 -                newSize = minCapacity;
  74.869 -            else
  74.870 -                newSize = Math.min(newSize, a.length >>> 1);
  74.871 -
  74.872 -            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
  74.873 -            Object[] newArray = new Object[newSize];
  74.874 -            tmp = newArray;
  74.875 -        }
  74.876 -        return tmp;
  74.877 -    }
  74.878 -
  74.879 -    /**
  74.880 -     * Checks that fromIndex and toIndex are in range, and throws an
  74.881 -     * appropriate exception if they aren't.
  74.882 -     *
  74.883 -     * @param arrayLen the length of the array
  74.884 -     * @param fromIndex the index of the first element of the range
  74.885 -     * @param toIndex the index after the last element of the range
  74.886 -     * @throws IllegalArgumentException if fromIndex > toIndex
  74.887 -     * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
  74.888 -     *         or toIndex > arrayLen
  74.889 -     */
  74.890 -    private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
  74.891 -        if (fromIndex > toIndex)
  74.892 -            throw new IllegalArgumentException("fromIndex(" + fromIndex +
  74.893 -                       ") > toIndex(" + toIndex+")");
  74.894 -        if (fromIndex < 0)
  74.895 -            throw new ArrayIndexOutOfBoundsException(fromIndex);
  74.896 -        if (toIndex > arrayLen)
  74.897 -            throw new ArrayIndexOutOfBoundsException(toIndex);
  74.898 -    }
  74.899 -}
    75.1 --- a/emul/compact/src/main/java/java/util/ConcurrentModificationException.java	Mon Feb 25 19:00:08 2013 +0100
    75.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.3 @@ -1,123 +0,0 @@
    75.4 -/*
    75.5 - * Copyright (c) 1997, 2010, 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 - * This exception may be thrown by methods that have detected concurrent
   75.33 - * modification of an object when such modification is not permissible.
   75.34 - * <p>
   75.35 - * For example, it is not generally permissible for one thread to modify a Collection
   75.36 - * while another thread is iterating over it.  In general, the results of the
   75.37 - * iteration are undefined under these circumstances.  Some Iterator
   75.38 - * implementations (including those of all the general purpose collection implementations
   75.39 - * provided by the JRE) may choose to throw this exception if this behavior is
   75.40 - * detected.  Iterators that do this are known as <i>fail-fast</i> iterators,
   75.41 - * as they fail quickly and cleanly, rather that risking arbitrary,
   75.42 - * non-deterministic behavior at an undetermined time in the future.
   75.43 - * <p>
   75.44 - * Note that this exception does not always indicate that an object has
   75.45 - * been concurrently modified by a <i>different</i> thread.  If a single
   75.46 - * thread issues a sequence of method invocations that violates the
   75.47 - * contract of an object, the object may throw this exception.  For
   75.48 - * example, if a thread modifies a collection directly while it is
   75.49 - * iterating over the collection with a fail-fast iterator, the iterator
   75.50 - * will throw this exception.
   75.51 - *
   75.52 - * <p>Note that fail-fast behavior cannot be guaranteed as it is, generally
   75.53 - * speaking, impossible to make any hard guarantees in the presence of
   75.54 - * unsynchronized concurrent modification.  Fail-fast operations
   75.55 - * throw {@code ConcurrentModificationException} on a best-effort basis.
   75.56 - * Therefore, it would be wrong to write a program that depended on this
   75.57 - * exception for its correctness: <i>{@code ConcurrentModificationException}
   75.58 - * should be used only to detect bugs.</i>
   75.59 - *
   75.60 - * @author  Josh Bloch
   75.61 - * @see     Collection
   75.62 - * @see     Iterator
   75.63 - * @see     ListIterator
   75.64 - * @see     Vector
   75.65 - * @see     LinkedList
   75.66 - * @see     HashSet
   75.67 - * @see     Hashtable
   75.68 - * @see     TreeMap
   75.69 - * @see     AbstractList
   75.70 - * @since   1.2
   75.71 - */
   75.72 -public class ConcurrentModificationException extends RuntimeException {
   75.73 -    private static final long serialVersionUID = -3666751008965953603L;
   75.74 -
   75.75 -    /**
   75.76 -     * Constructs a ConcurrentModificationException with no
   75.77 -     * detail message.
   75.78 -     */
   75.79 -    public ConcurrentModificationException() {
   75.80 -    }
   75.81 -
   75.82 -    /**
   75.83 -     * Constructs a {@code ConcurrentModificationException} with the
   75.84 -     * specified detail message.
   75.85 -     *
   75.86 -     * @param message the detail message pertaining to this exception.
   75.87 -     */
   75.88 -    public ConcurrentModificationException(String message) {
   75.89 -        super(message);
   75.90 -    }
   75.91 -
   75.92 -    /**
   75.93 -     * Constructs a new exception with the specified cause and a detail
   75.94 -     * message of {@code (cause==null ? null : cause.toString())} (which
   75.95 -     * typically contains the class and detail message of {@code cause}.
   75.96 -     *
   75.97 -     * @param  cause the cause (which is saved for later retrieval by the
   75.98 -     *         {@link Throwable#getCause()} method).  (A {@code null} value is
   75.99 -     *         permitted, and indicates that the cause is nonexistent or
  75.100 -     *         unknown.)
  75.101 -     * @since  1.7
  75.102 -     */
  75.103 -    public ConcurrentModificationException(Throwable cause) {
  75.104 -        super(cause);
  75.105 -    }
  75.106 -
  75.107 -    /**
  75.108 -     * Constructs a new exception with the specified detail message and
  75.109 -     * cause.
  75.110 -     *
  75.111 -     * <p>Note that the detail message associated with <code>cause</code> is
  75.112 -     * <i>not</i> automatically incorporated in this exception's detail
  75.113 -     * message.
  75.114 -     *
  75.115 -     * @param  message the detail message (which is saved for later retrieval
  75.116 -     *         by the {@link Throwable#getMessage()} method).
  75.117 -     * @param  cause the cause (which is saved for later retrieval by the
  75.118 -     *         {@link Throwable#getCause()} method).  (A {@code null} value
  75.119 -     *         is permitted, and indicates that the cause is nonexistent or
  75.120 -     *         unknown.)
  75.121 -     * @since 1.7
  75.122 -     */
  75.123 -    public ConcurrentModificationException(String message, Throwable cause) {
  75.124 -        super(message, cause);
  75.125 -    }
  75.126 -}
    76.1 --- a/emul/compact/src/main/java/java/util/Deque.java	Mon Feb 25 19:00:08 2013 +0100
    76.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.3 @@ -1,584 +0,0 @@
    76.4 -/*
    76.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    76.6 - *
    76.7 - * This code is free software; you can redistribute it and/or modify it
    76.8 - * under the terms of the GNU General Public License version 2 only, as
    76.9 - * published by the Free Software Foundation.  Oracle designates this
   76.10 - * particular file as subject to the "Classpath" exception as provided
   76.11 - * by Oracle in the LICENSE file that accompanied this code.
   76.12 - *
   76.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
   76.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   76.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   76.16 - * version 2 for more details (a copy is included in the LICENSE file that
   76.17 - * accompanied this code).
   76.18 - *
   76.19 - * You should have received a copy of the GNU General Public License version
   76.20 - * 2 along with this work; if not, write to the Free Software Foundation,
   76.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   76.22 - *
   76.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   76.24 - * or visit www.oracle.com if you need additional information or have any
   76.25 - * questions.
   76.26 - */
   76.27 -
   76.28 -/*
   76.29 - * This file is available under and governed by the GNU General Public
   76.30 - * License version 2 only, as published by the Free Software Foundation.
   76.31 - * However, the following notice accompanied the original version of this
   76.32 - * file:
   76.33 - *
   76.34 - * Written by Doug Lea and Josh Bloch with assistance from members of
   76.35 - * JCP JSR-166 Expert Group and released to the public domain, as explained
   76.36 - * at http://creativecommons.org/publicdomain/zero/1.0/
   76.37 - */
   76.38 -
   76.39 -package java.util;
   76.40 -
   76.41 -/**
   76.42 - * A linear collection that supports element insertion and removal at
   76.43 - * both ends.  The name <i>deque</i> is short for "double ended queue"
   76.44 - * and is usually pronounced "deck".  Most <tt>Deque</tt>
   76.45 - * implementations place no fixed limits on the number of elements
   76.46 - * they may contain, but this interface supports capacity-restricted
   76.47 - * deques as well as those with no fixed size limit.
   76.48 - *
   76.49 - * <p>This interface defines methods to access the elements at both
   76.50 - * ends of the deque.  Methods are provided to insert, remove, and
   76.51 - * examine the element.  Each of these methods exists in two forms:
   76.52 - * one throws an exception if the operation fails, the other returns a
   76.53 - * special value (either <tt>null</tt> or <tt>false</tt>, depending on
   76.54 - * the operation).  The latter form of the insert operation is
   76.55 - * designed specifically for use with capacity-restricted
   76.56 - * <tt>Deque</tt> implementations; in most implementations, insert
   76.57 - * operations cannot fail.
   76.58 - *
   76.59 - * <p>The twelve methods described above are summarized in the
   76.60 - * following table:
   76.61 - *
   76.62 - * <p>
   76.63 - * <table BORDER CELLPADDING=3 CELLSPACING=1>
   76.64 - *  <tr>
   76.65 - *    <td></td>
   76.66 - *    <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
   76.67 - *    <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
   76.68 - *  </tr>
   76.69 - *  <tr>
   76.70 - *    <td></td>
   76.71 - *    <td ALIGN=CENTER><em>Throws exception</em></td>
   76.72 - *    <td ALIGN=CENTER><em>Special value</em></td>
   76.73 - *    <td ALIGN=CENTER><em>Throws exception</em></td>
   76.74 - *    <td ALIGN=CENTER><em>Special value</em></td>
   76.75 - *  </tr>
   76.76 - *  <tr>
   76.77 - *    <td><b>Insert</b></td>
   76.78 - *    <td>{@link #addFirst addFirst(e)}</td>
   76.79 - *    <td>{@link #offerFirst offerFirst(e)}</td>
   76.80 - *    <td>{@link #addLast addLast(e)}</td>
   76.81 - *    <td>{@link #offerLast offerLast(e)}</td>
   76.82 - *  </tr>
   76.83 - *  <tr>
   76.84 - *    <td><b>Remove</b></td>
   76.85 - *    <td>{@link #removeFirst removeFirst()}</td>
   76.86 - *    <td>{@link #pollFirst pollFirst()}</td>
   76.87 - *    <td>{@link #removeLast removeLast()}</td>
   76.88 - *    <td>{@link #pollLast pollLast()}</td>
   76.89 - *  </tr>
   76.90 - *  <tr>
   76.91 - *    <td><b>Examine</b></td>
   76.92 - *    <td>{@link #getFirst getFirst()}</td>
   76.93 - *    <td>{@link #peekFirst peekFirst()}</td>
   76.94 - *    <td>{@link #getLast getLast()}</td>
   76.95 - *    <td>{@link #peekLast peekLast()}</td>
   76.96 - *  </tr>
   76.97 - * </table>
   76.98 - *
   76.99 - * <p>This interface extends the {@link Queue} interface.  When a deque is
  76.100 - * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are
  76.101 - * added at the end of the deque and removed from the beginning.  The methods
  76.102 - * inherited from the <tt>Queue</tt> interface are precisely equivalent to
  76.103 - * <tt>Deque</tt> methods as indicated in the following table:
  76.104 - *
  76.105 - * <p>
  76.106 - * <table BORDER CELLPADDING=3 CELLSPACING=1>
  76.107 - *  <tr>
  76.108 - *    <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
  76.109 - *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
  76.110 - *  </tr>
  76.111 - *  <tr>
  76.112 - *    <td>{@link java.util.Queue#add add(e)}</td>
  76.113 - *    <td>{@link #addLast addLast(e)}</td>
  76.114 - *  </tr>
  76.115 - *  <tr>
  76.116 - *    <td>{@link java.util.Queue#offer offer(e)}</td>
  76.117 - *    <td>{@link #offerLast offerLast(e)}</td>
  76.118 - *  </tr>
  76.119 - *  <tr>
  76.120 - *    <td>{@link java.util.Queue#remove remove()}</td>
  76.121 - *    <td>{@link #removeFirst removeFirst()}</td>
  76.122 - *  </tr>
  76.123 - *  <tr>
  76.124 - *    <td>{@link java.util.Queue#poll poll()}</td>
  76.125 - *    <td>{@link #pollFirst pollFirst()}</td>
  76.126 - *  </tr>
  76.127 - *  <tr>
  76.128 - *    <td>{@link java.util.Queue#element element()}</td>
  76.129 - *    <td>{@link #getFirst getFirst()}</td>
  76.130 - *  </tr>
  76.131 - *  <tr>
  76.132 - *    <td>{@link java.util.Queue#peek peek()}</td>
  76.133 - *    <td>{@link #peek peekFirst()}</td>
  76.134 - *  </tr>
  76.135 - * </table>
  76.136 - *
  76.137 - * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks.  This
  76.138 - * interface should be used in preference to the legacy {@link Stack} class.
  76.139 - * When a deque is used as a stack, elements are pushed and popped from the
  76.140 - * beginning of the deque.  Stack methods are precisely equivalent to
  76.141 - * <tt>Deque</tt> methods as indicated in the table below:
  76.142 - *
  76.143 - * <p>
  76.144 - * <table BORDER CELLPADDING=3 CELLSPACING=1>
  76.145 - *  <tr>
  76.146 - *    <td ALIGN=CENTER> <b>Stack Method</b></td>
  76.147 - *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
  76.148 - *  </tr>
  76.149 - *  <tr>
  76.150 - *    <td>{@link #push push(e)}</td>
  76.151 - *    <td>{@link #addFirst addFirst(e)}</td>
  76.152 - *  </tr>
  76.153 - *  <tr>
  76.154 - *    <td>{@link #pop pop()}</td>
  76.155 - *    <td>{@link #removeFirst removeFirst()}</td>
  76.156 - *  </tr>
  76.157 - *  <tr>
  76.158 - *    <td>{@link #peek peek()}</td>
  76.159 - *    <td>{@link #peekFirst peekFirst()}</td>
  76.160 - *  </tr>
  76.161 - * </table>
  76.162 - *
  76.163 - * <p>Note that the {@link #peek peek} method works equally well when
  76.164 - * a deque is used as a queue or a stack; in either case, elements are
  76.165 - * drawn from the beginning of the deque.
  76.166 - *
  76.167 - * <p>This interface provides two methods to remove interior
  76.168 - * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
  76.169 - * {@link #removeLastOccurrence removeLastOccurrence}.
  76.170 - *
  76.171 - * <p>Unlike the {@link List} interface, this interface does not
  76.172 - * provide support for indexed access to elements.
  76.173 - *
  76.174 - * <p>While <tt>Deque</tt> implementations are not strictly required
  76.175 - * to prohibit the insertion of null elements, they are strongly
  76.176 - * encouraged to do so.  Users of any <tt>Deque</tt> implementations
  76.177 - * that do allow null elements are strongly encouraged <i>not</i> to
  76.178 - * take advantage of the ability to insert nulls.  This is so because
  76.179 - * <tt>null</tt> is used as a special return value by various methods
  76.180 - * to indicated that the deque is empty.
  76.181 - *
  76.182 - * <p><tt>Deque</tt> implementations generally do not define
  76.183 - * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
  76.184 - * methods, but instead inherit the identity-based versions from class
  76.185 - * <tt>Object</tt>.
  76.186 - *
  76.187 - * <p>This interface is a member of the <a
  76.188 - * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
  76.189 - * Framework</a>.
  76.190 - *
  76.191 - * @author Doug Lea
  76.192 - * @author Josh Bloch
  76.193 - * @since  1.6
  76.194 - * @param <E> the type of elements held in this collection
  76.195 - */
  76.196 -
  76.197 -public interface Deque<E> extends Queue<E> {
  76.198 -    /**
  76.199 -     * Inserts the specified element at the front of this deque if it is
  76.200 -     * possible to do so immediately without violating capacity restrictions.
  76.201 -     * When using a capacity-restricted deque, it is generally preferable to
  76.202 -     * use method {@link #offerFirst}.
  76.203 -     *
  76.204 -     * @param e the element to add
  76.205 -     * @throws IllegalStateException if the element cannot be added at this
  76.206 -     *         time due to capacity restrictions
  76.207 -     * @throws ClassCastException if the class of the specified element
  76.208 -     *         prevents it from being added to this deque
  76.209 -     * @throws NullPointerException if the specified element is null and this
  76.210 -     *         deque does not permit null elements
  76.211 -     * @throws IllegalArgumentException if some property of the specified
  76.212 -     *         element prevents it from being added to this deque
  76.213 -     */
  76.214 -    void addFirst(E e);
  76.215 -
  76.216 -    /**
  76.217 -     * Inserts the specified element at the end of this deque if it is
  76.218 -     * possible to do so immediately without violating capacity restrictions.
  76.219 -     * When using a capacity-restricted deque, it is generally preferable to
  76.220 -     * use method {@link #offerLast}.
  76.221 -     *
  76.222 -     * <p>This method is equivalent to {@link #add}.
  76.223 -     *
  76.224 -     * @param e the element to add
  76.225 -     * @throws IllegalStateException if the element cannot be added at this
  76.226 -     *         time due to capacity restrictions
  76.227 -     * @throws ClassCastException if the class of the specified element
  76.228 -     *         prevents it from being added to this deque
  76.229 -     * @throws NullPointerException if the specified element is null and this
  76.230 -     *         deque does not permit null elements
  76.231 -     * @throws IllegalArgumentException if some property of the specified
  76.232 -     *         element prevents it from being added to this deque
  76.233 -     */
  76.234 -    void addLast(E e);
  76.235 -
  76.236 -    /**
  76.237 -     * Inserts the specified element at the front of this deque unless it would
  76.238 -     * violate capacity restrictions.  When using a capacity-restricted deque,
  76.239 -     * this method is generally preferable to the {@link #addFirst} method,
  76.240 -     * which can fail to insert an element only by throwing an exception.
  76.241 -     *
  76.242 -     * @param e the element to add
  76.243 -     * @return <tt>true</tt> if the element was added to this deque, else
  76.244 -     *         <tt>false</tt>
  76.245 -     * @throws ClassCastException if the class of the specified element
  76.246 -     *         prevents it from being added to this deque
  76.247 -     * @throws NullPointerException if the specified element is null and this
  76.248 -     *         deque does not permit null elements
  76.249 -     * @throws IllegalArgumentException if some property of the specified
  76.250 -     *         element prevents it from being added to this deque
  76.251 -     */
  76.252 -    boolean offerFirst(E e);
  76.253 -
  76.254 -    /**
  76.255 -     * Inserts the specified element at the end of this deque unless it would
  76.256 -     * violate capacity restrictions.  When using a capacity-restricted deque,
  76.257 -     * this method is generally preferable to the {@link #addLast} method,
  76.258 -     * which can fail to insert an element only by throwing an exception.
  76.259 -     *
  76.260 -     * @param e the element to add
  76.261 -     * @return <tt>true</tt> if the element was added to this deque, else
  76.262 -     *         <tt>false</tt>
  76.263 -     * @throws ClassCastException if the class of the specified element
  76.264 -     *         prevents it from being added to this deque
  76.265 -     * @throws NullPointerException if the specified element is null and this
  76.266 -     *         deque does not permit null elements
  76.267 -     * @throws IllegalArgumentException if some property of the specified
  76.268 -     *         element prevents it from being added to this deque
  76.269 -     */
  76.270 -    boolean offerLast(E e);
  76.271 -
  76.272 -    /**
  76.273 -     * Retrieves and removes the first element of this deque.  This method
  76.274 -     * differs from {@link #pollFirst pollFirst} only in that it throws an
  76.275 -     * exception if this deque is empty.
  76.276 -     *
  76.277 -     * @return the head of this deque
  76.278 -     * @throws NoSuchElementException if this deque is empty
  76.279 -     */
  76.280 -    E removeFirst();
  76.281 -
  76.282 -    /**
  76.283 -     * Retrieves and removes the last element of this deque.  This method
  76.284 -     * differs from {@link #pollLast pollLast} only in that it throws an
  76.285 -     * exception if this deque is empty.
  76.286 -     *
  76.287 -     * @return the tail of this deque
  76.288 -     * @throws NoSuchElementException if this deque is empty
  76.289 -     */
  76.290 -    E removeLast();
  76.291 -
  76.292 -    /**
  76.293 -     * Retrieves and removes the first element of this deque,
  76.294 -     * or returns <tt>null</tt> if this deque is empty.
  76.295 -     *
  76.296 -     * @return the head of this deque, or <tt>null</tt> if this deque is empty
  76.297 -     */
  76.298 -    E pollFirst();
  76.299 -
  76.300 -    /**
  76.301 -     * Retrieves and removes the last element of this deque,
  76.302 -     * or returns <tt>null</tt> if this deque is empty.
  76.303 -     *
  76.304 -     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
  76.305 -     */
  76.306 -    E pollLast();
  76.307 -
  76.308 -    /**
  76.309 -     * Retrieves, but does not remove, the first element of this deque.
  76.310 -     *
  76.311 -     * This method differs from {@link #peekFirst peekFirst} only in that it
  76.312 -     * throws an exception if this deque is empty.
  76.313 -     *
  76.314 -     * @return the head of this deque
  76.315 -     * @throws NoSuchElementException if this deque is empty
  76.316 -     */
  76.317 -    E getFirst();
  76.318 -
  76.319 -    /**
  76.320 -     * Retrieves, but does not remove, the last element of this deque.
  76.321 -     * This method differs from {@link #peekLast peekLast} only in that it
  76.322 -     * throws an exception if this deque is empty.
  76.323 -     *
  76.324 -     * @return the tail of this deque
  76.325 -     * @throws NoSuchElementException if this deque is empty
  76.326 -     */
  76.327 -    E getLast();
  76.328 -
  76.329 -    /**
  76.330 -     * Retrieves, but does not remove, the first element of this deque,
  76.331 -     * or returns <tt>null</tt> if this deque is empty.
  76.332 -     *
  76.333 -     * @return the head of this deque, or <tt>null</tt> if this deque is empty
  76.334 -     */
  76.335 -    E peekFirst();
  76.336 -
  76.337 -    /**
  76.338 -     * Retrieves, but does not remove, the last element of this deque,
  76.339 -     * or returns <tt>null</tt> if this deque is empty.
  76.340 -     *
  76.341 -     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
  76.342 -     */
  76.343 -    E peekLast();
  76.344 -
  76.345 -    /**
  76.346 -     * Removes the first occurrence of the specified element from this deque.
  76.347 -     * If the deque does not contain the element, it is unchanged.
  76.348 -     * More formally, removes the first element <tt>e</tt> such that
  76.349 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
  76.350 -     * (if such an element exists).
  76.351 -     * Returns <tt>true</tt> if this deque contained the specified element
  76.352 -     * (or equivalently, if this deque changed as a result of the call).
  76.353 -     *
  76.354 -     * @param o element to be removed from this deque, if present
  76.355 -     * @return <tt>true</tt> if an element was removed as a result of this call
  76.356 -     * @throws ClassCastException if the class of the specified element
  76.357 -     *         is incompatible with this deque
  76.358 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.359 -     * @throws NullPointerException if the specified element is null and this
  76.360 -     *         deque does not permit null elements
  76.361 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.362 -     */
  76.363 -    boolean removeFirstOccurrence(Object o);
  76.364 -
  76.365 -    /**
  76.366 -     * Removes the last occurrence of the specified element from this deque.
  76.367 -     * If the deque does not contain the element, it is unchanged.
  76.368 -     * More formally, removes the last element <tt>e</tt> such that
  76.369 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
  76.370 -     * (if such an element exists).
  76.371 -     * Returns <tt>true</tt> if this deque contained the specified element
  76.372 -     * (or equivalently, if this deque changed as a result of the call).
  76.373 -     *
  76.374 -     * @param o element to be removed from this deque, if present
  76.375 -     * @return <tt>true</tt> if an element was removed as a result of this call
  76.376 -     * @throws ClassCastException if the class of the specified element
  76.377 -     *         is incompatible with this deque
  76.378 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.379 -     * @throws NullPointerException if the specified element is null and this
  76.380 -     *         deque does not permit null elements
  76.381 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.382 -     */
  76.383 -    boolean removeLastOccurrence(Object o);
  76.384 -
  76.385 -    // *** Queue methods ***
  76.386 -
  76.387 -    /**
  76.388 -     * Inserts the specified element into the queue represented by this deque
  76.389 -     * (in other words, at the tail of this deque) if it is possible to do so
  76.390 -     * immediately without violating capacity restrictions, returning
  76.391 -     * <tt>true</tt> upon success and throwing an
  76.392 -     * <tt>IllegalStateException</tt> if no space is currently available.
  76.393 -     * When using a capacity-restricted deque, it is generally preferable to
  76.394 -     * use {@link #offer(Object) offer}.
  76.395 -     *
  76.396 -     * <p>This method is equivalent to {@link #addLast}.
  76.397 -     *
  76.398 -     * @param e the element to add
  76.399 -     * @return <tt>true</tt> (as specified by {@link Collection#add})
  76.400 -     * @throws IllegalStateException if the element cannot be added at this
  76.401 -     *         time due to capacity restrictions
  76.402 -     * @throws ClassCastException if the class of the specified element
  76.403 -     *         prevents it from being added to this deque
  76.404 -     * @throws NullPointerException if the specified element is null and this
  76.405 -     *         deque does not permit null elements
  76.406 -     * @throws IllegalArgumentException if some property of the specified
  76.407 -     *         element prevents it from being added to this deque
  76.408 -     */
  76.409 -    boolean add(E e);
  76.410 -
  76.411 -    /**
  76.412 -     * Inserts the specified element into the queue represented by this deque
  76.413 -     * (in other words, at the tail of this deque) if it is possible to do so
  76.414 -     * immediately without violating capacity restrictions, returning
  76.415 -     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
  76.416 -     * available.  When using a capacity-restricted deque, this method is
  76.417 -     * generally preferable to the {@link #add} method, which can fail to
  76.418 -     * insert an element only by throwing an exception.
  76.419 -     *
  76.420 -     * <p>This method is equivalent to {@link #offerLast}.
  76.421 -     *
  76.422 -     * @param e the element to add
  76.423 -     * @return <tt>true</tt> if the element was added to this deque, else
  76.424 -     *         <tt>false</tt>
  76.425 -     * @throws ClassCastException if the class of the specified element
  76.426 -     *         prevents it from being added to this deque
  76.427 -     * @throws NullPointerException if the specified element is null and this
  76.428 -     *         deque does not permit null elements
  76.429 -     * @throws IllegalArgumentException if some property of the specified
  76.430 -     *         element prevents it from being added to this deque
  76.431 -     */
  76.432 -    boolean offer(E e);
  76.433 -
  76.434 -    /**
  76.435 -     * Retrieves and removes the head of the queue represented by this deque
  76.436 -     * (in other words, the first element of this deque).
  76.437 -     * This method differs from {@link #poll poll} only in that it throws an
  76.438 -     * exception if this deque is empty.
  76.439 -     *
  76.440 -     * <p>This method is equivalent to {@link #removeFirst()}.
  76.441 -     *
  76.442 -     * @return the head of the queue represented by this deque
  76.443 -     * @throws NoSuchElementException if this deque is empty
  76.444 -     */
  76.445 -    E remove();
  76.446 -
  76.447 -    /**
  76.448 -     * Retrieves and removes the head of the queue represented by this deque
  76.449 -     * (in other words, the first element of this deque), or returns
  76.450 -     * <tt>null</tt> if this deque is empty.
  76.451 -     *
  76.452 -     * <p>This method is equivalent to {@link #pollFirst()}.
  76.453 -     *
  76.454 -     * @return the first element of this deque, or <tt>null</tt> if
  76.455 -     *         this deque is empty
  76.456 -     */
  76.457 -    E poll();
  76.458 -
  76.459 -    /**
  76.460 -     * Retrieves, but does not remove, the head of the queue represented by
  76.461 -     * this deque (in other words, the first element of this deque).
  76.462 -     * This method differs from {@link #peek peek} only in that it throws an
  76.463 -     * exception if this deque is empty.
  76.464 -     *
  76.465 -     * <p>This method is equivalent to {@link #getFirst()}.
  76.466 -     *
  76.467 -     * @return the head of the queue represented by this deque
  76.468 -     * @throws NoSuchElementException if this deque is empty
  76.469 -     */
  76.470 -    E element();
  76.471 -
  76.472 -    /**
  76.473 -     * Retrieves, but does not remove, the head of the queue represented by
  76.474 -     * this deque (in other words, the first element of this deque), or
  76.475 -     * returns <tt>null</tt> if this deque is empty.
  76.476 -     *
  76.477 -     * <p>This method is equivalent to {@link #peekFirst()}.
  76.478 -     *
  76.479 -     * @return the head of the queue represented by this deque, or
  76.480 -     *         <tt>null</tt> if this deque is empty
  76.481 -     */
  76.482 -    E peek();
  76.483 -
  76.484 -
  76.485 -    // *** Stack methods ***
  76.486 -
  76.487 -    /**
  76.488 -     * Pushes an element onto the stack represented by this deque (in other
  76.489 -     * words, at the head of this deque) if it is possible to do so
  76.490 -     * immediately without violating capacity restrictions, returning
  76.491 -     * <tt>true</tt> upon success and throwing an
  76.492 -     * <tt>IllegalStateException</tt> if no space is currently available.
  76.493 -     *
  76.494 -     * <p>This method is equivalent to {@link #addFirst}.
  76.495 -     *
  76.496 -     * @param e the element to push
  76.497 -     * @throws IllegalStateException if the element cannot be added at this
  76.498 -     *         time due to capacity restrictions
  76.499 -     * @throws ClassCastException if the class of the specified element
  76.500 -     *         prevents it from being added to this deque
  76.501 -     * @throws NullPointerException if the specified element is null and this
  76.502 -     *         deque does not permit null elements
  76.503 -     * @throws IllegalArgumentException if some property of the specified
  76.504 -     *         element prevents it from being added to this deque
  76.505 -     */
  76.506 -    void push(E e);
  76.507 -
  76.508 -    /**
  76.509 -     * Pops an element from the stack represented by this deque.  In other
  76.510 -     * words, removes and returns the first element of this deque.
  76.511 -     *
  76.512 -     * <p>This method is equivalent to {@link #removeFirst()}.
  76.513 -     *
  76.514 -     * @return the element at the front of this deque (which is the top
  76.515 -     *         of the stack represented by this deque)
  76.516 -     * @throws NoSuchElementException if this deque is empty
  76.517 -     */
  76.518 -    E pop();
  76.519 -
  76.520 -
  76.521 -    // *** Collection methods ***
  76.522 -
  76.523 -    /**
  76.524 -     * Removes the first occurrence of the specified element from this deque.
  76.525 -     * If the deque does not contain the element, it is unchanged.
  76.526 -     * More formally, removes the first element <tt>e</tt> such that
  76.527 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
  76.528 -     * (if such an element exists).
  76.529 -     * Returns <tt>true</tt> if this deque contained the specified element
  76.530 -     * (or equivalently, if this deque changed as a result of the call).
  76.531 -     *
  76.532 -     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
  76.533 -     *
  76.534 -     * @param o element to be removed from this deque, if present
  76.535 -     * @return <tt>true</tt> if an element was removed as a result of this call
  76.536 -     * @throws ClassCastException if the class of the specified element
  76.537 -     *         is incompatible with this deque
  76.538 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.539 -     * @throws NullPointerException if the specified element is null and this
  76.540 -     *         deque does not permit null elements
  76.541 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.542 -     */
  76.543 -    boolean remove(Object o);
  76.544 -
  76.545 -    /**
  76.546 -     * Returns <tt>true</tt> if this deque contains the specified element.
  76.547 -     * More formally, returns <tt>true</tt> if and only if this deque contains
  76.548 -     * at least one element <tt>e</tt> such that
  76.549 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  76.550 -     *
  76.551 -     * @param o element whose presence in this deque is to be tested
  76.552 -     * @return <tt>true</tt> if this deque contains the specified element
  76.553 -     * @throws ClassCastException if the type of the specified element
  76.554 -     *         is incompatible with this deque
  76.555 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.556 -     * @throws NullPointerException if the specified element is null and this
  76.557 -     *         deque does not permit null elements
  76.558 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  76.559 -     */
  76.560 -    boolean contains(Object o);
  76.561 -
  76.562 -    /**
  76.563 -     * Returns the number of elements in this deque.
  76.564 -     *
  76.565 -     * @return the number of elements in this deque
  76.566 -     */
  76.567 -    public int size();
  76.568 -
  76.569 -    /**
  76.570 -     * Returns an iterator over the elements in this deque in proper sequence.
  76.571 -     * The elements will be returned in order from first (head) to last (tail).
  76.572 -     *
  76.573 -     * @return an iterator over the elements in this deque in proper sequence
  76.574 -     */
  76.575 -    Iterator<E> iterator();
  76.576 -
  76.577 -    /**
  76.578 -     * Returns an iterator over the elements in this deque in reverse
  76.579 -     * sequential order.  The elements will be returned in order from
  76.580 -     * last (tail) to first (head).
  76.581 -     *
  76.582 -     * @return an iterator over the elements in this deque in reverse
  76.583 -     * sequence
  76.584 -     */
  76.585 -    Iterator<E> descendingIterator();
  76.586 -
  76.587 -}
    77.1 --- a/emul/compact/src/main/java/java/util/Dictionary.java	Mon Feb 25 19:00:08 2013 +0100
    77.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.3 @@ -1,155 +0,0 @@
    77.4 -/*
    77.5 - * Copyright (c) 1995, 2004, 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 -/**
   77.32 - * The <code>Dictionary</code> class is the abstract parent of any
   77.33 - * class, such as <code>Hashtable</code>, which maps keys to values.
   77.34 - * Every key and every value is an object. In any one <tt>Dictionary</tt>
   77.35 - * object, every key is associated with at most one value. Given a
   77.36 - * <tt>Dictionary</tt> and a key, the associated element can be looked up.
   77.37 - * Any non-<code>null</code> object can be used as a key and as a value.
   77.38 - * <p>
   77.39 - * As a rule, the <code>equals</code> method should be used by
   77.40 - * implementations of this class to decide if two keys are the same.
   77.41 - * <p>
   77.42 - * <strong>NOTE: This class is obsolete.  New implementations should
   77.43 - * implement the Map interface, rather than extending this class.</strong>
   77.44 - *
   77.45 - * @author  unascribed
   77.46 - * @see     java.util.Map
   77.47 - * @see     java.lang.Object#equals(java.lang.Object)
   77.48 - * @see     java.lang.Object#hashCode()
   77.49 - * @see     java.util.Hashtable
   77.50 - * @since   JDK1.0
   77.51 - */
   77.52 -public abstract
   77.53 -class Dictionary<K,V> {
   77.54 -    /**
   77.55 -     * Sole constructor.  (For invocation by subclass constructors, typically
   77.56 -     * implicit.)
   77.57 -     */
   77.58 -    public Dictionary() {
   77.59 -    }
   77.60 -
   77.61 -    /**
   77.62 -     * Returns the number of entries (distinct keys) in this dictionary.
   77.63 -     *
   77.64 -     * @return  the number of keys in this dictionary.
   77.65 -     */
   77.66 -    abstract public int size();
   77.67 -
   77.68 -    /**
   77.69 -     * Tests if this dictionary maps no keys to value. The general contract
   77.70 -     * for the <tt>isEmpty</tt> method is that the result is true if and only
   77.71 -     * if this dictionary contains no entries.
   77.72 -     *
   77.73 -     * @return  <code>true</code> if this dictionary maps no keys to values;
   77.74 -     *          <code>false</code> otherwise.
   77.75 -     */
   77.76 -    abstract public boolean isEmpty();
   77.77 -
   77.78 -    /**
   77.79 -     * Returns an enumeration of the keys in this dictionary. The general
   77.80 -     * contract for the keys method is that an <tt>Enumeration</tt> object
   77.81 -     * is returned that will generate all the keys for which this dictionary
   77.82 -     * contains entries.
   77.83 -     *
   77.84 -     * @return  an enumeration of the keys in this dictionary.
   77.85 -     * @see     java.util.Dictionary#elements()
   77.86 -     * @see     java.util.Enumeration
   77.87 -     */
   77.88 -    abstract public Enumeration<K> keys();
   77.89 -
   77.90 -    /**
   77.91 -     * Returns an enumeration of the values in this dictionary. The general
   77.92 -     * contract for the <tt>elements</tt> method is that an
   77.93 -     * <tt>Enumeration</tt> is returned that will generate all the elements
   77.94 -     * contained in entries in this dictionary.
   77.95 -     *
   77.96 -     * @return  an enumeration of the values in this dictionary.
   77.97 -     * @see     java.util.Dictionary#keys()
   77.98 -     * @see     java.util.Enumeration
   77.99 -     */
  77.100 -    abstract public Enumeration<V> elements();
  77.101 -
  77.102 -    /**
  77.103 -     * Returns the value to which the key is mapped in this dictionary.
  77.104 -     * The general contract for the <tt>isEmpty</tt> method is that if this
  77.105 -     * dictionary contains an entry for the specified key, the associated
  77.106 -     * value is returned; otherwise, <tt>null</tt> is returned.
  77.107 -     *
  77.108 -     * @return  the value to which the key is mapped in this dictionary;
  77.109 -     * @param   key   a key in this dictionary.
  77.110 -     *          <code>null</code> if the key is not mapped to any value in
  77.111 -     *          this dictionary.
  77.112 -     * @exception NullPointerException if the <tt>key</tt> is <tt>null</tt>.
  77.113 -     * @see     java.util.Dictionary#put(java.lang.Object, java.lang.Object)
  77.114 -     */
  77.115 -    abstract public V get(Object key);
  77.116 -
  77.117 -    /**
  77.118 -     * Maps the specified <code>key</code> to the specified
  77.119 -     * <code>value</code> in this dictionary. Neither the key nor the
  77.120 -     * value can be <code>null</code>.
  77.121 -     * <p>
  77.122 -     * If this dictionary already contains an entry for the specified
  77.123 -     * <tt>key</tt>, the value already in this dictionary for that
  77.124 -     * <tt>key</tt> is returned, after modifying the entry to contain the
  77.125 -     *  new element. <p>If this dictionary does not already have an entry
  77.126 -     *  for the specified <tt>key</tt>, an entry is created for the
  77.127 -     *  specified <tt>key</tt> and <tt>value</tt>, and <tt>null</tt> is
  77.128 -     *  returned.
  77.129 -     * <p>
  77.130 -     * The <code>value</code> can be retrieved by calling the
  77.131 -     * <code>get</code> method with a <code>key</code> that is equal to
  77.132 -     * the original <code>key</code>.
  77.133 -     *
  77.134 -     * @param      key     the hashtable key.
  77.135 -     * @param      value   the value.
  77.136 -     * @return     the previous value to which the <code>key</code> was mapped
  77.137 -     *             in this dictionary, or <code>null</code> if the key did not
  77.138 -     *             have a previous mapping.
  77.139 -     * @exception  NullPointerException  if the <code>key</code> or
  77.140 -     *               <code>value</code> is <code>null</code>.
  77.141 -     * @see        java.lang.Object#equals(java.lang.Object)
  77.142 -     * @see        java.util.Dictionary#get(java.lang.Object)
  77.143 -     */
  77.144 -    abstract public V put(K key, V value);
  77.145 -
  77.146 -    /**
  77.147 -     * Removes the <code>key</code> (and its corresponding
  77.148 -     * <code>value</code>) from this dictionary. This method does nothing
  77.149 -     * if the <code>key</code> is not in this dictionary.
  77.150 -     *
  77.151 -     * @param   key   the key that needs to be removed.
  77.152 -     * @return  the value to which the <code>key</code> had been mapped in this
  77.153 -     *          dictionary, or <code>null</code> if the key did not have a
  77.154 -     *          mapping.
  77.155 -     * @exception NullPointerException if <tt>key</tt> is <tt>null</tt>.
  77.156 -     */
  77.157 -    abstract public V remove(Object key);
  77.158 -}
    78.1 --- a/emul/compact/src/main/java/java/util/DualPivotQuicksort.java	Mon Feb 25 19:00:08 2013 +0100
    78.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.3 @@ -1,3018 +0,0 @@
    78.4 -/*
    78.5 - * Copyright (c) 2009, 2011, 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 - * This class implements the Dual-Pivot Quicksort algorithm by
   78.33 - * Vladimir Yaroslavskiy, Jon Bentley, and Josh Bloch. The algorithm
   78.34 - * offers O(n log(n)) performance on many data sets that cause other
   78.35 - * quicksorts to degrade to quadratic performance, and is typically
   78.36 - * faster than traditional (one-pivot) Quicksort implementations.
   78.37 - *
   78.38 - * @author Vladimir Yaroslavskiy
   78.39 - * @author Jon Bentley
   78.40 - * @author Josh Bloch
   78.41 - *
   78.42 - * @version 2011.02.11 m765.827.12i:5\7pm
   78.43 - * @since 1.7
   78.44 - */
   78.45 -final class DualPivotQuicksort {
   78.46 -
   78.47 -    /**
   78.48 -     * Prevents instantiation.
   78.49 -     */
   78.50 -    private DualPivotQuicksort() {}
   78.51 -
   78.52 -    /*
   78.53 -     * Tuning parameters.
   78.54 -     */
   78.55 -
   78.56 -    /**
   78.57 -     * The maximum number of runs in merge sort.
   78.58 -     */
   78.59 -    private static final int MAX_RUN_COUNT = 67;
   78.60 -
   78.61 -    /**
   78.62 -     * The maximum length of run in merge sort.
   78.63 -     */
   78.64 -    private static final int MAX_RUN_LENGTH = 33;
   78.65 -
   78.66 -    /**
   78.67 -     * If the length of an array to be sorted is less than this
   78.68 -     * constant, Quicksort is used in preference to merge sort.
   78.69 -     */
   78.70 -    private static final int QUICKSORT_THRESHOLD = 286;
   78.71 -
   78.72 -    /**
   78.73 -     * If the length of an array to be sorted is less than this
   78.74 -     * constant, insertion sort is used in preference to Quicksort.
   78.75 -     */
   78.76 -    private static final int INSERTION_SORT_THRESHOLD = 47;
   78.77 -
   78.78 -    /**
   78.79 -     * If the length of a byte array to be sorted is greater than this
   78.80 -     * constant, counting sort is used in preference to insertion sort.
   78.81 -     */
   78.82 -    private static final int COUNTING_SORT_THRESHOLD_FOR_BYTE = 29;
   78.83 -
   78.84 -    /**
   78.85 -     * If the length of a short or char array to be sorted is greater
   78.86 -     * than this constant, counting sort is used in preference to Quicksort.
   78.87 -     */
   78.88 -    private static final int COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR = 3200;
   78.89 -
   78.90 -    /*
   78.91 -     * Sorting methods for seven primitive types.
   78.92 -     */
   78.93 -
   78.94 -    /**
   78.95 -     * Sorts the specified array.
   78.96 -     *
   78.97 -     * @param a the array to be sorted
   78.98 -     */
   78.99 -    public static void sort(int[] a) {
  78.100 -        sort(a, 0, a.length - 1);
  78.101 -    }
  78.102 -
  78.103 -    /**
  78.104 -     * Sorts the specified range of the array.
  78.105 -     *
  78.106 -     * @param a the array to be sorted
  78.107 -     * @param left the index of the first element, inclusive, to be sorted
  78.108 -     * @param right the index of the last element, inclusive, to be sorted
  78.109 -     */
  78.110 -    public static void sort(int[] a, int left, int right) {
  78.111 -        // Use Quicksort on small arrays
  78.112 -        if (right - left < QUICKSORT_THRESHOLD) {
  78.113 -            sort(a, left, right, true);
  78.114 -            return;
  78.115 -        }
  78.116 -
  78.117 -        /*
  78.118 -         * Index run[i] is the start of i-th run
  78.119 -         * (ascending or descending sequence).
  78.120 -         */
  78.121 -        int[] run = new int[MAX_RUN_COUNT + 1];
  78.122 -        int count = 0; run[0] = left;
  78.123 -
  78.124 -        // Check if the array is nearly sorted
  78.125 -        for (int k = left; k < right; run[count] = k) {
  78.126 -            if (a[k] < a[k + 1]) { // ascending
  78.127 -                while (++k <= right && a[k - 1] <= a[k]);
  78.128 -            } else if (a[k] > a[k + 1]) { // descending
  78.129 -                while (++k <= right && a[k - 1] >= a[k]);
  78.130 -                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
  78.131 -                    int t = a[lo]; a[lo] = a[hi]; a[hi] = t;
  78.132 -                }
  78.133 -            } else { // equal
  78.134 -                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
  78.135 -                    if (--m == 0) {
  78.136 -                        sort(a, left, right, true);
  78.137 -                        return;
  78.138 -                    }
  78.139 -                }
  78.140 -            }
  78.141 -
  78.142 -            /*
  78.143 -             * The array is not highly structured,
  78.144 -             * use Quicksort instead of merge sort.
  78.145 -             */
  78.146 -            if (++count == MAX_RUN_COUNT) {
  78.147 -                sort(a, left, right, true);
  78.148 -                return;
  78.149 -            }
  78.150 -        }
  78.151 -
  78.152 -        // Check special cases
  78.153 -        if (run[count] == right++) { // The last run contains one element
  78.154 -            run[++count] = right;
  78.155 -        } else if (count == 1) { // The array is already sorted
  78.156 -            return;
  78.157 -        }
  78.158 -
  78.159 -        /*
  78.160 -         * Create temporary array, which is used for merging.
  78.161 -         * Implementation note: variable "right" is increased by 1.
  78.162 -         */
  78.163 -        int[] b; byte odd = 0;
  78.164 -        for (int n = 1; (n <<= 1) < count; odd ^= 1);
  78.165 -
  78.166 -        if (odd == 0) {
  78.167 -            b = a; a = new int[b.length];
  78.168 -            for (int i = left - 1; ++i < right; a[i] = b[i]);
  78.169 -        } else {
  78.170 -            b = new int[a.length];
  78.171 -        }
  78.172 -
  78.173 -        // Merging
  78.174 -        for (int last; count > 1; count = last) {
  78.175 -            for (int k = (last = 0) + 2; k <= count; k += 2) {
  78.176 -                int hi = run[k], mi = run[k - 1];
  78.177 -                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
  78.178 -                    if (q >= hi || p < mi && a[p] <= a[q]) {
  78.179 -                        b[i] = a[p++];
  78.180 -                    } else {
  78.181 -                        b[i] = a[q++];
  78.182 -                    }
  78.183 -                }
  78.184 -                run[++last] = hi;
  78.185 -            }
  78.186 -            if ((count & 1) != 0) {
  78.187 -                for (int i = right, lo = run[count - 1]; --i >= lo;
  78.188 -                    b[i] = a[i]
  78.189 -                );
  78.190 -                run[++last] = right;
  78.191 -            }
  78.192 -            int[] t = a; a = b; b = t;
  78.193 -        }
  78.194 -    }
  78.195 -
  78.196 -    /**
  78.197 -     * Sorts the specified range of the array by Dual-Pivot Quicksort.
  78.198 -     *
  78.199 -     * @param a the array to be sorted
  78.200 -     * @param left the index of the first element, inclusive, to be sorted
  78.201 -     * @param right the index of the last element, inclusive, to be sorted
  78.202 -     * @param leftmost indicates if this part is the leftmost in the range
  78.203 -     */
  78.204 -    private static void sort(int[] a, int left, int right, boolean leftmost) {
  78.205 -        int length = right - left + 1;
  78.206 -
  78.207 -        // Use insertion sort on tiny arrays
  78.208 -        if (length < INSERTION_SORT_THRESHOLD) {
  78.209 -            if (leftmost) {
  78.210 -                /*
  78.211 -                 * Traditional (without sentinel) insertion sort,
  78.212 -                 * optimized for server VM, is used in case of
  78.213 -                 * the leftmost part.
  78.214 -                 */
  78.215 -                for (int i = left, j = i; i < right; j = ++i) {
  78.216 -                    int ai = a[i + 1];
  78.217 -                    while (ai < a[j]) {
  78.218 -                        a[j + 1] = a[j];
  78.219 -                        if (j-- == left) {
  78.220 -                            break;
  78.221 -                        }
  78.222 -                    }
  78.223 -                    a[j + 1] = ai;
  78.224 -                }
  78.225 -            } else {
  78.226 -                /*
  78.227 -                 * Skip the longest ascending sequence.
  78.228 -                 */
  78.229 -                do {
  78.230 -                    if (left >= right) {
  78.231 -                        return;
  78.232 -                    }
  78.233 -                } while (a[++left] >= a[left - 1]);
  78.234 -
  78.235 -                /*
  78.236 -                 * Every element from adjoining part plays the role
  78.237 -                 * of sentinel, therefore this allows us to avoid the
  78.238 -                 * left range check on each iteration. Moreover, we use
  78.239 -                 * the more optimized algorithm, so called pair insertion
  78.240 -                 * sort, which is faster (in the context of Quicksort)
  78.241 -                 * than traditional implementation of insertion sort.
  78.242 -                 */
  78.243 -                for (int k = left; ++left <= right; k = ++left) {
  78.244 -                    int a1 = a[k], a2 = a[left];
  78.245 -
  78.246 -                    if (a1 < a2) {
  78.247 -                        a2 = a1; a1 = a[left];
  78.248 -                    }
  78.249 -                    while (a1 < a[--k]) {
  78.250 -                        a[k + 2] = a[k];
  78.251 -                    }
  78.252 -                    a[++k + 1] = a1;
  78.253 -
  78.254 -                    while (a2 < a[--k]) {
  78.255 -                        a[k + 1] = a[k];
  78.256 -                    }
  78.257 -                    a[k + 1] = a2;
  78.258 -                }
  78.259 -                int last = a[right];
  78.260 -
  78.261 -                while (last < a[--right]) {
  78.262 -                    a[right + 1] = a[right];
  78.263 -                }
  78.264 -                a[right + 1] = last;
  78.265 -            }
  78.266 -            return;
  78.267 -        }
  78.268 -
  78.269 -        // Inexpensive approximation of length / 7
  78.270 -        int seventh = (length >> 3) + (length >> 6) + 1;
  78.271 -
  78.272 -        /*
  78.273 -         * Sort five evenly spaced elements around (and including) the
  78.274 -         * center element in the range. These elements will be used for
  78.275 -         * pivot selection as described below. The choice for spacing
  78.276 -         * these elements was empirically determined to work well on
  78.277 -         * a wide variety of inputs.
  78.278 -         */
  78.279 -        int e3 = (left + right) >>> 1; // The midpoint
  78.280 -        int e2 = e3 - seventh;
  78.281 -        int e1 = e2 - seventh;
  78.282 -        int e4 = e3 + seventh;
  78.283 -        int e5 = e4 + seventh;
  78.284 -
  78.285 -        // Sort these elements using insertion sort
  78.286 -        if (a[e2] < a[e1]) { int t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
  78.287 -
  78.288 -        if (a[e3] < a[e2]) { int t = a[e3]; a[e3] = a[e2]; a[e2] = t;
  78.289 -            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  78.290 -        }
  78.291 -        if (a[e4] < a[e3]) { int t = a[e4]; a[e4] = a[e3]; a[e3] = t;
  78.292 -            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  78.293 -                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  78.294 -            }
  78.295 -        }
  78.296 -        if (a[e5] < a[e4]) { int t = a[e5]; a[e5] = a[e4]; a[e4] = t;
  78.297 -            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
  78.298 -                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  78.299 -                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  78.300 -                }
  78.301 -            }
  78.302 -        }
  78.303 -
  78.304 -        // Pointers
  78.305 -        int less  = left;  // The index of the first element of center part
  78.306 -        int great = right; // The index before the first element of right part
  78.307 -
  78.308 -        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
  78.309 -            /*
  78.310 -             * Use the second and fourth of the five sorted elements as pivots.
  78.311 -             * These values are inexpensive approximations of the first and
  78.312 -             * second terciles of the array. Note that pivot1 <= pivot2.
  78.313 -             */
  78.314 -            int pivot1 = a[e2];
  78.315 -            int pivot2 = a[e4];
  78.316 -
  78.317 -            /*
  78.318 -             * The first and the last elements to be sorted are moved to the
  78.319 -             * locations formerly occupied by the pivots. When partitioning
  78.320 -             * is complete, the pivots are swapped back into their final
  78.321 -             * positions, and excluded from subsequent sorting.
  78.322 -             */
  78.323 -            a[e2] = a[left];
  78.324 -            a[e4] = a[right];
  78.325 -
  78.326 -            /*
  78.327 -             * Skip elements, which are less or greater than pivot values.
  78.328 -             */
  78.329 -            while (a[++less] < pivot1);
  78.330 -            while (a[--great] > pivot2);
  78.331 -
  78.332 -            /*
  78.333 -             * Partitioning:
  78.334 -             *
  78.335 -             *   left part           center part                   right part
  78.336 -             * +--------------------------------------------------------------+
  78.337 -             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
  78.338 -             * +--------------------------------------------------------------+
  78.339 -             *               ^                          ^       ^
  78.340 -             *               |                          |       |
  78.341 -             *              less                        k     great
  78.342 -             *
  78.343 -             * Invariants:
  78.344 -             *
  78.345 -             *              all in (left, less)   < pivot1
  78.346 -             *    pivot1 <= all in [less, k)     <= pivot2
  78.347 -             *              all in (great, right) > pivot2
  78.348 -             *
  78.349 -             * Pointer k is the first index of ?-part.
  78.350 -             */
  78.351 -            outer:
  78.352 -            for (int k = less - 1; ++k <= great; ) {
  78.353 -                int ak = a[k];
  78.354 -                if (ak < pivot1) { // Move a[k] to left part
  78.355 -                    a[k] = a[less];
  78.356 -                    /*
  78.357 -                     * Here and below we use "a[i] = b; i++;" instead
  78.358 -                     * of "a[i++] = b;" due to performance issue.
  78.359 -                     */
  78.360 -                    a[less] = ak;
  78.361 -                    ++less;
  78.362 -                } else if (ak > pivot2) { // Move a[k] to right part
  78.363 -                    while (a[great] > pivot2) {
  78.364 -                        if (great-- == k) {
  78.365 -                            break outer;
  78.366 -                        }
  78.367 -                    }
  78.368 -                    if (a[great] < pivot1) { // a[great] <= pivot2
  78.369 -                        a[k] = a[less];
  78.370 -                        a[less] = a[great];
  78.371 -                        ++less;
  78.372 -                    } else { // pivot1 <= a[great] <= pivot2
  78.373 -                        a[k] = a[great];
  78.374 -                    }
  78.375 -                    /*
  78.376 -                     * Here and below we use "a[i] = b; i--;" instead
  78.377 -                     * of "a[i--] = b;" due to performance issue.
  78.378 -                     */
  78.379 -                    a[great] = ak;
  78.380 -                    --great;
  78.381 -                }
  78.382 -            }
  78.383 -
  78.384 -            // Swap pivots into their final positions
  78.385 -            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  78.386 -            a[right] = a[great + 1]; a[great + 1] = pivot2;
  78.387 -
  78.388 -            // Sort left and right parts recursively, excluding known pivots
  78.389 -            sort(a, left, less - 2, leftmost);
  78.390 -            sort(a, great + 2, right, false);
  78.391 -
  78.392 -            /*
  78.393 -             * If center part is too large (comprises > 4/7 of the array),
  78.394 -             * swap internal pivot values to ends.
  78.395 -             */
  78.396 -            if (less < e1 && e5 < great) {
  78.397 -                /*
  78.398 -                 * Skip elements, which are equal to pivot values.
  78.399 -                 */
  78.400 -                while (a[less] == pivot1) {
  78.401 -                    ++less;
  78.402 -                }
  78.403 -
  78.404 -                while (a[great] == pivot2) {
  78.405 -                    --great;
  78.406 -                }
  78.407 -
  78.408 -                /*
  78.409 -                 * Partitioning:
  78.410 -                 *
  78.411 -                 *   left part         center part                  right part
  78.412 -                 * +----------------------------------------------------------+
  78.413 -                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  78.414 -                 * +----------------------------------------------------------+
  78.415 -                 *              ^                        ^       ^
  78.416 -                 *              |                        |       |
  78.417 -                 *             less                      k     great
  78.418 -                 *
  78.419 -                 * Invariants:
  78.420 -                 *
  78.421 -                 *              all in (*,  less) == pivot1
  78.422 -                 *     pivot1 < all in [less,  k)  < pivot2
  78.423 -                 *              all in (great, *) == pivot2
  78.424 -                 *
  78.425 -                 * Pointer k is the first index of ?-part.
  78.426 -                 */
  78.427 -                outer:
  78.428 -                for (int k = less - 1; ++k <= great; ) {
  78.429 -                    int ak = a[k];
  78.430 -                    if (ak == pivot1) { // Move a[k] to left part
  78.431 -                        a[k] = a[less];
  78.432 -                        a[less] = ak;
  78.433 -                        ++less;
  78.434 -                    } else if (ak == pivot2) { // Move a[k] to right part
  78.435 -                        while (a[great] == pivot2) {
  78.436 -                            if (great-- == k) {
  78.437 -                                break outer;
  78.438 -                            }
  78.439 -                        }
  78.440 -                        if (a[great] == pivot1) { // a[great] < pivot2
  78.441 -                            a[k] = a[less];
  78.442 -                            /*
  78.443 -                             * Even though a[great] equals to pivot1, the
  78.444 -                             * assignment a[less] = pivot1 may be incorrect,
  78.445 -                             * if a[great] and pivot1 are floating-point zeros
  78.446 -                             * of different signs. Therefore in float and
  78.447 -                             * double sorting methods we have to use more
  78.448 -                             * accurate assignment a[less] = a[great].
  78.449 -                             */
  78.450 -                            a[less] = pivot1;
  78.451 -                            ++less;
  78.452 -                        } else { // pivot1 < a[great] < pivot2
  78.453 -                            a[k] = a[great];
  78.454 -                        }
  78.455 -                        a[great] = ak;
  78.456 -                        --great;
  78.457 -                    }
  78.458 -                }
  78.459 -            }
  78.460 -
  78.461 -            // Sort center part recursively
  78.462 -            sort(a, less, great, false);
  78.463 -
  78.464 -        } else { // Partitioning with one pivot
  78.465 -            /*
  78.466 -             * Use the third of the five sorted elements as pivot.
  78.467 -             * This value is inexpensive approximation of the median.
  78.468 -             */
  78.469 -            int pivot = a[e3];
  78.470 -
  78.471 -            /*
  78.472 -             * Partitioning degenerates to the traditional 3-way
  78.473 -             * (or "Dutch National Flag") schema:
  78.474 -             *
  78.475 -             *   left part    center part              right part
  78.476 -             * +-------------------------------------------------+
  78.477 -             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
  78.478 -             * +-------------------------------------------------+
  78.479 -             *              ^              ^        ^
  78.480 -             *              |              |        |
  78.481 -             *             less            k      great
  78.482 -             *
  78.483 -             * Invariants:
  78.484 -             *
  78.485 -             *   all in (left, less)   < pivot
  78.486 -             *   all in [less, k)     == pivot
  78.487 -             *   all in (great, right) > pivot
  78.488 -             *
  78.489 -             * Pointer k is the first index of ?-part.
  78.490 -             */
  78.491 -            for (int k = less; k <= great; ++k) {
  78.492 -                if (a[k] == pivot) {
  78.493 -                    continue;
  78.494 -                }
  78.495 -                int ak = a[k];
  78.496 -                if (ak < pivot) { // Move a[k] to left part
  78.497 -                    a[k] = a[less];
  78.498 -                    a[less] = ak;
  78.499 -                    ++less;
  78.500 -                } else { // a[k] > pivot - Move a[k] to right part
  78.501 -                    while (a[great] > pivot) {
  78.502 -                        --great;
  78.503 -                    }
  78.504 -                    if (a[great] < pivot) { // a[great] <= pivot
  78.505 -                        a[k] = a[less];
  78.506 -                        a[less] = a[great];
  78.507 -                        ++less;
  78.508 -                    } else { // a[great] == pivot
  78.509 -                        /*
  78.510 -                         * Even though a[great] equals to pivot, the
  78.511 -                         * assignment a[k] = pivot may be incorrect,
  78.512 -                         * if a[great] and pivot are floating-point
  78.513 -                         * zeros of different signs. Therefore in float
  78.514 -                         * and double sorting methods we have to use
  78.515 -                         * more accurate assignment a[k] = a[great].
  78.516 -                         */
  78.517 -                        a[k] = pivot;
  78.518 -                    }
  78.519 -                    a[great] = ak;
  78.520 -                    --great;
  78.521 -                }
  78.522 -            }
  78.523 -
  78.524 -            /*
  78.525 -             * Sort left and right parts recursively.
  78.526 -             * All elements from center part are equal
  78.527 -             * and, therefore, already sorted.
  78.528 -             */
  78.529 -            sort(a, left, less - 1, leftmost);
  78.530 -            sort(a, great + 1, right, false);
  78.531 -        }
  78.532 -    }
  78.533 -
  78.534 -    /**
  78.535 -     * Sorts the specified array.
  78.536 -     *
  78.537 -     * @param a the array to be sorted
  78.538 -     */
  78.539 -    public static void sort(long[] a) {
  78.540 -        sort(a, 0, a.length - 1);
  78.541 -    }
  78.542 -
  78.543 -    /**
  78.544 -     * Sorts the specified range of the array.
  78.545 -     *
  78.546 -     * @param a the array to be sorted
  78.547 -     * @param left the index of the first element, inclusive, to be sorted
  78.548 -     * @param right the index of the last element, inclusive, to be sorted
  78.549 -     */
  78.550 -    public static void sort(long[] a, int left, int right) {
  78.551 -        // Use Quicksort on small arrays
  78.552 -        if (right - left < QUICKSORT_THRESHOLD) {
  78.553 -            sort(a, left, right, true);
  78.554 -            return;
  78.555 -        }
  78.556 -
  78.557 -        /*
  78.558 -         * Index run[i] is the start of i-th run
  78.559 -         * (ascending or descending sequence).
  78.560 -         */
  78.561 -        int[] run = new int[MAX_RUN_COUNT + 1];
  78.562 -        int count = 0; run[0] = left;
  78.563 -
  78.564 -        // Check if the array is nearly sorted
  78.565 -        for (int k = left; k < right; run[count] = k) {
  78.566 -            if (a[k] < a[k + 1]) { // ascending
  78.567 -                while (++k <= right && a[k - 1] <= a[k]);
  78.568 -            } else if (a[k] > a[k + 1]) { // descending
  78.569 -                while (++k <= right && a[k - 1] >= a[k]);
  78.570 -                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
  78.571 -                    long t = a[lo]; a[lo] = a[hi]; a[hi] = t;
  78.572 -                }
  78.573 -            } else { // equal
  78.574 -                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
  78.575 -                    if (--m == 0) {
  78.576 -                        sort(a, left, right, true);
  78.577 -                        return;
  78.578 -                    }
  78.579 -                }
  78.580 -            }
  78.581 -
  78.582 -            /*
  78.583 -             * The array is not highly structured,
  78.584 -             * use Quicksort instead of merge sort.
  78.585 -             */
  78.586 -            if (++count == MAX_RUN_COUNT) {
  78.587 -                sort(a, left, right, true);
  78.588 -                return;
  78.589 -            }
  78.590 -        }
  78.591 -
  78.592 -        // Check special cases
  78.593 -        if (run[count] == right++) { // The last run contains one element
  78.594 -            run[++count] = right;
  78.595 -        } else if (count == 1) { // The array is already sorted
  78.596 -            return;
  78.597 -        }
  78.598 -
  78.599 -        /*
  78.600 -         * Create temporary array, which is used for merging.
  78.601 -         * Implementation note: variable "right" is increased by 1.
  78.602 -         */
  78.603 -        long[] b; byte odd = 0;
  78.604 -        for (int n = 1; (n <<= 1) < count; odd ^= 1);
  78.605 -
  78.606 -        if (odd == 0) {
  78.607 -            b = a; a = new long[b.length];
  78.608 -            for (int i = left - 1; ++i < right; a[i] = b[i]);
  78.609 -        } else {
  78.610 -            b = new long[a.length];
  78.611 -        }
  78.612 -
  78.613 -        // Merging
  78.614 -        for (int last; count > 1; count = last) {
  78.615 -            for (int k = (last = 0) + 2; k <= count; k += 2) {
  78.616 -                int hi = run[k], mi = run[k - 1];
  78.617 -                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
  78.618 -                    if (q >= hi || p < mi && a[p] <= a[q]) {
  78.619 -                        b[i] = a[p++];
  78.620 -                    } else {
  78.621 -                        b[i] = a[q++];
  78.622 -                    }
  78.623 -                }
  78.624 -                run[++last] = hi;
  78.625 -            }
  78.626 -            if ((count & 1) != 0) {
  78.627 -                for (int i = right, lo = run[count - 1]; --i >= lo;
  78.628 -                    b[i] = a[i]
  78.629 -                );
  78.630 -                run[++last] = right;
  78.631 -            }
  78.632 -            long[] t = a; a = b; b = t;
  78.633 -        }
  78.634 -    }
  78.635 -
  78.636 -    /**
  78.637 -     * Sorts the specified range of the array by Dual-Pivot Quicksort.
  78.638 -     *
  78.639 -     * @param a the array to be sorted
  78.640 -     * @param left the index of the first element, inclusive, to be sorted
  78.641 -     * @param right the index of the last element, inclusive, to be sorted
  78.642 -     * @param leftmost indicates if this part is the leftmost in the range
  78.643 -     */
  78.644 -    private static void sort(long[] a, int left, int right, boolean leftmost) {
  78.645 -        int length = right - left + 1;
  78.646 -
  78.647 -        // Use insertion sort on tiny arrays
  78.648 -        if (length < INSERTION_SORT_THRESHOLD) {
  78.649 -            if (leftmost) {
  78.650 -                /*
  78.651 -                 * Traditional (without sentinel) insertion sort,
  78.652 -                 * optimized for server VM, is used in case of
  78.653 -                 * the leftmost part.
  78.654 -                 */
  78.655 -                for (int i = left, j = i; i < right; j = ++i) {
  78.656 -                    long ai = a[i + 1];
  78.657 -                    while (ai < a[j]) {
  78.658 -                        a[j + 1] = a[j];
  78.659 -                        if (j-- == left) {
  78.660 -                            break;
  78.661 -                        }
  78.662 -                    }
  78.663 -                    a[j + 1] = ai;
  78.664 -                }
  78.665 -            } else {
  78.666 -                /*
  78.667 -                 * Skip the longest ascending sequence.
  78.668 -                 */
  78.669 -                do {
  78.670 -                    if (left >= right) {
  78.671 -                        return;
  78.672 -                    }
  78.673 -                } while (a[++left] >= a[left - 1]);
  78.674 -
  78.675 -                /*
  78.676 -                 * Every element from adjoining part plays the role
  78.677 -                 * of sentinel, therefore this allows us to avoid the
  78.678 -                 * left range check on each iteration. Moreover, we use
  78.679 -                 * the more optimized algorithm, so called pair insertion
  78.680 -                 * sort, which is faster (in the context of Quicksort)
  78.681 -                 * than traditional implementation of insertion sort.
  78.682 -                 */
  78.683 -                for (int k = left; ++left <= right; k = ++left) {
  78.684 -                    long a1 = a[k], a2 = a[left];
  78.685 -
  78.686 -                    if (a1 < a2) {
  78.687 -                        a2 = a1; a1 = a[left];
  78.688 -                    }
  78.689 -                    while (a1 < a[--k]) {
  78.690 -                        a[k + 2] = a[k];
  78.691 -                    }
  78.692 -                    a[++k + 1] = a1;
  78.693 -
  78.694 -                    while (a2 < a[--k]) {
  78.695 -                        a[k + 1] = a[k];
  78.696 -                    }
  78.697 -                    a[k + 1] = a2;
  78.698 -                }
  78.699 -                long last = a[right];
  78.700 -
  78.701 -                while (last < a[--right]) {
  78.702 -                    a[right + 1] = a[right];
  78.703 -                }
  78.704 -                a[right + 1] = last;
  78.705 -            }
  78.706 -            return;
  78.707 -        }
  78.708 -
  78.709 -        // Inexpensive approximation of length / 7
  78.710 -        int seventh = (length >> 3) + (length >> 6) + 1;
  78.711 -
  78.712 -        /*
  78.713 -         * Sort five evenly spaced elements around (and including) the
  78.714 -         * center element in the range. These elements will be used for
  78.715 -         * pivot selection as described below. The choice for spacing
  78.716 -         * these elements was empirically determined to work well on
  78.717 -         * a wide variety of inputs.
  78.718 -         */
  78.719 -        int e3 = (left + right) >>> 1; // The midpoint
  78.720 -        int e2 = e3 - seventh;
  78.721 -        int e1 = e2 - seventh;
  78.722 -        int e4 = e3 + seventh;
  78.723 -        int e5 = e4 + seventh;
  78.724 -
  78.725 -        // Sort these elements using insertion sort
  78.726 -        if (a[e2] < a[e1]) { long t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
  78.727 -
  78.728 -        if (a[e3] < a[e2]) { long t = a[e3]; a[e3] = a[e2]; a[e2] = t;
  78.729 -            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  78.730 -        }
  78.731 -        if (a[e4] < a[e3]) { long t = a[e4]; a[e4] = a[e3]; a[e3] = t;
  78.732 -            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  78.733 -                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  78.734 -            }
  78.735 -        }
  78.736 -        if (a[e5] < a[e4]) { long t = a[e5]; a[e5] = a[e4]; a[e4] = t;
  78.737 -            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
  78.738 -                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
  78.739 -                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
  78.740 -                }
  78.741 -            }
  78.742 -        }
  78.743 -
  78.744 -        // Pointers
  78.745 -        int less  = left;  // The index of the first element of center part
  78.746 -        int great = right; // The index before the first element of right part
  78.747 -
  78.748 -        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
  78.749 -            /*
  78.750 -             * Use the second and fourth of the five sorted elements as pivots.
  78.751 -             * These values are inexpensive approximations of the first and
  78.752 -             * second terciles of the array. Note that pivot1 <= pivot2.
  78.753 -             */
  78.754 -            long pivot1 = a[e2];
  78.755 -            long pivot2 = a[e4];
  78.756 -
  78.757 -            /*
  78.758 -             * The first and the last elements to be sorted are moved to the
  78.759 -             * locations formerly occupied by the pivots. When partitioning
  78.760 -             * is complete, the pivots are swapped back into their final
  78.761 -             * positions, and excluded from subsequent sorting.
  78.762 -             */
  78.763 -            a[e2] = a[left];
  78.764 -            a[e4] = a[right];
  78.765 -
  78.766 -            /*
  78.767 -             * Skip elements, which are less or greater than pivot values.
  78.768 -             */
  78.769 -            while (a[++less] < pivot1);
  78.770 -            while (a[--great] > pivot2);
  78.771 -
  78.772 -            /*
  78.773 -             * Partitioning:
  78.774 -             *
  78.775 -             *   left part           center part                   right part
  78.776 -             * +--------------------------------------------------------------+
  78.777 -             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
  78.778 -             * +--------------------------------------------------------------+
  78.779 -             *               ^                          ^       ^
  78.780 -             *               |                          |       |
  78.781 -             *              less                        k     great
  78.782 -             *
  78.783 -             * Invariants:
  78.784 -             *
  78.785 -             *              all in (left, less)   < pivot1
  78.786 -             *    pivot1 <= all in [less, k)     <= pivot2
  78.787 -             *              all in (great, right) > pivot2
  78.788 -             *
  78.789 -             * Pointer k is the first index of ?-part.
  78.790 -             */
  78.791 -            outer:
  78.792 -            for (int k = less - 1; ++k <= great; ) {
  78.793 -                long ak = a[k];
  78.794 -                if (ak < pivot1) { // Move a[k] to left part
  78.795 -                    a[k] = a[less];
  78.796 -                    /*
  78.797 -                     * Here and below we use "a[i] = b; i++;" instead
  78.798 -                     * of "a[i++] = b;" due to performance issue.
  78.799 -                     */
  78.800 -                    a[less] = ak;
  78.801 -                    ++less;
  78.802 -                } else if (ak > pivot2) { // Move a[k] to right part
  78.803 -                    while (a[great] > pivot2) {
  78.804 -                        if (great-- == k) {
  78.805 -                            break outer;
  78.806 -                        }
  78.807 -                    }
  78.808 -                    if (a[great] < pivot1) { // a[great] <= pivot2
  78.809 -                        a[k] = a[less];
  78.810 -                        a[less] = a[great];
  78.811 -                        ++less;
  78.812 -                    } else { // pivot1 <= a[great] <= pivot2
  78.813 -                        a[k] = a[great];
  78.814 -                    }
  78.815 -                    /*
  78.816 -                     * Here and below we use "a[i] = b; i--;" instead
  78.817 -                     * of "a[i--] = b;" due to performance issue.
  78.818 -                     */
  78.819 -                    a[great] = ak;
  78.820 -                    --great;
  78.821 -                }
  78.822 -            }
  78.823 -
  78.824 -            // Swap pivots into their final positions
  78.825 -            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
  78.826 -            a[right] = a[great + 1]; a[great + 1] = pivot2;
  78.827 -
  78.828 -            // Sort left and right parts recursively, excluding known pivots
  78.829 -            sort(a, left, less - 2, leftmost);
  78.830 -            sort(a, great + 2, right, false);
  78.831 -
  78.832 -            /*
  78.833 -             * If center part is too large (comprises > 4/7 of the array),
  78.834 -             * swap internal pivot values to ends.
  78.835 -             */
  78.836 -            if (less < e1 && e5 < great) {
  78.837 -                /*
  78.838 -                 * Skip elements, which are equal to pivot values.
  78.839 -                 */
  78.840 -                while (a[less] == pivot1) {
  78.841 -                    ++less;
  78.842 -                }
  78.843 -
  78.844 -                while (a[great] == pivot2) {
  78.845 -                    --great;
  78.846 -                }
  78.847 -
  78.848 -                /*
  78.849 -                 * Partitioning:
  78.850 -                 *
  78.851 -                 *   left part         center part                  right part
  78.852 -                 * +----------------------------------------------------------+
  78.853 -                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
  78.854 -                 * +----------------------------------------------------------+
  78.855 -                 *              ^                        ^       ^
  78.856 -                 *              |                        |       |
  78.857 -                 *             less                      k     great
  78.858 -                 *
  78.859 -                 * Invariants:
  78.860 -                 *
  78.861 -                 *              all in (*,  less) == pivot1
  78.862 -                 *     pivot1 < all in [less,  k)  < pivot2
  78.863 -                 *              all in (great, *) == pivot2
  78.864 -                 *
  78.865 -                 * Pointer k is the first index of ?-part.
  78.866 -                 */
  78.867 -                outer:
  78.868 -                for (int k = less - 1; ++k <= great; ) {
  78.869 -                    long ak = a[k];
  78.870 -                    if (ak == pivot1) { // Move a[k] to left part
  78.871 -                        a[k] = a[less];
  78.872 -                        a[less] = ak;
  78.873 -                        ++less;
  78.874 -                    } else if (ak == pivot2) { // Move a[k] to right part
  78.875 -                        while (a[great] == pivot2) {
  78.876 -                            if (great-- == k) {
  78.877 -                                break outer;
  78.878 -                            }
  78.879 -                        }
  78.880 -                        if (a[great] == pivot1) { // a[great] < pivot2
  78.881 -                            a[k] = a[less];
  78.882 -                            /*
  78.883 -                             * Even though a[great] equals to pivot1, the
  78.884 -                             * assignment a[less] = pivot1 may be incorrect,
  78.885 -                             * if a[great] and pivot1 are floating-point zeros
  78.886 -                             * of different signs. Therefore in float and
  78.887 -                             * double sorting methods we have to use more
  78.888 -                             * accurate assignment a[less] = a[great].
  78.889 -                             */
  78.890 -                            a[less] = pivot1;
  78.891 -                            ++less;
  78.892 -                        } else { // pivot1 < a[great] < pivot2
  78.893 -                            a[k] = a[great];
  78.894 -                        }
  78.895 -                        a[great] = ak;
  78.896 -                        --great;
  78.897 -                    }
  78.898 -                }
  78.899 -            }
  78.900 -
  78.901 -            // Sort center part recursively
  78.902 -            sort(a, less, great, false);
  78.903 -
  78.904 -        } else { // Partitioning with one pivot
  78.905 -            /*
  78.906 -             * Use the third of the five sorted elements as pivot.
  78.907 -             * This value is inexpensive approximation of the median.
  78.908 -             */
  78.909 -            long pivot = a[e3];
  78.910 -
  78.911 -            /*
  78.912 -             * Partitioning degenerates to the traditional 3-way
  78.913 -             * (or "Dutch National Flag") schema:
  78.914 -             *
  78.915 -             *   left part    center part              right part
  78.916 -             * +-------------------------------------------------+
  78.917 -             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
  78.918 -             * +-------------------------------------------------+
  78.919 -             *              ^              ^        ^
  78.920 -             *              |              |        |
  78.921 -             *             less            k      great
  78.922 -             *
  78.923 -             * Invariants:
  78.924 -             *
  78.925 -             *   all in (left, less)   < pivot
  78.926 -             *   all in [less, k)     == pivot
  78.927 -             *   all in (great, right) > pivot
  78.928 -             *
  78.929 -             * Pointer k is the first index of ?-part.
  78.930 -             */
  78.931 -            for (int k = less; k <= great; ++k) {
  78.932 -                if (a[k] == pivot) {
  78.933 -                    continue;
  78.934 -                }
  78.935 -                long ak = a[k];
  78.936 -                if (ak < pivot) { // Move a[k] to left part
  78.937 -                    a[k] = a[less];
  78.938 -                    a[less] = ak;
  78.939 -                    ++less;
  78.940 -                } else { // a[k] > pivot - Move a[k] to right part
  78.941 -                    while (a[great] > pivot) {
  78.942 -                        --great;
  78.943 -                    }
  78.944 -                    if (a[great] < pivot) { // a[great] <= pivot
  78.945 -                        a[k] = a[less];
  78.946 -                        a[less] = a[great];
  78.947 -                        ++less;
  78.948 -                    } else { // a[great] == pivot
  78.949 -                        /*
  78.950 -                         * Even though a[great] equals to pivot, the
  78.951 -                         * assignment a[k] = pivot may be incorrect,
  78.952 -                         * if a[great] and pivot are floating-point
  78.953 -                         * zeros of different signs. Therefore in float
  78.954 -                         * and double sorting methods we have to use
  78.955 -                         * more accurate assignment a[k] = a[great].
  78.956 -                         */
  78.957 -                        a[k] = pivot;
  78.958 -                    }
  78.959 -                    a[great] = ak;
  78.960 -                    --great;
  78.961 -                }
  78.962 -            }
  78.963 -
  78.964 -            /*
  78.965 -             * Sort left and right parts recursively.
  78.966 -             * All elements from center part are equal
  78.967 -             * and, therefore, already sorted.
  78.968 -             */
  78.969 -            sort(a, left, less - 1, leftmost);
  78.970 -            sort(a, great + 1, right, false);
  78.971 -        }
  78.972 -    }
  78.973 -
  78.974 -    /**
  78.975 -     * Sorts the specified array.
  78.976 -     *
  78.977 -     * @param a the array to be sorted
  78.978 -     */
  78.979 -    public static void sort(short[] a) {
  78.980 -        sort(a, 0, a.length - 1);
  78.981 -    }
  78.982 -
  78.983 -    /**
  78.984 -     * Sorts the specified range of the array.
  78.985 -     *
  78.986 -     * @param a the array to be sorted
  78.987 -     * @param left the index of the first element, inclusive, to be sorted
  78.988 -     * @param right the index of the last element, inclusive, to be sorted
  78.989 -     */
  78.990 -    public static void sort(short[] a, int left, int right) {
  78.991 -        // Use counting sort on large arrays
  78.992 -        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
  78.993 -            int[] count = new int[NUM_SHORT_VALUES];
  78.994 -
  78.995 -            for (int i = left - 1; ++i <= right;
  78.996 -                count[a[i] - Short.MIN_VALUE]++
  78.997 -            );
  78.998 -            for (int i = NUM_SHORT_VALUES, k = right + 1; k > left; ) {
  78.999 -                while (count[--i] == 0);
 78.1000 -                short value = (short) (i + Short.MIN_VALUE);
 78.1001 -                int s = count[i];
 78.1002 -
 78.1003 -                do {
 78.1004 -                    a[--k] = value;
 78.1005 -                } while (--s > 0);
 78.1006 -            }
 78.1007 -        } else { // Use Dual-Pivot Quicksort on small arrays
 78.1008 -            doSort(a, left, right);
 78.1009 -        }
 78.1010 -    }
 78.1011 -
 78.1012 -    /** The number of distinct short values. */
 78.1013 -    private static final int NUM_SHORT_VALUES = 1 << 16;
 78.1014 -
 78.1015 -    /**
 78.1016 -     * Sorts the specified range of the array.
 78.1017 -     *
 78.1018 -     * @param a the array to be sorted
 78.1019 -     * @param left the index of the first element, inclusive, to be sorted
 78.1020 -     * @param right the index of the last element, inclusive, to be sorted
 78.1021 -     */
 78.1022 -    private static void doSort(short[] a, int left, int right) {
 78.1023 -        // Use Quicksort on small arrays
 78.1024 -        if (right - left < QUICKSORT_THRESHOLD) {
 78.1025 -            sort(a, left, right, true);
 78.1026 -            return;
 78.1027 -        }
 78.1028 -
 78.1029 -        /*
 78.1030 -         * Index run[i] is the start of i-th run
 78.1031 -         * (ascending or descending sequence).
 78.1032 -         */
 78.1033 -        int[] run = new int[MAX_RUN_COUNT + 1];
 78.1034 -        int count = 0; run[0] = left;
 78.1035 -
 78.1036 -        // Check if the array is nearly sorted
 78.1037 -        for (int k = left; k < right; run[count] = k) {
 78.1038 -            if (a[k] < a[k + 1]) { // ascending
 78.1039 -                while (++k <= right && a[k - 1] <= a[k]);
 78.1040 -            } else if (a[k] > a[k + 1]) { // descending
 78.1041 -                while (++k <= right && a[k - 1] >= a[k]);
 78.1042 -                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 78.1043 -                    short t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 78.1044 -                }
 78.1045 -            } else { // equal
 78.1046 -                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 78.1047 -                    if (--m == 0) {
 78.1048 -                        sort(a, left, right, true);
 78.1049 -                        return;
 78.1050 -                    }
 78.1051 -                }
 78.1052 -            }
 78.1053 -
 78.1054 -            /*
 78.1055 -             * The array is not highly structured,
 78.1056 -             * use Quicksort instead of merge sort.
 78.1057 -             */
 78.1058 -            if (++count == MAX_RUN_COUNT) {
 78.1059 -                sort(a, left, right, true);
 78.1060 -                return;
 78.1061 -            }
 78.1062 -        }
 78.1063 -
 78.1064 -        // Check special cases
 78.1065 -        if (run[count] == right++) { // The last run contains one element
 78.1066 -            run[++count] = right;
 78.1067 -        } else if (count == 1) { // The array is already sorted
 78.1068 -            return;
 78.1069 -        }
 78.1070 -
 78.1071 -        /*
 78.1072 -         * Create temporary array, which is used for merging.
 78.1073 -         * Implementation note: variable "right" is increased by 1.
 78.1074 -         */
 78.1075 -        short[] b; byte odd = 0;
 78.1076 -        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 78.1077 -
 78.1078 -        if (odd == 0) {
 78.1079 -            b = a; a = new short[b.length];
 78.1080 -            for (int i = left - 1; ++i < right; a[i] = b[i]);
 78.1081 -        } else {
 78.1082 -            b = new short[a.length];
 78.1083 -        }
 78.1084 -
 78.1085 -        // Merging
 78.1086 -        for (int last; count > 1; count = last) {
 78.1087 -            for (int k = (last = 0) + 2; k <= count; k += 2) {
 78.1088 -                int hi = run[k], mi = run[k - 1];
 78.1089 -                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 78.1090 -                    if (q >= hi || p < mi && a[p] <= a[q]) {
 78.1091 -                        b[i] = a[p++];
 78.1092 -                    } else {
 78.1093 -                        b[i] = a[q++];
 78.1094 -                    }
 78.1095 -                }
 78.1096 -                run[++last] = hi;
 78.1097 -            }
 78.1098 -            if ((count & 1) != 0) {
 78.1099 -                for (int i = right, lo = run[count - 1]; --i >= lo;
 78.1100 -                    b[i] = a[i]
 78.1101 -                );
 78.1102 -                run[++last] = right;
 78.1103 -            }
 78.1104 -            short[] t = a; a = b; b = t;
 78.1105 -        }
 78.1106 -    }
 78.1107 -
 78.1108 -    /**
 78.1109 -     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 78.1110 -     *
 78.1111 -     * @param a the array to be sorted
 78.1112 -     * @param left the index of the first element, inclusive, to be sorted
 78.1113 -     * @param right the index of the last element, inclusive, to be sorted
 78.1114 -     * @param leftmost indicates if this part is the leftmost in the range
 78.1115 -     */
 78.1116 -    private static void sort(short[] a, int left, int right, boolean leftmost) {
 78.1117 -        int length = right - left + 1;
 78.1118 -
 78.1119 -        // Use insertion sort on tiny arrays
 78.1120 -        if (length < INSERTION_SORT_THRESHOLD) {
 78.1121 -            if (leftmost) {
 78.1122 -                /*
 78.1123 -                 * Traditional (without sentinel) insertion sort,
 78.1124 -                 * optimized for server VM, is used in case of
 78.1125 -                 * the leftmost part.
 78.1126 -                 */
 78.1127 -                for (int i = left, j = i; i < right; j = ++i) {
 78.1128 -                    short ai = a[i + 1];
 78.1129 -                    while (ai < a[j]) {
 78.1130 -                        a[j + 1] = a[j];
 78.1131 -                        if (j-- == left) {
 78.1132 -                            break;
 78.1133 -                        }
 78.1134 -                    }
 78.1135 -                    a[j + 1] = ai;
 78.1136 -                }
 78.1137 -            } else {
 78.1138 -                /*
 78.1139 -                 * Skip the longest ascending sequence.
 78.1140 -                 */
 78.1141 -                do {
 78.1142 -                    if (left >= right) {
 78.1143 -                        return;
 78.1144 -                    }
 78.1145 -                } while (a[++left] >= a[left - 1]);
 78.1146 -
 78.1147 -                /*
 78.1148 -                 * Every element from adjoining part plays the role
 78.1149 -                 * of sentinel, therefore this allows us to avoid the
 78.1150 -                 * left range check on each iteration. Moreover, we use
 78.1151 -                 * the more optimized algorithm, so called pair insertion
 78.1152 -                 * sort, which is faster (in the context of Quicksort)
 78.1153 -                 * than traditional implementation of insertion sort.
 78.1154 -                 */
 78.1155 -                for (int k = left; ++left <= right; k = ++left) {
 78.1156 -                    short a1 = a[k], a2 = a[left];
 78.1157 -
 78.1158 -                    if (a1 < a2) {
 78.1159 -                        a2 = a1; a1 = a[left];
 78.1160 -                    }
 78.1161 -                    while (a1 < a[--k]) {
 78.1162 -                        a[k + 2] = a[k];
 78.1163 -                    }
 78.1164 -                    a[++k + 1] = a1;
 78.1165 -
 78.1166 -                    while (a2 < a[--k]) {
 78.1167 -                        a[k + 1] = a[k];
 78.1168 -                    }
 78.1169 -                    a[k + 1] = a2;
 78.1170 -                }
 78.1171 -                short last = a[right];
 78.1172 -
 78.1173 -                while (last < a[--right]) {
 78.1174 -                    a[right + 1] = a[right];
 78.1175 -                }
 78.1176 -                a[right + 1] = last;
 78.1177 -            }
 78.1178 -            return;
 78.1179 -        }
 78.1180 -
 78.1181 -        // Inexpensive approximation of length / 7
 78.1182 -        int seventh = (length >> 3) + (length >> 6) + 1;
 78.1183 -
 78.1184 -        /*
 78.1185 -         * Sort five evenly spaced elements around (and including) the
 78.1186 -         * center element in the range. These elements will be used for
 78.1187 -         * pivot selection as described below. The choice for spacing
 78.1188 -         * these elements was empirically determined to work well on
 78.1189 -         * a wide variety of inputs.
 78.1190 -         */
 78.1191 -        int e3 = (left + right) >>> 1; // The midpoint
 78.1192 -        int e2 = e3 - seventh;
 78.1193 -        int e1 = e2 - seventh;
 78.1194 -        int e4 = e3 + seventh;
 78.1195 -        int e5 = e4 + seventh;
 78.1196 -
 78.1197 -        // Sort these elements using insertion sort
 78.1198 -        if (a[e2] < a[e1]) { short t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 78.1199 -
 78.1200 -        if (a[e3] < a[e2]) { short t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 78.1201 -            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.1202 -        }
 78.1203 -        if (a[e4] < a[e3]) { short t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 78.1204 -            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.1205 -                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.1206 -            }
 78.1207 -        }
 78.1208 -        if (a[e5] < a[e4]) { short t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 78.1209 -            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 78.1210 -                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.1211 -                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.1212 -                }
 78.1213 -            }
 78.1214 -        }
 78.1215 -
 78.1216 -        // Pointers
 78.1217 -        int less  = left;  // The index of the first element of center part
 78.1218 -        int great = right; // The index before the first element of right part
 78.1219 -
 78.1220 -        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 78.1221 -            /*
 78.1222 -             * Use the second and fourth of the five sorted elements as pivots.
 78.1223 -             * These values are inexpensive approximations of the first and
 78.1224 -             * second terciles of the array. Note that pivot1 <= pivot2.
 78.1225 -             */
 78.1226 -            short pivot1 = a[e2];
 78.1227 -            short pivot2 = a[e4];
 78.1228 -
 78.1229 -            /*
 78.1230 -             * The first and the last elements to be sorted are moved to the
 78.1231 -             * locations formerly occupied by the pivots. When partitioning
 78.1232 -             * is complete, the pivots are swapped back into their final
 78.1233 -             * positions, and excluded from subsequent sorting.
 78.1234 -             */
 78.1235 -            a[e2] = a[left];
 78.1236 -            a[e4] = a[right];
 78.1237 -
 78.1238 -            /*
 78.1239 -             * Skip elements, which are less or greater than pivot values.
 78.1240 -             */
 78.1241 -            while (a[++less] < pivot1);
 78.1242 -            while (a[--great] > pivot2);
 78.1243 -
 78.1244 -            /*
 78.1245 -             * Partitioning:
 78.1246 -             *
 78.1247 -             *   left part           center part                   right part
 78.1248 -             * +--------------------------------------------------------------+
 78.1249 -             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 78.1250 -             * +--------------------------------------------------------------+
 78.1251 -             *               ^                          ^       ^
 78.1252 -             *               |                          |       |
 78.1253 -             *              less                        k     great
 78.1254 -             *
 78.1255 -             * Invariants:
 78.1256 -             *
 78.1257 -             *              all in (left, less)   < pivot1
 78.1258 -             *    pivot1 <= all in [less, k)     <= pivot2
 78.1259 -             *              all in (great, right) > pivot2
 78.1260 -             *
 78.1261 -             * Pointer k is the first index of ?-part.
 78.1262 -             */
 78.1263 -            outer:
 78.1264 -            for (int k = less - 1; ++k <= great; ) {
 78.1265 -                short ak = a[k];
 78.1266 -                if (ak < pivot1) { // Move a[k] to left part
 78.1267 -                    a[k] = a[less];
 78.1268 -                    /*
 78.1269 -                     * Here and below we use "a[i] = b; i++;" instead
 78.1270 -                     * of "a[i++] = b;" due to performance issue.
 78.1271 -                     */
 78.1272 -                    a[less] = ak;
 78.1273 -                    ++less;
 78.1274 -                } else if (ak > pivot2) { // Move a[k] to right part
 78.1275 -                    while (a[great] > pivot2) {
 78.1276 -                        if (great-- == k) {
 78.1277 -                            break outer;
 78.1278 -                        }
 78.1279 -                    }
 78.1280 -                    if (a[great] < pivot1) { // a[great] <= pivot2
 78.1281 -                        a[k] = a[less];
 78.1282 -                        a[less] = a[great];
 78.1283 -                        ++less;
 78.1284 -                    } else { // pivot1 <= a[great] <= pivot2
 78.1285 -                        a[k] = a[great];
 78.1286 -                    }
 78.1287 -                    /*
 78.1288 -                     * Here and below we use "a[i] = b; i--;" instead
 78.1289 -                     * of "a[i--] = b;" due to performance issue.
 78.1290 -                     */
 78.1291 -                    a[great] = ak;
 78.1292 -                    --great;
 78.1293 -                }
 78.1294 -            }
 78.1295 -
 78.1296 -            // Swap pivots into their final positions
 78.1297 -            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 78.1298 -            a[right] = a[great + 1]; a[great + 1] = pivot2;
 78.1299 -
 78.1300 -            // Sort left and right parts recursively, excluding known pivots
 78.1301 -            sort(a, left, less - 2, leftmost);
 78.1302 -            sort(a, great + 2, right, false);
 78.1303 -
 78.1304 -            /*
 78.1305 -             * If center part is too large (comprises > 4/7 of the array),
 78.1306 -             * swap internal pivot values to ends.
 78.1307 -             */
 78.1308 -            if (less < e1 && e5 < great) {
 78.1309 -                /*
 78.1310 -                 * Skip elements, which are equal to pivot values.
 78.1311 -                 */
 78.1312 -                while (a[less] == pivot1) {
 78.1313 -                    ++less;
 78.1314 -                }
 78.1315 -
 78.1316 -                while (a[great] == pivot2) {
 78.1317 -                    --great;
 78.1318 -                }
 78.1319 -
 78.1320 -                /*
 78.1321 -                 * Partitioning:
 78.1322 -                 *
 78.1323 -                 *   left part         center part                  right part
 78.1324 -                 * +----------------------------------------------------------+
 78.1325 -                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 78.1326 -                 * +----------------------------------------------------------+
 78.1327 -                 *              ^                        ^       ^
 78.1328 -                 *              |                        |       |
 78.1329 -                 *             less                      k     great
 78.1330 -                 *
 78.1331 -                 * Invariants:
 78.1332 -                 *
 78.1333 -                 *              all in (*,  less) == pivot1
 78.1334 -                 *     pivot1 < all in [less,  k)  < pivot2
 78.1335 -                 *              all in (great, *) == pivot2
 78.1336 -                 *
 78.1337 -                 * Pointer k is the first index of ?-part.
 78.1338 -                 */
 78.1339 -                outer:
 78.1340 -                for (int k = less - 1; ++k <= great; ) {
 78.1341 -                    short ak = a[k];
 78.1342 -                    if (ak == pivot1) { // Move a[k] to left part
 78.1343 -                        a[k] = a[less];
 78.1344 -                        a[less] = ak;
 78.1345 -                        ++less;
 78.1346 -                    } else if (ak == pivot2) { // Move a[k] to right part
 78.1347 -                        while (a[great] == pivot2) {
 78.1348 -                            if (great-- == k) {
 78.1349 -                                break outer;
 78.1350 -                            }
 78.1351 -                        }
 78.1352 -                        if (a[great] == pivot1) { // a[great] < pivot2
 78.1353 -                            a[k] = a[less];
 78.1354 -                            /*
 78.1355 -                             * Even though a[great] equals to pivot1, the
 78.1356 -                             * assignment a[less] = pivot1 may be incorrect,
 78.1357 -                             * if a[great] and pivot1 are floating-point zeros
 78.1358 -                             * of different signs. Therefore in float and
 78.1359 -                             * double sorting methods we have to use more
 78.1360 -                             * accurate assignment a[less] = a[great].
 78.1361 -                             */
 78.1362 -                            a[less] = pivot1;
 78.1363 -                            ++less;
 78.1364 -                        } else { // pivot1 < a[great] < pivot2
 78.1365 -                            a[k] = a[great];
 78.1366 -                        }
 78.1367 -                        a[great] = ak;
 78.1368 -                        --great;
 78.1369 -                    }
 78.1370 -                }
 78.1371 -            }
 78.1372 -
 78.1373 -            // Sort center part recursively
 78.1374 -            sort(a, less, great, false);
 78.1375 -
 78.1376 -        } else { // Partitioning with one pivot
 78.1377 -            /*
 78.1378 -             * Use the third of the five sorted elements as pivot.
 78.1379 -             * This value is inexpensive approximation of the median.
 78.1380 -             */
 78.1381 -            short pivot = a[e3];
 78.1382 -
 78.1383 -            /*
 78.1384 -             * Partitioning degenerates to the traditional 3-way
 78.1385 -             * (or "Dutch National Flag") schema:
 78.1386 -             *
 78.1387 -             *   left part    center part              right part
 78.1388 -             * +-------------------------------------------------+
 78.1389 -             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 78.1390 -             * +-------------------------------------------------+
 78.1391 -             *              ^              ^        ^
 78.1392 -             *              |              |        |
 78.1393 -             *             less            k      great
 78.1394 -             *
 78.1395 -             * Invariants:
 78.1396 -             *
 78.1397 -             *   all in (left, less)   < pivot
 78.1398 -             *   all in [less, k)     == pivot
 78.1399 -             *   all in (great, right) > pivot
 78.1400 -             *
 78.1401 -             * Pointer k is the first index of ?-part.
 78.1402 -             */
 78.1403 -            for (int k = less; k <= great; ++k) {
 78.1404 -                if (a[k] == pivot) {
 78.1405 -                    continue;
 78.1406 -                }
 78.1407 -                short ak = a[k];
 78.1408 -                if (ak < pivot) { // Move a[k] to left part
 78.1409 -                    a[k] = a[less];
 78.1410 -                    a[less] = ak;
 78.1411 -                    ++less;
 78.1412 -                } else { // a[k] > pivot - Move a[k] to right part
 78.1413 -                    while (a[great] > pivot) {
 78.1414 -                        --great;
 78.1415 -                    }
 78.1416 -                    if (a[great] < pivot) { // a[great] <= pivot
 78.1417 -                        a[k] = a[less];
 78.1418 -                        a[less] = a[great];
 78.1419 -                        ++less;
 78.1420 -                    } else { // a[great] == pivot
 78.1421 -                        /*
 78.1422 -                         * Even though a[great] equals to pivot, the
 78.1423 -                         * assignment a[k] = pivot may be incorrect,
 78.1424 -                         * if a[great] and pivot are floating-point
 78.1425 -                         * zeros of different signs. Therefore in float
 78.1426 -                         * and double sorting methods we have to use
 78.1427 -                         * more accurate assignment a[k] = a[great].
 78.1428 -                         */
 78.1429 -                        a[k] = pivot;
 78.1430 -                    }
 78.1431 -                    a[great] = ak;
 78.1432 -                    --great;
 78.1433 -                }
 78.1434 -            }
 78.1435 -
 78.1436 -            /*
 78.1437 -             * Sort left and right parts recursively.
 78.1438 -             * All elements from center part are equal
 78.1439 -             * and, therefore, already sorted.
 78.1440 -             */
 78.1441 -            sort(a, left, less - 1, leftmost);
 78.1442 -            sort(a, great + 1, right, false);
 78.1443 -        }
 78.1444 -    }
 78.1445 -
 78.1446 -    /**
 78.1447 -     * Sorts the specified array.
 78.1448 -     *
 78.1449 -     * @param a the array to be sorted
 78.1450 -     */
 78.1451 -    public static void sort(char[] a) {
 78.1452 -        sort(a, 0, a.length - 1);
 78.1453 -    }
 78.1454 -
 78.1455 -    /**
 78.1456 -     * Sorts the specified range of the array.
 78.1457 -     *
 78.1458 -     * @param a the array to be sorted
 78.1459 -     * @param left the index of the first element, inclusive, to be sorted
 78.1460 -     * @param right the index of the last element, inclusive, to be sorted
 78.1461 -     */
 78.1462 -    public static void sort(char[] a, int left, int right) {
 78.1463 -        // Use counting sort on large arrays
 78.1464 -        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 78.1465 -            int[] count = new int[NUM_CHAR_VALUES];
 78.1466 -
 78.1467 -            for (int i = left - 1; ++i <= right;
 78.1468 -                count[a[i]]++
 78.1469 -            );
 78.1470 -            for (int i = NUM_CHAR_VALUES, k = right + 1; k > left; ) {
 78.1471 -                while (count[--i] == 0);
 78.1472 -                char value = (char) i;
 78.1473 -                int s = count[i];
 78.1474 -
 78.1475 -                do {
 78.1476 -                    a[--k] = value;
 78.1477 -                } while (--s > 0);
 78.1478 -            }
 78.1479 -        } else { // Use Dual-Pivot Quicksort on small arrays
 78.1480 -            doSort(a, left, right);
 78.1481 -        }
 78.1482 -    }
 78.1483 -
 78.1484 -    /** The number of distinct char values. */
 78.1485 -    private static final int NUM_CHAR_VALUES = 1 << 16;
 78.1486 -
 78.1487 -    /**
 78.1488 -     * Sorts the specified range of the array.
 78.1489 -     *
 78.1490 -     * @param a the array to be sorted
 78.1491 -     * @param left the index of the first element, inclusive, to be sorted
 78.1492 -     * @param right the index of the last element, inclusive, to be sorted
 78.1493 -     */
 78.1494 -    private static void doSort(char[] a, int left, int right) {
 78.1495 -        // Use Quicksort on small arrays
 78.1496 -        if (right - left < QUICKSORT_THRESHOLD) {
 78.1497 -            sort(a, left, right, true);
 78.1498 -            return;
 78.1499 -        }
 78.1500 -
 78.1501 -        /*
 78.1502 -         * Index run[i] is the start of i-th run
 78.1503 -         * (ascending or descending sequence).
 78.1504 -         */
 78.1505 -        int[] run = new int[MAX_RUN_COUNT + 1];
 78.1506 -        int count = 0; run[0] = left;
 78.1507 -
 78.1508 -        // Check if the array is nearly sorted
 78.1509 -        for (int k = left; k < right; run[count] = k) {
 78.1510 -            if (a[k] < a[k + 1]) { // ascending
 78.1511 -                while (++k <= right && a[k - 1] <= a[k]);
 78.1512 -            } else if (a[k] > a[k + 1]) { // descending
 78.1513 -                while (++k <= right && a[k - 1] >= a[k]);
 78.1514 -                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 78.1515 -                    char t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 78.1516 -                }
 78.1517 -            } else { // equal
 78.1518 -                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 78.1519 -                    if (--m == 0) {
 78.1520 -                        sort(a, left, right, true);
 78.1521 -                        return;
 78.1522 -                    }
 78.1523 -                }
 78.1524 -            }
 78.1525 -
 78.1526 -            /*
 78.1527 -             * The array is not highly structured,
 78.1528 -             * use Quicksort instead of merge sort.
 78.1529 -             */
 78.1530 -            if (++count == MAX_RUN_COUNT) {
 78.1531 -                sort(a, left, right, true);
 78.1532 -                return;
 78.1533 -            }
 78.1534 -        }
 78.1535 -
 78.1536 -        // Check special cases
 78.1537 -        if (run[count] == right++) { // The last run contains one element
 78.1538 -            run[++count] = right;
 78.1539 -        } else if (count == 1) { // The array is already sorted
 78.1540 -            return;
 78.1541 -        }
 78.1542 -
 78.1543 -        /*
 78.1544 -         * Create temporary array, which is used for merging.
 78.1545 -         * Implementation note: variable "right" is increased by 1.
 78.1546 -         */
 78.1547 -        char[] b; byte odd = 0;
 78.1548 -        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 78.1549 -
 78.1550 -        if (odd == 0) {
 78.1551 -            b = a; a = new char[b.length];
 78.1552 -            for (int i = left - 1; ++i < right; a[i] = b[i]);
 78.1553 -        } else {
 78.1554 -            b = new char[a.length];
 78.1555 -        }
 78.1556 -
 78.1557 -        // Merging
 78.1558 -        for (int last; count > 1; count = last) {
 78.1559 -            for (int k = (last = 0) + 2; k <= count; k += 2) {
 78.1560 -                int hi = run[k], mi = run[k - 1];
 78.1561 -                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 78.1562 -                    if (q >= hi || p < mi && a[p] <= a[q]) {
 78.1563 -                        b[i] = a[p++];
 78.1564 -                    } else {
 78.1565 -                        b[i] = a[q++];
 78.1566 -                    }
 78.1567 -                }
 78.1568 -                run[++last] = hi;
 78.1569 -            }
 78.1570 -            if ((count & 1) != 0) {
 78.1571 -                for (int i = right, lo = run[count - 1]; --i >= lo;
 78.1572 -                    b[i] = a[i]
 78.1573 -                );
 78.1574 -                run[++last] = right;
 78.1575 -            }
 78.1576 -            char[] t = a; a = b; b = t;
 78.1577 -        }
 78.1578 -    }
 78.1579 -
 78.1580 -    /**
 78.1581 -     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 78.1582 -     *
 78.1583 -     * @param a the array to be sorted
 78.1584 -     * @param left the index of the first element, inclusive, to be sorted
 78.1585 -     * @param right the index of the last element, inclusive, to be sorted
 78.1586 -     * @param leftmost indicates if this part is the leftmost in the range
 78.1587 -     */
 78.1588 -    private static void sort(char[] a, int left, int right, boolean leftmost) {
 78.1589 -        int length = right - left + 1;
 78.1590 -
 78.1591 -        // Use insertion sort on tiny arrays
 78.1592 -        if (length < INSERTION_SORT_THRESHOLD) {
 78.1593 -            if (leftmost) {
 78.1594 -                /*
 78.1595 -                 * Traditional (without sentinel) insertion sort,
 78.1596 -                 * optimized for server VM, is used in case of
 78.1597 -                 * the leftmost part.
 78.1598 -                 */
 78.1599 -                for (int i = left, j = i; i < right; j = ++i) {
 78.1600 -                    char ai = a[i + 1];
 78.1601 -                    while (ai < a[j]) {
 78.1602 -                        a[j + 1] = a[j];
 78.1603 -                        if (j-- == left) {
 78.1604 -                            break;
 78.1605 -                        }
 78.1606 -                    }
 78.1607 -                    a[j + 1] = ai;
 78.1608 -                }
 78.1609 -            } else {
 78.1610 -                /*
 78.1611 -                 * Skip the longest ascending sequence.
 78.1612 -                 */
 78.1613 -                do {
 78.1614 -                    if (left >= right) {
 78.1615 -                        return;
 78.1616 -                    }
 78.1617 -                } while (a[++left] >= a[left - 1]);
 78.1618 -
 78.1619 -                /*
 78.1620 -                 * Every element from adjoining part plays the role
 78.1621 -                 * of sentinel, therefore this allows us to avoid the
 78.1622 -                 * left range check on each iteration. Moreover, we use
 78.1623 -                 * the more optimized algorithm, so called pair insertion
 78.1624 -                 * sort, which is faster (in the context of Quicksort)
 78.1625 -                 * than traditional implementation of insertion sort.
 78.1626 -                 */
 78.1627 -                for (int k = left; ++left <= right; k = ++left) {
 78.1628 -                    char a1 = a[k], a2 = a[left];
 78.1629 -
 78.1630 -                    if (a1 < a2) {
 78.1631 -                        a2 = a1; a1 = a[left];
 78.1632 -                    }
 78.1633 -                    while (a1 < a[--k]) {
 78.1634 -                        a[k + 2] = a[k];
 78.1635 -                    }
 78.1636 -                    a[++k + 1] = a1;
 78.1637 -
 78.1638 -                    while (a2 < a[--k]) {
 78.1639 -                        a[k + 1] = a[k];
 78.1640 -                    }
 78.1641 -                    a[k + 1] = a2;
 78.1642 -                }
 78.1643 -                char last = a[right];
 78.1644 -
 78.1645 -                while (last < a[--right]) {
 78.1646 -                    a[right + 1] = a[right];
 78.1647 -                }
 78.1648 -                a[right + 1] = last;
 78.1649 -            }
 78.1650 -            return;
 78.1651 -        }
 78.1652 -
 78.1653 -        // Inexpensive approximation of length / 7
 78.1654 -        int seventh = (length >> 3) + (length >> 6) + 1;
 78.1655 -
 78.1656 -        /*
 78.1657 -         * Sort five evenly spaced elements around (and including) the
 78.1658 -         * center element in the range. These elements will be used for
 78.1659 -         * pivot selection as described below. The choice for spacing
 78.1660 -         * these elements was empirically determined to work well on
 78.1661 -         * a wide variety of inputs.
 78.1662 -         */
 78.1663 -        int e3 = (left + right) >>> 1; // The midpoint
 78.1664 -        int e2 = e3 - seventh;
 78.1665 -        int e1 = e2 - seventh;
 78.1666 -        int e4 = e3 + seventh;
 78.1667 -        int e5 = e4 + seventh;
 78.1668 -
 78.1669 -        // Sort these elements using insertion sort
 78.1670 -        if (a[e2] < a[e1]) { char t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 78.1671 -
 78.1672 -        if (a[e3] < a[e2]) { char t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 78.1673 -            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.1674 -        }
 78.1675 -        if (a[e4] < a[e3]) { char t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 78.1676 -            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.1677 -                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.1678 -            }
 78.1679 -        }
 78.1680 -        if (a[e5] < a[e4]) { char t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 78.1681 -            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 78.1682 -                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.1683 -                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.1684 -                }
 78.1685 -            }
 78.1686 -        }
 78.1687 -
 78.1688 -        // Pointers
 78.1689 -        int less  = left;  // The index of the first element of center part
 78.1690 -        int great = right; // The index before the first element of right part
 78.1691 -
 78.1692 -        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 78.1693 -            /*
 78.1694 -             * Use the second and fourth of the five sorted elements as pivots.
 78.1695 -             * These values are inexpensive approximations of the first and
 78.1696 -             * second terciles of the array. Note that pivot1 <= pivot2.
 78.1697 -             */
 78.1698 -            char pivot1 = a[e2];
 78.1699 -            char pivot2 = a[e4];
 78.1700 -
 78.1701 -            /*
 78.1702 -             * The first and the last elements to be sorted are moved to the
 78.1703 -             * locations formerly occupied by the pivots. When partitioning
 78.1704 -             * is complete, the pivots are swapped back into their final
 78.1705 -             * positions, and excluded from subsequent sorting.
 78.1706 -             */
 78.1707 -            a[e2] = a[left];
 78.1708 -            a[e4] = a[right];
 78.1709 -
 78.1710 -            /*
 78.1711 -             * Skip elements, which are less or greater than pivot values.
 78.1712 -             */
 78.1713 -            while (a[++less] < pivot1);
 78.1714 -            while (a[--great] > pivot2);
 78.1715 -
 78.1716 -            /*
 78.1717 -             * Partitioning:
 78.1718 -             *
 78.1719 -             *   left part           center part                   right part
 78.1720 -             * +--------------------------------------------------------------+
 78.1721 -             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 78.1722 -             * +--------------------------------------------------------------+
 78.1723 -             *               ^                          ^       ^
 78.1724 -             *               |                          |       |
 78.1725 -             *              less                        k     great
 78.1726 -             *
 78.1727 -             * Invariants:
 78.1728 -             *
 78.1729 -             *              all in (left, less)   < pivot1
 78.1730 -             *    pivot1 <= all in [less, k)     <= pivot2
 78.1731 -             *              all in (great, right) > pivot2
 78.1732 -             *
 78.1733 -             * Pointer k is the first index of ?-part.
 78.1734 -             */
 78.1735 -            outer:
 78.1736 -            for (int k = less - 1; ++k <= great; ) {
 78.1737 -                char ak = a[k];
 78.1738 -                if (ak < pivot1) { // Move a[k] to left part
 78.1739 -                    a[k] = a[less];
 78.1740 -                    /*
 78.1741 -                     * Here and below we use "a[i] = b; i++;" instead
 78.1742 -                     * of "a[i++] = b;" due to performance issue.
 78.1743 -                     */
 78.1744 -                    a[less] = ak;
 78.1745 -                    ++less;
 78.1746 -                } else if (ak > pivot2) { // Move a[k] to right part
 78.1747 -                    while (a[great] > pivot2) {
 78.1748 -                        if (great-- == k) {
 78.1749 -                            break outer;
 78.1750 -                        }
 78.1751 -                    }
 78.1752 -                    if (a[great] < pivot1) { // a[great] <= pivot2
 78.1753 -                        a[k] = a[less];
 78.1754 -                        a[less] = a[great];
 78.1755 -                        ++less;
 78.1756 -                    } else { // pivot1 <= a[great] <= pivot2
 78.1757 -                        a[k] = a[great];
 78.1758 -                    }
 78.1759 -                    /*
 78.1760 -                     * Here and below we use "a[i] = b; i--;" instead
 78.1761 -                     * of "a[i--] = b;" due to performance issue.
 78.1762 -                     */
 78.1763 -                    a[great] = ak;
 78.1764 -                    --great;
 78.1765 -                }
 78.1766 -            }
 78.1767 -
 78.1768 -            // Swap pivots into their final positions
 78.1769 -            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 78.1770 -            a[right] = a[great + 1]; a[great + 1] = pivot2;
 78.1771 -
 78.1772 -            // Sort left and right parts recursively, excluding known pivots
 78.1773 -            sort(a, left, less - 2, leftmost);
 78.1774 -            sort(a, great + 2, right, false);
 78.1775 -
 78.1776 -            /*
 78.1777 -             * If center part is too large (comprises > 4/7 of the array),
 78.1778 -             * swap internal pivot values to ends.
 78.1779 -             */
 78.1780 -            if (less < e1 && e5 < great) {
 78.1781 -                /*
 78.1782 -                 * Skip elements, which are equal to pivot values.
 78.1783 -                 */
 78.1784 -                while (a[less] == pivot1) {
 78.1785 -                    ++less;
 78.1786 -                }
 78.1787 -
 78.1788 -                while (a[great] == pivot2) {
 78.1789 -                    --great;
 78.1790 -                }
 78.1791 -
 78.1792 -                /*
 78.1793 -                 * Partitioning:
 78.1794 -                 *
 78.1795 -                 *   left part         center part                  right part
 78.1796 -                 * +----------------------------------------------------------+
 78.1797 -                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 78.1798 -                 * +----------------------------------------------------------+
 78.1799 -                 *              ^                        ^       ^
 78.1800 -                 *              |                        |       |
 78.1801 -                 *             less                      k     great
 78.1802 -                 *
 78.1803 -                 * Invariants:
 78.1804 -                 *
 78.1805 -                 *              all in (*,  less) == pivot1
 78.1806 -                 *     pivot1 < all in [less,  k)  < pivot2
 78.1807 -                 *              all in (great, *) == pivot2
 78.1808 -                 *
 78.1809 -                 * Pointer k is the first index of ?-part.
 78.1810 -                 */
 78.1811 -                outer:
 78.1812 -                for (int k = less - 1; ++k <= great; ) {
 78.1813 -                    char ak = a[k];
 78.1814 -                    if (ak == pivot1) { // Move a[k] to left part
 78.1815 -                        a[k] = a[less];
 78.1816 -                        a[less] = ak;
 78.1817 -                        ++less;
 78.1818 -                    } else if (ak == pivot2) { // Move a[k] to right part
 78.1819 -                        while (a[great] == pivot2) {
 78.1820 -                            if (great-- == k) {
 78.1821 -                                break outer;
 78.1822 -                            }
 78.1823 -                        }
 78.1824 -                        if (a[great] == pivot1) { // a[great] < pivot2
 78.1825 -                            a[k] = a[less];
 78.1826 -                            /*
 78.1827 -                             * Even though a[great] equals to pivot1, the
 78.1828 -                             * assignment a[less] = pivot1 may be incorrect,
 78.1829 -                             * if a[great] and pivot1 are floating-point zeros
 78.1830 -                             * of different signs. Therefore in float and
 78.1831 -                             * double sorting methods we have to use more
 78.1832 -                             * accurate assignment a[less] = a[great].
 78.1833 -                             */
 78.1834 -                            a[less] = pivot1;
 78.1835 -                            ++less;
 78.1836 -                        } else { // pivot1 < a[great] < pivot2
 78.1837 -                            a[k] = a[great];
 78.1838 -                        }
 78.1839 -                        a[great] = ak;
 78.1840 -                        --great;
 78.1841 -                    }
 78.1842 -                }
 78.1843 -            }
 78.1844 -
 78.1845 -            // Sort center part recursively
 78.1846 -            sort(a, less, great, false);
 78.1847 -
 78.1848 -        } else { // Partitioning with one pivot
 78.1849 -            /*
 78.1850 -             * Use the third of the five sorted elements as pivot.
 78.1851 -             * This value is inexpensive approximation of the median.
 78.1852 -             */
 78.1853 -            char pivot = a[e3];
 78.1854 -
 78.1855 -            /*
 78.1856 -             * Partitioning degenerates to the traditional 3-way
 78.1857 -             * (or "Dutch National Flag") schema:
 78.1858 -             *
 78.1859 -             *   left part    center part              right part
 78.1860 -             * +-------------------------------------------------+
 78.1861 -             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 78.1862 -             * +-------------------------------------------------+
 78.1863 -             *              ^              ^        ^
 78.1864 -             *              |              |        |
 78.1865 -             *             less            k      great
 78.1866 -             *
 78.1867 -             * Invariants:
 78.1868 -             *
 78.1869 -             *   all in (left, less)   < pivot
 78.1870 -             *   all in [less, k)     == pivot
 78.1871 -             *   all in (great, right) > pivot
 78.1872 -             *
 78.1873 -             * Pointer k is the first index of ?-part.
 78.1874 -             */
 78.1875 -            for (int k = less; k <= great; ++k) {
 78.1876 -                if (a[k] == pivot) {
 78.1877 -                    continue;
 78.1878 -                }
 78.1879 -                char ak = a[k];
 78.1880 -                if (ak < pivot) { // Move a[k] to left part
 78.1881 -                    a[k] = a[less];
 78.1882 -                    a[less] = ak;
 78.1883 -                    ++less;
 78.1884 -                } else { // a[k] > pivot - Move a[k] to right part
 78.1885 -                    while (a[great] > pivot) {
 78.1886 -                        --great;
 78.1887 -                    }
 78.1888 -                    if (a[great] < pivot) { // a[great] <= pivot
 78.1889 -                        a[k] = a[less];
 78.1890 -                        a[less] = a[great];
 78.1891 -                        ++less;
 78.1892 -                    } else { // a[great] == pivot
 78.1893 -                        /*
 78.1894 -                         * Even though a[great] equals to pivot, the
 78.1895 -                         * assignment a[k] = pivot may be incorrect,
 78.1896 -                         * if a[great] and pivot are floating-point
 78.1897 -                         * zeros of different signs. Therefore in float
 78.1898 -                         * and double sorting methods we have to use
 78.1899 -                         * more accurate assignment a[k] = a[great].
 78.1900 -                         */
 78.1901 -                        a[k] = pivot;
 78.1902 -                    }
 78.1903 -                    a[great] = ak;
 78.1904 -                    --great;
 78.1905 -                }
 78.1906 -            }
 78.1907 -
 78.1908 -            /*
 78.1909 -             * Sort left and right parts recursively.
 78.1910 -             * All elements from center part are equal
 78.1911 -             * and, therefore, already sorted.
 78.1912 -             */
 78.1913 -            sort(a, left, less - 1, leftmost);
 78.1914 -            sort(a, great + 1, right, false);
 78.1915 -        }
 78.1916 -    }
 78.1917 -
 78.1918 -    /** The number of distinct byte values. */
 78.1919 -    private static final int NUM_BYTE_VALUES = 1 << 8;
 78.1920 -
 78.1921 -    /**
 78.1922 -     * Sorts the specified array.
 78.1923 -     *
 78.1924 -     * @param a the array to be sorted
 78.1925 -     */
 78.1926 -    public static void sort(byte[] a) {
 78.1927 -        sort(a, 0, a.length - 1);
 78.1928 -    }
 78.1929 -
 78.1930 -    /**
 78.1931 -     * Sorts the specified range of the array.
 78.1932 -     *
 78.1933 -     * @param a the array to be sorted
 78.1934 -     * @param left the index of the first element, inclusive, to be sorted
 78.1935 -     * @param right the index of the last element, inclusive, to be sorted
 78.1936 -     */
 78.1937 -    public static void sort(byte[] a, int left, int right) {
 78.1938 -        // Use counting sort on large arrays
 78.1939 -        if (right - left > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
 78.1940 -            int[] count = new int[NUM_BYTE_VALUES];
 78.1941 -
 78.1942 -            for (int i = left - 1; ++i <= right;
 78.1943 -                count[a[i] - Byte.MIN_VALUE]++
 78.1944 -            );
 78.1945 -            for (int i = NUM_BYTE_VALUES, k = right + 1; k > left; ) {
 78.1946 -                while (count[--i] == 0);
 78.1947 -                byte value = (byte) (i + Byte.MIN_VALUE);
 78.1948 -                int s = count[i];
 78.1949 -
 78.1950 -                do {
 78.1951 -                    a[--k] = value;
 78.1952 -                } while (--s > 0);
 78.1953 -            }
 78.1954 -        } else { // Use insertion sort on small arrays
 78.1955 -            for (int i = left, j = i; i < right; j = ++i) {
 78.1956 -                byte ai = a[i + 1];
 78.1957 -                while (ai < a[j]) {
 78.1958 -                    a[j + 1] = a[j];
 78.1959 -                    if (j-- == left) {
 78.1960 -                        break;
 78.1961 -                    }
 78.1962 -                }
 78.1963 -                a[j + 1] = ai;
 78.1964 -            }
 78.1965 -        }
 78.1966 -    }
 78.1967 -
 78.1968 -    /**
 78.1969 -     * Sorts the specified array.
 78.1970 -     *
 78.1971 -     * @param a the array to be sorted
 78.1972 -     */
 78.1973 -    public static void sort(float[] a) {
 78.1974 -        sort(a, 0, a.length - 1);
 78.1975 -    }
 78.1976 -
 78.1977 -    /**
 78.1978 -     * Sorts the specified range of the array.
 78.1979 -     *
 78.1980 -     * @param a the array to be sorted
 78.1981 -     * @param left the index of the first element, inclusive, to be sorted
 78.1982 -     * @param right the index of the last element, inclusive, to be sorted
 78.1983 -     */
 78.1984 -    public static void sort(float[] a, int left, int right) {
 78.1985 -        /*
 78.1986 -         * Phase 1: Move NaNs to the end of the array.
 78.1987 -         */
 78.1988 -        while (left <= right && Float.isNaN(a[right])) {
 78.1989 -            --right;
 78.1990 -        }
 78.1991 -        for (int k = right; --k >= left; ) {
 78.1992 -            float ak = a[k];
 78.1993 -            if (ak != ak) { // a[k] is NaN
 78.1994 -                a[k] = a[right];
 78.1995 -                a[right] = ak;
 78.1996 -                --right;
 78.1997 -            }
 78.1998 -        }
 78.1999 -
 78.2000 -        /*
 78.2001 -         * Phase 2: Sort everything except NaNs (which are already in place).
 78.2002 -         */
 78.2003 -        doSort(a, left, right);
 78.2004 -
 78.2005 -        /*
 78.2006 -         * Phase 3: Place negative zeros before positive zeros.
 78.2007 -         */
 78.2008 -        int hi = right;
 78.2009 -
 78.2010 -        /*
 78.2011 -         * Find the first zero, or first positive, or last negative element.
 78.2012 -         */
 78.2013 -        while (left < hi) {
 78.2014 -            int middle = (left + hi) >>> 1;
 78.2015 -            float middleValue = a[middle];
 78.2016 -
 78.2017 -            if (middleValue < 0.0f) {
 78.2018 -                left = middle + 1;
 78.2019 -            } else {
 78.2020 -                hi = middle;
 78.2021 -            }
 78.2022 -        }
 78.2023 -
 78.2024 -        /*
 78.2025 -         * Skip the last negative value (if any) or all leading negative zeros.
 78.2026 -         */
 78.2027 -        while (left <= right && Float.floatToRawIntBits(a[left]) < 0) {
 78.2028 -            ++left;
 78.2029 -        }
 78.2030 -
 78.2031 -        /*
 78.2032 -         * Move negative zeros to the beginning of the sub-range.
 78.2033 -         *
 78.2034 -         * Partitioning:
 78.2035 -         *
 78.2036 -         * +----------------------------------------------------+
 78.2037 -         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
 78.2038 -         * +----------------------------------------------------+
 78.2039 -         *              ^          ^         ^
 78.2040 -         *              |          |         |
 78.2041 -         *             left        p         k
 78.2042 -         *
 78.2043 -         * Invariants:
 78.2044 -         *
 78.2045 -         *   all in (*,  left)  <  0.0
 78.2046 -         *   all in [left,  p) == -0.0
 78.2047 -         *   all in [p,     k) ==  0.0
 78.2048 -         *   all in [k, right] >=  0.0
 78.2049 -         *
 78.2050 -         * Pointer k is the first index of ?-part.
 78.2051 -         */
 78.2052 -        for (int k = left, p = left - 1; ++k <= right; ) {
 78.2053 -            float ak = a[k];
 78.2054 -            if (ak != 0.0f) {
 78.2055 -                break;
 78.2056 -            }
 78.2057 -            if (Float.floatToRawIntBits(ak) < 0) { // ak is -0.0f
 78.2058 -                a[k] = 0.0f;
 78.2059 -                a[++p] = -0.0f;
 78.2060 -            }
 78.2061 -        }
 78.2062 -    }
 78.2063 -
 78.2064 -    /**
 78.2065 -     * Sorts the specified range of the array.
 78.2066 -     *
 78.2067 -     * @param a the array to be sorted
 78.2068 -     * @param left the index of the first element, inclusive, to be sorted
 78.2069 -     * @param right the index of the last element, inclusive, to be sorted
 78.2070 -     */
 78.2071 -    private static void doSort(float[] a, int left, int right) {
 78.2072 -        // Use Quicksort on small arrays
 78.2073 -        if (right - left < QUICKSORT_THRESHOLD) {
 78.2074 -            sort(a, left, right, true);
 78.2075 -            return;
 78.2076 -        }
 78.2077 -
 78.2078 -        /*
 78.2079 -         * Index run[i] is the start of i-th run
 78.2080 -         * (ascending or descending sequence).
 78.2081 -         */
 78.2082 -        int[] run = new int[MAX_RUN_COUNT + 1];
 78.2083 -        int count = 0; run[0] = left;
 78.2084 -
 78.2085 -        // Check if the array is nearly sorted
 78.2086 -        for (int k = left; k < right; run[count] = k) {
 78.2087 -            if (a[k] < a[k + 1]) { // ascending
 78.2088 -                while (++k <= right && a[k - 1] <= a[k]);
 78.2089 -            } else if (a[k] > a[k + 1]) { // descending
 78.2090 -                while (++k <= right && a[k - 1] >= a[k]);
 78.2091 -                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 78.2092 -                    float t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 78.2093 -                }
 78.2094 -            } else { // equal
 78.2095 -                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 78.2096 -                    if (--m == 0) {
 78.2097 -                        sort(a, left, right, true);
 78.2098 -                        return;
 78.2099 -                    }
 78.2100 -                }
 78.2101 -            }
 78.2102 -
 78.2103 -            /*
 78.2104 -             * The array is not highly structured,
 78.2105 -             * use Quicksort instead of merge sort.
 78.2106 -             */
 78.2107 -            if (++count == MAX_RUN_COUNT) {
 78.2108 -                sort(a, left, right, true);
 78.2109 -                return;
 78.2110 -            }
 78.2111 -        }
 78.2112 -
 78.2113 -        // Check special cases
 78.2114 -        if (run[count] == right++) { // The last run contains one element
 78.2115 -            run[++count] = right;
 78.2116 -        } else if (count == 1) { // The array is already sorted
 78.2117 -            return;
 78.2118 -        }
 78.2119 -
 78.2120 -        /*
 78.2121 -         * Create temporary array, which is used for merging.
 78.2122 -         * Implementation note: variable "right" is increased by 1.
 78.2123 -         */
 78.2124 -        float[] b; byte odd = 0;
 78.2125 -        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 78.2126 -
 78.2127 -        if (odd == 0) {
 78.2128 -            b = a; a = new float[b.length];
 78.2129 -            for (int i = left - 1; ++i < right; a[i] = b[i]);
 78.2130 -        } else {
 78.2131 -            b = new float[a.length];
 78.2132 -        }
 78.2133 -
 78.2134 -        // Merging
 78.2135 -        for (int last; count > 1; count = last) {
 78.2136 -            for (int k = (last = 0) + 2; k <= count; k += 2) {
 78.2137 -                int hi = run[k], mi = run[k - 1];
 78.2138 -                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 78.2139 -                    if (q >= hi || p < mi && a[p] <= a[q]) {
 78.2140 -                        b[i] = a[p++];
 78.2141 -                    } else {
 78.2142 -                        b[i] = a[q++];
 78.2143 -                    }
 78.2144 -                }
 78.2145 -                run[++last] = hi;
 78.2146 -            }
 78.2147 -            if ((count & 1) != 0) {
 78.2148 -                for (int i = right, lo = run[count - 1]; --i >= lo;
 78.2149 -                    b[i] = a[i]
 78.2150 -                );
 78.2151 -                run[++last] = right;
 78.2152 -            }
 78.2153 -            float[] t = a; a = b; b = t;
 78.2154 -        }
 78.2155 -    }
 78.2156 -
 78.2157 -    /**
 78.2158 -     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 78.2159 -     *
 78.2160 -     * @param a the array to be sorted
 78.2161 -     * @param left the index of the first element, inclusive, to be sorted
 78.2162 -     * @param right the index of the last element, inclusive, to be sorted
 78.2163 -     * @param leftmost indicates if this part is the leftmost in the range
 78.2164 -     */
 78.2165 -    private static void sort(float[] a, int left, int right, boolean leftmost) {
 78.2166 -        int length = right - left + 1;
 78.2167 -
 78.2168 -        // Use insertion sort on tiny arrays
 78.2169 -        if (length < INSERTION_SORT_THRESHOLD) {
 78.2170 -            if (leftmost) {
 78.2171 -                /*
 78.2172 -                 * Traditional (without sentinel) insertion sort,
 78.2173 -                 * optimized for server VM, is used in case of
 78.2174 -                 * the leftmost part.
 78.2175 -                 */
 78.2176 -                for (int i = left, j = i; i < right; j = ++i) {
 78.2177 -                    float ai = a[i + 1];
 78.2178 -                    while (ai < a[j]) {
 78.2179 -                        a[j + 1] = a[j];
 78.2180 -                        if (j-- == left) {
 78.2181 -                            break;
 78.2182 -                        }
 78.2183 -                    }
 78.2184 -                    a[j + 1] = ai;
 78.2185 -                }
 78.2186 -            } else {
 78.2187 -                /*
 78.2188 -                 * Skip the longest ascending sequence.
 78.2189 -                 */
 78.2190 -                do {
 78.2191 -                    if (left >= right) {
 78.2192 -                        return;
 78.2193 -                    }
 78.2194 -                } while (a[++left] >= a[left - 1]);
 78.2195 -
 78.2196 -                /*
 78.2197 -                 * Every element from adjoining part plays the role
 78.2198 -                 * of sentinel, therefore this allows us to avoid the
 78.2199 -                 * left range check on each iteration. Moreover, we use
 78.2200 -                 * the more optimized algorithm, so called pair insertion
 78.2201 -                 * sort, which is faster (in the context of Quicksort)
 78.2202 -                 * than traditional implementation of insertion sort.
 78.2203 -                 */
 78.2204 -                for (int k = left; ++left <= right; k = ++left) {
 78.2205 -                    float a1 = a[k], a2 = a[left];
 78.2206 -
 78.2207 -                    if (a1 < a2) {
 78.2208 -                        a2 = a1; a1 = a[left];
 78.2209 -                    }
 78.2210 -                    while (a1 < a[--k]) {
 78.2211 -                        a[k + 2] = a[k];
 78.2212 -                    }
 78.2213 -                    a[++k + 1] = a1;
 78.2214 -
 78.2215 -                    while (a2 < a[--k]) {
 78.2216 -                        a[k + 1] = a[k];
 78.2217 -                    }
 78.2218 -                    a[k + 1] = a2;
 78.2219 -                }
 78.2220 -                float last = a[right];
 78.2221 -
 78.2222 -                while (last < a[--right]) {
 78.2223 -                    a[right + 1] = a[right];
 78.2224 -                }
 78.2225 -                a[right + 1] = last;
 78.2226 -            }
 78.2227 -            return;
 78.2228 -        }
 78.2229 -
 78.2230 -        // Inexpensive approximation of length / 7
 78.2231 -        int seventh = (length >> 3) + (length >> 6) + 1;
 78.2232 -
 78.2233 -        /*
 78.2234 -         * Sort five evenly spaced elements around (and including) the
 78.2235 -         * center element in the range. These elements will be used for
 78.2236 -         * pivot selection as described below. The choice for spacing
 78.2237 -         * these elements was empirically determined to work well on
 78.2238 -         * a wide variety of inputs.
 78.2239 -         */
 78.2240 -        int e3 = (left + right) >>> 1; // The midpoint
 78.2241 -        int e2 = e3 - seventh;
 78.2242 -        int e1 = e2 - seventh;
 78.2243 -        int e4 = e3 + seventh;
 78.2244 -        int e5 = e4 + seventh;
 78.2245 -
 78.2246 -        // Sort these elements using insertion sort
 78.2247 -        if (a[e2] < a[e1]) { float t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 78.2248 -
 78.2249 -        if (a[e3] < a[e2]) { float t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 78.2250 -            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.2251 -        }
 78.2252 -        if (a[e4] < a[e3]) { float t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 78.2253 -            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.2254 -                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.2255 -            }
 78.2256 -        }
 78.2257 -        if (a[e5] < a[e4]) { float t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 78.2258 -            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 78.2259 -                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.2260 -                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.2261 -                }
 78.2262 -            }
 78.2263 -        }
 78.2264 -
 78.2265 -        // Pointers
 78.2266 -        int less  = left;  // The index of the first element of center part
 78.2267 -        int great = right; // The index before the first element of right part
 78.2268 -
 78.2269 -        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 78.2270 -            /*
 78.2271 -             * Use the second and fourth of the five sorted elements as pivots.
 78.2272 -             * These values are inexpensive approximations of the first and
 78.2273 -             * second terciles of the array. Note that pivot1 <= pivot2.
 78.2274 -             */
 78.2275 -            float pivot1 = a[e2];
 78.2276 -            float pivot2 = a[e4];
 78.2277 -
 78.2278 -            /*
 78.2279 -             * The first and the last elements to be sorted are moved to the
 78.2280 -             * locations formerly occupied by the pivots. When partitioning
 78.2281 -             * is complete, the pivots are swapped back into their final
 78.2282 -             * positions, and excluded from subsequent sorting.
 78.2283 -             */
 78.2284 -            a[e2] = a[left];
 78.2285 -            a[e4] = a[right];
 78.2286 -
 78.2287 -            /*
 78.2288 -             * Skip elements, which are less or greater than pivot values.
 78.2289 -             */
 78.2290 -            while (a[++less] < pivot1);
 78.2291 -            while (a[--great] > pivot2);
 78.2292 -
 78.2293 -            /*
 78.2294 -             * Partitioning:
 78.2295 -             *
 78.2296 -             *   left part           center part                   right part
 78.2297 -             * +--------------------------------------------------------------+
 78.2298 -             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 78.2299 -             * +--------------------------------------------------------------+
 78.2300 -             *               ^                          ^       ^
 78.2301 -             *               |                          |       |
 78.2302 -             *              less                        k     great
 78.2303 -             *
 78.2304 -             * Invariants:
 78.2305 -             *
 78.2306 -             *              all in (left, less)   < pivot1
 78.2307 -             *    pivot1 <= all in [less, k)     <= pivot2
 78.2308 -             *              all in (great, right) > pivot2
 78.2309 -             *
 78.2310 -             * Pointer k is the first index of ?-part.
 78.2311 -             */
 78.2312 -            outer:
 78.2313 -            for (int k = less - 1; ++k <= great; ) {
 78.2314 -                float ak = a[k];
 78.2315 -                if (ak < pivot1) { // Move a[k] to left part
 78.2316 -                    a[k] = a[less];
 78.2317 -                    /*
 78.2318 -                     * Here and below we use "a[i] = b; i++;" instead
 78.2319 -                     * of "a[i++] = b;" due to performance issue.
 78.2320 -                     */
 78.2321 -                    a[less] = ak;
 78.2322 -                    ++less;
 78.2323 -                } else if (ak > pivot2) { // Move a[k] to right part
 78.2324 -                    while (a[great] > pivot2) {
 78.2325 -                        if (great-- == k) {
 78.2326 -                            break outer;
 78.2327 -                        }
 78.2328 -                    }
 78.2329 -                    if (a[great] < pivot1) { // a[great] <= pivot2
 78.2330 -                        a[k] = a[less];
 78.2331 -                        a[less] = a[great];
 78.2332 -                        ++less;
 78.2333 -                    } else { // pivot1 <= a[great] <= pivot2
 78.2334 -                        a[k] = a[great];
 78.2335 -                    }
 78.2336 -                    /*
 78.2337 -                     * Here and below we use "a[i] = b; i--;" instead
 78.2338 -                     * of "a[i--] = b;" due to performance issue.
 78.2339 -                     */
 78.2340 -                    a[great] = ak;
 78.2341 -                    --great;
 78.2342 -                }
 78.2343 -            }
 78.2344 -
 78.2345 -            // Swap pivots into their final positions
 78.2346 -            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 78.2347 -            a[right] = a[great + 1]; a[great + 1] = pivot2;
 78.2348 -
 78.2349 -            // Sort left and right parts recursively, excluding known pivots
 78.2350 -            sort(a, left, less - 2, leftmost);
 78.2351 -            sort(a, great + 2, right, false);
 78.2352 -
 78.2353 -            /*
 78.2354 -             * If center part is too large (comprises > 4/7 of the array),
 78.2355 -             * swap internal pivot values to ends.
 78.2356 -             */
 78.2357 -            if (less < e1 && e5 < great) {
 78.2358 -                /*
 78.2359 -                 * Skip elements, which are equal to pivot values.
 78.2360 -                 */
 78.2361 -                while (a[less] == pivot1) {
 78.2362 -                    ++less;
 78.2363 -                }
 78.2364 -
 78.2365 -                while (a[great] == pivot2) {
 78.2366 -                    --great;
 78.2367 -                }
 78.2368 -
 78.2369 -                /*
 78.2370 -                 * Partitioning:
 78.2371 -                 *
 78.2372 -                 *   left part         center part                  right part
 78.2373 -                 * +----------------------------------------------------------+
 78.2374 -                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 78.2375 -                 * +----------------------------------------------------------+
 78.2376 -                 *              ^                        ^       ^
 78.2377 -                 *              |                        |       |
 78.2378 -                 *             less                      k     great
 78.2379 -                 *
 78.2380 -                 * Invariants:
 78.2381 -                 *
 78.2382 -                 *              all in (*,  less) == pivot1
 78.2383 -                 *     pivot1 < all in [less,  k)  < pivot2
 78.2384 -                 *              all in (great, *) == pivot2
 78.2385 -                 *
 78.2386 -                 * Pointer k is the first index of ?-part.
 78.2387 -                 */
 78.2388 -                outer:
 78.2389 -                for (int k = less - 1; ++k <= great; ) {
 78.2390 -                    float ak = a[k];
 78.2391 -                    if (ak == pivot1) { // Move a[k] to left part
 78.2392 -                        a[k] = a[less];
 78.2393 -                        a[less] = ak;
 78.2394 -                        ++less;
 78.2395 -                    } else if (ak == pivot2) { // Move a[k] to right part
 78.2396 -                        while (a[great] == pivot2) {
 78.2397 -                            if (great-- == k) {
 78.2398 -                                break outer;
 78.2399 -                            }
 78.2400 -                        }
 78.2401 -                        if (a[great] == pivot1) { // a[great] < pivot2
 78.2402 -                            a[k] = a[less];
 78.2403 -                            /*
 78.2404 -                             * Even though a[great] equals to pivot1, the
 78.2405 -                             * assignment a[less] = pivot1 may be incorrect,
 78.2406 -                             * if a[great] and pivot1 are floating-point zeros
 78.2407 -                             * of different signs. Therefore in float and
 78.2408 -                             * double sorting methods we have to use more
 78.2409 -                             * accurate assignment a[less] = a[great].
 78.2410 -                             */
 78.2411 -                            a[less] = a[great];
 78.2412 -                            ++less;
 78.2413 -                        } else { // pivot1 < a[great] < pivot2
 78.2414 -                            a[k] = a[great];
 78.2415 -                        }
 78.2416 -                        a[great] = ak;
 78.2417 -                        --great;
 78.2418 -                    }
 78.2419 -                }
 78.2420 -            }
 78.2421 -
 78.2422 -            // Sort center part recursively
 78.2423 -            sort(a, less, great, false);
 78.2424 -
 78.2425 -        } else { // Partitioning with one pivot
 78.2426 -            /*
 78.2427 -             * Use the third of the five sorted elements as pivot.
 78.2428 -             * This value is inexpensive approximation of the median.
 78.2429 -             */
 78.2430 -            float pivot = a[e3];
 78.2431 -
 78.2432 -            /*
 78.2433 -             * Partitioning degenerates to the traditional 3-way
 78.2434 -             * (or "Dutch National Flag") schema:
 78.2435 -             *
 78.2436 -             *   left part    center part              right part
 78.2437 -             * +-------------------------------------------------+
 78.2438 -             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 78.2439 -             * +-------------------------------------------------+
 78.2440 -             *              ^              ^        ^
 78.2441 -             *              |              |        |
 78.2442 -             *             less            k      great
 78.2443 -             *
 78.2444 -             * Invariants:
 78.2445 -             *
 78.2446 -             *   all in (left, less)   < pivot
 78.2447 -             *   all in [less, k)     == pivot
 78.2448 -             *   all in (great, right) > pivot
 78.2449 -             *
 78.2450 -             * Pointer k is the first index of ?-part.
 78.2451 -             */
 78.2452 -            for (int k = less; k <= great; ++k) {
 78.2453 -                if (a[k] == pivot) {
 78.2454 -                    continue;
 78.2455 -                }
 78.2456 -                float ak = a[k];
 78.2457 -                if (ak < pivot) { // Move a[k] to left part
 78.2458 -                    a[k] = a[less];
 78.2459 -                    a[less] = ak;
 78.2460 -                    ++less;
 78.2461 -                } else { // a[k] > pivot - Move a[k] to right part
 78.2462 -                    while (a[great] > pivot) {
 78.2463 -                        --great;
 78.2464 -                    }
 78.2465 -                    if (a[great] < pivot) { // a[great] <= pivot
 78.2466 -                        a[k] = a[less];
 78.2467 -                        a[less] = a[great];
 78.2468 -                        ++less;
 78.2469 -                    } else { // a[great] == pivot
 78.2470 -                        /*
 78.2471 -                         * Even though a[great] equals to pivot, the
 78.2472 -                         * assignment a[k] = pivot may be incorrect,
 78.2473 -                         * if a[great] and pivot are floating-point
 78.2474 -                         * zeros of different signs. Therefore in float
 78.2475 -                         * and double sorting methods we have to use
 78.2476 -                         * more accurate assignment a[k] = a[great].
 78.2477 -                         */
 78.2478 -                        a[k] = a[great];
 78.2479 -                    }
 78.2480 -                    a[great] = ak;
 78.2481 -                    --great;
 78.2482 -                }
 78.2483 -            }
 78.2484 -
 78.2485 -            /*
 78.2486 -             * Sort left and right parts recursively.
 78.2487 -             * All elements from center part are equal
 78.2488 -             * and, therefore, already sorted.
 78.2489 -             */
 78.2490 -            sort(a, left, less - 1, leftmost);
 78.2491 -            sort(a, great + 1, right, false);
 78.2492 -        }
 78.2493 -    }
 78.2494 -
 78.2495 -    /**
 78.2496 -     * Sorts the specified array.
 78.2497 -     *
 78.2498 -     * @param a the array to be sorted
 78.2499 -     */
 78.2500 -    public static void sort(double[] a) {
 78.2501 -        sort(a, 0, a.length - 1);
 78.2502 -    }
 78.2503 -
 78.2504 -    /**
 78.2505 -     * Sorts the specified range of the array.
 78.2506 -     *
 78.2507 -     * @param a the array to be sorted
 78.2508 -     * @param left the index of the first element, inclusive, to be sorted
 78.2509 -     * @param right the index of the last element, inclusive, to be sorted
 78.2510 -     */
 78.2511 -    public static void sort(double[] a, int left, int right) {
 78.2512 -        /*
 78.2513 -         * Phase 1: Move NaNs to the end of the array.
 78.2514 -         */
 78.2515 -        while (left <= right && Double.isNaN(a[right])) {
 78.2516 -            --right;
 78.2517 -        }
 78.2518 -        for (int k = right; --k >= left; ) {
 78.2519 -            double ak = a[k];
 78.2520 -            if (ak != ak) { // a[k] is NaN
 78.2521 -                a[k] = a[right];
 78.2522 -                a[right] = ak;
 78.2523 -                --right;
 78.2524 -            }
 78.2525 -        }
 78.2526 -
 78.2527 -        /*
 78.2528 -         * Phase 2: Sort everything except NaNs (which are already in place).
 78.2529 -         */
 78.2530 -        doSort(a, left, right);
 78.2531 -
 78.2532 -        /*
 78.2533 -         * Phase 3: Place negative zeros before positive zeros.
 78.2534 -         */
 78.2535 -        int hi = right;
 78.2536 -
 78.2537 -        /*
 78.2538 -         * Find the first zero, or first positive, or last negative element.
 78.2539 -         */
 78.2540 -        while (left < hi) {
 78.2541 -            int middle = (left + hi) >>> 1;
 78.2542 -            double middleValue = a[middle];
 78.2543 -
 78.2544 -            if (middleValue < 0.0d) {
 78.2545 -                left = middle + 1;
 78.2546 -            } else {
 78.2547 -                hi = middle;
 78.2548 -            }
 78.2549 -        }
 78.2550 -
 78.2551 -        /*
 78.2552 -         * Skip the last negative value (if any) or all leading negative zeros.
 78.2553 -         */
 78.2554 -        while (left <= right && Double.doubleToRawLongBits(a[left]) < 0) {
 78.2555 -            ++left;
 78.2556 -        }
 78.2557 -
 78.2558 -        /*
 78.2559 -         * Move negative zeros to the beginning of the sub-range.
 78.2560 -         *
 78.2561 -         * Partitioning:
 78.2562 -         *
 78.2563 -         * +----------------------------------------------------+
 78.2564 -         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
 78.2565 -         * +----------------------------------------------------+
 78.2566 -         *              ^          ^         ^
 78.2567 -         *              |          |         |
 78.2568 -         *             left        p         k
 78.2569 -         *
 78.2570 -         * Invariants:
 78.2571 -         *
 78.2572 -         *   all in (*,  left)  <  0.0
 78.2573 -         *   all in [left,  p) == -0.0
 78.2574 -         *   all in [p,     k) ==  0.0
 78.2575 -         *   all in [k, right] >=  0.0
 78.2576 -         *
 78.2577 -         * Pointer k is the first index of ?-part.
 78.2578 -         */
 78.2579 -        for (int k = left, p = left - 1; ++k <= right; ) {
 78.2580 -            double ak = a[k];
 78.2581 -            if (ak != 0.0d) {
 78.2582 -                break;
 78.2583 -            }
 78.2584 -            if (Double.doubleToRawLongBits(ak) < 0) { // ak is -0.0d
 78.2585 -                a[k] = 0.0d;
 78.2586 -                a[++p] = -0.0d;
 78.2587 -            }
 78.2588 -        }
 78.2589 -    }
 78.2590 -
 78.2591 -    /**
 78.2592 -     * Sorts the specified range of the array.
 78.2593 -     *
 78.2594 -     * @param a the array to be sorted
 78.2595 -     * @param left the index of the first element, inclusive, to be sorted
 78.2596 -     * @param right the index of the last element, inclusive, to be sorted
 78.2597 -     */
 78.2598 -    private static void doSort(double[] a, int left, int right) {
 78.2599 -        // Use Quicksort on small arrays
 78.2600 -        if (right - left < QUICKSORT_THRESHOLD) {
 78.2601 -            sort(a, left, right, true);
 78.2602 -            return;
 78.2603 -        }
 78.2604 -
 78.2605 -        /*
 78.2606 -         * Index run[i] is the start of i-th run
 78.2607 -         * (ascending or descending sequence).
 78.2608 -         */
 78.2609 -        int[] run = new int[MAX_RUN_COUNT + 1];
 78.2610 -        int count = 0; run[0] = left;
 78.2611 -
 78.2612 -        // Check if the array is nearly sorted
 78.2613 -        for (int k = left; k < right; run[count] = k) {
 78.2614 -            if (a[k] < a[k + 1]) { // ascending
 78.2615 -                while (++k <= right && a[k - 1] <= a[k]);
 78.2616 -            } else if (a[k] > a[k + 1]) { // descending
 78.2617 -                while (++k <= right && a[k - 1] >= a[k]);
 78.2618 -                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 78.2619 -                    double t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 78.2620 -                }
 78.2621 -            } else { // equal
 78.2622 -                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 78.2623 -                    if (--m == 0) {
 78.2624 -                        sort(a, left, right, true);
 78.2625 -                        return;
 78.2626 -                    }
 78.2627 -                }
 78.2628 -            }
 78.2629 -
 78.2630 -            /*
 78.2631 -             * The array is not highly structured,
 78.2632 -             * use Quicksort instead of merge sort.
 78.2633 -             */
 78.2634 -            if (++count == MAX_RUN_COUNT) {
 78.2635 -                sort(a, left, right, true);
 78.2636 -                return;
 78.2637 -            }
 78.2638 -        }
 78.2639 -
 78.2640 -        // Check special cases
 78.2641 -        if (run[count] == right++) { // The last run contains one element
 78.2642 -            run[++count] = right;
 78.2643 -        } else if (count == 1) { // The array is already sorted
 78.2644 -            return;
 78.2645 -        }
 78.2646 -
 78.2647 -        /*
 78.2648 -         * Create temporary array, which is used for merging.
 78.2649 -         * Implementation note: variable "right" is increased by 1.
 78.2650 -         */
 78.2651 -        double[] b; byte odd = 0;
 78.2652 -        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 78.2653 -
 78.2654 -        if (odd == 0) {
 78.2655 -            b = a; a = new double[b.length];
 78.2656 -            for (int i = left - 1; ++i < right; a[i] = b[i]);
 78.2657 -        } else {
 78.2658 -            b = new double[a.length];
 78.2659 -        }
 78.2660 -
 78.2661 -        // Merging
 78.2662 -        for (int last; count > 1; count = last) {
 78.2663 -            for (int k = (last = 0) + 2; k <= count; k += 2) {
 78.2664 -                int hi = run[k], mi = run[k - 1];
 78.2665 -                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 78.2666 -                    if (q >= hi || p < mi && a[p] <= a[q]) {
 78.2667 -                        b[i] = a[p++];
 78.2668 -                    } else {
 78.2669 -                        b[i] = a[q++];
 78.2670 -                    }
 78.2671 -                }
 78.2672 -                run[++last] = hi;
 78.2673 -            }
 78.2674 -            if ((count & 1) != 0) {
 78.2675 -                for (int i = right, lo = run[count - 1]; --i >= lo;
 78.2676 -                    b[i] = a[i]
 78.2677 -                );
 78.2678 -                run[++last] = right;
 78.2679 -            }
 78.2680 -            double[] t = a; a = b; b = t;
 78.2681 -        }
 78.2682 -    }
 78.2683 -
 78.2684 -    /**
 78.2685 -     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 78.2686 -     *
 78.2687 -     * @param a the array to be sorted
 78.2688 -     * @param left the index of the first element, inclusive, to be sorted
 78.2689 -     * @param right the index of the last element, inclusive, to be sorted
 78.2690 -     * @param leftmost indicates if this part is the leftmost in the range
 78.2691 -     */
 78.2692 -    private static void sort(double[] a, int left, int right, boolean leftmost) {
 78.2693 -        int length = right - left + 1;
 78.2694 -
 78.2695 -        // Use insertion sort on tiny arrays
 78.2696 -        if (length < INSERTION_SORT_THRESHOLD) {
 78.2697 -            if (leftmost) {
 78.2698 -                /*
 78.2699 -                 * Traditional (without sentinel) insertion sort,
 78.2700 -                 * optimized for server VM, is used in case of
 78.2701 -                 * the leftmost part.
 78.2702 -                 */
 78.2703 -                for (int i = left, j = i; i < right; j = ++i) {
 78.2704 -                    double ai = a[i + 1];
 78.2705 -                    while (ai < a[j]) {
 78.2706 -                        a[j + 1] = a[j];
 78.2707 -                        if (j-- == left) {
 78.2708 -                            break;
 78.2709 -                        }
 78.2710 -                    }
 78.2711 -                    a[j + 1] = ai;
 78.2712 -                }
 78.2713 -            } else {
 78.2714 -                /*
 78.2715 -                 * Skip the longest ascending sequence.
 78.2716 -                 */
 78.2717 -                do {
 78.2718 -                    if (left >= right) {
 78.2719 -                        return;
 78.2720 -                    }
 78.2721 -                } while (a[++left] >= a[left - 1]);
 78.2722 -
 78.2723 -                /*
 78.2724 -                 * Every element from adjoining part plays the role
 78.2725 -                 * of sentinel, therefore this allows us to avoid the
 78.2726 -                 * left range check on each iteration. Moreover, we use
 78.2727 -                 * the more optimized algorithm, so called pair insertion
 78.2728 -                 * sort, which is faster (in the context of Quicksort)
 78.2729 -                 * than traditional implementation of insertion sort.
 78.2730 -                 */
 78.2731 -                for (int k = left; ++left <= right; k = ++left) {
 78.2732 -                    double a1 = a[k], a2 = a[left];
 78.2733 -
 78.2734 -                    if (a1 < a2) {
 78.2735 -                        a2 = a1; a1 = a[left];
 78.2736 -                    }
 78.2737 -                    while (a1 < a[--k]) {
 78.2738 -                        a[k + 2] = a[k];
 78.2739 -                    }
 78.2740 -                    a[++k + 1] = a1;
 78.2741 -
 78.2742 -                    while (a2 < a[--k]) {
 78.2743 -                        a[k + 1] = a[k];
 78.2744 -                    }
 78.2745 -                    a[k + 1] = a2;
 78.2746 -                }
 78.2747 -                double last = a[right];
 78.2748 -
 78.2749 -                while (last < a[--right]) {
 78.2750 -                    a[right + 1] = a[right];
 78.2751 -                }
 78.2752 -                a[right + 1] = last;
 78.2753 -            }
 78.2754 -            return;
 78.2755 -        }
 78.2756 -
 78.2757 -        // Inexpensive approximation of length / 7
 78.2758 -        int seventh = (length >> 3) + (length >> 6) + 1;
 78.2759 -
 78.2760 -        /*
 78.2761 -         * Sort five evenly spaced elements around (and including) the
 78.2762 -         * center element in the range. These elements will be used for
 78.2763 -         * pivot selection as described below. The choice for spacing
 78.2764 -         * these elements was empirically determined to work well on
 78.2765 -         * a wide variety of inputs.
 78.2766 -         */
 78.2767 -        int e3 = (left + right) >>> 1; // The midpoint
 78.2768 -        int e2 = e3 - seventh;
 78.2769 -        int e1 = e2 - seventh;
 78.2770 -        int e4 = e3 + seventh;
 78.2771 -        int e5 = e4 + seventh;
 78.2772 -
 78.2773 -        // Sort these elements using insertion sort
 78.2774 -        if (a[e2] < a[e1]) { double t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 78.2775 -
 78.2776 -        if (a[e3] < a[e2]) { double t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 78.2777 -            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.2778 -        }
 78.2779 -        if (a[e4] < a[e3]) { double t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 78.2780 -            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.2781 -                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.2782 -            }
 78.2783 -        }
 78.2784 -        if (a[e5] < a[e4]) { double t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 78.2785 -            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 78.2786 -                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 78.2787 -                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 78.2788 -                }
 78.2789 -            }
 78.2790 -        }
 78.2791 -
 78.2792 -        // Pointers
 78.2793 -        int less  = left;  // The index of the first element of center part
 78.2794 -        int great = right; // The index before the first element of right part
 78.2795 -
 78.2796 -        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 78.2797 -            /*
 78.2798 -             * Use the second and fourth of the five sorted elements as pivots.
 78.2799 -             * These values are inexpensive approximations of the first and
 78.2800 -             * second terciles of the array. Note that pivot1 <= pivot2.
 78.2801 -             */
 78.2802 -            double pivot1 = a[e2];
 78.2803 -            double pivot2 = a[e4];
 78.2804 -
 78.2805 -            /*
 78.2806 -             * The first and the last elements to be sorted are moved to the
 78.2807 -             * locations formerly occupied by the pivots. When partitioning
 78.2808 -             * is complete, the pivots are swapped back into their final
 78.2809 -             * positions, and excluded from subsequent sorting.
 78.2810 -             */
 78.2811 -            a[e2] = a[left];
 78.2812 -            a[e4] = a[right];
 78.2813 -
 78.2814 -            /*
 78.2815 -             * Skip elements, which are less or greater than pivot values.
 78.2816 -             */
 78.2817 -            while (a[++less] < pivot1);
 78.2818 -            while (a[--great] > pivot2);
 78.2819 -
 78.2820 -            /*
 78.2821 -             * Partitioning:
 78.2822 -             *
 78.2823 -             *   left part           center part                   right part
 78.2824 -             * +--------------------------------------------------------------+
 78.2825 -             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 78.2826 -             * +--------------------------------------------------------------+
 78.2827 -             *               ^                          ^       ^
 78.2828 -             *               |                          |       |
 78.2829 -             *              less                        k     great
 78.2830 -             *
 78.2831 -             * Invariants:
 78.2832 -             *
 78.2833 -             *              all in (left, less)   < pivot1
 78.2834 -             *    pivot1 <= all in [less, k)     <= pivot2
 78.2835 -             *              all in (great, right) > pivot2
 78.2836 -             *
 78.2837 -             * Pointer k is the first index of ?-part.
 78.2838 -             */
 78.2839 -            outer:
 78.2840 -            for (int k = less - 1; ++k <= great; ) {
 78.2841 -                double ak = a[k];
 78.2842 -                if (ak < pivot1) { // Move a[k] to left part
 78.2843 -                    a[k] = a[less];
 78.2844 -                    /*
 78.2845 -                     * Here and below we use "a[i] = b; i++;" instead
 78.2846 -                     * of "a[i++] = b;" due to performance issue.
 78.2847 -                     */
 78.2848 -                    a[less] = ak;
 78.2849 -                    ++less;
 78.2850 -                } else if (ak > pivot2) { // Move a[k] to right part
 78.2851 -                    while (a[great] > pivot2) {
 78.2852 -                        if (great-- == k) {
 78.2853 -                            break outer;
 78.2854 -                        }
 78.2855 -                    }
 78.2856 -                    if (a[great] < pivot1) { // a[great] <= pivot2
 78.2857 -                        a[k] = a[less];
 78.2858 -                        a[less] = a[great];
 78.2859 -                        ++less;
 78.2860 -                    } else { // pivot1 <= a[great] <= pivot2
 78.2861 -                        a[k] = a[great];
 78.2862 -                    }
 78.2863 -                    /*
 78.2864 -                     * Here and below we use "a[i] = b; i--;" instead
 78.2865 -                     * of "a[i--] = b;" due to performance issue.
 78.2866 -                     */
 78.2867 -                    a[great] = ak;
 78.2868 -                    --great;
 78.2869 -                }
 78.2870 -            }
 78.2871 -
 78.2872 -            // Swap pivots into their final positions
 78.2873 -            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 78.2874 -            a[right] = a[great + 1]; a[great + 1] = pivot2;
 78.2875 -
 78.2876 -            // Sort left and right parts recursively, excluding known pivots
 78.2877 -            sort(a, left, less - 2, leftmost);
 78.2878 -            sort(a, great + 2, right, false);
 78.2879 -
 78.2880 -            /*
 78.2881 -             * If center part is too large (comprises > 4/7 of the array),
 78.2882 -             * swap internal pivot values to ends.
 78.2883 -             */
 78.2884 -            if (less < e1 && e5 < great) {
 78.2885 -                /*
 78.2886 -                 * Skip elements, which are equal to pivot values.
 78.2887 -                 */
 78.2888 -                while (a[less] == pivot1) {
 78.2889 -                    ++less;
 78.2890 -                }
 78.2891 -
 78.2892 -                while (a[great] == pivot2) {
 78.2893 -                    --great;
 78.2894 -                }
 78.2895 -
 78.2896 -                /*
 78.2897 -                 * Partitioning:
 78.2898 -                 *
 78.2899 -                 *   left part         center part                  right part
 78.2900 -                 * +----------------------------------------------------------+
 78.2901 -                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 78.2902 -                 * +----------------------------------------------------------+
 78.2903 -                 *              ^                        ^       ^
 78.2904 -                 *              |                        |       |
 78.2905 -                 *             less                      k     great
 78.2906 -                 *
 78.2907 -                 * Invariants:
 78.2908 -                 *
 78.2909 -                 *              all in (*,  less) == pivot1
 78.2910 -                 *     pivot1 < all in [less,  k)  < pivot2
 78.2911 -                 *              all in (great, *) == pivot2
 78.2912 -                 *
 78.2913 -                 * Pointer k is the first index of ?-part.
 78.2914 -                 */
 78.2915 -                outer:
 78.2916 -                for (int k = less - 1; ++k <= great; ) {
 78.2917 -                    double ak = a[k];
 78.2918 -                    if (ak == pivot1) { // Move a[k] to left part
 78.2919 -                        a[k] = a[less];
 78.2920 -                        a[less] = ak;
 78.2921 -                        ++less;
 78.2922 -                    } else if (ak == pivot2) { // Move a[k] to right part
 78.2923 -                        while (a[great] == pivot2) {
 78.2924 -                            if (great-- == k) {
 78.2925 -                                break outer;
 78.2926 -                            }
 78.2927 -                        }
 78.2928 -                        if (a[great] == pivot1) { // a[great] < pivot2
 78.2929 -                            a[k] = a[less];
 78.2930 -                            /*
 78.2931 -                             * Even though a[great] equals to pivot1, the
 78.2932 -                             * assignment a[less] = pivot1 may be incorrect,
 78.2933 -                             * if a[great] and pivot1 are floating-point zeros
 78.2934 -                             * of different signs. Therefore in float and
 78.2935 -                             * double sorting methods we have to use more
 78.2936 -                             * accurate assignment a[less] = a[great].
 78.2937 -                             */
 78.2938 -                            a[less] = a[great];
 78.2939 -                            ++less;
 78.2940 -                        } else { // pivot1 < a[great] < pivot2
 78.2941 -                            a[k] = a[great];
 78.2942 -                        }
 78.2943 -                        a[great] = ak;
 78.2944 -                        --great;
 78.2945 -                    }
 78.2946 -                }
 78.2947 -            }
 78.2948 -
 78.2949 -            // Sort center part recursively
 78.2950 -            sort(a, less, great, false);
 78.2951 -
 78.2952 -        } else { // Partitioning with one pivot
 78.2953 -            /*
 78.2954 -             * Use the third of the five sorted elements as pivot.
 78.2955 -             * This value is inexpensive approximation of the median.
 78.2956 -             */
 78.2957 -            double pivot = a[e3];
 78.2958 -
 78.2959 -            /*
 78.2960 -             * Partitioning degenerates to the traditional 3-way
 78.2961 -             * (or "Dutch National Flag") schema:
 78.2962 -             *
 78.2963 -             *   left part    center part              right part
 78.2964 -             * +-------------------------------------------------+
 78.2965 -             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 78.2966 -             * +-------------------------------------------------+
 78.2967 -             *              ^              ^        ^
 78.2968 -             *              |              |        |
 78.2969 -             *             less            k      great
 78.2970 -             *
 78.2971 -             * Invariants:
 78.2972 -             *
 78.2973 -             *   all in (left, less)   < pivot
 78.2974 -             *   all in [less, k)     == pivot
 78.2975 -             *   all in (great, right) > pivot
 78.2976 -             *
 78.2977 -             * Pointer k is the first index of ?-part.
 78.2978 -             */
 78.2979 -            for (int k = less; k <= great; ++k) {
 78.2980 -                if (a[k] == pivot) {
 78.2981 -                    continue;
 78.2982 -                }
 78.2983 -                double ak = a[k];
 78.2984 -                if (ak < pivot) { // Move a[k] to left part
 78.2985 -                    a[k] = a[less];
 78.2986 -                    a[less] = ak;
 78.2987 -                    ++less;
 78.2988 -                } else { // a[k] > pivot - Move a[k] to right part
 78.2989 -                    while (a[great] > pivot) {
 78.2990 -                        --great;
 78.2991 -                    }
 78.2992 -                    if (a[great] < pivot) { // a[great] <= pivot
 78.2993 -                        a[k] = a[less];
 78.2994 -                        a[less] = a[great];
 78.2995 -                        ++less;
 78.2996 -                    } else { // a[great] == pivot
 78.2997 -                        /*
 78.2998 -                         * Even though a[great] equals to pivot, the
 78.2999 -                         * assignment a[k] = pivot may be incorrect,
 78.3000 -                         * if a[great] and pivot are floating-point
 78.3001 -                         * zeros of different signs. Therefore in float
 78.3002 -                         * and double sorting methods we have to use
 78.3003 -                         * more accurate assignment a[k] = a[great].
 78.3004 -                         */
 78.3005 -                        a[k] = a[great];
 78.3006 -                    }
 78.3007 -                    a[great] = ak;
 78.3008 -                    --great;
 78.3009 -                }
 78.3010 -            }
 78.3011 -
 78.3012 -            /*
 78.3013 -             * Sort left and right parts recursively.
 78.3014 -             * All elements from center part are equal
 78.3015 -             * and, therefore, already sorted.
 78.3016 -             */
 78.3017 -            sort(a, left, less - 1, leftmost);
 78.3018 -            sort(a, great + 1, right, false);
 78.3019 -        }
 78.3020 -    }
 78.3021 -}
    79.1 --- a/emul/compact/src/main/java/java/util/EmptyStackException.java	Mon Feb 25 19:00:08 2013 +0100
    79.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.3 @@ -1,46 +0,0 @@
    79.4 -/*
    79.5 - * Copyright (c) 1994, 2008, 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 - * Thrown by methods in the <code>Stack</code> class to indicate
   79.33 - * that the stack is empty.
   79.34 - *
   79.35 - * @author  Jonathan Payne
   79.36 - * @see     java.util.Stack
   79.37 - * @since   JDK1.0
   79.38 - */
   79.39 -public
   79.40 -class EmptyStackException extends RuntimeException {
   79.41 -    private static final long serialVersionUID = 5084686378493302095L;
   79.42 -
   79.43 -    /**
   79.44 -     * Constructs a new <code>EmptyStackException</code> with <tt>null</tt>
   79.45 -     * as its error message string.
   79.46 -     */
   79.47 -    public EmptyStackException() {
   79.48 -    }
   79.49 -}
    80.1 --- a/emul/compact/src/main/java/java/util/EventListener.java	Mon Feb 25 19:00:08 2013 +0100
    80.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.3 @@ -1,33 +0,0 @@
    80.4 -/*
    80.5 - * Copyright (c) 1996, 1999, 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 tagging interface that all event listener interfaces must extend.
   80.33 - * @since JDK1.1
   80.34 - */
   80.35 -public interface EventListener {
   80.36 -}
    81.1 --- a/emul/compact/src/main/java/java/util/EventListenerProxy.java	Mon Feb 25 19:00:08 2013 +0100
    81.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.3 @@ -1,75 +0,0 @@
    81.4 -/*
    81.5 - * Copyright (c) 2000, 2004, 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 - * An abstract wrapper class for an {@code EventListener} class
   81.33 - * which associates a set of additional parameters with the listener.
   81.34 - * Subclasses must provide the storage and accessor methods
   81.35 - * for the additional arguments or parameters.
   81.36 - * <p>
   81.37 - * For example, a bean which supports named properties
   81.38 - * would have a two argument method signature for adding
   81.39 - * a {@code PropertyChangeListener} for a property:
   81.40 - * <pre>
   81.41 - * public void addPropertyChangeListener(String propertyName,
   81.42 - *                                       PropertyChangeListener listener)
   81.43 - * </pre>
   81.44 - * If the bean also implemented the zero argument get listener method:
   81.45 - * <pre>
   81.46 - * public PropertyChangeListener[] getPropertyChangeListeners()
   81.47 - * </pre>
   81.48 - * then the array may contain inner {@code PropertyChangeListeners}
   81.49 - * which are also {@code PropertyChangeListenerProxy} objects.
   81.50 - * <p>
   81.51 - * If the calling method is interested in retrieving the named property
   81.52 - * then it would have to test the element to see if it is a proxy class.
   81.53 - *
   81.54 - * @since 1.4
   81.55 - */
   81.56 -public abstract class EventListenerProxy<T extends EventListener>
   81.57 -        implements EventListener {
   81.58 -
   81.59 -    private final T listener;
   81.60 -
   81.61 -    /**
   81.62 -     * Creates a proxy for the specified listener.
   81.63 -     *
   81.64 -     * @param listener  the listener object
   81.65 -     */
   81.66 -    public EventListenerProxy(T listener) {
   81.67 -        this.listener = listener;
   81.68 -    }
   81.69 -
   81.70 -    /**
   81.71 -     * Returns the listener associated with the proxy.
   81.72 -     *
   81.73 -     * @return  the listener associated with the proxy
   81.74 -     */
   81.75 -    public T getListener() {
   81.76 -        return this.listener;
   81.77 -    }
   81.78 -}
    82.1 --- a/emul/compact/src/main/java/java/util/EventObject.java	Mon Feb 25 19:00:08 2013 +0100
    82.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.3 @@ -1,78 +0,0 @@
    82.4 -/*
    82.5 - * Copyright (c) 1996, 2003, 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 -/**
   82.32 - * <p>
   82.33 - * The root class from which all event state objects shall be derived.
   82.34 - * <p>
   82.35 - * All Events are constructed with a reference to the object, the "source",
   82.36 - * that is logically deemed to be the object upon which the Event in question
   82.37 - * initially occurred upon.
   82.38 - *
   82.39 - * @since JDK1.1
   82.40 - */
   82.41 -
   82.42 -public class EventObject implements java.io.Serializable {
   82.43 -
   82.44 -    private static final long serialVersionUID = 5516075349620653480L;
   82.45 -
   82.46 -    /**
   82.47 -     * The object on which the Event initially occurred.
   82.48 -     */
   82.49 -    protected transient Object  source;
   82.50 -
   82.51 -    /**
   82.52 -     * Constructs a prototypical Event.
   82.53 -     *
   82.54 -     * @param    source    The object on which the Event initially occurred.
   82.55 -     * @exception  IllegalArgumentException  if source is null.
   82.56 -     */
   82.57 -    public EventObject(Object source) {
   82.58 -        if (source == null)
   82.59 -            throw new IllegalArgumentException("null source");
   82.60 -
   82.61 -        this.source = source;
   82.62 -    }
   82.63 -
   82.64 -    /**
   82.65 -     * The object on which the Event initially occurred.
   82.66 -     *
   82.67 -     * @return   The object on which the Event initially occurred.
   82.68 -     */
   82.69 -    public Object getSource() {
   82.70 -        return source;
   82.71 -    }
   82.72 -
   82.73 -    /**
   82.74 -     * Returns a String representation of this EventObject.
   82.75 -     *
   82.76 -     * @return  A a String representation of this EventObject.
   82.77 -     */
   82.78 -    public String toString() {
   82.79 -        return getClass().getName() + "[source=" + source + "]";
   82.80 -    }
   82.81 -}
    83.1 --- a/emul/compact/src/main/java/java/util/HashMap.java	Mon Feb 25 19:00:08 2013 +0100
    83.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.3 @@ -1,990 +0,0 @@
    83.4 -/*
    83.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    83.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    83.7 - *
    83.8 - * This code is free software; you can redistribute it and/or modify it
    83.9 - * under the terms of the GNU General Public License version 2 only, as
   83.10 - * published by the Free Software Foundation.  Oracle designates this
   83.11 - * particular file as subject to the "Classpath" exception as provided
   83.12 - * by Oracle in the LICENSE file that accompanied this code.
   83.13 - *
   83.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   83.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   83.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   83.17 - * version 2 for more details (a copy is included in the LICENSE file that
   83.18 - * accompanied this code).
   83.19 - *
   83.20 - * You should have received a copy of the GNU General Public License version
   83.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   83.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   83.23 - *
   83.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   83.25 - * or visit www.oracle.com if you need additional information or have any
   83.26 - * questions.
   83.27 - */
   83.28 -
   83.29 -package java.util;
   83.30 -import java.io.*;
   83.31 -
   83.32 -/**
   83.33 - * Hash table based implementation of the <tt>Map</tt> interface.  This
   83.34 - * implementation provides all of the optional map operations, and permits
   83.35 - * <tt>null</tt> values and the <tt>null</tt> key.  (The <tt>HashMap</tt>
   83.36 - * class is roughly equivalent to <tt>Hashtable</tt>, except that it is
   83.37 - * unsynchronized and permits nulls.)  This class makes no guarantees as to
   83.38 - * the order of the map; in particular, it does not guarantee that the order
   83.39 - * will remain constant over time.
   83.40 - *
   83.41 - * <p>This implementation provides constant-time performance for the basic
   83.42 - * operations (<tt>get</tt> and <tt>put</tt>), assuming the hash function
   83.43 - * disperses the elements properly among the buckets.  Iteration over
   83.44 - * collection views requires time proportional to the "capacity" of the
   83.45 - * <tt>HashMap</tt> instance (the number of buckets) plus its size (the number
   83.46 - * of key-value mappings).  Thus, it's very important not to set the initial
   83.47 - * capacity too high (or the load factor too low) if iteration performance is
   83.48 - * important.
   83.49 - *
   83.50 - * <p>An instance of <tt>HashMap</tt> has two parameters that affect its
   83.51 - * performance: <i>initial capacity</i> and <i>load factor</i>.  The
   83.52 - * <i>capacity</i> is the number of buckets in the hash table, and the initial
   83.53 - * capacity is simply the capacity at the time the hash table is created.  The
   83.54 - * <i>load factor</i> is a measure of how full the hash table is allowed to
   83.55 - * get before its capacity is automatically increased.  When the number of
   83.56 - * entries in the hash table exceeds the product of the load factor and the
   83.57 - * current capacity, the hash table is <i>rehashed</i> (that is, internal data
   83.58 - * structures are rebuilt) so that the hash table has approximately twice the
   83.59 - * number of buckets.
   83.60 - *
   83.61 - * <p>As a general rule, the default load factor (.75) offers a good tradeoff
   83.62 - * between time and space costs.  Higher values decrease the space overhead
   83.63 - * but increase the lookup cost (reflected in most of the operations of the
   83.64 - * <tt>HashMap</tt> class, including <tt>get</tt> and <tt>put</tt>).  The
   83.65 - * expected number of entries in the map and its load factor should be taken
   83.66 - * into account when setting its initial capacity, so as to minimize the
   83.67 - * number of rehash operations.  If the initial capacity is greater
   83.68 - * than the maximum number of entries divided by the load factor, no
   83.69 - * rehash operations will ever occur.
   83.70 - *
   83.71 - * <p>If many mappings are to be stored in a <tt>HashMap</tt> instance,
   83.72 - * creating it with a sufficiently large capacity will allow the mappings to
   83.73 - * be stored more efficiently than letting it perform automatic rehashing as
   83.74 - * needed to grow the table.
   83.75 - *
   83.76 - * <p><strong>Note that this implementation is not synchronized.</strong>
   83.77 - * If multiple threads access a hash map concurrently, and at least one of
   83.78 - * the threads modifies the map structurally, it <i>must</i> be
   83.79 - * synchronized externally.  (A structural modification is any operation
   83.80 - * that adds or deletes one or more mappings; merely changing the value
   83.81 - * associated with a key that an instance already contains is not a
   83.82 - * structural modification.)  This is typically accomplished by
   83.83 - * synchronizing on some object that naturally encapsulates the map.
   83.84 - *
   83.85 - * If no such object exists, the map should be "wrapped" using the
   83.86 - * {@link Collections#synchronizedMap Collections.synchronizedMap}
   83.87 - * method.  This is best done at creation time, to prevent accidental
   83.88 - * unsynchronized access to the map:<pre>
   83.89 - *   Map m = Collections.synchronizedMap(new HashMap(...));</pre>
   83.90 - *
   83.91 - * <p>The iterators returned by all of this class's "collection view methods"
   83.92 - * are <i>fail-fast</i>: if the map is structurally modified at any time after
   83.93 - * the iterator is created, in any way except through the iterator's own
   83.94 - * <tt>remove</tt> method, the iterator will throw a
   83.95 - * {@link ConcurrentModificationException}.  Thus, in the face of concurrent
   83.96 - * modification, the iterator fails quickly and cleanly, rather than risking
   83.97 - * arbitrary, non-deterministic behavior at an undetermined time in the
   83.98 - * future.
   83.99 - *
  83.100 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  83.101 - * as it is, generally speaking, impossible to make any hard guarantees in the
  83.102 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
  83.103 - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  83.104 - * Therefore, it would be wrong to write a program that depended on this
  83.105 - * exception for its correctness: <i>the fail-fast behavior of iterators
  83.106 - * should be used only to detect bugs.</i>
  83.107 - *
  83.108 - * <p>This class is a member of the
  83.109 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  83.110 - * Java Collections Framework</a>.
  83.111 - *
  83.112 - * @param <K> the type of keys maintained by this map
  83.113 - * @param <V> the type of mapped values
  83.114 - *
  83.115 - * @author  Doug Lea
  83.116 - * @author  Josh Bloch
  83.117 - * @author  Arthur van Hoff
  83.118 - * @author  Neal Gafter
  83.119 - * @see     Object#hashCode()
  83.120 - * @see     Collection
  83.121 - * @see     Map
  83.122 - * @see     TreeMap
  83.123 - * @see     Hashtable
  83.124 - * @since   1.2
  83.125 - */
  83.126 -
  83.127 -public class HashMap<K,V>
  83.128 -    extends AbstractMap<K,V>
  83.129 -    implements Map<K,V>, Cloneable, Serializable
  83.130 -{
  83.131 -
  83.132 -    /**
  83.133 -     * The default initial capacity - MUST be a power of two.
  83.134 -     */
  83.135 -    static final int DEFAULT_INITIAL_CAPACITY = 16;
  83.136 -
  83.137 -    /**
  83.138 -     * The maximum capacity, used if a higher value is implicitly specified
  83.139 -     * by either of the constructors with arguments.
  83.140 -     * MUST be a power of two <= 1<<30.
  83.141 -     */
  83.142 -    static final int MAXIMUM_CAPACITY = 1 << 30;
  83.143 -
  83.144 -    /**
  83.145 -     * The load factor used when none specified in constructor.
  83.146 -     */
  83.147 -    static final float DEFAULT_LOAD_FACTOR = 0.75f;
  83.148 -
  83.149 -    /**
  83.150 -     * The table, resized as necessary. Length MUST Always be a power of two.
  83.151 -     */
  83.152 -    transient Entry[] table;
  83.153 -
  83.154 -    /**
  83.155 -     * The number of key-value mappings contained in this map.
  83.156 -     */
  83.157 -    transient int size;
  83.158 -
  83.159 -    /**
  83.160 -     * The next size value at which to resize (capacity * load factor).
  83.161 -     * @serial
  83.162 -     */
  83.163 -    int threshold;
  83.164 -
  83.165 -    /**
  83.166 -     * The load factor for the hash table.
  83.167 -     *
  83.168 -     * @serial
  83.169 -     */
  83.170 -    final float loadFactor;
  83.171 -
  83.172 -    /**
  83.173 -     * The number of times this HashMap has been structurally modified
  83.174 -     * Structural modifications are those that change the number of mappings in
  83.175 -     * the HashMap or otherwise modify its internal structure (e.g.,
  83.176 -     * rehash).  This field is used to make iterators on Collection-views of
  83.177 -     * the HashMap fail-fast.  (See ConcurrentModificationException).
  83.178 -     */
  83.179 -    transient int modCount;
  83.180 -
  83.181 -    /**
  83.182 -     * Constructs an empty <tt>HashMap</tt> with the specified initial
  83.183 -     * capacity and load factor.
  83.184 -     *
  83.185 -     * @param  initialCapacity the initial capacity
  83.186 -     * @param  loadFactor      the load factor
  83.187 -     * @throws IllegalArgumentException if the initial capacity is negative
  83.188 -     *         or the load factor is nonpositive
  83.189 -     */
  83.190 -    public HashMap(int initialCapacity, float loadFactor) {
  83.191 -        if (initialCapacity < 0)
  83.192 -            throw new IllegalArgumentException("Illegal initial capacity: " +
  83.193 -                                               initialCapacity);
  83.194 -        if (initialCapacity > MAXIMUM_CAPACITY)
  83.195 -            initialCapacity = MAXIMUM_CAPACITY;
  83.196 -        if (loadFactor <= 0 || Float.isNaN(loadFactor))
  83.197 -            throw new IllegalArgumentException("Illegal load factor: " +
  83.198 -                                               loadFactor);
  83.199 -
  83.200 -        // Find a power of 2 >= initialCapacity
  83.201 -        int capacity = 1;
  83.202 -        while (capacity < initialCapacity)
  83.203 -            capacity <<= 1;
  83.204 -
  83.205 -        this.loadFactor = loadFactor;
  83.206 -        threshold = (int)(capacity * loadFactor);
  83.207 -        table = new Entry[capacity];
  83.208 -        init();
  83.209 -    }
  83.210 -
  83.211 -    /**
  83.212 -     * Constructs an empty <tt>HashMap</tt> with the specified initial
  83.213 -     * capacity and the default load factor (0.75).
  83.214 -     *
  83.215 -     * @param  initialCapacity the initial capacity.
  83.216 -     * @throws IllegalArgumentException if the initial capacity is negative.
  83.217 -     */
  83.218 -    public HashMap(int initialCapacity) {
  83.219 -        this(initialCapacity, DEFAULT_LOAD_FACTOR);
  83.220 -    }
  83.221 -
  83.222 -    /**
  83.223 -     * Constructs an empty <tt>HashMap</tt> with the default initial capacity
  83.224 -     * (16) and the default load factor (0.75).
  83.225 -     */
  83.226 -    public HashMap() {
  83.227 -        this.loadFactor = DEFAULT_LOAD_FACTOR;
  83.228 -        threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
  83.229 -        table = new Entry[DEFAULT_INITIAL_CAPACITY];
  83.230 -        init();
  83.231 -    }
  83.232 -
  83.233 -    /**
  83.234 -     * Constructs a new <tt>HashMap</tt> with the same mappings as the
  83.235 -     * specified <tt>Map</tt>.  The <tt>HashMap</tt> is created with
  83.236 -     * default load factor (0.75) and an initial capacity sufficient to
  83.237 -     * hold the mappings in the specified <tt>Map</tt>.
  83.238 -     *
  83.239 -     * @param   m the map whose mappings are to be placed in this map
  83.240 -     * @throws  NullPointerException if the specified map is null
  83.241 -     */
  83.242 -    public HashMap(Map<? extends K, ? extends V> m) {
  83.243 -        this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1,
  83.244 -                      DEFAULT_INITIAL_CAPACITY), DEFAULT_LOAD_FACTOR);
  83.245 -        putAllForCreate(m);
  83.246 -    }
  83.247 -
  83.248 -    // internal utilities
  83.249 -
  83.250 -    /**
  83.251 -     * Initialization hook for subclasses. This method is called
  83.252 -     * in all constructors and pseudo-constructors (clone, readObject)
  83.253 -     * after HashMap has been initialized but before any entries have
  83.254 -     * been inserted.  (In the absence of this method, readObject would
  83.255 -     * require explicit knowledge of subclasses.)
  83.256 -     */
  83.257 -    void init() {
  83.258 -    }
  83.259 -
  83.260 -    /**
  83.261 -     * Applies a supplemental hash function to a given hashCode, which
  83.262 -     * defends against poor quality hash functions.  This is critical
  83.263 -     * because HashMap uses power-of-two length hash tables, that
  83.264 -     * otherwise encounter collisions for hashCodes that do not differ
  83.265 -     * in lower bits. Note: Null keys always map to hash 0, thus index 0.
  83.266 -     */
  83.267 -    static int hash(int h) {
  83.268 -        // This function ensures that hashCodes that differ only by
  83.269 -        // constant multiples at each bit position have a bounded
  83.270 -        // number of collisions (approximately 8 at default load factor).
  83.271 -        h ^= (h >>> 20) ^ (h >>> 12);
  83.272 -        return h ^ (h >>> 7) ^ (h >>> 4);
  83.273 -    }
  83.274 -
  83.275 -    /**
  83.276 -     * Returns index for hash code h.
  83.277 -     */
  83.278 -    static int indexFor(int h, int length) {
  83.279 -        return h & (length-1);
  83.280 -    }
  83.281 -
  83.282 -    /**
  83.283 -     * Returns the number of key-value mappings in this map.
  83.284 -     *
  83.285 -     * @return the number of key-value mappings in this map
  83.286 -     */
  83.287 -    public int size() {
  83.288 -        return size;
  83.289 -    }
  83.290 -
  83.291 -    /**
  83.292 -     * Returns <tt>true</tt> if this map contains no key-value mappings.
  83.293 -     *
  83.294 -     * @return <tt>true</tt> if this map contains no key-value mappings
  83.295 -     */
  83.296 -    public boolean isEmpty() {
  83.297 -        return size == 0;
  83.298 -    }
  83.299 -
  83.300 -    /**
  83.301 -     * Returns the value to which the specified key is mapped,
  83.302 -     * or {@code null} if this map contains no mapping for the key.
  83.303 -     *
  83.304 -     * <p>More formally, if this map contains a mapping from a key
  83.305 -     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
  83.306 -     * key.equals(k))}, then this method returns {@code v}; otherwise
  83.307 -     * it returns {@code null}.  (There can be at most one such mapping.)
  83.308 -     *
  83.309 -     * <p>A return value of {@code null} does not <i>necessarily</i>
  83.310 -     * indicate that the map contains no mapping for the key; it's also
  83.311 -     * possible that the map explicitly maps the key to {@code null}.
  83.312 -     * The {@link #containsKey containsKey} operation may be used to
  83.313 -     * distinguish these two cases.
  83.314 -     *
  83.315 -     * @see #put(Object, Object)
  83.316 -     */
  83.317 -    public V get(Object key) {
  83.318 -        if (key == null)
  83.319 -            return getForNullKey();
  83.320 -        int hash = hash(key.hashCode());
  83.321 -        for (Entry<K,V> e = table[indexFor(hash, table.length)];
  83.322 -             e != null;
  83.323 -             e = e.next) {
  83.324 -            Object k;
  83.325 -            if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
  83.326 -                return e.value;
  83.327 -        }
  83.328 -        return null;
  83.329 -    }
  83.330 -
  83.331 -    /**
  83.332 -     * Offloaded version of get() to look up null keys.  Null keys map
  83.333 -     * to index 0.  This null case is split out into separate methods
  83.334 -     * for the sake of performance in the two most commonly used
  83.335 -     * operations (get and put), but incorporated with conditionals in
  83.336 -     * others.
  83.337 -     */
  83.338 -    private V getForNullKey() {
  83.339 -        for (Entry<K,V> e = table[0]; e != null; e = e.next) {
  83.340 -            if (e.key == null)
  83.341 -                return e.value;
  83.342 -        }
  83.343 -        return null;
  83.344 -    }
  83.345 -
  83.346 -    /**
  83.347 -     * Returns <tt>true</tt> if this map contains a mapping for the
  83.348 -     * specified key.
  83.349 -     *
  83.350 -     * @param   key   The key whose presence in this map is to be tested
  83.351 -     * @return <tt>true</tt> if this map contains a mapping for the specified
  83.352 -     * key.
  83.353 -     */
  83.354 -    public boolean containsKey(Object key) {
  83.355 -        return getEntry(key) != null;
  83.356 -    }
  83.357 -
  83.358 -    /**
  83.359 -     * Returns the entry associated with the specified key in the
  83.360 -     * HashMap.  Returns null if the HashMap contains no mapping
  83.361 -     * for the key.
  83.362 -     */
  83.363 -    final Entry<K,V> getEntry(Object key) {
  83.364 -        int hash = (key == null) ? 0 : hash(key.hashCode());
  83.365 -        for (Entry<K,V> e = table[indexFor(hash, table.length)];
  83.366 -             e != null;
  83.367 -             e = e.next) {
  83.368 -            Object k;
  83.369 -            if (e.hash == hash &&
  83.370 -                ((k = e.key) == key || (key != null && key.equals(k))))
  83.371 -                return e;
  83.372 -        }
  83.373 -        return null;
  83.374 -    }
  83.375 -
  83.376 -
  83.377 -    /**
  83.378 -     * Associates the specified value with the specified key in this map.
  83.379 -     * If the map previously contained a mapping for the key, the old
  83.380 -     * value is replaced.
  83.381 -     *
  83.382 -     * @param key key with which the specified value is to be associated
  83.383 -     * @param value value to be associated with the specified key
  83.384 -     * @return the previous value associated with <tt>key</tt>, or
  83.385 -     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  83.386 -     *         (A <tt>null</tt> return can also indicate that the map
  83.387 -     *         previously associated <tt>null</tt> with <tt>key</tt>.)
  83.388 -     */
  83.389 -    public V put(K key, V value) {
  83.390 -        if (key == null)
  83.391 -            return putForNullKey(value);
  83.392 -        int hash = hash(key.hashCode());
  83.393 -        int i = indexFor(hash, table.length);
  83.394 -        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
  83.395 -            Object k;
  83.396 -            if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
  83.397 -                V oldValue = e.value;
  83.398 -                e.value = value;
  83.399 -                e.recordAccess(this);
  83.400 -                return oldValue;
  83.401 -            }
  83.402 -        }
  83.403 -
  83.404 -        modCount++;
  83.405 -        addEntry(hash, key, value, i);
  83.406 -        return null;
  83.407 -    }
  83.408 -
  83.409 -    /**
  83.410 -     * Offloaded version of put for null keys
  83.411 -     */
  83.412 -    private V putForNullKey(V value) {
  83.413 -        for (Entry<K,V> e = table[0]; e != null; e = e.next) {
  83.414 -            if (e.key == null) {
  83.415 -                V oldValue = e.value;
  83.416 -                e.value = value;
  83.417 -                e.recordAccess(this);
  83.418 -                return oldValue;
  83.419 -            }
  83.420 -        }
  83.421 -        modCount++;
  83.422 -        addEntry(0, null, value, 0);
  83.423 -        return null;
  83.424 -    }
  83.425 -
  83.426 -    /**
  83.427 -     * This method is used instead of put by constructors and
  83.428 -     * pseudoconstructors (clone, readObject).  It does not resize the table,
  83.429 -     * check for comodification, etc.  It calls createEntry rather than
  83.430 -     * addEntry.
  83.431 -     */
  83.432 -    private void putForCreate(K key, V value) {
  83.433 -        int hash = (key == null) ? 0 : hash(key.hashCode());
  83.434 -        int i = indexFor(hash, table.length);
  83.435 -
  83.436 -        /**
  83.437 -         * Look for preexisting entry for key.  This will never happen for
  83.438 -         * clone or deserialize.  It will only happen for construction if the
  83.439 -         * input Map is a sorted map whose ordering is inconsistent w/ equals.
  83.440 -         */
  83.441 -        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
  83.442 -            Object k;
  83.443 -            if (e.hash == hash &&
  83.444 -                ((k = e.key) == key || (key != null && key.equals(k)))) {
  83.445 -                e.value = value;
  83.446 -                return;
  83.447 -            }
  83.448 -        }
  83.449 -
  83.450 -        createEntry(hash, key, value, i);
  83.451 -    }
  83.452 -
  83.453 -    private void putAllForCreate(Map<? extends K, ? extends V> m) {
  83.454 -        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
  83.455 -            putForCreate(e.getKey(), e.getValue());
  83.456 -    }
  83.457 -
  83.458 -    /**
  83.459 -     * Rehashes the contents of this map into a new array with a
  83.460 -     * larger capacity.  This method is called automatically when the
  83.461 -     * number of keys in this map reaches its threshold.
  83.462 -     *
  83.463 -     * If current capacity is MAXIMUM_CAPACITY, this method does not
  83.464 -     * resize the map, but sets threshold to Integer.MAX_VALUE.
  83.465 -     * This has the effect of preventing future calls.
  83.466 -     *
  83.467 -     * @param newCapacity the new capacity, MUST be a power of two;
  83.468 -     *        must be greater than current capacity unless current
  83.469 -     *        capacity is MAXIMUM_CAPACITY (in which case value
  83.470 -     *        is irrelevant).
  83.471 -     */
  83.472 -    void resize(int newCapacity) {
  83.473 -        Entry[] oldTable = table;
  83.474 -        int oldCapacity = oldTable.length;
  83.475 -        if (oldCapacity == MAXIMUM_CAPACITY) {
  83.476 -            threshold = Integer.MAX_VALUE;
  83.477 -            return;
  83.478 -        }
  83.479 -
  83.480 -        Entry[] newTable = new Entry[newCapacity];
  83.481 -        transfer(newTable);
  83.482 -        table = newTable;
  83.483 -        threshold = (int)(newCapacity * loadFactor);
  83.484 -    }
  83.485 -
  83.486 -    /**
  83.487 -     * Transfers all entries from current table to newTable.
  83.488 -     */
  83.489 -    void transfer(Entry[] newTable) {
  83.490 -        Entry[] src = table;
  83.491 -        int newCapacity = newTable.length;
  83.492 -        for (int j = 0; j < src.length; j++) {
  83.493 -            Entry<K,V> e = src[j];
  83.494 -            if (e != null) {
  83.495 -                src[j] = null;
  83.496 -                do {
  83.497 -                    Entry<K,V> next = e.next;
  83.498 -                    int i = indexFor(e.hash, newCapacity);
  83.499 -                    e.next = newTable[i];
  83.500 -                    newTable[i] = e;
  83.501 -                    e = next;
  83.502 -                } while (e != null);
  83.503 -            }
  83.504 -        }
  83.505 -    }
  83.506 -
  83.507 -    /**
  83.508 -     * Copies all of the mappings from the specified map to this map.
  83.509 -     * These mappings will replace any mappings that this map had for
  83.510 -     * any of the keys currently in the specified map.
  83.511 -     *
  83.512 -     * @param m mappings to be stored in this map
  83.513 -     * @throws NullPointerException if the specified map is null
  83.514 -     */
  83.515 -    public void putAll(Map<? extends K, ? extends V> m) {
  83.516 -        int numKeysToBeAdded = m.size();
  83.517 -        if (numKeysToBeAdded == 0)
  83.518 -            return;
  83.519 -
  83.520 -        /*
  83.521 -         * Expand the map if the map if the number of mappings to be added
  83.522 -         * is greater than or equal to threshold.  This is conservative; the
  83.523 -         * obvious condition is (m.size() + size) >= threshold, but this
  83.524 -         * condition could result in a map with twice the appropriate capacity,
  83.525 -         * if the keys to be added overlap with the keys already in this map.
  83.526 -         * By using the conservative calculation, we subject ourself
  83.527 -         * to at most one extra resize.
  83.528 -         */
  83.529 -        if (numKeysToBeAdded > threshold) {
  83.530 -            int targetCapacity = (int)(numKeysToBeAdded / loadFactor + 1);
  83.531 -            if (targetCapacity > MAXIMUM_CAPACITY)
  83.532 -                targetCapacity = MAXIMUM_CAPACITY;
  83.533 -            int newCapacity = table.length;
  83.534 -            while (newCapacity < targetCapacity)
  83.535 -                newCapacity <<= 1;
  83.536 -            if (newCapacity > table.length)
  83.537 -                resize(newCapacity);
  83.538 -        }
  83.539 -
  83.540 -        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
  83.541 -            put(e.getKey(), e.getValue());
  83.542 -    }
  83.543 -
  83.544 -    /**
  83.545 -     * Removes the mapping for the specified key from this map if present.
  83.546 -     *
  83.547 -     * @param  key key whose mapping is to be removed from the map
  83.548 -     * @return the previous value associated with <tt>key</tt>, or
  83.549 -     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  83.550 -     *         (A <tt>null</tt> return can also indicate that the map
  83.551 -     *         previously associated <tt>null</tt> with <tt>key</tt>.)
  83.552 -     */
  83.553 -    public V remove(Object key) {
  83.554 -        Entry<K,V> e = removeEntryForKey(key);
  83.555 -        return (e == null ? null : e.value);
  83.556 -    }
  83.557 -
  83.558 -    /**
  83.559 -     * Removes and returns the entry associated with the specified key
  83.560 -     * in the HashMap.  Returns null if the HashMap contains no mapping
  83.561 -     * for this key.
  83.562 -     */
  83.563 -    final Entry<K,V> removeEntryForKey(Object key) {
  83.564 -        int hash = (key == null) ? 0 : hash(key.hashCode());
  83.565 -        int i = indexFor(hash, table.length);
  83.566 -        Entry<K,V> prev = table[i];
  83.567 -        Entry<K,V> e = prev;
  83.568 -
  83.569 -        while (e != null) {
  83.570 -            Entry<K,V> next = e.next;
  83.571 -            Object k;
  83.572 -            if (e.hash == hash &&
  83.573 -                ((k = e.key) == key || (key != null && key.equals(k)))) {
  83.574 -                modCount++;
  83.575 -                size--;
  83.576 -                if (prev == e)
  83.577 -                    table[i] = next;
  83.578 -                else
  83.579 -                    prev.next = next;
  83.580 -                e.recordRemoval(this);
  83.581 -                return e;
  83.582 -            }
  83.583 -            prev = e;
  83.584 -            e = next;
  83.585 -        }
  83.586 -
  83.587 -        return e;
  83.588 -    }
  83.589 -
  83.590 -    /**
  83.591 -     * Special version of remove for EntrySet.
  83.592 -     */
  83.593 -    final Entry<K,V> removeMapping(Object o) {
  83.594 -        if (!(o instanceof Map.Entry))
  83.595 -            return null;
  83.596 -
  83.597 -        Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
  83.598 -        Object key = entry.getKey();
  83.599 -        int hash = (key == null) ? 0 : hash(key.hashCode());
  83.600 -        int i = indexFor(hash, table.length);
  83.601 -        Entry<K,V> prev = table[i];
  83.602 -        Entry<K,V> e = prev;
  83.603 -
  83.604 -        while (e != null) {
  83.605 -            Entry<K,V> next = e.next;
  83.606 -            if (e.hash == hash && e.equals(entry)) {
  83.607 -                modCount++;
  83.608 -                size--;
  83.609 -                if (prev == e)
  83.610 -                    table[i] = next;
  83.611 -                else
  83.612 -                    prev.next = next;
  83.613 -                e.recordRemoval(this);
  83.614 -                return e;
  83.615 -            }
  83.616 -            prev = e;
  83.617 -            e = next;
  83.618 -        }
  83.619 -
  83.620 -        return e;
  83.621 -    }
  83.622 -
  83.623 -    /**
  83.624 -     * Removes all of the mappings from this map.
  83.625 -     * The map will be empty after this call returns.
  83.626 -     */
  83.627 -    public void clear() {
  83.628 -        modCount++;
  83.629 -        Entry[] tab = table;
  83.630 -        for (int i = 0; i < tab.length; i++)
  83.631 -            tab[i] = null;
  83.632 -        size = 0;
  83.633 -    }
  83.634 -
  83.635 -    /**
  83.636 -     * Returns <tt>true</tt> if this map maps one or more keys to the
  83.637 -     * specified value.
  83.638 -     *
  83.639 -     * @param value value whose presence in this map is to be tested
  83.640 -     * @return <tt>true</tt> if this map maps one or more keys to the
  83.641 -     *         specified value
  83.642 -     */
  83.643 -    public boolean containsValue(Object value) {
  83.644 -        if (value == null)
  83.645 -            return containsNullValue();
  83.646 -
  83.647 -        Entry[] tab = table;
  83.648 -        for (int i = 0; i < tab.length ; i++)
  83.649 -            for (Entry e = tab[i] ; e != null ; e = e.next)
  83.650 -                if (value.equals(e.value))
  83.651 -                    return true;
  83.652 -        return false;
  83.653 -    }
  83.654 -
  83.655 -    /**
  83.656 -     * Special-case code for containsValue with null argument
  83.657 -     */
  83.658 -    private boolean containsNullValue() {
  83.659 -        Entry[] tab = table;
  83.660 -        for (int i = 0; i < tab.length ; i++)
  83.661 -            for (Entry e = tab[i] ; e != null ; e = e.next)
  83.662 -                if (e.value == null)
  83.663 -                    return true;
  83.664 -        return false;
  83.665 -    }
  83.666 -
  83.667 -    /**
  83.668 -     * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
  83.669 -     * values themselves are not cloned.
  83.670 -     *
  83.671 -     * @return a shallow copy of this map
  83.672 -     */
  83.673 -    public Object clone() {
  83.674 -        HashMap<K,V> result = null;
  83.675 -        try {
  83.676 -            result = (HashMap<K,V>)super.clone();
  83.677 -        } catch (CloneNotSupportedException e) {
  83.678 -            // assert false;
  83.679 -        }
  83.680 -        result.table = new Entry[table.length];
  83.681 -        result.entrySet = null;
  83.682 -        result.modCount = 0;
  83.683 -        result.size = 0;
  83.684 -        result.init();
  83.685 -        result.putAllForCreate(this);
  83.686 -
  83.687 -        return result;
  83.688 -    }
  83.689 -
  83.690 -    static class Entry<K,V> implements Map.Entry<K,V> {
  83.691 -        final K key;
  83.692 -        V value;
  83.693 -        Entry<K,V> next;
  83.694 -        final int hash;
  83.695 -
  83.696 -        /**
  83.697 -         * Creates new entry.
  83.698 -         */
  83.699 -        Entry(int h, K k, V v, Entry<K,V> n) {
  83.700 -            value = v;
  83.701 -            next = n;
  83.702 -            key = k;
  83.703 -            hash = h;
  83.704 -        }
  83.705 -
  83.706 -        public final K getKey() {
  83.707 -            return key;
  83.708 -        }
  83.709 -
  83.710 -        public final V getValue() {
  83.711 -            return value;
  83.712 -        }
  83.713 -
  83.714 -        public final V setValue(V newValue) {
  83.715 -            V oldValue = value;
  83.716 -            value = newValue;
  83.717 -            return oldValue;
  83.718 -        }
  83.719 -
  83.720 -        public final boolean equals(Object o) {
  83.721 -            if (!(o instanceof Map.Entry))
  83.722 -                return false;
  83.723 -            Map.Entry e = (Map.Entry)o;
  83.724 -            Object k1 = getKey();
  83.725 -            Object k2 = e.getKey();
  83.726 -            if (k1 == k2 || (k1 != null && k1.equals(k2))) {
  83.727 -                Object v1 = getValue();
  83.728 -                Object v2 = e.getValue();
  83.729 -                if (v1 == v2 || (v1 != null && v1.equals(v2)))
  83.730 -                    return true;
  83.731 -            }
  83.732 -            return false;
  83.733 -        }
  83.734 -
  83.735 -        public final int hashCode() {
  83.736 -            return (key==null   ? 0 : key.hashCode()) ^
  83.737 -                   (value==null ? 0 : value.hashCode());
  83.738 -        }
  83.739 -
  83.740 -        public final String toString() {
  83.741 -            return getKey() + "=" + getValue();
  83.742 -        }
  83.743 -
  83.744 -        /**
  83.745 -         * This method is invoked whenever the value in an entry is
  83.746 -         * overwritten by an invocation of put(k,v) for a key k that's already
  83.747 -         * in the HashMap.
  83.748 -         */
  83.749 -        void recordAccess(HashMap<K,V> m) {
  83.750 -        }
  83.751 -
  83.752 -        /**
  83.753 -         * This method is invoked whenever the entry is
  83.754 -         * removed from the table.
  83.755 -         */
  83.756 -        void recordRemoval(HashMap<K,V> m) {
  83.757 -        }
  83.758 -    }
  83.759 -
  83.760 -    /**
  83.761 -     * Adds a new entry with the specified key, value and hash code to
  83.762 -     * the specified bucket.  It is the responsibility of this
  83.763 -     * method to resize the table if appropriate.
  83.764 -     *
  83.765 -     * Subclass overrides this to alter the behavior of put method.
  83.766 -     */
  83.767 -    void addEntry(int hash, K key, V value, int bucketIndex) {
  83.768 -        Entry<K,V> e = table[bucketIndex];
  83.769 -        table[bucketIndex] = new Entry<>(hash, key, value, e);
  83.770 -        if (size++ >= threshold)
  83.771 -            resize(2 * table.length);
  83.772 -    }
  83.773 -
  83.774 -    /**
  83.775 -     * Like addEntry except that this version is used when creating entries
  83.776 -     * as part of Map construction or "pseudo-construction" (cloning,
  83.777 -     * deserialization).  This version needn't worry about resizing the table.
  83.778 -     *
  83.779 -     * Subclass overrides this to alter the behavior of HashMap(Map),
  83.780 -     * clone, and readObject.
  83.781 -     */
  83.782 -    void createEntry(int hash, K key, V value, int bucketIndex) {
  83.783 -        Entry<K,V> e = table[bucketIndex];
  83.784 -        table[bucketIndex] = new Entry<>(hash, key, value, e);
  83.785 -        size++;
  83.786 -    }
  83.787 -
  83.788 -    private abstract class HashIterator<E> implements Iterator<E> {
  83.789 -        Entry<K,V> next;        // next entry to return
  83.790 -        int expectedModCount;   // For fast-fail
  83.791 -        int index;              // current slot
  83.792 -        Entry<K,V> current;     // current entry
  83.793 -
  83.794 -        HashIterator() {
  83.795 -            expectedModCount = modCount;
  83.796 -            if (size > 0) { // advance to first entry
  83.797 -                Entry[] t = table;
  83.798 -                while (index < t.length && (next = t[index++]) == null)
  83.799 -                    ;
  83.800 -            }
  83.801 -        }
  83.802 -
  83.803 -        public final boolean hasNext() {
  83.804 -            return next != null;
  83.805 -        }
  83.806 -
  83.807 -        final Entry<K,V> nextEntry() {
  83.808 -            if (modCount != expectedModCount)
  83.809 -                throw new ConcurrentModificationException();
  83.810 -            Entry<K,V> e = next;
  83.811 -            if (e == null)
  83.812 -                throw new NoSuchElementException();
  83.813 -
  83.814 -            if ((next = e.next) == null) {
  83.815 -                Entry[] t = table;
  83.816 -                while (index < t.length && (next = t[index++]) == null)
  83.817 -                    ;
  83.818 -            }
  83.819 -            current = e;
  83.820 -            return e;
  83.821 -        }
  83.822 -
  83.823 -        public void remove() {
  83.824 -            if (current == null)
  83.825 -                throw new IllegalStateException();
  83.826 -            if (modCount != expectedModCount)
  83.827 -                throw new ConcurrentModificationException();
  83.828 -            Object k = current.key;
  83.829 -            current = null;
  83.830 -            HashMap.this.removeEntryForKey(k);
  83.831 -            expectedModCount = modCount;
  83.832 -        }
  83.833 -
  83.834 -    }
  83.835 -
  83.836 -    private final class ValueIterator extends HashIterator<V> {
  83.837 -        public V next() {
  83.838 -            return nextEntry().value;
  83.839 -        }
  83.840 -    }
  83.841 -
  83.842 -    private final class KeyIterator extends HashIterator<K> {
  83.843 -        public K next() {
  83.844 -            return nextEntry().getKey();
  83.845 -        }
  83.846 -    }
  83.847 -
  83.848 -    private final class EntryIterator extends HashIterator<Map.Entry<K,V>> {
  83.849 -        public Map.Entry<K,V> next() {
  83.850 -            return nextEntry();
  83.851 -        }
  83.852 -    }
  83.853 -
  83.854 -    // Subclass overrides these to alter behavior of views' iterator() method
  83.855 -    Iterator<K> newKeyIterator()   {
  83.856 -        return new KeyIterator();
  83.857 -    }
  83.858 -    Iterator<V> newValueIterator()   {
  83.859 -        return new ValueIterator();
  83.860 -    }
  83.861 -    Iterator<Map.Entry<K,V>> newEntryIterator()   {
  83.862 -        return new EntryIterator();
  83.863 -    }
  83.864 -
  83.865 -
  83.866 -    // Views
  83.867 -
  83.868 -    private transient Set<Map.Entry<K,V>> entrySet = null;
  83.869 -
  83.870 -    /**
  83.871 -     * Returns a {@link Set} view of the keys contained in this map.
  83.872 -     * The set is backed by the map, so changes to the map are
  83.873 -     * reflected in the set, and vice-versa.  If the map is modified
  83.874 -     * while an iteration over the set is in progress (except through
  83.875 -     * the iterator's own <tt>remove</tt> operation), the results of
  83.876 -     * the iteration are undefined.  The set supports element removal,
  83.877 -     * which removes the corresponding mapping from the map, via the
  83.878 -     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
  83.879 -     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
  83.880 -     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
  83.881 -     * operations.
  83.882 -     */
  83.883 -    public Set<K> keySet() {
  83.884 -        Set<K> ks = keySet;
  83.885 -        return (ks != null ? ks : (keySet = new KeySet()));
  83.886 -    }
  83.887 -
  83.888 -    private final class KeySet extends AbstractSet<K> {
  83.889 -        public Iterator<K> iterator() {
  83.890 -            return newKeyIterator();
  83.891 -        }
  83.892 -        public int size() {
  83.893 -            return size;
  83.894 -        }
  83.895 -        public boolean contains(Object o) {
  83.896 -            return containsKey(o);
  83.897 -        }
  83.898 -        public boolean remove(Object o) {
  83.899 -            return HashMap.this.removeEntryForKey(o) != null;
  83.900 -        }
  83.901 -        public void clear() {
  83.902 -            HashMap.this.clear();
  83.903 -        }
  83.904 -    }
  83.905 -
  83.906 -    /**
  83.907 -     * Returns a {@link Collection} view of the values contained in this map.
  83.908 -     * The collection is backed by the map, so changes to the map are
  83.909 -     * reflected in the collection, and vice-versa.  If the map is
  83.910 -     * modified while an iteration over the collection is in progress
  83.911 -     * (except through the iterator's own <tt>remove</tt> operation),
  83.912 -     * the results of the iteration are undefined.  The collection
  83.913 -     * supports element removal, which removes the corresponding
  83.914 -     * mapping from the map, via the <tt>Iterator.remove</tt>,
  83.915 -     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
  83.916 -     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
  83.917 -     * support the <tt>add</tt> or <tt>addAll</tt> operations.
  83.918 -     */
  83.919 -    public Collection<V> values() {
  83.920 -        Collection<V> vs = values;
  83.921 -        return (vs != null ? vs : (values = new Values()));
  83.922 -    }
  83.923 -
  83.924 -    private final class Values extends AbstractCollection<V> {
  83.925 -        public Iterator<V> iterator() {
  83.926 -            return newValueIterator();
  83.927 -        }
  83.928 -        public int size() {
  83.929 -            return size;
  83.930 -        }
  83.931 -        public boolean contains(Object o) {
  83.932 -            return containsValue(o);
  83.933 -        }
  83.934 -        public void clear() {
  83.935 -            HashMap.this.clear();
  83.936 -        }
  83.937 -    }
  83.938 -
  83.939 -    /**
  83.940 -     * Returns a {@link Set} view of the mappings contained in this map.
  83.941 -     * The set is backed by the map, so changes to the map are
  83.942 -     * reflected in the set, and vice-versa.  If the map is modified
  83.943 -     * while an iteration over the set is in progress (except through
  83.944 -     * the iterator's own <tt>remove</tt> operation, or through the
  83.945 -     * <tt>setValue</tt> operation on a map entry returned by the
  83.946 -     * iterator) the results of the iteration are undefined.  The set
  83.947 -     * supports element removal, which removes the corresponding
  83.948 -     * mapping from the map, via the <tt>Iterator.remove</tt>,
  83.949 -     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  83.950 -     * <tt>clear</tt> operations.  It does not support the
  83.951 -     * <tt>add</tt> or <tt>addAll</tt> operations.
  83.952 -     *
  83.953 -     * @return a set view of the mappings contained in this map
  83.954 -     */
  83.955 -    public Set<Map.Entry<K,V>> entrySet() {
  83.956 -        return entrySet0();
  83.957 -    }
  83.958 -
  83.959 -    private Set<Map.Entry<K,V>> entrySet0() {
  83.960 -        Set<Map.Entry<K,V>> es = entrySet;
  83.961 -        return es != null ? es : (entrySet = new EntrySet());
  83.962 -    }
  83.963 -
  83.964 -    private final class EntrySet extends AbstractSet<Map.Entry<K,V>> {
  83.965 -        public Iterator<Map.Entry<K,V>> iterator() {
  83.966 -            return newEntryIterator();
  83.967 -        }
  83.968 -        public boolean contains(Object o) {
  83.969 -            if (!(o instanceof Map.Entry))
  83.970 -                return false;
  83.971 -            Map.Entry<K,V> e = (Map.Entry<K,V>) o;
  83.972 -            Entry<K,V> candidate = getEntry(e.getKey());
  83.973 -            return candidate != null && candidate.equals(e);
  83.974 -        }
  83.975 -        public boolean remove(Object o) {
  83.976 -            return removeMapping(o) != null;
  83.977 -        }
  83.978 -        public int size() {
  83.979 -            return size;
  83.980 -        }
  83.981 -        public void clear() {
  83.982 -            HashMap.this.clear();
  83.983 -        }
  83.984 -    }
  83.985 -
  83.986 -
  83.987 -    private static final long serialVersionUID = 362498820763181265L;
  83.988 -
  83.989 -
  83.990 -    // These methods are used when serializing HashSets
  83.991 -    int   capacity()     { return table.length; }
  83.992 -    float loadFactor()   { return loadFactor;   }
  83.993 -}
    84.1 --- a/emul/compact/src/main/java/java/util/HashSet.java	Mon Feb 25 19:00:08 2013 +0100
    84.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.3 @@ -1,260 +0,0 @@
    84.4 -/*
    84.5 - * Copyright (c) 1997, 2010, 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 - * This class implements the <tt>Set</tt> interface, backed by a hash table
   84.33 - * (actually a <tt>HashMap</tt> instance).  It makes no guarantees as to the
   84.34 - * iteration order of the set; in particular, it does not guarantee that the
   84.35 - * order will remain constant over time.  This class permits the <tt>null</tt>
   84.36 - * element.
   84.37 - *
   84.38 - * <p>This class offers constant time performance for the basic operations
   84.39 - * (<tt>add</tt>, <tt>remove</tt>, <tt>contains</tt> and <tt>size</tt>),
   84.40 - * assuming the hash function disperses the elements properly among the
   84.41 - * buckets.  Iterating over this set requires time proportional to the sum of
   84.42 - * the <tt>HashSet</tt> instance's size (the number of elements) plus the
   84.43 - * "capacity" of the backing <tt>HashMap</tt> instance (the number of
   84.44 - * buckets).  Thus, it's very important not to set the initial capacity too
   84.45 - * high (or the load factor too low) if iteration performance is important.
   84.46 - *
   84.47 - * <p><strong>Note that this implementation is not synchronized.</strong>
   84.48 - * If multiple threads access a hash set concurrently, and at least one of
   84.49 - * the threads modifies the set, it <i>must</i> be synchronized externally.
   84.50 - * This is typically accomplished by synchronizing on some object that
   84.51 - * naturally encapsulates the set.
   84.52 - *
   84.53 - * If no such object exists, the set should be "wrapped" using the
   84.54 - * {@link Collections#synchronizedSet Collections.synchronizedSet}
   84.55 - * method.  This is best done at creation time, to prevent accidental
   84.56 - * unsynchronized access to the set:<pre>
   84.57 - *   Set s = Collections.synchronizedSet(new HashSet(...));</pre>
   84.58 - *
   84.59 - * <p>The iterators returned by this class's <tt>iterator</tt> method are
   84.60 - * <i>fail-fast</i>: if the set is modified at any time after the iterator is
   84.61 - * created, in any way except through the iterator's own <tt>remove</tt>
   84.62 - * method, the Iterator throws a {@link ConcurrentModificationException}.
   84.63 - * Thus, in the face of concurrent modification, the iterator fails quickly
   84.64 - * and cleanly, rather than risking arbitrary, non-deterministic behavior at
   84.65 - * an undetermined time in the future.
   84.66 - *
   84.67 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   84.68 - * as it is, generally speaking, impossible to make any hard guarantees in the
   84.69 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
   84.70 - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
   84.71 - * Therefore, it would be wrong to write a program that depended on this
   84.72 - * exception for its correctness: <i>the fail-fast behavior of iterators
   84.73 - * should be used only to detect bugs.</i>
   84.74 - *
   84.75 - * <p>This class is a member of the
   84.76 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   84.77 - * Java Collections Framework</a>.
   84.78 - *
   84.79 - * @param <E> the type of elements maintained by this set
   84.80 - *
   84.81 - * @author  Josh Bloch
   84.82 - * @author  Neal Gafter
   84.83 - * @see     Collection
   84.84 - * @see     Set
   84.85 - * @see     TreeSet
   84.86 - * @see     HashMap
   84.87 - * @since   1.2
   84.88 - */
   84.89 -
   84.90 -public class HashSet<E>
   84.91 -    extends AbstractSet<E>
   84.92 -    implements Set<E>, Cloneable, java.io.Serializable
   84.93 -{
   84.94 -    static final long serialVersionUID = -5024744406713321676L;
   84.95 -
   84.96 -    private transient HashMap<E,Object> map;
   84.97 -
   84.98 -    // Dummy value to associate with an Object in the backing Map
   84.99 -    private static final Object PRESENT = new Object();
  84.100 -
  84.101 -    /**
  84.102 -     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
  84.103 -     * default initial capacity (16) and load factor (0.75).
  84.104 -     */
  84.105 -    public HashSet() {
  84.106 -        map = new HashMap<>();
  84.107 -    }
  84.108 -
  84.109 -    /**
  84.110 -     * Constructs a new set containing the elements in the specified
  84.111 -     * collection.  The <tt>HashMap</tt> is created with default load factor
  84.112 -     * (0.75) and an initial capacity sufficient to contain the elements in
  84.113 -     * the specified collection.
  84.114 -     *
  84.115 -     * @param c the collection whose elements are to be placed into this set
  84.116 -     * @throws NullPointerException if the specified collection is null
  84.117 -     */
  84.118 -    public HashSet(Collection<? extends E> c) {
  84.119 -        map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16));
  84.120 -        addAll(c);
  84.121 -    }
  84.122 -
  84.123 -    /**
  84.124 -     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
  84.125 -     * the specified initial capacity and the specified load factor.
  84.126 -     *
  84.127 -     * @param      initialCapacity   the initial capacity of the hash map
  84.128 -     * @param      loadFactor        the load factor of the hash map
  84.129 -     * @throws     IllegalArgumentException if the initial capacity is less
  84.130 -     *             than zero, or if the load factor is nonpositive
  84.131 -     */
  84.132 -    public HashSet(int initialCapacity, float loadFactor) {
  84.133 -        map = new HashMap<>(initialCapacity, loadFactor);
  84.134 -    }
  84.135 -
  84.136 -    /**
  84.137 -     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
  84.138 -     * the specified initial capacity and default load factor (0.75).
  84.139 -     *
  84.140 -     * @param      initialCapacity   the initial capacity of the hash table
  84.141 -     * @throws     IllegalArgumentException if the initial capacity is less
  84.142 -     *             than zero
  84.143 -     */
  84.144 -    public HashSet(int initialCapacity) {
  84.145 -        map = new HashMap<>(initialCapacity);
  84.146 -    }
  84.147 -
  84.148 -    /**
  84.149 -     * Constructs a new, empty linked hash set.  (This package private
  84.150 -     * constructor is only used by LinkedHashSet.) The backing
  84.151 -     * HashMap instance is a LinkedHashMap with the specified initial
  84.152 -     * capacity and the specified load factor.
  84.153 -     *
  84.154 -     * @param      initialCapacity   the initial capacity of the hash map
  84.155 -     * @param      loadFactor        the load factor of the hash map
  84.156 -     * @param      dummy             ignored (distinguishes this
  84.157 -     *             constructor from other int, float constructor.)
  84.158 -     * @throws     IllegalArgumentException if the initial capacity is less
  84.159 -     *             than zero, or if the load factor is nonpositive
  84.160 -     */
  84.161 -    HashSet(int initialCapacity, float loadFactor, boolean dummy) {
  84.162 -        map = new LinkedHashMap<>(initialCapacity, loadFactor);
  84.163 -    }
  84.164 -
  84.165 -    /**
  84.166 -     * Returns an iterator over the elements in this set.  The elements
  84.167 -     * are returned in no particular order.
  84.168 -     *
  84.169 -     * @return an Iterator over the elements in this set
  84.170 -     * @see ConcurrentModificationException
  84.171 -     */
  84.172 -    public Iterator<E> iterator() {
  84.173 -        return map.keySet().iterator();
  84.174 -    }
  84.175 -
  84.176 -    /**
  84.177 -     * Returns the number of elements in this set (its cardinality).
  84.178 -     *
  84.179 -     * @return the number of elements in this set (its cardinality)
  84.180 -     */
  84.181 -    public int size() {
  84.182 -        return map.size();
  84.183 -    }
  84.184 -
  84.185 -    /**
  84.186 -     * Returns <tt>true</tt> if this set contains no elements.
  84.187 -     *
  84.188 -     * @return <tt>true</tt> if this set contains no elements
  84.189 -     */
  84.190 -    public boolean isEmpty() {
  84.191 -        return map.isEmpty();
  84.192 -    }
  84.193 -
  84.194 -    /**
  84.195 -     * Returns <tt>true</tt> if this set contains the specified element.
  84.196 -     * More formally, returns <tt>true</tt> if and only if this set
  84.197 -     * contains an element <tt>e</tt> such that
  84.198 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  84.199 -     *
  84.200 -     * @param o element whose presence in this set is to be tested
  84.201 -     * @return <tt>true</tt> if this set contains the specified element
  84.202 -     */
  84.203 -    public boolean contains(Object o) {
  84.204 -        return map.containsKey(o);
  84.205 -    }
  84.206 -
  84.207 -    /**
  84.208 -     * Adds the specified element to this set if it is not already present.
  84.209 -     * More formally, adds the specified element <tt>e</tt> to this set if
  84.210 -     * this set contains no element <tt>e2</tt> such that
  84.211 -     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
  84.212 -     * If this set already contains the element, the call leaves the set
  84.213 -     * unchanged and returns <tt>false</tt>.
  84.214 -     *
  84.215 -     * @param e element to be added to this set
  84.216 -     * @return <tt>true</tt> if this set did not already contain the specified
  84.217 -     * element
  84.218 -     */
  84.219 -    public boolean add(E e) {
  84.220 -        return map.put(e, PRESENT)==null;
  84.221 -    }
  84.222 -
  84.223 -    /**
  84.224 -     * Removes the specified element from this set if it is present.
  84.225 -     * More formally, removes an element <tt>e</tt> such that
  84.226 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
  84.227 -     * if this set contains such an element.  Returns <tt>true</tt> if
  84.228 -     * this set contained the element (or equivalently, if this set
  84.229 -     * changed as a result of the call).  (This set will not contain the
  84.230 -     * element once the call returns.)
  84.231 -     *
  84.232 -     * @param o object to be removed from this set, if present
  84.233 -     * @return <tt>true</tt> if the set contained the specified element
  84.234 -     */
  84.235 -    public boolean remove(Object o) {
  84.236 -        return map.remove(o)==PRESENT;
  84.237 -    }
  84.238 -
  84.239 -    /**
  84.240 -     * Removes all of the elements from this set.
  84.241 -     * The set will be empty after this call returns.
  84.242 -     */
  84.243 -    public void clear() {
  84.244 -        map.clear();
  84.245 -    }
  84.246 -
  84.247 -    /**
  84.248 -     * Returns a shallow copy of this <tt>HashSet</tt> instance: the elements
  84.249 -     * themselves are not cloned.
  84.250 -     *
  84.251 -     * @return a shallow copy of this set
  84.252 -     */
  84.253 -    public Object clone() {
  84.254 -        try {
  84.255 -            HashSet<E> newSet = (HashSet<E>) super.clone();
  84.256 -            newSet.map = (HashMap<E, Object>) map.clone();
  84.257 -            return newSet;
  84.258 -        } catch (CloneNotSupportedException e) {
  84.259 -            throw new InternalError();
  84.260 -        }
  84.261 -    }
  84.262 -
  84.263 -}
    85.1 --- a/emul/compact/src/main/java/java/util/Hashtable.java	Mon Feb 25 19:00:08 2013 +0100
    85.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.3 @@ -1,1005 +0,0 @@
    85.4 -/*
    85.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
    85.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    85.7 - *
    85.8 - * This code is free software; you can redistribute it and/or modify it
    85.9 - * under the terms of the GNU General Public License version 2 only, as
   85.10 - * published by the Free Software Foundation.  Oracle designates this
   85.11 - * particular file as subject to the "Classpath" exception as provided
   85.12 - * by Oracle in the LICENSE file that accompanied this code.
   85.13 - *
   85.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   85.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   85.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   85.17 - * version 2 for more details (a copy is included in the LICENSE file that
   85.18 - * accompanied this code).
   85.19 - *
   85.20 - * You should have received a copy of the GNU General Public License version
   85.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   85.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   85.23 - *
   85.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   85.25 - * or visit www.oracle.com if you need additional information or have any
   85.26 - * questions.
   85.27 - */
   85.28 -
   85.29 -package java.util;
   85.30 -import java.io.*;
   85.31 -
   85.32 -/**
   85.33 - * This class implements a hash table, which maps keys to values. Any
   85.34 - * non-<code>null</code> object can be used as a key or as a value. <p>
   85.35 - *
   85.36 - * To successfully store and retrieve objects from a hashtable, the
   85.37 - * objects used as keys must implement the <code>hashCode</code>
   85.38 - * method and the <code>equals</code> method. <p>
   85.39 - *
   85.40 - * An instance of <code>Hashtable</code> has two parameters that affect its
   85.41 - * performance: <i>initial capacity</i> and <i>load factor</i>.  The
   85.42 - * <i>capacity</i> is the number of <i>buckets</i> in the hash table, and the
   85.43 - * <i>initial capacity</i> is simply the capacity at the time the hash table
   85.44 - * is created.  Note that the hash table is <i>open</i>: in the case of a "hash
   85.45 - * collision", a single bucket stores multiple entries, which must be searched
   85.46 - * sequentially.  The <i>load factor</i> is a measure of how full the hash
   85.47 - * table is allowed to get before its capacity is automatically increased.
   85.48 - * The initial capacity and load factor parameters are merely hints to
   85.49 - * the implementation.  The exact details as to when and whether the rehash
   85.50 - * method is invoked are implementation-dependent.<p>
   85.51 - *
   85.52 - * Generally, the default load factor (.75) offers a good tradeoff between
   85.53 - * time and space costs.  Higher values decrease the space overhead but
   85.54 - * increase the time cost to look up an entry (which is reflected in most
   85.55 - * <tt>Hashtable</tt> operations, including <tt>get</tt> and <tt>put</tt>).<p>
   85.56 - *
   85.57 - * The initial capacity controls a tradeoff between wasted space and the
   85.58 - * need for <code>rehash</code> operations, which are time-consuming.
   85.59 - * No <code>rehash</code> operations will <i>ever</i> occur if the initial
   85.60 - * capacity is greater than the maximum number of entries the
   85.61 - * <tt>Hashtable</tt> will contain divided by its load factor.  However,
   85.62 - * setting the initial capacity too high can waste space.<p>
   85.63 - *
   85.64 - * If many entries are to be made into a <code>Hashtable</code>,
   85.65 - * creating it with a sufficiently large capacity may allow the
   85.66 - * entries to be inserted more efficiently than letting it perform
   85.67 - * automatic rehashing as needed to grow the table. <p>
   85.68 - *
   85.69 - * This example creates a hashtable of numbers. It uses the names of
   85.70 - * the numbers as keys:
   85.71 - * <pre>   {@code
   85.72 - *   Hashtable<String, Integer> numbers
   85.73 - *     = new Hashtable<String, Integer>();
   85.74 - *   numbers.put("one", 1);
   85.75 - *   numbers.put("two", 2);
   85.76 - *   numbers.put("three", 3);}</pre>
   85.77 - *
   85.78 - * <p>To retrieve a number, use the following code:
   85.79 - * <pre>   {@code
   85.80 - *   Integer n = numbers.get("two");
   85.81 - *   if (n != null) {
   85.82 - *     System.out.println("two = " + n);
   85.83 - *   }}</pre>
   85.84 - *
   85.85 - * <p>The iterators returned by the <tt>iterator</tt> method of the collections
   85.86 - * returned by all of this class's "collection view methods" are
   85.87 - * <em>fail-fast</em>: if the Hashtable is structurally modified at any time
   85.88 - * after the iterator is created, in any way except through the iterator's own
   85.89 - * <tt>remove</tt> method, the iterator will throw a {@link
   85.90 - * ConcurrentModificationException}.  Thus, in the face of concurrent
   85.91 - * modification, the iterator fails quickly and cleanly, rather than risking
   85.92 - * arbitrary, non-deterministic behavior at an undetermined time in the future.
   85.93 - * The Enumerations returned by Hashtable's keys and elements methods are
   85.94 - * <em>not</em> fail-fast.
   85.95 - *
   85.96 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   85.97 - * as it is, generally speaking, impossible to make any hard guarantees in the
   85.98 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
   85.99 - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  85.100 - * Therefore, it would be wrong to write a program that depended on this
  85.101 - * exception for its correctness: <i>the fail-fast behavior of iterators
  85.102 - * should be used only to detect bugs.</i>
  85.103 - *
  85.104 - * <p>As of the Java 2 platform v1.2, this class was retrofitted to
  85.105 - * implement the {@link Map} interface, making it a member of the
  85.106 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  85.107 - *
  85.108 - * Java Collections Framework</a>.  Unlike the new collection
  85.109 - * implementations, {@code Hashtable} is synchronized.  If a
  85.110 - * thread-safe implementation is not needed, it is recommended to use
  85.111 - * {@link HashMap} in place of {@code Hashtable}.  If a thread-safe
  85.112 - * highly-concurrent implementation is desired, then it is recommended
  85.113 - * to use {@link java.util.concurrent.ConcurrentHashMap} in place of
  85.114 - * {@code Hashtable}.
  85.115 - *
  85.116 - * @author  Arthur van Hoff
  85.117 - * @author  Josh Bloch
  85.118 - * @author  Neal Gafter
  85.119 - * @see     Object#equals(java.lang.Object)
  85.120 - * @see     Object#hashCode()
  85.121 - * @see     Hashtable#rehash()
  85.122 - * @see     Collection
  85.123 - * @see     Map
  85.124 - * @see     HashMap
  85.125 - * @see     TreeMap
  85.126 - * @since JDK1.0
  85.127 - */
  85.128 -public class Hashtable<K,V>
  85.129 -    extends Dictionary<K,V>
  85.130 -    implements Map<K,V>, Cloneable, java.io.Serializable {
  85.131 -
  85.132 -    /**
  85.133 -     * The hash table data.
  85.134 -     */
  85.135 -    private transient Entry[] table;
  85.136 -
  85.137 -    /**
  85.138 -     * The total number of entries in the hash table.
  85.139 -     */
  85.140 -    private transient int count;
  85.141 -
  85.142 -    /**
  85.143 -     * The table is rehashed when its size exceeds this threshold.  (The
  85.144 -     * value of this field is (int)(capacity * loadFactor).)
  85.145 -     *
  85.146 -     * @serial
  85.147 -     */
  85.148 -    private int threshold;
  85.149 -
  85.150 -    /**
  85.151 -     * The load factor for the hashtable.
  85.152 -     *
  85.153 -     * @serial
  85.154 -     */
  85.155 -    private float loadFactor;
  85.156 -
  85.157 -    /**
  85.158 -     * The number of times this Hashtable has been structurally modified
  85.159 -     * Structural modifications are those that change the number of entries in
  85.160 -     * the Hashtable or otherwise modify its internal structure (e.g.,
  85.161 -     * rehash).  This field is used to make iterators on Collection-views of
  85.162 -     * the Hashtable fail-fast.  (See ConcurrentModificationException).
  85.163 -     */
  85.164 -    private transient int modCount = 0;
  85.165 -
  85.166 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  85.167 -    private static final long serialVersionUID = 1421746759512286392L;
  85.168 -
  85.169 -    /**
  85.170 -     * Constructs a new, empty hashtable with the specified initial
  85.171 -     * capacity and the specified load factor.
  85.172 -     *
  85.173 -     * @param      initialCapacity   the initial capacity of the hashtable.
  85.174 -     * @param      loadFactor        the load factor of the hashtable.
  85.175 -     * @exception  IllegalArgumentException  if the initial capacity is less
  85.176 -     *             than zero, or if the load factor is nonpositive.
  85.177 -     */
  85.178 -    public Hashtable(int initialCapacity, float loadFactor) {
  85.179 -        if (initialCapacity < 0)
  85.180 -            throw new IllegalArgumentException("Illegal Capacity: "+
  85.181 -                                               initialCapacity);
  85.182 -        if (loadFactor <= 0 || Float.isNaN(loadFactor))
  85.183 -            throw new IllegalArgumentException("Illegal Load: "+loadFactor);
  85.184 -
  85.185 -        if (initialCapacity==0)
  85.186 -            initialCapacity = 1;
  85.187 -        this.loadFactor = loadFactor;
  85.188 -        table = new Entry[initialCapacity];
  85.189 -        threshold = (int)(initialCapacity * loadFactor);
  85.190 -    }
  85.191 -
  85.192 -    /**
  85.193 -     * Constructs a new, empty hashtable with the specified initial capacity
  85.194 -     * and default load factor (0.75).
  85.195 -     *
  85.196 -     * @param     initialCapacity   the initial capacity of the hashtable.
  85.197 -     * @exception IllegalArgumentException if the initial capacity is less
  85.198 -     *              than zero.
  85.199 -     */
  85.200 -    public Hashtable(int initialCapacity) {
  85.201 -        this(initialCapacity, 0.75f);
  85.202 -    }
  85.203 -
  85.204 -    /**
  85.205 -     * Constructs a new, empty hashtable with a default initial capacity (11)
  85.206 -     * and load factor (0.75).
  85.207 -     */
  85.208 -    public Hashtable() {
  85.209 -        this(11, 0.75f);
  85.210 -    }
  85.211 -
  85.212 -    /**
  85.213 -     * Constructs a new hashtable with the same mappings as the given
  85.214 -     * Map.  The hashtable is created with an initial capacity sufficient to
  85.215 -     * hold the mappings in the given Map and a default load factor (0.75).
  85.216 -     *
  85.217 -     * @param t the map whose mappings are to be placed in this map.
  85.218 -     * @throws NullPointerException if the specified map is null.
  85.219 -     * @since   1.2
  85.220 -     */
  85.221 -    public Hashtable(Map<? extends K, ? extends V> t) {
  85.222 -        this(Math.max(2*t.size(), 11), 0.75f);
  85.223 -        putAll(t);
  85.224 -    }
  85.225 -
  85.226 -    /**
  85.227 -     * Returns the number of keys in this hashtable.
  85.228 -     *
  85.229 -     * @return  the number of keys in this hashtable.
  85.230 -     */
  85.231 -    public synchronized int size() {
  85.232 -        return count;
  85.233 -    }
  85.234 -
  85.235 -    /**
  85.236 -     * Tests if this hashtable maps no keys to values.
  85.237 -     *
  85.238 -     * @return  <code>true</code> if this hashtable maps no keys to values;
  85.239 -     *          <code>false</code> otherwise.
  85.240 -     */
  85.241 -    public synchronized boolean isEmpty() {
  85.242 -        return count == 0;
  85.243 -    }
  85.244 -
  85.245 -    /**
  85.246 -     * Returns an enumeration of the keys in this hashtable.
  85.247 -     *
  85.248 -     * @return  an enumeration of the keys in this hashtable.
  85.249 -     * @see     Enumeration
  85.250 -     * @see     #elements()
  85.251 -     * @see     #keySet()
  85.252 -     * @see     Map
  85.253 -     */
  85.254 -    public synchronized Enumeration<K> keys() {
  85.255 -        return this.<K>getEnumeration(KEYS);
  85.256 -    }
  85.257 -
  85.258 -    /**
  85.259 -     * Returns an enumeration of the values in this hashtable.
  85.260 -     * Use the Enumeration methods on the returned object to fetch the elements
  85.261 -     * sequentially.
  85.262 -     *
  85.263 -     * @return  an enumeration of the values in this hashtable.
  85.264 -     * @see     java.util.Enumeration
  85.265 -     * @see     #keys()
  85.266 -     * @see     #values()
  85.267 -     * @see     Map
  85.268 -     */
  85.269 -    public synchronized Enumeration<V> elements() {
  85.270 -        return this.<V>getEnumeration(VALUES);
  85.271 -    }
  85.272 -
  85.273 -    /**
  85.274 -     * Tests if some key maps into the specified value in this hashtable.
  85.275 -     * This operation is more expensive than the {@link #containsKey
  85.276 -     * containsKey} method.
  85.277 -     *
  85.278 -     * <p>Note that this method is identical in functionality to
  85.279 -     * {@link #containsValue containsValue}, (which is part of the
  85.280 -     * {@link Map} interface in the collections framework).
  85.281 -     *
  85.282 -     * @param      value   a value to search for
  85.283 -     * @return     <code>true</code> if and only if some key maps to the
  85.284 -     *             <code>value</code> argument in this hashtable as
  85.285 -     *             determined by the <tt>equals</tt> method;
  85.286 -     *             <code>false</code> otherwise.
  85.287 -     * @exception  NullPointerException  if the value is <code>null</code>
  85.288 -     */
  85.289 -    public synchronized boolean contains(Object value) {
  85.290 -        if (value == null) {
  85.291 -            throw new NullPointerException();
  85.292 -        }
  85.293 -
  85.294 -        Entry tab[] = table;
  85.295 -        for (int i = tab.length ; i-- > 0 ;) {
  85.296 -            for (Entry<K,V> e = tab[i] ; e != null ; e = e.next) {
  85.297 -                if (e.value.equals(value)) {
  85.298 -                    return true;
  85.299 -                }
  85.300 -            }
  85.301 -        }
  85.302 -        return false;
  85.303 -    }
  85.304 -
  85.305 -    /**
  85.306 -     * Returns true if this hashtable maps one or more keys to this value.
  85.307 -     *
  85.308 -     * <p>Note that this method is identical in functionality to {@link
  85.309 -     * #contains contains} (which predates the {@link Map} interface).
  85.310 -     *
  85.311 -     * @param value value whose presence in this hashtable is to be tested
  85.312 -     * @return <tt>true</tt> if this map maps one or more keys to the
  85.313 -     *         specified value
  85.314 -     * @throws NullPointerException  if the value is <code>null</code>
  85.315 -     * @since 1.2
  85.316 -     */
  85.317 -    public boolean containsValue(Object value) {
  85.318 -        return contains(value);
  85.319 -    }
  85.320 -
  85.321 -    /**
  85.322 -     * Tests if the specified object is a key in this hashtable.
  85.323 -     *
  85.324 -     * @param   key   possible key
  85.325 -     * @return  <code>true</code> if and only if the specified object
  85.326 -     *          is a key in this hashtable, as determined by the
  85.327 -     *          <tt>equals</tt> method; <code>false</code> otherwise.
  85.328 -     * @throws  NullPointerException  if the key is <code>null</code>
  85.329 -     * @see     #contains(Object)
  85.330 -     */
  85.331 -    public synchronized boolean containsKey(Object key) {
  85.332 -        Entry tab[] = table;
  85.333 -        int hash = key.hashCode();
  85.334 -        int index = (hash & 0x7FFFFFFF) % tab.length;
  85.335 -        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
  85.336 -            if ((e.hash == hash) && e.key.equals(key)) {
  85.337 -                return true;
  85.338 -            }
  85.339 -        }
  85.340 -        return false;
  85.341 -    }
  85.342 -
  85.343 -    /**
  85.344 -     * Returns the value to which the specified key is mapped,
  85.345 -     * or {@code null} if this map contains no mapping for the key.
  85.346 -     *
  85.347 -     * <p>More formally, if this map contains a mapping from a key
  85.348 -     * {@code k} to a value {@code v} such that {@code (key.equals(k))},
  85.349 -     * then this method returns {@code v}; otherwise it returns
  85.350 -     * {@code null}.  (There can be at most one such mapping.)
  85.351 -     *
  85.352 -     * @param key the key whose associated value is to be returned
  85.353 -     * @return the value to which the specified key is mapped, or
  85.354 -     *         {@code null} if this map contains no mapping for the key
  85.355 -     * @throws NullPointerException if the specified key is null
  85.356 -     * @see     #put(Object, Object)
  85.357 -     */
  85.358 -    public synchronized V get(Object key) {
  85.359 -        Entry tab[] = table;
  85.360 -        int hash = key.hashCode();
  85.361 -        int index = (hash & 0x7FFFFFFF) % tab.length;
  85.362 -        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
  85.363 -            if ((e.hash == hash) && e.key.equals(key)) {
  85.364 -                return e.value;
  85.365 -            }
  85.366 -        }
  85.367 -        return null;
  85.368 -    }
  85.369 -
  85.370 -    /**
  85.371 -     * The maximum size of array to allocate.
  85.372 -     * Some VMs reserve some header words in an array.
  85.373 -     * Attempts to allocate larger arrays may result in
  85.374 -     * OutOfMemoryError: Requested array size exceeds VM limit
  85.375 -     */
  85.376 -    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  85.377 -
  85.378 -    /**
  85.379 -     * Increases the capacity of and internally reorganizes this
  85.380 -     * hashtable, in order to accommodate and access its entries more
  85.381 -     * efficiently.  This method is called automatically when the
  85.382 -     * number of keys in the hashtable exceeds this hashtable's capacity
  85.383 -     * and load factor.
  85.384 -     */
  85.385 -    protected void rehash() {
  85.386 -        int oldCapacity = table.length;
  85.387 -        Entry[] oldMap = table;
  85.388 -
  85.389 -        // overflow-conscious code
  85.390 -        int newCapacity = (oldCapacity << 1) + 1;
  85.391 -        if (newCapacity - MAX_ARRAY_SIZE > 0) {
  85.392 -            if (oldCapacity == MAX_ARRAY_SIZE)
  85.393 -                // Keep running with MAX_ARRAY_SIZE buckets
  85.394 -                return;
  85.395 -            newCapacity = MAX_ARRAY_SIZE;
  85.396 -        }
  85.397 -        Entry[] newMap = new Entry[newCapacity];
  85.398 -
  85.399 -        modCount++;
  85.400 -        threshold = (int)(newCapacity * loadFactor);
  85.401 -        table = newMap;
  85.402 -
  85.403 -        for (int i = oldCapacity ; i-- > 0 ;) {
  85.404 -            for (Entry<K,V> old = oldMap[i] ; old != null ; ) {
  85.405 -                Entry<K,V> e = old;
  85.406 -                old = old.next;
  85.407 -
  85.408 -                int index = (e.hash & 0x7FFFFFFF) % newCapacity;
  85.409 -                e.next = newMap[index];
  85.410 -                newMap[index] = e;
  85.411 -            }
  85.412 -        }
  85.413 -    }
  85.414 -
  85.415 -    /**
  85.416 -     * Maps the specified <code>key</code> to the specified
  85.417 -     * <code>value</code> in this hashtable. Neither the key nor the
  85.418 -     * value can be <code>null</code>. <p>
  85.419 -     *
  85.420 -     * The value can be retrieved by calling the <code>get</code> method
  85.421 -     * with a key that is equal to the original key.
  85.422 -     *
  85.423 -     * @param      key     the hashtable key
  85.424 -     * @param      value   the value
  85.425 -     * @return     the previous value of the specified key in this hashtable,
  85.426 -     *             or <code>null</code> if it did not have one
  85.427 -     * @exception  NullPointerException  if the key or value is
  85.428 -     *               <code>null</code>
  85.429 -     * @see     Object#equals(Object)
  85.430 -     * @see     #get(Object)
  85.431 -     */
  85.432 -    public synchronized V put(K key, V value) {
  85.433 -        // Make sure the value is not null
  85.434 -        if (value == null) {
  85.435 -            throw new NullPointerException();
  85.436 -        }
  85.437 -
  85.438 -        // Makes sure the key is not already in the hashtable.
  85.439 -        Entry tab[] = table;
  85.440 -        int hash = key.hashCode();
  85.441 -        int index = (hash & 0x7FFFFFFF) % tab.length;
  85.442 -        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
  85.443 -            if ((e.hash == hash) && e.key.equals(key)) {
  85.444 -                V old = e.value;
  85.445 -                e.value = value;
  85.446 -                return old;
  85.447 -            }
  85.448 -        }
  85.449 -
  85.450 -        modCount++;
  85.451 -        if (count >= threshold) {
  85.452 -            // Rehash the table if the threshold is exceeded
  85.453 -            rehash();
  85.454 -
  85.455 -            tab = table;
  85.456 -            index = (hash & 0x7FFFFFFF) % tab.length;
  85.457 -        }
  85.458 -
  85.459 -        // Creates the new entry.
  85.460 -        Entry<K,V> e = tab[index];
  85.461 -        tab[index] = new Entry<>(hash, key, value, e);
  85.462 -        count++;
  85.463 -        return null;
  85.464 -    }
  85.465 -
  85.466 -    /**
  85.467 -     * Removes the key (and its corresponding value) from this
  85.468 -     * hashtable. This method does nothing if the key is not in the hashtable.
  85.469 -     *
  85.470 -     * @param   key   the key that needs to be removed
  85.471 -     * @return  the value to which the key had been mapped in this hashtable,
  85.472 -     *          or <code>null</code> if the key did not have a mapping
  85.473 -     * @throws  NullPointerException  if the key is <code>null</code>
  85.474 -     */
  85.475 -    public synchronized V remove(Object key) {
  85.476 -        Entry tab[] = table;
  85.477 -        int hash = key.hashCode();
  85.478 -        int index = (hash & 0x7FFFFFFF) % tab.length;
  85.479 -        for (Entry<K,V> e = tab[index], prev = null ; e != null ; prev = e, e = e.next) {
  85.480 -            if ((e.hash == hash) && e.key.equals(key)) {
  85.481 -                modCount++;
  85.482 -                if (prev != null) {
  85.483 -                    prev.next = e.next;
  85.484 -                } else {
  85.485 -                    tab[index] = e.next;
  85.486 -                }
  85.487 -                count--;
  85.488 -                V oldValue = e.value;
  85.489 -                e.value = null;
  85.490 -                return oldValue;
  85.491 -            }
  85.492 -        }
  85.493 -        return null;
  85.494 -    }
  85.495 -
  85.496 -    /**
  85.497 -     * Copies all of the mappings from the specified map to this hashtable.
  85.498 -     * These mappings will replace any mappings that this hashtable had for any
  85.499 -     * of the keys currently in the specified map.
  85.500 -     *
  85.501 -     * @param t mappings to be stored in this map
  85.502 -     * @throws NullPointerException if the specified map is null
  85.503 -     * @since 1.2
  85.504 -     */
  85.505 -    public synchronized void putAll(Map<? extends K, ? extends V> t) {
  85.506 -        for (Map.Entry<? extends K, ? extends V> e : t.entrySet())
  85.507 -            put(e.getKey(), e.getValue());
  85.508 -    }
  85.509 -
  85.510 -    /**
  85.511 -     * Clears this hashtable so that it contains no keys.
  85.512 -     */
  85.513 -    public synchronized void clear() {
  85.514 -        Entry tab[] = table;
  85.515 -        modCount++;
  85.516 -        for (int index = tab.length; --index >= 0; )
  85.517 -            tab[index] = null;
  85.518 -        count = 0;
  85.519 -    }
  85.520 -
  85.521 -    /**
  85.522 -     * Creates a shallow copy of this hashtable. All the structure of the
  85.523 -     * hashtable itself is copied, but the keys and values are not cloned.
  85.524 -     * This is a relatively expensive operation.
  85.525 -     *
  85.526 -     * @return  a clone of the hashtable
  85.527 -     */
  85.528 -    public synchronized Object clone() {
  85.529 -        try {
  85.530 -            Hashtable<K,V> t = (Hashtable<K,V>) super.clone();
  85.531 -            t.table = new Entry[table.length];
  85.532 -            for (int i = table.length ; i-- > 0 ; ) {
  85.533 -                t.table[i] = (table[i] != null)
  85.534 -                    ? (Entry<K,V>) table[i].clone() : null;
  85.535 -            }
  85.536 -            t.keySet = null;
  85.537 -            t.entrySet = null;
  85.538 -            t.values = null;
  85.539 -            t.modCount = 0;
  85.540 -            return t;
  85.541 -        } catch (CloneNotSupportedException e) {
  85.542 -            // this shouldn't happen, since we are Cloneable
  85.543 -            throw new InternalError();
  85.544 -        }
  85.545 -    }
  85.546 -
  85.547 -    /**
  85.548 -     * Returns a string representation of this <tt>Hashtable</tt> object
  85.549 -     * in the form of a set of entries, enclosed in braces and separated
  85.550 -     * by the ASCII characters "<tt>,&nbsp;</tt>" (comma and space). Each
  85.551 -     * entry is rendered as the key, an equals sign <tt>=</tt>, and the
  85.552 -     * associated element, where the <tt>toString</tt> method is used to
  85.553 -     * convert the key and element to strings.
  85.554 -     *
  85.555 -     * @return  a string representation of this hashtable
  85.556 -     */
  85.557 -    public synchronized String toString() {
  85.558 -        int max = size() - 1;
  85.559 -        if (max == -1)
  85.560 -            return "{}";
  85.561 -
  85.562 -        StringBuilder sb = new StringBuilder();
  85.563 -        Iterator<Map.Entry<K,V>> it = entrySet().iterator();
  85.564 -
  85.565 -        sb.append('{');
  85.566 -        for (int i = 0; ; i++) {
  85.567 -            Map.Entry<K,V> e = it.next();
  85.568 -            K key = e.getKey();
  85.569 -            V value = e.getValue();
  85.570 -            sb.append(key   == this ? "(this Map)" : key.toString());
  85.571 -            sb.append('=');
  85.572 -            sb.append(value == this ? "(this Map)" : value.toString());
  85.573 -
  85.574 -            if (i == max)
  85.575 -                return sb.append('}').toString();
  85.576 -            sb.append(", ");
  85.577 -        }
  85.578 -    }
  85.579 -
  85.580 -
  85.581 -    private <T> Enumeration<T> getEnumeration(int type) {
  85.582 -        if (count == 0) {
  85.583 -            return Collections.emptyEnumeration();
  85.584 -        } else {
  85.585 -            return new Enumerator<>(type, false);
  85.586 -        }
  85.587 -    }
  85.588 -
  85.589 -    private <T> Iterator<T> getIterator(int type) {
  85.590 -        if (count == 0) {
  85.591 -            return Collections.emptyIterator();
  85.592 -        } else {
  85.593 -            return new Enumerator<>(type, true);
  85.594 -        }
  85.595 -    }
  85.596 -
  85.597 -    // Views
  85.598 -
  85.599 -    /**
  85.600 -     * Each of these fields are initialized to contain an instance of the
  85.601 -     * appropriate view the first time this view is requested.  The views are
  85.602 -     * stateless, so there's no reason to create more than one of each.
  85.603 -     */
  85.604 -    private transient volatile Set<K> keySet = null;
  85.605 -    private transient volatile Set<Map.Entry<K,V>> entrySet = null;
  85.606 -    private transient volatile Collection<V> values = null;
  85.607 -
  85.608 -    /**
  85.609 -     * Returns a {@link Set} view of the keys contained in this map.
  85.610 -     * The set is backed by the map, so changes to the map are
  85.611 -     * reflected in the set, and vice-versa.  If the map is modified
  85.612 -     * while an iteration over the set is in progress (except through
  85.613 -     * the iterator's own <tt>remove</tt> operation), the results of
  85.614 -     * the iteration are undefined.  The set supports element removal,
  85.615 -     * which removes the corresponding mapping from the map, via the
  85.616 -     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
  85.617 -     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
  85.618 -     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
  85.619 -     * operations.
  85.620 -     *
  85.621 -     * @since 1.2
  85.622 -     */
  85.623 -    public Set<K> keySet() {
  85.624 -        if (keySet == null)
  85.625 -            keySet = Collections.synchronizedSet(new KeySet(), this);
  85.626 -        return keySet;
  85.627 -    }
  85.628 -
  85.629 -    private class KeySet extends AbstractSet<K> {
  85.630 -        public Iterator<K> iterator() {
  85.631 -            return getIterator(KEYS);
  85.632 -        }
  85.633 -        public int size() {
  85.634 -            return count;
  85.635 -        }
  85.636 -        public boolean contains(Object o) {
  85.637 -            return containsKey(o);
  85.638 -        }
  85.639 -        public boolean remove(Object o) {
  85.640 -            return Hashtable.this.remove(o) != null;
  85.641 -        }
  85.642 -        public void clear() {
  85.643 -            Hashtable.this.clear();
  85.644 -        }
  85.645 -    }
  85.646 -
  85.647 -    /**
  85.648 -     * Returns a {@link Set} view of the mappings contained in this map.
  85.649 -     * The set is backed by the map, so changes to the map are
  85.650 -     * reflected in the set, and vice-versa.  If the map is modified
  85.651 -     * while an iteration over the set is in progress (except through
  85.652 -     * the iterator's own <tt>remove</tt> operation, or through the
  85.653 -     * <tt>setValue</tt> operation on a map entry returned by the
  85.654 -     * iterator) the results of the iteration are undefined.  The set
  85.655 -     * supports element removal, which removes the corresponding
  85.656 -     * mapping from the map, via the <tt>Iterator.remove</tt>,
  85.657 -     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  85.658 -     * <tt>clear</tt> operations.  It does not support the
  85.659 -     * <tt>add</tt> or <tt>addAll</tt> operations.
  85.660 -     *
  85.661 -     * @since 1.2
  85.662 -     */
  85.663 -    public Set<Map.Entry<K,V>> entrySet() {
  85.664 -        if (entrySet==null)
  85.665 -            entrySet = Collections.synchronizedSet(new EntrySet(), this);
  85.666 -        return entrySet;
  85.667 -    }
  85.668 -
  85.669 -    private class EntrySet extends AbstractSet<Map.Entry<K,V>> {
  85.670 -        public Iterator<Map.Entry<K,V>> iterator() {
  85.671 -            return getIterator(ENTRIES);
  85.672 -        }
  85.673 -
  85.674 -        public boolean add(Map.Entry<K,V> o) {
  85.675 -            return super.add(o);
  85.676 -        }
  85.677 -
  85.678 -        public boolean contains(Object o) {
  85.679 -            if (!(o instanceof Map.Entry))
  85.680 -                return false;
  85.681 -            Map.Entry entry = (Map.Entry)o;
  85.682 -            Object key = entry.getKey();
  85.683 -            Entry[] tab = table;
  85.684 -            int hash = key.hashCode();
  85.685 -            int index = (hash & 0x7FFFFFFF) % tab.length;
  85.686 -
  85.687 -            for (Entry e = tab[index]; e != null; e = e.next)
  85.688 -                if (e.hash==hash && e.equals(entry))
  85.689 -                    return true;
  85.690 -            return false;
  85.691 -        }
  85.692 -
  85.693 -        public boolean remove(Object o) {
  85.694 -            if (!(o instanceof Map.Entry))
  85.695 -                return false;
  85.696 -            Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
  85.697 -            K key = entry.getKey();
  85.698 -            Entry[] tab = table;
  85.699 -            int hash = key.hashCode();
  85.700 -            int index = (hash & 0x7FFFFFFF) % tab.length;
  85.701 -
  85.702 -            for (Entry<K,V> e = tab[index], prev = null; e != null;
  85.703 -                 prev = e, e = e.next) {
  85.704 -                if (e.hash==hash && e.equals(entry)) {
  85.705 -                    modCount++;
  85.706 -                    if (prev != null)
  85.707 -                        prev.next = e.next;
  85.708 -                    else
  85.709 -                        tab[index] = e.next;
  85.710 -
  85.711 -                    count--;
  85.712 -                    e.value = null;
  85.713 -                    return true;
  85.714 -                }
  85.715 -            }
  85.716 -            return false;
  85.717 -        }
  85.718 -
  85.719 -        public int size() {
  85.720 -            return count;
  85.721 -        }
  85.722 -
  85.723 -        public void clear() {
  85.724 -            Hashtable.this.clear();
  85.725 -        }
  85.726 -    }
  85.727 -
  85.728 -    /**
  85.729 -     * Returns a {@link Collection} view of the values contained in this map.
  85.730 -     * The collection is backed by the map, so changes to the map are
  85.731 -     * reflected in the collection, and vice-versa.  If the map is
  85.732 -     * modified while an iteration over the collection is in progress
  85.733 -     * (except through the iterator's own <tt>remove</tt> operation),
  85.734 -     * the results of the iteration are undefined.  The collection
  85.735 -     * supports element removal, which removes the corresponding
  85.736 -     * mapping from the map, via the <tt>Iterator.remove</tt>,
  85.737 -     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
  85.738 -     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
  85.739 -     * support the <tt>add</tt> or <tt>addAll</tt> operations.
  85.740 -     *
  85.741 -     * @since 1.2
  85.742 -     */
  85.743 -    public Collection<V> values() {
  85.744 -        if (values==null)
  85.745 -            values = Collections.synchronizedCollection(new ValueCollection(),
  85.746 -                                                        this);
  85.747 -        return values;
  85.748 -    }
  85.749 -
  85.750 -    private class ValueCollection extends AbstractCollection<V> {
  85.751 -        public Iterator<V> iterator() {
  85.752 -            return getIterator(VALUES);
  85.753 -        }
  85.754 -        public int size() {
  85.755 -            return count;
  85.756 -        }
  85.757 -        public boolean contains(Object o) {
  85.758 -            return containsValue(o);
  85.759 -        }
  85.760 -        public void clear() {
  85.761 -            Hashtable.this.clear();
  85.762 -        }
  85.763 -    }
  85.764 -
  85.765 -    // Comparison and hashing
  85.766 -
  85.767 -    /**
  85.768 -     * Compares the specified Object with this Map for equality,
  85.769 -     * as per the definition in the Map interface.
  85.770 -     *
  85.771 -     * @param  o object to be compared for equality with this hashtable
  85.772 -     * @return true if the specified Object is equal to this Map
  85.773 -     * @see Map#equals(Object)
  85.774 -     * @since 1.2
  85.775 -     */
  85.776 -    public synchronized boolean equals(Object o) {
  85.777 -        if (o == this)
  85.778 -            return true;
  85.779 -
  85.780 -        if (!(o instanceof Map))
  85.781 -            return false;
  85.782 -        Map<K,V> t = (Map<K,V>) o;
  85.783 -        if (t.size() != size())
  85.784 -            return false;
  85.785 -
  85.786 -        try {
  85.787 -            Iterator<Map.Entry<K,V>> i = entrySet().iterator();
  85.788 -            while (i.hasNext()) {
  85.789 -                Map.Entry<K,V> e = i.next();
  85.790 -                K key = e.getKey();
  85.791 -                V value = e.getValue();
  85.792 -                if (value == null) {
  85.793 -                    if (!(t.get(key)==null && t.containsKey(key)))
  85.794 -                        return false;
  85.795 -                } else {
  85.796 -                    if (!value.equals(t.get(key)))
  85.797 -                        return false;
  85.798 -                }
  85.799 -            }
  85.800 -        } catch (ClassCastException unused)   {
  85.801 -            return false;
  85.802 -        } catch (NullPointerException unused) {
  85.803 -            return false;
  85.804 -        }
  85.805 -
  85.806 -        return true;
  85.807 -    }
  85.808 -
  85.809 -    /**
  85.810 -     * Returns the hash code value for this Map as per the definition in the
  85.811 -     * Map interface.
  85.812 -     *
  85.813 -     * @see Map#hashCode()
  85.814 -     * @since 1.2
  85.815 -     */
  85.816 -    public synchronized int hashCode() {
  85.817 -        /*
  85.818 -         * This code detects the recursion caused by computing the hash code
  85.819 -         * of a self-referential hash table and prevents the stack overflow
  85.820 -         * that would otherwise result.  This allows certain 1.1-era
  85.821 -         * applets with self-referential hash tables to work.  This code
  85.822 -         * abuses the loadFactor field to do double-duty as a hashCode
  85.823 -         * in progress flag, so as not to worsen the space performance.
  85.824 -         * A negative load factor indicates that hash code computation is
  85.825 -         * in progress.
  85.826 -         */
  85.827 -        int h = 0;
  85.828 -        if (count == 0 || loadFactor < 0)
  85.829 -            return h;  // Returns zero
  85.830 -
  85.831 -        loadFactor = -loadFactor;  // Mark hashCode computation in progress
  85.832 -        Entry[] tab = table;
  85.833 -        for (int i = 0; i < tab.length; i++)
  85.834 -            for (Entry e = tab[i]; e != null; e = e.next)
  85.835 -                h += e.key.hashCode() ^ e.value.hashCode();
  85.836 -        loadFactor = -loadFactor;  // Mark hashCode computation complete
  85.837 -
  85.838 -        return h;
  85.839 -    }
  85.840 -
  85.841 -    /**
  85.842 -     * Hashtable collision list.
  85.843 -     */
  85.844 -    private static class Entry<K,V> implements Map.Entry<K,V> {
  85.845 -        int hash;
  85.846 -        K key;
  85.847 -        V value;
  85.848 -        Entry<K,V> next;
  85.849 -
  85.850 -        protected Entry(int hash, K key, V value, Entry<K,V> next) {
  85.851 -            this.hash = hash;
  85.852 -            this.key = key;
  85.853 -            this.value = value;
  85.854 -            this.next = next;
  85.855 -        }
  85.856 -
  85.857 -        protected Object clone() {
  85.858 -            return new Entry<>(hash, key, value,
  85.859 -                                  (next==null ? null : (Entry<K,V>) next.clone()));
  85.860 -        }
  85.861 -
  85.862 -        // Map.Entry Ops
  85.863 -
  85.864 -        public K getKey() {
  85.865 -            return key;
  85.866 -        }
  85.867 -
  85.868 -        public V getValue() {
  85.869 -            return value;
  85.870 -        }
  85.871 -
  85.872 -        public V setValue(V value) {
  85.873 -            if (value == null)
  85.874 -                throw new NullPointerException();
  85.875 -
  85.876 -            V oldValue = this.value;
  85.877 -            this.value = value;
  85.878 -            return oldValue;
  85.879 -        }
  85.880 -
  85.881 -        public boolean equals(Object o) {
  85.882 -            if (!(o instanceof Map.Entry))
  85.883 -                return false;
  85.884 -            Map.Entry e = (Map.Entry)o;
  85.885 -
  85.886 -            return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
  85.887 -               (value==null ? e.getValue()==null : value.equals(e.getValue()));
  85.888 -        }
  85.889 -
  85.890 -        public int hashCode() {
  85.891 -            return hash ^ (value==null ? 0 : value.hashCode());
  85.892 -        }
  85.893 -
  85.894 -        public String toString() {
  85.895 -            return key.toString()+"="+value.toString();
  85.896 -        }
  85.897 -    }
  85.898 -
  85.899 -    // Types of Enumerations/Iterations
  85.900 -    private static final int KEYS = 0;
  85.901 -    private static final int VALUES = 1;
  85.902 -    private static final int ENTRIES = 2;
  85.903 -
  85.904 -    /**
  85.905 -     * A hashtable enumerator class.  This class implements both the
  85.906 -     * Enumeration and Iterator interfaces, but individual instances
  85.907 -     * can be created with the Iterator methods disabled.  This is necessary
  85.908 -     * to avoid unintentionally increasing the capabilities granted a user
  85.909 -     * by passing an Enumeration.
  85.910 -     */
  85.911 -    private class Enumerator<T> implements Enumeration<T>, Iterator<T> {
  85.912 -        Entry[] table = Hashtable.this.table;
  85.913 -        int index = table.length;
  85.914 -        Entry<K,V> entry = null;
  85.915 -        Entry<K,V> lastReturned = null;
  85.916 -        int type;
  85.917 -
  85.918 -        /**
  85.919 -         * Indicates whether this Enumerator is serving as an Iterator
  85.920 -         * or an Enumeration.  (true -> Iterator).
  85.921 -         */
  85.922 -        boolean iterator;
  85.923 -
  85.924 -        /**
  85.925 -         * The modCount value that the iterator believes that the backing
  85.926 -         * Hashtable should have.  If this expectation is violated, the iterator
  85.927 -         * has detected concurrent modification.
  85.928 -         */
  85.929 -        protected int expectedModCount = modCount;
  85.930 -
  85.931 -        Enumerator(int type, boolean iterator) {
  85.932 -            this.type = type;
  85.933 -            this.iterator = iterator;
  85.934 -        }
  85.935 -
  85.936 -        public boolean hasMoreElements() {
  85.937 -            Entry<K,V> e = entry;
  85.938 -            int i = index;
  85.939 -            Entry[] t = table;
  85.940 -            /* Use locals for faster loop iteration */
  85.941 -            while (e == null && i > 0) {
  85.942 -                e = t[--i];
  85.943 -            }
  85.944 -            entry = e;
  85.945 -            index = i;
  85.946 -            return e != null;
  85.947 -        }
  85.948 -
  85.949 -        public T nextElement() {
  85.950 -            Entry<K,V> et = entry;
  85.951 -            int i = index;
  85.952 -            Entry[] t = table;
  85.953 -            /* Use locals for faster loop iteration */
  85.954 -            while (et == null && i > 0) {
  85.955 -                et = t[--i];
  85.956 -            }
  85.957 -            entry = et;
  85.958 -            index = i;
  85.959 -            if (et != null) {
  85.960 -                Entry<K,V> e = lastReturned = entry;
  85.961 -                entry = e.next;
  85.962 -                return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e);
  85.963 -            }
  85.964 -            throw new NoSuchElementException("Hashtable Enumerator");
  85.965 -        }
  85.966 -
  85.967 -        // Iterator methods
  85.968 -        public boolean hasNext() {
  85.969 -            return hasMoreElements();
  85.970 -        }
  85.971 -
  85.972 -        public T next() {
  85.973 -            if (modCount != expectedModCount)
  85.974 -                throw new ConcurrentModificationException();
  85.975 -            return nextElement();
  85.976 -        }
  85.977 -
  85.978 -        public void remove() {
  85.979 -            if (!iterator)
  85.980 -                throw new UnsupportedOperationException();
  85.981 -            if (lastReturned == null)
  85.982 -                throw new IllegalStateException("Hashtable Enumerator");
  85.983 -            if (modCount != expectedModCount)
  85.984 -                throw new ConcurrentModificationException();
  85.985 -
  85.986 -            synchronized(Hashtable.this) {
  85.987 -                Entry[] tab = Hashtable.this.table;
  85.988 -                int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
  85.989 -
  85.990 -                for (Entry<K,V> e = tab[index], prev = null; e != null;
  85.991 -                     prev = e, e = e.next) {
  85.992 -                    if (e == lastReturned) {
  85.993 -                        modCount++;
  85.994 -                        expectedModCount++;
  85.995 -                        if (prev == null)
  85.996 -                            tab[index] = e.next;
  85.997 -                        else
  85.998 -                            prev.next = e.next;
  85.999 -                        count--;
 85.1000 -                        lastReturned = null;
 85.1001 -                        return;
 85.1002 -                    }
 85.1003 -                }
 85.1004 -                throw new ConcurrentModificationException();
 85.1005 -            }
 85.1006 -        }
 85.1007 -    }
 85.1008 -}
    86.1 --- a/emul/compact/src/main/java/java/util/Iterator.java	Mon Feb 25 19:00:08 2013 +0100
    86.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.3 @@ -1,87 +0,0 @@
    86.4 -/*
    86.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    86.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    86.7 - *
    86.8 - * This code is free software; you can redistribute it and/or modify it
    86.9 - * under the terms of the GNU General Public License version 2 only, as
   86.10 - * published by the Free Software Foundation.  Oracle designates this
   86.11 - * particular file as subject to the "Classpath" exception as provided
   86.12 - * by Oracle in the LICENSE file that accompanied this code.
   86.13 - *
   86.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   86.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   86.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   86.17 - * version 2 for more details (a copy is included in the LICENSE file that
   86.18 - * accompanied this code).
   86.19 - *
   86.20 - * You should have received a copy of the GNU General Public License version
   86.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   86.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   86.23 - *
   86.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   86.25 - * or visit www.oracle.com if you need additional information or have any
   86.26 - * questions.
   86.27 - */
   86.28 -
   86.29 -package java.util;
   86.30 -
   86.31 -/**
   86.32 - * An iterator over a collection.  {@code Iterator} takes the place of
   86.33 - * {@link Enumeration} in the Java Collections Framework.  Iterators
   86.34 - * differ from enumerations in two ways:
   86.35 - *
   86.36 - * <ul>
   86.37 - *      <li> Iterators allow the caller to remove elements from the
   86.38 - *           underlying collection during the iteration with well-defined
   86.39 - *           semantics.
   86.40 - *      <li> Method names have been improved.
   86.41 - * </ul>
   86.42 - *
   86.43 - * <p>This interface is a member of the
   86.44 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   86.45 - * Java Collections Framework</a>.
   86.46 - *
   86.47 - * @param <E> the type of elements returned by this iterator
   86.48 - *
   86.49 - * @author  Josh Bloch
   86.50 - * @see Collection
   86.51 - * @see ListIterator
   86.52 - * @see Iterable
   86.53 - * @since 1.2
   86.54 - */
   86.55 -public interface Iterator<E> {
   86.56 -    /**
   86.57 -     * Returns {@code true} if the iteration has more elements.
   86.58 -     * (In other words, returns {@code true} if {@link #next} would
   86.59 -     * return an element rather than throwing an exception.)
   86.60 -     *
   86.61 -     * @return {@code true} if the iteration has more elements
   86.62 -     */
   86.63 -    boolean hasNext();
   86.64 -
   86.65 -    /**
   86.66 -     * Returns the next element in the iteration.
   86.67 -     *
   86.68 -     * @return the next element in the iteration
   86.69 -     * @throws NoSuchElementException if the iteration has no more elements
   86.70 -     */
   86.71 -    E next();
   86.72 -
   86.73 -    /**
   86.74 -     * Removes from the underlying collection the last element returned
   86.75 -     * by this iterator (optional operation).  This method can be called
   86.76 -     * only once per call to {@link #next}.  The behavior of an iterator
   86.77 -     * is unspecified if the underlying collection is modified while the
   86.78 -     * iteration is in progress in any way other than by calling this
   86.79 -     * method.
   86.80 -     *
   86.81 -     * @throws UnsupportedOperationException if the {@code remove}
   86.82 -     *         operation is not supported by this iterator
   86.83 -     *
   86.84 -     * @throws IllegalStateException if the {@code next} method has not
   86.85 -     *         yet been called, or the {@code remove} method has already
   86.86 -     *         been called after the last call to the {@code next}
   86.87 -     *         method
   86.88 -     */
   86.89 -    void remove();
   86.90 -}
    87.1 --- a/emul/compact/src/main/java/java/util/LinkedHashMap.java	Mon Feb 25 19:00:08 2013 +0100
    87.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.3 @@ -1,491 +0,0 @@
    87.4 -/*
    87.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    87.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    87.7 - *
    87.8 - * This code is free software; you can redistribute it and/or modify it
    87.9 - * under the terms of the GNU General Public License version 2 only, as
   87.10 - * published by the Free Software Foundation.  Oracle designates this
   87.11 - * particular file as subject to the "Classpath" exception as provided
   87.12 - * by Oracle in the LICENSE file that accompanied this code.
   87.13 - *
   87.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   87.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   87.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   87.17 - * version 2 for more details (a copy is included in the LICENSE file that
   87.18 - * accompanied this code).
   87.19 - *
   87.20 - * You should have received a copy of the GNU General Public License version
   87.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   87.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   87.23 - *
   87.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   87.25 - * or visit www.oracle.com if you need additional information or have any
   87.26 - * questions.
   87.27 - */
   87.28 -
   87.29 -package java.util;
   87.30 -import java.io.*;
   87.31 -
   87.32 -/**
   87.33 - * <p>Hash table and linked list implementation of the <tt>Map</tt> interface,
   87.34 - * with predictable iteration order.  This implementation differs from
   87.35 - * <tt>HashMap</tt> in that it maintains a doubly-linked list running through
   87.36 - * all of its entries.  This linked list defines the iteration ordering,
   87.37 - * which is normally the order in which keys were inserted into the map
   87.38 - * (<i>insertion-order</i>).  Note that insertion order is not affected
   87.39 - * if a key is <i>re-inserted</i> into the map.  (A key <tt>k</tt> is
   87.40 - * reinserted into a map <tt>m</tt> if <tt>m.put(k, v)</tt> is invoked when
   87.41 - * <tt>m.containsKey(k)</tt> would return <tt>true</tt> immediately prior to
   87.42 - * the invocation.)
   87.43 - *
   87.44 - * <p>This implementation spares its clients from the unspecified, generally
   87.45 - * chaotic ordering provided by {@link HashMap} (and {@link Hashtable}),
   87.46 - * without incurring the increased cost associated with {@link TreeMap}.  It
   87.47 - * can be used to produce a copy of a map that has the same order as the
   87.48 - * original, regardless of the original map's implementation:
   87.49 - * <pre>
   87.50 - *     void foo(Map m) {
   87.51 - *         Map copy = new LinkedHashMap(m);
   87.52 - *         ...
   87.53 - *     }
   87.54 - * </pre>
   87.55 - * This technique is particularly useful if a module takes a map on input,
   87.56 - * copies it, and later returns results whose order is determined by that of
   87.57 - * the copy.  (Clients generally appreciate having things returned in the same
   87.58 - * order they were presented.)
   87.59 - *
   87.60 - * <p>A special {@link #LinkedHashMap(int,float,boolean) constructor} is
   87.61 - * provided to create a linked hash map whose order of iteration is the order
   87.62 - * in which its entries were last accessed, from least-recently accessed to
   87.63 - * most-recently (<i>access-order</i>).  This kind of map is well-suited to
   87.64 - * building LRU caches.  Invoking the <tt>put</tt> or <tt>get</tt> method
   87.65 - * results in an access to the corresponding entry (assuming it exists after
   87.66 - * the invocation completes).  The <tt>putAll</tt> method generates one entry
   87.67 - * access for each mapping in the specified map, in the order that key-value
   87.68 - * mappings are provided by the specified map's entry set iterator.  <i>No
   87.69 - * other methods generate entry accesses.</i> In particular, operations on
   87.70 - * collection-views do <i>not</i> affect the order of iteration of the backing
   87.71 - * map.
   87.72 - *
   87.73 - * <p>The {@link #removeEldestEntry(Map.Entry)} method may be overridden to
   87.74 - * impose a policy for removing stale mappings automatically when new mappings
   87.75 - * are added to the map.
   87.76 - *
   87.77 - * <p>This class provides all of the optional <tt>Map</tt> operations, and
   87.78 - * permits null elements.  Like <tt>HashMap</tt>, it provides constant-time
   87.79 - * performance for the basic operations (<tt>add</tt>, <tt>contains</tt> and
   87.80 - * <tt>remove</tt>), assuming the hash function disperses elements
   87.81 - * properly among the buckets.  Performance is likely to be just slightly
   87.82 - * below that of <tt>HashMap</tt>, due to the added expense of maintaining the
   87.83 - * linked list, with one exception: Iteration over the collection-views
   87.84 - * of a <tt>LinkedHashMap</tt> requires time proportional to the <i>size</i>
   87.85 - * of the map, regardless of its capacity.  Iteration over a <tt>HashMap</tt>
   87.86 - * is likely to be more expensive, requiring time proportional to its
   87.87 - * <i>capacity</i>.
   87.88 - *
   87.89 - * <p>A linked hash map has two parameters that affect its performance:
   87.90 - * <i>initial capacity</i> and <i>load factor</i>.  They are defined precisely
   87.91 - * as for <tt>HashMap</tt>.  Note, however, that the penalty for choosing an
   87.92 - * excessively high value for initial capacity is less severe for this class
   87.93 - * than for <tt>HashMap</tt>, as iteration times for this class are unaffected
   87.94 - * by capacity.
   87.95 - *
   87.96 - * <p><strong>Note that this implementation is not synchronized.</strong>
   87.97 - * If multiple threads access a linked hash map concurrently, and at least
   87.98 - * one of the threads modifies the map structurally, it <em>must</em> be
   87.99 - * synchronized externally.  This is typically accomplished by
  87.100 - * synchronizing on some object that naturally encapsulates the map.
  87.101 - *
  87.102 - * If no such object exists, the map should be "wrapped" using the
  87.103 - * {@link Collections#synchronizedMap Collections.synchronizedMap}
  87.104 - * method.  This is best done at creation time, to prevent accidental
  87.105 - * unsynchronized access to the map:<pre>
  87.106 - *   Map m = Collections.synchronizedMap(new LinkedHashMap(...));</pre>
  87.107 - *
  87.108 - * A structural modification is any operation that adds or deletes one or more
  87.109 - * mappings or, in the case of access-ordered linked hash maps, affects
  87.110 - * iteration order.  In insertion-ordered linked hash maps, merely changing
  87.111 - * the value associated with a key that is already contained in the map is not
  87.112 - * a structural modification.  <strong>In access-ordered linked hash maps,
  87.113 - * merely querying the map with <tt>get</tt> is a structural
  87.114 - * modification.</strong>)
  87.115 - *
  87.116 - * <p>The iterators returned by the <tt>iterator</tt> method of the collections
  87.117 - * returned by all of this class's collection view methods are
  87.118 - * <em>fail-fast</em>: if the map is structurally modified at any time after
  87.119 - * the iterator is created, in any way except through the iterator's own
  87.120 - * <tt>remove</tt> method, the iterator will throw a {@link
  87.121 - * ConcurrentModificationException}.  Thus, in the face of concurrent
  87.122 - * modification, the iterator fails quickly and cleanly, rather than risking
  87.123 - * arbitrary, non-deterministic behavior at an undetermined time in the future.
  87.124 - *
  87.125 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  87.126 - * as it is, generally speaking, impossible to make any hard guarantees in the
  87.127 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
  87.128 - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  87.129 - * Therefore, it would be wrong to write a program that depended on this
  87.130 - * exception for its correctness:   <i>the fail-fast behavior of iterators
  87.131 - * should be used only to detect bugs.</i>
  87.132 - *
  87.133 - * <p>This class is a member of the
  87.134 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  87.135 - * Java Collections Framework</a>.
  87.136 - *
  87.137 - * @param <K> the type of keys maintained by this map
  87.138 - * @param <V> the type of mapped values
  87.139 - *
  87.140 - * @author  Josh Bloch
  87.141 - * @see     Object#hashCode()
  87.142 - * @see     Collection
  87.143 - * @see     Map
  87.144 - * @see     HashMap
  87.145 - * @see     TreeMap
  87.146 - * @see     Hashtable
  87.147 - * @since   1.4
  87.148 - */
  87.149 -
  87.150 -public class LinkedHashMap<K,V>
  87.151 -    extends HashMap<K,V>
  87.152 -    implements Map<K,V>
  87.153 -{
  87.154 -
  87.155 -    private static final long serialVersionUID = 3801124242820219131L;
  87.156 -
  87.157 -    /**
  87.158 -     * The head of the doubly linked list.
  87.159 -     */
  87.160 -    private transient Entry<K,V> header;
  87.161 -
  87.162 -    /**
  87.163 -     * The iteration ordering method for this linked hash map: <tt>true</tt>
  87.164 -     * for access-order, <tt>false</tt> for insertion-order.
  87.165 -     *
  87.166 -     * @serial
  87.167 -     */
  87.168 -    private final boolean accessOrder;
  87.169 -
  87.170 -    /**
  87.171 -     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
  87.172 -     * with the specified initial capacity and load factor.
  87.173 -     *
  87.174 -     * @param  initialCapacity the initial capacity
  87.175 -     * @param  loadFactor      the load factor
  87.176 -     * @throws IllegalArgumentException if the initial capacity is negative
  87.177 -     *         or the load factor is nonpositive
  87.178 -     */
  87.179 -    public LinkedHashMap(int initialCapacity, float loadFactor) {
  87.180 -        super(initialCapacity, loadFactor);
  87.181 -        accessOrder = false;
  87.182 -    }
  87.183 -
  87.184 -    /**
  87.185 -     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
  87.186 -     * with the specified initial capacity and a default load factor (0.75).
  87.187 -     *
  87.188 -     * @param  initialCapacity the initial capacity
  87.189 -     * @throws IllegalArgumentException if the initial capacity is negative
  87.190 -     */
  87.191 -    public LinkedHashMap(int initialCapacity) {
  87.192 -        super(initialCapacity);
  87.193 -        accessOrder = false;
  87.194 -    }
  87.195 -
  87.196 -    /**
  87.197 -     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
  87.198 -     * with the default initial capacity (16) and load factor (0.75).
  87.199 -     */
  87.200 -    public LinkedHashMap() {
  87.201 -        super();
  87.202 -        accessOrder = false;
  87.203 -    }
  87.204 -
  87.205 -    /**
  87.206 -     * Constructs an insertion-ordered <tt>LinkedHashMap</tt> instance with
  87.207 -     * the same mappings as the specified map.  The <tt>LinkedHashMap</tt>
  87.208 -     * instance is created with a default load factor (0.75) and an initial
  87.209 -     * capacity sufficient to hold the mappings in the specified map.
  87.210 -     *
  87.211 -     * @param  m the map whose mappings are to be placed in this map
  87.212 -     * @throws NullPointerException if the specified map is null
  87.213 -     */
  87.214 -    public LinkedHashMap(Map<? extends K, ? extends V> m) {
  87.215 -        super(m);
  87.216 -        accessOrder = false;
  87.217 -    }
  87.218 -
  87.219 -    /**
  87.220 -     * Constructs an empty <tt>LinkedHashMap</tt> instance with the
  87.221 -     * specified initial capacity, load factor and ordering mode.
  87.222 -     *
  87.223 -     * @param  initialCapacity the initial capacity
  87.224 -     * @param  loadFactor      the load factor
  87.225 -     * @param  accessOrder     the ordering mode - <tt>true</tt> for
  87.226 -     *         access-order, <tt>false</tt> for insertion-order
  87.227 -     * @throws IllegalArgumentException if the initial capacity is negative
  87.228 -     *         or the load factor is nonpositive
  87.229 -     */
  87.230 -    public LinkedHashMap(int initialCapacity,
  87.231 -                         float loadFactor,
  87.232 -                         boolean accessOrder) {
  87.233 -        super(initialCapacity, loadFactor);
  87.234 -        this.accessOrder = accessOrder;
  87.235 -    }
  87.236 -
  87.237 -    /**
  87.238 -     * Called by superclass constructors and pseudoconstructors (clone,
  87.239 -     * readObject) before any entries are inserted into the map.  Initializes
  87.240 -     * the chain.
  87.241 -     */
  87.242 -    void init() {
  87.243 -        header = new Entry<>(-1, null, null, null);
  87.244 -        header.before = header.after = header;
  87.245 -    }
  87.246 -
  87.247 -    /**
  87.248 -     * Transfers all entries to new table array.  This method is called
  87.249 -     * by superclass resize.  It is overridden for performance, as it is
  87.250 -     * faster to iterate using our linked list.
  87.251 -     */
  87.252 -    void transfer(HashMap.Entry[] newTable) {
  87.253 -        int newCapacity = newTable.length;
  87.254 -        for (Entry<K,V> e = header.after; e != header; e = e.after) {
  87.255 -            int index = indexFor(e.hash, newCapacity);
  87.256 -            e.next = newTable[index];
  87.257 -            newTable[index] = e;
  87.258 -        }
  87.259 -    }
  87.260 -
  87.261 -
  87.262 -    /**
  87.263 -     * Returns <tt>true</tt> if this map maps one or more keys to the
  87.264 -     * specified value.
  87.265 -     *
  87.266 -     * @param value value whose presence in this map is to be tested
  87.267 -     * @return <tt>true</tt> if this map maps one or more keys to the
  87.268 -     *         specified value
  87.269 -     */
  87.270 -    public boolean containsValue(Object value) {
  87.271 -        // Overridden to take advantage of faster iterator
  87.272 -        if (value==null) {
  87.273 -            for (Entry e = header.after; e != header; e = e.after)
  87.274 -                if (e.value==null)
  87.275 -                    return true;
  87.276 -        } else {
  87.277 -            for (Entry e = header.after; e != header; e = e.after)
  87.278 -                if (value.equals(e.value))
  87.279 -                    return true;
  87.280 -        }
  87.281 -        return false;
  87.282 -    }
  87.283 -
  87.284 -    /**
  87.285 -     * Returns the value to which the specified key is mapped,
  87.286 -     * or {@code null} if this map contains no mapping for the key.
  87.287 -     *
  87.288 -     * <p>More formally, if this map contains a mapping from a key
  87.289 -     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
  87.290 -     * key.equals(k))}, then this method returns {@code v}; otherwise
  87.291 -     * it returns {@code null}.  (There can be at most one such mapping.)
  87.292 -     *
  87.293 -     * <p>A return value of {@code null} does not <i>necessarily</i>
  87.294 -     * indicate that the map contains no mapping for the key; it's also
  87.295 -     * possible that the map explicitly maps the key to {@code null}.
  87.296 -     * The {@link #containsKey containsKey} operation may be used to
  87.297 -     * distinguish these two cases.
  87.298 -     */
  87.299 -    public V get(Object key) {
  87.300 -        Entry<K,V> e = (Entry<K,V>)getEntry(key);
  87.301 -        if (e == null)
  87.302 -            return null;
  87.303 -        e.recordAccess(this);
  87.304 -        return e.value;
  87.305 -    }
  87.306 -
  87.307 -    /**
  87.308 -     * Removes all of the mappings from this map.
  87.309 -     * The map will be empty after this call returns.
  87.310 -     */
  87.311 -    public void clear() {
  87.312 -        super.clear();
  87.313 -        header.before = header.after = header;
  87.314 -    }
  87.315 -
  87.316 -    /**
  87.317 -     * LinkedHashMap entry.
  87.318 -     */
  87.319 -    private static class Entry<K,V> extends HashMap.Entry<K,V> {
  87.320 -        // These fields comprise the doubly linked list used for iteration.
  87.321 -        Entry<K,V> before, after;
  87.322 -
  87.323 -        Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
  87.324 -            super(hash, key, value, next);
  87.325 -        }
  87.326 -
  87.327 -        /**
  87.328 -         * Removes this entry from the linked list.
  87.329 -         */
  87.330 -        private void remove() {
  87.331 -            before.after = after;
  87.332 -            after.before = before;
  87.333 -        }
  87.334 -
  87.335 -        /**
  87.336 -         * Inserts this entry before the specified existing entry in the list.
  87.337 -         */
  87.338 -        private void addBefore(Entry<K,V> existingEntry) {
  87.339 -            after  = existingEntry;
  87.340 -            before = existingEntry.before;
  87.341 -            before.after = this;
  87.342 -            after.before = this;
  87.343 -        }
  87.344 -
  87.345 -        /**
  87.346 -         * This method is invoked by the superclass whenever the value
  87.347 -         * of a pre-existing entry is read by Map.get or modified by Map.set.
  87.348 -         * If the enclosing Map is access-ordered, it moves the entry
  87.349 -         * to the end of the list; otherwise, it does nothing.
  87.350 -         */
  87.351 -        void recordAccess(HashMap<K,V> m) {
  87.352 -            LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;
  87.353 -            if (lm.accessOrder) {
  87.354 -                lm.modCount++;
  87.355 -                remove();
  87.356 -                addBefore(lm.header);
  87.357 -            }
  87.358 -        }
  87.359 -
  87.360 -        void recordRemoval(HashMap<K,V> m) {
  87.361 -            remove();
  87.362 -        }
  87.363 -    }
  87.364 -
  87.365 -    private abstract class LinkedHashIterator<T> implements Iterator<T> {
  87.366 -        Entry<K,V> nextEntry    = header.after;
  87.367 -        Entry<K,V> lastReturned = null;
  87.368 -
  87.369 -        /**
  87.370 -         * The modCount value that the iterator believes that the backing
  87.371 -         * List should have.  If this expectation is violated, the iterator
  87.372 -         * has detected concurrent modification.
  87.373 -         */
  87.374 -        int expectedModCount = modCount;
  87.375 -
  87.376 -        public boolean hasNext() {
  87.377 -            return nextEntry != header;
  87.378 -        }
  87.379 -
  87.380 -        public void remove() {
  87.381 -            if (lastReturned == null)
  87.382 -                throw new IllegalStateException();
  87.383 -            if (modCount != expectedModCount)
  87.384 -                throw new ConcurrentModificationException();
  87.385 -
  87.386 -            LinkedHashMap.this.remove(lastReturned.key);
  87.387 -            lastReturned = null;
  87.388 -            expectedModCount = modCount;
  87.389 -        }
  87.390 -
  87.391 -        Entry<K,V> nextEntry() {
  87.392 -            if (modCount != expectedModCount)
  87.393 -                throw new ConcurrentModificationException();
  87.394 -            if (nextEntry == header)
  87.395 -                throw new NoSuchElementException();
  87.396 -
  87.397 -            Entry<K,V> e = lastReturned = nextEntry;
  87.398 -            nextEntry = e.after;
  87.399 -            return e;
  87.400 -        }
  87.401 -    }
  87.402 -
  87.403 -    private class KeyIterator extends LinkedHashIterator<K> {
  87.404 -        public K next() { return nextEntry().getKey(); }
  87.405 -    }
  87.406 -
  87.407 -    private class ValueIterator extends LinkedHashIterator<V> {
  87.408 -        public V next() { return nextEntry().value; }
  87.409 -    }
  87.410 -
  87.411 -    private class EntryIterator extends LinkedHashIterator<Map.Entry<K,V>> {
  87.412 -        public Map.Entry<K,V> next() { return nextEntry(); }
  87.413 -    }
  87.414 -
  87.415 -    // These Overrides alter the behavior of superclass view iterator() methods
  87.416 -    Iterator<K> newKeyIterator()   { return new KeyIterator();   }
  87.417 -    Iterator<V> newValueIterator() { return new ValueIterator(); }
  87.418 -    Iterator<Map.Entry<K,V>> newEntryIterator() { return new EntryIterator(); }
  87.419 -
  87.420 -    /**
  87.421 -     * This override alters behavior of superclass put method. It causes newly
  87.422 -     * allocated entry to get inserted at the end of the linked list and
  87.423 -     * removes the eldest entry if appropriate.
  87.424 -     */
  87.425 -    void addEntry(int hash, K key, V value, int bucketIndex) {
  87.426 -        createEntry(hash, key, value, bucketIndex);
  87.427 -
  87.428 -        // Remove eldest entry if instructed, else grow capacity if appropriate
  87.429 -        Entry<K,V> eldest = header.after;
  87.430 -        if (removeEldestEntry(eldest)) {
  87.431 -            removeEntryForKey(eldest.key);
  87.432 -        } else {
  87.433 -            if (size >= threshold)
  87.434 -                resize(2 * table.length);
  87.435 -        }
  87.436 -    }
  87.437 -
  87.438 -    /**
  87.439 -     * This override differs from addEntry in that it doesn't resize the
  87.440 -     * table or remove the eldest entry.
  87.441 -     */
  87.442 -    void createEntry(int hash, K key, V value, int bucketIndex) {
  87.443 -        HashMap.Entry<K,V> old = table[bucketIndex];
  87.444 -        Entry<K,V> e = new Entry<>(hash, key, value, old);
  87.445 -        table[bucketIndex] = e;
  87.446 -        e.addBefore(header);
  87.447 -        size++;
  87.448 -    }
  87.449 -
  87.450 -    /**
  87.451 -     * Returns <tt>true</tt> if this map should remove its eldest entry.
  87.452 -     * This method is invoked by <tt>put</tt> and <tt>putAll</tt> after
  87.453 -     * inserting a new entry into the map.  It provides the implementor
  87.454 -     * with the opportunity to remove the eldest entry each time a new one
  87.455 -     * is added.  This is useful if the map represents a cache: it allows
  87.456 -     * the map to reduce memory consumption by deleting stale entries.
  87.457 -     *
  87.458 -     * <p>Sample use: this override will allow the map to grow up to 100
  87.459 -     * entries and then delete the eldest entry each time a new entry is
  87.460 -     * added, maintaining a steady state of 100 entries.
  87.461 -     * <pre>
  87.462 -     *     private static final int MAX_ENTRIES = 100;
  87.463 -     *
  87.464 -     *     protected boolean removeEldestEntry(Map.Entry eldest) {
  87.465 -     *        return size() > MAX_ENTRIES;
  87.466 -     *     }
  87.467 -     * </pre>
  87.468 -     *
  87.469 -     * <p>This method typically does not modify the map in any way,
  87.470 -     * instead allowing the map to modify itself as directed by its
  87.471 -     * return value.  It <i>is</i> permitted for this method to modify
  87.472 -     * the map directly, but if it does so, it <i>must</i> return
  87.473 -     * <tt>false</tt> (indicating that the map should not attempt any
  87.474 -     * further modification).  The effects of returning <tt>true</tt>
  87.475 -     * after modifying the map from within this method are unspecified.
  87.476 -     *
  87.477 -     * <p>This implementation merely returns <tt>false</tt> (so that this
  87.478 -     * map acts like a normal map - the eldest element is never removed).
  87.479 -     *
  87.480 -     * @param    eldest The least recently inserted entry in the map, or if
  87.481 -     *           this is an access-ordered map, the least recently accessed
  87.482 -     *           entry.  This is the entry that will be removed it this
  87.483 -     *           method returns <tt>true</tt>.  If the map was empty prior
  87.484 -     *           to the <tt>put</tt> or <tt>putAll</tt> invocation resulting
  87.485 -     *           in this invocation, this will be the entry that was just
  87.486 -     *           inserted; in other words, if the map contains a single
  87.487 -     *           entry, the eldest entry is also the newest.
  87.488 -     * @return   <tt>true</tt> if the eldest entry should be removed
  87.489 -     *           from the map; <tt>false</tt> if it should be retained.
  87.490 -     */
  87.491 -    protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
  87.492 -        return false;
  87.493 -    }
  87.494 -}
    88.1 --- a/emul/compact/src/main/java/java/util/LinkedList.java	Mon Feb 25 19:00:08 2013 +0100
    88.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.3 @@ -1,1100 +0,0 @@
    88.4 -/*
    88.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
    88.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    88.7 - *
    88.8 - * This code is free software; you can redistribute it and/or modify it
    88.9 - * under the terms of the GNU General Public License version 2 only, as
   88.10 - * published by the Free Software Foundation.  Oracle designates this
   88.11 - * particular file as subject to the "Classpath" exception as provided
   88.12 - * by Oracle in the LICENSE file that accompanied this code.
   88.13 - *
   88.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   88.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   88.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   88.17 - * version 2 for more details (a copy is included in the LICENSE file that
   88.18 - * accompanied this code).
   88.19 - *
   88.20 - * You should have received a copy of the GNU General Public License version
   88.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   88.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   88.23 - *
   88.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   88.25 - * or visit www.oracle.com if you need additional information or have any
   88.26 - * questions.
   88.27 - */
   88.28 -
   88.29 -package java.util;
   88.30 -
   88.31 -/**
   88.32 - * Doubly-linked list implementation of the {@code List} and {@code Deque}
   88.33 - * interfaces.  Implements all optional list operations, and permits all
   88.34 - * elements (including {@code null}).
   88.35 - *
   88.36 - * <p>All of the operations perform as could be expected for a doubly-linked
   88.37 - * list.  Operations that index into the list will traverse the list from
   88.38 - * the beginning or the end, whichever is closer to the specified index.
   88.39 - *
   88.40 - * <p><strong>Note that this implementation is not synchronized.</strong>
   88.41 - * If multiple threads access a linked list concurrently, and at least
   88.42 - * one of the threads modifies the list structurally, it <i>must</i> be
   88.43 - * synchronized externally.  (A structural modification is any operation
   88.44 - * that adds or deletes one or more elements; merely setting the value of
   88.45 - * an element is not a structural modification.)  This is typically
   88.46 - * accomplished by synchronizing on some object that naturally
   88.47 - * encapsulates the list.
   88.48 - *
   88.49 - * If no such object exists, the list should be "wrapped" using the
   88.50 - * {@link Collections#synchronizedList Collections.synchronizedList}
   88.51 - * method.  This is best done at creation time, to prevent accidental
   88.52 - * unsynchronized access to the list:<pre>
   88.53 - *   List list = Collections.synchronizedList(new LinkedList(...));</pre>
   88.54 - *
   88.55 - * <p>The iterators returned by this class's {@code iterator} and
   88.56 - * {@code listIterator} methods are <i>fail-fast</i>: if the list is
   88.57 - * structurally modified at any time after the iterator is created, in
   88.58 - * any way except through the Iterator's own {@code remove} or
   88.59 - * {@code add} methods, the iterator will throw a {@link
   88.60 - * ConcurrentModificationException}.  Thus, in the face of concurrent
   88.61 - * modification, the iterator fails quickly and cleanly, rather than
   88.62 - * risking arbitrary, non-deterministic behavior at an undetermined
   88.63 - * time in the future.
   88.64 - *
   88.65 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
   88.66 - * as it is, generally speaking, impossible to make any hard guarantees in the
   88.67 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
   88.68 - * throw {@code ConcurrentModificationException} on a best-effort basis.
   88.69 - * Therefore, it would be wrong to write a program that depended on this
   88.70 - * exception for its correctness:   <i>the fail-fast behavior of iterators
   88.71 - * should be used only to detect bugs.</i>
   88.72 - *
   88.73 - * <p>This class is a member of the
   88.74 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   88.75 - * Java Collections Framework</a>.
   88.76 - *
   88.77 - * @author  Josh Bloch
   88.78 - * @see     List
   88.79 - * @see     ArrayList
   88.80 - * @since 1.2
   88.81 - * @param <E> the type of elements held in this collection
   88.82 - */
   88.83 -
   88.84 -public class LinkedList<E>
   88.85 -    extends AbstractSequentialList<E>
   88.86 -    implements List<E>, Deque<E>, Cloneable, java.io.Serializable
   88.87 -{
   88.88 -    transient int size = 0;
   88.89 -
   88.90 -    /**
   88.91 -     * Pointer to first node.
   88.92 -     * Invariant: (first == null && last == null) ||
   88.93 -     *            (first.prev == null && first.item != null)
   88.94 -     */
   88.95 -    transient Node<E> first;
   88.96 -
   88.97 -    /**
   88.98 -     * Pointer to last node.
   88.99 -     * Invariant: (first == null && last == null) ||
  88.100 -     *            (last.next == null && last.item != null)
  88.101 -     */
  88.102 -    transient Node<E> last;
  88.103 -
  88.104 -    /**
  88.105 -     * Constructs an empty list.
  88.106 -     */
  88.107 -    public LinkedList() {
  88.108 -    }
  88.109 -
  88.110 -    /**
  88.111 -     * Constructs a list containing the elements of the specified
  88.112 -     * collection, in the order they are returned by the collection's
  88.113 -     * iterator.
  88.114 -     *
  88.115 -     * @param  c the collection whose elements are to be placed into this list
  88.116 -     * @throws NullPointerException if the specified collection is null
  88.117 -     */
  88.118 -    public LinkedList(Collection<? extends E> c) {
  88.119 -        this();
  88.120 -        addAll(c);
  88.121 -    }
  88.122 -
  88.123 -    /**
  88.124 -     * Links e as first element.
  88.125 -     */
  88.126 -    private void linkFirst(E e) {
  88.127 -        final Node<E> f = first;
  88.128 -        final Node<E> newNode = new Node<>(null, e, f);
  88.129 -        first = newNode;
  88.130 -        if (f == null)
  88.131 -            last = newNode;
  88.132 -        else
  88.133 -            f.prev = newNode;
  88.134 -        size++;
  88.135 -        modCount++;
  88.136 -    }
  88.137 -
  88.138 -    /**
  88.139 -     * Links e as last element.
  88.140 -     */
  88.141 -    void linkLast(E e) {
  88.142 -        final Node<E> l = last;
  88.143 -        final Node<E> newNode = new Node<>(l, e, null);
  88.144 -        last = newNode;
  88.145 -        if (l == null)
  88.146 -            first = newNode;
  88.147 -        else
  88.148 -            l.next = newNode;
  88.149 -        size++;
  88.150 -        modCount++;
  88.151 -    }
  88.152 -
  88.153 -    /**
  88.154 -     * Inserts element e before non-null Node succ.
  88.155 -     */
  88.156 -    void linkBefore(E e, Node<E> succ) {
  88.157 -        // assert succ != null;
  88.158 -        final Node<E> pred = succ.prev;
  88.159 -        final Node<E> newNode = new Node<>(pred, e, succ);
  88.160 -        succ.prev = newNode;
  88.161 -        if (pred == null)
  88.162 -            first = newNode;
  88.163 -        else
  88.164 -            pred.next = newNode;
  88.165 -        size++;
  88.166 -        modCount++;
  88.167 -    }
  88.168 -
  88.169 -    /**
  88.170 -     * Unlinks non-null first node f.
  88.171 -     */
  88.172 -    private E unlinkFirst(Node<E> f) {
  88.173 -        // assert f == first && f != null;
  88.174 -        final E element = f.item;
  88.175 -        final Node<E> next = f.next;
  88.176 -        f.item = null;
  88.177 -        f.next = null; // help GC
  88.178 -        first = next;
  88.179 -        if (next == null)
  88.180 -            last = null;
  88.181 -        else
  88.182 -            next.prev = null;
  88.183 -        size--;
  88.184 -        modCount++;
  88.185 -        return element;
  88.186 -    }
  88.187 -
  88.188 -    /**
  88.189 -     * Unlinks non-null last node l.
  88.190 -     */
  88.191 -    private E unlinkLast(Node<E> l) {
  88.192 -        // assert l == last && l != null;
  88.193 -        final E element = l.item;
  88.194 -        final Node<E> prev = l.prev;
  88.195 -        l.item = null;
  88.196 -        l.prev = null; // help GC
  88.197 -        last = prev;
  88.198 -        if (prev == null)
  88.199 -            first = null;
  88.200 -        else
  88.201 -            prev.next = null;
  88.202 -        size--;
  88.203 -        modCount++;
  88.204 -        return element;
  88.205 -    }
  88.206 -
  88.207 -    /**
  88.208 -     * Unlinks non-null node x.
  88.209 -     */
  88.210 -    E unlink(Node<E> x) {
  88.211 -        // assert x != null;
  88.212 -        final E element = x.item;
  88.213 -        final Node<E> next = x.next;
  88.214 -        final Node<E> prev = x.prev;
  88.215 -
  88.216 -        if (prev == null) {
  88.217 -            first = next;
  88.218 -        } else {
  88.219 -            prev.next = next;
  88.220 -            x.prev = null;
  88.221 -        }
  88.222 -
  88.223 -        if (next == null) {
  88.224 -            last = prev;
  88.225 -        } else {
  88.226 -            next.prev = prev;
  88.227 -            x.next = null;
  88.228 -        }
  88.229 -
  88.230 -        x.item = null;
  88.231 -        size--;
  88.232 -        modCount++;
  88.233 -        return element;
  88.234 -    }
  88.235 -
  88.236 -    /**
  88.237 -     * Returns the first element in this list.
  88.238 -     *
  88.239 -     * @return the first element in this list
  88.240 -     * @throws NoSuchElementException if this list is empty
  88.241 -     */
  88.242 -    public E getFirst() {
  88.243 -        final Node<E> f = first;
  88.244 -        if (f == null)
  88.245 -            throw new NoSuchElementException();
  88.246 -        return f.item;
  88.247 -    }
  88.248 -
  88.249 -    /**
  88.250 -     * Returns the last element in this list.
  88.251 -     *
  88.252 -     * @return the last element in this list
  88.253 -     * @throws NoSuchElementException if this list is empty
  88.254 -     */
  88.255 -    public E getLast() {
  88.256 -        final Node<E> l = last;
  88.257 -        if (l == null)
  88.258 -            throw new NoSuchElementException();
  88.259 -        return l.item;
  88.260 -    }
  88.261 -
  88.262 -    /**
  88.263 -     * Removes and returns the first element from this list.
  88.264 -     *
  88.265 -     * @return the first element from this list
  88.266 -     * @throws NoSuchElementException if this list is empty
  88.267 -     */
  88.268 -    public E removeFirst() {
  88.269 -        final Node<E> f = first;
  88.270 -        if (f == null)
  88.271 -            throw new NoSuchElementException();
  88.272 -        return unlinkFirst(f);
  88.273 -    }
  88.274 -
  88.275 -    /**
  88.276 -     * Removes and returns the last element from this list.
  88.277 -     *
  88.278 -     * @return the last element from this list
  88.279 -     * @throws NoSuchElementException if this list is empty
  88.280 -     */
  88.281 -    public E removeLast() {
  88.282 -        final Node<E> l = last;
  88.283 -        if (l == null)
  88.284 -            throw new NoSuchElementException();
  88.285 -        return unlinkLast(l);
  88.286 -    }
  88.287 -
  88.288 -    /**
  88.289 -     * Inserts the specified element at the beginning of this list.
  88.290 -     *
  88.291 -     * @param e the element to add
  88.292 -     */
  88.293 -    public void addFirst(E e) {
  88.294 -        linkFirst(e);
  88.295 -    }
  88.296 -
  88.297 -    /**
  88.298 -     * Appends the specified element to the end of this list.
  88.299 -     *
  88.300 -     * <p>This method is equivalent to {@link #add}.
  88.301 -     *
  88.302 -     * @param e the element to add
  88.303 -     */
  88.304 -    public void addLast(E e) {
  88.305 -        linkLast(e);
  88.306 -    }
  88.307 -
  88.308 -    /**
  88.309 -     * Returns {@code true} if this list contains the specified element.
  88.310 -     * More formally, returns {@code true} if and only if this list contains
  88.311 -     * at least one element {@code e} such that
  88.312 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  88.313 -     *
  88.314 -     * @param o element whose presence in this list is to be tested
  88.315 -     * @return {@code true} if this list contains the specified element
  88.316 -     */
  88.317 -    public boolean contains(Object o) {
  88.318 -        return indexOf(o) != -1;
  88.319 -    }
  88.320 -
  88.321 -    /**
  88.322 -     * Returns the number of elements in this list.
  88.323 -     *
  88.324 -     * @return the number of elements in this list
  88.325 -     */
  88.326 -    public int size() {
  88.327 -        return size;
  88.328 -    }
  88.329 -
  88.330 -    /**
  88.331 -     * Appends the specified element to the end of this list.
  88.332 -     *
  88.333 -     * <p>This method is equivalent to {@link #addLast}.
  88.334 -     *
  88.335 -     * @param e element to be appended to this list
  88.336 -     * @return {@code true} (as specified by {@link Collection#add})
  88.337 -     */
  88.338 -    public boolean add(E e) {
  88.339 -        linkLast(e);
  88.340 -        return true;
  88.341 -    }
  88.342 -
  88.343 -    /**
  88.344 -     * Removes the first occurrence of the specified element from this list,
  88.345 -     * if it is present.  If this list does not contain the element, it is
  88.346 -     * unchanged.  More formally, removes the element with the lowest index
  88.347 -     * {@code i} such that
  88.348 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
  88.349 -     * (if such an element exists).  Returns {@code true} if this list
  88.350 -     * contained the specified element (or equivalently, if this list
  88.351 -     * changed as a result of the call).
  88.352 -     *
  88.353 -     * @param o element to be removed from this list, if present
  88.354 -     * @return {@code true} if this list contained the specified element
  88.355 -     */
  88.356 -    public boolean remove(Object o) {
  88.357 -        if (o == null) {
  88.358 -            for (Node<E> x = first; x != null; x = x.next) {
  88.359 -                if (x.item == null) {
  88.360 -                    unlink(x);
  88.361 -                    return true;
  88.362 -                }
  88.363 -            }
  88.364 -        } else {
  88.365 -            for (Node<E> x = first; x != null; x = x.next) {
  88.366 -                if (o.equals(x.item)) {
  88.367 -                    unlink(x);
  88.368 -                    return true;
  88.369 -                }
  88.370 -            }
  88.371 -        }
  88.372 -        return false;
  88.373 -    }
  88.374 -
  88.375 -    /**
  88.376 -     * Appends all of the elements in the specified collection to the end of
  88.377 -     * this list, in the order that they are returned by the specified
  88.378 -     * collection's iterator.  The behavior of this operation is undefined if
  88.379 -     * the specified collection is modified while the operation is in
  88.380 -     * progress.  (Note that this will occur if the specified collection is
  88.381 -     * this list, and it's nonempty.)
  88.382 -     *
  88.383 -     * @param c collection containing elements to be added to this list
  88.384 -     * @return {@code true} if this list changed as a result of the call
  88.385 -     * @throws NullPointerException if the specified collection is null
  88.386 -     */
  88.387 -    public boolean addAll(Collection<? extends E> c) {
  88.388 -        return addAll(size, c);
  88.389 -    }
  88.390 -
  88.391 -    /**
  88.392 -     * Inserts all of the elements in the specified collection into this
  88.393 -     * list, starting at the specified position.  Shifts the element
  88.394 -     * currently at that position (if any) and any subsequent elements to
  88.395 -     * the right (increases their indices).  The new elements will appear
  88.396 -     * in the list in the order that they are returned by the
  88.397 -     * specified collection's iterator.
  88.398 -     *
  88.399 -     * @param index index at which to insert the first element
  88.400 -     *              from the specified collection
  88.401 -     * @param c collection containing elements to be added to this list
  88.402 -     * @return {@code true} if this list changed as a result of the call
  88.403 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  88.404 -     * @throws NullPointerException if the specified collection is null
  88.405 -     */
  88.406 -    public boolean addAll(int index, Collection<? extends E> c) {
  88.407 -        checkPositionIndex(index);
  88.408 -
  88.409 -        Object[] a = c.toArray();
  88.410 -        int numNew = a.length;
  88.411 -        if (numNew == 0)
  88.412 -            return false;
  88.413 -
  88.414 -        Node<E> pred, succ;
  88.415 -        if (index == size) {
  88.416 -            succ = null;
  88.417 -            pred = last;
  88.418 -        } else {
  88.419 -            succ = node(index);
  88.420 -            pred = succ.prev;
  88.421 -        }
  88.422 -
  88.423 -        for (Object o : a) {
  88.424 -            @SuppressWarnings("unchecked") E e = (E) o;
  88.425 -            Node<E> newNode = new Node<>(pred, e, null);
  88.426 -            if (pred == null)
  88.427 -                first = newNode;
  88.428 -            else
  88.429 -                pred.next = newNode;
  88.430 -            pred = newNode;
  88.431 -        }
  88.432 -
  88.433 -        if (succ == null) {
  88.434 -            last = pred;
  88.435 -        } else {
  88.436 -            pred.next = succ;
  88.437 -            succ.prev = pred;
  88.438 -        }
  88.439 -
  88.440 -        size += numNew;
  88.441 -        modCount++;
  88.442 -        return true;
  88.443 -    }
  88.444 -
  88.445 -    /**
  88.446 -     * Removes all of the elements from this list.
  88.447 -     * The list will be empty after this call returns.
  88.448 -     */
  88.449 -    public void clear() {
  88.450 -        // Clearing all of the links between nodes is "unnecessary", but:
  88.451 -        // - helps a generational GC if the discarded nodes inhabit
  88.452 -        //   more than one generation
  88.453 -        // - is sure to free memory even if there is a reachable Iterator
  88.454 -        for (Node<E> x = first; x != null; ) {
  88.455 -            Node<E> next = x.next;
  88.456 -            x.item = null;
  88.457 -            x.next = null;
  88.458 -            x.prev = null;
  88.459 -            x = next;
  88.460 -        }
  88.461 -        first = last = null;
  88.462 -        size = 0;
  88.463 -        modCount++;
  88.464 -    }
  88.465 -
  88.466 -
  88.467 -    // Positional Access Operations
  88.468 -
  88.469 -    /**
  88.470 -     * Returns the element at the specified position in this list.
  88.471 -     *
  88.472 -     * @param index index of the element to return
  88.473 -     * @return the element at the specified position in this list
  88.474 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  88.475 -     */
  88.476 -    public E get(int index) {
  88.477 -        checkElementIndex(index);
  88.478 -        return node(index).item;
  88.479 -    }
  88.480 -
  88.481 -    /**
  88.482 -     * Replaces the element at the specified position in this list with the
  88.483 -     * specified element.
  88.484 -     *
  88.485 -     * @param index index of the element to replace
  88.486 -     * @param element element to be stored at the specified position
  88.487 -     * @return the element previously at the specified position
  88.488 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  88.489 -     */
  88.490 -    public E set(int index, E element) {
  88.491 -        checkElementIndex(index);
  88.492 -        Node<E> x = node(index);
  88.493 -        E oldVal = x.item;
  88.494 -        x.item = element;
  88.495 -        return oldVal;
  88.496 -    }
  88.497 -
  88.498 -    /**
  88.499 -     * Inserts the specified element at the specified position in this list.
  88.500 -     * Shifts the element currently at that position (if any) and any
  88.501 -     * subsequent elements to the right (adds one to their indices).
  88.502 -     *
  88.503 -     * @param index index at which the specified element is to be inserted
  88.504 -     * @param element element to be inserted
  88.505 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  88.506 -     */
  88.507 -    public void add(int index, E element) {
  88.508 -        checkPositionIndex(index);
  88.509 -
  88.510 -        if (index == size)
  88.511 -            linkLast(element);
  88.512 -        else
  88.513 -            linkBefore(element, node(index));
  88.514 -    }
  88.515 -
  88.516 -    /**
  88.517 -     * Removes the element at the specified position in this list.  Shifts any
  88.518 -     * subsequent elements to the left (subtracts one from their indices).
  88.519 -     * Returns the element that was removed from the list.
  88.520 -     *
  88.521 -     * @param index the index of the element to be removed
  88.522 -     * @return the element previously at the specified position
  88.523 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  88.524 -     */
  88.525 -    public E remove(int index) {
  88.526 -        checkElementIndex(index);
  88.527 -        return unlink(node(index));
  88.528 -    }
  88.529 -
  88.530 -    /**
  88.531 -     * Tells if the argument is the index of an existing element.
  88.532 -     */
  88.533 -    private boolean isElementIndex(int index) {
  88.534 -        return index >= 0 && index < size;
  88.535 -    }
  88.536 -
  88.537 -    /**
  88.538 -     * Tells if the argument is the index of a valid position for an
  88.539 -     * iterator or an add operation.
  88.540 -     */
  88.541 -    private boolean isPositionIndex(int index) {
  88.542 -        return index >= 0 && index <= size;
  88.543 -    }
  88.544 -
  88.545 -    /**
  88.546 -     * Constructs an IndexOutOfBoundsException detail message.
  88.547 -     * Of the many possible refactorings of the error handling code,
  88.548 -     * this "outlining" performs best with both server and client VMs.
  88.549 -     */
  88.550 -    private String outOfBoundsMsg(int index) {
  88.551 -        return "Index: "+index+", Size: "+size;
  88.552 -    }
  88.553 -
  88.554 -    private void checkElementIndex(int index) {
  88.555 -        if (!isElementIndex(index))
  88.556 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  88.557 -    }
  88.558 -
  88.559 -    private void checkPositionIndex(int index) {
  88.560 -        if (!isPositionIndex(index))
  88.561 -            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  88.562 -    }
  88.563 -
  88.564 -    /**
  88.565 -     * Returns the (non-null) Node at the specified element index.
  88.566 -     */
  88.567 -    Node<E> node(int index) {
  88.568 -        // assert isElementIndex(index);
  88.569 -
  88.570 -        if (index < (size >> 1)) {
  88.571 -            Node<E> x = first;
  88.572 -            for (int i = 0; i < index; i++)
  88.573 -                x = x.next;
  88.574 -            return x;
  88.575 -        } else {
  88.576 -            Node<E> x = last;
  88.577 -            for (int i = size - 1; i > index; i--)
  88.578 -                x = x.prev;
  88.579 -            return x;
  88.580 -        }
  88.581 -    }
  88.582 -
  88.583 -    // Search Operations
  88.584 -
  88.585 -    /**
  88.586 -     * Returns the index of the first occurrence of the specified element
  88.587 -     * in this list, or -1 if this list does not contain the element.
  88.588 -     * More formally, returns the lowest index {@code i} such that
  88.589 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  88.590 -     * or -1 if there is no such index.
  88.591 -     *
  88.592 -     * @param o element to search for
  88.593 -     * @return the index of the first occurrence of the specified element in
  88.594 -     *         this list, or -1 if this list does not contain the element
  88.595 -     */
  88.596 -    public int indexOf(Object o) {
  88.597 -        int index = 0;
  88.598 -        if (o == null) {
  88.599 -            for (Node<E> x = first; x != null; x = x.next) {
  88.600 -                if (x.item == null)
  88.601 -                    return index;
  88.602 -                index++;
  88.603 -            }
  88.604 -        } else {
  88.605 -            for (Node<E> x = first; x != null; x = x.next) {
  88.606 -                if (o.equals(x.item))
  88.607 -                    return index;
  88.608 -                index++;
  88.609 -            }
  88.610 -        }
  88.611 -        return -1;
  88.612 -    }
  88.613 -
  88.614 -    /**
  88.615 -     * Returns the index of the last occurrence of the specified element
  88.616 -     * in this list, or -1 if this list does not contain the element.
  88.617 -     * More formally, returns the highest index {@code i} such that
  88.618 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  88.619 -     * or -1 if there is no such index.
  88.620 -     *
  88.621 -     * @param o element to search for
  88.622 -     * @return the index of the last occurrence of the specified element in
  88.623 -     *         this list, or -1 if this list does not contain the element
  88.624 -     */
  88.625 -    public int lastIndexOf(Object o) {
  88.626 -        int index = size;
  88.627 -        if (o == null) {
  88.628 -            for (Node<E> x = last; x != null; x = x.prev) {
  88.629 -                index--;
  88.630 -                if (x.item == null)
  88.631 -                    return index;
  88.632 -            }
  88.633 -        } else {
  88.634 -            for (Node<E> x = last; x != null; x = x.prev) {
  88.635 -                index--;
  88.636 -                if (o.equals(x.item))
  88.637 -                    return index;
  88.638 -            }
  88.639 -        }
  88.640 -        return -1;
  88.641 -    }
  88.642 -
  88.643 -    // Queue operations.
  88.644 -
  88.645 -    /**
  88.646 -     * Retrieves, but does not remove, the head (first element) of this list.
  88.647 -     *
  88.648 -     * @return the head of this list, or {@code null} if this list is empty
  88.649 -     * @since 1.5
  88.650 -     */
  88.651 -    public E peek() {
  88.652 -        final Node<E> f = first;
  88.653 -        return (f == null) ? null : f.item;
  88.654 -    }
  88.655 -
  88.656 -    /**
  88.657 -     * Retrieves, but does not remove, the head (first element) of this list.
  88.658 -     *
  88.659 -     * @return the head of this list
  88.660 -     * @throws NoSuchElementException if this list is empty
  88.661 -     * @since 1.5
  88.662 -     */
  88.663 -    public E element() {
  88.664 -        return getFirst();
  88.665 -    }
  88.666 -
  88.667 -    /**
  88.668 -     * Retrieves and removes the head (first element) of this list.
  88.669 -     *
  88.670 -     * @return the head of this list, or {@code null} if this list is empty
  88.671 -     * @since 1.5
  88.672 -     */
  88.673 -    public E poll() {
  88.674 -        final Node<E> f = first;
  88.675 -        return (f == null) ? null : unlinkFirst(f);
  88.676 -    }
  88.677 -
  88.678 -    /**
  88.679 -     * Retrieves and removes the head (first element) of this list.
  88.680 -     *
  88.681 -     * @return the head of this list
  88.682 -     * @throws NoSuchElementException if this list is empty
  88.683 -     * @since 1.5
  88.684 -     */
  88.685 -    public E remove() {
  88.686 -        return removeFirst();
  88.687 -    }
  88.688 -
  88.689 -    /**
  88.690 -     * Adds the specified element as the tail (last element) of this list.
  88.691 -     *
  88.692 -     * @param e the element to add
  88.693 -     * @return {@code true} (as specified by {@link Queue#offer})
  88.694 -     * @since 1.5
  88.695 -     */
  88.696 -    public boolean offer(E e) {
  88.697 -        return add(e);
  88.698 -    }
  88.699 -
  88.700 -    // Deque operations
  88.701 -    /**
  88.702 -     * Inserts the specified element at the front of this list.
  88.703 -     *
  88.704 -     * @param e the element to insert
  88.705 -     * @return {@code true} (as specified by {@link Deque#offerFirst})
  88.706 -     * @since 1.6
  88.707 -     */
  88.708 -    public boolean offerFirst(E e) {
  88.709 -        addFirst(e);
  88.710 -        return true;
  88.711 -    }
  88.712 -
  88.713 -    /**
  88.714 -     * Inserts the specified element at the end of this list.
  88.715 -     *
  88.716 -     * @param e the element to insert
  88.717 -     * @return {@code true} (as specified by {@link Deque#offerLast})
  88.718 -     * @since 1.6
  88.719 -     */
  88.720 -    public boolean offerLast(E e) {
  88.721 -        addLast(e);
  88.722 -        return true;
  88.723 -    }
  88.724 -
  88.725 -    /**
  88.726 -     * Retrieves, but does not remove, the first element of this list,
  88.727 -     * or returns {@code null} if this list is empty.
  88.728 -     *
  88.729 -     * @return the first element of this list, or {@code null}
  88.730 -     *         if this list is empty
  88.731 -     * @since 1.6
  88.732 -     */
  88.733 -    public E peekFirst() {
  88.734 -        final Node<E> f = first;
  88.735 -        return (f == null) ? null : f.item;
  88.736 -     }
  88.737 -
  88.738 -    /**
  88.739 -     * Retrieves, but does not remove, the last element of this list,
  88.740 -     * or returns {@code null} if this list is empty.
  88.741 -     *
  88.742 -     * @return the last element of this list, or {@code null}
  88.743 -     *         if this list is empty
  88.744 -     * @since 1.6
  88.745 -     */
  88.746 -    public E peekLast() {
  88.747 -        final Node<E> l = last;
  88.748 -        return (l == null) ? null : l.item;
  88.749 -    }
  88.750 -
  88.751 -    /**
  88.752 -     * Retrieves and removes the first element of this list,
  88.753 -     * or returns {@code null} if this list is empty.
  88.754 -     *
  88.755 -     * @return the first element of this list, or {@code null} if
  88.756 -     *     this list is empty
  88.757 -     * @since 1.6
  88.758 -     */
  88.759 -    public E pollFirst() {
  88.760 -        final Node<E> f = first;
  88.761 -        return (f == null) ? null : unlinkFirst(f);
  88.762 -    }
  88.763 -
  88.764 -    /**
  88.765 -     * Retrieves and removes the last element of this list,
  88.766 -     * or returns {@code null} if this list is empty.
  88.767 -     *
  88.768 -     * @return the last element of this list, or {@code null} if
  88.769 -     *     this list is empty
  88.770 -     * @since 1.6
  88.771 -     */
  88.772 -    public E pollLast() {
  88.773 -        final Node<E> l = last;
  88.774 -        return (l == null) ? null : unlinkLast(l);
  88.775 -    }
  88.776 -
  88.777 -    /**
  88.778 -     * Pushes an element onto the stack represented by this list.  In other
  88.779 -     * words, inserts the element at the front of this list.
  88.780 -     *
  88.781 -     * <p>This method is equivalent to {@link #addFirst}.
  88.782 -     *
  88.783 -     * @param e the element to push
  88.784 -     * @since 1.6
  88.785 -     */
  88.786 -    public void push(E e) {
  88.787 -        addFirst(e);
  88.788 -    }
  88.789 -
  88.790 -    /**
  88.791 -     * Pops an element from the stack represented by this list.  In other
  88.792 -     * words, removes and returns the first element of this list.
  88.793 -     *
  88.794 -     * <p>This method is equivalent to {@link #removeFirst()}.
  88.795 -     *
  88.796 -     * @return the element at the front of this list (which is the top
  88.797 -     *         of the stack represented by this list)
  88.798 -     * @throws NoSuchElementException if this list is empty
  88.799 -     * @since 1.6
  88.800 -     */
  88.801 -    public E pop() {
  88.802 -        return removeFirst();
  88.803 -    }
  88.804 -
  88.805 -    /**
  88.806 -     * Removes the first occurrence of the specified element in this
  88.807 -     * list (when traversing the list from head to tail).  If the list
  88.808 -     * does not contain the element, it is unchanged.
  88.809 -     *
  88.810 -     * @param o element to be removed from this list, if present
  88.811 -     * @return {@code true} if the list contained the specified element
  88.812 -     * @since 1.6
  88.813 -     */
  88.814 -    public boolean removeFirstOccurrence(Object o) {
  88.815 -        return remove(o);
  88.816 -    }
  88.817 -
  88.818 -    /**
  88.819 -     * Removes the last occurrence of the specified element in this
  88.820 -     * list (when traversing the list from head to tail).  If the list
  88.821 -     * does not contain the element, it is unchanged.
  88.822 -     *
  88.823 -     * @param o element to be removed from this list, if present
  88.824 -     * @return {@code true} if the list contained the specified element
  88.825 -     * @since 1.6
  88.826 -     */
  88.827 -    public boolean removeLastOccurrence(Object o) {
  88.828 -        if (o == null) {
  88.829 -            for (Node<E> x = last; x != null; x = x.prev) {
  88.830 -                if (x.item == null) {
  88.831 -                    unlink(x);
  88.832 -                    return true;
  88.833 -                }
  88.834 -            }
  88.835 -        } else {
  88.836 -            for (Node<E> x = last; x != null; x = x.prev) {
  88.837 -                if (o.equals(x.item)) {
  88.838 -                    unlink(x);
  88.839 -                    return true;
  88.840 -                }
  88.841 -            }
  88.842 -        }
  88.843 -        return false;
  88.844 -    }
  88.845 -
  88.846 -    /**
  88.847 -     * Returns a list-iterator of the elements in this list (in proper
  88.848 -     * sequence), starting at the specified position in the list.
  88.849 -     * Obeys the general contract of {@code List.listIterator(int)}.<p>
  88.850 -     *
  88.851 -     * The list-iterator is <i>fail-fast</i>: if the list is structurally
  88.852 -     * modified at any time after the Iterator is created, in any way except
  88.853 -     * through the list-iterator's own {@code remove} or {@code add}
  88.854 -     * methods, the list-iterator will throw a
  88.855 -     * {@code ConcurrentModificationException}.  Thus, in the face of
  88.856 -     * concurrent modification, the iterator fails quickly and cleanly, rather
  88.857 -     * than risking arbitrary, non-deterministic behavior at an undetermined
  88.858 -     * time in the future.
  88.859 -     *
  88.860 -     * @param index index of the first element to be returned from the
  88.861 -     *              list-iterator (by a call to {@code next})
  88.862 -     * @return a ListIterator of the elements in this list (in proper
  88.863 -     *         sequence), starting at the specified position in the list
  88.864 -     * @throws IndexOutOfBoundsException {@inheritDoc}
  88.865 -     * @see List#listIterator(int)
  88.866 -     */
  88.867 -    public ListIterator<E> listIterator(int index) {
  88.868 -        checkPositionIndex(index);
  88.869 -        return new ListItr(index);
  88.870 -    }
  88.871 -
  88.872 -    private class ListItr implements ListIterator<E> {
  88.873 -        private Node<E> lastReturned = null;
  88.874 -        private Node<E> next;
  88.875 -        private int nextIndex;
  88.876 -        private int expectedModCount = modCount;
  88.877 -
  88.878 -        ListItr(int index) {
  88.879 -            // assert isPositionIndex(index);
  88.880 -            next = (index == size) ? null : node(index);
  88.881 -            nextIndex = index;
  88.882 -        }
  88.883 -
  88.884 -        public boolean hasNext() {
  88.885 -            return nextIndex < size;
  88.886 -        }
  88.887 -
  88.888 -        public E next() {
  88.889 -            checkForComodification();
  88.890 -            if (!hasNext())
  88.891 -                throw new NoSuchElementException();
  88.892 -
  88.893 -            lastReturned = next;
  88.894 -            next = next.next;
  88.895 -            nextIndex++;
  88.896 -            return lastReturned.item;
  88.897 -        }
  88.898 -
  88.899 -        public boolean hasPrevious() {
  88.900 -            return nextIndex > 0;
  88.901 -        }
  88.902 -
  88.903 -        public E previous() {
  88.904 -            checkForComodification();
  88.905 -            if (!hasPrevious())
  88.906 -                throw new NoSuchElementException();
  88.907 -
  88.908 -            lastReturned = next = (next == null) ? last : next.prev;
  88.909 -            nextIndex--;
  88.910 -            return lastReturned.item;
  88.911 -        }
  88.912 -
  88.913 -        public int nextIndex() {
  88.914 -            return nextIndex;
  88.915 -        }
  88.916 -
  88.917 -        public int previousIndex() {
  88.918 -            return nextIndex - 1;
  88.919 -        }
  88.920 -
  88.921 -        public void remove() {
  88.922 -            checkForComodification();
  88.923 -            if (lastReturned == null)
  88.924 -                throw new IllegalStateException();
  88.925 -
  88.926 -            Node<E> lastNext = lastReturned.next;
  88.927 -            unlink(lastReturned);
  88.928 -            if (next == lastReturned)
  88.929 -                next = lastNext;
  88.930 -            else
  88.931 -                nextIndex--;
  88.932 -            lastReturned = null;
  88.933 -            expectedModCount++;
  88.934 -        }
  88.935 -
  88.936 -        public void set(E e) {
  88.937 -            if (lastReturned == null)
  88.938 -                throw new IllegalStateException();
  88.939 -            checkForComodification();
  88.940 -            lastReturned.item = e;
  88.941 -        }
  88.942 -
  88.943 -        public void add(E e) {
  88.944 -            checkForComodification();
  88.945 -            lastReturned = null;
  88.946 -            if (next == null)
  88.947 -                linkLast(e);
  88.948 -            else
  88.949 -                linkBefore(e, next);
  88.950 -            nextIndex++;
  88.951 -            expectedModCount++;
  88.952 -        }
  88.953 -
  88.954 -        final void checkForComodification() {
  88.955 -            if (modCount != expectedModCount)
  88.956 -                throw new ConcurrentModificationException();
  88.957 -        }
  88.958 -    }
  88.959 -
  88.960 -    private static class Node<E> {
  88.961 -        E item;
  88.962 -        Node<E> next;
  88.963 -        Node<E> prev;
  88.964 -
  88.965 -        Node(Node<E> prev, E element, Node<E> next) {
  88.966 -            this.item = element;
  88.967 -            this.next = next;
  88.968 -            this.prev = prev;
  88.969 -        }
  88.970 -    }
  88.971 -
  88.972 -    /**
  88.973 -     * @since 1.6
  88.974 -     */
  88.975 -    public Iterator<E> descendingIterator() {
  88.976 -        return new DescendingIterator();
  88.977 -    }
  88.978 -
  88.979 -    /**
  88.980 -     * Adapter to provide descending iterators via ListItr.previous
  88.981 -     */
  88.982 -    private class DescendingIterator implements Iterator<E> {
  88.983 -        private final ListItr itr = new ListItr(size());
  88.984 -        public boolean hasNext() {
  88.985 -            return itr.hasPrevious();
  88.986 -        }
  88.987 -        public E next() {
  88.988 -            return itr.previous();
  88.989 -        }
  88.990 -        public void remove() {
  88.991 -            itr.remove();
  88.992 -        }
  88.993 -    }
  88.994 -
  88.995 -    @SuppressWarnings("unchecked")
  88.996 -    private LinkedList<E> superClone() {
  88.997 -        try {
  88.998 -            return (LinkedList<E>) super.clone();
  88.999 -        } catch (CloneNotSupportedException e) {
 88.1000 -            throw new InternalError();
 88.1001 -        }
 88.1002 -    }
 88.1003 -
 88.1004 -    /**
 88.1005 -     * Returns a shallow copy of this {@code LinkedList}. (The elements
 88.1006 -     * themselves are not cloned.)
 88.1007 -     *
 88.1008 -     * @return a shallow copy of this {@code LinkedList} instance
 88.1009 -     */
 88.1010 -    public Object clone() {
 88.1011 -        LinkedList<E> clone = superClone();
 88.1012 -
 88.1013 -        // Put clone into "virgin" state
 88.1014 -        clone.first = clone.last = null;
 88.1015 -        clone.size = 0;
 88.1016 -        clone.modCount = 0;
 88.1017 -
 88.1018 -        // Initialize clone with our elements
 88.1019 -        for (Node<E> x = first; x != null; x = x.next)
 88.1020 -            clone.add(x.item);
 88.1021 -
 88.1022 -        return clone;
 88.1023 -    }
 88.1024 -
 88.1025 -    /**
 88.1026 -     * Returns an array containing all of the elements in this list
 88.1027 -     * in proper sequence (from first to last element).
 88.1028 -     *
 88.1029 -     * <p>The returned array will be "safe" in that no references to it are
 88.1030 -     * maintained by this list.  (In other words, this method must allocate
 88.1031 -     * a new array).  The caller is thus free to modify the returned array.
 88.1032 -     *
 88.1033 -     * <p>This method acts as bridge between array-based and collection-based
 88.1034 -     * APIs.
 88.1035 -     *
 88.1036 -     * @return an array containing all of the elements in this list
 88.1037 -     *         in proper sequence
 88.1038 -     */
 88.1039 -    public Object[] toArray() {
 88.1040 -        Object[] result = new Object[size];
 88.1041 -        int i = 0;
 88.1042 -        for (Node<E> x = first; x != null; x = x.next)
 88.1043 -            result[i++] = x.item;
 88.1044 -        return result;
 88.1045 -    }
 88.1046 -
 88.1047 -    /**
 88.1048 -     * Returns an array containing all of the elements in this list in
 88.1049 -     * proper sequence (from first to last element); the runtime type of
 88.1050 -     * the returned array is that of the specified array.  If the list fits
 88.1051 -     * in the specified array, it is returned therein.  Otherwise, a new
 88.1052 -     * array is allocated with the runtime type of the specified array and
 88.1053 -     * the size of this list.
 88.1054 -     *
 88.1055 -     * <p>If the list fits in the specified array with room to spare (i.e.,
 88.1056 -     * the array has more elements than the list), the element in the array
 88.1057 -     * immediately following the end of the list is set to {@code null}.
 88.1058 -     * (This is useful in determining the length of the list <i>only</i> if
 88.1059 -     * the caller knows that the list does not contain any null elements.)
 88.1060 -     *
 88.1061 -     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 88.1062 -     * array-based and collection-based APIs.  Further, this method allows
 88.1063 -     * precise control over the runtime type of the output array, and may,
 88.1064 -     * under certain circumstances, be used to save allocation costs.
 88.1065 -     *
 88.1066 -     * <p>Suppose {@code x} is a list known to contain only strings.
 88.1067 -     * The following code can be used to dump the list into a newly
 88.1068 -     * allocated array of {@code String}:
 88.1069 -     *
 88.1070 -     * <pre>
 88.1071 -     *     String[] y = x.toArray(new String[0]);</pre>
 88.1072 -     *
 88.1073 -     * Note that {@code toArray(new Object[0])} is identical in function to
 88.1074 -     * {@code toArray()}.
 88.1075 -     *
 88.1076 -     * @param a the array into which the elements of the list are to
 88.1077 -     *          be stored, if it is big enough; otherwise, a new array of the
 88.1078 -     *          same runtime type is allocated for this purpose.
 88.1079 -     * @return an array containing the elements of the list
 88.1080 -     * @throws ArrayStoreException if the runtime type of the specified array
 88.1081 -     *         is not a supertype of the runtime type of every element in
 88.1082 -     *         this list
 88.1083 -     * @throws NullPointerException if the specified array is null
 88.1084 -     */
 88.1085 -    @SuppressWarnings("unchecked")
 88.1086 -    public <T> T[] toArray(T[] a) {
 88.1087 -        if (a.length < size)
 88.1088 -            a = (T[])java.lang.reflect.Array.newInstance(
 88.1089 -                                a.getClass().getComponentType(), size);
 88.1090 -        int i = 0;
 88.1091 -        Object[] result = a;
 88.1092 -        for (Node<E> x = first; x != null; x = x.next)
 88.1093 -            result[i++] = x.item;
 88.1094 -
 88.1095 -        if (a.length > size)
 88.1096 -            a[size] = null;
 88.1097 -
 88.1098 -        return a;
 88.1099 -    }
 88.1100 -
 88.1101 -    private static final long serialVersionUID = 876323262645176354L;
 88.1102 -
 88.1103 -}
    89.1 --- a/emul/compact/src/main/java/java/util/List.java	Mon Feb 25 19:00:08 2013 +0100
    89.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.3 @@ -1,600 +0,0 @@
    89.4 -/*
    89.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    89.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    89.7 - *
    89.8 - * This code is free software; you can redistribute it and/or modify it
    89.9 - * under the terms of the GNU General Public License version 2 only, as
   89.10 - * published by the Free Software Foundation.  Oracle designates this
   89.11 - * particular file as subject to the "Classpath" exception as provided
   89.12 - * by Oracle in the LICENSE file that accompanied this code.
   89.13 - *
   89.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   89.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   89.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   89.17 - * version 2 for more details (a copy is included in the LICENSE file that
   89.18 - * accompanied this code).
   89.19 - *
   89.20 - * You should have received a copy of the GNU General Public License version
   89.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   89.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   89.23 - *
   89.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   89.25 - * or visit www.oracle.com if you need additional information or have any
   89.26 - * questions.
   89.27 - */
   89.28 -
   89.29 -package java.util;
   89.30 -
   89.31 -/**
   89.32 - * An ordered collection (also known as a <i>sequence</i>).  The user of this
   89.33 - * interface has precise control over where in the list each element is
   89.34 - * inserted.  The user can access elements by their integer index (position in
   89.35 - * the list), and search for elements in the list.<p>
   89.36 - *
   89.37 - * Unlike sets, lists typically allow duplicate elements.  More formally,
   89.38 - * lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt>
   89.39 - * such that <tt>e1.equals(e2)</tt>, and they typically allow multiple
   89.40 - * null elements if they allow null elements at all.  It is not inconceivable
   89.41 - * that someone might wish to implement a list that prohibits duplicates, by
   89.42 - * throwing runtime exceptions when the user attempts to insert them, but we
   89.43 - * expect this usage to be rare.<p>
   89.44 - *
   89.45 - * The <tt>List</tt> interface places additional stipulations, beyond those
   89.46 - * specified in the <tt>Collection</tt> interface, on the contracts of the
   89.47 - * <tt>iterator</tt>, <tt>add</tt>, <tt>remove</tt>, <tt>equals</tt>, and
   89.48 - * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
   89.49 - * also included here for convenience.<p>
   89.50 - *
   89.51 - * The <tt>List</tt> interface provides four methods for positional (indexed)
   89.52 - * access to list elements.  Lists (like Java arrays) are zero based.  Note
   89.53 - * that these operations may execute in time proportional to the index value
   89.54 - * for some implementations (the <tt>LinkedList</tt> class, for
   89.55 - * example). Thus, iterating over the elements in a list is typically
   89.56 - * preferable to indexing through it if the caller does not know the
   89.57 - * implementation.<p>
   89.58 - *
   89.59 - * The <tt>List</tt> interface provides a special iterator, called a
   89.60 - * <tt>ListIterator</tt>, that allows element insertion and replacement, and
   89.61 - * bidirectional access in addition to the normal operations that the
   89.62 - * <tt>Iterator</tt> interface provides.  A method is provided to obtain a
   89.63 - * list iterator that starts at a specified position in the list.<p>
   89.64 - *
   89.65 - * The <tt>List</tt> interface provides two methods to search for a specified
   89.66 - * object.  From a performance standpoint, these methods should be used with
   89.67 - * caution.  In many implementations they will perform costly linear
   89.68 - * searches.<p>
   89.69 - *
   89.70 - * The <tt>List</tt> interface provides two methods to efficiently insert and
   89.71 - * remove multiple elements at an arbitrary point in the list.<p>
   89.72 - *
   89.73 - * Note: While it is permissible for lists to contain themselves as elements,
   89.74 - * extreme caution is advised: the <tt>equals</tt> and <tt>hashCode</tt>
   89.75 - * methods are no longer well defined on such a list.
   89.76 - *
   89.77 - * <p>Some list implementations have restrictions on the elements that
   89.78 - * they may contain.  For example, some implementations prohibit null elements,
   89.79 - * and some have restrictions on the types of their elements.  Attempting to
   89.80 - * add an ineligible element throws an unchecked exception, typically
   89.81 - * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
   89.82 - * to query the presence of an ineligible element may throw an exception,
   89.83 - * or it may simply return false; some implementations will exhibit the former
   89.84 - * behavior and some will exhibit the latter.  More generally, attempting an
   89.85 - * operation on an ineligible element whose completion would not result in
   89.86 - * the insertion of an ineligible element into the list may throw an
   89.87 - * exception or it may succeed, at the option of the implementation.
   89.88 - * Such exceptions are marked as "optional" in the specification for this
   89.89 - * interface.
   89.90 - *
   89.91 - * <p>This interface is a member of the
   89.92 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   89.93 - * Java Collections Framework</a>.
   89.94 - *
   89.95 - * @param <E> the type of elements in this list
   89.96 - *
   89.97 - * @author  Josh Bloch
   89.98 - * @author  Neal Gafter
   89.99 - * @see Collection
  89.100 - * @see Set
  89.101 - * @see ArrayList
  89.102 - * @see LinkedList
  89.103 - * @see Vector
  89.104 - * @see Arrays#asList(Object[])
  89.105 - * @see Collections#nCopies(int, Object)
  89.106 - * @see Collections#EMPTY_LIST
  89.107 - * @see AbstractList
  89.108 - * @see AbstractSequentialList
  89.109 - * @since 1.2
  89.110 - */
  89.111 -
  89.112 -public interface List<E> extends Collection<E> {
  89.113 -    // Query Operations
  89.114 -
  89.115 -    /**
  89.116 -     * Returns the number of elements in this list.  If this list contains
  89.117 -     * more than <tt>Integer.MAX_VALUE</tt> elements, returns
  89.118 -     * <tt>Integer.MAX_VALUE</tt>.
  89.119 -     *
  89.120 -     * @return the number of elements in this list
  89.121 -     */
  89.122 -    int size();
  89.123 -
  89.124 -    /**
  89.125 -     * Returns <tt>true</tt> if this list contains no elements.
  89.126 -     *
  89.127 -     * @return <tt>true</tt> if this list contains no elements
  89.128 -     */
  89.129 -    boolean isEmpty();
  89.130 -
  89.131 -    /**
  89.132 -     * Returns <tt>true</tt> if this list contains the specified element.
  89.133 -     * More formally, returns <tt>true</tt> if and only if this list contains
  89.134 -     * at least one element <tt>e</tt> such that
  89.135 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  89.136 -     *
  89.137 -     * @param o element whose presence in this list is to be tested
  89.138 -     * @return <tt>true</tt> if this list contains the specified element
  89.139 -     * @throws ClassCastException if the type of the specified element
  89.140 -     *         is incompatible with this list
  89.141 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.142 -     * @throws NullPointerException if the specified element is null and this
  89.143 -     *         list does not permit null elements
  89.144 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.145 -     */
  89.146 -    boolean contains(Object o);
  89.147 -
  89.148 -    /**
  89.149 -     * Returns an iterator over the elements in this list in proper sequence.
  89.150 -     *
  89.151 -     * @return an iterator over the elements in this list in proper sequence
  89.152 -     */
  89.153 -    Iterator<E> iterator();
  89.154 -
  89.155 -    /**
  89.156 -     * Returns an array containing all of the elements in this list in proper
  89.157 -     * sequence (from first to last element).
  89.158 -     *
  89.159 -     * <p>The returned array will be "safe" in that no references to it are
  89.160 -     * maintained by this list.  (In other words, this method must
  89.161 -     * allocate a new array even if this list is backed by an array).
  89.162 -     * The caller is thus free to modify the returned array.
  89.163 -     *
  89.164 -     * <p>This method acts as bridge between array-based and collection-based
  89.165 -     * APIs.
  89.166 -     *
  89.167 -     * @return an array containing all of the elements in this list in proper
  89.168 -     *         sequence
  89.169 -     * @see Arrays#asList(Object[])
  89.170 -     */
  89.171 -    Object[] toArray();
  89.172 -
  89.173 -    /**
  89.174 -     * Returns an array containing all of the elements in this list in
  89.175 -     * proper sequence (from first to last element); the runtime type of
  89.176 -     * the returned array is that of the specified array.  If the list fits
  89.177 -     * in the specified array, it is returned therein.  Otherwise, a new
  89.178 -     * array is allocated with the runtime type of the specified array and
  89.179 -     * the size of this list.
  89.180 -     *
  89.181 -     * <p>If the list fits in the specified array with room to spare (i.e.,
  89.182 -     * the array has more elements than the list), the element in the array
  89.183 -     * immediately following the end of the list is set to <tt>null</tt>.
  89.184 -     * (This is useful in determining the length of the list <i>only</i> if
  89.185 -     * the caller knows that the list does not contain any null elements.)
  89.186 -     *
  89.187 -     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  89.188 -     * array-based and collection-based APIs.  Further, this method allows
  89.189 -     * precise control over the runtime type of the output array, and may,
  89.190 -     * under certain circumstances, be used to save allocation costs.
  89.191 -     *
  89.192 -     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
  89.193 -     * The following code can be used to dump the list into a newly
  89.194 -     * allocated array of <tt>String</tt>:
  89.195 -     *
  89.196 -     * <pre>
  89.197 -     *     String[] y = x.toArray(new String[0]);</pre>
  89.198 -     *
  89.199 -     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  89.200 -     * <tt>toArray()</tt>.
  89.201 -     *
  89.202 -     * @param a the array into which the elements of this list are to
  89.203 -     *          be stored, if it is big enough; otherwise, a new array of the
  89.204 -     *          same runtime type is allocated for this purpose.
  89.205 -     * @return an array containing the elements of this list
  89.206 -     * @throws ArrayStoreException if the runtime type of the specified array
  89.207 -     *         is not a supertype of the runtime type of every element in
  89.208 -     *         this list
  89.209 -     * @throws NullPointerException if the specified array is null
  89.210 -     */
  89.211 -    <T> T[] toArray(T[] a);
  89.212 -
  89.213 -
  89.214 -    // Modification Operations
  89.215 -
  89.216 -    /**
  89.217 -     * Appends the specified element to the end of this list (optional
  89.218 -     * operation).
  89.219 -     *
  89.220 -     * <p>Lists that support this operation may place limitations on what
  89.221 -     * elements may be added to this list.  In particular, some
  89.222 -     * lists will refuse to add null elements, and others will impose
  89.223 -     * restrictions on the type of elements that may be added.  List
  89.224 -     * classes should clearly specify in their documentation any restrictions
  89.225 -     * on what elements may be added.
  89.226 -     *
  89.227 -     * @param e element to be appended to this list
  89.228 -     * @return <tt>true</tt> (as specified by {@link Collection#add})
  89.229 -     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  89.230 -     *         is not supported by this list
  89.231 -     * @throws ClassCastException if the class of the specified element
  89.232 -     *         prevents it from being added to this list
  89.233 -     * @throws NullPointerException if the specified element is null and this
  89.234 -     *         list does not permit null elements
  89.235 -     * @throws IllegalArgumentException if some property of this element
  89.236 -     *         prevents it from being added to this list
  89.237 -     */
  89.238 -    boolean add(E e);
  89.239 -
  89.240 -    /**
  89.241 -     * Removes the first occurrence of the specified element from this list,
  89.242 -     * if it is present (optional operation).  If this list does not contain
  89.243 -     * the element, it is unchanged.  More formally, removes the element with
  89.244 -     * the lowest index <tt>i</tt> such that
  89.245 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
  89.246 -     * (if such an element exists).  Returns <tt>true</tt> if this list
  89.247 -     * contained the specified element (or equivalently, if this list changed
  89.248 -     * as a result of the call).
  89.249 -     *
  89.250 -     * @param o element to be removed from this list, if present
  89.251 -     * @return <tt>true</tt> if this list contained the specified element
  89.252 -     * @throws ClassCastException if the type of the specified element
  89.253 -     *         is incompatible with this list
  89.254 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.255 -     * @throws NullPointerException if the specified element is null and this
  89.256 -     *         list does not permit null elements
  89.257 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.258 -     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  89.259 -     *         is not supported by this list
  89.260 -     */
  89.261 -    boolean remove(Object o);
  89.262 -
  89.263 -
  89.264 -    // Bulk Modification Operations
  89.265 -
  89.266 -    /**
  89.267 -     * Returns <tt>true</tt> if this list contains all of the elements of the
  89.268 -     * specified collection.
  89.269 -     *
  89.270 -     * @param  c collection to be checked for containment in this list
  89.271 -     * @return <tt>true</tt> if this list contains all of the elements of the
  89.272 -     *         specified collection
  89.273 -     * @throws ClassCastException if the types of one or more elements
  89.274 -     *         in the specified collection are incompatible with this
  89.275 -     *         list
  89.276 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.277 -     * @throws NullPointerException if the specified collection contains one
  89.278 -     *         or more null elements and this list does not permit null
  89.279 -     *         elements
  89.280 -     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  89.281 -     *         or if the specified collection is null
  89.282 -     * @see #contains(Object)
  89.283 -     */
  89.284 -    boolean containsAll(Collection<?> c);
  89.285 -
  89.286 -    /**
  89.287 -     * Appends all of the elements in the specified collection to the end of
  89.288 -     * this list, in the order that they are returned by the specified
  89.289 -     * collection's iterator (optional operation).  The behavior of this
  89.290 -     * operation is undefined if the specified collection is modified while
  89.291 -     * the operation is in progress.  (Note that this will occur if the
  89.292 -     * specified collection is this list, and it's nonempty.)
  89.293 -     *
  89.294 -     * @param c collection containing elements to be added to this list
  89.295 -     * @return <tt>true</tt> if this list changed as a result of the call
  89.296 -     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  89.297 -     *         is not supported by this list
  89.298 -     * @throws ClassCastException if the class of an element of the specified
  89.299 -     *         collection prevents it from being added to this list
  89.300 -     * @throws NullPointerException if the specified collection contains one
  89.301 -     *         or more null elements and this list does not permit null
  89.302 -     *         elements, or if the specified collection is null
  89.303 -     * @throws IllegalArgumentException if some property of an element of the
  89.304 -     *         specified collection prevents it from being added to this list
  89.305 -     * @see #add(Object)
  89.306 -     */
  89.307 -    boolean addAll(Collection<? extends E> c);
  89.308 -
  89.309 -    /**
  89.310 -     * Inserts all of the elements in the specified collection into this
  89.311 -     * list at the specified position (optional operation).  Shifts the
  89.312 -     * element currently at that position (if any) and any subsequent
  89.313 -     * elements to the right (increases their indices).  The new elements
  89.314 -     * will appear in this list in the order that they are returned by the
  89.315 -     * specified collection's iterator.  The behavior of this operation is
  89.316 -     * undefined if the specified collection is modified while the
  89.317 -     * operation is in progress.  (Note that this will occur if the specified
  89.318 -     * collection is this list, and it's nonempty.)
  89.319 -     *
  89.320 -     * @param index index at which to insert the first element from the
  89.321 -     *              specified collection
  89.322 -     * @param c collection containing elements to be added to this list
  89.323 -     * @return <tt>true</tt> if this list changed as a result of the call
  89.324 -     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  89.325 -     *         is not supported by this list
  89.326 -     * @throws ClassCastException if the class of an element of the specified
  89.327 -     *         collection prevents it from being added to this list
  89.328 -     * @throws NullPointerException if the specified collection contains one
  89.329 -     *         or more null elements and this list does not permit null
  89.330 -     *         elements, or if the specified collection is null
  89.331 -     * @throws IllegalArgumentException if some property of an element of the
  89.332 -     *         specified collection prevents it from being added to this list
  89.333 -     * @throws IndexOutOfBoundsException if the index is out of range
  89.334 -     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
  89.335 -     */
  89.336 -    boolean addAll(int index, Collection<? extends E> c);
  89.337 -
  89.338 -    /**
  89.339 -     * Removes from this list all of its elements that are contained in the
  89.340 -     * specified collection (optional operation).
  89.341 -     *
  89.342 -     * @param c collection containing elements to be removed from this list
  89.343 -     * @return <tt>true</tt> if this list changed as a result of the call
  89.344 -     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
  89.345 -     *         is not supported by this list
  89.346 -     * @throws ClassCastException if the class of an element of this list
  89.347 -     *         is incompatible with the specified collection
  89.348 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.349 -     * @throws NullPointerException if this list contains a null element and the
  89.350 -     *         specified collection does not permit null elements
  89.351 -     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  89.352 -     *         or if the specified collection is null
  89.353 -     * @see #remove(Object)
  89.354 -     * @see #contains(Object)
  89.355 -     */
  89.356 -    boolean removeAll(Collection<?> c);
  89.357 -
  89.358 -    /**
  89.359 -     * Retains only the elements in this list that are contained in the
  89.360 -     * specified collection (optional operation).  In other words, removes
  89.361 -     * from this list all of its elements that are not contained in the
  89.362 -     * specified collection.
  89.363 -     *
  89.364 -     * @param c collection containing elements to be retained in this list
  89.365 -     * @return <tt>true</tt> if this list changed as a result of the call
  89.366 -     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
  89.367 -     *         is not supported by this list
  89.368 -     * @throws ClassCastException if the class of an element of this list
  89.369 -     *         is incompatible with the specified collection
  89.370 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  89.371 -     * @throws NullPointerException if this list contains a null element and the
  89.372 -     *         specified collection does not permit null elements
  89.373 -     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  89.374 -     *         or if the specified collection is null
  89.375 -     * @see #remove(Object)
  89.376 -     * @see #contains(Object)
  89.377 -     */
  89.378 -    boolean retainAll(Collection<?> c);
  89.379 -
  89.380 -    /**
  89.381 -     * Removes all of the elements from this list (optional operation).
  89.382 -     * The list will be empty after this call returns.
  89.383 -     *
  89.384 -     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
  89.385 -     *         is not supported by this list
  89.386 -     */
  89.387 -    void clear();
  89.388 -
  89.389 -
  89.390 -    // Comparison and hashing
  89.391 -
  89.392 -    /**
  89.393 -     * Compares the specified object with this list for equality.  Returns
  89.394 -     * <tt>true</tt> if and only if the specified object is also a list, both
  89.395 -     * lists have the same size, and all corresponding pairs of elements in
  89.396 -     * the two lists are <i>equal</i>.  (Two elements <tt>e1</tt> and
  89.397 -     * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
  89.398 -     * e1.equals(e2))</tt>.)  In other words, two lists are defined to be
  89.399 -     * equal if they contain the same elements in the same order.  This
  89.400 -     * definition ensures that the equals method works properly across
  89.401 -     * different implementations of the <tt>List</tt> interface.
  89.402 -     *
  89.403 -     * @param o the object to be compared for equality with this list
  89.404 -     * @return <tt>true</tt> if the specified object is equal to this list
  89.405 -     */
  89.406 -    boolean equals(Object o);
  89.407 -
  89.408 -    /**
  89.409 -     * Returns the hash code value for this list.  The hash code of a list
  89.410 -     * is defined to be the result of the following calculation:
  89.411 -     * <pre>
  89.412 -     *  int hashCode = 1;
  89.413 -     *  for (E e : list)
  89.414 -     *      hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
  89.415 -     * </pre>
  89.416 -     * This ensures that <tt>list1.equals(list2)</tt> implies that
  89.417 -     * <tt>list1.hashCode()==list2.hashCode()</tt> for any two lists,
  89.418 -     * <tt>list1</tt> and <tt>list2</tt>, as required by the general
  89.419 -     * contract of {@link Object#hashCode}.
  89.420 -     *
  89.421 -     * @return the hash code value for this list
  89.422 -     * @see Object#equals(Object)
  89.423 -     * @see #equals(Object)
  89.424 -     */
  89.425 -    int hashCode();
  89.426 -
  89.427 -
  89.428 -    // Positional Access Operations
  89.429 -
  89.430 -    /**
  89.431 -     * Returns the element at the specified position in this list.
  89.432 -     *
  89.433 -     * @param index index of the element to return
  89.434 -     * @return the element at the specified position in this list
  89.435 -     * @throws IndexOutOfBoundsException if the index is out of range
  89.436 -     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
  89.437 -     */
  89.438 -    E get(int index);
  89.439 -
  89.440 -    /**
  89.441 -     * Replaces the element at the specified position in this list with the
  89.442 -     * specified element (optional operation).
  89.443 -     *
  89.444 -     * @param index index of the element to replace
  89.445 -     * @param element element to be stored at the specified position
  89.446 -     * @return the element previously at the specified position
  89.447 -     * @throws UnsupportedOperationException if the <tt>set</tt> operation
  89.448 -     *         is not supported by this list
  89.449 -     * @throws ClassCastException if the class of the specified element
  89.450 -     *         prevents it from being added to this list
  89.451 -     * @throws NullPointerException if the specified element is null and
  89.452 -     *         this list does not permit null elements
  89.453 -     * @throws IllegalArgumentException if some property of the specified
  89.454 -     *         element prevents it from being added to this list
  89.455 -     * @throws IndexOutOfBoundsException if the index is out of range
  89.456 -     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
  89.457 -     */
  89.458 -    E set(int index, E element);
  89.459 -
  89.460 -    /**
  89.461 -     * Inserts the specified element at the specified position in this list
  89.462 -     * (optional operation).  Shifts the element currently at that position
  89.463 -     * (if any) and any subsequent elements to the right (adds one to their
  89.464 -     * indices).
  89.465 -     *
  89.466 -     * @param index index at which the specified element is to be inserted
  89.467 -     * @param element element to be inserted
  89.468 -     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  89.469 -     *         is not supported by this list
  89.470 -     * @throws ClassCastException if the class of the specified element
  89.471 -     *         prevents it from being added to this list
  89.472 -     * @throws NullPointerException if the specified element is null and
  89.473 -     *         this list does not permit null elements
  89.474 -     * @throws IllegalArgumentException if some property of the specified
  89.475 -     *         element prevents it from being added to this list
  89.476 -     * @throws IndexOutOfBoundsException if the index is out of range
  89.477 -     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
  89.478 -     */
  89.479 -    void add(int index, E element);
  89.480 -
  89.481 -    /**
  89.482 -     * Removes the element at the specified position in this list (optional
  89.483 -     * operation).  Shifts any subsequent elements to the left (subtracts one
  89.484 -     * from their indices).  Returns the element that was removed from the
  89.485 -     * list.
  89.486 -     *
  89.487 -     * @param index the index of the element to be removed
  89.488 -     * @return the element previously at the specified position
  89.489 -     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  89.490 -     *         is not supported by this list
  89.491 -     * @throws IndexOutOfBoundsException if the index is out of range
  89.492 -     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
  89.493 -     */
  89.494 -    E remove(int index);
  89.495 -
  89.496 -
  89.497 -    // Search Operations
  89.498 -
  89.499 -    /**
  89.500 -     * Returns the index of the first occurrence of the specified element
  89.501 -     * in this list, or -1 if this list does not contain the element.
  89.502 -     * More formally, returns the lowest index <tt>i</tt> such that
  89.503 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  89.504 -     * or -1 if there is no such index.
  89.505 -     *
  89.506 -     * @param o element to search for
  89.507 -     * @return the index of the first occurrence of the specified element in
  89.508 -     *         this list, or -1 if this list does not contain the element
  89.509 -     * @throws ClassCastException if the type of the specified element
  89.510 -     *         is incompatible with this list
  89.511 -     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  89.512 -     * @throws NullPointerException if the specified element is null and this
  89.513 -     *         list does not permit null elements
  89.514 -     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  89.515 -     */
  89.516 -    int indexOf(Object o);
  89.517 -
  89.518 -    /**
  89.519 -     * Returns the index of the last occurrence of the specified element
  89.520 -     * in this list, or -1 if this list does not contain the element.
  89.521 -     * More formally, returns the highest index <tt>i</tt> such that
  89.522 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
  89.523 -     * or -1 if there is no such index.
  89.524 -     *
  89.525 -     * @param o element to search for
  89.526 -     * @return the index of the last occurrence of the specified element in
  89.527 -     *         this list, or -1 if this list does not contain the element
  89.528 -     * @throws ClassCastException if the type of the specified element
  89.529 -     *         is incompatible with this list
  89.530 -     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  89.531 -     * @throws NullPointerException if the specified element is null and this
  89.532 -     *         list does not permit null elements
  89.533 -     *         (<a href="Collection.html#optional-restrictions">optional</a>)
  89.534 -     */
  89.535 -    int lastIndexOf(Object o);
  89.536 -
  89.537 -
  89.538 -    // List Iterators
  89.539 -
  89.540 -    /**
  89.541 -     * Returns a list iterator over the elements in this list (in proper
  89.542 -     * sequence).
  89.543 -     *
  89.544 -     * @return a list iterator over the elements in this list (in proper
  89.545 -     *         sequence)
  89.546 -     */
  89.547 -    ListIterator<E> listIterator();
  89.548 -
  89.549 -    /**
  89.550 -     * Returns a list iterator over the elements in this list (in proper
  89.551 -     * sequence), starting at the specified position in the list.
  89.552 -     * The specified index indicates the first element that would be
  89.553 -     * returned by an initial call to {@link ListIterator#next next}.
  89.554 -     * An initial call to {@link ListIterator#previous previous} would
  89.555 -     * return the element with the specified index minus one.
  89.556 -     *
  89.557 -     * @param index index of the first element to be returned from the
  89.558 -     *        list iterator (by a call to {@link ListIterator#next next})
  89.559 -     * @return a list iterator over the elements in this list (in proper
  89.560 -     *         sequence), starting at the specified position in the list
  89.561 -     * @throws IndexOutOfBoundsException if the index is out of range
  89.562 -     *         ({@code index < 0 || index > size()})
  89.563 -     */
  89.564 -    ListIterator<E> listIterator(int index);
  89.565 -
  89.566 -    // View
  89.567 -
  89.568 -    /**
  89.569 -     * Returns a view of the portion of this list between the specified
  89.570 -     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.  (If
  89.571 -     * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is
  89.572 -     * empty.)  The returned list is backed by this list, so non-structural
  89.573 -     * changes in the returned list are reflected in this list, and vice-versa.
  89.574 -     * The returned list supports all of the optional list operations supported
  89.575 -     * by this list.<p>
  89.576 -     *
  89.577 -     * This method eliminates the need for explicit range operations (of
  89.578 -     * the sort that commonly exist for arrays).  Any operation that expects
  89.579 -     * a list can be used as a range operation by passing a subList view
  89.580 -     * instead of a whole list.  For example, the following idiom
  89.581 -     * removes a range of elements from a list:
  89.582 -     * <pre>
  89.583 -     *      list.subList(from, to).clear();
  89.584 -     * </pre>
  89.585 -     * Similar idioms may be constructed for <tt>indexOf</tt> and
  89.586 -     * <tt>lastIndexOf</tt>, and all of the algorithms in the
  89.587 -     * <tt>Collections</tt> class can be applied to a subList.<p>
  89.588 -     *
  89.589 -     * The semantics of the list returned by this method become undefined if
  89.590 -     * the backing list (i.e., this list) is <i>structurally modified</i> in
  89.591 -     * any way other than via the returned list.  (Structural modifications are
  89.592 -     * those that change the size of this list, or otherwise perturb it in such
  89.593 -     * a fashion that iterations in progress may yield incorrect results.)
  89.594 -     *
  89.595 -     * @param fromIndex low endpoint (inclusive) of the subList
  89.596 -     * @param toIndex high endpoint (exclusive) of the subList
  89.597 -     * @return a view of the specified range within this list
  89.598 -     * @throws IndexOutOfBoundsException for an illegal endpoint index value
  89.599 -     *         (<tt>fromIndex &lt; 0 || toIndex &gt; size ||
  89.600 -     *         fromIndex &gt; toIndex</tt>)
  89.601 -     */
  89.602 -    List<E> subList(int fromIndex, int toIndex);
  89.603 -}
    90.1 --- a/emul/compact/src/main/java/java/util/ListIterator.java	Mon Feb 25 19:00:08 2013 +0100
    90.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.3 @@ -1,195 +0,0 @@
    90.4 -/*
    90.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
    90.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    90.7 - *
    90.8 - * This code is free software; you can redistribute it and/or modify it
    90.9 - * under the terms of the GNU General Public License version 2 only, as
   90.10 - * published by the Free Software Foundation.  Oracle designates this
   90.11 - * particular file as subject to the "Classpath" exception as provided
   90.12 - * by Oracle in the LICENSE file that accompanied this code.
   90.13 - *
   90.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   90.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   90.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   90.17 - * version 2 for more details (a copy is included in the LICENSE file that
   90.18 - * accompanied this code).
   90.19 - *
   90.20 - * You should have received a copy of the GNU General Public License version
   90.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   90.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   90.23 - *
   90.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   90.25 - * or visit www.oracle.com if you need additional information or have any
   90.26 - * questions.
   90.27 - */
   90.28 -
   90.29 -package java.util;
   90.30 -
   90.31 -/**
   90.32 - * An iterator for lists that allows the programmer
   90.33 - * to traverse the list in either direction, modify
   90.34 - * the list during iteration, and obtain the iterator's
   90.35 - * current position in the list. A {@code ListIterator}
   90.36 - * has no current element; its <I>cursor position</I> always
   90.37 - * lies between the element that would be returned by a call
   90.38 - * to {@code previous()} and the element that would be
   90.39 - * returned by a call to {@code next()}.
   90.40 - * An iterator for a list of length {@code n} has {@code n+1} possible
   90.41 - * cursor positions, as illustrated by the carets ({@code ^}) below:
   90.42 - * <PRE>
   90.43 - *                      Element(0)   Element(1)   Element(2)   ... Element(n-1)
   90.44 - * cursor positions:  ^            ^            ^            ^                  ^
   90.45 - * </PRE>
   90.46 - * Note that the {@link #remove} and {@link #set(Object)} methods are
   90.47 - * <i>not</i> defined in terms of the cursor position;  they are defined to
   90.48 - * operate on the last element returned by a call to {@link #next} or
   90.49 - * {@link #previous()}.
   90.50 - *
   90.51 - * <p>This interface is a member of the
   90.52 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   90.53 - * Java Collections Framework</a>.
   90.54 - *
   90.55 - * @author  Josh Bloch
   90.56 - * @see Collection
   90.57 - * @see List
   90.58 - * @see Iterator
   90.59 - * @see Enumeration
   90.60 - * @see List#listIterator()
   90.61 - * @since   1.2
   90.62 - */
   90.63 -public interface ListIterator<E> extends Iterator<E> {
   90.64 -    // Query Operations
   90.65 -
   90.66 -    /**
   90.67 -     * Returns {@code true} if this list iterator has more elements when
   90.68 -     * traversing the list in the forward direction. (In other words,
   90.69 -     * returns {@code true} if {@link #next} would return an element rather
   90.70 -     * than throwing an exception.)
   90.71 -     *
   90.72 -     * @return {@code true} if the list iterator has more elements when
   90.73 -     *         traversing the list in the forward direction
   90.74 -     */
   90.75 -    boolean hasNext();
   90.76 -
   90.77 -    /**
   90.78 -     * Returns the next element in the list and advances the cursor position.
   90.79 -     * This method may be called repeatedly to iterate through the list,
   90.80 -     * or intermixed with calls to {@link #previous} to go back and forth.
   90.81 -     * (Note that alternating calls to {@code next} and {@code previous}
   90.82 -     * will return the same element repeatedly.)
   90.83 -     *
   90.84 -     * @return the next element in the list
   90.85 -     * @throws NoSuchElementException if the iteration has no next element
   90.86 -     */
   90.87 -    E next();
   90.88 -
   90.89 -    /**
   90.90 -     * Returns {@code true} if this list iterator has more elements when
   90.91 -     * traversing the list in the reverse direction.  (In other words,
   90.92 -     * returns {@code true} if {@link #previous} would return an element
   90.93 -     * rather than throwing an exception.)
   90.94 -     *
   90.95 -     * @return {@code true} if the list iterator has more elements when
   90.96 -     *         traversing the list in the reverse direction
   90.97 -     */
   90.98 -    boolean hasPrevious();
   90.99 -
  90.100 -    /**
  90.101 -     * Returns the previous element in the list and moves the cursor
  90.102 -     * position backwards.  This method may be called repeatedly to
  90.103 -     * iterate through the list backwards, or intermixed with calls to
  90.104 -     * {@link #next} to go back and forth.  (Note that alternating calls
  90.105 -     * to {@code next} and {@code previous} will return the same
  90.106 -     * element repeatedly.)
  90.107 -     *
  90.108 -     * @return the previous element in the list
  90.109 -     * @throws NoSuchElementException if the iteration has no previous
  90.110 -     *         element
  90.111 -     */
  90.112 -    E previous();
  90.113 -
  90.114 -    /**
  90.115 -     * Returns the index of the element that would be returned by a
  90.116 -     * subsequent call to {@link #next}. (Returns list size if the list
  90.117 -     * iterator is at the end of the list.)
  90.118 -     *
  90.119 -     * @return the index of the element that would be returned by a
  90.120 -     *         subsequent call to {@code next}, or list size if the list
  90.121 -     *         iterator is at the end of the list
  90.122 -     */
  90.123 -    int nextIndex();
  90.124 -
  90.125 -    /**
  90.126 -     * Returns the index of the element that would be returned by a
  90.127 -     * subsequent call to {@link #previous}. (Returns -1 if the list
  90.128 -     * iterator is at the beginning of the list.)
  90.129 -     *
  90.130 -     * @return the index of the element that would be returned by a
  90.131 -     *         subsequent call to {@code previous}, or -1 if the list
  90.132 -     *         iterator is at the beginning of the list
  90.133 -     */
  90.134 -    int previousIndex();
  90.135 -
  90.136 -
  90.137 -    // Modification Operations
  90.138 -
  90.139 -    /**
  90.140 -     * Removes from the list the last element that was returned by {@link
  90.141 -     * #next} or {@link #previous} (optional operation).  This call can
  90.142 -     * only be made once per call to {@code next} or {@code previous}.
  90.143 -     * It can be made only if {@link #add} has not been
  90.144 -     * called after the last call to {@code next} or {@code previous}.
  90.145 -     *
  90.146 -     * @throws UnsupportedOperationException if the {@code remove}
  90.147 -     *         operation is not supported by this list iterator
  90.148 -     * @throws IllegalStateException if neither {@code next} nor
  90.149 -     *         {@code previous} have been called, or {@code remove} or
  90.150 -     *         {@code add} have been called after the last call to
  90.151 -     *         {@code next} or {@code previous}
  90.152 -     */
  90.153 -    void remove();
  90.154 -
  90.155 -    /**
  90.156 -     * Replaces the last element returned by {@link #next} or
  90.157 -     * {@link #previous} with the specified element (optional operation).
  90.158 -     * This call can be made only if neither {@link #remove} nor {@link
  90.159 -     * #add} have been called after the last call to {@code next} or
  90.160 -     * {@code previous}.
  90.161 -     *
  90.162 -     * @param e the element with which to replace the last element returned by
  90.163 -     *          {@code next} or {@code previous}
  90.164 -     * @throws UnsupportedOperationException if the {@code set} operation
  90.165 -     *         is not supported by this list iterator
  90.166 -     * @throws ClassCastException if the class of the specified element
  90.167 -     *         prevents it from being added to this list
  90.168 -     * @throws IllegalArgumentException if some aspect of the specified
  90.169 -     *         element prevents it from being added to this list
  90.170 -     * @throws IllegalStateException if neither {@code next} nor
  90.171 -     *         {@code previous} have been called, or {@code remove} or
  90.172 -     *         {@code add} have been called after the last call to
  90.173 -     *         {@code next} or {@code previous}
  90.174 -     */
  90.175 -    void set(E e);
  90.176 -
  90.177 -    /**
  90.178 -     * Inserts the specified element into the list (optional operation).
  90.179 -     * The element is inserted immediately before the element that
  90.180 -     * would be returned by {@link #next}, if any, and after the element
  90.181 -     * that would be returned by {@link #previous}, if any.  (If the
  90.182 -     * list contains no elements, the new element becomes the sole element
  90.183 -     * on the list.)  The new element is inserted before the implicit
  90.184 -     * cursor: a subsequent call to {@code next} would be unaffected, and a
  90.185 -     * subsequent call to {@code previous} would return the new element.
  90.186 -     * (This call increases by one the value that would be returned by a
  90.187 -     * call to {@code nextIndex} or {@code previousIndex}.)
  90.188 -     *
  90.189 -     * @param e the element to insert
  90.190 -     * @throws UnsupportedOperationException if the {@code add} method is
  90.191 -     *         not supported by this list iterator
  90.192 -     * @throws ClassCastException if the class of the specified element
  90.193 -     *         prevents it from being added to this list
  90.194 -     * @throws IllegalArgumentException if some aspect of this element
  90.195 -     *         prevents it from being added to this list
  90.196 -     */
  90.197 -    void add(E e);
  90.198 -}
    91.1 --- a/emul/compact/src/main/java/java/util/Map.java	Mon Feb 25 19:00:08 2013 +0100
    91.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.3 @@ -1,478 +0,0 @@
    91.4 -/*
    91.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
    91.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    91.7 - *
    91.8 - * This code is free software; you can redistribute it and/or modify it
    91.9 - * under the terms of the GNU General Public License version 2 only, as
   91.10 - * published by the Free Software Foundation.  Oracle designates this
   91.11 - * particular file as subject to the "Classpath" exception as provided
   91.12 - * by Oracle in the LICENSE file that accompanied this code.
   91.13 - *
   91.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   91.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   91.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   91.17 - * version 2 for more details (a copy is included in the LICENSE file that
   91.18 - * accompanied this code).
   91.19 - *
   91.20 - * You should have received a copy of the GNU General Public License version
   91.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   91.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   91.23 - *
   91.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   91.25 - * or visit www.oracle.com if you need additional information or have any
   91.26 - * questions.
   91.27 - */
   91.28 -
   91.29 -package java.util;
   91.30 -
   91.31 -/**
   91.32 - * An object that maps keys to values.  A map cannot contain duplicate keys;
   91.33 - * each key can map to at most one value.
   91.34 - *
   91.35 - * <p>This interface takes the place of the <tt>Dictionary</tt> class, which
   91.36 - * was a totally abstract class rather than an interface.
   91.37 - *
   91.38 - * <p>The <tt>Map</tt> interface provides three <i>collection views</i>, which
   91.39 - * allow a map's contents to be viewed as a set of keys, collection of values,
   91.40 - * or set of key-value mappings.  The <i>order</i> of a map is defined as
   91.41 - * the order in which the iterators on the map's collection views return their
   91.42 - * elements.  Some map implementations, like the <tt>TreeMap</tt> class, make
   91.43 - * specific guarantees as to their order; others, like the <tt>HashMap</tt>
   91.44 - * class, do not.
   91.45 - *
   91.46 - * <p>Note: great care must be exercised if mutable objects are used as map
   91.47 - * keys.  The behavior of a map is not specified if the value of an object is
   91.48 - * changed in a manner that affects <tt>equals</tt> comparisons while the
   91.49 - * object is a key in the map.  A special case of this prohibition is that it
   91.50 - * is not permissible for a map to contain itself as a key.  While it is
   91.51 - * permissible for a map to contain itself as a value, extreme caution is
   91.52 - * advised: the <tt>equals</tt> and <tt>hashCode</tt> methods are no longer
   91.53 - * well defined on such a map.
   91.54 - *
   91.55 - * <p>All general-purpose map implementation classes should provide two
   91.56 - * "standard" constructors: a void (no arguments) constructor which creates an
   91.57 - * empty map, and a constructor with a single argument of type <tt>Map</tt>,
   91.58 - * which creates a new map with the same key-value mappings as its argument.
   91.59 - * In effect, the latter constructor allows the user to copy any map,
   91.60 - * producing an equivalent map of the desired class.  There is no way to
   91.61 - * enforce this recommendation (as interfaces cannot contain constructors) but
   91.62 - * all of the general-purpose map implementations in the JDK comply.
   91.63 - *
   91.64 - * <p>The "destructive" methods contained in this interface, that is, the
   91.65 - * methods that modify the map on which they operate, are specified to throw
   91.66 - * <tt>UnsupportedOperationException</tt> if this map does not support the
   91.67 - * operation.  If this is the case, these methods may, but are not required
   91.68 - * to, throw an <tt>UnsupportedOperationException</tt> if the invocation would
   91.69 - * have no effect on the map.  For example, invoking the {@link #putAll(Map)}
   91.70 - * method on an unmodifiable map may, but is not required to, throw the
   91.71 - * exception if the map whose mappings are to be "superimposed" is empty.
   91.72 - *
   91.73 - * <p>Some map implementations have restrictions on the keys and values they
   91.74 - * may contain.  For example, some implementations prohibit null keys and
   91.75 - * values, and some have restrictions on the types of their keys.  Attempting
   91.76 - * to insert an ineligible key or value throws an unchecked exception,
   91.77 - * typically <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.
   91.78 - * Attempting to query the presence of an ineligible key or value may throw an
   91.79 - * exception, or it may simply return false; some implementations will exhibit
   91.80 - * the former behavior and some will exhibit the latter.  More generally,
   91.81 - * attempting an operation on an ineligible key or value whose completion
   91.82 - * would not result in the insertion of an ineligible element into the map may
   91.83 - * throw an exception or it may succeed, at the option of the implementation.
   91.84 - * Such exceptions are marked as "optional" in the specification for this
   91.85 - * interface.
   91.86 - *
   91.87 - * <p>This interface is a member of the
   91.88 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   91.89 - * Java Collections Framework</a>.
   91.90 - *
   91.91 - * <p>Many methods in Collections Framework interfaces are defined
   91.92 - * in terms of the {@link Object#equals(Object) equals} method.  For
   91.93 - * example, the specification for the {@link #containsKey(Object)
   91.94 - * containsKey(Object key)} method says: "returns <tt>true</tt> if and
   91.95 - * only if this map contains a mapping for a key <tt>k</tt> such that
   91.96 - * <tt>(key==null ? k==null : key.equals(k))</tt>." This specification should
   91.97 - * <i>not</i> be construed to imply that invoking <tt>Map.containsKey</tt>
   91.98 - * with a non-null argument <tt>key</tt> will cause <tt>key.equals(k)</tt> to
   91.99 - * be invoked for any key <tt>k</tt>.  Implementations are free to
  91.100 - * implement optimizations whereby the <tt>equals</tt> invocation is avoided,
  91.101 - * for example, by first comparing the hash codes of the two keys.  (The
  91.102 - * {@link Object#hashCode()} specification guarantees that two objects with
  91.103 - * unequal hash codes cannot be equal.)  More generally, implementations of
  91.104 - * the various Collections Framework interfaces are free to take advantage of
  91.105 - * the specified behavior of underlying {@link Object} methods wherever the
  91.106 - * implementor deems it appropriate.
  91.107 - *
  91.108 - * @param <K> the type of keys maintained by this map
  91.109 - * @param <V> the type of mapped values
  91.110 - *
  91.111 - * @author  Josh Bloch
  91.112 - * @see HashMap
  91.113 - * @see TreeMap
  91.114 - * @see Hashtable
  91.115 - * @see SortedMap
  91.116 - * @see Collection
  91.117 - * @see Set
  91.118 - * @since 1.2
  91.119 - */
  91.120 -public interface Map<K,V> {
  91.121 -    // Query Operations
  91.122 -
  91.123 -    /**
  91.124 -     * Returns the number of key-value mappings in this map.  If the
  91.125 -     * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
  91.126 -     * <tt>Integer.MAX_VALUE</tt>.
  91.127 -     *
  91.128 -     * @return the number of key-value mappings in this map
  91.129 -     */
  91.130 -    int size();
  91.131 -
  91.132 -    /**
  91.133 -     * Returns <tt>true</tt> if this map contains no key-value mappings.
  91.134 -     *
  91.135 -     * @return <tt>true</tt> if this map contains no key-value mappings
  91.136 -     */
  91.137 -    boolean isEmpty();
  91.138 -
  91.139 -    /**
  91.140 -     * Returns <tt>true</tt> if this map contains a mapping for the specified
  91.141 -     * key.  More formally, returns <tt>true</tt> if and only if
  91.142 -     * this map contains a mapping for a key <tt>k</tt> such that
  91.143 -     * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
  91.144 -     * at most one such mapping.)
  91.145 -     *
  91.146 -     * @param key key whose presence in this map is to be tested
  91.147 -     * @return <tt>true</tt> if this map contains a mapping for the specified
  91.148 -     *         key
  91.149 -     * @throws ClassCastException if the key is of an inappropriate type for
  91.150 -     *         this map
  91.151 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.152 -     * @throws NullPointerException if the specified key is null and this map
  91.153 -     *         does not permit null keys
  91.154 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.155 -     */
  91.156 -    boolean containsKey(Object key);
  91.157 -
  91.158 -    /**
  91.159 -     * Returns <tt>true</tt> if this map maps one or more keys to the
  91.160 -     * specified value.  More formally, returns <tt>true</tt> if and only if
  91.161 -     * this map contains at least one mapping to a value <tt>v</tt> such that
  91.162 -     * <tt>(value==null ? v==null : value.equals(v))</tt>.  This operation
  91.163 -     * will probably require time linear in the map size for most
  91.164 -     * implementations of the <tt>Map</tt> interface.
  91.165 -     *
  91.166 -     * @param value value whose presence in this map is to be tested
  91.167 -     * @return <tt>true</tt> if this map maps one or more keys to the
  91.168 -     *         specified value
  91.169 -     * @throws ClassCastException if the value is of an inappropriate type for
  91.170 -     *         this map
  91.171 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.172 -     * @throws NullPointerException if the specified value is null and this
  91.173 -     *         map does not permit null values
  91.174 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.175 -     */
  91.176 -    boolean containsValue(Object value);
  91.177 -
  91.178 -    /**
  91.179 -     * Returns the value to which the specified key is mapped,
  91.180 -     * or {@code null} if this map contains no mapping for the key.
  91.181 -     *
  91.182 -     * <p>More formally, if this map contains a mapping from a key
  91.183 -     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
  91.184 -     * key.equals(k))}, then this method returns {@code v}; otherwise
  91.185 -     * it returns {@code null}.  (There can be at most one such mapping.)
  91.186 -     *
  91.187 -     * <p>If this map permits null values, then a return value of
  91.188 -     * {@code null} does not <i>necessarily</i> indicate that the map
  91.189 -     * contains no mapping for the key; it's also possible that the map
  91.190 -     * explicitly maps the key to {@code null}.  The {@link #containsKey
  91.191 -     * containsKey} operation may be used to distinguish these two cases.
  91.192 -     *
  91.193 -     * @param key the key whose associated value is to be returned
  91.194 -     * @return the value to which the specified key is mapped, or
  91.195 -     *         {@code null} if this map contains no mapping for the key
  91.196 -     * @throws ClassCastException if the key is of an inappropriate type for
  91.197 -     *         this map
  91.198 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.199 -     * @throws NullPointerException if the specified key is null and this map
  91.200 -     *         does not permit null keys
  91.201 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.202 -     */
  91.203 -    V get(Object key);
  91.204 -
  91.205 -    // Modification Operations
  91.206 -
  91.207 -    /**
  91.208 -     * Associates the specified value with the specified key in this map
  91.209 -     * (optional operation).  If the map previously contained a mapping for
  91.210 -     * the key, the old value is replaced by the specified value.  (A map
  91.211 -     * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
  91.212 -     * if {@link #containsKey(Object) m.containsKey(k)} would return
  91.213 -     * <tt>true</tt>.)
  91.214 -     *
  91.215 -     * @param key key with which the specified value is to be associated
  91.216 -     * @param value value to be associated with the specified key
  91.217 -     * @return the previous value associated with <tt>key</tt>, or
  91.218 -     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  91.219 -     *         (A <tt>null</tt> return can also indicate that the map
  91.220 -     *         previously associated <tt>null</tt> with <tt>key</tt>,
  91.221 -     *         if the implementation supports <tt>null</tt> values.)
  91.222 -     * @throws UnsupportedOperationException if the <tt>put</tt> operation
  91.223 -     *         is not supported by this map
  91.224 -     * @throws ClassCastException if the class of the specified key or value
  91.225 -     *         prevents it from being stored in this map
  91.226 -     * @throws NullPointerException if the specified key or value is null
  91.227 -     *         and this map does not permit null keys or values
  91.228 -     * @throws IllegalArgumentException if some property of the specified key
  91.229 -     *         or value prevents it from being stored in this map
  91.230 -     */
  91.231 -    V put(K key, V value);
  91.232 -
  91.233 -    /**
  91.234 -     * Removes the mapping for a key from this map if it is present
  91.235 -     * (optional operation).   More formally, if this map contains a mapping
  91.236 -     * from key <tt>k</tt> to value <tt>v</tt> such that
  91.237 -     * <code>(key==null ?  k==null : key.equals(k))</code>, that mapping
  91.238 -     * is removed.  (The map can contain at most one such mapping.)
  91.239 -     *
  91.240 -     * <p>Returns the value to which this map previously associated the key,
  91.241 -     * or <tt>null</tt> if the map contained no mapping for the key.
  91.242 -     *
  91.243 -     * <p>If this map permits null values, then a return value of
  91.244 -     * <tt>null</tt> does not <i>necessarily</i> indicate that the map
  91.245 -     * contained no mapping for the key; it's also possible that the map
  91.246 -     * explicitly mapped the key to <tt>null</tt>.
  91.247 -     *
  91.248 -     * <p>The map will not contain a mapping for the specified key once the
  91.249 -     * call returns.
  91.250 -     *
  91.251 -     * @param key key whose mapping is to be removed from the map
  91.252 -     * @return the previous value associated with <tt>key</tt>, or
  91.253 -     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  91.254 -     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  91.255 -     *         is not supported by this map
  91.256 -     * @throws ClassCastException if the key is of an inappropriate type for
  91.257 -     *         this map
  91.258 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.259 -     * @throws NullPointerException if the specified key is null and this
  91.260 -     *         map does not permit null keys
  91.261 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  91.262 -     */
  91.263 -    V remove(Object key);
  91.264 -
  91.265 -
  91.266 -    // Bulk Operations
  91.267 -
  91.268 -    /**
  91.269 -     * Copies all of the mappings from the specified map to this map
  91.270 -     * (optional operation).  The effect of this call is equivalent to that
  91.271 -     * of calling {@link #put(Object,Object) put(k, v)} on this map once
  91.272 -     * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
  91.273 -     * specified map.  The behavior of this operation is undefined if the
  91.274 -     * specified map is modified while the operation is in progress.
  91.275 -     *
  91.276 -     * @param m mappings to be stored in this map
  91.277 -     * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
  91.278 -     *         is not supported by this map
  91.279 -     * @throws ClassCastException if the class of a key or value in the
  91.280 -     *         specified map prevents it from being stored in this map
  91.281 -     * @throws NullPointerException if the specified map is null, or if
  91.282 -     *         this map does not permit null keys or values, and the
  91.283 -     *         specified map contains null keys or values
  91.284 -     * @throws IllegalArgumentException if some property of a key or value in
  91.285 -     *         the specified map prevents it from being stored in this map
  91.286 -     */
  91.287 -    void putAll(Map<? extends K, ? extends V> m);
  91.288 -
  91.289 -    /**
  91.290 -     * Removes all of the mappings from this map (optional operation).
  91.291 -     * The map will be empty after this call returns.
  91.292 -     *
  91.293 -     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
  91.294 -     *         is not supported by this map
  91.295 -     */
  91.296 -    void clear();
  91.297 -
  91.298 -
  91.299 -    // Views
  91.300 -
  91.301 -    /**
  91.302 -     * Returns a {@link Set} view of the keys contained in this map.
  91.303 -     * The set is backed by the map, so changes to the map are
  91.304 -     * reflected in the set, and vice-versa.  If the map is modified
  91.305 -     * while an iteration over the set is in progress (except through
  91.306 -     * the iterator's own <tt>remove</tt> operation), the results of
  91.307 -     * the iteration are undefined.  The set supports element removal,
  91.308 -     * which removes the corresponding mapping from the map, via the
  91.309 -     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
  91.310 -     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
  91.311 -     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
  91.312 -     * operations.
  91.313 -     *
  91.314 -     * @return a set view of the keys contained in this map
  91.315 -     */
  91.316 -    Set<K> keySet();
  91.317 -
  91.318 -    /**
  91.319 -     * Returns a {@link Collection} view of the values contained in this map.
  91.320 -     * The collection is backed by the map, so changes to the map are
  91.321 -     * reflected in the collection, and vice-versa.  If the map is
  91.322 -     * modified while an iteration over the collection is in progress
  91.323 -     * (except through the iterator's own <tt>remove</tt> operation),
  91.324 -     * the results of the iteration are undefined.  The collection
  91.325 -     * supports element removal, which removes the corresponding
  91.326 -     * mapping from the map, via the <tt>Iterator.remove</tt>,
  91.327 -     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
  91.328 -     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
  91.329 -     * support the <tt>add</tt> or <tt>addAll</tt> operations.
  91.330 -     *
  91.331 -     * @return a collection view of the values contained in this map
  91.332 -     */
  91.333 -    Collection<V> values();
  91.334 -
  91.335 -    /**
  91.336 -     * Returns a {@link Set} view of the mappings contained in this map.
  91.337 -     * The set is backed by the map, so changes to the map are
  91.338 -     * reflected in the set, and vice-versa.  If the map is modified
  91.339 -     * while an iteration over the set is in progress (except through
  91.340 -     * the iterator's own <tt>remove</tt> operation, or through the
  91.341 -     * <tt>setValue</tt> operation on a map entry returned by the
  91.342 -     * iterator) the results of the iteration are undefined.  The set
  91.343 -     * supports element removal, which removes the corresponding
  91.344 -     * mapping from the map, via the <tt>Iterator.remove</tt>,
  91.345 -     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  91.346 -     * <tt>clear</tt> operations.  It does not support the
  91.347 -     * <tt>add</tt> or <tt>addAll</tt> operations.
  91.348 -     *
  91.349 -     * @return a set view of the mappings contained in this map
  91.350 -     */
  91.351 -    Set<Map.Entry<K, V>> entrySet();
  91.352 -
  91.353 -    /**
  91.354 -     * A map entry (key-value pair).  The <tt>Map.entrySet</tt> method returns
  91.355 -     * a collection-view of the map, whose elements are of this class.  The
  91.356 -     * <i>only</i> way to obtain a reference to a map entry is from the
  91.357 -     * iterator of this collection-view.  These <tt>Map.Entry</tt> objects are
  91.358 -     * valid <i>only</i> for the duration of the iteration; more formally,
  91.359 -     * the behavior of a map entry is undefined if the backing map has been
  91.360 -     * modified after the entry was returned by the iterator, except through
  91.361 -     * the <tt>setValue</tt> operation on the map entry.
  91.362 -     *
  91.363 -     * @see Map#entrySet()
  91.364 -     * @since 1.2
  91.365 -     */
  91.366 -    interface Entry<K,V> {
  91.367 -        /**
  91.368 -         * Returns the key corresponding to this entry.
  91.369 -         *
  91.370 -         * @return the key corresponding to this entry
  91.371 -         * @throws IllegalStateException implementations may, but are not
  91.372 -         *         required to, throw this exception if the entry has been
  91.373 -         *         removed from the backing map.
  91.374 -         */
  91.375 -        K getKey();
  91.376 -
  91.377 -        /**
  91.378 -         * Returns the value corresponding to this entry.  If the mapping
  91.379 -         * has been removed from the backing map (by the iterator's
  91.380 -         * <tt>remove</tt> operation), the results of this call are undefined.
  91.381 -         *
  91.382 -         * @return the value corresponding to this entry
  91.383 -         * @throws IllegalStateException implementations may, but are not
  91.384 -         *         required to, throw this exception if the entry has been
  91.385 -         *         removed from the backing map.
  91.386 -         */
  91.387 -        V getValue();
  91.388 -
  91.389 -        /**
  91.390 -         * Replaces the value corresponding to this entry with the specified
  91.391 -         * value (optional operation).  (Writes through to the map.)  The
  91.392 -         * behavior of this call is undefined if the mapping has already been
  91.393 -         * removed from the map (by the iterator's <tt>remove</tt> operation).
  91.394 -         *
  91.395 -         * @param value new value to be stored in this entry
  91.396 -         * @return old value corresponding to the entry
  91.397 -         * @throws UnsupportedOperationException if the <tt>put</tt> operation
  91.398 -         *         is not supported by the backing map
  91.399 -         * @throws ClassCastException if the class of the specified value
  91.400 -         *         prevents it from being stored in the backing map
  91.401 -         * @throws NullPointerException if the backing map does not permit
  91.402 -         *         null values, and the specified value is null
  91.403 -         * @throws IllegalArgumentException if some property of this value
  91.404 -         *         prevents it from being stored in the backing map
  91.405 -         * @throws IllegalStateException implementations may, but are not
  91.406 -         *         required to, throw this exception if the entry has been
  91.407 -         *         removed from the backing map.
  91.408 -         */
  91.409 -        V setValue(V value);
  91.410 -
  91.411 -        /**
  91.412 -         * Compares the specified object with this entry for equality.
  91.413 -         * Returns <tt>true</tt> if the given object is also a map entry and
  91.414 -         * the two entries represent the same mapping.  More formally, two
  91.415 -         * entries <tt>e1</tt> and <tt>e2</tt> represent the same mapping
  91.416 -         * if<pre>
  91.417 -         *     (e1.getKey()==null ?
  91.418 -         *      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &amp;&amp;
  91.419 -         *     (e1.getValue()==null ?
  91.420 -         *      e2.getValue()==null : e1.getValue().equals(e2.getValue()))
  91.421 -         * </pre>
  91.422 -         * This ensures that the <tt>equals</tt> method works properly across
  91.423 -         * different implementations of the <tt>Map.Entry</tt> interface.
  91.424 -         *
  91.425 -         * @param o object to be compared for equality with this map entry
  91.426 -         * @return <tt>true</tt> if the specified object is equal to this map
  91.427 -         *         entry
  91.428 -         */
  91.429 -        boolean equals(Object o);
  91.430 -
  91.431 -        /**
  91.432 -         * Returns the hash code value for this map entry.  The hash code
  91.433 -         * of a map entry <tt>e</tt> is defined to be: <pre>
  91.434 -         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
  91.435 -         *     (e.getValue()==null ? 0 : e.getValue().hashCode())
  91.436 -         * </pre>
  91.437 -         * This ensures that <tt>e1.equals(e2)</tt> implies that
  91.438 -         * <tt>e1.hashCode()==e2.hashCode()</tt> for any two Entries
  91.439 -         * <tt>e1</tt> and <tt>e2</tt>, as required by the general
  91.440 -         * contract of <tt>Object.hashCode</tt>.
  91.441 -         *
  91.442 -         * @return the hash code value for this map entry
  91.443 -         * @see Object#hashCode()
  91.444 -         * @see Object#equals(Object)
  91.445 -         * @see #equals(Object)
  91.446 -         */
  91.447 -        int hashCode();
  91.448 -    }
  91.449 -
  91.450 -    // Comparison and hashing
  91.451 -
  91.452 -    /**
  91.453 -     * Compares the specified object with this map for equality.  Returns
  91.454 -     * <tt>true</tt> if the given object is also a map and the two maps
  91.455 -     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
  91.456 -     * <tt>m2</tt> represent the same mappings if
  91.457 -     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
  91.458 -     * <tt>equals</tt> method works properly across different implementations
  91.459 -     * of the <tt>Map</tt> interface.
  91.460 -     *
  91.461 -     * @param o object to be compared for equality with this map
  91.462 -     * @return <tt>true</tt> if the specified object is equal to this map
  91.463 -     */
  91.464 -    boolean equals(Object o);
  91.465 -
  91.466 -    /**
  91.467 -     * Returns the hash code value for this map.  The hash code of a map is
  91.468 -     * defined to be the sum of the hash codes of each entry in the map's
  91.469 -     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
  91.470 -     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
  91.471 -     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
  91.472 -     * {@link Object#hashCode}.
  91.473 -     *
  91.474 -     * @return the hash code value for this map
  91.475 -     * @see Map.Entry#hashCode()
  91.476 -     * @see Object#equals(Object)
  91.477 -     * @see #equals(Object)
  91.478 -     */
  91.479 -    int hashCode();
  91.480 -
  91.481 -}
    92.1 --- a/emul/compact/src/main/java/java/util/Objects.java	Mon Feb 25 19:00:08 2013 +0100
    92.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.3 @@ -1,229 +0,0 @@
    92.4 -/*
    92.5 - * Copyright (c) 2009, 2011, 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.util;
   92.30 -
   92.31 -/**
   92.32 - * This class consists of {@code static} utility methods for operating
   92.33 - * on objects.  These utilities include {@code null}-safe or {@code
   92.34 - * null}-tolerant methods for computing the hash code of an object,
   92.35 - * returning a string for an object, and comparing two objects.
   92.36 - *
   92.37 - * @since 1.7
   92.38 - */
   92.39 -public final class Objects {
   92.40 -    private Objects() {
   92.41 -        throw new AssertionError("No java.util.Objects instances for you!");
   92.42 -    }
   92.43 -
   92.44 -    /**
   92.45 -     * Returns {@code true} if the arguments are equal to each other
   92.46 -     * and {@code false} otherwise.
   92.47 -     * Consequently, if both arguments are {@code null}, {@code true}
   92.48 -     * is returned and if exactly one argument is {@code null}, {@code
   92.49 -     * false} is returned.  Otherwise, equality is determined by using
   92.50 -     * the {@link Object#equals equals} method of the first
   92.51 -     * argument.
   92.52 -     *
   92.53 -     * @param a an object
   92.54 -     * @param b an object to be compared with {@code a} for equality
   92.55 -     * @return {@code true} if the arguments are equal to each other
   92.56 -     * and {@code false} otherwise
   92.57 -     * @see Object#equals(Object)
   92.58 -     */
   92.59 -    public static boolean equals(Object a, Object b) {
   92.60 -        return (a == b) || (a != null && a.equals(b));
   92.61 -    }
   92.62 -
   92.63 -   /**
   92.64 -    * Returns {@code true} if the arguments are deeply equal to each other
   92.65 -    * and {@code false} otherwise.
   92.66 -    *
   92.67 -    * Two {@code null} values are deeply equal.  If both arguments are
   92.68 -    * arrays, the algorithm in {@link Arrays#deepEquals(Object[],
   92.69 -    * Object[]) Arrays.deepEquals} is used to determine equality.
   92.70 -    * Otherwise, equality is determined by using the {@link
   92.71 -    * Object#equals equals} method of the first argument.
   92.72 -    *
   92.73 -    * @param a an object
   92.74 -    * @param b an object to be compared with {@code a} for deep equality
   92.75 -    * @return {@code true} if the arguments are deeply equal to each other
   92.76 -    * and {@code false} otherwise
   92.77 -    * @see Arrays#deepEquals(Object[], Object[])
   92.78 -    * @see Objects#equals(Object, Object)
   92.79 -    */
   92.80 -    public static boolean deepEquals(Object a, Object b) {
   92.81 -        if (a == b)
   92.82 -            return true;
   92.83 -        else if (a == null || b == null)
   92.84 -            return false;
   92.85 -        else
   92.86 -            return Arrays.deepEquals0(a, b);
   92.87 -    }
   92.88 -
   92.89 -    /**
   92.90 -     * Returns the hash code of a non-{@code null} argument and 0 for
   92.91 -     * a {@code null} argument.
   92.92 -     *
   92.93 -     * @param o an object
   92.94 -     * @return the hash code of a non-{@code null} argument and 0 for
   92.95 -     * a {@code null} argument
   92.96 -     * @see Object#hashCode
   92.97 -     */
   92.98 -    public static int hashCode(Object o) {
   92.99 -        return o != null ? o.hashCode() : 0;
  92.100 -    }
  92.101 -
  92.102 -   /**
  92.103 -    * Generates a hash code for a sequence of input values. The hash
  92.104 -    * code is generated as if all the input values were placed into an
  92.105 -    * array, and that array were hashed by calling {@link
  92.106 -    * Arrays#hashCode(Object[])}.
  92.107 -    *
  92.108 -    * <p>This method is useful for implementing {@link
  92.109 -    * Object#hashCode()} on objects containing multiple fields. For
  92.110 -    * example, if an object that has three fields, {@code x}, {@code
  92.111 -    * y}, and {@code z}, one could write:
  92.112 -    *
  92.113 -    * <blockquote><pre>
  92.114 -    * &#064;Override public int hashCode() {
  92.115 -    *     return Objects.hash(x, y, z);
  92.116 -    * }
  92.117 -    * </pre></blockquote>
  92.118 -    *
  92.119 -    * <b>Warning: When a single object reference is supplied, the returned
  92.120 -    * value does not equal the hash code of that object reference.</b> This
  92.121 -    * value can be computed by calling {@link #hashCode(Object)}.
  92.122 -    *
  92.123 -    * @param values the values to be hashed
  92.124 -    * @return a hash value of the sequence of input values
  92.125 -    * @see Arrays#hashCode(Object[])
  92.126 -    * @see List#hashCode
  92.127 -    */
  92.128 -    public static int hash(Object... values) {
  92.129 -        return Arrays.hashCode(values);
  92.130 -    }
  92.131 -
  92.132 -    /**
  92.133 -     * Returns the result of calling {@code toString} for a non-{@code
  92.134 -     * null} argument and {@code "null"} for a {@code null} argument.
  92.135 -     *
  92.136 -     * @param o an object
  92.137 -     * @return the result of calling {@code toString} for a non-{@code
  92.138 -     * null} argument and {@code "null"} for a {@code null} argument
  92.139 -     * @see Object#toString
  92.140 -     * @see String#valueOf(Object)
  92.141 -     */
  92.142 -    public static String toString(Object o) {
  92.143 -        return String.valueOf(o);
  92.144 -    }
  92.145 -
  92.146 -    /**
  92.147 -     * Returns the result of calling {@code toString} on the first
  92.148 -     * argument if the first argument is not {@code null} and returns
  92.149 -     * the second argument otherwise.
  92.150 -     *
  92.151 -     * @param o an object
  92.152 -     * @param nullDefault string to return if the first argument is
  92.153 -     *        {@code null}
  92.154 -     * @return the result of calling {@code toString} on the first
  92.155 -     * argument if it is not {@code null} and the second argument
  92.156 -     * otherwise.
  92.157 -     * @see Objects#toString(Object)
  92.158 -     */
  92.159 -    public static String toString(Object o, String nullDefault) {
  92.160 -        return (o != null) ? o.toString() : nullDefault;
  92.161 -    }
  92.162 -
  92.163 -    /**
  92.164 -     * Returns 0 if the arguments are identical and {@code
  92.165 -     * c.compare(a, b)} otherwise.
  92.166 -     * Consequently, if both arguments are {@code null} 0
  92.167 -     * is returned.
  92.168 -     *
  92.169 -     * <p>Note that if one of the arguments is {@code null}, a {@code
  92.170 -     * NullPointerException} may or may not be thrown depending on
  92.171 -     * what ordering policy, if any, the {@link Comparator Comparator}
  92.172 -     * chooses to have for {@code null} values.
  92.173 -     *
  92.174 -     * @param <T> the type of the objects being compared
  92.175 -     * @param a an object
  92.176 -     * @param b an object to be compared with {@code a}
  92.177 -     * @param c the {@code Comparator} to compare the first two arguments
  92.178 -     * @return 0 if the arguments are identical and {@code
  92.179 -     * c.compare(a, b)} otherwise.
  92.180 -     * @see Comparable
  92.181 -     * @see Comparator
  92.182 -     */
  92.183 -    public static <T> int compare(T a, T b, Comparator<? super T> c) {
  92.184 -        return (a == b) ? 0 :  c.compare(a, b);
  92.185 -    }
  92.186 -
  92.187 -    /**
  92.188 -     * Checks that the specified object reference is not {@code null}. This
  92.189 -     * method is designed primarily for doing parameter validation in methods
  92.190 -     * and constructors, as demonstrated below:
  92.191 -     * <blockquote><pre>
  92.192 -     * public Foo(Bar bar) {
  92.193 -     *     this.bar = Objects.requireNonNull(bar);
  92.194 -     * }
  92.195 -     * </pre></blockquote>
  92.196 -     *
  92.197 -     * @param obj the object reference to check for nullity
  92.198 -     * @param <T> the type of the reference
  92.199 -     * @return {@code obj} if not {@code null}
  92.200 -     * @throws NullPointerException if {@code obj} is {@code null}
  92.201 -     */
  92.202 -    public static <T> T requireNonNull(T obj) {
  92.203 -        if (obj == null)
  92.204 -            throw new NullPointerException();
  92.205 -        return obj;
  92.206 -    }
  92.207 -
  92.208 -    /**
  92.209 -     * Checks that the specified object reference is not {@code null} and
  92.210 -     * throws a customized {@link NullPointerException} if it is. This method
  92.211 -     * is designed primarily for doing parameter validation in methods and
  92.212 -     * constructors with multiple parameters, as demonstrated below:
  92.213 -     * <blockquote><pre>
  92.214 -     * public Foo(Bar bar, Baz baz) {
  92.215 -     *     this.bar = Objects.requireNonNull(bar, "bar must not be null");
  92.216 -     *     this.baz = Objects.requireNonNull(baz, "baz must not be null");
  92.217 -     * }
  92.218 -     * </pre></blockquote>
  92.219 -     *
  92.220 -     * @param obj     the object reference to check for nullity
  92.221 -     * @param message detail message to be used in the event that a {@code
  92.222 -     *                NullPointerException} is thrown
  92.223 -     * @param <T> the type of the reference
  92.224 -     * @return {@code obj} if not {@code null}
  92.225 -     * @throws NullPointerException if {@code obj} is {@code null}
  92.226 -     */
  92.227 -    public static <T> T requireNonNull(T obj, String message) {
  92.228 -        if (obj == null)
  92.229 -            throw new NullPointerException(message);
  92.230 -        return obj;
  92.231 -    }
  92.232 -}
    93.1 --- a/emul/compact/src/main/java/java/util/PriorityQueue.java	Mon Feb 25 19:00:08 2013 +0100
    93.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.3 @@ -1,731 +0,0 @@
    93.4 -/*
    93.5 - * Copyright (c) 2003, 2010, 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.util;
   93.30 -
   93.31 -
   93.32 -/**
   93.33 - * An unbounded priority {@linkplain Queue queue} based on a priority heap.
   93.34 - * The elements of the priority queue are ordered according to their
   93.35 - * {@linkplain Comparable natural ordering}, or by a {@link Comparator}
   93.36 - * provided at queue construction time, depending on which constructor is
   93.37 - * used.  A priority queue does not permit {@code null} elements.
   93.38 - * A priority queue relying on natural ordering also does not permit
   93.39 - * insertion of non-comparable objects (doing so may result in
   93.40 - * {@code ClassCastException}).
   93.41 - *
   93.42 - * <p>The <em>head</em> of this queue is the <em>least</em> element
   93.43 - * with respect to the specified ordering.  If multiple elements are
   93.44 - * tied for least value, the head is one of those elements -- ties are
   93.45 - * broken arbitrarily.  The queue retrieval operations {@code poll},
   93.46 - * {@code remove}, {@code peek}, and {@code element} access the
   93.47 - * element at the head of the queue.
   93.48 - *
   93.49 - * <p>A priority queue is unbounded, but has an internal
   93.50 - * <i>capacity</i> governing the size of an array used to store the
   93.51 - * elements on the queue.  It is always at least as large as the queue
   93.52 - * size.  As elements are added to a priority queue, its capacity
   93.53 - * grows automatically.  The details of the growth policy are not
   93.54 - * specified.
   93.55 - *
   93.56 - * <p>This class and its iterator implement all of the
   93.57 - * <em>optional</em> methods of the {@link Collection} and {@link
   93.58 - * Iterator} interfaces.  The Iterator provided in method {@link
   93.59 - * #iterator()} is <em>not</em> guaranteed to traverse the elements of
   93.60 - * the priority queue in any particular order. If you need ordered
   93.61 - * traversal, consider using {@code Arrays.sort(pq.toArray())}.
   93.62 - *
   93.63 - * <p> <strong>Note that this implementation is not synchronized.</strong>
   93.64 - * Multiple threads should not access a {@code PriorityQueue}
   93.65 - * instance concurrently if any of the threads modifies the queue.
   93.66 - * Instead, use the thread-safe {@link
   93.67 - * java.util.concurrent.PriorityBlockingQueue} class.
   93.68 - *
   93.69 - * <p>Implementation note: this implementation provides
   93.70 - * O(log(n)) time for the enqueing and dequeing methods
   93.71 - * ({@code offer}, {@code poll}, {@code remove()} and {@code add});
   93.72 - * linear time for the {@code remove(Object)} and {@code contains(Object)}
   93.73 - * methods; and constant time for the retrieval methods
   93.74 - * ({@code peek}, {@code element}, and {@code size}).
   93.75 - *
   93.76 - * <p>This class is a member of the
   93.77 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   93.78 - * Java Collections Framework</a>.
   93.79 - *
   93.80 - * @since 1.5
   93.81 - * @author Josh Bloch, Doug Lea
   93.82 - * @param <E> the type of elements held in this collection
   93.83 - */
   93.84 -public class PriorityQueue<E> extends AbstractQueue<E>
   93.85 -    implements java.io.Serializable {
   93.86 -
   93.87 -    private static final long serialVersionUID = -7720805057305804111L;
   93.88 -
   93.89 -    private static final int DEFAULT_INITIAL_CAPACITY = 11;
   93.90 -
   93.91 -    /**
   93.92 -     * Priority queue represented as a balanced binary heap: the two
   93.93 -     * children of queue[n] are queue[2*n+1] and queue[2*(n+1)].  The
   93.94 -     * priority queue is ordered by comparator, or by the elements'
   93.95 -     * natural ordering, if comparator is null: For each node n in the
   93.96 -     * heap and each descendant d of n, n <= d.  The element with the
   93.97 -     * lowest value is in queue[0], assuming the queue is nonempty.
   93.98 -     */
   93.99 -    private transient Object[] queue;
  93.100 -
  93.101 -    /**
  93.102 -     * The number of elements in the priority queue.
  93.103 -     */
  93.104 -    private int size = 0;
  93.105 -
  93.106 -    /**
  93.107 -     * The comparator, or null if priority queue uses elements'
  93.108 -     * natural ordering.
  93.109 -     */
  93.110 -    private final Comparator<? super E> comparator;
  93.111 -
  93.112 -    /**
  93.113 -     * The number of times this priority queue has been
  93.114 -     * <i>structurally modified</i>.  See AbstractList for gory details.
  93.115 -     */
  93.116 -    private transient int modCount = 0;
  93.117 -
  93.118 -    /**
  93.119 -     * Creates a {@code PriorityQueue} with the default initial
  93.120 -     * capacity (11) that orders its elements according to their
  93.121 -     * {@linkplain Comparable natural ordering}.
  93.122 -     */
  93.123 -    public PriorityQueue() {
  93.124 -        this(DEFAULT_INITIAL_CAPACITY, null);
  93.125 -    }
  93.126 -
  93.127 -    /**
  93.128 -     * Creates a {@code PriorityQueue} with the specified initial
  93.129 -     * capacity that orders its elements according to their
  93.130 -     * {@linkplain Comparable natural ordering}.
  93.131 -     *
  93.132 -     * @param initialCapacity the initial capacity for this priority queue
  93.133 -     * @throws IllegalArgumentException if {@code initialCapacity} is less
  93.134 -     *         than 1
  93.135 -     */
  93.136 -    public PriorityQueue(int initialCapacity) {
  93.137 -        this(initialCapacity, null);
  93.138 -    }
  93.139 -
  93.140 -    /**
  93.141 -     * Creates a {@code PriorityQueue} with the specified initial capacity
  93.142 -     * that orders its elements according to the specified comparator.
  93.143 -     *
  93.144 -     * @param  initialCapacity the initial capacity for this priority queue
  93.145 -     * @param  comparator the comparator that will be used to order this
  93.146 -     *         priority queue.  If {@code null}, the {@linkplain Comparable
  93.147 -     *         natural ordering} of the elements will be used.
  93.148 -     * @throws IllegalArgumentException if {@code initialCapacity} is
  93.149 -     *         less than 1
  93.150 -     */
  93.151 -    public PriorityQueue(int initialCapacity,
  93.152 -                         Comparator<? super E> comparator) {
  93.153 -        // Note: This restriction of at least one is not actually needed,
  93.154 -        // but continues for 1.5 compatibility
  93.155 -        if (initialCapacity < 1)
  93.156 -            throw new IllegalArgumentException();
  93.157 -        this.queue = new Object[initialCapacity];
  93.158 -        this.comparator = comparator;
  93.159 -    }
  93.160 -
  93.161 -    /**
  93.162 -     * Creates a {@code PriorityQueue} containing the elements in the
  93.163 -     * specified collection.  If the specified collection is an instance of
  93.164 -     * a {@link SortedSet} or is another {@code PriorityQueue}, this
  93.165 -     * priority queue will be ordered according to the same ordering.
  93.166 -     * Otherwise, this priority queue will be ordered according to the
  93.167 -     * {@linkplain Comparable natural ordering} of its elements.
  93.168 -     *
  93.169 -     * @param  c the collection whose elements are to be placed
  93.170 -     *         into this priority queue
  93.171 -     * @throws ClassCastException if elements of the specified collection
  93.172 -     *         cannot be compared to one another according to the priority
  93.173 -     *         queue's ordering
  93.174 -     * @throws NullPointerException if the specified collection or any
  93.175 -     *         of its elements are null
  93.176 -     */
  93.177 -    @SuppressWarnings("unchecked")
  93.178 -    public PriorityQueue(Collection<? extends E> c) {
  93.179 -        if (c instanceof SortedSet<?>) {
  93.180 -            SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
  93.181 -            this.comparator = (Comparator<? super E>) ss.comparator();
  93.182 -            initElementsFromCollection(ss);
  93.183 -        }
  93.184 -        else if (c instanceof PriorityQueue<?>) {
  93.185 -            PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c;
  93.186 -            this.comparator = (Comparator<? super E>) pq.comparator();
  93.187 -            initFromPriorityQueue(pq);
  93.188 -        }
  93.189 -        else {
  93.190 -            this.comparator = null;
  93.191 -            initFromCollection(c);
  93.192 -        }
  93.193 -    }
  93.194 -
  93.195 -    /**
  93.196 -     * Creates a {@code PriorityQueue} containing the elements in the
  93.197 -     * specified priority queue.  This priority queue will be
  93.198 -     * ordered according to the same ordering as the given priority
  93.199 -     * queue.
  93.200 -     *
  93.201 -     * @param  c the priority queue whose elements are to be placed
  93.202 -     *         into this priority queue
  93.203 -     * @throws ClassCastException if elements of {@code c} cannot be
  93.204 -     *         compared to one another according to {@code c}'s
  93.205 -     *         ordering
  93.206 -     * @throws NullPointerException if the specified priority queue or any
  93.207 -     *         of its elements are null
  93.208 -     */
  93.209 -    @SuppressWarnings("unchecked")
  93.210 -    public PriorityQueue(PriorityQueue<? extends E> c) {
  93.211 -        this.comparator = (Comparator<? super E>) c.comparator();
  93.212 -        initFromPriorityQueue(c);
  93.213 -    }
  93.214 -
  93.215 -    /**
  93.216 -     * Creates a {@code PriorityQueue} containing the elements in the
  93.217 -     * specified sorted set.   This priority queue will be ordered
  93.218 -     * according to the same ordering as the given sorted set.
  93.219 -     *
  93.220 -     * @param  c the sorted set whose elements are to be placed
  93.221 -     *         into this priority queue
  93.222 -     * @throws ClassCastException if elements of the specified sorted
  93.223 -     *         set cannot be compared to one another according to the
  93.224 -     *         sorted set's ordering
  93.225 -     * @throws NullPointerException if the specified sorted set or any
  93.226 -     *         of its elements are null
  93.227 -     */
  93.228 -    @SuppressWarnings("unchecked")
  93.229 -    public PriorityQueue(SortedSet<? extends E> c) {
  93.230 -        this.comparator = (Comparator<? super E>) c.comparator();
  93.231 -        initElementsFromCollection(c);
  93.232 -    }
  93.233 -
  93.234 -    private void initFromPriorityQueue(PriorityQueue<? extends E> c) {
  93.235 -        if (c.getClass() == PriorityQueue.class) {
  93.236 -            this.queue = c.toArray();
  93.237 -            this.size = c.size();
  93.238 -        } else {
  93.239 -            initFromCollection(c);
  93.240 -        }
  93.241 -    }
  93.242 -
  93.243 -    private void initElementsFromCollection(Collection<? extends E> c) {
  93.244 -        Object[] a = c.toArray();
  93.245 -        // If c.toArray incorrectly doesn't return Object[], copy it.
  93.246 -        if (a.getClass() != Object[].class)
  93.247 -            a = Arrays.copyOf(a, a.length, Object[].class);
  93.248 -        int len = a.length;
  93.249 -        if (len == 1 || this.comparator != null)
  93.250 -            for (int i = 0; i < len; i++)
  93.251 -                if (a[i] == null)
  93.252 -                    throw new NullPointerException();
  93.253 -        this.queue = a;
  93.254 -        this.size = a.length;
  93.255 -    }
  93.256 -
  93.257 -    /**
  93.258 -     * Initializes queue array with elements from the given Collection.
  93.259 -     *
  93.260 -     * @param c the collection
  93.261 -     */
  93.262 -    private void initFromCollection(Collection<? extends E> c) {
  93.263 -        initElementsFromCollection(c);
  93.264 -        heapify();
  93.265 -    }
  93.266 -
  93.267 -    /**
  93.268 -     * The maximum size of array to allocate.
  93.269 -     * Some VMs reserve some header words in an array.
  93.270 -     * Attempts to allocate larger arrays may result in
  93.271 -     * OutOfMemoryError: Requested array size exceeds VM limit
  93.272 -     */
  93.273 -    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
  93.274 -
  93.275 -    /**
  93.276 -     * Increases the capacity of the array.
  93.277 -     *
  93.278 -     * @param minCapacity the desired minimum capacity
  93.279 -     */
  93.280 -    private void grow(int minCapacity) {
  93.281 -        int oldCapacity = queue.length;
  93.282 -        // Double size if small; else grow by 50%
  93.283 -        int newCapacity = oldCapacity + ((oldCapacity < 64) ?
  93.284 -                                         (oldCapacity + 2) :
  93.285 -                                         (oldCapacity >> 1));
  93.286 -        // overflow-conscious code
  93.287 -        if (newCapacity - MAX_ARRAY_SIZE > 0)
  93.288 -            newCapacity = hugeCapacity(minCapacity);
  93.289 -        queue = Arrays.copyOf(queue, newCapacity);
  93.290 -    }
  93.291 -
  93.292 -    private static int hugeCapacity(int minCapacity) {
  93.293 -        if (minCapacity < 0) // overflow
  93.294 -            throw new OutOfMemoryError();
  93.295 -        return (minCapacity > MAX_ARRAY_SIZE) ?
  93.296 -            Integer.MAX_VALUE :
  93.297 -            MAX_ARRAY_SIZE;
  93.298 -    }
  93.299 -
  93.300 -    /**
  93.301 -     * Inserts the specified element into this priority queue.
  93.302 -     *
  93.303 -     * @return {@code true} (as specified by {@link Collection#add})
  93.304 -     * @throws ClassCastException if the specified element cannot be
  93.305 -     *         compared with elements currently in this priority queue
  93.306 -     *         according to the priority queue's ordering
  93.307 -     * @throws NullPointerException if the specified element is null
  93.308 -     */
  93.309 -    public boolean add(E e) {
  93.310 -        return offer(e);
  93.311 -    }
  93.312 -
  93.313 -    /**
  93.314 -     * Inserts the specified element into this priority queue.
  93.315 -     *
  93.316 -     * @return {@code true} (as specified by {@link Queue#offer})
  93.317 -     * @throws ClassCastException if the specified element cannot be
  93.318 -     *         compared with elements currently in this priority queue
  93.319 -     *         according to the priority queue's ordering
  93.320 -     * @throws NullPointerException if the specified element is null
  93.321 -     */
  93.322 -    public boolean offer(E e) {
  93.323 -        if (e == null)
  93.324 -            throw new NullPointerException();
  93.325 -        modCount++;
  93.326 -        int i = size;
  93.327 -        if (i >= queue.length)
  93.328 -            grow(i + 1);
  93.329 -        size = i + 1;
  93.330 -        if (i == 0)
  93.331 -            queue[0] = e;
  93.332 -        else
  93.333 -            siftUp(i, e);
  93.334 -        return true;
  93.335 -    }
  93.336 -
  93.337 -    public E peek() {
  93.338 -        if (size == 0)
  93.339 -            return null;
  93.340 -        return (E) queue[0];
  93.341 -    }
  93.342 -
  93.343 -    private int indexOf(Object o) {
  93.344 -        if (o != null) {
  93.345 -            for (int i = 0; i < size; i++)
  93.346 -                if (o.equals(queue[i]))
  93.347 -                    return i;
  93.348 -        }
  93.349 -        return -1;
  93.350 -    }
  93.351 -
  93.352 -    /**
  93.353 -     * Removes a single instance of the specified element from this queue,
  93.354 -     * if it is present.  More formally, removes an element {@code e} such
  93.355 -     * that {@code o.equals(e)}, if this queue contains one or more such
  93.356 -     * elements.  Returns {@code true} if and only if this queue contained
  93.357 -     * the specified element (or equivalently, if this queue changed as a
  93.358 -     * result of the call).
  93.359 -     *
  93.360 -     * @param o element to be removed from this queue, if present
  93.361 -     * @return {@code true} if this queue changed as a result of the call
  93.362 -     */
  93.363 -    public boolean remove(Object o) {
  93.364 -        int i = indexOf(o);
  93.365 -        if (i == -1)
  93.366 -            return false;
  93.367 -        else {
  93.368 -            removeAt(i);
  93.369 -            return true;
  93.370 -        }
  93.371 -    }
  93.372 -
  93.373 -    /**
  93.374 -     * Version of remove using reference equality, not equals.
  93.375 -     * Needed by iterator.remove.
  93.376 -     *
  93.377 -     * @param o element to be removed from this queue, if present
  93.378 -     * @return {@code true} if removed
  93.379 -     */
  93.380 -    boolean removeEq(Object o) {
  93.381 -        for (int i = 0; i < size; i++) {
  93.382 -            if (o == queue[i]) {
  93.383 -                removeAt(i);
  93.384 -                return true;
  93.385 -            }
  93.386 -        }
  93.387 -        return false;
  93.388 -    }
  93.389 -
  93.390 -    /**
  93.391 -     * Returns {@code true} if this queue contains the specified element.
  93.392 -     * More formally, returns {@code true} if and only if this queue contains
  93.393 -     * at least one element {@code e} such that {@code o.equals(e)}.
  93.394 -     *
  93.395 -     * @param o object to be checked for containment in this queue
  93.396 -     * @return {@code true} if this queue contains the specified element
  93.397 -     */
  93.398 -    public boolean contains(Object o) {
  93.399 -        return indexOf(o) != -1;
  93.400 -    }
  93.401 -
  93.402 -    /**
  93.403 -     * Returns an array containing all of the elements in this queue.
  93.404 -     * The elements are in no particular order.
  93.405 -     *
  93.406 -     * <p>The returned array will be "safe" in that no references to it are
  93.407 -     * maintained by this queue.  (In other words, this method must allocate
  93.408 -     * a new array).  The caller is thus free to modify the returned array.
  93.409 -     *
  93.410 -     * <p>This method acts as bridge between array-based and collection-based
  93.411 -     * APIs.
  93.412 -     *
  93.413 -     * @return an array containing all of the elements in this queue
  93.414 -     */
  93.415 -    public Object[] toArray() {
  93.416 -        return Arrays.copyOf(queue, size);
  93.417 -    }
  93.418 -
  93.419 -    /**
  93.420 -     * Returns an array containing all of the elements in this queue; the
  93.421 -     * runtime type of the returned array is that of the specified array.
  93.422 -     * The returned array elements are in no particular order.
  93.423 -     * If the queue fits in the specified array, it is returned therein.
  93.424 -     * Otherwise, a new array is allocated with the runtime type of the
  93.425 -     * specified array and the size of this queue.
  93.426 -     *
  93.427 -     * <p>If the queue fits in the specified array with room to spare
  93.428 -     * (i.e., the array has more elements than the queue), the element in
  93.429 -     * the array immediately following the end of the collection is set to
  93.430 -     * {@code null}.
  93.431 -     *
  93.432 -     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  93.433 -     * array-based and collection-based APIs.  Further, this method allows
  93.434 -     * precise control over the runtime type of the output array, and may,
  93.435 -     * under certain circumstances, be used to save allocation costs.
  93.436 -     *
  93.437 -     * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
  93.438 -     * The following code can be used to dump the queue into a newly
  93.439 -     * allocated array of <tt>String</tt>:
  93.440 -     *
  93.441 -     * <pre>
  93.442 -     *     String[] y = x.toArray(new String[0]);</pre>
  93.443 -     *
  93.444 -     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  93.445 -     * <tt>toArray()</tt>.
  93.446 -     *
  93.447 -     * @param a the array into which the elements of the queue are to
  93.448 -     *          be stored, if it is big enough; otherwise, a new array of the
  93.449 -     *          same runtime type is allocated for this purpose.
  93.450 -     * @return an array containing all of the elements in this queue
  93.451 -     * @throws ArrayStoreException if the runtime type of the specified array
  93.452 -     *         is not a supertype of the runtime type of every element in
  93.453 -     *         this queue
  93.454 -     * @throws NullPointerException if the specified array is null
  93.455 -     */
  93.456 -    public <T> T[] toArray(T[] a) {
  93.457 -        if (a.length < size)
  93.458 -            // Make a new array of a's runtime type, but my contents:
  93.459 -            return (T[]) Arrays.copyOf(queue, size, a.getClass());
  93.460 -        System.arraycopy(queue, 0, a, 0, size);
  93.461 -        if (a.length > size)
  93.462 -            a[size] = null;
  93.463 -        return a;
  93.464 -    }
  93.465 -
  93.466 -    /**
  93.467 -     * Returns an iterator over the elements in this queue. The iterator
  93.468 -     * does not return the elements in any particular order.
  93.469 -     *
  93.470 -     * @return an iterator over the elements in this queue
  93.471 -     */
  93.472 -    public Iterator<E> iterator() {
  93.473 -        return new Itr();
  93.474 -    }
  93.475 -
  93.476 -    private final class Itr implements Iterator<E> {
  93.477 -        /**
  93.478 -         * Index (into queue array) of element to be returned by
  93.479 -         * subsequent call to next.
  93.480 -         */
  93.481 -        private int cursor = 0;
  93.482 -
  93.483 -        /**
  93.484 -         * Index of element returned by most recent call to next,
  93.485 -         * unless that element came from the forgetMeNot list.
  93.486 -         * Set to -1 if element is deleted by a call to remove.
  93.487 -         */
  93.488 -        private int lastRet = -1;
  93.489 -
  93.490 -        /**
  93.491 -         * A queue of elements that were moved from the unvisited portion of
  93.492 -         * the heap into the visited portion as a result of "unlucky" element
  93.493 -         * removals during the iteration.  (Unlucky element removals are those
  93.494 -         * that require a siftup instead of a siftdown.)  We must visit all of
  93.495 -         * the elements in this list to complete the iteration.  We do this
  93.496 -         * after we've completed the "normal" iteration.
  93.497 -         *
  93.498 -         * We expect that most iterations, even those involving removals,
  93.499 -         * will not need to store elements in this field.
  93.500 -         */
  93.501 -        private ArrayDeque<E> forgetMeNot = null;
  93.502 -
  93.503 -        /**
  93.504 -         * Element returned by the most recent call to next iff that
  93.505 -         * element was drawn from the forgetMeNot list.
  93.506 -         */
  93.507 -        private E lastRetElt = null;
  93.508 -
  93.509 -        /**
  93.510 -         * The modCount value that the iterator believes that the backing
  93.511 -         * Queue should have.  If this expectation is violated, the iterator
  93.512 -         * has detected concurrent modification.
  93.513 -         */
  93.514 -        private int expectedModCount = modCount;
  93.515 -
  93.516 -        public boolean hasNext() {
  93.517 -            return cursor < size ||
  93.518 -                (forgetMeNot != null && !forgetMeNot.isEmpty());
  93.519 -        }
  93.520 -
  93.521 -        public E next() {
  93.522 -            if (expectedModCount != modCount)
  93.523 -                throw new ConcurrentModificationException();
  93.524 -            if (cursor < size)
  93.525 -                return (E) queue[lastRet = cursor++];
  93.526 -            if (forgetMeNot != null) {
  93.527 -                lastRet = -1;
  93.528 -                lastRetElt = forgetMeNot.poll();
  93.529 -                if (lastRetElt != null)
  93.530 -                    return lastRetElt;
  93.531 -            }
  93.532 -            throw new NoSuchElementException();
  93.533 -        }
  93.534 -
  93.535 -        public void remove() {
  93.536 -            if (expectedModCount != modCount)
  93.537 -                throw new ConcurrentModificationException();
  93.538 -            if (lastRet != -1) {
  93.539 -                E moved = PriorityQueue.this.removeAt(lastRet);
  93.540 -                lastRet = -1;
  93.541 -                if (moved == null)
  93.542 -                    cursor--;
  93.543 -                else {
  93.544 -                    if (forgetMeNot == null)
  93.545 -                        forgetMeNot = new ArrayDeque<>();
  93.546 -                    forgetMeNot.add(moved);
  93.547 -                }
  93.548 -            } else if (lastRetElt != null) {
  93.549 -                PriorityQueue.this.removeEq(lastRetElt);
  93.550 -                lastRetElt = null;
  93.551 -            } else {
  93.552 -                throw new IllegalStateException();
  93.553 -            }
  93.554 -            expectedModCount = modCount;
  93.555 -        }
  93.556 -    }
  93.557 -
  93.558 -    public int size() {
  93.559 -        return size;
  93.560 -    }
  93.561 -
  93.562 -    /**
  93.563 -     * Removes all of the elements from this priority queue.
  93.564 -     * The queue will be empty after this call returns.
  93.565 -     */
  93.566 -    public void clear() {
  93.567 -        modCount++;
  93.568 -        for (int i = 0; i < size; i++)
  93.569 -            queue[i] = null;
  93.570 -        size = 0;
  93.571 -    }
  93.572 -
  93.573 -    public E poll() {
  93.574 -        if (size == 0)
  93.575 -            return null;
  93.576 -        int s = --size;
  93.577 -        modCount++;
  93.578 -        E result = (E) queue[0];
  93.579 -        E x = (E) queue[s];
  93.580 -        queue[s] = null;
  93.581 -        if (s != 0)
  93.582 -            siftDown(0, x);
  93.583 -        return result;
  93.584 -    }
  93.585 -
  93.586 -    /**
  93.587 -     * Removes the ith element from queue.
  93.588 -     *
  93.589 -     * Normally this method leaves the elements at up to i-1,
  93.590 -     * inclusive, untouched.  Under these circumstances, it returns
  93.591 -     * null.  Occasionally, in order to maintain the heap invariant,
  93.592 -     * it must swap a later element of the list with one earlier than
  93.593 -     * i.  Under these circumstances, this method returns the element
  93.594 -     * that was previously at the end of the list and is now at some
  93.595 -     * position before i. This fact is used by iterator.remove so as to
  93.596 -     * avoid missing traversing elements.
  93.597 -     */
  93.598 -    private E removeAt(int i) {
  93.599 -        assert i >= 0 && i < size;
  93.600 -        modCount++;
  93.601 -        int s = --size;
  93.602 -        if (s == i) // removed last element
  93.603 -            queue[i] = null;
  93.604 -        else {
  93.605 -            E moved = (E) queue[s];
  93.606 -            queue[s] = null;
  93.607 -            siftDown(i, moved);
  93.608 -            if (queue[i] == moved) {
  93.609 -                siftUp(i, moved);
  93.610 -                if (queue[i] != moved)
  93.611 -                    return moved;
  93.612 -            }
  93.613 -        }
  93.614 -        return null;
  93.615 -    }
  93.616 -
  93.617 -    /**
  93.618 -     * Inserts item x at position k, maintaining heap invariant by
  93.619 -     * promoting x up the tree until it is greater than or equal to
  93.620 -     * its parent, or is the root.
  93.621 -     *
  93.622 -     * To simplify and speed up coercions and comparisons. the
  93.623 -     * Comparable and Comparator versions are separated into different
  93.624 -     * methods that are otherwise identical. (Similarly for siftDown.)
  93.625 -     *
  93.626 -     * @param k the position to fill
  93.627 -     * @param x the item to insert
  93.628 -     */
  93.629 -    private void siftUp(int k, E x) {
  93.630 -        if (comparator != null)
  93.631 -            siftUpUsingComparator(k, x);
  93.632 -        else
  93.633 -            siftUpComparable(k, x);
  93.634 -    }
  93.635 -
  93.636 -    private void siftUpComparable(int k, E x) {
  93.637 -        Comparable<? super E> key = (Comparable<? super E>) x;
  93.638 -        while (k > 0) {
  93.639 -            int parent = (k - 1) >>> 1;
  93.640 -            Object e = queue[parent];
  93.641 -            if (key.compareTo((E) e) >= 0)
  93.642 -                break;
  93.643 -            queue[k] = e;
  93.644 -            k = parent;
  93.645 -        }
  93.646 -        queue[k] = key;
  93.647 -    }
  93.648 -
  93.649 -    private void siftUpUsingComparator(int k, E x) {
  93.650 -        while (k > 0) {
  93.651 -            int parent = (k - 1) >>> 1;
  93.652 -            Object e = queue[parent];
  93.653 -            if (comparator.compare(x, (E) e) >= 0)
  93.654 -                break;
  93.655 -            queue[k] = e;
  93.656 -            k = parent;
  93.657 -        }
  93.658 -        queue[k] = x;
  93.659 -    }
  93.660 -
  93.661 -    /**
  93.662 -     * Inserts item x at position k, maintaining heap invariant by
  93.663 -     * demoting x down the tree repeatedly until it is less than or
  93.664 -     * equal to its children or is a leaf.
  93.665 -     *
  93.666 -     * @param k the position to fill
  93.667 -     * @param x the item to insert
  93.668 -     */
  93.669 -    private void siftDown(int k, E x) {
  93.670 -        if (comparator != null)
  93.671 -            siftDownUsingComparator(k, x);
  93.672 -        else
  93.673 -            siftDownComparable(k, x);
  93.674 -    }
  93.675 -
  93.676 -    private void siftDownComparable(int k, E x) {
  93.677 -        Comparable<? super E> key = (Comparable<? super E>)x;
  93.678 -        int half = size >>> 1;        // loop while a non-leaf
  93.679 -        while (k < half) {
  93.680 -            int child = (k << 1) + 1; // assume left child is least
  93.681 -            Object c = queue[child];
  93.682 -            int right = child + 1;
  93.683 -            if (right < size &&
  93.684 -                ((Comparable<? super E>) c).compareTo((E) queue[right]) > 0)
  93.685 -                c = queue[child = right];
  93.686 -            if (key.compareTo((E) c) <= 0)
  93.687 -                break;
  93.688 -            queue[k] = c;
  93.689 -            k = child;
  93.690 -        }
  93.691 -        queue[k] = key;
  93.692 -    }
  93.693 -
  93.694 -    private void siftDownUsingComparator(int k, E x) {
  93.695 -        int half = size >>> 1;
  93.696 -        while (k < half) {
  93.697 -            int child = (k << 1) + 1;
  93.698 -            Object c = queue[child];
  93.699 -            int right = child + 1;
  93.700 -            if (right < size &&
  93.701 -                comparator.compare((E) c, (E) queue[right]) > 0)
  93.702 -                c = queue[child = right];
  93.703 -            if (comparator.compare(x, (E) c) <= 0)
  93.704 -                break;
  93.705 -            queue[k] = c;
  93.706 -            k = child;
  93.707 -        }
  93.708 -        queue[k] = x;
  93.709 -    }
  93.710 -
  93.711 -    /**
  93.712 -     * Establishes the heap invariant (described above) in the entire tree,
  93.713 -     * assuming nothing about the order of the elements prior to the call.
  93.714 -     */
  93.715 -    private void heapify() {
  93.716 -        for (int i = (size >>> 1) - 1; i >= 0; i--)
  93.717 -            siftDown(i, (E) queue[i]);
  93.718 -    }
  93.719 -
  93.720 -    /**
  93.721 -     * Returns the comparator used to order the elements in this
  93.722 -     * queue, or {@code null} if this queue is sorted according to
  93.723 -     * the {@linkplain Comparable natural ordering} of its elements.
  93.724 -     *
  93.725 -     * @return the comparator used to order this queue, or
  93.726 -     *         {@code null} if this queue is sorted according to the
  93.727 -     *         natural ordering of its elements
  93.728 -     */
  93.729 -    public Comparator<? super E> comparator() {
  93.730 -        return comparator;
  93.731 -    }
  93.732 -
  93.733 -
  93.734 -}
    94.1 --- a/emul/compact/src/main/java/java/util/Queue.java	Mon Feb 25 19:00:08 2013 +0100
    94.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.3 @@ -1,218 +0,0 @@
    94.4 -/*
    94.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    94.6 - *
    94.7 - * This code is free software; you can redistribute it and/or modify it
    94.8 - * under the terms of the GNU General Public License version 2 only, as
    94.9 - * published by the Free Software Foundation.  Oracle designates this
   94.10 - * particular file as subject to the "Classpath" exception as provided
   94.11 - * by Oracle in the LICENSE file that accompanied this code.
   94.12 - *
   94.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
   94.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   94.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   94.16 - * version 2 for more details (a copy is included in the LICENSE file that
   94.17 - * accompanied this code).
   94.18 - *
   94.19 - * You should have received a copy of the GNU General Public License version
   94.20 - * 2 along with this work; if not, write to the Free Software Foundation,
   94.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   94.22 - *
   94.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   94.24 - * or visit www.oracle.com if you need additional information or have any
   94.25 - * questions.
   94.26 - */
   94.27 -
   94.28 -/*
   94.29 - * This file is available under and governed by the GNU General Public
   94.30 - * License version 2 only, as published by the Free Software Foundation.
   94.31 - * However, the following notice accompanied the original version of this
   94.32 - * file:
   94.33 - *
   94.34 - * Written by Doug Lea with assistance from members of JCP JSR-166
   94.35 - * Expert Group and released to the public domain, as explained at
   94.36 - * http://creativecommons.org/publicdomain/zero/1.0/
   94.37 - */
   94.38 -
   94.39 -package java.util;
   94.40 -
   94.41 -/**
   94.42 - * A collection designed for holding elements prior to processing.
   94.43 - * Besides basic {@link java.util.Collection Collection} operations,
   94.44 - * queues provide additional insertion, extraction, and inspection
   94.45 - * operations.  Each of these methods exists in two forms: one throws
   94.46 - * an exception if the operation fails, the other returns a special
   94.47 - * value (either <tt>null</tt> or <tt>false</tt>, depending on the
   94.48 - * operation).  The latter form of the insert operation is designed
   94.49 - * specifically for use with capacity-restricted <tt>Queue</tt>
   94.50 - * implementations; in most implementations, insert operations cannot
   94.51 - * fail.
   94.52 - *
   94.53 - * <p>
   94.54 - * <table BORDER CELLPADDING=3 CELLSPACING=1>
   94.55 - *  <tr>
   94.56 - *    <td></td>
   94.57 - *    <td ALIGN=CENTER><em>Throws exception</em></td>
   94.58 - *    <td ALIGN=CENTER><em>Returns special value</em></td>
   94.59 - *  </tr>
   94.60 - *  <tr>
   94.61 - *    <td><b>Insert</b></td>
   94.62 - *    <td>{@link #add add(e)}</td>
   94.63 - *    <td>{@link #offer offer(e)}</td>
   94.64 - *  </tr>
   94.65 - *  <tr>
   94.66 - *    <td><b>Remove</b></td>
   94.67 - *    <td>{@link #remove remove()}</td>
   94.68 - *    <td>{@link #poll poll()}</td>
   94.69 - *  </tr>
   94.70 - *  <tr>
   94.71 - *    <td><b>Examine</b></td>
   94.72 - *    <td>{@link #element element()}</td>
   94.73 - *    <td>{@link #peek peek()}</td>
   94.74 - *  </tr>
   94.75 - * </table>
   94.76 - *
   94.77 - * <p>Queues typically, but do not necessarily, order elements in a
   94.78 - * FIFO (first-in-first-out) manner.  Among the exceptions are
   94.79 - * priority queues, which order elements according to a supplied
   94.80 - * comparator, or the elements' natural ordering, and LIFO queues (or
   94.81 - * stacks) which order the elements LIFO (last-in-first-out).
   94.82 - * Whatever the ordering used, the <em>head</em> of the queue is that
   94.83 - * element which would be removed by a call to {@link #remove() } or
   94.84 - * {@link #poll()}.  In a FIFO queue, all new elements are inserted at
   94.85 - * the <em> tail</em> of the queue. Other kinds of queues may use
   94.86 - * different placement rules.  Every <tt>Queue</tt> implementation
   94.87 - * must specify its ordering properties.
   94.88 - *
   94.89 - * <p>The {@link #offer offer} method inserts an element if possible,
   94.90 - * otherwise returning <tt>false</tt>.  This differs from the {@link
   94.91 - * java.util.Collection#add Collection.add} method, which can fail to
   94.92 - * add an element only by throwing an unchecked exception.  The
   94.93 - * <tt>offer</tt> method is designed for use when failure is a normal,
   94.94 - * rather than exceptional occurrence, for example, in fixed-capacity
   94.95 - * (or &quot;bounded&quot;) queues.
   94.96 - *
   94.97 - * <p>The {@link #remove()} and {@link #poll()} methods remove and
   94.98 - * return the head of the queue.
   94.99 - * Exactly which element is removed from the queue is a
  94.100 - * function of the queue's ordering policy, which differs from
  94.101 - * implementation to implementation. The <tt>remove()</tt> and
  94.102 - * <tt>poll()</tt> methods differ only in their behavior when the
  94.103 - * queue is empty: the <tt>remove()</tt> method throws an exception,
  94.104 - * while the <tt>poll()</tt> method returns <tt>null</tt>.
  94.105 - *
  94.106 - * <p>The {@link #element()} and {@link #peek()} methods return, but do
  94.107 - * not remove, the head of the queue.
  94.108 - *
  94.109 - * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
  94.110 - * methods</i>, which are common in concurrent programming.  These methods,
  94.111 - * which wait for elements to appear or for space to become available, are
  94.112 - * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
  94.113 - * extends this interface.
  94.114 - *
  94.115 - * <p><tt>Queue</tt> implementations generally do not allow insertion
  94.116 - * of <tt>null</tt> elements, although some implementations, such as
  94.117 - * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
  94.118 - * Even in the implementations that permit it, <tt>null</tt> should
  94.119 - * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also
  94.120 - * used as a special return value by the <tt>poll</tt> method to
  94.121 - * indicate that the queue contains no elements.
  94.122 - *
  94.123 - * <p><tt>Queue</tt> implementations generally do not define
  94.124 - * element-based versions of methods <tt>equals</tt> and
  94.125 - * <tt>hashCode</tt> but instead inherit the identity based versions
  94.126 - * from class <tt>Object</tt>, because element-based equality is not
  94.127 - * always well-defined for queues with the same elements but different
  94.128 - * ordering properties.
  94.129 - *
  94.130 - *
  94.131 - * <p>This interface is a member of the
  94.132 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  94.133 - * Java Collections Framework</a>.
  94.134 - *
  94.135 - * @see java.util.Collection
  94.136 - * @see LinkedList
  94.137 - * @see PriorityQueue
  94.138 - * @see java.util.concurrent.LinkedBlockingQueue
  94.139 - * @see java.util.concurrent.BlockingQueue
  94.140 - * @see java.util.concurrent.ArrayBlockingQueue
  94.141 - * @see java.util.concurrent.LinkedBlockingQueue
  94.142 - * @see java.util.concurrent.PriorityBlockingQueue
  94.143 - * @since 1.5
  94.144 - * @author Doug Lea
  94.145 - * @param <E> the type of elements held in this collection
  94.146 - */
  94.147 -public interface Queue<E> extends Collection<E> {
  94.148 -    /**
  94.149 -     * Inserts the specified element into this queue if it is possible to do so
  94.150 -     * immediately without violating capacity restrictions, returning
  94.151 -     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
  94.152 -     * if no space is currently available.
  94.153 -     *
  94.154 -     * @param e the element to add
  94.155 -     * @return <tt>true</tt> (as specified by {@link Collection#add})
  94.156 -     * @throws IllegalStateException if the element cannot be added at this
  94.157 -     *         time due to capacity restrictions
  94.158 -     * @throws ClassCastException if the class of the specified element
  94.159 -     *         prevents it from being added to this queue
  94.160 -     * @throws NullPointerException if the specified element is null and
  94.161 -     *         this queue does not permit null elements
  94.162 -     * @throws IllegalArgumentException if some property of this element
  94.163 -     *         prevents it from being added to this queue
  94.164 -     */
  94.165 -    boolean add(E e);
  94.166 -
  94.167 -    /**
  94.168 -     * Inserts the specified element into this queue if it is possible to do
  94.169 -     * so immediately without violating capacity restrictions.
  94.170 -     * When using a capacity-restricted queue, this method is generally
  94.171 -     * preferable to {@link #add}, which can fail to insert an element only
  94.172 -     * by throwing an exception.
  94.173 -     *
  94.174 -     * @param e the element to add
  94.175 -     * @return <tt>true</tt> if the element was added to this queue, else
  94.176 -     *         <tt>false</tt>
  94.177 -     * @throws ClassCastException if the class of the specified element
  94.178 -     *         prevents it from being added to this queue
  94.179 -     * @throws NullPointerException if the specified element is null and
  94.180 -     *         this queue does not permit null elements
  94.181 -     * @throws IllegalArgumentException if some property of this element
  94.182 -     *         prevents it from being added to this queue
  94.183 -     */
  94.184 -    boolean offer(E e);
  94.185 -
  94.186 -    /**
  94.187 -     * Retrieves and removes the head of this queue.  This method differs
  94.188 -     * from {@link #poll poll} only in that it throws an exception if this
  94.189 -     * queue is empty.
  94.190 -     *
  94.191 -     * @return the head of this queue
  94.192 -     * @throws NoSuchElementException if this queue is empty
  94.193 -     */
  94.194 -    E remove();
  94.195 -
  94.196 -    /**
  94.197 -     * Retrieves and removes the head of this queue,
  94.198 -     * or returns <tt>null</tt> if this queue is empty.
  94.199 -     *
  94.200 -     * @return the head of this queue, or <tt>null</tt> if this queue is empty
  94.201 -     */
  94.202 -    E poll();
  94.203 -
  94.204 -    /**
  94.205 -     * Retrieves, but does not remove, the head of this queue.  This method
  94.206 -     * differs from {@link #peek peek} only in that it throws an exception
  94.207 -     * if this queue is empty.
  94.208 -     *
  94.209 -     * @return the head of this queue
  94.210 -     * @throws NoSuchElementException if this queue is empty
  94.211 -     */
  94.212 -    E element();
  94.213 -
  94.214 -    /**
  94.215 -     * Retrieves, but does not remove, the head of this queue,
  94.216 -     * or returns <tt>null</tt> if this queue is empty.
  94.217 -     *
  94.218 -     * @return the head of this queue, or <tt>null</tt> if this queue is empty
  94.219 -     */
  94.220 -    E peek();
  94.221 -}
    95.1 --- a/emul/compact/src/main/java/java/util/Random.java	Mon Feb 25 19:00:08 2013 +0100
    95.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.3 @@ -1,503 +0,0 @@
    95.4 -/*
    95.5 - * Copyright (c) 1995, 2010, 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.util;
   95.30 -
   95.31 -import org.apidesign.bck2brwsr.emul.lang.System;
   95.32 -
   95.33 -/**
   95.34 - * An instance of this class is used to generate a stream of
   95.35 - * pseudorandom numbers. The class uses a 48-bit seed, which is
   95.36 - * modified using a linear congruential formula. (See Donald Knuth,
   95.37 - * <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
   95.38 - * <p>
   95.39 - * If two instances of {@code Random} are created with the same
   95.40 - * seed, and the same sequence of method calls is made for each, they
   95.41 - * will generate and return identical sequences of numbers. In order to
   95.42 - * guarantee this property, particular algorithms are specified for the
   95.43 - * class {@code Random}. Java implementations must use all the algorithms
   95.44 - * shown here for the class {@code Random}, for the sake of absolute
   95.45 - * portability of Java code. However, subclasses of class {@code Random}
   95.46 - * are permitted to use other algorithms, so long as they adhere to the
   95.47 - * general contracts for all the methods.
   95.48 - * <p>
   95.49 - * The algorithms implemented by class {@code Random} use a
   95.50 - * {@code protected} utility method that on each invocation can supply
   95.51 - * up to 32 pseudorandomly generated bits.
   95.52 - * <p>
   95.53 - * Many applications will find the method {@link Math#random} simpler to use.
   95.54 - *
   95.55 - * <p>Instances of {@code java.util.Random} are threadsafe.
   95.56 - * However, the concurrent use of the same {@code java.util.Random}
   95.57 - * instance across threads may encounter contention and consequent
   95.58 - * poor performance. Consider instead using
   95.59 - * {@link java.util.concurrent.ThreadLocalRandom} in multithreaded
   95.60 - * designs.
   95.61 - *
   95.62 - * <p>Instances of {@code java.util.Random} are not cryptographically
   95.63 - * secure.  Consider instead using {@link java.security.SecureRandom} to
   95.64 - * get a cryptographically secure pseudo-random number generator for use
   95.65 - * by security-sensitive applications.
   95.66 - *
   95.67 - * @author  Frank Yellin
   95.68 - * @since   1.0
   95.69 - */
   95.70 -public
   95.71 -class Random implements java.io.Serializable {
   95.72 -    /** use serialVersionUID from JDK 1.1 for interoperability */
   95.73 -    static final long serialVersionUID = 3905348978240129619L;
   95.74 -
   95.75 -    /**
   95.76 -     * The internal state associated with this pseudorandom number generator.
   95.77 -     * (The specs for the methods in this class describe the ongoing
   95.78 -     * computation of this value.)
   95.79 -     */
   95.80 -    private long seed;
   95.81 -
   95.82 -    private static final long multiplier = 0x5DEECE66DL;
   95.83 -    private static final long addend = 0xBL;
   95.84 -    private static final long mask = (1L << 48) - 1;
   95.85 -
   95.86 -    /**
   95.87 -     * Creates a new random number generator. This constructor sets
   95.88 -     * the seed of the random number generator to a value very likely
   95.89 -     * to be distinct from any other invocation of this constructor.
   95.90 -     */
   95.91 -    public Random() {
   95.92 -        this(seedUniquifier() ^ System.nanoTime());
   95.93 -    }
   95.94 -    
   95.95 -    private static synchronized long seedUniquifier() {
   95.96 -        // L'Ecuyer, "Tables of Linear Congruential Generators of
   95.97 -        // Different Sizes and Good Lattice Structure", 1999
   95.98 -        long current = seedUniquifier;
   95.99 -        long next = current * 181783497276652981L;
  95.100 -        seedUniquifier = next;
  95.101 -        return next;
  95.102 -    }
  95.103 -
  95.104 -    private static long seedUniquifier = 8682522807148012L;
  95.105 -
  95.106 -    /**
  95.107 -     * Creates a new random number generator using a single {@code long} seed.
  95.108 -     * The seed is the initial value of the internal state of the pseudorandom
  95.109 -     * number generator which is maintained by method {@link #next}.
  95.110 -     *
  95.111 -     * <p>The invocation {@code new Random(seed)} is equivalent to:
  95.112 -     *  <pre> {@code
  95.113 -     * Random rnd = new Random();
  95.114 -     * rnd.setSeed(seed);}</pre>
  95.115 -     *
  95.116 -     * @param seed the initial seed
  95.117 -     * @see   #setSeed(long)
  95.118 -     */
  95.119 -    public Random(long seed) {
  95.120 -        this.seed = initialScramble(seed);
  95.121 -    }
  95.122 -
  95.123 -    private static long initialScramble(long seed) {
  95.124 -        return (seed ^ multiplier) & mask;
  95.125 -    }
  95.126 -
  95.127 -    /**
  95.128 -     * Sets the seed of this random number generator using a single
  95.129 -     * {@code long} seed. The general contract of {@code setSeed} is
  95.130 -     * that it alters the state of this random number generator object
  95.131 -     * so as to be in exactly the same state as if it had just been
  95.132 -     * created with the argument {@code seed} as a seed. The method
  95.133 -     * {@code setSeed} is implemented by class {@code Random} by
  95.134 -     * atomically updating the seed to
  95.135 -     *  <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre>
  95.136 -     * and clearing the {@code haveNextNextGaussian} flag used by {@link
  95.137 -     * #nextGaussian}.
  95.138 -     *
  95.139 -     * <p>The implementation of {@code setSeed} by class {@code Random}
  95.140 -     * happens to use only 48 bits of the given seed. In general, however,
  95.141 -     * an overriding method may use all 64 bits of the {@code long}
  95.142 -     * argument as a seed value.
  95.143 -     *
  95.144 -     * @param seed the initial seed
  95.145 -     */
  95.146 -    synchronized public void setSeed(long seed) {
  95.147 -        this.seed = initialScramble(seed);
  95.148 -        haveNextNextGaussian = false;
  95.149 -    }
  95.150 -
  95.151 -    /**
  95.152 -     * Generates the next pseudorandom number. Subclasses should
  95.153 -     * override this, as this is used by all other methods.
  95.154 -     *
  95.155 -     * <p>The general contract of {@code next} is that it returns an
  95.156 -     * {@code int} value and if the argument {@code bits} is between
  95.157 -     * {@code 1} and {@code 32} (inclusive), then that many low-order
  95.158 -     * bits of the returned value will be (approximately) independently
  95.159 -     * chosen bit values, each of which is (approximately) equally
  95.160 -     * likely to be {@code 0} or {@code 1}. The method {@code next} is
  95.161 -     * implemented by class {@code Random} by atomically updating the seed to
  95.162 -     *  <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
  95.163 -     * and returning
  95.164 -     *  <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
  95.165 -     *
  95.166 -     * This is a linear congruential pseudorandom number generator, as
  95.167 -     * defined by D. H. Lehmer and described by Donald E. Knuth in
  95.168 -     * <i>The Art of Computer Programming,</i> Volume 3:
  95.169 -     * <i>Seminumerical Algorithms</i>, section 3.2.1.
  95.170 -     *
  95.171 -     * @param  bits random bits
  95.172 -     * @return the next pseudorandom value from this random number
  95.173 -     *         generator's sequence
  95.174 -     * @since  1.1
  95.175 -     */
  95.176 -    protected synchronized int next(int bits) {
  95.177 -        long oldseed, nextseed;
  95.178 -        long seed = this.seed;
  95.179 -        oldseed = seed;
  95.180 -        nextseed = (oldseed * multiplier + addend) & mask;
  95.181 -        this.seed = nextseed;
  95.182 -        return (int)(nextseed >>> (48 - bits));
  95.183 -    }
  95.184 -
  95.185 -    /**
  95.186 -     * Generates random bytes and places them into a user-supplied
  95.187 -     * byte array.  The number of random bytes produced is equal to
  95.188 -     * the length of the byte array.
  95.189 -     *
  95.190 -     * <p>The method {@code nextBytes} is implemented by class {@code Random}
  95.191 -     * as if by:
  95.192 -     *  <pre> {@code
  95.193 -     * public void nextBytes(byte[] bytes) {
  95.194 -     *   for (int i = 0; i < bytes.length; )
  95.195 -     *     for (int rnd = nextInt(), n = Math.min(bytes.length - i, 4);
  95.196 -     *          n-- > 0; rnd >>= 8)
  95.197 -     *       bytes[i++] = (byte)rnd;
  95.198 -     * }}</pre>
  95.199 -     *
  95.200 -     * @param  bytes the byte array to fill with random bytes
  95.201 -     * @throws NullPointerException if the byte array is null
  95.202 -     * @since  1.1
  95.203 -     */
  95.204 -    public void nextBytes(byte[] bytes) {
  95.205 -        for (int i = 0, len = bytes.length; i < len; )
  95.206 -            for (int rnd = nextInt(),
  95.207 -                     n = Math.min(len - i, Integer.SIZE/Byte.SIZE);
  95.208 -                 n-- > 0; rnd >>= Byte.SIZE)
  95.209 -                bytes[i++] = (byte)rnd;
  95.210 -    }
  95.211 -
  95.212 -    /**
  95.213 -     * Returns the next pseudorandom, uniformly distributed {@code int}
  95.214 -     * value from this random number generator's sequence. The general
  95.215 -     * contract of {@code nextInt} is that one {@code int} value is
  95.216 -     * pseudorandomly generated and returned. All 2<font size="-1"><sup>32
  95.217 -     * </sup></font> possible {@code int} values are produced with
  95.218 -     * (approximately) equal probability.
  95.219 -     *
  95.220 -     * <p>The method {@code nextInt} is implemented by class {@code Random}
  95.221 -     * as if by:
  95.222 -     *  <pre> {@code
  95.223 -     * public int nextInt() {
  95.224 -     *   return next(32);
  95.225 -     * }}</pre>
  95.226 -     *
  95.227 -     * @return the next pseudorandom, uniformly distributed {@code int}
  95.228 -     *         value from this random number generator's sequence
  95.229 -     */
  95.230 -    public int nextInt() {
  95.231 -        return next(32);
  95.232 -    }
  95.233 -
  95.234 -    /**
  95.235 -     * Returns a pseudorandom, uniformly distributed {@code int} value
  95.236 -     * between 0 (inclusive) and the specified value (exclusive), drawn from
  95.237 -     * this random number generator's sequence.  The general contract of
  95.238 -     * {@code nextInt} is that one {@code int} value in the specified range
  95.239 -     * is pseudorandomly generated and returned.  All {@code n} possible
  95.240 -     * {@code int} values are produced with (approximately) equal
  95.241 -     * probability.  The method {@code nextInt(int n)} is implemented by
  95.242 -     * class {@code Random} as if by:
  95.243 -     *  <pre> {@code
  95.244 -     * public int nextInt(int n) {
  95.245 -     *   if (n <= 0)
  95.246 -     *     throw new IllegalArgumentException("n must be positive");
  95.247 -     *
  95.248 -     *   if ((n & -n) == n)  // i.e., n is a power of 2
  95.249 -     *     return (int)((n * (long)next(31)) >> 31);
  95.250 -     *
  95.251 -     *   int bits, val;
  95.252 -     *   do {
  95.253 -     *       bits = next(31);
  95.254 -     *       val = bits % n;
  95.255 -     *   } while (bits - val + (n-1) < 0);
  95.256 -     *   return val;
  95.257 -     * }}</pre>
  95.258 -     *
  95.259 -     * <p>The hedge "approximately" is used in the foregoing description only
  95.260 -     * because the next method is only approximately an unbiased source of
  95.261 -     * independently chosen bits.  If it were a perfect source of randomly
  95.262 -     * chosen bits, then the algorithm shown would choose {@code int}
  95.263 -     * values from the stated range with perfect uniformity.
  95.264 -     * <p>
  95.265 -     * The algorithm is slightly tricky.  It rejects values that would result
  95.266 -     * in an uneven distribution (due to the fact that 2^31 is not divisible
  95.267 -     * by n). The probability of a value being rejected depends on n.  The
  95.268 -     * worst case is n=2^30+1, for which the probability of a reject is 1/2,
  95.269 -     * and the expected number of iterations before the loop terminates is 2.
  95.270 -     * <p>
  95.271 -     * The algorithm treats the case where n is a power of two specially: it
  95.272 -     * returns the correct number of high-order bits from the underlying
  95.273 -     * pseudo-random number generator.  In the absence of special treatment,
  95.274 -     * the correct number of <i>low-order</i> bits would be returned.  Linear
  95.275 -     * congruential pseudo-random number generators such as the one
  95.276 -     * implemented by this class are known to have short periods in the
  95.277 -     * sequence of values of their low-order bits.  Thus, this special case
  95.278 -     * greatly increases the length of the sequence of values returned by
  95.279 -     * successive calls to this method if n is a small power of two.
  95.280 -     *
  95.281 -     * @param n the bound on the random number to be returned.  Must be
  95.282 -     *        positive.
  95.283 -     * @return the next pseudorandom, uniformly distributed {@code int}
  95.284 -     *         value between {@code 0} (inclusive) and {@code n} (exclusive)
  95.285 -     *         from this random number generator's sequence
  95.286 -     * @throws IllegalArgumentException if n is not positive
  95.287 -     * @since 1.2
  95.288 -     */
  95.289 -
  95.290 -    public int nextInt(int n) {
  95.291 -        if (n <= 0)
  95.292 -            throw new IllegalArgumentException("n must be positive");
  95.293 -
  95.294 -        if ((n & -n) == n)  // i.e., n is a power of 2
  95.295 -            return (int)((n * (long)next(31)) >> 31);
  95.296 -
  95.297 -        int bits, val;
  95.298 -        do {
  95.299 -            bits = next(31);
  95.300 -            val = bits % n;
  95.301 -        } while (bits - val + (n-1) < 0);
  95.302 -        return val;
  95.303 -    }
  95.304 -
  95.305 -    /**
  95.306 -     * Returns the next pseudorandom, uniformly distributed {@code long}
  95.307 -     * value from this random number generator's sequence. The general
  95.308 -     * contract of {@code nextLong} is that one {@code long} value is
  95.309 -     * pseudorandomly generated and returned.
  95.310 -     *
  95.311 -     * <p>The method {@code nextLong} is implemented by class {@code Random}
  95.312 -     * as if by:
  95.313 -     *  <pre> {@code
  95.314 -     * public long nextLong() {
  95.315 -     *   return ((long)next(32) << 32) + next(32);
  95.316 -     * }}</pre>
  95.317 -     *
  95.318 -     * Because class {@code Random} uses a seed with only 48 bits,
  95.319 -     * this algorithm will not return all possible {@code long} values.
  95.320 -     *
  95.321 -     * @return the next pseudorandom, uniformly distributed {@code long}
  95.322 -     *         value from this random number generator's sequence
  95.323 -     */
  95.324 -    public long nextLong() {
  95.325 -        // it's okay that the bottom word remains signed.
  95.326 -        return ((long)(next(32)) << 32) + next(32);
  95.327 -    }
  95.328 -
  95.329 -    /**
  95.330 -     * Returns the next pseudorandom, uniformly distributed
  95.331 -     * {@code boolean} value from this random number generator's
  95.332 -     * sequence. The general contract of {@code nextBoolean} is that one
  95.333 -     * {@code boolean} value is pseudorandomly generated and returned.  The
  95.334 -     * values {@code true} and {@code false} are produced with
  95.335 -     * (approximately) equal probability.
  95.336 -     *
  95.337 -     * <p>The method {@code nextBoolean} is implemented by class {@code Random}
  95.338 -     * as if by:
  95.339 -     *  <pre> {@code
  95.340 -     * public boolean nextBoolean() {
  95.341 -     *   return next(1) != 0;
  95.342 -     * }}</pre>
  95.343 -     *
  95.344 -     * @return the next pseudorandom, uniformly distributed
  95.345 -     *         {@code boolean} value from this random number generator's
  95.346 -     *         sequence
  95.347 -     * @since 1.2
  95.348 -     */
  95.349 -    public boolean nextBoolean() {
  95.350 -        return next(1) != 0;
  95.351 -    }
  95.352 -
  95.353 -    /**
  95.354 -     * Returns the next pseudorandom, uniformly distributed {@code float}
  95.355 -     * value between {@code 0.0} and {@code 1.0} from this random
  95.356 -     * number generator's sequence.
  95.357 -     *
  95.358 -     * <p>The general contract of {@code nextFloat} is that one
  95.359 -     * {@code float} value, chosen (approximately) uniformly from the
  95.360 -     * range {@code 0.0f} (inclusive) to {@code 1.0f} (exclusive), is
  95.361 -     * pseudorandomly generated and returned. All 2<font
  95.362 -     * size="-1"><sup>24</sup></font> possible {@code float} values
  95.363 -     * of the form <i>m&nbsp;x&nbsp</i>2<font
  95.364 -     * size="-1"><sup>-24</sup></font>, where <i>m</i> is a positive
  95.365 -     * integer less than 2<font size="-1"><sup>24</sup> </font>, are
  95.366 -     * produced with (approximately) equal probability.
  95.367 -     *
  95.368 -     * <p>The method {@code nextFloat} is implemented by class {@code Random}
  95.369 -     * as if by:
  95.370 -     *  <pre> {@code
  95.371 -     * public float nextFloat() {
  95.372 -     *   return next(24) / ((float)(1 << 24));
  95.373 -     * }}</pre>
  95.374 -     *
  95.375 -     * <p>The hedge "approximately" is used in the foregoing description only
  95.376 -     * because the next method is only approximately an unbiased source of
  95.377 -     * independently chosen bits. If it were a perfect source of randomly
  95.378 -     * chosen bits, then the algorithm shown would choose {@code float}
  95.379 -     * values from the stated range with perfect uniformity.<p>
  95.380 -     * [In early versions of Java, the result was incorrectly calculated as:
  95.381 -     *  <pre> {@code
  95.382 -     *   return next(30) / ((float)(1 << 30));}</pre>
  95.383 -     * This might seem to be equivalent, if not better, but in fact it
  95.384 -     * introduced a slight nonuniformity because of the bias in the rounding
  95.385 -     * of floating-point numbers: it was slightly more likely that the
  95.386 -     * low-order bit of the significand would be 0 than that it would be 1.]
  95.387 -     *
  95.388 -     * @return the next pseudorandom, uniformly distributed {@code float}
  95.389 -     *         value between {@code 0.0} and {@code 1.0} from this
  95.390 -     *         random number generator's sequence
  95.391 -     */
  95.392 -    public float nextFloat() {
  95.393 -        return next(24) / ((float)(1 << 24));
  95.394 -    }
  95.395 -
  95.396 -    /**
  95.397 -     * Returns the next pseudorandom, uniformly distributed
  95.398 -     * {@code double} value between {@code 0.0} and
  95.399 -     * {@code 1.0} from this random number generator's sequence.
  95.400 -     *
  95.401 -     * <p>The general contract of {@code nextDouble} is that one
  95.402 -     * {@code double} value, chosen (approximately) uniformly from the
  95.403 -     * range {@code 0.0d} (inclusive) to {@code 1.0d} (exclusive), is
  95.404 -     * pseudorandomly generated and returned.
  95.405 -     *
  95.406 -     * <p>The method {@code nextDouble} is implemented by class {@code Random}
  95.407 -     * as if by:
  95.408 -     *  <pre> {@code
  95.409 -     * public double nextDouble() {
  95.410 -     *   return (((long)next(26) << 27) + next(27))
  95.411 -     *     / (double)(1L << 53);
  95.412 -     * }}</pre>
  95.413 -     *
  95.414 -     * <p>The hedge "approximately" is used in the foregoing description only
  95.415 -     * because the {@code next} method is only approximately an unbiased
  95.416 -     * source of independently chosen bits. If it were a perfect source of
  95.417 -     * randomly chosen bits, then the algorithm shown would choose
  95.418 -     * {@code double} values from the stated range with perfect uniformity.
  95.419 -     * <p>[In early versions of Java, the result was incorrectly calculated as:
  95.420 -     *  <pre> {@code
  95.421 -     *   return (((long)next(27) << 27) + next(27))
  95.422 -     *     / (double)(1L << 54);}</pre>
  95.423 -     * This might seem to be equivalent, if not better, but in fact it
  95.424 -     * introduced a large nonuniformity because of the bias in the rounding
  95.425 -     * of floating-point numbers: it was three times as likely that the
  95.426 -     * low-order bit of the significand would be 0 than that it would be 1!
  95.427 -     * This nonuniformity probably doesn't matter much in practice, but we
  95.428 -     * strive for perfection.]
  95.429 -     *
  95.430 -     * @return the next pseudorandom, uniformly distributed {@code double}
  95.431 -     *         value between {@code 0.0} and {@code 1.0} from this
  95.432 -     *         random number generator's sequence
  95.433 -     * @see Math#random
  95.434 -     */
  95.435 -    public double nextDouble() {
  95.436 -        return (((long)(next(26)) << 27) + next(27))
  95.437 -            / (double)(1L << 53);
  95.438 -    }
  95.439 -
  95.440 -    private double nextNextGaussian;
  95.441 -    private boolean haveNextNextGaussian = false;
  95.442 -
  95.443 -    /**
  95.444 -     * Returns the next pseudorandom, Gaussian ("normally") distributed
  95.445 -     * {@code double} value with mean {@code 0.0} and standard
  95.446 -     * deviation {@code 1.0} from this random number generator's sequence.
  95.447 -     * <p>
  95.448 -     * The general contract of {@code nextGaussian} is that one
  95.449 -     * {@code double} value, chosen from (approximately) the usual
  95.450 -     * normal distribution with mean {@code 0.0} and standard deviation
  95.451 -     * {@code 1.0}, is pseudorandomly generated and returned.
  95.452 -     *
  95.453 -     * <p>The method {@code nextGaussian} is implemented by class
  95.454 -     * {@code Random} as if by a threadsafe version of the following:
  95.455 -     *  <pre> {@code
  95.456 -     * private double nextNextGaussian;
  95.457 -     * private boolean haveNextNextGaussian = false;
  95.458 -     *
  95.459 -     * public double nextGaussian() {
  95.460 -     *   if (haveNextNextGaussian) {
  95.461 -     *     haveNextNextGaussian = false;
  95.462 -     *     return nextNextGaussian;
  95.463 -     *   } else {
  95.464 -     *     double v1, v2, s;
  95.465 -     *     do {
  95.466 -     *       v1 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
  95.467 -     *       v2 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
  95.468 -     *       s = v1 * v1 + v2 * v2;
  95.469 -     *     } while (s >= 1 || s == 0);
  95.470 -     *     double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s);
  95.471 -     *     nextNextGaussian = v2 * multiplier;
  95.472 -     *     haveNextNextGaussian = true;
  95.473 -     *     return v1 * multiplier;
  95.474 -     *   }
  95.475 -     * }}</pre>
  95.476 -     * This uses the <i>polar method</i> of G. E. P. Box, M. E. Muller, and
  95.477 -     * G. Marsaglia, as described by Donald E. Knuth in <i>The Art of
  95.478 -     * Computer Programming</i>, Volume 3: <i>Seminumerical Algorithms</i>,
  95.479 -     * section 3.4.1, subsection C, algorithm P. Note that it generates two
  95.480 -     * independent values at the cost of only one call to {@code StrictMath.log}
  95.481 -     * and one call to {@code StrictMath.sqrt}.
  95.482 -     *
  95.483 -     * @return the next pseudorandom, Gaussian ("normally") distributed
  95.484 -     *         {@code double} value with mean {@code 0.0} and
  95.485 -     *         standard deviation {@code 1.0} from this random number
  95.486 -     *         generator's sequence
  95.487 -     */
  95.488 -    synchronized public double nextGaussian() {
  95.489 -        // See Knuth, ACP, Section 3.4.1 Algorithm C.
  95.490 -        if (haveNextNextGaussian) {
  95.491 -            haveNextNextGaussian = false;
  95.492 -            return nextNextGaussian;
  95.493 -        } else {
  95.494 -            double v1, v2, s;
  95.495 -            do {
  95.496 -                v1 = 2 * nextDouble() - 1; // between -1 and 1
  95.497 -                v2 = 2 * nextDouble() - 1; // between -1 and 1
  95.498 -                s = v1 * v1 + v2 * v2;
  95.499 -            } while (s >= 1 || s == 0);
  95.500 -            double multiplier = Math.sqrt(-2 * Math.log(s)/s);
  95.501 -            nextNextGaussian = v2 * multiplier;
  95.502 -            haveNextNextGaussian = true;
  95.503 -            return v1 * multiplier;
  95.504 -        }
  95.505 -    }
  95.506 -}
    96.1 --- a/emul/compact/src/main/java/java/util/RandomAccess.java	Mon Feb 25 19:00:08 2013 +0100
    96.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.3 @@ -1,68 +0,0 @@
    96.4 -/*
    96.5 - * Copyright (c) 2000, 2006, 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.util;
   96.30 -
   96.31 -/**
   96.32 - * Marker interface used by <tt>List</tt> implementations to indicate that
   96.33 - * they support fast (generally constant time) random access.  The primary
   96.34 - * purpose of this interface is to allow generic algorithms to alter their
   96.35 - * behavior to provide good performance when applied to either random or
   96.36 - * sequential access lists.
   96.37 - *
   96.38 - * <p>The best algorithms for manipulating random access lists (such as
   96.39 - * <tt>ArrayList</tt>) can produce quadratic behavior when applied to
   96.40 - * sequential access lists (such as <tt>LinkedList</tt>).  Generic list
   96.41 - * algorithms are encouraged to check whether the given list is an
   96.42 - * <tt>instanceof</tt> this interface before applying an algorithm that would
   96.43 - * provide poor performance if it were applied to a sequential access list,
   96.44 - * and to alter their behavior if necessary to guarantee acceptable
   96.45 - * performance.
   96.46 - *
   96.47 - * <p>It is recognized that the distinction between random and sequential
   96.48 - * access is often fuzzy.  For example, some <tt>List</tt> implementations
   96.49 - * provide asymptotically linear access times if they get huge, but constant
   96.50 - * access times in practice.  Such a <tt>List</tt> implementation
   96.51 - * should generally implement this interface.  As a rule of thumb, a
   96.52 - * <tt>List</tt> implementation should implement this interface if,
   96.53 - * for typical instances of the class, this loop:
   96.54 - * <pre>
   96.55 - *     for (int i=0, n=list.size(); i &lt; n; i++)
   96.56 - *         list.get(i);
   96.57 - * </pre>
   96.58 - * runs faster than this loop:
   96.59 - * <pre>
   96.60 - *     for (Iterator i=list.iterator(); i.hasNext(); )
   96.61 - *         i.next();
   96.62 - * </pre>
   96.63 - *
   96.64 - * <p>This interface is a member of the
   96.65 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   96.66 - * Java Collections Framework</a>.
   96.67 - *
   96.68 - * @since 1.4
   96.69 - */
   96.70 -public interface RandomAccess {
   96.71 -}
    97.1 --- a/emul/compact/src/main/java/java/util/ServiceConfigurationError.java	Mon Feb 25 19:00:08 2013 +0100
    97.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.3 @@ -1,87 +0,0 @@
    97.4 -/*
    97.5 - * Copyright (c) 2005, 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.util;
   97.30 -
   97.31 -
   97.32 -/**
   97.33 - * Error thrown when something goes wrong while loading a service provider.
   97.34 - *
   97.35 - * <p> This error will be thrown in the following situations:
   97.36 - *
   97.37 - * <ul>
   97.38 - *
   97.39 - *   <li> The format of a provider-configuration file violates the <a
   97.40 - *   href="ServiceLoader.html#format">specification</a>; </li>
   97.41 - *
   97.42 - *   <li> An {@link java.io.IOException IOException} occurs while reading a
   97.43 - *   provider-configuration file; </li>
   97.44 - *
   97.45 - *   <li> A concrete provider class named in a provider-configuration file
   97.46 - *   cannot be found; </li>
   97.47 - *
   97.48 - *   <li> A concrete provider class is not a subclass of the service class;
   97.49 - *   </li>
   97.50 - *
   97.51 - *   <li> A concrete provider class cannot be instantiated; or
   97.52 - *
   97.53 - *   <li> Some other kind of error occurs. </li>
   97.54 - *
   97.55 - * </ul>
   97.56 - *
   97.57 - *
   97.58 - * @author Mark Reinhold
   97.59 - * @since 1.6
   97.60 - */
   97.61 -
   97.62 -public class ServiceConfigurationError
   97.63 -    extends Error
   97.64 -{
   97.65 -
   97.66 -    private static final long serialVersionUID = 74132770414881L;
   97.67 -
   97.68 -    /**
   97.69 -     * Constructs a new instance with the specified message.
   97.70 -     *
   97.71 -     * @param  msg  The message, or <tt>null</tt> if there is no message
   97.72 -     *
   97.73 -     */
   97.74 -    public ServiceConfigurationError(String msg) {
   97.75 -        super(msg);
   97.76 -    }
   97.77 -
   97.78 -    /**
   97.79 -     * Constructs a new instance with the specified message and cause.
   97.80 -     *
   97.81 -     * @param  msg  The message, or <tt>null</tt> if there is no message
   97.82 -     *
   97.83 -     * @param  cause  The cause, or <tt>null</tt> if the cause is nonexistent
   97.84 -     *                or unknown
   97.85 -     */
   97.86 -    public ServiceConfigurationError(String msg, Throwable cause) {
   97.87 -        super(msg, cause);
   97.88 -    }
   97.89 -
   97.90 -}
    98.1 --- a/emul/compact/src/main/java/java/util/ServiceLoader.java	Mon Feb 25 19:00:08 2013 +0100
    98.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.3 @@ -1,538 +0,0 @@
    98.4 -/*
    98.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
    98.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    98.7 - *
    98.8 - * This code is free software; you can redistribute it and/or modify it
    98.9 - * under the terms of the GNU General Public License version 2 only, as
   98.10 - * published by the Free Software Foundation.  Oracle designates this
   98.11 - * particular file as subject to the "Classpath" exception as provided
   98.12 - * by Oracle in the LICENSE file that accompanied this code.
   98.13 - *
   98.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   98.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   98.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   98.17 - * version 2 for more details (a copy is included in the LICENSE file that
   98.18 - * accompanied this code).
   98.19 - *
   98.20 - * You should have received a copy of the GNU General Public License version
   98.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   98.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   98.23 - *
   98.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   98.25 - * or visit www.oracle.com if you need additional information or have any
   98.26 - * questions.
   98.27 - */
   98.28 -
   98.29 -package java.util;
   98.30 -
   98.31 -import java.io.BufferedReader;
   98.32 -import java.io.IOException;
   98.33 -import java.io.InputStream;
   98.34 -import java.io.InputStreamReader;
   98.35 -import java.net.URL;
   98.36 -import java.util.ArrayList;
   98.37 -import java.util.Enumeration;
   98.38 -import java.util.Iterator;
   98.39 -import java.util.List;
   98.40 -import java.util.NoSuchElementException;
   98.41 -
   98.42 -
   98.43 -/**
   98.44 - * A simple service-provider loading facility.
   98.45 - *
   98.46 - * <p> A <i>service</i> is a well-known set of interfaces and (usually
   98.47 - * abstract) classes.  A <i>service provider</i> is a specific implementation
   98.48 - * of a service.  The classes in a provider typically implement the interfaces
   98.49 - * and subclass the classes defined in the service itself.  Service providers
   98.50 - * can be installed in an implementation of the Java platform in the form of
   98.51 - * extensions, that is, jar files placed into any of the usual extension
   98.52 - * directories.  Providers can also be made available by adding them to the
   98.53 - * application's class path or by some other platform-specific means.
   98.54 - *
   98.55 - * <p> For the purpose of loading, a service is represented by a single type,
   98.56 - * that is, a single interface or abstract class.  (A concrete class can be
   98.57 - * used, but this is not recommended.)  A provider of a given service contains
   98.58 - * one or more concrete classes that extend this <i>service type</i> with data
   98.59 - * and code specific to the provider.  The <i>provider class</i> is typically
   98.60 - * not the entire provider itself but rather a proxy which contains enough
   98.61 - * information to decide whether the provider is able to satisfy a particular
   98.62 - * request together with code that can create the actual provider on demand.
   98.63 - * The details of provider classes tend to be highly service-specific; no
   98.64 - * single class or interface could possibly unify them, so no such type is
   98.65 - * defined here.  The only requirement enforced by this facility is that
   98.66 - * provider classes must have a zero-argument constructor so that they can be
   98.67 - * instantiated during loading.
   98.68 - *
   98.69 - * <p><a name="format"> A service provider is identified by placing a
   98.70 - * <i>provider-configuration file</i> in the resource directory
   98.71 - * <tt>META-INF/services</tt>.  The file's name is the fully-qualified <a
   98.72 - * href="../lang/ClassLoader.html#name">binary name</a> of the service's type.
   98.73 - * The file contains a list of fully-qualified binary names of concrete
   98.74 - * provider classes, one per line.  Space and tab characters surrounding each
   98.75 - * name, as well as blank lines, are ignored.  The comment character is
   98.76 - * <tt>'#'</tt> (<tt>'&#92;u0023'</tt>, <font size="-1">NUMBER SIGN</font>); on
   98.77 - * each line all characters following the first comment character are ignored.
   98.78 - * The file must be encoded in UTF-8.
   98.79 - *
   98.80 - * <p> If a particular concrete provider class is named in more than one
   98.81 - * configuration file, or is named in the same configuration file more than
   98.82 - * once, then the duplicates are ignored.  The configuration file naming a
   98.83 - * particular provider need not be in the same jar file or other distribution
   98.84 - * unit as the provider itself.  The provider must be accessible from the same
   98.85 - * class loader that was initially queried to locate the configuration file;
   98.86 - * note that this is not necessarily the class loader from which the file was
   98.87 - * actually loaded.
   98.88 - *
   98.89 - * <p> Providers are located and instantiated lazily, that is, on demand.  A
   98.90 - * service loader maintains a cache of the providers that have been loaded so
   98.91 - * far.  Each invocation of the {@link #iterator iterator} method returns an
   98.92 - * iterator that first yields all of the elements of the cache, in
   98.93 - * instantiation order, and then lazily locates and instantiates any remaining
   98.94 - * providers, adding each one to the cache in turn.  The cache can be cleared
   98.95 - * via the {@link #reload reload} method.
   98.96 - *
   98.97 - * <p> Service loaders always execute in the security context of the caller.
   98.98 - * Trusted system code should typically invoke the methods in this class, and
   98.99 - * the methods of the iterators which they return, from within a privileged
  98.100 - * security context.
  98.101 - *
  98.102 - * <p> Instances of this class are not safe for use by multiple concurrent
  98.103 - * threads.
  98.104 - *
  98.105 - * <p> Unless otherwise specified, passing a <tt>null</tt> argument to any
  98.106 - * method in this class will cause a {@link NullPointerException} to be thrown.
  98.107 - *
  98.108 - *
  98.109 - * <p><span style="font-weight: bold; padding-right: 1em">Example</span>
  98.110 - * Suppose we have a service type <tt>com.example.CodecSet</tt> which is
  98.111 - * intended to represent sets of encoder/decoder pairs for some protocol.  In
  98.112 - * this case it is an abstract class with two abstract methods:
  98.113 - *
  98.114 - * <blockquote><pre>
  98.115 - * public abstract Encoder getEncoder(String encodingName);
  98.116 - * public abstract Decoder getDecoder(String encodingName);</pre></blockquote>
  98.117 - *
  98.118 - * Each method returns an appropriate object or <tt>null</tt> if the provider
  98.119 - * does not support the given encoding.  Typical providers support more than
  98.120 - * one encoding.
  98.121 - *
  98.122 - * <p> If <tt>com.example.impl.StandardCodecs</tt> is an implementation of the
  98.123 - * <tt>CodecSet</tt> service then its jar file also contains a file named
  98.124 - *
  98.125 - * <blockquote><pre>
  98.126 - * META-INF/services/com.example.CodecSet</pre></blockquote>
  98.127 - *
  98.128 - * <p> This file contains the single line:
  98.129 - *
  98.130 - * <blockquote><pre>
  98.131 - * com.example.impl.StandardCodecs    # Standard codecs</pre></blockquote>
  98.132 - *
  98.133 - * <p> The <tt>CodecSet</tt> class creates and saves a single service instance
  98.134 - * at initialization:
  98.135 - *
  98.136 - * <blockquote><pre>
  98.137 - * private static ServiceLoader&lt;CodecSet&gt; codecSetLoader
  98.138 - *     = ServiceLoader.load(CodecSet.class);</pre></blockquote>
  98.139 - *
  98.140 - * <p> To locate an encoder for a given encoding name it defines a static
  98.141 - * factory method which iterates through the known and available providers,
  98.142 - * returning only when it has located a suitable encoder or has run out of
  98.143 - * providers.
  98.144 - *
  98.145 - * <blockquote><pre>
  98.146 - * public static Encoder getEncoder(String encodingName) {
  98.147 - *     for (CodecSet cp : codecSetLoader) {
  98.148 - *         Encoder enc = cp.getEncoder(encodingName);
  98.149 - *         if (enc != null)
  98.150 - *             return enc;
  98.151 - *     }
  98.152 - *     return null;
  98.153 - * }</pre></blockquote>
  98.154 - *
  98.155 - * <p> A <tt>getDecoder</tt> method is defined similarly.
  98.156 - *
  98.157 - *
  98.158 - * <p><span style="font-weight: bold; padding-right: 1em">Usage Note</span> If
  98.159 - * the class path of a class loader that is used for provider loading includes
  98.160 - * remote network URLs then those URLs will be dereferenced in the process of
  98.161 - * searching for provider-configuration files.
  98.162 - *
  98.163 - * <p> This activity is normal, although it may cause puzzling entries to be
  98.164 - * created in web-server logs.  If a web server is not configured correctly,
  98.165 - * however, then this activity may cause the provider-loading algorithm to fail
  98.166 - * spuriously.
  98.167 - *
  98.168 - * <p> A web server should return an HTTP 404 (Not Found) response when a
  98.169 - * requested resource does not exist.  Sometimes, however, web servers are
  98.170 - * erroneously configured to return an HTTP 200 (OK) response along with a
  98.171 - * helpful HTML error page in such cases.  This will cause a {@link
  98.172 - * ServiceConfigurationError} to be thrown when this class attempts to parse
  98.173 - * the HTML page as a provider-configuration file.  The best solution to this
  98.174 - * problem is to fix the misconfigured web server to return the correct
  98.175 - * response code (HTTP 404) along with the HTML error page.
  98.176 - *
  98.177 - * @param  <S>
  98.178 - *         The type of the service to be loaded by this loader
  98.179 - *
  98.180 - * @author Mark Reinhold
  98.181 - * @since 1.6
  98.182 - */
  98.183 -
  98.184 -public final class ServiceLoader<S>
  98.185 -    implements Iterable<S>
  98.186 -{
  98.187 -
  98.188 -    private static final String PREFIX = "META-INF/services/";
  98.189 -
  98.190 -    // The class or interface representing the service being loaded
  98.191 -    private Class<S> service;
  98.192 -
  98.193 -    // The class loader used to locate, load, and instantiate providers
  98.194 -    private ClassLoader loader;
  98.195 -
  98.196 -    // Cached providers, in instantiation order
  98.197 -    private LinkedHashMap<String,S> providers = new LinkedHashMap<>();
  98.198 -
  98.199 -    // The current lazy-lookup iterator
  98.200 -    private LazyIterator lookupIterator;
  98.201 -
  98.202 -    /**
  98.203 -     * Clear this loader's provider cache so that all providers will be
  98.204 -     * reloaded.
  98.205 -     *
  98.206 -     * <p> After invoking this method, subsequent invocations of the {@link
  98.207 -     * #iterator() iterator} method will lazily look up and instantiate
  98.208 -     * providers from scratch, just as is done by a newly-created loader.
  98.209 -     *
  98.210 -     * <p> This method is intended for use in situations in which new providers
  98.211 -     * can be installed into a running Java virtual machine.
  98.212 -     */
  98.213 -    public void reload() {
  98.214 -        providers.clear();
  98.215 -        lookupIterator = new LazyIterator(service, loader);
  98.216 -    }
  98.217 -
  98.218 -    private ServiceLoader(Class<S> svc, ClassLoader cl) {
  98.219 -        service = svc;
  98.220 -        loader = cl;
  98.221 -        reload();
  98.222 -    }
  98.223 -
  98.224 -    private static void fail(Class service, String msg, Throwable cause)
  98.225 -        throws ServiceConfigurationError
  98.226 -    {
  98.227 -        throw new ServiceConfigurationError(service.getName() + ": " + msg,
  98.228 -                                            cause);
  98.229 -    }
  98.230 -
  98.231 -    private static void fail(Class service, String msg)
  98.232 -        throws ServiceConfigurationError
  98.233 -    {
  98.234 -        throw new ServiceConfigurationError(service.getName() + ": " + msg);
  98.235 -    }
  98.236 -
  98.237 -    private static void fail(Class service, URL u, int line, String msg)
  98.238 -        throws ServiceConfigurationError
  98.239 -    {
  98.240 -        fail(service, u + ":" + line + ": " + msg);
  98.241 -    }
  98.242 -
  98.243 -    // Parse a single line from the given configuration file, adding the name
  98.244 -    // on the line to the names list.
  98.245 -    //
  98.246 -    private int parseLine(Class service, URL u, BufferedReader r, int lc,
  98.247 -                          List<String> names)
  98.248 -        throws IOException, ServiceConfigurationError
  98.249 -    {
  98.250 -        String ln = r.readLine();
  98.251 -        if (ln == null) {
  98.252 -            return -1;
  98.253 -        }
  98.254 -        int ci = ln.indexOf('#');
  98.255 -        if (ci >= 0) ln = ln.substring(0, ci);
  98.256 -        ln = ln.trim();
  98.257 -        int n = ln.length();
  98.258 -        if (n != 0) {
  98.259 -            if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
  98.260 -                fail(service, u, lc, "Illegal configuration-file syntax");
  98.261 -            int cp = ln.codePointAt(0);
  98.262 -            if (!Character.isJavaIdentifierStart(cp))
  98.263 -                fail(service, u, lc, "Illegal provider-class name: " + ln);
  98.264 -            for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
  98.265 -                cp = ln.codePointAt(i);
  98.266 -                if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
  98.267 -                    fail(service, u, lc, "Illegal provider-class name: " + ln);
  98.268 -            }
  98.269 -            if (!providers.containsKey(ln) && !names.contains(ln))
  98.270 -                names.add(ln);
  98.271 -        }
  98.272 -        return lc + 1;
  98.273 -    }
  98.274 -
  98.275 -    // Parse the content of the given URL as a provider-configuration file.
  98.276 -    //
  98.277 -    // @param  service
  98.278 -    //         The service type for which providers are being sought;
  98.279 -    //         used to construct error detail strings
  98.280 -    //
  98.281 -    // @param  u
  98.282 -    //         The URL naming the configuration file to be parsed
  98.283 -    //
  98.284 -    // @return A (possibly empty) iterator that will yield the provider-class
  98.285 -    //         names in the given configuration file that are not yet members
  98.286 -    //         of the returned set
  98.287 -    //
  98.288 -    // @throws ServiceConfigurationError
  98.289 -    //         If an I/O error occurs while reading from the given URL, or
  98.290 -    //         if a configuration-file format error is detected
  98.291 -    //
  98.292 -    private Iterator<String> parse(Class service, URL u)
  98.293 -        throws ServiceConfigurationError
  98.294 -    {
  98.295 -        InputStream in = null;
  98.296 -        BufferedReader r = null;
  98.297 -        ArrayList<String> names = new ArrayList<>();
  98.298 -        try {
  98.299 -            in = u.openStream();
  98.300 -            r = new BufferedReader(new InputStreamReader(in, "utf-8"));
  98.301 -            int lc = 1;
  98.302 -            while ((lc = parseLine(service, u, r, lc, names)) >= 0);
  98.303 -        } catch (IOException x) {
  98.304 -            fail(service, "Error reading configuration file", x);
  98.305 -        } finally {
  98.306 -            try {
  98.307 -                if (r != null) r.close();
  98.308 -                if (in != null) in.close();
  98.309 -            } catch (IOException y) {
  98.310 -                fail(service, "Error closing configuration file", y);
  98.311 -            }
  98.312 -        }
  98.313 -        return names.iterator();
  98.314 -    }
  98.315 -
  98.316 -    // Private inner class implementing fully-lazy provider lookup
  98.317 -    //
  98.318 -    private class LazyIterator
  98.319 -        implements Iterator<S>
  98.320 -    {
  98.321 -
  98.322 -        Class<S> service;
  98.323 -        ClassLoader loader;
  98.324 -        Enumeration<URL> configs = null;
  98.325 -        Iterator<String> pending = null;
  98.326 -        String nextName = null;
  98.327 -
  98.328 -        private LazyIterator(Class<S> service, ClassLoader loader) {
  98.329 -            this.service = service;
  98.330 -            this.loader = loader;
  98.331 -        }
  98.332 -
  98.333 -        public boolean hasNext() {
  98.334 -            if (nextName != null) {
  98.335 -                return true;
  98.336 -            }
  98.337 -            if (configs == null) {
  98.338 -                try {
  98.339 -                    String fullName = PREFIX + service.getName();
  98.340 -                    if (loader == null)
  98.341 -                        configs = ClassLoader.getSystemResources(fullName);
  98.342 -                    else
  98.343 -                        configs = loader.getResources(fullName);
  98.344 -                } catch (IOException x) {
  98.345 -                    fail(service, "Error locating configuration files", x);
  98.346 -                }
  98.347 -            }
  98.348 -            while ((pending == null) || !pending.hasNext()) {
  98.349 -                if (!configs.hasMoreElements()) {
  98.350 -                    return false;
  98.351 -                }
  98.352 -                pending = parse(service, configs.nextElement());
  98.353 -            }
  98.354 -            nextName = pending.next();
  98.355 -            return true;
  98.356 -        }
  98.357 -
  98.358 -        public S next() {
  98.359 -            if (!hasNext()) {
  98.360 -                throw new NoSuchElementException();
  98.361 -            }
  98.362 -            String cn = nextName;
  98.363 -            nextName = null;
  98.364 -            try {
  98.365 -                S p = service.cast(Class.forName(cn, true, loader)
  98.366 -                                   .newInstance());
  98.367 -                providers.put(cn, p);
  98.368 -                return p;
  98.369 -            } catch (ClassNotFoundException x) {
  98.370 -                fail(service,
  98.371 -                     "Provider " + cn + " not found");
  98.372 -            } catch (Throwable x) {
  98.373 -                fail(service,
  98.374 -                     "Provider " + cn + " could not be instantiated: " + x,
  98.375 -                     x);
  98.376 -            }
  98.377 -            throw new Error();          // This cannot happen
  98.378 -        }
  98.379 -
  98.380 -        public void remove() {
  98.381 -            throw new UnsupportedOperationException();
  98.382 -        }
  98.383 -
  98.384 -    }
  98.385 -
  98.386 -    /**
  98.387 -     * Lazily loads the available providers of this loader's service.
  98.388 -     *
  98.389 -     * <p> The iterator returned by this method first yields all of the
  98.390 -     * elements of the provider cache, in instantiation order.  It then lazily
  98.391 -     * loads and instantiates any remaining providers, adding each one to the
  98.392 -     * cache in turn.
  98.393 -     *
  98.394 -     * <p> To achieve laziness the actual work of parsing the available
  98.395 -     * provider-configuration files and instantiating providers must be done by
  98.396 -     * the iterator itself.  Its {@link java.util.Iterator#hasNext hasNext} and
  98.397 -     * {@link java.util.Iterator#next next} methods can therefore throw a
  98.398 -     * {@link ServiceConfigurationError} if a provider-configuration file
  98.399 -     * violates the specified format, or if it names a provider class that
  98.400 -     * cannot be found and instantiated, or if the result of instantiating the
  98.401 -     * class is not assignable to the service type, or if any other kind of
  98.402 -     * exception or error is thrown as the next provider is located and
  98.403 -     * instantiated.  To write robust code it is only necessary to catch {@link
  98.404 -     * ServiceConfigurationError} when using a service iterator.
  98.405 -     *
  98.406 -     * <p> If such an error is thrown then subsequent invocations of the
  98.407 -     * iterator will make a best effort to locate and instantiate the next
  98.408 -     * available provider, but in general such recovery cannot be guaranteed.
  98.409 -     *
  98.410 -     * <blockquote style="font-size: smaller; line-height: 1.2"><span
  98.411 -     * style="padding-right: 1em; font-weight: bold">Design Note</span>
  98.412 -     * Throwing an error in these cases may seem extreme.  The rationale for
  98.413 -     * this behavior is that a malformed provider-configuration file, like a
  98.414 -     * malformed class file, indicates a serious problem with the way the Java
  98.415 -     * virtual machine is configured or is being used.  As such it is
  98.416 -     * preferable to throw an error rather than try to recover or, even worse,
  98.417 -     * fail silently.</blockquote>
  98.418 -     *
  98.419 -     * <p> The iterator returned by this method does not support removal.
  98.420 -     * Invoking its {@link java.util.Iterator#remove() remove} method will
  98.421 -     * cause an {@link UnsupportedOperationException} to be thrown.
  98.422 -     *
  98.423 -     * @return  An iterator that lazily loads providers for this loader's
  98.424 -     *          service
  98.425 -     */
  98.426 -    public Iterator<S> iterator() {
  98.427 -        return new Iterator<S>() {
  98.428 -
  98.429 -            Iterator<Map.Entry<String,S>> knownProviders
  98.430 -                = providers.entrySet().iterator();
  98.431 -
  98.432 -            public boolean hasNext() {
  98.433 -                if (knownProviders.hasNext())
  98.434 -                    return true;
  98.435 -                return lookupIterator.hasNext();
  98.436 -            }
  98.437 -
  98.438 -            public S next() {
  98.439 -                if (knownProviders.hasNext())
  98.440 -                    return knownProviders.next().getValue();
  98.441 -                return lookupIterator.next();
  98.442 -            }
  98.443 -
  98.444 -            public void remove() {
  98.445 -                throw new UnsupportedOperationException();
  98.446 -            }
  98.447 -
  98.448 -        };
  98.449 -    }
  98.450 -
  98.451 -    /**
  98.452 -     * Creates a new service loader for the given service type and class
  98.453 -     * loader.
  98.454 -     *
  98.455 -     * @param  service
  98.456 -     *         The interface or abstract class representing the service
  98.457 -     *
  98.458 -     * @param  loader
  98.459 -     *         The class loader to be used to load provider-configuration files
  98.460 -     *         and provider classes, or <tt>null</tt> if the system class
  98.461 -     *         loader (or, failing that, the bootstrap class loader) is to be
  98.462 -     *         used
  98.463 -     *
  98.464 -     * @return A new service loader
  98.465 -     */
  98.466 -    public static <S> ServiceLoader<S> load(Class<S> service,
  98.467 -                                            ClassLoader loader)
  98.468 -    {
  98.469 -        return new ServiceLoader<>(service, loader);
  98.470 -    }
  98.471 -
  98.472 -    /**
  98.473 -     * Creates a new service loader for the given service type, using the
  98.474 -     * current thread's {@linkplain java.lang.Thread#getContextClassLoader
  98.475 -     * context class loader}.
  98.476 -     *
  98.477 -     * <p> An invocation of this convenience method of the form
  98.478 -     *
  98.479 -     * <blockquote><pre>
  98.480 -     * ServiceLoader.load(<i>service</i>)</pre></blockquote>
  98.481 -     *
  98.482 -     * is equivalent to
  98.483 -     *
  98.484 -     * <blockquote><pre>
  98.485 -     * ServiceLoader.load(<i>service</i>,
  98.486 -     *                    Thread.currentThread().getContextClassLoader())</pre></blockquote>
  98.487 -     *
  98.488 -     * @param  service
  98.489 -     *         The interface or abstract class representing the service
  98.490 -     *
  98.491 -     * @return A new service loader
  98.492 -     */
  98.493 -    public static <S> ServiceLoader<S> load(Class<S> service) {
  98.494 -        ClassLoader cl = null; // XXX: Thread.currentThread().getContextClassLoader();
  98.495 -        return ServiceLoader.load(service, cl);
  98.496 -    }
  98.497 -
  98.498 -    /**
  98.499 -     * Creates a new service loader for the given service type, using the
  98.500 -     * extension class loader.
  98.501 -     *
  98.502 -     * <p> This convenience method simply locates the extension class loader,
  98.503 -     * call it <tt><i>extClassLoader</i></tt>, and then returns
  98.504 -     *
  98.505 -     * <blockquote><pre>
  98.506 -     * ServiceLoader.load(<i>service</i>, <i>extClassLoader</i>)</pre></blockquote>
  98.507 -     *
  98.508 -     * <p> If the extension class loader cannot be found then the system class
  98.509 -     * loader is used; if there is no system class loader then the bootstrap
  98.510 -     * class loader is used.
  98.511 -     *
  98.512 -     * <p> This method is intended for use when only installed providers are
  98.513 -     * desired.  The resulting service will only find and load providers that
  98.514 -     * have been installed into the current Java virtual machine; providers on
  98.515 -     * the application's class path will be ignored.
  98.516 -     *
  98.517 -     * @param  service
  98.518 -     *         The interface or abstract class representing the service
  98.519 -     *
  98.520 -     * @return A new service loader
  98.521 -     */
  98.522 -    public static <S> ServiceLoader<S> loadInstalled(Class<S> service) {
  98.523 -        ClassLoader cl = ClassLoader.getSystemClassLoader();
  98.524 -        ClassLoader prev = null;
  98.525 -        while (cl != null) {
  98.526 -            prev = cl;
  98.527 -            cl = cl.getParent();
  98.528 -        }
  98.529 -        return ServiceLoader.load(service, prev);
  98.530 -    }
  98.531 -
  98.532 -    /**
  98.533 -     * Returns a string describing this service.
  98.534 -     *
  98.535 -     * @return  A descriptive string
  98.536 -     */
  98.537 -    public String toString() {
  98.538 -        return "java.util.ServiceLoader[" + service.getName() + "]";
  98.539 -    }
  98.540 -
  98.541 -}
    99.1 --- a/emul/compact/src/main/java/java/util/Set.java	Mon Feb 25 19:00:08 2013 +0100
    99.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.3 @@ -1,385 +0,0 @@
    99.4 -/*
    99.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
    99.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    99.7 - *
    99.8 - * This code is free software; you can redistribute it and/or modify it
    99.9 - * under the terms of the GNU General Public License version 2 only, as
   99.10 - * published by the Free Software Foundation.  Oracle designates this
   99.11 - * particular file as subject to the "Classpath" exception as provided
   99.12 - * by Oracle in the LICENSE file that accompanied this code.
   99.13 - *
   99.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   99.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   99.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   99.17 - * version 2 for more details (a copy is included in the LICENSE file that
   99.18 - * accompanied this code).
   99.19 - *
   99.20 - * You should have received a copy of the GNU General Public License version
   99.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   99.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   99.23 - *
   99.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   99.25 - * or visit www.oracle.com if you need additional information or have any
   99.26 - * questions.
   99.27 - */
   99.28 -
   99.29 -package java.util;
   99.30 -
   99.31 -/**
   99.32 - * A collection that contains no duplicate elements.  More formally, sets
   99.33 - * contain no pair of elements <code>e1</code> and <code>e2</code> such that
   99.34 - * <code>e1.equals(e2)</code>, and at most one null element.  As implied by
   99.35 - * its name, this interface models the mathematical <i>set</i> abstraction.
   99.36 - *
   99.37 - * <p>The <tt>Set</tt> interface places additional stipulations, beyond those
   99.38 - * inherited from the <tt>Collection</tt> interface, on the contracts of all
   99.39 - * constructors and on the contracts of the <tt>add</tt>, <tt>equals</tt> and
   99.40 - * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
   99.41 - * also included here for convenience.  (The specifications accompanying these
   99.42 - * declarations have been tailored to the <tt>Set</tt> interface, but they do
   99.43 - * not contain any additional stipulations.)
   99.44 - *
   99.45 - * <p>The additional stipulation on constructors is, not surprisingly,
   99.46 - * that all constructors must create a set that contains no duplicate elements
   99.47 - * (as defined above).
   99.48 - *
   99.49 - * <p>Note: Great care must be exercised if mutable objects are used as set
   99.50 - * elements.  The behavior of a set is not specified if the value of an object
   99.51 - * is changed in a manner that affects <tt>equals</tt> comparisons while the
   99.52 - * object is an element in the set.  A special case of this prohibition is
   99.53 - * that it is not permissible for a set to contain itself as an element.
   99.54 - *
   99.55 - * <p>Some set implementations have restrictions on the elements that
   99.56 - * they may contain.  For example, some implementations prohibit null elements,
   99.57 - * and some have restrictions on the types of their elements.  Attempting to
   99.58 - * add an ineligible element throws an unchecked exception, typically
   99.59 - * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
   99.60 - * to query the presence of an ineligible element may throw an exception,
   99.61 - * or it may simply return false; some implementations will exhibit the former
   99.62 - * behavior and some will exhibit the latter.  More generally, attempting an
   99.63 - * operation on an ineligible element whose completion would not result in
   99.64 - * the insertion of an ineligible element into the set may throw an
   99.65 - * exception or it may succeed, at the option of the implementation.
   99.66 - * Such exceptions are marked as "optional" in the specification for this
   99.67 - * interface.
   99.68 - *
   99.69 - * <p>This interface is a member of the
   99.70 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
   99.71 - * Java Collections Framework</a>.
   99.72 - *
   99.73 - * @param <E> the type of elements maintained by this set
   99.74 - *
   99.75 - * @author  Josh Bloch
   99.76 - * @author  Neal Gafter
   99.77 - * @see Collection
   99.78 - * @see List
   99.79 - * @see SortedSet
   99.80 - * @see HashSet
   99.81 - * @see TreeSet
   99.82 - * @see AbstractSet
   99.83 - * @see Collections#singleton(java.lang.Object)
   99.84 - * @see Collections#EMPTY_SET
   99.85 - * @since 1.2
   99.86 - */
   99.87 -
   99.88 -public interface Set<E> extends Collection<E> {
   99.89 -    // Query Operations
   99.90 -
   99.91 -    /**
   99.92 -     * Returns the number of elements in this set (its cardinality).  If this
   99.93 -     * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
   99.94 -     * <tt>Integer.MAX_VALUE</tt>.
   99.95 -     *
   99.96 -     * @return the number of elements in this set (its cardinality)
   99.97 -     */
   99.98 -    int size();
   99.99 -
  99.100 -    /**
  99.101 -     * Returns <tt>true</tt> if this set contains no elements.
  99.102 -     *
  99.103 -     * @return <tt>true</tt> if this set contains no elements
  99.104 -     */
  99.105 -    boolean isEmpty();
  99.106 -
  99.107 -    /**
  99.108 -     * Returns <tt>true</tt> if this set contains the specified element.
  99.109 -     * More formally, returns <tt>true</tt> if and only if this set
  99.110 -     * contains an element <tt>e</tt> such that
  99.111 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
  99.112 -     *
  99.113 -     * @param o element whose presence in this set is to be tested
  99.114 -     * @return <tt>true</tt> if this set contains the specified element
  99.115 -     * @throws ClassCastException if the type of the specified element
  99.116 -     *         is incompatible with this set
  99.117 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.118 -     * @throws NullPointerException if the specified element is null and this
  99.119 -     *         set does not permit null elements
  99.120 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.121 -     */
  99.122 -    boolean contains(Object o);
  99.123 -
  99.124 -    /**
  99.125 -     * Returns an iterator over the elements in this set.  The elements are
  99.126 -     * returned in no particular order (unless this set is an instance of some
  99.127 -     * class that provides a guarantee).
  99.128 -     *
  99.129 -     * @return an iterator over the elements in this set
  99.130 -     */
  99.131 -    Iterator<E> iterator();
  99.132 -
  99.133 -    /**
  99.134 -     * Returns an array containing all of the elements in this set.
  99.135 -     * If this set makes any guarantees as to what order its elements
  99.136 -     * are returned by its iterator, this method must return the
  99.137 -     * elements in the same order.
  99.138 -     *
  99.139 -     * <p>The returned array will be "safe" in that no references to it
  99.140 -     * are maintained by this set.  (In other words, this method must
  99.141 -     * allocate a new array even if this set is backed by an array).
  99.142 -     * The caller is thus free to modify the returned array.
  99.143 -     *
  99.144 -     * <p>This method acts as bridge between array-based and collection-based
  99.145 -     * APIs.
  99.146 -     *
  99.147 -     * @return an array containing all the elements in this set
  99.148 -     */
  99.149 -    Object[] toArray();
  99.150 -
  99.151 -    /**
  99.152 -     * Returns an array containing all of the elements in this set; the
  99.153 -     * runtime type of the returned array is that of the specified array.
  99.154 -     * If the set fits in the specified array, it is returned therein.
  99.155 -     * Otherwise, a new array is allocated with the runtime type of the
  99.156 -     * specified array and the size of this set.
  99.157 -     *
  99.158 -     * <p>If this set fits in the specified array with room to spare
  99.159 -     * (i.e., the array has more elements than this set), the element in
  99.160 -     * the array immediately following the end of the set is set to
  99.161 -     * <tt>null</tt>.  (This is useful in determining the length of this
  99.162 -     * set <i>only</i> if the caller knows that this set does not contain
  99.163 -     * any null elements.)
  99.164 -     *
  99.165 -     * <p>If this set makes any guarantees as to what order its elements
  99.166 -     * are returned by its iterator, this method must return the elements
  99.167 -     * in the same order.
  99.168 -     *
  99.169 -     * <p>Like the {@link #toArray()} method, this method acts as bridge between
  99.170 -     * array-based and collection-based APIs.  Further, this method allows
  99.171 -     * precise control over the runtime type of the output array, and may,
  99.172 -     * under certain circumstances, be used to save allocation costs.
  99.173 -     *
  99.174 -     * <p>Suppose <tt>x</tt> is a set known to contain only strings.
  99.175 -     * The following code can be used to dump the set into a newly allocated
  99.176 -     * array of <tt>String</tt>:
  99.177 -     *
  99.178 -     * <pre>
  99.179 -     *     String[] y = x.toArray(new String[0]);</pre>
  99.180 -     *
  99.181 -     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
  99.182 -     * <tt>toArray()</tt>.
  99.183 -     *
  99.184 -     * @param a the array into which the elements of this set are to be
  99.185 -     *        stored, if it is big enough; otherwise, a new array of the same
  99.186 -     *        runtime type is allocated for this purpose.
  99.187 -     * @return an array containing all the elements in this set
  99.188 -     * @throws ArrayStoreException if the runtime type of the specified array
  99.189 -     *         is not a supertype of the runtime type of every element in this
  99.190 -     *         set
  99.191 -     * @throws NullPointerException if the specified array is null
  99.192 -     */
  99.193 -    <T> T[] toArray(T[] a);
  99.194 -
  99.195 -
  99.196 -    // Modification Operations
  99.197 -
  99.198 -    /**
  99.199 -     * Adds the specified element to this set if it is not already present
  99.200 -     * (optional operation).  More formally, adds the specified element
  99.201 -     * <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
  99.202 -     * such that
  99.203 -     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
  99.204 -     * If this set already contains the element, the call leaves the set
  99.205 -     * unchanged and returns <tt>false</tt>.  In combination with the
  99.206 -     * restriction on constructors, this ensures that sets never contain
  99.207 -     * duplicate elements.
  99.208 -     *
  99.209 -     * <p>The stipulation above does not imply that sets must accept all
  99.210 -     * elements; sets may refuse to add any particular element, including
  99.211 -     * <tt>null</tt>, and throw an exception, as described in the
  99.212 -     * specification for {@link Collection#add Collection.add}.
  99.213 -     * Individual set implementations should clearly document any
  99.214 -     * restrictions on the elements that they may contain.
  99.215 -     *
  99.216 -     * @param e element to be added to this set
  99.217 -     * @return <tt>true</tt> if this set did not already contain the specified
  99.218 -     *         element
  99.219 -     * @throws UnsupportedOperationException if the <tt>add</tt> operation
  99.220 -     *         is not supported by this set
  99.221 -     * @throws ClassCastException if the class of the specified element
  99.222 -     *         prevents it from being added to this set
  99.223 -     * @throws NullPointerException if the specified element is null and this
  99.224 -     *         set does not permit null elements
  99.225 -     * @throws IllegalArgumentException if some property of the specified element
  99.226 -     *         prevents it from being added to this set
  99.227 -     */
  99.228 -    boolean add(E e);
  99.229 -
  99.230 -
  99.231 -    /**
  99.232 -     * Removes the specified element from this set if it is present
  99.233 -     * (optional operation).  More formally, removes an element <tt>e</tt>
  99.234 -     * such that
  99.235 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
  99.236 -     * this set contains such an element.  Returns <tt>true</tt> if this set
  99.237 -     * contained the element (or equivalently, if this set changed as a
  99.238 -     * result of the call).  (This set will not contain the element once the
  99.239 -     * call returns.)
  99.240 -     *
  99.241 -     * @param o object to be removed from this set, if present
  99.242 -     * @return <tt>true</tt> if this set contained the specified element
  99.243 -     * @throws ClassCastException if the type of the specified element
  99.244 -     *         is incompatible with this set
  99.245 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.246 -     * @throws NullPointerException if the specified element is null and this
  99.247 -     *         set does not permit null elements
  99.248 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.249 -     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
  99.250 -     *         is not supported by this set
  99.251 -     */
  99.252 -    boolean remove(Object o);
  99.253 -
  99.254 -
  99.255 -    // Bulk Operations
  99.256 -
  99.257 -    /**
  99.258 -     * Returns <tt>true</tt> if this set contains all of the elements of the
  99.259 -     * specified collection.  If the specified collection is also a set, this
  99.260 -     * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
  99.261 -     *
  99.262 -     * @param  c collection to be checked for containment in this set
  99.263 -     * @return <tt>true</tt> if this set contains all of the elements of the
  99.264 -     *         specified collection
  99.265 -     * @throws ClassCastException if the types of one or more elements
  99.266 -     *         in the specified collection are incompatible with this
  99.267 -     *         set
  99.268 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.269 -     * @throws NullPointerException if the specified collection contains one
  99.270 -     *         or more null elements and this set does not permit null
  99.271 -     *         elements
  99.272 -     * (<a href="Collection.html#optional-restrictions">optional</a>),
  99.273 -     *         or if the specified collection is null
  99.274 -     * @see    #contains(Object)
  99.275 -     */
  99.276 -    boolean containsAll(Collection<?> c);
  99.277 -
  99.278 -    /**
  99.279 -     * Adds all of the elements in the specified collection to this set if
  99.280 -     * they're not already present (optional operation).  If the specified
  99.281 -     * collection is also a set, the <tt>addAll</tt> operation effectively
  99.282 -     * modifies this set so that its value is the <i>union</i> of the two
  99.283 -     * sets.  The behavior of this operation is undefined if the specified
  99.284 -     * collection is modified while the operation is in progress.
  99.285 -     *
  99.286 -     * @param  c collection containing elements to be added to this set
  99.287 -     * @return <tt>true</tt> if this set changed as a result of the call
  99.288 -     *
  99.289 -     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
  99.290 -     *         is not supported by this set
  99.291 -     * @throws ClassCastException if the class of an element of the
  99.292 -     *         specified collection prevents it from being added to this set
  99.293 -     * @throws NullPointerException if the specified collection contains one
  99.294 -     *         or more null elements and this set does not permit null
  99.295 -     *         elements, or if the specified collection is null
  99.296 -     * @throws IllegalArgumentException if some property of an element of the
  99.297 -     *         specified collection prevents it from being added to this set
  99.298 -     * @see #add(Object)
  99.299 -     */
  99.300 -    boolean addAll(Collection<? extends E> c);
  99.301 -
  99.302 -    /**
  99.303 -     * Retains only the elements in this set that are contained in the
  99.304 -     * specified collection (optional operation).  In other words, removes
  99.305 -     * from this set all of its elements that are not contained in the
  99.306 -     * specified collection.  If the specified collection is also a set, this
  99.307 -     * operation effectively modifies this set so that its value is the
  99.308 -     * <i>intersection</i> of the two sets.
  99.309 -     *
  99.310 -     * @param  c collection containing elements to be retained in this set
  99.311 -     * @return <tt>true</tt> if this set changed as a result of the call
  99.312 -     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
  99.313 -     *         is not supported by this set
  99.314 -     * @throws ClassCastException if the class of an element of this set
  99.315 -     *         is incompatible with the specified collection
  99.316 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.317 -     * @throws NullPointerException if this set contains a null element and the
  99.318 -     *         specified collection does not permit null elements
  99.319 -     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  99.320 -     *         or if the specified collection is null
  99.321 -     * @see #remove(Object)
  99.322 -     */
  99.323 -    boolean retainAll(Collection<?> c);
  99.324 -
  99.325 -    /**
  99.326 -     * Removes from this set all of its elements that are contained in the
  99.327 -     * specified collection (optional operation).  If the specified
  99.328 -     * collection is also a set, this operation effectively modifies this
  99.329 -     * set so that its value is the <i>asymmetric set difference</i> of
  99.330 -     * the two sets.
  99.331 -     *
  99.332 -     * @param  c collection containing elements to be removed from this set
  99.333 -     * @return <tt>true</tt> if this set changed as a result of the call
  99.334 -     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
  99.335 -     *         is not supported by this set
  99.336 -     * @throws ClassCastException if the class of an element of this set
  99.337 -     *         is incompatible with the specified collection
  99.338 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
  99.339 -     * @throws NullPointerException if this set contains a null element and the
  99.340 -     *         specified collection does not permit null elements
  99.341 -     *         (<a href="Collection.html#optional-restrictions">optional</a>),
  99.342 -     *         or if the specified collection is null
  99.343 -     * @see #remove(Object)
  99.344 -     * @see #contains(Object)
  99.345 -     */
  99.346 -    boolean removeAll(Collection<?> c);
  99.347 -
  99.348 -    /**
  99.349 -     * Removes all of the elements from this set (optional operation).
  99.350 -     * The set will be empty after this call returns.
  99.351 -     *
  99.352 -     * @throws UnsupportedOperationException if the <tt>clear</tt> method
  99.353 -     *         is not supported by this set
  99.354 -     */
  99.355 -    void clear();
  99.356 -
  99.357 -
  99.358 -    // Comparison and hashing
  99.359 -
  99.360 -    /**
  99.361 -     * Compares the specified object with this set for equality.  Returns
  99.362 -     * <tt>true</tt> if the specified object is also a set, the two sets
  99.363 -     * have the same size, and every member of the specified set is
  99.364 -     * contained in this set (or equivalently, every member of this set is
  99.365 -     * contained in the specified set).  This definition ensures that the
  99.366 -     * equals method works properly across different implementations of the
  99.367 -     * set interface.
  99.368 -     *
  99.369 -     * @param o object to be compared for equality with this set
  99.370 -     * @return <tt>true</tt> if the specified object is equal to this set
  99.371 -     */
  99.372 -    boolean equals(Object o);
  99.373 -
  99.374 -    /**
  99.375 -     * Returns the hash code value for this set.  The hash code of a set is
  99.376 -     * defined to be the sum of the hash codes of the elements in the set,
  99.377 -     * where the hash code of a <tt>null</tt> element is defined to be zero.
  99.378 -     * This ensures that <tt>s1.equals(s2)</tt> implies that
  99.379 -     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
  99.380 -     * and <tt>s2</tt>, as required by the general contract of
  99.381 -     * {@link Object#hashCode}.
  99.382 -     *
  99.383 -     * @return the hash code value for this set
  99.384 -     * @see Object#equals(Object)
  99.385 -     * @see Set#equals(Object)
  99.386 -     */
  99.387 -    int hashCode();
  99.388 -}
   100.1 --- a/emul/compact/src/main/java/java/util/SortedMap.java	Mon Feb 25 19:00:08 2013 +0100
   100.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.3 @@ -1,284 +0,0 @@
   100.4 -/*
   100.5 - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
   100.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   100.7 - *
   100.8 - * This code is free software; you can redistribute it and/or modify it
   100.9 - * under the terms of the GNU General Public License version 2 only, as
  100.10 - * published by the Free Software Foundation.  Oracle designates this
  100.11 - * particular file as subject to the "Classpath" exception as provided
  100.12 - * by Oracle in the LICENSE file that accompanied this code.
  100.13 - *
  100.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  100.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  100.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  100.17 - * version 2 for more details (a copy is included in the LICENSE file that
  100.18 - * accompanied this code).
  100.19 - *
  100.20 - * You should have received a copy of the GNU General Public License version
  100.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  100.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  100.23 - *
  100.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  100.25 - * or visit www.oracle.com if you need additional information or have any
  100.26 - * questions.
  100.27 - */
  100.28 -
  100.29 -package java.util;
  100.30 -
  100.31 -/**
  100.32 - * A {@link Map} that further provides a <em>total ordering</em> on its keys.
  100.33 - * The map is ordered according to the {@linkplain Comparable natural
  100.34 - * ordering} of its keys, or by a {@link Comparator} typically
  100.35 - * provided at sorted map creation time.  This order is reflected when
  100.36 - * iterating over the sorted map's collection views (returned by the
  100.37 - * {@code entrySet}, {@code keySet} and {@code values} methods).
  100.38 - * Several additional operations are provided to take advantage of the
  100.39 - * ordering.  (This interface is the map analogue of {@link SortedSet}.)
  100.40 - *
  100.41 - * <p>All keys inserted into a sorted map must implement the {@code Comparable}
  100.42 - * interface (or be accepted by the specified comparator).  Furthermore, all
  100.43 - * such keys must be <em>mutually comparable</em>: {@code k1.compareTo(k2)} (or
  100.44 - * {@code comparator.compare(k1, k2)}) must not throw a
  100.45 - * {@code ClassCastException} for any keys {@code k1} and {@code k2} in
  100.46 - * the sorted map.  Attempts to violate this restriction will cause the
  100.47 - * offending method or constructor invocation to throw a
  100.48 - * {@code ClassCastException}.
  100.49 - *
  100.50 - * <p>Note that the ordering maintained by a sorted map (whether or not an
  100.51 - * explicit comparator is provided) must be <em>consistent with equals</em> if
  100.52 - * the sorted map is to correctly implement the {@code Map} interface.  (See
  100.53 - * the {@code Comparable} interface or {@code Comparator} interface for a
  100.54 - * precise definition of <em>consistent with equals</em>.)  This is so because
  100.55 - * the {@code Map} interface is defined in terms of the {@code equals}
  100.56 - * operation, but a sorted map performs all key comparisons using its
  100.57 - * {@code compareTo} (or {@code compare}) method, so two keys that are
  100.58 - * deemed equal by this method are, from the standpoint of the sorted map,
  100.59 - * equal.  The behavior of a tree map <em>is</em> well-defined even if its
  100.60 - * ordering is inconsistent with equals; it just fails to obey the general
  100.61 - * contract of the {@code Map} interface.
  100.62 - *
  100.63 - * <p>All general-purpose sorted map implementation classes should provide four
  100.64 - * "standard" constructors. It is not possible to enforce this recommendation
  100.65 - * though as required constructors cannot be specified by interfaces. The
  100.66 - * expected "standard" constructors for all sorted map implementations are:
  100.67 - * <ol>
  100.68 - *   <li>A void (no arguments) constructor, which creates an empty sorted map
  100.69 - *   sorted according to the natural ordering of its keys.</li>
  100.70 - *   <li>A constructor with a single argument of type {@code Comparator}, which
  100.71 - *   creates an empty sorted map sorted according to the specified comparator.</li>
  100.72 - *   <li>A constructor with a single argument of type {@code Map}, which creates
  100.73 - *   a new map with the same key-value mappings as its argument, sorted
  100.74 - *   according to the keys' natural ordering.</li>
  100.75 - *   <li>A constructor with a single argument of type {@code SortedMap}, which
  100.76 - *   creates a new sorted map with the same key-value mappings and the same
  100.77 - *   ordering as the input sorted map.</li>
  100.78 - * </ol>
  100.79 - *
  100.80 - * <p><strong>Note</strong>: several methods return submaps with restricted key
  100.81 - * ranges. Such ranges are <em>half-open</em>, that is, they include their low
  100.82 - * endpoint but not their high endpoint (where applicable).  If you need a
  100.83 - * <em>closed range</em> (which includes both endpoints), and the key type
  100.84 - * allows for calculation of the successor of a given key, merely request
  100.85 - * the subrange from {@code lowEndpoint} to
  100.86 - * {@code successor(highEndpoint)}.  For example, suppose that {@code m}
  100.87 - * is a map whose keys are strings.  The following idiom obtains a view
  100.88 - * containing all of the key-value mappings in {@code m} whose keys are
  100.89 - * between {@code low} and {@code high}, inclusive:<pre>
  100.90 - *   SortedMap&lt;String, V&gt; sub = m.subMap(low, high+"\0");</pre>
  100.91 - *
  100.92 - * A similar technique can be used to generate an <em>open range</em>
  100.93 - * (which contains neither endpoint).  The following idiom obtains a
  100.94 - * view containing all of the key-value mappings in {@code m} whose keys
  100.95 - * are between {@code low} and {@code high}, exclusive:<pre>
  100.96 - *   SortedMap&lt;String, V&gt; sub = m.subMap(low+"\0", high);</pre>
  100.97 - *
  100.98 - * <p>This interface is a member of the
  100.99 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 100.100 - * Java Collections Framework</a>.
 100.101 - *
 100.102 - * @param <K> the type of keys maintained by this map
 100.103 - * @param <V> the type of mapped values
 100.104 - *
 100.105 - * @author  Josh Bloch
 100.106 - * @see Map
 100.107 - * @see TreeMap
 100.108 - * @see SortedSet
 100.109 - * @see Comparator
 100.110 - * @see Comparable
 100.111 - * @see Collection
 100.112 - * @see ClassCastException
 100.113 - * @since 1.2
 100.114 - */
 100.115 -
 100.116 -public interface SortedMap<K,V> extends Map<K,V> {
 100.117 -    /**
 100.118 -     * Returns the comparator used to order the keys in this map, or
 100.119 -     * {@code null} if this map uses the {@linkplain Comparable
 100.120 -     * natural ordering} of its keys.
 100.121 -     *
 100.122 -     * @return the comparator used to order the keys in this map,
 100.123 -     *         or {@code null} if this map uses the natural ordering
 100.124 -     *         of its keys
 100.125 -     */
 100.126 -    Comparator<? super K> comparator();
 100.127 -
 100.128 -    /**
 100.129 -     * Returns a view of the portion of this map whose keys range from
 100.130 -     * {@code fromKey}, inclusive, to {@code toKey}, exclusive.  (If
 100.131 -     * {@code fromKey} and {@code toKey} are equal, the returned map
 100.132 -     * is empty.)  The returned map is backed by this map, so changes
 100.133 -     * in the returned map are reflected in this map, and vice-versa.
 100.134 -     * The returned map supports all optional map operations that this
 100.135 -     * map supports.
 100.136 -     *
 100.137 -     * <p>The returned map will throw an {@code IllegalArgumentException}
 100.138 -     * on an attempt to insert a key outside its range.
 100.139 -     *
 100.140 -     * @param fromKey low endpoint (inclusive) of the keys in the returned map
 100.141 -     * @param toKey high endpoint (exclusive) of the keys in the returned map
 100.142 -     * @return a view of the portion of this map whose keys range from
 100.143 -     *         {@code fromKey}, inclusive, to {@code toKey}, exclusive
 100.144 -     * @throws ClassCastException if {@code fromKey} and {@code toKey}
 100.145 -     *         cannot be compared to one another using this map's comparator
 100.146 -     *         (or, if the map has no comparator, using natural ordering).
 100.147 -     *         Implementations may, but are not required to, throw this
 100.148 -     *         exception if {@code fromKey} or {@code toKey}
 100.149 -     *         cannot be compared to keys currently in the map.
 100.150 -     * @throws NullPointerException if {@code fromKey} or {@code toKey}
 100.151 -     *         is null and this map does not permit null keys
 100.152 -     * @throws IllegalArgumentException if {@code fromKey} is greater than
 100.153 -     *         {@code toKey}; or if this map itself has a restricted
 100.154 -     *         range, and {@code fromKey} or {@code toKey} lies
 100.155 -     *         outside the bounds of the range
 100.156 -     */
 100.157 -    SortedMap<K,V> subMap(K fromKey, K toKey);
 100.158 -
 100.159 -    /**
 100.160 -     * Returns a view of the portion of this map whose keys are
 100.161 -     * strictly less than {@code toKey}.  The returned map is backed
 100.162 -     * by this map, so changes in the returned map are reflected in
 100.163 -     * this map, and vice-versa.  The returned map supports all
 100.164 -     * optional map operations that this map supports.
 100.165 -     *
 100.166 -     * <p>The returned map will throw an {@code IllegalArgumentException}
 100.167 -     * on an attempt to insert a key outside its range.
 100.168 -     *
 100.169 -     * @param toKey high endpoint (exclusive) of the keys in the returned map
 100.170 -     * @return a view of the portion of this map whose keys are strictly
 100.171 -     *         less than {@code toKey}
 100.172 -     * @throws ClassCastException if {@code toKey} is not compatible
 100.173 -     *         with this map's comparator (or, if the map has no comparator,
 100.174 -     *         if {@code toKey} does not implement {@link Comparable}).
 100.175 -     *         Implementations may, but are not required to, throw this
 100.176 -     *         exception if {@code toKey} cannot be compared to keys
 100.177 -     *         currently in the map.
 100.178 -     * @throws NullPointerException if {@code toKey} is null and
 100.179 -     *         this map does not permit null keys
 100.180 -     * @throws IllegalArgumentException if this map itself has a
 100.181 -     *         restricted range, and {@code toKey} lies outside the
 100.182 -     *         bounds of the range
 100.183 -     */
 100.184 -    SortedMap<K,V> headMap(K toKey);
 100.185 -
 100.186 -    /**
 100.187 -     * Returns a view of the portion of this map whose keys are
 100.188 -     * greater than or equal to {@code fromKey}.  The returned map is
 100.189 -     * backed by this map, so changes in the returned map are
 100.190 -     * reflected in this map, and vice-versa.  The returned map
 100.191 -     * supports all optional map operations that this map supports.
 100.192 -     *
 100.193 -     * <p>The returned map will throw an {@code IllegalArgumentException}
 100.194 -     * on an attempt to insert a key outside its range.
 100.195 -     *
 100.196 -     * @param fromKey low endpoint (inclusive) of the keys in the returned map
 100.197 -     * @return a view of the portion of this map whose keys are greater
 100.198 -     *         than or equal to {@code fromKey}
 100.199 -     * @throws ClassCastException if {@code fromKey} is not compatible
 100.200 -     *         with this map's comparator (or, if the map has no comparator,
 100.201 -     *         if {@code fromKey} does not implement {@link Comparable}).
 100.202 -     *         Implementations may, but are not required to, throw this
 100.203 -     *         exception if {@code fromKey} cannot be compared to keys
 100.204 -     *         currently in the map.
 100.205 -     * @throws NullPointerException if {@code fromKey} is null and
 100.206 -     *         this map does not permit null keys
 100.207 -     * @throws IllegalArgumentException if this map itself has a
 100.208 -     *         restricted range, and {@code fromKey} lies outside the
 100.209 -     *         bounds of the range
 100.210 -     */
 100.211 -    SortedMap<K,V> tailMap(K fromKey);
 100.212 -
 100.213 -    /**
 100.214 -     * Returns the first (lowest) key currently in this map.
 100.215 -     *
 100.216 -     * @return the first (lowest) key currently in this map
 100.217 -     * @throws NoSuchElementException if this map is empty
 100.218 -     */
 100.219 -    K firstKey();
 100.220 -
 100.221 -    /**
 100.222 -     * Returns the last (highest) key currently in this map.
 100.223 -     *
 100.224 -     * @return the last (highest) key currently in this map
 100.225 -     * @throws NoSuchElementException if this map is empty
 100.226 -     */
 100.227 -    K lastKey();
 100.228 -
 100.229 -    /**
 100.230 -     * Returns a {@link Set} view of the keys contained in this map.
 100.231 -     * The set's iterator returns the keys in ascending order.
 100.232 -     * The set is backed by the map, so changes to the map are
 100.233 -     * reflected in the set, and vice-versa.  If the map is modified
 100.234 -     * while an iteration over the set is in progress (except through
 100.235 -     * the iterator's own {@code remove} operation), the results of
 100.236 -     * the iteration are undefined.  The set supports element removal,
 100.237 -     * which removes the corresponding mapping from the map, via the
 100.238 -     * {@code Iterator.remove}, {@code Set.remove},
 100.239 -     * {@code removeAll}, {@code retainAll}, and {@code clear}
 100.240 -     * operations.  It does not support the {@code add} or {@code addAll}
 100.241 -     * operations.
 100.242 -     *
 100.243 -     * @return a set view of the keys contained in this map, sorted in
 100.244 -     *         ascending order
 100.245 -     */
 100.246 -    Set<K> keySet();
 100.247 -
 100.248 -    /**
 100.249 -     * Returns a {@link Collection} view of the values contained in this map.
 100.250 -     * The collection's iterator returns the values in ascending order
 100.251 -     * of the corresponding keys.
 100.252 -     * The collection is backed by the map, so changes to the map are
 100.253 -     * reflected in the collection, and vice-versa.  If the map is
 100.254 -     * modified while an iteration over the collection is in progress
 100.255 -     * (except through the iterator's own {@code remove} operation),
 100.256 -     * the results of the iteration are undefined.  The collection
 100.257 -     * supports element removal, which removes the corresponding
 100.258 -     * mapping from the map, via the {@code Iterator.remove},
 100.259 -     * {@code Collection.remove}, {@code removeAll},
 100.260 -     * {@code retainAll} and {@code clear} operations.  It does not
 100.261 -     * support the {@code add} or {@code addAll} operations.
 100.262 -     *
 100.263 -     * @return a collection view of the values contained in this map,
 100.264 -     *         sorted in ascending key order
 100.265 -     */
 100.266 -    Collection<V> values();
 100.267 -
 100.268 -    /**
 100.269 -     * Returns a {@link Set} view of the mappings contained in this map.
 100.270 -     * The set's iterator returns the entries in ascending key order.
 100.271 -     * The set is backed by the map, so changes to the map are
 100.272 -     * reflected in the set, and vice-versa.  If the map is modified
 100.273 -     * while an iteration over the set is in progress (except through
 100.274 -     * the iterator's own {@code remove} operation, or through the
 100.275 -     * {@code setValue} operation on a map entry returned by the
 100.276 -     * iterator) the results of the iteration are undefined.  The set
 100.277 -     * supports element removal, which removes the corresponding
 100.278 -     * mapping from the map, via the {@code Iterator.remove},
 100.279 -     * {@code Set.remove}, {@code removeAll}, {@code retainAll} and
 100.280 -     * {@code clear} operations.  It does not support the
 100.281 -     * {@code add} or {@code addAll} operations.
 100.282 -     *
 100.283 -     * @return a set view of the mappings contained in this map,
 100.284 -     *         sorted in ascending key order
 100.285 -     */
 100.286 -    Set<Map.Entry<K, V>> entrySet();
 100.287 -}
   101.1 --- a/emul/compact/src/main/java/java/util/SortedSet.java	Mon Feb 25 19:00:08 2013 +0100
   101.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.3 @@ -1,222 +0,0 @@
   101.4 -/*
   101.5 - * Copyright (c) 1998, 2006, 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.util;
  101.30 -
  101.31 -/**
  101.32 - * A {@link Set} that further provides a <i>total ordering</i> on its elements.
  101.33 - * The elements are ordered using their {@linkplain Comparable natural
  101.34 - * ordering}, or by a {@link Comparator} typically provided at sorted
  101.35 - * set creation time.  The set's iterator will traverse the set in
  101.36 - * ascending element order. Several additional operations are provided
  101.37 - * to take advantage of the ordering.  (This interface is the set
  101.38 - * analogue of {@link SortedMap}.)
  101.39 - *
  101.40 - * <p>All elements inserted into a sorted set must implement the <tt>Comparable</tt>
  101.41 - * interface (or be accepted by the specified comparator).  Furthermore, all
  101.42 - * such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt>
  101.43 - * (or <tt>comparator.compare(e1, e2)</tt>) must not throw a
  101.44 - * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in
  101.45 - * the sorted set.  Attempts to violate this restriction will cause the
  101.46 - * offending method or constructor invocation to throw a
  101.47 - * <tt>ClassCastException</tt>.
  101.48 - *
  101.49 - * <p>Note that the ordering maintained by a sorted set (whether or not an
  101.50 - * explicit comparator is provided) must be <i>consistent with equals</i> if
  101.51 - * the sorted set is to correctly implement the <tt>Set</tt> interface.  (See
  101.52 - * the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a
  101.53 - * precise definition of <i>consistent with equals</i>.)  This is so because
  101.54 - * the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt>
  101.55 - * operation, but a sorted set performs all element comparisons using its
  101.56 - * <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are
  101.57 - * deemed equal by this method are, from the standpoint of the sorted set,
  101.58 - * equal.  The behavior of a sorted set <i>is</i> well-defined even if its
  101.59 - * ordering is inconsistent with equals; it just fails to obey the general
  101.60 - * contract of the <tt>Set</tt> interface.
  101.61 - *
  101.62 - * <p>All general-purpose sorted set implementation classes should
  101.63 - * provide four "standard" constructors: 1) A void (no arguments)
  101.64 - * constructor, which creates an empty sorted set sorted according to
  101.65 - * the natural ordering of its elements.  2) A constructor with a
  101.66 - * single argument of type <tt>Comparator</tt>, which creates an empty
  101.67 - * sorted set sorted according to the specified comparator.  3) A
  101.68 - * constructor with a single argument of type <tt>Collection</tt>,
  101.69 - * which creates a new sorted set with the same elements as its
  101.70 - * argument, sorted according to the natural ordering of the elements.
  101.71 - * 4) A constructor with a single argument of type <tt>SortedSet</tt>,
  101.72 - * which creates a new sorted set with the same elements and the same
  101.73 - * ordering as the input sorted set.  There is no way to enforce this
  101.74 - * recommendation, as interfaces cannot contain constructors.
  101.75 - *
  101.76 - * <p>Note: several methods return subsets with restricted ranges.
  101.77 - * Such ranges are <i>half-open</i>, that is, they include their low
  101.78 - * endpoint but not their high endpoint (where applicable).
  101.79 - * If you need a <i>closed range</i> (which includes both endpoints), and
  101.80 - * the element type allows for calculation of the successor of a given
  101.81 - * value, merely request the subrange from <tt>lowEndpoint</tt> to
  101.82 - * <tt>successor(highEndpoint)</tt>.  For example, suppose that <tt>s</tt>
  101.83 - * is a sorted set of strings.  The following idiom obtains a view
  101.84 - * containing all of the strings in <tt>s</tt> from <tt>low</tt> to
  101.85 - * <tt>high</tt>, inclusive:<pre>
  101.86 - *   SortedSet&lt;String&gt; sub = s.subSet(low, high+"\0");</pre>
  101.87 - *
  101.88 - * A similar technique can be used to generate an <i>open range</i> (which
  101.89 - * contains neither endpoint).  The following idiom obtains a view
  101.90 - * containing all of the Strings in <tt>s</tt> from <tt>low</tt> to
  101.91 - * <tt>high</tt>, exclusive:<pre>
  101.92 - *   SortedSet&lt;String&gt; sub = s.subSet(low+"\0", high);</pre>
  101.93 - *
  101.94 - * <p>This interface is a member of the
  101.95 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  101.96 - * Java Collections Framework</a>.
  101.97 - *
  101.98 - * @param <E> the type of elements maintained by this set
  101.99 - *
 101.100 - * @author  Josh Bloch
 101.101 - * @see Set
 101.102 - * @see TreeSet
 101.103 - * @see SortedMap
 101.104 - * @see Collection
 101.105 - * @see Comparable
 101.106 - * @see Comparator
 101.107 - * @see ClassCastException
 101.108 - * @since 1.2
 101.109 - */
 101.110 -
 101.111 -public interface SortedSet<E> extends Set<E> {
 101.112 -    /**
 101.113 -     * Returns the comparator used to order the elements in this set,
 101.114 -     * or <tt>null</tt> if this set uses the {@linkplain Comparable
 101.115 -     * natural ordering} of its elements.
 101.116 -     *
 101.117 -     * @return the comparator used to order the elements in this set,
 101.118 -     *         or <tt>null</tt> if this set uses the natural ordering
 101.119 -     *         of its elements
 101.120 -     */
 101.121 -    Comparator<? super E> comparator();
 101.122 -
 101.123 -    /**
 101.124 -     * Returns a view of the portion of this set whose elements range
 101.125 -     * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
 101.126 -     * exclusive.  (If <tt>fromElement</tt> and <tt>toElement</tt> are
 101.127 -     * equal, the returned set is empty.)  The returned set is backed
 101.128 -     * by this set, so changes in the returned set are reflected in
 101.129 -     * this set, and vice-versa.  The returned set supports all
 101.130 -     * optional set operations that this set supports.
 101.131 -     *
 101.132 -     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 101.133 -     * on an attempt to insert an element outside its range.
 101.134 -     *
 101.135 -     * @param fromElement low endpoint (inclusive) of the returned set
 101.136 -     * @param toElement high endpoint (exclusive) of the returned set
 101.137 -     * @return a view of the portion of this set whose elements range from
 101.138 -     *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
 101.139 -     * @throws ClassCastException if <tt>fromElement</tt> and
 101.140 -     *         <tt>toElement</tt> cannot be compared to one another using this
 101.141 -     *         set's comparator (or, if the set has no comparator, using
 101.142 -     *         natural ordering).  Implementations may, but are not required
 101.143 -     *         to, throw this exception if <tt>fromElement</tt> or
 101.144 -     *         <tt>toElement</tt> cannot be compared to elements currently in
 101.145 -     *         the set.
 101.146 -     * @throws NullPointerException if <tt>fromElement</tt> or
 101.147 -     *         <tt>toElement</tt> is null and this set does not permit null
 101.148 -     *         elements
 101.149 -     * @throws IllegalArgumentException if <tt>fromElement</tt> is
 101.150 -     *         greater than <tt>toElement</tt>; or if this set itself
 101.151 -     *         has a restricted range, and <tt>fromElement</tt> or
 101.152 -     *         <tt>toElement</tt> lies outside the bounds of the range
 101.153 -     */
 101.154 -    SortedSet<E> subSet(E fromElement, E toElement);
 101.155 -
 101.156 -    /**
 101.157 -     * Returns a view of the portion of this set whose elements are
 101.158 -     * strictly less than <tt>toElement</tt>.  The returned set is
 101.159 -     * backed by this set, so changes in the returned set are
 101.160 -     * reflected in this set, and vice-versa.  The returned set
 101.161 -     * supports all optional set operations that this set supports.
 101.162 -     *
 101.163 -     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 101.164 -     * on an attempt to insert an element outside its range.
 101.165 -     *
 101.166 -     * @param toElement high endpoint (exclusive) of the returned set
 101.167 -     * @return a view of the portion of this set whose elements are strictly
 101.168 -     *         less than <tt>toElement</tt>
 101.169 -     * @throws ClassCastException if <tt>toElement</tt> is not compatible
 101.170 -     *         with this set's comparator (or, if the set has no comparator,
 101.171 -     *         if <tt>toElement</tt> does not implement {@link Comparable}).
 101.172 -     *         Implementations may, but are not required to, throw this
 101.173 -     *         exception if <tt>toElement</tt> cannot be compared to elements
 101.174 -     *         currently in the set.
 101.175 -     * @throws NullPointerException if <tt>toElement</tt> is null and
 101.176 -     *         this set does not permit null elements
 101.177 -     * @throws IllegalArgumentException if this set itself has a
 101.178 -     *         restricted range, and <tt>toElement</tt> lies outside the
 101.179 -     *         bounds of the range
 101.180 -     */
 101.181 -    SortedSet<E> headSet(E toElement);
 101.182 -
 101.183 -    /**
 101.184 -     * Returns a view of the portion of this set whose elements are
 101.185 -     * greater than or equal to <tt>fromElement</tt>.  The returned
 101.186 -     * set is backed by this set, so changes in the returned set are
 101.187 -     * reflected in this set, and vice-versa.  The returned set
 101.188 -     * supports all optional set operations that this set supports.
 101.189 -     *
 101.190 -     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 101.191 -     * on an attempt to insert an element outside its range.
 101.192 -     *
 101.193 -     * @param fromElement low endpoint (inclusive) of the returned set
 101.194 -     * @return a view of the portion of this set whose elements are greater
 101.195 -     *         than or equal to <tt>fromElement</tt>
 101.196 -     * @throws ClassCastException if <tt>fromElement</tt> is not compatible
 101.197 -     *         with this set's comparator (or, if the set has no comparator,
 101.198 -     *         if <tt>fromElement</tt> does not implement {@link Comparable}).
 101.199 -     *         Implementations may, but are not required to, throw this
 101.200 -     *         exception if <tt>fromElement</tt> cannot be compared to elements
 101.201 -     *         currently in the set.
 101.202 -     * @throws NullPointerException if <tt>fromElement</tt> is null
 101.203 -     *         and this set does not permit null elements
 101.204 -     * @throws IllegalArgumentException if this set itself has a
 101.205 -     *         restricted range, and <tt>fromElement</tt> lies outside the
 101.206 -     *         bounds of the range
 101.207 -     */
 101.208 -    SortedSet<E> tailSet(E fromElement);
 101.209 -
 101.210 -    /**
 101.211 -     * Returns the first (lowest) element currently in this set.
 101.212 -     *
 101.213 -     * @return the first (lowest) element currently in this set
 101.214 -     * @throws NoSuchElementException if this set is empty
 101.215 -     */
 101.216 -    E first();
 101.217 -
 101.218 -    /**
 101.219 -     * Returns the last (highest) element currently in this set.
 101.220 -     *
 101.221 -     * @return the last (highest) element currently in this set
 101.222 -     * @throws NoSuchElementException if this set is empty
 101.223 -     */
 101.224 -    E last();
 101.225 -}
   102.1 --- a/emul/compact/src/main/java/java/util/Stack.java	Mon Feb 25 19:00:08 2013 +0100
   102.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.3 @@ -1,141 +0,0 @@
   102.4 -/*
   102.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   102.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   102.7 - *
   102.8 - * This code is free software; you can redistribute it and/or modify it
   102.9 - * under the terms of the GNU General Public License version 2 only, as
  102.10 - * published by the Free Software Foundation.  Oracle designates this
  102.11 - * particular file as subject to the "Classpath" exception as provided
  102.12 - * by Oracle in the LICENSE file that accompanied this code.
  102.13 - *
  102.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  102.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  102.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  102.17 - * version 2 for more details (a copy is included in the LICENSE file that
  102.18 - * accompanied this code).
  102.19 - *
  102.20 - * You should have received a copy of the GNU General Public License version
  102.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  102.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  102.23 - *
  102.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  102.25 - * or visit www.oracle.com if you need additional information or have any
  102.26 - * questions.
  102.27 - */
  102.28 -
  102.29 -package java.util;
  102.30 -
  102.31 -/**
  102.32 - * The <code>Stack</code> class represents a last-in-first-out
  102.33 - * (LIFO) stack of objects. It extends class <tt>Vector</tt> with five
  102.34 - * operations that allow a vector to be treated as a stack. The usual
  102.35 - * <tt>push</tt> and <tt>pop</tt> operations are provided, as well as a
  102.36 - * method to <tt>peek</tt> at the top item on the stack, a method to test
  102.37 - * for whether the stack is <tt>empty</tt>, and a method to <tt>search</tt>
  102.38 - * the stack for an item and discover how far it is from the top.
  102.39 - * <p>
  102.40 - * When a stack is first created, it contains no items.
  102.41 - *
  102.42 - * <p>A more complete and consistent set of LIFO stack operations is
  102.43 - * provided by the {@link Deque} interface and its implementations, which
  102.44 - * should be used in preference to this class.  For example:
  102.45 - * <pre>   {@code
  102.46 - *   Deque<Integer> stack = new ArrayDeque<Integer>();}</pre>
  102.47 - *
  102.48 - * @author  Jonathan Payne
  102.49 - * @since   JDK1.0
  102.50 - */
  102.51 -public
  102.52 -class Stack<E> extends Vector<E> {
  102.53 -    /**
  102.54 -     * Creates an empty Stack.
  102.55 -     */
  102.56 -    public Stack() {
  102.57 -    }
  102.58 -
  102.59 -    /**
  102.60 -     * Pushes an item onto the top of this stack. This has exactly
  102.61 -     * the same effect as:
  102.62 -     * <blockquote><pre>
  102.63 -     * addElement(item)</pre></blockquote>
  102.64 -     *
  102.65 -     * @param   item   the item to be pushed onto this stack.
  102.66 -     * @return  the <code>item</code> argument.
  102.67 -     * @see     java.util.Vector#addElement
  102.68 -     */
  102.69 -    public E push(E item) {
  102.70 -        addElement(item);
  102.71 -
  102.72 -        return item;
  102.73 -    }
  102.74 -
  102.75 -    /**
  102.76 -     * Removes the object at the top of this stack and returns that
  102.77 -     * object as the value of this function.
  102.78 -     *
  102.79 -     * @return  The object at the top of this stack (the last item
  102.80 -     *          of the <tt>Vector</tt> object).
  102.81 -     * @throws  EmptyStackException  if this stack is empty.
  102.82 -     */
  102.83 -    public synchronized E pop() {
  102.84 -        E       obj;
  102.85 -        int     len = size();
  102.86 -
  102.87 -        obj = peek();
  102.88 -        removeElementAt(len - 1);
  102.89 -
  102.90 -        return obj;
  102.91 -    }
  102.92 -
  102.93 -    /**
  102.94 -     * Looks at the object at the top of this stack without removing it
  102.95 -     * from the stack.
  102.96 -     *
  102.97 -     * @return  the object at the top of this stack (the last item
  102.98 -     *          of the <tt>Vector</tt> object).
  102.99 -     * @throws  EmptyStackException  if this stack is empty.
 102.100 -     */
 102.101 -    public synchronized E peek() {
 102.102 -        int     len = size();
 102.103 -
 102.104 -        if (len == 0)
 102.105 -            throw new EmptyStackException();
 102.106 -        return elementAt(len - 1);
 102.107 -    }
 102.108 -
 102.109 -    /**
 102.110 -     * Tests if this stack is empty.
 102.111 -     *
 102.112 -     * @return  <code>true</code> if and only if this stack contains
 102.113 -     *          no items; <code>false</code> otherwise.
 102.114 -     */
 102.115 -    public boolean empty() {
 102.116 -        return size() == 0;
 102.117 -    }
 102.118 -
 102.119 -    /**
 102.120 -     * Returns the 1-based position where an object is on this stack.
 102.121 -     * If the object <tt>o</tt> occurs as an item in this stack, this
 102.122 -     * method returns the distance from the top of the stack of the
 102.123 -     * occurrence nearest the top of the stack; the topmost item on the
 102.124 -     * stack is considered to be at distance <tt>1</tt>. The <tt>equals</tt>
 102.125 -     * method is used to compare <tt>o</tt> to the
 102.126 -     * items in this stack.
 102.127 -     *
 102.128 -     * @param   o   the desired object.
 102.129 -     * @return  the 1-based position from the top of the stack where
 102.130 -     *          the object is located; the return value <code>-1</code>
 102.131 -     *          indicates that the object is not on the stack.
 102.132 -     */
 102.133 -    public synchronized int search(Object o) {
 102.134 -        int i = lastIndexOf(o);
 102.135 -
 102.136 -        if (i >= 0) {
 102.137 -            return size() - i;
 102.138 -        }
 102.139 -        return -1;
 102.140 -    }
 102.141 -
 102.142 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 102.143 -    private static final long serialVersionUID = 1224463164541339165L;
 102.144 -}
   103.1 --- a/emul/compact/src/main/java/java/util/StringTokenizer.java	Mon Feb 25 19:00:08 2013 +0100
   103.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.3 @@ -1,431 +0,0 @@
   103.4 -/*
   103.5 - * Copyright (c) 1994, 2004, 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.util;
  103.30 -
  103.31 -import java.lang.*;
  103.32 -
  103.33 -/**
  103.34 - * The string tokenizer class allows an application to break a
  103.35 - * string into tokens. The tokenization method is much simpler than
  103.36 - * the one used by the <code>StreamTokenizer</code> class. The
  103.37 - * <code>StringTokenizer</code> methods do not distinguish among
  103.38 - * identifiers, numbers, and quoted strings, nor do they recognize
  103.39 - * and skip comments.
  103.40 - * <p>
  103.41 - * The set of delimiters (the characters that separate tokens) may
  103.42 - * be specified either at creation time or on a per-token basis.
  103.43 - * <p>
  103.44 - * An instance of <code>StringTokenizer</code> behaves in one of two
  103.45 - * ways, depending on whether it was created with the
  103.46 - * <code>returnDelims</code> flag having the value <code>true</code>
  103.47 - * or <code>false</code>:
  103.48 - * <ul>
  103.49 - * <li>If the flag is <code>false</code>, delimiter characters serve to
  103.50 - *     separate tokens. A token is a maximal sequence of consecutive
  103.51 - *     characters that are not delimiters.
  103.52 - * <li>If the flag is <code>true</code>, delimiter characters are themselves
  103.53 - *     considered to be tokens. A token is thus either one delimiter
  103.54 - *     character, or a maximal sequence of consecutive characters that are
  103.55 - *     not delimiters.
  103.56 - * </ul><p>
  103.57 - * A <tt>StringTokenizer</tt> object internally maintains a current
  103.58 - * position within the string to be tokenized. Some operations advance this
  103.59 - * current position past the characters processed.<p>
  103.60 - * A token is returned by taking a substring of the string that was used to
  103.61 - * create the <tt>StringTokenizer</tt> object.
  103.62 - * <p>
  103.63 - * The following is one example of the use of the tokenizer. The code:
  103.64 - * <blockquote><pre>
  103.65 - *     StringTokenizer st = new StringTokenizer("this is a test");
  103.66 - *     while (st.hasMoreTokens()) {
  103.67 - *         System.out.println(st.nextToken());
  103.68 - *     }
  103.69 - * </pre></blockquote>
  103.70 - * <p>
  103.71 - * prints the following output:
  103.72 - * <blockquote><pre>
  103.73 - *     this
  103.74 - *     is
  103.75 - *     a
  103.76 - *     test
  103.77 - * </pre></blockquote>
  103.78 - *
  103.79 - * <p>
  103.80 - * <tt>StringTokenizer</tt> is a legacy class that is retained for
  103.81 - * compatibility reasons although its use is discouraged in new code. It is
  103.82 - * recommended that anyone seeking this functionality use the <tt>split</tt>
  103.83 - * method of <tt>String</tt> or the java.util.regex package instead.
  103.84 - * <p>
  103.85 - * The following example illustrates how the <tt>String.split</tt>
  103.86 - * method can be used to break up a string into its basic tokens:
  103.87 - * <blockquote><pre>
  103.88 - *     String[] result = "this is a test".split("\\s");
  103.89 - *     for (int x=0; x&lt;result.length; x++)
  103.90 - *         System.out.println(result[x]);
  103.91 - * </pre></blockquote>
  103.92 - * <p>
  103.93 - * prints the following output:
  103.94 - * <blockquote><pre>
  103.95 - *     this
  103.96 - *     is
  103.97 - *     a
  103.98 - *     test
  103.99 - * </pre></blockquote>
 103.100 - *
 103.101 - * @author  unascribed
 103.102 - * @see     java.io.StreamTokenizer
 103.103 - * @since   JDK1.0
 103.104 - */
 103.105 -public
 103.106 -class StringTokenizer implements Enumeration<Object> {
 103.107 -    private int currentPosition;
 103.108 -    private int newPosition;
 103.109 -    private int maxPosition;
 103.110 -    private String str;
 103.111 -    private String delimiters;
 103.112 -    private boolean retDelims;
 103.113 -    private boolean delimsChanged;
 103.114 -
 103.115 -    /**
 103.116 -     * maxDelimCodePoint stores the value of the delimiter character with the
 103.117 -     * highest value. It is used to optimize the detection of delimiter
 103.118 -     * characters.
 103.119 -     *
 103.120 -     * It is unlikely to provide any optimization benefit in the
 103.121 -     * hasSurrogates case because most string characters will be
 103.122 -     * smaller than the limit, but we keep it so that the two code
 103.123 -     * paths remain similar.
 103.124 -     */
 103.125 -    private int maxDelimCodePoint;
 103.126 -
 103.127 -    /**
 103.128 -     * If delimiters include any surrogates (including surrogate
 103.129 -     * pairs), hasSurrogates is true and the tokenizer uses the
 103.130 -     * different code path. This is because String.indexOf(int)
 103.131 -     * doesn't handle unpaired surrogates as a single character.
 103.132 -     */
 103.133 -    private boolean hasSurrogates = false;
 103.134 -
 103.135 -    /**
 103.136 -     * When hasSurrogates is true, delimiters are converted to code
 103.137 -     * points and isDelimiter(int) is used to determine if the given
 103.138 -     * codepoint is a delimiter.
 103.139 -     */
 103.140 -    private int[] delimiterCodePoints;
 103.141 -
 103.142 -    /**
 103.143 -     * Set maxDelimCodePoint to the highest char in the delimiter set.
 103.144 -     */
 103.145 -    private void setMaxDelimCodePoint() {
 103.146 -        if (delimiters == null) {
 103.147 -            maxDelimCodePoint = 0;
 103.148 -            return;
 103.149 -        }
 103.150 -
 103.151 -        int m = 0;
 103.152 -        int c;
 103.153 -        int count = 0;
 103.154 -        for (int i = 0; i < delimiters.length(); i += Character.charCount(c)) {
 103.155 -            c = delimiters.charAt(i);
 103.156 -            if (c >= Character.MIN_HIGH_SURROGATE && c <= Character.MAX_LOW_SURROGATE) {
 103.157 -                c = delimiters.codePointAt(i);
 103.158 -                hasSurrogates = true;
 103.159 -            }
 103.160 -            if (m < c)
 103.161 -                m = c;
 103.162 -            count++;
 103.163 -        }
 103.164 -        maxDelimCodePoint = m;
 103.165 -
 103.166 -        if (hasSurrogates) {
 103.167 -            delimiterCodePoints = new int[count];
 103.168 -            for (int i = 0, j = 0; i < count; i++, j += Character.charCount(c)) {
 103.169 -                c = delimiters.codePointAt(j);
 103.170 -                delimiterCodePoints[i] = c;
 103.171 -            }
 103.172 -        }
 103.173 -    }
 103.174 -
 103.175 -    /**
 103.176 -     * Constructs a string tokenizer for the specified string. All
 103.177 -     * characters in the <code>delim</code> argument are the delimiters
 103.178 -     * for separating tokens.
 103.179 -     * <p>
 103.180 -     * If the <code>returnDelims</code> flag is <code>true</code>, then
 103.181 -     * the delimiter characters are also returned as tokens. Each
 103.182 -     * delimiter is returned as a string of length one. If the flag is
 103.183 -     * <code>false</code>, the delimiter characters are skipped and only
 103.184 -     * serve as separators between tokens.
 103.185 -     * <p>
 103.186 -     * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does
 103.187 -     * not throw an exception. However, trying to invoke other methods on the
 103.188 -     * resulting <tt>StringTokenizer</tt> may result in a
 103.189 -     * <tt>NullPointerException</tt>.
 103.190 -     *
 103.191 -     * @param   str            a string to be parsed.
 103.192 -     * @param   delim          the delimiters.
 103.193 -     * @param   returnDelims   flag indicating whether to return the delimiters
 103.194 -     *                         as tokens.
 103.195 -     * @exception NullPointerException if str is <CODE>null</CODE>
 103.196 -     */
 103.197 -    public StringTokenizer(String str, String delim, boolean returnDelims) {
 103.198 -        currentPosition = 0;
 103.199 -        newPosition = -1;
 103.200 -        delimsChanged = false;
 103.201 -        this.str = str;
 103.202 -        maxPosition = str.length();
 103.203 -        delimiters = delim;
 103.204 -        retDelims = returnDelims;
 103.205 -        setMaxDelimCodePoint();
 103.206 -    }
 103.207 -
 103.208 -    /**
 103.209 -     * Constructs a string tokenizer for the specified string. The
 103.210 -     * characters in the <code>delim</code> argument are the delimiters
 103.211 -     * for separating tokens. Delimiter characters themselves will not
 103.212 -     * be treated as tokens.
 103.213 -     * <p>
 103.214 -     * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does
 103.215 -     * not throw an exception. However, trying to invoke other methods on the
 103.216 -     * resulting <tt>StringTokenizer</tt> may result in a
 103.217 -     * <tt>NullPointerException</tt>.
 103.218 -     *
 103.219 -     * @param   str     a string to be parsed.
 103.220 -     * @param   delim   the delimiters.
 103.221 -     * @exception NullPointerException if str is <CODE>null</CODE>
 103.222 -     */
 103.223 -    public StringTokenizer(String str, String delim) {
 103.224 -        this(str, delim, false);
 103.225 -    }
 103.226 -
 103.227 -    /**
 103.228 -     * Constructs a string tokenizer for the specified string. The
 103.229 -     * tokenizer uses the default delimiter set, which is
 103.230 -     * <code>"&nbsp;&#92;t&#92;n&#92;r&#92;f"</code>: the space character,
 103.231 -     * the tab character, the newline character, the carriage-return character,
 103.232 -     * and the form-feed character. Delimiter characters themselves will
 103.233 -     * not be treated as tokens.
 103.234 -     *
 103.235 -     * @param   str   a string to be parsed.
 103.236 -     * @exception NullPointerException if str is <CODE>null</CODE>
 103.237 -     */
 103.238 -    public StringTokenizer(String str) {
 103.239 -        this(str, " \t\n\r\f", false);
 103.240 -    }
 103.241 -
 103.242 -    /**
 103.243 -     * Skips delimiters starting from the specified position. If retDelims
 103.244 -     * is false, returns the index of the first non-delimiter character at or
 103.245 -     * after startPos. If retDelims is true, startPos is returned.
 103.246 -     */
 103.247 -    private int skipDelimiters(int startPos) {
 103.248 -        if (delimiters == null)
 103.249 -            throw new NullPointerException();
 103.250 -
 103.251 -        int position = startPos;
 103.252 -        while (!retDelims && position < maxPosition) {
 103.253 -            if (!hasSurrogates) {
 103.254 -                char c = str.charAt(position);
 103.255 -                if ((c > maxDelimCodePoint) || (delimiters.indexOf(c) < 0))
 103.256 -                    break;
 103.257 -                position++;
 103.258 -            } else {
 103.259 -                int c = str.codePointAt(position);
 103.260 -                if ((c > maxDelimCodePoint) || !isDelimiter(c)) {
 103.261 -                    break;
 103.262 -                }
 103.263 -                position += Character.charCount(c);
 103.264 -            }
 103.265 -        }
 103.266 -        return position;
 103.267 -    }
 103.268 -
 103.269 -    /**
 103.270 -     * Skips ahead from startPos and returns the index of the next delimiter
 103.271 -     * character encountered, or maxPosition if no such delimiter is found.
 103.272 -     */
 103.273 -    private int scanToken(int startPos) {
 103.274 -        int position = startPos;
 103.275 -        while (position < maxPosition) {
 103.276 -            if (!hasSurrogates) {
 103.277 -                char c = str.charAt(position);
 103.278 -                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
 103.279 -                    break;
 103.280 -                position++;
 103.281 -            } else {
 103.282 -                int c = str.codePointAt(position);
 103.283 -                if ((c <= maxDelimCodePoint) && isDelimiter(c))
 103.284 -                    break;
 103.285 -                position += Character.charCount(c);
 103.286 -            }
 103.287 -        }
 103.288 -        if (retDelims && (startPos == position)) {
 103.289 -            if (!hasSurrogates) {
 103.290 -                char c = str.charAt(position);
 103.291 -                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
 103.292 -                    position++;
 103.293 -            } else {
 103.294 -                int c = str.codePointAt(position);
 103.295 -                if ((c <= maxDelimCodePoint) && isDelimiter(c))
 103.296 -                    position += Character.charCount(c);
 103.297 -            }
 103.298 -        }
 103.299 -        return position;
 103.300 -    }
 103.301 -
 103.302 -    private boolean isDelimiter(int codePoint) {
 103.303 -        for (int i = 0; i < delimiterCodePoints.length; i++) {
 103.304 -            if (delimiterCodePoints[i] == codePoint) {
 103.305 -                return true;
 103.306 -            }
 103.307 -        }
 103.308 -        return false;
 103.309 -    }
 103.310 -
 103.311 -    /**
 103.312 -     * Tests if there are more tokens available from this tokenizer's string.
 103.313 -     * If this method returns <tt>true</tt>, then a subsequent call to
 103.314 -     * <tt>nextToken</tt> with no argument will successfully return a token.
 103.315 -     *
 103.316 -     * @return  <code>true</code> if and only if there is at least one token
 103.317 -     *          in the string after the current position; <code>false</code>
 103.318 -     *          otherwise.
 103.319 -     */
 103.320 -    public boolean hasMoreTokens() {
 103.321 -        /*
 103.322 -         * Temporarily store this position and use it in the following
 103.323 -         * nextToken() method only if the delimiters haven't been changed in
 103.324 -         * that nextToken() invocation.
 103.325 -         */
 103.326 -        newPosition = skipDelimiters(currentPosition);
 103.327 -        return (newPosition < maxPosition);
 103.328 -    }
 103.329 -
 103.330 -    /**
 103.331 -     * Returns the next token from this string tokenizer.
 103.332 -     *
 103.333 -     * @return     the next token from this string tokenizer.
 103.334 -     * @exception  NoSuchElementException  if there are no more tokens in this
 103.335 -     *               tokenizer's string.
 103.336 -     */
 103.337 -    public String nextToken() {
 103.338 -        /*
 103.339 -         * If next position already computed in hasMoreElements() and
 103.340 -         * delimiters have changed between the computation and this invocation,
 103.341 -         * then use the computed value.
 103.342 -         */
 103.343 -
 103.344 -        currentPosition = (newPosition >= 0 && !delimsChanged) ?
 103.345 -            newPosition : skipDelimiters(currentPosition);
 103.346 -
 103.347 -        /* Reset these anyway */
 103.348 -        delimsChanged = false;
 103.349 -        newPosition = -1;
 103.350 -
 103.351 -        if (currentPosition >= maxPosition)
 103.352 -            throw new NoSuchElementException();
 103.353 -        int start = currentPosition;
 103.354 -        currentPosition = scanToken(currentPosition);
 103.355 -        return str.substring(start, currentPosition);
 103.356 -    }
 103.357 -
 103.358 -    /**
 103.359 -     * Returns the next token in this string tokenizer's string. First,
 103.360 -     * the set of characters considered to be delimiters by this
 103.361 -     * <tt>StringTokenizer</tt> object is changed to be the characters in
 103.362 -     * the string <tt>delim</tt>. Then the next token in the string
 103.363 -     * after the current position is returned. The current position is
 103.364 -     * advanced beyond the recognized token.  The new delimiter set
 103.365 -     * remains the default after this call.
 103.366 -     *
 103.367 -     * @param      delim   the new delimiters.
 103.368 -     * @return     the next token, after switching to the new delimiter set.
 103.369 -     * @exception  NoSuchElementException  if there are no more tokens in this
 103.370 -     *               tokenizer's string.
 103.371 -     * @exception NullPointerException if delim is <CODE>null</CODE>
 103.372 -     */
 103.373 -    public String nextToken(String delim) {
 103.374 -        delimiters = delim;
 103.375 -
 103.376 -        /* delimiter string specified, so set the appropriate flag. */
 103.377 -        delimsChanged = true;
 103.378 -
 103.379 -        setMaxDelimCodePoint();
 103.380 -        return nextToken();
 103.381 -    }
 103.382 -
 103.383 -    /**
 103.384 -     * Returns the same value as the <code>hasMoreTokens</code>
 103.385 -     * method. It exists so that this class can implement the
 103.386 -     * <code>Enumeration</code> interface.
 103.387 -     *
 103.388 -     * @return  <code>true</code> if there are more tokens;
 103.389 -     *          <code>false</code> otherwise.
 103.390 -     * @see     java.util.Enumeration
 103.391 -     * @see     java.util.StringTokenizer#hasMoreTokens()
 103.392 -     */
 103.393 -    public boolean hasMoreElements() {
 103.394 -        return hasMoreTokens();
 103.395 -    }
 103.396 -
 103.397 -    /**
 103.398 -     * Returns the same value as the <code>nextToken</code> method,
 103.399 -     * except that its declared return value is <code>Object</code> rather than
 103.400 -     * <code>String</code>. It exists so that this class can implement the
 103.401 -     * <code>Enumeration</code> interface.
 103.402 -     *
 103.403 -     * @return     the next token in the string.
 103.404 -     * @exception  NoSuchElementException  if there are no more tokens in this
 103.405 -     *               tokenizer's string.
 103.406 -     * @see        java.util.Enumeration
 103.407 -     * @see        java.util.StringTokenizer#nextToken()
 103.408 -     */
 103.409 -    public Object nextElement() {
 103.410 -        return nextToken();
 103.411 -    }
 103.412 -
 103.413 -    /**
 103.414 -     * Calculates the number of times that this tokenizer's
 103.415 -     * <code>nextToken</code> method can be called before it generates an
 103.416 -     * exception. The current position is not advanced.
 103.417 -     *
 103.418 -     * @return  the number of tokens remaining in the string using the current
 103.419 -     *          delimiter set.
 103.420 -     * @see     java.util.StringTokenizer#nextToken()
 103.421 -     */
 103.422 -    public int countTokens() {
 103.423 -        int count = 0;
 103.424 -        int currpos = currentPosition;
 103.425 -        while (currpos < maxPosition) {
 103.426 -            currpos = skipDelimiters(currpos);
 103.427 -            if (currpos >= maxPosition)
 103.428 -                break;
 103.429 -            currpos = scanToken(currpos);
 103.430 -            count++;
 103.431 -        }
 103.432 -        return count;
 103.433 -    }
 103.434 -}
   104.1 --- a/emul/compact/src/main/java/java/util/TimSort.java	Mon Feb 25 19:00:08 2013 +0100
   104.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.3 @@ -1,929 +0,0 @@
   104.4 -/*
   104.5 - * Copyright 2009 Google Inc.  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.util;
  104.30 -
  104.31 -
  104.32 -/**
  104.33 - * A stable, adaptive, iterative mergesort that requires far fewer than
  104.34 - * n lg(n) comparisons when running on partially sorted arrays, while
  104.35 - * offering performance comparable to a traditional mergesort when run
  104.36 - * on random arrays.  Like all proper mergesorts, this sort is stable and
  104.37 - * runs O(n log n) time (worst case).  In the worst case, this sort requires
  104.38 - * temporary storage space for n/2 object references; in the best case,
  104.39 - * it requires only a small constant amount of space.
  104.40 - *
  104.41 - * This implementation was adapted from Tim Peters's list sort for
  104.42 - * Python, which is described in detail here:
  104.43 - *
  104.44 - *   http://svn.python.org/projects/python/trunk/Objects/listsort.txt
  104.45 - *
  104.46 - * Tim's C code may be found here:
  104.47 - *
  104.48 - *   http://svn.python.org/projects/python/trunk/Objects/listobject.c
  104.49 - *
  104.50 - * The underlying techniques are described in this paper (and may have
  104.51 - * even earlier origins):
  104.52 - *
  104.53 - *  "Optimistic Sorting and Information Theoretic Complexity"
  104.54 - *  Peter McIlroy
  104.55 - *  SODA (Fourth Annual ACM-SIAM Symposium on Discrete Algorithms),
  104.56 - *  pp 467-474, Austin, Texas, 25-27 January 1993.
  104.57 - *
  104.58 - * While the API to this class consists solely of static methods, it is
  104.59 - * (privately) instantiable; a TimSort instance holds the state of an ongoing
  104.60 - * sort, assuming the input array is large enough to warrant the full-blown
  104.61 - * TimSort. Small arrays are sorted in place, using a binary insertion sort.
  104.62 - *
  104.63 - * @author Josh Bloch
  104.64 - */
  104.65 -class TimSort<T> {
  104.66 -    /**
  104.67 -     * This is the minimum sized sequence that will be merged.  Shorter
  104.68 -     * sequences will be lengthened by calling binarySort.  If the entire
  104.69 -     * array is less than this length, no merges will be performed.
  104.70 -     *
  104.71 -     * This constant should be a power of two.  It was 64 in Tim Peter's C
  104.72 -     * implementation, but 32 was empirically determined to work better in
  104.73 -     * this implementation.  In the unlikely event that you set this constant
  104.74 -     * to be a number that's not a power of two, you'll need to change the
  104.75 -     * {@link #minRunLength} computation.
  104.76 -     *
  104.77 -     * If you decrease this constant, you must change the stackLen
  104.78 -     * computation in the TimSort constructor, or you risk an
  104.79 -     * ArrayOutOfBounds exception.  See listsort.txt for a discussion
  104.80 -     * of the minimum stack length required as a function of the length
  104.81 -     * of the array being sorted and the minimum merge sequence length.
  104.82 -     */
  104.83 -    private static final int MIN_MERGE = 32;
  104.84 -
  104.85 -    /**
  104.86 -     * The array being sorted.
  104.87 -     */
  104.88 -    private final T[] a;
  104.89 -
  104.90 -    /**
  104.91 -     * The comparator for this sort.
  104.92 -     */
  104.93 -    private final Comparator<? super T> c;
  104.94 -
  104.95 -    /**
  104.96 -     * When we get into galloping mode, we stay there until both runs win less
  104.97 -     * often than MIN_GALLOP consecutive times.
  104.98 -     */
  104.99 -    private static final int  MIN_GALLOP = 7;
 104.100 -
 104.101 -    /**
 104.102 -     * This controls when we get *into* galloping mode.  It is initialized
 104.103 -     * to MIN_GALLOP.  The mergeLo and mergeHi methods nudge it higher for
 104.104 -     * random data, and lower for highly structured data.
 104.105 -     */
 104.106 -    private int minGallop = MIN_GALLOP;
 104.107 -
 104.108 -    /**
 104.109 -     * Maximum initial size of tmp array, which is used for merging.  The array
 104.110 -     * can grow to accommodate demand.
 104.111 -     *
 104.112 -     * Unlike Tim's original C version, we do not allocate this much storage
 104.113 -     * when sorting smaller arrays.  This change was required for performance.
 104.114 -     */
 104.115 -    private static final int INITIAL_TMP_STORAGE_LENGTH = 256;
 104.116 -
 104.117 -    /**
 104.118 -     * Temp storage for merges.
 104.119 -     */
 104.120 -    private T[] tmp; // Actual runtime type will be Object[], regardless of T
 104.121 -
 104.122 -    /**
 104.123 -     * A stack of pending runs yet to be merged.  Run i starts at
 104.124 -     * address base[i] and extends for len[i] elements.  It's always
 104.125 -     * true (so long as the indices are in bounds) that:
 104.126 -     *
 104.127 -     *     runBase[i] + runLen[i] == runBase[i + 1]
 104.128 -     *
 104.129 -     * so we could cut the storage for this, but it's a minor amount,
 104.130 -     * and keeping all the info explicit simplifies the code.
 104.131 -     */
 104.132 -    private int stackSize = 0;  // Number of pending runs on stack
 104.133 -    private final int[] runBase;
 104.134 -    private final int[] runLen;
 104.135 -
 104.136 -    /**
 104.137 -     * Creates a TimSort instance to maintain the state of an ongoing sort.
 104.138 -     *
 104.139 -     * @param a the array to be sorted
 104.140 -     * @param c the comparator to determine the order of the sort
 104.141 -     */
 104.142 -    private TimSort(T[] a, Comparator<? super T> c) {
 104.143 -        this.a = a;
 104.144 -        this.c = c;
 104.145 -
 104.146 -        // Allocate temp storage (which may be increased later if necessary)
 104.147 -        int len = a.length;
 104.148 -        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
 104.149 -        T[] newArray = (T[]) new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
 104.150 -                                        len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
 104.151 -        tmp = newArray;
 104.152 -
 104.153 -        /*
 104.154 -         * Allocate runs-to-be-merged stack (which cannot be expanded).  The
 104.155 -         * stack length requirements are described in listsort.txt.  The C
 104.156 -         * version always uses the same stack length (85), but this was
 104.157 -         * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
 104.158 -         * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
 104.159 -         * large) stack lengths for smaller arrays.  The "magic numbers" in the
 104.160 -         * computation below must be changed if MIN_MERGE is decreased.  See
 104.161 -         * the MIN_MERGE declaration above for more information.
 104.162 -         */
 104.163 -        int stackLen = (len <    120  ?  5 :
 104.164 -                        len <   1542  ? 10 :
 104.165 -                        len < 119151  ? 19 : 40);
 104.166 -        runBase = new int[stackLen];
 104.167 -        runLen = new int[stackLen];
 104.168 -    }
 104.169 -
 104.170 -    /*
 104.171 -     * The next two methods (which are package private and static) constitute
 104.172 -     * the entire API of this class.  Each of these methods obeys the contract
 104.173 -     * of the public method with the same signature in java.util.Arrays.
 104.174 -     */
 104.175 -
 104.176 -    static <T> void sort(T[] a, Comparator<? super T> c) {
 104.177 -        sort(a, 0, a.length, c);
 104.178 -    }
 104.179 -
 104.180 -    static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c) {
 104.181 -        if (c == null) {
 104.182 -            Arrays.sort(a, lo, hi);
 104.183 -            return;
 104.184 -        }
 104.185 -
 104.186 -        rangeCheck(a.length, lo, hi);
 104.187 -        int nRemaining  = hi - lo;
 104.188 -        if (nRemaining < 2)
 104.189 -            return;  // Arrays of size 0 and 1 are always sorted
 104.190 -
 104.191 -        // If array is small, do a "mini-TimSort" with no merges
 104.192 -        if (nRemaining < MIN_MERGE) {
 104.193 -            int initRunLen = countRunAndMakeAscending(a, lo, hi, c);
 104.194 -            binarySort(a, lo, hi, lo + initRunLen, c);
 104.195 -            return;
 104.196 -        }
 104.197 -
 104.198 -        /**
 104.199 -         * March over the array once, left to right, finding natural runs,
 104.200 -         * extending short natural runs to minRun elements, and merging runs
 104.201 -         * to maintain stack invariant.
 104.202 -         */
 104.203 -        TimSort<T> ts = new TimSort<>(a, c);
 104.204 -        int minRun = minRunLength(nRemaining);
 104.205 -        do {
 104.206 -            // Identify next run
 104.207 -            int runLen = countRunAndMakeAscending(a, lo, hi, c);
 104.208 -
 104.209 -            // If run is short, extend to min(minRun, nRemaining)
 104.210 -            if (runLen < minRun) {
 104.211 -                int force = nRemaining <= minRun ? nRemaining : minRun;
 104.212 -                binarySort(a, lo, lo + force, lo + runLen, c);
 104.213 -                runLen = force;
 104.214 -            }
 104.215 -
 104.216 -            // Push run onto pending-run stack, and maybe merge
 104.217 -            ts.pushRun(lo, runLen);
 104.218 -            ts.mergeCollapse();
 104.219 -
 104.220 -            // Advance to find next run
 104.221 -            lo += runLen;
 104.222 -            nRemaining -= runLen;
 104.223 -        } while (nRemaining != 0);
 104.224 -
 104.225 -        // Merge all remaining runs to complete sort
 104.226 -        assert lo == hi;
 104.227 -        ts.mergeForceCollapse();
 104.228 -        assert ts.stackSize == 1;
 104.229 -    }
 104.230 -
 104.231 -    /**
 104.232 -     * Sorts the specified portion of the specified array using a binary
 104.233 -     * insertion sort.  This is the best method for sorting small numbers
 104.234 -     * of elements.  It requires O(n log n) compares, but O(n^2) data
 104.235 -     * movement (worst case).
 104.236 -     *
 104.237 -     * If the initial part of the specified range is already sorted,
 104.238 -     * this method can take advantage of it: the method assumes that the
 104.239 -     * elements from index {@code lo}, inclusive, to {@code start},
 104.240 -     * exclusive are already sorted.
 104.241 -     *
 104.242 -     * @param a the array in which a range is to be sorted
 104.243 -     * @param lo the index of the first element in the range to be sorted
 104.244 -     * @param hi the index after the last element in the range to be sorted
 104.245 -     * @param start the index of the first element in the range that is
 104.246 -     *        not already known to be sorted ({@code lo <= start <= hi})
 104.247 -     * @param c comparator to used for the sort
 104.248 -     */
 104.249 -    @SuppressWarnings("fallthrough")
 104.250 -    private static <T> void binarySort(T[] a, int lo, int hi, int start,
 104.251 -                                       Comparator<? super T> c) {
 104.252 -        assert lo <= start && start <= hi;
 104.253 -        if (start == lo)
 104.254 -            start++;
 104.255 -        for ( ; start < hi; start++) {
 104.256 -            T pivot = a[start];
 104.257 -
 104.258 -            // Set left (and right) to the index where a[start] (pivot) belongs
 104.259 -            int left = lo;
 104.260 -            int right = start;
 104.261 -            assert left <= right;
 104.262 -            /*
 104.263 -             * Invariants:
 104.264 -             *   pivot >= all in [lo, left).
 104.265 -             *   pivot <  all in [right, start).
 104.266 -             */
 104.267 -            while (left < right) {
 104.268 -                int mid = (left + right) >>> 1;
 104.269 -                if (c.compare(pivot, a[mid]) < 0)
 104.270 -                    right = mid;
 104.271 -                else
 104.272 -                    left = mid + 1;
 104.273 -            }
 104.274 -            assert left == right;
 104.275 -
 104.276 -            /*
 104.277 -             * The invariants still hold: pivot >= all in [lo, left) and
 104.278 -             * pivot < all in [left, start), so pivot belongs at left.  Note
 104.279 -             * that if there are elements equal to pivot, left points to the
 104.280 -             * first slot after them -- that's why this sort is stable.
 104.281 -             * Slide elements over to make room for pivot.
 104.282 -             */
 104.283 -            int n = start - left;  // The number of elements to move
 104.284 -            // Switch is just an optimization for arraycopy in default case
 104.285 -            switch (n) {
 104.286 -                case 2:  a[left + 2] = a[left + 1];
 104.287 -                case 1:  a[left + 1] = a[left];
 104.288 -                         break;
 104.289 -                default: System.arraycopy(a, left, a, left + 1, n);
 104.290 -            }
 104.291 -            a[left] = pivot;
 104.292 -        }
 104.293 -    }
 104.294 -
 104.295 -    /**
 104.296 -     * Returns the length of the run beginning at the specified position in
 104.297 -     * the specified array and reverses the run if it is descending (ensuring
 104.298 -     * that the run will always be ascending when the method returns).
 104.299 -     *
 104.300 -     * A run is the longest ascending sequence with:
 104.301 -     *
 104.302 -     *    a[lo] <= a[lo + 1] <= a[lo + 2] <= ...
 104.303 -     *
 104.304 -     * or the longest descending sequence with:
 104.305 -     *
 104.306 -     *    a[lo] >  a[lo + 1] >  a[lo + 2] >  ...
 104.307 -     *
 104.308 -     * For its intended use in a stable mergesort, the strictness of the
 104.309 -     * definition of "descending" is needed so that the call can safely
 104.310 -     * reverse a descending sequence without violating stability.
 104.311 -     *
 104.312 -     * @param a the array in which a run is to be counted and possibly reversed
 104.313 -     * @param lo index of the first element in the run
 104.314 -     * @param hi index after the last element that may be contained in the run.
 104.315 -              It is required that {@code lo < hi}.
 104.316 -     * @param c the comparator to used for the sort
 104.317 -     * @return  the length of the run beginning at the specified position in
 104.318 -     *          the specified array
 104.319 -     */
 104.320 -    private static <T> int countRunAndMakeAscending(T[] a, int lo, int hi,
 104.321 -                                                    Comparator<? super T> c) {
 104.322 -        assert lo < hi;
 104.323 -        int runHi = lo + 1;
 104.324 -        if (runHi == hi)
 104.325 -            return 1;
 104.326 -
 104.327 -        // Find end of run, and reverse range if descending
 104.328 -        if (c.compare(a[runHi++], a[lo]) < 0) { // Descending
 104.329 -            while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0)
 104.330 -                runHi++;
 104.331 -            reverseRange(a, lo, runHi);
 104.332 -        } else {                              // Ascending
 104.333 -            while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) >= 0)
 104.334 -                runHi++;
 104.335 -        }
 104.336 -
 104.337 -        return runHi - lo;
 104.338 -    }
 104.339 -
 104.340 -    /**
 104.341 -     * Reverse the specified range of the specified array.
 104.342 -     *
 104.343 -     * @param a the array in which a range is to be reversed
 104.344 -     * @param lo the index of the first element in the range to be reversed
 104.345 -     * @param hi the index after the last element in the range to be reversed
 104.346 -     */
 104.347 -    private static void reverseRange(Object[] a, int lo, int hi) {
 104.348 -        hi--;
 104.349 -        while (lo < hi) {
 104.350 -            Object t = a[lo];
 104.351 -            a[lo++] = a[hi];
 104.352 -            a[hi--] = t;
 104.353 -        }
 104.354 -    }
 104.355 -
 104.356 -    /**
 104.357 -     * Returns the minimum acceptable run length for an array of the specified
 104.358 -     * length. Natural runs shorter than this will be extended with
 104.359 -     * {@link #binarySort}.
 104.360 -     *
 104.361 -     * Roughly speaking, the computation is:
 104.362 -     *
 104.363 -     *  If n < MIN_MERGE, return n (it's too small to bother with fancy stuff).
 104.364 -     *  Else if n is an exact power of 2, return MIN_MERGE/2.
 104.365 -     *  Else return an int k, MIN_MERGE/2 <= k <= MIN_MERGE, such that n/k
 104.366 -     *   is close to, but strictly less than, an exact power of 2.
 104.367 -     *
 104.368 -     * For the rationale, see listsort.txt.
 104.369 -     *
 104.370 -     * @param n the length of the array to be sorted
 104.371 -     * @return the length of the minimum run to be merged
 104.372 -     */
 104.373 -    private static int minRunLength(int n) {
 104.374 -        assert n >= 0;
 104.375 -        int r = 0;      // Becomes 1 if any 1 bits are shifted off
 104.376 -        while (n >= MIN_MERGE) {
 104.377 -            r |= (n & 1);
 104.378 -            n >>= 1;
 104.379 -        }
 104.380 -        return n + r;
 104.381 -    }
 104.382 -
 104.383 -    /**
 104.384 -     * Pushes the specified run onto the pending-run stack.
 104.385 -     *
 104.386 -     * @param runBase index of the first element in the run
 104.387 -     * @param runLen  the number of elements in the run
 104.388 -     */
 104.389 -    private void pushRun(int runBase, int runLen) {
 104.390 -        this.runBase[stackSize] = runBase;
 104.391 -        this.runLen[stackSize] = runLen;
 104.392 -        stackSize++;
 104.393 -    }
 104.394 -
 104.395 -    /**
 104.396 -     * Examines the stack of runs waiting to be merged and merges adjacent runs
 104.397 -     * until the stack invariants are reestablished:
 104.398 -     *
 104.399 -     *     1. runLen[i - 3] > runLen[i - 2] + runLen[i - 1]
 104.400 -     *     2. runLen[i - 2] > runLen[i - 1]
 104.401 -     *
 104.402 -     * This method is called each time a new run is pushed onto the stack,
 104.403 -     * so the invariants are guaranteed to hold for i < stackSize upon
 104.404 -     * entry to the method.
 104.405 -     */
 104.406 -    private void mergeCollapse() {
 104.407 -        while (stackSize > 1) {
 104.408 -            int n = stackSize - 2;
 104.409 -            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
 104.410 -                if (runLen[n - 1] < runLen[n + 1])
 104.411 -                    n--;
 104.412 -                mergeAt(n);
 104.413 -            } else if (runLen[n] <= runLen[n + 1]) {
 104.414 -                mergeAt(n);
 104.415 -            } else {
 104.416 -                break; // Invariant is established
 104.417 -            }
 104.418 -        }
 104.419 -    }
 104.420 -
 104.421 -    /**
 104.422 -     * Merges all runs on the stack until only one remains.  This method is
 104.423 -     * called once, to complete the sort.
 104.424 -     */
 104.425 -    private void mergeForceCollapse() {
 104.426 -        while (stackSize > 1) {
 104.427 -            int n = stackSize - 2;
 104.428 -            if (n > 0 && runLen[n - 1] < runLen[n + 1])
 104.429 -                n--;
 104.430 -            mergeAt(n);
 104.431 -        }
 104.432 -    }
 104.433 -
 104.434 -    /**
 104.435 -     * Merges the two runs at stack indices i and i+1.  Run i must be
 104.436 -     * the penultimate or antepenultimate run on the stack.  In other words,
 104.437 -     * i must be equal to stackSize-2 or stackSize-3.
 104.438 -     *
 104.439 -     * @param i stack index of the first of the two runs to merge
 104.440 -     */
 104.441 -    private void mergeAt(int i) {
 104.442 -        assert stackSize >= 2;
 104.443 -        assert i >= 0;
 104.444 -        assert i == stackSize - 2 || i == stackSize - 3;
 104.445 -
 104.446 -        int base1 = runBase[i];
 104.447 -        int len1 = runLen[i];
 104.448 -        int base2 = runBase[i + 1];
 104.449 -        int len2 = runLen[i + 1];
 104.450 -        assert len1 > 0 && len2 > 0;
 104.451 -        assert base1 + len1 == base2;
 104.452 -
 104.453 -        /*
 104.454 -         * Record the length of the combined runs; if i is the 3rd-last
 104.455 -         * run now, also slide over the last run (which isn't involved
 104.456 -         * in this merge).  The current run (i+1) goes away in any case.
 104.457 -         */
 104.458 -        runLen[i] = len1 + len2;
 104.459 -        if (i == stackSize - 3) {
 104.460 -            runBase[i + 1] = runBase[i + 2];
 104.461 -            runLen[i + 1] = runLen[i + 2];
 104.462 -        }
 104.463 -        stackSize--;
 104.464 -
 104.465 -        /*
 104.466 -         * Find where the first element of run2 goes in run1. Prior elements
 104.467 -         * in run1 can be ignored (because they're already in place).
 104.468 -         */
 104.469 -        int k = gallopRight(a[base2], a, base1, len1, 0, c);
 104.470 -        assert k >= 0;
 104.471 -        base1 += k;
 104.472 -        len1 -= k;
 104.473 -        if (len1 == 0)
 104.474 -            return;
 104.475 -
 104.476 -        /*
 104.477 -         * Find where the last element of run1 goes in run2. Subsequent elements
 104.478 -         * in run2 can be ignored (because they're already in place).
 104.479 -         */
 104.480 -        len2 = gallopLeft(a[base1 + len1 - 1], a, base2, len2, len2 - 1, c);
 104.481 -        assert len2 >= 0;
 104.482 -        if (len2 == 0)
 104.483 -            return;
 104.484 -
 104.485 -        // Merge remaining runs, using tmp array with min(len1, len2) elements
 104.486 -        if (len1 <= len2)
 104.487 -            mergeLo(base1, len1, base2, len2);
 104.488 -        else
 104.489 -            mergeHi(base1, len1, base2, len2);
 104.490 -    }
 104.491 -
 104.492 -    /**
 104.493 -     * Locates the position at which to insert the specified key into the
 104.494 -     * specified sorted range; if the range contains an element equal to key,
 104.495 -     * returns the index of the leftmost equal element.
 104.496 -     *
 104.497 -     * @param key the key whose insertion point to search for
 104.498 -     * @param a the array in which to search
 104.499 -     * @param base the index of the first element in the range
 104.500 -     * @param len the length of the range; must be > 0
 104.501 -     * @param hint the index at which to begin the search, 0 <= hint < n.
 104.502 -     *     The closer hint is to the result, the faster this method will run.
 104.503 -     * @param c the comparator used to order the range, and to search
 104.504 -     * @return the int k,  0 <= k <= n such that a[b + k - 1] < key <= a[b + k],
 104.505 -     *    pretending that a[b - 1] is minus infinity and a[b + n] is infinity.
 104.506 -     *    In other words, key belongs at index b + k; or in other words,
 104.507 -     *    the first k elements of a should precede key, and the last n - k
 104.508 -     *    should follow it.
 104.509 -     */
 104.510 -    private static <T> int gallopLeft(T key, T[] a, int base, int len, int hint,
 104.511 -                                      Comparator<? super T> c) {
 104.512 -        assert len > 0 && hint >= 0 && hint < len;
 104.513 -        int lastOfs = 0;
 104.514 -        int ofs = 1;
 104.515 -        if (c.compare(key, a[base + hint]) > 0) {
 104.516 -            // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs]
 104.517 -            int maxOfs = len - hint;
 104.518 -            while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) > 0) {
 104.519 -                lastOfs = ofs;
 104.520 -                ofs = (ofs << 1) + 1;
 104.521 -                if (ofs <= 0)   // int overflow
 104.522 -                    ofs = maxOfs;
 104.523 -            }
 104.524 -            if (ofs > maxOfs)
 104.525 -                ofs = maxOfs;
 104.526 -
 104.527 -            // Make offsets relative to base
 104.528 -            lastOfs += hint;
 104.529 -            ofs += hint;
 104.530 -        } else { // key <= a[base + hint]
 104.531 -            // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs]
 104.532 -            final int maxOfs = hint + 1;
 104.533 -            while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) <= 0) {
 104.534 -                lastOfs = ofs;
 104.535 -                ofs = (ofs << 1) + 1;
 104.536 -                if (ofs <= 0)   // int overflow
 104.537 -                    ofs = maxOfs;
 104.538 -            }
 104.539 -            if (ofs > maxOfs)
 104.540 -                ofs = maxOfs;
 104.541 -
 104.542 -            // Make offsets relative to base
 104.543 -            int tmp = lastOfs;
 104.544 -            lastOfs = hint - ofs;
 104.545 -            ofs = hint - tmp;
 104.546 -        }
 104.547 -        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
 104.548 -
 104.549 -        /*
 104.550 -         * Now a[base+lastOfs] < key <= a[base+ofs], so key belongs somewhere
 104.551 -         * to the right of lastOfs but no farther right than ofs.  Do a binary
 104.552 -         * search, with invariant a[base + lastOfs - 1] < key <= a[base + ofs].
 104.553 -         */
 104.554 -        lastOfs++;
 104.555 -        while (lastOfs < ofs) {
 104.556 -            int m = lastOfs + ((ofs - lastOfs) >>> 1);
 104.557 -
 104.558 -            if (c.compare(key, a[base + m]) > 0)
 104.559 -                lastOfs = m + 1;  // a[base + m] < key
 104.560 -            else
 104.561 -                ofs = m;          // key <= a[base + m]
 104.562 -        }
 104.563 -        assert lastOfs == ofs;    // so a[base + ofs - 1] < key <= a[base + ofs]
 104.564 -        return ofs;
 104.565 -    }
 104.566 -
 104.567 -    /**
 104.568 -     * Like gallopLeft, except that if the range contains an element equal to
 104.569 -     * key, gallopRight returns the index after the rightmost equal element.
 104.570 -     *
 104.571 -     * @param key the key whose insertion point to search for
 104.572 -     * @param a the array in which to search
 104.573 -     * @param base the index of the first element in the range
 104.574 -     * @param len the length of the range; must be > 0
 104.575 -     * @param hint the index at which to begin the search, 0 <= hint < n.
 104.576 -     *     The closer hint is to the result, the faster this method will run.
 104.577 -     * @param c the comparator used to order the range, and to search
 104.578 -     * @return the int k,  0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
 104.579 -     */
 104.580 -    private static <T> int gallopRight(T key, T[] a, int base, int len,
 104.581 -                                       int hint, Comparator<? super T> c) {
 104.582 -        assert len > 0 && hint >= 0 && hint < len;
 104.583 -
 104.584 -        int ofs = 1;
 104.585 -        int lastOfs = 0;
 104.586 -        if (c.compare(key, a[base + hint]) < 0) {
 104.587 -            // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs]
 104.588 -            int maxOfs = hint + 1;
 104.589 -            while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) < 0) {
 104.590 -                lastOfs = ofs;
 104.591 -                ofs = (ofs << 1) + 1;
 104.592 -                if (ofs <= 0)   // int overflow
 104.593 -                    ofs = maxOfs;
 104.594 -            }
 104.595 -            if (ofs > maxOfs)
 104.596 -                ofs = maxOfs;
 104.597 -
 104.598 -            // Make offsets relative to b
 104.599 -            int tmp = lastOfs;
 104.600 -            lastOfs = hint - ofs;
 104.601 -            ofs = hint - tmp;
 104.602 -        } else { // a[b + hint] <= key
 104.603 -            // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs]
 104.604 -            int maxOfs = len - hint;
 104.605 -            while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) >= 0) {
 104.606 -                lastOfs = ofs;
 104.607 -                ofs = (ofs << 1) + 1;
 104.608 -                if (ofs <= 0)   // int overflow
 104.609 -                    ofs = maxOfs;
 104.610 -            }
 104.611 -            if (ofs > maxOfs)
 104.612 -                ofs = maxOfs;
 104.613 -
 104.614 -            // Make offsets relative to b
 104.615 -            lastOfs += hint;
 104.616 -            ofs += hint;
 104.617 -        }
 104.618 -        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
 104.619 -
 104.620 -        /*
 104.621 -         * Now a[b + lastOfs] <= key < a[b + ofs], so key belongs somewhere to
 104.622 -         * the right of lastOfs but no farther right than ofs.  Do a binary
 104.623 -         * search, with invariant a[b + lastOfs - 1] <= key < a[b + ofs].
 104.624 -         */
 104.625 -        lastOfs++;
 104.626 -        while (lastOfs < ofs) {
 104.627 -            int m = lastOfs + ((ofs - lastOfs) >>> 1);
 104.628 -
 104.629 -            if (c.compare(key, a[base + m]) < 0)
 104.630 -                ofs = m;          // key < a[b + m]
 104.631 -            else
 104.632 -                lastOfs = m + 1;  // a[b + m] <= key
 104.633 -        }
 104.634 -        assert lastOfs == ofs;    // so a[b + ofs - 1] <= key < a[b + ofs]
 104.635 -        return ofs;
 104.636 -    }
 104.637 -
 104.638 -    /**
 104.639 -     * Merges two adjacent runs in place, in a stable fashion.  The first
 104.640 -     * element of the first run must be greater than the first element of the
 104.641 -     * second run (a[base1] > a[base2]), and the last element of the first run
 104.642 -     * (a[base1 + len1-1]) must be greater than all elements of the second run.
 104.643 -     *
 104.644 -     * For performance, this method should be called only when len1 <= len2;
 104.645 -     * its twin, mergeHi should be called if len1 >= len2.  (Either method
 104.646 -     * may be called if len1 == len2.)
 104.647 -     *
 104.648 -     * @param base1 index of first element in first run to be merged
 104.649 -     * @param len1  length of first run to be merged (must be > 0)
 104.650 -     * @param base2 index of first element in second run to be merged
 104.651 -     *        (must be aBase + aLen)
 104.652 -     * @param len2  length of second run to be merged (must be > 0)
 104.653 -     */
 104.654 -    private void mergeLo(int base1, int len1, int base2, int len2) {
 104.655 -        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
 104.656 -
 104.657 -        // Copy first run into temp array
 104.658 -        T[] a = this.a; // For performance
 104.659 -        T[] tmp = ensureCapacity(len1);
 104.660 -        System.arraycopy(a, base1, tmp, 0, len1);
 104.661 -
 104.662 -        int cursor1 = 0;       // Indexes into tmp array
 104.663 -        int cursor2 = base2;   // Indexes int a
 104.664 -        int dest = base1;      // Indexes int a
 104.665 -
 104.666 -        // Move first element of second run and deal with degenerate cases
 104.667 -        a[dest++] = a[cursor2++];
 104.668 -        if (--len2 == 0) {
 104.669 -            System.arraycopy(tmp, cursor1, a, dest, len1);
 104.670 -            return;
 104.671 -        }
 104.672 -        if (len1 == 1) {
 104.673 -            System.arraycopy(a, cursor2, a, dest, len2);
 104.674 -            a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
 104.675 -            return;
 104.676 -        }
 104.677 -
 104.678 -        Comparator<? super T> c = this.c;  // Use local variable for performance
 104.679 -        int minGallop = this.minGallop;    //  "    "       "     "      "
 104.680 -    outer:
 104.681 -        while (true) {
 104.682 -            int count1 = 0; // Number of times in a row that first run won
 104.683 -            int count2 = 0; // Number of times in a row that second run won
 104.684 -
 104.685 -            /*
 104.686 -             * Do the straightforward thing until (if ever) one run starts
 104.687 -             * winning consistently.
 104.688 -             */
 104.689 -            do {
 104.690 -                assert len1 > 1 && len2 > 0;
 104.691 -                if (c.compare(a[cursor2], tmp[cursor1]) < 0) {
 104.692 -                    a[dest++] = a[cursor2++];
 104.693 -                    count2++;
 104.694 -                    count1 = 0;
 104.695 -                    if (--len2 == 0)
 104.696 -                        break outer;
 104.697 -                } else {
 104.698 -                    a[dest++] = tmp[cursor1++];
 104.699 -                    count1++;
 104.700 -                    count2 = 0;
 104.701 -                    if (--len1 == 1)
 104.702 -                        break outer;
 104.703 -                }
 104.704 -            } while ((count1 | count2) < minGallop);
 104.705 -
 104.706 -            /*
 104.707 -             * One run is winning so consistently that galloping may be a
 104.708 -             * huge win. So try that, and continue galloping until (if ever)
 104.709 -             * neither run appears to be winning consistently anymore.
 104.710 -             */
 104.711 -            do {
 104.712 -                assert len1 > 1 && len2 > 0;
 104.713 -                count1 = gallopRight(a[cursor2], tmp, cursor1, len1, 0, c);
 104.714 -                if (count1 != 0) {
 104.715 -                    System.arraycopy(tmp, cursor1, a, dest, count1);
 104.716 -                    dest += count1;
 104.717 -                    cursor1 += count1;
 104.718 -                    len1 -= count1;
 104.719 -                    if (len1 <= 1) // len1 == 1 || len1 == 0
 104.720 -                        break outer;
 104.721 -                }
 104.722 -                a[dest++] = a[cursor2++];
 104.723 -                if (--len2 == 0)
 104.724 -                    break outer;
 104.725 -
 104.726 -                count2 = gallopLeft(tmp[cursor1], a, cursor2, len2, 0, c);
 104.727 -                if (count2 != 0) {
 104.728 -                    System.arraycopy(a, cursor2, a, dest, count2);
 104.729 -                    dest += count2;
 104.730 -                    cursor2 += count2;
 104.731 -                    len2 -= count2;
 104.732 -                    if (len2 == 0)
 104.733 -                        break outer;
 104.734 -                }
 104.735 -                a[dest++] = tmp[cursor1++];
 104.736 -                if (--len1 == 1)
 104.737 -                    break outer;
 104.738 -                minGallop--;
 104.739 -            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
 104.740 -            if (minGallop < 0)
 104.741 -                minGallop = 0;
 104.742 -            minGallop += 2;  // Penalize for leaving gallop mode
 104.743 -        }  // End of "outer" loop
 104.744 -        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
 104.745 -
 104.746 -        if (len1 == 1) {
 104.747 -            assert len2 > 0;
 104.748 -            System.arraycopy(a, cursor2, a, dest, len2);
 104.749 -            a[dest + len2] = tmp[cursor1]; //  Last elt of run 1 to end of merge
 104.750 -        } else if (len1 == 0) {
 104.751 -            throw new IllegalArgumentException(
 104.752 -                "Comparison method violates its general contract!");
 104.753 -        } else {
 104.754 -            assert len2 == 0;
 104.755 -            assert len1 > 1;
 104.756 -            System.arraycopy(tmp, cursor1, a, dest, len1);
 104.757 -        }
 104.758 -    }
 104.759 -
 104.760 -    /**
 104.761 -     * Like mergeLo, except that this method should be called only if
 104.762 -     * len1 >= len2; mergeLo should be called if len1 <= len2.  (Either method
 104.763 -     * may be called if len1 == len2.)
 104.764 -     *
 104.765 -     * @param base1 index of first element in first run to be merged
 104.766 -     * @param len1  length of first run to be merged (must be > 0)
 104.767 -     * @param base2 index of first element in second run to be merged
 104.768 -     *        (must be aBase + aLen)
 104.769 -     * @param len2  length of second run to be merged (must be > 0)
 104.770 -     */
 104.771 -    private void mergeHi(int base1, int len1, int base2, int len2) {
 104.772 -        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
 104.773 -
 104.774 -        // Copy second run into temp array
 104.775 -        T[] a = this.a; // For performance
 104.776 -        T[] tmp = ensureCapacity(len2);
 104.777 -        System.arraycopy(a, base2, tmp, 0, len2);
 104.778 -
 104.779 -        int cursor1 = base1 + len1 - 1;  // Indexes into a
 104.780 -        int cursor2 = len2 - 1;          // Indexes into tmp array
 104.781 -        int dest = base2 + len2 - 1;     // Indexes into a
 104.782 -
 104.783 -        // Move last element of first run and deal with degenerate cases
 104.784 -        a[dest--] = a[cursor1--];
 104.785 -        if (--len1 == 0) {
 104.786 -            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
 104.787 -            return;
 104.788 -        }
 104.789 -        if (len2 == 1) {
 104.790 -            dest -= len1;
 104.791 -            cursor1 -= len1;
 104.792 -            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
 104.793 -            a[dest] = tmp[cursor2];
 104.794 -            return;
 104.795 -        }
 104.796 -
 104.797 -        Comparator<? super T> c = this.c;  // Use local variable for performance
 104.798 -        int minGallop = this.minGallop;    //  "    "       "     "      "
 104.799 -    outer:
 104.800 -        while (true) {
 104.801 -            int count1 = 0; // Number of times in a row that first run won
 104.802 -            int count2 = 0; // Number of times in a row that second run won
 104.803 -
 104.804 -            /*
 104.805 -             * Do the straightforward thing until (if ever) one run
 104.806 -             * appears to win consistently.
 104.807 -             */
 104.808 -            do {
 104.809 -                assert len1 > 0 && len2 > 1;
 104.810 -                if (c.compare(tmp[cursor2], a[cursor1]) < 0) {
 104.811 -                    a[dest--] = a[cursor1--];
 104.812 -                    count1++;
 104.813 -                    count2 = 0;
 104.814 -                    if (--len1 == 0)
 104.815 -                        break outer;
 104.816 -                } else {
 104.817 -                    a[dest--] = tmp[cursor2--];
 104.818 -                    count2++;
 104.819 -                    count1 = 0;
 104.820 -                    if (--len2 == 1)
 104.821 -                        break outer;
 104.822 -                }
 104.823 -            } while ((count1 | count2) < minGallop);
 104.824 -
 104.825 -            /*
 104.826 -             * One run is winning so consistently that galloping may be a
 104.827 -             * huge win. So try that, and continue galloping until (if ever)
 104.828 -             * neither run appears to be winning consistently anymore.
 104.829 -             */
 104.830 -            do {
 104.831 -                assert len1 > 0 && len2 > 1;
 104.832 -                count1 = len1 - gallopRight(tmp[cursor2], a, base1, len1, len1 - 1, c);
 104.833 -                if (count1 != 0) {
 104.834 -                    dest -= count1;
 104.835 -                    cursor1 -= count1;
 104.836 -                    len1 -= count1;
 104.837 -                    System.arraycopy(a, cursor1 + 1, a, dest + 1, count1);
 104.838 -                    if (len1 == 0)
 104.839 -                        break outer;
 104.840 -                }
 104.841 -                a[dest--] = tmp[cursor2--];
 104.842 -                if (--len2 == 1)
 104.843 -                    break outer;
 104.844 -
 104.845 -                count2 = len2 - gallopLeft(a[cursor1], tmp, 0, len2, len2 - 1, c);
 104.846 -                if (count2 != 0) {
 104.847 -                    dest -= count2;
 104.848 -                    cursor2 -= count2;
 104.849 -                    len2 -= count2;
 104.850 -                    System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
 104.851 -                    if (len2 <= 1)  // len2 == 1 || len2 == 0
 104.852 -                        break outer;
 104.853 -                }
 104.854 -                a[dest--] = a[cursor1--];
 104.855 -                if (--len1 == 0)
 104.856 -                    break outer;
 104.857 -                minGallop--;
 104.858 -            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
 104.859 -            if (minGallop < 0)
 104.860 -                minGallop = 0;
 104.861 -            minGallop += 2;  // Penalize for leaving gallop mode
 104.862 -        }  // End of "outer" loop
 104.863 -        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
 104.864 -
 104.865 -        if (len2 == 1) {
 104.866 -            assert len1 > 0;
 104.867 -            dest -= len1;
 104.868 -            cursor1 -= len1;
 104.869 -            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
 104.870 -            a[dest] = tmp[cursor2];  // Move first elt of run2 to front of merge
 104.871 -        } else if (len2 == 0) {
 104.872 -            throw new IllegalArgumentException(
 104.873 -                "Comparison method violates its general contract!");
 104.874 -        } else {
 104.875 -            assert len1 == 0;
 104.876 -            assert len2 > 0;
 104.877 -            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
 104.878 -        }
 104.879 -    }
 104.880 -
 104.881 -    /**
 104.882 -     * Ensures that the external array tmp has at least the specified
 104.883 -     * number of elements, increasing its size if necessary.  The size
 104.884 -     * increases exponentially to ensure amortized linear time complexity.
 104.885 -     *
 104.886 -     * @param minCapacity the minimum required capacity of the tmp array
 104.887 -     * @return tmp, whether or not it grew
 104.888 -     */
 104.889 -    private T[] ensureCapacity(int minCapacity) {
 104.890 -        if (tmp.length < minCapacity) {
 104.891 -            // Compute smallest power of 2 > minCapacity
 104.892 -            int newSize = minCapacity;
 104.893 -            newSize |= newSize >> 1;
 104.894 -            newSize |= newSize >> 2;
 104.895 -            newSize |= newSize >> 4;
 104.896 -            newSize |= newSize >> 8;
 104.897 -            newSize |= newSize >> 16;
 104.898 -            newSize++;
 104.899 -
 104.900 -            if (newSize < 0) // Not bloody likely!
 104.901 -                newSize = minCapacity;
 104.902 -            else
 104.903 -                newSize = Math.min(newSize, a.length >>> 1);
 104.904 -
 104.905 -            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
 104.906 -            T[] newArray = (T[]) new Object[newSize];
 104.907 -            tmp = newArray;
 104.908 -        }
 104.909 -        return tmp;
 104.910 -    }
 104.911 -
 104.912 -    /**
 104.913 -     * Checks that fromIndex and toIndex are in range, and throws an
 104.914 -     * appropriate exception if they aren't.
 104.915 -     *
 104.916 -     * @param arrayLen the length of the array
 104.917 -     * @param fromIndex the index of the first element of the range
 104.918 -     * @param toIndex the index after the last element of the range
 104.919 -     * @throws IllegalArgumentException if fromIndex > toIndex
 104.920 -     * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
 104.921 -     *         or toIndex > arrayLen
 104.922 -     */
 104.923 -    private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
 104.924 -        if (fromIndex > toIndex)
 104.925 -            throw new IllegalArgumentException("fromIndex(" + fromIndex +
 104.926 -                       ") > toIndex(" + toIndex+")");
 104.927 -        if (fromIndex < 0)
 104.928 -            throw new ArrayIndexOutOfBoundsException(fromIndex);
 104.929 -        if (toIndex > arrayLen)
 104.930 -            throw new ArrayIndexOutOfBoundsException(toIndex);
 104.931 -    }
 104.932 -}
   105.1 --- a/emul/compact/src/main/java/java/util/Vector.java	Mon Feb 25 19:00:08 2013 +0100
   105.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   105.3 @@ -1,1194 +0,0 @@
   105.4 -/*
   105.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   105.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   105.7 - *
   105.8 - * This code is free software; you can redistribute it and/or modify it
   105.9 - * under the terms of the GNU General Public License version 2 only, as
  105.10 - * published by the Free Software Foundation.  Oracle designates this
  105.11 - * particular file as subject to the "Classpath" exception as provided
  105.12 - * by Oracle in the LICENSE file that accompanied this code.
  105.13 - *
  105.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  105.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  105.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  105.17 - * version 2 for more details (a copy is included in the LICENSE file that
  105.18 - * accompanied this code).
  105.19 - *
  105.20 - * You should have received a copy of the GNU General Public License version
  105.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  105.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  105.23 - *
  105.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  105.25 - * or visit www.oracle.com if you need additional information or have any
  105.26 - * questions.
  105.27 - */
  105.28 -
  105.29 -package java.util;
  105.30 -
  105.31 -
  105.32 -/**
  105.33 - * The {@code Vector} class implements a growable array of
  105.34 - * objects. Like an array, it contains components that can be
  105.35 - * accessed using an integer index. However, the size of a
  105.36 - * {@code Vector} can grow or shrink as needed to accommodate
  105.37 - * adding and removing items after the {@code Vector} has been created.
  105.38 - *
  105.39 - * <p>Each vector tries to optimize storage management by maintaining a
  105.40 - * {@code capacity} and a {@code capacityIncrement}. The
  105.41 - * {@code capacity} is always at least as large as the vector
  105.42 - * size; it is usually larger because as components are added to the
  105.43 - * vector, the vector's storage increases in chunks the size of
  105.44 - * {@code capacityIncrement}. An application can increase the
  105.45 - * capacity of a vector before inserting a large number of
  105.46 - * components; this reduces the amount of incremental reallocation.
  105.47 - *
  105.48 - * <p><a name="fail-fast"/>
  105.49 - * The iterators returned by this class's {@link #iterator() iterator} and
  105.50 - * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
  105.51 - * if the vector is structurally modified at any time after the iterator is
  105.52 - * created, in any way except through the iterator's own
  105.53 - * {@link ListIterator#remove() remove} or
  105.54 - * {@link ListIterator#add(Object) add} methods, the iterator will throw a
  105.55 - * {@link ConcurrentModificationException}.  Thus, in the face of
  105.56 - * concurrent modification, the iterator fails quickly and cleanly, rather
  105.57 - * than risking arbitrary, non-deterministic behavior at an undetermined
  105.58 - * time in the future.  The {@link Enumeration Enumerations} returned by
  105.59 - * the {@link #elements() elements} method are <em>not</em> fail-fast.
  105.60 - *
  105.61 - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  105.62 - * as it is, generally speaking, impossible to make any hard guarantees in the
  105.63 - * presence of unsynchronized concurrent modification.  Fail-fast iterators
  105.64 - * throw {@code ConcurrentModificationException} on a best-effort basis.
  105.65 - * Therefore, it would be wrong to write a program that depended on this
  105.66 - * exception for its correctness:  <i>the fail-fast behavior of iterators
  105.67 - * should be used only to detect bugs.</i>
  105.68 - *
  105.69 - * <p>As of the Java 2 platform v1.2, this class was retrofitted to
  105.70 - * implement the {@link List} interface, making it a member of the
  105.71 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  105.72 - * Java Collections Framework</a>.  Unlike the new collection
  105.73 - * implementations, {@code Vector} is synchronized.  If a thread-safe
  105.74 - * implementation is not needed, it is recommended to use {@link
  105.75 - * ArrayList} in place of {@code Vector}.
  105.76 - *
  105.77 - * @author  Lee Boynton
  105.78 - * @author  Jonathan Payne
  105.79 - * @see Collection
  105.80 - * @see LinkedList
  105.81 - * @since   JDK1.0
  105.82 - */
  105.83 -public class Vector<E>
  105.84 -    extends AbstractList<E>
  105.85 -    implements List<E>, RandomAccess, Cloneable, java.io.Serializable
  105.86 -{
  105.87 -    /**
  105.88 -     * The array buffer into which the components of the vector are
  105.89 -     * stored. The capacity of the vector is the length of this array buffer,
  105.90 -     * and is at least large enough to contain all the vector's elements.
  105.91 -     *
  105.92 -     * <p>Any array elements following the last element in the Vector are null.
  105.93 -     *
  105.94 -     * @serial
  105.95 -     */
  105.96 -    protected Object[] elementData;
  105.97 -
  105.98 -    /**
  105.99 -     * The number of valid components in this {@code Vector} object.
 105.100 -     * Components {@code elementData[0]} through
 105.101 -     * {@code elementData[elementCount-1]} are the actual items.
 105.102 -     *
 105.103 -     * @serial
 105.104 -     */
 105.105 -    protected int elementCount;
 105.106 -
 105.107 -    /**
 105.108 -     * The amount by which the capacity of the vector is automatically
 105.109 -     * incremented when its size becomes greater than its capacity.  If
 105.110 -     * the capacity increment is less than or equal to zero, the capacity
 105.111 -     * of the vector is doubled each time it needs to grow.
 105.112 -     *
 105.113 -     * @serial
 105.114 -     */
 105.115 -    protected int capacityIncrement;
 105.116 -
 105.117 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 105.118 -    private static final long serialVersionUID = -2767605614048989439L;
 105.119 -
 105.120 -    /**
 105.121 -     * Constructs an empty vector with the specified initial capacity and
 105.122 -     * capacity increment.
 105.123 -     *
 105.124 -     * @param   initialCapacity     the initial capacity of the vector
 105.125 -     * @param   capacityIncrement   the amount by which the capacity is
 105.126 -     *                              increased when the vector overflows
 105.127 -     * @throws IllegalArgumentException if the specified initial capacity
 105.128 -     *         is negative
 105.129 -     */
 105.130 -    public Vector(int initialCapacity, int capacityIncrement) {
 105.131 -        super();
 105.132 -        if (initialCapacity < 0)
 105.133 -            throw new IllegalArgumentException("Illegal Capacity: "+
 105.134 -                                               initialCapacity);
 105.135 -        this.elementData = new Object[initialCapacity];
 105.136 -        this.capacityIncrement = capacityIncrement;
 105.137 -    }
 105.138 -
 105.139 -    /**
 105.140 -     * Constructs an empty vector with the specified initial capacity and
 105.141 -     * with its capacity increment equal to zero.
 105.142 -     *
 105.143 -     * @param   initialCapacity   the initial capacity of the vector
 105.144 -     * @throws IllegalArgumentException if the specified initial capacity
 105.145 -     *         is negative
 105.146 -     */
 105.147 -    public Vector(int initialCapacity) {
 105.148 -        this(initialCapacity, 0);
 105.149 -    }
 105.150 -
 105.151 -    /**
 105.152 -     * Constructs an empty vector so that its internal data array
 105.153 -     * has size {@code 10} and its standard capacity increment is
 105.154 -     * zero.
 105.155 -     */
 105.156 -    public Vector() {
 105.157 -        this(10);
 105.158 -    }
 105.159 -
 105.160 -    /**
 105.161 -     * Constructs a vector containing the elements of the specified
 105.162 -     * collection, in the order they are returned by the collection's
 105.163 -     * iterator.
 105.164 -     *
 105.165 -     * @param c the collection whose elements are to be placed into this
 105.166 -     *       vector
 105.167 -     * @throws NullPointerException if the specified collection is null
 105.168 -     * @since   1.2
 105.169 -     */
 105.170 -    public Vector(Collection<? extends E> c) {
 105.171 -        elementData = c.toArray();
 105.172 -        elementCount = elementData.length;
 105.173 -        // c.toArray might (incorrectly) not return Object[] (see 6260652)
 105.174 -        if (elementData.getClass() != Object[].class)
 105.175 -            elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
 105.176 -    }
 105.177 -
 105.178 -    /**
 105.179 -     * Copies the components of this vector into the specified array.
 105.180 -     * The item at index {@code k} in this vector is copied into
 105.181 -     * component {@code k} of {@code anArray}.
 105.182 -     *
 105.183 -     * @param  anArray the array into which the components get copied
 105.184 -     * @throws NullPointerException if the given array is null
 105.185 -     * @throws IndexOutOfBoundsException if the specified array is not
 105.186 -     *         large enough to hold all the components of this vector
 105.187 -     * @throws ArrayStoreException if a component of this vector is not of
 105.188 -     *         a runtime type that can be stored in the specified array
 105.189 -     * @see #toArray(Object[])
 105.190 -     */
 105.191 -    public synchronized void copyInto(Object[] anArray) {
 105.192 -        System.arraycopy(elementData, 0, anArray, 0, elementCount);
 105.193 -    }
 105.194 -
 105.195 -    /**
 105.196 -     * Trims the capacity of this vector to be the vector's current
 105.197 -     * size. If the capacity of this vector is larger than its current
 105.198 -     * size, then the capacity is changed to equal the size by replacing
 105.199 -     * its internal data array, kept in the field {@code elementData},
 105.200 -     * with a smaller one. An application can use this operation to
 105.201 -     * minimize the storage of a vector.
 105.202 -     */
 105.203 -    public synchronized void trimToSize() {
 105.204 -        modCount++;
 105.205 -        int oldCapacity = elementData.length;
 105.206 -        if (elementCount < oldCapacity) {
 105.207 -            elementData = Arrays.copyOf(elementData, elementCount);
 105.208 -        }
 105.209 -    }
 105.210 -
 105.211 -    /**
 105.212 -     * Increases the capacity of this vector, if necessary, to ensure
 105.213 -     * that it can hold at least the number of components specified by
 105.214 -     * the minimum capacity argument.
 105.215 -     *
 105.216 -     * <p>If the current capacity of this vector is less than
 105.217 -     * {@code minCapacity}, then its capacity is increased by replacing its
 105.218 -     * internal data array, kept in the field {@code elementData}, with a
 105.219 -     * larger one.  The size of the new data array will be the old size plus
 105.220 -     * {@code capacityIncrement}, unless the value of
 105.221 -     * {@code capacityIncrement} is less than or equal to zero, in which case
 105.222 -     * the new capacity will be twice the old capacity; but if this new size
 105.223 -     * is still smaller than {@code minCapacity}, then the new capacity will
 105.224 -     * be {@code minCapacity}.
 105.225 -     *
 105.226 -     * @param minCapacity the desired minimum capacity
 105.227 -     */
 105.228 -    public synchronized void ensureCapacity(int minCapacity) {
 105.229 -        if (minCapacity > 0) {
 105.230 -            modCount++;
 105.231 -            ensureCapacityHelper(minCapacity);
 105.232 -        }
 105.233 -    }
 105.234 -
 105.235 -    /**
 105.236 -     * This implements the unsynchronized semantics of ensureCapacity.
 105.237 -     * Synchronized methods in this class can internally call this
 105.238 -     * method for ensuring capacity without incurring the cost of an
 105.239 -     * extra synchronization.
 105.240 -     *
 105.241 -     * @see #ensureCapacity(int)
 105.242 -     */
 105.243 -    private void ensureCapacityHelper(int minCapacity) {
 105.244 -        // overflow-conscious code
 105.245 -        if (minCapacity - elementData.length > 0)
 105.246 -            grow(minCapacity);
 105.247 -    }
 105.248 -
 105.249 -    /**
 105.250 -     * The maximum size of array to allocate.
 105.251 -     * Some VMs reserve some header words in an array.
 105.252 -     * Attempts to allocate larger arrays may result in
 105.253 -     * OutOfMemoryError: Requested array size exceeds VM limit
 105.254 -     */
 105.255 -    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 105.256 -
 105.257 -    private void grow(int minCapacity) {
 105.258 -        // overflow-conscious code
 105.259 -        int oldCapacity = elementData.length;
 105.260 -        int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
 105.261 -                                         capacityIncrement : oldCapacity);
 105.262 -        if (newCapacity - minCapacity < 0)
 105.263 -            newCapacity = minCapacity;
 105.264 -        if (newCapacity - MAX_ARRAY_SIZE > 0)
 105.265 -            newCapacity = hugeCapacity(minCapacity);
 105.266 -        elementData = Arrays.copyOf(elementData, newCapacity);
 105.267 -    }
 105.268 -
 105.269 -    private static int hugeCapacity(int minCapacity) {
 105.270 -        if (minCapacity < 0) // overflow
 105.271 -            throw new OutOfMemoryError();
 105.272 -        return (minCapacity > MAX_ARRAY_SIZE) ?
 105.273 -            Integer.MAX_VALUE :
 105.274 -            MAX_ARRAY_SIZE;
 105.275 -    }
 105.276 -
 105.277 -    /**
 105.278 -     * Sets the size of this vector. If the new size is greater than the
 105.279 -     * current size, new {@code null} items are added to the end of
 105.280 -     * the vector. If the new size is less than the current size, all
 105.281 -     * components at index {@code newSize} and greater are discarded.
 105.282 -     *
 105.283 -     * @param  newSize   the new size of this vector
 105.284 -     * @throws ArrayIndexOutOfBoundsException if the new size is negative
 105.285 -     */
 105.286 -    public synchronized void setSize(int newSize) {
 105.287 -        modCount++;
 105.288 -        if (newSize > elementCount) {
 105.289 -            ensureCapacityHelper(newSize);
 105.290 -        } else {
 105.291 -            for (int i = newSize ; i < elementCount ; i++) {
 105.292 -                elementData[i] = null;
 105.293 -            }
 105.294 -        }
 105.295 -        elementCount = newSize;
 105.296 -    }
 105.297 -
 105.298 -    /**
 105.299 -     * Returns the current capacity of this vector.
 105.300 -     *
 105.301 -     * @return  the current capacity (the length of its internal
 105.302 -     *          data array, kept in the field {@code elementData}
 105.303 -     *          of this vector)
 105.304 -     */
 105.305 -    public synchronized int capacity() {
 105.306 -        return elementData.length;
 105.307 -    }
 105.308 -
 105.309 -    /**
 105.310 -     * Returns the number of components in this vector.
 105.311 -     *
 105.312 -     * @return  the number of components in this vector
 105.313 -     */
 105.314 -    public synchronized int size() {
 105.315 -        return elementCount;
 105.316 -    }
 105.317 -
 105.318 -    /**
 105.319 -     * Tests if this vector has no components.
 105.320 -     *
 105.321 -     * @return  {@code true} if and only if this vector has
 105.322 -     *          no components, that is, its size is zero;
 105.323 -     *          {@code false} otherwise.
 105.324 -     */
 105.325 -    public synchronized boolean isEmpty() {
 105.326 -        return elementCount == 0;
 105.327 -    }
 105.328 -
 105.329 -    /**
 105.330 -     * Returns an enumeration of the components of this vector. The
 105.331 -     * returned {@code Enumeration} object will generate all items in
 105.332 -     * this vector. The first item generated is the item at index {@code 0},
 105.333 -     * then the item at index {@code 1}, and so on.
 105.334 -     *
 105.335 -     * @return  an enumeration of the components of this vector
 105.336 -     * @see     Iterator
 105.337 -     */
 105.338 -    public Enumeration<E> elements() {
 105.339 -        return new Enumeration<E>() {
 105.340 -            int count = 0;
 105.341 -
 105.342 -            public boolean hasMoreElements() {
 105.343 -                return count < elementCount;
 105.344 -            }
 105.345 -
 105.346 -            public E nextElement() {
 105.347 -                synchronized (Vector.this) {
 105.348 -                    if (count < elementCount) {
 105.349 -                        return elementData(count++);
 105.350 -                    }
 105.351 -                }
 105.352 -                throw new NoSuchElementException("Vector Enumeration");
 105.353 -            }
 105.354 -        };
 105.355 -    }
 105.356 -
 105.357 -    /**
 105.358 -     * Returns {@code true} if this vector contains the specified element.
 105.359 -     * More formally, returns {@code true} if and only if this vector
 105.360 -     * contains at least one element {@code e} such that
 105.361 -     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 105.362 -     *
 105.363 -     * @param o element whose presence in this vector is to be tested
 105.364 -     * @return {@code true} if this vector contains the specified element
 105.365 -     */
 105.366 -    public boolean contains(Object o) {
 105.367 -        return indexOf(o, 0) >= 0;
 105.368 -    }
 105.369 -
 105.370 -    /**
 105.371 -     * Returns the index of the first occurrence of the specified element
 105.372 -     * in this vector, or -1 if this vector does not contain the element.
 105.373 -     * More formally, returns the lowest index {@code i} such that
 105.374 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 105.375 -     * or -1 if there is no such index.
 105.376 -     *
 105.377 -     * @param o element to search for
 105.378 -     * @return the index of the first occurrence of the specified element in
 105.379 -     *         this vector, or -1 if this vector does not contain the element
 105.380 -     */
 105.381 -    public int indexOf(Object o) {
 105.382 -        return indexOf(o, 0);
 105.383 -    }
 105.384 -
 105.385 -    /**
 105.386 -     * Returns the index of the first occurrence of the specified element in
 105.387 -     * this vector, searching forwards from {@code index}, or returns -1 if
 105.388 -     * the element is not found.
 105.389 -     * More formally, returns the lowest index {@code i} such that
 105.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>,
 105.391 -     * or -1 if there is no such index.
 105.392 -     *
 105.393 -     * @param o element to search for
 105.394 -     * @param index index to start searching from
 105.395 -     * @return the index of the first occurrence of the element in
 105.396 -     *         this vector at position {@code index} or later in the vector;
 105.397 -     *         {@code -1} if the element is not found.
 105.398 -     * @throws IndexOutOfBoundsException if the specified index is negative
 105.399 -     * @see     Object#equals(Object)
 105.400 -     */
 105.401 -    public synchronized int indexOf(Object o, int index) {
 105.402 -        if (o == null) {
 105.403 -            for (int i = index ; i < elementCount ; i++)
 105.404 -                if (elementData[i]==null)
 105.405 -                    return i;
 105.406 -        } else {
 105.407 -            for (int i = index ; i < elementCount ; i++)
 105.408 -                if (o.equals(elementData[i]))
 105.409 -                    return i;
 105.410 -        }
 105.411 -        return -1;
 105.412 -    }
 105.413 -
 105.414 -    /**
 105.415 -     * Returns the index of the last occurrence of the specified element
 105.416 -     * in this vector, or -1 if this vector does not contain the element.
 105.417 -     * More formally, returns the highest index {@code i} such that
 105.418 -     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 105.419 -     * or -1 if there is no such index.
 105.420 -     *
 105.421 -     * @param o element to search for
 105.422 -     * @return the index of the last occurrence of the specified element in
 105.423 -     *         this vector, or -1 if this vector does not contain the element
 105.424 -     */
 105.425 -    public synchronized int lastIndexOf(Object o) {
 105.426 -        return lastIndexOf(o, elementCount-1);
 105.427 -    }
 105.428 -
 105.429 -    /**
 105.430 -     * Returns the index of the last occurrence of the specified element in
 105.431 -     * this vector, searching backwards from {@code index}, or returns -1 if
 105.432 -     * the element is not found.
 105.433 -     * More formally, returns the highest index {@code i} such that
 105.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>,
 105.435 -     * or -1 if there is no such index.
 105.436 -     *
 105.437 -     * @param o element to search for
 105.438 -     * @param index index to start searching backwards from
 105.439 -     * @return the index of the last occurrence of the element at position
 105.440 -     *         less than or equal to {@code index} in this vector;
 105.441 -     *         -1 if the element is not found.
 105.442 -     * @throws IndexOutOfBoundsException if the specified index is greater
 105.443 -     *         than or equal to the current size of this vector
 105.444 -     */
 105.445 -    public synchronized int lastIndexOf(Object o, int index) {
 105.446 -        if (index >= elementCount)
 105.447 -            throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
 105.448 -
 105.449 -        if (o == null) {
 105.450 -            for (int i = index; i >= 0; i--)
 105.451 -                if (elementData[i]==null)
 105.452 -                    return i;
 105.453 -        } else {
 105.454 -            for (int i = index; i >= 0; i--)
 105.455 -                if (o.equals(elementData[i]))
 105.456 -                    return i;
 105.457 -        }
 105.458 -        return -1;
 105.459 -    }
 105.460 -
 105.461 -    /**
 105.462 -     * Returns the component at the specified index.
 105.463 -     *
 105.464 -     * <p>This method is identical in functionality to the {@link #get(int)}
 105.465 -     * method (which is part of the {@link List} interface).
 105.466 -     *
 105.467 -     * @param      index   an index into this vector
 105.468 -     * @return     the component at the specified index
 105.469 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.470 -     *         ({@code index < 0 || index >= size()})
 105.471 -     */
 105.472 -    public synchronized E elementAt(int index) {
 105.473 -        if (index >= elementCount) {
 105.474 -            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
 105.475 -        }
 105.476 -
 105.477 -        return elementData(index);
 105.478 -    }
 105.479 -
 105.480 -    /**
 105.481 -     * Returns the first component (the item at index {@code 0}) of
 105.482 -     * this vector.
 105.483 -     *
 105.484 -     * @return     the first component of this vector
 105.485 -     * @throws NoSuchElementException if this vector has no components
 105.486 -     */
 105.487 -    public synchronized E firstElement() {
 105.488 -        if (elementCount == 0) {
 105.489 -            throw new NoSuchElementException();
 105.490 -        }
 105.491 -        return elementData(0);
 105.492 -    }
 105.493 -
 105.494 -    /**
 105.495 -     * Returns the last component of the vector.
 105.496 -     *
 105.497 -     * @return  the last component of the vector, i.e., the component at index
 105.498 -     *          <code>size()&nbsp;-&nbsp;1</code>.
 105.499 -     * @throws NoSuchElementException if this vector is empty
 105.500 -     */
 105.501 -    public synchronized E lastElement() {
 105.502 -        if (elementCount == 0) {
 105.503 -            throw new NoSuchElementException();
 105.504 -        }
 105.505 -        return elementData(elementCount - 1);
 105.506 -    }
 105.507 -
 105.508 -    /**
 105.509 -     * Sets the component at the specified {@code index} of this
 105.510 -     * vector to be the specified object. The previous component at that
 105.511 -     * position is discarded.
 105.512 -     *
 105.513 -     * <p>The index must be a value greater than or equal to {@code 0}
 105.514 -     * and less than the current size of the vector.
 105.515 -     *
 105.516 -     * <p>This method is identical in functionality to the
 105.517 -     * {@link #set(int, Object) set(int, E)}
 105.518 -     * method (which is part of the {@link List} interface). Note that the
 105.519 -     * {@code set} method reverses the order of the parameters, to more closely
 105.520 -     * match array usage.  Note also that the {@code set} method returns the
 105.521 -     * old value that was stored at the specified position.
 105.522 -     *
 105.523 -     * @param      obj     what the component is to be set to
 105.524 -     * @param      index   the specified index
 105.525 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.526 -     *         ({@code index < 0 || index >= size()})
 105.527 -     */
 105.528 -    public synchronized void setElementAt(E obj, int index) {
 105.529 -        if (index >= elementCount) {
 105.530 -            throw new ArrayIndexOutOfBoundsException(index + " >= " +
 105.531 -                                                     elementCount);
 105.532 -        }
 105.533 -        elementData[index] = obj;
 105.534 -    }
 105.535 -
 105.536 -    /**
 105.537 -     * Deletes the component at the specified index. Each component in
 105.538 -     * this vector with an index greater or equal to the specified
 105.539 -     * {@code index} is shifted downward to have an index one
 105.540 -     * smaller than the value it had previously. The size of this vector
 105.541 -     * is decreased by {@code 1}.
 105.542 -     *
 105.543 -     * <p>The index must be a value greater than or equal to {@code 0}
 105.544 -     * and less than the current size of the vector.
 105.545 -     *
 105.546 -     * <p>This method is identical in functionality to the {@link #remove(int)}
 105.547 -     * method (which is part of the {@link List} interface).  Note that the
 105.548 -     * {@code remove} method returns the old value that was stored at the
 105.549 -     * specified position.
 105.550 -     *
 105.551 -     * @param      index   the index of the object to remove
 105.552 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.553 -     *         ({@code index < 0 || index >= size()})
 105.554 -     */
 105.555 -    public synchronized void removeElementAt(int index) {
 105.556 -        modCount++;
 105.557 -        if (index >= elementCount) {
 105.558 -            throw new ArrayIndexOutOfBoundsException(index + " >= " +
 105.559 -                                                     elementCount);
 105.560 -        }
 105.561 -        else if (index < 0) {
 105.562 -            throw new ArrayIndexOutOfBoundsException(index);
 105.563 -        }
 105.564 -        int j = elementCount - index - 1;
 105.565 -        if (j > 0) {
 105.566 -            System.arraycopy(elementData, index + 1, elementData, index, j);
 105.567 -        }
 105.568 -        elementCount--;
 105.569 -        elementData[elementCount] = null; /* to let gc do its work */
 105.570 -    }
 105.571 -
 105.572 -    /**
 105.573 -     * Inserts the specified object as a component in this vector at the
 105.574 -     * specified {@code index}. Each component in this vector with
 105.575 -     * an index greater or equal to the specified {@code index} is
 105.576 -     * shifted upward to have an index one greater than the value it had
 105.577 -     * previously.
 105.578 -     *
 105.579 -     * <p>The index must be a value greater than or equal to {@code 0}
 105.580 -     * and less than or equal to the current size of the vector. (If the
 105.581 -     * index is equal to the current size of the vector, the new element
 105.582 -     * is appended to the Vector.)
 105.583 -     *
 105.584 -     * <p>This method is identical in functionality to the
 105.585 -     * {@link #add(int, Object) add(int, E)}
 105.586 -     * method (which is part of the {@link List} interface).  Note that the
 105.587 -     * {@code add} method reverses the order of the parameters, to more closely
 105.588 -     * match array usage.
 105.589 -     *
 105.590 -     * @param      obj     the component to insert
 105.591 -     * @param      index   where to insert the new component
 105.592 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.593 -     *         ({@code index < 0 || index > size()})
 105.594 -     */
 105.595 -    public synchronized void insertElementAt(E obj, int index) {
 105.596 -        modCount++;
 105.597 -        if (index > elementCount) {
 105.598 -            throw new ArrayIndexOutOfBoundsException(index
 105.599 -                                                     + " > " + elementCount);
 105.600 -        }
 105.601 -        ensureCapacityHelper(elementCount + 1);
 105.602 -        System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
 105.603 -        elementData[index] = obj;
 105.604 -        elementCount++;
 105.605 -    }
 105.606 -
 105.607 -    /**
 105.608 -     * Adds the specified component to the end of this vector,
 105.609 -     * increasing its size by one. The capacity of this vector is
 105.610 -     * increased if its size becomes greater than its capacity.
 105.611 -     *
 105.612 -     * <p>This method is identical in functionality to the
 105.613 -     * {@link #add(Object) add(E)}
 105.614 -     * method (which is part of the {@link List} interface).
 105.615 -     *
 105.616 -     * @param   obj   the component to be added
 105.617 -     */
 105.618 -    public synchronized void addElement(E obj) {
 105.619 -        modCount++;
 105.620 -        ensureCapacityHelper(elementCount + 1);
 105.621 -        elementData[elementCount++] = obj;
 105.622 -    }
 105.623 -
 105.624 -    /**
 105.625 -     * Removes the first (lowest-indexed) occurrence of the argument
 105.626 -     * from this vector. If the object is found in this vector, each
 105.627 -     * component in the vector with an index greater or equal to the
 105.628 -     * object's index is shifted downward to have an index one smaller
 105.629 -     * than the value it had previously.
 105.630 -     *
 105.631 -     * <p>This method is identical in functionality to the
 105.632 -     * {@link #remove(Object)} method (which is part of the
 105.633 -     * {@link List} interface).
 105.634 -     *
 105.635 -     * @param   obj   the component to be removed
 105.636 -     * @return  {@code true} if the argument was a component of this
 105.637 -     *          vector; {@code false} otherwise.
 105.638 -     */
 105.639 -    public synchronized boolean removeElement(Object obj) {
 105.640 -        modCount++;
 105.641 -        int i = indexOf(obj);
 105.642 -        if (i >= 0) {
 105.643 -            removeElementAt(i);
 105.644 -            return true;
 105.645 -        }
 105.646 -        return false;
 105.647 -    }
 105.648 -
 105.649 -    /**
 105.650 -     * Removes all components from this vector and sets its size to zero.
 105.651 -     *
 105.652 -     * <p>This method is identical in functionality to the {@link #clear}
 105.653 -     * method (which is part of the {@link List} interface).
 105.654 -     */
 105.655 -    public synchronized void removeAllElements() {
 105.656 -        modCount++;
 105.657 -        // Let gc do its work
 105.658 -        for (int i = 0; i < elementCount; i++)
 105.659 -            elementData[i] = null;
 105.660 -
 105.661 -        elementCount = 0;
 105.662 -    }
 105.663 -
 105.664 -    /**
 105.665 -     * Returns a clone of this vector. The copy will contain a
 105.666 -     * reference to a clone of the internal data array, not a reference
 105.667 -     * to the original internal data array of this {@code Vector} object.
 105.668 -     *
 105.669 -     * @return  a clone of this vector
 105.670 -     */
 105.671 -    public synchronized Object clone() {
 105.672 -        try {
 105.673 -            @SuppressWarnings("unchecked")
 105.674 -                Vector<E> v = (Vector<E>) super.clone();
 105.675 -            v.elementData = Arrays.copyOf(elementData, elementCount);
 105.676 -            v.modCount = 0;
 105.677 -            return v;
 105.678 -        } catch (CloneNotSupportedException e) {
 105.679 -            // this shouldn't happen, since we are Cloneable
 105.680 -            throw new InternalError();
 105.681 -        }
 105.682 -    }
 105.683 -
 105.684 -    /**
 105.685 -     * Returns an array containing all of the elements in this Vector
 105.686 -     * in the correct order.
 105.687 -     *
 105.688 -     * @since 1.2
 105.689 -     */
 105.690 -    public synchronized Object[] toArray() {
 105.691 -        return Arrays.copyOf(elementData, elementCount);
 105.692 -    }
 105.693 -
 105.694 -    /**
 105.695 -     * Returns an array containing all of the elements in this Vector in the
 105.696 -     * correct order; the runtime type of the returned array is that of the
 105.697 -     * specified array.  If the Vector fits in the specified array, it is
 105.698 -     * returned therein.  Otherwise, a new array is allocated with the runtime
 105.699 -     * type of the specified array and the size of this Vector.
 105.700 -     *
 105.701 -     * <p>If the Vector fits in the specified array with room to spare
 105.702 -     * (i.e., the array has more elements than the Vector),
 105.703 -     * the element in the array immediately following the end of the
 105.704 -     * Vector is set to null.  (This is useful in determining the length
 105.705 -     * of the Vector <em>only</em> if the caller knows that the Vector
 105.706 -     * does not contain any null elements.)
 105.707 -     *
 105.708 -     * @param a the array into which the elements of the Vector are to
 105.709 -     *          be stored, if it is big enough; otherwise, a new array of the
 105.710 -     *          same runtime type is allocated for this purpose.
 105.711 -     * @return an array containing the elements of the Vector
 105.712 -     * @throws ArrayStoreException if the runtime type of a is not a supertype
 105.713 -     * of the runtime type of every element in this Vector
 105.714 -     * @throws NullPointerException if the given array is null
 105.715 -     * @since 1.2
 105.716 -     */
 105.717 -    @SuppressWarnings("unchecked")
 105.718 -    public synchronized <T> T[] toArray(T[] a) {
 105.719 -        if (a.length < elementCount)
 105.720 -            return (T[]) Arrays.copyOf(elementData, elementCount, a.getClass());
 105.721 -
 105.722 -        System.arraycopy(elementData, 0, a, 0, elementCount);
 105.723 -
 105.724 -        if (a.length > elementCount)
 105.725 -            a[elementCount] = null;
 105.726 -
 105.727 -        return a;
 105.728 -    }
 105.729 -
 105.730 -    // Positional Access Operations
 105.731 -
 105.732 -    @SuppressWarnings("unchecked")
 105.733 -    E elementData(int index) {
 105.734 -        return (E) elementData[index];
 105.735 -    }
 105.736 -
 105.737 -    /**
 105.738 -     * Returns the element at the specified position in this Vector.
 105.739 -     *
 105.740 -     * @param index index of the element to return
 105.741 -     * @return object at the specified index
 105.742 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.743 -     *            ({@code index < 0 || index >= size()})
 105.744 -     * @since 1.2
 105.745 -     */
 105.746 -    public synchronized E get(int index) {
 105.747 -        if (index >= elementCount)
 105.748 -            throw new ArrayIndexOutOfBoundsException(index);
 105.749 -
 105.750 -        return elementData(index);
 105.751 -    }
 105.752 -
 105.753 -    /**
 105.754 -     * Replaces the element at the specified position in this Vector with the
 105.755 -     * specified element.
 105.756 -     *
 105.757 -     * @param index index of the element to replace
 105.758 -     * @param element element to be stored at the specified position
 105.759 -     * @return the element previously at the specified position
 105.760 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.761 -     *         ({@code index < 0 || index >= size()})
 105.762 -     * @since 1.2
 105.763 -     */
 105.764 -    public synchronized E set(int index, E element) {
 105.765 -        if (index >= elementCount)
 105.766 -            throw new ArrayIndexOutOfBoundsException(index);
 105.767 -
 105.768 -        E oldValue = elementData(index);
 105.769 -        elementData[index] = element;
 105.770 -        return oldValue;
 105.771 -    }
 105.772 -
 105.773 -    /**
 105.774 -     * Appends the specified element to the end of this Vector.
 105.775 -     *
 105.776 -     * @param e element to be appended to this Vector
 105.777 -     * @return {@code true} (as specified by {@link Collection#add})
 105.778 -     * @since 1.2
 105.779 -     */
 105.780 -    public synchronized boolean add(E e) {
 105.781 -        modCount++;
 105.782 -        ensureCapacityHelper(elementCount + 1);
 105.783 -        elementData[elementCount++] = e;
 105.784 -        return true;
 105.785 -    }
 105.786 -
 105.787 -    /**
 105.788 -     * Removes the first occurrence of the specified element in this Vector
 105.789 -     * If the Vector does not contain the element, it is unchanged.  More
 105.790 -     * formally, removes the element with the lowest index i such that
 105.791 -     * {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
 105.792 -     * an element exists).
 105.793 -     *
 105.794 -     * @param o element to be removed from this Vector, if present
 105.795 -     * @return true if the Vector contained the specified element
 105.796 -     * @since 1.2
 105.797 -     */
 105.798 -    public boolean remove(Object o) {
 105.799 -        return removeElement(o);
 105.800 -    }
 105.801 -
 105.802 -    /**
 105.803 -     * Inserts the specified element at the specified position in this Vector.
 105.804 -     * Shifts the element currently at that position (if any) and any
 105.805 -     * subsequent elements to the right (adds one to their indices).
 105.806 -     *
 105.807 -     * @param index index at which the specified element is to be inserted
 105.808 -     * @param element element to be inserted
 105.809 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.810 -     *         ({@code index < 0 || index > size()})
 105.811 -     * @since 1.2
 105.812 -     */
 105.813 -    public void add(int index, E element) {
 105.814 -        insertElementAt(element, index);
 105.815 -    }
 105.816 -
 105.817 -    /**
 105.818 -     * Removes the element at the specified position in this Vector.
 105.819 -     * Shifts any subsequent elements to the left (subtracts one from their
 105.820 -     * indices).  Returns the element that was removed from the Vector.
 105.821 -     *
 105.822 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.823 -     *         ({@code index < 0 || index >= size()})
 105.824 -     * @param index the index of the element to be removed
 105.825 -     * @return element that was removed
 105.826 -     * @since 1.2
 105.827 -     */
 105.828 -    public synchronized E remove(int index) {
 105.829 -        modCount++;
 105.830 -        if (index >= elementCount)
 105.831 -            throw new ArrayIndexOutOfBoundsException(index);
 105.832 -        E oldValue = elementData(index);
 105.833 -
 105.834 -        int numMoved = elementCount - index - 1;
 105.835 -        if (numMoved > 0)
 105.836 -            System.arraycopy(elementData, index+1, elementData, index,
 105.837 -                             numMoved);
 105.838 -        elementData[--elementCount] = null; // Let gc do its work
 105.839 -
 105.840 -        return oldValue;
 105.841 -    }
 105.842 -
 105.843 -    /**
 105.844 -     * Removes all of the elements from this Vector.  The Vector will
 105.845 -     * be empty after this call returns (unless it throws an exception).
 105.846 -     *
 105.847 -     * @since 1.2
 105.848 -     */
 105.849 -    public void clear() {
 105.850 -        removeAllElements();
 105.851 -    }
 105.852 -
 105.853 -    // Bulk Operations
 105.854 -
 105.855 -    /**
 105.856 -     * Returns true if this Vector contains all of the elements in the
 105.857 -     * specified Collection.
 105.858 -     *
 105.859 -     * @param   c a collection whose elements will be tested for containment
 105.860 -     *          in this Vector
 105.861 -     * @return true if this Vector contains all of the elements in the
 105.862 -     *         specified collection
 105.863 -     * @throws NullPointerException if the specified collection is null
 105.864 -     */
 105.865 -    public synchronized boolean containsAll(Collection<?> c) {
 105.866 -        return super.containsAll(c);
 105.867 -    }
 105.868 -
 105.869 -    /**
 105.870 -     * Appends all of the elements in the specified Collection to the end of
 105.871 -     * this Vector, in the order that they are returned by the specified
 105.872 -     * Collection's Iterator.  The behavior of this operation is undefined if
 105.873 -     * the specified Collection is modified while the operation is in progress.
 105.874 -     * (This implies that the behavior of this call is undefined if the
 105.875 -     * specified Collection is this Vector, and this Vector is nonempty.)
 105.876 -     *
 105.877 -     * @param c elements to be inserted into this Vector
 105.878 -     * @return {@code true} if this Vector changed as a result of the call
 105.879 -     * @throws NullPointerException if the specified collection is null
 105.880 -     * @since 1.2
 105.881 -     */
 105.882 -    public synchronized boolean addAll(Collection<? extends E> c) {
 105.883 -        modCount++;
 105.884 -        Object[] a = c.toArray();
 105.885 -        int numNew = a.length;
 105.886 -        ensureCapacityHelper(elementCount + numNew);
 105.887 -        System.arraycopy(a, 0, elementData, elementCount, numNew);
 105.888 -        elementCount += numNew;
 105.889 -        return numNew != 0;
 105.890 -    }
 105.891 -
 105.892 -    /**
 105.893 -     * Removes from this Vector all of its elements that are contained in the
 105.894 -     * specified Collection.
 105.895 -     *
 105.896 -     * @param c a collection of elements to be removed from the Vector
 105.897 -     * @return true if this Vector changed as a result of the call
 105.898 -     * @throws ClassCastException if the types of one or more elements
 105.899 -     *         in this vector are incompatible with the specified
 105.900 -     *         collection
 105.901 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
 105.902 -     * @throws NullPointerException if this vector contains one or more null
 105.903 -     *         elements and the specified collection does not support null
 105.904 -     *         elements
 105.905 -     * (<a href="Collection.html#optional-restrictions">optional</a>),
 105.906 -     *         or if the specified collection is null
 105.907 -     * @since 1.2
 105.908 -     */
 105.909 -    public synchronized boolean removeAll(Collection<?> c) {
 105.910 -        return super.removeAll(c);
 105.911 -    }
 105.912 -
 105.913 -    /**
 105.914 -     * Retains only the elements in this Vector that are contained in the
 105.915 -     * specified Collection.  In other words, removes from this Vector all
 105.916 -     * of its elements that are not contained in the specified Collection.
 105.917 -     *
 105.918 -     * @param c a collection of elements to be retained in this Vector
 105.919 -     *          (all other elements are removed)
 105.920 -     * @return true if this Vector changed as a result of the call
 105.921 -     * @throws ClassCastException if the types of one or more elements
 105.922 -     *         in this vector are incompatible with the specified
 105.923 -     *         collection
 105.924 -     * (<a href="Collection.html#optional-restrictions">optional</a>)
 105.925 -     * @throws NullPointerException if this vector contains one or more null
 105.926 -     *         elements and the specified collection does not support null
 105.927 -     *         elements
 105.928 -     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 105.929 -     *         or if the specified collection is null
 105.930 -     * @since 1.2
 105.931 -     */
 105.932 -    public synchronized boolean retainAll(Collection<?> c) {
 105.933 -        return super.retainAll(c);
 105.934 -    }
 105.935 -
 105.936 -    /**
 105.937 -     * Inserts all of the elements in the specified Collection into this
 105.938 -     * Vector at the specified position.  Shifts the element currently at
 105.939 -     * that position (if any) and any subsequent elements to the right
 105.940 -     * (increases their indices).  The new elements will appear in the Vector
 105.941 -     * in the order that they are returned by the specified Collection's
 105.942 -     * iterator.
 105.943 -     *
 105.944 -     * @param index index at which to insert the first element from the
 105.945 -     *              specified collection
 105.946 -     * @param c elements to be inserted into this Vector
 105.947 -     * @return {@code true} if this Vector changed as a result of the call
 105.948 -     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 105.949 -     *         ({@code index < 0 || index > size()})
 105.950 -     * @throws NullPointerException if the specified collection is null
 105.951 -     * @since 1.2
 105.952 -     */
 105.953 -    public synchronized boolean addAll(int index, Collection<? extends E> c) {
 105.954 -        modCount++;
 105.955 -        if (index < 0 || index > elementCount)
 105.956 -            throw new ArrayIndexOutOfBoundsException(index);
 105.957 -
 105.958 -        Object[] a = c.toArray();
 105.959 -        int numNew = a.length;
 105.960 -        ensureCapacityHelper(elementCount + numNew);
 105.961 -
 105.962 -        int numMoved = elementCount - index;
 105.963 -        if (numMoved > 0)
 105.964 -            System.arraycopy(elementData, index, elementData, index + numNew,
 105.965 -                             numMoved);
 105.966 -
 105.967 -        System.arraycopy(a, 0, elementData, index, numNew);
 105.968 -        elementCount += numNew;
 105.969 -        return numNew != 0;
 105.970 -    }
 105.971 -
 105.972 -    /**
 105.973 -     * Compares the specified Object with this Vector for equality.  Returns
 105.974 -     * true if and only if the specified Object is also a List, both Lists
 105.975 -     * have the same size, and all corresponding pairs of elements in the two
 105.976 -     * Lists are <em>equal</em>.  (Two elements {@code e1} and
 105.977 -     * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
 105.978 -     * e1.equals(e2))}.)  In other words, two Lists are defined to be
 105.979 -     * equal if they contain the same elements in the same order.
 105.980 -     *
 105.981 -     * @param o the Object to be compared for equality with this Vector
 105.982 -     * @return true if the specified Object is equal to this Vector
 105.983 -     */
 105.984 -    public synchronized boolean equals(Object o) {
 105.985 -        return super.equals(o);
 105.986 -    }
 105.987 -
 105.988 -    /**
 105.989 -     * Returns the hash code value for this Vector.
 105.990 -     */
 105.991 -    public synchronized int hashCode() {
 105.992 -        return super.hashCode();
 105.993 -    }
 105.994 -
 105.995 -    /**
 105.996 -     * Returns a string representation of this Vector, containing
 105.997 -     * the String representation of each element.
 105.998 -     */
 105.999 -    public synchronized String toString() {
105.1000 -        return super.toString();
105.1001 -    }
105.1002 -
105.1003 -    /**
105.1004 -     * Returns a view of the portion of this List between fromIndex,
105.1005 -     * inclusive, and toIndex, exclusive.  (If fromIndex and toIndex are
105.1006 -     * equal, the returned List is empty.)  The returned List is backed by this
105.1007 -     * List, so changes in the returned List are reflected in this List, and
105.1008 -     * vice-versa.  The returned List supports all of the optional List
105.1009 -     * operations supported by this List.
105.1010 -     *
105.1011 -     * <p>This method eliminates the need for explicit range operations (of
105.1012 -     * the sort that commonly exist for arrays).  Any operation that expects
105.1013 -     * a List can be used as a range operation by operating on a subList view
105.1014 -     * instead of a whole List.  For example, the following idiom
105.1015 -     * removes a range of elements from a List:
105.1016 -     * <pre>
105.1017 -     *      list.subList(from, to).clear();
105.1018 -     * </pre>
105.1019 -     * Similar idioms may be constructed for indexOf and lastIndexOf,
105.1020 -     * and all of the algorithms in the Collections class can be applied to
105.1021 -     * a subList.
105.1022 -     *
105.1023 -     * <p>The semantics of the List returned by this method become undefined if
105.1024 -     * the backing list (i.e., this List) is <i>structurally modified</i> in
105.1025 -     * any way other than via the returned List.  (Structural modifications are
105.1026 -     * those that change the size of the List, or otherwise perturb it in such
105.1027 -     * a fashion that iterations in progress may yield incorrect results.)
105.1028 -     *
105.1029 -     * @param fromIndex low endpoint (inclusive) of the subList
105.1030 -     * @param toIndex high endpoint (exclusive) of the subList
105.1031 -     * @return a view of the specified range within this List
105.1032 -     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
105.1033 -     *         {@code (fromIndex < 0 || toIndex > size)}
105.1034 -     * @throws IllegalArgumentException if the endpoint indices are out of order
105.1035 -     *         {@code (fromIndex > toIndex)}
105.1036 -     */
105.1037 -    public synchronized List<E> subList(int fromIndex, int toIndex) {
105.1038 -        return Collections.synchronizedList(super.subList(fromIndex, toIndex),
105.1039 -                                            this);
105.1040 -    }
105.1041 -
105.1042 -    /**
105.1043 -     * Removes from this list all of the elements whose index is between
105.1044 -     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
105.1045 -     * Shifts any succeeding elements to the left (reduces their index).
105.1046 -     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
105.1047 -     * (If {@code toIndex==fromIndex}, this operation has no effect.)
105.1048 -     */
105.1049 -    protected synchronized void removeRange(int fromIndex, int toIndex) {
105.1050 -        modCount++;
105.1051 -        int numMoved = elementCount - toIndex;
105.1052 -        System.arraycopy(elementData, toIndex, elementData, fromIndex,
105.1053 -                         numMoved);
105.1054 -
105.1055 -        // Let gc do its work
105.1056 -        int newElementCount = elementCount - (toIndex-fromIndex);
105.1057 -        while (elementCount != newElementCount)
105.1058 -            elementData[--elementCount] = null;
105.1059 -    }
105.1060 -
105.1061 -    /**
105.1062 -     * Returns a list iterator over the elements in this list (in proper
105.1063 -     * sequence), starting at the specified position in the list.
105.1064 -     * The specified index indicates the first element that would be
105.1065 -     * returned by an initial call to {@link ListIterator#next next}.
105.1066 -     * An initial call to {@link ListIterator#previous previous} would
105.1067 -     * return the element with the specified index minus one.
105.1068 -     *
105.1069 -     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
105.1070 -     *
105.1071 -     * @throws IndexOutOfBoundsException {@inheritDoc}
105.1072 -     */
105.1073 -    public synchronized ListIterator<E> listIterator(int index) {
105.1074 -        if (index < 0 || index > elementCount)
105.1075 -            throw new IndexOutOfBoundsException("Index: "+index);
105.1076 -        return new ListItr(index);
105.1077 -    }
105.1078 -
105.1079 -    /**
105.1080 -     * Returns a list iterator over the elements in this list (in proper
105.1081 -     * sequence).
105.1082 -     *
105.1083 -     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
105.1084 -     *
105.1085 -     * @see #listIterator(int)
105.1086 -     */
105.1087 -    public synchronized ListIterator<E> listIterator() {
105.1088 -        return new ListItr(0);
105.1089 -    }
105.1090 -
105.1091 -    /**
105.1092 -     * Returns an iterator over the elements in this list in proper sequence.
105.1093 -     *
105.1094 -     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
105.1095 -     *
105.1096 -     * @return an iterator over the elements in this list in proper sequence
105.1097 -     */
105.1098 -    public synchronized Iterator<E> iterator() {
105.1099 -        return new Itr();
105.1100 -    }
105.1101 -
105.1102 -    /**
105.1103 -     * An optimized version of AbstractList.Itr
105.1104 -     */
105.1105 -    private class Itr implements Iterator<E> {
105.1106 -        int cursor;       // index of next element to return
105.1107 -        int lastRet = -1; // index of last element returned; -1 if no such
105.1108 -        int expectedModCount = modCount;
105.1109 -
105.1110 -        public boolean hasNext() {
105.1111 -            // Racy but within spec, since modifications are checked
105.1112 -            // within or after synchronization in next/previous
105.1113 -            return cursor != elementCount;
105.1114 -        }
105.1115 -
105.1116 -        public E next() {
105.1117 -            synchronized (Vector.this) {
105.1118 -                checkForComodification();
105.1119 -                int i = cursor;
105.1120 -                if (i >= elementCount)
105.1121 -                    throw new NoSuchElementException();
105.1122 -                cursor = i + 1;
105.1123 -                return elementData(lastRet = i);
105.1124 -            }
105.1125 -        }
105.1126 -
105.1127 -        public void remove() {
105.1128 -            if (lastRet == -1)
105.1129 -                throw new IllegalStateException();
105.1130 -            synchronized (Vector.this) {
105.1131 -                checkForComodification();
105.1132 -                Vector.this.remove(lastRet);
105.1133 -                expectedModCount = modCount;
105.1134 -            }
105.1135 -            cursor = lastRet;
105.1136 -            lastRet = -1;
105.1137 -        }
105.1138 -
105.1139 -        final void checkForComodification() {
105.1140 -            if (modCount != expectedModCount)
105.1141 -                throw new ConcurrentModificationException();
105.1142 -        }
105.1143 -    }
105.1144 -
105.1145 -    /**
105.1146 -     * An optimized version of AbstractList.ListItr
105.1147 -     */
105.1148 -    final class ListItr extends Itr implements ListIterator<E> {
105.1149 -        ListItr(int index) {
105.1150 -            super();
105.1151 -            cursor = index;
105.1152 -        }
105.1153 -
105.1154 -        public boolean hasPrevious() {
105.1155 -            return cursor != 0;
105.1156 -        }
105.1157 -
105.1158 -        public int nextIndex() {
105.1159 -            return cursor;
105.1160 -        }
105.1161 -
105.1162 -        public int previousIndex() {
105.1163 -            return cursor - 1;
105.1164 -        }
105.1165 -
105.1166 -        public E previous() {
105.1167 -            synchronized (Vector.this) {
105.1168 -                checkForComodification();
105.1169 -                int i = cursor - 1;
105.1170 -                if (i < 0)
105.1171 -                    throw new NoSuchElementException();
105.1172 -                cursor = i;
105.1173 -                return elementData(lastRet = i);
105.1174 -            }
105.1175 -        }
105.1176 -
105.1177 -        public void set(E e) {
105.1178 -            if (lastRet == -1)
105.1179 -                throw new IllegalStateException();
105.1180 -            synchronized (Vector.this) {
105.1181 -                checkForComodification();
105.1182 -                Vector.this.set(lastRet, e);
105.1183 -            }
105.1184 -        }
105.1185 -
105.1186 -        public void add(E e) {
105.1187 -            int i = cursor;
105.1188 -            synchronized (Vector.this) {
105.1189 -                checkForComodification();
105.1190 -                Vector.this.add(i, e);
105.1191 -                expectedModCount = modCount;
105.1192 -            }
105.1193 -            cursor = i + 1;
105.1194 -            lastRet = -1;
105.1195 -        }
105.1196 -    }
105.1197 -}
   106.1 --- a/emul/compact/src/main/java/java/util/concurrent/Callable.java	Mon Feb 25 19:00:08 2013 +0100
   106.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.3 @@ -1,65 +0,0 @@
   106.4 -/*
   106.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   106.6 - *
   106.7 - * This code is free software; you can redistribute it and/or modify it
   106.8 - * under the terms of the GNU General Public License version 2 only, as
   106.9 - * published by the Free Software Foundation.  Oracle designates this
  106.10 - * particular file as subject to the "Classpath" exception as provided
  106.11 - * by Oracle in the LICENSE file that accompanied this code.
  106.12 - *
  106.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
  106.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  106.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  106.16 - * version 2 for more details (a copy is included in the LICENSE file that
  106.17 - * accompanied this code).
  106.18 - *
  106.19 - * You should have received a copy of the GNU General Public License version
  106.20 - * 2 along with this work; if not, write to the Free Software Foundation,
  106.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  106.22 - *
  106.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  106.24 - * or visit www.oracle.com if you need additional information or have any
  106.25 - * questions.
  106.26 - */
  106.27 -
  106.28 -/*
  106.29 - * This file is available under and governed by the GNU General Public
  106.30 - * License version 2 only, as published by the Free Software Foundation.
  106.31 - * However, the following notice accompanied the original version of this
  106.32 - * file:
  106.33 - *
  106.34 - * Written by Doug Lea with assistance from members of JCP JSR-166
  106.35 - * Expert Group and released to the public domain, as explained at
  106.36 - * http://creativecommons.org/publicdomain/zero/1.0/
  106.37 - */
  106.38 -
  106.39 -package java.util.concurrent;
  106.40 -
  106.41 -/**
  106.42 - * A task that returns a result and may throw an exception.
  106.43 - * Implementors define a single method with no arguments called
  106.44 - * <tt>call</tt>.
  106.45 - *
  106.46 - * <p>The <tt>Callable</tt> interface is similar to {@link
  106.47 - * java.lang.Runnable}, in that both are designed for classes whose
  106.48 - * instances are potentially executed by another thread.  A
  106.49 - * <tt>Runnable</tt>, however, does not return a result and cannot
  106.50 - * throw a checked exception.
  106.51 - *
  106.52 - * <p> The {@link Executors} class contains utility methods to
  106.53 - * convert from other common forms to <tt>Callable</tt> classes.
  106.54 - *
  106.55 - * @see Executor
  106.56 - * @since 1.5
  106.57 - * @author Doug Lea
  106.58 - * @param <V> the result type of method <tt>call</tt>
  106.59 - */
  106.60 -public interface Callable<V> {
  106.61 -    /**
  106.62 -     * Computes a result, or throws an exception if unable to do so.
  106.63 -     *
  106.64 -     * @return computed result
  106.65 -     * @throws Exception if unable to compute a result
  106.66 -     */
  106.67 -    V call() throws Exception;
  106.68 -}
   107.1 --- a/emul/compact/src/main/java/java/util/concurrent/TimeUnit.java	Mon Feb 25 19:00:08 2013 +0100
   107.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.3 @@ -1,367 +0,0 @@
   107.4 -/*
   107.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   107.6 - *
   107.7 - * This code is free software; you can redistribute it and/or modify it
   107.8 - * under the terms of the GNU General Public License version 2 only, as
   107.9 - * published by the Free Software Foundation.  Oracle designates this
  107.10 - * particular file as subject to the "Classpath" exception as provided
  107.11 - * by Oracle in the LICENSE file that accompanied this code.
  107.12 - *
  107.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
  107.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  107.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  107.16 - * version 2 for more details (a copy is included in the LICENSE file that
  107.17 - * accompanied this code).
  107.18 - *
  107.19 - * You should have received a copy of the GNU General Public License version
  107.20 - * 2 along with this work; if not, write to the Free Software Foundation,
  107.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  107.22 - *
  107.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  107.24 - * or visit www.oracle.com if you need additional information or have any
  107.25 - * questions.
  107.26 - */
  107.27 -
  107.28 -/*
  107.29 - * This file is available under and governed by the GNU General Public
  107.30 - * License version 2 only, as published by the Free Software Foundation.
  107.31 - * However, the following notice accompanied the original version of this
  107.32 - * file:
  107.33 - *
  107.34 - * Written by Doug Lea with assistance from members of JCP JSR-166
  107.35 - * Expert Group and released to the public domain, as explained at
  107.36 - * http://creativecommons.org/publicdomain/zero/1.0/
  107.37 - */
  107.38 -
  107.39 -package java.util.concurrent;
  107.40 -
  107.41 -/**
  107.42 - * A <tt>TimeUnit</tt> represents time durations at a given unit of
  107.43 - * granularity and provides utility methods to convert across units,
  107.44 - * and to perform timing and delay operations in these units.  A
  107.45 - * <tt>TimeUnit</tt> does not maintain time information, but only
  107.46 - * helps organize and use time representations that may be maintained
  107.47 - * separately across various contexts.  A nanosecond is defined as one
  107.48 - * thousandth of a microsecond, a microsecond as one thousandth of a
  107.49 - * millisecond, a millisecond as one thousandth of a second, a minute
  107.50 - * as sixty seconds, an hour as sixty minutes, and a day as twenty four
  107.51 - * hours.
  107.52 - *
  107.53 - * <p>A <tt>TimeUnit</tt> is mainly used to inform time-based methods
  107.54 - * how a given timing parameter should be interpreted. For example,
  107.55 - * the following code will timeout in 50 milliseconds if the {@link
  107.56 - * java.util.concurrent.locks.Lock lock} is not available:
  107.57 - *
  107.58 - * <pre>  Lock lock = ...;
  107.59 - *  if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...
  107.60 - * </pre>
  107.61 - * while this code will timeout in 50 seconds:
  107.62 - * <pre>
  107.63 - *  Lock lock = ...;
  107.64 - *  if (lock.tryLock(50L, TimeUnit.SECONDS)) ...
  107.65 - * </pre>
  107.66 - *
  107.67 - * Note however, that there is no guarantee that a particular timeout
  107.68 - * implementation will be able to notice the passage of time at the
  107.69 - * same granularity as the given <tt>TimeUnit</tt>.
  107.70 - *
  107.71 - * @since 1.5
  107.72 - * @author Doug Lea
  107.73 - */
  107.74 -public enum TimeUnit {
  107.75 -    NANOSECONDS {
  107.76 -        public long toNanos(long d)   { return d; }
  107.77 -        public long toMicros(long d)  { return d/(C1/C0); }
  107.78 -        public long toMillis(long d)  { return d/(C2/C0); }
  107.79 -        public long toSeconds(long d) { return d/(C3/C0); }
  107.80 -        public long toMinutes(long d) { return d/(C4/C0); }
  107.81 -        public long toHours(long d)   { return d/(C5/C0); }
  107.82 -        public long toDays(long d)    { return d/(C6/C0); }
  107.83 -        public long convert(long d, TimeUnit u) { return u.toNanos(d); }
  107.84 -        int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
  107.85 -    },
  107.86 -    MICROSECONDS {
  107.87 -        public long toNanos(long d)   { return x(d, C1/C0, MAX/(C1/C0)); }
  107.88 -        public long toMicros(long d)  { return d; }
  107.89 -        public long toMillis(long d)  { return d/(C2/C1); }
  107.90 -        public long toSeconds(long d) { return d/(C3/C1); }
  107.91 -        public long toMinutes(long d) { return d/(C4/C1); }
  107.92 -        public long toHours(long d)   { return d/(C5/C1); }
  107.93 -        public long toDays(long d)    { return d/(C6/C1); }
  107.94 -        public long convert(long d, TimeUnit u) { return u.toMicros(d); }
  107.95 -        int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
  107.96 -    },
  107.97 -    MILLISECONDS {
  107.98 -        public long toNanos(long d)   { return x(d, C2/C0, MAX/(C2/C0)); }
  107.99 -        public long toMicros(long d)  { return x(d, C2/C1, MAX/(C2/C1)); }
 107.100 -        public long toMillis(long d)  { return d; }
 107.101 -        public long toSeconds(long d) { return d/(C3/C2); }
 107.102 -        public long toMinutes(long d) { return d/(C4/C2); }
 107.103 -        public long toHours(long d)   { return d/(C5/C2); }
 107.104 -        public long toDays(long d)    { return d/(C6/C2); }
 107.105 -        public long convert(long d, TimeUnit u) { return u.toMillis(d); }
 107.106 -        int excessNanos(long d, long m) { return 0; }
 107.107 -    },
 107.108 -    SECONDS {
 107.109 -        public long toNanos(long d)   { return x(d, C3/C0, MAX/(C3/C0)); }
 107.110 -        public long toMicros(long d)  { return x(d, C3/C1, MAX/(C3/C1)); }
 107.111 -        public long toMillis(long d)  { return x(d, C3/C2, MAX/(C3/C2)); }
 107.112 -        public long toSeconds(long d) { return d; }
 107.113 -        public long toMinutes(long d) { return d/(C4/C3); }
 107.114 -        public long toHours(long d)   { return d/(C5/C3); }
 107.115 -        public long toDays(long d)    { return d/(C6/C3); }
 107.116 -        public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
 107.117 -        int excessNanos(long d, long m) { return 0; }
 107.118 -    },
 107.119 -    MINUTES {
 107.120 -        public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
 107.121 -        public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
 107.122 -        public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
 107.123 -        public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); }
 107.124 -        public long toMinutes(long d) { return d; }
 107.125 -        public long toHours(long d)   { return d/(C5/C4); }
 107.126 -        public long toDays(long d)    { return d/(C6/C4); }
 107.127 -        public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
 107.128 -        int excessNanos(long d, long m) { return 0; }
 107.129 -    },
 107.130 -    HOURS {
 107.131 -        public long toNanos(long d)   { return x(d, C5/C0, MAX/(C5/C0)); }
 107.132 -        public long toMicros(long d)  { return x(d, C5/C1, MAX/(C5/C1)); }
 107.133 -        public long toMillis(long d)  { return x(d, C5/C2, MAX/(C5/C2)); }
 107.134 -        public long toSeconds(long d) { return x(d, C5/C3, MAX/(C5/C3)); }
 107.135 -        public long toMinutes(long d) { return x(d, C5/C4, MAX/(C5/C4)); }
 107.136 -        public long toHours(long d)   { return d; }
 107.137 -        public long toDays(long d)    { return d/(C6/C5); }
 107.138 -        public long convert(long d, TimeUnit u) { return u.toHours(d); }
 107.139 -        int excessNanos(long d, long m) { return 0; }
 107.140 -    },
 107.141 -    DAYS {
 107.142 -        public long toNanos(long d)   { return x(d, C6/C0, MAX/(C6/C0)); }
 107.143 -        public long toMicros(long d)  { return x(d, C6/C1, MAX/(C6/C1)); }
 107.144 -        public long toMillis(long d)  { return x(d, C6/C2, MAX/(C6/C2)); }
 107.145 -        public long toSeconds(long d) { return x(d, C6/C3, MAX/(C6/C3)); }
 107.146 -        public long toMinutes(long d) { return x(d, C6/C4, MAX/(C6/C4)); }
 107.147 -        public long toHours(long d)   { return x(d, C6/C5, MAX/(C6/C5)); }
 107.148 -        public long toDays(long d)    { return d; }
 107.149 -        public long convert(long d, TimeUnit u) { return u.toDays(d); }
 107.150 -        int excessNanos(long d, long m) { return 0; }
 107.151 -    };
 107.152 -
 107.153 -    // Handy constants for conversion methods
 107.154 -    static final long C0 = 1L;
 107.155 -    static final long C1 = C0 * 1000L;
 107.156 -    static final long C2 = C1 * 1000L;
 107.157 -    static final long C3 = C2 * 1000L;
 107.158 -    static final long C4 = C3 * 60L;
 107.159 -    static final long C5 = C4 * 60L;
 107.160 -    static final long C6 = C5 * 24L;
 107.161 -
 107.162 -    static final long MAX = Long.MAX_VALUE;
 107.163 -
 107.164 -    /**
 107.165 -     * Scale d by m, checking for overflow.
 107.166 -     * This has a short name to make above code more readable.
 107.167 -     */
 107.168 -    static long x(long d, long m, long over) {
 107.169 -        if (d >  over) return Long.MAX_VALUE;
 107.170 -        if (d < -over) return Long.MIN_VALUE;
 107.171 -        return d * m;
 107.172 -    }
 107.173 -
 107.174 -    // To maintain full signature compatibility with 1.5, and to improve the
 107.175 -    // clarity of the generated javadoc (see 6287639: Abstract methods in
 107.176 -    // enum classes should not be listed as abstract), method convert
 107.177 -    // etc. are not declared abstract but otherwise act as abstract methods.
 107.178 -
 107.179 -    /**
 107.180 -     * Convert the given time duration in the given unit to this
 107.181 -     * unit.  Conversions from finer to coarser granularities
 107.182 -     * truncate, so lose precision. For example converting
 107.183 -     * <tt>999</tt> milliseconds to seconds results in
 107.184 -     * <tt>0</tt>. Conversions from coarser to finer granularities
 107.185 -     * with arguments that would numerically overflow saturate to
 107.186 -     * <tt>Long.MIN_VALUE</tt> if negative or <tt>Long.MAX_VALUE</tt>
 107.187 -     * if positive.
 107.188 -     *
 107.189 -     * <p>For example, to convert 10 minutes to milliseconds, use:
 107.190 -     * <tt>TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)</tt>
 107.191 -     *
 107.192 -     * @param sourceDuration the time duration in the given <tt>sourceUnit</tt>
 107.193 -     * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
 107.194 -     * @return the converted duration in this unit,
 107.195 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.196 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.197 -     */
 107.198 -    public long convert(long sourceDuration, TimeUnit sourceUnit) {
 107.199 -        throw new AbstractMethodError();
 107.200 -    }
 107.201 -
 107.202 -    /**
 107.203 -     * Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>.
 107.204 -     * @param duration the duration
 107.205 -     * @return the converted duration,
 107.206 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.207 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.208 -     * @see #convert
 107.209 -     */
 107.210 -    public long toNanos(long duration) {
 107.211 -        throw new AbstractMethodError();
 107.212 -    }
 107.213 -
 107.214 -    /**
 107.215 -     * Equivalent to <tt>MICROSECONDS.convert(duration, this)</tt>.
 107.216 -     * @param duration the duration
 107.217 -     * @return the converted duration,
 107.218 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.219 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.220 -     * @see #convert
 107.221 -     */
 107.222 -    public long toMicros(long duration) {
 107.223 -        throw new AbstractMethodError();
 107.224 -    }
 107.225 -
 107.226 -    /**
 107.227 -     * Equivalent to <tt>MILLISECONDS.convert(duration, this)</tt>.
 107.228 -     * @param duration the duration
 107.229 -     * @return the converted duration,
 107.230 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.231 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.232 -     * @see #convert
 107.233 -     */
 107.234 -    public long toMillis(long duration) {
 107.235 -        throw new AbstractMethodError();
 107.236 -    }
 107.237 -
 107.238 -    /**
 107.239 -     * Equivalent to <tt>SECONDS.convert(duration, this)</tt>.
 107.240 -     * @param duration the duration
 107.241 -     * @return the converted duration,
 107.242 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.243 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.244 -     * @see #convert
 107.245 -     */
 107.246 -    public long toSeconds(long duration) {
 107.247 -        throw new AbstractMethodError();
 107.248 -    }
 107.249 -
 107.250 -    /**
 107.251 -     * Equivalent to <tt>MINUTES.convert(duration, this)</tt>.
 107.252 -     * @param duration the duration
 107.253 -     * @return the converted duration,
 107.254 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.255 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.256 -     * @see #convert
 107.257 -     * @since 1.6
 107.258 -     */
 107.259 -    public long toMinutes(long duration) {
 107.260 -        throw new AbstractMethodError();
 107.261 -    }
 107.262 -
 107.263 -    /**
 107.264 -     * Equivalent to <tt>HOURS.convert(duration, this)</tt>.
 107.265 -     * @param duration the duration
 107.266 -     * @return the converted duration,
 107.267 -     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 107.268 -     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 107.269 -     * @see #convert
 107.270 -     * @since 1.6
 107.271 -     */
 107.272 -    public long toHours(long duration) {
 107.273 -        throw new AbstractMethodError();
 107.274 -    }
 107.275 -
 107.276 -    /**
 107.277 -     * Equivalent to <tt>DAYS.convert(duration, this)</tt>.
 107.278 -     * @param duration the duration
 107.279 -     * @return the converted duration
 107.280 -     * @see #convert
 107.281 -     * @since 1.6
 107.282 -     */
 107.283 -    public long toDays(long duration) {
 107.284 -        throw new AbstractMethodError();
 107.285 -    }
 107.286 -
 107.287 -    /**
 107.288 -     * Utility to compute the excess-nanosecond argument to wait,
 107.289 -     * sleep, join.
 107.290 -     * @param d the duration
 107.291 -     * @param m the number of milliseconds
 107.292 -     * @return the number of nanoseconds
 107.293 -     */
 107.294 -    abstract int excessNanos(long d, long m);
 107.295 -
 107.296 -    /**
 107.297 -     * Performs a timed {@link Object#wait(long, int) Object.wait}
 107.298 -     * using this time unit.
 107.299 -     * This is a convenience method that converts timeout arguments
 107.300 -     * into the form required by the <tt>Object.wait</tt> method.
 107.301 -     *
 107.302 -     * <p>For example, you could implement a blocking <tt>poll</tt>
 107.303 -     * method (see {@link BlockingQueue#poll BlockingQueue.poll})
 107.304 -     * using:
 107.305 -     *
 107.306 -     *  <pre> {@code
 107.307 -     * public synchronized Object poll(long timeout, TimeUnit unit)
 107.308 -     *     throws InterruptedException {
 107.309 -     *   while (empty) {
 107.310 -     *     unit.timedWait(this, timeout);
 107.311 -     *     ...
 107.312 -     *   }
 107.313 -     * }}</pre>
 107.314 -     *
 107.315 -     * @param obj the object to wait on
 107.316 -     * @param timeout the maximum time to wait. If less than
 107.317 -     * or equal to zero, do not wait at all.
 107.318 -     * @throws InterruptedException if interrupted while waiting
 107.319 -     */
 107.320 -    public void timedWait(Object obj, long timeout)
 107.321 -            throws InterruptedException {
 107.322 -        if (timeout > 0) {
 107.323 -            long ms = toMillis(timeout);
 107.324 -            int ns = excessNanos(timeout, ms);
 107.325 -            obj.wait(ms, ns);
 107.326 -        }
 107.327 -    }
 107.328 -
 107.329 -    /**
 107.330 -     * Performs a timed {@link Thread#join(long, int) Thread.join}
 107.331 -     * using this time unit.
 107.332 -     * This is a convenience method that converts time arguments into the
 107.333 -     * form required by the <tt>Thread.join</tt> method.
 107.334 -     *
 107.335 -     * @param thread the thread to wait for
 107.336 -     * @param timeout the maximum time to wait. If less than
 107.337 -     * or equal to zero, do not wait at all.
 107.338 -     * @throws InterruptedException if interrupted while waiting
 107.339 -     */
 107.340 -//    public void timedJoin(Thread thread, long timeout)
 107.341 -//            throws InterruptedException {
 107.342 -//        if (timeout > 0) {
 107.343 -//            long ms = toMillis(timeout);
 107.344 -//            int ns = excessNanos(timeout, ms);
 107.345 -//            thread.join(ms, ns);
 107.346 -//        }
 107.347 -//    }
 107.348 -
 107.349 -    /**
 107.350 -     * Performs a {@link Thread#sleep(long, int) Thread.sleep} using
 107.351 -     * this time unit.
 107.352 -     * This is a convenience method that converts time arguments into the
 107.353 -     * form required by the <tt>Thread.sleep</tt> method.
 107.354 -     *
 107.355 -     * @param timeout the minimum time to sleep. If less than
 107.356 -     * or equal to zero, do not sleep at all.
 107.357 -     * @throws InterruptedException if interrupted while sleeping
 107.358 -     */
 107.359 -    public void sleep(long timeout) throws InterruptedException {
 107.360 -        if (timeout > 0) {
 107.361 -            long ms = toMillis(timeout);
 107.362 -            int ns = excessNanos(timeout, ms);
 107.363 -            Object o = new Object();
 107.364 -            synchronized (o) {
 107.365 -                o.wait(ms, ns);
 107.366 -            }
 107.367 -        }
 107.368 -    }
 107.369 -
 107.370 -}
   108.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java	Mon Feb 25 19:00:08 2013 +0100
   108.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.3 @@ -1,107 +0,0 @@
   108.4 -/**
   108.5 - * Back 2 Browser Bytecode Translator
   108.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   108.7 - *
   108.8 - * This program is free software: you can redistribute it and/or modify
   108.9 - * it under the terms of the GNU General Public License as published by
  108.10 - * the Free Software Foundation, version 2 of the License.
  108.11 - *
  108.12 - * This program is distributed in the hope that it will be useful,
  108.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  108.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  108.15 - * GNU General Public License for more details.
  108.16 - *
  108.17 - * You should have received a copy of the GNU General Public License
  108.18 - * along with this program. Look for COPYING file in the top folder.
  108.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  108.20 - */
  108.21 -package org.apidesign.bck2brwsr.compact.tck;
  108.22 -
  108.23 -import java.util.ArrayList;
  108.24 -import java.util.Arrays;
  108.25 -import java.util.Collection;
  108.26 -import java.util.Comparator;
  108.27 -import java.util.HashMap;
  108.28 -import java.util.HashSet;
  108.29 -import java.util.List;
  108.30 -import java.util.Map;
  108.31 -import java.util.Map.Entry;
  108.32 -import java.util.Vector;
  108.33 -import org.apidesign.bck2brwsr.vmtest.Compare;
  108.34 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  108.35 -import org.testng.annotations.Factory;
  108.36 -
  108.37 -/**
  108.38 - *
  108.39 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  108.40 - */
  108.41 -public class CollectionsTest {
  108.42 -    @Compare public String sortStringsInArray() {
  108.43 -        List<String> list = new ArrayList<>();
  108.44 -        list.add("one");
  108.45 -        list.add("two");
  108.46 -        list.add("three");
  108.47 -        list.add("four");
  108.48 -        list.add("five");
  108.49 -        list.add("six");
  108.50 -        list.add("seven");
  108.51 -        list.add("eight");
  108.52 -        list.add("nine");
  108.53 -        list.add("ten");
  108.54 -        
  108.55 -        String[] arr = list.toArray(new String[list.size()]);
  108.56 -        Arrays.sort(arr);
  108.57 -        
  108.58 -        return Arrays.asList(arr).toString();
  108.59 -    }
  108.60 -    
  108.61 -    @Compare public String sortStringsInHashSet() {
  108.62 -        Collection<String> list = new HashSet<>();
  108.63 -        list.add("one");
  108.64 -        list.add("two");
  108.65 -        list.add("three");
  108.66 -        list.add("four");
  108.67 -        list.add("five");
  108.68 -        list.add("six");
  108.69 -        list.add("seven");
  108.70 -        list.add("eight");
  108.71 -        list.add("nine");
  108.72 -        list.add("ten");
  108.73 -        
  108.74 -        String[] arr = list.toArray(new String[0]);
  108.75 -        Arrays.sort(arr);
  108.76 -        
  108.77 -        return Arrays.asList(arr).toString();
  108.78 -    }
  108.79 -
  108.80 -    @SuppressWarnings("unchecked")
  108.81 -    @Compare public String sortStringsInHashMapWithComparator() {
  108.82 -        class C implements Comparator<Map.Entry<String,Integer>> {
  108.83 -            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
  108.84 -                return o1.getKey().compareTo(o2.getKey());
  108.85 -            }
  108.86 -        }
  108.87 -        
  108.88 -        Map<String,Integer> map = new HashMap<>();
  108.89 -        map.put("one", 1);
  108.90 -        map.put("two", 2);
  108.91 -        map.put("three", 3);
  108.92 -        map.put("four", 4);
  108.93 -        map.put("five", 5);
  108.94 -        map.put("six", 6);
  108.95 -        map.put("seven", 7);
  108.96 -        map.put("eight", 8);
  108.97 -        map.put("nine", 9);
  108.98 -        map.put("ten", 10);
  108.99 -        
 108.100 -        List<Entry<String,Integer>> arr = new Vector<>();
 108.101 -        arr.addAll(map.entrySet());
 108.102 -        return arr.toString();
 108.103 -    }
 108.104 -    
 108.105 -    @Factory
 108.106 -    public static Object[] create() {
 108.107 -        return VMTest.create(CollectionsTest.class);
 108.108 -    }
 108.109 -    
 108.110 -}
   109.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java	Mon Feb 25 19:00:08 2013 +0100
   109.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.3 @@ -1,61 +0,0 @@
   109.4 -/**
   109.5 - * Back 2 Browser Bytecode Translator
   109.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   109.7 - *
   109.8 - * This program is free software: you can redistribute it and/or modify
   109.9 - * it under the terms of the GNU General Public License as published by
  109.10 - * the Free Software Foundation, version 2 of the License.
  109.11 - *
  109.12 - * This program is distributed in the hope that it will be useful,
  109.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  109.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  109.15 - * GNU General Public License for more details.
  109.16 - *
  109.17 - * You should have received a copy of the GNU General Public License
  109.18 - * along with this program. Look for COPYING file in the top folder.
  109.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  109.20 - */
  109.21 -package org.apidesign.bck2brwsr.compact.tck;
  109.22 -
  109.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  109.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  109.25 -import org.testng.annotations.Factory;
  109.26 -
  109.27 -
  109.28 -public class JFXIssuesTest {
  109.29 -    private abstract class Application {
  109.30 -        public abstract int getID();
  109.31 -    }
  109.32 -    
  109.33 -    private class MyApplication extends Application {
  109.34 -
  109.35 -        @Override
  109.36 -        public int getID() {
  109.37 -            return 1;
  109.38 -        }
  109.39 -        
  109.40 -    } 
  109.41 -    
  109.42 -    @Compare public boolean isClassAssignable() {
  109.43 -        return Application.class.isAssignableFrom(MyApplication.class);
  109.44 -    }
  109.45 -
  109.46 -    @Compare public boolean isNaN() {
  109.47 -        return Double.isNaN(Double.NaN);
  109.48 -    }
  109.49 -
  109.50 -    @Compare public boolean isInfinite() {
  109.51 -        return Float.isInfinite(Float.NEGATIVE_INFINITY);
  109.52 -    }
  109.53 -
  109.54 -    @Compare public boolean areTimesEqual() {
  109.55 -        long l1 = System.currentTimeMillis();
  109.56 -        long l2 = l1 + 0;
  109.57 -
  109.58 -        return l1 == l2;
  109.59 -    }
  109.60 -
  109.61 -    @Factory public static Object[] create() {
  109.62 -        return VMTest.create(JFXIssuesTest.class);
  109.63 -    }
  109.64 -}
   110.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/RandomTest.java	Mon Feb 25 19:00:08 2013 +0100
   110.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   110.3 @@ -1,40 +0,0 @@
   110.4 -/**
   110.5 - * Back 2 Browser Bytecode Translator
   110.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   110.7 - *
   110.8 - * This program is free software: you can redistribute it and/or modify
   110.9 - * it under the terms of the GNU General Public License as published by
  110.10 - * the Free Software Foundation, version 2 of the License.
  110.11 - *
  110.12 - * This program is distributed in the hope that it will be useful,
  110.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  110.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  110.15 - * GNU General Public License for more details.
  110.16 - *
  110.17 - * You should have received a copy of the GNU General Public License
  110.18 - * along with this program. Look for COPYING file in the top folder.
  110.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  110.20 - */
  110.21 -package org.apidesign.bck2brwsr.compact.tck;
  110.22 -
  110.23 -import java.util.Random;
  110.24 -import org.apidesign.bck2brwsr.vmtest.Compare;
  110.25 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  110.26 -import org.testng.annotations.Factory;
  110.27 -
  110.28 -/**
  110.29 - *
  110.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  110.31 - */
  110.32 -public class RandomTest {
  110.33 -    @Compare public boolean canInstantiateRandom() {
  110.34 -        Random r = new Random();
  110.35 -        r.nextInt();
  110.36 -        return r != null;
  110.37 -    }
  110.38 -
  110.39 -    
  110.40 -    @Factory public static Object[] create() {
  110.41 -        return VMTest.create(RandomTest.class);
  110.42 -    }
  110.43 -}
   111.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java	Mon Feb 25 19:00:08 2013 +0100
   111.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.3 @@ -1,61 +0,0 @@
   111.4 -/**
   111.5 - * Back 2 Browser Bytecode Translator
   111.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   111.7 - *
   111.8 - * This program is free software: you can redistribute it and/or modify
   111.9 - * it under the terms of the GNU General Public License as published by
  111.10 - * the Free Software Foundation, version 2 of the License.
  111.11 - *
  111.12 - * This program is distributed in the hope that it will be useful,
  111.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  111.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  111.15 - * GNU General Public License for more details.
  111.16 - *
  111.17 - * You should have received a copy of the GNU General Public License
  111.18 - * along with this program. Look for COPYING file in the top folder.
  111.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  111.20 - */
  111.21 -package org.apidesign.bck2brwsr.compact.tck;
  111.22 -
  111.23 -import java.io.ByteArrayInputStream;
  111.24 -import java.io.IOException;
  111.25 -import java.io.InputStreamReader;
  111.26 -import java.io.UnsupportedEncodingException;
  111.27 -import java.util.Arrays;
  111.28 -import org.apidesign.bck2brwsr.vmtest.Compare;
  111.29 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  111.30 -import org.testng.annotations.Factory;
  111.31 -
  111.32 -/**
  111.33 - *
  111.34 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  111.35 - */
  111.36 -public class ReaderTest {
  111.37 -    @Compare public String readUTFString() throws IOException {
  111.38 -        byte[] arr = { 
  111.39 -            (byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91, 
  111.40 -            (byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61, 
  111.41 -            (byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59, 
  111.42 -            (byte)-120 
  111.43 -        };
  111.44 -        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  111.45 -        InputStreamReader r = new InputStreamReader(is, "UTF-8");
  111.46 -        
  111.47 -        StringBuilder sb = new StringBuilder();
  111.48 -        for (;;) {
  111.49 -            int ch = r.read();
  111.50 -            if (ch == -1) {
  111.51 -                break;
  111.52 -            }
  111.53 -            sb.append((char)ch);
  111.54 -        }
  111.55 -        return sb.toString().toString();
  111.56 -    }
  111.57 -    @Compare public String stringToBytes() throws UnsupportedEncodingException {
  111.58 -        return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8"));
  111.59 -    }
  111.60 -    
  111.61 -    @Factory public static Object[] create() {
  111.62 -        return VMTest.create(ReaderTest.class);
  111.63 -    }
  111.64 -}
   112.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ServiceLoaderTest.java	Mon Feb 25 19:00:08 2013 +0100
   112.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.3 @@ -1,61 +0,0 @@
   112.4 -/**
   112.5 - * Back 2 Browser Bytecode Translator
   112.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   112.7 - *
   112.8 - * This program is free software: you can redistribute it and/or modify
   112.9 - * it under the terms of the GNU General Public License as published by
  112.10 - * the Free Software Foundation, version 2 of the License.
  112.11 - *
  112.12 - * This program is distributed in the hope that it will be useful,
  112.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  112.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  112.15 - * GNU General Public License for more details.
  112.16 - *
  112.17 - * You should have received a copy of the GNU General Public License
  112.18 - * along with this program. Look for COPYING file in the top folder.
  112.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  112.20 - */
  112.21 -package org.apidesign.bck2brwsr.compact.tck;
  112.22 -
  112.23 -import java.io.IOException;
  112.24 -import java.util.ServiceLoader;
  112.25 -import org.apidesign.bck2brwsr.vmtest.Compare;
  112.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  112.27 -import org.openide.util.lookup.ServiceProvider;
  112.28 -import org.testng.annotations.Factory;
  112.29 -
  112.30 -/**
  112.31 - *
  112.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  112.33 - */
  112.34 -public class ServiceLoaderTest {
  112.35 -    @Compare//(scripting = false) 
  112.36 -    public Object findsIOException() {
  112.37 -//      delayStart();
  112.38 -        for (IOException e : ServiceLoader.load(IOException.class)) {
  112.39 -            return "Found service: " + e.getClass().getName();
  112.40 -        }
  112.41 -        return null;
  112.42 -    }
  112.43 -/*    
  112.44 -    @org.apidesign.bck2brwsr.core.JavaScriptBody(args = { "a" }, body = "alert(a);")
  112.45 -    private static void alert(String a) {
  112.46 -    }
  112.47 -    private void delayStart() {
  112.48 -        for (int i = 0; i < 10; i++) {
  112.49 -            alert("State: " + i);
  112.50 -            for (int j = 0; j < 493208409; j++) ;
  112.51 -        }
  112.52 -    }
  112.53 -*/
  112.54 -    
  112.55 -    @Factory
  112.56 -    public static Object[] create() {
  112.57 -        return VMTest.create(ServiceLoaderTest.class);
  112.58 -    }
  112.59 -
  112.60 -    
  112.61 -    @ServiceProvider(service = IOException.class)
  112.62 -    public static class MyException extends IOException {
  112.63 -    }
  112.64 -}
   113.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipArchive.java	Mon Feb 25 19:00:08 2013 +0100
   113.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.3 @@ -1,154 +0,0 @@
   113.4 -/**
   113.5 - * Back 2 Browser Bytecode Translator
   113.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   113.7 - *
   113.8 - * This program is free software: you can redistribute it and/or modify
   113.9 - * it under the terms of the GNU General Public License as published by
  113.10 - * the Free Software Foundation, version 2 of the License.
  113.11 - *
  113.12 - * This program is distributed in the hope that it will be useful,
  113.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  113.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  113.15 - * GNU General Public License for more details.
  113.16 - *
  113.17 - * You should have received a copy of the GNU General Public License
  113.18 - * along with this program. Look for COPYING file in the top folder.
  113.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  113.20 - */
  113.21 -package org.apidesign.bck2brwsr.compact.tck;
  113.22 -
  113.23 -import java.io.ByteArrayOutputStream;
  113.24 -import java.io.IOException;
  113.25 -import java.io.InputStream;
  113.26 -import java.util.Arrays;
  113.27 -import java.util.LinkedHashMap;
  113.28 -import java.util.Map;
  113.29 -import java.util.Objects;
  113.30 -import java.util.zip.ZipEntry;
  113.31 -import org.apidesign.bck2brwsr.emul.zip.ZipInputStream;
  113.32 -
  113.33 -/**
  113.34 - *
  113.35 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  113.36 - */
  113.37 -final class ZipArchive {
  113.38 -    private final Map<String, byte[]> entries = new LinkedHashMap<>();
  113.39 -
  113.40 -    public static ZipArchive createZip(InputStream is) throws IOException {
  113.41 -        ZipArchive a = new ZipArchive();
  113.42 -        readZip(is, a);
  113.43 -        return a;
  113.44 -    }
  113.45 -
  113.46 -    public static ZipArchive createReal(InputStream is) throws IOException {
  113.47 -        ZipArchive a = new ZipArchive();
  113.48 -        realZip(is, a);
  113.49 -        return a;
  113.50 -    }
  113.51 -
  113.52 -    /**
  113.53 -     * Registers entry name and data
  113.54 -     */
  113.55 -    final void register(String entry, InputStream is) throws IOException {
  113.56 -        ByteArrayOutputStream os = new ByteArrayOutputStream();
  113.57 -        for (;;) {
  113.58 -            int ch = is.read();
  113.59 -            if (ch == -1) {
  113.60 -                break;
  113.61 -            }
  113.62 -            os.write(ch);
  113.63 -        }
  113.64 -        os.close();
  113.65 -        entries.put(entry, os.toByteArray());
  113.66 -    }
  113.67 -
  113.68 -    @Override
  113.69 -    public int hashCode() {
  113.70 -        return entries.hashCode();
  113.71 -    }
  113.72 -
  113.73 -    @Override
  113.74 -    public boolean equals(Object obj) {
  113.75 -        if (obj == null) {
  113.76 -            return false;
  113.77 -        }
  113.78 -        if (getClass() != obj.getClass()) {
  113.79 -            return false;
  113.80 -        }
  113.81 -        final ZipArchive other = (ZipArchive) obj;
  113.82 -        if (!Objects.deepEquals(this.entries, other.entries)) {
  113.83 -            return false;
  113.84 -        }
  113.85 -        return true;
  113.86 -    }
  113.87 -
  113.88 -    @Override
  113.89 -    public String toString() {
  113.90 -        StringBuilder sb = new StringBuilder();
  113.91 -        for (Map.Entry<String, byte[]> en : entries.entrySet()) {
  113.92 -            String string = en.getKey();
  113.93 -            byte[] bs = en.getValue();
  113.94 -            sb.append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
  113.95 -        }
  113.96 -        return sb.toString();
  113.97 -    }
  113.98 -
  113.99 -    public void assertEquals(ZipArchive zip, String msg) {
 113.100 -        boolean ok = true;
 113.101 -        StringBuilder sb = new StringBuilder();
 113.102 -        sb.append(msg);
 113.103 -        for (Map.Entry<String, byte[]> en : entries.entrySet()) {
 113.104 -            String string = en.getKey();
 113.105 -            byte[] bs = en.getValue();
 113.106 -            byte[] other = zip.entries.get(string);
 113.107 -            sb.append("\n");
 113.108 -            if (other == null) {
 113.109 -                sb.append("EXTRA ").append(string).append(" = ").append(Arrays.toString(bs));
 113.110 -                ok = false;
 113.111 -                continue;
 113.112 -            }
 113.113 -            if (Arrays.equals(bs, other)) {
 113.114 -                sb.append("OK    ").append(string);
 113.115 -                continue;
 113.116 -            } else {
 113.117 -                sb.append("DIFF  ").append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
 113.118 -                sb.append("    TO").append(string).append(" = ").append(Arrays.toString(other)).append("\n");
 113.119 -                ok = false;
 113.120 -                continue;
 113.121 -            }
 113.122 -        }
 113.123 -        for (Map.Entry<String, byte[]> entry : zip.entries.entrySet()) {
 113.124 -            String string = entry.getKey();
 113.125 -            if (entries.get(string) == null) {
 113.126 -                sb.append("MISS  ").append(string).append(" = ").append(Arrays.toString(entry.getValue()));
 113.127 -                ok = false;
 113.128 -            }
 113.129 -        }
 113.130 -        if (!ok) {
 113.131 -            assert false : sb.toString();
 113.132 -        }
 113.133 -    }
 113.134 -
 113.135 -    public static void readZip(InputStream is, ZipArchive data) throws IOException {
 113.136 -        ZipInputStream zip = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(is);
 113.137 -        for (;;) {
 113.138 -            ZipEntry en = zip.getNextEntry();
 113.139 -            if (en == null) {
 113.140 -                return;
 113.141 -            }
 113.142 -            data.register(en.getName(), zip);
 113.143 -        }
 113.144 -    }
 113.145 -
 113.146 -    public static void realZip(InputStream is, ZipArchive data) throws IOException {
 113.147 -        java.util.zip.ZipInputStream zip = new java.util.zip.ZipInputStream(is);
 113.148 -        for (;;) {
 113.149 -            ZipEntry en = zip.getNextEntry();
 113.150 -            if (en == null) {
 113.151 -                return;
 113.152 -            }
 113.153 -            data.register(en.getName(), zip);
 113.154 -        }
 113.155 -    }
 113.156 -    
 113.157 -}
   114.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java	Mon Feb 25 19:00:08 2013 +0100
   114.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.3 @@ -1,42 +0,0 @@
   114.4 -/**
   114.5 - * Back 2 Browser Bytecode Translator
   114.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   114.7 - *
   114.8 - * This program is free software: you can redistribute it and/or modify
   114.9 - * it under the terms of the GNU General Public License as published by
  114.10 - * the Free Software Foundation, version 2 of the License.
  114.11 - *
  114.12 - * This program is distributed in the hope that it will be useful,
  114.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  114.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  114.15 - * GNU General Public License for more details.
  114.16 - *
  114.17 - * You should have received a copy of the GNU General Public License
  114.18 - * along with this program. Look for COPYING file in the top folder.
  114.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  114.20 - */
  114.21 -package org.apidesign.bck2brwsr.compact.tck;
  114.22 -
  114.23 -import java.io.IOException;
  114.24 -import java.io.InputStream;
  114.25 -import org.apidesign.bck2brwsr.vmtest.Compare;
  114.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  114.27 -import org.testng.annotations.Factory;
  114.28 -
  114.29 -/**
  114.30 - *
  114.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  114.32 - */
  114.33 -public class ZipCompatibilityTest {
  114.34 -    @Compare
  114.35 -    public String testDemoStaticCalculator() throws IOException {
  114.36 -        InputStream is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
  114.37 -        ZipArchive zip = ZipArchive.createZip(is);
  114.38 -        return zip.toString();
  114.39 -    }
  114.40 -    
  114.41 -    @Factory
  114.42 -    public static Object[] create() {
  114.43 -        return VMTest.create(ZipCompatibilityTest.class);
  114.44 -    }
  114.45 -}
   115.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipVsJzLibTest.java	Mon Feb 25 19:00:08 2013 +0100
   115.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.3 @@ -1,39 +0,0 @@
   115.4 -/**
   115.5 - * Back 2 Browser Bytecode Translator
   115.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   115.7 - *
   115.8 - * This program is free software: you can redistribute it and/or modify
   115.9 - * it under the terms of the GNU General Public License as published by
  115.10 - * the Free Software Foundation, version 2 of the License.
  115.11 - *
  115.12 - * This program is distributed in the hope that it will be useful,
  115.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  115.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  115.15 - * GNU General Public License for more details.
  115.16 - *
  115.17 - * You should have received a copy of the GNU General Public License
  115.18 - * along with this program. Look for COPYING file in the top folder.
  115.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  115.20 - */
  115.21 -package org.apidesign.bck2brwsr.compact.tck;
  115.22 -
  115.23 -import java.io.IOException;
  115.24 -import java.io.InputStream;
  115.25 -import org.testng.annotations.Test;
  115.26 -
  115.27 -/**
  115.28 - *
  115.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  115.30 - */
  115.31 -public class ZipVsJzLibTest {
  115.32 -    @Test public void r() throws IOException {
  115.33 -        InputStream is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
  115.34 -        ZipArchive zip = ZipArchive.createZip(is);
  115.35 -        
  115.36 -        is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
  115.37 -        ZipArchive real = ZipArchive.createReal(is);
  115.38 -        
  115.39 -        real.assertEquals(zip, "Are they the same?");
  115.40 -    }
  115.41 -    
  115.42 -}
   116.1 Binary file emul/compact/src/test/resources/org/apidesign/bck2brwsr/compact/tck/demo.static.calculator-0.3-SNAPSHOT.jar has changed
   117.1 --- a/emul/mini/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   117.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.3 @@ -1,48 +0,0 @@
   117.4 -<?xml version="1.0"?>
   117.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"
   117.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   117.7 -  <modelVersion>4.0.0</modelVersion>
   117.8 -  <parent>
   117.9 -    <groupId>org.apidesign.bck2brwsr</groupId>
  117.10 -    <artifactId>emul.pom</artifactId>
  117.11 -    <version>0.3-SNAPSHOT</version>
  117.12 -  </parent>
  117.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
  117.14 -  <artifactId>emul.mini</artifactId>
  117.15 -  <version>0.3-SNAPSHOT</version>
  117.16 -  <name>Minimal API Profile</name>
  117.17 -  <url>http://maven.apache.org</url>
  117.18 -  <properties>
  117.19 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  117.20 -  </properties>
  117.21 -  <dependencies>
  117.22 -    <dependency>
  117.23 -      <groupId>org.apidesign.bck2brwsr</groupId>
  117.24 -      <artifactId>core</artifactId>
  117.25 -      <version>0.3-SNAPSHOT</version>
  117.26 -      <type>jar</type>
  117.27 -    </dependency>
  117.28 -    <dependency>
  117.29 -      <groupId>org.testng</groupId>
  117.30 -      <artifactId>testng</artifactId>
  117.31 -      <version>6.5.2</version>
  117.32 -      <scope>test</scope>
  117.33 -    </dependency>
  117.34 -  </dependencies>
  117.35 -  <build>
  117.36 -      <plugins>
  117.37 -          <plugin>
  117.38 -              <groupId>org.apache.maven.plugins</groupId>
  117.39 -              <artifactId>maven-compiler-plugin</artifactId>
  117.40 -              <version>2.5.1</version>
  117.41 -              <configuration>
  117.42 -                  <compilerArguments>
  117.43 -                      <bootclasspath>netbeans.ignore.jdk.bootsclasspath</bootclasspath>
  117.44 -                  </compilerArguments>
  117.45 -                 <source>1.7</source>
  117.46 -                 <target>1.7</target>
  117.47 -              </configuration>
  117.48 -          </plugin>
  117.49 -      </plugins>
  117.50 -  </build>
  117.51 -</project>
   118.1 --- a/emul/mini/src/main/java/java/io/ByteArrayInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   118.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.3 @@ -1,285 +0,0 @@
   118.4 -/*
   118.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   118.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   118.7 - *
   118.8 - * This code is free software; you can redistribute it and/or modify it
   118.9 - * under the terms of the GNU General Public License version 2 only, as
  118.10 - * published by the Free Software Foundation.  Oracle designates this
  118.11 - * particular file as subject to the "Classpath" exception as provided
  118.12 - * by Oracle in the LICENSE file that accompanied this code.
  118.13 - *
  118.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  118.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  118.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  118.17 - * version 2 for more details (a copy is included in the LICENSE file that
  118.18 - * accompanied this code).
  118.19 - *
  118.20 - * You should have received a copy of the GNU General Public License version
  118.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  118.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  118.23 - *
  118.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  118.25 - * or visit www.oracle.com if you need additional information or have any
  118.26 - * questions.
  118.27 - */
  118.28 -
  118.29 -package java.io;
  118.30 -
  118.31 -import org.apidesign.bck2brwsr.emul.lang.System;
  118.32 -
  118.33 -/**
  118.34 - * A <code>ByteArrayInputStream</code> contains
  118.35 - * an internal buffer that contains bytes that
  118.36 - * may be read from the stream. An internal
  118.37 - * counter keeps track of the next byte to
  118.38 - * be supplied by the <code>read</code> method.
  118.39 - * <p>
  118.40 - * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
  118.41 - * this class can be called after the stream has been closed without
  118.42 - * generating an <tt>IOException</tt>.
  118.43 - *
  118.44 - * @author  Arthur van Hoff
  118.45 - * @see     java.io.StringBufferInputStream
  118.46 - * @since   JDK1.0
  118.47 - */
  118.48 -public
  118.49 -class ByteArrayInputStream extends InputStream {
  118.50 -
  118.51 -    /**
  118.52 -     * An array of bytes that was provided
  118.53 -     * by the creator of the stream. Elements <code>buf[0]</code>
  118.54 -     * through <code>buf[count-1]</code> are the
  118.55 -     * only bytes that can ever be read from the
  118.56 -     * stream;  element <code>buf[pos]</code> is
  118.57 -     * the next byte to be read.
  118.58 -     */
  118.59 -    protected byte buf[];
  118.60 -
  118.61 -    /**
  118.62 -     * The index of the next character to read from the input stream buffer.
  118.63 -     * This value should always be nonnegative
  118.64 -     * and not larger than the value of <code>count</code>.
  118.65 -     * The next byte to be read from the input stream buffer
  118.66 -     * will be <code>buf[pos]</code>.
  118.67 -     */
  118.68 -    protected int pos;
  118.69 -
  118.70 -    /**
  118.71 -     * The currently marked position in the stream.
  118.72 -     * ByteArrayInputStream objects are marked at position zero by
  118.73 -     * default when constructed.  They may be marked at another
  118.74 -     * position within the buffer by the <code>mark()</code> method.
  118.75 -     * The current buffer position is set to this point by the
  118.76 -     * <code>reset()</code> method.
  118.77 -     * <p>
  118.78 -     * If no mark has been set, then the value of mark is the offset
  118.79 -     * passed to the constructor (or 0 if the offset was not supplied).
  118.80 -     *
  118.81 -     * @since   JDK1.1
  118.82 -     */
  118.83 -    protected int mark = 0;
  118.84 -
  118.85 -    /**
  118.86 -     * The index one greater than the last valid character in the input
  118.87 -     * stream buffer.
  118.88 -     * This value should always be nonnegative
  118.89 -     * and not larger than the length of <code>buf</code>.
  118.90 -     * It  is one greater than the position of
  118.91 -     * the last byte within <code>buf</code> that
  118.92 -     * can ever be read  from the input stream buffer.
  118.93 -     */
  118.94 -    protected int count;
  118.95 -
  118.96 -    /**
  118.97 -     * Creates a <code>ByteArrayInputStream</code>
  118.98 -     * so that it  uses <code>buf</code> as its
  118.99 -     * buffer array.
 118.100 -     * The buffer array is not copied.
 118.101 -     * The initial value of <code>pos</code>
 118.102 -     * is <code>0</code> and the initial value
 118.103 -     * of  <code>count</code> is the length of
 118.104 -     * <code>buf</code>.
 118.105 -     *
 118.106 -     * @param   buf   the input buffer.
 118.107 -     */
 118.108 -    public ByteArrayInputStream(byte buf[]) {
 118.109 -        this.buf = buf;
 118.110 -        this.pos = 0;
 118.111 -        this.count = buf.length;
 118.112 -    }
 118.113 -
 118.114 -    /**
 118.115 -     * Creates <code>ByteArrayInputStream</code>
 118.116 -     * that uses <code>buf</code> as its
 118.117 -     * buffer array. The initial value of <code>pos</code>
 118.118 -     * is <code>offset</code> and the initial value
 118.119 -     * of <code>count</code> is the minimum of <code>offset+length</code>
 118.120 -     * and <code>buf.length</code>.
 118.121 -     * The buffer array is not copied. The buffer's mark is
 118.122 -     * set to the specified offset.
 118.123 -     *
 118.124 -     * @param   buf      the input buffer.
 118.125 -     * @param   offset   the offset in the buffer of the first byte to read.
 118.126 -     * @param   length   the maximum number of bytes to read from the buffer.
 118.127 -     */
 118.128 -    public ByteArrayInputStream(byte buf[], int offset, int length) {
 118.129 -        this.buf = buf;
 118.130 -        this.pos = offset;
 118.131 -        this.count = Math.min(offset + length, buf.length);
 118.132 -        this.mark = offset;
 118.133 -    }
 118.134 -
 118.135 -    /**
 118.136 -     * Reads the next byte of data from this input stream. The value
 118.137 -     * byte is returned as an <code>int</code> in the range
 118.138 -     * <code>0</code> to <code>255</code>. If no byte is available
 118.139 -     * because the end of the stream has been reached, the value
 118.140 -     * <code>-1</code> is returned.
 118.141 -     * <p>
 118.142 -     * This <code>read</code> method
 118.143 -     * cannot block.
 118.144 -     *
 118.145 -     * @return  the next byte of data, or <code>-1</code> if the end of the
 118.146 -     *          stream has been reached.
 118.147 -     */
 118.148 -    public synchronized int read() {
 118.149 -        return (pos < count) ? (buf[pos++] & 0xff) : -1;
 118.150 -    }
 118.151 -
 118.152 -    /**
 118.153 -     * Reads up to <code>len</code> bytes of data into an array of bytes
 118.154 -     * from this input stream.
 118.155 -     * If <code>pos</code> equals <code>count</code>,
 118.156 -     * then <code>-1</code> is returned to indicate
 118.157 -     * end of file. Otherwise, the  number <code>k</code>
 118.158 -     * of bytes read is equal to the smaller of
 118.159 -     * <code>len</code> and <code>count-pos</code>.
 118.160 -     * If <code>k</code> is positive, then bytes
 118.161 -     * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
 118.162 -     * are copied into <code>b[off]</code>  through
 118.163 -     * <code>b[off+k-1]</code> in the manner performed
 118.164 -     * by <code>System.arraycopy</code>. The
 118.165 -     * value <code>k</code> is added into <code>pos</code>
 118.166 -     * and <code>k</code> is returned.
 118.167 -     * <p>
 118.168 -     * This <code>read</code> method cannot block.
 118.169 -     *
 118.170 -     * @param   b     the buffer into which the data is read.
 118.171 -     * @param   off   the start offset in the destination array <code>b</code>
 118.172 -     * @param   len   the maximum number of bytes read.
 118.173 -     * @return  the total number of bytes read into the buffer, or
 118.174 -     *          <code>-1</code> if there is no more data because the end of
 118.175 -     *          the stream has been reached.
 118.176 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 118.177 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 118.178 -     * <code>len</code> is negative, or <code>len</code> is greater than
 118.179 -     * <code>b.length - off</code>
 118.180 -     */
 118.181 -    public synchronized int read(byte b[], int off, int len) {
 118.182 -        if (b == null) {
 118.183 -            throw new NullPointerException();
 118.184 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 118.185 -            throw new IndexOutOfBoundsException();
 118.186 -        }
 118.187 -
 118.188 -        if (pos >= count) {
 118.189 -            return -1;
 118.190 -        }
 118.191 -
 118.192 -        int avail = count - pos;
 118.193 -        if (len > avail) {
 118.194 -            len = avail;
 118.195 -        }
 118.196 -        if (len <= 0) {
 118.197 -            return 0;
 118.198 -        }
 118.199 -        System.arraycopy(buf, pos, b, off, len);
 118.200 -        pos += len;
 118.201 -        return len;
 118.202 -    }
 118.203 -
 118.204 -    /**
 118.205 -     * Skips <code>n</code> bytes of input from this input stream. Fewer
 118.206 -     * bytes might be skipped if the end of the input stream is reached.
 118.207 -     * The actual number <code>k</code>
 118.208 -     * of bytes to be skipped is equal to the smaller
 118.209 -     * of <code>n</code> and  <code>count-pos</code>.
 118.210 -     * The value <code>k</code> is added into <code>pos</code>
 118.211 -     * and <code>k</code> is returned.
 118.212 -     *
 118.213 -     * @param   n   the number of bytes to be skipped.
 118.214 -     * @return  the actual number of bytes skipped.
 118.215 -     */
 118.216 -    public synchronized long skip(long n) {
 118.217 -        long k = count - pos;
 118.218 -        if (n < k) {
 118.219 -            k = n < 0 ? 0 : n;
 118.220 -        }
 118.221 -
 118.222 -        pos += k;
 118.223 -        return k;
 118.224 -    }
 118.225 -
 118.226 -    /**
 118.227 -     * Returns the number of remaining bytes that can be read (or skipped over)
 118.228 -     * from this input stream.
 118.229 -     * <p>
 118.230 -     * The value returned is <code>count&nbsp;- pos</code>,
 118.231 -     * which is the number of bytes remaining to be read from the input buffer.
 118.232 -     *
 118.233 -     * @return  the number of remaining bytes that can be read (or skipped
 118.234 -     *          over) from this input stream without blocking.
 118.235 -     */
 118.236 -    public synchronized int available() {
 118.237 -        return count - pos;
 118.238 -    }
 118.239 -
 118.240 -    /**
 118.241 -     * Tests if this <code>InputStream</code> supports mark/reset. The
 118.242 -     * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
 118.243 -     * always returns <code>true</code>.
 118.244 -     *
 118.245 -     * @since   JDK1.1
 118.246 -     */
 118.247 -    public boolean markSupported() {
 118.248 -        return true;
 118.249 -    }
 118.250 -
 118.251 -    /**
 118.252 -     * Set the current marked position in the stream.
 118.253 -     * ByteArrayInputStream objects are marked at position zero by
 118.254 -     * default when constructed.  They may be marked at another
 118.255 -     * position within the buffer by this method.
 118.256 -     * <p>
 118.257 -     * If no mark has been set, then the value of the mark is the
 118.258 -     * offset passed to the constructor (or 0 if the offset was not
 118.259 -     * supplied).
 118.260 -     *
 118.261 -     * <p> Note: The <code>readAheadLimit</code> for this class
 118.262 -     *  has no meaning.
 118.263 -     *
 118.264 -     * @since   JDK1.1
 118.265 -     */
 118.266 -    public void mark(int readAheadLimit) {
 118.267 -        mark = pos;
 118.268 -    }
 118.269 -
 118.270 -    /**
 118.271 -     * Resets the buffer to the marked position.  The marked position
 118.272 -     * is 0 unless another position was marked or an offset was specified
 118.273 -     * in the constructor.
 118.274 -     */
 118.275 -    public synchronized void reset() {
 118.276 -        pos = mark;
 118.277 -    }
 118.278 -
 118.279 -    /**
 118.280 -     * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
 118.281 -     * this class can be called after the stream has been closed without
 118.282 -     * generating an <tt>IOException</tt>.
 118.283 -     * <p>
 118.284 -     */
 118.285 -    public void close() throws IOException {
 118.286 -    }
 118.287 -
 118.288 -}
   119.1 --- a/emul/mini/src/main/java/java/io/Closeable.java	Mon Feb 25 19:00:08 2013 +0100
   119.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   119.3 @@ -1,48 +0,0 @@
   119.4 -/*
   119.5 - * Copyright (c) 2003, 2010, 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.io;
  119.30 -
  119.31 -import java.io.IOException;
  119.32 -
  119.33 -/**
  119.34 - * A {@code Closeable} is a source or destination of data that can be closed.
  119.35 - * The close method is invoked to release resources that the object is
  119.36 - * holding (such as open files).
  119.37 - *
  119.38 - * @since 1.5
  119.39 - */
  119.40 -
  119.41 -public interface Closeable extends AutoCloseable {
  119.42 -
  119.43 -    /**
  119.44 -     * Closes this stream and releases any system resources associated
  119.45 -     * with it. If the stream is already closed then invoking this
  119.46 -     * method has no effect.
  119.47 -     *
  119.48 -     * @throws IOException if an I/O error occurs
  119.49 -     */
  119.50 -    public void close() throws IOException;
  119.51 -}
   120.1 --- a/emul/mini/src/main/java/java/io/DataInput.java	Mon Feb 25 19:00:08 2013 +0100
   120.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   120.3 @@ -1,635 +0,0 @@
   120.4 -/*
   120.5 - * Copyright (c) 1995, 2006, 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.io;
  120.30 -
  120.31 -/**
  120.32 - * The <code>DataInput</code> interface provides
  120.33 - * for reading bytes from a binary stream and
  120.34 - * reconstructing from them data in any of
  120.35 - * the Java primitive types. There is also
  120.36 - * a
  120.37 - * facility for reconstructing a <code>String</code>
  120.38 - * from data in
  120.39 - * <a href="#modified-utf-8">modified UTF-8</a>
  120.40 - * format.
  120.41 - * <p>
  120.42 - * It is generally true of all the reading
  120.43 - * routines in this interface that if end of
  120.44 - * file is reached before the desired number
  120.45 - * of bytes has been read, an <code>EOFException</code>
  120.46 - * (which is a kind of <code>IOException</code>)
  120.47 - * is thrown. If any byte cannot be read for
  120.48 - * any reason other than end of file, an <code>IOException</code>
  120.49 - * other than <code>EOFException</code> is
  120.50 - * thrown. In particular, an <code>IOException</code>
  120.51 - * may be thrown if the input stream has been
  120.52 - * closed.
  120.53 - *
  120.54 - * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
  120.55 - * <p>
  120.56 - * Implementations of the DataInput and DataOutput interfaces represent
  120.57 - * Unicode strings in a format that is a slight modification of UTF-8.
  120.58 - * (For information regarding the standard UTF-8 format, see section
  120.59 - * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
  120.60 - * 4.0</i>).
  120.61 - * Note that in the following tables, the most significant bit appears in the
  120.62 - * far left-hand column.
  120.63 - * <p>
  120.64 - * All characters in the range <code>'&#92;u0001'</code> to
  120.65 - * <code>'&#92;u007F'</code> are represented by a single byte:
  120.66 - *
  120.67 - * <blockquote>
  120.68 - *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  120.69 - *          summary="Bit values and bytes">
  120.70 - *     <tr>
  120.71 - *       <td></td>
  120.72 - *       <th id="bit">Bit Values</th>
  120.73 - *     </tr>
  120.74 - *     <tr>
  120.75 - *       <th id="byte1">Byte 1</th>
  120.76 - *       <td>
  120.77 - *         <table border="1" cellspacing="0" width="100%">
  120.78 - *           <tr>
  120.79 - *             <td width="12%"><center>0</center>
  120.80 - *             <td colspan="7"><center>bits 6-0</center>
  120.81 - *           </tr>
  120.82 - *         </table>
  120.83 - *       </td>
  120.84 - *     </tr>
  120.85 - *   </table>
  120.86 - * </blockquote>
  120.87 - *
  120.88 - * <p>
  120.89 - * The null character <code>'&#92;u0000'</code> and characters in the
  120.90 - * range <code>'&#92;u0080'</code> to <code>'&#92;u07FF'</code> are
  120.91 - * represented by a pair of bytes:
  120.92 - *
  120.93 - * <blockquote>
  120.94 - *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  120.95 - *          summary="Bit values and bytes">
  120.96 - *     <tr>
  120.97 - *       <td></td>
  120.98 - *       <th id="bit">Bit Values</th>
  120.99 - *     </tr>
 120.100 - *     <tr>
 120.101 - *       <th id="byte1">Byte 1</th>
 120.102 - *       <td>
 120.103 - *         <table border="1" cellspacing="0" width="100%">
 120.104 - *           <tr>
 120.105 - *             <td width="12%"><center>1</center>
 120.106 - *             <td width="13%"><center>1</center>
 120.107 - *             <td width="12%"><center>0</center>
 120.108 - *             <td colspan="5"><center>bits 10-6</center>
 120.109 - *           </tr>
 120.110 - *         </table>
 120.111 - *       </td>
 120.112 - *     </tr>
 120.113 - *     <tr>
 120.114 - *       <th id="byte2">Byte 2</th>
 120.115 - *       <td>
 120.116 - *         <table border="1" cellspacing="0" width="100%">
 120.117 - *           <tr>
 120.118 - *             <td width="12%"><center>1</center>
 120.119 - *             <td width="13%"><center>0</center>
 120.120 - *             <td colspan="6"><center>bits 5-0</center>
 120.121 - *           </tr>
 120.122 - *         </table>
 120.123 - *       </td>
 120.124 - *     </tr>
 120.125 - *   </table>
 120.126 - *  </blockquote>
 120.127 - *
 120.128 - * <br>
 120.129 - * <code>char</code> values in the range <code>'&#92;u0800'</code> to
 120.130 - * <code>'&#92;uFFFF'</code> are represented by three bytes:
 120.131 - *
 120.132 - * <blockquote>
 120.133 - *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
 120.134 - *          summary="Bit values and bytes">
 120.135 - *     <tr>
 120.136 - *       <td></td>
 120.137 - *       <th id="bit">Bit Values</th>
 120.138 - *     </tr>
 120.139 - *     <tr>
 120.140 - *       <th id="byte1">Byte 1</th>
 120.141 - *       <td>
 120.142 - *         <table border="1" cellspacing="0" width="100%">
 120.143 - *           <tr>
 120.144 - *             <td width="12%"><center>1</center>
 120.145 - *             <td width="13%"><center>1</center>
 120.146 - *             <td width="12%"><center>1</center>
 120.147 - *             <td width="13%"><center>0</center>
 120.148 - *             <td colspan="4"><center>bits 15-12</center>
 120.149 - *           </tr>
 120.150 - *         </table>
 120.151 - *       </td>
 120.152 - *     </tr>
 120.153 - *     <tr>
 120.154 - *       <th id="byte2">Byte 2</th>
 120.155 - *       <td>
 120.156 - *         <table border="1" cellspacing="0" width="100%">
 120.157 - *           <tr>
 120.158 - *             <td width="12%"><center>1</center>
 120.159 - *             <td width="13%"><center>0</center>
 120.160 - *             <td colspan="6"><center>bits 11-6</center>
 120.161 - *           </tr>
 120.162 - *         </table>
 120.163 - *       </td>
 120.164 - *     </tr>
 120.165 - *     <tr>
 120.166 - *       <th id="byte3">Byte 3</th>
 120.167 - *       <td>
 120.168 - *         <table border="1" cellspacing="0" width="100%">
 120.169 - *           <tr>
 120.170 - *             <td width="12%"><center>1</center>
 120.171 - *             <td width="13%"><center>0</center>
 120.172 - *             <td colspan="6"><center>bits 5-0</center>
 120.173 - *           </tr>
 120.174 - *         </table>
 120.175 - *       </td>
 120.176 - *     </tr>
 120.177 - *   </table>
 120.178 - *  </blockquote>
 120.179 - *
 120.180 - * <p>
 120.181 - * The differences between this format and the
 120.182 - * standard UTF-8 format are the following:
 120.183 - * <ul>
 120.184 - * <li>The null byte <code>'&#92;u0000'</code> is encoded in 2-byte format
 120.185 - *     rather than 1-byte, so that the encoded strings never have
 120.186 - *     embedded nulls.
 120.187 - * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
 120.188 - * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
 120.189 - *     are represented in the form of surrogate pairs.
 120.190 - * </ul>
 120.191 - * @author  Frank Yellin
 120.192 - * @see     java.io.DataInputStream
 120.193 - * @see     java.io.DataOutput
 120.194 - * @since   JDK1.0
 120.195 - */
 120.196 -public
 120.197 -interface DataInput {
 120.198 -    /**
 120.199 -     * Reads some bytes from an input
 120.200 -     * stream and stores them into the buffer
 120.201 -     * array <code>b</code>. The number of bytes
 120.202 -     * read is equal
 120.203 -     * to the length of <code>b</code>.
 120.204 -     * <p>
 120.205 -     * This method blocks until one of the
 120.206 -     * following conditions occurs:<p>
 120.207 -     * <ul>
 120.208 -     * <li><code>b.length</code>
 120.209 -     * bytes of input data are available, in which
 120.210 -     * case a normal return is made.
 120.211 -     *
 120.212 -     * <li>End of
 120.213 -     * file is detected, in which case an <code>EOFException</code>
 120.214 -     * is thrown.
 120.215 -     *
 120.216 -     * <li>An I/O error occurs, in
 120.217 -     * which case an <code>IOException</code> other
 120.218 -     * than <code>EOFException</code> is thrown.
 120.219 -     * </ul>
 120.220 -     * <p>
 120.221 -     * If <code>b</code> is <code>null</code>,
 120.222 -     * a <code>NullPointerException</code> is thrown.
 120.223 -     * If <code>b.length</code> is zero, then
 120.224 -     * no bytes are read. Otherwise, the first
 120.225 -     * byte read is stored into element <code>b[0]</code>,
 120.226 -     * the next one into <code>b[1]</code>, and
 120.227 -     * so on.
 120.228 -     * If an exception is thrown from
 120.229 -     * this method, then it may be that some but
 120.230 -     * not all bytes of <code>b</code> have been
 120.231 -     * updated with data from the input stream.
 120.232 -     *
 120.233 -     * @param     b   the buffer into which the data is read.
 120.234 -     * @exception  EOFException  if this stream reaches the end before reading
 120.235 -     *               all the bytes.
 120.236 -     * @exception  IOException   if an I/O error occurs.
 120.237 -     */
 120.238 -    void readFully(byte b[]) throws IOException;
 120.239 -
 120.240 -    /**
 120.241 -     *
 120.242 -     * Reads <code>len</code>
 120.243 -     * bytes from
 120.244 -     * an input stream.
 120.245 -     * <p>
 120.246 -     * This method
 120.247 -     * blocks until one of the following conditions
 120.248 -     * occurs:<p>
 120.249 -     * <ul>
 120.250 -     * <li><code>len</code> bytes
 120.251 -     * of input data are available, in which case
 120.252 -     * a normal return is made.
 120.253 -     *
 120.254 -     * <li>End of file
 120.255 -     * is detected, in which case an <code>EOFException</code>
 120.256 -     * is thrown.
 120.257 -     *
 120.258 -     * <li>An I/O error occurs, in
 120.259 -     * which case an <code>IOException</code> other
 120.260 -     * than <code>EOFException</code> is thrown.
 120.261 -     * </ul>
 120.262 -     * <p>
 120.263 -     * If <code>b</code> is <code>null</code>,
 120.264 -     * a <code>NullPointerException</code> is thrown.
 120.265 -     * If <code>off</code> is negative, or <code>len</code>
 120.266 -     * is negative, or <code>off+len</code> is
 120.267 -     * greater than the length of the array <code>b</code>,
 120.268 -     * then an <code>IndexOutOfBoundsException</code>
 120.269 -     * is thrown.
 120.270 -     * If <code>len</code> is zero,
 120.271 -     * then no bytes are read. Otherwise, the first
 120.272 -     * byte read is stored into element <code>b[off]</code>,
 120.273 -     * the next one into <code>b[off+1]</code>,
 120.274 -     * and so on. The number of bytes read is,
 120.275 -     * at most, equal to <code>len</code>.
 120.276 -     *
 120.277 -     * @param     b   the buffer into which the data is read.
 120.278 -     * @param off  an int specifying the offset into the data.
 120.279 -     * @param len  an int specifying the number of bytes to read.
 120.280 -     * @exception  EOFException  if this stream reaches the end before reading
 120.281 -     *               all the bytes.
 120.282 -     * @exception  IOException   if an I/O error occurs.
 120.283 -     */
 120.284 -    void readFully(byte b[], int off, int len) throws IOException;
 120.285 -
 120.286 -    /**
 120.287 -     * Makes an attempt to skip over
 120.288 -     * <code>n</code> bytes
 120.289 -     * of data from the input
 120.290 -     * stream, discarding the skipped bytes. However,
 120.291 -     * it may skip
 120.292 -     * over some smaller number of
 120.293 -     * bytes, possibly zero. This may result from
 120.294 -     * any of a
 120.295 -     * number of conditions; reaching
 120.296 -     * end of file before <code>n</code> bytes
 120.297 -     * have been skipped is
 120.298 -     * only one possibility.
 120.299 -     * This method never throws an <code>EOFException</code>.
 120.300 -     * The actual
 120.301 -     * number of bytes skipped is returned.
 120.302 -     *
 120.303 -     * @param      n   the number of bytes to be skipped.
 120.304 -     * @return     the number of bytes actually skipped.
 120.305 -     * @exception  IOException   if an I/O error occurs.
 120.306 -     */
 120.307 -    int skipBytes(int n) throws IOException;
 120.308 -
 120.309 -    /**
 120.310 -     * Reads one input byte and returns
 120.311 -     * <code>true</code> if that byte is nonzero,
 120.312 -     * <code>false</code> if that byte is zero.
 120.313 -     * This method is suitable for reading
 120.314 -     * the byte written by the <code>writeBoolean</code>
 120.315 -     * method of interface <code>DataOutput</code>.
 120.316 -     *
 120.317 -     * @return     the <code>boolean</code> value read.
 120.318 -     * @exception  EOFException  if this stream reaches the end before reading
 120.319 -     *               all the bytes.
 120.320 -     * @exception  IOException   if an I/O error occurs.
 120.321 -     */
 120.322 -    boolean readBoolean() throws IOException;
 120.323 -
 120.324 -    /**
 120.325 -     * Reads and returns one input byte.
 120.326 -     * The byte is treated as a signed value in
 120.327 -     * the range <code>-128</code> through <code>127</code>,
 120.328 -     * inclusive.
 120.329 -     * This method is suitable for
 120.330 -     * reading the byte written by the <code>writeByte</code>
 120.331 -     * method of interface <code>DataOutput</code>.
 120.332 -     *
 120.333 -     * @return     the 8-bit value read.
 120.334 -     * @exception  EOFException  if this stream reaches the end before reading
 120.335 -     *               all the bytes.
 120.336 -     * @exception  IOException   if an I/O error occurs.
 120.337 -     */
 120.338 -    byte readByte() throws IOException;
 120.339 -
 120.340 -    /**
 120.341 -     * Reads one input byte, zero-extends
 120.342 -     * it to type <code>int</code>, and returns
 120.343 -     * the result, which is therefore in the range
 120.344 -     * <code>0</code>
 120.345 -     * through <code>255</code>.
 120.346 -     * This method is suitable for reading
 120.347 -     * the byte written by the <code>writeByte</code>
 120.348 -     * method of interface <code>DataOutput</code>
 120.349 -     * if the argument to <code>writeByte</code>
 120.350 -     * was intended to be a value in the range
 120.351 -     * <code>0</code> through <code>255</code>.
 120.352 -     *
 120.353 -     * @return     the unsigned 8-bit value read.
 120.354 -     * @exception  EOFException  if this stream reaches the end before reading
 120.355 -     *               all the bytes.
 120.356 -     * @exception  IOException   if an I/O error occurs.
 120.357 -     */
 120.358 -    int readUnsignedByte() throws IOException;
 120.359 -
 120.360 -    /**
 120.361 -     * Reads two input bytes and returns
 120.362 -     * a <code>short</code> value. Let <code>a</code>
 120.363 -     * be the first byte read and <code>b</code>
 120.364 -     * be the second byte. The value
 120.365 -     * returned
 120.366 -     * is:
 120.367 -     * <p><pre><code>(short)((a &lt;&lt; 8) | (b &amp; 0xff))
 120.368 -     * </code></pre>
 120.369 -     * This method
 120.370 -     * is suitable for reading the bytes written
 120.371 -     * by the <code>writeShort</code> method of
 120.372 -     * interface <code>DataOutput</code>.
 120.373 -     *
 120.374 -     * @return     the 16-bit value read.
 120.375 -     * @exception  EOFException  if this stream reaches the end before reading
 120.376 -     *               all the bytes.
 120.377 -     * @exception  IOException   if an I/O error occurs.
 120.378 -     */
 120.379 -    short readShort() throws IOException;
 120.380 -
 120.381 -    /**
 120.382 -     * Reads two input bytes and returns
 120.383 -     * an <code>int</code> value in the range <code>0</code>
 120.384 -     * through <code>65535</code>. Let <code>a</code>
 120.385 -     * be the first byte read and
 120.386 -     * <code>b</code>
 120.387 -     * be the second byte. The value returned is:
 120.388 -     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
 120.389 -     * </code></pre>
 120.390 -     * This method is suitable for reading the bytes
 120.391 -     * written by the <code>writeShort</code> method
 120.392 -     * of interface <code>DataOutput</code>  if
 120.393 -     * the argument to <code>writeShort</code>
 120.394 -     * was intended to be a value in the range
 120.395 -     * <code>0</code> through <code>65535</code>.
 120.396 -     *
 120.397 -     * @return     the unsigned 16-bit value read.
 120.398 -     * @exception  EOFException  if this stream reaches the end before reading
 120.399 -     *               all the bytes.
 120.400 -     * @exception  IOException   if an I/O error occurs.
 120.401 -     */
 120.402 -    int readUnsignedShort() throws IOException;
 120.403 -
 120.404 -    /**
 120.405 -     * Reads two input bytes and returns a <code>char</code> value.
 120.406 -     * Let <code>a</code>
 120.407 -     * be the first byte read and <code>b</code>
 120.408 -     * be the second byte. The value
 120.409 -     * returned is:
 120.410 -     * <p><pre><code>(char)((a &lt;&lt; 8) | (b &amp; 0xff))
 120.411 -     * </code></pre>
 120.412 -     * This method
 120.413 -     * is suitable for reading bytes written by
 120.414 -     * the <code>writeChar</code> method of interface
 120.415 -     * <code>DataOutput</code>.
 120.416 -     *
 120.417 -     * @return     the <code>char</code> value read.
 120.418 -     * @exception  EOFException  if this stream reaches the end before reading
 120.419 -     *               all the bytes.
 120.420 -     * @exception  IOException   if an I/O error occurs.
 120.421 -     */
 120.422 -    char readChar() throws IOException;
 120.423 -
 120.424 -    /**
 120.425 -     * Reads four input bytes and returns an
 120.426 -     * <code>int</code> value. Let <code>a-d</code>
 120.427 -     * be the first through fourth bytes read. The value returned is:
 120.428 -     * <p><pre>
 120.429 -     * <code>
 120.430 -     * (((a &amp; 0xff) &lt;&lt; 24) | ((b &amp; 0xff) &lt;&lt; 16) |
 120.431 -     * &#32;((c &amp; 0xff) &lt;&lt; 8) | (d &amp; 0xff))
 120.432 -     * </code></pre>
 120.433 -     * This method is suitable
 120.434 -     * for reading bytes written by the <code>writeInt</code>
 120.435 -     * method of interface <code>DataOutput</code>.
 120.436 -     *
 120.437 -     * @return     the <code>int</code> value read.
 120.438 -     * @exception  EOFException  if this stream reaches the end before reading
 120.439 -     *               all the bytes.
 120.440 -     * @exception  IOException   if an I/O error occurs.
 120.441 -     */
 120.442 -    int readInt() throws IOException;
 120.443 -
 120.444 -    /**
 120.445 -     * Reads eight input bytes and returns
 120.446 -     * a <code>long</code> value. Let <code>a-h</code>
 120.447 -     * be the first through eighth bytes read.
 120.448 -     * The value returned is:
 120.449 -     * <p><pre> <code>
 120.450 -     * (((long)(a &amp; 0xff) &lt;&lt; 56) |
 120.451 -     *  ((long)(b &amp; 0xff) &lt;&lt; 48) |
 120.452 -     *  ((long)(c &amp; 0xff) &lt;&lt; 40) |
 120.453 -     *  ((long)(d &amp; 0xff) &lt;&lt; 32) |
 120.454 -     *  ((long)(e &amp; 0xff) &lt;&lt; 24) |
 120.455 -     *  ((long)(f &amp; 0xff) &lt;&lt; 16) |
 120.456 -     *  ((long)(g &amp; 0xff) &lt;&lt;  8) |
 120.457 -     *  ((long)(h &amp; 0xff)))
 120.458 -     * </code></pre>
 120.459 -     * <p>
 120.460 -     * This method is suitable
 120.461 -     * for reading bytes written by the <code>writeLong</code>
 120.462 -     * method of interface <code>DataOutput</code>.
 120.463 -     *
 120.464 -     * @return     the <code>long</code> value read.
 120.465 -     * @exception  EOFException  if this stream reaches the end before reading
 120.466 -     *               all the bytes.
 120.467 -     * @exception  IOException   if an I/O error occurs.
 120.468 -     */
 120.469 -    long readLong() throws IOException;
 120.470 -
 120.471 -    /**
 120.472 -     * Reads four input bytes and returns
 120.473 -     * a <code>float</code> value. It does this
 120.474 -     * by first constructing an <code>int</code>
 120.475 -     * value in exactly the manner
 120.476 -     * of the <code>readInt</code>
 120.477 -     * method, then converting this <code>int</code>
 120.478 -     * value to a <code>float</code> in
 120.479 -     * exactly the manner of the method <code>Float.intBitsToFloat</code>.
 120.480 -     * This method is suitable for reading
 120.481 -     * bytes written by the <code>writeFloat</code>
 120.482 -     * method of interface <code>DataOutput</code>.
 120.483 -     *
 120.484 -     * @return     the <code>float</code> value read.
 120.485 -     * @exception  EOFException  if this stream reaches the end before reading
 120.486 -     *               all the bytes.
 120.487 -     * @exception  IOException   if an I/O error occurs.
 120.488 -     */
 120.489 -    float readFloat() throws IOException;
 120.490 -
 120.491 -    /**
 120.492 -     * Reads eight input bytes and returns
 120.493 -     * a <code>double</code> value. It does this
 120.494 -     * by first constructing a <code>long</code>
 120.495 -     * value in exactly the manner
 120.496 -     * of the <code>readlong</code>
 120.497 -     * method, then converting this <code>long</code>
 120.498 -     * value to a <code>double</code> in exactly
 120.499 -     * the manner of the method <code>Double.longBitsToDouble</code>.
 120.500 -     * This method is suitable for reading
 120.501 -     * bytes written by the <code>writeDouble</code>
 120.502 -     * method of interface <code>DataOutput</code>.
 120.503 -     *
 120.504 -     * @return     the <code>double</code> value read.
 120.505 -     * @exception  EOFException  if this stream reaches the end before reading
 120.506 -     *               all the bytes.
 120.507 -     * @exception  IOException   if an I/O error occurs.
 120.508 -     */
 120.509 -    double readDouble() throws IOException;
 120.510 -
 120.511 -    /**
 120.512 -     * Reads the next line of text from the input stream.
 120.513 -     * It reads successive bytes, converting
 120.514 -     * each byte separately into a character,
 120.515 -     * until it encounters a line terminator or
 120.516 -     * end of
 120.517 -     * file; the characters read are then
 120.518 -     * returned as a <code>String</code>. Note
 120.519 -     * that because this
 120.520 -     * method processes bytes,
 120.521 -     * it does not support input of the full Unicode
 120.522 -     * character set.
 120.523 -     * <p>
 120.524 -     * If end of file is encountered
 120.525 -     * before even one byte can be read, then <code>null</code>
 120.526 -     * is returned. Otherwise, each byte that is
 120.527 -     * read is converted to type <code>char</code>
 120.528 -     * by zero-extension. If the character <code>'\n'</code>
 120.529 -     * is encountered, it is discarded and reading
 120.530 -     * ceases. If the character <code>'\r'</code>
 120.531 -     * is encountered, it is discarded and, if
 120.532 -     * the following byte converts &#32;to the
 120.533 -     * character <code>'\n'</code>, then that is
 120.534 -     * discarded also; reading then ceases. If
 120.535 -     * end of file is encountered before either
 120.536 -     * of the characters <code>'\n'</code> and
 120.537 -     * <code>'\r'</code> is encountered, reading
 120.538 -     * ceases. Once reading has ceased, a <code>String</code>
 120.539 -     * is returned that contains all the characters
 120.540 -     * read and not discarded, taken in order.
 120.541 -     * Note that every character in this string
 120.542 -     * will have a value less than <code>&#92;u0100</code>,
 120.543 -     * that is, <code>(char)256</code>.
 120.544 -     *
 120.545 -     * @return the next line of text from the input stream,
 120.546 -     *         or <CODE>null</CODE> if the end of file is
 120.547 -     *         encountered before a byte can be read.
 120.548 -     * @exception  IOException  if an I/O error occurs.
 120.549 -     */
 120.550 -    String readLine() throws IOException;
 120.551 -
 120.552 -    /**
 120.553 -     * Reads in a string that has been encoded using a
 120.554 -     * <a href="#modified-utf-8">modified UTF-8</a>
 120.555 -     * format.
 120.556 -     * The general contract of <code>readUTF</code>
 120.557 -     * is that it reads a representation of a Unicode
 120.558 -     * character string encoded in modified
 120.559 -     * UTF-8 format; this string of characters
 120.560 -     * is then returned as a <code>String</code>.
 120.561 -     * <p>
 120.562 -     * First, two bytes are read and used to
 120.563 -     * construct an unsigned 16-bit integer in
 120.564 -     * exactly the manner of the <code>readUnsignedShort</code>
 120.565 -     * method . This integer value is called the
 120.566 -     * <i>UTF length</i> and specifies the number
 120.567 -     * of additional bytes to be read. These bytes
 120.568 -     * are then converted to characters by considering
 120.569 -     * them in groups. The length of each group
 120.570 -     * is computed from the value of the first
 120.571 -     * byte of the group. The byte following a
 120.572 -     * group, if any, is the first byte of the
 120.573 -     * next group.
 120.574 -     * <p>
 120.575 -     * If the first byte of a group
 120.576 -     * matches the bit pattern <code>0xxxxxxx</code>
 120.577 -     * (where <code>x</code> means "may be <code>0</code>
 120.578 -     * or <code>1</code>"), then the group consists
 120.579 -     * of just that byte. The byte is zero-extended
 120.580 -     * to form a character.
 120.581 -     * <p>
 120.582 -     * If the first byte
 120.583 -     * of a group matches the bit pattern <code>110xxxxx</code>,
 120.584 -     * then the group consists of that byte <code>a</code>
 120.585 -     * and a second byte <code>b</code>. If there
 120.586 -     * is no byte <code>b</code> (because byte
 120.587 -     * <code>a</code> was the last of the bytes
 120.588 -     * to be read), or if byte <code>b</code> does
 120.589 -     * not match the bit pattern <code>10xxxxxx</code>,
 120.590 -     * then a <code>UTFDataFormatException</code>
 120.591 -     * is thrown. Otherwise, the group is converted
 120.592 -     * to the character:<p>
 120.593 -     * <pre><code>(char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
 120.594 -     * </code></pre>
 120.595 -     * If the first byte of a group
 120.596 -     * matches the bit pattern <code>1110xxxx</code>,
 120.597 -     * then the group consists of that byte <code>a</code>
 120.598 -     * and two more bytes <code>b</code> and <code>c</code>.
 120.599 -     * If there is no byte <code>c</code> (because
 120.600 -     * byte <code>a</code> was one of the last
 120.601 -     * two of the bytes to be read), or either
 120.602 -     * byte <code>b</code> or byte <code>c</code>
 120.603 -     * does not match the bit pattern <code>10xxxxxx</code>,
 120.604 -     * then a <code>UTFDataFormatException</code>
 120.605 -     * is thrown. Otherwise, the group is converted
 120.606 -     * to the character:<p>
 120.607 -     * <pre><code>
 120.608 -     * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
 120.609 -     * </code></pre>
 120.610 -     * If the first byte of a group matches the
 120.611 -     * pattern <code>1111xxxx</code> or the pattern
 120.612 -     * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
 120.613 -     * is thrown.
 120.614 -     * <p>
 120.615 -     * If end of file is encountered
 120.616 -     * at any time during this entire process,
 120.617 -     * then an <code>EOFException</code> is thrown.
 120.618 -     * <p>
 120.619 -     * After every group has been converted to
 120.620 -     * a character by this process, the characters
 120.621 -     * are gathered, in the same order in which
 120.622 -     * their corresponding groups were read from
 120.623 -     * the input stream, to form a <code>String</code>,
 120.624 -     * which is returned.
 120.625 -     * <p>
 120.626 -     * The <code>writeUTF</code>
 120.627 -     * method of interface <code>DataOutput</code>
 120.628 -     * may be used to write data that is suitable
 120.629 -     * for reading by this method.
 120.630 -     * @return     a Unicode string.
 120.631 -     * @exception  EOFException            if this stream reaches the end
 120.632 -     *               before reading all the bytes.
 120.633 -     * @exception  IOException             if an I/O error occurs.
 120.634 -     * @exception  UTFDataFormatException  if the bytes do not represent a
 120.635 -     *               valid modified UTF-8 encoding of a string.
 120.636 -     */
 120.637 -    String readUTF() throws IOException;
 120.638 -}
   121.1 --- a/emul/mini/src/main/java/java/io/DataInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   121.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   121.3 @@ -1,700 +0,0 @@
   121.4 -/*
   121.5 - * Copyright (c) 1994, 2006, 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.io;
  121.30 -
  121.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  121.32 -import org.apidesign.bck2brwsr.emul.lang.System;
  121.33 -
  121.34 -/**
  121.35 - * A data input stream lets an application read primitive Java data
  121.36 - * types from an underlying input stream in a machine-independent
  121.37 - * way. An application uses a data output stream to write data that
  121.38 - * can later be read by a data input stream.
  121.39 - * <p>
  121.40 - * DataInputStream is not necessarily safe for multithreaded access.
  121.41 - * Thread safety is optional and is the responsibility of users of
  121.42 - * methods in this class.
  121.43 - *
  121.44 - * @author  Arthur van Hoff
  121.45 - * @see     java.io.DataOutputStream
  121.46 - * @since   JDK1.0
  121.47 - */
  121.48 -public
  121.49 -class DataInputStream extends FilterInputStream implements DataInput {
  121.50 -
  121.51 -    /**
  121.52 -     * Creates a DataInputStream that uses the specified
  121.53 -     * underlying InputStream.
  121.54 -     *
  121.55 -     * @param  in   the specified input stream
  121.56 -     */
  121.57 -    public DataInputStream(InputStream in) {
  121.58 -        super(in);
  121.59 -    }
  121.60 -
  121.61 -    /**
  121.62 -     * working arrays initialized on demand by readUTF
  121.63 -     */
  121.64 -    private byte bytearr[] = new byte[80];
  121.65 -    private char chararr[] = new char[80];
  121.66 -
  121.67 -    /**
  121.68 -     * Reads some number of bytes from the contained input stream and
  121.69 -     * stores them into the buffer array <code>b</code>. The number of
  121.70 -     * bytes actually read is returned as an integer. This method blocks
  121.71 -     * until input data is available, end of file is detected, or an
  121.72 -     * exception is thrown.
  121.73 -     *
  121.74 -     * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
  121.75 -     * thrown. If the length of <code>b</code> is zero, then no bytes are
  121.76 -     * read and <code>0</code> is returned; otherwise, there is an attempt
  121.77 -     * to read at least one byte. If no byte is available because the
  121.78 -     * stream is at end of file, the value <code>-1</code> is returned;
  121.79 -     * otherwise, at least one byte is read and stored into <code>b</code>.
  121.80 -     *
  121.81 -     * <p>The first byte read is stored into element <code>b[0]</code>, the
  121.82 -     * next one into <code>b[1]</code>, and so on. The number of bytes read
  121.83 -     * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
  121.84 -     * be the number of bytes actually read; these bytes will be stored in
  121.85 -     * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
  121.86 -     * elements <code>b[k]</code> through <code>b[b.length-1]</code>
  121.87 -     * unaffected.
  121.88 -     *
  121.89 -     * <p>The <code>read(b)</code> method has the same effect as:
  121.90 -     * <blockquote><pre>
  121.91 -     * read(b, 0, b.length)
  121.92 -     * </pre></blockquote>
  121.93 -     *
  121.94 -     * @param      b   the buffer into which the data is read.
  121.95 -     * @return     the total number of bytes read into the buffer, or
  121.96 -     *             <code>-1</code> if there is no more data because the end
  121.97 -     *             of the stream has been reached.
  121.98 -     * @exception  IOException if the first byte cannot be read for any reason
  121.99 -     * other than end of file, the stream has been closed and the underlying
 121.100 -     * input stream does not support reading after close, or another I/O
 121.101 -     * error occurs.
 121.102 -     * @see        java.io.FilterInputStream#in
 121.103 -     * @see        java.io.InputStream#read(byte[], int, int)
 121.104 -     */
 121.105 -    public final int read(byte b[]) throws IOException {
 121.106 -        return in.read(b, 0, b.length);
 121.107 -    }
 121.108 -
 121.109 -    /**
 121.110 -     * Reads up to <code>len</code> bytes of data from the contained
 121.111 -     * input stream into an array of bytes.  An attempt is made to read
 121.112 -     * as many as <code>len</code> bytes, but a smaller number may be read,
 121.113 -     * possibly zero. The number of bytes actually read is returned as an
 121.114 -     * integer.
 121.115 -     *
 121.116 -     * <p> This method blocks until input data is available, end of file is
 121.117 -     * detected, or an exception is thrown.
 121.118 -     *
 121.119 -     * <p> If <code>len</code> is zero, then no bytes are read and
 121.120 -     * <code>0</code> is returned; otherwise, there is an attempt to read at
 121.121 -     * least one byte. If no byte is available because the stream is at end of
 121.122 -     * file, the value <code>-1</code> is returned; otherwise, at least one
 121.123 -     * byte is read and stored into <code>b</code>.
 121.124 -     *
 121.125 -     * <p> The first byte read is stored into element <code>b[off]</code>, the
 121.126 -     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
 121.127 -     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
 121.128 -     * bytes actually read; these bytes will be stored in elements
 121.129 -     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
 121.130 -     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
 121.131 -     * <code>b[off+len-1]</code> unaffected.
 121.132 -     *
 121.133 -     * <p> In every case, elements <code>b[0]</code> through
 121.134 -     * <code>b[off]</code> and elements <code>b[off+len]</code> through
 121.135 -     * <code>b[b.length-1]</code> are unaffected.
 121.136 -     *
 121.137 -     * @param      b     the buffer into which the data is read.
 121.138 -     * @param off the start offset in the destination array <code>b</code>
 121.139 -     * @param      len   the maximum number of bytes read.
 121.140 -     * @return     the total number of bytes read into the buffer, or
 121.141 -     *             <code>-1</code> if there is no more data because the end
 121.142 -     *             of the stream has been reached.
 121.143 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 121.144 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 121.145 -     * <code>len</code> is negative, or <code>len</code> is greater than
 121.146 -     * <code>b.length - off</code>
 121.147 -     * @exception  IOException if the first byte cannot be read for any reason
 121.148 -     * other than end of file, the stream has been closed and the underlying
 121.149 -     * input stream does not support reading after close, or another I/O
 121.150 -     * error occurs.
 121.151 -     * @see        java.io.FilterInputStream#in
 121.152 -     * @see        java.io.InputStream#read(byte[], int, int)
 121.153 -     */
 121.154 -    public final int read(byte b[], int off, int len) throws IOException {
 121.155 -        return in.read(b, off, len);
 121.156 -    }
 121.157 -
 121.158 -    /**
 121.159 -     * See the general contract of the <code>readFully</code>
 121.160 -     * method of <code>DataInput</code>.
 121.161 -     * <p>
 121.162 -     * Bytes
 121.163 -     * for this operation are read from the contained
 121.164 -     * input stream.
 121.165 -     *
 121.166 -     * @param      b   the buffer into which the data is read.
 121.167 -     * @exception  EOFException  if this input stream reaches the end before
 121.168 -     *             reading all the bytes.
 121.169 -     * @exception  IOException   the stream has been closed and the contained
 121.170 -     *             input stream does not support reading after close, or
 121.171 -     *             another I/O error occurs.
 121.172 -     * @see        java.io.FilterInputStream#in
 121.173 -     */
 121.174 -    public final void readFully(byte b[]) throws IOException {
 121.175 -        readFully(b, 0, b.length);
 121.176 -    }
 121.177 -
 121.178 -    /**
 121.179 -     * See the general contract of the <code>readFully</code>
 121.180 -     * method of <code>DataInput</code>.
 121.181 -     * <p>
 121.182 -     * Bytes
 121.183 -     * for this operation are read from the contained
 121.184 -     * input stream.
 121.185 -     *
 121.186 -     * @param      b     the buffer into which the data is read.
 121.187 -     * @param      off   the start offset of the data.
 121.188 -     * @param      len   the number of bytes to read.
 121.189 -     * @exception  EOFException  if this input stream reaches the end before
 121.190 -     *               reading all the bytes.
 121.191 -     * @exception  IOException   the stream has been closed and the contained
 121.192 -     *             input stream does not support reading after close, or
 121.193 -     *             another I/O error occurs.
 121.194 -     * @see        java.io.FilterInputStream#in
 121.195 -     */
 121.196 -    public final void readFully(byte b[], int off, int len) throws IOException {
 121.197 -        if (len < 0)
 121.198 -            throw new IndexOutOfBoundsException();
 121.199 -        int n = 0;
 121.200 -        while (n < len) {
 121.201 -            int count = in.read(b, off + n, len - n);
 121.202 -            if (count < 0)
 121.203 -                throw new EOFException();
 121.204 -            n += count;
 121.205 -        }
 121.206 -    }
 121.207 -
 121.208 -    /**
 121.209 -     * See the general contract of the <code>skipBytes</code>
 121.210 -     * method of <code>DataInput</code>.
 121.211 -     * <p>
 121.212 -     * Bytes for this operation are read from the contained
 121.213 -     * input stream.
 121.214 -     *
 121.215 -     * @param      n   the number of bytes to be skipped.
 121.216 -     * @return     the actual number of bytes skipped.
 121.217 -     * @exception  IOException  if the contained input stream does not support
 121.218 -     *             seek, or the stream has been closed and
 121.219 -     *             the contained input stream does not support
 121.220 -     *             reading after close, or another I/O error occurs.
 121.221 -     */
 121.222 -    public final int skipBytes(int n) throws IOException {
 121.223 -        int total = 0;
 121.224 -        int cur = 0;
 121.225 -
 121.226 -        while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
 121.227 -            total += cur;
 121.228 -        }
 121.229 -
 121.230 -        return total;
 121.231 -    }
 121.232 -
 121.233 -    /**
 121.234 -     * See the general contract of the <code>readBoolean</code>
 121.235 -     * method of <code>DataInput</code>.
 121.236 -     * <p>
 121.237 -     * Bytes for this operation are read from the contained
 121.238 -     * input stream.
 121.239 -     *
 121.240 -     * @return     the <code>boolean</code> value read.
 121.241 -     * @exception  EOFException  if this input stream has reached the end.
 121.242 -     * @exception  IOException   the stream has been closed and the contained
 121.243 -     *             input stream does not support reading after close, or
 121.244 -     *             another I/O error occurs.
 121.245 -     * @see        java.io.FilterInputStream#in
 121.246 -     */
 121.247 -    public final boolean readBoolean() throws IOException {
 121.248 -        int ch = in.read();
 121.249 -        if (ch < 0)
 121.250 -            throw new EOFException();
 121.251 -        return (ch != 0);
 121.252 -    }
 121.253 -
 121.254 -    /**
 121.255 -     * See the general contract of the <code>readByte</code>
 121.256 -     * method of <code>DataInput</code>.
 121.257 -     * <p>
 121.258 -     * Bytes
 121.259 -     * for this operation are read from the contained
 121.260 -     * input stream.
 121.261 -     *
 121.262 -     * @return     the next byte of this input stream as a signed 8-bit
 121.263 -     *             <code>byte</code>.
 121.264 -     * @exception  EOFException  if this input stream has reached the end.
 121.265 -     * @exception  IOException   the stream has been closed and the contained
 121.266 -     *             input stream does not support reading after close, or
 121.267 -     *             another I/O error occurs.
 121.268 -     * @see        java.io.FilterInputStream#in
 121.269 -     */
 121.270 -    public final byte readByte() throws IOException {
 121.271 -        int ch = in.read();
 121.272 -        if (ch < 0)
 121.273 -            throw new EOFException();
 121.274 -        return (byte)(ch);
 121.275 -    }
 121.276 -
 121.277 -    /**
 121.278 -     * See the general contract of the <code>readUnsignedByte</code>
 121.279 -     * method of <code>DataInput</code>.
 121.280 -     * <p>
 121.281 -     * Bytes
 121.282 -     * for this operation are read from the contained
 121.283 -     * input stream.
 121.284 -     *
 121.285 -     * @return     the next byte of this input stream, interpreted as an
 121.286 -     *             unsigned 8-bit number.
 121.287 -     * @exception  EOFException  if this input stream has reached the end.
 121.288 -     * @exception  IOException   the stream has been closed and the contained
 121.289 -     *             input stream does not support reading after close, or
 121.290 -     *             another I/O error occurs.
 121.291 -     * @see         java.io.FilterInputStream#in
 121.292 -     */
 121.293 -    public final int readUnsignedByte() throws IOException {
 121.294 -        int ch = in.read();
 121.295 -        if (ch < 0)
 121.296 -            throw new EOFException();
 121.297 -        return ch;
 121.298 -    }
 121.299 -
 121.300 -    /**
 121.301 -     * See the general contract of the <code>readShort</code>
 121.302 -     * method of <code>DataInput</code>.
 121.303 -     * <p>
 121.304 -     * Bytes
 121.305 -     * for this operation are read from the contained
 121.306 -     * input stream.
 121.307 -     *
 121.308 -     * @return     the next two bytes of this input stream, interpreted as a
 121.309 -     *             signed 16-bit number.
 121.310 -     * @exception  EOFException  if this input stream reaches the end before
 121.311 -     *               reading two bytes.
 121.312 -     * @exception  IOException   the stream has been closed and the contained
 121.313 -     *             input stream does not support reading after close, or
 121.314 -     *             another I/O error occurs.
 121.315 -     * @see        java.io.FilterInputStream#in
 121.316 -     */
 121.317 -    public final short readShort() throws IOException {
 121.318 -        int ch1 = in.read();
 121.319 -        int ch2 = in.read();
 121.320 -        if ((ch1 | ch2) < 0)
 121.321 -            throw new EOFException();
 121.322 -        return (short)((ch1 << 8) + (ch2 << 0));
 121.323 -    }
 121.324 -
 121.325 -    /**
 121.326 -     * See the general contract of the <code>readUnsignedShort</code>
 121.327 -     * method of <code>DataInput</code>.
 121.328 -     * <p>
 121.329 -     * Bytes
 121.330 -     * for this operation are read from the contained
 121.331 -     * input stream.
 121.332 -     *
 121.333 -     * @return     the next two bytes of this input stream, interpreted as an
 121.334 -     *             unsigned 16-bit integer.
 121.335 -     * @exception  EOFException  if this input stream reaches the end before
 121.336 -     *             reading two bytes.
 121.337 -     * @exception  IOException   the stream has been closed and the contained
 121.338 -     *             input stream does not support reading after close, or
 121.339 -     *             another I/O error occurs.
 121.340 -     * @see        java.io.FilterInputStream#in
 121.341 -     */
 121.342 -    public final int readUnsignedShort() throws IOException {
 121.343 -        int ch1 = in.read();
 121.344 -        int ch2 = in.read();
 121.345 -        if ((ch1 | ch2) < 0)
 121.346 -            throw new EOFException();
 121.347 -        return (ch1 << 8) + (ch2 << 0);
 121.348 -    }
 121.349 -
 121.350 -    /**
 121.351 -     * See the general contract of the <code>readChar</code>
 121.352 -     * method of <code>DataInput</code>.
 121.353 -     * <p>
 121.354 -     * Bytes
 121.355 -     * for this operation are read from the contained
 121.356 -     * input stream.
 121.357 -     *
 121.358 -     * @return     the next two bytes of this input stream, interpreted as a
 121.359 -     *             <code>char</code>.
 121.360 -     * @exception  EOFException  if this input stream reaches the end before
 121.361 -     *               reading two bytes.
 121.362 -     * @exception  IOException   the stream has been closed and the contained
 121.363 -     *             input stream does not support reading after close, or
 121.364 -     *             another I/O error occurs.
 121.365 -     * @see        java.io.FilterInputStream#in
 121.366 -     */
 121.367 -    public final char readChar() throws IOException {
 121.368 -        int ch1 = in.read();
 121.369 -        int ch2 = in.read();
 121.370 -        if ((ch1 | ch2) < 0)
 121.371 -            throw new EOFException();
 121.372 -        return (char)((ch1 << 8) + (ch2 << 0));
 121.373 -    }
 121.374 -
 121.375 -    /**
 121.376 -     * See the general contract of the <code>readInt</code>
 121.377 -     * method of <code>DataInput</code>.
 121.378 -     * <p>
 121.379 -     * Bytes
 121.380 -     * for this operation are read from the contained
 121.381 -     * input stream.
 121.382 -     *
 121.383 -     * @return     the next four bytes of this input stream, interpreted as an
 121.384 -     *             <code>int</code>.
 121.385 -     * @exception  EOFException  if this input stream reaches the end before
 121.386 -     *               reading four bytes.
 121.387 -     * @exception  IOException   the stream has been closed and the contained
 121.388 -     *             input stream does not support reading after close, or
 121.389 -     *             another I/O error occurs.
 121.390 -     * @see        java.io.FilterInputStream#in
 121.391 -     */
 121.392 -    public final int readInt() throws IOException {
 121.393 -        int ch1 = in.read();
 121.394 -        int ch2 = in.read();
 121.395 -        int ch3 = in.read();
 121.396 -        int ch4 = in.read();
 121.397 -        if ((ch1 | ch2 | ch3 | ch4) < 0)
 121.398 -            throw new EOFException();
 121.399 -        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
 121.400 -    }
 121.401 -
 121.402 -    private byte readBuffer[] = new byte[8];
 121.403 -
 121.404 -    /**
 121.405 -     * See the general contract of the <code>readLong</code>
 121.406 -     * method of <code>DataInput</code>.
 121.407 -     * <p>
 121.408 -     * Bytes
 121.409 -     * for this operation are read from the contained
 121.410 -     * input stream.
 121.411 -     *
 121.412 -     * @return     the next eight bytes of this input stream, interpreted as a
 121.413 -     *             <code>long</code>.
 121.414 -     * @exception  EOFException  if this input stream reaches the end before
 121.415 -     *               reading eight bytes.
 121.416 -     * @exception  IOException   the stream has been closed and the contained
 121.417 -     *             input stream does not support reading after close, or
 121.418 -     *             another I/O error occurs.
 121.419 -     * @see        java.io.FilterInputStream#in
 121.420 -     */
 121.421 -    public final long readLong() throws IOException {
 121.422 -        readFully(readBuffer, 0, 8);
 121.423 -        return (((long)readBuffer[0] << 56) +
 121.424 -                ((long)(readBuffer[1] & 255) << 48) +
 121.425 -                ((long)(readBuffer[2] & 255) << 40) +
 121.426 -                ((long)(readBuffer[3] & 255) << 32) +
 121.427 -                ((long)(readBuffer[4] & 255) << 24) +
 121.428 -                ((readBuffer[5] & 255) << 16) +
 121.429 -                ((readBuffer[6] & 255) <<  8) +
 121.430 -                ((readBuffer[7] & 255) <<  0));
 121.431 -    }
 121.432 -
 121.433 -    /**
 121.434 -     * See the general contract of the <code>readFloat</code>
 121.435 -     * method of <code>DataInput</code>.
 121.436 -     * <p>
 121.437 -     * Bytes
 121.438 -     * for this operation are read from the contained
 121.439 -     * input stream.
 121.440 -     *
 121.441 -     * @return     the next four bytes of this input stream, interpreted as a
 121.442 -     *             <code>float</code>.
 121.443 -     * @exception  EOFException  if this input stream reaches the end before
 121.444 -     *               reading four bytes.
 121.445 -     * @exception  IOException   the stream has been closed and the contained
 121.446 -     *             input stream does not support reading after close, or
 121.447 -     *             another I/O error occurs.
 121.448 -     * @see        java.io.DataInputStream#readInt()
 121.449 -     * @see        java.lang.Float#intBitsToFloat(int)
 121.450 -     */
 121.451 -    public final float readFloat() throws IOException {
 121.452 -        return Float.intBitsToFloat(readInt());
 121.453 -    }
 121.454 -
 121.455 -    /**
 121.456 -     * See the general contract of the <code>readDouble</code>
 121.457 -     * method of <code>DataInput</code>.
 121.458 -     * <p>
 121.459 -     * Bytes
 121.460 -     * for this operation are read from the contained
 121.461 -     * input stream.
 121.462 -     *
 121.463 -     * @return     the next eight bytes of this input stream, interpreted as a
 121.464 -     *             <code>double</code>.
 121.465 -     * @exception  EOFException  if this input stream reaches the end before
 121.466 -     *               reading eight bytes.
 121.467 -     * @exception  IOException   the stream has been closed and the contained
 121.468 -     *             input stream does not support reading after close, or
 121.469 -     *             another I/O error occurs.
 121.470 -     * @see        java.io.DataInputStream#readLong()
 121.471 -     * @see        java.lang.Double#longBitsToDouble(long)
 121.472 -     */
 121.473 -    public final double readDouble() throws IOException {
 121.474 -        int hi = readInt();
 121.475 -        int low = readInt();
 121.476 -        return toDouble(hi, low);
 121.477 -    }
 121.478 -    
 121.479 -    @JavaScriptBody(args={ "hi", "low" },
 121.480 -        body=
 121.481 -          "if (low == 0) {\n"
 121.482 -        + "  if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
 121.483 -        + "  if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
 121.484 -        + "}\n"
 121.485 -        + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
 121.486 -        + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
 121.487 -        + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
 121.488 -        + "var e = (hi >> 20) & 0x7ff;\n"
 121.489 -        + "var to32 = low >> 0;\n"
 121.490 -        + "if (e === 0) {\n"
 121.491 -        + "  if (to32 & 0x80000000) {\n"
 121.492 -        + "    hi = hi << 1 + 1; low = low << 1;\n"
 121.493 -        + "  } else {\n"
 121.494 -        + "    hi = hi << 1; low = low << 1;\n"
 121.495 -        + "  }\n" 
 121.496 -        + "} else {\n"
 121.497 -        + "    hi = (hi & 0xfffff) | 0x100000;\n"
 121.498 -        + "}\n"
 121.499 -        + "to32 = low >> 0;\n"
 121.500 -        + "var m = Math.pow(2.0, 32) * hi + to32;\n"
 121.501 -        + "var r = s * m * Math.pow(2.0, e - 1075);\n"
 121.502 -        + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
 121.503 -        + "return r;\n"
 121.504 -    )
 121.505 -    private static double toDouble(int hi, int low) {
 121.506 -        long both = hi;
 121.507 -        both = (both << 32) & low;
 121.508 -        return Double.doubleToLongBits(both);
 121.509 -    }
 121.510 -
 121.511 -    private char lineBuffer[];
 121.512 -
 121.513 -    /**
 121.514 -     * See the general contract of the <code>readLine</code>
 121.515 -     * method of <code>DataInput</code>.
 121.516 -     * <p>
 121.517 -     * Bytes
 121.518 -     * for this operation are read from the contained
 121.519 -     * input stream.
 121.520 -     *
 121.521 -     * @deprecated This method does not properly convert bytes to characters.
 121.522 -     * As of JDK&nbsp;1.1, the preferred way to read lines of text is via the
 121.523 -     * <code>BufferedReader.readLine()</code> method.  Programs that use the
 121.524 -     * <code>DataInputStream</code> class to read lines can be converted to use
 121.525 -     * the <code>BufferedReader</code> class by replacing code of the form:
 121.526 -     * <blockquote><pre>
 121.527 -     *     DataInputStream d =&nbsp;new&nbsp;DataInputStream(in);
 121.528 -     * </pre></blockquote>
 121.529 -     * with:
 121.530 -     * <blockquote><pre>
 121.531 -     *     BufferedReader d
 121.532 -     *          =&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(in));
 121.533 -     * </pre></blockquote>
 121.534 -     *
 121.535 -     * @return     the next line of text from this input stream.
 121.536 -     * @exception  IOException  if an I/O error occurs.
 121.537 -     * @see        java.io.BufferedReader#readLine()
 121.538 -     * @see        java.io.FilterInputStream#in
 121.539 -     */
 121.540 -    @Deprecated
 121.541 -    public final String readLine() throws IOException {
 121.542 -        char buf[] = lineBuffer;
 121.543 -
 121.544 -        if (buf == null) {
 121.545 -            buf = lineBuffer = new char[128];
 121.546 -        }
 121.547 -
 121.548 -        int room = buf.length;
 121.549 -        int offset = 0;
 121.550 -        int c;
 121.551 -
 121.552 -loop:   while (true) {
 121.553 -            switch (c = in.read()) {
 121.554 -              case -1:
 121.555 -              case '\n':
 121.556 -                break loop;
 121.557 -
 121.558 -              case '\r':
 121.559 -                int c2 = in.read();
 121.560 -                if ((c2 != '\n') && (c2 != -1)) {
 121.561 -                    if (!(in instanceof PushbackInputStream)) {
 121.562 -                        this.in = new PushbackInputStream(in);
 121.563 -                    }
 121.564 -                    ((PushbackInputStream)in).unread(c2);
 121.565 -                }
 121.566 -                break loop;
 121.567 -
 121.568 -              default:
 121.569 -                if (--room < 0) {
 121.570 -                    buf = new char[offset + 128];
 121.571 -                    room = buf.length - offset - 1;
 121.572 -                    System.arraycopy(lineBuffer, 0, buf, 0, offset);
 121.573 -                    lineBuffer = buf;
 121.574 -                }
 121.575 -                buf[offset++] = (char) c;
 121.576 -                break;
 121.577 -            }
 121.578 -        }
 121.579 -        if ((c == -1) && (offset == 0)) {
 121.580 -            return null;
 121.581 -        }
 121.582 -        return String.copyValueOf(buf, 0, offset);
 121.583 -    }
 121.584 -
 121.585 -    /**
 121.586 -     * See the general contract of the <code>readUTF</code>
 121.587 -     * method of <code>DataInput</code>.
 121.588 -     * <p>
 121.589 -     * Bytes
 121.590 -     * for this operation are read from the contained
 121.591 -     * input stream.
 121.592 -     *
 121.593 -     * @return     a Unicode string.
 121.594 -     * @exception  EOFException  if this input stream reaches the end before
 121.595 -     *               reading all the bytes.
 121.596 -     * @exception  IOException   the stream has been closed and the contained
 121.597 -     *             input stream does not support reading after close, or
 121.598 -     *             another I/O error occurs.
 121.599 -     * @exception  UTFDataFormatException if the bytes do not represent a valid
 121.600 -     *             modified UTF-8 encoding of a string.
 121.601 -     * @see        java.io.DataInputStream#readUTF(java.io.DataInput)
 121.602 -     */
 121.603 -    public final String readUTF() throws IOException {
 121.604 -        return readUTF(this);
 121.605 -    }
 121.606 -
 121.607 -    /**
 121.608 -     * Reads from the
 121.609 -     * stream <code>in</code> a representation
 121.610 -     * of a Unicode  character string encoded in
 121.611 -     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
 121.612 -     * this string of characters is then returned as a <code>String</code>.
 121.613 -     * The details of the modified UTF-8 representation
 121.614 -     * are  exactly the same as for the <code>readUTF</code>
 121.615 -     * method of <code>DataInput</code>.
 121.616 -     *
 121.617 -     * @param      in   a data input stream.
 121.618 -     * @return     a Unicode string.
 121.619 -     * @exception  EOFException            if the input stream reaches the end
 121.620 -     *               before all the bytes.
 121.621 -     * @exception  IOException   the stream has been closed and the contained
 121.622 -     *             input stream does not support reading after close, or
 121.623 -     *             another I/O error occurs.
 121.624 -     * @exception  UTFDataFormatException  if the bytes do not represent a
 121.625 -     *               valid modified UTF-8 encoding of a Unicode string.
 121.626 -     * @see        java.io.DataInputStream#readUnsignedShort()
 121.627 -     */
 121.628 -    public final static String readUTF(DataInput in) throws IOException {
 121.629 -        int utflen = in.readUnsignedShort();
 121.630 -        byte[] bytearr = null;
 121.631 -        char[] chararr = null;
 121.632 -        if (in instanceof DataInputStream) {
 121.633 -            DataInputStream dis = (DataInputStream)in;
 121.634 -            if (dis.bytearr.length < utflen){
 121.635 -                dis.bytearr = new byte[utflen*2];
 121.636 -                dis.chararr = new char[utflen*2];
 121.637 -            }
 121.638 -            chararr = dis.chararr;
 121.639 -            bytearr = dis.bytearr;
 121.640 -        } else {
 121.641 -            bytearr = new byte[utflen];
 121.642 -            chararr = new char[utflen];
 121.643 -        }
 121.644 -
 121.645 -        int c, char2, char3;
 121.646 -        int count = 0;
 121.647 -        int chararr_count=0;
 121.648 -
 121.649 -        in.readFully(bytearr, 0, utflen);
 121.650 -
 121.651 -        while (count < utflen) {
 121.652 -            c = (int) bytearr[count] & 0xff;
 121.653 -            if (c > 127) break;
 121.654 -            count++;
 121.655 -            chararr[chararr_count++]=(char)c;
 121.656 -        }
 121.657 -
 121.658 -        while (count < utflen) {
 121.659 -            c = (int) bytearr[count] & 0xff;
 121.660 -            switch (c >> 4) {
 121.661 -                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
 121.662 -                    /* 0xxxxxxx*/
 121.663 -                    count++;
 121.664 -                    chararr[chararr_count++]=(char)c;
 121.665 -                    break;
 121.666 -                case 12: case 13:
 121.667 -                    /* 110x xxxx   10xx xxxx*/
 121.668 -                    count += 2;
 121.669 -                    if (count > utflen)
 121.670 -                        throw new UTFDataFormatException(
 121.671 -                            "malformed input: partial character at end");
 121.672 -                    char2 = (int) bytearr[count-1];
 121.673 -                    if ((char2 & 0xC0) != 0x80)
 121.674 -                        throw new UTFDataFormatException(
 121.675 -                            "malformed input around byte " + count);
 121.676 -                    chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
 121.677 -                                                    (char2 & 0x3F));
 121.678 -                    break;
 121.679 -                case 14:
 121.680 -                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
 121.681 -                    count += 3;
 121.682 -                    if (count > utflen)
 121.683 -                        throw new UTFDataFormatException(
 121.684 -                            "malformed input: partial character at end");
 121.685 -                    char2 = (int) bytearr[count-2];
 121.686 -                    char3 = (int) bytearr[count-1];
 121.687 -                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
 121.688 -                        throw new UTFDataFormatException(
 121.689 -                            "malformed input around byte " + (count-1));
 121.690 -                    chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
 121.691 -                                                    ((char2 & 0x3F) << 6)  |
 121.692 -                                                    ((char3 & 0x3F) << 0));
 121.693 -                    break;
 121.694 -                default:
 121.695 -                    /* 10xx xxxx,  1111 xxxx */
 121.696 -                    throw new UTFDataFormatException(
 121.697 -                        "malformed input around byte " + count);
 121.698 -            }
 121.699 -        }
 121.700 -        // The number of chars produced may be less than utflen
 121.701 -        return new String(chararr, 0, chararr_count);
 121.702 -    }
 121.703 -}
   122.1 --- a/emul/mini/src/main/java/java/io/EOFException.java	Mon Feb 25 19:00:08 2013 +0100
   122.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   122.3 @@ -1,65 +0,0 @@
   122.4 -/*
   122.5 - * Copyright (c) 1995, 2008, 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.io;
  122.30 -
  122.31 -/**
  122.32 - * Signals that an end of file or end of stream has been reached
  122.33 - * unexpectedly during input.
  122.34 - * <p>
  122.35 - * This exception is mainly used by data input streams to signal end of
  122.36 - * stream. Note that many other input operations return a special value on
  122.37 - * end of stream rather than throwing an exception.
  122.38 - * <p>
  122.39 - *
  122.40 - * @author  Frank Yellin
  122.41 - * @see     java.io.DataInputStream
  122.42 - * @see     java.io.IOException
  122.43 - * @since   JDK1.0
  122.44 - */
  122.45 -public
  122.46 -class EOFException extends IOException {
  122.47 -    private static final long serialVersionUID = 6433858223774886977L;
  122.48 -
  122.49 -    /**
  122.50 -     * Constructs an <code>EOFException</code> with <code>null</code>
  122.51 -     * as its error detail message.
  122.52 -     */
  122.53 -    public EOFException() {
  122.54 -        super();
  122.55 -    }
  122.56 -
  122.57 -    /**
  122.58 -     * Constructs an <code>EOFException</code> with the specified detail
  122.59 -     * message. The string <code>s</code> may later be retrieved by the
  122.60 -     * <code>{@link java.lang.Throwable#getMessage}</code> method of class
  122.61 -     * <code>java.lang.Throwable</code>.
  122.62 -     *
  122.63 -     * @param   s   the detail message.
  122.64 -     */
  122.65 -    public EOFException(String s) {
  122.66 -        super(s);
  122.67 -    }
  122.68 -}
   123.1 --- a/emul/mini/src/main/java/java/io/FilterInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   123.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   123.3 @@ -1,245 +0,0 @@
   123.4 -/*
   123.5 - * Copyright (c) 1994, 2010, 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.io;
  123.30 -
  123.31 -/**
  123.32 - * A <code>FilterInputStream</code> contains
  123.33 - * some other input stream, which it uses as
  123.34 - * its  basic source of data, possibly transforming
  123.35 - * the data along the way or providing  additional
  123.36 - * functionality. The class <code>FilterInputStream</code>
  123.37 - * itself simply overrides all  methods of
  123.38 - * <code>InputStream</code> with versions that
  123.39 - * pass all requests to the contained  input
  123.40 - * stream. Subclasses of <code>FilterInputStream</code>
  123.41 - * may further override some of  these methods
  123.42 - * and may also provide additional methods
  123.43 - * and fields.
  123.44 - *
  123.45 - * @author  Jonathan Payne
  123.46 - * @since   JDK1.0
  123.47 - */
  123.48 -public
  123.49 -class FilterInputStream extends InputStream {
  123.50 -    /**
  123.51 -     * The input stream to be filtered.
  123.52 -     */
  123.53 -    protected volatile InputStream in;
  123.54 -
  123.55 -    /**
  123.56 -     * Creates a <code>FilterInputStream</code>
  123.57 -     * by assigning the  argument <code>in</code>
  123.58 -     * to the field <code>this.in</code> so as
  123.59 -     * to remember it for later use.
  123.60 -     *
  123.61 -     * @param   in   the underlying input stream, or <code>null</code> if
  123.62 -     *          this instance is to be created without an underlying stream.
  123.63 -     */
  123.64 -    protected FilterInputStream(InputStream in) {
  123.65 -        this.in = in;
  123.66 -    }
  123.67 -
  123.68 -    /**
  123.69 -     * Reads the next byte of data from this input stream. The value
  123.70 -     * byte is returned as an <code>int</code> in the range
  123.71 -     * <code>0</code> to <code>255</code>. If no byte is available
  123.72 -     * because the end of the stream has been reached, the value
  123.73 -     * <code>-1</code> is returned. This method blocks until input data
  123.74 -     * is available, the end of the stream is detected, or an exception
  123.75 -     * is thrown.
  123.76 -     * <p>
  123.77 -     * This method
  123.78 -     * simply performs <code>in.read()</code> and returns the result.
  123.79 -     *
  123.80 -     * @return     the next byte of data, or <code>-1</code> if the end of the
  123.81 -     *             stream is reached.
  123.82 -     * @exception  IOException  if an I/O error occurs.
  123.83 -     * @see        java.io.FilterInputStream#in
  123.84 -     */
  123.85 -    public int read() throws IOException {
  123.86 -        return in.read();
  123.87 -    }
  123.88 -
  123.89 -    /**
  123.90 -     * Reads up to <code>byte.length</code> bytes of data from this
  123.91 -     * input stream into an array of bytes. This method blocks until some
  123.92 -     * input is available.
  123.93 -     * <p>
  123.94 -     * This method simply performs the call
  123.95 -     * <code>read(b, 0, b.length)</code> and returns
  123.96 -     * the  result. It is important that it does
  123.97 -     * <i>not</i> do <code>in.read(b)</code> instead;
  123.98 -     * certain subclasses of  <code>FilterInputStream</code>
  123.99 -     * depend on the implementation strategy actually
 123.100 -     * used.
 123.101 -     *
 123.102 -     * @param      b   the buffer into which the data is read.
 123.103 -     * @return     the total number of bytes read into the buffer, or
 123.104 -     *             <code>-1</code> if there is no more data because the end of
 123.105 -     *             the stream has been reached.
 123.106 -     * @exception  IOException  if an I/O error occurs.
 123.107 -     * @see        java.io.FilterInputStream#read(byte[], int, int)
 123.108 -     */
 123.109 -    public int read(byte b[]) throws IOException {
 123.110 -        return read(b, 0, b.length);
 123.111 -    }
 123.112 -
 123.113 -    /**
 123.114 -     * Reads up to <code>len</code> bytes of data from this input stream
 123.115 -     * into an array of bytes. If <code>len</code> is not zero, the method
 123.116 -     * blocks until some input is available; otherwise, no
 123.117 -     * bytes are read and <code>0</code> is returned.
 123.118 -     * <p>
 123.119 -     * This method simply performs <code>in.read(b, off, len)</code>
 123.120 -     * and returns the result.
 123.121 -     *
 123.122 -     * @param      b     the buffer into which the data is read.
 123.123 -     * @param      off   the start offset in the destination array <code>b</code>
 123.124 -     * @param      len   the maximum number of bytes read.
 123.125 -     * @return     the total number of bytes read into the buffer, or
 123.126 -     *             <code>-1</code> if there is no more data because the end of
 123.127 -     *             the stream has been reached.
 123.128 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 123.129 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 123.130 -     * <code>len</code> is negative, or <code>len</code> is greater than
 123.131 -     * <code>b.length - off</code>
 123.132 -     * @exception  IOException  if an I/O error occurs.
 123.133 -     * @see        java.io.FilterInputStream#in
 123.134 -     */
 123.135 -    public int read(byte b[], int off, int len) throws IOException {
 123.136 -        return in.read(b, off, len);
 123.137 -    }
 123.138 -
 123.139 -    /**
 123.140 -     * Skips over and discards <code>n</code> bytes of data from the
 123.141 -     * input stream. The <code>skip</code> method may, for a variety of
 123.142 -     * reasons, end up skipping over some smaller number of bytes,
 123.143 -     * possibly <code>0</code>. The actual number of bytes skipped is
 123.144 -     * returned.
 123.145 -     * <p>
 123.146 -     * This method simply performs <code>in.skip(n)</code>.
 123.147 -     *
 123.148 -     * @param      n   the number of bytes to be skipped.
 123.149 -     * @return     the actual number of bytes skipped.
 123.150 -     * @exception  IOException  if the stream does not support seek,
 123.151 -     *                          or if some other I/O error occurs.
 123.152 -     */
 123.153 -    public long skip(long n) throws IOException {
 123.154 -        return in.skip(n);
 123.155 -    }
 123.156 -
 123.157 -    /**
 123.158 -     * Returns an estimate of the number of bytes that can be read (or
 123.159 -     * skipped over) from this input stream without blocking by the next
 123.160 -     * caller of a method for this input stream. The next caller might be
 123.161 -     * the same thread or another thread.  A single read or skip of this
 123.162 -     * many bytes will not block, but may read or skip fewer bytes.
 123.163 -     * <p>
 123.164 -     * This method returns the result of {@link #in in}.available().
 123.165 -     *
 123.166 -     * @return     an estimate of the number of bytes that can be read (or skipped
 123.167 -     *             over) from this input stream without blocking.
 123.168 -     * @exception  IOException  if an I/O error occurs.
 123.169 -     */
 123.170 -    public int available() throws IOException {
 123.171 -        return in.available();
 123.172 -    }
 123.173 -
 123.174 -    /**
 123.175 -     * Closes this input stream and releases any system resources
 123.176 -     * associated with the stream.
 123.177 -     * This
 123.178 -     * method simply performs <code>in.close()</code>.
 123.179 -     *
 123.180 -     * @exception  IOException  if an I/O error occurs.
 123.181 -     * @see        java.io.FilterInputStream#in
 123.182 -     */
 123.183 -    public void close() throws IOException {
 123.184 -        in.close();
 123.185 -    }
 123.186 -
 123.187 -    /**
 123.188 -     * Marks the current position in this input stream. A subsequent
 123.189 -     * call to the <code>reset</code> method repositions this stream at
 123.190 -     * the last marked position so that subsequent reads re-read the same bytes.
 123.191 -     * <p>
 123.192 -     * The <code>readlimit</code> argument tells this input stream to
 123.193 -     * allow that many bytes to be read before the mark position gets
 123.194 -     * invalidated.
 123.195 -     * <p>
 123.196 -     * This method simply performs <code>in.mark(readlimit)</code>.
 123.197 -     *
 123.198 -     * @param   readlimit   the maximum limit of bytes that can be read before
 123.199 -     *                      the mark position becomes invalid.
 123.200 -     * @see     java.io.FilterInputStream#in
 123.201 -     * @see     java.io.FilterInputStream#reset()
 123.202 -     */
 123.203 -    public synchronized void mark(int readlimit) {
 123.204 -        in.mark(readlimit);
 123.205 -    }
 123.206 -
 123.207 -    /**
 123.208 -     * Repositions this stream to the position at the time the
 123.209 -     * <code>mark</code> method was last called on this input stream.
 123.210 -     * <p>
 123.211 -     * This method
 123.212 -     * simply performs <code>in.reset()</code>.
 123.213 -     * <p>
 123.214 -     * Stream marks are intended to be used in
 123.215 -     * situations where you need to read ahead a little to see what's in
 123.216 -     * the stream. Often this is most easily done by invoking some
 123.217 -     * general parser. If the stream is of the type handled by the
 123.218 -     * parse, it just chugs along happily. If the stream is not of
 123.219 -     * that type, the parser should toss an exception when it fails.
 123.220 -     * If this happens within readlimit bytes, it allows the outer
 123.221 -     * code to reset the stream and try another parser.
 123.222 -     *
 123.223 -     * @exception  IOException  if the stream has not been marked or if the
 123.224 -     *               mark has been invalidated.
 123.225 -     * @see        java.io.FilterInputStream#in
 123.226 -     * @see        java.io.FilterInputStream#mark(int)
 123.227 -     */
 123.228 -    public synchronized void reset() throws IOException {
 123.229 -        in.reset();
 123.230 -    }
 123.231 -
 123.232 -    /**
 123.233 -     * Tests if this input stream supports the <code>mark</code>
 123.234 -     * and <code>reset</code> methods.
 123.235 -     * This method
 123.236 -     * simply performs <code>in.markSupported()</code>.
 123.237 -     *
 123.238 -     * @return  <code>true</code> if this stream type supports the
 123.239 -     *          <code>mark</code> and <code>reset</code> method;
 123.240 -     *          <code>false</code> otherwise.
 123.241 -     * @see     java.io.FilterInputStream#in
 123.242 -     * @see     java.io.InputStream#mark(int)
 123.243 -     * @see     java.io.InputStream#reset()
 123.244 -     */
 123.245 -    public boolean markSupported() {
 123.246 -        return in.markSupported();
 123.247 -    }
 123.248 -}
   124.1 --- a/emul/mini/src/main/java/java/io/IOException.java	Mon Feb 25 19:00:08 2013 +0100
   124.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.3 @@ -1,101 +0,0 @@
   124.4 -/*
   124.5 - * Copyright (c) 1994, 2006, 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.io;
  124.30 -
  124.31 -/**
  124.32 - * Signals that an I/O exception of some sort has occurred. This
  124.33 - * class is the general class of exceptions produced by failed or
  124.34 - * interrupted I/O operations.
  124.35 - *
  124.36 - * @author  unascribed
  124.37 - * @see     java.io.InputStream
  124.38 - * @see     java.io.OutputStream
  124.39 - * @since   JDK1.0
  124.40 - */
  124.41 -public
  124.42 -class IOException extends Exception {
  124.43 -    static final long serialVersionUID = 7818375828146090155L;
  124.44 -
  124.45 -    /**
  124.46 -     * Constructs an {@code IOException} with {@code null}
  124.47 -     * as its error detail message.
  124.48 -     */
  124.49 -    public IOException() {
  124.50 -        super();
  124.51 -    }
  124.52 -
  124.53 -    /**
  124.54 -     * Constructs an {@code IOException} with the specified detail message.
  124.55 -     *
  124.56 -     * @param message
  124.57 -     *        The detail message (which is saved for later retrieval
  124.58 -     *        by the {@link #getMessage()} method)
  124.59 -     */
  124.60 -    public IOException(String message) {
  124.61 -        super(message);
  124.62 -    }
  124.63 -
  124.64 -    /**
  124.65 -     * Constructs an {@code IOException} with the specified detail message
  124.66 -     * and cause.
  124.67 -     *
  124.68 -     * <p> Note that the detail message associated with {@code cause} is
  124.69 -     * <i>not</i> automatically incorporated into this exception's detail
  124.70 -     * message.
  124.71 -     *
  124.72 -     * @param message
  124.73 -     *        The detail message (which is saved for later retrieval
  124.74 -     *        by the {@link #getMessage()} method)
  124.75 -     *
  124.76 -     * @param cause
  124.77 -     *        The cause (which is saved for later retrieval by the
  124.78 -     *        {@link #getCause()} method).  (A null value is permitted,
  124.79 -     *        and indicates that the cause is nonexistent or unknown.)
  124.80 -     *
  124.81 -     * @since 1.6
  124.82 -     */
  124.83 -    public IOException(String message, Throwable cause) {
  124.84 -        super(message, cause);
  124.85 -    }
  124.86 -
  124.87 -    /**
  124.88 -     * Constructs an {@code IOException} with the specified cause and a
  124.89 -     * detail message of {@code (cause==null ? null : cause.toString())}
  124.90 -     * (which typically contains the class and detail message of {@code cause}).
  124.91 -     * This constructor is useful for IO exceptions that are little more
  124.92 -     * than wrappers for other throwables.
  124.93 -     *
  124.94 -     * @param cause
  124.95 -     *        The cause (which is saved for later retrieval by the
  124.96 -     *        {@link #getCause()} method).  (A null value is permitted,
  124.97 -     *        and indicates that the cause is nonexistent or unknown.)
  124.98 -     *
  124.99 -     * @since 1.6
 124.100 -     */
 124.101 -    public IOException(Throwable cause) {
 124.102 -        super(cause);
 124.103 -    }
 124.104 -}
   125.1 --- a/emul/mini/src/main/java/java/io/InputStream.java	Mon Feb 25 19:00:08 2013 +0100
   125.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   125.3 @@ -1,370 +0,0 @@
   125.4 -/*
   125.5 - * Copyright (c) 1994, 2006, 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.io;
  125.30 -
  125.31 -/**
  125.32 - * This abstract class is the superclass of all classes representing
  125.33 - * an input stream of bytes.
  125.34 - *
  125.35 - * <p> Applications that need to define a subclass of <code>InputStream</code>
  125.36 - * must always provide a method that returns the next byte of input.
  125.37 - *
  125.38 - * @author  Arthur van Hoff
  125.39 - * @see     java.io.BufferedInputStream
  125.40 - * @see     java.io.ByteArrayInputStream
  125.41 - * @see     java.io.DataInputStream
  125.42 - * @see     java.io.FilterInputStream
  125.43 - * @see     java.io.InputStream#read()
  125.44 - * @see     java.io.OutputStream
  125.45 - * @see     java.io.PushbackInputStream
  125.46 - * @since   JDK1.0
  125.47 - */
  125.48 -public abstract class InputStream implements Closeable {
  125.49 -
  125.50 -    // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
  125.51 -    private static final int SKIP_BUFFER_SIZE = 2048;
  125.52 -    // skipBuffer is initialized in skip(long), if needed.
  125.53 -    private static byte[] skipBuffer;
  125.54 -
  125.55 -    /**
  125.56 -     * Reads the next byte of data from the input stream. The value byte is
  125.57 -     * returned as an <code>int</code> in the range <code>0</code> to
  125.58 -     * <code>255</code>. If no byte is available because the end of the stream
  125.59 -     * has been reached, the value <code>-1</code> is returned. This method
  125.60 -     * blocks until input data is available, the end of the stream is detected,
  125.61 -     * or an exception is thrown.
  125.62 -     *
  125.63 -     * <p> A subclass must provide an implementation of this method.
  125.64 -     *
  125.65 -     * @return     the next byte of data, or <code>-1</code> if the end of the
  125.66 -     *             stream is reached.
  125.67 -     * @exception  IOException  if an I/O error occurs.
  125.68 -     */
  125.69 -    public abstract int read() throws IOException;
  125.70 -
  125.71 -    /**
  125.72 -     * Reads some number of bytes from the input stream and stores them into
  125.73 -     * the buffer array <code>b</code>. The number of bytes actually read is
  125.74 -     * returned as an integer.  This method blocks until input data is
  125.75 -     * available, end of file is detected, or an exception is thrown.
  125.76 -     *
  125.77 -     * <p> If the length of <code>b</code> is zero, then no bytes are read and
  125.78 -     * <code>0</code> is returned; otherwise, there is an attempt to read at
  125.79 -     * least one byte. If no byte is available because the stream is at the
  125.80 -     * end of the file, the value <code>-1</code> is returned; otherwise, at
  125.81 -     * least one byte is read and stored into <code>b</code>.
  125.82 -     *
  125.83 -     * <p> The first byte read is stored into element <code>b[0]</code>, the
  125.84 -     * next one into <code>b[1]</code>, and so on. The number of bytes read is,
  125.85 -     * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
  125.86 -     * number of bytes actually read; these bytes will be stored in elements
  125.87 -     * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
  125.88 -     * leaving elements <code>b[</code><i>k</i><code>]</code> through
  125.89 -     * <code>b[b.length-1]</code> unaffected.
  125.90 -     *
  125.91 -     * <p> The <code>read(b)</code> method for class <code>InputStream</code>
  125.92 -     * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
  125.93 -     *
  125.94 -     * @param      b   the buffer into which the data is read.
  125.95 -     * @return     the total number of bytes read into the buffer, or
  125.96 -     *             <code>-1</code> if there is no more data because the end of
  125.97 -     *             the stream has been reached.
  125.98 -     * @exception  IOException  If the first byte cannot be read for any reason
  125.99 -     * other than the end of the file, if the input stream has been closed, or
 125.100 -     * if some other I/O error occurs.
 125.101 -     * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
 125.102 -     * @see        java.io.InputStream#read(byte[], int, int)
 125.103 -     */
 125.104 -    public int read(byte b[]) throws IOException {
 125.105 -        return read(b, 0, b.length);
 125.106 -    }
 125.107 -
 125.108 -    /**
 125.109 -     * Reads up to <code>len</code> bytes of data from the input stream into
 125.110 -     * an array of bytes.  An attempt is made to read as many as
 125.111 -     * <code>len</code> bytes, but a smaller number may be read.
 125.112 -     * The number of bytes actually read is returned as an integer.
 125.113 -     *
 125.114 -     * <p> This method blocks until input data is available, end of file is
 125.115 -     * detected, or an exception is thrown.
 125.116 -     *
 125.117 -     * <p> If <code>len</code> is zero, then no bytes are read and
 125.118 -     * <code>0</code> is returned; otherwise, there is an attempt to read at
 125.119 -     * least one byte. If no byte is available because the stream is at end of
 125.120 -     * file, the value <code>-1</code> is returned; otherwise, at least one
 125.121 -     * byte is read and stored into <code>b</code>.
 125.122 -     *
 125.123 -     * <p> The first byte read is stored into element <code>b[off]</code>, the
 125.124 -     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
 125.125 -     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
 125.126 -     * bytes actually read; these bytes will be stored in elements
 125.127 -     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
 125.128 -     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
 125.129 -     * <code>b[off+len-1]</code> unaffected.
 125.130 -     *
 125.131 -     * <p> In every case, elements <code>b[0]</code> through
 125.132 -     * <code>b[off]</code> and elements <code>b[off+len]</code> through
 125.133 -     * <code>b[b.length-1]</code> are unaffected.
 125.134 -     *
 125.135 -     * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
 125.136 -     * for class <code>InputStream</code> simply calls the method
 125.137 -     * <code>read()</code> repeatedly. If the first such call results in an
 125.138 -     * <code>IOException</code>, that exception is returned from the call to
 125.139 -     * the <code>read(b,</code> <code>off,</code> <code>len)</code> method.  If
 125.140 -     * any subsequent call to <code>read()</code> results in a
 125.141 -     * <code>IOException</code>, the exception is caught and treated as if it
 125.142 -     * were end of file; the bytes read up to that point are stored into
 125.143 -     * <code>b</code> and the number of bytes read before the exception
 125.144 -     * occurred is returned. The default implementation of this method blocks
 125.145 -     * until the requested amount of input data <code>len</code> has been read,
 125.146 -     * end of file is detected, or an exception is thrown. Subclasses are encouraged
 125.147 -     * to provide a more efficient implementation of this method.
 125.148 -     *
 125.149 -     * @param      b     the buffer into which the data is read.
 125.150 -     * @param      off   the start offset in array <code>b</code>
 125.151 -     *                   at which the data is written.
 125.152 -     * @param      len   the maximum number of bytes to read.
 125.153 -     * @return     the total number of bytes read into the buffer, or
 125.154 -     *             <code>-1</code> if there is no more data because the end of
 125.155 -     *             the stream has been reached.
 125.156 -     * @exception  IOException If the first byte cannot be read for any reason
 125.157 -     * other than end of file, or if the input stream has been closed, or if
 125.158 -     * some other I/O error occurs.
 125.159 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 125.160 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 125.161 -     * <code>len</code> is negative, or <code>len</code> is greater than
 125.162 -     * <code>b.length - off</code>
 125.163 -     * @see        java.io.InputStream#read()
 125.164 -     */
 125.165 -    public int read(byte b[], int off, int len) throws IOException {
 125.166 -        if (b == null) {
 125.167 -            throw new NullPointerException();
 125.168 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 125.169 -            throw new IndexOutOfBoundsException();
 125.170 -        } else if (len == 0) {
 125.171 -            return 0;
 125.172 -        }
 125.173 -
 125.174 -        int c = read();
 125.175 -        if (c == -1) {
 125.176 -            return -1;
 125.177 -        }
 125.178 -        b[off] = (byte)c;
 125.179 -
 125.180 -        int i = 1;
 125.181 -        try {
 125.182 -            for (; i < len ; i++) {
 125.183 -                c = read();
 125.184 -                if (c == -1) {
 125.185 -                    break;
 125.186 -                }
 125.187 -                b[off + i] = (byte)c;
 125.188 -            }
 125.189 -        } catch (IOException ee) {
 125.190 -        }
 125.191 -        return i;
 125.192 -    }
 125.193 -
 125.194 -    /**
 125.195 -     * Skips over and discards <code>n</code> bytes of data from this input
 125.196 -     * stream. The <code>skip</code> method may, for a variety of reasons, end
 125.197 -     * up skipping over some smaller number of bytes, possibly <code>0</code>.
 125.198 -     * This may result from any of a number of conditions; reaching end of file
 125.199 -     * before <code>n</code> bytes have been skipped is only one possibility.
 125.200 -     * The actual number of bytes skipped is returned.  If <code>n</code> is
 125.201 -     * negative, no bytes are skipped.
 125.202 -     *
 125.203 -     * <p> The <code>skip</code> method of this class creates a
 125.204 -     * byte array and then repeatedly reads into it until <code>n</code> bytes
 125.205 -     * have been read or the end of the stream has been reached. Subclasses are
 125.206 -     * encouraged to provide a more efficient implementation of this method.
 125.207 -     * For instance, the implementation may depend on the ability to seek.
 125.208 -     *
 125.209 -     * @param      n   the number of bytes to be skipped.
 125.210 -     * @return     the actual number of bytes skipped.
 125.211 -     * @exception  IOException  if the stream does not support seek,
 125.212 -     *                          or if some other I/O error occurs.
 125.213 -     */
 125.214 -    public long skip(long n) throws IOException {
 125.215 -
 125.216 -        long remaining = n;
 125.217 -        int nr;
 125.218 -        if (skipBuffer == null)
 125.219 -            skipBuffer = new byte[SKIP_BUFFER_SIZE];
 125.220 -
 125.221 -        byte[] localSkipBuffer = skipBuffer;
 125.222 -
 125.223 -        if (n <= 0) {
 125.224 -            return 0;
 125.225 -        }
 125.226 -
 125.227 -        while (remaining > 0) {
 125.228 -            nr = read(localSkipBuffer, 0,
 125.229 -                      (int) Math.min(SKIP_BUFFER_SIZE, remaining));
 125.230 -            if (nr < 0) {
 125.231 -                break;
 125.232 -            }
 125.233 -            remaining -= nr;
 125.234 -        }
 125.235 -
 125.236 -        return n - remaining;
 125.237 -    }
 125.238 -
 125.239 -    /**
 125.240 -     * Returns an estimate of the number of bytes that can be read (or
 125.241 -     * skipped over) from this input stream without blocking by the next
 125.242 -     * invocation of a method for this input stream. The next invocation
 125.243 -     * might be the same thread or another thread.  A single read or skip of this
 125.244 -     * many bytes will not block, but may read or skip fewer bytes.
 125.245 -     *
 125.246 -     * <p> Note that while some implementations of {@code InputStream} will return
 125.247 -     * the total number of bytes in the stream, many will not.  It is
 125.248 -     * never correct to use the return value of this method to allocate
 125.249 -     * a buffer intended to hold all data in this stream.
 125.250 -     *
 125.251 -     * <p> A subclass' implementation of this method may choose to throw an
 125.252 -     * {@link IOException} if this input stream has been closed by
 125.253 -     * invoking the {@link #close()} method.
 125.254 -     *
 125.255 -     * <p> The {@code available} method for class {@code InputStream} always
 125.256 -     * returns {@code 0}.
 125.257 -     *
 125.258 -     * <p> This method should be overridden by subclasses.
 125.259 -     *
 125.260 -     * @return     an estimate of the number of bytes that can be read (or skipped
 125.261 -     *             over) from this input stream without blocking or {@code 0} when
 125.262 -     *             it reaches the end of the input stream.
 125.263 -     * @exception  IOException if an I/O error occurs.
 125.264 -     */
 125.265 -    public int available() throws IOException {
 125.266 -        return 0;
 125.267 -    }
 125.268 -
 125.269 -    /**
 125.270 -     * Closes this input stream and releases any system resources associated
 125.271 -     * with the stream.
 125.272 -     *
 125.273 -     * <p> The <code>close</code> method of <code>InputStream</code> does
 125.274 -     * nothing.
 125.275 -     *
 125.276 -     * @exception  IOException  if an I/O error occurs.
 125.277 -     */
 125.278 -    public void close() throws IOException {}
 125.279 -
 125.280 -    /**
 125.281 -     * Marks the current position in this input stream. A subsequent call to
 125.282 -     * the <code>reset</code> method repositions this stream at the last marked
 125.283 -     * position so that subsequent reads re-read the same bytes.
 125.284 -     *
 125.285 -     * <p> The <code>readlimit</code> arguments tells this input stream to
 125.286 -     * allow that many bytes to be read before the mark position gets
 125.287 -     * invalidated.
 125.288 -     *
 125.289 -     * <p> The general contract of <code>mark</code> is that, if the method
 125.290 -     * <code>markSupported</code> returns <code>true</code>, the stream somehow
 125.291 -     * remembers all the bytes read after the call to <code>mark</code> and
 125.292 -     * stands ready to supply those same bytes again if and whenever the method
 125.293 -     * <code>reset</code> is called.  However, the stream is not required to
 125.294 -     * remember any data at all if more than <code>readlimit</code> bytes are
 125.295 -     * read from the stream before <code>reset</code> is called.
 125.296 -     *
 125.297 -     * <p> Marking a closed stream should not have any effect on the stream.
 125.298 -     *
 125.299 -     * <p> The <code>mark</code> method of <code>InputStream</code> does
 125.300 -     * nothing.
 125.301 -     *
 125.302 -     * @param   readlimit   the maximum limit of bytes that can be read before
 125.303 -     *                      the mark position becomes invalid.
 125.304 -     * @see     java.io.InputStream#reset()
 125.305 -     */
 125.306 -    public synchronized void mark(int readlimit) {}
 125.307 -
 125.308 -    /**
 125.309 -     * Repositions this stream to the position at the time the
 125.310 -     * <code>mark</code> method was last called on this input stream.
 125.311 -     *
 125.312 -     * <p> The general contract of <code>reset</code> is:
 125.313 -     *
 125.314 -     * <p><ul>
 125.315 -     *
 125.316 -     * <li> If the method <code>markSupported</code> returns
 125.317 -     * <code>true</code>, then:
 125.318 -     *
 125.319 -     *     <ul><li> If the method <code>mark</code> has not been called since
 125.320 -     *     the stream was created, or the number of bytes read from the stream
 125.321 -     *     since <code>mark</code> was last called is larger than the argument
 125.322 -     *     to <code>mark</code> at that last call, then an
 125.323 -     *     <code>IOException</code> might be thrown.
 125.324 -     *
 125.325 -     *     <li> If such an <code>IOException</code> is not thrown, then the
 125.326 -     *     stream is reset to a state such that all the bytes read since the
 125.327 -     *     most recent call to <code>mark</code> (or since the start of the
 125.328 -     *     file, if <code>mark</code> has not been called) will be resupplied
 125.329 -     *     to subsequent callers of the <code>read</code> method, followed by
 125.330 -     *     any bytes that otherwise would have been the next input data as of
 125.331 -     *     the time of the call to <code>reset</code>. </ul>
 125.332 -     *
 125.333 -     * <li> If the method <code>markSupported</code> returns
 125.334 -     * <code>false</code>, then:
 125.335 -     *
 125.336 -     *     <ul><li> The call to <code>reset</code> may throw an
 125.337 -     *     <code>IOException</code>.
 125.338 -     *
 125.339 -     *     <li> If an <code>IOException</code> is not thrown, then the stream
 125.340 -     *     is reset to a fixed state that depends on the particular type of the
 125.341 -     *     input stream and how it was created. The bytes that will be supplied
 125.342 -     *     to subsequent callers of the <code>read</code> method depend on the
 125.343 -     *     particular type of the input stream. </ul></ul>
 125.344 -     *
 125.345 -     * <p>The method <code>reset</code> for class <code>InputStream</code>
 125.346 -     * does nothing except throw an <code>IOException</code>.
 125.347 -     *
 125.348 -     * @exception  IOException  if this stream has not been marked or if the
 125.349 -     *               mark has been invalidated.
 125.350 -     * @see     java.io.InputStream#mark(int)
 125.351 -     * @see     java.io.IOException
 125.352 -     */
 125.353 -    public synchronized void reset() throws IOException {
 125.354 -        throw new IOException("mark/reset not supported");
 125.355 -    }
 125.356 -
 125.357 -    /**
 125.358 -     * Tests if this input stream supports the <code>mark</code> and
 125.359 -     * <code>reset</code> methods. Whether or not <code>mark</code> and
 125.360 -     * <code>reset</code> are supported is an invariant property of a
 125.361 -     * particular input stream instance. The <code>markSupported</code> method
 125.362 -     * of <code>InputStream</code> returns <code>false</code>.
 125.363 -     *
 125.364 -     * @return  <code>true</code> if this stream instance supports the mark
 125.365 -     *          and reset methods; <code>false</code> otherwise.
 125.366 -     * @see     java.io.InputStream#mark(int)
 125.367 -     * @see     java.io.InputStream#reset()
 125.368 -     */
 125.369 -    public boolean markSupported() {
 125.370 -        return false;
 125.371 -    }
 125.372 -
 125.373 -}
   126.1 --- a/emul/mini/src/main/java/java/io/PushbackInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   126.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   126.3 @@ -1,385 +0,0 @@
   126.4 -/*
   126.5 - * Copyright (c) 1994, 2011, 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.io;
  126.30 -
  126.31 -import org.apidesign.bck2brwsr.emul.lang.System;
  126.32 -
  126.33 -/**
  126.34 - * A <code>PushbackInputStream</code> adds
  126.35 - * functionality to another input stream, namely
  126.36 - * the  ability to "push back" or "unread"
  126.37 - * one byte. This is useful in situations where
  126.38 - * it is  convenient for a fragment of code
  126.39 - * to read an indefinite number of data bytes
  126.40 - * that  are delimited by a particular byte
  126.41 - * value; after reading the terminating byte,
  126.42 - * the  code fragment can "unread" it, so that
  126.43 - * the next read operation on the input stream
  126.44 - * will reread the byte that was pushed back.
  126.45 - * For example, bytes representing the  characters
  126.46 - * constituting an identifier might be terminated
  126.47 - * by a byte representing an  operator character;
  126.48 - * a method whose job is to read just an identifier
  126.49 - * can read until it  sees the operator and
  126.50 - * then push the operator back to be re-read.
  126.51 - *
  126.52 - * @author  David Connelly
  126.53 - * @author  Jonathan Payne
  126.54 - * @since   JDK1.0
  126.55 - */
  126.56 -public
  126.57 -class PushbackInputStream extends FilterInputStream {
  126.58 -    /**
  126.59 -     * The pushback buffer.
  126.60 -     * @since   JDK1.1
  126.61 -     */
  126.62 -    protected byte[] buf;
  126.63 -
  126.64 -    /**
  126.65 -     * The position within the pushback buffer from which the next byte will
  126.66 -     * be read.  When the buffer is empty, <code>pos</code> is equal to
  126.67 -     * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
  126.68 -     * equal to zero.
  126.69 -     *
  126.70 -     * @since   JDK1.1
  126.71 -     */
  126.72 -    protected int pos;
  126.73 -
  126.74 -    /**
  126.75 -     * Check to make sure that this stream has not been closed
  126.76 -     */
  126.77 -    private void ensureOpen() throws IOException {
  126.78 -        if (in == null)
  126.79 -            throw new IOException("Stream closed");
  126.80 -    }
  126.81 -
  126.82 -    /**
  126.83 -     * Creates a <code>PushbackInputStream</code>
  126.84 -     * with a pushback buffer of the specified <code>size</code>,
  126.85 -     * and saves its  argument, the input stream
  126.86 -     * <code>in</code>, for later use. Initially,
  126.87 -     * there is no pushed-back byte  (the field
  126.88 -     * <code>pushBack</code> is initialized to
  126.89 -     * <code>-1</code>).
  126.90 -     *
  126.91 -     * @param  in    the input stream from which bytes will be read.
  126.92 -     * @param  size  the size of the pushback buffer.
  126.93 -     * @exception IllegalArgumentException if size is <= 0
  126.94 -     * @since  JDK1.1
  126.95 -     */
  126.96 -    public PushbackInputStream(InputStream in, int size) {
  126.97 -        super(in);
  126.98 -        if (size <= 0) {
  126.99 -            throw new IllegalArgumentException("size <= 0");
 126.100 -        }
 126.101 -        this.buf = new byte[size];
 126.102 -        this.pos = size;
 126.103 -    }
 126.104 -
 126.105 -    /**
 126.106 -     * Creates a <code>PushbackInputStream</code>
 126.107 -     * and saves its  argument, the input stream
 126.108 -     * <code>in</code>, for later use. Initially,
 126.109 -     * there is no pushed-back byte  (the field
 126.110 -     * <code>pushBack</code> is initialized to
 126.111 -     * <code>-1</code>).
 126.112 -     *
 126.113 -     * @param   in   the input stream from which bytes will be read.
 126.114 -     */
 126.115 -    public PushbackInputStream(InputStream in) {
 126.116 -        this(in, 1);
 126.117 -    }
 126.118 -
 126.119 -    /**
 126.120 -     * Reads the next byte of data from this input stream. The value
 126.121 -     * byte is returned as an <code>int</code> in the range
 126.122 -     * <code>0</code> to <code>255</code>. If no byte is available
 126.123 -     * because the end of the stream has been reached, the value
 126.124 -     * <code>-1</code> is returned. This method blocks until input data
 126.125 -     * is available, the end of the stream is detected, or an exception
 126.126 -     * is thrown.
 126.127 -     *
 126.128 -     * <p> This method returns the most recently pushed-back byte, if there is
 126.129 -     * one, and otherwise calls the <code>read</code> method of its underlying
 126.130 -     * input stream and returns whatever value that method returns.
 126.131 -     *
 126.132 -     * @return     the next byte of data, or <code>-1</code> if the end of the
 126.133 -     *             stream has been reached.
 126.134 -     * @exception  IOException  if this input stream has been closed by
 126.135 -     *             invoking its {@link #close()} method,
 126.136 -     *             or an I/O error occurs.
 126.137 -     * @see        java.io.InputStream#read()
 126.138 -     */
 126.139 -    public int read() throws IOException {
 126.140 -        ensureOpen();
 126.141 -        if (pos < buf.length) {
 126.142 -            return buf[pos++] & 0xff;
 126.143 -        }
 126.144 -        return super.read();
 126.145 -    }
 126.146 -
 126.147 -    /**
 126.148 -     * Reads up to <code>len</code> bytes of data from this input stream into
 126.149 -     * an array of bytes.  This method first reads any pushed-back bytes; after
 126.150 -     * that, if fewer than <code>len</code> bytes have been read then it
 126.151 -     * reads from the underlying input stream. If <code>len</code> is not zero, the method
 126.152 -     * blocks until at least 1 byte of input is available; otherwise, no
 126.153 -     * bytes are read and <code>0</code> is returned.
 126.154 -     *
 126.155 -     * @param      b     the buffer into which the data is read.
 126.156 -     * @param      off   the start offset in the destination array <code>b</code>
 126.157 -     * @param      len   the maximum number of bytes read.
 126.158 -     * @return     the total number of bytes read into the buffer, or
 126.159 -     *             <code>-1</code> if there is no more data because the end of
 126.160 -     *             the stream has been reached.
 126.161 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 126.162 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 126.163 -     * <code>len</code> is negative, or <code>len</code> is greater than
 126.164 -     * <code>b.length - off</code>
 126.165 -     * @exception  IOException  if this input stream has been closed by
 126.166 -     *             invoking its {@link #close()} method,
 126.167 -     *             or an I/O error occurs.
 126.168 -     * @see        java.io.InputStream#read(byte[], int, int)
 126.169 -     */
 126.170 -    public int read(byte[] b, int off, int len) throws IOException {
 126.171 -        ensureOpen();
 126.172 -        if (b == null) {
 126.173 -            throw new NullPointerException();
 126.174 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 126.175 -            throw new IndexOutOfBoundsException();
 126.176 -        } else if (len == 0) {
 126.177 -            return 0;
 126.178 -        }
 126.179 -
 126.180 -        int avail = buf.length - pos;
 126.181 -        if (avail > 0) {
 126.182 -            if (len < avail) {
 126.183 -                avail = len;
 126.184 -            }
 126.185 -            System.arraycopy(buf, pos, b, off, avail);
 126.186 -            pos += avail;
 126.187 -            off += avail;
 126.188 -            len -= avail;
 126.189 -        }
 126.190 -        if (len > 0) {
 126.191 -            len = super.read(b, off, len);
 126.192 -            if (len == -1) {
 126.193 -                return avail == 0 ? -1 : avail;
 126.194 -            }
 126.195 -            return avail + len;
 126.196 -        }
 126.197 -        return avail;
 126.198 -    }
 126.199 -
 126.200 -    /**
 126.201 -     * Pushes back a byte by copying it to the front of the pushback buffer.
 126.202 -     * After this method returns, the next byte to be read will have the value
 126.203 -     * <code>(byte)b</code>.
 126.204 -     *
 126.205 -     * @param      b   the <code>int</code> value whose low-order
 126.206 -     *                  byte is to be pushed back.
 126.207 -     * @exception IOException If there is not enough room in the pushback
 126.208 -     *            buffer for the byte, or this input stream has been closed by
 126.209 -     *            invoking its {@link #close()} method.
 126.210 -     */
 126.211 -    public void unread(int b) throws IOException {
 126.212 -        ensureOpen();
 126.213 -        if (pos == 0) {
 126.214 -            throw new IOException("Push back buffer is full");
 126.215 -        }
 126.216 -        buf[--pos] = (byte)b;
 126.217 -    }
 126.218 -
 126.219 -    /**
 126.220 -     * Pushes back a portion of an array of bytes by copying it to the front
 126.221 -     * of the pushback buffer.  After this method returns, the next byte to be
 126.222 -     * read will have the value <code>b[off]</code>, the byte after that will
 126.223 -     * have the value <code>b[off+1]</code>, and so forth.
 126.224 -     *
 126.225 -     * @param b the byte array to push back.
 126.226 -     * @param off the start offset of the data.
 126.227 -     * @param len the number of bytes to push back.
 126.228 -     * @exception IOException If there is not enough room in the pushback
 126.229 -     *            buffer for the specified number of bytes,
 126.230 -     *            or this input stream has been closed by
 126.231 -     *            invoking its {@link #close()} method.
 126.232 -     * @since     JDK1.1
 126.233 -     */
 126.234 -    public void unread(byte[] b, int off, int len) throws IOException {
 126.235 -        ensureOpen();
 126.236 -        if (len > pos) {
 126.237 -            throw new IOException("Push back buffer is full");
 126.238 -        }
 126.239 -        pos -= len;
 126.240 -        System.arraycopy(b, off, buf, pos, len);
 126.241 -    }
 126.242 -
 126.243 -    /**
 126.244 -     * Pushes back an array of bytes by copying it to the front of the
 126.245 -     * pushback buffer.  After this method returns, the next byte to be read
 126.246 -     * will have the value <code>b[0]</code>, the byte after that will have the
 126.247 -     * value <code>b[1]</code>, and so forth.
 126.248 -     *
 126.249 -     * @param b the byte array to push back
 126.250 -     * @exception IOException If there is not enough room in the pushback
 126.251 -     *            buffer for the specified number of bytes,
 126.252 -     *            or this input stream has been closed by
 126.253 -     *            invoking its {@link #close()} method.
 126.254 -     * @since     JDK1.1
 126.255 -     */
 126.256 -    public void unread(byte[] b) throws IOException {
 126.257 -        unread(b, 0, b.length);
 126.258 -    }
 126.259 -
 126.260 -    /**
 126.261 -     * Returns an estimate of the number of bytes that can be read (or
 126.262 -     * skipped over) from this input stream without blocking by the next
 126.263 -     * invocation of a method for this input stream. The next invocation might be
 126.264 -     * the same thread or another thread.  A single read or skip of this
 126.265 -     * many bytes will not block, but may read or skip fewer bytes.
 126.266 -     *
 126.267 -     * <p> The method returns the sum of the number of bytes that have been
 126.268 -     * pushed back and the value returned by {@link
 126.269 -     * java.io.FilterInputStream#available available}.
 126.270 -     *
 126.271 -     * @return     the number of bytes that can be read (or skipped over) from
 126.272 -     *             the input stream without blocking.
 126.273 -     * @exception  IOException  if this input stream has been closed by
 126.274 -     *             invoking its {@link #close()} method,
 126.275 -     *             or an I/O error occurs.
 126.276 -     * @see        java.io.FilterInputStream#in
 126.277 -     * @see        java.io.InputStream#available()
 126.278 -     */
 126.279 -    public int available() throws IOException {
 126.280 -        ensureOpen();
 126.281 -        int n = buf.length - pos;
 126.282 -        int avail = super.available();
 126.283 -        return n > (Integer.MAX_VALUE - avail)
 126.284 -                    ? Integer.MAX_VALUE
 126.285 -                    : n + avail;
 126.286 -    }
 126.287 -
 126.288 -    /**
 126.289 -     * Skips over and discards <code>n</code> bytes of data from this
 126.290 -     * input stream. The <code>skip</code> method may, for a variety of
 126.291 -     * reasons, end up skipping over some smaller number of bytes,
 126.292 -     * possibly zero.  If <code>n</code> is negative, no bytes are skipped.
 126.293 -     *
 126.294 -     * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
 126.295 -     * first skips over the bytes in the pushback buffer, if any.  It then
 126.296 -     * calls the <code>skip</code> method of the underlying input stream if
 126.297 -     * more bytes need to be skipped.  The actual number of bytes skipped
 126.298 -     * is returned.
 126.299 -     *
 126.300 -     * @param      n  {@inheritDoc}
 126.301 -     * @return     {@inheritDoc}
 126.302 -     * @exception  IOException  if the stream does not support seek,
 126.303 -     *            or the stream has been closed by
 126.304 -     *            invoking its {@link #close()} method,
 126.305 -     *            or an I/O error occurs.
 126.306 -     * @see        java.io.FilterInputStream#in
 126.307 -     * @see        java.io.InputStream#skip(long n)
 126.308 -     * @since      1.2
 126.309 -     */
 126.310 -    public long skip(long n) throws IOException {
 126.311 -        ensureOpen();
 126.312 -        if (n <= 0) {
 126.313 -            return 0;
 126.314 -        }
 126.315 -
 126.316 -        long pskip = buf.length - pos;
 126.317 -        if (pskip > 0) {
 126.318 -            if (n < pskip) {
 126.319 -                pskip = n;
 126.320 -            }
 126.321 -            pos += pskip;
 126.322 -            n -= pskip;
 126.323 -        }
 126.324 -        if (n > 0) {
 126.325 -            pskip += super.skip(n);
 126.326 -        }
 126.327 -        return pskip;
 126.328 -    }
 126.329 -
 126.330 -    /**
 126.331 -     * Tests if this input stream supports the <code>mark</code> and
 126.332 -     * <code>reset</code> methods, which it does not.
 126.333 -     *
 126.334 -     * @return   <code>false</code>, since this class does not support the
 126.335 -     *           <code>mark</code> and <code>reset</code> methods.
 126.336 -     * @see     java.io.InputStream#mark(int)
 126.337 -     * @see     java.io.InputStream#reset()
 126.338 -     */
 126.339 -    public boolean markSupported() {
 126.340 -        return false;
 126.341 -    }
 126.342 -
 126.343 -    /**
 126.344 -     * Marks the current position in this input stream.
 126.345 -     *
 126.346 -     * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
 126.347 -     * does nothing.
 126.348 -     *
 126.349 -     * @param   readlimit   the maximum limit of bytes that can be read before
 126.350 -     *                      the mark position becomes invalid.
 126.351 -     * @see     java.io.InputStream#reset()
 126.352 -     */
 126.353 -    public synchronized void mark(int readlimit) {
 126.354 -    }
 126.355 -
 126.356 -    /**
 126.357 -     * Repositions this stream to the position at the time the
 126.358 -     * <code>mark</code> method was last called on this input stream.
 126.359 -     *
 126.360 -     * <p> The method <code>reset</code> for class
 126.361 -     * <code>PushbackInputStream</code> does nothing except throw an
 126.362 -     * <code>IOException</code>.
 126.363 -     *
 126.364 -     * @exception  IOException  if this method is invoked.
 126.365 -     * @see     java.io.InputStream#mark(int)
 126.366 -     * @see     java.io.IOException
 126.367 -     */
 126.368 -    public synchronized void reset() throws IOException {
 126.369 -        throw new IOException("mark/reset not supported");
 126.370 -    }
 126.371 -
 126.372 -    /**
 126.373 -     * Closes this input stream and releases any system resources
 126.374 -     * associated with the stream.
 126.375 -     * Once the stream has been closed, further read(), unread(),
 126.376 -     * available(), reset(), or skip() invocations will throw an IOException.
 126.377 -     * Closing a previously closed stream has no effect.
 126.378 -     *
 126.379 -     * @exception  IOException  if an I/O error occurs.
 126.380 -     */
 126.381 -    public synchronized void close() throws IOException {
 126.382 -        if (in == null)
 126.383 -            return;
 126.384 -        in.close();
 126.385 -        in = null;
 126.386 -        buf = null;
 126.387 -    }
 126.388 -}
   127.1 --- a/emul/mini/src/main/java/java/io/Serializable.java	Mon Feb 25 19:00:08 2013 +0100
   127.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   127.3 @@ -1,170 +0,0 @@
   127.4 -/*
   127.5 - * Copyright (c) 1996, 2005, 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.io;
  127.30 -
  127.31 -/**
  127.32 - * Serializability of a class is enabled by the class implementing the
  127.33 - * java.io.Serializable interface. Classes that do not implement this
  127.34 - * interface will not have any of their state serialized or
  127.35 - * deserialized.  All subtypes of a serializable class are themselves
  127.36 - * serializable.  The serialization interface has no methods or fields
  127.37 - * and serves only to identify the semantics of being serializable. <p>
  127.38 - *
  127.39 - * To allow subtypes of non-serializable classes to be serialized, the
  127.40 - * subtype may assume responsibility for saving and restoring the
  127.41 - * state of the supertype's public, protected, and (if accessible)
  127.42 - * package fields.  The subtype may assume this responsibility only if
  127.43 - * the class it extends has an accessible no-arg constructor to
  127.44 - * initialize the class's state.  It is an error to declare a class
  127.45 - * Serializable if this is not the case.  The error will be detected at
  127.46 - * runtime. <p>
  127.47 - *
  127.48 - * During deserialization, the fields of non-serializable classes will
  127.49 - * be initialized using the public or protected no-arg constructor of
  127.50 - * the class.  A no-arg constructor must be accessible to the subclass
  127.51 - * that is serializable.  The fields of serializable subclasses will
  127.52 - * be restored from the stream. <p>
  127.53 - *
  127.54 - * When traversing a graph, an object may be encountered that does not
  127.55 - * support the Serializable interface. In this case the
  127.56 - * NotSerializableException will be thrown and will identify the class
  127.57 - * of the non-serializable object. <p>
  127.58 - *
  127.59 - * Classes that require special handling during the serialization and
  127.60 - * deserialization process must implement special methods with these exact
  127.61 - * signatures: <p>
  127.62 - *
  127.63 - * <PRE>
  127.64 - * private void writeObject(java.io.ObjectOutputStream out)
  127.65 - *     throws IOException
  127.66 - * private void readObject(java.io.ObjectInputStream in)
  127.67 - *     throws IOException, ClassNotFoundException;
  127.68 - * private void readObjectNoData()
  127.69 - *     throws ObjectStreamException;
  127.70 - * </PRE>
  127.71 - *
  127.72 - * <p>The writeObject method is responsible for writing the state of the
  127.73 - * object for its particular class so that the corresponding
  127.74 - * readObject method can restore it.  The default mechanism for saving
  127.75 - * the Object's fields can be invoked by calling
  127.76 - * out.defaultWriteObject. The method does not need to concern
  127.77 - * itself with the state belonging to its superclasses or subclasses.
  127.78 - * State is saved by writing the individual fields to the
  127.79 - * ObjectOutputStream using the writeObject method or by using the
  127.80 - * methods for primitive data types supported by DataOutput.
  127.81 - *
  127.82 - * <p>The readObject method is responsible for reading from the stream and
  127.83 - * restoring the classes fields. It may call in.defaultReadObject to invoke
  127.84 - * the default mechanism for restoring the object's non-static and
  127.85 - * non-transient fields.  The defaultReadObject method uses information in
  127.86 - * the stream to assign the fields of the object saved in the stream with the
  127.87 - * correspondingly named fields in the current object.  This handles the case
  127.88 - * when the class has evolved to add new fields. The method does not need to
  127.89 - * concern itself with the state belonging to its superclasses or subclasses.
  127.90 - * State is saved by writing the individual fields to the
  127.91 - * ObjectOutputStream using the writeObject method or by using the
  127.92 - * methods for primitive data types supported by DataOutput.
  127.93 - *
  127.94 - * <p>The readObjectNoData method is responsible for initializing the state of
  127.95 - * the object for its particular class in the event that the serialization
  127.96 - * stream does not list the given class as a superclass of the object being
  127.97 - * deserialized.  This may occur in cases where the receiving party uses a
  127.98 - * different version of the deserialized instance's class than the sending
  127.99 - * party, and the receiver's version extends classes that are not extended by
 127.100 - * the sender's version.  This may also occur if the serialization stream has
 127.101 - * been tampered; hence, readObjectNoData is useful for initializing
 127.102 - * deserialized objects properly despite a "hostile" or incomplete source
 127.103 - * stream.
 127.104 - *
 127.105 - * <p>Serializable classes that need to designate an alternative object to be
 127.106 - * used when writing an object to the stream should implement this
 127.107 - * special method with the exact signature: <p>
 127.108 - *
 127.109 - * <PRE>
 127.110 - * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
 127.111 - * </PRE><p>
 127.112 - *
 127.113 - * This writeReplace method is invoked by serialization if the method
 127.114 - * exists and it would be accessible from a method defined within the
 127.115 - * class of the object being serialized. Thus, the method can have private,
 127.116 - * protected and package-private access. Subclass access to this method
 127.117 - * follows java accessibility rules. <p>
 127.118 - *
 127.119 - * Classes that need to designate a replacement when an instance of it
 127.120 - * is read from the stream should implement this special method with the
 127.121 - * exact signature.<p>
 127.122 - *
 127.123 - * <PRE>
 127.124 - * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
 127.125 - * </PRE><p>
 127.126 - *
 127.127 - * This readResolve method follows the same invocation rules and
 127.128 - * accessibility rules as writeReplace.<p>
 127.129 - *
 127.130 - * The serialization runtime associates with each serializable class a version
 127.131 - * number, called a serialVersionUID, which is used during deserialization to
 127.132 - * verify that the sender and receiver of a serialized object have loaded
 127.133 - * classes for that object that are compatible with respect to serialization.
 127.134 - * If the receiver has loaded a class for the object that has a different
 127.135 - * serialVersionUID than that of the corresponding sender's class, then
 127.136 - * deserialization will result in an {@link InvalidClassException}.  A
 127.137 - * serializable class can declare its own serialVersionUID explicitly by
 127.138 - * declaring a field named <code>"serialVersionUID"</code> that must be static,
 127.139 - * final, and of type <code>long</code>:<p>
 127.140 - *
 127.141 - * <PRE>
 127.142 - * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
 127.143 - * </PRE>
 127.144 - *
 127.145 - * If a serializable class does not explicitly declare a serialVersionUID, then
 127.146 - * the serialization runtime will calculate a default serialVersionUID value
 127.147 - * for that class based on various aspects of the class, as described in the
 127.148 - * Java(TM) Object Serialization Specification.  However, it is <em>strongly
 127.149 - * recommended</em> that all serializable classes explicitly declare
 127.150 - * serialVersionUID values, since the default serialVersionUID computation is
 127.151 - * highly sensitive to class details that may vary depending on compiler
 127.152 - * implementations, and can thus result in unexpected
 127.153 - * <code>InvalidClassException</code>s during deserialization.  Therefore, to
 127.154 - * guarantee a consistent serialVersionUID value across different java compiler
 127.155 - * implementations, a serializable class must declare an explicit
 127.156 - * serialVersionUID value.  It is also strongly advised that explicit
 127.157 - * serialVersionUID declarations use the <code>private</code> modifier where
 127.158 - * possible, since such declarations apply only to the immediately declaring
 127.159 - * class--serialVersionUID fields are not useful as inherited members. Array
 127.160 - * classes cannot declare an explicit serialVersionUID, so they always have
 127.161 - * the default computed value, but the requirement for matching
 127.162 - * serialVersionUID values is waived for array classes.
 127.163 - *
 127.164 - * @author  unascribed
 127.165 - * @see java.io.ObjectOutputStream
 127.166 - * @see java.io.ObjectInputStream
 127.167 - * @see java.io.ObjectOutput
 127.168 - * @see java.io.ObjectInput
 127.169 - * @see java.io.Externalizable
 127.170 - * @since   JDK1.1
 127.171 - */
 127.172 -public interface Serializable {
 127.173 -}
   128.1 --- a/emul/mini/src/main/java/java/io/UTFDataFormatException.java	Mon Feb 25 19:00:08 2013 +0100
   128.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   128.3 @@ -1,69 +0,0 @@
   128.4 -/*
   128.5 - * Copyright (c) 1995, 2008, 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.io;
  128.30 -
  128.31 -/**
  128.32 - * Signals that a malformed string in
  128.33 - * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  128.34 - * format has been read in a data
  128.35 - * input stream or by any class that implements the data input
  128.36 - * interface.
  128.37 - * See the
  128.38 - * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
  128.39 - * class description for the format in
  128.40 - * which modified UTF-8 strings are read and written.
  128.41 - *
  128.42 - * @author  Frank Yellin
  128.43 - * @see     java.io.DataInput
  128.44 - * @see     java.io.DataInputStream#readUTF(java.io.DataInput)
  128.45 - * @see     java.io.IOException
  128.46 - * @since   JDK1.0
  128.47 - */
  128.48 -public
  128.49 -class UTFDataFormatException extends IOException {
  128.50 -    private static final long serialVersionUID = 420743449228280612L;
  128.51 -
  128.52 -    /**
  128.53 -     * Constructs a <code>UTFDataFormatException</code> with
  128.54 -     * <code>null</code> as its error detail message.
  128.55 -     */
  128.56 -    public UTFDataFormatException() {
  128.57 -        super();
  128.58 -    }
  128.59 -
  128.60 -    /**
  128.61 -     * Constructs a <code>UTFDataFormatException</code> with the
  128.62 -     * specified detail message. The string <code>s</code> can be
  128.63 -     * retrieved later by the
  128.64 -     * <code>{@link java.lang.Throwable#getMessage}</code>
  128.65 -     * method of class <code>java.lang.Throwable</code>.
  128.66 -     *
  128.67 -     * @param   s   the detail message.
  128.68 -     */
  128.69 -    public UTFDataFormatException(String s) {
  128.70 -        super(s);
  128.71 -    }
  128.72 -}
   129.1 --- a/emul/mini/src/main/java/java/io/UnsupportedEncodingException.java	Mon Feb 25 19:00:08 2013 +0100
   129.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   129.3 @@ -1,52 +0,0 @@
   129.4 -/*
   129.5 - * Copyright (c) 1996, 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 -package java.io;
  129.29 -
  129.30 -/**
  129.31 - * The Character Encoding is not supported.
  129.32 - *
  129.33 - * @author  Asmus Freytag
  129.34 - * @since   JDK1.1
  129.35 - */
  129.36 -public class UnsupportedEncodingException
  129.37 -    extends IOException
  129.38 -{
  129.39 -    private static final long serialVersionUID = -4274276298326136670L;
  129.40 -
  129.41 -    /**
  129.42 -     * Constructs an UnsupportedEncodingException without a detail message.
  129.43 -     */
  129.44 -    public UnsupportedEncodingException() {
  129.45 -        super();
  129.46 -    }
  129.47 -
  129.48 -    /**
  129.49 -     * Constructs an UnsupportedEncodingException with a detail message.
  129.50 -     * @param s Describes the reason for the exception.
  129.51 -     */
  129.52 -    public UnsupportedEncodingException(String s) {
  129.53 -        super(s);
  129.54 -    }
  129.55 -}
   130.1 --- a/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java	Mon Feb 25 19:00:08 2013 +0100
   130.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   130.3 @@ -1,1414 +0,0 @@
   130.4 -/*
   130.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   130.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   130.7 - *
   130.8 - * This code is free software; you can redistribute it and/or modify it
   130.9 - * under the terms of the GNU General Public License version 2 only, as
  130.10 - * published by the Free Software Foundation.  Oracle designates this
  130.11 - * particular file as subject to the "Classpath" exception as provided
  130.12 - * by Oracle in the LICENSE file that accompanied this code.
  130.13 - *
  130.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  130.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  130.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  130.17 - * version 2 for more details (a copy is included in the LICENSE file that
  130.18 - * accompanied this code).
  130.19 - *
  130.20 - * You should have received a copy of the GNU General Public License version
  130.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  130.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  130.23 - *
  130.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  130.25 - * or visit www.oracle.com if you need additional information or have any
  130.26 - * questions.
  130.27 - */
  130.28 -
  130.29 -package java.lang;
  130.30 -
  130.31 -import org.apidesign.bck2brwsr.emul.lang.System;
  130.32 -
  130.33 -/**
  130.34 - * A mutable sequence of characters.
  130.35 - * <p>
  130.36 - * Implements a modifiable string. At any point in time it contains some
  130.37 - * particular sequence of characters, but the length and content of the
  130.38 - * sequence can be changed through certain method calls.
  130.39 - *
  130.40 - * @author      Michael McCloskey
  130.41 - * @author      Martin Buchholz
  130.42 - * @author      Ulf Zibis
  130.43 - * @since       1.5
  130.44 - */
  130.45 -abstract class AbstractStringBuilder implements Appendable, CharSequence {
  130.46 -    /**
  130.47 -     * The value is used for character storage.
  130.48 -     */
  130.49 -    char[] value;
  130.50 -
  130.51 -    /**
  130.52 -     * The count is the number of characters used.
  130.53 -     */
  130.54 -    int count;
  130.55 -
  130.56 -    /**
  130.57 -     * This no-arg constructor is necessary for serialization of subclasses.
  130.58 -     */
  130.59 -    AbstractStringBuilder() {
  130.60 -    }
  130.61 -
  130.62 -    /**
  130.63 -     * Creates an AbstractStringBuilder of the specified capacity.
  130.64 -     */
  130.65 -    AbstractStringBuilder(int capacity) {
  130.66 -        value = new char[capacity];
  130.67 -    }
  130.68 -
  130.69 -    /**
  130.70 -     * Returns the length (character count).
  130.71 -     *
  130.72 -     * @return  the length of the sequence of characters currently
  130.73 -     *          represented by this object
  130.74 -     */
  130.75 -    public int length() {
  130.76 -        return count;
  130.77 -    }
  130.78 -
  130.79 -    /**
  130.80 -     * Returns the current capacity. The capacity is the amount of storage
  130.81 -     * available for newly inserted characters, beyond which an allocation
  130.82 -     * will occur.
  130.83 -     *
  130.84 -     * @return  the current capacity
  130.85 -     */
  130.86 -    public int capacity() {
  130.87 -        return value.length;
  130.88 -    }
  130.89 -
  130.90 -    /**
  130.91 -     * Ensures that the capacity is at least equal to the specified minimum.
  130.92 -     * If the current capacity is less than the argument, then a new internal
  130.93 -     * array is allocated with greater capacity. The new capacity is the
  130.94 -     * larger of:
  130.95 -     * <ul>
  130.96 -     * <li>The <code>minimumCapacity</code> argument.
  130.97 -     * <li>Twice the old capacity, plus <code>2</code>.
  130.98 -     * </ul>
  130.99 -     * If the <code>minimumCapacity</code> argument is nonpositive, this
 130.100 -     * method takes no action and simply returns.
 130.101 -     *
 130.102 -     * @param   minimumCapacity   the minimum desired capacity.
 130.103 -     */
 130.104 -    public void ensureCapacity(int minimumCapacity) {
 130.105 -        if (minimumCapacity > 0)
 130.106 -            ensureCapacityInternal(minimumCapacity);
 130.107 -    }
 130.108 -
 130.109 -    /**
 130.110 -     * This method has the same contract as ensureCapacity, but is
 130.111 -     * never synchronized.
 130.112 -     */
 130.113 -    private void ensureCapacityInternal(int minimumCapacity) {
 130.114 -        // overflow-conscious code
 130.115 -        if (minimumCapacity - value.length > 0)
 130.116 -            expandCapacity(minimumCapacity);
 130.117 -    }
 130.118 -
 130.119 -    /**
 130.120 -     * This implements the expansion semantics of ensureCapacity with no
 130.121 -     * size check or synchronization.
 130.122 -     */
 130.123 -    void expandCapacity(int minimumCapacity) {
 130.124 -        int newCapacity = value.length * 2 + 2;
 130.125 -        if (newCapacity - minimumCapacity < 0)
 130.126 -            newCapacity = minimumCapacity;
 130.127 -        if (newCapacity < 0) {
 130.128 -            if (minimumCapacity < 0) // overflow
 130.129 -                throw new OutOfMemoryError();
 130.130 -            newCapacity = Integer.MAX_VALUE;
 130.131 -        }
 130.132 -        value = copyOf(value, newCapacity);
 130.133 -    }
 130.134 -
 130.135 -    /**
 130.136 -     * Attempts to reduce storage used for the character sequence.
 130.137 -     * If the buffer is larger than necessary to hold its current sequence of
 130.138 -     * characters, then it may be resized to become more space efficient.
 130.139 -     * Calling this method may, but is not required to, affect the value
 130.140 -     * returned by a subsequent call to the {@link #capacity()} method.
 130.141 -     */
 130.142 -    public void trimToSize() {
 130.143 -        if (count < value.length) {
 130.144 -            value = copyOf(value, count);
 130.145 -        }
 130.146 -    }
 130.147 -
 130.148 -    /**
 130.149 -     * Sets the length of the character sequence.
 130.150 -     * The sequence is changed to a new character sequence
 130.151 -     * whose length is specified by the argument. For every nonnegative
 130.152 -     * index <i>k</i> less than <code>newLength</code>, the character at
 130.153 -     * index <i>k</i> in the new character sequence is the same as the
 130.154 -     * character at index <i>k</i> in the old sequence if <i>k</i> is less
 130.155 -     * than the length of the old character sequence; otherwise, it is the
 130.156 -     * null character <code>'&#92;u0000'</code>.
 130.157 -     *
 130.158 -     * In other words, if the <code>newLength</code> argument is less than
 130.159 -     * the current length, the length is changed to the specified length.
 130.160 -     * <p>
 130.161 -     * If the <code>newLength</code> argument is greater than or equal
 130.162 -     * to the current length, sufficient null characters
 130.163 -     * (<code>'&#92;u0000'</code>) are appended so that
 130.164 -     * length becomes the <code>newLength</code> argument.
 130.165 -     * <p>
 130.166 -     * The <code>newLength</code> argument must be greater than or equal
 130.167 -     * to <code>0</code>.
 130.168 -     *
 130.169 -     * @param      newLength   the new length
 130.170 -     * @throws     IndexOutOfBoundsException  if the
 130.171 -     *               <code>newLength</code> argument is negative.
 130.172 -     */
 130.173 -    public void setLength(int newLength) {
 130.174 -        if (newLength < 0)
 130.175 -            throw new StringIndexOutOfBoundsException(newLength);
 130.176 -        ensureCapacityInternal(newLength);
 130.177 -
 130.178 -        if (count < newLength) {
 130.179 -            for (; count < newLength; count++)
 130.180 -                value[count] = '\0';
 130.181 -        } else {
 130.182 -            count = newLength;
 130.183 -        }
 130.184 -    }
 130.185 -
 130.186 -    /**
 130.187 -     * Returns the <code>char</code> value in this sequence at the specified index.
 130.188 -     * The first <code>char</code> value is at index <code>0</code>, the next at index
 130.189 -     * <code>1</code>, and so on, as in array indexing.
 130.190 -     * <p>
 130.191 -     * The index argument must be greater than or equal to
 130.192 -     * <code>0</code>, and less than the length of this sequence.
 130.193 -     *
 130.194 -     * <p>If the <code>char</code> value specified by the index is a
 130.195 -     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 130.196 -     * value is returned.
 130.197 -     *
 130.198 -     * @param      index   the index of the desired <code>char</code> value.
 130.199 -     * @return     the <code>char</code> value at the specified index.
 130.200 -     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 130.201 -     *             negative or greater than or equal to <code>length()</code>.
 130.202 -     */
 130.203 -    public char charAt(int index) {
 130.204 -        if ((index < 0) || (index >= count))
 130.205 -            throw new StringIndexOutOfBoundsException(index);
 130.206 -        return value[index];
 130.207 -    }
 130.208 -
 130.209 -    /**
 130.210 -     * Returns the character (Unicode code point) at the specified
 130.211 -     * index. The index refers to <code>char</code> values
 130.212 -     * (Unicode code units) and ranges from <code>0</code> to
 130.213 -     * {@link #length()}<code> - 1</code>.
 130.214 -     *
 130.215 -     * <p> If the <code>char</code> value specified at the given index
 130.216 -     * is in the high-surrogate range, the following index is less
 130.217 -     * than the length of this sequence, and the
 130.218 -     * <code>char</code> value at the following index is in the
 130.219 -     * low-surrogate range, then the supplementary code point
 130.220 -     * corresponding to this surrogate pair is returned. Otherwise,
 130.221 -     * the <code>char</code> value at the given index is returned.
 130.222 -     *
 130.223 -     * @param      index the index to the <code>char</code> values
 130.224 -     * @return     the code point value of the character at the
 130.225 -     *             <code>index</code>
 130.226 -     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 130.227 -     *             argument is negative or not less than the length of this
 130.228 -     *             sequence.
 130.229 -     */
 130.230 -    public int codePointAt(int index) {
 130.231 -        if ((index < 0) || (index >= count)) {
 130.232 -            throw new StringIndexOutOfBoundsException(index);
 130.233 -        }
 130.234 -        return Character.codePointAt(value, index);
 130.235 -    }
 130.236 -
 130.237 -    /**
 130.238 -     * Returns the character (Unicode code point) before the specified
 130.239 -     * index. The index refers to <code>char</code> values
 130.240 -     * (Unicode code units) and ranges from <code>1</code> to {@link
 130.241 -     * #length()}.
 130.242 -     *
 130.243 -     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 130.244 -     * is in the low-surrogate range, <code>(index - 2)</code> is not
 130.245 -     * negative, and the <code>char</code> value at <code>(index -
 130.246 -     * 2)</code> is in the high-surrogate range, then the
 130.247 -     * supplementary code point value of the surrogate pair is
 130.248 -     * returned. If the <code>char</code> value at <code>index -
 130.249 -     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 130.250 -     * surrogate value is returned.
 130.251 -     *
 130.252 -     * @param     index the index following the code point that should be returned
 130.253 -     * @return    the Unicode code point value before the given index.
 130.254 -     * @exception IndexOutOfBoundsException if the <code>index</code>
 130.255 -     *            argument is less than 1 or greater than the length
 130.256 -     *            of this sequence.
 130.257 -     */
 130.258 -    public int codePointBefore(int index) {
 130.259 -        int i = index - 1;
 130.260 -        if ((i < 0) || (i >= count)) {
 130.261 -            throw new StringIndexOutOfBoundsException(index);
 130.262 -        }
 130.263 -        return Character.codePointBefore(value, index);
 130.264 -    }
 130.265 -
 130.266 -    /**
 130.267 -     * Returns the number of Unicode code points in the specified text
 130.268 -     * range of this sequence. The text range begins at the specified
 130.269 -     * <code>beginIndex</code> and extends to the <code>char</code> at
 130.270 -     * index <code>endIndex - 1</code>. Thus the length (in
 130.271 -     * <code>char</code>s) of the text range is
 130.272 -     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 130.273 -     * this sequence count as one code point each.
 130.274 -     *
 130.275 -     * @param beginIndex the index to the first <code>char</code> of
 130.276 -     * the text range.
 130.277 -     * @param endIndex the index after the last <code>char</code> of
 130.278 -     * the text range.
 130.279 -     * @return the number of Unicode code points in the specified text
 130.280 -     * range
 130.281 -     * @exception IndexOutOfBoundsException if the
 130.282 -     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 130.283 -     * is larger than the length of this sequence, or
 130.284 -     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 130.285 -     */
 130.286 -    public int codePointCount(int beginIndex, int endIndex) {
 130.287 -        if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
 130.288 -            throw new IndexOutOfBoundsException();
 130.289 -        }
 130.290 -        return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
 130.291 -    }
 130.292 -
 130.293 -    /**
 130.294 -     * Returns the index within this sequence that is offset from the
 130.295 -     * given <code>index</code> by <code>codePointOffset</code> code
 130.296 -     * points. Unpaired surrogates within the text range given by
 130.297 -     * <code>index</code> and <code>codePointOffset</code> count as
 130.298 -     * one code point each.
 130.299 -     *
 130.300 -     * @param index the index to be offset
 130.301 -     * @param codePointOffset the offset in code points
 130.302 -     * @return the index within this sequence
 130.303 -     * @exception IndexOutOfBoundsException if <code>index</code>
 130.304 -     *   is negative or larger then the length of this sequence,
 130.305 -     *   or if <code>codePointOffset</code> is positive and the subsequence
 130.306 -     *   starting with <code>index</code> has fewer than
 130.307 -     *   <code>codePointOffset</code> code points,
 130.308 -     *   or if <code>codePointOffset</code> is negative and the subsequence
 130.309 -     *   before <code>index</code> has fewer than the absolute value of
 130.310 -     *   <code>codePointOffset</code> code points.
 130.311 -     */
 130.312 -    public int offsetByCodePoints(int index, int codePointOffset) {
 130.313 -        if (index < 0 || index > count) {
 130.314 -            throw new IndexOutOfBoundsException();
 130.315 -        }
 130.316 -        return Character.offsetByCodePointsImpl(value, 0, count,
 130.317 -                                                index, codePointOffset);
 130.318 -    }
 130.319 -
 130.320 -    /**
 130.321 -     * Characters are copied from this sequence into the
 130.322 -     * destination character array <code>dst</code>. The first character to
 130.323 -     * be copied is at index <code>srcBegin</code>; the last character to
 130.324 -     * be copied is at index <code>srcEnd-1</code>. The total number of
 130.325 -     * characters to be copied is <code>srcEnd-srcBegin</code>. The
 130.326 -     * characters are copied into the subarray of <code>dst</code> starting
 130.327 -     * at index <code>dstBegin</code> and ending at index:
 130.328 -     * <p><blockquote><pre>
 130.329 -     * dstbegin + (srcEnd-srcBegin) - 1
 130.330 -     * </pre></blockquote>
 130.331 -     *
 130.332 -     * @param      srcBegin   start copying at this offset.
 130.333 -     * @param      srcEnd     stop copying at this offset.
 130.334 -     * @param      dst        the array to copy the data into.
 130.335 -     * @param      dstBegin   offset into <code>dst</code>.
 130.336 -     * @throws     NullPointerException if <code>dst</code> is
 130.337 -     *             <code>null</code>.
 130.338 -     * @throws     IndexOutOfBoundsException  if any of the following is true:
 130.339 -     *             <ul>
 130.340 -     *             <li><code>srcBegin</code> is negative
 130.341 -     *             <li><code>dstBegin</code> is negative
 130.342 -     *             <li>the <code>srcBegin</code> argument is greater than
 130.343 -     *             the <code>srcEnd</code> argument.
 130.344 -     *             <li><code>srcEnd</code> is greater than
 130.345 -     *             <code>this.length()</code>.
 130.346 -     *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
 130.347 -     *             <code>dst.length</code>
 130.348 -     *             </ul>
 130.349 -     */
 130.350 -    public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
 130.351 -    {
 130.352 -        if (srcBegin < 0)
 130.353 -            throw new StringIndexOutOfBoundsException(srcBegin);
 130.354 -        if ((srcEnd < 0) || (srcEnd > count))
 130.355 -            throw new StringIndexOutOfBoundsException(srcEnd);
 130.356 -        if (srcBegin > srcEnd)
 130.357 -            throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
 130.358 -        System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
 130.359 -    }
 130.360 -
 130.361 -    /**
 130.362 -     * The character at the specified index is set to <code>ch</code>. This
 130.363 -     * sequence is altered to represent a new character sequence that is
 130.364 -     * identical to the old character sequence, except that it contains the
 130.365 -     * character <code>ch</code> at position <code>index</code>.
 130.366 -     * <p>
 130.367 -     * The index argument must be greater than or equal to
 130.368 -     * <code>0</code>, and less than the length of this sequence.
 130.369 -     *
 130.370 -     * @param      index   the index of the character to modify.
 130.371 -     * @param      ch      the new character.
 130.372 -     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 130.373 -     *             negative or greater than or equal to <code>length()</code>.
 130.374 -     */
 130.375 -    public void setCharAt(int index, char ch) {
 130.376 -        if ((index < 0) || (index >= count))
 130.377 -            throw new StringIndexOutOfBoundsException(index);
 130.378 -        value[index] = ch;
 130.379 -    }
 130.380 -
 130.381 -    /**
 130.382 -     * Appends the string representation of the {@code Object} argument.
 130.383 -     * <p>
 130.384 -     * The overall effect is exactly as if the argument were converted
 130.385 -     * to a string by the method {@link String#valueOf(Object)},
 130.386 -     * and the characters of that string were then
 130.387 -     * {@link #append(String) appended} to this character sequence.
 130.388 -     *
 130.389 -     * @param   obj   an {@code Object}.
 130.390 -     * @return  a reference to this object.
 130.391 -     */
 130.392 -    public AbstractStringBuilder append(Object obj) {
 130.393 -        return append(String.valueOf(obj));
 130.394 -    }
 130.395 -
 130.396 -    /**
 130.397 -     * Appends the specified string to this character sequence.
 130.398 -     * <p>
 130.399 -     * The characters of the {@code String} argument are appended, in
 130.400 -     * order, increasing the length of this sequence by the length of the
 130.401 -     * argument. If {@code str} is {@code null}, then the four
 130.402 -     * characters {@code "null"} are appended.
 130.403 -     * <p>
 130.404 -     * Let <i>n</i> be the length of this character sequence just prior to
 130.405 -     * execution of the {@code append} method. Then the character at
 130.406 -     * index <i>k</i> in the new character sequence is equal to the character
 130.407 -     * at index <i>k</i> in the old character sequence, if <i>k</i> is less
 130.408 -     * than <i>n</i>; otherwise, it is equal to the character at index
 130.409 -     * <i>k-n</i> in the argument {@code str}.
 130.410 -     *
 130.411 -     * @param   str   a string.
 130.412 -     * @return  a reference to this object.
 130.413 -     */
 130.414 -    public AbstractStringBuilder append(String str) {
 130.415 -        if (str == null) str = "null";
 130.416 -        int len = str.length();
 130.417 -        ensureCapacityInternal(count + len);
 130.418 -        str.getChars(0, len, value, count);
 130.419 -        count += len;
 130.420 -        return this;
 130.421 -    }
 130.422 -
 130.423 -    // Documentation in subclasses because of synchro difference
 130.424 -    public AbstractStringBuilder append(StringBuffer sb) {
 130.425 -        if (sb == null)
 130.426 -            return append("null");
 130.427 -        int len = sb.length();
 130.428 -        ensureCapacityInternal(count + len);
 130.429 -        sb.getChars(0, len, value, count);
 130.430 -        count += len;
 130.431 -        return this;
 130.432 -    }
 130.433 -
 130.434 -    // Documentation in subclasses because of synchro difference
 130.435 -    public AbstractStringBuilder append(CharSequence s) {
 130.436 -        if (s == null)
 130.437 -            s = "null";
 130.438 -        if (s instanceof String)
 130.439 -            return this.append((String)s);
 130.440 -        if (s instanceof StringBuffer)
 130.441 -            return this.append((StringBuffer)s);
 130.442 -        return this.append(s, 0, s.length());
 130.443 -    }
 130.444 -
 130.445 -    /**
 130.446 -     * Appends a subsequence of the specified {@code CharSequence} to this
 130.447 -     * sequence.
 130.448 -     * <p>
 130.449 -     * Characters of the argument {@code s}, starting at
 130.450 -     * index {@code start}, are appended, in order, to the contents of
 130.451 -     * this sequence up to the (exclusive) index {@code end}. The length
 130.452 -     * of this sequence is increased by the value of {@code end - start}.
 130.453 -     * <p>
 130.454 -     * Let <i>n</i> be the length of this character sequence just prior to
 130.455 -     * execution of the {@code append} method. Then the character at
 130.456 -     * index <i>k</i> in this character sequence becomes equal to the
 130.457 -     * character at index <i>k</i> in this sequence, if <i>k</i> is less than
 130.458 -     * <i>n</i>; otherwise, it is equal to the character at index
 130.459 -     * <i>k+start-n</i> in the argument {@code s}.
 130.460 -     * <p>
 130.461 -     * If {@code s} is {@code null}, then this method appends
 130.462 -     * characters as if the s parameter was a sequence containing the four
 130.463 -     * characters {@code "null"}.
 130.464 -     *
 130.465 -     * @param   s the sequence to append.
 130.466 -     * @param   start   the starting index of the subsequence to be appended.
 130.467 -     * @param   end     the end index of the subsequence to be appended.
 130.468 -     * @return  a reference to this object.
 130.469 -     * @throws     IndexOutOfBoundsException if
 130.470 -     *             {@code start} is negative, or
 130.471 -     *             {@code start} is greater than {@code end} or
 130.472 -     *             {@code end} is greater than {@code s.length()}
 130.473 -     */
 130.474 -    public AbstractStringBuilder append(CharSequence s, int start, int end) {
 130.475 -        if (s == null)
 130.476 -            s = "null";
 130.477 -        if ((start < 0) || (start > end) || (end > s.length()))
 130.478 -            throw new IndexOutOfBoundsException(
 130.479 -                "start " + start + ", end " + end + ", s.length() "
 130.480 -                + s.length());
 130.481 -        int len = end - start;
 130.482 -        ensureCapacityInternal(count + len);
 130.483 -        for (int i = start, j = count; i < end; i++, j++)
 130.484 -            value[j] = s.charAt(i);
 130.485 -        count += len;
 130.486 -        return this;
 130.487 -    }
 130.488 -
 130.489 -    /**
 130.490 -     * Appends the string representation of the {@code char} array
 130.491 -     * argument to this sequence.
 130.492 -     * <p>
 130.493 -     * The characters of the array argument are appended, in order, to
 130.494 -     * the contents of this sequence. The length of this sequence
 130.495 -     * increases by the length of the argument.
 130.496 -     * <p>
 130.497 -     * The overall effect is exactly as if the argument were converted
 130.498 -     * to a string by the method {@link String#valueOf(char[])},
 130.499 -     * and the characters of that string were then
 130.500 -     * {@link #append(String) appended} to this character sequence.
 130.501 -     *
 130.502 -     * @param   str   the characters to be appended.
 130.503 -     * @return  a reference to this object.
 130.504 -     */
 130.505 -    public AbstractStringBuilder append(char[] str) {
 130.506 -        int len = str.length;
 130.507 -        ensureCapacityInternal(count + len);
 130.508 -        System.arraycopy(str, 0, value, count, len);
 130.509 -        count += len;
 130.510 -        return this;
 130.511 -    }
 130.512 -
 130.513 -    /**
 130.514 -     * Appends the string representation of a subarray of the
 130.515 -     * {@code char} array argument to this sequence.
 130.516 -     * <p>
 130.517 -     * Characters of the {@code char} array {@code str}, starting at
 130.518 -     * index {@code offset}, are appended, in order, to the contents
 130.519 -     * of this sequence. The length of this sequence increases
 130.520 -     * by the value of {@code len}.
 130.521 -     * <p>
 130.522 -     * The overall effect is exactly as if the arguments were converted
 130.523 -     * to a string by the method {@link String#valueOf(char[],int,int)},
 130.524 -     * and the characters of that string were then
 130.525 -     * {@link #append(String) appended} to this character sequence.
 130.526 -     *
 130.527 -     * @param   str      the characters to be appended.
 130.528 -     * @param   offset   the index of the first {@code char} to append.
 130.529 -     * @param   len      the number of {@code char}s to append.
 130.530 -     * @return  a reference to this object.
 130.531 -     * @throws IndexOutOfBoundsException
 130.532 -     *         if {@code offset < 0} or {@code len < 0}
 130.533 -     *         or {@code offset+len > str.length}
 130.534 -     */
 130.535 -    public AbstractStringBuilder append(char str[], int offset, int len) {
 130.536 -        if (len > 0)                // let arraycopy report AIOOBE for len < 0
 130.537 -            ensureCapacityInternal(count + len);
 130.538 -        System.arraycopy(str, offset, value, count, len);
 130.539 -        count += len;
 130.540 -        return this;
 130.541 -    }
 130.542 -
 130.543 -    /**
 130.544 -     * Appends the string representation of the {@code boolean}
 130.545 -     * argument to the sequence.
 130.546 -     * <p>
 130.547 -     * The overall effect is exactly as if the argument were converted
 130.548 -     * to a string by the method {@link String#valueOf(boolean)},
 130.549 -     * and the characters of that string were then
 130.550 -     * {@link #append(String) appended} to this character sequence.
 130.551 -     *
 130.552 -     * @param   b   a {@code boolean}.
 130.553 -     * @return  a reference to this object.
 130.554 -     */
 130.555 -    public AbstractStringBuilder append(boolean b) {
 130.556 -        if (b) {
 130.557 -            ensureCapacityInternal(count + 4);
 130.558 -            value[count++] = 't';
 130.559 -            value[count++] = 'r';
 130.560 -            value[count++] = 'u';
 130.561 -            value[count++] = 'e';
 130.562 -        } else {
 130.563 -            ensureCapacityInternal(count + 5);
 130.564 -            value[count++] = 'f';
 130.565 -            value[count++] = 'a';
 130.566 -            value[count++] = 'l';
 130.567 -            value[count++] = 's';
 130.568 -            value[count++] = 'e';
 130.569 -        }
 130.570 -        return this;
 130.571 -    }
 130.572 -
 130.573 -    /**
 130.574 -     * Appends the string representation of the {@code char}
 130.575 -     * argument to this sequence.
 130.576 -     * <p>
 130.577 -     * The argument is appended to the contents of this sequence.
 130.578 -     * The length of this sequence increases by {@code 1}.
 130.579 -     * <p>
 130.580 -     * The overall effect is exactly as if the argument were converted
 130.581 -     * to a string by the method {@link String#valueOf(char)},
 130.582 -     * and the character in that string were then
 130.583 -     * {@link #append(String) appended} to this character sequence.
 130.584 -     *
 130.585 -     * @param   c   a {@code char}.
 130.586 -     * @return  a reference to this object.
 130.587 -     */
 130.588 -    public AbstractStringBuilder append(char c) {
 130.589 -        ensureCapacityInternal(count + 1);
 130.590 -        value[count++] = c;
 130.591 -        return this;
 130.592 -    }
 130.593 -
 130.594 -    /**
 130.595 -     * Appends the string representation of the {@code int}
 130.596 -     * argument to this sequence.
 130.597 -     * <p>
 130.598 -     * The overall effect is exactly as if the argument were converted
 130.599 -     * to a string by the method {@link String#valueOf(int)},
 130.600 -     * and the characters of that string were then
 130.601 -     * {@link #append(String) appended} to this character sequence.
 130.602 -     *
 130.603 -     * @param   i   an {@code int}.
 130.604 -     * @return  a reference to this object.
 130.605 -     */
 130.606 -    public AbstractStringBuilder append(int i) {
 130.607 -        return append(Integer.toString(i));
 130.608 -    }
 130.609 -
 130.610 -    /**
 130.611 -     * Appends the string representation of the {@code long}
 130.612 -     * argument to this sequence.
 130.613 -     * <p>
 130.614 -     * The overall effect is exactly as if the argument were converted
 130.615 -     * to a string by the method {@link String#valueOf(long)},
 130.616 -     * and the characters of that string were then
 130.617 -     * {@link #append(String) appended} to this character sequence.
 130.618 -     *
 130.619 -     * @param   l   a {@code long}.
 130.620 -     * @return  a reference to this object.
 130.621 -     */
 130.622 -    public AbstractStringBuilder append(long l) {
 130.623 -        if (l == Long.MIN_VALUE) {
 130.624 -            append("-9223372036854775808");
 130.625 -            return this;
 130.626 -        }
 130.627 -        int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
 130.628 -                                     : Long.stringSize(l);
 130.629 -        int spaceNeeded = count + appendedLength;
 130.630 -        ensureCapacityInternal(spaceNeeded);
 130.631 -        Long.getChars(l, spaceNeeded, value);
 130.632 -        count = spaceNeeded;
 130.633 -        return this;
 130.634 -    }
 130.635 -
 130.636 -    /**
 130.637 -     * Appends the string representation of the {@code float}
 130.638 -     * argument to this sequence.
 130.639 -     * <p>
 130.640 -     * The overall effect is exactly as if the argument were converted
 130.641 -     * to a string by the method {@link String#valueOf(float)},
 130.642 -     * and the characters of that string were then
 130.643 -     * {@link #append(String) appended} to this character sequence.
 130.644 -     *
 130.645 -     * @param   f   a {@code float}.
 130.646 -     * @return  a reference to this object.
 130.647 -     */
 130.648 -    public AbstractStringBuilder append(float f) {
 130.649 -        return append(Float.toString(f));
 130.650 -    }
 130.651 -
 130.652 -    /**
 130.653 -     * Appends the string representation of the {@code double}
 130.654 -     * argument to this sequence.
 130.655 -     * <p>
 130.656 -     * The overall effect is exactly as if the argument were converted
 130.657 -     * to a string by the method {@link String#valueOf(double)},
 130.658 -     * and the characters of that string were then
 130.659 -     * {@link #append(String) appended} to this character sequence.
 130.660 -     *
 130.661 -     * @param   d   a {@code double}.
 130.662 -     * @return  a reference to this object.
 130.663 -     */
 130.664 -    public AbstractStringBuilder append(double d) {
 130.665 -        return append(Double.toString(d));
 130.666 -    }
 130.667 -
 130.668 -    /**
 130.669 -     * Removes the characters in a substring of this sequence.
 130.670 -     * The substring begins at the specified {@code start} and extends to
 130.671 -     * the character at index {@code end - 1} or to the end of the
 130.672 -     * sequence if no such character exists. If
 130.673 -     * {@code start} is equal to {@code end}, no changes are made.
 130.674 -     *
 130.675 -     * @param      start  The beginning index, inclusive.
 130.676 -     * @param      end    The ending index, exclusive.
 130.677 -     * @return     This object.
 130.678 -     * @throws     StringIndexOutOfBoundsException  if {@code start}
 130.679 -     *             is negative, greater than {@code length()}, or
 130.680 -     *             greater than {@code end}.
 130.681 -     */
 130.682 -    public AbstractStringBuilder delete(int start, int end) {
 130.683 -        if (start < 0)
 130.684 -            throw new StringIndexOutOfBoundsException(start);
 130.685 -        if (end > count)
 130.686 -            end = count;
 130.687 -        if (start > end)
 130.688 -            throw new StringIndexOutOfBoundsException();
 130.689 -        int len = end - start;
 130.690 -        if (len > 0) {
 130.691 -            System.arraycopy(value, start+len, value, start, count-end);
 130.692 -            count -= len;
 130.693 -        }
 130.694 -        return this;
 130.695 -    }
 130.696 -
 130.697 -    /**
 130.698 -     * Appends the string representation of the {@code codePoint}
 130.699 -     * argument to this sequence.
 130.700 -     *
 130.701 -     * <p> The argument is appended to the contents of this sequence.
 130.702 -     * The length of this sequence increases by
 130.703 -     * {@link Character#charCount(int) Character.charCount(codePoint)}.
 130.704 -     *
 130.705 -     * <p> The overall effect is exactly as if the argument were
 130.706 -     * converted to a {@code char} array by the method
 130.707 -     * {@link Character#toChars(int)} and the character in that array
 130.708 -     * were then {@link #append(char[]) appended} to this character
 130.709 -     * sequence.
 130.710 -     *
 130.711 -     * @param   codePoint   a Unicode code point
 130.712 -     * @return  a reference to this object.
 130.713 -     * @exception IllegalArgumentException if the specified
 130.714 -     * {@code codePoint} isn't a valid Unicode code point
 130.715 -     */
 130.716 -    public AbstractStringBuilder appendCodePoint(int codePoint) {
 130.717 -        final int count = this.count;
 130.718 -
 130.719 -        if (Character.isBmpCodePoint(codePoint)) {
 130.720 -            ensureCapacityInternal(count + 1);
 130.721 -            value[count] = (char) codePoint;
 130.722 -            this.count = count + 1;
 130.723 -        } else if (Character.isValidCodePoint(codePoint)) {
 130.724 -            ensureCapacityInternal(count + 2);
 130.725 -            Character.toSurrogates(codePoint, value, count);
 130.726 -            this.count = count + 2;
 130.727 -        } else {
 130.728 -            throw new IllegalArgumentException();
 130.729 -        }
 130.730 -        return this;
 130.731 -    }
 130.732 -
 130.733 -    /**
 130.734 -     * Removes the <code>char</code> at the specified position in this
 130.735 -     * sequence. This sequence is shortened by one <code>char</code>.
 130.736 -     *
 130.737 -     * <p>Note: If the character at the given index is a supplementary
 130.738 -     * character, this method does not remove the entire character. If
 130.739 -     * correct handling of supplementary characters is required,
 130.740 -     * determine the number of <code>char</code>s to remove by calling
 130.741 -     * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
 130.742 -     * where <code>thisSequence</code> is this sequence.
 130.743 -     *
 130.744 -     * @param       index  Index of <code>char</code> to remove
 130.745 -     * @return      This object.
 130.746 -     * @throws      StringIndexOutOfBoundsException  if the <code>index</code>
 130.747 -     *              is negative or greater than or equal to
 130.748 -     *              <code>length()</code>.
 130.749 -     */
 130.750 -    public AbstractStringBuilder deleteCharAt(int index) {
 130.751 -        if ((index < 0) || (index >= count))
 130.752 -            throw new StringIndexOutOfBoundsException(index);
 130.753 -        System.arraycopy(value, index+1, value, index, count-index-1);
 130.754 -        count--;
 130.755 -        return this;
 130.756 -    }
 130.757 -
 130.758 -    /**
 130.759 -     * Replaces the characters in a substring of this sequence
 130.760 -     * with characters in the specified <code>String</code>. The substring
 130.761 -     * begins at the specified <code>start</code> and extends to the character
 130.762 -     * at index <code>end - 1</code> or to the end of the
 130.763 -     * sequence if no such character exists. First the
 130.764 -     * characters in the substring are removed and then the specified
 130.765 -     * <code>String</code> is inserted at <code>start</code>. (This
 130.766 -     * sequence will be lengthened to accommodate the
 130.767 -     * specified String if necessary.)
 130.768 -     *
 130.769 -     * @param      start    The beginning index, inclusive.
 130.770 -     * @param      end      The ending index, exclusive.
 130.771 -     * @param      str   String that will replace previous contents.
 130.772 -     * @return     This object.
 130.773 -     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 130.774 -     *             is negative, greater than <code>length()</code>, or
 130.775 -     *             greater than <code>end</code>.
 130.776 -     */
 130.777 -    public AbstractStringBuilder replace(int start, int end, String str) {
 130.778 -        if (start < 0)
 130.779 -            throw new StringIndexOutOfBoundsException(start);
 130.780 -        if (start > count)
 130.781 -            throw new StringIndexOutOfBoundsException("start > length()");
 130.782 -        if (start > end)
 130.783 -            throw new StringIndexOutOfBoundsException("start > end");
 130.784 -
 130.785 -        if (end > count)
 130.786 -            end = count;
 130.787 -        int len = str.length();
 130.788 -        int newCount = count + len - (end - start);
 130.789 -        ensureCapacityInternal(newCount);
 130.790 -
 130.791 -        System.arraycopy(value, end, value, start + len, count - end);
 130.792 -        str.getChars(value, start);
 130.793 -        count = newCount;
 130.794 -        return this;
 130.795 -    }
 130.796 -
 130.797 -    /**
 130.798 -     * Returns a new <code>String</code> that contains a subsequence of
 130.799 -     * characters currently contained in this character sequence. The
 130.800 -     * substring begins at the specified index and extends to the end of
 130.801 -     * this sequence.
 130.802 -     *
 130.803 -     * @param      start    The beginning index, inclusive.
 130.804 -     * @return     The new string.
 130.805 -     * @throws     StringIndexOutOfBoundsException  if <code>start</code> is
 130.806 -     *             less than zero, or greater than the length of this object.
 130.807 -     */
 130.808 -    public String substring(int start) {
 130.809 -        return substring(start, count);
 130.810 -    }
 130.811 -
 130.812 -    /**
 130.813 -     * Returns a new character sequence that is a subsequence of this sequence.
 130.814 -     *
 130.815 -     * <p> An invocation of this method of the form
 130.816 -     *
 130.817 -     * <blockquote><pre>
 130.818 -     * sb.subSequence(begin,&nbsp;end)</pre></blockquote>
 130.819 -     *
 130.820 -     * behaves in exactly the same way as the invocation
 130.821 -     *
 130.822 -     * <blockquote><pre>
 130.823 -     * sb.substring(begin,&nbsp;end)</pre></blockquote>
 130.824 -     *
 130.825 -     * This method is provided so that this class can
 130.826 -     * implement the {@link CharSequence} interface. </p>
 130.827 -     *
 130.828 -     * @param      start   the start index, inclusive.
 130.829 -     * @param      end     the end index, exclusive.
 130.830 -     * @return     the specified subsequence.
 130.831 -     *
 130.832 -     * @throws  IndexOutOfBoundsException
 130.833 -     *          if <tt>start</tt> or <tt>end</tt> are negative,
 130.834 -     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 130.835 -     *          or if <tt>start</tt> is greater than <tt>end</tt>
 130.836 -     * @spec JSR-51
 130.837 -     */
 130.838 -    public CharSequence subSequence(int start, int end) {
 130.839 -        return substring(start, end);
 130.840 -    }
 130.841 -
 130.842 -    /**
 130.843 -     * Returns a new <code>String</code> that contains a subsequence of
 130.844 -     * characters currently contained in this sequence. The
 130.845 -     * substring begins at the specified <code>start</code> and
 130.846 -     * extends to the character at index <code>end - 1</code>.
 130.847 -     *
 130.848 -     * @param      start    The beginning index, inclusive.
 130.849 -     * @param      end      The ending index, exclusive.
 130.850 -     * @return     The new string.
 130.851 -     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 130.852 -     *             or <code>end</code> are negative or greater than
 130.853 -     *             <code>length()</code>, or <code>start</code> is
 130.854 -     *             greater than <code>end</code>.
 130.855 -     */
 130.856 -    public String substring(int start, int end) {
 130.857 -        if (start < 0)
 130.858 -            throw new StringIndexOutOfBoundsException(start);
 130.859 -        if (end > count)
 130.860 -            throw new StringIndexOutOfBoundsException(end);
 130.861 -        if (start > end)
 130.862 -            throw new StringIndexOutOfBoundsException(end - start);
 130.863 -        return new String(value, start, end - start);
 130.864 -    }
 130.865 -
 130.866 -    /**
 130.867 -     * Inserts the string representation of a subarray of the {@code str}
 130.868 -     * array argument into this sequence. The subarray begins at the
 130.869 -     * specified {@code offset} and extends {@code len} {@code char}s.
 130.870 -     * The characters of the subarray are inserted into this sequence at
 130.871 -     * the position indicated by {@code index}. The length of this
 130.872 -     * sequence increases by {@code len} {@code char}s.
 130.873 -     *
 130.874 -     * @param      index    position at which to insert subarray.
 130.875 -     * @param      str       A {@code char} array.
 130.876 -     * @param      offset   the index of the first {@code char} in subarray to
 130.877 -     *             be inserted.
 130.878 -     * @param      len      the number of {@code char}s in the subarray to
 130.879 -     *             be inserted.
 130.880 -     * @return     This object
 130.881 -     * @throws     StringIndexOutOfBoundsException  if {@code index}
 130.882 -     *             is negative or greater than {@code length()}, or
 130.883 -     *             {@code offset} or {@code len} are negative, or
 130.884 -     *             {@code (offset+len)} is greater than
 130.885 -     *             {@code str.length}.
 130.886 -     */
 130.887 -    public AbstractStringBuilder insert(int index, char[] str, int offset,
 130.888 -                                        int len)
 130.889 -    {
 130.890 -        if ((index < 0) || (index > length()))
 130.891 -            throw new StringIndexOutOfBoundsException(index);
 130.892 -        if ((offset < 0) || (len < 0) || (offset > str.length - len))
 130.893 -            throw new StringIndexOutOfBoundsException(
 130.894 -                "offset " + offset + ", len " + len + ", str.length "
 130.895 -                + str.length);
 130.896 -        ensureCapacityInternal(count + len);
 130.897 -        System.arraycopy(value, index, value, index + len, count - index);
 130.898 -        System.arraycopy(str, offset, value, index, len);
 130.899 -        count += len;
 130.900 -        return this;
 130.901 -    }
 130.902 -
 130.903 -    /**
 130.904 -     * Inserts the string representation of the {@code Object}
 130.905 -     * argument into this character sequence.
 130.906 -     * <p>
 130.907 -     * The overall effect is exactly as if the second argument were
 130.908 -     * converted to a string by the method {@link String#valueOf(Object)},
 130.909 -     * and the characters of that string were then
 130.910 -     * {@link #insert(int,String) inserted} into this character
 130.911 -     * sequence at the indicated offset.
 130.912 -     * <p>
 130.913 -     * The {@code offset} argument must be greater than or equal to
 130.914 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 130.915 -     * of this sequence.
 130.916 -     *
 130.917 -     * @param      offset   the offset.
 130.918 -     * @param      obj      an {@code Object}.
 130.919 -     * @return     a reference to this object.
 130.920 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 130.921 -     */
 130.922 -    public AbstractStringBuilder insert(int offset, Object obj) {
 130.923 -        return insert(offset, String.valueOf(obj));
 130.924 -    }
 130.925 -
 130.926 -    /**
 130.927 -     * Inserts the string into this character sequence.
 130.928 -     * <p>
 130.929 -     * The characters of the {@code String} argument are inserted, in
 130.930 -     * order, into this sequence at the indicated offset, moving up any
 130.931 -     * characters originally above that position and increasing the length
 130.932 -     * of this sequence by the length of the argument. If
 130.933 -     * {@code str} is {@code null}, then the four characters
 130.934 -     * {@code "null"} are inserted into this sequence.
 130.935 -     * <p>
 130.936 -     * The character at index <i>k</i> in the new character sequence is
 130.937 -     * equal to:
 130.938 -     * <ul>
 130.939 -     * <li>the character at index <i>k</i> in the old character sequence, if
 130.940 -     * <i>k</i> is less than {@code offset}
 130.941 -     * <li>the character at index <i>k</i>{@code -offset} in the
 130.942 -     * argument {@code str}, if <i>k</i> is not less than
 130.943 -     * {@code offset} but is less than {@code offset+str.length()}
 130.944 -     * <li>the character at index <i>k</i>{@code -str.length()} in the
 130.945 -     * old character sequence, if <i>k</i> is not less than
 130.946 -     * {@code offset+str.length()}
 130.947 -     * </ul><p>
 130.948 -     * The {@code offset} argument must be greater than or equal to
 130.949 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 130.950 -     * of this sequence.
 130.951 -     *
 130.952 -     * @param      offset   the offset.
 130.953 -     * @param      str      a string.
 130.954 -     * @return     a reference to this object.
 130.955 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 130.956 -     */
 130.957 -    public AbstractStringBuilder insert(int offset, String str) {
 130.958 -        if ((offset < 0) || (offset > length()))
 130.959 -            throw new StringIndexOutOfBoundsException(offset);
 130.960 -        if (str == null)
 130.961 -            str = "null";
 130.962 -        int len = str.length();
 130.963 -        ensureCapacityInternal(count + len);
 130.964 -        System.arraycopy(value, offset, value, offset + len, count - offset);
 130.965 -        str.getChars(value, offset);
 130.966 -        count += len;
 130.967 -        return this;
 130.968 -    }
 130.969 -
 130.970 -    /**
 130.971 -     * Inserts the string representation of the {@code char} array
 130.972 -     * argument into this sequence.
 130.973 -     * <p>
 130.974 -     * The characters of the array argument are inserted into the
 130.975 -     * contents of this sequence at the position indicated by
 130.976 -     * {@code offset}. The length of this sequence increases by
 130.977 -     * the length of the argument.
 130.978 -     * <p>
 130.979 -     * The overall effect is exactly as if the second argument were
 130.980 -     * converted to a string by the method {@link String#valueOf(char[])},
 130.981 -     * and the characters of that string were then
 130.982 -     * {@link #insert(int,String) inserted} into this character
 130.983 -     * sequence at the indicated offset.
 130.984 -     * <p>
 130.985 -     * The {@code offset} argument must be greater than or equal to
 130.986 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 130.987 -     * of this sequence.
 130.988 -     *
 130.989 -     * @param      offset   the offset.
 130.990 -     * @param      str      a character array.
 130.991 -     * @return     a reference to this object.
 130.992 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 130.993 -     */
 130.994 -    public AbstractStringBuilder insert(int offset, char[] str) {
 130.995 -        if ((offset < 0) || (offset > length()))
 130.996 -            throw new StringIndexOutOfBoundsException(offset);
 130.997 -        int len = str.length;
 130.998 -        ensureCapacityInternal(count + len);
 130.999 -        System.arraycopy(value, offset, value, offset + len, count - offset);
130.1000 -        System.arraycopy(str, 0, value, offset, len);
130.1001 -        count += len;
130.1002 -        return this;
130.1003 -    }
130.1004 -
130.1005 -    /**
130.1006 -     * Inserts the specified {@code CharSequence} into this sequence.
130.1007 -     * <p>
130.1008 -     * The characters of the {@code CharSequence} argument are inserted,
130.1009 -     * in order, into this sequence at the indicated offset, moving up
130.1010 -     * any characters originally above that position and increasing the length
130.1011 -     * of this sequence by the length of the argument s.
130.1012 -     * <p>
130.1013 -     * The result of this method is exactly the same as if it were an
130.1014 -     * invocation of this object's
130.1015 -     * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
130.1016 -     * method.
130.1017 -     *
130.1018 -     * <p>If {@code s} is {@code null}, then the four characters
130.1019 -     * {@code "null"} are inserted into this sequence.
130.1020 -     *
130.1021 -     * @param      dstOffset   the offset.
130.1022 -     * @param      s the sequence to be inserted
130.1023 -     * @return     a reference to this object.
130.1024 -     * @throws     IndexOutOfBoundsException  if the offset is invalid.
130.1025 -     */
130.1026 -    public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
130.1027 -        if (s == null)
130.1028 -            s = "null";
130.1029 -        if (s instanceof String)
130.1030 -            return this.insert(dstOffset, (String)s);
130.1031 -        return this.insert(dstOffset, s, 0, s.length());
130.1032 -    }
130.1033 -
130.1034 -    /**
130.1035 -     * Inserts a subsequence of the specified {@code CharSequence} into
130.1036 -     * this sequence.
130.1037 -     * <p>
130.1038 -     * The subsequence of the argument {@code s} specified by
130.1039 -     * {@code start} and {@code end} are inserted,
130.1040 -     * in order, into this sequence at the specified destination offset, moving
130.1041 -     * up any characters originally above that position. The length of this
130.1042 -     * sequence is increased by {@code end - start}.
130.1043 -     * <p>
130.1044 -     * The character at index <i>k</i> in this sequence becomes equal to:
130.1045 -     * <ul>
130.1046 -     * <li>the character at index <i>k</i> in this sequence, if
130.1047 -     * <i>k</i> is less than {@code dstOffset}
130.1048 -     * <li>the character at index <i>k</i>{@code +start-dstOffset} in
130.1049 -     * the argument {@code s}, if <i>k</i> is greater than or equal to
130.1050 -     * {@code dstOffset} but is less than {@code dstOffset+end-start}
130.1051 -     * <li>the character at index <i>k</i>{@code -(end-start)} in this
130.1052 -     * sequence, if <i>k</i> is greater than or equal to
130.1053 -     * {@code dstOffset+end-start}
130.1054 -     * </ul><p>
130.1055 -     * The {@code dstOffset} argument must be greater than or equal to
130.1056 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1057 -     * of this sequence.
130.1058 -     * <p>The start argument must be nonnegative, and not greater than
130.1059 -     * {@code end}.
130.1060 -     * <p>The end argument must be greater than or equal to
130.1061 -     * {@code start}, and less than or equal to the length of s.
130.1062 -     *
130.1063 -     * <p>If {@code s} is {@code null}, then this method inserts
130.1064 -     * characters as if the s parameter was a sequence containing the four
130.1065 -     * characters {@code "null"}.
130.1066 -     *
130.1067 -     * @param      dstOffset   the offset in this sequence.
130.1068 -     * @param      s       the sequence to be inserted.
130.1069 -     * @param      start   the starting index of the subsequence to be inserted.
130.1070 -     * @param      end     the end index of the subsequence to be inserted.
130.1071 -     * @return     a reference to this object.
130.1072 -     * @throws     IndexOutOfBoundsException  if {@code dstOffset}
130.1073 -     *             is negative or greater than {@code this.length()}, or
130.1074 -     *              {@code start} or {@code end} are negative, or
130.1075 -     *              {@code start} is greater than {@code end} or
130.1076 -     *              {@code end} is greater than {@code s.length()}
130.1077 -     */
130.1078 -     public AbstractStringBuilder insert(int dstOffset, CharSequence s,
130.1079 -                                         int start, int end) {
130.1080 -        if (s == null)
130.1081 -            s = "null";
130.1082 -        if ((dstOffset < 0) || (dstOffset > this.length()))
130.1083 -            throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
130.1084 -        if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
130.1085 -            throw new IndexOutOfBoundsException(
130.1086 -                "start " + start + ", end " + end + ", s.length() "
130.1087 -                + s.length());
130.1088 -        int len = end - start;
130.1089 -        ensureCapacityInternal(count + len);
130.1090 -        System.arraycopy(value, dstOffset, value, dstOffset + len,
130.1091 -                         count - dstOffset);
130.1092 -        for (int i=start; i<end; i++)
130.1093 -            value[dstOffset++] = s.charAt(i);
130.1094 -        count += len;
130.1095 -        return this;
130.1096 -    }
130.1097 -
130.1098 -    /**
130.1099 -     * Inserts the string representation of the {@code boolean}
130.1100 -     * argument into this sequence.
130.1101 -     * <p>
130.1102 -     * The overall effect is exactly as if the second argument were
130.1103 -     * converted to a string by the method {@link String#valueOf(boolean)},
130.1104 -     * and the characters of that string were then
130.1105 -     * {@link #insert(int,String) inserted} into this character
130.1106 -     * sequence at the indicated offset.
130.1107 -     * <p>
130.1108 -     * The {@code offset} argument must be greater than or equal to
130.1109 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1110 -     * of this sequence.
130.1111 -     *
130.1112 -     * @param      offset   the offset.
130.1113 -     * @param      b        a {@code boolean}.
130.1114 -     * @return     a reference to this object.
130.1115 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
130.1116 -     */
130.1117 -    public AbstractStringBuilder insert(int offset, boolean b) {
130.1118 -        return insert(offset, String.valueOf(b));
130.1119 -    }
130.1120 -
130.1121 -    /**
130.1122 -     * Inserts the string representation of the {@code char}
130.1123 -     * argument into this sequence.
130.1124 -     * <p>
130.1125 -     * The overall effect is exactly as if the second argument were
130.1126 -     * converted to a string by the method {@link String#valueOf(char)},
130.1127 -     * and the character in that string were then
130.1128 -     * {@link #insert(int,String) inserted} into this character
130.1129 -     * sequence at the indicated offset.
130.1130 -     * <p>
130.1131 -     * The {@code offset} argument must be greater than or equal to
130.1132 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1133 -     * of this sequence.
130.1134 -     *
130.1135 -     * @param      offset   the offset.
130.1136 -     * @param      c        a {@code char}.
130.1137 -     * @return     a reference to this object.
130.1138 -     * @throws     IndexOutOfBoundsException  if the offset is invalid.
130.1139 -     */
130.1140 -    public AbstractStringBuilder insert(int offset, char c) {
130.1141 -        ensureCapacityInternal(count + 1);
130.1142 -        System.arraycopy(value, offset, value, offset + 1, count - offset);
130.1143 -        value[offset] = c;
130.1144 -        count += 1;
130.1145 -        return this;
130.1146 -    }
130.1147 -
130.1148 -    /**
130.1149 -     * Inserts the string representation of the second {@code int}
130.1150 -     * argument into this sequence.
130.1151 -     * <p>
130.1152 -     * The overall effect is exactly as if the second argument were
130.1153 -     * converted to a string by the method {@link String#valueOf(int)},
130.1154 -     * and the characters of that string were then
130.1155 -     * {@link #insert(int,String) inserted} into this character
130.1156 -     * sequence at the indicated offset.
130.1157 -     * <p>
130.1158 -     * The {@code offset} argument must be greater than or equal to
130.1159 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1160 -     * of this sequence.
130.1161 -     *
130.1162 -     * @param      offset   the offset.
130.1163 -     * @param      i        an {@code int}.
130.1164 -     * @return     a reference to this object.
130.1165 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
130.1166 -     */
130.1167 -    public AbstractStringBuilder insert(int offset, int i) {
130.1168 -        return insert(offset, String.valueOf(i));
130.1169 -    }
130.1170 -
130.1171 -    /**
130.1172 -     * Inserts the string representation of the {@code long}
130.1173 -     * argument into this sequence.
130.1174 -     * <p>
130.1175 -     * The overall effect is exactly as if the second argument were
130.1176 -     * converted to a string by the method {@link String#valueOf(long)},
130.1177 -     * and the characters of that string were then
130.1178 -     * {@link #insert(int,String) inserted} into this character
130.1179 -     * sequence at the indicated offset.
130.1180 -     * <p>
130.1181 -     * The {@code offset} argument must be greater than or equal to
130.1182 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1183 -     * of this sequence.
130.1184 -     *
130.1185 -     * @param      offset   the offset.
130.1186 -     * @param      l        a {@code long}.
130.1187 -     * @return     a reference to this object.
130.1188 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
130.1189 -     */
130.1190 -    public AbstractStringBuilder insert(int offset, long l) {
130.1191 -        return insert(offset, String.valueOf(l));
130.1192 -    }
130.1193 -
130.1194 -    /**
130.1195 -     * Inserts the string representation of the {@code float}
130.1196 -     * argument into this sequence.
130.1197 -     * <p>
130.1198 -     * The overall effect is exactly as if the second argument were
130.1199 -     * converted to a string by the method {@link String#valueOf(float)},
130.1200 -     * and the characters of that string were then
130.1201 -     * {@link #insert(int,String) inserted} into this character
130.1202 -     * sequence at the indicated offset.
130.1203 -     * <p>
130.1204 -     * The {@code offset} argument must be greater than or equal to
130.1205 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1206 -     * of this sequence.
130.1207 -     *
130.1208 -     * @param      offset   the offset.
130.1209 -     * @param      f        a {@code float}.
130.1210 -     * @return     a reference to this object.
130.1211 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
130.1212 -     */
130.1213 -    public AbstractStringBuilder insert(int offset, float f) {
130.1214 -        return insert(offset, String.valueOf(f));
130.1215 -    }
130.1216 -
130.1217 -    /**
130.1218 -     * Inserts the string representation of the {@code double}
130.1219 -     * argument into this sequence.
130.1220 -     * <p>
130.1221 -     * The overall effect is exactly as if the second argument were
130.1222 -     * converted to a string by the method {@link String#valueOf(double)},
130.1223 -     * and the characters of that string were then
130.1224 -     * {@link #insert(int,String) inserted} into this character
130.1225 -     * sequence at the indicated offset.
130.1226 -     * <p>
130.1227 -     * The {@code offset} argument must be greater than or equal to
130.1228 -     * {@code 0}, and less than or equal to the {@linkplain #length() length}
130.1229 -     * of this sequence.
130.1230 -     *
130.1231 -     * @param      offset   the offset.
130.1232 -     * @param      d        a {@code double}.
130.1233 -     * @return     a reference to this object.
130.1234 -     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
130.1235 -     */
130.1236 -    public AbstractStringBuilder insert(int offset, double d) {
130.1237 -        return insert(offset, String.valueOf(d));
130.1238 -    }
130.1239 -
130.1240 -    /**
130.1241 -     * Returns the index within this string of the first occurrence of the
130.1242 -     * specified substring. The integer returned is the smallest value
130.1243 -     * <i>k</i> such that:
130.1244 -     * <blockquote><pre>
130.1245 -     * this.toString().startsWith(str, <i>k</i>)
130.1246 -     * </pre></blockquote>
130.1247 -     * is <code>true</code>.
130.1248 -     *
130.1249 -     * @param   str   any string.
130.1250 -     * @return  if the string argument occurs as a substring within this
130.1251 -     *          object, then the index of the first character of the first
130.1252 -     *          such substring is returned; if it does not occur as a
130.1253 -     *          substring, <code>-1</code> is returned.
130.1254 -     * @throws  java.lang.NullPointerException if <code>str</code> is
130.1255 -     *          <code>null</code>.
130.1256 -     */
130.1257 -    public int indexOf(String str) {
130.1258 -        return indexOf(str, 0);
130.1259 -    }
130.1260 -
130.1261 -    /**
130.1262 -     * Returns the index within this string of the first occurrence of the
130.1263 -     * specified substring, starting at the specified index.  The integer
130.1264 -     * returned is the smallest value <tt>k</tt> for which:
130.1265 -     * <blockquote><pre>
130.1266 -     *     k >= Math.min(fromIndex, str.length()) &&
130.1267 -     *                   this.toString().startsWith(str, k)
130.1268 -     * </pre></blockquote>
130.1269 -     * If no such value of <i>k</i> exists, then -1 is returned.
130.1270 -     *
130.1271 -     * @param   str         the substring for which to search.
130.1272 -     * @param   fromIndex   the index from which to start the search.
130.1273 -     * @return  the index within this string of the first occurrence of the
130.1274 -     *          specified substring, starting at the specified index.
130.1275 -     * @throws  java.lang.NullPointerException if <code>str</code> is
130.1276 -     *            <code>null</code>.
130.1277 -     */
130.1278 -    public int indexOf(String str, int fromIndex) {
130.1279 -        return toString().indexOf(str, fromIndex);
130.1280 -    }
130.1281 -
130.1282 -    /**
130.1283 -     * Returns the index within this string of the rightmost occurrence
130.1284 -     * of the specified substring.  The rightmost empty string "" is
130.1285 -     * considered to occur at the index value <code>this.length()</code>.
130.1286 -     * The returned index is the largest value <i>k</i> such that
130.1287 -     * <blockquote><pre>
130.1288 -     * this.toString().startsWith(str, k)
130.1289 -     * </pre></blockquote>
130.1290 -     * is true.
130.1291 -     *
130.1292 -     * @param   str   the substring to search for.
130.1293 -     * @return  if the string argument occurs one or more times as a substring
130.1294 -     *          within this object, then the index of the first character of
130.1295 -     *          the last such substring is returned. If it does not occur as
130.1296 -     *          a substring, <code>-1</code> is returned.
130.1297 -     * @throws  java.lang.NullPointerException  if <code>str</code> is
130.1298 -     *          <code>null</code>.
130.1299 -     */
130.1300 -    public int lastIndexOf(String str) {
130.1301 -        return lastIndexOf(str, count);
130.1302 -    }
130.1303 -
130.1304 -    /**
130.1305 -     * Returns the index within this string of the last occurrence of the
130.1306 -     * specified substring. The integer returned is the largest value <i>k</i>
130.1307 -     * such that:
130.1308 -     * <blockquote><pre>
130.1309 -     *     k <= Math.min(fromIndex, str.length()) &&
130.1310 -     *                   this.toString().startsWith(str, k)
130.1311 -     * </pre></blockquote>
130.1312 -     * If no such value of <i>k</i> exists, then -1 is returned.
130.1313 -     *
130.1314 -     * @param   str         the substring to search for.
130.1315 -     * @param   fromIndex   the index to start the search from.
130.1316 -     * @return  the index within this sequence of the last occurrence of the
130.1317 -     *          specified substring.
130.1318 -     * @throws  java.lang.NullPointerException if <code>str</code> is
130.1319 -     *          <code>null</code>.
130.1320 -     */
130.1321 -    public int lastIndexOf(String str, int fromIndex) {
130.1322 -        return String.lastIndexOf(value, 0, count,
130.1323 -                              str.toCharArray(), 0, str.length(), fromIndex);
130.1324 -    }
130.1325 -
130.1326 -    /**
130.1327 -     * Causes this character sequence to be replaced by the reverse of
130.1328 -     * the sequence. If there are any surrogate pairs included in the
130.1329 -     * sequence, these are treated as single characters for the
130.1330 -     * reverse operation. Thus, the order of the high-low surrogates
130.1331 -     * is never reversed.
130.1332 -     *
130.1333 -     * Let <i>n</i> be the character length of this character sequence
130.1334 -     * (not the length in <code>char</code> values) just prior to
130.1335 -     * execution of the <code>reverse</code> method. Then the
130.1336 -     * character at index <i>k</i> in the new character sequence is
130.1337 -     * equal to the character at index <i>n-k-1</i> in the old
130.1338 -     * character sequence.
130.1339 -     *
130.1340 -     * <p>Note that the reverse operation may result in producing
130.1341 -     * surrogate pairs that were unpaired low-surrogates and
130.1342 -     * high-surrogates before the operation. For example, reversing
130.1343 -     * "&#92;uDC00&#92;uD800" produces "&#92;uD800&#92;uDC00" which is
130.1344 -     * a valid surrogate pair.
130.1345 -     *
130.1346 -     * @return  a reference to this object.
130.1347 -     */
130.1348 -    public AbstractStringBuilder reverse() {
130.1349 -        boolean hasSurrogate = false;
130.1350 -        int n = count - 1;
130.1351 -        for (int j = (n-1) >> 1; j >= 0; --j) {
130.1352 -            char temp = value[j];
130.1353 -            char temp2 = value[n - j];
130.1354 -            if (!hasSurrogate) {
130.1355 -                hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
130.1356 -                    || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
130.1357 -            }
130.1358 -            value[j] = temp2;
130.1359 -            value[n - j] = temp;
130.1360 -        }
130.1361 -        if (hasSurrogate) {
130.1362 -            // Reverse back all valid surrogate pairs
130.1363 -            for (int i = 0; i < count - 1; i++) {
130.1364 -                char c2 = value[i];
130.1365 -                if (Character.isLowSurrogate(c2)) {
130.1366 -                    char c1 = value[i + 1];
130.1367 -                    if (Character.isHighSurrogate(c1)) {
130.1368 -                        value[i++] = c1;
130.1369 -                        value[i] = c2;
130.1370 -                    }
130.1371 -                }
130.1372 -            }
130.1373 -        }
130.1374 -        return this;
130.1375 -    }
130.1376 -
130.1377 -    /**
130.1378 -     * Returns a string representing the data in this sequence.
130.1379 -     * A new <code>String</code> object is allocated and initialized to
130.1380 -     * contain the character sequence currently represented by this
130.1381 -     * object. This <code>String</code> is then returned. Subsequent
130.1382 -     * changes to this sequence do not affect the contents of the
130.1383 -     * <code>String</code>.
130.1384 -     *
130.1385 -     * @return  a string representation of this sequence of characters.
130.1386 -     */
130.1387 -    public abstract String toString();
130.1388 -
130.1389 -    /**
130.1390 -     * Needed by <tt>String</tt> for the contentEquals method.
130.1391 -     */
130.1392 -    final char[] getValue() {
130.1393 -        return value;
130.1394 -    }
130.1395 -
130.1396 -    static char[] copyOfRange(char[] original, int from, int to) {
130.1397 -        int newLength = to - from;
130.1398 -        if (newLength < 0) {
130.1399 -            throw new IllegalArgumentException(from + " > " + to);
130.1400 -        }
130.1401 -        char[] copy = new char[newLength];
130.1402 -        System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
130.1403 -        return copy;
130.1404 -    }
130.1405 -
130.1406 -    // access system property
130.1407 -    static String getProperty(String nm) {
130.1408 -        return null;
130.1409 -    }
130.1410 -
130.1411 -    static char[] copyOf(char[] original, int newLength) {
130.1412 -        char[] copy = new char[newLength];
130.1413 -        System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
130.1414 -        return copy;
130.1415 -    }
130.1416 -    
130.1417 -}
   131.1 --- a/emul/mini/src/main/java/java/lang/Appendable.java	Mon Feb 25 19:00:08 2013 +0100
   131.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   131.3 @@ -1,121 +0,0 @@
   131.4 -/*
   131.5 - * Copyright (c) 2003, 2004, 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 java.io.IOException;
  131.32 -
  131.33 -/**
  131.34 - * An object to which <tt>char</tt> sequences and values can be appended.  The
  131.35 - * <tt>Appendable</tt> interface must be implemented by any class whose
  131.36 - * instances are intended to receive formatted output from a {@link
  131.37 - * java.util.Formatter}.
  131.38 - *
  131.39 - * <p> The characters to be appended should be valid Unicode characters as
  131.40 - * described in <a href="Character.html#unicode">Unicode Character
  131.41 - * Representation</a>.  Note that supplementary characters may be composed of
  131.42 - * multiple 16-bit <tt>char</tt> values.
  131.43 - *
  131.44 - * <p> Appendables are not necessarily safe for multithreaded access.  Thread
  131.45 - * safety is the responsibility of classes that extend and implement this
  131.46 - * interface.
  131.47 - *
  131.48 - * <p> Since this interface may be implemented by existing classes
  131.49 - * with different styles of error handling there is no guarantee that
  131.50 - * errors will be propagated to the invoker.
  131.51 - *
  131.52 - * @since 1.5
  131.53 - */
  131.54 -public interface Appendable {
  131.55 -
  131.56 -    /**
  131.57 -     * Appends the specified character sequence to this <tt>Appendable</tt>.
  131.58 -     *
  131.59 -     * <p> Depending on which class implements the character sequence
  131.60 -     * <tt>csq</tt>, the entire sequence may not be appended.  For
  131.61 -     * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
  131.62 -     * the subsequence to append is defined by the buffer's position and limit.
  131.63 -     *
  131.64 -     * @param  csq
  131.65 -     *         The character sequence to append.  If <tt>csq</tt> is
  131.66 -     *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
  131.67 -     *         appended to this Appendable.
  131.68 -     *
  131.69 -     * @return  A reference to this <tt>Appendable</tt>
  131.70 -     *
  131.71 -     * @throws  IOException
  131.72 -     *          If an I/O error occurs
  131.73 -     */
  131.74 -    Appendable append(CharSequence csq) throws IOException;
  131.75 -
  131.76 -    /**
  131.77 -     * Appends a subsequence of the specified character sequence to this
  131.78 -     * <tt>Appendable</tt>.
  131.79 -     *
  131.80 -     * <p> An invocation of this method of the form <tt>out.append(csq, start,
  131.81 -     * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
  131.82 -     * exactly the same way as the invocation
  131.83 -     *
  131.84 -     * <pre>
  131.85 -     *     out.append(csq.subSequence(start, end)) </pre>
  131.86 -     *
  131.87 -     * @param  csq
  131.88 -     *         The character sequence from which a subsequence will be
  131.89 -     *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
  131.90 -     *         will be appended as if <tt>csq</tt> contained the four
  131.91 -     *         characters <tt>"null"</tt>.
  131.92 -     *
  131.93 -     * @param  start
  131.94 -     *         The index of the first character in the subsequence
  131.95 -     *
  131.96 -     * @param  end
  131.97 -     *         The index of the character following the last character in the
  131.98 -     *         subsequence
  131.99 -     *
 131.100 -     * @return  A reference to this <tt>Appendable</tt>
 131.101 -     *
 131.102 -     * @throws  IndexOutOfBoundsException
 131.103 -     *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
 131.104 -     *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
 131.105 -     *          <tt>csq.length()</tt>
 131.106 -     *
 131.107 -     * @throws  IOException
 131.108 -     *          If an I/O error occurs
 131.109 -     */
 131.110 -    Appendable append(CharSequence csq, int start, int end) throws IOException;
 131.111 -
 131.112 -    /**
 131.113 -     * Appends the specified character to this <tt>Appendable</tt>.
 131.114 -     *
 131.115 -     * @param  c
 131.116 -     *         The character to append
 131.117 -     *
 131.118 -     * @return  A reference to this <tt>Appendable</tt>
 131.119 -     *
 131.120 -     * @throws  IOException
 131.121 -     *          If an I/O error occurs
 131.122 -     */
 131.123 -    Appendable append(char c) throws IOException;
 131.124 -}
   132.1 --- a/emul/mini/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java	Mon Feb 25 19:00:08 2013 +0100
   132.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   132.3 @@ -1,67 +0,0 @@
   132.4 -/*
   132.5 - * Copyright (c) 1994, 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 to indicate that an array has been accessed with an
  132.33 - * illegal index. The index is either negative or greater than or
  132.34 - * equal to the size of the array.
  132.35 - *
  132.36 - * @author  unascribed
  132.37 - * @since   JDK1.0
  132.38 - */
  132.39 -public
  132.40 -class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
  132.41 -    private static final long serialVersionUID = -5116101128118950844L;
  132.42 -
  132.43 -    /**
  132.44 -     * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
  132.45 -     * detail message.
  132.46 -     */
  132.47 -    public ArrayIndexOutOfBoundsException() {
  132.48 -        super();
  132.49 -    }
  132.50 -
  132.51 -    /**
  132.52 -     * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
  132.53 -     * class with an argument indicating the illegal index.
  132.54 -     *
  132.55 -     * @param   index   the illegal index.
  132.56 -     */
  132.57 -    public ArrayIndexOutOfBoundsException(int index) {
  132.58 -        super("Array index out of range: " + index);
  132.59 -    }
  132.60 -
  132.61 -    /**
  132.62 -     * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
  132.63 -     * with the specified detail message.
  132.64 -     *
  132.65 -     * @param   s   the detail message.
  132.66 -     */
  132.67 -    public ArrayIndexOutOfBoundsException(String s) {
  132.68 -        super(s);
  132.69 -    }
  132.70 -}
   133.1 --- a/emul/mini/src/main/java/java/lang/ArrayStoreException.java	Mon Feb 25 19:00:08 2013 +0100
   133.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   133.3 @@ -1,60 +0,0 @@
   133.4 -/*
   133.5 - * Copyright (c) 1995, 2008, 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 - * Thrown to indicate that an attempt has been made to store the
  133.33 - * wrong type of object into an array of objects. For example, the
  133.34 - * following code generates an <code>ArrayStoreException</code>:
  133.35 - * <p><blockquote><pre>
  133.36 - *     Object x[] = new String[3];
  133.37 - *     x[0] = new Integer(0);
  133.38 - * </pre></blockquote>
  133.39 - *
  133.40 - * @author  unascribed
  133.41 - * @since   JDK1.0
  133.42 - */
  133.43 -public
  133.44 -class ArrayStoreException extends RuntimeException {
  133.45 -    private static final long serialVersionUID = -4522193890499838241L;
  133.46 -
  133.47 -    /**
  133.48 -     * Constructs an <code>ArrayStoreException</code> with no detail message.
  133.49 -     */
  133.50 -    public ArrayStoreException() {
  133.51 -        super();
  133.52 -    }
  133.53 -
  133.54 -    /**
  133.55 -     * Constructs an <code>ArrayStoreException</code> with the specified
  133.56 -     * detail message.
  133.57 -     *
  133.58 -     * @param   s   the detail message.
  133.59 -     */
  133.60 -    public ArrayStoreException(String s) {
  133.61 -        super(s);
  133.62 -    }
  133.63 -}
   134.1 --- a/emul/mini/src/main/java/java/lang/AssertionError.java	Mon Feb 25 19:00:08 2013 +0100
   134.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   134.3 @@ -1,167 +0,0 @@
   134.4 -/*
   134.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   134.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   134.7 - *
   134.8 - * This code is free software; you can redistribute it and/or modify it
   134.9 - * under the terms of the GNU General Public License version 2 only, as
  134.10 - * published by the Free Software Foundation.  Oracle designates this
  134.11 - * particular file as subject to the "Classpath" exception as provided
  134.12 - * by Oracle in the LICENSE file that accompanied this code.
  134.13 - *
  134.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  134.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  134.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  134.17 - * version 2 for more details (a copy is included in the LICENSE file that
  134.18 - * accompanied this code).
  134.19 - *
  134.20 - * You should have received a copy of the GNU General Public License version
  134.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  134.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  134.23 - *
  134.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  134.25 - * or visit www.oracle.com if you need additional information or have any
  134.26 - * questions.
  134.27 - */
  134.28 -
  134.29 -package java.lang;
  134.30 -
  134.31 -/**
  134.32 - * Thrown to indicate that an assertion has failed.
  134.33 - *
  134.34 - * <p>The seven one-argument public constructors provided by this
  134.35 - * class ensure that the assertion error returned by the invocation:
  134.36 - * <pre>
  134.37 - *     new AssertionError(<i>expression</i>)
  134.38 - * </pre>
  134.39 - * has as its detail message the <i>string conversion</i> of
  134.40 - * <i>expression</i> (as defined in section 15.18.1.1 of
  134.41 - * <cite>The Java&trade; Language Specification</cite>),
  134.42 - * regardless of the type of <i>expression</i>.
  134.43 - *
  134.44 - * @since   1.4
  134.45 - */
  134.46 -public class AssertionError extends Error {
  134.47 -    private static final long serialVersionUID = -5013299493970297370L;
  134.48 -
  134.49 -    /**
  134.50 -     * Constructs an AssertionError with no detail message.
  134.51 -     */
  134.52 -    public AssertionError() {
  134.53 -    }
  134.54 -
  134.55 -    /**
  134.56 -     * This internal constructor does no processing on its string argument,
  134.57 -     * even if it is a null reference.  The public constructors will
  134.58 -     * never call this constructor with a null argument.
  134.59 -     */
  134.60 -    private AssertionError(String detailMessage) {
  134.61 -        super(detailMessage);
  134.62 -    }
  134.63 -
  134.64 -    /**
  134.65 -     * Constructs an AssertionError with its detail message derived
  134.66 -     * from the specified object, which is converted to a string as
  134.67 -     * defined in section 15.18.1.1 of
  134.68 -     * <cite>The Java&trade; Language Specification</cite>.
  134.69 -     *<p>
  134.70 -     * If the specified object is an instance of {@code Throwable}, it
  134.71 -     * becomes the <i>cause</i> of the newly constructed assertion error.
  134.72 -     *
  134.73 -     * @param detailMessage value to be used in constructing detail message
  134.74 -     * @see   Throwable#getCause()
  134.75 -     */
  134.76 -    public AssertionError(Object detailMessage) {
  134.77 -        this("" +  detailMessage);
  134.78 -        if (detailMessage instanceof Throwable)
  134.79 -            initCause((Throwable) detailMessage);
  134.80 -    }
  134.81 -
  134.82 -    /**
  134.83 -     * Constructs an AssertionError with its detail message derived
  134.84 -     * from the specified <code>boolean</code>, which is converted to
  134.85 -     * a string as defined in section 15.18.1.1 of
  134.86 -     * <cite>The Java&trade; Language Specification</cite>.
  134.87 -     *
  134.88 -     * @param detailMessage value to be used in constructing detail message
  134.89 -     */
  134.90 -    public AssertionError(boolean detailMessage) {
  134.91 -        this("" +  detailMessage);
  134.92 -    }
  134.93 -
  134.94 -    /**
  134.95 -     * Constructs an AssertionError with its detail message derived
  134.96 -     * from the specified <code>char</code>, which is converted to a
  134.97 -     * string as defined in section 15.18.1.1 of
  134.98 -     * <cite>The Java&trade; Language Specification</cite>.
  134.99 -     *
 134.100 -     * @param detailMessage value to be used in constructing detail message
 134.101 -     */
 134.102 -    public AssertionError(char detailMessage) {
 134.103 -        this("" +  detailMessage);
 134.104 -    }
 134.105 -
 134.106 -    /**
 134.107 -     * Constructs an AssertionError with its detail message derived
 134.108 -     * from the specified <code>int</code>, which is converted to a
 134.109 -     * string as defined in section 15.18.1.1 of
 134.110 -     * <cite>The Java&trade; Language Specification</cite>.
 134.111 -     *
 134.112 -     * @param detailMessage value to be used in constructing detail message
 134.113 -     */
 134.114 -    public AssertionError(int detailMessage) {
 134.115 -        this("" +  detailMessage);
 134.116 -    }
 134.117 -
 134.118 -    /**
 134.119 -     * Constructs an AssertionError with its detail message derived
 134.120 -     * from the specified <code>long</code>, which is converted to a
 134.121 -     * string as defined in section 15.18.1.1 of
 134.122 -     * <cite>The Java&trade; Language Specification</cite>.
 134.123 -     *
 134.124 -     * @param detailMessage value to be used in constructing detail message
 134.125 -     */
 134.126 -    public AssertionError(long detailMessage) {
 134.127 -        this("" +  detailMessage);
 134.128 -    }
 134.129 -
 134.130 -    /**
 134.131 -     * Constructs an AssertionError with its detail message derived
 134.132 -     * from the specified <code>float</code>, which is converted to a
 134.133 -     * string as defined in section 15.18.1.1 of
 134.134 -     * <cite>The Java&trade; Language Specification</cite>.
 134.135 -     *
 134.136 -     * @param detailMessage value to be used in constructing detail message
 134.137 -     */
 134.138 -    public AssertionError(float detailMessage) {
 134.139 -        this("" +  detailMessage);
 134.140 -    }
 134.141 -
 134.142 -    /**
 134.143 -     * Constructs an AssertionError with its detail message derived
 134.144 -     * from the specified <code>double</code>, which is converted to a
 134.145 -     * string as defined in section 15.18.1.1 of
 134.146 -     * <cite>The Java&trade; Language Specification</cite>.
 134.147 -     *
 134.148 -     * @param detailMessage value to be used in constructing detail message
 134.149 -     */
 134.150 -    public AssertionError(double detailMessage) {
 134.151 -        this("" +  detailMessage);
 134.152 -    }
 134.153 -
 134.154 -    /**
 134.155 -     * Constructs a new {@code AssertionError} with the specified
 134.156 -     * detail message and cause.
 134.157 -     *
 134.158 -     * <p>Note that the detail message associated with
 134.159 -     * {@code cause} is <i>not</i> automatically incorporated in
 134.160 -     * this error's detail message.
 134.161 -     *
 134.162 -     * @param  message the detail message, may be {@code null}
 134.163 -     * @param  cause the cause, may be {@code null}
 134.164 -     *
 134.165 -     * @since 1.7
 134.166 -     */
 134.167 -    public AssertionError(String message, Throwable cause) {
 134.168 -        super(message, cause);
 134.169 -    }
 134.170 -}
   135.1 --- a/emul/mini/src/main/java/java/lang/AutoCloseable.java	Mon Feb 25 19:00:08 2013 +0100
   135.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   135.3 @@ -1,72 +0,0 @@
   135.4 -/*
   135.5 - * Copyright (c) 2009, 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 -/**
  135.32 - * A resource that must be closed when it is no longer needed.
  135.33 - *
  135.34 - * @author Josh Bloch
  135.35 - * @since 1.7
  135.36 - */
  135.37 -public interface AutoCloseable {
  135.38 -    /**
  135.39 -     * Closes this resource, relinquishing any underlying resources.
  135.40 -     * This method is invoked automatically on objects managed by the
  135.41 -     * {@code try}-with-resources statement.
  135.42 -     *
  135.43 -     * <p>While this interface method is declared to throw {@code
  135.44 -     * Exception}, implementers are <em>strongly</em> encouraged to
  135.45 -     * declare concrete implementations of the {@code close} method to
  135.46 -     * throw more specific exceptions, or to throw no exception at all
  135.47 -     * if the close operation cannot fail.
  135.48 -     *
  135.49 -     * <p><em>Implementers of this interface are also strongly advised
  135.50 -     * to not have the {@code close} method throw {@link
  135.51 -     * InterruptedException}.</em>
  135.52 -     *
  135.53 -     * This exception interacts with a thread's interrupted status,
  135.54 -     * and runtime misbehavior is likely to occur if an {@code
  135.55 -     * InterruptedException} is {@linkplain Throwable#addSuppressed
  135.56 -     * suppressed}.
  135.57 -     *
  135.58 -     * More generally, if it would cause problems for an
  135.59 -     * exception to be suppressed, the {@code AutoCloseable.close}
  135.60 -     * method should not throw it.
  135.61 -     *
  135.62 -     * <p>Note that unlike the {@link java.io.Closeable#close close}
  135.63 -     * method of {@link java.io.Closeable}, this {@code close} method
  135.64 -     * is <em>not</em> required to be idempotent.  In other words,
  135.65 -     * calling this {@code close} method more than once may have some
  135.66 -     * visible side effect, unlike {@code Closeable.close} which is
  135.67 -     * required to have no effect if called more than once.
  135.68 -     *
  135.69 -     * However, implementers of this interface are strongly encouraged
  135.70 -     * to make their {@code close} methods idempotent.
  135.71 -     *
  135.72 -     * @throws Exception if this resource cannot be closed
  135.73 -     */
  135.74 -    void close() throws Exception;
  135.75 -}
   136.1 --- a/emul/mini/src/main/java/java/lang/Boolean.java	Mon Feb 25 19:00:08 2013 +0100
   136.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   136.3 @@ -1,282 +0,0 @@
   136.4 -/*
   136.5 - * Copyright (c) 1994, 2006, 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 - * The Boolean class wraps a value of the primitive type
  136.33 - * {@code boolean} in an object. An object of type
  136.34 - * {@code Boolean} contains a single field whose type is
  136.35 - * {@code boolean}.
  136.36 - * <p>
  136.37 - * In addition, this class provides many methods for
  136.38 - * converting a {@code boolean} to a {@code String} and a
  136.39 - * {@code String} to a {@code boolean}, as well as other
  136.40 - * constants and methods useful when dealing with a
  136.41 - * {@code boolean}.
  136.42 - *
  136.43 - * @author  Arthur van Hoff
  136.44 - * @since   JDK1.0
  136.45 - */
  136.46 -public final class Boolean implements java.io.Serializable,
  136.47 -                                      Comparable<Boolean>
  136.48 -{
  136.49 -    /**
  136.50 -     * The {@code Boolean} object corresponding to the primitive
  136.51 -     * value {@code true}.
  136.52 -     */
  136.53 -    public static final Boolean TRUE = new Boolean(true);
  136.54 -
  136.55 -    /**
  136.56 -     * The {@code Boolean} object corresponding to the primitive
  136.57 -     * value {@code false}.
  136.58 -     */
  136.59 -    public static final Boolean FALSE = new Boolean(false);
  136.60 -
  136.61 -    /**
  136.62 -     * The Class object representing the primitive type boolean.
  136.63 -     *
  136.64 -     * @since   JDK1.1
  136.65 -     */
  136.66 -    public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
  136.67 -
  136.68 -    /**
  136.69 -     * The value of the Boolean.
  136.70 -     *
  136.71 -     * @serial
  136.72 -     */
  136.73 -    private final boolean value;
  136.74 -
  136.75 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  136.76 -    private static final long serialVersionUID = -3665804199014368530L;
  136.77 -
  136.78 -    /**
  136.79 -     * Allocates a {@code Boolean} object representing the
  136.80 -     * {@code value} argument.
  136.81 -     *
  136.82 -     * <p><b>Note: It is rarely appropriate to use this constructor.
  136.83 -     * Unless a <i>new</i> instance is required, the static factory
  136.84 -     * {@link #valueOf(boolean)} is generally a better choice. It is
  136.85 -     * likely to yield significantly better space and time performance.</b>
  136.86 -     *
  136.87 -     * @param   value   the value of the {@code Boolean}.
  136.88 -     */
  136.89 -    public Boolean(boolean value) {
  136.90 -        this.value = value;
  136.91 -    }
  136.92 -
  136.93 -    /**
  136.94 -     * Allocates a {@code Boolean} object representing the value
  136.95 -     * {@code true} if the string argument is not {@code null}
  136.96 -     * and is equal, ignoring case, to the string {@code "true"}.
  136.97 -     * Otherwise, allocate a {@code Boolean} object representing the
  136.98 -     * value {@code false}. Examples:<p>
  136.99 -     * {@code new Boolean("True")} produces a {@code Boolean} object
 136.100 -     * that represents {@code true}.<br>
 136.101 -     * {@code new Boolean("yes")} produces a {@code Boolean} object
 136.102 -     * that represents {@code false}.
 136.103 -     *
 136.104 -     * @param   s   the string to be converted to a {@code Boolean}.
 136.105 -     */
 136.106 -    public Boolean(String s) {
 136.107 -        this(toBoolean(s));
 136.108 -    }
 136.109 -
 136.110 -    /**
 136.111 -     * Parses the string argument as a boolean.  The {@code boolean}
 136.112 -     * returned represents the value {@code true} if the string argument
 136.113 -     * is not {@code null} and is equal, ignoring case, to the string
 136.114 -     * {@code "true"}. <p>
 136.115 -     * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
 136.116 -     * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
 136.117 -     *
 136.118 -     * @param      s   the {@code String} containing the boolean
 136.119 -     *                 representation to be parsed
 136.120 -     * @return     the boolean represented by the string argument
 136.121 -     * @since 1.5
 136.122 -     */
 136.123 -    public static boolean parseBoolean(String s) {
 136.124 -        return toBoolean(s);
 136.125 -    }
 136.126 -
 136.127 -    /**
 136.128 -     * Returns the value of this {@code Boolean} object as a boolean
 136.129 -     * primitive.
 136.130 -     *
 136.131 -     * @return  the primitive {@code boolean} value of this object.
 136.132 -     */
 136.133 -    public boolean booleanValue() {
 136.134 -        return value;
 136.135 -    }
 136.136 -
 136.137 -    /**
 136.138 -     * Returns a {@code Boolean} instance representing the specified
 136.139 -     * {@code boolean} value.  If the specified {@code boolean} value
 136.140 -     * is {@code true}, this method returns {@code Boolean.TRUE};
 136.141 -     * if it is {@code false}, this method returns {@code Boolean.FALSE}.
 136.142 -     * If a new {@code Boolean} instance is not required, this method
 136.143 -     * should generally be used in preference to the constructor
 136.144 -     * {@link #Boolean(boolean)}, as this method is likely to yield
 136.145 -     * significantly better space and time performance.
 136.146 -     *
 136.147 -     * @param  b a boolean value.
 136.148 -     * @return a {@code Boolean} instance representing {@code b}.
 136.149 -     * @since  1.4
 136.150 -     */
 136.151 -    public static Boolean valueOf(boolean b) {
 136.152 -        return (b ? TRUE : FALSE);
 136.153 -    }
 136.154 -
 136.155 -    /**
 136.156 -     * Returns a {@code Boolean} with a value represented by the
 136.157 -     * specified string.  The {@code Boolean} returned represents a
 136.158 -     * true value if the string argument is not {@code null}
 136.159 -     * and is equal, ignoring case, to the string {@code "true"}.
 136.160 -     *
 136.161 -     * @param   s   a string.
 136.162 -     * @return  the {@code Boolean} value represented by the string.
 136.163 -     */
 136.164 -    public static Boolean valueOf(String s) {
 136.165 -        return toBoolean(s) ? TRUE : FALSE;
 136.166 -    }
 136.167 -
 136.168 -    /**
 136.169 -     * Returns a {@code String} object representing the specified
 136.170 -     * boolean.  If the specified boolean is {@code true}, then
 136.171 -     * the string {@code "true"} will be returned, otherwise the
 136.172 -     * string {@code "false"} will be returned.
 136.173 -     *
 136.174 -     * @param b the boolean to be converted
 136.175 -     * @return the string representation of the specified {@code boolean}
 136.176 -     * @since 1.4
 136.177 -     */
 136.178 -    public static String toString(boolean b) {
 136.179 -        return b ? "true" : "false";
 136.180 -    }
 136.181 -
 136.182 -    /**
 136.183 -     * Returns a {@code String} object representing this Boolean's
 136.184 -     * value.  If this object represents the value {@code true},
 136.185 -     * a string equal to {@code "true"} is returned. Otherwise, a
 136.186 -     * string equal to {@code "false"} is returned.
 136.187 -     *
 136.188 -     * @return  a string representation of this object.
 136.189 -     */
 136.190 -    public String toString() {
 136.191 -        return value ? "true" : "false";
 136.192 -    }
 136.193 -
 136.194 -    /**
 136.195 -     * Returns a hash code for this {@code Boolean} object.
 136.196 -     *
 136.197 -     * @return  the integer {@code 1231} if this object represents
 136.198 -     * {@code true}; returns the integer {@code 1237} if this
 136.199 -     * object represents {@code false}.
 136.200 -     */
 136.201 -    public int hashCode() {
 136.202 -        return value ? 1231 : 1237;
 136.203 -    }
 136.204 -
 136.205 -    /**
 136.206 -     * Returns {@code true} if and only if the argument is not
 136.207 -     * {@code null} and is a {@code Boolean} object that
 136.208 -     * represents the same {@code boolean} value as this object.
 136.209 -     *
 136.210 -     * @param   obj   the object to compare with.
 136.211 -     * @return  {@code true} if the Boolean objects represent the
 136.212 -     *          same value; {@code false} otherwise.
 136.213 -     */
 136.214 -    public boolean equals(Object obj) {
 136.215 -        if (obj instanceof Boolean) {
 136.216 -            return value == ((Boolean)obj).booleanValue();
 136.217 -        }
 136.218 -        return false;
 136.219 -    }
 136.220 -
 136.221 -    /**
 136.222 -     * Returns {@code true} if and only if the system property
 136.223 -     * named by the argument exists and is equal to the string
 136.224 -     * {@code "true"}. (Beginning with version 1.0.2 of the
 136.225 -     * Java<small><sup>TM</sup></small> platform, the test of
 136.226 -     * this string is case insensitive.) A system property is accessible
 136.227 -     * through {@code getProperty}, a method defined by the
 136.228 -     * {@code System} class.
 136.229 -     * <p>
 136.230 -     * If there is no property with the specified name, or if the specified
 136.231 -     * name is empty or null, then {@code false} is returned.
 136.232 -     *
 136.233 -     * @param   name   the system property name.
 136.234 -     * @return  the {@code boolean} value of the system property.
 136.235 -     * @see     java.lang.System#getProperty(java.lang.String)
 136.236 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 136.237 -     */
 136.238 -    public static boolean getBoolean(String name) {
 136.239 -        boolean result = false;
 136.240 -        try {
 136.241 -            result = toBoolean(AbstractStringBuilder.getProperty(name));
 136.242 -        } catch (IllegalArgumentException e) {
 136.243 -        } catch (NullPointerException e) {
 136.244 -        }
 136.245 -        return result;
 136.246 -    }
 136.247 -
 136.248 -    /**
 136.249 -     * Compares this {@code Boolean} instance with another.
 136.250 -     *
 136.251 -     * @param   b the {@code Boolean} instance to be compared
 136.252 -     * @return  zero if this object represents the same boolean value as the
 136.253 -     *          argument; a positive value if this object represents true
 136.254 -     *          and the argument represents false; and a negative value if
 136.255 -     *          this object represents false and the argument represents true
 136.256 -     * @throws  NullPointerException if the argument is {@code null}
 136.257 -     * @see     Comparable
 136.258 -     * @since  1.5
 136.259 -     */
 136.260 -    public int compareTo(Boolean b) {
 136.261 -        return compare(this.value, b.value);
 136.262 -    }
 136.263 -
 136.264 -    /**
 136.265 -     * Compares two {@code boolean} values.
 136.266 -     * The value returned is identical to what would be returned by:
 136.267 -     * <pre>
 136.268 -     *    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
 136.269 -     * </pre>
 136.270 -     *
 136.271 -     * @param  x the first {@code boolean} to compare
 136.272 -     * @param  y the second {@code boolean} to compare
 136.273 -     * @return the value {@code 0} if {@code x == y};
 136.274 -     *         a value less than {@code 0} if {@code !x && y}; and
 136.275 -     *         a value greater than {@code 0} if {@code x && !y}
 136.276 -     * @since 1.7
 136.277 -     */
 136.278 -    public static int compare(boolean x, boolean y) {
 136.279 -        return (x == y) ? 0 : (x ? 1 : -1);
 136.280 -    }
 136.281 -
 136.282 -    private static boolean toBoolean(String name) {
 136.283 -        return ((name != null) && name.equalsIgnoreCase("true"));
 136.284 -    }
 136.285 -}
   137.1 --- a/emul/mini/src/main/java/java/lang/Byte.java	Mon Feb 25 19:00:08 2013 +0100
   137.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   137.3 @@ -1,452 +0,0 @@
   137.4 -/*
   137.5 - * Copyright (c) 1996, 2009, 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 - *
  137.33 - * The {@code Byte} class wraps a value of primitive type {@code byte}
  137.34 - * in an object.  An object of type {@code Byte} contains a single
  137.35 - * field whose type is {@code byte}.
  137.36 - *
  137.37 - * <p>In addition, this class provides several methods for converting
  137.38 - * a {@code byte} to a {@code String} and a {@code String} to a {@code
  137.39 - * byte}, as well as other constants and methods useful when dealing
  137.40 - * with a {@code byte}.
  137.41 - *
  137.42 - * @author  Nakul Saraiya
  137.43 - * @author  Joseph D. Darcy
  137.44 - * @see     java.lang.Number
  137.45 - * @since   JDK1.1
  137.46 - */
  137.47 -public final class Byte extends Number implements Comparable<Byte> {
  137.48 -
  137.49 -    /**
  137.50 -     * A constant holding the minimum value a {@code byte} can
  137.51 -     * have, -2<sup>7</sup>.
  137.52 -     */
  137.53 -    public static final byte   MIN_VALUE = -128;
  137.54 -
  137.55 -    /**
  137.56 -     * A constant holding the maximum value a {@code byte} can
  137.57 -     * have, 2<sup>7</sup>-1.
  137.58 -     */
  137.59 -    public static final byte   MAX_VALUE = 127;
  137.60 -
  137.61 -    /**
  137.62 -     * The {@code Class} instance representing the primitive type
  137.63 -     * {@code byte}.
  137.64 -     */
  137.65 -    public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
  137.66 -
  137.67 -    /**
  137.68 -     * Returns a new {@code String} object representing the
  137.69 -     * specified {@code byte}. The radix is assumed to be 10.
  137.70 -     *
  137.71 -     * @param b the {@code byte} to be converted
  137.72 -     * @return the string representation of the specified {@code byte}
  137.73 -     * @see java.lang.Integer#toString(int)
  137.74 -     */
  137.75 -    public static String toString(byte b) {
  137.76 -        return Integer.toString((int)b, 10);
  137.77 -    }
  137.78 -
  137.79 -    private static class ByteCache {
  137.80 -        private ByteCache(){}
  137.81 -
  137.82 -        static final Byte cache[] = new Byte[-(-128) + 127 + 1];
  137.83 -
  137.84 -        static {
  137.85 -            for(int i = 0; i < cache.length; i++)
  137.86 -                cache[i] = new Byte((byte)(i - 128));
  137.87 -        }
  137.88 -    }
  137.89 -
  137.90 -    /**
  137.91 -     * Returns a {@code Byte} instance representing the specified
  137.92 -     * {@code byte} value.
  137.93 -     * If a new {@code Byte} instance is not required, this method
  137.94 -     * should generally be used in preference to the constructor
  137.95 -     * {@link #Byte(byte)}, as this method is likely to yield
  137.96 -     * significantly better space and time performance since
  137.97 -     * all byte values are cached.
  137.98 -     *
  137.99 -     * @param  b a byte value.
 137.100 -     * @return a {@code Byte} instance representing {@code b}.
 137.101 -     * @since  1.5
 137.102 -     */
 137.103 -    public static Byte valueOf(byte b) {
 137.104 -        final int offset = 128;
 137.105 -        return ByteCache.cache[(int)b + offset];
 137.106 -    }
 137.107 -
 137.108 -    /**
 137.109 -     * Parses the string argument as a signed {@code byte} in the
 137.110 -     * radix specified by the second argument. The characters in the
 137.111 -     * string must all be digits, of the specified radix (as
 137.112 -     * determined by whether {@link java.lang.Character#digit(char,
 137.113 -     * int)} returns a nonnegative value) except that the first
 137.114 -     * character may be an ASCII minus sign {@code '-'}
 137.115 -     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 137.116 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 137.117 -     * indicate a positive value.  The resulting {@code byte} value is
 137.118 -     * returned.
 137.119 -     *
 137.120 -     * <p>An exception of type {@code NumberFormatException} is
 137.121 -     * thrown if any of the following situations occurs:
 137.122 -     * <ul>
 137.123 -     * <li> The first argument is {@code null} or is a string of
 137.124 -     * length zero.
 137.125 -     *
 137.126 -     * <li> The radix is either smaller than {@link
 137.127 -     * java.lang.Character#MIN_RADIX} or larger than {@link
 137.128 -     * java.lang.Character#MAX_RADIX}.
 137.129 -     *
 137.130 -     * <li> Any character of the string is not a digit of the
 137.131 -     * specified radix, except that the first character may be a minus
 137.132 -     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 137.133 -     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 137.134 -     * string is longer than length 1.
 137.135 -     *
 137.136 -     * <li> The value represented by the string is not a value of type
 137.137 -     * {@code byte}.
 137.138 -     * </ul>
 137.139 -     *
 137.140 -     * @param s         the {@code String} containing the
 137.141 -     *                  {@code byte}
 137.142 -     *                  representation to be parsed
 137.143 -     * @param radix     the radix to be used while parsing {@code s}
 137.144 -     * @return          the {@code byte} value represented by the string
 137.145 -     *                   argument in the specified radix
 137.146 -     * @throws          NumberFormatException If the string does
 137.147 -     *                  not contain a parsable {@code byte}.
 137.148 -     */
 137.149 -    public static byte parseByte(String s, int radix)
 137.150 -        throws NumberFormatException {
 137.151 -        int i = Integer.parseInt(s, radix);
 137.152 -        if (i < MIN_VALUE || i > MAX_VALUE)
 137.153 -            throw new NumberFormatException(
 137.154 -                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 137.155 -        return (byte)i;
 137.156 -    }
 137.157 -
 137.158 -    /**
 137.159 -     * Parses the string argument as a signed decimal {@code
 137.160 -     * byte}. The characters in the string must all be decimal digits,
 137.161 -     * except that the first character may be an ASCII minus sign
 137.162 -     * {@code '-'} (<code>'&#92;u002D'</code>) to indicate a negative
 137.163 -     * value or an ASCII plus sign {@code '+'}
 137.164 -     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 137.165 -     * resulting {@code byte} value is returned, exactly as if the
 137.166 -     * argument and the radix 10 were given as arguments to the {@link
 137.167 -     * #parseByte(java.lang.String, int)} method.
 137.168 -     *
 137.169 -     * @param s         a {@code String} containing the
 137.170 -     *                  {@code byte} representation to be parsed
 137.171 -     * @return          the {@code byte} value represented by the
 137.172 -     *                  argument in decimal
 137.173 -     * @throws          NumberFormatException if the string does not
 137.174 -     *                  contain a parsable {@code byte}.
 137.175 -     */
 137.176 -    public static byte parseByte(String s) throws NumberFormatException {
 137.177 -        return parseByte(s, 10);
 137.178 -    }
 137.179 -
 137.180 -    /**
 137.181 -     * Returns a {@code Byte} object holding the value
 137.182 -     * extracted from the specified {@code String} when parsed
 137.183 -     * with the radix given by the second argument. The first argument
 137.184 -     * is interpreted as representing a signed {@code byte} in
 137.185 -     * the radix specified by the second argument, exactly as if the
 137.186 -     * argument were given to the {@link #parseByte(java.lang.String,
 137.187 -     * int)} method. The result is a {@code Byte} object that
 137.188 -     * represents the {@code byte} value specified by the string.
 137.189 -     *
 137.190 -     * <p> In other words, this method returns a {@code Byte} object
 137.191 -     * equal to the value of:
 137.192 -     *
 137.193 -     * <blockquote>
 137.194 -     * {@code new Byte(Byte.parseByte(s, radix))}
 137.195 -     * </blockquote>
 137.196 -     *
 137.197 -     * @param s         the string to be parsed
 137.198 -     * @param radix     the radix to be used in interpreting {@code s}
 137.199 -     * @return          a {@code Byte} object holding the value
 137.200 -     *                  represented by the string argument in the
 137.201 -     *                  specified radix.
 137.202 -     * @throws          NumberFormatException If the {@code String} does
 137.203 -     *                  not contain a parsable {@code byte}.
 137.204 -     */
 137.205 -    public static Byte valueOf(String s, int radix)
 137.206 -        throws NumberFormatException {
 137.207 -        return valueOf(parseByte(s, radix));
 137.208 -    }
 137.209 -
 137.210 -    /**
 137.211 -     * Returns a {@code Byte} object holding the value
 137.212 -     * given by the specified {@code String}. The argument is
 137.213 -     * interpreted as representing a signed decimal {@code byte},
 137.214 -     * exactly as if the argument were given to the {@link
 137.215 -     * #parseByte(java.lang.String)} method. The result is a
 137.216 -     * {@code Byte} object that represents the {@code byte}
 137.217 -     * value specified by the string.
 137.218 -     *
 137.219 -     * <p> In other words, this method returns a {@code Byte} object
 137.220 -     * equal to the value of:
 137.221 -     *
 137.222 -     * <blockquote>
 137.223 -     * {@code new Byte(Byte.parseByte(s))}
 137.224 -     * </blockquote>
 137.225 -     *
 137.226 -     * @param s         the string to be parsed
 137.227 -     * @return          a {@code Byte} object holding the value
 137.228 -     *                  represented by the string argument
 137.229 -     * @throws          NumberFormatException If the {@code String} does
 137.230 -     *                  not contain a parsable {@code byte}.
 137.231 -     */
 137.232 -    public static Byte valueOf(String s) throws NumberFormatException {
 137.233 -        return valueOf(s, 10);
 137.234 -    }
 137.235 -
 137.236 -    /**
 137.237 -     * Decodes a {@code String} into a {@code Byte}.
 137.238 -     * Accepts decimal, hexadecimal, and octal numbers given by
 137.239 -     * the following grammar:
 137.240 -     *
 137.241 -     * <blockquote>
 137.242 -     * <dl>
 137.243 -     * <dt><i>DecodableString:</i>
 137.244 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 137.245 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 137.246 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 137.247 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 137.248 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 137.249 -     * <p>
 137.250 -     * <dt><i>Sign:</i>
 137.251 -     * <dd>{@code -}
 137.252 -     * <dd>{@code +}
 137.253 -     * </dl>
 137.254 -     * </blockquote>
 137.255 -     *
 137.256 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 137.257 -     * are as defined in section 3.10.1 of
 137.258 -     * <cite>The Java&trade; Language Specification</cite>,
 137.259 -     * except that underscores are not accepted between digits.
 137.260 -     *
 137.261 -     * <p>The sequence of characters following an optional
 137.262 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 137.263 -     * "{@code #}", or leading zero) is parsed as by the {@code
 137.264 -     * Byte.parseByte} method with the indicated radix (10, 16, or 8).
 137.265 -     * This sequence of characters must represent a positive value or
 137.266 -     * a {@link NumberFormatException} will be thrown.  The result is
 137.267 -     * negated if first character of the specified {@code String} is
 137.268 -     * the minus sign.  No whitespace characters are permitted in the
 137.269 -     * {@code String}.
 137.270 -     *
 137.271 -     * @param     nm the {@code String} to decode.
 137.272 -     * @return   a {@code Byte} object holding the {@code byte}
 137.273 -     *          value represented by {@code nm}
 137.274 -     * @throws  NumberFormatException  if the {@code String} does not
 137.275 -     *            contain a parsable {@code byte}.
 137.276 -     * @see java.lang.Byte#parseByte(java.lang.String, int)
 137.277 -     */
 137.278 -    public static Byte decode(String nm) throws NumberFormatException {
 137.279 -        int i = Integer.decode(nm);
 137.280 -        if (i < MIN_VALUE || i > MAX_VALUE)
 137.281 -            throw new NumberFormatException(
 137.282 -                    "Value " + i + " out of range from input " + nm);
 137.283 -        return valueOf((byte)i);
 137.284 -    }
 137.285 -
 137.286 -    /**
 137.287 -     * The value of the {@code Byte}.
 137.288 -     *
 137.289 -     * @serial
 137.290 -     */
 137.291 -    private final byte value;
 137.292 -
 137.293 -    /**
 137.294 -     * Constructs a newly allocated {@code Byte} object that
 137.295 -     * represents the specified {@code byte} value.
 137.296 -     *
 137.297 -     * @param value     the value to be represented by the
 137.298 -     *                  {@code Byte}.
 137.299 -     */
 137.300 -    public Byte(byte value) {
 137.301 -        this.value = value;
 137.302 -    }
 137.303 -
 137.304 -    /**
 137.305 -     * Constructs a newly allocated {@code Byte} object that
 137.306 -     * represents the {@code byte} value indicated by the
 137.307 -     * {@code String} parameter. The string is converted to a
 137.308 -     * {@code byte} value in exactly the manner used by the
 137.309 -     * {@code parseByte} method for radix 10.
 137.310 -     *
 137.311 -     * @param s         the {@code String} to be converted to a
 137.312 -     *                  {@code Byte}
 137.313 -     * @throws           NumberFormatException If the {@code String}
 137.314 -     *                  does not contain a parsable {@code byte}.
 137.315 -     * @see        java.lang.Byte#parseByte(java.lang.String, int)
 137.316 -     */
 137.317 -    public Byte(String s) throws NumberFormatException {
 137.318 -        this.value = parseByte(s, 10);
 137.319 -    }
 137.320 -
 137.321 -    /**
 137.322 -     * Returns the value of this {@code Byte} as a
 137.323 -     * {@code byte}.
 137.324 -     */
 137.325 -    public byte byteValue() {
 137.326 -        return value;
 137.327 -    }
 137.328 -
 137.329 -    /**
 137.330 -     * Returns the value of this {@code Byte} as a
 137.331 -     * {@code short}.
 137.332 -     */
 137.333 -    public short shortValue() {
 137.334 -        return (short)value;
 137.335 -    }
 137.336 -
 137.337 -    /**
 137.338 -     * Returns the value of this {@code Byte} as an
 137.339 -     * {@code int}.
 137.340 -     */
 137.341 -    public int intValue() {
 137.342 -        return (int)value;
 137.343 -    }
 137.344 -
 137.345 -    /**
 137.346 -     * Returns the value of this {@code Byte} as a
 137.347 -     * {@code long}.
 137.348 -     */
 137.349 -    public long longValue() {
 137.350 -        return (long)value;
 137.351 -    }
 137.352 -
 137.353 -    /**
 137.354 -     * Returns the value of this {@code Byte} as a
 137.355 -     * {@code float}.
 137.356 -     */
 137.357 -    public float floatValue() {
 137.358 -        return (float)value;
 137.359 -    }
 137.360 -
 137.361 -    /**
 137.362 -     * Returns the value of this {@code Byte} as a
 137.363 -     * {@code double}.
 137.364 -     */
 137.365 -    public double doubleValue() {
 137.366 -        return (double)value;
 137.367 -    }
 137.368 -
 137.369 -    /**
 137.370 -     * Returns a {@code String} object representing this
 137.371 -     * {@code Byte}'s value.  The value is converted to signed
 137.372 -     * decimal representation and returned as a string, exactly as if
 137.373 -     * the {@code byte} value were given as an argument to the
 137.374 -     * {@link java.lang.Byte#toString(byte)} method.
 137.375 -     *
 137.376 -     * @return  a string representation of the value of this object in
 137.377 -     *          base&nbsp;10.
 137.378 -     */
 137.379 -    public String toString() {
 137.380 -        return Integer.toString((int)value);
 137.381 -    }
 137.382 -
 137.383 -    /**
 137.384 -     * Returns a hash code for this {@code Byte}; equal to the result
 137.385 -     * of invoking {@code intValue()}.
 137.386 -     *
 137.387 -     * @return a hash code value for this {@code Byte}
 137.388 -     */
 137.389 -    public int hashCode() {
 137.390 -        return (int)value;
 137.391 -    }
 137.392 -
 137.393 -    /**
 137.394 -     * Compares this object to the specified object.  The result is
 137.395 -     * {@code true} if and only if the argument is not
 137.396 -     * {@code null} and is a {@code Byte} object that
 137.397 -     * contains the same {@code byte} value as this object.
 137.398 -     *
 137.399 -     * @param obj       the object to compare with
 137.400 -     * @return          {@code true} if the objects are the same;
 137.401 -     *                  {@code false} otherwise.
 137.402 -     */
 137.403 -    public boolean equals(Object obj) {
 137.404 -        if (obj instanceof Byte) {
 137.405 -            return value == ((Byte)obj).byteValue();
 137.406 -        }
 137.407 -        return false;
 137.408 -    }
 137.409 -
 137.410 -    /**
 137.411 -     * Compares two {@code Byte} objects numerically.
 137.412 -     *
 137.413 -     * @param   anotherByte   the {@code Byte} to be compared.
 137.414 -     * @return  the value {@code 0} if this {@code Byte} is
 137.415 -     *          equal to the argument {@code Byte}; a value less than
 137.416 -     *          {@code 0} if this {@code Byte} is numerically less
 137.417 -     *          than the argument {@code Byte}; and a value greater than
 137.418 -     *           {@code 0} if this {@code Byte} is numerically
 137.419 -     *           greater than the argument {@code Byte} (signed
 137.420 -     *           comparison).
 137.421 -     * @since   1.2
 137.422 -     */
 137.423 -    public int compareTo(Byte anotherByte) {
 137.424 -        return compare(this.value, anotherByte.value);
 137.425 -    }
 137.426 -
 137.427 -    /**
 137.428 -     * Compares two {@code byte} values numerically.
 137.429 -     * The value returned is identical to what would be returned by:
 137.430 -     * <pre>
 137.431 -     *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 137.432 -     * </pre>
 137.433 -     *
 137.434 -     * @param  x the first {@code byte} to compare
 137.435 -     * @param  y the second {@code byte} to compare
 137.436 -     * @return the value {@code 0} if {@code x == y};
 137.437 -     *         a value less than {@code 0} if {@code x < y}; and
 137.438 -     *         a value greater than {@code 0} if {@code x > y}
 137.439 -     * @since 1.7
 137.440 -     */
 137.441 -    public static int compare(byte x, byte y) {
 137.442 -        return x - y;
 137.443 -    }
 137.444 -
 137.445 -    /**
 137.446 -     * The number of bits used to represent a {@code byte} value in two's
 137.447 -     * complement binary form.
 137.448 -     *
 137.449 -     * @since 1.5
 137.450 -     */
 137.451 -    public static final int SIZE = 8;
 137.452 -
 137.453 -    /** use serialVersionUID from JDK 1.1. for interoperability */
 137.454 -    private static final long serialVersionUID = -7183698231559129828L;
 137.455 -}
   138.1 --- a/emul/mini/src/main/java/java/lang/CharSequence.java	Mon Feb 25 19:00:08 2013 +0100
   138.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   138.3 @@ -1,111 +0,0 @@
   138.4 -/*
   138.5 - * Copyright (c) 2000, 2003, 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 -/**
  138.33 - * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
  138.34 - * interface provides uniform, read-only access to many different kinds of
  138.35 - * <code>char</code> sequences.
  138.36 - * A <code>char</code> value represents a character in the <i>Basic
  138.37 - * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
  138.38 - * href="Character.html#unicode">Unicode Character Representation</a> for details.
  138.39 - *
  138.40 - * <p> This interface does not refine the general contracts of the {@link
  138.41 - * java.lang.Object#equals(java.lang.Object) equals} and {@link
  138.42 - * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
  138.43 - * objects that implement <tt>CharSequence</tt> is therefore, in general,
  138.44 - * undefined.  Each object may be implemented by a different class, and there
  138.45 - * is no guarantee that each class will be capable of testing its instances
  138.46 - * for equality with those of the other.  It is therefore inappropriate to use
  138.47 - * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
  138.48 - * a map. </p>
  138.49 - *
  138.50 - * @author Mike McCloskey
  138.51 - * @since 1.4
  138.52 - * @spec JSR-51
  138.53 - */
  138.54 -
  138.55 -public interface CharSequence {
  138.56 -
  138.57 -    /**
  138.58 -     * Returns the length of this character sequence.  The length is the number
  138.59 -     * of 16-bit <code>char</code>s in the sequence.</p>
  138.60 -     *
  138.61 -     * @return  the number of <code>char</code>s in this sequence
  138.62 -     */
  138.63 -    int length();
  138.64 -
  138.65 -    /**
  138.66 -     * Returns the <code>char</code> value at the specified index.  An index ranges from zero
  138.67 -     * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
  138.68 -     * index zero, the next at index one, and so on, as for array
  138.69 -     * indexing. </p>
  138.70 -     *
  138.71 -     * <p>If the <code>char</code> value specified by the index is a
  138.72 -     * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
  138.73 -     * value is returned.
  138.74 -     *
  138.75 -     * @param   index   the index of the <code>char</code> value to be returned
  138.76 -     *
  138.77 -     * @return  the specified <code>char</code> value
  138.78 -     *
  138.79 -     * @throws  IndexOutOfBoundsException
  138.80 -     *          if the <tt>index</tt> argument is negative or not less than
  138.81 -     *          <tt>length()</tt>
  138.82 -     */
  138.83 -    char charAt(int index);
  138.84 -
  138.85 -    /**
  138.86 -     * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
  138.87 -     * The subsequence starts with the <code>char</code> value at the specified index and
  138.88 -     * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
  138.89 -     * (in <code>char</code>s) of the
  138.90 -     * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
  138.91 -     * then an empty sequence is returned. </p>
  138.92 -     *
  138.93 -     * @param   start   the start index, inclusive
  138.94 -     * @param   end     the end index, exclusive
  138.95 -     *
  138.96 -     * @return  the specified subsequence
  138.97 -     *
  138.98 -     * @throws  IndexOutOfBoundsException
  138.99 -     *          if <tt>start</tt> or <tt>end</tt> are negative,
 138.100 -     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 138.101 -     *          or if <tt>start</tt> is greater than <tt>end</tt>
 138.102 -     */
 138.103 -    CharSequence subSequence(int start, int end);
 138.104 -
 138.105 -    /**
 138.106 -     * Returns a string containing the characters in this sequence in the same
 138.107 -     * order as this sequence.  The length of the string will be the length of
 138.108 -     * this sequence. </p>
 138.109 -     *
 138.110 -     * @return  a string consisting of exactly this sequence of characters
 138.111 -     */
 138.112 -    public String toString();
 138.113 -
 138.114 -}
   139.1 --- a/emul/mini/src/main/java/java/lang/Character.java	Mon Feb 25 19:00:08 2013 +0100
   139.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   139.3 @@ -1,2519 +0,0 @@
   139.4 -/*
   139.5 - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
   139.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   139.7 - *
   139.8 - * This code is free software; you can redistribute it and/or modify it
   139.9 - * under the terms of the GNU General Public License version 2 only, as
  139.10 - * published by the Free Software Foundation.  Oracle designates this
  139.11 - * particular file as subject to the "Classpath" exception as provided
  139.12 - * by Oracle in the LICENSE file that accompanied this code.
  139.13 - *
  139.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  139.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  139.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  139.17 - * version 2 for more details (a copy is included in the LICENSE file that
  139.18 - * accompanied this code).
  139.19 - *
  139.20 - * You should have received a copy of the GNU General Public License version
  139.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  139.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  139.23 - *
  139.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  139.25 - * or visit www.oracle.com if you need additional information or have any
  139.26 - * questions.
  139.27 - */
  139.28 -
  139.29 -package java.lang;
  139.30 -
  139.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  139.32 -
  139.33 -/**
  139.34 - * The {@code Character} class wraps a value of the primitive
  139.35 - * type {@code char} in an object. An object of type
  139.36 - * {@code Character} contains a single field whose type is
  139.37 - * {@code char}.
  139.38 - * <p>
  139.39 - * In addition, this class provides several methods for determining
  139.40 - * a character's category (lowercase letter, digit, etc.) and for converting
  139.41 - * characters from uppercase to lowercase and vice versa.
  139.42 - * <p>
  139.43 - * Character information is based on the Unicode Standard, version 6.0.0.
  139.44 - * <p>
  139.45 - * The methods and data of class {@code Character} are defined by
  139.46 - * the information in the <i>UnicodeData</i> file that is part of the
  139.47 - * Unicode Character Database maintained by the Unicode
  139.48 - * Consortium. This file specifies various properties including name
  139.49 - * and general category for every defined Unicode code point or
  139.50 - * character range.
  139.51 - * <p>
  139.52 - * The file and its description are available from the Unicode Consortium at:
  139.53 - * <ul>
  139.54 - * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
  139.55 - * </ul>
  139.56 - *
  139.57 - * <h4><a name="unicode">Unicode Character Representations</a></h4>
  139.58 - *
  139.59 - * <p>The {@code char} data type (and therefore the value that a
  139.60 - * {@code Character} object encapsulates) are based on the
  139.61 - * original Unicode specification, which defined characters as
  139.62 - * fixed-width 16-bit entities. The Unicode Standard has since been
  139.63 - * changed to allow for characters whose representation requires more
  139.64 - * than 16 bits.  The range of legal <em>code point</em>s is now
  139.65 - * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
  139.66 - * (Refer to the <a
  139.67 - * href="http://www.unicode.org/reports/tr27/#notation"><i>
  139.68 - * definition</i></a> of the U+<i>n</i> notation in the Unicode
  139.69 - * Standard.)
  139.70 - *
  139.71 - * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
  139.72 - * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
  139.73 - * <a name="supplementary">Characters</a> whose code points are greater
  139.74 - * than U+FFFF are called <em>supplementary character</em>s.  The Java
  139.75 - * platform uses the UTF-16 representation in {@code char} arrays and
  139.76 - * in the {@code String} and {@code StringBuffer} classes. In
  139.77 - * this representation, supplementary characters are represented as a pair
  139.78 - * of {@code char} values, the first from the <em>high-surrogates</em>
  139.79 - * range, (&#92;uD800-&#92;uDBFF), the second from the
  139.80 - * <em>low-surrogates</em> range (&#92;uDC00-&#92;uDFFF).
  139.81 - *
  139.82 - * <p>A {@code char} value, therefore, represents Basic
  139.83 - * Multilingual Plane (BMP) code points, including the surrogate
  139.84 - * code points, or code units of the UTF-16 encoding. An
  139.85 - * {@code int} value represents all Unicode code points,
  139.86 - * including supplementary code points. The lower (least significant)
  139.87 - * 21 bits of {@code int} are used to represent Unicode code
  139.88 - * points and the upper (most significant) 11 bits must be zero.
  139.89 - * Unless otherwise specified, the behavior with respect to
  139.90 - * supplementary characters and surrogate {@code char} values is
  139.91 - * as follows:
  139.92 - *
  139.93 - * <ul>
  139.94 - * <li>The methods that only accept a {@code char} value cannot support
  139.95 - * supplementary characters. They treat {@code char} values from the
  139.96 - * surrogate ranges as undefined characters. For example,
  139.97 - * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
  139.98 - * this specific value if followed by any low-surrogate value in a string
  139.99 - * would represent a letter.
 139.100 - *
 139.101 - * <li>The methods that accept an {@code int} value support all
 139.102 - * Unicode characters, including supplementary characters. For
 139.103 - * example, {@code Character.isLetter(0x2F81A)} returns
 139.104 - * {@code true} because the code point value represents a letter
 139.105 - * (a CJK ideograph).
 139.106 - * </ul>
 139.107 - *
 139.108 - * <p>In the Java SE API documentation, <em>Unicode code point</em> is
 139.109 - * used for character values in the range between U+0000 and U+10FFFF,
 139.110 - * and <em>Unicode code unit</em> is used for 16-bit
 139.111 - * {@code char} values that are code units of the <em>UTF-16</em>
 139.112 - * encoding. For more information on Unicode terminology, refer to the
 139.113 - * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
 139.114 - *
 139.115 - * @author  Lee Boynton
 139.116 - * @author  Guy Steele
 139.117 - * @author  Akira Tanaka
 139.118 - * @author  Martin Buchholz
 139.119 - * @author  Ulf Zibis
 139.120 - * @since   1.0
 139.121 - */
 139.122 -public final
 139.123 -class Character implements java.io.Serializable, Comparable<Character> {
 139.124 -    /**
 139.125 -     * The minimum radix available for conversion to and from strings.
 139.126 -     * The constant value of this field is the smallest value permitted
 139.127 -     * for the radix argument in radix-conversion methods such as the
 139.128 -     * {@code digit} method, the {@code forDigit} method, and the
 139.129 -     * {@code toString} method of class {@code Integer}.
 139.130 -     *
 139.131 -     * @see     Character#digit(char, int)
 139.132 -     * @see     Character#forDigit(int, int)
 139.133 -     * @see     Integer#toString(int, int)
 139.134 -     * @see     Integer#valueOf(String)
 139.135 -     */
 139.136 -    public static final int MIN_RADIX = 2;
 139.137 -
 139.138 -    /**
 139.139 -     * The maximum radix available for conversion to and from strings.
 139.140 -     * The constant value of this field is the largest value permitted
 139.141 -     * for the radix argument in radix-conversion methods such as the
 139.142 -     * {@code digit} method, the {@code forDigit} method, and the
 139.143 -     * {@code toString} method of class {@code Integer}.
 139.144 -     *
 139.145 -     * @see     Character#digit(char, int)
 139.146 -     * @see     Character#forDigit(int, int)
 139.147 -     * @see     Integer#toString(int, int)
 139.148 -     * @see     Integer#valueOf(String)
 139.149 -     */
 139.150 -    public static final int MAX_RADIX = 36;
 139.151 -
 139.152 -    /**
 139.153 -     * The constant value of this field is the smallest value of type
 139.154 -     * {@code char}, {@code '\u005Cu0000'}.
 139.155 -     *
 139.156 -     * @since   1.0.2
 139.157 -     */
 139.158 -    public static final char MIN_VALUE = '\u0000';
 139.159 -
 139.160 -    /**
 139.161 -     * The constant value of this field is the largest value of type
 139.162 -     * {@code char}, {@code '\u005CuFFFF'}.
 139.163 -     *
 139.164 -     * @since   1.0.2
 139.165 -     */
 139.166 -    public static final char MAX_VALUE = '\uFFFF';
 139.167 -
 139.168 -    /**
 139.169 -     * The {@code Class} instance representing the primitive type
 139.170 -     * {@code char}.
 139.171 -     *
 139.172 -     * @since   1.1
 139.173 -     */
 139.174 -    public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
 139.175 -
 139.176 -    /*
 139.177 -     * Normative general types
 139.178 -     */
 139.179 -
 139.180 -    /*
 139.181 -     * General character types
 139.182 -     */
 139.183 -
 139.184 -    /**
 139.185 -     * General category "Cn" in the Unicode specification.
 139.186 -     * @since   1.1
 139.187 -     */
 139.188 -    public static final byte UNASSIGNED = 0;
 139.189 -
 139.190 -    /**
 139.191 -     * General category "Lu" in the Unicode specification.
 139.192 -     * @since   1.1
 139.193 -     */
 139.194 -    public static final byte UPPERCASE_LETTER = 1;
 139.195 -
 139.196 -    /**
 139.197 -     * General category "Ll" in the Unicode specification.
 139.198 -     * @since   1.1
 139.199 -     */
 139.200 -    public static final byte LOWERCASE_LETTER = 2;
 139.201 -
 139.202 -    /**
 139.203 -     * General category "Lt" in the Unicode specification.
 139.204 -     * @since   1.1
 139.205 -     */
 139.206 -    public static final byte TITLECASE_LETTER = 3;
 139.207 -
 139.208 -    /**
 139.209 -     * General category "Lm" in the Unicode specification.
 139.210 -     * @since   1.1
 139.211 -     */
 139.212 -    public static final byte MODIFIER_LETTER = 4;
 139.213 -
 139.214 -    /**
 139.215 -     * General category "Lo" in the Unicode specification.
 139.216 -     * @since   1.1
 139.217 -     */
 139.218 -    public static final byte OTHER_LETTER = 5;
 139.219 -
 139.220 -    /**
 139.221 -     * General category "Mn" in the Unicode specification.
 139.222 -     * @since   1.1
 139.223 -     */
 139.224 -    public static final byte NON_SPACING_MARK = 6;
 139.225 -
 139.226 -    /**
 139.227 -     * General category "Me" in the Unicode specification.
 139.228 -     * @since   1.1
 139.229 -     */
 139.230 -    public static final byte ENCLOSING_MARK = 7;
 139.231 -
 139.232 -    /**
 139.233 -     * General category "Mc" in the Unicode specification.
 139.234 -     * @since   1.1
 139.235 -     */
 139.236 -    public static final byte COMBINING_SPACING_MARK = 8;
 139.237 -
 139.238 -    /**
 139.239 -     * General category "Nd" in the Unicode specification.
 139.240 -     * @since   1.1
 139.241 -     */
 139.242 -    public static final byte DECIMAL_DIGIT_NUMBER        = 9;
 139.243 -
 139.244 -    /**
 139.245 -     * General category "Nl" in the Unicode specification.
 139.246 -     * @since   1.1
 139.247 -     */
 139.248 -    public static final byte LETTER_NUMBER = 10;
 139.249 -
 139.250 -    /**
 139.251 -     * General category "No" in the Unicode specification.
 139.252 -     * @since   1.1
 139.253 -     */
 139.254 -    public static final byte OTHER_NUMBER = 11;
 139.255 -
 139.256 -    /**
 139.257 -     * General category "Zs" in the Unicode specification.
 139.258 -     * @since   1.1
 139.259 -     */
 139.260 -    public static final byte SPACE_SEPARATOR = 12;
 139.261 -
 139.262 -    /**
 139.263 -     * General category "Zl" in the Unicode specification.
 139.264 -     * @since   1.1
 139.265 -     */
 139.266 -    public static final byte LINE_SEPARATOR = 13;
 139.267 -
 139.268 -    /**
 139.269 -     * General category "Zp" in the Unicode specification.
 139.270 -     * @since   1.1
 139.271 -     */
 139.272 -    public static final byte PARAGRAPH_SEPARATOR = 14;
 139.273 -
 139.274 -    /**
 139.275 -     * General category "Cc" in the Unicode specification.
 139.276 -     * @since   1.1
 139.277 -     */
 139.278 -    public static final byte CONTROL = 15;
 139.279 -
 139.280 -    /**
 139.281 -     * General category "Cf" in the Unicode specification.
 139.282 -     * @since   1.1
 139.283 -     */
 139.284 -    public static final byte FORMAT = 16;
 139.285 -
 139.286 -    /**
 139.287 -     * General category "Co" in the Unicode specification.
 139.288 -     * @since   1.1
 139.289 -     */
 139.290 -    public static final byte PRIVATE_USE = 18;
 139.291 -
 139.292 -    /**
 139.293 -     * General category "Cs" in the Unicode specification.
 139.294 -     * @since   1.1
 139.295 -     */
 139.296 -    public static final byte SURROGATE = 19;
 139.297 -
 139.298 -    /**
 139.299 -     * General category "Pd" in the Unicode specification.
 139.300 -     * @since   1.1
 139.301 -     */
 139.302 -    public static final byte DASH_PUNCTUATION = 20;
 139.303 -
 139.304 -    /**
 139.305 -     * General category "Ps" in the Unicode specification.
 139.306 -     * @since   1.1
 139.307 -     */
 139.308 -    public static final byte START_PUNCTUATION = 21;
 139.309 -
 139.310 -    /**
 139.311 -     * General category "Pe" in the Unicode specification.
 139.312 -     * @since   1.1
 139.313 -     */
 139.314 -    public static final byte END_PUNCTUATION = 22;
 139.315 -
 139.316 -    /**
 139.317 -     * General category "Pc" in the Unicode specification.
 139.318 -     * @since   1.1
 139.319 -     */
 139.320 -    public static final byte CONNECTOR_PUNCTUATION = 23;
 139.321 -
 139.322 -    /**
 139.323 -     * General category "Po" in the Unicode specification.
 139.324 -     * @since   1.1
 139.325 -     */
 139.326 -    public static final byte OTHER_PUNCTUATION = 24;
 139.327 -
 139.328 -    /**
 139.329 -     * General category "Sm" in the Unicode specification.
 139.330 -     * @since   1.1
 139.331 -     */
 139.332 -    public static final byte MATH_SYMBOL = 25;
 139.333 -
 139.334 -    /**
 139.335 -     * General category "Sc" in the Unicode specification.
 139.336 -     * @since   1.1
 139.337 -     */
 139.338 -    public static final byte CURRENCY_SYMBOL = 26;
 139.339 -
 139.340 -    /**
 139.341 -     * General category "Sk" in the Unicode specification.
 139.342 -     * @since   1.1
 139.343 -     */
 139.344 -    public static final byte MODIFIER_SYMBOL = 27;
 139.345 -
 139.346 -    /**
 139.347 -     * General category "So" in the Unicode specification.
 139.348 -     * @since   1.1
 139.349 -     */
 139.350 -    public static final byte OTHER_SYMBOL = 28;
 139.351 -
 139.352 -    /**
 139.353 -     * General category "Pi" in the Unicode specification.
 139.354 -     * @since   1.4
 139.355 -     */
 139.356 -    public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
 139.357 -
 139.358 -    /**
 139.359 -     * General category "Pf" in the Unicode specification.
 139.360 -     * @since   1.4
 139.361 -     */
 139.362 -    public static final byte FINAL_QUOTE_PUNCTUATION = 30;
 139.363 -
 139.364 -    /**
 139.365 -     * Error flag. Use int (code point) to avoid confusion with U+FFFF.
 139.366 -     */
 139.367 -    static final int ERROR = 0xFFFFFFFF;
 139.368 -
 139.369 -
 139.370 -    /**
 139.371 -     * Undefined bidirectional character type. Undefined {@code char}
 139.372 -     * values have undefined directionality in the Unicode specification.
 139.373 -     * @since 1.4
 139.374 -     */
 139.375 -    public static final byte DIRECTIONALITY_UNDEFINED = -1;
 139.376 -
 139.377 -    /**
 139.378 -     * Strong bidirectional character type "L" in the Unicode specification.
 139.379 -     * @since 1.4
 139.380 -     */
 139.381 -    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
 139.382 -
 139.383 -    /**
 139.384 -     * Strong bidirectional character type "R" in the Unicode specification.
 139.385 -     * @since 1.4
 139.386 -     */
 139.387 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
 139.388 -
 139.389 -    /**
 139.390 -    * Strong bidirectional character type "AL" in the Unicode specification.
 139.391 -     * @since 1.4
 139.392 -     */
 139.393 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
 139.394 -
 139.395 -    /**
 139.396 -     * Weak bidirectional character type "EN" in the Unicode specification.
 139.397 -     * @since 1.4
 139.398 -     */
 139.399 -    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
 139.400 -
 139.401 -    /**
 139.402 -     * Weak bidirectional character type "ES" in the Unicode specification.
 139.403 -     * @since 1.4
 139.404 -     */
 139.405 -    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
 139.406 -
 139.407 -    /**
 139.408 -     * Weak bidirectional character type "ET" in the Unicode specification.
 139.409 -     * @since 1.4
 139.410 -     */
 139.411 -    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
 139.412 -
 139.413 -    /**
 139.414 -     * Weak bidirectional character type "AN" in the Unicode specification.
 139.415 -     * @since 1.4
 139.416 -     */
 139.417 -    public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
 139.418 -
 139.419 -    /**
 139.420 -     * Weak bidirectional character type "CS" in the Unicode specification.
 139.421 -     * @since 1.4
 139.422 -     */
 139.423 -    public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
 139.424 -
 139.425 -    /**
 139.426 -     * Weak bidirectional character type "NSM" in the Unicode specification.
 139.427 -     * @since 1.4
 139.428 -     */
 139.429 -    public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
 139.430 -
 139.431 -    /**
 139.432 -     * Weak bidirectional character type "BN" in the Unicode specification.
 139.433 -     * @since 1.4
 139.434 -     */
 139.435 -    public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
 139.436 -
 139.437 -    /**
 139.438 -     * Neutral bidirectional character type "B" in the Unicode specification.
 139.439 -     * @since 1.4
 139.440 -     */
 139.441 -    public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
 139.442 -
 139.443 -    /**
 139.444 -     * Neutral bidirectional character type "S" in the Unicode specification.
 139.445 -     * @since 1.4
 139.446 -     */
 139.447 -    public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
 139.448 -
 139.449 -    /**
 139.450 -     * Neutral bidirectional character type "WS" in the Unicode specification.
 139.451 -     * @since 1.4
 139.452 -     */
 139.453 -    public static final byte DIRECTIONALITY_WHITESPACE = 12;
 139.454 -
 139.455 -    /**
 139.456 -     * Neutral bidirectional character type "ON" in the Unicode specification.
 139.457 -     * @since 1.4
 139.458 -     */
 139.459 -    public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
 139.460 -
 139.461 -    /**
 139.462 -     * Strong bidirectional character type "LRE" in the Unicode specification.
 139.463 -     * @since 1.4
 139.464 -     */
 139.465 -    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
 139.466 -
 139.467 -    /**
 139.468 -     * Strong bidirectional character type "LRO" in the Unicode specification.
 139.469 -     * @since 1.4
 139.470 -     */
 139.471 -    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
 139.472 -
 139.473 -    /**
 139.474 -     * Strong bidirectional character type "RLE" in the Unicode specification.
 139.475 -     * @since 1.4
 139.476 -     */
 139.477 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
 139.478 -
 139.479 -    /**
 139.480 -     * Strong bidirectional character type "RLO" in the Unicode specification.
 139.481 -     * @since 1.4
 139.482 -     */
 139.483 -    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
 139.484 -
 139.485 -    /**
 139.486 -     * Weak bidirectional character type "PDF" in the Unicode specification.
 139.487 -     * @since 1.4
 139.488 -     */
 139.489 -    public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
 139.490 -
 139.491 -    /**
 139.492 -     * The minimum value of a
 139.493 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 139.494 -     * Unicode high-surrogate code unit</a>
 139.495 -     * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
 139.496 -     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 139.497 -     *
 139.498 -     * @since 1.5
 139.499 -     */
 139.500 -    public static final char MIN_HIGH_SURROGATE = '\uD800';
 139.501 -
 139.502 -    /**
 139.503 -     * The maximum value of a
 139.504 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 139.505 -     * Unicode high-surrogate code unit</a>
 139.506 -     * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
 139.507 -     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 139.508 -     *
 139.509 -     * @since 1.5
 139.510 -     */
 139.511 -    public static final char MAX_HIGH_SURROGATE = '\uDBFF';
 139.512 -
 139.513 -    /**
 139.514 -     * The minimum value of a
 139.515 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 139.516 -     * Unicode low-surrogate code unit</a>
 139.517 -     * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
 139.518 -     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 139.519 -     *
 139.520 -     * @since 1.5
 139.521 -     */
 139.522 -    public static final char MIN_LOW_SURROGATE  = '\uDC00';
 139.523 -
 139.524 -    /**
 139.525 -     * The maximum value of a
 139.526 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 139.527 -     * Unicode low-surrogate code unit</a>
 139.528 -     * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 139.529 -     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 139.530 -     *
 139.531 -     * @since 1.5
 139.532 -     */
 139.533 -    public static final char MAX_LOW_SURROGATE  = '\uDFFF';
 139.534 -
 139.535 -    /**
 139.536 -     * The minimum value of a Unicode surrogate code unit in the
 139.537 -     * UTF-16 encoding, constant {@code '\u005CuD800'}.
 139.538 -     *
 139.539 -     * @since 1.5
 139.540 -     */
 139.541 -    public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
 139.542 -
 139.543 -    /**
 139.544 -     * The maximum value of a Unicode surrogate code unit in the
 139.545 -     * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 139.546 -     *
 139.547 -     * @since 1.5
 139.548 -     */
 139.549 -    public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
 139.550 -
 139.551 -    /**
 139.552 -     * The minimum value of a
 139.553 -     * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
 139.554 -     * Unicode supplementary code point</a>, constant {@code U+10000}.
 139.555 -     *
 139.556 -     * @since 1.5
 139.557 -     */
 139.558 -    public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
 139.559 -
 139.560 -    /**
 139.561 -     * The minimum value of a
 139.562 -     * <a href="http://www.unicode.org/glossary/#code_point">
 139.563 -     * Unicode code point</a>, constant {@code U+0000}.
 139.564 -     *
 139.565 -     * @since 1.5
 139.566 -     */
 139.567 -    public static final int MIN_CODE_POINT = 0x000000;
 139.568 -
 139.569 -    /**
 139.570 -     * The maximum value of a
 139.571 -     * <a href="http://www.unicode.org/glossary/#code_point">
 139.572 -     * Unicode code point</a>, constant {@code U+10FFFF}.
 139.573 -     *
 139.574 -     * @since 1.5
 139.575 -     */
 139.576 -    public static final int MAX_CODE_POINT = 0X10FFFF;
 139.577 -
 139.578 -
 139.579 -    /**
 139.580 -     * Instances of this class represent particular subsets of the Unicode
 139.581 -     * character set.  The only family of subsets defined in the
 139.582 -     * {@code Character} class is {@link Character.UnicodeBlock}.
 139.583 -     * Other portions of the Java API may define other subsets for their
 139.584 -     * own purposes.
 139.585 -     *
 139.586 -     * @since 1.2
 139.587 -     */
 139.588 -    public static class Subset  {
 139.589 -
 139.590 -        private String name;
 139.591 -
 139.592 -        /**
 139.593 -         * Constructs a new {@code Subset} instance.
 139.594 -         *
 139.595 -         * @param  name  The name of this subset
 139.596 -         * @exception NullPointerException if name is {@code null}
 139.597 -         */
 139.598 -        protected Subset(String name) {
 139.599 -            if (name == null) {
 139.600 -                throw new NullPointerException("name");
 139.601 -            }
 139.602 -            this.name = name;
 139.603 -        }
 139.604 -
 139.605 -        /**
 139.606 -         * Compares two {@code Subset} objects for equality.
 139.607 -         * This method returns {@code true} if and only if
 139.608 -         * {@code this} and the argument refer to the same
 139.609 -         * object; since this method is {@code final}, this
 139.610 -         * guarantee holds for all subclasses.
 139.611 -         */
 139.612 -        public final boolean equals(Object obj) {
 139.613 -            return (this == obj);
 139.614 -        }
 139.615 -
 139.616 -        /**
 139.617 -         * Returns the standard hash code as defined by the
 139.618 -         * {@link Object#hashCode} method.  This method
 139.619 -         * is {@code final} in order to ensure that the
 139.620 -         * {@code equals} and {@code hashCode} methods will
 139.621 -         * be consistent in all subclasses.
 139.622 -         */
 139.623 -        public final int hashCode() {
 139.624 -            return super.hashCode();
 139.625 -        }
 139.626 -
 139.627 -        /**
 139.628 -         * Returns the name of this subset.
 139.629 -         */
 139.630 -        public final String toString() {
 139.631 -            return name;
 139.632 -        }
 139.633 -    }
 139.634 -
 139.635 -    // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
 139.636 -    // for the latest specification of Unicode Blocks.
 139.637 -
 139.638 -
 139.639 -    /**
 139.640 -     * The value of the {@code Character}.
 139.641 -     *
 139.642 -     * @serial
 139.643 -     */
 139.644 -    private final char value;
 139.645 -
 139.646 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 139.647 -    private static final long serialVersionUID = 3786198910865385080L;
 139.648 -
 139.649 -    /**
 139.650 -     * Constructs a newly allocated {@code Character} object that
 139.651 -     * represents the specified {@code char} value.
 139.652 -     *
 139.653 -     * @param  value   the value to be represented by the
 139.654 -     *                  {@code Character} object.
 139.655 -     */
 139.656 -    public Character(char value) {
 139.657 -        this.value = value;
 139.658 -    }
 139.659 -
 139.660 -    private static class CharacterCache {
 139.661 -        private CharacterCache(){}
 139.662 -
 139.663 -        static final Character cache[] = new Character[127 + 1];
 139.664 -
 139.665 -        static {
 139.666 -            for (int i = 0; i < cache.length; i++)
 139.667 -                cache[i] = new Character((char)i);
 139.668 -        }
 139.669 -    }
 139.670 -
 139.671 -    /**
 139.672 -     * Returns a <tt>Character</tt> instance representing the specified
 139.673 -     * <tt>char</tt> value.
 139.674 -     * If a new <tt>Character</tt> instance is not required, this method
 139.675 -     * should generally be used in preference to the constructor
 139.676 -     * {@link #Character(char)}, as this method is likely to yield
 139.677 -     * significantly better space and time performance by caching
 139.678 -     * frequently requested values.
 139.679 -     *
 139.680 -     * This method will always cache values in the range {@code
 139.681 -     * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
 139.682 -     * cache other values outside of this range.
 139.683 -     *
 139.684 -     * @param  c a char value.
 139.685 -     * @return a <tt>Character</tt> instance representing <tt>c</tt>.
 139.686 -     * @since  1.5
 139.687 -     */
 139.688 -    public static Character valueOf(char c) {
 139.689 -        if (c <= 127) { // must cache
 139.690 -            return CharacterCache.cache[(int)c];
 139.691 -        }
 139.692 -        return new Character(c);
 139.693 -    }
 139.694 -
 139.695 -    /**
 139.696 -     * Returns the value of this {@code Character} object.
 139.697 -     * @return  the primitive {@code char} value represented by
 139.698 -     *          this object.
 139.699 -     */
 139.700 -    public char charValue() {
 139.701 -        return value;
 139.702 -    }
 139.703 -
 139.704 -    /**
 139.705 -     * Returns a hash code for this {@code Character}; equal to the result
 139.706 -     * of invoking {@code charValue()}.
 139.707 -     *
 139.708 -     * @return a hash code value for this {@code Character}
 139.709 -     */
 139.710 -    public int hashCode() {
 139.711 -        return (int)value;
 139.712 -    }
 139.713 -
 139.714 -    /**
 139.715 -     * Compares this object against the specified object.
 139.716 -     * The result is {@code true} if and only if the argument is not
 139.717 -     * {@code null} and is a {@code Character} object that
 139.718 -     * represents the same {@code char} value as this object.
 139.719 -     *
 139.720 -     * @param   obj   the object to compare with.
 139.721 -     * @return  {@code true} if the objects are the same;
 139.722 -     *          {@code false} otherwise.
 139.723 -     */
 139.724 -    public boolean equals(Object obj) {
 139.725 -        if (obj instanceof Character) {
 139.726 -            return value == ((Character)obj).charValue();
 139.727 -        }
 139.728 -        return false;
 139.729 -    }
 139.730 -
 139.731 -    /**
 139.732 -     * Returns a {@code String} object representing this
 139.733 -     * {@code Character}'s value.  The result is a string of
 139.734 -     * length 1 whose sole component is the primitive
 139.735 -     * {@code char} value represented by this
 139.736 -     * {@code Character} object.
 139.737 -     *
 139.738 -     * @return  a string representation of this object.
 139.739 -     */
 139.740 -    public String toString() {
 139.741 -        char buf[] = {value};
 139.742 -        return String.valueOf(buf);
 139.743 -    }
 139.744 -
 139.745 -    /**
 139.746 -     * Returns a {@code String} object representing the
 139.747 -     * specified {@code char}.  The result is a string of length
 139.748 -     * 1 consisting solely of the specified {@code char}.
 139.749 -     *
 139.750 -     * @param c the {@code char} to be converted
 139.751 -     * @return the string representation of the specified {@code char}
 139.752 -     * @since 1.4
 139.753 -     */
 139.754 -    public static String toString(char c) {
 139.755 -        return String.valueOf(c);
 139.756 -    }
 139.757 -
 139.758 -    /**
 139.759 -     * Determines whether the specified code point is a valid
 139.760 -     * <a href="http://www.unicode.org/glossary/#code_point">
 139.761 -     * Unicode code point value</a>.
 139.762 -     *
 139.763 -     * @param  codePoint the Unicode code point to be tested
 139.764 -     * @return {@code true} if the specified code point value is between
 139.765 -     *         {@link #MIN_CODE_POINT} and
 139.766 -     *         {@link #MAX_CODE_POINT} inclusive;
 139.767 -     *         {@code false} otherwise.
 139.768 -     * @since  1.5
 139.769 -     */
 139.770 -    public static boolean isValidCodePoint(int codePoint) {
 139.771 -        // Optimized form of:
 139.772 -        //     codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
 139.773 -        int plane = codePoint >>> 16;
 139.774 -        return plane < ((MAX_CODE_POINT + 1) >>> 16);
 139.775 -    }
 139.776 -
 139.777 -    /**
 139.778 -     * Determines whether the specified character (Unicode code point)
 139.779 -     * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
 139.780 -     * Such code points can be represented using a single {@code char}.
 139.781 -     *
 139.782 -     * @param  codePoint the character (Unicode code point) to be tested
 139.783 -     * @return {@code true} if the specified code point is between
 139.784 -     *         {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
 139.785 -     *         {@code false} otherwise.
 139.786 -     * @since  1.7
 139.787 -     */
 139.788 -    public static boolean isBmpCodePoint(int codePoint) {
 139.789 -        return codePoint >>> 16 == 0;
 139.790 -        // Optimized form of:
 139.791 -        //     codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
 139.792 -        // We consistently use logical shift (>>>) to facilitate
 139.793 -        // additional runtime optimizations.
 139.794 -    }
 139.795 -
 139.796 -    /**
 139.797 -     * Determines whether the specified character (Unicode code point)
 139.798 -     * is in the <a href="#supplementary">supplementary character</a> range.
 139.799 -     *
 139.800 -     * @param  codePoint the character (Unicode code point) to be tested
 139.801 -     * @return {@code true} if the specified code point is between
 139.802 -     *         {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
 139.803 -     *         {@link #MAX_CODE_POINT} inclusive;
 139.804 -     *         {@code false} otherwise.
 139.805 -     * @since  1.5
 139.806 -     */
 139.807 -    public static boolean isSupplementaryCodePoint(int codePoint) {
 139.808 -        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
 139.809 -            && codePoint <  MAX_CODE_POINT + 1;
 139.810 -    }
 139.811 -
 139.812 -    /**
 139.813 -     * Determines if the given {@code char} value is a
 139.814 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 139.815 -     * Unicode high-surrogate code unit</a>
 139.816 -     * (also known as <i>leading-surrogate code unit</i>).
 139.817 -     *
 139.818 -     * <p>Such values do not represent characters by themselves,
 139.819 -     * but are used in the representation of
 139.820 -     * <a href="#supplementary">supplementary characters</a>
 139.821 -     * in the UTF-16 encoding.
 139.822 -     *
 139.823 -     * @param  ch the {@code char} value to be tested.
 139.824 -     * @return {@code true} if the {@code char} value is between
 139.825 -     *         {@link #MIN_HIGH_SURROGATE} and
 139.826 -     *         {@link #MAX_HIGH_SURROGATE} inclusive;
 139.827 -     *         {@code false} otherwise.
 139.828 -     * @see    Character#isLowSurrogate(char)
 139.829 -     * @see    Character.UnicodeBlock#of(int)
 139.830 -     * @since  1.5
 139.831 -     */
 139.832 -    public static boolean isHighSurrogate(char ch) {
 139.833 -        // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
 139.834 -        return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
 139.835 -    }
 139.836 -
 139.837 -    /**
 139.838 -     * Determines if the given {@code char} value is a
 139.839 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 139.840 -     * Unicode low-surrogate code unit</a>
 139.841 -     * (also known as <i>trailing-surrogate code unit</i>).
 139.842 -     *
 139.843 -     * <p>Such values do not represent characters by themselves,
 139.844 -     * but are used in the representation of
 139.845 -     * <a href="#supplementary">supplementary characters</a>
 139.846 -     * in the UTF-16 encoding.
 139.847 -     *
 139.848 -     * @param  ch the {@code char} value to be tested.
 139.849 -     * @return {@code true} if the {@code char} value is between
 139.850 -     *         {@link #MIN_LOW_SURROGATE} and
 139.851 -     *         {@link #MAX_LOW_SURROGATE} inclusive;
 139.852 -     *         {@code false} otherwise.
 139.853 -     * @see    Character#isHighSurrogate(char)
 139.854 -     * @since  1.5
 139.855 -     */
 139.856 -    public static boolean isLowSurrogate(char ch) {
 139.857 -        return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
 139.858 -    }
 139.859 -
 139.860 -    /**
 139.861 -     * Determines if the given {@code char} value is a Unicode
 139.862 -     * <i>surrogate code unit</i>.
 139.863 -     *
 139.864 -     * <p>Such values do not represent characters by themselves,
 139.865 -     * but are used in the representation of
 139.866 -     * <a href="#supplementary">supplementary characters</a>
 139.867 -     * in the UTF-16 encoding.
 139.868 -     *
 139.869 -     * <p>A char value is a surrogate code unit if and only if it is either
 139.870 -     * a {@linkplain #isLowSurrogate(char) low-surrogate code unit} or
 139.871 -     * a {@linkplain #isHighSurrogate(char) high-surrogate code unit}.
 139.872 -     *
 139.873 -     * @param  ch the {@code char} value to be tested.
 139.874 -     * @return {@code true} if the {@code char} value is between
 139.875 -     *         {@link #MIN_SURROGATE} and
 139.876 -     *         {@link #MAX_SURROGATE} inclusive;
 139.877 -     *         {@code false} otherwise.
 139.878 -     * @since  1.7
 139.879 -     */
 139.880 -    public static boolean isSurrogate(char ch) {
 139.881 -        return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
 139.882 -    }
 139.883 -
 139.884 -    /**
 139.885 -     * Determines whether the specified pair of {@code char}
 139.886 -     * values is a valid
 139.887 -     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
 139.888 -     * Unicode surrogate pair</a>.
 139.889 -
 139.890 -     * <p>This method is equivalent to the expression:
 139.891 -     * <blockquote><pre>
 139.892 -     * isHighSurrogate(high) && isLowSurrogate(low)
 139.893 -     * </pre></blockquote>
 139.894 -     *
 139.895 -     * @param  high the high-surrogate code value to be tested
 139.896 -     * @param  low the low-surrogate code value to be tested
 139.897 -     * @return {@code true} if the specified high and
 139.898 -     * low-surrogate code values represent a valid surrogate pair;
 139.899 -     * {@code false} otherwise.
 139.900 -     * @since  1.5
 139.901 -     */
 139.902 -    public static boolean isSurrogatePair(char high, char low) {
 139.903 -        return isHighSurrogate(high) && isLowSurrogate(low);
 139.904 -    }
 139.905 -
 139.906 -    /**
 139.907 -     * Determines the number of {@code char} values needed to
 139.908 -     * represent the specified character (Unicode code point). If the
 139.909 -     * specified character is equal to or greater than 0x10000, then
 139.910 -     * the method returns 2. Otherwise, the method returns 1.
 139.911 -     *
 139.912 -     * <p>This method doesn't validate the specified character to be a
 139.913 -     * valid Unicode code point. The caller must validate the
 139.914 -     * character value using {@link #isValidCodePoint(int) isValidCodePoint}
 139.915 -     * if necessary.
 139.916 -     *
 139.917 -     * @param   codePoint the character (Unicode code point) to be tested.
 139.918 -     * @return  2 if the character is a valid supplementary character; 1 otherwise.
 139.919 -     * @see     Character#isSupplementaryCodePoint(int)
 139.920 -     * @since   1.5
 139.921 -     */
 139.922 -    public static int charCount(int codePoint) {
 139.923 -        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
 139.924 -    }
 139.925 -
 139.926 -    /**
 139.927 -     * Converts the specified surrogate pair to its supplementary code
 139.928 -     * point value. This method does not validate the specified
 139.929 -     * surrogate pair. The caller must validate it using {@link
 139.930 -     * #isSurrogatePair(char, char) isSurrogatePair} if necessary.
 139.931 -     *
 139.932 -     * @param  high the high-surrogate code unit
 139.933 -     * @param  low the low-surrogate code unit
 139.934 -     * @return the supplementary code point composed from the
 139.935 -     *         specified surrogate pair.
 139.936 -     * @since  1.5
 139.937 -     */
 139.938 -    public static int toCodePoint(char high, char low) {
 139.939 -        // Optimized form of:
 139.940 -        // return ((high - MIN_HIGH_SURROGATE) << 10)
 139.941 -        //         + (low - MIN_LOW_SURROGATE)
 139.942 -        //         + MIN_SUPPLEMENTARY_CODE_POINT;
 139.943 -        return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT
 139.944 -                                       - (MIN_HIGH_SURROGATE << 10)
 139.945 -                                       - MIN_LOW_SURROGATE);
 139.946 -    }
 139.947 -
 139.948 -    /**
 139.949 -     * Returns the code point at the given index of the
 139.950 -     * {@code CharSequence}. If the {@code char} value at
 139.951 -     * the given index in the {@code CharSequence} is in the
 139.952 -     * high-surrogate range, the following index is less than the
 139.953 -     * length of the {@code CharSequence}, and the
 139.954 -     * {@code char} value at the following index is in the
 139.955 -     * low-surrogate range, then the supplementary code point
 139.956 -     * corresponding to this surrogate pair is returned. Otherwise,
 139.957 -     * the {@code char} value at the given index is returned.
 139.958 -     *
 139.959 -     * @param seq a sequence of {@code char} values (Unicode code
 139.960 -     * units)
 139.961 -     * @param index the index to the {@code char} values (Unicode
 139.962 -     * code units) in {@code seq} to be converted
 139.963 -     * @return the Unicode code point at the given index
 139.964 -     * @exception NullPointerException if {@code seq} is null.
 139.965 -     * @exception IndexOutOfBoundsException if the value
 139.966 -     * {@code index} is negative or not less than
 139.967 -     * {@link CharSequence#length() seq.length()}.
 139.968 -     * @since  1.5
 139.969 -     */
 139.970 -    public static int codePointAt(CharSequence seq, int index) {
 139.971 -        char c1 = seq.charAt(index++);
 139.972 -        if (isHighSurrogate(c1)) {
 139.973 -            if (index < seq.length()) {
 139.974 -                char c2 = seq.charAt(index);
 139.975 -                if (isLowSurrogate(c2)) {
 139.976 -                    return toCodePoint(c1, c2);
 139.977 -                }
 139.978 -            }
 139.979 -        }
 139.980 -        return c1;
 139.981 -    }
 139.982 -
 139.983 -    /**
 139.984 -     * Returns the code point at the given index of the
 139.985 -     * {@code char} array. If the {@code char} value at
 139.986 -     * the given index in the {@code char} array is in the
 139.987 -     * high-surrogate range, the following index is less than the
 139.988 -     * length of the {@code char} array, and the
 139.989 -     * {@code char} value at the following index is in the
 139.990 -     * low-surrogate range, then the supplementary code point
 139.991 -     * corresponding to this surrogate pair is returned. Otherwise,
 139.992 -     * the {@code char} value at the given index is returned.
 139.993 -     *
 139.994 -     * @param a the {@code char} array
 139.995 -     * @param index the index to the {@code char} values (Unicode
 139.996 -     * code units) in the {@code char} array to be converted
 139.997 -     * @return the Unicode code point at the given index
 139.998 -     * @exception NullPointerException if {@code a} is null.
 139.999 -     * @exception IndexOutOfBoundsException if the value
139.1000 -     * {@code index} is negative or not less than
139.1001 -     * the length of the {@code char} array.
139.1002 -     * @since  1.5
139.1003 -     */
139.1004 -    public static int codePointAt(char[] a, int index) {
139.1005 -        return codePointAtImpl(a, index, a.length);
139.1006 -    }
139.1007 -
139.1008 -    /**
139.1009 -     * Returns the code point at the given index of the
139.1010 -     * {@code char} array, where only array elements with
139.1011 -     * {@code index} less than {@code limit} can be used. If
139.1012 -     * the {@code char} value at the given index in the
139.1013 -     * {@code char} array is in the high-surrogate range, the
139.1014 -     * following index is less than the {@code limit}, and the
139.1015 -     * {@code char} value at the following index is in the
139.1016 -     * low-surrogate range, then the supplementary code point
139.1017 -     * corresponding to this surrogate pair is returned. Otherwise,
139.1018 -     * the {@code char} value at the given index is returned.
139.1019 -     *
139.1020 -     * @param a the {@code char} array
139.1021 -     * @param index the index to the {@code char} values (Unicode
139.1022 -     * code units) in the {@code char} array to be converted
139.1023 -     * @param limit the index after the last array element that
139.1024 -     * can be used in the {@code char} array
139.1025 -     * @return the Unicode code point at the given index
139.1026 -     * @exception NullPointerException if {@code a} is null.
139.1027 -     * @exception IndexOutOfBoundsException if the {@code index}
139.1028 -     * argument is negative or not less than the {@code limit}
139.1029 -     * argument, or if the {@code limit} argument is negative or
139.1030 -     * greater than the length of the {@code char} array.
139.1031 -     * @since  1.5
139.1032 -     */
139.1033 -    public static int codePointAt(char[] a, int index, int limit) {
139.1034 -        if (index >= limit || limit < 0 || limit > a.length) {
139.1035 -            throw new IndexOutOfBoundsException();
139.1036 -        }
139.1037 -        return codePointAtImpl(a, index, limit);
139.1038 -    }
139.1039 -
139.1040 -    // throws ArrayIndexOutofBoundsException if index out of bounds
139.1041 -    static int codePointAtImpl(char[] a, int index, int limit) {
139.1042 -        char c1 = a[index++];
139.1043 -        if (isHighSurrogate(c1)) {
139.1044 -            if (index < limit) {
139.1045 -                char c2 = a[index];
139.1046 -                if (isLowSurrogate(c2)) {
139.1047 -                    return toCodePoint(c1, c2);
139.1048 -                }
139.1049 -            }
139.1050 -        }
139.1051 -        return c1;
139.1052 -    }
139.1053 -
139.1054 -    /**
139.1055 -     * Returns the code point preceding the given index of the
139.1056 -     * {@code CharSequence}. If the {@code char} value at
139.1057 -     * {@code (index - 1)} in the {@code CharSequence} is in
139.1058 -     * the low-surrogate range, {@code (index - 2)} is not
139.1059 -     * negative, and the {@code char} value at {@code (index - 2)}
139.1060 -     * in the {@code CharSequence} is in the
139.1061 -     * high-surrogate range, then the supplementary code point
139.1062 -     * corresponding to this surrogate pair is returned. Otherwise,
139.1063 -     * the {@code char} value at {@code (index - 1)} is
139.1064 -     * returned.
139.1065 -     *
139.1066 -     * @param seq the {@code CharSequence} instance
139.1067 -     * @param index the index following the code point that should be returned
139.1068 -     * @return the Unicode code point value before the given index.
139.1069 -     * @exception NullPointerException if {@code seq} is null.
139.1070 -     * @exception IndexOutOfBoundsException if the {@code index}
139.1071 -     * argument is less than 1 or greater than {@link
139.1072 -     * CharSequence#length() seq.length()}.
139.1073 -     * @since  1.5
139.1074 -     */
139.1075 -    public static int codePointBefore(CharSequence seq, int index) {
139.1076 -        char c2 = seq.charAt(--index);
139.1077 -        if (isLowSurrogate(c2)) {
139.1078 -            if (index > 0) {
139.1079 -                char c1 = seq.charAt(--index);
139.1080 -                if (isHighSurrogate(c1)) {
139.1081 -                    return toCodePoint(c1, c2);
139.1082 -                }
139.1083 -            }
139.1084 -        }
139.1085 -        return c2;
139.1086 -    }
139.1087 -
139.1088 -    /**
139.1089 -     * Returns the code point preceding the given index of the
139.1090 -     * {@code char} array. If the {@code char} value at
139.1091 -     * {@code (index - 1)} in the {@code char} array is in
139.1092 -     * the low-surrogate range, {@code (index - 2)} is not
139.1093 -     * negative, and the {@code char} value at {@code (index - 2)}
139.1094 -     * in the {@code char} array is in the
139.1095 -     * high-surrogate range, then the supplementary code point
139.1096 -     * corresponding to this surrogate pair is returned. Otherwise,
139.1097 -     * the {@code char} value at {@code (index - 1)} is
139.1098 -     * returned.
139.1099 -     *
139.1100 -     * @param a the {@code char} array
139.1101 -     * @param index the index following the code point that should be returned
139.1102 -     * @return the Unicode code point value before the given index.
139.1103 -     * @exception NullPointerException if {@code a} is null.
139.1104 -     * @exception IndexOutOfBoundsException if the {@code index}
139.1105 -     * argument is less than 1 or greater than the length of the
139.1106 -     * {@code char} array
139.1107 -     * @since  1.5
139.1108 -     */
139.1109 -    public static int codePointBefore(char[] a, int index) {
139.1110 -        return codePointBeforeImpl(a, index, 0);
139.1111 -    }
139.1112 -
139.1113 -    /**
139.1114 -     * Returns the code point preceding the given index of the
139.1115 -     * {@code char} array, where only array elements with
139.1116 -     * {@code index} greater than or equal to {@code start}
139.1117 -     * can be used. If the {@code char} value at {@code (index - 1)}
139.1118 -     * in the {@code char} array is in the
139.1119 -     * low-surrogate range, {@code (index - 2)} is not less than
139.1120 -     * {@code start}, and the {@code char} value at
139.1121 -     * {@code (index - 2)} in the {@code char} array is in
139.1122 -     * the high-surrogate range, then the supplementary code point
139.1123 -     * corresponding to this surrogate pair is returned. Otherwise,
139.1124 -     * the {@code char} value at {@code (index - 1)} is
139.1125 -     * returned.
139.1126 -     *
139.1127 -     * @param a the {@code char} array
139.1128 -     * @param index the index following the code point that should be returned
139.1129 -     * @param start the index of the first array element in the
139.1130 -     * {@code char} array
139.1131 -     * @return the Unicode code point value before the given index.
139.1132 -     * @exception NullPointerException if {@code a} is null.
139.1133 -     * @exception IndexOutOfBoundsException if the {@code index}
139.1134 -     * argument is not greater than the {@code start} argument or
139.1135 -     * is greater than the length of the {@code char} array, or
139.1136 -     * if the {@code start} argument is negative or not less than
139.1137 -     * the length of the {@code char} array.
139.1138 -     * @since  1.5
139.1139 -     */
139.1140 -    public static int codePointBefore(char[] a, int index, int start) {
139.1141 -        if (index <= start || start < 0 || start >= a.length) {
139.1142 -            throw new IndexOutOfBoundsException();
139.1143 -        }
139.1144 -        return codePointBeforeImpl(a, index, start);
139.1145 -    }
139.1146 -
139.1147 -    // throws ArrayIndexOutofBoundsException if index-1 out of bounds
139.1148 -    static int codePointBeforeImpl(char[] a, int index, int start) {
139.1149 -        char c2 = a[--index];
139.1150 -        if (isLowSurrogate(c2)) {
139.1151 -            if (index > start) {
139.1152 -                char c1 = a[--index];
139.1153 -                if (isHighSurrogate(c1)) {
139.1154 -                    return toCodePoint(c1, c2);
139.1155 -                }
139.1156 -            }
139.1157 -        }
139.1158 -        return c2;
139.1159 -    }
139.1160 -
139.1161 -    /**
139.1162 -     * Returns the leading surrogate (a
139.1163 -     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
139.1164 -     * high surrogate code unit</a>) of the
139.1165 -     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
139.1166 -     * surrogate pair</a>
139.1167 -     * representing the specified supplementary character (Unicode
139.1168 -     * code point) in the UTF-16 encoding.  If the specified character
139.1169 -     * is not a
139.1170 -     * <a href="Character.html#supplementary">supplementary character</a>,
139.1171 -     * an unspecified {@code char} is returned.
139.1172 -     *
139.1173 -     * <p>If
139.1174 -     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
139.1175 -     * is {@code true}, then
139.1176 -     * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
139.1177 -     * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
139.1178 -     * are also always {@code true}.
139.1179 -     *
139.1180 -     * @param   codePoint a supplementary character (Unicode code point)
139.1181 -     * @return  the leading surrogate code unit used to represent the
139.1182 -     *          character in the UTF-16 encoding
139.1183 -     * @since   1.7
139.1184 -     */
139.1185 -    public static char highSurrogate(int codePoint) {
139.1186 -        return (char) ((codePoint >>> 10)
139.1187 -            + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
139.1188 -    }
139.1189 -
139.1190 -    /**
139.1191 -     * Returns the trailing surrogate (a
139.1192 -     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
139.1193 -     * low surrogate code unit</a>) of the
139.1194 -     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
139.1195 -     * surrogate pair</a>
139.1196 -     * representing the specified supplementary character (Unicode
139.1197 -     * code point) in the UTF-16 encoding.  If the specified character
139.1198 -     * is not a
139.1199 -     * <a href="Character.html#supplementary">supplementary character</a>,
139.1200 -     * an unspecified {@code char} is returned.
139.1201 -     *
139.1202 -     * <p>If
139.1203 -     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
139.1204 -     * is {@code true}, then
139.1205 -     * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
139.1206 -     * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
139.1207 -     * are also always {@code true}.
139.1208 -     *
139.1209 -     * @param   codePoint a supplementary character (Unicode code point)
139.1210 -     * @return  the trailing surrogate code unit used to represent the
139.1211 -     *          character in the UTF-16 encoding
139.1212 -     * @since   1.7
139.1213 -     */
139.1214 -    public static char lowSurrogate(int codePoint) {
139.1215 -        return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
139.1216 -    }
139.1217 -
139.1218 -    /**
139.1219 -     * Converts the specified character (Unicode code point) to its
139.1220 -     * UTF-16 representation. If the specified code point is a BMP
139.1221 -     * (Basic Multilingual Plane or Plane 0) value, the same value is
139.1222 -     * stored in {@code dst[dstIndex]}, and 1 is returned. If the
139.1223 -     * specified code point is a supplementary character, its
139.1224 -     * surrogate values are stored in {@code dst[dstIndex]}
139.1225 -     * (high-surrogate) and {@code dst[dstIndex+1]}
139.1226 -     * (low-surrogate), and 2 is returned.
139.1227 -     *
139.1228 -     * @param  codePoint the character (Unicode code point) to be converted.
139.1229 -     * @param  dst an array of {@code char} in which the
139.1230 -     * {@code codePoint}'s UTF-16 value is stored.
139.1231 -     * @param dstIndex the start index into the {@code dst}
139.1232 -     * array where the converted value is stored.
139.1233 -     * @return 1 if the code point is a BMP code point, 2 if the
139.1234 -     * code point is a supplementary code point.
139.1235 -     * @exception IllegalArgumentException if the specified
139.1236 -     * {@code codePoint} is not a valid Unicode code point.
139.1237 -     * @exception NullPointerException if the specified {@code dst} is null.
139.1238 -     * @exception IndexOutOfBoundsException if {@code dstIndex}
139.1239 -     * is negative or not less than {@code dst.length}, or if
139.1240 -     * {@code dst} at {@code dstIndex} doesn't have enough
139.1241 -     * array element(s) to store the resulting {@code char}
139.1242 -     * value(s). (If {@code dstIndex} is equal to
139.1243 -     * {@code dst.length-1} and the specified
139.1244 -     * {@code codePoint} is a supplementary character, the
139.1245 -     * high-surrogate value is not stored in
139.1246 -     * {@code dst[dstIndex]}.)
139.1247 -     * @since  1.5
139.1248 -     */
139.1249 -    public static int toChars(int codePoint, char[] dst, int dstIndex) {
139.1250 -        if (isBmpCodePoint(codePoint)) {
139.1251 -            dst[dstIndex] = (char) codePoint;
139.1252 -            return 1;
139.1253 -        } else if (isValidCodePoint(codePoint)) {
139.1254 -            toSurrogates(codePoint, dst, dstIndex);
139.1255 -            return 2;
139.1256 -        } else {
139.1257 -            throw new IllegalArgumentException();
139.1258 -        }
139.1259 -    }
139.1260 -
139.1261 -    /**
139.1262 -     * Converts the specified character (Unicode code point) to its
139.1263 -     * UTF-16 representation stored in a {@code char} array. If
139.1264 -     * the specified code point is a BMP (Basic Multilingual Plane or
139.1265 -     * Plane 0) value, the resulting {@code char} array has
139.1266 -     * the same value as {@code codePoint}. If the specified code
139.1267 -     * point is a supplementary code point, the resulting
139.1268 -     * {@code char} array has the corresponding surrogate pair.
139.1269 -     *
139.1270 -     * @param  codePoint a Unicode code point
139.1271 -     * @return a {@code char} array having
139.1272 -     *         {@code codePoint}'s UTF-16 representation.
139.1273 -     * @exception IllegalArgumentException if the specified
139.1274 -     * {@code codePoint} is not a valid Unicode code point.
139.1275 -     * @since  1.5
139.1276 -     */
139.1277 -    public static char[] toChars(int codePoint) {
139.1278 -        if (isBmpCodePoint(codePoint)) {
139.1279 -            return new char[] { (char) codePoint };
139.1280 -        } else if (isValidCodePoint(codePoint)) {
139.1281 -            char[] result = new char[2];
139.1282 -            toSurrogates(codePoint, result, 0);
139.1283 -            return result;
139.1284 -        } else {
139.1285 -            throw new IllegalArgumentException();
139.1286 -        }
139.1287 -    }
139.1288 -
139.1289 -    static void toSurrogates(int codePoint, char[] dst, int index) {
139.1290 -        // We write elements "backwards" to guarantee all-or-nothing
139.1291 -        dst[index+1] = lowSurrogate(codePoint);
139.1292 -        dst[index] = highSurrogate(codePoint);
139.1293 -    }
139.1294 -
139.1295 -    /**
139.1296 -     * Returns the number of Unicode code points in the text range of
139.1297 -     * the specified char sequence. The text range begins at the
139.1298 -     * specified {@code beginIndex} and extends to the
139.1299 -     * {@code char} at index {@code endIndex - 1}. Thus the
139.1300 -     * length (in {@code char}s) of the text range is
139.1301 -     * {@code endIndex-beginIndex}. Unpaired surrogates within
139.1302 -     * the text range count as one code point each.
139.1303 -     *
139.1304 -     * @param seq the char sequence
139.1305 -     * @param beginIndex the index to the first {@code char} of
139.1306 -     * the text range.
139.1307 -     * @param endIndex the index after the last {@code char} of
139.1308 -     * the text range.
139.1309 -     * @return the number of Unicode code points in the specified text
139.1310 -     * range
139.1311 -     * @exception NullPointerException if {@code seq} is null.
139.1312 -     * @exception IndexOutOfBoundsException if the
139.1313 -     * {@code beginIndex} is negative, or {@code endIndex}
139.1314 -     * is larger than the length of the given sequence, or
139.1315 -     * {@code beginIndex} is larger than {@code endIndex}.
139.1316 -     * @since  1.5
139.1317 -     */
139.1318 -    public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) {
139.1319 -        int length = seq.length();
139.1320 -        if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
139.1321 -            throw new IndexOutOfBoundsException();
139.1322 -        }
139.1323 -        int n = endIndex - beginIndex;
139.1324 -        for (int i = beginIndex; i < endIndex; ) {
139.1325 -            if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
139.1326 -                isLowSurrogate(seq.charAt(i))) {
139.1327 -                n--;
139.1328 -                i++;
139.1329 -            }
139.1330 -        }
139.1331 -        return n;
139.1332 -    }
139.1333 -
139.1334 -    /**
139.1335 -     * Returns the number of Unicode code points in a subarray of the
139.1336 -     * {@code char} array argument. The {@code offset}
139.1337 -     * argument is the index of the first {@code char} of the
139.1338 -     * subarray and the {@code count} argument specifies the
139.1339 -     * length of the subarray in {@code char}s. Unpaired
139.1340 -     * surrogates within the subarray count as one code point each.
139.1341 -     *
139.1342 -     * @param a the {@code char} array
139.1343 -     * @param offset the index of the first {@code char} in the
139.1344 -     * given {@code char} array
139.1345 -     * @param count the length of the subarray in {@code char}s
139.1346 -     * @return the number of Unicode code points in the specified subarray
139.1347 -     * @exception NullPointerException if {@code a} is null.
139.1348 -     * @exception IndexOutOfBoundsException if {@code offset} or
139.1349 -     * {@code count} is negative, or if {@code offset +
139.1350 -     * count} is larger than the length of the given array.
139.1351 -     * @since  1.5
139.1352 -     */
139.1353 -    public static int codePointCount(char[] a, int offset, int count) {
139.1354 -        if (count > a.length - offset || offset < 0 || count < 0) {
139.1355 -            throw new IndexOutOfBoundsException();
139.1356 -        }
139.1357 -        return codePointCountImpl(a, offset, count);
139.1358 -    }
139.1359 -
139.1360 -    static int codePointCountImpl(char[] a, int offset, int count) {
139.1361 -        int endIndex = offset + count;
139.1362 -        int n = count;
139.1363 -        for (int i = offset; i < endIndex; ) {
139.1364 -            if (isHighSurrogate(a[i++]) && i < endIndex &&
139.1365 -                isLowSurrogate(a[i])) {
139.1366 -                n--;
139.1367 -                i++;
139.1368 -            }
139.1369 -        }
139.1370 -        return n;
139.1371 -    }
139.1372 -
139.1373 -    /**
139.1374 -     * Returns the index within the given char sequence that is offset
139.1375 -     * from the given {@code index} by {@code codePointOffset}
139.1376 -     * code points. Unpaired surrogates within the text range given by
139.1377 -     * {@code index} and {@code codePointOffset} count as
139.1378 -     * one code point each.
139.1379 -     *
139.1380 -     * @param seq the char sequence
139.1381 -     * @param index the index to be offset
139.1382 -     * @param codePointOffset the offset in code points
139.1383 -     * @return the index within the char sequence
139.1384 -     * @exception NullPointerException if {@code seq} is null.
139.1385 -     * @exception IndexOutOfBoundsException if {@code index}
139.1386 -     *   is negative or larger then the length of the char sequence,
139.1387 -     *   or if {@code codePointOffset} is positive and the
139.1388 -     *   subsequence starting with {@code index} has fewer than
139.1389 -     *   {@code codePointOffset} code points, or if
139.1390 -     *   {@code codePointOffset} is negative and the subsequence
139.1391 -     *   before {@code index} has fewer than the absolute value
139.1392 -     *   of {@code codePointOffset} code points.
139.1393 -     * @since 1.5
139.1394 -     */
139.1395 -    public static int offsetByCodePoints(CharSequence seq, int index,
139.1396 -                                         int codePointOffset) {
139.1397 -        int length = seq.length();
139.1398 -        if (index < 0 || index > length) {
139.1399 -            throw new IndexOutOfBoundsException();
139.1400 -        }
139.1401 -
139.1402 -        int x = index;
139.1403 -        if (codePointOffset >= 0) {
139.1404 -            int i;
139.1405 -            for (i = 0; x < length && i < codePointOffset; i++) {
139.1406 -                if (isHighSurrogate(seq.charAt(x++)) && x < length &&
139.1407 -                    isLowSurrogate(seq.charAt(x))) {
139.1408 -                    x++;
139.1409 -                }
139.1410 -            }
139.1411 -            if (i < codePointOffset) {
139.1412 -                throw new IndexOutOfBoundsException();
139.1413 -            }
139.1414 -        } else {
139.1415 -            int i;
139.1416 -            for (i = codePointOffset; x > 0 && i < 0; i++) {
139.1417 -                if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
139.1418 -                    isHighSurrogate(seq.charAt(x-1))) {
139.1419 -                    x--;
139.1420 -                }
139.1421 -            }
139.1422 -            if (i < 0) {
139.1423 -                throw new IndexOutOfBoundsException();
139.1424 -            }
139.1425 -        }
139.1426 -        return x;
139.1427 -    }
139.1428 -
139.1429 -    /**
139.1430 -     * Returns the index within the given {@code char} subarray
139.1431 -     * that is offset from the given {@code index} by
139.1432 -     * {@code codePointOffset} code points. The
139.1433 -     * {@code start} and {@code count} arguments specify a
139.1434 -     * subarray of the {@code char} array. Unpaired surrogates
139.1435 -     * within the text range given by {@code index} and
139.1436 -     * {@code codePointOffset} count as one code point each.
139.1437 -     *
139.1438 -     * @param a the {@code char} array
139.1439 -     * @param start the index of the first {@code char} of the
139.1440 -     * subarray
139.1441 -     * @param count the length of the subarray in {@code char}s
139.1442 -     * @param index the index to be offset
139.1443 -     * @param codePointOffset the offset in code points
139.1444 -     * @return the index within the subarray
139.1445 -     * @exception NullPointerException if {@code a} is null.
139.1446 -     * @exception IndexOutOfBoundsException
139.1447 -     *   if {@code start} or {@code count} is negative,
139.1448 -     *   or if {@code start + count} is larger than the length of
139.1449 -     *   the given array,
139.1450 -     *   or if {@code index} is less than {@code start} or
139.1451 -     *   larger then {@code start + count},
139.1452 -     *   or if {@code codePointOffset} is positive and the text range
139.1453 -     *   starting with {@code index} and ending with {@code start + count - 1}
139.1454 -     *   has fewer than {@code codePointOffset} code
139.1455 -     *   points,
139.1456 -     *   or if {@code codePointOffset} is negative and the text range
139.1457 -     *   starting with {@code start} and ending with {@code index - 1}
139.1458 -     *   has fewer than the absolute value of
139.1459 -     *   {@code codePointOffset} code points.
139.1460 -     * @since 1.5
139.1461 -     */
139.1462 -    public static int offsetByCodePoints(char[] a, int start, int count,
139.1463 -                                         int index, int codePointOffset) {
139.1464 -        if (count > a.length-start || start < 0 || count < 0
139.1465 -            || index < start || index > start+count) {
139.1466 -            throw new IndexOutOfBoundsException();
139.1467 -        }
139.1468 -        return offsetByCodePointsImpl(a, start, count, index, codePointOffset);
139.1469 -    }
139.1470 -
139.1471 -    static int offsetByCodePointsImpl(char[]a, int start, int count,
139.1472 -                                      int index, int codePointOffset) {
139.1473 -        int x = index;
139.1474 -        if (codePointOffset >= 0) {
139.1475 -            int limit = start + count;
139.1476 -            int i;
139.1477 -            for (i = 0; x < limit && i < codePointOffset; i++) {
139.1478 -                if (isHighSurrogate(a[x++]) && x < limit &&
139.1479 -                    isLowSurrogate(a[x])) {
139.1480 -                    x++;
139.1481 -                }
139.1482 -            }
139.1483 -            if (i < codePointOffset) {
139.1484 -                throw new IndexOutOfBoundsException();
139.1485 -            }
139.1486 -        } else {
139.1487 -            int i;
139.1488 -            for (i = codePointOffset; x > start && i < 0; i++) {
139.1489 -                if (isLowSurrogate(a[--x]) && x > start &&
139.1490 -                    isHighSurrogate(a[x-1])) {
139.1491 -                    x--;
139.1492 -                }
139.1493 -            }
139.1494 -            if (i < 0) {
139.1495 -                throw new IndexOutOfBoundsException();
139.1496 -            }
139.1497 -        }
139.1498 -        return x;
139.1499 -    }
139.1500 -
139.1501 -    /**
139.1502 -     * Determines if the specified character is a lowercase character.
139.1503 -     * <p>
139.1504 -     * A character is lowercase if its general category type, provided
139.1505 -     * by {@code Character.getType(ch)}, is
139.1506 -     * {@code LOWERCASE_LETTER}, or it has contributory property
139.1507 -     * Other_Lowercase as defined by the Unicode Standard.
139.1508 -     * <p>
139.1509 -     * The following are examples of lowercase characters:
139.1510 -     * <p><blockquote><pre>
139.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
139.1512 -     * '&#92;u00DF' '&#92;u00E0' '&#92;u00E1' '&#92;u00E2' '&#92;u00E3' '&#92;u00E4' '&#92;u00E5' '&#92;u00E6'
139.1513 -     * '&#92;u00E7' '&#92;u00E8' '&#92;u00E9' '&#92;u00EA' '&#92;u00EB' '&#92;u00EC' '&#92;u00ED' '&#92;u00EE'
139.1514 -     * '&#92;u00EF' '&#92;u00F0' '&#92;u00F1' '&#92;u00F2' '&#92;u00F3' '&#92;u00F4' '&#92;u00F5' '&#92;u00F6'
139.1515 -     * '&#92;u00F8' '&#92;u00F9' '&#92;u00FA' '&#92;u00FB' '&#92;u00FC' '&#92;u00FD' '&#92;u00FE' '&#92;u00FF'
139.1516 -     * </pre></blockquote>
139.1517 -     * <p> Many other Unicode characters are lowercase too.
139.1518 -     *
139.1519 -     * <p><b>Note:</b> This method cannot handle <a
139.1520 -     * href="#supplementary"> supplementary characters</a>. To support
139.1521 -     * all Unicode characters, including supplementary characters, use
139.1522 -     * the {@link #isLowerCase(int)} method.
139.1523 -     *
139.1524 -     * @param   ch   the character to be tested.
139.1525 -     * @return  {@code true} if the character is lowercase;
139.1526 -     *          {@code false} otherwise.
139.1527 -     * @see     Character#isLowerCase(char)
139.1528 -     * @see     Character#isTitleCase(char)
139.1529 -     * @see     Character#toLowerCase(char)
139.1530 -     * @see     Character#getType(char)
139.1531 -     */
139.1532 -    public static boolean isLowerCase(char ch) {
139.1533 -        return ch == toLowerCase(ch);
139.1534 -    }
139.1535 -
139.1536 -    /**
139.1537 -     * Determines if the specified character is an uppercase character.
139.1538 -     * <p>
139.1539 -     * A character is uppercase if its general category type, provided by
139.1540 -     * {@code Character.getType(ch)}, is {@code UPPERCASE_LETTER}.
139.1541 -     * or it has contributory property Other_Uppercase as defined by the Unicode Standard.
139.1542 -     * <p>
139.1543 -     * The following are examples of uppercase characters:
139.1544 -     * <p><blockquote><pre>
139.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
139.1546 -     * '&#92;u00C0' '&#92;u00C1' '&#92;u00C2' '&#92;u00C3' '&#92;u00C4' '&#92;u00C5' '&#92;u00C6' '&#92;u00C7'
139.1547 -     * '&#92;u00C8' '&#92;u00C9' '&#92;u00CA' '&#92;u00CB' '&#92;u00CC' '&#92;u00CD' '&#92;u00CE' '&#92;u00CF'
139.1548 -     * '&#92;u00D0' '&#92;u00D1' '&#92;u00D2' '&#92;u00D3' '&#92;u00D4' '&#92;u00D5' '&#92;u00D6' '&#92;u00D8'
139.1549 -     * '&#92;u00D9' '&#92;u00DA' '&#92;u00DB' '&#92;u00DC' '&#92;u00DD' '&#92;u00DE'
139.1550 -     * </pre></blockquote>
139.1551 -     * <p> Many other Unicode characters are uppercase too.<p>
139.1552 -     *
139.1553 -     * <p><b>Note:</b> This method cannot handle <a
139.1554 -     * href="#supplementary"> supplementary characters</a>. To support
139.1555 -     * all Unicode characters, including supplementary characters, use
139.1556 -     * the {@link #isUpperCase(int)} method.
139.1557 -     *
139.1558 -     * @param   ch   the character to be tested.
139.1559 -     * @return  {@code true} if the character is uppercase;
139.1560 -     *          {@code false} otherwise.
139.1561 -     * @see     Character#isLowerCase(char)
139.1562 -     * @see     Character#isTitleCase(char)
139.1563 -     * @see     Character#toUpperCase(char)
139.1564 -     * @see     Character#getType(char)
139.1565 -     * @since   1.0
139.1566 -     */
139.1567 -    public static boolean isUpperCase(char ch) {
139.1568 -        return ch == toUpperCase(ch);
139.1569 -    }
139.1570 -
139.1571 -    /**
139.1572 -     * Determines if the specified character is a titlecase character.
139.1573 -     * <p>
139.1574 -     * A character is a titlecase character if its general
139.1575 -     * category type, provided by {@code Character.getType(ch)},
139.1576 -     * is {@code TITLECASE_LETTER}.
139.1577 -     * <p>
139.1578 -     * Some characters look like pairs of Latin letters. For example, there
139.1579 -     * is an uppercase letter that looks like "LJ" and has a corresponding
139.1580 -     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
139.1581 -     * is the appropriate form to use when rendering a word in lowercase
139.1582 -     * with initial capitals, as for a book title.
139.1583 -     * <p>
139.1584 -     * These are some of the Unicode characters for which this method returns
139.1585 -     * {@code true}:
139.1586 -     * <ul>
139.1587 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
139.1588 -     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
139.1589 -     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
139.1590 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
139.1591 -     * </ul>
139.1592 -     * <p> Many other Unicode characters are titlecase too.<p>
139.1593 -     *
139.1594 -     * <p><b>Note:</b> This method cannot handle <a
139.1595 -     * href="#supplementary"> supplementary characters</a>. To support
139.1596 -     * all Unicode characters, including supplementary characters, use
139.1597 -     * the {@link #isTitleCase(int)} method.
139.1598 -     *
139.1599 -     * @param   ch   the character to be tested.
139.1600 -     * @return  {@code true} if the character is titlecase;
139.1601 -     *          {@code false} otherwise.
139.1602 -     * @see     Character#isLowerCase(char)
139.1603 -     * @see     Character#isUpperCase(char)
139.1604 -     * @see     Character#toTitleCase(char)
139.1605 -     * @see     Character#getType(char)
139.1606 -     * @since   1.0.2
139.1607 -     */
139.1608 -    public static boolean isTitleCase(char ch) {
139.1609 -        return isTitleCase((int)ch);
139.1610 -    }
139.1611 -
139.1612 -    /**
139.1613 -     * Determines if the specified character (Unicode code point) is a titlecase character.
139.1614 -     * <p>
139.1615 -     * A character is a titlecase character if its general
139.1616 -     * category type, provided by {@link Character#getType(int) getType(codePoint)},
139.1617 -     * is {@code TITLECASE_LETTER}.
139.1618 -     * <p>
139.1619 -     * Some characters look like pairs of Latin letters. For example, there
139.1620 -     * is an uppercase letter that looks like "LJ" and has a corresponding
139.1621 -     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
139.1622 -     * is the appropriate form to use when rendering a word in lowercase
139.1623 -     * with initial capitals, as for a book title.
139.1624 -     * <p>
139.1625 -     * These are some of the Unicode characters for which this method returns
139.1626 -     * {@code true}:
139.1627 -     * <ul>
139.1628 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
139.1629 -     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
139.1630 -     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
139.1631 -     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
139.1632 -     * </ul>
139.1633 -     * <p> Many other Unicode characters are titlecase too.<p>
139.1634 -     *
139.1635 -     * @param   codePoint the character (Unicode code point) to be tested.
139.1636 -     * @return  {@code true} if the character is titlecase;
139.1637 -     *          {@code false} otherwise.
139.1638 -     * @see     Character#isLowerCase(int)
139.1639 -     * @see     Character#isUpperCase(int)
139.1640 -     * @see     Character#toTitleCase(int)
139.1641 -     * @see     Character#getType(int)
139.1642 -     * @since   1.5
139.1643 -     */
139.1644 -    public static boolean isTitleCase(int codePoint) {
139.1645 -        return getType(codePoint) == Character.TITLECASE_LETTER;
139.1646 -    }
139.1647 -
139.1648 -    /**
139.1649 -     * Determines if the specified character is a digit.
139.1650 -     * <p>
139.1651 -     * A character is a digit if its general category type, provided
139.1652 -     * by {@code Character.getType(ch)}, is
139.1653 -     * {@code DECIMAL_DIGIT_NUMBER}.
139.1654 -     * <p>
139.1655 -     * Some Unicode character ranges that contain digits:
139.1656 -     * <ul>
139.1657 -     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
139.1658 -     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
139.1659 -     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
139.1660 -     *     Arabic-Indic digits
139.1661 -     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
139.1662 -     *     Extended Arabic-Indic digits
139.1663 -     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
139.1664 -     *     Devanagari digits
139.1665 -     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
139.1666 -     *     Fullwidth digits
139.1667 -     * </ul>
139.1668 -     *
139.1669 -     * Many other character ranges contain digits as well.
139.1670 -     *
139.1671 -     * <p><b>Note:</b> This method cannot handle <a
139.1672 -     * href="#supplementary"> supplementary characters</a>. To support
139.1673 -     * all Unicode characters, including supplementary characters, use
139.1674 -     * the {@link #isDigit(int)} method.
139.1675 -     *
139.1676 -     * @param   ch   the character to be tested.
139.1677 -     * @return  {@code true} if the character is a digit;
139.1678 -     *          {@code false} otherwise.
139.1679 -     * @see     Character#digit(char, int)
139.1680 -     * @see     Character#forDigit(int, int)
139.1681 -     * @see     Character#getType(char)
139.1682 -     */
139.1683 -    public static boolean isDigit(char ch) {
139.1684 -        return String.valueOf(ch).matches("\\d");
139.1685 -    }
139.1686 -
139.1687 -    /**
139.1688 -     * Determines if the specified character (Unicode code point) is a digit.
139.1689 -     * <p>
139.1690 -     * A character is a digit if its general category type, provided
139.1691 -     * by {@link Character#getType(int) getType(codePoint)}, is
139.1692 -     * {@code DECIMAL_DIGIT_NUMBER}.
139.1693 -     * <p>
139.1694 -     * Some Unicode character ranges that contain digits:
139.1695 -     * <ul>
139.1696 -     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
139.1697 -     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
139.1698 -     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
139.1699 -     *     Arabic-Indic digits
139.1700 -     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
139.1701 -     *     Extended Arabic-Indic digits
139.1702 -     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
139.1703 -     *     Devanagari digits
139.1704 -     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
139.1705 -     *     Fullwidth digits
139.1706 -     * </ul>
139.1707 -     *
139.1708 -     * Many other character ranges contain digits as well.
139.1709 -     *
139.1710 -     * @param   codePoint the character (Unicode code point) to be tested.
139.1711 -     * @return  {@code true} if the character is a digit;
139.1712 -     *          {@code false} otherwise.
139.1713 -     * @see     Character#forDigit(int, int)
139.1714 -     * @see     Character#getType(int)
139.1715 -     * @since   1.5
139.1716 -     */
139.1717 -    public static boolean isDigit(int codePoint) {
139.1718 -        return fromCodeChars(codePoint).matches("\\d");
139.1719 -    }
139.1720 -    
139.1721 -    @JavaScriptBody(args = "c", body = "return String.fromCharCode(c);")
139.1722 -    private native static String fromCodeChars(int codePoint);
139.1723 -
139.1724 -    /**
139.1725 -     * Determines if a character is defined in Unicode.
139.1726 -     * <p>
139.1727 -     * A character is defined if at least one of the following is true:
139.1728 -     * <ul>
139.1729 -     * <li>It has an entry in the UnicodeData file.
139.1730 -     * <li>It has a value in a range defined by the UnicodeData file.
139.1731 -     * </ul>
139.1732 -     *
139.1733 -     * <p><b>Note:</b> This method cannot handle <a
139.1734 -     * href="#supplementary"> supplementary characters</a>. To support
139.1735 -     * all Unicode characters, including supplementary characters, use
139.1736 -     * the {@link #isDefined(int)} method.
139.1737 -     *
139.1738 -     * @param   ch   the character to be tested
139.1739 -     * @return  {@code true} if the character has a defined meaning
139.1740 -     *          in Unicode; {@code false} otherwise.
139.1741 -     * @see     Character#isDigit(char)
139.1742 -     * @see     Character#isLetter(char)
139.1743 -     * @see     Character#isLetterOrDigit(char)
139.1744 -     * @see     Character#isLowerCase(char)
139.1745 -     * @see     Character#isTitleCase(char)
139.1746 -     * @see     Character#isUpperCase(char)
139.1747 -     * @since   1.0.2
139.1748 -     */
139.1749 -    public static boolean isDefined(char ch) {
139.1750 -        return isDefined((int)ch);
139.1751 -    }
139.1752 -
139.1753 -    /**
139.1754 -     * Determines if a character (Unicode code point) is defined in Unicode.
139.1755 -     * <p>
139.1756 -     * A character is defined if at least one of the following is true:
139.1757 -     * <ul>
139.1758 -     * <li>It has an entry in the UnicodeData file.
139.1759 -     * <li>It has a value in a range defined by the UnicodeData file.
139.1760 -     * </ul>
139.1761 -     *
139.1762 -     * @param   codePoint the character (Unicode code point) to be tested.
139.1763 -     * @return  {@code true} if the character has a defined meaning
139.1764 -     *          in Unicode; {@code false} otherwise.
139.1765 -     * @see     Character#isDigit(int)
139.1766 -     * @see     Character#isLetter(int)
139.1767 -     * @see     Character#isLetterOrDigit(int)
139.1768 -     * @see     Character#isLowerCase(int)
139.1769 -     * @see     Character#isTitleCase(int)
139.1770 -     * @see     Character#isUpperCase(int)
139.1771 -     * @since   1.5
139.1772 -     */
139.1773 -    public static boolean isDefined(int codePoint) {
139.1774 -        return getType(codePoint) != Character.UNASSIGNED;
139.1775 -    }
139.1776 -
139.1777 -    /**
139.1778 -     * Determines if the specified character is a letter.
139.1779 -     * <p>
139.1780 -     * A character is considered to be a letter if its general
139.1781 -     * category type, provided by {@code Character.getType(ch)},
139.1782 -     * is any of the following:
139.1783 -     * <ul>
139.1784 -     * <li> {@code UPPERCASE_LETTER}
139.1785 -     * <li> {@code LOWERCASE_LETTER}
139.1786 -     * <li> {@code TITLECASE_LETTER}
139.1787 -     * <li> {@code MODIFIER_LETTER}
139.1788 -     * <li> {@code OTHER_LETTER}
139.1789 -     * </ul>
139.1790 -     *
139.1791 -     * Not all letters have case. Many characters are
139.1792 -     * letters but are neither uppercase nor lowercase nor titlecase.
139.1793 -     *
139.1794 -     * <p><b>Note:</b> This method cannot handle <a
139.1795 -     * href="#supplementary"> supplementary characters</a>. To support
139.1796 -     * all Unicode characters, including supplementary characters, use
139.1797 -     * the {@link #isLetter(int)} method.
139.1798 -     *
139.1799 -     * @param   ch   the character to be tested.
139.1800 -     * @return  {@code true} if the character is a letter;
139.1801 -     *          {@code false} otherwise.
139.1802 -     * @see     Character#isDigit(char)
139.1803 -     * @see     Character#isJavaIdentifierStart(char)
139.1804 -     * @see     Character#isJavaLetter(char)
139.1805 -     * @see     Character#isJavaLetterOrDigit(char)
139.1806 -     * @see     Character#isLetterOrDigit(char)
139.1807 -     * @see     Character#isLowerCase(char)
139.1808 -     * @see     Character#isTitleCase(char)
139.1809 -     * @see     Character#isUnicodeIdentifierStart(char)
139.1810 -     * @see     Character#isUpperCase(char)
139.1811 -     */
139.1812 -    public static boolean isLetter(char ch) {
139.1813 -        return String.valueOf(ch).matches("\\w") && !isDigit(ch);
139.1814 -    }
139.1815 -
139.1816 -    /**
139.1817 -     * Determines if the specified character (Unicode code point) is a letter.
139.1818 -     * <p>
139.1819 -     * A character is considered to be a letter if its general
139.1820 -     * category type, provided by {@link Character#getType(int) getType(codePoint)},
139.1821 -     * is any of the following:
139.1822 -     * <ul>
139.1823 -     * <li> {@code UPPERCASE_LETTER}
139.1824 -     * <li> {@code LOWERCASE_LETTER}
139.1825 -     * <li> {@code TITLECASE_LETTER}
139.1826 -     * <li> {@code MODIFIER_LETTER}
139.1827 -     * <li> {@code OTHER_LETTER}
139.1828 -     * </ul>
139.1829 -     *
139.1830 -     * Not all letters have case. Many characters are
139.1831 -     * letters but are neither uppercase nor lowercase nor titlecase.
139.1832 -     *
139.1833 -     * @param   codePoint the character (Unicode code point) to be tested.
139.1834 -     * @return  {@code true} if the character is a letter;
139.1835 -     *          {@code false} otherwise.
139.1836 -     * @see     Character#isDigit(int)
139.1837 -     * @see     Character#isJavaIdentifierStart(int)
139.1838 -     * @see     Character#isLetterOrDigit(int)
139.1839 -     * @see     Character#isLowerCase(int)
139.1840 -     * @see     Character#isTitleCase(int)
139.1841 -     * @see     Character#isUnicodeIdentifierStart(int)
139.1842 -     * @see     Character#isUpperCase(int)
139.1843 -     * @since   1.5
139.1844 -     */
139.1845 -    public static boolean isLetter(int codePoint) {
139.1846 -        return fromCodeChars(codePoint).matches("\\w") && !isDigit(codePoint);
139.1847 -    }
139.1848 -
139.1849 -    /**
139.1850 -     * Determines if the specified character is a letter or digit.
139.1851 -     * <p>
139.1852 -     * A character is considered to be a letter or digit if either
139.1853 -     * {@code Character.isLetter(char ch)} or
139.1854 -     * {@code Character.isDigit(char ch)} returns
139.1855 -     * {@code true} for the character.
139.1856 -     *
139.1857 -     * <p><b>Note:</b> This method cannot handle <a
139.1858 -     * href="#supplementary"> supplementary characters</a>. To support
139.1859 -     * all Unicode characters, including supplementary characters, use
139.1860 -     * the {@link #isLetterOrDigit(int)} method.
139.1861 -     *
139.1862 -     * @param   ch   the character to be tested.
139.1863 -     * @return  {@code true} if the character is a letter or digit;
139.1864 -     *          {@code false} otherwise.
139.1865 -     * @see     Character#isDigit(char)
139.1866 -     * @see     Character#isJavaIdentifierPart(char)
139.1867 -     * @see     Character#isJavaLetter(char)
139.1868 -     * @see     Character#isJavaLetterOrDigit(char)
139.1869 -     * @see     Character#isLetter(char)
139.1870 -     * @see     Character#isUnicodeIdentifierPart(char)
139.1871 -     * @since   1.0.2
139.1872 -     */
139.1873 -    public static boolean isLetterOrDigit(char ch) {
139.1874 -        return String.valueOf(ch).matches("\\w");
139.1875 -    }
139.1876 -
139.1877 -    /**
139.1878 -     * Determines if the specified character (Unicode code point) is a letter or digit.
139.1879 -     * <p>
139.1880 -     * A character is considered to be a letter or digit if either
139.1881 -     * {@link #isLetter(int) isLetter(codePoint)} or
139.1882 -     * {@link #isDigit(int) isDigit(codePoint)} returns
139.1883 -     * {@code true} for the character.
139.1884 -     *
139.1885 -     * @param   codePoint the character (Unicode code point) to be tested.
139.1886 -     * @return  {@code true} if the character is a letter or digit;
139.1887 -     *          {@code false} otherwise.
139.1888 -     * @see     Character#isDigit(int)
139.1889 -     * @see     Character#isJavaIdentifierPart(int)
139.1890 -     * @see     Character#isLetter(int)
139.1891 -     * @see     Character#isUnicodeIdentifierPart(int)
139.1892 -     * @since   1.5
139.1893 -     */
139.1894 -    public static boolean isLetterOrDigit(int codePoint) {
139.1895 -        return fromCodeChars(codePoint).matches("\\w");
139.1896 -    }
139.1897 -    
139.1898 -    static int getType(int x) {
139.1899 -        throw new UnsupportedOperationException();
139.1900 -    }
139.1901 - 
139.1902 -    /**
139.1903 -     * Determines if the specified character is
139.1904 -     * permissible as the first character in a Java identifier.
139.1905 -     * <p>
139.1906 -     * A character may start a Java identifier if and only if
139.1907 -     * one of the following conditions is true:
139.1908 -     * <ul>
139.1909 -     * <li> {@link #isLetter(char) isLetter(ch)} returns {@code true}
139.1910 -     * <li> {@link #getType(char) getType(ch)} returns {@code LETTER_NUMBER}
139.1911 -     * <li> {@code ch} is a currency symbol (such as {@code '$'})
139.1912 -     * <li> {@code ch} is a connecting punctuation character (such as {@code '_'}).
139.1913 -     * </ul>
139.1914 -     *
139.1915 -     * <p><b>Note:</b> This method cannot handle <a
139.1916 -     * href="#supplementary"> supplementary characters</a>. To support
139.1917 -     * all Unicode characters, including supplementary characters, use
139.1918 -     * the {@link #isJavaIdentifierStart(int)} method.
139.1919 -     *
139.1920 -     * @param   ch the character to be tested.
139.1921 -     * @return  {@code true} if the character may start a Java identifier;
139.1922 -     *          {@code false} otherwise.
139.1923 -     * @see     Character#isJavaIdentifierPart(char)
139.1924 -     * @see     Character#isLetter(char)
139.1925 -     * @see     Character#isUnicodeIdentifierStart(char)
139.1926 -     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
139.1927 -     * @since   1.1
139.1928 -     */
139.1929 -    public static boolean isJavaIdentifierStart(char ch) {
139.1930 -        return isJavaIdentifierStart((int)ch);
139.1931 -    }
139.1932 -
139.1933 -    /**
139.1934 -     * Determines if the character (Unicode code point) is
139.1935 -     * permissible as the first character in a Java identifier.
139.1936 -     * <p>
139.1937 -     * A character may start a Java identifier if and only if
139.1938 -     * one of the following conditions is true:
139.1939 -     * <ul>
139.1940 -     * <li> {@link #isLetter(int) isLetter(codePoint)}
139.1941 -     *      returns {@code true}
139.1942 -     * <li> {@link #getType(int) getType(codePoint)}
139.1943 -     *      returns {@code LETTER_NUMBER}
139.1944 -     * <li> the referenced character is a currency symbol (such as {@code '$'})
139.1945 -     * <li> the referenced character is a connecting punctuation character
139.1946 -     *      (such as {@code '_'}).
139.1947 -     * </ul>
139.1948 -     *
139.1949 -     * @param   codePoint the character (Unicode code point) to be tested.
139.1950 -     * @return  {@code true} if the character may start a Java identifier;
139.1951 -     *          {@code false} otherwise.
139.1952 -     * @see     Character#isJavaIdentifierPart(int)
139.1953 -     * @see     Character#isLetter(int)
139.1954 -     * @see     Character#isUnicodeIdentifierStart(int)
139.1955 -     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
139.1956 -     * @since   1.5
139.1957 -     */
139.1958 -    public static boolean isJavaIdentifierStart(int codePoint) {
139.1959 -        return 
139.1960 -            ('A' <= codePoint && codePoint <= 'Z') ||
139.1961 -            ('a' <= codePoint && codePoint <= 'z');
139.1962 -    }
139.1963 -
139.1964 -    /**
139.1965 -     * Determines if the specified character may be part of a Java
139.1966 -     * identifier as other than the first character.
139.1967 -     * <p>
139.1968 -     * A character may be part of a Java identifier if any of the following
139.1969 -     * are true:
139.1970 -     * <ul>
139.1971 -     * <li>  it is a letter
139.1972 -     * <li>  it is a currency symbol (such as {@code '$'})
139.1973 -     * <li>  it is a connecting punctuation character (such as {@code '_'})
139.1974 -     * <li>  it is a digit
139.1975 -     * <li>  it is a numeric letter (such as a Roman numeral character)
139.1976 -     * <li>  it is a combining mark
139.1977 -     * <li>  it is a non-spacing mark
139.1978 -     * <li> {@code isIdentifierIgnorable} returns
139.1979 -     * {@code true} for the character
139.1980 -     * </ul>
139.1981 -     *
139.1982 -     * <p><b>Note:</b> This method cannot handle <a
139.1983 -     * href="#supplementary"> supplementary characters</a>. To support
139.1984 -     * all Unicode characters, including supplementary characters, use
139.1985 -     * the {@link #isJavaIdentifierPart(int)} method.
139.1986 -     *
139.1987 -     * @param   ch      the character to be tested.
139.1988 -     * @return {@code true} if the character may be part of a
139.1989 -     *          Java identifier; {@code false} otherwise.
139.1990 -     * @see     Character#isIdentifierIgnorable(char)
139.1991 -     * @see     Character#isJavaIdentifierStart(char)
139.1992 -     * @see     Character#isLetterOrDigit(char)
139.1993 -     * @see     Character#isUnicodeIdentifierPart(char)
139.1994 -     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
139.1995 -     * @since   1.1
139.1996 -     */
139.1997 -    public static boolean isJavaIdentifierPart(char ch) {
139.1998 -        return isJavaIdentifierPart((int)ch);
139.1999 -    }
139.2000 -
139.2001 -    /**
139.2002 -     * Determines if the character (Unicode code point) may be part of a Java
139.2003 -     * identifier as other than the first character.
139.2004 -     * <p>
139.2005 -     * A character may be part of a Java identifier if any of the following
139.2006 -     * are true:
139.2007 -     * <ul>
139.2008 -     * <li>  it is a letter
139.2009 -     * <li>  it is a currency symbol (such as {@code '$'})
139.2010 -     * <li>  it is a connecting punctuation character (such as {@code '_'})
139.2011 -     * <li>  it is a digit
139.2012 -     * <li>  it is a numeric letter (such as a Roman numeral character)
139.2013 -     * <li>  it is a combining mark
139.2014 -     * <li>  it is a non-spacing mark
139.2015 -     * <li> {@link #isIdentifierIgnorable(int)
139.2016 -     * isIdentifierIgnorable(codePoint)} returns {@code true} for
139.2017 -     * the character
139.2018 -     * </ul>
139.2019 -     *
139.2020 -     * @param   codePoint the character (Unicode code point) to be tested.
139.2021 -     * @return {@code true} if the character may be part of a
139.2022 -     *          Java identifier; {@code false} otherwise.
139.2023 -     * @see     Character#isIdentifierIgnorable(int)
139.2024 -     * @see     Character#isJavaIdentifierStart(int)
139.2025 -     * @see     Character#isLetterOrDigit(int)
139.2026 -     * @see     Character#isUnicodeIdentifierPart(int)
139.2027 -     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
139.2028 -     * @since   1.5
139.2029 -     */
139.2030 -    public static boolean isJavaIdentifierPart(int codePoint) {
139.2031 -        return isJavaIdentifierStart(codePoint) ||
139.2032 -            ('0' <= codePoint && codePoint <= '9') || codePoint == '$';
139.2033 -    }
139.2034 -   
139.2035 -    /**
139.2036 -     * Converts the character argument to lowercase using case
139.2037 -     * mapping information from the UnicodeData file.
139.2038 -     * <p>
139.2039 -     * Note that
139.2040 -     * {@code Character.isLowerCase(Character.toLowerCase(ch))}
139.2041 -     * does not always return {@code true} for some ranges of
139.2042 -     * characters, particularly those that are symbols or ideographs.
139.2043 -     *
139.2044 -     * <p>In general, {@link String#toLowerCase()} should be used to map
139.2045 -     * characters to lowercase. {@code String} case mapping methods
139.2046 -     * have several benefits over {@code Character} case mapping methods.
139.2047 -     * {@code String} case mapping methods can perform locale-sensitive
139.2048 -     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
139.2049 -     * the {@code Character} case mapping methods cannot.
139.2050 -     *
139.2051 -     * <p><b>Note:</b> This method cannot handle <a
139.2052 -     * href="#supplementary"> supplementary characters</a>. To support
139.2053 -     * all Unicode characters, including supplementary characters, use
139.2054 -     * the {@link #toLowerCase(int)} method.
139.2055 -     *
139.2056 -     * @param   ch   the character to be converted.
139.2057 -     * @return  the lowercase equivalent of the character, if any;
139.2058 -     *          otherwise, the character itself.
139.2059 -     * @see     Character#isLowerCase(char)
139.2060 -     * @see     String#toLowerCase()
139.2061 -     */
139.2062 -    public static char toLowerCase(char ch) {
139.2063 -        return String.valueOf(ch).toLowerCase().charAt(0);
139.2064 -    }
139.2065 -
139.2066 -    /**
139.2067 -     * Converts the character argument to uppercase using case mapping
139.2068 -     * information from the UnicodeData file.
139.2069 -     * <p>
139.2070 -     * Note that
139.2071 -     * {@code Character.isUpperCase(Character.toUpperCase(ch))}
139.2072 -     * does not always return {@code true} for some ranges of
139.2073 -     * characters, particularly those that are symbols or ideographs.
139.2074 -     *
139.2075 -     * <p>In general, {@link String#toUpperCase()} should be used to map
139.2076 -     * characters to uppercase. {@code String} case mapping methods
139.2077 -     * have several benefits over {@code Character} case mapping methods.
139.2078 -     * {@code String} case mapping methods can perform locale-sensitive
139.2079 -     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
139.2080 -     * the {@code Character} case mapping methods cannot.
139.2081 -     *
139.2082 -     * <p><b>Note:</b> This method cannot handle <a
139.2083 -     * href="#supplementary"> supplementary characters</a>. To support
139.2084 -     * all Unicode characters, including supplementary characters, use
139.2085 -     * the {@link #toUpperCase(int)} method.
139.2086 -     *
139.2087 -     * @param   ch   the character to be converted.
139.2088 -     * @return  the uppercase equivalent of the character, if any;
139.2089 -     *          otherwise, the character itself.
139.2090 -     * @see     Character#isUpperCase(char)
139.2091 -     * @see     String#toUpperCase()
139.2092 -     */
139.2093 -    public static char toUpperCase(char ch) {
139.2094 -        return String.valueOf(ch).toUpperCase().charAt(0);
139.2095 -    }
139.2096 -
139.2097 -    /**
139.2098 -     * Returns the numeric value of the character {@code ch} in the
139.2099 -     * specified radix.
139.2100 -     * <p>
139.2101 -     * If the radix is not in the range {@code MIN_RADIX} &le;
139.2102 -     * {@code radix} &le; {@code MAX_RADIX} or if the
139.2103 -     * value of {@code ch} is not a valid digit in the specified
139.2104 -     * radix, {@code -1} is returned. A character is a valid digit
139.2105 -     * if at least one of the following is true:
139.2106 -     * <ul>
139.2107 -     * <li>The method {@code isDigit} is {@code true} of the character
139.2108 -     *     and the Unicode decimal digit value of the character (or its
139.2109 -     *     single-character decomposition) is less than the specified radix.
139.2110 -     *     In this case the decimal digit value is returned.
139.2111 -     * <li>The character is one of the uppercase Latin letters
139.2112 -     *     {@code 'A'} through {@code 'Z'} and its code is less than
139.2113 -     *     {@code radix + 'A' - 10}.
139.2114 -     *     In this case, {@code ch - 'A' + 10}
139.2115 -     *     is returned.
139.2116 -     * <li>The character is one of the lowercase Latin letters
139.2117 -     *     {@code 'a'} through {@code 'z'} and its code is less than
139.2118 -     *     {@code radix + 'a' - 10}.
139.2119 -     *     In this case, {@code ch - 'a' + 10}
139.2120 -     *     is returned.
139.2121 -     * <li>The character is one of the fullwidth uppercase Latin letters A
139.2122 -     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
139.2123 -     *     and its code is less than
139.2124 -     *     {@code radix + '\u005CuFF21' - 10}.
139.2125 -     *     In this case, {@code ch - '\u005CuFF21' + 10}
139.2126 -     *     is returned.
139.2127 -     * <li>The character is one of the fullwidth lowercase Latin letters a
139.2128 -     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
139.2129 -     *     and its code is less than
139.2130 -     *     {@code radix + '\u005CuFF41' - 10}.
139.2131 -     *     In this case, {@code ch - '\u005CuFF41' + 10}
139.2132 -     *     is returned.
139.2133 -     * </ul>
139.2134 -     *
139.2135 -     * <p><b>Note:</b> This method cannot handle <a
139.2136 -     * href="#supplementary"> supplementary characters</a>. To support
139.2137 -     * all Unicode characters, including supplementary characters, use
139.2138 -     * the {@link #digit(int, int)} method.
139.2139 -     *
139.2140 -     * @param   ch      the character to be converted.
139.2141 -     * @param   radix   the radix.
139.2142 -     * @return  the numeric value represented by the character in the
139.2143 -     *          specified radix.
139.2144 -     * @see     Character#forDigit(int, int)
139.2145 -     * @see     Character#isDigit(char)
139.2146 -     */
139.2147 -    public static int digit(char ch, int radix) {
139.2148 -        return digit((int)ch, radix);
139.2149 -    }
139.2150 -
139.2151 -    /**
139.2152 -     * Returns the numeric value of the specified character (Unicode
139.2153 -     * code point) in the specified radix.
139.2154 -     *
139.2155 -     * <p>If the radix is not in the range {@code MIN_RADIX} &le;
139.2156 -     * {@code radix} &le; {@code MAX_RADIX} or if the
139.2157 -     * character is not a valid digit in the specified
139.2158 -     * radix, {@code -1} is returned. A character is a valid digit
139.2159 -     * if at least one of the following is true:
139.2160 -     * <ul>
139.2161 -     * <li>The method {@link #isDigit(int) isDigit(codePoint)} is {@code true} of the character
139.2162 -     *     and the Unicode decimal digit value of the character (or its
139.2163 -     *     single-character decomposition) is less than the specified radix.
139.2164 -     *     In this case the decimal digit value is returned.
139.2165 -     * <li>The character is one of the uppercase Latin letters
139.2166 -     *     {@code 'A'} through {@code 'Z'} and its code is less than
139.2167 -     *     {@code radix + 'A' - 10}.
139.2168 -     *     In this case, {@code codePoint - 'A' + 10}
139.2169 -     *     is returned.
139.2170 -     * <li>The character is one of the lowercase Latin letters
139.2171 -     *     {@code 'a'} through {@code 'z'} and its code is less than
139.2172 -     *     {@code radix + 'a' - 10}.
139.2173 -     *     In this case, {@code codePoint - 'a' + 10}
139.2174 -     *     is returned.
139.2175 -     * <li>The character is one of the fullwidth uppercase Latin letters A
139.2176 -     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
139.2177 -     *     and its code is less than
139.2178 -     *     {@code radix + '\u005CuFF21' - 10}.
139.2179 -     *     In this case,
139.2180 -     *     {@code codePoint - '\u005CuFF21' + 10}
139.2181 -     *     is returned.
139.2182 -     * <li>The character is one of the fullwidth lowercase Latin letters a
139.2183 -     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
139.2184 -     *     and its code is less than
139.2185 -     *     {@code radix + '\u005CuFF41'- 10}.
139.2186 -     *     In this case,
139.2187 -     *     {@code codePoint - '\u005CuFF41' + 10}
139.2188 -     *     is returned.
139.2189 -     * </ul>
139.2190 -     *
139.2191 -     * @param   codePoint the character (Unicode code point) to be converted.
139.2192 -     * @param   radix   the radix.
139.2193 -     * @return  the numeric value represented by the character in the
139.2194 -     *          specified radix.
139.2195 -     * @see     Character#forDigit(int, int)
139.2196 -     * @see     Character#isDigit(int)
139.2197 -     * @since   1.5
139.2198 -     */
139.2199 -    @JavaScriptBody(args = { "codePoint", "radix" }, body=
139.2200 -        "var x = parseInt(String.fromCharCode(codePoint), radix);\n"
139.2201 -      + "return isNaN(x) ? -1 : x;"
139.2202 -    )
139.2203 -    public static int digit(int codePoint, int radix) {
139.2204 -        throw new UnsupportedOperationException();
139.2205 -    }
139.2206 -
139.2207 -    /**
139.2208 -     * Returns the {@code int} value that the specified Unicode
139.2209 -     * character represents. For example, the character
139.2210 -     * {@code '\u005Cu216C'} (the roman numeral fifty) will return
139.2211 -     * an int with a value of 50.
139.2212 -     * <p>
139.2213 -     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
139.2214 -     * {@code '\u005Cu005A'}), lowercase
139.2215 -     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
139.2216 -     * full width variant ({@code '\u005CuFF21'} through
139.2217 -     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
139.2218 -     * {@code '\u005CuFF5A'}) forms have numeric values from 10
139.2219 -     * through 35. This is independent of the Unicode specification,
139.2220 -     * which does not assign numeric values to these {@code char}
139.2221 -     * values.
139.2222 -     * <p>
139.2223 -     * If the character does not have a numeric value, then -1 is returned.
139.2224 -     * If the character has a numeric value that cannot be represented as a
139.2225 -     * nonnegative integer (for example, a fractional value), then -2
139.2226 -     * is returned.
139.2227 -     *
139.2228 -     * <p><b>Note:</b> This method cannot handle <a
139.2229 -     * href="#supplementary"> supplementary characters</a>. To support
139.2230 -     * all Unicode characters, including supplementary characters, use
139.2231 -     * the {@link #getNumericValue(int)} method.
139.2232 -     *
139.2233 -     * @param   ch      the character to be converted.
139.2234 -     * @return  the numeric value of the character, as a nonnegative {@code int}
139.2235 -     *           value; -2 if the character has a numeric value that is not a
139.2236 -     *          nonnegative integer; -1 if the character has no numeric value.
139.2237 -     * @see     Character#forDigit(int, int)
139.2238 -     * @see     Character#isDigit(char)
139.2239 -     * @since   1.1
139.2240 -     */
139.2241 -    public static int getNumericValue(char ch) {
139.2242 -        return getNumericValue((int)ch);
139.2243 -    }
139.2244 -
139.2245 -    /**
139.2246 -     * Returns the {@code int} value that the specified
139.2247 -     * character (Unicode code point) represents. For example, the character
139.2248 -     * {@code '\u005Cu216C'} (the Roman numeral fifty) will return
139.2249 -     * an {@code int} with a value of 50.
139.2250 -     * <p>
139.2251 -     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
139.2252 -     * {@code '\u005Cu005A'}), lowercase
139.2253 -     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
139.2254 -     * full width variant ({@code '\u005CuFF21'} through
139.2255 -     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
139.2256 -     * {@code '\u005CuFF5A'}) forms have numeric values from 10
139.2257 -     * through 35. This is independent of the Unicode specification,
139.2258 -     * which does not assign numeric values to these {@code char}
139.2259 -     * values.
139.2260 -     * <p>
139.2261 -     * If the character does not have a numeric value, then -1 is returned.
139.2262 -     * If the character has a numeric value that cannot be represented as a
139.2263 -     * nonnegative integer (for example, a fractional value), then -2
139.2264 -     * is returned.
139.2265 -     *
139.2266 -     * @param   codePoint the character (Unicode code point) to be converted.
139.2267 -     * @return  the numeric value of the character, as a nonnegative {@code int}
139.2268 -     *          value; -2 if the character has a numeric value that is not a
139.2269 -     *          nonnegative integer; -1 if the character has no numeric value.
139.2270 -     * @see     Character#forDigit(int, int)
139.2271 -     * @see     Character#isDigit(int)
139.2272 -     * @since   1.5
139.2273 -     */
139.2274 -    public static int getNumericValue(int codePoint) {
139.2275 -        throw new UnsupportedOperationException();
139.2276 -    }
139.2277 -
139.2278 -    /**
139.2279 -     * Determines if the specified character is ISO-LATIN-1 white space.
139.2280 -     * This method returns {@code true} for the following five
139.2281 -     * characters only:
139.2282 -     * <table>
139.2283 -     * <tr><td>{@code '\t'}</td>            <td>{@code U+0009}</td>
139.2284 -     *     <td>{@code HORIZONTAL TABULATION}</td></tr>
139.2285 -     * <tr><td>{@code '\n'}</td>            <td>{@code U+000A}</td>
139.2286 -     *     <td>{@code NEW LINE}</td></tr>
139.2287 -     * <tr><td>{@code '\f'}</td>            <td>{@code U+000C}</td>
139.2288 -     *     <td>{@code FORM FEED}</td></tr>
139.2289 -     * <tr><td>{@code '\r'}</td>            <td>{@code U+000D}</td>
139.2290 -     *     <td>{@code CARRIAGE RETURN}</td></tr>
139.2291 -     * <tr><td>{@code '&nbsp;'}</td>  <td>{@code U+0020}</td>
139.2292 -     *     <td>{@code SPACE}</td></tr>
139.2293 -     * </table>
139.2294 -     *
139.2295 -     * @param      ch   the character to be tested.
139.2296 -     * @return     {@code true} if the character is ISO-LATIN-1 white
139.2297 -     *             space; {@code false} otherwise.
139.2298 -     * @see        Character#isSpaceChar(char)
139.2299 -     * @see        Character#isWhitespace(char)
139.2300 -     * @deprecated Replaced by isWhitespace(char).
139.2301 -     */
139.2302 -    @Deprecated
139.2303 -    public static boolean isSpace(char ch) {
139.2304 -        return (ch <= 0x0020) &&
139.2305 -            (((((1L << 0x0009) |
139.2306 -            (1L << 0x000A) |
139.2307 -            (1L << 0x000C) |
139.2308 -            (1L << 0x000D) |
139.2309 -            (1L << 0x0020)) >> ch) & 1L) != 0);
139.2310 -    }
139.2311 -
139.2312 -
139.2313 -
139.2314 -    /**
139.2315 -     * Determines if the specified character is white space according to Java.
139.2316 -     * A character is a Java whitespace character if and only if it satisfies
139.2317 -     * one of the following criteria:
139.2318 -     * <ul>
139.2319 -     * <li> It is a Unicode space character ({@code SPACE_SEPARATOR},
139.2320 -     *      {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})
139.2321 -     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
139.2322 -     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
139.2323 -     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
139.2324 -     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
139.2325 -     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
139.2326 -     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
139.2327 -     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
139.2328 -     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
139.2329 -     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
139.2330 -     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
139.2331 -     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
139.2332 -     * </ul>
139.2333 -     *
139.2334 -     * <p><b>Note:</b> This method cannot handle <a
139.2335 -     * href="#supplementary"> supplementary characters</a>. To support
139.2336 -     * all Unicode characters, including supplementary characters, use
139.2337 -     * the {@link #isWhitespace(int)} method.
139.2338 -     *
139.2339 -     * @param   ch the character to be tested.
139.2340 -     * @return  {@code true} if the character is a Java whitespace
139.2341 -     *          character; {@code false} otherwise.
139.2342 -     * @see     Character#isSpaceChar(char)
139.2343 -     * @since   1.1
139.2344 -     */
139.2345 -    public static boolean isWhitespace(char ch) {
139.2346 -        return isWhitespace((int)ch);
139.2347 -    }
139.2348 -
139.2349 -    /**
139.2350 -     * Determines if the specified character (Unicode code point) is
139.2351 -     * white space according to Java.  A character is a Java
139.2352 -     * whitespace character if and only if it satisfies one of the
139.2353 -     * following criteria:
139.2354 -     * <ul>
139.2355 -     * <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},
139.2356 -     *      {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})
139.2357 -     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
139.2358 -     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
139.2359 -     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
139.2360 -     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
139.2361 -     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
139.2362 -     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
139.2363 -     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
139.2364 -     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
139.2365 -     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
139.2366 -     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
139.2367 -     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
139.2368 -     * </ul>
139.2369 -     * <p>
139.2370 -     *
139.2371 -     * @param   codePoint the character (Unicode code point) to be tested.
139.2372 -     * @return  {@code true} if the character is a Java whitespace
139.2373 -     *          character; {@code false} otherwise.
139.2374 -     * @see     Character#isSpaceChar(int)
139.2375 -     * @since   1.5
139.2376 -     */
139.2377 -    public static boolean isWhitespace(int codePoint) {
139.2378 -        throw new UnsupportedOperationException();
139.2379 -    }
139.2380 -
139.2381 -    /**
139.2382 -     * Determines if the specified character is an ISO control
139.2383 -     * character.  A character is considered to be an ISO control
139.2384 -     * character if its code is in the range {@code '\u005Cu0000'}
139.2385 -     * through {@code '\u005Cu001F'} or in the range
139.2386 -     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
139.2387 -     *
139.2388 -     * <p><b>Note:</b> This method cannot handle <a
139.2389 -     * href="#supplementary"> supplementary characters</a>. To support
139.2390 -     * all Unicode characters, including supplementary characters, use
139.2391 -     * the {@link #isISOControl(int)} method.
139.2392 -     *
139.2393 -     * @param   ch      the character to be tested.
139.2394 -     * @return  {@code true} if the character is an ISO control character;
139.2395 -     *          {@code false} otherwise.
139.2396 -     *
139.2397 -     * @see     Character#isSpaceChar(char)
139.2398 -     * @see     Character#isWhitespace(char)
139.2399 -     * @since   1.1
139.2400 -     */
139.2401 -    public static boolean isISOControl(char ch) {
139.2402 -        return isISOControl((int)ch);
139.2403 -    }
139.2404 -
139.2405 -    /**
139.2406 -     * Determines if the referenced character (Unicode code point) is an ISO control
139.2407 -     * character.  A character is considered to be an ISO control
139.2408 -     * character if its code is in the range {@code '\u005Cu0000'}
139.2409 -     * through {@code '\u005Cu001F'} or in the range
139.2410 -     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
139.2411 -     *
139.2412 -     * @param   codePoint the character (Unicode code point) to be tested.
139.2413 -     * @return  {@code true} if the character is an ISO control character;
139.2414 -     *          {@code false} otherwise.
139.2415 -     * @see     Character#isSpaceChar(int)
139.2416 -     * @see     Character#isWhitespace(int)
139.2417 -     * @since   1.5
139.2418 -     */
139.2419 -    public static boolean isISOControl(int codePoint) {
139.2420 -        // Optimized form of:
139.2421 -        //     (codePoint >= 0x00 && codePoint <= 0x1F) ||
139.2422 -        //     (codePoint >= 0x7F && codePoint <= 0x9F);
139.2423 -        return codePoint <= 0x9F &&
139.2424 -            (codePoint >= 0x7F || (codePoint >>> 5 == 0));
139.2425 -    }
139.2426 -
139.2427 -    /**
139.2428 -     * Determines the character representation for a specific digit in
139.2429 -     * the specified radix. If the value of {@code radix} is not a
139.2430 -     * valid radix, or the value of {@code digit} is not a valid
139.2431 -     * digit in the specified radix, the null character
139.2432 -     * ({@code '\u005Cu0000'}) is returned.
139.2433 -     * <p>
139.2434 -     * The {@code radix} argument is valid if it is greater than or
139.2435 -     * equal to {@code MIN_RADIX} and less than or equal to
139.2436 -     * {@code MAX_RADIX}. The {@code digit} argument is valid if
139.2437 -     * {@code 0 <= digit < radix}.
139.2438 -     * <p>
139.2439 -     * If the digit is less than 10, then
139.2440 -     * {@code '0' + digit} is returned. Otherwise, the value
139.2441 -     * {@code 'a' + digit - 10} is returned.
139.2442 -     *
139.2443 -     * @param   digit   the number to convert to a character.
139.2444 -     * @param   radix   the radix.
139.2445 -     * @return  the {@code char} representation of the specified digit
139.2446 -     *          in the specified radix.
139.2447 -     * @see     Character#MIN_RADIX
139.2448 -     * @see     Character#MAX_RADIX
139.2449 -     * @see     Character#digit(char, int)
139.2450 -     */
139.2451 -    public static char forDigit(int digit, int radix) {
139.2452 -        if ((digit >= radix) || (digit < 0)) {
139.2453 -            return '\0';
139.2454 -        }
139.2455 -        if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
139.2456 -            return '\0';
139.2457 -        }
139.2458 -        if (digit < 10) {
139.2459 -            return (char)('0' + digit);
139.2460 -        }
139.2461 -        return (char)('a' - 10 + digit);
139.2462 -    }
139.2463 -
139.2464 -    /**
139.2465 -     * Compares two {@code Character} objects numerically.
139.2466 -     *
139.2467 -     * @param   anotherCharacter   the {@code Character} to be compared.
139.2468 -
139.2469 -     * @return  the value {@code 0} if the argument {@code Character}
139.2470 -     *          is equal to this {@code Character}; a value less than
139.2471 -     *          {@code 0} if this {@code Character} is numerically less
139.2472 -     *          than the {@code Character} argument; and a value greater than
139.2473 -     *          {@code 0} if this {@code Character} is numerically greater
139.2474 -     *          than the {@code Character} argument (unsigned comparison).
139.2475 -     *          Note that this is strictly a numerical comparison; it is not
139.2476 -     *          locale-dependent.
139.2477 -     * @since   1.2
139.2478 -     */
139.2479 -    public int compareTo(Character anotherCharacter) {
139.2480 -        return compare(this.value, anotherCharacter.value);
139.2481 -    }
139.2482 -
139.2483 -    /**
139.2484 -     * Compares two {@code char} values numerically.
139.2485 -     * The value returned is identical to what would be returned by:
139.2486 -     * <pre>
139.2487 -     *    Character.valueOf(x).compareTo(Character.valueOf(y))
139.2488 -     * </pre>
139.2489 -     *
139.2490 -     * @param  x the first {@code char} to compare
139.2491 -     * @param  y the second {@code char} to compare
139.2492 -     * @return the value {@code 0} if {@code x == y};
139.2493 -     *         a value less than {@code 0} if {@code x < y}; and
139.2494 -     *         a value greater than {@code 0} if {@code x > y}
139.2495 -     * @since 1.7
139.2496 -     */
139.2497 -    public static int compare(char x, char y) {
139.2498 -        return x - y;
139.2499 -    }
139.2500 -
139.2501 -
139.2502 -    /**
139.2503 -     * The number of bits used to represent a <tt>char</tt> value in unsigned
139.2504 -     * binary form, constant {@code 16}.
139.2505 -     *
139.2506 -     * @since 1.5
139.2507 -     */
139.2508 -    public static final int SIZE = 16;
139.2509 -
139.2510 -    /**
139.2511 -     * Returns the value obtained by reversing the order of the bytes in the
139.2512 -     * specified <tt>char</tt> value.
139.2513 -     *
139.2514 -     * @return the value obtained by reversing (or, equivalently, swapping)
139.2515 -     *     the bytes in the specified <tt>char</tt> value.
139.2516 -     * @since 1.5
139.2517 -     */
139.2518 -    public static char reverseBytes(char ch) {
139.2519 -        return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
139.2520 -    }
139.2521 -
139.2522 -}
   140.1 --- a/emul/mini/src/main/java/java/lang/Class.java	Mon Feb 25 19:00:08 2013 +0100
   140.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   140.3 @@ -1,1390 +0,0 @@
   140.4 -/*
   140.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   140.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   140.7 - *
   140.8 - * This code is free software; you can redistribute it and/or modify it
   140.9 - * under the terms of the GNU General Public License version 2 only, as
  140.10 - * published by the Free Software Foundation.  Oracle designates this
  140.11 - * particular file as subject to the "Classpath" exception as provided
  140.12 - * by Oracle in the LICENSE file that accompanied this code.
  140.13 - *
  140.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  140.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  140.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  140.17 - * version 2 for more details (a copy is included in the LICENSE file that
  140.18 - * accompanied this code).
  140.19 - *
  140.20 - * You should have received a copy of the GNU General Public License version
  140.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  140.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  140.23 - *
  140.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  140.25 - * or visit www.oracle.com if you need additional information or have any
  140.26 - * questions.
  140.27 - */
  140.28 -
  140.29 -package java.lang;
  140.30 -
  140.31 -import java.io.ByteArrayInputStream;
  140.32 -import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
  140.33 -import java.io.InputStream;
  140.34 -import java.lang.annotation.Annotation;
  140.35 -import java.lang.reflect.Field;
  140.36 -import java.lang.reflect.Method;
  140.37 -import java.lang.reflect.TypeVariable;
  140.38 -import java.net.URL;
  140.39 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  140.40 -import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
  140.41 -
  140.42 -/**
  140.43 - * Instances of the class {@code Class} represent classes and
  140.44 - * interfaces in a running Java application.  An enum is a kind of
  140.45 - * class and an annotation is a kind of interface.  Every array also
  140.46 - * belongs to a class that is reflected as a {@code Class} object
  140.47 - * that is shared by all arrays with the same element type and number
  140.48 - * of dimensions.  The primitive Java types ({@code boolean},
  140.49 - * {@code byte}, {@code char}, {@code short},
  140.50 - * {@code int}, {@code long}, {@code float}, and
  140.51 - * {@code double}), and the keyword {@code void} are also
  140.52 - * represented as {@code Class} objects.
  140.53 - *
  140.54 - * <p> {@code Class} has no public constructor. Instead {@code Class}
  140.55 - * objects are constructed automatically by the Java Virtual Machine as classes
  140.56 - * are loaded and by calls to the {@code defineClass} method in the class
  140.57 - * loader.
  140.58 - *
  140.59 - * <p> The following example uses a {@code Class} object to print the
  140.60 - * class name of an object:
  140.61 - *
  140.62 - * <p> <blockquote><pre>
  140.63 - *     void printClassName(Object obj) {
  140.64 - *         System.out.println("The class of " + obj +
  140.65 - *                            " is " + obj.getClass().getName());
  140.66 - *     }
  140.67 - * </pre></blockquote>
  140.68 - *
  140.69 - * <p> It is also possible to get the {@code Class} object for a named
  140.70 - * type (or for void) using a class literal.  See Section 15.8.2 of
  140.71 - * <cite>The Java&trade; Language Specification</cite>.
  140.72 - * For example:
  140.73 - *
  140.74 - * <p> <blockquote>
  140.75 - *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
  140.76 - * </blockquote>
  140.77 - *
  140.78 - * @param <T> the type of the class modeled by this {@code Class}
  140.79 - * object.  For example, the type of {@code String.class} is {@code
  140.80 - * Class<String>}.  Use {@code Class<?>} if the class being modeled is
  140.81 - * unknown.
  140.82 - *
  140.83 - * @author  unascribed
  140.84 - * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
  140.85 - * @since   JDK1.0
  140.86 - */
  140.87 -public final
  140.88 -    class Class<T> implements java.io.Serializable,
  140.89 -                              java.lang.reflect.GenericDeclaration,
  140.90 -                              java.lang.reflect.Type,
  140.91 -                              java.lang.reflect.AnnotatedElement {
  140.92 -    private static final int ANNOTATION= 0x00002000;
  140.93 -    private static final int ENUM      = 0x00004000;
  140.94 -    private static final int SYNTHETIC = 0x00001000;
  140.95 -
  140.96 -    /*
  140.97 -     * Constructor. Only the Java Virtual Machine creates Class
  140.98 -     * objects.
  140.99 -     */
 140.100 -    private Class() {}
 140.101 -
 140.102 -
 140.103 -    /**
 140.104 -     * Converts the object to a string. The string representation is the
 140.105 -     * string "class" or "interface", followed by a space, and then by the
 140.106 -     * fully qualified name of the class in the format returned by
 140.107 -     * {@code getName}.  If this {@code Class} object represents a
 140.108 -     * primitive type, this method returns the name of the primitive type.  If
 140.109 -     * this {@code Class} object represents void this method returns
 140.110 -     * "void".
 140.111 -     *
 140.112 -     * @return a string representation of this class object.
 140.113 -     */
 140.114 -    public String toString() {
 140.115 -        return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
 140.116 -            + getName();
 140.117 -    }
 140.118 -
 140.119 -
 140.120 -    /**
 140.121 -     * Returns the {@code Class} object associated with the class or
 140.122 -     * interface with the given string name.  Invoking this method is
 140.123 -     * equivalent to:
 140.124 -     *
 140.125 -     * <blockquote>
 140.126 -     *  {@code Class.forName(className, true, currentLoader)}
 140.127 -     * </blockquote>
 140.128 -     *
 140.129 -     * where {@code currentLoader} denotes the defining class loader of
 140.130 -     * the current class.
 140.131 -     *
 140.132 -     * <p> For example, the following code fragment returns the
 140.133 -     * runtime {@code Class} descriptor for the class named
 140.134 -     * {@code java.lang.Thread}:
 140.135 -     *
 140.136 -     * <blockquote>
 140.137 -     *   {@code Class t = Class.forName("java.lang.Thread")}
 140.138 -     * </blockquote>
 140.139 -     * <p>
 140.140 -     * A call to {@code forName("X")} causes the class named
 140.141 -     * {@code X} to be initialized.
 140.142 -     *
 140.143 -     * @param      className   the fully qualified name of the desired class.
 140.144 -     * @return     the {@code Class} object for the class with the
 140.145 -     *             specified name.
 140.146 -     * @exception LinkageError if the linkage fails
 140.147 -     * @exception ExceptionInInitializerError if the initialization provoked
 140.148 -     *            by this method fails
 140.149 -     * @exception ClassNotFoundException if the class cannot be located
 140.150 -     */
 140.151 -    public static Class<?> forName(String className)
 140.152 -    throws ClassNotFoundException {
 140.153 -        if (className.startsWith("[")) {
 140.154 -            Class<?> arrType = defineArray(className);
 140.155 -            Class<?> c = arrType;
 140.156 -            while (c != null && c.isArray()) {
 140.157 -                c = c.getComponentType0(); // verify component type is sane
 140.158 -            }
 140.159 -            return arrType;
 140.160 -        }
 140.161 -        Class<?> c = loadCls(className, className.replace('.', '_'));
 140.162 -        if (c == null) {
 140.163 -            throw new ClassNotFoundException(className);
 140.164 -        }
 140.165 -        return c;
 140.166 -    }
 140.167 -
 140.168 -
 140.169 -    /**
 140.170 -     * Returns the {@code Class} object associated with the class or
 140.171 -     * interface with the given string name, using the given class loader.
 140.172 -     * Given the fully qualified name for a class or interface (in the same
 140.173 -     * format returned by {@code getName}) this method attempts to
 140.174 -     * locate, load, and link the class or interface.  The specified class
 140.175 -     * loader is used to load the class or interface.  If the parameter
 140.176 -     * {@code loader} is null, the class is loaded through the bootstrap
 140.177 -     * class loader.  The class is initialized only if the
 140.178 -     * {@code initialize} parameter is {@code true} and if it has
 140.179 -     * not been initialized earlier.
 140.180 -     *
 140.181 -     * <p> If {@code name} denotes a primitive type or void, an attempt
 140.182 -     * will be made to locate a user-defined class in the unnamed package whose
 140.183 -     * name is {@code name}. Therefore, this method cannot be used to
 140.184 -     * obtain any of the {@code Class} objects representing primitive
 140.185 -     * types or void.
 140.186 -     *
 140.187 -     * <p> If {@code name} denotes an array class, the component type of
 140.188 -     * the array class is loaded but not initialized.
 140.189 -     *
 140.190 -     * <p> For example, in an instance method the expression:
 140.191 -     *
 140.192 -     * <blockquote>
 140.193 -     *  {@code Class.forName("Foo")}
 140.194 -     * </blockquote>
 140.195 -     *
 140.196 -     * is equivalent to:
 140.197 -     *
 140.198 -     * <blockquote>
 140.199 -     *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
 140.200 -     * </blockquote>
 140.201 -     *
 140.202 -     * Note that this method throws errors related to loading, linking or
 140.203 -     * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
 140.204 -     * Java Language Specification</em>.
 140.205 -     * Note that this method does not check whether the requested class
 140.206 -     * is accessible to its caller.
 140.207 -     *
 140.208 -     * <p> If the {@code loader} is {@code null}, and a security
 140.209 -     * manager is present, and the caller's class loader is not null, then this
 140.210 -     * method calls the security manager's {@code checkPermission} method
 140.211 -     * with a {@code RuntimePermission("getClassLoader")} permission to
 140.212 -     * ensure it's ok to access the bootstrap class loader.
 140.213 -     *
 140.214 -     * @param name       fully qualified name of the desired class
 140.215 -     * @param initialize whether the class must be initialized
 140.216 -     * @param loader     class loader from which the class must be loaded
 140.217 -     * @return           class object representing the desired class
 140.218 -     *
 140.219 -     * @exception LinkageError if the linkage fails
 140.220 -     * @exception ExceptionInInitializerError if the initialization provoked
 140.221 -     *            by this method fails
 140.222 -     * @exception ClassNotFoundException if the class cannot be located by
 140.223 -     *            the specified class loader
 140.224 -     *
 140.225 -     * @see       java.lang.Class#forName(String)
 140.226 -     * @see       java.lang.ClassLoader
 140.227 -     * @since     1.2
 140.228 -     */
 140.229 -    public static Class<?> forName(String name, boolean initialize,
 140.230 -                                   ClassLoader loader)
 140.231 -        throws ClassNotFoundException
 140.232 -    {
 140.233 -        return forName(name);
 140.234 -    }
 140.235 -    
 140.236 -    @JavaScriptBody(args = {"n", "c" }, body =
 140.237 -        "if (!vm[c]) {\n"
 140.238 -      + "  if (vm.loadClass) {\n"
 140.239 -      + "    vm.loadClass(n);\n"
 140.240 -      + "  }\n"
 140.241 -      + "  if (!vm[c]) return null;\n"
 140.242 -      + "}\n"
 140.243 -      + "vm[c](false);"
 140.244 -      + "return vm[c].$class;"
 140.245 -    )
 140.246 -    private static native Class<?> loadCls(String n, String c);
 140.247 -
 140.248 -
 140.249 -    /**
 140.250 -     * Creates a new instance of the class represented by this {@code Class}
 140.251 -     * object.  The class is instantiated as if by a {@code new}
 140.252 -     * expression with an empty argument list.  The class is initialized if it
 140.253 -     * has not already been initialized.
 140.254 -     *
 140.255 -     * <p>Note that this method propagates any exception thrown by the
 140.256 -     * nullary constructor, including a checked exception.  Use of
 140.257 -     * this method effectively bypasses the compile-time exception
 140.258 -     * checking that would otherwise be performed by the compiler.
 140.259 -     * The {@link
 140.260 -     * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
 140.261 -     * Constructor.newInstance} method avoids this problem by wrapping
 140.262 -     * any exception thrown by the constructor in a (checked) {@link
 140.263 -     * java.lang.reflect.InvocationTargetException}.
 140.264 -     *
 140.265 -     * @return     a newly allocated instance of the class represented by this
 140.266 -     *             object.
 140.267 -     * @exception  IllegalAccessException  if the class or its nullary
 140.268 -     *               constructor is not accessible.
 140.269 -     * @exception  InstantiationException
 140.270 -     *               if this {@code Class} represents an abstract class,
 140.271 -     *               an interface, an array class, a primitive type, or void;
 140.272 -     *               or if the class has no nullary constructor;
 140.273 -     *               or if the instantiation fails for some other reason.
 140.274 -     * @exception  ExceptionInInitializerError if the initialization
 140.275 -     *               provoked by this method fails.
 140.276 -     * @exception  SecurityException
 140.277 -     *             If a security manager, <i>s</i>, is present and any of the
 140.278 -     *             following conditions is met:
 140.279 -     *
 140.280 -     *             <ul>
 140.281 -     *
 140.282 -     *             <li> invocation of
 140.283 -     *             {@link SecurityManager#checkMemberAccess
 140.284 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 140.285 -     *             creation of new instances of this class
 140.286 -     *
 140.287 -     *             <li> the caller's class loader is not the same as or an
 140.288 -     *             ancestor of the class loader for the current class and
 140.289 -     *             invocation of {@link SecurityManager#checkPackageAccess
 140.290 -     *             s.checkPackageAccess()} denies access to the package
 140.291 -     *             of this class
 140.292 -     *
 140.293 -     *             </ul>
 140.294 -     *
 140.295 -     */
 140.296 -    @JavaScriptBody(args = { "self", "illegal" }, body =
 140.297 -          "\nvar c = self.cnstr;"
 140.298 -        + "\nif (c['cons__V']) {"
 140.299 -        + "\n  if ((c.cons__V.access & 0x1) != 0) {"
 140.300 -        + "\n    var inst = c();"
 140.301 -        + "\n    c.cons__V.call(inst);"
 140.302 -        + "\n    return inst;"
 140.303 -        + "\n  }"
 140.304 -        + "\n  return illegal;"
 140.305 -        + "\n}"
 140.306 -        + "\nreturn null;"
 140.307 -    )
 140.308 -    private static native Object newInstance0(Class<?> self, Object illegal);
 140.309 -    
 140.310 -    public T newInstance()
 140.311 -        throws InstantiationException, IllegalAccessException
 140.312 -    {
 140.313 -        Object illegal = new Object();
 140.314 -        Object inst = newInstance0(this, illegal);
 140.315 -        if (inst == null) {
 140.316 -            throw new InstantiationException(getName());
 140.317 -        }
 140.318 -        if (inst == illegal) {
 140.319 -            throw new IllegalAccessException();
 140.320 -        }
 140.321 -        return (T)inst;
 140.322 -    }
 140.323 -
 140.324 -    /**
 140.325 -     * Determines if the specified {@code Object} is assignment-compatible
 140.326 -     * with the object represented by this {@code Class}.  This method is
 140.327 -     * the dynamic equivalent of the Java language {@code instanceof}
 140.328 -     * operator. The method returns {@code true} if the specified
 140.329 -     * {@code Object} argument is non-null and can be cast to the
 140.330 -     * reference type represented by this {@code Class} object without
 140.331 -     * raising a {@code ClassCastException.} It returns {@code false}
 140.332 -     * otherwise.
 140.333 -     *
 140.334 -     * <p> Specifically, if this {@code Class} object represents a
 140.335 -     * declared class, this method returns {@code true} if the specified
 140.336 -     * {@code Object} argument is an instance of the represented class (or
 140.337 -     * of any of its subclasses); it returns {@code false} otherwise. If
 140.338 -     * this {@code Class} object represents an array class, this method
 140.339 -     * returns {@code true} if the specified {@code Object} argument
 140.340 -     * can be converted to an object of the array class by an identity
 140.341 -     * conversion or by a widening reference conversion; it returns
 140.342 -     * {@code false} otherwise. If this {@code Class} object
 140.343 -     * represents an interface, this method returns {@code true} if the
 140.344 -     * class or any superclass of the specified {@code Object} argument
 140.345 -     * implements this interface; it returns {@code false} otherwise. If
 140.346 -     * this {@code Class} object represents a primitive type, this method
 140.347 -     * returns {@code false}.
 140.348 -     *
 140.349 -     * @param   obj the object to check
 140.350 -     * @return  true if {@code obj} is an instance of this class
 140.351 -     *
 140.352 -     * @since JDK1.1
 140.353 -     */
 140.354 -    public boolean isInstance(Object obj) {
 140.355 -        if (obj == null) {
 140.356 -            return false;
 140.357 -        }
 140.358 -        if (isArray()) {
 140.359 -            return isAssignableFrom(obj.getClass());
 140.360 -        }
 140.361 -        
 140.362 -        String prop = "$instOf_" + getName().replace('.', '_');
 140.363 -        return hasProperty(obj, prop);
 140.364 -    }
 140.365 -    
 140.366 -    @JavaScriptBody(args = { "who", "prop" }, body = 
 140.367 -        "if (who[prop]) return true; else return false;"
 140.368 -    )
 140.369 -    private static native boolean hasProperty(Object who, String prop);
 140.370 -
 140.371 -
 140.372 -    /**
 140.373 -     * Determines if the class or interface represented by this
 140.374 -     * {@code Class} object is either the same as, or is a superclass or
 140.375 -     * superinterface of, the class or interface represented by the specified
 140.376 -     * {@code Class} parameter. It returns {@code true} if so;
 140.377 -     * otherwise it returns {@code false}. If this {@code Class}
 140.378 -     * object represents a primitive type, this method returns
 140.379 -     * {@code true} if the specified {@code Class} parameter is
 140.380 -     * exactly this {@code Class} object; otherwise it returns
 140.381 -     * {@code false}.
 140.382 -     *
 140.383 -     * <p> Specifically, this method tests whether the type represented by the
 140.384 -     * specified {@code Class} parameter can be converted to the type
 140.385 -     * represented by this {@code Class} object via an identity conversion
 140.386 -     * or via a widening reference conversion. See <em>The Java Language
 140.387 -     * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
 140.388 -     *
 140.389 -     * @param cls the {@code Class} object to be checked
 140.390 -     * @return the {@code boolean} value indicating whether objects of the
 140.391 -     * type {@code cls} can be assigned to objects of this class
 140.392 -     * @exception NullPointerException if the specified Class parameter is
 140.393 -     *            null.
 140.394 -     * @since JDK1.1
 140.395 -     */
 140.396 -    public boolean isAssignableFrom(Class<?> cls) {
 140.397 -        if (this == cls) {
 140.398 -            return true;
 140.399 -        }
 140.400 -        
 140.401 -        if (isArray()) {
 140.402 -            final Class<?> cmpType = cls.getComponentType();
 140.403 -            if (isPrimitive()) {
 140.404 -                return this == cmpType;
 140.405 -            }
 140.406 -            return cmpType != null && getComponentType().isAssignableFrom(cmpType);
 140.407 -        }
 140.408 -        String prop = "$instOf_" + getName().replace('.', '_');
 140.409 -        return hasCnstrProperty(cls, prop);
 140.410 -    }
 140.411 -
 140.412 -    @JavaScriptBody(args = { "who", "prop" }, body = 
 140.413 -        "if (who.cnstr.prototype[prop]) return true; else return false;"
 140.414 -    )
 140.415 -    private static native boolean hasCnstrProperty(Object who, String prop);
 140.416 -    
 140.417 -    
 140.418 -    /**
 140.419 -     * Determines if the specified {@code Class} object represents an
 140.420 -     * interface type.
 140.421 -     *
 140.422 -     * @return  {@code true} if this object represents an interface;
 140.423 -     *          {@code false} otherwise.
 140.424 -     */
 140.425 -    public boolean isInterface() {
 140.426 -        return (getAccess() & 0x200) != 0;
 140.427 -    }
 140.428 -    
 140.429 -    @JavaScriptBody(args = {}, body = "return this.access;")
 140.430 -    private native int getAccess();
 140.431 -
 140.432 -
 140.433 -    /**
 140.434 -     * Determines if this {@code Class} object represents an array class.
 140.435 -     *
 140.436 -     * @return  {@code true} if this object represents an array class;
 140.437 -     *          {@code false} otherwise.
 140.438 -     * @since   JDK1.1
 140.439 -     */
 140.440 -    public boolean isArray() {
 140.441 -        return hasProperty(this, "array"); // NOI18N
 140.442 -    }
 140.443 -
 140.444 -
 140.445 -    /**
 140.446 -     * Determines if the specified {@code Class} object represents a
 140.447 -     * primitive type.
 140.448 -     *
 140.449 -     * <p> There are nine predefined {@code Class} objects to represent
 140.450 -     * the eight primitive types and void.  These are created by the Java
 140.451 -     * Virtual Machine, and have the same names as the primitive types that
 140.452 -     * they represent, namely {@code boolean}, {@code byte},
 140.453 -     * {@code char}, {@code short}, {@code int},
 140.454 -     * {@code long}, {@code float}, and {@code double}.
 140.455 -     *
 140.456 -     * <p> These objects may only be accessed via the following public static
 140.457 -     * final variables, and are the only {@code Class} objects for which
 140.458 -     * this method returns {@code true}.
 140.459 -     *
 140.460 -     * @return true if and only if this class represents a primitive type
 140.461 -     *
 140.462 -     * @see     java.lang.Boolean#TYPE
 140.463 -     * @see     java.lang.Character#TYPE
 140.464 -     * @see     java.lang.Byte#TYPE
 140.465 -     * @see     java.lang.Short#TYPE
 140.466 -     * @see     java.lang.Integer#TYPE
 140.467 -     * @see     java.lang.Long#TYPE
 140.468 -     * @see     java.lang.Float#TYPE
 140.469 -     * @see     java.lang.Double#TYPE
 140.470 -     * @see     java.lang.Void#TYPE
 140.471 -     * @since JDK1.1
 140.472 -     */
 140.473 -    @JavaScriptBody(args = {}, body = 
 140.474 -           "if (this.primitive) return true;"
 140.475 -        + "else return false;"
 140.476 -    )
 140.477 -    public native boolean isPrimitive();
 140.478 -
 140.479 -    /**
 140.480 -     * Returns true if this {@code Class} object represents an annotation
 140.481 -     * type.  Note that if this method returns true, {@link #isInterface()}
 140.482 -     * would also return true, as all annotation types are also interfaces.
 140.483 -     *
 140.484 -     * @return {@code true} if this class object represents an annotation
 140.485 -     *      type; {@code false} otherwise
 140.486 -     * @since 1.5
 140.487 -     */
 140.488 -    public boolean isAnnotation() {
 140.489 -        return (getModifiers() & ANNOTATION) != 0;
 140.490 -    }
 140.491 -
 140.492 -    /**
 140.493 -     * Returns {@code true} if this class is a synthetic class;
 140.494 -     * returns {@code false} otherwise.
 140.495 -     * @return {@code true} if and only if this class is a synthetic class as
 140.496 -     *         defined by the Java Language Specification.
 140.497 -     * @since 1.5
 140.498 -     */
 140.499 -    public boolean isSynthetic() {
 140.500 -        return (getModifiers() & SYNTHETIC) != 0;
 140.501 -    }
 140.502 -
 140.503 -    /**
 140.504 -     * Returns the  name of the entity (class, interface, array class,
 140.505 -     * primitive type, or void) represented by this {@code Class} object,
 140.506 -     * as a {@code String}.
 140.507 -     *
 140.508 -     * <p> If this class object represents a reference type that is not an
 140.509 -     * array type then the binary name of the class is returned, as specified
 140.510 -     * by
 140.511 -     * <cite>The Java&trade; Language Specification</cite>.
 140.512 -     *
 140.513 -     * <p> If this class object represents a primitive type or void, then the
 140.514 -     * name returned is a {@code String} equal to the Java language
 140.515 -     * keyword corresponding to the primitive type or void.
 140.516 -     *
 140.517 -     * <p> If this class object represents a class of arrays, then the internal
 140.518 -     * form of the name consists of the name of the element type preceded by
 140.519 -     * one or more '{@code [}' characters representing the depth of the array
 140.520 -     * nesting.  The encoding of element type names is as follows:
 140.521 -     *
 140.522 -     * <blockquote><table summary="Element types and encodings">
 140.523 -     * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
 140.524 -     * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
 140.525 -     * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
 140.526 -     * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
 140.527 -     * <tr><td> class or interface
 140.528 -     *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
 140.529 -     * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
 140.530 -     * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
 140.531 -     * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
 140.532 -     * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
 140.533 -     * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
 140.534 -     * </table></blockquote>
 140.535 -     *
 140.536 -     * <p> The class or interface name <i>classname</i> is the binary name of
 140.537 -     * the class specified above.
 140.538 -     *
 140.539 -     * <p> Examples:
 140.540 -     * <blockquote><pre>
 140.541 -     * String.class.getName()
 140.542 -     *     returns "java.lang.String"
 140.543 -     * byte.class.getName()
 140.544 -     *     returns "byte"
 140.545 -     * (new Object[3]).getClass().getName()
 140.546 -     *     returns "[Ljava.lang.Object;"
 140.547 -     * (new int[3][4][5][6][7][8][9]).getClass().getName()
 140.548 -     *     returns "[[[[[[[I"
 140.549 -     * </pre></blockquote>
 140.550 -     *
 140.551 -     * @return  the name of the class or interface
 140.552 -     *          represented by this object.
 140.553 -     */
 140.554 -    public String getName() {
 140.555 -        return jvmName().replace('/', '.');
 140.556 -    }
 140.557 -
 140.558 -    @JavaScriptBody(args = {}, body = "return this.jvmName;")
 140.559 -    private native String jvmName();
 140.560 -
 140.561 -    
 140.562 -    /**
 140.563 -     * Returns an array of {@code TypeVariable} objects that represent the
 140.564 -     * type variables declared by the generic declaration represented by this
 140.565 -     * {@code GenericDeclaration} object, in declaration order.  Returns an
 140.566 -     * array of length 0 if the underlying generic declaration declares no type
 140.567 -     * variables.
 140.568 -     *
 140.569 -     * @return an array of {@code TypeVariable} objects that represent
 140.570 -     *     the type variables declared by this generic declaration
 140.571 -     * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 140.572 -     *     signature of this generic declaration does not conform to
 140.573 -     *     the format specified in
 140.574 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 140.575 -     * @since 1.5
 140.576 -     */
 140.577 -    public TypeVariable<Class<T>>[] getTypeParameters() {
 140.578 -        throw new UnsupportedOperationException();
 140.579 -    }
 140.580 - 
 140.581 -    /**
 140.582 -     * Returns the {@code Class} representing the superclass of the entity
 140.583 -     * (class, interface, primitive type or void) represented by this
 140.584 -     * {@code Class}.  If this {@code Class} represents either the
 140.585 -     * {@code Object} class, an interface, a primitive type, or void, then
 140.586 -     * null is returned.  If this object represents an array class then the
 140.587 -     * {@code Class} object representing the {@code Object} class is
 140.588 -     * returned.
 140.589 -     *
 140.590 -     * @return the superclass of the class represented by this object.
 140.591 -     */
 140.592 -    @JavaScriptBody(args = {}, body = "return this.superclass;")
 140.593 -    public native Class<? super T> getSuperclass();
 140.594 -
 140.595 -    /**
 140.596 -     * Returns the Java language modifiers for this class or interface, encoded
 140.597 -     * in an integer. The modifiers consist of the Java Virtual Machine's
 140.598 -     * constants for {@code public}, {@code protected},
 140.599 -     * {@code private}, {@code final}, {@code static},
 140.600 -     * {@code abstract} and {@code interface}; they should be decoded
 140.601 -     * using the methods of class {@code Modifier}.
 140.602 -     *
 140.603 -     * <p> If the underlying class is an array class, then its
 140.604 -     * {@code public}, {@code private} and {@code protected}
 140.605 -     * modifiers are the same as those of its component type.  If this
 140.606 -     * {@code Class} represents a primitive type or void, its
 140.607 -     * {@code public} modifier is always {@code true}, and its
 140.608 -     * {@code protected} and {@code private} modifiers are always
 140.609 -     * {@code false}. If this object represents an array class, a
 140.610 -     * primitive type or void, then its {@code final} modifier is always
 140.611 -     * {@code true} and its interface modifier is always
 140.612 -     * {@code false}. The values of its other modifiers are not determined
 140.613 -     * by this specification.
 140.614 -     *
 140.615 -     * <p> The modifier encodings are defined in <em>The Java Virtual Machine
 140.616 -     * Specification</em>, table 4.1.
 140.617 -     *
 140.618 -     * @return the {@code int} representing the modifiers for this class
 140.619 -     * @see     java.lang.reflect.Modifier
 140.620 -     * @since JDK1.1
 140.621 -     */
 140.622 -    public int getModifiers() {
 140.623 -        return getAccess();
 140.624 -    }
 140.625 -
 140.626 -
 140.627 -    /**
 140.628 -     * Returns the simple name of the underlying class as given in the
 140.629 -     * source code. Returns an empty string if the underlying class is
 140.630 -     * anonymous.
 140.631 -     *
 140.632 -     * <p>The simple name of an array is the simple name of the
 140.633 -     * component type with "[]" appended.  In particular the simple
 140.634 -     * name of an array whose component type is anonymous is "[]".
 140.635 -     *
 140.636 -     * @return the simple name of the underlying class
 140.637 -     * @since 1.5
 140.638 -     */
 140.639 -    public String getSimpleName() {
 140.640 -        if (isArray())
 140.641 -            return getComponentType().getSimpleName()+"[]";
 140.642 -
 140.643 -        String simpleName = getSimpleBinaryName();
 140.644 -        if (simpleName == null) { // top level class
 140.645 -            simpleName = getName();
 140.646 -            return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
 140.647 -        }
 140.648 -        // According to JLS3 "Binary Compatibility" (13.1) the binary
 140.649 -        // name of non-package classes (not top level) is the binary
 140.650 -        // name of the immediately enclosing class followed by a '$' followed by:
 140.651 -        // (for nested and inner classes): the simple name.
 140.652 -        // (for local classes): 1 or more digits followed by the simple name.
 140.653 -        // (for anonymous classes): 1 or more digits.
 140.654 -
 140.655 -        // Since getSimpleBinaryName() will strip the binary name of
 140.656 -        // the immediatly enclosing class, we are now looking at a
 140.657 -        // string that matches the regular expression "\$[0-9]*"
 140.658 -        // followed by a simple name (considering the simple of an
 140.659 -        // anonymous class to be the empty string).
 140.660 -
 140.661 -        // Remove leading "\$[0-9]*" from the name
 140.662 -        int length = simpleName.length();
 140.663 -        if (length < 1 || simpleName.charAt(0) != '$')
 140.664 -            throw new IllegalStateException("Malformed class name");
 140.665 -        int index = 1;
 140.666 -        while (index < length && isAsciiDigit(simpleName.charAt(index)))
 140.667 -            index++;
 140.668 -        // Eventually, this is the empty string iff this is an anonymous class
 140.669 -        return simpleName.substring(index);
 140.670 -    }
 140.671 -
 140.672 -    /**
 140.673 -     * Returns the "simple binary name" of the underlying class, i.e.,
 140.674 -     * the binary name without the leading enclosing class name.
 140.675 -     * Returns {@code null} if the underlying class is a top level
 140.676 -     * class.
 140.677 -     */
 140.678 -    private String getSimpleBinaryName() {
 140.679 -        Class<?> enclosingClass = null; // XXX getEnclosingClass();
 140.680 -        if (enclosingClass == null) // top level class
 140.681 -            return null;
 140.682 -        // Otherwise, strip the enclosing class' name
 140.683 -        try {
 140.684 -            return getName().substring(enclosingClass.getName().length());
 140.685 -        } catch (IndexOutOfBoundsException ex) {
 140.686 -            throw new IllegalStateException("Malformed class name");
 140.687 -        }
 140.688 -    }
 140.689 -
 140.690 -    /**
 140.691 -     * Returns an array containing {@code Field} objects reflecting all
 140.692 -     * the accessible public fields of the class or interface represented by
 140.693 -     * this {@code Class} object.  The elements in the array returned are
 140.694 -     * not sorted and are not in any particular order.  This method returns an
 140.695 -     * array of length 0 if the class or interface has no accessible public
 140.696 -     * fields, or if it represents an array class, a primitive type, or void.
 140.697 -     *
 140.698 -     * <p> Specifically, if this {@code Class} object represents a class,
 140.699 -     * this method returns the public fields of this class and of all its
 140.700 -     * superclasses.  If this {@code Class} object represents an
 140.701 -     * interface, this method returns the fields of this interface and of all
 140.702 -     * its superinterfaces.
 140.703 -     *
 140.704 -     * <p> The implicit length field for array class is not reflected by this
 140.705 -     * method. User code should use the methods of class {@code Array} to
 140.706 -     * manipulate arrays.
 140.707 -     *
 140.708 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 140.709 -     *
 140.710 -     * @return the array of {@code Field} objects representing the
 140.711 -     * public fields
 140.712 -     * @exception  SecurityException
 140.713 -     *             If a security manager, <i>s</i>, is present and any of the
 140.714 -     *             following conditions is met:
 140.715 -     *
 140.716 -     *             <ul>
 140.717 -     *
 140.718 -     *             <li> invocation of
 140.719 -     *             {@link SecurityManager#checkMemberAccess
 140.720 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 140.721 -     *             access to the fields within this class
 140.722 -     *
 140.723 -     *             <li> the caller's class loader is not the same as or an
 140.724 -     *             ancestor of the class loader for the current class and
 140.725 -     *             invocation of {@link SecurityManager#checkPackageAccess
 140.726 -     *             s.checkPackageAccess()} denies access to the package
 140.727 -     *             of this class
 140.728 -     *
 140.729 -     *             </ul>
 140.730 -     *
 140.731 -     * @since JDK1.1
 140.732 -     */
 140.733 -    public Field[] getFields() throws SecurityException {
 140.734 -        throw new SecurityException();
 140.735 -    }
 140.736 -
 140.737 -    /**
 140.738 -     * Returns an array containing {@code Method} objects reflecting all
 140.739 -     * the public <em>member</em> methods of the class or interface represented
 140.740 -     * by this {@code Class} object, including those declared by the class
 140.741 -     * or interface and those inherited from superclasses and
 140.742 -     * superinterfaces.  Array classes return all the (public) member methods
 140.743 -     * inherited from the {@code Object} class.  The elements in the array
 140.744 -     * returned are not sorted and are not in any particular order.  This
 140.745 -     * method returns an array of length 0 if this {@code Class} object
 140.746 -     * represents a class or interface that has no public member methods, or if
 140.747 -     * this {@code Class} object represents a primitive type or void.
 140.748 -     *
 140.749 -     * <p> The class initialization method {@code <clinit>} is not
 140.750 -     * included in the returned array. If the class declares multiple public
 140.751 -     * member methods with the same parameter types, they are all included in
 140.752 -     * the returned array.
 140.753 -     *
 140.754 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 140.755 -     *
 140.756 -     * @return the array of {@code Method} objects representing the
 140.757 -     * public methods of this class
 140.758 -     * @exception  SecurityException
 140.759 -     *             If a security manager, <i>s</i>, is present and any of the
 140.760 -     *             following conditions is met:
 140.761 -     *
 140.762 -     *             <ul>
 140.763 -     *
 140.764 -     *             <li> invocation of
 140.765 -     *             {@link SecurityManager#checkMemberAccess
 140.766 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 140.767 -     *             access to the methods within this class
 140.768 -     *
 140.769 -     *             <li> the caller's class loader is not the same as or an
 140.770 -     *             ancestor of the class loader for the current class and
 140.771 -     *             invocation of {@link SecurityManager#checkPackageAccess
 140.772 -     *             s.checkPackageAccess()} denies access to the package
 140.773 -     *             of this class
 140.774 -     *
 140.775 -     *             </ul>
 140.776 -     *
 140.777 -     * @since JDK1.1
 140.778 -     */
 140.779 -    public Method[] getMethods() throws SecurityException {
 140.780 -        return MethodImpl.findMethods(this, 0x01);
 140.781 -    }
 140.782 -
 140.783 -    /**
 140.784 -     * Returns a {@code Field} object that reflects the specified public
 140.785 -     * member field of the class or interface represented by this
 140.786 -     * {@code Class} object. The {@code name} parameter is a
 140.787 -     * {@code String} specifying the simple name of the desired field.
 140.788 -     *
 140.789 -     * <p> The field to be reflected is determined by the algorithm that
 140.790 -     * follows.  Let C be the class represented by this object:
 140.791 -     * <OL>
 140.792 -     * <LI> If C declares a public field with the name specified, that is the
 140.793 -     *      field to be reflected.</LI>
 140.794 -     * <LI> If no field was found in step 1 above, this algorithm is applied
 140.795 -     *      recursively to each direct superinterface of C. The direct
 140.796 -     *      superinterfaces are searched in the order they were declared.</LI>
 140.797 -     * <LI> If no field was found in steps 1 and 2 above, and C has a
 140.798 -     *      superclass S, then this algorithm is invoked recursively upon S.
 140.799 -     *      If C has no superclass, then a {@code NoSuchFieldException}
 140.800 -     *      is thrown.</LI>
 140.801 -     * </OL>
 140.802 -     *
 140.803 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 140.804 -     *
 140.805 -     * @param name the field name
 140.806 -     * @return  the {@code Field} object of this class specified by
 140.807 -     * {@code name}
 140.808 -     * @exception NoSuchFieldException if a field with the specified name is
 140.809 -     *              not found.
 140.810 -     * @exception NullPointerException if {@code name} is {@code null}
 140.811 -     * @exception  SecurityException
 140.812 -     *             If a security manager, <i>s</i>, is present and any of the
 140.813 -     *             following conditions is met:
 140.814 -     *
 140.815 -     *             <ul>
 140.816 -     *
 140.817 -     *             <li> invocation of
 140.818 -     *             {@link SecurityManager#checkMemberAccess
 140.819 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 140.820 -     *             access to the field
 140.821 -     *
 140.822 -     *             <li> the caller's class loader is not the same as or an
 140.823 -     *             ancestor of the class loader for the current class and
 140.824 -     *             invocation of {@link SecurityManager#checkPackageAccess
 140.825 -     *             s.checkPackageAccess()} denies access to the package
 140.826 -     *             of this class
 140.827 -     *
 140.828 -     *             </ul>
 140.829 -     *
 140.830 -     * @since JDK1.1
 140.831 -     */
 140.832 -    public Field getField(String name)
 140.833 -        throws SecurityException {
 140.834 -        throw new SecurityException();
 140.835 -    }
 140.836 -    
 140.837 -    
 140.838 -    /**
 140.839 -     * Returns a {@code Method} object that reflects the specified public
 140.840 -     * member method of the class or interface represented by this
 140.841 -     * {@code Class} object. The {@code name} parameter is a
 140.842 -     * {@code String} specifying the simple name of the desired method. The
 140.843 -     * {@code parameterTypes} parameter is an array of {@code Class}
 140.844 -     * objects that identify the method's formal parameter types, in declared
 140.845 -     * order. If {@code parameterTypes} is {@code null}, it is
 140.846 -     * treated as if it were an empty array.
 140.847 -     *
 140.848 -     * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
 140.849 -     * {@code NoSuchMethodException} is raised. Otherwise, the method to
 140.850 -     * be reflected is determined by the algorithm that follows.  Let C be the
 140.851 -     * class represented by this object:
 140.852 -     * <OL>
 140.853 -     * <LI> C is searched for any <I>matching methods</I>. If no matching
 140.854 -     *      method is found, the algorithm of step 1 is invoked recursively on
 140.855 -     *      the superclass of C.</LI>
 140.856 -     * <LI> If no method was found in step 1 above, the superinterfaces of C
 140.857 -     *      are searched for a matching method. If any such method is found, it
 140.858 -     *      is reflected.</LI>
 140.859 -     * </OL>
 140.860 -     *
 140.861 -     * To find a matching method in a class C:&nbsp; If C declares exactly one
 140.862 -     * public method with the specified name and exactly the same formal
 140.863 -     * parameter types, that is the method reflected. If more than one such
 140.864 -     * method is found in C, and one of these methods has a return type that is
 140.865 -     * more specific than any of the others, that method is reflected;
 140.866 -     * otherwise one of the methods is chosen arbitrarily.
 140.867 -     *
 140.868 -     * <p>Note that there may be more than one matching method in a
 140.869 -     * class because while the Java language forbids a class to
 140.870 -     * declare multiple methods with the same signature but different
 140.871 -     * return types, the Java virtual machine does not.  This
 140.872 -     * increased flexibility in the virtual machine can be used to
 140.873 -     * implement various language features.  For example, covariant
 140.874 -     * returns can be implemented with {@linkplain
 140.875 -     * java.lang.reflect.Method#isBridge bridge methods}; the bridge
 140.876 -     * method and the method being overridden would have the same
 140.877 -     * signature but different return types.
 140.878 -     *
 140.879 -     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 140.880 -     *
 140.881 -     * @param name the name of the method
 140.882 -     * @param parameterTypes the list of parameters
 140.883 -     * @return the {@code Method} object that matches the specified
 140.884 -     * {@code name} and {@code parameterTypes}
 140.885 -     * @exception NoSuchMethodException if a matching method is not found
 140.886 -     *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
 140.887 -     * @exception NullPointerException if {@code name} is {@code null}
 140.888 -     * @exception  SecurityException
 140.889 -     *             If a security manager, <i>s</i>, is present and any of the
 140.890 -     *             following conditions is met:
 140.891 -     *
 140.892 -     *             <ul>
 140.893 -     *
 140.894 -     *             <li> invocation of
 140.895 -     *             {@link SecurityManager#checkMemberAccess
 140.896 -     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 140.897 -     *             access to the method
 140.898 -     *
 140.899 -     *             <li> the caller's class loader is not the same as or an
 140.900 -     *             ancestor of the class loader for the current class and
 140.901 -     *             invocation of {@link SecurityManager#checkPackageAccess
 140.902 -     *             s.checkPackageAccess()} denies access to the package
 140.903 -     *             of this class
 140.904 -     *
 140.905 -     *             </ul>
 140.906 -     *
 140.907 -     * @since JDK1.1
 140.908 -     */
 140.909 -    public Method getMethod(String name, Class<?>... parameterTypes)
 140.910 -        throws SecurityException, NoSuchMethodException {
 140.911 -        Method m = MethodImpl.findMethod(this, name, parameterTypes);
 140.912 -        if (m == null) {
 140.913 -            StringBuilder sb = new StringBuilder();
 140.914 -            sb.append(getName()).append('.').append(name).append('(');
 140.915 -            String sep = "";
 140.916 -            for (int i = 0; i < parameterTypes.length; i++) {
 140.917 -                sb.append(sep).append(parameterTypes[i].getName());
 140.918 -                sep = ", ";
 140.919 -            }
 140.920 -            sb.append(')');
 140.921 -            throw new NoSuchMethodException(sb.toString());
 140.922 -        }
 140.923 -        return m;
 140.924 -    }
 140.925 -    
 140.926 -    /**
 140.927 -     * Returns an array of {@code Method} objects reflecting all the
 140.928 -     * methods declared by the class or interface represented by this
 140.929 -     * {@code Class} object. This includes public, protected, default
 140.930 -     * (package) access, and private methods, but excludes inherited methods.
 140.931 -     * The elements in the array returned are not sorted and are not in any
 140.932 -     * particular order.  This method returns an array of length 0 if the class
 140.933 -     * or interface declares no methods, or if this {@code Class} object
 140.934 -     * represents a primitive type, an array class, or void.  The class
 140.935 -     * initialization method {@code <clinit>} is not included in the
 140.936 -     * returned array. If the class declares multiple public member methods
 140.937 -     * with the same parameter types, they are all included in the returned
 140.938 -     * array.
 140.939 -     *
 140.940 -     * <p> See <em>The Java Language Specification</em>, section 8.2.
 140.941 -     *
 140.942 -     * @return    the array of {@code Method} objects representing all the
 140.943 -     * declared methods of this class
 140.944 -     * @exception  SecurityException
 140.945 -     *             If a security manager, <i>s</i>, is present and any of the
 140.946 -     *             following conditions is met:
 140.947 -     *
 140.948 -     *             <ul>
 140.949 -     *
 140.950 -     *             <li> invocation of
 140.951 -     *             {@link SecurityManager#checkMemberAccess
 140.952 -     *             s.checkMemberAccess(this, Member.DECLARED)} denies
 140.953 -     *             access to the declared methods within this class
 140.954 -     *
 140.955 -     *             <li> the caller's class loader is not the same as or an
 140.956 -     *             ancestor of the class loader for the current class and
 140.957 -     *             invocation of {@link SecurityManager#checkPackageAccess
 140.958 -     *             s.checkPackageAccess()} denies access to the package
 140.959 -     *             of this class
 140.960 -     *
 140.961 -     *             </ul>
 140.962 -     *
 140.963 -     * @since JDK1.1
 140.964 -     */
 140.965 -    public Method[] getDeclaredMethods() throws SecurityException {
 140.966 -        throw new SecurityException();
 140.967 -    }
 140.968 -    
 140.969 -    /**
 140.970 -     * Character.isDigit answers {@code true} to some non-ascii
 140.971 -     * digits.  This one does not.
 140.972 -     */
 140.973 -    private static boolean isAsciiDigit(char c) {
 140.974 -        return '0' <= c && c <= '9';
 140.975 -    }
 140.976 -
 140.977 -    /**
 140.978 -     * Returns the canonical name of the underlying class as
 140.979 -     * defined by the Java Language Specification.  Returns null if
 140.980 -     * the underlying class does not have a canonical name (i.e., if
 140.981 -     * it is a local or anonymous class or an array whose component
 140.982 -     * type does not have a canonical name).
 140.983 -     * @return the canonical name of the underlying class if it exists, and
 140.984 -     * {@code null} otherwise.
 140.985 -     * @since 1.5
 140.986 -     */
 140.987 -    public String getCanonicalName() {
 140.988 -        if (isArray()) {
 140.989 -            String canonicalName = getComponentType().getCanonicalName();
 140.990 -            if (canonicalName != null)
 140.991 -                return canonicalName + "[]";
 140.992 -            else
 140.993 -                return null;
 140.994 -        }
 140.995 -//        if (isLocalOrAnonymousClass())
 140.996 -//            return null;
 140.997 -//        Class<?> enclosingClass = getEnclosingClass();
 140.998 -        Class<?> enclosingClass = null;
 140.999 -        if (enclosingClass == null) { // top level class
140.1000 -            return getName();
140.1001 -        } else {
140.1002 -            String enclosingName = enclosingClass.getCanonicalName();
140.1003 -            if (enclosingName == null)
140.1004 -                return null;
140.1005 -            return enclosingName + "." + getSimpleName();
140.1006 -        }
140.1007 -    }
140.1008 -
140.1009 -    /**
140.1010 -     * Finds a resource with a given name.  The rules for searching resources
140.1011 -     * associated with a given class are implemented by the defining
140.1012 -     * {@linkplain ClassLoader class loader} of the class.  This method
140.1013 -     * delegates to this object's class loader.  If this object was loaded by
140.1014 -     * the bootstrap class loader, the method delegates to {@link
140.1015 -     * ClassLoader#getSystemResourceAsStream}.
140.1016 -     *
140.1017 -     * <p> Before delegation, an absolute resource name is constructed from the
140.1018 -     * given resource name using this algorithm:
140.1019 -     *
140.1020 -     * <ul>
140.1021 -     *
140.1022 -     * <li> If the {@code name} begins with a {@code '/'}
140.1023 -     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
140.1024 -     * portion of the {@code name} following the {@code '/'}.
140.1025 -     *
140.1026 -     * <li> Otherwise, the absolute name is of the following form:
140.1027 -     *
140.1028 -     * <blockquote>
140.1029 -     *   {@code modified_package_name/name}
140.1030 -     * </blockquote>
140.1031 -     *
140.1032 -     * <p> Where the {@code modified_package_name} is the package name of this
140.1033 -     * object with {@code '/'} substituted for {@code '.'}
140.1034 -     * (<tt>'&#92;u002e'</tt>).
140.1035 -     *
140.1036 -     * </ul>
140.1037 -     *
140.1038 -     * @param  name name of the desired resource
140.1039 -     * @return      A {@link java.io.InputStream} object or {@code null} if
140.1040 -     *              no resource with this name is found
140.1041 -     * @throws  NullPointerException If {@code name} is {@code null}
140.1042 -     * @since  JDK1.1
140.1043 -     */
140.1044 -     public InputStream getResourceAsStream(String name) {
140.1045 -        name = resolveName(name);
140.1046 -        byte[] arr = getResourceAsStream0(name);
140.1047 -        return arr == null ? null : new ByteArrayInputStream(arr);
140.1048 -     }
140.1049 -     
140.1050 -     @JavaScriptBody(args = "name", body = 
140.1051 -         "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
140.1052 -     )
140.1053 -     private static native byte[] getResourceAsStream0(String name);
140.1054 -
140.1055 -    /**
140.1056 -     * Finds a resource with a given name.  The rules for searching resources
140.1057 -     * associated with a given class are implemented by the defining
140.1058 -     * {@linkplain ClassLoader class loader} of the class.  This method
140.1059 -     * delegates to this object's class loader.  If this object was loaded by
140.1060 -     * the bootstrap class loader, the method delegates to {@link
140.1061 -     * ClassLoader#getSystemResource}.
140.1062 -     *
140.1063 -     * <p> Before delegation, an absolute resource name is constructed from the
140.1064 -     * given resource name using this algorithm:
140.1065 -     *
140.1066 -     * <ul>
140.1067 -     *
140.1068 -     * <li> If the {@code name} begins with a {@code '/'}
140.1069 -     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
140.1070 -     * portion of the {@code name} following the {@code '/'}.
140.1071 -     *
140.1072 -     * <li> Otherwise, the absolute name is of the following form:
140.1073 -     *
140.1074 -     * <blockquote>
140.1075 -     *   {@code modified_package_name/name}
140.1076 -     * </blockquote>
140.1077 -     *
140.1078 -     * <p> Where the {@code modified_package_name} is the package name of this
140.1079 -     * object with {@code '/'} substituted for {@code '.'}
140.1080 -     * (<tt>'&#92;u002e'</tt>).
140.1081 -     *
140.1082 -     * </ul>
140.1083 -     *
140.1084 -     * @param  name name of the desired resource
140.1085 -     * @return      A  {@link java.net.URL} object or {@code null} if no
140.1086 -     *              resource with this name is found
140.1087 -     * @since  JDK1.1
140.1088 -     */
140.1089 -    public java.net.URL getResource(String name) {
140.1090 -        InputStream is = getResourceAsStream(name);
140.1091 -        return is == null ? null : newResourceURL(URL.class, "res:/" + name, is);
140.1092 -    }
140.1093 -    
140.1094 -    @JavaScriptBody(args = { "url", "spec", "is" }, body = 
140.1095 -        "var u = url.cnstr(true);\n"
140.1096 -      + "u.constructor.cons__VLjava_lang_String_2Ljava_io_InputStream_2.call(u, spec, is);\n"
140.1097 -      + "return u;"
140.1098 -    )
140.1099 -    private static native URL newResourceURL(Class<URL> url, String spec, InputStream is);
140.1100 -
140.1101 -   /**
140.1102 -     * Add a package name prefix if the name is not absolute Remove leading "/"
140.1103 -     * if name is absolute
140.1104 -     */
140.1105 -    private String resolveName(String name) {
140.1106 -        if (name == null) {
140.1107 -            return name;
140.1108 -        }
140.1109 -        if (!name.startsWith("/")) {
140.1110 -            Class<?> c = this;
140.1111 -            while (c.isArray()) {
140.1112 -                c = c.getComponentType();
140.1113 -            }
140.1114 -            String baseName = c.getName();
140.1115 -            int index = baseName.lastIndexOf('.');
140.1116 -            if (index != -1) {
140.1117 -                name = baseName.substring(0, index).replace('.', '/')
140.1118 -                    +"/"+name;
140.1119 -            }
140.1120 -        } else {
140.1121 -            name = name.substring(1);
140.1122 -        }
140.1123 -        return name;
140.1124 -    }
140.1125 -    
140.1126 -    /**
140.1127 -     * Returns the class loader for the class.  Some implementations may use
140.1128 -     * null to represent the bootstrap class loader. This method will return
140.1129 -     * null in such implementations if this class was loaded by the bootstrap
140.1130 -     * class loader.
140.1131 -     *
140.1132 -     * <p> If a security manager is present, and the caller's class loader is
140.1133 -     * not null and the caller's class loader is not the same as or an ancestor of
140.1134 -     * the class loader for the class whose class loader is requested, then
140.1135 -     * this method calls the security manager's {@code checkPermission}
140.1136 -     * method with a {@code RuntimePermission("getClassLoader")}
140.1137 -     * permission to ensure it's ok to access the class loader for the class.
140.1138 -     *
140.1139 -     * <p>If this object
140.1140 -     * represents a primitive type or void, null is returned.
140.1141 -     *
140.1142 -     * @return  the class loader that loaded the class or interface
140.1143 -     *          represented by this object.
140.1144 -     * @throws SecurityException
140.1145 -     *    if a security manager exists and its
140.1146 -     *    {@code checkPermission} method denies
140.1147 -     *    access to the class loader for the class.
140.1148 -     * @see java.lang.ClassLoader
140.1149 -     * @see SecurityManager#checkPermission
140.1150 -     * @see java.lang.RuntimePermission
140.1151 -     */
140.1152 -    public ClassLoader getClassLoader() {
140.1153 -        throw new SecurityException();
140.1154 -    }
140.1155 -
140.1156 -    /**
140.1157 -     * Determines the interfaces implemented by the class or interface
140.1158 -     * represented by this object.
140.1159 -     *
140.1160 -     * <p> If this object represents a class, the return value is an array
140.1161 -     * containing objects representing all interfaces implemented by the
140.1162 -     * class. The order of the interface objects in the array corresponds to
140.1163 -     * the order of the interface names in the {@code implements} clause
140.1164 -     * of the declaration of the class represented by this object. For
140.1165 -     * example, given the declaration:
140.1166 -     * <blockquote>
140.1167 -     * {@code class Shimmer implements FloorWax, DessertTopping { ... }}
140.1168 -     * </blockquote>
140.1169 -     * suppose the value of {@code s} is an instance of
140.1170 -     * {@code Shimmer}; the value of the expression:
140.1171 -     * <blockquote>
140.1172 -     * {@code s.getClass().getInterfaces()[0]}
140.1173 -     * </blockquote>
140.1174 -     * is the {@code Class} object that represents interface
140.1175 -     * {@code FloorWax}; and the value of:
140.1176 -     * <blockquote>
140.1177 -     * {@code s.getClass().getInterfaces()[1]}
140.1178 -     * </blockquote>
140.1179 -     * is the {@code Class} object that represents interface
140.1180 -     * {@code DessertTopping}.
140.1181 -     *
140.1182 -     * <p> If this object represents an interface, the array contains objects
140.1183 -     * representing all interfaces extended by the interface. The order of the
140.1184 -     * interface objects in the array corresponds to the order of the interface
140.1185 -     * names in the {@code extends} clause of the declaration of the
140.1186 -     * interface represented by this object.
140.1187 -     *
140.1188 -     * <p> If this object represents a class or interface that implements no
140.1189 -     * interfaces, the method returns an array of length 0.
140.1190 -     *
140.1191 -     * <p> If this object represents a primitive type or void, the method
140.1192 -     * returns an array of length 0.
140.1193 -     *
140.1194 -     * @return an array of interfaces implemented by this class.
140.1195 -     */
140.1196 -    public native Class<?>[] getInterfaces();
140.1197 -    
140.1198 -    /**
140.1199 -     * Returns the {@code Class} representing the component type of an
140.1200 -     * array.  If this class does not represent an array class this method
140.1201 -     * returns null.
140.1202 -     *
140.1203 -     * @return the {@code Class} representing the component type of this
140.1204 -     * class if this class is an array
140.1205 -     * @see     java.lang.reflect.Array
140.1206 -     * @since JDK1.1
140.1207 -     */
140.1208 -    public Class<?> getComponentType() {
140.1209 -        if (isArray()) {
140.1210 -            try {
140.1211 -                return getComponentType0();
140.1212 -            } catch (ClassNotFoundException cnfe) {
140.1213 -                throw new IllegalStateException(cnfe);
140.1214 -            }
140.1215 -        }
140.1216 -        return null;
140.1217 -    }
140.1218 -
140.1219 -    private Class<?> getComponentType0() throws ClassNotFoundException {
140.1220 -        String n = getName().substring(1);
140.1221 -        switch (n.charAt(0)) {
140.1222 -            case 'L': 
140.1223 -                n = n.substring(1, n.length() - 1);
140.1224 -                return Class.forName(n);
140.1225 -            case 'I':
140.1226 -                return Integer.TYPE;
140.1227 -            case 'J':
140.1228 -                return Long.TYPE;
140.1229 -            case 'D':
140.1230 -                return Double.TYPE;
140.1231 -            case 'F':
140.1232 -                return Float.TYPE;
140.1233 -            case 'B':
140.1234 -                return Byte.TYPE;
140.1235 -            case 'Z':
140.1236 -                return Boolean.TYPE;
140.1237 -            case 'S':
140.1238 -                return Short.TYPE;
140.1239 -            case 'V':
140.1240 -                return Void.TYPE;
140.1241 -            case 'C':
140.1242 -                return Character.TYPE;
140.1243 -            case '[':
140.1244 -                return defineArray(n);
140.1245 -            default:
140.1246 -                throw new ClassNotFoundException("Unknown component type of " + getName());
140.1247 -        }
140.1248 -    }
140.1249 -    
140.1250 -    @JavaScriptBody(args = { "sig" }, body = 
140.1251 -        "var c = Array[sig];\n" +
140.1252 -        "if (c) return c;\n" +
140.1253 -        "c = vm.java_lang_Class(true);\n" +
140.1254 -        "c.jvmName = sig;\n" +
140.1255 -        "c.superclass = vm.java_lang_Object(false).$class;\n" +
140.1256 -        "c.array = true;\n" +
140.1257 -        "Array[sig] = c;\n" +
140.1258 -        "return c;"
140.1259 -    )
140.1260 -    private static native Class<?> defineArray(String sig);
140.1261 -    
140.1262 -    /**
140.1263 -     * Returns true if and only if this class was declared as an enum in the
140.1264 -     * source code.
140.1265 -     *
140.1266 -     * @return true if and only if this class was declared as an enum in the
140.1267 -     *     source code
140.1268 -     * @since 1.5
140.1269 -     */
140.1270 -    public boolean isEnum() {
140.1271 -        // An enum must both directly extend java.lang.Enum and have
140.1272 -        // the ENUM bit set; classes for specialized enum constants
140.1273 -        // don't do the former.
140.1274 -        return (this.getModifiers() & ENUM) != 0 &&
140.1275 -        this.getSuperclass() == java.lang.Enum.class;
140.1276 -    }
140.1277 -
140.1278 -    /**
140.1279 -     * Casts an object to the class or interface represented
140.1280 -     * by this {@code Class} object.
140.1281 -     *
140.1282 -     * @param obj the object to be cast
140.1283 -     * @return the object after casting, or null if obj is null
140.1284 -     *
140.1285 -     * @throws ClassCastException if the object is not
140.1286 -     * null and is not assignable to the type T.
140.1287 -     *
140.1288 -     * @since 1.5
140.1289 -     */
140.1290 -    public T cast(Object obj) {
140.1291 -        if (obj != null && !isInstance(obj))
140.1292 -            throw new ClassCastException(cannotCastMsg(obj));
140.1293 -        return (T) obj;
140.1294 -    }
140.1295 -
140.1296 -    private String cannotCastMsg(Object obj) {
140.1297 -        return "Cannot cast " + obj.getClass().getName() + " to " + getName();
140.1298 -    }
140.1299 -
140.1300 -    /**
140.1301 -     * Casts this {@code Class} object to represent a subclass of the class
140.1302 -     * represented by the specified class object.  Checks that that the cast
140.1303 -     * is valid, and throws a {@code ClassCastException} if it is not.  If
140.1304 -     * this method succeeds, it always returns a reference to this class object.
140.1305 -     *
140.1306 -     * <p>This method is useful when a client needs to "narrow" the type of
140.1307 -     * a {@code Class} object to pass it to an API that restricts the
140.1308 -     * {@code Class} objects that it is willing to accept.  A cast would
140.1309 -     * generate a compile-time warning, as the correctness of the cast
140.1310 -     * could not be checked at runtime (because generic types are implemented
140.1311 -     * by erasure).
140.1312 -     *
140.1313 -     * @return this {@code Class} object, cast to represent a subclass of
140.1314 -     *    the specified class object.
140.1315 -     * @throws ClassCastException if this {@code Class} object does not
140.1316 -     *    represent a subclass of the specified class (here "subclass" includes
140.1317 -     *    the class itself).
140.1318 -     * @since 1.5
140.1319 -     */
140.1320 -    public <U> Class<? extends U> asSubclass(Class<U> clazz) {
140.1321 -        if (clazz.isAssignableFrom(this))
140.1322 -            return (Class<? extends U>) this;
140.1323 -        else
140.1324 -            throw new ClassCastException(this.toString());
140.1325 -    }
140.1326 -
140.1327 -    @JavaScriptBody(args = { "ac" }, 
140.1328 -        body = 
140.1329 -          "if (this.anno) {"
140.1330 -        + "  return this.anno['L' + ac.jvmName + ';'];"
140.1331 -        + "} else return null;"
140.1332 -    )
140.1333 -    private Object getAnnotationData(Class<?> annotationClass) {
140.1334 -        throw new UnsupportedOperationException();
140.1335 -    }
140.1336 -    /**
140.1337 -     * @throws NullPointerException {@inheritDoc}
140.1338 -     * @since 1.5
140.1339 -     */
140.1340 -    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
140.1341 -        Object data = getAnnotationData(annotationClass);
140.1342 -        return data == null ? null : AnnotationImpl.create(annotationClass, data);
140.1343 -    }
140.1344 -
140.1345 -    /**
140.1346 -     * @throws NullPointerException {@inheritDoc}
140.1347 -     * @since 1.5
140.1348 -     */
140.1349 -    @JavaScriptBody(args = { "ac" }, 
140.1350 -        body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
140.1351 -        + "else return false;"
140.1352 -    )
140.1353 -    public boolean isAnnotationPresent(
140.1354 -        Class<? extends Annotation> annotationClass) {
140.1355 -        if (annotationClass == null)
140.1356 -            throw new NullPointerException();
140.1357 -
140.1358 -        return getAnnotation(annotationClass) != null;
140.1359 -    }
140.1360 -
140.1361 -    @JavaScriptBody(args = {}, body = "return this.anno;")
140.1362 -    private Object getAnnotationData() {
140.1363 -        throw new UnsupportedOperationException();
140.1364 -    }
140.1365 -
140.1366 -    /**
140.1367 -     * @since 1.5
140.1368 -     */
140.1369 -    public Annotation[] getAnnotations() {
140.1370 -        Object data = getAnnotationData();
140.1371 -        return data == null ? new Annotation[0] : AnnotationImpl.create(data);
140.1372 -    }
140.1373 -
140.1374 -    /**
140.1375 -     * @since 1.5
140.1376 -     */
140.1377 -    public Annotation[] getDeclaredAnnotations()  {
140.1378 -        throw new UnsupportedOperationException();
140.1379 -    }
140.1380 -
140.1381 -    @JavaScriptBody(args = "type", body = ""
140.1382 -        + "var c = vm.java_lang_Class(true);"
140.1383 -        + "c.jvmName = type;"
140.1384 -        + "c.primitive = true;"
140.1385 -        + "return c;"
140.1386 -    )
140.1387 -    native static Class getPrimitiveClass(String type);
140.1388 -
140.1389 -    @JavaScriptBody(args = {}, body = 
140.1390 -        "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
140.1391 -    )
140.1392 -    public native boolean desiredAssertionStatus();
140.1393 -}
   141.1 --- a/emul/mini/src/main/java/java/lang/ClassCastException.java	Mon Feb 25 19:00:08 2013 +0100
   141.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   141.3 @@ -1,60 +0,0 @@
   141.4 -/*
   141.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   141.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   141.7 - *
   141.8 - * This code is free software; you can redistribute it and/or modify it
   141.9 - * under the terms of the GNU General Public License version 2 only, as
  141.10 - * published by the Free Software Foundation.  Oracle designates this
  141.11 - * particular file as subject to the "Classpath" exception as provided
  141.12 - * by Oracle in the LICENSE file that accompanied this code.
  141.13 - *
  141.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  141.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  141.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  141.17 - * version 2 for more details (a copy is included in the LICENSE file that
  141.18 - * accompanied this code).
  141.19 - *
  141.20 - * You should have received a copy of the GNU General Public License version
  141.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  141.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  141.23 - *
  141.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  141.25 - * or visit www.oracle.com if you need additional information or have any
  141.26 - * questions.
  141.27 - */
  141.28 -
  141.29 -package java.lang;
  141.30 -
  141.31 -/**
  141.32 - * Thrown to indicate that the code has attempted to cast an object
  141.33 - * to a subclass of which it is not an instance. For example, the
  141.34 - * following code generates a <code>ClassCastException</code>:
  141.35 - * <p><blockquote><pre>
  141.36 - *     Object x = new Integer(0);
  141.37 - *     System.out.println((String)x);
  141.38 - * </pre></blockquote>
  141.39 - *
  141.40 - * @author  unascribed
  141.41 - * @since   JDK1.0
  141.42 - */
  141.43 -public
  141.44 -class ClassCastException extends RuntimeException {
  141.45 -    private static final long serialVersionUID = -9223365651070458532L;
  141.46 -
  141.47 -    /**
  141.48 -     * Constructs a <code>ClassCastException</code> with no detail message.
  141.49 -     */
  141.50 -    public ClassCastException() {
  141.51 -        super();
  141.52 -    }
  141.53 -
  141.54 -    /**
  141.55 -     * Constructs a <code>ClassCastException</code> with the specified
  141.56 -     * detail message.
  141.57 -     *
  141.58 -     * @param   s   the detail message.
  141.59 -     */
  141.60 -    public ClassCastException(String s) {
  141.61 -        super(s);
  141.62 -    }
  141.63 -}
   142.1 --- a/emul/mini/src/main/java/java/lang/ClassFormatError.java	Mon Feb 25 19:00:08 2013 +0100
   142.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   142.3 @@ -1,56 +0,0 @@
   142.4 -/*
   142.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   142.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   142.7 - *
   142.8 - * This code is free software; you can redistribute it and/or modify it
   142.9 - * under the terms of the GNU General Public License version 2 only, as
  142.10 - * published by the Free Software Foundation.  Oracle designates this
  142.11 - * particular file as subject to the "Classpath" exception as provided
  142.12 - * by Oracle in the LICENSE file that accompanied this code.
  142.13 - *
  142.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  142.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  142.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  142.17 - * version 2 for more details (a copy is included in the LICENSE file that
  142.18 - * accompanied this code).
  142.19 - *
  142.20 - * You should have received a copy of the GNU General Public License version
  142.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  142.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  142.23 - *
  142.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  142.25 - * or visit www.oracle.com if you need additional information or have any
  142.26 - * questions.
  142.27 - */
  142.28 -
  142.29 -package java.lang;
  142.30 -
  142.31 -/**
  142.32 - * Thrown when the Java Virtual Machine attempts to read a class
  142.33 - * file and determines that the file is malformed or otherwise cannot
  142.34 - * be interpreted as a class file.
  142.35 - *
  142.36 - * @author  unascribed
  142.37 - * @since   JDK1.0
  142.38 - */
  142.39 -public
  142.40 -class ClassFormatError extends LinkageError {
  142.41 -    private static final long serialVersionUID = -8420114879011949195L;
  142.42 -
  142.43 -    /**
  142.44 -     * Constructs a <code>ClassFormatError</code> with no detail message.
  142.45 -     */
  142.46 -    public ClassFormatError() {
  142.47 -        super();
  142.48 -    }
  142.49 -
  142.50 -    /**
  142.51 -     * Constructs a <code>ClassFormatError</code> with the specified
  142.52 -     * detail message.
  142.53 -     *
  142.54 -     * @param   s   the detail message.
  142.55 -     */
  142.56 -    public ClassFormatError(String s) {
  142.57 -        super(s);
  142.58 -    }
  142.59 -}
   143.1 --- a/emul/mini/src/main/java/java/lang/ClassLoader.java	Mon Feb 25 19:00:08 2013 +0100
   143.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   143.3 @@ -1,936 +0,0 @@
   143.4 -/*
   143.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   143.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   143.7 - *
   143.8 - * This code is free software; you can redistribute it and/or modify it
   143.9 - * under the terms of the GNU General Public License version 2 only, as
  143.10 - * published by the Free Software Foundation.  Oracle designates this
  143.11 - * particular file as subject to the "Classpath" exception as provided
  143.12 - * by Oracle in the LICENSE file that accompanied this code.
  143.13 - *
  143.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  143.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  143.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  143.17 - * version 2 for more details (a copy is included in the LICENSE file that
  143.18 - * accompanied this code).
  143.19 - *
  143.20 - * You should have received a copy of the GNU General Public License version
  143.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  143.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  143.23 - *
  143.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  143.25 - * or visit www.oracle.com if you need additional information or have any
  143.26 - * questions.
  143.27 - */
  143.28 -package java.lang;
  143.29 -
  143.30 -import java.io.InputStream;
  143.31 -import java.io.IOException;
  143.32 -import java.net.URL;
  143.33 -import java.util.Enumeration;
  143.34 -import java.util.NoSuchElementException;
  143.35 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  143.36 -
  143.37 -/**
  143.38 - * A class loader is an object that is responsible for loading classes. The
  143.39 - * class <tt>ClassLoader</tt> is an abstract class.  Given the <a
  143.40 - * href="#name">binary name</a> of a class, a class loader should attempt to
  143.41 - * locate or generate data that constitutes a definition for the class.  A
  143.42 - * typical strategy is to transform the name into a file name and then read a
  143.43 - * "class file" of that name from a file system.
  143.44 - *
  143.45 - * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
  143.46 - * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
  143.47 - * it.
  143.48 - *
  143.49 - * <p> <tt>Class</tt> objects for array classes are not created by class
  143.50 - * loaders, but are created automatically as required by the Java runtime.
  143.51 - * The class loader for an array class, as returned by {@link
  143.52 - * Class#getClassLoader()} is the same as the class loader for its element
  143.53 - * type; if the element type is a primitive type, then the array class has no
  143.54 - * class loader.
  143.55 - *
  143.56 - * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
  143.57 - * extend the manner in which the Java virtual machine dynamically loads
  143.58 - * classes.
  143.59 - *
  143.60 - * <p> Class loaders may typically be used by security managers to indicate
  143.61 - * security domains.
  143.62 - *
  143.63 - * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
  143.64 - * classes and resources.  Each instance of <tt>ClassLoader</tt> has an
  143.65 - * associated parent class loader.  When requested to find a class or
  143.66 - * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
  143.67 - * class or resource to its parent class loader before attempting to find the
  143.68 - * class or resource itself.  The virtual machine's built-in class loader,
  143.69 - * called the "bootstrap class loader", does not itself have a parent but may
  143.70 - * serve as the parent of a <tt>ClassLoader</tt> instance.
  143.71 - *
  143.72 - * <p> Class loaders that support concurrent loading of classes are known as
  143.73 - * <em>parallel capable</em> class loaders and are required to register
  143.74 - * themselves at their class initialization time by invoking the
  143.75 - * {@link
  143.76 - * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
  143.77 - * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
  143.78 - * capable by default. However, its subclasses still need to register themselves
  143.79 - * if they are parallel capable. <br>
  143.80 - * In environments in which the delegation model is not strictly
  143.81 - * hierarchical, class loaders need to be parallel capable, otherwise class
  143.82 - * loading can lead to deadlocks because the loader lock is held for the
  143.83 - * duration of the class loading process (see {@link #loadClass
  143.84 - * <tt>loadClass</tt>} methods).
  143.85 - *
  143.86 - * <p> Normally, the Java virtual machine loads classes from the local file
  143.87 - * system in a platform-dependent manner.  For example, on UNIX systems, the
  143.88 - * virtual machine loads classes from the directory defined by the
  143.89 - * <tt>CLASSPATH</tt> environment variable.
  143.90 - *
  143.91 - * <p> However, some classes may not originate from a file; they may originate
  143.92 - * from other sources, such as the network, or they could be constructed by an
  143.93 - * application.  The method {@link #defineClass(String, byte[], int, int)
  143.94 - * <tt>defineClass</tt>} converts an array of bytes into an instance of class
  143.95 - * <tt>Class</tt>. Instances of this newly defined class can be created using
  143.96 - * {@link Class#newInstance <tt>Class.newInstance</tt>}.
  143.97 - *
  143.98 - * <p> The methods and constructors of objects created by a class loader may
  143.99 - * reference other classes.  To determine the class(es) referred to, the Java
 143.100 - * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
 143.101 - * the class loader that originally created the class.
 143.102 - *
 143.103 - * <p> For example, an application could create a network class loader to
 143.104 - * download class files from a server.  Sample code might look like:
 143.105 - *
 143.106 - * <blockquote><pre>
 143.107 - *   ClassLoader loader&nbsp;= new NetworkClassLoader(host,&nbsp;port);
 143.108 - *   Object main&nbsp;= loader.loadClass("Main", true).newInstance();
 143.109 - *       &nbsp;.&nbsp;.&nbsp;.
 143.110 - * </pre></blockquote>
 143.111 - *
 143.112 - * <p> The network class loader subclass must define the methods {@link
 143.113 - * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
 143.114 - * from the network.  Once it has downloaded the bytes that make up the class,
 143.115 - * it should use the method {@link #defineClass <tt>defineClass</tt>} to
 143.116 - * create a class instance.  A sample implementation is:
 143.117 - *
 143.118 - * <blockquote><pre>
 143.119 - *     class NetworkClassLoader extends ClassLoader {
 143.120 - *         String host;
 143.121 - *         int port;
 143.122 - *
 143.123 - *         public Class findClass(String name) {
 143.124 - *             byte[] b = loadClassData(name);
 143.125 - *             return defineClass(name, b, 0, b.length);
 143.126 - *         }
 143.127 - *
 143.128 - *         private byte[] loadClassData(String name) {
 143.129 - *             // load the class data from the connection
 143.130 - *             &nbsp;.&nbsp;.&nbsp;.
 143.131 - *         }
 143.132 - *     }
 143.133 - * </pre></blockquote>
 143.134 - *
 143.135 - * <h4> <a name="name">Binary names</a> </h4>
 143.136 - *
 143.137 - * <p> Any class name provided as a {@link String} parameter to methods in
 143.138 - * <tt>ClassLoader</tt> must be a binary name as defined by
 143.139 - * <cite>The Java&trade; Language Specification</cite>.
 143.140 - *
 143.141 - * <p> Examples of valid class names include:
 143.142 - * <blockquote><pre>
 143.143 - *   "java.lang.String"
 143.144 - *   "javax.swing.JSpinner$DefaultEditor"
 143.145 - *   "java.security.KeyStore$Builder$FileBuilder$1"
 143.146 - *   "java.net.URLClassLoader$3$1"
 143.147 - * </pre></blockquote>
 143.148 - *
 143.149 - * @see      #resolveClass(Class)
 143.150 - * @since 1.0
 143.151 - */
 143.152 -public abstract class ClassLoader {
 143.153 -
 143.154 -    @JavaScriptBody(args = {}, body = "")
 143.155 -    private static native void registerNatives();
 143.156 -    static {
 143.157 -        registerNatives();
 143.158 -    }
 143.159 -
 143.160 -    // The parent class loader for delegation
 143.161 -    // Note: VM hardcoded the offset of this field, thus all new fields
 143.162 -    // must be added *after* it.
 143.163 -    private final ClassLoader parent;
 143.164 -
 143.165 -
 143.166 -    /**
 143.167 -     * Creates a new class loader using the specified parent class loader for
 143.168 -     * delegation.
 143.169 -     *
 143.170 -     * <p> If there is a security manager, its {@link
 143.171 -     * SecurityManager#checkCreateClassLoader()
 143.172 -     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 143.173 -     * a security exception.  </p>
 143.174 -     *
 143.175 -     * @param  parent
 143.176 -     *         The parent class loader
 143.177 -     *
 143.178 -     * @throws  SecurityException
 143.179 -     *          If a security manager exists and its
 143.180 -     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 143.181 -     *          of a new class loader.
 143.182 -     *
 143.183 -     * @since  1.2
 143.184 -     */
 143.185 -    protected ClassLoader(ClassLoader parent) {
 143.186 -        throw new SecurityException();
 143.187 -    }
 143.188 -
 143.189 -    /**
 143.190 -     * Creates a new class loader using the <tt>ClassLoader</tt> returned by
 143.191 -     * the method {@link #getSystemClassLoader()
 143.192 -     * <tt>getSystemClassLoader()</tt>} as the parent class loader.
 143.193 -     *
 143.194 -     * <p> If there is a security manager, its {@link
 143.195 -     * SecurityManager#checkCreateClassLoader()
 143.196 -     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 143.197 -     * a security exception.  </p>
 143.198 -     *
 143.199 -     * @throws  SecurityException
 143.200 -     *          If a security manager exists and its
 143.201 -     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 143.202 -     *          of a new class loader.
 143.203 -     */
 143.204 -    protected ClassLoader() {
 143.205 -        throw new SecurityException();
 143.206 -    }
 143.207 -
 143.208 -    // -- Class --
 143.209 -
 143.210 -    /**
 143.211 -     * Loads the class with the specified <a href="#name">binary name</a>.
 143.212 -     * This method searches for classes in the same manner as the {@link
 143.213 -     * #loadClass(String, boolean)} method.  It is invoked by the Java virtual
 143.214 -     * machine to resolve class references.  Invoking this method is equivalent
 143.215 -     * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
 143.216 -     * false)</tt>}.  </p>
 143.217 -     *
 143.218 -     * @param  name
 143.219 -     *         The <a href="#name">binary name</a> of the class
 143.220 -     *
 143.221 -     * @return  The resulting <tt>Class</tt> object
 143.222 -     *
 143.223 -     * @throws  ClassNotFoundException
 143.224 -     *          If the class was not found
 143.225 -     */
 143.226 -    public Class<?> loadClass(String name) throws ClassNotFoundException {
 143.227 -        return loadClass(name, false);
 143.228 -    }
 143.229 -
 143.230 -    /**
 143.231 -     * Loads the class with the specified <a href="#name">binary name</a>.  The
 143.232 -     * default implementation of this method searches for classes in the
 143.233 -     * following order:
 143.234 -     *
 143.235 -     * <p><ol>
 143.236 -     *
 143.237 -     *   <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
 143.238 -     *   has already been loaded.  </p></li>
 143.239 -     *
 143.240 -     *   <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
 143.241 -     *   on the parent class loader.  If the parent is <tt>null</tt> the class
 143.242 -     *   loader built-in to the virtual machine is used, instead.  </p></li>
 143.243 -     *
 143.244 -     *   <li><p> Invoke the {@link #findClass(String)} method to find the
 143.245 -     *   class.  </p></li>
 143.246 -     *
 143.247 -     * </ol>
 143.248 -     *
 143.249 -     * <p> If the class was found using the above steps, and the
 143.250 -     * <tt>resolve</tt> flag is true, this method will then invoke the {@link
 143.251 -     * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
 143.252 -     *
 143.253 -     * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
 143.254 -     * #findClass(String)}, rather than this method.  </p>
 143.255 -     *
 143.256 -     * <p> Unless overridden, this method synchronizes on the result of
 143.257 -     * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
 143.258 -     * during the entire class loading process.
 143.259 -     *
 143.260 -     * @param  name
 143.261 -     *         The <a href="#name">binary name</a> of the class
 143.262 -     *
 143.263 -     * @param  resolve
 143.264 -     *         If <tt>true</tt> then resolve the class
 143.265 -     *
 143.266 -     * @return  The resulting <tt>Class</tt> object
 143.267 -     *
 143.268 -     * @throws  ClassNotFoundException
 143.269 -     *          If the class could not be found
 143.270 -     */
 143.271 -    protected Class<?> loadClass(String name, boolean resolve)
 143.272 -        throws ClassNotFoundException
 143.273 -    {
 143.274 -        synchronized (getClassLoadingLock(name)) {
 143.275 -            // First, check if the class has already been loaded
 143.276 -            Class c = findLoadedClass(name);
 143.277 -            if (c == null) {
 143.278 -                try {
 143.279 -                    if (parent != null) {
 143.280 -                        c = parent.loadClass(name, false);
 143.281 -                    } else {
 143.282 -                        c = findBootstrapClassOrNull(name);
 143.283 -                    }
 143.284 -                } catch (ClassNotFoundException e) {
 143.285 -                    // ClassNotFoundException thrown if class not found
 143.286 -                    // from the non-null parent class loader
 143.287 -                }
 143.288 -
 143.289 -                if (c == null) {
 143.290 -                    // If still not found, then invoke findClass in order
 143.291 -                    // to find the class.
 143.292 -                    c = findClass(name);
 143.293 -
 143.294 -//                    // this is the defining class loader; record the stats
 143.295 -//                    sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
 143.296 -//                    sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
 143.297 -//                    sun.misc.PerfCounter.getFindClasses().increment();
 143.298 -                }
 143.299 -            }
 143.300 -            if (resolve) {
 143.301 -                resolveClass(c);
 143.302 -            }
 143.303 -            return c;
 143.304 -        }
 143.305 -    }
 143.306 -
 143.307 -    /**
 143.308 -     * Returns the lock object for class loading operations.
 143.309 -     * For backward compatibility, the default implementation of this method
 143.310 -     * behaves as follows. If this ClassLoader object is registered as
 143.311 -     * parallel capable, the method returns a dedicated object associated
 143.312 -     * with the specified class name. Otherwise, the method returns this
 143.313 -     * ClassLoader object. </p>
 143.314 -     *
 143.315 -     * @param  className
 143.316 -     *         The name of the to-be-loaded class
 143.317 -     *
 143.318 -     * @return the lock for class loading operations
 143.319 -     *
 143.320 -     * @throws NullPointerException
 143.321 -     *         If registered as parallel capable and <tt>className</tt> is null
 143.322 -     *
 143.323 -     * @see #loadClass(String, boolean)
 143.324 -     *
 143.325 -     * @since  1.7
 143.326 -     */
 143.327 -    protected Object getClassLoadingLock(String className) {
 143.328 -        Object lock = this;
 143.329 -        return lock;
 143.330 -    }
 143.331 -
 143.332 -    /**
 143.333 -     * Finds the class with the specified <a href="#name">binary name</a>.
 143.334 -     * This method should be overridden by class loader implementations that
 143.335 -     * follow the delegation model for loading classes, and will be invoked by
 143.336 -     * the {@link #loadClass <tt>loadClass</tt>} method after checking the
 143.337 -     * parent class loader for the requested class.  The default implementation
 143.338 -     * throws a <tt>ClassNotFoundException</tt>.  </p>
 143.339 -     *
 143.340 -     * @param  name
 143.341 -     *         The <a href="#name">binary name</a> of the class
 143.342 -     *
 143.343 -     * @return  The resulting <tt>Class</tt> object
 143.344 -     *
 143.345 -     * @throws  ClassNotFoundException
 143.346 -     *          If the class could not be found
 143.347 -     *
 143.348 -     * @since  1.2
 143.349 -     */
 143.350 -    protected Class<?> findClass(String name) throws ClassNotFoundException {
 143.351 -        throw new ClassNotFoundException(name);
 143.352 -    }
 143.353 -
 143.354 -    /**
 143.355 -     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 143.356 -     * Before the <tt>Class</tt> can be used it must be resolved.  This method
 143.357 -     * is deprecated in favor of the version that takes a <a
 143.358 -     * href="#name">binary name</a> as its first argument, and is more secure.
 143.359 -     *
 143.360 -     * @param  b
 143.361 -     *         The bytes that make up the class data.  The bytes in positions
 143.362 -     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 143.363 -     *         of a valid class file as defined by
 143.364 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 143.365 -     *
 143.366 -     * @param  off
 143.367 -     *         The start offset in <tt>b</tt> of the class data
 143.368 -     *
 143.369 -     * @param  len
 143.370 -     *         The length of the class data
 143.371 -     *
 143.372 -     * @return  The <tt>Class</tt> object that was created from the specified
 143.373 -     *          class data
 143.374 -     *
 143.375 -     * @throws  ClassFormatError
 143.376 -     *          If the data did not contain a valid class
 143.377 -     *
 143.378 -     * @throws  IndexOutOfBoundsException
 143.379 -     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 143.380 -     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 143.381 -     *
 143.382 -     * @throws  SecurityException
 143.383 -     *          If an attempt is made to add this class to a package that
 143.384 -     *          contains classes that were signed by a different set of
 143.385 -     *          certificates than this class, or if an attempt is made
 143.386 -     *          to define a class in a package with a fully-qualified name
 143.387 -     *          that starts with "{@code java.}".
 143.388 -     *
 143.389 -     * @see  #loadClass(String, boolean)
 143.390 -     * @see  #resolveClass(Class)
 143.391 -     *
 143.392 -     * @deprecated  Replaced by {@link #defineClass(String, byte[], int, int)
 143.393 -     * defineClass(String, byte[], int, int)}
 143.394 -     */
 143.395 -    @Deprecated
 143.396 -    protected final Class<?> defineClass(byte[] b, int off, int len)
 143.397 -        throws ClassFormatError
 143.398 -    {
 143.399 -        throw new SecurityException();
 143.400 -    }
 143.401 -
 143.402 -    /**
 143.403 -     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 143.404 -     * Before the <tt>Class</tt> can be used it must be resolved.
 143.405 -     *
 143.406 -     * <p> This method assigns a default {@link java.security.ProtectionDomain
 143.407 -     * <tt>ProtectionDomain</tt>} to the newly defined class.  The
 143.408 -     * <tt>ProtectionDomain</tt> is effectively granted the same set of
 143.409 -     * permissions returned when {@link
 143.410 -     * java.security.Policy#getPermissions(java.security.CodeSource)
 143.411 -     * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
 143.412 -     * is invoked.  The default domain is created on the first invocation of
 143.413 -     * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
 143.414 -     * and re-used on subsequent invocations.
 143.415 -     *
 143.416 -     * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
 143.417 -     * the {@link #defineClass(String, byte[], int, int,
 143.418 -     * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
 143.419 -     * <tt>ProtectionDomain</tt> as one of its arguments.  </p>
 143.420 -     *
 143.421 -     * @param  name
 143.422 -     *         The expected <a href="#name">binary name</a> of the class, or
 143.423 -     *         <tt>null</tt> if not known
 143.424 -     *
 143.425 -     * @param  b
 143.426 -     *         The bytes that make up the class data.  The bytes in positions
 143.427 -     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 143.428 -     *         of a valid class file as defined by
 143.429 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 143.430 -     *
 143.431 -     * @param  off
 143.432 -     *         The start offset in <tt>b</tt> of the class data
 143.433 -     *
 143.434 -     * @param  len
 143.435 -     *         The length of the class data
 143.436 -     *
 143.437 -     * @return  The <tt>Class</tt> object that was created from the specified
 143.438 -     *          class data.
 143.439 -     *
 143.440 -     * @throws  ClassFormatError
 143.441 -     *          If the data did not contain a valid class
 143.442 -     *
 143.443 -     * @throws  IndexOutOfBoundsException
 143.444 -     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 143.445 -     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 143.446 -     *
 143.447 -     * @throws  SecurityException
 143.448 -     *          If an attempt is made to add this class to a package that
 143.449 -     *          contains classes that were signed by a different set of
 143.450 -     *          certificates than this class (which is unsigned), or if
 143.451 -     *          <tt>name</tt> begins with "<tt>java.</tt>".
 143.452 -     *
 143.453 -     * @see  #loadClass(String, boolean)
 143.454 -     * @see  #resolveClass(Class)
 143.455 -     * @see  java.security.CodeSource
 143.456 -     * @see  java.security.SecureClassLoader
 143.457 -     *
 143.458 -     * @since  1.1
 143.459 -     */
 143.460 -    protected final Class<?> defineClass(String name, byte[] b, int off, int len)
 143.461 -        throws ClassFormatError
 143.462 -    {
 143.463 -        throw new SecurityException();
 143.464 -    }
 143.465 -
 143.466 -    /**
 143.467 -     * Links the specified class.  This (misleadingly named) method may be
 143.468 -     * used by a class loader to link a class.  If the class <tt>c</tt> has
 143.469 -     * already been linked, then this method simply returns. Otherwise, the
 143.470 -     * class is linked as described in the "Execution" chapter of
 143.471 -     * <cite>The Java&trade; Language Specification</cite>.
 143.472 -     * </p>
 143.473 -     *
 143.474 -     * @param  c
 143.475 -     *         The class to link
 143.476 -     *
 143.477 -     * @throws  NullPointerException
 143.478 -     *          If <tt>c</tt> is <tt>null</tt>.
 143.479 -     *
 143.480 -     * @see  #defineClass(String, byte[], int, int)
 143.481 -     */
 143.482 -    protected final void resolveClass(Class<?> c) {
 143.483 -        resolveClass0(c);
 143.484 -    }
 143.485 -
 143.486 -    private native void resolveClass0(Class c);
 143.487 -
 143.488 -
 143.489 -    /**
 143.490 -     * Returns the class with the given <a href="#name">binary name</a> if this
 143.491 -     * loader has been recorded by the Java virtual machine as an initiating
 143.492 -     * loader of a class with that <a href="#name">binary name</a>.  Otherwise
 143.493 -     * <tt>null</tt> is returned.  </p>
 143.494 -     *
 143.495 -     * @param  name
 143.496 -     *         The <a href="#name">binary name</a> of the class
 143.497 -     *
 143.498 -     * @return  The <tt>Class</tt> object, or <tt>null</tt> if the class has
 143.499 -     *          not been loaded
 143.500 -     *
 143.501 -     * @since  1.1
 143.502 -     */
 143.503 -    protected final Class<?> findLoadedClass(String name) {
 143.504 -        if (!checkName(name))
 143.505 -            return null;
 143.506 -        return findLoadedClass0(name);
 143.507 -    }
 143.508 -
 143.509 -    private native final Class findLoadedClass0(String name);
 143.510 -
 143.511 -    /**
 143.512 -     * Sets the signers of a class.  This should be invoked after defining a
 143.513 -     * class.  </p>
 143.514 -     *
 143.515 -     * @param  c
 143.516 -     *         The <tt>Class</tt> object
 143.517 -     *
 143.518 -     * @param  signers
 143.519 -     *         The signers for the class
 143.520 -     *
 143.521 -     * @since  1.1
 143.522 -     */
 143.523 -    protected final void setSigners(Class<?> c, Object[] signers) {
 143.524 -        //c.setSigners(signers);
 143.525 -        throw new UnsupportedOperationException();
 143.526 -    }
 143.527 -
 143.528 -
 143.529 -    // -- Resource --
 143.530 -
 143.531 -    /**
 143.532 -     * Finds the resource with the given name.  A resource is some data
 143.533 -     * (images, audio, text, etc) that can be accessed by class code in a way
 143.534 -     * that is independent of the location of the code.
 143.535 -     *
 143.536 -     * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
 143.537 -     * identifies the resource.
 143.538 -     *
 143.539 -     * <p> This method will first search the parent class loader for the
 143.540 -     * resource; if the parent is <tt>null</tt> the path of the class loader
 143.541 -     * built-in to the virtual machine is searched.  That failing, this method
 143.542 -     * will invoke {@link #findResource(String)} to find the resource.  </p>
 143.543 -     *
 143.544 -     * @param  name
 143.545 -     *         The resource name
 143.546 -     *
 143.547 -     * @return  A <tt>URL</tt> object for reading the resource, or
 143.548 -     *          <tt>null</tt> if the resource could not be found or the invoker
 143.549 -     *          doesn't have adequate  privileges to get the resource.
 143.550 -     *
 143.551 -     * @since  1.1
 143.552 -     */
 143.553 -    public URL getResource(String name) {
 143.554 -        URL url;
 143.555 -        if (parent != null) {
 143.556 -            url = parent.getResource(name);
 143.557 -        } else {
 143.558 -            url = getBootstrapResource(name);
 143.559 -        }
 143.560 -        if (url == null) {
 143.561 -            url = findResource(name);
 143.562 -        }
 143.563 -        return url;
 143.564 -    }
 143.565 -
 143.566 -    /**
 143.567 -     * Finds all the resources with the given name. A resource is some data
 143.568 -     * (images, audio, text, etc) that can be accessed by class code in a way
 143.569 -     * that is independent of the location of the code.
 143.570 -     *
 143.571 -     * <p>The name of a resource is a <tt>/</tt>-separated path name that
 143.572 -     * identifies the resource.
 143.573 -     *
 143.574 -     * <p> The search order is described in the documentation for {@link
 143.575 -     * #getResource(String)}.  </p>
 143.576 -     *
 143.577 -     * @param  name
 143.578 -     *         The resource name
 143.579 -     *
 143.580 -     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 143.581 -     *          the resource.  If no resources could  be found, the enumeration
 143.582 -     *          will be empty.  Resources that the class loader doesn't have
 143.583 -     *          access to will not be in the enumeration.
 143.584 -     *
 143.585 -     * @throws  IOException
 143.586 -     *          If I/O errors occur
 143.587 -     *
 143.588 -     * @see  #findResources(String)
 143.589 -     *
 143.590 -     * @since  1.2
 143.591 -     */
 143.592 -    public Enumeration<URL> getResources(String name) throws IOException {
 143.593 -        Enumeration[] tmp = new Enumeration[2];
 143.594 -        if (parent != null) {
 143.595 -            tmp[0] = parent.getResources(name);
 143.596 -        } else {
 143.597 -            tmp[0] = getBootstrapResources(name);
 143.598 -        }
 143.599 -        tmp[1] = findResources(name);
 143.600 -
 143.601 -        return new CompoundEnumeration(tmp);
 143.602 -    }
 143.603 -
 143.604 -    /**
 143.605 -     * Finds the resource with the given name. Class loader implementations
 143.606 -     * should override this method to specify where to find resources.  </p>
 143.607 -     *
 143.608 -     * @param  name
 143.609 -     *         The resource name
 143.610 -     *
 143.611 -     * @return  A <tt>URL</tt> object for reading the resource, or
 143.612 -     *          <tt>null</tt> if the resource could not be found
 143.613 -     *
 143.614 -     * @since  1.2
 143.615 -     */
 143.616 -    protected URL findResource(String name) {
 143.617 -        return null;
 143.618 -    }
 143.619 -
 143.620 -    /**
 143.621 -     * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
 143.622 -     * representing all the resources with the given name. Class loader
 143.623 -     * implementations should override this method to specify where to load
 143.624 -     * resources from.  </p>
 143.625 -     *
 143.626 -     * @param  name
 143.627 -     *         The resource name
 143.628 -     *
 143.629 -     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 143.630 -     *          the resources
 143.631 -     *
 143.632 -     * @throws  IOException
 143.633 -     *          If I/O errors occur
 143.634 -     *
 143.635 -     * @since  1.2
 143.636 -     */
 143.637 -    protected Enumeration<URL> findResources(String name) throws IOException {
 143.638 -        return new CompoundEnumeration(new Enumeration[0]);
 143.639 -    }
 143.640 -
 143.641 -    // index 0: java.lang.ClassLoader.class
 143.642 -    // index 1: the immediate caller of index 0.
 143.643 -    // index 2: the immediate caller of index 1.
 143.644 -    private static native Class<? extends ClassLoader> getCaller(int index);
 143.645 -
 143.646 -    /**
 143.647 -     * Registers the caller as parallel capable.</p>
 143.648 -     * The registration succeeds if and only if all of the following
 143.649 -     * conditions are met: <br>
 143.650 -     * 1. no instance of the caller has been created</p>
 143.651 -     * 2. all of the super classes (except class Object) of the caller are
 143.652 -     * registered as parallel capable</p>
 143.653 -     * Note that once a class loader is registered as parallel capable, there
 143.654 -     * is no way to change it back. </p>
 143.655 -     *
 143.656 -     * @return  true if the caller is successfully registered as
 143.657 -     *          parallel capable and false if otherwise.
 143.658 -     *
 143.659 -     * @since   1.7
 143.660 -     */
 143.661 -//    protected static boolean registerAsParallelCapable() {
 143.662 -//        return false;
 143.663 -//    }
 143.664 -
 143.665 -    /**
 143.666 -     * Find a resource of the specified name from the search path used to load
 143.667 -     * classes.  This method locates the resource through the system class
 143.668 -     * loader (see {@link #getSystemClassLoader()}).  </p>
 143.669 -     *
 143.670 -     * @param  name
 143.671 -     *         The resource name
 143.672 -     *
 143.673 -     * @return  A {@link java.net.URL <tt>URL</tt>} object for reading the
 143.674 -     *          resource, or <tt>null</tt> if the resource could not be found
 143.675 -     *
 143.676 -     * @since  1.1
 143.677 -     */
 143.678 -    public static URL getSystemResource(String name) {
 143.679 -        ClassLoader system = getSystemClassLoader();
 143.680 -        if (system == null) {
 143.681 -            return getBootstrapResource(name);
 143.682 -        }
 143.683 -        return system.getResource(name);
 143.684 -    }
 143.685 -
 143.686 -    /**
 143.687 -     * Finds all resources of the specified name from the search path used to
 143.688 -     * load classes.  The resources thus found are returned as an
 143.689 -     * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
 143.690 -     * java.net.URL <tt>URL</tt>} objects.
 143.691 -     *
 143.692 -     * <p> The search order is described in the documentation for {@link
 143.693 -     * #getSystemResource(String)}.  </p>
 143.694 -     *
 143.695 -     * @param  name
 143.696 -     *         The resource name
 143.697 -     *
 143.698 -     * @return  An enumeration of resource {@link java.net.URL <tt>URL</tt>}
 143.699 -     *          objects
 143.700 -     *
 143.701 -     * @throws  IOException
 143.702 -     *          If I/O errors occur
 143.703 -
 143.704 -     * @since  1.2
 143.705 -     */
 143.706 -    public static Enumeration<URL> getSystemResources(String name)
 143.707 -        throws IOException
 143.708 -    {
 143.709 -        ClassLoader system = null; // getSystemClassLoader();
 143.710 -        if (system == null) {
 143.711 -            return getBootstrapResources(name);
 143.712 -        }
 143.713 -        return system.getResources(name);
 143.714 -    }
 143.715 -
 143.716 -
 143.717 -
 143.718 -    /**
 143.719 -     * Returns an input stream for reading the specified resource.
 143.720 -     *
 143.721 -     * <p> The search order is described in the documentation for {@link
 143.722 -     * #getResource(String)}.  </p>
 143.723 -     *
 143.724 -     * @param  name
 143.725 -     *         The resource name
 143.726 -     *
 143.727 -     * @return  An input stream for reading the resource, or <tt>null</tt>
 143.728 -     *          if the resource could not be found
 143.729 -     *
 143.730 -     * @since  1.1
 143.731 -     */
 143.732 -    public InputStream getResourceAsStream(String name) {
 143.733 -        URL url = getResource(name);
 143.734 -        try {
 143.735 -            return url != null ? url.openStream() : null;
 143.736 -        } catch (IOException e) {
 143.737 -            return null;
 143.738 -        }
 143.739 -    }
 143.740 -
 143.741 -    /**
 143.742 -     * Open for reading, a resource of the specified name from the search path
 143.743 -     * used to load classes.  This method locates the resource through the
 143.744 -     * system class loader (see {@link #getSystemClassLoader()}).  </p>
 143.745 -     *
 143.746 -     * @param  name
 143.747 -     *         The resource name
 143.748 -     *
 143.749 -     * @return  An input stream for reading the resource, or <tt>null</tt>
 143.750 -     *          if the resource could not be found
 143.751 -     *
 143.752 -     * @since  1.1
 143.753 -     */
 143.754 -    public static InputStream getSystemResourceAsStream(String name) {
 143.755 -        URL url = getSystemResource(name);
 143.756 -        try {
 143.757 -            return url != null ? url.openStream() : null;
 143.758 -        } catch (IOException e) {
 143.759 -            return null;
 143.760 -        }
 143.761 -    }
 143.762 -
 143.763 -
 143.764 -    // -- Hierarchy --
 143.765 -
 143.766 -    /**
 143.767 -     * Returns the parent class loader for delegation. Some implementations may
 143.768 -     * use <tt>null</tt> to represent the bootstrap class loader. This method
 143.769 -     * will return <tt>null</tt> in such implementations if this class loader's
 143.770 -     * parent is the bootstrap class loader.
 143.771 -     *
 143.772 -     * <p> If a security manager is present, and the invoker's class loader is
 143.773 -     * not <tt>null</tt> and is not an ancestor of this class loader, then this
 143.774 -     * method invokes the security manager's {@link
 143.775 -     * SecurityManager#checkPermission(java.security.Permission)
 143.776 -     * <tt>checkPermission</tt>} method with a {@link
 143.777 -     * RuntimePermission#RuntimePermission(String)
 143.778 -     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 143.779 -     * access to the parent class loader is permitted.  If not, a
 143.780 -     * <tt>SecurityException</tt> will be thrown.  </p>
 143.781 -     *
 143.782 -     * @return  The parent <tt>ClassLoader</tt>
 143.783 -     *
 143.784 -     * @throws  SecurityException
 143.785 -     *          If a security manager exists and its <tt>checkPermission</tt>
 143.786 -     *          method doesn't allow access to this class loader's parent class
 143.787 -     *          loader.
 143.788 -     *
 143.789 -     * @since  1.2
 143.790 -     */
 143.791 -    public final ClassLoader getParent() {
 143.792 -        throw new SecurityException();
 143.793 -    }
 143.794 -
 143.795 -    /**
 143.796 -     * Returns the system class loader for delegation.  This is the default
 143.797 -     * delegation parent for new <tt>ClassLoader</tt> instances, and is
 143.798 -     * typically the class loader used to start the application.
 143.799 -     *
 143.800 -     * <p> This method is first invoked early in the runtime's startup
 143.801 -     * sequence, at which point it creates the system class loader and sets it
 143.802 -     * as the context class loader of the invoking <tt>Thread</tt>.
 143.803 -     *
 143.804 -     * <p> The default system class loader is an implementation-dependent
 143.805 -     * instance of this class.
 143.806 -     *
 143.807 -     * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
 143.808 -     * when this method is first invoked then the value of that property is
 143.809 -     * taken to be the name of a class that will be returned as the system
 143.810 -     * class loader.  The class is loaded using the default system class loader
 143.811 -     * and must define a public constructor that takes a single parameter of
 143.812 -     * type <tt>ClassLoader</tt> which is used as the delegation parent.  An
 143.813 -     * instance is then created using this constructor with the default system
 143.814 -     * class loader as the parameter.  The resulting class loader is defined
 143.815 -     * to be the system class loader.
 143.816 -     *
 143.817 -     * <p> If a security manager is present, and the invoker's class loader is
 143.818 -     * not <tt>null</tt> and the invoker's class loader is not the same as or
 143.819 -     * an ancestor of the system class loader, then this method invokes the
 143.820 -     * security manager's {@link
 143.821 -     * SecurityManager#checkPermission(java.security.Permission)
 143.822 -     * <tt>checkPermission</tt>} method with a {@link
 143.823 -     * RuntimePermission#RuntimePermission(String)
 143.824 -     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 143.825 -     * access to the system class loader.  If not, a
 143.826 -     * <tt>SecurityException</tt> will be thrown.  </p>
 143.827 -     *
 143.828 -     * @return  The system <tt>ClassLoader</tt> for delegation, or
 143.829 -     *          <tt>null</tt> if none
 143.830 -     *
 143.831 -     * @throws  SecurityException
 143.832 -     *          If a security manager exists and its <tt>checkPermission</tt>
 143.833 -     *          method doesn't allow access to the system class loader.
 143.834 -     *
 143.835 -     * @throws  IllegalStateException
 143.836 -     *          If invoked recursively during the construction of the class
 143.837 -     *          loader specified by the "<tt>java.system.class.loader</tt>"
 143.838 -     *          property.
 143.839 -     *
 143.840 -     * @throws  Error
 143.841 -     *          If the system property "<tt>java.system.class.loader</tt>"
 143.842 -     *          is defined but the named class could not be loaded, the
 143.843 -     *          provider class does not define the required constructor, or an
 143.844 -     *          exception is thrown by that constructor when it is invoked. The
 143.845 -     *          underlying cause of the error can be retrieved via the
 143.846 -     *          {@link Throwable#getCause()} method.
 143.847 -     *
 143.848 -     * @revised  1.4
 143.849 -     */
 143.850 -    public static ClassLoader getSystemClassLoader() {
 143.851 -        throw new SecurityException();
 143.852 -    }
 143.853 -
 143.854 -    // Returns true if the specified class loader can be found in this class
 143.855 -    // loader's delegation chain.
 143.856 -    boolean isAncestor(ClassLoader cl) {
 143.857 -        ClassLoader acl = this;
 143.858 -        do {
 143.859 -            acl = acl.parent;
 143.860 -            if (cl == acl) {
 143.861 -                return true;
 143.862 -            }
 143.863 -        } while (acl != null);
 143.864 -        return false;
 143.865 -    }
 143.866 -
 143.867 -    private boolean checkName(String name) {
 143.868 -        throw new UnsupportedOperationException(); 
 143.869 -    }
 143.870 -
 143.871 -    private Class findBootstrapClassOrNull(String name) {
 143.872 -        throw new UnsupportedOperationException();
 143.873 -    }
 143.874 -
 143.875 -    private static URL getBootstrapResource(String name) {
 143.876 -        throw new UnsupportedOperationException();
 143.877 -    }
 143.878 -
 143.879 -    private static Enumeration<URL> getBootstrapResources(String name) {
 143.880 -        URL u = Object.class.getResource("/" + name);
 143.881 -        return new OneOrZeroEnum(u);
 143.882 -    }
 143.883 -    
 143.884 -    private static class OneOrZeroEnum implements Enumeration<URL> {
 143.885 -        private URL u;
 143.886 -
 143.887 -        public OneOrZeroEnum(URL u) {
 143.888 -            this.u = u;
 143.889 -        }
 143.890 -
 143.891 -        public boolean hasMoreElements() {
 143.892 -            return u != null;
 143.893 -        }
 143.894 -
 143.895 -        public URL nextElement() {
 143.896 -            URL r = u;
 143.897 -            if (r == null) {
 143.898 -                throw new NoSuchElementException();
 143.899 -            }
 143.900 -            u = null;
 143.901 -            return r;
 143.902 -        }
 143.903 -    }
 143.904 -
 143.905 -    private static class CompoundEnumeration implements Enumeration<URL> {
 143.906 -        private URL next;
 143.907 -        private int index;
 143.908 -        private final Enumeration[] arr;
 143.909 -
 143.910 -        public CompoundEnumeration(Enumeration[] arr) {
 143.911 -            this.arr = arr;
 143.912 -            this.index = 0;
 143.913 -        }
 143.914 -
 143.915 -        public boolean hasMoreElements() {
 143.916 -            if (next == null) {
 143.917 -                if (arr[index].hasMoreElements()) {
 143.918 -                    next = (URL) arr[index].nextElement();
 143.919 -                } else {
 143.920 -                    if (index < arr.length) {
 143.921 -                        index++;
 143.922 -                        return hasMoreElements();
 143.923 -                    }
 143.924 -                }
 143.925 -            }
 143.926 -            return next != null;
 143.927 -        }
 143.928 -
 143.929 -        public URL nextElement() {
 143.930 -            if (!hasMoreElements()) {
 143.931 -                throw new NoSuchElementException();
 143.932 -            }
 143.933 -            URL r = next;
 143.934 -            next = null;
 143.935 -            return r;
 143.936 -        }
 143.937 -        
 143.938 -    }
 143.939 -}
   144.1 --- a/emul/mini/src/main/java/java/lang/ClassNotFoundException.java	Mon Feb 25 19:00:08 2013 +0100
   144.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   144.3 @@ -1,125 +0,0 @@
   144.4 -/*
   144.5 - * Copyright (c) 1995, 2004, 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 - * Thrown when an application tries to load in a class through its
  144.33 - * string name using:
  144.34 - * <ul>
  144.35 - * <li>The <code>forName</code> method in class <code>Class</code>.
  144.36 - * <li>The <code>findSystemClass</code> method in class
  144.37 - *     <code>ClassLoader</code> .
  144.38 - * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
  144.39 - * </ul>
  144.40 - * <p>
  144.41 - * but no definition for the class with the specified name could be found.
  144.42 - *
  144.43 - * <p>As of release 1.4, this exception has been retrofitted to conform to
  144.44 - * the general purpose exception-chaining mechanism.  The "optional exception
  144.45 - * that was raised while loading the class" that may be provided at
  144.46 - * construction time and accessed via the {@link #getException()} method is
  144.47 - * now known as the <i>cause</i>, and may be accessed via the {@link
  144.48 - * Throwable#getCause()} method, as well as the aforementioned "legacy method."
  144.49 - *
  144.50 - * @author  unascribed
  144.51 - * @see     java.lang.Class#forName(java.lang.String)
  144.52 - * @see     java.lang.ClassLoader#findSystemClass(java.lang.String)
  144.53 - * @see     java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  144.54 - * @since   JDK1.0
  144.55 - */
  144.56 -public class ClassNotFoundException extends ReflectiveOperationException {
  144.57 -    /**
  144.58 -     * use serialVersionUID from JDK 1.1.X for interoperability
  144.59 -     */
  144.60 -     private static final long serialVersionUID = 9176873029745254542L;
  144.61 -
  144.62 -    /**
  144.63 -     * This field holds the exception ex if the
  144.64 -     * ClassNotFoundException(String s, Throwable ex) constructor was
  144.65 -     * used to instantiate the object
  144.66 -     * @serial
  144.67 -     * @since 1.2
  144.68 -     */
  144.69 -    private Throwable ex;
  144.70 -
  144.71 -    /**
  144.72 -     * Constructs a <code>ClassNotFoundException</code> with no detail message.
  144.73 -     */
  144.74 -    public ClassNotFoundException() {
  144.75 -        super((Throwable)null);  // Disallow initCause
  144.76 -    }
  144.77 -
  144.78 -    /**
  144.79 -     * Constructs a <code>ClassNotFoundException</code> with the
  144.80 -     * specified detail message.
  144.81 -     *
  144.82 -     * @param   s   the detail message.
  144.83 -     */
  144.84 -    public ClassNotFoundException(String s) {
  144.85 -        super(s, null);  //  Disallow initCause
  144.86 -    }
  144.87 -
  144.88 -    /**
  144.89 -     * Constructs a <code>ClassNotFoundException</code> with the
  144.90 -     * specified detail message and optional exception that was
  144.91 -     * raised while loading the class.
  144.92 -     *
  144.93 -     * @param s the detail message
  144.94 -     * @param ex the exception that was raised while loading the class
  144.95 -     * @since 1.2
  144.96 -     */
  144.97 -    public ClassNotFoundException(String s, Throwable ex) {
  144.98 -        super(s, null);  //  Disallow initCause
  144.99 -        this.ex = ex;
 144.100 -    }
 144.101 -
 144.102 -    /**
 144.103 -     * Returns the exception that was raised if an error occurred while
 144.104 -     * attempting to load the class. Otherwise, returns <tt>null</tt>.
 144.105 -     *
 144.106 -     * <p>This method predates the general-purpose exception chaining facility.
 144.107 -     * The {@link Throwable#getCause()} method is now the preferred means of
 144.108 -     * obtaining this information.
 144.109 -     *
 144.110 -     * @return the <code>Exception</code> that was raised while loading a class
 144.111 -     * @since 1.2
 144.112 -     */
 144.113 -    public Throwable getException() {
 144.114 -        return ex;
 144.115 -    }
 144.116 -
 144.117 -    /**
 144.118 -     * Returns the cause of this exception (the exception that was raised
 144.119 -     * if an error occurred while attempting to load the class; otherwise
 144.120 -     * <tt>null</tt>).
 144.121 -     *
 144.122 -     * @return  the cause of this exception.
 144.123 -     * @since   1.4
 144.124 -     */
 144.125 -    public Throwable getCause() {
 144.126 -        return ex;
 144.127 -    }
 144.128 -}
   145.1 --- a/emul/mini/src/main/java/java/lang/CloneNotSupportedException.java	Mon Feb 25 19:00:08 2013 +0100
   145.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   145.3 @@ -1,65 +0,0 @@
   145.4 -/*
   145.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   145.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   145.7 - *
   145.8 - * This code is free software; you can redistribute it and/or modify it
   145.9 - * under the terms of the GNU General Public License version 2 only, as
  145.10 - * published by the Free Software Foundation.  Oracle designates this
  145.11 - * particular file as subject to the "Classpath" exception as provided
  145.12 - * by Oracle in the LICENSE file that accompanied this code.
  145.13 - *
  145.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  145.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  145.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  145.17 - * version 2 for more details (a copy is included in the LICENSE file that
  145.18 - * accompanied this code).
  145.19 - *
  145.20 - * You should have received a copy of the GNU General Public License version
  145.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  145.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  145.23 - *
  145.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  145.25 - * or visit www.oracle.com if you need additional information or have any
  145.26 - * questions.
  145.27 - */
  145.28 -
  145.29 -package java.lang;
  145.30 -
  145.31 -/**
  145.32 - * Thrown to indicate that the <code>clone</code> method in class
  145.33 - * <code>Object</code> has been called to clone an object, but that
  145.34 - * the object's class does not implement the <code>Cloneable</code>
  145.35 - * interface.
  145.36 - * <p>
  145.37 - * Applications that override the <code>clone</code> method can also
  145.38 - * throw this exception to indicate that an object could not or
  145.39 - * should not be cloned.
  145.40 - *
  145.41 - * @author  unascribed
  145.42 - * @see     java.lang.Cloneable
  145.43 - * @see     java.lang.Object#clone()
  145.44 - * @since   JDK1.0
  145.45 - */
  145.46 -
  145.47 -public
  145.48 -class CloneNotSupportedException extends Exception {
  145.49 -    private static final long serialVersionUID = 5195511250079656443L;
  145.50 -
  145.51 -    /**
  145.52 -     * Constructs a <code>CloneNotSupportedException</code> with no
  145.53 -     * detail message.
  145.54 -     */
  145.55 -    public CloneNotSupportedException() {
  145.56 -        super();
  145.57 -    }
  145.58 -
  145.59 -    /**
  145.60 -     * Constructs a <code>CloneNotSupportedException</code> with the
  145.61 -     * specified detail message.
  145.62 -     *
  145.63 -     * @param   s   the detail message.
  145.64 -     */
  145.65 -    public CloneNotSupportedException(String s) {
  145.66 -        super(s);
  145.67 -    }
  145.68 -}
   146.1 --- a/emul/mini/src/main/java/java/lang/Cloneable.java	Mon Feb 25 19:00:08 2013 +0100
   146.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.3 @@ -1,54 +0,0 @@
   146.4 -/*
   146.5 - * Copyright (c) 1995, 2004, 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 - * A class implements the <code>Cloneable</code> interface to
  146.33 - * indicate to the {@link java.lang.Object#clone()} method that it
  146.34 - * is legal for that method to make a
  146.35 - * field-for-field copy of instances of that class.
  146.36 - * <p>
  146.37 - * Invoking Object's clone method on an instance that does not implement the
  146.38 - * <code>Cloneable</code> interface results in the exception
  146.39 - * <code>CloneNotSupportedException</code> being thrown.
  146.40 - * <p>
  146.41 - * By convention, classes that implement this interface should override
  146.42 - * <tt>Object.clone</tt> (which is protected) with a public method.
  146.43 - * See {@link java.lang.Object#clone()} for details on overriding this
  146.44 - * method.
  146.45 - * <p>
  146.46 - * Note that this interface does <i>not</i> contain the <tt>clone</tt> method.
  146.47 - * Therefore, it is not possible to clone an object merely by virtue of the
  146.48 - * fact that it implements this interface.  Even if the clone method is invoked
  146.49 - * reflectively, there is no guarantee that it will succeed.
  146.50 - *
  146.51 - * @author  unascribed
  146.52 - * @see     java.lang.CloneNotSupportedException
  146.53 - * @see     java.lang.Object#clone()
  146.54 - * @since   JDK1.0
  146.55 - */
  146.56 -public interface Cloneable {
  146.57 -}
   147.1 --- a/emul/mini/src/main/java/java/lang/Comparable.java	Mon Feb 25 19:00:08 2013 +0100
   147.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   147.3 @@ -1,137 +0,0 @@
   147.4 -/*
   147.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
   147.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   147.7 - *
   147.8 - * This code is free software; you can redistribute it and/or modify it
   147.9 - * under the terms of the GNU General Public License version 2 only, as
  147.10 - * published by the Free Software Foundation.  Oracle designates this
  147.11 - * particular file as subject to the "Classpath" exception as provided
  147.12 - * by Oracle in the LICENSE file that accompanied this code.
  147.13 - *
  147.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  147.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  147.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  147.17 - * version 2 for more details (a copy is included in the LICENSE file that
  147.18 - * accompanied this code).
  147.19 - *
  147.20 - * You should have received a copy of the GNU General Public License version
  147.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  147.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  147.23 - *
  147.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  147.25 - * or visit www.oracle.com if you need additional information or have any
  147.26 - * questions.
  147.27 - */
  147.28 -
  147.29 -package java.lang;
  147.30 -
  147.31 -/**
  147.32 - * This interface imposes a total ordering on the objects of each class that
  147.33 - * implements it.  This ordering is referred to as the class's <i>natural
  147.34 - * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
  147.35 - * its <i>natural comparison method</i>.<p>
  147.36 - *
  147.37 - * Lists (and arrays) of objects that implement this interface can be sorted
  147.38 - * automatically by {@link Collections#sort(List) Collections.sort} (and
  147.39 - * {@link Arrays#sort(Object[]) Arrays.sort}).  Objects that implement this
  147.40 - * interface can be used as keys in a {@linkplain SortedMap sorted map} or as
  147.41 - * elements in a {@linkplain SortedSet sorted set}, without the need to
  147.42 - * specify a {@linkplain Comparator comparator}.<p>
  147.43 - *
  147.44 - * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
  147.45 - * with equals</i> if and only if <tt>e1.compareTo(e2) == 0</tt> has
  147.46 - * the same boolean value as <tt>e1.equals(e2)</tt> for every
  147.47 - * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>.  Note that <tt>null</tt>
  147.48 - * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
  147.49 - * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
  147.50 - * returns <tt>false</tt>.<p>
  147.51 - *
  147.52 - * It is strongly recommended (though not required) that natural orderings be
  147.53 - * consistent with equals.  This is so because sorted sets (and sorted maps)
  147.54 - * without explicit comparators behave "strangely" when they are used with
  147.55 - * elements (or keys) whose natural ordering is inconsistent with equals.  In
  147.56 - * particular, such a sorted set (or sorted map) violates the general contract
  147.57 - * for set (or map), which is defined in terms of the <tt>equals</tt>
  147.58 - * method.<p>
  147.59 - *
  147.60 - * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
  147.61 - * <tt>(!a.equals(b) && a.compareTo(b) == 0)</tt> to a sorted
  147.62 - * set that does not use an explicit comparator, the second <tt>add</tt>
  147.63 - * operation returns false (and the size of the sorted set does not increase)
  147.64 - * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
  147.65 - * perspective.<p>
  147.66 - *
  147.67 - * Virtually all Java core classes that implement <tt>Comparable</tt> have natural
  147.68 - * orderings that are consistent with equals.  One exception is
  147.69 - * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
  147.70 - * <tt>BigDecimal</tt> objects with equal values and different precisions
  147.71 - * (such as 4.0 and 4.00).<p>
  147.72 - *
  147.73 - * For the mathematically inclined, the <i>relation</i> that defines
  147.74 - * the natural ordering on a given class C is:<pre>
  147.75 - *       {(x, y) such that x.compareTo(y) &lt;= 0}.
  147.76 - * </pre> The <i>quotient</i> for this total order is: <pre>
  147.77 - *       {(x, y) such that x.compareTo(y) == 0}.
  147.78 - * </pre>
  147.79 - *
  147.80 - * It follows immediately from the contract for <tt>compareTo</tt> that the
  147.81 - * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
  147.82 - * natural ordering is a <i>total order</i> on <tt>C</tt>.  When we say that a
  147.83 - * class's natural ordering is <i>consistent with equals</i>, we mean that the
  147.84 - * quotient for the natural ordering is the equivalence relation defined by
  147.85 - * the class's {@link Object#equals(Object) equals(Object)} method:<pre>
  147.86 - *     {(x, y) such that x.equals(y)}. </pre><p>
  147.87 - *
  147.88 - * This interface is a member of the
  147.89 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  147.90 - * Java Collections Framework</a>.
  147.91 - *
  147.92 - * @param <T> the type of objects that this object may be compared to
  147.93 - *
  147.94 - * @author  Josh Bloch
  147.95 - * @see java.util.Comparator
  147.96 - * @since 1.2
  147.97 - */
  147.98 -
  147.99 -public interface Comparable<T> {
 147.100 -    /**
 147.101 -     * Compares this object with the specified object for order.  Returns a
 147.102 -     * negative integer, zero, or a positive integer as this object is less
 147.103 -     * than, equal to, or greater than the specified object.
 147.104 -     *
 147.105 -     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
 147.106 -     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 147.107 -     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
 147.108 -     * <tt>y.compareTo(x)</tt> throws an exception.)
 147.109 -     *
 147.110 -     * <p>The implementor must also ensure that the relation is transitive:
 147.111 -     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
 147.112 -     * <tt>x.compareTo(z)&gt;0</tt>.
 147.113 -     *
 147.114 -     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
 147.115 -     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
 147.116 -     * all <tt>z</tt>.
 147.117 -     *
 147.118 -     * <p>It is strongly recommended, but <i>not</i> strictly required that
 147.119 -     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
 147.120 -     * class that implements the <tt>Comparable</tt> interface and violates
 147.121 -     * this condition should clearly indicate this fact.  The recommended
 147.122 -     * language is "Note: this class has a natural ordering that is
 147.123 -     * inconsistent with equals."
 147.124 -     *
 147.125 -     * <p>In the foregoing description, the notation
 147.126 -     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 147.127 -     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 147.128 -     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 147.129 -     * <i>expression</i> is negative, zero or positive.
 147.130 -     *
 147.131 -     * @param   o the object to be compared.
 147.132 -     * @return  a negative integer, zero, or a positive integer as this object
 147.133 -     *          is less than, equal to, or greater than the specified object.
 147.134 -     *
 147.135 -     * @throws NullPointerException if the specified object is null
 147.136 -     * @throws ClassCastException if the specified object's type prevents it
 147.137 -     *         from being compared to this object.
 147.138 -     */
 147.139 -    public int compareTo(T o);
 147.140 -}
   148.1 --- a/emul/mini/src/main/java/java/lang/Deprecated.java	Mon Feb 25 19:00:08 2013 +0100
   148.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.3 @@ -1,44 +0,0 @@
   148.4 -/*
   148.5 - * Copyright (c) 2003, 2010, 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 -import java.lang.annotation.*;
  148.32 -import static java.lang.annotation.ElementType.*;
  148.33 -
  148.34 -/**
  148.35 - * A program element annotated &#64;Deprecated is one that programmers
  148.36 - * are discouraged from using, typically because it is dangerous,
  148.37 - * or because a better alternative exists.  Compilers warn when a
  148.38 - * deprecated program element is used or overridden in non-deprecated code.
  148.39 - *
  148.40 - * @author  Neal Gafter
  148.41 - * @since 1.5
  148.42 - */
  148.43 -@Documented
  148.44 -@Retention(RetentionPolicy.RUNTIME)
  148.45 -@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
  148.46 -public @interface Deprecated {
  148.47 -}
   149.1 --- a/emul/mini/src/main/java/java/lang/Double.java	Mon Feb 25 19:00:08 2013 +0100
   149.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   149.3 @@ -1,994 +0,0 @@
   149.4 -/*
   149.5 - * Copyright (c) 1994, 2010, 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 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  149.32 -
  149.33 -/**
  149.34 - * The {@code Double} class wraps a value of the primitive type
  149.35 - * {@code double} in an object. An object of type
  149.36 - * {@code Double} contains a single field whose type is
  149.37 - * {@code double}.
  149.38 - *
  149.39 - * <p>In addition, this class provides several methods for converting a
  149.40 - * {@code double} to a {@code String} and a
  149.41 - * {@code String} to a {@code double}, as well as other
  149.42 - * constants and methods useful when dealing with a
  149.43 - * {@code double}.
  149.44 - *
  149.45 - * @author  Lee Boynton
  149.46 - * @author  Arthur van Hoff
  149.47 - * @author  Joseph D. Darcy
  149.48 - * @since JDK1.0
  149.49 - */
  149.50 -public final class Double extends Number implements Comparable<Double> {
  149.51 -    /**
  149.52 -     * A constant holding the positive infinity of type
  149.53 -     * {@code double}. It is equal to the value returned by
  149.54 -     * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  149.55 -     */
  149.56 -    public static final double POSITIVE_INFINITY = 1.0 / 0.0;
  149.57 -
  149.58 -    /**
  149.59 -     * A constant holding the negative infinity of type
  149.60 -     * {@code double}. It is equal to the value returned by
  149.61 -     * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  149.62 -     */
  149.63 -    public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
  149.64 -
  149.65 -    /**
  149.66 -     * A constant holding a Not-a-Number (NaN) value of type
  149.67 -     * {@code double}. It is equivalent to the value returned by
  149.68 -     * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  149.69 -     */
  149.70 -    public static final double NaN = 0.0d / 0.0;
  149.71 -
  149.72 -    /**
  149.73 -     * A constant holding the largest positive finite value of type
  149.74 -     * {@code double},
  149.75 -     * (2-2<sup>-52</sup>)&middot;2<sup>1023</sup>.  It is equal to
  149.76 -     * the hexadecimal floating-point literal
  149.77 -     * {@code 0x1.fffffffffffffP+1023} and also equal to
  149.78 -     * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
  149.79 -     */
  149.80 -    public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
  149.81 -
  149.82 -    /**
  149.83 -     * A constant holding the smallest positive normal value of type
  149.84 -     * {@code double}, 2<sup>-1022</sup>.  It is equal to the
  149.85 -     * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
  149.86 -     * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
  149.87 -     *
  149.88 -     * @since 1.6
  149.89 -     */
  149.90 -    public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
  149.91 -
  149.92 -    /**
  149.93 -     * A constant holding the smallest positive nonzero value of type
  149.94 -     * {@code double}, 2<sup>-1074</sup>. It is equal to the
  149.95 -     * hexadecimal floating-point literal
  149.96 -     * {@code 0x0.0000000000001P-1022} and also equal to
  149.97 -     * {@code Double.longBitsToDouble(0x1L)}.
  149.98 -     */
  149.99 -    public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
 149.100 -
 149.101 -    /**
 149.102 -     * Maximum exponent a finite {@code double} variable may have.
 149.103 -     * It is equal to the value returned by
 149.104 -     * {@code Math.getExponent(Double.MAX_VALUE)}.
 149.105 -     *
 149.106 -     * @since 1.6
 149.107 -     */
 149.108 -    public static final int MAX_EXPONENT = 1023;
 149.109 -
 149.110 -    /**
 149.111 -     * Minimum exponent a normalized {@code double} variable may
 149.112 -     * have.  It is equal to the value returned by
 149.113 -     * {@code Math.getExponent(Double.MIN_NORMAL)}.
 149.114 -     *
 149.115 -     * @since 1.6
 149.116 -     */
 149.117 -    public static final int MIN_EXPONENT = -1022;
 149.118 -
 149.119 -    /**
 149.120 -     * The number of bits used to represent a {@code double} value.
 149.121 -     *
 149.122 -     * @since 1.5
 149.123 -     */
 149.124 -    public static final int SIZE = 64;
 149.125 -
 149.126 -    /**
 149.127 -     * The {@code Class} instance representing the primitive type
 149.128 -     * {@code double}.
 149.129 -     *
 149.130 -     * @since JDK1.1
 149.131 -     */
 149.132 -    public static final Class<Double>   TYPE = (Class<Double>) Class.getPrimitiveClass("double");
 149.133 -
 149.134 -    /**
 149.135 -     * Returns a string representation of the {@code double}
 149.136 -     * argument. All characters mentioned below are ASCII characters.
 149.137 -     * <ul>
 149.138 -     * <li>If the argument is NaN, the result is the string
 149.139 -     *     "{@code NaN}".
 149.140 -     * <li>Otherwise, the result is a string that represents the sign and
 149.141 -     * magnitude (absolute value) of the argument. If the sign is negative,
 149.142 -     * the first character of the result is '{@code -}'
 149.143 -     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 149.144 -     * appears in the result. As for the magnitude <i>m</i>:
 149.145 -     * <ul>
 149.146 -     * <li>If <i>m</i> is infinity, it is represented by the characters
 149.147 -     * {@code "Infinity"}; thus, positive infinity produces the result
 149.148 -     * {@code "Infinity"} and negative infinity produces the result
 149.149 -     * {@code "-Infinity"}.
 149.150 -     *
 149.151 -     * <li>If <i>m</i> is zero, it is represented by the characters
 149.152 -     * {@code "0.0"}; thus, negative zero produces the result
 149.153 -     * {@code "-0.0"} and positive zero produces the result
 149.154 -     * {@code "0.0"}.
 149.155 -     *
 149.156 -     * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
 149.157 -     * than 10<sup>7</sup>, then it is represented as the integer part of
 149.158 -     * <i>m</i>, in decimal form with no leading zeroes, followed by
 149.159 -     * '{@code .}' (<code>'&#92;u002E'</code>), followed by one or
 149.160 -     * more decimal digits representing the fractional part of <i>m</i>.
 149.161 -     *
 149.162 -     * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 149.163 -     * equal to 10<sup>7</sup>, then it is represented in so-called
 149.164 -     * "computerized scientific notation." Let <i>n</i> be the unique
 149.165 -     * integer such that 10<sup><i>n</i></sup> &le; <i>m</i> {@literal <}
 149.166 -     * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
 149.167 -     * mathematically exact quotient of <i>m</i> and
 149.168 -     * 10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10. The
 149.169 -     * magnitude is then represented as the integer part of <i>a</i>,
 149.170 -     * as a single decimal digit, followed by '{@code .}'
 149.171 -     * (<code>'&#92;u002E'</code>), followed by decimal digits
 149.172 -     * representing the fractional part of <i>a</i>, followed by the
 149.173 -     * letter '{@code E}' (<code>'&#92;u0045'</code>), followed
 149.174 -     * by a representation of <i>n</i> as a decimal integer, as
 149.175 -     * produced by the method {@link Integer#toString(int)}.
 149.176 -     * </ul>
 149.177 -     * </ul>
 149.178 -     * How many digits must be printed for the fractional part of
 149.179 -     * <i>m</i> or <i>a</i>? There must be at least one digit to represent
 149.180 -     * the fractional part, and beyond that as many, but only as many, more
 149.181 -     * digits as are needed to uniquely distinguish the argument value from
 149.182 -     * adjacent values of type {@code double}. That is, suppose that
 149.183 -     * <i>x</i> is the exact mathematical value represented by the decimal
 149.184 -     * representation produced by this method for a finite nonzero argument
 149.185 -     * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
 149.186 -     * to <i>x</i>; or if two {@code double} values are equally close
 149.187 -     * to <i>x</i>, then <i>d</i> must be one of them and the least
 149.188 -     * significant bit of the significand of <i>d</i> must be {@code 0}.
 149.189 -     *
 149.190 -     * <p>To create localized string representations of a floating-point
 149.191 -     * value, use subclasses of {@link java.text.NumberFormat}.
 149.192 -     *
 149.193 -     * @param   d   the {@code double} to be converted.
 149.194 -     * @return a string representation of the argument.
 149.195 -     */
 149.196 -    @JavaScriptBody(args="d", body="var r = d.toString();"
 149.197 -        + "if (isFinite(d) && (r.indexOf('.') === -1)) r = r + '.0';"
 149.198 -        + "return r;")
 149.199 -    public static String toString(double d) {
 149.200 -        throw new UnsupportedOperationException();
 149.201 -    }
 149.202 -
 149.203 -    /**
 149.204 -     * Returns a hexadecimal string representation of the
 149.205 -     * {@code double} argument. All characters mentioned below
 149.206 -     * are ASCII characters.
 149.207 -     *
 149.208 -     * <ul>
 149.209 -     * <li>If the argument is NaN, the result is the string
 149.210 -     *     "{@code NaN}".
 149.211 -     * <li>Otherwise, the result is a string that represents the sign
 149.212 -     * and magnitude of the argument. If the sign is negative, the
 149.213 -     * first character of the result is '{@code -}'
 149.214 -     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign
 149.215 -     * character appears in the result. As for the magnitude <i>m</i>:
 149.216 -     *
 149.217 -     * <ul>
 149.218 -     * <li>If <i>m</i> is infinity, it is represented by the string
 149.219 -     * {@code "Infinity"}; thus, positive infinity produces the
 149.220 -     * result {@code "Infinity"} and negative infinity produces
 149.221 -     * the result {@code "-Infinity"}.
 149.222 -     *
 149.223 -     * <li>If <i>m</i> is zero, it is represented by the string
 149.224 -     * {@code "0x0.0p0"}; thus, negative zero produces the result
 149.225 -     * {@code "-0x0.0p0"} and positive zero produces the result
 149.226 -     * {@code "0x0.0p0"}.
 149.227 -     *
 149.228 -     * <li>If <i>m</i> is a {@code double} value with a
 149.229 -     * normalized representation, substrings are used to represent the
 149.230 -     * significand and exponent fields.  The significand is
 149.231 -     * represented by the characters {@code "0x1."}
 149.232 -     * followed by a lowercase hexadecimal representation of the rest
 149.233 -     * of the significand as a fraction.  Trailing zeros in the
 149.234 -     * hexadecimal representation are removed unless all the digits
 149.235 -     * are zero, in which case a single zero is used. Next, the
 149.236 -     * exponent is represented by {@code "p"} followed
 149.237 -     * by a decimal string of the unbiased exponent as if produced by
 149.238 -     * a call to {@link Integer#toString(int) Integer.toString} on the
 149.239 -     * exponent value.
 149.240 -     *
 149.241 -     * <li>If <i>m</i> is a {@code double} value with a subnormal
 149.242 -     * representation, the significand is represented by the
 149.243 -     * characters {@code "0x0."} followed by a
 149.244 -     * hexadecimal representation of the rest of the significand as a
 149.245 -     * fraction.  Trailing zeros in the hexadecimal representation are
 149.246 -     * removed. Next, the exponent is represented by
 149.247 -     * {@code "p-1022"}.  Note that there must be at
 149.248 -     * least one nonzero digit in a subnormal significand.
 149.249 -     *
 149.250 -     * </ul>
 149.251 -     *
 149.252 -     * </ul>
 149.253 -     *
 149.254 -     * <table border>
 149.255 -     * <caption><h3>Examples</h3></caption>
 149.256 -     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 149.257 -     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 149.258 -     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 149.259 -     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 149.260 -     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 149.261 -     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 149.262 -     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 149.263 -     * <tr><td>{@code Double.MAX_VALUE}</td>
 149.264 -     *     <td>{@code 0x1.fffffffffffffp1023}</td>
 149.265 -     * <tr><td>{@code Minimum Normal Value}</td>
 149.266 -     *     <td>{@code 0x1.0p-1022}</td>
 149.267 -     * <tr><td>{@code Maximum Subnormal Value}</td>
 149.268 -     *     <td>{@code 0x0.fffffffffffffp-1022}</td>
 149.269 -     * <tr><td>{@code Double.MIN_VALUE}</td>
 149.270 -     *     <td>{@code 0x0.0000000000001p-1022}</td>
 149.271 -     * </table>
 149.272 -     * @param   d   the {@code double} to be converted.
 149.273 -     * @return a hex string representation of the argument.
 149.274 -     * @since 1.5
 149.275 -     * @author Joseph D. Darcy
 149.276 -     */
 149.277 -    public static String toHexString(double d) {
 149.278 -        throw new UnsupportedOperationException();
 149.279 -//        /*
 149.280 -//         * Modeled after the "a" conversion specifier in C99, section
 149.281 -//         * 7.19.6.1; however, the output of this method is more
 149.282 -//         * tightly specified.
 149.283 -//         */
 149.284 -//        if (!FpUtils.isFinite(d) )
 149.285 -//            // For infinity and NaN, use the decimal output.
 149.286 -//            return Double.toString(d);
 149.287 -//        else {
 149.288 -//            // Initialized to maximum size of output.
 149.289 -//            StringBuffer answer = new StringBuffer(24);
 149.290 -//
 149.291 -//            if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
 149.292 -//                answer.append("-");                  // so append sign info
 149.293 -//
 149.294 -//            answer.append("0x");
 149.295 -//
 149.296 -//            d = Math.abs(d);
 149.297 -//
 149.298 -//            if(d == 0.0) {
 149.299 -//                answer.append("0.0p0");
 149.300 -//            }
 149.301 -//            else {
 149.302 -//                boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
 149.303 -//
 149.304 -//                // Isolate significand bits and OR in a high-order bit
 149.305 -//                // so that the string representation has a known
 149.306 -//                // length.
 149.307 -//                long signifBits = (Double.doubleToLongBits(d)
 149.308 -//                                   & DoubleConsts.SIGNIF_BIT_MASK) |
 149.309 -//                    0x1000000000000000L;
 149.310 -//
 149.311 -//                // Subnormal values have a 0 implicit bit; normal
 149.312 -//                // values have a 1 implicit bit.
 149.313 -//                answer.append(subnormal ? "0." : "1.");
 149.314 -//
 149.315 -//                // Isolate the low-order 13 digits of the hex
 149.316 -//                // representation.  If all the digits are zero,
 149.317 -//                // replace with a single 0; otherwise, remove all
 149.318 -//                // trailing zeros.
 149.319 -//                String signif = Long.toHexString(signifBits).substring(3,16);
 149.320 -//                answer.append(signif.equals("0000000000000") ? // 13 zeros
 149.321 -//                              "0":
 149.322 -//                              signif.replaceFirst("0{1,12}$", ""));
 149.323 -//
 149.324 -//                // If the value is subnormal, use the E_min exponent
 149.325 -//                // value for double; otherwise, extract and report d's
 149.326 -//                // exponent (the representation of a subnormal uses
 149.327 -//                // E_min -1).
 149.328 -//                answer.append("p" + (subnormal ?
 149.329 -//                               DoubleConsts.MIN_EXPONENT:
 149.330 -//                               FpUtils.getExponent(d) ));
 149.331 -//            }
 149.332 -//            return answer.toString();
 149.333 -//        }
 149.334 -    }
 149.335 -
 149.336 -    /**
 149.337 -     * Returns a {@code Double} object holding the
 149.338 -     * {@code double} value represented by the argument string
 149.339 -     * {@code s}.
 149.340 -     *
 149.341 -     * <p>If {@code s} is {@code null}, then a
 149.342 -     * {@code NullPointerException} is thrown.
 149.343 -     *
 149.344 -     * <p>Leading and trailing whitespace characters in {@code s}
 149.345 -     * are ignored.  Whitespace is removed as if by the {@link
 149.346 -     * String#trim} method; that is, both ASCII space and control
 149.347 -     * characters are removed. The rest of {@code s} should
 149.348 -     * constitute a <i>FloatValue</i> as described by the lexical
 149.349 -     * syntax rules:
 149.350 -     *
 149.351 -     * <blockquote>
 149.352 -     * <dl>
 149.353 -     * <dt><i>FloatValue:</i>
 149.354 -     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 149.355 -     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 149.356 -     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 149.357 -     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 149.358 -     * <dd><i>SignedInteger</i>
 149.359 -     * </dl>
 149.360 -     *
 149.361 -     * <p>
 149.362 -     *
 149.363 -     * <dl>
 149.364 -     * <dt><i>HexFloatingPointLiteral</i>:
 149.365 -     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 149.366 -     * </dl>
 149.367 -     *
 149.368 -     * <p>
 149.369 -     *
 149.370 -     * <dl>
 149.371 -     * <dt><i>HexSignificand:</i>
 149.372 -     * <dd><i>HexNumeral</i>
 149.373 -     * <dd><i>HexNumeral</i> {@code .}
 149.374 -     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 149.375 -     *     </i>{@code .}<i> HexDigits</i>
 149.376 -     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 149.377 -     *     </i>{@code .} <i>HexDigits</i>
 149.378 -     * </dl>
 149.379 -     *
 149.380 -     * <p>
 149.381 -     *
 149.382 -     * <dl>
 149.383 -     * <dt><i>BinaryExponent:</i>
 149.384 -     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 149.385 -     * </dl>
 149.386 -     *
 149.387 -     * <p>
 149.388 -     *
 149.389 -     * <dl>
 149.390 -     * <dt><i>BinaryExponentIndicator:</i>
 149.391 -     * <dd>{@code p}
 149.392 -     * <dd>{@code P}
 149.393 -     * </dl>
 149.394 -     *
 149.395 -     * </blockquote>
 149.396 -     *
 149.397 -     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 149.398 -     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 149.399 -     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 149.400 -     * sections of
 149.401 -     * <cite>The Java&trade; Language Specification</cite>,
 149.402 -     * except that underscores are not accepted between digits.
 149.403 -     * If {@code s} does not have the form of
 149.404 -     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 149.405 -     * is thrown. Otherwise, {@code s} is regarded as
 149.406 -     * representing an exact decimal value in the usual
 149.407 -     * "computerized scientific notation" or as an exact
 149.408 -     * hexadecimal value; this exact numerical value is then
 149.409 -     * conceptually converted to an "infinitely precise"
 149.410 -     * binary value that is then rounded to type {@code double}
 149.411 -     * by the usual round-to-nearest rule of IEEE 754 floating-point
 149.412 -     * arithmetic, which includes preserving the sign of a zero
 149.413 -     * value.
 149.414 -     *
 149.415 -     * Note that the round-to-nearest rule also implies overflow and
 149.416 -     * underflow behaviour; if the exact value of {@code s} is large
 149.417 -     * enough in magnitude (greater than or equal to ({@link
 149.418 -     * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
 149.419 -     * rounding to {@code double} will result in an infinity and if the
 149.420 -     * exact value of {@code s} is small enough in magnitude (less
 149.421 -     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 149.422 -     * result in a zero.
 149.423 -     *
 149.424 -     * Finally, after rounding a {@code Double} object representing
 149.425 -     * this {@code double} value is returned.
 149.426 -     *
 149.427 -     * <p> To interpret localized string representations of a
 149.428 -     * floating-point value, use subclasses of {@link
 149.429 -     * java.text.NumberFormat}.
 149.430 -     *
 149.431 -     * <p>Note that trailing format specifiers, specifiers that
 149.432 -     * determine the type of a floating-point literal
 149.433 -     * ({@code 1.0f} is a {@code float} value;
 149.434 -     * {@code 1.0d} is a {@code double} value), do
 149.435 -     * <em>not</em> influence the results of this method.  In other
 149.436 -     * words, the numerical value of the input string is converted
 149.437 -     * directly to the target floating-point type.  The two-step
 149.438 -     * sequence of conversions, string to {@code float} followed
 149.439 -     * by {@code float} to {@code double}, is <em>not</em>
 149.440 -     * equivalent to converting a string directly to
 149.441 -     * {@code double}. For example, the {@code float}
 149.442 -     * literal {@code 0.1f} is equal to the {@code double}
 149.443 -     * value {@code 0.10000000149011612}; the {@code float}
 149.444 -     * literal {@code 0.1f} represents a different numerical
 149.445 -     * value than the {@code double} literal
 149.446 -     * {@code 0.1}. (The numerical value 0.1 cannot be exactly
 149.447 -     * represented in a binary floating-point number.)
 149.448 -     *
 149.449 -     * <p>To avoid calling this method on an invalid string and having
 149.450 -     * a {@code NumberFormatException} be thrown, the regular
 149.451 -     * expression below can be used to screen the input string:
 149.452 -     *
 149.453 -     * <code>
 149.454 -     * <pre>
 149.455 -     *  final String Digits     = "(\\p{Digit}+)";
 149.456 -     *  final String HexDigits  = "(\\p{XDigit}+)";
 149.457 -     *  // an exponent is 'e' or 'E' followed by an optionally
 149.458 -     *  // signed decimal integer.
 149.459 -     *  final String Exp        = "[eE][+-]?"+Digits;
 149.460 -     *  final String fpRegex    =
 149.461 -     *      ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
 149.462 -     *       "[+-]?(" + // Optional sign character
 149.463 -     *       "NaN|" +           // "NaN" string
 149.464 -     *       "Infinity|" +      // "Infinity" string
 149.465 -     *
 149.466 -     *       // A decimal floating-point string representing a finite positive
 149.467 -     *       // number without a leading sign has at most five basic pieces:
 149.468 -     *       // Digits . Digits ExponentPart FloatTypeSuffix
 149.469 -     *       //
 149.470 -     *       // Since this method allows integer-only strings as input
 149.471 -     *       // in addition to strings of floating-point literals, the
 149.472 -     *       // two sub-patterns below are simplifications of the grammar
 149.473 -     *       // productions from section 3.10.2 of
 149.474 -     *       // <cite>The Java&trade; Language Specification</cite>.
 149.475 -     *
 149.476 -     *       // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
 149.477 -     *       "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
 149.478 -     *
 149.479 -     *       // . Digits ExponentPart_opt FloatTypeSuffix_opt
 149.480 -     *       "(\\.("+Digits+")("+Exp+")?)|"+
 149.481 -     *
 149.482 -     *       // Hexadecimal strings
 149.483 -     *       "((" +
 149.484 -     *        // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
 149.485 -     *        "(0[xX]" + HexDigits + "(\\.)?)|" +
 149.486 -     *
 149.487 -     *        // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
 149.488 -     *        "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
 149.489 -     *
 149.490 -     *        ")[pP][+-]?" + Digits + "))" +
 149.491 -     *       "[fFdD]?))" +
 149.492 -     *       "[\\x00-\\x20]*");// Optional trailing "whitespace"
 149.493 -     *
 149.494 -     *  if (Pattern.matches(fpRegex, myString))
 149.495 -     *      Double.valueOf(myString); // Will not throw NumberFormatException
 149.496 -     *  else {
 149.497 -     *      // Perform suitable alternative action
 149.498 -     *  }
 149.499 -     * </pre>
 149.500 -     * </code>
 149.501 -     *
 149.502 -     * @param      s   the string to be parsed.
 149.503 -     * @return     a {@code Double} object holding the value
 149.504 -     *             represented by the {@code String} argument.
 149.505 -     * @throws     NumberFormatException  if the string does not contain a
 149.506 -     *             parsable number.
 149.507 -     */
 149.508 -    @JavaScriptBody(args="s", body="return parseFloat(s);")
 149.509 -    public static Double valueOf(String s) throws NumberFormatException {
 149.510 -        throw new UnsupportedOperationException();
 149.511 -//        return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
 149.512 -    }
 149.513 -
 149.514 -    /**
 149.515 -     * Returns a {@code Double} instance representing the specified
 149.516 -     * {@code double} value.
 149.517 -     * If a new {@code Double} instance is not required, this method
 149.518 -     * should generally be used in preference to the constructor
 149.519 -     * {@link #Double(double)}, as this method is likely to yield
 149.520 -     * significantly better space and time performance by caching
 149.521 -     * frequently requested values.
 149.522 -     *
 149.523 -     * @param  d a double value.
 149.524 -     * @return a {@code Double} instance representing {@code d}.
 149.525 -     * @since  1.5
 149.526 -     */
 149.527 -    public static Double valueOf(double d) {
 149.528 -        return new Double(d);
 149.529 -    }
 149.530 -
 149.531 -    /**
 149.532 -     * Returns a new {@code double} initialized to the value
 149.533 -     * represented by the specified {@code String}, as performed
 149.534 -     * by the {@code valueOf} method of class
 149.535 -     * {@code Double}.
 149.536 -     *
 149.537 -     * @param  s   the string to be parsed.
 149.538 -     * @return the {@code double} value represented by the string
 149.539 -     *         argument.
 149.540 -     * @throws NullPointerException  if the string is null
 149.541 -     * @throws NumberFormatException if the string does not contain
 149.542 -     *         a parsable {@code double}.
 149.543 -     * @see    java.lang.Double#valueOf(String)
 149.544 -     * @since 1.2
 149.545 -     */
 149.546 -    @JavaScriptBody(args="s", body="return parseFloat(s);")
 149.547 -    public static double parseDouble(String s) throws NumberFormatException {
 149.548 -        throw new UnsupportedOperationException();
 149.549 -//        return FloatingDecimal.readJavaFormatString(s).doubleValue();
 149.550 -    }
 149.551 -
 149.552 -    /**
 149.553 -     * Returns {@code true} if the specified number is a
 149.554 -     * Not-a-Number (NaN) value, {@code false} otherwise.
 149.555 -     *
 149.556 -     * @param   v   the value to be tested.
 149.557 -     * @return  {@code true} if the value of the argument is NaN;
 149.558 -     *          {@code false} otherwise.
 149.559 -     */
 149.560 -    static public boolean isNaN(double v) {
 149.561 -        return (v != v);
 149.562 -    }
 149.563 -
 149.564 -    /**
 149.565 -     * Returns {@code true} if the specified number is infinitely
 149.566 -     * large in magnitude, {@code false} otherwise.
 149.567 -     *
 149.568 -     * @param   v   the value to be tested.
 149.569 -     * @return  {@code true} if the value of the argument is positive
 149.570 -     *          infinity or negative infinity; {@code false} otherwise.
 149.571 -     */
 149.572 -    static public boolean isInfinite(double v) {
 149.573 -        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 149.574 -    }
 149.575 -
 149.576 -    /**
 149.577 -     * The value of the Double.
 149.578 -     *
 149.579 -     * @serial
 149.580 -     */
 149.581 -    private final double value;
 149.582 -
 149.583 -    /**
 149.584 -     * Constructs a newly allocated {@code Double} object that
 149.585 -     * represents the primitive {@code double} argument.
 149.586 -     *
 149.587 -     * @param   value   the value to be represented by the {@code Double}.
 149.588 -     */
 149.589 -    public Double(double value) {
 149.590 -        this.value = value;
 149.591 -    }
 149.592 -
 149.593 -    /**
 149.594 -     * Constructs a newly allocated {@code Double} object that
 149.595 -     * represents the floating-point value of type {@code double}
 149.596 -     * represented by the string. The string is converted to a
 149.597 -     * {@code double} value as if by the {@code valueOf} method.
 149.598 -     *
 149.599 -     * @param  s  a string to be converted to a {@code Double}.
 149.600 -     * @throws    NumberFormatException  if the string does not contain a
 149.601 -     *            parsable number.
 149.602 -     * @see       java.lang.Double#valueOf(java.lang.String)
 149.603 -     */
 149.604 -    public Double(String s) throws NumberFormatException {
 149.605 -        // REMIND: this is inefficient
 149.606 -        this(valueOf(s).doubleValue());
 149.607 -    }
 149.608 -
 149.609 -    /**
 149.610 -     * Returns {@code true} if this {@code Double} value is
 149.611 -     * a Not-a-Number (NaN), {@code false} otherwise.
 149.612 -     *
 149.613 -     * @return  {@code true} if the value represented by this object is
 149.614 -     *          NaN; {@code false} otherwise.
 149.615 -     */
 149.616 -    public boolean isNaN() {
 149.617 -        return isNaN(value);
 149.618 -    }
 149.619 -
 149.620 -    /**
 149.621 -     * Returns {@code true} if this {@code Double} value is
 149.622 -     * infinitely large in magnitude, {@code false} otherwise.
 149.623 -     *
 149.624 -     * @return  {@code true} if the value represented by this object is
 149.625 -     *          positive infinity or negative infinity;
 149.626 -     *          {@code false} otherwise.
 149.627 -     */
 149.628 -    public boolean isInfinite() {
 149.629 -        return isInfinite(value);
 149.630 -    }
 149.631 -
 149.632 -    /**
 149.633 -     * Returns a string representation of this {@code Double} object.
 149.634 -     * The primitive {@code double} value represented by this
 149.635 -     * object is converted to a string exactly as if by the method
 149.636 -     * {@code toString} of one argument.
 149.637 -     *
 149.638 -     * @return  a {@code String} representation of this object.
 149.639 -     * @see java.lang.Double#toString(double)
 149.640 -     */
 149.641 -    public String toString() {
 149.642 -        return toString(value);
 149.643 -    }
 149.644 -
 149.645 -    /**
 149.646 -     * Returns the value of this {@code Double} as a {@code byte} (by
 149.647 -     * casting to a {@code byte}).
 149.648 -     *
 149.649 -     * @return  the {@code double} value represented by this object
 149.650 -     *          converted to type {@code byte}
 149.651 -     * @since JDK1.1
 149.652 -     */
 149.653 -    public byte byteValue() {
 149.654 -        return (byte)value;
 149.655 -    }
 149.656 -
 149.657 -    /**
 149.658 -     * Returns the value of this {@code Double} as a
 149.659 -     * {@code short} (by casting to a {@code short}).
 149.660 -     *
 149.661 -     * @return  the {@code double} value represented by this object
 149.662 -     *          converted to type {@code short}
 149.663 -     * @since JDK1.1
 149.664 -     */
 149.665 -    public short shortValue() {
 149.666 -        return (short)value;
 149.667 -    }
 149.668 -
 149.669 -    /**
 149.670 -     * Returns the value of this {@code Double} as an
 149.671 -     * {@code int} (by casting to type {@code int}).
 149.672 -     *
 149.673 -     * @return  the {@code double} value represented by this object
 149.674 -     *          converted to type {@code int}
 149.675 -     */
 149.676 -    public int intValue() {
 149.677 -        return (int)value;
 149.678 -    }
 149.679 -
 149.680 -    /**
 149.681 -     * Returns the value of this {@code Double} as a
 149.682 -     * {@code long} (by casting to type {@code long}).
 149.683 -     *
 149.684 -     * @return  the {@code double} value represented by this object
 149.685 -     *          converted to type {@code long}
 149.686 -     */
 149.687 -    public long longValue() {
 149.688 -        return (long)value;
 149.689 -    }
 149.690 -
 149.691 -    /**
 149.692 -     * Returns the {@code float} value of this
 149.693 -     * {@code Double} object.
 149.694 -     *
 149.695 -     * @return  the {@code double} value represented by this object
 149.696 -     *          converted to type {@code float}
 149.697 -     * @since JDK1.0
 149.698 -     */
 149.699 -    public float floatValue() {
 149.700 -        return (float)value;
 149.701 -    }
 149.702 -
 149.703 -    /**
 149.704 -     * Returns the {@code double} value of this
 149.705 -     * {@code Double} object.
 149.706 -     *
 149.707 -     * @return the {@code double} value represented by this object
 149.708 -     */
 149.709 -    public double doubleValue() {
 149.710 -        return (double)value;
 149.711 -    }
 149.712 -
 149.713 -    /**
 149.714 -     * Returns a hash code for this {@code Double} object. The
 149.715 -     * result is the exclusive OR of the two halves of the
 149.716 -     * {@code long} integer bit representation, exactly as
 149.717 -     * produced by the method {@link #doubleToLongBits(double)}, of
 149.718 -     * the primitive {@code double} value represented by this
 149.719 -     * {@code Double} object. That is, the hash code is the value
 149.720 -     * of the expression:
 149.721 -     *
 149.722 -     * <blockquote>
 149.723 -     *  {@code (int)(v^(v>>>32))}
 149.724 -     * </blockquote>
 149.725 -     *
 149.726 -     * where {@code v} is defined by:
 149.727 -     *
 149.728 -     * <blockquote>
 149.729 -     *  {@code long v = Double.doubleToLongBits(this.doubleValue());}
 149.730 -     * </blockquote>
 149.731 -     *
 149.732 -     * @return  a {@code hash code} value for this object.
 149.733 -     */
 149.734 -    public int hashCode() {
 149.735 -        long bits = doubleToLongBits(value);
 149.736 -        return (int)(bits ^ (bits >>> 32));
 149.737 -    }
 149.738 -
 149.739 -    /**
 149.740 -     * Compares this object against the specified object.  The result
 149.741 -     * is {@code true} if and only if the argument is not
 149.742 -     * {@code null} and is a {@code Double} object that
 149.743 -     * represents a {@code double} that has the same value as the
 149.744 -     * {@code double} represented by this object. For this
 149.745 -     * purpose, two {@code double} values are considered to be
 149.746 -     * the same if and only if the method {@link
 149.747 -     * #doubleToLongBits(double)} returns the identical
 149.748 -     * {@code long} value when applied to each.
 149.749 -     *
 149.750 -     * <p>Note that in most cases, for two instances of class
 149.751 -     * {@code Double}, {@code d1} and {@code d2}, the
 149.752 -     * value of {@code d1.equals(d2)} is {@code true} if and
 149.753 -     * only if
 149.754 -     *
 149.755 -     * <blockquote>
 149.756 -     *  {@code d1.doubleValue() == d2.doubleValue()}
 149.757 -     * </blockquote>
 149.758 -     *
 149.759 -     * <p>also has the value {@code true}. However, there are two
 149.760 -     * exceptions:
 149.761 -     * <ul>
 149.762 -     * <li>If {@code d1} and {@code d2} both represent
 149.763 -     *     {@code Double.NaN}, then the {@code equals} method
 149.764 -     *     returns {@code true}, even though
 149.765 -     *     {@code Double.NaN==Double.NaN} has the value
 149.766 -     *     {@code false}.
 149.767 -     * <li>If {@code d1} represents {@code +0.0} while
 149.768 -     *     {@code d2} represents {@code -0.0}, or vice versa,
 149.769 -     *     the {@code equal} test has the value {@code false},
 149.770 -     *     even though {@code +0.0==-0.0} has the value {@code true}.
 149.771 -     * </ul>
 149.772 -     * This definition allows hash tables to operate properly.
 149.773 -     * @param   obj   the object to compare with.
 149.774 -     * @return  {@code true} if the objects are the same;
 149.775 -     *          {@code false} otherwise.
 149.776 -     * @see java.lang.Double#doubleToLongBits(double)
 149.777 -     */
 149.778 -    public boolean equals(Object obj) {
 149.779 -        return (obj instanceof Double)
 149.780 -               && (((Double)obj).value) == value;
 149.781 -    }
 149.782 -
 149.783 -    /**
 149.784 -     * Returns a representation of the specified floating-point value
 149.785 -     * according to the IEEE 754 floating-point "double
 149.786 -     * format" bit layout.
 149.787 -     *
 149.788 -     * <p>Bit 63 (the bit that is selected by the mask
 149.789 -     * {@code 0x8000000000000000L}) represents the sign of the
 149.790 -     * floating-point number. Bits
 149.791 -     * 62-52 (the bits that are selected by the mask
 149.792 -     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 149.793 -     * (the bits that are selected by the mask
 149.794 -     * {@code 0x000fffffffffffffL}) represent the significand
 149.795 -     * (sometimes called the mantissa) of the floating-point number.
 149.796 -     *
 149.797 -     * <p>If the argument is positive infinity, the result is
 149.798 -     * {@code 0x7ff0000000000000L}.
 149.799 -     *
 149.800 -     * <p>If the argument is negative infinity, the result is
 149.801 -     * {@code 0xfff0000000000000L}.
 149.802 -     *
 149.803 -     * <p>If the argument is NaN, the result is
 149.804 -     * {@code 0x7ff8000000000000L}.
 149.805 -     *
 149.806 -     * <p>In all cases, the result is a {@code long} integer that, when
 149.807 -     * given to the {@link #longBitsToDouble(long)} method, will produce a
 149.808 -     * floating-point value the same as the argument to
 149.809 -     * {@code doubleToLongBits} (except all NaN values are
 149.810 -     * collapsed to a single "canonical" NaN value).
 149.811 -     *
 149.812 -     * @param   value   a {@code double} precision floating-point number.
 149.813 -     * @return the bits that represent the floating-point number.
 149.814 -     */
 149.815 -    public static long doubleToLongBits(double value) {
 149.816 -        throw new UnsupportedOperationException();
 149.817 -//        long result = doubleToRawLongBits(value);
 149.818 -//        // Check for NaN based on values of bit fields, maximum
 149.819 -//        // exponent and nonzero significand.
 149.820 -//        if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
 149.821 -//              DoubleConsts.EXP_BIT_MASK) &&
 149.822 -//             (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
 149.823 -//            result = 0x7ff8000000000000L;
 149.824 -//        return result;
 149.825 -    }
 149.826 -
 149.827 -    /**
 149.828 -     * Returns a representation of the specified floating-point value
 149.829 -     * according to the IEEE 754 floating-point "double
 149.830 -     * format" bit layout, preserving Not-a-Number (NaN) values.
 149.831 -     *
 149.832 -     * <p>Bit 63 (the bit that is selected by the mask
 149.833 -     * {@code 0x8000000000000000L}) represents the sign of the
 149.834 -     * floating-point number. Bits
 149.835 -     * 62-52 (the bits that are selected by the mask
 149.836 -     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 149.837 -     * (the bits that are selected by the mask
 149.838 -     * {@code 0x000fffffffffffffL}) represent the significand
 149.839 -     * (sometimes called the mantissa) of the floating-point number.
 149.840 -     *
 149.841 -     * <p>If the argument is positive infinity, the result is
 149.842 -     * {@code 0x7ff0000000000000L}.
 149.843 -     *
 149.844 -     * <p>If the argument is negative infinity, the result is
 149.845 -     * {@code 0xfff0000000000000L}.
 149.846 -     *
 149.847 -     * <p>If the argument is NaN, the result is the {@code long}
 149.848 -     * integer representing the actual NaN value.  Unlike the
 149.849 -     * {@code doubleToLongBits} method,
 149.850 -     * {@code doubleToRawLongBits} does not collapse all the bit
 149.851 -     * patterns encoding a NaN to a single "canonical" NaN
 149.852 -     * value.
 149.853 -     *
 149.854 -     * <p>In all cases, the result is a {@code long} integer that,
 149.855 -     * when given to the {@link #longBitsToDouble(long)} method, will
 149.856 -     * produce a floating-point value the same as the argument to
 149.857 -     * {@code doubleToRawLongBits}.
 149.858 -     *
 149.859 -     * @param   value   a {@code double} precision floating-point number.
 149.860 -     * @return the bits that represent the floating-point number.
 149.861 -     * @since 1.3
 149.862 -     */
 149.863 -    public static native long doubleToRawLongBits(double value);
 149.864 -
 149.865 -    /**
 149.866 -     * Returns the {@code double} value corresponding to a given
 149.867 -     * bit representation.
 149.868 -     * The argument is considered to be a representation of a
 149.869 -     * floating-point value according to the IEEE 754 floating-point
 149.870 -     * "double format" bit layout.
 149.871 -     *
 149.872 -     * <p>If the argument is {@code 0x7ff0000000000000L}, the result
 149.873 -     * is positive infinity.
 149.874 -     *
 149.875 -     * <p>If the argument is {@code 0xfff0000000000000L}, the result
 149.876 -     * is negative infinity.
 149.877 -     *
 149.878 -     * <p>If the argument is any value in the range
 149.879 -     * {@code 0x7ff0000000000001L} through
 149.880 -     * {@code 0x7fffffffffffffffL} or in the range
 149.881 -     * {@code 0xfff0000000000001L} through
 149.882 -     * {@code 0xffffffffffffffffL}, the result is a NaN.  No IEEE
 149.883 -     * 754 floating-point operation provided by Java can distinguish
 149.884 -     * between two NaN values of the same type with different bit
 149.885 -     * patterns.  Distinct values of NaN are only distinguishable by
 149.886 -     * use of the {@code Double.doubleToRawLongBits} method.
 149.887 -     *
 149.888 -     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 149.889 -     * values that can be computed from the argument:
 149.890 -     *
 149.891 -     * <blockquote><pre>
 149.892 -     * int s = ((bits &gt;&gt; 63) == 0) ? 1 : -1;
 149.893 -     * int e = (int)((bits &gt;&gt; 52) & 0x7ffL);
 149.894 -     * long m = (e == 0) ?
 149.895 -     *                 (bits & 0xfffffffffffffL) &lt;&lt; 1 :
 149.896 -     *                 (bits & 0xfffffffffffffL) | 0x10000000000000L;
 149.897 -     * </pre></blockquote>
 149.898 -     *
 149.899 -     * Then the floating-point result equals the value of the mathematical
 149.900 -     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-1075</sup>.
 149.901 -     *
 149.902 -     * <p>Note that this method may not be able to return a
 149.903 -     * {@code double} NaN with exactly same bit pattern as the
 149.904 -     * {@code long} argument.  IEEE 754 distinguishes between two
 149.905 -     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 149.906 -     * differences between the two kinds of NaN are generally not
 149.907 -     * visible in Java.  Arithmetic operations on signaling NaNs turn
 149.908 -     * them into quiet NaNs with a different, but often similar, bit
 149.909 -     * pattern.  However, on some processors merely copying a
 149.910 -     * signaling NaN also performs that conversion.  In particular,
 149.911 -     * copying a signaling NaN to return it to the calling method
 149.912 -     * may perform this conversion.  So {@code longBitsToDouble}
 149.913 -     * may not be able to return a {@code double} with a
 149.914 -     * signaling NaN bit pattern.  Consequently, for some
 149.915 -     * {@code long} values,
 149.916 -     * {@code doubleToRawLongBits(longBitsToDouble(start))} may
 149.917 -     * <i>not</i> equal {@code start}.  Moreover, which
 149.918 -     * particular bit patterns represent signaling NaNs is platform
 149.919 -     * dependent; although all NaN bit patterns, quiet or signaling,
 149.920 -     * must be in the NaN range identified above.
 149.921 -     *
 149.922 -     * @param   bits   any {@code long} integer.
 149.923 -     * @return  the {@code double} floating-point value with the same
 149.924 -     *          bit pattern.
 149.925 -     */
 149.926 -    public static native double longBitsToDouble(long bits);
 149.927 -
 149.928 -    /**
 149.929 -     * Compares two {@code Double} objects numerically.  There
 149.930 -     * are two ways in which comparisons performed by this method
 149.931 -     * differ from those performed by the Java language numerical
 149.932 -     * comparison operators ({@code <, <=, ==, >=, >})
 149.933 -     * when applied to primitive {@code double} values:
 149.934 -     * <ul><li>
 149.935 -     *          {@code Double.NaN} is considered by this method
 149.936 -     *          to be equal to itself and greater than all other
 149.937 -     *          {@code double} values (including
 149.938 -     *          {@code Double.POSITIVE_INFINITY}).
 149.939 -     * <li>
 149.940 -     *          {@code 0.0d} is considered by this method to be greater
 149.941 -     *          than {@code -0.0d}.
 149.942 -     * </ul>
 149.943 -     * This ensures that the <i>natural ordering</i> of
 149.944 -     * {@code Double} objects imposed by this method is <i>consistent
 149.945 -     * with equals</i>.
 149.946 -     *
 149.947 -     * @param   anotherDouble   the {@code Double} to be compared.
 149.948 -     * @return  the value {@code 0} if {@code anotherDouble} is
 149.949 -     *          numerically equal to this {@code Double}; a value
 149.950 -     *          less than {@code 0} if this {@code Double}
 149.951 -     *          is numerically less than {@code anotherDouble};
 149.952 -     *          and a value greater than {@code 0} if this
 149.953 -     *          {@code Double} is numerically greater than
 149.954 -     *          {@code anotherDouble}.
 149.955 -     *
 149.956 -     * @since   1.2
 149.957 -     */
 149.958 -    public int compareTo(Double anotherDouble) {
 149.959 -        return Double.compare(value, anotherDouble.value);
 149.960 -    }
 149.961 -
 149.962 -    /**
 149.963 -     * Compares the two specified {@code double} values. The sign
 149.964 -     * of the integer value returned is the same as that of the
 149.965 -     * integer that would be returned by the call:
 149.966 -     * <pre>
 149.967 -     *    new Double(d1).compareTo(new Double(d2))
 149.968 -     * </pre>
 149.969 -     *
 149.970 -     * @param   d1        the first {@code double} to compare
 149.971 -     * @param   d2        the second {@code double} to compare
 149.972 -     * @return  the value {@code 0} if {@code d1} is
 149.973 -     *          numerically equal to {@code d2}; a value less than
 149.974 -     *          {@code 0} if {@code d1} is numerically less than
 149.975 -     *          {@code d2}; and a value greater than {@code 0}
 149.976 -     *          if {@code d1} is numerically greater than
 149.977 -     *          {@code d2}.
 149.978 -     * @since 1.4
 149.979 -     */
 149.980 -    public static int compare(double d1, double d2) {
 149.981 -        if (d1 < d2)
 149.982 -            return -1;           // Neither val is NaN, thisVal is smaller
 149.983 -        if (d1 > d2)
 149.984 -            return 1;            // Neither val is NaN, thisVal is larger
 149.985 -
 149.986 -        // Cannot use doubleToRawLongBits because of possibility of NaNs.
 149.987 -        long thisBits    = Double.doubleToLongBits(d1);
 149.988 -        long anotherBits = Double.doubleToLongBits(d2);
 149.989 -
 149.990 -        return (thisBits == anotherBits ?  0 : // Values are equal
 149.991 -                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 149.992 -                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 149.993 -    }
 149.994 -
 149.995 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 149.996 -    private static final long serialVersionUID = -9172774392245257468L;
 149.997 -}
   150.1 --- a/emul/mini/src/main/java/java/lang/Enum.java	Mon Feb 25 19:00:08 2013 +0100
   150.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.3 @@ -1,254 +0,0 @@
   150.4 -/*
   150.5 - * Copyright (c) 2003, 2009, 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.io.Serializable;
  150.32 -import java.io.IOException;
  150.33 -
  150.34 -/**
  150.35 - * This is the common base class of all Java language enumeration types.
  150.36 - *
  150.37 - * More information about enums, including descriptions of the
  150.38 - * implicitly declared methods synthesized by the compiler, can be
  150.39 - * found in section 8.9 of
  150.40 - * <cite>The Java&trade; Language Specification</cite>.
  150.41 - *
  150.42 - * <p> Note that when using an enumeration type as the type of a set
  150.43 - * or as the type of the keys in a map, specialized and efficient
  150.44 - * {@linkplain java.util.EnumSet set} and {@linkplain
  150.45 - * java.util.EnumMap map} implementations are available.
  150.46 - *
  150.47 - * @param <E> The enum type subclass
  150.48 - * @author  Josh Bloch
  150.49 - * @author  Neal Gafter
  150.50 - * @see     Class#getEnumConstants()
  150.51 - * @see     java.util.EnumSet
  150.52 - * @see     java.util.EnumMap
  150.53 - * @since   1.5
  150.54 - */
  150.55 -public abstract class Enum<E extends Enum<E>>
  150.56 -        implements Comparable<E>, Serializable {
  150.57 -    /**
  150.58 -     * The name of this enum constant, as declared in the enum declaration.
  150.59 -     * Most programmers should use the {@link #toString} method rather than
  150.60 -     * accessing this field.
  150.61 -     */
  150.62 -    private final String name;
  150.63 -
  150.64 -    /**
  150.65 -     * Returns the name of this enum constant, exactly as declared in its
  150.66 -     * enum declaration.
  150.67 -     *
  150.68 -     * <b>Most programmers should use the {@link #toString} method in
  150.69 -     * preference to this one, as the toString method may return
  150.70 -     * a more user-friendly name.</b>  This method is designed primarily for
  150.71 -     * use in specialized situations where correctness depends on getting the
  150.72 -     * exact name, which will not vary from release to release.
  150.73 -     *
  150.74 -     * @return the name of this enum constant
  150.75 -     */
  150.76 -    public final String name() {
  150.77 -        return name;
  150.78 -    }
  150.79 -
  150.80 -    /**
  150.81 -     * The ordinal of this enumeration constant (its position
  150.82 -     * in the enum declaration, where the initial constant is assigned
  150.83 -     * an ordinal of zero).
  150.84 -     *
  150.85 -     * Most programmers will have no use for this field.  It is designed
  150.86 -     * for use by sophisticated enum-based data structures, such as
  150.87 -     * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  150.88 -     */
  150.89 -    private final int ordinal;
  150.90 -
  150.91 -    /**
  150.92 -     * Returns the ordinal of this enumeration constant (its position
  150.93 -     * in its enum declaration, where the initial constant is assigned
  150.94 -     * an ordinal of zero).
  150.95 -     *
  150.96 -     * Most programmers will have no use for this method.  It is
  150.97 -     * designed for use by sophisticated enum-based data structures, such
  150.98 -     * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  150.99 -     *
 150.100 -     * @return the ordinal of this enumeration constant
 150.101 -     */
 150.102 -    public final int ordinal() {
 150.103 -        return ordinal;
 150.104 -    }
 150.105 -
 150.106 -    /**
 150.107 -     * Sole constructor.  Programmers cannot invoke this constructor.
 150.108 -     * It is for use by code emitted by the compiler in response to
 150.109 -     * enum type declarations.
 150.110 -     *
 150.111 -     * @param name - The name of this enum constant, which is the identifier
 150.112 -     *               used to declare it.
 150.113 -     * @param ordinal - The ordinal of this enumeration constant (its position
 150.114 -     *         in the enum declaration, where the initial constant is assigned
 150.115 -     *         an ordinal of zero).
 150.116 -     */
 150.117 -    protected Enum(String name, int ordinal) {
 150.118 -        this.name = name;
 150.119 -        this.ordinal = ordinal;
 150.120 -    }
 150.121 -
 150.122 -    /**
 150.123 -     * Returns the name of this enum constant, as contained in the
 150.124 -     * declaration.  This method may be overridden, though it typically
 150.125 -     * isn't necessary or desirable.  An enum type should override this
 150.126 -     * method when a more "programmer-friendly" string form exists.
 150.127 -     *
 150.128 -     * @return the name of this enum constant
 150.129 -     */
 150.130 -    public String toString() {
 150.131 -        return name;
 150.132 -    }
 150.133 -
 150.134 -    /**
 150.135 -     * Returns true if the specified object is equal to this
 150.136 -     * enum constant.
 150.137 -     *
 150.138 -     * @param other the object to be compared for equality with this object.
 150.139 -     * @return  true if the specified object is equal to this
 150.140 -     *          enum constant.
 150.141 -     */
 150.142 -    public final boolean equals(Object other) {
 150.143 -        return this==other;
 150.144 -    }
 150.145 -
 150.146 -    /**
 150.147 -     * Returns a hash code for this enum constant.
 150.148 -     *
 150.149 -     * @return a hash code for this enum constant.
 150.150 -     */
 150.151 -    public final int hashCode() {
 150.152 -        return super.hashCode();
 150.153 -    }
 150.154 -
 150.155 -    /**
 150.156 -     * Throws CloneNotSupportedException.  This guarantees that enums
 150.157 -     * are never cloned, which is necessary to preserve their "singleton"
 150.158 -     * status.
 150.159 -     *
 150.160 -     * @return (never returns)
 150.161 -     */
 150.162 -    protected final Object clone() throws CloneNotSupportedException {
 150.163 -        throw new CloneNotSupportedException();
 150.164 -    }
 150.165 -
 150.166 -    /**
 150.167 -     * Compares this enum with the specified object for order.  Returns a
 150.168 -     * negative integer, zero, or a positive integer as this object is less
 150.169 -     * than, equal to, or greater than the specified object.
 150.170 -     *
 150.171 -     * Enum constants are only comparable to other enum constants of the
 150.172 -     * same enum type.  The natural order implemented by this
 150.173 -     * method is the order in which the constants are declared.
 150.174 -     */
 150.175 -    public final int compareTo(E o) {
 150.176 -        Enum other = (Enum)o;
 150.177 -        Enum self = this;
 150.178 -        if (self.getClass() != other.getClass() && // optimization
 150.179 -            self.getDeclaringClass() != other.getDeclaringClass())
 150.180 -            throw new ClassCastException();
 150.181 -        return self.ordinal - other.ordinal;
 150.182 -    }
 150.183 -
 150.184 -    /**
 150.185 -     * Returns the Class object corresponding to this enum constant's
 150.186 -     * enum type.  Two enum constants e1 and  e2 are of the
 150.187 -     * same enum type if and only if
 150.188 -     *   e1.getDeclaringClass() == e2.getDeclaringClass().
 150.189 -     * (The value returned by this method may differ from the one returned
 150.190 -     * by the {@link Object#getClass} method for enum constants with
 150.191 -     * constant-specific class bodies.)
 150.192 -     *
 150.193 -     * @return the Class object corresponding to this enum constant's
 150.194 -     *     enum type
 150.195 -     */
 150.196 -    public final Class<E> getDeclaringClass() {
 150.197 -        Class clazz = getClass();
 150.198 -        Class zuper = clazz.getSuperclass();
 150.199 -        return (zuper == Enum.class) ? clazz : zuper;
 150.200 -    }
 150.201 -
 150.202 -    /**
 150.203 -     * Returns the enum constant of the specified enum type with the
 150.204 -     * specified name.  The name must match exactly an identifier used
 150.205 -     * to declare an enum constant in this type.  (Extraneous whitespace
 150.206 -     * characters are not permitted.)
 150.207 -     *
 150.208 -     * <p>Note that for a particular enum type {@code T}, the
 150.209 -     * implicitly declared {@code public static T valueOf(String)}
 150.210 -     * method on that enum may be used instead of this method to map
 150.211 -     * from a name to the corresponding enum constant.  All the
 150.212 -     * constants of an enum type can be obtained by calling the
 150.213 -     * implicit {@code public static T[] values()} method of that
 150.214 -     * type.
 150.215 -     *
 150.216 -     * @param <T> The enum type whose constant is to be returned
 150.217 -     * @param enumType the {@code Class} object of the enum type from which
 150.218 -     *      to return a constant
 150.219 -     * @param name the name of the constant to return
 150.220 -     * @return the enum constant of the specified enum type with the
 150.221 -     *      specified name
 150.222 -     * @throws IllegalArgumentException if the specified enum type has
 150.223 -     *         no constant with the specified name, or the specified
 150.224 -     *         class object does not represent an enum type
 150.225 -     * @throws NullPointerException if {@code enumType} or {@code name}
 150.226 -     *         is null
 150.227 -     * @since 1.5
 150.228 -     */
 150.229 -    public static <T extends Enum<T>> T valueOf(Class<T> enumType,
 150.230 -                                                String name) {
 150.231 -        throw new UnsupportedOperationException();
 150.232 -//        T result = enumType.enumConstantDirectory().get(name);
 150.233 -//        if (result != null)
 150.234 -//            return result;
 150.235 -//        if (name == null)
 150.236 -//            throw new NullPointerException("Name is null");
 150.237 -//        throw new IllegalArgumentException(
 150.238 -//            "No enum constant " + enumType.getCanonicalName() + "." + name);
 150.239 -    }
 150.240 -
 150.241 -    /**
 150.242 -     * enum classes cannot have finalize methods.
 150.243 -     */
 150.244 -    protected final void finalize() { }
 150.245 -
 150.246 -    /**
 150.247 -     * prevent default deserialization
 150.248 -     */
 150.249 -//    private void readObject(ObjectInputStream in) throws IOException,
 150.250 -//        ClassNotFoundException {
 150.251 -//        throw new InvalidObjectException("can't deserialize enum");
 150.252 -//    }
 150.253 -//
 150.254 -//    private void readObjectNoData() throws ObjectStreamException {
 150.255 -//        throw new InvalidObjectException("can't deserialize enum");
 150.256 -//    }
 150.257 -}
   151.1 --- a/emul/mini/src/main/java/java/lang/Error.java	Mon Feb 25 19:00:08 2013 +0100
   151.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.3 @@ -1,128 +0,0 @@
   151.4 -/*
   151.5 - * Copyright (c) 1995, 2011, 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 - * An {@code Error} is a subclass of {@code Throwable}
  151.33 - * that indicates serious problems that a reasonable application
  151.34 - * should not try to catch. Most such errors are abnormal conditions.
  151.35 - * The {@code ThreadDeath} error, though a "normal" condition,
  151.36 - * is also a subclass of {@code Error} because most applications
  151.37 - * should not try to catch it.
  151.38 - * <p>
  151.39 - * A method is not required to declare in its {@code throws}
  151.40 - * clause any subclasses of {@code Error} that might be thrown
  151.41 - * during the execution of the method but not caught, since these
  151.42 - * errors are abnormal conditions that should never occur.
  151.43 - *
  151.44 - * That is, {@code Error} and its subclasses are regarded as unchecked
  151.45 - * exceptions for the purposes of compile-time checking of exceptions.
  151.46 - *
  151.47 - * @author  Frank Yellin
  151.48 - * @see     java.lang.ThreadDeath
  151.49 - * @jls 11.2 Compile-Time Checking of Exceptions
  151.50 - * @since   JDK1.0
  151.51 - */
  151.52 -public class Error extends Throwable {
  151.53 -    static final long serialVersionUID = 4980196508277280342L;
  151.54 -
  151.55 -    /**
  151.56 -     * Constructs a new error with {@code null} as its detail message.
  151.57 -     * The cause is not initialized, and may subsequently be initialized by a
  151.58 -     * call to {@link #initCause}.
  151.59 -     */
  151.60 -    public Error() {
  151.61 -        super();
  151.62 -    }
  151.63 -
  151.64 -    /**
  151.65 -     * Constructs a new error with the specified detail message.  The
  151.66 -     * cause is not initialized, and may subsequently be initialized by
  151.67 -     * a call to {@link #initCause}.
  151.68 -     *
  151.69 -     * @param   message   the detail message. The detail message is saved for
  151.70 -     *          later retrieval by the {@link #getMessage()} method.
  151.71 -     */
  151.72 -    public Error(String message) {
  151.73 -        super(message);
  151.74 -    }
  151.75 -
  151.76 -    /**
  151.77 -     * Constructs a new error with the specified detail message and
  151.78 -     * cause.  <p>Note that the detail message associated with
  151.79 -     * {@code cause} is <i>not</i> automatically incorporated in
  151.80 -     * this error's detail message.
  151.81 -     *
  151.82 -     * @param  message the detail message (which is saved for later retrieval
  151.83 -     *         by the {@link #getMessage()} method).
  151.84 -     * @param  cause the cause (which is saved for later retrieval by the
  151.85 -     *         {@link #getCause()} method).  (A {@code null} value is
  151.86 -     *         permitted, and indicates that the cause is nonexistent or
  151.87 -     *         unknown.)
  151.88 -     * @since  1.4
  151.89 -     */
  151.90 -    public Error(String message, Throwable cause) {
  151.91 -        super(message, cause);
  151.92 -    }
  151.93 -
  151.94 -    /**
  151.95 -     * Constructs a new error with the specified cause and a detail
  151.96 -     * message of {@code (cause==null ? null : cause.toString())} (which
  151.97 -     * typically contains the class and detail message of {@code cause}).
  151.98 -     * This constructor is useful for errors that are little more than
  151.99 -     * wrappers for other throwables.
 151.100 -     *
 151.101 -     * @param  cause the cause (which is saved for later retrieval by the
 151.102 -     *         {@link #getCause()} method).  (A {@code null} value is
 151.103 -     *         permitted, and indicates that the cause is nonexistent or
 151.104 -     *         unknown.)
 151.105 -     * @since  1.4
 151.106 -     */
 151.107 -    public Error(Throwable cause) {
 151.108 -        super(cause);
 151.109 -    }
 151.110 -
 151.111 -    /**
 151.112 -     * Constructs a new error with the specified detail message,
 151.113 -     * cause, suppression enabled or disabled, and writable stack
 151.114 -     * trace enabled or disabled.
 151.115 -     *
 151.116 -     * @param  message the detail message.
 151.117 -     * @param cause the cause.  (A {@code null} value is permitted,
 151.118 -     * and indicates that the cause is nonexistent or unknown.)
 151.119 -     * @param enableSuppression whether or not suppression is enabled
 151.120 -     *                          or disabled
 151.121 -     * @param writableStackTrace whether or not the stack trace should
 151.122 -     *                           be writable
 151.123 -     *
 151.124 -     * @since 1.7
 151.125 -     */
 151.126 -    protected Error(String message, Throwable cause,
 151.127 -                    boolean enableSuppression,
 151.128 -                    boolean writableStackTrace) {
 151.129 -        super(message, cause, enableSuppression, writableStackTrace);
 151.130 -    }
 151.131 -}
   152.1 --- a/emul/mini/src/main/java/java/lang/Exception.java	Mon Feb 25 19:00:08 2013 +0100
   152.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   152.3 @@ -1,124 +0,0 @@
   152.4 -/*
   152.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   152.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   152.7 - *
   152.8 - * This code is free software; you can redistribute it and/or modify it
   152.9 - * under the terms of the GNU General Public License version 2 only, as
  152.10 - * published by the Free Software Foundation.  Oracle designates this
  152.11 - * particular file as subject to the "Classpath" exception as provided
  152.12 - * by Oracle in the LICENSE file that accompanied this code.
  152.13 - *
  152.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  152.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  152.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  152.17 - * version 2 for more details (a copy is included in the LICENSE file that
  152.18 - * accompanied this code).
  152.19 - *
  152.20 - * You should have received a copy of the GNU General Public License version
  152.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  152.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  152.23 - *
  152.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  152.25 - * or visit www.oracle.com if you need additional information or have any
  152.26 - * questions.
  152.27 - */
  152.28 -
  152.29 -package java.lang;
  152.30 -
  152.31 -/**
  152.32 - * The class {@code Exception} and its subclasses are a form of
  152.33 - * {@code Throwable} that indicates conditions that a reasonable
  152.34 - * application might want to catch.
  152.35 - *
  152.36 - * <p>The class {@code Exception} and any subclasses that are not also
  152.37 - * subclasses of {@link RuntimeException} are <em>checked
  152.38 - * exceptions</em>.  Checked exceptions need to be declared in a
  152.39 - * method or constructor's {@code throws} clause if they can be thrown
  152.40 - * by the execution of the method or constructor and propagate outside
  152.41 - * the method or constructor boundary.
  152.42 - *
  152.43 - * @author  Frank Yellin
  152.44 - * @see     java.lang.Error
  152.45 - * @jls 11.2 Compile-Time Checking of Exceptions
  152.46 - * @since   JDK1.0
  152.47 - */
  152.48 -public class Exception extends Throwable {
  152.49 -    static final long serialVersionUID = -3387516993124229948L;
  152.50 -
  152.51 -    /**
  152.52 -     * Constructs a new exception with {@code null} as its detail message.
  152.53 -     * The cause is not initialized, and may subsequently be initialized by a
  152.54 -     * call to {@link #initCause}.
  152.55 -     */
  152.56 -    public Exception() {
  152.57 -        super();
  152.58 -    }
  152.59 -
  152.60 -    /**
  152.61 -     * Constructs a new exception with the specified detail message.  The
  152.62 -     * cause is not initialized, and may subsequently be initialized by
  152.63 -     * a call to {@link #initCause}.
  152.64 -     *
  152.65 -     * @param   message   the detail message. The detail message is saved for
  152.66 -     *          later retrieval by the {@link #getMessage()} method.
  152.67 -     */
  152.68 -    public Exception(String message) {
  152.69 -        super(message);
  152.70 -    }
  152.71 -
  152.72 -    /**
  152.73 -     * Constructs a new exception with the specified detail message and
  152.74 -     * cause.  <p>Note that the detail message associated with
  152.75 -     * {@code cause} is <i>not</i> automatically incorporated in
  152.76 -     * this exception's detail message.
  152.77 -     *
  152.78 -     * @param  message the detail message (which is saved for later retrieval
  152.79 -     *         by the {@link #getMessage()} method).
  152.80 -     * @param  cause the cause (which is saved for later retrieval by the
  152.81 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  152.82 -     *         permitted, and indicates that the cause is nonexistent or
  152.83 -     *         unknown.)
  152.84 -     * @since  1.4
  152.85 -     */
  152.86 -    public Exception(String message, Throwable cause) {
  152.87 -        super(message, cause);
  152.88 -    }
  152.89 -
  152.90 -    /**
  152.91 -     * Constructs a new exception with the specified cause and a detail
  152.92 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  152.93 -     * typically contains the class and detail message of <tt>cause</tt>).
  152.94 -     * This constructor is useful for exceptions that are little more than
  152.95 -     * wrappers for other throwables (for example, {@link
  152.96 -     * java.security.PrivilegedActionException}).
  152.97 -     *
  152.98 -     * @param  cause the cause (which is saved for later retrieval by the
  152.99 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
 152.100 -     *         permitted, and indicates that the cause is nonexistent or
 152.101 -     *         unknown.)
 152.102 -     * @since  1.4
 152.103 -     */
 152.104 -    public Exception(Throwable cause) {
 152.105 -        super(cause);
 152.106 -    }
 152.107 -
 152.108 -    /**
 152.109 -     * Constructs a new exception with the specified detail message,
 152.110 -     * cause, suppression enabled or disabled, and writable stack
 152.111 -     * trace enabled or disabled.
 152.112 -     *
 152.113 -     * @param  message the detail message.
 152.114 -     * @param cause the cause.  (A {@code null} value is permitted,
 152.115 -     * and indicates that the cause is nonexistent or unknown.)
 152.116 -     * @param enableSuppression whether or not suppression is enabled
 152.117 -     *                          or disabled
 152.118 -     * @param writableStackTrace whether or not the stack trace should
 152.119 -     *                           be writable
 152.120 -     * @since 1.7
 152.121 -     */
 152.122 -    protected Exception(String message, Throwable cause,
 152.123 -                        boolean enableSuppression,
 152.124 -                        boolean writableStackTrace) {
 152.125 -        super(message, cause, enableSuppression, writableStackTrace);
 152.126 -    }
 152.127 -}
   153.1 --- a/emul/mini/src/main/java/java/lang/Float.java	Mon Feb 25 19:00:08 2013 +0100
   153.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   153.3 @@ -1,909 +0,0 @@
   153.4 -/*
   153.5 - * Copyright (c) 1994, 2010, 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 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  153.32 -
  153.33 -/**
  153.34 - * The {@code Float} class wraps a value of primitive type
  153.35 - * {@code float} in an object. An object of type
  153.36 - * {@code Float} contains a single field whose type is
  153.37 - * {@code float}.
  153.38 - *
  153.39 - * <p>In addition, this class provides several methods for converting a
  153.40 - * {@code float} to a {@code String} and a
  153.41 - * {@code String} to a {@code float}, as well as other
  153.42 - * constants and methods useful when dealing with a
  153.43 - * {@code float}.
  153.44 - *
  153.45 - * @author  Lee Boynton
  153.46 - * @author  Arthur van Hoff
  153.47 - * @author  Joseph D. Darcy
  153.48 - * @since JDK1.0
  153.49 - */
  153.50 -public final class Float extends Number implements Comparable<Float> {
  153.51 -    /**
  153.52 -     * A constant holding the positive infinity of type
  153.53 -     * {@code float}. It is equal to the value returned by
  153.54 -     * {@code Float.intBitsToFloat(0x7f800000)}.
  153.55 -     */
  153.56 -    public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  153.57 -
  153.58 -    /**
  153.59 -     * A constant holding the negative infinity of type
  153.60 -     * {@code float}. It is equal to the value returned by
  153.61 -     * {@code Float.intBitsToFloat(0xff800000)}.
  153.62 -     */
  153.63 -    public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  153.64 -
  153.65 -    /**
  153.66 -     * A constant holding a Not-a-Number (NaN) value of type
  153.67 -     * {@code float}.  It is equivalent to the value returned by
  153.68 -     * {@code Float.intBitsToFloat(0x7fc00000)}.
  153.69 -     */
  153.70 -    public static final float NaN = 0.0f / 0.0f;
  153.71 -
  153.72 -    /**
  153.73 -     * A constant holding the largest positive finite value of type
  153.74 -     * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
  153.75 -     * It is equal to the hexadecimal floating-point literal
  153.76 -     * {@code 0x1.fffffeP+127f} and also equal to
  153.77 -     * {@code Float.intBitsToFloat(0x7f7fffff)}.
  153.78 -     */
  153.79 -    public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
  153.80 -
  153.81 -    /**
  153.82 -     * A constant holding the smallest positive normal value of type
  153.83 -     * {@code float}, 2<sup>-126</sup>.  It is equal to the
  153.84 -     * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
  153.85 -     * equal to {@code Float.intBitsToFloat(0x00800000)}.
  153.86 -     *
  153.87 -     * @since 1.6
  153.88 -     */
  153.89 -    public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
  153.90 -
  153.91 -    /**
  153.92 -     * A constant holding the smallest positive nonzero value of type
  153.93 -     * {@code float}, 2<sup>-149</sup>. It is equal to the
  153.94 -     * hexadecimal floating-point literal {@code 0x0.000002P-126f}
  153.95 -     * and also equal to {@code Float.intBitsToFloat(0x1)}.
  153.96 -     */
  153.97 -    public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
  153.98 -
  153.99 -    /**
 153.100 -     * Maximum exponent a finite {@code float} variable may have.  It
 153.101 -     * is equal to the value returned by {@code
 153.102 -     * Math.getExponent(Float.MAX_VALUE)}.
 153.103 -     *
 153.104 -     * @since 1.6
 153.105 -     */
 153.106 -    public static final int MAX_EXPONENT = 127;
 153.107 -
 153.108 -    /**
 153.109 -     * Minimum exponent a normalized {@code float} variable may have.
 153.110 -     * It is equal to the value returned by {@code
 153.111 -     * Math.getExponent(Float.MIN_NORMAL)}.
 153.112 -     *
 153.113 -     * @since 1.6
 153.114 -     */
 153.115 -    public static final int MIN_EXPONENT = -126;
 153.116 -
 153.117 -    /**
 153.118 -     * The number of bits used to represent a {@code float} value.
 153.119 -     *
 153.120 -     * @since 1.5
 153.121 -     */
 153.122 -    public static final int SIZE = 32;
 153.123 -
 153.124 -    /**
 153.125 -     * The {@code Class} instance representing the primitive type
 153.126 -     * {@code float}.
 153.127 -     *
 153.128 -     * @since JDK1.1
 153.129 -     */
 153.130 -    public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
 153.131 -
 153.132 -    /**
 153.133 -     * Returns a string representation of the {@code float}
 153.134 -     * argument. All characters mentioned below are ASCII characters.
 153.135 -     * <ul>
 153.136 -     * <li>If the argument is NaN, the result is the string
 153.137 -     * "{@code NaN}".
 153.138 -     * <li>Otherwise, the result is a string that represents the sign and
 153.139 -     *     magnitude (absolute value) of the argument. If the sign is
 153.140 -     *     negative, the first character of the result is
 153.141 -     *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
 153.142 -     *     positive, no sign character appears in the result. As for
 153.143 -     *     the magnitude <i>m</i>:
 153.144 -     * <ul>
 153.145 -     * <li>If <i>m</i> is infinity, it is represented by the characters
 153.146 -     *     {@code "Infinity"}; thus, positive infinity produces
 153.147 -     *     the result {@code "Infinity"} and negative infinity
 153.148 -     *     produces the result {@code "-Infinity"}.
 153.149 -     * <li>If <i>m</i> is zero, it is represented by the characters
 153.150 -     *     {@code "0.0"}; thus, negative zero produces the result
 153.151 -     *     {@code "-0.0"} and positive zero produces the result
 153.152 -     *     {@code "0.0"}.
 153.153 -     * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
 153.154 -     *      less than 10<sup>7</sup>, then it is represented as the
 153.155 -     *      integer part of <i>m</i>, in decimal form with no leading
 153.156 -     *      zeroes, followed by '{@code .}'
 153.157 -     *      (<code>'&#92;u002E'</code>), followed by one or more
 153.158 -     *      decimal digits representing the fractional part of
 153.159 -     *      <i>m</i>.
 153.160 -     * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 153.161 -     *      equal to 10<sup>7</sup>, then it is represented in
 153.162 -     *      so-called "computerized scientific notation." Let <i>n</i>
 153.163 -     *      be the unique integer such that 10<sup><i>n</i> </sup>&le;
 153.164 -     *      <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
 153.165 -     *      be the mathematically exact quotient of <i>m</i> and
 153.166 -     *      10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10.
 153.167 -     *      The magnitude is then represented as the integer part of
 153.168 -     *      <i>a</i>, as a single decimal digit, followed by
 153.169 -     *      '{@code .}' (<code>'&#92;u002E'</code>), followed by
 153.170 -     *      decimal digits representing the fractional part of
 153.171 -     *      <i>a</i>, followed by the letter '{@code E}'
 153.172 -     *      (<code>'&#92;u0045'</code>), followed by a representation
 153.173 -     *      of <i>n</i> as a decimal integer, as produced by the
 153.174 -     *      method {@link java.lang.Integer#toString(int)}.
 153.175 -     *
 153.176 -     * </ul>
 153.177 -     * </ul>
 153.178 -     * How many digits must be printed for the fractional part of
 153.179 -     * <i>m</i> or <i>a</i>? There must be at least one digit
 153.180 -     * to represent the fractional part, and beyond that as many, but
 153.181 -     * only as many, more digits as are needed to uniquely distinguish
 153.182 -     * the argument value from adjacent values of type
 153.183 -     * {@code float}. That is, suppose that <i>x</i> is the
 153.184 -     * exact mathematical value represented by the decimal
 153.185 -     * representation produced by this method for a finite nonzero
 153.186 -     * argument <i>f</i>. Then <i>f</i> must be the {@code float}
 153.187 -     * value nearest to <i>x</i>; or, if two {@code float} values are
 153.188 -     * equally close to <i>x</i>, then <i>f</i> must be one of
 153.189 -     * them and the least significant bit of the significand of
 153.190 -     * <i>f</i> must be {@code 0}.
 153.191 -     *
 153.192 -     * <p>To create localized string representations of a floating-point
 153.193 -     * value, use subclasses of {@link java.text.NumberFormat}.
 153.194 -     *
 153.195 -     * @param   f   the float to be converted.
 153.196 -     * @return a string representation of the argument.
 153.197 -     */
 153.198 -    public static String toString(float f) {
 153.199 -        return Double.toString(f);
 153.200 -    }
 153.201 -
 153.202 -    /**
 153.203 -     * Returns a hexadecimal string representation of the
 153.204 -     * {@code float} argument. All characters mentioned below are
 153.205 -     * ASCII characters.
 153.206 -     *
 153.207 -     * <ul>
 153.208 -     * <li>If the argument is NaN, the result is the string
 153.209 -     *     "{@code NaN}".
 153.210 -     * <li>Otherwise, the result is a string that represents the sign and
 153.211 -     * magnitude (absolute value) of the argument. If the sign is negative,
 153.212 -     * the first character of the result is '{@code -}'
 153.213 -     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 153.214 -     * appears in the result. As for the magnitude <i>m</i>:
 153.215 -     *
 153.216 -     * <ul>
 153.217 -     * <li>If <i>m</i> is infinity, it is represented by the string
 153.218 -     * {@code "Infinity"}; thus, positive infinity produces the
 153.219 -     * result {@code "Infinity"} and negative infinity produces
 153.220 -     * the result {@code "-Infinity"}.
 153.221 -     *
 153.222 -     * <li>If <i>m</i> is zero, it is represented by the string
 153.223 -     * {@code "0x0.0p0"}; thus, negative zero produces the result
 153.224 -     * {@code "-0x0.0p0"} and positive zero produces the result
 153.225 -     * {@code "0x0.0p0"}.
 153.226 -     *
 153.227 -     * <li>If <i>m</i> is a {@code float} value with a
 153.228 -     * normalized representation, substrings are used to represent the
 153.229 -     * significand and exponent fields.  The significand is
 153.230 -     * represented by the characters {@code "0x1."}
 153.231 -     * followed by a lowercase hexadecimal representation of the rest
 153.232 -     * of the significand as a fraction.  Trailing zeros in the
 153.233 -     * hexadecimal representation are removed unless all the digits
 153.234 -     * are zero, in which case a single zero is used. Next, the
 153.235 -     * exponent is represented by {@code "p"} followed
 153.236 -     * by a decimal string of the unbiased exponent as if produced by
 153.237 -     * a call to {@link Integer#toString(int) Integer.toString} on the
 153.238 -     * exponent value.
 153.239 -     *
 153.240 -     * <li>If <i>m</i> is a {@code float} value with a subnormal
 153.241 -     * representation, the significand is represented by the
 153.242 -     * characters {@code "0x0."} followed by a
 153.243 -     * hexadecimal representation of the rest of the significand as a
 153.244 -     * fraction.  Trailing zeros in the hexadecimal representation are
 153.245 -     * removed. Next, the exponent is represented by
 153.246 -     * {@code "p-126"}.  Note that there must be at
 153.247 -     * least one nonzero digit in a subnormal significand.
 153.248 -     *
 153.249 -     * </ul>
 153.250 -     *
 153.251 -     * </ul>
 153.252 -     *
 153.253 -     * <table border>
 153.254 -     * <caption><h3>Examples</h3></caption>
 153.255 -     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 153.256 -     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 153.257 -     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 153.258 -     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 153.259 -     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 153.260 -     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 153.261 -     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 153.262 -     * <tr><td>{@code Float.MAX_VALUE}</td>
 153.263 -     *     <td>{@code 0x1.fffffep127}</td>
 153.264 -     * <tr><td>{@code Minimum Normal Value}</td>
 153.265 -     *     <td>{@code 0x1.0p-126}</td>
 153.266 -     * <tr><td>{@code Maximum Subnormal Value}</td>
 153.267 -     *     <td>{@code 0x0.fffffep-126}</td>
 153.268 -     * <tr><td>{@code Float.MIN_VALUE}</td>
 153.269 -     *     <td>{@code 0x0.000002p-126}</td>
 153.270 -     * </table>
 153.271 -     * @param   f   the {@code float} to be converted.
 153.272 -     * @return a hex string representation of the argument.
 153.273 -     * @since 1.5
 153.274 -     * @author Joseph D. Darcy
 153.275 -     */
 153.276 -    public static String toHexString(float f) {
 153.277 -        throw new UnsupportedOperationException();
 153.278 -//        if (Math.abs(f) < FloatConsts.MIN_NORMAL
 153.279 -//            &&  f != 0.0f ) {// float subnormal
 153.280 -//            // Adjust exponent to create subnormal double, then
 153.281 -//            // replace subnormal double exponent with subnormal float
 153.282 -//            // exponent
 153.283 -//            String s = Double.toHexString(FpUtils.scalb((double)f,
 153.284 -//                                                        /* -1022+126 */
 153.285 -//                                                        DoubleConsts.MIN_EXPONENT-
 153.286 -//                                                        FloatConsts.MIN_EXPONENT));
 153.287 -//            return s.replaceFirst("p-1022$", "p-126");
 153.288 -//        }
 153.289 -//        else // double string will be the same as float string
 153.290 -//            return Double.toHexString(f);
 153.291 -    }
 153.292 -
 153.293 -    /**
 153.294 -     * Returns a {@code Float} object holding the
 153.295 -     * {@code float} value represented by the argument string
 153.296 -     * {@code s}.
 153.297 -     *
 153.298 -     * <p>If {@code s} is {@code null}, then a
 153.299 -     * {@code NullPointerException} is thrown.
 153.300 -     *
 153.301 -     * <p>Leading and trailing whitespace characters in {@code s}
 153.302 -     * are ignored.  Whitespace is removed as if by the {@link
 153.303 -     * String#trim} method; that is, both ASCII space and control
 153.304 -     * characters are removed. The rest of {@code s} should
 153.305 -     * constitute a <i>FloatValue</i> as described by the lexical
 153.306 -     * syntax rules:
 153.307 -     *
 153.308 -     * <blockquote>
 153.309 -     * <dl>
 153.310 -     * <dt><i>FloatValue:</i>
 153.311 -     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 153.312 -     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 153.313 -     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 153.314 -     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 153.315 -     * <dd><i>SignedInteger</i>
 153.316 -     * </dl>
 153.317 -     *
 153.318 -     * <p>
 153.319 -     *
 153.320 -     * <dl>
 153.321 -     * <dt><i>HexFloatingPointLiteral</i>:
 153.322 -     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 153.323 -     * </dl>
 153.324 -     *
 153.325 -     * <p>
 153.326 -     *
 153.327 -     * <dl>
 153.328 -     * <dt><i>HexSignificand:</i>
 153.329 -     * <dd><i>HexNumeral</i>
 153.330 -     * <dd><i>HexNumeral</i> {@code .}
 153.331 -     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 153.332 -     *     </i>{@code .}<i> HexDigits</i>
 153.333 -     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 153.334 -     *     </i>{@code .} <i>HexDigits</i>
 153.335 -     * </dl>
 153.336 -     *
 153.337 -     * <p>
 153.338 -     *
 153.339 -     * <dl>
 153.340 -     * <dt><i>BinaryExponent:</i>
 153.341 -     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 153.342 -     * </dl>
 153.343 -     *
 153.344 -     * <p>
 153.345 -     *
 153.346 -     * <dl>
 153.347 -     * <dt><i>BinaryExponentIndicator:</i>
 153.348 -     * <dd>{@code p}
 153.349 -     * <dd>{@code P}
 153.350 -     * </dl>
 153.351 -     *
 153.352 -     * </blockquote>
 153.353 -     *
 153.354 -     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 153.355 -     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 153.356 -     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 153.357 -     * sections of
 153.358 -     * <cite>The Java&trade; Language Specification</cite>,
 153.359 -     * except that underscores are not accepted between digits.
 153.360 -     * If {@code s} does not have the form of
 153.361 -     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 153.362 -     * is thrown. Otherwise, {@code s} is regarded as
 153.363 -     * representing an exact decimal value in the usual
 153.364 -     * "computerized scientific notation" or as an exact
 153.365 -     * hexadecimal value; this exact numerical value is then
 153.366 -     * conceptually converted to an "infinitely precise"
 153.367 -     * binary value that is then rounded to type {@code float}
 153.368 -     * by the usual round-to-nearest rule of IEEE 754 floating-point
 153.369 -     * arithmetic, which includes preserving the sign of a zero
 153.370 -     * value.
 153.371 -     *
 153.372 -     * Note that the round-to-nearest rule also implies overflow and
 153.373 -     * underflow behaviour; if the exact value of {@code s} is large
 153.374 -     * enough in magnitude (greater than or equal to ({@link
 153.375 -     * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
 153.376 -     * rounding to {@code float} will result in an infinity and if the
 153.377 -     * exact value of {@code s} is small enough in magnitude (less
 153.378 -     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 153.379 -     * result in a zero.
 153.380 -     *
 153.381 -     * Finally, after rounding a {@code Float} object representing
 153.382 -     * this {@code float} value is returned.
 153.383 -     *
 153.384 -     * <p>To interpret localized string representations of a
 153.385 -     * floating-point value, use subclasses of {@link
 153.386 -     * java.text.NumberFormat}.
 153.387 -     *
 153.388 -     * <p>Note that trailing format specifiers, specifiers that
 153.389 -     * determine the type of a floating-point literal
 153.390 -     * ({@code 1.0f} is a {@code float} value;
 153.391 -     * {@code 1.0d} is a {@code double} value), do
 153.392 -     * <em>not</em> influence the results of this method.  In other
 153.393 -     * words, the numerical value of the input string is converted
 153.394 -     * directly to the target floating-point type.  In general, the
 153.395 -     * two-step sequence of conversions, string to {@code double}
 153.396 -     * followed by {@code double} to {@code float}, is
 153.397 -     * <em>not</em> equivalent to converting a string directly to
 153.398 -     * {@code float}.  For example, if first converted to an
 153.399 -     * intermediate {@code double} and then to
 153.400 -     * {@code float}, the string<br>
 153.401 -     * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
 153.402 -     * results in the {@code float} value
 153.403 -     * {@code 1.0000002f}; if the string is converted directly to
 153.404 -     * {@code float}, <code>1.000000<b>1</b>f</code> results.
 153.405 -     *
 153.406 -     * <p>To avoid calling this method on an invalid string and having
 153.407 -     * a {@code NumberFormatException} be thrown, the documentation
 153.408 -     * for {@link Double#valueOf Double.valueOf} lists a regular
 153.409 -     * expression which can be used to screen the input.
 153.410 -     *
 153.411 -     * @param   s   the string to be parsed.
 153.412 -     * @return  a {@code Float} object holding the value
 153.413 -     *          represented by the {@code String} argument.
 153.414 -     * @throws  NumberFormatException  if the string does not contain a
 153.415 -     *          parsable number.
 153.416 -     */
 153.417 -    public static Float valueOf(String s) throws NumberFormatException {
 153.418 -        throw new UnsupportedOperationException();
 153.419 -//        return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
 153.420 -    }
 153.421 -
 153.422 -    /**
 153.423 -     * Returns a {@code Float} instance representing the specified
 153.424 -     * {@code float} value.
 153.425 -     * If a new {@code Float} instance is not required, this method
 153.426 -     * should generally be used in preference to the constructor
 153.427 -     * {@link #Float(float)}, as this method is likely to yield
 153.428 -     * significantly better space and time performance by caching
 153.429 -     * frequently requested values.
 153.430 -     *
 153.431 -     * @param  f a float value.
 153.432 -     * @return a {@code Float} instance representing {@code f}.
 153.433 -     * @since  1.5
 153.434 -     */
 153.435 -    public static Float valueOf(float f) {
 153.436 -        return new Float(f);
 153.437 -    }
 153.438 -
 153.439 -    /**
 153.440 -     * Returns a new {@code float} initialized to the value
 153.441 -     * represented by the specified {@code String}, as performed
 153.442 -     * by the {@code valueOf} method of class {@code Float}.
 153.443 -     *
 153.444 -     * @param  s the string to be parsed.
 153.445 -     * @return the {@code float} value represented by the string
 153.446 -     *         argument.
 153.447 -     * @throws NullPointerException  if the string is null
 153.448 -     * @throws NumberFormatException if the string does not contain a
 153.449 -     *               parsable {@code float}.
 153.450 -     * @see    java.lang.Float#valueOf(String)
 153.451 -     * @since 1.2
 153.452 -     */
 153.453 -    public static float parseFloat(String s) throws NumberFormatException {
 153.454 -        throw new UnsupportedOperationException();
 153.455 -//        return FloatingDecimal.readJavaFormatString(s).floatValue();
 153.456 -    }
 153.457 -
 153.458 -    /**
 153.459 -     * Returns {@code true} if the specified number is a
 153.460 -     * Not-a-Number (NaN) value, {@code false} otherwise.
 153.461 -     *
 153.462 -     * @param   v   the value to be tested.
 153.463 -     * @return  {@code true} if the argument is NaN;
 153.464 -     *          {@code false} otherwise.
 153.465 -     */
 153.466 -    static public boolean isNaN(float v) {
 153.467 -        return (v != v);
 153.468 -    }
 153.469 -
 153.470 -    /**
 153.471 -     * Returns {@code true} if the specified number is infinitely
 153.472 -     * large in magnitude, {@code false} otherwise.
 153.473 -     *
 153.474 -     * @param   v   the value to be tested.
 153.475 -     * @return  {@code true} if the argument is positive infinity or
 153.476 -     *          negative infinity; {@code false} otherwise.
 153.477 -     */
 153.478 -    static public boolean isInfinite(float v) {
 153.479 -        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 153.480 -    }
 153.481 -
 153.482 -    /**
 153.483 -     * The value of the Float.
 153.484 -     *
 153.485 -     * @serial
 153.486 -     */
 153.487 -    private final float value;
 153.488 -
 153.489 -    /**
 153.490 -     * Constructs a newly allocated {@code Float} object that
 153.491 -     * represents the primitive {@code float} argument.
 153.492 -     *
 153.493 -     * @param   value   the value to be represented by the {@code Float}.
 153.494 -     */
 153.495 -    public Float(float value) {
 153.496 -        this.value = value;
 153.497 -    }
 153.498 -
 153.499 -    /**
 153.500 -     * Constructs a newly allocated {@code Float} object that
 153.501 -     * represents the argument converted to type {@code float}.
 153.502 -     *
 153.503 -     * @param   value   the value to be represented by the {@code Float}.
 153.504 -     */
 153.505 -    public Float(double value) {
 153.506 -        this.value = (float)value;
 153.507 -    }
 153.508 -
 153.509 -    /**
 153.510 -     * Constructs a newly allocated {@code Float} object that
 153.511 -     * represents the floating-point value of type {@code float}
 153.512 -     * represented by the string. The string is converted to a
 153.513 -     * {@code float} value as if by the {@code valueOf} method.
 153.514 -     *
 153.515 -     * @param      s   a string to be converted to a {@code Float}.
 153.516 -     * @throws  NumberFormatException  if the string does not contain a
 153.517 -     *               parsable number.
 153.518 -     * @see        java.lang.Float#valueOf(java.lang.String)
 153.519 -     */
 153.520 -    public Float(String s) throws NumberFormatException {
 153.521 -        // REMIND: this is inefficient
 153.522 -        this(valueOf(s).floatValue());
 153.523 -    }
 153.524 -
 153.525 -    /**
 153.526 -     * Returns {@code true} if this {@code Float} value is a
 153.527 -     * Not-a-Number (NaN), {@code false} otherwise.
 153.528 -     *
 153.529 -     * @return  {@code true} if the value represented by this object is
 153.530 -     *          NaN; {@code false} otherwise.
 153.531 -     */
 153.532 -    public boolean isNaN() {
 153.533 -        return isNaN(value);
 153.534 -    }
 153.535 -
 153.536 -    /**
 153.537 -     * Returns {@code true} if this {@code Float} value is
 153.538 -     * infinitely large in magnitude, {@code false} otherwise.
 153.539 -     *
 153.540 -     * @return  {@code true} if the value represented by this object is
 153.541 -     *          positive infinity or negative infinity;
 153.542 -     *          {@code false} otherwise.
 153.543 -     */
 153.544 -    public boolean isInfinite() {
 153.545 -        return isInfinite(value);
 153.546 -    }
 153.547 -
 153.548 -    /**
 153.549 -     * Returns a string representation of this {@code Float} object.
 153.550 -     * The primitive {@code float} value represented by this object
 153.551 -     * is converted to a {@code String} exactly as if by the method
 153.552 -     * {@code toString} of one argument.
 153.553 -     *
 153.554 -     * @return  a {@code String} representation of this object.
 153.555 -     * @see java.lang.Float#toString(float)
 153.556 -     */
 153.557 -    public String toString() {
 153.558 -        return Float.toString(value);
 153.559 -    }
 153.560 -
 153.561 -    /**
 153.562 -     * Returns the value of this {@code Float} as a {@code byte} (by
 153.563 -     * casting to a {@code byte}).
 153.564 -     *
 153.565 -     * @return  the {@code float} value represented by this object
 153.566 -     *          converted to type {@code byte}
 153.567 -     */
 153.568 -    public byte byteValue() {
 153.569 -        return (byte)value;
 153.570 -    }
 153.571 -
 153.572 -    /**
 153.573 -     * Returns the value of this {@code Float} as a {@code short} (by
 153.574 -     * casting to a {@code short}).
 153.575 -     *
 153.576 -     * @return  the {@code float} value represented by this object
 153.577 -     *          converted to type {@code short}
 153.578 -     * @since JDK1.1
 153.579 -     */
 153.580 -    public short shortValue() {
 153.581 -        return (short)value;
 153.582 -    }
 153.583 -
 153.584 -    /**
 153.585 -     * Returns the value of this {@code Float} as an {@code int} (by
 153.586 -     * casting to type {@code int}).
 153.587 -     *
 153.588 -     * @return  the {@code float} value represented by this object
 153.589 -     *          converted to type {@code int}
 153.590 -     */
 153.591 -    public int intValue() {
 153.592 -        return (int)value;
 153.593 -    }
 153.594 -
 153.595 -    /**
 153.596 -     * Returns value of this {@code Float} as a {@code long} (by
 153.597 -     * casting to type {@code long}).
 153.598 -     *
 153.599 -     * @return  the {@code float} value represented by this object
 153.600 -     *          converted to type {@code long}
 153.601 -     */
 153.602 -    public long longValue() {
 153.603 -        return (long)value;
 153.604 -    }
 153.605 -
 153.606 -    /**
 153.607 -     * Returns the {@code float} value of this {@code Float} object.
 153.608 -     *
 153.609 -     * @return the {@code float} value represented by this object
 153.610 -     */
 153.611 -    public float floatValue() {
 153.612 -        return value;
 153.613 -    }
 153.614 -
 153.615 -    /**
 153.616 -     * Returns the {@code double} value of this {@code Float} object.
 153.617 -     *
 153.618 -     * @return the {@code float} value represented by this
 153.619 -     *         object is converted to type {@code double} and the
 153.620 -     *         result of the conversion is returned.
 153.621 -     */
 153.622 -    public double doubleValue() {
 153.623 -        return (double)value;
 153.624 -    }
 153.625 -
 153.626 -    /**
 153.627 -     * Returns a hash code for this {@code Float} object. The
 153.628 -     * result is the integer bit representation, exactly as produced
 153.629 -     * by the method {@link #floatToIntBits(float)}, of the primitive
 153.630 -     * {@code float} value represented by this {@code Float}
 153.631 -     * object.
 153.632 -     *
 153.633 -     * @return a hash code value for this object.
 153.634 -     */
 153.635 -    public int hashCode() {
 153.636 -        return floatToIntBits(value);
 153.637 -    }
 153.638 -
 153.639 -    /**
 153.640 -
 153.641 -     * Compares this object against the specified object.  The result
 153.642 -     * is {@code true} if and only if the argument is not
 153.643 -     * {@code null} and is a {@code Float} object that
 153.644 -     * represents a {@code float} with the same value as the
 153.645 -     * {@code float} represented by this object. For this
 153.646 -     * purpose, two {@code float} values are considered to be the
 153.647 -     * same if and only if the method {@link #floatToIntBits(float)}
 153.648 -     * returns the identical {@code int} value when applied to
 153.649 -     * each.
 153.650 -     *
 153.651 -     * <p>Note that in most cases, for two instances of class
 153.652 -     * {@code Float}, {@code f1} and {@code f2}, the value
 153.653 -     * of {@code f1.equals(f2)} is {@code true} if and only if
 153.654 -     *
 153.655 -     * <blockquote><pre>
 153.656 -     *   f1.floatValue() == f2.floatValue()
 153.657 -     * </pre></blockquote>
 153.658 -     *
 153.659 -     * <p>also has the value {@code true}. However, there are two exceptions:
 153.660 -     * <ul>
 153.661 -     * <li>If {@code f1} and {@code f2} both represent
 153.662 -     *     {@code Float.NaN}, then the {@code equals} method returns
 153.663 -     *     {@code true}, even though {@code Float.NaN==Float.NaN}
 153.664 -     *     has the value {@code false}.
 153.665 -     * <li>If {@code f1} represents {@code +0.0f} while
 153.666 -     *     {@code f2} represents {@code -0.0f}, or vice
 153.667 -     *     versa, the {@code equal} test has the value
 153.668 -     *     {@code false}, even though {@code 0.0f==-0.0f}
 153.669 -     *     has the value {@code true}.
 153.670 -     * </ul>
 153.671 -     *
 153.672 -     * This definition allows hash tables to operate properly.
 153.673 -     *
 153.674 -     * @param obj the object to be compared
 153.675 -     * @return  {@code true} if the objects are the same;
 153.676 -     *          {@code false} otherwise.
 153.677 -     * @see java.lang.Float#floatToIntBits(float)
 153.678 -     */
 153.679 -    public boolean equals(Object obj) {
 153.680 -        return (obj instanceof Float)
 153.681 -               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
 153.682 -    }
 153.683 -
 153.684 -    /**
 153.685 -     * Returns a representation of the specified floating-point value
 153.686 -     * according to the IEEE 754 floating-point "single format" bit
 153.687 -     * layout.
 153.688 -     *
 153.689 -     * <p>Bit 31 (the bit that is selected by the mask
 153.690 -     * {@code 0x80000000}) represents the sign of the floating-point
 153.691 -     * number.
 153.692 -     * Bits 30-23 (the bits that are selected by the mask
 153.693 -     * {@code 0x7f800000}) represent the exponent.
 153.694 -     * Bits 22-0 (the bits that are selected by the mask
 153.695 -     * {@code 0x007fffff}) represent the significand (sometimes called
 153.696 -     * the mantissa) of the floating-point number.
 153.697 -     *
 153.698 -     * <p>If the argument is positive infinity, the result is
 153.699 -     * {@code 0x7f800000}.
 153.700 -     *
 153.701 -     * <p>If the argument is negative infinity, the result is
 153.702 -     * {@code 0xff800000}.
 153.703 -     *
 153.704 -     * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
 153.705 -     *
 153.706 -     * <p>In all cases, the result is an integer that, when given to the
 153.707 -     * {@link #intBitsToFloat(int)} method, will produce a floating-point
 153.708 -     * value the same as the argument to {@code floatToIntBits}
 153.709 -     * (except all NaN values are collapsed to a single
 153.710 -     * "canonical" NaN value).
 153.711 -     *
 153.712 -     * @param   value   a floating-point number.
 153.713 -     * @return the bits that represent the floating-point number.
 153.714 -     */
 153.715 -    public static int floatToIntBits(float value) {
 153.716 -        throw new UnsupportedOperationException();
 153.717 -//        int result = floatToRawIntBits(value);
 153.718 -//        // Check for NaN based on values of bit fields, maximum
 153.719 -//        // exponent and nonzero significand.
 153.720 -//        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
 153.721 -//              FloatConsts.EXP_BIT_MASK) &&
 153.722 -//             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
 153.723 -//            result = 0x7fc00000;
 153.724 -//        return result;
 153.725 -    }
 153.726 -
 153.727 -    /**
 153.728 -     * Returns a representation of the specified floating-point value
 153.729 -     * according to the IEEE 754 floating-point "single format" bit
 153.730 -     * layout, preserving Not-a-Number (NaN) values.
 153.731 -     *
 153.732 -     * <p>Bit 31 (the bit that is selected by the mask
 153.733 -     * {@code 0x80000000}) represents the sign of the floating-point
 153.734 -     * number.
 153.735 -     * Bits 30-23 (the bits that are selected by the mask
 153.736 -     * {@code 0x7f800000}) represent the exponent.
 153.737 -     * Bits 22-0 (the bits that are selected by the mask
 153.738 -     * {@code 0x007fffff}) represent the significand (sometimes called
 153.739 -     * the mantissa) of the floating-point number.
 153.740 -     *
 153.741 -     * <p>If the argument is positive infinity, the result is
 153.742 -     * {@code 0x7f800000}.
 153.743 -     *
 153.744 -     * <p>If the argument is negative infinity, the result is
 153.745 -     * {@code 0xff800000}.
 153.746 -     *
 153.747 -     * <p>If the argument is NaN, the result is the integer representing
 153.748 -     * the actual NaN value.  Unlike the {@code floatToIntBits}
 153.749 -     * method, {@code floatToRawIntBits} does not collapse all the
 153.750 -     * bit patterns encoding a NaN to a single "canonical"
 153.751 -     * NaN value.
 153.752 -     *
 153.753 -     * <p>In all cases, the result is an integer that, when given to the
 153.754 -     * {@link #intBitsToFloat(int)} method, will produce a
 153.755 -     * floating-point value the same as the argument to
 153.756 -     * {@code floatToRawIntBits}.
 153.757 -     *
 153.758 -     * @param   value   a floating-point number.
 153.759 -     * @return the bits that represent the floating-point number.
 153.760 -     * @since 1.3
 153.761 -     */
 153.762 -    public static native int floatToRawIntBits(float value);
 153.763 -
 153.764 -    /**
 153.765 -     * Returns the {@code float} value corresponding to a given
 153.766 -     * bit representation.
 153.767 -     * The argument is considered to be a representation of a
 153.768 -     * floating-point value according to the IEEE 754 floating-point
 153.769 -     * "single format" bit layout.
 153.770 -     *
 153.771 -     * <p>If the argument is {@code 0x7f800000}, the result is positive
 153.772 -     * infinity.
 153.773 -     *
 153.774 -     * <p>If the argument is {@code 0xff800000}, the result is negative
 153.775 -     * infinity.
 153.776 -     *
 153.777 -     * <p>If the argument is any value in the range
 153.778 -     * {@code 0x7f800001} through {@code 0x7fffffff} or in
 153.779 -     * the range {@code 0xff800001} through
 153.780 -     * {@code 0xffffffff}, the result is a NaN.  No IEEE 754
 153.781 -     * floating-point operation provided by Java can distinguish
 153.782 -     * between two NaN values of the same type with different bit
 153.783 -     * patterns.  Distinct values of NaN are only distinguishable by
 153.784 -     * use of the {@code Float.floatToRawIntBits} method.
 153.785 -     *
 153.786 -     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 153.787 -     * values that can be computed from the argument:
 153.788 -     *
 153.789 -     * <blockquote><pre>
 153.790 -     * int s = ((bits &gt;&gt; 31) == 0) ? 1 : -1;
 153.791 -     * int e = ((bits &gt;&gt; 23) & 0xff);
 153.792 -     * int m = (e == 0) ?
 153.793 -     *                 (bits & 0x7fffff) &lt;&lt; 1 :
 153.794 -     *                 (bits & 0x7fffff) | 0x800000;
 153.795 -     * </pre></blockquote>
 153.796 -     *
 153.797 -     * Then the floating-point result equals the value of the mathematical
 153.798 -     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-150</sup>.
 153.799 -     *
 153.800 -     * <p>Note that this method may not be able to return a
 153.801 -     * {@code float} NaN with exactly same bit pattern as the
 153.802 -     * {@code int} argument.  IEEE 754 distinguishes between two
 153.803 -     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 153.804 -     * differences between the two kinds of NaN are generally not
 153.805 -     * visible in Java.  Arithmetic operations on signaling NaNs turn
 153.806 -     * them into quiet NaNs with a different, but often similar, bit
 153.807 -     * pattern.  However, on some processors merely copying a
 153.808 -     * signaling NaN also performs that conversion.  In particular,
 153.809 -     * copying a signaling NaN to return it to the calling method may
 153.810 -     * perform this conversion.  So {@code intBitsToFloat} may
 153.811 -     * not be able to return a {@code float} with a signaling NaN
 153.812 -     * bit pattern.  Consequently, for some {@code int} values,
 153.813 -     * {@code floatToRawIntBits(intBitsToFloat(start))} may
 153.814 -     * <i>not</i> equal {@code start}.  Moreover, which
 153.815 -     * particular bit patterns represent signaling NaNs is platform
 153.816 -     * dependent; although all NaN bit patterns, quiet or signaling,
 153.817 -     * must be in the NaN range identified above.
 153.818 -     *
 153.819 -     * @param   bits   an integer.
 153.820 -     * @return  the {@code float} floating-point value with the same bit
 153.821 -     *          pattern.
 153.822 -     */
 153.823 -    @JavaScriptBody(args = "bits",
 153.824 -        body = 
 153.825 -          "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
 153.826 -        + "var e = ((bits >> 23) & 0xff);\n"
 153.827 -        + "if (e === 0xff) {\n"
 153.828 -        + "    if ((bits & 0x7fffff) === 0) {\n"
 153.829 -        + "        return (s > 0) ? Number.POSITIVE_INFINITY"
 153.830 -                              + " : Number.NEGATIVE_INFINITY;\n"
 153.831 -        + "    }\n"
 153.832 -        + "    return Number.NaN;\n"
 153.833 -        + "}\n"
 153.834 -        + "var m = (e == 0) ?\n"
 153.835 -        + "  (bits & 0x7fffff) << 1 :\n"
 153.836 -        + "  (bits & 0x7fffff) | 0x800000;\n"
 153.837 -        + "return s * m * Math.pow(2.0, e - 150);\n"
 153.838 -    )
 153.839 -    public static native float intBitsToFloat(int bits);
 153.840 -
 153.841 -    /**
 153.842 -     * Compares two {@code Float} objects numerically.  There are
 153.843 -     * two ways in which comparisons performed by this method differ
 153.844 -     * from those performed by the Java language numerical comparison
 153.845 -     * operators ({@code <, <=, ==, >=, >}) when
 153.846 -     * applied to primitive {@code float} values:
 153.847 -     *
 153.848 -     * <ul><li>
 153.849 -     *          {@code Float.NaN} is considered by this method to
 153.850 -     *          be equal to itself and greater than all other
 153.851 -     *          {@code float} values
 153.852 -     *          (including {@code Float.POSITIVE_INFINITY}).
 153.853 -     * <li>
 153.854 -     *          {@code 0.0f} is considered by this method to be greater
 153.855 -     *          than {@code -0.0f}.
 153.856 -     * </ul>
 153.857 -     *
 153.858 -     * This ensures that the <i>natural ordering</i> of {@code Float}
 153.859 -     * objects imposed by this method is <i>consistent with equals</i>.
 153.860 -     *
 153.861 -     * @param   anotherFloat   the {@code Float} to be compared.
 153.862 -     * @return  the value {@code 0} if {@code anotherFloat} is
 153.863 -     *          numerically equal to this {@code Float}; a value
 153.864 -     *          less than {@code 0} if this {@code Float}
 153.865 -     *          is numerically less than {@code anotherFloat};
 153.866 -     *          and a value greater than {@code 0} if this
 153.867 -     *          {@code Float} is numerically greater than
 153.868 -     *          {@code anotherFloat}.
 153.869 -     *
 153.870 -     * @since   1.2
 153.871 -     * @see Comparable#compareTo(Object)
 153.872 -     */
 153.873 -    public int compareTo(Float anotherFloat) {
 153.874 -        return Float.compare(value, anotherFloat.value);
 153.875 -    }
 153.876 -
 153.877 -    /**
 153.878 -     * Compares the two specified {@code float} values. The sign
 153.879 -     * of the integer value returned is the same as that of the
 153.880 -     * integer that would be returned by the call:
 153.881 -     * <pre>
 153.882 -     *    new Float(f1).compareTo(new Float(f2))
 153.883 -     * </pre>
 153.884 -     *
 153.885 -     * @param   f1        the first {@code float} to compare.
 153.886 -     * @param   f2        the second {@code float} to compare.
 153.887 -     * @return  the value {@code 0} if {@code f1} is
 153.888 -     *          numerically equal to {@code f2}; a value less than
 153.889 -     *          {@code 0} if {@code f1} is numerically less than
 153.890 -     *          {@code f2}; and a value greater than {@code 0}
 153.891 -     *          if {@code f1} is numerically greater than
 153.892 -     *          {@code f2}.
 153.893 -     * @since 1.4
 153.894 -     */
 153.895 -    public static int compare(float f1, float f2) {
 153.896 -        if (f1 < f2)
 153.897 -            return -1;           // Neither val is NaN, thisVal is smaller
 153.898 -        if (f1 > f2)
 153.899 -            return 1;            // Neither val is NaN, thisVal is larger
 153.900 -
 153.901 -        // Cannot use floatToRawIntBits because of possibility of NaNs.
 153.902 -        int thisBits    = Float.floatToIntBits(f1);
 153.903 -        int anotherBits = Float.floatToIntBits(f2);
 153.904 -
 153.905 -        return (thisBits == anotherBits ?  0 : // Values are equal
 153.906 -                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 153.907 -                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 153.908 -    }
 153.909 -
 153.910 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 153.911 -    private static final long serialVersionUID = -2671257302660747028L;
 153.912 -}
   154.1 --- a/emul/mini/src/main/java/java/lang/IllegalAccessError.java	Mon Feb 25 19:00:08 2013 +0100
   154.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   154.3 @@ -1,58 +0,0 @@
   154.4 -/*
   154.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   154.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   154.7 - *
   154.8 - * This code is free software; you can redistribute it and/or modify it
   154.9 - * under the terms of the GNU General Public License version 2 only, as
  154.10 - * published by the Free Software Foundation.  Oracle designates this
  154.11 - * particular file as subject to the "Classpath" exception as provided
  154.12 - * by Oracle in the LICENSE file that accompanied this code.
  154.13 - *
  154.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  154.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  154.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  154.17 - * version 2 for more details (a copy is included in the LICENSE file that
  154.18 - * accompanied this code).
  154.19 - *
  154.20 - * You should have received a copy of the GNU General Public License version
  154.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  154.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  154.23 - *
  154.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  154.25 - * or visit www.oracle.com if you need additional information or have any
  154.26 - * questions.
  154.27 - */
  154.28 -
  154.29 -package java.lang;
  154.30 -
  154.31 -/**
  154.32 - * Thrown if an application attempts to access or modify a field, or
  154.33 - * to call a method that it does not have access to.
  154.34 - * <p>
  154.35 - * Normally, this error is caught by the compiler; this error can
  154.36 - * only occur at run time if the definition of a class has
  154.37 - * incompatibly changed.
  154.38 - *
  154.39 - * @author  unascribed
  154.40 - * @since   JDK1.0
  154.41 - */
  154.42 -public class IllegalAccessError extends IncompatibleClassChangeError {
  154.43 -    private static final long serialVersionUID = -8988904074992417891L;
  154.44 -
  154.45 -    /**
  154.46 -     * Constructs an <code>IllegalAccessError</code> with no detail message.
  154.47 -     */
  154.48 -    public IllegalAccessError() {
  154.49 -        super();
  154.50 -    }
  154.51 -
  154.52 -    /**
  154.53 -     * Constructs an <code>IllegalAccessError</code> with the specified
  154.54 -     * detail message.
  154.55 -     *
  154.56 -     * @param   s   the detail message.
  154.57 -     */
  154.58 -    public IllegalAccessError(String s) {
  154.59 -        super(s);
  154.60 -    }
  154.61 -}
   155.1 --- a/emul/mini/src/main/java/java/lang/IllegalAccessException.java	Mon Feb 25 19:00:08 2013 +0100
   155.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   155.3 @@ -1,78 +0,0 @@
   155.4 -/*
   155.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   155.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   155.7 - *
   155.8 - * This code is free software; you can redistribute it and/or modify it
   155.9 - * under the terms of the GNU General Public License version 2 only, as
  155.10 - * published by the Free Software Foundation.  Oracle designates this
  155.11 - * particular file as subject to the "Classpath" exception as provided
  155.12 - * by Oracle in the LICENSE file that accompanied this code.
  155.13 - *
  155.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  155.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  155.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  155.17 - * version 2 for more details (a copy is included in the LICENSE file that
  155.18 - * accompanied this code).
  155.19 - *
  155.20 - * You should have received a copy of the GNU General Public License version
  155.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  155.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  155.23 - *
  155.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  155.25 - * or visit www.oracle.com if you need additional information or have any
  155.26 - * questions.
  155.27 - */
  155.28 -
  155.29 -package java.lang;
  155.30 -
  155.31 -/**
  155.32 - * An IllegalAccessException is thrown when an application tries
  155.33 - * to reflectively create an instance (other than an array),
  155.34 - * set or get a field, or invoke a method, but the currently
  155.35 - * executing method does not have access to the definition of
  155.36 - * the specified class, field, method or constructor.
  155.37 - *
  155.38 - * @author  unascribed
  155.39 - * @see     Class#newInstance()
  155.40 - * @see     java.lang.reflect.Field#set(Object, Object)
  155.41 - * @see     java.lang.reflect.Field#setBoolean(Object, boolean)
  155.42 - * @see     java.lang.reflect.Field#setByte(Object, byte)
  155.43 - * @see     java.lang.reflect.Field#setShort(Object, short)
  155.44 - * @see     java.lang.reflect.Field#setChar(Object, char)
  155.45 - * @see     java.lang.reflect.Field#setInt(Object, int)
  155.46 - * @see     java.lang.reflect.Field#setLong(Object, long)
  155.47 - * @see     java.lang.reflect.Field#setFloat(Object, float)
  155.48 - * @see     java.lang.reflect.Field#setDouble(Object, double)
  155.49 - * @see     java.lang.reflect.Field#get(Object)
  155.50 - * @see     java.lang.reflect.Field#getBoolean(Object)
  155.51 - * @see     java.lang.reflect.Field#getByte(Object)
  155.52 - * @see     java.lang.reflect.Field#getShort(Object)
  155.53 - * @see     java.lang.reflect.Field#getChar(Object)
  155.54 - * @see     java.lang.reflect.Field#getInt(Object)
  155.55 - * @see     java.lang.reflect.Field#getLong(Object)
  155.56 - * @see     java.lang.reflect.Field#getFloat(Object)
  155.57 - * @see     java.lang.reflect.Field#getDouble(Object)
  155.58 - * @see     java.lang.reflect.Method#invoke(Object, Object[])
  155.59 - * @see     java.lang.reflect.Constructor#newInstance(Object[])
  155.60 - * @since   JDK1.0
  155.61 - */
  155.62 -public class IllegalAccessException extends ReflectiveOperationException {
  155.63 -    private static final long serialVersionUID = 6616958222490762034L;
  155.64 -
  155.65 -    /**
  155.66 -     * Constructs an <code>IllegalAccessException</code> without a
  155.67 -     * detail message.
  155.68 -     */
  155.69 -    public IllegalAccessException() {
  155.70 -        super();
  155.71 -    }
  155.72 -
  155.73 -    /**
  155.74 -     * Constructs an <code>IllegalAccessException</code> with a detail message.
  155.75 -     *
  155.76 -     * @param   s   the detail message.
  155.77 -     */
  155.78 -    public IllegalAccessException(String s) {
  155.79 -        super(s);
  155.80 -    }
  155.81 -}
   156.1 --- a/emul/mini/src/main/java/java/lang/IllegalArgumentException.java	Mon Feb 25 19:00:08 2013 +0100
   156.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   156.3 @@ -1,95 +0,0 @@
   156.4 -/*
   156.5 - * Copyright (c) 1994, 2003, 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 - * Thrown to indicate that a method has been passed an illegal or
  156.33 - * inappropriate argument.
  156.34 - *
  156.35 - * @author  unascribed
  156.36 - * @see     java.lang.Thread#setPriority(int)
  156.37 - * @since   JDK1.0
  156.38 - */
  156.39 -public
  156.40 -class IllegalArgumentException extends RuntimeException {
  156.41 -    /**
  156.42 -     * Constructs an <code>IllegalArgumentException</code> with no
  156.43 -     * detail message.
  156.44 -     */
  156.45 -    public IllegalArgumentException() {
  156.46 -        super();
  156.47 -    }
  156.48 -
  156.49 -    /**
  156.50 -     * Constructs an <code>IllegalArgumentException</code> with the
  156.51 -     * specified detail message.
  156.52 -     *
  156.53 -     * @param   s   the detail message.
  156.54 -     */
  156.55 -    public IllegalArgumentException(String s) {
  156.56 -        super(s);
  156.57 -    }
  156.58 -
  156.59 -    /**
  156.60 -     * Constructs a new exception with the specified detail message and
  156.61 -     * cause.
  156.62 -     *
  156.63 -     * <p>Note that the detail message associated with <code>cause</code> is
  156.64 -     * <i>not</i> automatically incorporated in this exception's detail
  156.65 -     * message.
  156.66 -     *
  156.67 -     * @param  message the detail message (which is saved for later retrieval
  156.68 -     *         by the {@link Throwable#getMessage()} method).
  156.69 -     * @param  cause the cause (which is saved for later retrieval by the
  156.70 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  156.71 -     *         is permitted, and indicates that the cause is nonexistent or
  156.72 -     *         unknown.)
  156.73 -     * @since 1.5
  156.74 -     */
  156.75 -    public IllegalArgumentException(String message, Throwable cause) {
  156.76 -        super(message, cause);
  156.77 -    }
  156.78 -
  156.79 -    /**
  156.80 -     * Constructs a new exception with the specified cause and a detail
  156.81 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  156.82 -     * typically contains the class and detail message of <tt>cause</tt>).
  156.83 -     * This constructor is useful for exceptions that are little more than
  156.84 -     * wrappers for other throwables (for example, {@link
  156.85 -     * java.security.PrivilegedActionException}).
  156.86 -     *
  156.87 -     * @param  cause the cause (which is saved for later retrieval by the
  156.88 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  156.89 -     *         permitted, and indicates that the cause is nonexistent or
  156.90 -     *         unknown.)
  156.91 -     * @since  1.5
  156.92 -     */
  156.93 -    public IllegalArgumentException(Throwable cause) {
  156.94 -        super(cause);
  156.95 -    }
  156.96 -
  156.97 -    private static final long serialVersionUID = -5365630128856068164L;
  156.98 -}
   157.1 --- a/emul/mini/src/main/java/java/lang/IllegalStateException.java	Mon Feb 25 19:00:08 2013 +0100
   157.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   157.3 @@ -1,97 +0,0 @@
   157.4 -/*
   157.5 - * Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
   157.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   157.7 - *
   157.8 - * This code is free software; you can redistribute it and/or modify it
   157.9 - * under the terms of the GNU General Public License version 2 only, as
  157.10 - * published by the Free Software Foundation.  Oracle designates this
  157.11 - * particular file as subject to the "Classpath" exception as provided
  157.12 - * by Oracle in the LICENSE file that accompanied this code.
  157.13 - *
  157.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  157.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  157.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  157.17 - * version 2 for more details (a copy is included in the LICENSE file that
  157.18 - * accompanied this code).
  157.19 - *
  157.20 - * You should have received a copy of the GNU General Public License version
  157.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  157.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  157.23 - *
  157.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  157.25 - * or visit www.oracle.com if you need additional information or have any
  157.26 - * questions.
  157.27 - */
  157.28 -
  157.29 -package java.lang;
  157.30 -
  157.31 -/**
  157.32 - * Signals that a method has been invoked at an illegal or
  157.33 - * inappropriate time.  In other words, the Java environment or
  157.34 - * Java application is not in an appropriate state for the requested
  157.35 - * operation.
  157.36 - *
  157.37 - * @author  Jonni Kanerva
  157.38 - * @since   JDK1.1
  157.39 - */
  157.40 -public
  157.41 -class IllegalStateException extends RuntimeException {
  157.42 -    /**
  157.43 -     * Constructs an IllegalStateException with no detail message.
  157.44 -     * A detail message is a String that describes this particular exception.
  157.45 -     */
  157.46 -    public IllegalStateException() {
  157.47 -        super();
  157.48 -    }
  157.49 -
  157.50 -    /**
  157.51 -     * Constructs an IllegalStateException with the specified detail
  157.52 -     * message.  A detail message is a String that describes this particular
  157.53 -     * exception.
  157.54 -     *
  157.55 -     * @param s the String that contains a detailed message
  157.56 -     */
  157.57 -    public IllegalStateException(String s) {
  157.58 -        super(s);
  157.59 -    }
  157.60 -
  157.61 -    /**
  157.62 -     * Constructs a new exception with the specified detail message and
  157.63 -     * cause.
  157.64 -     *
  157.65 -     * <p>Note that the detail message associated with <code>cause</code> is
  157.66 -     * <i>not</i> automatically incorporated in this exception's detail
  157.67 -     * message.
  157.68 -     *
  157.69 -     * @param  message the detail message (which is saved for later retrieval
  157.70 -     *         by the {@link Throwable#getMessage()} method).
  157.71 -     * @param  cause the cause (which is saved for later retrieval by the
  157.72 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  157.73 -     *         is permitted, and indicates that the cause is nonexistent or
  157.74 -     *         unknown.)
  157.75 -     * @since 1.5
  157.76 -     */
  157.77 -    public IllegalStateException(String message, Throwable cause) {
  157.78 -        super(message, cause);
  157.79 -    }
  157.80 -
  157.81 -    /**
  157.82 -     * Constructs a new exception with the specified cause and a detail
  157.83 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  157.84 -     * typically contains the class and detail message of <tt>cause</tt>).
  157.85 -     * This constructor is useful for exceptions that are little more than
  157.86 -     * wrappers for other throwables (for example, {@link
  157.87 -     * java.security.PrivilegedActionException}).
  157.88 -     *
  157.89 -     * @param  cause the cause (which is saved for later retrieval by the
  157.90 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  157.91 -     *         permitted, and indicates that the cause is nonexistent or
  157.92 -     *         unknown.)
  157.93 -     * @since  1.5
  157.94 -     */
  157.95 -    public IllegalStateException(Throwable cause) {
  157.96 -        super(cause);
  157.97 -    }
  157.98 -
  157.99 -    static final long serialVersionUID = -1848914673093119416L;
 157.100 -}
   158.1 --- a/emul/mini/src/main/java/java/lang/IncompatibleClassChangeError.java	Mon Feb 25 19:00:08 2013 +0100
   158.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.3 @@ -1,57 +0,0 @@
   158.4 -/*
   158.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   158.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   158.7 - *
   158.8 - * This code is free software; you can redistribute it and/or modify it
   158.9 - * under the terms of the GNU General Public License version 2 only, as
  158.10 - * published by the Free Software Foundation.  Oracle designates this
  158.11 - * particular file as subject to the "Classpath" exception as provided
  158.12 - * by Oracle in the LICENSE file that accompanied this code.
  158.13 - *
  158.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  158.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  158.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  158.17 - * version 2 for more details (a copy is included in the LICENSE file that
  158.18 - * accompanied this code).
  158.19 - *
  158.20 - * You should have received a copy of the GNU General Public License version
  158.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  158.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  158.23 - *
  158.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  158.25 - * or visit www.oracle.com if you need additional information or have any
  158.26 - * questions.
  158.27 - */
  158.28 -
  158.29 -package java.lang;
  158.30 -
  158.31 -/**
  158.32 - * Thrown when an incompatible class change has occurred to some class
  158.33 - * definition. The definition of some class, on which the currently
  158.34 - * executing method depends, has since changed.
  158.35 - *
  158.36 - * @author  unascribed
  158.37 - * @since   JDK1.0
  158.38 - */
  158.39 -public
  158.40 -class IncompatibleClassChangeError extends LinkageError {
  158.41 -    private static final long serialVersionUID = -4914975503642802119L;
  158.42 -
  158.43 -    /**
  158.44 -     * Constructs an <code>IncompatibleClassChangeError</code> with no
  158.45 -     * detail message.
  158.46 -     */
  158.47 -    public IncompatibleClassChangeError () {
  158.48 -        super();
  158.49 -    }
  158.50 -
  158.51 -    /**
  158.52 -     * Constructs an <code>IncompatibleClassChangeError</code> with the
  158.53 -     * specified detail message.
  158.54 -     *
  158.55 -     * @param   s   the detail message.
  158.56 -     */
  158.57 -    public IncompatibleClassChangeError(String s) {
  158.58 -        super(s);
  158.59 -    }
  158.60 -}
   159.1 --- a/emul/mini/src/main/java/java/lang/IndexOutOfBoundsException.java	Mon Feb 25 19:00:08 2013 +0100
   159.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.3 @@ -1,58 +0,0 @@
   159.4 -/*
   159.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   159.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   159.7 - *
   159.8 - * This code is free software; you can redistribute it and/or modify it
   159.9 - * under the terms of the GNU General Public License version 2 only, as
  159.10 - * published by the Free Software Foundation.  Oracle designates this
  159.11 - * particular file as subject to the "Classpath" exception as provided
  159.12 - * by Oracle in the LICENSE file that accompanied this code.
  159.13 - *
  159.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  159.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  159.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  159.17 - * version 2 for more details (a copy is included in the LICENSE file that
  159.18 - * accompanied this code).
  159.19 - *
  159.20 - * You should have received a copy of the GNU General Public License version
  159.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  159.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  159.23 - *
  159.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  159.25 - * or visit www.oracle.com if you need additional information or have any
  159.26 - * questions.
  159.27 - */
  159.28 -
  159.29 -package java.lang;
  159.30 -
  159.31 -/**
  159.32 - * Thrown to indicate that an index of some sort (such as to an array, to a
  159.33 - * string, or to a vector) is out of range.
  159.34 - * <p>
  159.35 - * Applications can subclass this class to indicate similar exceptions.
  159.36 - *
  159.37 - * @author  Frank Yellin
  159.38 - * @since   JDK1.0
  159.39 - */
  159.40 -public
  159.41 -class IndexOutOfBoundsException extends RuntimeException {
  159.42 -    private static final long serialVersionUID = 234122996006267687L;
  159.43 -
  159.44 -    /**
  159.45 -     * Constructs an <code>IndexOutOfBoundsException</code> with no
  159.46 -     * detail message.
  159.47 -     */
  159.48 -    public IndexOutOfBoundsException() {
  159.49 -        super();
  159.50 -    }
  159.51 -
  159.52 -    /**
  159.53 -     * Constructs an <code>IndexOutOfBoundsException</code> with the
  159.54 -     * specified detail message.
  159.55 -     *
  159.56 -     * @param   s   the detail message.
  159.57 -     */
  159.58 -    public IndexOutOfBoundsException(String s) {
  159.59 -        super(s);
  159.60 -    }
  159.61 -}
   160.1 --- a/emul/mini/src/main/java/java/lang/InstantiationException.java	Mon Feb 25 19:00:08 2013 +0100
   160.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.3 @@ -1,65 +0,0 @@
   160.4 -/*
   160.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   160.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   160.7 - *
   160.8 - * This code is free software; you can redistribute it and/or modify it
   160.9 - * under the terms of the GNU General Public License version 2 only, as
  160.10 - * published by the Free Software Foundation.  Oracle designates this
  160.11 - * particular file as subject to the "Classpath" exception as provided
  160.12 - * by Oracle in the LICENSE file that accompanied this code.
  160.13 - *
  160.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  160.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  160.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  160.17 - * version 2 for more details (a copy is included in the LICENSE file that
  160.18 - * accompanied this code).
  160.19 - *
  160.20 - * You should have received a copy of the GNU General Public License version
  160.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  160.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  160.23 - *
  160.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  160.25 - * or visit www.oracle.com if you need additional information or have any
  160.26 - * questions.
  160.27 - */
  160.28 -
  160.29 -package java.lang;
  160.30 -
  160.31 -/**
  160.32 - * Thrown when an application tries to create an instance of a class
  160.33 - * using the {@code newInstance} method in class
  160.34 - * {@code Class}, but the specified class object cannot be
  160.35 - * instantiated.  The instantiation can fail for a variety of
  160.36 - * reasons including but not limited to:
  160.37 - *
  160.38 - * <ul>
  160.39 - * <li> the class object represents an abstract class, an interface,
  160.40 - *      an array class, a primitive type, or {@code void}
  160.41 - * <li> the class has no nullary constructor
  160.42 - *</ul>
  160.43 - *
  160.44 - * @author  unascribed
  160.45 - * @see     java.lang.Class#newInstance()
  160.46 - * @since   JDK1.0
  160.47 - */
  160.48 -public
  160.49 -class InstantiationException extends ReflectiveOperationException {
  160.50 -    private static final long serialVersionUID = -8441929162975509110L;
  160.51 -
  160.52 -    /**
  160.53 -     * Constructs an {@code InstantiationException} with no detail message.
  160.54 -     */
  160.55 -    public InstantiationException() {
  160.56 -        super();
  160.57 -    }
  160.58 -
  160.59 -    /**
  160.60 -     * Constructs an {@code InstantiationException} with the
  160.61 -     * specified detail message.
  160.62 -     *
  160.63 -     * @param   s   the detail message.
  160.64 -     */
  160.65 -    public InstantiationException(String s) {
  160.66 -        super(s);
  160.67 -    }
  160.68 -}
   161.1 --- a/emul/mini/src/main/java/java/lang/Integer.java	Mon Feb 25 19:00:08 2013 +0100
   161.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.3 @@ -1,1246 +0,0 @@
   161.4 -/*
   161.5 - * Copyright (c) 1994, 2010, 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;
  161.30 -
  161.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  161.32 -
  161.33 -/**
  161.34 - * The {@code Integer} class wraps a value of the primitive type
  161.35 - * {@code int} in an object. An object of type {@code Integer}
  161.36 - * contains a single field whose type is {@code int}.
  161.37 - *
  161.38 - * <p>In addition, this class provides several methods for converting
  161.39 - * an {@code int} to a {@code String} and a {@code String} to an
  161.40 - * {@code int}, as well as other constants and methods useful when
  161.41 - * dealing with an {@code int}.
  161.42 - *
  161.43 - * <p>Implementation note: The implementations of the "bit twiddling"
  161.44 - * methods (such as {@link #highestOneBit(int) highestOneBit} and
  161.45 - * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  161.46 - * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  161.47 - * Delight</i>, (Addison Wesley, 2002).
  161.48 - *
  161.49 - * @author  Lee Boynton
  161.50 - * @author  Arthur van Hoff
  161.51 - * @author  Josh Bloch
  161.52 - * @author  Joseph D. Darcy
  161.53 - * @since JDK1.0
  161.54 - */
  161.55 -public final class Integer extends Number implements Comparable<Integer> {
  161.56 -    /**
  161.57 -     * A constant holding the minimum value an {@code int} can
  161.58 -     * have, -2<sup>31</sup>.
  161.59 -     */
  161.60 -    public static final int   MIN_VALUE = 0x80000000;
  161.61 -
  161.62 -    /**
  161.63 -     * A constant holding the maximum value an {@code int} can
  161.64 -     * have, 2<sup>31</sup>-1.
  161.65 -     */
  161.66 -    public static final int   MAX_VALUE = 0x7fffffff;
  161.67 -
  161.68 -    /**
  161.69 -     * The {@code Class} instance representing the primitive type
  161.70 -     * {@code int}.
  161.71 -     *
  161.72 -     * @since   JDK1.1
  161.73 -     */
  161.74 -    public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
  161.75 -
  161.76 -    /**
  161.77 -     * All possible chars for representing a number as a String
  161.78 -     */
  161.79 -    final static char[] digits = {
  161.80 -        '0' , '1' , '2' , '3' , '4' , '5' ,
  161.81 -        '6' , '7' , '8' , '9' , 'a' , 'b' ,
  161.82 -        'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
  161.83 -        'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
  161.84 -        'o' , 'p' , 'q' , 'r' , 's' , 't' ,
  161.85 -        'u' , 'v' , 'w' , 'x' , 'y' , 'z'
  161.86 -    };
  161.87 -
  161.88 -    /**
  161.89 -     * Returns a string representation of the first argument in the
  161.90 -     * radix specified by the second argument.
  161.91 -     *
  161.92 -     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  161.93 -     * or larger than {@code Character.MAX_RADIX}, then the radix
  161.94 -     * {@code 10} is used instead.
  161.95 -     *
  161.96 -     * <p>If the first argument is negative, the first element of the
  161.97 -     * result is the ASCII minus character {@code '-'}
  161.98 -     * (<code>'&#92;u002D'</code>). If the first argument is not
  161.99 -     * negative, no sign character appears in the result.
 161.100 -     *
 161.101 -     * <p>The remaining characters of the result represent the magnitude
 161.102 -     * of the first argument. If the magnitude is zero, it is
 161.103 -     * represented by a single zero character {@code '0'}
 161.104 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 161.105 -     * the representation of the magnitude will not be the zero
 161.106 -     * character.  The following ASCII characters are used as digits:
 161.107 -     *
 161.108 -     * <blockquote>
 161.109 -     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
 161.110 -     * </blockquote>
 161.111 -     *
 161.112 -     * These are <code>'&#92;u0030'</code> through
 161.113 -     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 161.114 -     * <code>'&#92;u007A'</code>. If {@code radix} is
 161.115 -     * <var>N</var>, then the first <var>N</var> of these characters
 161.116 -     * are used as radix-<var>N</var> digits in the order shown. Thus,
 161.117 -     * the digits for hexadecimal (radix 16) are
 161.118 -     * {@code 0123456789abcdef}. If uppercase letters are
 161.119 -     * desired, the {@link java.lang.String#toUpperCase()} method may
 161.120 -     * be called on the result:
 161.121 -     *
 161.122 -     * <blockquote>
 161.123 -     *  {@code Integer.toString(n, 16).toUpperCase()}
 161.124 -     * </blockquote>
 161.125 -     *
 161.126 -     * @param   i       an integer to be converted to a string.
 161.127 -     * @param   radix   the radix to use in the string representation.
 161.128 -     * @return  a string representation of the argument in the specified radix.
 161.129 -     * @see     java.lang.Character#MAX_RADIX
 161.130 -     * @see     java.lang.Character#MIN_RADIX
 161.131 -     */
 161.132 -    public static String toString(int i, int radix) {
 161.133 -
 161.134 -        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 161.135 -            radix = 10;
 161.136 -
 161.137 -        /* Use the faster version */
 161.138 -        if (radix == 10) {
 161.139 -            return toString(i);
 161.140 -        }
 161.141 -
 161.142 -        char buf[] = new char[33];
 161.143 -        boolean negative = (i < 0);
 161.144 -        int charPos = 32;
 161.145 -
 161.146 -        if (!negative) {
 161.147 -            i = -i;
 161.148 -        }
 161.149 -
 161.150 -        while (i <= -radix) {
 161.151 -            buf[charPos--] = digits[-(i % radix)];
 161.152 -            i = i / radix;
 161.153 -        }
 161.154 -        buf[charPos] = digits[-i];
 161.155 -
 161.156 -        if (negative) {
 161.157 -            buf[--charPos] = '-';
 161.158 -        }
 161.159 -
 161.160 -        return new String(buf, charPos, (33 - charPos));
 161.161 -    }
 161.162 -
 161.163 -    /**
 161.164 -     * Returns a string representation of the integer argument as an
 161.165 -     * unsigned integer in base&nbsp;16.
 161.166 -     *
 161.167 -     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 161.168 -     * if the argument is negative; otherwise, it is equal to the
 161.169 -     * argument.  This value is converted to a string of ASCII digits
 161.170 -     * in hexadecimal (base&nbsp;16) with no extra leading
 161.171 -     * {@code 0}s. If the unsigned magnitude is zero, it is
 161.172 -     * represented by a single zero character {@code '0'}
 161.173 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 161.174 -     * the representation of the unsigned magnitude will not be the
 161.175 -     * zero character. The following characters are used as
 161.176 -     * hexadecimal digits:
 161.177 -     *
 161.178 -     * <blockquote>
 161.179 -     *  {@code 0123456789abcdef}
 161.180 -     * </blockquote>
 161.181 -     *
 161.182 -     * These are the characters <code>'&#92;u0030'</code> through
 161.183 -     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 161.184 -     * <code>'&#92;u0066'</code>. If uppercase letters are
 161.185 -     * desired, the {@link java.lang.String#toUpperCase()} method may
 161.186 -     * be called on the result:
 161.187 -     *
 161.188 -     * <blockquote>
 161.189 -     *  {@code Integer.toHexString(n).toUpperCase()}
 161.190 -     * </blockquote>
 161.191 -     *
 161.192 -     * @param   i   an integer to be converted to a string.
 161.193 -     * @return  the string representation of the unsigned integer value
 161.194 -     *          represented by the argument in hexadecimal (base&nbsp;16).
 161.195 -     * @since   JDK1.0.2
 161.196 -     */
 161.197 -    public static String toHexString(int i) {
 161.198 -        return toUnsignedString(i, 4);
 161.199 -    }
 161.200 -
 161.201 -    /**
 161.202 -     * Returns a string representation of the integer argument as an
 161.203 -     * unsigned integer in base&nbsp;8.
 161.204 -     *
 161.205 -     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 161.206 -     * if the argument is negative; otherwise, it is equal to the
 161.207 -     * argument.  This value is converted to a string of ASCII digits
 161.208 -     * in octal (base&nbsp;8) with no extra leading {@code 0}s.
 161.209 -     *
 161.210 -     * <p>If the unsigned magnitude is zero, it is represented by a
 161.211 -     * single zero character {@code '0'}
 161.212 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 161.213 -     * the representation of the unsigned magnitude will not be the
 161.214 -     * zero character. The following characters are used as octal
 161.215 -     * digits:
 161.216 -     *
 161.217 -     * <blockquote>
 161.218 -     * {@code 01234567}
 161.219 -     * </blockquote>
 161.220 -     *
 161.221 -     * These are the characters <code>'&#92;u0030'</code> through
 161.222 -     * <code>'&#92;u0037'</code>.
 161.223 -     *
 161.224 -     * @param   i   an integer to be converted to a string.
 161.225 -     * @return  the string representation of the unsigned integer value
 161.226 -     *          represented by the argument in octal (base&nbsp;8).
 161.227 -     * @since   JDK1.0.2
 161.228 -     */
 161.229 -    public static String toOctalString(int i) {
 161.230 -        return toUnsignedString(i, 3);
 161.231 -    }
 161.232 -
 161.233 -    /**
 161.234 -     * Returns a string representation of the integer argument as an
 161.235 -     * unsigned integer in base&nbsp;2.
 161.236 -     *
 161.237 -     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 161.238 -     * if the argument is negative; otherwise it is equal to the
 161.239 -     * argument.  This value is converted to a string of ASCII digits
 161.240 -     * in binary (base&nbsp;2) with no extra leading {@code 0}s.
 161.241 -     * If the unsigned magnitude is zero, it is represented by a
 161.242 -     * single zero character {@code '0'}
 161.243 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 161.244 -     * the representation of the unsigned magnitude will not be the
 161.245 -     * zero character. The characters {@code '0'}
 161.246 -     * (<code>'&#92;u0030'</code>) and {@code '1'}
 161.247 -     * (<code>'&#92;u0031'</code>) are used as binary digits.
 161.248 -     *
 161.249 -     * @param   i   an integer to be converted to a string.
 161.250 -     * @return  the string representation of the unsigned integer value
 161.251 -     *          represented by the argument in binary (base&nbsp;2).
 161.252 -     * @since   JDK1.0.2
 161.253 -     */
 161.254 -    public static String toBinaryString(int i) {
 161.255 -        return toUnsignedString(i, 1);
 161.256 -    }
 161.257 -
 161.258 -    /**
 161.259 -     * Convert the integer to an unsigned number.
 161.260 -     */
 161.261 -    private static String toUnsignedString(int i, int shift) {
 161.262 -        char[] buf = new char[32];
 161.263 -        int charPos = 32;
 161.264 -        int radix = 1 << shift;
 161.265 -        int mask = radix - 1;
 161.266 -        do {
 161.267 -            buf[--charPos] = digits[i & mask];
 161.268 -            i >>>= shift;
 161.269 -        } while (i != 0);
 161.270 -
 161.271 -        return new String(buf, charPos, (32 - charPos));
 161.272 -    }
 161.273 -
 161.274 -
 161.275 -    final static char [] DigitTens = {
 161.276 -        '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
 161.277 -        '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
 161.278 -        '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
 161.279 -        '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
 161.280 -        '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
 161.281 -        '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
 161.282 -        '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
 161.283 -        '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
 161.284 -        '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
 161.285 -        '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
 161.286 -        } ;
 161.287 -
 161.288 -    final static char [] DigitOnes = {
 161.289 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.290 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.291 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.292 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.293 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.294 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.295 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.296 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.297 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.298 -        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 161.299 -        } ;
 161.300 -
 161.301 -        // I use the "invariant division by multiplication" trick to
 161.302 -        // accelerate Integer.toString.  In particular we want to
 161.303 -        // avoid division by 10.
 161.304 -        //
 161.305 -        // The "trick" has roughly the same performance characteristics
 161.306 -        // as the "classic" Integer.toString code on a non-JIT VM.
 161.307 -        // The trick avoids .rem and .div calls but has a longer code
 161.308 -        // path and is thus dominated by dispatch overhead.  In the
 161.309 -        // JIT case the dispatch overhead doesn't exist and the
 161.310 -        // "trick" is considerably faster than the classic code.
 161.311 -        //
 161.312 -        // TODO-FIXME: convert (x * 52429) into the equiv shift-add
 161.313 -        // sequence.
 161.314 -        //
 161.315 -        // RE:  Division by Invariant Integers using Multiplication
 161.316 -        //      T Gralund, P Montgomery
 161.317 -        //      ACM PLDI 1994
 161.318 -        //
 161.319 -
 161.320 -    /**
 161.321 -     * Returns a {@code String} object representing the
 161.322 -     * specified integer. The argument is converted to signed decimal
 161.323 -     * representation and returned as a string, exactly as if the
 161.324 -     * argument and radix 10 were given as arguments to the {@link
 161.325 -     * #toString(int, int)} method.
 161.326 -     *
 161.327 -     * @param   i   an integer to be converted.
 161.328 -     * @return  a string representation of the argument in base&nbsp;10.
 161.329 -     */
 161.330 -    @JavaScriptBody(args = "i", body = "return i.toString();")
 161.331 -    public static String toString(int i) {
 161.332 -        if (i == Integer.MIN_VALUE)
 161.333 -            return "-2147483648";
 161.334 -        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 161.335 -        char[] buf = new char[size];
 161.336 -        getChars(i, size, buf);
 161.337 -        return new String(buf, 0, size);
 161.338 -    }
 161.339 -
 161.340 -    /**
 161.341 -     * Places characters representing the integer i into the
 161.342 -     * character array buf. The characters are placed into
 161.343 -     * the buffer backwards starting with the least significant
 161.344 -     * digit at the specified index (exclusive), and working
 161.345 -     * backwards from there.
 161.346 -     *
 161.347 -     * Will fail if i == Integer.MIN_VALUE
 161.348 -     */
 161.349 -    static void getChars(int i, int index, char[] buf) {
 161.350 -        int q, r;
 161.351 -        int charPos = index;
 161.352 -        char sign = 0;
 161.353 -
 161.354 -        if (i < 0) {
 161.355 -            sign = '-';
 161.356 -            i = -i;
 161.357 -        }
 161.358 -
 161.359 -        // Generate two digits per iteration
 161.360 -        while (i >= 65536) {
 161.361 -            q = i / 100;
 161.362 -        // really: r = i - (q * 100);
 161.363 -            r = i - ((q << 6) + (q << 5) + (q << 2));
 161.364 -            i = q;
 161.365 -            buf [--charPos] = DigitOnes[r];
 161.366 -            buf [--charPos] = DigitTens[r];
 161.367 -        }
 161.368 -
 161.369 -        // Fall thru to fast mode for smaller numbers
 161.370 -        // assert(i <= 65536, i);
 161.371 -        for (;;) {
 161.372 -            q = (i * 52429) >>> (16+3);
 161.373 -            r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
 161.374 -            buf [--charPos] = digits [r];
 161.375 -            i = q;
 161.376 -            if (i == 0) break;
 161.377 -        }
 161.378 -        if (sign != 0) {
 161.379 -            buf [--charPos] = sign;
 161.380 -        }
 161.381 -    }
 161.382 -
 161.383 -    final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
 161.384 -                                      99999999, 999999999, Integer.MAX_VALUE };
 161.385 -
 161.386 -    // Requires positive x
 161.387 -    static int stringSize(int x) {
 161.388 -        for (int i=0; ; i++)
 161.389 -            if (x <= sizeTable[i])
 161.390 -                return i+1;
 161.391 -    }
 161.392 -
 161.393 -    /**
 161.394 -     * Parses the string argument as a signed integer in the radix
 161.395 -     * specified by the second argument. The characters in the string
 161.396 -     * must all be digits of the specified radix (as determined by
 161.397 -     * whether {@link java.lang.Character#digit(char, int)} returns a
 161.398 -     * nonnegative value), except that the first character may be an
 161.399 -     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 161.400 -     * indicate a negative value or an ASCII plus sign {@code '+'}
 161.401 -     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 161.402 -     * resulting integer value is returned.
 161.403 -     *
 161.404 -     * <p>An exception of type {@code NumberFormatException} is
 161.405 -     * thrown if any of the following situations occurs:
 161.406 -     * <ul>
 161.407 -     * <li>The first argument is {@code null} or is a string of
 161.408 -     * length zero.
 161.409 -     *
 161.410 -     * <li>The radix is either smaller than
 161.411 -     * {@link java.lang.Character#MIN_RADIX} or
 161.412 -     * larger than {@link java.lang.Character#MAX_RADIX}.
 161.413 -     *
 161.414 -     * <li>Any character of the string is not a digit of the specified
 161.415 -     * radix, except that the first character may be a minus sign
 161.416 -     * {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 161.417 -     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 161.418 -     * string is longer than length 1.
 161.419 -     *
 161.420 -     * <li>The value represented by the string is not a value of type
 161.421 -     * {@code int}.
 161.422 -     * </ul>
 161.423 -     *
 161.424 -     * <p>Examples:
 161.425 -     * <blockquote><pre>
 161.426 -     * parseInt("0", 10) returns 0
 161.427 -     * parseInt("473", 10) returns 473
 161.428 -     * parseInt("+42", 10) returns 42
 161.429 -     * parseInt("-0", 10) returns 0
 161.430 -     * parseInt("-FF", 16) returns -255
 161.431 -     * parseInt("1100110", 2) returns 102
 161.432 -     * parseInt("2147483647", 10) returns 2147483647
 161.433 -     * parseInt("-2147483648", 10) returns -2147483648
 161.434 -     * parseInt("2147483648", 10) throws a NumberFormatException
 161.435 -     * parseInt("99", 8) throws a NumberFormatException
 161.436 -     * parseInt("Kona", 10) throws a NumberFormatException
 161.437 -     * parseInt("Kona", 27) returns 411787
 161.438 -     * </pre></blockquote>
 161.439 -     *
 161.440 -     * @param      s   the {@code String} containing the integer
 161.441 -     *                  representation to be parsed
 161.442 -     * @param      radix   the radix to be used while parsing {@code s}.
 161.443 -     * @return     the integer represented by the string argument in the
 161.444 -     *             specified radix.
 161.445 -     * @exception  NumberFormatException if the {@code String}
 161.446 -     *             does not contain a parsable {@code int}.
 161.447 -     */
 161.448 -    @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
 161.449 -    public static int parseInt(String s, int radix)
 161.450 -                throws NumberFormatException
 161.451 -    {
 161.452 -        /*
 161.453 -         * WARNING: This method may be invoked early during VM initialization
 161.454 -         * before IntegerCache is initialized. Care must be taken to not use
 161.455 -         * the valueOf method.
 161.456 -         */
 161.457 -
 161.458 -        if (s == null) {
 161.459 -            throw new NumberFormatException("null");
 161.460 -        }
 161.461 -
 161.462 -        if (radix < Character.MIN_RADIX) {
 161.463 -            throw new NumberFormatException("radix " + radix +
 161.464 -                                            " less than Character.MIN_RADIX");
 161.465 -        }
 161.466 -
 161.467 -        if (radix > Character.MAX_RADIX) {
 161.468 -            throw new NumberFormatException("radix " + radix +
 161.469 -                                            " greater than Character.MAX_RADIX");
 161.470 -        }
 161.471 -
 161.472 -        int result = 0;
 161.473 -        boolean negative = false;
 161.474 -        int i = 0, len = s.length();
 161.475 -        int limit = -Integer.MAX_VALUE;
 161.476 -        int multmin;
 161.477 -        int digit;
 161.478 -
 161.479 -        if (len > 0) {
 161.480 -            char firstChar = s.charAt(0);
 161.481 -            if (firstChar < '0') { // Possible leading "+" or "-"
 161.482 -                if (firstChar == '-') {
 161.483 -                    negative = true;
 161.484 -                    limit = Integer.MIN_VALUE;
 161.485 -                } else if (firstChar != '+')
 161.486 -                    throw NumberFormatException.forInputString(s);
 161.487 -
 161.488 -                if (len == 1) // Cannot have lone "+" or "-"
 161.489 -                    throw NumberFormatException.forInputString(s);
 161.490 -                i++;
 161.491 -            }
 161.492 -            multmin = limit / radix;
 161.493 -            while (i < len) {
 161.494 -                // Accumulating negatively avoids surprises near MAX_VALUE
 161.495 -                digit = Character.digit(s.charAt(i++),radix);
 161.496 -                if (digit < 0) {
 161.497 -                    throw NumberFormatException.forInputString(s);
 161.498 -                }
 161.499 -                if (result < multmin) {
 161.500 -                    throw NumberFormatException.forInputString(s);
 161.501 -                }
 161.502 -                result *= radix;
 161.503 -                if (result < limit + digit) {
 161.504 -                    throw NumberFormatException.forInputString(s);
 161.505 -                }
 161.506 -                result -= digit;
 161.507 -            }
 161.508 -        } else {
 161.509 -            throw NumberFormatException.forInputString(s);
 161.510 -        }
 161.511 -        return negative ? result : -result;
 161.512 -    }
 161.513 -
 161.514 -    /**
 161.515 -     * Parses the string argument as a signed decimal integer. The
 161.516 -     * characters in the string must all be decimal digits, except
 161.517 -     * that the first character may be an ASCII minus sign {@code '-'}
 161.518 -     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 161.519 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 161.520 -     * indicate a positive value. The resulting integer value is
 161.521 -     * returned, exactly as if the argument and the radix 10 were
 161.522 -     * given as arguments to the {@link #parseInt(java.lang.String,
 161.523 -     * int)} method.
 161.524 -     *
 161.525 -     * @param s    a {@code String} containing the {@code int}
 161.526 -     *             representation to be parsed
 161.527 -     * @return     the integer value represented by the argument in decimal.
 161.528 -     * @exception  NumberFormatException  if the string does not contain a
 161.529 -     *               parsable integer.
 161.530 -     */
 161.531 -    public static int parseInt(String s) throws NumberFormatException {
 161.532 -        return parseInt(s,10);
 161.533 -    }
 161.534 -
 161.535 -    /**
 161.536 -     * Returns an {@code Integer} object holding the value
 161.537 -     * extracted from the specified {@code String} when parsed
 161.538 -     * with the radix given by the second argument. The first argument
 161.539 -     * is interpreted as representing a signed integer in the radix
 161.540 -     * specified by the second argument, exactly as if the arguments
 161.541 -     * were given to the {@link #parseInt(java.lang.String, int)}
 161.542 -     * method. The result is an {@code Integer} object that
 161.543 -     * represents the integer value specified by the string.
 161.544 -     *
 161.545 -     * <p>In other words, this method returns an {@code Integer}
 161.546 -     * object equal to the value of:
 161.547 -     *
 161.548 -     * <blockquote>
 161.549 -     *  {@code new Integer(Integer.parseInt(s, radix))}
 161.550 -     * </blockquote>
 161.551 -     *
 161.552 -     * @param      s   the string to be parsed.
 161.553 -     * @param      radix the radix to be used in interpreting {@code s}
 161.554 -     * @return     an {@code Integer} object holding the value
 161.555 -     *             represented by the string argument in the specified
 161.556 -     *             radix.
 161.557 -     * @exception NumberFormatException if the {@code String}
 161.558 -     *            does not contain a parsable {@code int}.
 161.559 -     */
 161.560 -    public static Integer valueOf(String s, int radix) throws NumberFormatException {
 161.561 -        return Integer.valueOf(parseInt(s,radix));
 161.562 -    }
 161.563 -
 161.564 -    /**
 161.565 -     * Returns an {@code Integer} object holding the
 161.566 -     * value of the specified {@code String}. The argument is
 161.567 -     * interpreted as representing a signed decimal integer, exactly
 161.568 -     * as if the argument were given to the {@link
 161.569 -     * #parseInt(java.lang.String)} method. The result is an
 161.570 -     * {@code Integer} object that represents the integer value
 161.571 -     * specified by the string.
 161.572 -     *
 161.573 -     * <p>In other words, this method returns an {@code Integer}
 161.574 -     * object equal to the value of:
 161.575 -     *
 161.576 -     * <blockquote>
 161.577 -     *  {@code new Integer(Integer.parseInt(s))}
 161.578 -     * </blockquote>
 161.579 -     *
 161.580 -     * @param      s   the string to be parsed.
 161.581 -     * @return     an {@code Integer} object holding the value
 161.582 -     *             represented by the string argument.
 161.583 -     * @exception  NumberFormatException  if the string cannot be parsed
 161.584 -     *             as an integer.
 161.585 -     */
 161.586 -    public static Integer valueOf(String s) throws NumberFormatException {
 161.587 -        return Integer.valueOf(parseInt(s, 10));
 161.588 -    }
 161.589 -
 161.590 -    /**
 161.591 -     * Cache to support the object identity semantics of autoboxing for values between
 161.592 -     * -128 and 127 (inclusive) as required by JLS.
 161.593 -     *
 161.594 -     * The cache is initialized on first usage.  The size of the cache
 161.595 -     * may be controlled by the -XX:AutoBoxCacheMax=<size> option.
 161.596 -     * During VM initialization, java.lang.Integer.IntegerCache.high property
 161.597 -     * may be set and saved in the private system properties in the
 161.598 -     * sun.misc.VM class.
 161.599 -     */
 161.600 -
 161.601 -    private static class IntegerCache {
 161.602 -        static final int low = -128;
 161.603 -        static final int high;
 161.604 -        static final Integer cache[];
 161.605 -
 161.606 -        static {
 161.607 -            // high value may be configured by property
 161.608 -            int h = 127;
 161.609 -            String integerCacheHighPropValue =
 161.610 -                AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
 161.611 -            if (integerCacheHighPropValue != null) {
 161.612 -                int i = parseInt(integerCacheHighPropValue);
 161.613 -                i = Math.max(i, 127);
 161.614 -                // Maximum array size is Integer.MAX_VALUE
 161.615 -                h = Math.min(i, Integer.MAX_VALUE - (-low));
 161.616 -            }
 161.617 -            high = h;
 161.618 -
 161.619 -            cache = new Integer[(high - low) + 1];
 161.620 -            int j = low;
 161.621 -            for(int k = 0; k < cache.length; k++)
 161.622 -                cache[k] = new Integer(j++);
 161.623 -        }
 161.624 -
 161.625 -        private IntegerCache() {}
 161.626 -    }
 161.627 -
 161.628 -    /**
 161.629 -     * Returns an {@code Integer} instance representing the specified
 161.630 -     * {@code int} value.  If a new {@code Integer} instance is not
 161.631 -     * required, this method should generally be used in preference to
 161.632 -     * the constructor {@link #Integer(int)}, as this method is likely
 161.633 -     * to yield significantly better space and time performance by
 161.634 -     * caching frequently requested values.
 161.635 -     *
 161.636 -     * This method will always cache values in the range -128 to 127,
 161.637 -     * inclusive, and may cache other values outside of this range.
 161.638 -     *
 161.639 -     * @param  i an {@code int} value.
 161.640 -     * @return an {@code Integer} instance representing {@code i}.
 161.641 -     * @since  1.5
 161.642 -     */
 161.643 -    public static Integer valueOf(int i) {
 161.644 -        //assert IntegerCache.high >= 127;
 161.645 -        if (i >= IntegerCache.low && i <= IntegerCache.high)
 161.646 -            return IntegerCache.cache[i + (-IntegerCache.low)];
 161.647 -        return new Integer(i);
 161.648 -    }
 161.649 -
 161.650 -    /**
 161.651 -     * The value of the {@code Integer}.
 161.652 -     *
 161.653 -     * @serial
 161.654 -     */
 161.655 -    private final int value;
 161.656 -
 161.657 -    /**
 161.658 -     * Constructs a newly allocated {@code Integer} object that
 161.659 -     * represents the specified {@code int} value.
 161.660 -     *
 161.661 -     * @param   value   the value to be represented by the
 161.662 -     *                  {@code Integer} object.
 161.663 -     */
 161.664 -    public Integer(int value) {
 161.665 -        this.value = value;
 161.666 -    }
 161.667 -
 161.668 -    /**
 161.669 -     * Constructs a newly allocated {@code Integer} object that
 161.670 -     * represents the {@code int} value indicated by the
 161.671 -     * {@code String} parameter. The string is converted to an
 161.672 -     * {@code int} value in exactly the manner used by the
 161.673 -     * {@code parseInt} method for radix 10.
 161.674 -     *
 161.675 -     * @param      s   the {@code String} to be converted to an
 161.676 -     *                 {@code Integer}.
 161.677 -     * @exception  NumberFormatException  if the {@code String} does not
 161.678 -     *               contain a parsable integer.
 161.679 -     * @see        java.lang.Integer#parseInt(java.lang.String, int)
 161.680 -     */
 161.681 -    public Integer(String s) throws NumberFormatException {
 161.682 -        this.value = parseInt(s, 10);
 161.683 -    }
 161.684 -
 161.685 -    /**
 161.686 -     * Returns the value of this {@code Integer} as a
 161.687 -     * {@code byte}.
 161.688 -     */
 161.689 -    public byte byteValue() {
 161.690 -        return (byte)value;
 161.691 -    }
 161.692 -
 161.693 -    /**
 161.694 -     * Returns the value of this {@code Integer} as a
 161.695 -     * {@code short}.
 161.696 -     */
 161.697 -    public short shortValue() {
 161.698 -        return (short)value;
 161.699 -    }
 161.700 -
 161.701 -    /**
 161.702 -     * Returns the value of this {@code Integer} as an
 161.703 -     * {@code int}.
 161.704 -     */
 161.705 -    public int intValue() {
 161.706 -        return value;
 161.707 -    }
 161.708 -
 161.709 -    /**
 161.710 -     * Returns the value of this {@code Integer} as a
 161.711 -     * {@code long}.
 161.712 -     */
 161.713 -    public long longValue() {
 161.714 -        return (long)value;
 161.715 -    }
 161.716 -
 161.717 -    /**
 161.718 -     * Returns the value of this {@code Integer} as a
 161.719 -     * {@code float}.
 161.720 -     */
 161.721 -    public float floatValue() {
 161.722 -        return (float)value;
 161.723 -    }
 161.724 -
 161.725 -    /**
 161.726 -     * Returns the value of this {@code Integer} as a
 161.727 -     * {@code double}.
 161.728 -     */
 161.729 -    public double doubleValue() {
 161.730 -        return (double)value;
 161.731 -    }
 161.732 -
 161.733 -    /**
 161.734 -     * Returns a {@code String} object representing this
 161.735 -     * {@code Integer}'s value. The value is converted to signed
 161.736 -     * decimal representation and returned as a string, exactly as if
 161.737 -     * the integer value were given as an argument to the {@link
 161.738 -     * java.lang.Integer#toString(int)} method.
 161.739 -     *
 161.740 -     * @return  a string representation of the value of this object in
 161.741 -     *          base&nbsp;10.
 161.742 -     */
 161.743 -    public String toString() {
 161.744 -        return toString(value);
 161.745 -    }
 161.746 -
 161.747 -    /**
 161.748 -     * Returns a hash code for this {@code Integer}.
 161.749 -     *
 161.750 -     * @return  a hash code value for this object, equal to the
 161.751 -     *          primitive {@code int} value represented by this
 161.752 -     *          {@code Integer} object.
 161.753 -     */
 161.754 -    public int hashCode() {
 161.755 -        return value;
 161.756 -    }
 161.757 -
 161.758 -    /**
 161.759 -     * Compares this object to the specified object.  The result is
 161.760 -     * {@code true} if and only if the argument is not
 161.761 -     * {@code null} and is an {@code Integer} object that
 161.762 -     * contains the same {@code int} value as this object.
 161.763 -     *
 161.764 -     * @param   obj   the object to compare with.
 161.765 -     * @return  {@code true} if the objects are the same;
 161.766 -     *          {@code false} otherwise.
 161.767 -     */
 161.768 -    public boolean equals(Object obj) {
 161.769 -        if (obj instanceof Integer) {
 161.770 -            return value == ((Integer)obj).intValue();
 161.771 -        }
 161.772 -        return false;
 161.773 -    }
 161.774 -
 161.775 -    /**
 161.776 -     * Determines the integer value of the system property with the
 161.777 -     * specified name.
 161.778 -     *
 161.779 -     * <p>The first argument is treated as the name of a system property.
 161.780 -     * System properties are accessible through the
 161.781 -     * {@link java.lang.System#getProperty(java.lang.String)} method. The
 161.782 -     * string value of this property is then interpreted as an integer
 161.783 -     * value and an {@code Integer} object representing this value is
 161.784 -     * returned. Details of possible numeric formats can be found with
 161.785 -     * the definition of {@code getProperty}.
 161.786 -     *
 161.787 -     * <p>If there is no property with the specified name, if the specified name
 161.788 -     * is empty or {@code null}, or if the property does not have
 161.789 -     * the correct numeric format, then {@code null} is returned.
 161.790 -     *
 161.791 -     * <p>In other words, this method returns an {@code Integer}
 161.792 -     * object equal to the value of:
 161.793 -     *
 161.794 -     * <blockquote>
 161.795 -     *  {@code getInteger(nm, null)}
 161.796 -     * </blockquote>
 161.797 -     *
 161.798 -     * @param   nm   property name.
 161.799 -     * @return  the {@code Integer} value of the property.
 161.800 -     * @see     java.lang.System#getProperty(java.lang.String)
 161.801 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 161.802 -     */
 161.803 -    public static Integer getInteger(String nm) {
 161.804 -        return getInteger(nm, null);
 161.805 -    }
 161.806 -
 161.807 -    /**
 161.808 -     * Determines the integer value of the system property with the
 161.809 -     * specified name.
 161.810 -     *
 161.811 -     * <p>The first argument is treated as the name of a system property.
 161.812 -     * System properties are accessible through the {@link
 161.813 -     * java.lang.System#getProperty(java.lang.String)} method. The
 161.814 -     * string value of this property is then interpreted as an integer
 161.815 -     * value and an {@code Integer} object representing this value is
 161.816 -     * returned. Details of possible numeric formats can be found with
 161.817 -     * the definition of {@code getProperty}.
 161.818 -     *
 161.819 -     * <p>The second argument is the default value. An {@code Integer} object
 161.820 -     * that represents the value of the second argument is returned if there
 161.821 -     * is no property of the specified name, if the property does not have
 161.822 -     * the correct numeric format, or if the specified name is empty or
 161.823 -     * {@code null}.
 161.824 -     *
 161.825 -     * <p>In other words, this method returns an {@code Integer} object
 161.826 -     * equal to the value of:
 161.827 -     *
 161.828 -     * <blockquote>
 161.829 -     *  {@code getInteger(nm, new Integer(val))}
 161.830 -     * </blockquote>
 161.831 -     *
 161.832 -     * but in practice it may be implemented in a manner such as:
 161.833 -     *
 161.834 -     * <blockquote><pre>
 161.835 -     * Integer result = getInteger(nm, null);
 161.836 -     * return (result == null) ? new Integer(val) : result;
 161.837 -     * </pre></blockquote>
 161.838 -     *
 161.839 -     * to avoid the unnecessary allocation of an {@code Integer}
 161.840 -     * object when the default value is not needed.
 161.841 -     *
 161.842 -     * @param   nm   property name.
 161.843 -     * @param   val   default value.
 161.844 -     * @return  the {@code Integer} value of the property.
 161.845 -     * @see     java.lang.System#getProperty(java.lang.String)
 161.846 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 161.847 -     */
 161.848 -    public static Integer getInteger(String nm, int val) {
 161.849 -        Integer result = getInteger(nm, null);
 161.850 -        return (result == null) ? Integer.valueOf(val) : result;
 161.851 -    }
 161.852 -
 161.853 -    /**
 161.854 -     * Returns the integer value of the system property with the
 161.855 -     * specified name.  The first argument is treated as the name of a
 161.856 -     * system property.  System properties are accessible through the
 161.857 -     * {@link java.lang.System#getProperty(java.lang.String)} method.
 161.858 -     * The string value of this property is then interpreted as an
 161.859 -     * integer value, as per the {@code Integer.decode} method,
 161.860 -     * and an {@code Integer} object representing this value is
 161.861 -     * returned.
 161.862 -     *
 161.863 -     * <ul><li>If the property value begins with the two ASCII characters
 161.864 -     *         {@code 0x} or the ASCII character {@code #}, not
 161.865 -     *      followed by a minus sign, then the rest of it is parsed as a
 161.866 -     *      hexadecimal integer exactly as by the method
 161.867 -     *      {@link #valueOf(java.lang.String, int)} with radix 16.
 161.868 -     * <li>If the property value begins with the ASCII character
 161.869 -     *     {@code 0} followed by another character, it is parsed as an
 161.870 -     *     octal integer exactly as by the method
 161.871 -     *     {@link #valueOf(java.lang.String, int)} with radix 8.
 161.872 -     * <li>Otherwise, the property value is parsed as a decimal integer
 161.873 -     * exactly as by the method {@link #valueOf(java.lang.String, int)}
 161.874 -     * with radix 10.
 161.875 -     * </ul>
 161.876 -     *
 161.877 -     * <p>The second argument is the default value. The default value is
 161.878 -     * returned if there is no property of the specified name, if the
 161.879 -     * property does not have the correct numeric format, or if the
 161.880 -     * specified name is empty or {@code null}.
 161.881 -     *
 161.882 -     * @param   nm   property name.
 161.883 -     * @param   val   default value.
 161.884 -     * @return  the {@code Integer} value of the property.
 161.885 -     * @see     java.lang.System#getProperty(java.lang.String)
 161.886 -     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 161.887 -     * @see java.lang.Integer#decode
 161.888 -     */
 161.889 -    public static Integer getInteger(String nm, Integer val) {
 161.890 -        String v = null;
 161.891 -        try {
 161.892 -            v = AbstractStringBuilder.getProperty(nm);
 161.893 -        } catch (IllegalArgumentException e) {
 161.894 -        } catch (NullPointerException e) {
 161.895 -        }
 161.896 -        if (v != null) {
 161.897 -            try {
 161.898 -                return Integer.decode(v);
 161.899 -            } catch (NumberFormatException e) {
 161.900 -            }
 161.901 -        }
 161.902 -        return val;
 161.903 -    }
 161.904 -
 161.905 -    /**
 161.906 -     * Decodes a {@code String} into an {@code Integer}.
 161.907 -     * Accepts decimal, hexadecimal, and octal numbers given
 161.908 -     * by the following grammar:
 161.909 -     *
 161.910 -     * <blockquote>
 161.911 -     * <dl>
 161.912 -     * <dt><i>DecodableString:</i>
 161.913 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 161.914 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 161.915 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 161.916 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 161.917 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 161.918 -     * <p>
 161.919 -     * <dt><i>Sign:</i>
 161.920 -     * <dd>{@code -}
 161.921 -     * <dd>{@code +}
 161.922 -     * </dl>
 161.923 -     * </blockquote>
 161.924 -     *
 161.925 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 161.926 -     * are as defined in section 3.10.1 of
 161.927 -     * <cite>The Java&trade; Language Specification</cite>,
 161.928 -     * except that underscores are not accepted between digits.
 161.929 -     *
 161.930 -     * <p>The sequence of characters following an optional
 161.931 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 161.932 -     * "{@code #}", or leading zero) is parsed as by the {@code
 161.933 -     * Integer.parseInt} method with the indicated radix (10, 16, or
 161.934 -     * 8).  This sequence of characters must represent a positive
 161.935 -     * value or a {@link NumberFormatException} will be thrown.  The
 161.936 -     * result is negated if first character of the specified {@code
 161.937 -     * String} is the minus sign.  No whitespace characters are
 161.938 -     * permitted in the {@code String}.
 161.939 -     *
 161.940 -     * @param     nm the {@code String} to decode.
 161.941 -     * @return    an {@code Integer} object holding the {@code int}
 161.942 -     *             value represented by {@code nm}
 161.943 -     * @exception NumberFormatException  if the {@code String} does not
 161.944 -     *            contain a parsable integer.
 161.945 -     * @see java.lang.Integer#parseInt(java.lang.String, int)
 161.946 -     */
 161.947 -    public static Integer decode(String nm) throws NumberFormatException {
 161.948 -        int radix = 10;
 161.949 -        int index = 0;
 161.950 -        boolean negative = false;
 161.951 -        Integer result;
 161.952 -
 161.953 -        if (nm.length() == 0)
 161.954 -            throw new NumberFormatException("Zero length string");
 161.955 -        char firstChar = nm.charAt(0);
 161.956 -        // Handle sign, if present
 161.957 -        if (firstChar == '-') {
 161.958 -            negative = true;
 161.959 -            index++;
 161.960 -        } else if (firstChar == '+')
 161.961 -            index++;
 161.962 -
 161.963 -        // Handle radix specifier, if present
 161.964 -        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 161.965 -            index += 2;
 161.966 -            radix = 16;
 161.967 -        }
 161.968 -        else if (nm.startsWith("#", index)) {
 161.969 -            index ++;
 161.970 -            radix = 16;
 161.971 -        }
 161.972 -        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 161.973 -            index ++;
 161.974 -            radix = 8;
 161.975 -        }
 161.976 -
 161.977 -        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 161.978 -            throw new NumberFormatException("Sign character in wrong position");
 161.979 -
 161.980 -        try {
 161.981 -            result = Integer.valueOf(nm.substring(index), radix);
 161.982 -            result = negative ? Integer.valueOf(-result.intValue()) : result;
 161.983 -        } catch (NumberFormatException e) {
 161.984 -            // If number is Integer.MIN_VALUE, we'll end up here. The next line
 161.985 -            // handles this case, and causes any genuine format error to be
 161.986 -            // rethrown.
 161.987 -            String constant = negative ? ("-" + nm.substring(index))
 161.988 -                                       : nm.substring(index);
 161.989 -            result = Integer.valueOf(constant, radix);
 161.990 -        }
 161.991 -        return result;
 161.992 -    }
 161.993 -
 161.994 -    /**
 161.995 -     * Compares two {@code Integer} objects numerically.
 161.996 -     *
 161.997 -     * @param   anotherInteger   the {@code Integer} to be compared.
 161.998 -     * @return  the value {@code 0} if this {@code Integer} is
 161.999 -     *          equal to the argument {@code Integer}; a value less than
161.1000 -     *          {@code 0} if this {@code Integer} is numerically less
161.1001 -     *          than the argument {@code Integer}; and a value greater
161.1002 -     *          than {@code 0} if this {@code Integer} is numerically
161.1003 -     *           greater than the argument {@code Integer} (signed
161.1004 -     *           comparison).
161.1005 -     * @since   1.2
161.1006 -     */
161.1007 -    public int compareTo(Integer anotherInteger) {
161.1008 -        return compare(this.value, anotherInteger.value);
161.1009 -    }
161.1010 -
161.1011 -    /**
161.1012 -     * Compares two {@code int} values numerically.
161.1013 -     * The value returned is identical to what would be returned by:
161.1014 -     * <pre>
161.1015 -     *    Integer.valueOf(x).compareTo(Integer.valueOf(y))
161.1016 -     * </pre>
161.1017 -     *
161.1018 -     * @param  x the first {@code int} to compare
161.1019 -     * @param  y the second {@code int} to compare
161.1020 -     * @return the value {@code 0} if {@code x == y};
161.1021 -     *         a value less than {@code 0} if {@code x < y}; and
161.1022 -     *         a value greater than {@code 0} if {@code x > y}
161.1023 -     * @since 1.7
161.1024 -     */
161.1025 -    public static int compare(int x, int y) {
161.1026 -        return (x < y) ? -1 : ((x == y) ? 0 : 1);
161.1027 -    }
161.1028 -
161.1029 -
161.1030 -    // Bit twiddling
161.1031 -
161.1032 -    /**
161.1033 -     * The number of bits used to represent an {@code int} value in two's
161.1034 -     * complement binary form.
161.1035 -     *
161.1036 -     * @since 1.5
161.1037 -     */
161.1038 -    public static final int SIZE = 32;
161.1039 -
161.1040 -    /**
161.1041 -     * Returns an {@code int} value with at most a single one-bit, in the
161.1042 -     * position of the highest-order ("leftmost") one-bit in the specified
161.1043 -     * {@code int} value.  Returns zero if the specified value has no
161.1044 -     * one-bits in its two's complement binary representation, that is, if it
161.1045 -     * is equal to zero.
161.1046 -     *
161.1047 -     * @return an {@code int} value with a single one-bit, in the position
161.1048 -     *     of the highest-order one-bit in the specified value, or zero if
161.1049 -     *     the specified value is itself equal to zero.
161.1050 -     * @since 1.5
161.1051 -     */
161.1052 -    public static int highestOneBit(int i) {
161.1053 -        // HD, Figure 3-1
161.1054 -        i |= (i >>  1);
161.1055 -        i |= (i >>  2);
161.1056 -        i |= (i >>  4);
161.1057 -        i |= (i >>  8);
161.1058 -        i |= (i >> 16);
161.1059 -        return i - (i >>> 1);
161.1060 -    }
161.1061 -
161.1062 -    /**
161.1063 -     * Returns an {@code int} value with at most a single one-bit, in the
161.1064 -     * position of the lowest-order ("rightmost") one-bit in the specified
161.1065 -     * {@code int} value.  Returns zero if the specified value has no
161.1066 -     * one-bits in its two's complement binary representation, that is, if it
161.1067 -     * is equal to zero.
161.1068 -     *
161.1069 -     * @return an {@code int} value with a single one-bit, in the position
161.1070 -     *     of the lowest-order one-bit in the specified value, or zero if
161.1071 -     *     the specified value is itself equal to zero.
161.1072 -     * @since 1.5
161.1073 -     */
161.1074 -    public static int lowestOneBit(int i) {
161.1075 -        // HD, Section 2-1
161.1076 -        return i & -i;
161.1077 -    }
161.1078 -
161.1079 -    /**
161.1080 -     * Returns the number of zero bits preceding the highest-order
161.1081 -     * ("leftmost") one-bit in the two's complement binary representation
161.1082 -     * of the specified {@code int} value.  Returns 32 if the
161.1083 -     * specified value has no one-bits in its two's complement representation,
161.1084 -     * in other words if it is equal to zero.
161.1085 -     *
161.1086 -     * <p>Note that this method is closely related to the logarithm base 2.
161.1087 -     * For all positive {@code int} values x:
161.1088 -     * <ul>
161.1089 -     * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
161.1090 -     * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
161.1091 -     * </ul>
161.1092 -     *
161.1093 -     * @return the number of zero bits preceding the highest-order
161.1094 -     *     ("leftmost") one-bit in the two's complement binary representation
161.1095 -     *     of the specified {@code int} value, or 32 if the value
161.1096 -     *     is equal to zero.
161.1097 -     * @since 1.5
161.1098 -     */
161.1099 -    public static int numberOfLeadingZeros(int i) {
161.1100 -        // HD, Figure 5-6
161.1101 -        if (i == 0)
161.1102 -            return 32;
161.1103 -        int n = 1;
161.1104 -        if (i >>> 16 == 0) { n += 16; i <<= 16; }
161.1105 -        if (i >>> 24 == 0) { n +=  8; i <<=  8; }
161.1106 -        if (i >>> 28 == 0) { n +=  4; i <<=  4; }
161.1107 -        if (i >>> 30 == 0) { n +=  2; i <<=  2; }
161.1108 -        n -= i >>> 31;
161.1109 -        return n;
161.1110 -    }
161.1111 -
161.1112 -    /**
161.1113 -     * Returns the number of zero bits following the lowest-order ("rightmost")
161.1114 -     * one-bit in the two's complement binary representation of the specified
161.1115 -     * {@code int} value.  Returns 32 if the specified value has no
161.1116 -     * one-bits in its two's complement representation, in other words if it is
161.1117 -     * equal to zero.
161.1118 -     *
161.1119 -     * @return the number of zero bits following the lowest-order ("rightmost")
161.1120 -     *     one-bit in the two's complement binary representation of the
161.1121 -     *     specified {@code int} value, or 32 if the value is equal
161.1122 -     *     to zero.
161.1123 -     * @since 1.5
161.1124 -     */
161.1125 -    public static int numberOfTrailingZeros(int i) {
161.1126 -        // HD, Figure 5-14
161.1127 -        int y;
161.1128 -        if (i == 0) return 32;
161.1129 -        int n = 31;
161.1130 -        y = i <<16; if (y != 0) { n = n -16; i = y; }
161.1131 -        y = i << 8; if (y != 0) { n = n - 8; i = y; }
161.1132 -        y = i << 4; if (y != 0) { n = n - 4; i = y; }
161.1133 -        y = i << 2; if (y != 0) { n = n - 2; i = y; }
161.1134 -        return n - ((i << 1) >>> 31);
161.1135 -    }
161.1136 -
161.1137 -    /**
161.1138 -     * Returns the number of one-bits in the two's complement binary
161.1139 -     * representation of the specified {@code int} value.  This function is
161.1140 -     * sometimes referred to as the <i>population count</i>.
161.1141 -     *
161.1142 -     * @return the number of one-bits in the two's complement binary
161.1143 -     *     representation of the specified {@code int} value.
161.1144 -     * @since 1.5
161.1145 -     */
161.1146 -    public static int bitCount(int i) {
161.1147 -        // HD, Figure 5-2
161.1148 -        i = i - ((i >>> 1) & 0x55555555);
161.1149 -        i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
161.1150 -        i = (i + (i >>> 4)) & 0x0f0f0f0f;
161.1151 -        i = i + (i >>> 8);
161.1152 -        i = i + (i >>> 16);
161.1153 -        return i & 0x3f;
161.1154 -    }
161.1155 -
161.1156 -    /**
161.1157 -     * Returns the value obtained by rotating the two's complement binary
161.1158 -     * representation of the specified {@code int} value left by the
161.1159 -     * specified number of bits.  (Bits shifted out of the left hand, or
161.1160 -     * high-order, side reenter on the right, or low-order.)
161.1161 -     *
161.1162 -     * <p>Note that left rotation with a negative distance is equivalent to
161.1163 -     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
161.1164 -     * distance)}.  Note also that rotation by any multiple of 32 is a
161.1165 -     * no-op, so all but the last five bits of the rotation distance can be
161.1166 -     * ignored, even if the distance is negative: {@code rotateLeft(val,
161.1167 -     * distance) == rotateLeft(val, distance & 0x1F)}.
161.1168 -     *
161.1169 -     * @return the value obtained by rotating the two's complement binary
161.1170 -     *     representation of the specified {@code int} value left by the
161.1171 -     *     specified number of bits.
161.1172 -     * @since 1.5
161.1173 -     */
161.1174 -    public static int rotateLeft(int i, int distance) {
161.1175 -        return (i << distance) | (i >>> -distance);
161.1176 -    }
161.1177 -
161.1178 -    /**
161.1179 -     * Returns the value obtained by rotating the two's complement binary
161.1180 -     * representation of the specified {@code int} value right by the
161.1181 -     * specified number of bits.  (Bits shifted out of the right hand, or
161.1182 -     * low-order, side reenter on the left, or high-order.)
161.1183 -     *
161.1184 -     * <p>Note that right rotation with a negative distance is equivalent to
161.1185 -     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
161.1186 -     * distance)}.  Note also that rotation by any multiple of 32 is a
161.1187 -     * no-op, so all but the last five bits of the rotation distance can be
161.1188 -     * ignored, even if the distance is negative: {@code rotateRight(val,
161.1189 -     * distance) == rotateRight(val, distance & 0x1F)}.
161.1190 -     *
161.1191 -     * @return the value obtained by rotating the two's complement binary
161.1192 -     *     representation of the specified {@code int} value right by the
161.1193 -     *     specified number of bits.
161.1194 -     * @since 1.5
161.1195 -     */
161.1196 -    public static int rotateRight(int i, int distance) {
161.1197 -        return (i >>> distance) | (i << -distance);
161.1198 -    }
161.1199 -
161.1200 -    /**
161.1201 -     * Returns the value obtained by reversing the order of the bits in the
161.1202 -     * two's complement binary representation of the specified {@code int}
161.1203 -     * value.
161.1204 -     *
161.1205 -     * @return the value obtained by reversing order of the bits in the
161.1206 -     *     specified {@code int} value.
161.1207 -     * @since 1.5
161.1208 -     */
161.1209 -    public static int reverse(int i) {
161.1210 -        // HD, Figure 7-1
161.1211 -        i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
161.1212 -        i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
161.1213 -        i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
161.1214 -        i = (i << 24) | ((i & 0xff00) << 8) |
161.1215 -            ((i >>> 8) & 0xff00) | (i >>> 24);
161.1216 -        return i;
161.1217 -    }
161.1218 -
161.1219 -    /**
161.1220 -     * Returns the signum function of the specified {@code int} value.  (The
161.1221 -     * return value is -1 if the specified value is negative; 0 if the
161.1222 -     * specified value is zero; and 1 if the specified value is positive.)
161.1223 -     *
161.1224 -     * @return the signum function of the specified {@code int} value.
161.1225 -     * @since 1.5
161.1226 -     */
161.1227 -    public static int signum(int i) {
161.1228 -        // HD, Section 2-7
161.1229 -        return (i >> 31) | (-i >>> 31);
161.1230 -    }
161.1231 -
161.1232 -    /**
161.1233 -     * Returns the value obtained by reversing the order of the bytes in the
161.1234 -     * two's complement representation of the specified {@code int} value.
161.1235 -     *
161.1236 -     * @return the value obtained by reversing the bytes in the specified
161.1237 -     *     {@code int} value.
161.1238 -     * @since 1.5
161.1239 -     */
161.1240 -    public static int reverseBytes(int i) {
161.1241 -        return ((i >>> 24)           ) |
161.1242 -               ((i >>   8) &   0xFF00) |
161.1243 -               ((i <<   8) & 0xFF0000) |
161.1244 -               ((i << 24));
161.1245 -    }
161.1246 -
161.1247 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
161.1248 -    private static final long serialVersionUID = 1360826667806852920L;
161.1249 -}
   162.1 --- a/emul/mini/src/main/java/java/lang/InterruptedException.java	Mon Feb 25 19:00:08 2013 +0100
   162.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   162.3 @@ -1,69 +0,0 @@
   162.4 -/*
   162.5 - * Copyright (c) 1995, 2008, 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;
  162.30 -
  162.31 -/**
  162.32 - * Thrown when a thread is waiting, sleeping, or otherwise occupied,
  162.33 - * and the thread is interrupted, either before or during the activity.
  162.34 - * Occasionally a method may wish to test whether the current
  162.35 - * thread has been interrupted, and if so, to immediately throw
  162.36 - * this exception.  The following code can be used to achieve
  162.37 - * this effect:
  162.38 - * <pre>
  162.39 - *  if (Thread.interrupted())  // Clears interrupted status!
  162.40 - *      throw new InterruptedException();
  162.41 - * </pre>
  162.42 - *
  162.43 - * @author  Frank Yellin
  162.44 - * @see     java.lang.Object#wait()
  162.45 - * @see     java.lang.Object#wait(long)
  162.46 - * @see     java.lang.Object#wait(long, int)
  162.47 - * @see     java.lang.Thread#sleep(long)
  162.48 - * @see     java.lang.Thread#interrupt()
  162.49 - * @see     java.lang.Thread#interrupted()
  162.50 - * @since   JDK1.0
  162.51 - */
  162.52 -public
  162.53 -class InterruptedException extends Exception {
  162.54 -    private static final long serialVersionUID = 6700697376100628473L;
  162.55 -
  162.56 -    /**
  162.57 -     * Constructs an <code>InterruptedException</code> with no detail  message.
  162.58 -     */
  162.59 -    public InterruptedException() {
  162.60 -        super();
  162.61 -    }
  162.62 -
  162.63 -    /**
  162.64 -     * Constructs an <code>InterruptedException</code> with the
  162.65 -     * specified detail message.
  162.66 -     *
  162.67 -     * @param   s   the detail message.
  162.68 -     */
  162.69 -    public InterruptedException(String s) {
  162.70 -        super(s);
  162.71 -    }
  162.72 -}
   163.1 --- a/emul/mini/src/main/java/java/lang/LinkageError.java	Mon Feb 25 19:00:08 2013 +0100
   163.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   163.3 @@ -1,69 +0,0 @@
   163.4 -/*
   163.5 - * Copyright (c) 1995, 2010, 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 - * Subclasses of {@code LinkageError} indicate that a class has
  163.33 - * some dependency on another class; however, the latter class has
  163.34 - * incompatibly changed after the compilation of the former class.
  163.35 - *
  163.36 - *
  163.37 - * @author  Frank Yellin
  163.38 - * @since   JDK1.0
  163.39 - */
  163.40 -public
  163.41 -class LinkageError extends Error {
  163.42 -    private static final long serialVersionUID = 3579600108157160122L;
  163.43 -
  163.44 -    /**
  163.45 -     * Constructs a {@code LinkageError} with no detail message.
  163.46 -     */
  163.47 -    public LinkageError() {
  163.48 -        super();
  163.49 -    }
  163.50 -
  163.51 -    /**
  163.52 -     * Constructs a {@code LinkageError} with the specified detail
  163.53 -     * message.
  163.54 -     *
  163.55 -     * @param   s   the detail message.
  163.56 -     */
  163.57 -    public LinkageError(String s) {
  163.58 -        super(s);
  163.59 -    }
  163.60 -
  163.61 -    /**
  163.62 -     * Constructs a {@code LinkageError} with the specified detail
  163.63 -     * message and cause.
  163.64 -     *
  163.65 -     * @param s     the detail message.
  163.66 -     * @param cause the cause, may be {@code null}
  163.67 -     * @since 1.7
  163.68 -     */
  163.69 -    public LinkageError(String s, Throwable cause) {
  163.70 -        super(s, cause);
  163.71 -    }
  163.72 -}
   164.1 --- a/emul/mini/src/main/java/java/lang/Long.java	Mon Feb 25 19:00:08 2013 +0100
   164.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   164.3 @@ -1,1202 +0,0 @@
   164.4 -/*
   164.5 - * Copyright (c) 1994, 2009, 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;
  164.30 -
  164.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  164.32 -
  164.33 -/**
  164.34 - * The {@code Long} class wraps a value of the primitive type {@code
  164.35 - * long} in an object. An object of type {@code Long} contains a
  164.36 - * single field whose type is {@code long}.
  164.37 - *
  164.38 - * <p> In addition, this class provides several methods for converting
  164.39 - * a {@code long} to a {@code String} and a {@code String} to a {@code
  164.40 - * long}, as well as other constants and methods useful when dealing
  164.41 - * with a {@code long}.
  164.42 - *
  164.43 - * <p>Implementation note: The implementations of the "bit twiddling"
  164.44 - * methods (such as {@link #highestOneBit(long) highestOneBit} and
  164.45 - * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
  164.46 - * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  164.47 - * Delight</i>, (Addison Wesley, 2002).
  164.48 - *
  164.49 - * @author  Lee Boynton
  164.50 - * @author  Arthur van Hoff
  164.51 - * @author  Josh Bloch
  164.52 - * @author  Joseph D. Darcy
  164.53 - * @since   JDK1.0
  164.54 - */
  164.55 -public final class Long extends Number implements Comparable<Long> {
  164.56 -    /**
  164.57 -     * A constant holding the minimum value a {@code long} can
  164.58 -     * have, -2<sup>63</sup>.
  164.59 -     */
  164.60 -    public static final long MIN_VALUE = 0x8000000000000000L;
  164.61 -
  164.62 -    /**
  164.63 -     * A constant holding the maximum value a {@code long} can
  164.64 -     * have, 2<sup>63</sup>-1.
  164.65 -     */
  164.66 -    public static final long MAX_VALUE = 0x7fffffffffffffffL;
  164.67 -
  164.68 -    /**
  164.69 -     * The {@code Class} instance representing the primitive type
  164.70 -     * {@code long}.
  164.71 -     *
  164.72 -     * @since   JDK1.1
  164.73 -     */
  164.74 -    public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
  164.75 -
  164.76 -    /**
  164.77 -     * Returns a string representation of the first argument in the
  164.78 -     * radix specified by the second argument.
  164.79 -     *
  164.80 -     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  164.81 -     * or larger than {@code Character.MAX_RADIX}, then the radix
  164.82 -     * {@code 10} is used instead.
  164.83 -     *
  164.84 -     * <p>If the first argument is negative, the first element of the
  164.85 -     * result is the ASCII minus sign {@code '-'}
  164.86 -     * (<code>'&#92;u002d'</code>). If the first argument is not
  164.87 -     * negative, no sign character appears in the result.
  164.88 -     *
  164.89 -     * <p>The remaining characters of the result represent the magnitude
  164.90 -     * of the first argument. If the magnitude is zero, it is
  164.91 -     * represented by a single zero character {@code '0'}
  164.92 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
  164.93 -     * the representation of the magnitude will not be the zero
  164.94 -     * character.  The following ASCII characters are used as digits:
  164.95 -     *
  164.96 -     * <blockquote>
  164.97 -     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
  164.98 -     * </blockquote>
  164.99 -     *
 164.100 -     * These are <code>'&#92;u0030'</code> through
 164.101 -     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 164.102 -     * <code>'&#92;u007a'</code>. If {@code radix} is
 164.103 -     * <var>N</var>, then the first <var>N</var> of these characters
 164.104 -     * are used as radix-<var>N</var> digits in the order shown. Thus,
 164.105 -     * the digits for hexadecimal (radix 16) are
 164.106 -     * {@code 0123456789abcdef}. If uppercase letters are
 164.107 -     * desired, the {@link java.lang.String#toUpperCase()} method may
 164.108 -     * be called on the result:
 164.109 -     *
 164.110 -     * <blockquote>
 164.111 -     *  {@code Long.toString(n, 16).toUpperCase()}
 164.112 -     * </blockquote>
 164.113 -     *
 164.114 -     * @param   i       a {@code long} to be converted to a string.
 164.115 -     * @param   radix   the radix to use in the string representation.
 164.116 -     * @return  a string representation of the argument in the specified radix.
 164.117 -     * @see     java.lang.Character#MAX_RADIX
 164.118 -     * @see     java.lang.Character#MIN_RADIX
 164.119 -     */
 164.120 -    public static String toString(long i, int radix) {
 164.121 -        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 164.122 -            radix = 10;
 164.123 -        if (radix == 10)
 164.124 -            return toString(i);
 164.125 -        char[] buf = new char[65];
 164.126 -        int charPos = 64;
 164.127 -        boolean negative = (i < 0);
 164.128 -
 164.129 -        if (!negative) {
 164.130 -            i = -i;
 164.131 -        }
 164.132 -
 164.133 -        while (i <= -radix) {
 164.134 -            buf[charPos--] = Integer.digits[(int)(-(i % radix))];
 164.135 -            i = i / radix;
 164.136 -        }
 164.137 -        buf[charPos] = Integer.digits[(int)(-i)];
 164.138 -
 164.139 -        if (negative) {
 164.140 -            buf[--charPos] = '-';
 164.141 -        }
 164.142 -
 164.143 -        return new String(buf, charPos, (65 - charPos));
 164.144 -    }
 164.145 -
 164.146 -    /**
 164.147 -     * Returns a string representation of the {@code long}
 164.148 -     * argument as an unsigned integer in base&nbsp;16.
 164.149 -     *
 164.150 -     * <p>The unsigned {@code long} value is the argument plus
 164.151 -     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 164.152 -     * equal to the argument.  This value is converted to a string of
 164.153 -     * ASCII digits in hexadecimal (base&nbsp;16) with no extra
 164.154 -     * leading {@code 0}s.  If the unsigned magnitude is zero, it
 164.155 -     * is represented by a single zero character {@code '0'}
 164.156 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 164.157 -     * the representation of the unsigned magnitude will not be the
 164.158 -     * zero character. The following characters are used as
 164.159 -     * hexadecimal digits:
 164.160 -     *
 164.161 -     * <blockquote>
 164.162 -     *  {@code 0123456789abcdef}
 164.163 -     * </blockquote>
 164.164 -     *
 164.165 -     * These are the characters <code>'&#92;u0030'</code> through
 164.166 -     * <code>'&#92;u0039'</code> and  <code>'&#92;u0061'</code> through
 164.167 -     * <code>'&#92;u0066'</code>.  If uppercase letters are desired,
 164.168 -     * the {@link java.lang.String#toUpperCase()} method may be called
 164.169 -     * on the result:
 164.170 -     *
 164.171 -     * <blockquote>
 164.172 -     *  {@code Long.toHexString(n).toUpperCase()}
 164.173 -     * </blockquote>
 164.174 -     *
 164.175 -     * @param   i   a {@code long} to be converted to a string.
 164.176 -     * @return  the string representation of the unsigned {@code long}
 164.177 -     *          value represented by the argument in hexadecimal
 164.178 -     *          (base&nbsp;16).
 164.179 -     * @since   JDK 1.0.2
 164.180 -     */
 164.181 -    public static String toHexString(long i) {
 164.182 -        return toUnsignedString(i, 4);
 164.183 -    }
 164.184 -
 164.185 -    /**
 164.186 -     * Returns a string representation of the {@code long}
 164.187 -     * argument as an unsigned integer in base&nbsp;8.
 164.188 -     *
 164.189 -     * <p>The unsigned {@code long} value is the argument plus
 164.190 -     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 164.191 -     * equal to the argument.  This value is converted to a string of
 164.192 -     * ASCII digits in octal (base&nbsp;8) with no extra leading
 164.193 -     * {@code 0}s.
 164.194 -     *
 164.195 -     * <p>If the unsigned magnitude is zero, it is represented by a
 164.196 -     * single zero character {@code '0'}
 164.197 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 164.198 -     * the representation of the unsigned magnitude will not be the
 164.199 -     * zero character. The following characters are used as octal
 164.200 -     * digits:
 164.201 -     *
 164.202 -     * <blockquote>
 164.203 -     *  {@code 01234567}
 164.204 -     * </blockquote>
 164.205 -     *
 164.206 -     * These are the characters <code>'&#92;u0030'</code> through
 164.207 -     * <code>'&#92;u0037'</code>.
 164.208 -     *
 164.209 -     * @param   i   a {@code long} to be converted to a string.
 164.210 -     * @return  the string representation of the unsigned {@code long}
 164.211 -     *          value represented by the argument in octal (base&nbsp;8).
 164.212 -     * @since   JDK 1.0.2
 164.213 -     */
 164.214 -    public static String toOctalString(long i) {
 164.215 -        return toUnsignedString(i, 3);
 164.216 -    }
 164.217 -
 164.218 -    /**
 164.219 -     * Returns a string representation of the {@code long}
 164.220 -     * argument as an unsigned integer in base&nbsp;2.
 164.221 -     *
 164.222 -     * <p>The unsigned {@code long} value is the argument plus
 164.223 -     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 164.224 -     * equal to the argument.  This value is converted to a string of
 164.225 -     * ASCII digits in binary (base&nbsp;2) with no extra leading
 164.226 -     * {@code 0}s.  If the unsigned magnitude is zero, it is
 164.227 -     * represented by a single zero character {@code '0'}
 164.228 -     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 164.229 -     * the representation of the unsigned magnitude will not be the
 164.230 -     * zero character. The characters {@code '0'}
 164.231 -     * (<code>'&#92;u0030'</code>) and {@code '1'}
 164.232 -     * (<code>'&#92;u0031'</code>) are used as binary digits.
 164.233 -     *
 164.234 -     * @param   i   a {@code long} to be converted to a string.
 164.235 -     * @return  the string representation of the unsigned {@code long}
 164.236 -     *          value represented by the argument in binary (base&nbsp;2).
 164.237 -     * @since   JDK 1.0.2
 164.238 -     */
 164.239 -    public static String toBinaryString(long i) {
 164.240 -        return toUnsignedString(i, 1);
 164.241 -    }
 164.242 -
 164.243 -    /**
 164.244 -     * Convert the integer to an unsigned number.
 164.245 -     */
 164.246 -    private static String toUnsignedString(long i, int shift) {
 164.247 -        char[] buf = new char[64];
 164.248 -        int charPos = 64;
 164.249 -        int radix = 1 << shift;
 164.250 -        long mask = radix - 1;
 164.251 -        do {
 164.252 -            buf[--charPos] = Integer.digits[(int)(i & mask)];
 164.253 -            i >>>= shift;
 164.254 -        } while (i != 0);
 164.255 -        return new String(buf, charPos, (64 - charPos));
 164.256 -    }
 164.257 -
 164.258 -    /**
 164.259 -     * Returns a {@code String} object representing the specified
 164.260 -     * {@code long}.  The argument is converted to signed decimal
 164.261 -     * representation and returned as a string, exactly as if the
 164.262 -     * argument and the radix 10 were given as arguments to the {@link
 164.263 -     * #toString(long, int)} method.
 164.264 -     *
 164.265 -     * @param   i   a {@code long} to be converted.
 164.266 -     * @return  a string representation of the argument in base&nbsp;10.
 164.267 -     */
 164.268 -    @JavaScriptBody(args = "i", body = "return i.toExactString();")
 164.269 -    public static String toString(long i) {
 164.270 -        if (i == Long.MIN_VALUE)
 164.271 -            return "-9223372036854775808";
 164.272 -        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 164.273 -        char[] buf = new char[size];
 164.274 -        getChars(i, size, buf);
 164.275 -        return new String(buf, 0, size);
 164.276 -    }
 164.277 -
 164.278 -    /**
 164.279 -     * Places characters representing the integer i into the
 164.280 -     * character array buf. The characters are placed into
 164.281 -     * the buffer backwards starting with the least significant
 164.282 -     * digit at the specified index (exclusive), and working
 164.283 -     * backwards from there.
 164.284 -     *
 164.285 -     * Will fail if i == Long.MIN_VALUE
 164.286 -     */
 164.287 -    static void getChars(long i, int index, char[] buf) {
 164.288 -        long q;
 164.289 -        int r;
 164.290 -        int charPos = index;
 164.291 -        char sign = 0;
 164.292 -
 164.293 -        if (i < 0) {
 164.294 -            sign = '-';
 164.295 -            i = -i;
 164.296 -        }
 164.297 -
 164.298 -        // Get 2 digits/iteration using longs until quotient fits into an int
 164.299 -        while (i > Integer.MAX_VALUE) {
 164.300 -            q = i / 100;
 164.301 -            // really: r = i - (q * 100);
 164.302 -            r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
 164.303 -            i = q;
 164.304 -            buf[--charPos] = Integer.DigitOnes[r];
 164.305 -            buf[--charPos] = Integer.DigitTens[r];
 164.306 -        }
 164.307 -
 164.308 -        // Get 2 digits/iteration using ints
 164.309 -        int q2;
 164.310 -        int i2 = (int)i;
 164.311 -        while (i2 >= 65536) {
 164.312 -            q2 = i2 / 100;
 164.313 -            // really: r = i2 - (q * 100);
 164.314 -            r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
 164.315 -            i2 = q2;
 164.316 -            buf[--charPos] = Integer.DigitOnes[r];
 164.317 -            buf[--charPos] = Integer.DigitTens[r];
 164.318 -        }
 164.319 -
 164.320 -        // Fall thru to fast mode for smaller numbers
 164.321 -        // assert(i2 <= 65536, i2);
 164.322 -        for (;;) {
 164.323 -            q2 = (i2 * 52429) >>> (16+3);
 164.324 -            r = i2 - ((q2 << 3) + (q2 << 1));  // r = i2-(q2*10) ...
 164.325 -            buf[--charPos] = Integer.digits[r];
 164.326 -            i2 = q2;
 164.327 -            if (i2 == 0) break;
 164.328 -        }
 164.329 -        if (sign != 0) {
 164.330 -            buf[--charPos] = sign;
 164.331 -        }
 164.332 -    }
 164.333 -
 164.334 -    // Requires positive x
 164.335 -    static int stringSize(long x) {
 164.336 -        long p = 10;
 164.337 -        for (int i=1; i<19; i++) {
 164.338 -            if (x < p)
 164.339 -                return i;
 164.340 -            p = 10*p;
 164.341 -        }
 164.342 -        return 19;
 164.343 -    }
 164.344 -
 164.345 -    /**
 164.346 -     * Parses the string argument as a signed {@code long} in the
 164.347 -     * radix specified by the second argument. The characters in the
 164.348 -     * string must all be digits of the specified radix (as determined
 164.349 -     * by whether {@link java.lang.Character#digit(char, int)} returns
 164.350 -     * a nonnegative value), except that the first character may be an
 164.351 -     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 164.352 -     * indicate a negative value or an ASCII plus sign {@code '+'}
 164.353 -     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 164.354 -     * resulting {@code long} value is returned.
 164.355 -     *
 164.356 -     * <p>Note that neither the character {@code L}
 164.357 -     * (<code>'&#92;u004C'</code>) nor {@code l}
 164.358 -     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 164.359 -     * of the string as a type indicator, as would be permitted in
 164.360 -     * Java programming language source code - except that either
 164.361 -     * {@code L} or {@code l} may appear as a digit for a
 164.362 -     * radix greater than 22.
 164.363 -     *
 164.364 -     * <p>An exception of type {@code NumberFormatException} is
 164.365 -     * thrown if any of the following situations occurs:
 164.366 -     * <ul>
 164.367 -     *
 164.368 -     * <li>The first argument is {@code null} or is a string of
 164.369 -     * length zero.
 164.370 -     *
 164.371 -     * <li>The {@code radix} is either smaller than {@link
 164.372 -     * java.lang.Character#MIN_RADIX} or larger than {@link
 164.373 -     * java.lang.Character#MAX_RADIX}.
 164.374 -     *
 164.375 -     * <li>Any character of the string is not a digit of the specified
 164.376 -     * radix, except that the first character may be a minus sign
 164.377 -     * {@code '-'} (<code>'&#92;u002d'</code>) or plus sign {@code
 164.378 -     * '+'} (<code>'&#92;u002B'</code>) provided that the string is
 164.379 -     * longer than length 1.
 164.380 -     *
 164.381 -     * <li>The value represented by the string is not a value of type
 164.382 -     *      {@code long}.
 164.383 -     * </ul>
 164.384 -     *
 164.385 -     * <p>Examples:
 164.386 -     * <blockquote><pre>
 164.387 -     * parseLong("0", 10) returns 0L
 164.388 -     * parseLong("473", 10) returns 473L
 164.389 -     * parseLong("+42", 10) returns 42L
 164.390 -     * parseLong("-0", 10) returns 0L
 164.391 -     * parseLong("-FF", 16) returns -255L
 164.392 -     * parseLong("1100110", 2) returns 102L
 164.393 -     * parseLong("99", 8) throws a NumberFormatException
 164.394 -     * parseLong("Hazelnut", 10) throws a NumberFormatException
 164.395 -     * parseLong("Hazelnut", 36) returns 1356099454469L
 164.396 -     * </pre></blockquote>
 164.397 -     *
 164.398 -     * @param      s       the {@code String} containing the
 164.399 -     *                     {@code long} representation to be parsed.
 164.400 -     * @param      radix   the radix to be used while parsing {@code s}.
 164.401 -     * @return     the {@code long} represented by the string argument in
 164.402 -     *             the specified radix.
 164.403 -     * @throws     NumberFormatException  if the string does not contain a
 164.404 -     *             parsable {@code long}.
 164.405 -     */
 164.406 -    public static long parseLong(String s, int radix)
 164.407 -              throws NumberFormatException
 164.408 -    {
 164.409 -        if (s == null) {
 164.410 -            throw new NumberFormatException("null");
 164.411 -        }
 164.412 -
 164.413 -        if (radix < Character.MIN_RADIX) {
 164.414 -            throw new NumberFormatException("radix " + radix +
 164.415 -                                            " less than Character.MIN_RADIX");
 164.416 -        }
 164.417 -        if (radix > Character.MAX_RADIX) {
 164.418 -            throw new NumberFormatException("radix " + radix +
 164.419 -                                            " greater than Character.MAX_RADIX");
 164.420 -        }
 164.421 -
 164.422 -        long result = 0;
 164.423 -        boolean negative = false;
 164.424 -        int i = 0, len = s.length();
 164.425 -        long limit = -Long.MAX_VALUE;
 164.426 -        long multmin;
 164.427 -        int digit;
 164.428 -
 164.429 -        if (len > 0) {
 164.430 -            char firstChar = s.charAt(0);
 164.431 -            if (firstChar < '0') { // Possible leading "+" or "-"
 164.432 -                if (firstChar == '-') {
 164.433 -                    negative = true;
 164.434 -                    limit = Long.MIN_VALUE;
 164.435 -                } else if (firstChar != '+')
 164.436 -                    throw NumberFormatException.forInputString(s);
 164.437 -
 164.438 -                if (len == 1) // Cannot have lone "+" or "-"
 164.439 -                    throw NumberFormatException.forInputString(s);
 164.440 -                i++;
 164.441 -            }
 164.442 -            multmin = limit / radix;
 164.443 -            while (i < len) {
 164.444 -                // Accumulating negatively avoids surprises near MAX_VALUE
 164.445 -                digit = Character.digit(s.charAt(i++),radix);
 164.446 -                if (digit < 0) {
 164.447 -                    throw NumberFormatException.forInputString(s);
 164.448 -                }
 164.449 -                if (result < multmin) {
 164.450 -                    throw NumberFormatException.forInputString(s);
 164.451 -                }
 164.452 -                result *= radix;
 164.453 -                if (result < limit + digit) {
 164.454 -                    throw NumberFormatException.forInputString(s);
 164.455 -                }
 164.456 -                result -= digit;
 164.457 -            }
 164.458 -        } else {
 164.459 -            throw NumberFormatException.forInputString(s);
 164.460 -        }
 164.461 -        return negative ? result : -result;
 164.462 -    }
 164.463 -
 164.464 -    /**
 164.465 -     * Parses the string argument as a signed decimal {@code long}.
 164.466 -     * The characters in the string must all be decimal digits, except
 164.467 -     * that the first character may be an ASCII minus sign {@code '-'}
 164.468 -     * (<code>&#92;u002D'</code>) to indicate a negative value or an
 164.469 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 164.470 -     * indicate a positive value. The resulting {@code long} value is
 164.471 -     * returned, exactly as if the argument and the radix {@code 10}
 164.472 -     * were given as arguments to the {@link
 164.473 -     * #parseLong(java.lang.String, int)} method.
 164.474 -     *
 164.475 -     * <p>Note that neither the character {@code L}
 164.476 -     * (<code>'&#92;u004C'</code>) nor {@code l}
 164.477 -     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 164.478 -     * of the string as a type indicator, as would be permitted in
 164.479 -     * Java programming language source code.
 164.480 -     *
 164.481 -     * @param      s   a {@code String} containing the {@code long}
 164.482 -     *             representation to be parsed
 164.483 -     * @return     the {@code long} represented by the argument in
 164.484 -     *             decimal.
 164.485 -     * @throws     NumberFormatException  if the string does not contain a
 164.486 -     *             parsable {@code long}.
 164.487 -     */
 164.488 -    public static long parseLong(String s) throws NumberFormatException {
 164.489 -        return parseLong(s, 10);
 164.490 -    }
 164.491 -
 164.492 -    /**
 164.493 -     * Returns a {@code Long} object holding the value
 164.494 -     * extracted from the specified {@code String} when parsed
 164.495 -     * with the radix given by the second argument.  The first
 164.496 -     * argument is interpreted as representing a signed
 164.497 -     * {@code long} in the radix specified by the second
 164.498 -     * argument, exactly as if the arguments were given to the {@link
 164.499 -     * #parseLong(java.lang.String, int)} method. The result is a
 164.500 -     * {@code Long} object that represents the {@code long}
 164.501 -     * value specified by the string.
 164.502 -     *
 164.503 -     * <p>In other words, this method returns a {@code Long} object equal
 164.504 -     * to the value of:
 164.505 -     *
 164.506 -     * <blockquote>
 164.507 -     *  {@code new Long(Long.parseLong(s, radix))}
 164.508 -     * </blockquote>
 164.509 -     *
 164.510 -     * @param      s       the string to be parsed
 164.511 -     * @param      radix   the radix to be used in interpreting {@code s}
 164.512 -     * @return     a {@code Long} object holding the value
 164.513 -     *             represented by the string argument in the specified
 164.514 -     *             radix.
 164.515 -     * @throws     NumberFormatException  If the {@code String} does not
 164.516 -     *             contain a parsable {@code long}.
 164.517 -     */
 164.518 -    public static Long valueOf(String s, int radix) throws NumberFormatException {
 164.519 -        return Long.valueOf(parseLong(s, radix));
 164.520 -    }
 164.521 -
 164.522 -    /**
 164.523 -     * Returns a {@code Long} object holding the value
 164.524 -     * of the specified {@code String}. The argument is
 164.525 -     * interpreted as representing a signed decimal {@code long},
 164.526 -     * exactly as if the argument were given to the {@link
 164.527 -     * #parseLong(java.lang.String)} method. The result is a
 164.528 -     * {@code Long} object that represents the integer value
 164.529 -     * specified by the string.
 164.530 -     *
 164.531 -     * <p>In other words, this method returns a {@code Long} object
 164.532 -     * equal to the value of:
 164.533 -     *
 164.534 -     * <blockquote>
 164.535 -     *  {@code new Long(Long.parseLong(s))}
 164.536 -     * </blockquote>
 164.537 -     *
 164.538 -     * @param      s   the string to be parsed.
 164.539 -     * @return     a {@code Long} object holding the value
 164.540 -     *             represented by the string argument.
 164.541 -     * @throws     NumberFormatException  If the string cannot be parsed
 164.542 -     *             as a {@code long}.
 164.543 -     */
 164.544 -    public static Long valueOf(String s) throws NumberFormatException
 164.545 -    {
 164.546 -        return Long.valueOf(parseLong(s, 10));
 164.547 -    }
 164.548 -
 164.549 -    private static class LongCache {
 164.550 -        private LongCache(){}
 164.551 -
 164.552 -        static final Long cache[] = new Long[-(-128) + 127 + 1];
 164.553 -
 164.554 -        static {
 164.555 -            for(int i = 0; i < cache.length; i++)
 164.556 -                cache[i] = new Long(i - 128);
 164.557 -        }
 164.558 -    }
 164.559 -
 164.560 -    /**
 164.561 -     * Returns a {@code Long} instance representing the specified
 164.562 -     * {@code long} value.
 164.563 -     * If a new {@code Long} instance is not required, this method
 164.564 -     * should generally be used in preference to the constructor
 164.565 -     * {@link #Long(long)}, as this method is likely to yield
 164.566 -     * significantly better space and time performance by caching
 164.567 -     * frequently requested values.
 164.568 -     *
 164.569 -     * Note that unlike the {@linkplain Integer#valueOf(int)
 164.570 -     * corresponding method} in the {@code Integer} class, this method
 164.571 -     * is <em>not</em> required to cache values within a particular
 164.572 -     * range.
 164.573 -     *
 164.574 -     * @param  l a long value.
 164.575 -     * @return a {@code Long} instance representing {@code l}.
 164.576 -     * @since  1.5
 164.577 -     */
 164.578 -    public static Long valueOf(long l) {
 164.579 -        final int offset = 128;
 164.580 -        if (l >= -128 && l <= 127) { // will cache
 164.581 -            return LongCache.cache[(int)l + offset];
 164.582 -        }
 164.583 -        return new Long(l);
 164.584 -    }
 164.585 -
 164.586 -    /**
 164.587 -     * Decodes a {@code String} into a {@code Long}.
 164.588 -     * Accepts decimal, hexadecimal, and octal numbers given by the
 164.589 -     * following grammar:
 164.590 -     *
 164.591 -     * <blockquote>
 164.592 -     * <dl>
 164.593 -     * <dt><i>DecodableString:</i>
 164.594 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 164.595 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 164.596 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 164.597 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 164.598 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 164.599 -     * <p>
 164.600 -     * <dt><i>Sign:</i>
 164.601 -     * <dd>{@code -}
 164.602 -     * <dd>{@code +}
 164.603 -     * </dl>
 164.604 -     * </blockquote>
 164.605 -     *
 164.606 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 164.607 -     * are as defined in section 3.10.1 of
 164.608 -     * <cite>The Java&trade; Language Specification</cite>,
 164.609 -     * except that underscores are not accepted between digits.
 164.610 -     *
 164.611 -     * <p>The sequence of characters following an optional
 164.612 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 164.613 -     * "{@code #}", or leading zero) is parsed as by the {@code
 164.614 -     * Long.parseLong} method with the indicated radix (10, 16, or 8).
 164.615 -     * This sequence of characters must represent a positive value or
 164.616 -     * a {@link NumberFormatException} will be thrown.  The result is
 164.617 -     * negated if first character of the specified {@code String} is
 164.618 -     * the minus sign.  No whitespace characters are permitted in the
 164.619 -     * {@code String}.
 164.620 -     *
 164.621 -     * @param     nm the {@code String} to decode.
 164.622 -     * @return    a {@code Long} object holding the {@code long}
 164.623 -     *            value represented by {@code nm}
 164.624 -     * @throws    NumberFormatException  if the {@code String} does not
 164.625 -     *            contain a parsable {@code long}.
 164.626 -     * @see java.lang.Long#parseLong(String, int)
 164.627 -     * @since 1.2
 164.628 -     */
 164.629 -    public static Long decode(String nm) throws NumberFormatException {
 164.630 -        int radix = 10;
 164.631 -        int index = 0;
 164.632 -        boolean negative = false;
 164.633 -        Long result;
 164.634 -
 164.635 -        if (nm.length() == 0)
 164.636 -            throw new NumberFormatException("Zero length string");
 164.637 -        char firstChar = nm.charAt(0);
 164.638 -        // Handle sign, if present
 164.639 -        if (firstChar == '-') {
 164.640 -            negative = true;
 164.641 -            index++;
 164.642 -        } else if (firstChar == '+')
 164.643 -            index++;
 164.644 -
 164.645 -        // Handle radix specifier, if present
 164.646 -        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 164.647 -            index += 2;
 164.648 -            radix = 16;
 164.649 -        }
 164.650 -        else if (nm.startsWith("#", index)) {
 164.651 -            index ++;
 164.652 -            radix = 16;
 164.653 -        }
 164.654 -        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 164.655 -            index ++;
 164.656 -            radix = 8;
 164.657 -        }
 164.658 -
 164.659 -        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 164.660 -            throw new NumberFormatException("Sign character in wrong position");
 164.661 -
 164.662 -        try {
 164.663 -            result = Long.valueOf(nm.substring(index), radix);
 164.664 -            result = negative ? Long.valueOf(-result.longValue()) : result;
 164.665 -        } catch (NumberFormatException e) {
 164.666 -            // If number is Long.MIN_VALUE, we'll end up here. The next line
 164.667 -            // handles this case, and causes any genuine format error to be
 164.668 -            // rethrown.
 164.669 -            String constant = negative ? ("-" + nm.substring(index))
 164.670 -                                       : nm.substring(index);
 164.671 -            result = Long.valueOf(constant, radix);
 164.672 -        }
 164.673 -        return result;
 164.674 -    }
 164.675 -
 164.676 -    /**
 164.677 -     * The value of the {@code Long}.
 164.678 -     *
 164.679 -     * @serial
 164.680 -     */
 164.681 -    private final long value;
 164.682 -
 164.683 -    /**
 164.684 -     * Constructs a newly allocated {@code Long} object that
 164.685 -     * represents the specified {@code long} argument.
 164.686 -     *
 164.687 -     * @param   value   the value to be represented by the
 164.688 -     *          {@code Long} object.
 164.689 -     */
 164.690 -    public Long(long value) {
 164.691 -        this.value = value;
 164.692 -    }
 164.693 -
 164.694 -    /**
 164.695 -     * Constructs a newly allocated {@code Long} object that
 164.696 -     * represents the {@code long} value indicated by the
 164.697 -     * {@code String} parameter. The string is converted to a
 164.698 -     * {@code long} value in exactly the manner used by the
 164.699 -     * {@code parseLong} method for radix 10.
 164.700 -     *
 164.701 -     * @param      s   the {@code String} to be converted to a
 164.702 -     *             {@code Long}.
 164.703 -     * @throws     NumberFormatException  if the {@code String} does not
 164.704 -     *             contain a parsable {@code long}.
 164.705 -     * @see        java.lang.Long#parseLong(java.lang.String, int)
 164.706 -     */
 164.707 -    public Long(String s) throws NumberFormatException {
 164.708 -        this.value = parseLong(s, 10);
 164.709 -    }
 164.710 -
 164.711 -    /**
 164.712 -     * Returns the value of this {@code Long} as a
 164.713 -     * {@code byte}.
 164.714 -     */
 164.715 -    public byte byteValue() {
 164.716 -        return (byte)value;
 164.717 -    }
 164.718 -
 164.719 -    /**
 164.720 -     * Returns the value of this {@code Long} as a
 164.721 -     * {@code short}.
 164.722 -     */
 164.723 -    public short shortValue() {
 164.724 -        return (short)value;
 164.725 -    }
 164.726 -
 164.727 -    /**
 164.728 -     * Returns the value of this {@code Long} as an
 164.729 -     * {@code int}.
 164.730 -     */
 164.731 -    public int intValue() {
 164.732 -        return (int)value;
 164.733 -    }
 164.734 -
 164.735 -    /**
 164.736 -     * Returns the value of this {@code Long} as a
 164.737 -     * {@code long} value.
 164.738 -     */
 164.739 -    public long longValue() {
 164.740 -        return (long)value;
 164.741 -    }
 164.742 -
 164.743 -    /**
 164.744 -     * Returns the value of this {@code Long} as a
 164.745 -     * {@code float}.
 164.746 -     */
 164.747 -    public float floatValue() {
 164.748 -        return (float)value;
 164.749 -    }
 164.750 -
 164.751 -    /**
 164.752 -     * Returns the value of this {@code Long} as a
 164.753 -     * {@code double}.
 164.754 -     */
 164.755 -    public double doubleValue() {
 164.756 -        return (double)value;
 164.757 -    }
 164.758 -
 164.759 -    /**
 164.760 -     * Returns a {@code String} object representing this
 164.761 -     * {@code Long}'s value.  The value is converted to signed
 164.762 -     * decimal representation and returned as a string, exactly as if
 164.763 -     * the {@code long} value were given as an argument to the
 164.764 -     * {@link java.lang.Long#toString(long)} method.
 164.765 -     *
 164.766 -     * @return  a string representation of the value of this object in
 164.767 -     *          base&nbsp;10.
 164.768 -     */
 164.769 -    public String toString() {
 164.770 -        return toString(value);
 164.771 -    }
 164.772 -
 164.773 -    /**
 164.774 -     * Returns a hash code for this {@code Long}. The result is
 164.775 -     * the exclusive OR of the two halves of the primitive
 164.776 -     * {@code long} value held by this {@code Long}
 164.777 -     * object. That is, the hashcode is the value of the expression:
 164.778 -     *
 164.779 -     * <blockquote>
 164.780 -     *  {@code (int)(this.longValue()^(this.longValue()>>>32))}
 164.781 -     * </blockquote>
 164.782 -     *
 164.783 -     * @return  a hash code value for this object.
 164.784 -     */
 164.785 -    public int hashCode() {
 164.786 -        return (int)(value ^ (value >>> 32));
 164.787 -    }
 164.788 -
 164.789 -    /**
 164.790 -     * Compares this object to the specified object.  The result is
 164.791 -     * {@code true} if and only if the argument is not
 164.792 -     * {@code null} and is a {@code Long} object that
 164.793 -     * contains the same {@code long} value as this object.
 164.794 -     *
 164.795 -     * @param   obj   the object to compare with.
 164.796 -     * @return  {@code true} if the objects are the same;
 164.797 -     *          {@code false} otherwise.
 164.798 -     */
 164.799 -    public boolean equals(Object obj) {
 164.800 -        if (obj instanceof Long) {
 164.801 -            return value == ((Long)obj).longValue();
 164.802 -        }
 164.803 -        return false;
 164.804 -    }
 164.805 -
 164.806 -    /**
 164.807 -     * Determines the {@code long} value of the system property
 164.808 -     * with the specified name.
 164.809 -     *
 164.810 -     * <p>The first argument is treated as the name of a system property.
 164.811 -     * System properties are accessible through the {@link
 164.812 -     * java.lang.System#getProperty(java.lang.String)} method. The
 164.813 -     * string value of this property is then interpreted as a
 164.814 -     * {@code long} value and a {@code Long} object
 164.815 -     * representing this value is returned.  Details of possible
 164.816 -     * numeric formats can be found with the definition of
 164.817 -     * {@code getProperty}.
 164.818 -     *
 164.819 -     * <p>If there is no property with the specified name, if the
 164.820 -     * specified name is empty or {@code null}, or if the
 164.821 -     * property does not have the correct numeric format, then
 164.822 -     * {@code null} is returned.
 164.823 -     *
 164.824 -     * <p>In other words, this method returns a {@code Long} object equal to
 164.825 -     * the value of:
 164.826 -     *
 164.827 -     * <blockquote>
 164.828 -     *  {@code getLong(nm, null)}
 164.829 -     * </blockquote>
 164.830 -     *
 164.831 -     * @param   nm   property name.
 164.832 -     * @return  the {@code Long} value of the property.
 164.833 -     * @see     java.lang.System#getProperty(java.lang.String)
 164.834 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 164.835 -     */
 164.836 -    public static Long getLong(String nm) {
 164.837 -        return getLong(nm, null);
 164.838 -    }
 164.839 -
 164.840 -    /**
 164.841 -     * Determines the {@code long} value of the system property
 164.842 -     * with the specified name.
 164.843 -     *
 164.844 -     * <p>The first argument is treated as the name of a system property.
 164.845 -     * System properties are accessible through the {@link
 164.846 -     * java.lang.System#getProperty(java.lang.String)} method. The
 164.847 -     * string value of this property is then interpreted as a
 164.848 -     * {@code long} value and a {@code Long} object
 164.849 -     * representing this value is returned.  Details of possible
 164.850 -     * numeric formats can be found with the definition of
 164.851 -     * {@code getProperty}.
 164.852 -     *
 164.853 -     * <p>The second argument is the default value. A {@code Long} object
 164.854 -     * that represents the value of the second argument is returned if there
 164.855 -     * is no property of the specified name, if the property does not have
 164.856 -     * the correct numeric format, or if the specified name is empty or null.
 164.857 -     *
 164.858 -     * <p>In other words, this method returns a {@code Long} object equal
 164.859 -     * to the value of:
 164.860 -     *
 164.861 -     * <blockquote>
 164.862 -     *  {@code getLong(nm, new Long(val))}
 164.863 -     * </blockquote>
 164.864 -     *
 164.865 -     * but in practice it may be implemented in a manner such as:
 164.866 -     *
 164.867 -     * <blockquote><pre>
 164.868 -     * Long result = getLong(nm, null);
 164.869 -     * return (result == null) ? new Long(val) : result;
 164.870 -     * </pre></blockquote>
 164.871 -     *
 164.872 -     * to avoid the unnecessary allocation of a {@code Long} object when
 164.873 -     * the default value is not needed.
 164.874 -     *
 164.875 -     * @param   nm    property name.
 164.876 -     * @param   val   default value.
 164.877 -     * @return  the {@code Long} value of the property.
 164.878 -     * @see     java.lang.System#getProperty(java.lang.String)
 164.879 -     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 164.880 -     */
 164.881 -    public static Long getLong(String nm, long val) {
 164.882 -        Long result = Long.getLong(nm, null);
 164.883 -        return (result == null) ? Long.valueOf(val) : result;
 164.884 -    }
 164.885 -
 164.886 -    /**
 164.887 -     * Returns the {@code long} value of the system property with
 164.888 -     * the specified name.  The first argument is treated as the name
 164.889 -     * of a system property.  System properties are accessible through
 164.890 -     * the {@link java.lang.System#getProperty(java.lang.String)}
 164.891 -     * method. The string value of this property is then interpreted
 164.892 -     * as a {@code long} value, as per the
 164.893 -     * {@code Long.decode} method, and a {@code Long} object
 164.894 -     * representing this value is returned.
 164.895 -     *
 164.896 -     * <ul>
 164.897 -     * <li>If the property value begins with the two ASCII characters
 164.898 -     * {@code 0x} or the ASCII character {@code #}, not followed by
 164.899 -     * a minus sign, then the rest of it is parsed as a hexadecimal integer
 164.900 -     * exactly as for the method {@link #valueOf(java.lang.String, int)}
 164.901 -     * with radix 16.
 164.902 -     * <li>If the property value begins with the ASCII character
 164.903 -     * {@code 0} followed by another character, it is parsed as
 164.904 -     * an octal integer exactly as by the method {@link
 164.905 -     * #valueOf(java.lang.String, int)} with radix 8.
 164.906 -     * <li>Otherwise the property value is parsed as a decimal
 164.907 -     * integer exactly as by the method
 164.908 -     * {@link #valueOf(java.lang.String, int)} with radix 10.
 164.909 -     * </ul>
 164.910 -     *
 164.911 -     * <p>Note that, in every case, neither {@code L}
 164.912 -     * (<code>'&#92;u004C'</code>) nor {@code l}
 164.913 -     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 164.914 -     * of the property value as a type indicator, as would be
 164.915 -     * permitted in Java programming language source code.
 164.916 -     *
 164.917 -     * <p>The second argument is the default value. The default value is
 164.918 -     * returned if there is no property of the specified name, if the
 164.919 -     * property does not have the correct numeric format, or if the
 164.920 -     * specified name is empty or {@code null}.
 164.921 -     *
 164.922 -     * @param   nm   property name.
 164.923 -     * @param   val   default value.
 164.924 -     * @return  the {@code Long} value of the property.
 164.925 -     * @see     java.lang.System#getProperty(java.lang.String)
 164.926 -     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 164.927 -     * @see java.lang.Long#decode
 164.928 -     */
 164.929 -    public static Long getLong(String nm, Long val) {
 164.930 -        String v = null;
 164.931 -        try {
 164.932 -            v = AbstractStringBuilder.getProperty(nm);
 164.933 -        } catch (IllegalArgumentException e) {
 164.934 -        } catch (NullPointerException e) {
 164.935 -        }
 164.936 -        if (v != null) {
 164.937 -            try {
 164.938 -                return Long.decode(v);
 164.939 -            } catch (NumberFormatException e) {
 164.940 -            }
 164.941 -        }
 164.942 -        return val;
 164.943 -    }
 164.944 -
 164.945 -    /**
 164.946 -     * Compares two {@code Long} objects numerically.
 164.947 -     *
 164.948 -     * @param   anotherLong   the {@code Long} to be compared.
 164.949 -     * @return  the value {@code 0} if this {@code Long} is
 164.950 -     *          equal to the argument {@code Long}; a value less than
 164.951 -     *          {@code 0} if this {@code Long} is numerically less
 164.952 -     *          than the argument {@code Long}; and a value greater
 164.953 -     *          than {@code 0} if this {@code Long} is numerically
 164.954 -     *           greater than the argument {@code Long} (signed
 164.955 -     *           comparison).
 164.956 -     * @since   1.2
 164.957 -     */
 164.958 -    public int compareTo(Long anotherLong) {
 164.959 -        return compare(this.value, anotherLong.value);
 164.960 -    }
 164.961 -
 164.962 -    /**
 164.963 -     * Compares two {@code long} values numerically.
 164.964 -     * The value returned is identical to what would be returned by:
 164.965 -     * <pre>
 164.966 -     *    Long.valueOf(x).compareTo(Long.valueOf(y))
 164.967 -     * </pre>
 164.968 -     *
 164.969 -     * @param  x the first {@code long} to compare
 164.970 -     * @param  y the second {@code long} to compare
 164.971 -     * @return the value {@code 0} if {@code x == y};
 164.972 -     *         a value less than {@code 0} if {@code x < y}; and
 164.973 -     *         a value greater than {@code 0} if {@code x > y}
 164.974 -     * @since 1.7
 164.975 -     */
 164.976 -    public static int compare(long x, long y) {
 164.977 -        return (x < y) ? -1 : ((x == y) ? 0 : 1);
 164.978 -    }
 164.979 -
 164.980 -
 164.981 -    // Bit Twiddling
 164.982 -
 164.983 -    /**
 164.984 -     * The number of bits used to represent a {@code long} value in two's
 164.985 -     * complement binary form.
 164.986 -     *
 164.987 -     * @since 1.5
 164.988 -     */
 164.989 -    public static final int SIZE = 64;
 164.990 -
 164.991 -    /**
 164.992 -     * Returns a {@code long} value with at most a single one-bit, in the
 164.993 -     * position of the highest-order ("leftmost") one-bit in the specified
 164.994 -     * {@code long} value.  Returns zero if the specified value has no
 164.995 -     * one-bits in its two's complement binary representation, that is, if it
 164.996 -     * is equal to zero.
 164.997 -     *
 164.998 -     * @return a {@code long} value with a single one-bit, in the position
 164.999 -     *     of the highest-order one-bit in the specified value, or zero if
164.1000 -     *     the specified value is itself equal to zero.
164.1001 -     * @since 1.5
164.1002 -     */
164.1003 -    public static long highestOneBit(long i) {
164.1004 -        // HD, Figure 3-1
164.1005 -        i |= (i >>  1);
164.1006 -        i |= (i >>  2);
164.1007 -        i |= (i >>  4);
164.1008 -        i |= (i >>  8);
164.1009 -        i |= (i >> 16);
164.1010 -        i |= (i >> 32);
164.1011 -        return i - (i >>> 1);
164.1012 -    }
164.1013 -
164.1014 -    /**
164.1015 -     * Returns a {@code long} value with at most a single one-bit, in the
164.1016 -     * position of the lowest-order ("rightmost") one-bit in the specified
164.1017 -     * {@code long} value.  Returns zero if the specified value has no
164.1018 -     * one-bits in its two's complement binary representation, that is, if it
164.1019 -     * is equal to zero.
164.1020 -     *
164.1021 -     * @return a {@code long} value with a single one-bit, in the position
164.1022 -     *     of the lowest-order one-bit in the specified value, or zero if
164.1023 -     *     the specified value is itself equal to zero.
164.1024 -     * @since 1.5
164.1025 -     */
164.1026 -    public static long lowestOneBit(long i) {
164.1027 -        // HD, Section 2-1
164.1028 -        return i & -i;
164.1029 -    }
164.1030 -
164.1031 -    /**
164.1032 -     * Returns the number of zero bits preceding the highest-order
164.1033 -     * ("leftmost") one-bit in the two's complement binary representation
164.1034 -     * of the specified {@code long} value.  Returns 64 if the
164.1035 -     * specified value has no one-bits in its two's complement representation,
164.1036 -     * in other words if it is equal to zero.
164.1037 -     *
164.1038 -     * <p>Note that this method is closely related to the logarithm base 2.
164.1039 -     * For all positive {@code long} values x:
164.1040 -     * <ul>
164.1041 -     * <li>floor(log<sub>2</sub>(x)) = {@code 63 - numberOfLeadingZeros(x)}
164.1042 -     * <li>ceil(log<sub>2</sub>(x)) = {@code 64 - numberOfLeadingZeros(x - 1)}
164.1043 -     * </ul>
164.1044 -     *
164.1045 -     * @return the number of zero bits preceding the highest-order
164.1046 -     *     ("leftmost") one-bit in the two's complement binary representation
164.1047 -     *     of the specified {@code long} value, or 64 if the value
164.1048 -     *     is equal to zero.
164.1049 -     * @since 1.5
164.1050 -     */
164.1051 -    public static int numberOfLeadingZeros(long i) {
164.1052 -        // HD, Figure 5-6
164.1053 -         if (i == 0)
164.1054 -            return 64;
164.1055 -        int n = 1;
164.1056 -        int x = (int)(i >>> 32);
164.1057 -        if (x == 0) { n += 32; x = (int)i; }
164.1058 -        if (x >>> 16 == 0) { n += 16; x <<= 16; }
164.1059 -        if (x >>> 24 == 0) { n +=  8; x <<=  8; }
164.1060 -        if (x >>> 28 == 0) { n +=  4; x <<=  4; }
164.1061 -        if (x >>> 30 == 0) { n +=  2; x <<=  2; }
164.1062 -        n -= x >>> 31;
164.1063 -        return n;
164.1064 -    }
164.1065 -
164.1066 -    /**
164.1067 -     * Returns the number of zero bits following the lowest-order ("rightmost")
164.1068 -     * one-bit in the two's complement binary representation of the specified
164.1069 -     * {@code long} value.  Returns 64 if the specified value has no
164.1070 -     * one-bits in its two's complement representation, in other words if it is
164.1071 -     * equal to zero.
164.1072 -     *
164.1073 -     * @return the number of zero bits following the lowest-order ("rightmost")
164.1074 -     *     one-bit in the two's complement binary representation of the
164.1075 -     *     specified {@code long} value, or 64 if the value is equal
164.1076 -     *     to zero.
164.1077 -     * @since 1.5
164.1078 -     */
164.1079 -    public static int numberOfTrailingZeros(long i) {
164.1080 -        // HD, Figure 5-14
164.1081 -        int x, y;
164.1082 -        if (i == 0) return 64;
164.1083 -        int n = 63;
164.1084 -        y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
164.1085 -        y = x <<16; if (y != 0) { n = n -16; x = y; }
164.1086 -        y = x << 8; if (y != 0) { n = n - 8; x = y; }
164.1087 -        y = x << 4; if (y != 0) { n = n - 4; x = y; }
164.1088 -        y = x << 2; if (y != 0) { n = n - 2; x = y; }
164.1089 -        return n - ((x << 1) >>> 31);
164.1090 -    }
164.1091 -
164.1092 -    /**
164.1093 -     * Returns the number of one-bits in the two's complement binary
164.1094 -     * representation of the specified {@code long} value.  This function is
164.1095 -     * sometimes referred to as the <i>population count</i>.
164.1096 -     *
164.1097 -     * @return the number of one-bits in the two's complement binary
164.1098 -     *     representation of the specified {@code long} value.
164.1099 -     * @since 1.5
164.1100 -     */
164.1101 -     public static int bitCount(long i) {
164.1102 -        // HD, Figure 5-14
164.1103 -        i = i - ((i >>> 1) & 0x5555555555555555L);
164.1104 -        i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
164.1105 -        i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
164.1106 -        i = i + (i >>> 8);
164.1107 -        i = i + (i >>> 16);
164.1108 -        i = i + (i >>> 32);
164.1109 -        return (int)i & 0x7f;
164.1110 -     }
164.1111 -
164.1112 -    /**
164.1113 -     * Returns the value obtained by rotating the two's complement binary
164.1114 -     * representation of the specified {@code long} value left by the
164.1115 -     * specified number of bits.  (Bits shifted out of the left hand, or
164.1116 -     * high-order, side reenter on the right, or low-order.)
164.1117 -     *
164.1118 -     * <p>Note that left rotation with a negative distance is equivalent to
164.1119 -     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
164.1120 -     * distance)}.  Note also that rotation by any multiple of 64 is a
164.1121 -     * no-op, so all but the last six bits of the rotation distance can be
164.1122 -     * ignored, even if the distance is negative: {@code rotateLeft(val,
164.1123 -     * distance) == rotateLeft(val, distance & 0x3F)}.
164.1124 -     *
164.1125 -     * @return the value obtained by rotating the two's complement binary
164.1126 -     *     representation of the specified {@code long} value left by the
164.1127 -     *     specified number of bits.
164.1128 -     * @since 1.5
164.1129 -     */
164.1130 -    public static long rotateLeft(long i, int distance) {
164.1131 -        return (i << distance) | (i >>> -distance);
164.1132 -    }
164.1133 -
164.1134 -    /**
164.1135 -     * Returns the value obtained by rotating the two's complement binary
164.1136 -     * representation of the specified {@code long} value right by the
164.1137 -     * specified number of bits.  (Bits shifted out of the right hand, or
164.1138 -     * low-order, side reenter on the left, or high-order.)
164.1139 -     *
164.1140 -     * <p>Note that right rotation with a negative distance is equivalent to
164.1141 -     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
164.1142 -     * distance)}.  Note also that rotation by any multiple of 64 is a
164.1143 -     * no-op, so all but the last six bits of the rotation distance can be
164.1144 -     * ignored, even if the distance is negative: {@code rotateRight(val,
164.1145 -     * distance) == rotateRight(val, distance & 0x3F)}.
164.1146 -     *
164.1147 -     * @return the value obtained by rotating the two's complement binary
164.1148 -     *     representation of the specified {@code long} value right by the
164.1149 -     *     specified number of bits.
164.1150 -     * @since 1.5
164.1151 -     */
164.1152 -    public static long rotateRight(long i, int distance) {
164.1153 -        return (i >>> distance) | (i << -distance);
164.1154 -    }
164.1155 -
164.1156 -    /**
164.1157 -     * Returns the value obtained by reversing the order of the bits in the
164.1158 -     * two's complement binary representation of the specified {@code long}
164.1159 -     * value.
164.1160 -     *
164.1161 -     * @return the value obtained by reversing order of the bits in the
164.1162 -     *     specified {@code long} value.
164.1163 -     * @since 1.5
164.1164 -     */
164.1165 -    public static long reverse(long i) {
164.1166 -        // HD, Figure 7-1
164.1167 -        i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
164.1168 -        i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
164.1169 -        i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
164.1170 -        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
164.1171 -        i = (i << 48) | ((i & 0xffff0000L) << 16) |
164.1172 -            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
164.1173 -        return i;
164.1174 -    }
164.1175 -
164.1176 -    /**
164.1177 -     * Returns the signum function of the specified {@code long} value.  (The
164.1178 -     * return value is -1 if the specified value is negative; 0 if the
164.1179 -     * specified value is zero; and 1 if the specified value is positive.)
164.1180 -     *
164.1181 -     * @return the signum function of the specified {@code long} value.
164.1182 -     * @since 1.5
164.1183 -     */
164.1184 -    public static int signum(long i) {
164.1185 -        // HD, Section 2-7
164.1186 -        return (int) ((i >> 63) | (-i >>> 63));
164.1187 -    }
164.1188 -
164.1189 -    /**
164.1190 -     * Returns the value obtained by reversing the order of the bytes in the
164.1191 -     * two's complement representation of the specified {@code long} value.
164.1192 -     *
164.1193 -     * @return the value obtained by reversing the bytes in the specified
164.1194 -     *     {@code long} value.
164.1195 -     * @since 1.5
164.1196 -     */
164.1197 -    public static long reverseBytes(long i) {
164.1198 -        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
164.1199 -        return (i << 48) | ((i & 0xffff0000L) << 16) |
164.1200 -            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
164.1201 -    }
164.1202 -
164.1203 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
164.1204 -    private static final long serialVersionUID = 4290774380558885855L;
164.1205 -}
   165.1 --- a/emul/mini/src/main/java/java/lang/Math.java	Mon Feb 25 19:00:08 2013 +0100
   165.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   165.3 @@ -1,1310 +0,0 @@
   165.4 -/*
   165.5 - * Copyright (c) 1994, 2011, 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;
  165.30 -
  165.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  165.32 -
  165.33 -
  165.34 -/**
  165.35 - * The class {@code Math} contains methods for performing basic
  165.36 - * numeric operations such as the elementary exponential, logarithm,
  165.37 - * square root, and trigonometric functions.
  165.38 - *
  165.39 - * <p>Unlike some of the numeric methods of class
  165.40 - * {@code StrictMath}, all implementations of the equivalent
  165.41 - * functions of class {@code Math} are not defined to return the
  165.42 - * bit-for-bit same results.  This relaxation permits
  165.43 - * better-performing implementations where strict reproducibility is
  165.44 - * not required.
  165.45 - *
  165.46 - * <p>By default many of the {@code Math} methods simply call
  165.47 - * the equivalent method in {@code StrictMath} for their
  165.48 - * implementation.  Code generators are encouraged to use
  165.49 - * platform-specific native libraries or microprocessor instructions,
  165.50 - * where available, to provide higher-performance implementations of
  165.51 - * {@code Math} methods.  Such higher-performance
  165.52 - * implementations still must conform to the specification for
  165.53 - * {@code Math}.
  165.54 - *
  165.55 - * <p>The quality of implementation specifications concern two
  165.56 - * properties, accuracy of the returned result and monotonicity of the
  165.57 - * method.  Accuracy of the floating-point {@code Math} methods
  165.58 - * is measured in terms of <i>ulps</i>, units in the last place.  For
  165.59 - * a given floating-point format, an ulp of a specific real number
  165.60 - * value is the distance between the two floating-point values
  165.61 - * bracketing that numerical value.  When discussing the accuracy of a
  165.62 - * method as a whole rather than at a specific argument, the number of
  165.63 - * ulps cited is for the worst-case error at any argument.  If a
  165.64 - * method always has an error less than 0.5 ulps, the method always
  165.65 - * returns the floating-point number nearest the exact result; such a
  165.66 - * method is <i>correctly rounded</i>.  A correctly rounded method is
  165.67 - * generally the best a floating-point approximation can be; however,
  165.68 - * it is impractical for many floating-point methods to be correctly
  165.69 - * rounded.  Instead, for the {@code Math} class, a larger error
  165.70 - * bound of 1 or 2 ulps is allowed for certain methods.  Informally,
  165.71 - * with a 1 ulp error bound, when the exact result is a representable
  165.72 - * number, the exact result should be returned as the computed result;
  165.73 - * otherwise, either of the two floating-point values which bracket
  165.74 - * the exact result may be returned.  For exact results large in
  165.75 - * magnitude, one of the endpoints of the bracket may be infinite.
  165.76 - * Besides accuracy at individual arguments, maintaining proper
  165.77 - * relations between the method at different arguments is also
  165.78 - * important.  Therefore, most methods with more than 0.5 ulp errors
  165.79 - * are required to be <i>semi-monotonic</i>: whenever the mathematical
  165.80 - * function is non-decreasing, so is the floating-point approximation,
  165.81 - * likewise, whenever the mathematical function is non-increasing, so
  165.82 - * is the floating-point approximation.  Not all approximations that
  165.83 - * have 1 ulp accuracy will automatically meet the monotonicity
  165.84 - * requirements.
  165.85 - *
  165.86 - * @author  unascribed
  165.87 - * @author  Joseph D. Darcy
  165.88 - * @since   JDK1.0
  165.89 - */
  165.90 -
  165.91 -public final class Math {
  165.92 -
  165.93 -    /**
  165.94 -     * Don't let anyone instantiate this class.
  165.95 -     */
  165.96 -    private Math() {}
  165.97 -
  165.98 -    /**
  165.99 -     * The {@code double} value that is closer than any other to
 165.100 -     * <i>e</i>, the base of the natural logarithms.
 165.101 -     */
 165.102 -    public static final double E = 2.7182818284590452354;
 165.103 -
 165.104 -    /**
 165.105 -     * The {@code double} value that is closer than any other to
 165.106 -     * <i>pi</i>, the ratio of the circumference of a circle to its
 165.107 -     * diameter.
 165.108 -     */
 165.109 -    public static final double PI = 3.14159265358979323846;
 165.110 -
 165.111 -    /**
 165.112 -     * Returns the trigonometric sine of an angle.  Special cases:
 165.113 -     * <ul><li>If the argument is NaN or an infinity, then the
 165.114 -     * result is NaN.
 165.115 -     * <li>If the argument is zero, then the result is a zero with the
 165.116 -     * same sign as the argument.</ul>
 165.117 -     *
 165.118 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.119 -     * Results must be semi-monotonic.
 165.120 -     *
 165.121 -     * @param   a   an angle, in radians.
 165.122 -     * @return  the sine of the argument.
 165.123 -     */
 165.124 -    @JavaScriptBody(args="a", body="return Math.sin(a);")
 165.125 -    public static double sin(double a) {
 165.126 -        throw new UnsupportedOperationException();
 165.127 -    }
 165.128 -
 165.129 -    /**
 165.130 -     * Returns the trigonometric cosine of an angle. Special cases:
 165.131 -     * <ul><li>If the argument is NaN or an infinity, then the
 165.132 -     * result is NaN.</ul>
 165.133 -     *
 165.134 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.135 -     * Results must be semi-monotonic.
 165.136 -     *
 165.137 -     * @param   a   an angle, in radians.
 165.138 -     * @return  the cosine of the argument.
 165.139 -     */
 165.140 -    @JavaScriptBody(args="a", body="return Math.cos(a);")
 165.141 -    public static double cos(double a) {
 165.142 -        throw new UnsupportedOperationException();
 165.143 -    }
 165.144 -
 165.145 -    /**
 165.146 -     * Returns the trigonometric tangent of an angle.  Special cases:
 165.147 -     * <ul><li>If the argument is NaN or an infinity, then the result
 165.148 -     * is NaN.
 165.149 -     * <li>If the argument is zero, then the result is a zero with the
 165.150 -     * same sign as the argument.</ul>
 165.151 -     *
 165.152 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.153 -     * Results must be semi-monotonic.
 165.154 -     *
 165.155 -     * @param   a   an angle, in radians.
 165.156 -     * @return  the tangent of the argument.
 165.157 -     */
 165.158 -    @JavaScriptBody(args="a", body="return Math.tan(a);")
 165.159 -    public static double tan(double a) {
 165.160 -        throw new UnsupportedOperationException();
 165.161 -    }
 165.162 -
 165.163 -    /**
 165.164 -     * Returns the arc sine of a value; the returned angle is in the
 165.165 -     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 165.166 -     * <ul><li>If the argument is NaN or its absolute value is greater
 165.167 -     * than 1, then the result is NaN.
 165.168 -     * <li>If the argument is zero, then the result is a zero with the
 165.169 -     * same sign as the argument.</ul>
 165.170 -     *
 165.171 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.172 -     * Results must be semi-monotonic.
 165.173 -     *
 165.174 -     * @param   a   the value whose arc sine is to be returned.
 165.175 -     * @return  the arc sine of the argument.
 165.176 -     */
 165.177 -    @JavaScriptBody(args="a", body="return Math.asin(a);")
 165.178 -    public static double asin(double a) {
 165.179 -        throw new UnsupportedOperationException();
 165.180 -    }
 165.181 -
 165.182 -    /**
 165.183 -     * Returns the arc cosine of a value; the returned angle is in the
 165.184 -     * range 0.0 through <i>pi</i>.  Special case:
 165.185 -     * <ul><li>If the argument is NaN or its absolute value is greater
 165.186 -     * than 1, then the result is NaN.</ul>
 165.187 -     *
 165.188 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.189 -     * Results must be semi-monotonic.
 165.190 -     *
 165.191 -     * @param   a   the value whose arc cosine is to be returned.
 165.192 -     * @return  the arc cosine of the argument.
 165.193 -     */
 165.194 -    @JavaScriptBody(args="a", body="return Math.acos(a);")
 165.195 -    public static double acos(double a) {
 165.196 -        throw new UnsupportedOperationException();
 165.197 -    }
 165.198 -
 165.199 -    /**
 165.200 -     * Returns the arc tangent of a value; the returned angle is in the
 165.201 -     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 165.202 -     * <ul><li>If the argument is NaN, then the result is NaN.
 165.203 -     * <li>If the argument is zero, then the result is a zero with the
 165.204 -     * same sign as the argument.</ul>
 165.205 -     *
 165.206 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.207 -     * Results must be semi-monotonic.
 165.208 -     *
 165.209 -     * @param   a   the value whose arc tangent is to be returned.
 165.210 -     * @return  the arc tangent of the argument.
 165.211 -     */
 165.212 -    @JavaScriptBody(args="a", body="return Math.atan(a);")
 165.213 -    public static double atan(double a) {
 165.214 -        throw new UnsupportedOperationException();
 165.215 -    }
 165.216 -
 165.217 -    /**
 165.218 -     * Converts an angle measured in degrees to an approximately
 165.219 -     * equivalent angle measured in radians.  The conversion from
 165.220 -     * degrees to radians is generally inexact.
 165.221 -     *
 165.222 -     * @param   angdeg   an angle, in degrees
 165.223 -     * @return  the measurement of the angle {@code angdeg}
 165.224 -     *          in radians.
 165.225 -     * @since   1.2
 165.226 -     */
 165.227 -    public static double toRadians(double angdeg) {
 165.228 -        return angdeg / 180.0 * PI;
 165.229 -    }
 165.230 -
 165.231 -    /**
 165.232 -     * Converts an angle measured in radians to an approximately
 165.233 -     * equivalent angle measured in degrees.  The conversion from
 165.234 -     * radians to degrees is generally inexact; users should
 165.235 -     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
 165.236 -     * equal {@code 0.0}.
 165.237 -     *
 165.238 -     * @param   angrad   an angle, in radians
 165.239 -     * @return  the measurement of the angle {@code angrad}
 165.240 -     *          in degrees.
 165.241 -     * @since   1.2
 165.242 -     */
 165.243 -    public static double toDegrees(double angrad) {
 165.244 -        return angrad * 180.0 / PI;
 165.245 -    }
 165.246 -
 165.247 -    /**
 165.248 -     * Returns Euler's number <i>e</i> raised to the power of a
 165.249 -     * {@code double} value.  Special cases:
 165.250 -     * <ul><li>If the argument is NaN, the result is NaN.
 165.251 -     * <li>If the argument is positive infinity, then the result is
 165.252 -     * positive infinity.
 165.253 -     * <li>If the argument is negative infinity, then the result is
 165.254 -     * positive zero.</ul>
 165.255 -     *
 165.256 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.257 -     * Results must be semi-monotonic.
 165.258 -     *
 165.259 -     * @param   a   the exponent to raise <i>e</i> to.
 165.260 -     * @return  the value <i>e</i><sup>{@code a}</sup>,
 165.261 -     *          where <i>e</i> is the base of the natural logarithms.
 165.262 -     */
 165.263 -    @JavaScriptBody(args="a", body="return Math.exp(a);")
 165.264 -    public static double exp(double a) {
 165.265 -        throw new UnsupportedOperationException();
 165.266 -    }
 165.267 -
 165.268 -    /**
 165.269 -     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
 165.270 -     * value.  Special cases:
 165.271 -     * <ul><li>If the argument is NaN or less than zero, then the result
 165.272 -     * is NaN.
 165.273 -     * <li>If the argument is positive infinity, then the result is
 165.274 -     * positive infinity.
 165.275 -     * <li>If the argument is positive zero or negative zero, then the
 165.276 -     * result is negative infinity.</ul>
 165.277 -     *
 165.278 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.279 -     * Results must be semi-monotonic.
 165.280 -     *
 165.281 -     * @param   a   a value
 165.282 -     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
 165.283 -     *          {@code a}.
 165.284 -     */
 165.285 -    @JavaScriptBody(args="a", body="return Math.log(a);")
 165.286 -    public static double log(double a) {
 165.287 -        throw new UnsupportedOperationException();
 165.288 -    }
 165.289 -
 165.290 -    /**
 165.291 -     * Returns the base 10 logarithm of a {@code double} value.
 165.292 -     * Special cases:
 165.293 -     *
 165.294 -     * <ul><li>If the argument is NaN or less than zero, then the result
 165.295 -     * is NaN.
 165.296 -     * <li>If the argument is positive infinity, then the result is
 165.297 -     * positive infinity.
 165.298 -     * <li>If the argument is positive zero or negative zero, then the
 165.299 -     * result is negative infinity.
 165.300 -     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
 165.301 -     * integer <i>n</i>, then the result is <i>n</i>.
 165.302 -     * </ul>
 165.303 -     *
 165.304 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.305 -     * Results must be semi-monotonic.
 165.306 -     *
 165.307 -     * @param   a   a value
 165.308 -     * @return  the base 10 logarithm of  {@code a}.
 165.309 -     * @since 1.5
 165.310 -     */
 165.311 -    @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
 165.312 -    public static double log10(double a) {
 165.313 -        throw new UnsupportedOperationException();
 165.314 -    }
 165.315 -
 165.316 -    /**
 165.317 -     * Returns the correctly rounded positive square root of a
 165.318 -     * {@code double} value.
 165.319 -     * Special cases:
 165.320 -     * <ul><li>If the argument is NaN or less than zero, then the result
 165.321 -     * is NaN.
 165.322 -     * <li>If the argument is positive infinity, then the result is positive
 165.323 -     * infinity.
 165.324 -     * <li>If the argument is positive zero or negative zero, then the
 165.325 -     * result is the same as the argument.</ul>
 165.326 -     * Otherwise, the result is the {@code double} value closest to
 165.327 -     * the true mathematical square root of the argument value.
 165.328 -     *
 165.329 -     * @param   a   a value.
 165.330 -     * @return  the positive square root of {@code a}.
 165.331 -     *          If the argument is NaN or less than zero, the result is NaN.
 165.332 -     */
 165.333 -    @JavaScriptBody(args="a", body="return Math.sqrt(a);")
 165.334 -    public static double sqrt(double a) {
 165.335 -        throw new UnsupportedOperationException();
 165.336 -    }
 165.337 -
 165.338 -    /**
 165.339 -     * Returns the smallest (closest to negative infinity)
 165.340 -     * {@code double} value that is greater than or equal to the
 165.341 -     * argument and is equal to a mathematical integer. Special cases:
 165.342 -     * <ul><li>If the argument value is already equal to a
 165.343 -     * mathematical integer, then the result is the same as the
 165.344 -     * argument.  <li>If the argument is NaN or an infinity or
 165.345 -     * positive zero or negative zero, then the result is the same as
 165.346 -     * the argument.  <li>If the argument value is less than zero but
 165.347 -     * greater than -1.0, then the result is negative zero.</ul> Note
 165.348 -     * that the value of {@code Math.ceil(x)} is exactly the
 165.349 -     * value of {@code -Math.floor(-x)}.
 165.350 -     *
 165.351 -     *
 165.352 -     * @param   a   a value.
 165.353 -     * @return  the smallest (closest to negative infinity)
 165.354 -     *          floating-point value that is greater than or equal to
 165.355 -     *          the argument and is equal to a mathematical integer.
 165.356 -     */
 165.357 -    @JavaScriptBody(args="a", body="return Math.ceil(a);")
 165.358 -    public static double ceil(double a) {
 165.359 -        throw new UnsupportedOperationException();
 165.360 -    }
 165.361 -
 165.362 -    /**
 165.363 -     * Returns the largest (closest to positive infinity)
 165.364 -     * {@code double} value that is less than or equal to the
 165.365 -     * argument and is equal to a mathematical integer. Special cases:
 165.366 -     * <ul><li>If the argument value is already equal to a
 165.367 -     * mathematical integer, then the result is the same as the
 165.368 -     * argument.  <li>If the argument is NaN or an infinity or
 165.369 -     * positive zero or negative zero, then the result is the same as
 165.370 -     * the argument.</ul>
 165.371 -     *
 165.372 -     * @param   a   a value.
 165.373 -     * @return  the largest (closest to positive infinity)
 165.374 -     *          floating-point value that less than or equal to the argument
 165.375 -     *          and is equal to a mathematical integer.
 165.376 -     */
 165.377 -    @JavaScriptBody(args="a", body="return Math.floor(a);")
 165.378 -    public static double floor(double a) {
 165.379 -        throw new UnsupportedOperationException();
 165.380 -    }
 165.381 -    /**
 165.382 -     * Computes the remainder operation on two arguments as prescribed
 165.383 -     * by the IEEE 754 standard.
 165.384 -     * The remainder value is mathematically equal to
 165.385 -     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
 165.386 -     * where <i>n</i> is the mathematical integer closest to the exact
 165.387 -     * mathematical value of the quotient {@code f1/f2}, and if two
 165.388 -     * mathematical integers are equally close to {@code f1/f2},
 165.389 -     * then <i>n</i> is the integer that is even. If the remainder is
 165.390 -     * zero, its sign is the same as the sign of the first argument.
 165.391 -     * Special cases:
 165.392 -     * <ul><li>If either argument is NaN, or the first argument is infinite,
 165.393 -     * or the second argument is positive zero or negative zero, then the
 165.394 -     * result is NaN.
 165.395 -     * <li>If the first argument is finite and the second argument is
 165.396 -     * infinite, then the result is the same as the first argument.</ul>
 165.397 -     *
 165.398 -     * @param   f1   the dividend.
 165.399 -     * @param   f2   the divisor.
 165.400 -     * @return  the remainder when {@code f1} is divided by
 165.401 -     *          {@code f2}.
 165.402 -     */
 165.403 -    public static double IEEEremainder(double f1, double f2) {
 165.404 -        return f1 - (f2 * Math.round(f1 / f2));
 165.405 -    }
 165.406 -
 165.407 -    /**
 165.408 -     * Returns the {@code double} value that is closest in value
 165.409 -     * to the argument and is equal to a mathematical integer. If two
 165.410 -     * {@code double} values that are mathematical integers are
 165.411 -     * equally close, the result is the integer value that is
 165.412 -     * even. Special cases:
 165.413 -     * <ul><li>If the argument value is already equal to a mathematical
 165.414 -     * integer, then the result is the same as the argument.
 165.415 -     * <li>If the argument is NaN or an infinity or positive zero or negative
 165.416 -     * zero, then the result is the same as the argument.</ul>
 165.417 -     *
 165.418 -     * @param   a   a {@code double} value.
 165.419 -     * @return  the closest floating-point value to {@code a} that is
 165.420 -     *          equal to a mathematical integer.
 165.421 -     */
 165.422 -    public static double rint(double a) {
 165.423 -        double ceil = ceil(a);
 165.424 -        double floor = floor(a);
 165.425 -        
 165.426 -        double dc = ceil - a;
 165.427 -        double df = a - floor;
 165.428 -        
 165.429 -        if (dc < df) {
 165.430 -            return ceil;
 165.431 -        } else if (dc > df) {
 165.432 -            return floor;
 165.433 -        }
 165.434 -        
 165.435 -        int tenC = (int) (ceil % 10.0);
 165.436 -        
 165.437 -        if (tenC % 2 == 0) {
 165.438 -            return ceil;
 165.439 -        } else {
 165.440 -            return floor;
 165.441 -        }
 165.442 -    }
 165.443 -
 165.444 -    /**
 165.445 -     * Returns the angle <i>theta</i> from the conversion of rectangular
 165.446 -     * coordinates ({@code x},&nbsp;{@code y}) to polar
 165.447 -     * coordinates (r,&nbsp;<i>theta</i>).
 165.448 -     * This method computes the phase <i>theta</i> by computing an arc tangent
 165.449 -     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
 165.450 -     * cases:
 165.451 -     * <ul><li>If either argument is NaN, then the result is NaN.
 165.452 -     * <li>If the first argument is positive zero and the second argument
 165.453 -     * is positive, or the first argument is positive and finite and the
 165.454 -     * second argument is positive infinity, then the result is positive
 165.455 -     * zero.
 165.456 -     * <li>If the first argument is negative zero and the second argument
 165.457 -     * is positive, or the first argument is negative and finite and the
 165.458 -     * second argument is positive infinity, then the result is negative zero.
 165.459 -     * <li>If the first argument is positive zero and the second argument
 165.460 -     * is negative, or the first argument is positive and finite and the
 165.461 -     * second argument is negative infinity, then the result is the
 165.462 -     * {@code double} value closest to <i>pi</i>.
 165.463 -     * <li>If the first argument is negative zero and the second argument
 165.464 -     * is negative, or the first argument is negative and finite and the
 165.465 -     * second argument is negative infinity, then the result is the
 165.466 -     * {@code double} value closest to -<i>pi</i>.
 165.467 -     * <li>If the first argument is positive and the second argument is
 165.468 -     * positive zero or negative zero, or the first argument is positive
 165.469 -     * infinity and the second argument is finite, then the result is the
 165.470 -     * {@code double} value closest to <i>pi</i>/2.
 165.471 -     * <li>If the first argument is negative and the second argument is
 165.472 -     * positive zero or negative zero, or the first argument is negative
 165.473 -     * infinity and the second argument is finite, then the result is the
 165.474 -     * {@code double} value closest to -<i>pi</i>/2.
 165.475 -     * <li>If both arguments are positive infinity, then the result is the
 165.476 -     * {@code double} value closest to <i>pi</i>/4.
 165.477 -     * <li>If the first argument is positive infinity and the second argument
 165.478 -     * is negative infinity, then the result is the {@code double}
 165.479 -     * value closest to 3*<i>pi</i>/4.
 165.480 -     * <li>If the first argument is negative infinity and the second argument
 165.481 -     * is positive infinity, then the result is the {@code double} value
 165.482 -     * closest to -<i>pi</i>/4.
 165.483 -     * <li>If both arguments are negative infinity, then the result is the
 165.484 -     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
 165.485 -     *
 165.486 -     * <p>The computed result must be within 2 ulps of the exact result.
 165.487 -     * Results must be semi-monotonic.
 165.488 -     *
 165.489 -     * @param   y   the ordinate coordinate
 165.490 -     * @param   x   the abscissa coordinate
 165.491 -     * @return  the <i>theta</i> component of the point
 165.492 -     *          (<i>r</i>,&nbsp;<i>theta</i>)
 165.493 -     *          in polar coordinates that corresponds to the point
 165.494 -     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
 165.495 -     */
 165.496 -    @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
 165.497 -    public static double atan2(double y, double x) {
 165.498 -        throw new UnsupportedOperationException();
 165.499 -    }
 165.500 -
 165.501 -    /**
 165.502 -     * Returns the value of the first argument raised to the power of the
 165.503 -     * second argument. Special cases:
 165.504 -     *
 165.505 -     * <ul><li>If the second argument is positive or negative zero, then the
 165.506 -     * result is 1.0.
 165.507 -     * <li>If the second argument is 1.0, then the result is the same as the
 165.508 -     * first argument.
 165.509 -     * <li>If the second argument is NaN, then the result is NaN.
 165.510 -     * <li>If the first argument is NaN and the second argument is nonzero,
 165.511 -     * then the result is NaN.
 165.512 -     *
 165.513 -     * <li>If
 165.514 -     * <ul>
 165.515 -     * <li>the absolute value of the first argument is greater than 1
 165.516 -     * and the second argument is positive infinity, or
 165.517 -     * <li>the absolute value of the first argument is less than 1 and
 165.518 -     * the second argument is negative infinity,
 165.519 -     * </ul>
 165.520 -     * then the result is positive infinity.
 165.521 -     *
 165.522 -     * <li>If
 165.523 -     * <ul>
 165.524 -     * <li>the absolute value of the first argument is greater than 1 and
 165.525 -     * the second argument is negative infinity, or
 165.526 -     * <li>the absolute value of the
 165.527 -     * first argument is less than 1 and the second argument is positive
 165.528 -     * infinity,
 165.529 -     * </ul>
 165.530 -     * then the result is positive zero.
 165.531 -     *
 165.532 -     * <li>If the absolute value of the first argument equals 1 and the
 165.533 -     * second argument is infinite, then the result is NaN.
 165.534 -     *
 165.535 -     * <li>If
 165.536 -     * <ul>
 165.537 -     * <li>the first argument is positive zero and the second argument
 165.538 -     * is greater than zero, or
 165.539 -     * <li>the first argument is positive infinity and the second
 165.540 -     * argument is less than zero,
 165.541 -     * </ul>
 165.542 -     * then the result is positive zero.
 165.543 -     *
 165.544 -     * <li>If
 165.545 -     * <ul>
 165.546 -     * <li>the first argument is positive zero and the second argument
 165.547 -     * is less than zero, or
 165.548 -     * <li>the first argument is positive infinity and the second
 165.549 -     * argument is greater than zero,
 165.550 -     * </ul>
 165.551 -     * then the result is positive infinity.
 165.552 -     *
 165.553 -     * <li>If
 165.554 -     * <ul>
 165.555 -     * <li>the first argument is negative zero and the second argument
 165.556 -     * is greater than zero but not a finite odd integer, or
 165.557 -     * <li>the first argument is negative infinity and the second
 165.558 -     * argument is less than zero but not a finite odd integer,
 165.559 -     * </ul>
 165.560 -     * then the result is positive zero.
 165.561 -     *
 165.562 -     * <li>If
 165.563 -     * <ul>
 165.564 -     * <li>the first argument is negative zero and the second argument
 165.565 -     * is a positive finite odd integer, or
 165.566 -     * <li>the first argument is negative infinity and the second
 165.567 -     * argument is a negative finite odd integer,
 165.568 -     * </ul>
 165.569 -     * then the result is negative zero.
 165.570 -     *
 165.571 -     * <li>If
 165.572 -     * <ul>
 165.573 -     * <li>the first argument is negative zero and the second argument
 165.574 -     * is less than zero but not a finite odd integer, or
 165.575 -     * <li>the first argument is negative infinity and the second
 165.576 -     * argument is greater than zero but not a finite odd integer,
 165.577 -     * </ul>
 165.578 -     * then the result is positive infinity.
 165.579 -     *
 165.580 -     * <li>If
 165.581 -     * <ul>
 165.582 -     * <li>the first argument is negative zero and the second argument
 165.583 -     * is a negative finite odd integer, or
 165.584 -     * <li>the first argument is negative infinity and the second
 165.585 -     * argument is a positive finite odd integer,
 165.586 -     * </ul>
 165.587 -     * then the result is negative infinity.
 165.588 -     *
 165.589 -     * <li>If the first argument is finite and less than zero
 165.590 -     * <ul>
 165.591 -     * <li> if the second argument is a finite even integer, the
 165.592 -     * result is equal to the result of raising the absolute value of
 165.593 -     * the first argument to the power of the second argument
 165.594 -     *
 165.595 -     * <li>if the second argument is a finite odd integer, the result
 165.596 -     * is equal to the negative of the result of raising the absolute
 165.597 -     * value of the first argument to the power of the second
 165.598 -     * argument
 165.599 -     *
 165.600 -     * <li>if the second argument is finite and not an integer, then
 165.601 -     * the result is NaN.
 165.602 -     * </ul>
 165.603 -     *
 165.604 -     * <li>If both arguments are integers, then the result is exactly equal
 165.605 -     * to the mathematical result of raising the first argument to the power
 165.606 -     * of the second argument if that result can in fact be represented
 165.607 -     * exactly as a {@code double} value.</ul>
 165.608 -     *
 165.609 -     * <p>(In the foregoing descriptions, a floating-point value is
 165.610 -     * considered to be an integer if and only if it is finite and a
 165.611 -     * fixed point of the method {@link #ceil ceil} or,
 165.612 -     * equivalently, a fixed point of the method {@link #floor
 165.613 -     * floor}. A value is a fixed point of a one-argument
 165.614 -     * method if and only if the result of applying the method to the
 165.615 -     * value is equal to the value.)
 165.616 -     *
 165.617 -     * <p>The computed result must be within 1 ulp of the exact result.
 165.618 -     * Results must be semi-monotonic.
 165.619 -     *
 165.620 -     * @param   a   the base.
 165.621 -     * @param   b   the exponent.
 165.622 -     * @return  the value {@code a}<sup>{@code b}</sup>.
 165.623 -     */
 165.624 -    @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
 165.625 -    public static double pow(double a, double b) {
 165.626 -        throw new UnsupportedOperationException();
 165.627 -    }
 165.628 -
 165.629 -    /**
 165.630 -     * Returns the closest {@code int} to the argument, with ties
 165.631 -     * rounding up.
 165.632 -     *
 165.633 -     * <p>
 165.634 -     * Special cases:
 165.635 -     * <ul><li>If the argument is NaN, the result is 0.
 165.636 -     * <li>If the argument is negative infinity or any value less than or
 165.637 -     * equal to the value of {@code Integer.MIN_VALUE}, the result is
 165.638 -     * equal to the value of {@code Integer.MIN_VALUE}.
 165.639 -     * <li>If the argument is positive infinity or any value greater than or
 165.640 -     * equal to the value of {@code Integer.MAX_VALUE}, the result is
 165.641 -     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
 165.642 -     *
 165.643 -     * @param   a   a floating-point value to be rounded to an integer.
 165.644 -     * @return  the value of the argument rounded to the nearest
 165.645 -     *          {@code int} value.
 165.646 -     * @see     java.lang.Integer#MAX_VALUE
 165.647 -     * @see     java.lang.Integer#MIN_VALUE
 165.648 -     */
 165.649 -    @JavaScriptBody(args="a", body="return Math.round(a);")
 165.650 -    public static int round(float a) {
 165.651 -        throw new UnsupportedOperationException();
 165.652 -    }
 165.653 -
 165.654 -    /**
 165.655 -     * Returns the closest {@code long} to the argument, with ties
 165.656 -     * rounding up.
 165.657 -     *
 165.658 -     * <p>Special cases:
 165.659 -     * <ul><li>If the argument is NaN, the result is 0.
 165.660 -     * <li>If the argument is negative infinity or any value less than or
 165.661 -     * equal to the value of {@code Long.MIN_VALUE}, the result is
 165.662 -     * equal to the value of {@code Long.MIN_VALUE}.
 165.663 -     * <li>If the argument is positive infinity or any value greater than or
 165.664 -     * equal to the value of {@code Long.MAX_VALUE}, the result is
 165.665 -     * equal to the value of {@code Long.MAX_VALUE}.</ul>
 165.666 -     *
 165.667 -     * @param   a   a floating-point value to be rounded to a
 165.668 -     *          {@code long}.
 165.669 -     * @return  the value of the argument rounded to the nearest
 165.670 -     *          {@code long} value.
 165.671 -     * @see     java.lang.Long#MAX_VALUE
 165.672 -     * @see     java.lang.Long#MIN_VALUE
 165.673 -     */
 165.674 -    @JavaScriptBody(args="a", body="return Math.round(a);")
 165.675 -    public static long round(double a) {
 165.676 -        throw new UnsupportedOperationException();
 165.677 -    }
 165.678 -
 165.679 -//    private static Random randomNumberGenerator;
 165.680 -//
 165.681 -//    private static synchronized Random initRNG() {
 165.682 -//        Random rnd = randomNumberGenerator;
 165.683 -//        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
 165.684 -//    }
 165.685 -
 165.686 -    /**
 165.687 -     * Returns a {@code double} value with a positive sign, greater
 165.688 -     * than or equal to {@code 0.0} and less than {@code 1.0}.
 165.689 -     * Returned values are chosen pseudorandomly with (approximately)
 165.690 -     * uniform distribution from that range.
 165.691 -     *
 165.692 -     * <p>When this method is first called, it creates a single new
 165.693 -     * pseudorandom-number generator, exactly as if by the expression
 165.694 -     *
 165.695 -     * <blockquote>{@code new java.util.Random()}</blockquote>
 165.696 -     *
 165.697 -     * This new pseudorandom-number generator is used thereafter for
 165.698 -     * all calls to this method and is used nowhere else.
 165.699 -     *
 165.700 -     * <p>This method is properly synchronized to allow correct use by
 165.701 -     * more than one thread. However, if many threads need to generate
 165.702 -     * pseudorandom numbers at a great rate, it may reduce contention
 165.703 -     * for each thread to have its own pseudorandom-number generator.
 165.704 -     *
 165.705 -     * @return  a pseudorandom {@code double} greater than or equal
 165.706 -     * to {@code 0.0} and less than {@code 1.0}.
 165.707 -     * @see Random#nextDouble()
 165.708 -     */
 165.709 -    @JavaScriptBody(args={}, body="return Math.random();")
 165.710 -    public static double random() {
 165.711 -        throw new UnsupportedOperationException();
 165.712 -    }
 165.713 -
 165.714 -    /**
 165.715 -     * Returns the absolute value of an {@code int} value.
 165.716 -     * If the argument is not negative, the argument is returned.
 165.717 -     * If the argument is negative, the negation of the argument is returned.
 165.718 -     *
 165.719 -     * <p>Note that if the argument is equal to the value of
 165.720 -     * {@link Integer#MIN_VALUE}, the most negative representable
 165.721 -     * {@code int} value, the result is that same value, which is
 165.722 -     * negative.
 165.723 -     *
 165.724 -     * @param   a   the argument whose absolute value is to be determined
 165.725 -     * @return  the absolute value of the argument.
 165.726 -     */
 165.727 -    public static int abs(int a) {
 165.728 -        return (a < 0) ? -a : a;
 165.729 -    }
 165.730 -
 165.731 -    /**
 165.732 -     * Returns the absolute value of a {@code long} value.
 165.733 -     * If the argument is not negative, the argument is returned.
 165.734 -     * If the argument is negative, the negation of the argument is returned.
 165.735 -     *
 165.736 -     * <p>Note that if the argument is equal to the value of
 165.737 -     * {@link Long#MIN_VALUE}, the most negative representable
 165.738 -     * {@code long} value, the result is that same value, which
 165.739 -     * is negative.
 165.740 -     *
 165.741 -     * @param   a   the argument whose absolute value is to be determined
 165.742 -     * @return  the absolute value of the argument.
 165.743 -     */
 165.744 -    public static long abs(long a) {
 165.745 -        return (a < 0) ? -a : a;
 165.746 -    }
 165.747 -
 165.748 -    /**
 165.749 -     * Returns the absolute value of a {@code float} value.
 165.750 -     * If the argument is not negative, the argument is returned.
 165.751 -     * If the argument is negative, the negation of the argument is returned.
 165.752 -     * Special cases:
 165.753 -     * <ul><li>If the argument is positive zero or negative zero, the
 165.754 -     * result is positive zero.
 165.755 -     * <li>If the argument is infinite, the result is positive infinity.
 165.756 -     * <li>If the argument is NaN, the result is NaN.</ul>
 165.757 -     * In other words, the result is the same as the value of the expression:
 165.758 -     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
 165.759 -     *
 165.760 -     * @param   a   the argument whose absolute value is to be determined
 165.761 -     * @return  the absolute value of the argument.
 165.762 -     */
 165.763 -    public static float abs(float a) {
 165.764 -        return (a <= 0.0F) ? 0.0F - a : a;
 165.765 -    }
 165.766 -
 165.767 -    /**
 165.768 -     * Returns the absolute value of a {@code double} value.
 165.769 -     * If the argument is not negative, the argument is returned.
 165.770 -     * If the argument is negative, the negation of the argument is returned.
 165.771 -     * Special cases:
 165.772 -     * <ul><li>If the argument is positive zero or negative zero, the result
 165.773 -     * is positive zero.
 165.774 -     * <li>If the argument is infinite, the result is positive infinity.
 165.775 -     * <li>If the argument is NaN, the result is NaN.</ul>
 165.776 -     * In other words, the result is the same as the value of the expression:
 165.777 -     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
 165.778 -     *
 165.779 -     * @param   a   the argument whose absolute value is to be determined
 165.780 -     * @return  the absolute value of the argument.
 165.781 -     */
 165.782 -    public static double abs(double a) {
 165.783 -        return (a <= 0.0D) ? 0.0D - a : a;
 165.784 -    }
 165.785 -
 165.786 -    /**
 165.787 -     * Returns the greater of two {@code int} values. That is, the
 165.788 -     * result is the argument closer to the value of
 165.789 -     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
 165.790 -     * the result is that same value.
 165.791 -     *
 165.792 -     * @param   a   an argument.
 165.793 -     * @param   b   another argument.
 165.794 -     * @return  the larger of {@code a} and {@code b}.
 165.795 -     */
 165.796 -    public static int max(int a, int b) {
 165.797 -        return (a >= b) ? a : b;
 165.798 -    }
 165.799 -
 165.800 -    /**
 165.801 -     * Returns the greater of two {@code long} values. That is, the
 165.802 -     * result is the argument closer to the value of
 165.803 -     * {@link Long#MAX_VALUE}. If the arguments have the same value,
 165.804 -     * the result is that same value.
 165.805 -     *
 165.806 -     * @param   a   an argument.
 165.807 -     * @param   b   another argument.
 165.808 -     * @return  the larger of {@code a} and {@code b}.
 165.809 -     */
 165.810 -    public static long max(long a, long b) {
 165.811 -        return (a >= b) ? a : b;
 165.812 -    }
 165.813 -
 165.814 -    /**
 165.815 -     * Returns the greater of two {@code float} values.  That is,
 165.816 -     * the result is the argument closer to positive infinity. If the
 165.817 -     * arguments have the same value, the result is that same
 165.818 -     * value. If either value is NaN, then the result is NaN.  Unlike
 165.819 -     * the numerical comparison operators, this method considers
 165.820 -     * negative zero to be strictly smaller than positive zero. If one
 165.821 -     * argument is positive zero and the other negative zero, the
 165.822 -     * result is positive zero.
 165.823 -     *
 165.824 -     * @param   a   an argument.
 165.825 -     * @param   b   another argument.
 165.826 -     * @return  the larger of {@code a} and {@code b}.
 165.827 -     */
 165.828 -    @JavaScriptBody(args={"a", "b"},
 165.829 -        body="return Math.max(a,b);"
 165.830 -    )
 165.831 -    public static float max(float a, float b) {
 165.832 -        throw new UnsupportedOperationException();
 165.833 -    }
 165.834 -
 165.835 -    /**
 165.836 -     * Returns the greater of two {@code double} values.  That
 165.837 -     * is, the result is the argument closer to positive infinity. If
 165.838 -     * the arguments have the same value, the result is that same
 165.839 -     * value. If either value is NaN, then the result is NaN.  Unlike
 165.840 -     * the numerical comparison operators, this method considers
 165.841 -     * negative zero to be strictly smaller than positive zero. If one
 165.842 -     * argument is positive zero and the other negative zero, the
 165.843 -     * result is positive zero.
 165.844 -     *
 165.845 -     * @param   a   an argument.
 165.846 -     * @param   b   another argument.
 165.847 -     * @return  the larger of {@code a} and {@code b}.
 165.848 -     */
 165.849 -    @JavaScriptBody(args={"a", "b"},
 165.850 -        body="return Math.max(a,b);"
 165.851 -    )
 165.852 -    public static double max(double a, double b) {
 165.853 -        throw new UnsupportedOperationException();
 165.854 -    }
 165.855 -
 165.856 -    /**
 165.857 -     * Returns the smaller of two {@code int} values. That is,
 165.858 -     * the result the argument closer to the value of
 165.859 -     * {@link Integer#MIN_VALUE}.  If the arguments have the same
 165.860 -     * value, the result is that same value.
 165.861 -     *
 165.862 -     * @param   a   an argument.
 165.863 -     * @param   b   another argument.
 165.864 -     * @return  the smaller of {@code a} and {@code b}.
 165.865 -     */
 165.866 -    public static int min(int a, int b) {
 165.867 -        return (a <= b) ? a : b;
 165.868 -    }
 165.869 -
 165.870 -    /**
 165.871 -     * Returns the smaller of two {@code long} values. That is,
 165.872 -     * the result is the argument closer to the value of
 165.873 -     * {@link Long#MIN_VALUE}. If the arguments have the same
 165.874 -     * value, the result is that same value.
 165.875 -     *
 165.876 -     * @param   a   an argument.
 165.877 -     * @param   b   another argument.
 165.878 -     * @return  the smaller of {@code a} and {@code b}.
 165.879 -     */
 165.880 -    public static long min(long a, long b) {
 165.881 -        return (a <= b) ? a : b;
 165.882 -    }
 165.883 -
 165.884 -    /**
 165.885 -     * Returns the smaller of two {@code float} values.  That is,
 165.886 -     * the result is the value closer to negative infinity. If the
 165.887 -     * arguments have the same value, the result is that same
 165.888 -     * value. If either value is NaN, then the result is NaN.  Unlike
 165.889 -     * the numerical comparison operators, this method considers
 165.890 -     * negative zero to be strictly smaller than positive zero.  If
 165.891 -     * one argument is positive zero and the other is negative zero,
 165.892 -     * the result is negative zero.
 165.893 -     *
 165.894 -     * @param   a   an argument.
 165.895 -     * @param   b   another argument.
 165.896 -     * @return  the smaller of {@code a} and {@code b}.
 165.897 -     */
 165.898 -    @JavaScriptBody(args={"a", "b"},
 165.899 -        body="return Math.min(a,b);"
 165.900 -    )
 165.901 -    public static float min(float a, float b) {
 165.902 -        throw new UnsupportedOperationException();
 165.903 -    }
 165.904 -
 165.905 -    /**
 165.906 -     * Returns the smaller of two {@code double} values.  That
 165.907 -     * is, the result is the value closer to negative infinity. If the
 165.908 -     * arguments have the same value, the result is that same
 165.909 -     * value. If either value is NaN, then the result is NaN.  Unlike
 165.910 -     * the numerical comparison operators, this method considers
 165.911 -     * negative zero to be strictly smaller than positive zero. If one
 165.912 -     * argument is positive zero and the other is negative zero, the
 165.913 -     * result is negative zero.
 165.914 -     *
 165.915 -     * @param   a   an argument.
 165.916 -     * @param   b   another argument.
 165.917 -     * @return  the smaller of {@code a} and {@code b}.
 165.918 -     */
 165.919 -    @JavaScriptBody(args={"a", "b"},
 165.920 -        body="return Math.min(a,b);"
 165.921 -    )
 165.922 -    public static double min(double a, double b) {
 165.923 -        throw new UnsupportedOperationException();
 165.924 -    }
 165.925 -
 165.926 -    /**
 165.927 -     * Returns the size of an ulp of the argument.  An ulp of a
 165.928 -     * {@code double} value is the positive distance between this
 165.929 -     * floating-point value and the {@code double} value next
 165.930 -     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 165.931 -     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 165.932 -     *
 165.933 -     * <p>Special Cases:
 165.934 -     * <ul>
 165.935 -     * <li> If the argument is NaN, then the result is NaN.
 165.936 -     * <li> If the argument is positive or negative infinity, then the
 165.937 -     * result is positive infinity.
 165.938 -     * <li> If the argument is positive or negative zero, then the result is
 165.939 -     * {@code Double.MIN_VALUE}.
 165.940 -     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
 165.941 -     * the result is equal to 2<sup>971</sup>.
 165.942 -     * </ul>
 165.943 -     *
 165.944 -     * @param d the floating-point value whose ulp is to be returned
 165.945 -     * @return the size of an ulp of the argument
 165.946 -     * @author Joseph D. Darcy
 165.947 -     * @since 1.5
 165.948 -     */
 165.949 -//    public static double ulp(double d) {
 165.950 -//        return sun.misc.FpUtils.ulp(d);
 165.951 -//    }
 165.952 -
 165.953 -    /**
 165.954 -     * Returns the size of an ulp of the argument.  An ulp of a
 165.955 -     * {@code float} value is the positive distance between this
 165.956 -     * floating-point value and the {@code float} value next
 165.957 -     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 165.958 -     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 165.959 -     *
 165.960 -     * <p>Special Cases:
 165.961 -     * <ul>
 165.962 -     * <li> If the argument is NaN, then the result is NaN.
 165.963 -     * <li> If the argument is positive or negative infinity, then the
 165.964 -     * result is positive infinity.
 165.965 -     * <li> If the argument is positive or negative zero, then the result is
 165.966 -     * {@code Float.MIN_VALUE}.
 165.967 -     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
 165.968 -     * the result is equal to 2<sup>104</sup>.
 165.969 -     * </ul>
 165.970 -     *
 165.971 -     * @param f the floating-point value whose ulp is to be returned
 165.972 -     * @return the size of an ulp of the argument
 165.973 -     * @author Joseph D. Darcy
 165.974 -     * @since 1.5
 165.975 -     */
 165.976 -//    public static float ulp(float f) {
 165.977 -//        return sun.misc.FpUtils.ulp(f);
 165.978 -//    }
 165.979 -
 165.980 -    /**
 165.981 -     * Returns the signum function of the argument; zero if the argument
 165.982 -     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
 165.983 -     * argument is less than zero.
 165.984 -     *
 165.985 -     * <p>Special Cases:
 165.986 -     * <ul>
 165.987 -     * <li> If the argument is NaN, then the result is NaN.
 165.988 -     * <li> If the argument is positive zero or negative zero, then the
 165.989 -     *      result is the same as the argument.
 165.990 -     * </ul>
 165.991 -     *
 165.992 -     * @param d the floating-point value whose signum is to be returned
 165.993 -     * @return the signum function of the argument
 165.994 -     * @author Joseph D. Darcy
 165.995 -     * @since 1.5
 165.996 -     */
 165.997 -    public static double signum(double d) {
 165.998 -        if (d < 0.0) { return -1.0; }
 165.999 -        if (d > 0.0) { return 1.0; }
165.1000 -        return d;
165.1001 -    }
165.1002 -
165.1003 -    /**
165.1004 -     * Returns the signum function of the argument; zero if the argument
165.1005 -     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
165.1006 -     * argument is less than zero.
165.1007 -     *
165.1008 -     * <p>Special Cases:
165.1009 -     * <ul>
165.1010 -     * <li> If the argument is NaN, then the result is NaN.
165.1011 -     * <li> If the argument is positive zero or negative zero, then the
165.1012 -     *      result is the same as the argument.
165.1013 -     * </ul>
165.1014 -     *
165.1015 -     * @param f the floating-point value whose signum is to be returned
165.1016 -     * @return the signum function of the argument
165.1017 -     * @author Joseph D. Darcy
165.1018 -     * @since 1.5
165.1019 -     */
165.1020 -    public static float signum(float f) {
165.1021 -        if (f < 0.0f) { return -1.0f; }
165.1022 -        if (f > 0.0f) { return 1.0f; }
165.1023 -        return f;
165.1024 -    }
165.1025 -
165.1026 -    /**
165.1027 -     * Returns the first floating-point argument with the sign of the
165.1028 -     * second floating-point argument.  Note that unlike the {@link
165.1029 -     * StrictMath#copySign(double, double) StrictMath.copySign}
165.1030 -     * method, this method does not require NaN {@code sign}
165.1031 -     * arguments to be treated as positive values; implementations are
165.1032 -     * permitted to treat some NaN arguments as positive and other NaN
165.1033 -     * arguments as negative to allow greater performance.
165.1034 -     *
165.1035 -     * @param magnitude  the parameter providing the magnitude of the result
165.1036 -     * @param sign   the parameter providing the sign of the result
165.1037 -     * @return a value with the magnitude of {@code magnitude}
165.1038 -     * and the sign of {@code sign}.
165.1039 -     * @since 1.6
165.1040 -     */
165.1041 -//    public static double copySign(double magnitude, double sign) {
165.1042 -//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
165.1043 -//    }
165.1044 -
165.1045 -    /**
165.1046 -     * Returns the first floating-point argument with the sign of the
165.1047 -     * second floating-point argument.  Note that unlike the {@link
165.1048 -     * StrictMath#copySign(float, float) StrictMath.copySign}
165.1049 -     * method, this method does not require NaN {@code sign}
165.1050 -     * arguments to be treated as positive values; implementations are
165.1051 -     * permitted to treat some NaN arguments as positive and other NaN
165.1052 -     * arguments as negative to allow greater performance.
165.1053 -     *
165.1054 -     * @param magnitude  the parameter providing the magnitude of the result
165.1055 -     * @param sign   the parameter providing the sign of the result
165.1056 -     * @return a value with the magnitude of {@code magnitude}
165.1057 -     * and the sign of {@code sign}.
165.1058 -     * @since 1.6
165.1059 -     */
165.1060 -//    public static float copySign(float magnitude, float sign) {
165.1061 -//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
165.1062 -//    }
165.1063 -
165.1064 -    /**
165.1065 -     * Returns the unbiased exponent used in the representation of a
165.1066 -     * {@code float}.  Special cases:
165.1067 -     *
165.1068 -     * <ul>
165.1069 -     * <li>If the argument is NaN or infinite, then the result is
165.1070 -     * {@link Float#MAX_EXPONENT} + 1.
165.1071 -     * <li>If the argument is zero or subnormal, then the result is
165.1072 -     * {@link Float#MIN_EXPONENT} -1.
165.1073 -     * </ul>
165.1074 -     * @param f a {@code float} value
165.1075 -     * @return the unbiased exponent of the argument
165.1076 -     * @since 1.6
165.1077 -     */
165.1078 -//    public static int getExponent(float f) {
165.1079 -//        return sun.misc.FpUtils.getExponent(f);
165.1080 -//    }
165.1081 -
165.1082 -    /**
165.1083 -     * Returns the unbiased exponent used in the representation of a
165.1084 -     * {@code double}.  Special cases:
165.1085 -     *
165.1086 -     * <ul>
165.1087 -     * <li>If the argument is NaN or infinite, then the result is
165.1088 -     * {@link Double#MAX_EXPONENT} + 1.
165.1089 -     * <li>If the argument is zero or subnormal, then the result is
165.1090 -     * {@link Double#MIN_EXPONENT} -1.
165.1091 -     * </ul>
165.1092 -     * @param d a {@code double} value
165.1093 -     * @return the unbiased exponent of the argument
165.1094 -     * @since 1.6
165.1095 -     */
165.1096 -//    public static int getExponent(double d) {
165.1097 -//        return sun.misc.FpUtils.getExponent(d);
165.1098 -//    }
165.1099 -
165.1100 -    /**
165.1101 -     * Returns the floating-point number adjacent to the first
165.1102 -     * argument in the direction of the second argument.  If both
165.1103 -     * arguments compare as equal the second argument is returned.
165.1104 -     *
165.1105 -     * <p>
165.1106 -     * Special cases:
165.1107 -     * <ul>
165.1108 -     * <li> If either argument is a NaN, then NaN is returned.
165.1109 -     *
165.1110 -     * <li> If both arguments are signed zeros, {@code direction}
165.1111 -     * is returned unchanged (as implied by the requirement of
165.1112 -     * returning the second argument if the arguments compare as
165.1113 -     * equal).
165.1114 -     *
165.1115 -     * <li> If {@code start} is
165.1116 -     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
165.1117 -     * has a value such that the result should have a smaller
165.1118 -     * magnitude, then a zero with the same sign as {@code start}
165.1119 -     * is returned.
165.1120 -     *
165.1121 -     * <li> If {@code start} is infinite and
165.1122 -     * {@code direction} has a value such that the result should
165.1123 -     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
165.1124 -     * same sign as {@code start} is returned.
165.1125 -     *
165.1126 -     * <li> If {@code start} is equal to &plusmn;
165.1127 -     * {@link Double#MAX_VALUE} and {@code direction} has a
165.1128 -     * value such that the result should have a larger magnitude, an
165.1129 -     * infinity with same sign as {@code start} is returned.
165.1130 -     * </ul>
165.1131 -     *
165.1132 -     * @param start  starting floating-point value
165.1133 -     * @param direction value indicating which of
165.1134 -     * {@code start}'s neighbors or {@code start} should
165.1135 -     * be returned
165.1136 -     * @return The floating-point number adjacent to {@code start} in the
165.1137 -     * direction of {@code direction}.
165.1138 -     * @since 1.6
165.1139 -     */
165.1140 -//    public static double nextAfter(double start, double direction) {
165.1141 -//        return sun.misc.FpUtils.nextAfter(start, direction);
165.1142 -//    }
165.1143 -
165.1144 -    /**
165.1145 -     * Returns the floating-point number adjacent to the first
165.1146 -     * argument in the direction of the second argument.  If both
165.1147 -     * arguments compare as equal a value equivalent to the second argument
165.1148 -     * is returned.
165.1149 -     *
165.1150 -     * <p>
165.1151 -     * Special cases:
165.1152 -     * <ul>
165.1153 -     * <li> If either argument is a NaN, then NaN is returned.
165.1154 -     *
165.1155 -     * <li> If both arguments are signed zeros, a value equivalent
165.1156 -     * to {@code direction} is returned.
165.1157 -     *
165.1158 -     * <li> If {@code start} is
165.1159 -     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
165.1160 -     * has a value such that the result should have a smaller
165.1161 -     * magnitude, then a zero with the same sign as {@code start}
165.1162 -     * is returned.
165.1163 -     *
165.1164 -     * <li> If {@code start} is infinite and
165.1165 -     * {@code direction} has a value such that the result should
165.1166 -     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
165.1167 -     * same sign as {@code start} is returned.
165.1168 -     *
165.1169 -     * <li> If {@code start} is equal to &plusmn;
165.1170 -     * {@link Float#MAX_VALUE} and {@code direction} has a
165.1171 -     * value such that the result should have a larger magnitude, an
165.1172 -     * infinity with same sign as {@code start} is returned.
165.1173 -     * </ul>
165.1174 -     *
165.1175 -     * @param start  starting floating-point value
165.1176 -     * @param direction value indicating which of
165.1177 -     * {@code start}'s neighbors or {@code start} should
165.1178 -     * be returned
165.1179 -     * @return The floating-point number adjacent to {@code start} in the
165.1180 -     * direction of {@code direction}.
165.1181 -     * @since 1.6
165.1182 -     */
165.1183 -//    public static float nextAfter(float start, double direction) {
165.1184 -//        return sun.misc.FpUtils.nextAfter(start, direction);
165.1185 -//    }
165.1186 -
165.1187 -    /**
165.1188 -     * Returns the floating-point value adjacent to {@code d} in
165.1189 -     * the direction of positive infinity.  This method is
165.1190 -     * semantically equivalent to {@code nextAfter(d,
165.1191 -     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
165.1192 -     * implementation may run faster than its equivalent
165.1193 -     * {@code nextAfter} call.
165.1194 -     *
165.1195 -     * <p>Special Cases:
165.1196 -     * <ul>
165.1197 -     * <li> If the argument is NaN, the result is NaN.
165.1198 -     *
165.1199 -     * <li> If the argument is positive infinity, the result is
165.1200 -     * positive infinity.
165.1201 -     *
165.1202 -     * <li> If the argument is zero, the result is
165.1203 -     * {@link Double#MIN_VALUE}
165.1204 -     *
165.1205 -     * </ul>
165.1206 -     *
165.1207 -     * @param d starting floating-point value
165.1208 -     * @return The adjacent floating-point value closer to positive
165.1209 -     * infinity.
165.1210 -     * @since 1.6
165.1211 -     */
165.1212 -//    public static double nextUp(double d) {
165.1213 -//        return sun.misc.FpUtils.nextUp(d);
165.1214 -//    }
165.1215 -
165.1216 -    /**
165.1217 -     * Returns the floating-point value adjacent to {@code f} in
165.1218 -     * the direction of positive infinity.  This method is
165.1219 -     * semantically equivalent to {@code nextAfter(f,
165.1220 -     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
165.1221 -     * implementation may run faster than its equivalent
165.1222 -     * {@code nextAfter} call.
165.1223 -     *
165.1224 -     * <p>Special Cases:
165.1225 -     * <ul>
165.1226 -     * <li> If the argument is NaN, the result is NaN.
165.1227 -     *
165.1228 -     * <li> If the argument is positive infinity, the result is
165.1229 -     * positive infinity.
165.1230 -     *
165.1231 -     * <li> If the argument is zero, the result is
165.1232 -     * {@link Float#MIN_VALUE}
165.1233 -     *
165.1234 -     * </ul>
165.1235 -     *
165.1236 -     * @param f starting floating-point value
165.1237 -     * @return The adjacent floating-point value closer to positive
165.1238 -     * infinity.
165.1239 -     * @since 1.6
165.1240 -     */
165.1241 -//    public static float nextUp(float f) {
165.1242 -//        return sun.misc.FpUtils.nextUp(f);
165.1243 -//    }
165.1244 -
165.1245 -
165.1246 -    /**
165.1247 -     * Return {@code d} &times;
165.1248 -     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
165.1249 -     * by a single correctly rounded floating-point multiply to a
165.1250 -     * member of the double value set.  See the Java
165.1251 -     * Language Specification for a discussion of floating-point
165.1252 -     * value sets.  If the exponent of the result is between {@link
165.1253 -     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
165.1254 -     * answer is calculated exactly.  If the exponent of the result
165.1255 -     * would be larger than {@code Double.MAX_EXPONENT}, an
165.1256 -     * infinity is returned.  Note that if the result is subnormal,
165.1257 -     * precision may be lost; that is, when {@code scalb(x, n)}
165.1258 -     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
165.1259 -     * <i>x</i>.  When the result is non-NaN, the result has the same
165.1260 -     * sign as {@code d}.
165.1261 -     *
165.1262 -     * <p>Special cases:
165.1263 -     * <ul>
165.1264 -     * <li> If the first argument is NaN, NaN is returned.
165.1265 -     * <li> If the first argument is infinite, then an infinity of the
165.1266 -     * same sign is returned.
165.1267 -     * <li> If the first argument is zero, then a zero of the same
165.1268 -     * sign is returned.
165.1269 -     * </ul>
165.1270 -     *
165.1271 -     * @param d number to be scaled by a power of two.
165.1272 -     * @param scaleFactor power of 2 used to scale {@code d}
165.1273 -     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
165.1274 -     * @since 1.6
165.1275 -     */
165.1276 -//    public static double scalb(double d, int scaleFactor) {
165.1277 -//        return sun.misc.FpUtils.scalb(d, scaleFactor);
165.1278 -//    }
165.1279 -
165.1280 -    /**
165.1281 -     * Return {@code f} &times;
165.1282 -     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
165.1283 -     * by a single correctly rounded floating-point multiply to a
165.1284 -     * member of the float value set.  See the Java
165.1285 -     * Language Specification for a discussion of floating-point
165.1286 -     * value sets.  If the exponent of the result is between {@link
165.1287 -     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
165.1288 -     * answer is calculated exactly.  If the exponent of the result
165.1289 -     * would be larger than {@code Float.MAX_EXPONENT}, an
165.1290 -     * infinity is returned.  Note that if the result is subnormal,
165.1291 -     * precision may be lost; that is, when {@code scalb(x, n)}
165.1292 -     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
165.1293 -     * <i>x</i>.  When the result is non-NaN, the result has the same
165.1294 -     * sign as {@code f}.
165.1295 -     *
165.1296 -     * <p>Special cases:
165.1297 -     * <ul>
165.1298 -     * <li> If the first argument is NaN, NaN is returned.
165.1299 -     * <li> If the first argument is infinite, then an infinity of the
165.1300 -     * same sign is returned.
165.1301 -     * <li> If the first argument is zero, then a zero of the same
165.1302 -     * sign is returned.
165.1303 -     * </ul>
165.1304 -     *
165.1305 -     * @param f number to be scaled by a power of two.
165.1306 -     * @param scaleFactor power of 2 used to scale {@code f}
165.1307 -     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
165.1308 -     * @since 1.6
165.1309 -     */
165.1310 -//    public static float scalb(float f, int scaleFactor) {
165.1311 -//        return sun.misc.FpUtils.scalb(f, scaleFactor);
165.1312 -//    }
165.1313 -}
   166.1 --- a/emul/mini/src/main/java/java/lang/NegativeArraySizeException.java	Mon Feb 25 19:00:08 2013 +0100
   166.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   166.3 @@ -1,55 +0,0 @@
   166.4 -/*
   166.5 - * Copyright (c) 1994, 2008, 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;
  166.30 -
  166.31 -/**
  166.32 - * Thrown if an application tries to create an array with negative size.
  166.33 - *
  166.34 - * @author  unascribed
  166.35 - * @since   JDK1.0
  166.36 - */
  166.37 -public
  166.38 -class NegativeArraySizeException extends RuntimeException {
  166.39 -    private static final long serialVersionUID = -8960118058596991861L;
  166.40 -
  166.41 -    /**
  166.42 -     * Constructs a <code>NegativeArraySizeException</code> with no
  166.43 -     * detail message.
  166.44 -     */
  166.45 -    public NegativeArraySizeException() {
  166.46 -        super();
  166.47 -    }
  166.48 -
  166.49 -    /**
  166.50 -     * Constructs a <code>NegativeArraySizeException</code> with the
  166.51 -     * specified detail message.
  166.52 -     *
  166.53 -     * @param   s   the detail message.
  166.54 -     */
  166.55 -    public NegativeArraySizeException(String s) {
  166.56 -        super(s);
  166.57 -    }
  166.58 -}
   167.1 --- a/emul/mini/src/main/java/java/lang/NoSuchMethodException.java	Mon Feb 25 19:00:08 2013 +0100
   167.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   167.3 @@ -1,53 +0,0 @@
   167.4 -/*
   167.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   167.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   167.7 - *
   167.8 - * This code is free software; you can redistribute it and/or modify it
   167.9 - * under the terms of the GNU General Public License version 2 only, as
  167.10 - * published by the Free Software Foundation.  Oracle designates this
  167.11 - * particular file as subject to the "Classpath" exception as provided
  167.12 - * by Oracle in the LICENSE file that accompanied this code.
  167.13 - *
  167.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  167.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  167.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  167.17 - * version 2 for more details (a copy is included in the LICENSE file that
  167.18 - * accompanied this code).
  167.19 - *
  167.20 - * You should have received a copy of the GNU General Public License version
  167.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  167.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  167.23 - *
  167.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  167.25 - * or visit www.oracle.com if you need additional information or have any
  167.26 - * questions.
  167.27 - */
  167.28 -
  167.29 -package java.lang;
  167.30 -
  167.31 -/**
  167.32 - * Thrown when a particular method cannot be found.
  167.33 - *
  167.34 - * @author     unascribed
  167.35 - * @since      JDK1.0
  167.36 - */
  167.37 -public
  167.38 -class NoSuchMethodException extends ReflectiveOperationException {
  167.39 -    private static final long serialVersionUID = 5034388446362600923L;
  167.40 -
  167.41 -    /**
  167.42 -     * Constructs a <code>NoSuchMethodException</code> without a detail message.
  167.43 -     */
  167.44 -    public NoSuchMethodException() {
  167.45 -        super();
  167.46 -    }
  167.47 -
  167.48 -    /**
  167.49 -     * Constructs a <code>NoSuchMethodException</code> with a detail message.
  167.50 -     *
  167.51 -     * @param      s   the detail message.
  167.52 -     */
  167.53 -    public NoSuchMethodException(String s) {
  167.54 -        super(s);
  167.55 -    }
  167.56 -}
   168.1 --- a/emul/mini/src/main/java/java/lang/NullPointerException.java	Mon Feb 25 19:00:08 2013 +0100
   168.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   168.3 @@ -1,72 +0,0 @@
   168.4 -/*
   168.5 - * Copyright (c) 1994, 2011, 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;
  168.30 -
  168.31 -/**
  168.32 - * Thrown when an application attempts to use {@code null} in a
  168.33 - * case where an object is required. These include:
  168.34 - * <ul>
  168.35 - * <li>Calling the instance method of a {@code null} object.
  168.36 - * <li>Accessing or modifying the field of a {@code null} object.
  168.37 - * <li>Taking the length of {@code null} as if it were an array.
  168.38 - * <li>Accessing or modifying the slots of {@code null} as if it
  168.39 - *     were an array.
  168.40 - * <li>Throwing {@code null} as if it were a {@code Throwable}
  168.41 - *     value.
  168.42 - * </ul>
  168.43 - * <p>
  168.44 - * Applications should throw instances of this class to indicate
  168.45 - * other illegal uses of the {@code null} object.
  168.46 - *
  168.47 - * {@code NullPointerException} objects may be constructed by the
  168.48 - * virtual machine as if {@linkplain Throwable#Throwable(String,
  168.49 - * Throwable, boolean, boolean) suppression were disabled and/or the
  168.50 - * stack trace was not writable}.
  168.51 - *
  168.52 - * @author  unascribed
  168.53 - * @since   JDK1.0
  168.54 - */
  168.55 -public
  168.56 -class NullPointerException extends RuntimeException {
  168.57 -    private static final long serialVersionUID = 5162710183389028792L;
  168.58 -
  168.59 -    /**
  168.60 -     * Constructs a {@code NullPointerException} with no detail message.
  168.61 -     */
  168.62 -    public NullPointerException() {
  168.63 -        super();
  168.64 -    }
  168.65 -
  168.66 -    /**
  168.67 -     * Constructs a {@code NullPointerException} with the specified
  168.68 -     * detail message.
  168.69 -     *
  168.70 -     * @param   s   the detail message.
  168.71 -     */
  168.72 -    public NullPointerException(String s) {
  168.73 -        super(s);
  168.74 -    }
  168.75 -}
   169.1 --- a/emul/mini/src/main/java/java/lang/Number.java	Mon Feb 25 19:00:08 2013 +0100
   169.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   169.3 @@ -1,118 +0,0 @@
   169.4 -/*
   169.5 - * Copyright (c) 1994, 2001, 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;
  169.30 -
  169.31 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  169.32 -
  169.33 -/**
  169.34 - * The abstract class <code>Number</code> is the superclass of classes
  169.35 - * <code>BigDecimal</code>, <code>BigInteger</code>,
  169.36 - * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
  169.37 - * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
  169.38 - * <p>
  169.39 - * Subclasses of <code>Number</code> must provide methods to convert
  169.40 - * the represented numeric value to <code>byte</code>, <code>double</code>,
  169.41 - * <code>float</code>, <code>int</code>, <code>long</code>, and
  169.42 - * <code>short</code>.
  169.43 - *
  169.44 - * @author      Lee Boynton
  169.45 - * @author      Arthur van Hoff
  169.46 - * @see     java.lang.Byte
  169.47 - * @see     java.lang.Double
  169.48 - * @see     java.lang.Float
  169.49 - * @see     java.lang.Integer
  169.50 - * @see     java.lang.Long
  169.51 - * @see     java.lang.Short
  169.52 - * @since   JDK1.0
  169.53 - */
  169.54 -@ExtraJavaScript(
  169.55 -    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js",
  169.56 -    processByteCode=true
  169.57 -)
  169.58 -public abstract class Number implements java.io.Serializable {
  169.59 -    /**
  169.60 -     * Returns the value of the specified number as an <code>int</code>.
  169.61 -     * This may involve rounding or truncation.
  169.62 -     *
  169.63 -     * @return  the numeric value represented by this object after conversion
  169.64 -     *          to type <code>int</code>.
  169.65 -     */
  169.66 -    public abstract int intValue();
  169.67 -
  169.68 -    /**
  169.69 -     * Returns the value of the specified number as a <code>long</code>.
  169.70 -     * This may involve rounding or truncation.
  169.71 -     *
  169.72 -     * @return  the numeric value represented by this object after conversion
  169.73 -     *          to type <code>long</code>.
  169.74 -     */
  169.75 -    public abstract long longValue();
  169.76 -
  169.77 -    /**
  169.78 -     * Returns the value of the specified number as a <code>float</code>.
  169.79 -     * This may involve rounding.
  169.80 -     *
  169.81 -     * @return  the numeric value represented by this object after conversion
  169.82 -     *          to type <code>float</code>.
  169.83 -     */
  169.84 -    public abstract float floatValue();
  169.85 -
  169.86 -    /**
  169.87 -     * Returns the value of the specified number as a <code>double</code>.
  169.88 -     * This may involve rounding.
  169.89 -     *
  169.90 -     * @return  the numeric value represented by this object after conversion
  169.91 -     *          to type <code>double</code>.
  169.92 -     */
  169.93 -    public abstract double doubleValue();
  169.94 -
  169.95 -    /**
  169.96 -     * Returns the value of the specified number as a <code>byte</code>.
  169.97 -     * This may involve rounding or truncation.
  169.98 -     *
  169.99 -     * @return  the numeric value represented by this object after conversion
 169.100 -     *          to type <code>byte</code>.
 169.101 -     * @since   JDK1.1
 169.102 -     */
 169.103 -    public byte byteValue() {
 169.104 -        return (byte)intValue();
 169.105 -    }
 169.106 -
 169.107 -    /**
 169.108 -     * Returns the value of the specified number as a <code>short</code>.
 169.109 -     * This may involve rounding or truncation.
 169.110 -     *
 169.111 -     * @return  the numeric value represented by this object after conversion
 169.112 -     *          to type <code>short</code>.
 169.113 -     * @since   JDK1.1
 169.114 -     */
 169.115 -    public short shortValue() {
 169.116 -        return (short)intValue();
 169.117 -    }
 169.118 -
 169.119 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 169.120 -    private static final long serialVersionUID = -8742448824652078965L;
 169.121 -}
   170.1 --- a/emul/mini/src/main/java/java/lang/NumberFormatException.java	Mon Feb 25 19:00:08 2013 +0100
   170.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   170.3 @@ -1,67 +0,0 @@
   170.4 -/*
   170.5 - * Copyright (c) 1994, 2001, 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;
  170.30 -
  170.31 -/**
  170.32 - * Thrown to indicate that the application has attempted to convert
  170.33 - * a string to one of the numeric types, but that the string does not
  170.34 - * have the appropriate format.
  170.35 - *
  170.36 - * @author  unascribed
  170.37 - * @see     java.lang.Integer#toString()
  170.38 - * @since   JDK1.0
  170.39 - */
  170.40 -public
  170.41 -class NumberFormatException extends IllegalArgumentException {
  170.42 -    static final long serialVersionUID = -2848938806368998894L;
  170.43 -
  170.44 -    /**
  170.45 -     * Constructs a <code>NumberFormatException</code> with no detail message.
  170.46 -     */
  170.47 -    public NumberFormatException () {
  170.48 -        super();
  170.49 -    }
  170.50 -
  170.51 -    /**
  170.52 -     * Constructs a <code>NumberFormatException</code> with the
  170.53 -     * specified detail message.
  170.54 -     *
  170.55 -     * @param   s   the detail message.
  170.56 -     */
  170.57 -    public NumberFormatException (String s) {
  170.58 -        super (s);
  170.59 -    }
  170.60 -
  170.61 -    /**
  170.62 -     * Factory method for making a <code>NumberFormatException</code>
  170.63 -     * given the specified input which caused the error.
  170.64 -     *
  170.65 -     * @param   s   the input causing the error
  170.66 -     */
  170.67 -    static NumberFormatException forInputString(String s) {
  170.68 -        return new NumberFormatException("For input string: \"" + s + "\"");
  170.69 -    }
  170.70 -}
   171.1 --- a/emul/mini/src/main/java/java/lang/Object.java	Mon Feb 25 19:00:08 2013 +0100
   171.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   171.3 @@ -1,595 +0,0 @@
   171.4 -/*
   171.5 - * Copyright (c) 1994, 2010, 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;
  171.30 -
  171.31 -import java.lang.reflect.Array;
  171.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  171.33 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  171.34 -
  171.35 -/**
  171.36 - * Class {@code Object} is the root of the class hierarchy.
  171.37 - * Every class has {@code Object} as a superclass. All objects,
  171.38 - * including arrays, implement the methods of this class.
  171.39 - *
  171.40 - * @author  unascribed
  171.41 - * @see     java.lang.Class
  171.42 - * @since   JDK1.0
  171.43 - */
  171.44 -@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
  171.45 -public class Object {
  171.46 -
  171.47 -    private static void registerNatives() {
  171.48 -        try {
  171.49 -            Array.get(null, 0);
  171.50 -        } catch (Throwable ex) {
  171.51 -            // ignore
  171.52 -        }
  171.53 -    }
  171.54 -    static {
  171.55 -        registerNatives();
  171.56 -    }
  171.57 -
  171.58 -    /**
  171.59 -     * Returns the runtime class of this {@code Object}. The returned
  171.60 -     * {@code Class} object is the object that is locked by {@code
  171.61 -     * static synchronized} methods of the represented class.
  171.62 -     *
  171.63 -     * <p><b>The actual result type is {@code Class<? extends |X|>}
  171.64 -     * where {@code |X|} is the erasure of the static type of the
  171.65 -     * expression on which {@code getClass} is called.</b> For
  171.66 -     * example, no cast is required in this code fragment:</p>
  171.67 -     *
  171.68 -     * <p>
  171.69 -     * {@code Number n = 0;                             }<br>
  171.70 -     * {@code Class<? extends Number> c = n.getClass(); }
  171.71 -     * </p>
  171.72 -     *
  171.73 -     * @return The {@code Class} object that represents the runtime
  171.74 -     *         class of this object.
  171.75 -     * @see    Class Literals, section 15.8.2 of
  171.76 -     *         <cite>The Java&trade; Language Specification</cite>.
  171.77 -     */
  171.78 -    @JavaScriptBody(args={}, body="return this.constructor.$class;")
  171.79 -    public final native Class<?> getClass();
  171.80 -
  171.81 -    /**
  171.82 -     * Returns a hash code value for the object. This method is
  171.83 -     * supported for the benefit of hash tables such as those provided by
  171.84 -     * {@link java.util.HashMap}.
  171.85 -     * <p>
  171.86 -     * The general contract of {@code hashCode} is:
  171.87 -     * <ul>
  171.88 -     * <li>Whenever it is invoked on the same object more than once during
  171.89 -     *     an execution of a Java application, the {@code hashCode} method
  171.90 -     *     must consistently return the same integer, provided no information
  171.91 -     *     used in {@code equals} comparisons on the object is modified.
  171.92 -     *     This integer need not remain consistent from one execution of an
  171.93 -     *     application to another execution of the same application.
  171.94 -     * <li>If two objects are equal according to the {@code equals(Object)}
  171.95 -     *     method, then calling the {@code hashCode} method on each of
  171.96 -     *     the two objects must produce the same integer result.
  171.97 -     * <li>It is <em>not</em> required that if two objects are unequal
  171.98 -     *     according to the {@link java.lang.Object#equals(java.lang.Object)}
  171.99 -     *     method, then calling the {@code hashCode} method on each of the
 171.100 -     *     two objects must produce distinct integer results.  However, the
 171.101 -     *     programmer should be aware that producing distinct integer results
 171.102 -     *     for unequal objects may improve the performance of hash tables.
 171.103 -     * </ul>
 171.104 -     * <p>
 171.105 -     * As much as is reasonably practical, the hashCode method defined by
 171.106 -     * class {@code Object} does return distinct integers for distinct
 171.107 -     * objects. (This is typically implemented by converting the internal
 171.108 -     * address of the object into an integer, but this implementation
 171.109 -     * technique is not required by the
 171.110 -     * Java<font size="-2"><sup>TM</sup></font> programming language.)
 171.111 -     *
 171.112 -     * @return  a hash code value for this object.
 171.113 -     * @see     java.lang.Object#equals(java.lang.Object)
 171.114 -     * @see     java.lang.System#identityHashCode
 171.115 -     */
 171.116 -    @JavaScriptBody(args = {}, body = 
 171.117 -        "if (this.$hashCode) return this.$hashCode;\n"
 171.118 -        + "var h = this.computeHashCode__I();\n"
 171.119 -        + "return this.$hashCode = h & h;"
 171.120 -    )
 171.121 -    public native int hashCode();
 171.122 -
 171.123 -    @JavaScriptBody(args = {}, body = "return Math.random() * Math.pow(2, 32);")
 171.124 -    native int computeHashCode();
 171.125 -    
 171.126 -    /**
 171.127 -     * Indicates whether some other object is "equal to" this one.
 171.128 -     * <p>
 171.129 -     * The {@code equals} method implements an equivalence relation
 171.130 -     * on non-null object references:
 171.131 -     * <ul>
 171.132 -     * <li>It is <i>reflexive</i>: for any non-null reference value
 171.133 -     *     {@code x}, {@code x.equals(x)} should return
 171.134 -     *     {@code true}.
 171.135 -     * <li>It is <i>symmetric</i>: for any non-null reference values
 171.136 -     *     {@code x} and {@code y}, {@code x.equals(y)}
 171.137 -     *     should return {@code true} if and only if
 171.138 -     *     {@code y.equals(x)} returns {@code true}.
 171.139 -     * <li>It is <i>transitive</i>: for any non-null reference values
 171.140 -     *     {@code x}, {@code y}, and {@code z}, if
 171.141 -     *     {@code x.equals(y)} returns {@code true} and
 171.142 -     *     {@code y.equals(z)} returns {@code true}, then
 171.143 -     *     {@code x.equals(z)} should return {@code true}.
 171.144 -     * <li>It is <i>consistent</i>: for any non-null reference values
 171.145 -     *     {@code x} and {@code y}, multiple invocations of
 171.146 -     *     {@code x.equals(y)} consistently return {@code true}
 171.147 -     *     or consistently return {@code false}, provided no
 171.148 -     *     information used in {@code equals} comparisons on the
 171.149 -     *     objects is modified.
 171.150 -     * <li>For any non-null reference value {@code x},
 171.151 -     *     {@code x.equals(null)} should return {@code false}.
 171.152 -     * </ul>
 171.153 -     * <p>
 171.154 -     * The {@code equals} method for class {@code Object} implements
 171.155 -     * the most discriminating possible equivalence relation on objects;
 171.156 -     * that is, for any non-null reference values {@code x} and
 171.157 -     * {@code y}, this method returns {@code true} if and only
 171.158 -     * if {@code x} and {@code y} refer to the same object
 171.159 -     * ({@code x == y} has the value {@code true}).
 171.160 -     * <p>
 171.161 -     * Note that it is generally necessary to override the {@code hashCode}
 171.162 -     * method whenever this method is overridden, so as to maintain the
 171.163 -     * general contract for the {@code hashCode} method, which states
 171.164 -     * that equal objects must have equal hash codes.
 171.165 -     *
 171.166 -     * @param   obj   the reference object with which to compare.
 171.167 -     * @return  {@code true} if this object is the same as the obj
 171.168 -     *          argument; {@code false} otherwise.
 171.169 -     * @see     #hashCode()
 171.170 -     * @see     java.util.HashMap
 171.171 -     */
 171.172 -    public boolean equals(Object obj) {
 171.173 -        return (this == obj);
 171.174 -    }
 171.175 -
 171.176 -    /**
 171.177 -     * Creates and returns a copy of this object.  The precise meaning
 171.178 -     * of "copy" may depend on the class of the object. The general
 171.179 -     * intent is that, for any object {@code x}, the expression:
 171.180 -     * <blockquote>
 171.181 -     * <pre>
 171.182 -     * x.clone() != x</pre></blockquote>
 171.183 -     * will be true, and that the expression:
 171.184 -     * <blockquote>
 171.185 -     * <pre>
 171.186 -     * x.clone().getClass() == x.getClass()</pre></blockquote>
 171.187 -     * will be {@code true}, but these are not absolute requirements.
 171.188 -     * While it is typically the case that:
 171.189 -     * <blockquote>
 171.190 -     * <pre>
 171.191 -     * x.clone().equals(x)</pre></blockquote>
 171.192 -     * will be {@code true}, this is not an absolute requirement.
 171.193 -     * <p>
 171.194 -     * By convention, the returned object should be obtained by calling
 171.195 -     * {@code super.clone}.  If a class and all of its superclasses (except
 171.196 -     * {@code Object}) obey this convention, it will be the case that
 171.197 -     * {@code x.clone().getClass() == x.getClass()}.
 171.198 -     * <p>
 171.199 -     * By convention, the object returned by this method should be independent
 171.200 -     * of this object (which is being cloned).  To achieve this independence,
 171.201 -     * it may be necessary to modify one or more fields of the object returned
 171.202 -     * by {@code super.clone} before returning it.  Typically, this means
 171.203 -     * copying any mutable objects that comprise the internal "deep structure"
 171.204 -     * of the object being cloned and replacing the references to these
 171.205 -     * objects with references to the copies.  If a class contains only
 171.206 -     * primitive fields or references to immutable objects, then it is usually
 171.207 -     * the case that no fields in the object returned by {@code super.clone}
 171.208 -     * need to be modified.
 171.209 -     * <p>
 171.210 -     * The method {@code clone} for class {@code Object} performs a
 171.211 -     * specific cloning operation. First, if the class of this object does
 171.212 -     * not implement the interface {@code Cloneable}, then a
 171.213 -     * {@code CloneNotSupportedException} is thrown. Note that all arrays
 171.214 -     * are considered to implement the interface {@code Cloneable} and that
 171.215 -     * the return type of the {@code clone} method of an array type {@code T[]}
 171.216 -     * is {@code T[]} where T is any reference or primitive type.
 171.217 -     * Otherwise, this method creates a new instance of the class of this
 171.218 -     * object and initializes all its fields with exactly the contents of
 171.219 -     * the corresponding fields of this object, as if by assignment; the
 171.220 -     * contents of the fields are not themselves cloned. Thus, this method
 171.221 -     * performs a "shallow copy" of this object, not a "deep copy" operation.
 171.222 -     * <p>
 171.223 -     * The class {@code Object} does not itself implement the interface
 171.224 -     * {@code Cloneable}, so calling the {@code clone} method on an object
 171.225 -     * whose class is {@code Object} will result in throwing an
 171.226 -     * exception at run time.
 171.227 -     *
 171.228 -     * @return     a clone of this instance.
 171.229 -     * @exception  CloneNotSupportedException  if the object's class does not
 171.230 -     *               support the {@code Cloneable} interface. Subclasses
 171.231 -     *               that override the {@code clone} method can also
 171.232 -     *               throw this exception to indicate that an instance cannot
 171.233 -     *               be cloned.
 171.234 -     * @see java.lang.Cloneable
 171.235 -     */
 171.236 -    protected Object clone() throws CloneNotSupportedException {
 171.237 -        Object ret = clone(this);
 171.238 -        if (ret == null) {
 171.239 -            throw new CloneNotSupportedException(getClass().getName());
 171.240 -        }
 171.241 -        return ret;
 171.242 -    }
 171.243 -
 171.244 -    @JavaScriptBody(args = "self", body = 
 171.245 -          "\nif (!self.$instOf_java_lang_Cloneable) {"
 171.246 -        + "\n  return null;"
 171.247 -        + "\n} else {"
 171.248 -        + "\n  var clone = self.constructor(true);"
 171.249 -        + "\n  var props = Object.getOwnPropertyNames(self);"
 171.250 -        + "\n  for (var i = 0; i < props.length; i++) {"
 171.251 -        + "\n    var p = props[i];"
 171.252 -        + "\n    clone[p] = self[p];"
 171.253 -        + "\n  };"
 171.254 -        + "\n  return clone;"
 171.255 -        + "\n}"
 171.256 -    )
 171.257 -    private static native Object clone(Object self) throws CloneNotSupportedException;
 171.258 -
 171.259 -    /**
 171.260 -     * Returns a string representation of the object. In general, the
 171.261 -     * {@code toString} method returns a string that
 171.262 -     * "textually represents" this object. The result should
 171.263 -     * be a concise but informative representation that is easy for a
 171.264 -     * person to read.
 171.265 -     * It is recommended that all subclasses override this method.
 171.266 -     * <p>
 171.267 -     * The {@code toString} method for class {@code Object}
 171.268 -     * returns a string consisting of the name of the class of which the
 171.269 -     * object is an instance, the at-sign character `{@code @}', and
 171.270 -     * the unsigned hexadecimal representation of the hash code of the
 171.271 -     * object. In other words, this method returns a string equal to the
 171.272 -     * value of:
 171.273 -     * <blockquote>
 171.274 -     * <pre>
 171.275 -     * getClass().getName() + '@' + Integer.toHexString(hashCode())
 171.276 -     * </pre></blockquote>
 171.277 -     *
 171.278 -     * @return  a string representation of the object.
 171.279 -     */
 171.280 -    public String toString() {
 171.281 -        return getClass().getName() + "@" + Integer.toHexString(hashCode());
 171.282 -    }
 171.283 -
 171.284 -    /**
 171.285 -     * Wakes up a single thread that is waiting on this object's
 171.286 -     * monitor. If any threads are waiting on this object, one of them
 171.287 -     * is chosen to be awakened. The choice is arbitrary and occurs at
 171.288 -     * the discretion of the implementation. A thread waits on an object's
 171.289 -     * monitor by calling one of the {@code wait} methods.
 171.290 -     * <p>
 171.291 -     * The awakened thread will not be able to proceed until the current
 171.292 -     * thread relinquishes the lock on this object. The awakened thread will
 171.293 -     * compete in the usual manner with any other threads that might be
 171.294 -     * actively competing to synchronize on this object; for example, the
 171.295 -     * awakened thread enjoys no reliable privilege or disadvantage in being
 171.296 -     * the next thread to lock this object.
 171.297 -     * <p>
 171.298 -     * This method should only be called by a thread that is the owner
 171.299 -     * of this object's monitor. A thread becomes the owner of the
 171.300 -     * object's monitor in one of three ways:
 171.301 -     * <ul>
 171.302 -     * <li>By executing a synchronized instance method of that object.
 171.303 -     * <li>By executing the body of a {@code synchronized} statement
 171.304 -     *     that synchronizes on the object.
 171.305 -     * <li>For objects of type {@code Class,} by executing a
 171.306 -     *     synchronized static method of that class.
 171.307 -     * </ul>
 171.308 -     * <p>
 171.309 -     * Only one thread at a time can own an object's monitor.
 171.310 -     *
 171.311 -     * @exception  IllegalMonitorStateException  if the current thread is not
 171.312 -     *               the owner of this object's monitor.
 171.313 -     * @see        java.lang.Object#notifyAll()
 171.314 -     * @see        java.lang.Object#wait()
 171.315 -     */
 171.316 -    public final native void notify();
 171.317 -
 171.318 -    /**
 171.319 -     * Wakes up all threads that are waiting on this object's monitor. A
 171.320 -     * thread waits on an object's monitor by calling one of the
 171.321 -     * {@code wait} methods.
 171.322 -     * <p>
 171.323 -     * The awakened threads will not be able to proceed until the current
 171.324 -     * thread relinquishes the lock on this object. The awakened threads
 171.325 -     * will compete in the usual manner with any other threads that might
 171.326 -     * be actively competing to synchronize on this object; for example,
 171.327 -     * the awakened threads enjoy no reliable privilege or disadvantage in
 171.328 -     * being the next thread to lock this object.
 171.329 -     * <p>
 171.330 -     * This method should only be called by a thread that is the owner
 171.331 -     * of this object's monitor. See the {@code notify} method for a
 171.332 -     * description of the ways in which a thread can become the owner of
 171.333 -     * a monitor.
 171.334 -     *
 171.335 -     * @exception  IllegalMonitorStateException  if the current thread is not
 171.336 -     *               the owner of this object's monitor.
 171.337 -     * @see        java.lang.Object#notify()
 171.338 -     * @see        java.lang.Object#wait()
 171.339 -     */
 171.340 -    public final native void notifyAll();
 171.341 -
 171.342 -    /**
 171.343 -     * Causes the current thread to wait until either another thread invokes the
 171.344 -     * {@link java.lang.Object#notify()} method or the
 171.345 -     * {@link java.lang.Object#notifyAll()} method for this object, or a
 171.346 -     * specified amount of time has elapsed.
 171.347 -     * <p>
 171.348 -     * The current thread must own this object's monitor.
 171.349 -     * <p>
 171.350 -     * This method causes the current thread (call it <var>T</var>) to
 171.351 -     * place itself in the wait set for this object and then to relinquish
 171.352 -     * any and all synchronization claims on this object. Thread <var>T</var>
 171.353 -     * becomes disabled for thread scheduling purposes and lies dormant
 171.354 -     * until one of four things happens:
 171.355 -     * <ul>
 171.356 -     * <li>Some other thread invokes the {@code notify} method for this
 171.357 -     * object and thread <var>T</var> happens to be arbitrarily chosen as
 171.358 -     * the thread to be awakened.
 171.359 -     * <li>Some other thread invokes the {@code notifyAll} method for this
 171.360 -     * object.
 171.361 -     * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
 171.362 -     * thread <var>T</var>.
 171.363 -     * <li>The specified amount of real time has elapsed, more or less.  If
 171.364 -     * {@code timeout} is zero, however, then real time is not taken into
 171.365 -     * consideration and the thread simply waits until notified.
 171.366 -     * </ul>
 171.367 -     * The thread <var>T</var> is then removed from the wait set for this
 171.368 -     * object and re-enabled for thread scheduling. It then competes in the
 171.369 -     * usual manner with other threads for the right to synchronize on the
 171.370 -     * object; once it has gained control of the object, all its
 171.371 -     * synchronization claims on the object are restored to the status quo
 171.372 -     * ante - that is, to the situation as of the time that the {@code wait}
 171.373 -     * method was invoked. Thread <var>T</var> then returns from the
 171.374 -     * invocation of the {@code wait} method. Thus, on return from the
 171.375 -     * {@code wait} method, the synchronization state of the object and of
 171.376 -     * thread {@code T} is exactly as it was when the {@code wait} method
 171.377 -     * was invoked.
 171.378 -     * <p>
 171.379 -     * A thread can also wake up without being notified, interrupted, or
 171.380 -     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
 171.381 -     * occur in practice, applications must guard against it by testing for
 171.382 -     * the condition that should have caused the thread to be awakened, and
 171.383 -     * continuing to wait if the condition is not satisfied.  In other words,
 171.384 -     * waits should always occur in loops, like this one:
 171.385 -     * <pre>
 171.386 -     *     synchronized (obj) {
 171.387 -     *         while (&lt;condition does not hold&gt;)
 171.388 -     *             obj.wait(timeout);
 171.389 -     *         ... // Perform action appropriate to condition
 171.390 -     *     }
 171.391 -     * </pre>
 171.392 -     * (For more information on this topic, see Section 3.2.3 in Doug Lea's
 171.393 -     * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
 171.394 -     * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
 171.395 -     * Language Guide" (Addison-Wesley, 2001).
 171.396 -     *
 171.397 -     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
 171.398 -     * interrupted} by any thread before or while it is waiting, then an
 171.399 -     * {@code InterruptedException} is thrown.  This exception is not
 171.400 -     * thrown until the lock status of this object has been restored as
 171.401 -     * described above.
 171.402 -     *
 171.403 -     * <p>
 171.404 -     * Note that the {@code wait} method, as it places the current thread
 171.405 -     * into the wait set for this object, unlocks only this object; any
 171.406 -     * other objects on which the current thread may be synchronized remain
 171.407 -     * locked while the thread waits.
 171.408 -     * <p>
 171.409 -     * This method should only be called by a thread that is the owner
 171.410 -     * of this object's monitor. See the {@code notify} method for a
 171.411 -     * description of the ways in which a thread can become the owner of
 171.412 -     * a monitor.
 171.413 -     *
 171.414 -     * @param      timeout   the maximum time to wait in milliseconds.
 171.415 -     * @exception  IllegalArgumentException      if the value of timeout is
 171.416 -     *               negative.
 171.417 -     * @exception  IllegalMonitorStateException  if the current thread is not
 171.418 -     *               the owner of the object's monitor.
 171.419 -     * @exception  InterruptedException if any thread interrupted the
 171.420 -     *             current thread before or while the current thread
 171.421 -     *             was waiting for a notification.  The <i>interrupted
 171.422 -     *             status</i> of the current thread is cleared when
 171.423 -     *             this exception is thrown.
 171.424 -     * @see        java.lang.Object#notify()
 171.425 -     * @see        java.lang.Object#notifyAll()
 171.426 -     */
 171.427 -    public final native void wait(long timeout) throws InterruptedException;
 171.428 -
 171.429 -    /**
 171.430 -     * Causes the current thread to wait until another thread invokes the
 171.431 -     * {@link java.lang.Object#notify()} method or the
 171.432 -     * {@link java.lang.Object#notifyAll()} method for this object, or
 171.433 -     * some other thread interrupts the current thread, or a certain
 171.434 -     * amount of real time has elapsed.
 171.435 -     * <p>
 171.436 -     * This method is similar to the {@code wait} method of one
 171.437 -     * argument, but it allows finer control over the amount of time to
 171.438 -     * wait for a notification before giving up. The amount of real time,
 171.439 -     * measured in nanoseconds, is given by:
 171.440 -     * <blockquote>
 171.441 -     * <pre>
 171.442 -     * 1000000*timeout+nanos</pre></blockquote>
 171.443 -     * <p>
 171.444 -     * In all other respects, this method does the same thing as the
 171.445 -     * method {@link #wait(long)} of one argument. In particular,
 171.446 -     * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
 171.447 -     * <p>
 171.448 -     * The current thread must own this object's monitor. The thread
 171.449 -     * releases ownership of this monitor and waits until either of the
 171.450 -     * following two conditions has occurred:
 171.451 -     * <ul>
 171.452 -     * <li>Another thread notifies threads waiting on this object's monitor
 171.453 -     *     to wake up either through a call to the {@code notify} method
 171.454 -     *     or the {@code notifyAll} method.
 171.455 -     * <li>The timeout period, specified by {@code timeout}
 171.456 -     *     milliseconds plus {@code nanos} nanoseconds arguments, has
 171.457 -     *     elapsed.
 171.458 -     * </ul>
 171.459 -     * <p>
 171.460 -     * The thread then waits until it can re-obtain ownership of the
 171.461 -     * monitor and resumes execution.
 171.462 -     * <p>
 171.463 -     * As in the one argument version, interrupts and spurious wakeups are
 171.464 -     * possible, and this method should always be used in a loop:
 171.465 -     * <pre>
 171.466 -     *     synchronized (obj) {
 171.467 -     *         while (&lt;condition does not hold&gt;)
 171.468 -     *             obj.wait(timeout, nanos);
 171.469 -     *         ... // Perform action appropriate to condition
 171.470 -     *     }
 171.471 -     * </pre>
 171.472 -     * This method should only be called by a thread that is the owner
 171.473 -     * of this object's monitor. See the {@code notify} method for a
 171.474 -     * description of the ways in which a thread can become the owner of
 171.475 -     * a monitor.
 171.476 -     *
 171.477 -     * @param      timeout   the maximum time to wait in milliseconds.
 171.478 -     * @param      nanos      additional time, in nanoseconds range
 171.479 -     *                       0-999999.
 171.480 -     * @exception  IllegalArgumentException      if the value of timeout is
 171.481 -     *                      negative or the value of nanos is
 171.482 -     *                      not in the range 0-999999.
 171.483 -     * @exception  IllegalMonitorStateException  if the current thread is not
 171.484 -     *               the owner of this object's monitor.
 171.485 -     * @exception  InterruptedException if any thread interrupted the
 171.486 -     *             current thread before or while the current thread
 171.487 -     *             was waiting for a notification.  The <i>interrupted
 171.488 -     *             status</i> of the current thread is cleared when
 171.489 -     *             this exception is thrown.
 171.490 -     */
 171.491 -    public final void wait(long timeout, int nanos) throws InterruptedException {
 171.492 -        if (timeout < 0) {
 171.493 -            throw new IllegalArgumentException("timeout value is negative");
 171.494 -        }
 171.495 -
 171.496 -        if (nanos < 0 || nanos > 999999) {
 171.497 -            throw new IllegalArgumentException(
 171.498 -                                "nanosecond timeout value out of range");
 171.499 -        }
 171.500 -
 171.501 -        if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
 171.502 -            timeout++;
 171.503 -        }
 171.504 -
 171.505 -        wait(timeout);
 171.506 -    }
 171.507 -
 171.508 -    /**
 171.509 -     * Causes the current thread to wait until another thread invokes the
 171.510 -     * {@link java.lang.Object#notify()} method or the
 171.511 -     * {@link java.lang.Object#notifyAll()} method for this object.
 171.512 -     * In other words, this method behaves exactly as if it simply
 171.513 -     * performs the call {@code wait(0)}.
 171.514 -     * <p>
 171.515 -     * The current thread must own this object's monitor. The thread
 171.516 -     * releases ownership of this monitor and waits until another thread
 171.517 -     * notifies threads waiting on this object's monitor to wake up
 171.518 -     * either through a call to the {@code notify} method or the
 171.519 -     * {@code notifyAll} method. The thread then waits until it can
 171.520 -     * re-obtain ownership of the monitor and resumes execution.
 171.521 -     * <p>
 171.522 -     * As in the one argument version, interrupts and spurious wakeups are
 171.523 -     * possible, and this method should always be used in a loop:
 171.524 -     * <pre>
 171.525 -     *     synchronized (obj) {
 171.526 -     *         while (&lt;condition does not hold&gt;)
 171.527 -     *             obj.wait();
 171.528 -     *         ... // Perform action appropriate to condition
 171.529 -     *     }
 171.530 -     * </pre>
 171.531 -     * This method should only be called by a thread that is the owner
 171.532 -     * of this object's monitor. See the {@code notify} method for a
 171.533 -     * description of the ways in which a thread can become the owner of
 171.534 -     * a monitor.
 171.535 -     *
 171.536 -     * @exception  IllegalMonitorStateException  if the current thread is not
 171.537 -     *               the owner of the object's monitor.
 171.538 -     * @exception  InterruptedException if any thread interrupted the
 171.539 -     *             current thread before or while the current thread
 171.540 -     *             was waiting for a notification.  The <i>interrupted
 171.541 -     *             status</i> of the current thread is cleared when
 171.542 -     *             this exception is thrown.
 171.543 -     * @see        java.lang.Object#notify()
 171.544 -     * @see        java.lang.Object#notifyAll()
 171.545 -     */
 171.546 -    public final void wait() throws InterruptedException {
 171.547 -        wait(0);
 171.548 -    }
 171.549 -
 171.550 -    /**
 171.551 -     * Called by the garbage collector on an object when garbage collection
 171.552 -     * determines that there are no more references to the object.
 171.553 -     * A subclass overrides the {@code finalize} method to dispose of
 171.554 -     * system resources or to perform other cleanup.
 171.555 -     * <p>
 171.556 -     * The general contract of {@code finalize} is that it is invoked
 171.557 -     * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
 171.558 -     * machine has determined that there is no longer any
 171.559 -     * means by which this object can be accessed by any thread that has
 171.560 -     * not yet died, except as a result of an action taken by the
 171.561 -     * finalization of some other object or class which is ready to be
 171.562 -     * finalized. The {@code finalize} method may take any action, including
 171.563 -     * making this object available again to other threads; the usual purpose
 171.564 -     * of {@code finalize}, however, is to perform cleanup actions before
 171.565 -     * the object is irrevocably discarded. For example, the finalize method
 171.566 -     * for an object that represents an input/output connection might perform
 171.567 -     * explicit I/O transactions to break the connection before the object is
 171.568 -     * permanently discarded.
 171.569 -     * <p>
 171.570 -     * The {@code finalize} method of class {@code Object} performs no
 171.571 -     * special action; it simply returns normally. Subclasses of
 171.572 -     * {@code Object} may override this definition.
 171.573 -     * <p>
 171.574 -     * The Java programming language does not guarantee which thread will
 171.575 -     * invoke the {@code finalize} method for any given object. It is
 171.576 -     * guaranteed, however, that the thread that invokes finalize will not
 171.577 -     * be holding any user-visible synchronization locks when finalize is
 171.578 -     * invoked. If an uncaught exception is thrown by the finalize method,
 171.579 -     * the exception is ignored and finalization of that object terminates.
 171.580 -     * <p>
 171.581 -     * After the {@code finalize} method has been invoked for an object, no
 171.582 -     * further action is taken until the Java virtual machine has again
 171.583 -     * determined that there is no longer any means by which this object can
 171.584 -     * be accessed by any thread that has not yet died, including possible
 171.585 -     * actions by other objects or classes which are ready to be finalized,
 171.586 -     * at which point the object may be discarded.
 171.587 -     * <p>
 171.588 -     * The {@code finalize} method is never invoked more than once by a Java
 171.589 -     * virtual machine for any given object.
 171.590 -     * <p>
 171.591 -     * Any exception thrown by the {@code finalize} method causes
 171.592 -     * the finalization of this object to be halted, but is otherwise
 171.593 -     * ignored.
 171.594 -     *
 171.595 -     * @throws Throwable the {@code Exception} raised by this method
 171.596 -     */
 171.597 -    protected void finalize() throws Throwable { }
 171.598 -}
   172.1 --- a/emul/mini/src/main/java/java/lang/OutOfMemoryError.java	Mon Feb 25 19:00:08 2013 +0100
   172.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   172.3 @@ -1,60 +0,0 @@
   172.4 -/*
   172.5 - * Copyright (c) 1994, 2011, 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;
  172.30 -
  172.31 -/**
  172.32 - * Thrown when the Java Virtual Machine cannot allocate an object
  172.33 - * because it is out of memory, and no more memory could be made
  172.34 - * available by the garbage collector.
  172.35 - *
  172.36 - * {@code OutOfMemoryError} objects may be constructed by the virtual
  172.37 - * machine as if {@linkplain Throwable#Throwable(String, Throwable,
  172.38 - * boolean, boolean) suppression were disabled and/or the stack trace was not
  172.39 - * writable}.
  172.40 - *
  172.41 - * @author  unascribed
  172.42 - * @since   JDK1.0
  172.43 - */
  172.44 -public class OutOfMemoryError extends VirtualMachineError {
  172.45 -    private static final long serialVersionUID = 8228564086184010517L;
  172.46 -
  172.47 -    /**
  172.48 -     * Constructs an {@code OutOfMemoryError} with no detail message.
  172.49 -     */
  172.50 -    public OutOfMemoryError() {
  172.51 -        super();
  172.52 -    }
  172.53 -
  172.54 -    /**
  172.55 -     * Constructs an {@code OutOfMemoryError} with the specified
  172.56 -     * detail message.
  172.57 -     *
  172.58 -     * @param   s   the detail message.
  172.59 -     */
  172.60 -    public OutOfMemoryError(String s) {
  172.61 -        super(s);
  172.62 -    }
  172.63 -}
   173.1 --- a/emul/mini/src/main/java/java/lang/Override.java	Mon Feb 25 19:00:08 2013 +0100
   173.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   173.3 @@ -1,52 +0,0 @@
   173.4 -/*
   173.5 - * Copyright (c) 2003, 2006, 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;
  173.30 -
  173.31 -import java.lang.annotation.*;
  173.32 -
  173.33 -/**
  173.34 - * Indicates that a method declaration is intended to override a
  173.35 - * method declaration in a supertype. If a method is annotated with
  173.36 - * this annotation type compilers are required to generate an error
  173.37 - * message unless at least one of the following conditions hold:
  173.38 - *
  173.39 - * <ul><li>
  173.40 - * The method does override or implement a method declared in a
  173.41 - * supertype.
  173.42 - * </li><li>
  173.43 - * The method has a signature that is override-equivalent to that of
  173.44 - * any public method declared in {@linkplain Object}.
  173.45 - * </li></ul>
  173.46 - *
  173.47 - * @author  Peter von der Ah&eacute;
  173.48 - * @author  Joshua Bloch
  173.49 - * @jls 9.6.1.4 Override
  173.50 - * @since 1.5
  173.51 - */
  173.52 -@Target(ElementType.METHOD)
  173.53 -@Retention(RetentionPolicy.SOURCE)
  173.54 -public @interface Override {
  173.55 -}
   174.1 --- a/emul/mini/src/main/java/java/lang/ReflectiveOperationException.java	Mon Feb 25 19:00:08 2013 +0100
   174.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   174.3 @@ -1,91 +0,0 @@
   174.4 -/*
   174.5 - * Copyright (c) 2009, 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;
  174.30 -
  174.31 -/**
  174.32 - * Common superclass of exceptions thrown by reflective operations in
  174.33 - * core reflection.
  174.34 - *
  174.35 - * @see LinkageError
  174.36 - * @since 1.7
  174.37 - */
  174.38 -public class ReflectiveOperationException extends Exception {
  174.39 -    static final long serialVersionUID = 123456789L;
  174.40 -
  174.41 -    /**
  174.42 -     * Constructs a new exception with {@code null} as its detail
  174.43 -     * message.  The cause is not initialized, and may subsequently be
  174.44 -     * initialized by a call to {@link #initCause}.
  174.45 -     */
  174.46 -    public ReflectiveOperationException() {
  174.47 -        super();
  174.48 -    }
  174.49 -
  174.50 -    /**
  174.51 -     * Constructs a new exception with the specified detail message.
  174.52 -     * The cause is not initialized, and may subsequently be
  174.53 -     * initialized by a call to {@link #initCause}.
  174.54 -     *
  174.55 -     * @param   message   the detail message. The detail message is saved for
  174.56 -     *          later retrieval by the {@link #getMessage()} method.
  174.57 -     */
  174.58 -    public ReflectiveOperationException(String message) {
  174.59 -        super(message);
  174.60 -    }
  174.61 -
  174.62 -    /**
  174.63 -     * Constructs a new exception with the specified detail message
  174.64 -     * and cause.
  174.65 -     *
  174.66 -     * <p>Note that the detail message associated with
  174.67 -     * {@code cause} is <em>not</em> automatically incorporated in
  174.68 -     * this exception's detail message.
  174.69 -     *
  174.70 -     * @param  message the detail message (which is saved for later retrieval
  174.71 -     *         by the {@link #getMessage()} method).
  174.72 -     * @param  cause the cause (which is saved for later retrieval by the
  174.73 -     *         {@link #getCause()} method).  (A {@code null} value is
  174.74 -     *         permitted, and indicates that the cause is nonexistent or
  174.75 -     *         unknown.)
  174.76 -     */
  174.77 -    public ReflectiveOperationException(String message, Throwable cause) {
  174.78 -        super(message, cause);
  174.79 -    }
  174.80 -
  174.81 -    /**
  174.82 -     * Constructs a new exception with the specified cause and a detail
  174.83 -     * message of {@code (cause==null ? null : cause.toString())} (which
  174.84 -     * typically contains the class and detail message of {@code cause}).
  174.85 -     *
  174.86 -     * @param  cause the cause (which is saved for later retrieval by the
  174.87 -     *         {@link #getCause()} method).  (A {@code null} value is
  174.88 -     *         permitted, and indicates that the cause is nonexistent or
  174.89 -     *         unknown.)
  174.90 -     */
  174.91 -    public ReflectiveOperationException(Throwable cause) {
  174.92 -        super(cause);
  174.93 -    }
  174.94 -}
   175.1 --- a/emul/mini/src/main/java/java/lang/Runnable.java	Mon Feb 25 19:00:08 2013 +0100
   175.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   175.3 @@ -1,69 +0,0 @@
   175.4 -/*
   175.5 - * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
   175.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   175.7 - *
   175.8 - * This code is free software; you can redistribute it and/or modify it
   175.9 - * under the terms of the GNU General Public License version 2 only, as
  175.10 - * published by the Free Software Foundation.  Oracle designates this
  175.11 - * particular file as subject to the "Classpath" exception as provided
  175.12 - * by Oracle in the LICENSE file that accompanied this code.
  175.13 - *
  175.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  175.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  175.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  175.17 - * version 2 for more details (a copy is included in the LICENSE file that
  175.18 - * accompanied this code).
  175.19 - *
  175.20 - * You should have received a copy of the GNU General Public License version
  175.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  175.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  175.23 - *
  175.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  175.25 - * or visit www.oracle.com if you need additional information or have any
  175.26 - * questions.
  175.27 - */
  175.28 -
  175.29 -package java.lang;
  175.30 -
  175.31 -/**
  175.32 - * The <code>Runnable</code> interface should be implemented by any
  175.33 - * class whose instances are intended to be executed by a thread. The
  175.34 - * class must define a method of no arguments called <code>run</code>.
  175.35 - * <p>
  175.36 - * This interface is designed to provide a common protocol for objects that
  175.37 - * wish to execute code while they are active. For example,
  175.38 - * <code>Runnable</code> is implemented by class <code>Thread</code>.
  175.39 - * Being active simply means that a thread has been started and has not
  175.40 - * yet been stopped.
  175.41 - * <p>
  175.42 - * In addition, <code>Runnable</code> provides the means for a class to be
  175.43 - * active while not subclassing <code>Thread</code>. A class that implements
  175.44 - * <code>Runnable</code> can run without subclassing <code>Thread</code>
  175.45 - * by instantiating a <code>Thread</code> instance and passing itself in
  175.46 - * as the target.  In most cases, the <code>Runnable</code> interface should
  175.47 - * be used if you are only planning to override the <code>run()</code>
  175.48 - * method and no other <code>Thread</code> methods.
  175.49 - * This is important because classes should not be subclassed
  175.50 - * unless the programmer intends on modifying or enhancing the fundamental
  175.51 - * behavior of the class.
  175.52 - *
  175.53 - * @author  Arthur van Hoff
  175.54 - * @see     java.lang.Thread
  175.55 - * @see     java.util.concurrent.Callable
  175.56 - * @since   JDK1.0
  175.57 - */
  175.58 -public
  175.59 -interface Runnable {
  175.60 -    /**
  175.61 -     * When an object implementing interface <code>Runnable</code> is used
  175.62 -     * to create a thread, starting the thread causes the object's
  175.63 -     * <code>run</code> method to be called in that separately executing
  175.64 -     * thread.
  175.65 -     * <p>
  175.66 -     * The general contract of the method <code>run</code> is that it may
  175.67 -     * take any action whatsoever.
  175.68 -     *
  175.69 -     * @see     java.lang.Thread#run()
  175.70 -     */
  175.71 -    public abstract void run();
  175.72 -}
   176.1 --- a/emul/mini/src/main/java/java/lang/RuntimeException.java	Mon Feb 25 19:00:08 2013 +0100
   176.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   176.3 @@ -1,119 +0,0 @@
   176.4 -/*
   176.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   176.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   176.7 - *
   176.8 - * This code is free software; you can redistribute it and/or modify it
   176.9 - * under the terms of the GNU General Public License version 2 only, as
  176.10 - * published by the Free Software Foundation.  Oracle designates this
  176.11 - * particular file as subject to the "Classpath" exception as provided
  176.12 - * by Oracle in the LICENSE file that accompanied this code.
  176.13 - *
  176.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  176.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  176.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  176.17 - * version 2 for more details (a copy is included in the LICENSE file that
  176.18 - * accompanied this code).
  176.19 - *
  176.20 - * You should have received a copy of the GNU General Public License version
  176.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  176.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  176.23 - *
  176.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  176.25 - * or visit www.oracle.com if you need additional information or have any
  176.26 - * questions.
  176.27 - */
  176.28 -
  176.29 -package java.lang;
  176.30 -
  176.31 -/**
  176.32 - * {@code RuntimeException} is the superclass of those
  176.33 - * exceptions that can be thrown during the normal operation of the
  176.34 - * Java Virtual Machine.
  176.35 - *
  176.36 - * <p>{@code RuntimeException} and its subclasses are <em>unchecked
  176.37 - * exceptions</em>.  Unchecked exceptions do <em>not</em> need to be
  176.38 - * declared in a method or constructor's {@code throws} clause if they
  176.39 - * can be thrown by the execution of the method or constructor and
  176.40 - * propagate outside the method or constructor boundary.
  176.41 - *
  176.42 - * @author  Frank Yellin
  176.43 - * @jls 11.2 Compile-Time Checking of Exceptions
  176.44 - * @since   JDK1.0
  176.45 - */
  176.46 -public class RuntimeException extends Exception {
  176.47 -    static final long serialVersionUID = -7034897190745766939L;
  176.48 -
  176.49 -    /** Constructs a new runtime exception with {@code null} as its
  176.50 -     * detail message.  The cause is not initialized, and may subsequently be
  176.51 -     * initialized by a call to {@link #initCause}.
  176.52 -     */
  176.53 -    public RuntimeException() {
  176.54 -        super();
  176.55 -    }
  176.56 -
  176.57 -    /** Constructs a new runtime exception with the specified detail message.
  176.58 -     * The cause is not initialized, and may subsequently be initialized by a
  176.59 -     * call to {@link #initCause}.
  176.60 -     *
  176.61 -     * @param   message   the detail message. The detail message is saved for
  176.62 -     *          later retrieval by the {@link #getMessage()} method.
  176.63 -     */
  176.64 -    public RuntimeException(String message) {
  176.65 -        super(message);
  176.66 -    }
  176.67 -
  176.68 -    /**
  176.69 -     * Constructs a new runtime exception with the specified detail message and
  176.70 -     * cause.  <p>Note that the detail message associated with
  176.71 -     * {@code cause} is <i>not</i> automatically incorporated in
  176.72 -     * this runtime exception's detail message.
  176.73 -     *
  176.74 -     * @param  message the detail message (which is saved for later retrieval
  176.75 -     *         by the {@link #getMessage()} method).
  176.76 -     * @param  cause the cause (which is saved for later retrieval by the
  176.77 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  176.78 -     *         permitted, and indicates that the cause is nonexistent or
  176.79 -     *         unknown.)
  176.80 -     * @since  1.4
  176.81 -     */
  176.82 -    public RuntimeException(String message, Throwable cause) {
  176.83 -        super(message, cause);
  176.84 -    }
  176.85 -
  176.86 -    /** Constructs a new runtime exception with the specified cause and a
  176.87 -     * detail message of <tt>(cause==null ? null : cause.toString())</tt>
  176.88 -     * (which typically contains the class and detail message of
  176.89 -     * <tt>cause</tt>).  This constructor is useful for runtime exceptions
  176.90 -     * that are little more than wrappers for other throwables.
  176.91 -     *
  176.92 -     * @param  cause the cause (which is saved for later retrieval by the
  176.93 -     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  176.94 -     *         permitted, and indicates that the cause is nonexistent or
  176.95 -     *         unknown.)
  176.96 -     * @since  1.4
  176.97 -     */
  176.98 -    public RuntimeException(Throwable cause) {
  176.99 -        super(cause);
 176.100 -    }
 176.101 -
 176.102 -    /**
 176.103 -     * Constructs a new runtime exception with the specified detail
 176.104 -     * message, cause, suppression enabled or disabled, and writable
 176.105 -     * stack trace enabled or disabled.
 176.106 -     *
 176.107 -     * @param  message the detail message.
 176.108 -     * @param cause the cause.  (A {@code null} value is permitted,
 176.109 -     * and indicates that the cause is nonexistent or unknown.)
 176.110 -     * @param enableSuppression whether or not suppression is enabled
 176.111 -     *                          or disabled
 176.112 -     * @param writableStackTrace whether or not the stack trace should
 176.113 -     *                           be writable
 176.114 -     *
 176.115 -     * @since 1.7
 176.116 -     */
 176.117 -    protected RuntimeException(String message, Throwable cause,
 176.118 -                               boolean enableSuppression,
 176.119 -                               boolean writableStackTrace) {
 176.120 -        super(message, cause, enableSuppression, writableStackTrace);
 176.121 -    }
 176.122 -}
   177.1 --- a/emul/mini/src/main/java/java/lang/SecurityException.java	Mon Feb 25 19:00:08 2013 +0100
   177.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   177.3 @@ -1,84 +0,0 @@
   177.4 -/*
   177.5 - * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
   177.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   177.7 - *
   177.8 - * This code is free software; you can redistribute it and/or modify it
   177.9 - * under the terms of the GNU General Public License version 2 only, as
  177.10 - * published by the Free Software Foundation.  Oracle designates this
  177.11 - * particular file as subject to the "Classpath" exception as provided
  177.12 - * by Oracle in the LICENSE file that accompanied this code.
  177.13 - *
  177.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  177.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  177.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  177.17 - * version 2 for more details (a copy is included in the LICENSE file that
  177.18 - * accompanied this code).
  177.19 - *
  177.20 - * You should have received a copy of the GNU General Public License version
  177.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  177.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  177.23 - *
  177.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  177.25 - * or visit www.oracle.com if you need additional information or have any
  177.26 - * questions.
  177.27 - */
  177.28 -package java.lang;
  177.29 -
  177.30 -/**
  177.31 - * Thrown by the security manager to indicate a security violation.
  177.32 - *
  177.33 - * @author  unascribed
  177.34 - * @see     java.lang.SecurityManager
  177.35 - * @since   JDK1.0
  177.36 - */
  177.37 -public class SecurityException extends RuntimeException {
  177.38 -
  177.39 -    private static final long serialVersionUID = 6878364983674394167L;
  177.40 -
  177.41 -    /**
  177.42 -     * Constructs a <code>SecurityException</code> with no detail  message.
  177.43 -     */
  177.44 -    public SecurityException() {
  177.45 -        super();
  177.46 -    }
  177.47 -
  177.48 -    /**
  177.49 -     * Constructs a <code>SecurityException</code> with the specified
  177.50 -     * detail message.
  177.51 -     *
  177.52 -     * @param   s   the detail message.
  177.53 -     */
  177.54 -    public SecurityException(String s) {
  177.55 -        super(s);
  177.56 -    }
  177.57 -
  177.58 -    /**
  177.59 -     * Creates a <code>SecurityException</code> with the specified
  177.60 -     * detail message and cause.
  177.61 -     *
  177.62 -     * @param message the detail message (which is saved for later retrieval
  177.63 -     *        by the {@link #getMessage()} method).
  177.64 -     * @param cause the cause (which is saved for later retrieval by the
  177.65 -     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  177.66 -     *        and indicates that the cause is nonexistent or unknown.)
  177.67 -     * @since 1.5
  177.68 -     */
  177.69 -    public SecurityException(String message, Throwable cause) {
  177.70 -        super(message, cause);
  177.71 -    }
  177.72 -
  177.73 -    /**
  177.74 -     * Creates a <code>SecurityException</code> with the specified cause
  177.75 -     * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
  177.76 -     * (which typically contains the class and detail message of
  177.77 -     * <tt>cause</tt>).
  177.78 -     *
  177.79 -     * @param cause the cause (which is saved for later retrieval by the
  177.80 -     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  177.81 -     *        and indicates that the cause is nonexistent or unknown.)
  177.82 -     * @since 1.5
  177.83 -     */
  177.84 -    public SecurityException(Throwable cause) {
  177.85 -        super(cause);
  177.86 -    }
  177.87 -}
   178.1 --- a/emul/mini/src/main/java/java/lang/Short.java	Mon Feb 25 19:00:08 2013 +0100
   178.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   178.3 @@ -1,468 +0,0 @@
   178.4 -/*
   178.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   178.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   178.7 - *
   178.8 - * This code is free software; you can redistribute it and/or modify it
   178.9 - * under the terms of the GNU General Public License version 2 only, as
  178.10 - * published by the Free Software Foundation.  Oracle designates this
  178.11 - * particular file as subject to the "Classpath" exception as provided
  178.12 - * by Oracle in the LICENSE file that accompanied this code.
  178.13 - *
  178.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  178.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  178.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  178.17 - * version 2 for more details (a copy is included in the LICENSE file that
  178.18 - * accompanied this code).
  178.19 - *
  178.20 - * You should have received a copy of the GNU General Public License version
  178.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  178.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  178.23 - *
  178.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  178.25 - * or visit www.oracle.com if you need additional information or have any
  178.26 - * questions.
  178.27 - */
  178.28 -
  178.29 -package java.lang;
  178.30 -
  178.31 -/**
  178.32 - * The {@code Short} class wraps a value of primitive type {@code
  178.33 - * short} in an object.  An object of type {@code Short} contains a
  178.34 - * single field whose type is {@code short}.
  178.35 - *
  178.36 - * <p>In addition, this class provides several methods for converting
  178.37 - * a {@code short} to a {@code String} and a {@code String} to a
  178.38 - * {@code short}, as well as other constants and methods useful when
  178.39 - * dealing with a {@code short}.
  178.40 - *
  178.41 - * @author  Nakul Saraiya
  178.42 - * @author  Joseph D. Darcy
  178.43 - * @see     java.lang.Number
  178.44 - * @since   JDK1.1
  178.45 - */
  178.46 -public final class Short extends Number implements Comparable<Short> {
  178.47 -
  178.48 -    /**
  178.49 -     * A constant holding the minimum value a {@code short} can
  178.50 -     * have, -2<sup>15</sup>.
  178.51 -     */
  178.52 -    public static final short   MIN_VALUE = -32768;
  178.53 -
  178.54 -    /**
  178.55 -     * A constant holding the maximum value a {@code short} can
  178.56 -     * have, 2<sup>15</sup>-1.
  178.57 -     */
  178.58 -    public static final short   MAX_VALUE = 32767;
  178.59 -
  178.60 -    /**
  178.61 -     * The {@code Class} instance representing the primitive type
  178.62 -     * {@code short}.
  178.63 -     */
  178.64 -    public static final Class<Short>    TYPE = (Class<Short>) Class.getPrimitiveClass("short");
  178.65 -
  178.66 -    /**
  178.67 -     * Returns a new {@code String} object representing the
  178.68 -     * specified {@code short}. The radix is assumed to be 10.
  178.69 -     *
  178.70 -     * @param s the {@code short} to be converted
  178.71 -     * @return the string representation of the specified {@code short}
  178.72 -     * @see java.lang.Integer#toString(int)
  178.73 -     */
  178.74 -    public static String toString(short s) {
  178.75 -        return Integer.toString((int)s, 10);
  178.76 -    }
  178.77 -
  178.78 -    /**
  178.79 -     * Parses the string argument as a signed {@code short} in the
  178.80 -     * radix specified by the second argument. The characters in the
  178.81 -     * string must all be digits, of the specified radix (as
  178.82 -     * determined by whether {@link java.lang.Character#digit(char,
  178.83 -     * int)} returns a nonnegative value) except that the first
  178.84 -     * character may be an ASCII minus sign {@code '-'}
  178.85 -     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
  178.86 -     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
  178.87 -     * indicate a positive value.  The resulting {@code short} value
  178.88 -     * is returned.
  178.89 -     *
  178.90 -     * <p>An exception of type {@code NumberFormatException} is
  178.91 -     * thrown if any of the following situations occurs:
  178.92 -     * <ul>
  178.93 -     * <li> The first argument is {@code null} or is a string of
  178.94 -     * length zero.
  178.95 -     *
  178.96 -     * <li> The radix is either smaller than {@link
  178.97 -     * java.lang.Character#MIN_RADIX} or larger than {@link
  178.98 -     * java.lang.Character#MAX_RADIX}.
  178.99 -     *
 178.100 -     * <li> Any character of the string is not a digit of the
 178.101 -     * specified radix, except that the first character may be a minus
 178.102 -     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 178.103 -     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 178.104 -     * string is longer than length 1.
 178.105 -     *
 178.106 -     * <li> The value represented by the string is not a value of type
 178.107 -     * {@code short}.
 178.108 -     * </ul>
 178.109 -     *
 178.110 -     * @param s         the {@code String} containing the
 178.111 -     *                  {@code short} representation to be parsed
 178.112 -     * @param radix     the radix to be used while parsing {@code s}
 178.113 -     * @return          the {@code short} represented by the string
 178.114 -     *                  argument in the specified radix.
 178.115 -     * @throws          NumberFormatException If the {@code String}
 178.116 -     *                  does not contain a parsable {@code short}.
 178.117 -     */
 178.118 -    public static short parseShort(String s, int radix)
 178.119 -        throws NumberFormatException {
 178.120 -        int i = Integer.parseInt(s, radix);
 178.121 -        if (i < MIN_VALUE || i > MAX_VALUE)
 178.122 -            throw new NumberFormatException(
 178.123 -                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 178.124 -        return (short)i;
 178.125 -    }
 178.126 -
 178.127 -    /**
 178.128 -     * Parses the string argument as a signed decimal {@code
 178.129 -     * short}. The characters in the string must all be decimal
 178.130 -     * digits, except that the first character may be an ASCII minus
 178.131 -     * sign {@code '-'} (<code>'&#92;u002D'</code>) to indicate a
 178.132 -     * negative value or an ASCII plus sign {@code '+'}
 178.133 -     * (<code>'&#92;u002B'</code>) to indicate a positive value.  The
 178.134 -     * resulting {@code short} value is returned, exactly as if the
 178.135 -     * argument and the radix 10 were given as arguments to the {@link
 178.136 -     * #parseShort(java.lang.String, int)} method.
 178.137 -     *
 178.138 -     * @param s a {@code String} containing the {@code short}
 178.139 -     *          representation to be parsed
 178.140 -     * @return  the {@code short} value represented by the
 178.141 -     *          argument in decimal.
 178.142 -     * @throws  NumberFormatException If the string does not
 178.143 -     *          contain a parsable {@code short}.
 178.144 -     */
 178.145 -    public static short parseShort(String s) throws NumberFormatException {
 178.146 -        return parseShort(s, 10);
 178.147 -    }
 178.148 -
 178.149 -    /**
 178.150 -     * Returns a {@code Short} object holding the value
 178.151 -     * extracted from the specified {@code String} when parsed
 178.152 -     * with the radix given by the second argument. The first argument
 178.153 -     * is interpreted as representing a signed {@code short} in
 178.154 -     * the radix specified by the second argument, exactly as if the
 178.155 -     * argument were given to the {@link #parseShort(java.lang.String,
 178.156 -     * int)} method. The result is a {@code Short} object that
 178.157 -     * represents the {@code short} value specified by the string.
 178.158 -     *
 178.159 -     * <p>In other words, this method returns a {@code Short} object
 178.160 -     * equal to the value of:
 178.161 -     *
 178.162 -     * <blockquote>
 178.163 -     *  {@code new Short(Short.parseShort(s, radix))}
 178.164 -     * </blockquote>
 178.165 -     *
 178.166 -     * @param s         the string to be parsed
 178.167 -     * @param radix     the radix to be used in interpreting {@code s}
 178.168 -     * @return          a {@code Short} object holding the value
 178.169 -     *                  represented by the string argument in the
 178.170 -     *                  specified radix.
 178.171 -     * @throws          NumberFormatException If the {@code String} does
 178.172 -     *                  not contain a parsable {@code short}.
 178.173 -     */
 178.174 -    public static Short valueOf(String s, int radix)
 178.175 -        throws NumberFormatException {
 178.176 -        return valueOf(parseShort(s, radix));
 178.177 -    }
 178.178 -
 178.179 -    /**
 178.180 -     * Returns a {@code Short} object holding the
 178.181 -     * value given by the specified {@code String}. The argument
 178.182 -     * is interpreted as representing a signed decimal
 178.183 -     * {@code short}, exactly as if the argument were given to
 178.184 -     * the {@link #parseShort(java.lang.String)} method. The result is
 178.185 -     * a {@code Short} object that represents the
 178.186 -     * {@code short} value specified by the string.
 178.187 -     *
 178.188 -     * <p>In other words, this method returns a {@code Short} object
 178.189 -     * equal to the value of:
 178.190 -     *
 178.191 -     * <blockquote>
 178.192 -     *  {@code new Short(Short.parseShort(s))}
 178.193 -     * </blockquote>
 178.194 -     *
 178.195 -     * @param s the string to be parsed
 178.196 -     * @return  a {@code Short} object holding the value
 178.197 -     *          represented by the string argument
 178.198 -     * @throws  NumberFormatException If the {@code String} does
 178.199 -     *          not contain a parsable {@code short}.
 178.200 -     */
 178.201 -    public static Short valueOf(String s) throws NumberFormatException {
 178.202 -        return valueOf(s, 10);
 178.203 -    }
 178.204 -
 178.205 -    private static class ShortCache {
 178.206 -        private ShortCache(){}
 178.207 -
 178.208 -        static final Short cache[] = new Short[-(-128) + 127 + 1];
 178.209 -
 178.210 -        static {
 178.211 -            for(int i = 0; i < cache.length; i++)
 178.212 -                cache[i] = new Short((short)(i - 128));
 178.213 -        }
 178.214 -    }
 178.215 -
 178.216 -    /**
 178.217 -     * Returns a {@code Short} instance representing the specified
 178.218 -     * {@code short} value.
 178.219 -     * If a new {@code Short} instance is not required, this method
 178.220 -     * should generally be used in preference to the constructor
 178.221 -     * {@link #Short(short)}, as this method is likely to yield
 178.222 -     * significantly better space and time performance by caching
 178.223 -     * frequently requested values.
 178.224 -     *
 178.225 -     * This method will always cache values in the range -128 to 127,
 178.226 -     * inclusive, and may cache other values outside of this range.
 178.227 -     *
 178.228 -     * @param  s a short value.
 178.229 -     * @return a {@code Short} instance representing {@code s}.
 178.230 -     * @since  1.5
 178.231 -     */
 178.232 -    public static Short valueOf(short s) {
 178.233 -        final int offset = 128;
 178.234 -        int sAsInt = s;
 178.235 -        if (sAsInt >= -128 && sAsInt <= 127) { // must cache
 178.236 -            return ShortCache.cache[sAsInt + offset];
 178.237 -        }
 178.238 -        return new Short(s);
 178.239 -    }
 178.240 -
 178.241 -    /**
 178.242 -     * Decodes a {@code String} into a {@code Short}.
 178.243 -     * Accepts decimal, hexadecimal, and octal numbers given by
 178.244 -     * the following grammar:
 178.245 -     *
 178.246 -     * <blockquote>
 178.247 -     * <dl>
 178.248 -     * <dt><i>DecodableString:</i>
 178.249 -     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 178.250 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 178.251 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 178.252 -     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 178.253 -     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 178.254 -     * <p>
 178.255 -     * <dt><i>Sign:</i>
 178.256 -     * <dd>{@code -}
 178.257 -     * <dd>{@code +}
 178.258 -     * </dl>
 178.259 -     * </blockquote>
 178.260 -     *
 178.261 -     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 178.262 -     * are as defined in section 3.10.1 of
 178.263 -     * <cite>The Java&trade; Language Specification</cite>,
 178.264 -     * except that underscores are not accepted between digits.
 178.265 -     *
 178.266 -     * <p>The sequence of characters following an optional
 178.267 -     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 178.268 -     * "{@code #}", or leading zero) is parsed as by the {@code
 178.269 -     * Short.parseShort} method with the indicated radix (10, 16, or
 178.270 -     * 8).  This sequence of characters must represent a positive
 178.271 -     * value or a {@link NumberFormatException} will be thrown.  The
 178.272 -     * result is negated if first character of the specified {@code
 178.273 -     * String} is the minus sign.  No whitespace characters are
 178.274 -     * permitted in the {@code String}.
 178.275 -     *
 178.276 -     * @param     nm the {@code String} to decode.
 178.277 -     * @return    a {@code Short} object holding the {@code short}
 178.278 -     *            value represented by {@code nm}
 178.279 -     * @throws    NumberFormatException  if the {@code String} does not
 178.280 -     *            contain a parsable {@code short}.
 178.281 -     * @see java.lang.Short#parseShort(java.lang.String, int)
 178.282 -     */
 178.283 -    public static Short decode(String nm) throws NumberFormatException {
 178.284 -        int i = Integer.decode(nm);
 178.285 -        if (i < MIN_VALUE || i > MAX_VALUE)
 178.286 -            throw new NumberFormatException(
 178.287 -                    "Value " + i + " out of range from input " + nm);
 178.288 -        return valueOf((short)i);
 178.289 -    }
 178.290 -
 178.291 -    /**
 178.292 -     * The value of the {@code Short}.
 178.293 -     *
 178.294 -     * @serial
 178.295 -     */
 178.296 -    private final short value;
 178.297 -
 178.298 -    /**
 178.299 -     * Constructs a newly allocated {@code Short} object that
 178.300 -     * represents the specified {@code short} value.
 178.301 -     *
 178.302 -     * @param value     the value to be represented by the
 178.303 -     *                  {@code Short}.
 178.304 -     */
 178.305 -    public Short(short value) {
 178.306 -        this.value = value;
 178.307 -    }
 178.308 -
 178.309 -    /**
 178.310 -     * Constructs a newly allocated {@code Short} object that
 178.311 -     * represents the {@code short} value indicated by the
 178.312 -     * {@code String} parameter. The string is converted to a
 178.313 -     * {@code short} value in exactly the manner used by the
 178.314 -     * {@code parseShort} method for radix 10.
 178.315 -     *
 178.316 -     * @param s the {@code String} to be converted to a
 178.317 -     *          {@code Short}
 178.318 -     * @throws  NumberFormatException If the {@code String}
 178.319 -     *          does not contain a parsable {@code short}.
 178.320 -     * @see     java.lang.Short#parseShort(java.lang.String, int)
 178.321 -     */
 178.322 -    public Short(String s) throws NumberFormatException {
 178.323 -        this.value = parseShort(s, 10);
 178.324 -    }
 178.325 -
 178.326 -    /**
 178.327 -     * Returns the value of this {@code Short} as a
 178.328 -     * {@code byte}.
 178.329 -     */
 178.330 -    public byte byteValue() {
 178.331 -        return (byte)value;
 178.332 -    }
 178.333 -
 178.334 -    /**
 178.335 -     * Returns the value of this {@code Short} as a
 178.336 -     * {@code short}.
 178.337 -     */
 178.338 -    public short shortValue() {
 178.339 -        return value;
 178.340 -    }
 178.341 -
 178.342 -    /**
 178.343 -     * Returns the value of this {@code Short} as an
 178.344 -     * {@code int}.
 178.345 -     */
 178.346 -    public int intValue() {
 178.347 -        return (int)value;
 178.348 -    }
 178.349 -
 178.350 -    /**
 178.351 -     * Returns the value of this {@code Short} as a
 178.352 -     * {@code long}.
 178.353 -     */
 178.354 -    public long longValue() {
 178.355 -        return (long)value;
 178.356 -    }
 178.357 -
 178.358 -    /**
 178.359 -     * Returns the value of this {@code Short} as a
 178.360 -     * {@code float}.
 178.361 -     */
 178.362 -    public float floatValue() {
 178.363 -        return (float)value;
 178.364 -    }
 178.365 -
 178.366 -    /**
 178.367 -     * Returns the value of this {@code Short} as a
 178.368 -     * {@code double}.
 178.369 -     */
 178.370 -    public double doubleValue() {
 178.371 -        return (double)value;
 178.372 -    }
 178.373 -
 178.374 -    /**
 178.375 -     * Returns a {@code String} object representing this
 178.376 -     * {@code Short}'s value.  The value is converted to signed
 178.377 -     * decimal representation and returned as a string, exactly as if
 178.378 -     * the {@code short} value were given as an argument to the
 178.379 -     * {@link java.lang.Short#toString(short)} method.
 178.380 -     *
 178.381 -     * @return  a string representation of the value of this object in
 178.382 -     *          base&nbsp;10.
 178.383 -     */
 178.384 -    public String toString() {
 178.385 -        return Integer.toString((int)value);
 178.386 -    }
 178.387 -
 178.388 -    /**
 178.389 -     * Returns a hash code for this {@code Short}; equal to the result
 178.390 -     * of invoking {@code intValue()}.
 178.391 -     *
 178.392 -     * @return a hash code value for this {@code Short}
 178.393 -     */
 178.394 -    public int hashCode() {
 178.395 -        return (int)value;
 178.396 -    }
 178.397 -
 178.398 -    /**
 178.399 -     * Compares this object to the specified object.  The result is
 178.400 -     * {@code true} if and only if the argument is not
 178.401 -     * {@code null} and is a {@code Short} object that
 178.402 -     * contains the same {@code short} value as this object.
 178.403 -     *
 178.404 -     * @param obj       the object to compare with
 178.405 -     * @return          {@code true} if the objects are the same;
 178.406 -     *                  {@code false} otherwise.
 178.407 -     */
 178.408 -    public boolean equals(Object obj) {
 178.409 -        if (obj instanceof Short) {
 178.410 -            return value == ((Short)obj).shortValue();
 178.411 -        }
 178.412 -        return false;
 178.413 -    }
 178.414 -
 178.415 -    /**
 178.416 -     * Compares two {@code Short} objects numerically.
 178.417 -     *
 178.418 -     * @param   anotherShort   the {@code Short} to be compared.
 178.419 -     * @return  the value {@code 0} if this {@code Short} is
 178.420 -     *          equal to the argument {@code Short}; a value less than
 178.421 -     *          {@code 0} if this {@code Short} is numerically less
 178.422 -     *          than the argument {@code Short}; and a value greater than
 178.423 -     *           {@code 0} if this {@code Short} is numerically
 178.424 -     *           greater than the argument {@code Short} (signed
 178.425 -     *           comparison).
 178.426 -     * @since   1.2
 178.427 -     */
 178.428 -    public int compareTo(Short anotherShort) {
 178.429 -        return compare(this.value, anotherShort.value);
 178.430 -    }
 178.431 -
 178.432 -    /**
 178.433 -     * Compares two {@code short} values numerically.
 178.434 -     * The value returned is identical to what would be returned by:
 178.435 -     * <pre>
 178.436 -     *    Short.valueOf(x).compareTo(Short.valueOf(y))
 178.437 -     * </pre>
 178.438 -     *
 178.439 -     * @param  x the first {@code short} to compare
 178.440 -     * @param  y the second {@code short} to compare
 178.441 -     * @return the value {@code 0} if {@code x == y};
 178.442 -     *         a value less than {@code 0} if {@code x < y}; and
 178.443 -     *         a value greater than {@code 0} if {@code x > y}
 178.444 -     * @since 1.7
 178.445 -     */
 178.446 -    public static int compare(short x, short y) {
 178.447 -        return x - y;
 178.448 -    }
 178.449 -
 178.450 -    /**
 178.451 -     * The number of bits used to represent a {@code short} value in two's
 178.452 -     * complement binary form.
 178.453 -     * @since 1.5
 178.454 -     */
 178.455 -    public static final int SIZE = 16;
 178.456 -
 178.457 -    /**
 178.458 -     * Returns the value obtained by reversing the order of the bytes in the
 178.459 -     * two's complement representation of the specified {@code short} value.
 178.460 -     *
 178.461 -     * @return the value obtained by reversing (or, equivalently, swapping)
 178.462 -     *     the bytes in the specified {@code short} value.
 178.463 -     * @since 1.5
 178.464 -     */
 178.465 -    public static short reverseBytes(short i) {
 178.466 -        return (short) (((i & 0xFF00) >> 8) | (i << 8));
 178.467 -    }
 178.468 -
 178.469 -    /** use serialVersionUID from JDK 1.1. for interoperability */
 178.470 -    private static final long serialVersionUID = 7515723908773894738L;
 178.471 -}
   179.1 --- a/emul/mini/src/main/java/java/lang/StackTraceElement.java	Mon Feb 25 19:00:08 2013 +0100
   179.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   179.3 @@ -1,223 +0,0 @@
   179.4 -/*
   179.5 - * Copyright (c) 2000, 2011, 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.lang;
  179.30 -
  179.31 -/**
  179.32 - * An element in a stack trace, as returned by {@link
  179.33 - * Throwable#getStackTrace()}.  Each element represents a single stack frame.
  179.34 - * All stack frames except for the one at the top of the stack represent
  179.35 - * a method invocation.  The frame at the top of the stack represents the
  179.36 - * execution point at which the stack trace was generated.  Typically,
  179.37 - * this is the point at which the throwable corresponding to the stack trace
  179.38 - * was created.
  179.39 - *
  179.40 - * @since  1.4
  179.41 - * @author Josh Bloch
  179.42 - */
  179.43 -public final class StackTraceElement implements java.io.Serializable {
  179.44 -    // Normally initialized by VM (public constructor added in 1.5)
  179.45 -    private String declaringClass;
  179.46 -    private String methodName;
  179.47 -    private String fileName;
  179.48 -    private int    lineNumber;
  179.49 -
  179.50 -    /**
  179.51 -     * Creates a stack trace element representing the specified execution
  179.52 -     * point.
  179.53 -     *
  179.54 -     * @param declaringClass the fully qualified name of the class containing
  179.55 -     *        the execution point represented by the stack trace element
  179.56 -     * @param methodName the name of the method containing the execution point
  179.57 -     *        represented by the stack trace element
  179.58 -     * @param fileName the name of the file containing the execution point
  179.59 -     *         represented by the stack trace element, or {@code null} if
  179.60 -     *         this information is unavailable
  179.61 -     * @param lineNumber the line number of the source line containing the
  179.62 -     *         execution point represented by this stack trace element, or
  179.63 -     *         a negative number if this information is unavailable. A value
  179.64 -     *         of -2 indicates that the method containing the execution point
  179.65 -     *         is a native method
  179.66 -     * @throws NullPointerException if {@code declaringClass} or
  179.67 -     *         {@code methodName} is null
  179.68 -     * @since 1.5
  179.69 -     */
  179.70 -    public StackTraceElement(String declaringClass, String methodName,
  179.71 -                             String fileName, int lineNumber) {
  179.72 -        this.declaringClass = declaringClass;
  179.73 -        this.methodName     = methodName;
  179.74 -        this.fileName       = fileName;
  179.75 -        this.lineNumber     = lineNumber;
  179.76 -    }
  179.77 -
  179.78 -    /**
  179.79 -     * Returns the name of the source file containing the execution point
  179.80 -     * represented by this stack trace element.  Generally, this corresponds
  179.81 -     * to the {@code SourceFile} attribute of the relevant {@code class}
  179.82 -     * file (as per <i>The Java Virtual Machine Specification</i>, Section
  179.83 -     * 4.7.7).  In some systems, the name may refer to some source code unit
  179.84 -     * other than a file, such as an entry in source repository.
  179.85 -     *
  179.86 -     * @return the name of the file containing the execution point
  179.87 -     *         represented by this stack trace element, or {@code null} if
  179.88 -     *         this information is unavailable.
  179.89 -     */
  179.90 -    public String getFileName() {
  179.91 -        return fileName;
  179.92 -    }
  179.93 -
  179.94 -    /**
  179.95 -     * Returns the line number of the source line containing the execution
  179.96 -     * point represented by this stack trace element.  Generally, this is
  179.97 -     * derived from the {@code LineNumberTable} attribute of the relevant
  179.98 -     * {@code class} file (as per <i>The Java Virtual Machine
  179.99 -     * Specification</i>, Section 4.7.8).
 179.100 -     *
 179.101 -     * @return the line number of the source line containing the execution
 179.102 -     *         point represented by this stack trace element, or a negative
 179.103 -     *         number if this information is unavailable.
 179.104 -     */
 179.105 -    public int getLineNumber() {
 179.106 -        return lineNumber;
 179.107 -    }
 179.108 -
 179.109 -    /**
 179.110 -     * Returns the fully qualified name of the class containing the
 179.111 -     * execution point represented by this stack trace element.
 179.112 -     *
 179.113 -     * @return the fully qualified name of the {@code Class} containing
 179.114 -     *         the execution point represented by this stack trace element.
 179.115 -     */
 179.116 -    public String getClassName() {
 179.117 -        return declaringClass;
 179.118 -    }
 179.119 -
 179.120 -    /**
 179.121 -     * Returns the name of the method containing the execution point
 179.122 -     * represented by this stack trace element.  If the execution point is
 179.123 -     * contained in an instance or class initializer, this method will return
 179.124 -     * the appropriate <i>special method name</i>, {@code <init>} or
 179.125 -     * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
 179.126 -     * Machine Specification</i>.
 179.127 -     *
 179.128 -     * @return the name of the method containing the execution point
 179.129 -     *         represented by this stack trace element.
 179.130 -     */
 179.131 -    public String getMethodName() {
 179.132 -        return methodName;
 179.133 -    }
 179.134 -
 179.135 -    /**
 179.136 -     * Returns true if the method containing the execution point
 179.137 -     * represented by this stack trace element is a native method.
 179.138 -     *
 179.139 -     * @return {@code true} if the method containing the execution point
 179.140 -     *         represented by this stack trace element is a native method.
 179.141 -     */
 179.142 -    public boolean isNativeMethod() {
 179.143 -        return lineNumber == -2;
 179.144 -    }
 179.145 -
 179.146 -    /**
 179.147 -     * Returns a string representation of this stack trace element.  The
 179.148 -     * format of this string depends on the implementation, but the following
 179.149 -     * examples may be regarded as typical:
 179.150 -     * <ul>
 179.151 -     * <li>
 179.152 -     *   {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
 179.153 -     *   is the <i>fully-qualified name</i> of the class containing the
 179.154 -     *   execution point represented by this stack trace element,
 179.155 -     *   {@code "mash"} is the name of the method containing the execution
 179.156 -     *   point, {@code "MyClass.java"} is the source file containing the
 179.157 -     *   execution point, and {@code "9"} is the line number of the source
 179.158 -     *   line containing the execution point.
 179.159 -     * <li>
 179.160 -     *   {@code "MyClass.mash(MyClass.java)"} - As above, but the line
 179.161 -     *   number is unavailable.
 179.162 -     * <li>
 179.163 -     *   {@code "MyClass.mash(Unknown Source)"} - As above, but neither
 179.164 -     *   the file name nor the line  number are available.
 179.165 -     * <li>
 179.166 -     *   {@code "MyClass.mash(Native Method)"} - As above, but neither
 179.167 -     *   the file name nor the line  number are available, and the method
 179.168 -     *   containing the execution point is known to be a native method.
 179.169 -     * </ul>
 179.170 -     * @see    Throwable#printStackTrace()
 179.171 -     */
 179.172 -    public String toString() {
 179.173 -        return getClassName() + "." + methodName +
 179.174 -            (isNativeMethod() ? "(Native Method)" :
 179.175 -             (fileName != null && lineNumber >= 0 ?
 179.176 -              "(" + fileName + ":" + lineNumber + ")" :
 179.177 -              (fileName != null ?  "("+fileName+")" : "(Unknown Source)")));
 179.178 -    }
 179.179 -
 179.180 -    /**
 179.181 -     * Returns true if the specified object is another
 179.182 -     * {@code StackTraceElement} instance representing the same execution
 179.183 -     * point as this instance.  Two stack trace elements {@code a} and
 179.184 -     * {@code b} are equal if and only if:
 179.185 -     * <pre>
 179.186 -     *     equals(a.getFileName(), b.getFileName()) &&
 179.187 -     *     a.getLineNumber() == b.getLineNumber()) &&
 179.188 -     *     equals(a.getClassName(), b.getClassName()) &&
 179.189 -     *     equals(a.getMethodName(), b.getMethodName())
 179.190 -     * </pre>
 179.191 -     * where {@code equals} has the semantics of {@link
 179.192 -     * java.util.Objects#equals(Object, Object) Objects.equals}.
 179.193 -     *
 179.194 -     * @param  obj the object to be compared with this stack trace element.
 179.195 -     * @return true if the specified object is another
 179.196 -     *         {@code StackTraceElement} instance representing the same
 179.197 -     *         execution point as this instance.
 179.198 -     */
 179.199 -    public boolean equals(Object obj) {
 179.200 -        if (obj==this)
 179.201 -            return true;
 179.202 -        if (!(obj instanceof StackTraceElement))
 179.203 -            return false;
 179.204 -        StackTraceElement e = (StackTraceElement)obj;
 179.205 -        return e.declaringClass.equals(declaringClass) &&
 179.206 -            e.lineNumber == lineNumber &&
 179.207 -            equals(methodName, e.methodName) &&
 179.208 -            equals(fileName, e.fileName);
 179.209 -    }
 179.210 -
 179.211 -    /**
 179.212 -     * Returns a hash code value for this stack trace element.
 179.213 -     */
 179.214 -    public int hashCode() {
 179.215 -        int result = 31*declaringClass.hashCode() + methodName.hashCode();
 179.216 -        result = 31*result + (fileName == null ? 0 : fileName.hashCode());
 179.217 -        result = 31*result + lineNumber;
 179.218 -        return result;
 179.219 -    }
 179.220 -    
 179.221 -    private static boolean equals(Object a, Object b) {
 179.222 -        return (a == b) || (a != null && a.equals(b));
 179.223 -    }
 179.224 -
 179.225 -    private static final long serialVersionUID = 6992337162326171013L;
 179.226 -}
   180.1 --- a/emul/mini/src/main/java/java/lang/String.java	Mon Feb 25 19:00:08 2013 +0100
   180.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   180.3 @@ -1,3079 +0,0 @@
   180.4 -/*
   180.5 - * Copyright (c) 1994, 2010, 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.lang;
  180.30 -
  180.31 -import java.io.UnsupportedEncodingException;
  180.32 -import java.util.Comparator;
  180.33 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  180.34 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  180.35 -import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  180.36 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  180.37 -import org.apidesign.bck2brwsr.emul.lang.System;
  180.38 -
  180.39 -/**
  180.40 - * The <code>String</code> class represents character strings. All
  180.41 - * string literals in Java programs, such as <code>"abc"</code>, are
  180.42 - * implemented as instances of this class.
  180.43 - * <p>
  180.44 - * Strings are constant; their values cannot be changed after they
  180.45 - * are created. String buffers support mutable strings.
  180.46 - * Because String objects are immutable they can be shared. For example:
  180.47 - * <p><blockquote><pre>
  180.48 - *     String str = "abc";
  180.49 - * </pre></blockquote><p>
  180.50 - * is equivalent to:
  180.51 - * <p><blockquote><pre>
  180.52 - *     char data[] = {'a', 'b', 'c'};
  180.53 - *     String str = new String(data);
  180.54 - * </pre></blockquote><p>
  180.55 - * Here are some more examples of how strings can be used:
  180.56 - * <p><blockquote><pre>
  180.57 - *     System.out.println("abc");
  180.58 - *     String cde = "cde";
  180.59 - *     System.out.println("abc" + cde);
  180.60 - *     String c = "abc".substring(2,3);
  180.61 - *     String d = cde.substring(1, 2);
  180.62 - * </pre></blockquote>
  180.63 - * <p>
  180.64 - * The class <code>String</code> includes methods for examining
  180.65 - * individual characters of the sequence, for comparing strings, for
  180.66 - * searching strings, for extracting substrings, and for creating a
  180.67 - * copy of a string with all characters translated to uppercase or to
  180.68 - * lowercase. Case mapping is based on the Unicode Standard version
  180.69 - * specified by the {@link java.lang.Character Character} class.
  180.70 - * <p>
  180.71 - * The Java language provides special support for the string
  180.72 - * concatenation operator (&nbsp;+&nbsp;), and for conversion of
  180.73 - * other objects to strings. String concatenation is implemented
  180.74 - * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
  180.75 - * class and its <code>append</code> method.
  180.76 - * String conversions are implemented through the method
  180.77 - * <code>toString</code>, defined by <code>Object</code> and
  180.78 - * inherited by all classes in Java. For additional information on
  180.79 - * string concatenation and conversion, see Gosling, Joy, and Steele,
  180.80 - * <i>The Java Language Specification</i>.
  180.81 - *
  180.82 - * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  180.83 - * or method in this class will cause a {@link NullPointerException} to be
  180.84 - * thrown.
  180.85 - *
  180.86 - * <p>A <code>String</code> represents a string in the UTF-16 format
  180.87 - * in which <em>supplementary characters</em> are represented by <em>surrogate
  180.88 - * pairs</em> (see the section <a href="Character.html#unicode">Unicode
  180.89 - * Character Representations</a> in the <code>Character</code> class for
  180.90 - * more information).
  180.91 - * Index values refer to <code>char</code> code units, so a supplementary
  180.92 - * character uses two positions in a <code>String</code>.
  180.93 - * <p>The <code>String</code> class provides methods for dealing with
  180.94 - * Unicode code points (i.e., characters), in addition to those for
  180.95 - * dealing with Unicode code units (i.e., <code>char</code> values).
  180.96 - *
  180.97 - * @author  Lee Boynton
  180.98 - * @author  Arthur van Hoff
  180.99 - * @author  Martin Buchholz
 180.100 - * @author  Ulf Zibis
 180.101 - * @see     java.lang.Object#toString()
 180.102 - * @see     java.lang.StringBuffer
 180.103 - * @see     java.lang.StringBuilder
 180.104 - * @see     java.nio.charset.Charset
 180.105 - * @since   JDK1.0
 180.106 - */
 180.107 -
 180.108 -@ExtraJavaScript(
 180.109 -    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js",
 180.110 -    processByteCode=true
 180.111 -)
 180.112 -@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
 180.113 -public final class String
 180.114 -    implements java.io.Serializable, Comparable<String>, CharSequence
 180.115 -{
 180.116 -    /** real string to delegate to */
 180.117 -    private Object r;
 180.118 -
 180.119 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 180.120 -    private static final long serialVersionUID = -6849794470754667710L;
 180.121 -    
 180.122 -    @JavaScriptOnly(name="toString", value="String.prototype._r")
 180.123 -    private static void jsToString() {
 180.124 -    }
 180.125 -    
 180.126 -    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 180.127 -    private static void jsValudOf() {
 180.128 -    }
 180.129 -
 180.130 -    /**
 180.131 -     * Class String is special cased within the Serialization Stream Protocol.
 180.132 -     *
 180.133 -     * A String instance is written initially into an ObjectOutputStream in the
 180.134 -     * following format:
 180.135 -     * <pre>
 180.136 -     *      <code>TC_STRING</code> (utf String)
 180.137 -     * </pre>
 180.138 -     * The String is written by method <code>DataOutput.writeUTF</code>.
 180.139 -     * A new handle is generated to  refer to all future references to the
 180.140 -     * string instance within the stream.
 180.141 -     */
 180.142 -//    private static final ObjectStreamField[] serialPersistentFields =
 180.143 -//        new ObjectStreamField[0];
 180.144 -
 180.145 -    /**
 180.146 -     * Initializes a newly created {@code String} object so that it represents
 180.147 -     * an empty character sequence.  Note that use of this constructor is
 180.148 -     * unnecessary since Strings are immutable.
 180.149 -     */
 180.150 -    public String() {
 180.151 -        this.r = "";
 180.152 -    }
 180.153 -
 180.154 -    /**
 180.155 -     * Initializes a newly created {@code String} object so that it represents
 180.156 -     * the same sequence of characters as the argument; in other words, the
 180.157 -     * newly created string is a copy of the argument string. Unless an
 180.158 -     * explicit copy of {@code original} is needed, use of this constructor is
 180.159 -     * unnecessary since Strings are immutable.
 180.160 -     *
 180.161 -     * @param  original
 180.162 -     *         A {@code String}
 180.163 -     */
 180.164 -    public String(String original) {
 180.165 -        this.r = original.toString();
 180.166 -    }
 180.167 -
 180.168 -    /**
 180.169 -     * Allocates a new {@code String} so that it represents the sequence of
 180.170 -     * characters currently contained in the character array argument. The
 180.171 -     * contents of the character array are copied; subsequent modification of
 180.172 -     * the character array does not affect the newly created string.
 180.173 -     *
 180.174 -     * @param  value
 180.175 -     *         The initial value of the string
 180.176 -     */
 180.177 -    @JavaScriptBody(args = { "charArr" }, body=
 180.178 -        "for (var i = 0; i < charArr.length; i++) {\n"
 180.179 -      + "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
 180.180 -      + "}\n"
 180.181 -      + "this._r(charArr.join(''));\n"
 180.182 -    )
 180.183 -    public String(char value[]) {
 180.184 -    }
 180.185 -
 180.186 -    /**
 180.187 -     * Allocates a new {@code String} that contains characters from a subarray
 180.188 -     * of the character array argument. The {@code offset} argument is the
 180.189 -     * index of the first character of the subarray and the {@code count}
 180.190 -     * argument specifies the length of the subarray. The contents of the
 180.191 -     * subarray are copied; subsequent modification of the character array does
 180.192 -     * not affect the newly created string.
 180.193 -     *
 180.194 -     * @param  value
 180.195 -     *         Array that is the source of characters
 180.196 -     *
 180.197 -     * @param  offset
 180.198 -     *         The initial offset
 180.199 -     *
 180.200 -     * @param  count
 180.201 -     *         The length
 180.202 -     *
 180.203 -     * @throws  IndexOutOfBoundsException
 180.204 -     *          If the {@code offset} and {@code count} arguments index
 180.205 -     *          characters outside the bounds of the {@code value} array
 180.206 -     */
 180.207 -    public String(char value[], int offset, int count) {
 180.208 -        initFromCharArray(value, offset, count);
 180.209 -    }
 180.210 -    
 180.211 -    @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
 180.212 -        "var up = off + cnt;\n" +
 180.213 -        "for (var i = off; i < up; i++) {\n" +
 180.214 -        "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
 180.215 -        "}\n" +
 180.216 -        "this._r(charArr.slice(off, up).join(\"\"));\n"
 180.217 -    )
 180.218 -    private native void initFromCharArray(char value[], int offset, int count);
 180.219 -
 180.220 -    /**
 180.221 -     * Allocates a new {@code String} that contains characters from a subarray
 180.222 -     * of the <a href="Character.html#unicode">Unicode code point</a> array
 180.223 -     * argument.  The {@code offset} argument is the index of the first code
 180.224 -     * point of the subarray and the {@code count} argument specifies the
 180.225 -     * length of the subarray.  The contents of the subarray are converted to
 180.226 -     * {@code char}s; subsequent modification of the {@code int} array does not
 180.227 -     * affect the newly created string.
 180.228 -     *
 180.229 -     * @param  codePoints
 180.230 -     *         Array that is the source of Unicode code points
 180.231 -     *
 180.232 -     * @param  offset
 180.233 -     *         The initial offset
 180.234 -     *
 180.235 -     * @param  count
 180.236 -     *         The length
 180.237 -     *
 180.238 -     * @throws  IllegalArgumentException
 180.239 -     *          If any invalid Unicode code point is found in {@code
 180.240 -     *          codePoints}
 180.241 -     *
 180.242 -     * @throws  IndexOutOfBoundsException
 180.243 -     *          If the {@code offset} and {@code count} arguments index
 180.244 -     *          characters outside the bounds of the {@code codePoints} array
 180.245 -     *
 180.246 -     * @since  1.5
 180.247 -     */
 180.248 -    public String(int[] codePoints, int offset, int count) {
 180.249 -        if (offset < 0) {
 180.250 -            throw new StringIndexOutOfBoundsException(offset);
 180.251 -        }
 180.252 -        if (count < 0) {
 180.253 -            throw new StringIndexOutOfBoundsException(count);
 180.254 -        }
 180.255 -        // Note: offset or count might be near -1>>>1.
 180.256 -        if (offset > codePoints.length - count) {
 180.257 -            throw new StringIndexOutOfBoundsException(offset + count);
 180.258 -        }
 180.259 -
 180.260 -        final int end = offset + count;
 180.261 -
 180.262 -        // Pass 1: Compute precise size of char[]
 180.263 -        int n = count;
 180.264 -        for (int i = offset; i < end; i++) {
 180.265 -            int c = codePoints[i];
 180.266 -            if (Character.isBmpCodePoint(c))
 180.267 -                continue;
 180.268 -            else if (Character.isValidCodePoint(c))
 180.269 -                n++;
 180.270 -            else throw new IllegalArgumentException(Integer.toString(c));
 180.271 -        }
 180.272 -
 180.273 -        // Pass 2: Allocate and fill in char[]
 180.274 -        final char[] v = new char[n];
 180.275 -
 180.276 -        for (int i = offset, j = 0; i < end; i++, j++) {
 180.277 -            int c = codePoints[i];
 180.278 -            if (Character.isBmpCodePoint(c))
 180.279 -                v[j] = (char) c;
 180.280 -            else
 180.281 -                Character.toSurrogates(c, v, j++);
 180.282 -        }
 180.283 -
 180.284 -        this.r = new String(v, 0, n);
 180.285 -    }
 180.286 -
 180.287 -    /**
 180.288 -     * Allocates a new {@code String} constructed from a subarray of an array
 180.289 -     * of 8-bit integer values.
 180.290 -     *
 180.291 -     * <p> The {@code offset} argument is the index of the first byte of the
 180.292 -     * subarray, and the {@code count} argument specifies the length of the
 180.293 -     * subarray.
 180.294 -     *
 180.295 -     * <p> Each {@code byte} in the subarray is converted to a {@code char} as
 180.296 -     * specified in the method above.
 180.297 -     *
 180.298 -     * @deprecated This method does not properly convert bytes into characters.
 180.299 -     * As of JDK&nbsp;1.1, the preferred way to do this is via the
 180.300 -     * {@code String} constructors that take a {@link
 180.301 -     * java.nio.charset.Charset}, charset name, or that use the platform's
 180.302 -     * default charset.
 180.303 -     *
 180.304 -     * @param  ascii
 180.305 -     *         The bytes to be converted to characters
 180.306 -     *
 180.307 -     * @param  hibyte
 180.308 -     *         The top 8 bits of each 16-bit Unicode code unit
 180.309 -     *
 180.310 -     * @param  offset
 180.311 -     *         The initial offset
 180.312 -     * @param  count
 180.313 -     *         The length
 180.314 -     *
 180.315 -     * @throws  IndexOutOfBoundsException
 180.316 -     *          If the {@code offset} or {@code count} argument is invalid
 180.317 -     *
 180.318 -     * @see  #String(byte[], int)
 180.319 -     * @see  #String(byte[], int, int, java.lang.String)
 180.320 -     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 180.321 -     * @see  #String(byte[], int, int)
 180.322 -     * @see  #String(byte[], java.lang.String)
 180.323 -     * @see  #String(byte[], java.nio.charset.Charset)
 180.324 -     * @see  #String(byte[])
 180.325 -     */
 180.326 -    @Deprecated
 180.327 -    public String(byte ascii[], int hibyte, int offset, int count) {
 180.328 -        checkBounds(ascii, offset, count);
 180.329 -        char value[] = new char[count];
 180.330 -
 180.331 -        if (hibyte == 0) {
 180.332 -            for (int i = count ; i-- > 0 ;) {
 180.333 -                value[i] = (char) (ascii[i + offset] & 0xff);
 180.334 -            }
 180.335 -        } else {
 180.336 -            hibyte <<= 8;
 180.337 -            for (int i = count ; i-- > 0 ;) {
 180.338 -                value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
 180.339 -            }
 180.340 -        }
 180.341 -        initFromCharArray(value, offset, count);
 180.342 -    }
 180.343 -
 180.344 -    /**
 180.345 -     * Allocates a new {@code String} containing characters constructed from
 180.346 -     * an array of 8-bit integer values. Each character <i>c</i>in the
 180.347 -     * resulting string is constructed from the corresponding component
 180.348 -     * <i>b</i> in the byte array such that:
 180.349 -     *
 180.350 -     * <blockquote><pre>
 180.351 -     *     <b><i>c</i></b> == (char)(((hibyte &amp; 0xff) &lt;&lt; 8)
 180.352 -     *                         | (<b><i>b</i></b> &amp; 0xff))
 180.353 -     * </pre></blockquote>
 180.354 -     *
 180.355 -     * @deprecated  This method does not properly convert bytes into
 180.356 -     * characters.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 180.357 -     * {@code String} constructors that take a {@link
 180.358 -     * java.nio.charset.Charset}, charset name, or that use the platform's
 180.359 -     * default charset.
 180.360 -     *
 180.361 -     * @param  ascii
 180.362 -     *         The bytes to be converted to characters
 180.363 -     *
 180.364 -     * @param  hibyte
 180.365 -     *         The top 8 bits of each 16-bit Unicode code unit
 180.366 -     *
 180.367 -     * @see  #String(byte[], int, int, java.lang.String)
 180.368 -     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 180.369 -     * @see  #String(byte[], int, int)
 180.370 -     * @see  #String(byte[], java.lang.String)
 180.371 -     * @see  #String(byte[], java.nio.charset.Charset)
 180.372 -     * @see  #String(byte[])
 180.373 -     */
 180.374 -    @Deprecated
 180.375 -    public String(byte ascii[], int hibyte) {
 180.376 -        this(ascii, hibyte, 0, ascii.length);
 180.377 -    }
 180.378 -
 180.379 -    /* Common private utility method used to bounds check the byte array
 180.380 -     * and requested offset & length values used by the String(byte[],..)
 180.381 -     * constructors.
 180.382 -     */
 180.383 -    private static void checkBounds(byte[] bytes, int offset, int length) {
 180.384 -        if (length < 0)
 180.385 -            throw new StringIndexOutOfBoundsException(length);
 180.386 -        if (offset < 0)
 180.387 -            throw new StringIndexOutOfBoundsException(offset);
 180.388 -        if (offset > bytes.length - length)
 180.389 -            throw new StringIndexOutOfBoundsException(offset + length);
 180.390 -    }
 180.391 -
 180.392 -    /**
 180.393 -     * Constructs a new {@code String} by decoding the specified subarray of
 180.394 -     * bytes using the specified charset.  The length of the new {@code String}
 180.395 -     * is a function of the charset, and hence may not be equal to the length
 180.396 -     * of the subarray.
 180.397 -     *
 180.398 -     * <p> The behavior of this constructor when the given bytes are not valid
 180.399 -     * in the given charset is unspecified.  The {@link
 180.400 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 180.401 -     * over the decoding process is required.
 180.402 -     *
 180.403 -     * @param  bytes
 180.404 -     *         The bytes to be decoded into characters
 180.405 -     *
 180.406 -     * @param  offset
 180.407 -     *         The index of the first byte to decode
 180.408 -     *
 180.409 -     * @param  length
 180.410 -     *         The number of bytes to decode
 180.411 -
 180.412 -     * @param  charsetName
 180.413 -     *         The name of a supported {@linkplain java.nio.charset.Charset
 180.414 -     *         charset}
 180.415 -     *
 180.416 -     * @throws  UnsupportedEncodingException
 180.417 -     *          If the named charset is not supported
 180.418 -     *
 180.419 -     * @throws  IndexOutOfBoundsException
 180.420 -     *          If the {@code offset} and {@code length} arguments index
 180.421 -     *          characters outside the bounds of the {@code bytes} array
 180.422 -     *
 180.423 -     * @since  JDK1.1
 180.424 -     */
 180.425 -    public String(byte bytes[], int offset, int length, String charsetName)
 180.426 -        throws UnsupportedEncodingException
 180.427 -    {
 180.428 -        this(checkUTF8(bytes, charsetName), offset, length);
 180.429 -    }
 180.430 -
 180.431 -    /**
 180.432 -     * Constructs a new {@code String} by decoding the specified subarray of
 180.433 -     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 180.434 -     * The length of the new {@code String} is a function of the charset, and
 180.435 -     * hence may not be equal to the length of the subarray.
 180.436 -     *
 180.437 -     * <p> This method always replaces malformed-input and unmappable-character
 180.438 -     * sequences with this charset's default replacement string.  The {@link
 180.439 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 180.440 -     * over the decoding process is required.
 180.441 -     *
 180.442 -     * @param  bytes
 180.443 -     *         The bytes to be decoded into characters
 180.444 -     *
 180.445 -     * @param  offset
 180.446 -     *         The index of the first byte to decode
 180.447 -     *
 180.448 -     * @param  length
 180.449 -     *         The number of bytes to decode
 180.450 -     *
 180.451 -     * @param  charset
 180.452 -     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 180.453 -     *         decode the {@code bytes}
 180.454 -     *
 180.455 -     * @throws  IndexOutOfBoundsException
 180.456 -     *          If the {@code offset} and {@code length} arguments index
 180.457 -     *          characters outside the bounds of the {@code bytes} array
 180.458 -     *
 180.459 -     * @since  1.6
 180.460 -     */
 180.461 -    /* don't want dependnecy on Charset
 180.462 -    public String(byte bytes[], int offset, int length, Charset charset) {
 180.463 -        if (charset == null)
 180.464 -            throw new NullPointerException("charset");
 180.465 -        checkBounds(bytes, offset, length);
 180.466 -        char[] v = StringCoding.decode(charset, bytes, offset, length);
 180.467 -        this.offset = 0;
 180.468 -        this.count = v.length;
 180.469 -        this.value = v;
 180.470 -    }
 180.471 -    */
 180.472 -
 180.473 -    /**
 180.474 -     * Constructs a new {@code String} by decoding the specified array of bytes
 180.475 -     * using the specified {@linkplain java.nio.charset.Charset charset}.  The
 180.476 -     * length of the new {@code String} is a function of the charset, and hence
 180.477 -     * may not be equal to the length of the byte array.
 180.478 -     *
 180.479 -     * <p> The behavior of this constructor when the given bytes are not valid
 180.480 -     * in the given charset is unspecified.  The {@link
 180.481 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 180.482 -     * over the decoding process is required.
 180.483 -     *
 180.484 -     * @param  bytes
 180.485 -     *         The bytes to be decoded into characters
 180.486 -     *
 180.487 -     * @param  charsetName
 180.488 -     *         The name of a supported {@linkplain java.nio.charset.Charset
 180.489 -     *         charset}
 180.490 -     *
 180.491 -     * @throws  UnsupportedEncodingException
 180.492 -     *          If the named charset is not supported
 180.493 -     *
 180.494 -     * @since  JDK1.1
 180.495 -     */
 180.496 -    public String(byte bytes[], String charsetName)
 180.497 -        throws UnsupportedEncodingException
 180.498 -    {
 180.499 -        this(bytes, 0, bytes.length, charsetName);
 180.500 -    }
 180.501 -
 180.502 -    /**
 180.503 -     * Constructs a new {@code String} by decoding the specified array of
 180.504 -     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 180.505 -     * The length of the new {@code String} is a function of the charset, and
 180.506 -     * hence may not be equal to the length of the byte array.
 180.507 -     *
 180.508 -     * <p> This method always replaces malformed-input and unmappable-character
 180.509 -     * sequences with this charset's default replacement string.  The {@link
 180.510 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 180.511 -     * over the decoding process is required.
 180.512 -     *
 180.513 -     * @param  bytes
 180.514 -     *         The bytes to be decoded into characters
 180.515 -     *
 180.516 -     * @param  charset
 180.517 -     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 180.518 -     *         decode the {@code bytes}
 180.519 -     *
 180.520 -     * @since  1.6
 180.521 -     */
 180.522 -    /* don't want dep on Charset
 180.523 -    public String(byte bytes[], Charset charset) {
 180.524 -        this(bytes, 0, bytes.length, charset);
 180.525 -    }
 180.526 -    */
 180.527 -
 180.528 -    /**
 180.529 -     * Constructs a new {@code String} by decoding the specified subarray of
 180.530 -     * bytes using the platform's default charset.  The length of the new
 180.531 -     * {@code String} is a function of the charset, and hence may not be equal
 180.532 -     * to the length of the subarray.
 180.533 -     *
 180.534 -     * <p> The behavior of this constructor when the given bytes are not valid
 180.535 -     * in the default charset is unspecified.  The {@link
 180.536 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 180.537 -     * over the decoding process is required.
 180.538 -     *
 180.539 -     * @param  bytes
 180.540 -     *         The bytes to be decoded into characters
 180.541 -     *
 180.542 -     * @param  offset
 180.543 -     *         The index of the first byte to decode
 180.544 -     *
 180.545 -     * @param  length
 180.546 -     *         The number of bytes to decode
 180.547 -     *
 180.548 -     * @throws  IndexOutOfBoundsException
 180.549 -     *          If the {@code offset} and the {@code length} arguments index
 180.550 -     *          characters outside the bounds of the {@code bytes} array
 180.551 -     *
 180.552 -     * @since  JDK1.1
 180.553 -     */
 180.554 -    public String(byte bytes[], int offset, int length) {
 180.555 -        checkBounds(bytes, offset, length);
 180.556 -        char[] v  = new char[length];
 180.557 -        int[] at = { offset };
 180.558 -        int end = offset + length;
 180.559 -        int chlen = 0;
 180.560 -        while (at[0] < end) {
 180.561 -            int ch = nextChar(bytes, at);
 180.562 -            v[chlen++] = (char)ch;
 180.563 -        }
 180.564 -        initFromCharArray(v, 0, chlen);
 180.565 -    }
 180.566 -
 180.567 -    /**
 180.568 -     * Constructs a new {@code String} by decoding the specified array of bytes
 180.569 -     * using the platform's default charset.  The length of the new {@code
 180.570 -     * String} is a function of the charset, and hence may not be equal to the
 180.571 -     * length of the byte array.
 180.572 -     *
 180.573 -     * <p> The behavior of this constructor when the given bytes are not valid
 180.574 -     * in the default charset is unspecified.  The {@link
 180.575 -     * java.nio.charset.CharsetDecoder} class should be used when more control
 180.576 -     * over the decoding process is required.
 180.577 -     *
 180.578 -     * @param  bytes
 180.579 -     *         The bytes to be decoded into characters
 180.580 -     *
 180.581 -     * @since  JDK1.1
 180.582 -     */
 180.583 -    public String(byte bytes[]) {
 180.584 -        this(bytes, 0, bytes.length);
 180.585 -    }
 180.586 -
 180.587 -    /**
 180.588 -     * Allocates a new string that contains the sequence of characters
 180.589 -     * currently contained in the string buffer argument. The contents of the
 180.590 -     * string buffer are copied; subsequent modification of the string buffer
 180.591 -     * does not affect the newly created string.
 180.592 -     *
 180.593 -     * @param  buffer
 180.594 -     *         A {@code StringBuffer}
 180.595 -     */
 180.596 -    public String(StringBuffer buffer) {
 180.597 -        this.r = buffer.toString();
 180.598 -    }
 180.599 -
 180.600 -    /**
 180.601 -     * Allocates a new string that contains the sequence of characters
 180.602 -     * currently contained in the string builder argument. The contents of the
 180.603 -     * string builder are copied; subsequent modification of the string builder
 180.604 -     * does not affect the newly created string.
 180.605 -     *
 180.606 -     * <p> This constructor is provided to ease migration to {@code
 180.607 -     * StringBuilder}. Obtaining a string from a string builder via the {@code
 180.608 -     * toString} method is likely to run faster and is generally preferred.
 180.609 -     *
 180.610 -     * @param   builder
 180.611 -     *          A {@code StringBuilder}
 180.612 -     *
 180.613 -     * @since  1.5
 180.614 -     */
 180.615 -    public String(StringBuilder builder) {
 180.616 -        this.r = builder.toString();
 180.617 -    }
 180.618 -
 180.619 -    /**
 180.620 -     * Returns the length of this string.
 180.621 -     * The length is equal to the number of <a href="Character.html#unicode">Unicode
 180.622 -     * code units</a> in the string.
 180.623 -     *
 180.624 -     * @return  the length of the sequence of characters represented by this
 180.625 -     *          object.
 180.626 -     */
 180.627 -    @JavaScriptBody(args = {}, body = "return this.toString().length;")
 180.628 -    public int length() {
 180.629 -        throw new UnsupportedOperationException();
 180.630 -    }
 180.631 -
 180.632 -    /**
 180.633 -     * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
 180.634 -     *
 180.635 -     * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
 180.636 -     * <tt>false</tt>
 180.637 -     *
 180.638 -     * @since 1.6
 180.639 -     */
 180.640 -    @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
 180.641 -    public boolean isEmpty() {
 180.642 -        return length() == 0;
 180.643 -    }
 180.644 -
 180.645 -    /**
 180.646 -     * Returns the <code>char</code> value at the
 180.647 -     * specified index. An index ranges from <code>0</code> to
 180.648 -     * <code>length() - 1</code>. The first <code>char</code> value of the sequence
 180.649 -     * is at index <code>0</code>, the next at index <code>1</code>,
 180.650 -     * and so on, as for array indexing.
 180.651 -     *
 180.652 -     * <p>If the <code>char</code> value specified by the index is a
 180.653 -     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 180.654 -     * value is returned.
 180.655 -     *
 180.656 -     * @param      index   the index of the <code>char</code> value.
 180.657 -     * @return     the <code>char</code> value at the specified index of this string.
 180.658 -     *             The first <code>char</code> value is at index <code>0</code>.
 180.659 -     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 180.660 -     *             argument is negative or not less than the length of this
 180.661 -     *             string.
 180.662 -     */
 180.663 -    @JavaScriptBody(args = { "index" }, 
 180.664 -        body = "return this.toString().charCodeAt(index);"
 180.665 -    )
 180.666 -    public char charAt(int index) {
 180.667 -        throw new UnsupportedOperationException();
 180.668 -    }
 180.669 -
 180.670 -    /**
 180.671 -     * Returns the character (Unicode code point) at the specified
 180.672 -     * index. The index refers to <code>char</code> values
 180.673 -     * (Unicode code units) and ranges from <code>0</code> to
 180.674 -     * {@link #length()}<code> - 1</code>.
 180.675 -     *
 180.676 -     * <p> If the <code>char</code> value specified at the given index
 180.677 -     * is in the high-surrogate range, the following index is less
 180.678 -     * than the length of this <code>String</code>, and the
 180.679 -     * <code>char</code> value at the following index is in the
 180.680 -     * low-surrogate range, then the supplementary code point
 180.681 -     * corresponding to this surrogate pair is returned. Otherwise,
 180.682 -     * the <code>char</code> value at the given index is returned.
 180.683 -     *
 180.684 -     * @param      index the index to the <code>char</code> values
 180.685 -     * @return     the code point value of the character at the
 180.686 -     *             <code>index</code>
 180.687 -     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 180.688 -     *             argument is negative or not less than the length of this
 180.689 -     *             string.
 180.690 -     * @since      1.5
 180.691 -     */
 180.692 -    public int codePointAt(int index) {
 180.693 -        if ((index < 0) || (index >= length())) {
 180.694 -            throw new StringIndexOutOfBoundsException(index);
 180.695 -        }
 180.696 -        return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
 180.697 -    }
 180.698 -
 180.699 -    /**
 180.700 -     * Returns the character (Unicode code point) before the specified
 180.701 -     * index. The index refers to <code>char</code> values
 180.702 -     * (Unicode code units) and ranges from <code>1</code> to {@link
 180.703 -     * CharSequence#length() length}.
 180.704 -     *
 180.705 -     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 180.706 -     * is in the low-surrogate range, <code>(index - 2)</code> is not
 180.707 -     * negative, and the <code>char</code> value at <code>(index -
 180.708 -     * 2)</code> is in the high-surrogate range, then the
 180.709 -     * supplementary code point value of the surrogate pair is
 180.710 -     * returned. If the <code>char</code> value at <code>index -
 180.711 -     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 180.712 -     * surrogate value is returned.
 180.713 -     *
 180.714 -     * @param     index the index following the code point that should be returned
 180.715 -     * @return    the Unicode code point value before the given index.
 180.716 -     * @exception IndexOutOfBoundsException if the <code>index</code>
 180.717 -     *            argument is less than 1 or greater than the length
 180.718 -     *            of this string.
 180.719 -     * @since     1.5
 180.720 -     */
 180.721 -    public int codePointBefore(int index) {
 180.722 -        int i = index - 1;
 180.723 -        if ((i < 0) || (i >= length())) {
 180.724 -            throw new StringIndexOutOfBoundsException(index);
 180.725 -        }
 180.726 -        return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
 180.727 -    }
 180.728 -
 180.729 -    /**
 180.730 -     * Returns the number of Unicode code points in the specified text
 180.731 -     * range of this <code>String</code>. The text range begins at the
 180.732 -     * specified <code>beginIndex</code> and extends to the
 180.733 -     * <code>char</code> at index <code>endIndex - 1</code>. Thus the
 180.734 -     * length (in <code>char</code>s) of the text range is
 180.735 -     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 180.736 -     * the text range count as one code point each.
 180.737 -     *
 180.738 -     * @param beginIndex the index to the first <code>char</code> of
 180.739 -     * the text range.
 180.740 -     * @param endIndex the index after the last <code>char</code> of
 180.741 -     * the text range.
 180.742 -     * @return the number of Unicode code points in the specified text
 180.743 -     * range
 180.744 -     * @exception IndexOutOfBoundsException if the
 180.745 -     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 180.746 -     * is larger than the length of this <code>String</code>, or
 180.747 -     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 180.748 -     * @since  1.5
 180.749 -     */
 180.750 -    public int codePointCount(int beginIndex, int endIndex) {
 180.751 -        if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
 180.752 -            throw new IndexOutOfBoundsException();
 180.753 -        }
 180.754 -        return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
 180.755 -    }
 180.756 -
 180.757 -    /**
 180.758 -     * Returns the index within this <code>String</code> that is
 180.759 -     * offset from the given <code>index</code> by
 180.760 -     * <code>codePointOffset</code> code points. Unpaired surrogates
 180.761 -     * within the text range given by <code>index</code> and
 180.762 -     * <code>codePointOffset</code> count as one code point each.
 180.763 -     *
 180.764 -     * @param index the index to be offset
 180.765 -     * @param codePointOffset the offset in code points
 180.766 -     * @return the index within this <code>String</code>
 180.767 -     * @exception IndexOutOfBoundsException if <code>index</code>
 180.768 -     *   is negative or larger then the length of this
 180.769 -     *   <code>String</code>, or if <code>codePointOffset</code> is positive
 180.770 -     *   and the substring starting with <code>index</code> has fewer
 180.771 -     *   than <code>codePointOffset</code> code points,
 180.772 -     *   or if <code>codePointOffset</code> is negative and the substring
 180.773 -     *   before <code>index</code> has fewer than the absolute value
 180.774 -     *   of <code>codePointOffset</code> code points.
 180.775 -     * @since 1.5
 180.776 -     */
 180.777 -    public int offsetByCodePoints(int index, int codePointOffset) {
 180.778 -        if (index < 0 || index > length()) {
 180.779 -            throw new IndexOutOfBoundsException();
 180.780 -        }
 180.781 -        return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
 180.782 -                                                offset()+index, codePointOffset) - offset();
 180.783 -    }
 180.784 -
 180.785 -    /**
 180.786 -     * Copy characters from this string into dst starting at dstBegin.
 180.787 -     * This method doesn't perform any range checking.
 180.788 -     */
 180.789 -    @JavaScriptBody(args = { "arr", "to" }, body = 
 180.790 -        "var s = this.toString();\n" +
 180.791 -        "for (var i = 0; i < s.length; i++) {\n" +
 180.792 -        "   arr[to++] = s[i];\n" +
 180.793 -        "}"
 180.794 -    )
 180.795 -    void getChars(char dst[], int dstBegin) {
 180.796 -        System.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
 180.797 -    }
 180.798 -
 180.799 -    /**
 180.800 -     * Copies characters from this string into the destination character
 180.801 -     * array.
 180.802 -     * <p>
 180.803 -     * The first character to be copied is at index <code>srcBegin</code>;
 180.804 -     * the last character to be copied is at index <code>srcEnd-1</code>
 180.805 -     * (thus the total number of characters to be copied is
 180.806 -     * <code>srcEnd-srcBegin</code>). The characters are copied into the
 180.807 -     * subarray of <code>dst</code> starting at index <code>dstBegin</code>
 180.808 -     * and ending at index:
 180.809 -     * <p><blockquote><pre>
 180.810 -     *     dstbegin + (srcEnd-srcBegin) - 1
 180.811 -     * </pre></blockquote>
 180.812 -     *
 180.813 -     * @param      srcBegin   index of the first character in the string
 180.814 -     *                        to copy.
 180.815 -     * @param      srcEnd     index after the last character in the string
 180.816 -     *                        to copy.
 180.817 -     * @param      dst        the destination array.
 180.818 -     * @param      dstBegin   the start offset in the destination array.
 180.819 -     * @exception IndexOutOfBoundsException If any of the following
 180.820 -     *            is true:
 180.821 -     *            <ul><li><code>srcBegin</code> is negative.
 180.822 -     *            <li><code>srcBegin</code> is greater than <code>srcEnd</code>
 180.823 -     *            <li><code>srcEnd</code> is greater than the length of this
 180.824 -     *                string
 180.825 -     *            <li><code>dstBegin</code> is negative
 180.826 -     *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
 180.827 -     *                <code>dst.length</code></ul>
 180.828 -     */
 180.829 -    @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
 180.830 -        "var s = this.toString();\n" +
 180.831 -        "while (beg < end) {\n" +
 180.832 -        "  arr[dst++] = s.charCodeAt(beg++);\n" +
 180.833 -        "}\n"
 180.834 -    )
 180.835 -    public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
 180.836 -        if (srcBegin < 0) {
 180.837 -            throw new StringIndexOutOfBoundsException(srcBegin);
 180.838 -        }
 180.839 -        if (srcEnd > length()) {
 180.840 -            throw new StringIndexOutOfBoundsException(srcEnd);
 180.841 -        }
 180.842 -        if (srcBegin > srcEnd) {
 180.843 -            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 180.844 -        }
 180.845 -        System.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
 180.846 -             srcEnd - srcBegin);
 180.847 -    }
 180.848 -
 180.849 -    /**
 180.850 -     * Copies characters from this string into the destination byte array. Each
 180.851 -     * byte receives the 8 low-order bits of the corresponding character. The
 180.852 -     * eight high-order bits of each character are not copied and do not
 180.853 -     * participate in the transfer in any way.
 180.854 -     *
 180.855 -     * <p> The first character to be copied is at index {@code srcBegin}; the
 180.856 -     * last character to be copied is at index {@code srcEnd-1}.  The total
 180.857 -     * number of characters to be copied is {@code srcEnd-srcBegin}. The
 180.858 -     * characters, converted to bytes, are copied into the subarray of {@code
 180.859 -     * dst} starting at index {@code dstBegin} and ending at index:
 180.860 -     *
 180.861 -     * <blockquote><pre>
 180.862 -     *     dstbegin + (srcEnd-srcBegin) - 1
 180.863 -     * </pre></blockquote>
 180.864 -     *
 180.865 -     * @deprecated  This method does not properly convert characters into
 180.866 -     * bytes.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 180.867 -     * {@link #getBytes()} method, which uses the platform's default charset.
 180.868 -     *
 180.869 -     * @param  srcBegin
 180.870 -     *         Index of the first character in the string to copy
 180.871 -     *
 180.872 -     * @param  srcEnd
 180.873 -     *         Index after the last character in the string to copy
 180.874 -     *
 180.875 -     * @param  dst
 180.876 -     *         The destination array
 180.877 -     *
 180.878 -     * @param  dstBegin
 180.879 -     *         The start offset in the destination array
 180.880 -     *
 180.881 -     * @throws  IndexOutOfBoundsException
 180.882 -     *          If any of the following is true:
 180.883 -     *          <ul>
 180.884 -     *            <li> {@code srcBegin} is negative
 180.885 -     *            <li> {@code srcBegin} is greater than {@code srcEnd}
 180.886 -     *            <li> {@code srcEnd} is greater than the length of this String
 180.887 -     *            <li> {@code dstBegin} is negative
 180.888 -     *            <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
 180.889 -     *                 dst.length}
 180.890 -     *          </ul>
 180.891 -     */
 180.892 -    @Deprecated
 180.893 -    public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
 180.894 -        if (srcBegin < 0) {
 180.895 -            throw new StringIndexOutOfBoundsException(srcBegin);
 180.896 -        }
 180.897 -        if (srcEnd > length()) {
 180.898 -            throw new StringIndexOutOfBoundsException(srcEnd);
 180.899 -        }
 180.900 -        if (srcBegin > srcEnd) {
 180.901 -            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 180.902 -        }
 180.903 -        int j = dstBegin;
 180.904 -        int n = offset() + srcEnd;
 180.905 -        int i = offset() + srcBegin;
 180.906 -        char[] val = toCharArray();   /* avoid getfield opcode */
 180.907 -
 180.908 -        while (i < n) {
 180.909 -            dst[j++] = (byte)val[i++];
 180.910 -        }
 180.911 -    }
 180.912 -
 180.913 -    /**
 180.914 -     * Encodes this {@code String} into a sequence of bytes using the named
 180.915 -     * charset, storing the result into a new byte array.
 180.916 -     *
 180.917 -     * <p> The behavior of this method when this string cannot be encoded in
 180.918 -     * the given charset is unspecified.  The {@link
 180.919 -     * java.nio.charset.CharsetEncoder} class should be used when more control
 180.920 -     * over the encoding process is required.
 180.921 -     *
 180.922 -     * @param  charsetName
 180.923 -     *         The name of a supported {@linkplain java.nio.charset.Charset
 180.924 -     *         charset}
 180.925 -     *
 180.926 -     * @return  The resultant byte array
 180.927 -     *
 180.928 -     * @throws  UnsupportedEncodingException
 180.929 -     *          If the named charset is not supported
 180.930 -     *
 180.931 -     * @since  JDK1.1
 180.932 -     */
 180.933 -    public byte[] getBytes(String charsetName)
 180.934 -        throws UnsupportedEncodingException
 180.935 -    {
 180.936 -        checkUTF8(null, charsetName);
 180.937 -        return getBytes();
 180.938 -    }
 180.939 -
 180.940 -    /**
 180.941 -     * Encodes this {@code String} into a sequence of bytes using the given
 180.942 -     * {@linkplain java.nio.charset.Charset charset}, storing the result into a
 180.943 -     * new byte array.
 180.944 -     *
 180.945 -     * <p> This method always replaces malformed-input and unmappable-character
 180.946 -     * sequences with this charset's default replacement byte array.  The
 180.947 -     * {@link java.nio.charset.CharsetEncoder} class should be used when more
 180.948 -     * control over the encoding process is required.
 180.949 -     *
 180.950 -     * @param  charset
 180.951 -     *         The {@linkplain java.nio.charset.Charset} to be used to encode
 180.952 -     *         the {@code String}
 180.953 -     *
 180.954 -     * @return  The resultant byte array
 180.955 -     *
 180.956 -     * @since  1.6
 180.957 -     */
 180.958 -    /* don't want dep on Charset
 180.959 -    public byte[] getBytes(Charset charset) {
 180.960 -        if (charset == null) throw new NullPointerException();
 180.961 -        return StringCoding.encode(charset, value, offset, count);
 180.962 -    }
 180.963 -    */
 180.964 -
 180.965 -    /**
 180.966 -     * Encodes this {@code String} into a sequence of bytes using the
 180.967 -     * platform's default charset, storing the result into a new byte array.
 180.968 -     *
 180.969 -     * <p> The behavior of this method when this string cannot be encoded in
 180.970 -     * the default charset is unspecified.  The {@link
 180.971 -     * java.nio.charset.CharsetEncoder} class should be used when more control
 180.972 -     * over the encoding process is required.
 180.973 -     *
 180.974 -     * @return  The resultant byte array
 180.975 -     *
 180.976 -     * @since      JDK1.1
 180.977 -     */
 180.978 -    public byte[] getBytes() {
 180.979 -        int len = length();
 180.980 -        byte[] arr = new byte[len];
 180.981 -        for (int i = 0, j = 0; j < len; j++) {
 180.982 -            final int v = charAt(j);
 180.983 -            if (v < 128) {
 180.984 -                arr[i++] = (byte) v;
 180.985 -                continue;
 180.986 -            }
 180.987 -            if (v < 0x0800) {
 180.988 -                arr = System.expandArray(arr, i + 1);
 180.989 -                arr[i++] = (byte) (0xC0 | (v >> 6));
 180.990 -                arr[i++] = (byte) (0x80 | (0x3F & v));
 180.991 -                continue;
 180.992 -            }
 180.993 -            arr = System.expandArray(arr, i + 2);
 180.994 -            arr[i++] = (byte) (0xE0 | (v >> 12));
 180.995 -            arr[i++] = (byte) (0x80 | ((v >> 6) & 0x7F));
 180.996 -            arr[i++] = (byte) (0x80 | (0x3F & v));
 180.997 -        }
 180.998 -        return arr;
 180.999 -    }
180.1000 -
180.1001 -    /**
180.1002 -     * Compares this string to the specified object.  The result is {@code
180.1003 -     * true} if and only if the argument is not {@code null} and is a {@code
180.1004 -     * String} object that represents the same sequence of characters as this
180.1005 -     * object.
180.1006 -     *
180.1007 -     * @param  anObject
180.1008 -     *         The object to compare this {@code String} against
180.1009 -     *
180.1010 -     * @return  {@code true} if the given object represents a {@code String}
180.1011 -     *          equivalent to this string, {@code false} otherwise
180.1012 -     *
180.1013 -     * @see  #compareTo(String)
180.1014 -     * @see  #equalsIgnoreCase(String)
180.1015 -     */
180.1016 -    @JavaScriptBody(args = { "obj" }, body = 
180.1017 -        "return obj != null && obj.$instOf_java_lang_String && "
180.1018 -        + "this.toString() === obj.toString();"
180.1019 -    )
180.1020 -    public boolean equals(Object anObject) {
180.1021 -        if (this == anObject) {
180.1022 -            return true;
180.1023 -        }
180.1024 -        if (anObject instanceof String) {
180.1025 -            String anotherString = (String)anObject;
180.1026 -            int n = length();
180.1027 -            if (n == anotherString.length()) {
180.1028 -                char v1[] = toCharArray();
180.1029 -                char v2[] = anotherString.toCharArray();
180.1030 -                int i = offset();
180.1031 -                int j = anotherString.offset();
180.1032 -                while (n-- != 0) {
180.1033 -                    if (v1[i++] != v2[j++])
180.1034 -                        return false;
180.1035 -                }
180.1036 -                return true;
180.1037 -            }
180.1038 -        }
180.1039 -        return false;
180.1040 -    }
180.1041 -
180.1042 -    /**
180.1043 -     * Compares this string to the specified {@code StringBuffer}.  The result
180.1044 -     * is {@code true} if and only if this {@code String} represents the same
180.1045 -     * sequence of characters as the specified {@code StringBuffer}.
180.1046 -     *
180.1047 -     * @param  sb
180.1048 -     *         The {@code StringBuffer} to compare this {@code String} against
180.1049 -     *
180.1050 -     * @return  {@code true} if this {@code String} represents the same
180.1051 -     *          sequence of characters as the specified {@code StringBuffer},
180.1052 -     *          {@code false} otherwise
180.1053 -     *
180.1054 -     * @since  1.4
180.1055 -     */
180.1056 -    public boolean contentEquals(StringBuffer sb) {
180.1057 -        synchronized(sb) {
180.1058 -            return contentEquals((CharSequence)sb);
180.1059 -        }
180.1060 -    }
180.1061 -
180.1062 -    /**
180.1063 -     * Compares this string to the specified {@code CharSequence}.  The result
180.1064 -     * is {@code true} if and only if this {@code String} represents the same
180.1065 -     * sequence of char values as the specified sequence.
180.1066 -     *
180.1067 -     * @param  cs
180.1068 -     *         The sequence to compare this {@code String} against
180.1069 -     *
180.1070 -     * @return  {@code true} if this {@code String} represents the same
180.1071 -     *          sequence of char values as the specified sequence, {@code
180.1072 -     *          false} otherwise
180.1073 -     *
180.1074 -     * @since  1.5
180.1075 -     */
180.1076 -    public boolean contentEquals(CharSequence cs) {
180.1077 -        if (length() != cs.length())
180.1078 -            return false;
180.1079 -        // Argument is a StringBuffer, StringBuilder
180.1080 -        if (cs instanceof AbstractStringBuilder) {
180.1081 -            char v1[] = toCharArray();
180.1082 -            char v2[] = ((AbstractStringBuilder)cs).getValue();
180.1083 -            int i = offset();
180.1084 -            int j = 0;
180.1085 -            int n = length();
180.1086 -            while (n-- != 0) {
180.1087 -                if (v1[i++] != v2[j++])
180.1088 -                    return false;
180.1089 -            }
180.1090 -            return true;
180.1091 -        }
180.1092 -        // Argument is a String
180.1093 -        if (cs.equals(this))
180.1094 -            return true;
180.1095 -        // Argument is a generic CharSequence
180.1096 -        char v1[] = toCharArray();
180.1097 -        int i = offset();
180.1098 -        int j = 0;
180.1099 -        int n = length();
180.1100 -        while (n-- != 0) {
180.1101 -            if (v1[i++] != cs.charAt(j++))
180.1102 -                return false;
180.1103 -        }
180.1104 -        return true;
180.1105 -    }
180.1106 -
180.1107 -    /**
180.1108 -     * Compares this {@code String} to another {@code String}, ignoring case
180.1109 -     * considerations.  Two strings are considered equal ignoring case if they
180.1110 -     * are of the same length and corresponding characters in the two strings
180.1111 -     * are equal ignoring case.
180.1112 -     *
180.1113 -     * <p> Two characters {@code c1} and {@code c2} are considered the same
180.1114 -     * ignoring case if at least one of the following is true:
180.1115 -     * <ul>
180.1116 -     *   <li> The two characters are the same (as compared by the
180.1117 -     *        {@code ==} operator)
180.1118 -     *   <li> Applying the method {@link
180.1119 -     *        java.lang.Character#toUpperCase(char)} to each character
180.1120 -     *        produces the same result
180.1121 -     *   <li> Applying the method {@link
180.1122 -     *        java.lang.Character#toLowerCase(char)} to each character
180.1123 -     *        produces the same result
180.1124 -     * </ul>
180.1125 -     *
180.1126 -     * @param  anotherString
180.1127 -     *         The {@code String} to compare this {@code String} against
180.1128 -     *
180.1129 -     * @return  {@code true} if the argument is not {@code null} and it
180.1130 -     *          represents an equivalent {@code String} ignoring case; {@code
180.1131 -     *          false} otherwise
180.1132 -     *
180.1133 -     * @see  #equals(Object)
180.1134 -     */
180.1135 -    public boolean equalsIgnoreCase(String anotherString) {
180.1136 -        return (this == anotherString) ? true :
180.1137 -               (anotherString != null) && (anotherString.length() == length()) &&
180.1138 -               regionMatches(true, 0, anotherString, 0, length());
180.1139 -    }
180.1140 -
180.1141 -    /**
180.1142 -     * Compares two strings lexicographically.
180.1143 -     * The comparison is based on the Unicode value of each character in
180.1144 -     * the strings. The character sequence represented by this
180.1145 -     * <code>String</code> object is compared lexicographically to the
180.1146 -     * character sequence represented by the argument string. The result is
180.1147 -     * a negative integer if this <code>String</code> object
180.1148 -     * lexicographically precedes the argument string. The result is a
180.1149 -     * positive integer if this <code>String</code> object lexicographically
180.1150 -     * follows the argument string. The result is zero if the strings
180.1151 -     * are equal; <code>compareTo</code> returns <code>0</code> exactly when
180.1152 -     * the {@link #equals(Object)} method would return <code>true</code>.
180.1153 -     * <p>
180.1154 -     * This is the definition of lexicographic ordering. If two strings are
180.1155 -     * different, then either they have different characters at some index
180.1156 -     * that is a valid index for both strings, or their lengths are different,
180.1157 -     * or both. If they have different characters at one or more index
180.1158 -     * positions, let <i>k</i> be the smallest such index; then the string
180.1159 -     * whose character at position <i>k</i> has the smaller value, as
180.1160 -     * determined by using the &lt; operator, lexicographically precedes the
180.1161 -     * other string. In this case, <code>compareTo</code> returns the
180.1162 -     * difference of the two character values at position <code>k</code> in
180.1163 -     * the two string -- that is, the value:
180.1164 -     * <blockquote><pre>
180.1165 -     * this.charAt(k)-anotherString.charAt(k)
180.1166 -     * </pre></blockquote>
180.1167 -     * If there is no index position at which they differ, then the shorter
180.1168 -     * string lexicographically precedes the longer string. In this case,
180.1169 -     * <code>compareTo</code> returns the difference of the lengths of the
180.1170 -     * strings -- that is, the value:
180.1171 -     * <blockquote><pre>
180.1172 -     * this.length()-anotherString.length()
180.1173 -     * </pre></blockquote>
180.1174 -     *
180.1175 -     * @param   anotherString   the <code>String</code> to be compared.
180.1176 -     * @return  the value <code>0</code> if the argument string is equal to
180.1177 -     *          this string; a value less than <code>0</code> if this string
180.1178 -     *          is lexicographically less than the string argument; and a
180.1179 -     *          value greater than <code>0</code> if this string is
180.1180 -     *          lexicographically greater than the string argument.
180.1181 -     */
180.1182 -    public int compareTo(String anotherString) {
180.1183 -        int len1 = length();
180.1184 -        int len2 = anotherString.length();
180.1185 -        int n = Math.min(len1, len2);
180.1186 -        char v1[] = toCharArray();
180.1187 -        char v2[] = anotherString.toCharArray();
180.1188 -        int i = offset();
180.1189 -        int j = anotherString.offset();
180.1190 -
180.1191 -        if (i == j) {
180.1192 -            int k = i;
180.1193 -            int lim = n + i;
180.1194 -            while (k < lim) {
180.1195 -                char c1 = v1[k];
180.1196 -                char c2 = v2[k];
180.1197 -                if (c1 != c2) {
180.1198 -                    return c1 - c2;
180.1199 -                }
180.1200 -                k++;
180.1201 -            }
180.1202 -        } else {
180.1203 -            while (n-- != 0) {
180.1204 -                char c1 = v1[i++];
180.1205 -                char c2 = v2[j++];
180.1206 -                if (c1 != c2) {
180.1207 -                    return c1 - c2;
180.1208 -                }
180.1209 -            }
180.1210 -        }
180.1211 -        return len1 - len2;
180.1212 -    }
180.1213 -
180.1214 -    /**
180.1215 -     * A Comparator that orders <code>String</code> objects as by
180.1216 -     * <code>compareToIgnoreCase</code>. This comparator is serializable.
180.1217 -     * <p>
180.1218 -     * Note that this Comparator does <em>not</em> take locale into account,
180.1219 -     * and will result in an unsatisfactory ordering for certain locales.
180.1220 -     * The java.text package provides <em>Collators</em> to allow
180.1221 -     * locale-sensitive ordering.
180.1222 -     *
180.1223 -     * @see     java.text.Collator#compare(String, String)
180.1224 -     * @since   1.2
180.1225 -     */
180.1226 -    public static final Comparator<String> CASE_INSENSITIVE_ORDER
180.1227 -                                         = new CaseInsensitiveComparator();
180.1228 -
180.1229 -    private static int offset() {
180.1230 -        return 0;
180.1231 -    }
180.1232 -
180.1233 -    private static class CaseInsensitiveComparator
180.1234 -                         implements Comparator<String>, java.io.Serializable {
180.1235 -        // use serialVersionUID from JDK 1.2.2 for interoperability
180.1236 -        private static final long serialVersionUID = 8575799808933029326L;
180.1237 -
180.1238 -        public int compare(String s1, String s2) {
180.1239 -            int n1 = s1.length();
180.1240 -            int n2 = s2.length();
180.1241 -            int min = Math.min(n1, n2);
180.1242 -            for (int i = 0; i < min; i++) {
180.1243 -                char c1 = s1.charAt(i);
180.1244 -                char c2 = s2.charAt(i);
180.1245 -                if (c1 != c2) {
180.1246 -                    c1 = Character.toUpperCase(c1);
180.1247 -                    c2 = Character.toUpperCase(c2);
180.1248 -                    if (c1 != c2) {
180.1249 -                        c1 = Character.toLowerCase(c1);
180.1250 -                        c2 = Character.toLowerCase(c2);
180.1251 -                        if (c1 != c2) {
180.1252 -                            // No overflow because of numeric promotion
180.1253 -                            return c1 - c2;
180.1254 -                        }
180.1255 -                    }
180.1256 -                }
180.1257 -            }
180.1258 -            return n1 - n2;
180.1259 -        }
180.1260 -    }
180.1261 -
180.1262 -    /**
180.1263 -     * Compares two strings lexicographically, ignoring case
180.1264 -     * differences. This method returns an integer whose sign is that of
180.1265 -     * calling <code>compareTo</code> with normalized versions of the strings
180.1266 -     * where case differences have been eliminated by calling
180.1267 -     * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
180.1268 -     * each character.
180.1269 -     * <p>
180.1270 -     * Note that this method does <em>not</em> take locale into account,
180.1271 -     * and will result in an unsatisfactory ordering for certain locales.
180.1272 -     * The java.text package provides <em>collators</em> to allow
180.1273 -     * locale-sensitive ordering.
180.1274 -     *
180.1275 -     * @param   str   the <code>String</code> to be compared.
180.1276 -     * @return  a negative integer, zero, or a positive integer as the
180.1277 -     *          specified String is greater than, equal to, or less
180.1278 -     *          than this String, ignoring case considerations.
180.1279 -     * @see     java.text.Collator#compare(String, String)
180.1280 -     * @since   1.2
180.1281 -     */
180.1282 -    public int compareToIgnoreCase(String str) {
180.1283 -        return CASE_INSENSITIVE_ORDER.compare(this, str);
180.1284 -    }
180.1285 -
180.1286 -    /**
180.1287 -     * Tests if two string regions are equal.
180.1288 -     * <p>
180.1289 -     * A substring of this <tt>String</tt> object is compared to a substring
180.1290 -     * of the argument other. The result is true if these substrings
180.1291 -     * represent identical character sequences. The substring of this
180.1292 -     * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
180.1293 -     * and has length <tt>len</tt>. The substring of other to be compared
180.1294 -     * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
180.1295 -     * result is <tt>false</tt> if and only if at least one of the following
180.1296 -     * is true:
180.1297 -     * <ul><li><tt>toffset</tt> is negative.
180.1298 -     * <li><tt>ooffset</tt> is negative.
180.1299 -     * <li><tt>toffset+len</tt> is greater than the length of this
180.1300 -     * <tt>String</tt> object.
180.1301 -     * <li><tt>ooffset+len</tt> is greater than the length of the other
180.1302 -     * argument.
180.1303 -     * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
180.1304 -     * such that:
180.1305 -     * <tt>this.charAt(toffset+<i>k</i>)&nbsp;!=&nbsp;other.charAt(ooffset+<i>k</i>)</tt>
180.1306 -     * </ul>
180.1307 -     *
180.1308 -     * @param   toffset   the starting offset of the subregion in this string.
180.1309 -     * @param   other     the string argument.
180.1310 -     * @param   ooffset   the starting offset of the subregion in the string
180.1311 -     *                    argument.
180.1312 -     * @param   len       the number of characters to compare.
180.1313 -     * @return  <code>true</code> if the specified subregion of this string
180.1314 -     *          exactly matches the specified subregion of the string argument;
180.1315 -     *          <code>false</code> otherwise.
180.1316 -     */
180.1317 -    public boolean regionMatches(int toffset, String other, int ooffset,
180.1318 -                                 int len) {
180.1319 -        char ta[] = toCharArray();
180.1320 -        int to = offset() + toffset;
180.1321 -        char pa[] = other.toCharArray();
180.1322 -        int po = other.offset() + ooffset;
180.1323 -        // Note: toffset, ooffset, or len might be near -1>>>1.
180.1324 -        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
180.1325 -            || (ooffset > (long)other.length() - len)) {
180.1326 -            return false;
180.1327 -        }
180.1328 -        while (len-- > 0) {
180.1329 -            if (ta[to++] != pa[po++]) {
180.1330 -                return false;
180.1331 -            }
180.1332 -        }
180.1333 -        return true;
180.1334 -    }
180.1335 -
180.1336 -    /**
180.1337 -     * Tests if two string regions are equal.
180.1338 -     * <p>
180.1339 -     * A substring of this <tt>String</tt> object is compared to a substring
180.1340 -     * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
180.1341 -     * substrings represent character sequences that are the same, ignoring
180.1342 -     * case if and only if <tt>ignoreCase</tt> is true. The substring of
180.1343 -     * this <tt>String</tt> object to be compared begins at index
180.1344 -     * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
180.1345 -     * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
180.1346 -     * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
180.1347 -     * at least one of the following is true:
180.1348 -     * <ul><li><tt>toffset</tt> is negative.
180.1349 -     * <li><tt>ooffset</tt> is negative.
180.1350 -     * <li><tt>toffset+len</tt> is greater than the length of this
180.1351 -     * <tt>String</tt> object.
180.1352 -     * <li><tt>ooffset+len</tt> is greater than the length of the other
180.1353 -     * argument.
180.1354 -     * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
180.1355 -     * integer <i>k</i> less than <tt>len</tt> such that:
180.1356 -     * <blockquote><pre>
180.1357 -     * this.charAt(toffset+k) != other.charAt(ooffset+k)
180.1358 -     * </pre></blockquote>
180.1359 -     * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
180.1360 -     * integer <i>k</i> less than <tt>len</tt> such that:
180.1361 -     * <blockquote><pre>
180.1362 -     * Character.toLowerCase(this.charAt(toffset+k)) !=
180.1363 -               Character.toLowerCase(other.charAt(ooffset+k))
180.1364 -     * </pre></blockquote>
180.1365 -     * and:
180.1366 -     * <blockquote><pre>
180.1367 -     * Character.toUpperCase(this.charAt(toffset+k)) !=
180.1368 -     *         Character.toUpperCase(other.charAt(ooffset+k))
180.1369 -     * </pre></blockquote>
180.1370 -     * </ul>
180.1371 -     *
180.1372 -     * @param   ignoreCase   if <code>true</code>, ignore case when comparing
180.1373 -     *                       characters.
180.1374 -     * @param   toffset      the starting offset of the subregion in this
180.1375 -     *                       string.
180.1376 -     * @param   other        the string argument.
180.1377 -     * @param   ooffset      the starting offset of the subregion in the string
180.1378 -     *                       argument.
180.1379 -     * @param   len          the number of characters to compare.
180.1380 -     * @return  <code>true</code> if the specified subregion of this string
180.1381 -     *          matches the specified subregion of the string argument;
180.1382 -     *          <code>false</code> otherwise. Whether the matching is exact
180.1383 -     *          or case insensitive depends on the <code>ignoreCase</code>
180.1384 -     *          argument.
180.1385 -     */
180.1386 -    public boolean regionMatches(boolean ignoreCase, int toffset,
180.1387 -                           String other, int ooffset, int len) {
180.1388 -        char ta[] = toCharArray();
180.1389 -        int to = offset() + toffset;
180.1390 -        char pa[] = other.toCharArray();
180.1391 -        int po = other.offset() + ooffset;
180.1392 -        // Note: toffset, ooffset, or len might be near -1>>>1.
180.1393 -        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
180.1394 -                (ooffset > (long)other.length() - len)) {
180.1395 -            return false;
180.1396 -        }
180.1397 -        while (len-- > 0) {
180.1398 -            char c1 = ta[to++];
180.1399 -            char c2 = pa[po++];
180.1400 -            if (c1 == c2) {
180.1401 -                continue;
180.1402 -            }
180.1403 -            if (ignoreCase) {
180.1404 -                // If characters don't match but case may be ignored,
180.1405 -                // try converting both characters to uppercase.
180.1406 -                // If the results match, then the comparison scan should
180.1407 -                // continue.
180.1408 -                char u1 = Character.toUpperCase(c1);
180.1409 -                char u2 = Character.toUpperCase(c2);
180.1410 -                if (u1 == u2) {
180.1411 -                    continue;
180.1412 -                }
180.1413 -                // Unfortunately, conversion to uppercase does not work properly
180.1414 -                // for the Georgian alphabet, which has strange rules about case
180.1415 -                // conversion.  So we need to make one last check before
180.1416 -                // exiting.
180.1417 -                if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
180.1418 -                    continue;
180.1419 -                }
180.1420 -            }
180.1421 -            return false;
180.1422 -        }
180.1423 -        return true;
180.1424 -    }
180.1425 -
180.1426 -    /**
180.1427 -     * Tests if the substring of this string beginning at the
180.1428 -     * specified index starts with the specified prefix.
180.1429 -     *
180.1430 -     * @param   prefix    the prefix.
180.1431 -     * @param   toffset   where to begin looking in this string.
180.1432 -     * @return  <code>true</code> if the character sequence represented by the
180.1433 -     *          argument is a prefix of the substring of this object starting
180.1434 -     *          at index <code>toffset</code>; <code>false</code> otherwise.
180.1435 -     *          The result is <code>false</code> if <code>toffset</code> is
180.1436 -     *          negative or greater than the length of this
180.1437 -     *          <code>String</code> object; otherwise the result is the same
180.1438 -     *          as the result of the expression
180.1439 -     *          <pre>
180.1440 -     *          this.substring(toffset).startsWith(prefix)
180.1441 -     *          </pre>
180.1442 -     */
180.1443 -    @JavaScriptBody(args = { "find", "from" }, body=
180.1444 -        "find = find.toString();\n" +
180.1445 -        "return this.toString().substring(from, from + find.length) === find;\n"
180.1446 -    )
180.1447 -    public boolean startsWith(String prefix, int toffset) {
180.1448 -        char ta[] = toCharArray();
180.1449 -        int to = offset() + toffset;
180.1450 -        char pa[] = prefix.toCharArray();
180.1451 -        int po = prefix.offset();
180.1452 -        int pc = prefix.length();
180.1453 -        // Note: toffset might be near -1>>>1.
180.1454 -        if ((toffset < 0) || (toffset > length() - pc)) {
180.1455 -            return false;
180.1456 -        }
180.1457 -        while (--pc >= 0) {
180.1458 -            if (ta[to++] != pa[po++]) {
180.1459 -                return false;
180.1460 -            }
180.1461 -        }
180.1462 -        return true;
180.1463 -    }
180.1464 -
180.1465 -    /**
180.1466 -     * Tests if this string starts with the specified prefix.
180.1467 -     *
180.1468 -     * @param   prefix   the prefix.
180.1469 -     * @return  <code>true</code> if the character sequence represented by the
180.1470 -     *          argument is a prefix of the character sequence represented by
180.1471 -     *          this string; <code>false</code> otherwise.
180.1472 -     *          Note also that <code>true</code> will be returned if the
180.1473 -     *          argument is an empty string or is equal to this
180.1474 -     *          <code>String</code> object as determined by the
180.1475 -     *          {@link #equals(Object)} method.
180.1476 -     * @since   1. 0
180.1477 -     */
180.1478 -    public boolean startsWith(String prefix) {
180.1479 -        return startsWith(prefix, 0);
180.1480 -    }
180.1481 -
180.1482 -    /**
180.1483 -     * Tests if this string ends with the specified suffix.
180.1484 -     *
180.1485 -     * @param   suffix   the suffix.
180.1486 -     * @return  <code>true</code> if the character sequence represented by the
180.1487 -     *          argument is a suffix of the character sequence represented by
180.1488 -     *          this object; <code>false</code> otherwise. Note that the
180.1489 -     *          result will be <code>true</code> if the argument is the
180.1490 -     *          empty string or is equal to this <code>String</code> object
180.1491 -     *          as determined by the {@link #equals(Object)} method.
180.1492 -     */
180.1493 -    public boolean endsWith(String suffix) {
180.1494 -        return startsWith(suffix, length() - suffix.length());
180.1495 -    }
180.1496 -
180.1497 -    /**
180.1498 -     * Returns a hash code for this string. The hash code for a
180.1499 -     * <code>String</code> object is computed as
180.1500 -     * <blockquote><pre>
180.1501 -     * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
180.1502 -     * </pre></blockquote>
180.1503 -     * using <code>int</code> arithmetic, where <code>s[i]</code> is the
180.1504 -     * <i>i</i>th character of the string, <code>n</code> is the length of
180.1505 -     * the string, and <code>^</code> indicates exponentiation.
180.1506 -     * (The hash value of the empty string is zero.)
180.1507 -     *
180.1508 -     * @return  a hash code value for this object.
180.1509 -     */
180.1510 -    public int hashCode() {
180.1511 -        return super.hashCode();
180.1512 -    }
180.1513 -    int computeHashCode() {
180.1514 -        int h = 0;
180.1515 -        if (h == 0 && length() > 0) {
180.1516 -            int off = offset();
180.1517 -            int len = length();
180.1518 -
180.1519 -            for (int i = 0; i < len; i++) {
180.1520 -                h = 31*h + charAt(off++);
180.1521 -            }
180.1522 -        }
180.1523 -        return h;
180.1524 -    }
180.1525 -
180.1526 -    /**
180.1527 -     * Returns the index within this string of the first occurrence of
180.1528 -     * the specified character. If a character with value
180.1529 -     * <code>ch</code> occurs in the character sequence represented by
180.1530 -     * this <code>String</code> object, then the index (in Unicode
180.1531 -     * code units) of the first such occurrence is returned. For
180.1532 -     * values of <code>ch</code> in the range from 0 to 0xFFFF
180.1533 -     * (inclusive), this is the smallest value <i>k</i> such that:
180.1534 -     * <blockquote><pre>
180.1535 -     * this.charAt(<i>k</i>) == ch
180.1536 -     * </pre></blockquote>
180.1537 -     * is true. For other values of <code>ch</code>, it is the
180.1538 -     * smallest value <i>k</i> such that:
180.1539 -     * <blockquote><pre>
180.1540 -     * this.codePointAt(<i>k</i>) == ch
180.1541 -     * </pre></blockquote>
180.1542 -     * is true. In either case, if no such character occurs in this
180.1543 -     * string, then <code>-1</code> is returned.
180.1544 -     *
180.1545 -     * @param   ch   a character (Unicode code point).
180.1546 -     * @return  the index of the first occurrence of the character in the
180.1547 -     *          character sequence represented by this object, or
180.1548 -     *          <code>-1</code> if the character does not occur.
180.1549 -     */
180.1550 -    public int indexOf(int ch) {
180.1551 -        return indexOf(ch, 0);
180.1552 -    }
180.1553 -
180.1554 -    /**
180.1555 -     * Returns the index within this string of the first occurrence of the
180.1556 -     * specified character, starting the search at the specified index.
180.1557 -     * <p>
180.1558 -     * If a character with value <code>ch</code> occurs in the
180.1559 -     * character sequence represented by this <code>String</code>
180.1560 -     * object at an index no smaller than <code>fromIndex</code>, then
180.1561 -     * the index of the first such occurrence is returned. For values
180.1562 -     * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
180.1563 -     * this is the smallest value <i>k</i> such that:
180.1564 -     * <blockquote><pre>
180.1565 -     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
180.1566 -     * </pre></blockquote>
180.1567 -     * is true. For other values of <code>ch</code>, it is the
180.1568 -     * smallest value <i>k</i> such that:
180.1569 -     * <blockquote><pre>
180.1570 -     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
180.1571 -     * </pre></blockquote>
180.1572 -     * is true. In either case, if no such character occurs in this
180.1573 -     * string at or after position <code>fromIndex</code>, then
180.1574 -     * <code>-1</code> is returned.
180.1575 -     *
180.1576 -     * <p>
180.1577 -     * There is no restriction on the value of <code>fromIndex</code>. If it
180.1578 -     * is negative, it has the same effect as if it were zero: this entire
180.1579 -     * string may be searched. If it is greater than the length of this
180.1580 -     * string, it has the same effect as if it were equal to the length of
180.1581 -     * this string: <code>-1</code> is returned.
180.1582 -     *
180.1583 -     * <p>All indices are specified in <code>char</code> values
180.1584 -     * (Unicode code units).
180.1585 -     *
180.1586 -     * @param   ch          a character (Unicode code point).
180.1587 -     * @param   fromIndex   the index to start the search from.
180.1588 -     * @return  the index of the first occurrence of the character in the
180.1589 -     *          character sequence represented by this object that is greater
180.1590 -     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
180.1591 -     *          if the character does not occur.
180.1592 -     */
180.1593 -    @JavaScriptBody(args = { "ch", "from" }, body = 
180.1594 -        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
180.1595 -        "return this.toString().indexOf(ch, from);\n"
180.1596 -    )
180.1597 -    public int indexOf(int ch, int fromIndex) {
180.1598 -        if (fromIndex < 0) {
180.1599 -            fromIndex = 0;
180.1600 -        } else if (fromIndex >= length()) {
180.1601 -            // Note: fromIndex might be near -1>>>1.
180.1602 -            return -1;
180.1603 -        }
180.1604 -
180.1605 -        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
180.1606 -            // handle most cases here (ch is a BMP code point or a
180.1607 -            // negative value (invalid code point))
180.1608 -            final char[] value = this.toCharArray();
180.1609 -            final int offset = this.offset();
180.1610 -            final int max = offset + length();
180.1611 -            for (int i = offset + fromIndex; i < max ; i++) {
180.1612 -                if (value[i] == ch) {
180.1613 -                    return i - offset;
180.1614 -                }
180.1615 -            }
180.1616 -            return -1;
180.1617 -        } else {
180.1618 -            return indexOfSupplementary(ch, fromIndex);
180.1619 -        }
180.1620 -    }
180.1621 -
180.1622 -    /**
180.1623 -     * Handles (rare) calls of indexOf with a supplementary character.
180.1624 -     */
180.1625 -    private int indexOfSupplementary(int ch, int fromIndex) {
180.1626 -        if (Character.isValidCodePoint(ch)) {
180.1627 -            final char[] value = this.toCharArray();
180.1628 -            final int offset = this.offset();
180.1629 -            final char hi = Character.highSurrogate(ch);
180.1630 -            final char lo = Character.lowSurrogate(ch);
180.1631 -            final int max = offset + length() - 1;
180.1632 -            for (int i = offset + fromIndex; i < max; i++) {
180.1633 -                if (value[i] == hi && value[i+1] == lo) {
180.1634 -                    return i - offset;
180.1635 -                }
180.1636 -            }
180.1637 -        }
180.1638 -        return -1;
180.1639 -    }
180.1640 -
180.1641 -    /**
180.1642 -     * Returns the index within this string of the last occurrence of
180.1643 -     * the specified character. For values of <code>ch</code> in the
180.1644 -     * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
180.1645 -     * units) returned is the largest value <i>k</i> such that:
180.1646 -     * <blockquote><pre>
180.1647 -     * this.charAt(<i>k</i>) == ch
180.1648 -     * </pre></blockquote>
180.1649 -     * is true. For other values of <code>ch</code>, it is the
180.1650 -     * largest value <i>k</i> such that:
180.1651 -     * <blockquote><pre>
180.1652 -     * this.codePointAt(<i>k</i>) == ch
180.1653 -     * </pre></blockquote>
180.1654 -     * is true.  In either case, if no such character occurs in this
180.1655 -     * string, then <code>-1</code> is returned.  The
180.1656 -     * <code>String</code> is searched backwards starting at the last
180.1657 -     * character.
180.1658 -     *
180.1659 -     * @param   ch   a character (Unicode code point).
180.1660 -     * @return  the index of the last occurrence of the character in the
180.1661 -     *          character sequence represented by this object, or
180.1662 -     *          <code>-1</code> if the character does not occur.
180.1663 -     */
180.1664 -    public int lastIndexOf(int ch) {
180.1665 -        return lastIndexOf(ch, length() - 1);
180.1666 -    }
180.1667 -
180.1668 -    /**
180.1669 -     * Returns the index within this string of the last occurrence of
180.1670 -     * the specified character, searching backward starting at the
180.1671 -     * specified index. For values of <code>ch</code> in the range
180.1672 -     * from 0 to 0xFFFF (inclusive), the index returned is the largest
180.1673 -     * value <i>k</i> such that:
180.1674 -     * <blockquote><pre>
180.1675 -     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
180.1676 -     * </pre></blockquote>
180.1677 -     * is true. For other values of <code>ch</code>, it is the
180.1678 -     * largest value <i>k</i> such that:
180.1679 -     * <blockquote><pre>
180.1680 -     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
180.1681 -     * </pre></blockquote>
180.1682 -     * is true. In either case, if no such character occurs in this
180.1683 -     * string at or before position <code>fromIndex</code>, then
180.1684 -     * <code>-1</code> is returned.
180.1685 -     *
180.1686 -     * <p>All indices are specified in <code>char</code> values
180.1687 -     * (Unicode code units).
180.1688 -     *
180.1689 -     * @param   ch          a character (Unicode code point).
180.1690 -     * @param   fromIndex   the index to start the search from. There is no
180.1691 -     *          restriction on the value of <code>fromIndex</code>. If it is
180.1692 -     *          greater than or equal to the length of this string, it has
180.1693 -     *          the same effect as if it were equal to one less than the
180.1694 -     *          length of this string: this entire string may be searched.
180.1695 -     *          If it is negative, it has the same effect as if it were -1:
180.1696 -     *          -1 is returned.
180.1697 -     * @return  the index of the last occurrence of the character in the
180.1698 -     *          character sequence represented by this object that is less
180.1699 -     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
180.1700 -     *          if the character does not occur before that point.
180.1701 -     */
180.1702 -    @JavaScriptBody(args = { "ch", "from" }, body = 
180.1703 -        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
180.1704 -        "return this.toString().lastIndexOf(ch, from);"
180.1705 -    )
180.1706 -    public int lastIndexOf(int ch, int fromIndex) {
180.1707 -        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
180.1708 -            // handle most cases here (ch is a BMP code point or a
180.1709 -            // negative value (invalid code point))
180.1710 -            final char[] value = this.toCharArray();
180.1711 -            final int offset = this.offset();
180.1712 -            int i = offset + Math.min(fromIndex, length() - 1);
180.1713 -            for (; i >= offset ; i--) {
180.1714 -                if (value[i] == ch) {
180.1715 -                    return i - offset;
180.1716 -                }
180.1717 -            }
180.1718 -            return -1;
180.1719 -        } else {
180.1720 -            return lastIndexOfSupplementary(ch, fromIndex);
180.1721 -        }
180.1722 -    }
180.1723 -
180.1724 -    /**
180.1725 -     * Handles (rare) calls of lastIndexOf with a supplementary character.
180.1726 -     */
180.1727 -    private int lastIndexOfSupplementary(int ch, int fromIndex) {
180.1728 -        if (Character.isValidCodePoint(ch)) {
180.1729 -            final char[] value = this.toCharArray();
180.1730 -            final int offset = this.offset();
180.1731 -            char hi = Character.highSurrogate(ch);
180.1732 -            char lo = Character.lowSurrogate(ch);
180.1733 -            int i = offset + Math.min(fromIndex, length() - 2);
180.1734 -            for (; i >= offset; i--) {
180.1735 -                if (value[i] == hi && value[i+1] == lo) {
180.1736 -                    return i - offset;
180.1737 -                }
180.1738 -            }
180.1739 -        }
180.1740 -        return -1;
180.1741 -    }
180.1742 -
180.1743 -    /**
180.1744 -     * Returns the index within this string of the first occurrence of the
180.1745 -     * specified substring.
180.1746 -     *
180.1747 -     * <p>The returned index is the smallest value <i>k</i> for which:
180.1748 -     * <blockquote><pre>
180.1749 -     * this.startsWith(str, <i>k</i>)
180.1750 -     * </pre></blockquote>
180.1751 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
180.1752 -     *
180.1753 -     * @param   str   the substring to search for.
180.1754 -     * @return  the index of the first occurrence of the specified substring,
180.1755 -     *          or {@code -1} if there is no such occurrence.
180.1756 -     */
180.1757 -    public int indexOf(String str) {
180.1758 -        return indexOf(str, 0);
180.1759 -    }
180.1760 -
180.1761 -    /**
180.1762 -     * Returns the index within this string of the first occurrence of the
180.1763 -     * specified substring, starting at the specified index.
180.1764 -     *
180.1765 -     * <p>The returned index is the smallest value <i>k</i> for which:
180.1766 -     * <blockquote><pre>
180.1767 -     * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
180.1768 -     * </pre></blockquote>
180.1769 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
180.1770 -     *
180.1771 -     * @param   str         the substring to search for.
180.1772 -     * @param   fromIndex   the index from which to start the search.
180.1773 -     * @return  the index of the first occurrence of the specified substring,
180.1774 -     *          starting at the specified index,
180.1775 -     *          or {@code -1} if there is no such occurrence.
180.1776 -     */
180.1777 -    @JavaScriptBody(args = { "str", "fromIndex" }, body =
180.1778 -        "return this.toString().indexOf(str.toString(), fromIndex);"
180.1779 -    )
180.1780 -    public native int indexOf(String str, int fromIndex);
180.1781 -
180.1782 -    /**
180.1783 -     * Returns the index within this string of the last occurrence of the
180.1784 -     * specified substring.  The last occurrence of the empty string ""
180.1785 -     * is considered to occur at the index value {@code this.length()}.
180.1786 -     *
180.1787 -     * <p>The returned index is the largest value <i>k</i> for which:
180.1788 -     * <blockquote><pre>
180.1789 -     * this.startsWith(str, <i>k</i>)
180.1790 -     * </pre></blockquote>
180.1791 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
180.1792 -     *
180.1793 -     * @param   str   the substring to search for.
180.1794 -     * @return  the index of the last occurrence of the specified substring,
180.1795 -     *          or {@code -1} if there is no such occurrence.
180.1796 -     */
180.1797 -    public int lastIndexOf(String str) {
180.1798 -        return lastIndexOf(str, length());
180.1799 -    }
180.1800 -
180.1801 -    /**
180.1802 -     * Returns the index within this string of the last occurrence of the
180.1803 -     * specified substring, searching backward starting at the specified index.
180.1804 -     *
180.1805 -     * <p>The returned index is the largest value <i>k</i> for which:
180.1806 -     * <blockquote><pre>
180.1807 -     * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
180.1808 -     * </pre></blockquote>
180.1809 -     * If no such value of <i>k</i> exists, then {@code -1} is returned.
180.1810 -     *
180.1811 -     * @param   str         the substring to search for.
180.1812 -     * @param   fromIndex   the index to start the search from.
180.1813 -     * @return  the index of the last occurrence of the specified substring,
180.1814 -     *          searching backward from the specified index,
180.1815 -     *          or {@code -1} if there is no such occurrence.
180.1816 -     */
180.1817 -    @JavaScriptBody(args = { "s", "from" }, body = 
180.1818 -        "return this.toString().lastIndexOf(s.toString(), from);"
180.1819 -    )
180.1820 -    public int lastIndexOf(String str, int fromIndex) {
180.1821 -        return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
180.1822 -    }
180.1823 -
180.1824 -    /**
180.1825 -     * Code shared by String and StringBuffer to do searches. The
180.1826 -     * source is the character array being searched, and the target
180.1827 -     * is the string being searched for.
180.1828 -     *
180.1829 -     * @param   source       the characters being searched.
180.1830 -     * @param   sourceOffset offset of the source string.
180.1831 -     * @param   sourceCount  count of the source string.
180.1832 -     * @param   target       the characters being searched for.
180.1833 -     * @param   targetOffset offset of the target string.
180.1834 -     * @param   targetCount  count of the target string.
180.1835 -     * @param   fromIndex    the index to begin searching from.
180.1836 -     */
180.1837 -    static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
180.1838 -                           char[] target, int targetOffset, int targetCount,
180.1839 -                           int fromIndex) {
180.1840 -        /*
180.1841 -         * Check arguments; return immediately where possible. For
180.1842 -         * consistency, don't check for null str.
180.1843 -         */
180.1844 -        int rightIndex = sourceCount - targetCount;
180.1845 -        if (fromIndex < 0) {
180.1846 -            return -1;
180.1847 -        }
180.1848 -        if (fromIndex > rightIndex) {
180.1849 -            fromIndex = rightIndex;
180.1850 -        }
180.1851 -        /* Empty string always matches. */
180.1852 -        if (targetCount == 0) {
180.1853 -            return fromIndex;
180.1854 -        }
180.1855 -
180.1856 -        int strLastIndex = targetOffset + targetCount - 1;
180.1857 -        char strLastChar = target[strLastIndex];
180.1858 -        int min = sourceOffset + targetCount - 1;
180.1859 -        int i = min + fromIndex;
180.1860 -
180.1861 -    startSearchForLastChar:
180.1862 -        while (true) {
180.1863 -            while (i >= min && source[i] != strLastChar) {
180.1864 -                i--;
180.1865 -            }
180.1866 -            if (i < min) {
180.1867 -                return -1;
180.1868 -            }
180.1869 -            int j = i - 1;
180.1870 -            int start = j - (targetCount - 1);
180.1871 -            int k = strLastIndex - 1;
180.1872 -
180.1873 -            while (j > start) {
180.1874 -                if (source[j--] != target[k--]) {
180.1875 -                    i--;
180.1876 -                    continue startSearchForLastChar;
180.1877 -                }
180.1878 -            }
180.1879 -            return start - sourceOffset + 1;
180.1880 -        }
180.1881 -    }
180.1882 -
180.1883 -    /**
180.1884 -     * Returns a new string that is a substring of this string. The
180.1885 -     * substring begins with the character at the specified index and
180.1886 -     * extends to the end of this string. <p>
180.1887 -     * Examples:
180.1888 -     * <blockquote><pre>
180.1889 -     * "unhappy".substring(2) returns "happy"
180.1890 -     * "Harbison".substring(3) returns "bison"
180.1891 -     * "emptiness".substring(9) returns "" (an empty string)
180.1892 -     * </pre></blockquote>
180.1893 -     *
180.1894 -     * @param      beginIndex   the beginning index, inclusive.
180.1895 -     * @return     the specified substring.
180.1896 -     * @exception  IndexOutOfBoundsException  if
180.1897 -     *             <code>beginIndex</code> is negative or larger than the
180.1898 -     *             length of this <code>String</code> object.
180.1899 -     */
180.1900 -    public String substring(int beginIndex) {
180.1901 -        return substring(beginIndex, length());
180.1902 -    }
180.1903 -
180.1904 -    /**
180.1905 -     * Returns a new string that is a substring of this string. The
180.1906 -     * substring begins at the specified <code>beginIndex</code> and
180.1907 -     * extends to the character at index <code>endIndex - 1</code>.
180.1908 -     * Thus the length of the substring is <code>endIndex-beginIndex</code>.
180.1909 -     * <p>
180.1910 -     * Examples:
180.1911 -     * <blockquote><pre>
180.1912 -     * "hamburger".substring(4, 8) returns "urge"
180.1913 -     * "smiles".substring(1, 5) returns "mile"
180.1914 -     * </pre></blockquote>
180.1915 -     *
180.1916 -     * @param      beginIndex   the beginning index, inclusive.
180.1917 -     * @param      endIndex     the ending index, exclusive.
180.1918 -     * @return     the specified substring.
180.1919 -     * @exception  IndexOutOfBoundsException  if the
180.1920 -     *             <code>beginIndex</code> is negative, or
180.1921 -     *             <code>endIndex</code> is larger than the length of
180.1922 -     *             this <code>String</code> object, or
180.1923 -     *             <code>beginIndex</code> is larger than
180.1924 -     *             <code>endIndex</code>.
180.1925 -     */
180.1926 -    @JavaScriptBody(args = { "beginIndex", "endIndex" }, body = 
180.1927 -        "return this.toString().substring(beginIndex, endIndex);"
180.1928 -    )
180.1929 -    public String substring(int beginIndex, int endIndex) {
180.1930 -        if (beginIndex < 0) {
180.1931 -            throw new StringIndexOutOfBoundsException(beginIndex);
180.1932 -        }
180.1933 -        if (endIndex > length()) {
180.1934 -            throw new StringIndexOutOfBoundsException(endIndex);
180.1935 -        }
180.1936 -        if (beginIndex > endIndex) {
180.1937 -            throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
180.1938 -        }
180.1939 -        return ((beginIndex == 0) && (endIndex == length())) ? this :
180.1940 -            new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
180.1941 -    }
180.1942 -
180.1943 -    /**
180.1944 -     * Returns a new character sequence that is a subsequence of this sequence.
180.1945 -     *
180.1946 -     * <p> An invocation of this method of the form
180.1947 -     *
180.1948 -     * <blockquote><pre>
180.1949 -     * str.subSequence(begin,&nbsp;end)</pre></blockquote>
180.1950 -     *
180.1951 -     * behaves in exactly the same way as the invocation
180.1952 -     *
180.1953 -     * <blockquote><pre>
180.1954 -     * str.substring(begin,&nbsp;end)</pre></blockquote>
180.1955 -     *
180.1956 -     * This method is defined so that the <tt>String</tt> class can implement
180.1957 -     * the {@link CharSequence} interface. </p>
180.1958 -     *
180.1959 -     * @param      beginIndex   the begin index, inclusive.
180.1960 -     * @param      endIndex     the end index, exclusive.
180.1961 -     * @return     the specified subsequence.
180.1962 -     *
180.1963 -     * @throws  IndexOutOfBoundsException
180.1964 -     *          if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
180.1965 -     *          if <tt>endIndex</tt> is greater than <tt>length()</tt>,
180.1966 -     *          or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
180.1967 -     *
180.1968 -     * @since 1.4
180.1969 -     * @spec JSR-51
180.1970 -     */
180.1971 -    public CharSequence subSequence(int beginIndex, int endIndex) {
180.1972 -        return this.substring(beginIndex, endIndex);
180.1973 -    }
180.1974 -
180.1975 -    /**
180.1976 -     * Concatenates the specified string to the end of this string.
180.1977 -     * <p>
180.1978 -     * If the length of the argument string is <code>0</code>, then this
180.1979 -     * <code>String</code> object is returned. Otherwise, a new
180.1980 -     * <code>String</code> object is created, representing a character
180.1981 -     * sequence that is the concatenation of the character sequence
180.1982 -     * represented by this <code>String</code> object and the character
180.1983 -     * sequence represented by the argument string.<p>
180.1984 -     * Examples:
180.1985 -     * <blockquote><pre>
180.1986 -     * "cares".concat("s") returns "caress"
180.1987 -     * "to".concat("get").concat("her") returns "together"
180.1988 -     * </pre></blockquote>
180.1989 -     *
180.1990 -     * @param   str   the <code>String</code> that is concatenated to the end
180.1991 -     *                of this <code>String</code>.
180.1992 -     * @return  a string that represents the concatenation of this object's
180.1993 -     *          characters followed by the string argument's characters.
180.1994 -     */
180.1995 -    public String concat(String str) {
180.1996 -        int otherLen = str.length();
180.1997 -        if (otherLen == 0) {
180.1998 -            return this;
180.1999 -        }
180.2000 -        char buf[] = new char[length() + otherLen];
180.2001 -        getChars(0, length(), buf, 0);
180.2002 -        str.getChars(0, otherLen, buf, length());
180.2003 -        return new String(buf, 0, length() + otherLen);
180.2004 -    }
180.2005 -
180.2006 -    /**
180.2007 -     * Returns a new string resulting from replacing all occurrences of
180.2008 -     * <code>oldChar</code> in this string with <code>newChar</code>.
180.2009 -     * <p>
180.2010 -     * If the character <code>oldChar</code> does not occur in the
180.2011 -     * character sequence represented by this <code>String</code> object,
180.2012 -     * then a reference to this <code>String</code> object is returned.
180.2013 -     * Otherwise, a new <code>String</code> object is created that
180.2014 -     * represents a character sequence identical to the character sequence
180.2015 -     * represented by this <code>String</code> object, except that every
180.2016 -     * occurrence of <code>oldChar</code> is replaced by an occurrence
180.2017 -     * of <code>newChar</code>.
180.2018 -     * <p>
180.2019 -     * Examples:
180.2020 -     * <blockquote><pre>
180.2021 -     * "mesquite in your cellar".replace('e', 'o')
180.2022 -     *         returns "mosquito in your collar"
180.2023 -     * "the war of baronets".replace('r', 'y')
180.2024 -     *         returns "the way of bayonets"
180.2025 -     * "sparring with a purple porpoise".replace('p', 't')
180.2026 -     *         returns "starring with a turtle tortoise"
180.2027 -     * "JonL".replace('q', 'x') returns "JonL" (no change)
180.2028 -     * </pre></blockquote>
180.2029 -     *
180.2030 -     * @param   oldChar   the old character.
180.2031 -     * @param   newChar   the new character.
180.2032 -     * @return  a string derived from this string by replacing every
180.2033 -     *          occurrence of <code>oldChar</code> with <code>newChar</code>.
180.2034 -     */
180.2035 -    @JavaScriptBody(args = { "arg1", "arg2" }, body =
180.2036 -        "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
180.2037 -        "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
180.2038 -        "var s = this.toString();\n" +
180.2039 -        "for (;;) {\n" +
180.2040 -        "  var ret = s.replace(arg1, arg2);\n" +
180.2041 -        "  if (ret === s) {\n" +
180.2042 -        "    return ret;\n" +
180.2043 -        "  }\n" +
180.2044 -        "  s = ret;\n" +
180.2045 -        "}"
180.2046 -    )
180.2047 -    public String replace(char oldChar, char newChar) {
180.2048 -        if (oldChar != newChar) {
180.2049 -            int len = length();
180.2050 -            int i = -1;
180.2051 -            char[] val = toCharArray(); /* avoid getfield opcode */
180.2052 -            int off = offset();   /* avoid getfield opcode */
180.2053 -
180.2054 -            while (++i < len) {
180.2055 -                if (val[off + i] == oldChar) {
180.2056 -                    break;
180.2057 -                }
180.2058 -            }
180.2059 -            if (i < len) {
180.2060 -                char buf[] = new char[len];
180.2061 -                for (int j = 0 ; j < i ; j++) {
180.2062 -                    buf[j] = val[off+j];
180.2063 -                }
180.2064 -                while (i < len) {
180.2065 -                    char c = val[off + i];
180.2066 -                    buf[i] = (c == oldChar) ? newChar : c;
180.2067 -                    i++;
180.2068 -                }
180.2069 -                return new String(buf, 0, len);
180.2070 -            }
180.2071 -        }
180.2072 -        return this;
180.2073 -    }
180.2074 -
180.2075 -    /**
180.2076 -     * Tells whether or not this string matches the given <a
180.2077 -     * href="../util/regex/Pattern.html#sum">regular expression</a>.
180.2078 -     *
180.2079 -     * <p> An invocation of this method of the form
180.2080 -     * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
180.2081 -     * same result as the expression
180.2082 -     *
180.2083 -     * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
180.2084 -     * java.util.regex.Pattern#matches(String,CharSequence)
180.2085 -     * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
180.2086 -     *
180.2087 -     * @param   regex
180.2088 -     *          the regular expression to which this string is to be matched
180.2089 -     *
180.2090 -     * @return  <tt>true</tt> if, and only if, this string matches the
180.2091 -     *          given regular expression
180.2092 -     *
180.2093 -     * @throws  PatternSyntaxException
180.2094 -     *          if the regular expression's syntax is invalid
180.2095 -     *
180.2096 -     * @see java.util.regex.Pattern
180.2097 -     *
180.2098 -     * @since 1.4
180.2099 -     * @spec JSR-51
180.2100 -     */
180.2101 -    @JavaScriptBody(args = { "regex" }, body = 
180.2102 -          "var self = this.toString();\n"
180.2103 -        + "var re = new RegExp(regex.toString());\n"
180.2104 -        + "var r = re.exec(self);\n"
180.2105 -        + "return r != null && r.length > 0 && self.length == r[0].length;"
180.2106 -    )
180.2107 -    public boolean matches(String regex) {
180.2108 -        throw new UnsupportedOperationException();
180.2109 -    }
180.2110 -
180.2111 -    /**
180.2112 -     * Returns true if and only if this string contains the specified
180.2113 -     * sequence of char values.
180.2114 -     *
180.2115 -     * @param s the sequence to search for
180.2116 -     * @return true if this string contains <code>s</code>, false otherwise
180.2117 -     * @throws NullPointerException if <code>s</code> is <code>null</code>
180.2118 -     * @since 1.5
180.2119 -     */
180.2120 -    public boolean contains(CharSequence s) {
180.2121 -        return indexOf(s.toString()) > -1;
180.2122 -    }
180.2123 -
180.2124 -    /**
180.2125 -     * Replaces the first substring of this string that matches the given <a
180.2126 -     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
180.2127 -     * given replacement.
180.2128 -     *
180.2129 -     * <p> An invocation of this method of the form
180.2130 -     * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
180.2131 -     * yields exactly the same result as the expression
180.2132 -     *
180.2133 -     * <blockquote><tt>
180.2134 -     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
180.2135 -     * compile}(</tt><i>regex</i><tt>).{@link
180.2136 -     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
180.2137 -     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
180.2138 -     * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
180.2139 -     *
180.2140 -     *<p>
180.2141 -     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
180.2142 -     * replacement string may cause the results to be different than if it were
180.2143 -     * being treated as a literal replacement string; see
180.2144 -     * {@link java.util.regex.Matcher#replaceFirst}.
180.2145 -     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
180.2146 -     * meaning of these characters, if desired.
180.2147 -     *
180.2148 -     * @param   regex
180.2149 -     *          the regular expression to which this string is to be matched
180.2150 -     * @param   replacement
180.2151 -     *          the string to be substituted for the first match
180.2152 -     *
180.2153 -     * @return  The resulting <tt>String</tt>
180.2154 -     *
180.2155 -     * @throws  PatternSyntaxException
180.2156 -     *          if the regular expression's syntax is invalid
180.2157 -     *
180.2158 -     * @see java.util.regex.Pattern
180.2159 -     *
180.2160 -     * @since 1.4
180.2161 -     * @spec JSR-51
180.2162 -     */
180.2163 -    public String replaceFirst(String regex, String replacement) {
180.2164 -        throw new UnsupportedOperationException();
180.2165 -    }
180.2166 -
180.2167 -    /**
180.2168 -     * Replaces each substring of this string that matches the given <a
180.2169 -     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
180.2170 -     * given replacement.
180.2171 -     *
180.2172 -     * <p> An invocation of this method of the form
180.2173 -     * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
180.2174 -     * yields exactly the same result as the expression
180.2175 -     *
180.2176 -     * <blockquote><tt>
180.2177 -     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
180.2178 -     * compile}(</tt><i>regex</i><tt>).{@link
180.2179 -     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
180.2180 -     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
180.2181 -     * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
180.2182 -     *
180.2183 -     *<p>
180.2184 -     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
180.2185 -     * replacement string may cause the results to be different than if it were
180.2186 -     * being treated as a literal replacement string; see
180.2187 -     * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
180.2188 -     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
180.2189 -     * meaning of these characters, if desired.
180.2190 -     *
180.2191 -     * @param   regex
180.2192 -     *          the regular expression to which this string is to be matched
180.2193 -     * @param   replacement
180.2194 -     *          the string to be substituted for each match
180.2195 -     *
180.2196 -     * @return  The resulting <tt>String</tt>
180.2197 -     *
180.2198 -     * @throws  PatternSyntaxException
180.2199 -     *          if the regular expression's syntax is invalid
180.2200 -     *
180.2201 -     * @see java.util.regex.Pattern
180.2202 -     *
180.2203 -     * @since 1.4
180.2204 -     * @spec JSR-51
180.2205 -     */
180.2206 -    public String replaceAll(String regex, String replacement) {
180.2207 -        throw new UnsupportedOperationException();
180.2208 -    }
180.2209 -
180.2210 -    /**
180.2211 -     * Replaces each substring of this string that matches the literal target
180.2212 -     * sequence with the specified literal replacement sequence. The
180.2213 -     * replacement proceeds from the beginning of the string to the end, for
180.2214 -     * example, replacing "aa" with "b" in the string "aaa" will result in
180.2215 -     * "ba" rather than "ab".
180.2216 -     *
180.2217 -     * @param  target The sequence of char values to be replaced
180.2218 -     * @param  replacement The replacement sequence of char values
180.2219 -     * @return  The resulting string
180.2220 -     * @throws NullPointerException if <code>target</code> or
180.2221 -     *         <code>replacement</code> is <code>null</code>.
180.2222 -     * @since 1.5
180.2223 -     */
180.2224 -    public String replace(CharSequence target, CharSequence replacement) {
180.2225 -        throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
180.2226 -    }
180.2227 -
180.2228 -    /**
180.2229 -     * Splits this string around matches of the given
180.2230 -     * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
180.2231 -     *
180.2232 -     * <p> The array returned by this method contains each substring of this
180.2233 -     * string that is terminated by another substring that matches the given
180.2234 -     * expression or is terminated by the end of the string.  The substrings in
180.2235 -     * the array are in the order in which they occur in this string.  If the
180.2236 -     * expression does not match any part of the input then the resulting array
180.2237 -     * has just one element, namely this string.
180.2238 -     *
180.2239 -     * <p> The <tt>limit</tt> parameter controls the number of times the
180.2240 -     * pattern is applied and therefore affects the length of the resulting
180.2241 -     * array.  If the limit <i>n</i> is greater than zero then the pattern
180.2242 -     * will be applied at most <i>n</i>&nbsp;-&nbsp;1 times, the array's
180.2243 -     * length will be no greater than <i>n</i>, and the array's last entry
180.2244 -     * will contain all input beyond the last matched delimiter.  If <i>n</i>
180.2245 -     * is non-positive then the pattern will be applied as many times as
180.2246 -     * possible and the array can have any length.  If <i>n</i> is zero then
180.2247 -     * the pattern will be applied as many times as possible, the array can
180.2248 -     * have any length, and trailing empty strings will be discarded.
180.2249 -     *
180.2250 -     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
180.2251 -     * following results with these parameters:
180.2252 -     *
180.2253 -     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
180.2254 -     * <tr>
180.2255 -     *     <th>Regex</th>
180.2256 -     *     <th>Limit</th>
180.2257 -     *     <th>Result</th>
180.2258 -     * </tr>
180.2259 -     * <tr><td align=center>:</td>
180.2260 -     *     <td align=center>2</td>
180.2261 -     *     <td><tt>{ "boo", "and:foo" }</tt></td></tr>
180.2262 -     * <tr><td align=center>:</td>
180.2263 -     *     <td align=center>5</td>
180.2264 -     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
180.2265 -     * <tr><td align=center>:</td>
180.2266 -     *     <td align=center>-2</td>
180.2267 -     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
180.2268 -     * <tr><td align=center>o</td>
180.2269 -     *     <td align=center>5</td>
180.2270 -     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
180.2271 -     * <tr><td align=center>o</td>
180.2272 -     *     <td align=center>-2</td>
180.2273 -     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
180.2274 -     * <tr><td align=center>o</td>
180.2275 -     *     <td align=center>0</td>
180.2276 -     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
180.2277 -     * </table></blockquote>
180.2278 -     *
180.2279 -     * <p> An invocation of this method of the form
180.2280 -     * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
180.2281 -     * yields the same result as the expression
180.2282 -     *
180.2283 -     * <blockquote>
180.2284 -     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
180.2285 -     * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
180.2286 -     * java.util.regex.Pattern#split(java.lang.CharSequence,int)
180.2287 -     * split}<tt>(</tt><i>str</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
180.2288 -     * </blockquote>
180.2289 -     *
180.2290 -     *
180.2291 -     * @param  regex
180.2292 -     *         the delimiting regular expression
180.2293 -     *
180.2294 -     * @param  limit
180.2295 -     *         the result threshold, as described above
180.2296 -     *
180.2297 -     * @return  the array of strings computed by splitting this string
180.2298 -     *          around matches of the given regular expression
180.2299 -     *
180.2300 -     * @throws  PatternSyntaxException
180.2301 -     *          if the regular expression's syntax is invalid
180.2302 -     *
180.2303 -     * @see java.util.regex.Pattern
180.2304 -     *
180.2305 -     * @since 1.4
180.2306 -     * @spec JSR-51
180.2307 -     */
180.2308 -    public String[] split(String regex, int limit) {
180.2309 -        throw new UnsupportedOperationException("Needs regexp");
180.2310 -    }
180.2311 -
180.2312 -    /**
180.2313 -     * Splits this string around matches of the given <a
180.2314 -     * href="../util/regex/Pattern.html#sum">regular expression</a>.
180.2315 -     *
180.2316 -     * <p> This method works as if by invoking the two-argument {@link
180.2317 -     * #split(String, int) split} method with the given expression and a limit
180.2318 -     * argument of zero.  Trailing empty strings are therefore not included in
180.2319 -     * the resulting array.
180.2320 -     *
180.2321 -     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
180.2322 -     * results with these expressions:
180.2323 -     *
180.2324 -     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
180.2325 -     * <tr>
180.2326 -     *  <th>Regex</th>
180.2327 -     *  <th>Result</th>
180.2328 -     * </tr>
180.2329 -     * <tr><td align=center>:</td>
180.2330 -     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
180.2331 -     * <tr><td align=center>o</td>
180.2332 -     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
180.2333 -     * </table></blockquote>
180.2334 -     *
180.2335 -     *
180.2336 -     * @param  regex
180.2337 -     *         the delimiting regular expression
180.2338 -     *
180.2339 -     * @return  the array of strings computed by splitting this string
180.2340 -     *          around matches of the given regular expression
180.2341 -     *
180.2342 -     * @throws  PatternSyntaxException
180.2343 -     *          if the regular expression's syntax is invalid
180.2344 -     *
180.2345 -     * @see java.util.regex.Pattern
180.2346 -     *
180.2347 -     * @since 1.4
180.2348 -     * @spec JSR-51
180.2349 -     */
180.2350 -    public String[] split(String regex) {
180.2351 -        return split(regex, 0);
180.2352 -    }
180.2353 -
180.2354 -    /**
180.2355 -     * Converts all of the characters in this <code>String</code> to lower
180.2356 -     * case using the rules of the given <code>Locale</code>.  Case mapping is based
180.2357 -     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
180.2358 -     * class. Since case mappings are not always 1:1 char mappings, the resulting
180.2359 -     * <code>String</code> may be a different length than the original <code>String</code>.
180.2360 -     * <p>
180.2361 -     * Examples of lowercase  mappings are in the following table:
180.2362 -     * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
180.2363 -     * <tr>
180.2364 -     *   <th>Language Code of Locale</th>
180.2365 -     *   <th>Upper Case</th>
180.2366 -     *   <th>Lower Case</th>
180.2367 -     *   <th>Description</th>
180.2368 -     * </tr>
180.2369 -     * <tr>
180.2370 -     *   <td>tr (Turkish)</td>
180.2371 -     *   <td>&#92;u0130</td>
180.2372 -     *   <td>&#92;u0069</td>
180.2373 -     *   <td>capital letter I with dot above -&gt; small letter i</td>
180.2374 -     * </tr>
180.2375 -     * <tr>
180.2376 -     *   <td>tr (Turkish)</td>
180.2377 -     *   <td>&#92;u0049</td>
180.2378 -     *   <td>&#92;u0131</td>
180.2379 -     *   <td>capital letter I -&gt; small letter dotless i </td>
180.2380 -     * </tr>
180.2381 -     * <tr>
180.2382 -     *   <td>(all)</td>
180.2383 -     *   <td>French Fries</td>
180.2384 -     *   <td>french fries</td>
180.2385 -     *   <td>lowercased all chars in String</td>
180.2386 -     * </tr>
180.2387 -     * <tr>
180.2388 -     *   <td>(all)</td>
180.2389 -     *   <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
180.2390 -     *       <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
180.2391 -     *       <img src="doc-files/capsigma.gif" alt="capsigma"></td>
180.2392 -     *   <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
180.2393 -     *       <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
180.2394 -     *       <img src="doc-files/sigma1.gif" alt="sigma"></td>
180.2395 -     *   <td>lowercased all chars in String</td>
180.2396 -     * </tr>
180.2397 -     * </table>
180.2398 -     *
180.2399 -     * @param locale use the case transformation rules for this locale
180.2400 -     * @return the <code>String</code>, converted to lowercase.
180.2401 -     * @see     java.lang.String#toLowerCase()
180.2402 -     * @see     java.lang.String#toUpperCase()
180.2403 -     * @see     java.lang.String#toUpperCase(Locale)
180.2404 -     * @since   1.1
180.2405 -     */
180.2406 -//    public String toLowerCase(Locale locale) {
180.2407 -//        if (locale == null) {
180.2408 -//            throw new NullPointerException();
180.2409 -//        }
180.2410 -//
180.2411 -//        int     firstUpper;
180.2412 -//
180.2413 -//        /* Now check if there are any characters that need to be changed. */
180.2414 -//        scan: {
180.2415 -//            for (firstUpper = 0 ; firstUpper < count; ) {
180.2416 -//                char c = value[offset+firstUpper];
180.2417 -//                if ((c >= Character.MIN_HIGH_SURROGATE) &&
180.2418 -//                    (c <= Character.MAX_HIGH_SURROGATE)) {
180.2419 -//                    int supplChar = codePointAt(firstUpper);
180.2420 -//                    if (supplChar != Character.toLowerCase(supplChar)) {
180.2421 -//                        break scan;
180.2422 -//                    }
180.2423 -//                    firstUpper += Character.charCount(supplChar);
180.2424 -//                } else {
180.2425 -//                    if (c != Character.toLowerCase(c)) {
180.2426 -//                        break scan;
180.2427 -//                    }
180.2428 -//                    firstUpper++;
180.2429 -//                }
180.2430 -//            }
180.2431 -//            return this;
180.2432 -//        }
180.2433 -//
180.2434 -//        char[]  result = new char[count];
180.2435 -//        int     resultOffset = 0;  /* result may grow, so i+resultOffset
180.2436 -//                                    * is the write location in result */
180.2437 -//
180.2438 -//        /* Just copy the first few lowerCase characters. */
180.2439 -//        System.arraycopy(value, offset, result, 0, firstUpper);
180.2440 -//
180.2441 -//        String lang = locale.getLanguage();
180.2442 -//        boolean localeDependent =
180.2443 -//            (lang == "tr" || lang == "az" || lang == "lt");
180.2444 -//        char[] lowerCharArray;
180.2445 -//        int lowerChar;
180.2446 -//        int srcChar;
180.2447 -//        int srcCount;
180.2448 -//        for (int i = firstUpper; i < count; i += srcCount) {
180.2449 -//            srcChar = (int)value[offset+i];
180.2450 -//            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
180.2451 -//                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
180.2452 -//                srcChar = codePointAt(i);
180.2453 -//                srcCount = Character.charCount(srcChar);
180.2454 -//            } else {
180.2455 -//                srcCount = 1;
180.2456 -//            }
180.2457 -//            if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
180.2458 -//                lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
180.2459 -//            } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
180.2460 -//                lowerChar = Character.ERROR;
180.2461 -//            } else {
180.2462 -//                lowerChar = Character.toLowerCase(srcChar);
180.2463 -//            }
180.2464 -//            if ((lowerChar == Character.ERROR) ||
180.2465 -//                (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
180.2466 -//                if (lowerChar == Character.ERROR) {
180.2467 -//                     if (!localeDependent && srcChar == '\u0130') {
180.2468 -//                         lowerCharArray =
180.2469 -//                             ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
180.2470 -//                     } else {
180.2471 -//                        lowerCharArray =
180.2472 -//                            ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
180.2473 -//                     }
180.2474 -//                } else if (srcCount == 2) {
180.2475 -//                    resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
180.2476 -//                    continue;
180.2477 -//                } else {
180.2478 -//                    lowerCharArray = Character.toChars(lowerChar);
180.2479 -//                }
180.2480 -//
180.2481 -//                /* Grow result if needed */
180.2482 -//                int mapLen = lowerCharArray.length;
180.2483 -//                if (mapLen > srcCount) {
180.2484 -//                    char[] result2 = new char[result.length + mapLen - srcCount];
180.2485 -//                    System.arraycopy(result, 0, result2, 0,
180.2486 -//                        i + resultOffset);
180.2487 -//                    result = result2;
180.2488 -//                }
180.2489 -//                for (int x=0; x<mapLen; ++x) {
180.2490 -//                    result[i+resultOffset+x] = lowerCharArray[x];
180.2491 -//                }
180.2492 -//                resultOffset += (mapLen - srcCount);
180.2493 -//            } else {
180.2494 -//                result[i+resultOffset] = (char)lowerChar;
180.2495 -//            }
180.2496 -//        }
180.2497 -//        return new String(0, count+resultOffset, result);
180.2498 -//    }
180.2499 -
180.2500 -    /**
180.2501 -     * Converts all of the characters in this <code>String</code> to lower
180.2502 -     * case using the rules of the default locale. This is equivalent to calling
180.2503 -     * <code>toLowerCase(Locale.getDefault())</code>.
180.2504 -     * <p>
180.2505 -     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
180.2506 -     * results if used for strings that are intended to be interpreted locale
180.2507 -     * independently.
180.2508 -     * Examples are programming language identifiers, protocol keys, and HTML
180.2509 -     * tags.
180.2510 -     * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
180.2511 -     * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
180.2512 -     * LATIN SMALL LETTER DOTLESS I character.
180.2513 -     * To obtain correct results for locale insensitive strings, use
180.2514 -     * <code>toLowerCase(Locale.ENGLISH)</code>.
180.2515 -     * <p>
180.2516 -     * @return  the <code>String</code>, converted to lowercase.
180.2517 -     * @see     java.lang.String#toLowerCase(Locale)
180.2518 -     */
180.2519 -    @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
180.2520 -    public String toLowerCase() {
180.2521 -        throw new UnsupportedOperationException("Should be supported but without connection to locale");
180.2522 -    }
180.2523 -
180.2524 -    /**
180.2525 -     * Converts all of the characters in this <code>String</code> to upper
180.2526 -     * case using the rules of the given <code>Locale</code>. Case mapping is based
180.2527 -     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
180.2528 -     * class. Since case mappings are not always 1:1 char mappings, the resulting
180.2529 -     * <code>String</code> may be a different length than the original <code>String</code>.
180.2530 -     * <p>
180.2531 -     * Examples of locale-sensitive and 1:M case mappings are in the following table.
180.2532 -     * <p>
180.2533 -     * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
180.2534 -     * <tr>
180.2535 -     *   <th>Language Code of Locale</th>
180.2536 -     *   <th>Lower Case</th>
180.2537 -     *   <th>Upper Case</th>
180.2538 -     *   <th>Description</th>
180.2539 -     * </tr>
180.2540 -     * <tr>
180.2541 -     *   <td>tr (Turkish)</td>
180.2542 -     *   <td>&#92;u0069</td>
180.2543 -     *   <td>&#92;u0130</td>
180.2544 -     *   <td>small letter i -&gt; capital letter I with dot above</td>
180.2545 -     * </tr>
180.2546 -     * <tr>
180.2547 -     *   <td>tr (Turkish)</td>
180.2548 -     *   <td>&#92;u0131</td>
180.2549 -     *   <td>&#92;u0049</td>
180.2550 -     *   <td>small letter dotless i -&gt; capital letter I</td>
180.2551 -     * </tr>
180.2552 -     * <tr>
180.2553 -     *   <td>(all)</td>
180.2554 -     *   <td>&#92;u00df</td>
180.2555 -     *   <td>&#92;u0053 &#92;u0053</td>
180.2556 -     *   <td>small letter sharp s -&gt; two letters: SS</td>
180.2557 -     * </tr>
180.2558 -     * <tr>
180.2559 -     *   <td>(all)</td>
180.2560 -     *   <td>Fahrvergn&uuml;gen</td>
180.2561 -     *   <td>FAHRVERGN&Uuml;GEN</td>
180.2562 -     *   <td></td>
180.2563 -     * </tr>
180.2564 -     * </table>
180.2565 -     * @param locale use the case transformation rules for this locale
180.2566 -     * @return the <code>String</code>, converted to uppercase.
180.2567 -     * @see     java.lang.String#toUpperCase()
180.2568 -     * @see     java.lang.String#toLowerCase()
180.2569 -     * @see     java.lang.String#toLowerCase(Locale)
180.2570 -     * @since   1.1
180.2571 -     */
180.2572 -    /* not for javascript 
180.2573 -    public String toUpperCase(Locale locale) {
180.2574 -        if (locale == null) {
180.2575 -            throw new NullPointerException();
180.2576 -        }
180.2577 -
180.2578 -        int     firstLower;
180.2579 -
180.2580 -        // Now check if there are any characters that need to be changed. 
180.2581 -        scan: {
180.2582 -            for (firstLower = 0 ; firstLower < count; ) {
180.2583 -                int c = (int)value[offset+firstLower];
180.2584 -                int srcCount;
180.2585 -                if ((c >= Character.MIN_HIGH_SURROGATE) &&
180.2586 -                    (c <= Character.MAX_HIGH_SURROGATE)) {
180.2587 -                    c = codePointAt(firstLower);
180.2588 -                    srcCount = Character.charCount(c);
180.2589 -                } else {
180.2590 -                    srcCount = 1;
180.2591 -                }
180.2592 -                int upperCaseChar = Character.toUpperCaseEx(c);
180.2593 -                if ((upperCaseChar == Character.ERROR) ||
180.2594 -                    (c != upperCaseChar)) {
180.2595 -                    break scan;
180.2596 -                }
180.2597 -                firstLower += srcCount;
180.2598 -            }
180.2599 -            return this;
180.2600 -        }
180.2601 -
180.2602 -        char[]  result       = new char[count]; /* may grow *
180.2603 -        int     resultOffset = 0;  /* result may grow, so i+resultOffset
180.2604 -                                    * is the write location in result *
180.2605 -
180.2606 -        /* Just copy the first few upperCase characters. *
180.2607 -        System.arraycopy(value, offset, result, 0, firstLower);
180.2608 -
180.2609 -        String lang = locale.getLanguage();
180.2610 -        boolean localeDependent =
180.2611 -            (lang == "tr" || lang == "az" || lang == "lt");
180.2612 -        char[] upperCharArray;
180.2613 -        int upperChar;
180.2614 -        int srcChar;
180.2615 -        int srcCount;
180.2616 -        for (int i = firstLower; i < count; i += srcCount) {
180.2617 -            srcChar = (int)value[offset+i];
180.2618 -            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
180.2619 -                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
180.2620 -                srcChar = codePointAt(i);
180.2621 -                srcCount = Character.charCount(srcChar);
180.2622 -            } else {
180.2623 -                srcCount = 1;
180.2624 -            }
180.2625 -            if (localeDependent) {
180.2626 -                upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
180.2627 -            } else {
180.2628 -                upperChar = Character.toUpperCaseEx(srcChar);
180.2629 -            }
180.2630 -            if ((upperChar == Character.ERROR) ||
180.2631 -                (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
180.2632 -                if (upperChar == Character.ERROR) {
180.2633 -                    if (localeDependent) {
180.2634 -                        upperCharArray =
180.2635 -                            ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
180.2636 -                    } else {
180.2637 -                        upperCharArray = Character.toUpperCaseCharArray(srcChar);
180.2638 -                    }
180.2639 -                } else if (srcCount == 2) {
180.2640 -                    resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
180.2641 -                    continue;
180.2642 -                } else {
180.2643 -                    upperCharArray = Character.toChars(upperChar);
180.2644 -                }
180.2645 -
180.2646 -                /* Grow result if needed *
180.2647 -                int mapLen = upperCharArray.length;
180.2648 -                if (mapLen > srcCount) {
180.2649 -                    char[] result2 = new char[result.length + mapLen - srcCount];
180.2650 -                    System.arraycopy(result, 0, result2, 0,
180.2651 -                        i + resultOffset);
180.2652 -                    result = result2;
180.2653 -                }
180.2654 -                for (int x=0; x<mapLen; ++x) {
180.2655 -                    result[i+resultOffset+x] = upperCharArray[x];
180.2656 -                }
180.2657 -                resultOffset += (mapLen - srcCount);
180.2658 -            } else {
180.2659 -                result[i+resultOffset] = (char)upperChar;
180.2660 -            }
180.2661 -        }
180.2662 -        return new String(0, count+resultOffset, result);
180.2663 -    }
180.2664 -    */
180.2665 -
180.2666 -    /**
180.2667 -     * Converts all of the characters in this <code>String</code> to upper
180.2668 -     * case using the rules of the default locale. This method is equivalent to
180.2669 -     * <code>toUpperCase(Locale.getDefault())</code>.
180.2670 -     * <p>
180.2671 -     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
180.2672 -     * results if used for strings that are intended to be interpreted locale
180.2673 -     * independently.
180.2674 -     * Examples are programming language identifiers, protocol keys, and HTML
180.2675 -     * tags.
180.2676 -     * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
180.2677 -     * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
180.2678 -     * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
180.2679 -     * To obtain correct results for locale insensitive strings, use
180.2680 -     * <code>toUpperCase(Locale.ENGLISH)</code>.
180.2681 -     * <p>
180.2682 -     * @return  the <code>String</code>, converted to uppercase.
180.2683 -     * @see     java.lang.String#toUpperCase(Locale)
180.2684 -     */
180.2685 -    @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
180.2686 -    public String toUpperCase() {
180.2687 -        throw new UnsupportedOperationException();
180.2688 -    }
180.2689 -
180.2690 -    /**
180.2691 -     * Returns a copy of the string, with leading and trailing whitespace
180.2692 -     * omitted.
180.2693 -     * <p>
180.2694 -     * If this <code>String</code> object represents an empty character
180.2695 -     * sequence, or the first and last characters of character sequence
180.2696 -     * represented by this <code>String</code> object both have codes
180.2697 -     * greater than <code>'&#92;u0020'</code> (the space character), then a
180.2698 -     * reference to this <code>String</code> object is returned.
180.2699 -     * <p>
180.2700 -     * Otherwise, if there is no character with a code greater than
180.2701 -     * <code>'&#92;u0020'</code> in the string, then a new
180.2702 -     * <code>String</code> object representing an empty string is created
180.2703 -     * and returned.
180.2704 -     * <p>
180.2705 -     * Otherwise, let <i>k</i> be the index of the first character in the
180.2706 -     * string whose code is greater than <code>'&#92;u0020'</code>, and let
180.2707 -     * <i>m</i> be the index of the last character in the string whose code
180.2708 -     * is greater than <code>'&#92;u0020'</code>. A new <code>String</code>
180.2709 -     * object is created, representing the substring of this string that
180.2710 -     * begins with the character at index <i>k</i> and ends with the
180.2711 -     * character at index <i>m</i>-that is, the result of
180.2712 -     * <code>this.substring(<i>k</i>,&nbsp;<i>m</i>+1)</code>.
180.2713 -     * <p>
180.2714 -     * This method may be used to trim whitespace (as defined above) from
180.2715 -     * the beginning and end of a string.
180.2716 -     *
180.2717 -     * @return  A copy of this string with leading and trailing white
180.2718 -     *          space removed, or this string if it has no leading or
180.2719 -     *          trailing white space.
180.2720 -     */
180.2721 -    public String trim() {
180.2722 -        int len = length();
180.2723 -        int st = 0;
180.2724 -        int off = offset();      /* avoid getfield opcode */
180.2725 -        char[] val = toCharArray();    /* avoid getfield opcode */
180.2726 -
180.2727 -        while ((st < len) && (val[off + st] <= ' ')) {
180.2728 -            st++;
180.2729 -        }
180.2730 -        while ((st < len) && (val[off + len - 1] <= ' ')) {
180.2731 -            len--;
180.2732 -        }
180.2733 -        return ((st > 0) || (len < length())) ? substring(st, len) : this;
180.2734 -    }
180.2735 -
180.2736 -    /**
180.2737 -     * This object (which is already a string!) is itself returned.
180.2738 -     *
180.2739 -     * @return  the string itself.
180.2740 -     */
180.2741 -    @JavaScriptBody(args = {}, body = "return this.toString();")
180.2742 -    public String toString() {
180.2743 -        return this;
180.2744 -    }
180.2745 -
180.2746 -    /**
180.2747 -     * Converts this string to a new character array.
180.2748 -     *
180.2749 -     * @return  a newly allocated character array whose length is the length
180.2750 -     *          of this string and whose contents are initialized to contain
180.2751 -     *          the character sequence represented by this string.
180.2752 -     */
180.2753 -    public char[] toCharArray() {
180.2754 -        char result[] = new char[length()];
180.2755 -        getChars(0, length(), result, 0);
180.2756 -        return result;
180.2757 -    }
180.2758 -
180.2759 -    /**
180.2760 -     * Returns a formatted string using the specified format string and
180.2761 -     * arguments.
180.2762 -     *
180.2763 -     * <p> The locale always used is the one returned by {@link
180.2764 -     * java.util.Locale#getDefault() Locale.getDefault()}.
180.2765 -     *
180.2766 -     * @param  format
180.2767 -     *         A <a href="../util/Formatter.html#syntax">format string</a>
180.2768 -     *
180.2769 -     * @param  args
180.2770 -     *         Arguments referenced by the format specifiers in the format
180.2771 -     *         string.  If there are more arguments than format specifiers, the
180.2772 -     *         extra arguments are ignored.  The number of arguments is
180.2773 -     *         variable and may be zero.  The maximum number of arguments is
180.2774 -     *         limited by the maximum dimension of a Java array as defined by
180.2775 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
180.2776 -     *         The behaviour on a
180.2777 -     *         <tt>null</tt> argument depends on the <a
180.2778 -     *         href="../util/Formatter.html#syntax">conversion</a>.
180.2779 -     *
180.2780 -     * @throws  IllegalFormatException
180.2781 -     *          If a format string contains an illegal syntax, a format
180.2782 -     *          specifier that is incompatible with the given arguments,
180.2783 -     *          insufficient arguments given the format string, or other
180.2784 -     *          illegal conditions.  For specification of all possible
180.2785 -     *          formatting errors, see the <a
180.2786 -     *          href="../util/Formatter.html#detail">Details</a> section of the
180.2787 -     *          formatter class specification.
180.2788 -     *
180.2789 -     * @throws  NullPointerException
180.2790 -     *          If the <tt>format</tt> is <tt>null</tt>
180.2791 -     *
180.2792 -     * @return  A formatted string
180.2793 -     *
180.2794 -     * @see  java.util.Formatter
180.2795 -     * @since  1.5
180.2796 -     */
180.2797 -    public static String format(String format, Object ... args) {
180.2798 -        throw new UnsupportedOperationException();
180.2799 -    }
180.2800 -
180.2801 -    /**
180.2802 -     * Returns a formatted string using the specified locale, format string,
180.2803 -     * and arguments.
180.2804 -     *
180.2805 -     * @param  l
180.2806 -     *         The {@linkplain java.util.Locale locale} to apply during
180.2807 -     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
180.2808 -     *         is applied.
180.2809 -     *
180.2810 -     * @param  format
180.2811 -     *         A <a href="../util/Formatter.html#syntax">format string</a>
180.2812 -     *
180.2813 -     * @param  args
180.2814 -     *         Arguments referenced by the format specifiers in the format
180.2815 -     *         string.  If there are more arguments than format specifiers, the
180.2816 -     *         extra arguments are ignored.  The number of arguments is
180.2817 -     *         variable and may be zero.  The maximum number of arguments is
180.2818 -     *         limited by the maximum dimension of a Java array as defined by
180.2819 -     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
180.2820 -     *         The behaviour on a
180.2821 -     *         <tt>null</tt> argument depends on the <a
180.2822 -     *         href="../util/Formatter.html#syntax">conversion</a>.
180.2823 -     *
180.2824 -     * @throws  IllegalFormatException
180.2825 -     *          If a format string contains an illegal syntax, a format
180.2826 -     *          specifier that is incompatible with the given arguments,
180.2827 -     *          insufficient arguments given the format string, or other
180.2828 -     *          illegal conditions.  For specification of all possible
180.2829 -     *          formatting errors, see the <a
180.2830 -     *          href="../util/Formatter.html#detail">Details</a> section of the
180.2831 -     *          formatter class specification
180.2832 -     *
180.2833 -     * @throws  NullPointerException
180.2834 -     *          If the <tt>format</tt> is <tt>null</tt>
180.2835 -     *
180.2836 -     * @return  A formatted string
180.2837 -     *
180.2838 -     * @see  java.util.Formatter
180.2839 -     * @since  1.5
180.2840 -     */
180.2841 -//    public static String format(Locale l, String format, Object ... args) {
180.2842 -//        return new Formatter(l).format(format, args).toString();
180.2843 -//    }
180.2844 -
180.2845 -    /**
180.2846 -     * Returns the string representation of the <code>Object</code> argument.
180.2847 -     *
180.2848 -     * @param   obj   an <code>Object</code>.
180.2849 -     * @return  if the argument is <code>null</code>, then a string equal to
180.2850 -     *          <code>"null"</code>; otherwise, the value of
180.2851 -     *          <code>obj.toString()</code> is returned.
180.2852 -     * @see     java.lang.Object#toString()
180.2853 -     */
180.2854 -    public static String valueOf(Object obj) {
180.2855 -        return (obj == null) ? "null" : obj.toString();
180.2856 -    }
180.2857 -
180.2858 -    /**
180.2859 -     * Returns the string representation of the <code>char</code> array
180.2860 -     * argument. The contents of the character array are copied; subsequent
180.2861 -     * modification of the character array does not affect the newly
180.2862 -     * created string.
180.2863 -     *
180.2864 -     * @param   data   a <code>char</code> array.
180.2865 -     * @return  a newly allocated string representing the same sequence of
180.2866 -     *          characters contained in the character array argument.
180.2867 -     */
180.2868 -    public static String valueOf(char data[]) {
180.2869 -        return new String(data);
180.2870 -    }
180.2871 -
180.2872 -    /**
180.2873 -     * Returns the string representation of a specific subarray of the
180.2874 -     * <code>char</code> array argument.
180.2875 -     * <p>
180.2876 -     * The <code>offset</code> argument is the index of the first
180.2877 -     * character of the subarray. The <code>count</code> argument
180.2878 -     * specifies the length of the subarray. The contents of the subarray
180.2879 -     * are copied; subsequent modification of the character array does not
180.2880 -     * affect the newly created string.
180.2881 -     *
180.2882 -     * @param   data     the character array.
180.2883 -     * @param   offset   the initial offset into the value of the
180.2884 -     *                  <code>String</code>.
180.2885 -     * @param   count    the length of the value of the <code>String</code>.
180.2886 -     * @return  a string representing the sequence of characters contained
180.2887 -     *          in the subarray of the character array argument.
180.2888 -     * @exception IndexOutOfBoundsException if <code>offset</code> is
180.2889 -     *          negative, or <code>count</code> is negative, or
180.2890 -     *          <code>offset+count</code> is larger than
180.2891 -     *          <code>data.length</code>.
180.2892 -     */
180.2893 -    public static String valueOf(char data[], int offset, int count) {
180.2894 -        return new String(data, offset, count);
180.2895 -    }
180.2896 -
180.2897 -    /**
180.2898 -     * Returns a String that represents the character sequence in the
180.2899 -     * array specified.
180.2900 -     *
180.2901 -     * @param   data     the character array.
180.2902 -     * @param   offset   initial offset of the subarray.
180.2903 -     * @param   count    length of the subarray.
180.2904 -     * @return  a <code>String</code> that contains the characters of the
180.2905 -     *          specified subarray of the character array.
180.2906 -     */
180.2907 -    public static String copyValueOf(char data[], int offset, int count) {
180.2908 -        // All public String constructors now copy the data.
180.2909 -        return new String(data, offset, count);
180.2910 -    }
180.2911 -
180.2912 -    /**
180.2913 -     * Returns a String that represents the character sequence in the
180.2914 -     * array specified.
180.2915 -     *
180.2916 -     * @param   data   the character array.
180.2917 -     * @return  a <code>String</code> that contains the characters of the
180.2918 -     *          character array.
180.2919 -     */
180.2920 -    public static String copyValueOf(char data[]) {
180.2921 -        return copyValueOf(data, 0, data.length);
180.2922 -    }
180.2923 -
180.2924 -    /**
180.2925 -     * Returns the string representation of the <code>boolean</code> argument.
180.2926 -     *
180.2927 -     * @param   b   a <code>boolean</code>.
180.2928 -     * @return  if the argument is <code>true</code>, a string equal to
180.2929 -     *          <code>"true"</code> is returned; otherwise, a string equal to
180.2930 -     *          <code>"false"</code> is returned.
180.2931 -     */
180.2932 -    public static String valueOf(boolean b) {
180.2933 -        return b ? "true" : "false";
180.2934 -    }
180.2935 -
180.2936 -    /**
180.2937 -     * Returns the string representation of the <code>char</code>
180.2938 -     * argument.
180.2939 -     *
180.2940 -     * @param   c   a <code>char</code>.
180.2941 -     * @return  a string of length <code>1</code> containing
180.2942 -     *          as its single character the argument <code>c</code>.
180.2943 -     */
180.2944 -    public static String valueOf(char c) {
180.2945 -        char data[] = {c};
180.2946 -        return new String(data, 0, 1);
180.2947 -    }
180.2948 -
180.2949 -    /**
180.2950 -     * Returns the string representation of the <code>int</code> argument.
180.2951 -     * <p>
180.2952 -     * The representation is exactly the one returned by the
180.2953 -     * <code>Integer.toString</code> method of one argument.
180.2954 -     *
180.2955 -     * @param   i   an <code>int</code>.
180.2956 -     * @return  a string representation of the <code>int</code> argument.
180.2957 -     * @see     java.lang.Integer#toString(int, int)
180.2958 -     */
180.2959 -    public static String valueOf(int i) {
180.2960 -        return Integer.toString(i);
180.2961 -    }
180.2962 -
180.2963 -    /**
180.2964 -     * Returns the string representation of the <code>long</code> argument.
180.2965 -     * <p>
180.2966 -     * The representation is exactly the one returned by the
180.2967 -     * <code>Long.toString</code> method of one argument.
180.2968 -     *
180.2969 -     * @param   l   a <code>long</code>.
180.2970 -     * @return  a string representation of the <code>long</code> argument.
180.2971 -     * @see     java.lang.Long#toString(long)
180.2972 -     */
180.2973 -    public static String valueOf(long l) {
180.2974 -        return Long.toString(l);
180.2975 -    }
180.2976 -
180.2977 -    /**
180.2978 -     * Returns the string representation of the <code>float</code> argument.
180.2979 -     * <p>
180.2980 -     * The representation is exactly the one returned by the
180.2981 -     * <code>Float.toString</code> method of one argument.
180.2982 -     *
180.2983 -     * @param   f   a <code>float</code>.
180.2984 -     * @return  a string representation of the <code>float</code> argument.
180.2985 -     * @see     java.lang.Float#toString(float)
180.2986 -     */
180.2987 -    public static String valueOf(float f) {
180.2988 -        return Float.toString(f);
180.2989 -    }
180.2990 -
180.2991 -    /**
180.2992 -     * Returns the string representation of the <code>double</code> argument.
180.2993 -     * <p>
180.2994 -     * The representation is exactly the one returned by the
180.2995 -     * <code>Double.toString</code> method of one argument.
180.2996 -     *
180.2997 -     * @param   d   a <code>double</code>.
180.2998 -     * @return  a  string representation of the <code>double</code> argument.
180.2999 -     * @see     java.lang.Double#toString(double)
180.3000 -     */
180.3001 -    public static String valueOf(double d) {
180.3002 -        return Double.toString(d);
180.3003 -    }
180.3004 -
180.3005 -    /**
180.3006 -     * Returns a canonical representation for the string object.
180.3007 -     * <p>
180.3008 -     * A pool of strings, initially empty, is maintained privately by the
180.3009 -     * class <code>String</code>.
180.3010 -     * <p>
180.3011 -     * When the intern method is invoked, if the pool already contains a
180.3012 -     * string equal to this <code>String</code> object as determined by
180.3013 -     * the {@link #equals(Object)} method, then the string from the pool is
180.3014 -     * returned. Otherwise, this <code>String</code> object is added to the
180.3015 -     * pool and a reference to this <code>String</code> object is returned.
180.3016 -     * <p>
180.3017 -     * It follows that for any two strings <code>s</code> and <code>t</code>,
180.3018 -     * <code>s.intern()&nbsp;==&nbsp;t.intern()</code> is <code>true</code>
180.3019 -     * if and only if <code>s.equals(t)</code> is <code>true</code>.
180.3020 -     * <p>
180.3021 -     * All literal strings and string-valued constant expressions are
180.3022 -     * interned. String literals are defined in section 3.10.5 of the
180.3023 -     * <cite>The Java&trade; Language Specification</cite>.
180.3024 -     *
180.3025 -     * @return  a string that has the same contents as this string, but is
180.3026 -     *          guaranteed to be from a pool of unique strings.
180.3027 -     */
180.3028 -    public native String intern();
180.3029 -    
180.3030 -    
180.3031 -    private static <T> T checkUTF8(T data, String charsetName)
180.3032 -        throws UnsupportedEncodingException {
180.3033 -        if (charsetName == null) {
180.3034 -            throw new NullPointerException("charsetName");
180.3035 -        }
180.3036 -        if (!charsetName.equalsIgnoreCase("UTF-8")
180.3037 -            && !charsetName.equalsIgnoreCase("UTF8")) {
180.3038 -            throw new UnsupportedEncodingException(charsetName);
180.3039 -        }
180.3040 -        return data;
180.3041 -    }
180.3042 -    
180.3043 -    private static int nextChar(byte[] arr, int[] index) throws IndexOutOfBoundsException {
180.3044 -        int c = arr[index[0]++] & 0xff;
180.3045 -        switch (c >> 4) {
180.3046 -            case 0:
180.3047 -            case 1:
180.3048 -            case 2:
180.3049 -            case 3:
180.3050 -            case 4:
180.3051 -            case 5:
180.3052 -            case 6:
180.3053 -            case 7:
180.3054 -                /* 0xxxxxxx*/
180.3055 -                return c;
180.3056 -            case 12:
180.3057 -            case 13: {
180.3058 -                /* 110x xxxx   10xx xxxx*/
180.3059 -                int char2 = (int) arr[index[0]++];
180.3060 -                if ((char2 & 0xC0) != 0x80) {
180.3061 -                    throw new IndexOutOfBoundsException("malformed input");
180.3062 -                }
180.3063 -                return (((c & 0x1F) << 6) | (char2 & 0x3F));
180.3064 -            }
180.3065 -            case 14: {
180.3066 -                /* 1110 xxxx  10xx xxxx  10xx xxxx */
180.3067 -                int char2 = arr[index[0]++];
180.3068 -                int char3 = arr[index[0]++];
180.3069 -                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
180.3070 -                    throw new IndexOutOfBoundsException("malformed input");
180.3071 -                }
180.3072 -                return (((c & 0x0F) << 12)
180.3073 -                    | ((char2 & 0x3F) << 6)
180.3074 -                    | ((char3 & 0x3F) << 0));
180.3075 -            }
180.3076 -            default:
180.3077 -                /* 10xx xxxx,  1111 xxxx */
180.3078 -                throw new IndexOutOfBoundsException("malformed input");
180.3079 -        }
180.3080 -        
180.3081 -    }
180.3082 -}
   181.1 --- a/emul/mini/src/main/java/java/lang/StringBuffer.java	Mon Feb 25 19:00:08 2013 +0100
   181.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   181.3 @@ -1,604 +0,0 @@
   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.lang;
  181.30 -
  181.31 -
  181.32 -/**
  181.33 - * A thread-safe, mutable sequence of characters.
  181.34 - * A string buffer is like a {@link String}, but can be modified. At any
  181.35 - * point in time it contains some particular sequence of characters, but
  181.36 - * the length and content of the sequence can be changed through certain
  181.37 - * method calls.
  181.38 - * <p>
  181.39 - * String buffers are safe for use by multiple threads. The methods
  181.40 - * are synchronized where necessary so that all the operations on any
  181.41 - * particular instance behave as if they occur in some serial order
  181.42 - * that is consistent with the order of the method calls made by each of
  181.43 - * the individual threads involved.
  181.44 - * <p>
  181.45 - * The principal operations on a <code>StringBuffer</code> are the
  181.46 - * <code>append</code> and <code>insert</code> methods, which are
  181.47 - * overloaded so as to accept data of any type. Each effectively
  181.48 - * converts a given datum to a string and then appends or inserts the
  181.49 - * characters of that string to the string buffer. The
  181.50 - * <code>append</code> method always adds these characters at the end
  181.51 - * of the buffer; the <code>insert</code> method adds the characters at
  181.52 - * a specified point.
  181.53 - * <p>
  181.54 - * For example, if <code>z</code> refers to a string buffer object
  181.55 - * whose current contents are "<code>start</code>", then
  181.56 - * the method call <code>z.append("le")</code> would cause the string
  181.57 - * buffer to contain "<code>startle</code>", whereas
  181.58 - * <code>z.insert(4, "le")</code> would alter the string buffer to
  181.59 - * contain "<code>starlet</code>".
  181.60 - * <p>
  181.61 - * In general, if sb refers to an instance of a <code>StringBuffer</code>,
  181.62 - * then <code>sb.append(x)</code> has the same effect as
  181.63 - * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  181.64 - * <p>
  181.65 - * Whenever an operation occurs involving a source sequence (such as
  181.66 - * appending or inserting from a source sequence) this class synchronizes
  181.67 - * only on the string buffer performing the operation, not on the source.
  181.68 - * <p>
  181.69 - * Every string buffer has a capacity. As long as the length of the
  181.70 - * character sequence contained in the string buffer does not exceed
  181.71 - * the capacity, it is not necessary to allocate a new internal
  181.72 - * buffer array. If the internal buffer overflows, it is
  181.73 - * automatically made larger.
  181.74 - *
  181.75 - * As of  release JDK 5, this class has been supplemented with an equivalent
  181.76 - * class designed for use by a single thread, {@link StringBuilder}.  The
  181.77 - * <tt>StringBuilder</tt> class should generally be used in preference to
  181.78 - * this one, as it supports all of the same operations but it is faster, as
  181.79 - * it performs no synchronization.
  181.80 - *
  181.81 - * @author      Arthur van Hoff
  181.82 - * @see     java.lang.StringBuilder
  181.83 - * @see     java.lang.String
  181.84 - * @since   JDK1.0
  181.85 - */
  181.86 - public final class StringBuffer
  181.87 -    extends AbstractStringBuilder
  181.88 -    implements java.io.Serializable, CharSequence
  181.89 -{
  181.90 -
  181.91 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  181.92 -    static final long serialVersionUID = 3388685877147921107L;
  181.93 -
  181.94 -    /**
  181.95 -     * Constructs a string buffer with no characters in it and an
  181.96 -     * initial capacity of 16 characters.
  181.97 -     */
  181.98 -    public StringBuffer() {
  181.99 -        super(16);
 181.100 -    }
 181.101 -
 181.102 -    /**
 181.103 -     * Constructs a string buffer with no characters in it and
 181.104 -     * the specified initial capacity.
 181.105 -     *
 181.106 -     * @param      capacity  the initial capacity.
 181.107 -     * @exception  NegativeArraySizeException  if the <code>capacity</code>
 181.108 -     *               argument is less than <code>0</code>.
 181.109 -     */
 181.110 -    public StringBuffer(int capacity) {
 181.111 -        super(capacity);
 181.112 -    }
 181.113 -
 181.114 -    /**
 181.115 -     * Constructs a string buffer initialized to the contents of the
 181.116 -     * specified string. The initial capacity of the string buffer is
 181.117 -     * <code>16</code> plus the length of the string argument.
 181.118 -     *
 181.119 -     * @param   str   the initial contents of the buffer.
 181.120 -     * @exception NullPointerException if <code>str</code> is <code>null</code>
 181.121 -     */
 181.122 -    public StringBuffer(String str) {
 181.123 -        super(str.length() + 16);
 181.124 -        append(str);
 181.125 -    }
 181.126 -
 181.127 -    /**
 181.128 -     * Constructs a string buffer that contains the same characters
 181.129 -     * as the specified <code>CharSequence</code>. The initial capacity of
 181.130 -     * the string buffer is <code>16</code> plus the length of the
 181.131 -     * <code>CharSequence</code> argument.
 181.132 -     * <p>
 181.133 -     * If the length of the specified <code>CharSequence</code> is
 181.134 -     * less than or equal to zero, then an empty buffer of capacity
 181.135 -     * <code>16</code> is returned.
 181.136 -     *
 181.137 -     * @param      seq   the sequence to copy.
 181.138 -     * @exception NullPointerException if <code>seq</code> is <code>null</code>
 181.139 -     * @since 1.5
 181.140 -     */
 181.141 -    public StringBuffer(CharSequence seq) {
 181.142 -        this(seq.length() + 16);
 181.143 -        append(seq);
 181.144 -    }
 181.145 -
 181.146 -    public synchronized int length() {
 181.147 -        return count;
 181.148 -    }
 181.149 -
 181.150 -    public synchronized int capacity() {
 181.151 -        return value.length;
 181.152 -    }
 181.153 -
 181.154 -
 181.155 -    public synchronized void ensureCapacity(int minimumCapacity) {
 181.156 -        if (minimumCapacity > value.length) {
 181.157 -            expandCapacity(minimumCapacity);
 181.158 -        }
 181.159 -    }
 181.160 -
 181.161 -    /**
 181.162 -     * @since      1.5
 181.163 -     */
 181.164 -    public synchronized void trimToSize() {
 181.165 -        super.trimToSize();
 181.166 -    }
 181.167 -
 181.168 -    /**
 181.169 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.170 -     * @see        #length()
 181.171 -     */
 181.172 -    public synchronized void setLength(int newLength) {
 181.173 -        super.setLength(newLength);
 181.174 -    }
 181.175 -
 181.176 -    /**
 181.177 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.178 -     * @see        #length()
 181.179 -     */
 181.180 -    public synchronized char charAt(int index) {
 181.181 -        if ((index < 0) || (index >= count))
 181.182 -            throw new StringIndexOutOfBoundsException(index);
 181.183 -        return value[index];
 181.184 -    }
 181.185 -
 181.186 -    /**
 181.187 -     * @since      1.5
 181.188 -     */
 181.189 -    public synchronized int codePointAt(int index) {
 181.190 -        return super.codePointAt(index);
 181.191 -    }
 181.192 -
 181.193 -    /**
 181.194 -     * @since     1.5
 181.195 -     */
 181.196 -    public synchronized int codePointBefore(int index) {
 181.197 -        return super.codePointBefore(index);
 181.198 -    }
 181.199 -
 181.200 -    /**
 181.201 -     * @since     1.5
 181.202 -     */
 181.203 -    public synchronized int codePointCount(int beginIndex, int endIndex) {
 181.204 -        return super.codePointCount(beginIndex, endIndex);
 181.205 -    }
 181.206 -
 181.207 -    /**
 181.208 -     * @since     1.5
 181.209 -     */
 181.210 -    public synchronized int offsetByCodePoints(int index, int codePointOffset) {
 181.211 -        return super.offsetByCodePoints(index, codePointOffset);
 181.212 -    }
 181.213 -
 181.214 -    /**
 181.215 -     * @throws NullPointerException {@inheritDoc}
 181.216 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.217 -     */
 181.218 -    public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
 181.219 -                                      int dstBegin)
 181.220 -    {
 181.221 -        super.getChars(srcBegin, srcEnd, dst, dstBegin);
 181.222 -    }
 181.223 -
 181.224 -    /**
 181.225 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.226 -     * @see        #length()
 181.227 -     */
 181.228 -    public synchronized void setCharAt(int index, char ch) {
 181.229 -        if ((index < 0) || (index >= count))
 181.230 -            throw new StringIndexOutOfBoundsException(index);
 181.231 -        value[index] = ch;
 181.232 -    }
 181.233 -
 181.234 -    public synchronized StringBuffer append(Object obj) {
 181.235 -        super.append(String.valueOf(obj));
 181.236 -        return this;
 181.237 -    }
 181.238 -
 181.239 -    public synchronized StringBuffer append(String str) {
 181.240 -        super.append(str);
 181.241 -        return this;
 181.242 -    }
 181.243 -
 181.244 -    /**
 181.245 -     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 181.246 -     * <p>
 181.247 -     * The characters of the <tt>StringBuffer</tt> argument are appended,
 181.248 -     * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
 181.249 -     * length of this <tt>StringBuffer</tt> by the length of the argument.
 181.250 -     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 181.251 -     * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
 181.252 -     * <p>
 181.253 -     * Let <i>n</i> be the length of the old character sequence, the one
 181.254 -     * contained in the <tt>StringBuffer</tt> just prior to execution of the
 181.255 -     * <tt>append</tt> method. Then the character at index <i>k</i> in
 181.256 -     * the new character sequence is equal to the character at index <i>k</i>
 181.257 -     * in the old character sequence, if <i>k</i> is less than <i>n</i>;
 181.258 -     * otherwise, it is equal to the character at index <i>k-n</i> in the
 181.259 -     * argument <code>sb</code>.
 181.260 -     * <p>
 181.261 -     * This method synchronizes on <code>this</code> (the destination)
 181.262 -     * object but does not synchronize on the source (<code>sb</code>).
 181.263 -     *
 181.264 -     * @param   sb   the <tt>StringBuffer</tt> to append.
 181.265 -     * @return  a reference to this object.
 181.266 -     * @since 1.4
 181.267 -     */
 181.268 -    public synchronized StringBuffer append(StringBuffer sb) {
 181.269 -        super.append(sb);
 181.270 -        return this;
 181.271 -    }
 181.272 -
 181.273 -
 181.274 -    /**
 181.275 -     * Appends the specified <code>CharSequence</code> to this
 181.276 -     * sequence.
 181.277 -     * <p>
 181.278 -     * The characters of the <code>CharSequence</code> argument are appended,
 181.279 -     * in order, increasing the length of this sequence by the length of the
 181.280 -     * argument.
 181.281 -     *
 181.282 -     * <p>The result of this method is exactly the same as if it were an
 181.283 -     * invocation of this.append(s, 0, s.length());
 181.284 -     *
 181.285 -     * <p>This method synchronizes on this (the destination)
 181.286 -     * object but does not synchronize on the source (<code>s</code>).
 181.287 -     *
 181.288 -     * <p>If <code>s</code> is <code>null</code>, then the four characters
 181.289 -     * <code>"null"</code> are appended.
 181.290 -     *
 181.291 -     * @param   s the <code>CharSequence</code> to append.
 181.292 -     * @return  a reference to this object.
 181.293 -     * @since 1.5
 181.294 -     */
 181.295 -    public StringBuffer append(CharSequence s) {
 181.296 -        // Note, synchronization achieved via other invocations
 181.297 -        if (s == null)
 181.298 -            s = "null";
 181.299 -        if (s instanceof String)
 181.300 -            return this.append((String)s);
 181.301 -        if (s instanceof StringBuffer)
 181.302 -            return this.append((StringBuffer)s);
 181.303 -        return this.append(s, 0, s.length());
 181.304 -    }
 181.305 -
 181.306 -    /**
 181.307 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.308 -     * @since      1.5
 181.309 -     */
 181.310 -    public synchronized StringBuffer append(CharSequence s, int start, int end)
 181.311 -    {
 181.312 -        super.append(s, start, end);
 181.313 -        return this;
 181.314 -    }
 181.315 -
 181.316 -    public synchronized StringBuffer append(char[] str) {
 181.317 -        super.append(str);
 181.318 -        return this;
 181.319 -    }
 181.320 -
 181.321 -    /**
 181.322 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.323 -     */
 181.324 -    public synchronized StringBuffer append(char[] str, int offset, int len) {
 181.325 -        super.append(str, offset, len);
 181.326 -        return this;
 181.327 -    }
 181.328 -
 181.329 -    public synchronized StringBuffer append(boolean b) {
 181.330 -        super.append(b);
 181.331 -        return this;
 181.332 -    }
 181.333 -
 181.334 -    public synchronized StringBuffer append(char c) {
 181.335 -        super.append(c);
 181.336 -        return this;
 181.337 -    }
 181.338 -
 181.339 -    public synchronized StringBuffer append(int i) {
 181.340 -        super.append(i);
 181.341 -        return this;
 181.342 -    }
 181.343 -
 181.344 -    /**
 181.345 -     * @since 1.5
 181.346 -     */
 181.347 -    public synchronized StringBuffer appendCodePoint(int codePoint) {
 181.348 -        super.appendCodePoint(codePoint);
 181.349 -        return this;
 181.350 -    }
 181.351 -
 181.352 -    public synchronized StringBuffer append(long lng) {
 181.353 -        super.append(lng);
 181.354 -        return this;
 181.355 -    }
 181.356 -
 181.357 -    public synchronized StringBuffer append(float f) {
 181.358 -        super.append(f);
 181.359 -        return this;
 181.360 -    }
 181.361 -
 181.362 -    public synchronized StringBuffer append(double d) {
 181.363 -        super.append(d);
 181.364 -        return this;
 181.365 -    }
 181.366 -
 181.367 -    /**
 181.368 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.369 -     * @since      1.2
 181.370 -     */
 181.371 -    public synchronized StringBuffer delete(int start, int end) {
 181.372 -        super.delete(start, end);
 181.373 -        return this;
 181.374 -    }
 181.375 -
 181.376 -    /**
 181.377 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.378 -     * @since      1.2
 181.379 -     */
 181.380 -    public synchronized StringBuffer deleteCharAt(int index) {
 181.381 -        super.deleteCharAt(index);
 181.382 -        return this;
 181.383 -    }
 181.384 -
 181.385 -    /**
 181.386 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.387 -     * @since      1.2
 181.388 -     */
 181.389 -    public synchronized StringBuffer replace(int start, int end, String str) {
 181.390 -        super.replace(start, end, str);
 181.391 -        return this;
 181.392 -    }
 181.393 -
 181.394 -    /**
 181.395 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.396 -     * @since      1.2
 181.397 -     */
 181.398 -    public synchronized String substring(int start) {
 181.399 -        return substring(start, count);
 181.400 -    }
 181.401 -
 181.402 -    /**
 181.403 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.404 -     * @since      1.4
 181.405 -     */
 181.406 -    public synchronized CharSequence subSequence(int start, int end) {
 181.407 -        return super.substring(start, end);
 181.408 -    }
 181.409 -
 181.410 -    /**
 181.411 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.412 -     * @since      1.2
 181.413 -     */
 181.414 -    public synchronized String substring(int start, int end) {
 181.415 -        return super.substring(start, end);
 181.416 -    }
 181.417 -
 181.418 -    /**
 181.419 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.420 -     * @since      1.2
 181.421 -     */
 181.422 -    public synchronized StringBuffer insert(int index, char[] str, int offset,
 181.423 -                                            int len)
 181.424 -    {
 181.425 -        super.insert(index, str, offset, len);
 181.426 -        return this;
 181.427 -    }
 181.428 -
 181.429 -    /**
 181.430 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.431 -     */
 181.432 -    public synchronized StringBuffer insert(int offset, Object obj) {
 181.433 -        super.insert(offset, String.valueOf(obj));
 181.434 -        return this;
 181.435 -    }
 181.436 -
 181.437 -    /**
 181.438 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.439 -     */
 181.440 -    public synchronized StringBuffer insert(int offset, String str) {
 181.441 -        super.insert(offset, str);
 181.442 -        return this;
 181.443 -    }
 181.444 -
 181.445 -    /**
 181.446 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.447 -     */
 181.448 -    public synchronized StringBuffer insert(int offset, char[] str) {
 181.449 -        super.insert(offset, str);
 181.450 -        return this;
 181.451 -    }
 181.452 -
 181.453 -    /**
 181.454 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.455 -     * @since      1.5
 181.456 -     */
 181.457 -    public StringBuffer insert(int dstOffset, CharSequence s) {
 181.458 -        // Note, synchronization achieved via other invocations
 181.459 -        if (s == null)
 181.460 -            s = "null";
 181.461 -        if (s instanceof String)
 181.462 -            return this.insert(dstOffset, (String)s);
 181.463 -        return this.insert(dstOffset, s, 0, s.length());
 181.464 -    }
 181.465 -
 181.466 -    /**
 181.467 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.468 -     * @since      1.5
 181.469 -     */
 181.470 -    public synchronized StringBuffer insert(int dstOffset, CharSequence s,
 181.471 -                                            int start, int end)
 181.472 -    {
 181.473 -        super.insert(dstOffset, s, start, end);
 181.474 -        return this;
 181.475 -    }
 181.476 -
 181.477 -    /**
 181.478 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.479 -     */
 181.480 -    public StringBuffer insert(int offset, boolean b) {
 181.481 -        return insert(offset, String.valueOf(b));
 181.482 -    }
 181.483 -
 181.484 -    /**
 181.485 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 181.486 -     */
 181.487 -    public synchronized StringBuffer insert(int offset, char c) {
 181.488 -        super.insert(offset, c);
 181.489 -        return this;
 181.490 -    }
 181.491 -
 181.492 -    /**
 181.493 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.494 -     */
 181.495 -    public StringBuffer insert(int offset, int i) {
 181.496 -        return insert(offset, String.valueOf(i));
 181.497 -    }
 181.498 -
 181.499 -    /**
 181.500 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.501 -     */
 181.502 -    public StringBuffer insert(int offset, long l) {
 181.503 -        return insert(offset, String.valueOf(l));
 181.504 -    }
 181.505 -
 181.506 -    /**
 181.507 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.508 -     */
 181.509 -    public StringBuffer insert(int offset, float f) {
 181.510 -        return insert(offset, String.valueOf(f));
 181.511 -    }
 181.512 -
 181.513 -    /**
 181.514 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 181.515 -     */
 181.516 -    public StringBuffer insert(int offset, double d) {
 181.517 -        return insert(offset, String.valueOf(d));
 181.518 -    }
 181.519 -
 181.520 -    /**
 181.521 -     * @throws NullPointerException {@inheritDoc}
 181.522 -     * @since      1.4
 181.523 -     */
 181.524 -    public int indexOf(String str) {
 181.525 -        return indexOf(str, 0);
 181.526 -    }
 181.527 -
 181.528 -    /**
 181.529 -     * @throws NullPointerException {@inheritDoc}
 181.530 -     * @since      1.4
 181.531 -     */
 181.532 -    public synchronized int indexOf(String str, int fromIndex) {
 181.533 -        return super.indexOf(str, fromIndex);
 181.534 -    }
 181.535 -
 181.536 -    /**
 181.537 -     * @throws NullPointerException {@inheritDoc}
 181.538 -     * @since      1.4
 181.539 -     */
 181.540 -    public int lastIndexOf(String str) {
 181.541 -        // Note, synchronization achieved via other invocations
 181.542 -        return lastIndexOf(str, count);
 181.543 -    }
 181.544 -
 181.545 -    /**
 181.546 -     * @throws NullPointerException {@inheritDoc}
 181.547 -     * @since      1.4
 181.548 -     */
 181.549 -    public synchronized int lastIndexOf(String str, int fromIndex) {
 181.550 -        return String.lastIndexOf(value, 0, count,
 181.551 -                              str.toCharArray(), 0, str.length(), fromIndex);
 181.552 -    }
 181.553 -
 181.554 -    /**
 181.555 -     * @since   JDK1.0.2
 181.556 -     */
 181.557 -    public synchronized StringBuffer reverse() {
 181.558 -        super.reverse();
 181.559 -        return this;
 181.560 -    }
 181.561 -
 181.562 -    public synchronized String toString() {
 181.563 -        return new String(value, 0, count);
 181.564 -    }
 181.565 -
 181.566 -//    /**
 181.567 -//     * Serializable fields for StringBuffer.
 181.568 -//     *
 181.569 -//     * @serialField value  char[]
 181.570 -//     *              The backing character array of this StringBuffer.
 181.571 -//     * @serialField count int
 181.572 -//     *              The number of characters in this StringBuffer.
 181.573 -//     * @serialField shared  boolean
 181.574 -//     *              A flag indicating whether the backing array is shared.
 181.575 -//     *              The value is ignored upon deserialization.
 181.576 -//     */
 181.577 -//    private static final java.io.ObjectStreamField[] serialPersistentFields =
 181.578 -//    {
 181.579 -//        new java.io.ObjectStreamField("value", char[].class),
 181.580 -//        new java.io.ObjectStreamField("count", Integer.TYPE),
 181.581 -//        new java.io.ObjectStreamField("shared", Boolean.TYPE),
 181.582 -//    };
 181.583 -//
 181.584 -//    /**
 181.585 -//     * readObject is called to restore the state of the StringBuffer from
 181.586 -//     * a stream.
 181.587 -//     */
 181.588 -//    private synchronized void writeObject(java.io.ObjectOutputStream s)
 181.589 -//        throws java.io.IOException {
 181.590 -//        java.io.ObjectOutputStream.PutField fields = s.putFields();
 181.591 -//        fields.put("value", value);
 181.592 -//        fields.put("count", count);
 181.593 -//        fields.put("shared", false);
 181.594 -//        s.writeFields();
 181.595 -//    }
 181.596 -//
 181.597 -//    /**
 181.598 -//     * readObject is called to restore the state of the StringBuffer from
 181.599 -//     * a stream.
 181.600 -//     */
 181.601 -//    private void readObject(java.io.ObjectInputStream s)
 181.602 -//        throws java.io.IOException, ClassNotFoundException {
 181.603 -//        java.io.ObjectInputStream.GetField fields = s.readFields();
 181.604 -//        value = (char[])fields.get("value", null);
 181.605 -//        count = fields.get("count", 0);
 181.606 -//    }
 181.607 -}
   182.1 --- a/emul/mini/src/main/java/java/lang/StringBuilder.java	Mon Feb 25 19:00:08 2013 +0100
   182.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   182.3 @@ -1,436 +0,0 @@
   182.4 -/*
   182.5 - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
   182.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   182.7 - *
   182.8 - * This code is free software; you can redistribute it and/or modify it
   182.9 - * under the terms of the GNU General Public License version 2 only, as
  182.10 - * published by the Free Software Foundation.  Oracle designates this
  182.11 - * particular file as subject to the "Classpath" exception as provided
  182.12 - * by Oracle in the LICENSE file that accompanied this code.
  182.13 - *
  182.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  182.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  182.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  182.17 - * version 2 for more details (a copy is included in the LICENSE file that
  182.18 - * accompanied this code).
  182.19 - *
  182.20 - * You should have received a copy of the GNU General Public License version
  182.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  182.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  182.23 - *
  182.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  182.25 - * or visit www.oracle.com if you need additional information or have any
  182.26 - * questions.
  182.27 - */
  182.28 -
  182.29 -package java.lang;
  182.30 -
  182.31 -
  182.32 -/**
  182.33 - * A mutable sequence of characters.  This class provides an API compatible
  182.34 - * with <code>StringBuffer</code>, but with no guarantee of synchronization.
  182.35 - * This class is designed for use as a drop-in replacement for
  182.36 - * <code>StringBuffer</code> in places where the string buffer was being
  182.37 - * used by a single thread (as is generally the case).   Where possible,
  182.38 - * it is recommended that this class be used in preference to
  182.39 - * <code>StringBuffer</code> as it will be faster under most implementations.
  182.40 - *
  182.41 - * <p>The principal operations on a <code>StringBuilder</code> are the
  182.42 - * <code>append</code> and <code>insert</code> methods, which are
  182.43 - * overloaded so as to accept data of any type. Each effectively
  182.44 - * converts a given datum to a string and then appends or inserts the
  182.45 - * characters of that string to the string builder. The
  182.46 - * <code>append</code> method always adds these characters at the end
  182.47 - * of the builder; the <code>insert</code> method adds the characters at
  182.48 - * a specified point.
  182.49 - * <p>
  182.50 - * For example, if <code>z</code> refers to a string builder object
  182.51 - * whose current contents are "<code>start</code>", then
  182.52 - * the method call <code>z.append("le")</code> would cause the string
  182.53 - * builder to contain "<code>startle</code>", whereas
  182.54 - * <code>z.insert(4, "le")</code> would alter the string builder to
  182.55 - * contain "<code>starlet</code>".
  182.56 - * <p>
  182.57 - * In general, if sb refers to an instance of a <code>StringBuilder</code>,
  182.58 - * then <code>sb.append(x)</code> has the same effect as
  182.59 - * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  182.60 - *
  182.61 - * Every string builder has a capacity. As long as the length of the
  182.62 - * character sequence contained in the string builder does not exceed
  182.63 - * the capacity, it is not necessary to allocate a new internal
  182.64 - * buffer. If the internal buffer overflows, it is automatically made larger.
  182.65 - *
  182.66 - * <p>Instances of <code>StringBuilder</code> are not safe for
  182.67 - * use by multiple threads. If such synchronization is required then it is
  182.68 - * recommended that {@link java.lang.StringBuffer} be used.
  182.69 - *
  182.70 - * @author      Michael McCloskey
  182.71 - * @see         java.lang.StringBuffer
  182.72 - * @see         java.lang.String
  182.73 - * @since       1.5
  182.74 - */
  182.75 -public final class StringBuilder
  182.76 -    extends AbstractStringBuilder
  182.77 -    implements java.io.Serializable, CharSequence
  182.78 -{
  182.79 -
  182.80 -    /** use serialVersionUID for interoperability */
  182.81 -    static final long serialVersionUID = 4383685877147921099L;
  182.82 -
  182.83 -    /**
  182.84 -     * Constructs a string builder with no characters in it and an
  182.85 -     * initial capacity of 16 characters.
  182.86 -     */
  182.87 -    public StringBuilder() {
  182.88 -        super(16);
  182.89 -    }
  182.90 -
  182.91 -    /**
  182.92 -     * Constructs a string builder with no characters in it and an
  182.93 -     * initial capacity specified by the <code>capacity</code> argument.
  182.94 -     *
  182.95 -     * @param      capacity  the initial capacity.
  182.96 -     * @throws     NegativeArraySizeException  if the <code>capacity</code>
  182.97 -     *               argument is less than <code>0</code>.
  182.98 -     */
  182.99 -    public StringBuilder(int capacity) {
 182.100 -        super(capacity);
 182.101 -    }
 182.102 -
 182.103 -    /**
 182.104 -     * Constructs a string builder initialized to the contents of the
 182.105 -     * specified string. The initial capacity of the string builder is
 182.106 -     * <code>16</code> plus the length of the string argument.
 182.107 -     *
 182.108 -     * @param   str   the initial contents of the buffer.
 182.109 -     * @throws    NullPointerException if <code>str</code> is <code>null</code>
 182.110 -     */
 182.111 -    public StringBuilder(String str) {
 182.112 -        super(str.length() + 16);
 182.113 -        append(str);
 182.114 -    }
 182.115 -
 182.116 -    /**
 182.117 -     * Constructs a string builder that contains the same characters
 182.118 -     * as the specified <code>CharSequence</code>. The initial capacity of
 182.119 -     * the string builder is <code>16</code> plus the length of the
 182.120 -     * <code>CharSequence</code> argument.
 182.121 -     *
 182.122 -     * @param      seq   the sequence to copy.
 182.123 -     * @throws    NullPointerException if <code>seq</code> is <code>null</code>
 182.124 -     */
 182.125 -    public StringBuilder(CharSequence seq) {
 182.126 -        this(seq.length() + 16);
 182.127 -        append(seq);
 182.128 -    }
 182.129 -
 182.130 -    public StringBuilder append(Object obj) {
 182.131 -        return append(String.valueOf(obj));
 182.132 -    }
 182.133 -
 182.134 -    public StringBuilder append(String str) {
 182.135 -        super.append(str);
 182.136 -        return this;
 182.137 -    }
 182.138 -
 182.139 -    // Appends the specified string builder to this sequence.
 182.140 -    private StringBuilder append(StringBuilder sb) {
 182.141 -        if (sb == null)
 182.142 -            return append("null");
 182.143 -        int len = sb.length();
 182.144 -        int newcount = count + len;
 182.145 -        if (newcount > value.length)
 182.146 -            expandCapacity(newcount);
 182.147 -        sb.getChars(0, len, value, count);
 182.148 -        count = newcount;
 182.149 -        return this;
 182.150 -    }
 182.151 -
 182.152 -    /**
 182.153 -     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 182.154 -     * <p>
 182.155 -     * The characters of the <tt>StringBuffer</tt> argument are appended,
 182.156 -     * in order, to this sequence, increasing the
 182.157 -     * length of this sequence by the length of the argument.
 182.158 -     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 182.159 -     * <tt>"null"</tt> are appended to this sequence.
 182.160 -     * <p>
 182.161 -     * Let <i>n</i> be the length of this character sequence just prior to
 182.162 -     * execution of the <tt>append</tt> method. Then the character at index
 182.163 -     * <i>k</i> in the new character sequence is equal to the character at
 182.164 -     * index <i>k</i> in the old character sequence, if <i>k</i> is less than
 182.165 -     * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
 182.166 -     * in the argument <code>sb</code>.
 182.167 -     *
 182.168 -     * @param   sb   the <tt>StringBuffer</tt> to append.
 182.169 -     * @return  a reference to this object.
 182.170 -     */
 182.171 -    public StringBuilder append(StringBuffer sb) {
 182.172 -        super.append(sb);
 182.173 -        return this;
 182.174 -    }
 182.175 -
 182.176 -    /**
 182.177 -     */
 182.178 -    public StringBuilder append(CharSequence s) {
 182.179 -        if (s == null)
 182.180 -            s = "null";
 182.181 -        if (s instanceof String)
 182.182 -            return this.append((String)s);
 182.183 -        if (s instanceof StringBuffer)
 182.184 -            return this.append((StringBuffer)s);
 182.185 -        if (s instanceof StringBuilder)
 182.186 -            return this.append((StringBuilder)s);
 182.187 -        return this.append(s, 0, s.length());
 182.188 -    }
 182.189 -
 182.190 -    /**
 182.191 -     * @throws     IndexOutOfBoundsException {@inheritDoc}
 182.192 -     */
 182.193 -    public StringBuilder append(CharSequence s, int start, int end) {
 182.194 -        super.append(s, start, end);
 182.195 -        return this;
 182.196 -    }
 182.197 -
 182.198 -    public StringBuilder append(char[] str) {
 182.199 -        super.append(str);
 182.200 -        return this;
 182.201 -    }
 182.202 -
 182.203 -    /**
 182.204 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 182.205 -     */
 182.206 -    public StringBuilder append(char[] str, int offset, int len) {
 182.207 -        super.append(str, offset, len);
 182.208 -        return this;
 182.209 -    }
 182.210 -
 182.211 -    public StringBuilder append(boolean b) {
 182.212 -        super.append(b);
 182.213 -        return this;
 182.214 -    }
 182.215 -
 182.216 -    public StringBuilder append(char c) {
 182.217 -        super.append(c);
 182.218 -        return this;
 182.219 -    }
 182.220 -
 182.221 -    public StringBuilder append(int i) {
 182.222 -        super.append(i);
 182.223 -        return this;
 182.224 -    }
 182.225 -
 182.226 -    public StringBuilder append(long lng) {
 182.227 -        super.append(lng);
 182.228 -        return this;
 182.229 -    }
 182.230 -
 182.231 -    public StringBuilder append(float f) {
 182.232 -        super.append(f);
 182.233 -        return this;
 182.234 -    }
 182.235 -
 182.236 -    public StringBuilder append(double d) {
 182.237 -        super.append(d);
 182.238 -        return this;
 182.239 -    }
 182.240 -
 182.241 -    /**
 182.242 -     * @since 1.5
 182.243 -     */
 182.244 -    public StringBuilder appendCodePoint(int codePoint) {
 182.245 -        super.appendCodePoint(codePoint);
 182.246 -        return this;
 182.247 -    }
 182.248 -
 182.249 -    /**
 182.250 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.251 -     */
 182.252 -    public StringBuilder delete(int start, int end) {
 182.253 -        super.delete(start, end);
 182.254 -        return this;
 182.255 -    }
 182.256 -
 182.257 -    /**
 182.258 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.259 -     */
 182.260 -    public StringBuilder deleteCharAt(int index) {
 182.261 -        super.deleteCharAt(index);
 182.262 -        return this;
 182.263 -    }
 182.264 -
 182.265 -    /**
 182.266 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.267 -     */
 182.268 -    public StringBuilder replace(int start, int end, String str) {
 182.269 -        super.replace(start, end, str);
 182.270 -        return this;
 182.271 -    }
 182.272 -
 182.273 -    /**
 182.274 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.275 -     */
 182.276 -    public StringBuilder insert(int index, char[] str, int offset,
 182.277 -                                int len)
 182.278 -    {
 182.279 -        super.insert(index, str, offset, len);
 182.280 -        return this;
 182.281 -    }
 182.282 -
 182.283 -    /**
 182.284 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.285 -     */
 182.286 -    public StringBuilder insert(int offset, Object obj) {
 182.287 -        return insert(offset, String.valueOf(obj));
 182.288 -    }
 182.289 -
 182.290 -    /**
 182.291 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.292 -     */
 182.293 -    public StringBuilder insert(int offset, String str) {
 182.294 -        super.insert(offset, str);
 182.295 -        return this;
 182.296 -    }
 182.297 -
 182.298 -    /**
 182.299 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.300 -     */
 182.301 -    public StringBuilder insert(int offset, char[] str) {
 182.302 -        super.insert(offset, str);
 182.303 -        return this;
 182.304 -    }
 182.305 -
 182.306 -    /**
 182.307 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 182.308 -     */
 182.309 -    public StringBuilder insert(int dstOffset, CharSequence s) {
 182.310 -        if (s == null)
 182.311 -            s = "null";
 182.312 -        if (s instanceof String)
 182.313 -            return this.insert(dstOffset, (String)s);
 182.314 -        return this.insert(dstOffset, s, 0, s.length());
 182.315 -    }
 182.316 -
 182.317 -    /**
 182.318 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 182.319 -     */
 182.320 -    public StringBuilder insert(int dstOffset, CharSequence s,
 182.321 -                                int start, int end)
 182.322 -    {
 182.323 -        super.insert(dstOffset, s, start, end);
 182.324 -        return this;
 182.325 -    }
 182.326 -
 182.327 -    /**
 182.328 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.329 -     */
 182.330 -    public StringBuilder insert(int offset, boolean b) {
 182.331 -        super.insert(offset, b);
 182.332 -        return this;
 182.333 -    }
 182.334 -
 182.335 -    /**
 182.336 -     * @throws IndexOutOfBoundsException {@inheritDoc}
 182.337 -     */
 182.338 -    public StringBuilder insert(int offset, char c) {
 182.339 -        super.insert(offset, c);
 182.340 -        return this;
 182.341 -    }
 182.342 -
 182.343 -    /**
 182.344 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.345 -     */
 182.346 -    public StringBuilder insert(int offset, int i) {
 182.347 -        return insert(offset, String.valueOf(i));
 182.348 -    }
 182.349 -
 182.350 -    /**
 182.351 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.352 -     */
 182.353 -    public StringBuilder insert(int offset, long l) {
 182.354 -        return insert(offset, String.valueOf(l));
 182.355 -    }
 182.356 -
 182.357 -    /**
 182.358 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.359 -     */
 182.360 -    public StringBuilder insert(int offset, float f) {
 182.361 -        return insert(offset, String.valueOf(f));
 182.362 -    }
 182.363 -
 182.364 -    /**
 182.365 -     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 182.366 -     */
 182.367 -    public StringBuilder insert(int offset, double d) {
 182.368 -        return insert(offset, String.valueOf(d));
 182.369 -    }
 182.370 -
 182.371 -    /**
 182.372 -     * @throws NullPointerException {@inheritDoc}
 182.373 -     */
 182.374 -    public int indexOf(String str) {
 182.375 -        return indexOf(str, 0);
 182.376 -    }
 182.377 -
 182.378 -    /**
 182.379 -     * @throws NullPointerException {@inheritDoc}
 182.380 -     */
 182.381 -    public int indexOf(String str, int fromIndex) {
 182.382 -        return super.indexOf(str, fromIndex);
 182.383 -    }
 182.384 -
 182.385 -    /**
 182.386 -     * @throws NullPointerException {@inheritDoc}
 182.387 -     */
 182.388 -    public int lastIndexOf(String str) {
 182.389 -        return lastIndexOf(str, count);
 182.390 -    }
 182.391 -
 182.392 -    /**
 182.393 -     * @throws NullPointerException {@inheritDoc}
 182.394 -     */
 182.395 -    public int lastIndexOf(String str, int fromIndex) {
 182.396 -        return String.lastIndexOf(value, 0, count,
 182.397 -                              str.toCharArray(), 0, str.length(), fromIndex);
 182.398 -    }
 182.399 -
 182.400 -    public StringBuilder reverse() {
 182.401 -        super.reverse();
 182.402 -        return this;
 182.403 -    }
 182.404 -
 182.405 -    public String toString() {
 182.406 -        // Create a copy, don't share the array
 182.407 -        return new String(value, 0, count);
 182.408 -    }
 182.409 -
 182.410 -    /**
 182.411 -     * Save the state of the <tt>StringBuilder</tt> instance to a stream
 182.412 -     * (that is, serialize it).
 182.413 -     *
 182.414 -     * @serialData the number of characters currently stored in the string
 182.415 -     *             builder (<tt>int</tt>), followed by the characters in the
 182.416 -     *             string builder (<tt>char[]</tt>).   The length of the
 182.417 -     *             <tt>char</tt> array may be greater than the number of
 182.418 -     *             characters currently stored in the string builder, in which
 182.419 -     *             case extra characters are ignored.
 182.420 -     */
 182.421 -//    private void writeObject(java.io.ObjectOutputStream s)
 182.422 -//        throws java.io.IOException {
 182.423 -//        s.defaultWriteObject();
 182.424 -//        s.writeInt(count);
 182.425 -//        s.writeObject(value);
 182.426 -//    }
 182.427 -
 182.428 -    /**
 182.429 -     * readObject is called to restore the state of the StringBuffer from
 182.430 -     * a stream.
 182.431 -     */
 182.432 -//    private void readObject(java.io.ObjectInputStream s)
 182.433 -//        throws java.io.IOException, ClassNotFoundException {
 182.434 -//        s.defaultReadObject();
 182.435 -//        count = s.readInt();
 182.436 -//        value = (char[]) s.readObject();
 182.437 -//    }
 182.438 -
 182.439 -}
   183.1 --- a/emul/mini/src/main/java/java/lang/StringIndexOutOfBoundsException.java	Mon Feb 25 19:00:08 2013 +0100
   183.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   183.3 @@ -1,71 +0,0 @@
   183.4 -/*
   183.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   183.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   183.7 - *
   183.8 - * This code is free software; you can redistribute it and/or modify it
   183.9 - * under the terms of the GNU General Public License version 2 only, as
  183.10 - * published by the Free Software Foundation.  Oracle designates this
  183.11 - * particular file as subject to the "Classpath" exception as provided
  183.12 - * by Oracle in the LICENSE file that accompanied this code.
  183.13 - *
  183.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  183.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  183.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  183.17 - * version 2 for more details (a copy is included in the LICENSE file that
  183.18 - * accompanied this code).
  183.19 - *
  183.20 - * You should have received a copy of the GNU General Public License version
  183.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  183.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  183.23 - *
  183.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  183.25 - * or visit www.oracle.com if you need additional information or have any
  183.26 - * questions.
  183.27 - */
  183.28 -
  183.29 -package java.lang;
  183.30 -
  183.31 -/**
  183.32 - * Thrown by <code>String</code> methods to indicate that an index
  183.33 - * is either negative or greater than the size of the string.  For
  183.34 - * some methods such as the charAt method, this exception also is
  183.35 - * thrown when the index is equal to the size of the string.
  183.36 - *
  183.37 - * @author  unascribed
  183.38 - * @see     java.lang.String#charAt(int)
  183.39 - * @since   JDK1.0
  183.40 - */
  183.41 -public
  183.42 -class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
  183.43 -    private static final long serialVersionUID = -6762910422159637258L;
  183.44 -
  183.45 -    /**
  183.46 -     * Constructs a <code>StringIndexOutOfBoundsException</code> with no
  183.47 -     * detail message.
  183.48 -     *
  183.49 -     * @since   JDK1.0.
  183.50 -     */
  183.51 -    public StringIndexOutOfBoundsException() {
  183.52 -        super();
  183.53 -    }
  183.54 -
  183.55 -    /**
  183.56 -     * Constructs a <code>StringIndexOutOfBoundsException</code> with
  183.57 -     * the specified detail message.
  183.58 -     *
  183.59 -     * @param   s   the detail message.
  183.60 -     */
  183.61 -    public StringIndexOutOfBoundsException(String s) {
  183.62 -        super(s);
  183.63 -    }
  183.64 -
  183.65 -    /**
  183.66 -     * Constructs a new <code>StringIndexOutOfBoundsException</code>
  183.67 -     * class with an argument indicating the illegal index.
  183.68 -     *
  183.69 -     * @param   index   the illegal index.
  183.70 -     */
  183.71 -    public StringIndexOutOfBoundsException(int index) {
  183.72 -        super("String index out of range: " + index);
  183.73 -    }
  183.74 -}
   184.1 --- a/emul/mini/src/main/java/java/lang/Throwable.java	Mon Feb 25 19:00:08 2013 +0100
   184.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   184.3 @@ -1,1088 +0,0 @@
   184.4 -/*
   184.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   184.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   184.7 - *
   184.8 - * This code is free software; you can redistribute it and/or modify it
   184.9 - * under the terms of the GNU General Public License version 2 only, as
  184.10 - * published by the Free Software Foundation.  Oracle designates this
  184.11 - * particular file as subject to the "Classpath" exception as provided
  184.12 - * by Oracle in the LICENSE file that accompanied this code.
  184.13 - *
  184.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  184.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  184.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  184.17 - * version 2 for more details (a copy is included in the LICENSE file that
  184.18 - * accompanied this code).
  184.19 - *
  184.20 - * You should have received a copy of the GNU General Public License version
  184.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  184.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  184.23 - *
  184.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  184.25 - * or visit www.oracle.com if you need additional information or have any
  184.26 - * questions.
  184.27 - */
  184.28 -
  184.29 -package java.lang;
  184.30 -import  java.io.*;
  184.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  184.32 -import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  184.33 -
  184.34 -/**
  184.35 - * The {@code Throwable} class is the superclass of all errors and
  184.36 - * exceptions in the Java language. Only objects that are instances of this
  184.37 - * class (or one of its subclasses) are thrown by the Java Virtual Machine or
  184.38 - * can be thrown by the Java {@code throw} statement. Similarly, only
  184.39 - * this class or one of its subclasses can be the argument type in a
  184.40 - * {@code catch} clause.
  184.41 - *
  184.42 - * For the purposes of compile-time checking of exceptions, {@code
  184.43 - * Throwable} and any subclass of {@code Throwable} that is not also a
  184.44 - * subclass of either {@link RuntimeException} or {@link Error} are
  184.45 - * regarded as checked exceptions.
  184.46 - *
  184.47 - * <p>Instances of two subclasses, {@link java.lang.Error} and
  184.48 - * {@link java.lang.Exception}, are conventionally used to indicate
  184.49 - * that exceptional situations have occurred. Typically, these instances
  184.50 - * are freshly created in the context of the exceptional situation so
  184.51 - * as to include relevant information (such as stack trace data).
  184.52 - *
  184.53 - * <p>A throwable contains a snapshot of the execution stack of its
  184.54 - * thread at the time it was created. It can also contain a message
  184.55 - * string that gives more information about the error. Over time, a
  184.56 - * throwable can {@linkplain Throwable#addSuppressed suppress} other
  184.57 - * throwables from being propagated.  Finally, the throwable can also
  184.58 - * contain a <i>cause</i>: another throwable that caused this
  184.59 - * throwable to be constructed.  The recording of this causal information
  184.60 - * is referred to as the <i>chained exception</i> facility, as the
  184.61 - * cause can, itself, have a cause, and so on, leading to a "chain" of
  184.62 - * exceptions, each caused by another.
  184.63 - *
  184.64 - * <p>One reason that a throwable may have a cause is that the class that
  184.65 - * throws it is built atop a lower layered abstraction, and an operation on
  184.66 - * the upper layer fails due to a failure in the lower layer.  It would be bad
  184.67 - * design to let the throwable thrown by the lower layer propagate outward, as
  184.68 - * it is generally unrelated to the abstraction provided by the upper layer.
  184.69 - * Further, doing so would tie the API of the upper layer to the details of
  184.70 - * its implementation, assuming the lower layer's exception was a checked
  184.71 - * exception.  Throwing a "wrapped exception" (i.e., an exception containing a
  184.72 - * cause) allows the upper layer to communicate the details of the failure to
  184.73 - * its caller without incurring either of these shortcomings.  It preserves
  184.74 - * the flexibility to change the implementation of the upper layer without
  184.75 - * changing its API (in particular, the set of exceptions thrown by its
  184.76 - * methods).
  184.77 - *
  184.78 - * <p>A second reason that a throwable may have a cause is that the method
  184.79 - * that throws it must conform to a general-purpose interface that does not
  184.80 - * permit the method to throw the cause directly.  For example, suppose
  184.81 - * a persistent collection conforms to the {@link java.util.Collection
  184.82 - * Collection} interface, and that its persistence is implemented atop
  184.83 - * {@code java.io}.  Suppose the internals of the {@code add} method
  184.84 - * can throw an {@link java.io.IOException IOException}.  The implementation
  184.85 - * can communicate the details of the {@code IOException} to its caller
  184.86 - * while conforming to the {@code Collection} interface by wrapping the
  184.87 - * {@code IOException} in an appropriate unchecked exception.  (The
  184.88 - * specification for the persistent collection should indicate that it is
  184.89 - * capable of throwing such exceptions.)
  184.90 - *
  184.91 - * <p>A cause can be associated with a throwable in two ways: via a
  184.92 - * constructor that takes the cause as an argument, or via the
  184.93 - * {@link #initCause(Throwable)} method.  New throwable classes that
  184.94 - * wish to allow causes to be associated with them should provide constructors
  184.95 - * that take a cause and delegate (perhaps indirectly) to one of the
  184.96 - * {@code Throwable} constructors that takes a cause.
  184.97 - *
  184.98 - * Because the {@code initCause} method is public, it allows a cause to be
  184.99 - * associated with any throwable, even a "legacy throwable" whose
 184.100 - * implementation predates the addition of the exception chaining mechanism to
 184.101 - * {@code Throwable}.
 184.102 - *
 184.103 - * <p>By convention, class {@code Throwable} and its subclasses have two
 184.104 - * constructors, one that takes no arguments and one that takes a
 184.105 - * {@code String} argument that can be used to produce a detail message.
 184.106 - * Further, those subclasses that might likely have a cause associated with
 184.107 - * them should have two more constructors, one that takes a
 184.108 - * {@code Throwable} (the cause), and one that takes a
 184.109 - * {@code String} (the detail message) and a {@code Throwable} (the
 184.110 - * cause).
 184.111 - *
 184.112 - * @author  unascribed
 184.113 - * @author  Josh Bloch (Added exception chaining and programmatic access to
 184.114 - *          stack trace in 1.4.)
 184.115 - * @jls 11.2 Compile-Time Checking of Exceptions
 184.116 - * @since JDK1.0
 184.117 - */
 184.118 -public class Throwable implements Serializable {
 184.119 -    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 184.120 -    private static final long serialVersionUID = -3042686055658047285L;
 184.121 -
 184.122 -    /**
 184.123 -     * Native code saves some indication of the stack backtrace in this slot.
 184.124 -     */
 184.125 -    private transient Object backtrace;
 184.126 -
 184.127 -    /**
 184.128 -     * Specific details about the Throwable.  For example, for
 184.129 -     * {@code FileNotFoundException}, this contains the name of
 184.130 -     * the file that could not be found.
 184.131 -     *
 184.132 -     * @serial
 184.133 -     */
 184.134 -    private String detailMessage;
 184.135 -
 184.136 -
 184.137 -    /**
 184.138 -     * Holder class to defer initializing sentinel objects only used
 184.139 -     * for serialization.
 184.140 -     */
 184.141 -    private static class SentinelHolder {
 184.142 -        /**
 184.143 -         * {@linkplain #setStackTrace(StackTraceElement[]) Setting the
 184.144 -         * stack trace} to a one-element array containing this sentinel
 184.145 -         * value indicates future attempts to set the stack trace will be
 184.146 -         * ignored.  The sentinal is equal to the result of calling:<br>
 184.147 -         * {@code new StackTraceElement("", "", null, Integer.MIN_VALUE)}
 184.148 -         */
 184.149 -        public static final StackTraceElement STACK_TRACE_ELEMENT_SENTINEL =
 184.150 -            new StackTraceElement("", "", null, Integer.MIN_VALUE);
 184.151 -
 184.152 -        /**
 184.153 -         * Sentinel value used in the serial form to indicate an immutable
 184.154 -         * stack trace.
 184.155 -         */
 184.156 -        public static final StackTraceElement[] STACK_TRACE_SENTINEL =
 184.157 -            new StackTraceElement[] {STACK_TRACE_ELEMENT_SENTINEL};
 184.158 -    }
 184.159 -
 184.160 -    /**
 184.161 -     * A shared value for an empty stack.
 184.162 -     */
 184.163 -    private static final StackTraceElement[] UNASSIGNED_STACK = new StackTraceElement[0];
 184.164 -
 184.165 -    /*
 184.166 -     * To allow Throwable objects to be made immutable and safely
 184.167 -     * reused by the JVM, such as OutOfMemoryErrors, fields of
 184.168 -     * Throwable that are writable in response to user actions, cause,
 184.169 -     * stackTrace, and suppressedExceptions obey the following
 184.170 -     * protocol:
 184.171 -     *
 184.172 -     * 1) The fields are initialized to a non-null sentinel value
 184.173 -     * which indicates the value has logically not been set.
 184.174 -     *
 184.175 -     * 2) Writing a null to the field indicates further writes
 184.176 -     * are forbidden
 184.177 -     *
 184.178 -     * 3) The sentinel value may be replaced with another non-null
 184.179 -     * value.
 184.180 -     *
 184.181 -     * For example, implementations of the HotSpot JVM have
 184.182 -     * preallocated OutOfMemoryError objects to provide for better
 184.183 -     * diagnosability of that situation.  These objects are created
 184.184 -     * without calling the constructor for that class and the fields
 184.185 -     * in question are initialized to null.  To support this
 184.186 -     * capability, any new fields added to Throwable that require
 184.187 -     * being initialized to a non-null value require a coordinated JVM
 184.188 -     * change.
 184.189 -     */
 184.190 -
 184.191 -    /**
 184.192 -     * The throwable that caused this throwable to get thrown, or null if this
 184.193 -     * throwable was not caused by another throwable, or if the causative
 184.194 -     * throwable is unknown.  If this field is equal to this throwable itself,
 184.195 -     * it indicates that the cause of this throwable has not yet been
 184.196 -     * initialized.
 184.197 -     *
 184.198 -     * @serial
 184.199 -     * @since 1.4
 184.200 -     */
 184.201 -    private Throwable cause = this;
 184.202 -
 184.203 -    /**
 184.204 -     * The stack trace, as returned by {@link #getStackTrace()}.
 184.205 -     *
 184.206 -     * The field is initialized to a zero-length array.  A {@code
 184.207 -     * null} value of this field indicates subsequent calls to {@link
 184.208 -     * #setStackTrace(StackTraceElement[])} and {@link
 184.209 -     * #fillInStackTrace()} will be be no-ops.
 184.210 -     *
 184.211 -     * @serial
 184.212 -     * @since 1.4
 184.213 -     */
 184.214 -    private StackTraceElement[] stackTrace = UNASSIGNED_STACK;
 184.215 -
 184.216 -    // Setting this static field introduces an acceptable
 184.217 -    // initialization dependency on a few java.util classes.
 184.218 -// I don't think this dependency is acceptable
 184.219 -//    private static final List<Throwable> SUPPRESSED_SENTINEL =
 184.220 -//        Collections.unmodifiableList(new ArrayList<Throwable>(0));
 184.221 -
 184.222 -    /**
 184.223 -     * The list of suppressed exceptions, as returned by {@link
 184.224 -     * #getSuppressed()}.  The list is initialized to a zero-element
 184.225 -     * unmodifiable sentinel list.  When a serialized Throwable is
 184.226 -     * read in, if the {@code suppressedExceptions} field points to a
 184.227 -     * zero-element list, the field is reset to the sentinel value.
 184.228 -     *
 184.229 -     * @serial
 184.230 -     * @since 1.7
 184.231 -     */
 184.232 -//    private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
 184.233 -
 184.234 -    /** Message for trying to suppress a null exception. */
 184.235 -    private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
 184.236 -
 184.237 -    /** Message for trying to suppress oneself. */
 184.238 -    private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
 184.239 -
 184.240 -    /** Caption  for labeling causative exception stack traces */
 184.241 -    @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
 184.242 -    private static void jsToString() {
 184.243 -    }
 184.244 -    
 184.245 -    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 184.246 -    private static void jsValudOf() {
 184.247 -    }
 184.248 -    private static final String CAUSE_CAPTION = "Caused by: ";
 184.249 -
 184.250 -    /** Caption for labeling suppressed exception stack traces */
 184.251 -    private static final String SUPPRESSED_CAPTION = "Suppressed: ";
 184.252 -
 184.253 -    /**
 184.254 -     * Constructs a new throwable with {@code null} as its detail message.
 184.255 -     * The cause is not initialized, and may subsequently be initialized by a
 184.256 -     * call to {@link #initCause}.
 184.257 -     *
 184.258 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 184.259 -     * the stack trace data in the newly created throwable.
 184.260 -     */
 184.261 -    public Throwable() {
 184.262 -        fillInStackTrace();
 184.263 -    }
 184.264 -
 184.265 -    /**
 184.266 -     * Constructs a new throwable with the specified detail message.  The
 184.267 -     * cause is not initialized, and may subsequently be initialized by
 184.268 -     * a call to {@link #initCause}.
 184.269 -     *
 184.270 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 184.271 -     * the stack trace data in the newly created throwable.
 184.272 -     *
 184.273 -     * @param   message   the detail message. The detail message is saved for
 184.274 -     *          later retrieval by the {@link #getMessage()} method.
 184.275 -     */
 184.276 -    public Throwable(String message) {
 184.277 -        fillInStackTrace();
 184.278 -        detailMessage = message;
 184.279 -    }
 184.280 -
 184.281 -    /**
 184.282 -     * Constructs a new throwable with the specified detail message and
 184.283 -     * cause.  <p>Note that the detail message associated with
 184.284 -     * {@code cause} is <i>not</i> automatically incorporated in
 184.285 -     * this throwable's detail message.
 184.286 -     *
 184.287 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 184.288 -     * the stack trace data in the newly created throwable.
 184.289 -     *
 184.290 -     * @param  message the detail message (which is saved for later retrieval
 184.291 -     *         by the {@link #getMessage()} method).
 184.292 -     * @param  cause the cause (which is saved for later retrieval by the
 184.293 -     *         {@link #getCause()} method).  (A {@code null} value is
 184.294 -     *         permitted, and indicates that the cause is nonexistent or
 184.295 -     *         unknown.)
 184.296 -     * @since  1.4
 184.297 -     */
 184.298 -    public Throwable(String message, Throwable cause) {
 184.299 -        fillInStackTrace();
 184.300 -        detailMessage = message;
 184.301 -        this.cause = cause;
 184.302 -    }
 184.303 -
 184.304 -    /**
 184.305 -     * Constructs a new throwable with the specified cause and a detail
 184.306 -     * message of {@code (cause==null ? null : cause.toString())} (which
 184.307 -     * typically contains the class and detail message of {@code cause}).
 184.308 -     * This constructor is useful for throwables that are little more than
 184.309 -     * wrappers for other throwables (for example, {@link
 184.310 -     * java.security.PrivilegedActionException}).
 184.311 -     *
 184.312 -     * <p>The {@link #fillInStackTrace()} method is called to initialize
 184.313 -     * the stack trace data in the newly created throwable.
 184.314 -     *
 184.315 -     * @param  cause the cause (which is saved for later retrieval by the
 184.316 -     *         {@link #getCause()} method).  (A {@code null} value is
 184.317 -     *         permitted, and indicates that the cause is nonexistent or
 184.318 -     *         unknown.)
 184.319 -     * @since  1.4
 184.320 -     */
 184.321 -    public Throwable(Throwable cause) {
 184.322 -        fillInStackTrace();
 184.323 -        detailMessage = (cause==null ? null : cause.toString());
 184.324 -        this.cause = cause;
 184.325 -    }
 184.326 -
 184.327 -    /**
 184.328 -     * Constructs a new throwable with the specified detail message,
 184.329 -     * cause, {@linkplain #addSuppressed suppression} enabled or
 184.330 -     * disabled, and writable stack trace enabled or disabled.  If
 184.331 -     * suppression is disabled, {@link #getSuppressed} for this object
 184.332 -     * will return a zero-length array and calls to {@link
 184.333 -     * #addSuppressed} that would otherwise append an exception to the
 184.334 -     * suppressed list will have no effect.  If the writable stack
 184.335 -     * trace is false, this constructor will not call {@link
 184.336 -     * #fillInStackTrace()}, a {@code null} will be written to the
 184.337 -     * {@code stackTrace} field, and subsequent calls to {@code
 184.338 -     * fillInStackTrace} and {@link
 184.339 -     * #setStackTrace(StackTraceElement[])} will not set the stack
 184.340 -     * trace.  If the writable stack trace is false, {@link
 184.341 -     * #getStackTrace} will return a zero length array.
 184.342 -     *
 184.343 -     * <p>Note that the other constructors of {@code Throwable} treat
 184.344 -     * suppression as being enabled and the stack trace as being
 184.345 -     * writable.  Subclasses of {@code Throwable} should document any
 184.346 -     * conditions under which suppression is disabled and document
 184.347 -     * conditions under which the stack trace is not writable.
 184.348 -     * Disabling of suppression should only occur in exceptional
 184.349 -     * circumstances where special requirements exist, such as a
 184.350 -     * virtual machine reusing exception objects under low-memory
 184.351 -     * situations.  Circumstances where a given exception object is
 184.352 -     * repeatedly caught and rethrown, such as to implement control
 184.353 -     * flow between two sub-systems, is another situation where
 184.354 -     * immutable throwable objects would be appropriate.
 184.355 -     *
 184.356 -     * @param  message the detail message.
 184.357 -     * @param cause the cause.  (A {@code null} value is permitted,
 184.358 -     * and indicates that the cause is nonexistent or unknown.)
 184.359 -     * @param enableSuppression whether or not suppression is enabled or disabled
 184.360 -     * @param writableStackTrace whether or not the stack trace should be
 184.361 -     *                           writable
 184.362 -     *
 184.363 -     * @see OutOfMemoryError
 184.364 -     * @see NullPointerException
 184.365 -     * @see ArithmeticException
 184.366 -     * @since 1.7
 184.367 -     */
 184.368 -    protected Throwable(String message, Throwable cause,
 184.369 -                        boolean enableSuppression,
 184.370 -                        boolean writableStackTrace) {
 184.371 -        if (writableStackTrace) {
 184.372 -            fillInStackTrace();
 184.373 -        } else {
 184.374 -            stackTrace = null;
 184.375 -        }
 184.376 -        detailMessage = message;
 184.377 -        this.cause = cause;
 184.378 -//        if (!enableSuppression)
 184.379 -//            suppressedExceptions = null;
 184.380 -    }
 184.381 -
 184.382 -    /**
 184.383 -     * Returns the detail message string of this throwable.
 184.384 -     *
 184.385 -     * @return  the detail message string of this {@code Throwable} instance
 184.386 -     *          (which may be {@code null}).
 184.387 -     */
 184.388 -    public String getMessage() {
 184.389 -        return detailMessage;
 184.390 -    }
 184.391 -
 184.392 -    /**
 184.393 -     * Creates a localized description of this throwable.
 184.394 -     * Subclasses may override this method in order to produce a
 184.395 -     * locale-specific message.  For subclasses that do not override this
 184.396 -     * method, the default implementation returns the same result as
 184.397 -     * {@code getMessage()}.
 184.398 -     *
 184.399 -     * @return  The localized description of this throwable.
 184.400 -     * @since   JDK1.1
 184.401 -     */
 184.402 -    public String getLocalizedMessage() {
 184.403 -        return getMessage();
 184.404 -    }
 184.405 -
 184.406 -    /**
 184.407 -     * Returns the cause of this throwable or {@code null} if the
 184.408 -     * cause is nonexistent or unknown.  (The cause is the throwable that
 184.409 -     * caused this throwable to get thrown.)
 184.410 -     *
 184.411 -     * <p>This implementation returns the cause that was supplied via one of
 184.412 -     * the constructors requiring a {@code Throwable}, or that was set after
 184.413 -     * creation with the {@link #initCause(Throwable)} method.  While it is
 184.414 -     * typically unnecessary to override this method, a subclass can override
 184.415 -     * it to return a cause set by some other means.  This is appropriate for
 184.416 -     * a "legacy chained throwable" that predates the addition of chained
 184.417 -     * exceptions to {@code Throwable}.  Note that it is <i>not</i>
 184.418 -     * necessary to override any of the {@code PrintStackTrace} methods,
 184.419 -     * all of which invoke the {@code getCause} method to determine the
 184.420 -     * cause of a throwable.
 184.421 -     *
 184.422 -     * @return  the cause of this throwable or {@code null} if the
 184.423 -     *          cause is nonexistent or unknown.
 184.424 -     * @since 1.4
 184.425 -     */
 184.426 -    public synchronized Throwable getCause() {
 184.427 -        return (cause==this ? null : cause);
 184.428 -    }
 184.429 -
 184.430 -    /**
 184.431 -     * Initializes the <i>cause</i> of this throwable to the specified value.
 184.432 -     * (The cause is the throwable that caused this throwable to get thrown.)
 184.433 -     *
 184.434 -     * <p>This method can be called at most once.  It is generally called from
 184.435 -     * within the constructor, or immediately after creating the
 184.436 -     * throwable.  If this throwable was created
 184.437 -     * with {@link #Throwable(Throwable)} or
 184.438 -     * {@link #Throwable(String,Throwable)}, this method cannot be called
 184.439 -     * even once.
 184.440 -     *
 184.441 -     * <p>An example of using this method on a legacy throwable type
 184.442 -     * without other support for setting the cause is:
 184.443 -     *
 184.444 -     * <pre>
 184.445 -     * try {
 184.446 -     *     lowLevelOp();
 184.447 -     * } catch (LowLevelException le) {
 184.448 -     *     throw (HighLevelException)
 184.449 -     *           new HighLevelException().initCause(le); // Legacy constructor
 184.450 -     * }
 184.451 -     * </pre>
 184.452 -     *
 184.453 -     * @param  cause the cause (which is saved for later retrieval by the
 184.454 -     *         {@link #getCause()} method).  (A {@code null} value is
 184.455 -     *         permitted, and indicates that the cause is nonexistent or
 184.456 -     *         unknown.)
 184.457 -     * @return  a reference to this {@code Throwable} instance.
 184.458 -     * @throws IllegalArgumentException if {@code cause} is this
 184.459 -     *         throwable.  (A throwable cannot be its own cause.)
 184.460 -     * @throws IllegalStateException if this throwable was
 184.461 -     *         created with {@link #Throwable(Throwable)} or
 184.462 -     *         {@link #Throwable(String,Throwable)}, or this method has already
 184.463 -     *         been called on this throwable.
 184.464 -     * @since  1.4
 184.465 -     */
 184.466 -    public synchronized Throwable initCause(Throwable cause) {
 184.467 -        if (this.cause != this)
 184.468 -            throw new IllegalStateException("Can't overwrite cause");
 184.469 -        if (cause == this)
 184.470 -            throw new IllegalArgumentException("Self-causation not permitted");
 184.471 -        this.cause = cause;
 184.472 -        return this;
 184.473 -    }
 184.474 -
 184.475 -    /**
 184.476 -     * Returns a short description of this throwable.
 184.477 -     * The result is the concatenation of:
 184.478 -     * <ul>
 184.479 -     * <li> the {@linkplain Class#getName() name} of the class of this object
 184.480 -     * <li> ": " (a colon and a space)
 184.481 -     * <li> the result of invoking this object's {@link #getLocalizedMessage}
 184.482 -     *      method
 184.483 -     * </ul>
 184.484 -     * If {@code getLocalizedMessage} returns {@code null}, then just
 184.485 -     * the class name is returned.
 184.486 -     *
 184.487 -     * @return a string representation of this throwable.
 184.488 -     */
 184.489 -    public String toString() {
 184.490 -        String s = getClass().getName();
 184.491 -        String message = getLocalizedMessage();
 184.492 -        return (message != null) ? (s + ": " + message) : s;
 184.493 -    }
 184.494 -
 184.495 -    /**
 184.496 -     * Prints this throwable and its backtrace to the
 184.497 -     * standard error stream. This method prints a stack trace for this
 184.498 -     * {@code Throwable} object on the error output stream that is
 184.499 -     * the value of the field {@code System.err}. The first line of
 184.500 -     * output contains the result of the {@link #toString()} method for
 184.501 -     * this object.  Remaining lines represent data previously recorded by
 184.502 -     * the method {@link #fillInStackTrace()}. The format of this
 184.503 -     * information depends on the implementation, but the following
 184.504 -     * example may be regarded as typical:
 184.505 -     * <blockquote><pre>
 184.506 -     * java.lang.NullPointerException
 184.507 -     *         at MyClass.mash(MyClass.java:9)
 184.508 -     *         at MyClass.crunch(MyClass.java:6)
 184.509 -     *         at MyClass.main(MyClass.java:3)
 184.510 -     * </pre></blockquote>
 184.511 -     * This example was produced by running the program:
 184.512 -     * <pre>
 184.513 -     * class MyClass {
 184.514 -     *     public static void main(String[] args) {
 184.515 -     *         crunch(null);
 184.516 -     *     }
 184.517 -     *     static void crunch(int[] a) {
 184.518 -     *         mash(a);
 184.519 -     *     }
 184.520 -     *     static void mash(int[] b) {
 184.521 -     *         System.out.println(b[0]);
 184.522 -     *     }
 184.523 -     * }
 184.524 -     * </pre>
 184.525 -     * The backtrace for a throwable with an initialized, non-null cause
 184.526 -     * should generally include the backtrace for the cause.  The format
 184.527 -     * of this information depends on the implementation, but the following
 184.528 -     * example may be regarded as typical:
 184.529 -     * <pre>
 184.530 -     * HighLevelException: MidLevelException: LowLevelException
 184.531 -     *         at Junk.a(Junk.java:13)
 184.532 -     *         at Junk.main(Junk.java:4)
 184.533 -     * Caused by: MidLevelException: LowLevelException
 184.534 -     *         at Junk.c(Junk.java:23)
 184.535 -     *         at Junk.b(Junk.java:17)
 184.536 -     *         at Junk.a(Junk.java:11)
 184.537 -     *         ... 1 more
 184.538 -     * Caused by: LowLevelException
 184.539 -     *         at Junk.e(Junk.java:30)
 184.540 -     *         at Junk.d(Junk.java:27)
 184.541 -     *         at Junk.c(Junk.java:21)
 184.542 -     *         ... 3 more
 184.543 -     * </pre>
 184.544 -     * Note the presence of lines containing the characters {@code "..."}.
 184.545 -     * These lines indicate that the remainder of the stack trace for this
 184.546 -     * exception matches the indicated number of frames from the bottom of the
 184.547 -     * stack trace of the exception that was caused by this exception (the
 184.548 -     * "enclosing" exception).  This shorthand can greatly reduce the length
 184.549 -     * of the output in the common case where a wrapped exception is thrown
 184.550 -     * from same method as the "causative exception" is caught.  The above
 184.551 -     * example was produced by running the program:
 184.552 -     * <pre>
 184.553 -     * public class Junk {
 184.554 -     *     public static void main(String args[]) {
 184.555 -     *         try {
 184.556 -     *             a();
 184.557 -     *         } catch(HighLevelException e) {
 184.558 -     *             e.printStackTrace();
 184.559 -     *         }
 184.560 -     *     }
 184.561 -     *     static void a() throws HighLevelException {
 184.562 -     *         try {
 184.563 -     *             b();
 184.564 -     *         } catch(MidLevelException e) {
 184.565 -     *             throw new HighLevelException(e);
 184.566 -     *         }
 184.567 -     *     }
 184.568 -     *     static void b() throws MidLevelException {
 184.569 -     *         c();
 184.570 -     *     }
 184.571 -     *     static void c() throws MidLevelException {
 184.572 -     *         try {
 184.573 -     *             d();
 184.574 -     *         } catch(LowLevelException e) {
 184.575 -     *             throw new MidLevelException(e);
 184.576 -     *         }
 184.577 -     *     }
 184.578 -     *     static void d() throws LowLevelException {
 184.579 -     *        e();
 184.580 -     *     }
 184.581 -     *     static void e() throws LowLevelException {
 184.582 -     *         throw new LowLevelException();
 184.583 -     *     }
 184.584 -     * }
 184.585 -     *
 184.586 -     * class HighLevelException extends Exception {
 184.587 -     *     HighLevelException(Throwable cause) { super(cause); }
 184.588 -     * }
 184.589 -     *
 184.590 -     * class MidLevelException extends Exception {
 184.591 -     *     MidLevelException(Throwable cause)  { super(cause); }
 184.592 -     * }
 184.593 -     *
 184.594 -     * class LowLevelException extends Exception {
 184.595 -     * }
 184.596 -     * </pre>
 184.597 -     * As of release 7, the platform supports the notion of
 184.598 -     * <i>suppressed exceptions</i> (in conjunction with the {@code
 184.599 -     * try}-with-resources statement). Any exceptions that were
 184.600 -     * suppressed in order to deliver an exception are printed out
 184.601 -     * beneath the stack trace.  The format of this information
 184.602 -     * depends on the implementation, but the following example may be
 184.603 -     * regarded as typical:
 184.604 -     *
 184.605 -     * <pre>
 184.606 -     * Exception in thread "main" java.lang.Exception: Something happened
 184.607 -     *  at Foo.bar(Foo.java:10)
 184.608 -     *  at Foo.main(Foo.java:5)
 184.609 -     *  Suppressed: Resource$CloseFailException: Resource ID = 0
 184.610 -     *          at Resource.close(Resource.java:26)
 184.611 -     *          at Foo.bar(Foo.java:9)
 184.612 -     *          ... 1 more
 184.613 -     * </pre>
 184.614 -     * Note that the "... n more" notation is used on suppressed exceptions
 184.615 -     * just at it is used on causes. Unlike causes, suppressed exceptions are
 184.616 -     * indented beyond their "containing exceptions."
 184.617 -     *
 184.618 -     * <p>An exception can have both a cause and one or more suppressed
 184.619 -     * exceptions:
 184.620 -     * <pre>
 184.621 -     * Exception in thread "main" java.lang.Exception: Main block
 184.622 -     *  at Foo3.main(Foo3.java:7)
 184.623 -     *  Suppressed: Resource$CloseFailException: Resource ID = 2
 184.624 -     *          at Resource.close(Resource.java:26)
 184.625 -     *          at Foo3.main(Foo3.java:5)
 184.626 -     *  Suppressed: Resource$CloseFailException: Resource ID = 1
 184.627 -     *          at Resource.close(Resource.java:26)
 184.628 -     *          at Foo3.main(Foo3.java:5)
 184.629 -     * Caused by: java.lang.Exception: I did it
 184.630 -     *  at Foo3.main(Foo3.java:8)
 184.631 -     * </pre>
 184.632 -     * Likewise, a suppressed exception can have a cause:
 184.633 -     * <pre>
 184.634 -     * Exception in thread "main" java.lang.Exception: Main block
 184.635 -     *  at Foo4.main(Foo4.java:6)
 184.636 -     *  Suppressed: Resource2$CloseFailException: Resource ID = 1
 184.637 -     *          at Resource2.close(Resource2.java:20)
 184.638 -     *          at Foo4.main(Foo4.java:5)
 184.639 -     *  Caused by: java.lang.Exception: Rats, you caught me
 184.640 -     *          at Resource2$CloseFailException.<init>(Resource2.java:45)
 184.641 -     *          ... 2 more
 184.642 -     * </pre>
 184.643 -     */
 184.644 -//    public void printStackTrace() {
 184.645 -//        printStackTrace(System.err);
 184.646 -//    }
 184.647 -//
 184.648 -//    /**
 184.649 -//     * Prints this throwable and its backtrace to the specified print stream.
 184.650 -//     *
 184.651 -//     * @param s {@code PrintStream} to use for output
 184.652 -//     */
 184.653 -//    public void printStackTrace(PrintStream s) {
 184.654 -//        printStackTrace(new WrappedPrintStream(s));
 184.655 -//    }
 184.656 -//
 184.657 -//    private void printStackTrace(PrintStreamOrWriter s) {
 184.658 -//        // Guard against malicious overrides of Throwable.equals by
 184.659 -//        // using a Set with identity equality semantics.
 184.660 -////        Set<Throwable> dejaVu =
 184.661 -////            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
 184.662 -////        dejaVu.add(this);
 184.663 -//
 184.664 -//        synchronized (s.lock()) {
 184.665 -//            // Print our stack trace
 184.666 -//            s.println(this);
 184.667 -//            StackTraceElement[] trace = getOurStackTrace();
 184.668 -//            for (StackTraceElement traceElement : trace)
 184.669 -//                s.println("\tat " + traceElement);
 184.670 -//
 184.671 -//            // Print suppressed exceptions, if any
 184.672 -////            for (Throwable se : getSuppressed())
 184.673 -////                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
 184.674 -//
 184.675 -//            // Print cause, if any
 184.676 -//            Throwable ourCause = getCause();
 184.677 -////            if (ourCause != null)
 184.678 -////                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
 184.679 -//        }
 184.680 -//    }
 184.681 -//
 184.682 -//    /**
 184.683 -//     * Print our stack trace as an enclosed exception for the specified
 184.684 -//     * stack trace.
 184.685 -//     */
 184.686 -//    private void printEnclosedStackTrace(PrintStreamOrWriter s,
 184.687 -//                                         StackTraceElement[] enclosingTrace,
 184.688 -//                                         String caption,
 184.689 -//                                         String prefix,
 184.690 -//                                         Object dejaVu) {
 184.691 -//        assert Thread.holdsLock(s.lock());
 184.692 -//        {
 184.693 -//            // Compute number of frames in common between this and enclosing trace
 184.694 -//            StackTraceElement[] trace = getOurStackTrace();
 184.695 -//            int m = trace.length - 1;
 184.696 -//            int n = enclosingTrace.length - 1;
 184.697 -//            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
 184.698 -//                m--; n--;
 184.699 -//            }
 184.700 -//            int framesInCommon = trace.length - 1 - m;
 184.701 -//
 184.702 -//            // Print our stack trace
 184.703 -//            s.println(prefix + caption + this);
 184.704 -//            for (int i = 0; i <= m; i++)
 184.705 -//                s.println(prefix + "\tat " + trace[i]);
 184.706 -//            if (framesInCommon != 0)
 184.707 -//                s.println(prefix + "\t... " + framesInCommon + " more");
 184.708 -//
 184.709 -//            // Print suppressed exceptions, if any
 184.710 -//            for (Throwable se : getSuppressed())
 184.711 -//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
 184.712 -//                                           prefix +"\t", dejaVu);
 184.713 -//
 184.714 -//            // Print cause, if any
 184.715 -//            Throwable ourCause = getCause();
 184.716 -//            if (ourCause != null)
 184.717 -//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
 184.718 -//        }
 184.719 -//    }
 184.720 -//
 184.721 -//    /**
 184.722 -//     * Prints this throwable and its backtrace to the specified
 184.723 -//     * print writer.
 184.724 -//     *
 184.725 -//     * @param s {@code PrintWriter} to use for output
 184.726 -//     * @since   JDK1.1
 184.727 -//     */
 184.728 -//    public void printStackTrace(PrintWriter s) {
 184.729 -//        printStackTrace(new WrappedPrintWriter(s));
 184.730 -//    }
 184.731 -//
 184.732 -//    /**
 184.733 -//     * Wrapper class for PrintStream and PrintWriter to enable a single
 184.734 -//     * implementation of printStackTrace.
 184.735 -//     */
 184.736 -//    private abstract static class PrintStreamOrWriter {
 184.737 -//        /** Returns the object to be locked when using this StreamOrWriter */
 184.738 -//        abstract Object lock();
 184.739 -//
 184.740 -//        /** Prints the specified string as a line on this StreamOrWriter */
 184.741 -//        abstract void println(Object o);
 184.742 -//    }
 184.743 -//
 184.744 -//    private static class WrappedPrintStream extends PrintStreamOrWriter {
 184.745 -//        private final PrintStream printStream;
 184.746 -//
 184.747 -//        WrappedPrintStream(PrintStream printStream) {
 184.748 -//            this.printStream = printStream;
 184.749 -//        }
 184.750 -//
 184.751 -//        Object lock() {
 184.752 -//            return printStream;
 184.753 -//        }
 184.754 -//
 184.755 -//        void println(Object o) {
 184.756 -//            printStream.println(o);
 184.757 -//        }
 184.758 -//    }
 184.759 -//
 184.760 -//    private static class WrappedPrintWriter extends PrintStreamOrWriter {
 184.761 -//        private final PrintWriter printWriter;
 184.762 -//
 184.763 -//        WrappedPrintWriter(PrintWriter printWriter) {
 184.764 -//            this.printWriter = printWriter;
 184.765 -//        }
 184.766 -//
 184.767 -//        Object lock() {
 184.768 -//            return printWriter;
 184.769 -//        }
 184.770 -//
 184.771 -//        void println(Object o) {
 184.772 -//            printWriter.println(o);
 184.773 -//        }
 184.774 -//    }
 184.775 -
 184.776 -    /**
 184.777 -     * Fills in the execution stack trace. This method records within this
 184.778 -     * {@code Throwable} object information about the current state of
 184.779 -     * the stack frames for the current thread.
 184.780 -     *
 184.781 -     * <p>If the stack trace of this {@code Throwable} {@linkplain
 184.782 -     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 184.783 -     * writable}, calling this method has no effect.
 184.784 -     *
 184.785 -     * @return  a reference to this {@code Throwable} instance.
 184.786 -     * @see     java.lang.Throwable#printStackTrace()
 184.787 -     */
 184.788 -    public synchronized Throwable fillInStackTrace() {
 184.789 -        if (stackTrace != null ||
 184.790 -            backtrace != null /* Out of protocol state */ ) {
 184.791 -            fillInStackTrace(0);
 184.792 -            stackTrace = UNASSIGNED_STACK;
 184.793 -        }
 184.794 -        return this;
 184.795 -    }
 184.796 -
 184.797 -    @JavaScriptBody(args = { "dummy" }, body = "")
 184.798 -    private native Throwable fillInStackTrace(int dummy);
 184.799 -
 184.800 -    /**
 184.801 -     * Provides programmatic access to the stack trace information printed by
 184.802 -     * {@link #printStackTrace()}.  Returns an array of stack trace elements,
 184.803 -     * each representing one stack frame.  The zeroth element of the array
 184.804 -     * (assuming the array's length is non-zero) represents the top of the
 184.805 -     * stack, which is the last method invocation in the sequence.  Typically,
 184.806 -     * this is the point at which this throwable was created and thrown.
 184.807 -     * The last element of the array (assuming the array's length is non-zero)
 184.808 -     * represents the bottom of the stack, which is the first method invocation
 184.809 -     * in the sequence.
 184.810 -     *
 184.811 -     * <p>Some virtual machines may, under some circumstances, omit one
 184.812 -     * or more stack frames from the stack trace.  In the extreme case,
 184.813 -     * a virtual machine that has no stack trace information concerning
 184.814 -     * this throwable is permitted to return a zero-length array from this
 184.815 -     * method.  Generally speaking, the array returned by this method will
 184.816 -     * contain one element for every frame that would be printed by
 184.817 -     * {@code printStackTrace}.  Writes to the returned array do not
 184.818 -     * affect future calls to this method.
 184.819 -     *
 184.820 -     * @return an array of stack trace elements representing the stack trace
 184.821 -     *         pertaining to this throwable.
 184.822 -     * @since  1.4
 184.823 -     */
 184.824 -    public StackTraceElement[] getStackTrace() {
 184.825 -        return getOurStackTrace().clone();
 184.826 -    }
 184.827 -
 184.828 -    private synchronized StackTraceElement[] getOurStackTrace() {
 184.829 -        // Initialize stack trace field with information from
 184.830 -        // backtrace if this is the first call to this method
 184.831 -        if (stackTrace == UNASSIGNED_STACK ||
 184.832 -            (stackTrace == null && backtrace != null) /* Out of protocol state */) {
 184.833 -            int depth = getStackTraceDepth();
 184.834 -            stackTrace = new StackTraceElement[depth];
 184.835 -            for (int i=0; i < depth; i++)
 184.836 -                stackTrace[i] = getStackTraceElement(i);
 184.837 -        } else if (stackTrace == null) {
 184.838 -            return UNASSIGNED_STACK;
 184.839 -        }
 184.840 -        return stackTrace;
 184.841 -    }
 184.842 -
 184.843 -    /**
 184.844 -     * Sets the stack trace elements that will be returned by
 184.845 -     * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
 184.846 -     * and related methods.
 184.847 -     *
 184.848 -     * This method, which is designed for use by RPC frameworks and other
 184.849 -     * advanced systems, allows the client to override the default
 184.850 -     * stack trace that is either generated by {@link #fillInStackTrace()}
 184.851 -     * when a throwable is constructed or deserialized when a throwable is
 184.852 -     * read from a serialization stream.
 184.853 -     *
 184.854 -     * <p>If the stack trace of this {@code Throwable} {@linkplain
 184.855 -     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 184.856 -     * writable}, calling this method has no effect other than
 184.857 -     * validating its argument.
 184.858 -     *
 184.859 -     * @param   stackTrace the stack trace elements to be associated with
 184.860 -     * this {@code Throwable}.  The specified array is copied by this
 184.861 -     * call; changes in the specified array after the method invocation
 184.862 -     * returns will have no affect on this {@code Throwable}'s stack
 184.863 -     * trace.
 184.864 -     *
 184.865 -     * @throws NullPointerException if {@code stackTrace} is
 184.866 -     *         {@code null} or if any of the elements of
 184.867 -     *         {@code stackTrace} are {@code null}
 184.868 -     *
 184.869 -     * @since  1.4
 184.870 -     */
 184.871 -    public void setStackTrace(StackTraceElement[] stackTrace) {
 184.872 -        // Validate argument
 184.873 -        StackTraceElement[] defensiveCopy = stackTrace.clone();
 184.874 -        for (int i = 0; i < defensiveCopy.length; i++) {
 184.875 -            if (defensiveCopy[i] == null)
 184.876 -                throw new NullPointerException("stackTrace[" + i + "]");
 184.877 -        }
 184.878 -
 184.879 -        synchronized (this) {
 184.880 -            if (this.stackTrace == null && // Immutable stack
 184.881 -                backtrace == null) // Test for out of protocol state
 184.882 -                return;
 184.883 -            this.stackTrace = defensiveCopy;
 184.884 -        }
 184.885 -    }
 184.886 -
 184.887 -    /**
 184.888 -     * Returns the number of elements in the stack trace (or 0 if the stack
 184.889 -     * trace is unavailable).
 184.890 -     *
 184.891 -     * package-protection for use by SharedSecrets.
 184.892 -     */
 184.893 -    native int getStackTraceDepth();
 184.894 -
 184.895 -    /**
 184.896 -     * Returns the specified element of the stack trace.
 184.897 -     *
 184.898 -     * package-protection for use by SharedSecrets.
 184.899 -     *
 184.900 -     * @param index index of the element to return.
 184.901 -     * @throws IndexOutOfBoundsException if {@code index < 0 ||
 184.902 -     *         index >= getStackTraceDepth() }
 184.903 -     */
 184.904 -    native StackTraceElement getStackTraceElement(int index);
 184.905 -
 184.906 -    /**
 184.907 -     * Reads a {@code Throwable} from a stream, enforcing
 184.908 -     * well-formedness constraints on fields.  Null entries and
 184.909 -     * self-pointers are not allowed in the list of {@code
 184.910 -     * suppressedExceptions}.  Null entries are not allowed for stack
 184.911 -     * trace elements.  A null stack trace in the serial form results
 184.912 -     * in a zero-length stack element array. A single-element stack
 184.913 -     * trace whose entry is equal to {@code new StackTraceElement("",
 184.914 -     * "", null, Integer.MIN_VALUE)} results in a {@code null} {@code
 184.915 -     * stackTrace} field.
 184.916 -     *
 184.917 -     * Note that there are no constraints on the value the {@code
 184.918 -     * cause} field can hold; both {@code null} and {@code this} are
 184.919 -     * valid values for the field.
 184.920 -     */
 184.921 -//    private void readObject(ObjectInputStream s)
 184.922 -//        throws IOException, ClassNotFoundException {
 184.923 -//        s.defaultReadObject();     // read in all fields
 184.924 -//        if (suppressedExceptions != null) {
 184.925 -//            List<Throwable> suppressed = null;
 184.926 -//            if (suppressedExceptions.isEmpty()) {
 184.927 -//                // Use the sentinel for a zero-length list
 184.928 -//                suppressed = SUPPRESSED_SENTINEL;
 184.929 -//            } else { // Copy Throwables to new list
 184.930 -//                suppressed = new ArrayList<Throwable>(1);
 184.931 -//                for (Throwable t : suppressedExceptions) {
 184.932 -//                    // Enforce constraints on suppressed exceptions in
 184.933 -//                    // case of corrupt or malicious stream.
 184.934 -//                    if (t == null)
 184.935 -//                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
 184.936 -//                    if (t == this)
 184.937 -//                        throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
 184.938 -//                    suppressed.add(t);
 184.939 -//                }
 184.940 -//            }
 184.941 -//            suppressedExceptions = suppressed;
 184.942 -//        } // else a null suppressedExceptions field remains null
 184.943 -//
 184.944 -//        /*
 184.945 -//         * For zero-length stack traces, use a clone of
 184.946 -//         * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
 184.947 -//         * allow identity comparison against UNASSIGNED_STACK in
 184.948 -//         * getOurStackTrace.  The identity of UNASSIGNED_STACK in
 184.949 -//         * stackTrace indicates to the getOurStackTrace method that
 184.950 -//         * the stackTrace needs to be constructed from the information
 184.951 -//         * in backtrace.
 184.952 -//         */
 184.953 -//        if (stackTrace != null) {
 184.954 -//            if (stackTrace.length == 0) {
 184.955 -//                stackTrace = UNASSIGNED_STACK.clone();
 184.956 -//            }  else if (stackTrace.length == 1 &&
 184.957 -//                        // Check for the marker of an immutable stack trace
 184.958 -//                        SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
 184.959 -//                stackTrace = null;
 184.960 -//            } else { // Verify stack trace elements are non-null.
 184.961 -//                for(StackTraceElement ste : stackTrace) {
 184.962 -//                    if (ste == null)
 184.963 -//                        throw new NullPointerException("null StackTraceElement in serial stream. ");
 184.964 -//                }
 184.965 -//            }
 184.966 -//        } else {
 184.967 -//            // A null stackTrace field in the serial form can result
 184.968 -//            // from an exception serialized without that field in
 184.969 -//            // older JDK releases; treat such exceptions as having
 184.970 -//            // empty stack traces.
 184.971 -//            stackTrace = UNASSIGNED_STACK.clone();
 184.972 -//        }
 184.973 -//    }
 184.974 -
 184.975 -    /**
 184.976 -     * Write a {@code Throwable} object to a stream.
 184.977 -     *
 184.978 -     * A {@code null} stack trace field is represented in the serial
 184.979 -     * form as a one-element array whose element is equal to {@code
 184.980 -     * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
 184.981 -     */
 184.982 -//    private synchronized void writeObject(ObjectOutputStream s)
 184.983 -//        throws IOException {
 184.984 -//        // Ensure that the stackTrace field is initialized to a
 184.985 -//        // non-null value, if appropriate.  As of JDK 7, a null stack
 184.986 -//        // trace field is a valid value indicating the stack trace
 184.987 -//        // should not be set.
 184.988 -//        getOurStackTrace();
 184.989 -//
 184.990 -//        StackTraceElement[] oldStackTrace = stackTrace;
 184.991 -//        try {
 184.992 -//            if (stackTrace == null)
 184.993 -//                stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
 184.994 -//            s.defaultWriteObject();
 184.995 -//        } finally {
 184.996 -//            stackTrace = oldStackTrace;
 184.997 -//        }
 184.998 -//    }
 184.999 -
184.1000 -    /**
184.1001 -     * Appends the specified exception to the exceptions that were
184.1002 -     * suppressed in order to deliver this exception. This method is
184.1003 -     * thread-safe and typically called (automatically and implicitly)
184.1004 -     * by the {@code try}-with-resources statement.
184.1005 -     *
184.1006 -     * <p>The suppression behavior is enabled <em>unless</em> disabled
184.1007 -     * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
184.1008 -     * a constructor}.  When suppression is disabled, this method does
184.1009 -     * nothing other than to validate its argument.
184.1010 -     *
184.1011 -     * <p>Note that when one exception {@linkplain
184.1012 -     * #initCause(Throwable) causes} another exception, the first
184.1013 -     * exception is usually caught and then the second exception is
184.1014 -     * thrown in response.  In other words, there is a causal
184.1015 -     * connection between the two exceptions.
184.1016 -     *
184.1017 -     * In contrast, there are situations where two independent
184.1018 -     * exceptions can be thrown in sibling code blocks, in particular
184.1019 -     * in the {@code try} block of a {@code try}-with-resources
184.1020 -     * statement and the compiler-generated {@code finally} block
184.1021 -     * which closes the resource.
184.1022 -     *
184.1023 -     * In these situations, only one of the thrown exceptions can be
184.1024 -     * propagated.  In the {@code try}-with-resources statement, when
184.1025 -     * there are two such exceptions, the exception originating from
184.1026 -     * the {@code try} block is propagated and the exception from the
184.1027 -     * {@code finally} block is added to the list of exceptions
184.1028 -     * suppressed by the exception from the {@code try} block.  As an
184.1029 -     * exception unwinds the stack, it can accumulate multiple
184.1030 -     * suppressed exceptions.
184.1031 -     *
184.1032 -     * <p>An exception may have suppressed exceptions while also being
184.1033 -     * caused by another exception.  Whether or not an exception has a
184.1034 -     * cause is semantically known at the time of its creation, unlike
184.1035 -     * whether or not an exception will suppress other exceptions
184.1036 -     * which is typically only determined after an exception is
184.1037 -     * thrown.
184.1038 -     *
184.1039 -     * <p>Note that programmer written code is also able to take
184.1040 -     * advantage of calling this method in situations where there are
184.1041 -     * multiple sibling exceptions and only one can be propagated.
184.1042 -     *
184.1043 -     * @param exception the exception to be added to the list of
184.1044 -     *        suppressed exceptions
184.1045 -     * @throws IllegalArgumentException if {@code exception} is this
184.1046 -     *         throwable; a throwable cannot suppress itself.
184.1047 -     * @throws NullPointerException if {@code exception} is {@code null}
184.1048 -     * @since 1.7
184.1049 -     */
184.1050 -    public final synchronized void addSuppressed(Throwable exception) {
184.1051 -        if (exception == this)
184.1052 -            throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
184.1053 -
184.1054 -        if (exception == null)
184.1055 -            throw new NullPointerException(NULL_CAUSE_MESSAGE);
184.1056 -
184.1057 -//        if (suppressedExceptions == null) // Suppressed exceptions not recorded
184.1058 -//            return;
184.1059 -//
184.1060 -//        if (suppressedExceptions == SUPPRESSED_SENTINEL)
184.1061 -//            suppressedExceptions = new ArrayList<Throwable>(1);
184.1062 -//
184.1063 -//        suppressedExceptions.add(exception);
184.1064 -    }
184.1065 -
184.1066 -    private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
184.1067 -
184.1068 -    /**
184.1069 -     * Returns an array containing all of the exceptions that were
184.1070 -     * suppressed, typically by the {@code try}-with-resources
184.1071 -     * statement, in order to deliver this exception.
184.1072 -     *
184.1073 -     * If no exceptions were suppressed or {@linkplain
184.1074 -     * #Throwable(String, Throwable, boolean, boolean) suppression is
184.1075 -     * disabled}, an empty array is returned.  This method is
184.1076 -     * thread-safe.  Writes to the returned array do not affect future
184.1077 -     * calls to this method.
184.1078 -     *
184.1079 -     * @return an array containing all of the exceptions that were
184.1080 -     *         suppressed to deliver this exception.
184.1081 -     * @since 1.7
184.1082 -     */
184.1083 -    public final synchronized Throwable[] getSuppressed() {
184.1084 -        return new Throwable[0];
184.1085 -//        if (suppressedExceptions == SUPPRESSED_SENTINEL ||
184.1086 -//            suppressedExceptions == null)
184.1087 -//            return EMPTY_THROWABLE_ARRAY;
184.1088 -//        else
184.1089 -//            return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
184.1090 -    }
184.1091 -}
   185.1 --- a/emul/mini/src/main/java/java/lang/VirtualMachineError.java	Mon Feb 25 19:00:08 2013 +0100
   185.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   185.3 @@ -1,54 +0,0 @@
   185.4 -/*
   185.5 - * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
   185.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   185.7 - *
   185.8 - * This code is free software; you can redistribute it and/or modify it
   185.9 - * under the terms of the GNU General Public License version 2 only, as
  185.10 - * published by the Free Software Foundation.  Oracle designates this
  185.11 - * particular file as subject to the "Classpath" exception as provided
  185.12 - * by Oracle in the LICENSE file that accompanied this code.
  185.13 - *
  185.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  185.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  185.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  185.17 - * version 2 for more details (a copy is included in the LICENSE file that
  185.18 - * accompanied this code).
  185.19 - *
  185.20 - * You should have received a copy of the GNU General Public License version
  185.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  185.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  185.23 - *
  185.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  185.25 - * or visit www.oracle.com if you need additional information or have any
  185.26 - * questions.
  185.27 - */
  185.28 -
  185.29 -package java.lang;
  185.30 -
  185.31 -/**
  185.32 - * Thrown to indicate that the Java Virtual Machine is broken or has
  185.33 - * run out of resources necessary for it to continue operating.
  185.34 - *
  185.35 - *
  185.36 - * @author  Frank Yellin
  185.37 - * @since   JDK1.0
  185.38 - */
  185.39 -abstract public
  185.40 -class VirtualMachineError extends Error {
  185.41 -    /**
  185.42 -     * Constructs a <code>VirtualMachineError</code> with no detail message.
  185.43 -     */
  185.44 -    public VirtualMachineError() {
  185.45 -        super();
  185.46 -    }
  185.47 -
  185.48 -    /**
  185.49 -     * Constructs a <code>VirtualMachineError</code> with the specified
  185.50 -     * detail message.
  185.51 -     *
  185.52 -     * @param   s   the detail message.
  185.53 -     */
  185.54 -    public VirtualMachineError(String s) {
  185.55 -        super(s);
  185.56 -    }
  185.57 -}
   186.1 --- a/emul/mini/src/main/java/java/lang/Void.java	Mon Feb 25 19:00:08 2013 +0100
   186.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   186.3 @@ -1,49 +0,0 @@
   186.4 -/*
   186.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   186.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   186.7 - *
   186.8 - * This code is free software; you can redistribute it and/or modify it
   186.9 - * under the terms of the GNU General Public License version 2 only, as
  186.10 - * published by the Free Software Foundation.  Oracle designates this
  186.11 - * particular file as subject to the "Classpath" exception as provided
  186.12 - * by Oracle in the LICENSE file that accompanied this code.
  186.13 - *
  186.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  186.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  186.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  186.17 - * version 2 for more details (a copy is included in the LICENSE file that
  186.18 - * accompanied this code).
  186.19 - *
  186.20 - * You should have received a copy of the GNU General Public License version
  186.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  186.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  186.23 - *
  186.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  186.25 - * or visit www.oracle.com if you need additional information or have any
  186.26 - * questions.
  186.27 - */
  186.28 -
  186.29 -package java.lang;
  186.30 -
  186.31 -/**
  186.32 - * The {@code Void} class is an uninstantiable placeholder class to hold a
  186.33 - * reference to the {@code Class} object representing the Java keyword
  186.34 - * void.
  186.35 - *
  186.36 - * @author  unascribed
  186.37 - * @since   JDK1.1
  186.38 - */
  186.39 -public final
  186.40 -class Void {
  186.41 -
  186.42 -    /**
  186.43 -     * The {@code Class} object representing the pseudo-type corresponding to
  186.44 -     * the keyword {@code void}.
  186.45 -     */
  186.46 -    public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
  186.47 -
  186.48 -    /*
  186.49 -     * The Void class cannot be instantiated.
  186.50 -     */
  186.51 -    private Void() {}
  186.52 -}
   187.1 --- a/emul/mini/src/main/java/java/lang/annotation/Annotation.java	Mon Feb 25 19:00:08 2013 +0100
   187.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   187.3 @@ -1,131 +0,0 @@
   187.4 -/*
   187.5 - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
   187.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   187.7 - *
   187.8 - * This code is free software; you can redistribute it and/or modify it
   187.9 - * under the terms of the GNU General Public License version 2 only, as
  187.10 - * published by the Free Software Foundation.  Oracle designates this
  187.11 - * particular file as subject to the "Classpath" exception as provided
  187.12 - * by Oracle in the LICENSE file that accompanied this code.
  187.13 - *
  187.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  187.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  187.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  187.17 - * version 2 for more details (a copy is included in the LICENSE file that
  187.18 - * accompanied this code).
  187.19 - *
  187.20 - * You should have received a copy of the GNU General Public License version
  187.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  187.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  187.23 - *
  187.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  187.25 - * or visit www.oracle.com if you need additional information or have any
  187.26 - * questions.
  187.27 - */
  187.28 -
  187.29 -package java.lang.annotation;
  187.30 -
  187.31 -/**
  187.32 - * The common interface extended by all annotation types.  Note that an
  187.33 - * interface that manually extends this one does <i>not</i> define
  187.34 - * an annotation type.  Also note that this interface does not itself
  187.35 - * define an annotation type.
  187.36 - *
  187.37 - * More information about annotation types can be found in section 9.6 of
  187.38 - * <cite>The Java&trade; Language Specification</cite>.
  187.39 - *
  187.40 - * @author  Josh Bloch
  187.41 - * @since   1.5
  187.42 - */
  187.43 -public interface Annotation {
  187.44 -    /**
  187.45 -     * Returns true if the specified object represents an annotation
  187.46 -     * that is logically equivalent to this one.  In other words,
  187.47 -     * returns true if the specified object is an instance of the same
  187.48 -     * annotation type as this instance, all of whose members are equal
  187.49 -     * to the corresponding member of this annotation, as defined below:
  187.50 -     * <ul>
  187.51 -     *    <li>Two corresponding primitive typed members whose values are
  187.52 -     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
  187.53 -     *    unless their type is <tt>float</tt> or <tt>double</tt>.
  187.54 -     *
  187.55 -     *    <li>Two corresponding <tt>float</tt> members whose values
  187.56 -     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  187.57 -     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
  187.58 -     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  187.59 -     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
  187.60 -     *
  187.61 -     *    <li>Two corresponding <tt>double</tt> members whose values
  187.62 -     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  187.63 -     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
  187.64 -     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  187.65 -     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
  187.66 -     *
  187.67 -     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
  187.68 -     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
  187.69 -     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
  187.70 -     *    definition is recursive for annotation typed members.)
  187.71 -     *
  187.72 -     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
  187.73 -     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
  187.74 -     *    appropriate overloading of {@link java.util.Arrays#equals}.
  187.75 -     * </ul>
  187.76 -     *
  187.77 -     * @return true if the specified object represents an annotation
  187.78 -     *     that is logically equivalent to this one, otherwise false
  187.79 -     */
  187.80 -    boolean equals(Object obj);
  187.81 -
  187.82 -    /**
  187.83 -     * Returns the hash code of this annotation, as defined below:
  187.84 -     *
  187.85 -     * <p>The hash code of an annotation is the sum of the hash codes
  187.86 -     * of its members (including those with default values), as defined
  187.87 -     * below:
  187.88 -     *
  187.89 -     * The hash code of an annotation member is (127 times the hash code
  187.90 -     * of the member-name as computed by {@link String#hashCode()}) XOR
  187.91 -     * the hash code of the member-value, as defined below:
  187.92 -     *
  187.93 -     * <p>The hash code of a member-value depends on its type:
  187.94 -     * <ul>
  187.95 -     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
  187.96 -     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
  187.97 -     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
  187.98 -     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
  187.99 -     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
 187.100 -     *     {@link Long}, {@link Short}, or {@link Boolean}).
 187.101 -     *
 187.102 -     * <li>The hash code of a string, enum, class, or annotation member-value
 187.103 -     I     <tt><i>v</i></tt> is computed as by calling
 187.104 -     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
 187.105 -     *     member values, this is a recursive definition.)
 187.106 -     *
 187.107 -     * <li>The hash code of an array member-value is computed by calling
 187.108 -     *     the appropriate overloading of
 187.109 -     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
 187.110 -     *     on the value.  (There is one overloading for each primitive
 187.111 -     *     type, and one for object reference types.)
 187.112 -     * </ul>
 187.113 -     *
 187.114 -     * @return the hash code of this annotation
 187.115 -     */
 187.116 -    int hashCode();
 187.117 -
 187.118 -    /**
 187.119 -     * Returns a string representation of this annotation.  The details
 187.120 -     * of the representation are implementation-dependent, but the following
 187.121 -     * may be regarded as typical:
 187.122 -     * <pre>
 187.123 -     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
 187.124 -     * </pre>
 187.125 -     *
 187.126 -     * @return a string representation of this annotation
 187.127 -     */
 187.128 -    String toString();
 187.129 -
 187.130 -    /**
 187.131 -     * Returns the annotation type of this annotation.
 187.132 -     */
 187.133 -    Class<? extends Annotation> annotationType();
 187.134 -}
   188.1 --- a/emul/mini/src/main/java/java/lang/annotation/Documented.java	Mon Feb 25 19:00:08 2013 +0100
   188.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   188.3 @@ -1,43 +0,0 @@
   188.4 -/*
   188.5 - * Copyright (c) 2003, 2004, 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.lang.annotation;
  188.30 -
  188.31 -/**
  188.32 - * Indicates that annotations with a type are to be documented by javadoc
  188.33 - * and similar tools by default.  This type should be used to annotate the
  188.34 - * declarations of types whose annotations affect the use of annotated
  188.35 - * elements by their clients.  If a type declaration is annotated with
  188.36 - * Documented, its annotations become part of the public API
  188.37 - * of the annotated elements.
  188.38 - *
  188.39 - * @author  Joshua Bloch
  188.40 - * @since 1.5
  188.41 - */
  188.42 -@Documented
  188.43 -@Retention(RetentionPolicy.RUNTIME)
  188.44 -@Target(ElementType.ANNOTATION_TYPE)
  188.45 -public @interface Documented {
  188.46 -}
   189.1 --- a/emul/mini/src/main/java/java/lang/annotation/ElementType.java	Mon Feb 25 19:00:08 2013 +0100
   189.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   189.3 @@ -1,63 +0,0 @@
   189.4 -/*
   189.5 - * Copyright (c) 2003, 2011, 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.lang.annotation;
  189.30 -
  189.31 -/**
  189.32 - * A program element type.  The constants of this enumerated type
  189.33 - * provide a simple classification of the declared elements in a
  189.34 - * Java program.
  189.35 - *
  189.36 - * <p>These constants are used with the {@link Target} meta-annotation type
  189.37 - * to specify where it is legal to use an annotation type.
  189.38 - *
  189.39 - * @author  Joshua Bloch
  189.40 - * @since 1.5
  189.41 - */
  189.42 -public enum ElementType {
  189.43 -    /** Class, interface (including annotation type), or enum declaration */
  189.44 -    TYPE,
  189.45 -
  189.46 -    /** Field declaration (includes enum constants) */
  189.47 -    FIELD,
  189.48 -
  189.49 -    /** Method declaration */
  189.50 -    METHOD,
  189.51 -
  189.52 -    /** Parameter declaration */
  189.53 -    PARAMETER,
  189.54 -
  189.55 -    /** Constructor declaration */
  189.56 -    CONSTRUCTOR,
  189.57 -
  189.58 -    /** Local variable declaration */
  189.59 -    LOCAL_VARIABLE,
  189.60 -
  189.61 -    /** Annotation type declaration */
  189.62 -    ANNOTATION_TYPE,
  189.63 -
  189.64 -    /** Package declaration */
  189.65 -    PACKAGE
  189.66 -}
   190.1 --- a/emul/mini/src/main/java/java/lang/annotation/Retention.java	Mon Feb 25 19:00:08 2013 +0100
   190.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   190.3 @@ -1,47 +0,0 @@
   190.4 -/*
   190.5 - * Copyright (c) 2003, 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.lang.annotation;
  190.30 -
  190.31 -/**
  190.32 - * Indicates how long annotations with the annotated type are to
  190.33 - * be retained.  If no Retention annotation is present on
  190.34 - * an annotation type declaration, the retention policy defaults to
  190.35 - * {@code RetentionPolicy.CLASS}.
  190.36 - *
  190.37 - * <p>A Retention meta-annotation has effect only if the
  190.38 - * meta-annotated type is used directly for annotation.  It has no
  190.39 - * effect if the meta-annotated type is used as a member type in
  190.40 - * another annotation type.
  190.41 - *
  190.42 - * @author  Joshua Bloch
  190.43 - * @since 1.5
  190.44 - */
  190.45 -@Documented
  190.46 -@Retention(RetentionPolicy.RUNTIME)
  190.47 -@Target(ElementType.ANNOTATION_TYPE)
  190.48 -public @interface Retention {
  190.49 -    RetentionPolicy value();
  190.50 -}
   191.1 --- a/emul/mini/src/main/java/java/lang/annotation/RetentionPolicy.java	Mon Feb 25 19:00:08 2013 +0100
   191.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   191.3 @@ -1,57 +0,0 @@
   191.4 -/*
   191.5 - * Copyright (c) 2003, 2004, 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.lang.annotation;
  191.30 -
  191.31 -/**
  191.32 - * Annotation retention policy.  The constants of this enumerated type
  191.33 - * describe the various policies for retaining annotations.  They are used
  191.34 - * in conjunction with the {@link Retention} meta-annotation type to specify
  191.35 - * how long annotations are to be retained.
  191.36 - *
  191.37 - * @author  Joshua Bloch
  191.38 - * @since 1.5
  191.39 - */
  191.40 -public enum RetentionPolicy {
  191.41 -    /**
  191.42 -     * Annotations are to be discarded by the compiler.
  191.43 -     */
  191.44 -    SOURCE,
  191.45 -
  191.46 -    /**
  191.47 -     * Annotations are to be recorded in the class file by the compiler
  191.48 -     * but need not be retained by the VM at run time.  This is the default
  191.49 -     * behavior.
  191.50 -     */
  191.51 -    CLASS,
  191.52 -
  191.53 -    /**
  191.54 -     * Annotations are to be recorded in the class file by the compiler and
  191.55 -     * retained by the VM at run time, so they may be read reflectively.
  191.56 -     *
  191.57 -     * @see java.lang.reflect.AnnotatedElement
  191.58 -     */
  191.59 -    RUNTIME
  191.60 -}
   192.1 --- a/emul/mini/src/main/java/java/lang/annotation/Target.java	Mon Feb 25 19:00:08 2013 +0100
   192.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   192.3 @@ -1,68 +0,0 @@
   192.4 -/*
   192.5 - * Copyright (c) 2003, 2004, 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.lang.annotation;
  192.30 -
  192.31 -/**
  192.32 - * Indicates the kinds of program element to which an annotation type
  192.33 - * is applicable.  If a Target meta-annotation is not present on an
  192.34 - * annotation type declaration, the declared type may be used on any
  192.35 - * program element.  If such a meta-annotation is present, the compiler
  192.36 - * will enforce the specified usage restriction.
  192.37 - *
  192.38 - * For example, this meta-annotation indicates that the declared type is
  192.39 - * itself a meta-annotation type.  It can only be used on annotation type
  192.40 - * declarations:
  192.41 - * <pre>
  192.42 - *    &#064;Target(ElementType.ANNOTATION_TYPE)
  192.43 - *    public &#064;interface MetaAnnotationType {
  192.44 - *        ...
  192.45 - *    }
  192.46 - * </pre>
  192.47 - * This meta-annotation indicates that the declared type is intended solely
  192.48 - * for use as a member type in complex annotation type declarations.  It
  192.49 - * cannot be used to annotate anything directly:
  192.50 - * <pre>
  192.51 - *    &#064;Target({})
  192.52 - *    public &#064;interface MemberType {
  192.53 - *        ...
  192.54 - *    }
  192.55 - * </pre>
  192.56 - * It is a compile-time error for a single ElementType constant to
  192.57 - * appear more than once in a Target annotation.  For example, the
  192.58 - * following meta-annotation is illegal:
  192.59 - * <pre>
  192.60 - *    &#064;Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
  192.61 - *    public &#064;interface Bogus {
  192.62 - *        ...
  192.63 - *    }
  192.64 - * </pre>
  192.65 - */
  192.66 -@Documented
  192.67 -@Retention(RetentionPolicy.RUNTIME)
  192.68 -@Target(ElementType.ANNOTATION_TYPE)
  192.69 -public @interface Target {
  192.70 -    ElementType[] value();
  192.71 -}
   193.1 --- a/emul/mini/src/main/java/java/lang/annotation/UnsupportedOperationException.java	Mon Feb 25 19:00:08 2013 +0100
   193.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   193.3 @@ -1,94 +0,0 @@
   193.4 -/*
   193.5 - * Copyright (c) 1997, 2006, 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.lang;
  193.30 -
  193.31 -/**
  193.32 - * Thrown to indicate that the requested operation is not supported.<p>
  193.33 - *
  193.34 - * This class is a member of the
  193.35 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  193.36 - * Java Collections Framework</a>.
  193.37 - *
  193.38 - * @author  Josh Bloch
  193.39 - * @since   1.2
  193.40 - */
  193.41 -public class UnsupportedOperationException extends RuntimeException {
  193.42 -    /**
  193.43 -     * Constructs an UnsupportedOperationException with no detail message.
  193.44 -     */
  193.45 -    public UnsupportedOperationException() {
  193.46 -    }
  193.47 -
  193.48 -    /**
  193.49 -     * Constructs an UnsupportedOperationException with the specified
  193.50 -     * detail message.
  193.51 -     *
  193.52 -     * @param message the detail message
  193.53 -     */
  193.54 -    public UnsupportedOperationException(String message) {
  193.55 -        super(message);
  193.56 -    }
  193.57 -
  193.58 -    /**
  193.59 -     * Constructs a new exception with the specified detail message and
  193.60 -     * cause.
  193.61 -     *
  193.62 -     * <p>Note that the detail message associated with <code>cause</code> is
  193.63 -     * <i>not</i> automatically incorporated in this exception's detail
  193.64 -     * message.
  193.65 -     *
  193.66 -     * @param  message the detail message (which is saved for later retrieval
  193.67 -     *         by the {@link Throwable#getMessage()} method).
  193.68 -     * @param  cause the cause (which is saved for later retrieval by the
  193.69 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  193.70 -     *         is permitted, and indicates that the cause is nonexistent or
  193.71 -     *         unknown.)
  193.72 -     * @since 1.5
  193.73 -     */
  193.74 -    public UnsupportedOperationException(String message, Throwable cause) {
  193.75 -        super(message, cause);
  193.76 -    }
  193.77 -
  193.78 -    /**
  193.79 -     * Constructs a new exception with the specified cause and a detail
  193.80 -     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  193.81 -     * typically contains the class and detail message of <tt>cause</tt>).
  193.82 -     * This constructor is useful for exceptions that are little more than
  193.83 -     * wrappers for other throwables (for example, {@link
  193.84 -     * java.security.PrivilegedActionException}).
  193.85 -     *
  193.86 -     * @param  cause the cause (which is saved for later retrieval by the
  193.87 -     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  193.88 -     *         permitted, and indicates that the cause is nonexistent or
  193.89 -     *         unknown.)
  193.90 -     * @since  1.5
  193.91 -     */
  193.92 -    public UnsupportedOperationException(Throwable cause) {
  193.93 -        super(cause);
  193.94 -    }
  193.95 -
  193.96 -    static final long serialVersionUID = -1242599979055084673L;
  193.97 -}
   194.1 --- a/emul/mini/src/main/java/java/lang/reflect/AccessibleObject.java	Mon Feb 25 19:00:08 2013 +0100
   194.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   194.3 @@ -1,167 +0,0 @@
   194.4 -/*
   194.5 - * Copyright (c) 1997, 2008, 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.lang.reflect;
  194.30 -
  194.31 -import java.lang.annotation.Annotation;
  194.32 -
  194.33 -/**
  194.34 - * The AccessibleObject class is the base class for Field, Method and
  194.35 - * Constructor objects.  It provides the ability to flag a reflected
  194.36 - * object as suppressing default Java language access control checks
  194.37 - * when it is used.  The access checks--for public, default (package)
  194.38 - * access, protected, and private members--are performed when Fields,
  194.39 - * Methods or Constructors are used to set or get fields, to invoke
  194.40 - * methods, or to create and initialize new instances of classes,
  194.41 - * respectively.
  194.42 - *
  194.43 - * <p>Setting the {@code accessible} flag in a reflected object
  194.44 - * permits sophisticated applications with sufficient privilege, such
  194.45 - * as Java Object Serialization or other persistence mechanisms, to
  194.46 - * manipulate objects in a manner that would normally be prohibited.
  194.47 - *
  194.48 - * <p>By default, a reflected object is <em>not</em> accessible.
  194.49 - *
  194.50 - * @see Field
  194.51 - * @see Method
  194.52 - * @see Constructor
  194.53 - * @see ReflectPermission
  194.54 - *
  194.55 - * @since 1.2
  194.56 - */
  194.57 -public class AccessibleObject implements AnnotatedElement {
  194.58 -
  194.59 -    /**
  194.60 -     * Convenience method to set the {@code accessible} flag for an
  194.61 -     * array of objects with a single security check (for efficiency).
  194.62 -     *
  194.63 -     * <p>First, if there is a security manager, its
  194.64 -     * {@code checkPermission} method is called with a
  194.65 -     * {@code ReflectPermission("suppressAccessChecks")} permission.
  194.66 -     *
  194.67 -     * <p>A {@code SecurityException} is raised if {@code flag} is
  194.68 -     * {@code true} but accessibility of any of the elements of the input
  194.69 -     * {@code array} may not be changed (for example, if the element
  194.70 -     * object is a {@link Constructor} object for the class {@link
  194.71 -     * java.lang.Class}).  In the event of such a SecurityException, the
  194.72 -     * accessibility of objects is set to {@code flag} for array elements
  194.73 -     * upto (and excluding) the element for which the exception occurred; the
  194.74 -     * accessibility of elements beyond (and including) the element for which
  194.75 -     * the exception occurred is unchanged.
  194.76 -     *
  194.77 -     * @param array the array of AccessibleObjects
  194.78 -     * @param flag  the new value for the {@code accessible} flag
  194.79 -     *              in each object
  194.80 -     * @throws SecurityException if the request is denied.
  194.81 -     * @see SecurityManager#checkPermission
  194.82 -     * @see java.lang.RuntimePermission
  194.83 -     */
  194.84 -    public static void setAccessible(AccessibleObject[] array, boolean flag)
  194.85 -        throws SecurityException {
  194.86 -        throw new SecurityException();
  194.87 -    }
  194.88 -
  194.89 -    /**
  194.90 -     * Set the {@code accessible} flag for this object to
  194.91 -     * the indicated boolean value.  A value of {@code true} indicates that
  194.92 -     * the reflected object should suppress Java language access
  194.93 -     * checking when it is used.  A value of {@code false} indicates
  194.94 -     * that the reflected object should enforce Java language access checks.
  194.95 -     *
  194.96 -     * <p>First, if there is a security manager, its
  194.97 -     * {@code checkPermission} method is called with a
  194.98 -     * {@code ReflectPermission("suppressAccessChecks")} permission.
  194.99 -     *
 194.100 -     * <p>A {@code SecurityException} is raised if {@code flag} is
 194.101 -     * {@code true} but accessibility of this object may not be changed
 194.102 -     * (for example, if this element object is a {@link Constructor} object for
 194.103 -     * the class {@link java.lang.Class}).
 194.104 -     *
 194.105 -     * <p>A {@code SecurityException} is raised if this object is a {@link
 194.106 -     * java.lang.reflect.Constructor} object for the class
 194.107 -     * {@code java.lang.Class}, and {@code flag} is true.
 194.108 -     *
 194.109 -     * @param flag the new value for the {@code accessible} flag
 194.110 -     * @throws SecurityException if the request is denied.
 194.111 -     * @see SecurityManager#checkPermission
 194.112 -     * @see java.lang.RuntimePermission
 194.113 -     */
 194.114 -    public void setAccessible(boolean flag) throws SecurityException {
 194.115 -        throw new SecurityException();
 194.116 -    }
 194.117 -
 194.118 -    /**
 194.119 -     * Get the value of the {@code accessible} flag for this object.
 194.120 -     *
 194.121 -     * @return the value of the object's {@code accessible} flag
 194.122 -     */
 194.123 -    public boolean isAccessible() {
 194.124 -        return override;
 194.125 -    }
 194.126 -
 194.127 -    /**
 194.128 -     * Constructor: only used by the Java Virtual Machine.
 194.129 -     */
 194.130 -    protected AccessibleObject() {}
 194.131 -
 194.132 -    // Indicates whether language-level access checks are overridden
 194.133 -    // by this object. Initializes to "false". This field is used by
 194.134 -    // Field, Method, and Constructor.
 194.135 -    //
 194.136 -    // NOTE: for security purposes, this field must not be visible
 194.137 -    // outside this package.
 194.138 -    boolean override;
 194.139 -
 194.140 -    /**
 194.141 -     * @throws NullPointerException {@inheritDoc}
 194.142 -     * @since 1.5
 194.143 -     */
 194.144 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 194.145 -        throw new AssertionError("All subclasses should override this method");
 194.146 -    }
 194.147 -
 194.148 -    /**
 194.149 -     * @throws NullPointerException {@inheritDoc}
 194.150 -     * @since 1.5
 194.151 -     */
 194.152 -    public boolean isAnnotationPresent(
 194.153 -        Class<? extends Annotation> annotationClass) {
 194.154 -        return getAnnotation(annotationClass) != null;
 194.155 -    }
 194.156 -
 194.157 -    /**
 194.158 -     * @since 1.5
 194.159 -     */
 194.160 -    public Annotation[] getAnnotations() {
 194.161 -        return getDeclaredAnnotations();
 194.162 -    }
 194.163 -
 194.164 -    /**
 194.165 -     * @since 1.5
 194.166 -     */
 194.167 -    public Annotation[] getDeclaredAnnotations()  {
 194.168 -        throw new AssertionError("All subclasses should override this method");
 194.169 -    }
 194.170 -}
   195.1 --- a/emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java	Mon Feb 25 19:00:08 2013 +0100
   195.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   195.3 @@ -1,112 +0,0 @@
   195.4 -/*
   195.5 - * Copyright (c) 2003, 2005, 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.lang.reflect;
  195.30 -
  195.31 -import java.lang.annotation.Annotation;
  195.32 -
  195.33 -/**
  195.34 - * Represents an annotated element of the program currently running in this
  195.35 - * VM.  This interface allows annotations to be read reflectively.  All
  195.36 - * annotations returned by methods in this interface are immutable and
  195.37 - * serializable.  It is permissible for the caller to modify the
  195.38 - * arrays returned by accessors for array-valued enum members; it will
  195.39 - * have no affect on the arrays returned to other callers.
  195.40 - *
  195.41 - * <p>If an annotation returned by a method in this interface contains
  195.42 - * (directly or indirectly) a {@link Class}-valued member referring to
  195.43 - * a class that is not accessible in this VM, attempting to read the class
  195.44 - * by calling the relevant Class-returning method on the returned annotation
  195.45 - * will result in a {@link TypeNotPresentException}.
  195.46 - *
  195.47 - * <p>Similarly, attempting to read an enum-valued member will result in
  195.48 - * a {@link EnumConstantNotPresentException} if the enum constant in the
  195.49 - * annotation is no longer present in the enum type.
  195.50 - *
  195.51 - * <p>Finally, Attempting to read a member whose definition has evolved
  195.52 - * incompatibly will result in a {@link
  195.53 - * java.lang.annotation.AnnotationTypeMismatchException} or an
  195.54 - * {@link java.lang.annotation.IncompleteAnnotationException}.
  195.55 - *
  195.56 - * @see java.lang.EnumConstantNotPresentException
  195.57 - * @see java.lang.TypeNotPresentException
  195.58 - * @see java.lang.annotation.AnnotationFormatError
  195.59 - * @see java.lang.annotation.AnnotationTypeMismatchException
  195.60 - * @see java.lang.annotation.IncompleteAnnotationException
  195.61 - * @since 1.5
  195.62 - * @author Josh Bloch
  195.63 - */
  195.64 -public interface AnnotatedElement {
  195.65 -    /**
  195.66 -     * Returns true if an annotation for the specified type
  195.67 -     * is present on this element, else false.  This method
  195.68 -     * is designed primarily for convenient access to marker annotations.
  195.69 -     *
  195.70 -     * @param annotationClass the Class object corresponding to the
  195.71 -     *        annotation type
  195.72 -     * @return true if an annotation for the specified annotation
  195.73 -     *     type is present on this element, else false
  195.74 -     * @throws NullPointerException if the given annotation class is null
  195.75 -     * @since 1.5
  195.76 -     */
  195.77 -     boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
  195.78 -
  195.79 -   /**
  195.80 -     * Returns this element's annotation for the specified type if
  195.81 -     * such an annotation is present, else null.
  195.82 -     *
  195.83 -     * @param annotationClass the Class object corresponding to the
  195.84 -     *        annotation type
  195.85 -     * @return this element's annotation for the specified annotation type if
  195.86 -     *     present on this element, else null
  195.87 -     * @throws NullPointerException if the given annotation class is null
  195.88 -     * @since 1.5
  195.89 -     */
  195.90 -    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
  195.91 -
  195.92 -    /**
  195.93 -     * Returns all annotations present on this element.  (Returns an array
  195.94 -     * of length zero if this element has no annotations.)  The caller of
  195.95 -     * this method is free to modify the returned array; it will have no
  195.96 -     * effect on the arrays returned to other callers.
  195.97 -     *
  195.98 -     * @return all annotations present on this element
  195.99 -     * @since 1.5
 195.100 -     */
 195.101 -    Annotation[] getAnnotations();
 195.102 -
 195.103 -    /**
 195.104 -     * Returns all annotations that are directly present on this
 195.105 -     * element.  Unlike the other methods in this interface, this method
 195.106 -     * ignores inherited annotations.  (Returns an array of length zero if
 195.107 -     * no annotations are directly present on this element.)  The caller of
 195.108 -     * this method is free to modify the returned array; it will have no
 195.109 -     * effect on the arrays returned to other callers.
 195.110 -     *
 195.111 -     * @return All annotations directly present on this element
 195.112 -     * @since 1.5
 195.113 -     */
 195.114 -    Annotation[] getDeclaredAnnotations();
 195.115 -}
   196.1 --- a/emul/mini/src/main/java/java/lang/reflect/Array.java	Mon Feb 25 19:00:08 2013 +0100
   196.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   196.3 @@ -1,663 +0,0 @@
   196.4 -/*
   196.5 - * Copyright (c) 1996, 2006, 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.lang.reflect;
  196.30 -
  196.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  196.32 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  196.33 -
  196.34 -/**
  196.35 - * The {@code Array} class provides static methods to dynamically create and
  196.36 - * access Java arrays.
  196.37 - *
  196.38 - * <p>{@code Array} permits widening conversions to occur during a get or set
  196.39 - * operation, but throws an {@code IllegalArgumentException} if a narrowing
  196.40 - * conversion would occur.
  196.41 - *
  196.42 - * @author Nakul Saraiya
  196.43 - */
  196.44 -@JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
  196.45 -public final
  196.46 -class Array {
  196.47 -
  196.48 -    /**
  196.49 -     * Constructor.  Class Array is not instantiable.
  196.50 -     */
  196.51 -    private Array() {}
  196.52 -
  196.53 -    /**
  196.54 -     * Creates a new array with the specified component type and
  196.55 -     * length.
  196.56 -     * Invoking this method is equivalent to creating an array
  196.57 -     * as follows:
  196.58 -     * <blockquote>
  196.59 -     * <pre>
  196.60 -     * int[] x = {length};
  196.61 -     * Array.newInstance(componentType, x);
  196.62 -     * </pre>
  196.63 -     * </blockquote>
  196.64 -     *
  196.65 -     * @param componentType the {@code Class} object representing the
  196.66 -     * component type of the new array
  196.67 -     * @param length the length of the new array
  196.68 -     * @return the new array
  196.69 -     * @exception NullPointerException if the specified
  196.70 -     * {@code componentType} parameter is null
  196.71 -     * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
  196.72 -     * @exception NegativeArraySizeException if the specified {@code length}
  196.73 -     * is negative
  196.74 -     */
  196.75 -    public static Object newInstance(Class<?> componentType, int length)
  196.76 -    throws NegativeArraySizeException {
  196.77 -        if (length < 0) {
  196.78 -            throw new NegativeArraySizeException();
  196.79 -        }
  196.80 -        String sig = findSignature(componentType);
  196.81 -        return newArray(componentType.isPrimitive(), sig, length);
  196.82 -    }
  196.83 -    
  196.84 -    private static String findSignature(Class<?> type) {
  196.85 -        if (type == Integer.TYPE) {
  196.86 -            return "[I";
  196.87 -        }
  196.88 -        if (type == Long.TYPE) {
  196.89 -            return "[J";
  196.90 -        }
  196.91 -        if (type == Double.TYPE) {
  196.92 -            return "[D";
  196.93 -        }
  196.94 -        if (type == Float.TYPE) {
  196.95 -            return "[F";
  196.96 -        }
  196.97 -        if (type == Byte.TYPE) {
  196.98 -            return "[B";
  196.99 -        }
 196.100 -        if (type == Boolean.TYPE) {
 196.101 -            return "[Z";
 196.102 -        }
 196.103 -        if (type == Short.TYPE) {
 196.104 -            return "[S";
 196.105 -        }
 196.106 -        if (type == Character.TYPE) {
 196.107 -            return "[C";
 196.108 -        }
 196.109 -        if (type.getName().equals("void")) {
 196.110 -            throw new IllegalStateException("Can't create array for " + type);
 196.111 -        }
 196.112 -        return "[L" + type.getName() + ";";
 196.113 -    }
 196.114 -    /**
 196.115 -     * Creates a new array
 196.116 -     * with the specified component type and dimensions.
 196.117 -     * If {@code componentType}
 196.118 -     * represents a non-array class or interface, the new array
 196.119 -     * has {@code dimensions.length} dimensions and
 196.120 -     * {@code componentType} as its component type. If
 196.121 -     * {@code componentType} represents an array class, the
 196.122 -     * number of dimensions of the new array is equal to the sum
 196.123 -     * of {@code dimensions.length} and the number of
 196.124 -     * dimensions of {@code componentType}. In this case, the
 196.125 -     * component type of the new array is the component type of
 196.126 -     * {@code componentType}.
 196.127 -     *
 196.128 -     * <p>The number of dimensions of the new array must not
 196.129 -     * exceed the number of array dimensions supported by the
 196.130 -     * implementation (typically 255).
 196.131 -     *
 196.132 -     * @param componentType the {@code Class} object representing the component
 196.133 -     * type of the new array
 196.134 -     * @param dimensions an array of {@code int} representing the dimensions of
 196.135 -     * the new array
 196.136 -     * @return the new array
 196.137 -     * @exception NullPointerException if the specified
 196.138 -     * {@code componentType} argument is null
 196.139 -     * @exception IllegalArgumentException if the specified {@code dimensions}
 196.140 -     * argument is a zero-dimensional array, or if the number of
 196.141 -     * requested dimensions exceeds the limit on the number of array dimensions
 196.142 -     * supported by the implementation (typically 255), or if componentType
 196.143 -     * is {@link Void#TYPE}.
 196.144 -     * @exception NegativeArraySizeException if any of the components in
 196.145 -     * the specified {@code dimensions} argument is negative.
 196.146 -     */
 196.147 -    public static Object newInstance(Class<?> componentType, int... dimensions)
 196.148 -        throws IllegalArgumentException, NegativeArraySizeException {
 196.149 -        StringBuilder sig = new StringBuilder();
 196.150 -        for (int i = 1; i < dimensions.length; i++) {
 196.151 -            sig.append('[');
 196.152 -        }
 196.153 -        sig.append(findSignature(componentType));
 196.154 -        return multiNewArray(sig.toString(), dimensions, 0);
 196.155 -    }
 196.156 -
 196.157 -    /**
 196.158 -     * Returns the length of the specified array object, as an {@code int}.
 196.159 -     *
 196.160 -     * @param array the array
 196.161 -     * @return the length of the array
 196.162 -     * @exception IllegalArgumentException if the object argument is not
 196.163 -     * an array
 196.164 -     */
 196.165 -    public static int getLength(Object array)
 196.166 -    throws IllegalArgumentException {
 196.167 -        if (!array.getClass().isArray()) {
 196.168 -            throw new IllegalArgumentException("Argument is not an array");
 196.169 -        }
 196.170 -        return length(array);
 196.171 -    }
 196.172 -    
 196.173 -    @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
 196.174 -    private static native int length(Object arr);
 196.175 -
 196.176 -    /**
 196.177 -     * Returns the value of the indexed component in the specified
 196.178 -     * array object.  The value is automatically wrapped in an object
 196.179 -     * if it has a primitive type.
 196.180 -     *
 196.181 -     * @param array the array
 196.182 -     * @param index the index
 196.183 -     * @return the (possibly wrapped) value of the indexed component in
 196.184 -     * the specified array
 196.185 -     * @exception NullPointerException If the specified object is null
 196.186 -     * @exception IllegalArgumentException If the specified object is not
 196.187 -     * an array
 196.188 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.189 -     * argument is negative, or if it is greater than or equal to the
 196.190 -     * length of the specified array
 196.191 -     */
 196.192 -    public static Object get(Object array, int index)
 196.193 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.194 -        final Class<?> t = array.getClass().getComponentType();
 196.195 -        if (t.isPrimitive()) {
 196.196 -            return fromPrimitive(t, array, index);
 196.197 -        } else {
 196.198 -            return ((Object[])array)[index];
 196.199 -        }
 196.200 -    }
 196.201 -
 196.202 -    /**
 196.203 -     * Returns the value of the indexed component in the specified
 196.204 -     * array object, as a {@code boolean}.
 196.205 -     *
 196.206 -     * @param array the array
 196.207 -     * @param index the index
 196.208 -     * @return the value of the indexed component in the specified array
 196.209 -     * @exception NullPointerException If the specified object is null
 196.210 -     * @exception IllegalArgumentException If the specified object is not
 196.211 -     * an array, or if the indexed element cannot be converted to the
 196.212 -     * return type by an identity or widening conversion
 196.213 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.214 -     * argument is negative, or if it is greater than or equal to the
 196.215 -     * length of the specified array
 196.216 -     * @see Array#get
 196.217 -     */
 196.218 -    public static native boolean getBoolean(Object array, int index)
 196.219 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 196.220 -
 196.221 -    /**
 196.222 -     * Returns the value of the indexed component in the specified
 196.223 -     * array object, as a {@code byte}.
 196.224 -     *
 196.225 -     * @param array the array
 196.226 -     * @param index the index
 196.227 -     * @return the value of the indexed component in the specified array
 196.228 -     * @exception NullPointerException If the specified object is null
 196.229 -     * @exception IllegalArgumentException If the specified object is not
 196.230 -     * an array, or if the indexed element cannot be converted to the
 196.231 -     * return type by an identity or widening conversion
 196.232 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.233 -     * argument is negative, or if it is greater than or equal to the
 196.234 -     * length of the specified array
 196.235 -     * @see Array#get
 196.236 -     */
 196.237 -    public static byte getByte(Object array, int index)
 196.238 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.239 -        if (array.getClass().getComponentType() != Byte.TYPE) {
 196.240 -            throw new IllegalArgumentException();
 196.241 -        }
 196.242 -        byte[] arr = (byte[]) array;
 196.243 -        return arr[index];
 196.244 -    }
 196.245 -
 196.246 -    /**
 196.247 -     * Returns the value of the indexed component in the specified
 196.248 -     * array object, as a {@code char}.
 196.249 -     *
 196.250 -     * @param array the array
 196.251 -     * @param index the index
 196.252 -     * @return the value of the indexed component in the specified array
 196.253 -     * @exception NullPointerException If the specified object is null
 196.254 -     * @exception IllegalArgumentException If the specified object is not
 196.255 -     * an array, or if the indexed element cannot be converted to the
 196.256 -     * return type by an identity or widening conversion
 196.257 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.258 -     * argument is negative, or if it is greater than or equal to the
 196.259 -     * length of the specified array
 196.260 -     * @see Array#get
 196.261 -     */
 196.262 -    public static native char getChar(Object array, int index)
 196.263 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 196.264 -
 196.265 -    /**
 196.266 -     * Returns the value of the indexed component in the specified
 196.267 -     * array object, as a {@code short}.
 196.268 -     *
 196.269 -     * @param array the array
 196.270 -     * @param index the index
 196.271 -     * @return the value of the indexed component in the specified array
 196.272 -     * @exception NullPointerException If the specified object is null
 196.273 -     * @exception IllegalArgumentException If the specified object is not
 196.274 -     * an array, or if the indexed element cannot be converted to the
 196.275 -     * return type by an identity or widening conversion
 196.276 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.277 -     * argument is negative, or if it is greater than or equal to the
 196.278 -     * length of the specified array
 196.279 -     * @see Array#get
 196.280 -     */
 196.281 -    public static short getShort(Object array, int index)
 196.282 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.283 -        final Class<?> t = array.getClass().getComponentType();
 196.284 -        if (t == Short.TYPE) {
 196.285 -            short[] arr = (short[]) array;
 196.286 -            return arr[index];
 196.287 -        }
 196.288 -        return getByte(array, index);
 196.289 -    }
 196.290 -
 196.291 -    /**
 196.292 -     * Returns the value of the indexed component in the specified
 196.293 -     * array object, as an {@code int}.
 196.294 -     *
 196.295 -     * @param array the array
 196.296 -     * @param index the index
 196.297 -     * @return the value of the indexed component in the specified array
 196.298 -     * @exception NullPointerException If the specified object is null
 196.299 -     * @exception IllegalArgumentException If the specified object is not
 196.300 -     * an array, or if the indexed element cannot be converted to the
 196.301 -     * return type by an identity or widening conversion
 196.302 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.303 -     * argument is negative, or if it is greater than or equal to the
 196.304 -     * length of the specified array
 196.305 -     * @see Array#get
 196.306 -     */
 196.307 -    public static int getInt(Object array, int index) 
 196.308 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.309 -        final Class<?> t = array.getClass().getComponentType();
 196.310 -        if (t == Integer.TYPE) {
 196.311 -            int[] arr = (int[]) array;
 196.312 -            return arr[index];
 196.313 -        }
 196.314 -        return getShort(array, index);
 196.315 -    }
 196.316 -
 196.317 -    /**
 196.318 -     * Returns the value of the indexed component in the specified
 196.319 -     * array object, as a {@code long}.
 196.320 -     *
 196.321 -     * @param array the array
 196.322 -     * @param index the index
 196.323 -     * @return the value of the indexed component in the specified array
 196.324 -     * @exception NullPointerException If the specified object is null
 196.325 -     * @exception IllegalArgumentException If the specified object is not
 196.326 -     * an array, or if the indexed element cannot be converted to the
 196.327 -     * return type by an identity or widening conversion
 196.328 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.329 -     * argument is negative, or if it is greater than or equal to the
 196.330 -     * length of the specified array
 196.331 -     * @see Array#get
 196.332 -     */
 196.333 -    public static long getLong(Object array, int index)
 196.334 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.335 -        final Class<?> t = array.getClass().getComponentType();
 196.336 -        if (t == Long.TYPE) {
 196.337 -            long[] arr = (long[]) array;
 196.338 -            return arr[index];
 196.339 -        }
 196.340 -        return getInt(array, index);
 196.341 -    }
 196.342 -
 196.343 -    /**
 196.344 -     * Returns the value of the indexed component in the specified
 196.345 -     * array object, as a {@code float}.
 196.346 -     *
 196.347 -     * @param array the array
 196.348 -     * @param index the index
 196.349 -     * @return the value of the indexed component in the specified array
 196.350 -     * @exception NullPointerException If the specified object is null
 196.351 -     * @exception IllegalArgumentException If the specified object is not
 196.352 -     * an array, or if the indexed element cannot be converted to the
 196.353 -     * return type by an identity or widening conversion
 196.354 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.355 -     * argument is negative, or if it is greater than or equal to the
 196.356 -     * length of the specified array
 196.357 -     * @see Array#get
 196.358 -     */
 196.359 -    public static float getFloat(Object array, int index)
 196.360 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.361 -        final Class<?> t = array.getClass().getComponentType();
 196.362 -        if (t == Float.TYPE) {
 196.363 -            float[] arr = (float[]) array;
 196.364 -            return arr[index];
 196.365 -        }
 196.366 -        return getLong(array, index);
 196.367 -    }
 196.368 -
 196.369 -    /**
 196.370 -     * Returns the value of the indexed component in the specified
 196.371 -     * array object, as a {@code double}.
 196.372 -     *
 196.373 -     * @param array the array
 196.374 -     * @param index the index
 196.375 -     * @return the value of the indexed component in the specified array
 196.376 -     * @exception NullPointerException If the specified object is null
 196.377 -     * @exception IllegalArgumentException If the specified object is not
 196.378 -     * an array, or if the indexed element cannot be converted to the
 196.379 -     * return type by an identity or widening conversion
 196.380 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.381 -     * argument is negative, or if it is greater than or equal to the
 196.382 -     * length of the specified array
 196.383 -     * @see Array#get
 196.384 -     */
 196.385 -    public static double getDouble(Object array, int index)
 196.386 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.387 -        final Class<?> t = array.getClass().getComponentType();
 196.388 -        if (t == Double.TYPE) {
 196.389 -            double[] arr = (double[]) array;
 196.390 -            return arr[index];
 196.391 -        }
 196.392 -        return getFloat(array, index);
 196.393 -    }
 196.394 -
 196.395 -    /**
 196.396 -     * Sets the value of the indexed component of the specified array
 196.397 -     * object to the specified new value.  The new value is first
 196.398 -     * automatically unwrapped if the array has a primitive component
 196.399 -     * type.
 196.400 -     * @param array the array
 196.401 -     * @param index the index into the array
 196.402 -     * @param value the new value of the indexed component
 196.403 -     * @exception NullPointerException If the specified object argument
 196.404 -     * is null
 196.405 -     * @exception IllegalArgumentException If the specified object argument
 196.406 -     * is not an array, or if the array component type is primitive and
 196.407 -     * an unwrapping conversion fails
 196.408 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.409 -     * argument is negative, or if it is greater than or equal to
 196.410 -     * the length of the specified array
 196.411 -     */
 196.412 -    public static void set(Object array, int index, Object value)
 196.413 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.414 -        if (array.getClass().getComponentType().isPrimitive()) {
 196.415 -            throw new IllegalArgumentException();
 196.416 -        } else {
 196.417 -            Object[] arr = (Object[])array;
 196.418 -            arr[index] = value;
 196.419 -        }
 196.420 -    }
 196.421 -
 196.422 -    /**
 196.423 -     * Sets the value of the indexed component of the specified array
 196.424 -     * object to the specified {@code boolean} value.
 196.425 -     * @param array the array
 196.426 -     * @param index the index into the array
 196.427 -     * @param z the new value of the indexed component
 196.428 -     * @exception NullPointerException If the specified object argument
 196.429 -     * is null
 196.430 -     * @exception IllegalArgumentException If the specified object argument
 196.431 -     * is not an array, or if the specified value cannot be converted
 196.432 -     * to the underlying array's component type by an identity or a
 196.433 -     * primitive widening conversion
 196.434 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.435 -     * argument is negative, or if it is greater than or equal to
 196.436 -     * the length of the specified array
 196.437 -     * @see Array#set
 196.438 -     */
 196.439 -    public static native void setBoolean(Object array, int index, boolean z)
 196.440 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 196.441 -
 196.442 -    /**
 196.443 -     * Sets the value of the indexed component of the specified array
 196.444 -     * object to the specified {@code byte} value.
 196.445 -     * @param array the array
 196.446 -     * @param index the index into the array
 196.447 -     * @param b the new value of the indexed component
 196.448 -     * @exception NullPointerException If the specified object argument
 196.449 -     * is null
 196.450 -     * @exception IllegalArgumentException If the specified object argument
 196.451 -     * is not an array, or if the specified value cannot be converted
 196.452 -     * to the underlying array's component type by an identity or a
 196.453 -     * primitive widening conversion
 196.454 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.455 -     * argument is negative, or if it is greater than or equal to
 196.456 -     * the length of the specified array
 196.457 -     * @see Array#set
 196.458 -     */
 196.459 -    public static void setByte(Object array, int index, byte b)
 196.460 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.461 -        Class<?> t = array.getClass().getComponentType();
 196.462 -        if (t == Byte.TYPE) {
 196.463 -            byte[] arr = (byte[]) array;
 196.464 -            arr[index] = b;
 196.465 -        } else {
 196.466 -            setShort(array, index, b);
 196.467 -        }
 196.468 -    }
 196.469 -
 196.470 -    /**
 196.471 -     * Sets the value of the indexed component of the specified array
 196.472 -     * object to the specified {@code char} value.
 196.473 -     * @param array the array
 196.474 -     * @param index the index into the array
 196.475 -     * @param c the new value of the indexed component
 196.476 -     * @exception NullPointerException If the specified object argument
 196.477 -     * is null
 196.478 -     * @exception IllegalArgumentException If the specified object argument
 196.479 -     * is not an array, or if the specified value cannot be converted
 196.480 -     * to the underlying array's component type by an identity or a
 196.481 -     * primitive widening conversion
 196.482 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.483 -     * argument is negative, or if it is greater than or equal to
 196.484 -     * the length of the specified array
 196.485 -     * @see Array#set
 196.486 -     */
 196.487 -    public static native void setChar(Object array, int index, char c)
 196.488 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 196.489 -
 196.490 -    /**
 196.491 -     * Sets the value of the indexed component of the specified array
 196.492 -     * object to the specified {@code short} value.
 196.493 -     * @param array the array
 196.494 -     * @param index the index into the array
 196.495 -     * @param s the new value of the indexed component
 196.496 -     * @exception NullPointerException If the specified object argument
 196.497 -     * is null
 196.498 -     * @exception IllegalArgumentException If the specified object argument
 196.499 -     * is not an array, or if the specified value cannot be converted
 196.500 -     * to the underlying array's component type by an identity or a
 196.501 -     * primitive widening conversion
 196.502 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.503 -     * argument is negative, or if it is greater than or equal to
 196.504 -     * the length of the specified array
 196.505 -     * @see Array#set
 196.506 -     */
 196.507 -    public static void setShort(Object array, int index, short s)
 196.508 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.509 -        Class<?> t = array.getClass().getComponentType();
 196.510 -        if (t == Short.TYPE) {
 196.511 -            short[] arr = (short[]) array;
 196.512 -            arr[index] = s;
 196.513 -        } else {
 196.514 -            setInt(array, index, s);
 196.515 -        }
 196.516 -        
 196.517 -    }
 196.518 -    
 196.519 -    /**
 196.520 -     * Sets the value of the indexed component of the specified array
 196.521 -     * object to the specified {@code int} value.
 196.522 -     * @param array the array
 196.523 -     * @param index the index into the array
 196.524 -     * @param i the new value of the indexed component
 196.525 -     * @exception NullPointerException If the specified object argument
 196.526 -     * is null
 196.527 -     * @exception IllegalArgumentException If the specified object argument
 196.528 -     * is not an array, or if the specified value cannot be converted
 196.529 -     * to the underlying array's component type by an identity or a
 196.530 -     * primitive widening conversion
 196.531 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.532 -     * argument is negative, or if it is greater than or equal to
 196.533 -     * the length of the specified array
 196.534 -     * @see Array#set
 196.535 -     */
 196.536 -    public static void setInt(Object array, int index, int i)
 196.537 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.538 -        Class<?> t = array.getClass().getComponentType();
 196.539 -        if (t == Integer.TYPE) {
 196.540 -            int[] arr = (int[]) array;
 196.541 -            arr[index] = i;
 196.542 -        } else {
 196.543 -            setLong(array, index, i);
 196.544 -        }
 196.545 -    }
 196.546 -
 196.547 -    /**
 196.548 -     * Sets the value of the indexed component of the specified array
 196.549 -     * object to the specified {@code long} value.
 196.550 -     * @param array the array
 196.551 -     * @param index the index into the array
 196.552 -     * @param l the new value of the indexed component
 196.553 -     * @exception NullPointerException If the specified object argument
 196.554 -     * is null
 196.555 -     * @exception IllegalArgumentException If the specified object argument
 196.556 -     * is not an array, or if the specified value cannot be converted
 196.557 -     * to the underlying array's component type by an identity or a
 196.558 -     * primitive widening conversion
 196.559 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.560 -     * argument is negative, or if it is greater than or equal to
 196.561 -     * the length of the specified array
 196.562 -     * @see Array#set
 196.563 -     */
 196.564 -    public static void setLong(Object array, int index, long l)
 196.565 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.566 -        Class<?> t = array.getClass().getComponentType();
 196.567 -        if (t == Long.TYPE) {
 196.568 -            long[] arr = (long[]) array;
 196.569 -            arr[index] = l;
 196.570 -        } else {
 196.571 -            setFloat(array, index, l);
 196.572 -        }
 196.573 -    }
 196.574 -
 196.575 -    /**
 196.576 -     * Sets the value of the indexed component of the specified array
 196.577 -     * object to the specified {@code float} value.
 196.578 -     * @param array the array
 196.579 -     * @param index the index into the array
 196.580 -     * @param f the new value of the indexed component
 196.581 -     * @exception NullPointerException If the specified object argument
 196.582 -     * is null
 196.583 -     * @exception IllegalArgumentException If the specified object argument
 196.584 -     * is not an array, or if the specified value cannot be converted
 196.585 -     * to the underlying array's component type by an identity or a
 196.586 -     * primitive widening conversion
 196.587 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.588 -     * argument is negative, or if it is greater than or equal to
 196.589 -     * the length of the specified array
 196.590 -     * @see Array#set
 196.591 -     */
 196.592 -    public static void setFloat(Object array, int index, float f)
 196.593 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.594 -        Class<?> t = array.getClass().getComponentType();
 196.595 -        if (t == Float.TYPE) {
 196.596 -            float[] arr = (float[])array;
 196.597 -            arr[index] = f;
 196.598 -        } else {
 196.599 -            setDouble(array, index, f);
 196.600 -        }
 196.601 -    }
 196.602 -
 196.603 -    /**
 196.604 -     * Sets the value of the indexed component of the specified array
 196.605 -     * object to the specified {@code double} value.
 196.606 -     * @param array the array
 196.607 -     * @param index the index into the array
 196.608 -     * @param d the new value of the indexed component
 196.609 -     * @exception NullPointerException If the specified object argument
 196.610 -     * is null
 196.611 -     * @exception IllegalArgumentException If the specified object argument
 196.612 -     * is not an array, or if the specified value cannot be converted
 196.613 -     * to the underlying array's component type by an identity or a
 196.614 -     * primitive widening conversion
 196.615 -     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 196.616 -     * argument is negative, or if it is greater than or equal to
 196.617 -     * the length of the specified array
 196.618 -     * @see Array#set
 196.619 -     */
 196.620 -    public static void setDouble(Object array, int index, double d)
 196.621 -    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 196.622 -        Class<?> t = array.getClass().getComponentType();
 196.623 -        if (t == Double.TYPE) {
 196.624 -            double[] arr = (double[])array;
 196.625 -            arr[index] = d;
 196.626 -        } else {
 196.627 -            throw new IllegalArgumentException("argument type mismatch");
 196.628 -        }
 196.629 -    }
 196.630 -
 196.631 -    /*
 196.632 -     * Private
 196.633 -     */
 196.634 -
 196.635 -    @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
 196.636 -          "var arr = new Array(length);\n"
 196.637 -        + "var value = primitive ? 0 : null;\n"
 196.638 -        + "for(var i = 0; i < length; i++) arr[i] = value;\n"
 196.639 -        + "arr.jvmName = sig;\n"
 196.640 -        + "return arr;"
 196.641 -    )
 196.642 -    private static native Object newArray(boolean primitive, String sig, int length);
 196.643 -
 196.644 -    private static Object multiNewArray(String sig, int[] dims, int index)
 196.645 -    throws IllegalArgumentException, NegativeArraySizeException {
 196.646 -        if (dims.length == index + 1) {
 196.647 -            return newArray(sig.length() == 2, sig, dims[index]);
 196.648 -        }
 196.649 -        Object arr = newArray(false, sig, dims[index]);
 196.650 -        String compsig = sig.substring(1);
 196.651 -        int len = getLength(arr);
 196.652 -        for (int i = 0; i < len; i++) {
 196.653 -            setArray(arr, i, multiNewArray(compsig, dims, index + 1));
 196.654 -        }
 196.655 -        return arr;
 196.656 -    }
 196.657 -    private static Object fromPrimitive(Class<?> t, Object array, int index) {
 196.658 -        return Method.fromPrimitive(t, atArray(array, index));
 196.659 -    }
 196.660 -    
 196.661 -    @JavaScriptBody(args = { "array", "index" }, body = "return array[index];")
 196.662 -    private static native Object atArray(Object array, int index);
 196.663 -
 196.664 -    @JavaScriptBody(args = { "array", "index", "v" }, body = "array[index] = v;")
 196.665 -    private static native Object setArray(Object array, int index, Object v);
 196.666 -}
   197.1 --- a/emul/mini/src/main/java/java/lang/reflect/Constructor.java	Mon Feb 25 19:00:08 2013 +0100
   197.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   197.3 @@ -1,567 +0,0 @@
   197.4 -/*
   197.5 - * Copyright (c) 1996, 2010, 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.lang.reflect;
  197.30 -
  197.31 -import java.lang.annotation.Annotation;
  197.32 -import org.apidesign.bck2brwsr.emul.reflect.TypeProvider;
  197.33 -
  197.34 -/**
  197.35 - * {@code Constructor} provides information about, and access to, a single
  197.36 - * constructor for a class.
  197.37 - *
  197.38 - * <p>{@code Constructor} permits widening conversions to occur when matching the
  197.39 - * actual parameters to newInstance() with the underlying
  197.40 - * constructor's formal parameters, but throws an
  197.41 - * {@code IllegalArgumentException} if a narrowing conversion would occur.
  197.42 - *
  197.43 - * @param <T> the class in which the constructor is declared
  197.44 - *
  197.45 - * @see Member
  197.46 - * @see java.lang.Class
  197.47 - * @see java.lang.Class#getConstructors()
  197.48 - * @see java.lang.Class#getConstructor(Class[])
  197.49 - * @see java.lang.Class#getDeclaredConstructors()
  197.50 - *
  197.51 - * @author      Kenneth Russell
  197.52 - * @author      Nakul Saraiya
  197.53 - */
  197.54 -public final
  197.55 -    class Constructor<T> extends AccessibleObject implements
  197.56 -                                                    GenericDeclaration,
  197.57 -                                                    Member {
  197.58 -
  197.59 -    private Class<T>            clazz;
  197.60 -    private int                 slot;
  197.61 -    private Class<?>[]          parameterTypes;
  197.62 -    private Class<?>[]          exceptionTypes;
  197.63 -    private int                 modifiers;
  197.64 -    // Generics and annotations support
  197.65 -    private transient String    signature;
  197.66 -    private byte[]              annotations;
  197.67 -    private byte[]              parameterAnnotations;
  197.68 -
  197.69 -
  197.70 -    // For sharing of ConstructorAccessors. This branching structure
  197.71 -    // is currently only two levels deep (i.e., one root Constructor
  197.72 -    // and potentially many Constructor objects pointing to it.)
  197.73 -    private Constructor<T>      root;
  197.74 -
  197.75 -    /**
  197.76 -     * Package-private constructor used by ReflectAccess to enable
  197.77 -     * instantiation of these objects in Java code from the java.lang
  197.78 -     * package via sun.reflect.LangReflectAccess.
  197.79 -     */
  197.80 -    Constructor(Class<T> declaringClass,
  197.81 -                Class<?>[] parameterTypes,
  197.82 -                Class<?>[] checkedExceptions,
  197.83 -                int modifiers,
  197.84 -                int slot,
  197.85 -                String signature,
  197.86 -                byte[] annotations,
  197.87 -                byte[] parameterAnnotations)
  197.88 -    {
  197.89 -        this.clazz = declaringClass;
  197.90 -        this.parameterTypes = parameterTypes;
  197.91 -        this.exceptionTypes = checkedExceptions;
  197.92 -        this.modifiers = modifiers;
  197.93 -        this.slot = slot;
  197.94 -        this.signature = signature;
  197.95 -        this.annotations = annotations;
  197.96 -        this.parameterAnnotations = parameterAnnotations;
  197.97 -    }
  197.98 -
  197.99 -    /**
 197.100 -     * Package-private routine (exposed to java.lang.Class via
 197.101 -     * ReflectAccess) which returns a copy of this Constructor. The copy's
 197.102 -     * "root" field points to this Constructor.
 197.103 -     */
 197.104 -    Constructor<T> copy() {
 197.105 -        return this;
 197.106 -    }
 197.107 -
 197.108 -    /**
 197.109 -     * Returns the {@code Class} object representing the class that declares
 197.110 -     * the constructor represented by this {@code Constructor} object.
 197.111 -     */
 197.112 -    public Class<T> getDeclaringClass() {
 197.113 -        return clazz;
 197.114 -    }
 197.115 -
 197.116 -    /**
 197.117 -     * Returns the name of this constructor, as a string.  This is
 197.118 -     * the binary name of the constructor's declaring class.
 197.119 -     */
 197.120 -    public String getName() {
 197.121 -        return getDeclaringClass().getName();
 197.122 -    }
 197.123 -
 197.124 -    /**
 197.125 -     * Returns the Java language modifiers for the constructor
 197.126 -     * represented by this {@code Constructor} object, as an integer. The
 197.127 -     * {@code Modifier} class should be used to decode the modifiers.
 197.128 -     *
 197.129 -     * @see Modifier
 197.130 -     */
 197.131 -    public int getModifiers() {
 197.132 -        return modifiers;
 197.133 -    }
 197.134 -
 197.135 -    /**
 197.136 -     * Returns an array of {@code TypeVariable} objects that represent the
 197.137 -     * type variables declared by the generic declaration represented by this
 197.138 -     * {@code GenericDeclaration} object, in declaration order.  Returns an
 197.139 -     * array of length 0 if the underlying generic declaration declares no type
 197.140 -     * variables.
 197.141 -     *
 197.142 -     * @return an array of {@code TypeVariable} objects that represent
 197.143 -     *     the type variables declared by this generic declaration
 197.144 -     * @throws GenericSignatureFormatError if the generic
 197.145 -     *     signature of this generic declaration does not conform to
 197.146 -     *     the format specified in
 197.147 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 197.148 -     * @since 1.5
 197.149 -     */
 197.150 -    public TypeVariable<Constructor<T>>[] getTypeParameters() {
 197.151 -        return TypeProvider.getDefault().getTypeParameters(this);
 197.152 -    }
 197.153 -
 197.154 -
 197.155 -    /**
 197.156 -     * Returns an array of {@code Class} objects that represent the formal
 197.157 -     * parameter types, in declaration order, of the constructor
 197.158 -     * represented by this {@code Constructor} object.  Returns an array of
 197.159 -     * length 0 if the underlying constructor takes no parameters.
 197.160 -     *
 197.161 -     * @return the parameter types for the constructor this object
 197.162 -     * represents
 197.163 -     */
 197.164 -    public Class<?>[] getParameterTypes() {
 197.165 -        return (Class<?>[]) parameterTypes.clone();
 197.166 -    }
 197.167 -
 197.168 -
 197.169 -    /**
 197.170 -     * Returns an array of {@code Type} objects that represent the formal
 197.171 -     * parameter types, in declaration order, of the method represented by
 197.172 -     * this {@code Constructor} object. Returns an array of length 0 if the
 197.173 -     * underlying method takes no parameters.
 197.174 -     *
 197.175 -     * <p>If a formal parameter type is a parameterized type,
 197.176 -     * the {@code Type} object returned for it must accurately reflect
 197.177 -     * the actual type parameters used in the source code.
 197.178 -     *
 197.179 -     * <p>If a formal parameter type is a type variable or a parameterized
 197.180 -     * type, it is created. Otherwise, it is resolved.
 197.181 -     *
 197.182 -     * @return an array of {@code Type}s that represent the formal
 197.183 -     *     parameter types of the underlying method, in declaration order
 197.184 -     * @throws GenericSignatureFormatError
 197.185 -     *     if the generic method signature does not conform to the format
 197.186 -     *     specified in
 197.187 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 197.188 -     * @throws TypeNotPresentException if any of the parameter
 197.189 -     *     types of the underlying method refers to a non-existent type
 197.190 -     *     declaration
 197.191 -     * @throws MalformedParameterizedTypeException if any of
 197.192 -     *     the underlying method's parameter types refer to a parameterized
 197.193 -     *     type that cannot be instantiated for any reason
 197.194 -     * @since 1.5
 197.195 -     */
 197.196 -    public Type[] getGenericParameterTypes() {
 197.197 -        return TypeProvider.getDefault().getGenericParameterTypes(this);
 197.198 -    }
 197.199 -
 197.200 -
 197.201 -    /**
 197.202 -     * Returns an array of {@code Class} objects that represent the types
 197.203 -     * of exceptions declared to be thrown by the underlying constructor
 197.204 -     * represented by this {@code Constructor} object.  Returns an array of
 197.205 -     * length 0 if the constructor declares no exceptions in its {@code throws} clause.
 197.206 -     *
 197.207 -     * @return the exception types declared as being thrown by the
 197.208 -     * constructor this object represents
 197.209 -     */
 197.210 -    public Class<?>[] getExceptionTypes() {
 197.211 -        return (Class<?>[])exceptionTypes.clone();
 197.212 -    }
 197.213 -
 197.214 -
 197.215 -    /**
 197.216 -     * Returns an array of {@code Type} objects that represent the
 197.217 -     * exceptions declared to be thrown by this {@code Constructor} object.
 197.218 -     * Returns an array of length 0 if the underlying method declares
 197.219 -     * no exceptions in its {@code throws} clause.
 197.220 -     *
 197.221 -     * <p>If an exception type is a type variable or a parameterized
 197.222 -     * type, it is created. Otherwise, it is resolved.
 197.223 -     *
 197.224 -     * @return an array of Types that represent the exception types
 197.225 -     *     thrown by the underlying method
 197.226 -     * @throws GenericSignatureFormatError
 197.227 -     *     if the generic method signature does not conform to the format
 197.228 -     *     specified in
 197.229 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 197.230 -     * @throws TypeNotPresentException if the underlying method's
 197.231 -     *     {@code throws} clause refers to a non-existent type declaration
 197.232 -     * @throws MalformedParameterizedTypeException if
 197.233 -     *     the underlying method's {@code throws} clause refers to a
 197.234 -     *     parameterized type that cannot be instantiated for any reason
 197.235 -     * @since 1.5
 197.236 -     */
 197.237 -      public Type[] getGenericExceptionTypes() {
 197.238 -          return TypeProvider.getDefault().getGenericExceptionTypes(this);
 197.239 -      }
 197.240 -
 197.241 -    /**
 197.242 -     * Compares this {@code Constructor} against the specified object.
 197.243 -     * Returns true if the objects are the same.  Two {@code Constructor} objects are
 197.244 -     * the same if they were declared by the same class and have the
 197.245 -     * same formal parameter types.
 197.246 -     */
 197.247 -    public boolean equals(Object obj) {
 197.248 -        if (obj != null && obj instanceof Constructor) {
 197.249 -            Constructor<?> other = (Constructor<?>)obj;
 197.250 -            if (getDeclaringClass() == other.getDeclaringClass()) {
 197.251 -                /* Avoid unnecessary cloning */
 197.252 -                Class<?>[] params1 = parameterTypes;
 197.253 -                Class<?>[] params2 = other.parameterTypes;
 197.254 -                if (params1.length == params2.length) {
 197.255 -                    for (int i = 0; i < params1.length; i++) {
 197.256 -                        if (params1[i] != params2[i])
 197.257 -                            return false;
 197.258 -                    }
 197.259 -                    return true;
 197.260 -                }
 197.261 -            }
 197.262 -        }
 197.263 -        return false;
 197.264 -    }
 197.265 -
 197.266 -    /**
 197.267 -     * Returns a hashcode for this {@code Constructor}. The hashcode is
 197.268 -     * the same as the hashcode for the underlying constructor's
 197.269 -     * declaring class name.
 197.270 -     */
 197.271 -    public int hashCode() {
 197.272 -        return getDeclaringClass().getName().hashCode();
 197.273 -    }
 197.274 -
 197.275 -    /**
 197.276 -     * Returns a string describing this {@code Constructor}.  The string is
 197.277 -     * formatted as the constructor access modifiers, if any,
 197.278 -     * followed by the fully-qualified name of the declaring class,
 197.279 -     * followed by a parenthesized, comma-separated list of the
 197.280 -     * constructor's formal parameter types.  For example:
 197.281 -     * <pre>
 197.282 -     *    public java.util.Hashtable(int,float)
 197.283 -     * </pre>
 197.284 -     *
 197.285 -     * <p>The only possible modifiers for constructors are the access
 197.286 -     * modifiers {@code public}, {@code protected} or
 197.287 -     * {@code private}.  Only one of these may appear, or none if the
 197.288 -     * constructor has default (package) access.
 197.289 -     */
 197.290 -    public String toString() {
 197.291 -        try {
 197.292 -            StringBuffer sb = new StringBuffer();
 197.293 -            int mod = getModifiers() & Modifier.constructorModifiers();
 197.294 -            if (mod != 0) {
 197.295 -                sb.append(Modifier.toString(mod) + " ");
 197.296 -            }
 197.297 -            sb.append(Field.getTypeName(getDeclaringClass()));
 197.298 -            sb.append("(");
 197.299 -            Class<?>[] params = parameterTypes; // avoid clone
 197.300 -            for (int j = 0; j < params.length; j++) {
 197.301 -                sb.append(Field.getTypeName(params[j]));
 197.302 -                if (j < (params.length - 1))
 197.303 -                    sb.append(",");
 197.304 -            }
 197.305 -            sb.append(")");
 197.306 -            Class<?>[] exceptions = exceptionTypes; // avoid clone
 197.307 -            if (exceptions.length > 0) {
 197.308 -                sb.append(" throws ");
 197.309 -                for (int k = 0; k < exceptions.length; k++) {
 197.310 -                    sb.append(exceptions[k].getName());
 197.311 -                    if (k < (exceptions.length - 1))
 197.312 -                        sb.append(",");
 197.313 -                }
 197.314 -            }
 197.315 -            return sb.toString();
 197.316 -        } catch (Exception e) {
 197.317 -            return "<" + e + ">";
 197.318 -        }
 197.319 -    }
 197.320 -
 197.321 -    /**
 197.322 -     * Returns a string describing this {@code Constructor},
 197.323 -     * including type parameters.  The string is formatted as the
 197.324 -     * constructor access modifiers, if any, followed by an
 197.325 -     * angle-bracketed comma separated list of the constructor's type
 197.326 -     * parameters, if any, followed by the fully-qualified name of the
 197.327 -     * declaring class, followed by a parenthesized, comma-separated
 197.328 -     * list of the constructor's generic formal parameter types.
 197.329 -     *
 197.330 -     * If this constructor was declared to take a variable number of
 197.331 -     * arguments, instead of denoting the last parameter as
 197.332 -     * "<tt><i>Type</i>[]</tt>", it is denoted as
 197.333 -     * "<tt><i>Type</i>...</tt>".
 197.334 -     *
 197.335 -     * A space is used to separate access modifiers from one another
 197.336 -     * and from the type parameters or return type.  If there are no
 197.337 -     * type parameters, the type parameter list is elided; if the type
 197.338 -     * parameter list is present, a space separates the list from the
 197.339 -     * class name.  If the constructor is declared to throw
 197.340 -     * exceptions, the parameter list is followed by a space, followed
 197.341 -     * by the word "{@code throws}" followed by a
 197.342 -     * comma-separated list of the thrown exception types.
 197.343 -     *
 197.344 -     * <p>The only possible modifiers for constructors are the access
 197.345 -     * modifiers {@code public}, {@code protected} or
 197.346 -     * {@code private}.  Only one of these may appear, or none if the
 197.347 -     * constructor has default (package) access.
 197.348 -     *
 197.349 -     * @return a string describing this {@code Constructor},
 197.350 -     * include type parameters
 197.351 -     *
 197.352 -     * @since 1.5
 197.353 -     */
 197.354 -    public String toGenericString() {
 197.355 -        try {
 197.356 -            StringBuilder sb = new StringBuilder();
 197.357 -            int mod = getModifiers() & Modifier.constructorModifiers();
 197.358 -            if (mod != 0) {
 197.359 -                sb.append(Modifier.toString(mod) + " ");
 197.360 -            }
 197.361 -            TypeVariable<?>[] typeparms = getTypeParameters();
 197.362 -            if (typeparms.length > 0) {
 197.363 -                boolean first = true;
 197.364 -                sb.append("<");
 197.365 -                for(TypeVariable<?> typeparm: typeparms) {
 197.366 -                    if (!first)
 197.367 -                        sb.append(",");
 197.368 -                    // Class objects can't occur here; no need to test
 197.369 -                    // and call Class.getName().
 197.370 -                    sb.append(typeparm.toString());
 197.371 -                    first = false;
 197.372 -                }
 197.373 -                sb.append("> ");
 197.374 -            }
 197.375 -            sb.append(Field.getTypeName(getDeclaringClass()));
 197.376 -            sb.append("(");
 197.377 -            Type[] params = getGenericParameterTypes();
 197.378 -            for (int j = 0; j < params.length; j++) {
 197.379 -                String param = (params[j] instanceof Class<?>)?
 197.380 -                    Field.getTypeName((Class<?>)params[j]):
 197.381 -                    (params[j].toString());
 197.382 -                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 197.383 -                    param = param.replaceFirst("\\[\\]$", "...");
 197.384 -                sb.append(param);
 197.385 -                if (j < (params.length - 1))
 197.386 -                    sb.append(",");
 197.387 -            }
 197.388 -            sb.append(")");
 197.389 -            Type[] exceptions = getGenericExceptionTypes();
 197.390 -            if (exceptions.length > 0) {
 197.391 -                sb.append(" throws ");
 197.392 -                for (int k = 0; k < exceptions.length; k++) {
 197.393 -                    sb.append((exceptions[k] instanceof Class)?
 197.394 -                              ((Class<?>)exceptions[k]).getName():
 197.395 -                              exceptions[k].toString());
 197.396 -                    if (k < (exceptions.length - 1))
 197.397 -                        sb.append(",");
 197.398 -                }
 197.399 -            }
 197.400 -            return sb.toString();
 197.401 -        } catch (Exception e) {
 197.402 -            return "<" + e + ">";
 197.403 -        }
 197.404 -    }
 197.405 -
 197.406 -    /**
 197.407 -     * Uses the constructor represented by this {@code Constructor} object to
 197.408 -     * create and initialize a new instance of the constructor's
 197.409 -     * declaring class, with the specified initialization parameters.
 197.410 -     * Individual parameters are automatically unwrapped to match
 197.411 -     * primitive formal parameters, and both primitive and reference
 197.412 -     * parameters are subject to method invocation conversions as necessary.
 197.413 -     *
 197.414 -     * <p>If the number of formal parameters required by the underlying constructor
 197.415 -     * is 0, the supplied {@code initargs} array may be of length 0 or null.
 197.416 -     *
 197.417 -     * <p>If the constructor's declaring class is an inner class in a
 197.418 -     * non-static context, the first argument to the constructor needs
 197.419 -     * to be the enclosing instance; see section 15.9.3 of
 197.420 -     * <cite>The Java&trade; Language Specification</cite>.
 197.421 -     *
 197.422 -     * <p>If the required access and argument checks succeed and the
 197.423 -     * instantiation will proceed, the constructor's declaring class
 197.424 -     * is initialized if it has not already been initialized.
 197.425 -     *
 197.426 -     * <p>If the constructor completes normally, returns the newly
 197.427 -     * created and initialized instance.
 197.428 -     *
 197.429 -     * @param initargs array of objects to be passed as arguments to
 197.430 -     * the constructor call; values of primitive types are wrapped in
 197.431 -     * a wrapper object of the appropriate type (e.g. a {@code float}
 197.432 -     * in a {@link java.lang.Float Float})
 197.433 -     *
 197.434 -     * @return a new object created by calling the constructor
 197.435 -     * this object represents
 197.436 -     *
 197.437 -     * @exception IllegalAccessException    if this {@code Constructor} object
 197.438 -     *              is enforcing Java language access control and the underlying
 197.439 -     *              constructor is inaccessible.
 197.440 -     * @exception IllegalArgumentException  if the number of actual
 197.441 -     *              and formal parameters differ; if an unwrapping
 197.442 -     *              conversion for primitive arguments fails; or if,
 197.443 -     *              after possible unwrapping, a parameter value
 197.444 -     *              cannot be converted to the corresponding formal
 197.445 -     *              parameter type by a method invocation conversion; if
 197.446 -     *              this constructor pertains to an enum type.
 197.447 -     * @exception InstantiationException    if the class that declares the
 197.448 -     *              underlying constructor represents an abstract class.
 197.449 -     * @exception InvocationTargetException if the underlying constructor
 197.450 -     *              throws an exception.
 197.451 -     * @exception ExceptionInInitializerError if the initialization provoked
 197.452 -     *              by this method fails.
 197.453 -     */
 197.454 -    public T newInstance(Object ... initargs)
 197.455 -        throws InstantiationException, IllegalAccessException,
 197.456 -               IllegalArgumentException, InvocationTargetException
 197.457 -    {
 197.458 -        throw new SecurityException();
 197.459 -    }
 197.460 -
 197.461 -    /**
 197.462 -     * Returns {@code true} if this constructor was declared to take
 197.463 -     * a variable number of arguments; returns {@code false}
 197.464 -     * otherwise.
 197.465 -     *
 197.466 -     * @return {@code true} if an only if this constructor was declared to
 197.467 -     * take a variable number of arguments.
 197.468 -     * @since 1.5
 197.469 -     */
 197.470 -    public boolean isVarArgs() {
 197.471 -        return (getModifiers() & Modifier.VARARGS) != 0;
 197.472 -    }
 197.473 -
 197.474 -    /**
 197.475 -     * Returns {@code true} if this constructor is a synthetic
 197.476 -     * constructor; returns {@code false} otherwise.
 197.477 -     *
 197.478 -     * @return true if and only if this constructor is a synthetic
 197.479 -     * constructor as defined by
 197.480 -     * <cite>The Java&trade; Language Specification</cite>.
 197.481 -     * @since 1.5
 197.482 -     */
 197.483 -    public boolean isSynthetic() {
 197.484 -        return Modifier.isSynthetic(getModifiers());
 197.485 -    }
 197.486 -
 197.487 -    int getSlot() {
 197.488 -        return slot;
 197.489 -    }
 197.490 -
 197.491 -   String getSignature() {
 197.492 -            return signature;
 197.493 -   }
 197.494 -
 197.495 -    byte[] getRawAnnotations() {
 197.496 -        return annotations;
 197.497 -    }
 197.498 -
 197.499 -    byte[] getRawParameterAnnotations() {
 197.500 -        return parameterAnnotations;
 197.501 -    }
 197.502 -
 197.503 -    /**
 197.504 -     * @throws NullPointerException {@inheritDoc}
 197.505 -     * @since 1.5
 197.506 -     */
 197.507 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 197.508 -        if (annotationClass == null)
 197.509 -            throw new NullPointerException();
 197.510 -
 197.511 -        return null; // XXX (T) declaredAnnotations().get(annotationClass);
 197.512 -    }
 197.513 -
 197.514 -    /**
 197.515 -     * @since 1.5
 197.516 -     */
 197.517 -    public Annotation[] getDeclaredAnnotations()  {
 197.518 -        return new Annotation[0]; // XXX AnnotationParser.toArray(declaredAnnotations());
 197.519 -    }
 197.520 -
 197.521 -    /**
 197.522 -     * Returns an array of arrays that represent the annotations on the formal
 197.523 -     * parameters, in declaration order, of the method represented by
 197.524 -     * this {@code Constructor} object. (Returns an array of length zero if the
 197.525 -     * underlying method is parameterless.  If the method has one or more
 197.526 -     * parameters, a nested array of length zero is returned for each parameter
 197.527 -     * with no annotations.) The annotation objects contained in the returned
 197.528 -     * arrays are serializable.  The caller of this method is free to modify
 197.529 -     * the returned arrays; it will have no effect on the arrays returned to
 197.530 -     * other callers.
 197.531 -     *
 197.532 -     * @return an array of arrays that represent the annotations on the formal
 197.533 -     *    parameters, in declaration order, of the method represented by this
 197.534 -     *    Constructor object
 197.535 -     * @since 1.5
 197.536 -     */
 197.537 -    public Annotation[][] getParameterAnnotations() {
 197.538 -        int numParameters = parameterTypes.length;
 197.539 -        if (parameterAnnotations == null)
 197.540 -            return new Annotation[numParameters][0];
 197.541 -        
 197.542 -        return new Annotation[numParameters][0]; // XXX
 197.543 -/*
 197.544 -        Annotation[][] result = AnnotationParser.parseParameterAnnotations(
 197.545 -            parameterAnnotations,
 197.546 -            sun.misc.SharedSecrets.getJavaLangAccess().
 197.547 -                getConstantPool(getDeclaringClass()),
 197.548 -            getDeclaringClass());
 197.549 -        if (result.length != numParameters) {
 197.550 -            Class<?> declaringClass = getDeclaringClass();
 197.551 -            if (declaringClass.isEnum() ||
 197.552 -                declaringClass.isAnonymousClass() ||
 197.553 -                declaringClass.isLocalClass() )
 197.554 -                ; // Can't do reliable parameter counting
 197.555 -            else {
 197.556 -                if (!declaringClass.isMemberClass() || // top-level
 197.557 -                    // Check for the enclosing instance parameter for
 197.558 -                    // non-static member classes
 197.559 -                    (declaringClass.isMemberClass() &&
 197.560 -                     ((declaringClass.getModifiers() & Modifier.STATIC) == 0)  &&
 197.561 -                     result.length + 1 != numParameters) ) {
 197.562 -                    throw new AnnotationFormatError(
 197.563 -                              "Parameter annotations don't match number of parameters");
 197.564 -                }
 197.565 -            }
 197.566 -        }
 197.567 -        return result;
 197.568 -        */
 197.569 -    }
 197.570 -}
   198.1 --- a/emul/mini/src/main/java/java/lang/reflect/Field.java	Mon Feb 25 19:00:08 2013 +0100
   198.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   198.3 @@ -1,953 +0,0 @@
   198.4 -/*
   198.5 - * Copyright (c) 1996, 2006, 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.lang.reflect;
  198.30 -
  198.31 -import java.lang.annotation.Annotation;
  198.32 -
  198.33 -
  198.34 -/**
  198.35 - * A {@code Field} provides information about, and dynamic access to, a
  198.36 - * single field of a class or an interface.  The reflected field may
  198.37 - * be a class (static) field or an instance field.
  198.38 - *
  198.39 - * <p>A {@code Field} permits widening conversions to occur during a get or
  198.40 - * set access operation, but throws an {@code IllegalArgumentException} if a
  198.41 - * narrowing conversion would occur.
  198.42 - *
  198.43 - * @see Member
  198.44 - * @see java.lang.Class
  198.45 - * @see java.lang.Class#getFields()
  198.46 - * @see java.lang.Class#getField(String)
  198.47 - * @see java.lang.Class#getDeclaredFields()
  198.48 - * @see java.lang.Class#getDeclaredField(String)
  198.49 - *
  198.50 - * @author Kenneth Russell
  198.51 - * @author Nakul Saraiya
  198.52 - */
  198.53 -public final
  198.54 -class Field extends AccessibleObject implements Member {
  198.55 -
  198.56 -    private Class<?>            clazz;
  198.57 -    private int                 slot;
  198.58 -    // This is guaranteed to be interned by the VM in the 1.4
  198.59 -    // reflection implementation
  198.60 -    private String              name;
  198.61 -    private Class<?>            type;
  198.62 -    private int                 modifiers;
  198.63 -    // Generics and annotations support
  198.64 -    private transient String    signature;
  198.65 -    private byte[]              annotations;
  198.66 -    // For sharing of FieldAccessors. This branching structure is
  198.67 -    // currently only two levels deep (i.e., one root Field and
  198.68 -    // potentially many Field objects pointing to it.)
  198.69 -    private Field               root;
  198.70 -
  198.71 -    // Generics infrastructure
  198.72 -
  198.73 -    private String getGenericSignature() {return signature;}
  198.74 -
  198.75 -
  198.76 -    /**
  198.77 -     * Package-private constructor used by ReflectAccess to enable
  198.78 -     * instantiation of these objects in Java code from the java.lang
  198.79 -     * package via sun.reflect.LangReflectAccess.
  198.80 -     */
  198.81 -    Field(Class<?> declaringClass,
  198.82 -          String name,
  198.83 -          Class<?> type,
  198.84 -          int modifiers,
  198.85 -          int slot,
  198.86 -          String signature,
  198.87 -          byte[] annotations)
  198.88 -    {
  198.89 -        this.clazz = declaringClass;
  198.90 -        this.name = name;
  198.91 -        this.type = type;
  198.92 -        this.modifiers = modifiers;
  198.93 -        this.slot = slot;
  198.94 -        this.signature = signature;
  198.95 -        this.annotations = annotations;
  198.96 -    }
  198.97 -
  198.98 -    /**
  198.99 -     * Package-private routine (exposed to java.lang.Class via
 198.100 -     * ReflectAccess) which returns a copy of this Field. The copy's
 198.101 -     * "root" field points to this Field.
 198.102 -     */
 198.103 -    Field copy() {
 198.104 -        // This routine enables sharing of FieldAccessor objects
 198.105 -        // among Field objects which refer to the same underlying
 198.106 -        // method in the VM. (All of this contortion is only necessary
 198.107 -        // because of the "accessibility" bit in AccessibleObject,
 198.108 -        // which implicitly requires that new java.lang.reflect
 198.109 -        // objects be fabricated for each reflective call on Class
 198.110 -        // objects.)
 198.111 -        Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 198.112 -        res.root = this;
 198.113 -        return res;
 198.114 -    }
 198.115 -
 198.116 -    /**
 198.117 -     * Returns the {@code Class} object representing the class or interface
 198.118 -     * that declares the field represented by this {@code Field} object.
 198.119 -     */
 198.120 -    public Class<?> getDeclaringClass() {
 198.121 -        return clazz;
 198.122 -    }
 198.123 -
 198.124 -    /**
 198.125 -     * Returns the name of the field represented by this {@code Field} object.
 198.126 -     */
 198.127 -    public String getName() {
 198.128 -        return name;
 198.129 -    }
 198.130 -
 198.131 -    /**
 198.132 -     * Returns the Java language modifiers for the field represented
 198.133 -     * by this {@code Field} object, as an integer. The {@code Modifier} class should
 198.134 -     * be used to decode the modifiers.
 198.135 -     *
 198.136 -     * @see Modifier
 198.137 -     */
 198.138 -    public int getModifiers() {
 198.139 -        return modifiers;
 198.140 -    }
 198.141 -
 198.142 -    /**
 198.143 -     * Returns {@code true} if this field represents an element of
 198.144 -     * an enumerated type; returns {@code false} otherwise.
 198.145 -     *
 198.146 -     * @return {@code true} if and only if this field represents an element of
 198.147 -     * an enumerated type.
 198.148 -     * @since 1.5
 198.149 -     */
 198.150 -    public boolean isEnumConstant() {
 198.151 -        return (getModifiers() & Modifier.ENUM) != 0;
 198.152 -    }
 198.153 -
 198.154 -    /**
 198.155 -     * Returns {@code true} if this field is a synthetic
 198.156 -     * field; returns {@code false} otherwise.
 198.157 -     *
 198.158 -     * @return true if and only if this field is a synthetic
 198.159 -     * field as defined by the Java Language Specification.
 198.160 -     * @since 1.5
 198.161 -     */
 198.162 -    public boolean isSynthetic() {
 198.163 -        return Modifier.isSynthetic(getModifiers());
 198.164 -    }
 198.165 -
 198.166 -    /**
 198.167 -     * Returns a {@code Class} object that identifies the
 198.168 -     * declared type for the field represented by this
 198.169 -     * {@code Field} object.
 198.170 -     *
 198.171 -     * @return a {@code Class} object identifying the declared
 198.172 -     * type of the field represented by this object
 198.173 -     */
 198.174 -    public Class<?> getType() {
 198.175 -        return type;
 198.176 -    }
 198.177 -
 198.178 -    /**
 198.179 -     * Returns a {@code Type} object that represents the declared type for
 198.180 -     * the field represented by this {@code Field} object.
 198.181 -     *
 198.182 -     * <p>If the {@code Type} is a parameterized type, the
 198.183 -     * {@code Type} object returned must accurately reflect the
 198.184 -     * actual type parameters used in the source code.
 198.185 -     *
 198.186 -     * <p>If the type of the underlying field is a type variable or a
 198.187 -     * parameterized type, it is created. Otherwise, it is resolved.
 198.188 -     *
 198.189 -     * @return a {@code Type} object that represents the declared type for
 198.190 -     *     the field represented by this {@code Field} object
 198.191 -     * @throws GenericSignatureFormatError if the generic field
 198.192 -     *     signature does not conform to the format specified in
 198.193 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 198.194 -     * @throws TypeNotPresentException if the generic type
 198.195 -     *     signature of the underlying field refers to a non-existent
 198.196 -     *     type declaration
 198.197 -     * @throws MalformedParameterizedTypeException if the generic
 198.198 -     *     signature of the underlying field refers to a parameterized type
 198.199 -     *     that cannot be instantiated for any reason
 198.200 -     * @since 1.5
 198.201 -     */
 198.202 -    public Type getGenericType() {
 198.203 -        throw new UnsupportedOperationException();
 198.204 -    }
 198.205 -
 198.206 -
 198.207 -    /**
 198.208 -     * Compares this {@code Field} against the specified object.  Returns
 198.209 -     * true if the objects are the same.  Two {@code Field} objects are the same if
 198.210 -     * they were declared by the same class and have the same name
 198.211 -     * and type.
 198.212 -     */
 198.213 -    public boolean equals(Object obj) {
 198.214 -        if (obj != null && obj instanceof Field) {
 198.215 -            Field other = (Field)obj;
 198.216 -            return (getDeclaringClass() == other.getDeclaringClass())
 198.217 -                && (getName() == other.getName())
 198.218 -                && (getType() == other.getType());
 198.219 -        }
 198.220 -        return false;
 198.221 -    }
 198.222 -
 198.223 -    /**
 198.224 -     * Returns a hashcode for this {@code Field}.  This is computed as the
 198.225 -     * exclusive-or of the hashcodes for the underlying field's
 198.226 -     * declaring class name and its name.
 198.227 -     */
 198.228 -    public int hashCode() {
 198.229 -        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 198.230 -    }
 198.231 -
 198.232 -    /**
 198.233 -     * Returns a string describing this {@code Field}.  The format is
 198.234 -     * the access modifiers for the field, if any, followed
 198.235 -     * by the field type, followed by a space, followed by
 198.236 -     * the fully-qualified name of the class declaring the field,
 198.237 -     * followed by a period, followed by the name of the field.
 198.238 -     * For example:
 198.239 -     * <pre>
 198.240 -     *    public static final int java.lang.Thread.MIN_PRIORITY
 198.241 -     *    private int java.io.FileDescriptor.fd
 198.242 -     * </pre>
 198.243 -     *
 198.244 -     * <p>The modifiers are placed in canonical order as specified by
 198.245 -     * "The Java Language Specification".  This is {@code public},
 198.246 -     * {@code protected} or {@code private} first, and then other
 198.247 -     * modifiers in the following order: {@code static}, {@code final},
 198.248 -     * {@code transient}, {@code volatile}.
 198.249 -     */
 198.250 -    public String toString() {
 198.251 -        int mod = getModifiers();
 198.252 -        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 198.253 -            + getTypeName(getType()) + " "
 198.254 -            + getTypeName(getDeclaringClass()) + "."
 198.255 -            + getName());
 198.256 -    }
 198.257 -
 198.258 -    /**
 198.259 -     * Returns a string describing this {@code Field}, including
 198.260 -     * its generic type.  The format is the access modifiers for the
 198.261 -     * field, if any, followed by the generic field type, followed by
 198.262 -     * a space, followed by the fully-qualified name of the class
 198.263 -     * declaring the field, followed by a period, followed by the name
 198.264 -     * of the field.
 198.265 -     *
 198.266 -     * <p>The modifiers are placed in canonical order as specified by
 198.267 -     * "The Java Language Specification".  This is {@code public},
 198.268 -     * {@code protected} or {@code private} first, and then other
 198.269 -     * modifiers in the following order: {@code static}, {@code final},
 198.270 -     * {@code transient}, {@code volatile}.
 198.271 -     *
 198.272 -     * @return a string describing this {@code Field}, including
 198.273 -     * its generic type
 198.274 -     *
 198.275 -     * @since 1.5
 198.276 -     */
 198.277 -    public String toGenericString() {
 198.278 -        int mod = getModifiers();
 198.279 -        Type fieldType = getGenericType();
 198.280 -        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 198.281 -            +  ((fieldType instanceof Class) ?
 198.282 -                getTypeName((Class)fieldType): fieldType.toString())+ " "
 198.283 -            + getTypeName(getDeclaringClass()) + "."
 198.284 -            + getName());
 198.285 -    }
 198.286 -
 198.287 -    /**
 198.288 -     * Returns the value of the field represented by this {@code Field}, on
 198.289 -     * the specified object. The value is automatically wrapped in an
 198.290 -     * object if it has a primitive type.
 198.291 -     *
 198.292 -     * <p>The underlying field's value is obtained as follows:
 198.293 -     *
 198.294 -     * <p>If the underlying field is a static field, the {@code obj} argument
 198.295 -     * is ignored; it may be null.
 198.296 -     *
 198.297 -     * <p>Otherwise, the underlying field is an instance field.  If the
 198.298 -     * specified {@code obj} argument is null, the method throws a
 198.299 -     * {@code NullPointerException}. If the specified object is not an
 198.300 -     * instance of the class or interface declaring the underlying
 198.301 -     * field, the method throws an {@code IllegalArgumentException}.
 198.302 -     *
 198.303 -     * <p>If this {@code Field} object is enforcing Java language access control, and
 198.304 -     * the underlying field is inaccessible, the method throws an
 198.305 -     * {@code IllegalAccessException}.
 198.306 -     * If the underlying field is static, the class that declared the
 198.307 -     * field is initialized if it has not already been initialized.
 198.308 -     *
 198.309 -     * <p>Otherwise, the value is retrieved from the underlying instance
 198.310 -     * or static field.  If the field has a primitive type, the value
 198.311 -     * is wrapped in an object before being returned, otherwise it is
 198.312 -     * returned as is.
 198.313 -     *
 198.314 -     * <p>If the field is hidden in the type of {@code obj},
 198.315 -     * the field's value is obtained according to the preceding rules.
 198.316 -     *
 198.317 -     * @param obj object from which the represented field's value is
 198.318 -     * to be extracted
 198.319 -     * @return the value of the represented field in object
 198.320 -     * {@code obj}; primitive values are wrapped in an appropriate
 198.321 -     * object before being returned
 198.322 -     *
 198.323 -     * @exception IllegalAccessException    if this {@code Field} object
 198.324 -     *              is enforcing Java language access control and the underlying
 198.325 -     *              field is inaccessible.
 198.326 -     * @exception IllegalArgumentException  if the specified object is not an
 198.327 -     *              instance of the class or interface declaring the underlying
 198.328 -     *              field (or a subclass or implementor thereof).
 198.329 -     * @exception NullPointerException      if the specified object is null
 198.330 -     *              and the field is an instance field.
 198.331 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.332 -     *              by this method fails.
 198.333 -     */
 198.334 -    public Object get(Object obj)
 198.335 -        throws IllegalArgumentException, IllegalAccessException
 198.336 -    {
 198.337 -        return getFieldAccessor(obj).get(obj);
 198.338 -    }
 198.339 -
 198.340 -    /**
 198.341 -     * Gets the value of a static or instance {@code boolean} field.
 198.342 -     *
 198.343 -     * @param obj the object to extract the {@code boolean} value
 198.344 -     * from
 198.345 -     * @return the value of the {@code boolean} field
 198.346 -     *
 198.347 -     * @exception IllegalAccessException    if this {@code Field} object
 198.348 -     *              is enforcing Java language access control and the underlying
 198.349 -     *              field is inaccessible.
 198.350 -     * @exception IllegalArgumentException  if the specified object is not
 198.351 -     *              an instance of the class or interface declaring the
 198.352 -     *              underlying field (or a subclass or implementor
 198.353 -     *              thereof), or if the field value cannot be
 198.354 -     *              converted to the type {@code boolean} by a
 198.355 -     *              widening conversion.
 198.356 -     * @exception NullPointerException      if the specified object is null
 198.357 -     *              and the field is an instance field.
 198.358 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.359 -     *              by this method fails.
 198.360 -     * @see       Field#get
 198.361 -     */
 198.362 -    public boolean getBoolean(Object obj)
 198.363 -        throws IllegalArgumentException, IllegalAccessException
 198.364 -    {
 198.365 -        return getFieldAccessor(obj).getBoolean(obj);
 198.366 -    }
 198.367 -
 198.368 -    /**
 198.369 -     * Gets the value of a static or instance {@code byte} field.
 198.370 -     *
 198.371 -     * @param obj the object to extract the {@code byte} value
 198.372 -     * from
 198.373 -     * @return the value of the {@code byte} field
 198.374 -     *
 198.375 -     * @exception IllegalAccessException    if this {@code Field} object
 198.376 -     *              is enforcing Java language access control and the underlying
 198.377 -     *              field is inaccessible.
 198.378 -     * @exception IllegalArgumentException  if the specified object is not
 198.379 -     *              an instance of the class or interface declaring the
 198.380 -     *              underlying field (or a subclass or implementor
 198.381 -     *              thereof), or if the field value cannot be
 198.382 -     *              converted to the type {@code byte} by a
 198.383 -     *              widening conversion.
 198.384 -     * @exception NullPointerException      if the specified object is null
 198.385 -     *              and the field is an instance field.
 198.386 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.387 -     *              by this method fails.
 198.388 -     * @see       Field#get
 198.389 -     */
 198.390 -    public byte getByte(Object obj)
 198.391 -        throws IllegalArgumentException, IllegalAccessException
 198.392 -    {
 198.393 -        return getFieldAccessor(obj).getByte(obj);
 198.394 -    }
 198.395 -
 198.396 -    /**
 198.397 -     * Gets the value of a static or instance field of type
 198.398 -     * {@code char} or of another primitive type convertible to
 198.399 -     * type {@code char} via a widening conversion.
 198.400 -     *
 198.401 -     * @param obj the object to extract the {@code char} value
 198.402 -     * from
 198.403 -     * @return the value of the field converted to type {@code char}
 198.404 -     *
 198.405 -     * @exception IllegalAccessException    if this {@code Field} object
 198.406 -     *              is enforcing Java language access control and the underlying
 198.407 -     *              field is inaccessible.
 198.408 -     * @exception IllegalArgumentException  if the specified object is not
 198.409 -     *              an instance of the class or interface declaring the
 198.410 -     *              underlying field (or a subclass or implementor
 198.411 -     *              thereof), or if the field value cannot be
 198.412 -     *              converted to the type {@code char} by a
 198.413 -     *              widening conversion.
 198.414 -     * @exception NullPointerException      if the specified object is null
 198.415 -     *              and the field is an instance field.
 198.416 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.417 -     *              by this method fails.
 198.418 -     * @see Field#get
 198.419 -     */
 198.420 -    public char getChar(Object obj)
 198.421 -        throws IllegalArgumentException, IllegalAccessException
 198.422 -    {
 198.423 -        return getFieldAccessor(obj).getChar(obj);
 198.424 -    }
 198.425 -
 198.426 -    /**
 198.427 -     * Gets the value of a static or instance field of type
 198.428 -     * {@code short} or of another primitive type convertible to
 198.429 -     * type {@code short} via a widening conversion.
 198.430 -     *
 198.431 -     * @param obj the object to extract the {@code short} value
 198.432 -     * from
 198.433 -     * @return the value of the field converted to type {@code short}
 198.434 -     *
 198.435 -     * @exception IllegalAccessException    if this {@code Field} object
 198.436 -     *              is enforcing Java language access control and the underlying
 198.437 -     *              field is inaccessible.
 198.438 -     * @exception IllegalArgumentException  if the specified object is not
 198.439 -     *              an instance of the class or interface declaring the
 198.440 -     *              underlying field (or a subclass or implementor
 198.441 -     *              thereof), or if the field value cannot be
 198.442 -     *              converted to the type {@code short} by a
 198.443 -     *              widening conversion.
 198.444 -     * @exception NullPointerException      if the specified object is null
 198.445 -     *              and the field is an instance field.
 198.446 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.447 -     *              by this method fails.
 198.448 -     * @see       Field#get
 198.449 -     */
 198.450 -    public short getShort(Object obj)
 198.451 -        throws IllegalArgumentException, IllegalAccessException
 198.452 -    {
 198.453 -        return getFieldAccessor(obj).getShort(obj);
 198.454 -    }
 198.455 -
 198.456 -    /**
 198.457 -     * Gets the value of a static or instance field of type
 198.458 -     * {@code int} or of another primitive type convertible to
 198.459 -     * type {@code int} via a widening conversion.
 198.460 -     *
 198.461 -     * @param obj the object to extract the {@code int} value
 198.462 -     * from
 198.463 -     * @return the value of the field converted to type {@code int}
 198.464 -     *
 198.465 -     * @exception IllegalAccessException    if this {@code Field} object
 198.466 -     *              is enforcing Java language access control and the underlying
 198.467 -     *              field is inaccessible.
 198.468 -     * @exception IllegalArgumentException  if the specified object is not
 198.469 -     *              an instance of the class or interface declaring the
 198.470 -     *              underlying field (or a subclass or implementor
 198.471 -     *              thereof), or if the field value cannot be
 198.472 -     *              converted to the type {@code int} by a
 198.473 -     *              widening conversion.
 198.474 -     * @exception NullPointerException      if the specified object is null
 198.475 -     *              and the field is an instance field.
 198.476 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.477 -     *              by this method fails.
 198.478 -     * @see       Field#get
 198.479 -     */
 198.480 -    public int getInt(Object obj)
 198.481 -        throws IllegalArgumentException, IllegalAccessException
 198.482 -    {
 198.483 -        return getFieldAccessor(obj).getInt(obj);
 198.484 -    }
 198.485 -
 198.486 -    /**
 198.487 -     * Gets the value of a static or instance field of type
 198.488 -     * {@code long} or of another primitive type convertible to
 198.489 -     * type {@code long} via a widening conversion.
 198.490 -     *
 198.491 -     * @param obj the object to extract the {@code long} value
 198.492 -     * from
 198.493 -     * @return the value of the field converted to type {@code long}
 198.494 -     *
 198.495 -     * @exception IllegalAccessException    if this {@code Field} object
 198.496 -     *              is enforcing Java language access control and the underlying
 198.497 -     *              field is inaccessible.
 198.498 -     * @exception IllegalArgumentException  if the specified object is not
 198.499 -     *              an instance of the class or interface declaring the
 198.500 -     *              underlying field (or a subclass or implementor
 198.501 -     *              thereof), or if the field value cannot be
 198.502 -     *              converted to the type {@code long} by a
 198.503 -     *              widening conversion.
 198.504 -     * @exception NullPointerException      if the specified object is null
 198.505 -     *              and the field is an instance field.
 198.506 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.507 -     *              by this method fails.
 198.508 -     * @see       Field#get
 198.509 -     */
 198.510 -    public long getLong(Object obj)
 198.511 -        throws IllegalArgumentException, IllegalAccessException
 198.512 -    {
 198.513 -        return getFieldAccessor(obj).getLong(obj);
 198.514 -    }
 198.515 -
 198.516 -    /**
 198.517 -     * Gets the value of a static or instance field of type
 198.518 -     * {@code float} or of another primitive type convertible to
 198.519 -     * type {@code float} via a widening conversion.
 198.520 -     *
 198.521 -     * @param obj the object to extract the {@code float} value
 198.522 -     * from
 198.523 -     * @return the value of the field converted to type {@code float}
 198.524 -     *
 198.525 -     * @exception IllegalAccessException    if this {@code Field} object
 198.526 -     *              is enforcing Java language access control and the underlying
 198.527 -     *              field is inaccessible.
 198.528 -     * @exception IllegalArgumentException  if the specified object is not
 198.529 -     *              an instance of the class or interface declaring the
 198.530 -     *              underlying field (or a subclass or implementor
 198.531 -     *              thereof), or if the field value cannot be
 198.532 -     *              converted to the type {@code float} by a
 198.533 -     *              widening conversion.
 198.534 -     * @exception NullPointerException      if the specified object is null
 198.535 -     *              and the field is an instance field.
 198.536 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.537 -     *              by this method fails.
 198.538 -     * @see Field#get
 198.539 -     */
 198.540 -    public float getFloat(Object obj)
 198.541 -        throws IllegalArgumentException, IllegalAccessException
 198.542 -    {
 198.543 -        return getFieldAccessor(obj).getFloat(obj);
 198.544 -    }
 198.545 -
 198.546 -    /**
 198.547 -     * Gets the value of a static or instance field of type
 198.548 -     * {@code double} or of another primitive type convertible to
 198.549 -     * type {@code double} via a widening conversion.
 198.550 -     *
 198.551 -     * @param obj the object to extract the {@code double} value
 198.552 -     * from
 198.553 -     * @return the value of the field converted to type {@code double}
 198.554 -     *
 198.555 -     * @exception IllegalAccessException    if this {@code Field} object
 198.556 -     *              is enforcing Java language access control and the underlying
 198.557 -     *              field is inaccessible.
 198.558 -     * @exception IllegalArgumentException  if the specified object is not
 198.559 -     *              an instance of the class or interface declaring the
 198.560 -     *              underlying field (or a subclass or implementor
 198.561 -     *              thereof), or if the field value cannot be
 198.562 -     *              converted to the type {@code double} by a
 198.563 -     *              widening conversion.
 198.564 -     * @exception NullPointerException      if the specified object is null
 198.565 -     *              and the field is an instance field.
 198.566 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.567 -     *              by this method fails.
 198.568 -     * @see       Field#get
 198.569 -     */
 198.570 -    public double getDouble(Object obj)
 198.571 -        throws IllegalArgumentException, IllegalAccessException
 198.572 -    {
 198.573 -        return getFieldAccessor(obj).getDouble(obj);
 198.574 -    }
 198.575 -
 198.576 -    /**
 198.577 -     * Sets the field represented by this {@code Field} object on the
 198.578 -     * specified object argument to the specified new value. The new
 198.579 -     * value is automatically unwrapped if the underlying field has a
 198.580 -     * primitive type.
 198.581 -     *
 198.582 -     * <p>The operation proceeds as follows:
 198.583 -     *
 198.584 -     * <p>If the underlying field is static, the {@code obj} argument is
 198.585 -     * ignored; it may be null.
 198.586 -     *
 198.587 -     * <p>Otherwise the underlying field is an instance field.  If the
 198.588 -     * specified object argument is null, the method throws a
 198.589 -     * {@code NullPointerException}.  If the specified object argument is not
 198.590 -     * an instance of the class or interface declaring the underlying
 198.591 -     * field, the method throws an {@code IllegalArgumentException}.
 198.592 -     *
 198.593 -     * <p>If this {@code Field} object is enforcing Java language access control, and
 198.594 -     * the underlying field is inaccessible, the method throws an
 198.595 -     * {@code IllegalAccessException}.
 198.596 -     *
 198.597 -     * <p>If the underlying field is final, the method throws an
 198.598 -     * {@code IllegalAccessException} unless {@code setAccessible(true)}
 198.599 -     * has succeeded for this {@code Field} object
 198.600 -     * and the field is non-static. Setting a final field in this way
 198.601 -     * is meaningful only during deserialization or reconstruction of
 198.602 -     * instances of classes with blank final fields, before they are
 198.603 -     * made available for access by other parts of a program. Use in
 198.604 -     * any other context may have unpredictable effects, including cases
 198.605 -     * in which other parts of a program continue to use the original
 198.606 -     * value of this field.
 198.607 -     *
 198.608 -     * <p>If the underlying field is of a primitive type, an unwrapping
 198.609 -     * conversion is attempted to convert the new value to a value of
 198.610 -     * a primitive type.  If this attempt fails, the method throws an
 198.611 -     * {@code IllegalArgumentException}.
 198.612 -     *
 198.613 -     * <p>If, after possible unwrapping, the new value cannot be
 198.614 -     * converted to the type of the underlying field by an identity or
 198.615 -     * widening conversion, the method throws an
 198.616 -     * {@code IllegalArgumentException}.
 198.617 -     *
 198.618 -     * <p>If the underlying field is static, the class that declared the
 198.619 -     * field is initialized if it has not already been initialized.
 198.620 -     *
 198.621 -     * <p>The field is set to the possibly unwrapped and widened new value.
 198.622 -     *
 198.623 -     * <p>If the field is hidden in the type of {@code obj},
 198.624 -     * the field's value is set according to the preceding rules.
 198.625 -     *
 198.626 -     * @param obj the object whose field should be modified
 198.627 -     * @param value the new value for the field of {@code obj}
 198.628 -     * being modified
 198.629 -     *
 198.630 -     * @exception IllegalAccessException    if this {@code Field} object
 198.631 -     *              is enforcing Java language access control and the underlying
 198.632 -     *              field is either inaccessible or final.
 198.633 -     * @exception IllegalArgumentException  if the specified object is not an
 198.634 -     *              instance of the class or interface declaring the underlying
 198.635 -     *              field (or a subclass or implementor thereof),
 198.636 -     *              or if an unwrapping conversion fails.
 198.637 -     * @exception NullPointerException      if the specified object is null
 198.638 -     *              and the field is an instance field.
 198.639 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.640 -     *              by this method fails.
 198.641 -     */
 198.642 -    public void set(Object obj, Object value)
 198.643 -        throws IllegalArgumentException, IllegalAccessException
 198.644 -    {
 198.645 -        getFieldAccessor(obj).set(obj, value);
 198.646 -    }
 198.647 -
 198.648 -    /**
 198.649 -     * Sets the value of a field as a {@code boolean} on the specified object.
 198.650 -     * This method is equivalent to
 198.651 -     * {@code set(obj, zObj)},
 198.652 -     * where {@code zObj} is a {@code Boolean} object and
 198.653 -     * {@code zObj.booleanValue() == z}.
 198.654 -     *
 198.655 -     * @param obj the object whose field should be modified
 198.656 -     * @param z   the new value for the field of {@code obj}
 198.657 -     * being modified
 198.658 -     *
 198.659 -     * @exception IllegalAccessException    if this {@code Field} object
 198.660 -     *              is enforcing Java language access control and the underlying
 198.661 -     *              field is either inaccessible or final.
 198.662 -     * @exception IllegalArgumentException  if the specified object is not an
 198.663 -     *              instance of the class or interface declaring the underlying
 198.664 -     *              field (or a subclass or implementor thereof),
 198.665 -     *              or if an unwrapping conversion fails.
 198.666 -     * @exception NullPointerException      if the specified object is null
 198.667 -     *              and the field is an instance field.
 198.668 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.669 -     *              by this method fails.
 198.670 -     * @see       Field#set
 198.671 -     */
 198.672 -    public void setBoolean(Object obj, boolean z)
 198.673 -        throws IllegalArgumentException, IllegalAccessException
 198.674 -    {
 198.675 -        getFieldAccessor(obj).setBoolean(obj, z);
 198.676 -    }
 198.677 -
 198.678 -    /**
 198.679 -     * Sets the value of a field as a {@code byte} on the specified object.
 198.680 -     * This method is equivalent to
 198.681 -     * {@code set(obj, bObj)},
 198.682 -     * where {@code bObj} is a {@code Byte} object and
 198.683 -     * {@code bObj.byteValue() == b}.
 198.684 -     *
 198.685 -     * @param obj the object whose field should be modified
 198.686 -     * @param b   the new value for the field of {@code obj}
 198.687 -     * being modified
 198.688 -     *
 198.689 -     * @exception IllegalAccessException    if this {@code Field} object
 198.690 -     *              is enforcing Java language access control and the underlying
 198.691 -     *              field is either inaccessible or final.
 198.692 -     * @exception IllegalArgumentException  if the specified object is not an
 198.693 -     *              instance of the class or interface declaring the underlying
 198.694 -     *              field (or a subclass or implementor thereof),
 198.695 -     *              or if an unwrapping conversion fails.
 198.696 -     * @exception NullPointerException      if the specified object is null
 198.697 -     *              and the field is an instance field.
 198.698 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.699 -     *              by this method fails.
 198.700 -     * @see       Field#set
 198.701 -     */
 198.702 -    public void setByte(Object obj, byte b)
 198.703 -        throws IllegalArgumentException, IllegalAccessException
 198.704 -    {
 198.705 -        getFieldAccessor(obj).setByte(obj, b);
 198.706 -    }
 198.707 -
 198.708 -    /**
 198.709 -     * Sets the value of a field as a {@code char} on the specified object.
 198.710 -     * This method is equivalent to
 198.711 -     * {@code set(obj, cObj)},
 198.712 -     * where {@code cObj} is a {@code Character} object and
 198.713 -     * {@code cObj.charValue() == c}.
 198.714 -     *
 198.715 -     * @param obj the object whose field should be modified
 198.716 -     * @param c   the new value for the field of {@code obj}
 198.717 -     * being modified
 198.718 -     *
 198.719 -     * @exception IllegalAccessException    if this {@code Field} object
 198.720 -     *              is enforcing Java language access control and the underlying
 198.721 -     *              field is either inaccessible or final.
 198.722 -     * @exception IllegalArgumentException  if the specified object is not an
 198.723 -     *              instance of the class or interface declaring the underlying
 198.724 -     *              field (or a subclass or implementor thereof),
 198.725 -     *              or if an unwrapping conversion fails.
 198.726 -     * @exception NullPointerException      if the specified object is null
 198.727 -     *              and the field is an instance field.
 198.728 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.729 -     *              by this method fails.
 198.730 -     * @see       Field#set
 198.731 -     */
 198.732 -    public void setChar(Object obj, char c)
 198.733 -        throws IllegalArgumentException, IllegalAccessException
 198.734 -    {
 198.735 -        getFieldAccessor(obj).setChar(obj, c);
 198.736 -    }
 198.737 -
 198.738 -    /**
 198.739 -     * Sets the value of a field as a {@code short} on the specified object.
 198.740 -     * This method is equivalent to
 198.741 -     * {@code set(obj, sObj)},
 198.742 -     * where {@code sObj} is a {@code Short} object and
 198.743 -     * {@code sObj.shortValue() == s}.
 198.744 -     *
 198.745 -     * @param obj the object whose field should be modified
 198.746 -     * @param s   the new value for the field of {@code obj}
 198.747 -     * being modified
 198.748 -     *
 198.749 -     * @exception IllegalAccessException    if this {@code Field} object
 198.750 -     *              is enforcing Java language access control and the underlying
 198.751 -     *              field is either inaccessible or final.
 198.752 -     * @exception IllegalArgumentException  if the specified object is not an
 198.753 -     *              instance of the class or interface declaring the underlying
 198.754 -     *              field (or a subclass or implementor thereof),
 198.755 -     *              or if an unwrapping conversion fails.
 198.756 -     * @exception NullPointerException      if the specified object is null
 198.757 -     *              and the field is an instance field.
 198.758 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.759 -     *              by this method fails.
 198.760 -     * @see       Field#set
 198.761 -     */
 198.762 -    public void setShort(Object obj, short s)
 198.763 -        throws IllegalArgumentException, IllegalAccessException
 198.764 -    {
 198.765 -        getFieldAccessor(obj).setShort(obj, s);
 198.766 -    }
 198.767 -
 198.768 -    /**
 198.769 -     * Sets the value of a field as an {@code int} on the specified object.
 198.770 -     * This method is equivalent to
 198.771 -     * {@code set(obj, iObj)},
 198.772 -     * where {@code iObj} is a {@code Integer} object and
 198.773 -     * {@code iObj.intValue() == i}.
 198.774 -     *
 198.775 -     * @param obj the object whose field should be modified
 198.776 -     * @param i   the new value for the field of {@code obj}
 198.777 -     * being modified
 198.778 -     *
 198.779 -     * @exception IllegalAccessException    if this {@code Field} object
 198.780 -     *              is enforcing Java language access control and the underlying
 198.781 -     *              field is either inaccessible or final.
 198.782 -     * @exception IllegalArgumentException  if the specified object is not an
 198.783 -     *              instance of the class or interface declaring the underlying
 198.784 -     *              field (or a subclass or implementor thereof),
 198.785 -     *              or if an unwrapping conversion fails.
 198.786 -     * @exception NullPointerException      if the specified object is null
 198.787 -     *              and the field is an instance field.
 198.788 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.789 -     *              by this method fails.
 198.790 -     * @see       Field#set
 198.791 -     */
 198.792 -    public void setInt(Object obj, int i)
 198.793 -        throws IllegalArgumentException, IllegalAccessException
 198.794 -    {
 198.795 -        getFieldAccessor(obj).setInt(obj, i);
 198.796 -    }
 198.797 -
 198.798 -    /**
 198.799 -     * Sets the value of a field as a {@code long} on the specified object.
 198.800 -     * This method is equivalent to
 198.801 -     * {@code set(obj, lObj)},
 198.802 -     * where {@code lObj} is a {@code Long} object and
 198.803 -     * {@code lObj.longValue() == l}.
 198.804 -     *
 198.805 -     * @param obj the object whose field should be modified
 198.806 -     * @param l   the new value for the field of {@code obj}
 198.807 -     * being modified
 198.808 -     *
 198.809 -     * @exception IllegalAccessException    if this {@code Field} object
 198.810 -     *              is enforcing Java language access control and the underlying
 198.811 -     *              field is either inaccessible or final.
 198.812 -     * @exception IllegalArgumentException  if the specified object is not an
 198.813 -     *              instance of the class or interface declaring the underlying
 198.814 -     *              field (or a subclass or implementor thereof),
 198.815 -     *              or if an unwrapping conversion fails.
 198.816 -     * @exception NullPointerException      if the specified object is null
 198.817 -     *              and the field is an instance field.
 198.818 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.819 -     *              by this method fails.
 198.820 -     * @see       Field#set
 198.821 -     */
 198.822 -    public void setLong(Object obj, long l)
 198.823 -        throws IllegalArgumentException, IllegalAccessException
 198.824 -    {
 198.825 -        getFieldAccessor(obj).setLong(obj, l);
 198.826 -    }
 198.827 -
 198.828 -    /**
 198.829 -     * Sets the value of a field as a {@code float} on the specified object.
 198.830 -     * This method is equivalent to
 198.831 -     * {@code set(obj, fObj)},
 198.832 -     * where {@code fObj} is a {@code Float} object and
 198.833 -     * {@code fObj.floatValue() == f}.
 198.834 -     *
 198.835 -     * @param obj the object whose field should be modified
 198.836 -     * @param f   the new value for the field of {@code obj}
 198.837 -     * being modified
 198.838 -     *
 198.839 -     * @exception IllegalAccessException    if this {@code Field} object
 198.840 -     *              is enforcing Java language access control and the underlying
 198.841 -     *              field is either inaccessible or final.
 198.842 -     * @exception IllegalArgumentException  if the specified object is not an
 198.843 -     *              instance of the class or interface declaring the underlying
 198.844 -     *              field (or a subclass or implementor thereof),
 198.845 -     *              or if an unwrapping conversion fails.
 198.846 -     * @exception NullPointerException      if the specified object is null
 198.847 -     *              and the field is an instance field.
 198.848 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.849 -     *              by this method fails.
 198.850 -     * @see       Field#set
 198.851 -     */
 198.852 -    public void setFloat(Object obj, float f)
 198.853 -        throws IllegalArgumentException, IllegalAccessException
 198.854 -    {
 198.855 -        getFieldAccessor(obj).setFloat(obj, f);
 198.856 -    }
 198.857 -
 198.858 -    /**
 198.859 -     * Sets the value of a field as a {@code double} on the specified object.
 198.860 -     * This method is equivalent to
 198.861 -     * {@code set(obj, dObj)},
 198.862 -     * where {@code dObj} is a {@code Double} object and
 198.863 -     * {@code dObj.doubleValue() == d}.
 198.864 -     *
 198.865 -     * @param obj the object whose field should be modified
 198.866 -     * @param d   the new value for the field of {@code obj}
 198.867 -     * being modified
 198.868 -     *
 198.869 -     * @exception IllegalAccessException    if this {@code Field} object
 198.870 -     *              is enforcing Java language access control and the underlying
 198.871 -     *              field is either inaccessible or final.
 198.872 -     * @exception IllegalArgumentException  if the specified object is not an
 198.873 -     *              instance of the class or interface declaring the underlying
 198.874 -     *              field (or a subclass or implementor thereof),
 198.875 -     *              or if an unwrapping conversion fails.
 198.876 -     * @exception NullPointerException      if the specified object is null
 198.877 -     *              and the field is an instance field.
 198.878 -     * @exception ExceptionInInitializerError if the initialization provoked
 198.879 -     *              by this method fails.
 198.880 -     * @see       Field#set
 198.881 -     */
 198.882 -    public void setDouble(Object obj, double d)
 198.883 -        throws IllegalArgumentException, IllegalAccessException
 198.884 -    {
 198.885 -        getFieldAccessor(obj).setDouble(obj, d);
 198.886 -    }
 198.887 -
 198.888 -    // Convenience routine which performs security checks
 198.889 -    private FieldAccessor getFieldAccessor(Object obj)
 198.890 -        throws IllegalAccessException
 198.891 -    {
 198.892 -        throw new SecurityException();
 198.893 -    }
 198.894 -    
 198.895 -    private static abstract class FieldAccessor {
 198.896 -        abstract void setShort(Object obj, short s);
 198.897 -        abstract void setInt(Object obj, int i);
 198.898 -        abstract void setChar(Object obj, char c);
 198.899 -        abstract void setByte(Object obj, byte b);
 198.900 -        abstract void setBoolean(Object obj, boolean z);
 198.901 -        abstract void set(Object obj, Object value);
 198.902 -        abstract double getDouble(Object obj);
 198.903 -        abstract void setLong(Object obj, long l);
 198.904 -        abstract void setFloat(Object obj, float f);
 198.905 -        abstract void setDouble(Object obj, double d);
 198.906 -        abstract long getLong(Object obj);
 198.907 -        abstract int getInt(Object obj);
 198.908 -        abstract short getShort(Object obj);
 198.909 -        abstract char getChar(Object obj);
 198.910 -        abstract byte getByte(Object obj);
 198.911 -        abstract boolean getBoolean(Object obj);
 198.912 -        abstract Object get(Object obj);
 198.913 -        abstract float getFloat(Object obj);
 198.914 -    }
 198.915 -
 198.916 -    /*
 198.917 -     * Utility routine to paper over array type names
 198.918 -     */
 198.919 -    static String getTypeName(Class<?> type) {
 198.920 -        if (type.isArray()) {
 198.921 -            try {
 198.922 -                Class<?> cl = type;
 198.923 -                int dimensions = 0;
 198.924 -                while (cl.isArray()) {
 198.925 -                    dimensions++;
 198.926 -                    cl = cl.getComponentType();
 198.927 -                }
 198.928 -                StringBuffer sb = new StringBuffer();
 198.929 -                sb.append(cl.getName());
 198.930 -                for (int i = 0; i < dimensions; i++) {
 198.931 -                    sb.append("[]");
 198.932 -                }
 198.933 -                return sb.toString();
 198.934 -            } catch (Throwable e) { /*FALLTHRU*/ }
 198.935 -        }
 198.936 -        return type.getName();
 198.937 -    }
 198.938 -
 198.939 -    /**
 198.940 -     * @throws NullPointerException {@inheritDoc}
 198.941 -     * @since 1.5
 198.942 -     */
 198.943 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 198.944 -        if (annotationClass == null)
 198.945 -            throw new NullPointerException();
 198.946 -
 198.947 -        throw new UnsupportedOperationException();
 198.948 -    }
 198.949 -
 198.950 -    /**
 198.951 -     * @since 1.5
 198.952 -     */
 198.953 -    public Annotation[] getDeclaredAnnotations()  {
 198.954 -        throw new UnsupportedOperationException();
 198.955 -    }
 198.956 -}
   199.1 --- a/emul/mini/src/main/java/java/lang/reflect/GenericDeclaration.java	Mon Feb 25 19:00:08 2013 +0100
   199.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   199.3 @@ -1,49 +0,0 @@
   199.4 -/*
   199.5 - * Copyright (c) 2003, 2004, 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 -
  199.29 -package java.lang.reflect;
  199.30 -
  199.31 -/**
  199.32 - * A common interface for all entities that declare type variables.
  199.33 - *
  199.34 - * @since 1.5
  199.35 - */
  199.36 -public interface GenericDeclaration {
  199.37 -    /**
  199.38 -     * Returns an array of {@code TypeVariable} objects that
  199.39 -     * represent the type variables declared by the generic
  199.40 -     * declaration represented by this {@code GenericDeclaration}
  199.41 -     * object, in declaration order.  Returns an array of length 0 if
  199.42 -     * the underlying generic declaration declares no type variables.
  199.43 -     *
  199.44 -     * @return an array of {@code TypeVariable} objects that represent
  199.45 -     *     the type variables declared by this generic declaration
  199.46 -     * @throws GenericSignatureFormatError if the generic
  199.47 -     *     signature of this generic declaration does not conform to
  199.48 -     *     the format specified in
  199.49 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
  199.50 -     */
  199.51 -    public TypeVariable<?>[] getTypeParameters();
  199.52 -}
   200.1 --- a/emul/mini/src/main/java/java/lang/reflect/InvocationHandler.java	Mon Feb 25 19:00:08 2013 +0100
   200.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   200.3 @@ -1,95 +0,0 @@
   200.4 -/*
   200.5 - * Copyright (c) 1999, 2006, 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.reflect;
  200.30 -
  200.31 -/**
  200.32 - * {@code InvocationHandler} is the interface implemented by
  200.33 - * the <i>invocation handler</i> of a proxy instance.
  200.34 - *
  200.35 - * <p>Each proxy instance has an associated invocation handler.
  200.36 - * When a method is invoked on a proxy instance, the method
  200.37 - * invocation is encoded and dispatched to the {@code invoke}
  200.38 - * method of its invocation handler.
  200.39 - *
  200.40 - * @author      Peter Jones
  200.41 - * @see         Proxy
  200.42 - * @since       1.3
  200.43 - */
  200.44 -public interface InvocationHandler {
  200.45 -
  200.46 -    /**
  200.47 -     * Processes a method invocation on a proxy instance and returns
  200.48 -     * the result.  This method will be invoked on an invocation handler
  200.49 -     * when a method is invoked on a proxy instance that it is
  200.50 -     * associated with.
  200.51 -     *
  200.52 -     * @param   proxy the proxy instance that the method was invoked on
  200.53 -     *
  200.54 -     * @param   method the {@code Method} instance corresponding to
  200.55 -     * the interface method invoked on the proxy instance.  The declaring
  200.56 -     * class of the {@code Method} object will be the interface that
  200.57 -     * the method was declared in, which may be a superinterface of the
  200.58 -     * proxy interface that the proxy class inherits the method through.
  200.59 -     *
  200.60 -     * @param   args an array of objects containing the values of the
  200.61 -     * arguments passed in the method invocation on the proxy instance,
  200.62 -     * or {@code null} if interface method takes no arguments.
  200.63 -     * Arguments of primitive types are wrapped in instances of the
  200.64 -     * appropriate primitive wrapper class, such as
  200.65 -     * {@code java.lang.Integer} or {@code java.lang.Boolean}.
  200.66 -     *
  200.67 -     * @return  the value to return from the method invocation on the
  200.68 -     * proxy instance.  If the declared return type of the interface
  200.69 -     * method is a primitive type, then the value returned by
  200.70 -     * this method must be an instance of the corresponding primitive
  200.71 -     * wrapper class; otherwise, it must be a type assignable to the
  200.72 -     * declared return type.  If the value returned by this method is
  200.73 -     * {@code null} and the interface method's return type is
  200.74 -     * primitive, then a {@code NullPointerException} will be
  200.75 -     * thrown by the method invocation on the proxy instance.  If the
  200.76 -     * value returned by this method is otherwise not compatible with
  200.77 -     * the interface method's declared return type as described above,
  200.78 -     * a {@code ClassCastException} will be thrown by the method
  200.79 -     * invocation on the proxy instance.
  200.80 -     *
  200.81 -     * @throws  Throwable the exception to throw from the method
  200.82 -     * invocation on the proxy instance.  The exception's type must be
  200.83 -     * assignable either to any of the exception types declared in the
  200.84 -     * {@code throws} clause of the interface method or to the
  200.85 -     * unchecked exception types {@code java.lang.RuntimeException}
  200.86 -     * or {@code java.lang.Error}.  If a checked exception is
  200.87 -     * thrown by this method that is not assignable to any of the
  200.88 -     * exception types declared in the {@code throws} clause of
  200.89 -     * the interface method, then an
  200.90 -     * {@link UndeclaredThrowableException} containing the
  200.91 -     * exception that was thrown by this method will be thrown by the
  200.92 -     * method invocation on the proxy instance.
  200.93 -     *
  200.94 -     * @see     UndeclaredThrowableException
  200.95 -     */
  200.96 -    public Object invoke(Object proxy, Method method, Object[] args)
  200.97 -        throws Throwable;
  200.98 -}
   201.1 --- a/emul/mini/src/main/java/java/lang/reflect/InvocationTargetException.java	Mon Feb 25 19:00:08 2013 +0100
   201.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   201.3 @@ -1,111 +0,0 @@
   201.4 -/*
   201.5 - * Copyright (c) 1996, 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.reflect;
  201.30 -
  201.31 -/**
  201.32 - * InvocationTargetException is a checked exception that wraps
  201.33 - * an exception thrown by an invoked method or constructor.
  201.34 - *
  201.35 - * <p>As of release 1.4, this exception has been retrofitted to conform to
  201.36 - * the general purpose exception-chaining mechanism.  The "target exception"
  201.37 - * that is provided at construction time and accessed via the
  201.38 - * {@link #getTargetException()} method is now known as the <i>cause</i>,
  201.39 - * and may be accessed via the {@link Throwable#getCause()} method,
  201.40 - * as well as the aforementioned "legacy method."
  201.41 - *
  201.42 - * @see Method
  201.43 - * @see Constructor
  201.44 - */
  201.45 -public class InvocationTargetException extends ReflectiveOperationException {
  201.46 -    /**
  201.47 -     * Use serialVersionUID from JDK 1.1.X for interoperability
  201.48 -     */
  201.49 -    private static final long serialVersionUID = 4085088731926701167L;
  201.50 -
  201.51 -     /**
  201.52 -     * This field holds the target if the
  201.53 -     * InvocationTargetException(Throwable target) constructor was
  201.54 -     * used to instantiate the object
  201.55 -     *
  201.56 -     * @serial
  201.57 -     *
  201.58 -     */
  201.59 -    private Throwable target;
  201.60 -
  201.61 -    /**
  201.62 -     * Constructs an {@code InvocationTargetException} with
  201.63 -     * {@code null} as the target exception.
  201.64 -     */
  201.65 -    protected InvocationTargetException() {
  201.66 -        super((Throwable)null);  // Disallow initCause
  201.67 -    }
  201.68 -
  201.69 -    /**
  201.70 -     * Constructs a InvocationTargetException with a target exception.
  201.71 -     *
  201.72 -     * @param target the target exception
  201.73 -     */
  201.74 -    public InvocationTargetException(Throwable target) {
  201.75 -        super((Throwable)null);  // Disallow initCause
  201.76 -        this.target = target;
  201.77 -    }
  201.78 -
  201.79 -    /**
  201.80 -     * Constructs a InvocationTargetException with a target exception
  201.81 -     * and a detail message.
  201.82 -     *
  201.83 -     * @param target the target exception
  201.84 -     * @param s      the detail message
  201.85 -     */
  201.86 -    public InvocationTargetException(Throwable target, String s) {
  201.87 -        super(s, null);  // Disallow initCause
  201.88 -        this.target = target;
  201.89 -    }
  201.90 -
  201.91 -    /**
  201.92 -     * Get the thrown target exception.
  201.93 -     *
  201.94 -     * <p>This method predates the general-purpose exception chaining facility.
  201.95 -     * The {@link Throwable#getCause()} method is now the preferred means of
  201.96 -     * obtaining this information.
  201.97 -     *
  201.98 -     * @return the thrown target exception (cause of this exception).
  201.99 -     */
 201.100 -    public Throwable getTargetException() {
 201.101 -        return target;
 201.102 -    }
 201.103 -
 201.104 -    /**
 201.105 -     * Returns the cause of this exception (the thrown target exception,
 201.106 -     * which may be {@code null}).
 201.107 -     *
 201.108 -     * @return  the cause of this exception.
 201.109 -     * @since   1.4
 201.110 -     */
 201.111 -    public Throwable getCause() {
 201.112 -        return target;
 201.113 -    }
 201.114 -}
   202.1 --- a/emul/mini/src/main/java/java/lang/reflect/Member.java	Mon Feb 25 19:00:08 2013 +0100
   202.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   202.3 @@ -1,93 +0,0 @@
   202.4 -/*
   202.5 - * Copyright (c) 1996, 2006, 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.reflect;
  202.30 -
  202.31 -/**
  202.32 - * Member is an interface that reflects identifying information about
  202.33 - * a single member (a field or a method) or a constructor.
  202.34 - *
  202.35 - * @see java.lang.Class
  202.36 - * @see Field
  202.37 - * @see Method
  202.38 - * @see Constructor
  202.39 - *
  202.40 - * @author Nakul Saraiya
  202.41 - */
  202.42 -public
  202.43 -interface Member {
  202.44 -
  202.45 -    /**
  202.46 -     * Identifies the set of all public members of a class or interface,
  202.47 -     * including inherited members.
  202.48 -     * @see java.lang.SecurityManager#checkMemberAccess
  202.49 -     */
  202.50 -    public static final int PUBLIC = 0;
  202.51 -
  202.52 -    /**
  202.53 -     * Identifies the set of declared members of a class or interface.
  202.54 -     * Inherited members are not included.
  202.55 -     * @see java.lang.SecurityManager#checkMemberAccess
  202.56 -     */
  202.57 -    public static final int DECLARED = 1;
  202.58 -
  202.59 -    /**
  202.60 -     * Returns the Class object representing the class or interface
  202.61 -     * that declares the member or constructor represented by this Member.
  202.62 -     *
  202.63 -     * @return an object representing the declaring class of the
  202.64 -     * underlying member
  202.65 -     */
  202.66 -    public Class<?> getDeclaringClass();
  202.67 -
  202.68 -    /**
  202.69 -     * Returns the simple name of the underlying member or constructor
  202.70 -     * represented by this Member.
  202.71 -     *
  202.72 -     * @return the simple name of the underlying member
  202.73 -     */
  202.74 -    public String getName();
  202.75 -
  202.76 -    /**
  202.77 -     * Returns the Java language modifiers for the member or
  202.78 -     * constructor represented by this Member, as an integer.  The
  202.79 -     * Modifier class should be used to decode the modifiers in
  202.80 -     * the integer.
  202.81 -     *
  202.82 -     * @return the Java language modifiers for the underlying member
  202.83 -     * @see Modifier
  202.84 -     */
  202.85 -    public int getModifiers();
  202.86 -
  202.87 -    /**
  202.88 -     * Returns {@code true} if this member was introduced by
  202.89 -     * the compiler; returns {@code false} otherwise.
  202.90 -     *
  202.91 -     * @return true if and only if this member was introduced by
  202.92 -     * the compiler.
  202.93 -     * @since 1.5
  202.94 -     */
  202.95 -    public boolean isSynthetic();
  202.96 -}
   203.1 --- a/emul/mini/src/main/java/java/lang/reflect/Method.java	Mon Feb 25 19:00:08 2013 +0100
   203.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   203.3 @@ -1,721 +0,0 @@
   203.4 -/*
   203.5 - * Copyright (c) 1996, 2006, 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.reflect;
  203.30 -
  203.31 -import java.lang.annotation.Annotation;
  203.32 -import java.util.Enumeration;
  203.33 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  203.34 -import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
  203.35 -import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
  203.36 -
  203.37 -/**
  203.38 - * A {@code Method} provides information about, and access to, a single method
  203.39 - * on a class or interface.  The reflected method may be a class method
  203.40 - * or an instance method (including an abstract method).
  203.41 - *
  203.42 - * <p>A {@code Method} permits widening conversions to occur when matching the
  203.43 - * actual parameters to invoke with the underlying method's formal
  203.44 - * parameters, but it throws an {@code IllegalArgumentException} if a
  203.45 - * narrowing conversion would occur.
  203.46 - *
  203.47 - * @see Member
  203.48 - * @see java.lang.Class
  203.49 - * @see java.lang.Class#getMethods()
  203.50 - * @see java.lang.Class#getMethod(String, Class[])
  203.51 - * @see java.lang.Class#getDeclaredMethods()
  203.52 - * @see java.lang.Class#getDeclaredMethod(String, Class[])
  203.53 - *
  203.54 - * @author Kenneth Russell
  203.55 - * @author Nakul Saraiya
  203.56 - */
  203.57 -public final
  203.58 -    class Method extends AccessibleObject implements GenericDeclaration,
  203.59 -                                                     Member {
  203.60 -    private final Class<?> clazz;
  203.61 -    private final String name;
  203.62 -    private final Object data;
  203.63 -    private final String sig;
  203.64 -
  203.65 -   // Generics infrastructure
  203.66 -
  203.67 -    private String getGenericSignature() {return null;}
  203.68 -
  203.69 -    /**
  203.70 -     * Package-private constructor used by ReflectAccess to enable
  203.71 -     * instantiation of these objects in Java code from the java.lang
  203.72 -     * package via sun.reflect.LangReflectAccess.
  203.73 -     */
  203.74 -    Method(Class<?> declaringClass, String name, Object data, String sig)
  203.75 -    {
  203.76 -        this.clazz = declaringClass;
  203.77 -        this.name = name;
  203.78 -        this.data = data;
  203.79 -        this.sig = sig;
  203.80 -    }
  203.81 -
  203.82 -    /**
  203.83 -     * Package-private routine (exposed to java.lang.Class via
  203.84 -     * ReflectAccess) which returns a copy of this Method. The copy's
  203.85 -     * "root" field points to this Method.
  203.86 -     */
  203.87 -    Method copy() {
  203.88 -        return this;
  203.89 -    }
  203.90 -
  203.91 -    /**
  203.92 -     * Returns the {@code Class} object representing the class or interface
  203.93 -     * that declares the method represented by this {@code Method} object.
  203.94 -     */
  203.95 -    public Class<?> getDeclaringClass() {
  203.96 -        return clazz;
  203.97 -    }
  203.98 -
  203.99 -    /**
 203.100 -     * Returns the name of the method represented by this {@code Method}
 203.101 -     * object, as a {@code String}.
 203.102 -     */
 203.103 -    public String getName() {
 203.104 -        return name;
 203.105 -    }
 203.106 -
 203.107 -    /**
 203.108 -     * Returns the Java language modifiers for the method represented
 203.109 -     * by this {@code Method} object, as an integer. The {@code Modifier} class should
 203.110 -     * be used to decode the modifiers.
 203.111 -     *
 203.112 -     * @see Modifier
 203.113 -     */
 203.114 -    public int getModifiers() {
 203.115 -        return getAccess(data);
 203.116 -    }
 203.117 -    
 203.118 -    @JavaScriptBody(args = "self", body = "return self.access;")
 203.119 -    private static native int getAccess(Object self);
 203.120 -    
 203.121 -    /**
 203.122 -     * Returns an array of {@code TypeVariable} objects that represent the
 203.123 -     * type variables declared by the generic declaration represented by this
 203.124 -     * {@code GenericDeclaration} object, in declaration order.  Returns an
 203.125 -     * array of length 0 if the underlying generic declaration declares no type
 203.126 -     * variables.
 203.127 -     *
 203.128 -     * @return an array of {@code TypeVariable} objects that represent
 203.129 -     *     the type variables declared by this generic declaration
 203.130 -     * @throws GenericSignatureFormatError if the generic
 203.131 -     *     signature of this generic declaration does not conform to
 203.132 -     *     the format specified in
 203.133 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 203.134 -     * @since 1.5
 203.135 -     */
 203.136 -    public TypeVariable<Method>[] getTypeParameters() {
 203.137 -        throw new UnsupportedOperationException();
 203.138 -    }
 203.139 -
 203.140 -    /**
 203.141 -     * Returns a {@code Class} object that represents the formal return type
 203.142 -     * of the method represented by this {@code Method} object.
 203.143 -     *
 203.144 -     * @return the return type for the method this object represents
 203.145 -     */
 203.146 -    public Class<?> getReturnType() {
 203.147 -        return MethodImpl.signatureParser(sig).nextElement();
 203.148 -    }
 203.149 -
 203.150 -    /**
 203.151 -     * Returns a {@code Type} object that represents the formal return
 203.152 -     * type of the method represented by this {@code Method} object.
 203.153 -     *
 203.154 -     * <p>If the return type is a parameterized type,
 203.155 -     * the {@code Type} object returned must accurately reflect
 203.156 -     * the actual type parameters used in the source code.
 203.157 -     *
 203.158 -     * <p>If the return type is a type variable or a parameterized type, it
 203.159 -     * is created. Otherwise, it is resolved.
 203.160 -     *
 203.161 -     * @return  a {@code Type} object that represents the formal return
 203.162 -     *     type of the underlying  method
 203.163 -     * @throws GenericSignatureFormatError
 203.164 -     *     if the generic method signature does not conform to the format
 203.165 -     *     specified in
 203.166 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 203.167 -     * @throws TypeNotPresentException if the underlying method's
 203.168 -     *     return type refers to a non-existent type declaration
 203.169 -     * @throws MalformedParameterizedTypeException if the
 203.170 -     *     underlying method's return typed refers to a parameterized
 203.171 -     *     type that cannot be instantiated for any reason
 203.172 -     * @since 1.5
 203.173 -     */
 203.174 -    public Type getGenericReturnType() {
 203.175 -        throw new UnsupportedOperationException();
 203.176 -    }
 203.177 -
 203.178 -
 203.179 -    /**
 203.180 -     * Returns an array of {@code Class} objects that represent the formal
 203.181 -     * parameter types, in declaration order, of the method
 203.182 -     * represented by this {@code Method} object.  Returns an array of length
 203.183 -     * 0 if the underlying method takes no parameters.
 203.184 -     *
 203.185 -     * @return the parameter types for the method this object
 203.186 -     * represents
 203.187 -     */
 203.188 -    public Class<?>[] getParameterTypes() {
 203.189 -        Class[] arr = new Class[MethodImpl.signatureElements(sig) - 1];
 203.190 -        Enumeration<Class> en = MethodImpl.signatureParser(sig);
 203.191 -        en.nextElement(); // return type
 203.192 -        for (int i = 0; i < arr.length; i++) {
 203.193 -            arr[i] = en.nextElement();
 203.194 -        }
 203.195 -        return arr;
 203.196 -    }
 203.197 -
 203.198 -    /**
 203.199 -     * Returns an array of {@code Type} objects that represent the formal
 203.200 -     * parameter types, in declaration order, of the method represented by
 203.201 -     * this {@code Method} object. Returns an array of length 0 if the
 203.202 -     * underlying method takes no parameters.
 203.203 -     *
 203.204 -     * <p>If a formal parameter type is a parameterized type,
 203.205 -     * the {@code Type} object returned for it must accurately reflect
 203.206 -     * the actual type parameters used in the source code.
 203.207 -     *
 203.208 -     * <p>If a formal parameter type is a type variable or a parameterized
 203.209 -     * type, it is created. Otherwise, it is resolved.
 203.210 -     *
 203.211 -     * @return an array of Types that represent the formal
 203.212 -     *     parameter types of the underlying method, in declaration order
 203.213 -     * @throws GenericSignatureFormatError
 203.214 -     *     if the generic method signature does not conform to the format
 203.215 -     *     specified in
 203.216 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 203.217 -     * @throws TypeNotPresentException if any of the parameter
 203.218 -     *     types of the underlying method refers to a non-existent type
 203.219 -     *     declaration
 203.220 -     * @throws MalformedParameterizedTypeException if any of
 203.221 -     *     the underlying method's parameter types refer to a parameterized
 203.222 -     *     type that cannot be instantiated for any reason
 203.223 -     * @since 1.5
 203.224 -     */
 203.225 -    public Type[] getGenericParameterTypes() {
 203.226 -        throw new UnsupportedOperationException();
 203.227 -    }
 203.228 -
 203.229 -
 203.230 -    /**
 203.231 -     * Returns an array of {@code Class} objects that represent
 203.232 -     * the types of the exceptions declared to be thrown
 203.233 -     * by the underlying method
 203.234 -     * represented by this {@code Method} object.  Returns an array of length
 203.235 -     * 0 if the method declares no exceptions in its {@code throws} clause.
 203.236 -     *
 203.237 -     * @return the exception types declared as being thrown by the
 203.238 -     * method this object represents
 203.239 -     */
 203.240 -    public Class<?>[] getExceptionTypes() {
 203.241 -        throw new UnsupportedOperationException();
 203.242 -        //return (Class<?>[]) exceptionTypes.clone();
 203.243 -    }
 203.244 -
 203.245 -    /**
 203.246 -     * Returns an array of {@code Type} objects that represent the
 203.247 -     * exceptions declared to be thrown by this {@code Method} object.
 203.248 -     * Returns an array of length 0 if the underlying method declares
 203.249 -     * no exceptions in its {@code throws} clause.
 203.250 -     *
 203.251 -     * <p>If an exception type is a type variable or a parameterized
 203.252 -     * type, it is created. Otherwise, it is resolved.
 203.253 -     *
 203.254 -     * @return an array of Types that represent the exception types
 203.255 -     *     thrown by the underlying method
 203.256 -     * @throws GenericSignatureFormatError
 203.257 -     *     if the generic method signature does not conform to the format
 203.258 -     *     specified in
 203.259 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 203.260 -     * @throws TypeNotPresentException if the underlying method's
 203.261 -     *     {@code throws} clause refers to a non-existent type declaration
 203.262 -     * @throws MalformedParameterizedTypeException if
 203.263 -     *     the underlying method's {@code throws} clause refers to a
 203.264 -     *     parameterized type that cannot be instantiated for any reason
 203.265 -     * @since 1.5
 203.266 -     */
 203.267 -      public Type[] getGenericExceptionTypes() {
 203.268 -        throw new UnsupportedOperationException();
 203.269 -      }
 203.270 -
 203.271 -    /**
 203.272 -     * Compares this {@code Method} against the specified object.  Returns
 203.273 -     * true if the objects are the same.  Two {@code Methods} are the same if
 203.274 -     * they were declared by the same class and have the same name
 203.275 -     * and formal parameter types and return type.
 203.276 -     */
 203.277 -    public boolean equals(Object obj) {
 203.278 -        if (obj != null && obj instanceof Method) {
 203.279 -            Method other = (Method)obj;
 203.280 -            return data == other.data;
 203.281 -        }
 203.282 -        return false;
 203.283 -    }
 203.284 -
 203.285 -    /**
 203.286 -     * Returns a hashcode for this {@code Method}.  The hashcode is computed
 203.287 -     * as the exclusive-or of the hashcodes for the underlying
 203.288 -     * method's declaring class name and the method's name.
 203.289 -     */
 203.290 -    public int hashCode() {
 203.291 -        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 203.292 -    }
 203.293 -
 203.294 -    /**
 203.295 -     * Returns a string describing this {@code Method}.  The string is
 203.296 -     * formatted as the method access modifiers, if any, followed by
 203.297 -     * the method return type, followed by a space, followed by the
 203.298 -     * class declaring the method, followed by a period, followed by
 203.299 -     * the method name, followed by a parenthesized, comma-separated
 203.300 -     * list of the method's formal parameter types. If the method
 203.301 -     * throws checked exceptions, the parameter list is followed by a
 203.302 -     * space, followed by the word throws followed by a
 203.303 -     * comma-separated list of the thrown exception types.
 203.304 -     * For example:
 203.305 -     * <pre>
 203.306 -     *    public boolean java.lang.Object.equals(java.lang.Object)
 203.307 -     * </pre>
 203.308 -     *
 203.309 -     * <p>The access modifiers are placed in canonical order as
 203.310 -     * specified by "The Java Language Specification".  This is
 203.311 -     * {@code public}, {@code protected} or {@code private} first,
 203.312 -     * and then other modifiers in the following order:
 203.313 -     * {@code abstract}, {@code static}, {@code final},
 203.314 -     * {@code synchronized}, {@code native}, {@code strictfp}.
 203.315 -     */
 203.316 -    public String toString() {
 203.317 -        try {
 203.318 -            StringBuilder sb = new StringBuilder();
 203.319 -            int mod = getModifiers() & Modifier.methodModifiers();
 203.320 -            if (mod != 0) {
 203.321 -                sb.append(Modifier.toString(mod)).append(' ');
 203.322 -            }
 203.323 -            sb.append(Field.getTypeName(getReturnType())).append(' ');
 203.324 -            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 203.325 -            sb.append(getName()).append('(');
 203.326 -            Class<?>[] params = getParameterTypes(); // avoid clone
 203.327 -            for (int j = 0; j < params.length; j++) {
 203.328 -                sb.append(Field.getTypeName(params[j]));
 203.329 -                if (j < (params.length - 1))
 203.330 -                    sb.append(',');
 203.331 -            }
 203.332 -            sb.append(')');
 203.333 -            /*
 203.334 -            Class<?>[] exceptions = exceptionTypes; // avoid clone
 203.335 -            if (exceptions.length > 0) {
 203.336 -                sb.append(" throws ");
 203.337 -                for (int k = 0; k < exceptions.length; k++) {
 203.338 -                    sb.append(exceptions[k].getName());
 203.339 -                    if (k < (exceptions.length - 1))
 203.340 -                        sb.append(',');
 203.341 -                }
 203.342 -            }
 203.343 -            */
 203.344 -            return sb.toString();
 203.345 -        } catch (Exception e) {
 203.346 -            return "<" + e + ">";
 203.347 -        }
 203.348 -    }
 203.349 -
 203.350 -    /**
 203.351 -     * Returns a string describing this {@code Method}, including
 203.352 -     * type parameters.  The string is formatted as the method access
 203.353 -     * modifiers, if any, followed by an angle-bracketed
 203.354 -     * comma-separated list of the method's type parameters, if any,
 203.355 -     * followed by the method's generic return type, followed by a
 203.356 -     * space, followed by the class declaring the method, followed by
 203.357 -     * a period, followed by the method name, followed by a
 203.358 -     * parenthesized, comma-separated list of the method's generic
 203.359 -     * formal parameter types.
 203.360 -     *
 203.361 -     * If this method was declared to take a variable number of
 203.362 -     * arguments, instead of denoting the last parameter as
 203.363 -     * "<tt><i>Type</i>[]</tt>", it is denoted as
 203.364 -     * "<tt><i>Type</i>...</tt>".
 203.365 -     *
 203.366 -     * A space is used to separate access modifiers from one another
 203.367 -     * and from the type parameters or return type.  If there are no
 203.368 -     * type parameters, the type parameter list is elided; if the type
 203.369 -     * parameter list is present, a space separates the list from the
 203.370 -     * class name.  If the method is declared to throw exceptions, the
 203.371 -     * parameter list is followed by a space, followed by the word
 203.372 -     * throws followed by a comma-separated list of the generic thrown
 203.373 -     * exception types.  If there are no type parameters, the type
 203.374 -     * parameter list is elided.
 203.375 -     *
 203.376 -     * <p>The access modifiers are placed in canonical order as
 203.377 -     * specified by "The Java Language Specification".  This is
 203.378 -     * {@code public}, {@code protected} or {@code private} first,
 203.379 -     * and then other modifiers in the following order:
 203.380 -     * {@code abstract}, {@code static}, {@code final},
 203.381 -     * {@code synchronized}, {@code native}, {@code strictfp}.
 203.382 -     *
 203.383 -     * @return a string describing this {@code Method},
 203.384 -     * include type parameters
 203.385 -     *
 203.386 -     * @since 1.5
 203.387 -     */
 203.388 -    public String toGenericString() {
 203.389 -        try {
 203.390 -            StringBuilder sb = new StringBuilder();
 203.391 -            int mod = getModifiers() & Modifier.methodModifiers();
 203.392 -            if (mod != 0) {
 203.393 -                sb.append(Modifier.toString(mod)).append(' ');
 203.394 -            }
 203.395 -            TypeVariable<?>[] typeparms = getTypeParameters();
 203.396 -            if (typeparms.length > 0) {
 203.397 -                boolean first = true;
 203.398 -                sb.append('<');
 203.399 -                for(TypeVariable<?> typeparm: typeparms) {
 203.400 -                    if (!first)
 203.401 -                        sb.append(',');
 203.402 -                    // Class objects can't occur here; no need to test
 203.403 -                    // and call Class.getName().
 203.404 -                    sb.append(typeparm.toString());
 203.405 -                    first = false;
 203.406 -                }
 203.407 -                sb.append("> ");
 203.408 -            }
 203.409 -
 203.410 -            Type genRetType = getGenericReturnType();
 203.411 -            sb.append( ((genRetType instanceof Class<?>)?
 203.412 -                        Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
 203.413 -                    .append(' ');
 203.414 -
 203.415 -            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 203.416 -            sb.append(getName()).append('(');
 203.417 -            Type[] params = getGenericParameterTypes();
 203.418 -            for (int j = 0; j < params.length; j++) {
 203.419 -                String param = (params[j] instanceof Class)?
 203.420 -                    Field.getTypeName((Class)params[j]):
 203.421 -                    (params[j].toString());
 203.422 -                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 203.423 -                    param = param.replaceFirst("\\[\\]$", "...");
 203.424 -                sb.append(param);
 203.425 -                if (j < (params.length - 1))
 203.426 -                    sb.append(',');
 203.427 -            }
 203.428 -            sb.append(')');
 203.429 -            Type[] exceptions = getGenericExceptionTypes();
 203.430 -            if (exceptions.length > 0) {
 203.431 -                sb.append(" throws ");
 203.432 -                for (int k = 0; k < exceptions.length; k++) {
 203.433 -                    sb.append((exceptions[k] instanceof Class)?
 203.434 -                              ((Class)exceptions[k]).getName():
 203.435 -                              exceptions[k].toString());
 203.436 -                    if (k < (exceptions.length - 1))
 203.437 -                        sb.append(',');
 203.438 -                }
 203.439 -            }
 203.440 -            return sb.toString();
 203.441 -        } catch (Exception e) {
 203.442 -            return "<" + e + ">";
 203.443 -        }
 203.444 -    }
 203.445 -
 203.446 -    /**
 203.447 -     * Invokes the underlying method represented by this {@code Method}
 203.448 -     * object, on the specified object with the specified parameters.
 203.449 -     * Individual parameters are automatically unwrapped to match
 203.450 -     * primitive formal parameters, and both primitive and reference
 203.451 -     * parameters are subject to method invocation conversions as
 203.452 -     * necessary.
 203.453 -     *
 203.454 -     * <p>If the underlying method is static, then the specified {@code obj}
 203.455 -     * argument is ignored. It may be null.
 203.456 -     *
 203.457 -     * <p>If the number of formal parameters required by the underlying method is
 203.458 -     * 0, the supplied {@code args} array may be of length 0 or null.
 203.459 -     *
 203.460 -     * <p>If the underlying method is an instance method, it is invoked
 203.461 -     * using dynamic method lookup as documented in The Java Language
 203.462 -     * Specification, Second Edition, section 15.12.4.4; in particular,
 203.463 -     * overriding based on the runtime type of the target object will occur.
 203.464 -     *
 203.465 -     * <p>If the underlying method is static, the class that declared
 203.466 -     * the method is initialized if it has not already been initialized.
 203.467 -     *
 203.468 -     * <p>If the method completes normally, the value it returns is
 203.469 -     * returned to the caller of invoke; if the value has a primitive
 203.470 -     * type, it is first appropriately wrapped in an object. However,
 203.471 -     * if the value has the type of an array of a primitive type, the
 203.472 -     * elements of the array are <i>not</i> wrapped in objects; in
 203.473 -     * other words, an array of primitive type is returned.  If the
 203.474 -     * underlying method return type is void, the invocation returns
 203.475 -     * null.
 203.476 -     *
 203.477 -     * @param obj  the object the underlying method is invoked from
 203.478 -     * @param args the arguments used for the method call
 203.479 -     * @return the result of dispatching the method represented by
 203.480 -     * this object on {@code obj} with parameters
 203.481 -     * {@code args}
 203.482 -     *
 203.483 -     * @exception IllegalAccessException    if this {@code Method} object
 203.484 -     *              is enforcing Java language access control and the underlying
 203.485 -     *              method is inaccessible.
 203.486 -     * @exception IllegalArgumentException  if the method is an
 203.487 -     *              instance method and the specified object argument
 203.488 -     *              is not an instance of the class or interface
 203.489 -     *              declaring the underlying method (or of a subclass
 203.490 -     *              or implementor thereof); if the number of actual
 203.491 -     *              and formal parameters differ; if an unwrapping
 203.492 -     *              conversion for primitive arguments fails; or if,
 203.493 -     *              after possible unwrapping, a parameter value
 203.494 -     *              cannot be converted to the corresponding formal
 203.495 -     *              parameter type by a method invocation conversion.
 203.496 -     * @exception InvocationTargetException if the underlying method
 203.497 -     *              throws an exception.
 203.498 -     * @exception NullPointerException      if the specified object is null
 203.499 -     *              and the method is an instance method.
 203.500 -     * @exception ExceptionInInitializerError if the initialization
 203.501 -     * provoked by this method fails.
 203.502 -     */
 203.503 -    public Object invoke(Object obj, Object... args)
 203.504 -        throws IllegalAccessException, IllegalArgumentException,
 203.505 -           InvocationTargetException
 203.506 -    {
 203.507 -        final boolean isStatic = (getModifiers() & Modifier.STATIC) == 0;
 203.508 -        if (isStatic && obj == null) {
 203.509 -            throw new NullPointerException();
 203.510 -        }
 203.511 -        Class[] types = getParameterTypes();
 203.512 -        if (types.length != args.length) {
 203.513 -            throw new IllegalArgumentException("Types len " + types.length + " args: " + args.length);
 203.514 -        } else {
 203.515 -            args = args.clone();
 203.516 -            for (int i = 0; i < types.length; i++) {
 203.517 -                Class c = types[i];
 203.518 -                if (c.isPrimitive()) {
 203.519 -                    args[i] = toPrimitive(c, args[i]);
 203.520 -                }
 203.521 -            }
 203.522 -        }
 203.523 -        Object res = invoke0(isStatic, this, obj, args);
 203.524 -        if (getReturnType().isPrimitive()) {
 203.525 -            res = fromPrimitive(getReturnType(), res);
 203.526 -        }
 203.527 -        return res;
 203.528 -    }
 203.529 -    
 203.530 -    @JavaScriptBody(args = { "st", "method", "self", "args" }, body =
 203.531 -          "var p;\n"
 203.532 -        + "if (st) {\n"
 203.533 -        + "  p = new Array(1);\n"
 203.534 -        + "  p[0] = self;\n"
 203.535 -        + "  p = p.concat(args);\n"
 203.536 -        + "} else {\n"
 203.537 -        + "  p = args;\n"
 203.538 -        + "}\n"
 203.539 -        + "return method._data().apply(self, p);\n"
 203.540 -    )
 203.541 -    private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
 203.542 -
 203.543 -    static Object fromPrimitive(Class<?> type, Object o) {
 203.544 -        if (type == Integer.TYPE) {
 203.545 -            return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
 203.546 -        }
 203.547 -        if (type == Long.TYPE) {
 203.548 -            return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
 203.549 -        }
 203.550 -        if (type == Double.TYPE) {
 203.551 -            return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
 203.552 -        }
 203.553 -        if (type == Float.TYPE) {
 203.554 -            return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
 203.555 -        }
 203.556 -        if (type == Byte.TYPE) {
 203.557 -            return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
 203.558 -        }
 203.559 -        if (type == Boolean.TYPE) {
 203.560 -            return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
 203.561 -        }
 203.562 -        if (type == Short.TYPE) {
 203.563 -            return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
 203.564 -        }
 203.565 -        if (type == Character.TYPE) {
 203.566 -            return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
 203.567 -        }
 203.568 -        if (type.getName().equals("void")) {
 203.569 -            return null;
 203.570 -        }
 203.571 -        throw new IllegalStateException("Can't convert " + o);
 203.572 -    }
 203.573 -    
 203.574 -    @JavaScriptBody(args = { "cls", "m", "o" }, 
 203.575 -        body = "return cls.cnstr(false)[m](o);"
 203.576 -    )
 203.577 -    private static native Integer fromRaw(Class<?> cls, String m, Object o);
 203.578 -
 203.579 -    private static Object toPrimitive(Class<?> type, Object o) {
 203.580 -        if (type == Integer.TYPE) {
 203.581 -            return toRaw("intValue__I", o);
 203.582 -        }
 203.583 -        if (type == Long.TYPE) {
 203.584 -            return toRaw("longValue__J", o);
 203.585 -        }
 203.586 -        if (type == Double.TYPE) {
 203.587 -            return toRaw("doubleValue__D", o);
 203.588 -        }
 203.589 -        if (type == Float.TYPE) {
 203.590 -            return toRaw("floatValue__F", o);
 203.591 -        }
 203.592 -        if (type == Byte.TYPE) {
 203.593 -            return toRaw("byteValue__B", o);
 203.594 -        }
 203.595 -        if (type == Boolean.TYPE) {
 203.596 -            return toRaw("booleanValue__Z", o);
 203.597 -        }
 203.598 -        if (type == Short.TYPE) {
 203.599 -            return toRaw("shortValue__S", o);
 203.600 -        }
 203.601 -        if (type == Character.TYPE) {
 203.602 -            return toRaw("charValue__C", o);
 203.603 -        }
 203.604 -        if (type.getName().equals("void")) {
 203.605 -            return o;
 203.606 -        }
 203.607 -        throw new IllegalStateException("Can't convert " + o);
 203.608 -    }
 203.609 -    
 203.610 -    @JavaScriptBody(args = { "m", "o" }, 
 203.611 -        body = "return o[m](o);"
 203.612 -    )
 203.613 -    private static native Object toRaw(String m, Object o);
 203.614 -    
 203.615 -    /**
 203.616 -     * Returns {@code true} if this method is a bridge
 203.617 -     * method; returns {@code false} otherwise.
 203.618 -     *
 203.619 -     * @return true if and only if this method is a bridge
 203.620 -     * method as defined by the Java Language Specification.
 203.621 -     * @since 1.5
 203.622 -     */
 203.623 -    public boolean isBridge() {
 203.624 -        return (getModifiers() & Modifier.BRIDGE) != 0;
 203.625 -    }
 203.626 -
 203.627 -    /**
 203.628 -     * Returns {@code true} if this method was declared to take
 203.629 -     * a variable number of arguments; returns {@code false}
 203.630 -     * otherwise.
 203.631 -     *
 203.632 -     * @return {@code true} if an only if this method was declared to
 203.633 -     * take a variable number of arguments.
 203.634 -     * @since 1.5
 203.635 -     */
 203.636 -    public boolean isVarArgs() {
 203.637 -        return (getModifiers() & Modifier.VARARGS) != 0;
 203.638 -    }
 203.639 -
 203.640 -    /**
 203.641 -     * Returns {@code true} if this method is a synthetic
 203.642 -     * method; returns {@code false} otherwise.
 203.643 -     *
 203.644 -     * @return true if and only if this method is a synthetic
 203.645 -     * method as defined by the Java Language Specification.
 203.646 -     * @since 1.5
 203.647 -     */
 203.648 -    public boolean isSynthetic() {
 203.649 -        return Modifier.isSynthetic(getModifiers());
 203.650 -    }
 203.651 -
 203.652 -    @JavaScriptBody(args = { "ac" }, 
 203.653 -        body = 
 203.654 -          "var a = this._data().anno;"
 203.655 -        + "if (a) {"
 203.656 -        + "  return a['L' + ac.jvmName + ';'];"
 203.657 -        + "} else return null;"
 203.658 -    )
 203.659 -    private Object getAnnotationData(Class<?> annotationClass) {
 203.660 -        throw new UnsupportedOperationException();
 203.661 -    }
 203.662 -    
 203.663 -    /**
 203.664 -     * @throws NullPointerException {@inheritDoc}
 203.665 -     * @since 1.5
 203.666 -     */
 203.667 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 203.668 -        Object data = getAnnotationData(annotationClass);
 203.669 -        return data == null ? null : AnnotationImpl.create(annotationClass, data);
 203.670 -    }
 203.671 -
 203.672 -    /**
 203.673 -     * @since 1.5
 203.674 -     */
 203.675 -    public Annotation[] getDeclaredAnnotations()  {
 203.676 -        throw new UnsupportedOperationException();
 203.677 -    }
 203.678 -
 203.679 -    /**
 203.680 -     * Returns the default value for the annotation member represented by
 203.681 -     * this {@code Method} instance.  If the member is of a primitive type,
 203.682 -     * an instance of the corresponding wrapper type is returned. Returns
 203.683 -     * null if no default is associated with the member, or if the method
 203.684 -     * instance does not represent a declared member of an annotation type.
 203.685 -     *
 203.686 -     * @return the default value for the annotation member represented
 203.687 -     *     by this {@code Method} instance.
 203.688 -     * @throws TypeNotPresentException if the annotation is of type
 203.689 -     *     {@link Class} and no definition can be found for the
 203.690 -     *     default class value.
 203.691 -     * @since  1.5
 203.692 -     */
 203.693 -    public Object getDefaultValue() {
 203.694 -        throw new UnsupportedOperationException();
 203.695 -    }
 203.696 -
 203.697 -    /**
 203.698 -     * Returns an array of arrays that represent the annotations on the formal
 203.699 -     * parameters, in declaration order, of the method represented by
 203.700 -     * this {@code Method} object. (Returns an array of length zero if the
 203.701 -     * underlying method is parameterless.  If the method has one or more
 203.702 -     * parameters, a nested array of length zero is returned for each parameter
 203.703 -     * with no annotations.) The annotation objects contained in the returned
 203.704 -     * arrays are serializable.  The caller of this method is free to modify
 203.705 -     * the returned arrays; it will have no effect on the arrays returned to
 203.706 -     * other callers.
 203.707 -     *
 203.708 -     * @return an array of arrays that represent the annotations on the formal
 203.709 -     *    parameters, in declaration order, of the method represented by this
 203.710 -     *    Method object
 203.711 -     * @since 1.5
 203.712 -     */
 203.713 -    public Annotation[][] getParameterAnnotations() {
 203.714 -        throw new UnsupportedOperationException();
 203.715 -    }
 203.716 -
 203.717 -    static {
 203.718 -        MethodImpl.INSTANCE = new MethodImpl() {
 203.719 -            protected Method create(Class<?> declaringClass, String name, Object data, String sig) {
 203.720 -                return new Method(declaringClass, name, data, sig);
 203.721 -            }
 203.722 -        };
 203.723 -    }
 203.724 -}
   204.1 --- a/emul/mini/src/main/java/java/lang/reflect/Modifier.java	Mon Feb 25 19:00:08 2013 +0100
   204.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   204.3 @@ -1,437 +0,0 @@
   204.4 -/*
   204.5 - * Copyright (c) 1996, 2008, 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.reflect;
  204.30 -
  204.31 -/**
  204.32 - * The Modifier class provides {@code static} methods and
  204.33 - * constants to decode class and member access modifiers.  The sets of
  204.34 - * modifiers are represented as integers with distinct bit positions
  204.35 - * representing different modifiers.  The values for the constants
  204.36 - * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  204.37 - * <cite>The Java&trade; Virtual Machine Specification</cite>.
  204.38 - *
  204.39 - * @see Class#getModifiers()
  204.40 - * @see Member#getModifiers()
  204.41 - *
  204.42 - * @author Nakul Saraiya
  204.43 - * @author Kenneth Russell
  204.44 - */
  204.45 -public
  204.46 -class Modifier {
  204.47 -
  204.48 -    /**
  204.49 -     * Return {@code true} if the integer argument includes the
  204.50 -     * {@code public} modifier, {@code false} otherwise.
  204.51 -     *
  204.52 -     * @param   mod a set of modifiers
  204.53 -     * @return {@code true} if {@code mod} includes the
  204.54 -     * {@code public} modifier; {@code false} otherwise.
  204.55 -     */
  204.56 -    public static boolean isPublic(int mod) {
  204.57 -        return (mod & PUBLIC) != 0;
  204.58 -    }
  204.59 -
  204.60 -    /**
  204.61 -     * Return {@code true} if the integer argument includes the
  204.62 -     * {@code private} modifier, {@code false} otherwise.
  204.63 -     *
  204.64 -     * @param   mod a set of modifiers
  204.65 -     * @return {@code true} if {@code mod} includes the
  204.66 -     * {@code private} modifier; {@code false} otherwise.
  204.67 -     */
  204.68 -    public static boolean isPrivate(int mod) {
  204.69 -        return (mod & PRIVATE) != 0;
  204.70 -    }
  204.71 -
  204.72 -    /**
  204.73 -     * Return {@code true} if the integer argument includes the
  204.74 -     * {@code protected} modifier, {@code false} otherwise.
  204.75 -     *
  204.76 -     * @param   mod a set of modifiers
  204.77 -     * @return {@code true} if {@code mod} includes the
  204.78 -     * {@code protected} modifier; {@code false} otherwise.
  204.79 -     */
  204.80 -    public static boolean isProtected(int mod) {
  204.81 -        return (mod & PROTECTED) != 0;
  204.82 -    }
  204.83 -
  204.84 -    /**
  204.85 -     * Return {@code true} if the integer argument includes the
  204.86 -     * {@code static} modifier, {@code false} otherwise.
  204.87 -     *
  204.88 -     * @param   mod a set of modifiers
  204.89 -     * @return {@code true} if {@code mod} includes the
  204.90 -     * {@code static} modifier; {@code false} otherwise.
  204.91 -     */
  204.92 -    public static boolean isStatic(int mod) {
  204.93 -        return (mod & STATIC) != 0;
  204.94 -    }
  204.95 -
  204.96 -    /**
  204.97 -     * Return {@code true} if the integer argument includes the
  204.98 -     * {@code final} modifier, {@code false} otherwise.
  204.99 -     *
 204.100 -     * @param   mod a set of modifiers
 204.101 -     * @return {@code true} if {@code mod} includes the
 204.102 -     * {@code final} modifier; {@code false} otherwise.
 204.103 -     */
 204.104 -    public static boolean isFinal(int mod) {
 204.105 -        return (mod & FINAL) != 0;
 204.106 -    }
 204.107 -
 204.108 -    /**
 204.109 -     * Return {@code true} if the integer argument includes the
 204.110 -     * {@code synchronized} modifier, {@code false} otherwise.
 204.111 -     *
 204.112 -     * @param   mod a set of modifiers
 204.113 -     * @return {@code true} if {@code mod} includes the
 204.114 -     * {@code synchronized} modifier; {@code false} otherwise.
 204.115 -     */
 204.116 -    public static boolean isSynchronized(int mod) {
 204.117 -        return (mod & SYNCHRONIZED) != 0;
 204.118 -    }
 204.119 -
 204.120 -    /**
 204.121 -     * Return {@code true} if the integer argument includes the
 204.122 -     * {@code volatile} modifier, {@code false} otherwise.
 204.123 -     *
 204.124 -     * @param   mod a set of modifiers
 204.125 -     * @return {@code true} if {@code mod} includes the
 204.126 -     * {@code volatile} modifier; {@code false} otherwise.
 204.127 -     */
 204.128 -    public static boolean isVolatile(int mod) {
 204.129 -        return (mod & VOLATILE) != 0;
 204.130 -    }
 204.131 -
 204.132 -    /**
 204.133 -     * Return {@code true} if the integer argument includes the
 204.134 -     * {@code transient} modifier, {@code false} otherwise.
 204.135 -     *
 204.136 -     * @param   mod a set of modifiers
 204.137 -     * @return {@code true} if {@code mod} includes the
 204.138 -     * {@code transient} modifier; {@code false} otherwise.
 204.139 -     */
 204.140 -    public static boolean isTransient(int mod) {
 204.141 -        return (mod & TRANSIENT) != 0;
 204.142 -    }
 204.143 -
 204.144 -    /**
 204.145 -     * Return {@code true} if the integer argument includes the
 204.146 -     * {@code native} modifier, {@code false} otherwise.
 204.147 -     *
 204.148 -     * @param   mod a set of modifiers
 204.149 -     * @return {@code true} if {@code mod} includes the
 204.150 -     * {@code native} modifier; {@code false} otherwise.
 204.151 -     */
 204.152 -    public static boolean isNative(int mod) {
 204.153 -        return (mod & NATIVE) != 0;
 204.154 -    }
 204.155 -
 204.156 -    /**
 204.157 -     * Return {@code true} if the integer argument includes the
 204.158 -     * {@code interface} modifier, {@code false} otherwise.
 204.159 -     *
 204.160 -     * @param   mod a set of modifiers
 204.161 -     * @return {@code true} if {@code mod} includes the
 204.162 -     * {@code interface} modifier; {@code false} otherwise.
 204.163 -     */
 204.164 -    public static boolean isInterface(int mod) {
 204.165 -        return (mod & INTERFACE) != 0;
 204.166 -    }
 204.167 -
 204.168 -    /**
 204.169 -     * Return {@code true} if the integer argument includes the
 204.170 -     * {@code abstract} modifier, {@code false} otherwise.
 204.171 -     *
 204.172 -     * @param   mod a set of modifiers
 204.173 -     * @return {@code true} if {@code mod} includes the
 204.174 -     * {@code abstract} modifier; {@code false} otherwise.
 204.175 -     */
 204.176 -    public static boolean isAbstract(int mod) {
 204.177 -        return (mod & ABSTRACT) != 0;
 204.178 -    }
 204.179 -
 204.180 -    /**
 204.181 -     * Return {@code true} if the integer argument includes the
 204.182 -     * {@code strictfp} modifier, {@code false} otherwise.
 204.183 -     *
 204.184 -     * @param   mod a set of modifiers
 204.185 -     * @return {@code true} if {@code mod} includes the
 204.186 -     * {@code strictfp} modifier; {@code false} otherwise.
 204.187 -     */
 204.188 -    public static boolean isStrict(int mod) {
 204.189 -        return (mod & STRICT) != 0;
 204.190 -    }
 204.191 -
 204.192 -    /**
 204.193 -     * Return a string describing the access modifier flags in
 204.194 -     * the specified modifier. For example:
 204.195 -     * <blockquote><pre>
 204.196 -     *    public final synchronized strictfp
 204.197 -     * </pre></blockquote>
 204.198 -     * The modifier names are returned in an order consistent with the
 204.199 -     * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
 204.200 -     * <cite>The Java&trade; Language Specification</cite>.
 204.201 -     * The full modifier ordering used by this method is:
 204.202 -     * <blockquote> {@code
 204.203 -     * public protected private abstract static final transient
 204.204 -     * volatile synchronized native strictfp
 204.205 -     * interface } </blockquote>
 204.206 -     * The {@code interface} modifier discussed in this class is
 204.207 -     * not a true modifier in the Java language and it appears after
 204.208 -     * all other modifiers listed by this method.  This method may
 204.209 -     * return a string of modifiers that are not valid modifiers of a
 204.210 -     * Java entity; in other words, no checking is done on the
 204.211 -     * possible validity of the combination of modifiers represented
 204.212 -     * by the input.
 204.213 -     *
 204.214 -     * Note that to perform such checking for a known kind of entity,
 204.215 -     * such as a constructor or method, first AND the argument of
 204.216 -     * {@code toString} with the appropriate mask from a method like
 204.217 -     * {@link #constructorModifiers} or {@link #methodModifiers}.
 204.218 -     *
 204.219 -     * @param   mod a set of modifiers
 204.220 -     * @return  a string representation of the set of modifiers
 204.221 -     * represented by {@code mod}
 204.222 -     */
 204.223 -    public static String toString(int mod) {
 204.224 -        StringBuffer sb = new StringBuffer();
 204.225 -        int len;
 204.226 -
 204.227 -        if ((mod & PUBLIC) != 0)        sb.append("public ");
 204.228 -        if ((mod & PROTECTED) != 0)     sb.append("protected ");
 204.229 -        if ((mod & PRIVATE) != 0)       sb.append("private ");
 204.230 -
 204.231 -        /* Canonical order */
 204.232 -        if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
 204.233 -        if ((mod & STATIC) != 0)        sb.append("static ");
 204.234 -        if ((mod & FINAL) != 0)         sb.append("final ");
 204.235 -        if ((mod & TRANSIENT) != 0)     sb.append("transient ");
 204.236 -        if ((mod & VOLATILE) != 0)      sb.append("volatile ");
 204.237 -        if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
 204.238 -        if ((mod & NATIVE) != 0)        sb.append("native ");
 204.239 -        if ((mod & STRICT) != 0)        sb.append("strictfp ");
 204.240 -        if ((mod & INTERFACE) != 0)     sb.append("interface ");
 204.241 -
 204.242 -        if ((len = sb.length()) > 0)    /* trim trailing space */
 204.243 -            return sb.toString().substring(0, len-1);
 204.244 -        return "";
 204.245 -    }
 204.246 -
 204.247 -    /*
 204.248 -     * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
 204.249 -     * <cite>The Java&trade; Virtual Machine Specification</cite>
 204.250 -     */
 204.251 -
 204.252 -    /**
 204.253 -     * The {@code int} value representing the {@code public}
 204.254 -     * modifier.
 204.255 -     */
 204.256 -    public static final int PUBLIC           = 0x00000001;
 204.257 -
 204.258 -    /**
 204.259 -     * The {@code int} value representing the {@code private}
 204.260 -     * modifier.
 204.261 -     */
 204.262 -    public static final int PRIVATE          = 0x00000002;
 204.263 -
 204.264 -    /**
 204.265 -     * The {@code int} value representing the {@code protected}
 204.266 -     * modifier.
 204.267 -     */
 204.268 -    public static final int PROTECTED        = 0x00000004;
 204.269 -
 204.270 -    /**
 204.271 -     * The {@code int} value representing the {@code static}
 204.272 -     * modifier.
 204.273 -     */
 204.274 -    public static final int STATIC           = 0x00000008;
 204.275 -
 204.276 -    /**
 204.277 -     * The {@code int} value representing the {@code final}
 204.278 -     * modifier.
 204.279 -     */
 204.280 -    public static final int FINAL            = 0x00000010;
 204.281 -
 204.282 -    /**
 204.283 -     * The {@code int} value representing the {@code synchronized}
 204.284 -     * modifier.
 204.285 -     */
 204.286 -    public static final int SYNCHRONIZED     = 0x00000020;
 204.287 -
 204.288 -    /**
 204.289 -     * The {@code int} value representing the {@code volatile}
 204.290 -     * modifier.
 204.291 -     */
 204.292 -    public static final int VOLATILE         = 0x00000040;
 204.293 -
 204.294 -    /**
 204.295 -     * The {@code int} value representing the {@code transient}
 204.296 -     * modifier.
 204.297 -     */
 204.298 -    public static final int TRANSIENT        = 0x00000080;
 204.299 -
 204.300 -    /**
 204.301 -     * The {@code int} value representing the {@code native}
 204.302 -     * modifier.
 204.303 -     */
 204.304 -    public static final int NATIVE           = 0x00000100;
 204.305 -
 204.306 -    /**
 204.307 -     * The {@code int} value representing the {@code interface}
 204.308 -     * modifier.
 204.309 -     */
 204.310 -    public static final int INTERFACE        = 0x00000200;
 204.311 -
 204.312 -    /**
 204.313 -     * The {@code int} value representing the {@code abstract}
 204.314 -     * modifier.
 204.315 -     */
 204.316 -    public static final int ABSTRACT         = 0x00000400;
 204.317 -
 204.318 -    /**
 204.319 -     * The {@code int} value representing the {@code strictfp}
 204.320 -     * modifier.
 204.321 -     */
 204.322 -    public static final int STRICT           = 0x00000800;
 204.323 -
 204.324 -    // Bits not (yet) exposed in the public API either because they
 204.325 -    // have different meanings for fields and methods and there is no
 204.326 -    // way to distinguish between the two in this class, or because
 204.327 -    // they are not Java programming language keywords
 204.328 -    static final int BRIDGE    = 0x00000040;
 204.329 -    static final int VARARGS   = 0x00000080;
 204.330 -    static final int SYNTHETIC = 0x00001000;
 204.331 -    static final int ANNOTATION= 0x00002000;
 204.332 -    static final int ENUM      = 0x00004000;
 204.333 -    static boolean isSynthetic(int mod) {
 204.334 -      return (mod & SYNTHETIC) != 0;
 204.335 -    }
 204.336 -
 204.337 -    /**
 204.338 -     * See JLSv3 section 8.1.1.
 204.339 -     */
 204.340 -    private static final int CLASS_MODIFIERS =
 204.341 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 204.342 -        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 204.343 -        Modifier.STRICT;
 204.344 -
 204.345 -    /**
 204.346 -     * See JLSv3 section 9.1.1.
 204.347 -     */
 204.348 -    private static final int INTERFACE_MODIFIERS =
 204.349 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 204.350 -        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.STRICT;
 204.351 -
 204.352 -
 204.353 -    /**
 204.354 -     * See JLSv3 section 8.8.3.
 204.355 -     */
 204.356 -    private static final int CONSTRUCTOR_MODIFIERS =
 204.357 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE;
 204.358 -
 204.359 -    /**
 204.360 -     * See JLSv3 section 8.4.3.
 204.361 -     */
 204.362 -    private static final int METHOD_MODIFIERS =
 204.363 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 204.364 -        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 204.365 -        Modifier.SYNCHRONIZED   | Modifier.NATIVE       | Modifier.STRICT;
 204.366 -
 204.367 -    /**
 204.368 -     * See JLSv3 section 8.3.1.
 204.369 -     */
 204.370 -    private static final int FIELD_MODIFIERS =
 204.371 -        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 204.372 -        Modifier.STATIC         | Modifier.FINAL        | Modifier.TRANSIENT |
 204.373 -        Modifier.VOLATILE;
 204.374 -
 204.375 -    /**
 204.376 -     * Return an {@code int} value OR-ing together the source language
 204.377 -     * modifiers that can be applied to a class.
 204.378 -     * @return an {@code int} value OR-ing together the source language
 204.379 -     * modifiers that can be applied to a class.
 204.380 -     *
 204.381 -     * @jls 8.1.1 Class Modifiers
 204.382 -     * @since 1.7
 204.383 -     */
 204.384 -    public static int classModifiers() {
 204.385 -        return CLASS_MODIFIERS;
 204.386 -    }
 204.387 -
 204.388 -    /**
 204.389 -     * Return an {@code int} value OR-ing together the source language
 204.390 -     * modifiers that can be applied to an interface.
 204.391 -     * @return an {@code int} value OR-ing together the source language
 204.392 -     * modifiers that can be applied to an inteface.
 204.393 -     *
 204.394 -     * @jls 9.1.1 Interface Modifiers
 204.395 -     * @since 1.7
 204.396 -     */
 204.397 -    public static int interfaceModifiers() {
 204.398 -        return INTERFACE_MODIFIERS;
 204.399 -    }
 204.400 -
 204.401 -    /**
 204.402 -     * Return an {@code int} value OR-ing together the source language
 204.403 -     * modifiers that can be applied to a constructor.
 204.404 -     * @return an {@code int} value OR-ing together the source language
 204.405 -     * modifiers that can be applied to a constructor.
 204.406 -     *
 204.407 -     * @jls 8.8.3 Constructor Modifiers
 204.408 -     * @since 1.7
 204.409 -     */
 204.410 -    public static int constructorModifiers() {
 204.411 -        return CONSTRUCTOR_MODIFIERS;
 204.412 -    }
 204.413 -
 204.414 -    /**
 204.415 -     * Return an {@code int} value OR-ing together the source language
 204.416 -     * modifiers that can be applied to a method.
 204.417 -     * @return an {@code int} value OR-ing together the source language
 204.418 -     * modifiers that can be applied to a method.
 204.419 -     *
 204.420 -     * @jls 8.4.3 Method Modifiers
 204.421 -     * @since 1.7
 204.422 -     */
 204.423 -    public static int methodModifiers() {
 204.424 -        return METHOD_MODIFIERS;
 204.425 -    }
 204.426 -
 204.427 -
 204.428 -    /**
 204.429 -     * Return an {@code int} value OR-ing together the source language
 204.430 -     * modifiers that can be applied to a field.
 204.431 -     * @return an {@code int} value OR-ing together the source language
 204.432 -     * modifiers that can be applied to a field.
 204.433 -     *
 204.434 -     * @jls 8.3.1 Field Modifiers
 204.435 -     * @since 1.7
 204.436 -     */
 204.437 -    public static int fieldModifiers() {
 204.438 -        return FIELD_MODIFIERS;
 204.439 -    }
 204.440 -}
   205.1 --- a/emul/mini/src/main/java/java/lang/reflect/Proxy.java	Mon Feb 25 19:00:08 2013 +0100
   205.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   205.3 @@ -1,407 +0,0 @@
   205.4 -/*
   205.5 - * Copyright (c) 1999, 2010, 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.reflect;
  205.30 -
  205.31 -
  205.32 -/**
  205.33 - * {@code Proxy} provides static methods for creating dynamic proxy
  205.34 - * classes and instances, and it is also the superclass of all
  205.35 - * dynamic proxy classes created by those methods.
  205.36 - *
  205.37 - * <p>To create a proxy for some interface {@code Foo}:
  205.38 - * <pre>
  205.39 - *     InvocationHandler handler = new MyInvocationHandler(...);
  205.40 - *     Class proxyClass = Proxy.getProxyClass(
  205.41 - *         Foo.class.getClassLoader(), new Class[] { Foo.class });
  205.42 - *     Foo f = (Foo) proxyClass.
  205.43 - *         getConstructor(new Class[] { InvocationHandler.class }).
  205.44 - *         newInstance(new Object[] { handler });
  205.45 - * </pre>
  205.46 - * or more simply:
  205.47 - * <pre>
  205.48 - *     Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
  205.49 - *                                          new Class[] { Foo.class },
  205.50 - *                                          handler);
  205.51 - * </pre>
  205.52 - *
  205.53 - * <p>A <i>dynamic proxy class</i> (simply referred to as a <i>proxy
  205.54 - * class</i> below) is a class that implements a list of interfaces
  205.55 - * specified at runtime when the class is created, with behavior as
  205.56 - * described below.
  205.57 - *
  205.58 - * A <i>proxy interface</i> is such an interface that is implemented
  205.59 - * by a proxy class.
  205.60 - *
  205.61 - * A <i>proxy instance</i> is an instance of a proxy class.
  205.62 - *
  205.63 - * Each proxy instance has an associated <i>invocation handler</i>
  205.64 - * object, which implements the interface {@link InvocationHandler}.
  205.65 - * A method invocation on a proxy instance through one of its proxy
  205.66 - * interfaces will be dispatched to the {@link InvocationHandler#invoke
  205.67 - * invoke} method of the instance's invocation handler, passing the proxy
  205.68 - * instance, a {@code java.lang.reflect.Method} object identifying
  205.69 - * the method that was invoked, and an array of type {@code Object}
  205.70 - * containing the arguments.  The invocation handler processes the
  205.71 - * encoded method invocation as appropriate and the result that it
  205.72 - * returns will be returned as the result of the method invocation on
  205.73 - * the proxy instance.
  205.74 - *
  205.75 - * <p>A proxy class has the following properties:
  205.76 - *
  205.77 - * <ul>
  205.78 - * <li>Proxy classes are public, final, and not abstract.
  205.79 - *
  205.80 - * <li>The unqualified name of a proxy class is unspecified.  The space
  205.81 - * of class names that begin with the string {@code "$Proxy"}
  205.82 - * should be, however, reserved for proxy classes.
  205.83 - *
  205.84 - * <li>A proxy class extends {@code java.lang.reflect.Proxy}.
  205.85 - *
  205.86 - * <li>A proxy class implements exactly the interfaces specified at its
  205.87 - * creation, in the same order.
  205.88 - *
  205.89 - * <li>If a proxy class implements a non-public interface, then it will
  205.90 - * be defined in the same package as that interface.  Otherwise, the
  205.91 - * package of a proxy class is also unspecified.  Note that package
  205.92 - * sealing will not prevent a proxy class from being successfully defined
  205.93 - * in a particular package at runtime, and neither will classes already
  205.94 - * defined by the same class loader and the same package with particular
  205.95 - * signers.
  205.96 - *
  205.97 - * <li>Since a proxy class implements all of the interfaces specified at
  205.98 - * its creation, invoking {@code getInterfaces} on its
  205.99 - * {@code Class} object will return an array containing the same
 205.100 - * list of interfaces (in the order specified at its creation), invoking
 205.101 - * {@code getMethods} on its {@code Class} object will return
 205.102 - * an array of {@code Method} objects that include all of the
 205.103 - * methods in those interfaces, and invoking {@code getMethod} will
 205.104 - * find methods in the proxy interfaces as would be expected.
 205.105 - *
 205.106 - * <li>The {@link Proxy#isProxyClass Proxy.isProxyClass} method will
 205.107 - * return true if it is passed a proxy class-- a class returned by
 205.108 - * {@code Proxy.getProxyClass} or the class of an object returned by
 205.109 - * {@code Proxy.newProxyInstance}-- and false otherwise.
 205.110 - *
 205.111 - * <li>The {@code java.security.ProtectionDomain} of a proxy class
 205.112 - * is the same as that of system classes loaded by the bootstrap class
 205.113 - * loader, such as {@code java.lang.Object}, because the code for a
 205.114 - * proxy class is generated by trusted system code.  This protection
 205.115 - * domain will typically be granted
 205.116 - * {@code java.security.AllPermission}.
 205.117 - *
 205.118 - * <li>Each proxy class has one public constructor that takes one argument,
 205.119 - * an implementation of the interface {@link InvocationHandler}, to set
 205.120 - * the invocation handler for a proxy instance.  Rather than having to use
 205.121 - * the reflection API to access the public constructor, a proxy instance
 205.122 - * can be also be created by calling the {@link Proxy#newProxyInstance
 205.123 - * Proxy.newProxyInstance} method, which combines the actions of calling
 205.124 - * {@link Proxy#getProxyClass Proxy.getProxyClass} with invoking the
 205.125 - * constructor with an invocation handler.
 205.126 - * </ul>
 205.127 - *
 205.128 - * <p>A proxy instance has the following properties:
 205.129 - *
 205.130 - * <ul>
 205.131 - * <li>Given a proxy instance {@code proxy} and one of the
 205.132 - * interfaces implemented by its proxy class {@code Foo}, the
 205.133 - * following expression will return true:
 205.134 - * <pre>
 205.135 - *     {@code proxy instanceof Foo}
 205.136 - * </pre>
 205.137 - * and the following cast operation will succeed (rather than throwing
 205.138 - * a {@code ClassCastException}):
 205.139 - * <pre>
 205.140 - *     {@code (Foo) proxy}
 205.141 - * </pre>
 205.142 - *
 205.143 - * <li>Each proxy instance has an associated invocation handler, the one
 205.144 - * that was passed to its constructor.  The static
 205.145 - * {@link Proxy#getInvocationHandler Proxy.getInvocationHandler} method
 205.146 - * will return the invocation handler associated with the proxy instance
 205.147 - * passed as its argument.
 205.148 - *
 205.149 - * <li>An interface method invocation on a proxy instance will be
 205.150 - * encoded and dispatched to the invocation handler's {@link
 205.151 - * InvocationHandler#invoke invoke} method as described in the
 205.152 - * documentation for that method.
 205.153 - *
 205.154 - * <li>An invocation of the {@code hashCode},
 205.155 - * {@code equals}, or {@code toString} methods declared in
 205.156 - * {@code java.lang.Object} on a proxy instance will be encoded and
 205.157 - * dispatched to the invocation handler's {@code invoke} method in
 205.158 - * the same manner as interface method invocations are encoded and
 205.159 - * dispatched, as described above.  The declaring class of the
 205.160 - * {@code Method} object passed to {@code invoke} will be
 205.161 - * {@code java.lang.Object}.  Other public methods of a proxy
 205.162 - * instance inherited from {@code java.lang.Object} are not
 205.163 - * overridden by a proxy class, so invocations of those methods behave
 205.164 - * like they do for instances of {@code java.lang.Object}.
 205.165 - * </ul>
 205.166 - *
 205.167 - * <h3>Methods Duplicated in Multiple Proxy Interfaces</h3>
 205.168 - *
 205.169 - * <p>When two or more interfaces of a proxy class contain a method with
 205.170 - * the same name and parameter signature, the order of the proxy class's
 205.171 - * interfaces becomes significant.  When such a <i>duplicate method</i>
 205.172 - * is invoked on a proxy instance, the {@code Method} object passed
 205.173 - * to the invocation handler will not necessarily be the one whose
 205.174 - * declaring class is assignable from the reference type of the interface
 205.175 - * that the proxy's method was invoked through.  This limitation exists
 205.176 - * because the corresponding method implementation in the generated proxy
 205.177 - * class cannot determine which interface it was invoked through.
 205.178 - * Therefore, when a duplicate method is invoked on a proxy instance,
 205.179 - * the {@code Method} object for the method in the foremost interface
 205.180 - * that contains the method (either directly or inherited through a
 205.181 - * superinterface) in the proxy class's list of interfaces is passed to
 205.182 - * the invocation handler's {@code invoke} method, regardless of the
 205.183 - * reference type through which the method invocation occurred.
 205.184 - *
 205.185 - * <p>If a proxy interface contains a method with the same name and
 205.186 - * parameter signature as the {@code hashCode}, {@code equals},
 205.187 - * or {@code toString} methods of {@code java.lang.Object},
 205.188 - * when such a method is invoked on a proxy instance, the
 205.189 - * {@code Method} object passed to the invocation handler will have
 205.190 - * {@code java.lang.Object} as its declaring class.  In other words,
 205.191 - * the public, non-final methods of {@code java.lang.Object}
 205.192 - * logically precede all of the proxy interfaces for the determination of
 205.193 - * which {@code Method} object to pass to the invocation handler.
 205.194 - *
 205.195 - * <p>Note also that when a duplicate method is dispatched to an
 205.196 - * invocation handler, the {@code invoke} method may only throw
 205.197 - * checked exception types that are assignable to one of the exception
 205.198 - * types in the {@code throws} clause of the method in <i>all</i> of
 205.199 - * the proxy interfaces that it can be invoked through.  If the
 205.200 - * {@code invoke} method throws a checked exception that is not
 205.201 - * assignable to any of the exception types declared by the method in one
 205.202 - * of the proxy interfaces that it can be invoked through, then an
 205.203 - * unchecked {@code UndeclaredThrowableException} will be thrown by
 205.204 - * the invocation on the proxy instance.  This restriction means that not
 205.205 - * all of the exception types returned by invoking
 205.206 - * {@code getExceptionTypes} on the {@code Method} object
 205.207 - * passed to the {@code invoke} method can necessarily be thrown
 205.208 - * successfully by the {@code invoke} method.
 205.209 - *
 205.210 - * @author      Peter Jones
 205.211 - * @see         InvocationHandler
 205.212 - * @since       1.3
 205.213 - */
 205.214 -public class Proxy implements java.io.Serializable {
 205.215 -
 205.216 -    private static final long serialVersionUID = -2222568056686623797L;
 205.217 -
 205.218 -
 205.219 -
 205.220 -    /**
 205.221 -     * the invocation handler for this proxy instance.
 205.222 -     * @serial
 205.223 -     */
 205.224 -    protected InvocationHandler h;
 205.225 -
 205.226 -    /**
 205.227 -     * Prohibits instantiation.
 205.228 -     */
 205.229 -    private Proxy() {
 205.230 -    }
 205.231 -
 205.232 -    /**
 205.233 -     * Constructs a new {@code Proxy} instance from a subclass
 205.234 -     * (typically, a dynamic proxy class) with the specified value
 205.235 -     * for its invocation handler.
 205.236 -     *
 205.237 -     * @param   h the invocation handler for this proxy instance
 205.238 -     */
 205.239 -    protected Proxy(InvocationHandler h) {
 205.240 -        this.h = h;
 205.241 -    }
 205.242 -
 205.243 -    /**
 205.244 -     * Returns the {@code java.lang.Class} object for a proxy class
 205.245 -     * given a class loader and an array of interfaces.  The proxy class
 205.246 -     * will be defined by the specified class loader and will implement
 205.247 -     * all of the supplied interfaces.  If a proxy class for the same
 205.248 -     * permutation of interfaces has already been defined by the class
 205.249 -     * loader, then the existing proxy class will be returned; otherwise,
 205.250 -     * a proxy class for those interfaces will be generated dynamically
 205.251 -     * and defined by the class loader.
 205.252 -     *
 205.253 -     * <p>There are several restrictions on the parameters that may be
 205.254 -     * passed to {@code Proxy.getProxyClass}:
 205.255 -     *
 205.256 -     * <ul>
 205.257 -     * <li>All of the {@code Class} objects in the
 205.258 -     * {@code interfaces} array must represent interfaces, not
 205.259 -     * classes or primitive types.
 205.260 -     *
 205.261 -     * <li>No two elements in the {@code interfaces} array may
 205.262 -     * refer to identical {@code Class} objects.
 205.263 -     *
 205.264 -     * <li>All of the interface types must be visible by name through the
 205.265 -     * specified class loader.  In other words, for class loader
 205.266 -     * {@code cl} and every interface {@code i}, the following
 205.267 -     * expression must be true:
 205.268 -     * <pre>
 205.269 -     *     Class.forName(i.getName(), false, cl) == i
 205.270 -     * </pre>
 205.271 -     *
 205.272 -     * <li>All non-public interfaces must be in the same package;
 205.273 -     * otherwise, it would not be possible for the proxy class to
 205.274 -     * implement all of the interfaces, regardless of what package it is
 205.275 -     * defined in.
 205.276 -     *
 205.277 -     * <li>For any set of member methods of the specified interfaces
 205.278 -     * that have the same signature:
 205.279 -     * <ul>
 205.280 -     * <li>If the return type of any of the methods is a primitive
 205.281 -     * type or void, then all of the methods must have that same
 205.282 -     * return type.
 205.283 -     * <li>Otherwise, one of the methods must have a return type that
 205.284 -     * is assignable to all of the return types of the rest of the
 205.285 -     * methods.
 205.286 -     * </ul>
 205.287 -     *
 205.288 -     * <li>The resulting proxy class must not exceed any limits imposed
 205.289 -     * on classes by the virtual machine.  For example, the VM may limit
 205.290 -     * the number of interfaces that a class may implement to 65535; in
 205.291 -     * that case, the size of the {@code interfaces} array must not
 205.292 -     * exceed 65535.
 205.293 -     * </ul>
 205.294 -     *
 205.295 -     * <p>If any of these restrictions are violated,
 205.296 -     * {@code Proxy.getProxyClass} will throw an
 205.297 -     * {@code IllegalArgumentException}.  If the {@code interfaces}
 205.298 -     * array argument or any of its elements are {@code null}, a
 205.299 -     * {@code NullPointerException} will be thrown.
 205.300 -     *
 205.301 -     * <p>Note that the order of the specified proxy interfaces is
 205.302 -     * significant: two requests for a proxy class with the same combination
 205.303 -     * of interfaces but in a different order will result in two distinct
 205.304 -     * proxy classes.
 205.305 -     *
 205.306 -     * @param   loader the class loader to define the proxy class
 205.307 -     * @param   interfaces the list of interfaces for the proxy class
 205.308 -     *          to implement
 205.309 -     * @return  a proxy class that is defined in the specified class loader
 205.310 -     *          and that implements the specified interfaces
 205.311 -     * @throws  IllegalArgumentException if any of the restrictions on the
 205.312 -     *          parameters that may be passed to {@code getProxyClass}
 205.313 -     *          are violated
 205.314 -     * @throws  NullPointerException if the {@code interfaces} array
 205.315 -     *          argument or any of its elements are {@code null}
 205.316 -     */
 205.317 -    public static Class<?> getProxyClass(ClassLoader loader,
 205.318 -                                         Class<?>... interfaces)
 205.319 -        throws IllegalArgumentException
 205.320 -    {
 205.321 -        throw new IllegalArgumentException();
 205.322 -    }
 205.323 -
 205.324 -    /**
 205.325 -     * Returns an instance of a proxy class for the specified interfaces
 205.326 -     * that dispatches method invocations to the specified invocation
 205.327 -     * handler.  This method is equivalent to:
 205.328 -     * <pre>
 205.329 -     *     Proxy.getProxyClass(loader, interfaces).
 205.330 -     *         getConstructor(new Class[] { InvocationHandler.class }).
 205.331 -     *         newInstance(new Object[] { handler });
 205.332 -     * </pre>
 205.333 -     *
 205.334 -     * <p>{@code Proxy.newProxyInstance} throws
 205.335 -     * {@code IllegalArgumentException} for the same reasons that
 205.336 -     * {@code Proxy.getProxyClass} does.
 205.337 -     *
 205.338 -     * @param   loader the class loader to define the proxy class
 205.339 -     * @param   interfaces the list of interfaces for the proxy class
 205.340 -     *          to implement
 205.341 -     * @param   h the invocation handler to dispatch method invocations to
 205.342 -     * @return  a proxy instance with the specified invocation handler of a
 205.343 -     *          proxy class that is defined by the specified class loader
 205.344 -     *          and that implements the specified interfaces
 205.345 -     * @throws  IllegalArgumentException if any of the restrictions on the
 205.346 -     *          parameters that may be passed to {@code getProxyClass}
 205.347 -     *          are violated
 205.348 -     * @throws  NullPointerException if the {@code interfaces} array
 205.349 -     *          argument or any of its elements are {@code null}, or
 205.350 -     *          if the invocation handler, {@code h}, is
 205.351 -     *          {@code null}
 205.352 -     */
 205.353 -    public static Object newProxyInstance(ClassLoader loader,
 205.354 -                                          Class<?>[] interfaces,
 205.355 -                                          InvocationHandler h)
 205.356 -        throws IllegalArgumentException
 205.357 -    {
 205.358 -        if (h == null) {
 205.359 -            throw new NullPointerException();
 205.360 -        }
 205.361 -        throw new IllegalArgumentException();
 205.362 -    }
 205.363 -
 205.364 -    /**
 205.365 -     * Returns true if and only if the specified class was dynamically
 205.366 -     * generated to be a proxy class using the {@code getProxyClass}
 205.367 -     * method or the {@code newProxyInstance} method.
 205.368 -     *
 205.369 -     * <p>The reliability of this method is important for the ability
 205.370 -     * to use it to make security decisions, so its implementation should
 205.371 -     * not just test if the class in question extends {@code Proxy}.
 205.372 -     *
 205.373 -     * @param   cl the class to test
 205.374 -     * @return  {@code true} if the class is a proxy class and
 205.375 -     *          {@code false} otherwise
 205.376 -     * @throws  NullPointerException if {@code cl} is {@code null}
 205.377 -     */
 205.378 -    public static boolean isProxyClass(Class<?> cl) {
 205.379 -        if (cl == null) {
 205.380 -            throw new NullPointerException();
 205.381 -        }
 205.382 -
 205.383 -        return false;
 205.384 -    }
 205.385 -
 205.386 -    /**
 205.387 -     * Returns the invocation handler for the specified proxy instance.
 205.388 -     *
 205.389 -     * @param   proxy the proxy instance to return the invocation handler for
 205.390 -     * @return  the invocation handler for the proxy instance
 205.391 -     * @throws  IllegalArgumentException if the argument is not a
 205.392 -     *          proxy instance
 205.393 -     */
 205.394 -    public static InvocationHandler getInvocationHandler(Object proxy)
 205.395 -        throws IllegalArgumentException
 205.396 -    {
 205.397 -        /*
 205.398 -         * Verify that the object is actually a proxy instance.
 205.399 -         */
 205.400 -        if (!isProxyClass(proxy.getClass())) {
 205.401 -            throw new IllegalArgumentException("not a proxy instance");
 205.402 -        }
 205.403 -
 205.404 -        Proxy p = (Proxy) proxy;
 205.405 -        return p.h;
 205.406 -    }
 205.407 -
 205.408 -    private static native Class defineClass0(ClassLoader loader, String name,
 205.409 -                                             byte[] b, int off, int len);
 205.410 -}
   206.1 --- a/emul/mini/src/main/java/java/lang/reflect/Type.java	Mon Feb 25 19:00:08 2013 +0100
   206.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   206.3 @@ -1,37 +0,0 @@
   206.4 -/*
   206.5 - * Copyright (c) 2003, 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.reflect;
  206.30 -
  206.31 -/**
  206.32 - * Type is the common superinterface for all types in the Java
  206.33 - * programming language. These include raw types, parameterized types,
  206.34 - * array types, type variables and primitive types.
  206.35 - *
  206.36 - * @since 1.5
  206.37 - */
  206.38 -
  206.39 -public interface Type {
  206.40 -}
   207.1 --- a/emul/mini/src/main/java/java/lang/reflect/TypeVariable.java	Mon Feb 25 19:00:08 2013 +0100
   207.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   207.3 @@ -1,89 +0,0 @@
   207.4 -/*
   207.5 - * Copyright (c) 2003, 2005, 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.reflect;
  207.30 -
  207.31 -/**
  207.32 - * TypeVariable is the common superinterface for type variables of kinds.
  207.33 - * A type variable is created the first time it is needed by a reflective
  207.34 - * method, as specified in this package.  If a type variable t is referenced
  207.35 - * by a type (i.e, class, interface or annotation type) T, and T is declared
  207.36 - * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
  207.37 - * requires the resolution (see JVMS 5) of the ith enclosing class of T,
  207.38 - * for i = 0 to n, inclusive. Creating a type variable must not cause the
  207.39 - * creation of its bounds. Repeated creation of a type variable has no effect.
  207.40 - *
  207.41 - * <p>Multiple objects may be instantiated at run-time to
  207.42 - * represent a given type variable. Even though a type variable is
  207.43 - * created only once, this does not imply any requirement to cache
  207.44 - * instances representing the type variable. However, all instances
  207.45 - * representing a type variable must be equal() to each other.
  207.46 - * As a consequence, users of type variables must not rely on the identity
  207.47 - * of instances of classes implementing this interface.
  207.48 - *
  207.49 - * @param <D> the type of generic declaration that declared the
  207.50 - * underlying type variable.
  207.51 - *
  207.52 - * @since 1.5
  207.53 - */
  207.54 -public interface TypeVariable<D extends GenericDeclaration> extends Type {
  207.55 -    /**
  207.56 -     * Returns an array of {@code Type} objects representing the
  207.57 -     * upper bound(s) of this type variable.  Note that if no upper bound is
  207.58 -     * explicitly declared, the upper bound is {@code Object}.
  207.59 -     *
  207.60 -     * <p>For each upper bound B: <ul> <li>if B is a parameterized
  207.61 -     * type or a type variable, it is created, (see {@link
  207.62 -     * java.lang.reflect.ParameterizedType ParameterizedType} for the
  207.63 -     * details of the creation process for parameterized types).
  207.64 -     * <li>Otherwise, B is resolved.  </ul>
  207.65 -     *
  207.66 -     * @throws TypeNotPresentException  if any of the
  207.67 -     *     bounds refers to a non-existent type declaration
  207.68 -     * @throws MalformedParameterizedTypeException if any of the
  207.69 -     *     bounds refer to a parameterized type that cannot be instantiated
  207.70 -     *     for any reason
  207.71 -     * @return an array of {@code Type}s representing the upper
  207.72 -     *     bound(s) of this type variable
  207.73 -    */
  207.74 -    Type[] getBounds();
  207.75 -
  207.76 -    /**
  207.77 -     * Returns the {@code GenericDeclaration} object representing the
  207.78 -     * generic declaration declared this type variable.
  207.79 -     *
  207.80 -     * @return the generic declaration declared for this type variable.
  207.81 -     *
  207.82 -     * @since 1.5
  207.83 -     */
  207.84 -    D getGenericDeclaration();
  207.85 -
  207.86 -    /**
  207.87 -     * Returns the name of this type variable, as it occurs in the source code.
  207.88 -     *
  207.89 -     * @return the name of this type variable, as it appears in the source code
  207.90 -     */
  207.91 -    String getName();
  207.92 -}
   208.1 --- a/emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java	Mon Feb 25 19:00:08 2013 +0100
   208.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   208.3 @@ -1,119 +0,0 @@
   208.4 -/*
   208.5 - * Copyright (c) 1999, 2006, 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.reflect;
  208.30 -
  208.31 -/**
  208.32 - * Thrown by a method invocation on a proxy instance if its invocation
  208.33 - * handler's {@link InvocationHandler#invoke invoke} method throws a
  208.34 - * checked exception (a {@code Throwable} that is not assignable
  208.35 - * to {@code RuntimeException} or {@code Error}) that
  208.36 - * is not assignable to any of the exception types declared in the
  208.37 - * {@code throws} clause of the method that was invoked on the
  208.38 - * proxy instance and dispatched to the invocation handler.
  208.39 - *
  208.40 - * <p>An {@code UndeclaredThrowableException} instance contains
  208.41 - * the undeclared checked exception that was thrown by the invocation
  208.42 - * handler, and it can be retrieved with the
  208.43 - * {@code getUndeclaredThrowable()} method.
  208.44 - * {@code UndeclaredThrowableException} extends
  208.45 - * {@code RuntimeException}, so it is an unchecked exception
  208.46 - * that wraps a checked exception.
  208.47 - *
  208.48 - * <p>As of release 1.4, this exception has been retrofitted to
  208.49 - * conform to the general purpose exception-chaining mechanism.  The
  208.50 - * "undeclared checked exception that was thrown by the invocation
  208.51 - * handler" that may be provided at construction time and accessed via
  208.52 - * the {@link #getUndeclaredThrowable()} method is now known as the
  208.53 - * <i>cause</i>, and may be accessed via the {@link
  208.54 - * Throwable#getCause()} method, as well as the aforementioned "legacy
  208.55 - * method."
  208.56 - *
  208.57 - * @author      Peter Jones
  208.58 - * @see         InvocationHandler
  208.59 - * @since       1.3
  208.60 - */
  208.61 -public class UndeclaredThrowableException extends RuntimeException {
  208.62 -    static final long serialVersionUID = 330127114055056639L;
  208.63 -
  208.64 -    /**
  208.65 -     * the undeclared checked exception that was thrown
  208.66 -     * @serial
  208.67 -     */
  208.68 -    private Throwable undeclaredThrowable;
  208.69 -
  208.70 -    /**
  208.71 -     * Constructs an {@code UndeclaredThrowableException} with the
  208.72 -     * specified {@code Throwable}.
  208.73 -     *
  208.74 -     * @param   undeclaredThrowable the undeclared checked exception
  208.75 -     *          that was thrown
  208.76 -     */
  208.77 -    public UndeclaredThrowableException(Throwable undeclaredThrowable) {
  208.78 -        super((Throwable) null);  // Disallow initCause
  208.79 -        this.undeclaredThrowable = undeclaredThrowable;
  208.80 -    }
  208.81 -
  208.82 -    /**
  208.83 -     * Constructs an {@code UndeclaredThrowableException} with the
  208.84 -     * specified {@code Throwable} and a detail message.
  208.85 -     *
  208.86 -     * @param   undeclaredThrowable the undeclared checked exception
  208.87 -     *          that was thrown
  208.88 -     * @param   s the detail message
  208.89 -     */
  208.90 -    public UndeclaredThrowableException(Throwable undeclaredThrowable,
  208.91 -                                        String s)
  208.92 -    {
  208.93 -        super(s, null);  // Disallow initCause
  208.94 -        this.undeclaredThrowable = undeclaredThrowable;
  208.95 -    }
  208.96 -
  208.97 -    /**
  208.98 -     * Returns the {@code Throwable} instance wrapped in this
  208.99 -     * {@code UndeclaredThrowableException}, which may be {@code null}.
 208.100 -     *
 208.101 -     * <p>This method predates the general-purpose exception chaining facility.
 208.102 -     * The {@link Throwable#getCause()} method is now the preferred means of
 208.103 -     * obtaining this information.
 208.104 -     *
 208.105 -     * @return the undeclared checked exception that was thrown
 208.106 -     */
 208.107 -    public Throwable getUndeclaredThrowable() {
 208.108 -        return undeclaredThrowable;
 208.109 -    }
 208.110 -
 208.111 -    /**
 208.112 -     * Returns the cause of this exception (the {@code Throwable}
 208.113 -     * instance wrapped in this {@code UndeclaredThrowableException},
 208.114 -     * which may be {@code null}).
 208.115 -     *
 208.116 -     * @return  the cause of this exception.
 208.117 -     * @since   1.4
 208.118 -     */
 208.119 -    public Throwable getCause() {
 208.120 -        return undeclaredThrowable;
 208.121 -    }
 208.122 -}
   209.1 --- a/emul/mini/src/main/java/java/lang/reflect/package-info.java	Mon Feb 25 19:00:08 2013 +0100
   209.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   209.3 @@ -1,49 +0,0 @@
   209.4 -/*
   209.5 - * Copyright (c) 1998, 2006, 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 -/**
  209.30 - * Provides classes and interfaces for obtaining reflective
  209.31 - * information about classes and objects.  Reflection allows
  209.32 - * programmatic access to information about the fields, methods and
  209.33 - * constructors of loaded classes, and the use of reflected fields,
  209.34 - * methods, and constructors to operate on their underlying
  209.35 - * counterparts, within security restrictions.
  209.36 - *
  209.37 - * <p>{@code AccessibleObject} allows suppression of access checks if
  209.38 - * the necessary {@code ReflectPermission} is available.
  209.39 - *
  209.40 - * <p>{@code Array} provides static methods to dynamically create and
  209.41 - * access arrays.
  209.42 - *
  209.43 - * <p>Classes in this package, along with {@code java.lang.Class}
  209.44 - * accommodate applications such as debuggers, interpreters, object
  209.45 - * inspectors, class browsers, and services such as Object
  209.46 - * Serialization and JavaBeans that need access to either the public
  209.47 - * members of a target object (based on its runtime class) or the
  209.48 - * members declared by a given class.
  209.49 - *
  209.50 - * @since JDK1.1
  209.51 - */
  209.52 -package java.lang.reflect;
   210.1 --- a/emul/mini/src/main/java/java/net/MalformedURLException.java	Mon Feb 25 19:00:08 2013 +0100
   210.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   210.3 @@ -1,56 +0,0 @@
   210.4 -/*
   210.5 - * Copyright (c) 1995, 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.net;
  210.30 -
  210.31 -import java.io.IOException;
  210.32 -
  210.33 -/**
  210.34 - * Thrown to indicate that a malformed URL has occurred. Either no
  210.35 - * legal protocol could be found in a specification string or the
  210.36 - * string could not be parsed.
  210.37 - *
  210.38 - * @author  Arthur van Hoff
  210.39 - * @since   JDK1.0
  210.40 - */
  210.41 -public class MalformedURLException extends IOException {
  210.42 -    private static final long serialVersionUID = -182787522200415866L;
  210.43 -
  210.44 -    /**
  210.45 -     * Constructs a <code>MalformedURLException</code> with no detail message.
  210.46 -     */
  210.47 -    public MalformedURLException() {
  210.48 -    }
  210.49 -
  210.50 -    /**
  210.51 -     * Constructs a <code>MalformedURLException</code> with the
  210.52 -     * specified detail message.
  210.53 -     *
  210.54 -     * @param   msg   the detail message.
  210.55 -     */
  210.56 -    public MalformedURLException(String msg) {
  210.57 -        super(msg);
  210.58 -    }
  210.59 -}
   211.1 --- a/emul/mini/src/main/java/java/net/URL.java	Mon Feb 25 19:00:08 2013 +0100
   211.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   211.3 @@ -1,1090 +0,0 @@
   211.4 -/*
   211.5 - * Copyright (c) 1995, 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.net;
  211.30 -
  211.31 -import java.io.ByteArrayInputStream;
  211.32 -import java.io.IOException;
  211.33 -import java.io.InputStream;
  211.34 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  211.35 -
  211.36 -
  211.37 -/**
  211.38 - * Class <code>URL</code> represents a Uniform Resource
  211.39 - * Locator, a pointer to a "resource" on the World
  211.40 - * Wide Web. A resource can be something as simple as a file or a
  211.41 - * directory, or it can be a reference to a more complicated object,
  211.42 - * such as a query to a database or to a search engine. More
  211.43 - * information on the types of URLs and their formats can be found at:
  211.44 - * <blockquote>
  211.45 - *     <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
  211.46 - *    <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
  211.47 - * </blockquote>
  211.48 - * <p>
  211.49 - * In general, a URL can be broken into several parts. The previous
  211.50 - * example of a URL indicates that the protocol to use is
  211.51 - * <code>http</code> (HyperText Transfer Protocol) and that the
  211.52 - * information resides on a host machine named
  211.53 - * <code>www.socs.uts.edu.au</code>. The information on that host
  211.54 - * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
  211.55 - * meaning of this name on the host machine is both protocol
  211.56 - * dependent and host dependent. The information normally resides in
  211.57 - * a file, but it could be generated on the fly. This component of
  211.58 - * the URL is called the <i>path</i> component.
  211.59 - * <p>
  211.60 - * A URL can optionally specify a "port", which is the
  211.61 - * port number to which the TCP connection is made on the remote host
  211.62 - * machine. If the port is not specified, the default port for
  211.63 - * the protocol is used instead. For example, the default port for
  211.64 - * <code>http</code> is <code>80</code>. An alternative port could be
  211.65 - * specified as:
  211.66 - * <blockquote><pre>
  211.67 - *     http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
  211.68 - * </pre></blockquote>
  211.69 - * <p>
  211.70 - * The syntax of <code>URL</code> is defined by  <a
  211.71 - * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
  211.72 - * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
  211.73 - * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
  211.74 - * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
  211.75 - * also supports scope_ids. The syntax and usage of scope_ids is described
  211.76 - * <a href="Inet6Address.html#scoped">here</a>.
  211.77 - * <p>
  211.78 - * A URL may have appended to it a "fragment", also known
  211.79 - * as a "ref" or a "reference". The fragment is indicated by the sharp
  211.80 - * sign character "#" followed by more characters. For example,
  211.81 - * <blockquote><pre>
  211.82 - *     http://java.sun.com/index.html#chapter1
  211.83 - * </pre></blockquote>
  211.84 - * <p>
  211.85 - * This fragment is not technically part of the URL. Rather, it
  211.86 - * indicates that after the specified resource is retrieved, the
  211.87 - * application is specifically interested in that part of the
  211.88 - * document that has the tag <code>chapter1</code> attached to it. The
  211.89 - * meaning of a tag is resource specific.
  211.90 - * <p>
  211.91 - * An application can also specify a "relative URL",
  211.92 - * which contains only enough information to reach the resource
  211.93 - * relative to another URL. Relative URLs are frequently used within
  211.94 - * HTML pages. For example, if the contents of the URL:
  211.95 - * <blockquote><pre>
  211.96 - *     http://java.sun.com/index.html
  211.97 - * </pre></blockquote>
  211.98 - * contained within it the relative URL:
  211.99 - * <blockquote><pre>
 211.100 - *     FAQ.html
 211.101 - * </pre></blockquote>
 211.102 - * it would be a shorthand for:
 211.103 - * <blockquote><pre>
 211.104 - *     http://java.sun.com/FAQ.html
 211.105 - * </pre></blockquote>
 211.106 - * <p>
 211.107 - * The relative URL need not specify all the components of a URL. If
 211.108 - * the protocol, host name, or port number is missing, the value is
 211.109 - * inherited from the fully specified URL. The file component must be
 211.110 - * specified. The optional fragment is not inherited.
 211.111 - * <p>
 211.112 - * The URL class does not itself encode or decode any URL components
 211.113 - * according to the escaping mechanism defined in RFC2396. It is the
 211.114 - * responsibility of the caller to encode any fields, which need to be
 211.115 - * escaped prior to calling URL, and also to decode any escaped fields,
 211.116 - * that are returned from URL. Furthermore, because URL has no knowledge
 211.117 - * of URL escaping, it does not recognise equivalence between the encoded
 211.118 - * or decoded form of the same URL. For example, the two URLs:<br>
 211.119 - * <pre>    http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
 211.120 - * would be considered not equal to each other.
 211.121 - * <p>
 211.122 - * Note, the {@link java.net.URI} class does perform escaping of its
 211.123 - * component fields in certain circumstances. The recommended way
 211.124 - * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
 211.125 - * and to convert between these two classes using {@link #toURI()} and
 211.126 - * {@link URI#toURL()}.
 211.127 - * <p>
 211.128 - * The {@link URLEncoder} and {@link URLDecoder} classes can also be
 211.129 - * used, but only for HTML form encoding, which is not the same
 211.130 - * as the encoding scheme defined in RFC2396.
 211.131 - *
 211.132 - * @author  James Gosling
 211.133 - * @since JDK1.0
 211.134 - */
 211.135 -public final class URL implements java.io.Serializable {
 211.136 -
 211.137 -    static final long serialVersionUID = -7627629688361524110L;
 211.138 -
 211.139 -    /**
 211.140 -     * The property which specifies the package prefix list to be scanned
 211.141 -     * for protocol handlers.  The value of this property (if any) should
 211.142 -     * be a vertical bar delimited list of package names to search through
 211.143 -     * for a protocol handler to load.  The policy of this class is that
 211.144 -     * all protocol handlers will be in a class called <protocolname>.Handler,
 211.145 -     * and each package in the list is examined in turn for a matching
 211.146 -     * handler.  If none are found (or the property is not specified), the
 211.147 -     * default package prefix, sun.net.www.protocol, is used.  The search
 211.148 -     * proceeds from the first package in the list to the last and stops
 211.149 -     * when a match is found.
 211.150 -     */
 211.151 -    private static final String protocolPathProp = "java.protocol.handler.pkgs";
 211.152 -
 211.153 -    /**
 211.154 -     * The protocol to use (ftp, http, nntp, ... etc.) .
 211.155 -     * @serial
 211.156 -     */
 211.157 -    private String protocol;
 211.158 -
 211.159 -    /**
 211.160 -     * The host name to connect to.
 211.161 -     * @serial
 211.162 -     */
 211.163 -    private String host;
 211.164 -
 211.165 -    /**
 211.166 -     * The protocol port to connect to.
 211.167 -     * @serial
 211.168 -     */
 211.169 -    private int port = -1;
 211.170 -
 211.171 -    /**
 211.172 -     * The specified file name on that host. <code>file</code> is
 211.173 -     * defined as <code>path[?query]</code>
 211.174 -     * @serial
 211.175 -     */
 211.176 -    private String file;
 211.177 -
 211.178 -    /**
 211.179 -     * The query part of this URL.
 211.180 -     */
 211.181 -    private transient String query;
 211.182 -
 211.183 -    /**
 211.184 -     * The authority part of this URL.
 211.185 -     * @serial
 211.186 -     */
 211.187 -    private String authority;
 211.188 -
 211.189 -    /**
 211.190 -     * The path part of this URL.
 211.191 -     */
 211.192 -    private transient String path;
 211.193 -
 211.194 -    /**
 211.195 -     * The userinfo part of this URL.
 211.196 -     */
 211.197 -    private transient String userInfo;
 211.198 -
 211.199 -    /**
 211.200 -     * # reference.
 211.201 -     * @serial
 211.202 -     */
 211.203 -    private String ref;
 211.204 -
 211.205 -    /**
 211.206 -     * The host's IP address, used in equals and hashCode.
 211.207 -     * Computed on demand. An uninitialized or unknown hostAddress is null.
 211.208 -     */
 211.209 -    transient Object hostAddress;
 211.210 -
 211.211 -    /**
 211.212 -     * The URLStreamHandler for this URL.
 211.213 -     */
 211.214 -    transient URLStreamHandler handler;
 211.215 -
 211.216 -    /* Our hash code.
 211.217 -     * @serial
 211.218 -     */
 211.219 -    private int hashCode = -1;
 211.220 -    
 211.221 -    /** input stream associated with the URL */
 211.222 -    private InputStream is;
 211.223 -
 211.224 -    /**
 211.225 -     * Creates a <code>URL</code> object from the specified
 211.226 -     * <code>protocol</code>, <code>host</code>, <code>port</code>
 211.227 -     * number, and <code>file</code>.<p>
 211.228 -     *
 211.229 -     * <code>host</code> can be expressed as a host name or a literal
 211.230 -     * IP address. If IPv6 literal address is used, it should be
 211.231 -     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
 211.232 -     * specified by <a
 211.233 -     * href="http://www.ietf.org/rfc/rfc2732.txt">RFC&nbsp;2732</a>;
 211.234 -     * However, the literal IPv6 address format defined in <a
 211.235 -     * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
 211.236 -     * Version 6 Addressing Architecture</i></a> is also accepted.<p>
 211.237 -     *
 211.238 -     * Specifying a <code>port</code> number of <code>-1</code>
 211.239 -     * indicates that the URL should use the default port for the
 211.240 -     * protocol.<p>
 211.241 -     *
 211.242 -     * If this is the first URL object being created with the specified
 211.243 -     * protocol, a <i>stream protocol handler</i> object, an instance of
 211.244 -     * class <code>URLStreamHandler</code>, is created for that protocol:
 211.245 -     * <ol>
 211.246 -     * <li>If the application has previously set up an instance of
 211.247 -     *     <code>URLStreamHandlerFactory</code> as the stream handler factory,
 211.248 -     *     then the <code>createURLStreamHandler</code> method of that instance
 211.249 -     *     is called with the protocol string as an argument to create the
 211.250 -     *     stream protocol handler.
 211.251 -     * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
 211.252 -     *     or if the factory's <code>createURLStreamHandler</code> method
 211.253 -     *     returns <code>null</code>, then the constructor finds the
 211.254 -     *     value of the system property:
 211.255 -     *     <blockquote><pre>
 211.256 -     *         java.protocol.handler.pkgs
 211.257 -     *     </pre></blockquote>
 211.258 -     *     If the value of that system property is not <code>null</code>,
 211.259 -     *     it is interpreted as a list of packages separated by a vertical
 211.260 -     *     slash character '<code>|</code>'. The constructor tries to load
 211.261 -     *     the class named:
 211.262 -     *     <blockquote><pre>
 211.263 -     *         &lt;<i>package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 211.264 -     *     </pre></blockquote>
 211.265 -     *     where &lt;<i>package</i>&gt; is replaced by the name of the package
 211.266 -     *     and &lt;<i>protocol</i>&gt; is replaced by the name of the protocol.
 211.267 -     *     If this class does not exist, or if the class exists but it is not
 211.268 -     *     a subclass of <code>URLStreamHandler</code>, then the next package
 211.269 -     *     in the list is tried.
 211.270 -     * <li>If the previous step fails to find a protocol handler, then the
 211.271 -     *     constructor tries to load from a system default package.
 211.272 -     *     <blockquote><pre>
 211.273 -     *         &lt;<i>system default package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 211.274 -     *     </pre></blockquote>
 211.275 -     *     If this class does not exist, or if the class exists but it is not a
 211.276 -     *     subclass of <code>URLStreamHandler</code>, then a
 211.277 -     *     <code>MalformedURLException</code> is thrown.
 211.278 -     * </ol>
 211.279 -     *
 211.280 -     * <p>Protocol handlers for the following protocols are guaranteed
 211.281 -     * to exist on the search path :-
 211.282 -     * <blockquote><pre>
 211.283 -     *     http, https, ftp, file, and jar
 211.284 -     * </pre></blockquote>
 211.285 -     * Protocol handlers for additional protocols may also be
 211.286 -     * available.
 211.287 -     *
 211.288 -     * <p>No validation of the inputs is performed by this constructor.
 211.289 -     *
 211.290 -     * @param      protocol   the name of the protocol to use.
 211.291 -     * @param      host       the name of the host.
 211.292 -     * @param      port       the port number on the host.
 211.293 -     * @param      file       the file on the host
 211.294 -     * @exception  MalformedURLException  if an unknown protocol is specified.
 211.295 -     * @see        java.lang.System#getProperty(java.lang.String)
 211.296 -     * @see        java.net.URL#setURLStreamHandlerFactory(
 211.297 -     *                  java.net.URLStreamHandlerFactory)
 211.298 -     * @see        java.net.URLStreamHandler
 211.299 -     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 211.300 -     *                  java.lang.String)
 211.301 -     */
 211.302 -    public URL(String protocol, String host, int port, String file)
 211.303 -        throws MalformedURLException
 211.304 -    {
 211.305 -        this(protocol, host, port, file, null);
 211.306 -    }
 211.307 -
 211.308 -    /**
 211.309 -     * Creates a URL from the specified <code>protocol</code>
 211.310 -     * name, <code>host</code> name, and <code>file</code> name. The
 211.311 -     * default port for the specified protocol is used.
 211.312 -     * <p>
 211.313 -     * This method is equivalent to calling the four-argument
 211.314 -     * constructor with the arguments being <code>protocol</code>,
 211.315 -     * <code>host</code>, <code>-1</code>, and <code>file</code>.
 211.316 -     *
 211.317 -     * No validation of the inputs is performed by this constructor.
 211.318 -     *
 211.319 -     * @param      protocol   the name of the protocol to use.
 211.320 -     * @param      host       the name of the host.
 211.321 -     * @param      file       the file on the host.
 211.322 -     * @exception  MalformedURLException  if an unknown protocol is specified.
 211.323 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 211.324 -     *                  int, java.lang.String)
 211.325 -     */
 211.326 -    public URL(String protocol, String host, String file)
 211.327 -            throws MalformedURLException {
 211.328 -        this(protocol, host, -1, file);
 211.329 -    }
 211.330 -
 211.331 -    /**
 211.332 -     * Creates a <code>URL</code> object from the specified
 211.333 -     * <code>protocol</code>, <code>host</code>, <code>port</code>
 211.334 -     * number, <code>file</code>, and <code>handler</code>. Specifying
 211.335 -     * a <code>port</code> number of <code>-1</code> indicates that
 211.336 -     * the URL should use the default port for the protocol. Specifying
 211.337 -     * a <code>handler</code> of <code>null</code> indicates that the URL
 211.338 -     * should use a default stream handler for the protocol, as outlined
 211.339 -     * for:
 211.340 -     *     java.net.URL#URL(java.lang.String, java.lang.String, int,
 211.341 -     *                      java.lang.String)
 211.342 -     *
 211.343 -     * <p>If the handler is not null and there is a security manager,
 211.344 -     * the security manager's <code>checkPermission</code>
 211.345 -     * method is called with a
 211.346 -     * <code>NetPermission("specifyStreamHandler")</code> permission.
 211.347 -     * This may result in a SecurityException.
 211.348 -     *
 211.349 -     * No validation of the inputs is performed by this constructor.
 211.350 -     *
 211.351 -     * @param      protocol   the name of the protocol to use.
 211.352 -     * @param      host       the name of the host.
 211.353 -     * @param      port       the port number on the host.
 211.354 -     * @param      file       the file on the host
 211.355 -     * @param      handler    the stream handler for the URL.
 211.356 -     * @exception  MalformedURLException  if an unknown protocol is specified.
 211.357 -     * @exception  SecurityException
 211.358 -     *        if a security manager exists and its
 211.359 -     *        <code>checkPermission</code> method doesn't allow
 211.360 -     *        specifying a stream handler explicitly.
 211.361 -     * @see        java.lang.System#getProperty(java.lang.String)
 211.362 -     * @see        java.net.URL#setURLStreamHandlerFactory(
 211.363 -     *                  java.net.URLStreamHandlerFactory)
 211.364 -     * @see        java.net.URLStreamHandler
 211.365 -     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 211.366 -     *                  java.lang.String)
 211.367 -     * @see        SecurityManager#checkPermission
 211.368 -     * @see        java.net.NetPermission
 211.369 -     */
 211.370 -    public URL(String protocol, String host, int port, String file,
 211.371 -               URLStreamHandler handler) throws MalformedURLException {
 211.372 -        if (handler != null) {
 211.373 -            throw new SecurityException();
 211.374 -        }
 211.375 -
 211.376 -        protocol = protocol.toLowerCase();
 211.377 -        this.protocol = protocol;
 211.378 -        if (host != null) {
 211.379 -
 211.380 -            /**
 211.381 -             * if host is a literal IPv6 address,
 211.382 -             * we will make it conform to RFC 2732
 211.383 -             */
 211.384 -            if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
 211.385 -                host = "["+host+"]";
 211.386 -            }
 211.387 -            this.host = host;
 211.388 -
 211.389 -            if (port < -1) {
 211.390 -                throw new MalformedURLException("Invalid port number :" +
 211.391 -                                                    port);
 211.392 -            }
 211.393 -            this.port = port;
 211.394 -            authority = (port == -1) ? host : host + ":" + port;
 211.395 -        }
 211.396 -
 211.397 -        Parts parts = new Parts(file);
 211.398 -        path = parts.getPath();
 211.399 -        query = parts.getQuery();
 211.400 -
 211.401 -        if (query != null) {
 211.402 -            this.file = path + "?" + query;
 211.403 -        } else {
 211.404 -            this.file = path;
 211.405 -        }
 211.406 -        ref = parts.getRef();
 211.407 -
 211.408 -        // Note: we don't do validation of the URL here. Too risky to change
 211.409 -        // right now, but worth considering for future reference. -br
 211.410 -        if (handler == null &&
 211.411 -            (handler = getURLStreamHandler(protocol)) == null) {
 211.412 -            throw new MalformedURLException("unknown protocol: " + protocol);
 211.413 -        }
 211.414 -        this.handler = handler;
 211.415 -    }
 211.416 -
 211.417 -    /**
 211.418 -     * Creates a <code>URL</code> object from the <code>String</code>
 211.419 -     * representation.
 211.420 -     * <p>
 211.421 -     * This constructor is equivalent to a call to the two-argument
 211.422 -     * constructor with a <code>null</code> first argument.
 211.423 -     *
 211.424 -     * @param      spec   the <code>String</code> to parse as a URL.
 211.425 -     * @exception  MalformedURLException  if no protocol is specified, or an
 211.426 -     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 211.427 -     * @see        java.net.URL#URL(java.net.URL, java.lang.String)
 211.428 -     */
 211.429 -    public URL(String spec) throws MalformedURLException {
 211.430 -        this(null, spec);
 211.431 -    }
 211.432 -    
 211.433 -    private URL(String spec, InputStream is) throws MalformedURLException {
 211.434 -        this(null, spec);
 211.435 -        this.is = is;
 211.436 -    }
 211.437 -
 211.438 -    /**
 211.439 -     * Creates a URL by parsing the given spec within a specified context.
 211.440 -     *
 211.441 -     * The new URL is created from the given context URL and the spec
 211.442 -     * argument as described in
 211.443 -     * RFC2396 &quot;Uniform Resource Identifiers : Generic * Syntax&quot; :
 211.444 -     * <blockquote><pre>
 211.445 -     *          &lt;scheme&gt;://&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;
 211.446 -     * </pre></blockquote>
 211.447 -     * The reference is parsed into the scheme, authority, path, query and
 211.448 -     * fragment parts. If the path component is empty and the scheme,
 211.449 -     * authority, and query components are undefined, then the new URL is a
 211.450 -     * reference to the current document. Otherwise, the fragment and query
 211.451 -     * parts present in the spec are used in the new URL.
 211.452 -     * <p>
 211.453 -     * If the scheme component is defined in the given spec and does not match
 211.454 -     * the scheme of the context, then the new URL is created as an absolute
 211.455 -     * URL based on the spec alone. Otherwise the scheme component is inherited
 211.456 -     * from the context URL.
 211.457 -     * <p>
 211.458 -     * If the authority component is present in the spec then the spec is
 211.459 -     * treated as absolute and the spec authority and path will replace the
 211.460 -     * context authority and path. If the authority component is absent in the
 211.461 -     * spec then the authority of the new URL will be inherited from the
 211.462 -     * context.
 211.463 -     * <p>
 211.464 -     * If the spec's path component begins with a slash character
 211.465 -     * &quot;/&quot; then the
 211.466 -     * path is treated as absolute and the spec path replaces the context path.
 211.467 -     * <p>
 211.468 -     * Otherwise, the path is treated as a relative path and is appended to the
 211.469 -     * context path, as described in RFC2396. Also, in this case,
 211.470 -     * the path is canonicalized through the removal of directory
 211.471 -     * changes made by occurences of &quot;..&quot; and &quot;.&quot;.
 211.472 -     * <p>
 211.473 -     * For a more detailed description of URL parsing, refer to RFC2396.
 211.474 -     *
 211.475 -     * @param      context   the context in which to parse the specification.
 211.476 -     * @param      spec      the <code>String</code> to parse as a URL.
 211.477 -     * @exception  MalformedURLException  if no protocol is specified, or an
 211.478 -     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 211.479 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 211.480 -     *                  int, java.lang.String)
 211.481 -     * @see        java.net.URLStreamHandler
 211.482 -     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 211.483 -     *                  java.lang.String, int, int)
 211.484 -     */
 211.485 -    public URL(URL context, String spec) throws MalformedURLException {
 211.486 -        this(context, spec, null);
 211.487 -    }
 211.488 -
 211.489 -    /**
 211.490 -     * Creates a URL by parsing the given spec with the specified handler
 211.491 -     * within a specified context. If the handler is null, the parsing
 211.492 -     * occurs as with the two argument constructor.
 211.493 -     *
 211.494 -     * @param      context   the context in which to parse the specification.
 211.495 -     * @param      spec      the <code>String</code> to parse as a URL.
 211.496 -     * @param      handler   the stream handler for the URL.
 211.497 -     * @exception  MalformedURLException  if no protocol is specified, or an
 211.498 -     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 211.499 -     * @exception  SecurityException
 211.500 -     *        if a security manager exists and its
 211.501 -     *        <code>checkPermission</code> method doesn't allow
 211.502 -     *        specifying a stream handler.
 211.503 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 211.504 -     *                  int, java.lang.String)
 211.505 -     * @see        java.net.URLStreamHandler
 211.506 -     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 211.507 -     *                  java.lang.String, int, int)
 211.508 -     */
 211.509 -    public URL(URL context, String spec, URLStreamHandler handler)
 211.510 -        throws MalformedURLException
 211.511 -    {
 211.512 -        this(findContext(context), spec, handler != null);
 211.513 -    }
 211.514 -    
 211.515 -    private URL(URL context, String spec, boolean ishandler)
 211.516 -    throws MalformedURLException {
 211.517 -        // Check for permission to specify a handler
 211.518 -        if (ishandler) {
 211.519 -            throw new SecurityException();
 211.520 -        }
 211.521 -        URLStreamHandler handler = null;
 211.522 -        
 211.523 -        String original = spec;
 211.524 -        int i, limit, c;
 211.525 -        int start = 0;
 211.526 -        String newProtocol = null;
 211.527 -        boolean aRef=false;
 211.528 -        boolean isRelative = false;
 211.529 -
 211.530 -
 211.531 -        try {
 211.532 -            limit = spec.length();
 211.533 -            while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
 211.534 -                limit--;        //eliminate trailing whitespace
 211.535 -            }
 211.536 -            while ((start < limit) && (spec.charAt(start) <= ' ')) {
 211.537 -                start++;        // eliminate leading whitespace
 211.538 -            }
 211.539 -
 211.540 -            if (spec.regionMatches(true, start, "url:", 0, 4)) {
 211.541 -                start += 4;
 211.542 -            }
 211.543 -            if (start < spec.length() && spec.charAt(start) == '#') {
 211.544 -                /* we're assuming this is a ref relative to the context URL.
 211.545 -                 * This means protocols cannot start w/ '#', but we must parse
 211.546 -                 * ref URL's like: "hello:there" w/ a ':' in them.
 211.547 -                 */
 211.548 -                aRef=true;
 211.549 -            }
 211.550 -            for (i = start ; !aRef && (i < limit) &&
 211.551 -                     ((c = spec.charAt(i)) != '/') ; i++) {
 211.552 -                if (c == ':') {
 211.553 -
 211.554 -                    String s = spec.substring(start, i).toLowerCase();
 211.555 -                    if (isValidProtocol(s)) {
 211.556 -                        newProtocol = s;
 211.557 -                        start = i + 1;
 211.558 -                    }
 211.559 -                    break;
 211.560 -                }
 211.561 -            }
 211.562 -
 211.563 -            // Only use our context if the protocols match.
 211.564 -            protocol = newProtocol;
 211.565 -            if ((context != null) && ((newProtocol == null) ||
 211.566 -                            newProtocol.equalsIgnoreCase(context.protocol))) {
 211.567 -                // inherit the protocol handler from the context
 211.568 -                // if not specified to the constructor
 211.569 -                if (handler == null) {
 211.570 -                    handler = context.handler;
 211.571 -                }
 211.572 -
 211.573 -                // If the context is a hierarchical URL scheme and the spec
 211.574 -                // contains a matching scheme then maintain backwards
 211.575 -                // compatibility and treat it as if the spec didn't contain
 211.576 -                // the scheme; see 5.2.3 of RFC2396
 211.577 -                if (context.path != null && context.path.startsWith("/"))
 211.578 -                    newProtocol = null;
 211.579 -
 211.580 -                if (newProtocol == null) {
 211.581 -                    protocol = context.protocol;
 211.582 -                    authority = context.authority;
 211.583 -                    userInfo = context.userInfo;
 211.584 -                    host = context.host;
 211.585 -                    port = context.port;
 211.586 -                    file = context.file;
 211.587 -                    path = context.path;
 211.588 -                    isRelative = true;
 211.589 -                }
 211.590 -            }
 211.591 -
 211.592 -            if (protocol == null) {
 211.593 -                throw new MalformedURLException("no protocol: "+original);
 211.594 -            }
 211.595 -
 211.596 -            // Get the protocol handler if not specified or the protocol
 211.597 -            // of the context could not be used
 211.598 -            if (handler == null &&
 211.599 -                (handler = getURLStreamHandler(protocol)) == null) {
 211.600 -                throw new MalformedURLException("unknown protocol: "+protocol);
 211.601 -            }
 211.602 -            this.handler = handler;
 211.603 -
 211.604 -            i = spec.indexOf('#', start);
 211.605 -            if (i >= 0) {
 211.606 -//thrw(protocol + " hnd: " + handler.getClass().getName() + " i: " + i);
 211.607 -                ref = spec.substring(i + 1, limit);
 211.608 -                limit = i;
 211.609 -            }
 211.610 -
 211.611 -            /*
 211.612 -             * Handle special case inheritance of query and fragment
 211.613 -             * implied by RFC2396 section 5.2.2.
 211.614 -             */
 211.615 -            if (isRelative && start == limit) {
 211.616 -                query = context.query;
 211.617 -                if (ref == null) {
 211.618 -                    ref = context.ref;
 211.619 -                }
 211.620 -            }
 211.621 -
 211.622 -            handler.parseURL(this, spec, start, limit);
 211.623 -
 211.624 -        } catch(MalformedURLException e) {
 211.625 -            throw e;
 211.626 -        } catch(Exception e) {
 211.627 -            MalformedURLException exception = new MalformedURLException(e.getMessage());
 211.628 -            exception.initCause(e);
 211.629 -            throw exception;
 211.630 -        }
 211.631 -    }
 211.632 -    
 211.633 -    /*
 211.634 -     * Returns true if specified string is a valid protocol name.
 211.635 -     */
 211.636 -    private boolean isValidProtocol(String protocol) {
 211.637 -        int len = protocol.length();
 211.638 -        if (len < 1)
 211.639 -            return false;
 211.640 -        char c = protocol.charAt(0);
 211.641 -        if (!Character.isLetter(c))
 211.642 -            return false;
 211.643 -        for (int i = 1; i < len; i++) {
 211.644 -            c = protocol.charAt(i);
 211.645 -            if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
 211.646 -                c != '-') {
 211.647 -                return false;
 211.648 -            }
 211.649 -        }
 211.650 -        return true;
 211.651 -    }
 211.652 -
 211.653 -    /**
 211.654 -     * Sets the fields of the URL. This is not a public method so that
 211.655 -     * only URLStreamHandlers can modify URL fields. URLs are
 211.656 -     * otherwise constant.
 211.657 -     *
 211.658 -     * @param protocol the name of the protocol to use
 211.659 -     * @param host the name of the host
 211.660 -       @param port the port number on the host
 211.661 -     * @param file the file on the host
 211.662 -     * @param ref the internal reference in the URL
 211.663 -     */
 211.664 -    protected void set(String protocol, String host,
 211.665 -                       int port, String file, String ref) {
 211.666 -        synchronized (this) {
 211.667 -            this.protocol = protocol;
 211.668 -            this.host = host;
 211.669 -            authority = port == -1 ? host : host + ":" + port;
 211.670 -            this.port = port;
 211.671 -            this.file = file;
 211.672 -            this.ref = ref;
 211.673 -            /* This is very important. We must recompute this after the
 211.674 -             * URL has been changed. */
 211.675 -            hashCode = -1;
 211.676 -            hostAddress = null;
 211.677 -            int q = file.lastIndexOf('?');
 211.678 -            if (q != -1) {
 211.679 -                query = file.substring(q+1);
 211.680 -                path = file.substring(0, q);
 211.681 -            } else
 211.682 -                path = file;
 211.683 -        }
 211.684 -    }
 211.685 -
 211.686 -    /**
 211.687 -     * Sets the specified 8 fields of the URL. This is not a public method so
 211.688 -     * that only URLStreamHandlers can modify URL fields. URLs are otherwise
 211.689 -     * constant.
 211.690 -     *
 211.691 -     * @param protocol the name of the protocol to use
 211.692 -     * @param host the name of the host
 211.693 -     * @param port the port number on the host
 211.694 -     * @param authority the authority part for the url
 211.695 -     * @param userInfo the username and password
 211.696 -     * @param path the file on the host
 211.697 -     * @param ref the internal reference in the URL
 211.698 -     * @param query the query part of this URL
 211.699 -     * @since 1.3
 211.700 -     */
 211.701 -    protected void set(String protocol, String host, int port,
 211.702 -                       String authority, String userInfo, String path,
 211.703 -                       String query, String ref) {
 211.704 -        synchronized (this) {
 211.705 -            this.protocol = protocol;
 211.706 -            this.host = host;
 211.707 -            this.port = port;
 211.708 -            this.file = query == null ? path : path + "?" + query;
 211.709 -            this.userInfo = userInfo;
 211.710 -            this.path = path;
 211.711 -            this.ref = ref;
 211.712 -            /* This is very important. We must recompute this after the
 211.713 -             * URL has been changed. */
 211.714 -            hashCode = -1;
 211.715 -            hostAddress = null;
 211.716 -            this.query = query;
 211.717 -            this.authority = authority;
 211.718 -        }
 211.719 -    }
 211.720 -
 211.721 -    /**
 211.722 -     * Gets the query part of this <code>URL</code>.
 211.723 -     *
 211.724 -     * @return  the query part of this <code>URL</code>,
 211.725 -     * or <CODE>null</CODE> if one does not exist
 211.726 -     * @since 1.3
 211.727 -     */
 211.728 -    public String getQuery() {
 211.729 -        return query;
 211.730 -    }
 211.731 -
 211.732 -    /**
 211.733 -     * Gets the path part of this <code>URL</code>.
 211.734 -     *
 211.735 -     * @return  the path part of this <code>URL</code>, or an
 211.736 -     * empty string if one does not exist
 211.737 -     * @since 1.3
 211.738 -     */
 211.739 -    public String getPath() {
 211.740 -        return path;
 211.741 -    }
 211.742 -
 211.743 -    /**
 211.744 -     * Gets the userInfo part of this <code>URL</code>.
 211.745 -     *
 211.746 -     * @return  the userInfo part of this <code>URL</code>, or
 211.747 -     * <CODE>null</CODE> if one does not exist
 211.748 -     * @since 1.3
 211.749 -     */
 211.750 -    public String getUserInfo() {
 211.751 -        return userInfo;
 211.752 -    }
 211.753 -
 211.754 -    /**
 211.755 -     * Gets the authority part of this <code>URL</code>.
 211.756 -     *
 211.757 -     * @return  the authority part of this <code>URL</code>
 211.758 -     * @since 1.3
 211.759 -     */
 211.760 -    public String getAuthority() {
 211.761 -        return authority;
 211.762 -    }
 211.763 -
 211.764 -    /**
 211.765 -     * Gets the port number of this <code>URL</code>.
 211.766 -     *
 211.767 -     * @return  the port number, or -1 if the port is not set
 211.768 -     */
 211.769 -    public int getPort() {
 211.770 -        return port;
 211.771 -    }
 211.772 -
 211.773 -    /**
 211.774 -     * Gets the default port number of the protocol associated
 211.775 -     * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
 211.776 -     * for the URL do not define a default port number,
 211.777 -     * then -1 is returned.
 211.778 -     *
 211.779 -     * @return  the port number
 211.780 -     * @since 1.4
 211.781 -     */
 211.782 -    public int getDefaultPort() {
 211.783 -        return handler.getDefaultPort();
 211.784 -    }
 211.785 -
 211.786 -    /**
 211.787 -     * Gets the protocol name of this <code>URL</code>.
 211.788 -     *
 211.789 -     * @return  the protocol of this <code>URL</code>.
 211.790 -     */
 211.791 -    public String getProtocol() {
 211.792 -        return protocol;
 211.793 -    }
 211.794 -
 211.795 -    /**
 211.796 -     * Gets the host name of this <code>URL</code>, if applicable.
 211.797 -     * The format of the host conforms to RFC 2732, i.e. for a
 211.798 -     * literal IPv6 address, this method will return the IPv6 address
 211.799 -     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
 211.800 -     *
 211.801 -     * @return  the host name of this <code>URL</code>.
 211.802 -     */
 211.803 -    public String getHost() {
 211.804 -        return host;
 211.805 -    }
 211.806 -
 211.807 -    /**
 211.808 -     * Gets the file name of this <code>URL</code>.
 211.809 -     * The returned file portion will be
 211.810 -     * the same as <CODE>getPath()</CODE>, plus the concatenation of
 211.811 -     * the value of <CODE>getQuery()</CODE>, if any. If there is
 211.812 -     * no query portion, this method and <CODE>getPath()</CODE> will
 211.813 -     * return identical results.
 211.814 -     *
 211.815 -     * @return  the file name of this <code>URL</code>,
 211.816 -     * or an empty string if one does not exist
 211.817 -     */
 211.818 -    public String getFile() {
 211.819 -        return file;
 211.820 -    }
 211.821 -
 211.822 -    /**
 211.823 -     * Gets the anchor (also known as the "reference") of this
 211.824 -     * <code>URL</code>.
 211.825 -     *
 211.826 -     * @return  the anchor (also known as the "reference") of this
 211.827 -     *          <code>URL</code>, or <CODE>null</CODE> if one does not exist
 211.828 -     */
 211.829 -    public String getRef() {
 211.830 -        return ref;
 211.831 -    }
 211.832 -
 211.833 -    /**
 211.834 -     * Compares this URL for equality with another object.<p>
 211.835 -     *
 211.836 -     * If the given object is not a URL then this method immediately returns
 211.837 -     * <code>false</code>.<p>
 211.838 -     *
 211.839 -     * Two URL objects are equal if they have the same protocol, reference
 211.840 -     * equivalent hosts, have the same port number on the host, and the same
 211.841 -     * file and fragment of the file.<p>
 211.842 -     *
 211.843 -     * Two hosts are considered equivalent if both host names can be resolved
 211.844 -     * into the same IP addresses; else if either host name can't be
 211.845 -     * resolved, the host names must be equal without regard to case; or both
 211.846 -     * host names equal to null.<p>
 211.847 -     *
 211.848 -     * Since hosts comparison requires name resolution, this operation is a
 211.849 -     * blocking operation. <p>
 211.850 -     *
 211.851 -     * Note: The defined behavior for <code>equals</code> is known to
 211.852 -     * be inconsistent with virtual hosting in HTTP.
 211.853 -     *
 211.854 -     * @param   obj   the URL to compare against.
 211.855 -     * @return  <code>true</code> if the objects are the same;
 211.856 -     *          <code>false</code> otherwise.
 211.857 -     */
 211.858 -    public boolean equals(Object obj) {
 211.859 -        if (!(obj instanceof URL))
 211.860 -            return false;
 211.861 -        URL u2 = (URL)obj;
 211.862 -
 211.863 -        return handler.equals(this, u2);
 211.864 -    }
 211.865 -
 211.866 -    /**
 211.867 -     * Creates an integer suitable for hash table indexing.<p>
 211.868 -     *
 211.869 -     * The hash code is based upon all the URL components relevant for URL
 211.870 -     * comparison. As such, this operation is a blocking operation.<p>
 211.871 -     *
 211.872 -     * @return  a hash code for this <code>URL</code>.
 211.873 -     */
 211.874 -    public synchronized int hashCode() {
 211.875 -        if (hashCode != -1)
 211.876 -            return hashCode;
 211.877 -
 211.878 -        hashCode = handler.hashCode(this);
 211.879 -        return hashCode;
 211.880 -    }
 211.881 -
 211.882 -    /**
 211.883 -     * Compares two URLs, excluding the fragment component.<p>
 211.884 -     *
 211.885 -     * Returns <code>true</code> if this <code>URL</code> and the
 211.886 -     * <code>other</code> argument are equal without taking the
 211.887 -     * fragment component into consideration.
 211.888 -     *
 211.889 -     * @param   other   the <code>URL</code> to compare against.
 211.890 -     * @return  <code>true</code> if they reference the same remote object;
 211.891 -     *          <code>false</code> otherwise.
 211.892 -     */
 211.893 -    public boolean sameFile(URL other) {
 211.894 -        return handler.sameFile(this, other);
 211.895 -    }
 211.896 -
 211.897 -    /**
 211.898 -     * Constructs a string representation of this <code>URL</code>. The
 211.899 -     * string is created by calling the <code>toExternalForm</code>
 211.900 -     * method of the stream protocol handler for this object.
 211.901 -     *
 211.902 -     * @return  a string representation of this object.
 211.903 -     * @see     java.net.URL#URL(java.lang.String, java.lang.String, int,
 211.904 -     *                  java.lang.String)
 211.905 -     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 211.906 -     */
 211.907 -    public String toString() {
 211.908 -        return toExternalForm();
 211.909 -    }
 211.910 -
 211.911 -    /**
 211.912 -     * Constructs a string representation of this <code>URL</code>. The
 211.913 -     * string is created by calling the <code>toExternalForm</code>
 211.914 -     * method of the stream protocol handler for this object.
 211.915 -     *
 211.916 -     * @return  a string representation of this object.
 211.917 -     * @see     java.net.URL#URL(java.lang.String, java.lang.String,
 211.918 -     *                  int, java.lang.String)
 211.919 -     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 211.920 -     */
 211.921 -    public String toExternalForm() {
 211.922 -        return handler.toExternalForm(this);
 211.923 -    }
 211.924 -
 211.925 -    /**
 211.926 -     * Returns a {@link java.net.URLConnection URLConnection} instance that
 211.927 -     * represents a connection to the remote object referred to by the
 211.928 -     * {@code URL}.
 211.929 -     *
 211.930 -     * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
 211.931 -     * created every time when invoking the
 211.932 -     * {@linkplain java.net.URLStreamHandler#openConnection(URL)
 211.933 -     * URLStreamHandler.openConnection(URL)} method of the protocol handler for
 211.934 -     * this URL.</P>
 211.935 -     *
 211.936 -     * <P>It should be noted that a URLConnection instance does not establish
 211.937 -     * the actual network connection on creation. This will happen only when
 211.938 -     * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
 211.939 -     *
 211.940 -     * <P>If for the URL's protocol (such as HTTP or JAR), there
 211.941 -     * exists a public, specialized URLConnection subclass belonging
 211.942 -     * to one of the following packages or one of their subpackages:
 211.943 -     * java.lang, java.io, java.util, java.net, the connection
 211.944 -     * returned will be of that subclass. For example, for HTTP an
 211.945 -     * HttpURLConnection will be returned, and for JAR a
 211.946 -     * JarURLConnection will be returned.</P>
 211.947 -     *
 211.948 -     * @return     a {@link java.net.URLConnection URLConnection} linking
 211.949 -     *             to the URL.
 211.950 -     * @exception  IOException  if an I/O exception occurs.
 211.951 -     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 211.952 -     *             int, java.lang.String)
 211.953 -     */
 211.954 -//    public URLConnection openConnection() throws java.io.IOException {
 211.955 -//        return handler.openConnection(this);
 211.956 -//    }
 211.957 -
 211.958 -
 211.959 -    /**
 211.960 -     * Opens a connection to this <code>URL</code> and returns an
 211.961 -     * <code>InputStream</code> for reading from that connection. This
 211.962 -     * method is a shorthand for:
 211.963 -     * <blockquote><pre>
 211.964 -     *     openConnection().getInputStream()
 211.965 -     * </pre></blockquote>
 211.966 -     *
 211.967 -     * @return     an input stream for reading from the URL connection.
 211.968 -     * @exception  IOException  if an I/O exception occurs.
 211.969 -     * @see        java.net.URL#openConnection()
 211.970 -     * @see        java.net.URLConnection#getInputStream()
 211.971 -     */
 211.972 -    public final InputStream openStream() throws java.io.IOException {
 211.973 -        if (is != null) {
 211.974 -            return is;
 211.975 -        }
 211.976 -        byte[] arr = (byte[]) getContent(new Class[] { byte[].class });
 211.977 -        if (arr == null) {
 211.978 -            throw new IOException();
 211.979 -        }
 211.980 -        return new ByteArrayInputStream(arr);
 211.981 -    }
 211.982 -
 211.983 -    /**
 211.984 -     * Gets the contents of this URL. This method is a shorthand for:
 211.985 -     * <blockquote><pre>
 211.986 -     *     openConnection().getContent()
 211.987 -     * </pre></blockquote>
 211.988 -     *
 211.989 -     * @return     the contents of this URL.
 211.990 -     * @exception  IOException  if an I/O exception occurs.
 211.991 -     * @see        java.net.URLConnection#getContent()
 211.992 -     */
 211.993 -    public final Object getContent() throws java.io.IOException {
 211.994 -        return loadText(toExternalForm());
 211.995 -    }
 211.996 -    
 211.997 -    @JavaScriptBody(args = "url", body = ""
 211.998 -        + "var request = new XMLHttpRequest();\n"
 211.999 -        + "request.open('GET', url, false);\n"
211.1000 -        + "request.send();\n"
211.1001 -        + "return request.responseText;\n"
211.1002 -    )
211.1003 -    private static native String loadText(String url) throws IOException;
211.1004 -
211.1005 -    @JavaScriptBody(args = { "url", "arr" }, body = ""
211.1006 -        + "var request = new XMLHttpRequest();\n"
211.1007 -        + "request.open('GET', url, false);\n"
211.1008 -        + "request.overrideMimeType('text\\/plain; charset=x-user-defined');\n"
211.1009 -        + "request.send();\n"
211.1010 -        + "var t = request.responseText;\n"
211.1011 -        + "for (var i = 0; i < t.length; i++) arr.push(t.charCodeAt(i) & 0xff);\n"
211.1012 -        + "return arr;\n"
211.1013 -    )
211.1014 -    private static native Object loadBytes(String url, byte[] arr) throws IOException;
211.1015 -
211.1016 -    /**
211.1017 -     * Gets the contents of this URL. This method is a shorthand for:
211.1018 -     * <blockquote><pre>
211.1019 -     *     openConnection().getContent(Class[])
211.1020 -     * </pre></blockquote>
211.1021 -     *
211.1022 -     * @param classes an array of Java types
211.1023 -     * @return     the content object of this URL that is the first match of
211.1024 -     *               the types specified in the classes array.
211.1025 -     *               null if none of the requested types are supported.
211.1026 -     * @exception  IOException  if an I/O exception occurs.
211.1027 -     * @see        java.net.URLConnection#getContent(Class[])
211.1028 -     * @since 1.3
211.1029 -     */
211.1030 -    public final Object getContent(Class[] classes)
211.1031 -    throws java.io.IOException {
211.1032 -        for (Class<?> c : classes) {
211.1033 -            if (c == String.class) {
211.1034 -                return loadText(toExternalForm());
211.1035 -            }
211.1036 -            if (c == byte[].class) {
211.1037 -                return loadBytes(toExternalForm(), new byte[0]);
211.1038 -            }
211.1039 -        }
211.1040 -        return null;
211.1041 -    }
211.1042 -
211.1043 -    static URLStreamHandler getURLStreamHandler(String protocol) {
211.1044 -        URLStreamHandler universal = new URLStreamHandler() {};
211.1045 -        return universal;
211.1046 -    }
211.1047 -
211.1048 -    private static URL findContext(URL context) throws MalformedURLException {
211.1049 -        if (context == null) {
211.1050 -            String base = findBaseURL();
211.1051 -            if (base != null) {
211.1052 -                context = new URL(null, base, false);
211.1053 -            }
211.1054 -        }
211.1055 -        return context;
211.1056 -    }
211.1057 -    
211.1058 -    @JavaScriptBody(args = {}, body = 
211.1059 -          "if (typeof window !== 'object') return null;\n"
211.1060 -        + "if (!window.location) return null;\n"
211.1061 -        + "if (!window.location.href) return null;\n"
211.1062 -        + "return window.location.href;\n"
211.1063 -    )
211.1064 -    private static native String findBaseURL();
211.1065 -}
211.1066 -class Parts {
211.1067 -    String path, query, ref;
211.1068 -
211.1069 -    Parts(String file) {
211.1070 -        int ind = file.indexOf('#');
211.1071 -        ref = ind < 0 ? null: file.substring(ind + 1);
211.1072 -        file = ind < 0 ? file: file.substring(0, ind);
211.1073 -        int q = file.lastIndexOf('?');
211.1074 -        if (q != -1) {
211.1075 -            query = file.substring(q+1);
211.1076 -            path = file.substring(0, q);
211.1077 -        } else {
211.1078 -            path = file;
211.1079 -        }
211.1080 -    }
211.1081 -
211.1082 -    String getPath() {
211.1083 -        return path;
211.1084 -    }
211.1085 -
211.1086 -    String getQuery() {
211.1087 -        return query;
211.1088 -    }
211.1089 -
211.1090 -    String getRef() {
211.1091 -        return ref;
211.1092 -    }
211.1093 -}
   212.1 --- a/emul/mini/src/main/java/java/net/URLStreamHandler.java	Mon Feb 25 19:00:08 2013 +0100
   212.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   212.3 @@ -1,568 +0,0 @@
   212.4 -/*
   212.5 - * Copyright (c) 1995, 2006, 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 -
  212.29 -package java.net;
  212.30 -
  212.31 -
  212.32 -/**
  212.33 - * The abstract class <code>URLStreamHandler</code> is the common
  212.34 - * superclass for all stream protocol handlers. A stream protocol
  212.35 - * handler knows how to make a connection for a particular protocol
  212.36 - * type, such as <code>http</code>, <code>ftp</code>, or
  212.37 - * <code>gopher</code>.
  212.38 - * <p>
  212.39 - * In most cases, an instance of a <code>URLStreamHandler</code>
  212.40 - * subclass is not created directly by an application. Rather, the
  212.41 - * first time a protocol name is encountered when constructing a
  212.42 - * <code>URL</code>, the appropriate stream protocol handler is
  212.43 - * automatically loaded.
  212.44 - *
  212.45 - * @author  James Gosling
  212.46 - * @see     java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
  212.47 - * @since   JDK1.0
  212.48 - */
  212.49 -public abstract class URLStreamHandler {
  212.50 -    /**
  212.51 -     * Opens a connection to the object referenced by the
  212.52 -     * <code>URL</code> argument.
  212.53 -     * This method should be overridden by a subclass.
  212.54 -     *
  212.55 -     * <p>If for the handler's protocol (such as HTTP or JAR), there
  212.56 -     * exists a public, specialized URLConnection subclass belonging
  212.57 -     * to one of the following packages or one of their subpackages:
  212.58 -     * java.lang, java.io, java.util, java.net, the connection
  212.59 -     * returned will be of that subclass. For example, for HTTP an
  212.60 -     * HttpURLConnection will be returned, and for JAR a
  212.61 -     * JarURLConnection will be returned.
  212.62 -     *
  212.63 -     * @param      u   the URL that this connects to.
  212.64 -     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
  212.65 -     * @exception  IOException  if an I/O error occurs while opening the
  212.66 -     *               connection.
  212.67 -     */
  212.68 -//    abstract protected URLConnection openConnection(URL u) throws IOException;
  212.69 -
  212.70 -    /**
  212.71 -     * Same as openConnection(URL), except that the connection will be
  212.72 -     * made through the specified proxy; Protocol handlers that do not
  212.73 -     * support proxying will ignore the proxy parameter and make a
  212.74 -     * normal connection.
  212.75 -     *
  212.76 -     * Calling this method preempts the system's default ProxySelector
  212.77 -     * settings.
  212.78 -     *
  212.79 -     * @param      u   the URL that this connects to.
  212.80 -     * @param      p   the proxy through which the connection will be made.
  212.81 -     *                 If direct connection is desired, Proxy.NO_PROXY
  212.82 -     *                 should be specified.
  212.83 -     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
  212.84 -     * @exception  IOException  if an I/O error occurs while opening the
  212.85 -     *               connection.
  212.86 -     * @exception  IllegalArgumentException if either u or p is null,
  212.87 -     *               or p has the wrong type.
  212.88 -     * @exception  UnsupportedOperationException if the subclass that
  212.89 -     *               implements the protocol doesn't support this method.
  212.90 -     * @since      1.5
  212.91 -     */
  212.92 -//    protected URLConnection openConnection(URL u, Proxy p) throws IOException {
  212.93 -//        throw new UnsupportedOperationException("Method not implemented.");
  212.94 -//    }
  212.95 -
  212.96 -    /**
  212.97 -     * Parses the string representation of a <code>URL</code> into a
  212.98 -     * <code>URL</code> object.
  212.99 -     * <p>
 212.100 -     * If there is any inherited context, then it has already been
 212.101 -     * copied into the <code>URL</code> argument.
 212.102 -     * <p>
 212.103 -     * The <code>parseURL</code> method of <code>URLStreamHandler</code>
 212.104 -     * parses the string representation as if it were an
 212.105 -     * <code>http</code> specification. Most URL protocol families have a
 212.106 -     * similar parsing. A stream protocol handler for a protocol that has
 212.107 -     * a different syntax must override this routine.
 212.108 -     *
 212.109 -     * @param   u       the <code>URL</code> to receive the result of parsing
 212.110 -     *                  the spec.
 212.111 -     * @param   spec    the <code>String</code> representing the URL that
 212.112 -     *                  must be parsed.
 212.113 -     * @param   start   the character index at which to begin parsing. This is
 212.114 -     *                  just past the '<code>:</code>' (if there is one) that
 212.115 -     *                  specifies the determination of the protocol name.
 212.116 -     * @param   limit   the character position to stop parsing at. This is the
 212.117 -     *                  end of the string or the position of the
 212.118 -     *                  "<code>#</code>" character, if present. All information
 212.119 -     *                  after the sharp sign indicates an anchor.
 212.120 -     */
 212.121 -    protected void parseURL(URL u, String spec, int start, int limit) {
 212.122 -        // These fields may receive context content if this was relative URL
 212.123 -        String protocol = u.getProtocol();
 212.124 -        String authority = u.getAuthority();
 212.125 -        String userInfo = u.getUserInfo();
 212.126 -        String host = u.getHost();
 212.127 -        int port = u.getPort();
 212.128 -        String path = u.getPath();
 212.129 -        String query = u.getQuery();
 212.130 -
 212.131 -        // This field has already been parsed
 212.132 -        String ref = u.getRef();
 212.133 -
 212.134 -        boolean isRelPath = false;
 212.135 -        boolean queryOnly = false;
 212.136 -
 212.137 -// FIX: should not assume query if opaque
 212.138 -        // Strip off the query part
 212.139 -        if (start < limit) {
 212.140 -            int queryStart = spec.indexOf('?');
 212.141 -            queryOnly = queryStart == start;
 212.142 -            if ((queryStart != -1) && (queryStart < limit)) {
 212.143 -                query = spec.substring(queryStart+1, limit);
 212.144 -                if (limit > queryStart)
 212.145 -                    limit = queryStart;
 212.146 -                spec = spec.substring(0, queryStart);
 212.147 -            }
 212.148 -        }
 212.149 -
 212.150 -        int i = 0;
 212.151 -        // Parse the authority part if any
 212.152 -        boolean isUNCName = (start <= limit - 4) &&
 212.153 -                        (spec.charAt(start) == '/') &&
 212.154 -                        (spec.charAt(start + 1) == '/') &&
 212.155 -                        (spec.charAt(start + 2) == '/') &&
 212.156 -                        (spec.charAt(start + 3) == '/');
 212.157 -        if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
 212.158 -            (spec.charAt(start + 1) == '/')) {
 212.159 -            start += 2;
 212.160 -            i = spec.indexOf('/', start);
 212.161 -            if (i < 0) {
 212.162 -                i = spec.indexOf('?', start);
 212.163 -                if (i < 0)
 212.164 -                    i = limit;
 212.165 -            }
 212.166 -
 212.167 -            host = authority = spec.substring(start, i);
 212.168 -
 212.169 -            int ind = authority.indexOf('@');
 212.170 -            if (ind != -1) {
 212.171 -                userInfo = authority.substring(0, ind);
 212.172 -                host = authority.substring(ind+1);
 212.173 -            } else {
 212.174 -                userInfo = null;
 212.175 -            }
 212.176 -            if (host != null) {
 212.177 -                // If the host is surrounded by [ and ] then its an IPv6
 212.178 -                // literal address as specified in RFC2732
 212.179 -                if (host.length()>0 && (host.charAt(0) == '[')) {
 212.180 -                    if ((ind = host.indexOf(']')) > 2) {
 212.181 -
 212.182 -                        String nhost = host ;
 212.183 -                        host = nhost.substring(0,ind+1);
 212.184 -//                        if (!IPAddressUtil.
 212.185 -//                            isIPv6LiteralAddress(host.substring(1, ind))) {
 212.186 -//                            throw new IllegalArgumentException(
 212.187 -//                                "Invalid host: "+ host);
 212.188 -//                        }
 212.189 -
 212.190 -                        port = -1 ;
 212.191 -                        if (nhost.length() > ind+1) {
 212.192 -                            if (nhost.charAt(ind+1) == ':') {
 212.193 -                                ++ind ;
 212.194 -                                // port can be null according to RFC2396
 212.195 -                                if (nhost.length() > (ind + 1)) {
 212.196 -                                    port = Integer.parseInt(nhost.substring(ind+1));
 212.197 -                                }
 212.198 -                            } else {
 212.199 -                                throw new IllegalArgumentException(
 212.200 -                                    "Invalid authority field: " + authority);
 212.201 -                            }
 212.202 -                        }
 212.203 -                    } else {
 212.204 -                        throw new IllegalArgumentException(
 212.205 -                            "Invalid authority field: " + authority);
 212.206 -                    }
 212.207 -                } else {
 212.208 -                    ind = host.indexOf(':');
 212.209 -                    port = -1;
 212.210 -                    if (ind >= 0) {
 212.211 -                        // port can be null according to RFC2396
 212.212 -                        if (host.length() > (ind + 1)) {
 212.213 -                            port = Integer.parseInt(host.substring(ind + 1));
 212.214 -                        }
 212.215 -                        host = host.substring(0, ind);
 212.216 -                    }
 212.217 -                }
 212.218 -            } else {
 212.219 -                host = "";
 212.220 -            }
 212.221 -            if (port < -1)
 212.222 -                throw new IllegalArgumentException("Invalid port number :" +
 212.223 -                                                   port);
 212.224 -            start = i;
 212.225 -            // If the authority is defined then the path is defined by the
 212.226 -            // spec only; See RFC 2396 Section 5.2.4.
 212.227 -            if (authority != null && authority.length() > 0)
 212.228 -                path = "";
 212.229 -        }
 212.230 -
 212.231 -        if (host == null) {
 212.232 -            host = "";
 212.233 -        }
 212.234 -
 212.235 -        // Parse the file path if any
 212.236 -        if (start < limit) {
 212.237 -            if (spec.charAt(start) == '/') {
 212.238 -                path = spec.substring(start, limit);
 212.239 -            } else if (path != null && path.length() > 0) {
 212.240 -                isRelPath = true;
 212.241 -                int ind = path.lastIndexOf('/');
 212.242 -                String seperator = "";
 212.243 -                if (ind == -1 && authority != null)
 212.244 -                    seperator = "/";
 212.245 -                path = path.substring(0, ind + 1) + seperator +
 212.246 -                         spec.substring(start, limit);
 212.247 -
 212.248 -            } else {
 212.249 -                String seperator = (authority != null) ? "/" : "";
 212.250 -                path = seperator + spec.substring(start, limit);
 212.251 -            }
 212.252 -        } else if (queryOnly && path != null) {
 212.253 -            int ind = path.lastIndexOf('/');
 212.254 -            if (ind < 0)
 212.255 -                ind = 0;
 212.256 -            path = path.substring(0, ind) + "/";
 212.257 -        }
 212.258 -        if (path == null)
 212.259 -            path = "";
 212.260 -
 212.261 -        if (isRelPath) {
 212.262 -            // Remove embedded /./
 212.263 -            while ((i = path.indexOf("/./")) >= 0) {
 212.264 -                path = path.substring(0, i) + path.substring(i + 2);
 212.265 -            }
 212.266 -            // Remove embedded /../ if possible
 212.267 -            i = 0;
 212.268 -            while ((i = path.indexOf("/../", i)) >= 0) {
 212.269 -                /*
 212.270 -                 * A "/../" will cancel the previous segment and itself,
 212.271 -                 * unless that segment is a "/../" itself
 212.272 -                 * i.e. "/a/b/../c" becomes "/a/c"
 212.273 -                 * but "/../../a" should stay unchanged
 212.274 -                 */
 212.275 -                if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
 212.276 -                    (path.indexOf("/../", limit) != 0)) {
 212.277 -                    path = path.substring(0, limit) + path.substring(i + 3);
 212.278 -                    i = 0;
 212.279 -                } else {
 212.280 -                    i = i + 3;
 212.281 -                }
 212.282 -            }
 212.283 -            // Remove trailing .. if possible
 212.284 -            while (path.endsWith("/..")) {
 212.285 -                i = path.indexOf("/..");
 212.286 -                if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
 212.287 -                    path = path.substring(0, limit+1);
 212.288 -                } else {
 212.289 -                    break;
 212.290 -                }
 212.291 -            }
 212.292 -            // Remove starting .
 212.293 -            if (path.startsWith("./") && path.length() > 2)
 212.294 -                path = path.substring(2);
 212.295 -
 212.296 -            // Remove trailing .
 212.297 -            if (path.endsWith("/."))
 212.298 -                path = path.substring(0, path.length() -1);
 212.299 -        }
 212.300 -
 212.301 -        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
 212.302 -    }
 212.303 -
 212.304 -    /**
 212.305 -     * Returns the default port for a URL parsed by this handler. This method
 212.306 -     * is meant to be overidden by handlers with default port numbers.
 212.307 -     * @return the default port for a <code>URL</code> parsed by this handler.
 212.308 -     * @since 1.3
 212.309 -     */
 212.310 -    protected int getDefaultPort() {
 212.311 -        return -1;
 212.312 -    }
 212.313 -
 212.314 -    /**
 212.315 -     * Provides the default equals calculation. May be overidden by handlers
 212.316 -     * for other protocols that have different requirements for equals().
 212.317 -     * This method requires that none of its arguments is null. This is
 212.318 -     * guaranteed by the fact that it is only called by java.net.URL class.
 212.319 -     * @param u1 a URL object
 212.320 -     * @param u2 a URL object
 212.321 -     * @return <tt>true</tt> if the two urls are
 212.322 -     * considered equal, ie. they refer to the same
 212.323 -     * fragment in the same file.
 212.324 -     * @since 1.3
 212.325 -     */
 212.326 -    protected boolean equals(URL u1, URL u2) {
 212.327 -        String ref1 = u1.getRef();
 212.328 -        String ref2 = u2.getRef();
 212.329 -        return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
 212.330 -               sameFile(u1, u2);
 212.331 -    }
 212.332 -
 212.333 -    /**
 212.334 -     * Provides the default hash calculation. May be overidden by handlers for
 212.335 -     * other protocols that have different requirements for hashCode
 212.336 -     * calculation.
 212.337 -     * @param u a URL object
 212.338 -     * @return an <tt>int</tt> suitable for hash table indexing
 212.339 -     * @since 1.3
 212.340 -     */
 212.341 -    protected int hashCode(URL u) {
 212.342 -        int h = 0;
 212.343 -
 212.344 -        // Generate the protocol part.
 212.345 -        String protocol = u.getProtocol();
 212.346 -        if (protocol != null)
 212.347 -            h += protocol.hashCode();
 212.348 -
 212.349 -        // Generate the host part.
 212.350 -        Object addr = getHostAddress(u);
 212.351 -        if (addr != null) {
 212.352 -            h += addr.hashCode();
 212.353 -        } else {
 212.354 -            String host = u.getHost();
 212.355 -            if (host != null)
 212.356 -                h += host.toLowerCase().hashCode();
 212.357 -        }
 212.358 -
 212.359 -        // Generate the file part.
 212.360 -        String file = u.getFile();
 212.361 -        if (file != null)
 212.362 -            h += file.hashCode();
 212.363 -
 212.364 -        // Generate the port part.
 212.365 -        if (u.getPort() == -1)
 212.366 -            h += getDefaultPort();
 212.367 -        else
 212.368 -            h += u.getPort();
 212.369 -
 212.370 -        // Generate the ref part.
 212.371 -        String ref = u.getRef();
 212.372 -        if (ref != null)
 212.373 -            h += ref.hashCode();
 212.374 -
 212.375 -        return h;
 212.376 -    }
 212.377 -
 212.378 -    /**
 212.379 -     * Compare two urls to see whether they refer to the same file,
 212.380 -     * i.e., having the same protocol, host, port, and path.
 212.381 -     * This method requires that none of its arguments is null. This is
 212.382 -     * guaranteed by the fact that it is only called indirectly
 212.383 -     * by java.net.URL class.
 212.384 -     * @param u1 a URL object
 212.385 -     * @param u2 a URL object
 212.386 -     * @return true if u1 and u2 refer to the same file
 212.387 -     * @since 1.3
 212.388 -     */
 212.389 -    protected boolean sameFile(URL u1, URL u2) {
 212.390 -        // Compare the protocols.
 212.391 -        if (!((u1.getProtocol() == u2.getProtocol()) ||
 212.392 -              (u1.getProtocol() != null &&
 212.393 -               u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
 212.394 -            return false;
 212.395 -
 212.396 -        // Compare the files.
 212.397 -        if (!(u1.getFile() == u2.getFile() ||
 212.398 -              (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
 212.399 -            return false;
 212.400 -
 212.401 -        // Compare the ports.
 212.402 -        int port1, port2;
 212.403 -        port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
 212.404 -        port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
 212.405 -        if (port1 != port2)
 212.406 -            return false;
 212.407 -
 212.408 -        // Compare the hosts.
 212.409 -        if (!hostsEqual(u1, u2))
 212.410 -            return false;
 212.411 -
 212.412 -        return true;
 212.413 -    }
 212.414 -
 212.415 -    /**
 212.416 -     * Get the IP address of our host. An empty host field or a DNS failure
 212.417 -     * will result in a null return.
 212.418 -     *
 212.419 -     * @param u a URL object
 212.420 -     * @return an <code>InetAddress</code> representing the host
 212.421 -     * IP address.
 212.422 -     * @since 1.3
 212.423 -     */
 212.424 -    private synchronized Object getHostAddress(URL u) {
 212.425 -        return u.hostAddress;
 212.426 -    }
 212.427 -
 212.428 -    /**
 212.429 -     * Compares the host components of two URLs.
 212.430 -     * @param u1 the URL of the first host to compare
 212.431 -     * @param u2 the URL of the second host to compare
 212.432 -     * @return  <tt>true</tt> if and only if they
 212.433 -     * are equal, <tt>false</tt> otherwise.
 212.434 -     * @since 1.3
 212.435 -     */
 212.436 -    protected boolean hostsEqual(URL u1, URL u2) {
 212.437 -        Object a1 = getHostAddress(u1);
 212.438 -        Object a2 = getHostAddress(u2);
 212.439 -        // if we have internet address for both, compare them
 212.440 -        if (a1 != null && a2 != null) {
 212.441 -            return a1.equals(a2);
 212.442 -        // else, if both have host names, compare them
 212.443 -        } else if (u1.getHost() != null && u2.getHost() != null)
 212.444 -            return u1.getHost().equalsIgnoreCase(u2.getHost());
 212.445 -         else
 212.446 -            return u1.getHost() == null && u2.getHost() == null;
 212.447 -    }
 212.448 -
 212.449 -    /**
 212.450 -     * Converts a <code>URL</code> of a specific protocol to a
 212.451 -     * <code>String</code>.
 212.452 -     *
 212.453 -     * @param   u   the URL.
 212.454 -     * @return  a string representation of the <code>URL</code> argument.
 212.455 -     */
 212.456 -    protected String toExternalForm(URL u) {
 212.457 -
 212.458 -        // pre-compute length of StringBuffer
 212.459 -        int len = u.getProtocol().length() + 1;
 212.460 -        if (u.getAuthority() != null && u.getAuthority().length() > 0)
 212.461 -            len += 2 + u.getAuthority().length();
 212.462 -        if (u.getPath() != null) {
 212.463 -            len += u.getPath().length();
 212.464 -        }
 212.465 -        if (u.getQuery() != null) {
 212.466 -            len += 1 + u.getQuery().length();
 212.467 -        }
 212.468 -        if (u.getRef() != null)
 212.469 -            len += 1 + u.getRef().length();
 212.470 -
 212.471 -        StringBuffer result = new StringBuffer(len);
 212.472 -        result.append(u.getProtocol());
 212.473 -        result.append(":");
 212.474 -        if (u.getAuthority() != null && u.getAuthority().length() > 0) {
 212.475 -            result.append("//");
 212.476 -            result.append(u.getAuthority());
 212.477 -        }
 212.478 -        if (u.getPath() != null) {
 212.479 -            result.append(u.getPath());
 212.480 -        }
 212.481 -        if (u.getQuery() != null) {
 212.482 -            result.append('?');
 212.483 -            result.append(u.getQuery());
 212.484 -        }
 212.485 -        if (u.getRef() != null) {
 212.486 -            result.append("#");
 212.487 -            result.append(u.getRef());
 212.488 -        }
 212.489 -        return result.toString();
 212.490 -    }
 212.491 -
 212.492 -    /**
 212.493 -     * Sets the fields of the <code>URL</code> argument to the indicated values.
 212.494 -     * Only classes derived from URLStreamHandler are supposed to be able
 212.495 -     * to call the set method on a URL.
 212.496 -     *
 212.497 -     * @param   u         the URL to modify.
 212.498 -     * @param   protocol  the protocol name.
 212.499 -     * @param   host      the remote host value for the URL.
 212.500 -     * @param   port      the port on the remote machine.
 212.501 -     * @param   authority the authority part for the URL.
 212.502 -     * @param   userInfo the userInfo part of the URL.
 212.503 -     * @param   path      the path component of the URL.
 212.504 -     * @param   query     the query part for the URL.
 212.505 -     * @param   ref       the reference.
 212.506 -     * @exception       SecurityException       if the protocol handler of the URL is
 212.507 -     *                                  different from this one
 212.508 -     * @see     java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
 212.509 -     * @since 1.3
 212.510 -     */
 212.511 -       protected void setURL(URL u, String protocol, String host, int port,
 212.512 -                             String authority, String userInfo, String path,
 212.513 -                             String query, String ref) {
 212.514 -        if (this != u.handler) {
 212.515 -            throw new SecurityException("handler for url different from " +
 212.516 -                                        "this handler");
 212.517 -        }
 212.518 -        // ensure that no one can reset the protocol on a given URL.
 212.519 -        u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
 212.520 -    }
 212.521 -
 212.522 -    /**
 212.523 -     * Sets the fields of the <code>URL</code> argument to the indicated values.
 212.524 -     * Only classes derived from URLStreamHandler are supposed to be able
 212.525 -     * to call the set method on a URL.
 212.526 -     *
 212.527 -     * @param   u         the URL to modify.
 212.528 -     * @param   protocol  the protocol name. This value is ignored since 1.2.
 212.529 -     * @param   host      the remote host value for the URL.
 212.530 -     * @param   port      the port on the remote machine.
 212.531 -     * @param   file      the file.
 212.532 -     * @param   ref       the reference.
 212.533 -     * @exception       SecurityException       if the protocol handler of the URL is
 212.534 -     *                                  different from this one
 212.535 -     * @deprecated Use setURL(URL, String, String, int, String, String, String,
 212.536 -     *             String);
 212.537 -     */
 212.538 -    @Deprecated
 212.539 -    protected void setURL(URL u, String protocol, String host, int port,
 212.540 -                          String file, String ref) {
 212.541 -        /*
 212.542 -         * Only old URL handlers call this, so assume that the host
 212.543 -         * field might contain "user:passwd@host". Fix as necessary.
 212.544 -         */
 212.545 -        String authority = null;
 212.546 -        String userInfo = null;
 212.547 -        if (host != null && host.length() != 0) {
 212.548 -            authority = (port == -1) ? host : host + ":" + port;
 212.549 -            int at = host.lastIndexOf('@');
 212.550 -            if (at != -1) {
 212.551 -                userInfo = host.substring(0, at);
 212.552 -                host = host.substring(at+1);
 212.553 -            }
 212.554 -        }
 212.555 -
 212.556 -        /*
 212.557 -         * Assume file might contain query part. Fix as necessary.
 212.558 -         */
 212.559 -        String path = null;
 212.560 -        String query = null;
 212.561 -        if (file != null) {
 212.562 -            int q = file.lastIndexOf('?');
 212.563 -            if (q != -1) {
 212.564 -                query = file.substring(q+1);
 212.565 -                path = file.substring(0, q);
 212.566 -            } else
 212.567 -                path = file;
 212.568 -        }
 212.569 -        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
 212.570 -    }
 212.571 -}
   213.1 --- a/emul/mini/src/main/java/java/util/Comparator.java	Mon Feb 25 19:00:08 2013 +0100
   213.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   213.3 @@ -1,168 +0,0 @@
   213.4 -/*
   213.5 - * Copyright (c) 1997, 2007, 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.util;
  213.30 -
  213.31 -/**
  213.32 - * A comparison function, which imposes a <i>total ordering</i> on some
  213.33 - * collection of objects.  Comparators can be passed to a sort method (such
  213.34 - * as {@link Collections#sort(List,Comparator) Collections.sort} or {@link
  213.35 - * Arrays#sort(Object[],Comparator) Arrays.sort}) to allow precise control
  213.36 - * over the sort order.  Comparators can also be used to control the order of
  213.37 - * certain data structures (such as {@link SortedSet sorted sets} or {@link
  213.38 - * SortedMap sorted maps}), or to provide an ordering for collections of
  213.39 - * objects that don't have a {@link Comparable natural ordering}.<p>
  213.40 - *
  213.41 - * The ordering imposed by a comparator <tt>c</tt> on a set of elements
  213.42 - * <tt>S</tt> is said to be <i>consistent with equals</i> if and only if
  213.43 - * <tt>c.compare(e1, e2)==0</tt> has the same boolean value as
  213.44 - * <tt>e1.equals(e2)</tt> for every <tt>e1</tt> and <tt>e2</tt> in
  213.45 - * <tt>S</tt>.<p>
  213.46 - *
  213.47 - * Caution should be exercised when using a comparator capable of imposing an
  213.48 - * ordering inconsistent with equals to order a sorted set (or sorted map).
  213.49 - * Suppose a sorted set (or sorted map) with an explicit comparator <tt>c</tt>
  213.50 - * is used with elements (or keys) drawn from a set <tt>S</tt>.  If the
  213.51 - * ordering imposed by <tt>c</tt> on <tt>S</tt> is inconsistent with equals,
  213.52 - * the sorted set (or sorted map) will behave "strangely."  In particular the
  213.53 - * sorted set (or sorted map) will violate the general contract for set (or
  213.54 - * map), which is defined in terms of <tt>equals</tt>.<p>
  213.55 - *
  213.56 - * For example, suppose one adds two elements {@code a} and {@code b} such that
  213.57 - * {@code (a.equals(b) && c.compare(a, b) != 0)}
  213.58 - * to an empty {@code TreeSet} with comparator {@code c}.
  213.59 - * The second {@code add} operation will return
  213.60 - * true (and the size of the tree set will increase) because {@code a} and
  213.61 - * {@code b} are not equivalent from the tree set's perspective, even though
  213.62 - * this is contrary to the specification of the
  213.63 - * {@link Set#add Set.add} method.<p>
  213.64 - *
  213.65 - * Note: It is generally a good idea for comparators to also implement
  213.66 - * <tt>java.io.Serializable</tt>, as they may be used as ordering methods in
  213.67 - * serializable data structures (like {@link TreeSet}, {@link TreeMap}).  In
  213.68 - * order for the data structure to serialize successfully, the comparator (if
  213.69 - * provided) must implement <tt>Serializable</tt>.<p>
  213.70 - *
  213.71 - * For the mathematically inclined, the <i>relation</i> that defines the
  213.72 - * <i>imposed ordering</i> that a given comparator <tt>c</tt> imposes on a
  213.73 - * given set of objects <tt>S</tt> is:<pre>
  213.74 - *       {(x, y) such that c.compare(x, y) &lt;= 0}.
  213.75 - * </pre> The <i>quotient</i> for this total order is:<pre>
  213.76 - *       {(x, y) such that c.compare(x, y) == 0}.
  213.77 - * </pre>
  213.78 - *
  213.79 - * It follows immediately from the contract for <tt>compare</tt> that the
  213.80 - * quotient is an <i>equivalence relation</i> on <tt>S</tt>, and that the
  213.81 - * imposed ordering is a <i>total order</i> on <tt>S</tt>.  When we say that
  213.82 - * the ordering imposed by <tt>c</tt> on <tt>S</tt> is <i>consistent with
  213.83 - * equals</i>, we mean that the quotient for the ordering is the equivalence
  213.84 - * relation defined by the objects' {@link Object#equals(Object)
  213.85 - * equals(Object)} method(s):<pre>
  213.86 - *     {(x, y) such that x.equals(y)}. </pre>
  213.87 - *
  213.88 - * <p>Unlike {@code Comparable}, a comparator may optionally permit
  213.89 - * comparison of null arguments, while maintaining the requirements for
  213.90 - * an equivalence relation.
  213.91 - *
  213.92 - * <p>This interface is a member of the
  213.93 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  213.94 - * Java Collections Framework</a>.
  213.95 - *
  213.96 - * @param <T> the type of objects that may be compared by this comparator
  213.97 - *
  213.98 - * @author  Josh Bloch
  213.99 - * @author  Neal Gafter
 213.100 - * @see Comparable
 213.101 - * @see java.io.Serializable
 213.102 - * @since 1.2
 213.103 - */
 213.104 -
 213.105 -public interface Comparator<T> {
 213.106 -    /**
 213.107 -     * Compares its two arguments for order.  Returns a negative integer,
 213.108 -     * zero, or a positive integer as the first argument is less than, equal
 213.109 -     * to, or greater than the second.<p>
 213.110 -     *
 213.111 -     * In the foregoing description, the notation
 213.112 -     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 213.113 -     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 213.114 -     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 213.115 -     * <i>expression</i> is negative, zero or positive.<p>
 213.116 -     *
 213.117 -     * The implementor must ensure that <tt>sgn(compare(x, y)) ==
 213.118 -     * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 213.119 -     * implies that <tt>compare(x, y)</tt> must throw an exception if and only
 213.120 -     * if <tt>compare(y, x)</tt> throws an exception.)<p>
 213.121 -     *
 213.122 -     * The implementor must also ensure that the relation is transitive:
 213.123 -     * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
 213.124 -     * <tt>compare(x, z)&gt;0</tt>.<p>
 213.125 -     *
 213.126 -     * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
 213.127 -     * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
 213.128 -     * <tt>z</tt>.<p>
 213.129 -     *
 213.130 -     * It is generally the case, but <i>not</i> strictly required that
 213.131 -     * <tt>(compare(x, y)==0) == (x.equals(y))</tt>.  Generally speaking,
 213.132 -     * any comparator that violates this condition should clearly indicate
 213.133 -     * this fact.  The recommended language is "Note: this comparator
 213.134 -     * imposes orderings that are inconsistent with equals."
 213.135 -     *
 213.136 -     * @param o1 the first object to be compared.
 213.137 -     * @param o2 the second object to be compared.
 213.138 -     * @return a negative integer, zero, or a positive integer as the
 213.139 -     *         first argument is less than, equal to, or greater than the
 213.140 -     *         second.
 213.141 -     * @throws NullPointerException if an argument is null and this
 213.142 -     *         comparator does not permit null arguments
 213.143 -     * @throws ClassCastException if the arguments' types prevent them from
 213.144 -     *         being compared by this comparator.
 213.145 -     */
 213.146 -    int compare(T o1, T o2);
 213.147 -
 213.148 -    /**
 213.149 -     * Indicates whether some other object is &quot;equal to&quot; this
 213.150 -     * comparator.  This method must obey the general contract of
 213.151 -     * {@link Object#equals(Object)}.  Additionally, this method can return
 213.152 -     * <tt>true</tt> <i>only</i> if the specified object is also a comparator
 213.153 -     * and it imposes the same ordering as this comparator.  Thus,
 213.154 -     * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
 213.155 -     * o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
 213.156 -     * <tt>o1</tt> and <tt>o2</tt>.<p>
 213.157 -     *
 213.158 -     * Note that it is <i>always</i> safe <i>not</i> to override
 213.159 -     * <tt>Object.equals(Object)</tt>.  However, overriding this method may,
 213.160 -     * in some cases, improve performance by allowing programs to determine
 213.161 -     * that two distinct comparators impose the same order.
 213.162 -     *
 213.163 -     * @param   obj   the reference object with which to compare.
 213.164 -     * @return  <code>true</code> only if the specified object is also
 213.165 -     *          a comparator and it imposes the same ordering as this
 213.166 -     *          comparator.
 213.167 -     * @see Object#equals(Object)
 213.168 -     * @see Object#hashCode()
 213.169 -     */
 213.170 -    boolean equals(Object obj);
 213.171 -}
   214.1 --- a/emul/mini/src/main/java/java/util/Enumeration.java	Mon Feb 25 19:00:08 2013 +0100
   214.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   214.3 @@ -1,79 +0,0 @@
   214.4 -/*
   214.5 - * Copyright (c) 1994, 2005, 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.util;
  214.30 -
  214.31 -/**
  214.32 - * An object that implements the Enumeration interface generates a
  214.33 - * series of elements, one at a time. Successive calls to the
  214.34 - * <code>nextElement</code> method return successive elements of the
  214.35 - * series.
  214.36 - * <p>
  214.37 - * For example, to print all elements of a <tt>Vector&lt;E&gt;</tt> <i>v</i>:
  214.38 - * <pre>
  214.39 - *   for (Enumeration&lt;E&gt; e = v.elements(); e.hasMoreElements();)
  214.40 - *       System.out.println(e.nextElement());</pre>
  214.41 - * <p>
  214.42 - * Methods are provided to enumerate through the elements of a
  214.43 - * vector, the keys of a hashtable, and the values in a hashtable.
  214.44 - * Enumerations are also used to specify the input streams to a
  214.45 - * <code>SequenceInputStream</code>.
  214.46 - * <p>
  214.47 - * NOTE: The functionality of this interface is duplicated by the Iterator
  214.48 - * interface.  In addition, Iterator adds an optional remove operation, and
  214.49 - * has shorter method names.  New implementations should consider using
  214.50 - * Iterator in preference to Enumeration.
  214.51 - *
  214.52 - * @see     java.util.Iterator
  214.53 - * @see     java.io.SequenceInputStream
  214.54 - * @see     java.util.Enumeration#nextElement()
  214.55 - * @see     java.util.Hashtable
  214.56 - * @see     java.util.Hashtable#elements()
  214.57 - * @see     java.util.Hashtable#keys()
  214.58 - * @see     java.util.Vector
  214.59 - * @see     java.util.Vector#elements()
  214.60 - *
  214.61 - * @author  Lee Boynton
  214.62 - * @since   JDK1.0
  214.63 - */
  214.64 -public interface Enumeration<E> {
  214.65 -    /**
  214.66 -     * Tests if this enumeration contains more elements.
  214.67 -     *
  214.68 -     * @return  <code>true</code> if and only if this enumeration object
  214.69 -     *           contains at least one more element to provide;
  214.70 -     *          <code>false</code> otherwise.
  214.71 -     */
  214.72 -    boolean hasMoreElements();
  214.73 -
  214.74 -    /**
  214.75 -     * Returns the next element of this enumeration if this enumeration
  214.76 -     * object has at least one more element to provide.
  214.77 -     *
  214.78 -     * @return     the next element of this enumeration.
  214.79 -     * @exception  NoSuchElementException  if no more elements exist.
  214.80 -     */
  214.81 -    E nextElement();
  214.82 -}
   215.1 --- a/emul/mini/src/main/java/java/util/NoSuchElementException.java	Mon Feb 25 19:00:08 2013 +0100
   215.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   215.3 @@ -1,60 +0,0 @@
   215.4 -/*
   215.5 - * Copyright (c) 1994, 2008, 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.util;
  215.30 -
  215.31 -/**
  215.32 - * Thrown by the <code>nextElement</code> method of an
  215.33 - * <code>Enumeration</code> to indicate that there are no more
  215.34 - * elements in the enumeration.
  215.35 - *
  215.36 - * @author  unascribed
  215.37 - * @see     java.util.Enumeration
  215.38 - * @see     java.util.Enumeration#nextElement()
  215.39 - * @since   JDK1.0
  215.40 - */
  215.41 -public
  215.42 -class NoSuchElementException extends RuntimeException {
  215.43 -    private static final long serialVersionUID = 6769829250639411880L;
  215.44 -
  215.45 -    /**
  215.46 -     * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
  215.47 -     * as its error message string.
  215.48 -     */
  215.49 -    public NoSuchElementException() {
  215.50 -        super();
  215.51 -    }
  215.52 -
  215.53 -    /**
  215.54 -     * Constructs a <code>NoSuchElementException</code>, saving a reference
  215.55 -     * to the error message string <tt>s</tt> for later retrieval by the
  215.56 -     * <tt>getMessage</tt> method.
  215.57 -     *
  215.58 -     * @param   s   the detail message.
  215.59 -     */
  215.60 -    public NoSuchElementException(String s) {
  215.61 -        super(s);
  215.62 -    }
  215.63 -}
   216.1 --- a/emul/mini/src/main/java/java/util/zip/Adler32.java	Mon Feb 25 19:00:08 2013 +0100
   216.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   216.3 @@ -1,205 +0,0 @@
   216.4 -/* Adler32.java - Computes Adler32 data checksum of a data stream
   216.5 -   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
   216.6 -
   216.7 -This file is part of GNU Classpath.
   216.8 -
   216.9 -GNU Classpath is free software; you can redistribute it and/or modify
  216.10 -it under the terms of the GNU General Public License as published by
  216.11 -the Free Software Foundation; either version 2, or (at your option)
  216.12 -any later version.
  216.13 -
  216.14 -GNU Classpath is distributed in the hope that it will be useful, but
  216.15 -WITHOUT ANY WARRANTY; without even the implied warranty of
  216.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  216.17 -General Public License for more details.
  216.18 -
  216.19 -You should have received a copy of the GNU General Public License
  216.20 -along with GNU Classpath; see the file COPYING.  If not, write to the
  216.21 -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  216.22 -02111-1307 USA.
  216.23 -
  216.24 -Linking this library statically or dynamically with other modules is
  216.25 -making a combined work based on this library.  Thus, the terms and
  216.26 -conditions of the GNU General Public License cover the whole
  216.27 -combination.
  216.28 -
  216.29 -As a special exception, the copyright holders of this library give you
  216.30 -permission to link this library with independent modules to produce an
  216.31 -executable, regardless of the license terms of these independent
  216.32 -modules, and to copy and distribute the resulting executable under
  216.33 -terms of your choice, provided that you also meet, for each linked
  216.34 -independent module, the terms and conditions of the license of that
  216.35 -module.  An independent module is a module which is not derived from
  216.36 -or based on this library.  If you modify this library, you may extend
  216.37 -this exception to your version of the library, but you are not
  216.38 -obligated to do so.  If you do not wish to do so, delete this
  216.39 -exception statement from your version. */
  216.40 -
  216.41 -package java.util.zip;
  216.42 -
  216.43 -/*
  216.44 - * Written using on-line Java Platform 1.2 API Specification, as well
  216.45 - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
  216.46 - * The actual Adler32 algorithm is taken from RFC 1950.
  216.47 - * Status:  Believed complete and correct.
  216.48 - */
  216.49 -
  216.50 -/**
  216.51 - * Computes Adler32 checksum for a stream of data. An Adler32 
  216.52 - * checksum is not as reliable as a CRC32 checksum, but a lot faster to 
  216.53 - * compute.
  216.54 - *<p>
  216.55 - * The specification for Adler32 may be found in RFC 1950.
  216.56 - * (ZLIB Compressed Data Format Specification version 3.3)
  216.57 - *<p>
  216.58 - *<p>
  216.59 - * From that document:
  216.60 - *<p>
  216.61 - *      "ADLER32 (Adler-32 checksum)
  216.62 - *       This contains a checksum value of the uncompressed data
  216.63 - *       (excluding any dictionary data) computed according to Adler-32
  216.64 - *       algorithm. This algorithm is a 32-bit extension and improvement
  216.65 - *       of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
  216.66 - *       standard. 
  216.67 - *<p>
  216.68 - *       Adler-32 is composed of two sums accumulated per byte: s1 is
  216.69 - *       the sum of all bytes, s2 is the sum of all s1 values. Both sums
  216.70 - *       are done modulo 65521. s1 is initialized to 1, s2 to zero.  The
  216.71 - *       Adler-32 checksum is stored as s2*65536 + s1 in most-
  216.72 - *       significant-byte first (network) order."
  216.73 - *<p>
  216.74 - * "8.2. The Adler-32 algorithm
  216.75 - *<p>
  216.76 - *    The Adler-32 algorithm is much faster than the CRC32 algorithm yet
  216.77 - *    still provides an extremely low probability of undetected errors.
  216.78 - *<p>
  216.79 - *    The modulo on unsigned long accumulators can be delayed for 5552
  216.80 - *    bytes, so the modulo operation time is negligible.  If the bytes
  216.81 - *    are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
  216.82 - *    and order sensitive, unlike the first sum, which is just a
  216.83 - *    checksum.  That 65521 is prime is important to avoid a possible
  216.84 - *    large class of two-byte errors that leave the check unchanged.
  216.85 - *    (The Fletcher checksum uses 255, which is not prime and which also
  216.86 - *    makes the Fletcher check insensitive to single byte changes 0 <->
  216.87 - *    255.)
  216.88 - *<p>
  216.89 - *    The sum s1 is initialized to 1 instead of zero to make the length
  216.90 - *    of the sequence part of s2, so that the length does not have to be
  216.91 - *   checked separately. (Any sequence of zeroes has a Fletcher
  216.92 - *    checksum of zero.)"
  216.93 - *
  216.94 - * @author John Leuner, Per Bothner
  216.95 - * @since JDK 1.1
  216.96 - *
  216.97 - * @see InflaterInputStream
  216.98 - * @see DeflaterOutputStream
  216.99 - */
 216.100 -public class Adler32 implements Checksum
 216.101 -{
 216.102 -
 216.103 -  /** largest prime smaller than 65536 */
 216.104 -  private static final int BASE = 65521;
 216.105 -
 216.106 -  private int checksum; //we do all in int.
 216.107 -
 216.108 -  //Note that java doesn't have unsigned integers,
 216.109 -  //so we have to be careful with what arithmetic 
 216.110 -  //we do. We return the checksum as a long to 
 216.111 -  //avoid sign confusion.
 216.112 -
 216.113 -  /**
 216.114 -   * Creates a new instance of the <code>Adler32</code> class. 
 216.115 -   * The checksum starts off with a value of 1. 
 216.116 -   */
 216.117 -  public Adler32 ()
 216.118 -  {
 216.119 -    reset();
 216.120 -  }
 216.121 -
 216.122 -  /**
 216.123 -   * Resets the Adler32 checksum to the initial value.
 216.124 -   */
 216.125 -  public void reset () 
 216.126 -  {
 216.127 -    checksum = 1; //Initialize to 1    
 216.128 -  }
 216.129 -
 216.130 -  /**
 216.131 -   * Updates the checksum with the byte b. 
 216.132 -   *
 216.133 -   * @param bval the data value to add. The high byte of the int is ignored.
 216.134 -   */
 216.135 -  public void update (int bval)
 216.136 -  {
 216.137 -    //We could make a length 1 byte array and call update again, but I
 216.138 -    //would rather not have that overhead
 216.139 -    int s1 = checksum & 0xffff;
 216.140 -    int s2 = checksum >>> 16;
 216.141 -    
 216.142 -    s1 = (s1 + (bval & 0xFF)) % BASE;
 216.143 -    s2 = (s1 + s2) % BASE;
 216.144 -    
 216.145 -    checksum = (s2 << 16) + s1;
 216.146 -  }
 216.147 -
 216.148 -  /**
 216.149 -   * Updates the checksum with the bytes taken from the array. 
 216.150 -   * 
 216.151 -   * @param buffer an array of bytes
 216.152 -   */
 216.153 -  public void update (byte[] buffer)
 216.154 -  {
 216.155 -    update(buffer, 0, buffer.length);
 216.156 -  }
 216.157 -
 216.158 -  /**
 216.159 -   * Updates the checksum with the bytes taken from the array. 
 216.160 -   * 
 216.161 -   * @param buf an array of bytes
 216.162 -   * @param off the start of the data used for this update
 216.163 -   * @param len the number of bytes to use for this update
 216.164 -   */
 216.165 -  public void update (byte[] buf, int off, int len)
 216.166 -  {
 216.167 -    //(By Per Bothner)
 216.168 -    int s1 = checksum & 0xffff;
 216.169 -    int s2 = checksum >>> 16;
 216.170 -
 216.171 -    while (len > 0)
 216.172 -      {
 216.173 -	// We can defer the modulo operation:
 216.174 -	// s1 maximally grows from 65521 to 65521 + 255 * 3800
 216.175 -	// s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
 216.176 -	int n = 3800;
 216.177 -	if (n > len)
 216.178 -	  n = len;
 216.179 -	len -= n;
 216.180 -	while (--n >= 0)
 216.181 -	  {
 216.182 -	    s1 = s1 + (buf[off++] & 0xFF);
 216.183 -	    s2 = s2 + s1;
 216.184 -	  }
 216.185 -	s1 %= BASE;
 216.186 -	s2 %= BASE;
 216.187 -      }
 216.188 -
 216.189 -    /*Old implementation, borrowed from somewhere:
 216.190 -    int n;
 216.191 -    
 216.192 -    while (len-- > 0) {
 216.193 -
 216.194 -      s1 = (s1 + (bs[offset++] & 0xff)) % BASE; 
 216.195 -      s2 = (s2 + s1) % BASE;
 216.196 -    }*/
 216.197 -    
 216.198 -    checksum = (s2 << 16) | s1;
 216.199 -  }
 216.200 -
 216.201 -  /**
 216.202 -   * Returns the Adler32 data checksum computed so far.
 216.203 -   */
 216.204 -  public long getValue()
 216.205 -  {
 216.206 -    return (long) checksum & 0xffffffffL;
 216.207 -  }
 216.208 -}
   217.1 --- a/emul/mini/src/main/java/java/util/zip/CRC32.java	Mon Feb 25 19:00:08 2013 +0100
   217.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   217.3 @@ -1,132 +0,0 @@
   217.4 -/* CRC32.java - Computes CRC32 data checksum of a data stream
   217.5 -   Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
   217.6 -
   217.7 -This file is part of GNU Classpath.
   217.8 -
   217.9 -GNU Classpath is free software; you can redistribute it and/or modify
  217.10 -it under the terms of the GNU General Public License as published by
  217.11 -the Free Software Foundation; either version 2, or (at your option)
  217.12 -any later version.
  217.13 -
  217.14 -GNU Classpath is distributed in the hope that it will be useful, but
  217.15 -WITHOUT ANY WARRANTY; without even the implied warranty of
  217.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  217.17 -General Public License for more details.
  217.18 -
  217.19 -You should have received a copy of the GNU General Public License
  217.20 -along with GNU Classpath; see the file COPYING.  If not, write to the
  217.21 -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  217.22 -02111-1307 USA.
  217.23 -
  217.24 -Linking this library statically or dynamically with other modules is
  217.25 -making a combined work based on this library.  Thus, the terms and
  217.26 -conditions of the GNU General Public License cover the whole
  217.27 -combination.
  217.28 -
  217.29 -As a special exception, the copyright holders of this library give you
  217.30 -permission to link this library with independent modules to produce an
  217.31 -executable, regardless of the license terms of these independent
  217.32 -modules, and to copy and distribute the resulting executable under
  217.33 -terms of your choice, provided that you also meet, for each linked
  217.34 -independent module, the terms and conditions of the license of that
  217.35 -module.  An independent module is a module which is not derived from
  217.36 -or based on this library.  If you modify this library, you may extend
  217.37 -this exception to your version of the library, but you are not
  217.38 -obligated to do so.  If you do not wish to do so, delete this
  217.39 -exception statement from your version. */
  217.40 -
  217.41 -package java.util.zip;
  217.42 -
  217.43 -/*
  217.44 - * Written using on-line Java Platform 1.2 API Specification, as well
  217.45 - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
  217.46 - * The actual CRC32 algorithm is taken from RFC 1952.
  217.47 - * Status:  Believed complete and correct.
  217.48 - */
  217.49 -
  217.50 -/**
  217.51 - * Computes CRC32 data checksum of a data stream.
  217.52 - * The actual CRC32 algorithm is described in RFC 1952
  217.53 - * (GZIP file format specification version 4.3).
  217.54 - * Can be used to get the CRC32 over a stream if used with checked input/output
  217.55 - * streams.
  217.56 - *
  217.57 - * @see InflaterInputStream
  217.58 - * @see DeflaterOutputStream
  217.59 - *
  217.60 - * @author Per Bothner
  217.61 - * @date April 1, 1999.
  217.62 - */
  217.63 -public class CRC32 implements Checksum
  217.64 -{
  217.65 -  /** The crc data checksum so far. */
  217.66 -  private int crc = 0;
  217.67 -
  217.68 -  /** The fast CRC table. Computed once when the CRC32 class is loaded. */
  217.69 -  private static int[] crc_table = make_crc_table();
  217.70 -
  217.71 -  /** Make the table for a fast CRC. */
  217.72 -  private static int[] make_crc_table ()
  217.73 -  {
  217.74 -    int[] crc_table = new int[256];
  217.75 -    for (int n = 0; n < 256; n++)
  217.76 -      {
  217.77 -	int c = n;
  217.78 -	for (int k = 8;  --k >= 0; )
  217.79 -	  {
  217.80 -	    if ((c & 1) != 0)
  217.81 -	      c = 0xedb88320 ^ (c >>> 1);
  217.82 -	    else
  217.83 -	      c = c >>> 1;
  217.84 -	  }
  217.85 -	crc_table[n] = c;
  217.86 -      }
  217.87 -    return crc_table;
  217.88 -  }
  217.89 -
  217.90 -  /**
  217.91 -   * Returns the CRC32 data checksum computed so far.
  217.92 -   */
  217.93 -  public long getValue ()
  217.94 -  {
  217.95 -    return (long) crc & 0xffffffffL;
  217.96 -  }
  217.97 -
  217.98 -  /**
  217.99 -   * Resets the CRC32 data checksum as if no update was ever called.
 217.100 -   */
 217.101 -  public void reset () { crc = 0; }
 217.102 -
 217.103 -  /**
 217.104 -   * Updates the checksum with the int bval. 
 217.105 -   *
 217.106 -   * @param bval (the byte is taken as the lower 8 bits of bval)
 217.107 -   */
 217.108 -
 217.109 -  public void update (int bval)
 217.110 -  {
 217.111 -    int c = ~crc;
 217.112 -    c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
 217.113 -    crc = ~c;
 217.114 -  }
 217.115 -
 217.116 -  /**
 217.117 -   * Adds the byte array to the data checksum.
 217.118 -   *
 217.119 -   * @param buf the buffer which contains the data
 217.120 -   * @param off the offset in the buffer where the data starts
 217.121 -   * @param len the length of the data
 217.122 -   */
 217.123 -  public void update (byte[] buf, int off, int len)
 217.124 -  {
 217.125 -    int c = ~crc;
 217.126 -    while (--len >= 0)
 217.127 -      c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
 217.128 -    crc = ~c;
 217.129 -  }
 217.130 -
 217.131 -  /**
 217.132 -   * Adds the complete byte array to the data checksum.
 217.133 -   */
 217.134 -  public void update (byte[] buf) { update(buf, 0, buf.length); }
 217.135 -}
   218.1 --- a/emul/mini/src/main/java/java/util/zip/Checksum.java	Mon Feb 25 19:00:08 2013 +0100
   218.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   218.3 @@ -1,60 +0,0 @@
   218.4 -/*
   218.5 - * Copyright (c) 1996, 1999, 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.util.zip;
  218.30 -
  218.31 -/**
  218.32 - * An interface representing a data checksum.
  218.33 - *
  218.34 - * @author      David Connelly
  218.35 - */
  218.36 -public
  218.37 -interface Checksum {
  218.38 -    /**
  218.39 -     * Updates the current checksum with the specified byte.
  218.40 -     *
  218.41 -     * @param b the byte to update the checksum with
  218.42 -     */
  218.43 -    public void update(int b);
  218.44 -
  218.45 -    /**
  218.46 -     * Updates the current checksum with the specified array of bytes.
  218.47 -     * @param b the byte array to update the checksum with
  218.48 -     * @param off the start offset of the data
  218.49 -     * @param len the number of bytes to use for the update
  218.50 -     */
  218.51 -    public void update(byte[] b, int off, int len);
  218.52 -
  218.53 -    /**
  218.54 -     * Returns the current checksum value.
  218.55 -     * @return the current checksum value
  218.56 -     */
  218.57 -    public long getValue();
  218.58 -
  218.59 -    /**
  218.60 -     * Resets the checksum to its initial value.
  218.61 -     */
  218.62 -    public void reset();
  218.63 -}
   219.1 --- a/emul/mini/src/main/java/java/util/zip/DataFormatException.java	Mon Feb 25 19:00:08 2013 +0100
   219.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   219.3 @@ -1,52 +0,0 @@
   219.4 -/*
   219.5 - * Copyright (c) 1996, 2008, 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.util.zip;
  219.30 -
  219.31 -/**
  219.32 - * Signals that a data format error has occurred.
  219.33 - *
  219.34 - * @author      David Connelly
  219.35 - */
  219.36 -public
  219.37 -class DataFormatException extends Exception {
  219.38 -    private static final long serialVersionUID = 2219632870893641452L;
  219.39 -
  219.40 -    /**
  219.41 -     * Constructs a DataFormatException with no detail message.
  219.42 -     */
  219.43 -    public DataFormatException() {
  219.44 -        super();
  219.45 -    }
  219.46 -
  219.47 -    /**
  219.48 -     * Constructs a DataFormatException with the specified detail message.
  219.49 -     * A detail message is a String that describes this particular exception.
  219.50 -     * @param s the String containing a detail message
  219.51 -     */
  219.52 -    public DataFormatException(String s) {
  219.53 -        super(s);
  219.54 -    }
  219.55 -}
   220.1 --- a/emul/mini/src/main/java/java/util/zip/Inflater.java	Mon Feb 25 19:00:08 2013 +0100
   220.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   220.3 @@ -1,310 +0,0 @@
   220.4 -/*
   220.5 - * Copyright (c) 1996, 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.util.zip;
  220.30 -
  220.31 -/**
  220.32 - * This class provides support for general purpose decompression using the
  220.33 - * popular ZLIB compression library. The ZLIB compression library was
  220.34 - * initially developed as part of the PNG graphics standard and is not
  220.35 - * protected by patents. It is fully described in the specifications at
  220.36 - * the <a href="package-summary.html#package_description">java.util.zip
  220.37 - * package description</a>.
  220.38 - *
  220.39 - * <p>The following code fragment demonstrates a trivial compression
  220.40 - * and decompression of a string using <tt>Deflater</tt> and
  220.41 - * <tt>Inflater</tt>.
  220.42 - *
  220.43 - * <blockquote><pre>
  220.44 - * try {
  220.45 - *     // Encode a String into bytes
  220.46 - *     String inputString = "blahblahblah\u20AC\u20AC";
  220.47 - *     byte[] input = inputString.getBytes("UTF-8");
  220.48 - *
  220.49 - *     // Compress the bytes
  220.50 - *     byte[] output = new byte[100];
  220.51 - *     Deflater compresser = new Deflater();
  220.52 - *     compresser.setInput(input);
  220.53 - *     compresser.finish();
  220.54 - *     int compressedDataLength = compresser.deflate(output);
  220.55 - *
  220.56 - *     // Decompress the bytes
  220.57 - *     Inflater decompresser = new Inflater();
  220.58 - *     decompresser.setInput(output, 0, compressedDataLength);
  220.59 - *     byte[] result = new byte[100];
  220.60 - *     int resultLength = decompresser.inflate(result);
  220.61 - *     decompresser.end();
  220.62 - *
  220.63 - *     // Decode the bytes into a String
  220.64 - *     String outputString = new String(result, 0, resultLength, "UTF-8");
  220.65 - * } catch(java.io.UnsupportedEncodingException ex) {
  220.66 - *     // handle
  220.67 - * } catch (java.util.zip.DataFormatException ex) {
  220.68 - *     // handle
  220.69 - * }
  220.70 - * </pre></blockquote>
  220.71 - *
  220.72 - * @see         Deflater
  220.73 - * @author      David Connelly
  220.74 - *
  220.75 - */
  220.76 -public
  220.77 -class Inflater {
  220.78 -    private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
  220.79 -    
  220.80 -    /**
  220.81 -     * Creates a new decompressor. If the parameter 'nowrap' is true then
  220.82 -     * the ZLIB header and checksum fields will not be used. This provides
  220.83 -     * compatibility with the compression format used by both GZIP and PKZIP.
  220.84 -     * <p>
  220.85 -     * Note: When using the 'nowrap' option it is also necessary to provide
  220.86 -     * an extra "dummy" byte as input. This is required by the ZLIB native
  220.87 -     * library in order to support certain optimizations.
  220.88 -     *
  220.89 -     * @param nowrap if true then support GZIP compatible compression
  220.90 -     */
  220.91 -    public Inflater(boolean nowrap) {
  220.92 -        if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
  220.93 -            impl = null;
  220.94 -        } else {
  220.95 -            impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
  220.96 -        }
  220.97 -    }
  220.98 -
  220.99 -    /**
 220.100 -     * Creates a new decompressor.
 220.101 -     */
 220.102 -    public Inflater() {
 220.103 -        this(false);
 220.104 -    }
 220.105 -
 220.106 -    /**
 220.107 -     * Sets input data for decompression. Should be called whenever
 220.108 -     * needsInput() returns true indicating that more input data is
 220.109 -     * required.
 220.110 -     * @param b the input data bytes
 220.111 -     * @param off the start offset of the input data
 220.112 -     * @param len the length of the input data
 220.113 -     * @see Inflater#needsInput
 220.114 -     */
 220.115 -    public void setInput(byte[] b, int off, int len) {
 220.116 -        impl.setInput(b, off, len);
 220.117 -    }
 220.118 -
 220.119 -    /**
 220.120 -     * Sets input data for decompression. Should be called whenever
 220.121 -     * needsInput() returns true indicating that more input data is
 220.122 -     * required.
 220.123 -     * @param b the input data bytes
 220.124 -     * @see Inflater#needsInput
 220.125 -     */
 220.126 -    public void setInput(byte[] b) {
 220.127 -        impl.setInput(b);
 220.128 -    }
 220.129 -
 220.130 -    /**
 220.131 -     * Sets the preset dictionary to the given array of bytes. Should be
 220.132 -     * called when inflate() returns 0 and needsDictionary() returns true
 220.133 -     * indicating that a preset dictionary is required. The method getAdler()
 220.134 -     * can be used to get the Adler-32 value of the dictionary needed.
 220.135 -     * @param b the dictionary data bytes
 220.136 -     * @param off the start offset of the data
 220.137 -     * @param len the length of the data
 220.138 -     * @see Inflater#needsDictionary
 220.139 -     * @see Inflater#getAdler
 220.140 -     */
 220.141 -    public void setDictionary(byte[] b, int off, int len) {
 220.142 -        impl.setDictionary(b, off, len);
 220.143 -    }
 220.144 -
 220.145 -    /**
 220.146 -     * Sets the preset dictionary to the given array of bytes. Should be
 220.147 -     * called when inflate() returns 0 and needsDictionary() returns true
 220.148 -     * indicating that a preset dictionary is required. The method getAdler()
 220.149 -     * can be used to get the Adler-32 value of the dictionary needed.
 220.150 -     * @param b the dictionary data bytes
 220.151 -     * @see Inflater#needsDictionary
 220.152 -     * @see Inflater#getAdler
 220.153 -     */
 220.154 -    public void setDictionary(byte[] b) {
 220.155 -        impl.setDictionary(b);
 220.156 -    }
 220.157 -
 220.158 -    /**
 220.159 -     * Returns the total number of bytes remaining in the input buffer.
 220.160 -     * This can be used to find out what bytes still remain in the input
 220.161 -     * buffer after decompression has finished.
 220.162 -     * @return the total number of bytes remaining in the input buffer
 220.163 -     */
 220.164 -    public int getRemaining() {
 220.165 -        return impl.getRemaining();
 220.166 -    }
 220.167 -
 220.168 -    /**
 220.169 -     * Returns true if no data remains in the input buffer. This can
 220.170 -     * be used to determine if #setInput should be called in order
 220.171 -     * to provide more input.
 220.172 -     * @return true if no data remains in the input buffer
 220.173 -     */
 220.174 -    public boolean needsInput() {
 220.175 -        return impl.needsInput();
 220.176 -    }
 220.177 -
 220.178 -    /**
 220.179 -     * Returns true if a preset dictionary is needed for decompression.
 220.180 -     * @return true if a preset dictionary is needed for decompression
 220.181 -     * @see Inflater#setDictionary
 220.182 -     */
 220.183 -    public boolean needsDictionary() {
 220.184 -        return impl.needsDictionary();
 220.185 -    }
 220.186 -
 220.187 -    /**
 220.188 -     * Returns true if the end of the compressed data stream has been
 220.189 -     * reached.
 220.190 -     * @return true if the end of the compressed data stream has been
 220.191 -     * reached
 220.192 -     */
 220.193 -    public boolean finished() {
 220.194 -        return impl.finished();
 220.195 -    }
 220.196 -
 220.197 -    /**
 220.198 -     * Uncompresses bytes into specified buffer. Returns actual number
 220.199 -     * of bytes uncompressed. A return value of 0 indicates that
 220.200 -     * needsInput() or needsDictionary() should be called in order to
 220.201 -     * determine if more input data or a preset dictionary is required.
 220.202 -     * In the latter case, getAdler() can be used to get the Adler-32
 220.203 -     * value of the dictionary required.
 220.204 -     * @param b the buffer for the uncompressed data
 220.205 -     * @param off the start offset of the data
 220.206 -     * @param len the maximum number of uncompressed bytes
 220.207 -     * @return the actual number of uncompressed bytes
 220.208 -     * @exception DataFormatException if the compressed data format is invalid
 220.209 -     * @see Inflater#needsInput
 220.210 -     * @see Inflater#needsDictionary
 220.211 -     */
 220.212 -    public int inflate(byte[] b, int off, int len)
 220.213 -        throws DataFormatException
 220.214 -    {
 220.215 -        return impl.inflate(b, off, len);
 220.216 -    }
 220.217 -
 220.218 -    /**
 220.219 -     * Uncompresses bytes into specified buffer. Returns actual number
 220.220 -     * of bytes uncompressed. A return value of 0 indicates that
 220.221 -     * needsInput() or needsDictionary() should be called in order to
 220.222 -     * determine if more input data or a preset dictionary is required.
 220.223 -     * In the latter case, getAdler() can be used to get the Adler-32
 220.224 -     * value of the dictionary required.
 220.225 -     * @param b the buffer for the uncompressed data
 220.226 -     * @return the actual number of uncompressed bytes
 220.227 -     * @exception DataFormatException if the compressed data format is invalid
 220.228 -     * @see Inflater#needsInput
 220.229 -     * @see Inflater#needsDictionary
 220.230 -     */
 220.231 -    public int inflate(byte[] b) throws DataFormatException {
 220.232 -        return impl.inflate(b);
 220.233 -    }
 220.234 -
 220.235 -    /**
 220.236 -     * Returns the ADLER-32 value of the uncompressed data.
 220.237 -     * @return the ADLER-32 value of the uncompressed data
 220.238 -     */
 220.239 -    public int getAdler() {
 220.240 -        return impl.getAdler();
 220.241 -    }
 220.242 -
 220.243 -    /**
 220.244 -     * Returns the total number of compressed bytes input so far.
 220.245 -     *
 220.246 -     * <p>Since the number of bytes may be greater than
 220.247 -     * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
 220.248 -     * the preferred means of obtaining this information.</p>
 220.249 -     *
 220.250 -     * @return the total number of compressed bytes input so far
 220.251 -     */
 220.252 -    public int getTotalIn() {
 220.253 -        return impl.getTotalIn();
 220.254 -    }
 220.255 -
 220.256 -    /**
 220.257 -     * Returns the total number of compressed bytes input so far.</p>
 220.258 -     *
 220.259 -     * @return the total (non-negative) number of compressed bytes input so far
 220.260 -     * @since 1.5
 220.261 -     */
 220.262 -    public long getBytesRead() {
 220.263 -        return impl.getBytesRead();
 220.264 -    }
 220.265 -
 220.266 -    /**
 220.267 -     * Returns the total number of uncompressed bytes output so far.
 220.268 -     *
 220.269 -     * <p>Since the number of bytes may be greater than
 220.270 -     * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
 220.271 -     * the preferred means of obtaining this information.</p>
 220.272 -     *
 220.273 -     * @return the total number of uncompressed bytes output so far
 220.274 -     */
 220.275 -    public int getTotalOut() {
 220.276 -        return impl.getTotalOut();
 220.277 -    }
 220.278 -
 220.279 -    /**
 220.280 -     * Returns the total number of uncompressed bytes output so far.</p>
 220.281 -     *
 220.282 -     * @return the total (non-negative) number of uncompressed bytes output so far
 220.283 -     * @since 1.5
 220.284 -     */
 220.285 -    public long getBytesWritten() {
 220.286 -        return impl.getBytesWritten();
 220.287 -    }
 220.288 -
 220.289 -    /**
 220.290 -     * Resets inflater so that a new set of input data can be processed.
 220.291 -     */
 220.292 -    public void reset() {
 220.293 -        impl.reset();
 220.294 -    }
 220.295 -
 220.296 -    /**
 220.297 -     * Closes the decompressor and discards any unprocessed input.
 220.298 -     * This method should be called when the decompressor is no longer
 220.299 -     * being used, but will also be called automatically by the finalize()
 220.300 -     * method. Once this method is called, the behavior of the Inflater
 220.301 -     * object is undefined.
 220.302 -     */
 220.303 -    public void end() {
 220.304 -        impl.end();
 220.305 -    }
 220.306 -
 220.307 -    /**
 220.308 -     * Closes the decompressor when garbage is collected.
 220.309 -     */
 220.310 -    protected void finalize() {
 220.311 -        end();
 220.312 -    }
 220.313 -}
   221.1 --- a/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   221.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   221.3 @@ -1,288 +0,0 @@
   221.4 -/*
   221.5 - * Copyright (c) 1996, 2006, 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.util.zip;
  221.30 -
  221.31 -import java.io.FilterInputStream;
  221.32 -import java.io.InputStream;
  221.33 -import java.io.IOException;
  221.34 -import java.io.EOFException;
  221.35 -
  221.36 -/**
  221.37 - * This class implements a stream filter for uncompressing data in the
  221.38 - * "deflate" compression format. It is also used as the basis for other
  221.39 - * decompression filters, such as GZIPInputStream.
  221.40 - *
  221.41 - * @see         Inflater
  221.42 - * @author      David Connelly
  221.43 - */
  221.44 -public
  221.45 -class InflaterInputStream extends FilterInputStream {
  221.46 -    /**
  221.47 -     * Decompressor for this stream.
  221.48 -     */
  221.49 -    protected Inflater inf;
  221.50 -
  221.51 -    /**
  221.52 -     * Input buffer for decompression.
  221.53 -     */
  221.54 -    protected byte[] buf;
  221.55 -
  221.56 -    /**
  221.57 -     * Length of input buffer.
  221.58 -     */
  221.59 -    protected int len;
  221.60 -
  221.61 -    private boolean closed = false;
  221.62 -    // this flag is set to true after EOF has reached
  221.63 -    private boolean reachEOF = false;
  221.64 -
  221.65 -    /**
  221.66 -     * Check to make sure that this stream has not been closed
  221.67 -     */
  221.68 -    private void ensureOpen() throws IOException {
  221.69 -        if (closed) {
  221.70 -            throw new IOException("Stream closed");
  221.71 -        }
  221.72 -    }
  221.73 -
  221.74 -
  221.75 -    /**
  221.76 -     * Creates a new input stream with the specified decompressor and
  221.77 -     * buffer size.
  221.78 -     * @param in the input stream
  221.79 -     * @param inf the decompressor ("inflater")
  221.80 -     * @param size the input buffer size
  221.81 -     * @exception IllegalArgumentException if size is <= 0
  221.82 -     */
  221.83 -    public InflaterInputStream(InputStream in, Inflater inf, int size) {
  221.84 -        super(in);
  221.85 -        if (in == null || inf == null) {
  221.86 -            throw new NullPointerException();
  221.87 -        } else if (size <= 0) {
  221.88 -            throw new IllegalArgumentException("buffer size <= 0");
  221.89 -        }
  221.90 -        this.inf = inf;
  221.91 -        buf = new byte[size];
  221.92 -    }
  221.93 -
  221.94 -    /**
  221.95 -     * Creates a new input stream with the specified decompressor and a
  221.96 -     * default buffer size.
  221.97 -     * @param in the input stream
  221.98 -     * @param inf the decompressor ("inflater")
  221.99 -     */
 221.100 -    public InflaterInputStream(InputStream in, Inflater inf) {
 221.101 -        this(in, inf, 512);
 221.102 -    }
 221.103 -
 221.104 -    boolean usesDefaultInflater = false;
 221.105 -
 221.106 -    /**
 221.107 -     * Creates a new input stream with a default decompressor and buffer size.
 221.108 -     * @param in the input stream
 221.109 -     */
 221.110 -    public InflaterInputStream(InputStream in) {
 221.111 -        this(in, new Inflater());
 221.112 -        usesDefaultInflater = true;
 221.113 -    }
 221.114 -
 221.115 -    private byte[] singleByteBuf = new byte[1];
 221.116 -
 221.117 -    /**
 221.118 -     * Reads a byte of uncompressed data. This method will block until
 221.119 -     * enough input is available for decompression.
 221.120 -     * @return the byte read, or -1 if end of compressed input is reached
 221.121 -     * @exception IOException if an I/O error has occurred
 221.122 -     */
 221.123 -    public int read() throws IOException {
 221.124 -        ensureOpen();
 221.125 -        return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
 221.126 -    }
 221.127 -
 221.128 -    /**
 221.129 -     * Reads uncompressed data into an array of bytes. If <code>len</code> is not
 221.130 -     * zero, the method will block until some input can be decompressed; otherwise,
 221.131 -     * no bytes are read and <code>0</code> is returned.
 221.132 -     * @param b the buffer into which the data is read
 221.133 -     * @param off the start offset in the destination array <code>b</code>
 221.134 -     * @param len the maximum number of bytes read
 221.135 -     * @return the actual number of bytes read, or -1 if the end of the
 221.136 -     *         compressed input is reached or a preset dictionary is needed
 221.137 -     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 221.138 -     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 221.139 -     * <code>len</code> is negative, or <code>len</code> is greater than
 221.140 -     * <code>b.length - off</code>
 221.141 -     * @exception ZipException if a ZIP format error has occurred
 221.142 -     * @exception IOException if an I/O error has occurred
 221.143 -     */
 221.144 -    public int read(byte[] b, int off, int len) throws IOException {
 221.145 -        ensureOpen();
 221.146 -        if (b == null) {
 221.147 -            throw new NullPointerException();
 221.148 -        } else if (off < 0 || len < 0 || len > b.length - off) {
 221.149 -            throw new IndexOutOfBoundsException();
 221.150 -        } else if (len == 0) {
 221.151 -            return 0;
 221.152 -        }
 221.153 -        try {
 221.154 -            int n;
 221.155 -            while ((n = inf.inflate(b, off, len)) == 0) {
 221.156 -                if (inf.finished() || inf.needsDictionary()) {
 221.157 -                    reachEOF = true;
 221.158 -                    return -1;
 221.159 -                }
 221.160 -                if (inf.needsInput()) {
 221.161 -                    fill();
 221.162 -                }
 221.163 -            }
 221.164 -            return n;
 221.165 -        } catch (DataFormatException e) {
 221.166 -            String s = e.getMessage();
 221.167 -            throw new ZipException(s != null ? s : "Invalid ZLIB data format");
 221.168 -        }
 221.169 -    }
 221.170 -
 221.171 -    /**
 221.172 -     * Returns 0 after EOF has been reached, otherwise always return 1.
 221.173 -     * <p>
 221.174 -     * Programs should not count on this method to return the actual number
 221.175 -     * of bytes that could be read without blocking.
 221.176 -     *
 221.177 -     * @return     1 before EOF and 0 after EOF.
 221.178 -     * @exception  IOException  if an I/O error occurs.
 221.179 -     *
 221.180 -     */
 221.181 -    public int available() throws IOException {
 221.182 -        ensureOpen();
 221.183 -        if (reachEOF) {
 221.184 -            return 0;
 221.185 -        } else {
 221.186 -            return 1;
 221.187 -        }
 221.188 -    }
 221.189 -
 221.190 -    private byte[] b = new byte[512];
 221.191 -
 221.192 -    /**
 221.193 -     * Skips specified number of bytes of uncompressed data.
 221.194 -     * @param n the number of bytes to skip
 221.195 -     * @return the actual number of bytes skipped.
 221.196 -     * @exception IOException if an I/O error has occurred
 221.197 -     * @exception IllegalArgumentException if n < 0
 221.198 -     */
 221.199 -    public long skip(long n) throws IOException {
 221.200 -        if (n < 0) {
 221.201 -            throw new IllegalArgumentException("negative skip length");
 221.202 -        }
 221.203 -        ensureOpen();
 221.204 -        int max = (int)Math.min(n, Integer.MAX_VALUE);
 221.205 -        int total = 0;
 221.206 -        while (total < max) {
 221.207 -            int len = max - total;
 221.208 -            if (len > b.length) {
 221.209 -                len = b.length;
 221.210 -            }
 221.211 -            len = read(b, 0, len);
 221.212 -            if (len == -1) {
 221.213 -                reachEOF = true;
 221.214 -                break;
 221.215 -            }
 221.216 -            total += len;
 221.217 -        }
 221.218 -        return total;
 221.219 -    }
 221.220 -
 221.221 -    /**
 221.222 -     * Closes this input stream and releases any system resources associated
 221.223 -     * with the stream.
 221.224 -     * @exception IOException if an I/O error has occurred
 221.225 -     */
 221.226 -    public void close() throws IOException {
 221.227 -        if (!closed) {
 221.228 -            if (usesDefaultInflater)
 221.229 -                inf.end();
 221.230 -            in.close();
 221.231 -            closed = true;
 221.232 -        }
 221.233 -    }
 221.234 -
 221.235 -    /**
 221.236 -     * Fills input buffer with more data to decompress.
 221.237 -     * @exception IOException if an I/O error has occurred
 221.238 -     */
 221.239 -    protected void fill() throws IOException {
 221.240 -        ensureOpen();
 221.241 -        len = in.read(buf, 0, buf.length);
 221.242 -        if (len == -1) {
 221.243 -            throw new EOFException("Unexpected end of ZLIB input stream");
 221.244 -        }
 221.245 -        inf.setInput(buf, 0, len);
 221.246 -    }
 221.247 -
 221.248 -    /**
 221.249 -     * Tests if this input stream supports the <code>mark</code> and
 221.250 -     * <code>reset</code> methods. The <code>markSupported</code>
 221.251 -     * method of <code>InflaterInputStream</code> returns
 221.252 -     * <code>false</code>.
 221.253 -     *
 221.254 -     * @return  a <code>boolean</code> indicating if this stream type supports
 221.255 -     *          the <code>mark</code> and <code>reset</code> methods.
 221.256 -     * @see     java.io.InputStream#mark(int)
 221.257 -     * @see     java.io.InputStream#reset()
 221.258 -     */
 221.259 -    public boolean markSupported() {
 221.260 -        return false;
 221.261 -    }
 221.262 -
 221.263 -    /**
 221.264 -     * Marks the current position in this input stream.
 221.265 -     *
 221.266 -     * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
 221.267 -     * does nothing.
 221.268 -     *
 221.269 -     * @param   readlimit   the maximum limit of bytes that can be read before
 221.270 -     *                      the mark position becomes invalid.
 221.271 -     * @see     java.io.InputStream#reset()
 221.272 -     */
 221.273 -    public synchronized void mark(int readlimit) {
 221.274 -    }
 221.275 -
 221.276 -    /**
 221.277 -     * Repositions this stream to the position at the time the
 221.278 -     * <code>mark</code> method was last called on this input stream.
 221.279 -     *
 221.280 -     * <p> The method <code>reset</code> for class
 221.281 -     * <code>InflaterInputStream</code> does nothing except throw an
 221.282 -     * <code>IOException</code>.
 221.283 -     *
 221.284 -     * @exception  IOException  if this method is invoked.
 221.285 -     * @see     java.io.InputStream#mark(int)
 221.286 -     * @see     java.io.IOException
 221.287 -     */
 221.288 -    public synchronized void reset() throws IOException {
 221.289 -        throw new IOException("mark/reset not supported");
 221.290 -    }
 221.291 -}
   222.1 --- a/emul/mini/src/main/java/java/util/zip/ZStreamRef.java	Mon Feb 25 19:00:08 2013 +0100
   222.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   222.3 @@ -1,46 +0,0 @@
   222.4 -/*
   222.5 - * Copyright (c) 2009, 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.util.zip;
  222.30 -
  222.31 -/**
  222.32 - * A reference to the native zlib's z_stream structure.
  222.33 - */
  222.34 -
  222.35 -class ZStreamRef {
  222.36 -
  222.37 -    private long address;
  222.38 -    ZStreamRef (long address) {
  222.39 -        this.address = address;
  222.40 -    }
  222.41 -
  222.42 -    long address() {
  222.43 -        return address;
  222.44 -    }
  222.45 -
  222.46 -    void clear() {
  222.47 -        address = 0;
  222.48 -    }
  222.49 -}
   223.1 --- a/emul/mini/src/main/java/java/util/zip/ZipConstants.java	Mon Feb 25 19:00:08 2013 +0100
   223.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   223.3 @@ -1,98 +0,0 @@
   223.4 -/*
   223.5 - * Copyright (c) 1995, 1996, 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.util.zip;
  223.30 -
  223.31 -/*
  223.32 - * This interface defines the constants that are used by the classes
  223.33 - * which manipulate ZIP files.
  223.34 - *
  223.35 - * @author      David Connelly
  223.36 - */
  223.37 -interface ZipConstants {
  223.38 -    /*
  223.39 -     * Header signatures
  223.40 -     */
  223.41 -    static long LOCSIG = 0x04034b50L;   // "PK\003\004"
  223.42 -    static long EXTSIG = 0x08074b50L;   // "PK\007\008"
  223.43 -    static long CENSIG = 0x02014b50L;   // "PK\001\002"
  223.44 -    static long ENDSIG = 0x06054b50L;   // "PK\005\006"
  223.45 -
  223.46 -    /*
  223.47 -     * Header sizes in bytes (including signatures)
  223.48 -     */
  223.49 -    static final int LOCHDR = 30;       // LOC header size
  223.50 -    static final int EXTHDR = 16;       // EXT header size
  223.51 -    static final int CENHDR = 46;       // CEN header size
  223.52 -    static final int ENDHDR = 22;       // END header size
  223.53 -
  223.54 -    /*
  223.55 -     * Local file (LOC) header field offsets
  223.56 -     */
  223.57 -    static final int LOCVER = 4;        // version needed to extract
  223.58 -    static final int LOCFLG = 6;        // general purpose bit flag
  223.59 -    static final int LOCHOW = 8;        // compression method
  223.60 -    static final int LOCTIM = 10;       // modification time
  223.61 -    static final int LOCCRC = 14;       // uncompressed file crc-32 value
  223.62 -    static final int LOCSIZ = 18;       // compressed size
  223.63 -    static final int LOCLEN = 22;       // uncompressed size
  223.64 -    static final int LOCNAM = 26;       // filename length
  223.65 -    static final int LOCEXT = 28;       // extra field length
  223.66 -
  223.67 -    /*
  223.68 -     * Extra local (EXT) header field offsets
  223.69 -     */
  223.70 -    static final int EXTCRC = 4;        // uncompressed file crc-32 value
  223.71 -    static final int EXTSIZ = 8;        // compressed size
  223.72 -    static final int EXTLEN = 12;       // uncompressed size
  223.73 -
  223.74 -    /*
  223.75 -     * Central directory (CEN) header field offsets
  223.76 -     */
  223.77 -    static final int CENVEM = 4;        // version made by
  223.78 -    static final int CENVER = 6;        // version needed to extract
  223.79 -    static final int CENFLG = 8;        // encrypt, decrypt flags
  223.80 -    static final int CENHOW = 10;       // compression method
  223.81 -    static final int CENTIM = 12;       // modification time
  223.82 -    static final int CENCRC = 16;       // uncompressed file crc-32 value
  223.83 -    static final int CENSIZ = 20;       // compressed size
  223.84 -    static final int CENLEN = 24;       // uncompressed size
  223.85 -    static final int CENNAM = 28;       // filename length
  223.86 -    static final int CENEXT = 30;       // extra field length
  223.87 -    static final int CENCOM = 32;       // comment length
  223.88 -    static final int CENDSK = 34;       // disk number start
  223.89 -    static final int CENATT = 36;       // internal file attributes
  223.90 -    static final int CENATX = 38;       // external file attributes
  223.91 -    static final int CENOFF = 42;       // LOC header offset
  223.92 -
  223.93 -    /*
  223.94 -     * End of central directory (END) header field offsets
  223.95 -     */
  223.96 -    static final int ENDSUB = 8;        // number of entries on this disk
  223.97 -    static final int ENDTOT = 10;       // total number of entries
  223.98 -    static final int ENDSIZ = 12;       // central directory size in bytes
  223.99 -    static final int ENDOFF = 16;       // offset of first CEN header
 223.100 -    static final int ENDCOM = 20;       // zip file comment length
 223.101 -}
   224.1 --- a/emul/mini/src/main/java/java/util/zip/ZipEntry.java	Mon Feb 25 19:00:08 2013 +0100
   224.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   224.3 @@ -1,331 +0,0 @@
   224.4 -/*
   224.5 - * Copyright (c) 1995, 2011, 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.util.zip;
  224.30 -
  224.31 -/**
  224.32 - * This class is used to represent a ZIP file entry.
  224.33 - *
  224.34 - * @author      David Connelly
  224.35 - */
  224.36 -public
  224.37 -class ZipEntry implements ZipConstants, Cloneable {
  224.38 -    String name;        // entry name
  224.39 -    long time = -1;     // modification time (in DOS time)
  224.40 -    long crc = -1;      // crc-32 of entry data
  224.41 -    long size = -1;     // uncompressed size of entry data
  224.42 -    long csize = -1;    // compressed size of entry data
  224.43 -    int method = -1;    // compression method
  224.44 -    int flag = 0;       // general purpose flag
  224.45 -    byte[] extra;       // optional extra field data for entry
  224.46 -    String comment;     // optional comment string for entry
  224.47 -
  224.48 -    /**
  224.49 -     * Compression method for uncompressed entries.
  224.50 -     */
  224.51 -    public static final int STORED = 0;
  224.52 -
  224.53 -    /**
  224.54 -     * Compression method for compressed (deflated) entries.
  224.55 -     */
  224.56 -    public static final int DEFLATED = 8;
  224.57 -
  224.58 -    /**
  224.59 -     * Creates a new zip entry with the specified name.
  224.60 -     *
  224.61 -     * @param name the entry name
  224.62 -     * @exception NullPointerException if the entry name is null
  224.63 -     * @exception IllegalArgumentException if the entry name is longer than
  224.64 -     *            0xFFFF bytes
  224.65 -     */
  224.66 -    public ZipEntry(String name) {
  224.67 -        if (name == null) {
  224.68 -            throw new NullPointerException();
  224.69 -        }
  224.70 -        if (name.length() > 0xFFFF) {
  224.71 -            throw new IllegalArgumentException("entry name too long");
  224.72 -        }
  224.73 -        this.name = name;
  224.74 -    }
  224.75 -
  224.76 -    /**
  224.77 -     * Creates a new zip entry with fields taken from the specified
  224.78 -     * zip entry.
  224.79 -     * @param e a zip Entry object
  224.80 -     */
  224.81 -    public ZipEntry(ZipEntry e) {
  224.82 -        name = e.name;
  224.83 -        time = e.time;
  224.84 -        crc = e.crc;
  224.85 -        size = e.size;
  224.86 -        csize = e.csize;
  224.87 -        method = e.method;
  224.88 -        flag = e.flag;
  224.89 -        extra = e.extra;
  224.90 -        comment = e.comment;
  224.91 -    }
  224.92 -
  224.93 -    /*
  224.94 -     * Creates a new un-initialized zip entry
  224.95 -     */
  224.96 -    ZipEntry() {}
  224.97 -
  224.98 -    /**
  224.99 -     * Returns the name of the entry.
 224.100 -     * @return the name of the entry
 224.101 -     */
 224.102 -    public String getName() {
 224.103 -        return name;
 224.104 -    }
 224.105 -
 224.106 -    /**
 224.107 -     * Sets the modification time of the entry.
 224.108 -     * @param time the entry modification time in number of milliseconds
 224.109 -     *             since the epoch
 224.110 -     * @see #getTime()
 224.111 -     */
 224.112 -    public void setTime(long time) {
 224.113 -        this.time = javaToDosTime(time);
 224.114 -    }
 224.115 -
 224.116 -    /**
 224.117 -     * Returns the modification time of the entry, or -1 if not specified.
 224.118 -     * @return the modification time of the entry, or -1 if not specified
 224.119 -     * @see #setTime(long)
 224.120 -     */
 224.121 -    public long getTime() {
 224.122 -        return time != -1 ? dosToJavaTime(time) : -1;
 224.123 -    }
 224.124 -
 224.125 -    /**
 224.126 -     * Sets the uncompressed size of the entry data.
 224.127 -     * @param size the uncompressed size in bytes
 224.128 -     * @exception IllegalArgumentException if the specified size is less
 224.129 -     *            than 0, is greater than 0xFFFFFFFF when
 224.130 -     *            <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
 224.131 -     *            or is less than 0 when ZIP64 is supported
 224.132 -     * @see #getSize()
 224.133 -     */
 224.134 -    public void setSize(long size) {
 224.135 -        if (size < 0) {
 224.136 -            throw new IllegalArgumentException("invalid entry size");
 224.137 -        }
 224.138 -        this.size = size;
 224.139 -    }
 224.140 -
 224.141 -    /**
 224.142 -     * Returns the uncompressed size of the entry data, or -1 if not known.
 224.143 -     * @return the uncompressed size of the entry data, or -1 if not known
 224.144 -     * @see #setSize(long)
 224.145 -     */
 224.146 -    public long getSize() {
 224.147 -        return size;
 224.148 -    }
 224.149 -
 224.150 -    /**
 224.151 -     * Returns the size of the compressed entry data, or -1 if not known.
 224.152 -     * In the case of a stored entry, the compressed size will be the same
 224.153 -     * as the uncompressed size of the entry.
 224.154 -     * @return the size of the compressed entry data, or -1 if not known
 224.155 -     * @see #setCompressedSize(long)
 224.156 -     */
 224.157 -    public long getCompressedSize() {
 224.158 -        return csize;
 224.159 -    }
 224.160 -
 224.161 -    /**
 224.162 -     * Sets the size of the compressed entry data.
 224.163 -     * @param csize the compressed size to set to
 224.164 -     * @see #getCompressedSize()
 224.165 -     */
 224.166 -    public void setCompressedSize(long csize) {
 224.167 -        this.csize = csize;
 224.168 -    }
 224.169 -
 224.170 -    /**
 224.171 -     * Sets the CRC-32 checksum of the uncompressed entry data.
 224.172 -     * @param crc the CRC-32 value
 224.173 -     * @exception IllegalArgumentException if the specified CRC-32 value is
 224.174 -     *            less than 0 or greater than 0xFFFFFFFF
 224.175 -     * @see #getCrc()
 224.176 -     */
 224.177 -    public void setCrc(long crc) {
 224.178 -        if (crc < 0 || crc > 0xFFFFFFFFL) {
 224.179 -            throw new IllegalArgumentException("invalid entry crc-32");
 224.180 -        }
 224.181 -        this.crc = crc;
 224.182 -    }
 224.183 -
 224.184 -    /**
 224.185 -     * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
 224.186 -     * not known.
 224.187 -     * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
 224.188 -     * not known
 224.189 -     * @see #setCrc(long)
 224.190 -     */
 224.191 -    public long getCrc() {
 224.192 -        return crc;
 224.193 -    }
 224.194 -
 224.195 -    /**
 224.196 -     * Sets the compression method for the entry.
 224.197 -     * @param method the compression method, either STORED or DEFLATED
 224.198 -     * @exception IllegalArgumentException if the specified compression
 224.199 -     *            method is invalid
 224.200 -     * @see #getMethod()
 224.201 -     */
 224.202 -    public void setMethod(int method) {
 224.203 -        if (method != STORED && method != DEFLATED) {
 224.204 -            throw new IllegalArgumentException("invalid compression method");
 224.205 -        }
 224.206 -        this.method = method;
 224.207 -    }
 224.208 -
 224.209 -    /**
 224.210 -     * Returns the compression method of the entry, or -1 if not specified.
 224.211 -     * @return the compression method of the entry, or -1 if not specified
 224.212 -     * @see #setMethod(int)
 224.213 -     */
 224.214 -    public int getMethod() {
 224.215 -        return method;
 224.216 -    }
 224.217 -
 224.218 -    /**
 224.219 -     * Sets the optional extra field data for the entry.
 224.220 -     * @param extra the extra field data bytes
 224.221 -     * @exception IllegalArgumentException if the length of the specified
 224.222 -     *            extra field data is greater than 0xFFFF bytes
 224.223 -     * @see #getExtra()
 224.224 -     */
 224.225 -    public void setExtra(byte[] extra) {
 224.226 -        if (extra != null && extra.length > 0xFFFF) {
 224.227 -            throw new IllegalArgumentException("invalid extra field length");
 224.228 -        }
 224.229 -        this.extra = extra;
 224.230 -    }
 224.231 -
 224.232 -    /**
 224.233 -     * Returns the extra field data for the entry, or null if none.
 224.234 -     * @return the extra field data for the entry, or null if none
 224.235 -     * @see #setExtra(byte[])
 224.236 -     */
 224.237 -    public byte[] getExtra() {
 224.238 -        return extra;
 224.239 -    }
 224.240 -
 224.241 -    /**
 224.242 -     * Sets the optional comment string for the entry.
 224.243 -     *
 224.244 -     * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
 224.245 -     * specified comment string is greater than 0xFFFF bytes after encoding, only
 224.246 -     * the first 0xFFFF bytes are output to the ZIP file entry.
 224.247 -     *
 224.248 -     * @param comment the comment string
 224.249 -     *
 224.250 -     * @see #getComment()
 224.251 -     */
 224.252 -    public void setComment(String comment) {
 224.253 -        this.comment = comment;
 224.254 -    }
 224.255 -
 224.256 -    /**
 224.257 -     * Returns the comment string for the entry, or null if none.
 224.258 -     * @return the comment string for the entry, or null if none
 224.259 -     * @see #setComment(String)
 224.260 -     */
 224.261 -    public String getComment() {
 224.262 -        return comment;
 224.263 -    }
 224.264 -
 224.265 -    /**
 224.266 -     * Returns true if this is a directory entry. A directory entry is
 224.267 -     * defined to be one whose name ends with a '/'.
 224.268 -     * @return true if this is a directory entry
 224.269 -     */
 224.270 -    public boolean isDirectory() {
 224.271 -        return name.endsWith("/");
 224.272 -    }
 224.273 -
 224.274 -    /**
 224.275 -     * Returns a string representation of the ZIP entry.
 224.276 -     */
 224.277 -    public String toString() {
 224.278 -        return getName();
 224.279 -    }
 224.280 -
 224.281 -    /*
 224.282 -     * Converts DOS time to Java time (number of milliseconds since epoch).
 224.283 -     */
 224.284 -    private static long dosToJavaTime(long dtime) {
 224.285 -        return dtime;
 224.286 -        /* XXX:
 224.287 -        Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
 224.288 -                          (int)(((dtime >> 21) & 0x0f) - 1),
 224.289 -                          (int)((dtime >> 16) & 0x1f),
 224.290 -                          (int)((dtime >> 11) & 0x1f),
 224.291 -                          (int)((dtime >> 5) & 0x3f),
 224.292 -                          (int)((dtime << 1) & 0x3e));
 224.293 -        return d.getTime();
 224.294 -        */
 224.295 -    }
 224.296 -
 224.297 -    /*
 224.298 -     * Converts Java time to DOS time.
 224.299 -     */
 224.300 -    private static long javaToDosTime(long time) {
 224.301 -        return time;
 224.302 -        /* XXX:
 224.303 -        Date d = new Date(time);
 224.304 -        int year = d.getYear() + 1900;
 224.305 -        if (year < 1980) {
 224.306 -            return (1 << 21) | (1 << 16);
 224.307 -        }
 224.308 -        return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
 224.309 -               d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
 224.310 -               d.getSeconds() >> 1;
 224.311 -        */
 224.312 -    }
 224.313 -
 224.314 -    /**
 224.315 -     * Returns the hash code value for this entry.
 224.316 -     */
 224.317 -    public int hashCode() {
 224.318 -        return name.hashCode();
 224.319 -    }
 224.320 -
 224.321 -    /**
 224.322 -     * Returns a copy of this entry.
 224.323 -     */
 224.324 -    public Object clone() {
 224.325 -        try {
 224.326 -            ZipEntry e = (ZipEntry)super.clone();
 224.327 -            e.extra = (extra == null) ? null : extra.clone();
 224.328 -            return e;
 224.329 -        } catch (CloneNotSupportedException e) {
 224.330 -            // This should never happen, since we are Cloneable
 224.331 -            throw new IllegalStateException();
 224.332 -        }
 224.333 -    }
 224.334 -}
   225.1 --- a/emul/mini/src/main/java/java/util/zip/ZipException.java	Mon Feb 25 19:00:08 2013 +0100
   225.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   225.3 @@ -1,60 +0,0 @@
   225.4 -/*
   225.5 - * Copyright (c) 1995, 2010, 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.util.zip;
  225.30 -
  225.31 -import java.io.IOException;
  225.32 -
  225.33 -/**
  225.34 - * Signals that a Zip exception of some sort has occurred.
  225.35 - *
  225.36 - * @author  unascribed
  225.37 - * @see     java.io.IOException
  225.38 - * @since   JDK1.0
  225.39 - */
  225.40 -
  225.41 -public
  225.42 -class ZipException extends IOException {
  225.43 -    private static final long serialVersionUID = 8000196834066748623L;
  225.44 -
  225.45 -    /**
  225.46 -     * Constructs a <code>ZipException</code> with <code>null</code>
  225.47 -     * as its error detail message.
  225.48 -     */
  225.49 -    public ZipException() {
  225.50 -        super();
  225.51 -    }
  225.52 -
  225.53 -    /**
  225.54 -     * Constructs a <code>ZipException</code> with the specified detail
  225.55 -     * message.
  225.56 -     *
  225.57 -     * @param   s   the detail message.
  225.58 -     */
  225.59 -
  225.60 -    public ZipException(String s) {
  225.61 -        super(s);
  225.62 -    }
  225.63 -}
   226.1 --- a/emul/mini/src/main/java/java/util/zip/ZipInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   226.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   226.3 @@ -1,194 +0,0 @@
   226.4 -/*
   226.5 - * Copyright (c) 1996, 2009, 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.util.zip;
  226.30 -
  226.31 -import java.io.InputStream;
  226.32 -import java.io.IOException;
  226.33 -
  226.34 -/**
  226.35 - * This class implements an input stream filter for reading files in the
  226.36 - * ZIP file format. Includes support for both compressed and uncompressed
  226.37 - * entries.
  226.38 - *
  226.39 - * @author      David Connelly
  226.40 - */
  226.41 -public
  226.42 -class ZipInputStream extends InflaterInputStream implements ZipConstants {
  226.43 -    private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
  226.44 -
  226.45 -    /**
  226.46 -     * Creates a new ZIP input stream.
  226.47 -     *
  226.48 -     * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
  226.49 -     * decode the entry names.
  226.50 -     *
  226.51 -     * @param in the actual input stream
  226.52 -     */
  226.53 -    public ZipInputStream(InputStream in) {
  226.54 -        super(in);
  226.55 -        impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
  226.56 -    }
  226.57 -
  226.58 -    /**
  226.59 -     * Creates a new ZIP input stream.
  226.60 -     *
  226.61 -     * @param in the actual input stream
  226.62 -     *
  226.63 -     * @param charset
  226.64 -     *        The {@linkplain java.nio.charset.Charset charset} to be
  226.65 -     *        used to decode the ZIP entry name (ignored if the
  226.66 -     *        <a href="package-summary.html#lang_encoding"> language
  226.67 -     *        encoding bit</a> of the ZIP entry's general purpose bit
  226.68 -     *        flag is set).
  226.69 -     *
  226.70 -     * @since 1.7
  226.71 -     *
  226.72 -    public ZipInputStream(InputStream in, Charset charset) {
  226.73 -        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
  226.74 -        usesDefaultInflater = true;
  226.75 -        if(in == null) {
  226.76 -            throw new NullPointerException("in is null");
  226.77 -        }
  226.78 -        if (charset == null)
  226.79 -            throw new NullPointerException("charset is null");
  226.80 -        this.zc = ZipCoder.get(charset);
  226.81 -    }
  226.82 -    */
  226.83 -
  226.84 -    /**
  226.85 -     * Reads the next ZIP file entry and positions the stream at the
  226.86 -     * beginning of the entry data.
  226.87 -     * @return the next ZIP file entry, or null if there are no more entries
  226.88 -     * @exception ZipException if a ZIP file error has occurred
  226.89 -     * @exception IOException if an I/O error has occurred
  226.90 -     */
  226.91 -    public ZipEntry getNextEntry() throws IOException {
  226.92 -        return impl.getNextEntry();
  226.93 -    }
  226.94 -
  226.95 -    /**
  226.96 -     * Closes the current ZIP entry and positions the stream for reading the
  226.97 -     * next entry.
  226.98 -     * @exception ZipException if a ZIP file error has occurred
  226.99 -     * @exception IOException if an I/O error has occurred
 226.100 -     */
 226.101 -    public void closeEntry() throws IOException {
 226.102 -        impl.closeEntry();
 226.103 -    }
 226.104 -
 226.105 -    /**
 226.106 -     * Returns 0 after EOF has reached for the current entry data,
 226.107 -     * otherwise always return 1.
 226.108 -     * <p>
 226.109 -     * Programs should not count on this method to return the actual number
 226.110 -     * of bytes that could be read without blocking.
 226.111 -     *
 226.112 -     * @return     1 before EOF and 0 after EOF has reached for current entry.
 226.113 -     * @exception  IOException  if an I/O error occurs.
 226.114 -     *
 226.115 -     */
 226.116 -    public int available() throws IOException {
 226.117 -        return impl.available();
 226.118 -    }
 226.119 -
 226.120 -    /**
 226.121 -     * Reads from the current ZIP entry into an array of bytes.
 226.122 -     * If <code>len</code> is not zero, the method
 226.123 -     * blocks until some input is available; otherwise, no
 226.124 -     * bytes are read and <code>0</code> is returned.
 226.125 -     * @param b the buffer into which the data is read
 226.126 -     * @param off the start offset in the destination array <code>b</code>
 226.127 -     * @param len the maximum number of bytes read
 226.128 -     * @return the actual number of bytes read, or -1 if the end of the
 226.129 -     *         entry is reached
 226.130 -     * @exception  NullPointerException if <code>b</code> is <code>null</code>.
 226.131 -     * @exception  IndexOutOfBoundsException if <code>off</code> is negative,
 226.132 -     * <code>len</code> is negative, or <code>len</code> is greater than
 226.133 -     * <code>b.length - off</code>
 226.134 -     * @exception ZipException if a ZIP file error has occurred
 226.135 -     * @exception IOException if an I/O error has occurred
 226.136 -     */
 226.137 -    public int read(byte[] b, int off, int len) throws IOException {
 226.138 -        return impl.read(b, off, len);
 226.139 -    }
 226.140 -
 226.141 -    /**
 226.142 -     * Skips specified number of bytes in the current ZIP entry.
 226.143 -     * @param n the number of bytes to skip
 226.144 -     * @return the actual number of bytes skipped
 226.145 -     * @exception ZipException if a ZIP file error has occurred
 226.146 -     * @exception IOException if an I/O error has occurred
 226.147 -     * @exception IllegalArgumentException if n < 0
 226.148 -     */
 226.149 -    public long skip(long n) throws IOException {
 226.150 -        return impl.skip(n);
 226.151 -    }
 226.152 -
 226.153 -    /**
 226.154 -     * Closes this input stream and releases any system resources associated
 226.155 -     * with the stream.
 226.156 -     * @exception IOException if an I/O error has occurred
 226.157 -     */
 226.158 -    public void close() throws IOException {
 226.159 -        impl.close();
 226.160 -    }
 226.161 -
 226.162 -    /**
 226.163 -     * Creates a new <code>ZipEntry</code> object for the specified
 226.164 -     * entry name.
 226.165 -     *
 226.166 -     * @param name the ZIP file entry name
 226.167 -     * @return the ZipEntry just created
 226.168 -     */
 226.169 -    protected ZipEntry createZipEntry(String name) {
 226.170 -        return new ZipEntry(name);
 226.171 -    }
 226.172 -
 226.173 -    @Override
 226.174 -    public int read() throws IOException {
 226.175 -        return impl.read();
 226.176 -    }
 226.177 -
 226.178 -    @Override
 226.179 -    public boolean markSupported() {
 226.180 -        return impl.markSupported();
 226.181 -    }
 226.182 -
 226.183 -    @Override
 226.184 -    public void mark(int readlimit) {
 226.185 -        impl.mark(readlimit);
 226.186 -    }
 226.187 -
 226.188 -    @Override
 226.189 -    public void reset() throws IOException {
 226.190 -        impl.reset();
 226.191 -    }
 226.192 -
 226.193 -    @Override
 226.194 -    public int read(byte[] b) throws IOException {
 226.195 -        return impl.read(b);
 226.196 -    }
 226.197 -}
   227.1 --- a/emul/mini/src/main/java/java/util/zip/package.html	Mon Feb 25 19:00:08 2013 +0100
   227.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   227.3 @@ -1,98 +0,0 @@
   227.4 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
   227.5 -<html>
   227.6 -<head>
   227.7 -<!--
   227.8 -Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
   227.9 -DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  227.10 -
  227.11 -This code is free software; you can redistribute it and/or modify it
  227.12 -under the terms of the GNU General Public License version 2 only, as
  227.13 -published by the Free Software Foundation.  Oracle designates this
  227.14 -particular file as subject to the "Classpath" exception as provided
  227.15 -by Oracle in the LICENSE file that accompanied this code.
  227.16 -
  227.17 -This code is distributed in the hope that it will be useful, but WITHOUT
  227.18 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  227.19 -FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  227.20 -version 2 for more details (a copy is included in the LICENSE file that
  227.21 -accompanied this code).
  227.22 -
  227.23 -You should have received a copy of the GNU General Public License version
  227.24 -2 along with this work; if not, write to the Free Software Foundation,
  227.25 -Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  227.26 -
  227.27 -Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  227.28 -or visit www.oracle.com if you need additional information or have any
  227.29 -questions.
  227.30 --->
  227.31 -
  227.32 -</head>
  227.33 -<body bgcolor="white">
  227.34 -
  227.35 -Provides classes for reading and writing the standard ZIP and GZIP
  227.36 -file formats.  Also includes classes for compressing and decompressing
  227.37 -data using the DEFLATE compression algorithm, which is used by the
  227.38 -ZIP and GZIP file formats. Additionally, there are utility classes
  227.39 -for computing the CRC-32 and Adler-32 checksums of arbitrary
  227.40 -input streams.
  227.41 -
  227.42 -
  227.43 -<h2>Package Specification</h2>
  227.44 -
  227.45 -</a>
  227.46 -<ul>
  227.47 -  <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
  227.48 -      Info-ZIP Application Note 970311
  227.49 -      </a> - a detailed description of the Info-ZIP format upon which
  227.50 -      the <code>java.util.zip</code> classes are based.
  227.51 -<p>
  227.52 -  <a name="zip64">
  227.53 -  <li>An implementation may optionally support the ZIP64(tm) format extensions
  227.54 -      defined by the 
  227.55 -      <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
  227.56 -      PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
  227.57 -      are used to overcome the size limitations of the original ZIP format.
  227.58 -<p>
  227.59 -  <a name="lang_encoding">
  227.60 -  <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
  227.61 -      PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
  227.62 -      encode ZIP entry filename and comment fields using UTF-8.
  227.63 -<p>
  227.64 -  <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
  227.65 -      ZLIB Compressed Data Format Specification version 3.3</a>
  227.66 -      &nbsp;
  227.67 -      <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
  227.68 -      (RFC 1950)
  227.69 -<p>
  227.70 -  <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
  227.71 -      DEFLATE Compressed Data Format Specification version 1.3</a>
  227.72 -      &nbsp;
  227.73 -      <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
  227.74 -      (RFC 1951)
  227.75 -<p>
  227.76 -  <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
  227.77 -      GZIP file format specification version 4.3</a>
  227.78 -      &nbsp;
  227.79 -      <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
  227.80 -      (RFC 1952)
  227.81 -<p>
  227.82 -  <li>CRC-32 checksum is described in RFC 1952 (above)
  227.83 -<p>
  227.84 -  <li>Adler-32 checksum is described in RFC 1950 (above)
  227.85 -</ul>
  227.86 -
  227.87 -
  227.88 -<!--
  227.89 -<h2>Related Documentation</h2>
  227.90 -
  227.91 -For overviews, tutorials, examples, guides, and tool documentation, please see:
  227.92 -<ul>
  227.93 -  <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
  227.94 -</ul>
  227.95 --->
  227.96 -
  227.97 -@since JDK1.1
  227.98 -</body>
  227.99 -</html>
 227.100 -
 227.101 -
   228.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/ManifestInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   228.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   228.3 @@ -1,228 +0,0 @@
   228.4 -/*
   228.5 - * Copyright (c) 1997, 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 -package org.apidesign.bck2brwsr.emul.lang;
  228.29 -
  228.30 -import java.io.FilterInputStream;
  228.31 -import java.io.IOException;
  228.32 -import java.io.InputStream;
  228.33 -
  228.34 -/*
  228.35 - * A fast buffered input stream for parsing manifest files.
  228.36 - * 
  228.37 - * Taken from java.util.jar.Manifest.FastInputStream and modified to be
  228.38 - * independent of other Manifest functionality.
  228.39 - */
  228.40 -public abstract class ManifestInputStream extends FilterInputStream {
  228.41 -    private byte[] buf;
  228.42 -    private int count = 0;
  228.43 -    private int pos = 0;
  228.44 -
  228.45 -    protected ManifestInputStream(InputStream in) {
  228.46 -        this(in, 8192);
  228.47 -    }
  228.48 -
  228.49 -    protected ManifestInputStream(InputStream in, int size) {
  228.50 -        super(in);
  228.51 -        buf = new byte[size];
  228.52 -    }
  228.53 -
  228.54 -    public int read() throws IOException {
  228.55 -        if (pos >= count) {
  228.56 -            fill();
  228.57 -            if (pos >= count) {
  228.58 -                return -1;
  228.59 -            }
  228.60 -        }
  228.61 -        return buf[pos++] & 0xff;
  228.62 -    }
  228.63 -
  228.64 -    public int read(byte[] b, int off, int len) throws IOException {
  228.65 -        int avail = count - pos;
  228.66 -        if (avail <= 0) {
  228.67 -            if (len >= buf.length) {
  228.68 -                return in.read(b, off, len);
  228.69 -            }
  228.70 -            fill();
  228.71 -            avail = count - pos;
  228.72 -            if (avail <= 0) {
  228.73 -                return -1;
  228.74 -            }
  228.75 -        }
  228.76 -        if (len > avail) {
  228.77 -            len = avail;
  228.78 -        }
  228.79 -        System.arraycopy(buf, pos, b, off, len);
  228.80 -        pos += len;
  228.81 -        return len;
  228.82 -    }
  228.83 -
  228.84 -    /*
  228.85 -     * Reads 'len' bytes from the input stream, or until an end-of-line
  228.86 -     * is reached. Returns the number of bytes read.
  228.87 -     */
  228.88 -    public int readLine(byte[] b, int off, int len) throws IOException {
  228.89 -        byte[] tbuf = this.buf;
  228.90 -        int total = 0;
  228.91 -        while (total < len) {
  228.92 -            int avail = count - pos;
  228.93 -            if (avail <= 0) {
  228.94 -                fill();
  228.95 -                avail = count - pos;
  228.96 -                if (avail <= 0) {
  228.97 -                    return -1;
  228.98 -                }
  228.99 -            }
 228.100 -            int n = len - total;
 228.101 -            if (n > avail) {
 228.102 -                n = avail;
 228.103 -            }
 228.104 -            int tpos = pos;
 228.105 -            int maxpos = tpos + n;
 228.106 -            while (tpos < maxpos && tbuf[tpos++] != '\n') {
 228.107 -                ;
 228.108 -            }
 228.109 -            n = tpos - pos;
 228.110 -            System.arraycopy(tbuf, pos, b, off, n);
 228.111 -            off += n;
 228.112 -            total += n;
 228.113 -            pos = tpos;
 228.114 -            if (tbuf[tpos - 1] == '\n') {
 228.115 -                break;
 228.116 -            }
 228.117 -        }
 228.118 -        return total;
 228.119 -    }
 228.120 -
 228.121 -    public byte peek() throws IOException {
 228.122 -        if (pos == count) {
 228.123 -            fill();
 228.124 -        }
 228.125 -        if (pos == count) {
 228.126 -            return -1; // nothing left in buffer
 228.127 -        }
 228.128 -        return buf[pos];
 228.129 -    }
 228.130 -
 228.131 -    public int readLine(byte[] b) throws IOException {
 228.132 -        return readLine(b, 0, b.length);
 228.133 -    }
 228.134 -
 228.135 -    public long skip(long n) throws IOException {
 228.136 -        if (n <= 0) {
 228.137 -            return 0;
 228.138 -        }
 228.139 -        long avail = count - pos;
 228.140 -        if (avail <= 0) {
 228.141 -            return in.skip(n);
 228.142 -        }
 228.143 -        if (n > avail) {
 228.144 -            n = avail;
 228.145 -        }
 228.146 -        pos += n;
 228.147 -        return n;
 228.148 -    }
 228.149 -
 228.150 -    public int available() throws IOException {
 228.151 -        return (count - pos) + in.available();
 228.152 -    }
 228.153 -
 228.154 -    public void close() throws IOException {
 228.155 -        if (in != null) {
 228.156 -            in.close();
 228.157 -            in = null;
 228.158 -            buf = null;
 228.159 -        }
 228.160 -    }
 228.161 -
 228.162 -    private void fill() throws IOException {
 228.163 -        count = pos = 0;
 228.164 -        int n = in.read(buf, 0, buf.length);
 228.165 -        if (n > 0) {
 228.166 -            count = n;
 228.167 -        }
 228.168 -    }
 228.169 -    
 228.170 -    protected abstract String putValue(String key, String value);
 228.171 -
 228.172 -    public void readAttributes(byte[] lbuf) throws IOException {
 228.173 -        ManifestInputStream is = this;
 228.174 -
 228.175 -        String name = null;
 228.176 -        String value = null;
 228.177 -        byte[] lastline = null;
 228.178 -        int len;
 228.179 -        while ((len = is.readLine(lbuf)) != -1) {
 228.180 -            boolean lineContinued = false;
 228.181 -            if (lbuf[--len] != '\n') {
 228.182 -                throw new IOException("line too long");
 228.183 -            }
 228.184 -            if (len > 0 && lbuf[len - 1] == '\r') {
 228.185 -                --len;
 228.186 -            }
 228.187 -            if (len == 0) {
 228.188 -                break;
 228.189 -            }
 228.190 -            int i = 0;
 228.191 -            if (lbuf[0] == ' ') {
 228.192 -                if (name == null) {
 228.193 -                    throw new IOException("misplaced continuation line");
 228.194 -                }
 228.195 -                lineContinued = true;
 228.196 -                byte[] buf = new byte[lastline.length + len - 1];
 228.197 -                System.arraycopy(lastline, 0, buf, 0, lastline.length);
 228.198 -                System.arraycopy(lbuf, 1, buf, lastline.length, len - 1);
 228.199 -                if (is.peek() == ' ') {
 228.200 -                    lastline = buf;
 228.201 -                    continue;
 228.202 -                }
 228.203 -                value = new String(buf, 0, buf.length, "UTF8");
 228.204 -                lastline = null;
 228.205 -            } else {
 228.206 -                while (lbuf[i++] != ':') {
 228.207 -                    if (i >= len) {
 228.208 -                        throw new IOException("invalid header field");
 228.209 -                    }
 228.210 -                }
 228.211 -                if (lbuf[i++] != ' ') {
 228.212 -                    throw new IOException("invalid header field");
 228.213 -                }
 228.214 -                name = new String(lbuf, 0, 0, i - 2);
 228.215 -                if (is.peek() == ' ') {
 228.216 -                    lastline = new byte[len - i];
 228.217 -                    System.arraycopy(lbuf, i, lastline, 0, len - i);
 228.218 -                    continue;
 228.219 -                }
 228.220 -                value = new String(lbuf, i, len - i, "UTF8");
 228.221 -            }
 228.222 -            try {
 228.223 -                if ((putValue(name, value) != null) && (!lineContinued)) {
 228.224 -                    throw new IOException("Duplicate name in Manifest: " + name + ".\n" + "Ensure that the manifest does not " + "have duplicate entries, and\n" + "that blank lines separate " + "individual sections in both your\n" + "manifest and in the META-INF/MANIFEST.MF " + "entry in the jar file.");
 228.225 -                }
 228.226 -            } catch (IllegalArgumentException e) {
 228.227 -                throw new IOException("invalid header field name: " + name);
 228.228 -            }
 228.229 -        }
 228.230 -    }
 228.231 -}
   229.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Mon Feb 25 19:00:08 2013 +0100
   229.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   229.3 @@ -1,69 +0,0 @@
   229.4 -/**
   229.5 - * Back 2 Browser Bytecode Translator
   229.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   229.7 - *
   229.8 - * This program is free software: you can redistribute it and/or modify
   229.9 - * it under the terms of the GNU General Public License as published by
  229.10 - * the Free Software Foundation, version 2 of the License.
  229.11 - *
  229.12 - * This program is distributed in the hope that it will be useful,
  229.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  229.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  229.15 - * GNU General Public License for more details.
  229.16 - *
  229.17 - * You should have received a copy of the GNU General Public License
  229.18 - * along with this program. Look for COPYING file in the top folder.
  229.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  229.20 - */
  229.21 -package org.apidesign.bck2brwsr.emul.lang;
  229.22 -
  229.23 -import java.lang.reflect.Method;
  229.24 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  229.25 -
  229.26 -/**
  229.27 - *
  229.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  229.29 - */
  229.30 -public class System {
  229.31 -    private System() {
  229.32 -    }
  229.33 -
  229.34 -    @JavaScriptBody(args = { "value", "srcBegin", "dst", "dstBegin", "count" }, body = 
  229.35 -        "if (srcBegin < dstBegin) {\n" +
  229.36 -        "    while (count-- > 0) {\n" +
  229.37 -        "        dst[dstBegin + count] = value[srcBegin + count];\n" +
  229.38 -        "    }\n" +
  229.39 -        "} else {\n" +
  229.40 -        "    while (count-- > 0) {\n" +
  229.41 -        "        dst[dstBegin++] = value[srcBegin++];\n" +
  229.42 -        "    }\n" +
  229.43 -        "}"
  229.44 -    )
  229.45 -    public static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) {
  229.46 -        try {
  229.47 -            Class<?> system = Class.forName("java.lang.System");
  229.48 -            Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class);
  229.49 -            m.invoke(null, src, srcBegin, dst, dstBegin, count);
  229.50 -        } catch (Exception ex) {
  229.51 -            throw new IllegalStateException(ex);
  229.52 -        }
  229.53 -    }
  229.54 -
  229.55 -    @JavaScriptBody(args = { "arr", "expectedSize" }, body = 
  229.56 -        "while (expectedSize-- > arr.length) { arr.push(0); }; return arr;"
  229.57 -    )
  229.58 -    public static native byte[] expandArray(byte[] arr, int expectedSize);
  229.59 -
  229.60 -    @JavaScriptBody(args = {}, body = "return new Date().getTime();")
  229.61 -    private static native double currentTimeMillisDouble();
  229.62 -
  229.63 -    public static long currentTimeMillis() {
  229.64 -        return (long) currentTimeMillisDouble();
  229.65 -    }
  229.66 -
  229.67 -    public static long nanoTime() {
  229.68 -        return 1000000L * currentTimeMillis();
  229.69 -    }
  229.70 -    @JavaScriptBody(args = { "obj" }, body="return vm.java_lang_Object(false).hashCode__I.call(obj);")
  229.71 -    public static native int identityHashCode(Object obj);
  229.72 -}
   230.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/AnnotationImpl.java	Mon Feb 25 19:00:08 2013 +0100
   230.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   230.3 @@ -1,130 +0,0 @@
   230.4 -/**
   230.5 - * Back 2 Browser Bytecode Translator
   230.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   230.7 - *
   230.8 - * This program is free software: you can redistribute it and/or modify
   230.9 - * it under the terms of the GNU General Public License as published by
  230.10 - * the Free Software Foundation, version 2 of the License.
  230.11 - *
  230.12 - * This program is distributed in the hope that it will be useful,
  230.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  230.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  230.15 - * GNU General Public License for more details.
  230.16 - *
  230.17 - * You should have received a copy of the GNU General Public License
  230.18 - * along with this program. Look for COPYING file in the top folder.
  230.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  230.20 - */
  230.21 -package org.apidesign.bck2brwsr.emul.reflect;
  230.22 -
  230.23 -import java.lang.annotation.Annotation;
  230.24 -import java.lang.reflect.Method;
  230.25 -import java.lang.reflect.Modifier;
  230.26 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  230.27 -
  230.28 -/**
  230.29 - *
  230.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  230.31 - */
  230.32 -public final class AnnotationImpl implements Annotation {
  230.33 -    private final Class<? extends Annotation> type;
  230.34 -
  230.35 -    public AnnotationImpl(Class<? extends Annotation> type) {
  230.36 -        this.type = type;
  230.37 -    }
  230.38 -    
  230.39 -    public Class<? extends Annotation> annotationType() {
  230.40 -        return type;
  230.41 -    }
  230.42 -
  230.43 -    @JavaScriptBody(args = { "a", "n", "arr", "values" }, body = ""
  230.44 -        + "function f(val, prop, clazz) {\n"
  230.45 -        + "  return function() {\n"
  230.46 -        + "    if (clazz == null) return val[prop];\n"
  230.47 -        + "    if (clazz.isArray__Z()) {\n"
  230.48 -        + "      var valarr = val[prop];\n"
  230.49 -        + "      var cmp = clazz.getComponentType__Ljava_lang_Class_2();\n"
  230.50 -        + "      var retarr = vm.java_lang_reflect_Array(false).newInstance__Ljava_lang_Object_2Ljava_lang_Class_2I(cmp, valarr.length);\n"
  230.51 -        + "      for (var i = 0; i < valarr.length; i++) {\n"
  230.52 -        + "        retarr[i] = CLS.prototype.c__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_Object_2(cmp, valarr[i]);\n"
  230.53 -        + "      }\n"
  230.54 -        + "      return retarr;\n"
  230.55 -        + "    }\n"
  230.56 -        + "    return CLS.prototype.c__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_Object_2(clazz, val[prop]);\n"
  230.57 -        + "  };\n"
  230.58 -        + "}\n"
  230.59 -        + "for (var i = 0; i < arr.length; i += 3) {\n"
  230.60 -        + "  var m = arr[i];\n"
  230.61 -        + "  var p = arr[i + 1];\n"
  230.62 -        + "  var c = arr[i + 2];\n"
  230.63 -        + "  a[m] = f(values, p, c);\n"
  230.64 -        + "}\n"
  230.65 -        + "a['$instOf_' + n] = true;\n"
  230.66 -        + "return a;"
  230.67 -    )
  230.68 -    private static native <T extends Annotation> T create(
  230.69 -        AnnotationImpl a, String n, Object[] methodsAndProps, Object values
  230.70 -    );
  230.71 -    
  230.72 -    private static Object c(Class<? extends Annotation> a, Object v) {
  230.73 -        return create(a, v);
  230.74 -    }
  230.75 -    
  230.76 -    public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
  230.77 -        return create(new AnnotationImpl(annoClass), 
  230.78 -            annoClass.getName().replace('.', '_'), 
  230.79 -            findProps(annoClass), values
  230.80 -        );
  230.81 -    }
  230.82 -
  230.83 -    public static Annotation[] create(Object anno) {
  230.84 -        String[] names = findNames(anno);
  230.85 -        Annotation[] ret = new Annotation[names.length];
  230.86 -        for (int i = 0; i < names.length; i++) {
  230.87 -            String annoNameSlash = names[i].substring(1, names[i].length() - 1);
  230.88 -            Class<? extends Annotation> annoClass;
  230.89 -            try {
  230.90 -                annoClass = (Class<? extends Annotation>)Class.forName(annoNameSlash.replace('/', '.'));
  230.91 -            } catch (ClassNotFoundException ex) {
  230.92 -                throw new IllegalStateException("Can't find annotation class " + annoNameSlash);
  230.93 -            }
  230.94 -            ret[i] = create(
  230.95 -                new AnnotationImpl(annoClass), 
  230.96 -                annoNameSlash.replace('/', '_'),
  230.97 -                findProps(annoClass),
  230.98 -                findData(anno, names[i])
  230.99 -            );
 230.100 -        }
 230.101 -        return ret;
 230.102 -    }
 230.103 -    @JavaScriptBody(args = "anno", body =
 230.104 -          "var arr = new Array();"
 230.105 -        + "var props = Object.getOwnPropertyNames(anno);\n"
 230.106 -        + "for (var i = 0; i < props.length; i++) {\n"
 230.107 -        + "  var p = props[i];\n"
 230.108 -        + "  arr.push(p);"
 230.109 -        + "}"
 230.110 -        + "return arr;"
 230.111 -    )
 230.112 -    private static native String[] findNames(Object anno);
 230.113 -
 230.114 -    @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
 230.115 -    private static native Object findData(Object anno, String p);
 230.116 -
 230.117 -    private static Object[] findProps(Class<?> annoClass) {
 230.118 -        final Method[] marr = MethodImpl.findMethods(annoClass, Modifier.PUBLIC);
 230.119 -        Object[] arr = new Object[marr.length * 3];
 230.120 -        int pos = 0;
 230.121 -        for (Method m : marr) {
 230.122 -            arr[pos++] = MethodImpl.toSignature(m);
 230.123 -            arr[pos++] = m.getName();
 230.124 -            final Class<?> rt = m.getReturnType();
 230.125 -            if (rt.isArray()) {
 230.126 -                arr[pos++] = rt.getComponentType().isAnnotation() ? rt : null;
 230.127 -            } else {
 230.128 -                arr[pos++] = rt.isAnnotation() ? rt : null;
 230.129 -            }
 230.130 -        }
 230.131 -        return arr;
 230.132 -    }
 230.133 -}
   231.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/MethodImpl.java	Mon Feb 25 19:00:08 2013 +0100
   231.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   231.3 @@ -1,224 +0,0 @@
   231.4 -/**
   231.5 - * Back 2 Browser Bytecode Translator
   231.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   231.7 - *
   231.8 - * This program is free software: you can redistribute it and/or modify
   231.9 - * it under the terms of the GNU General Public License as published by
  231.10 - * the Free Software Foundation, version 2 of the License.
  231.11 - *
  231.12 - * This program is distributed in the hope that it will be useful,
  231.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  231.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  231.15 - * GNU General Public License for more details.
  231.16 - *
  231.17 - * You should have received a copy of the GNU General Public License
  231.18 - * along with this program. Look for COPYING file in the top folder.
  231.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  231.20 - */
  231.21 -package org.apidesign.bck2brwsr.emul.reflect;
  231.22 -
  231.23 -import java.lang.reflect.Array;
  231.24 -import java.lang.reflect.Method;
  231.25 -import java.util.Enumeration;
  231.26 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  231.27 -
  231.28 -/** Utilities to work on methods.
  231.29 - *
  231.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  231.31 - */
  231.32 -public abstract class MethodImpl {
  231.33 -    public static MethodImpl INSTANCE;
  231.34 -    static {
  231.35 -        try {
  231.36 -            Class.forName(Method.class.getName());
  231.37 -        } catch (ClassNotFoundException ex) {
  231.38 -            throw new IllegalStateException(ex);
  231.39 -        }
  231.40 -    }
  231.41 -
  231.42 -    protected abstract Method create(Class<?> declaringClass, String name, Object data, String sig);
  231.43 -    
  231.44 -    
  231.45 -    //
  231.46 -    // bck2brwsr implementation
  231.47 -    //
  231.48 -
  231.49 -    @JavaScriptBody(args = {"clazz", "prefix"},
  231.50 -        body = ""
  231.51 -        + "var c = clazz.cnstr.prototype;"
  231.52 -        + "var arr = new Array();\n"
  231.53 -        + "for (m in c) {\n"
  231.54 -        + "  if (m.indexOf(prefix) === 0) {\n"
  231.55 -        + "     if (!c[m].cls) continue;\n"
  231.56 -        + "     arr.push(m);\n"
  231.57 -        + "     arr.push(c[m]);\n"
  231.58 -        + "     arr.push(c[m].cls.$class);\n"
  231.59 -        + "  }"
  231.60 -        + "}\n"
  231.61 -        + "return arr;")
  231.62 -    private static native Object[] findMethodData(
  231.63 -        Class<?> clazz, String prefix);
  231.64 -
  231.65 -    public static Method findMethod(
  231.66 -        Class<?> clazz, String name, Class<?>... parameterTypes) {
  231.67 -        Object[] data = findMethodData(clazz, name + "__");
  231.68 -        BIG: for (int i = 0; i < data.length; i += 3) {
  231.69 -            String sig = ((String) data[i]).substring(name.length() + 2);
  231.70 -            Class<?> cls = (Class<?>) data[i + 2];
  231.71 -            Method tmp = INSTANCE.create(cls, name, data[i + 1], sig);
  231.72 -            Class<?>[] tmpParms = tmp.getParameterTypes();
  231.73 -            if (parameterTypes.length != tmpParms.length) {
  231.74 -                continue;
  231.75 -            }
  231.76 -            for (int j = 0; j < tmpParms.length; j++) {
  231.77 -                if (!parameterTypes[j].equals(tmpParms[j])) {
  231.78 -                    continue BIG;
  231.79 -                }
  231.80 -            }
  231.81 -            return tmp;
  231.82 -        }
  231.83 -        return null;
  231.84 -    }
  231.85 -
  231.86 -    public static Method[] findMethods(Class<?> clazz, int mask) {
  231.87 -        Object[] namesAndData = findMethodData(clazz, "");
  231.88 -        int cnt = 0;
  231.89 -        for (int i = 0; i < namesAndData.length; i += 3) {
  231.90 -            String sig = (String) namesAndData[i];
  231.91 -            Object data = namesAndData[i + 1];
  231.92 -            int middle = sig.indexOf("__");
  231.93 -            if (middle == -1) {
  231.94 -                continue;
  231.95 -            }
  231.96 -            String name = sig.substring(0, middle);
  231.97 -            sig = sig.substring(middle + 2);
  231.98 -            Class<?> cls = (Class<?>) namesAndData[i + 2];
  231.99 -            final Method m = INSTANCE.create(cls, name, data, sig);
 231.100 -            if ((m.getModifiers() & mask) == 0) {
 231.101 -                continue;
 231.102 -            }
 231.103 -            namesAndData[cnt++] = m;
 231.104 -        }
 231.105 -        Method[] arr = new Method[cnt];
 231.106 -        for (int i = 0; i < cnt; i++) {
 231.107 -            arr[i] = (Method) namesAndData[i];
 231.108 -        }
 231.109 -        return arr;
 231.110 -    }
 231.111 -    static String toSignature(Method m) {
 231.112 -        StringBuilder sb = new StringBuilder();
 231.113 -        sb.append(m.getName()).append("__");
 231.114 -        appendType(sb, m.getReturnType());
 231.115 -        Class<?>[] arr = m.getParameterTypes();
 231.116 -        for (int i = 0; i < arr.length; i++) {
 231.117 -            appendType(sb, arr[i]);
 231.118 -        }
 231.119 -        return sb.toString();
 231.120 -    }
 231.121 -    
 231.122 -    private static void appendType(StringBuilder sb, Class<?> type) {
 231.123 -        if (type == Integer.TYPE) {
 231.124 -            sb.append('I');
 231.125 -            return;
 231.126 -        }
 231.127 -        if (type == Long.TYPE) {
 231.128 -            sb.append('J');
 231.129 -            return;
 231.130 -        }
 231.131 -        if (type == Double.TYPE) {
 231.132 -            sb.append('D');
 231.133 -            return;
 231.134 -        }
 231.135 -        if (type == Float.TYPE) {
 231.136 -            sb.append('F');
 231.137 -            return;
 231.138 -        }
 231.139 -        if (type == Byte.TYPE) {
 231.140 -            sb.append('B');
 231.141 -            return;
 231.142 -        }
 231.143 -        if (type == Boolean.TYPE) {
 231.144 -            sb.append('Z');
 231.145 -            return;
 231.146 -        }
 231.147 -        if (type == Short.TYPE) {
 231.148 -            sb.append('S');
 231.149 -            return;
 231.150 -        }
 231.151 -        if (type == Void.TYPE) {
 231.152 -            sb.append('V');
 231.153 -            return;
 231.154 -        }
 231.155 -        if (type == Character.TYPE) {
 231.156 -            sb.append('C');
 231.157 -            return;
 231.158 -        }
 231.159 -        if (type.isArray()) {
 231.160 -            sb.append("_3");
 231.161 -            appendType(sb, type.getComponentType());
 231.162 -            return;
 231.163 -        }
 231.164 -        sb.append('L').append(type.getName().replace('.', '_'));
 231.165 -        sb.append("_2");
 231.166 -    }
 231.167 -
 231.168 -    public static int signatureElements(String sig) {
 231.169 -        Enumeration<Class> en = signatureParser(sig);
 231.170 -        int cnt = 0;
 231.171 -        while (en.hasMoreElements()) {
 231.172 -            en.nextElement();
 231.173 -            cnt++;
 231.174 -        }
 231.175 -        return cnt;
 231.176 -    }
 231.177 -    
 231.178 -    public static Enumeration<Class> signatureParser(final String sig) {
 231.179 -        class E implements Enumeration<Class> {
 231.180 -            int pos;
 231.181 -            
 231.182 -            public boolean hasMoreElements() {
 231.183 -                return pos < sig.length();
 231.184 -            }
 231.185 -
 231.186 -            public Class nextElement() {
 231.187 -                switch (sig.charAt(pos++)) {
 231.188 -                    case 'I':
 231.189 -                        return Integer.TYPE;
 231.190 -                    case 'J':
 231.191 -                        return Long.TYPE;
 231.192 -                    case 'D':
 231.193 -                        return Double.TYPE;
 231.194 -                    case 'F':
 231.195 -                        return Float.TYPE;
 231.196 -                    case 'B':
 231.197 -                        return Byte.TYPE;
 231.198 -                    case 'Z':
 231.199 -                        return Boolean.TYPE;
 231.200 -                    case 'S':
 231.201 -                        return Short.TYPE;
 231.202 -                    case 'V':
 231.203 -                        return Void.TYPE;
 231.204 -                    case 'C':
 231.205 -                        return Character.TYPE;
 231.206 -                    case 'L':
 231.207 -                        try {
 231.208 -                            int up = sig.indexOf("_2", pos);
 231.209 -                            String type = sig.substring(pos, up);
 231.210 -                            pos = up + 2;
 231.211 -                            return Class.forName(type.replace('_', '.'));
 231.212 -                        } catch (ClassNotFoundException ex) {
 231.213 -                            throw new IllegalStateException(ex);
 231.214 -                        }
 231.215 -                    case '_': {
 231.216 -                        char nch = sig.charAt(pos++);
 231.217 -                        assert nch == '3' : "Can't find '3' at " + sig.substring(pos - 1);
 231.218 -                        final Class compType = nextElement();
 231.219 -                        return Array.newInstance(compType, 0).getClass();
 231.220 -                    }
 231.221 -                }
 231.222 -                throw new UnsupportedOperationException(sig + " at " + pos);
 231.223 -            }
 231.224 -        }
 231.225 -        return new E();
 231.226 -    }
 231.227 -}
   232.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/TypeProvider.java	Mon Feb 25 19:00:08 2013 +0100
   232.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   232.3 @@ -1,40 +0,0 @@
   232.4 -/**
   232.5 - * Back 2 Browser Bytecode Translator
   232.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   232.7 - *
   232.8 - * This program is free software: you can redistribute it and/or modify
   232.9 - * it under the terms of the GNU General Public License as published by
  232.10 - * the Free Software Foundation, version 2 of the License.
  232.11 - *
  232.12 - * This program is distributed in the hope that it will be useful,
  232.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  232.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  232.15 - * GNU General Public License for more details.
  232.16 - *
  232.17 - * You should have received a copy of the GNU General Public License
  232.18 - * along with this program. Look for COPYING file in the top folder.
  232.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  232.20 - */
  232.21 -package org.apidesign.bck2brwsr.emul.reflect;
  232.22 -
  232.23 -import java.lang.reflect.Constructor;
  232.24 -import java.lang.reflect.Type;
  232.25 -import java.lang.reflect.TypeVariable;
  232.26 -
  232.27 -/**
  232.28 - *
  232.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  232.30 - */
  232.31 -public abstract class TypeProvider {
  232.32 -    private TypeProvider() {
  232.33 -    }
  232.34 -    
  232.35 -    public static TypeProvider getDefault() {
  232.36 -        return null;
  232.37 -    }
  232.38 -    
  232.39 -    public abstract <T> TypeVariable<Constructor<T>>[] getTypeParameters(Constructor<T> c);
  232.40 -    public abstract <T> Type[] getGenericParameterTypes(Constructor<T> c);
  232.41 -    public abstract <T> Type[] getGenericExceptionTypes(Constructor<T> c);
  232.42 -    
  232.43 -}
   233.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java	Mon Feb 25 19:00:08 2013 +0100
   233.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   233.3 @@ -1,139 +0,0 @@
   233.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   233.5 -/*
   233.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
   233.7 -
   233.8 -Redistribution and use in source and binary forms, with or without
   233.9 -modification, are permitted provided that the following conditions are met:
  233.10 -
  233.11 -  1. Redistributions of source code must retain the above copyright notice,
  233.12 -     this list of conditions and the following disclaimer.
  233.13 -
  233.14 -  2. Redistributions in binary form must reproduce the above copyright 
  233.15 -     notice, this list of conditions and the following disclaimer in 
  233.16 -     the documentation and/or other materials provided with the distribution.
  233.17 -
  233.18 -  3. The names of the authors may not be used to endorse or promote products
  233.19 -     derived from this software without specific prior written permission.
  233.20 -
  233.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  233.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  233.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  233.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  233.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  233.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  233.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  233.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  233.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  233.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  233.31 - */
  233.32 -/*
  233.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  233.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  233.35 - * and contributors of zlib.
  233.36 - */
  233.37 -
  233.38 -package org.apidesign.bck2brwsr.emul.zip;
  233.39 -
  233.40 -final class Adler32 implements Checksum {
  233.41 -
  233.42 -  // largest prime smaller than 65536
  233.43 -  static final private int BASE=65521; 
  233.44 -  // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
  233.45 -  static final private int NMAX=5552;
  233.46 -
  233.47 -  private long s1=1L;
  233.48 -  private long s2=0L;
  233.49 -
  233.50 -  public void reset(long init){
  233.51 -    s1=init&0xffff;
  233.52 -    s2=(init>>16)&0xffff;
  233.53 -  }
  233.54 -
  233.55 -  public void reset(){
  233.56 -    s1=1L;
  233.57 -    s2=0L;
  233.58 -  }
  233.59 -
  233.60 -  public long getValue(){
  233.61 -    return ((s2<<16)|s1);
  233.62 -  }
  233.63 -
  233.64 -  public void update(byte[] buf, int index, int len){
  233.65 -
  233.66 -    if(len==1){
  233.67 -      s1+=buf[index++]&0xff; s2+=s1;
  233.68 -      s1%=BASE;
  233.69 -      s2%=BASE;
  233.70 -      return;
  233.71 -    }
  233.72 -
  233.73 -    int len1 = len/NMAX;
  233.74 -    int len2 = len%NMAX;
  233.75 -    while(len1-->0) {
  233.76 -      int k=NMAX;
  233.77 -      len-=k;
  233.78 -      while(k-->0){
  233.79 -	s1+=buf[index++]&0xff; s2+=s1;
  233.80 -      }
  233.81 -      s1%=BASE;
  233.82 -      s2%=BASE;
  233.83 -    }
  233.84 -
  233.85 -    int k=len2;
  233.86 -    len-=k;
  233.87 -    while(k-->0){
  233.88 -      s1+=buf[index++]&0xff; s2+=s1;
  233.89 -    }
  233.90 -    s1%=BASE;
  233.91 -    s2%=BASE;
  233.92 -  }
  233.93 -
  233.94 -  public Adler32 copy(){
  233.95 -    Adler32 foo = new Adler32();
  233.96 -    foo.s1 = this.s1;
  233.97 -    foo.s2 = this.s2;
  233.98 -    return foo;
  233.99 -  }
 233.100 -
 233.101 -  // The following logic has come from zlib.1.2.
 233.102 -  static long combine(long adler1, long adler2, long len2){
 233.103 -    long BASEL = (long)BASE;
 233.104 -    long sum1;
 233.105 -    long sum2;
 233.106 -    long rem;  // unsigned int
 233.107 -
 233.108 -    rem = len2 % BASEL;
 233.109 -    sum1 = adler1 & 0xffffL;
 233.110 -    sum2 = rem * sum1;
 233.111 -    sum2 %= BASEL; // MOD(sum2);
 233.112 -    sum1 += (adler2 & 0xffffL) + BASEL - 1;
 233.113 -    sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
 233.114 -    if (sum1 >= BASEL) sum1 -= BASEL;
 233.115 -    if (sum1 >= BASEL) sum1 -= BASEL;
 233.116 -    if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
 233.117 -    if (sum2 >= BASEL) sum2 -= BASEL;
 233.118 -    return sum1 | (sum2 << 16);
 233.119 -  }
 233.120 -
 233.121 -/*
 233.122 -  private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
 233.123 -  public void update(byte[] buf, int index, int len){
 233.124 -    if(buf==null) {adler.reset();}
 233.125 -    else{adler.update(buf, index, len);}
 233.126 -  }
 233.127 -  public void reset(){
 233.128 -    adler.reset();
 233.129 -  }
 233.130 -  public void reset(long init){
 233.131 -    if(init==1L){
 233.132 -      adler.reset();
 233.133 -    }
 233.134 -    else{
 233.135 -      System.err.println("unsupported operation");
 233.136 -    }
 233.137 -  }
 233.138 -  public long getValue(){
 233.139 -    return adler.getValue();
 233.140 -  }
 233.141 -*/
 233.142 -}
   234.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java	Mon Feb 25 19:00:08 2013 +0100
   234.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   234.3 @@ -1,181 +0,0 @@
   234.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   234.5 -/*
   234.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   234.7 -
   234.8 -Redistribution and use in source and binary forms, with or without
   234.9 -modification, are permitted provided that the following conditions are met:
  234.10 -
  234.11 -  1. Redistributions of source code must retain the above copyright notice,
  234.12 -     this list of conditions and the following disclaimer.
  234.13 -
  234.14 -  2. Redistributions in binary form must reproduce the above copyright 
  234.15 -     notice, this list of conditions and the following disclaimer in 
  234.16 -     the documentation and/or other materials provided with the distribution.
  234.17 -
  234.18 -  3. The names of the authors may not be used to endorse or promote products
  234.19 -     derived from this software without specific prior written permission.
  234.20 -
  234.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  234.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  234.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  234.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  234.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  234.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  234.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  234.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  234.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  234.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  234.31 - */
  234.32 -/*
  234.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  234.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  234.35 - * and contributors of zlib.
  234.36 - */
  234.37 -
  234.38 -package org.apidesign.bck2brwsr.emul.zip;
  234.39 -
  234.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  234.41 -
  234.42 -final class CRC32 implements Checksum {
  234.43 -
  234.44 -  /*
  234.45 -   *  The following logic has come from RFC1952.
  234.46 -   */
  234.47 -  private int v = 0;
  234.48 -  private static int[] crc_table = null;
  234.49 -  static {
  234.50 -    crc_table = new int[256];
  234.51 -    for (int n = 0; n < 256; n++) {
  234.52 -      int c = n;
  234.53 -      for (int k = 8;  --k >= 0; ) {
  234.54 -        if ((c & 1) != 0)
  234.55 -	  c = 0xedb88320 ^ (c >>> 1);
  234.56 -        else
  234.57 -          c = c >>> 1;
  234.58 -      }
  234.59 -      crc_table[n] = c;
  234.60 -    }
  234.61 -  }
  234.62 -
  234.63 -  public void update (byte[] buf, int index, int len) {
  234.64 -    int c = ~v;
  234.65 -    while (--len >= 0)
  234.66 -      c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
  234.67 -    v = ~c;
  234.68 -  }
  234.69 -
  234.70 -  public void reset(){
  234.71 -    v = 0;
  234.72 -  }
  234.73 -
  234.74 -  public void reset(long vv){
  234.75 -    v = (int)(vv&0xffffffffL);
  234.76 -  }
  234.77 -
  234.78 -  public long getValue(){
  234.79 -    return (long)(v&0xffffffffL);
  234.80 -  }
  234.81 -
  234.82 -  // The following logic has come from zlib.1.2.
  234.83 -  private static final int GF2_DIM = 32;
  234.84 -  static long combine(long crc1, long crc2, long len2){
  234.85 -    long row;
  234.86 -    long[] even = new long[GF2_DIM];
  234.87 -    long[] odd = new long[GF2_DIM];
  234.88 -
  234.89 -    // degenerate case (also disallow negative lengths)
  234.90 -    if (len2 <= 0)
  234.91 -      return crc1;
  234.92 -
  234.93 -    // put operator for one zero bit in odd
  234.94 -    odd[0] = 0xedb88320L;          // CRC-32 polynomial
  234.95 -    row = 1;
  234.96 -    for (int n = 1; n < GF2_DIM; n++) {
  234.97 -        odd[n] = row;
  234.98 -        row <<= 1;
  234.99 -    }
 234.100 -
 234.101 -    // put operator for two zero bits in even
 234.102 -    gf2_matrix_square(even, odd);
 234.103 -
 234.104 -    // put operator for four zero bits in odd
 234.105 -    gf2_matrix_square(odd, even);
 234.106 -
 234.107 -    // apply len2 zeros to crc1 (first square will put the operator for one
 234.108 -    // zero byte, eight zero bits, in even)
 234.109 -    do {
 234.110 -      // apply zeros operator for this bit of len2
 234.111 -      gf2_matrix_square(even, odd);
 234.112 -      if ((len2 & 1)!=0)
 234.113 -        crc1 = gf2_matrix_times(even, crc1);
 234.114 -      len2 >>= 1;
 234.115 -
 234.116 -      // if no more bits set, then done
 234.117 -      if (len2 == 0)
 234.118 -        break;
 234.119 -
 234.120 -      // another iteration of the loop with odd and even swapped
 234.121 -      gf2_matrix_square(odd, even);
 234.122 -      if ((len2 & 1)!=0)
 234.123 -        crc1 = gf2_matrix_times(odd, crc1);
 234.124 -      len2 >>= 1;
 234.125 -
 234.126 -      // if no more bits set, then done
 234.127 -    } while (len2 != 0);
 234.128 -
 234.129 -    /* return combined crc */
 234.130 -    crc1 ^= crc2;
 234.131 -    return crc1;
 234.132 -  }
 234.133 -
 234.134 -  private static long gf2_matrix_times(long[] mat, long vec){
 234.135 -    long sum = 0;
 234.136 -    int index = 0;
 234.137 -    while (vec!=0) {
 234.138 -      if ((vec & 1)!=0)
 234.139 -        sum ^= mat[index];
 234.140 -      vec >>= 1;
 234.141 -      index++;
 234.142 -    }
 234.143 -    return sum;
 234.144 -  }
 234.145 -
 234.146 -  static final void gf2_matrix_square(long[] square, long[] mat) {
 234.147 -    for (int n = 0; n < GF2_DIM; n++)
 234.148 -      square[n] = gf2_matrix_times(mat, mat[n]);
 234.149 -  }
 234.150 -
 234.151 -  /*
 234.152 -  private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
 234.153 -
 234.154 -  public void update(byte[] buf, int index, int len){
 234.155 -    if(buf==null) {crc32.reset();}
 234.156 -    else{crc32.update(buf, index, len);}
 234.157 -  }
 234.158 -  public void reset(){
 234.159 -    crc32.reset();
 234.160 -  }
 234.161 -  public void reset(long init){
 234.162 -    if(init==0L){
 234.163 -      crc32.reset();
 234.164 -    }
 234.165 -    else{
 234.166 -      System.err.println("unsupported operation");
 234.167 -    }
 234.168 -  }
 234.169 -  public long getValue(){
 234.170 -    return crc32.getValue();
 234.171 -  }
 234.172 -*/
 234.173 -  public CRC32 copy(){
 234.174 -    CRC32 foo = new CRC32();
 234.175 -    foo.v = this.v;
 234.176 -    return foo;
 234.177 -  }
 234.178 -
 234.179 -  public static int[] getCRC32Table(){
 234.180 -    int[] tmp = new int[crc_table.length];
 234.181 -    System.arraycopy(crc_table, 0, tmp, 0, tmp.length);
 234.182 -    return tmp;
 234.183 -  }
 234.184 -}
   235.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java	Mon Feb 25 19:00:08 2013 +0100
   235.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   235.3 @@ -1,43 +0,0 @@
   235.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   235.5 -/*
   235.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   235.7 -
   235.8 -Redistribution and use in source and binary forms, with or without
   235.9 -modification, are permitted provided that the following conditions are met:
  235.10 -
  235.11 -  1. Redistributions of source code must retain the above copyright notice,
  235.12 -     this list of conditions and the following disclaimer.
  235.13 -
  235.14 -  2. Redistributions in binary form must reproduce the above copyright 
  235.15 -     notice, this list of conditions and the following disclaimer in 
  235.16 -     the documentation and/or other materials provided with the distribution.
  235.17 -
  235.18 -  3. The names of the authors may not be used to endorse or promote products
  235.19 -     derived from this software without specific prior written permission.
  235.20 -
  235.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  235.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  235.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  235.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  235.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  235.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  235.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  235.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  235.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  235.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  235.31 - */
  235.32 -/*
  235.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  235.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  235.35 - * and contributors of zlib.
  235.36 - */
  235.37 -
  235.38 -package org.apidesign.bck2brwsr.emul.zip;
  235.39 -
  235.40 -interface Checksum {
  235.41 -  void update(byte[] buf, int index, int len);
  235.42 -  void reset();
  235.43 -  void reset(long init);
  235.44 -  long getValue();
  235.45 -  Checksum copy();
  235.46 -}
   236.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java	Mon Feb 25 19:00:08 2013 +0100
   236.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   236.3 @@ -1,175 +0,0 @@
   236.4 -/*
   236.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   236.6 - *
   236.7 - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   236.8 - *
   236.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  236.10 - * Other names may be trademarks of their respective owners.
  236.11 - *
  236.12 - * The contents of this file are subject to the terms of either the GNU
  236.13 - * General Public License Version 2 only ("GPL") or the Common
  236.14 - * Development and Distribution License("CDDL") (collectively, the
  236.15 - * "License"). You may not use this file except in compliance with the
  236.16 - * License. You can obtain a copy of the License at
  236.17 - * http://www.netbeans.org/cddl-gplv2.html
  236.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  236.19 - * specific language governing permissions and limitations under the
  236.20 - * License.  When distributing the software, include this License Header
  236.21 - * Notice in each file and include the License file at
  236.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  236.23 - * particular file as subject to the "Classpath" exception as provided
  236.24 - * by Oracle in the GPL Version 2 section of the License file that
  236.25 - * accompanied this code. If applicable, add the following below the
  236.26 - * License Header, with the fields enclosed by brackets [] replaced by
  236.27 - * your own identifying information:
  236.28 - * "Portions Copyrighted [year] [name of copyright owner]"
  236.29 - *
  236.30 - * Contributor(s):
  236.31 - *
  236.32 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
  236.33 - */
  236.34 -package org.apidesign.bck2brwsr.emul.zip;
  236.35 -
  236.36 -import java.io.ByteArrayInputStream;
  236.37 -import java.io.IOException;
  236.38 -import java.io.InputStream;
  236.39 -import java.util.zip.ZipEntry;
  236.40 -import java.util.zip.ZipInputStream;
  236.41 -
  236.42 -/**
  236.43 - *
  236.44 - * @author Tomas Zezula
  236.45 - */
  236.46 -public final class FastJar {
  236.47 -    private final byte[] arr;
  236.48 -
  236.49 -    public FastJar(byte[] arr) {
  236.50 -        this.arr = arr;
  236.51 -    }
  236.52 -    
  236.53 -    
  236.54 -    private static final int GIVE_UP = 1<<16;
  236.55 -
  236.56 -    public static final  class Entry {
  236.57 -        
  236.58 -        public final String name;
  236.59 -        final long offset;
  236.60 -        private final long dosTime;
  236.61 -        
  236.62 -        Entry (String name, long offset, long time) {
  236.63 -            assert name != null;
  236.64 -            this.name = name;
  236.65 -            this.offset = offset;
  236.66 -            this.dosTime = time;
  236.67 -        }        
  236.68 -/*        
  236.69 -        public long getTime () {
  236.70 -            Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
  236.71 -                    (int)(((dosTime >> 21) & 0x0f) - 1),
  236.72 -                    (int)((dosTime >> 16) & 0x1f),
  236.73 -                    (int)((dosTime >> 11) & 0x1f),
  236.74 -                    (int)((dosTime >> 5) & 0x3f),
  236.75 -                    (int)((dosTime << 1) & 0x3e));
  236.76 -            return d.getTime();
  236.77 -        }
  236.78 -        */
  236.79 -    }
  236.80 -    
  236.81 -    public InputStream getInputStream (final Entry e) throws IOException {
  236.82 -        return getInputStream(arr, e.offset);
  236.83 -    }
  236.84 -    
  236.85 -    private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
  236.86 -        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  236.87 -        is.skip(offset);
  236.88 -        ZipInputStream in = new ZipInputStream (is);
  236.89 -        ZipEntry e = in.getNextEntry();
  236.90 -        if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
  236.91 -            int cp = arr.length - is.available();
  236.92 -            return new ByteArrayInputStream(arr, cp, (int)e.getSize());
  236.93 -        }
  236.94 -        return in;
  236.95 -    }
  236.96 -    
  236.97 -    public Entry[] list() throws IOException {
  236.98 -        final int size = arr.length;
  236.99 -
 236.100 -        int at = size - ZipInputStream.ENDHDR;
 236.101 -
 236.102 -        byte[] data = new byte[ZipInputStream.ENDHDR];        
 236.103 -        int giveup = 0;
 236.104 -
 236.105 -        do {
 236.106 -            org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
 236.107 -            at--;
 236.108 -            giveup++;
 236.109 -            if (giveup > GIVE_UP) {
 236.110 -                throw new IOException ();
 236.111 -            }
 236.112 -        } while (getsig(data) != ZipInputStream.ENDSIG);
 236.113 -
 236.114 -
 236.115 -        final long censize = endsiz(data);
 236.116 -        final long cenoff  = endoff(data);
 236.117 -        at = (int) cenoff;                                                     
 236.118 -
 236.119 -        Entry[] result = new Entry[0];
 236.120 -        int cenread = 0;
 236.121 -        data = new byte[ZipInputStream.CENHDR];
 236.122 -        while (cenread < censize) {
 236.123 -            org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
 236.124 -            at += data.length;
 236.125 -            if (getsig(data) != ZipInputStream.CENSIG) {
 236.126 -                throw new IOException("No central table");          //NOI18N
 236.127 -            }
 236.128 -            int cennam = cennam(data);
 236.129 -            int cenext = cenext(data);
 236.130 -            int cencom = cencom(data);
 236.131 -            long lhoff = cenoff(data);
 236.132 -            long centim = centim(data);
 236.133 -            String name = new String(arr, at, cennam, "UTF-8");
 236.134 -            at += cennam;
 236.135 -            int seekby = cenext+cencom;
 236.136 -            int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
 236.137 -            cenread+=cendatalen;
 236.138 -            result = addEntry(result, new Entry(name,lhoff, centim));
 236.139 -            at += seekby;
 236.140 -        }
 236.141 -        return result;
 236.142 -    }
 236.143 -
 236.144 -    private Entry[] addEntry(Entry[] result, Entry entry) {
 236.145 -        Entry[] e = new Entry[result.length + 1];
 236.146 -        e[result.length] = entry;
 236.147 -        org.apidesign.bck2brwsr.emul.lang.System.arraycopy(result, 0, e, 0, result.length);
 236.148 -        return e;
 236.149 -    }
 236.150 -
 236.151 -    private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
 236.152 -    private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
 236.153 -    private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
 236.154 -    private static final long  cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
 236.155 -    private static final long  censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
 236.156 -    private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
 236.157 -    private static final int  cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
 236.158 -    private static final int  cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
 236.159 -    private static final int  cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
 236.160 -    private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
 236.161 -    private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
 236.162 -    private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
 236.163 -    private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
 236.164 -    private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
 236.165 -    
 236.166 -    private static final int get16(final byte[] b, int off) throws IOException {        
 236.167 -        final int b1 = b[off];
 236.168 -	final int b2 = b[off+1];
 236.169 -        return (b1 & 0xff) | ((b2 & 0xff) << 8);
 236.170 -    }
 236.171 -
 236.172 -    private static final long get32(final byte[] b, int off) throws IOException {
 236.173 -	final int s1 = get16(b, off);
 236.174 -	final int s2 = get16(b, off+2);
 236.175 -        return s1 | ((long)s2 << 16);
 236.176 -    }
 236.177 -
 236.178 -}
   237.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java	Mon Feb 25 19:00:08 2013 +0100
   237.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   237.3 @@ -1,215 +0,0 @@
   237.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   237.5 -/*
   237.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   237.7 -
   237.8 -Redistribution and use in source and binary forms, with or without
   237.9 -modification, are permitted provided that the following conditions are met:
  237.10 -
  237.11 -  1. Redistributions of source code must retain the above copyright notice,
  237.12 -     this list of conditions and the following disclaimer.
  237.13 -
  237.14 -  2. Redistributions in binary form must reproduce the above copyright 
  237.15 -     notice, this list of conditions and the following disclaimer in 
  237.16 -     the documentation and/or other materials provided with the distribution.
  237.17 -
  237.18 -  3. The names of the authors may not be used to endorse or promote products
  237.19 -     derived from this software without specific prior written permission.
  237.20 -
  237.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  237.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  237.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  237.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  237.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  237.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  237.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  237.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  237.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  237.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  237.31 - */
  237.32 -/*
  237.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  237.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  237.35 - * and contributors of zlib.
  237.36 - */
  237.37 -
  237.38 -package org.apidesign.bck2brwsr.emul.zip;
  237.39 -
  237.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  237.41 -import java.io.UnsupportedEncodingException;
  237.42 -
  237.43 -/**
  237.44 - * @see "http://www.ietf.org/rfc/rfc1952.txt"
  237.45 - */
  237.46 -final class GZIPHeader implements Cloneable {
  237.47 -
  237.48 -  public static final byte OS_MSDOS = (byte) 0x00;
  237.49 -  public static final byte OS_AMIGA = (byte) 0x01;
  237.50 -  public static final byte OS_VMS = (byte) 0x02;
  237.51 -  public static final byte OS_UNIX = (byte) 0x03;
  237.52 -  public static final byte OS_ATARI = (byte) 0x05;
  237.53 -  public static final byte OS_OS2 = (byte) 0x06;
  237.54 -  public static final byte OS_MACOS = (byte) 0x07;
  237.55 -  public static final byte OS_TOPS20 = (byte) 0x0a;
  237.56 -  public static final byte OS_WIN32 = (byte) 0x0b;
  237.57 -  public static final byte OS_VMCMS = (byte) 0x04;
  237.58 -  public static final byte OS_ZSYSTEM = (byte) 0x08;
  237.59 -  public static final byte OS_CPM = (byte) 0x09;
  237.60 -  public static final byte OS_QDOS = (byte) 0x0c;
  237.61 -  public static final byte OS_RISCOS = (byte) 0x0d;
  237.62 -  public static final byte OS_UNKNOWN = (byte) 0xff;
  237.63 -
  237.64 -  boolean text = false;
  237.65 -  private boolean fhcrc = false;
  237.66 -  long time;
  237.67 -  int xflags;
  237.68 -  int os = 255;
  237.69 -  byte[] extra;
  237.70 -  byte[] name;
  237.71 -  byte[] comment;
  237.72 -  int hcrc;
  237.73 -  long crc;
  237.74 -  boolean done = false;
  237.75 -  long mtime = 0;
  237.76 -
  237.77 -  public void setModifiedTime(long mtime) {
  237.78 -    this.mtime = mtime;
  237.79 -  }
  237.80 -
  237.81 -  public long getModifiedTime() {
  237.82 -    return mtime;
  237.83 -  }
  237.84 -
  237.85 -  public void setOS(int os) {
  237.86 -    if((0<=os && os <=13) || os==255)
  237.87 -      this.os=os;
  237.88 -    else
  237.89 -      throw new IllegalArgumentException("os: "+os);
  237.90 -  }
  237.91 -
  237.92 -  public int getOS(){
  237.93 -    return os;
  237.94 -  }
  237.95 -
  237.96 -  public void setName(String name) {
  237.97 -    try{
  237.98 -      this.name=name.getBytes("ISO-8859-1");
  237.99 -    }
 237.100 -    catch(UnsupportedEncodingException e){
 237.101 -      throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
 237.102 -    }
 237.103 -  }
 237.104 -
 237.105 -  public String getName(){
 237.106 -    if(name==null) return "";
 237.107 -    try {
 237.108 -      return new String(name, "ISO-8859-1");
 237.109 -    }
 237.110 -    catch (UnsupportedEncodingException e) {
 237.111 -      throw new IllegalArgumentException(e.toString());
 237.112 -    }
 237.113 -  }
 237.114 -
 237.115 -  public void setComment(String comment) {
 237.116 -    try{
 237.117 -      this.comment=comment.getBytes("ISO-8859-1");
 237.118 -    }
 237.119 -    catch(UnsupportedEncodingException e){
 237.120 -      throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
 237.121 -    }
 237.122 -  }
 237.123 -
 237.124 -  public String getComment(){
 237.125 -    if(comment==null) return "";
 237.126 -    try {
 237.127 -      return new String(comment, "ISO-8859-1");
 237.128 -    }
 237.129 -    catch (UnsupportedEncodingException e) {
 237.130 -      throw new IllegalArgumentException(e.toString());
 237.131 -    }
 237.132 -  }
 237.133 -
 237.134 -  public void setCRC(long crc){
 237.135 -    this.crc = crc;
 237.136 -  }
 237.137 -
 237.138 -  public long getCRC(){
 237.139 -    return crc;
 237.140 -  }
 237.141 -/*
 237.142 -  void put(Deflate d){
 237.143 -    int flag = 0;
 237.144 -    if(text){
 237.145 -      flag |= 1;     // FTEXT
 237.146 -    }
 237.147 -    if(fhcrc){
 237.148 -      flag |= 2;     // FHCRC
 237.149 -    }
 237.150 -    if(extra!=null){
 237.151 -      flag |= 4;     // FEXTRA
 237.152 -    }
 237.153 -    if(name!=null){
 237.154 -      flag |= 8;    // FNAME
 237.155 -    }
 237.156 -    if(comment!=null){
 237.157 -      flag |= 16;   // FCOMMENT
 237.158 -    }
 237.159 -    int xfl = 0;
 237.160 -    if(d.level == JZlib.Z_BEST_SPEED){
 237.161 -      xfl |= 4;
 237.162 -    }
 237.163 -    else if (d.level == JZlib.Z_BEST_COMPRESSION){
 237.164 -      xfl |= 2;
 237.165 -    }
 237.166 -
 237.167 -    d.put_short((short)0x8b1f);  // ID1 ID2
 237.168 -    d.put_byte((byte)8);         // CM(Compression Method)
 237.169 -    d.put_byte((byte)flag);
 237.170 -    d.put_byte((byte)mtime);
 237.171 -    d.put_byte((byte)(mtime>>8));
 237.172 -    d.put_byte((byte)(mtime>>16));
 237.173 -    d.put_byte((byte)(mtime>>24));
 237.174 -    d.put_byte((byte)xfl);
 237.175 -    d.put_byte((byte)os);
 237.176 -
 237.177 -    if(extra!=null){
 237.178 -      d.put_byte((byte)extra.length);
 237.179 -      d.put_byte((byte)(extra.length>>8));
 237.180 -      d.put_byte(extra, 0, extra.length);
 237.181 -    }
 237.182 -
 237.183 -    if(name!=null){
 237.184 -      d.put_byte(name, 0, name.length);
 237.185 -      d.put_byte((byte)0);
 237.186 -    }
 237.187 -
 237.188 -    if(comment!=null){
 237.189 -      d.put_byte(comment, 0, comment.length);
 237.190 -      d.put_byte((byte)0);
 237.191 -    }
 237.192 -  }
 237.193 -*/
 237.194 -  @Override
 237.195 -  public Object clone() throws CloneNotSupportedException {
 237.196 -    GZIPHeader gheader = (GZIPHeader)super.clone();
 237.197 -    byte[] tmp;
 237.198 -    if(gheader.extra!=null){
 237.199 -      tmp=new byte[gheader.extra.length];
 237.200 -      System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
 237.201 -      gheader.extra = tmp;
 237.202 -    }
 237.203 -
 237.204 -    if(gheader.name!=null){
 237.205 -      tmp=new byte[gheader.name.length];
 237.206 -      System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
 237.207 -      gheader.name = tmp;
 237.208 -    }
 237.209 -
 237.210 -    if(gheader.comment!=null){
 237.211 -      tmp=new byte[gheader.comment.length];
 237.212 -      System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
 237.213 -      gheader.comment = tmp;
 237.214 -    }
 237.215 -
 237.216 -    return gheader;
 237.217 -  }
 237.218 -}
   238.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java	Mon Feb 25 19:00:08 2013 +0100
   238.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   238.3 @@ -1,616 +0,0 @@
   238.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   238.5 -/*
   238.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   238.7 -
   238.8 -Redistribution and use in source and binary forms, with or without
   238.9 -modification, are permitted provided that the following conditions are met:
  238.10 -
  238.11 -  1. Redistributions of source code must retain the above copyright notice,
  238.12 -     this list of conditions and the following disclaimer.
  238.13 -
  238.14 -  2. Redistributions in binary form must reproduce the above copyright 
  238.15 -     notice, this list of conditions and the following disclaimer in 
  238.16 -     the documentation and/or other materials provided with the distribution.
  238.17 -
  238.18 -  3. The names of the authors may not be used to endorse or promote products
  238.19 -     derived from this software without specific prior written permission.
  238.20 -
  238.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  238.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  238.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  238.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  238.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  238.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  238.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  238.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  238.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  238.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  238.31 - */
  238.32 -/*
  238.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  238.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  238.35 - * and contributors of zlib.
  238.36 - */
  238.37 -
  238.38 -package org.apidesign.bck2brwsr.emul.zip;
  238.39 -
  238.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  238.41 -
  238.42 -final class InfBlocks{
  238.43 -  static final private int MANY=1440;
  238.44 -
  238.45 -  // And'ing with mask[n] masks the lower n bits
  238.46 -  static final private int[] inflate_mask = {
  238.47 -    0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
  238.48 -    0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
  238.49 -    0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
  238.50 -    0x00007fff, 0x0000ffff
  238.51 -  };
  238.52 -
  238.53 -  // Table for deflate from PKZIP's appnote.txt.
  238.54 -  static final int[] border = { // Order of the bit length code lengths
  238.55 -    16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  238.56 -  };
  238.57 -
  238.58 -  static final private int Z_OK=0;
  238.59 -  static final private int Z_STREAM_END=1;
  238.60 -  static final private int Z_NEED_DICT=2;
  238.61 -  static final private int Z_ERRNO=-1;
  238.62 -  static final private int Z_STREAM_ERROR=-2;
  238.63 -  static final private int Z_DATA_ERROR=-3;
  238.64 -  static final private int Z_MEM_ERROR=-4;
  238.65 -  static final private int Z_BUF_ERROR=-5;
  238.66 -  static final private int Z_VERSION_ERROR=-6;
  238.67 -
  238.68 -  static final private int TYPE=0;  // get type bits (3, including end bit)
  238.69 -  static final private int LENS=1;  // get lengths for stored
  238.70 -  static final private int STORED=2;// processing stored block
  238.71 -  static final private int TABLE=3; // get table lengths
  238.72 -  static final private int BTREE=4; // get bit lengths tree for a dynamic block
  238.73 -  static final private int DTREE=5; // get length, distance trees for a dynamic block
  238.74 -  static final private int CODES=6; // processing fixed or dynamic block
  238.75 -  static final private int DRY=7;   // output remaining window bytes
  238.76 -  static final private int DONE=8;  // finished last block, done
  238.77 -  static final private int BAD=9;   // ot a data error--stuck here
  238.78 -
  238.79 -  int mode;            // current inflate_block mode 
  238.80 -
  238.81 -  int left;            // if STORED, bytes left to copy 
  238.82 -
  238.83 -  int table;           // table lengths (14 bits) 
  238.84 -  int index;           // index into blens (or border) 
  238.85 -  int[] blens;         // bit lengths of codes 
  238.86 -  int[] bb=new int[1]; // bit length tree depth 
  238.87 -  int[] tb=new int[1]; // bit length decoding tree 
  238.88 -
  238.89 -  int[] bl=new int[1];
  238.90 -  int[] bd=new int[1];
  238.91 -
  238.92 -  int[][] tl=new int[1][];
  238.93 -  int[][] td=new int[1][];
  238.94 -  int[] tli=new int[1]; // tl_index
  238.95 -  int[] tdi=new int[1]; // td_index
  238.96 -
  238.97 -  private final InfCodes codes;      // if CODES, current state 
  238.98 -
  238.99 -  int last;            // true if this block is the last block 
 238.100 -
 238.101 -  // mode independent information 
 238.102 -  int bitk;            // bits in bit buffer 
 238.103 -  int bitb;            // bit buffer 
 238.104 -  int[] hufts;         // single malloc for tree space 
 238.105 -  byte[] window;       // sliding window 
 238.106 -  int end;             // one byte after sliding window 
 238.107 -  int read;            // window read pointer 
 238.108 -  int write;           // window write pointer 
 238.109 -  private boolean check;
 238.110 -
 238.111 -  private final InfTree inftree=new InfTree();
 238.112 -
 238.113 -  private final ZStream z; 
 238.114 -
 238.115 -  InfBlocks(ZStream z, int w){
 238.116 -    this.z=z;
 238.117 -    this.codes=new InfCodes(this.z, this);
 238.118 -    hufts=new int[MANY*3];
 238.119 -    window=new byte[w];
 238.120 -    end=w;
 238.121 -    this.check = (z.istate.wrap==0) ? false : true;
 238.122 -    mode = TYPE;
 238.123 -    reset();
 238.124 -  }
 238.125 -
 238.126 -  void reset(){
 238.127 -    if(mode==BTREE || mode==DTREE){
 238.128 -    }
 238.129 -    if(mode==CODES){
 238.130 -      codes.free(z);
 238.131 -    }
 238.132 -    mode=TYPE;
 238.133 -    bitk=0;
 238.134 -    bitb=0;
 238.135 -    read=write=0;
 238.136 -    if(check){
 238.137 -      z.adler.reset();
 238.138 -    }
 238.139 -  }
 238.140 -
 238.141 -  int proc(int r){
 238.142 -    int t;              // temporary storage
 238.143 -    int b;              // bit buffer
 238.144 -    int k;              // bits in bit buffer
 238.145 -    int p;              // input data pointer
 238.146 -    int n;              // bytes available there
 238.147 -    int q;              // output window write pointer
 238.148 -    int m;              // bytes to end of window or read pointer
 238.149 -
 238.150 -    // copy input/output information to locals (UPDATE macro restores)
 238.151 -    {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
 238.152 -    {q=write;m=(int)(q<read?read-q-1:end-q);}
 238.153 -
 238.154 -    // process input based on current state
 238.155 -    while(true){
 238.156 -      switch (mode){
 238.157 -      case TYPE:
 238.158 -
 238.159 -	while(k<(3)){
 238.160 -	  if(n!=0){
 238.161 -	    r=Z_OK;
 238.162 -	  }
 238.163 -	  else{
 238.164 -	    bitb=b; bitk=k; 
 238.165 -	    z.avail_in=n;
 238.166 -	    z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.167 -	    write=q;
 238.168 -	    return inflate_flush(r);
 238.169 -	  };
 238.170 -	  n--;
 238.171 -	  b|=(z.next_in[p++]&0xff)<<k;
 238.172 -	  k+=8;
 238.173 -	}
 238.174 -	t = (int)(b & 7);
 238.175 -	last = t & 1;
 238.176 -
 238.177 -	switch (t >>> 1){
 238.178 -        case 0:                         // stored 
 238.179 -          {b>>>=(3);k-=(3);}
 238.180 -          t = k & 7;                    // go to byte boundary
 238.181 -
 238.182 -          {b>>>=(t);k-=(t);}
 238.183 -          mode = LENS;                  // get length of stored block
 238.184 -          break;
 238.185 -        case 1:                         // fixed
 238.186 -          InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
 238.187 -          codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
 238.188 -
 238.189 -          {b>>>=(3);k-=(3);}
 238.190 -
 238.191 -          mode = CODES;
 238.192 -          break;
 238.193 -        case 2:                         // dynamic
 238.194 -
 238.195 -          {b>>>=(3);k-=(3);}
 238.196 -
 238.197 -          mode = TABLE;
 238.198 -          break;
 238.199 -        case 3:                         // illegal
 238.200 -
 238.201 -          {b>>>=(3);k-=(3);}
 238.202 -          mode = BAD;
 238.203 -          z.msg = "invalid block type";
 238.204 -          r = Z_DATA_ERROR;
 238.205 -
 238.206 -	  bitb=b; bitk=k; 
 238.207 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.208 -	  write=q;
 238.209 -	  return inflate_flush(r);
 238.210 -	}
 238.211 -	break;
 238.212 -      case LENS:
 238.213 -
 238.214 -	while(k<(32)){
 238.215 -	  if(n!=0){
 238.216 -	    r=Z_OK;
 238.217 -	  }
 238.218 -	  else{
 238.219 -	    bitb=b; bitk=k; 
 238.220 -	    z.avail_in=n;
 238.221 -	    z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.222 -	    write=q;
 238.223 -	    return inflate_flush(r);
 238.224 -	  };
 238.225 -	  n--;
 238.226 -	  b|=(z.next_in[p++]&0xff)<<k;
 238.227 -	  k+=8;
 238.228 -	}
 238.229 -
 238.230 -	if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)){
 238.231 -	  mode = BAD;
 238.232 -	  z.msg = "invalid stored block lengths";
 238.233 -	  r = Z_DATA_ERROR;
 238.234 -
 238.235 -	  bitb=b; bitk=k; 
 238.236 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.237 -	  write=q;
 238.238 -	  return inflate_flush(r);
 238.239 -	}
 238.240 -	left = (b & 0xffff);
 238.241 -	b = k = 0;                       // dump bits
 238.242 -	mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
 238.243 -	break;
 238.244 -      case STORED:
 238.245 -	if (n == 0){
 238.246 -	  bitb=b; bitk=k; 
 238.247 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.248 -	  write=q;
 238.249 -	  return inflate_flush(r);
 238.250 -	}
 238.251 -
 238.252 -	if(m==0){
 238.253 -	  if(q==end&&read!=0){
 238.254 -	    q=0; m=(int)(q<read?read-q-1:end-q);
 238.255 -	  }
 238.256 -	  if(m==0){
 238.257 -	    write=q; 
 238.258 -	    r=inflate_flush(r);
 238.259 -	    q=write;m=(int)(q<read?read-q-1:end-q);
 238.260 -	    if(q==end&&read!=0){
 238.261 -	      q=0; m=(int)(q<read?read-q-1:end-q);
 238.262 -	    }
 238.263 -	    if(m==0){
 238.264 -	      bitb=b; bitk=k; 
 238.265 -	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.266 -	      write=q;
 238.267 -	      return inflate_flush(r);
 238.268 -	    }
 238.269 -	  }
 238.270 -	}
 238.271 -	r=Z_OK;
 238.272 -
 238.273 -	t = left;
 238.274 -	if(t>n) t = n;
 238.275 -	if(t>m) t = m;
 238.276 -	System.arraycopy(z.next_in, p, window, q, t);
 238.277 -	p += t;  n -= t;
 238.278 -	q += t;  m -= t;
 238.279 -	if ((left -= t) != 0)
 238.280 -	  break;
 238.281 -	mode = last!=0 ? DRY : TYPE;
 238.282 -	break;
 238.283 -      case TABLE:
 238.284 -
 238.285 -	while(k<(14)){
 238.286 -	  if(n!=0){
 238.287 -	    r=Z_OK;
 238.288 -	  }
 238.289 -	  else{
 238.290 -	    bitb=b; bitk=k; 
 238.291 -	    z.avail_in=n;
 238.292 -	    z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.293 -	    write=q;
 238.294 -	    return inflate_flush(r);
 238.295 -	  };
 238.296 -	  n--;
 238.297 -	  b|=(z.next_in[p++]&0xff)<<k;
 238.298 -	  k+=8;
 238.299 -	}
 238.300 -
 238.301 -	table = t = (b & 0x3fff);
 238.302 -	if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
 238.303 -	  {
 238.304 -	    mode = BAD;
 238.305 -	    z.msg = "too many length or distance symbols";
 238.306 -	    r = Z_DATA_ERROR;
 238.307 -
 238.308 -	    bitb=b; bitk=k; 
 238.309 -	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.310 -	    write=q;
 238.311 -	    return inflate_flush(r);
 238.312 -	  }
 238.313 -	t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
 238.314 -	if(blens==null || blens.length<t){
 238.315 -	  blens=new int[t];
 238.316 -	}
 238.317 -	else{
 238.318 -	  for(int i=0; i<t; i++){blens[i]=0;}
 238.319 -	}
 238.320 -
 238.321 -	{b>>>=(14);k-=(14);}
 238.322 -
 238.323 -	index = 0;
 238.324 -	mode = BTREE;
 238.325 -      case BTREE:
 238.326 -	while (index < 4 + (table >>> 10)){
 238.327 -	  while(k<(3)){
 238.328 -	    if(n!=0){
 238.329 -	      r=Z_OK;
 238.330 -	    }
 238.331 -	    else{
 238.332 -	      bitb=b; bitk=k; 
 238.333 -	      z.avail_in=n;
 238.334 -	      z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.335 -	      write=q;
 238.336 -	      return inflate_flush(r);
 238.337 -	    };
 238.338 -	    n--;
 238.339 -	    b|=(z.next_in[p++]&0xff)<<k;
 238.340 -	    k+=8;
 238.341 -	  }
 238.342 -
 238.343 -	  blens[border[index++]] = b&7;
 238.344 -
 238.345 -	  {b>>>=(3);k-=(3);}
 238.346 -	}
 238.347 -
 238.348 -	while(index < 19){
 238.349 -	  blens[border[index++]] = 0;
 238.350 -	}
 238.351 -
 238.352 -	bb[0] = 7;
 238.353 -	t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
 238.354 -	if (t != Z_OK){
 238.355 -	  r = t;
 238.356 -	  if (r == Z_DATA_ERROR){
 238.357 -	    blens=null;
 238.358 -	    mode = BAD;
 238.359 -	  }
 238.360 -
 238.361 -	  bitb=b; bitk=k; 
 238.362 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.363 -	  write=q;
 238.364 -	  return inflate_flush(r);
 238.365 -	}
 238.366 -
 238.367 -	index = 0;
 238.368 -	mode = DTREE;
 238.369 -      case DTREE:
 238.370 -	while (true){
 238.371 -	  t = table;
 238.372 -	  if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
 238.373 -	    break;
 238.374 -	  }
 238.375 -
 238.376 -	  int[] h;
 238.377 -	  int i, j, c;
 238.378 -
 238.379 -	  t = bb[0];
 238.380 -
 238.381 -	  while(k<(t)){
 238.382 -	    if(n!=0){
 238.383 -	      r=Z_OK;
 238.384 -	    }
 238.385 -	    else{
 238.386 -	      bitb=b; bitk=k; 
 238.387 -	      z.avail_in=n;
 238.388 -	      z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.389 -	      write=q;
 238.390 -	      return inflate_flush(r);
 238.391 -	    };
 238.392 -	    n--;
 238.393 -	    b|=(z.next_in[p++]&0xff)<<k;
 238.394 -	    k+=8;
 238.395 -	  }
 238.396 -
 238.397 -	  if(tb[0]==-1){
 238.398 -            //System.err.println("null...");
 238.399 -	  }
 238.400 -
 238.401 -	  t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
 238.402 -	  c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
 238.403 -
 238.404 -	  if (c < 16){
 238.405 -	    b>>>=(t);k-=(t);
 238.406 -	    blens[index++] = c;
 238.407 -	  }
 238.408 -	  else { // c == 16..18
 238.409 -	    i = c == 18 ? 7 : c - 14;
 238.410 -	    j = c == 18 ? 11 : 3;
 238.411 -
 238.412 -	    while(k<(t+i)){
 238.413 -	      if(n!=0){
 238.414 -		r=Z_OK;
 238.415 -	      }
 238.416 -	      else{
 238.417 -		bitb=b; bitk=k; 
 238.418 -		z.avail_in=n;
 238.419 -		z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.420 -		write=q;
 238.421 -		return inflate_flush(r);
 238.422 -	      };
 238.423 -	      n--;
 238.424 -	      b|=(z.next_in[p++]&0xff)<<k;
 238.425 -	      k+=8;
 238.426 -	    }
 238.427 -
 238.428 -	    b>>>=(t);k-=(t);
 238.429 -
 238.430 -	    j += (b & inflate_mask[i]);
 238.431 -
 238.432 -	    b>>>=(i);k-=(i);
 238.433 -
 238.434 -	    i = index;
 238.435 -	    t = table;
 238.436 -	    if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
 238.437 -		(c == 16 && i < 1)){
 238.438 -	      blens=null;
 238.439 -	      mode = BAD;
 238.440 -	      z.msg = "invalid bit length repeat";
 238.441 -	      r = Z_DATA_ERROR;
 238.442 -
 238.443 -	      bitb=b; bitk=k; 
 238.444 -	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.445 -	      write=q;
 238.446 -	      return inflate_flush(r);
 238.447 -	    }
 238.448 -
 238.449 -	    c = c == 16 ? blens[i-1] : 0;
 238.450 -	    do{
 238.451 -	      blens[i++] = c;
 238.452 -	    }
 238.453 -	    while (--j!=0);
 238.454 -	    index = i;
 238.455 -	  }
 238.456 -	}
 238.457 -
 238.458 -	tb[0]=-1;
 238.459 -	{
 238.460 -	  bl[0] = 9;         // must be <= 9 for lookahead assumptions
 238.461 -	  bd[0] = 6;         // must be <= 9 for lookahead assumptions
 238.462 -	  t = table;
 238.463 -	  t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 
 238.464 -					    1 + ((t >> 5) & 0x1f),
 238.465 -					    blens, bl, bd, tli, tdi, hufts, z);
 238.466 -
 238.467 -	  if (t != Z_OK){
 238.468 -	    if (t == Z_DATA_ERROR){
 238.469 -	      blens=null;
 238.470 -	      mode = BAD;
 238.471 -	    }
 238.472 -	    r = t;
 238.473 -
 238.474 -	    bitb=b; bitk=k; 
 238.475 -	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.476 -	    write=q;
 238.477 -	    return inflate_flush(r);
 238.478 -	  }
 238.479 -	  codes.init(bl[0], bd[0], hufts, tli[0], hufts, tdi[0]);
 238.480 -	}
 238.481 -	mode = CODES;
 238.482 -      case CODES:
 238.483 -	bitb=b; bitk=k;
 238.484 -	z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.485 -	write=q;
 238.486 -
 238.487 -	if ((r = codes.proc(r)) != Z_STREAM_END){
 238.488 -	  return inflate_flush(r);
 238.489 -	}
 238.490 -	r = Z_OK;
 238.491 -	codes.free(z);
 238.492 -
 238.493 -	p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
 238.494 -	q=write;m=(int)(q<read?read-q-1:end-q);
 238.495 -
 238.496 -	if (last==0){
 238.497 -	  mode = TYPE;
 238.498 -	  break;
 238.499 -	}
 238.500 -	mode = DRY;
 238.501 -      case DRY:
 238.502 -	write=q; 
 238.503 -	r=inflate_flush(r); 
 238.504 -	q=write; m=(int)(q<read?read-q-1:end-q);
 238.505 -	if (read != write){
 238.506 -	  bitb=b; bitk=k; 
 238.507 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.508 -	  write=q;
 238.509 -	  return inflate_flush(r);
 238.510 -	}
 238.511 -	mode = DONE;
 238.512 -      case DONE:
 238.513 -	r = Z_STREAM_END;
 238.514 -
 238.515 -	bitb=b; bitk=k; 
 238.516 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.517 -	write=q;
 238.518 -	return inflate_flush(r);
 238.519 -      case BAD:
 238.520 -	r = Z_DATA_ERROR;
 238.521 -
 238.522 -	bitb=b; bitk=k; 
 238.523 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.524 -	write=q;
 238.525 -	return inflate_flush(r);
 238.526 -
 238.527 -      default:
 238.528 -	r = Z_STREAM_ERROR;
 238.529 -
 238.530 -	bitb=b; bitk=k; 
 238.531 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 238.532 -	write=q;
 238.533 -	return inflate_flush(r);
 238.534 -      }
 238.535 -    }
 238.536 -  }
 238.537 -
 238.538 -  void free(){
 238.539 -    reset();
 238.540 -    window=null;
 238.541 -    hufts=null;
 238.542 -    //ZFREE(z, s);
 238.543 -  }
 238.544 -
 238.545 -  void set_dictionary(byte[] d, int start, int n){
 238.546 -    System.arraycopy(d, start, window, 0, n);
 238.547 -    read = write = n;
 238.548 -  }
 238.549 -
 238.550 -  // Returns true if inflate is currently at the end of a block generated
 238.551 -  // by Z_SYNC_FLUSH or Z_FULL_FLUSH. 
 238.552 -  int sync_point(){
 238.553 -    return mode == LENS ? 1 : 0;
 238.554 -  }
 238.555 -
 238.556 -  // copy as much as possible from the sliding window to the output area
 238.557 -  int inflate_flush(int r){
 238.558 -    int n;
 238.559 -    int p;
 238.560 -    int q;
 238.561 -
 238.562 -    // local copies of source and destination pointers
 238.563 -    p = z.next_out_index;
 238.564 -    q = read;
 238.565 -
 238.566 -    // compute number of bytes to copy as far as end of window
 238.567 -    n = (int)((q <= write ? write : end) - q);
 238.568 -    if(n > z.avail_out) n = z.avail_out;
 238.569 -    if(n!=0 && r == Z_BUF_ERROR) r = Z_OK;
 238.570 -
 238.571 -    // update counters
 238.572 -    z.avail_out -= n;
 238.573 -    z.total_out += n;
 238.574 -
 238.575 -    // update check information
 238.576 -    if(check && n>0){
 238.577 -      z.adler.update(window, q, n);
 238.578 -    }
 238.579 -
 238.580 -    // copy as far as end of window
 238.581 -    System.arraycopy(window, q, z.next_out, p, n);
 238.582 -    p += n;
 238.583 -    q += n;
 238.584 -
 238.585 -    // see if more to copy at beginning of window
 238.586 -    if (q == end){
 238.587 -      // wrap pointers
 238.588 -      q = 0;
 238.589 -      if (write == end)
 238.590 -        write = 0;
 238.591 -
 238.592 -      // compute bytes to copy
 238.593 -      n = write - q;
 238.594 -      if (n > z.avail_out) n = z.avail_out;
 238.595 -      if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
 238.596 -
 238.597 -      // update counters
 238.598 -      z.avail_out -= n;
 238.599 -      z.total_out += n;
 238.600 -
 238.601 -      // update check information
 238.602 -      if(check && n>0){
 238.603 -	z.adler.update(window, q, n);
 238.604 -      }
 238.605 -
 238.606 -      // copy
 238.607 -      System.arraycopy(window, q, z.next_out, p, n);
 238.608 -      p += n;
 238.609 -      q += n;
 238.610 -    }
 238.611 -
 238.612 -    // update pointers
 238.613 -    z.next_out_index = p;
 238.614 -    read = q;
 238.615 -
 238.616 -    // done
 238.617 -    return r;
 238.618 -  }
 238.619 -}
   239.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java	Mon Feb 25 19:00:08 2013 +0100
   239.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   239.3 @@ -1,612 +0,0 @@
   239.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   239.5 -/*
   239.6 -Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
   239.7 -
   239.8 -Redistribution and use in source and binary forms, with or without
   239.9 -modification, are permitted provided that the following conditions are met:
  239.10 -
  239.11 -  1. Redistributions of source code must retain the above copyright notice,
  239.12 -     this list of conditions and the following disclaimer.
  239.13 -
  239.14 -  2. Redistributions in binary form must reproduce the above copyright 
  239.15 -     notice, this list of conditions and the following disclaimer in 
  239.16 -     the documentation and/or other materials provided with the distribution.
  239.17 -
  239.18 -  3. The names of the authors may not be used to endorse or promote products
  239.19 -     derived from this software without specific prior written permission.
  239.20 -
  239.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  239.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  239.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  239.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  239.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  239.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  239.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  239.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  239.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  239.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  239.31 - */
  239.32 -/*
  239.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  239.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  239.35 - * and contributors of zlib.
  239.36 - */
  239.37 -
  239.38 -package org.apidesign.bck2brwsr.emul.zip;
  239.39 -
  239.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  239.41 -
  239.42 -final class InfCodes{
  239.43 -
  239.44 -  static final private int[] inflate_mask = {
  239.45 -    0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
  239.46 -    0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
  239.47 -    0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
  239.48 -    0x00007fff, 0x0000ffff
  239.49 -  };
  239.50 -
  239.51 -  static final private int Z_OK=0;
  239.52 -  static final private int Z_STREAM_END=1;
  239.53 -  static final private int Z_NEED_DICT=2;
  239.54 -  static final private int Z_ERRNO=-1;
  239.55 -  static final private int Z_STREAM_ERROR=-2;
  239.56 -  static final private int Z_DATA_ERROR=-3;
  239.57 -  static final private int Z_MEM_ERROR=-4;
  239.58 -  static final private int Z_BUF_ERROR=-5;
  239.59 -  static final private int Z_VERSION_ERROR=-6;
  239.60 -
  239.61 -  // waiting for "i:"=input,
  239.62 -  //             "o:"=output,
  239.63 -  //             "x:"=nothing
  239.64 -  static final private int START=0;  // x: set up for LEN
  239.65 -  static final private int LEN=1;    // i: get length/literal/eob next
  239.66 -  static final private int LENEXT=2; // i: getting length extra (have base)
  239.67 -  static final private int DIST=3;   // i: get distance next
  239.68 -  static final private int DISTEXT=4;// i: getting distance extra
  239.69 -  static final private int COPY=5;   // o: copying bytes in window, waiting for space
  239.70 -  static final private int LIT=6;    // o: got literal, waiting for output space
  239.71 -  static final private int WASH=7;   // o: got eob, possibly still output waiting
  239.72 -  static final private int END=8;    // x: got eob and all data flushed
  239.73 -  static final private int BADCODE=9;// x: got error
  239.74 -
  239.75 -  int mode;      // current inflate_codes mode
  239.76 -
  239.77 -  // mode dependent information
  239.78 -  int len;
  239.79 -
  239.80 -  int[] tree; // pointer into tree
  239.81 -  int tree_index=0;
  239.82 -  int need;   // bits needed
  239.83 -
  239.84 -  int lit;
  239.85 -
  239.86 -  // if EXT or COPY, where and how much
  239.87 -  int get;              // bits to get for extra
  239.88 -  int dist;             // distance back to copy from
  239.89 -
  239.90 -  byte lbits;           // ltree bits decoded per branch
  239.91 -  byte dbits;           // dtree bits decoder per branch
  239.92 -  int[] ltree;          // literal/length/eob tree
  239.93 -  int ltree_index;      // literal/length/eob tree
  239.94 -  int[] dtree;          // distance tree
  239.95 -  int dtree_index;      // distance tree
  239.96 -
  239.97 -  private final ZStream z;
  239.98 -  private final InfBlocks s;
  239.99 -  InfCodes(ZStream z, InfBlocks s){
 239.100 -    this.z=z; 
 239.101 -    this.s=s; 
 239.102 -  }
 239.103 -
 239.104 -  void init(int bl, int bd,
 239.105 -	   int[] tl, int tl_index,
 239.106 -	   int[] td, int td_index){
 239.107 -    mode=START;
 239.108 -    lbits=(byte)bl;
 239.109 -    dbits=(byte)bd;
 239.110 -    ltree=tl;
 239.111 -    ltree_index=tl_index;
 239.112 -    dtree = td;
 239.113 -    dtree_index=td_index;
 239.114 -    tree=null;
 239.115 -  }
 239.116 -
 239.117 -  int proc(int r){ 
 239.118 -    int j;              // temporary storage
 239.119 -    int[] t;            // temporary pointer
 239.120 -    int tindex;         // temporary pointer
 239.121 -    int e;              // extra bits or operation
 239.122 -    int b=0;            // bit buffer
 239.123 -    int k=0;            // bits in bit buffer
 239.124 -    int p=0;            // input data pointer
 239.125 -    int n;              // bytes available there
 239.126 -    int q;              // output window write pointer
 239.127 -    int m;              // bytes to end of window or read pointer
 239.128 -    int f;              // pointer to copy strings from
 239.129 -
 239.130 -    // copy input/output information to locals (UPDATE macro restores)
 239.131 -    p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
 239.132 -    q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 239.133 -
 239.134 -    // process input and output based on current state
 239.135 -    while (true){
 239.136 -      switch (mode){
 239.137 -	// waiting for "i:"=input, "o:"=output, "x:"=nothing
 239.138 -      case START:         // x: set up for LEN
 239.139 -	if (m >= 258 && n >= 10){
 239.140 -
 239.141 -	  s.bitb=b;s.bitk=k;
 239.142 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.143 -	  s.write=q;
 239.144 -	  r = inflate_fast(lbits, dbits, 
 239.145 -			   ltree, ltree_index, 
 239.146 -			   dtree, dtree_index,
 239.147 -			   s, z);
 239.148 -
 239.149 -	  p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
 239.150 -	  q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 239.151 -
 239.152 -	  if (r != Z_OK){
 239.153 -	    mode = r == Z_STREAM_END ? WASH : BADCODE;
 239.154 -	    break;
 239.155 -	  }
 239.156 -	}
 239.157 -	need = lbits;
 239.158 -	tree = ltree;
 239.159 -	tree_index=ltree_index;
 239.160 -
 239.161 -	mode = LEN;
 239.162 -      case LEN:           // i: get length/literal/eob next
 239.163 -	j = need;
 239.164 -
 239.165 -	while(k<(j)){
 239.166 -	  if(n!=0)r=Z_OK;
 239.167 -	  else{
 239.168 -
 239.169 -	    s.bitb=b;s.bitk=k;
 239.170 -	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.171 -	    s.write=q;
 239.172 -	    return s.inflate_flush(r);
 239.173 -	  }
 239.174 -	  n--;
 239.175 -	  b|=(z.next_in[p++]&0xff)<<k;
 239.176 -	  k+=8;
 239.177 -	}
 239.178 -
 239.179 -	tindex=(tree_index+(b&inflate_mask[j]))*3;
 239.180 -
 239.181 -	b>>>=(tree[tindex+1]);
 239.182 -	k-=(tree[tindex+1]);
 239.183 -
 239.184 -	e=tree[tindex];
 239.185 -
 239.186 -	if(e == 0){               // literal
 239.187 -	  lit = tree[tindex+2];
 239.188 -	  mode = LIT;
 239.189 -	  break;
 239.190 -	}
 239.191 -	if((e & 16)!=0 ){          // length
 239.192 -	  get = e & 15;
 239.193 -	  len = tree[tindex+2];
 239.194 -	  mode = LENEXT;
 239.195 -	  break;
 239.196 -	}
 239.197 -	if ((e & 64) == 0){        // next table
 239.198 -	  need = e;
 239.199 -	  tree_index = tindex/3+tree[tindex+2];
 239.200 -	  break;
 239.201 -	}
 239.202 -	if ((e & 32)!=0){               // end of block
 239.203 -	  mode = WASH;
 239.204 -	  break;
 239.205 -	}
 239.206 -	mode = BADCODE;        // invalid code
 239.207 -	z.msg = "invalid literal/length code";
 239.208 -	r = Z_DATA_ERROR;
 239.209 -
 239.210 -	s.bitb=b;s.bitk=k;
 239.211 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.212 -	s.write=q;
 239.213 -	return s.inflate_flush(r);
 239.214 -
 239.215 -      case LENEXT:        // i: getting length extra (have base)
 239.216 -	j = get;
 239.217 -
 239.218 -	while(k<(j)){
 239.219 -	  if(n!=0)r=Z_OK;
 239.220 -	  else{
 239.221 -
 239.222 -	    s.bitb=b;s.bitk=k;
 239.223 -	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.224 -	    s.write=q;
 239.225 -	    return s.inflate_flush(r);
 239.226 -	  }
 239.227 -	  n--; b|=(z.next_in[p++]&0xff)<<k;
 239.228 -	  k+=8;
 239.229 -	}
 239.230 -
 239.231 -	len += (b & inflate_mask[j]);
 239.232 -
 239.233 -	b>>=j;
 239.234 -	k-=j;
 239.235 -
 239.236 -	need = dbits;
 239.237 -	tree = dtree;
 239.238 -	tree_index=dtree_index;
 239.239 -	mode = DIST;
 239.240 -      case DIST:          // i: get distance next
 239.241 -	j = need;
 239.242 -
 239.243 -	while(k<(j)){
 239.244 -	  if(n!=0)r=Z_OK;
 239.245 -	  else{
 239.246 -
 239.247 -	    s.bitb=b;s.bitk=k;
 239.248 -	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.249 -	    s.write=q;
 239.250 -	    return s.inflate_flush(r);
 239.251 -	  }
 239.252 -	  n--; b|=(z.next_in[p++]&0xff)<<k;
 239.253 -	  k+=8;
 239.254 -	}
 239.255 -
 239.256 -	tindex=(tree_index+(b & inflate_mask[j]))*3;
 239.257 -
 239.258 -	b>>=tree[tindex+1];
 239.259 -	k-=tree[tindex+1];
 239.260 -
 239.261 -	e = (tree[tindex]);
 239.262 -	if((e & 16)!=0){               // distance
 239.263 -	  get = e & 15;
 239.264 -	  dist = tree[tindex+2];
 239.265 -	  mode = DISTEXT;
 239.266 -	  break;
 239.267 -	}
 239.268 -	if ((e & 64) == 0){        // next table
 239.269 -	  need = e;
 239.270 -	  tree_index = tindex/3 + tree[tindex+2];
 239.271 -	  break;
 239.272 -	}
 239.273 -	mode = BADCODE;        // invalid code
 239.274 -	z.msg = "invalid distance code";
 239.275 -	r = Z_DATA_ERROR;
 239.276 -
 239.277 -	s.bitb=b;s.bitk=k;
 239.278 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.279 -	s.write=q;
 239.280 -	return s.inflate_flush(r);
 239.281 -
 239.282 -      case DISTEXT:       // i: getting distance extra
 239.283 -	j = get;
 239.284 -
 239.285 -	while(k<(j)){
 239.286 -	  if(n!=0)r=Z_OK;
 239.287 -	  else{
 239.288 -
 239.289 -	    s.bitb=b;s.bitk=k;
 239.290 -	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.291 -	    s.write=q;
 239.292 -	    return s.inflate_flush(r);
 239.293 -	  }
 239.294 -	  n--; b|=(z.next_in[p++]&0xff)<<k;
 239.295 -	  k+=8;
 239.296 -	}
 239.297 -
 239.298 -	dist += (b & inflate_mask[j]);
 239.299 -
 239.300 -	b>>=j;
 239.301 -	k-=j;
 239.302 -
 239.303 -	mode = COPY;
 239.304 -      case COPY:          // o: copying bytes in window, waiting for space
 239.305 -        f = q - dist;
 239.306 -        while(f < 0){     // modulo window size-"while" instead
 239.307 -          f += s.end;     // of "if" handles invalid distances
 239.308 -	}
 239.309 -	while (len!=0){
 239.310 -
 239.311 -	  if(m==0){
 239.312 -	    if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 239.313 -	    if(m==0){
 239.314 -	      s.write=q; r=s.inflate_flush(r);
 239.315 -	      q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 239.316 -
 239.317 -	      if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 239.318 -
 239.319 -	      if(m==0){
 239.320 -		s.bitb=b;s.bitk=k;
 239.321 -		z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.322 -		s.write=q;
 239.323 -		return s.inflate_flush(r);
 239.324 -	      }  
 239.325 -	    }
 239.326 -	  }
 239.327 -
 239.328 -	  s.window[q++]=s.window[f++]; m--;
 239.329 -
 239.330 -	  if (f == s.end)
 239.331 -            f = 0;
 239.332 -	  len--;
 239.333 -	}
 239.334 -	mode = START;
 239.335 -	break;
 239.336 -      case LIT:           // o: got literal, waiting for output space
 239.337 -	if(m==0){
 239.338 -	  if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 239.339 -	  if(m==0){
 239.340 -	    s.write=q; r=s.inflate_flush(r);
 239.341 -	    q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 239.342 -
 239.343 -	    if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 239.344 -	    if(m==0){
 239.345 -	      s.bitb=b;s.bitk=k;
 239.346 -	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.347 -	      s.write=q;
 239.348 -	      return s.inflate_flush(r);
 239.349 -	    }
 239.350 -	  }
 239.351 -	}
 239.352 -	r=Z_OK;
 239.353 -
 239.354 -	s.window[q++]=(byte)lit; m--;
 239.355 -
 239.356 -	mode = START;
 239.357 -	break;
 239.358 -      case WASH:           // o: got eob, possibly more output
 239.359 -	if (k > 7){        // return unused byte, if any
 239.360 -	  k -= 8;
 239.361 -	  n++;
 239.362 -	  p--;             // can always return one
 239.363 -	}
 239.364 -
 239.365 -	s.write=q; r=s.inflate_flush(r);
 239.366 -	q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 239.367 -
 239.368 -	if (s.read != s.write){
 239.369 -	  s.bitb=b;s.bitk=k;
 239.370 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.371 -	  s.write=q;
 239.372 -	  return s.inflate_flush(r);
 239.373 -	}
 239.374 -	mode = END;
 239.375 -      case END:
 239.376 -	r = Z_STREAM_END;
 239.377 -	s.bitb=b;s.bitk=k;
 239.378 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.379 -	s.write=q;
 239.380 -	return s.inflate_flush(r);
 239.381 -
 239.382 -      case BADCODE:       // x: got error
 239.383 -
 239.384 -	r = Z_DATA_ERROR;
 239.385 -
 239.386 -	s.bitb=b;s.bitk=k;
 239.387 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.388 -	s.write=q;
 239.389 -	return s.inflate_flush(r);
 239.390 -
 239.391 -      default:
 239.392 -	r = Z_STREAM_ERROR;
 239.393 -
 239.394 -	s.bitb=b;s.bitk=k;
 239.395 -	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.396 -	s.write=q;
 239.397 -	return s.inflate_flush(r);
 239.398 -      }
 239.399 -    }
 239.400 -  }
 239.401 -
 239.402 -  void free(ZStream z){
 239.403 -    //  ZFREE(z, c);
 239.404 -  }
 239.405 -
 239.406 -  // Called with number of bytes left to write in window at least 258
 239.407 -  // (the maximum string length) and number of input bytes available
 239.408 -  // at least ten.  The ten bytes are six bytes for the longest length/
 239.409 -  // distance pair plus four bytes for overloading the bit buffer.
 239.410 -
 239.411 -  int inflate_fast(int bl, int bd, 
 239.412 -		   int[] tl, int tl_index,
 239.413 -		   int[] td, int td_index,
 239.414 -		   InfBlocks s, ZStream z){
 239.415 -    int t;                // temporary pointer
 239.416 -    int[] tp;             // temporary pointer
 239.417 -    int tp_index;         // temporary pointer
 239.418 -    int e;                // extra bits or operation
 239.419 -    int b;                // bit buffer
 239.420 -    int k;                // bits in bit buffer
 239.421 -    int p;                // input data pointer
 239.422 -    int n;                // bytes available there
 239.423 -    int q;                // output window write pointer
 239.424 -    int m;                // bytes to end of window or read pointer
 239.425 -    int ml;               // mask for literal/length tree
 239.426 -    int md;               // mask for distance tree
 239.427 -    int c;                // bytes to copy
 239.428 -    int d;                // distance back to copy from
 239.429 -    int r;                // copy source pointer
 239.430 -
 239.431 -    int tp_index_t_3;     // (tp_index+t)*3
 239.432 -
 239.433 -    // load input, output, bit values
 239.434 -    p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
 239.435 -    q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 239.436 -
 239.437 -    // initialize masks
 239.438 -    ml = inflate_mask[bl];
 239.439 -    md = inflate_mask[bd];
 239.440 -
 239.441 -    // do until not enough input or output space for fast loop
 239.442 -    do {                          // assume called with m >= 258 && n >= 10
 239.443 -      // get literal/length code
 239.444 -      while(k<(20)){              // max bits for literal/length code
 239.445 -	n--;
 239.446 -	b|=(z.next_in[p++]&0xff)<<k;k+=8;
 239.447 -      }
 239.448 -
 239.449 -      t= b&ml;
 239.450 -      tp=tl; 
 239.451 -      tp_index=tl_index;
 239.452 -      tp_index_t_3=(tp_index+t)*3;
 239.453 -      if ((e = tp[tp_index_t_3]) == 0){
 239.454 -	b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 239.455 -
 239.456 -	s.window[q++] = (byte)tp[tp_index_t_3+2];
 239.457 -	m--;
 239.458 -	continue;
 239.459 -      }
 239.460 -      do {
 239.461 -
 239.462 -	b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 239.463 -
 239.464 -	if((e&16)!=0){
 239.465 -	  e &= 15;
 239.466 -	  c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
 239.467 -
 239.468 -	  b>>=e; k-=e;
 239.469 -
 239.470 -	  // decode distance base of block to copy
 239.471 -	  while(k<(15)){           // max bits for distance code
 239.472 -	    n--;
 239.473 -	    b|=(z.next_in[p++]&0xff)<<k;k+=8;
 239.474 -	  }
 239.475 -
 239.476 -	  t= b&md;
 239.477 -	  tp=td;
 239.478 -	  tp_index=td_index;
 239.479 -          tp_index_t_3=(tp_index+t)*3;
 239.480 -	  e = tp[tp_index_t_3];
 239.481 -
 239.482 -	  do {
 239.483 -
 239.484 -	    b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 239.485 -
 239.486 -	    if((e&16)!=0){
 239.487 -	      // get extra bits to add to distance base
 239.488 -	      e &= 15;
 239.489 -	      while(k<(e)){         // get extra bits (up to 13)
 239.490 -		n--;
 239.491 -		b|=(z.next_in[p++]&0xff)<<k;k+=8;
 239.492 -	      }
 239.493 -
 239.494 -	      d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
 239.495 -
 239.496 -	      b>>=(e); k-=(e);
 239.497 -
 239.498 -	      // do the copy
 239.499 -	      m -= c;
 239.500 -	      if (q >= d){                // offset before dest
 239.501 -		//  just copy
 239.502 -		r=q-d;
 239.503 -		if(q-r>0 && 2>(q-r)){           
 239.504 -		  s.window[q++]=s.window[r++]; // minimum count is three,
 239.505 -		  s.window[q++]=s.window[r++]; // so unroll loop a little
 239.506 -		  c-=2;
 239.507 -		}
 239.508 -		else{
 239.509 -		  System.arraycopy(s.window, r, s.window, q, 2);
 239.510 -		  q+=2; r+=2; c-=2;
 239.511 -		}
 239.512 -	      }
 239.513 -	      else{                  // else offset after destination
 239.514 -                r=q-d;
 239.515 -                do{
 239.516 -                  r+=s.end;          // force pointer in window
 239.517 -                }while(r<0);         // covers invalid distances
 239.518 -		e=s.end-r;
 239.519 -		if(c>e){             // if source crosses,
 239.520 -		  c-=e;              // wrapped copy
 239.521 -		  if(q-r>0 && e>(q-r)){           
 239.522 -		    do{s.window[q++] = s.window[r++];}
 239.523 -		    while(--e!=0);
 239.524 -		  }
 239.525 -		  else{
 239.526 -		    System.arraycopy(s.window, r, s.window, q, e);
 239.527 -		    q+=e; r+=e; e=0;
 239.528 -		  }
 239.529 -		  r = 0;                  // copy rest from start of window
 239.530 -		}
 239.531 -
 239.532 -	      }
 239.533 -
 239.534 -	      // copy all or what's left
 239.535 -	      if(q-r>0 && c>(q-r)){           
 239.536 -		do{s.window[q++] = s.window[r++];}
 239.537 -		while(--c!=0);
 239.538 -	      }
 239.539 -	      else{
 239.540 -		System.arraycopy(s.window, r, s.window, q, c);
 239.541 -		q+=c; r+=c; c=0;
 239.542 -	      }
 239.543 -	      break;
 239.544 -	    }
 239.545 -	    else if((e&64)==0){
 239.546 -	      t+=tp[tp_index_t_3+2];
 239.547 -	      t+=(b&inflate_mask[e]);
 239.548 -	      tp_index_t_3=(tp_index+t)*3;
 239.549 -	      e=tp[tp_index_t_3];
 239.550 -	    }
 239.551 -	    else{
 239.552 -	      z.msg = "invalid distance code";
 239.553 -
 239.554 -	      c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 239.555 -
 239.556 -	      s.bitb=b;s.bitk=k;
 239.557 -	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.558 -	      s.write=q;
 239.559 -
 239.560 -	      return Z_DATA_ERROR;
 239.561 -	    }
 239.562 -	  }
 239.563 -	  while(true);
 239.564 -	  break;
 239.565 -	}
 239.566 -
 239.567 -	if((e&64)==0){
 239.568 -	  t+=tp[tp_index_t_3+2];
 239.569 -	  t+=(b&inflate_mask[e]);
 239.570 -	  tp_index_t_3=(tp_index+t)*3;
 239.571 -	  if((e=tp[tp_index_t_3])==0){
 239.572 -
 239.573 -	    b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 239.574 -
 239.575 -	    s.window[q++]=(byte)tp[tp_index_t_3+2];
 239.576 -	    m--;
 239.577 -	    break;
 239.578 -	  }
 239.579 -	}
 239.580 -	else if((e&32)!=0){
 239.581 -
 239.582 -	  c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 239.583 - 
 239.584 -	  s.bitb=b;s.bitk=k;
 239.585 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.586 -	  s.write=q;
 239.587 -
 239.588 -	  return Z_STREAM_END;
 239.589 -	}
 239.590 -	else{
 239.591 -	  z.msg="invalid literal/length code";
 239.592 -
 239.593 -	  c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 239.594 -
 239.595 -	  s.bitb=b;s.bitk=k;
 239.596 -	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.597 -	  s.write=q;
 239.598 -
 239.599 -	  return Z_DATA_ERROR;
 239.600 -	}
 239.601 -      } 
 239.602 -      while(true);
 239.603 -    } 
 239.604 -    while(m>=258 && n>= 10);
 239.605 -
 239.606 -    // not enough input or output--restore pointers and return
 239.607 -    c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 239.608 -
 239.609 -    s.bitb=b;s.bitk=k;
 239.610 -    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 239.611 -    s.write=q;
 239.612 -
 239.613 -    return Z_OK;
 239.614 -  }
 239.615 -}
   240.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java	Mon Feb 25 19:00:08 2013 +0100
   240.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   240.3 @@ -1,520 +0,0 @@
   240.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
   240.5 -/*
   240.6 -Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
   240.7 -
   240.8 -Redistribution and use in source and binary forms, with or without
   240.9 -modification, are permitted provided that the following conditions are met:
  240.10 -
  240.11 -  1. Redistributions of source code must retain the above copyright notice,
  240.12 -     this list of conditions and the following disclaimer.
  240.13 -
  240.14 -  2. Redistributions in binary form must reproduce the above copyright 
  240.15 -     notice, this list of conditions and the following disclaimer in 
  240.16 -     the documentation and/or other materials provided with the distribution.
  240.17 -
  240.18 -  3. The names of the authors may not be used to endorse or promote products
  240.19 -     derived from this software without specific prior written permission.
  240.20 -
  240.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  240.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  240.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  240.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  240.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  240.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  240.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  240.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  240.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  240.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  240.31 - */
  240.32 -/*
  240.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  240.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  240.35 - * and contributors of zlib.
  240.36 - */
  240.37 -
  240.38 -package org.apidesign.bck2brwsr.emul.zip;
  240.39 -
  240.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  240.41 -
  240.42 -final class InfTree{
  240.43 -
  240.44 -  static final private int MANY=1440;
  240.45 -
  240.46 -  static final private int Z_OK=0;
  240.47 -  static final private int Z_STREAM_END=1;
  240.48 -  static final private int Z_NEED_DICT=2;
  240.49 -  static final private int Z_ERRNO=-1;
  240.50 -  static final private int Z_STREAM_ERROR=-2;
  240.51 -  static final private int Z_DATA_ERROR=-3;
  240.52 -  static final private int Z_MEM_ERROR=-4;
  240.53 -  static final private int Z_BUF_ERROR=-5;
  240.54 -  static final private int Z_VERSION_ERROR=-6;
  240.55 -
  240.56 -  static final int fixed_bl = 9;
  240.57 -  static final int fixed_bd = 5;
  240.58 -
  240.59 -  static final int[] fixed_tl = {
  240.60 -    96,7,256, 0,8,80, 0,8,16, 84,8,115,
  240.61 -    82,7,31, 0,8,112, 0,8,48, 0,9,192,
  240.62 -    80,7,10, 0,8,96, 0,8,32, 0,9,160,
  240.63 -    0,8,0, 0,8,128, 0,8,64, 0,9,224,
  240.64 -    80,7,6, 0,8,88, 0,8,24, 0,9,144,
  240.65 -    83,7,59, 0,8,120, 0,8,56, 0,9,208,
  240.66 -    81,7,17, 0,8,104, 0,8,40, 0,9,176,
  240.67 -    0,8,8, 0,8,136, 0,8,72, 0,9,240,
  240.68 -    80,7,4, 0,8,84, 0,8,20, 85,8,227,
  240.69 -    83,7,43, 0,8,116, 0,8,52, 0,9,200,
  240.70 -    81,7,13, 0,8,100, 0,8,36, 0,9,168,
  240.71 -    0,8,4, 0,8,132, 0,8,68, 0,9,232,
  240.72 -    80,7,8, 0,8,92, 0,8,28, 0,9,152,
  240.73 -    84,7,83, 0,8,124, 0,8,60, 0,9,216,
  240.74 -    82,7,23, 0,8,108, 0,8,44, 0,9,184,
  240.75 -    0,8,12, 0,8,140, 0,8,76, 0,9,248,
  240.76 -    80,7,3, 0,8,82, 0,8,18, 85,8,163,
  240.77 -    83,7,35, 0,8,114, 0,8,50, 0,9,196,
  240.78 -    81,7,11, 0,8,98, 0,8,34, 0,9,164,
  240.79 -    0,8,2, 0,8,130, 0,8,66, 0,9,228,
  240.80 -    80,7,7, 0,8,90, 0,8,26, 0,9,148,
  240.81 -    84,7,67, 0,8,122, 0,8,58, 0,9,212,
  240.82 -    82,7,19, 0,8,106, 0,8,42, 0,9,180,
  240.83 -    0,8,10, 0,8,138, 0,8,74, 0,9,244,
  240.84 -    80,7,5, 0,8,86, 0,8,22, 192,8,0,
  240.85 -    83,7,51, 0,8,118, 0,8,54, 0,9,204,
  240.86 -    81,7,15, 0,8,102, 0,8,38, 0,9,172,
  240.87 -    0,8,6, 0,8,134, 0,8,70, 0,9,236,
  240.88 -    80,7,9, 0,8,94, 0,8,30, 0,9,156,
  240.89 -    84,7,99, 0,8,126, 0,8,62, 0,9,220,
  240.90 -    82,7,27, 0,8,110, 0,8,46, 0,9,188,
  240.91 -    0,8,14, 0,8,142, 0,8,78, 0,9,252,
  240.92 -    96,7,256, 0,8,81, 0,8,17, 85,8,131,
  240.93 -    82,7,31, 0,8,113, 0,8,49, 0,9,194,
  240.94 -    80,7,10, 0,8,97, 0,8,33, 0,9,162,
  240.95 -    0,8,1, 0,8,129, 0,8,65, 0,9,226,
  240.96 -    80,7,6, 0,8,89, 0,8,25, 0,9,146,
  240.97 -    83,7,59, 0,8,121, 0,8,57, 0,9,210,
  240.98 -    81,7,17, 0,8,105, 0,8,41, 0,9,178,
  240.99 -    0,8,9, 0,8,137, 0,8,73, 0,9,242,
 240.100 -    80,7,4, 0,8,85, 0,8,21, 80,8,258,
 240.101 -    83,7,43, 0,8,117, 0,8,53, 0,9,202,
 240.102 -    81,7,13, 0,8,101, 0,8,37, 0,9,170,
 240.103 -    0,8,5, 0,8,133, 0,8,69, 0,9,234,
 240.104 -    80,7,8, 0,8,93, 0,8,29, 0,9,154,
 240.105 -    84,7,83, 0,8,125, 0,8,61, 0,9,218,
 240.106 -    82,7,23, 0,8,109, 0,8,45, 0,9,186,
 240.107 -    0,8,13, 0,8,141, 0,8,77, 0,9,250,
 240.108 -    80,7,3, 0,8,83, 0,8,19, 85,8,195,
 240.109 -    83,7,35, 0,8,115, 0,8,51, 0,9,198,
 240.110 -    81,7,11, 0,8,99, 0,8,35, 0,9,166,
 240.111 -    0,8,3, 0,8,131, 0,8,67, 0,9,230,
 240.112 -    80,7,7, 0,8,91, 0,8,27, 0,9,150,
 240.113 -    84,7,67, 0,8,123, 0,8,59, 0,9,214,
 240.114 -    82,7,19, 0,8,107, 0,8,43, 0,9,182,
 240.115 -    0,8,11, 0,8,139, 0,8,75, 0,9,246,
 240.116 -    80,7,5, 0,8,87, 0,8,23, 192,8,0,
 240.117 -    83,7,51, 0,8,119, 0,8,55, 0,9,206,
 240.118 -    81,7,15, 0,8,103, 0,8,39, 0,9,174,
 240.119 -    0,8,7, 0,8,135, 0,8,71, 0,9,238,
 240.120 -    80,7,9, 0,8,95, 0,8,31, 0,9,158,
 240.121 -    84,7,99, 0,8,127, 0,8,63, 0,9,222,
 240.122 -    82,7,27, 0,8,111, 0,8,47, 0,9,190,
 240.123 -    0,8,15, 0,8,143, 0,8,79, 0,9,254,
 240.124 -    96,7,256, 0,8,80, 0,8,16, 84,8,115,
 240.125 -    82,7,31, 0,8,112, 0,8,48, 0,9,193,
 240.126 -
 240.127 -    80,7,10, 0,8,96, 0,8,32, 0,9,161,
 240.128 -    0,8,0, 0,8,128, 0,8,64, 0,9,225,
 240.129 -    80,7,6, 0,8,88, 0,8,24, 0,9,145,
 240.130 -    83,7,59, 0,8,120, 0,8,56, 0,9,209,
 240.131 -    81,7,17, 0,8,104, 0,8,40, 0,9,177,
 240.132 -    0,8,8, 0,8,136, 0,8,72, 0,9,241,
 240.133 -    80,7,4, 0,8,84, 0,8,20, 85,8,227,
 240.134 -    83,7,43, 0,8,116, 0,8,52, 0,9,201,
 240.135 -    81,7,13, 0,8,100, 0,8,36, 0,9,169,
 240.136 -    0,8,4, 0,8,132, 0,8,68, 0,9,233,
 240.137 -    80,7,8, 0,8,92, 0,8,28, 0,9,153,
 240.138 -    84,7,83, 0,8,124, 0,8,60, 0,9,217,
 240.139 -    82,7,23, 0,8,108, 0,8,44, 0,9,185,
 240.140 -    0,8,12, 0,8,140, 0,8,76, 0,9,249,
 240.141 -    80,7,3, 0,8,82, 0,8,18, 85,8,163,
 240.142 -    83,7,35, 0,8,114, 0,8,50, 0,9,197,
 240.143 -    81,7,11, 0,8,98, 0,8,34, 0,9,165,
 240.144 -    0,8,2, 0,8,130, 0,8,66, 0,9,229,
 240.145 -    80,7,7, 0,8,90, 0,8,26, 0,9,149,
 240.146 -    84,7,67, 0,8,122, 0,8,58, 0,9,213,
 240.147 -    82,7,19, 0,8,106, 0,8,42, 0,9,181,
 240.148 -    0,8,10, 0,8,138, 0,8,74, 0,9,245,
 240.149 -    80,7,5, 0,8,86, 0,8,22, 192,8,0,
 240.150 -    83,7,51, 0,8,118, 0,8,54, 0,9,205,
 240.151 -    81,7,15, 0,8,102, 0,8,38, 0,9,173,
 240.152 -    0,8,6, 0,8,134, 0,8,70, 0,9,237,
 240.153 -    80,7,9, 0,8,94, 0,8,30, 0,9,157,
 240.154 -    84,7,99, 0,8,126, 0,8,62, 0,9,221,
 240.155 -    82,7,27, 0,8,110, 0,8,46, 0,9,189,
 240.156 -    0,8,14, 0,8,142, 0,8,78, 0,9,253,
 240.157 -    96,7,256, 0,8,81, 0,8,17, 85,8,131,
 240.158 -    82,7,31, 0,8,113, 0,8,49, 0,9,195,
 240.159 -    80,7,10, 0,8,97, 0,8,33, 0,9,163,
 240.160 -    0,8,1, 0,8,129, 0,8,65, 0,9,227,
 240.161 -    80,7,6, 0,8,89, 0,8,25, 0,9,147,
 240.162 -    83,7,59, 0,8,121, 0,8,57, 0,9,211,
 240.163 -    81,7,17, 0,8,105, 0,8,41, 0,9,179,
 240.164 -    0,8,9, 0,8,137, 0,8,73, 0,9,243,
 240.165 -    80,7,4, 0,8,85, 0,8,21, 80,8,258,
 240.166 -    83,7,43, 0,8,117, 0,8,53, 0,9,203,
 240.167 -    81,7,13, 0,8,101, 0,8,37, 0,9,171,
 240.168 -    0,8,5, 0,8,133, 0,8,69, 0,9,235,
 240.169 -    80,7,8, 0,8,93, 0,8,29, 0,9,155,
 240.170 -    84,7,83, 0,8,125, 0,8,61, 0,9,219,
 240.171 -    82,7,23, 0,8,109, 0,8,45, 0,9,187,
 240.172 -    0,8,13, 0,8,141, 0,8,77, 0,9,251,
 240.173 -    80,7,3, 0,8,83, 0,8,19, 85,8,195,
 240.174 -    83,7,35, 0,8,115, 0,8,51, 0,9,199,
 240.175 -    81,7,11, 0,8,99, 0,8,35, 0,9,167,
 240.176 -    0,8,3, 0,8,131, 0,8,67, 0,9,231,
 240.177 -    80,7,7, 0,8,91, 0,8,27, 0,9,151,
 240.178 -    84,7,67, 0,8,123, 0,8,59, 0,9,215,
 240.179 -    82,7,19, 0,8,107, 0,8,43, 0,9,183,
 240.180 -    0,8,11, 0,8,139, 0,8,75, 0,9,247,
 240.181 -    80,7,5, 0,8,87, 0,8,23, 192,8,0,
 240.182 -    83,7,51, 0,8,119, 0,8,55, 0,9,207,
 240.183 -    81,7,15, 0,8,103, 0,8,39, 0,9,175,
 240.184 -    0,8,7, 0,8,135, 0,8,71, 0,9,239,
 240.185 -    80,7,9, 0,8,95, 0,8,31, 0,9,159,
 240.186 -    84,7,99, 0,8,127, 0,8,63, 0,9,223,
 240.187 -    82,7,27, 0,8,111, 0,8,47, 0,9,191,
 240.188 -    0,8,15, 0,8,143, 0,8,79, 0,9,255
 240.189 -  };
 240.190 -  static final int[] fixed_td = {
 240.191 -    80,5,1, 87,5,257, 83,5,17, 91,5,4097,
 240.192 -    81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
 240.193 -    80,5,3, 88,5,513, 84,5,33, 92,5,8193,
 240.194 -    82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
 240.195 -    80,5,2, 87,5,385, 83,5,25, 91,5,6145,
 240.196 -    81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
 240.197 -    80,5,4, 88,5,769, 84,5,49, 92,5,12289,
 240.198 -    82,5,13, 90,5,3073, 86,5,193, 192,5,24577
 240.199 -  };
 240.200 -
 240.201 -  // Tables for deflate from PKZIP's appnote.txt.
 240.202 -  static final int[] cplens = { // Copy lengths for literal codes 257..285
 240.203 -        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
 240.204 -        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
 240.205 -  };
 240.206 -
 240.207 -  // see note #13 above about 258
 240.208 -  static final int[] cplext = { // Extra bits for literal codes 257..285
 240.209 -        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
 240.210 -        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112  // 112==invalid
 240.211 -  };
 240.212 -
 240.213 -  static final int[] cpdist = { // Copy offsets for distance codes 0..29
 240.214 -        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
 240.215 -        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
 240.216 -        8193, 12289, 16385, 24577
 240.217 -  };
 240.218 -
 240.219 -  static final int[] cpdext = { // Extra bits for distance codes
 240.220 -        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
 240.221 -        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
 240.222 -        12, 12, 13, 13};
 240.223 -
 240.224 -  // If BMAX needs to be larger than 16, then h and x[] should be uLong.
 240.225 -  static final int BMAX=15;         // maximum bit length of any code
 240.226 -
 240.227 -  int[] hn = null;  // hufts used in space
 240.228 -  int[] v = null;   // work area for huft_build 
 240.229 -  int[] c = null;   // bit length count table
 240.230 -  int[] r = null;   // table entry for structure assignment
 240.231 -  int[] u = null;   // table stack
 240.232 -  int[] x = null;   // bit offsets, then code stack
 240.233 -
 240.234 -  private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
 240.235 -                         int bindex, 
 240.236 -                         int n,   // number of codes (assumed <= 288)
 240.237 -                         int s,   // number of simple-valued codes (0..s-1)
 240.238 -                         int[] d, // list of base values for non-simple codes
 240.239 -                         int[] e, // list of extra bits for non-simple codes
 240.240 -                         int[] t, // result: starting table
 240.241 -                         int[] m, // maximum lookup bits, returns actual
 240.242 -                         int[] hp,// space for trees
 240.243 -                         int[] hn,// hufts used in space
 240.244 -                         int[] v  // working area: values in order of bit length
 240.245 -                         ){
 240.246 -    // Given a list of code lengths and a maximum table size, make a set of
 240.247 -    // tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
 240.248 -    // if the given code set is incomplete (the tables are still built in this
 240.249 -    // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
 240.250 -    // lengths), or Z_MEM_ERROR if not enough memory.
 240.251 -
 240.252 -    int a;                       // counter for codes of length k
 240.253 -    int f;                       // i repeats in table every f entries
 240.254 -    int g;                       // maximum code length
 240.255 -    int h;                       // table level
 240.256 -    int i;                       // counter, current code
 240.257 -    int j;                       // counter
 240.258 -    int k;                       // number of bits in current code
 240.259 -    int l;                       // bits per table (returned in m)
 240.260 -    int mask;                    // (1 << w) - 1, to avoid cc -O bug on HP
 240.261 -    int p;                       // pointer into c[], b[], or v[]
 240.262 -    int q;                       // points to current table
 240.263 -    int w;                       // bits before this table == (l * h)
 240.264 -    int xp;                      // pointer into x
 240.265 -    int y;                       // number of dummy codes added
 240.266 -    int z;                       // number of entries in current table
 240.267 -
 240.268 -    // Generate counts for each bit length
 240.269 -
 240.270 -    p = 0; i = n;
 240.271 -    do {
 240.272 -      c[b[bindex+p]]++; p++; i--;   // assume all entries <= BMAX
 240.273 -    }while(i!=0);
 240.274 -
 240.275 -    if(c[0] == n){                // null input--all zero length codes
 240.276 -      t[0] = -1;
 240.277 -      m[0] = 0;
 240.278 -      return Z_OK;
 240.279 -    }
 240.280 -
 240.281 -    // Find minimum and maximum length, bound *m by those
 240.282 -    l = m[0];
 240.283 -    for (j = 1; j <= BMAX; j++)
 240.284 -      if(c[j]!=0) break;
 240.285 -    k = j;                        // minimum code length
 240.286 -    if(l < j){
 240.287 -      l = j;
 240.288 -    }
 240.289 -    for (i = BMAX; i!=0; i--){
 240.290 -      if(c[i]!=0) break;
 240.291 -    }
 240.292 -    g = i;                        // maximum code length
 240.293 -    if(l > i){
 240.294 -      l = i;
 240.295 -    }
 240.296 -    m[0] = l;
 240.297 -
 240.298 -    // Adjust last length count to fill out codes, if needed
 240.299 -    for (y = 1 << j; j < i; j++, y <<= 1){
 240.300 -      if ((y -= c[j]) < 0){
 240.301 -        return Z_DATA_ERROR;
 240.302 -      }
 240.303 -    }
 240.304 -    if ((y -= c[i]) < 0){
 240.305 -      return Z_DATA_ERROR;
 240.306 -    }
 240.307 -    c[i] += y;
 240.308 -
 240.309 -    // Generate starting offsets into the value table for each length
 240.310 -    x[1] = j = 0;
 240.311 -    p = 1;  xp = 2;
 240.312 -    while (--i!=0) {                 // note that i == g from above
 240.313 -      x[xp] = (j += c[p]);
 240.314 -      xp++;
 240.315 -      p++;
 240.316 -    }
 240.317 -
 240.318 -    // Make a table of values in order of bit lengths
 240.319 -    i = 0; p = 0;
 240.320 -    do {
 240.321 -      if ((j = b[bindex+p]) != 0){
 240.322 -        v[x[j]++] = i;
 240.323 -      }
 240.324 -      p++;
 240.325 -    }
 240.326 -    while (++i < n);
 240.327 -    n = x[g];                     // set n to length of v
 240.328 -
 240.329 -    // Generate the Huffman codes and for each, make the table entries
 240.330 -    x[0] = i = 0;                 // first Huffman code is zero
 240.331 -    p = 0;                        // grab values in bit order
 240.332 -    h = -1;                       // no tables yet--level -1
 240.333 -    w = -l;                       // bits decoded == (l * h)
 240.334 -    u[0] = 0;                     // just to keep compilers happy
 240.335 -    q = 0;                        // ditto
 240.336 -    z = 0;                        // ditto
 240.337 -
 240.338 -    // go through the bit lengths (k already is bits in shortest code)
 240.339 -    for (; k <= g; k++){
 240.340 -      a = c[k];
 240.341 -      while (a--!=0){
 240.342 -	// here i is the Huffman code of length k bits for value *p
 240.343 -	// make tables up to required level
 240.344 -        while (k > w + l){
 240.345 -          h++;
 240.346 -          w += l;                 // previous table always l bits
 240.347 -	  // compute minimum size table less than or equal to l bits
 240.348 -          z = g - w;
 240.349 -          z = (z > l) ? l : z;        // table size upper limit
 240.350 -          if((f=1<<(j=k-w))>a+1){     // try a k-w bit table
 240.351 -                                      // too few codes for k-w bit table
 240.352 -            f -= a + 1;               // deduct codes from patterns left
 240.353 -            xp = k;
 240.354 -            if(j < z){
 240.355 -              while (++j < z){        // try smaller tables up to z bits
 240.356 -                if((f <<= 1) <= c[++xp])
 240.357 -                  break;              // enough codes to use up j bits
 240.358 -                f -= c[xp];           // else deduct codes from patterns
 240.359 -              }
 240.360 -	    }
 240.361 -          }
 240.362 -          z = 1 << j;                 // table entries for j-bit table
 240.363 -
 240.364 -	  // allocate new table
 240.365 -          if (hn[0] + z > MANY){       // (note: doesn't matter for fixed)
 240.366 -            return Z_DATA_ERROR;       // overflow of MANY
 240.367 -          }
 240.368 -          u[h] = q = /*hp+*/ hn[0];   // DEBUG
 240.369 -          hn[0] += z;
 240.370 - 
 240.371 -	  // connect to last table, if there is one
 240.372 -	  if(h!=0){
 240.373 -            x[h]=i;           // save pattern for backing up
 240.374 -            r[0]=(byte)j;     // bits in this table
 240.375 -            r[1]=(byte)l;     // bits to dump before this table
 240.376 -            j=i>>>(w - l);
 240.377 -            r[2] = (int)(q - u[h-1] - j);               // offset to this table
 240.378 -            System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
 240.379 -          }
 240.380 -          else{
 240.381 -            t[0] = q;               // first table is returned result
 240.382 -	  }
 240.383 -        }
 240.384 -
 240.385 -	// set up table entry in r
 240.386 -        r[1] = (byte)(k - w);
 240.387 -        if (p >= n){
 240.388 -          r[0] = 128 + 64;      // out of values--invalid code
 240.389 -	}
 240.390 -        else if (v[p] < s){
 240.391 -          r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64);  // 256 is end-of-block
 240.392 -          r[2] = v[p++];          // simple code is just the value
 240.393 -        }
 240.394 -        else{
 240.395 -          r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
 240.396 -          r[2]=d[v[p++] - s];
 240.397 -        }
 240.398 -
 240.399 -        // fill code-like entries with r
 240.400 -        f=1<<(k-w);
 240.401 -        for (j=i>>>w;j<z;j+=f){
 240.402 -          System.arraycopy(r, 0, hp, (q+j)*3, 3);
 240.403 -	}
 240.404 -
 240.405 -	// backwards increment the k-bit code i
 240.406 -        for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
 240.407 -          i ^= j;
 240.408 -	}
 240.409 -        i ^= j;
 240.410 -
 240.411 -	// backup over finished tables
 240.412 -        mask = (1 << w) - 1;      // needed on HP, cc -O bug
 240.413 -        while ((i & mask) != x[h]){
 240.414 -          h--;                    // don't need to update q
 240.415 -          w -= l;
 240.416 -          mask = (1 << w) - 1;
 240.417 -        }
 240.418 -      }
 240.419 -    }
 240.420 -    // Return Z_BUF_ERROR if we were given an incomplete table
 240.421 -    return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
 240.422 -  }
 240.423 -
 240.424 -  int inflate_trees_bits(int[] c,  // 19 code lengths
 240.425 -                         int[] bb, // bits tree desired/actual depth
 240.426 -                         int[] tb, // bits tree result
 240.427 -                         int[] hp, // space for trees
 240.428 -                         ZStream z // for messages
 240.429 -                         ){
 240.430 -    int result;
 240.431 -    initWorkArea(19);
 240.432 -    hn[0]=0;
 240.433 -    result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
 240.434 -
 240.435 -    if(result == Z_DATA_ERROR){
 240.436 -      z.msg = "oversubscribed dynamic bit lengths tree";
 240.437 -    }
 240.438 -    else if(result == Z_BUF_ERROR || bb[0] == 0){
 240.439 -      z.msg = "incomplete dynamic bit lengths tree";
 240.440 -      result = Z_DATA_ERROR;
 240.441 -    }
 240.442 -    return result;
 240.443 -  }
 240.444 -
 240.445 -  int inflate_trees_dynamic(int nl,   // number of literal/length codes
 240.446 -                            int nd,   // number of distance codes
 240.447 -                            int[] c,  // that many (total) code lengths
 240.448 -                            int[] bl, // literal desired/actual bit depth
 240.449 -                            int[] bd, // distance desired/actual bit depth 
 240.450 -                            int[] tl, // literal/length tree result
 240.451 -                            int[] td, // distance tree result
 240.452 -                            int[] hp, // space for trees
 240.453 -                            ZStream z // for messages
 240.454 -                            ){
 240.455 -    int result;
 240.456 -
 240.457 -    // build literal/length tree
 240.458 -    initWorkArea(288);
 240.459 -    hn[0]=0;
 240.460 -    result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
 240.461 -    if (result != Z_OK || bl[0] == 0){
 240.462 -      if(result == Z_DATA_ERROR){
 240.463 -        z.msg = "oversubscribed literal/length tree";
 240.464 -      }
 240.465 -      else if (result != Z_MEM_ERROR){
 240.466 -        z.msg = "incomplete literal/length tree";
 240.467 -        result = Z_DATA_ERROR;
 240.468 -      }
 240.469 -      return result;
 240.470 -    }
 240.471 -
 240.472 -    // build distance tree
 240.473 -    initWorkArea(288);
 240.474 -    result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
 240.475 -
 240.476 -    if (result != Z_OK || (bd[0] == 0 && nl > 257)){
 240.477 -      if (result == Z_DATA_ERROR){
 240.478 -        z.msg = "oversubscribed distance tree";
 240.479 -      }
 240.480 -      else if (result == Z_BUF_ERROR) {
 240.481 -        z.msg = "incomplete distance tree";
 240.482 -        result = Z_DATA_ERROR;
 240.483 -      }
 240.484 -      else if (result != Z_MEM_ERROR){
 240.485 -        z.msg = "empty distance tree with lengths";
 240.486 -        result = Z_DATA_ERROR;
 240.487 -      }
 240.488 -      return result;
 240.489 -    }
 240.490 -
 240.491 -    return Z_OK;
 240.492 -  }
 240.493 -
 240.494 -  static int inflate_trees_fixed(int[] bl,  //literal desired/actual bit depth
 240.495 -                                 int[] bd,  //distance desired/actual bit depth
 240.496 -                                 int[][] tl,//literal/length tree result
 240.497 -                                 int[][] td,//distance tree result 
 240.498 -                                 ZStream z  //for memory allocation
 240.499 -				 ){
 240.500 -    bl[0]=fixed_bl;
 240.501 -    bd[0]=fixed_bd;
 240.502 -    tl[0]=fixed_tl;
 240.503 -    td[0]=fixed_td;
 240.504 -    return Z_OK;
 240.505 -  }
 240.506 -
 240.507 -  private void initWorkArea(int vsize){
 240.508 -    if(hn==null){
 240.509 -      hn=new int[1];
 240.510 -      v=new int[vsize];
 240.511 -      c=new int[BMAX+1];
 240.512 -      r=new int[3];
 240.513 -      u=new int[BMAX];
 240.514 -      x=new int[BMAX+1];
 240.515 -    }
 240.516 -    if(v.length<vsize){ v=new int[vsize]; }
 240.517 -    for(int i=0; i<vsize; i++){v[i]=0;}
 240.518 -    for(int i=0; i<BMAX+1; i++){c[i]=0;}
 240.519 -    for(int i=0; i<3; i++){r[i]=0;}
 240.520 -    System.arraycopy(c, 0, u, 0, BMAX);
 240.521 -    System.arraycopy(c, 0, x, 0, BMAX+1);
 240.522 -  }
 240.523 -}
   241.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflate.java	Mon Feb 25 19:00:08 2013 +0100
   241.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   241.3 @@ -1,727 +0,0 @@
   241.4 -/* -*-mode:java; c-basic-offset:2; -*- */
   241.5 -/*
   241.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
   241.7 -
   241.8 -Redistribution and use in source and binary forms, with or without
   241.9 -modification, are permitted provided that the following conditions are met:
  241.10 -
  241.11 -  1. Redistributions of source code must retain the above copyright notice,
  241.12 -     this list of conditions and the following disclaimer.
  241.13 -
  241.14 -  2. Redistributions in binary form must reproduce the above copyright 
  241.15 -     notice, this list of conditions and the following disclaimer in 
  241.16 -     the documentation and/or other materials provided with the distribution.
  241.17 -
  241.18 -  3. The names of the authors may not be used to endorse or promote products
  241.19 -     derived from this software without specific prior written permission.
  241.20 -
  241.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  241.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  241.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  241.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  241.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  241.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  241.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  241.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  241.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  241.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  241.31 - */
  241.32 -/*
  241.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  241.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  241.35 - * and contributors of zlib.
  241.36 - */
  241.37 -
  241.38 -package org.apidesign.bck2brwsr.emul.zip;
  241.39 -
  241.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  241.41 -
  241.42 -final class Inflate{
  241.43 -  
  241.44 -  static final private int MAX_WBITS=15; // 32K LZ77 window
  241.45 -
  241.46 -  // preset dictionary flag in zlib header
  241.47 -  static final private int PRESET_DICT=0x20;
  241.48 -
  241.49 -  static final int Z_NO_FLUSH=0;
  241.50 -  static final int Z_PARTIAL_FLUSH=1;
  241.51 -  static final int Z_SYNC_FLUSH=2;
  241.52 -  static final int Z_FULL_FLUSH=3;
  241.53 -  static final int Z_FINISH=4;
  241.54 -
  241.55 -  static final private int Z_DEFLATED=8;
  241.56 -
  241.57 -  static final private int Z_OK=0;
  241.58 -  static final private int Z_STREAM_END=1;
  241.59 -  static final private int Z_NEED_DICT=2;
  241.60 -  static final private int Z_ERRNO=-1;
  241.61 -  static final private int Z_STREAM_ERROR=-2;
  241.62 -  static final private int Z_DATA_ERROR=-3;
  241.63 -  static final private int Z_MEM_ERROR=-4;
  241.64 -  static final private int Z_BUF_ERROR=-5;
  241.65 -  static final private int Z_VERSION_ERROR=-6;
  241.66 -
  241.67 -  static final private int METHOD=0;   // waiting for method byte
  241.68 -  static final private int FLAG=1;     // waiting for flag byte
  241.69 -  static final private int DICT4=2;    // four dictionary check bytes to go
  241.70 -  static final private int DICT3=3;    // three dictionary check bytes to go
  241.71 -  static final private int DICT2=4;    // two dictionary check bytes to go
  241.72 -  static final private int DICT1=5;    // one dictionary check byte to go
  241.73 -  static final int DICT0=6;    // waiting for inflateSetDictionary
  241.74 -  static final private int BLOCKS=7;   // decompressing blocks
  241.75 -  static final private int CHECK4=8;   // four check bytes to go
  241.76 -  static final private int CHECK3=9;   // three check bytes to go
  241.77 -  static final private int CHECK2=10;  // two check bytes to go
  241.78 -  static final private int CHECK1=11;  // one check byte to go
  241.79 -  static final private int DONE=12;    // finished check, done
  241.80 -  static final private int BAD=13;     // got an error--stay here
  241.81 -
  241.82 -  static final private int HEAD=14;
  241.83 -  static final private int LENGTH=15;
  241.84 -  static final private int TIME=16;
  241.85 -  static final private int OS=17;
  241.86 -  static final private int EXLEN=18;
  241.87 -  static final private int EXTRA=19;
  241.88 -  static final private int NAME=20;
  241.89 -  static final private int COMMENT=21;
  241.90 -  static final private int HCRC=22;
  241.91 -  static final private int FLAGS=23;
  241.92 -
  241.93 -  int mode;                            // current inflate mode
  241.94 -
  241.95 -  // mode dependent information
  241.96 -  int method;        // if FLAGS, method byte
  241.97 -
  241.98 -  // if CHECK, check values to compare
  241.99 -  long was = -1;           // computed check value
 241.100 -  long need;               // stream check value
 241.101 -
 241.102 -  // if BAD, inflateSync's marker bytes count
 241.103 -  int marker;
 241.104 -
 241.105 -  // mode independent information
 241.106 -  int  wrap;          // flag for no wrapper
 241.107 -  int wbits;            // log2(window size)  (8..15, defaults to 15)
 241.108 -
 241.109 -  InfBlocks blocks;     // current inflate_blocks state
 241.110 -
 241.111 -  private final ZStream z;
 241.112 -
 241.113 -  private int flags; 
 241.114 -
 241.115 -  private int need_bytes = -1;
 241.116 -  private byte[] crcbuf=new byte[4];
 241.117 -
 241.118 -  GZIPHeader gheader = null;
 241.119 -
 241.120 -  int inflateReset(){
 241.121 -    if(z == null) return Z_STREAM_ERROR;
 241.122 -    
 241.123 -    z.total_in = z.total_out = 0;
 241.124 -    z.msg = null;
 241.125 -    this.mode = HEAD;
 241.126 -    this.need_bytes = -1;
 241.127 -    this.blocks.reset();
 241.128 -    return Z_OK;
 241.129 -  }
 241.130 -
 241.131 -  int inflateEnd(){
 241.132 -    if(blocks != null){
 241.133 -      blocks.free();
 241.134 -    }
 241.135 -    return Z_OK;
 241.136 -  }
 241.137 -
 241.138 -  Inflate(ZStream z){
 241.139 -    this.z=z;
 241.140 -  }
 241.141 -
 241.142 -  int inflateInit(int w){
 241.143 -    z.msg = null;
 241.144 -    blocks = null;
 241.145 -
 241.146 -    // handle undocumented wrap option (no zlib header or check)
 241.147 -    wrap = 0;
 241.148 -    if(w < 0){
 241.149 -      w = - w;
 241.150 -    }
 241.151 -    else {
 241.152 -      wrap = (w >> 4) + 1;
 241.153 -      if(w < 48)
 241.154 -        w &= 15;
 241.155 -    }
 241.156 -
 241.157 -    if(w<8 ||w>15){
 241.158 -      inflateEnd();
 241.159 -      return Z_STREAM_ERROR;
 241.160 -    }
 241.161 -    if(blocks != null && wbits != w){
 241.162 -      blocks.free();
 241.163 -      blocks=null;
 241.164 -    }
 241.165 -
 241.166 -    // set window size
 241.167 -    wbits=w;
 241.168 -
 241.169 -    this.blocks=new InfBlocks(z, 1<<w);
 241.170 -
 241.171 -    // reset state
 241.172 -    inflateReset();
 241.173 -
 241.174 -    return Z_OK;
 241.175 -  }
 241.176 -
 241.177 -  int inflate(int f){
 241.178 -    int hold = 0;
 241.179 -
 241.180 -    int r;
 241.181 -    int b;
 241.182 -
 241.183 -    if(z == null || z.next_in == null){
 241.184 -      if(f == Z_FINISH && this.mode==HEAD)
 241.185 -        return Z_OK; 
 241.186 -      return Z_STREAM_ERROR;
 241.187 -    }
 241.188 -
 241.189 -    f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
 241.190 -    r = Z_BUF_ERROR;
 241.191 -    while (true){
 241.192 -
 241.193 -      switch (this.mode){
 241.194 -      case HEAD:
 241.195 -        if(wrap==0){
 241.196 -	  this.mode = BLOCKS;
 241.197 -          break;
 241.198 -        } 
 241.199 -
 241.200 -        try { r=readBytes(2, r, f); }
 241.201 -        catch(Return e){ return e.r; }
 241.202 -
 241.203 -        if((wrap&2)!=0 && this.need == 0x8b1fL) {   // gzip header
 241.204 -	  z.adler=new CRC32();
 241.205 -          checksum(2, this.need);
 241.206 -
 241.207 -          if(gheader==null) 
 241.208 -            gheader=new GZIPHeader();
 241.209 -
 241.210 -          this.mode = FLAGS;
 241.211 -          break;
 241.212 -        }
 241.213 -
 241.214 -        flags = 0;
 241.215 -
 241.216 -        this.method = ((int)this.need)&0xff;
 241.217 -        b=((int)(this.need>>8))&0xff;
 241.218 -
 241.219 -        if((wrap&1)==0 ||  // check if zlib header allowed
 241.220 -           (((this.method << 8)+b) % 31)!=0){
 241.221 -          this.mode = BAD;
 241.222 -          z.msg = "incorrect header check";
 241.223 -          // since zlib 1.2, it is allowted to inflateSync for this case.
 241.224 -          /*
 241.225 -          this.marker = 5;       // can't try inflateSync
 241.226 -          */
 241.227 -          break;
 241.228 -        }
 241.229 -
 241.230 -        if((this.method&0xf)!=Z_DEFLATED){
 241.231 -          this.mode = BAD;
 241.232 -          z.msg="unknown compression method";
 241.233 -          // since zlib 1.2, it is allowted to inflateSync for this case.
 241.234 -	  /*
 241.235 -          this.marker = 5;       // can't try inflateSync
 241.236 -	  */
 241.237 -          break;
 241.238 -        }
 241.239 -
 241.240 -        if((this.method>>4)+8>this.wbits){
 241.241 -          this.mode = BAD;
 241.242 -          z.msg="invalid window size";
 241.243 -          // since zlib 1.2, it is allowted to inflateSync for this case.
 241.244 -	  /*
 241.245 -          this.marker = 5;       // can't try inflateSync
 241.246 -	  */
 241.247 -          break;
 241.248 -        }
 241.249 -
 241.250 -        z.adler=new Adler32();
 241.251 -
 241.252 -        if((b&PRESET_DICT)==0){
 241.253 -          this.mode = BLOCKS;
 241.254 -          break;
 241.255 -        }
 241.256 -        this.mode = DICT4;
 241.257 -      case DICT4:
 241.258 -
 241.259 -        if(z.avail_in==0)return r;r=f;
 241.260 -
 241.261 -        z.avail_in--; z.total_in++;
 241.262 -        this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
 241.263 -        this.mode=DICT3;
 241.264 -      case DICT3:
 241.265 -
 241.266 -        if(z.avail_in==0)return r;r=f;
 241.267 -
 241.268 -        z.avail_in--; z.total_in++;
 241.269 -        this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
 241.270 -        this.mode=DICT2;
 241.271 -      case DICT2:
 241.272 -
 241.273 -        if(z.avail_in==0)return r;r=f;
 241.274 -
 241.275 -        z.avail_in--; z.total_in++;
 241.276 -        this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
 241.277 -        this.mode=DICT1;
 241.278 -      case DICT1:
 241.279 -
 241.280 -        if(z.avail_in==0)return r;r=f;
 241.281 -
 241.282 -        z.avail_in--; z.total_in++;
 241.283 -        this.need += (z.next_in[z.next_in_index++]&0xffL);
 241.284 -        z.adler.reset(this.need);
 241.285 -        this.mode = DICT0;
 241.286 -        return Z_NEED_DICT;
 241.287 -      case DICT0:
 241.288 -        this.mode = BAD;
 241.289 -        z.msg = "need dictionary";
 241.290 -        this.marker = 0;       // can try inflateSync
 241.291 -        return Z_STREAM_ERROR;
 241.292 -      case BLOCKS:
 241.293 -        r = this.blocks.proc(r);
 241.294 -        if(r == Z_DATA_ERROR){
 241.295 -          this.mode = BAD;
 241.296 -          this.marker = 0;     // can try inflateSync
 241.297 -          break;
 241.298 -        }
 241.299 -        if(r == Z_OK){
 241.300 -          r = f;
 241.301 -        }
 241.302 -        if(r != Z_STREAM_END){
 241.303 -          return r;
 241.304 -        }
 241.305 -        r = f;
 241.306 -        this.was=z.adler.getValue();
 241.307 -        this.blocks.reset();
 241.308 -        if(this.wrap==0){
 241.309 -          this.mode=DONE;
 241.310 -          break;
 241.311 -        }
 241.312 -        this.mode=CHECK4;
 241.313 -      case CHECK4:
 241.314 -
 241.315 -        if(z.avail_in==0)return r;r=f;
 241.316 -
 241.317 -        z.avail_in--; z.total_in++;
 241.318 -        this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
 241.319 -        this.mode=CHECK3;
 241.320 -      case CHECK3:
 241.321 -
 241.322 -        if(z.avail_in==0)return r;r=f;
 241.323 -
 241.324 -        z.avail_in--; z.total_in++;
 241.325 -        this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
 241.326 -        this.mode = CHECK2;
 241.327 -      case CHECK2:
 241.328 -
 241.329 -        if(z.avail_in==0)return r;r=f;
 241.330 -
 241.331 -        z.avail_in--; z.total_in++;
 241.332 -        this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
 241.333 -        this.mode = CHECK1;
 241.334 -      case CHECK1:
 241.335 -
 241.336 -        if(z.avail_in==0)return r;r=f;
 241.337 -
 241.338 -        z.avail_in--; z.total_in++;
 241.339 -        this.need+=(z.next_in[z.next_in_index++]&0xffL);
 241.340 -
 241.341 -        if(flags!=0){  // gzip
 241.342 -          this.need = ((this.need&0xff000000)>>24 | 
 241.343 -                          (this.need&0x00ff0000)>>8 | 
 241.344 -                          (this.need&0x0000ff00)<<8 | 
 241.345 -                          (this.need&0x0000ffff)<<24)&0xffffffffL;
 241.346 -        }
 241.347 -
 241.348 -        if(((int)(this.was)) != ((int)(this.need))){
 241.349 -          z.msg = "incorrect data check";
 241.350 -          // chack is delayed
 241.351 -          /*
 241.352 -          this.mode = BAD;
 241.353 -          this.marker = 5;       // can't try inflateSync
 241.354 -          break;
 241.355 -	  */
 241.356 -        }
 241.357 -        else if(flags!=0 && gheader!=null){
 241.358 -          gheader.crc = this.need; 
 241.359 -        }
 241.360 -
 241.361 -        this.mode = LENGTH;
 241.362 -      case LENGTH:
 241.363 -        if (wrap!=0 && flags!=0) {
 241.364 -
 241.365 -          try { r=readBytes(4, r, f); }
 241.366 -          catch(Return e){ return e.r; }
 241.367 -
 241.368 -          if(z.msg!=null && z.msg.equals("incorrect data check")){
 241.369 -            this.mode = BAD;
 241.370 -            this.marker = 5;       // can't try inflateSync
 241.371 -            break;
 241.372 -          }
 241.373 -
 241.374 -          if (this.need != (z.total_out & 0xffffffffL)) {
 241.375 -            z.msg = "incorrect length check";
 241.376 -            this.mode = BAD;
 241.377 -            break;
 241.378 -          }
 241.379 -          z.msg = null;
 241.380 -        }
 241.381 -        else {
 241.382 -          if(z.msg!=null && z.msg.equals("incorrect data check")){
 241.383 -            this.mode = BAD;
 241.384 -            this.marker = 5;       // can't try inflateSync
 241.385 -            break;
 241.386 -          }
 241.387 -        }
 241.388 -
 241.389 -        this.mode = DONE;
 241.390 -      case DONE:
 241.391 -        return Z_STREAM_END;
 241.392 -      case BAD:
 241.393 -        return Z_DATA_ERROR;
 241.394 -
 241.395 -      case FLAGS:
 241.396 -
 241.397 -        try { r=readBytes(2, r, f); }
 241.398 -        catch(Return e){ return e.r; }
 241.399 -
 241.400 -        flags = ((int)this.need)&0xffff;
 241.401 -
 241.402 -        if ((flags & 0xff) != Z_DEFLATED) {
 241.403 -          z.msg = "unknown compression method";
 241.404 -          this.mode = BAD; 
 241.405 -          break;
 241.406 -        }
 241.407 -        if ((flags & 0xe000)!=0) {
 241.408 -          z.msg = "unknown header flags set";
 241.409 -          this.mode = BAD; 
 241.410 -          break;
 241.411 -        }
 241.412 -
 241.413 -        if ((flags & 0x0200)!=0){
 241.414 -          checksum(2, this.need);
 241.415 -        } 
 241.416 -
 241.417 -        this.mode = TIME;
 241.418 -
 241.419 -      case TIME:
 241.420 -        try { r=readBytes(4, r, f); }
 241.421 -        catch(Return e){ return e.r; }
 241.422 -        if(gheader!=null)
 241.423 -          gheader.time = this.need;
 241.424 -        if ((flags & 0x0200)!=0){
 241.425 -          checksum(4, this.need);
 241.426 -        }
 241.427 -        this.mode = OS;
 241.428 -      case OS:
 241.429 -        try { r=readBytes(2, r, f); }
 241.430 -        catch(Return e){ return e.r; }
 241.431 -        if(gheader!=null){
 241.432 -          gheader.xflags = ((int)this.need)&0xff;
 241.433 -          gheader.os = (((int)this.need)>>8)&0xff;
 241.434 -        }
 241.435 -        if ((flags & 0x0200)!=0){
 241.436 -          checksum(2, this.need);
 241.437 -        }
 241.438 -        this.mode = EXLEN;
 241.439 -      case EXLEN:
 241.440 -        if ((flags & 0x0400)!=0) {
 241.441 -          try { r=readBytes(2, r, f); }
 241.442 -          catch(Return e){ return e.r; }
 241.443 -          if(gheader!=null){
 241.444 -            gheader.extra = new byte[((int)this.need)&0xffff];
 241.445 -          }
 241.446 -          if ((flags & 0x0200)!=0){
 241.447 -            checksum(2, this.need);
 241.448 -          }
 241.449 -        }
 241.450 -        else if(gheader!=null){
 241.451 -          gheader.extra=null;
 241.452 -        }
 241.453 -        this.mode = EXTRA;
 241.454 -
 241.455 -      case EXTRA:
 241.456 -        if ((flags & 0x0400)!=0) {
 241.457 -          try { 
 241.458 -            r=readBytes(r, f);
 241.459 -            if(gheader!=null){
 241.460 -              byte[] foo = tmp_array;
 241.461 -              tmp_array=null;
 241.462 -              if(foo.length == gheader.extra.length){
 241.463 -                System.arraycopy(foo, 0, gheader.extra, 0, foo.length);
 241.464 -	      }
 241.465 -              else{
 241.466 -                z.msg = "bad extra field length";
 241.467 -                this.mode = BAD; 
 241.468 -                break;
 241.469 -	      }
 241.470 -            }
 241.471 -          }
 241.472 -          catch(Return e){ return e.r; }
 241.473 -        }
 241.474 -        else if(gheader!=null){
 241.475 -          gheader.extra=null;
 241.476 -	}
 241.477 -	this.mode = NAME;
 241.478 -      case NAME:
 241.479 -	if ((flags & 0x0800)!=0) {
 241.480 -          try { 
 241.481 -            r=readString(r, f);
 241.482 -            if(gheader!=null){
 241.483 -              gheader.name=tmp_array;
 241.484 -            }
 241.485 -            tmp_array=null;
 241.486 -          }
 241.487 -          catch(Return e){ return e.r; }
 241.488 -        }
 241.489 -        else if(gheader!=null){
 241.490 -          gheader.name=null;
 241.491 -	}
 241.492 -        this.mode = COMMENT;
 241.493 -      case COMMENT:
 241.494 -        if ((flags & 0x1000)!=0) {
 241.495 -          try { 
 241.496 -            r=readString(r, f);
 241.497 -            if(gheader!=null){
 241.498 -              gheader.comment=tmp_array;
 241.499 -            }
 241.500 -            tmp_array=null;
 241.501 -          }
 241.502 -          catch(Return e){ return e.r; }
 241.503 -        }
 241.504 -        else if(gheader!=null){
 241.505 -          gheader.comment=null;
 241.506 -	}
 241.507 -        this.mode = HCRC;
 241.508 -      case HCRC:
 241.509 -	if ((flags & 0x0200)!=0) {
 241.510 -          try { r=readBytes(2, r, f); }
 241.511 -          catch(Return e){ return e.r; }
 241.512 -          if(gheader!=null){
 241.513 -            gheader.hcrc=(int)(this.need&0xffff);
 241.514 -          }
 241.515 -          if(this.need != (z.adler.getValue()&0xffffL)){
 241.516 -            this.mode = BAD;
 241.517 -            z.msg = "header crc mismatch";
 241.518 -            this.marker = 5;       // can't try inflateSync
 241.519 -            break;
 241.520 -          }
 241.521 -        }
 241.522 -        z.adler = new CRC32();
 241.523 -
 241.524 -        this.mode = BLOCKS;
 241.525 -        break;
 241.526 -      default:
 241.527 -        return Z_STREAM_ERROR;
 241.528 -      }
 241.529 -    }
 241.530 -  }
 241.531 -
 241.532 -  int inflateSetDictionary(byte[] dictionary, int dictLength){
 241.533 -    if(z==null || (this.mode != DICT0 && this.wrap != 0)){
 241.534 -      return Z_STREAM_ERROR;
 241.535 -    }
 241.536 -
 241.537 -    int index=0;
 241.538 -    int length = dictLength;
 241.539 -
 241.540 -    if(this.mode==DICT0){
 241.541 -      long adler_need=z.adler.getValue();
 241.542 -      z.adler.reset();
 241.543 -      z.adler.update(dictionary, 0, dictLength);
 241.544 -      if(z.adler.getValue()!=adler_need){
 241.545 -        return Z_DATA_ERROR;
 241.546 -      }
 241.547 -    }
 241.548 -
 241.549 -    z.adler.reset();
 241.550 -
 241.551 -    if(length >= (1<<this.wbits)){
 241.552 -      length = (1<<this.wbits)-1;
 241.553 -      index=dictLength - length;
 241.554 -    }
 241.555 -    this.blocks.set_dictionary(dictionary, index, length);
 241.556 -    this.mode = BLOCKS;
 241.557 -    return Z_OK;
 241.558 -  }
 241.559 -
 241.560 -  static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
 241.561 -
 241.562 -  int inflateSync(){
 241.563 -    int n;       // number of bytes to look at
 241.564 -    int p;       // pointer to bytes
 241.565 -    int m;       // number of marker bytes found in a row
 241.566 -    long r, w;   // temporaries to save total_in and total_out
 241.567 -
 241.568 -    // set up
 241.569 -    if(z == null)
 241.570 -      return Z_STREAM_ERROR;
 241.571 -    if(this.mode != BAD){
 241.572 -      this.mode = BAD;
 241.573 -      this.marker = 0;
 241.574 -    }
 241.575 -    if((n=z.avail_in)==0)
 241.576 -      return Z_BUF_ERROR;
 241.577 -
 241.578 -    p=z.next_in_index;
 241.579 -    m=this.marker;
 241.580 -    // search
 241.581 -    while (n!=0 && m < 4){
 241.582 -      if(z.next_in[p] == mark[m]){
 241.583 -        m++;
 241.584 -      }
 241.585 -      else if(z.next_in[p]!=0){
 241.586 -        m = 0;
 241.587 -      }
 241.588 -      else{
 241.589 -        m = 4 - m;
 241.590 -      }
 241.591 -      p++; n--;
 241.592 -    }
 241.593 -
 241.594 -    // restore
 241.595 -    z.total_in += p-z.next_in_index;
 241.596 -    z.next_in_index = p;
 241.597 -    z.avail_in = n;
 241.598 -    this.marker = m;
 241.599 -
 241.600 -    // return no joy or set up to restart on a new block
 241.601 -    if(m != 4){
 241.602 -      return Z_DATA_ERROR;
 241.603 -    }
 241.604 -    r=z.total_in;  w=z.total_out;
 241.605 -    inflateReset();
 241.606 -    z.total_in=r;  z.total_out = w;
 241.607 -    this.mode = BLOCKS;
 241.608 -
 241.609 -    return Z_OK;
 241.610 -  }
 241.611 -
 241.612 -  // Returns true if inflate is currently at the end of a block generated
 241.613 -  // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
 241.614 -  // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
 241.615 -  // but removes the length bytes of the resulting empty stored block. When
 241.616 -  // decompressing, PPP checks that at the end of input packet, inflate is
 241.617 -  // waiting for these length bytes.
 241.618 -  int inflateSyncPoint(){
 241.619 -    if(z == null || this.blocks == null)
 241.620 -      return Z_STREAM_ERROR;
 241.621 -    return this.blocks.sync_point();
 241.622 -  }
 241.623 -
 241.624 -  private int readBytes(int n, int r, int f) throws Return{
 241.625 -    if(need_bytes == -1){
 241.626 -      need_bytes=n;
 241.627 -      this.need=0;
 241.628 -    }
 241.629 -    while(need_bytes>0){
 241.630 -      if(z.avail_in==0){ throw new Return(r); }; r=f;
 241.631 -      z.avail_in--; z.total_in++;
 241.632 -      this.need = this.need | 
 241.633 -	((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8));
 241.634 -      need_bytes--;
 241.635 -    }
 241.636 -    if(n==2){
 241.637 -      this.need&=0xffffL;
 241.638 -    }
 241.639 -    else if(n==4) {
 241.640 -      this.need&=0xffffffffL;
 241.641 -    }
 241.642 -    need_bytes=-1;
 241.643 -    return r;
 241.644 -  }
 241.645 -  class Return extends Exception{
 241.646 -    int r;
 241.647 -    Return(int r){this.r=r; }
 241.648 -  }
 241.649 -
 241.650 -  private byte[] tmp_array;
 241.651 -  private int readString(int r, int f) throws Return{
 241.652 -    int b=0; 
 241.653 -    byte[] arr = new byte[4092];
 241.654 -    int at = 0;
 241.655 -    do {
 241.656 -      if(z.avail_in==0){ throw new Return(r); }; r=f;
 241.657 -      z.avail_in--; z.total_in++;
 241.658 -      b = z.next_in[z.next_in_index];
 241.659 -      if(b!=0) arr = append(arr, z.next_in[z.next_in_index], at++);
 241.660 -      z.adler.update(z.next_in, z.next_in_index, 1);
 241.661 -      z.next_in_index++;
 241.662 -    }while(b!=0);
 241.663 -    
 241.664 -    tmp_array = copy(arr, at);
 241.665 -    
 241.666 -    return r;
 241.667 -  }
 241.668 -
 241.669 -  private int readBytes(int r, int f) throws Return{
 241.670 -    int b=0; 
 241.671 -    byte[] arr = new byte[4092];
 241.672 -    int at = 0;
 241.673 -    while(this.need>0){
 241.674 -      if(z.avail_in==0){ throw new Return(r); }; r=f;
 241.675 -      z.avail_in--; z.total_in++;
 241.676 -      b = z.next_in[z.next_in_index];
 241.677 -      arr = append(arr, z.next_in[z.next_in_index], at++);
 241.678 -      z.adler.update(z.next_in, z.next_in_index, 1);
 241.679 -      z.next_in_index++;
 241.680 -      this.need--;
 241.681 -    }
 241.682 -    
 241.683 -    tmp_array = copy(arr, at);
 241.684 -    
 241.685 -    return r;
 241.686 -  }
 241.687 -  
 241.688 -  private static byte[] copy(byte[] arr, int len) {
 241.689 -      byte[] ret = new byte[len];
 241.690 -      org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, 0, ret, 0, len);
 241.691 -      return ret;
 241.692 -  }
 241.693 -  private static byte[] append(byte[] arr, byte b, int index) {
 241.694 -      arr[index] = b;
 241.695 -      return arr;
 241.696 -  }
 241.697 -
 241.698 -  private void checksum(int n, long v){
 241.699 -    for(int i=0; i<n; i++){
 241.700 -      crcbuf[i]=(byte)(v&0xff);
 241.701 -      v>>=8;
 241.702 -    }
 241.703 -    z.adler.update(crcbuf, 0, n);
 241.704 -  }
 241.705 -
 241.706 -  public GZIPHeader getGZIPHeader(){
 241.707 -    return gheader;
 241.708 -  }
 241.709 -
 241.710 -  boolean inParsingHeader(){
 241.711 -    switch(mode){
 241.712 -      case HEAD:
 241.713 -      case DICT4:
 241.714 -      case DICT3:
 241.715 -      case DICT2:
 241.716 -      case DICT1:
 241.717 -      case FLAGS:
 241.718 -      case TIME:
 241.719 -      case OS:
 241.720 -      case EXLEN:
 241.721 -      case EXTRA:
 241.722 -      case NAME:
 241.723 -      case COMMENT:
 241.724 -      case HCRC:
 241.725 -	return true;
 241.726 -      default:
 241.727 -	return false;
 241.728 -    }
 241.729 -  }
 241.730 -}
   242.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java	Mon Feb 25 19:00:08 2013 +0100
   242.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   242.3 @@ -1,338 +0,0 @@
   242.4 -/*
   242.5 - * Copyright (c) 1996, 2011, 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 org.apidesign.bck2brwsr.emul.zip;
  242.30 -
  242.31 -import java.util.zip.*;
  242.32 -import java.io.IOException;
  242.33 -
  242.34 -/**
  242.35 - * This class provides support for general purpose decompression using the
  242.36 - * popular ZLIB compression library. The ZLIB compression library was
  242.37 - * initially developed as part of the PNG graphics standard and is not
  242.38 - * protected by patents. It is fully described in the specifications at
  242.39 - * the <a href="package-summary.html#package_description">java.util.zip
  242.40 - * package description</a>.
  242.41 - *
  242.42 - * <p>The following code fragment demonstrates a trivial compression
  242.43 - * and decompression of a string using <tt>Deflater</tt> and
  242.44 - * <tt>Inflater</tt>.
  242.45 - *
  242.46 - * <blockquote><pre>
  242.47 - * try {
  242.48 - *     // Encode a String into bytes
  242.49 - *     String inputString = "blahblahblah\u20AC\u20AC";
  242.50 - *     byte[] input = inputString.getBytes("UTF-8");
  242.51 - *
  242.52 - *     // Compress the bytes
  242.53 - *     byte[] output = new byte[100];
  242.54 - *     Deflater compresser = new Deflater();
  242.55 - *     compresser.setInput(input);
  242.56 - *     compresser.finish();
  242.57 - *     int compressedDataLength = compresser.deflate(output);
  242.58 - *
  242.59 - *     // Decompress the bytes
  242.60 - *     Inflater decompresser = new Inflater();
  242.61 - *     decompresser.setInput(output, 0, compressedDataLength);
  242.62 - *     byte[] result = new byte[100];
  242.63 - *     int resultLength = decompresser.inflate(result);
  242.64 - *     decompresser.end();
  242.65 - *
  242.66 - *     // Decode the bytes into a String
  242.67 - *     String outputString = new String(result, 0, resultLength, "UTF-8");
  242.68 - * } catch(java.io.UnsupportedEncodingException ex) {
  242.69 - *     // handle
  242.70 - * } catch (java.util.zip.DataFormatException ex) {
  242.71 - *     // handle
  242.72 - * }
  242.73 - * </pre></blockquote>
  242.74 - *
  242.75 - * @see         Deflater
  242.76 - * @author      David Connelly
  242.77 - *
  242.78 - */
  242.79 -public
  242.80 -class Inflater extends java.util.zip.Inflater {
  242.81 -    private final boolean nowrap;
  242.82 -    private JzLibInflater impl;
  242.83 -    
  242.84 -    /**
  242.85 -     * Creates a new decompressor. If the parameter 'nowrap' is true then
  242.86 -     * the ZLIB header and checksum fields will not be used. This provides
  242.87 -     * compatibility with the compression format used by both GZIP and PKZIP.
  242.88 -     * <p>
  242.89 -     * Note: When using the 'nowrap' option it is also necessary to provide
  242.90 -     * an extra "dummy" byte as input. This is required by the ZLIB native
  242.91 -     * library in order to support certain optimizations.
  242.92 -     *
  242.93 -     * @param nowrap if true then support GZIP compatible compression
  242.94 -     */
  242.95 -    public Inflater(boolean nowrap) {
  242.96 -        this.nowrap = nowrap;
  242.97 -        reset();
  242.98 -    }
  242.99 -
 242.100 -    /**
 242.101 -     * Creates a new decompressor.
 242.102 -     */
 242.103 -    public Inflater() {
 242.104 -        this(false);
 242.105 -    }
 242.106 -
 242.107 -    /**
 242.108 -     * Sets input data for decompression. Should be called whenever
 242.109 -     * needsInput() returns true indicating that more input data is
 242.110 -     * required.
 242.111 -     * @param b the input data bytes
 242.112 -     * @param off the start offset of the input data
 242.113 -     * @param len the length of the input data
 242.114 -     * @see Inflater#needsInput
 242.115 -     */
 242.116 -    public void setInput(byte[] b, int off, int len) {
 242.117 -        if (b == null) {
 242.118 -            throw new NullPointerException();
 242.119 -        }
 242.120 -        if (off < 0 || len < 0 || off > b.length - len) {
 242.121 -            throw new ArrayIndexOutOfBoundsException();
 242.122 -        }
 242.123 -        impl.setInput(b, off, len, false);
 242.124 -    }
 242.125 -
 242.126 -    /**
 242.127 -     * Sets input data for decompression. Should be called whenever
 242.128 -     * needsInput() returns true indicating that more input data is
 242.129 -     * required.
 242.130 -     * @param b the input data bytes
 242.131 -     * @see Inflater#needsInput
 242.132 -     */
 242.133 -    public void setInput(byte[] b) {
 242.134 -        setInput(b, 0, b.length);
 242.135 -    }
 242.136 -
 242.137 -    /**
 242.138 -     * Sets the preset dictionary to the given array of bytes. Should be
 242.139 -     * called when inflate() returns 0 and needsDictionary() returns true
 242.140 -     * indicating that a preset dictionary is required. The method getAdler()
 242.141 -     * can be used to get the Adler-32 value of the dictionary needed.
 242.142 -     * @param b the dictionary data bytes
 242.143 -     * @param off the start offset of the data
 242.144 -     * @param len the length of the data
 242.145 -     * @see Inflater#needsDictionary
 242.146 -     * @see Inflater#getAdler
 242.147 -     */
 242.148 -    public void setDictionary(byte[] b, int off, int len) {
 242.149 -        if (b == null) {
 242.150 -            throw new NullPointerException();
 242.151 -        }
 242.152 -        if (off < 0 || len < 0 || off > b.length - len) {
 242.153 -            throw new ArrayIndexOutOfBoundsException();
 242.154 -        }
 242.155 -        byte[] arr;
 242.156 -        if (off == 0) {
 242.157 -            arr = b;
 242.158 -        } else {
 242.159 -            arr = new byte[len];
 242.160 -            org.apidesign.bck2brwsr.emul.lang.System.arraycopy(b, off, arr, 0, len);
 242.161 -        }
 242.162 -        impl.setDictionary(arr, len);
 242.163 -    }
 242.164 -
 242.165 -    /**
 242.166 -     * Sets the preset dictionary to the given array of bytes. Should be
 242.167 -     * called when inflate() returns 0 and needsDictionary() returns true
 242.168 -     * indicating that a preset dictionary is required. The method getAdler()
 242.169 -     * can be used to get the Adler-32 value of the dictionary needed.
 242.170 -     * @param b the dictionary data bytes
 242.171 -     * @see Inflater#needsDictionary
 242.172 -     * @see Inflater#getAdler
 242.173 -     */
 242.174 -    public void setDictionary(byte[] b) {
 242.175 -        impl.setDictionary(b, b.length);
 242.176 -    }
 242.177 -
 242.178 -    /**
 242.179 -     * Returns the total number of bytes remaining in the input buffer.
 242.180 -     * This can be used to find out what bytes still remain in the input
 242.181 -     * buffer after decompression has finished.
 242.182 -     * @return the total number of bytes remaining in the input buffer
 242.183 -     */
 242.184 -    public int getRemaining() {
 242.185 -        return impl.getAvailIn();
 242.186 -    }
 242.187 -
 242.188 -    /**
 242.189 -     * Returns true if no data remains in the input buffer. This can
 242.190 -     * be used to determine if #setInput should be called in order
 242.191 -     * to provide more input.
 242.192 -     * @return true if no data remains in the input buffer
 242.193 -     */
 242.194 -    public boolean needsInput() {
 242.195 -        return getRemaining() <= 0;
 242.196 -    }
 242.197 -
 242.198 -    /**
 242.199 -     * Returns true if a preset dictionary is needed for decompression.
 242.200 -     * @return true if a preset dictionary is needed for decompression
 242.201 -     * @see Inflater#setDictionary
 242.202 -     */
 242.203 -    public boolean needsDictionary() {
 242.204 -        return impl.needDict();
 242.205 -    }
 242.206 -
 242.207 -    /**
 242.208 -     * Returns true if the end of the compressed data stream has been
 242.209 -     * reached.
 242.210 -     * @return true if the end of the compressed data stream has been
 242.211 -     * reached
 242.212 -     */
 242.213 -    public boolean finished() {
 242.214 -        return impl.finished();
 242.215 -    }
 242.216 -
 242.217 -    /**
 242.218 -     * Uncompresses bytes into specified buffer. Returns actual number
 242.219 -     * of bytes uncompressed. A return value of 0 indicates that
 242.220 -     * needsInput() or needsDictionary() should be called in order to
 242.221 -     * determine if more input data or a preset dictionary is required.
 242.222 -     * In the latter case, getAdler() can be used to get the Adler-32
 242.223 -     * value of the dictionary required.
 242.224 -     * @param b the buffer for the uncompressed data
 242.225 -     * @param off the start offset of the data
 242.226 -     * @param len the maximum number of uncompressed bytes
 242.227 -     * @return the actual number of uncompressed bytes
 242.228 -     * @exception DataFormatException if the compressed data format is invalid
 242.229 -     * @see Inflater#needsInput
 242.230 -     * @see Inflater#needsDictionary
 242.231 -     */
 242.232 -    public int inflate(byte[] b, int off, int len)
 242.233 -        throws DataFormatException
 242.234 -    {
 242.235 -        if (b == null) {
 242.236 -            throw new NullPointerException();
 242.237 -        }
 242.238 -        if (off < 0 || len < 0 || off > b.length - len) {
 242.239 -            throw new ArrayIndexOutOfBoundsException();
 242.240 -        }
 242.241 -        impl.setOutput(b, off, len);
 242.242 -        int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
 242.243 -        return impl.next_out_index - off;
 242.244 -    }
 242.245 -
 242.246 -    /**
 242.247 -     * Uncompresses bytes into specified buffer. Returns actual number
 242.248 -     * of bytes uncompressed. A return value of 0 indicates that
 242.249 -     * needsInput() or needsDictionary() should be called in order to
 242.250 -     * determine if more input data or a preset dictionary is required.
 242.251 -     * In the latter case, getAdler() can be used to get the Adler-32
 242.252 -     * value of the dictionary required.
 242.253 -     * @param b the buffer for the uncompressed data
 242.254 -     * @return the actual number of uncompressed bytes
 242.255 -     * @exception DataFormatException if the compressed data format is invalid
 242.256 -     * @see Inflater#needsInput
 242.257 -     * @see Inflater#needsDictionary
 242.258 -     */
 242.259 -    public int inflate(byte[] b) throws DataFormatException {
 242.260 -        return inflate(b, 0, b.length);
 242.261 -    }
 242.262 -
 242.263 -    /**
 242.264 -     * Returns the ADLER-32 value of the uncompressed data.
 242.265 -     * @return the ADLER-32 value of the uncompressed data
 242.266 -     */
 242.267 -    public int getAdler() {
 242.268 -        return (int) impl.getAdler();
 242.269 -    }
 242.270 -
 242.271 -    /**
 242.272 -     * Returns the total number of compressed bytes input so far.
 242.273 -     *
 242.274 -     * <p>Since the number of bytes may be greater than
 242.275 -     * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
 242.276 -     * the preferred means of obtaining this information.</p>
 242.277 -     *
 242.278 -     * @return the total number of compressed bytes input so far
 242.279 -     */
 242.280 -    public int getTotalIn() {
 242.281 -        return (int) getBytesRead();
 242.282 -    }
 242.283 -
 242.284 -    /**
 242.285 -     * Returns the total number of compressed bytes input so far.</p>
 242.286 -     *
 242.287 -     * @return the total (non-negative) number of compressed bytes input so far
 242.288 -     * @since 1.5
 242.289 -     */
 242.290 -    public long getBytesRead() {
 242.291 -        return impl.total_in;
 242.292 -    }
 242.293 -
 242.294 -    /**
 242.295 -     * Returns the total number of uncompressed bytes output so far.
 242.296 -     *
 242.297 -     * <p>Since the number of bytes may be greater than
 242.298 -     * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
 242.299 -     * the preferred means of obtaining this information.</p>
 242.300 -     *
 242.301 -     * @return the total number of uncompressed bytes output so far
 242.302 -     */
 242.303 -    public int getTotalOut() {
 242.304 -        return (int) getBytesWritten();
 242.305 -    }
 242.306 -
 242.307 -    /**
 242.308 -     * Returns the total number of uncompressed bytes output so far.</p>
 242.309 -     *
 242.310 -     * @return the total (non-negative) number of uncompressed bytes output so far
 242.311 -     * @since 1.5
 242.312 -     */
 242.313 -    public long getBytesWritten() {
 242.314 -        return impl.total_out;
 242.315 -    }
 242.316 -
 242.317 -    /**
 242.318 -     * Resets inflater so that a new set of input data can be processed.
 242.319 -     */
 242.320 -    public void reset() {
 242.321 -        impl = new JzLibInflater(15, nowrap);
 242.322 -    }
 242.323 -
 242.324 -    /**
 242.325 -     * Closes the decompressor and discards any unprocessed input.
 242.326 -     * This method should be called when the decompressor is no longer
 242.327 -     * being used, but will also be called automatically by the finalize()
 242.328 -     * method. Once this method is called, the behavior of the Inflater
 242.329 -     * object is undefined.
 242.330 -     */
 242.331 -    public void end() {
 242.332 -        impl.end();
 242.333 -    }
 242.334 -
 242.335 -    /**
 242.336 -     * Closes the decompressor when garbage is collected.
 242.337 -     */
 242.338 -    protected void finalize() {
 242.339 -        end();
 242.340 -    }
 242.341 -}
   243.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java	Mon Feb 25 19:00:08 2013 +0100
   243.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   243.3 @@ -1,137 +0,0 @@
   243.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
   243.5 -/*
   243.6 -Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   243.7 -
   243.8 -Redistribution and use in source and binary forms, with or without
   243.9 -modification, are permitted provided that the following conditions are met:
  243.10 -
  243.11 -  1. Redistributions of source code must retain the above copyright notice,
  243.12 -     this list of conditions and the following disclaimer.
  243.13 -
  243.14 -  2. Redistributions in binary form must reproduce the above copyright 
  243.15 -     notice, this list of conditions and the following disclaimer in 
  243.16 -     the documentation and/or other materials provided with the distribution.
  243.17 -
  243.18 -  3. The names of the authors may not be used to endorse or promote products
  243.19 -     derived from this software without specific prior written permission.
  243.20 -
  243.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  243.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  243.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  243.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  243.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  243.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  243.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  243.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  243.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  243.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  243.31 - */
  243.32 -/*
  243.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  243.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  243.35 - * and contributors of zlib.
  243.36 - */
  243.37 -
  243.38 -package org.apidesign.bck2brwsr.emul.zip;
  243.39 -
  243.40 -final class JzLibInflater extends ZStream{
  243.41 -
  243.42 -  static final private int MAX_WBITS=15;        // 32K LZ77 window
  243.43 -  static final private int DEF_WBITS=MAX_WBITS;
  243.44 -
  243.45 -  public static final int Z_NO_FLUSH=0;
  243.46 -  static final private int Z_PARTIAL_FLUSH=1;
  243.47 -  static final private int Z_SYNC_FLUSH=2;
  243.48 -  static final private int Z_FULL_FLUSH=3;
  243.49 -  static final private int Z_FINISH=4;
  243.50 -
  243.51 -  static final private int MAX_MEM_LEVEL=9;
  243.52 -
  243.53 -  static final private int Z_OK=0;
  243.54 -  static final private int Z_STREAM_END=1;
  243.55 -  static final private int Z_NEED_DICT=2;
  243.56 -  static final private int Z_ERRNO=-1;
  243.57 -  static final private int Z_STREAM_ERROR=-2;
  243.58 -  static final private int Z_DATA_ERROR=-3;
  243.59 -  static final private int Z_MEM_ERROR=-4;
  243.60 -  static final private int Z_BUF_ERROR=-5;
  243.61 -  static final private int Z_VERSION_ERROR=-6;
  243.62 -
  243.63 -  public JzLibInflater() {
  243.64 -    super();
  243.65 -    init();
  243.66 -  }
  243.67 -
  243.68 -  public JzLibInflater(int w)  {
  243.69 -    this(w, false);
  243.70 -  }
  243.71 -
  243.72 -  public JzLibInflater(int w, boolean nowrap)  {
  243.73 -    super();
  243.74 -    int ret = init(w, nowrap);
  243.75 -    if(ret!=Z_OK)
  243.76 -      throw new IllegalStateException(ret+": "+msg);
  243.77 -  }
  243.78 -
  243.79 -  private boolean finished = false;
  243.80 -
  243.81 -  public int init(){
  243.82 -    return init(DEF_WBITS);
  243.83 -  }
  243.84 -
  243.85 -  public int init(boolean nowrap){
  243.86 -    return init(DEF_WBITS, nowrap);
  243.87 -  }
  243.88 -
  243.89 -  public int init(int w){
  243.90 -    return init(w, false);
  243.91 -  }
  243.92 -
  243.93 -  public int init(int w, boolean nowrap){
  243.94 -    finished = false;
  243.95 -    istate=new Inflate(this);
  243.96 -    return istate.inflateInit(nowrap?-w:w);
  243.97 -  }
  243.98 -
  243.99 -  public int inflate(int f){
 243.100 -    if(istate==null) return Z_STREAM_ERROR;
 243.101 -    int ret = istate.inflate(f);
 243.102 -    if(ret == Z_STREAM_END) 
 243.103 -      finished = true;
 243.104 -    return ret;
 243.105 -  }
 243.106 -
 243.107 -  public int end(){
 243.108 -    finished = true;
 243.109 -    if(istate==null) return Z_STREAM_ERROR;
 243.110 -    int ret=istate.inflateEnd();
 243.111 -//    istate = null;
 243.112 -    return ret;
 243.113 -  }
 243.114 -
 243.115 -  public int sync(){
 243.116 -    if(istate == null)
 243.117 -      return Z_STREAM_ERROR;
 243.118 -    return istate.inflateSync();
 243.119 -  }
 243.120 -
 243.121 -  public int syncPoint(){
 243.122 -    if(istate == null)
 243.123 -      return Z_STREAM_ERROR;
 243.124 -    return istate.inflateSyncPoint();
 243.125 -  }
 243.126 -
 243.127 -  public int setDictionary(byte[] dictionary, int dictLength){
 243.128 -    if(istate == null)
 243.129 -      return Z_STREAM_ERROR;
 243.130 -    return istate.inflateSetDictionary(dictionary, dictLength);
 243.131 -  }
 243.132 -
 243.133 -  public boolean finished(){
 243.134 -    return istate.mode==12 /*DONE*/;
 243.135 -  }
 243.136 -
 243.137 -  public boolean needDict() {
 243.138 -    return istate == null ? false : istate.mode == Inflate.DICT0;
 243.139 -  }
 243.140 -}
   244.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java	Mon Feb 25 19:00:08 2013 +0100
   244.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   244.3 @@ -1,253 +0,0 @@
   244.4 -/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
   244.5 -/*
   244.6 -Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
   244.7 -
   244.8 -Redistribution and use in source and binary forms, with or without
   244.9 -modification, are permitted provided that the following conditions are met:
  244.10 -
  244.11 -  1. Redistributions of source code must retain the above copyright notice,
  244.12 -     this list of conditions and the following disclaimer.
  244.13 -
  244.14 -  2. Redistributions in binary form must reproduce the above copyright 
  244.15 -     notice, this list of conditions and the following disclaimer in 
  244.16 -     the documentation and/or other materials provided with the distribution.
  244.17 -
  244.18 -  3. The names of the authors may not be used to endorse or promote products
  244.19 -     derived from this software without specific prior written permission.
  244.20 -
  244.21 -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  244.22 -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  244.23 -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  244.24 -INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  244.25 -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  244.26 -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  244.27 -OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  244.28 -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  244.29 -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  244.30 -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  244.31 - */
  244.32 -/*
  244.33 - * This program is based on zlib-1.1.3, so all credit should go authors
  244.34 - * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  244.35 - * and contributors of zlib.
  244.36 - */
  244.37 -
  244.38 -package org.apidesign.bck2brwsr.emul.zip;
  244.39 -
  244.40 -import org.apidesign.bck2brwsr.emul.lang.System;
  244.41 -
  244.42 -/**
  244.43 - * ZStream
  244.44 - *
  244.45 - * @deprecated  Not for public use in the future.
  244.46 - */
  244.47 -@Deprecated
  244.48 -class ZStream{
  244.49 -
  244.50 -  static final private int MAX_WBITS=15;        // 32K LZ77 window
  244.51 -  static final private int DEF_WBITS=MAX_WBITS;
  244.52 -
  244.53 -  static final private int Z_NO_FLUSH=0;
  244.54 -  static final private int Z_PARTIAL_FLUSH=1;
  244.55 -  static final private int Z_SYNC_FLUSH=2;
  244.56 -  static final private int Z_FULL_FLUSH=3;
  244.57 -  static final private int Z_FINISH=4;
  244.58 -
  244.59 -  static final private int MAX_MEM_LEVEL=9;
  244.60 -
  244.61 -  static final private int Z_OK=0;
  244.62 -  static final private int Z_STREAM_END=1;
  244.63 -  static final private int Z_NEED_DICT=2;
  244.64 -  static final private int Z_ERRNO=-1;
  244.65 -  static final private int Z_STREAM_ERROR=-2;
  244.66 -  static final private int Z_DATA_ERROR=-3;
  244.67 -  static final private int Z_MEM_ERROR=-4;
  244.68 -  static final private int Z_BUF_ERROR=-5;
  244.69 -  static final private int Z_VERSION_ERROR=-6;
  244.70 -
  244.71 -  public byte[] next_in;     // next input byte
  244.72 -  public int next_in_index;
  244.73 -  public int avail_in;       // number of bytes available at next_in
  244.74 -  public long total_in;      // total nb of input bytes read so far
  244.75 -
  244.76 -  public byte[] next_out;    // next output byte should be put there
  244.77 -  public int next_out_index;
  244.78 -  public int avail_out;      // remaining free space at next_out
  244.79 -  public long total_out;     // total nb of bytes output so far
  244.80 -
  244.81 -  public String msg;
  244.82 -
  244.83 -  Inflate istate; 
  244.84 -
  244.85 -  int data_type; // best guess about the data type: ascii or binary
  244.86 -
  244.87 -  Checksum adler;
  244.88 -
  244.89 -  public ZStream(){
  244.90 -    this(new Adler32());
  244.91 -  }
  244.92 -
  244.93 -  public ZStream(Checksum adler){
  244.94 -    this.adler=adler;
  244.95 -  }
  244.96 -
  244.97 -  public int inflateInit(){
  244.98 -    return inflateInit(DEF_WBITS);
  244.99 -  }
 244.100 -  public int inflateInit(boolean nowrap){
 244.101 -    return inflateInit(DEF_WBITS, nowrap);
 244.102 -  }
 244.103 -  public int inflateInit(int w){
 244.104 -    return inflateInit(w, false);
 244.105 -  }
 244.106 -
 244.107 -  public int inflateInit(int w, boolean nowrap){
 244.108 -    istate=new Inflate(this);
 244.109 -    return istate.inflateInit(nowrap?-w:w);
 244.110 -  }
 244.111 -
 244.112 -  public int inflate(int f){
 244.113 -    if(istate==null) return Z_STREAM_ERROR;
 244.114 -    return istate.inflate(f);
 244.115 -  }
 244.116 -  public int inflateEnd(){
 244.117 -    if(istate==null) return Z_STREAM_ERROR;
 244.118 -    int ret=istate.inflateEnd();
 244.119 -//    istate = null;
 244.120 -    return ret;
 244.121 -  }
 244.122 -  
 244.123 -  public int inflateSync(){
 244.124 -    if(istate == null)
 244.125 -      return Z_STREAM_ERROR;
 244.126 -    return istate.inflateSync();
 244.127 -  }
 244.128 -  public int inflateSyncPoint(){
 244.129 -    if(istate == null)
 244.130 -      return Z_STREAM_ERROR;
 244.131 -    return istate.inflateSyncPoint();
 244.132 -  }
 244.133 -  public int inflateSetDictionary(byte[] dictionary, int dictLength){
 244.134 -    if(istate == null)
 244.135 -      return Z_STREAM_ERROR;
 244.136 -    return istate.inflateSetDictionary(dictionary, dictLength);
 244.137 -  }
 244.138 -  public boolean inflateFinished(){
 244.139 -    return istate.mode==12 /*DONE*/;
 244.140 -  }
 244.141 -
 244.142 -
 244.143 -  public long getAdler(){
 244.144 -    return adler.getValue();
 244.145 -  }
 244.146 -
 244.147 -  public void free(){
 244.148 -    next_in=null;
 244.149 -    next_out=null;
 244.150 -    msg=null;
 244.151 -  }
 244.152 -
 244.153 -  public void setOutput(byte[] buf){
 244.154 -    setOutput(buf, 0, buf.length); 
 244.155 -  }
 244.156 -
 244.157 -  public void setOutput(byte[] buf, int off, int len){
 244.158 -    next_out = buf;
 244.159 -    next_out_index = off;
 244.160 -    avail_out = len;
 244.161 -  }
 244.162 -
 244.163 -  public void setInput(byte[] buf){
 244.164 -    setInput(buf, 0, buf.length, false); 
 244.165 -  }
 244.166 -
 244.167 -  public void setInput(byte[] buf, boolean append){
 244.168 -    setInput(buf, 0, buf.length, append); 
 244.169 -  }
 244.170 -
 244.171 -  public void setInput(byte[] buf, int off, int len, boolean append){
 244.172 -    if(len<=0 && append && next_in!=null) return;
 244.173 -
 244.174 -    if(avail_in>0 && append){  
 244.175 -      byte[] tmp = new byte[avail_in+len];
 244.176 -      System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
 244.177 -      System.arraycopy(buf, off, tmp, avail_in, len);
 244.178 -      next_in=tmp;
 244.179 -      next_in_index=0;
 244.180 -      avail_in+=len;
 244.181 -    }
 244.182 -    else{
 244.183 -      next_in=buf;
 244.184 -      next_in_index=off;
 244.185 -      avail_in=len;
 244.186 -    }
 244.187 -  }
 244.188 -
 244.189 -  public byte[] getNextIn(){
 244.190 -    return next_in;
 244.191 -  }
 244.192 -
 244.193 -  public void setNextIn(byte[] next_in){
 244.194 -    this.next_in = next_in;
 244.195 -  }
 244.196 -
 244.197 -  public int getNextInIndex(){
 244.198 -    return next_in_index;
 244.199 -  }
 244.200 -
 244.201 -  public void setNextInIndex(int next_in_index){
 244.202 -    this.next_in_index = next_in_index;
 244.203 -  }
 244.204 -
 244.205 -  public int getAvailIn(){
 244.206 -    return avail_in;
 244.207 -  }
 244.208 -
 244.209 -  public void setAvailIn(int avail_in){
 244.210 -    this.avail_in = avail_in;
 244.211 -  }
 244.212 -
 244.213 -  public byte[] getNextOut(){
 244.214 -    return next_out;
 244.215 -  }
 244.216 -
 244.217 -  public void setNextOut(byte[] next_out){
 244.218 -    this.next_out = next_out;
 244.219 -  }
 244.220 -
 244.221 -  public int getNextOutIndex(){
 244.222 -    return next_out_index;
 244.223 -  }
 244.224 -
 244.225 -  public void setNextOutIndex(int next_out_index){
 244.226 -    this.next_out_index = next_out_index;
 244.227 -  }
 244.228 -
 244.229 -  public int getAvailOut(){
 244.230 -    return avail_out;
 244.231 -
 244.232 -  }
 244.233 -
 244.234 -  public void setAvailOut(int avail_out){
 244.235 -    this.avail_out = avail_out;
 244.236 -  }
 244.237 -
 244.238 -  public long getTotalOut(){
 244.239 -    return total_out;
 244.240 -  }
 244.241 -
 244.242 -  public long getTotalIn(){
 244.243 -    return total_in;
 244.244 -  }
 244.245 -
 244.246 -  public String getMessage(){
 244.247 -    return msg;
 244.248 -  }
 244.249 -
 244.250 -  /**
 244.251 -   * Those methods are expected to be override by Inflater and Deflater.
 244.252 -   * In the future, they will become abstract methods.
 244.253 -   */ 
 244.254 -  public int end(){ return Z_OK; }
 244.255 -  public boolean finished(){ return false; }
 244.256 -}
   245.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java	Mon Feb 25 19:00:08 2013 +0100
   245.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   245.3 @@ -1,84 +0,0 @@
   245.4 -/*
   245.5 - * Copyright (c) 1995, 1996, 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 org.apidesign.bck2brwsr.emul.zip;
  245.30 -
  245.31 -/*
  245.32 - * This class defines the constants that are used by the classes
  245.33 - * which manipulate Zip64 files.
  245.34 - */
  245.35 -
  245.36 -public class ZipConstants64 {
  245.37 -
  245.38 -    /*
  245.39 -     * ZIP64 constants
  245.40 -     */
  245.41 -    static final long ZIP64_ENDSIG = 0x06064b50L;  // "PK\006\006"
  245.42 -    static final long ZIP64_LOCSIG = 0x07064b50L;  // "PK\006\007"
  245.43 -    static final int  ZIP64_ENDHDR = 56;           // ZIP64 end header size
  245.44 -    static final int  ZIP64_LOCHDR = 20;           // ZIP64 end loc header size
  245.45 -    static final int  ZIP64_EXTHDR = 24;           // EXT header size
  245.46 -    static final int  ZIP64_EXTID  = 0x0001;       // Extra field Zip64 header ID
  245.47 -
  245.48 -    static final int  ZIP64_MAGICCOUNT = 0xFFFF;
  245.49 -    static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
  245.50 -
  245.51 -    /*
  245.52 -     * Zip64 End of central directory (END) header field offsets
  245.53 -     */
  245.54 -    static final int  ZIP64_ENDLEN = 4;       // size of zip64 end of central dir
  245.55 -    static final int  ZIP64_ENDVEM = 12;      // version made by
  245.56 -    static final int  ZIP64_ENDVER = 14;      // version needed to extract
  245.57 -    static final int  ZIP64_ENDNMD = 16;      // number of this disk
  245.58 -    static final int  ZIP64_ENDDSK = 20;      // disk number of start
  245.59 -    static final int  ZIP64_ENDTOD = 24;      // total number of entries on this disk
  245.60 -    static final int  ZIP64_ENDTOT = 32;      // total number of entries
  245.61 -    static final int  ZIP64_ENDSIZ = 40;      // central directory size in bytes
  245.62 -    static final int  ZIP64_ENDOFF = 48;      // offset of first CEN header
  245.63 -    static final int  ZIP64_ENDEXT = 56;      // zip64 extensible data sector
  245.64 -
  245.65 -    /*
  245.66 -     * Zip64 End of central directory locator field offsets
  245.67 -     */
  245.68 -    static final int  ZIP64_LOCDSK = 4;       // disk number start
  245.69 -    static final int  ZIP64_LOCOFF = 8;       // offset of zip64 end
  245.70 -    static final int  ZIP64_LOCTOT = 16;      // total number of disks
  245.71 -
  245.72 -    /*
  245.73 -     * Zip64 Extra local (EXT) header field offsets
  245.74 -     */
  245.75 -    static final int  ZIP64_EXTCRC = 4;       // uncompressed file crc-32 value
  245.76 -    static final int  ZIP64_EXTSIZ = 8;       // compressed size, 8-byte
  245.77 -    static final int  ZIP64_EXTLEN = 16;      // uncompressed size, 8-byte
  245.78 -
  245.79 -    /*
  245.80 -     * Language encoding flag EFS
  245.81 -     */
  245.82 -    static final int EFS = 0x800;       // If this bit is set the filename and
  245.83 -                                        // comment fields for this file must be
  245.84 -                                        // encoded using UTF-8.
  245.85 -
  245.86 -    private ZipConstants64() {}
  245.87 -}
   246.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java	Mon Feb 25 19:00:08 2013 +0100
   246.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   246.3 @@ -1,468 +0,0 @@
   246.4 -/*
   246.5 - * Copyright (c) 1996, 2009, 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 org.apidesign.bck2brwsr.emul.zip;
  246.30 -
  246.31 -import java.util.zip.*;
  246.32 -import java.io.InputStream;
  246.33 -import java.io.IOException;
  246.34 -import java.io.EOFException;
  246.35 -import java.io.PushbackInputStream;
  246.36 -import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*;
  246.37 -import static java.util.zip.ZipInputStream.*;
  246.38 -
  246.39 -/**
  246.40 - * This class implements an input stream filter for reading files in the
  246.41 - * ZIP file format. Includes support for both compressed and uncompressed
  246.42 - * entries.
  246.43 - *
  246.44 - * @author      David Connelly
  246.45 - */
  246.46 -public
  246.47 -class ZipInputStream extends InflaterInputStream  {
  246.48 -    private ZipEntry entry;
  246.49 -    private int flag;
  246.50 -    private CRC32 crc = new CRC32();
  246.51 -    private long remaining;
  246.52 -    private byte[] tmpbuf = new byte[512];
  246.53 -
  246.54 -    private static final int STORED = ZipEntry.STORED;
  246.55 -    private static final int DEFLATED = ZipEntry.DEFLATED;
  246.56 -
  246.57 -    private boolean closed = false;
  246.58 -    // this flag is set to true after EOF has reached for
  246.59 -    // one entry
  246.60 -    private boolean entryEOF = false;
  246.61 -
  246.62 -    /**
  246.63 -     * Check to make sure that this stream has not been closed
  246.64 -     */
  246.65 -    private void ensureOpen() throws IOException {
  246.66 -        if (closed) {
  246.67 -            throw new IOException("Stream closed");
  246.68 -        }
  246.69 -    }
  246.70 -
  246.71 -    /**
  246.72 -     * Creates a new ZIP input stream.
  246.73 -     *
  246.74 -     * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
  246.75 -     * decode the entry names.
  246.76 -     *
  246.77 -     * @param in the actual input stream
  246.78 -     */
  246.79 -    public ZipInputStream(InputStream in) {
  246.80 -//        this(in, "UTF-8");
  246.81 -        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
  246.82 -        //usesDefaultInflater = true;
  246.83 -        if(in == null) {
  246.84 -            throw new NullPointerException("in is null");
  246.85 -        }
  246.86 -    }
  246.87 -
  246.88 -    /**
  246.89 -     * Creates a new ZIP input stream.
  246.90 -     *
  246.91 -     * @param in the actual input stream
  246.92 -     *
  246.93 -     * @param charset
  246.94 -     *        The {@linkplain java.nio.charset.Charset charset} to be
  246.95 -     *        used to decode the ZIP entry name (ignored if the
  246.96 -     *        <a href="package-summary.html#lang_encoding"> language
  246.97 -     *        encoding bit</a> of the ZIP entry's general purpose bit
  246.98 -     *        flag is set).
  246.99 -     *
 246.100 -     * @since 1.7
 246.101 -     *
 246.102 -    public ZipInputStream(InputStream in, Charset charset) {
 246.103 -        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
 246.104 -        usesDefaultInflater = true;
 246.105 -        if(in == null) {
 246.106 -            throw new NullPointerException("in is null");
 246.107 -        }
 246.108 -        if (charset == null)
 246.109 -            throw new NullPointerException("charset is null");
 246.110 -        this.zc = ZipCoder.get(charset);
 246.111 -    }
 246.112 -    */
 246.113 -
 246.114 -    /**
 246.115 -     * Reads the next ZIP file entry and positions the stream at the
 246.116 -     * beginning of the entry data.
 246.117 -     * @return the next ZIP file entry, or null if there are no more entries
 246.118 -     * @exception ZipException if a ZIP file error has occurred
 246.119 -     * @exception IOException if an I/O error has occurred
 246.120 -     */
 246.121 -    public ZipEntry getNextEntry() throws IOException {
 246.122 -        ensureOpen();
 246.123 -        if (entry != null) {
 246.124 -            closeEntry();
 246.125 -        }
 246.126 -        crc.reset();
 246.127 -        inf.reset();
 246.128 -        if ((entry = readLOC()) == null) {
 246.129 -            return null;
 246.130 -        }
 246.131 -        if (entry.getMethod() == STORED) {
 246.132 -            remaining = entry.getSize();
 246.133 -        }
 246.134 -        entryEOF = false;
 246.135 -        return entry;
 246.136 -    }
 246.137 -
 246.138 -    /**
 246.139 -     * Closes the current ZIP entry and positions the stream for reading the
 246.140 -     * next entry.
 246.141 -     * @exception ZipException if a ZIP file error has occurred
 246.142 -     * @exception IOException if an I/O error has occurred
 246.143 -     */
 246.144 -    public void closeEntry() throws IOException {
 246.145 -        ensureOpen();
 246.146 -        while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
 246.147 -        entryEOF = true;
 246.148 -    }
 246.149 -
 246.150 -    /**
 246.151 -     * Returns 0 after EOF has reached for the current entry data,
 246.152 -     * otherwise always return 1.
 246.153 -     * <p>
 246.154 -     * Programs should not count on this method to return the actual number
 246.155 -     * of bytes that could be read without blocking.
 246.156 -     *
 246.157 -     * @return     1 before EOF and 0 after EOF has reached for current entry.
 246.158 -     * @exception  IOException  if an I/O error occurs.
 246.159 -     *
 246.160 -     */
 246.161 -    public int available() throws IOException {
 246.162 -        ensureOpen();
 246.163 -        if (entryEOF) {
 246.164 -            return 0;
 246.165 -        } else {
 246.166 -            return 1;
 246.167 -        }
 246.168 -    }
 246.169 -
 246.170 -    /**
 246.171 -     * Reads from the current ZIP entry into an array of bytes.
 246.172 -     * If <code>len</code> is not zero, the method
 246.173 -     * blocks until some input is available; otherwise, no
 246.174 -     * bytes are read and <code>0</code> is returned.
 246.175 -     * @param b the buffer into which the data is read
 246.176 -     * @param off the start offset in the destination array <code>b</code>
 246.177 -     * @param len the maximum number of bytes read
 246.178 -     * @return the actual number of bytes read, or -1 if the end of the
 246.179 -     *         entry is reached
 246.180 -     * @exception  NullPointerException if <code>b</code> is <code>null</code>.
 246.181 -     * @exception  IndexOutOfBoundsException if <code>off</code> is negative,
 246.182 -     * <code>len</code> is negative, or <code>len</code> is greater than
 246.183 -     * <code>b.length - off</code>
 246.184 -     * @exception ZipException if a ZIP file error has occurred
 246.185 -     * @exception IOException if an I/O error has occurred
 246.186 -     */
 246.187 -    public int read(byte[] b, int off, int len) throws IOException {
 246.188 -        ensureOpen();
 246.189 -        if (off < 0 || len < 0 || off > b.length - len) {
 246.190 -            throw new IndexOutOfBoundsException();
 246.191 -        } else if (len == 0) {
 246.192 -            return 0;
 246.193 -        }
 246.194 -
 246.195 -        if (entry == null) {
 246.196 -            return -1;
 246.197 -        }
 246.198 -        switch (entry.getMethod()) {
 246.199 -        case DEFLATED:
 246.200 -            len = super.read(b, off, len);
 246.201 -            if (len == -1) {
 246.202 -                readEnd(entry);
 246.203 -                entryEOF = true;
 246.204 -                entry = null;
 246.205 -            } else {
 246.206 -                crc.update(b, off, len);
 246.207 -            }
 246.208 -            return len;
 246.209 -        case STORED:
 246.210 -            if (remaining <= 0) {
 246.211 -                entryEOF = true;
 246.212 -                entry = null;
 246.213 -                return -1;
 246.214 -            }
 246.215 -            if (len > remaining) {
 246.216 -                len = (int)remaining;
 246.217 -            }
 246.218 -            len = in.read(b, off, len);
 246.219 -            if (len == -1) {
 246.220 -                throw new ZipException("unexpected EOF");
 246.221 -            }
 246.222 -            crc.update(b, off, len);
 246.223 -            remaining -= len;
 246.224 -            if (remaining == 0 && entry.getCrc() != crc.getValue()) {
 246.225 -                throw new ZipException(
 246.226 -                    "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
 246.227 -                    " but got 0x" + Long.toHexString(crc.getValue()) + ")");
 246.228 -            }
 246.229 -            return len;
 246.230 -        default:
 246.231 -            throw new ZipException("invalid compression method");
 246.232 -        }
 246.233 -    }
 246.234 -
 246.235 -    /**
 246.236 -     * Skips specified number of bytes in the current ZIP entry.
 246.237 -     * @param n the number of bytes to skip
 246.238 -     * @return the actual number of bytes skipped
 246.239 -     * @exception ZipException if a ZIP file error has occurred
 246.240 -     * @exception IOException if an I/O error has occurred
 246.241 -     * @exception IllegalArgumentException if n < 0
 246.242 -     */
 246.243 -    public long skip(long n) throws IOException {
 246.244 -        if (n < 0) {
 246.245 -            throw new IllegalArgumentException("negative skip length");
 246.246 -        }
 246.247 -        ensureOpen();
 246.248 -        int max = (int)Math.min(n, Integer.MAX_VALUE);
 246.249 -        int total = 0;
 246.250 -        while (total < max) {
 246.251 -            int len = max - total;
 246.252 -            if (len > tmpbuf.length) {
 246.253 -                len = tmpbuf.length;
 246.254 -            }
 246.255 -            len = read(tmpbuf, 0, len);
 246.256 -            if (len == -1) {
 246.257 -                entryEOF = true;
 246.258 -                break;
 246.259 -            }
 246.260 -            total += len;
 246.261 -        }
 246.262 -        return total;
 246.263 -    }
 246.264 -
 246.265 -    /**
 246.266 -     * Closes this input stream and releases any system resources associated
 246.267 -     * with the stream.
 246.268 -     * @exception IOException if an I/O error has occurred
 246.269 -     */
 246.270 -    public void close() throws IOException {
 246.271 -        if (!closed) {
 246.272 -            super.close();
 246.273 -            closed = true;
 246.274 -        }
 246.275 -    }
 246.276 -
 246.277 -    private byte[] b = new byte[256];
 246.278 -
 246.279 -    /*
 246.280 -     * Reads local file (LOC) header for next entry.
 246.281 -     */
 246.282 -    private ZipEntry readLOC() throws IOException {
 246.283 -        try {
 246.284 -            readFully(tmpbuf, 0, LOCHDR);
 246.285 -        } catch (EOFException e) {
 246.286 -            return null;
 246.287 -        }
 246.288 -        if (get32(tmpbuf, 0) != LOCSIG) {
 246.289 -            return null;
 246.290 -        }
 246.291 -        // get flag first, we need check EFS.
 246.292 -        flag = get16(tmpbuf, LOCFLG);
 246.293 -        // get the entry name and create the ZipEntry first
 246.294 -        int len = get16(tmpbuf, LOCNAM);
 246.295 -        int blen = b.length;
 246.296 -        if (len > blen) {
 246.297 -            do
 246.298 -                blen = blen * 2;
 246.299 -            while (len > blen);
 246.300 -            b = new byte[blen];
 246.301 -        }
 246.302 -        readFully(b, 0, len);
 246.303 -        // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
 246.304 -        ZipEntry e = createZipEntry(((flag & EFS) != 0)
 246.305 -                                    ? toStringUTF8(b, len)
 246.306 -                                    : toString(b, len));
 246.307 -        // now get the remaining fields for the entry
 246.308 -        if ((flag & 1) == 1) {
 246.309 -            throw new ZipException("encrypted ZIP entry not supported");
 246.310 -        }
 246.311 -        e.setMethod(get16(tmpbuf, LOCHOW));
 246.312 -        e.setTime(get32(tmpbuf, LOCTIM));
 246.313 -        if ((flag & 8) == 8) {
 246.314 -            /* "Data Descriptor" present */
 246.315 -            if (e.getMethod() != DEFLATED) {
 246.316 -                throw new ZipException(
 246.317 -                        "only DEFLATED entries can have EXT descriptor");
 246.318 -            }
 246.319 -        } else {
 246.320 -            e.setCrc(get32(tmpbuf, LOCCRC));
 246.321 -            e.setCompressedSize(get32(tmpbuf, LOCSIZ));
 246.322 -            e.setSize(get32(tmpbuf, LOCLEN));
 246.323 -        }
 246.324 -        len = get16(tmpbuf, LOCEXT);
 246.325 -        if (len > 0) {
 246.326 -            byte[] bb = new byte[len];
 246.327 -            readFully(bb, 0, len);
 246.328 -            e.setExtra(bb);
 246.329 -            // extra fields are in "HeaderID(2)DataSize(2)Data... format
 246.330 -            if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
 246.331 -                int off = 0;
 246.332 -                while (off + 4 < len) {
 246.333 -                    int sz = get16(bb, off + 2);
 246.334 -                    if (get16(bb, off) == ZIP64_EXTID) {
 246.335 -                        off += 4;
 246.336 -                        // LOC extra zip64 entry MUST include BOTH original and
 246.337 -                        // compressed file size fields
 246.338 -                        if (sz < 16 || (off + sz) > len ) {
 246.339 -                            // Invalid zip64 extra fields, simply skip. Even it's
 246.340 -                            // rare, it's possible the entry size happens to be
 246.341 -                            // the magic value and it "accidnetly" has some bytes
 246.342 -                            // in extra match the id.
 246.343 -                            return e;
 246.344 -                        }
 246.345 -                        e.setSize(get64(bb, off));
 246.346 -                        e.setCompressedSize(get64(bb, off + 8));
 246.347 -                        break;
 246.348 -                    }
 246.349 -                    off += (sz + 4);
 246.350 -                }
 246.351 -            }
 246.352 -        }
 246.353 -        return e;
 246.354 -    }
 246.355 -
 246.356 -    /**
 246.357 -     * Creates a new <code>ZipEntry</code> object for the specified
 246.358 -     * entry name.
 246.359 -     *
 246.360 -     * @param name the ZIP file entry name
 246.361 -     * @return the ZipEntry just created
 246.362 -     */
 246.363 -    protected ZipEntry createZipEntry(String name) {
 246.364 -        return new ZipEntry(name);
 246.365 -    }
 246.366 -
 246.367 -    /*
 246.368 -     * Reads end of deflated entry as well as EXT descriptor if present.
 246.369 -     */
 246.370 -    private void readEnd(ZipEntry e) throws IOException {
 246.371 -        int n = inf.getRemaining();
 246.372 -        if (n > 0) {
 246.373 -            ((PushbackInputStream)in).unread(buf, len - n, n);
 246.374 -        }
 246.375 -        if ((flag & 8) == 8) {
 246.376 -            /* "Data Descriptor" present */
 246.377 -            if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
 246.378 -                inf.getBytesRead() > ZIP64_MAGICVAL) {
 246.379 -                // ZIP64 format
 246.380 -                readFully(tmpbuf, 0, ZIP64_EXTHDR);
 246.381 -                long sig = get32(tmpbuf, 0);
 246.382 -                if (sig != EXTSIG) { // no EXTSIG present
 246.383 -                    e.setCrc(sig);
 246.384 -                    e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
 246.385 -                    e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
 246.386 -                    ((PushbackInputStream)in).unread(
 246.387 -                        tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
 246.388 -                } else {
 246.389 -                    e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
 246.390 -                    e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
 246.391 -                    e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
 246.392 -                }
 246.393 -            } else {
 246.394 -                readFully(tmpbuf, 0, EXTHDR);
 246.395 -                long sig = get32(tmpbuf, 0);
 246.396 -                if (sig != EXTSIG) { // no EXTSIG present
 246.397 -                    e.setCrc(sig);
 246.398 -                    e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
 246.399 -                    e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
 246.400 -                    ((PushbackInputStream)in).unread(
 246.401 -                                               tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
 246.402 -                } else {
 246.403 -                    e.setCrc(get32(tmpbuf, EXTCRC));
 246.404 -                    e.setCompressedSize(get32(tmpbuf, EXTSIZ));
 246.405 -                    e.setSize(get32(tmpbuf, EXTLEN));
 246.406 -                }
 246.407 -            }
 246.408 -        }
 246.409 -        if (e.getSize() != inf.getBytesWritten()) {
 246.410 -            throw new ZipException(
 246.411 -                "invalid entry size (expected " + e.getSize() +
 246.412 -                " but got " + inf.getBytesWritten() + " bytes)");
 246.413 -        }
 246.414 -        if (e.getCompressedSize() != inf.getBytesRead()) {
 246.415 -            throw new ZipException(
 246.416 -                "invalid entry compressed size (expected " + e.getCompressedSize() +
 246.417 -                " but got " + inf.getBytesRead() + " bytes)");
 246.418 -        }
 246.419 -        if (e.getCrc() != crc.getValue()) {
 246.420 -            throw new ZipException(
 246.421 -                "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
 246.422 -                " but got 0x" + Long.toHexString(crc.getValue()) + ")");
 246.423 -        }
 246.424 -    }
 246.425 -
 246.426 -    /*
 246.427 -     * Reads bytes, blocking until all bytes are read.
 246.428 -     */
 246.429 -    private void readFully(byte[] b, int off, int len) throws IOException {
 246.430 -        while (len > 0) {
 246.431 -            int n = in.read(b, off, len);
 246.432 -            if (n == -1) {
 246.433 -                throw new EOFException();
 246.434 -            }
 246.435 -            off += n;
 246.436 -            len -= n;
 246.437 -        }
 246.438 -    }
 246.439 -
 246.440 -    /*
 246.441 -     * Fetches unsigned 16-bit value from byte array at specified offset.
 246.442 -     * The bytes are assumed to be in Intel (little-endian) byte order.
 246.443 -     */
 246.444 -    private static final int get16(byte b[], int off) {
 246.445 -        return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
 246.446 -    }
 246.447 -
 246.448 -    /*
 246.449 -     * Fetches unsigned 32-bit value from byte array at specified offset.
 246.450 -     * The bytes are assumed to be in Intel (little-endian) byte order.
 246.451 -     */
 246.452 -    private static final long get32(byte b[], int off) {
 246.453 -        return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
 246.454 -    }
 246.455 -
 246.456 -    /*
 246.457 -     * Fetches signed 64-bit value from byte array at specified offset.
 246.458 -     * The bytes are assumed to be in Intel (little-endian) byte order.
 246.459 -     */
 246.460 -    private static final long get64(byte b[], int off) {
 246.461 -        return get32(b, off) | (get32(b, off+4) << 32);
 246.462 -    }
 246.463 -
 246.464 -    private static String toStringUTF8(byte[] arr, int len) {
 246.465 -        return new String(arr, 0, len);
 246.466 -    }
 246.467 -    
 246.468 -    private static String toString(byte[] b, int len) {
 246.469 -        return new String(b, 0, len);
 246.470 -    }
 246.471 -}
   247.1 --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js	Mon Feb 25 19:00:08 2013 +0100
   247.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   247.3 @@ -1,544 +0,0 @@
   247.4 -// empty line needed here
   247.5 -Number.prototype.add32 = function(x) { return (this + x) | 0; };
   247.6 -Number.prototype.sub32 = function(x) { return (this - x) | 0; };
   247.7 -Number.prototype.mul32 = function(x) { 
   247.8 -    return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
   247.9 -};
  247.10 -Number.prototype.neg32 = function() { return (-this) | 0; };
  247.11 -
  247.12 -Number.prototype.toInt8 = function()  { return (this << 24) >> 24; };
  247.13 -Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
  247.14 -
  247.15 -var __m32 = 0xFFFFFFFF;
  247.16 -
  247.17 -Number.prototype.next32 = function(low) {
  247.18 -  if (this === 0) {
  247.19 -    return low;
  247.20 -  }
  247.21 -  var l = new Number(low);
  247.22 -  l.hi = this | 0;
  247.23 -  return l;
  247.24 -};
  247.25 -
  247.26 -Number.prototype.high32 = function() { 
  247.27 -    return this.hi ? this.hi : (Math.floor(this / (__m32+1))) | 0;
  247.28 -};
  247.29 -Number.prototype.toInt32 = function() { return this | 0; };
  247.30 -Number.prototype.toFP = function() {
  247.31 -    return this.hi ? this.hi * (__m32+1) + this : this;
  247.32 -};
  247.33 -Number.prototype.toLong = function() {
  247.34 -    var hi = (this > __m32) ? (Math.floor(this / (__m32+1))) | 0 : 0;
  247.35 -    return hi.next32(Math.floor(this % (__m32+1)));
  247.36 -};
  247.37 -
  247.38 -Number.prototype.toExactString = function() {
  247.39 -    if (this.hi) {
  247.40 -        // check for Long.MIN_VALUE
  247.41 -        if ((this.hi == (0x80000000 | 0)) && (this == 0)) {
  247.42 -            return '-9223372036854775808';
  247.43 -        }
  247.44 -        var res = 0;
  247.45 -        var a = [ 6,9,2,7,6,9,4,9,2,4 ];
  247.46 -        var s = '';
  247.47 -        var digit;
  247.48 -        var neg = this.hi < 0;
  247.49 -        if (neg) {
  247.50 -            var x = this.neg64();
  247.51 -            var hi = x.hi;
  247.52 -            var low = x;
  247.53 -        } else {
  247.54 -            var hi = this.hi;
  247.55 -            var low = this;
  247.56 -        }
  247.57 -        for (var i = 0; i < a.length; i++) {
  247.58 -            res += hi * a[i];
  247.59 -            var low_digit = low % 10;
  247.60 -            digit = (res % 10) + low_digit;
  247.61 -
  247.62 -            low = Math.floor(low / 10);
  247.63 -            res = Math.floor(res / 10);
  247.64 -
  247.65 -            if (digit >= 10) {
  247.66 -                digit -= 10;
  247.67 -                res++;
  247.68 -            }
  247.69 -            s = String(digit).concat(s);
  247.70 -        }
  247.71 -        s = String(res).concat(s).replace(/^0+/, '');
  247.72 -        return (neg ? '-' : '').concat(s);
  247.73 -    }
  247.74 -    return String(this);
  247.75 -};
  247.76 -
  247.77 -Number.prototype.add64 = function(x) {
  247.78 -    var low = this + x;
  247.79 -    carry = 0;
  247.80 -    if (low > __m32) {
  247.81 -        carry = 1;
  247.82 -        low -= (__m32+1);
  247.83 -    }
  247.84 -    var hi = (this.high32() + x.high32() + carry) | 0;
  247.85 -    return hi.next32(low);
  247.86 -};
  247.87 -
  247.88 -Number.prototype.sub64 = function(x) {
  247.89 -    var low = this - x;
  247.90 -    carry = 0;
  247.91 -    if (low < 0) {
  247.92 -        carry = 1;
  247.93 -        low += (__m32+1);
  247.94 -    }
  247.95 -    var hi = (this.high32() - x.high32() - carry) | 0;
  247.96 -    return hi.next32(low);
  247.97 -};
  247.98 -
  247.99 -Number.prototype.mul64 = function(x) {
 247.100 -    var low = this.mul32(x);
 247.101 -    low += (low < 0) ? (__m32+1) : 0;
 247.102 -    // first count upper 32 bits of (this.low * x.low)
 247.103 -    var hi_hi = 0;
 247.104 -    var hi_low = 0;
 247.105 -    var m = 1;
 247.106 -    for (var i = 0; i < 32; i++) {
 247.107 -        if (x & m) {
 247.108 -            hi_hi += this >>> 16;
 247.109 -            hi_low += this & 0xFFFF
 247.110 -        }
 247.111 -        hi_low >>= 1;
 247.112 -        hi_low += (hi_hi & 1) ? 0x8000 : 0;
 247.113 -        hi_hi >>= 1;
 247.114 -        m <<= 1;
 247.115 -    }
 247.116 -    var hi = (hi_hi << 16) + hi_low;
 247.117 -    
 247.118 -    var m1 = this.high32().mul32(x);
 247.119 -    var m2 = this.mul32(x.high32());
 247.120 -    hi = hi.add32(m1).add32(m2);
 247.121 -    
 247.122 -    return hi.next32(low);
 247.123 -};
 247.124 -
 247.125 -Number.prototype.and64 = function(x) {
 247.126 -    var low = this & x;
 247.127 -    low += (low < 0) ? (__m32+1) : 0;
 247.128 -    if (this.hi && x.hi) {
 247.129 -        var hi = this.hi & x.hi;
 247.130 -        return hi.next32(low);
 247.131 -    };
 247.132 -    return low;
 247.133 -};
 247.134 -
 247.135 -Number.prototype.or64 = function(x) {
 247.136 -    var low = this | x;
 247.137 -    low += (low < 0) ? (__m32+1) : 0;
 247.138 -    if (this.hi || x.hi) {
 247.139 -        var hi = this.hi | x.hi;
 247.140 -        return hi.next32(low);
 247.141 -    };
 247.142 -    return low;
 247.143 -};
 247.144 -
 247.145 -Number.prototype.xor64 = function(x) {
 247.146 -    var low = this ^ x;
 247.147 -    low += (low < 0) ? (__m32+1) : 0;
 247.148 -    if (this.hi || x.hi) {
 247.149 -        var hi = this.hi ^ x.hi;
 247.150 -        return hi.next32(low);
 247.151 -    };
 247.152 -    return low;
 247.153 -};
 247.154 -
 247.155 -Number.prototype.shl64 = function(x) {
 247.156 -    if (x >= 32) {
 247.157 -        var hi = this << (x - 32);
 247.158 -        return hi.next32(0);
 247.159 -    } else {
 247.160 -        var hi = this.high32() << x;
 247.161 -        var low_reminder = this >> (32 - x);
 247.162 -        hi |= low_reminder;
 247.163 -        var low = this << x;
 247.164 -        low += (low < 0) ? (__m32+1) : 0;
 247.165 -        return hi.next32(low);
 247.166 -    }
 247.167 -};
 247.168 -
 247.169 -Number.prototype.shr64 = function(x) {
 247.170 -    if (x >= 32) {
 247.171 -        var low = this.high32() >> (x - 32);
 247.172 -        low += (low < 0) ? (__m32+1) : 0;
 247.173 -        return low;
 247.174 -    } else {
 247.175 -        var low = this >> x;
 247.176 -        var hi_reminder = this.high32() << (32 - x);
 247.177 -        low |= hi_reminder;
 247.178 -        low += (low < 0) ? (__m32+1) : 0;
 247.179 -        var hi = this.high32() >> x;
 247.180 -        return hi.next32(low);
 247.181 -    }
 247.182 -};
 247.183 -
 247.184 -Number.prototype.ushr64 = function(x) {
 247.185 -    if (x >= 32) {
 247.186 -        var low = this.high32() >>> (x - 32);
 247.187 -        low += (low < 0) ? (__m32+1) : 0;
 247.188 -        return low;
 247.189 -    } else {
 247.190 -        var low = this >>> x;
 247.191 -        var hi_reminder = this.high32() << (32 - x);
 247.192 -        low |= hi_reminder;
 247.193 -        low += (low < 0) ? (__m32+1) : 0;
 247.194 -        var hi = this.high32() >>> x;
 247.195 -        return hi.next32(low);
 247.196 -    }
 247.197 -};
 247.198 -
 247.199 -Number.prototype.compare64 = function(x) {
 247.200 -    if (this.high32() === x.high32()) {
 247.201 -        return (this < x) ? -1 : ((this > x) ? 1 : 0);
 247.202 -    }
 247.203 -    return (this.high32() < x.high32()) ? -1 : 1;
 247.204 -};
 247.205 -
 247.206 -Number.prototype.neg64 = function() {
 247.207 -    var hi = this.high32();
 247.208 -    var low = this;
 247.209 -    if ((hi === 0) && (low < 0)) { return -low; }
 247.210 -    hi = ~hi;
 247.211 -    low = ~low;
 247.212 -    low += (low < 0) ? (__m32+1) : 0;
 247.213 -    var ret = hi.next32(low);
 247.214 -    return ret.add64(1);
 247.215 -};
 247.216 -
 247.217 -(function(numberPrototype) {
 247.218 -    function __handleDivByZero() {
 247.219 -        var exception = new vm.java_lang_ArithmeticException;
 247.220 -        vm.java_lang_ArithmeticException(false).constructor
 247.221 -          .cons__VLjava_lang_String_2.call(exception, "/ by zero");
 247.222 -
 247.223 -        throw exception;
 247.224 -    }
 247.225 -
 247.226 -    function __Int64(hi32, lo32) {
 247.227 -        this.hi32 = hi32 | 0;
 247.228 -        this.lo32 = lo32 | 0;
 247.229 -
 247.230 -        this.get32 = function(bitIndex) {
 247.231 -            var v0;
 247.232 -            var v1;
 247.233 -            bitIndex += 32;
 247.234 -            var selector = bitIndex >>> 5;
 247.235 -            switch (selector) {
 247.236 -                case 0:
 247.237 -                    v0 = 0;
 247.238 -                    v1 = this.lo32;
 247.239 -                    break;
 247.240 -                case 1:
 247.241 -                    v0 = this.lo32;
 247.242 -                    v1 = this.hi32;
 247.243 -                    break;
 247.244 -                case 2:
 247.245 -                    v0 = this.hi32;
 247.246 -                    v1 = 0;
 247.247 -                    break
 247.248 -                default:
 247.249 -                    return 0;
 247.250 -            }
 247.251 -
 247.252 -            var shift = bitIndex & 31;
 247.253 -            if (shift === 0) {
 247.254 -                return v0;
 247.255 -            }
 247.256 -
 247.257 -            return (v1 << (32 - shift)) | (v0 >>> shift);
 247.258 -        }
 247.259 -
 247.260 -        this.get16 = function(bitIndex) {
 247.261 -            return this.get32(bitIndex) & 0xffff;
 247.262 -        }
 247.263 -
 247.264 -        this.set16 = function(bitIndex, value) {
 247.265 -            bitIndex += 32;
 247.266 -            var shift = bitIndex & 15;
 247.267 -            var svalue = (value & 0xffff) << shift; 
 247.268 -            var smask = 0xffff << shift;
 247.269 -            var selector = bitIndex >>> 4;
 247.270 -            switch (selector) {
 247.271 -                case 0:
 247.272 -                    break;
 247.273 -                case 1:
 247.274 -                    this.lo32 = (this.lo32 & ~(smask >>> 16))
 247.275 -                                    | (svalue >>> 16);
 247.276 -                    break;
 247.277 -                case 2:
 247.278 -                    this.lo32 = (this.lo32 & ~smask) | svalue;
 247.279 -                    break;
 247.280 -                case 3:
 247.281 -                    this.lo32 = (this.lo32 & ~(smask << 16))
 247.282 -                                    | (svalue << 16);
 247.283 -                    this.hi32 = (this.hi32 & ~(smask >>> 16))
 247.284 -                                    | (svalue >>> 16);
 247.285 -                    break;
 247.286 -                case 4:
 247.287 -                    this.hi32 = (this.hi32 & ~smask) | svalue;
 247.288 -                    break;
 247.289 -                case 5:
 247.290 -                    this.hi32 = (this.hi32 & ~(smask << 16))
 247.291 -                                    | (svalue << 16);
 247.292 -                    break;
 247.293 -            }
 247.294 -        }
 247.295 -
 247.296 -        this.getDigit = function(index, shift) {
 247.297 -            return this.get16((index << 4) - shift);
 247.298 -        }
 247.299 -
 247.300 -        this.getTwoDigits = function(index, shift) {
 247.301 -            return this.get32(((index - 1) << 4) - shift);
 247.302 -        }
 247.303 -
 247.304 -        this.setDigit = function(index, shift, value) {
 247.305 -            this.set16((index << 4) - shift, value);
 247.306 -        }
 247.307 -
 247.308 -        this.countSignificantDigits = function() {
 247.309 -            var sd;
 247.310 -            var remaining;
 247.311 -
 247.312 -            if (this.hi32 === 0) {
 247.313 -                if (this.lo32 === 0) {
 247.314 -                    return 0;
 247.315 -                }
 247.316 -
 247.317 -                sd = 2;
 247.318 -                remaining = this.lo32;
 247.319 -            } else {
 247.320 -                sd = 4;
 247.321 -                remaining = this.hi32;
 247.322 -            }
 247.323 -
 247.324 -            if (remaining < 0) {
 247.325 -                return sd;
 247.326 -            }
 247.327 -
 247.328 -            return (remaining < 65536) ? sd - 1 : sd;
 247.329 -        }
 247.330 -        
 247.331 -        this.toNumber = function() {
 247.332 -            var lo32 = this.lo32;
 247.333 -            if (lo32 < 0) {
 247.334 -                lo32 += 0x100000000;
 247.335 -            }
 247.336 -
 247.337 -            return this.hi32.next32(lo32);
 247.338 -        }
 247.339 -    }
 247.340 -
 247.341 -    function __countLeadingZeroes16(number) {
 247.342 -        var nlz = 0;
 247.343 -
 247.344 -        if (number < 256) {
 247.345 -            nlz += 8;
 247.346 -            number <<= 8;
 247.347 -        }
 247.348 -
 247.349 -        if (number < 4096) {
 247.350 -            nlz += 4;
 247.351 -            number <<= 4;
 247.352 -        }
 247.353 -
 247.354 -        if (number < 16384) {
 247.355 -            nlz += 2;
 247.356 -            number <<= 2;
 247.357 -        }
 247.358 -
 247.359 -        return (number < 32768) ? nlz + 1 : nlz;
 247.360 -    }
 247.361 -    
 247.362 -    // q = u / v; r = u - q * v;
 247.363 -    // v != 0
 247.364 -    function __div64(q, r, u, v) {
 247.365 -        var m = u.countSignificantDigits();
 247.366 -        var n = v.countSignificantDigits();
 247.367 -
 247.368 -        q.hi32 = q.lo32 = 0;
 247.369 -
 247.370 -        if (n === 1) {
 247.371 -            // v has single digit
 247.372 -            var vd = v.getDigit(0, 0);
 247.373 -            var carry = 0;
 247.374 -            for (var i = m - 1; i >= 0; --i) {
 247.375 -                var ui = (carry << 16) | u.getDigit(i, 0);
 247.376 -                if (ui < 0) {
 247.377 -                    ui += 0x100000000;
 247.378 -                }
 247.379 -                var qi = (ui / vd) | 0;
 247.380 -                q.setDigit(i, 0, qi);
 247.381 -                carry = ui - qi * vd;
 247.382 -            }
 247.383 -
 247.384 -            r.hi32 = 0;
 247.385 -            r.lo32 = carry;
 247.386 -            return;
 247.387 -        }
 247.388 -
 247.389 -        r.hi32 = u.hi32;  
 247.390 -        r.lo32 = u.lo32;
 247.391 -
 247.392 -        if (m < n) {
 247.393 -            return;
 247.394 -        }
 247.395 -
 247.396 -        // Normalize
 247.397 -        var nrm = __countLeadingZeroes16(v.getDigit(n - 1, 0));
 247.398 -
 247.399 -        var vd1 = v.getDigit(n - 1, nrm);                
 247.400 -        var vd0 = v.getDigit(n - 2, nrm);
 247.401 -        for (var j = m - n; j >= 0; --j) {
 247.402 -            // Calculate qj estimate
 247.403 -            var ud21 = r.getTwoDigits(j + n, nrm);
 247.404 -            var ud2 = ud21 >>> 16;
 247.405 -            if (ud21 < 0) {
 247.406 -                ud21 += 0x100000000;
 247.407 -            }
 247.408 -
 247.409 -            var qest = (ud2 === vd1) ? 0xFFFF : ((ud21 / vd1) | 0);
 247.410 -            var rest = ud21 - qest * vd1;
 247.411 -
 247.412 -            // 0 <= (qest - qj) <= 2
 247.413 -
 247.414 -            // Refine qj estimate
 247.415 -            var ud0 = r.getDigit(j + n - 2, nrm);
 247.416 -            while ((qest * vd0) > ((rest * 0x10000) + ud0)) {
 247.417 -                --qest;
 247.418 -                rest += vd1;
 247.419 -            }
 247.420 -
 247.421 -            // 0 <= (qest - qj) <= 1
 247.422 -            
 247.423 -            // Multiply and subtract
 247.424 -            var carry = 0;
 247.425 -            for (var i = 0; i < n; ++i) {
 247.426 -                var vi = qest * v.getDigit(i, nrm);
 247.427 -                var ui = r.getDigit(i + j, nrm) - carry - (vi & 0xffff);
 247.428 -                r.setDigit(i + j, nrm, ui);
 247.429 -                carry = (vi >>> 16) - (ui >> 16);
 247.430 -            }
 247.431 -            var uj = ud2 - carry;
 247.432 -
 247.433 -            if (uj < 0) {
 247.434 -                // qest - qj = 1
 247.435 -
 247.436 -                // Add back
 247.437 -                --qest;
 247.438 -                var carry = 0;
 247.439 -                for (var i = 0; i < n; ++i) {
 247.440 -                    var ui = r.getDigit(i + j, nrm) + v.getDigit(i, nrm)
 247.441 -                                 + carry;
 247.442 -                    r.setDigit(i + j, nrm, ui);
 247.443 -                    carry = ui >> 16;
 247.444 -                }
 247.445 -                uj += carry;
 247.446 -            }
 247.447 -
 247.448 -            q.setDigit(j, 0, qest);
 247.449 -            r.setDigit(j + n, nrm, uj);
 247.450 -        }
 247.451 -    }
 247.452 -
 247.453 -    numberPrototype.div32 = function(x) {
 247.454 -        if (x === 0) {
 247.455 -            __handleDivByZero();
 247.456 -        }
 247.457 -
 247.458 -        return (this / x) | 0;
 247.459 -    }
 247.460 -
 247.461 -    numberPrototype.mod32 = function(x) {
 247.462 -        if (x === 0) {
 247.463 -            __handleDivByZero();
 247.464 -        }
 247.465 -
 247.466 -        return (this % x);
 247.467 -    }
 247.468 -
 247.469 -    numberPrototype.div64 = function(x) {
 247.470 -        var negateResult = false;
 247.471 -        var u, v;
 247.472 -
 247.473 -        if ((this.high32() & 0x80000000) != 0) {
 247.474 -            u = this.neg64();
 247.475 -            negateResult = !negateResult;
 247.476 -        } else {
 247.477 -            u = this;        
 247.478 -        }
 247.479 -
 247.480 -        if ((x.high32() & 0x80000000) != 0) {
 247.481 -            v = x.neg64();
 247.482 -            negateResult = !negateResult;
 247.483 -        } else {
 247.484 -            v = x;
 247.485 -        }
 247.486 -
 247.487 -        if ((v === 0) && (v.high32() === 0)) {
 247.488 -            __handleDivByZero();
 247.489 -        }
 247.490 -
 247.491 -        if (u.high32() === 0) {
 247.492 -            if (v.high32() === 0) {
 247.493 -                var result = (u / v) | 0;
 247.494 -                return negateResult ? result.neg64() : result; 
 247.495 -            }
 247.496 -
 247.497 -            return 0;
 247.498 -        }
 247.499 -
 247.500 -        var u64 = new __Int64(u.high32(), u);
 247.501 -        var v64 = new __Int64(v.high32(), v);
 247.502 -        var q64 = new __Int64(0, 0);
 247.503 -        var r64 = new __Int64(0, 0);
 247.504 -
 247.505 -        __div64(q64, r64, u64, v64);
 247.506 -
 247.507 -        var result = q64.toNumber();
 247.508 -        return negateResult ? result.neg64() : result; 
 247.509 -    }
 247.510 -
 247.511 -    numberPrototype.mod64 = function(x) {
 247.512 -        var negateResult = false;
 247.513 -        var u, v;
 247.514 -        
 247.515 -        if ((this.high32() & 0x80000000) != 0) {
 247.516 -            u = this.neg64();
 247.517 -            negateResult = !negateResult;
 247.518 -        } else {
 247.519 -            u = this;        
 247.520 -        }
 247.521 -
 247.522 -        if ((x.high32() & 0x80000000) != 0) {
 247.523 -            v = x.neg64();
 247.524 -        } else {
 247.525 -            v = x;
 247.526 -        }
 247.527 -
 247.528 -        if ((v === 0) && (v.high32() === 0)) {
 247.529 -            __handleDivByZero();
 247.530 -        }
 247.531 -
 247.532 -        if (u.high32() === 0) {
 247.533 -            var result = (v.high32() === 0) ? (u % v) : u;
 247.534 -            return negateResult ? result.neg64() : result; 
 247.535 -        }
 247.536 -
 247.537 -        var u64 = new __Int64(u.high32(), u);
 247.538 -        var v64 = new __Int64(v.high32(), v);
 247.539 -        var q64 = new __Int64(0, 0);
 247.540 -        var r64 = new __Int64(0, 0);
 247.541 -
 247.542 -        __div64(q64, r64, u64, v64);
 247.543 -
 247.544 -        var result = r64.toNumber();
 247.545 -        return negateResult ? result.neg64() : result; 
 247.546 -    }
 247.547 -})(Number.prototype);
   248.1 --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js	Mon Feb 25 19:00:08 2013 +0100
   248.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   248.3 @@ -1,27 +0,0 @@
   248.4 -// initialize methods on arrays and String constants
   248.5 -vm.java_lang_reflect_Array(false);
   248.6 -vm.java_lang_String(false);
   248.7 -
   248.8 -Array.prototype.at = function(indx, value) {
   248.9 -  if (indx < 0 || indx > this.length) {
  248.10 -      var e = vm.java_lang_ArrayIndexOutOfBoundsException(true);
  248.11 -      e.constructor.cons__VLjava_lang_String_2.call(e, indx.toString());
  248.12 -      throw e;
  248.13 -  }
  248.14 -  if (arguments.length === 2) {
  248.15 -      this[indx] = value;
  248.16 -  }
  248.17 -  return this[indx];
  248.18 -};
  248.19 -Array.prototype.getClass__Ljava_lang_Class_2 = function() {
  248.20 -  return vm.java_lang_Class(false).defineArray__Ljava_lang_Class_2Ljava_lang_String_2(this.jvmName);
  248.21 -};
  248.22 -Array.prototype.clone__Ljava_lang_Object_2 = function() {
  248.23 -  var s = this.length;
  248.24 -  var ret = new Array(s);
  248.25 -  for (var i = 0; i < s; i++) {
  248.26 -      ret[i] = this[i];
  248.27 -  }
  248.28 -  ret.jvmName = this.jvmName;
  248.29 -  return ret;
  248.30 -};
   249.1 --- a/emul/mini/src/test/java/org/apidesign/bck2brwsr/emul/reflect/MethodImplTest.java	Mon Feb 25 19:00:08 2013 +0100
   249.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   249.3 @@ -1,49 +0,0 @@
   249.4 -/**
   249.5 - * Back 2 Browser Bytecode Translator
   249.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   249.7 - *
   249.8 - * This program is free software: you can redistribute it and/or modify
   249.9 - * it under the terms of the GNU General Public License as published by
  249.10 - * the Free Software Foundation, version 2 of the License.
  249.11 - *
  249.12 - * This program is distributed in the hope that it will be useful,
  249.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  249.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  249.15 - * GNU General Public License for more details.
  249.16 - *
  249.17 - * You should have received a copy of the GNU General Public License
  249.18 - * along with this program. Look for COPYING file in the top folder.
  249.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  249.20 - */
  249.21 -package org.apidesign.bck2brwsr.emul.reflect;
  249.22 -
  249.23 -import java.lang.reflect.Method;
  249.24 -import java.util.Enumeration;
  249.25 -import org.testng.annotations.Test;
  249.26 -
  249.27 -/**
  249.28 - *
  249.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  249.30 - */
  249.31 -public class MethodImplTest {
  249.32 -    
  249.33 -    public MethodImplTest() {
  249.34 -    }
  249.35 -    
  249.36 -    public static String[] arr(String... arr) {
  249.37 -        return arr;
  249.38 -    }
  249.39 -
  249.40 -    @Test
  249.41 -    public void testSignatureForMethodWithAnArray() throws NoSuchMethodException {
  249.42 -        Method m = MethodImplTest.class.getMethod("arr", String[].class);
  249.43 -        String sig = MethodImpl.toSignature(m);
  249.44 -        int sep = sig.indexOf("__");
  249.45 -        assert sep > 0 : "Separator found " + sig;
  249.46 -        
  249.47 -        Enumeration<Class> en = MethodImpl.signatureParser(sig.substring(sep + 2));
  249.48 -        
  249.49 -        assert en.nextElement() == m.getReturnType() : "Return type is the same";
  249.50 -        assert en.nextElement() == m.getParameterTypes()[0] : "1st param type is the same";
  249.51 -    }
  249.52 -}
  249.53 \ No newline at end of file
   250.1 --- a/emul/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   250.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   250.3 @@ -1,18 +0,0 @@
   250.4 -<?xml version="1.0" encoding="UTF-8"?>
   250.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">
   250.6 -  <modelVersion>4.0.0</modelVersion>
   250.7 -  <parent>
   250.8 -    <artifactId>bck2brwsr</artifactId>
   250.9 -    <groupId>org.apidesign</groupId>
  250.10 -    <version>0.3-SNAPSHOT</version>
  250.11 -  </parent>
  250.12 -  <groupId>org.apidesign.bck2brwsr</groupId>
  250.13 -  <artifactId>emul.pom</artifactId>
  250.14 -  <version>0.3-SNAPSHOT</version>
  250.15 -  <packaging>pom</packaging>
  250.16 -  <name>Emulation of Core Libraries</name>
  250.17 -  <modules>
  250.18 -    <module>mini</module>
  250.19 -    <module>compact</module>
  250.20 -  </modules>
  250.21 -</project>
   251.1 --- a/javap/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   251.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   251.3 @@ -1,41 +0,0 @@
   251.4 -<?xml version="1.0"?>
   251.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"
   251.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   251.7 -  <modelVersion>4.0.0</modelVersion>
   251.8 -  <parent>
   251.9 -    <groupId>org.apidesign</groupId>
  251.10 -    <artifactId>bck2brwsr</artifactId>
  251.11 -    <version>0.3-SNAPSHOT</version>
  251.12 -  </parent>
  251.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
  251.14 -  <artifactId>javap</artifactId>
  251.15 -  <version>0.3-SNAPSHOT</version>
  251.16 -  <name>javap</name>
  251.17 -  <url>http://maven.apache.org</url>
  251.18 -  <properties>
  251.19 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  251.20 -  </properties>
  251.21 -  <build>
  251.22 -      <plugins>
  251.23 -          <plugin>
  251.24 -              <groupId>org.apache.maven.plugins</groupId>
  251.25 -              <artifactId>maven-compiler-plugin</artifactId>
  251.26 -              <version>2.5.1</version>
  251.27 -              <configuration>
  251.28 -                  <compilerArguments>
  251.29 -                      <!--<bootclasspath>non-existing</bootclasspath>-->
  251.30 -                  </compilerArguments>
  251.31 -                 <source>1.6</source>
  251.32 -                 <target>1.6</target>
  251.33 -              </configuration>
  251.34 -          </plugin>
  251.35 -      </plugins>
  251.36 -  </build>
  251.37 -  <dependencies>
  251.38 -    <dependency>
  251.39 -      <groupId>org.apidesign.bck2brwsr</groupId>
  251.40 -      <artifactId>emul.mini</artifactId>
  251.41 -      <version>0.3-SNAPSHOT</version>
  251.42 -    </dependency>
  251.43 -  </dependencies>
  251.44 -</project>
   252.1 --- a/javap/src/main/java/org/apidesign/javap/AnnotationParser.java	Mon Feb 25 19:00:08 2013 +0100
   252.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   252.3 @@ -1,145 +0,0 @@
   252.4 -/*
   252.5 - * Copyright (c) 2002, 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 -package org.apidesign.javap;
  252.29 -
  252.30 -import java.io.ByteArrayInputStream;
  252.31 -import java.io.DataInputStream;
  252.32 -import java.io.IOException;
  252.33 -
  252.34 -/** An abstract parser for annotation definitions. Analyses the bytes and
  252.35 - * performs some callbacks to the overriden parser methods.
  252.36 - *
  252.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  252.38 - */
  252.39 -public class AnnotationParser {
  252.40 -    private final boolean textual;
  252.41 -    private final boolean iterateArray;
  252.42 -    
  252.43 -    protected AnnotationParser(boolean textual, boolean iterateArray) {
  252.44 -        this.textual = textual;
  252.45 -        this.iterateArray = iterateArray;
  252.46 -    }
  252.47 -
  252.48 -    protected void visitAnnotationStart(String type, boolean top) throws IOException {
  252.49 -    }
  252.50 -
  252.51 -    protected void visitAnnotationEnd(String type, boolean top) throws IOException {
  252.52 -    }
  252.53 -
  252.54 -    protected void visitValueStart(String attrName, char type) throws IOException {
  252.55 -    }
  252.56 -
  252.57 -    protected void visitValueEnd(String attrName, char type) throws IOException {
  252.58 -    }
  252.59 -
  252.60 -    
  252.61 -    protected void visitAttr(
  252.62 -        String annoType, String attr, String attrType, String value
  252.63 -    ) throws IOException {
  252.64 -    }
  252.65 -    
  252.66 -    protected void visitEnumAttr(
  252.67 -        String annoType, String attr, String attrType, String value
  252.68 -    ) throws IOException {
  252.69 -        visitAttr(annoType, attr, attrType, value);
  252.70 -    }
  252.71 -    
  252.72 -    /** Initialize the parsing with constant pool from <code>cd</code>.
  252.73 -     * 
  252.74 -     * @param attr the attribute defining annotations
  252.75 -     * @param cd constant pool
  252.76 -     * @throws IOException in case I/O fails
  252.77 -     */
  252.78 -    public final void parse(byte[] attr, ClassData cd) throws IOException {
  252.79 -        ByteArrayInputStream is = new ByteArrayInputStream(attr);
  252.80 -        DataInputStream dis = new DataInputStream(is);
  252.81 -        try {
  252.82 -            read(dis, cd);
  252.83 -        } finally {
  252.84 -            is.close();
  252.85 -        }
  252.86 -    }
  252.87 -    
  252.88 -    private void read(DataInputStream dis, ClassData cd) throws IOException {
  252.89 -    	int cnt = dis.readUnsignedShort();
  252.90 -        for (int i = 0; i < cnt; i++) {
  252.91 -            readAnno(dis, cd, true);
  252.92 -        }
  252.93 -    }
  252.94 -
  252.95 -    private void readAnno(DataInputStream dis, ClassData cd, boolean top) throws IOException {
  252.96 -        int type = dis.readUnsignedShort();
  252.97 -        String typeName = cd.StringValue(type);
  252.98 -        visitAnnotationStart(typeName, top);
  252.99 -    	int cnt = dis.readUnsignedShort();
 252.100 -    	for (int i = 0; i < cnt; i++) {
 252.101 -            String attrName = cd.StringValue(dis.readUnsignedShort());
 252.102 -            readValue(dis, cd, typeName, attrName);
 252.103 -        }
 252.104 -        visitAnnotationEnd(typeName, top);
 252.105 -        if (cnt == 0) {
 252.106 -            visitAttr(typeName, null, null, null);
 252.107 -        }
 252.108 -    }
 252.109 -
 252.110 -    private void readValue(
 252.111 -        DataInputStream dis, ClassData cd, String typeName, String attrName
 252.112 -    ) throws IOException {
 252.113 -        char type = (char)dis.readByte();
 252.114 -        visitValueStart(attrName, type);
 252.115 -        if (type == '@') {
 252.116 -            readAnno(dis, cd, false);
 252.117 -        } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
 252.118 -            int primitive = dis.readUnsignedShort();
 252.119 -            String val = cd.stringValue(primitive, textual);
 252.120 -            String attrType;
 252.121 -            if (type == 's') {
 252.122 -                attrType = "Ljava_lang_String_2";
 252.123 -                if (textual) {
 252.124 -                    val = '"' + val + '"';
 252.125 -                }
 252.126 -            } else {
 252.127 -                attrType = "" + type;
 252.128 -            }
 252.129 -            visitAttr(typeName, attrName, attrType, val);
 252.130 -        } else if (type == 'c') {
 252.131 -            int cls = dis.readUnsignedShort();
 252.132 -        } else if (type == '[') {
 252.133 -            int cnt = dis.readUnsignedShort();
 252.134 -            for (int i = 0; i < cnt; i++) {
 252.135 -                readValue(dis, cd, typeName, iterateArray ? attrName : null);
 252.136 -            }
 252.137 -        } else if (type == 'e') {
 252.138 -            int enumT = dis.readUnsignedShort();
 252.139 -            String attrType = cd.stringValue(enumT, textual);
 252.140 -            int enumN = dis.readUnsignedShort();
 252.141 -            String val = cd.stringValue(enumN, textual);
 252.142 -            visitEnumAttr(typeName, attrName, attrType, val);
 252.143 -        } else {
 252.144 -            throw new IOException("Unknown type " + type);
 252.145 -        }
 252.146 -        visitValueEnd(attrName, type);
 252.147 -    }
 252.148 -}
   253.1 --- a/javap/src/main/java/org/apidesign/javap/AttrData.java	Mon Feb 25 19:00:08 2013 +0100
   253.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   253.3 @@ -1,77 +0,0 @@
   253.4 -/*
   253.5 - * Copyright (c) 2002, 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 -
  253.30 -
  253.31 -package org.apidesign.javap;
  253.32 -
  253.33 -import java.io.*;
  253.34 -
  253.35 -/**
  253.36 - * Reads and stores attribute information.
  253.37 - *
  253.38 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  253.39 - */
  253.40 -class AttrData {
  253.41 -    ClassData cls;
  253.42 -    int name_cpx;
  253.43 -    int datalen;
  253.44 -    byte data[];
  253.45 -
  253.46 -    public AttrData (ClassData cls) {
  253.47 -        this.cls=cls;
  253.48 -    }
  253.49 -
  253.50 -    /**
  253.51 -     * Reads unknown attribute.
  253.52 -     */
  253.53 -    public void read(int name_cpx, DataInputStream in) throws IOException {
  253.54 -        this.name_cpx=name_cpx;
  253.55 -        datalen=in.readInt();
  253.56 -        data=new byte[datalen];
  253.57 -        in.readFully(data);
  253.58 -    }
  253.59 -
  253.60 -    /**
  253.61 -     * Reads just the name of known attribute.
  253.62 -     */
  253.63 -    public void read(int name_cpx){
  253.64 -        this.name_cpx=name_cpx;
  253.65 -    }
  253.66 -
  253.67 -    /**
  253.68 -     * Returns attribute name.
  253.69 -     */
  253.70 -    public String getAttrName(){
  253.71 -        return cls.getString(name_cpx);
  253.72 -    }
  253.73 -
  253.74 -    /**
  253.75 -     * Returns attribute data.
  253.76 -     */
  253.77 -    public byte[] getData(){
  253.78 -        return data;
  253.79 -    }
  253.80 -}
   254.1 --- a/javap/src/main/java/org/apidesign/javap/CPX.java	Mon Feb 25 19:00:08 2013 +0100
   254.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   254.3 @@ -1,40 +0,0 @@
   254.4 -/*
   254.5 - * Copyright (c) 2002, 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 -
  254.30 -package org.apidesign.javap;
  254.31 -
  254.32 -/**
  254.33 - * Stores constant pool entry information with one field.
  254.34 - *
  254.35 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  254.36 - */
  254.37 -class CPX {
  254.38 -    int cpx;
  254.39 -
  254.40 -    CPX (int cpx) {
  254.41 -        this.cpx=cpx;
  254.42 -    }
  254.43 -}
   255.1 --- a/javap/src/main/java/org/apidesign/javap/CPX2.java	Mon Feb 25 19:00:08 2013 +0100
   255.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   255.3 @@ -1,41 +0,0 @@
   255.4 -/*
   255.5 - * Copyright (c) 2002, 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 -
  255.30 -package org.apidesign.javap;
  255.31 -
  255.32 -/**
  255.33 - *  Stores constant pool entry information with two fields.
  255.34 - *
  255.35 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  255.36 - */
  255.37 -class CPX2 {
  255.38 -    int cpx1,cpx2;
  255.39 -
  255.40 -    CPX2 (int cpx1, int cpx2) {
  255.41 -        this.cpx1=cpx1;
  255.42 -        this.cpx2=cpx2;
  255.43 -    }
  255.44 -}
   256.1 --- a/javap/src/main/java/org/apidesign/javap/ClassData.java	Mon Feb 25 19:00:08 2013 +0100
   256.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   256.3 @@ -1,713 +0,0 @@
   256.4 -/*
   256.5 - * Copyright (c) 2002, 2004, 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 -
  256.30 -package org.apidesign.javap;
  256.31 -
  256.32 -import java.io.*;
  256.33 -
  256.34 -/**
  256.35 - * Central data repository of the Java Disassembler.
  256.36 - * Stores all the information in java class file.
  256.37 - *
  256.38 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  256.39 - */
  256.40 -public final class ClassData implements RuntimeConstants {
  256.41 -
  256.42 -    private int magic;
  256.43 -    private int minor_version;
  256.44 -    private int major_version;
  256.45 -    private int cpool_count;
  256.46 -    private Object cpool[];
  256.47 -    private int access;
  256.48 -    private int this_class = 0;;
  256.49 -    private int super_class;
  256.50 -    private int interfaces_count;
  256.51 -    private int[] interfaces = new int[0];;
  256.52 -    private int fields_count;
  256.53 -    private FieldData[] fields;
  256.54 -    private int methods_count;
  256.55 -    private MethodData[] methods;
  256.56 -    private InnerClassData[] innerClasses;
  256.57 -    private int attributes_count;
  256.58 -    private AttrData[] attrs;
  256.59 -    private String classname;
  256.60 -    private String superclassname;
  256.61 -    private int source_cpx=0;
  256.62 -    private byte tags[];
  256.63 -    private Hashtable indexHashAscii = new Hashtable();
  256.64 -    private String pkgPrefix="";
  256.65 -    private int pkgPrefixLen=0;
  256.66 -
  256.67 -    /**
  256.68 -     * Read classfile to disassemble.
  256.69 -     */
  256.70 -    public ClassData(InputStream infile) throws IOException {
  256.71 -        this.read(new DataInputStream(infile));
  256.72 -    }
  256.73 -
  256.74 -    /**
  256.75 -     * Reads and stores class file information.
  256.76 -     */
  256.77 -    public void read(DataInputStream in) throws IOException {
  256.78 -        // Read the header
  256.79 -        magic = in.readInt();
  256.80 -        if (magic != JAVA_MAGIC) {
  256.81 -            throw new ClassFormatError("wrong magic: " +
  256.82 -                                       toHex(magic) + ", expected " +
  256.83 -                                       toHex(JAVA_MAGIC));
  256.84 -        }
  256.85 -        minor_version = in.readShort();
  256.86 -        major_version = in.readShort();
  256.87 -        if (major_version != JAVA_VERSION) {
  256.88 -        }
  256.89 -
  256.90 -        // Read the constant pool
  256.91 -        readCP(in);
  256.92 -        access = in.readUnsignedShort();
  256.93 -        this_class = in.readUnsignedShort();
  256.94 -        super_class = in.readUnsignedShort();
  256.95 -
  256.96 -        //Read interfaces.
  256.97 -        interfaces_count = in.readUnsignedShort();
  256.98 -        if(interfaces_count > 0){
  256.99 -            interfaces = new int[interfaces_count];
 256.100 -        }
 256.101 -        for (int i = 0; i < interfaces_count; i++) {
 256.102 -            interfaces[i]=in.readShort();
 256.103 -        }
 256.104 -
 256.105 -        // Read the fields
 256.106 -        readFields(in);
 256.107 -
 256.108 -        // Read the methods
 256.109 -        readMethods(in);
 256.110 -
 256.111 -        // Read the attributes
 256.112 -        attributes_count = in.readUnsignedShort();
 256.113 -        attrs=new AttrData[attributes_count];
 256.114 -        for (int k = 0; k < attributes_count; k++) {
 256.115 -            int name_cpx=in.readUnsignedShort();
 256.116 -            if (getTag(name_cpx)==CONSTANT_UTF8
 256.117 -                && getString(name_cpx).equals("SourceFile")
 256.118 -                ){      if (in.readInt()!=2)
 256.119 -                    throw new ClassFormatError("invalid attr length");
 256.120 -                source_cpx=in.readUnsignedShort();
 256.121 -                AttrData attr=new AttrData(this);
 256.122 -                attr.read(name_cpx);
 256.123 -                attrs[k]=attr;
 256.124 -
 256.125 -            } else if (getTag(name_cpx)==CONSTANT_UTF8
 256.126 -                       && getString(name_cpx).equals("InnerClasses")
 256.127 -                       ){       int length=in.readInt();
 256.128 -                       int num=in.readUnsignedShort();
 256.129 -                       if (2+num*8 != length)
 256.130 -                           throw new ClassFormatError("invalid attr length");
 256.131 -                       innerClasses=new InnerClassData[num];
 256.132 -                       for (int j = 0; j < num; j++) {
 256.133 -                           InnerClassData innerClass=new InnerClassData(this);
 256.134 -                           innerClass.read(in);
 256.135 -                           innerClasses[j]=innerClass;
 256.136 -                       }
 256.137 -                       AttrData attr=new AttrData(this);
 256.138 -                       attr.read(name_cpx);
 256.139 -                       attrs[k]=attr;
 256.140 -            } else {
 256.141 -                AttrData attr=new AttrData(this);
 256.142 -                attr.read(name_cpx, in);
 256.143 -                attrs[k]=attr;
 256.144 -            }
 256.145 -        }
 256.146 -        in.close();
 256.147 -    } // end ClassData.read()
 256.148 -
 256.149 -    /**
 256.150 -     * Reads and stores constant pool info.
 256.151 -     */
 256.152 -    void readCP(DataInputStream in) throws IOException {
 256.153 -        cpool_count = in.readUnsignedShort();
 256.154 -        tags = new byte[cpool_count];
 256.155 -        cpool = new Object[cpool_count];
 256.156 -        for (int i = 1; i < cpool_count; i++) {
 256.157 -            byte tag = in.readByte();
 256.158 -
 256.159 -            switch(tags[i] = tag) {
 256.160 -            case CONSTANT_UTF8:
 256.161 -                String str=in.readUTF();
 256.162 -                indexHashAscii.put(cpool[i] = str, new Integer(i));
 256.163 -                break;
 256.164 -            case CONSTANT_INTEGER:
 256.165 -                cpool[i] = new Integer(in.readInt());
 256.166 -                break;
 256.167 -            case CONSTANT_FLOAT:
 256.168 -                cpool[i] = new Float(in.readFloat());
 256.169 -                break;
 256.170 -            case CONSTANT_LONG:
 256.171 -                cpool[i++] = new Long(in.readLong());
 256.172 -                break;
 256.173 -            case CONSTANT_DOUBLE:
 256.174 -                cpool[i++] = new Double(in.readDouble());
 256.175 -                break;
 256.176 -            case CONSTANT_CLASS:
 256.177 -            case CONSTANT_STRING:
 256.178 -                cpool[i] = new CPX(in.readUnsignedShort());
 256.179 -                break;
 256.180 -
 256.181 -            case CONSTANT_FIELD:
 256.182 -            case CONSTANT_METHOD:
 256.183 -            case CONSTANT_INTERFACEMETHOD:
 256.184 -            case CONSTANT_NAMEANDTYPE:
 256.185 -                cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
 256.186 -                break;
 256.187 -
 256.188 -            case 0:
 256.189 -            default:
 256.190 -                throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
 256.191 -            }
 256.192 -        }
 256.193 -    }
 256.194 -
 256.195 -    /**
 256.196 -     * Reads and strores field info.
 256.197 -     */
 256.198 -    protected void readFields(DataInputStream in) throws IOException {
 256.199 -        int fields_count = in.readUnsignedShort();
 256.200 -        fields=new FieldData[fields_count];
 256.201 -        for (int k = 0; k < fields_count; k++) {
 256.202 -            FieldData field=new FieldData(this);
 256.203 -            field.read(in);
 256.204 -            fields[k]=field;
 256.205 -        }
 256.206 -    }
 256.207 -
 256.208 -    /**
 256.209 -     * Reads and strores Method info.
 256.210 -     */
 256.211 -    protected void readMethods(DataInputStream in) throws IOException {
 256.212 -        int methods_count = in.readUnsignedShort();
 256.213 -        methods=new MethodData[methods_count];
 256.214 -        for (int k = 0; k < methods_count ; k++) {
 256.215 -            MethodData method=new MethodData(this);
 256.216 -            method.read(in);
 256.217 -            methods[k]=method;
 256.218 -        }
 256.219 -    }
 256.220 -
 256.221 -    /**
 256.222 -     * get a string
 256.223 -     */
 256.224 -    public String getString(int n) {
 256.225 -        if (n == 0) {
 256.226 -            return null; 
 256.227 -        } else {
 256.228 -            return (String)cpool[n];
 256.229 -        }
 256.230 -    }
 256.231 -
 256.232 -    /**
 256.233 -     * get the type of constant given an index
 256.234 -     */
 256.235 -    public byte getTag(int n) {
 256.236 -        try{
 256.237 -            return tags[n];
 256.238 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.239 -            return (byte)100;
 256.240 -        }
 256.241 -    }
 256.242 -
 256.243 -    static final String hexString="0123456789ABCDEF";
 256.244 -
 256.245 -    public static char hexTable[]=hexString.toCharArray();
 256.246 -
 256.247 -    static String toHex(long val, int width) {
 256.248 -        StringBuffer s = new StringBuffer();
 256.249 -        for (int i=width-1; i>=0; i--)
 256.250 -            s.append(hexTable[((int)(val>>(4*i)))&0xF]);
 256.251 -        return "0x"+s.toString();
 256.252 -    }
 256.253 -
 256.254 -    static String toHex(long val) {
 256.255 -        int width;
 256.256 -        for (width=16; width>0; width--) {
 256.257 -            if ((val>>(width-1)*4)!=0) break;
 256.258 -        }
 256.259 -        return toHex(val, width);
 256.260 -    }
 256.261 -
 256.262 -    static String toHex(int val) {
 256.263 -        int width;
 256.264 -        for (width=8; width>0; width--) {
 256.265 -            if ((val>>(width-1)*4)!=0) break;
 256.266 -        }
 256.267 -        return toHex(val, width);
 256.268 -    }
 256.269 -
 256.270 -    /**
 256.271 -     * Returns the name of this class.
 256.272 -     */
 256.273 -    public String getClassName() {
 256.274 -        String res=null;
 256.275 -        if (this_class==0) {
 256.276 -            return res;
 256.277 -        }
 256.278 -        int tcpx;
 256.279 -        try {
 256.280 -            if (tags[this_class]!=CONSTANT_CLASS) {
 256.281 -                return res; //"<CP["+cpx+"] is not a Class> ";
 256.282 -            }
 256.283 -            tcpx=((CPX)cpool[this_class]).cpx;
 256.284 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.285 -            return res; // "#"+cpx+"// invalid constant pool index";
 256.286 -        } catch (Throwable e) {
 256.287 -            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 256.288 -        }
 256.289 -
 256.290 -        try {
 256.291 -            return (String)(cpool[tcpx]);
 256.292 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.293 -            return  res; // "class #"+scpx+"// invalid constant pool index";
 256.294 -        } catch (ClassCastException e) {
 256.295 -            return  res; // "class #"+scpx+"// invalid constant pool reference";
 256.296 -        } catch (Throwable e) {
 256.297 -            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 256.298 -        }
 256.299 -
 256.300 -    }
 256.301 -
 256.302 -    /**
 256.303 -     * Returns the name of class at perticular index.
 256.304 -     */
 256.305 -    public String getClassName(int cpx) {
 256.306 -        String res="#"+cpx;
 256.307 -        if (cpx==0) {
 256.308 -            return res;
 256.309 -        }
 256.310 -        int scpx;
 256.311 -        try {
 256.312 -            if (tags[cpx]!=CONSTANT_CLASS) {
 256.313 -                return res; //"<CP["+cpx+"] is not a Class> ";
 256.314 -            }
 256.315 -            scpx=((CPX)cpool[cpx]).cpx;
 256.316 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.317 -            return res; // "#"+cpx+"// invalid constant pool index";
 256.318 -        } catch (Throwable e) {
 256.319 -            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 256.320 -        }
 256.321 -        res="#"+scpx;
 256.322 -        try {
 256.323 -            return (String)(cpool[scpx]);
 256.324 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.325 -            return  res; // "class #"+scpx+"// invalid constant pool index";
 256.326 -        } catch (ClassCastException e) {
 256.327 -            return  res; // "class #"+scpx+"// invalid constant pool reference";
 256.328 -        } catch (Throwable e) {
 256.329 -            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 256.330 -        }
 256.331 -    }
 256.332 -    
 256.333 -    public int getAccessFlags() {
 256.334 -        return access;
 256.335 -    }
 256.336 -
 256.337 -    /**
 256.338 -     * Returns true if it is a class
 256.339 -     */
 256.340 -    public boolean isClass() {
 256.341 -        if((access & ACC_INTERFACE) == 0) return true;
 256.342 -        return false;
 256.343 -    }
 256.344 -
 256.345 -    /**
 256.346 -     * Returns true if it is a interface.
 256.347 -     */
 256.348 -    public boolean isInterface(){
 256.349 -        if((access & ACC_INTERFACE) != 0) return true;
 256.350 -        return false;
 256.351 -    }
 256.352 -
 256.353 -    /**
 256.354 -     * Returns true if this member is public, false otherwise.
 256.355 -     */
 256.356 -    public boolean isPublic(){
 256.357 -        return (access & ACC_PUBLIC) != 0;
 256.358 -    }
 256.359 -
 256.360 -    /**
 256.361 -     * Returns the access of this class or interface.
 256.362 -     */
 256.363 -    public String[] getAccess(){
 256.364 -        Vector v = new Vector();
 256.365 -        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
 256.366 -        if ((access & ACC_FINAL)    !=0) v.addElement("final");
 256.367 -        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
 256.368 -        String[] accflags = new String[v.size()];
 256.369 -        v.copyInto(accflags);
 256.370 -        return accflags;
 256.371 -    }
 256.372 -
 256.373 -    /**
 256.374 -     * Returns list of innerclasses.
 256.375 -     */
 256.376 -    public InnerClassData[] getInnerClasses(){
 256.377 -        return innerClasses;
 256.378 -    }
 256.379 -
 256.380 -    /**
 256.381 -     * Returns list of attributes.
 256.382 -     */
 256.383 -    final AttrData[] getAttributes(){
 256.384 -        return attrs;
 256.385 -    }
 256.386 -    
 256.387 -    public byte[] findAnnotationData(boolean classRetention) {
 256.388 -        String n = classRetention ?
 256.389 -            "RuntimeInvisibleAnnotations" : // NOI18N
 256.390 -            "RuntimeVisibleAnnotations"; // NOI18N
 256.391 -        return findAttr(n, attrs);
 256.392 -    }
 256.393 -
 256.394 -    /**
 256.395 -     * Returns true if superbit is set.
 256.396 -     */
 256.397 -    public boolean isSuperSet(){
 256.398 -        if ((access & ACC_SUPER)   !=0) return true;
 256.399 -        return false;
 256.400 -    }
 256.401 -
 256.402 -    /**
 256.403 -     * Returns super class name.
 256.404 -     */
 256.405 -    public String getSuperClassName(){
 256.406 -        String res=null;
 256.407 -        if (super_class==0) {
 256.408 -            return res;
 256.409 -        }
 256.410 -        int scpx;
 256.411 -        try {
 256.412 -            if (tags[super_class]!=CONSTANT_CLASS) {
 256.413 -                return res; //"<CP["+cpx+"] is not a Class> ";
 256.414 -            }
 256.415 -            scpx=((CPX)cpool[super_class]).cpx;
 256.416 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.417 -            return res; // "#"+cpx+"// invalid constant pool index";
 256.418 -        } catch (Throwable e) {
 256.419 -            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 256.420 -        }
 256.421 -
 256.422 -        try {
 256.423 -            return (String)(cpool[scpx]);
 256.424 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.425 -            return  res; // "class #"+scpx+"// invalid constant pool index";
 256.426 -        } catch (ClassCastException e) {
 256.427 -            return  res; // "class #"+scpx+"// invalid constant pool reference";
 256.428 -        } catch (Throwable e) {
 256.429 -            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 256.430 -        }
 256.431 -    }
 256.432 -
 256.433 -    /**
 256.434 -     * Returns list of super interfaces.
 256.435 -     */
 256.436 -    public String[] getSuperInterfaces(){
 256.437 -        String interfacenames[] = new String[interfaces.length];
 256.438 -        int interfacecpx = -1;
 256.439 -        for(int i = 0; i < interfaces.length; i++){
 256.440 -            interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
 256.441 -            interfacenames[i] = (String)(cpool[interfacecpx]);
 256.442 -        }
 256.443 -        return interfacenames;
 256.444 -    }
 256.445 -
 256.446 -    /**
 256.447 -     * Returns string at prticular constant pool index.
 256.448 -     */
 256.449 -    public String getStringValue(int cpoolx) {
 256.450 -        try {
 256.451 -            return ((String)cpool[cpoolx]);
 256.452 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.453 -            return "//invalid constant pool index:"+cpoolx;
 256.454 -        } catch (ClassCastException e) {
 256.455 -            return "//invalid constant pool ref:"+cpoolx;
 256.456 -        }
 256.457 -    }
 256.458 -
 256.459 -    /**
 256.460 -     * Returns list of field info.
 256.461 -     */
 256.462 -    public  FieldData[] getFields(){
 256.463 -        return fields;
 256.464 -    }
 256.465 -
 256.466 -    /**
 256.467 -     * Returns list of method info.
 256.468 -     */
 256.469 -    public  MethodData[] getMethods(){
 256.470 -        return methods;
 256.471 -    }
 256.472 -
 256.473 -    /**
 256.474 -     * Returns constant pool entry at that index.
 256.475 -     */
 256.476 -    public CPX2 getCpoolEntry(int cpx){
 256.477 -        return ((CPX2)(cpool[cpx]));
 256.478 -    }
 256.479 -
 256.480 -    public Object getCpoolEntryobj(int cpx){
 256.481 -        return (cpool[cpx]);
 256.482 -    }
 256.483 -
 256.484 -    /**
 256.485 -     * Returns index of this class.
 256.486 -     */
 256.487 -    public int getthis_cpx(){
 256.488 -        return this_class;
 256.489 -    }
 256.490 -
 256.491 -    /**
 256.492 -     * Returns string at that index.
 256.493 -     */
 256.494 -    public String StringValue(int cpx) {
 256.495 -        return stringValue(cpx, false);
 256.496 -    }
 256.497 -    public String stringValue(int cpx, boolean textual) {
 256.498 -        return stringValue(cpx, textual, null);
 256.499 -    }
 256.500 -    public String stringValue(int cpx, String[] classRefs) {
 256.501 -        return stringValue(cpx, true, classRefs);
 256.502 -    }
 256.503 -    private String stringValue(int cpx, boolean textual, String[] refs) {
 256.504 -        if (cpx==0) return "#0";
 256.505 -        int tag;
 256.506 -        Object x;
 256.507 -        String suffix="";
 256.508 -        try {
 256.509 -            tag=tags[cpx];
 256.510 -            x=cpool[cpx];
 256.511 -        } catch (IndexOutOfBoundsException e) {
 256.512 -            return "<Incorrect CP index:"+cpx+">";
 256.513 -        }
 256.514 -
 256.515 -        if (x==null) return "<NULL>";
 256.516 -        switch (tag) {
 256.517 -        case CONSTANT_UTF8: {
 256.518 -            if (!textual) {
 256.519 -                return (String)x;
 256.520 -            }
 256.521 -            StringBuilder sb=new StringBuilder();
 256.522 -            String s=(String)x;
 256.523 -            for (int k=0; k<s.length(); k++) {
 256.524 -                char c=s.charAt(k);
 256.525 -                switch (c) {
 256.526 -                case '\\': sb.append('\\').append('\\'); break;
 256.527 -                case '\t': sb.append('\\').append('t'); break;
 256.528 -                case '\n': sb.append('\\').append('n'); break;
 256.529 -                case '\r': sb.append('\\').append('r'); break;
 256.530 -                case '\"': sb.append('\\').append('\"'); break;
 256.531 -                default: sb.append(c);
 256.532 -                }
 256.533 -            }
 256.534 -            return sb.toString();
 256.535 -        }
 256.536 -        case CONSTANT_DOUBLE: {
 256.537 -            Double d=(Double)x;
 256.538 -            String sd=d.toString();
 256.539 -            if (textual) {
 256.540 -                return sd;
 256.541 -            }
 256.542 -            return sd+"d";
 256.543 -        }
 256.544 -        case CONSTANT_FLOAT: {
 256.545 -            Float f=(Float)x;
 256.546 -            String sf=(f).toString();
 256.547 -            if (textual) {
 256.548 -                return sf;
 256.549 -            }
 256.550 -            return sf+"f";
 256.551 -        }
 256.552 -        case CONSTANT_LONG: {
 256.553 -            Long ln = (Long)x;
 256.554 -            if (textual) {
 256.555 -                return ln.toString();
 256.556 -            }
 256.557 -            return ln.toString()+'l';
 256.558 -        }
 256.559 -        case CONSTANT_INTEGER: {
 256.560 -            Integer in = (Integer)x;
 256.561 -            return in.toString();
 256.562 -        }
 256.563 -        case CONSTANT_CLASS:
 256.564 -            String jn = getClassName(cpx);
 256.565 -            if (textual) {
 256.566 -                if (refs != null) {
 256.567 -                    refs[0] = jn;
 256.568 -                }
 256.569 -                return jn;
 256.570 -            }
 256.571 -            return javaName(jn);
 256.572 -        case CONSTANT_STRING:
 256.573 -            String sv = stringValue(((CPX)x).cpx, textual);
 256.574 -            if (textual) {
 256.575 -                return '"' + sv + '"';
 256.576 -            } else {
 256.577 -                return sv;
 256.578 -            }
 256.579 -        case CONSTANT_FIELD:
 256.580 -        case CONSTANT_METHOD:
 256.581 -        case CONSTANT_INTERFACEMETHOD:
 256.582 -            //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
 256.583 -             return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
 256.584 -
 256.585 -        case CONSTANT_NAMEANDTYPE:
 256.586 -            return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
 256.587 -        default:
 256.588 -            return "UnknownTag"; //TBD
 256.589 -        }
 256.590 -    }
 256.591 -
 256.592 -    /**
 256.593 -     * Returns resolved java type name.
 256.594 -     */
 256.595 -    public String javaName(String name) {
 256.596 -        if( name==null) return "null";
 256.597 -        int len=name.length();
 256.598 -        if (len==0) return "\"\"";
 256.599 -        int cc='/';
 256.600 -    fullname: { // xxx/yyy/zzz
 256.601 -            int cp;
 256.602 -            for (int k=0; k<len; k += Character.charCount(cp)) {
 256.603 -                cp=name.codePointAt(k);
 256.604 -                if (cc=='/') {
 256.605 -                    if (!isJavaIdentifierStart(cp)) break fullname;
 256.606 -                } else if (cp!='/') {
 256.607 -                    if (!isJavaIdentifierPart(cp)) break fullname;
 256.608 -                }
 256.609 -                cc=cp;
 256.610 -            }
 256.611 -            return name;
 256.612 -        }
 256.613 -        return "\""+name+"\"";
 256.614 -    }
 256.615 -
 256.616 -    public String getName(int cpx) {
 256.617 -        String res;
 256.618 -        try {
 256.619 -            return javaName((String)cpool[cpx]); //.replace('/','.');
 256.620 -        } catch (ArrayIndexOutOfBoundsException e) {
 256.621 -            return "<invalid constant pool index:"+cpx+">";
 256.622 -        } catch (ClassCastException e) {
 256.623 -            return "<invalid constant pool ref:"+cpx+">";
 256.624 -        }
 256.625 -    }
 256.626 -
 256.627 -    /**
 256.628 -     * Returns unqualified class name.
 256.629 -     */
 256.630 -    public String getShortClassName(int cpx) {
 256.631 -        String classname=javaName(getClassName(cpx));
 256.632 -        pkgPrefixLen=classname.lastIndexOf("/")+1;
 256.633 -        if (pkgPrefixLen!=0) {
 256.634 -            pkgPrefix=classname.substring(0,pkgPrefixLen);
 256.635 -            if (classname.startsWith(pkgPrefix)) {
 256.636 -                return classname.substring(pkgPrefixLen);
 256.637 -            }
 256.638 -        }
 256.639 -        return classname;
 256.640 -    }
 256.641 -
 256.642 -    /**
 256.643 -     * Returns source file name.
 256.644 -     */
 256.645 -    public String getSourceName(){
 256.646 -        return getName(source_cpx);
 256.647 -    }
 256.648 -
 256.649 -    /**
 256.650 -     * Returns package name.
 256.651 -     */
 256.652 -    public String getPkgName(){
 256.653 -        String classname=getClassName(this_class);
 256.654 -        pkgPrefixLen=classname.lastIndexOf("/")+1;
 256.655 -        if (pkgPrefixLen!=0) {
 256.656 -            pkgPrefix=classname.substring(0,pkgPrefixLen);
 256.657 -            return("package  "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
 256.658 -        }else return null;
 256.659 -    }
 256.660 -
 256.661 -    /**
 256.662 -     * Returns total constant pool entry count.
 256.663 -     */
 256.664 -    public int getCpoolCount(){
 256.665 -        return cpool_count;
 256.666 -    }
 256.667 -
 256.668 -    /**
 256.669 -     * Returns minor version of class file.
 256.670 -     */
 256.671 -    public int getMinor_version(){
 256.672 -        return minor_version;
 256.673 -    }
 256.674 -
 256.675 -    /**
 256.676 -     * Returns major version of class file.
 256.677 -     */
 256.678 -    public int getMajor_version(){
 256.679 -        return major_version;
 256.680 -    }
 256.681 -
 256.682 -    private boolean isJavaIdentifierStart(int cp) {
 256.683 -        return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');
 256.684 -    }
 256.685 -
 256.686 -    private boolean isJavaIdentifierPart(int cp) {
 256.687 -        return isJavaIdentifierStart(cp) || ('0' <= cp && cp <= '9');
 256.688 -    }
 256.689 -
 256.690 -    public String[] getNameAndType(int indx) {
 256.691 -        return getNameAndType(indx, 0, new String[2]);
 256.692 -    }
 256.693 -    
 256.694 -    private String[] getNameAndType(int indx, int at, String[] arr) {
 256.695 -        CPX2 c2 = getCpoolEntry(indx);
 256.696 -        arr[at] = StringValue(c2.cpx1);
 256.697 -        arr[at + 1] = StringValue(c2.cpx2);
 256.698 -        return arr;
 256.699 -    }
 256.700 -
 256.701 -    public String[] getFieldInfoName(int indx) {
 256.702 -        CPX2 c2 = getCpoolEntry(indx);
 256.703 -        String[] arr = new String[3];
 256.704 -        arr[0] = getClassName(c2.cpx1);
 256.705 -        return getNameAndType(c2.cpx2, 1, arr);
 256.706 -    }
 256.707 -
 256.708 -    static byte[] findAttr(String n, AttrData[] attrs) {
 256.709 -        for (AttrData ad : attrs) {
 256.710 -            if (n.equals(ad.getAttrName())) {
 256.711 -                return ad.getData();
 256.712 -            }
 256.713 -        }
 256.714 -        return null;
 256.715 -    }
 256.716 -}
   257.1 --- a/javap/src/main/java/org/apidesign/javap/Constants.java	Mon Feb 25 19:00:08 2013 +0100
   257.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   257.3 @@ -1,372 +0,0 @@
   257.4 -/*
   257.5 - * Copyright (c) 2002, 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 -
  257.30 -
  257.31 -package org.apidesign.javap;
  257.32 -
  257.33 -/**
  257.34 - * This interface defines constant that are used
  257.35 - * throughout the compiler. It inherits from RuntimeConstants,
  257.36 - * which is an autogenerated class that contains contstants
  257.37 - * defined in the interpreter.
  257.38 - */
  257.39 -
  257.40 -public
  257.41 -interface Constants extends RuntimeConstants {
  257.42 -
  257.43 -     /**
  257.44 -     * End of input
  257.45 -     */
  257.46 -    public static final int EOF = -1;
  257.47 -
  257.48 -   /*
  257.49 -     * Flags
  257.50 -     */
  257.51 -    public static final int F_VERBOSE           = 1 << 0;
  257.52 -    public static final int F_DUMP              = 1 << 1;
  257.53 -    public static final int F_WARNINGS          = 1 << 2;
  257.54 -    public static final int F_DEBUG             = 1 << 3;
  257.55 -    public static final int F_OPTIMIZE          = 1 << 4;
  257.56 -    public static final int F_DEPENDENCIES      = 1 << 5;
  257.57 -
  257.58 -    /*
  257.59 -     * Type codes
  257.60 -     */
  257.61 -    public static final int TC_BOOLEAN   = 0;
  257.62 -    public static final int TC_BYTE      = 1;
  257.63 -    public static final int TC_CHAR      = 2;
  257.64 -    public static final int TC_SHORT     = 3;
  257.65 -    public static final int TC_INT       = 4;
  257.66 -    public static final int TC_LONG      = 5;
  257.67 -    public static final int TC_FLOAT     = 6;
  257.68 -    public static final int TC_DOUBLE    = 7;
  257.69 -    public static final int TC_NULL      = 8;
  257.70 -    public static final int TC_ARRAY     = 9;
  257.71 -    public static final int TC_CLASS     = 10;
  257.72 -    public static final int TC_VOID      = 11;
  257.73 -    public static final int TC_METHOD    = 12;
  257.74 -    public static final int TC_ERROR     = 13;
  257.75 -
  257.76 -    /*
  257.77 -     * Type Masks
  257.78 -     */
  257.79 -    public static final int TM_NULL      = 1 << TC_NULL;
  257.80 -    public static final int TM_VOID      = 1 << TC_VOID;
  257.81 -    public static final int TM_BOOLEAN   = 1 << TC_BOOLEAN;
  257.82 -    public static final int TM_BYTE      = 1 << TC_BYTE;
  257.83 -    public static final int TM_CHAR      = 1 << TC_CHAR;
  257.84 -    public static final int TM_SHORT     = 1 << TC_SHORT;
  257.85 -    public static final int TM_INT       = 1 << TC_INT;
  257.86 -    public static final int TM_LONG      = 1 << TC_LONG;
  257.87 -    public static final int TM_FLOAT     = 1 << TC_FLOAT;
  257.88 -    public static final int TM_DOUBLE    = 1 << TC_DOUBLE;
  257.89 -    public static final int TM_ARRAY     = 1 << TC_ARRAY;
  257.90 -    public static final int TM_CLASS     = 1 << TC_CLASS;
  257.91 -    public static final int TM_METHOD    = 1 << TC_METHOD;
  257.92 -    public static final int TM_ERROR     = 1 << TC_ERROR;
  257.93 -
  257.94 -    public static final int TM_INT32     = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
  257.95 -    public static final int TM_NUM32     = TM_INT32 | TM_FLOAT;
  257.96 -    public static final int TM_NUM64     = TM_LONG | TM_DOUBLE;
  257.97 -    public static final int TM_INTEGER   = TM_INT32 | TM_LONG;
  257.98 -    public static final int TM_REAL      = TM_FLOAT | TM_DOUBLE;
  257.99 -    public static final int TM_NUMBER    = TM_INTEGER | TM_REAL;
 257.100 -    public static final int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;
 257.101 -
 257.102 -    /*
 257.103 -     * Class status
 257.104 -     */
 257.105 -    public static final int CS_UNDEFINED        = 0;
 257.106 -    public static final int CS_UNDECIDED        = 1;
 257.107 -    public static final int CS_BINARY           = 2;
 257.108 -    public static final int CS_SOURCE           = 3;
 257.109 -    public static final int CS_PARSED           = 4;
 257.110 -    public static final int CS_COMPILED         = 5;
 257.111 -    public static final int CS_NOTFOUND         = 6;
 257.112 -
 257.113 -    /*
 257.114 -     * Attributes
 257.115 -     */
 257.116 -    public static final int ATT_ALL             = -1;
 257.117 -    public static final int ATT_CODE            = 1;
 257.118 -
 257.119 -    /*
 257.120 -     * Number of bits used in file offsets
 257.121 -     */
 257.122 -    public static final int OFFSETBITS          = 19;
 257.123 -    public static final int MAXFILESIZE         = (1 << OFFSETBITS) - 1;
 257.124 -    public static final int MAXLINENUMBER       = (1 << (32 - OFFSETBITS)) - 1;
 257.125 -
 257.126 -    /*
 257.127 -     * Operators
 257.128 -     */
 257.129 -    public final int COMMA              = 0;
 257.130 -    public final int ASSIGN             = 1;
 257.131 -
 257.132 -    public final int ASGMUL             = 2;
 257.133 -    public final int ASGDIV             = 3;
 257.134 -    public final int ASGREM             = 4;
 257.135 -    public final int ASGADD             = 5;
 257.136 -    public final int ASGSUB             = 6;
 257.137 -    public final int ASGLSHIFT          = 7;
 257.138 -    public final int ASGRSHIFT          = 8;
 257.139 -    public final int ASGURSHIFT         = 9;
 257.140 -    public final int ASGBITAND          = 10;
 257.141 -    public final int ASGBITOR           = 11;
 257.142 -    public final int ASGBITXOR          = 12;
 257.143 -
 257.144 -    public final int COND               = 13;
 257.145 -    public final int OR                 = 14;
 257.146 -    public final int AND                = 15;
 257.147 -    public final int BITOR              = 16;
 257.148 -    public final int BITXOR             = 17;
 257.149 -    public final int BITAND             = 18;
 257.150 -    public final int NE                 = 19;
 257.151 -    public final int EQ                 = 20;
 257.152 -    public final int GE                 = 21;
 257.153 -    public final int GT                 = 22;
 257.154 -    public final int LE                 = 23;
 257.155 -    public final int LT                 = 24;
 257.156 -    public final int INSTANCEOF         = 25;
 257.157 -    public final int LSHIFT             = 26;
 257.158 -    public final int RSHIFT             = 27;
 257.159 -    public final int URSHIFT            = 28;
 257.160 -    public final int ADD                = 29;
 257.161 -    public final int SUB                = 30;
 257.162 -    public final int DIV                = 31;
 257.163 -    public final int REM                = 32;
 257.164 -    public final int MUL                = 33;
 257.165 -    public final int CAST               = 34;           // (x)y
 257.166 -    public final int POS                = 35;           // +x
 257.167 -    public final int NEG                = 36;           // -x
 257.168 -    public final int NOT                = 37;
 257.169 -    public final int BITNOT             = 38;
 257.170 -    public final int PREINC             = 39;           // ++x
 257.171 -    public final int PREDEC             = 40;           // --x
 257.172 -    public final int NEWARRAY           = 41;
 257.173 -    public final int NEWINSTANCE        = 42;
 257.174 -    public final int NEWFROMNAME        = 43;
 257.175 -    public final int POSTINC            = 44;           // x++
 257.176 -    public final int POSTDEC            = 45;           // x--
 257.177 -    public final int FIELD              = 46;
 257.178 -    public final int METHOD             = 47;           // x(y)
 257.179 -    public final int ARRAYACCESS        = 48;           // x[y]
 257.180 -    public final int NEW                = 49;
 257.181 -    public final int INC                = 50;
 257.182 -    public final int DEC                = 51;
 257.183 -
 257.184 -    public final int CONVERT            = 55;           // implicit conversion
 257.185 -    public final int EXPR               = 56;           // (x)
 257.186 -    public final int ARRAY              = 57;           // {x, y, ...}
 257.187 -    public final int GOTO               = 58;
 257.188 -
 257.189 -    /*
 257.190 -     * Value tokens
 257.191 -     */
 257.192 -    public final int IDENT              = 60;
 257.193 -    public final int BOOLEANVAL         = 61;
 257.194 -    public final int BYTEVAL            = 62;
 257.195 -    public final int CHARVAL            = 63;
 257.196 -    public final int SHORTVAL           = 64;
 257.197 -    public final int INTVAL                     = 65;
 257.198 -    public final int LONGVAL            = 66;
 257.199 -    public final int FLOATVAL           = 67;
 257.200 -    public final int DOUBLEVAL          = 68;
 257.201 -    public final int STRINGVAL          = 69;
 257.202 -
 257.203 -    /*
 257.204 -     * Type keywords
 257.205 -     */
 257.206 -    public final int BYTE               = 70;
 257.207 -    public final int CHAR               = 71;
 257.208 -    public final int SHORT              = 72;
 257.209 -    public final int INT                = 73;
 257.210 -    public final int LONG               = 74;
 257.211 -    public final int FLOAT              = 75;
 257.212 -    public final int DOUBLE             = 76;
 257.213 -    public final int VOID               = 77;
 257.214 -    public final int BOOLEAN            = 78;
 257.215 -
 257.216 -    /*
 257.217 -     * Expression keywords
 257.218 -     */
 257.219 -    public final int TRUE               = 80;
 257.220 -    public final int FALSE              = 81;
 257.221 -    public final int THIS               = 82;
 257.222 -    public final int SUPER              = 83;
 257.223 -    public final int NULL               = 84;
 257.224 -
 257.225 -    /*
 257.226 -     * Statement keywords
 257.227 -     */
 257.228 -    public final int IF                 = 90;
 257.229 -    public final int ELSE               = 91;
 257.230 -    public final int FOR                = 92;
 257.231 -    public final int WHILE              = 93;
 257.232 -    public final int DO                 = 94;
 257.233 -    public final int SWITCH             = 95;
 257.234 -    public final int CASE               = 96;
 257.235 -    public final int DEFAULT            = 97;
 257.236 -    public final int BREAK              = 98;
 257.237 -    public final int CONTINUE           = 99;
 257.238 -    public final int RETURN             = 100;
 257.239 -    public final int TRY                = 101;
 257.240 -    public final int CATCH              = 102;
 257.241 -    public final int FINALLY            = 103;
 257.242 -    public final int THROW              = 104;
 257.243 -    public final int STAT               = 105;
 257.244 -    public final int EXPRESSION         = 106;
 257.245 -    public final int DECLARATION        = 107;
 257.246 -    public final int VARDECLARATION     = 108;
 257.247 -
 257.248 -    /*
 257.249 -     * Declaration keywords
 257.250 -     */
 257.251 -    public final int IMPORT             = 110;
 257.252 -    public final int CLASS              = 111;
 257.253 -    public final int EXTENDS            = 112;
 257.254 -    public final int IMPLEMENTS         = 113;
 257.255 -    public final int INTERFACE          = 114;
 257.256 -    public final int PACKAGE            = 115;
 257.257 -
 257.258 -    /*
 257.259 -     * Modifier keywords
 257.260 -     */
 257.261 -    public final int PRIVATE    = 120;
 257.262 -    public final int PUBLIC             = 121;
 257.263 -    public final int PROTECTED  = 122;
 257.264 -    public final int CONST              = 123;
 257.265 -    public final int STATIC             = 124;
 257.266 -    public final int TRANSIENT          = 125;
 257.267 -    public final int SYNCHRONIZED       = 126;
 257.268 -    public final int NATIVE             = 127;
 257.269 -    public final int FINAL              = 128;
 257.270 -    public final int VOLATILE   = 129;
 257.271 -    public final int ABSTRACT   = 130;
 257.272 -    public final int STRICT             = 165;
 257.273 -
 257.274 -    /*
 257.275 -     * Punctuation
 257.276 -     */
 257.277 -    public final int SEMICOLON  = 135;
 257.278 -    public final int COLON              = 136;
 257.279 -    public final int QUESTIONMARK       = 137;
 257.280 -    public final int LBRACE             = 138;
 257.281 -    public final int RBRACE             = 139;
 257.282 -    public final int LPAREN             = 140;
 257.283 -    public final int RPAREN             = 141;
 257.284 -    public final int LSQBRACKET = 142;
 257.285 -    public final int RSQBRACKET = 143;
 257.286 -    public final int THROWS     = 144;
 257.287 -
 257.288 -    /*
 257.289 -     * Special tokens
 257.290 -     */
 257.291 -    public final int ERROR              = 145;          // an error
 257.292 -    public final int COMMENT    = 146;          // not used anymore.
 257.293 -    public final int TYPE               = 147;
 257.294 -    public final int LENGTH             = 148;
 257.295 -    public final int INLINERETURN       = 149;
 257.296 -    public final int INLINEMETHOD       = 150;
 257.297 -    public final int INLINENEWINSTANCE  = 151;
 257.298 -
 257.299 -    /*
 257.300 -     * Added for jasm
 257.301 -     */
 257.302 -        public final int METHODREF      = 152;
 257.303 -        public final int FIELDREF       = 153;
 257.304 -    public final int STACK              = 154;
 257.305 -    public final int LOCAL              = 155;
 257.306 -    public final int CPINDEX    = 156;
 257.307 -    public final int CPNAME             = 157;
 257.308 -    public final int SIGN               = 158;
 257.309 -    public final int BITS               = 159;
 257.310 -    public final int INF                = 160;
 257.311 -    public final int NAN                = 161;
 257.312 -    public final int INNERCLASS = 162;
 257.313 -    public final int OF         = 163;
 257.314 -    public final int SYNTHETIC          = 164;
 257.315 -// last used=165;
 257.316 -
 257.317 -   /*
 257.318 -     * Operator precedence
 257.319 -     */
 257.320 -    public static final int opPrecedence[] = {
 257.321 -        10,     11,     11,     11,     11,     11,     11,     11,     11,     11,
 257.322 -        11,     11,     11,     12,     13,     14,     15,     16,     17,     18,
 257.323 -        18,     19,     19,     19,     19,     19,     20,     20,     20,     21,
 257.324 -        21,     22,     22,     22,     23,     24,     24,     24,     24,     24,
 257.325 -        24,     25,     25,     26,     26,     26,     26,     26,     26
 257.326 -    };
 257.327 -
 257.328 -    /*
 257.329 -     * Operator names
 257.330 -     */
 257.331 -    public static final String opNames[] = {
 257.332 -        ",",            "=",            "*=",           "/=",           "%=",
 257.333 -        "+=",           "-=",           "<<=",          ">>=",          "<<<=",
 257.334 -        "&=",           "|=",           "^=",           "?:",           "||",
 257.335 -        "&&",           "|",            "^",            "&",            "!=",
 257.336 -        "==",           ">=",           ">",            "<=",           "<",
 257.337 -        "instanceof",   "<<",           ">>",           "<<<",          "+",
 257.338 -        "-",            "/",            "%",            "*",            "cast",
 257.339 -        "+",            "-",            "!",            "~",            "++",
 257.340 -        "--",           "new",          "new",          "new",          "++",
 257.341 -        "--",           "field",        "method",       "[]",           "new",
 257.342 -        "++",           "--",           null,           null,           null,
 257.343 -
 257.344 -        "convert",      "expr",         "array",        "goto",         null,
 257.345 -
 257.346 -        "Identifier",   "Boolean",      "Byte",         "Char",         "Short",
 257.347 -        "Integer",              "Long",         "Float",        "Double",       "String",
 257.348 -
 257.349 -        "byte",         "char",         "short",        "int",          "long",
 257.350 -        "float",        "double",       "void",         "boolean",      null,
 257.351 -
 257.352 -        "true",         "false",        "this",         "super",        "null",
 257.353 -        null,           null,           null,           null,           null,
 257.354 -
 257.355 -        "if",           "else",         "for",          "while",        "do",
 257.356 -        "switch",       "case",         "default",      "break",        "continue",
 257.357 -        "return",       "try",          "catch",        "finally",      "throw",
 257.358 -        "stat",         "expression",   "declaration",  "declaration",  null,
 257.359 -
 257.360 -        "import",       "class",        "extends",      "implements",   "interface",
 257.361 -        "package",      null,           null,           null,           null,
 257.362 -
 257.363 -        "private",      "public",       "protected",    "const",        "static",
 257.364 -        "transient",    "synchronized", "native",       "final",        "volatile",
 257.365 -        "abstract",     null,           null,           null,           null,
 257.366 -
 257.367 -        ";",            ":",            "?",            "{",            "}",
 257.368 -        "(",            ")",            "[",            "]",            "throws",
 257.369 -        "error",        "comment",      "type",         "length",       "inline-return",
 257.370 -        "inline-method", "inline-new",
 257.371 -        "method", "field", "stack", "locals", "CPINDEX", "CPName", "SIGN",
 257.372 -        "bits", "INF", "NaN", "InnerClass", "of", "synthetic"
 257.373 -    };
 257.374 -
 257.375 -}
   258.1 --- a/javap/src/main/java/org/apidesign/javap/FieldData.java	Mon Feb 25 19:00:08 2013 +0100
   258.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   258.3 @@ -1,168 +0,0 @@
   258.4 -/*
   258.5 - * Copyright (c) 2002, 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 -
  258.30 -package org.apidesign.javap;
  258.31 -
  258.32 -import java.io.*;
  258.33 -
  258.34 -/**
  258.35 - * Strores field data informastion.
  258.36 - *
  258.37 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  258.38 - */
  258.39 -
  258.40 -public class FieldData implements RuntimeConstants  {
  258.41 -
  258.42 -    ClassData cls;
  258.43 -    int access;
  258.44 -    int name_index;
  258.45 -    int descriptor_index;
  258.46 -    int attributes_count;
  258.47 -    int value_cpx=0;
  258.48 -    boolean isSynthetic=false;
  258.49 -    boolean isDeprecated=false;
  258.50 -    Vector attrs;
  258.51 -
  258.52 -    public FieldData(ClassData cls){
  258.53 -        this.cls=cls;
  258.54 -    }
  258.55 -
  258.56 -    /**
  258.57 -     * Read and store field info.
  258.58 -     */
  258.59 -    public void read(DataInputStream in) throws IOException {
  258.60 -        access = in.readUnsignedShort();
  258.61 -        name_index = in.readUnsignedShort();
  258.62 -        descriptor_index = in.readUnsignedShort();
  258.63 -        // Read the attributes
  258.64 -        int attributes_count = in.readUnsignedShort();
  258.65 -        attrs=new Vector(attributes_count);
  258.66 -        for (int i = 0; i < attributes_count; i++) {
  258.67 -            int attr_name_index=in.readUnsignedShort();
  258.68 -            if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
  258.69 -            String attr_name=cls.getString(attr_name_index);
  258.70 -            if (attr_name.equals("ConstantValue")){
  258.71 -                if (in.readInt()!=2)
  258.72 -                    throw new ClassFormatError("invalid ConstantValue attr length");
  258.73 -                value_cpx=in.readUnsignedShort();
  258.74 -                AttrData attr=new AttrData(cls);
  258.75 -                attr.read(attr_name_index);
  258.76 -                attrs.addElement(attr);
  258.77 -            } else if (attr_name.equals("Synthetic")){
  258.78 -                if (in.readInt()!=0)
  258.79 -                    throw new ClassFormatError("invalid Synthetic attr length");
  258.80 -                isSynthetic=true;
  258.81 -                AttrData attr=new AttrData(cls);
  258.82 -                attr.read(attr_name_index);
  258.83 -                attrs.addElement(attr);
  258.84 -            } else if (attr_name.equals("Deprecated")){
  258.85 -                if (in.readInt()!=0)
  258.86 -                    throw new ClassFormatError("invalid Synthetic attr length");
  258.87 -                isDeprecated = true;
  258.88 -                AttrData attr=new AttrData(cls);
  258.89 -                attr.read(attr_name_index);
  258.90 -                attrs.addElement(attr);
  258.91 -            } else {
  258.92 -                AttrData attr=new AttrData(cls);
  258.93 -                attr.read(attr_name_index, in);
  258.94 -                attrs.addElement(attr);
  258.95 -            }
  258.96 -        }
  258.97 -
  258.98 -    }  // end read
  258.99 -
 258.100 -    public boolean isStatic() {
 258.101 -        return (access & ACC_STATIC) != 0;
 258.102 -    }
 258.103 -    
 258.104 -    /**
 258.105 -     * Returns access of a field.
 258.106 -     */
 258.107 -    public String[] getAccess(){
 258.108 -        Vector v = new Vector();
 258.109 -        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
 258.110 -        if ((access & ACC_PRIVATE)   !=0) v.addElement("private");
 258.111 -        if ((access & ACC_PROTECTED)   !=0) v.addElement("protected");
 258.112 -        if ((access & ACC_STATIC)   !=0) v.addElement("static");
 258.113 -        if ((access & ACC_FINAL)    !=0) v.addElement("final");
 258.114 -        if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
 258.115 -        if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
 258.116 -        String[] accflags = new String[v.size()];
 258.117 -        v.copyInto(accflags);
 258.118 -        return accflags;
 258.119 -    }
 258.120 -
 258.121 -    /**
 258.122 -     * Returns name of a field.
 258.123 -     */
 258.124 -    public String getName(){
 258.125 -        return cls.getStringValue(name_index);
 258.126 -    }
 258.127 -
 258.128 -    /**
 258.129 -     * Returns internal signature of a field
 258.130 -     */
 258.131 -    public String getInternalSig(){
 258.132 -        return cls.getStringValue(descriptor_index);
 258.133 -    }
 258.134 -
 258.135 -    /**
 258.136 -     * Returns true if field is synthetic.
 258.137 -     */
 258.138 -    public boolean isSynthetic(){
 258.139 -        return isSynthetic;
 258.140 -    }
 258.141 -
 258.142 -    /**
 258.143 -     * Returns true if field is deprecated.
 258.144 -     */
 258.145 -    public boolean isDeprecated(){
 258.146 -        return isDeprecated;
 258.147 -    }
 258.148 -
 258.149 -    /**
 258.150 -     * Returns index of constant value in cpool.
 258.151 -     */
 258.152 -    public int getConstantValueIndex(){
 258.153 -        return (value_cpx);
 258.154 -    }
 258.155 -
 258.156 -    /**
 258.157 -     * Returns list of attributes of field.
 258.158 -     */
 258.159 -    public Vector getAttributes(){
 258.160 -        return attrs;
 258.161 -    }
 258.162 -
 258.163 -    public byte[] findAnnotationData(boolean classRetention) {
 258.164 -        String n = classRetention ?
 258.165 -            "RuntimeInvisibleAnnotations" : // NOI18N
 258.166 -            "RuntimeVisibleAnnotations"; // NOI18N
 258.167 -        AttrData[] arr = new AttrData[attrs.size()];
 258.168 -        attrs.copyInto(arr);
 258.169 -        return ClassData.findAttr(n, arr);
 258.170 -    }
 258.171 -}
   259.1 --- a/javap/src/main/java/org/apidesign/javap/Hashtable.java	Mon Feb 25 19:00:08 2013 +0100
   259.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   259.3 @@ -1,94 +0,0 @@
   259.4 -/**
   259.5 - * Back 2 Browser Bytecode Translator
   259.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   259.7 - *
   259.8 - * This program is free software: you can redistribute it and/or modify
   259.9 - * it under the terms of the GNU General Public License as published by
  259.10 - * the Free Software Foundation, version 2 of the License.
  259.11 - *
  259.12 - * This program is distributed in the hope that it will be useful,
  259.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  259.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  259.15 - * GNU General Public License for more details.
  259.16 - *
  259.17 - * You should have received a copy of the GNU General Public License
  259.18 - * along with this program. Look for COPYING file in the top folder.
  259.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  259.20 - */
  259.21 -package org.apidesign.javap;
  259.22 -
  259.23 -/** A JavaScript optimized replacement for Hashtable.
  259.24 - *
  259.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  259.26 - */
  259.27 -final class Hashtable {
  259.28 -    private Object[] keys;
  259.29 -    private Object[] values;
  259.30 -
  259.31 -    Hashtable(int i) {
  259.32 -        this();
  259.33 -    }
  259.34 -
  259.35 -    Hashtable(int i, double d) {
  259.36 -        this();
  259.37 -    }
  259.38 -
  259.39 -    Hashtable() {
  259.40 -    }
  259.41 -
  259.42 -    synchronized void put(Object key, Object val) {
  259.43 -        int[] where = { -1, -1 };
  259.44 -        Object found = get(key, where);
  259.45 -        if (where[0] != -1) {
  259.46 -            // key exists
  259.47 -            values[where[0]] = val;
  259.48 -        } else {
  259.49 -            if (where[1] != -1) {
  259.50 -                // null found
  259.51 -                keys[where[1]] = key;
  259.52 -                values[where[1]] = val;
  259.53 -            } else {
  259.54 -                if (keys == null) {
  259.55 -                    keys = new Object[11];
  259.56 -                    values = new Object[11];
  259.57 -                    keys[0] = key;
  259.58 -                    values[0] = val;
  259.59 -                } else {
  259.60 -                    Object[] newKeys = new Object[keys.length * 2];
  259.61 -                    Object[] newValues = new Object[values.length * 2];
  259.62 -                    for (int i = 0; i < keys.length; i++) {
  259.63 -                        newKeys[i] = keys[i];
  259.64 -                        newValues[i] = values[i];
  259.65 -                    }
  259.66 -                    newKeys[keys.length] = key;
  259.67 -                    newValues[keys.length] = val;
  259.68 -                    keys = newKeys;
  259.69 -                    values = newValues;
  259.70 -                }
  259.71 -            }
  259.72 -        }
  259.73 -    }
  259.74 -
  259.75 -    Object get(Object key) {
  259.76 -        return get(key, null);
  259.77 -    }
  259.78 -    private synchronized Object get(Object key, int[] foundAndNull) {
  259.79 -        if (keys == null) {
  259.80 -            return null;
  259.81 -        }
  259.82 -        for (int i = 0; i < keys.length; i++) {
  259.83 -            if (keys[i] == null) {
  259.84 -                if (foundAndNull != null) {
  259.85 -                    foundAndNull[1] = i;
  259.86 -                }
  259.87 -            } else if (keys[i].equals(key)) {
  259.88 -                if (foundAndNull != null) {
  259.89 -                    foundAndNull[0] = i;
  259.90 -                }
  259.91 -                return values[i];
  259.92 -            }
  259.93 -        }
  259.94 -        return null;
  259.95 -    }
  259.96 -    
  259.97 -}
   260.1 --- a/javap/src/main/java/org/apidesign/javap/InnerClassData.java	Mon Feb 25 19:00:08 2013 +0100
   260.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   260.3 @@ -1,75 +0,0 @@
   260.4 -/*
   260.5 - * Copyright (c) 2002, 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 -
  260.30 -package org.apidesign.javap;
  260.31 -
  260.32 -import java.io.*;
  260.33 -import java.util.*;
  260.34 -
  260.35 -/**
  260.36 - * Strores InnerClass data informastion.
  260.37 - *
  260.38 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  260.39 - */
  260.40 -class InnerClassData  implements RuntimeConstants {
  260.41 -    ClassData cls;
  260.42 -
  260.43 -
  260.44 -    int inner_class_info_index
  260.45 -        ,outer_class_info_index
  260.46 -        ,inner_name_index
  260.47 -        ,access
  260.48 -        ;
  260.49 -
  260.50 -    public InnerClassData(ClassData cls) {
  260.51 -        this.cls=cls;
  260.52 -
  260.53 -    }
  260.54 -
  260.55 -    /**
  260.56 -     * Read Innerclass attribute data.
  260.57 -     */
  260.58 -    public void read(DataInputStream in) throws IOException {
  260.59 -        inner_class_info_index = in.readUnsignedShort();
  260.60 -        outer_class_info_index = in.readUnsignedShort();
  260.61 -        inner_name_index = in.readUnsignedShort();
  260.62 -        access = in.readUnsignedShort();
  260.63 -    }  // end read
  260.64 -
  260.65 -    /**
  260.66 -     * Returns the access of this class or interface.
  260.67 -     */
  260.68 -    public String[] getAccess(){
  260.69 -        Vector v = new Vector();
  260.70 -        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
  260.71 -        if ((access & ACC_FINAL)    !=0) v.addElement("final");
  260.72 -        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
  260.73 -        String[] accflags = new String[v.size()];
  260.74 -        v.copyInto(accflags);
  260.75 -        return accflags;
  260.76 -    }
  260.77 -
  260.78 -} // end InnerClassData
   261.1 --- a/javap/src/main/java/org/apidesign/javap/LineNumData.java	Mon Feb 25 19:00:08 2013 +0100
   261.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   261.3 @@ -1,50 +0,0 @@
   261.4 -/*
   261.5 - * Copyright (c) 2002, 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 -
  261.30 -package org.apidesign.javap;
  261.31 -
  261.32 -import java.util.*;
  261.33 -import java.io.*;
  261.34 -
  261.35 -/**
  261.36 - * Strores LineNumberTable data information.
  261.37 - *
  261.38 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  261.39 - */
  261.40 -class LineNumData {
  261.41 -    short start_pc, line_number;
  261.42 -
  261.43 -    public LineNumData() {}
  261.44 -
  261.45 -    /**
  261.46 -     * Read LineNumberTable attribute.
  261.47 -     */
  261.48 -    public LineNumData(DataInputStream in) throws IOException {
  261.49 -        start_pc = in.readShort();
  261.50 -        line_number=in.readShort();
  261.51 -
  261.52 -    }
  261.53 -}
   262.1 --- a/javap/src/main/java/org/apidesign/javap/LocVarData.java	Mon Feb 25 19:00:08 2013 +0100
   262.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   262.3 @@ -1,54 +0,0 @@
   262.4 -/*
   262.5 - * Copyright (c) 2002, 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 -
  262.30 -package org.apidesign.javap;
  262.31 -
  262.32 -import java.util.*;
  262.33 -import java.io.*;
  262.34 -
  262.35 -/**
  262.36 - * Strores LocalVariableTable data information.
  262.37 - *
  262.38 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  262.39 - */
  262.40 -class LocVarData {
  262.41 -    short start_pc, length, name_cpx, sig_cpx, slot;
  262.42 -
  262.43 -    public LocVarData() {
  262.44 -    }
  262.45 -
  262.46 -    /**
  262.47 -     * Read LocalVariableTable attribute.
  262.48 -     */
  262.49 -    public LocVarData(DataInputStream in) throws IOException {
  262.50 -        start_pc = in.readShort();
  262.51 -        length=in.readShort();
  262.52 -        name_cpx=in.readShort();
  262.53 -        sig_cpx=in.readShort();
  262.54 -        slot=in.readShort();
  262.55 -
  262.56 -    }
  262.57 -}
   263.1 --- a/javap/src/main/java/org/apidesign/javap/MethodData.java	Mon Feb 25 19:00:08 2013 +0100
   263.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   263.3 @@ -1,394 +0,0 @@
   263.4 -/*
   263.5 - * Copyright (c) 2002, 2005, 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 org.apidesign.javap;
  263.30 -
  263.31 -
  263.32 -import java.io.DataInputStream;
  263.33 -import java.io.IOException;
  263.34 -import static org.apidesign.javap.RuntimeConstants.*;
  263.35 -
  263.36 -/**
  263.37 - * Strores method data informastion.
  263.38 - *
  263.39 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  263.40 - */
  263.41 -public class MethodData {
  263.42 -
  263.43 -    ClassData cls;
  263.44 -    int access;
  263.45 -    int name_index;
  263.46 -    int descriptor_index;
  263.47 -    int attributes_count;
  263.48 -    byte[] code;
  263.49 -    Vector exception_table = new Vector(0);
  263.50 -    Vector lin_num_tb = new Vector(0);
  263.51 -    Vector loc_var_tb = new Vector(0);
  263.52 -    StackMapTableData[] stackMapTable;
  263.53 -    StackMapData[] stackMap;
  263.54 -    int[] exc_index_table=null;
  263.55 -    Vector attrs=new Vector(0);
  263.56 -    Vector code_attrs=new Vector(0);
  263.57 -    int max_stack,  max_locals;
  263.58 -    boolean isSynthetic=false;
  263.59 -    boolean isDeprecated=false;
  263.60 -
  263.61 -    public MethodData(ClassData cls){
  263.62 -        this.cls=cls;
  263.63 -    }
  263.64 -
  263.65 -    /**
  263.66 -     * Read method info.
  263.67 -     */
  263.68 -    public void read(DataInputStream in) throws IOException {
  263.69 -        access = in.readUnsignedShort();
  263.70 -        name_index=in.readUnsignedShort();
  263.71 -        descriptor_index =in.readUnsignedShort();
  263.72 -        int attributes_count = in.readUnsignedShort();
  263.73 -        for (int i = 0; i < attributes_count; i++) {
  263.74 -            int attr_name_index=in.readUnsignedShort();
  263.75 -
  263.76 -        readAttr: {
  263.77 -                if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
  263.78 -                    String  attr_name=cls.getString(attr_name_index);
  263.79 -                    if ( attr_name.equals("Code")){
  263.80 -                        readCode (in);
  263.81 -                        AttrData attr=new AttrData(cls);
  263.82 -                        attr.read(attr_name_index);
  263.83 -                        attrs.addElement(attr);
  263.84 -                        break readAttr;
  263.85 -                    } else if ( attr_name.equals("Exceptions")){
  263.86 -                        readExceptions(in);
  263.87 -                        AttrData attr=new AttrData(cls);
  263.88 -                        attr.read(attr_name_index);
  263.89 -                        attrs.addElement(attr);
  263.90 -                        break readAttr;
  263.91 -                    } else if (attr_name.equals("Synthetic")){
  263.92 -                        if (in.readInt()!=0)
  263.93 -                            throw new ClassFormatError("invalid Synthetic attr length");
  263.94 -                        isSynthetic=true;
  263.95 -                        AttrData attr=new AttrData(cls);
  263.96 -                        attr.read(attr_name_index);
  263.97 -                        attrs.addElement(attr);
  263.98 -                        break readAttr;
  263.99 -                    } else if (attr_name.equals("Deprecated")){
 263.100 -                        if (in.readInt()!=0)
 263.101 -                            throw new ClassFormatError("invalid Synthetic attr length");
 263.102 -                        isDeprecated = true;
 263.103 -                        AttrData attr=new AttrData(cls);
 263.104 -                        attr.read(attr_name_index);
 263.105 -                        attrs.addElement(attr);
 263.106 -                        break readAttr;
 263.107 -                    }
 263.108 -                }
 263.109 -                AttrData attr=new AttrData(cls);
 263.110 -                attr.read(attr_name_index, in);
 263.111 -                attrs.addElement(attr);
 263.112 -            }
 263.113 -        }
 263.114 -    }
 263.115 -
 263.116 -    /**
 263.117 -     * Read code attribute info.
 263.118 -     */
 263.119 -    public void readCode(DataInputStream in) throws IOException {
 263.120 -
 263.121 -        int attr_length = in.readInt();
 263.122 -        max_stack=in.readUnsignedShort();
 263.123 -        max_locals=in.readUnsignedShort();
 263.124 -        int codelen=in.readInt();
 263.125 -
 263.126 -        code=new byte[codelen];
 263.127 -        int totalread = 0;
 263.128 -        while(totalread < codelen){
 263.129 -            totalread += in.read(code, totalread, codelen-totalread);
 263.130 -        }
 263.131 -        //      in.read(code, 0, codelen);
 263.132 -        int clen = 0;
 263.133 -        readExceptionTable(in);
 263.134 -        int code_attributes_count = in.readUnsignedShort();
 263.135 -
 263.136 -        for (int k = 0 ; k < code_attributes_count ; k++) {
 263.137 -            int table_name_index=in.readUnsignedShort();
 263.138 -            int table_name_tag=cls.getTag(table_name_index);
 263.139 -            AttrData attr=new AttrData(cls);
 263.140 -            if (table_name_tag==CONSTANT_UTF8) {
 263.141 -                String table_name_tstr=cls.getString(table_name_index);
 263.142 -                if (table_name_tstr.equals("LineNumberTable")) {
 263.143 -                    readLineNumTable(in);
 263.144 -                    attr.read(table_name_index);
 263.145 -                } else if (table_name_tstr.equals("LocalVariableTable")) {
 263.146 -                    readLocVarTable(in);
 263.147 -                    attr.read(table_name_index);
 263.148 -                } else if (table_name_tstr.equals("StackMapTable")) {
 263.149 -                    readStackMapTable(in);
 263.150 -                    attr.read(table_name_index);
 263.151 -                } else if (table_name_tstr.equals("StackMap")) {
 263.152 -                    readStackMap(in);
 263.153 -                    attr.read(table_name_index);
 263.154 -                } else {
 263.155 -                    attr.read(table_name_index, in);
 263.156 -                }
 263.157 -                code_attrs.addElement(attr);
 263.158 -                continue;
 263.159 -            }
 263.160 -
 263.161 -            attr.read(table_name_index, in);
 263.162 -            code_attrs.addElement(attr);
 263.163 -        }
 263.164 -    }
 263.165 -
 263.166 -    /**
 263.167 -     * Read exception table info.
 263.168 -     */
 263.169 -    void readExceptionTable (DataInputStream in) throws IOException {
 263.170 -        int exception_table_len=in.readUnsignedShort();
 263.171 -        exception_table=new Vector(exception_table_len);
 263.172 -        for (int l = 0; l < exception_table_len; l++) {
 263.173 -            exception_table.addElement(new TrapData(in, l));
 263.174 -        }
 263.175 -    }
 263.176 -
 263.177 -    /**
 263.178 -     * Read LineNumberTable attribute info.
 263.179 -     */
 263.180 -    void readLineNumTable (DataInputStream in) throws IOException {
 263.181 -        int attr_len = in.readInt(); // attr_length
 263.182 -        int lin_num_tb_len = in.readUnsignedShort();
 263.183 -        lin_num_tb=new Vector(lin_num_tb_len);
 263.184 -        for (int l = 0; l < lin_num_tb_len; l++) {
 263.185 -            lin_num_tb.addElement(new LineNumData(in));
 263.186 -        }
 263.187 -    }
 263.188 -
 263.189 -    /**
 263.190 -     * Read LocalVariableTable attribute info.
 263.191 -     */
 263.192 -    void readLocVarTable (DataInputStream in) throws IOException {
 263.193 -        int attr_len=in.readInt(); // attr_length
 263.194 -        int loc_var_tb_len = in.readUnsignedShort();
 263.195 -        loc_var_tb = new Vector(loc_var_tb_len);
 263.196 -        for (int l = 0; l < loc_var_tb_len; l++) {
 263.197 -            loc_var_tb.addElement(new LocVarData(in));
 263.198 -        }
 263.199 -    }
 263.200 -
 263.201 -    /**
 263.202 -     * Read Exception attribute info.
 263.203 -     */
 263.204 -    public void readExceptions(DataInputStream in) throws IOException {
 263.205 -        int attr_len=in.readInt(); // attr_length in prog
 263.206 -        int num_exceptions = in.readUnsignedShort();
 263.207 -        exc_index_table=new int[num_exceptions];
 263.208 -        for (int l = 0; l < num_exceptions; l++) {
 263.209 -            int exc=in.readShort();
 263.210 -            exc_index_table[l]=exc;
 263.211 -        }
 263.212 -    }
 263.213 -
 263.214 -    /**
 263.215 -     * Read StackMapTable attribute info.
 263.216 -     */
 263.217 -    void readStackMapTable(DataInputStream in) throws IOException {
 263.218 -        int attr_len = in.readInt();  //attr_length
 263.219 -        int stack_map_tb_len = in.readUnsignedShort();
 263.220 -        stackMapTable = new StackMapTableData[stack_map_tb_len];
 263.221 -        for (int i=0; i<stack_map_tb_len; i++) {
 263.222 -            stackMapTable[i] = StackMapTableData.getInstance(in, this);
 263.223 -        }
 263.224 -    }
 263.225 -
 263.226 -    /**
 263.227 -     * Read StackMap attribute info.
 263.228 -     */
 263.229 -    void readStackMap(DataInputStream in) throws IOException {
 263.230 -        int attr_len = in.readInt();  //attr_length
 263.231 -        int stack_map_len = in.readUnsignedShort();
 263.232 -        stackMap = new StackMapData[stack_map_len];
 263.233 -        for (int i = 0; i<stack_map_len; i++) {
 263.234 -            stackMap[i] = new StackMapData(in, this);
 263.235 -        }
 263.236 -    }
 263.237 -
 263.238 -    /**
 263.239 -     * Return access of the method.
 263.240 -     */
 263.241 -    public int getAccess(){
 263.242 -        return access;
 263.243 -    }
 263.244 -
 263.245 -    /**
 263.246 -     * Return name of the method.
 263.247 -     */
 263.248 -    public String getName(){
 263.249 -        return cls.getStringValue(name_index);
 263.250 -    }
 263.251 -
 263.252 -    /**
 263.253 -     * Return internal siganature of the method.
 263.254 -     */
 263.255 -    public String getInternalSig(){
 263.256 -        return cls.getStringValue(descriptor_index);
 263.257 -    }
 263.258 -
 263.259 -    /**
 263.260 -     * Return code attribute data of a method.
 263.261 -     */
 263.262 -    public byte[] getCode(){
 263.263 -        return code;
 263.264 -    }
 263.265 -
 263.266 -    /**
 263.267 -     * Return LineNumberTable size.
 263.268 -     */
 263.269 -    public int getnumlines(){
 263.270 -        return lin_num_tb.size();
 263.271 -    }
 263.272 -
 263.273 -    /**
 263.274 -     * Return LineNumberTable
 263.275 -     */
 263.276 -    public Vector getlin_num_tb(){
 263.277 -        return lin_num_tb;
 263.278 -    }
 263.279 -
 263.280 -    /**
 263.281 -     * Return LocalVariableTable size.
 263.282 -     */
 263.283 -    public int getloc_var_tbsize(){
 263.284 -        return loc_var_tb.size();
 263.285 -    }
 263.286 -
 263.287 -
 263.288 -    /**
 263.289 -     * Return LocalVariableTable.
 263.290 -     */
 263.291 -    public Vector getloc_var_tb(){
 263.292 -        return loc_var_tb;
 263.293 -    }
 263.294 -
 263.295 -    /**
 263.296 -     * Return StackMap.
 263.297 -     */
 263.298 -    public StackMapData[] getStackMap() {
 263.299 -        return stackMap;
 263.300 -    }
 263.301 -
 263.302 -    /**
 263.303 -     * Return StackMapTable.
 263.304 -     */
 263.305 -    public StackMapTableData[] getStackMapTable() {
 263.306 -        return stackMapTable;
 263.307 -    }
 263.308 -
 263.309 -    public StackMapIterator createStackMapIterator() {
 263.310 -        return new StackMapIterator(this);
 263.311 -    }
 263.312 -
 263.313 -    /**
 263.314 -     * Return true if method is static
 263.315 -     */
 263.316 -    public boolean isStatic(){
 263.317 -        if ((access & ACC_STATIC)   !=0) return true;
 263.318 -        return false;
 263.319 -    }
 263.320 -
 263.321 -
 263.322 -    /**
 263.323 -     * Return max depth of operand stack.
 263.324 -     */
 263.325 -    public int getMaxStack(){
 263.326 -        return  max_stack;
 263.327 -    }
 263.328 -
 263.329 -
 263.330 -    /**
 263.331 -     * Return number of local variables.
 263.332 -     */
 263.333 -    public int getMaxLocals(){
 263.334 -        return max_locals;
 263.335 -    }
 263.336 -
 263.337 -
 263.338 -    /**
 263.339 -     * Return exception index table in Exception attribute.
 263.340 -     */
 263.341 -    public int []get_exc_index_table(){
 263.342 -        return  exc_index_table;
 263.343 -    }
 263.344 -
 263.345 -
 263.346 -    /**
 263.347 -     * Return exception table in code attributre.
 263.348 -     */
 263.349 -    public TrapDataIterator getTrapDataIterator(){
 263.350 -        return new TrapDataIterator(exception_table);
 263.351 -    }
 263.352 -    
 263.353 -
 263.354 -    /**
 263.355 -     * Return method attributes.
 263.356 -     */
 263.357 -    public Vector getAttributes(){
 263.358 -        return attrs;
 263.359 -    }
 263.360 -
 263.361 -
 263.362 -    /**
 263.363 -     * Return code attributes.
 263.364 -     */
 263.365 -    public Vector getCodeAttributes(){
 263.366 -        return code_attrs;
 263.367 -    }
 263.368 -
 263.369 -
 263.370 -    /**
 263.371 -     * Return true if method id synthetic.
 263.372 -     */
 263.373 -    public boolean isSynthetic(){
 263.374 -        return isSynthetic;
 263.375 -    }
 263.376 -
 263.377 -
 263.378 -    /**
 263.379 -     * Return true if method is deprecated.
 263.380 -     */
 263.381 -    public boolean isDeprecated(){
 263.382 -        return isDeprecated;
 263.383 -    }
 263.384 -
 263.385 -    public byte[] findAnnotationData(boolean classRetention) {
 263.386 -        String n = classRetention ?
 263.387 -            "RuntimeInvisibleAnnotations" : // NOI18N
 263.388 -            "RuntimeVisibleAnnotations"; // NOI18N
 263.389 -        AttrData[] arr = new AttrData[attrs.size()];
 263.390 -        attrs.copyInto(arr);
 263.391 -        return ClassData.findAttr(n, arr);
 263.392 -    }
 263.393 -
 263.394 -    public boolean isConstructor() {
 263.395 -        return "<init>".equals(getName());
 263.396 -    }
 263.397 -}
   264.1 --- a/javap/src/main/java/org/apidesign/javap/RuntimeConstants.java	Mon Feb 25 19:00:08 2013 +0100
   264.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   264.3 @@ -1,787 +0,0 @@
   264.4 -/*
   264.5 - * Copyright (c) 2002, 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 -
  264.30 -package org.apidesign.javap;
  264.31 -
  264.32 -public interface RuntimeConstants {
  264.33 -
  264.34 -    /* Signature Characters */
  264.35 -    public static final char   SIGC_VOID                  = 'V';
  264.36 -    public static final String SIG_VOID                   = "V";
  264.37 -    public static final char   SIGC_BOOLEAN               = 'Z';
  264.38 -    public static final String SIG_BOOLEAN                = "Z";
  264.39 -    public static final char   SIGC_BYTE                  = 'B';
  264.40 -    public static final String SIG_BYTE                   = "B";
  264.41 -    public static final char   SIGC_CHAR                  = 'C';
  264.42 -    public static final String SIG_CHAR                   = "C";
  264.43 -    public static final char   SIGC_SHORT                 = 'S';
  264.44 -    public static final String SIG_SHORT                  = "S";
  264.45 -    public static final char   SIGC_INT                   = 'I';
  264.46 -    public static final String SIG_INT                    = "I";
  264.47 -    public static final char   SIGC_LONG                  = 'J';
  264.48 -    public static final String SIG_LONG                   = "J";
  264.49 -    public static final char   SIGC_FLOAT                 = 'F';
  264.50 -    public static final String SIG_FLOAT                  = "F";
  264.51 -    public static final char   SIGC_DOUBLE                = 'D';
  264.52 -    public static final String SIG_DOUBLE                 = "D";
  264.53 -    public static final char   SIGC_ARRAY                 = '[';
  264.54 -    public static final String SIG_ARRAY                  = "[";
  264.55 -    public static final char   SIGC_CLASS                 = 'L';
  264.56 -    public static final String SIG_CLASS                  = "L";
  264.57 -    public static final char   SIGC_METHOD                = '(';
  264.58 -    public static final String SIG_METHOD                 = "(";
  264.59 -    public static final char   SIGC_ENDCLASS              = ';';
  264.60 -    public static final String SIG_ENDCLASS               = ";";
  264.61 -    public static final char   SIGC_ENDMETHOD             = ')';
  264.62 -    public static final String SIG_ENDMETHOD              = ")";
  264.63 -    public static final char   SIGC_PACKAGE               = '/';
  264.64 -    public static final String SIG_PACKAGE                = "/";
  264.65 -
  264.66 -    /* Class File Constants */
  264.67 -    public static final int JAVA_MAGIC                   = 0xcafebabe;
  264.68 -    public static final int JAVA_VERSION                 = 45;
  264.69 -    public static final int JAVA_MINOR_VERSION           = 3;
  264.70 -
  264.71 -    /* Constant table */
  264.72 -    public static final int CONSTANT_UTF8                = 1;
  264.73 -    public static final int CONSTANT_UNICODE             = 2;
  264.74 -    public static final int CONSTANT_INTEGER             = 3;
  264.75 -    public static final int CONSTANT_FLOAT               = 4;
  264.76 -    public static final int CONSTANT_LONG                = 5;
  264.77 -    public static final int CONSTANT_DOUBLE              = 6;
  264.78 -    public static final int CONSTANT_CLASS               = 7;
  264.79 -    public static final int CONSTANT_STRING              = 8;
  264.80 -    public static final int CONSTANT_FIELD               = 9;
  264.81 -    public static final int CONSTANT_METHOD              = 10;
  264.82 -    public static final int CONSTANT_INTERFACEMETHOD     = 11;
  264.83 -    public static final int CONSTANT_NAMEANDTYPE         = 12;
  264.84 -
  264.85 -    /* Access Flags */
  264.86 -    public static final int ACC_PUBLIC                   = 0x00000001;
  264.87 -    public static final int ACC_PRIVATE                  = 0x00000002;
  264.88 -    public static final int ACC_PROTECTED                = 0x00000004;
  264.89 -    public static final int ACC_STATIC                   = 0x00000008;
  264.90 -    public static final int ACC_FINAL                    = 0x00000010;
  264.91 -    public static final int ACC_SYNCHRONIZED             = 0x00000020;
  264.92 -    public static final int ACC_SUPER                        = 0x00000020;
  264.93 -    public static final int ACC_VOLATILE                 = 0x00000040;
  264.94 -    public static final int ACC_TRANSIENT                = 0x00000080;
  264.95 -    public static final int ACC_NATIVE                   = 0x00000100;
  264.96 -    public static final int ACC_INTERFACE                = 0x00000200;
  264.97 -    public static final int ACC_ABSTRACT                 = 0x00000400;
  264.98 -    public static final int ACC_STRICT                   = 0x00000800;
  264.99 -    public static final int ACC_EXPLICIT                 = 0x00001000;
 264.100 -    public static final int ACC_SYNTHETIC                = 0x00010000; // actually, this is an attribute
 264.101 -
 264.102 -    /* Type codes */
 264.103 -    public static final int T_CLASS                      = 0x00000002;
 264.104 -    public static final int T_BOOLEAN                    = 0x00000004;
 264.105 -    public static final int T_CHAR                       = 0x00000005;
 264.106 -    public static final int T_FLOAT                      = 0x00000006;
 264.107 -    public static final int T_DOUBLE                     = 0x00000007;
 264.108 -    public static final int T_BYTE                       = 0x00000008;
 264.109 -    public static final int T_SHORT                      = 0x00000009;
 264.110 -    public static final int T_INT                        = 0x0000000a;
 264.111 -    public static final int T_LONG                       = 0x0000000b;
 264.112 -
 264.113 -    /* Type codes for StackMap attribute */
 264.114 -    public static final int ITEM_Bogus      =0; // an unknown or uninitialized value
 264.115 -    public static final int ITEM_Integer    =1; // a 32-bit integer
 264.116 -    public static final int ITEM_Float      =2; // not used
 264.117 -    public static final int ITEM_Double     =3; // not used
 264.118 -    public static final int ITEM_Long       =4; // a 64-bit integer
 264.119 -    public static final int ITEM_Null       =5; // the type of null
 264.120 -    public static final int ITEM_InitObject =6; // "this" in constructor
 264.121 -    public static final int ITEM_Object     =7; // followed by 2-byte index of class name
 264.122 -    public static final int ITEM_NewObject  =8; // followed by 2-byte ref to "new"
 264.123 -
 264.124 -    /* Constants used in StackMapTable attribute */
 264.125 -    public static final int SAME_FRAME_BOUND                  = 64;
 264.126 -    public static final int SAME_LOCALS_1_STACK_ITEM_BOUND    = 128;
 264.127 -    public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
 264.128 -    public static final int SAME_FRAME_EXTENDED               = 251;
 264.129 -    public static final int FULL_FRAME                        = 255;
 264.130 -
 264.131 -    /* Opcodes */
 264.132 -    public static final int opc_dead                     = -2;
 264.133 -    public static final int opc_label                    = -1;
 264.134 -    public static final int opc_nop                      = 0;
 264.135 -    public static final int opc_aconst_null              = 1;
 264.136 -    public static final int opc_iconst_m1                = 2;
 264.137 -    public static final int opc_iconst_0                 = 3;
 264.138 -    public static final int opc_iconst_1                 = 4;
 264.139 -    public static final int opc_iconst_2                 = 5;
 264.140 -    public static final int opc_iconst_3                 = 6;
 264.141 -    public static final int opc_iconst_4                 = 7;
 264.142 -    public static final int opc_iconst_5                 = 8;
 264.143 -    public static final int opc_lconst_0                 = 9;
 264.144 -    public static final int opc_lconst_1                 = 10;
 264.145 -    public static final int opc_fconst_0                 = 11;
 264.146 -    public static final int opc_fconst_1                 = 12;
 264.147 -    public static final int opc_fconst_2                 = 13;
 264.148 -    public static final int opc_dconst_0                 = 14;
 264.149 -    public static final int opc_dconst_1                 = 15;
 264.150 -    public static final int opc_bipush                   = 16;
 264.151 -    public static final int opc_sipush                   = 17;
 264.152 -    public static final int opc_ldc                      = 18;
 264.153 -    public static final int opc_ldc_w                    = 19;
 264.154 -    public static final int opc_ldc2_w                   = 20;
 264.155 -    public static final int opc_iload                    = 21;
 264.156 -    public static final int opc_lload                    = 22;
 264.157 -    public static final int opc_fload                    = 23;
 264.158 -    public static final int opc_dload                    = 24;
 264.159 -    public static final int opc_aload                    = 25;
 264.160 -    public static final int opc_iload_0                  = 26;
 264.161 -    public static final int opc_iload_1                  = 27;
 264.162 -    public static final int opc_iload_2                  = 28;
 264.163 -    public static final int opc_iload_3                  = 29;
 264.164 -    public static final int opc_lload_0                  = 30;
 264.165 -    public static final int opc_lload_1                  = 31;
 264.166 -    public static final int opc_lload_2                  = 32;
 264.167 -    public static final int opc_lload_3                  = 33;
 264.168 -    public static final int opc_fload_0                  = 34;
 264.169 -    public static final int opc_fload_1                  = 35;
 264.170 -    public static final int opc_fload_2                  = 36;
 264.171 -    public static final int opc_fload_3                  = 37;
 264.172 -    public static final int opc_dload_0                  = 38;
 264.173 -    public static final int opc_dload_1                  = 39;
 264.174 -    public static final int opc_dload_2                  = 40;
 264.175 -    public static final int opc_dload_3                  = 41;
 264.176 -    public static final int opc_aload_0                  = 42;
 264.177 -    public static final int opc_aload_1                  = 43;
 264.178 -    public static final int opc_aload_2                  = 44;
 264.179 -    public static final int opc_aload_3                  = 45;
 264.180 -    public static final int opc_iaload                   = 46;
 264.181 -    public static final int opc_laload                   = 47;
 264.182 -    public static final int opc_faload                   = 48;
 264.183 -    public static final int opc_daload                   = 49;
 264.184 -    public static final int opc_aaload                   = 50;
 264.185 -    public static final int opc_baload                   = 51;
 264.186 -    public static final int opc_caload                   = 52;
 264.187 -    public static final int opc_saload                   = 53;
 264.188 -    public static final int opc_istore                   = 54;
 264.189 -    public static final int opc_lstore                   = 55;
 264.190 -    public static final int opc_fstore                   = 56;
 264.191 -    public static final int opc_dstore                   = 57;
 264.192 -    public static final int opc_astore                   = 58;
 264.193 -    public static final int opc_istore_0                 = 59;
 264.194 -    public static final int opc_istore_1                 = 60;
 264.195 -    public static final int opc_istore_2                 = 61;
 264.196 -    public static final int opc_istore_3                 = 62;
 264.197 -    public static final int opc_lstore_0                 = 63;
 264.198 -    public static final int opc_lstore_1                 = 64;
 264.199 -    public static final int opc_lstore_2                 = 65;
 264.200 -    public static final int opc_lstore_3                 = 66;
 264.201 -    public static final int opc_fstore_0                 = 67;
 264.202 -    public static final int opc_fstore_1                 = 68;
 264.203 -    public static final int opc_fstore_2                 = 69;
 264.204 -    public static final int opc_fstore_3                 = 70;
 264.205 -    public static final int opc_dstore_0                 = 71;
 264.206 -    public static final int opc_dstore_1                 = 72;
 264.207 -    public static final int opc_dstore_2                 = 73;
 264.208 -    public static final int opc_dstore_3                 = 74;
 264.209 -    public static final int opc_astore_0                 = 75;
 264.210 -    public static final int opc_astore_1                 = 76;
 264.211 -    public static final int opc_astore_2                 = 77;
 264.212 -    public static final int opc_astore_3                 = 78;
 264.213 -    public static final int opc_iastore                  = 79;
 264.214 -    public static final int opc_lastore                  = 80;
 264.215 -    public static final int opc_fastore                  = 81;
 264.216 -    public static final int opc_dastore                  = 82;
 264.217 -    public static final int opc_aastore                  = 83;
 264.218 -    public static final int opc_bastore                  = 84;
 264.219 -    public static final int opc_castore                  = 85;
 264.220 -    public static final int opc_sastore                  = 86;
 264.221 -    public static final int opc_pop                      = 87;
 264.222 -    public static final int opc_pop2                     = 88;
 264.223 -    public static final int opc_dup                      = 89;
 264.224 -    public static final int opc_dup_x1                   = 90;
 264.225 -    public static final int opc_dup_x2                   = 91;
 264.226 -    public static final int opc_dup2                     = 92;
 264.227 -    public static final int opc_dup2_x1                  = 93;
 264.228 -    public static final int opc_dup2_x2                  = 94;
 264.229 -    public static final int opc_swap                     = 95;
 264.230 -    public static final int opc_iadd                     = 96;
 264.231 -    public static final int opc_ladd                     = 97;
 264.232 -    public static final int opc_fadd                     = 98;
 264.233 -    public static final int opc_dadd                     = 99;
 264.234 -    public static final int opc_isub                     = 100;
 264.235 -    public static final int opc_lsub                     = 101;
 264.236 -    public static final int opc_fsub                     = 102;
 264.237 -    public static final int opc_dsub                     = 103;
 264.238 -    public static final int opc_imul                     = 104;
 264.239 -    public static final int opc_lmul                     = 105;
 264.240 -    public static final int opc_fmul                     = 106;
 264.241 -    public static final int opc_dmul                     = 107;
 264.242 -    public static final int opc_idiv                     = 108;
 264.243 -    public static final int opc_ldiv                     = 109;
 264.244 -    public static final int opc_fdiv                     = 110;
 264.245 -    public static final int opc_ddiv                     = 111;
 264.246 -    public static final int opc_irem                     = 112;
 264.247 -    public static final int opc_lrem                     = 113;
 264.248 -    public static final int opc_frem                     = 114;
 264.249 -    public static final int opc_drem                     = 115;
 264.250 -    public static final int opc_ineg                     = 116;
 264.251 -    public static final int opc_lneg                     = 117;
 264.252 -    public static final int opc_fneg                     = 118;
 264.253 -    public static final int opc_dneg                     = 119;
 264.254 -    public static final int opc_ishl                     = 120;
 264.255 -    public static final int opc_lshl                     = 121;
 264.256 -    public static final int opc_ishr                     = 122;
 264.257 -    public static final int opc_lshr                     = 123;
 264.258 -    public static final int opc_iushr                    = 124;
 264.259 -    public static final int opc_lushr                    = 125;
 264.260 -    public static final int opc_iand                     = 126;
 264.261 -    public static final int opc_land                     = 127;
 264.262 -    public static final int opc_ior                      = 128;
 264.263 -    public static final int opc_lor                      = 129;
 264.264 -    public static final int opc_ixor                     = 130;
 264.265 -    public static final int opc_lxor                     = 131;
 264.266 -    public static final int opc_iinc                     = 132;
 264.267 -    public static final int opc_i2l                      = 133;
 264.268 -    public static final int opc_i2f                      = 134;
 264.269 -    public static final int opc_i2d                      = 135;
 264.270 -    public static final int opc_l2i                      = 136;
 264.271 -    public static final int opc_l2f                      = 137;
 264.272 -    public static final int opc_l2d                      = 138;
 264.273 -    public static final int opc_f2i                      = 139;
 264.274 -    public static final int opc_f2l                      = 140;
 264.275 -    public static final int opc_f2d                      = 141;
 264.276 -    public static final int opc_d2i                      = 142;
 264.277 -    public static final int opc_d2l                      = 143;
 264.278 -    public static final int opc_d2f                      = 144;
 264.279 -    public static final int opc_i2b                      = 145;
 264.280 -    public static final int opc_int2byte                 = 145;
 264.281 -    public static final int opc_i2c                      = 146;
 264.282 -    public static final int opc_int2char                 = 146;
 264.283 -    public static final int opc_i2s                      = 147;
 264.284 -    public static final int opc_int2short                = 147;
 264.285 -    public static final int opc_lcmp                     = 148;
 264.286 -    public static final int opc_fcmpl                    = 149;
 264.287 -    public static final int opc_fcmpg                    = 150;
 264.288 -    public static final int opc_dcmpl                    = 151;
 264.289 -    public static final int opc_dcmpg                    = 152;
 264.290 -    public static final int opc_ifeq                     = 153;
 264.291 -    public static final int opc_ifne                     = 154;
 264.292 -    public static final int opc_iflt                     = 155;
 264.293 -    public static final int opc_ifge                     = 156;
 264.294 -    public static final int opc_ifgt                     = 157;
 264.295 -    public static final int opc_ifle                     = 158;
 264.296 -    public static final int opc_if_icmpeq                = 159;
 264.297 -    public static final int opc_if_icmpne                = 160;
 264.298 -    public static final int opc_if_icmplt                = 161;
 264.299 -    public static final int opc_if_icmpge                = 162;
 264.300 -    public static final int opc_if_icmpgt                = 163;
 264.301 -    public static final int opc_if_icmple                = 164;
 264.302 -    public static final int opc_if_acmpeq                = 165;
 264.303 -    public static final int opc_if_acmpne                = 166;
 264.304 -    public static final int opc_goto                     = 167;
 264.305 -    public static final int opc_jsr                      = 168;
 264.306 -    public static final int opc_ret                      = 169;
 264.307 -    public static final int opc_tableswitch              = 170;
 264.308 -    public static final int opc_lookupswitch             = 171;
 264.309 -    public static final int opc_ireturn                  = 172;
 264.310 -    public static final int opc_lreturn                  = 173;
 264.311 -    public static final int opc_freturn                  = 174;
 264.312 -    public static final int opc_dreturn                  = 175;
 264.313 -    public static final int opc_areturn                  = 176;
 264.314 -    public static final int opc_return                   = 177;
 264.315 -    public static final int opc_getstatic                = 178;
 264.316 -    public static final int opc_putstatic                = 179;
 264.317 -    public static final int opc_getfield                 = 180;
 264.318 -    public static final int opc_putfield                 = 181;
 264.319 -    public static final int opc_invokevirtual            = 182;
 264.320 -    public static final int opc_invokenonvirtual         = 183;
 264.321 -    public static final int opc_invokespecial            = 183;
 264.322 -    public static final int opc_invokestatic             = 184;
 264.323 -    public static final int opc_invokeinterface          = 185;
 264.324 -//    public static final int opc_xxxunusedxxx             = 186;
 264.325 -    public static final int opc_new                      = 187;
 264.326 -    public static final int opc_newarray                 = 188;
 264.327 -    public static final int opc_anewarray                = 189;
 264.328 -    public static final int opc_arraylength              = 190;
 264.329 -    public static final int opc_athrow                   = 191;
 264.330 -    public static final int opc_checkcast                = 192;
 264.331 -    public static final int opc_instanceof               = 193;
 264.332 -    public static final int opc_monitorenter             = 194;
 264.333 -    public static final int opc_monitorexit              = 195;
 264.334 -    public static final int opc_wide                     = 196;
 264.335 -    public static final int opc_multianewarray           = 197;
 264.336 -    public static final int opc_ifnull                   = 198;
 264.337 -    public static final int opc_ifnonnull                = 199;
 264.338 -    public static final int opc_goto_w                   = 200;
 264.339 -    public static final int opc_jsr_w                    = 201;
 264.340 -        /* Pseudo-instructions */
 264.341 -    public static final int opc_bytecode                 = 203;
 264.342 -    public static final int opc_try                      = 204;
 264.343 -    public static final int opc_endtry                   = 205;
 264.344 -    public static final int opc_catch                    = 206;
 264.345 -    public static final int opc_var                      = 207;
 264.346 -    public static final int opc_endvar                   = 208;
 264.347 -    public static final int opc_localsmap                = 209;
 264.348 -    public static final int opc_stackmap                 = 210;
 264.349 -        /* PicoJava prefixes */
 264.350 -    public static final int opc_nonpriv                  = 254;
 264.351 -    public static final int opc_priv                     = 255;
 264.352 -
 264.353 -        /* Wide instructions */
 264.354 -    public static final int opc_iload_w         = (opc_wide<<8)|opc_iload;
 264.355 -    public static final int opc_lload_w         = (opc_wide<<8)|opc_lload;
 264.356 -    public static final int opc_fload_w         = (opc_wide<<8)|opc_fload;
 264.357 -    public static final int opc_dload_w         = (opc_wide<<8)|opc_dload;
 264.358 -    public static final int opc_aload_w         = (opc_wide<<8)|opc_aload;
 264.359 -    public static final int opc_istore_w        = (opc_wide<<8)|opc_istore;
 264.360 -    public static final int opc_lstore_w        = (opc_wide<<8)|opc_lstore;
 264.361 -    public static final int opc_fstore_w        = (opc_wide<<8)|opc_fstore;
 264.362 -    public static final int opc_dstore_w        = (opc_wide<<8)|opc_dstore;
 264.363 -    public static final int opc_astore_w        = (opc_wide<<8)|opc_astore;
 264.364 -    public static final int opc_ret_w           = (opc_wide<<8)|opc_ret;
 264.365 -    public static final int opc_iinc_w          = (opc_wide<<8)|opc_iinc;
 264.366 -
 264.367 -    /* Opcode Names */
 264.368 -  public static final String opcNamesTab[] = {
 264.369 -        "nop",
 264.370 -        "aconst_null",
 264.371 -        "iconst_m1",
 264.372 -        "iconst_0",
 264.373 -        "iconst_1",
 264.374 -        "iconst_2",
 264.375 -        "iconst_3",
 264.376 -        "iconst_4",
 264.377 -        "iconst_5",
 264.378 -        "lconst_0",
 264.379 -        "lconst_1",
 264.380 -        "fconst_0",
 264.381 -        "fconst_1",
 264.382 -        "fconst_2",
 264.383 -        "dconst_0",
 264.384 -        "dconst_1",
 264.385 -        "bipush",
 264.386 -        "sipush",
 264.387 -        "ldc",
 264.388 -        "ldc_w",
 264.389 -        "ldc2_w",
 264.390 -        "iload",
 264.391 -        "lload",
 264.392 -        "fload",
 264.393 -        "dload",
 264.394 -        "aload",
 264.395 -        "iload_0",
 264.396 -        "iload_1",
 264.397 -        "iload_2",
 264.398 -        "iload_3",
 264.399 -        "lload_0",
 264.400 -        "lload_1",
 264.401 -        "lload_2",
 264.402 -        "lload_3",
 264.403 -        "fload_0",
 264.404 -        "fload_1",
 264.405 -        "fload_2",
 264.406 -        "fload_3",
 264.407 -        "dload_0",
 264.408 -        "dload_1",
 264.409 -        "dload_2",
 264.410 -        "dload_3",
 264.411 -        "aload_0",
 264.412 -        "aload_1",
 264.413 -        "aload_2",
 264.414 -        "aload_3",
 264.415 -        "iaload",
 264.416 -        "laload",
 264.417 -        "faload",
 264.418 -        "daload",
 264.419 -        "aaload",
 264.420 -        "baload",
 264.421 -        "caload",
 264.422 -        "saload",
 264.423 -        "istore",
 264.424 -        "lstore",
 264.425 -        "fstore",
 264.426 -        "dstore",
 264.427 -        "astore",
 264.428 -        "istore_0",
 264.429 -        "istore_1",
 264.430 -        "istore_2",
 264.431 -        "istore_3",
 264.432 -        "lstore_0",
 264.433 -        "lstore_1",
 264.434 -        "lstore_2",
 264.435 -        "lstore_3",
 264.436 -        "fstore_0",
 264.437 -        "fstore_1",
 264.438 -        "fstore_2",
 264.439 -        "fstore_3",
 264.440 -        "dstore_0",
 264.441 -        "dstore_1",
 264.442 -        "dstore_2",
 264.443 -        "dstore_3",
 264.444 -        "astore_0",
 264.445 -        "astore_1",
 264.446 -        "astore_2",
 264.447 -        "astore_3",
 264.448 -        "iastore",
 264.449 -        "lastore",
 264.450 -        "fastore",
 264.451 -        "dastore",
 264.452 -        "aastore",
 264.453 -        "bastore",
 264.454 -        "castore",
 264.455 -        "sastore",
 264.456 -        "pop",
 264.457 -        "pop2",
 264.458 -        "dup",
 264.459 -        "dup_x1",
 264.460 -        "dup_x2",
 264.461 -        "dup2",
 264.462 -        "dup2_x1",
 264.463 -        "dup2_x2",
 264.464 -        "swap",
 264.465 -        "iadd",
 264.466 -        "ladd",
 264.467 -        "fadd",
 264.468 -        "dadd",
 264.469 -        "isub",
 264.470 -        "lsub",
 264.471 -        "fsub",
 264.472 -        "dsub",
 264.473 -        "imul",
 264.474 -        "lmul",
 264.475 -        "fmul",
 264.476 -        "dmul",
 264.477 -        "idiv",
 264.478 -        "ldiv",
 264.479 -        "fdiv",
 264.480 -        "ddiv",
 264.481 -        "irem",
 264.482 -        "lrem",
 264.483 -        "frem",
 264.484 -        "drem",
 264.485 -        "ineg",
 264.486 -        "lneg",
 264.487 -        "fneg",
 264.488 -        "dneg",
 264.489 -        "ishl",
 264.490 -        "lshl",
 264.491 -        "ishr",
 264.492 -        "lshr",
 264.493 -        "iushr",
 264.494 -        "lushr",
 264.495 -        "iand",
 264.496 -        "land",
 264.497 -        "ior",
 264.498 -        "lor",
 264.499 -        "ixor",
 264.500 -        "lxor",
 264.501 -        "iinc",
 264.502 -        "i2l",
 264.503 -        "i2f",
 264.504 -        "i2d",
 264.505 -        "l2i",
 264.506 -        "l2f",
 264.507 -        "l2d",
 264.508 -        "f2i",
 264.509 -        "f2l",
 264.510 -        "f2d",
 264.511 -        "d2i",
 264.512 -        "d2l",
 264.513 -        "d2f",
 264.514 -        "i2b",
 264.515 -        "i2c",
 264.516 -        "i2s",
 264.517 -        "lcmp",
 264.518 -        "fcmpl",
 264.519 -        "fcmpg",
 264.520 -        "dcmpl",
 264.521 -        "dcmpg",
 264.522 -        "ifeq",
 264.523 -        "ifne",
 264.524 -        "iflt",
 264.525 -        "ifge",
 264.526 -        "ifgt",
 264.527 -        "ifle",
 264.528 -        "if_icmpeq",
 264.529 -        "if_icmpne",
 264.530 -        "if_icmplt",
 264.531 -        "if_icmpge",
 264.532 -        "if_icmpgt",
 264.533 -        "if_icmple",
 264.534 -        "if_acmpeq",
 264.535 -        "if_acmpne",
 264.536 -        "goto",
 264.537 -        "jsr",
 264.538 -        "ret",
 264.539 -        "tableswitch",
 264.540 -        "lookupswitch",
 264.541 -        "ireturn",
 264.542 -        "lreturn",
 264.543 -        "freturn",
 264.544 -        "dreturn",
 264.545 -        "areturn",
 264.546 -        "return",
 264.547 -        "getstatic",
 264.548 -        "putstatic",
 264.549 -        "getfield",
 264.550 -        "putfield",
 264.551 -        "invokevirtual",
 264.552 -        "invokespecial", //     was "invokenonvirtual",
 264.553 -        "invokestatic",
 264.554 -        "invokeinterface",
 264.555 -        "bytecode 186", //"xxxunusedxxx",
 264.556 -        "new",
 264.557 -        "newarray",
 264.558 -        "anewarray",
 264.559 -        "arraylength",
 264.560 -        "athrow",
 264.561 -        "checkcast",
 264.562 -        "instanceof",
 264.563 -        "monitorenter",
 264.564 -        "monitorexit",
 264.565 -         null, // "wide",
 264.566 -        "multianewarray",
 264.567 -        "ifnull",
 264.568 -        "ifnonnull",
 264.569 -        "goto_w",
 264.570 -        "jsr_w",
 264.571 -        "bytecode 202", // "breakpoint",
 264.572 -        "bytecode",
 264.573 -        "try",
 264.574 -        "endtry",
 264.575 -        "catch",
 264.576 -        "var",
 264.577 -        "endvar",
 264.578 -        "locals_map",
 264.579 -        "stack_map"
 264.580 -  };
 264.581 -
 264.582 -    /* Opcode Lengths */
 264.583 -  public static final int opcLengthsTab[] = {
 264.584 -        1,
 264.585 -        1,
 264.586 -        1,
 264.587 -        1,
 264.588 -        1,
 264.589 -        1,
 264.590 -        1,
 264.591 -        1,
 264.592 -        1,
 264.593 -        1,
 264.594 -        1,
 264.595 -        1,
 264.596 -        1,
 264.597 -        1,
 264.598 -        1,
 264.599 -        1,
 264.600 -        2,
 264.601 -        3,
 264.602 -        2,
 264.603 -        3,
 264.604 -        3,
 264.605 -        2,
 264.606 -        2,
 264.607 -        2,
 264.608 -        2,
 264.609 -        2,
 264.610 -        1,
 264.611 -        1,
 264.612 -        1,
 264.613 -        1,
 264.614 -        1,
 264.615 -        1,
 264.616 -        1,
 264.617 -        1,
 264.618 -        1,
 264.619 -        1,
 264.620 -        1,
 264.621 -        1,
 264.622 -        1,
 264.623 -        1,
 264.624 -        1,
 264.625 -        1,
 264.626 -        1,
 264.627 -        1,
 264.628 -        1,
 264.629 -        1,
 264.630 -        1,
 264.631 -        1,
 264.632 -        1,
 264.633 -        1,
 264.634 -        1,
 264.635 -        1,
 264.636 -        1,
 264.637 -        1,
 264.638 -        2,
 264.639 -        2,
 264.640 -        2,
 264.641 -        2,
 264.642 -        2,
 264.643 -        1,
 264.644 -        1,
 264.645 -        1,
 264.646 -        1,
 264.647 -        1,
 264.648 -        1,
 264.649 -        1,
 264.650 -        1,
 264.651 -        1,
 264.652 -        1,
 264.653 -        1,
 264.654 -        1,
 264.655 -        1,
 264.656 -        1,
 264.657 -        1,
 264.658 -        1,
 264.659 -        1,
 264.660 -        1,
 264.661 -        1,
 264.662 -        1,
 264.663 -        1,
 264.664 -        1,
 264.665 -        1,
 264.666 -        1,
 264.667 -        1,
 264.668 -        1,
 264.669 -        1,
 264.670 -        1,
 264.671 -        1,
 264.672 -        1,
 264.673 -        1,
 264.674 -        1,
 264.675 -        1,
 264.676 -        1,
 264.677 -        1,
 264.678 -        1,
 264.679 -        1,
 264.680 -        1,
 264.681 -        1,
 264.682 -        1,
 264.683 -        1,
 264.684 -        1,
 264.685 -        1,
 264.686 -        1,
 264.687 -        1,
 264.688 -        1,
 264.689 -        1,
 264.690 -        1,
 264.691 -        1,
 264.692 -        1,
 264.693 -        1,
 264.694 -        1,
 264.695 -        1,
 264.696 -        1,
 264.697 -        1,
 264.698 -        1,
 264.699 -        1,
 264.700 -        1,
 264.701 -        1,
 264.702 -        1,
 264.703 -        1,
 264.704 -        1,
 264.705 -        1,
 264.706 -        1,
 264.707 -        1,
 264.708 -        1,
 264.709 -        1,
 264.710 -        1,
 264.711 -        1,
 264.712 -        1,
 264.713 -        1,
 264.714 -        1,
 264.715 -        1,
 264.716 -        3,
 264.717 -        1,
 264.718 -        1,
 264.719 -        1,
 264.720 -        1,
 264.721 -        1,
 264.722 -        1,
 264.723 -        1,
 264.724 -        1,
 264.725 -        1,
 264.726 -        1,
 264.727 -        1,
 264.728 -        1,
 264.729 -        1,
 264.730 -        1,
 264.731 -        1,
 264.732 -        1,
 264.733 -        1,
 264.734 -        1,
 264.735 -        1,
 264.736 -        1,
 264.737 -        3,
 264.738 -        3,
 264.739 -        3,
 264.740 -        3,
 264.741 -        3,
 264.742 -        3,
 264.743 -        3,
 264.744 -        3,
 264.745 -        3,
 264.746 -        3,
 264.747 -        3,
 264.748 -        3,
 264.749 -        3,
 264.750 -        3,
 264.751 -        3,
 264.752 -        3,
 264.753 -        2,
 264.754 -        99,
 264.755 -        99,
 264.756 -        1,
 264.757 -        1,
 264.758 -        1,
 264.759 -        1,
 264.760 -        1,
 264.761 -        1,
 264.762 -        3,
 264.763 -        3,
 264.764 -        3,
 264.765 -        3,
 264.766 -        3,
 264.767 -        3,
 264.768 -        3,
 264.769 -        5,
 264.770 -        0,
 264.771 -        3,
 264.772 -        2,
 264.773 -        3,
 264.774 -        1,
 264.775 -        1,
 264.776 -        3,
 264.777 -        3,
 264.778 -        1,
 264.779 -        1,
 264.780 -        0, // wide
 264.781 -        4,
 264.782 -        3,
 264.783 -        3,
 264.784 -        5,
 264.785 -        5,
 264.786 -        1,
 264.787 -        1, 0, 0, 0, 0, 0 // pseudo
 264.788 -  };
 264.789 -
 264.790 -}
   265.1 --- a/javap/src/main/java/org/apidesign/javap/StackMapData.java	Mon Feb 25 19:00:08 2013 +0100
   265.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   265.3 @@ -1,71 +0,0 @@
   265.4 -/*
   265.5 - * Copyright (c) 2005, 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 -package org.apidesign.javap;
  265.31 -
  265.32 -import java.util.*;
  265.33 -import java.io.*;
  265.34 -
  265.35 -import static org.apidesign.javap.RuntimeConstants.*;
  265.36 -
  265.37 -/* represents one entry of StackMap attribute
  265.38 - */
  265.39 -class StackMapData {
  265.40 -    final int offset;
  265.41 -    final int[] locals;
  265.42 -    final int[] stack;
  265.43 -
  265.44 -    StackMapData(int offset, int[] locals, int[] stack) {
  265.45 -        this.offset = offset;
  265.46 -        this.locals = locals;
  265.47 -        this.stack = stack;
  265.48 -    }
  265.49 -
  265.50 -    StackMapData(DataInputStream in, MethodData method) throws IOException {
  265.51 -        offset = in.readUnsignedShort();
  265.52 -        int local_size = in.readUnsignedShort();
  265.53 -        locals = readTypeArray(in, local_size, method);
  265.54 -        int stack_size = in.readUnsignedShort();
  265.55 -        stack = readTypeArray(in, stack_size, method);
  265.56 -    }
  265.57 -
  265.58 -    static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
  265.59 -        int[] types = new int[length];
  265.60 -        for (int i=0; i<length; i++) {
  265.61 -            types[i] = readType(in, method);
  265.62 -        }
  265.63 -        return types;
  265.64 -    }
  265.65 -
  265.66 -    static final int readType(DataInputStream in, MethodData method) throws IOException {
  265.67 -        int type = in.readUnsignedByte();
  265.68 -        if (type == ITEM_Object || type == ITEM_NewObject) {
  265.69 -            type = type | (in.readUnsignedShort()<<8);
  265.70 -        }
  265.71 -        return type;
  265.72 -    }
  265.73 -
  265.74 -}
   266.1 --- a/javap/src/main/java/org/apidesign/javap/StackMapIterator.java	Mon Feb 25 19:00:08 2013 +0100
   266.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   266.3 @@ -1,179 +0,0 @@
   266.4 -/*
   266.5 - * Copyright (c) 2012, 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 org.apidesign.javap;
  266.30 -
  266.31 -import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
  266.32 -import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
  266.33 -import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
  266.34 -import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
  266.35 -import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
  266.36 -
  266.37 -public final class StackMapIterator {
  266.38 -    private final StackMapTableData[] stackMapTable;
  266.39 -    private final TypeArray argTypes;
  266.40 -    private final TypeArray localTypes;
  266.41 -    private final TypeArray stackTypes;
  266.42 -
  266.43 -    private int nextFrameIndex;
  266.44 -    private int lastFrameByteCodeOffset;
  266.45 -
  266.46 -    private int byteCodeOffset;
  266.47 -
  266.48 -    StackMapIterator(final MethodData methodData) {
  266.49 -        this(methodData.getStackMapTable(),
  266.50 -             methodData.getInternalSig(),
  266.51 -             methodData.isStatic());
  266.52 -    }
  266.53 -
  266.54 -    StackMapIterator(final StackMapTableData[] stackMapTable,
  266.55 -                     final String methodSignature,
  266.56 -                     final boolean isStaticMethod) {
  266.57 -        this.stackMapTable = (stackMapTable != null)
  266.58 -                                 ? stackMapTable
  266.59 -                                 : new StackMapTableData[0];
  266.60 -
  266.61 -        argTypes = getArgTypes(methodSignature, isStaticMethod);
  266.62 -        localTypes = new TypeArray();
  266.63 -        stackTypes = new TypeArray();
  266.64 -
  266.65 -        localTypes.addAll(argTypes);
  266.66 -
  266.67 -        lastFrameByteCodeOffset = -1;
  266.68 -        advanceBy(0);
  266.69 -    }
  266.70 -
  266.71 -    public String getFrameAsString() {
  266.72 -        return (nextFrameIndex == 0)
  266.73 -                   ? StackMapTableData.toString("INITIAL", 0, null, null)
  266.74 -                   : stackMapTable[nextFrameIndex - 1].toString();
  266.75 -    }
  266.76 -
  266.77 -    public int getFrameIndex() {
  266.78 -        return nextFrameIndex;
  266.79 -    }
  266.80 -
  266.81 -    public TypeArray getFrameStack() {
  266.82 -        return stackTypes;
  266.83 -    }
  266.84 -
  266.85 -    public TypeArray getFrameLocals() {
  266.86 -        return localTypes;
  266.87 -    }
  266.88 -
  266.89 -    public TypeArray getArguments() {
  266.90 -        return argTypes;
  266.91 -    }
  266.92 -
  266.93 -    public void advanceBy(final int numByteCodes) {
  266.94 -        if (numByteCodes < 0) {
  266.95 -            throw new IllegalStateException("Forward only iterator");
  266.96 -        }
  266.97 -
  266.98 -        byteCodeOffset += numByteCodes;
  266.99 -        while ((nextFrameIndex < stackMapTable.length)
 266.100 -                    && ((byteCodeOffset - lastFrameByteCodeOffset)
 266.101 -                            >= (stackMapTable[nextFrameIndex].offsetDelta
 266.102 -                                    + 1))) {
 266.103 -            final StackMapTableData nextFrame = stackMapTable[nextFrameIndex];
 266.104 -
 266.105 -            lastFrameByteCodeOffset += nextFrame.offsetDelta + 1;
 266.106 -            nextFrame.applyTo(localTypes, stackTypes);
 266.107 -
 266.108 -            ++nextFrameIndex;
 266.109 -        }
 266.110 -    }
 266.111 -
 266.112 -    public void advanceTo(final int nextByteCodeOffset) {
 266.113 -        advanceBy(nextByteCodeOffset - byteCodeOffset);
 266.114 -    }
 266.115 -
 266.116 -    private static TypeArray getArgTypes(final String methodSignature,
 266.117 -                                         final boolean isStaticMethod) {
 266.118 -        final TypeArray argTypes = new TypeArray();
 266.119 -
 266.120 -        if (!isStaticMethod) {
 266.121 -            argTypes.add(ITEM_Object);
 266.122 -        }
 266.123 -
 266.124 -        if (methodSignature.charAt(0) != '(') {
 266.125 -            throw new IllegalArgumentException("Invalid method signature");
 266.126 -        }
 266.127 -
 266.128 -        final int length = methodSignature.length();
 266.129 -        boolean skipType = false;
 266.130 -        int argType;
 266.131 -        for (int i = 1; i < length; ++i) {
 266.132 -            switch (methodSignature.charAt(i)) {
 266.133 -                case 'B':
 266.134 -                case 'C':
 266.135 -                case 'S':
 266.136 -                case 'Z':
 266.137 -                case 'I':
 266.138 -                    argType = ITEM_Integer;
 266.139 -                    break;
 266.140 -                case 'J':
 266.141 -                    argType = ITEM_Long;
 266.142 -                    break;
 266.143 -                case 'F':
 266.144 -                    argType = ITEM_Float;
 266.145 -                    break;
 266.146 -                case 'D':
 266.147 -                    argType = ITEM_Double;
 266.148 -                    break;
 266.149 -                case 'L': {
 266.150 -                    i = methodSignature.indexOf(';', i + 1);
 266.151 -                    if (i == -1) {
 266.152 -                        throw new IllegalArgumentException(
 266.153 -                                      "Invalid method signature");
 266.154 -                    }
 266.155 -                    argType = ITEM_Object;
 266.156 -                    break;
 266.157 -                }
 266.158 -                case ')':
 266.159 -                    // not interested in the return value type
 266.160 -                    return argTypes;
 266.161 -                case '[':
 266.162 -                    if (!skipType) {
 266.163 -                        argTypes.add(ITEM_Object);
 266.164 -                        skipType = true;
 266.165 -                    }
 266.166 -                    continue;
 266.167 -
 266.168 -                default:
 266.169 -                    throw new IllegalArgumentException(
 266.170 -                                  "Invalid method signature");
 266.171 -            }
 266.172 -
 266.173 -            if (!skipType) {
 266.174 -                argTypes.add(argType);
 266.175 -            } else {
 266.176 -                skipType = false;
 266.177 -            }
 266.178 -        }
 266.179 -
 266.180 -        return argTypes;
 266.181 -    }
 266.182 -}
   267.1 --- a/javap/src/main/java/org/apidesign/javap/StackMapTableData.java	Mon Feb 25 19:00:08 2013 +0100
   267.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   267.3 @@ -1,223 +0,0 @@
   267.4 -/*
   267.5 - * Copyright (c) 2005, 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 -
  267.30 -package org.apidesign.javap;
  267.31 -
  267.32 -import java.io.*;
  267.33 -
  267.34 -import static org.apidesign.javap.RuntimeConstants.*;
  267.35 -
  267.36 -/* represents one entry of StackMapTable attribute
  267.37 - */
  267.38 -abstract class StackMapTableData {
  267.39 -    final int frameType;
  267.40 -    int offsetDelta;
  267.41 -
  267.42 -    StackMapTableData(int frameType) {
  267.43 -        this.frameType = frameType;
  267.44 -    }
  267.45 -
  267.46 -    abstract void applyTo(TypeArray localTypes, TypeArray stackTypes);
  267.47 -
  267.48 -    protected static String toString(
  267.49 -            final String frameType,
  267.50 -            final int offset,
  267.51 -            final int[] localTypes,
  267.52 -            final int[] stackTypes) {
  267.53 -        final StringBuilder sb = new StringBuilder(frameType);
  267.54 -
  267.55 -        sb.append("(off: +").append(offset);
  267.56 -        if (localTypes != null) {
  267.57 -            sb.append(", locals: ");
  267.58 -            appendTypes(sb, localTypes);
  267.59 -        }
  267.60 -        if (stackTypes != null) {
  267.61 -            sb.append(", stack: ");
  267.62 -            appendTypes(sb, stackTypes);
  267.63 -        }
  267.64 -        sb.append(')');
  267.65 -
  267.66 -        return sb.toString();
  267.67 -    }
  267.68 -
  267.69 -    private static void appendTypes(final StringBuilder sb, final int[] types) {
  267.70 -        sb.append('[');
  267.71 -        if (types.length > 0) {
  267.72 -            sb.append(TypeArray.typeString(types[0]));
  267.73 -            for (int i = 1; i < types.length; ++i) {
  267.74 -                sb.append(", ");
  267.75 -                sb.append(TypeArray.typeString(types[i]));
  267.76 -            }
  267.77 -        }
  267.78 -        sb.append(']');
  267.79 -    }
  267.80 -
  267.81 -    static class SameFrame extends StackMapTableData {
  267.82 -        SameFrame(int frameType, int offsetDelta) {
  267.83 -            super(frameType);
  267.84 -            this.offsetDelta = offsetDelta;
  267.85 -        }
  267.86 -
  267.87 -        @Override
  267.88 -        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
  267.89 -            stackTypes.clear();
  267.90 -        }
  267.91 -
  267.92 -        @Override
  267.93 -        public String toString() {
  267.94 -            return toString("SAME" + ((frameType == SAME_FRAME_EXTENDED)
  267.95 -                                          ? "_FRAME_EXTENDED" : ""),
  267.96 -                            offsetDelta,
  267.97 -                            null, null);
  267.98 -        }
  267.99 -    }
 267.100 -
 267.101 -    static class SameLocals1StackItem extends StackMapTableData {
 267.102 -        final int[] stack;
 267.103 -        SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
 267.104 -            super(frameType);
 267.105 -            this.offsetDelta = offsetDelta;
 267.106 -            this.stack = stack;
 267.107 -        }
 267.108 -
 267.109 -        @Override
 267.110 -        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 267.111 -            stackTypes.setAll(stack);
 267.112 -        }
 267.113 -
 267.114 -        @Override
 267.115 -        public String toString() {
 267.116 -            return toString(
 267.117 -                       "SAME_LOCALS_1_STACK_ITEM"
 267.118 -                           + ((frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED)
 267.119 -                                  ? "_EXTENDED" : ""),
 267.120 -                       offsetDelta,
 267.121 -                       null, stack);
 267.122 -        }
 267.123 -    }
 267.124 -
 267.125 -    static class ChopFrame extends StackMapTableData {
 267.126 -        ChopFrame(int frameType, int offsetDelta) {
 267.127 -            super(frameType);
 267.128 -            this.offsetDelta = offsetDelta;
 267.129 -        }
 267.130 -
 267.131 -        @Override
 267.132 -        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 267.133 -            localTypes.setSize(localTypes.getSize()
 267.134 -                                   - (SAME_FRAME_EXTENDED - frameType));
 267.135 -            stackTypes.clear();
 267.136 -        }
 267.137 -
 267.138 -        @Override
 267.139 -        public String toString() {
 267.140 -            return toString("CHOP", offsetDelta, null, null);
 267.141 -        }
 267.142 -    }
 267.143 -
 267.144 -    static class AppendFrame extends StackMapTableData {
 267.145 -        final int[] locals;
 267.146 -        AppendFrame(int frameType, int offsetDelta, int[] locals) {
 267.147 -            super(frameType);
 267.148 -            this.offsetDelta = offsetDelta;
 267.149 -            this.locals = locals;
 267.150 -        }
 267.151 -
 267.152 -        @Override
 267.153 -        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 267.154 -            localTypes.addAll(locals);
 267.155 -            stackTypes.clear();
 267.156 -        }
 267.157 -
 267.158 -        @Override
 267.159 -        public String toString() {
 267.160 -            return toString("APPEND", offsetDelta, locals, null);
 267.161 -        }
 267.162 -    }
 267.163 -
 267.164 -    static class FullFrame extends StackMapTableData {
 267.165 -        final int[] locals;
 267.166 -        final int[] stack;
 267.167 -        FullFrame(int offsetDelta, int[] locals, int[] stack) {
 267.168 -            super(FULL_FRAME);
 267.169 -            this.offsetDelta = offsetDelta;
 267.170 -            this.locals = locals;
 267.171 -            this.stack = stack;
 267.172 -        }
 267.173 -
 267.174 -        @Override
 267.175 -        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 267.176 -            localTypes.setAll(locals);
 267.177 -            stackTypes.setAll(stack);
 267.178 -        }
 267.179 -
 267.180 -        @Override
 267.181 -        public String toString() {
 267.182 -            return toString("FULL", offsetDelta, locals, stack);
 267.183 -        }
 267.184 -    }
 267.185 -
 267.186 -    static StackMapTableData getInstance(DataInputStream in, MethodData method)
 267.187 -                  throws IOException {
 267.188 -        int frameType = in.readUnsignedByte();
 267.189 -
 267.190 -        if (frameType < SAME_FRAME_BOUND) {
 267.191 -            // same_frame
 267.192 -            return new SameFrame(frameType, frameType);
 267.193 -        } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
 267.194 -            // same_locals_1_stack_item_frame
 267.195 -            // read additional single stack element
 267.196 -            return new SameLocals1StackItem(frameType,
 267.197 -                                            (frameType - SAME_FRAME_BOUND),
 267.198 -                                            StackMapData.readTypeArray(in, 1, method));
 267.199 -        } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
 267.200 -            // same_locals_1_stack_item_extended
 267.201 -            return new SameLocals1StackItem(frameType,
 267.202 -                                            in.readUnsignedShort(),
 267.203 -                                            StackMapData.readTypeArray(in, 1, method));
 267.204 -        } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType  && frameType < SAME_FRAME_EXTENDED) {
 267.205 -            // chop_frame or same_frame_extended
 267.206 -            return new ChopFrame(frameType, in.readUnsignedShort());
 267.207 -        } else if (frameType == SAME_FRAME_EXTENDED) {
 267.208 -            // chop_frame or same_frame_extended
 267.209 -            return new SameFrame(frameType, in.readUnsignedShort());
 267.210 -        } else if (SAME_FRAME_EXTENDED < frameType  && frameType < FULL_FRAME) {
 267.211 -            // append_frame
 267.212 -            return new AppendFrame(frameType, in.readUnsignedShort(),
 267.213 -                                   StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
 267.214 -        } else if (frameType == FULL_FRAME) {
 267.215 -            // full_frame
 267.216 -            int offsetDelta = in.readUnsignedShort();
 267.217 -            int locals_size = in.readUnsignedShort();
 267.218 -            int[] locals = StackMapData.readTypeArray(in, locals_size, method);
 267.219 -            int stack_size = in.readUnsignedShort();
 267.220 -            int[] stack = StackMapData.readTypeArray(in, stack_size, method);
 267.221 -            return new FullFrame(offsetDelta, locals, stack);
 267.222 -        } else {
 267.223 -            throw new ClassFormatError("unrecognized frame_type in StackMapTable");
 267.224 -        }
 267.225 -    }
 267.226 -}
   268.1 --- a/javap/src/main/java/org/apidesign/javap/TrapData.java	Mon Feb 25 19:00:08 2013 +0100
   268.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   268.3 @@ -1,62 +0,0 @@
   268.4 -/*
   268.5 - * Copyright (c) 2002, 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 -
  268.30 -package org.apidesign.javap;
  268.31 -
  268.32 -import java.io.*;
  268.33 -
  268.34 -/**
  268.35 - * Stores exception table data in code attribute.
  268.36 - *
  268.37 - * @author  Sucheta Dambalkar (Adopted code from jdis)
  268.38 - */
  268.39 -public final class TrapData {
  268.40 -  public final short start_pc;
  268.41 -  public final short end_pc;
  268.42 -  public final short handler_pc;
  268.43 -  public final short catch_cpx;
  268.44 -  final int num;
  268.45 -
  268.46 -
  268.47 -    /**
  268.48 -     * Read and store exception table data in code attribute.
  268.49 -     */
  268.50 -    TrapData(DataInputStream in, int num) throws IOException {
  268.51 -        this.num=num;
  268.52 -        start_pc = in.readShort();
  268.53 -        end_pc=in.readShort();
  268.54 -        handler_pc=in.readShort();
  268.55 -        catch_cpx=in.readShort();
  268.56 -    }
  268.57 -
  268.58 -    /**
  268.59 -     * returns recommended identifier
  268.60 -     */
  268.61 -    public String ident() {
  268.62 -        return "t"+num;
  268.63 -    }
  268.64 -
  268.65 -}
   269.1 --- a/javap/src/main/java/org/apidesign/javap/TrapDataIterator.java	Mon Feb 25 19:00:08 2013 +0100
   269.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   269.3 @@ -1,114 +0,0 @@
   269.4 -/**
   269.5 - * Back 2 Browser Bytecode Translator
   269.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   269.7 - *
   269.8 - * This program is free software: you can redistribute it and/or modify
   269.9 - * it under the terms of the GNU General Public License as published by
  269.10 - * the Free Software Foundation, version 2 of the License.
  269.11 - *
  269.12 - * This program is distributed in the hope that it will be useful,
  269.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  269.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  269.15 - * GNU General Public License for more details.
  269.16 - *
  269.17 - * You should have received a copy of the GNU General Public License
  269.18 - * along with this program. Look for COPYING file in the top folder.
  269.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  269.20 - */
  269.21 -package org.apidesign.javap;
  269.22 -
  269.23 -/**
  269.24 - *
  269.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  269.26 - */
  269.27 -public final class TrapDataIterator {
  269.28 -    private final Hashtable exStart = new Hashtable();
  269.29 -    private final Hashtable exStop = new Hashtable();
  269.30 -    private TrapData[] current = new TrapData[10];
  269.31 -    private int currentCount;
  269.32 -    
  269.33 -    TrapDataIterator(Vector exceptionTable) {
  269.34 -        for (int i=0 ; i < exceptionTable.size(); i++) {
  269.35 -            final TrapData td = (TrapData)exceptionTable.elementAt(i);
  269.36 -            put(exStart, td.start_pc, td);
  269.37 -            put(exStop, td.end_pc, td);
  269.38 -        }
  269.39 -    }
  269.40 -    
  269.41 -    private static void put(Hashtable h, short key, TrapData td) {
  269.42 -        Short s = Short.valueOf((short)key);
  269.43 -        Vector v = (Vector) h.get(s);
  269.44 -        if (v == null) {
  269.45 -            v = new Vector(1);
  269.46 -            h.put(s, v);
  269.47 -        }
  269.48 -        v.add(td);
  269.49 -    }
  269.50 -    
  269.51 -    private boolean processAll(Hashtable h, Short key, boolean add) {
  269.52 -        boolean change = false;
  269.53 -        Vector v = (Vector)h.get(key);
  269.54 -        if (v != null) {
  269.55 -            int s = v.size();
  269.56 -            for (int i = 0; i < s; i++) {
  269.57 -                TrapData td = (TrapData)v.elementAt(i);
  269.58 -                if (add) {
  269.59 -                    add(td);
  269.60 -                    change = true;
  269.61 -                } else {
  269.62 -                    remove(td);
  269.63 -                    change = true;
  269.64 -                }
  269.65 -            }
  269.66 -        }
  269.67 -        return change;
  269.68 -    }
  269.69 -    
  269.70 -    public boolean advanceTo(int i) {
  269.71 -        Short s = Short.valueOf((short)i);
  269.72 -        boolean ch1 = processAll(exStart, s, true);
  269.73 -        boolean ch2 = processAll(exStop, s, false);
  269.74 -        return ch1 || ch2;
  269.75 -    }
  269.76 -
  269.77 -    public boolean useTry() {
  269.78 -        return currentCount > 0;
  269.79 -    }
  269.80 -
  269.81 -    public TrapData[] current() {
  269.82 -        TrapData[] copy = new TrapData[currentCount];
  269.83 -        for (int i = 0; i < currentCount; i++) {
  269.84 -            copy[i] = current[i];
  269.85 -        }
  269.86 -        return copy;
  269.87 -    }
  269.88 -
  269.89 -    private void add(TrapData e) {
  269.90 -        if (currentCount == current.length) {
  269.91 -            TrapData[] data = new TrapData[currentCount * 2];
  269.92 -            for (int i = 0; i < currentCount; i++) {
  269.93 -                data[i] = current[i];
  269.94 -            }
  269.95 -            current = data;
  269.96 -        }
  269.97 -        current[currentCount++] = e;
  269.98 -    }
  269.99 -
 269.100 -    private void remove(TrapData e) {
 269.101 -        if (currentCount == 0) {
 269.102 -            return;
 269.103 -        }
 269.104 -        int from = 0;
 269.105 -        while (from < currentCount) {
 269.106 -            if (e == current[from++]) {
 269.107 -                break;
 269.108 -            }
 269.109 -        }
 269.110 -        while (from < currentCount) {
 269.111 -            current[from - 1] = current[from];
 269.112 -            current[from] = null;
 269.113 -            from++;
 269.114 -        }
 269.115 -        currentCount--;
 269.116 -    }
 269.117 -}
   270.1 --- a/javap/src/main/java/org/apidesign/javap/TypeArray.java	Mon Feb 25 19:00:08 2013 +0100
   270.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   270.3 @@ -1,186 +0,0 @@
   270.4 -/*
   270.5 - * Copyright (c) 2012, 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 org.apidesign.javap;
  270.30 -
  270.31 -import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus;
  270.32 -import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
  270.33 -import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
  270.34 -import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
  270.35 -import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
  270.36 -import static org.apidesign.javap.RuntimeConstants.ITEM_Null;
  270.37 -import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject;
  270.38 -import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
  270.39 -import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject;
  270.40 -
  270.41 -public final class TypeArray {
  270.42 -    private static final int CAPACITY_INCREMENT = 16;
  270.43 -
  270.44 -    private int[] types;
  270.45 -    private int size;
  270.46 -
  270.47 -    public TypeArray() {
  270.48 -    }
  270.49 -    
  270.50 -    public TypeArray(final TypeArray initialTypes) {
  270.51 -        setAll(initialTypes);
  270.52 -    }
  270.53 -
  270.54 -    public void add(final int newType) {
  270.55 -        ensureCapacity(size + 1);
  270.56 -        types[size++] = newType;
  270.57 -    }
  270.58 -
  270.59 -    public void addAll(final TypeArray newTypes) {
  270.60 -        addAll(newTypes.types, 0, newTypes.size);
  270.61 -    }
  270.62 -
  270.63 -    public void addAll(final int[] newTypes) {
  270.64 -        addAll(newTypes, 0, newTypes.length);
  270.65 -    }
  270.66 -
  270.67 -    public void addAll(final int[] newTypes,
  270.68 -                       final int offset,
  270.69 -                       final int count) {
  270.70 -        if (count > 0) {
  270.71 -            ensureCapacity(size + count);
  270.72 -            arraycopy(newTypes, offset, types, size, count);
  270.73 -            size += count;
  270.74 -        }
  270.75 -    }
  270.76 -
  270.77 -    public void set(final int index, final int newType) {
  270.78 -        types[index] = newType;
  270.79 -    }
  270.80 -
  270.81 -    public void setAll(final TypeArray newTypes) {
  270.82 -        setAll(newTypes.types, 0, newTypes.size);
  270.83 -    }
  270.84 -
  270.85 -    public void setAll(final int[] newTypes) {
  270.86 -        setAll(newTypes, 0, newTypes.length);
  270.87 -    }
  270.88 -
  270.89 -    public void setAll(final int[] newTypes,
  270.90 -                       final int offset,
  270.91 -                       final int count) {
  270.92 -        if (count > 0) {
  270.93 -            ensureCapacity(count);
  270.94 -            arraycopy(newTypes, offset, types, 0, count);
  270.95 -            size = count;
  270.96 -        } else {
  270.97 -            clear();
  270.98 -        }
  270.99 -    }
 270.100 -
 270.101 -    public void setSize(final int newSize) {
 270.102 -        if (size != newSize) {
 270.103 -            ensureCapacity(newSize);
 270.104 -
 270.105 -            for (int i = size; i < newSize; ++i) {
 270.106 -                types[i] = 0;
 270.107 -            }
 270.108 -            size = newSize;
 270.109 -        }
 270.110 -    }
 270.111 -
 270.112 -    public void clear() {
 270.113 -        size = 0;
 270.114 -    }
 270.115 -
 270.116 -    public int getSize() {
 270.117 -        return size;
 270.118 -    }
 270.119 -
 270.120 -    public int get(final int index) {
 270.121 -        return types[index];
 270.122 -    }
 270.123 -
 270.124 -    public static String typeString(final int type) {
 270.125 -        switch (type & 0xff) {
 270.126 -            case ITEM_Bogus:
 270.127 -                return "_top_";
 270.128 -            case ITEM_Integer:
 270.129 -                return "_int_";
 270.130 -            case ITEM_Float:
 270.131 -                return "_float_";
 270.132 -            case ITEM_Double:
 270.133 -                return "_double_";
 270.134 -            case ITEM_Long:
 270.135 -                return "_long_";
 270.136 -            case ITEM_Null:
 270.137 -                return "_null_";
 270.138 -            case ITEM_InitObject: // UninitializedThis
 270.139 -                return "_init_";
 270.140 -            case ITEM_Object:
 270.141 -                return "_object_";
 270.142 -            case ITEM_NewObject: // Uninitialized
 270.143 -                return "_new_";
 270.144 -            default:
 270.145 -                throw new IllegalArgumentException("Unknown type");
 270.146 -        }
 270.147 -    }
 270.148 -
 270.149 -    @Override
 270.150 -    public String toString() {
 270.151 -        final StringBuilder sb = new StringBuilder("[");
 270.152 -        if (size > 0) {
 270.153 -            sb.append(typeString(types[0]));
 270.154 -            for (int i = 1; i < size; ++i) {
 270.155 -                sb.append(", ");
 270.156 -                sb.append(typeString(types[i]));
 270.157 -            }
 270.158 -        }
 270.159 -
 270.160 -        return sb.append(']').toString();
 270.161 -    }
 270.162 -
 270.163 -    private void ensureCapacity(final int minCapacity) {
 270.164 -        if ((minCapacity == 0)
 270.165 -                || (types != null) && (minCapacity <= types.length)) {
 270.166 -            return;
 270.167 -        }
 270.168 -
 270.169 -        final int newCapacity =
 270.170 -                ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT)
 270.171 -                    * CAPACITY_INCREMENT;
 270.172 -        final int[] newTypes = new int[newCapacity];
 270.173 -
 270.174 -        if (size > 0) {
 270.175 -            arraycopy(types, 0, newTypes, 0, size);
 270.176 -        }
 270.177 -
 270.178 -        types = newTypes;
 270.179 -    }
 270.180 -
 270.181 -    // no System.arraycopy
 270.182 -    private void arraycopy(final int[] src, final int srcPos,
 270.183 -                           final int[] dest, final int destPos,
 270.184 -                           final int length) {
 270.185 -        for (int i = 0; i < length; ++i) {
 270.186 -            dest[destPos + i] = src[srcPos + i];
 270.187 -        }
 270.188 -    }
 270.189 -}
   271.1 --- a/javap/src/main/java/org/apidesign/javap/Vector.java	Mon Feb 25 19:00:08 2013 +0100
   271.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   271.3 @@ -1,89 +0,0 @@
   271.4 -/**
   271.5 - * Back 2 Browser Bytecode Translator
   271.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   271.7 - *
   271.8 - * This program is free software: you can redistribute it and/or modify
   271.9 - * it under the terms of the GNU General Public License as published by
  271.10 - * the Free Software Foundation, version 2 of the License.
  271.11 - *
  271.12 - * This program is distributed in the hope that it will be useful,
  271.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  271.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  271.15 - * GNU General Public License for more details.
  271.16 - *
  271.17 - * You should have received a copy of the GNU General Public License
  271.18 - * along with this program. Look for COPYING file in the top folder.
  271.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  271.20 - */
  271.21 -package org.apidesign.javap;
  271.22 -
  271.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  271.24 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  271.25 -
  271.26 -/** A JavaScript ready replacement for java.util.Vector
  271.27 - *
  271.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  271.29 - */
  271.30 -@JavaScriptPrototype(prototype = "new Array" )
  271.31 -final class Vector {
  271.32 -    private Object[] arr;
  271.33 -    
  271.34 -    Vector() {
  271.35 -    }
  271.36 -
  271.37 -    Vector(int i) {
  271.38 -    }
  271.39 -
  271.40 -    void add(Object objectType) {
  271.41 -        addElement(objectType);
  271.42 -    }
  271.43 -    @JavaScriptBody(args = { "obj" }, body = 
  271.44 -        "this.push(obj);"
  271.45 -    )
  271.46 -    void addElement(Object obj) {
  271.47 -        final int s = size();
  271.48 -        setSize(s + 1);
  271.49 -        setElementAt(obj, s);
  271.50 -    }
  271.51 -
  271.52 -    @JavaScriptBody(args = { }, body = 
  271.53 -        "return this.length;"
  271.54 -    )
  271.55 -    int size() {
  271.56 -        return arr == null ? 0 : arr.length;
  271.57 -    }
  271.58 -
  271.59 -    @JavaScriptBody(args = { "newArr" }, body =
  271.60 -        "for (var i = 0; i < this.length; i++) {\n"
  271.61 -      + "  newArr[i] = this[i];\n"
  271.62 -      + "}\n")
  271.63 -    void copyInto(Object[] newArr) {
  271.64 -        if (arr == null) {
  271.65 -            return;
  271.66 -        }
  271.67 -        int min = Math.min(newArr.length, arr.length);
  271.68 -        for (int i = 0; i < min; i++) {
  271.69 -            newArr[i] = arr[i];
  271.70 -        }
  271.71 -    }
  271.72 -
  271.73 -    @JavaScriptBody(args = { "index" }, body =
  271.74 -        "return this[index];"
  271.75 -    )
  271.76 -    Object elementAt(int index) {
  271.77 -        return arr[index];
  271.78 -    }
  271.79 -
  271.80 -    private void setSize(int len) {
  271.81 -        Object[] newArr = new Object[len];
  271.82 -        copyInto(newArr);
  271.83 -        arr = newArr;
  271.84 -    }
  271.85 -
  271.86 -    @JavaScriptBody(args = { "val", "index" }, body = 
  271.87 -        "this[index] = val;"
  271.88 -    )
  271.89 -    void setElementAt(Object val, int index) {
  271.90 -        arr[index] = val;
  271.91 -    }
  271.92 -}
   272.1 --- a/launcher/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   272.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   272.3 @@ -1,57 +0,0 @@
   272.4 -<?xml version="1.0"?>
   272.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"
   272.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   272.7 -  <modelVersion>4.0.0</modelVersion>
   272.8 -  <parent>
   272.9 -    <groupId>org.apidesign</groupId>
  272.10 -    <artifactId>bck2brwsr</artifactId>
  272.11 -    <version>0.3-SNAPSHOT</version>
  272.12 -  </parent>
  272.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
  272.14 -  <artifactId>launcher</artifactId>
  272.15 -  <version>0.3-SNAPSHOT</version>
  272.16 -  <name>Bck2Brwsr Launcher</name>
  272.17 -  <url>http://maven.apache.org</url>
  272.18 -    <build>
  272.19 -        <plugins>
  272.20 -            <plugin>
  272.21 -                <groupId>org.apache.maven.plugins</groupId>
  272.22 -                <artifactId>maven-compiler-plugin</artifactId>
  272.23 -                <version>2.3.2</version>
  272.24 -                <configuration>
  272.25 -                    <source>1.7</source>
  272.26 -                    <target>1.7</target>
  272.27 -                </configuration>
  272.28 -            </plugin>
  272.29 -            <plugin>
  272.30 -                <groupId>org.apache.maven.plugins</groupId>
  272.31 -                <artifactId>maven-javadoc-plugin</artifactId>
  272.32 -                <version>2.8.1</version>
  272.33 -                <configuration>
  272.34 -                    <excludePackageNames>org.apidesign.bck2brwsr.launcher.impl</excludePackageNames>
  272.35 -                </configuration>
  272.36 -            </plugin>
  272.37 -        </plugins>
  272.38 -    </build>
  272.39 -    <properties>
  272.40 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  272.41 -  </properties>
  272.42 -  <dependencies>
  272.43 -    <dependency>
  272.44 -      <groupId>junit</groupId>
  272.45 -      <artifactId>junit</artifactId>
  272.46 -      <version>3.8.1</version>
  272.47 -      <scope>test</scope>
  272.48 -    </dependency>
  272.49 -    <dependency>
  272.50 -      <groupId>org.glassfish.grizzly</groupId>
  272.51 -      <artifactId>grizzly-http-server</artifactId>
  272.52 -      <version>2.2.19</version>
  272.53 -    </dependency>
  272.54 -    <dependency>
  272.55 -      <groupId>${project.groupId}</groupId>
  272.56 -      <artifactId>vm4brwsr</artifactId>
  272.57 -      <version>${project.version}</version>
  272.58 -    </dependency>
  272.59 -  </dependencies>
  272.60 -</project>
   273.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Mon Feb 25 19:00:08 2013 +0100
   273.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   273.3 @@ -1,559 +0,0 @@
   273.4 -/**
   273.5 - * Back 2 Browser Bytecode Translator
   273.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   273.7 - *
   273.8 - * This program is free software: you can redistribute it and/or modify
   273.9 - * it under the terms of the GNU General Public License as published by
  273.10 - * the Free Software Foundation, version 2 of the License.
  273.11 - *
  273.12 - * This program is distributed in the hope that it will be useful,
  273.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  273.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  273.15 - * GNU General Public License for more details.
  273.16 - *
  273.17 - * You should have received a copy of the GNU General Public License
  273.18 - * along with this program. Look for COPYING file in the top folder.
  273.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  273.20 - */
  273.21 -package org.apidesign.bck2brwsr.launcher;
  273.22 -
  273.23 -import java.io.Closeable;
  273.24 -import java.io.File;
  273.25 -import java.io.IOException;
  273.26 -import java.io.InputStream;
  273.27 -import java.io.InterruptedIOException;
  273.28 -import java.io.OutputStream;
  273.29 -import java.io.Writer;
  273.30 -import java.net.URI;
  273.31 -import java.net.URISyntaxException;
  273.32 -import java.net.URL;
  273.33 -import java.util.ArrayList;
  273.34 -import java.util.Arrays;
  273.35 -import java.util.Enumeration;
  273.36 -import java.util.LinkedHashSet;
  273.37 -import java.util.List;
  273.38 -import java.util.Set;
  273.39 -import java.util.concurrent.BlockingQueue;
  273.40 -import java.util.concurrent.CountDownLatch;
  273.41 -import java.util.concurrent.LinkedBlockingQueue;
  273.42 -import java.util.concurrent.TimeUnit;
  273.43 -import java.util.logging.Level;
  273.44 -import java.util.logging.Logger;
  273.45 -import org.apidesign.bck2brwsr.launcher.InvocationContext.Resource;
  273.46 -import org.apidesign.vm4brwsr.Bck2Brwsr;
  273.47 -import org.glassfish.grizzly.PortRange;
  273.48 -import org.glassfish.grizzly.http.server.HttpHandler;
  273.49 -import org.glassfish.grizzly.http.server.HttpServer;
  273.50 -import org.glassfish.grizzly.http.server.NetworkListener;
  273.51 -import org.glassfish.grizzly.http.server.Request;
  273.52 -import org.glassfish.grizzly.http.server.Response;
  273.53 -import org.glassfish.grizzly.http.server.ServerConfiguration;
  273.54 -import org.glassfish.grizzly.http.util.HttpStatus;
  273.55 -
  273.56 -/**
  273.57 - * Lightweight server to launch Bck2Brwsr applications and tests.
  273.58 - * Supports execution in native browser as well as Java's internal 
  273.59 - * execution engine.
  273.60 - */
  273.61 -final class Bck2BrwsrLauncher extends Launcher implements Closeable {
  273.62 -    private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
  273.63 -    private static final InvocationContext END = new InvocationContext(null, null, null);
  273.64 -    private final Set<ClassLoader> loaders = new LinkedHashSet<>();
  273.65 -    private final BlockingQueue<InvocationContext> methods = new LinkedBlockingQueue<>();
  273.66 -    private long timeOut;
  273.67 -    private final Res resources = new Res();
  273.68 -    private final String cmd;
  273.69 -    private Object[] brwsr;
  273.70 -    private HttpServer server;
  273.71 -    private CountDownLatch wait;
  273.72 -    
  273.73 -    public Bck2BrwsrLauncher(String cmd) {
  273.74 -        this.cmd = cmd;
  273.75 -    }
  273.76 -    
  273.77 -    @Override
  273.78 -    InvocationContext runMethod(InvocationContext c) throws IOException {
  273.79 -        loaders.add(c.clazz.getClassLoader());
  273.80 -        methods.add(c);
  273.81 -        try {
  273.82 -            c.await(timeOut);
  273.83 -        } catch (InterruptedException ex) {
  273.84 -            throw new IOException(ex);
  273.85 -        }
  273.86 -        return c;
  273.87 -    }
  273.88 -    
  273.89 -    public void setTimeout(long ms) {
  273.90 -        timeOut = ms;
  273.91 -    }
  273.92 -    
  273.93 -    public void addClassLoader(ClassLoader url) {
  273.94 -        this.loaders.add(url);
  273.95 -    }
  273.96 -
  273.97 -    public void showURL(String startpage) throws IOException {
  273.98 -        if (!startpage.startsWith("/")) {
  273.99 -            startpage = "/" + startpage;
 273.100 -        }
 273.101 -        HttpServer s = initServer(".", true);
 273.102 -        int last = startpage.lastIndexOf('/');
 273.103 -        String simpleName = startpage.substring(last);
 273.104 -        s.getServerConfiguration().addHttpHandler(new Page(resources, startpage), simpleName);
 273.105 -        s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/");
 273.106 -        try {
 273.107 -            launchServerAndBrwsr(s, simpleName);
 273.108 -        } catch (URISyntaxException | InterruptedException ex) {
 273.109 -            throw new IOException(ex);
 273.110 -        }
 273.111 -    }
 273.112 -
 273.113 -    void showDirectory(File dir, String startpage) throws IOException {
 273.114 -        if (!startpage.startsWith("/")) {
 273.115 -            startpage = "/" + startpage;
 273.116 -        }
 273.117 -        HttpServer s = initServer(dir.getPath(), false);
 273.118 -        try {
 273.119 -            launchServerAndBrwsr(s, startpage);
 273.120 -        } catch (URISyntaxException | InterruptedException ex) {
 273.121 -            throw new IOException(ex);
 273.122 -        }
 273.123 -    }
 273.124 -
 273.125 -    @Override
 273.126 -    public void initialize() throws IOException {
 273.127 -        try {
 273.128 -            executeInBrowser();
 273.129 -        } catch (InterruptedException ex) {
 273.130 -            final InterruptedIOException iio = new InterruptedIOException(ex.getMessage());
 273.131 -            iio.initCause(ex);
 273.132 -            throw iio;
 273.133 -        } catch (Exception ex) {
 273.134 -            if (ex instanceof IOException) {
 273.135 -                throw (IOException)ex;
 273.136 -            }
 273.137 -            if (ex instanceof RuntimeException) {
 273.138 -                throw (RuntimeException)ex;
 273.139 -            }
 273.140 -            throw new IOException(ex);
 273.141 -        }
 273.142 -    }
 273.143 -    
 273.144 -    private HttpServer initServer(String path, boolean addClasses) throws IOException {
 273.145 -        HttpServer s = HttpServer.createSimpleServer(path, new PortRange(8080, 65535));
 273.146 -
 273.147 -        final ServerConfiguration conf = s.getServerConfiguration();
 273.148 -        if (addClasses) {
 273.149 -            conf.addHttpHandler(new VM(resources), "/bck2brwsr.js");
 273.150 -            conf.addHttpHandler(new Classes(resources), "/classes/");
 273.151 -        }
 273.152 -        return s;
 273.153 -    }
 273.154 -    
 273.155 -    private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
 273.156 -        wait = new CountDownLatch(1);
 273.157 -        server = initServer(".", true);
 273.158 -        final ServerConfiguration conf = server.getServerConfiguration();
 273.159 -        
 273.160 -        class DynamicResourceHandler extends HttpHandler {
 273.161 -            private final InvocationContext ic;
 273.162 -            public DynamicResourceHandler(InvocationContext ic) {
 273.163 -                if (ic == null || ic.resources.isEmpty()) {
 273.164 -                    throw new NullPointerException();
 273.165 -                }
 273.166 -                this.ic = ic;
 273.167 -                for (Resource r : ic.resources) {
 273.168 -                    conf.addHttpHandler(this, r.httpPath);
 273.169 -                }
 273.170 -            }
 273.171 -
 273.172 -            public void close() {
 273.173 -                conf.removeHttpHandler(this);
 273.174 -            }
 273.175 -            
 273.176 -            @Override
 273.177 -            public void service(Request request, Response response) throws Exception {
 273.178 -                for (Resource r : ic.resources) {
 273.179 -                    if (r.httpPath.equals(request.getRequestURI())) {
 273.180 -                        LOG.log(Level.INFO, "Serving HttpResource for {0}", request.getRequestURI());
 273.181 -                        response.setContentType(r.httpType);
 273.182 -                        copyStream(r.httpContent, response.getOutputStream(), null);
 273.183 -                    }
 273.184 -                }
 273.185 -            }
 273.186 -        }
 273.187 -        
 273.188 -        conf.addHttpHandler(new Page(resources, 
 273.189 -            "org/apidesign/bck2brwsr/launcher/harness.xhtml"
 273.190 -        ), "/execute");
 273.191 -        
 273.192 -        conf.addHttpHandler(new HttpHandler() {
 273.193 -            int cnt;
 273.194 -            List<InvocationContext> cases = new ArrayList<>();
 273.195 -            DynamicResourceHandler prev;
 273.196 -            @Override
 273.197 -            public void service(Request request, Response response) throws Exception {
 273.198 -                String id = request.getParameter("request");
 273.199 -                String value = request.getParameter("result");
 273.200 -                
 273.201 -                
 273.202 -                InvocationContext mi = null;
 273.203 -                int caseNmbr = -1;
 273.204 -                
 273.205 -                if (id != null && value != null) {
 273.206 -                    LOG.log(Level.INFO, "Received result for case {0} = {1}", new Object[]{id, value});
 273.207 -                    value = decodeURL(value);
 273.208 -                    int indx = Integer.parseInt(id);
 273.209 -                    cases.get(indx).result(value, null);
 273.210 -                    if (++indx < cases.size()) {
 273.211 -                        mi = cases.get(indx);
 273.212 -                        LOG.log(Level.INFO, "Re-executing case {0}", indx);
 273.213 -                        caseNmbr = indx;
 273.214 -                    }
 273.215 -                } else {
 273.216 -                    if (!cases.isEmpty()) {
 273.217 -                        LOG.info("Re-executing test cases");
 273.218 -                        mi = cases.get(0);
 273.219 -                        caseNmbr = 0;
 273.220 -                    }
 273.221 -                }
 273.222 -                
 273.223 -                if (prev != null) {
 273.224 -                    prev.close();
 273.225 -                    prev = null;
 273.226 -                }
 273.227 -                
 273.228 -                if (mi == null) {
 273.229 -                    mi = methods.take();
 273.230 -                    caseNmbr = cnt++;
 273.231 -                }
 273.232 -                if (mi == END) {
 273.233 -                    response.getWriter().write("");
 273.234 -                    wait.countDown();
 273.235 -                    cnt = 0;
 273.236 -                    LOG.log(Level.INFO, "End of data reached. Exiting.");
 273.237 -                    return;
 273.238 -                }
 273.239 -                
 273.240 -                if (!mi.resources.isEmpty()) {
 273.241 -                    prev = new DynamicResourceHandler(mi);
 273.242 -                }
 273.243 -                
 273.244 -                cases.add(mi);
 273.245 -                final String cn = mi.clazz.getName();
 273.246 -                final String mn = mi.methodName;
 273.247 -                LOG.log(Level.INFO, "Request for {0} case. Sending {1}.{2}", new Object[]{caseNmbr, cn, mn});
 273.248 -                response.getWriter().write("{"
 273.249 -                    + "className: '" + cn + "', "
 273.250 -                    + "methodName: '" + mn + "', "
 273.251 -                    + "request: " + caseNmbr
 273.252 -                );
 273.253 -                if (mi.html != null) {
 273.254 -                    response.getWriter().write(", html: '");
 273.255 -                    response.getWriter().write(encodeJSON(mi.html));
 273.256 -                    response.getWriter().write("'");
 273.257 -                }
 273.258 -                response.getWriter().write("}");
 273.259 -            }
 273.260 -        }, "/data");
 273.261 -
 273.262 -        this.brwsr = launchServerAndBrwsr(server, "/execute");
 273.263 -    }
 273.264 -    
 273.265 -    private static String encodeJSON(String in) {
 273.266 -        StringBuilder sb = new StringBuilder();
 273.267 -        for (int i = 0; i < in.length(); i++) {
 273.268 -            char ch = in.charAt(i);
 273.269 -            if (ch < 32 || ch == '\'' || ch == '"') {
 273.270 -                sb.append("\\u");
 273.271 -                String hs = "0000" + Integer.toHexString(ch);
 273.272 -                hs = hs.substring(hs.length() - 4);
 273.273 -                sb.append(hs);
 273.274 -            } else {
 273.275 -                sb.append(ch);
 273.276 -            }
 273.277 -        }
 273.278 -        return sb.toString();
 273.279 -    }
 273.280 -    
 273.281 -    @Override
 273.282 -    public void shutdown() throws IOException {
 273.283 -        methods.offer(END);
 273.284 -        for (;;) {
 273.285 -            int prev = methods.size();
 273.286 -            try {
 273.287 -                if (wait != null && wait.await(timeOut, TimeUnit.MILLISECONDS)) {
 273.288 -                    break;
 273.289 -                }
 273.290 -            } catch (InterruptedException ex) {
 273.291 -                throw new IOException(ex);
 273.292 -            }
 273.293 -            if (prev == methods.size()) {
 273.294 -                LOG.log(
 273.295 -                    Level.WARNING, 
 273.296 -                    "Timeout and no test has been executed meanwhile (at {0}). Giving up.", 
 273.297 -                    methods.size()
 273.298 -                );
 273.299 -                break;
 273.300 -            }
 273.301 -            LOG.log(Level.INFO, 
 273.302 -                "Timeout, but tests got from {0} to {1}. Trying again.", 
 273.303 -                new Object[]{prev, methods.size()}
 273.304 -            );
 273.305 -        }
 273.306 -        stopServerAndBrwsr(server, brwsr);
 273.307 -    }
 273.308 -    
 273.309 -    static void copyStream(InputStream is, OutputStream os, String baseURL, String... params) throws IOException {
 273.310 -        for (;;) {
 273.311 -            int ch = is.read();
 273.312 -            if (ch == -1) {
 273.313 -                break;
 273.314 -            }
 273.315 -            if (ch == '$' && params.length > 0) {
 273.316 -                int cnt = is.read() - '0';
 273.317 -                if (cnt == 'U' - '0') {
 273.318 -                    os.write(baseURL.getBytes("UTF-8"));
 273.319 -                }
 273.320 -                if (cnt >= 0 && cnt < params.length) {
 273.321 -                    os.write(params[cnt].getBytes("UTF-8"));
 273.322 -                }
 273.323 -            } else {
 273.324 -                os.write(ch);
 273.325 -            }
 273.326 -        }
 273.327 -    }
 273.328 -
 273.329 -    private Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
 273.330 -        server.start();
 273.331 -        NetworkListener listener = server.getListeners().iterator().next();
 273.332 -        int port = listener.getPort();
 273.333 -        
 273.334 -        URI uri = new URI("http://localhost:" + port + page);
 273.335 -        LOG.log(Level.INFO, "Showing {0}", uri);
 273.336 -        if (cmd == null) {
 273.337 -            try {
 273.338 -                LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
 273.339 -                    System.getProperty("java.vm.name"),
 273.340 -                    System.getProperty("java.vm.vendor"),
 273.341 -                    System.getProperty("java.vm.version"),
 273.342 -                });
 273.343 -                java.awt.Desktop.getDesktop().browse(uri);
 273.344 -                LOG.log(Level.INFO, "Desktop.browse successfully finished");
 273.345 -                return null;
 273.346 -            } catch (UnsupportedOperationException ex) {
 273.347 -                LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
 273.348 -                LOG.log(Level.FINE, null, ex);
 273.349 -            }
 273.350 -        }
 273.351 -        {
 273.352 -            String cmdName = cmd == null ? "xdg-open" : cmd;
 273.353 -            String[] cmdArr = { 
 273.354 -                cmdName, uri.toString()
 273.355 -            };
 273.356 -            LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
 273.357 -            final Process process = Runtime.getRuntime().exec(cmdArr);
 273.358 -            return new Object[] { process, null };
 273.359 -        }
 273.360 -    }
 273.361 -    
 273.362 -    private static String decodeURL(String s) {
 273.363 -        for (;;) {
 273.364 -            int pos = s.indexOf('%');
 273.365 -            if (pos == -1) {
 273.366 -                return s;
 273.367 -            }
 273.368 -            int i = Integer.parseInt(s.substring(pos + 1, pos + 2), 16);
 273.369 -            s = s.substring(0, pos) + (char)i + s.substring(pos + 2);
 273.370 -        }
 273.371 -    }
 273.372 -    
 273.373 -    private void stopServerAndBrwsr(HttpServer server, Object[] brwsr) throws IOException {
 273.374 -        if (brwsr == null) {
 273.375 -            return;
 273.376 -        }
 273.377 -        Process process = (Process)brwsr[0];
 273.378 -        
 273.379 -        server.stop();
 273.380 -        InputStream stdout = process.getInputStream();
 273.381 -        InputStream stderr = process.getErrorStream();
 273.382 -        drain("StdOut", stdout);
 273.383 -        drain("StdErr", stderr);
 273.384 -        process.destroy();
 273.385 -        int res;
 273.386 -        try {
 273.387 -            res = process.waitFor();
 273.388 -        } catch (InterruptedException ex) {
 273.389 -            throw new IOException(ex);
 273.390 -        }
 273.391 -        LOG.log(Level.INFO, "Exit code: {0}", res);
 273.392 -
 273.393 -        deleteTree((File)brwsr[1]);
 273.394 -    }
 273.395 -    
 273.396 -    private static void drain(String name, InputStream is) throws IOException {
 273.397 -        int av = is.available();
 273.398 -        if (av > 0) {
 273.399 -            StringBuilder sb = new StringBuilder();
 273.400 -            sb.append("v== ").append(name).append(" ==v\n");
 273.401 -            while (av-- > 0) {
 273.402 -                sb.append((char)is.read());
 273.403 -            }
 273.404 -            sb.append("\n^== ").append(name).append(" ==^");
 273.405 -            LOG.log(Level.INFO, sb.toString());
 273.406 -        }
 273.407 -    }
 273.408 -
 273.409 -    private void deleteTree(File file) {
 273.410 -        if (file == null) {
 273.411 -            return;
 273.412 -        }
 273.413 -        File[] arr = file.listFiles();
 273.414 -        if (arr != null) {
 273.415 -            for (File s : arr) {
 273.416 -                deleteTree(s);
 273.417 -            }
 273.418 -        }
 273.419 -        file.delete();
 273.420 -    }
 273.421 -
 273.422 -    @Override
 273.423 -    public void close() throws IOException {
 273.424 -        shutdown();
 273.425 -    }
 273.426 -
 273.427 -    private class Res implements Bck2Brwsr.Resources {
 273.428 -        @Override
 273.429 -        public InputStream get(String resource) throws IOException {
 273.430 -            for (ClassLoader l : loaders) {
 273.431 -                URL u = null;
 273.432 -                Enumeration<URL> en = l.getResources(resource);
 273.433 -                while (en.hasMoreElements()) {
 273.434 -                    u = en.nextElement();
 273.435 -                }
 273.436 -                if (u != null) {
 273.437 -                    return u.openStream();
 273.438 -                }
 273.439 -            }
 273.440 -            throw new IOException("Can't find " + resource);
 273.441 -        }
 273.442 -    }
 273.443 -
 273.444 -    private static class Page extends HttpHandler {
 273.445 -        private final String resource;
 273.446 -        private final String[] args;
 273.447 -        private final Res res;
 273.448 -        
 273.449 -        public Page(Res res, String resource, String... args) {
 273.450 -            this.res = res;
 273.451 -            this.resource = resource;
 273.452 -            this.args = args.length == 0 ? new String[] { "$0" } : args;
 273.453 -        }
 273.454 -
 273.455 -        @Override
 273.456 -        public void service(Request request, Response response) throws Exception {
 273.457 -            String r = resource;
 273.458 -            if (r == null) {
 273.459 -                r = request.getHttpHandlerPath();
 273.460 -            }
 273.461 -            if (r.startsWith("/")) {
 273.462 -                r = r.substring(1);
 273.463 -            }
 273.464 -            String[] replace = {};
 273.465 -            if (r.endsWith(".html")) {
 273.466 -                response.setContentType("text/html");
 273.467 -                LOG.info("Content type text/html");
 273.468 -                replace = args;
 273.469 -            }
 273.470 -            if (r.endsWith(".xhtml")) {
 273.471 -                response.setContentType("application/xhtml+xml");
 273.472 -                LOG.info("Content type application/xhtml+xml");
 273.473 -                replace = args;
 273.474 -            }
 273.475 -            OutputStream os = response.getOutputStream();
 273.476 -            try (InputStream is = res.get(r)) {
 273.477 -                copyStream(is, os, request.getRequestURL().toString(), replace);
 273.478 -            } catch (IOException ex) {
 273.479 -                response.setDetailMessage(ex.getLocalizedMessage());
 273.480 -                response.setError();
 273.481 -                response.setStatus(404);
 273.482 -            }
 273.483 -        }
 273.484 -    }
 273.485 -
 273.486 -    private static class VM extends HttpHandler {
 273.487 -        private final String bck2brwsr;
 273.488 -
 273.489 -        public VM(Res loader) throws IOException {
 273.490 -            StringBuilder sb = new StringBuilder();
 273.491 -            Bck2Brwsr.generate(sb, loader);
 273.492 -            sb.append(
 273.493 -                  "(function WrapperVM(global) {"
 273.494 -                + "  function ldCls(res) {\n"
 273.495 -                + "    var request = new XMLHttpRequest();\n"
 273.496 -                + "    request.open('GET', '/classes/' + res, false);\n"
 273.497 -                + "    request.send();\n"
 273.498 -                + "    if (request.status !== 200) return null;\n"
 273.499 -                + "    var arr = eval('(' + request.responseText + ')');\n"
 273.500 -                + "    return arr;\n"
 273.501 -                + "  }\n"
 273.502 -                + "  var prevvm = global.bck2brwsr;\n"
 273.503 -                + "  global.bck2brwsr = function() {\n"
 273.504 -                + "    var args = Array.prototype.slice.apply(arguments);\n"
 273.505 -                + "    args.unshift(ldCls);\n"
 273.506 -                + "    return prevvm.apply(null, args);\n"
 273.507 -                + "  };\n"
 273.508 -                + "})(this);\n"
 273.509 -            );
 273.510 -            this.bck2brwsr = sb.toString();
 273.511 -        }
 273.512 -
 273.513 -        @Override
 273.514 -        public void service(Request request, Response response) throws Exception {
 273.515 -            response.setCharacterEncoding("UTF-8");
 273.516 -            response.setContentType("text/javascript");
 273.517 -            response.getWriter().write(bck2brwsr);
 273.518 -        }
 273.519 -    }
 273.520 -
 273.521 -    private static class Classes extends HttpHandler {
 273.522 -        private final Res loader;
 273.523 -
 273.524 -        public Classes(Res loader) {
 273.525 -            this.loader = loader;
 273.526 -        }
 273.527 -
 273.528 -        @Override
 273.529 -        public void service(Request request, Response response) throws Exception {
 273.530 -            String res = request.getHttpHandlerPath();
 273.531 -            if (res.startsWith("/")) {
 273.532 -                res = res.substring(1);
 273.533 -            }
 273.534 -            try (InputStream is = loader.get(res)) {
 273.535 -                response.setContentType("text/javascript");
 273.536 -                Writer w = response.getWriter();
 273.537 -                w.append("[");
 273.538 -                for (int i = 0;; i++) {
 273.539 -                    int b = is.read();
 273.540 -                    if (b == -1) {
 273.541 -                        break;
 273.542 -                    }
 273.543 -                    if (i > 0) {
 273.544 -                        w.append(", ");
 273.545 -                    }
 273.546 -                    if (i % 20 == 0) {
 273.547 -                        w.write("\n");
 273.548 -                    }
 273.549 -                    if (b > 127) {
 273.550 -                        b = b - 256;
 273.551 -                    }
 273.552 -                    w.append(Integer.toString(b));
 273.553 -                }
 273.554 -                w.append("\n]");
 273.555 -            } catch (IOException ex) {
 273.556 -                response.setStatus(HttpStatus.NOT_FOUND_404);
 273.557 -                response.setError();
 273.558 -                response.setDetailMessage(ex.getMessage());
 273.559 -            }
 273.560 -        }
 273.561 -    }
 273.562 -}
   274.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java	Mon Feb 25 19:00:08 2013 +0100
   274.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   274.3 @@ -1,110 +0,0 @@
   274.4 -/**
   274.5 - * Back 2 Browser Bytecode Translator
   274.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   274.7 - *
   274.8 - * This program is free software: you can redistribute it and/or modify
   274.9 - * it under the terms of the GNU General Public License as published by
  274.10 - * the Free Software Foundation, version 2 of the License.
  274.11 - *
  274.12 - * This program is distributed in the hope that it will be useful,
  274.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  274.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  274.15 - * GNU General Public License for more details.
  274.16 - *
  274.17 - * You should have received a copy of the GNU General Public License
  274.18 - * along with this program. Look for COPYING file in the top folder.
  274.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  274.20 - */
  274.21 -package org.apidesign.bck2brwsr.launcher;
  274.22 -
  274.23 -import java.io.IOException;
  274.24 -import java.io.InputStream;
  274.25 -import java.util.ArrayList;
  274.26 -import java.util.List;
  274.27 -import java.util.concurrent.CountDownLatch;
  274.28 -import java.util.concurrent.TimeUnit;
  274.29 -
  274.30 -/** Represents individual method invocation, its context and its result.
  274.31 - *
  274.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  274.33 - */
  274.34 -public final class InvocationContext {
  274.35 -    final CountDownLatch wait = new CountDownLatch(1);
  274.36 -    final Class<?> clazz;
  274.37 -    final String methodName;
  274.38 -    private final Launcher launcher;
  274.39 -    private String result;
  274.40 -    private Throwable exception;
  274.41 -    String html;
  274.42 -    final List<Resource> resources = new ArrayList<>();
  274.43 -
  274.44 -    InvocationContext(Launcher launcher, Class<?> clazz, String methodName) {
  274.45 -        this.launcher = launcher;
  274.46 -        this.clazz = clazz;
  274.47 -        this.methodName = methodName;
  274.48 -    }
  274.49 -    
  274.50 -    /** An HTML fragment to be available for the execution. Useful primarily when
  274.51 -     * executing in a browser via {@link Launcher#createBrowser(java.lang.String)}.
  274.52 -     * @param html the html fragment
  274.53 -     */
  274.54 -    public void setHtmlFragment(String html) {
  274.55 -        this.html = html;
  274.56 -    }
  274.57 -    
  274.58 -    /** HTTP resource to be available during execution. An invocation may
  274.59 -     * perform an HTTP query and obtain a resource relative to the page.
  274.60 -     */
  274.61 -    public void addHttpResource(String relativePath, String mimeType, InputStream content) {
  274.62 -        if (relativePath == null || mimeType == null || content == null) {
  274.63 -            throw new NullPointerException();
  274.64 -        }
  274.65 -        resources.add(new Resource(content, mimeType, relativePath));
  274.66 -    }
  274.67 -    
  274.68 -    /** Invokes the associated method. 
  274.69 -     * @return the textual result of the invocation
  274.70 -     */
  274.71 -    public String invoke() throws IOException {
  274.72 -        launcher.runMethod(this);
  274.73 -        return toString();
  274.74 -    }
  274.75 -    
  274.76 -    /** Obtains textual result of the invocation.
  274.77 -     * @return text representing the exception or result value
  274.78 -     */
  274.79 -    @Override
  274.80 -    public String toString() {
  274.81 -        if (exception != null) {
  274.82 -            return exception.toString();
  274.83 -        }
  274.84 -        return result;
  274.85 -    }
  274.86 -    
  274.87 -    /**
  274.88 -     * @param timeOut
  274.89 -     * @throws InterruptedException 
  274.90 -     */
  274.91 -    void await(long timeOut) throws InterruptedException {
  274.92 -        wait.await(timeOut, TimeUnit.MILLISECONDS);
  274.93 -    }
  274.94 -    
  274.95 -    void result(String r, Throwable e) {
  274.96 -        this.result = r;
  274.97 -        this.exception = e;
  274.98 -        wait.countDown();
  274.99 -    }
 274.100 -
 274.101 -
 274.102 -    static final class Resource {
 274.103 -        final InputStream httpContent;
 274.104 -        final String httpType;
 274.105 -        final String httpPath;
 274.106 -
 274.107 -        Resource(InputStream httpContent, String httpType, String httpPath) {
 274.108 -            this.httpContent = httpContent;
 274.109 -            this.httpType = httpType;
 274.110 -            this.httpPath = httpPath;
 274.111 -        }
 274.112 -    }
 274.113 -}
   275.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java	Mon Feb 25 19:00:08 2013 +0100
   275.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   275.3 @@ -1,132 +0,0 @@
   275.4 -/**
   275.5 - * Back 2 Browser Bytecode Translator
   275.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   275.7 - *
   275.8 - * This program is free software: you can redistribute it and/or modify
   275.9 - * it under the terms of the GNU General Public License as published by
  275.10 - * the Free Software Foundation, version 2 of the License.
  275.11 - *
  275.12 - * This program is distributed in the hope that it will be useful,
  275.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  275.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  275.15 - * GNU General Public License for more details.
  275.16 - *
  275.17 - * You should have received a copy of the GNU General Public License
  275.18 - * along with this program. Look for COPYING file in the top folder.
  275.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  275.20 - */
  275.21 -package org.apidesign.bck2brwsr.launcher;
  275.22 -
  275.23 -import org.apidesign.bck2brwsr.launcher.impl.Console;
  275.24 -import java.io.IOException;
  275.25 -import java.io.InputStream;
  275.26 -import java.net.URL;
  275.27 -import java.util.Enumeration;
  275.28 -import java.util.LinkedHashSet;
  275.29 -import java.util.Set;
  275.30 -import java.util.logging.Level;
  275.31 -import java.util.logging.Logger;
  275.32 -import javax.script.Invocable;
  275.33 -import javax.script.ScriptEngine;
  275.34 -import javax.script.ScriptEngineManager;
  275.35 -import javax.script.ScriptException;
  275.36 -import org.apidesign.vm4brwsr.Bck2Brwsr;
  275.37 -
  275.38 -/**
  275.39 - * Tests execution in Java's internal scripting engine.
  275.40 - */
  275.41 -final class JSLauncher extends Launcher {
  275.42 -    private static final Logger LOG = Logger.getLogger(JSLauncher.class.getName());
  275.43 -    private Set<ClassLoader> loaders = new LinkedHashSet<>();
  275.44 -    private final Res resources = new Res();
  275.45 -    private Invocable code;
  275.46 -    private StringBuilder codeSeq;
  275.47 -    private Object console;
  275.48 -    
  275.49 -    
  275.50 -    @Override InvocationContext runMethod(InvocationContext mi) {
  275.51 -        loaders.add(mi.clazz.getClassLoader());
  275.52 -        try {
  275.53 -            long time = System.currentTimeMillis();
  275.54 -            LOG.log(Level.FINE, "Invoking {0}.{1}", new Object[]{mi.clazz.getName(), mi.methodName});
  275.55 -            String res = code.invokeMethod(
  275.56 -                console,
  275.57 -                "invoke__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2",
  275.58 -                mi.clazz.getName(), mi.methodName).toString();
  275.59 -            time = System.currentTimeMillis() - time;
  275.60 -            LOG.log(Level.FINE, "Resut of {0}.{1} = {2} in {3} ms", new Object[]{mi.clazz.getName(), mi.methodName, res, time});
  275.61 -            mi.result(res, null);
  275.62 -        } catch (ScriptException | NoSuchMethodException ex) {
  275.63 -            mi.result(null, ex);
  275.64 -        }
  275.65 -        return mi;
  275.66 -    }
  275.67 -    
  275.68 -    public void addClassLoader(ClassLoader url) {
  275.69 -        this.loaders.add(url);
  275.70 -    }
  275.71 -
  275.72 -    @Override
  275.73 -    public void initialize() throws IOException {
  275.74 -        try {
  275.75 -            initRhino();
  275.76 -        } catch (Exception ex) {
  275.77 -            if (ex instanceof IOException) {
  275.78 -                throw (IOException)ex;
  275.79 -            }
  275.80 -            if (ex instanceof RuntimeException) {
  275.81 -                throw (RuntimeException)ex;
  275.82 -            }
  275.83 -            throw new IOException(ex);
  275.84 -        }
  275.85 -    }
  275.86 -    
  275.87 -    private void initRhino() throws IOException, ScriptException, NoSuchMethodException {
  275.88 -        StringBuilder sb = new StringBuilder();
  275.89 -        Bck2Brwsr.generate(sb, new Res());
  275.90 -
  275.91 -        ScriptEngineManager sem = new ScriptEngineManager();
  275.92 -        ScriptEngine mach = sem.getEngineByExtension("js");
  275.93 -
  275.94 -        sb.append(
  275.95 -              "\nvar vm = new bck2brwsr(org.apidesign.bck2brwsr.launcher.impl.Console.read);"
  275.96 -            + "\nfunction initVM() { return vm; };"
  275.97 -            + "\n");
  275.98 -
  275.99 -        Object res = mach.eval(sb.toString());
 275.100 -        if (!(mach instanceof Invocable)) {
 275.101 -            throw new IOException("It is invocable object: " + res);
 275.102 -        }
 275.103 -        code = (Invocable) mach;
 275.104 -        codeSeq = sb;
 275.105 -        
 275.106 -        Object vm = code.invokeFunction("initVM");
 275.107 -        console = code.invokeMethod(vm, "loadClass", Console.class.getName());
 275.108 -    }
 275.109 -
 275.110 -    @Override
 275.111 -    public void shutdown() throws IOException {
 275.112 -    }
 275.113 -
 275.114 -    @Override
 275.115 -    public String toString() {
 275.116 -        return codeSeq.toString();
 275.117 -    }
 275.118 -    
 275.119 -    private class Res implements Bck2Brwsr.Resources {
 275.120 -        @Override
 275.121 -        public InputStream get(String resource) throws IOException {
 275.122 -            for (ClassLoader l : loaders) {
 275.123 -                URL u = null;
 275.124 -                Enumeration<URL> en = l.getResources(resource);
 275.125 -                while (en.hasMoreElements()) {
 275.126 -                    u = en.nextElement();
 275.127 -                }
 275.128 -                if (u != null) {
 275.129 -                    return u.openStream();
 275.130 -                }
 275.131 -            }
 275.132 -            throw new IOException("Can't find " + resource);
 275.133 -        }
 275.134 -    }
 275.135 -}
   276.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Mon Feb 25 19:00:08 2013 +0100
   276.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   276.3 @@ -1,115 +0,0 @@
   276.4 -/**
   276.5 - * Back 2 Browser Bytecode Translator
   276.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   276.7 - *
   276.8 - * This program is free software: you can redistribute it and/or modify
   276.9 - * it under the terms of the GNU General Public License as published by
  276.10 - * the Free Software Foundation, version 2 of the License.
  276.11 - *
  276.12 - * This program is distributed in the hope that it will be useful,
  276.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  276.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  276.15 - * GNU General Public License for more details.
  276.16 - *
  276.17 - * You should have received a copy of the GNU General Public License
  276.18 - * along with this program. Look for COPYING file in the top folder.
  276.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  276.20 - */
  276.21 -package org.apidesign.bck2brwsr.launcher;
  276.22 -
  276.23 -import java.io.Closeable;
  276.24 -import java.io.File;
  276.25 -import java.io.IOException;
  276.26 -import java.net.URLClassLoader;
  276.27 -import org.apidesign.vm4brwsr.Bck2Brwsr;
  276.28 -
  276.29 -/** An abstraction for executing tests in a Bck2Brwsr virtual machine.
  276.30 - * Either in {@linkm Launcher#createJavaScript JavaScript engine}, 
  276.31 - * or in {@linkm Launcher#createBrowser external browser}.
  276.32 - *
  276.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  276.34 - */
  276.35 -public abstract class Launcher {
  276.36 -
  276.37 -    Launcher() {
  276.38 -    }
  276.39 -
  276.40 -    /** Initializes the launcher. This may mean starting a web browser or
  276.41 -     * initializing execution engine.
  276.42 -     * @throws IOException if something goes wrong
  276.43 -     */
  276.44 -    public abstract void initialize() throws IOException;
  276.45 -    
  276.46 -    /** Shuts down the launcher.
  276.47 -     * @throws IOException if something goes wrong
  276.48 -     */
  276.49 -    public abstract void shutdown() throws IOException;
  276.50 -    
  276.51 -    
  276.52 -    /** Builds an invocation context. The context can later be customized
  276.53 -     * and {@link InvocationContext#invoke() invoked}.
  276.54 -     * 
  276.55 -     * @param clazz the class to execute method from
  276.56 -     * @param method the method to execute
  276.57 -     * @return the context pointing to the selected method
  276.58 -     */
  276.59 -    public InvocationContext createInvocation(Class<?> clazz, String method) {
  276.60 -        return new InvocationContext(this, clazz, method);
  276.61 -    }
  276.62 -    
  276.63 -
  276.64 -    /** Creates launcher that uses internal JavaScript engine (Rhino).
  276.65 -     * @return the launcher
  276.66 -     */
  276.67 -    public static Launcher createJavaScript() {
  276.68 -        final JSLauncher l = new JSLauncher();
  276.69 -        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
  276.70 -        return l;
  276.71 -    }
  276.72 -    
  276.73 -    /** Creates launcher that is using external browser.
  276.74 -     * 
  276.75 -     * @param cmd <code>null</code> to use <code>java.awt.Desktop</code> to show the launcher
  276.76 -     *    or a string to execute in an external process (with a parameter to the URL)
  276.77 -     * @return launcher executing in external browser.
  276.78 -     */
  276.79 -    public static Launcher createBrowser(String cmd) {
  276.80 -        final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
  276.81 -        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
  276.82 -        l.setTimeout(180000);
  276.83 -        return l;
  276.84 -    }
  276.85 -    
  276.86 -    /** Starts an HTTP server which provides access to classes and resources
  276.87 -     * available in the <code>classes</code> URL and shows a start page
  276.88 -     * available as {@link ClassLoader#getResource(java.lang.String)} from the
  276.89 -     * provide classloader. Opens a browser with URL showing the start page.
  276.90 -     * 
  276.91 -     * @param classes classloader offering access to classes and resources
  276.92 -     * @param startpage page to show in the browser
  276.93 -     * @return interface that allows one to stop the server
  276.94 -     * @throws IOException if something goes wrong
  276.95 -     */
  276.96 -    public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
  276.97 -        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
  276.98 -        l.addClassLoader(classes);
  276.99 -        l.showURL(startpage);
 276.100 -        return l;
 276.101 -    }
 276.102 -    /** Starts an HTTP server which provides access to certain directory.
 276.103 -     * The <code>startpage</code> should be relative location inside the root 
 276.104 -     * driecotry
 276.105 -     * Opens a browser with URL showing the start page.
 276.106 -     * 
 276.107 -     * @param directory the root directory on disk
 276.108 -     * @praam startpage relative path from the root to the page
 276.109 -     * @exception IOException if something goes wrong.
 276.110 -     */
 276.111 -    public static Closeable showDir(File directory, String startpage) throws IOException {
 276.112 -        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
 276.113 -        l.showDirectory(directory, startpage);
 276.114 -        return l;
 276.115 -    }
 276.116 -
 276.117 -    abstract InvocationContext runMethod(InvocationContext c) throws IOException; 
 276.118 -}
   277.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java	Mon Feb 25 19:00:08 2013 +0100
   277.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   277.3 @@ -1,255 +0,0 @@
   277.4 -/**
   277.5 - * Back 2 Browser Bytecode Translator
   277.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   277.7 - *
   277.8 - * This program is free software: you can redistribute it and/or modify
   277.9 - * it under the terms of the GNU General Public License as published by
  277.10 - * the Free Software Foundation, version 2 of the License.
  277.11 - *
  277.12 - * This program is distributed in the hope that it will be useful,
  277.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  277.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  277.15 - * GNU General Public License for more details.
  277.16 - *
  277.17 - * You should have received a copy of the GNU General Public License
  277.18 - * along with this program. Look for COPYING file in the top folder.
  277.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  277.20 - */
  277.21 -package org.apidesign.bck2brwsr.launcher.impl;
  277.22 -
  277.23 -import java.io.IOException;
  277.24 -import java.io.InputStream;
  277.25 -import java.lang.reflect.InvocationTargetException;
  277.26 -import java.lang.reflect.Method;
  277.27 -import java.lang.reflect.Modifier;
  277.28 -import java.net.URL;
  277.29 -import java.util.Enumeration;
  277.30 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  277.31 -
  277.32 -/**
  277.33 - *
  277.34 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  277.35 - */
  277.36 -public class Console {
  277.37 -    private Console() {
  277.38 -    }
  277.39 -    static {
  277.40 -        turnAssetionStatusOn();
  277.41 -    }
  277.42 -    
  277.43 -    @JavaScriptBody(args = {"id", "attr"}, body = 
  277.44 -        "return window.document.getElementById(id)[attr].toString();")
  277.45 -    private static native Object getAttr(String id, String attr);
  277.46 -
  277.47 -    @JavaScriptBody(args = {"id", "attr", "value"}, body = 
  277.48 -        "window.document.getElementById(id)[attr] = value;")
  277.49 -    private static native void setAttr(String id, String attr, Object value);
  277.50 -    
  277.51 -    @JavaScriptBody(args = {}, body = "return; window.close();")
  277.52 -    private static native void closeWindow();
  277.53 -
  277.54 -    private static void log(String newText) {
  277.55 -        String id = "bck2brwsr.result";
  277.56 -        String attr = "value";
  277.57 -        setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
  277.58 -        setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
  277.59 -    }
  277.60 -    
  277.61 -    public static void execute() throws Exception {
  277.62 -        String clazz = (String) getAttr("clazz", "value");
  277.63 -        String method = (String) getAttr("method", "value");
  277.64 -        Object res = invokeMethod(clazz, method);
  277.65 -        setAttr("bck2brwsr.result", "value", res);
  277.66 -    }
  277.67 -
  277.68 -    @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
  277.69 -        + "var request = new XMLHttpRequest();\n"
  277.70 -        + "request.open('GET', url, true);\n"
  277.71 -        + "request.onreadystatechange = function() {\n"
  277.72 -        + "  if (this.readyState!==4) return;\n"
  277.73 -        + "  arr[0] = this.responseText;\n"
  277.74 -        + "  callback.run__V();\n"
  277.75 -        + "};"
  277.76 -        + "request.send();"
  277.77 -    )
  277.78 -    private static native void loadText(String url, Runnable callback, String[] arr) throws IOException;
  277.79 -    
  277.80 -    public static void harness(String url) throws IOException {
  277.81 -        log("Connecting to " + url);
  277.82 -        Request r = new Request(url);
  277.83 -    }
  277.84 -    
  277.85 -    private static class Request implements Runnable {
  277.86 -        private final String[] arr = { null };
  277.87 -        private final String url;
  277.88 -
  277.89 -        private Request(String url) throws IOException {
  277.90 -            this.url = url;
  277.91 -            loadText(url, this, arr);
  277.92 -        }
  277.93 -        
  277.94 -        @Override
  277.95 -        public void run() {
  277.96 -            try {
  277.97 -                String data = arr[0];
  277.98 -                log("\nGot \"" + data + "\"");
  277.99 -                
 277.100 -                if (data == null) {
 277.101 -                    log("Some error exiting");
 277.102 -                    closeWindow();
 277.103 -                    return;
 277.104 -                }
 277.105 -                
 277.106 -                if (data.isEmpty()) {
 277.107 -                    log("No data, exiting");
 277.108 -                    closeWindow();
 277.109 -                    return;
 277.110 -                }
 277.111 -                
 277.112 -                Case c = Case.parseData(data);
 277.113 -                if (c.getHtmlFragment() != null) {
 277.114 -                    setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
 277.115 -                }
 277.116 -                log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
 277.117 -
 277.118 -                Object result = invokeMethod(c.getClassName(), c.getMethodName());
 277.119 -                
 277.120 -                setAttr("bck2brwsr.fragment", "innerHTML", "");
 277.121 -                log("Result: " + result);
 277.122 -                
 277.123 -                result = encodeURL("" + result);
 277.124 -                
 277.125 -                log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
 277.126 -                String u = url + "?request=" + c.getRequestId() + "&result=" + result;
 277.127 -                
 277.128 -                loadText(u, this, arr);
 277.129 -                
 277.130 -            } catch (Exception ex) {
 277.131 -                log(ex.getClass().getName() + ":" + ex.getMessage());
 277.132 -            }
 277.133 -        }
 277.134 -    }
 277.135 -    
 277.136 -    private static String encodeURL(String r) {
 277.137 -        StringBuilder sb = new StringBuilder();
 277.138 -        for (int i = 0; i < r.length(); i++) {
 277.139 -            int ch = r.charAt(i);
 277.140 -            if (ch < 32 || ch == '%' || ch == '+') {
 277.141 -                sb.append("%").append(("0" + Integer.toHexString(ch)).substring(0, 2));
 277.142 -            } else {
 277.143 -                if (ch == 32) {
 277.144 -                    sb.append("+");
 277.145 -                } else {
 277.146 -                    sb.append((char)ch);
 277.147 -                }
 277.148 -            }
 277.149 -        }
 277.150 -        return sb.toString();
 277.151 -    }
 277.152 -    
 277.153 -    static String invoke(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
 277.154 -        final Object r = invokeMethod(clazz, method);
 277.155 -        return r == null ? "null" : r.toString().toString();
 277.156 -    }
 277.157 -
 277.158 -    /** Helper method that inspects the classpath and loads given resource
 277.159 -     * (usually a class file). Used while running tests in Rhino.
 277.160 -     * 
 277.161 -     * @param name resource name to find
 277.162 -     * @return the array of bytes in the given resource
 277.163 -     * @throws IOException I/O in case something goes wrong
 277.164 -     */
 277.165 -    public static byte[] read(String name) throws IOException {
 277.166 -        URL u = null;
 277.167 -        Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
 277.168 -        while (en.hasMoreElements()) {
 277.169 -            u = en.nextElement();
 277.170 -        }
 277.171 -        if (u == null) {
 277.172 -            throw new IOException("Can't find " + name);
 277.173 -        }
 277.174 -        try (InputStream is = u.openStream()) {
 277.175 -            byte[] arr;
 277.176 -            arr = new byte[is.available()];
 277.177 -            int offset = 0;
 277.178 -            while (offset < arr.length) {
 277.179 -                int len = is.read(arr, offset, arr.length - offset);
 277.180 -                if (len == -1) {
 277.181 -                    throw new IOException("Can't read " + name);
 277.182 -                }
 277.183 -                offset += len;
 277.184 -            }
 277.185 -            return arr;
 277.186 -        }
 277.187 -    }
 277.188 -   
 277.189 -    private static Object invokeMethod(String clazz, String method) 
 277.190 -    throws ClassNotFoundException, InvocationTargetException, 
 277.191 -    SecurityException, IllegalAccessException, IllegalArgumentException,
 277.192 -    InstantiationException {
 277.193 -        Method found = null;
 277.194 -        Class<?> c = Class.forName(clazz);
 277.195 -        for (Method m : c.getMethods()) {
 277.196 -            if (m.getName().equals(method)) {
 277.197 -                found = m;
 277.198 -            }
 277.199 -        }
 277.200 -        Object res;
 277.201 -        if (found != null) {
 277.202 -            try {
 277.203 -                if ((found.getModifiers() & Modifier.STATIC) != 0) {
 277.204 -                    res = found.invoke(null);
 277.205 -                } else {
 277.206 -                    res = found.invoke(c.newInstance());
 277.207 -                }
 277.208 -            } catch (Throwable ex) {
 277.209 -                res = ex.getClass().getName() + ":" + ex.getMessage();
 277.210 -            }
 277.211 -        } else {
 277.212 -            res = "Can't find method " + method + " in " + clazz;
 277.213 -        }
 277.214 -        return res;
 277.215 -    }
 277.216 -
 277.217 -    @JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
 277.218 -    private static void turnAssetionStatusOn() {
 277.219 -    }
 277.220 -    
 277.221 -    private static final class Case {
 277.222 -        private final Object data;
 277.223 -
 277.224 -        private Case(Object data) {
 277.225 -            this.data = data;
 277.226 -        }
 277.227 -        
 277.228 -        public static Case parseData(String s) {
 277.229 -            return new Case(toJSON(s));
 277.230 -        }
 277.231 -        
 277.232 -        public String getMethodName() {
 277.233 -            return value("methodName", data);
 277.234 -        }
 277.235 -
 277.236 -        public String getClassName() {
 277.237 -            return value("className", data);
 277.238 -        }
 277.239 -        
 277.240 -        public String getRequestId() {
 277.241 -            return value("request", data);
 277.242 -        }
 277.243 -
 277.244 -        public String getHtmlFragment() {
 277.245 -            return value("html", data);
 277.246 -        }
 277.247 -        
 277.248 -        @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
 277.249 -        private static native Object toJSON(String s);
 277.250 -        
 277.251 -        @JavaScriptBody(args = {"p", "d"}, body = 
 277.252 -              "var v = d[p];\n"
 277.253 -            + "if (typeof v === 'undefined') return null;\n"
 277.254 -            + "return v.toString();"
 277.255 -        )
 277.256 -        private static native String value(String p, Object d);
 277.257 -    }
 277.258 -}
   278.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml	Mon Feb 25 19:00:08 2013 +0100
   278.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   278.3 @@ -1,43 +0,0 @@
   278.4 -<?xml version="1.0" encoding="UTF-8"?>
   278.5 -<!--
   278.6 -
   278.7 -    Back 2 Browser Bytecode Translator
   278.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   278.9 -
  278.10 -    This program is free software: you can redistribute it and/or modify
  278.11 -    it under the terms of the GNU General Public License as published by
  278.12 -    the Free Software Foundation, version 2 of the License.
  278.13 -
  278.14 -    This program is distributed in the hope that it will be useful,
  278.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
  278.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  278.17 -    GNU General Public License for more details.
  278.18 -
  278.19 -    You should have received a copy of the GNU General Public License
  278.20 -    along with this program. Look for COPYING file in the top folder.
  278.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
  278.22 -
  278.23 --->
  278.24 -<!DOCTYPE html>
  278.25 -<html xmlns="http://www.w3.org/1999/xhtml">
  278.26 -    <head>
  278.27 -        <title>Bck2Brwsr Harness</title>
  278.28 -    </head>
  278.29 -    <body>
  278.30 -        <script src="/bck2brwsr.js"></script>
  278.31 -        <script>
  278.32 -            var vm = bck2brwsr();
  278.33 -        </script>
  278.34 -        
  278.35 -        <h1>Bck2Brwsr Execution Harness</h1>
  278.36 -        
  278.37 -        <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
  278.38 -        </textarea>
  278.39 -
  278.40 -        <div id="bck2brwsr.fragment"/>
  278.41 -        
  278.42 -        <script type="text/javascript">
  278.43 -            vm.loadClass('org.apidesign.bck2brwsr.launcher.impl.Console').harness__VLjava_lang_String_2('$U/../data');
  278.44 -        </script>
  278.45 -    </body>
  278.46 -</html>
   279.1 --- a/mojo/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   279.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   279.3 @@ -1,86 +0,0 @@
   279.4 -<?xml version="1.0"?>
   279.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"
   279.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   279.7 -  <modelVersion>4.0.0</modelVersion>
   279.8 -  <parent>
   279.9 -    <groupId>org.apidesign</groupId>
  279.10 -    <artifactId>bck2brwsr</artifactId>
  279.11 -    <version>0.3-SNAPSHOT</version>
  279.12 -  </parent>
  279.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
  279.14 -  <artifactId>mojo</artifactId>
  279.15 -  <version>0.3-SNAPSHOT</version>
  279.16 -  <packaging>maven-plugin</packaging>
  279.17 -  <name>Bck2Brwsr Maven Project</name>
  279.18 -  <url>http://maven.apache.org</url>
  279.19 -      <build>
  279.20 -        <plugins>
  279.21 -            <plugin>
  279.22 -                <groupId>org.apache.maven.plugins</groupId>
  279.23 -                <artifactId>maven-plugin-plugin</artifactId>
  279.24 -                <version>3.1</version>
  279.25 -                <configuration>
  279.26 -                    <extractors>
  279.27 -                        <extractor>java-annotations</extractor>
  279.28 -                    </extractors>
  279.29 -                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
  279.30 -                 </configuration>
  279.31 -                <executions>
  279.32 -                    <execution>
  279.33 -                        <id>mojo-descriptor</id>
  279.34 -                        <phase>process-classes</phase>
  279.35 -                        <goals>
  279.36 -                            <goal>descriptor</goal>
  279.37 -                        </goals>
  279.38 -                    </execution>
  279.39 -                </executions>
  279.40 -            </plugin>
  279.41 -            <plugin>
  279.42 -                <groupId>org.apache.maven.plugins</groupId>
  279.43 -                <artifactId>maven-compiler-plugin</artifactId>
  279.44 -                <version>2.3.2</version>
  279.45 -                <configuration>
  279.46 -                    <source>1.6</source>
  279.47 -                    <target>1.6</target>
  279.48 -                </configuration>
  279.49 -            </plugin>
  279.50 -        </plugins>
  279.51 -      </build>
  279.52 -      
  279.53 -<dependencies>
  279.54 -    <dependency>
  279.55 -      <groupId>org.apache.maven</groupId>
  279.56 -      <artifactId>maven-plugin-api</artifactId>
  279.57 -      <version>3.0.4</version>
  279.58 -      <type>jar</type>
  279.59 -    </dependency>
  279.60 -    <dependency>
  279.61 -      <groupId>org.apache.maven.plugin-tools</groupId>
  279.62 -      <artifactId>maven-plugin-annotations</artifactId>
  279.63 -      <version>3.0</version>
  279.64 -      <type>jar</type>
  279.65 -    </dependency>
  279.66 -    <dependency>
  279.67 -      <groupId>${project.groupId}</groupId>
  279.68 -      <artifactId>vm4brwsr</artifactId>
  279.69 -      <version>0.3-SNAPSHOT</version>
  279.70 -      <exclusions>
  279.71 -        <exclusion>
  279.72 -          <artifactId>emul.mini</artifactId>
  279.73 -          <groupId>org.apidesign.bck2brwsr</groupId>
  279.74 -        </exclusion>
  279.75 -      </exclusions>
  279.76 -    </dependency>
  279.77 -    <dependency>
  279.78 -        <groupId>org.apache.maven</groupId>
  279.79 -        <artifactId>maven-core</artifactId>
  279.80 -      <version>3.0.2</version>
  279.81 -      <type>jar</type>
  279.82 -    </dependency>
  279.83 -    <dependency>
  279.84 -        <groupId>${project.groupId}</groupId>
  279.85 -        <artifactId>launcher</artifactId>
  279.86 -      <version>${project.version}</version>
  279.87 -    </dependency>
  279.88 -</dependencies>
  279.89 -</project>
   280.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Mon Feb 25 19:00:08 2013 +0100
   280.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   280.3 @@ -1,99 +0,0 @@
   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.bck2brwsr.mojo;
  280.22 -
  280.23 -import java.io.Closeable;
  280.24 -import org.apache.maven.plugin.AbstractMojo;
  280.25 -
  280.26 -import java.io.File;
  280.27 -import java.io.IOException;
  280.28 -import java.net.MalformedURLException;
  280.29 -import java.net.URL;
  280.30 -import java.net.URLClassLoader;
  280.31 -import java.util.ArrayList;
  280.32 -import java.util.Collection;
  280.33 -import java.util.List;
  280.34 -import org.apache.maven.artifact.Artifact;
  280.35 -import org.apache.maven.plugin.MojoExecutionException;
  280.36 -import org.apache.maven.plugins.annotations.LifecyclePhase;
  280.37 -import org.apache.maven.plugins.annotations.Mojo;
  280.38 -import org.apache.maven.plugins.annotations.Parameter;
  280.39 -import org.apache.maven.project.MavenProject;
  280.40 -import org.apidesign.bck2brwsr.launcher.Launcher;
  280.41 -
  280.42 -/** Executes given HTML page in a browser. */
  280.43 -@Mojo(name="brwsr", defaultPhase=LifecyclePhase.NONE)
  280.44 -public class BrswrMojo extends AbstractMojo {
  280.45 -    public BrswrMojo() {
  280.46 -    }
  280.47 -    /** Resource to show as initial page */
  280.48 -    @Parameter
  280.49 -    private String startpage;
  280.50 -
  280.51 -    @Parameter(defaultValue="${project}")
  280.52 -    private MavenProject prj;
  280.53 -    
  280.54 -    /** Root of the class files */
  280.55 -    @Parameter(defaultValue="${project.build.directory}/classes")
  280.56 -    private File classes;
  280.57 -    
  280.58 -    /** Root of all pages, and files, etc. */
  280.59 -    @Parameter
  280.60 -    private File directory;
  280.61 -
  280.62 -    @Override
  280.63 -    public void execute() throws MojoExecutionException {
  280.64 -        if (startpage == null) {
  280.65 -            throw new MojoExecutionException("You have to provide a start page");
  280.66 -        }
  280.67 -        
  280.68 -        try {
  280.69 -            Closeable httpServer;
  280.70 -            if (directory != null) {
  280.71 -                httpServer = Launcher.showDir(directory, startpage);
  280.72 -            } else {
  280.73 -                URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
  280.74 -                try {
  280.75 -                    httpServer = Launcher.showURL(url, startpage());
  280.76 -                } catch (Exception ex) {
  280.77 -                    throw new MojoExecutionException("Can't open " + startpage(), ex);
  280.78 -                }
  280.79 -            }
  280.80 -            System.in.read();
  280.81 -            httpServer.close();
  280.82 -        } catch (IOException ex) {
  280.83 -            throw new MojoExecutionException("Can't show the browser", ex);
  280.84 -        }
  280.85 -    }
  280.86 -    
  280.87 -    private String startpage() {
  280.88 -        return startpage;
  280.89 -    }
  280.90 -
  280.91 -    private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
  280.92 -        List<URL> arr = new ArrayList<URL>();
  280.93 -        arr.add(root.toURI().toURL());
  280.94 -        for (Artifact a : deps) {
  280.95 -            final File f = a.getFile();
  280.96 -            if (f != null) {
  280.97 -                arr.add(f.toURI().toURL());
  280.98 -            }
  280.99 -        }
 280.100 -        return new URLClassLoader(arr.toArray(new URL[0]), BrswrMojo.class.getClassLoader());
 280.101 -    }
 280.102 -}
   281.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java	Mon Feb 25 19:00:08 2013 +0100
   281.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   281.3 @@ -1,122 +0,0 @@
   281.4 -/**
   281.5 - * Back 2 Browser Bytecode Translator
   281.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   281.7 - *
   281.8 - * This program is free software: you can redistribute it and/or modify
   281.9 - * it under the terms of the GNU General Public License as published by
  281.10 - * the Free Software Foundation, version 2 of the License.
  281.11 - *
  281.12 - * This program is distributed in the hope that it will be useful,
  281.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  281.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  281.15 - * GNU General Public License for more details.
  281.16 - *
  281.17 - * You should have received a copy of the GNU General Public License
  281.18 - * along with this program. Look for COPYING file in the top folder.
  281.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  281.20 - */
  281.21 -package org.apidesign.bck2brwsr.mojo;
  281.22 -
  281.23 -import org.apache.maven.plugin.AbstractMojo;
  281.24 -
  281.25 -import java.io.File;
  281.26 -import java.io.FileWriter;
  281.27 -import java.io.IOException;
  281.28 -import java.net.MalformedURLException;
  281.29 -import java.net.URL;
  281.30 -import java.net.URLClassLoader;
  281.31 -import java.util.ArrayList;
  281.32 -import java.util.Collection;
  281.33 -import java.util.List;
  281.34 -import org.apache.maven.artifact.Artifact;
  281.35 -import org.apache.maven.plugin.MojoExecutionException;
  281.36 -import org.apache.maven.plugins.annotations.LifecyclePhase;
  281.37 -import org.apache.maven.plugins.annotations.Mojo;
  281.38 -import org.apache.maven.plugins.annotations.Parameter;
  281.39 -import org.apache.maven.project.MavenProject;
  281.40 -import org.apidesign.vm4brwsr.Bck2Brwsr;
  281.41 -
  281.42 -/** Compiles classes into JavaScript. */
  281.43 -@Mojo(name="j2js", defaultPhase=LifecyclePhase.PROCESS_CLASSES)
  281.44 -public class Java2JavaScript extends AbstractMojo {
  281.45 -    public Java2JavaScript() {
  281.46 -    }
  281.47 -    /** Root of the class files */
  281.48 -    @Parameter(defaultValue="${project.build.directory}/classes")
  281.49 -    private File classes;
  281.50 -    /** File to generate. Defaults bootjava.js in the first non-empty 
  281.51 -     package under the classes directory */
  281.52 -    @Parameter
  281.53 -    private File javascript;
  281.54 -    
  281.55 -    @Parameter(defaultValue="${project}")
  281.56 -    private MavenProject prj;
  281.57 -    
  281.58 -    
  281.59 -
  281.60 -    @Override
  281.61 -    public void execute() throws MojoExecutionException {
  281.62 -        if (!classes.isDirectory()) {
  281.63 -            throw new MojoExecutionException("Can't find " + classes);
  281.64 -        }
  281.65 -
  281.66 -        if (javascript == null) {
  281.67 -            javascript = new File(findNonEmptyFolder(classes), "bootjava.js");
  281.68 -        }
  281.69 -
  281.70 -        List<String> arr = new ArrayList<String>();
  281.71 -        long newest = collectAllClasses("", classes, arr);
  281.72 -        
  281.73 -        if (javascript.lastModified() > newest) {
  281.74 -            return;
  281.75 -        }
  281.76 -
  281.77 -        try {
  281.78 -            URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
  281.79 -            FileWriter w = new FileWriter(javascript);
  281.80 -            Bck2Brwsr.generate(w, url, arr.toArray(new String[0]));
  281.81 -            w.close();
  281.82 -        } catch (IOException ex) {
  281.83 -            throw new MojoExecutionException("Can't compile", ex);
  281.84 -        }
  281.85 -    }
  281.86 -
  281.87 -    private static File findNonEmptyFolder(File dir) throws MojoExecutionException {
  281.88 -        if (!dir.isDirectory()) {
  281.89 -            throw new MojoExecutionException("Not a directory " + dir);
  281.90 -        }
  281.91 -        File[] arr = dir.listFiles();
  281.92 -        if (arr.length == 1 && arr[0].isDirectory()) {
  281.93 -            return findNonEmptyFolder(arr[0]);
  281.94 -        }
  281.95 -        return dir;
  281.96 -    }
  281.97 -
  281.98 -    private static long collectAllClasses(String prefix, File toCheck, List<String> arr) {
  281.99 -        File[] files = toCheck.listFiles();
 281.100 -        if (files != null) {
 281.101 -            long newest = 0L;
 281.102 -            for (File f : files) {
 281.103 -                long lastModified = collectAllClasses(prefix + f.getName() + "/", f, arr);
 281.104 -                if (newest < lastModified) {
 281.105 -                    newest = lastModified;
 281.106 -                }
 281.107 -            }
 281.108 -            return newest;
 281.109 -        } else if (toCheck.getName().endsWith(".class")) {
 281.110 -            arr.add(prefix.substring(0, prefix.length() - 7));
 281.111 -            return toCheck.lastModified();
 281.112 -        } else {
 281.113 -            return 0L;
 281.114 -        }
 281.115 -    }
 281.116 -
 281.117 -    private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
 281.118 -        List<URL> arr = new ArrayList<URL>();
 281.119 -        arr.add(root.toURI().toURL());
 281.120 -        for (Artifact a : deps) {
 281.121 -            arr.add(a.getFile().toURI().toURL());
 281.122 -        }
 281.123 -        return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
 281.124 -    }
 281.125 -}
   282.1 --- a/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml	Mon Feb 25 19:00:08 2013 +0100
   282.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   282.3 @@ -1,55 +0,0 @@
   282.4 -<?xml version="1.0" encoding="UTF-8"?>
   282.5 -<!--
   282.6 -
   282.7 -    Back 2 Browser Bytecode Translator
   282.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   282.9 -
  282.10 -    This program is free software: you can redistribute it and/or modify
  282.11 -    it under the terms of the GNU General Public License as published by
  282.12 -    the Free Software Foundation, version 2 of the License.
  282.13 -
  282.14 -    This program is distributed in the hope that it will be useful,
  282.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
  282.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  282.17 -    GNU General Public License for more details.
  282.18 -
  282.19 -    You should have received a copy of the GNU General Public License
  282.20 -    along with this program. Look for COPYING file in the top folder.
  282.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
  282.22 -
  282.23 --->
  282.24 -<archetype-descriptor name="bck2brwsr">
  282.25 -  <fileSets>
  282.26 -    <fileSet filtered="true" packaged="true">
  282.27 -      <directory>src/main/java</directory>
  282.28 -      <includes>
  282.29 -        <include>**/App.java</include>
  282.30 -      </includes>
  282.31 -    </fileSet>
  282.32 -    <fileSet filtered="true" packaged="true">
  282.33 -      <directory>src/main/resources</directory>
  282.34 -      <includes>
  282.35 -        <include>**/*.xhtml</include>
  282.36 -        <include>**/*.html</include>
  282.37 -      </includes>
  282.38 -    </fileSet>
  282.39 -    <fileSet filtered="true" packaged="true">
  282.40 -      <directory>src/test/java</directory>
  282.41 -      <includes>
  282.42 -        <include>**/*Test.java</include>
  282.43 -      </includes>
  282.44 -    </fileSet>
  282.45 -    <fileSet filtered="false" packaged="false">
  282.46 -      <directory></directory>
  282.47 -      <includes>
  282.48 -        <include>nbactions.xml</include>
  282.49 -      </includes>
  282.50 -    </fileSet>
  282.51 -    <fileSet filtered="true" packaged="false">
  282.52 -      <directory></directory>
  282.53 -      <includes>
  282.54 -        <include>bck2brwsr-assembly.xml</include>
  282.55 -      </includes>
  282.56 -    </fileSet>
  282.57 -  </fileSets>    
  282.58 -</archetype-descriptor>
  282.59 \ No newline at end of file
   283.1 --- a/mojo/src/main/resources/archetype-resources/bck2brwsr-assembly.xml	Mon Feb 25 19:00:08 2013 +0100
   283.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   283.3 @@ -1,61 +0,0 @@
   283.4 -<?xml version="1.0"?>
   283.5 -<!--
   283.6 -
   283.7 -    Back 2 Browser Bytecode Translator
   283.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   283.9 -
  283.10 -    This program is free software: you can redistribute it and/or modify
  283.11 -    it under the terms of the GNU General Public License as published by
  283.12 -    the Free Software Foundation, version 2 of the License.
  283.13 -
  283.14 -    This program is distributed in the hope that it will be useful,
  283.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
  283.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  283.17 -    GNU General Public License for more details.
  283.18 -
  283.19 -    You should have received a copy of the GNU General Public License
  283.20 -    along with this program. Look for COPYING file in the top folder.
  283.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
  283.22 -
  283.23 --->
  283.24 -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  283.25 -  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  283.26 -  
  283.27 -  <id>bck2brwsr</id>
  283.28 -  <formats>
  283.29 -      <format>zip</format>
  283.30 -  </formats>
  283.31 -  <baseDirectory>public_html</baseDirectory>
  283.32 -  <dependencySets>
  283.33 -    <dependencySet>
  283.34 -        <useProjectArtifact>false</useProjectArtifact>
  283.35 -        <scope>runtime</scope>
  283.36 -        <outputDirectory>lib</outputDirectory>
  283.37 -        <includes>
  283.38 -            <include>*:jar</include>
  283.39 -            <include>*:rt</include>
  283.40 -        </includes>
  283.41 -    </dependencySet>
  283.42 -    <dependencySet>
  283.43 -        <useProjectArtifact>false</useProjectArtifact>
  283.44 -        <scope>provided</scope>
  283.45 -        <includes>
  283.46 -            <include>*:js</include>
  283.47 -        </includes>
  283.48 -        <unpack>true</unpack>
  283.49 -        <outputDirectory>/</outputDirectory>
  283.50 -    </dependencySet>
  283.51 -  </dependencySets> 
  283.52 -  <files>
  283.53 -    <file>
  283.54 -      <source>${project.build.directory}/${project.build.finalName}.jar</source>
  283.55 -      <outputDirectory>/</outputDirectory>
  283.56 -    </file>
  283.57 -    <file>
  283.58 -      <source>${project.build.directory}/classes/${package.replace('.','/')}/index.html</source>
  283.59 -      <outputDirectory>/</outputDirectory>
  283.60 -      <destName>index.html</destName>
  283.61 -    </file>
  283.62 -  </files>
  283.63 -
  283.64 -</assembly>
  283.65 \ No newline at end of file
   284.1 --- a/mojo/src/main/resources/archetype-resources/nbactions.xml	Mon Feb 25 19:00:08 2013 +0100
   284.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   284.3 @@ -1,10 +0,0 @@
   284.4 -<?xml version="1.0" encoding="UTF-8"?>
   284.5 -<actions>
   284.6 -    <action>
   284.7 -        <actionName>run</actionName>
   284.8 -        <goals>
   284.9 -            <goal>process-classes</goal>
  284.10 -            <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
  284.11 -        </goals>
  284.12 -    </action>
  284.13 -</actions>
   285.1 --- a/mojo/src/main/resources/archetype-resources/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   285.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   285.3 @@ -1,135 +0,0 @@
   285.4 -<?xml version="1.0"?>
   285.5 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   285.6 -  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   285.7 -  <modelVersion>4.0.0</modelVersion>
   285.8 -
   285.9 -  <groupId>${groupId}</groupId>
  285.10 -  <artifactId>${artifactId}</artifactId>
  285.11 -  <version>${version}</version>
  285.12 -  <packaging>jar</packaging>
  285.13 -
  285.14 -  <name>${artifactId}</name>
  285.15 -
  285.16 -  <repositories>
  285.17 -      <repository>
  285.18 -          <id>java.net</id>
  285.19 -          <name>Java.net</name>
  285.20 -          <url>https://maven.java.net/content/repositories/snapshots/</url>
  285.21 -          <snapshots>
  285.22 -              <enabled>true</enabled>
  285.23 -          </snapshots>
  285.24 -      </repository>
  285.25 -      <repository>
  285.26 -          <id>netbeans</id>
  285.27 -          <name>NetBeans</name>
  285.28 -          <url>http://bits.netbeans.org/maven2/</url>
  285.29 -      </repository>
  285.30 -  </repositories>
  285.31 -  <pluginRepositories>
  285.32 -      <pluginRepository>
  285.33 -          <id>java.net</id>
  285.34 -          <name>Local Maven repository of releases</name>
  285.35 -          <url>https://maven.java.net/content/repositories/snapshots/</url>
  285.36 -          <snapshots>
  285.37 -              <enabled>true</enabled>
  285.38 -          </snapshots>
  285.39 -      </pluginRepository>
  285.40 -  </pluginRepositories>
  285.41 -
  285.42 -  <properties>
  285.43 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  285.44 -  </properties>
  285.45 -  <build>
  285.46 -      <plugins>
  285.47 -            <plugin>
  285.48 -                <groupId>org.apidesign.bck2brwsr</groupId>
  285.49 -                <artifactId>mojo</artifactId>
  285.50 -                <version>0.3-SNAPSHOT</version>
  285.51 -                <executions>
  285.52 -                    <execution>
  285.53 -                        <goals>
  285.54 -                            <goal>brwsr</goal>
  285.55 -                        </goals>
  285.56 -                    </execution>
  285.57 -                </executions>
  285.58 -                <configuration>
  285.59 -                    <startpage>${package.replace('.','/')}/index.html</startpage>
  285.60 -                </configuration>
  285.61 -            </plugin>
  285.62 -         <plugin>
  285.63 -            <groupId>org.apache.maven.plugins</groupId>
  285.64 -            <artifactId>maven-compiler-plugin</artifactId>
  285.65 -            <version>2.3.2</version>
  285.66 -            <configuration>
  285.67 -               <source>1.7</source>
  285.68 -               <target>1.7</target>
  285.69 -            </configuration>
  285.70 -         </plugin>
  285.71 -         <plugin>
  285.72 -             <groupId>org.apache.maven.plugins</groupId>
  285.73 -             <artifactId>maven-jar-plugin</artifactId>
  285.74 -             <version>2.4</version>
  285.75 -             <configuration>
  285.76 -                 <archive>
  285.77 -                     <manifest>
  285.78 -                         <addClasspath>true</addClasspath>
  285.79 -                         <classpathPrefix>lib/</classpathPrefix>
  285.80 -                     </manifest>
  285.81 -                 </archive>
  285.82 -             </configuration>
  285.83 -         </plugin>
  285.84 -         <plugin>
  285.85 -             <artifactId>maven-assembly-plugin</artifactId>
  285.86 -             <version>2.4</version>
  285.87 -             <executions>
  285.88 -                 <execution>
  285.89 -                     <id>distro-assembly</id>
  285.90 -                     <phase>package</phase>
  285.91 -                     <goals>
  285.92 -                         <goal>single</goal>
  285.93 -                     </goals>
  285.94 -                     <configuration>
  285.95 -                         <descriptors>
  285.96 -                             <descriptor>bck2brwsr-assembly.xml</descriptor>
  285.97 -                         </descriptors>
  285.98 -                     </configuration>
  285.99 -                 </execution>
 285.100 -             </executions>                
 285.101 -         </plugin>      
 285.102 -      </plugins>
 285.103 -  </build>
 285.104 -
 285.105 -  <dependencies>
 285.106 -    <dependency>
 285.107 -      <groupId>org.apidesign.bck2brwsr</groupId>
 285.108 -      <artifactId>emul</artifactId>
 285.109 -      <version>0.3-SNAPSHOT</version>
 285.110 -      <classifier>rt</classifier>
 285.111 -    </dependency>
 285.112 -    <dependency>
 285.113 -      <groupId>org.apidesign.bck2brwsr</groupId>
 285.114 -      <artifactId>javaquery.api</artifactId>
 285.115 -      <version>0.3-SNAPSHOT</version>
 285.116 -    </dependency>
 285.117 -    <dependency>
 285.118 -      <groupId>org.testng</groupId>
 285.119 -      <artifactId>testng</artifactId>
 285.120 -      <version>6.5.2</version>
 285.121 -      <scope>test</scope>
 285.122 -    </dependency>
 285.123 -    <dependency>
 285.124 -      <groupId>org.apidesign.bck2brwsr</groupId>
 285.125 -      <artifactId>vm4brwsr</artifactId>
 285.126 -      <classifier>js</classifier>
 285.127 -      <type>zip</type>
 285.128 -      <version>0.3-SNAPSHOT</version>
 285.129 -      <scope>provided</scope>
 285.130 -    </dependency>
 285.131 -    <dependency>
 285.132 -      <groupId>org.apidesign.bck2brwsr</groupId>
 285.133 -      <artifactId>vmtest</artifactId>
 285.134 -      <version>0.3-SNAPSHOT</version>
 285.135 -      <scope>test</scope>
 285.136 -    </dependency>
 285.137 -  </dependencies>
 285.138 -</project>
   286.1 --- a/mojo/src/main/resources/archetype-resources/src/main/java/App.java	Mon Feb 25 19:00:08 2013 +0100
   286.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   286.3 @@ -1,34 +0,0 @@
   286.4 -package ${package};
   286.5 -
   286.6 -import org.apidesign.bck2brwsr.htmlpage.api.*;
   286.7 -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   286.8 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
   286.9 -import org.apidesign.bck2brwsr.htmlpage.api.Property;
  286.10 -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  286.11 -
  286.12 -/** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
  286.13 - * Use this class to define behavior of the elements.
  286.14 - */
  286.15 -@Page(xhtml="index.html", className="Index", properties={
  286.16 -    @Property(name="name", type=String.class)
  286.17 -})
  286.18 -public class App {
  286.19 -    static {
  286.20 -        Index model = new Index();
  286.21 -        model.setName("World");
  286.22 -        model.applyBindings();
  286.23 -    }
  286.24 -    
  286.25 -    @On(event = CLICK, id="hello")
  286.26 -    static void hello(Index m) {
  286.27 -        GraphicsContext g = m.CANVAS.getContext();
  286.28 -        g.clearRect(0, 0, 1000, 1000);
  286.29 -        g.setFont("italic 40px Calibri");
  286.30 -        g.fillText(m.getHelloMessage(), 10, 40);
  286.31 -    }
  286.32 -    
  286.33 -    @ComputedProperty
  286.34 -    static String helloMessage(String name) {
  286.35 -        return "Hello " + name + "!";
  286.36 -    }
  286.37 -}
   287.1 --- a/mojo/src/main/resources/archetype-resources/src/main/resources/index.html	Mon Feb 25 19:00:08 2013 +0100
   287.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   287.3 @@ -1,22 +0,0 @@
   287.4 -<?xml version="1.0" encoding="UTF-8"?>
   287.5 -<!DOCTYPE html>
   287.6 -<html xmlns="http://www.w3.org/1999/xhtml">
   287.7 -    <head>
   287.8 -        <title>Bck2Brwsr's Hello World</title>
   287.9 -    </head>
  287.10 -    <body>
  287.11 -        <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
  287.12 -        Your name: <input id='input' data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
  287.13 -        <button id="hello">Say Hello!</button>
  287.14 -        <p>
  287.15 -            <canvas id="canvas" width="300" height="50">
  287.16 -            </canvas>
  287.17 -        </p>
  287.18 -
  287.19 -        <script src="bck2brwsr.js"></script>
  287.20 -        <script type="text/javascript">
  287.21 -            var vm = bck2brwsr('${artifactId}-${version}.jar');
  287.22 -            vm.loadClass('${package}.App');
  287.23 -        </script>
  287.24 -    </body>
  287.25 -</html>
   288.1 --- a/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java	Mon Feb 25 19:00:08 2013 +0100
   288.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   288.3 @@ -1,26 +0,0 @@
   288.4 -package ${package};
   288.5 -
   288.6 -import static org.testng.Assert.*;
   288.7 -import org.testng.annotations.BeforeMethod;
   288.8 -import org.testng.annotations.Test;
   288.9 -
  288.10 -/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot
  288.11 - * as it does not reference any HTML elements or browser functionality. Just
  288.12 - * operates on the page model.
  288.13 - *
  288.14 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  288.15 - */
  288.16 -public class AppTest {
  288.17 -    private Index model;
  288.18 -    
  288.19 -
  288.20 -    @BeforeMethod
  288.21 -    public void initModel() {
  288.22 -        model = new Index().applyBindings();
  288.23 -    }
  288.24 -
  288.25 -    @Test public void testHelloMessage() {
  288.26 -        model.setName("Joe");
  288.27 -        assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +");
  288.28 -    }
  288.29 -}
   289.1 --- a/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java	Mon Feb 25 19:00:08 2013 +0100
   289.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   289.3 @@ -1,40 +0,0 @@
   289.4 -package ${package};
   289.5 -
   289.6 -import org.apidesign.bck2brwsr.vmtest.Compare;
   289.7 -import org.apidesign.bck2brwsr.vmtest.VMTest;
   289.8 -import org.testng.annotations.Factory;
   289.9 -
  289.10 -/** Bck2brwsr cares about compatibility with real Java. Whatever API is
  289.11 - * supported by bck2brwsr, it needs to behave the same way as when running
  289.12 - * in HotSpot VM. 
  289.13 - * <p>
  289.14 - * There can be bugs, however. To help us fix them, we kindly ask you to 
  289.15 - * write an "inconsistency" test. A test that compares behavior of the API
  289.16 - * between real VM and bck2brwsr VM. This class is skeleton of such test.
  289.17 - *
  289.18 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  289.19 - */
  289.20 -public class InconsistencyTest {
  289.21 -    /** A method to demonstrate inconsistency between bck2brwsr and HotSpot.
  289.22 -     * Make calls to an API that behaves strangely, return some result at
  289.23 -     * the end. No need to use any <code>assert</code>.
  289.24 -     * 
  289.25 -     * @return value to compare between HotSpot and bck2brwsr
  289.26 -     */
  289.27 -    @Compare
  289.28 -    public int checkStringHashCode() throws Exception {
  289.29 -        return "Is string hashCode the same?".hashCode();
  289.30 -    }
  289.31 -
  289.32 -    /** Factory method that creates a three tests for each method annotated with
  289.33 -     * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in
  289.34 -     * HotSpot, one in Rhino and the last one compares the results.
  289.35 -     * 
  289.36 -     * @see org.apidesign.bck2brwsr.vmtest.VMTest
  289.37 -     */
  289.38 -    @Factory
  289.39 -    public static Object[] create() {
  289.40 -        return VMTest.create(InconsistencyTest.class);
  289.41 -    }
  289.42 -    
  289.43 -}
   290.1 --- a/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java	Mon Feb 25 19:00:08 2013 +0100
   290.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   290.3 @@ -1,46 +0,0 @@
   290.4 -package ${package};
   290.5 -
   290.6 -import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
   290.7 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
   290.8 -import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
   290.9 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  290.10 -import org.testng.annotations.Factory;
  290.11 -
  290.12 -/** Sometimes it is useful to run tests inside of the real browser. 
  290.13 - * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
  290.14 - * and that is it. If your code references elements on the HTML page,
  290.15 - * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
  290.16 - * will be made available on the page before your test starts.
  290.17 - *
  290.18 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  290.19 - */
  290.20 -public class IntegrationTest {
  290.21 -    
  290.22 -    /** Write to testing code here. Use <code>assert</code> (but not TestNG's
  290.23 -     * Assert, as TestNG is not compiled with target 1.6 yet).
  290.24 -     */
  290.25 -    @HtmlFragment(
  290.26 -        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
  290.27 -        "Your name: <input id='input' data-bind=\"value: name, valueUpdate: 'afterkeydown'\"></input>\n" +
  290.28 -        "<button id=\"hello\">Say Hello!</button>\n" +
  290.29 -        "<p>\n" +
  290.30 -        "    <canvas id=\"canvas\" width=\"300\" height=\"50\"></canvas>\n" +
  290.31 -        "</p>\n"
  290.32 -    )
  290.33 -    @BrwsrTest
  290.34 -    public void modifyValueAssertChangeInModel() {
  290.35 -        Index m = new Index();
  290.36 -        m.setName("Joe Hacker");
  290.37 -        m.applyBindings();
  290.38 -        assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue();
  290.39 -        m.INPUT.setValue("Happy Joe");
  290.40 -        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
  290.41 -        assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName();
  290.42 -    }
  290.43 -
  290.44 -    @Factory
  290.45 -    public static Object[] create() {
  290.46 -        return VMTest.create(IntegrationTest.class);
  290.47 -    }
  290.48 -    
  290.49 -}
   291.1 --- a/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   291.2 +++ b/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   291.3 @@ -12,17 +12,11 @@
   291.4      <version>3</version>
   291.5    </parent>  
   291.6    <modules>
   291.7 -    <module>vm</module>
   291.8 -    <module>emul</module>
   291.9 -    <module>core</module>
  291.10      <module>dew</module>
  291.11 -    <module>mojo</module>
  291.12      <module>javaquery</module>
  291.13 -    <module>javap</module>
  291.14      <module>benchmarks</module>
  291.15 -    <module>launcher</module>
  291.16 -    <module>vmtest</module>
  291.17      <module>ide</module>
  291.18 +    <module>rt</module>
  291.19    </modules>
  291.20    <licenses>
  291.21        <license>
  291.22 @@ -81,13 +75,13 @@
  291.23                    <header>COPYING</header>
  291.24                    <strictCheck>true</strictCheck>
  291.25                    <excludes>
  291.26 -                       <exclude>emul/*/src/main/**</exclude>
  291.27 -                       <exclude>javap/**</exclude>
  291.28                         <exclude>*</exclude>
  291.29                         <exclude>.*/**</exclude>
  291.30 -                       <exclude>mojo/src/main/resources/archetype-resources/**</exclude>
  291.31 +                       <exclude>rt/emul/*/src/main/**</exclude>
  291.32 +                       <exclude>rt/javap/**</exclude>
  291.33 +                       <exclude>rt/mojo/src/main/resources/archetype-resources/**</exclude>
  291.34 +                       <exclude>rt/vmtest/src/test/resources/**</exclude>
  291.35                         <exclude>dew/src/main/resources/org/apidesign/bck2brwsr/dew/**</exclude>
  291.36 -                       <exclude>vmtest/src/test/resources/**</exclude>
  291.37                         <exclude>javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout*.js</exclude>
  291.38                    </excludes>
  291.39                </configuration>
   292.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   292.2 +++ b/rt/core/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   292.3 @@ -0,0 +1,46 @@
   292.4 +<?xml version="1.0"?>
   292.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"
   292.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   292.7 +  <modelVersion>4.0.0</modelVersion>
   292.8 +  <parent>
   292.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  292.10 +    <artifactId>rt</artifactId>
  292.11 +    <version>0.3-SNAPSHOT</version>
  292.12 +  </parent>
  292.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  292.14 +  <artifactId>core</artifactId>
  292.15 +  <version>0.3-SNAPSHOT</version>
  292.16 +  <name>Bck2Brwsr Native Annotations</name>
  292.17 +  <url>http://maven.apache.org</url>
  292.18 +    <build>
  292.19 +        <plugins>
  292.20 +            <plugin>
  292.21 +                <groupId>org.apache.maven.plugins</groupId>
  292.22 +                <artifactId>maven-compiler-plugin</artifactId>
  292.23 +                <version>2.3.2</version>
  292.24 +                <configuration>
  292.25 +                    <source>1.7</source>
  292.26 +                    <target>1.7</target>
  292.27 +                </configuration>
  292.28 +            </plugin>
  292.29 +        </plugins>
  292.30 +    </build>
  292.31 +    <properties>
  292.32 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  292.33 +  </properties>
  292.34 +  <dependencies>
  292.35 +    <dependency>
  292.36 +      <groupId>junit</groupId>
  292.37 +      <artifactId>junit</artifactId>
  292.38 +      <version>3.8.1</version>
  292.39 +      <scope>test</scope>
  292.40 +    </dependency>
  292.41 +    <dependency>
  292.42 +      <groupId>org.netbeans.api</groupId>
  292.43 +      <artifactId>org-openide-util-lookup</artifactId>
  292.44 +      <scope>provided</scope>
  292.45 +    </dependency>
  292.46 +  </dependencies>
  292.47 +    <description>Contains esential annotations for associating JavaScript code with
  292.48 +methods and classes.</description>
  292.49 +</project>
   293.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   293.2 +++ b/rt/core/src/main/java/org/apidesign/bck2brwsr/core/ExtraJavaScript.java	Wed Feb 27 11:24:58 2013 +0100
   293.3 @@ -0,0 +1,36 @@
   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.core;
  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 +/**
  293.29 + *
  293.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  293.31 + */
  293.32 +@Retention(RetentionPolicy.CLASS)
  293.33 +@Target(ElementType.TYPE)
  293.34 +public @interface ExtraJavaScript {
  293.35 +    /** location of a script to load */
  293.36 +    String resource();
  293.37 +    /** should the class file still be processed or not? */
  293.38 +    boolean processByteCode() default true;
  293.39 +}
   294.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   294.2 +++ b/rt/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptBody.java	Wed Feb 27 11:24:58 2013 +0100
   294.3 @@ -0,0 +1,51 @@
   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.core;
  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 +/** Put this method on a method in case it should have a special
  294.29 + * body in the <em>JavaScript</em>.
  294.30 + *
  294.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  294.32 + */
  294.33 +@Retention(RetentionPolicy.CLASS)
  294.34 +@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
  294.35 +public @interface JavaScriptBody {
  294.36 +    /** Names of parameters for the method. 
  294.37 +     * 
  294.38 +     * <!--
  294.39 +     * If not specified
  294.40 +     * it will be <code>arg0, arg1, arg2</code>. In case of
  294.41 +     * instance methods, the <code>arg0</code> is reference
  294.42 +     * to <code>this</code>.
  294.43 +     * -->
  294.44 +     * 
  294.45 +     * @return array of the names of parameters for the method
  294.46 +     *    in JavaScript
  294.47 +     */
  294.48 +    public String[] args();
  294.49 +    
  294.50 +    /** The actual body of the method in JavaScript. This string will be
  294.51 +     * put into generated header (ends with '{') and footer (ends with '}').
  294.52 +     */
  294.53 +    public String body();
  294.54 +}
   295.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   295.2 +++ b/rt/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptOnly.java	Wed Feb 27 11:24:58 2013 +0100
   295.3 @@ -0,0 +1,37 @@
   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.core;
  295.22 +
  295.23 +import java.lang.annotation.ElementType;
  295.24 +import java.lang.annotation.Retention;
  295.25 +import java.lang.annotation.RetentionPolicy;
  295.26 +import java.lang.annotation.Target;
  295.27 +
  295.28 +/** Don't include given field or method in generated JavaScript. Rather
  295.29 + * generate completely independent JavaScript code.
  295.30 + *
  295.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  295.32 + */
  295.33 +@Retention(RetentionPolicy.CLASS)
  295.34 +@Target({ ElementType.METHOD, ElementType.FIELD })
  295.35 +public @interface JavaScriptOnly {
  295.36 +    /** name of the variable to assign given value to */
  295.37 +    String name() default "";
  295.38 +    /** value to assign to given field */
  295.39 +    String value() default "";
  295.40 +}
   296.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   296.2 +++ b/rt/core/src/main/java/org/apidesign/bck2brwsr/core/JavaScriptPrototype.java	Wed Feb 27 11:24:58 2013 +0100
   296.3 @@ -0,0 +1,44 @@
   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.core;
  296.22 +
  296.23 +import java.lang.annotation.ElementType;
  296.24 +import java.lang.annotation.Retention;
  296.25 +import java.lang.annotation.RetentionPolicy;
  296.26 +import java.lang.annotation.Target;
  296.27 +
  296.28 +/** Controls how JavaScript inheritance should be handled.
  296.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  296.30 + */
  296.31 +@Retention(RetentionPolicy.CLASS)
  296.32 +@Target({ ElementType.TYPE })
  296.33 +public @interface JavaScriptPrototype {
  296.34 +    /** Expression that identifies the function where all methods
  296.35 +     * should be added into. If this attribute is unspecified
  296.36 +     * all methods are added to the same object specified by
  296.37 +     * {@link #prototype()}.
  296.38 +     * 
  296.39 +     * @return name of function to contain methods found in given class
  296.40 +     */
  296.41 +    String container() default "";
  296.42 +    /** Expression that defines the way to construct prototype for this
  296.43 +     * class.
  296.44 +     * @return expression to construct prototype
  296.45 +     */
  296.46 +    String prototype();
  296.47 +}
   297.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   297.2 +++ b/rt/core/src/main/java/org/apidesign/bck2brwsr/core/impl/JavaScriptProcesor.java	Wed Feb 27 11:24:58 2013 +0100
   297.3 @@ -0,0 +1,100 @@
   297.4 +/**
   297.5 + * Back 2 Browser Bytecode Translator
   297.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   297.7 + *
   297.8 + * This program is free software: you can redistribute it and/or modify
   297.9 + * it under the terms of the GNU General Public License as published by
  297.10 + * the Free Software Foundation, version 2 of the License.
  297.11 + *
  297.12 + * This program is distributed in the hope that it will be useful,
  297.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  297.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  297.15 + * GNU General Public License for more details.
  297.16 + *
  297.17 + * You should have received a copy of the GNU General Public License
  297.18 + * along with this program. Look for COPYING file in the top folder.
  297.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  297.20 + */
  297.21 +package org.apidesign.bck2brwsr.core.impl;
  297.22 +
  297.23 +import java.util.Collections;
  297.24 +import java.util.HashSet;
  297.25 +import java.util.List;
  297.26 +import java.util.Set;
  297.27 +import javax.annotation.processing.AbstractProcessor;
  297.28 +import javax.annotation.processing.Completion;
  297.29 +import javax.annotation.processing.Completions;
  297.30 +import javax.annotation.processing.Messager;
  297.31 +import javax.annotation.processing.Processor;
  297.32 +import javax.annotation.processing.RoundEnvironment;
  297.33 +import javax.lang.model.element.AnnotationMirror;
  297.34 +import javax.lang.model.element.Element;
  297.35 +import javax.lang.model.element.ElementKind;
  297.36 +import javax.lang.model.element.ExecutableElement;
  297.37 +import javax.lang.model.element.TypeElement;
  297.38 +import javax.lang.model.element.VariableElement;
  297.39 +import javax.lang.model.type.TypeKind;
  297.40 +import javax.tools.Diagnostic;
  297.41 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  297.42 +import org.openide.util.lookup.ServiceProvider;
  297.43 +
  297.44 +/**
  297.45 + *
  297.46 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  297.47 + */
  297.48 +@ServiceProvider(service = Processor.class)
  297.49 +public final class JavaScriptProcesor extends AbstractProcessor {
  297.50 +    @Override
  297.51 +    public Set<String> getSupportedAnnotationTypes() {
  297.52 +        Set<String> set = new HashSet<>();
  297.53 +        set.add(JavaScriptBody.class.getName());
  297.54 +        return set;
  297.55 +    }
  297.56 +    
  297.57 +    @Override
  297.58 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  297.59 +        final Messager msg = processingEnv.getMessager();
  297.60 +        for (Element e : roundEnv.getElementsAnnotatedWith(JavaScriptBody.class)) {
  297.61 +            if (e.getKind() != ElementKind.METHOD && e.getKind() != ElementKind.CONSTRUCTOR) {
  297.62 +                continue;
  297.63 +            }
  297.64 +            ExecutableElement ee = (ExecutableElement)e;
  297.65 +            List<? extends VariableElement> params = ee.getParameters();
  297.66 +            
  297.67 +            JavaScriptBody jsb = e.getAnnotation(JavaScriptBody.class);
  297.68 +            if (jsb == null) {
  297.69 +                continue;
  297.70 +            }
  297.71 +            String[] arr = jsb.args();
  297.72 +            if (params.size() != arr.length) {
  297.73 +                msg.printMessage(Diagnostic.Kind.ERROR, "Number of args arguments does not match real arguments!", e);
  297.74 +            }
  297.75 +            if (ee.getReturnType().getKind() == TypeKind.LONG) {
  297.76 +                msg.printMessage(Diagnostic.Kind.WARNING, "Don't return long. Return double and convert it to long in Java code.", e);
  297.77 +            }
  297.78 +        }
  297.79 +        return true;
  297.80 +    }
  297.81 +
  297.82 +    @Override
  297.83 +    public Iterable<? extends Completion> getCompletions(Element e, 
  297.84 +        AnnotationMirror annotation, ExecutableElement member, String userText
  297.85 +    ) {
  297.86 +        StringBuilder sb = new StringBuilder();
  297.87 +        if (e.getKind() == ElementKind.METHOD && member.getSimpleName().contentEquals("args")) {
  297.88 +            ExecutableElement ee = (ExecutableElement) e;
  297.89 +            String sep = "";
  297.90 +            sb.append("{ ");
  297.91 +            for (VariableElement ve : ee.getParameters()) {
  297.92 +                sb.append(sep).append('"').append(ve.getSimpleName())
  297.93 +                    .append('"');
  297.94 +                sep = ", ";
  297.95 +            }
  297.96 +            sb.append(" }");
  297.97 +            return Collections.nCopies(1, Completions.of(sb.toString()));
  297.98 +        }
  297.99 +        return null;
 297.100 +    }
 297.101 +
 297.102 +    
 297.103 +}
   298.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   298.2 +++ b/rt/emul/compact/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   298.3 @@ -0,0 +1,72 @@
   298.4 +<?xml version="1.0"?>
   298.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"
   298.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   298.7 +  <modelVersion>4.0.0</modelVersion>
   298.8 +  <parent>
   298.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  298.10 +    <artifactId>emul.pom</artifactId>
  298.11 +    <version>0.3-SNAPSHOT</version>
  298.12 +  </parent>
  298.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  298.14 +  <artifactId>emul</artifactId>
  298.15 +  <version>0.3-SNAPSHOT</version>
  298.16 +  <name>Bck2Brwsr API Profile</name>
  298.17 +  <url>http://maven.apache.org</url>
  298.18 +  <properties>
  298.19 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  298.20 +  </properties>
  298.21 +  <dependencies>
  298.22 +    <dependency>
  298.23 +      <groupId>${project.groupId}</groupId>
  298.24 +      <artifactId>emul.mini</artifactId>
  298.25 +      <version>${project.version}</version>
  298.26 +      <scope>provided</scope>
  298.27 +    </dependency>
  298.28 +    <dependency>
  298.29 +      <groupId>${project.groupId}</groupId>
  298.30 +      <artifactId>vmtest</artifactId>
  298.31 +      <version>${project.version}</version>
  298.32 +      <scope>test</scope>
  298.33 +    </dependency>
  298.34 +    <dependency>
  298.35 +      <groupId>org.netbeans.api</groupId>
  298.36 +      <artifactId>org-openide-util-lookup</artifactId>
  298.37 +      <scope>test</scope>
  298.38 +    </dependency>
  298.39 +  </dependencies>
  298.40 +  <build>
  298.41 +      <plugins>
  298.42 +          <plugin>
  298.43 +              <groupId>org.apache.maven.plugins</groupId>
  298.44 +              <artifactId>maven-compiler-plugin</artifactId>
  298.45 +              <version>2.5.1</version>
  298.46 +              <configuration>
  298.47 +                  <compilerArguments>
  298.48 +                      <bootclasspath>netbeans.ignore.jdk.bootclasspath</bootclasspath>
  298.49 +                  </compilerArguments>
  298.50 +                 <source>1.7</source>
  298.51 +                 <target>1.7</target>
  298.52 +              </configuration>
  298.53 +          </plugin>
  298.54 +         <plugin>
  298.55 +            <artifactId>maven-assembly-plugin</artifactId>
  298.56 +                <version>2.4</version>
  298.57 +                <executions>
  298.58 +                    <execution>
  298.59 +                        <id>rt</id>
  298.60 +                        <phase>package</phase>
  298.61 +                        <goals>
  298.62 +                            <goal>single</goal>
  298.63 +                        </goals>
  298.64 +                        <configuration>
  298.65 +                            <descriptors>
  298.66 +                                <descriptor>src/main/assembly/rt.xml</descriptor>
  298.67 +                            </descriptors>
  298.68 +                            <finalName>bck2brwsr-${project.version}</finalName>
  298.69 +                        </configuration>
  298.70 +                    </execution>
  298.71 +                </executions>                
  298.72 +            </plugin>      
  298.73 +      </plugins>
  298.74 +  </build>
  298.75 +</project>
   299.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   299.2 +++ b/rt/emul/compact/src/main/assembly/rt.xml	Wed Feb 27 11:24:58 2013 +0100
   299.3 @@ -0,0 +1,26 @@
   299.4 +<?xml version="1.0"?>
   299.5 +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
   299.6 +  <id>rt</id>
   299.7 +  <formats>
   299.8 +    <format>jar</format>
   299.9 +  </formats>
  299.10 +  <includeBaseDirectory>false</includeBaseDirectory>
  299.11 +  <dependencySets>
  299.12 +    <dependencySet>
  299.13 +      <useProjectArtifact>true</useProjectArtifact>
  299.14 +      <unpack>true</unpack>
  299.15 +      <scope>provided</scope>
  299.16 +      <unpackOptions>
  299.17 +        <excludes>
  299.18 +          <exclude>META-INF/maven/**</exclude>
  299.19 +        </excludes>
  299.20 +      </unpackOptions>
  299.21 +    </dependencySet>
  299.22 +  </dependencySets>
  299.23 +  <fileSets>
  299.24 +    <fileSet>
  299.25 +      <directory>${project.build.outputDirectory}</directory>
  299.26 +      <outputDirectory>/</outputDirectory>
  299.27 +    </fileSet>
  299.28 +  </fileSets>
  299.29 +</assembly>
  299.30 \ No newline at end of file
   300.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   300.2 +++ b/rt/emul/compact/src/main/java/java/beans/ChangeListenerMap.java	Wed Feb 27 11:24:58 2013 +0100
   300.3 @@ -0,0 +1,248 @@
   300.4 +/*
   300.5 + * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   300.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   300.7 + *
   300.8 + * This code is free software; you can redistribute it and/or modify it
   300.9 + * under the terms of the GNU General Public License version 2 only, as
  300.10 + * published by the Free Software Foundation.  Oracle designates this
  300.11 + * particular file as subject to the "Classpath" exception as provided
  300.12 + * by Oracle in the LICENSE file that accompanied this code.
  300.13 + *
  300.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  300.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  300.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  300.17 + * version 2 for more details (a copy is included in the LICENSE file that
  300.18 + * accompanied this code).
  300.19 + *
  300.20 + * You should have received a copy of the GNU General Public License version
  300.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  300.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  300.23 + *
  300.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  300.25 + * or visit www.oracle.com if you need additional information or have any
  300.26 + * questions.
  300.27 + */
  300.28 +package java.beans;
  300.29 +
  300.30 +import java.util.ArrayList;
  300.31 +import java.util.Collections;
  300.32 +import java.util.EventListener;
  300.33 +import java.util.EventListenerProxy;
  300.34 +import java.util.HashMap;
  300.35 +import java.util.List;
  300.36 +import java.util.Map;
  300.37 +import java.util.Map.Entry;
  300.38 +import java.util.Set;
  300.39 +import org.apidesign.bck2brwsr.emul.lang.System;
  300.40 +
  300.41 +/**
  300.42 + * This is an abstract class that provides base functionality
  300.43 + * for the {@link PropertyChangeSupport PropertyChangeSupport} class
  300.44 + * and the {@link VetoableChangeSupport VetoableChangeSupport} class.
  300.45 + *
  300.46 + * @see PropertyChangeListenerMap
  300.47 + * @see VetoableChangeListenerMap
  300.48 + *
  300.49 + * @author Sergey A. Malenkov
  300.50 + */
  300.51 +abstract class ChangeListenerMap<L extends EventListener> {
  300.52 +    private Map<String, L[]> map;
  300.53 +
  300.54 +    /**
  300.55 +     * Creates an array of listeners.
  300.56 +     * This method can be optimized by using
  300.57 +     * the same instance of the empty array
  300.58 +     * when {@code length} is equal to {@code 0}.
  300.59 +     *
  300.60 +     * @param length  the array length
  300.61 +     * @return        an array with specified length
  300.62 +     */
  300.63 +    protected abstract L[] newArray(int length);
  300.64 +
  300.65 +    /**
  300.66 +     * Creates a proxy listener for the specified property.
  300.67 +     *
  300.68 +     * @param name      the name of the property to listen on
  300.69 +     * @param listener  the listener to process events
  300.70 +     * @return          a proxy listener
  300.71 +     */
  300.72 +    protected abstract L newProxy(String name, L listener);
  300.73 +
  300.74 +    /**
  300.75 +     * Adds a listener to the list of listeners for the specified property.
  300.76 +     * This listener is called as many times as it was added.
  300.77 +     *
  300.78 +     * @param name      the name of the property to listen on
  300.79 +     * @param listener  the listener to process events
  300.80 +     */
  300.81 +    public final synchronized void add(String name, L listener) {
  300.82 +        if (this.map == null) {
  300.83 +            this.map = new HashMap<String, L[]>();
  300.84 +        }
  300.85 +        L[] array = this.map.get(name);
  300.86 +        int size = (array != null)
  300.87 +                ? array.length
  300.88 +                : 0;
  300.89 +
  300.90 +        L[] clone = newArray(size + 1);
  300.91 +        clone[size] = listener;
  300.92 +        if (array != null) {
  300.93 +            System.arraycopy(array, 0, clone, 0, size);
  300.94 +        }
  300.95 +        this.map.put(name, clone);
  300.96 +    }
  300.97 +
  300.98 +    /**
  300.99 +     * Removes a listener from the list of listeners for the specified property.
 300.100 +     * If the listener was added more than once to the same event source,
 300.101 +     * this listener will be notified one less time after being removed.
 300.102 +     *
 300.103 +     * @param name      the name of the property to listen on
 300.104 +     * @param listener  the listener to process events
 300.105 +     */
 300.106 +    public final synchronized void remove(String name, L listener) {
 300.107 +        if (this.map != null) {
 300.108 +            L[] array = this.map.get(name);
 300.109 +            if (array != null) {
 300.110 +                for (int i = 0; i < array.length; i++) {
 300.111 +                    if (listener.equals(array[i])) {
 300.112 +                        int size = array.length - 1;
 300.113 +                        if (size > 0) {
 300.114 +                            L[] clone = newArray(size);
 300.115 +                            System.arraycopy(array, 0, clone, 0, i);
 300.116 +                            System.arraycopy(array, i + 1, clone, i, size - i);
 300.117 +                            this.map.put(name, clone);
 300.118 +                        }
 300.119 +                        else {
 300.120 +                            this.map.remove(name);
 300.121 +                            if (this.map.isEmpty()) {
 300.122 +                                this.map = null;
 300.123 +                            }
 300.124 +                        }
 300.125 +                        break;
 300.126 +                    }
 300.127 +                }
 300.128 +            }
 300.129 +        }
 300.130 +    }
 300.131 +
 300.132 +    /**
 300.133 +     * Returns the list of listeners for the specified property.
 300.134 +     *
 300.135 +     * @param name  the name of the property
 300.136 +     * @return      the corresponding list of listeners
 300.137 +     */
 300.138 +    public final synchronized L[] get(String name) {
 300.139 +        return (this.map != null)
 300.140 +                ? this.map.get(name)
 300.141 +                : null;
 300.142 +    }
 300.143 +
 300.144 +    /**
 300.145 +     * Sets new list of listeners for the specified property.
 300.146 +     *
 300.147 +     * @param name       the name of the property
 300.148 +     * @param listeners  new list of listeners
 300.149 +     */
 300.150 +    public final void set(String name, L[] listeners) {
 300.151 +        if (listeners != null) {
 300.152 +            if (this.map == null) {
 300.153 +                this.map = new HashMap<String, L[]>();
 300.154 +            }
 300.155 +            this.map.put(name, listeners);
 300.156 +        }
 300.157 +        else if (this.map != null) {
 300.158 +            this.map.remove(name);
 300.159 +            if (this.map.isEmpty()) {
 300.160 +                this.map = null;
 300.161 +            }
 300.162 +        }
 300.163 +    }
 300.164 +
 300.165 +    /**
 300.166 +     * Returns all listeners in the map.
 300.167 +     *
 300.168 +     * @return an array of all listeners
 300.169 +     */
 300.170 +    public final synchronized L[] getListeners() {
 300.171 +        if (this.map == null) {
 300.172 +            return newArray(0);
 300.173 +        }
 300.174 +        List<L> list = new ArrayList<L>();
 300.175 +
 300.176 +        L[] listeners = this.map.get(null);
 300.177 +        if (listeners != null) {
 300.178 +            for (L listener : listeners) {
 300.179 +                list.add(listener);
 300.180 +            }
 300.181 +        }
 300.182 +        for (Entry<String, L[]> entry : this.map.entrySet()) {
 300.183 +            String name = entry.getKey();
 300.184 +            if (name != null) {
 300.185 +                for (L listener : entry.getValue()) {
 300.186 +                    list.add(newProxy(name, listener));
 300.187 +                }
 300.188 +            }
 300.189 +        }
 300.190 +        return list.toArray(newArray(list.size()));
 300.191 +    }
 300.192 +
 300.193 +    /**
 300.194 +     * Returns listeners that have been associated with the named property.
 300.195 +     *
 300.196 +     * @param name  the name of the property
 300.197 +     * @return an array of listeners for the named property
 300.198 +     */
 300.199 +    public final L[] getListeners(String name) {
 300.200 +        if (name != null) {
 300.201 +            L[] listeners = get(name);
 300.202 +            if (listeners != null) {
 300.203 +                return listeners.clone();
 300.204 +            }
 300.205 +        }
 300.206 +        return newArray(0);
 300.207 +    }
 300.208 +
 300.209 +    /**
 300.210 +     * Indicates whether the map contains
 300.211 +     * at least one listener to be notified.
 300.212 +     *
 300.213 +     * @param name  the name of the property
 300.214 +     * @return      {@code true} if at least one listener exists or
 300.215 +     *              {@code false} otherwise
 300.216 +     */
 300.217 +    public final synchronized boolean hasListeners(String name) {
 300.218 +        if (this.map == null) {
 300.219 +            return false;
 300.220 +        }
 300.221 +        L[] array = this.map.get(null);
 300.222 +        return (array != null) || ((name != null) && (null != this.map.get(name)));
 300.223 +    }
 300.224 +
 300.225 +    /**
 300.226 +     * Returns a set of entries from the map.
 300.227 +     * Each entry is a pair consisted of the property name
 300.228 +     * and the corresponding list of listeners.
 300.229 +     *
 300.230 +     * @return a set of entries from the map
 300.231 +     */
 300.232 +    public final Set<Entry<String, L[]>> getEntries() {
 300.233 +        return (this.map != null)
 300.234 +                ? this.map.entrySet()
 300.235 +                : Collections.<Entry<String, L[]>>emptySet();
 300.236 +    }
 300.237 +
 300.238 +    /**
 300.239 +     * Extracts a real listener from the proxy listener.
 300.240 +     * It is necessary because default proxy class is not serializable.
 300.241 +     *
 300.242 +     * @return a real listener
 300.243 +     */
 300.244 +    public final L extract(L listener) {
 300.245 +        while (listener instanceof EventListenerProxy) {
 300.246 +            EventListenerProxy<L> proxy = (EventListenerProxy<L>) listener;
 300.247 +            listener = proxy.getListener();
 300.248 +        }
 300.249 +        return listener;
 300.250 +    }
 300.251 +}
   301.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   301.2 +++ b/rt/emul/compact/src/main/java/java/beans/IndexedPropertyChangeEvent.java	Wed Feb 27 11:24:58 2013 +0100
   301.3 @@ -0,0 +1,78 @@
   301.4 +/*
   301.5 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   301.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   301.7 + *
   301.8 + * This code is free software; you can redistribute it and/or modify it
   301.9 + * under the terms of the GNU General Public License version 2 only, as
  301.10 + * published by the Free Software Foundation.  Oracle designates this
  301.11 + * particular file as subject to the "Classpath" exception as provided
  301.12 + * by Oracle in the LICENSE file that accompanied this code.
  301.13 + *
  301.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  301.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  301.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  301.17 + * version 2 for more details (a copy is included in the LICENSE file that
  301.18 + * accompanied this code).
  301.19 + *
  301.20 + * You should have received a copy of the GNU General Public License version
  301.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  301.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  301.23 + *
  301.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  301.25 + * or visit www.oracle.com if you need additional information or have any
  301.26 + * questions.
  301.27 + */
  301.28 +package java.beans;
  301.29 +
  301.30 +/**
  301.31 + * An "IndexedPropertyChange" event gets delivered whenever a component that
  301.32 + * conforms to the JavaBeans&trade; specification (a "bean") changes a bound
  301.33 + * indexed property. This class is an extension of <code>PropertyChangeEvent</code>
  301.34 + * but contains the index of the property that has changed.
  301.35 + * <P>
  301.36 + * Null values may be provided for the old and the new values if their
  301.37 + * true values are not known.
  301.38 + * <P>
  301.39 + * An event source may send a null object as the name to indicate that an
  301.40 + * arbitrary set of if its properties have changed.  In this case the
  301.41 + * old and new values should also be null.
  301.42 + *
  301.43 + * @since 1.5
  301.44 + * @author Mark Davidson
  301.45 + */
  301.46 +public class IndexedPropertyChangeEvent extends PropertyChangeEvent {
  301.47 +    private static final long serialVersionUID = -320227448495806870L;
  301.48 +
  301.49 +    private int index;
  301.50 +
  301.51 +    /**
  301.52 +     * Constructs a new <code>IndexedPropertyChangeEvent</code> object.
  301.53 +     *
  301.54 +     * @param source  The bean that fired the event.
  301.55 +     * @param propertyName  The programmatic name of the property that
  301.56 +     *             was changed.
  301.57 +     * @param oldValue      The old value of the property.
  301.58 +     * @param newValue      The new value of the property.
  301.59 +     * @param index index of the property element that was changed.
  301.60 +     */
  301.61 +    public IndexedPropertyChangeEvent(Object source, String propertyName,
  301.62 +                                      Object oldValue, Object newValue,
  301.63 +                                      int index) {
  301.64 +        super (source, propertyName, oldValue, newValue);
  301.65 +        this.index = index;
  301.66 +    }
  301.67 +
  301.68 +    /**
  301.69 +     * Gets the index of the property that was changed.
  301.70 +     *
  301.71 +     * @return The index specifying the property element that was
  301.72 +     *         changed.
  301.73 +     */
  301.74 +    public int getIndex() {
  301.75 +        return index;
  301.76 +    }
  301.77 +
  301.78 +    void appendTo(StringBuilder sb) {
  301.79 +        sb.append("; index=").append(getIndex());
  301.80 +    }
  301.81 +}
   302.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   302.2 +++ b/rt/emul/compact/src/main/java/java/beans/PropertyChangeEvent.java	Wed Feb 27 11:24:58 2013 +0100
   302.3 @@ -0,0 +1,164 @@
   302.4 +/*
   302.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   302.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   302.7 + *
   302.8 + * This code is free software; you can redistribute it and/or modify it
   302.9 + * under the terms of the GNU General Public License version 2 only, as
  302.10 + * published by the Free Software Foundation.  Oracle designates this
  302.11 + * particular file as subject to the "Classpath" exception as provided
  302.12 + * by Oracle in the LICENSE file that accompanied this code.
  302.13 + *
  302.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  302.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  302.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  302.17 + * version 2 for more details (a copy is included in the LICENSE file that
  302.18 + * accompanied this code).
  302.19 + *
  302.20 + * You should have received a copy of the GNU General Public License version
  302.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  302.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  302.23 + *
  302.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  302.25 + * or visit www.oracle.com if you need additional information or have any
  302.26 + * questions.
  302.27 + */
  302.28 +
  302.29 +package java.beans;
  302.30 +
  302.31 +/**
  302.32 + * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
  302.33 + * or "constrained" property.  A PropertyChangeEvent object is sent as an
  302.34 + * argument to the PropertyChangeListener and VetoableChangeListener methods.
  302.35 + * <P>
  302.36 + * Normally PropertyChangeEvents are accompanied by the name and the old
  302.37 + * and new value of the changed property.  If the new value is a primitive
  302.38 + * type (such as int or boolean) it must be wrapped as the
  302.39 + * corresponding java.lang.* Object type (such as Integer or Boolean).
  302.40 + * <P>
  302.41 + * Null values may be provided for the old and the new values if their
  302.42 + * true values are not known.
  302.43 + * <P>
  302.44 + * An event source may send a null object as the name to indicate that an
  302.45 + * arbitrary set of if its properties have changed.  In this case the
  302.46 + * old and new values should also be null.
  302.47 + */
  302.48 +
  302.49 +public class PropertyChangeEvent extends java.util.EventObject {
  302.50 +    private static final long serialVersionUID = 7042693688939648123L;
  302.51 +
  302.52 +    /**
  302.53 +     * Constructs a new <code>PropertyChangeEvent</code>.
  302.54 +     *
  302.55 +     * @param source  The bean that fired the event.
  302.56 +     * @param propertyName  The programmatic name of the property
  302.57 +     *          that was changed.
  302.58 +     * @param oldValue  The old value of the property.
  302.59 +     * @param newValue  The new value of the property.
  302.60 +     */
  302.61 +    public PropertyChangeEvent(Object source, String propertyName,
  302.62 +                                     Object oldValue, Object newValue) {
  302.63 +        super(source);
  302.64 +        this.propertyName = propertyName;
  302.65 +        this.newValue = newValue;
  302.66 +        this.oldValue = oldValue;
  302.67 +    }
  302.68 +
  302.69 +    /**
  302.70 +     * Gets the programmatic name of the property that was changed.
  302.71 +     *
  302.72 +     * @return  The programmatic name of the property that was changed.
  302.73 +     *          May be null if multiple properties have changed.
  302.74 +     */
  302.75 +    public String getPropertyName() {
  302.76 +        return propertyName;
  302.77 +    }
  302.78 +
  302.79 +    /**
  302.80 +     * Gets the new value for the property, expressed as an Object.
  302.81 +     *
  302.82 +     * @return  The new value for the property, expressed as an Object.
  302.83 +     *          May be null if multiple properties have changed.
  302.84 +     */
  302.85 +    public Object getNewValue() {
  302.86 +        return newValue;
  302.87 +    }
  302.88 +
  302.89 +    /**
  302.90 +     * Gets the old value for the property, expressed as an Object.
  302.91 +     *
  302.92 +     * @return  The old value for the property, expressed as an Object.
  302.93 +     *          May be null if multiple properties have changed.
  302.94 +     */
  302.95 +    public Object getOldValue() {
  302.96 +        return oldValue;
  302.97 +    }
  302.98 +
  302.99 +    /**
 302.100 +     * Sets the propagationId object for the event.
 302.101 +     *
 302.102 +     * @param propagationId  The propagationId object for the event.
 302.103 +     */
 302.104 +    public void setPropagationId(Object propagationId) {
 302.105 +        this.propagationId = propagationId;
 302.106 +    }
 302.107 +
 302.108 +    /**
 302.109 +     * The "propagationId" field is reserved for future use.  In Beans 1.0
 302.110 +     * the sole requirement is that if a listener catches a PropertyChangeEvent
 302.111 +     * and then fires a PropertyChangeEvent of its own, then it should
 302.112 +     * make sure that it propagates the propagationId field from its
 302.113 +     * incoming event to its outgoing event.
 302.114 +     *
 302.115 +     * @return the propagationId object associated with a bound/constrained
 302.116 +     *          property update.
 302.117 +     */
 302.118 +    public Object getPropagationId() {
 302.119 +        return propagationId;
 302.120 +    }
 302.121 +
 302.122 +    /**
 302.123 +     * name of the property that changed.  May be null, if not known.
 302.124 +     * @serial
 302.125 +     */
 302.126 +    private String propertyName;
 302.127 +
 302.128 +    /**
 302.129 +     * New value for property.  May be null if not known.
 302.130 +     * @serial
 302.131 +     */
 302.132 +    private Object newValue;
 302.133 +
 302.134 +    /**
 302.135 +     * Previous value for property.  May be null if not known.
 302.136 +     * @serial
 302.137 +     */
 302.138 +    private Object oldValue;
 302.139 +
 302.140 +    /**
 302.141 +     * Propagation ID.  May be null.
 302.142 +     * @serial
 302.143 +     * @see #getPropagationId
 302.144 +     */
 302.145 +    private Object propagationId;
 302.146 +
 302.147 +    /**
 302.148 +     * Returns a string representation of the object.
 302.149 +     *
 302.150 +     * @return a string representation of the object
 302.151 +     *
 302.152 +     * @since 1.7
 302.153 +     */
 302.154 +    public String toString() {
 302.155 +        StringBuilder sb = new StringBuilder(getClass().getName());
 302.156 +        sb.append("[propertyName=").append(getPropertyName());
 302.157 +        appendTo(sb);
 302.158 +        sb.append("; oldValue=").append(getOldValue());
 302.159 +        sb.append("; newValue=").append(getNewValue());
 302.160 +        sb.append("; propagationId=").append(getPropagationId());
 302.161 +        sb.append("; source=").append(getSource());
 302.162 +        return sb.append("]").toString();
 302.163 +    }
 302.164 +
 302.165 +    void appendTo(StringBuilder sb) {
 302.166 +    }
 302.167 +}
   303.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   303.2 +++ b/rt/emul/compact/src/main/java/java/beans/PropertyChangeListener.java	Wed Feb 27 11:24:58 2013 +0100
   303.3 @@ -0,0 +1,44 @@
   303.4 +/*
   303.5 + * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved.
   303.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   303.7 + *
   303.8 + * This code is free software; you can redistribute it and/or modify it
   303.9 + * under the terms of the GNU General Public License version 2 only, as
  303.10 + * published by the Free Software Foundation.  Oracle designates this
  303.11 + * particular file as subject to the "Classpath" exception as provided
  303.12 + * by Oracle in the LICENSE file that accompanied this code.
  303.13 + *
  303.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  303.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  303.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  303.17 + * version 2 for more details (a copy is included in the LICENSE file that
  303.18 + * accompanied this code).
  303.19 + *
  303.20 + * You should have received a copy of the GNU General Public License version
  303.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  303.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  303.23 + *
  303.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  303.25 + * or visit www.oracle.com if you need additional information or have any
  303.26 + * questions.
  303.27 + */
  303.28 +
  303.29 +package java.beans;
  303.30 +
  303.31 +/**
  303.32 + * A "PropertyChange" event gets fired whenever a bean changes a "bound"
  303.33 + * property.  You can register a PropertyChangeListener with a source
  303.34 + * bean so as to be notified of any bound property updates.
  303.35 + */
  303.36 +
  303.37 +public interface PropertyChangeListener extends java.util.EventListener {
  303.38 +
  303.39 +    /**
  303.40 +     * This method gets called when a bound property is changed.
  303.41 +     * @param evt A PropertyChangeEvent object describing the event source
  303.42 +     *          and the property that has changed.
  303.43 +     */
  303.44 +
  303.45 +    void propertyChange(PropertyChangeEvent evt);
  303.46 +
  303.47 +}
   304.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   304.2 +++ b/rt/emul/compact/src/main/java/java/beans/PropertyChangeListenerProxy.java	Wed Feb 27 11:24:58 2013 +0100
   304.3 @@ -0,0 +1,81 @@
   304.4 +/*
   304.5 + * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
   304.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   304.7 + *
   304.8 + * This code is free software; you can redistribute it and/or modify it
   304.9 + * under the terms of the GNU General Public License version 2 only, as
  304.10 + * published by the Free Software Foundation.  Oracle designates this
  304.11 + * particular file as subject to the "Classpath" exception as provided
  304.12 + * by Oracle in the LICENSE file that accompanied this code.
  304.13 + *
  304.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  304.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  304.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  304.17 + * version 2 for more details (a copy is included in the LICENSE file that
  304.18 + * accompanied this code).
  304.19 + *
  304.20 + * You should have received a copy of the GNU General Public License version
  304.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  304.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  304.23 + *
  304.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  304.25 + * or visit www.oracle.com if you need additional information or have any
  304.26 + * questions.
  304.27 + */
  304.28 +
  304.29 +package java.beans;
  304.30 +
  304.31 +import java.util.EventListenerProxy;
  304.32 +
  304.33 +/**
  304.34 + * A class which extends the {@code EventListenerProxy}
  304.35 + * specifically for adding a {@code PropertyChangeListener}
  304.36 + * with a "bound" property.
  304.37 + * Instances of this class can be added
  304.38 + * as {@code PropertyChangeListener}s to a bean
  304.39 + * which supports firing property change events.
  304.40 + * <p>
  304.41 + * If the object has a {@code getPropertyChangeListeners} method
  304.42 + * then the array returned could be a mixture of {@code PropertyChangeListener}
  304.43 + * and {@code PropertyChangeListenerProxy} objects.
  304.44 + *
  304.45 + * @see java.util.EventListenerProxy
  304.46 + * @see PropertyChangeSupport#getPropertyChangeListeners
  304.47 + * @since 1.4
  304.48 + */
  304.49 +public class PropertyChangeListenerProxy
  304.50 +        extends EventListenerProxy<PropertyChangeListener>
  304.51 +        implements PropertyChangeListener {
  304.52 +
  304.53 +    private final String propertyName;
  304.54 +
  304.55 +    /**
  304.56 +     * Constructor which binds the {@code PropertyChangeListener}
  304.57 +     * to a specific property.
  304.58 +     *
  304.59 +     * @param propertyName  the name of the property to listen on
  304.60 +     * @param listener      the listener object
  304.61 +     */
  304.62 +    public PropertyChangeListenerProxy(String propertyName, PropertyChangeListener listener) {
  304.63 +        super(listener);
  304.64 +        this.propertyName = propertyName;
  304.65 +    }
  304.66 +
  304.67 +    /**
  304.68 +     * Forwards the property change event to the listener delegate.
  304.69 +     *
  304.70 +     * @param event  the property change event
  304.71 +     */
  304.72 +    public void propertyChange(PropertyChangeEvent event) {
  304.73 +        getListener().propertyChange(event);
  304.74 +    }
  304.75 +
  304.76 +    /**
  304.77 +     * Returns the name of the named property associated with the listener.
  304.78 +     *
  304.79 +     * @return the name of the named property associated with the listener
  304.80 +     */
  304.81 +    public String getPropertyName() {
  304.82 +        return this.propertyName;
  304.83 +    }
  304.84 +}
   305.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   305.2 +++ b/rt/emul/compact/src/main/java/java/beans/PropertyChangeSupport.java	Wed Feb 27 11:24:58 2013 +0100
   305.3 @@ -0,0 +1,536 @@
   305.4 +/*
   305.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   305.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   305.7 + *
   305.8 + * This code is free software; you can redistribute it and/or modify it
   305.9 + * under the terms of the GNU General Public License version 2 only, as
  305.10 + * published by the Free Software Foundation.  Oracle designates this
  305.11 + * particular file as subject to the "Classpath" exception as provided
  305.12 + * by Oracle in the LICENSE file that accompanied this code.
  305.13 + *
  305.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  305.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  305.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  305.17 + * version 2 for more details (a copy is included in the LICENSE file that
  305.18 + * accompanied this code).
  305.19 + *
  305.20 + * You should have received a copy of the GNU General Public License version
  305.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  305.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  305.23 + *
  305.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  305.25 + * or visit www.oracle.com if you need additional information or have any
  305.26 + * questions.
  305.27 + */
  305.28 +package java.beans;
  305.29 +
  305.30 +import java.io.Serializable;
  305.31 +import java.io.ObjectStreamField;
  305.32 +import java.io.ObjectOutputStream;
  305.33 +import java.io.ObjectInputStream;
  305.34 +import java.io.IOException;
  305.35 +import java.util.Hashtable;
  305.36 +import java.util.Map.Entry;
  305.37 +
  305.38 +/**
  305.39 + * This is a utility class that can be used by beans that support bound
  305.40 + * properties.  It manages a list of listeners and dispatches
  305.41 + * {@link PropertyChangeEvent}s to them.  You can use an instance of this class
  305.42 + * as a member field of your bean and delegate these types of work to it.
  305.43 + * The {@link PropertyChangeListener} can be registered for all properties
  305.44 + * or for a property specified by name.
  305.45 + * <p>
  305.46 + * Here is an example of {@code PropertyChangeSupport} usage that follows
  305.47 + * the rules and recommendations laid out in the JavaBeans&trade; specification:
  305.48 + * <pre>
  305.49 + * public class MyBean {
  305.50 + *     private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  305.51 + *
  305.52 + *     public void addPropertyChangeListener(PropertyChangeListener listener) {
  305.53 + *         this.pcs.addPropertyChangeListener(listener);
  305.54 + *     }
  305.55 + *
  305.56 + *     public void removePropertyChangeListener(PropertyChangeListener listener) {
  305.57 + *         this.pcs.removePropertyChangeListener(listener);
  305.58 + *     }
  305.59 + *
  305.60 + *     private String value;
  305.61 + *
  305.62 + *     public String getValue() {
  305.63 + *         return this.value;
  305.64 + *     }
  305.65 + *
  305.66 + *     public void setValue(String newValue) {
  305.67 + *         String oldValue = this.value;
  305.68 + *         this.value = newValue;
  305.69 + *         this.pcs.firePropertyChange("value", oldValue, newValue);
  305.70 + *     }
  305.71 + *
  305.72 + *     [...]
  305.73 + * }
  305.74 + * </pre>
  305.75 + * <p>
  305.76 + * A {@code PropertyChangeSupport} instance is thread-safe.
  305.77 + * <p>
  305.78 + * This class is serializable.  When it is serialized it will save
  305.79 + * (and restore) any listeners that are themselves serializable.  Any
  305.80 + * non-serializable listeners will be skipped during serialization.
  305.81 + *
  305.82 + * @see VetoableChangeSupport
  305.83 + */
  305.84 +public class PropertyChangeSupport implements Serializable {
  305.85 +    private PropertyChangeListenerMap map = new PropertyChangeListenerMap();
  305.86 +
  305.87 +    /**
  305.88 +     * Constructs a <code>PropertyChangeSupport</code> object.
  305.89 +     *
  305.90 +     * @param sourceBean  The bean to be given as the source for any events.
  305.91 +     */
  305.92 +    public PropertyChangeSupport(Object sourceBean) {
  305.93 +        if (sourceBean == null) {
  305.94 +            throw new NullPointerException();
  305.95 +        }
  305.96 +        source = sourceBean;
  305.97 +    }
  305.98 +
  305.99 +    /**
 305.100 +     * Add a PropertyChangeListener to the listener list.
 305.101 +     * The listener is registered for all properties.
 305.102 +     * The same listener object may be added more than once, and will be called
 305.103 +     * as many times as it is added.
 305.104 +     * If <code>listener</code> is null, no exception is thrown and no action
 305.105 +     * is taken.
 305.106 +     *
 305.107 +     * @param listener  The PropertyChangeListener to be added
 305.108 +     */
 305.109 +    public void addPropertyChangeListener(PropertyChangeListener listener) {
 305.110 +        if (listener == null) {
 305.111 +            return;
 305.112 +        }
 305.113 +        if (listener instanceof PropertyChangeListenerProxy) {
 305.114 +            PropertyChangeListenerProxy proxy =
 305.115 +                   (PropertyChangeListenerProxy)listener;
 305.116 +            // Call two argument add method.
 305.117 +            addPropertyChangeListener(proxy.getPropertyName(),
 305.118 +                                      proxy.getListener());
 305.119 +        } else {
 305.120 +            this.map.add(null, listener);
 305.121 +        }
 305.122 +    }
 305.123 +
 305.124 +    /**
 305.125 +     * Remove a PropertyChangeListener from the listener list.
 305.126 +     * This removes a PropertyChangeListener that was registered
 305.127 +     * for all properties.
 305.128 +     * If <code>listener</code> was added more than once to the same event
 305.129 +     * source, it will be notified one less time after being removed.
 305.130 +     * If <code>listener</code> is null, or was never added, no exception is
 305.131 +     * thrown and no action is taken.
 305.132 +     *
 305.133 +     * @param listener  The PropertyChangeListener to be removed
 305.134 +     */
 305.135 +    public void removePropertyChangeListener(PropertyChangeListener listener) {
 305.136 +        if (listener == null) {
 305.137 +            return;
 305.138 +        }
 305.139 +        if (listener instanceof PropertyChangeListenerProxy) {
 305.140 +            PropertyChangeListenerProxy proxy =
 305.141 +                    (PropertyChangeListenerProxy)listener;
 305.142 +            // Call two argument remove method.
 305.143 +            removePropertyChangeListener(proxy.getPropertyName(),
 305.144 +                                         proxy.getListener());
 305.145 +        } else {
 305.146 +            this.map.remove(null, listener);
 305.147 +        }
 305.148 +    }
 305.149 +
 305.150 +    /**
 305.151 +     * Returns an array of all the listeners that were added to the
 305.152 +     * PropertyChangeSupport object with addPropertyChangeListener().
 305.153 +     * <p>
 305.154 +     * If some listeners have been added with a named property, then
 305.155 +     * the returned array will be a mixture of PropertyChangeListeners
 305.156 +     * and <code>PropertyChangeListenerProxy</code>s. If the calling
 305.157 +     * method is interested in distinguishing the listeners then it must
 305.158 +     * test each element to see if it's a
 305.159 +     * <code>PropertyChangeListenerProxy</code>, perform the cast, and examine
 305.160 +     * the parameter.
 305.161 +     *
 305.162 +     * <pre>
 305.163 +     * PropertyChangeListener[] listeners = bean.getPropertyChangeListeners();
 305.164 +     * for (int i = 0; i < listeners.length; i++) {
 305.165 +     *   if (listeners[i] instanceof PropertyChangeListenerProxy) {
 305.166 +     *     PropertyChangeListenerProxy proxy =
 305.167 +     *                    (PropertyChangeListenerProxy)listeners[i];
 305.168 +     *     if (proxy.getPropertyName().equals("foo")) {
 305.169 +     *       // proxy is a PropertyChangeListener which was associated
 305.170 +     *       // with the property named "foo"
 305.171 +     *     }
 305.172 +     *   }
 305.173 +     * }
 305.174 +     *</pre>
 305.175 +     *
 305.176 +     * @see PropertyChangeListenerProxy
 305.177 +     * @return all of the <code>PropertyChangeListeners</code> added or an
 305.178 +     *         empty array if no listeners have been added
 305.179 +     * @since 1.4
 305.180 +     */
 305.181 +    public PropertyChangeListener[] getPropertyChangeListeners() {
 305.182 +        return this.map.getListeners();
 305.183 +    }
 305.184 +
 305.185 +    /**
 305.186 +     * Add a PropertyChangeListener for a specific property.  The listener
 305.187 +     * will be invoked only when a call on firePropertyChange names that
 305.188 +     * specific property.
 305.189 +     * The same listener object may be added more than once.  For each
 305.190 +     * property,  the listener will be invoked the number of times it was added
 305.191 +     * for that property.
 305.192 +     * If <code>propertyName</code> or <code>listener</code> is null, no
 305.193 +     * exception is thrown and no action is taken.
 305.194 +     *
 305.195 +     * @param propertyName  The name of the property to listen on.
 305.196 +     * @param listener  The PropertyChangeListener to be added
 305.197 +     */
 305.198 +    public void addPropertyChangeListener(
 305.199 +                String propertyName,
 305.200 +                PropertyChangeListener listener) {
 305.201 +        if (listener == null || propertyName == null) {
 305.202 +            return;
 305.203 +        }
 305.204 +        listener = this.map.extract(listener);
 305.205 +        if (listener != null) {
 305.206 +            this.map.add(propertyName, listener);
 305.207 +        }
 305.208 +    }
 305.209 +
 305.210 +    /**
 305.211 +     * Remove a PropertyChangeListener for a specific property.
 305.212 +     * If <code>listener</code> was added more than once to the same event
 305.213 +     * source for the specified property, it will be notified one less time
 305.214 +     * after being removed.
 305.215 +     * If <code>propertyName</code> is null,  no exception is thrown and no
 305.216 +     * action is taken.
 305.217 +     * If <code>listener</code> is null, or was never added for the specified
 305.218 +     * property, no exception is thrown and no action is taken.
 305.219 +     *
 305.220 +     * @param propertyName  The name of the property that was listened on.
 305.221 +     * @param listener  The PropertyChangeListener to be removed
 305.222 +     */
 305.223 +    public void removePropertyChangeListener(
 305.224 +                String propertyName,
 305.225 +                PropertyChangeListener listener) {
 305.226 +        if (listener == null || propertyName == null) {
 305.227 +            return;
 305.228 +        }
 305.229 +        listener = this.map.extract(listener);
 305.230 +        if (listener != null) {
 305.231 +            this.map.remove(propertyName, listener);
 305.232 +        }
 305.233 +    }
 305.234 +
 305.235 +    /**
 305.236 +     * Returns an array of all the listeners which have been associated
 305.237 +     * with the named property.
 305.238 +     *
 305.239 +     * @param propertyName  The name of the property being listened to
 305.240 +     * @return all of the <code>PropertyChangeListeners</code> associated with
 305.241 +     *         the named property.  If no such listeners have been added,
 305.242 +     *         or if <code>propertyName</code> is null, an empty array is
 305.243 +     *         returned.
 305.244 +     * @since 1.4
 305.245 +     */
 305.246 +    public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
 305.247 +        return this.map.getListeners(propertyName);
 305.248 +    }
 305.249 +
 305.250 +    /**
 305.251 +     * Reports a bound property update to listeners
 305.252 +     * that have been registered to track updates of
 305.253 +     * all properties or a property with the specified name.
 305.254 +     * <p>
 305.255 +     * No event is fired if old and new values are equal and non-null.
 305.256 +     * <p>
 305.257 +     * This is merely a convenience wrapper around the more general
 305.258 +     * {@link #firePropertyChange(PropertyChangeEvent)} method.
 305.259 +     *
 305.260 +     * @param propertyName  the programmatic name of the property that was changed
 305.261 +     * @param oldValue      the old value of the property
 305.262 +     * @param newValue      the new value of the property
 305.263 +     */
 305.264 +    public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
 305.265 +        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
 305.266 +            firePropertyChange(new PropertyChangeEvent(this.source, propertyName, oldValue, newValue));
 305.267 +        }
 305.268 +    }
 305.269 +
 305.270 +    /**
 305.271 +     * Reports an integer bound property update to listeners
 305.272 +     * that have been registered to track updates of
 305.273 +     * all properties or a property with the specified name.
 305.274 +     * <p>
 305.275 +     * No event is fired if old and new values are equal.
 305.276 +     * <p>
 305.277 +     * This is merely a convenience wrapper around the more general
 305.278 +     * {@link #firePropertyChange(String, Object, Object)}  method.
 305.279 +     *
 305.280 +     * @param propertyName  the programmatic name of the property that was changed
 305.281 +     * @param oldValue      the old value of the property
 305.282 +     * @param newValue      the new value of the property
 305.283 +     */
 305.284 +    public void firePropertyChange(String propertyName, int oldValue, int newValue) {
 305.285 +        if (oldValue != newValue) {
 305.286 +            firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
 305.287 +        }
 305.288 +    }
 305.289 +
 305.290 +    /**
 305.291 +     * Reports a boolean bound property update to listeners
 305.292 +     * that have been registered to track updates of
 305.293 +     * all properties or a property with the specified name.
 305.294 +     * <p>
 305.295 +     * No event is fired if old and new values are equal.
 305.296 +     * <p>
 305.297 +     * This is merely a convenience wrapper around the more general
 305.298 +     * {@link #firePropertyChange(String, Object, Object)}  method.
 305.299 +     *
 305.300 +     * @param propertyName  the programmatic name of the property that was changed
 305.301 +     * @param oldValue      the old value of the property
 305.302 +     * @param newValue      the new value of the property
 305.303 +     */
 305.304 +    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
 305.305 +        if (oldValue != newValue) {
 305.306 +            firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
 305.307 +        }
 305.308 +    }
 305.309 +
 305.310 +    /**
 305.311 +     * Fires a property change event to listeners
 305.312 +     * that have been registered to track updates of
 305.313 +     * all properties or a property with the specified name.
 305.314 +     * <p>
 305.315 +     * No event is fired if the given event's old and new values are equal and non-null.
 305.316 +     *
 305.317 +     * @param event  the {@code PropertyChangeEvent} to be fired
 305.318 +     */
 305.319 +    public void firePropertyChange(PropertyChangeEvent event) {
 305.320 +        Object oldValue = event.getOldValue();
 305.321 +        Object newValue = event.getNewValue();
 305.322 +        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
 305.323 +            String name = event.getPropertyName();
 305.324 +
 305.325 +            PropertyChangeListener[] common = this.map.get(null);
 305.326 +            PropertyChangeListener[] named = (name != null)
 305.327 +                        ? this.map.get(name)
 305.328 +                        : null;
 305.329 +
 305.330 +            fire(common, event);
 305.331 +            fire(named, event);
 305.332 +        }
 305.333 +    }
 305.334 +
 305.335 +    private static void fire(PropertyChangeListener[] listeners, PropertyChangeEvent event) {
 305.336 +        if (listeners != null) {
 305.337 +            for (PropertyChangeListener listener : listeners) {
 305.338 +                listener.propertyChange(event);
 305.339 +            }
 305.340 +        }
 305.341 +    }
 305.342 +
 305.343 +    /**
 305.344 +     * Reports a bound indexed property update to listeners
 305.345 +     * that have been registered to track updates of
 305.346 +     * all properties or a property with the specified name.
 305.347 +     * <p>
 305.348 +     * No event is fired if old and new values are equal and non-null.
 305.349 +     * <p>
 305.350 +     * This is merely a convenience wrapper around the more general
 305.351 +     * {@link #firePropertyChange(PropertyChangeEvent)} method.
 305.352 +     *
 305.353 +     * @param propertyName  the programmatic name of the property that was changed
 305.354 +     * @param index         the index of the property element that was changed
 305.355 +     * @param oldValue      the old value of the property
 305.356 +     * @param newValue      the new value of the property
 305.357 +     * @since 1.5
 305.358 +     */
 305.359 +    public void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) {
 305.360 +        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
 305.361 +            firePropertyChange(new IndexedPropertyChangeEvent(source, propertyName, oldValue, newValue, index));
 305.362 +        }
 305.363 +    }
 305.364 +
 305.365 +    /**
 305.366 +     * Reports an integer bound indexed property update to listeners
 305.367 +     * that have been registered to track updates of
 305.368 +     * all properties or a property with the specified name.
 305.369 +     * <p>
 305.370 +     * No event is fired if old and new values are equal.
 305.371 +     * <p>
 305.372 +     * This is merely a convenience wrapper around the more general
 305.373 +     * {@link #fireIndexedPropertyChange(String, int, Object, Object)} method.
 305.374 +     *
 305.375 +     * @param propertyName  the programmatic name of the property that was changed
 305.376 +     * @param index         the index of the property element that was changed
 305.377 +     * @param oldValue      the old value of the property
 305.378 +     * @param newValue      the new value of the property
 305.379 +     * @since 1.5
 305.380 +     */
 305.381 +    public void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue) {
 305.382 +        if (oldValue != newValue) {
 305.383 +            fireIndexedPropertyChange(propertyName, index, Integer.valueOf(oldValue), Integer.valueOf(newValue));
 305.384 +        }
 305.385 +    }
 305.386 +
 305.387 +    /**
 305.388 +     * Reports a boolean bound indexed property update to listeners
 305.389 +     * that have been registered to track updates of
 305.390 +     * all properties or a property with the specified name.
 305.391 +     * <p>
 305.392 +     * No event is fired if old and new values are equal.
 305.393 +     * <p>
 305.394 +     * This is merely a convenience wrapper around the more general
 305.395 +     * {@link #fireIndexedPropertyChange(String, int, Object, Object)} method.
 305.396 +     *
 305.397 +     * @param propertyName  the programmatic name of the property that was changed
 305.398 +     * @param index         the index of the property element that was changed
 305.399 +     * @param oldValue      the old value of the property
 305.400 +     * @param newValue      the new value of the property
 305.401 +     * @since 1.5
 305.402 +     */
 305.403 +    public void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue) {
 305.404 +        if (oldValue != newValue) {
 305.405 +            fireIndexedPropertyChange(propertyName, index, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
 305.406 +        }
 305.407 +    }
 305.408 +
 305.409 +    /**
 305.410 +     * Check if there are any listeners for a specific property, including
 305.411 +     * those registered on all properties.  If <code>propertyName</code>
 305.412 +     * is null, only check for listeners registered on all properties.
 305.413 +     *
 305.414 +     * @param propertyName  the property name.
 305.415 +     * @return true if there are one or more listeners for the given property
 305.416 +     */
 305.417 +    public boolean hasListeners(String propertyName) {
 305.418 +        return this.map.hasListeners(propertyName);
 305.419 +    }
 305.420 +
 305.421 +    /**
 305.422 +     * @serialData Null terminated list of <code>PropertyChangeListeners</code>.
 305.423 +     * <p>
 305.424 +     * At serialization time we skip non-serializable listeners and
 305.425 +     * only serialize the serializable listeners.
 305.426 +     */
 305.427 +    private void writeObject(ObjectOutputStream s) throws IOException {
 305.428 +        Hashtable<String, PropertyChangeSupport> children = null;
 305.429 +        PropertyChangeListener[] listeners = null;
 305.430 +        synchronized (this.map) {
 305.431 +            for (Entry<String, PropertyChangeListener[]> entry : this.map.getEntries()) {
 305.432 +                String property = entry.getKey();
 305.433 +                if (property == null) {
 305.434 +                    listeners = entry.getValue();
 305.435 +                } else {
 305.436 +                    if (children == null) {
 305.437 +                        children = new Hashtable<String, PropertyChangeSupport>();
 305.438 +                    }
 305.439 +                    PropertyChangeSupport pcs = new PropertyChangeSupport(this.source);
 305.440 +                    pcs.map.set(null, entry.getValue());
 305.441 +                    children.put(property, pcs);
 305.442 +                }
 305.443 +            }
 305.444 +        }
 305.445 +        ObjectOutputStream.PutField fields = s.putFields();
 305.446 +        fields.put("children", children);
 305.447 +        fields.put("source", this.source);
 305.448 +        fields.put("propertyChangeSupportSerializedDataVersion", 2);
 305.449 +        s.writeFields();
 305.450 +
 305.451 +        if (listeners != null) {
 305.452 +            for (PropertyChangeListener l : listeners) {
 305.453 +                if (l instanceof Serializable) {
 305.454 +                    s.writeObject(l);
 305.455 +                }
 305.456 +            }
 305.457 +        }
 305.458 +        s.writeObject(null);
 305.459 +    }
 305.460 +
 305.461 +    private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
 305.462 +        this.map = new PropertyChangeListenerMap();
 305.463 +
 305.464 +        ObjectInputStream.GetField fields = s.readFields();
 305.465 +
 305.466 +        Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
 305.467 +        this.source = fields.get("source", null);
 305.468 +        fields.get("propertyChangeSupportSerializedDataVersion", 2);
 305.469 +
 305.470 +        Object listenerOrNull;
 305.471 +        while (null != (listenerOrNull = s.readObject())) {
 305.472 +            this.map.add(null, (PropertyChangeListener)listenerOrNull);
 305.473 +        }
 305.474 +        if (children != null) {
 305.475 +            for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
 305.476 +                for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
 305.477 +                    this.map.add(entry.getKey(), listener);
 305.478 +                }
 305.479 +            }
 305.480 +        }
 305.481 +    }
 305.482 +
 305.483 +    /**
 305.484 +     * The object to be provided as the "source" for any generated events.
 305.485 +     */
 305.486 +    private Object source;
 305.487 +
 305.488 +    /**
 305.489 +     * @serialField children                                   Hashtable
 305.490 +     * @serialField source                                     Object
 305.491 +     * @serialField propertyChangeSupportSerializedDataVersion int
 305.492 +     */
 305.493 +    private static final ObjectStreamField[] serialPersistentFields = {
 305.494 +            new ObjectStreamField("children", Hashtable.class),
 305.495 +            new ObjectStreamField("source", Object.class),
 305.496 +            new ObjectStreamField("propertyChangeSupportSerializedDataVersion", Integer.TYPE)
 305.497 +    };
 305.498 +
 305.499 +    /**
 305.500 +     * Serialization version ID, so we're compatible with JDK 1.1
 305.501 +     */
 305.502 +    static final long serialVersionUID = 6401253773779951803L;
 305.503 +
 305.504 +    /**
 305.505 +     * This is a {@link ChangeListenerMap ChangeListenerMap} implementation
 305.506 +     * that works with {@link PropertyChangeListener PropertyChangeListener} objects.
 305.507 +     */
 305.508 +    private static final class PropertyChangeListenerMap extends ChangeListenerMap<PropertyChangeListener> {
 305.509 +        private static final PropertyChangeListener[] EMPTY = {};
 305.510 +
 305.511 +        /**
 305.512 +         * Creates an array of {@link PropertyChangeListener PropertyChangeListener} objects.
 305.513 +         * This method uses the same instance of the empty array
 305.514 +         * when {@code length} equals {@code 0}.
 305.515 +         *
 305.516 +         * @param length  the array length
 305.517 +         * @return        an array with specified length
 305.518 +         */
 305.519 +        @Override
 305.520 +        protected PropertyChangeListener[] newArray(int length) {
 305.521 +            return (0 < length)
 305.522 +                    ? new PropertyChangeListener[length]
 305.523 +                    : EMPTY;
 305.524 +        }
 305.525 +
 305.526 +        /**
 305.527 +         * Creates a {@link PropertyChangeListenerProxy PropertyChangeListenerProxy}
 305.528 +         * object for the specified property.
 305.529 +         *
 305.530 +         * @param name      the name of the property to listen on
 305.531 +         * @param listener  the listener to process events
 305.532 +         * @return          a {@code PropertyChangeListenerProxy} object
 305.533 +         */
 305.534 +        @Override
 305.535 +        protected PropertyChangeListener newProxy(String name, PropertyChangeListener listener) {
 305.536 +            return new PropertyChangeListenerProxy(name, listener);
 305.537 +        }
 305.538 +    }
 305.539 +}
   306.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   306.2 +++ b/rt/emul/compact/src/main/java/java/beans/PropertyVetoException.java	Wed Feb 27 11:24:58 2013 +0100
   306.3 @@ -0,0 +1,64 @@
   306.4 +/*
   306.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   306.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   306.7 + *
   306.8 + * This code is free software; you can redistribute it and/or modify it
   306.9 + * under the terms of the GNU General Public License version 2 only, as
  306.10 + * published by the Free Software Foundation.  Oracle designates this
  306.11 + * particular file as subject to the "Classpath" exception as provided
  306.12 + * by Oracle in the LICENSE file that accompanied this code.
  306.13 + *
  306.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  306.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  306.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  306.17 + * version 2 for more details (a copy is included in the LICENSE file that
  306.18 + * accompanied this code).
  306.19 + *
  306.20 + * You should have received a copy of the GNU General Public License version
  306.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  306.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  306.23 + *
  306.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  306.25 + * or visit www.oracle.com if you need additional information or have any
  306.26 + * questions.
  306.27 + */
  306.28 +
  306.29 +package java.beans;
  306.30 +
  306.31 +
  306.32 +/**
  306.33 + * A PropertyVetoException is thrown when a proposed change to a
  306.34 + * property represents an unacceptable value.
  306.35 + */
  306.36 +
  306.37 +public
  306.38 +class PropertyVetoException extends Exception {
  306.39 +    private static final long serialVersionUID = 129596057694162164L;
  306.40 +
  306.41 +    /**
  306.42 +     * Constructs a <code>PropertyVetoException</code> with a
  306.43 +     * detailed message.
  306.44 +     *
  306.45 +     * @param mess Descriptive message
  306.46 +     * @param evt A PropertyChangeEvent describing the vetoed change.
  306.47 +     */
  306.48 +    public PropertyVetoException(String mess, PropertyChangeEvent evt) {
  306.49 +        super(mess);
  306.50 +        this.evt = evt;
  306.51 +    }
  306.52 +
  306.53 +     /**
  306.54 +     * Gets the vetoed <code>PropertyChangeEvent</code>.
  306.55 +     *
  306.56 +     * @return A PropertyChangeEvent describing the vetoed change.
  306.57 +     */
  306.58 +    public PropertyChangeEvent getPropertyChangeEvent() {
  306.59 +        return evt;
  306.60 +    }
  306.61 +
  306.62 +    /**
  306.63 +     * A PropertyChangeEvent describing the vetoed change.
  306.64 +     * @serial
  306.65 +     */
  306.66 +    private PropertyChangeEvent evt;
  306.67 +}
   307.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   307.2 +++ b/rt/emul/compact/src/main/java/java/beans/VetoableChangeListener.java	Wed Feb 27 11:24:58 2013 +0100
   307.3 @@ -0,0 +1,44 @@
   307.4 +/*
   307.5 + * Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved.
   307.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   307.7 + *
   307.8 + * This code is free software; you can redistribute it and/or modify it
   307.9 + * under the terms of the GNU General Public License version 2 only, as
  307.10 + * published by the Free Software Foundation.  Oracle designates this
  307.11 + * particular file as subject to the "Classpath" exception as provided
  307.12 + * by Oracle in the LICENSE file that accompanied this code.
  307.13 + *
  307.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  307.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  307.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  307.17 + * version 2 for more details (a copy is included in the LICENSE file that
  307.18 + * accompanied this code).
  307.19 + *
  307.20 + * You should have received a copy of the GNU General Public License version
  307.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  307.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  307.23 + *
  307.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  307.25 + * or visit www.oracle.com if you need additional information or have any
  307.26 + * questions.
  307.27 + */
  307.28 +
  307.29 +package java.beans;
  307.30 +
  307.31 +/**
  307.32 + * A VetoableChange event gets fired whenever a bean changes a "constrained"
  307.33 + * property.  You can register a VetoableChangeListener with a source bean
  307.34 + * so as to be notified of any constrained property updates.
  307.35 + */
  307.36 +public interface VetoableChangeListener extends java.util.EventListener {
  307.37 +    /**
  307.38 +     * This method gets called when a constrained property is changed.
  307.39 +     *
  307.40 +     * @param     evt a <code>PropertyChangeEvent</code> object describing the
  307.41 +     *                event source and the property that has changed.
  307.42 +     * @exception PropertyVetoException if the recipient wishes the property
  307.43 +     *              change to be rolled back.
  307.44 +     */
  307.45 +    void vetoableChange(PropertyChangeEvent evt)
  307.46 +                                throws PropertyVetoException;
  307.47 +}
   308.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   308.2 +++ b/rt/emul/compact/src/main/java/java/beans/VetoableChangeListenerProxy.java	Wed Feb 27 11:24:58 2013 +0100
   308.3 @@ -0,0 +1,84 @@
   308.4 +/*
   308.5 + * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
   308.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   308.7 + *
   308.8 + * This code is free software; you can redistribute it and/or modify it
   308.9 + * under the terms of the GNU General Public License version 2 only, as
  308.10 + * published by the Free Software Foundation.  Oracle designates this
  308.11 + * particular file as subject to the "Classpath" exception as provided
  308.12 + * by Oracle in the LICENSE file that accompanied this code.
  308.13 + *
  308.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  308.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  308.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  308.17 + * version 2 for more details (a copy is included in the LICENSE file that
  308.18 + * accompanied this code).
  308.19 + *
  308.20 + * You should have received a copy of the GNU General Public License version
  308.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  308.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  308.23 + *
  308.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  308.25 + * or visit www.oracle.com if you need additional information or have any
  308.26 + * questions.
  308.27 + */
  308.28 +
  308.29 +package java.beans;
  308.30 +
  308.31 +import java.util.EventListenerProxy;
  308.32 +
  308.33 +/**
  308.34 + * A class which extends the {@code EventListenerProxy}
  308.35 + * specifically for adding a {@code VetoableChangeListener}
  308.36 + * with a "constrained" property.
  308.37 + * Instances of this class can be added
  308.38 + * as {@code VetoableChangeListener}s to a bean
  308.39 + * which supports firing vetoable change events.
  308.40 + * <p>
  308.41 + * If the object has a {@code getVetoableChangeListeners} method
  308.42 + * then the array returned could be a mixture of {@code VetoableChangeListener}
  308.43 + * and {@code VetoableChangeListenerProxy} objects.
  308.44 + *
  308.45 + * @see java.util.EventListenerProxy
  308.46 + * @see VetoableChangeSupport#getVetoableChangeListeners
  308.47 + * @since 1.4
  308.48 + */
  308.49 +public class VetoableChangeListenerProxy
  308.50 +        extends EventListenerProxy<VetoableChangeListener>
  308.51 +        implements VetoableChangeListener {
  308.52 +
  308.53 +    private final String propertyName;
  308.54 +
  308.55 +    /**
  308.56 +     * Constructor which binds the {@code VetoableChangeListener}
  308.57 +     * to a specific property.
  308.58 +     *
  308.59 +     * @param propertyName  the name of the property to listen on
  308.60 +     * @param listener      the listener object
  308.61 +     */
  308.62 +    public VetoableChangeListenerProxy(String propertyName, VetoableChangeListener listener) {
  308.63 +        super(listener);
  308.64 +        this.propertyName = propertyName;
  308.65 +    }
  308.66 +
  308.67 +    /**
  308.68 +    * Forwards the property change event to the listener delegate.
  308.69 +    *
  308.70 +    * @param event  the property change event
  308.71 +    *
  308.72 +    * @exception PropertyVetoException if the recipient wishes the property
  308.73 +    *                                  change to be rolled back
  308.74 +    */
  308.75 +    public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException{
  308.76 +        getListener().vetoableChange(event);
  308.77 +    }
  308.78 +
  308.79 +    /**
  308.80 +     * Returns the name of the named property associated with the listener.
  308.81 +     *
  308.82 +     * @return the name of the named property associated with the listener
  308.83 +     */
  308.84 +    public String getPropertyName() {
  308.85 +        return this.propertyName;
  308.86 +    }
  308.87 +}
   309.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   309.2 +++ b/rt/emul/compact/src/main/java/java/beans/VetoableChangeSupport.java	Wed Feb 27 11:24:58 2013 +0100
   309.3 @@ -0,0 +1,526 @@
   309.4 +/*
   309.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
   309.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   309.7 + *
   309.8 + * This code is free software; you can redistribute it and/or modify it
   309.9 + * under the terms of the GNU General Public License version 2 only, as
  309.10 + * published by the Free Software Foundation.  Oracle designates this
  309.11 + * particular file as subject to the "Classpath" exception as provided
  309.12 + * by Oracle in the LICENSE file that accompanied this code.
  309.13 + *
  309.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  309.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  309.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  309.17 + * version 2 for more details (a copy is included in the LICENSE file that
  309.18 + * accompanied this code).
  309.19 + *
  309.20 + * You should have received a copy of the GNU General Public License version
  309.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  309.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  309.23 + *
  309.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  309.25 + * or visit www.oracle.com if you need additional information or have any
  309.26 + * questions.
  309.27 + */
  309.28 +package java.beans;
  309.29 +
  309.30 +import java.io.Serializable;
  309.31 +import java.io.ObjectStreamField;
  309.32 +import java.io.ObjectOutputStream;
  309.33 +import java.io.ObjectInputStream;
  309.34 +import java.io.IOException;
  309.35 +import java.util.Hashtable;
  309.36 +import java.util.Map.Entry;
  309.37 +import org.apidesign.bck2brwsr.emul.lang.System;
  309.38 +
  309.39 +/**
  309.40 + * This is a utility class that can be used by beans that support constrained
  309.41 + * properties.  It manages a list of listeners and dispatches
  309.42 + * {@link PropertyChangeEvent}s to them.  You can use an instance of this class
  309.43 + * as a member field of your bean and delegate these types of work to it.
  309.44 + * The {@link VetoableChangeListener} can be registered for all properties
  309.45 + * or for a property specified by name.
  309.46 + * <p>
  309.47 + * Here is an example of {@code VetoableChangeSupport} usage that follows
  309.48 + * the rules and recommendations laid out in the JavaBeans&trade; specification:
  309.49 + * <pre>
  309.50 + * public class MyBean {
  309.51 + *     private final VetoableChangeSupport vcs = new VetoableChangeSupport(this);
  309.52 + *
  309.53 + *     public void addVetoableChangeListener(VetoableChangeListener listener) {
  309.54 + *         this.vcs.addVetoableChangeListener(listener);
  309.55 + *     }
  309.56 + *
  309.57 + *     public void removeVetoableChangeListener(VetoableChangeListener listener) {
  309.58 + *         this.vcs.removeVetoableChangeListener(listener);
  309.59 + *     }
  309.60 + *
  309.61 + *     private String value;
  309.62 + *
  309.63 + *     public String getValue() {
  309.64 + *         return this.value;
  309.65 + *     }
  309.66 + *
  309.67 + *     public void setValue(String newValue) throws PropertyVetoException {
  309.68 + *         String oldValue = this.value;
  309.69 + *         this.vcs.fireVetoableChange("value", oldValue, newValue);
  309.70 + *         this.value = newValue;
  309.71 + *     }
  309.72 + *
  309.73 + *     [...]
  309.74 + * }
  309.75 + * </pre>
  309.76 + * <p>
  309.77 + * A {@code VetoableChangeSupport} instance is thread-safe.
  309.78 + * <p>
  309.79 + * This class is serializable.  When it is serialized it will save
  309.80 + * (and restore) any listeners that are themselves serializable.  Any
  309.81 + * non-serializable listeners will be skipped during serialization.
  309.82 + *
  309.83 + * @see PropertyChangeSupport
  309.84 + */
  309.85 +public class VetoableChangeSupport implements Serializable {
  309.86 +    private VetoableChangeListenerMap map = new VetoableChangeListenerMap();
  309.87 +
  309.88 +    /**
  309.89 +     * Constructs a <code>VetoableChangeSupport</code> object.
  309.90 +     *
  309.91 +     * @param sourceBean  The bean to be given as the source for any events.
  309.92 +     */
  309.93 +    public VetoableChangeSupport(Object sourceBean) {
  309.94 +        if (sourceBean == null) {
  309.95 +            throw new NullPointerException();
  309.96 +        }
  309.97 +        source = sourceBean;
  309.98 +    }
  309.99 +
 309.100 +    /**
 309.101 +     * Add a VetoableChangeListener to the listener list.
 309.102 +     * The listener is registered for all properties.
 309.103 +     * The same listener object may be added more than once, and will be called
 309.104 +     * as many times as it is added.
 309.105 +     * If <code>listener</code> is null, no exception is thrown and no action
 309.106 +     * is taken.
 309.107 +     *
 309.108 +     * @param listener  The VetoableChangeListener to be added
 309.109 +     */
 309.110 +    public void addVetoableChangeListener(VetoableChangeListener listener) {
 309.111 +        if (listener == null) {
 309.112 +            return;
 309.113 +        }
 309.114 +        if (listener instanceof VetoableChangeListenerProxy) {
 309.115 +            VetoableChangeListenerProxy proxy =
 309.116 +                    (VetoableChangeListenerProxy)listener;
 309.117 +            // Call two argument add method.
 309.118 +            addVetoableChangeListener(proxy.getPropertyName(),
 309.119 +                                      proxy.getListener());
 309.120 +        } else {
 309.121 +            this.map.add(null, listener);
 309.122 +        }
 309.123 +    }
 309.124 +
 309.125 +    /**
 309.126 +     * Remove a VetoableChangeListener from the listener list.
 309.127 +     * This removes a VetoableChangeListener that was registered
 309.128 +     * for all properties.
 309.129 +     * If <code>listener</code> was added more than once to the same event
 309.130 +     * source, it will be notified one less time after being removed.
 309.131 +     * If <code>listener</code> is null, or was never added, no exception is
 309.132 +     * thrown and no action is taken.
 309.133 +     *
 309.134 +     * @param listener  The VetoableChangeListener to be removed
 309.135 +     */
 309.136 +    public void removeVetoableChangeListener(VetoableChangeListener listener) {
 309.137 +        if (listener == null) {
 309.138 +            return;
 309.139 +        }
 309.140 +        if (listener instanceof VetoableChangeListenerProxy) {
 309.141 +            VetoableChangeListenerProxy proxy =
 309.142 +                    (VetoableChangeListenerProxy)listener;
 309.143 +            // Call two argument remove method.
 309.144 +            removeVetoableChangeListener(proxy.getPropertyName(),
 309.145 +                                         proxy.getListener());
 309.146 +        } else {
 309.147 +            this.map.remove(null, listener);
 309.148 +        }
 309.149 +    }
 309.150 +
 309.151 +    /**
 309.152 +     * Returns an array of all the listeners that were added to the
 309.153 +     * VetoableChangeSupport object with addVetoableChangeListener().
 309.154 +     * <p>
 309.155 +     * If some listeners have been added with a named property, then
 309.156 +     * the returned array will be a mixture of VetoableChangeListeners
 309.157 +     * and <code>VetoableChangeListenerProxy</code>s. If the calling
 309.158 +     * method is interested in distinguishing the listeners then it must
 309.159 +     * test each element to see if it's a
 309.160 +     * <code>VetoableChangeListenerProxy</code>, perform the cast, and examine
 309.161 +     * the parameter.
 309.162 +     *
 309.163 +     * <pre>
 309.164 +     * VetoableChangeListener[] listeners = bean.getVetoableChangeListeners();
 309.165 +     * for (int i = 0; i < listeners.length; i++) {
 309.166 +     *        if (listeners[i] instanceof VetoableChangeListenerProxy) {
 309.167 +     *     VetoableChangeListenerProxy proxy =
 309.168 +     *                    (VetoableChangeListenerProxy)listeners[i];
 309.169 +     *     if (proxy.getPropertyName().equals("foo")) {
 309.170 +     *       // proxy is a VetoableChangeListener which was associated
 309.171 +     *       // with the property named "foo"
 309.172 +     *     }
 309.173 +     *   }
 309.174 +     * }
 309.175 +     *</pre>
 309.176 +     *
 309.177 +     * @see VetoableChangeListenerProxy
 309.178 +     * @return all of the <code>VetoableChangeListeners</code> added or an
 309.179 +     *         empty array if no listeners have been added
 309.180 +     * @since 1.4
 309.181 +     */
 309.182 +    public VetoableChangeListener[] getVetoableChangeListeners(){
 309.183 +        return this.map.getListeners();
 309.184 +    }
 309.185 +
 309.186 +    /**
 309.187 +     * Add a VetoableChangeListener for a specific property.  The listener
 309.188 +     * will be invoked only when a call on fireVetoableChange names that
 309.189 +     * specific property.
 309.190 +     * The same listener object may be added more than once.  For each
 309.191 +     * property,  the listener will be invoked the number of times it was added
 309.192 +     * for that property.
 309.193 +     * If <code>propertyName</code> or <code>listener</code> is null, no
 309.194 +     * exception is thrown and no action is taken.
 309.195 +     *
 309.196 +     * @param propertyName  The name of the property to listen on.
 309.197 +     * @param listener  The VetoableChangeListener to be added
 309.198 +     */
 309.199 +    public void addVetoableChangeListener(
 309.200 +                                String propertyName,
 309.201 +                VetoableChangeListener listener) {
 309.202 +        if (listener == null || propertyName == null) {
 309.203 +            return;
 309.204 +        }
 309.205 +        listener = this.map.extract(listener);
 309.206 +        if (listener != null) {
 309.207 +            this.map.add(propertyName, listener);
 309.208 +        }
 309.209 +    }
 309.210 +
 309.211 +    /**
 309.212 +     * Remove a VetoableChangeListener for a specific property.
 309.213 +     * If <code>listener</code> was added more than once to the same event
 309.214 +     * source for the specified property, it will be notified one less time
 309.215 +     * after being removed.
 309.216 +     * If <code>propertyName</code> is null, no exception is thrown and no
 309.217 +     * action is taken.
 309.218 +     * If <code>listener</code> is null, or was never added for the specified
 309.219 +     * property, no exception is thrown and no action is taken.
 309.220 +     *
 309.221 +     * @param propertyName  The name of the property that was listened on.
 309.222 +     * @param listener  The VetoableChangeListener to be removed
 309.223 +     */
 309.224 +    public void removeVetoableChangeListener(
 309.225 +                                String propertyName,
 309.226 +                VetoableChangeListener listener) {
 309.227 +        if (listener == null || propertyName == null) {
 309.228 +            return;
 309.229 +        }
 309.230 +        listener = this.map.extract(listener);
 309.231 +        if (listener != null) {
 309.232 +            this.map.remove(propertyName, listener);
 309.233 +        }
 309.234 +    }
 309.235 +
 309.236 +    /**
 309.237 +     * Returns an array of all the listeners which have been associated
 309.238 +     * with the named property.
 309.239 +     *
 309.240 +     * @param propertyName  The name of the property being listened to
 309.241 +     * @return all the <code>VetoableChangeListeners</code> associated with
 309.242 +     *         the named property.  If no such listeners have been added,
 309.243 +     *         or if <code>propertyName</code> is null, an empty array is
 309.244 +     *         returned.
 309.245 +     * @since 1.4
 309.246 +     */
 309.247 +    public VetoableChangeListener[] getVetoableChangeListeners(String propertyName) {
 309.248 +        return this.map.getListeners(propertyName);
 309.249 +    }
 309.250 +
 309.251 +    /**
 309.252 +     * Reports a constrained property update to listeners
 309.253 +     * that have been registered to track updates of
 309.254 +     * all properties or a property with the specified name.
 309.255 +     * <p>
 309.256 +     * Any listener can throw a {@code PropertyVetoException} to veto the update.
 309.257 +     * If one of the listeners vetoes the update, this method passes
 309.258 +     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
 309.259 +     * to all listeners that already confirmed this update
 309.260 +     * and throws the {@code PropertyVetoException} again.
 309.261 +     * <p>
 309.262 +     * No event is fired if old and new values are equal and non-null.
 309.263 +     * <p>
 309.264 +     * This is merely a convenience wrapper around the more general
 309.265 +     * {@link #fireVetoableChange(PropertyChangeEvent)} method.
 309.266 +     *
 309.267 +     * @param propertyName  the programmatic name of the property that is about to change
 309.268 +     * @param oldValue      the old value of the property
 309.269 +     * @param newValue      the new value of the property
 309.270 +     * @throws PropertyVetoException if one of listeners vetoes the property update
 309.271 +     */
 309.272 +    public void fireVetoableChange(String propertyName, Object oldValue, Object newValue)
 309.273 +            throws PropertyVetoException {
 309.274 +        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
 309.275 +            fireVetoableChange(new PropertyChangeEvent(this.source, propertyName, oldValue, newValue));
 309.276 +        }
 309.277 +    }
 309.278 +
 309.279 +    /**
 309.280 +     * Reports an integer constrained property update to listeners
 309.281 +     * that have been registered to track updates of
 309.282 +     * all properties or a property with the specified name.
 309.283 +     * <p>
 309.284 +     * Any listener can throw a {@code PropertyVetoException} to veto the update.
 309.285 +     * If one of the listeners vetoes the update, this method passes
 309.286 +     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
 309.287 +     * to all listeners that already confirmed this update
 309.288 +     * and throws the {@code PropertyVetoException} again.
 309.289 +     * <p>
 309.290 +     * No event is fired if old and new values are equal.
 309.291 +     * <p>
 309.292 +     * This is merely a convenience wrapper around the more general
 309.293 +     * {@link #fireVetoableChange(String, Object, Object)} method.
 309.294 +     *
 309.295 +     * @param propertyName  the programmatic name of the property that is about to change
 309.296 +     * @param oldValue      the old value of the property
 309.297 +     * @param newValue      the new value of the property
 309.298 +     * @throws PropertyVetoException if one of listeners vetoes the property update
 309.299 +     */
 309.300 +    public void fireVetoableChange(String propertyName, int oldValue, int newValue)
 309.301 +            throws PropertyVetoException {
 309.302 +        if (oldValue != newValue) {
 309.303 +            fireVetoableChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
 309.304 +        }
 309.305 +    }
 309.306 +
 309.307 +    /**
 309.308 +     * Reports a boolean constrained property update to listeners
 309.309 +     * that have been registered to track updates of
 309.310 +     * all properties or a property with the specified name.
 309.311 +     * <p>
 309.312 +     * Any listener can throw a {@code PropertyVetoException} to veto the update.
 309.313 +     * If one of the listeners vetoes the update, this method passes
 309.314 +     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
 309.315 +     * to all listeners that already confirmed this update
 309.316 +     * and throws the {@code PropertyVetoException} again.
 309.317 +     * <p>
 309.318 +     * No event is fired if old and new values are equal.
 309.319 +     * <p>
 309.320 +     * This is merely a convenience wrapper around the more general
 309.321 +     * {@link #fireVetoableChange(String, Object, Object)} method.
 309.322 +     *
 309.323 +     * @param propertyName  the programmatic name of the property that is about to change
 309.324 +     * @param oldValue      the old value of the property
 309.325 +     * @param newValue      the new value of the property
 309.326 +     * @throws PropertyVetoException if one of listeners vetoes the property update
 309.327 +     */
 309.328 +    public void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue)
 309.329 +            throws PropertyVetoException {
 309.330 +        if (oldValue != newValue) {
 309.331 +            fireVetoableChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
 309.332 +        }
 309.333 +    }
 309.334 +
 309.335 +    /**
 309.336 +     * Fires a property change event to listeners
 309.337 +     * that have been registered to track updates of
 309.338 +     * all properties or a property with the specified name.
 309.339 +     * <p>
 309.340 +     * Any listener can throw a {@code PropertyVetoException} to veto the update.
 309.341 +     * If one of the listeners vetoes the update, this method passes
 309.342 +     * a new "undo" {@code PropertyChangeEvent} that reverts to the old value
 309.343 +     * to all listeners that already confirmed this update
 309.344 +     * and throws the {@code PropertyVetoException} again.
 309.345 +     * <p>
 309.346 +     * No event is fired if the given event's old and new values are equal and non-null.
 309.347 +     *
 309.348 +     * @param event  the {@code PropertyChangeEvent} to be fired
 309.349 +     * @throws PropertyVetoException if one of listeners vetoes the property update
 309.350 +     */
 309.351 +    public void fireVetoableChange(PropertyChangeEvent event)
 309.352 +            throws PropertyVetoException {
 309.353 +        Object oldValue = event.getOldValue();
 309.354 +        Object newValue = event.getNewValue();
 309.355 +        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
 309.356 +            String name = event.getPropertyName();
 309.357 +
 309.358 +            VetoableChangeListener[] common = this.map.get(null);
 309.359 +            VetoableChangeListener[] named = (name != null)
 309.360 +                        ? this.map.get(name)
 309.361 +                        : null;
 309.362 +
 309.363 +            VetoableChangeListener[] listeners;
 309.364 +            if (common == null) {
 309.365 +                listeners = named;
 309.366 +            }
 309.367 +            else if (named == null) {
 309.368 +                listeners = common;
 309.369 +            }
 309.370 +            else {
 309.371 +                listeners = new VetoableChangeListener[common.length + named.length];
 309.372 +                System.arraycopy(common, 0, listeners, 0, common.length);
 309.373 +                System.arraycopy(named, 0, listeners, common.length, named.length);
 309.374 +            }
 309.375 +            if (listeners != null) {
 309.376 +                int current = 0;
 309.377 +                try {
 309.378 +                    while (current < listeners.length) {
 309.379 +                        listeners[current].vetoableChange(event);
 309.380 +                        current++;
 309.381 +                    }
 309.382 +                }
 309.383 +                catch (PropertyVetoException veto) {
 309.384 +                    event = new PropertyChangeEvent(this.source, name, newValue, oldValue);
 309.385 +                    for (int i = 0; i < current; i++) {
 309.386 +                        try {
 309.387 +                            listeners[i].vetoableChange(event);
 309.388 +                        }
 309.389 +                        catch (PropertyVetoException exception) {
 309.390 +                            // ignore exceptions that occur during rolling back
 309.391 +                        }
 309.392 +                    }
 309.393 +                    throw veto; // rethrow the veto exception
 309.394 +                }
 309.395 +            }
 309.396 +        }
 309.397 +    }
 309.398 +
 309.399 +    /**
 309.400 +     * Check if there are any listeners for a specific property, including
 309.401 +     * those registered on all properties.  If <code>propertyName</code>
 309.402 +     * is null, only check for listeners registered on all properties.
 309.403 +     *
 309.404 +     * @param propertyName  the property name.
 309.405 +     * @return true if there are one or more listeners for the given property
 309.406 +     */
 309.407 +    public boolean hasListeners(String propertyName) {
 309.408 +        return this.map.hasListeners(propertyName);
 309.409 +    }
 309.410 +
 309.411 +    /**
 309.412 +     * @serialData Null terminated list of <code>VetoableChangeListeners</code>.
 309.413 +     * <p>
 309.414 +     * At serialization time we skip non-serializable listeners and
 309.415 +     * only serialize the serializable listeners.
 309.416 +     */
 309.417 +    private void writeObject(ObjectOutputStream s) throws IOException {
 309.418 +        Hashtable<String, VetoableChangeSupport> children = null;
 309.419 +        VetoableChangeListener[] listeners = null;
 309.420 +        synchronized (this.map) {
 309.421 +            for (Entry<String, VetoableChangeListener[]> entry : this.map.getEntries()) {
 309.422 +                String property = entry.getKey();
 309.423 +                if (property == null) {
 309.424 +                    listeners = entry.getValue();
 309.425 +                } else {
 309.426 +                    if (children == null) {
 309.427 +                        children = new Hashtable<String, VetoableChangeSupport>();
 309.428 +                    }
 309.429 +                    VetoableChangeSupport vcs = new VetoableChangeSupport(this.source);
 309.430 +                    vcs.map.set(null, entry.getValue());
 309.431 +                    children.put(property, vcs);
 309.432 +                }
 309.433 +            }
 309.434 +        }
 309.435 +        ObjectOutputStream.PutField fields = s.putFields();
 309.436 +        fields.put("children", children);
 309.437 +        fields.put("source", this.source);
 309.438 +        fields.put("vetoableChangeSupportSerializedDataVersion", 2);
 309.439 +        s.writeFields();
 309.440 +
 309.441 +        if (listeners != null) {
 309.442 +            for (VetoableChangeListener l : listeners) {
 309.443 +                if (l instanceof Serializable) {
 309.444 +                    s.writeObject(l);
 309.445 +                }
 309.446 +            }
 309.447 +        }
 309.448 +        s.writeObject(null);
 309.449 +    }
 309.450 +
 309.451 +    private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
 309.452 +        this.map = new VetoableChangeListenerMap();
 309.453 +
 309.454 +        ObjectInputStream.GetField fields = s.readFields();
 309.455 +
 309.456 +        Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>) fields.get("children", null);
 309.457 +        this.source = fields.get("source", null);
 309.458 +        fields.get("vetoableChangeSupportSerializedDataVersion", 2);
 309.459 +
 309.460 +        Object listenerOrNull;
 309.461 +        while (null != (listenerOrNull = s.readObject())) {
 309.462 +            this.map.add(null, (VetoableChangeListener)listenerOrNull);
 309.463 +        }
 309.464 +        if (children != null) {
 309.465 +            for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
 309.466 +                for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
 309.467 +                    this.map.add(entry.getKey(), listener);
 309.468 +                }
 309.469 +            }
 309.470 +        }
 309.471 +    }
 309.472 +
 309.473 +    /**
 309.474 +     * The object to be provided as the "source" for any generated events.
 309.475 +     */
 309.476 +    private Object source;
 309.477 +
 309.478 +    /**
 309.479 +     * @serialField children                                   Hashtable
 309.480 +     * @serialField source                                     Object
 309.481 +     * @serialField vetoableChangeSupportSerializedDataVersion int
 309.482 +     */
 309.483 +    private static final ObjectStreamField[] serialPersistentFields = {
 309.484 +            new ObjectStreamField("children", Hashtable.class),
 309.485 +            new ObjectStreamField("source", Object.class),
 309.486 +            new ObjectStreamField("vetoableChangeSupportSerializedDataVersion", Integer.TYPE)
 309.487 +    };
 309.488 +
 309.489 +    /**
 309.490 +     * Serialization version ID, so we're compatible with JDK 1.1
 309.491 +     */
 309.492 +    static final long serialVersionUID = -5090210921595982017L;
 309.493 +
 309.494 +    /**
 309.495 +     * This is a {@link ChangeListenerMap ChangeListenerMap} implementation
 309.496 +     * that works with {@link VetoableChangeListener VetoableChangeListener} objects.
 309.497 +     */
 309.498 +    private static final class VetoableChangeListenerMap extends ChangeListenerMap<VetoableChangeListener> {
 309.499 +        private static final VetoableChangeListener[] EMPTY = {};
 309.500 +
 309.501 +        /**
 309.502 +         * Creates an array of {@link VetoableChangeListener VetoableChangeListener} objects.
 309.503 +         * This method uses the same instance of the empty array
 309.504 +         * when {@code length} equals {@code 0}.
 309.505 +         *
 309.506 +         * @param length  the array length
 309.507 +         * @return        an array with specified length
 309.508 +         */
 309.509 +        @Override
 309.510 +        protected VetoableChangeListener[] newArray(int length) {
 309.511 +            return (0 < length)
 309.512 +                    ? new VetoableChangeListener[length]
 309.513 +                    : EMPTY;
 309.514 +        }
 309.515 +
 309.516 +        /**
 309.517 +         * Creates a {@link VetoableChangeListenerProxy VetoableChangeListenerProxy}
 309.518 +         * object for the specified property.
 309.519 +         *
 309.520 +         * @param name      the name of the property to listen on
 309.521 +         * @param listener  the listener to process events
 309.522 +         * @return          a {@code VetoableChangeListenerProxy} object
 309.523 +         */
 309.524 +        @Override
 309.525 +        protected VetoableChangeListener newProxy(String name, VetoableChangeListener listener) {
 309.526 +            return new VetoableChangeListenerProxy(name, listener);
 309.527 +        }
 309.528 +    }
 309.529 +}
   310.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   310.2 +++ b/rt/emul/compact/src/main/java/java/io/Bits.java	Wed Feb 27 11:24:58 2013 +0100
   310.3 @@ -0,0 +1,123 @@
   310.4 +/*
   310.5 + * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
   310.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   310.7 + *
   310.8 + * This code is free software; you can redistribute it and/or modify it
   310.9 + * under the terms of the GNU General Public License version 2 only, as
  310.10 + * published by the Free Software Foundation.  Oracle designates this
  310.11 + * particular file as subject to the "Classpath" exception as provided
  310.12 + * by Oracle in the LICENSE file that accompanied this code.
  310.13 + *
  310.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  310.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  310.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  310.17 + * version 2 for more details (a copy is included in the LICENSE file that
  310.18 + * accompanied this code).
  310.19 + *
  310.20 + * You should have received a copy of the GNU General Public License version
  310.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  310.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  310.23 + *
  310.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  310.25 + * or visit www.oracle.com if you need additional information or have any
  310.26 + * questions.
  310.27 + */
  310.28 +
  310.29 +package java.io;
  310.30 +
  310.31 +/**
  310.32 + * Utility methods for packing/unpacking primitive values in/out of byte arrays
  310.33 + * using big-endian byte ordering.
  310.34 + */
  310.35 +class Bits {
  310.36 +
  310.37 +    /*
  310.38 +     * Methods for unpacking primitive values from byte arrays starting at
  310.39 +     * given offsets.
  310.40 +     */
  310.41 +
  310.42 +    static boolean getBoolean(byte[] b, int off) {
  310.43 +        return b[off] != 0;
  310.44 +    }
  310.45 +
  310.46 +    static char getChar(byte[] b, int off) {
  310.47 +        return (char) ((b[off + 1] & 0xFF) +
  310.48 +                       (b[off] << 8));
  310.49 +    }
  310.50 +
  310.51 +    static short getShort(byte[] b, int off) {
  310.52 +        return (short) ((b[off + 1] & 0xFF) +
  310.53 +                        (b[off] << 8));
  310.54 +    }
  310.55 +
  310.56 +    static int getInt(byte[] b, int off) {
  310.57 +        return ((b[off + 3] & 0xFF)      ) +
  310.58 +               ((b[off + 2] & 0xFF) <<  8) +
  310.59 +               ((b[off + 1] & 0xFF) << 16) +
  310.60 +               ((b[off    ]       ) << 24);
  310.61 +    }
  310.62 +
  310.63 +    static float getFloat(byte[] b, int off) {
  310.64 +        return Float.intBitsToFloat(getInt(b, off));
  310.65 +    }
  310.66 +
  310.67 +    static long getLong(byte[] b, int off) {
  310.68 +        return ((b[off + 7] & 0xFFL)      ) +
  310.69 +               ((b[off + 6] & 0xFFL) <<  8) +
  310.70 +               ((b[off + 5] & 0xFFL) << 16) +
  310.71 +               ((b[off + 4] & 0xFFL) << 24) +
  310.72 +               ((b[off + 3] & 0xFFL) << 32) +
  310.73 +               ((b[off + 2] & 0xFFL) << 40) +
  310.74 +               ((b[off + 1] & 0xFFL) << 48) +
  310.75 +               (((long) b[off])      << 56);
  310.76 +    }
  310.77 +
  310.78 +    static double getDouble(byte[] b, int off) {
  310.79 +        return Double.longBitsToDouble(getLong(b, off));
  310.80 +    }
  310.81 +
  310.82 +    /*
  310.83 +     * Methods for packing primitive values into byte arrays starting at given
  310.84 +     * offsets.
  310.85 +     */
  310.86 +
  310.87 +    static void putBoolean(byte[] b, int off, boolean val) {
  310.88 +        b[off] = (byte) (val ? 1 : 0);
  310.89 +    }
  310.90 +
  310.91 +    static void putChar(byte[] b, int off, char val) {
  310.92 +        b[off + 1] = (byte) (val      );
  310.93 +        b[off    ] = (byte) (val >>> 8);
  310.94 +    }
  310.95 +
  310.96 +    static void putShort(byte[] b, int off, short val) {
  310.97 +        b[off + 1] = (byte) (val      );
  310.98 +        b[off    ] = (byte) (val >>> 8);
  310.99 +    }
 310.100 +
 310.101 +    static void putInt(byte[] b, int off, int val) {
 310.102 +        b[off + 3] = (byte) (val       );
 310.103 +        b[off + 2] = (byte) (val >>>  8);
 310.104 +        b[off + 1] = (byte) (val >>> 16);
 310.105 +        b[off    ] = (byte) (val >>> 24);
 310.106 +    }
 310.107 +
 310.108 +    static void putFloat(byte[] b, int off, float val) {
 310.109 +        putInt(b, off,  Float.floatToIntBits(val));
 310.110 +    }
 310.111 +
 310.112 +    static void putLong(byte[] b, int off, long val) {
 310.113 +        b[off + 7] = (byte) (val       );
 310.114 +        b[off + 6] = (byte) (val >>>  8);
 310.115 +        b[off + 5] = (byte) (val >>> 16);
 310.116 +        b[off + 4] = (byte) (val >>> 24);
 310.117 +        b[off + 3] = (byte) (val >>> 32);
 310.118 +        b[off + 2] = (byte) (val >>> 40);
 310.119 +        b[off + 1] = (byte) (val >>> 48);
 310.120 +        b[off    ] = (byte) (val >>> 56);
 310.121 +    }
 310.122 +
 310.123 +    static void putDouble(byte[] b, int off, double val) {
 310.124 +        putLong(b, off, Double.doubleToLongBits(val));
 310.125 +    }
 310.126 +}
   311.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   311.2 +++ b/rt/emul/compact/src/main/java/java/io/BufferedOutputStream.java	Wed Feb 27 11:24:58 2013 +0100
   311.3 @@ -0,0 +1,143 @@
   311.4 +/*
   311.5 + * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
   311.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   311.7 + *
   311.8 + * This code is free software; you can redistribute it and/or modify it
   311.9 + * under the terms of the GNU General Public License version 2 only, as
  311.10 + * published by the Free Software Foundation.  Oracle designates this
  311.11 + * particular file as subject to the "Classpath" exception as provided
  311.12 + * by Oracle in the LICENSE file that accompanied this code.
  311.13 + *
  311.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  311.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  311.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  311.17 + * version 2 for more details (a copy is included in the LICENSE file that
  311.18 + * accompanied this code).
  311.19 + *
  311.20 + * You should have received a copy of the GNU General Public License version
  311.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  311.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  311.23 + *
  311.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  311.25 + * or visit www.oracle.com if you need additional information or have any
  311.26 + * questions.
  311.27 + */
  311.28 +
  311.29 +package java.io;
  311.30 +
  311.31 +/**
  311.32 + * The class implements a buffered output stream. By setting up such
  311.33 + * an output stream, an application can write bytes to the underlying
  311.34 + * output stream without necessarily causing a call to the underlying
  311.35 + * system for each byte written.
  311.36 + *
  311.37 + * @author  Arthur van Hoff
  311.38 + * @since   JDK1.0
  311.39 + */
  311.40 +public
  311.41 +class BufferedOutputStream extends FilterOutputStream {
  311.42 +    /**
  311.43 +     * The internal buffer where data is stored.
  311.44 +     */
  311.45 +    protected byte buf[];
  311.46 +
  311.47 +    /**
  311.48 +     * The number of valid bytes in the buffer. This value is always
  311.49 +     * in the range <tt>0</tt> through <tt>buf.length</tt>; elements
  311.50 +     * <tt>buf[0]</tt> through <tt>buf[count-1]</tt> contain valid
  311.51 +     * byte data.
  311.52 +     */
  311.53 +    protected int count;
  311.54 +
  311.55 +    /**
  311.56 +     * Creates a new buffered output stream to write data to the
  311.57 +     * specified underlying output stream.
  311.58 +     *
  311.59 +     * @param   out   the underlying output stream.
  311.60 +     */
  311.61 +    public BufferedOutputStream(OutputStream out) {
  311.62 +        this(out, 8192);
  311.63 +    }
  311.64 +
  311.65 +    /**
  311.66 +     * Creates a new buffered output stream to write data to the
  311.67 +     * specified underlying output stream with the specified buffer
  311.68 +     * size.
  311.69 +     *
  311.70 +     * @param   out    the underlying output stream.
  311.71 +     * @param   size   the buffer size.
  311.72 +     * @exception IllegalArgumentException if size &lt;= 0.
  311.73 +     */
  311.74 +    public BufferedOutputStream(OutputStream out, int size) {
  311.75 +        super(out);
  311.76 +        if (size <= 0) {
  311.77 +            throw new IllegalArgumentException("Buffer size <= 0");
  311.78 +        }
  311.79 +        buf = new byte[size];
  311.80 +    }
  311.81 +
  311.82 +    /** Flush the internal buffer */
  311.83 +    private void flushBuffer() throws IOException {
  311.84 +        if (count > 0) {
  311.85 +            out.write(buf, 0, count);
  311.86 +            count = 0;
  311.87 +        }
  311.88 +    }
  311.89 +
  311.90 +    /**
  311.91 +     * Writes the specified byte to this buffered output stream.
  311.92 +     *
  311.93 +     * @param      b   the byte to be written.
  311.94 +     * @exception  IOException  if an I/O error occurs.
  311.95 +     */
  311.96 +    public synchronized void write(int b) throws IOException {
  311.97 +        if (count >= buf.length) {
  311.98 +            flushBuffer();
  311.99 +        }
 311.100 +        buf[count++] = (byte)b;
 311.101 +    }
 311.102 +
 311.103 +    /**
 311.104 +     * Writes <code>len</code> bytes from the specified byte array
 311.105 +     * starting at offset <code>off</code> to this buffered output stream.
 311.106 +     *
 311.107 +     * <p> Ordinarily this method stores bytes from the given array into this
 311.108 +     * stream's buffer, flushing the buffer to the underlying output stream as
 311.109 +     * needed.  If the requested length is at least as large as this stream's
 311.110 +     * buffer, however, then this method will flush the buffer and write the
 311.111 +     * bytes directly to the underlying output stream.  Thus redundant
 311.112 +     * <code>BufferedOutputStream</code>s will not copy data unnecessarily.
 311.113 +     *
 311.114 +     * @param      b     the data.
 311.115 +     * @param      off   the start offset in the data.
 311.116 +     * @param      len   the number of bytes to write.
 311.117 +     * @exception  IOException  if an I/O error occurs.
 311.118 +     */
 311.119 +    public synchronized void write(byte b[], int off, int len) throws IOException {
 311.120 +        if (len >= buf.length) {
 311.121 +            /* If the request length exceeds the size of the output buffer,
 311.122 +               flush the output buffer and then write the data directly.
 311.123 +               In this way buffered streams will cascade harmlessly. */
 311.124 +            flushBuffer();
 311.125 +            out.write(b, off, len);
 311.126 +            return;
 311.127 +        }
 311.128 +        if (len > buf.length - count) {
 311.129 +            flushBuffer();
 311.130 +        }
 311.131 +        System.arraycopy(b, off, buf, count, len);
 311.132 +        count += len;
 311.133 +    }
 311.134 +
 311.135 +    /**
 311.136 +     * Flushes this buffered output stream. This forces any buffered
 311.137 +     * output bytes to be written out to the underlying output stream.
 311.138 +     *
 311.139 +     * @exception  IOException  if an I/O error occurs.
 311.140 +     * @see        java.io.FilterOutputStream#out
 311.141 +     */
 311.142 +    public synchronized void flush() throws IOException {
 311.143 +        flushBuffer();
 311.144 +        out.flush();
 311.145 +    }
 311.146 +}
   312.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   312.2 +++ b/rt/emul/compact/src/main/java/java/io/BufferedReader.java	Wed Feb 27 11:24:58 2013 +0100
   312.3 @@ -0,0 +1,523 @@
   312.4 +/*
   312.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
   312.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   312.7 + *
   312.8 + * This code is free software; you can redistribute it and/or modify it
   312.9 + * under the terms of the GNU General Public License version 2 only, as
  312.10 + * published by the Free Software Foundation.  Oracle designates this
  312.11 + * particular file as subject to the "Classpath" exception as provided
  312.12 + * by Oracle in the LICENSE file that accompanied this code.
  312.13 + *
  312.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  312.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  312.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  312.17 + * version 2 for more details (a copy is included in the LICENSE file that
  312.18 + * accompanied this code).
  312.19 + *
  312.20 + * You should have received a copy of the GNU General Public License version
  312.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  312.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  312.23 + *
  312.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  312.25 + * or visit www.oracle.com if you need additional information or have any
  312.26 + * questions.
  312.27 + */
  312.28 +
  312.29 +package java.io;
  312.30 +
  312.31 +
  312.32 +
  312.33 +/**
  312.34 + * Reads text from a character-input stream, buffering characters so as to
  312.35 + * provide for the efficient reading of characters, arrays, and lines.
  312.36 + *
  312.37 + * <p> The buffer size may be specified, or the default size may be used.  The
  312.38 + * default is large enough for most purposes.
  312.39 + *
  312.40 + * <p> In general, each read request made of a Reader causes a corresponding
  312.41 + * read request to be made of the underlying character or byte stream.  It is
  312.42 + * therefore advisable to wrap a BufferedReader around any Reader whose read()
  312.43 + * operations may be costly, such as FileReaders and InputStreamReaders.  For
  312.44 + * example,
  312.45 + *
  312.46 + * <pre>
  312.47 + * BufferedReader in
  312.48 + *   = new BufferedReader(new FileReader("foo.in"));
  312.49 + * </pre>
  312.50 + *
  312.51 + * will buffer the input from the specified file.  Without buffering, each
  312.52 + * invocation of read() or readLine() could cause bytes to be read from the
  312.53 + * file, converted into characters, and then returned, which can be very
  312.54 + * inefficient.
  312.55 + *
  312.56 + * <p> Programs that use DataInputStreams for textual input can be localized by
  312.57 + * replacing each DataInputStream with an appropriate BufferedReader.
  312.58 + *
  312.59 + * @see FileReader
  312.60 + * @see InputStreamReader
  312.61 + * @see java.nio.file.Files#newBufferedReader
  312.62 + *
  312.63 + * @author      Mark Reinhold
  312.64 + * @since       JDK1.1
  312.65 + */
  312.66 +
  312.67 +public class BufferedReader extends Reader {
  312.68 +
  312.69 +    private Reader in;
  312.70 +
  312.71 +    private char cb[];
  312.72 +    private int nChars, nextChar;
  312.73 +
  312.74 +    private static final int INVALIDATED = -2;
  312.75 +    private static final int UNMARKED = -1;
  312.76 +    private int markedChar = UNMARKED;
  312.77 +    private int readAheadLimit = 0; /* Valid only when markedChar > 0 */
  312.78 +
  312.79 +    /** If the next character is a line feed, skip it */
  312.80 +    private boolean skipLF = false;
  312.81 +
  312.82 +    /** The skipLF flag when the mark was set */
  312.83 +    private boolean markedSkipLF = false;
  312.84 +
  312.85 +    private static int defaultCharBufferSize = 8192;
  312.86 +    private static int defaultExpectedLineLength = 80;
  312.87 +
  312.88 +    /**
  312.89 +     * Creates a buffering character-input stream that uses an input buffer of
  312.90 +     * the specified size.
  312.91 +     *
  312.92 +     * @param  in   A Reader
  312.93 +     * @param  sz   Input-buffer size
  312.94 +     *
  312.95 +     * @exception  IllegalArgumentException  If sz is <= 0
  312.96 +     */
  312.97 +    public BufferedReader(Reader in, int sz) {
  312.98 +        super(in);
  312.99 +        if (sz <= 0)
 312.100 +            throw new IllegalArgumentException("Buffer size <= 0");
 312.101 +        this.in = in;
 312.102 +        cb = new char[sz];
 312.103 +        nextChar = nChars = 0;
 312.104 +    }
 312.105 +
 312.106 +    /**
 312.107 +     * Creates a buffering character-input stream that uses a default-sized
 312.108 +     * input buffer.
 312.109 +     *
 312.110 +     * @param  in   A Reader
 312.111 +     */
 312.112 +    public BufferedReader(Reader in) {
 312.113 +        this(in, defaultCharBufferSize);
 312.114 +    }
 312.115 +
 312.116 +    /** Checks to make sure that the stream has not been closed */
 312.117 +    private void ensureOpen() throws IOException {
 312.118 +        if (in == null)
 312.119 +            throw new IOException("Stream closed");
 312.120 +    }
 312.121 +
 312.122 +    /**
 312.123 +     * Fills the input buffer, taking the mark into account if it is valid.
 312.124 +     */
 312.125 +    private void fill() throws IOException {
 312.126 +        int dst;
 312.127 +        if (markedChar <= UNMARKED) {
 312.128 +            /* No mark */
 312.129 +            dst = 0;
 312.130 +        } else {
 312.131 +            /* Marked */
 312.132 +            int delta = nextChar - markedChar;
 312.133 +            if (delta >= readAheadLimit) {
 312.134 +                /* Gone past read-ahead limit: Invalidate mark */
 312.135 +                markedChar = INVALIDATED;
 312.136 +                readAheadLimit = 0;
 312.137 +                dst = 0;
 312.138 +            } else {
 312.139 +                if (readAheadLimit <= cb.length) {
 312.140 +                    /* Shuffle in the current buffer */
 312.141 +                    System.arraycopy(cb, markedChar, cb, 0, delta);
 312.142 +                    markedChar = 0;
 312.143 +                    dst = delta;
 312.144 +                } else {
 312.145 +                    /* Reallocate buffer to accommodate read-ahead limit */
 312.146 +                    char ncb[] = new char[readAheadLimit];
 312.147 +                    System.arraycopy(cb, markedChar, ncb, 0, delta);
 312.148 +                    cb = ncb;
 312.149 +                    markedChar = 0;
 312.150 +                    dst = delta;
 312.151 +                }
 312.152 +                nextChar = nChars = delta;
 312.153 +            }
 312.154 +        }
 312.155 +
 312.156 +        int n;
 312.157 +        do {
 312.158 +            n = in.read(cb, dst, cb.length - dst);
 312.159 +        } while (n == 0);
 312.160 +        if (n > 0) {
 312.161 +            nChars = dst + n;
 312.162 +            nextChar = dst;
 312.163 +        }
 312.164 +    }
 312.165 +
 312.166 +    /**
 312.167 +     * Reads a single character.
 312.168 +     *
 312.169 +     * @return The character read, as an integer in the range
 312.170 +     *         0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the
 312.171 +     *         end of the stream has been reached
 312.172 +     * @exception  IOException  If an I/O error occurs
 312.173 +     */
 312.174 +    public int read() throws IOException {
 312.175 +        synchronized (lock) {
 312.176 +            ensureOpen();
 312.177 +            for (;;) {
 312.178 +                if (nextChar >= nChars) {
 312.179 +                    fill();
 312.180 +                    if (nextChar >= nChars)
 312.181 +                        return -1;
 312.182 +                }
 312.183 +                if (skipLF) {
 312.184 +                    skipLF = false;
 312.185 +                    if (cb[nextChar] == '\n') {
 312.186 +                        nextChar++;
 312.187 +                        continue;
 312.188 +                    }
 312.189 +                }
 312.190 +                return cb[nextChar++];
 312.191 +            }
 312.192 +        }
 312.193 +    }
 312.194 +
 312.195 +    /**
 312.196 +     * Reads characters into a portion of an array, reading from the underlying
 312.197 +     * stream if necessary.
 312.198 +     */
 312.199 +    private int read1(char[] cbuf, int off, int len) throws IOException {
 312.200 +        if (nextChar >= nChars) {
 312.201 +            /* If the requested length is at least as large as the buffer, and
 312.202 +               if there is no mark/reset activity, and if line feeds are not
 312.203 +               being skipped, do not bother to copy the characters into the
 312.204 +               local buffer.  In this way buffered streams will cascade
 312.205 +               harmlessly. */
 312.206 +            if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {
 312.207 +                return in.read(cbuf, off, len);
 312.208 +            }
 312.209 +            fill();
 312.210 +        }
 312.211 +        if (nextChar >= nChars) return -1;
 312.212 +        if (skipLF) {
 312.213 +            skipLF = false;
 312.214 +            if (cb[nextChar] == '\n') {
 312.215 +                nextChar++;
 312.216 +                if (nextChar >= nChars)
 312.217 +                    fill();
 312.218 +                if (nextChar >= nChars)
 312.219 +                    return -1;
 312.220 +            }
 312.221 +        }
 312.222 +        int n = Math.min(len, nChars - nextChar);
 312.223 +        System.arraycopy(cb, nextChar, cbuf, off, n);
 312.224 +        nextChar += n;
 312.225 +        return n;
 312.226 +    }
 312.227 +
 312.228 +    /**
 312.229 +     * Reads characters into a portion of an array.
 312.230 +     *
 312.231 +     * <p> This method implements the general contract of the corresponding
 312.232 +     * <code>{@link Reader#read(char[], int, int) read}</code> method of the
 312.233 +     * <code>{@link Reader}</code> class.  As an additional convenience, it
 312.234 +     * attempts to read as many characters as possible by repeatedly invoking
 312.235 +     * the <code>read</code> method of the underlying stream.  This iterated
 312.236 +     * <code>read</code> continues until one of the following conditions becomes
 312.237 +     * true: <ul>
 312.238 +     *
 312.239 +     *   <li> The specified number of characters have been read,
 312.240 +     *
 312.241 +     *   <li> The <code>read</code> method of the underlying stream returns
 312.242 +     *   <code>-1</code>, indicating end-of-file, or
 312.243 +     *
 312.244 +     *   <li> The <code>ready</code> method of the underlying stream
 312.245 +     *   returns <code>false</code>, indicating that further input requests
 312.246 +     *   would block.
 312.247 +     *
 312.248 +     * </ul> If the first <code>read</code> on the underlying stream returns
 312.249 +     * <code>-1</code> to indicate end-of-file then this method returns
 312.250 +     * <code>-1</code>.  Otherwise this method returns the number of characters
 312.251 +     * actually read.
 312.252 +     *
 312.253 +     * <p> Subclasses of this class are encouraged, but not required, to
 312.254 +     * attempt to read as many characters as possible in the same fashion.
 312.255 +     *
 312.256 +     * <p> Ordinarily this method takes characters from this stream's character
 312.257 +     * buffer, filling it from the underlying stream as necessary.  If,
 312.258 +     * however, the buffer is empty, the mark is not valid, and the requested
 312.259 +     * length is at least as large as the buffer, then this method will read
 312.260 +     * characters directly from the underlying stream into the given array.
 312.261 +     * Thus redundant <code>BufferedReader</code>s will not copy data
 312.262 +     * unnecessarily.
 312.263 +     *
 312.264 +     * @param      cbuf  Destination buffer
 312.265 +     * @param      off   Offset at which to start storing characters
 312.266 +     * @param      len   Maximum number of characters to read
 312.267 +     *
 312.268 +     * @return     The number of characters read, or -1 if the end of the
 312.269 +     *             stream has been reached
 312.270 +     *
 312.271 +     * @exception  IOException  If an I/O error occurs
 312.272 +     */
 312.273 +    public int read(char cbuf[], int off, int len) throws IOException {
 312.274 +        synchronized (lock) {
 312.275 +            ensureOpen();
 312.276 +            if ((off < 0) || (off > cbuf.length) || (len < 0) ||
 312.277 +                ((off + len) > cbuf.length) || ((off + len) < 0)) {
 312.278 +                throw new IndexOutOfBoundsException();
 312.279 +            } else if (len == 0) {
 312.280 +                return 0;
 312.281 +            }
 312.282 +
 312.283 +            int n = read1(cbuf, off, len);
 312.284 +            if (n <= 0) return n;
 312.285 +            while ((n < len) && in.ready()) {
 312.286 +                int n1 = read1(cbuf, off + n, len - n);
 312.287 +                if (n1 <= 0) break;
 312.288 +                n += n1;
 312.289 +            }
 312.290 +            return n;
 312.291 +        }
 312.292 +    }
 312.293 +
 312.294 +    /**
 312.295 +     * Reads a line of text.  A line is considered to be terminated by any one
 312.296 +     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
 312.297 +     * followed immediately by a linefeed.
 312.298 +     *
 312.299 +     * @param      ignoreLF  If true, the next '\n' will be skipped
 312.300 +     *
 312.301 +     * @return     A String containing the contents of the line, not including
 312.302 +     *             any line-termination characters, or null if the end of the
 312.303 +     *             stream has been reached
 312.304 +     *
 312.305 +     * @see        java.io.LineNumberReader#readLine()
 312.306 +     *
 312.307 +     * @exception  IOException  If an I/O error occurs
 312.308 +     */
 312.309 +    String readLine(boolean ignoreLF) throws IOException {
 312.310 +        StringBuffer s = null;
 312.311 +        int startChar;
 312.312 +
 312.313 +        synchronized (lock) {
 312.314 +            ensureOpen();
 312.315 +            boolean omitLF = ignoreLF || skipLF;
 312.316 +
 312.317 +        bufferLoop:
 312.318 +            for (;;) {
 312.319 +
 312.320 +                if (nextChar >= nChars)
 312.321 +                    fill();
 312.322 +                if (nextChar >= nChars) { /* EOF */
 312.323 +                    if (s != null && s.length() > 0)
 312.324 +                        return s.toString();
 312.325 +                    else
 312.326 +                        return null;
 312.327 +                }
 312.328 +                boolean eol = false;
 312.329 +                char c = 0;
 312.330 +                int i;
 312.331 +
 312.332 +                /* Skip a leftover '\n', if necessary */
 312.333 +                if (omitLF && (cb[nextChar] == '\n'))
 312.334 +                    nextChar++;
 312.335 +                skipLF = false;
 312.336 +                omitLF = false;
 312.337 +
 312.338 +            charLoop:
 312.339 +                for (i = nextChar; i < nChars; i++) {
 312.340 +                    c = cb[i];
 312.341 +                    if ((c == '\n') || (c == '\r')) {
 312.342 +                        eol = true;
 312.343 +                        break charLoop;
 312.344 +                    }
 312.345 +                }
 312.346 +
 312.347 +                startChar = nextChar;
 312.348 +                nextChar = i;
 312.349 +
 312.350 +                if (eol) {
 312.351 +                    String str;
 312.352 +                    if (s == null) {
 312.353 +                        str = new String(cb, startChar, i - startChar);
 312.354 +                    } else {
 312.355 +                        s.append(cb, startChar, i - startChar);
 312.356 +                        str = s.toString();
 312.357 +                    }
 312.358 +                    nextChar++;
 312.359 +                    if (c == '\r') {
 312.360 +                        skipLF = true;
 312.361 +                    }
 312.362 +                    return str;
 312.363 +                }
 312.364 +
 312.365 +                if (s == null)
 312.366 +                    s = new StringBuffer(defaultExpectedLineLength);
 312.367 +                s.append(cb, startChar, i - startChar);
 312.368 +            }
 312.369 +        }
 312.370 +    }
 312.371 +
 312.372 +    /**
 312.373 +     * Reads a line of text.  A line is considered to be terminated by any one
 312.374 +     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
 312.375 +     * followed immediately by a linefeed.
 312.376 +     *
 312.377 +     * @return     A String containing the contents of the line, not including
 312.378 +     *             any line-termination characters, or null if the end of the
 312.379 +     *             stream has been reached
 312.380 +     *
 312.381 +     * @exception  IOException  If an I/O error occurs
 312.382 +     *
 312.383 +     * @see java.nio.file.Files#readAllLines
 312.384 +     */
 312.385 +    public String readLine() throws IOException {
 312.386 +        return readLine(false);
 312.387 +    }
 312.388 +
 312.389 +    /**
 312.390 +     * Skips characters.
 312.391 +     *
 312.392 +     * @param  n  The number of characters to skip
 312.393 +     *
 312.394 +     * @return    The number of characters actually skipped
 312.395 +     *
 312.396 +     * @exception  IllegalArgumentException  If <code>n</code> is negative.
 312.397 +     * @exception  IOException  If an I/O error occurs
 312.398 +     */
 312.399 +    public long skip(long n) throws IOException {
 312.400 +        if (n < 0L) {
 312.401 +            throw new IllegalArgumentException("skip value is negative");
 312.402 +        }
 312.403 +        synchronized (lock) {
 312.404 +            ensureOpen();
 312.405 +            long r = n;
 312.406 +            while (r > 0) {
 312.407 +                if (nextChar >= nChars)
 312.408 +                    fill();
 312.409 +                if (nextChar >= nChars) /* EOF */
 312.410 +                    break;
 312.411 +                if (skipLF) {
 312.412 +                    skipLF = false;
 312.413 +                    if (cb[nextChar] == '\n') {
 312.414 +                        nextChar++;
 312.415 +                    }
 312.416 +                }
 312.417 +                long d = nChars - nextChar;
 312.418 +                if (r <= d) {
 312.419 +                    nextChar += r;
 312.420 +                    r = 0;
 312.421 +                    break;
 312.422 +                }
 312.423 +                else {
 312.424 +                    r -= d;
 312.425 +                    nextChar = nChars;
 312.426 +                }
 312.427 +            }
 312.428 +            return n - r;
 312.429 +        }
 312.430 +    }
 312.431 +
 312.432 +    /**
 312.433 +     * Tells whether this stream is ready to be read.  A buffered character
 312.434 +     * stream is ready if the buffer is not empty, or if the underlying
 312.435 +     * character stream is ready.
 312.436 +     *
 312.437 +     * @exception  IOException  If an I/O error occurs
 312.438 +     */
 312.439 +    public boolean ready() throws IOException {
 312.440 +        synchronized (lock) {
 312.441 +            ensureOpen();
 312.442 +
 312.443 +            /*
 312.444 +             * If newline needs to be skipped and the next char to be read
 312.445 +             * is a newline character, then just skip it right away.
 312.446 +             */
 312.447 +            if (skipLF) {
 312.448 +                /* Note that in.ready() will return true if and only if the next
 312.449 +                 * read on the stream will not block.
 312.450 +                 */
 312.451 +                if (nextChar >= nChars && in.ready()) {
 312.452 +                    fill();
 312.453 +                }
 312.454 +                if (nextChar < nChars) {
 312.455 +                    if (cb[nextChar] == '\n')
 312.456 +                        nextChar++;
 312.457 +                    skipLF = false;
 312.458 +                }
 312.459 +            }
 312.460 +            return (nextChar < nChars) || in.ready();
 312.461 +        }
 312.462 +    }
 312.463 +
 312.464 +    /**
 312.465 +     * Tells whether this stream supports the mark() operation, which it does.
 312.466 +     */
 312.467 +    public boolean markSupported() {
 312.468 +        return true;
 312.469 +    }
 312.470 +
 312.471 +    /**
 312.472 +     * Marks the present position in the stream.  Subsequent calls to reset()
 312.473 +     * will attempt to reposition the stream to this point.
 312.474 +     *
 312.475 +     * @param readAheadLimit   Limit on the number of characters that may be
 312.476 +     *                         read while still preserving the mark. An attempt
 312.477 +     *                         to reset the stream after reading characters
 312.478 +     *                         up to this limit or beyond may fail.
 312.479 +     *                         A limit value larger than the size of the input
 312.480 +     *                         buffer will cause a new buffer to be allocated
 312.481 +     *                         whose size is no smaller than limit.
 312.482 +     *                         Therefore large values should be used with care.
 312.483 +     *
 312.484 +     * @exception  IllegalArgumentException  If readAheadLimit is < 0
 312.485 +     * @exception  IOException  If an I/O error occurs
 312.486 +     */
 312.487 +    public void mark(int readAheadLimit) throws IOException {
 312.488 +        if (readAheadLimit < 0) {
 312.489 +            throw new IllegalArgumentException("Read-ahead limit < 0");
 312.490 +        }
 312.491 +        synchronized (lock) {
 312.492 +            ensureOpen();
 312.493 +            this.readAheadLimit = readAheadLimit;
 312.494 +            markedChar = nextChar;
 312.495 +            markedSkipLF = skipLF;
 312.496 +        }
 312.497 +    }
 312.498 +
 312.499 +    /**
 312.500 +     * Resets the stream to the most recent mark.
 312.501 +     *
 312.502 +     * @exception  IOException  If the stream has never been marked,
 312.503 +     *                          or if the mark has been invalidated
 312.504 +     */
 312.505 +    public void reset() throws IOException {
 312.506 +        synchronized (lock) {
 312.507 +            ensureOpen();
 312.508 +            if (markedChar < 0)
 312.509 +                throw new IOException((markedChar == INVALIDATED)
 312.510 +                                      ? "Mark invalid"
 312.511 +                                      : "Stream not marked");
 312.512 +            nextChar = markedChar;
 312.513 +            skipLF = markedSkipLF;
 312.514 +        }
 312.515 +    }
 312.516 +
 312.517 +    public void close() throws IOException {
 312.518 +        synchronized (lock) {
 312.519 +            if (in == null)
 312.520 +                return;
 312.521 +            in.close();
 312.522 +            in = null;
 312.523 +            cb = null;
 312.524 +        }
 312.525 +    }
 312.526 +}
   313.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   313.2 +++ b/rt/emul/compact/src/main/java/java/io/ByteArrayOutputStream.java	Wed Feb 27 11:24:58 2013 +0100
   313.3 @@ -0,0 +1,272 @@
   313.4 +/*
   313.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   313.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   313.7 + *
   313.8 + * This code is free software; you can redistribute it and/or modify it
   313.9 + * under the terms of the GNU General Public License version 2 only, as
  313.10 + * published by the Free Software Foundation.  Oracle designates this
  313.11 + * particular file as subject to the "Classpath" exception as provided
  313.12 + * by Oracle in the LICENSE file that accompanied this code.
  313.13 + *
  313.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  313.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  313.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  313.17 + * version 2 for more details (a copy is included in the LICENSE file that
  313.18 + * accompanied this code).
  313.19 + *
  313.20 + * You should have received a copy of the GNU General Public License version
  313.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  313.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  313.23 + *
  313.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  313.25 + * or visit www.oracle.com if you need additional information or have any
  313.26 + * questions.
  313.27 + */
  313.28 +
  313.29 +package java.io;
  313.30 +
  313.31 +import java.util.Arrays;
  313.32 +
  313.33 +/**
  313.34 + * This class implements an output stream in which the data is
  313.35 + * written into a byte array. The buffer automatically grows as data
  313.36 + * is written to it.
  313.37 + * The data can be retrieved using <code>toByteArray()</code> and
  313.38 + * <code>toString()</code>.
  313.39 + * <p>
  313.40 + * Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
  313.41 + * this class can be called after the stream has been closed without
  313.42 + * generating an <tt>IOException</tt>.
  313.43 + *
  313.44 + * @author  Arthur van Hoff
  313.45 + * @since   JDK1.0
  313.46 + */
  313.47 +
  313.48 +public class ByteArrayOutputStream extends OutputStream {
  313.49 +
  313.50 +    /**
  313.51 +     * The buffer where data is stored.
  313.52 +     */
  313.53 +    protected byte buf[];
  313.54 +
  313.55 +    /**
  313.56 +     * The number of valid bytes in the buffer.
  313.57 +     */
  313.58 +    protected int count;
  313.59 +
  313.60 +    /**
  313.61 +     * Creates a new byte array output stream. The buffer capacity is
  313.62 +     * initially 32 bytes, though its size increases if necessary.
  313.63 +     */
  313.64 +    public ByteArrayOutputStream() {
  313.65 +        this(32);
  313.66 +    }
  313.67 +
  313.68 +    /**
  313.69 +     * Creates a new byte array output stream, with a buffer capacity of
  313.70 +     * the specified size, in bytes.
  313.71 +     *
  313.72 +     * @param   size   the initial size.
  313.73 +     * @exception  IllegalArgumentException if size is negative.
  313.74 +     */
  313.75 +    public ByteArrayOutputStream(int size) {
  313.76 +        if (size < 0) {
  313.77 +            throw new IllegalArgumentException("Negative initial size: "
  313.78 +                                               + size);
  313.79 +        }
  313.80 +        buf = new byte[size];
  313.81 +    }
  313.82 +
  313.83 +    /**
  313.84 +     * Increases the capacity if necessary to ensure that it can hold
  313.85 +     * at least the number of elements specified by the minimum
  313.86 +     * capacity argument.
  313.87 +     *
  313.88 +     * @param minCapacity the desired minimum capacity
  313.89 +     * @throws OutOfMemoryError if {@code minCapacity < 0}.  This is
  313.90 +     * interpreted as a request for the unsatisfiably large capacity
  313.91 +     * {@code (long) Integer.MAX_VALUE + (minCapacity - Integer.MAX_VALUE)}.
  313.92 +     */
  313.93 +    private void ensureCapacity(int minCapacity) {
  313.94 +        // overflow-conscious code
  313.95 +        if (minCapacity - buf.length > 0)
  313.96 +            grow(minCapacity);
  313.97 +    }
  313.98 +
  313.99 +    /**
 313.100 +     * Increases the capacity to ensure that it can hold at least the
 313.101 +     * number of elements specified by the minimum capacity argument.
 313.102 +     *
 313.103 +     * @param minCapacity the desired minimum capacity
 313.104 +     */
 313.105 +    private void grow(int minCapacity) {
 313.106 +        // overflow-conscious code
 313.107 +        int oldCapacity = buf.length;
 313.108 +        int newCapacity = oldCapacity << 1;
 313.109 +        if (newCapacity - minCapacity < 0)
 313.110 +            newCapacity = minCapacity;
 313.111 +        if (newCapacity < 0) {
 313.112 +            if (minCapacity < 0) // overflow
 313.113 +                throw new OutOfMemoryError();
 313.114 +            newCapacity = Integer.MAX_VALUE;
 313.115 +        }
 313.116 +        buf = Arrays.copyOf(buf, newCapacity);
 313.117 +    }
 313.118 +
 313.119 +    /**
 313.120 +     * Writes the specified byte to this byte array output stream.
 313.121 +     *
 313.122 +     * @param   b   the byte to be written.
 313.123 +     */
 313.124 +    public synchronized void write(int b) {
 313.125 +        ensureCapacity(count + 1);
 313.126 +        buf[count] = (byte) b;
 313.127 +        count += 1;
 313.128 +    }
 313.129 +
 313.130 +    /**
 313.131 +     * Writes <code>len</code> bytes from the specified byte array
 313.132 +     * starting at offset <code>off</code> to this byte array output stream.
 313.133 +     *
 313.134 +     * @param   b     the data.
 313.135 +     * @param   off   the start offset in the data.
 313.136 +     * @param   len   the number of bytes to write.
 313.137 +     */
 313.138 +    public synchronized void write(byte b[], int off, int len) {
 313.139 +        if ((off < 0) || (off > b.length) || (len < 0) ||
 313.140 +            ((off + len) - b.length > 0)) {
 313.141 +            throw new IndexOutOfBoundsException();
 313.142 +        }
 313.143 +        ensureCapacity(count + len);
 313.144 +        System.arraycopy(b, off, buf, count, len);
 313.145 +        count += len;
 313.146 +    }
 313.147 +
 313.148 +    /**
 313.149 +     * Writes the complete contents of this byte array output stream to
 313.150 +     * the specified output stream argument, as if by calling the output
 313.151 +     * stream's write method using <code>out.write(buf, 0, count)</code>.
 313.152 +     *
 313.153 +     * @param      out   the output stream to which to write the data.
 313.154 +     * @exception  IOException  if an I/O error occurs.
 313.155 +     */
 313.156 +    public synchronized void writeTo(OutputStream out) throws IOException {
 313.157 +        out.write(buf, 0, count);
 313.158 +    }
 313.159 +
 313.160 +    /**
 313.161 +     * Resets the <code>count</code> field of this byte array output
 313.162 +     * stream to zero, so that all currently accumulated output in the
 313.163 +     * output stream is discarded. The output stream can be used again,
 313.164 +     * reusing the already allocated buffer space.
 313.165 +     *
 313.166 +     * @see     java.io.ByteArrayInputStream#count
 313.167 +     */
 313.168 +    public synchronized void reset() {
 313.169 +        count = 0;
 313.170 +    }
 313.171 +
 313.172 +    /**
 313.173 +     * Creates a newly allocated byte array. Its size is the current
 313.174 +     * size of this output stream and the valid contents of the buffer
 313.175 +     * have been copied into it.
 313.176 +     *
 313.177 +     * @return  the current contents of this output stream, as a byte array.
 313.178 +     * @see     java.io.ByteArrayOutputStream#size()
 313.179 +     */
 313.180 +    public synchronized byte toByteArray()[] {
 313.181 +        return Arrays.copyOf(buf, count);
 313.182 +    }
 313.183 +
 313.184 +    /**
 313.185 +     * Returns the current size of the buffer.
 313.186 +     *
 313.187 +     * @return  the value of the <code>count</code> field, which is the number
 313.188 +     *          of valid bytes in this output stream.
 313.189 +     * @see     java.io.ByteArrayOutputStream#count
 313.190 +     */
 313.191 +    public synchronized int size() {
 313.192 +        return count;
 313.193 +    }
 313.194 +
 313.195 +    /**
 313.196 +     * Converts the buffer's contents into a string decoding bytes using the
 313.197 +     * platform's default character set. The length of the new <tt>String</tt>
 313.198 +     * is a function of the character set, and hence may not be equal to the
 313.199 +     * size of the buffer.
 313.200 +     *
 313.201 +     * <p> This method always replaces malformed-input and unmappable-character
 313.202 +     * sequences with the default replacement string for the platform's
 313.203 +     * default character set. The {@linkplain java.nio.charset.CharsetDecoder}
 313.204 +     * class should be used when more control over the decoding process is
 313.205 +     * required.
 313.206 +     *
 313.207 +     * @return String decoded from the buffer's contents.
 313.208 +     * @since  JDK1.1
 313.209 +     */
 313.210 +    public synchronized String toString() {
 313.211 +        return new String(buf, 0, count);
 313.212 +    }
 313.213 +
 313.214 +    /**
 313.215 +     * Converts the buffer's contents into a string by decoding the bytes using
 313.216 +     * the specified {@link java.nio.charset.Charset charsetName}. The length of
 313.217 +     * the new <tt>String</tt> is a function of the charset, and hence may not be
 313.218 +     * equal to the length of the byte array.
 313.219 +     *
 313.220 +     * <p> This method always replaces malformed-input and unmappable-character
 313.221 +     * sequences with this charset's default replacement string. The {@link
 313.222 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 313.223 +     * over the decoding process is required.
 313.224 +     *
 313.225 +     * @param  charsetName  the name of a supported
 313.226 +     *              {@linkplain java.nio.charset.Charset </code>charset<code>}
 313.227 +     * @return String decoded from the buffer's contents.
 313.228 +     * @exception  UnsupportedEncodingException
 313.229 +     *             If the named charset is not supported
 313.230 +     * @since   JDK1.1
 313.231 +     */
 313.232 +    public synchronized String toString(String charsetName)
 313.233 +        throws UnsupportedEncodingException
 313.234 +    {
 313.235 +        return new String(buf, 0, count, charsetName);
 313.236 +    }
 313.237 +
 313.238 +    /**
 313.239 +     * Creates a newly allocated string. Its size is the current size of
 313.240 +     * the output stream and the valid contents of the buffer have been
 313.241 +     * copied into it. Each character <i>c</i> in the resulting string is
 313.242 +     * constructed from the corresponding element <i>b</i> in the byte
 313.243 +     * array such that:
 313.244 +     * <blockquote><pre>
 313.245 +     *     c == (char)(((hibyte &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
 313.246 +     * </pre></blockquote>
 313.247 +     *
 313.248 +     * @deprecated This method does not properly convert bytes into characters.
 313.249 +     * As of JDK&nbsp;1.1, the preferred way to do this is via the
 313.250 +     * <code>toString(String enc)</code> method, which takes an encoding-name
 313.251 +     * argument, or the <code>toString()</code> method, which uses the
 313.252 +     * platform's default character encoding.
 313.253 +     *
 313.254 +     * @param      hibyte    the high byte of each resulting Unicode character.
 313.255 +     * @return     the current contents of the output stream, as a string.
 313.256 +     * @see        java.io.ByteArrayOutputStream#size()
 313.257 +     * @see        java.io.ByteArrayOutputStream#toString(String)
 313.258 +     * @see        java.io.ByteArrayOutputStream#toString()
 313.259 +     */
 313.260 +    @Deprecated
 313.261 +    public synchronized String toString(int hibyte) {
 313.262 +        return new String(buf, hibyte, 0, count);
 313.263 +    }
 313.264 +
 313.265 +    /**
 313.266 +     * Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
 313.267 +     * this class can be called after the stream has been closed without
 313.268 +     * generating an <tt>IOException</tt>.
 313.269 +     * <p>
 313.270 +     *
 313.271 +     */
 313.272 +    public void close() throws IOException {
 313.273 +    }
 313.274 +
 313.275 +}
   314.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   314.2 +++ b/rt/emul/compact/src/main/java/java/io/DataOutput.java	Wed Feb 27 11:24:58 2013 +0100
   314.3 @@ -0,0 +1,354 @@
   314.4 +/*
   314.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
   314.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   314.7 + *
   314.8 + * This code is free software; you can redistribute it and/or modify it
   314.9 + * under the terms of the GNU General Public License version 2 only, as
  314.10 + * published by the Free Software Foundation.  Oracle designates this
  314.11 + * particular file as subject to the "Classpath" exception as provided
  314.12 + * by Oracle in the LICENSE file that accompanied this code.
  314.13 + *
  314.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  314.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  314.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  314.17 + * version 2 for more details (a copy is included in the LICENSE file that
  314.18 + * accompanied this code).
  314.19 + *
  314.20 + * You should have received a copy of the GNU General Public License version
  314.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  314.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  314.23 + *
  314.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  314.25 + * or visit www.oracle.com if you need additional information or have any
  314.26 + * questions.
  314.27 + */
  314.28 +
  314.29 +package java.io;
  314.30 +
  314.31 +/**
  314.32 + * The <code>DataOutput</code> interface provides
  314.33 + * for converting data from any of the Java
  314.34 + * primitive types to a series of bytes and
  314.35 + * writing these bytes to a binary stream.
  314.36 + * There is  also a facility for converting
  314.37 + * a <code>String</code> into
  314.38 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  314.39 + * format and writing the resulting series
  314.40 + * of bytes.
  314.41 + * <p>
  314.42 + * For all the methods in this interface that
  314.43 + * write bytes, it is generally true that if
  314.44 + * a byte cannot be written for any reason,
  314.45 + * an <code>IOException</code> is thrown.
  314.46 + *
  314.47 + * @author  Frank Yellin
  314.48 + * @see     java.io.DataInput
  314.49 + * @see     java.io.DataOutputStream
  314.50 + * @since   JDK1.0
  314.51 + */
  314.52 +public
  314.53 +interface DataOutput {
  314.54 +    /**
  314.55 +     * Writes to the output stream the eight
  314.56 +     * low-order bits of the argument <code>b</code>.
  314.57 +     * The 24 high-order  bits of <code>b</code>
  314.58 +     * are ignored.
  314.59 +     *
  314.60 +     * @param      b   the byte to be written.
  314.61 +     * @throws     IOException  if an I/O error occurs.
  314.62 +     */
  314.63 +    void write(int b) throws IOException;
  314.64 +
  314.65 +    /**
  314.66 +     * Writes to the output stream all the bytes in array <code>b</code>.
  314.67 +     * If <code>b</code> is <code>null</code>,
  314.68 +     * a <code>NullPointerException</code> is thrown.
  314.69 +     * If <code>b.length</code> is zero, then
  314.70 +     * no bytes are written. Otherwise, the byte
  314.71 +     * <code>b[0]</code> is written first, then
  314.72 +     * <code>b[1]</code>, and so on; the last byte
  314.73 +     * written is <code>b[b.length-1]</code>.
  314.74 +     *
  314.75 +     * @param      b   the data.
  314.76 +     * @throws     IOException  if an I/O error occurs.
  314.77 +     */
  314.78 +    void write(byte b[]) throws IOException;
  314.79 +
  314.80 +    /**
  314.81 +     * Writes <code>len</code> bytes from array
  314.82 +     * <code>b</code>, in order,  to
  314.83 +     * the output stream.  If <code>b</code>
  314.84 +     * is <code>null</code>, a <code>NullPointerException</code>
  314.85 +     * is thrown.  If <code>off</code> is negative,
  314.86 +     * or <code>len</code> is negative, or <code>off+len</code>
  314.87 +     * is greater than the length of the array
  314.88 +     * <code>b</code>, then an <code>IndexOutOfBoundsException</code>
  314.89 +     * is thrown.  If <code>len</code> is zero,
  314.90 +     * then no bytes are written. Otherwise, the
  314.91 +     * byte <code>b[off]</code> is written first,
  314.92 +     * then <code>b[off+1]</code>, and so on; the
  314.93 +     * last byte written is <code>b[off+len-1]</code>.
  314.94 +     *
  314.95 +     * @param      b     the data.
  314.96 +     * @param      off   the start offset in the data.
  314.97 +     * @param      len   the number of bytes to write.
  314.98 +     * @throws     IOException  if an I/O error occurs.
  314.99 +     */
 314.100 +    void write(byte b[], int off, int len) throws IOException;
 314.101 +
 314.102 +    /**
 314.103 +     * Writes a <code>boolean</code> value to this output stream.
 314.104 +     * If the argument <code>v</code>
 314.105 +     * is <code>true</code>, the value <code>(byte)1</code>
 314.106 +     * is written; if <code>v</code> is <code>false</code>,
 314.107 +     * the  value <code>(byte)0</code> is written.
 314.108 +     * The byte written by this method may
 314.109 +     * be read by the <code>readBoolean</code>
 314.110 +     * method of interface <code>DataInput</code>,
 314.111 +     * which will then return a <code>boolean</code>
 314.112 +     * equal to <code>v</code>.
 314.113 +     *
 314.114 +     * @param      v   the boolean to be written.
 314.115 +     * @throws     IOException  if an I/O error occurs.
 314.116 +     */
 314.117 +    void writeBoolean(boolean v) throws IOException;
 314.118 +
 314.119 +    /**
 314.120 +     * Writes to the output stream the eight low-
 314.121 +     * order bits of the argument <code>v</code>.
 314.122 +     * The 24 high-order bits of <code>v</code>
 314.123 +     * are ignored. (This means  that <code>writeByte</code>
 314.124 +     * does exactly the same thing as <code>write</code>
 314.125 +     * for an integer argument.) The byte written
 314.126 +     * by this method may be read by the <code>readByte</code>
 314.127 +     * method of interface <code>DataInput</code>,
 314.128 +     * which will then return a <code>byte</code>
 314.129 +     * equal to <code>(byte)v</code>.
 314.130 +     *
 314.131 +     * @param      v   the byte value to be written.
 314.132 +     * @throws     IOException  if an I/O error occurs.
 314.133 +     */
 314.134 +    void writeByte(int v) throws IOException;
 314.135 +
 314.136 +    /**
 314.137 +     * Writes two bytes to the output
 314.138 +     * stream to represent the value of the argument.
 314.139 +     * The byte values to be written, in the  order
 314.140 +     * shown, are: <p>
 314.141 +     * <pre><code>
 314.142 +     * (byte)(0xff &amp; (v &gt;&gt; 8))
 314.143 +     * (byte)(0xff &amp; v)
 314.144 +     * </code> </pre> <p>
 314.145 +     * The bytes written by this method may be
 314.146 +     * read by the <code>readShort</code> method
 314.147 +     * of interface <code>DataInput</code> , which
 314.148 +     * will then return a <code>short</code> equal
 314.149 +     * to <code>(short)v</code>.
 314.150 +     *
 314.151 +     * @param      v   the <code>short</code> value to be written.
 314.152 +     * @throws     IOException  if an I/O error occurs.
 314.153 +     */
 314.154 +    void writeShort(int v) throws IOException;
 314.155 +
 314.156 +    /**
 314.157 +     * Writes a <code>char</code> value, which
 314.158 +     * is comprised of two bytes, to the
 314.159 +     * output stream.
 314.160 +     * The byte values to be written, in the  order
 314.161 +     * shown, are:
 314.162 +     * <p><pre><code>
 314.163 +     * (byte)(0xff &amp; (v &gt;&gt; 8))
 314.164 +     * (byte)(0xff &amp; v)
 314.165 +     * </code></pre><p>
 314.166 +     * The bytes written by this method may be
 314.167 +     * read by the <code>readChar</code> method
 314.168 +     * of interface <code>DataInput</code> , which
 314.169 +     * will then return a <code>char</code> equal
 314.170 +     * to <code>(char)v</code>.
 314.171 +     *
 314.172 +     * @param      v   the <code>char</code> value to be written.
 314.173 +     * @throws     IOException  if an I/O error occurs.
 314.174 +     */
 314.175 +    void writeChar(int v) throws IOException;
 314.176 +
 314.177 +    /**
 314.178 +     * Writes an <code>int</code> value, which is
 314.179 +     * comprised of four bytes, to the output stream.
 314.180 +     * The byte values to be written, in the  order
 314.181 +     * shown, are:
 314.182 +     * <p><pre><code>
 314.183 +     * (byte)(0xff &amp; (v &gt;&gt; 24))
 314.184 +     * (byte)(0xff &amp; (v &gt;&gt; 16))
 314.185 +     * (byte)(0xff &amp; (v &gt;&gt; &#32; &#32;8))
 314.186 +     * (byte)(0xff &amp; v)
 314.187 +     * </code></pre><p>
 314.188 +     * The bytes written by this method may be read
 314.189 +     * by the <code>readInt</code> method of interface
 314.190 +     * <code>DataInput</code> , which will then
 314.191 +     * return an <code>int</code> equal to <code>v</code>.
 314.192 +     *
 314.193 +     * @param      v   the <code>int</code> value to be written.
 314.194 +     * @throws     IOException  if an I/O error occurs.
 314.195 +     */
 314.196 +    void writeInt(int v) throws IOException;
 314.197 +
 314.198 +    /**
 314.199 +     * Writes a <code>long</code> value, which is
 314.200 +     * comprised of eight bytes, to the output stream.
 314.201 +     * The byte values to be written, in the  order
 314.202 +     * shown, are:
 314.203 +     * <p><pre><code>
 314.204 +     * (byte)(0xff &amp; (v &gt;&gt; 56))
 314.205 +     * (byte)(0xff &amp; (v &gt;&gt; 48))
 314.206 +     * (byte)(0xff &amp; (v &gt;&gt; 40))
 314.207 +     * (byte)(0xff &amp; (v &gt;&gt; 32))
 314.208 +     * (byte)(0xff &amp; (v &gt;&gt; 24))
 314.209 +     * (byte)(0xff &amp; (v &gt;&gt; 16))
 314.210 +     * (byte)(0xff &amp; (v &gt;&gt;  8))
 314.211 +     * (byte)(0xff &amp; v)
 314.212 +     * </code></pre><p>
 314.213 +     * The bytes written by this method may be
 314.214 +     * read by the <code>readLong</code> method
 314.215 +     * of interface <code>DataInput</code> , which
 314.216 +     * will then return a <code>long</code> equal
 314.217 +     * to <code>v</code>.
 314.218 +     *
 314.219 +     * @param      v   the <code>long</code> value to be written.
 314.220 +     * @throws     IOException  if an I/O error occurs.
 314.221 +     */
 314.222 +    void writeLong(long v) throws IOException;
 314.223 +
 314.224 +    /**
 314.225 +     * Writes a <code>float</code> value,
 314.226 +     * which is comprised of four bytes, to the output stream.
 314.227 +     * It does this as if it first converts this
 314.228 +     * <code>float</code> value to an <code>int</code>
 314.229 +     * in exactly the manner of the <code>Float.floatToIntBits</code>
 314.230 +     * method  and then writes the <code>int</code>
 314.231 +     * value in exactly the manner of the  <code>writeInt</code>
 314.232 +     * method.  The bytes written by this method
 314.233 +     * may be read by the <code>readFloat</code>
 314.234 +     * method of interface <code>DataInput</code>,
 314.235 +     * which will then return a <code>float</code>
 314.236 +     * equal to <code>v</code>.
 314.237 +     *
 314.238 +     * @param      v   the <code>float</code> value to be written.
 314.239 +     * @throws     IOException  if an I/O error occurs.
 314.240 +     */
 314.241 +    void writeFloat(float v) throws IOException;
 314.242 +
 314.243 +    /**
 314.244 +     * Writes a <code>double</code> value,
 314.245 +     * which is comprised of eight bytes, to the output stream.
 314.246 +     * It does this as if it first converts this
 314.247 +     * <code>double</code> value to a <code>long</code>
 314.248 +     * in exactly the manner of the <code>Double.doubleToLongBits</code>
 314.249 +     * method  and then writes the <code>long</code>
 314.250 +     * value in exactly the manner of the  <code>writeLong</code>
 314.251 +     * method. The bytes written by this method
 314.252 +     * may be read by the <code>readDouble</code>
 314.253 +     * method of interface <code>DataInput</code>,
 314.254 +     * which will then return a <code>double</code>
 314.255 +     * equal to <code>v</code>.
 314.256 +     *
 314.257 +     * @param      v   the <code>double</code> value to be written.
 314.258 +     * @throws     IOException  if an I/O error occurs.
 314.259 +     */
 314.260 +    void writeDouble(double v) throws IOException;
 314.261 +
 314.262 +    /**
 314.263 +     * Writes a string to the output stream.
 314.264 +     * For every character in the string
 314.265 +     * <code>s</code>,  taken in order, one byte
 314.266 +     * is written to the output stream.  If
 314.267 +     * <code>s</code> is <code>null</code>, a <code>NullPointerException</code>
 314.268 +     * is thrown.<p>  If <code>s.length</code>
 314.269 +     * is zero, then no bytes are written. Otherwise,
 314.270 +     * the character <code>s[0]</code> is written
 314.271 +     * first, then <code>s[1]</code>, and so on;
 314.272 +     * the last character written is <code>s[s.length-1]</code>.
 314.273 +     * For each character, one byte is written,
 314.274 +     * the low-order byte, in exactly the manner
 314.275 +     * of the <code>writeByte</code> method . The
 314.276 +     * high-order eight bits of each character
 314.277 +     * in the string are ignored.
 314.278 +     *
 314.279 +     * @param      s   the string of bytes to be written.
 314.280 +     * @throws     IOException  if an I/O error occurs.
 314.281 +     */
 314.282 +    void writeBytes(String s) throws IOException;
 314.283 +
 314.284 +    /**
 314.285 +     * Writes every character in the string <code>s</code>,
 314.286 +     * to the output stream, in order,
 314.287 +     * two bytes per character. If <code>s</code>
 314.288 +     * is <code>null</code>, a <code>NullPointerException</code>
 314.289 +     * is thrown.  If <code>s.length</code>
 314.290 +     * is zero, then no characters are written.
 314.291 +     * Otherwise, the character <code>s[0]</code>
 314.292 +     * is written first, then <code>s[1]</code>,
 314.293 +     * and so on; the last character written is
 314.294 +     * <code>s[s.length-1]</code>. For each character,
 314.295 +     * two bytes are actually written, high-order
 314.296 +     * byte first, in exactly the manner of the
 314.297 +     * <code>writeChar</code> method.
 314.298 +     *
 314.299 +     * @param      s   the string value to be written.
 314.300 +     * @throws     IOException  if an I/O error occurs.
 314.301 +     */
 314.302 +    void writeChars(String s) throws IOException;
 314.303 +
 314.304 +    /**
 314.305 +     * Writes two bytes of length information
 314.306 +     * to the output stream, followed
 314.307 +     * by the
 314.308 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
 314.309 +     * representation
 314.310 +     * of  every character in the string <code>s</code>.
 314.311 +     * If <code>s</code> is <code>null</code>,
 314.312 +     * a <code>NullPointerException</code> is thrown.
 314.313 +     * Each character in the string <code>s</code>
 314.314 +     * is converted to a group of one, two, or
 314.315 +     * three bytes, depending on the value of the
 314.316 +     * character.<p>
 314.317 +     * If a character <code>c</code>
 314.318 +     * is in the range <code>&#92;u0001</code> through
 314.319 +     * <code>&#92;u007f</code>, it is represented
 314.320 +     * by one byte:<p>
 314.321 +     * <pre>(byte)c </pre>  <p>
 314.322 +     * If a character <code>c</code> is <code>&#92;u0000</code>
 314.323 +     * or is in the range <code>&#92;u0080</code>
 314.324 +     * through <code>&#92;u07ff</code>, then it is
 314.325 +     * represented by two bytes, to be written
 314.326 +     * in the order shown:<p> <pre><code>
 314.327 +     * (byte)(0xc0 | (0x1f &amp; (c &gt;&gt; 6)))
 314.328 +     * (byte)(0x80 | (0x3f &amp; c))
 314.329 +     *  </code></pre>  <p> If a character
 314.330 +     * <code>c</code> is in the range <code>&#92;u0800</code>
 314.331 +     * through <code>uffff</code>, then it is
 314.332 +     * represented by three bytes, to be written
 314.333 +     * in the order shown:<p> <pre><code>
 314.334 +     * (byte)(0xe0 | (0x0f &amp; (c &gt;&gt; 12)))
 314.335 +     * (byte)(0x80 | (0x3f &amp; (c &gt;&gt;  6)))
 314.336 +     * (byte)(0x80 | (0x3f &amp; c))
 314.337 +     *  </code></pre>  <p> First,
 314.338 +     * the total number of bytes needed to represent
 314.339 +     * all the characters of <code>s</code> is
 314.340 +     * calculated. If this number is larger than
 314.341 +     * <code>65535</code>, then a <code>UTFDataFormatException</code>
 314.342 +     * is thrown. Otherwise, this length is written
 314.343 +     * to the output stream in exactly the manner
 314.344 +     * of the <code>writeShort</code> method;
 314.345 +     * after this, the one-, two-, or three-byte
 314.346 +     * representation of each character in the
 314.347 +     * string <code>s</code> is written.<p>  The
 314.348 +     * bytes written by this method may be read
 314.349 +     * by the <code>readUTF</code> method of interface
 314.350 +     * <code>DataInput</code> , which will then
 314.351 +     * return a <code>String</code> equal to <code>s</code>.
 314.352 +     *
 314.353 +     * @param      s   the string value to be written.
 314.354 +     * @throws     IOException  if an I/O error occurs.
 314.355 +     */
 314.356 +    void writeUTF(String s) throws IOException;
 314.357 +}
   315.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   315.2 +++ b/rt/emul/compact/src/main/java/java/io/DataOutputStream.java	Wed Feb 27 11:24:58 2013 +0100
   315.3 @@ -0,0 +1,416 @@
   315.4 +/*
   315.5 + * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
   315.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   315.7 + *
   315.8 + * This code is free software; you can redistribute it and/or modify it
   315.9 + * under the terms of the GNU General Public License version 2 only, as
  315.10 + * published by the Free Software Foundation.  Oracle designates this
  315.11 + * particular file as subject to the "Classpath" exception as provided
  315.12 + * by Oracle in the LICENSE file that accompanied this code.
  315.13 + *
  315.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  315.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  315.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  315.17 + * version 2 for more details (a copy is included in the LICENSE file that
  315.18 + * accompanied this code).
  315.19 + *
  315.20 + * You should have received a copy of the GNU General Public License version
  315.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  315.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  315.23 + *
  315.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  315.25 + * or visit www.oracle.com if you need additional information or have any
  315.26 + * questions.
  315.27 + */
  315.28 +
  315.29 +package java.io;
  315.30 +
  315.31 +/**
  315.32 + * A data output stream lets an application write primitive Java data
  315.33 + * types to an output stream in a portable way. An application can
  315.34 + * then use a data input stream to read the data back in.
  315.35 + *
  315.36 + * @author  unascribed
  315.37 + * @see     java.io.DataInputStream
  315.38 + * @since   JDK1.0
  315.39 + */
  315.40 +public
  315.41 +class DataOutputStream extends FilterOutputStream implements DataOutput {
  315.42 +    /**
  315.43 +     * The number of bytes written to the data output stream so far.
  315.44 +     * If this counter overflows, it will be wrapped to Integer.MAX_VALUE.
  315.45 +     */
  315.46 +    protected int written;
  315.47 +
  315.48 +    /**
  315.49 +     * bytearr is initialized on demand by writeUTF
  315.50 +     */
  315.51 +    private byte[] bytearr = null;
  315.52 +
  315.53 +    /**
  315.54 +     * Creates a new data output stream to write data to the specified
  315.55 +     * underlying output stream. The counter <code>written</code> is
  315.56 +     * set to zero.
  315.57 +     *
  315.58 +     * @param   out   the underlying output stream, to be saved for later
  315.59 +     *                use.
  315.60 +     * @see     java.io.FilterOutputStream#out
  315.61 +     */
  315.62 +    public DataOutputStream(OutputStream out) {
  315.63 +        super(out);
  315.64 +    }
  315.65 +
  315.66 +    /**
  315.67 +     * Increases the written counter by the specified value
  315.68 +     * until it reaches Integer.MAX_VALUE.
  315.69 +     */
  315.70 +    private void incCount(int value) {
  315.71 +        int temp = written + value;
  315.72 +        if (temp < 0) {
  315.73 +            temp = Integer.MAX_VALUE;
  315.74 +        }
  315.75 +        written = temp;
  315.76 +    }
  315.77 +
  315.78 +    /**
  315.79 +     * Writes the specified byte (the low eight bits of the argument
  315.80 +     * <code>b</code>) to the underlying output stream. If no exception
  315.81 +     * is thrown, the counter <code>written</code> is incremented by
  315.82 +     * <code>1</code>.
  315.83 +     * <p>
  315.84 +     * Implements the <code>write</code> method of <code>OutputStream</code>.
  315.85 +     *
  315.86 +     * @param      b   the <code>byte</code> to be written.
  315.87 +     * @exception  IOException  if an I/O error occurs.
  315.88 +     * @see        java.io.FilterOutputStream#out
  315.89 +     */
  315.90 +    public synchronized void write(int b) throws IOException {
  315.91 +        out.write(b);
  315.92 +        incCount(1);
  315.93 +    }
  315.94 +
  315.95 +    /**
  315.96 +     * Writes <code>len</code> bytes from the specified byte array
  315.97 +     * starting at offset <code>off</code> to the underlying output stream.
  315.98 +     * If no exception is thrown, the counter <code>written</code> is
  315.99 +     * incremented by <code>len</code>.
 315.100 +     *
 315.101 +     * @param      b     the data.
 315.102 +     * @param      off   the start offset in the data.
 315.103 +     * @param      len   the number of bytes to write.
 315.104 +     * @exception  IOException  if an I/O error occurs.
 315.105 +     * @see        java.io.FilterOutputStream#out
 315.106 +     */
 315.107 +    public synchronized void write(byte b[], int off, int len)
 315.108 +        throws IOException
 315.109 +    {
 315.110 +        out.write(b, off, len);
 315.111 +        incCount(len);
 315.112 +    }
 315.113 +
 315.114 +    /**
 315.115 +     * Flushes this data output stream. This forces any buffered output
 315.116 +     * bytes to be written out to the stream.
 315.117 +     * <p>
 315.118 +     * The <code>flush</code> method of <code>DataOutputStream</code>
 315.119 +     * calls the <code>flush</code> method of its underlying output stream.
 315.120 +     *
 315.121 +     * @exception  IOException  if an I/O error occurs.
 315.122 +     * @see        java.io.FilterOutputStream#out
 315.123 +     * @see        java.io.OutputStream#flush()
 315.124 +     */
 315.125 +    public void flush() throws IOException {
 315.126 +        out.flush();
 315.127 +    }
 315.128 +
 315.129 +    /**
 315.130 +     * Writes a <code>boolean</code> to the underlying output stream as
 315.131 +     * a 1-byte value. The value <code>true</code> is written out as the
 315.132 +     * value <code>(byte)1</code>; the value <code>false</code> is
 315.133 +     * written out as the value <code>(byte)0</code>. If no exception is
 315.134 +     * thrown, the counter <code>written</code> is incremented by
 315.135 +     * <code>1</code>.
 315.136 +     *
 315.137 +     * @param      v   a <code>boolean</code> value to be written.
 315.138 +     * @exception  IOException  if an I/O error occurs.
 315.139 +     * @see        java.io.FilterOutputStream#out
 315.140 +     */
 315.141 +    public final void writeBoolean(boolean v) throws IOException {
 315.142 +        out.write(v ? 1 : 0);
 315.143 +        incCount(1);
 315.144 +    }
 315.145 +
 315.146 +    /**
 315.147 +     * Writes out a <code>byte</code> to the underlying output stream as
 315.148 +     * a 1-byte value. If no exception is thrown, the counter
 315.149 +     * <code>written</code> is incremented by <code>1</code>.
 315.150 +     *
 315.151 +     * @param      v   a <code>byte</code> value to be written.
 315.152 +     * @exception  IOException  if an I/O error occurs.
 315.153 +     * @see        java.io.FilterOutputStream#out
 315.154 +     */
 315.155 +    public final void writeByte(int v) throws IOException {
 315.156 +        out.write(v);
 315.157 +        incCount(1);
 315.158 +    }
 315.159 +
 315.160 +    /**
 315.161 +     * Writes a <code>short</code> to the underlying output stream as two
 315.162 +     * bytes, high byte first. If no exception is thrown, the counter
 315.163 +     * <code>written</code> is incremented by <code>2</code>.
 315.164 +     *
 315.165 +     * @param      v   a <code>short</code> to be written.
 315.166 +     * @exception  IOException  if an I/O error occurs.
 315.167 +     * @see        java.io.FilterOutputStream#out
 315.168 +     */
 315.169 +    public final void writeShort(int v) throws IOException {
 315.170 +        out.write((v >>> 8) & 0xFF);
 315.171 +        out.write((v >>> 0) & 0xFF);
 315.172 +        incCount(2);
 315.173 +    }
 315.174 +
 315.175 +    /**
 315.176 +     * Writes a <code>char</code> to the underlying output stream as a
 315.177 +     * 2-byte value, high byte first. If no exception is thrown, the
 315.178 +     * counter <code>written</code> is incremented by <code>2</code>.
 315.179 +     *
 315.180 +     * @param      v   a <code>char</code> value to be written.
 315.181 +     * @exception  IOException  if an I/O error occurs.
 315.182 +     * @see        java.io.FilterOutputStream#out
 315.183 +     */
 315.184 +    public final void writeChar(int v) throws IOException {
 315.185 +        out.write((v >>> 8) & 0xFF);
 315.186 +        out.write((v >>> 0) & 0xFF);
 315.187 +        incCount(2);
 315.188 +    }
 315.189 +
 315.190 +    /**
 315.191 +     * Writes an <code>int</code> to the underlying output stream as four
 315.192 +     * bytes, high byte first. If no exception is thrown, the counter
 315.193 +     * <code>written</code> is incremented by <code>4</code>.
 315.194 +     *
 315.195 +     * @param      v   an <code>int</code> to be written.
 315.196 +     * @exception  IOException  if an I/O error occurs.
 315.197 +     * @see        java.io.FilterOutputStream#out
 315.198 +     */
 315.199 +    public final void writeInt(int v) throws IOException {
 315.200 +        out.write((v >>> 24) & 0xFF);
 315.201 +        out.write((v >>> 16) & 0xFF);
 315.202 +        out.write((v >>>  8) & 0xFF);
 315.203 +        out.write((v >>>  0) & 0xFF);
 315.204 +        incCount(4);
 315.205 +    }
 315.206 +
 315.207 +    private byte writeBuffer[] = new byte[8];
 315.208 +
 315.209 +    /**
 315.210 +     * Writes a <code>long</code> to the underlying output stream as eight
 315.211 +     * bytes, high byte first. In no exception is thrown, the counter
 315.212 +     * <code>written</code> is incremented by <code>8</code>.
 315.213 +     *
 315.214 +     * @param      v   a <code>long</code> to be written.
 315.215 +     * @exception  IOException  if an I/O error occurs.
 315.216 +     * @see        java.io.FilterOutputStream#out
 315.217 +     */
 315.218 +    public final void writeLong(long v) throws IOException {
 315.219 +        writeBuffer[0] = (byte)(v >>> 56);
 315.220 +        writeBuffer[1] = (byte)(v >>> 48);
 315.221 +        writeBuffer[2] = (byte)(v >>> 40);
 315.222 +        writeBuffer[3] = (byte)(v >>> 32);
 315.223 +        writeBuffer[4] = (byte)(v >>> 24);
 315.224 +        writeBuffer[5] = (byte)(v >>> 16);
 315.225 +        writeBuffer[6] = (byte)(v >>>  8);
 315.226 +        writeBuffer[7] = (byte)(v >>>  0);
 315.227 +        out.write(writeBuffer, 0, 8);
 315.228 +        incCount(8);
 315.229 +    }
 315.230 +
 315.231 +    /**
 315.232 +     * Converts the float argument to an <code>int</code> using the
 315.233 +     * <code>floatToIntBits</code> method in class <code>Float</code>,
 315.234 +     * and then writes that <code>int</code> value to the underlying
 315.235 +     * output stream as a 4-byte quantity, high byte first. If no
 315.236 +     * exception is thrown, the counter <code>written</code> is
 315.237 +     * incremented by <code>4</code>.
 315.238 +     *
 315.239 +     * @param      v   a <code>float</code> value to be written.
 315.240 +     * @exception  IOException  if an I/O error occurs.
 315.241 +     * @see        java.io.FilterOutputStream#out
 315.242 +     * @see        java.lang.Float#floatToIntBits(float)
 315.243 +     */
 315.244 +    public final void writeFloat(float v) throws IOException {
 315.245 +        writeInt(Float.floatToIntBits(v));
 315.246 +    }
 315.247 +
 315.248 +    /**
 315.249 +     * Converts the double argument to a <code>long</code> using the
 315.250 +     * <code>doubleToLongBits</code> method in class <code>Double</code>,
 315.251 +     * and then writes that <code>long</code> value to the underlying
 315.252 +     * output stream as an 8-byte quantity, high byte first. If no
 315.253 +     * exception is thrown, the counter <code>written</code> is
 315.254 +     * incremented by <code>8</code>.
 315.255 +     *
 315.256 +     * @param      v   a <code>double</code> value to be written.
 315.257 +     * @exception  IOException  if an I/O error occurs.
 315.258 +     * @see        java.io.FilterOutputStream#out
 315.259 +     * @see        java.lang.Double#doubleToLongBits(double)
 315.260 +     */
 315.261 +    public final void writeDouble(double v) throws IOException {
 315.262 +        writeLong(Double.doubleToLongBits(v));
 315.263 +    }
 315.264 +
 315.265 +    /**
 315.266 +     * Writes out the string to the underlying output stream as a
 315.267 +     * sequence of bytes. Each character in the string is written out, in
 315.268 +     * sequence, by discarding its high eight bits. If no exception is
 315.269 +     * thrown, the counter <code>written</code> is incremented by the
 315.270 +     * length of <code>s</code>.
 315.271 +     *
 315.272 +     * @param      s   a string of bytes to be written.
 315.273 +     * @exception  IOException  if an I/O error occurs.
 315.274 +     * @see        java.io.FilterOutputStream#out
 315.275 +     */
 315.276 +    public final void writeBytes(String s) throws IOException {
 315.277 +        int len = s.length();
 315.278 +        for (int i = 0 ; i < len ; i++) {
 315.279 +            out.write((byte)s.charAt(i));
 315.280 +        }
 315.281 +        incCount(len);
 315.282 +    }
 315.283 +
 315.284 +    /**
 315.285 +     * Writes a string to the underlying output stream as a sequence of
 315.286 +     * characters. Each character is written to the data output stream as
 315.287 +     * if by the <code>writeChar</code> method. If no exception is
 315.288 +     * thrown, the counter <code>written</code> is incremented by twice
 315.289 +     * the length of <code>s</code>.
 315.290 +     *
 315.291 +     * @param      s   a <code>String</code> value to be written.
 315.292 +     * @exception  IOException  if an I/O error occurs.
 315.293 +     * @see        java.io.DataOutputStream#writeChar(int)
 315.294 +     * @see        java.io.FilterOutputStream#out
 315.295 +     */
 315.296 +    public final void writeChars(String s) throws IOException {
 315.297 +        int len = s.length();
 315.298 +        for (int i = 0 ; i < len ; i++) {
 315.299 +            int v = s.charAt(i);
 315.300 +            out.write((v >>> 8) & 0xFF);
 315.301 +            out.write((v >>> 0) & 0xFF);
 315.302 +        }
 315.303 +        incCount(len * 2);
 315.304 +    }
 315.305 +
 315.306 +    /**
 315.307 +     * Writes a string to the underlying output stream using
 315.308 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
 315.309 +     * encoding in a machine-independent manner.
 315.310 +     * <p>
 315.311 +     * First, two bytes are written to the output stream as if by the
 315.312 +     * <code>writeShort</code> method giving the number of bytes to
 315.313 +     * follow. This value is the number of bytes actually written out,
 315.314 +     * not the length of the string. Following the length, each character
 315.315 +     * of the string is output, in sequence, using the modified UTF-8 encoding
 315.316 +     * for the character. If no exception is thrown, the counter
 315.317 +     * <code>written</code> is incremented by the total number of
 315.318 +     * bytes written to the output stream. This will be at least two
 315.319 +     * plus the length of <code>str</code>, and at most two plus
 315.320 +     * thrice the length of <code>str</code>.
 315.321 +     *
 315.322 +     * @param      str   a string to be written.
 315.323 +     * @exception  IOException  if an I/O error occurs.
 315.324 +     */
 315.325 +    public final void writeUTF(String str) throws IOException {
 315.326 +        writeUTF(str, this);
 315.327 +    }
 315.328 +
 315.329 +    /**
 315.330 +     * Writes a string to the specified DataOutput using
 315.331 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
 315.332 +     * encoding in a machine-independent manner.
 315.333 +     * <p>
 315.334 +     * First, two bytes are written to out as if by the <code>writeShort</code>
 315.335 +     * method giving the number of bytes to follow. This value is the number of
 315.336 +     * bytes actually written out, not the length of the string. Following the
 315.337 +     * length, each character of the string is output, in sequence, using the
 315.338 +     * modified UTF-8 encoding for the character. If no exception is thrown, the
 315.339 +     * counter <code>written</code> is incremented by the total number of
 315.340 +     * bytes written to the output stream. This will be at least two
 315.341 +     * plus the length of <code>str</code>, and at most two plus
 315.342 +     * thrice the length of <code>str</code>.
 315.343 +     *
 315.344 +     * @param      str   a string to be written.
 315.345 +     * @param      out   destination to write to
 315.346 +     * @return     The number of bytes written out.
 315.347 +     * @exception  IOException  if an I/O error occurs.
 315.348 +     */
 315.349 +    static int writeUTF(String str, DataOutput out) throws IOException {
 315.350 +        int strlen = str.length();
 315.351 +        int utflen = 0;
 315.352 +        int c, count = 0;
 315.353 +
 315.354 +        /* use charAt instead of copying String to char array */
 315.355 +        for (int i = 0; i < strlen; i++) {
 315.356 +            c = str.charAt(i);
 315.357 +            if ((c >= 0x0001) && (c <= 0x007F)) {
 315.358 +                utflen++;
 315.359 +            } else if (c > 0x07FF) {
 315.360 +                utflen += 3;
 315.361 +            } else {
 315.362 +                utflen += 2;
 315.363 +            }
 315.364 +        }
 315.365 +
 315.366 +        if (utflen > 65535)
 315.367 +            throw new UTFDataFormatException(
 315.368 +                "encoded string too long: " + utflen + " bytes");
 315.369 +
 315.370 +        byte[] bytearr = null;
 315.371 +        if (out instanceof DataOutputStream) {
 315.372 +            DataOutputStream dos = (DataOutputStream)out;
 315.373 +            if(dos.bytearr == null || (dos.bytearr.length < (utflen+2)))
 315.374 +                dos.bytearr = new byte[(utflen*2) + 2];
 315.375 +            bytearr = dos.bytearr;
 315.376 +        } else {
 315.377 +            bytearr = new byte[utflen+2];
 315.378 +        }
 315.379 +
 315.380 +        bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
 315.381 +        bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
 315.382 +
 315.383 +        int i=0;
 315.384 +        for (i=0; i<strlen; i++) {
 315.385 +           c = str.charAt(i);
 315.386 +           if (!((c >= 0x0001) && (c <= 0x007F))) break;
 315.387 +           bytearr[count++] = (byte) c;
 315.388 +        }
 315.389 +
 315.390 +        for (;i < strlen; i++){
 315.391 +            c = str.charAt(i);
 315.392 +            if ((c >= 0x0001) && (c <= 0x007F)) {
 315.393 +                bytearr[count++] = (byte) c;
 315.394 +
 315.395 +            } else if (c > 0x07FF) {
 315.396 +                bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
 315.397 +                bytearr[count++] = (byte) (0x80 | ((c >>  6) & 0x3F));
 315.398 +                bytearr[count++] = (byte) (0x80 | ((c >>  0) & 0x3F));
 315.399 +            } else {
 315.400 +                bytearr[count++] = (byte) (0xC0 | ((c >>  6) & 0x1F));
 315.401 +                bytearr[count++] = (byte) (0x80 | ((c >>  0) & 0x3F));
 315.402 +            }
 315.403 +        }
 315.404 +        out.write(bytearr, 0, utflen+2);
 315.405 +        return utflen + 2;
 315.406 +    }
 315.407 +
 315.408 +    /**
 315.409 +     * Returns the current value of the counter <code>written</code>,
 315.410 +     * the number of bytes written to this data output stream so far.
 315.411 +     * If the counter overflows, it will be wrapped to Integer.MAX_VALUE.
 315.412 +     *
 315.413 +     * @return  the value of the <code>written</code> field.
 315.414 +     * @see     java.io.DataOutputStream#written
 315.415 +     */
 315.416 +    public final int size() {
 315.417 +        return written;
 315.418 +    }
 315.419 +}
   316.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   316.2 +++ b/rt/emul/compact/src/main/java/java/io/Externalizable.java	Wed Feb 27 11:24:58 2013 +0100
   316.3 @@ -0,0 +1,97 @@
   316.4 +/*
   316.5 + * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
   316.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   316.7 + *
   316.8 + * This code is free software; you can redistribute it and/or modify it
   316.9 + * under the terms of the GNU General Public License version 2 only, as
  316.10 + * published by the Free Software Foundation.  Oracle designates this
  316.11 + * particular file as subject to the "Classpath" exception as provided
  316.12 + * by Oracle in the LICENSE file that accompanied this code.
  316.13 + *
  316.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  316.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  316.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  316.17 + * version 2 for more details (a copy is included in the LICENSE file that
  316.18 + * accompanied this code).
  316.19 + *
  316.20 + * You should have received a copy of the GNU General Public License version
  316.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  316.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  316.23 + *
  316.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  316.25 + * or visit www.oracle.com if you need additional information or have any
  316.26 + * questions.
  316.27 + */
  316.28 +
  316.29 +package java.io;
  316.30 +
  316.31 +import java.io.ObjectOutput;
  316.32 +import java.io.ObjectInput;
  316.33 +
  316.34 +/**
  316.35 + * Only the identity of the class of an Externalizable instance is
  316.36 + * written in the serialization stream and it is the responsibility
  316.37 + * of the class to save and restore the contents of its instances.
  316.38 + *
  316.39 + * The writeExternal and readExternal methods of the Externalizable
  316.40 + * interface are implemented by a class to give the class complete
  316.41 + * control over the format and contents of the stream for an object
  316.42 + * and its supertypes. These methods must explicitly
  316.43 + * coordinate with the supertype to save its state. These methods supersede
  316.44 + * customized implementations of writeObject and readObject methods.<br>
  316.45 + *
  316.46 + * Object Serialization uses the Serializable and Externalizable
  316.47 + * interfaces.  Object persistence mechanisms can use them as well.  Each
  316.48 + * object to be stored is tested for the Externalizable interface. If
  316.49 + * the object supports Externalizable, the writeExternal method is called. If the
  316.50 + * object does not support Externalizable and does implement
  316.51 + * Serializable, the object is saved using
  316.52 + * ObjectOutputStream. <br> When an Externalizable object is
  316.53 + * reconstructed, an instance is created using the public no-arg
  316.54 + * constructor, then the readExternal method called.  Serializable
  316.55 + * objects are restored by reading them from an ObjectInputStream.<br>
  316.56 + *
  316.57 + * An Externalizable instance can designate a substitution object via
  316.58 + * the writeReplace and readResolve methods documented in the Serializable
  316.59 + * interface.<br>
  316.60 + *
  316.61 + * @author  unascribed
  316.62 + * @see java.io.ObjectOutputStream
  316.63 + * @see java.io.ObjectInputStream
  316.64 + * @see java.io.ObjectOutput
  316.65 + * @see java.io.ObjectInput
  316.66 + * @see java.io.Serializable
  316.67 + * @since   JDK1.1
  316.68 + */
  316.69 +public interface Externalizable extends java.io.Serializable {
  316.70 +    /**
  316.71 +     * The object implements the writeExternal method to save its contents
  316.72 +     * by calling the methods of DataOutput for its primitive values or
  316.73 +     * calling the writeObject method of ObjectOutput for objects, strings,
  316.74 +     * and arrays.
  316.75 +     *
  316.76 +     * @serialData Overriding methods should use this tag to describe
  316.77 +     *             the data layout of this Externalizable object.
  316.78 +     *             List the sequence of element types and, if possible,
  316.79 +     *             relate the element to a public/protected field and/or
  316.80 +     *             method of this Externalizable class.
  316.81 +     *
  316.82 +     * @param out the stream to write the object to
  316.83 +     * @exception IOException Includes any I/O exceptions that may occur
  316.84 +     */
  316.85 +    void writeExternal(ObjectOutput out) throws IOException;
  316.86 +
  316.87 +    /**
  316.88 +     * The object implements the readExternal method to restore its
  316.89 +     * contents by calling the methods of DataInput for primitive
  316.90 +     * types and readObject for objects, strings and arrays.  The
  316.91 +     * readExternal method must read the values in the same sequence
  316.92 +     * and with the same types as were written by writeExternal.
  316.93 +     *
  316.94 +     * @param in the stream to read data from in order to restore the object
  316.95 +     * @exception IOException if I/O errors occur
  316.96 +     * @exception ClassNotFoundException If the class for an object being
  316.97 +     *              restored cannot be found.
  316.98 +     */
  316.99 +    void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
 316.100 +}
   317.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   317.2 +++ b/rt/emul/compact/src/main/java/java/io/FilterOutputStream.java	Wed Feb 27 11:24:58 2013 +0100
   317.3 @@ -0,0 +1,162 @@
   317.4 +/*
   317.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   317.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   317.7 + *
   317.8 + * This code is free software; you can redistribute it and/or modify it
   317.9 + * under the terms of the GNU General Public License version 2 only, as
  317.10 + * published by the Free Software Foundation.  Oracle designates this
  317.11 + * particular file as subject to the "Classpath" exception as provided
  317.12 + * by Oracle in the LICENSE file that accompanied this code.
  317.13 + *
  317.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  317.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  317.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  317.17 + * version 2 for more details (a copy is included in the LICENSE file that
  317.18 + * accompanied this code).
  317.19 + *
  317.20 + * You should have received a copy of the GNU General Public License version
  317.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  317.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  317.23 + *
  317.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  317.25 + * or visit www.oracle.com if you need additional information or have any
  317.26 + * questions.
  317.27 + */
  317.28 +
  317.29 +package java.io;
  317.30 +
  317.31 +/**
  317.32 + * This class is the superclass of all classes that filter output
  317.33 + * streams. These streams sit on top of an already existing output
  317.34 + * stream (the <i>underlying</i> output stream) which it uses as its
  317.35 + * basic sink of data, but possibly transforming the data along the
  317.36 + * way or providing additional functionality.
  317.37 + * <p>
  317.38 + * The class <code>FilterOutputStream</code> itself simply overrides
  317.39 + * all methods of <code>OutputStream</code> with versions that pass
  317.40 + * all requests to the underlying output stream. Subclasses of
  317.41 + * <code>FilterOutputStream</code> may further override some of these
  317.42 + * methods as well as provide additional methods and fields.
  317.43 + *
  317.44 + * @author  Jonathan Payne
  317.45 + * @since   JDK1.0
  317.46 + */
  317.47 +public
  317.48 +class FilterOutputStream extends OutputStream {
  317.49 +    /**
  317.50 +     * The underlying output stream to be filtered.
  317.51 +     */
  317.52 +    protected OutputStream out;
  317.53 +
  317.54 +    /**
  317.55 +     * Creates an output stream filter built on top of the specified
  317.56 +     * underlying output stream.
  317.57 +     *
  317.58 +     * @param   out   the underlying output stream to be assigned to
  317.59 +     *                the field <tt>this.out</tt> for later use, or
  317.60 +     *                <code>null</code> if this instance is to be
  317.61 +     *                created without an underlying stream.
  317.62 +     */
  317.63 +    public FilterOutputStream(OutputStream out) {
  317.64 +        this.out = out;
  317.65 +    }
  317.66 +
  317.67 +    /**
  317.68 +     * Writes the specified <code>byte</code> to this output stream.
  317.69 +     * <p>
  317.70 +     * The <code>write</code> method of <code>FilterOutputStream</code>
  317.71 +     * calls the <code>write</code> method of its underlying output stream,
  317.72 +     * that is, it performs <tt>out.write(b)</tt>.
  317.73 +     * <p>
  317.74 +     * Implements the abstract <tt>write</tt> method of <tt>OutputStream</tt>.
  317.75 +     *
  317.76 +     * @param      b   the <code>byte</code>.
  317.77 +     * @exception  IOException  if an I/O error occurs.
  317.78 +     */
  317.79 +    public void write(int b) throws IOException {
  317.80 +        out.write(b);
  317.81 +    }
  317.82 +
  317.83 +    /**
  317.84 +     * Writes <code>b.length</code> bytes to this output stream.
  317.85 +     * <p>
  317.86 +     * The <code>write</code> method of <code>FilterOutputStream</code>
  317.87 +     * calls its <code>write</code> method of three arguments with the
  317.88 +     * arguments <code>b</code>, <code>0</code>, and
  317.89 +     * <code>b.length</code>.
  317.90 +     * <p>
  317.91 +     * Note that this method does not call the one-argument
  317.92 +     * <code>write</code> method of its underlying stream with the single
  317.93 +     * argument <code>b</code>.
  317.94 +     *
  317.95 +     * @param      b   the data to be written.
  317.96 +     * @exception  IOException  if an I/O error occurs.
  317.97 +     * @see        java.io.FilterOutputStream#write(byte[], int, int)
  317.98 +     */
  317.99 +    public void write(byte b[]) throws IOException {
 317.100 +        write(b, 0, b.length);
 317.101 +    }
 317.102 +
 317.103 +    /**
 317.104 +     * Writes <code>len</code> bytes from the specified
 317.105 +     * <code>byte</code> array starting at offset <code>off</code> to
 317.106 +     * this output stream.
 317.107 +     * <p>
 317.108 +     * The <code>write</code> method of <code>FilterOutputStream</code>
 317.109 +     * calls the <code>write</code> method of one argument on each
 317.110 +     * <code>byte</code> to output.
 317.111 +     * <p>
 317.112 +     * Note that this method does not call the <code>write</code> method
 317.113 +     * of its underlying input stream with the same arguments. Subclasses
 317.114 +     * of <code>FilterOutputStream</code> should provide a more efficient
 317.115 +     * implementation of this method.
 317.116 +     *
 317.117 +     * @param      b     the data.
 317.118 +     * @param      off   the start offset in the data.
 317.119 +     * @param      len   the number of bytes to write.
 317.120 +     * @exception  IOException  if an I/O error occurs.
 317.121 +     * @see        java.io.FilterOutputStream#write(int)
 317.122 +     */
 317.123 +    public void write(byte b[], int off, int len) throws IOException {
 317.124 +        if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
 317.125 +            throw new IndexOutOfBoundsException();
 317.126 +
 317.127 +        for (int i = 0 ; i < len ; i++) {
 317.128 +            write(b[off + i]);
 317.129 +        }
 317.130 +    }
 317.131 +
 317.132 +    /**
 317.133 +     * Flushes this output stream and forces any buffered output bytes
 317.134 +     * to be written out to the stream.
 317.135 +     * <p>
 317.136 +     * The <code>flush</code> method of <code>FilterOutputStream</code>
 317.137 +     * calls the <code>flush</code> method of its underlying output stream.
 317.138 +     *
 317.139 +     * @exception  IOException  if an I/O error occurs.
 317.140 +     * @see        java.io.FilterOutputStream#out
 317.141 +     */
 317.142 +    public void flush() throws IOException {
 317.143 +        out.flush();
 317.144 +    }
 317.145 +
 317.146 +    /**
 317.147 +     * Closes this output stream and releases any system resources
 317.148 +     * associated with the stream.
 317.149 +     * <p>
 317.150 +     * The <code>close</code> method of <code>FilterOutputStream</code>
 317.151 +     * calls its <code>flush</code> method, and then calls the
 317.152 +     * <code>close</code> method of its underlying output stream.
 317.153 +     *
 317.154 +     * @exception  IOException  if an I/O error occurs.
 317.155 +     * @see        java.io.FilterOutputStream#flush()
 317.156 +     * @see        java.io.FilterOutputStream#out
 317.157 +     */
 317.158 +    public void close() throws IOException {
 317.159 +        try {
 317.160 +          flush();
 317.161 +        } catch (IOException ignored) {
 317.162 +        }
 317.163 +        out.close();
 317.164 +    }
 317.165 +}
   318.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   318.2 +++ b/rt/emul/compact/src/main/java/java/io/Flushable.java	Wed Feb 27 11:24:58 2013 +0100
   318.3 @@ -0,0 +1,47 @@
   318.4 +/*
   318.5 + * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   318.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   318.7 + *
   318.8 + * This code is free software; you can redistribute it and/or modify it
   318.9 + * under the terms of the GNU General Public License version 2 only, as
  318.10 + * published by the Free Software Foundation.  Oracle designates this
  318.11 + * particular file as subject to the "Classpath" exception as provided
  318.12 + * by Oracle in the LICENSE file that accompanied this code.
  318.13 + *
  318.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  318.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  318.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  318.17 + * version 2 for more details (a copy is included in the LICENSE file that
  318.18 + * accompanied this code).
  318.19 + *
  318.20 + * You should have received a copy of the GNU General Public License version
  318.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  318.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  318.23 + *
  318.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  318.25 + * or visit www.oracle.com if you need additional information or have any
  318.26 + * questions.
  318.27 + */
  318.28 +
  318.29 +package java.io;
  318.30 +
  318.31 +import java.io.IOException;
  318.32 +
  318.33 +/**
  318.34 + * A <tt>Flushable</tt> is a destination of data that can be flushed.  The
  318.35 + * flush method is invoked to write any buffered output to the underlying
  318.36 + * stream.
  318.37 + *
  318.38 + * @since 1.5
  318.39 + */
  318.40 +
  318.41 +public interface Flushable {
  318.42 +
  318.43 +    /**
  318.44 +     * Flushes this stream by writing any buffered output to the underlying
  318.45 +     * stream.
  318.46 +     *
  318.47 +     * @throws IOException If an I/O error occurs
  318.48 +     */
  318.49 +    void flush() throws IOException;
  318.50 +}
   319.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   319.2 +++ b/rt/emul/compact/src/main/java/java/io/InputStreamReader.java	Wed Feb 27 11:24:58 2013 +0100
   319.3 @@ -0,0 +1,230 @@
   319.4 +/*
   319.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   319.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   319.7 + *
   319.8 + * This code is free software; you can redistribute it and/or modify it
   319.9 + * under the terms of the GNU General Public License version 2 only, as
  319.10 + * published by the Free Software Foundation.  Oracle designates this
  319.11 + * particular file as subject to the "Classpath" exception as provided
  319.12 + * by Oracle in the LICENSE file that accompanied this code.
  319.13 + *
  319.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  319.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  319.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  319.17 + * version 2 for more details (a copy is included in the LICENSE file that
  319.18 + * accompanied this code).
  319.19 + *
  319.20 + * You should have received a copy of the GNU General Public License version
  319.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  319.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  319.23 + *
  319.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  319.25 + * or visit www.oracle.com if you need additional information or have any
  319.26 + * questions.
  319.27 + */
  319.28 +
  319.29 +package java.io;
  319.30 +
  319.31 +
  319.32 +/**
  319.33 + * An InputStreamReader is a bridge from byte streams to character streams: It
  319.34 + * reads bytes and decodes them into characters using a specified {@link
  319.35 + * java.nio.charset.Charset <code>charset</code>}.  The charset that it uses
  319.36 + * may be specified by name or may be given explicitly, or the platform's
  319.37 + * default charset may be accepted.
  319.38 + *
  319.39 + * <p> Each invocation of one of an InputStreamReader's read() methods may
  319.40 + * cause one or more bytes to be read from the underlying byte-input stream.
  319.41 + * To enable the efficient conversion of bytes to characters, more bytes may
  319.42 + * be read ahead from the underlying stream than are necessary to satisfy the
  319.43 + * current read operation.
  319.44 + *
  319.45 + * <p> For top efficiency, consider wrapping an InputStreamReader within a
  319.46 + * BufferedReader.  For example:
  319.47 + *
  319.48 + * <pre>
  319.49 + * BufferedReader in
  319.50 + *   = new BufferedReader(new InputStreamReader(System.in));
  319.51 + * </pre>
  319.52 + *
  319.53 + * @see BufferedReader
  319.54 + * @see InputStream
  319.55 + * @see java.nio.charset.Charset
  319.56 + *
  319.57 + * @author      Mark Reinhold
  319.58 + * @since       JDK1.1
  319.59 + */
  319.60 +
  319.61 +public class InputStreamReader extends Reader {
  319.62 +
  319.63 +    /**
  319.64 +     * Creates an InputStreamReader that uses the default charset.
  319.65 +     *
  319.66 +     * @param  in   An InputStream
  319.67 +     */
  319.68 +    public InputStreamReader(InputStream in) {
  319.69 +        super(in);
  319.70 +    }
  319.71 +
  319.72 +    /**
  319.73 +     * Creates an InputStreamReader that uses the named charset.
  319.74 +     *
  319.75 +     * @param  in
  319.76 +     *         An InputStream
  319.77 +     *
  319.78 +     * @param  charsetName
  319.79 +     *         The name of a supported
  319.80 +     *         {@link java.nio.charset.Charset </code>charset<code>}
  319.81 +     *
  319.82 +     * @exception  UnsupportedEncodingException
  319.83 +     *             If the named charset is not supported
  319.84 +     */
  319.85 +    public InputStreamReader(InputStream in, String charsetName)
  319.86 +        throws UnsupportedEncodingException
  319.87 +    {
  319.88 +        super(in);
  319.89 +        if (!charsetName.toUpperCase().equals("UTF-8")) {
  319.90 +            throw new UnsupportedEncodingException(charsetName);
  319.91 +        }
  319.92 +    }
  319.93 +
  319.94 +    /**
  319.95 +     * Creates an InputStreamReader that uses the given charset. </p>
  319.96 +     *
  319.97 +     * @param  in       An InputStream
  319.98 +     * @param  cs       A charset
  319.99 +     *
 319.100 +     * @since 1.4
 319.101 +     * @spec JSR-51
 319.102 +     */
 319.103 +/* XXX:
 319.104 +    public InputStreamReader(InputStream in, Charset cs) {
 319.105 +        super(in);
 319.106 +        if (cs == null)
 319.107 +            throw new NullPointerException("charset");
 319.108 +        sd = StreamDecoder.forInputStreamReader(in, this, cs);
 319.109 +    }
 319.110 +*/
 319.111 +    /**
 319.112 +     * Creates an InputStreamReader that uses the given charset decoder.  </p>
 319.113 +     *
 319.114 +     * @param  in       An InputStream
 319.115 +     * @param  dec      A charset decoder
 319.116 +     *
 319.117 +     * @since 1.4
 319.118 +     * @spec JSR-51
 319.119 +     */
 319.120 +/* XXX:
 319.121 +    public InputStreamReader(InputStream in, CharsetDecoder dec) {
 319.122 +        super(in);
 319.123 +        if (dec == null)
 319.124 +            throw new NullPointerException("charset decoder");
 319.125 +        sd = StreamDecoder.forInputStreamReader(in, this, dec);
 319.126 +    }
 319.127 +*/
 319.128 +    
 319.129 +    /**
 319.130 +     * Returns the name of the character encoding being used by this stream.
 319.131 +     *
 319.132 +     * <p> If the encoding has an historical name then that name is returned;
 319.133 +     * otherwise the encoding's canonical name is returned.
 319.134 +     *
 319.135 +     * <p> If this instance was created with the {@link
 319.136 +     * #InputStreamReader(InputStream, String)} constructor then the returned
 319.137 +     * name, being unique for the encoding, may differ from the name passed to
 319.138 +     * the constructor. This method will return <code>null</code> if the
 319.139 +     * stream has been closed.
 319.140 +     * </p>
 319.141 +     * @return The historical name of this encoding, or
 319.142 +     *         <code>null</code> if the stream has been closed
 319.143 +     *
 319.144 +     * @see java.nio.charset.Charset
 319.145 +     *
 319.146 +     * @revised 1.4
 319.147 +     * @spec JSR-51
 319.148 +     */
 319.149 +    public String getEncoding() {
 319.150 +        return "UTF-8";
 319.151 +    }
 319.152 +
 319.153 +    /**
 319.154 +     * Reads a single character.
 319.155 +     *
 319.156 +     * @return The character read, or -1 if the end of the stream has been
 319.157 +     *         reached
 319.158 +     *
 319.159 +     * @exception  IOException  If an I/O error occurs
 319.160 +     */
 319.161 +    public int read() throws IOException {
 319.162 +        final InputStream is = (InputStream)lock;
 319.163 +        int c = is.read();
 319.164 +        if (c == -1) {
 319.165 +            return -1;
 319.166 +        }
 319.167 +        c = (int) c & 0xff;
 319.168 +        switch (c >> 4) {
 319.169 +            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
 319.170 +                /* 0xxxxxxx*/
 319.171 +                return c;
 319.172 +            case 12: case 13: {
 319.173 +                /* 110x xxxx   10xx xxxx*/
 319.174 +                int char2 = (int) is.read();
 319.175 +                if ((char2 & 0xC0) != 0x80)
 319.176 +                    throw new UTFDataFormatException("malformed input");
 319.177 +                return (((c & 0x1F) << 6) | (char2 & 0x3F));
 319.178 +            }
 319.179 +            case 14: {
 319.180 +                /* 1110 xxxx  10xx xxxx  10xx xxxx */
 319.181 +                int char2 = is.read();
 319.182 +                int char3 = is.read();
 319.183 +                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
 319.184 +                    throw new UTFDataFormatException("malformed input");
 319.185 +                return (((c    & 0x0F) << 12) |
 319.186 +                       ((char2 & 0x3F) << 6)  |
 319.187 +                       ((char3 & 0x3F) << 0));
 319.188 +            }
 319.189 +            default:
 319.190 +                /* 10xx xxxx,  1111 xxxx */
 319.191 +                throw new UTFDataFormatException("malformed input");
 319.192 +        }
 319.193 +    }
 319.194 +    
 319.195 +    /**
 319.196 +     * Reads characters into a portion of an array.
 319.197 +     *
 319.198 +     * @param      cbuf     Destination buffer
 319.199 +     * @param      offset   Offset at which to start storing characters
 319.200 +     * @param      length   Maximum number of characters to read
 319.201 +     *
 319.202 +     * @return     The number of characters read, or -1 if the end of the
 319.203 +     *             stream has been reached
 319.204 +     *
 319.205 +     * @exception  IOException  If an I/O error occurs
 319.206 +     */
 319.207 +    public int read(char cbuf[], int offset, int length) throws IOException {
 319.208 +        for (int i = 0; i < length; i++) {
 319.209 +            int ch = read();
 319.210 +            if (ch == -1) {
 319.211 +                if (i == 0) return -1;
 319.212 +                return i;
 319.213 +            }
 319.214 +            cbuf[offset++] = (char) ch;
 319.215 +        }
 319.216 +        return length;
 319.217 +    }
 319.218 +
 319.219 +    /**
 319.220 +     * Tells whether this stream is ready to be read.  An InputStreamReader is
 319.221 +     * ready if its input buffer is not empty, or if bytes are available to be
 319.222 +     * read from the underlying byte stream.
 319.223 +     *
 319.224 +     * @exception  IOException  If an I/O error occurs
 319.225 +     */
 319.226 +    public boolean ready() throws IOException {
 319.227 +        return ((InputStream)lock).available() > 0;
 319.228 +    }
 319.229 +
 319.230 +    public void close() throws IOException {
 319.231 +        ((InputStream)lock).close();
 319.232 +    }
 319.233 +}
   320.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   320.2 +++ b/rt/emul/compact/src/main/java/java/io/InvalidClassException.java	Wed Feb 27 11:24:58 2013 +0100
   320.3 @@ -0,0 +1,81 @@
   320.4 +/*
   320.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   320.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   320.7 + *
   320.8 + * This code is free software; you can redistribute it and/or modify it
   320.9 + * under the terms of the GNU General Public License version 2 only, as
  320.10 + * published by the Free Software Foundation.  Oracle designates this
  320.11 + * particular file as subject to the "Classpath" exception as provided
  320.12 + * by Oracle in the LICENSE file that accompanied this code.
  320.13 + *
  320.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  320.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  320.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  320.17 + * version 2 for more details (a copy is included in the LICENSE file that
  320.18 + * accompanied this code).
  320.19 + *
  320.20 + * You should have received a copy of the GNU General Public License version
  320.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  320.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  320.23 + *
  320.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  320.25 + * or visit www.oracle.com if you need additional information or have any
  320.26 + * questions.
  320.27 + */
  320.28 +
  320.29 +package java.io;
  320.30 +
  320.31 +/**
  320.32 + * Thrown when the Serialization runtime detects one of the following
  320.33 + * problems with a Class.
  320.34 + * <UL>
  320.35 + * <LI> The serial version of the class does not match that of the class
  320.36 + *      descriptor read from the stream
  320.37 + * <LI> The class contains unknown datatypes
  320.38 + * <LI> The class does not have an accessible no-arg constructor
  320.39 + * </UL>
  320.40 + *
  320.41 + * @author  unascribed
  320.42 + * @since   JDK1.1
  320.43 + */
  320.44 +public class InvalidClassException extends ObjectStreamException {
  320.45 +
  320.46 +    private static final long serialVersionUID = -4333316296251054416L;
  320.47 +
  320.48 +    /**
  320.49 +     * Name of the invalid class.
  320.50 +     *
  320.51 +     * @serial Name of the invalid class.
  320.52 +     */
  320.53 +    public String classname;
  320.54 +
  320.55 +    /**
  320.56 +     * Report an InvalidClassException for the reason specified.
  320.57 +     *
  320.58 +     * @param reason  String describing the reason for the exception.
  320.59 +     */
  320.60 +    public InvalidClassException(String reason) {
  320.61 +        super(reason);
  320.62 +    }
  320.63 +
  320.64 +    /**
  320.65 +     * Constructs an InvalidClassException object.
  320.66 +     *
  320.67 +     * @param cname   a String naming the invalid class.
  320.68 +     * @param reason  a String describing the reason for the exception.
  320.69 +     */
  320.70 +    public InvalidClassException(String cname, String reason) {
  320.71 +        super(reason);
  320.72 +        classname = cname;
  320.73 +    }
  320.74 +
  320.75 +    /**
  320.76 +     * Produce the message and include the classname, if present.
  320.77 +     */
  320.78 +    public String getMessage() {
  320.79 +        if (classname == null)
  320.80 +            return super.getMessage();
  320.81 +        else
  320.82 +            return classname + "; " + super.getMessage();
  320.83 +    }
  320.84 +}
   321.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   321.2 +++ b/rt/emul/compact/src/main/java/java/io/InvalidObjectException.java	Wed Feb 27 11:24:58 2013 +0100
   321.3 @@ -0,0 +1,51 @@
   321.4 +/*
   321.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   321.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   321.7 + *
   321.8 + * This code is free software; you can redistribute it and/or modify it
   321.9 + * under the terms of the GNU General Public License version 2 only, as
  321.10 + * published by the Free Software Foundation.  Oracle designates this
  321.11 + * particular file as subject to the "Classpath" exception as provided
  321.12 + * by Oracle in the LICENSE file that accompanied this code.
  321.13 + *
  321.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  321.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  321.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  321.17 + * version 2 for more details (a copy is included in the LICENSE file that
  321.18 + * accompanied this code).
  321.19 + *
  321.20 + * You should have received a copy of the GNU General Public License version
  321.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  321.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  321.23 + *
  321.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  321.25 + * or visit www.oracle.com if you need additional information or have any
  321.26 + * questions.
  321.27 + */
  321.28 +
  321.29 +package java.io;
  321.30 +
  321.31 +/**
  321.32 + * Indicates that one or more deserialized objects failed validation
  321.33 + * tests.  The argument should provide the reason for the failure.
  321.34 + *
  321.35 + * @see ObjectInputValidation
  321.36 + * @since JDK1.1
  321.37 + *
  321.38 + * @author  unascribed
  321.39 + * @since   JDK1.1
  321.40 + */
  321.41 +public class InvalidObjectException extends ObjectStreamException {
  321.42 +
  321.43 +    private static final long serialVersionUID = 3233174318281839583L;
  321.44 +
  321.45 +    /**
  321.46 +     * Constructs an <code>InvalidObjectException</code>.
  321.47 +     * @param reason Detailed message explaining the reason for the failure.
  321.48 +     *
  321.49 +     * @see ObjectInputValidation
  321.50 +     */
  321.51 +    public  InvalidObjectException(String reason) {
  321.52 +        super(reason);
  321.53 +    }
  321.54 +}
   322.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   322.2 +++ b/rt/emul/compact/src/main/java/java/io/NotActiveException.java	Wed Feb 27 11:24:58 2013 +0100
   322.3 @@ -0,0 +1,53 @@
   322.4 +/*
   322.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   322.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   322.7 + *
   322.8 + * This code is free software; you can redistribute it and/or modify it
   322.9 + * under the terms of the GNU General Public License version 2 only, as
  322.10 + * published by the Free Software Foundation.  Oracle designates this
  322.11 + * particular file as subject to the "Classpath" exception as provided
  322.12 + * by Oracle in the LICENSE file that accompanied this code.
  322.13 + *
  322.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  322.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  322.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  322.17 + * version 2 for more details (a copy is included in the LICENSE file that
  322.18 + * accompanied this code).
  322.19 + *
  322.20 + * You should have received a copy of the GNU General Public License version
  322.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  322.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  322.23 + *
  322.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  322.25 + * or visit www.oracle.com if you need additional information or have any
  322.26 + * questions.
  322.27 + */
  322.28 +
  322.29 +package java.io;
  322.30 +
  322.31 +/**
  322.32 + * Thrown when serialization or deserialization is not active.
  322.33 + *
  322.34 + * @author  unascribed
  322.35 + * @since   JDK1.1
  322.36 + */
  322.37 +public class NotActiveException extends ObjectStreamException {
  322.38 +
  322.39 +    private static final long serialVersionUID = -3893467273049808895L;
  322.40 +
  322.41 +    /**
  322.42 +     * Constructor to create a new NotActiveException with the reason given.
  322.43 +     *
  322.44 +     * @param reason  a String describing the reason for the exception.
  322.45 +     */
  322.46 +    public NotActiveException(String reason) {
  322.47 +        super(reason);
  322.48 +    }
  322.49 +
  322.50 +    /**
  322.51 +     * Constructor to create a new NotActiveException without a reason.
  322.52 +     */
  322.53 +    public NotActiveException() {
  322.54 +        super();
  322.55 +    }
  322.56 +}
   323.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   323.2 +++ b/rt/emul/compact/src/main/java/java/io/NotSerializableException.java	Wed Feb 27 11:24:58 2013 +0100
   323.3 @@ -0,0 +1,55 @@
   323.4 +/*
   323.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   323.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   323.7 + *
   323.8 + * This code is free software; you can redistribute it and/or modify it
   323.9 + * under the terms of the GNU General Public License version 2 only, as
  323.10 + * published by the Free Software Foundation.  Oracle designates this
  323.11 + * particular file as subject to the "Classpath" exception as provided
  323.12 + * by Oracle in the LICENSE file that accompanied this code.
  323.13 + *
  323.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  323.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  323.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  323.17 + * version 2 for more details (a copy is included in the LICENSE file that
  323.18 + * accompanied this code).
  323.19 + *
  323.20 + * You should have received a copy of the GNU General Public License version
  323.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  323.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  323.23 + *
  323.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  323.25 + * or visit www.oracle.com if you need additional information or have any
  323.26 + * questions.
  323.27 + */
  323.28 +
  323.29 +package java.io;
  323.30 +
  323.31 +/**
  323.32 + * Thrown when an instance is required to have a Serializable interface.
  323.33 + * The serialization runtime or the class of the instance can throw
  323.34 + * this exception. The argument should be the name of the class.
  323.35 + *
  323.36 + * @author  unascribed
  323.37 + * @since   JDK1.1
  323.38 + */
  323.39 +public class NotSerializableException extends ObjectStreamException {
  323.40 +
  323.41 +    private static final long serialVersionUID = 2906642554793891381L;
  323.42 +
  323.43 +    /**
  323.44 +     * Constructs a NotSerializableException object with message string.
  323.45 +     *
  323.46 +     * @param classname Class of the instance being serialized/deserialized.
  323.47 +     */
  323.48 +    public NotSerializableException(String classname) {
  323.49 +        super(classname);
  323.50 +    }
  323.51 +
  323.52 +    /**
  323.53 +     *  Constructs a NotSerializableException object.
  323.54 +     */
  323.55 +    public NotSerializableException() {
  323.56 +        super();
  323.57 +    }
  323.58 +}
   324.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   324.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectInput.java	Wed Feb 27 11:24:58 2013 +0100
   324.3 @@ -0,0 +1,107 @@
   324.4 +/*
   324.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   324.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   324.7 + *
   324.8 + * This code is free software; you can redistribute it and/or modify it
   324.9 + * under the terms of the GNU General Public License version 2 only, as
  324.10 + * published by the Free Software Foundation.  Oracle designates this
  324.11 + * particular file as subject to the "Classpath" exception as provided
  324.12 + * by Oracle in the LICENSE file that accompanied this code.
  324.13 + *
  324.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  324.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  324.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  324.17 + * version 2 for more details (a copy is included in the LICENSE file that
  324.18 + * accompanied this code).
  324.19 + *
  324.20 + * You should have received a copy of the GNU General Public License version
  324.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  324.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  324.23 + *
  324.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  324.25 + * or visit www.oracle.com if you need additional information or have any
  324.26 + * questions.
  324.27 + */
  324.28 +
  324.29 +package java.io;
  324.30 +
  324.31 +/**
  324.32 + * ObjectInput extends the DataInput interface to include the reading of
  324.33 + * objects. DataInput includes methods for the input of primitive types,
  324.34 + * ObjectInput extends that interface to include objects, arrays, and Strings.
  324.35 + *
  324.36 + * @author  unascribed
  324.37 + * @see java.io.InputStream
  324.38 + * @see java.io.ObjectOutputStream
  324.39 + * @see java.io.ObjectInputStream
  324.40 + * @since   JDK1.1
  324.41 + */
  324.42 +public interface ObjectInput extends DataInput, AutoCloseable {
  324.43 +    /**
  324.44 +     * Read and return an object. The class that implements this interface
  324.45 +     * defines where the object is "read" from.
  324.46 +     *
  324.47 +     * @return the object read from the stream
  324.48 +     * @exception java.lang.ClassNotFoundException If the class of a serialized
  324.49 +     *      object cannot be found.
  324.50 +     * @exception IOException If any of the usual Input/Output
  324.51 +     * related exceptions occur.
  324.52 +     */
  324.53 +    public Object readObject()
  324.54 +        throws ClassNotFoundException, IOException;
  324.55 +
  324.56 +    /**
  324.57 +     * Reads a byte of data. This method will block if no input is
  324.58 +     * available.
  324.59 +     * @return  the byte read, or -1 if the end of the
  324.60 +     *          stream is reached.
  324.61 +     * @exception IOException If an I/O error has occurred.
  324.62 +     */
  324.63 +    public int read() throws IOException;
  324.64 +
  324.65 +    /**
  324.66 +     * Reads into an array of bytes.  This method will
  324.67 +     * block until some input is available.
  324.68 +     * @param b the buffer into which the data is read
  324.69 +     * @return  the actual number of bytes read, -1 is
  324.70 +     *          returned when the end of the stream is reached.
  324.71 +     * @exception IOException If an I/O error has occurred.
  324.72 +     */
  324.73 +    public int read(byte b[]) throws IOException;
  324.74 +
  324.75 +    /**
  324.76 +     * Reads into an array of bytes.  This method will
  324.77 +     * block until some input is available.
  324.78 +     * @param b the buffer into which the data is read
  324.79 +     * @param off the start offset of the data
  324.80 +     * @param len the maximum number of bytes read
  324.81 +     * @return  the actual number of bytes read, -1 is
  324.82 +     *          returned when the end of the stream is reached.
  324.83 +     * @exception IOException If an I/O error has occurred.
  324.84 +     */
  324.85 +    public int read(byte b[], int off, int len) throws IOException;
  324.86 +
  324.87 +    /**
  324.88 +     * Skips n bytes of input.
  324.89 +     * @param n the number of bytes to be skipped
  324.90 +     * @return  the actual number of bytes skipped.
  324.91 +     * @exception IOException If an I/O error has occurred.
  324.92 +     */
  324.93 +    public long skip(long n) throws IOException;
  324.94 +
  324.95 +    /**
  324.96 +     * Returns the number of bytes that can be read
  324.97 +     * without blocking.
  324.98 +     * @return the number of available bytes.
  324.99 +     * @exception IOException If an I/O error has occurred.
 324.100 +     */
 324.101 +    public int available() throws IOException;
 324.102 +
 324.103 +    /**
 324.104 +     * Closes the input stream. Must be called
 324.105 +     * to release any resources associated with
 324.106 +     * the stream.
 324.107 +     * @exception IOException If an I/O error has occurred.
 324.108 +     */
 324.109 +    public void close() throws IOException;
 324.110 +}
   325.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   325.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   325.3 @@ -0,0 +1,3357 @@
   325.4 +/*
   325.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   325.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   325.7 + *
   325.8 + * This code is free software; you can redistribute it and/or modify it
   325.9 + * under the terms of the GNU General Public License version 2 only, as
  325.10 + * published by the Free Software Foundation.  Oracle designates this
  325.11 + * particular file as subject to the "Classpath" exception as provided
  325.12 + * by Oracle in the LICENSE file that accompanied this code.
  325.13 + *
  325.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  325.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  325.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  325.17 + * version 2 for more details (a copy is included in the LICENSE file that
  325.18 + * accompanied this code).
  325.19 + *
  325.20 + * You should have received a copy of the GNU General Public License version
  325.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  325.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  325.23 + *
  325.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  325.25 + * or visit www.oracle.com if you need additional information or have any
  325.26 + * questions.
  325.27 + */
  325.28 +
  325.29 +package java.io;
  325.30 +
  325.31 +import java.lang.reflect.Array;
  325.32 +import java.lang.reflect.Modifier;
  325.33 +import java.lang.reflect.Proxy;
  325.34 +import java.util.Arrays;
  325.35 +import java.util.HashMap;
  325.36 +import org.apidesign.bck2brwsr.emul.lang.System;
  325.37 +
  325.38 +/**
  325.39 + * An ObjectInputStream deserializes primitive data and objects previously
  325.40 + * written using an ObjectOutputStream.
  325.41 + *
  325.42 + * <p>ObjectOutputStream and ObjectInputStream can provide an application with
  325.43 + * persistent storage for graphs of objects when used with a FileOutputStream
  325.44 + * and FileInputStream respectively.  ObjectInputStream is used to recover
  325.45 + * those objects previously serialized. Other uses include passing objects
  325.46 + * between hosts using a socket stream or for marshaling and unmarshaling
  325.47 + * arguments and parameters in a remote communication system.
  325.48 + *
  325.49 + * <p>ObjectInputStream ensures that the types of all objects in the graph
  325.50 + * created from the stream match the classes present in the Java Virtual
  325.51 + * Machine.  Classes are loaded as required using the standard mechanisms.
  325.52 + *
  325.53 + * <p>Only objects that support the java.io.Serializable or
  325.54 + * java.io.Externalizable interface can be read from streams.
  325.55 + *
  325.56 + * <p>The method <code>readObject</code> is used to read an object from the
  325.57 + * stream.  Java's safe casting should be used to get the desired type.  In
  325.58 + * Java, strings and arrays are objects and are treated as objects during
  325.59 + * serialization. When read they need to be cast to the expected type.
  325.60 + *
  325.61 + * <p>Primitive data types can be read from the stream using the appropriate
  325.62 + * method on DataInput.
  325.63 + *
  325.64 + * <p>The default deserialization mechanism for objects restores the contents
  325.65 + * of each field to the value and type it had when it was written.  Fields
  325.66 + * declared as transient or static are ignored by the deserialization process.
  325.67 + * References to other objects cause those objects to be read from the stream
  325.68 + * as necessary.  Graphs of objects are restored correctly using a reference
  325.69 + * sharing mechanism.  New objects are always allocated when deserializing,
  325.70 + * which prevents existing objects from being overwritten.
  325.71 + *
  325.72 + * <p>Reading an object is analogous to running the constructors of a new
  325.73 + * object.  Memory is allocated for the object and initialized to zero (NULL).
  325.74 + * No-arg constructors are invoked for the non-serializable classes and then
  325.75 + * the fields of the serializable classes are restored from the stream starting
  325.76 + * with the serializable class closest to java.lang.object and finishing with
  325.77 + * the object's most specific class.
  325.78 + *
  325.79 + * <p>For example to read from a stream as written by the example in
  325.80 + * ObjectOutputStream:
  325.81 + * <br>
  325.82 + * <pre>
  325.83 + *      FileInputStream fis = new FileInputStream("t.tmp");
  325.84 + *      ObjectInputStream ois = new ObjectInputStream(fis);
  325.85 + *
  325.86 + *      int i = ois.readInt();
  325.87 + *      String today = (String) ois.readObject();
  325.88 + *      Date date = (Date) ois.readObject();
  325.89 + *
  325.90 + *      ois.close();
  325.91 + * </pre>
  325.92 + *
  325.93 + * <p>Classes control how they are serialized by implementing either the
  325.94 + * java.io.Serializable or java.io.Externalizable interfaces.
  325.95 + *
  325.96 + * <p>Implementing the Serializable interface allows object serialization to
  325.97 + * save and restore the entire state of the object and it allows classes to
  325.98 + * evolve between the time the stream is written and the time it is read.  It
  325.99 + * automatically traverses references between objects, saving and restoring
 325.100 + * entire graphs.
 325.101 + *
 325.102 + * <p>Serializable classes that require special handling during the
 325.103 + * serialization and deserialization process should implement the following
 325.104 + * methods:<p>
 325.105 + *
 325.106 + * <pre>
 325.107 + * private void writeObject(java.io.ObjectOutputStream stream)
 325.108 + *     throws IOException;
 325.109 + * private void readObject(java.io.ObjectInputStream stream)
 325.110 + *     throws IOException, ClassNotFoundException;
 325.111 + * private void readObjectNoData()
 325.112 + *     throws ObjectStreamException;
 325.113 + * </pre>
 325.114 + *
 325.115 + * <p>The readObject method is responsible for reading and restoring the state
 325.116 + * of the object for its particular class using data written to the stream by
 325.117 + * the corresponding writeObject method.  The method does not need to concern
 325.118 + * itself with the state belonging to its superclasses or subclasses.  State is
 325.119 + * restored by reading data from the ObjectInputStream for the individual
 325.120 + * fields and making assignments to the appropriate fields of the object.
 325.121 + * Reading primitive data types is supported by DataInput.
 325.122 + *
 325.123 + * <p>Any attempt to read object data which exceeds the boundaries of the
 325.124 + * custom data written by the corresponding writeObject method will cause an
 325.125 + * OptionalDataException to be thrown with an eof field value of true.
 325.126 + * Non-object reads which exceed the end of the allotted data will reflect the
 325.127 + * end of data in the same way that they would indicate the end of the stream:
 325.128 + * bytewise reads will return -1 as the byte read or number of bytes read, and
 325.129 + * primitive reads will throw EOFExceptions.  If there is no corresponding
 325.130 + * writeObject method, then the end of default serialized data marks the end of
 325.131 + * the allotted data.
 325.132 + *
 325.133 + * <p>Primitive and object read calls issued from within a readExternal method
 325.134 + * behave in the same manner--if the stream is already positioned at the end of
 325.135 + * data written by the corresponding writeExternal method, object reads will
 325.136 + * throw OptionalDataExceptions with eof set to true, bytewise reads will
 325.137 + * return -1, and primitive reads will throw EOFExceptions.  Note that this
 325.138 + * behavior does not hold for streams written with the old
 325.139 + * <code>ObjectStreamConstants.PROTOCOL_VERSION_1</code> protocol, in which the
 325.140 + * end of data written by writeExternal methods is not demarcated, and hence
 325.141 + * cannot be detected.
 325.142 + *
 325.143 + * <p>The readObjectNoData method is responsible for initializing the state of
 325.144 + * the object for its particular class in the event that the serialization
 325.145 + * stream does not list the given class as a superclass of the object being
 325.146 + * deserialized.  This may occur in cases where the receiving party uses a
 325.147 + * different version of the deserialized instance's class than the sending
 325.148 + * party, and the receiver's version extends classes that are not extended by
 325.149 + * the sender's version.  This may also occur if the serialization stream has
 325.150 + * been tampered; hence, readObjectNoData is useful for initializing
 325.151 + * deserialized objects properly despite a "hostile" or incomplete source
 325.152 + * stream.
 325.153 + *
 325.154 + * <p>Serialization does not read or assign values to the fields of any object
 325.155 + * that does not implement the java.io.Serializable interface.  Subclasses of
 325.156 + * Objects that are not serializable can be serializable. In this case the
 325.157 + * non-serializable class must have a no-arg constructor to allow its fields to
 325.158 + * be initialized.  In this case it is the responsibility of the subclass to
 325.159 + * save and restore the state of the non-serializable class. It is frequently
 325.160 + * the case that the fields of that class are accessible (public, package, or
 325.161 + * protected) or that there are get and set methods that can be used to restore
 325.162 + * the state.
 325.163 + *
 325.164 + * <p>Any exception that occurs while deserializing an object will be caught by
 325.165 + * the ObjectInputStream and abort the reading process.
 325.166 + *
 325.167 + * <p>Implementing the Externalizable interface allows the object to assume
 325.168 + * complete control over the contents and format of the object's serialized
 325.169 + * form.  The methods of the Externalizable interface, writeExternal and
 325.170 + * readExternal, are called to save and restore the objects state.  When
 325.171 + * implemented by a class they can write and read their own state using all of
 325.172 + * the methods of ObjectOutput and ObjectInput.  It is the responsibility of
 325.173 + * the objects to handle any versioning that occurs.
 325.174 + *
 325.175 + * <p>Enum constants are deserialized differently than ordinary serializable or
 325.176 + * externalizable objects.  The serialized form of an enum constant consists
 325.177 + * solely of its name; field values of the constant are not transmitted.  To
 325.178 + * deserialize an enum constant, ObjectInputStream reads the constant name from
 325.179 + * the stream; the deserialized constant is then obtained by calling the static
 325.180 + * method <code>Enum.valueOf(Class, String)</code> with the enum constant's
 325.181 + * base type and the received constant name as arguments.  Like other
 325.182 + * serializable or externalizable objects, enum constants can function as the
 325.183 + * targets of back references appearing subsequently in the serialization
 325.184 + * stream.  The process by which enum constants are deserialized cannot be
 325.185 + * customized: any class-specific readObject, readObjectNoData, and readResolve
 325.186 + * methods defined by enum types are ignored during deserialization.
 325.187 + * Similarly, any serialPersistentFields or serialVersionUID field declarations
 325.188 + * are also ignored--all enum types have a fixed serialVersionUID of 0L.
 325.189 + *
 325.190 + * @author      Mike Warres
 325.191 + * @author      Roger Riggs
 325.192 + * @see java.io.DataInput
 325.193 + * @see java.io.ObjectOutputStream
 325.194 + * @see java.io.Serializable
 325.195 + * @see <a href="../../../platform/serialization/spec/input.html"> Object Serialization Specification, Section 3, Object Input Classes</a>
 325.196 + * @since   JDK1.1
 325.197 + */
 325.198 +public class ObjectInputStream
 325.199 +    extends InputStream implements ObjectInput, ObjectStreamConstants
 325.200 +{
 325.201 +    /** handle value representing null */
 325.202 +    private static final int NULL_HANDLE = -1;
 325.203 +
 325.204 +    /** marker for unshared objects in internal handle table */
 325.205 +    private static final Object unsharedMarker = new Object();
 325.206 +
 325.207 +    /** table mapping primitive type names to corresponding class objects */
 325.208 +    private static final HashMap<String, Class<?>> primClasses
 325.209 +        = new HashMap<>(8, 1.0F);
 325.210 +    static {
 325.211 +        primClasses.put("boolean", boolean.class);
 325.212 +        primClasses.put("byte", byte.class);
 325.213 +        primClasses.put("char", char.class);
 325.214 +        primClasses.put("short", short.class);
 325.215 +        primClasses.put("int", int.class);
 325.216 +        primClasses.put("long", long.class);
 325.217 +        primClasses.put("float", float.class);
 325.218 +        primClasses.put("double", double.class);
 325.219 +        primClasses.put("void", void.class);
 325.220 +    }
 325.221 +
 325.222 +    /** filter stream for handling block data conversion */
 325.223 +    private final BlockDataInputStream bin;
 325.224 +    /** validation callback list */
 325.225 +    private final ValidationList vlist;
 325.226 +    /** recursion depth */
 325.227 +    private int depth;
 325.228 +    /** whether stream is closed */
 325.229 +    private boolean closed;
 325.230 +
 325.231 +    /** wire handle -> obj/exception map */
 325.232 +    private final HandleTable handles;
 325.233 +    /** scratch field for passing handle values up/down call stack */
 325.234 +    private int passHandle = NULL_HANDLE;
 325.235 +    /** flag set when at end of field value block with no TC_ENDBLOCKDATA */
 325.236 +    private boolean defaultDataEnd = false;
 325.237 +
 325.238 +    /** buffer for reading primitive field values */
 325.239 +    private byte[] primVals;
 325.240 +
 325.241 +    /** if true, invoke readObjectOverride() instead of readObject() */
 325.242 +    private final boolean enableOverride;
 325.243 +    /** if true, invoke resolveObject() */
 325.244 +    private boolean enableResolve;
 325.245 +
 325.246 +    /**
 325.247 +     * Context during upcalls to class-defined readObject methods; holds
 325.248 +     * object currently being deserialized and descriptor for current class.
 325.249 +     * Null when not during readObject upcall.
 325.250 +     */
 325.251 +    private Object curContext;
 325.252 +
 325.253 +    /**
 325.254 +     * Creates an ObjectInputStream that reads from the specified InputStream.
 325.255 +     * A serialization stream header is read from the stream and verified.
 325.256 +     * This constructor will block until the corresponding ObjectOutputStream
 325.257 +     * has written and flushed the header.
 325.258 +     *
 325.259 +     * <p>If a security manager is installed, this constructor will check for
 325.260 +     * the "enableSubclassImplementation" SerializablePermission when invoked
 325.261 +     * directly or indirectly by the constructor of a subclass which overrides
 325.262 +     * the ObjectInputStream.readFields or ObjectInputStream.readUnshared
 325.263 +     * methods.
 325.264 +     *
 325.265 +     * @param   in input stream to read from
 325.266 +     * @throws  StreamCorruptedException if the stream header is incorrect
 325.267 +     * @throws  IOException if an I/O error occurs while reading stream header
 325.268 +     * @throws  SecurityException if untrusted subclass illegally overrides
 325.269 +     *          security-sensitive methods
 325.270 +     * @throws  NullPointerException if <code>in</code> is <code>null</code>
 325.271 +     * @see     ObjectInputStream#ObjectInputStream()
 325.272 +     * @see     ObjectInputStream#readFields()
 325.273 +     * @see     ObjectOutputStream#ObjectOutputStream(OutputStream)
 325.274 +     */
 325.275 +    public ObjectInputStream(InputStream in) throws IOException {
 325.276 +        verifySubclass();
 325.277 +        bin = new BlockDataInputStream(in);
 325.278 +        handles = new HandleTable(10);
 325.279 +        vlist = new ValidationList();
 325.280 +        enableOverride = false;
 325.281 +        readStreamHeader();
 325.282 +        bin.setBlockDataMode(true);
 325.283 +    }
 325.284 +
 325.285 +    /**
 325.286 +     * Provide a way for subclasses that are completely reimplementing
 325.287 +     * ObjectInputStream to not have to allocate private data just used by this
 325.288 +     * implementation of ObjectInputStream.
 325.289 +     *
 325.290 +     * <p>If there is a security manager installed, this method first calls the
 325.291 +     * security manager's <code>checkPermission</code> method with the
 325.292 +     * <code>SerializablePermission("enableSubclassImplementation")</code>
 325.293 +     * permission to ensure it's ok to enable subclassing.
 325.294 +     *
 325.295 +     * @throws  SecurityException if a security manager exists and its
 325.296 +     *          <code>checkPermission</code> method denies enabling
 325.297 +     *          subclassing.
 325.298 +     * @see SecurityManager#checkPermission
 325.299 +     * @see java.io.SerializablePermission
 325.300 +     */
 325.301 +    protected ObjectInputStream() throws IOException, SecurityException {
 325.302 +        throw new SecurityException();
 325.303 +    }
 325.304 +
 325.305 +    /**
 325.306 +     * Read an object from the ObjectInputStream.  The class of the object, the
 325.307 +     * signature of the class, and the values of the non-transient and
 325.308 +     * non-static fields of the class and all of its supertypes are read.
 325.309 +     * Default deserializing for a class can be overriden using the writeObject
 325.310 +     * and readObject methods.  Objects referenced by this object are read
 325.311 +     * transitively so that a complete equivalent graph of objects is
 325.312 +     * reconstructed by readObject.
 325.313 +     *
 325.314 +     * <p>The root object is completely restored when all of its fields and the
 325.315 +     * objects it references are completely restored.  At this point the object
 325.316 +     * validation callbacks are executed in order based on their registered
 325.317 +     * priorities. The callbacks are registered by objects (in the readObject
 325.318 +     * special methods) as they are individually restored.
 325.319 +     *
 325.320 +     * <p>Exceptions are thrown for problems with the InputStream and for
 325.321 +     * classes that should not be deserialized.  All exceptions are fatal to
 325.322 +     * the InputStream and leave it in an indeterminate state; it is up to the
 325.323 +     * caller to ignore or recover the stream state.
 325.324 +     *
 325.325 +     * @throws  ClassNotFoundException Class of a serialized object cannot be
 325.326 +     *          found.
 325.327 +     * @throws  InvalidClassException Something is wrong with a class used by
 325.328 +     *          serialization.
 325.329 +     * @throws  StreamCorruptedException Control information in the
 325.330 +     *          stream is inconsistent.
 325.331 +     * @throws  OptionalDataException Primitive data was found in the
 325.332 +     *          stream instead of objects.
 325.333 +     * @throws  IOException Any of the usual Input/Output related exceptions.
 325.334 +     */
 325.335 +    public final Object readObject()
 325.336 +        throws IOException, ClassNotFoundException
 325.337 +    {
 325.338 +        throw new IOException();
 325.339 +    }
 325.340 +
 325.341 +    /**
 325.342 +     * This method is called by trusted subclasses of ObjectOutputStream that
 325.343 +     * constructed ObjectOutputStream using the protected no-arg constructor.
 325.344 +     * The subclass is expected to provide an override method with the modifier
 325.345 +     * "final".
 325.346 +     *
 325.347 +     * @return  the Object read from the stream.
 325.348 +     * @throws  ClassNotFoundException Class definition of a serialized object
 325.349 +     *          cannot be found.
 325.350 +     * @throws  OptionalDataException Primitive data was found in the stream
 325.351 +     *          instead of objects.
 325.352 +     * @throws  IOException if I/O errors occurred while reading from the
 325.353 +     *          underlying stream
 325.354 +     * @see #ObjectInputStream()
 325.355 +     * @see #readObject()
 325.356 +     * @since 1.2
 325.357 +     */
 325.358 +    protected Object readObjectOverride()
 325.359 +        throws IOException, ClassNotFoundException
 325.360 +    {
 325.361 +        return null;
 325.362 +    }
 325.363 +
 325.364 +    /**
 325.365 +     * Reads an "unshared" object from the ObjectInputStream.  This method is
 325.366 +     * identical to readObject, except that it prevents subsequent calls to
 325.367 +     * readObject and readUnshared from returning additional references to the
 325.368 +     * deserialized instance obtained via this call.  Specifically:
 325.369 +     * <ul>
 325.370 +     *   <li>If readUnshared is called to deserialize a back-reference (the
 325.371 +     *       stream representation of an object which has been written
 325.372 +     *       previously to the stream), an ObjectStreamException will be
 325.373 +     *       thrown.
 325.374 +     *
 325.375 +     *   <li>If readUnshared returns successfully, then any subsequent attempts
 325.376 +     *       to deserialize back-references to the stream handle deserialized
 325.377 +     *       by readUnshared will cause an ObjectStreamException to be thrown.
 325.378 +     * </ul>
 325.379 +     * Deserializing an object via readUnshared invalidates the stream handle
 325.380 +     * associated with the returned object.  Note that this in itself does not
 325.381 +     * always guarantee that the reference returned by readUnshared is unique;
 325.382 +     * the deserialized object may define a readResolve method which returns an
 325.383 +     * object visible to other parties, or readUnshared may return a Class
 325.384 +     * object or enum constant obtainable elsewhere in the stream or through
 325.385 +     * external means. If the deserialized object defines a readResolve method
 325.386 +     * and the invocation of that method returns an array, then readUnshared
 325.387 +     * returns a shallow clone of that array; this guarantees that the returned
 325.388 +     * array object is unique and cannot be obtained a second time from an
 325.389 +     * invocation of readObject or readUnshared on the ObjectInputStream,
 325.390 +     * even if the underlying data stream has been manipulated.
 325.391 +     *
 325.392 +     * <p>ObjectInputStream subclasses which override this method can only be
 325.393 +     * constructed in security contexts possessing the
 325.394 +     * "enableSubclassImplementation" SerializablePermission; any attempt to
 325.395 +     * instantiate such a subclass without this permission will cause a
 325.396 +     * SecurityException to be thrown.
 325.397 +     *
 325.398 +     * @return  reference to deserialized object
 325.399 +     * @throws  ClassNotFoundException if class of an object to deserialize
 325.400 +     *          cannot be found
 325.401 +     * @throws  StreamCorruptedException if control information in the stream
 325.402 +     *          is inconsistent
 325.403 +     * @throws  ObjectStreamException if object to deserialize has already
 325.404 +     *          appeared in stream
 325.405 +     * @throws  OptionalDataException if primitive data is next in stream
 325.406 +     * @throws  IOException if an I/O error occurs during deserialization
 325.407 +     * @since   1.4
 325.408 +     */
 325.409 +    public Object readUnshared() throws IOException, ClassNotFoundException {
 325.410 +        // if nested read, passHandle contains handle of enclosing object
 325.411 +        int outerHandle = passHandle;
 325.412 +        try {
 325.413 +            Object obj = readObject0(true);
 325.414 +            handles.markDependency(outerHandle, passHandle);
 325.415 +            ClassNotFoundException ex = handles.lookupException(passHandle);
 325.416 +            if (ex != null) {
 325.417 +                throw ex;
 325.418 +            }
 325.419 +            if (depth == 0) {
 325.420 +                vlist.doCallbacks();
 325.421 +            }
 325.422 +            return obj;
 325.423 +        } finally {
 325.424 +            passHandle = outerHandle;
 325.425 +            if (closed && depth == 0) {
 325.426 +                clear();
 325.427 +            }
 325.428 +        }
 325.429 +    }
 325.430 +
 325.431 +    /**
 325.432 +     * Read the non-static and non-transient fields of the current class from
 325.433 +     * this stream.  This may only be called from the readObject method of the
 325.434 +     * class being deserialized. It will throw the NotActiveException if it is
 325.435 +     * called otherwise.
 325.436 +     *
 325.437 +     * @throws  ClassNotFoundException if the class of a serialized object
 325.438 +     *          could not be found.
 325.439 +     * @throws  IOException if an I/O error occurs.
 325.440 +     * @throws  NotActiveException if the stream is not currently reading
 325.441 +     *          objects.
 325.442 +     */
 325.443 +    public void defaultReadObject()
 325.444 +        throws IOException, ClassNotFoundException
 325.445 +    {
 325.446 +        if (curContext == null) {
 325.447 +            throw new NotActiveException("not in call to readObject");
 325.448 +        }
 325.449 +        Object curObj = null; // curContext.getObj();
 325.450 +        ObjectStreamClass curDesc = null; // curContext.getDesc();
 325.451 +        bin.setBlockDataMode(false);
 325.452 +        defaultReadFields(curObj, curDesc);
 325.453 +        bin.setBlockDataMode(true);
 325.454 +        if (!curDesc.hasWriteObjectData()) {
 325.455 +            /*
 325.456 +             * Fix for 4360508: since stream does not contain terminating
 325.457 +             * TC_ENDBLOCKDATA tag, set flag so that reading code elsewhere
 325.458 +             * knows to simulate end-of-custom-data behavior.
 325.459 +             */
 325.460 +            defaultDataEnd = true;
 325.461 +        }
 325.462 +        ClassNotFoundException ex = handles.lookupException(passHandle);
 325.463 +        if (ex != null) {
 325.464 +            throw ex;
 325.465 +        }
 325.466 +    }
 325.467 +
 325.468 +    /**
 325.469 +     * Reads the persistent fields from the stream and makes them available by
 325.470 +     * name.
 325.471 +     *
 325.472 +     * @return  the <code>GetField</code> object representing the persistent
 325.473 +     *          fields of the object being deserialized
 325.474 +     * @throws  ClassNotFoundException if the class of a serialized object
 325.475 +     *          could not be found.
 325.476 +     * @throws  IOException if an I/O error occurs.
 325.477 +     * @throws  NotActiveException if the stream is not currently reading
 325.478 +     *          objects.
 325.479 +     * @since 1.2
 325.480 +     */
 325.481 +    public ObjectInputStream.GetField readFields()
 325.482 +        throws IOException, ClassNotFoundException
 325.483 +    {
 325.484 +        if (curContext == null) {
 325.485 +            throw new NotActiveException("not in call to readObject");
 325.486 +        }
 325.487 +        Object curObj = null; // curContext.getObj();
 325.488 +        ObjectStreamClass curDesc = null; // curContext.getDesc();
 325.489 +        bin.setBlockDataMode(false);
 325.490 +        GetFieldImpl getField = new GetFieldImpl(curDesc);
 325.491 +        getField.readFields();
 325.492 +        bin.setBlockDataMode(true);
 325.493 +        if (!curDesc.hasWriteObjectData()) {
 325.494 +            /*
 325.495 +             * Fix for 4360508: since stream does not contain terminating
 325.496 +             * TC_ENDBLOCKDATA tag, set flag so that reading code elsewhere
 325.497 +             * knows to simulate end-of-custom-data behavior.
 325.498 +             */
 325.499 +            defaultDataEnd = true;
 325.500 +        }
 325.501 +
 325.502 +        return getField;
 325.503 +    }
 325.504 +
 325.505 +    /**
 325.506 +     * Register an object to be validated before the graph is returned.  While
 325.507 +     * similar to resolveObject these validations are called after the entire
 325.508 +     * graph has been reconstituted.  Typically, a readObject method will
 325.509 +     * register the object with the stream so that when all of the objects are
 325.510 +     * restored a final set of validations can be performed.
 325.511 +     *
 325.512 +     * @param   obj the object to receive the validation callback.
 325.513 +     * @param   prio controls the order of callbacks;zero is a good default.
 325.514 +     *          Use higher numbers to be called back earlier, lower numbers for
 325.515 +     *          later callbacks. Within a priority, callbacks are processed in
 325.516 +     *          no particular order.
 325.517 +     * @throws  NotActiveException The stream is not currently reading objects
 325.518 +     *          so it is invalid to register a callback.
 325.519 +     * @throws  InvalidObjectException The validation object is null.
 325.520 +     */
 325.521 +    public void registerValidation(ObjectInputValidation obj, int prio)
 325.522 +        throws NotActiveException, InvalidObjectException
 325.523 +    {
 325.524 +        if (depth == 0) {
 325.525 +            throw new NotActiveException("stream inactive");
 325.526 +        }
 325.527 +        vlist.register(obj, prio);
 325.528 +    }
 325.529 +
 325.530 +    /**
 325.531 +     * Load the local class equivalent of the specified stream class
 325.532 +     * description.  Subclasses may implement this method to allow classes to
 325.533 +     * be fetched from an alternate source.
 325.534 +     *
 325.535 +     * <p>The corresponding method in <code>ObjectOutputStream</code> is
 325.536 +     * <code>annotateClass</code>.  This method will be invoked only once for
 325.537 +     * each unique class in the stream.  This method can be implemented by
 325.538 +     * subclasses to use an alternate loading mechanism but must return a
 325.539 +     * <code>Class</code> object. Once returned, if the class is not an array
 325.540 +     * class, its serialVersionUID is compared to the serialVersionUID of the
 325.541 +     * serialized class, and if there is a mismatch, the deserialization fails
 325.542 +     * and an {@link InvalidClassException} is thrown.
 325.543 +     *
 325.544 +     * <p>The default implementation of this method in
 325.545 +     * <code>ObjectInputStream</code> returns the result of calling
 325.546 +     * <pre>
 325.547 +     *     Class.forName(desc.getName(), false, loader)
 325.548 +     * </pre>
 325.549 +     * where <code>loader</code> is determined as follows: if there is a
 325.550 +     * method on the current thread's stack whose declaring class was
 325.551 +     * defined by a user-defined class loader (and was not a generated to
 325.552 +     * implement reflective invocations), then <code>loader</code> is class
 325.553 +     * loader corresponding to the closest such method to the currently
 325.554 +     * executing frame; otherwise, <code>loader</code> is
 325.555 +     * <code>null</code>. If this call results in a
 325.556 +     * <code>ClassNotFoundException</code> and the name of the passed
 325.557 +     * <code>ObjectStreamClass</code> instance is the Java language keyword
 325.558 +     * for a primitive type or void, then the <code>Class</code> object
 325.559 +     * representing that primitive type or void will be returned
 325.560 +     * (e.g., an <code>ObjectStreamClass</code> with the name
 325.561 +     * <code>"int"</code> will be resolved to <code>Integer.TYPE</code>).
 325.562 +     * Otherwise, the <code>ClassNotFoundException</code> will be thrown to
 325.563 +     * the caller of this method.
 325.564 +     *
 325.565 +     * @param   desc an instance of class <code>ObjectStreamClass</code>
 325.566 +     * @return  a <code>Class</code> object corresponding to <code>desc</code>
 325.567 +     * @throws  IOException any of the usual Input/Output exceptions.
 325.568 +     * @throws  ClassNotFoundException if class of a serialized object cannot
 325.569 +     *          be found.
 325.570 +     */
 325.571 +    protected Class<?> resolveClass(ObjectStreamClass desc)
 325.572 +        throws IOException, ClassNotFoundException
 325.573 +    {
 325.574 +        String name = desc.getName();
 325.575 +        try {
 325.576 +            return Class.forName(name, false, latestUserDefinedLoader());
 325.577 +        } catch (ClassNotFoundException ex) {
 325.578 +            Class<?> cl = primClasses.get(name);
 325.579 +            if (cl != null) {
 325.580 +                return cl;
 325.581 +            } else {
 325.582 +                throw ex;
 325.583 +            }
 325.584 +        }
 325.585 +    }
 325.586 +
 325.587 +    /**
 325.588 +     * Returns a proxy class that implements the interfaces named in a proxy
 325.589 +     * class descriptor; subclasses may implement this method to read custom
 325.590 +     * data from the stream along with the descriptors for dynamic proxy
 325.591 +     * classes, allowing them to use an alternate loading mechanism for the
 325.592 +     * interfaces and the proxy class.
 325.593 +     *
 325.594 +     * <p>This method is called exactly once for each unique proxy class
 325.595 +     * descriptor in the stream.
 325.596 +     *
 325.597 +     * <p>The corresponding method in <code>ObjectOutputStream</code> is
 325.598 +     * <code>annotateProxyClass</code>.  For a given subclass of
 325.599 +     * <code>ObjectInputStream</code> that overrides this method, the
 325.600 +     * <code>annotateProxyClass</code> method in the corresponding subclass of
 325.601 +     * <code>ObjectOutputStream</code> must write any data or objects read by
 325.602 +     * this method.
 325.603 +     *
 325.604 +     * <p>The default implementation of this method in
 325.605 +     * <code>ObjectInputStream</code> returns the result of calling
 325.606 +     * <code>Proxy.getProxyClass</code> with the list of <code>Class</code>
 325.607 +     * objects for the interfaces that are named in the <code>interfaces</code>
 325.608 +     * parameter.  The <code>Class</code> object for each interface name
 325.609 +     * <code>i</code> is the value returned by calling
 325.610 +     * <pre>
 325.611 +     *     Class.forName(i, false, loader)
 325.612 +     * </pre>
 325.613 +     * where <code>loader</code> is that of the first non-<code>null</code>
 325.614 +     * class loader up the execution stack, or <code>null</code> if no
 325.615 +     * non-<code>null</code> class loaders are on the stack (the same class
 325.616 +     * loader choice used by the <code>resolveClass</code> method).  Unless any
 325.617 +     * of the resolved interfaces are non-public, this same value of
 325.618 +     * <code>loader</code> is also the class loader passed to
 325.619 +     * <code>Proxy.getProxyClass</code>; if non-public interfaces are present,
 325.620 +     * their class loader is passed instead (if more than one non-public
 325.621 +     * interface class loader is encountered, an
 325.622 +     * <code>IllegalAccessError</code> is thrown).
 325.623 +     * If <code>Proxy.getProxyClass</code> throws an
 325.624 +     * <code>IllegalArgumentException</code>, <code>resolveProxyClass</code>
 325.625 +     * will throw a <code>ClassNotFoundException</code> containing the
 325.626 +     * <code>IllegalArgumentException</code>.
 325.627 +     *
 325.628 +     * @param interfaces the list of interface names that were
 325.629 +     *                deserialized in the proxy class descriptor
 325.630 +     * @return  a proxy class for the specified interfaces
 325.631 +     * @throws        IOException any exception thrown by the underlying
 325.632 +     *                <code>InputStream</code>
 325.633 +     * @throws        ClassNotFoundException if the proxy class or any of the
 325.634 +     *                named interfaces could not be found
 325.635 +     * @see ObjectOutputStream#annotateProxyClass(Class)
 325.636 +     * @since 1.3
 325.637 +     */
 325.638 +    protected Class<?> resolveProxyClass(String[] interfaces)
 325.639 +        throws IOException, ClassNotFoundException
 325.640 +    {
 325.641 +        ClassLoader latestLoader = latestUserDefinedLoader();
 325.642 +        ClassLoader nonPublicLoader = null;
 325.643 +        boolean hasNonPublicInterface = false;
 325.644 +
 325.645 +        // define proxy in class loader of non-public interface(s), if any
 325.646 +        Class[] classObjs = new Class[interfaces.length];
 325.647 +        for (int i = 0; i < interfaces.length; i++) {
 325.648 +            Class cl = Class.forName(interfaces[i], false, latestLoader);
 325.649 +            if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
 325.650 +                if (hasNonPublicInterface) {
 325.651 +                    if (nonPublicLoader != cl.getClassLoader()) {
 325.652 +                        throw new IllegalAccessError(
 325.653 +                            "conflicting non-public interface class loaders");
 325.654 +                    }
 325.655 +                } else {
 325.656 +                    nonPublicLoader = cl.getClassLoader();
 325.657 +                    hasNonPublicInterface = true;
 325.658 +                }
 325.659 +            }
 325.660 +            classObjs[i] = cl;
 325.661 +        }
 325.662 +        try {
 325.663 +            return Proxy.getProxyClass(
 325.664 +                hasNonPublicInterface ? nonPublicLoader : latestLoader,
 325.665 +                classObjs);
 325.666 +        } catch (IllegalArgumentException e) {
 325.667 +            throw new ClassNotFoundException(null, e);
 325.668 +        }
 325.669 +    }
 325.670 +
 325.671 +    /**
 325.672 +     * This method will allow trusted subclasses of ObjectInputStream to
 325.673 +     * substitute one object for another during deserialization. Replacing
 325.674 +     * objects is disabled until enableResolveObject is called. The
 325.675 +     * enableResolveObject method checks that the stream requesting to resolve
 325.676 +     * object can be trusted. Every reference to serializable objects is passed
 325.677 +     * to resolveObject.  To insure that the private state of objects is not
 325.678 +     * unintentionally exposed only trusted streams may use resolveObject.
 325.679 +     *
 325.680 +     * <p>This method is called after an object has been read but before it is
 325.681 +     * returned from readObject.  The default resolveObject method just returns
 325.682 +     * the same object.
 325.683 +     *
 325.684 +     * <p>When a subclass is replacing objects it must insure that the
 325.685 +     * substituted object is compatible with every field where the reference
 325.686 +     * will be stored.  Objects whose type is not a subclass of the type of the
 325.687 +     * field or array element abort the serialization by raising an exception
 325.688 +     * and the object is not be stored.
 325.689 +     *
 325.690 +     * <p>This method is called only once when each object is first
 325.691 +     * encountered.  All subsequent references to the object will be redirected
 325.692 +     * to the new object.
 325.693 +     *
 325.694 +     * @param   obj object to be substituted
 325.695 +     * @return  the substituted object
 325.696 +     * @throws  IOException Any of the usual Input/Output exceptions.
 325.697 +     */
 325.698 +    protected Object resolveObject(Object obj) throws IOException {
 325.699 +        return obj;
 325.700 +    }
 325.701 +
 325.702 +    /**
 325.703 +     * Enable the stream to allow objects read from the stream to be replaced.
 325.704 +     * When enabled, the resolveObject method is called for every object being
 325.705 +     * deserialized.
 325.706 +     *
 325.707 +     * <p>If <i>enable</i> is true, and there is a security manager installed,
 325.708 +     * this method first calls the security manager's
 325.709 +     * <code>checkPermission</code> method with the
 325.710 +     * <code>SerializablePermission("enableSubstitution")</code> permission to
 325.711 +     * ensure it's ok to enable the stream to allow objects read from the
 325.712 +     * stream to be replaced.
 325.713 +     *
 325.714 +     * @param   enable true for enabling use of <code>resolveObject</code> for
 325.715 +     *          every object being deserialized
 325.716 +     * @return  the previous setting before this method was invoked
 325.717 +     * @throws  SecurityException if a security manager exists and its
 325.718 +     *          <code>checkPermission</code> method denies enabling the stream
 325.719 +     *          to allow objects read from the stream to be replaced.
 325.720 +     * @see SecurityManager#checkPermission
 325.721 +     * @see java.io.SerializablePermission
 325.722 +     */
 325.723 +    protected boolean enableResolveObject(boolean enable)
 325.724 +        throws SecurityException
 325.725 +    {
 325.726 +        throw new SecurityException();
 325.727 +    }
 325.728 +
 325.729 +    /**
 325.730 +     * The readStreamHeader method is provided to allow subclasses to read and
 325.731 +     * verify their own stream headers. It reads and verifies the magic number
 325.732 +     * and version number.
 325.733 +     *
 325.734 +     * @throws  IOException if there are I/O errors while reading from the
 325.735 +     *          underlying <code>InputStream</code>
 325.736 +     * @throws  StreamCorruptedException if control information in the stream
 325.737 +     *          is inconsistent
 325.738 +     */
 325.739 +    protected void readStreamHeader()
 325.740 +        throws IOException, StreamCorruptedException
 325.741 +    {
 325.742 +        short s0 = bin.readShort();
 325.743 +        short s1 = bin.readShort();
 325.744 +        if (s0 != STREAM_MAGIC || s1 != STREAM_VERSION) {
 325.745 +            throw new StreamCorruptedException(
 325.746 +                String.format("invalid stream header: %04X%04X", s0, s1));
 325.747 +        }
 325.748 +    }
 325.749 +
 325.750 +    /**
 325.751 +     * Read a class descriptor from the serialization stream.  This method is
 325.752 +     * called when the ObjectInputStream expects a class descriptor as the next
 325.753 +     * item in the serialization stream.  Subclasses of ObjectInputStream may
 325.754 +     * override this method to read in class descriptors that have been written
 325.755 +     * in non-standard formats (by subclasses of ObjectOutputStream which have
 325.756 +     * overridden the <code>writeClassDescriptor</code> method).  By default,
 325.757 +     * this method reads class descriptors according to the format defined in
 325.758 +     * the Object Serialization specification.
 325.759 +     *
 325.760 +     * @return  the class descriptor read
 325.761 +     * @throws  IOException If an I/O error has occurred.
 325.762 +     * @throws  ClassNotFoundException If the Class of a serialized object used
 325.763 +     *          in the class descriptor representation cannot be found
 325.764 +     * @see java.io.ObjectOutputStream#writeClassDescriptor(java.io.ObjectStreamClass)
 325.765 +     * @since 1.3
 325.766 +     */
 325.767 +    protected ObjectStreamClass readClassDescriptor()
 325.768 +        throws IOException, ClassNotFoundException
 325.769 +    {
 325.770 +        ObjectStreamClass desc = new ObjectStreamClass();
 325.771 +        desc.readNonProxy(this);
 325.772 +        return desc;
 325.773 +    }
 325.774 +
 325.775 +    /**
 325.776 +     * Reads a byte of data. This method will block if no input is available.
 325.777 +     *
 325.778 +     * @return  the byte read, or -1 if the end of the stream is reached.
 325.779 +     * @throws  IOException If an I/O error has occurred.
 325.780 +     */
 325.781 +    public int read() throws IOException {
 325.782 +        return bin.read();
 325.783 +    }
 325.784 +
 325.785 +    /**
 325.786 +     * Reads into an array of bytes.  This method will block until some input
 325.787 +     * is available. Consider using java.io.DataInputStream.readFully to read
 325.788 +     * exactly 'length' bytes.
 325.789 +     *
 325.790 +     * @param   buf the buffer into which the data is read
 325.791 +     * @param   off the start offset of the data
 325.792 +     * @param   len the maximum number of bytes read
 325.793 +     * @return  the actual number of bytes read, -1 is returned when the end of
 325.794 +     *          the stream is reached.
 325.795 +     * @throws  IOException If an I/O error has occurred.
 325.796 +     * @see java.io.DataInputStream#readFully(byte[],int,int)
 325.797 +     */
 325.798 +    public int read(byte[] buf, int off, int len) throws IOException {
 325.799 +        if (buf == null) {
 325.800 +            throw new NullPointerException();
 325.801 +        }
 325.802 +        int endoff = off + len;
 325.803 +        if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
 325.804 +            throw new IndexOutOfBoundsException();
 325.805 +        }
 325.806 +        return bin.read(buf, off, len, false);
 325.807 +    }
 325.808 +
 325.809 +    /**
 325.810 +     * Returns the number of bytes that can be read without blocking.
 325.811 +     *
 325.812 +     * @return  the number of available bytes.
 325.813 +     * @throws  IOException if there are I/O errors while reading from the
 325.814 +     *          underlying <code>InputStream</code>
 325.815 +     */
 325.816 +    public int available() throws IOException {
 325.817 +        return bin.available();
 325.818 +    }
 325.819 +
 325.820 +    /**
 325.821 +     * Closes the input stream. Must be called to release any resources
 325.822 +     * associated with the stream.
 325.823 +     *
 325.824 +     * @throws  IOException If an I/O error has occurred.
 325.825 +     */
 325.826 +    public void close() throws IOException {
 325.827 +        /*
 325.828 +         * Even if stream already closed, propagate redundant close to
 325.829 +         * underlying stream to stay consistent with previous implementations.
 325.830 +         */
 325.831 +        closed = true;
 325.832 +        if (depth == 0) {
 325.833 +            clear();
 325.834 +        }
 325.835 +        bin.close();
 325.836 +    }
 325.837 +
 325.838 +    /**
 325.839 +     * Reads in a boolean.
 325.840 +     *
 325.841 +     * @return  the boolean read.
 325.842 +     * @throws  EOFException If end of file is reached.
 325.843 +     * @throws  IOException If other I/O error has occurred.
 325.844 +     */
 325.845 +    public boolean readBoolean() throws IOException {
 325.846 +        return bin.readBoolean();
 325.847 +    }
 325.848 +
 325.849 +    /**
 325.850 +     * Reads an 8 bit byte.
 325.851 +     *
 325.852 +     * @return  the 8 bit byte read.
 325.853 +     * @throws  EOFException If end of file is reached.
 325.854 +     * @throws  IOException If other I/O error has occurred.
 325.855 +     */
 325.856 +    public byte readByte() throws IOException  {
 325.857 +        return bin.readByte();
 325.858 +    }
 325.859 +
 325.860 +    /**
 325.861 +     * Reads an unsigned 8 bit byte.
 325.862 +     *
 325.863 +     * @return  the 8 bit byte read.
 325.864 +     * @throws  EOFException If end of file is reached.
 325.865 +     * @throws  IOException If other I/O error has occurred.
 325.866 +     */
 325.867 +    public int readUnsignedByte()  throws IOException {
 325.868 +        return bin.readUnsignedByte();
 325.869 +    }
 325.870 +
 325.871 +    /**
 325.872 +     * Reads a 16 bit char.
 325.873 +     *
 325.874 +     * @return  the 16 bit char read.
 325.875 +     * @throws  EOFException If end of file is reached.
 325.876 +     * @throws  IOException If other I/O error has occurred.
 325.877 +     */
 325.878 +    public char readChar()  throws IOException {
 325.879 +        return bin.readChar();
 325.880 +    }
 325.881 +
 325.882 +    /**
 325.883 +     * Reads a 16 bit short.
 325.884 +     *
 325.885 +     * @return  the 16 bit short read.
 325.886 +     * @throws  EOFException If end of file is reached.
 325.887 +     * @throws  IOException If other I/O error has occurred.
 325.888 +     */
 325.889 +    public short readShort()  throws IOException {
 325.890 +        return bin.readShort();
 325.891 +    }
 325.892 +
 325.893 +    /**
 325.894 +     * Reads an unsigned 16 bit short.
 325.895 +     *
 325.896 +     * @return  the 16 bit short read.
 325.897 +     * @throws  EOFException If end of file is reached.
 325.898 +     * @throws  IOException If other I/O error has occurred.
 325.899 +     */
 325.900 +    public int readUnsignedShort() throws IOException {
 325.901 +        return bin.readUnsignedShort();
 325.902 +    }
 325.903 +
 325.904 +    /**
 325.905 +     * Reads a 32 bit int.
 325.906 +     *
 325.907 +     * @return  the 32 bit integer read.
 325.908 +     * @throws  EOFException If end of file is reached.
 325.909 +     * @throws  IOException If other I/O error has occurred.
 325.910 +     */
 325.911 +    public int readInt()  throws IOException {
 325.912 +        return bin.readInt();
 325.913 +    }
 325.914 +
 325.915 +    /**
 325.916 +     * Reads a 64 bit long.
 325.917 +     *
 325.918 +     * @return  the read 64 bit long.
 325.919 +     * @throws  EOFException If end of file is reached.
 325.920 +     * @throws  IOException If other I/O error has occurred.
 325.921 +     */
 325.922 +    public long readLong()  throws IOException {
 325.923 +        return bin.readLong();
 325.924 +    }
 325.925 +
 325.926 +    /**
 325.927 +     * Reads a 32 bit float.
 325.928 +     *
 325.929 +     * @return  the 32 bit float read.
 325.930 +     * @throws  EOFException If end of file is reached.
 325.931 +     * @throws  IOException If other I/O error has occurred.
 325.932 +     */
 325.933 +    public float readFloat() throws IOException {
 325.934 +        return bin.readFloat();
 325.935 +    }
 325.936 +
 325.937 +    /**
 325.938 +     * Reads a 64 bit double.
 325.939 +     *
 325.940 +     * @return  the 64 bit double read.
 325.941 +     * @throws  EOFException If end of file is reached.
 325.942 +     * @throws  IOException If other I/O error has occurred.
 325.943 +     */
 325.944 +    public double readDouble() throws IOException {
 325.945 +        return bin.readDouble();
 325.946 +    }
 325.947 +
 325.948 +    /**
 325.949 +     * Reads bytes, blocking until all bytes are read.
 325.950 +     *
 325.951 +     * @param   buf the buffer into which the data is read
 325.952 +     * @throws  EOFException If end of file is reached.
 325.953 +     * @throws  IOException If other I/O error has occurred.
 325.954 +     */
 325.955 +    public void readFully(byte[] buf) throws IOException {
 325.956 +        bin.readFully(buf, 0, buf.length, false);
 325.957 +    }
 325.958 +
 325.959 +    /**
 325.960 +     * Reads bytes, blocking until all bytes are read.
 325.961 +     *
 325.962 +     * @param   buf the buffer into which the data is read
 325.963 +     * @param   off the start offset of the data
 325.964 +     * @param   len the maximum number of bytes to read
 325.965 +     * @throws  EOFException If end of file is reached.
 325.966 +     * @throws  IOException If other I/O error has occurred.
 325.967 +     */
 325.968 +    public void readFully(byte[] buf, int off, int len) throws IOException {
 325.969 +        int endoff = off + len;
 325.970 +        if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
 325.971 +            throw new IndexOutOfBoundsException();
 325.972 +        }
 325.973 +        bin.readFully(buf, off, len, false);
 325.974 +    }
 325.975 +
 325.976 +    /**
 325.977 +     * Skips bytes.
 325.978 +     *
 325.979 +     * @param   len the number of bytes to be skipped
 325.980 +     * @return  the actual number of bytes skipped.
 325.981 +     * @throws  IOException If an I/O error has occurred.
 325.982 +     */
 325.983 +    public int skipBytes(int len) throws IOException {
 325.984 +        return bin.skipBytes(len);
 325.985 +    }
 325.986 +
 325.987 +    /**
 325.988 +     * Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
 325.989 +     *
 325.990 +     * @return  a String copy of the line.
 325.991 +     * @throws  IOException if there are I/O errors while reading from the
 325.992 +     *          underlying <code>InputStream</code>
 325.993 +     * @deprecated This method does not properly convert bytes to characters.
 325.994 +     *          see DataInputStream for the details and alternatives.
 325.995 +     */
 325.996 +    @Deprecated
 325.997 +    public String readLine() throws IOException {
 325.998 +        return bin.readLine();
 325.999 +    }
325.1000 +
325.1001 +    /**
325.1002 +     * Reads a String in
325.1003 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
325.1004 +     * format.
325.1005 +     *
325.1006 +     * @return  the String.
325.1007 +     * @throws  IOException if there are I/O errors while reading from the
325.1008 +     *          underlying <code>InputStream</code>
325.1009 +     * @throws  UTFDataFormatException if read bytes do not represent a valid
325.1010 +     *          modified UTF-8 encoding of a string
325.1011 +     */
325.1012 +    public String readUTF() throws IOException {
325.1013 +        return bin.readUTF();
325.1014 +    }
325.1015 +
325.1016 +    /**
325.1017 +     * Provide access to the persistent fields read from the input stream.
325.1018 +     */
325.1019 +    public static abstract class GetField {
325.1020 +
325.1021 +        /**
325.1022 +         * Get the ObjectStreamClass that describes the fields in the stream.
325.1023 +         *
325.1024 +         * @return  the descriptor class that describes the serializable fields
325.1025 +         */
325.1026 +        public abstract ObjectStreamClass getObjectStreamClass();
325.1027 +
325.1028 +        /**
325.1029 +         * Return true if the named field is defaulted and has no value in this
325.1030 +         * stream.
325.1031 +         *
325.1032 +         * @param  name the name of the field
325.1033 +         * @return true, if and only if the named field is defaulted
325.1034 +         * @throws IOException if there are I/O errors while reading from
325.1035 +         *         the underlying <code>InputStream</code>
325.1036 +         * @throws IllegalArgumentException if <code>name</code> does not
325.1037 +         *         correspond to a serializable field
325.1038 +         */
325.1039 +        public abstract boolean defaulted(String name) throws IOException;
325.1040 +
325.1041 +        /**
325.1042 +         * Get the value of the named boolean field from the persistent field.
325.1043 +         *
325.1044 +         * @param  name the name of the field
325.1045 +         * @param  val the default value to use if <code>name</code> does not
325.1046 +         *         have a value
325.1047 +         * @return the value of the named <code>boolean</code> field
325.1048 +         * @throws IOException if there are I/O errors while reading from the
325.1049 +         *         underlying <code>InputStream</code>
325.1050 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1051 +         *         not serializable or if the field type is incorrect
325.1052 +         */
325.1053 +        public abstract boolean get(String name, boolean val)
325.1054 +            throws IOException;
325.1055 +
325.1056 +        /**
325.1057 +         * Get the value of the named byte field from the persistent field.
325.1058 +         *
325.1059 +         * @param  name the name of the field
325.1060 +         * @param  val the default value to use if <code>name</code> does not
325.1061 +         *         have a value
325.1062 +         * @return the value of the named <code>byte</code> field
325.1063 +         * @throws IOException if there are I/O errors while reading from the
325.1064 +         *         underlying <code>InputStream</code>
325.1065 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1066 +         *         not serializable or if the field type is incorrect
325.1067 +         */
325.1068 +        public abstract byte get(String name, byte val) throws IOException;
325.1069 +
325.1070 +        /**
325.1071 +         * Get the value of the named char field from the persistent field.
325.1072 +         *
325.1073 +         * @param  name the name of the field
325.1074 +         * @param  val the default value to use if <code>name</code> does not
325.1075 +         *         have a value
325.1076 +         * @return the value of the named <code>char</code> field
325.1077 +         * @throws IOException if there are I/O errors while reading from the
325.1078 +         *         underlying <code>InputStream</code>
325.1079 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1080 +         *         not serializable or if the field type is incorrect
325.1081 +         */
325.1082 +        public abstract char get(String name, char val) throws IOException;
325.1083 +
325.1084 +        /**
325.1085 +         * Get the value of the named short field from the persistent field.
325.1086 +         *
325.1087 +         * @param  name the name of the field
325.1088 +         * @param  val the default value to use if <code>name</code> does not
325.1089 +         *         have a value
325.1090 +         * @return the value of the named <code>short</code> field
325.1091 +         * @throws IOException if there are I/O errors while reading from the
325.1092 +         *         underlying <code>InputStream</code>
325.1093 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1094 +         *         not serializable or if the field type is incorrect
325.1095 +         */
325.1096 +        public abstract short get(String name, short val) throws IOException;
325.1097 +
325.1098 +        /**
325.1099 +         * Get the value of the named int field from the persistent field.
325.1100 +         *
325.1101 +         * @param  name the name of the field
325.1102 +         * @param  val the default value to use if <code>name</code> does not
325.1103 +         *         have a value
325.1104 +         * @return the value of the named <code>int</code> field
325.1105 +         * @throws IOException if there are I/O errors while reading from the
325.1106 +         *         underlying <code>InputStream</code>
325.1107 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1108 +         *         not serializable or if the field type is incorrect
325.1109 +         */
325.1110 +        public abstract int get(String name, int val) throws IOException;
325.1111 +
325.1112 +        /**
325.1113 +         * Get the value of the named long field from the persistent field.
325.1114 +         *
325.1115 +         * @param  name the name of the field
325.1116 +         * @param  val the default value to use if <code>name</code> does not
325.1117 +         *         have a value
325.1118 +         * @return the value of the named <code>long</code> field
325.1119 +         * @throws IOException if there are I/O errors while reading from the
325.1120 +         *         underlying <code>InputStream</code>
325.1121 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1122 +         *         not serializable or if the field type is incorrect
325.1123 +         */
325.1124 +        public abstract long get(String name, long val) throws IOException;
325.1125 +
325.1126 +        /**
325.1127 +         * Get the value of the named float field from the persistent field.
325.1128 +         *
325.1129 +         * @param  name the name of the field
325.1130 +         * @param  val the default value to use if <code>name</code> does not
325.1131 +         *         have a value
325.1132 +         * @return the value of the named <code>float</code> field
325.1133 +         * @throws IOException if there are I/O errors while reading from the
325.1134 +         *         underlying <code>InputStream</code>
325.1135 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1136 +         *         not serializable or if the field type is incorrect
325.1137 +         */
325.1138 +        public abstract float get(String name, float val) throws IOException;
325.1139 +
325.1140 +        /**
325.1141 +         * Get the value of the named double field from the persistent field.
325.1142 +         *
325.1143 +         * @param  name the name of the field
325.1144 +         * @param  val the default value to use if <code>name</code> does not
325.1145 +         *         have a value
325.1146 +         * @return the value of the named <code>double</code> field
325.1147 +         * @throws IOException if there are I/O errors while reading from the
325.1148 +         *         underlying <code>InputStream</code>
325.1149 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1150 +         *         not serializable or if the field type is incorrect
325.1151 +         */
325.1152 +        public abstract double get(String name, double val) throws IOException;
325.1153 +
325.1154 +        /**
325.1155 +         * Get the value of the named Object field from the persistent field.
325.1156 +         *
325.1157 +         * @param  name the name of the field
325.1158 +         * @param  val the default value to use if <code>name</code> does not
325.1159 +         *         have a value
325.1160 +         * @return the value of the named <code>Object</code> field
325.1161 +         * @throws IOException if there are I/O errors while reading from the
325.1162 +         *         underlying <code>InputStream</code>
325.1163 +         * @throws IllegalArgumentException if type of <code>name</code> is
325.1164 +         *         not serializable or if the field type is incorrect
325.1165 +         */
325.1166 +        public abstract Object get(String name, Object val) throws IOException;
325.1167 +    }
325.1168 +
325.1169 +    /**
325.1170 +     * Verifies that this (possibly subclass) instance can be constructed
325.1171 +     * without violating security constraints: the subclass must not override
325.1172 +     * security-sensitive non-final methods, or else the
325.1173 +     * "enableSubclassImplementation" SerializablePermission is checked.
325.1174 +     */
325.1175 +    private void verifySubclass() {
325.1176 +        Class cl = getClass();
325.1177 +        if (cl == ObjectInputStream.class) {
325.1178 +            return;
325.1179 +        }
325.1180 +        throw new SecurityException();
325.1181 +    }
325.1182 +
325.1183 +    /**
325.1184 +     * Clears internal data structures.
325.1185 +     */
325.1186 +    private void clear() {
325.1187 +        handles.clear();
325.1188 +        vlist.clear();
325.1189 +    }
325.1190 +
325.1191 +    /**
325.1192 +     * Underlying readObject implementation.
325.1193 +     */
325.1194 +    private Object readObject0(boolean unshared) throws IOException {
325.1195 +        boolean oldMode = bin.getBlockDataMode();
325.1196 +        if (oldMode) {
325.1197 +            int remain = bin.currentBlockRemaining();
325.1198 +            if (remain > 0) {
325.1199 +                throw new OptionalDataException(remain);
325.1200 +            } else if (defaultDataEnd) {
325.1201 +                /*
325.1202 +                 * Fix for 4360508: stream is currently at the end of a field
325.1203 +                 * value block written via default serialization; since there
325.1204 +                 * is no terminating TC_ENDBLOCKDATA tag, simulate
325.1205 +                 * end-of-custom-data behavior explicitly.
325.1206 +                 */
325.1207 +                throw new OptionalDataException(true);
325.1208 +            }
325.1209 +            bin.setBlockDataMode(false);
325.1210 +        }
325.1211 +
325.1212 +        byte tc;
325.1213 +        while ((tc = bin.peekByte()) == TC_RESET) {
325.1214 +            bin.readByte();
325.1215 +            handleReset();
325.1216 +        }
325.1217 +
325.1218 +        depth++;
325.1219 +        try {
325.1220 +            switch (tc) {
325.1221 +                case TC_NULL:
325.1222 +                    return readNull();
325.1223 +
325.1224 +                case TC_REFERENCE:
325.1225 +                    return readHandle(unshared);
325.1226 +
325.1227 +                case TC_CLASS:
325.1228 +                    return readClass(unshared);
325.1229 +
325.1230 +                case TC_CLASSDESC:
325.1231 +                case TC_PROXYCLASSDESC:
325.1232 +                    return readClassDesc(unshared);
325.1233 +
325.1234 +                case TC_STRING:
325.1235 +                case TC_LONGSTRING:
325.1236 +                    return checkResolve(readString(unshared));
325.1237 +
325.1238 +                case TC_ARRAY:
325.1239 +                    return checkResolve(readArray(unshared));
325.1240 +
325.1241 +                case TC_ENUM:
325.1242 +                    return checkResolve(readEnum(unshared));
325.1243 +
325.1244 +                case TC_OBJECT:
325.1245 +                    return checkResolve(readOrdinaryObject(unshared));
325.1246 +
325.1247 +                case TC_EXCEPTION:
325.1248 +                    IOException ex = readFatalException();
325.1249 +                    throw new WriteAbortedException("writing aborted", ex);
325.1250 +
325.1251 +                case TC_BLOCKDATA:
325.1252 +                case TC_BLOCKDATALONG:
325.1253 +                    if (oldMode) {
325.1254 +                        bin.setBlockDataMode(true);
325.1255 +                        bin.peek();             // force header read
325.1256 +                        throw new OptionalDataException(
325.1257 +                            bin.currentBlockRemaining());
325.1258 +                    } else {
325.1259 +                        throw new StreamCorruptedException(
325.1260 +                            "unexpected block data");
325.1261 +                    }
325.1262 +
325.1263 +                case TC_ENDBLOCKDATA:
325.1264 +                    if (oldMode) {
325.1265 +                        throw new OptionalDataException(true);
325.1266 +                    } else {
325.1267 +                        throw new StreamCorruptedException(
325.1268 +                            "unexpected end of block data");
325.1269 +                    }
325.1270 +
325.1271 +                default:
325.1272 +                    throw new StreamCorruptedException(
325.1273 +                        String.format("invalid type code: %02X", tc));
325.1274 +            }
325.1275 +        } finally {
325.1276 +            depth--;
325.1277 +            bin.setBlockDataMode(oldMode);
325.1278 +        }
325.1279 +    }
325.1280 +
325.1281 +    /**
325.1282 +     * If resolveObject has been enabled and given object does not have an
325.1283 +     * exception associated with it, calls resolveObject to determine
325.1284 +     * replacement for object, and updates handle table accordingly.  Returns
325.1285 +     * replacement object, or echoes provided object if no replacement
325.1286 +     * occurred.  Expects that passHandle is set to given object's handle prior
325.1287 +     * to calling this method.
325.1288 +     */
325.1289 +    private Object checkResolve(Object obj) throws IOException {
325.1290 +        if (!enableResolve || handles.lookupException(passHandle) != null) {
325.1291 +            return obj;
325.1292 +        }
325.1293 +        Object rep = resolveObject(obj);
325.1294 +        if (rep != obj) {
325.1295 +            handles.setObject(passHandle, rep);
325.1296 +        }
325.1297 +        return rep;
325.1298 +    }
325.1299 +
325.1300 +    /**
325.1301 +     * Reads string without allowing it to be replaced in stream.  Called from
325.1302 +     * within ObjectStreamClass.read().
325.1303 +     */
325.1304 +    String readTypeString() throws IOException {
325.1305 +        int oldHandle = passHandle;
325.1306 +        try {
325.1307 +            byte tc = bin.peekByte();
325.1308 +            switch (tc) {
325.1309 +                case TC_NULL:
325.1310 +                    return (String) readNull();
325.1311 +
325.1312 +                case TC_REFERENCE:
325.1313 +                    return (String) readHandle(false);
325.1314 +
325.1315 +                case TC_STRING:
325.1316 +                case TC_LONGSTRING:
325.1317 +                    return readString(false);
325.1318 +
325.1319 +                default:
325.1320 +                    throw new StreamCorruptedException(
325.1321 +                        String.format("invalid type code: %02X", tc));
325.1322 +            }
325.1323 +        } finally {
325.1324 +            passHandle = oldHandle;
325.1325 +        }
325.1326 +    }
325.1327 +
325.1328 +    /**
325.1329 +     * Reads in null code, sets passHandle to NULL_HANDLE and returns null.
325.1330 +     */
325.1331 +    private Object readNull() throws IOException {
325.1332 +        if (bin.readByte() != TC_NULL) {
325.1333 +            throw new InternalError();
325.1334 +        }
325.1335 +        passHandle = NULL_HANDLE;
325.1336 +        return null;
325.1337 +    }
325.1338 +
325.1339 +    /**
325.1340 +     * Reads in object handle, sets passHandle to the read handle, and returns
325.1341 +     * object associated with the handle.
325.1342 +     */
325.1343 +    private Object readHandle(boolean unshared) throws IOException {
325.1344 +        if (bin.readByte() != TC_REFERENCE) {
325.1345 +            throw new InternalError();
325.1346 +        }
325.1347 +        passHandle = bin.readInt() - baseWireHandle;
325.1348 +        if (passHandle < 0 || passHandle >= handles.size()) {
325.1349 +            throw new StreamCorruptedException(
325.1350 +                String.format("invalid handle value: %08X", passHandle +
325.1351 +                baseWireHandle));
325.1352 +        }
325.1353 +        if (unshared) {
325.1354 +            // REMIND: what type of exception to throw here?
325.1355 +            throw new InvalidObjectException(
325.1356 +                "cannot read back reference as unshared");
325.1357 +        }
325.1358 +
325.1359 +        Object obj = handles.lookupObject(passHandle);
325.1360 +        if (obj == unsharedMarker) {
325.1361 +            // REMIND: what type of exception to throw here?
325.1362 +            throw new InvalidObjectException(
325.1363 +                "cannot read back reference to unshared object");
325.1364 +        }
325.1365 +        return obj;
325.1366 +    }
325.1367 +
325.1368 +    /**
325.1369 +     * Reads in and returns class object.  Sets passHandle to class object's
325.1370 +     * assigned handle.  Returns null if class is unresolvable (in which case a
325.1371 +     * ClassNotFoundException will be associated with the class' handle in the
325.1372 +     * handle table).
325.1373 +     */
325.1374 +    private Class readClass(boolean unshared) throws IOException {
325.1375 +        if (bin.readByte() != TC_CLASS) {
325.1376 +            throw new InternalError();
325.1377 +        }
325.1378 +        ObjectStreamClass desc = readClassDesc(false);
325.1379 +        Class cl = desc.forClass();
325.1380 +        passHandle = handles.assign(unshared ? unsharedMarker : cl);
325.1381 +
325.1382 +        ClassNotFoundException resolveEx = desc.getResolveException();
325.1383 +        if (resolveEx != null) {
325.1384 +            handles.markException(passHandle, resolveEx);
325.1385 +        }
325.1386 +
325.1387 +        handles.finish(passHandle);
325.1388 +        return cl;
325.1389 +    }
325.1390 +
325.1391 +    /**
325.1392 +     * Reads in and returns (possibly null) class descriptor.  Sets passHandle
325.1393 +     * to class descriptor's assigned handle.  If class descriptor cannot be
325.1394 +     * resolved to a class in the local VM, a ClassNotFoundException is
325.1395 +     * associated with the class descriptor's handle.
325.1396 +     */
325.1397 +    private ObjectStreamClass readClassDesc(boolean unshared)
325.1398 +        throws IOException
325.1399 +    {
325.1400 +        byte tc = bin.peekByte();
325.1401 +        switch (tc) {
325.1402 +            case TC_NULL:
325.1403 +                return (ObjectStreamClass) readNull();
325.1404 +
325.1405 +            case TC_REFERENCE:
325.1406 +                return (ObjectStreamClass) readHandle(unshared);
325.1407 +
325.1408 +            case TC_PROXYCLASSDESC:
325.1409 +                return readProxyDesc(unshared);
325.1410 +
325.1411 +            case TC_CLASSDESC:
325.1412 +                return readNonProxyDesc(unshared);
325.1413 +
325.1414 +            default:
325.1415 +                throw new StreamCorruptedException(
325.1416 +                    String.format("invalid type code: %02X", tc));
325.1417 +        }
325.1418 +    }
325.1419 +
325.1420 +    /**
325.1421 +     * Reads in and returns class descriptor for a dynamic proxy class.  Sets
325.1422 +     * passHandle to proxy class descriptor's assigned handle.  If proxy class
325.1423 +     * descriptor cannot be resolved to a class in the local VM, a
325.1424 +     * ClassNotFoundException is associated with the descriptor's handle.
325.1425 +     */
325.1426 +    private ObjectStreamClass readProxyDesc(boolean unshared)
325.1427 +        throws IOException
325.1428 +    {
325.1429 +        if (bin.readByte() != TC_PROXYCLASSDESC) {
325.1430 +            throw new InternalError();
325.1431 +        }
325.1432 +
325.1433 +        ObjectStreamClass desc = new ObjectStreamClass();
325.1434 +        int descHandle = handles.assign(unshared ? unsharedMarker : desc);
325.1435 +        passHandle = NULL_HANDLE;
325.1436 +
325.1437 +        int numIfaces = bin.readInt();
325.1438 +        String[] ifaces = new String[numIfaces];
325.1439 +        for (int i = 0; i < numIfaces; i++) {
325.1440 +            ifaces[i] = bin.readUTF();
325.1441 +        }
325.1442 +
325.1443 +        Class cl = null;
325.1444 +        ClassNotFoundException resolveEx = null;
325.1445 +        bin.setBlockDataMode(true);
325.1446 +        try {
325.1447 +            if ((cl = resolveProxyClass(ifaces)) == null) {
325.1448 +                resolveEx = new ClassNotFoundException("null class");
325.1449 +            }
325.1450 +        } catch (ClassNotFoundException ex) {
325.1451 +            resolveEx = ex;
325.1452 +        }
325.1453 +        skipCustomData();
325.1454 +
325.1455 +        desc.initProxy(cl, resolveEx, readClassDesc(false));
325.1456 +
325.1457 +        handles.finish(descHandle);
325.1458 +        passHandle = descHandle;
325.1459 +        return desc;
325.1460 +    }
325.1461 +
325.1462 +    /**
325.1463 +     * Reads in and returns class descriptor for a class that is not a dynamic
325.1464 +     * proxy class.  Sets passHandle to class descriptor's assigned handle.  If
325.1465 +     * class descriptor cannot be resolved to a class in the local VM, a
325.1466 +     * ClassNotFoundException is associated with the descriptor's handle.
325.1467 +     */
325.1468 +    private ObjectStreamClass readNonProxyDesc(boolean unshared)
325.1469 +        throws IOException
325.1470 +    {
325.1471 +        if (bin.readByte() != TC_CLASSDESC) {
325.1472 +            throw new InternalError();
325.1473 +        }
325.1474 +
325.1475 +        ObjectStreamClass desc = new ObjectStreamClass();
325.1476 +        int descHandle = handles.assign(unshared ? unsharedMarker : desc);
325.1477 +        passHandle = NULL_HANDLE;
325.1478 +
325.1479 +        ObjectStreamClass readDesc = null;
325.1480 +        try {
325.1481 +            readDesc = readClassDescriptor();
325.1482 +        } catch (ClassNotFoundException ex) {
325.1483 +            throw (IOException) new InvalidClassException(
325.1484 +                "failed to read class descriptor").initCause(ex);
325.1485 +        }
325.1486 +
325.1487 +        Class cl = null;
325.1488 +        ClassNotFoundException resolveEx = null;
325.1489 +        bin.setBlockDataMode(true);
325.1490 +        try {
325.1491 +            if ((cl = resolveClass(readDesc)) == null) {
325.1492 +                resolveEx = new ClassNotFoundException("null class");
325.1493 +            }
325.1494 +        } catch (ClassNotFoundException ex) {
325.1495 +            resolveEx = ex;
325.1496 +        }
325.1497 +        skipCustomData();
325.1498 +
325.1499 +        desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false));
325.1500 +
325.1501 +        handles.finish(descHandle);
325.1502 +        passHandle = descHandle;
325.1503 +        return desc;
325.1504 +    }
325.1505 +
325.1506 +    /**
325.1507 +     * Reads in and returns new string.  Sets passHandle to new string's
325.1508 +     * assigned handle.
325.1509 +     */
325.1510 +    private String readString(boolean unshared) throws IOException {
325.1511 +        String str;
325.1512 +        byte tc = bin.readByte();
325.1513 +        switch (tc) {
325.1514 +            case TC_STRING:
325.1515 +                str = bin.readUTF();
325.1516 +                break;
325.1517 +
325.1518 +            case TC_LONGSTRING:
325.1519 +                str = bin.readLongUTF();
325.1520 +                break;
325.1521 +
325.1522 +            default:
325.1523 +                throw new StreamCorruptedException(
325.1524 +                    String.format("invalid type code: %02X", tc));
325.1525 +        }
325.1526 +        passHandle = handles.assign(unshared ? unsharedMarker : str);
325.1527 +        handles.finish(passHandle);
325.1528 +        return str;
325.1529 +    }
325.1530 +
325.1531 +    /**
325.1532 +     * Reads in and returns array object, or null if array class is
325.1533 +     * unresolvable.  Sets passHandle to array's assigned handle.
325.1534 +     */
325.1535 +    private Object readArray(boolean unshared) throws IOException {
325.1536 +        if (bin.readByte() != TC_ARRAY) {
325.1537 +            throw new InternalError();
325.1538 +        }
325.1539 +
325.1540 +        ObjectStreamClass desc = readClassDesc(false);
325.1541 +        int len = bin.readInt();
325.1542 +
325.1543 +        Object array = null;
325.1544 +        Class cl, ccl = null;
325.1545 +        if ((cl = desc.forClass()) != null) {
325.1546 +            ccl = cl.getComponentType();
325.1547 +            array = Array.newInstance(ccl, len);
325.1548 +        }
325.1549 +
325.1550 +        int arrayHandle = handles.assign(unshared ? unsharedMarker : array);
325.1551 +        ClassNotFoundException resolveEx = desc.getResolveException();
325.1552 +        if (resolveEx != null) {
325.1553 +            handles.markException(arrayHandle, resolveEx);
325.1554 +        }
325.1555 +
325.1556 +        if (ccl == null) {
325.1557 +            for (int i = 0; i < len; i++) {
325.1558 +                readObject0(false);
325.1559 +            }
325.1560 +        } else if (ccl.isPrimitive()) {
325.1561 +            if (ccl == Integer.TYPE) {
325.1562 +                bin.readInts((int[]) array, 0, len);
325.1563 +            } else if (ccl == Byte.TYPE) {
325.1564 +                bin.readFully((byte[]) array, 0, len, true);
325.1565 +            } else if (ccl == Long.TYPE) {
325.1566 +                bin.readLongs((long[]) array, 0, len);
325.1567 +            } else if (ccl == Float.TYPE) {
325.1568 +                bin.readFloats((float[]) array, 0, len);
325.1569 +            } else if (ccl == Double.TYPE) {
325.1570 +                bin.readDoubles((double[]) array, 0, len);
325.1571 +            } else if (ccl == Short.TYPE) {
325.1572 +                bin.readShorts((short[]) array, 0, len);
325.1573 +            } else if (ccl == Character.TYPE) {
325.1574 +                bin.readChars((char[]) array, 0, len);
325.1575 +            } else if (ccl == Boolean.TYPE) {
325.1576 +                bin.readBooleans((boolean[]) array, 0, len);
325.1577 +            } else {
325.1578 +                throw new InternalError();
325.1579 +            }
325.1580 +        } else {
325.1581 +            Object[] oa = (Object[]) array;
325.1582 +            for (int i = 0; i < len; i++) {
325.1583 +                oa[i] = readObject0(false);
325.1584 +                handles.markDependency(arrayHandle, passHandle);
325.1585 +            }
325.1586 +        }
325.1587 +
325.1588 +        handles.finish(arrayHandle);
325.1589 +        passHandle = arrayHandle;
325.1590 +        return array;
325.1591 +    }
325.1592 +
325.1593 +    /**
325.1594 +     * Reads in and returns enum constant, or null if enum type is
325.1595 +     * unresolvable.  Sets passHandle to enum constant's assigned handle.
325.1596 +     */
325.1597 +    private Enum readEnum(boolean unshared) throws IOException {
325.1598 +        if (bin.readByte() != TC_ENUM) {
325.1599 +            throw new InternalError();
325.1600 +        }
325.1601 +
325.1602 +        ObjectStreamClass desc = readClassDesc(false);
325.1603 +        if (!desc.isEnum()) {
325.1604 +            throw new InvalidClassException("non-enum class: " + desc);
325.1605 +        }
325.1606 +
325.1607 +        int enumHandle = handles.assign(unshared ? unsharedMarker : null);
325.1608 +        ClassNotFoundException resolveEx = desc.getResolveException();
325.1609 +        if (resolveEx != null) {
325.1610 +            handles.markException(enumHandle, resolveEx);
325.1611 +        }
325.1612 +
325.1613 +        String name = readString(false);
325.1614 +        Enum en = null;
325.1615 +        Class cl = desc.forClass();
325.1616 +        if (cl != null) {
325.1617 +            try {
325.1618 +                en = Enum.valueOf(cl, name);
325.1619 +            } catch (IllegalArgumentException ex) {
325.1620 +                throw (IOException) new InvalidObjectException(
325.1621 +                    "enum constant " + name + " does not exist in " +
325.1622 +                    cl).initCause(ex);
325.1623 +            }
325.1624 +            if (!unshared) {
325.1625 +                handles.setObject(enumHandle, en);
325.1626 +            }
325.1627 +        }
325.1628 +
325.1629 +        handles.finish(enumHandle);
325.1630 +        passHandle = enumHandle;
325.1631 +        return en;
325.1632 +    }
325.1633 +
325.1634 +    /**
325.1635 +     * Reads and returns "ordinary" (i.e., not a String, Class,
325.1636 +     * ObjectStreamClass, array, or enum constant) object, or null if object's
325.1637 +     * class is unresolvable (in which case a ClassNotFoundException will be
325.1638 +     * associated with object's handle).  Sets passHandle to object's assigned
325.1639 +     * handle.
325.1640 +     */
325.1641 +    private Object readOrdinaryObject(boolean unshared)
325.1642 +        throws IOException
325.1643 +    {
325.1644 +        if (bin.readByte() != TC_OBJECT) {
325.1645 +            throw new InternalError();
325.1646 +        }
325.1647 +
325.1648 +        ObjectStreamClass desc = readClassDesc(false);
325.1649 +        desc.checkDeserialize();
325.1650 +
325.1651 +        Object obj;
325.1652 +        try {
325.1653 +            obj = desc.isInstantiable() ? desc.newInstance() : null;
325.1654 +        } catch (Exception ex) {
325.1655 +            throw (IOException) new InvalidClassException(
325.1656 +                desc.forClass().getName(),
325.1657 +                "unable to create instance").initCause(ex);
325.1658 +        }
325.1659 +
325.1660 +        passHandle = handles.assign(unshared ? unsharedMarker : obj);
325.1661 +        ClassNotFoundException resolveEx = desc.getResolveException();
325.1662 +        if (resolveEx != null) {
325.1663 +            handles.markException(passHandle, resolveEx);
325.1664 +        }
325.1665 +
325.1666 +        if (desc.isExternalizable()) {
325.1667 +            readExternalData((Externalizable) obj, desc);
325.1668 +        } else {
325.1669 +            readSerialData(obj, desc);
325.1670 +        }
325.1671 +
325.1672 +        handles.finish(passHandle);
325.1673 +
325.1674 +        if (obj != null &&
325.1675 +            handles.lookupException(passHandle) == null &&
325.1676 +            desc.hasReadResolveMethod())
325.1677 +        {
325.1678 +            Object rep = desc.invokeReadResolve(obj);
325.1679 +            if (unshared && rep.getClass().isArray()) {
325.1680 +                rep = cloneArray(rep);
325.1681 +            }
325.1682 +            if (rep != obj) {
325.1683 +                handles.setObject(passHandle, obj = rep);
325.1684 +            }
325.1685 +        }
325.1686 +
325.1687 +        return obj;
325.1688 +    }
325.1689 +
325.1690 +    /**
325.1691 +     * If obj is non-null, reads externalizable data by invoking readExternal()
325.1692 +     * method of obj; otherwise, attempts to skip over externalizable data.
325.1693 +     * Expects that passHandle is set to obj's handle before this method is
325.1694 +     * called.
325.1695 +     */
325.1696 +    private void readExternalData(Externalizable obj, ObjectStreamClass desc)
325.1697 +        throws IOException
325.1698 +    {
325.1699 +        Object oldContext = curContext;
325.1700 +        curContext = null;
325.1701 +        try {
325.1702 +            boolean blocked = desc.hasBlockExternalData();
325.1703 +            if (blocked) {
325.1704 +                bin.setBlockDataMode(true);
325.1705 +            }
325.1706 +            if (obj != null) {
325.1707 +                try {
325.1708 +                    obj.readExternal(this);
325.1709 +                } catch (ClassNotFoundException ex) {
325.1710 +                    /*
325.1711 +                     * In most cases, the handle table has already propagated
325.1712 +                     * a CNFException to passHandle at this point; this mark
325.1713 +                     * call is included to address cases where the readExternal
325.1714 +                     * method has cons'ed and thrown a new CNFException of its
325.1715 +                     * own.
325.1716 +                     */
325.1717 +                     handles.markException(passHandle, ex);
325.1718 +                }
325.1719 +            }
325.1720 +            if (blocked) {
325.1721 +                skipCustomData();
325.1722 +            }
325.1723 +        } finally {
325.1724 +            curContext = oldContext;
325.1725 +        }
325.1726 +        /*
325.1727 +         * At this point, if the externalizable data was not written in
325.1728 +         * block-data form and either the externalizable class doesn't exist
325.1729 +         * locally (i.e., obj == null) or readExternal() just threw a
325.1730 +         * CNFException, then the stream is probably in an inconsistent state,
325.1731 +         * since some (or all) of the externalizable data may not have been
325.1732 +         * consumed.  Since there's no "correct" action to take in this case,
325.1733 +         * we mimic the behavior of past serialization implementations and
325.1734 +         * blindly hope that the stream is in sync; if it isn't and additional
325.1735 +         * externalizable data remains in the stream, a subsequent read will
325.1736 +         * most likely throw a StreamCorruptedException.
325.1737 +         */
325.1738 +    }
325.1739 +
325.1740 +    /**
325.1741 +     * Reads (or attempts to skip, if obj is null or is tagged with a
325.1742 +     * ClassNotFoundException) instance data for each serializable class of
325.1743 +     * object in stream, from superclass to subclass.  Expects that passHandle
325.1744 +     * is set to obj's handle before this method is called.
325.1745 +     */
325.1746 +    private void readSerialData(Object obj, ObjectStreamClass desc)
325.1747 +        throws IOException
325.1748 +    {
325.1749 +        ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
325.1750 +        for (int i = 0; i < slots.length; i++) {
325.1751 +            ObjectStreamClass slotDesc = slots[i].desc;
325.1752 +
325.1753 +            if (slots[i].hasData) {
325.1754 +                if (obj != null &&
325.1755 +                    slotDesc.hasReadObjectMethod() &&
325.1756 +                    handles.lookupException(passHandle) == null)
325.1757 +                {
325.1758 +                    Object oldContext = curContext;
325.1759 +
325.1760 +                    try {
325.1761 +                        curContext = null; //new SerialCallbackContext(obj, slotDesc);
325.1762 +
325.1763 +                        bin.setBlockDataMode(true);
325.1764 +                        slotDesc.invokeReadObject(obj, this);
325.1765 +                    } catch (ClassNotFoundException ex) {
325.1766 +                        /*
325.1767 +                         * In most cases, the handle table has already
325.1768 +                         * propagated a CNFException to passHandle at this
325.1769 +                         * point; this mark call is included to address cases
325.1770 +                         * where the custom readObject method has cons'ed and
325.1771 +                         * thrown a new CNFException of its own.
325.1772 +                         */
325.1773 +                        handles.markException(passHandle, ex);
325.1774 +                    } finally {
325.1775 +                        //curContext.setUsed();
325.1776 +                        curContext = oldContext;
325.1777 +                    }
325.1778 +
325.1779 +                    /*
325.1780 +                     * defaultDataEnd may have been set indirectly by custom
325.1781 +                     * readObject() method when calling defaultReadObject() or
325.1782 +                     * readFields(); clear it to restore normal read behavior.
325.1783 +                     */
325.1784 +                    defaultDataEnd = false;
325.1785 +                } else {
325.1786 +                    defaultReadFields(obj, slotDesc);
325.1787 +                }
325.1788 +                if (slotDesc.hasWriteObjectData()) {
325.1789 +                    skipCustomData();
325.1790 +                } else {
325.1791 +                    bin.setBlockDataMode(false);
325.1792 +                }
325.1793 +            } else {
325.1794 +                if (obj != null &&
325.1795 +                    slotDesc.hasReadObjectNoDataMethod() &&
325.1796 +                    handles.lookupException(passHandle) == null)
325.1797 +                {
325.1798 +                    slotDesc.invokeReadObjectNoData(obj);
325.1799 +                }
325.1800 +            }
325.1801 +        }
325.1802 +    }
325.1803 +
325.1804 +    /**
325.1805 +     * Skips over all block data and objects until TC_ENDBLOCKDATA is
325.1806 +     * encountered.
325.1807 +     */
325.1808 +    private void skipCustomData() throws IOException {
325.1809 +        int oldHandle = passHandle;
325.1810 +        for (;;) {
325.1811 +            if (bin.getBlockDataMode()) {
325.1812 +                bin.skipBlockData();
325.1813 +                bin.setBlockDataMode(false);
325.1814 +            }
325.1815 +            switch (bin.peekByte()) {
325.1816 +                case TC_BLOCKDATA:
325.1817 +                case TC_BLOCKDATALONG:
325.1818 +                    bin.setBlockDataMode(true);
325.1819 +                    break;
325.1820 +
325.1821 +                case TC_ENDBLOCKDATA:
325.1822 +                    bin.readByte();
325.1823 +                    passHandle = oldHandle;
325.1824 +                    return;
325.1825 +
325.1826 +                default:
325.1827 +                    readObject0(false);
325.1828 +                    break;
325.1829 +            }
325.1830 +        }
325.1831 +    }
325.1832 +
325.1833 +    /**
325.1834 +     * Reads in values of serializable fields declared by given class
325.1835 +     * descriptor.  If obj is non-null, sets field values in obj.  Expects that
325.1836 +     * passHandle is set to obj's handle before this method is called.
325.1837 +     */
325.1838 +    private void defaultReadFields(Object obj, ObjectStreamClass desc)
325.1839 +        throws IOException
325.1840 +    {
325.1841 +        // REMIND: is isInstance check necessary?
325.1842 +        Class cl = desc.forClass();
325.1843 +        if (cl != null && obj != null && !cl.isInstance(obj)) {
325.1844 +            throw new ClassCastException();
325.1845 +        }
325.1846 +
325.1847 +        int primDataSize = desc.getPrimDataSize();
325.1848 +        if (primVals == null || primVals.length < primDataSize) {
325.1849 +            primVals = new byte[primDataSize];
325.1850 +        }
325.1851 +        bin.readFully(primVals, 0, primDataSize, false);
325.1852 +        if (obj != null) {
325.1853 +            desc.setPrimFieldValues(obj, primVals);
325.1854 +        }
325.1855 +
325.1856 +        int objHandle = passHandle;
325.1857 +        ObjectStreamField[] fields = desc.getFields(false);
325.1858 +        Object[] objVals = new Object[desc.getNumObjFields()];
325.1859 +        int numPrimFields = fields.length - objVals.length;
325.1860 +        for (int i = 0; i < objVals.length; i++) {
325.1861 +            ObjectStreamField f = fields[numPrimFields + i];
325.1862 +            objVals[i] = readObject0(f.isUnshared());
325.1863 +            if (f.getField() != null) {
325.1864 +                handles.markDependency(objHandle, passHandle);
325.1865 +            }
325.1866 +        }
325.1867 +        if (obj != null) {
325.1868 +            desc.setObjFieldValues(obj, objVals);
325.1869 +        }
325.1870 +        passHandle = objHandle;
325.1871 +    }
325.1872 +
325.1873 +    /**
325.1874 +     * Reads in and returns IOException that caused serialization to abort.
325.1875 +     * All stream state is discarded prior to reading in fatal exception.  Sets
325.1876 +     * passHandle to fatal exception's handle.
325.1877 +     */
325.1878 +    private IOException readFatalException() throws IOException {
325.1879 +        if (bin.readByte() != TC_EXCEPTION) {
325.1880 +            throw new InternalError();
325.1881 +        }
325.1882 +        clear();
325.1883 +        return (IOException) readObject0(false);
325.1884 +    }
325.1885 +
325.1886 +    /**
325.1887 +     * If recursion depth is 0, clears internal data structures; otherwise,
325.1888 +     * throws a StreamCorruptedException.  This method is called when a
325.1889 +     * TC_RESET typecode is encountered.
325.1890 +     */
325.1891 +    private void handleReset() throws StreamCorruptedException {
325.1892 +        if (depth > 0) {
325.1893 +            throw new StreamCorruptedException(
325.1894 +                "unexpected reset; recursion depth: " + depth);
325.1895 +        }
325.1896 +        clear();
325.1897 +    }
325.1898 +
325.1899 +    /**
325.1900 +     * Converts specified span of bytes into float values.
325.1901 +     */
325.1902 +    // REMIND: remove once hotspot inlines Float.intBitsToFloat
325.1903 +    private static native void bytesToFloats(byte[] src, int srcpos,
325.1904 +                                             float[] dst, int dstpos,
325.1905 +                                             int nfloats);
325.1906 +
325.1907 +    /**
325.1908 +     * Converts specified span of bytes into double values.
325.1909 +     */
325.1910 +    // REMIND: remove once hotspot inlines Double.longBitsToDouble
325.1911 +    private static native void bytesToDoubles(byte[] src, int srcpos,
325.1912 +                                              double[] dst, int dstpos,
325.1913 +                                              int ndoubles);
325.1914 +
325.1915 +    /**
325.1916 +     * Returns the first non-null class loader (not counting class loaders of
325.1917 +     * generated reflection implementation classes) up the execution stack, or
325.1918 +     * null if only code from the null class loader is on the stack.  This
325.1919 +     * method is also called via reflection by the following RMI-IIOP class:
325.1920 +     *
325.1921 +     *     com.sun.corba.se.internal.util.JDKClassLoader
325.1922 +     *
325.1923 +     * This method should not be removed or its signature changed without
325.1924 +     * corresponding modifications to the above class.
325.1925 +     */
325.1926 +    // REMIND: change name to something more accurate?
325.1927 +    private static native ClassLoader latestUserDefinedLoader();
325.1928 +
325.1929 +    /**
325.1930 +     * Default GetField implementation.
325.1931 +     */
325.1932 +    private class GetFieldImpl extends GetField {
325.1933 +
325.1934 +        /** class descriptor describing serializable fields */
325.1935 +        private final ObjectStreamClass desc;
325.1936 +        /** primitive field values */
325.1937 +        private final byte[] primVals;
325.1938 +        /** object field values */
325.1939 +        private final Object[] objVals;
325.1940 +        /** object field value handles */
325.1941 +        private final int[] objHandles;
325.1942 +
325.1943 +        /**
325.1944 +         * Creates GetFieldImpl object for reading fields defined in given
325.1945 +         * class descriptor.
325.1946 +         */
325.1947 +        GetFieldImpl(ObjectStreamClass desc) {
325.1948 +            this.desc = desc;
325.1949 +            primVals = new byte[desc.getPrimDataSize()];
325.1950 +            objVals = new Object[desc.getNumObjFields()];
325.1951 +            objHandles = new int[objVals.length];
325.1952 +        }
325.1953 +
325.1954 +        public ObjectStreamClass getObjectStreamClass() {
325.1955 +            return desc;
325.1956 +        }
325.1957 +
325.1958 +        public boolean defaulted(String name) throws IOException {
325.1959 +            return (getFieldOffset(name, null) < 0);
325.1960 +        }
325.1961 +
325.1962 +        public boolean get(String name, boolean val) throws IOException {
325.1963 +            int off = getFieldOffset(name, Boolean.TYPE);
325.1964 +            return (off >= 0) ? Bits.getBoolean(primVals, off) : val;
325.1965 +        }
325.1966 +
325.1967 +        public byte get(String name, byte val) throws IOException {
325.1968 +            int off = getFieldOffset(name, Byte.TYPE);
325.1969 +            return (off >= 0) ? primVals[off] : val;
325.1970 +        }
325.1971 +
325.1972 +        public char get(String name, char val) throws IOException {
325.1973 +            int off = getFieldOffset(name, Character.TYPE);
325.1974 +            return (off >= 0) ? Bits.getChar(primVals, off) : val;
325.1975 +        }
325.1976 +
325.1977 +        public short get(String name, short val) throws IOException {
325.1978 +            int off = getFieldOffset(name, Short.TYPE);
325.1979 +            return (off >= 0) ? Bits.getShort(primVals, off) : val;
325.1980 +        }
325.1981 +
325.1982 +        public int get(String name, int val) throws IOException {
325.1983 +            int off = getFieldOffset(name, Integer.TYPE);
325.1984 +            return (off >= 0) ? Bits.getInt(primVals, off) : val;
325.1985 +        }
325.1986 +
325.1987 +        public float get(String name, float val) throws IOException {
325.1988 +            int off = getFieldOffset(name, Float.TYPE);
325.1989 +            return (off >= 0) ? Bits.getFloat(primVals, off) : val;
325.1990 +        }
325.1991 +
325.1992 +        public long get(String name, long val) throws IOException {
325.1993 +            int off = getFieldOffset(name, Long.TYPE);
325.1994 +            return (off >= 0) ? Bits.getLong(primVals, off) : val;
325.1995 +        }
325.1996 +
325.1997 +        public double get(String name, double val) throws IOException {
325.1998 +            int off = getFieldOffset(name, Double.TYPE);
325.1999 +            return (off >= 0) ? Bits.getDouble(primVals, off) : val;
325.2000 +        }
325.2001 +
325.2002 +        public Object get(String name, Object val) throws IOException {
325.2003 +            int off = getFieldOffset(name, Object.class);
325.2004 +            if (off >= 0) {
325.2005 +                int objHandle = objHandles[off];
325.2006 +                handles.markDependency(passHandle, objHandle);
325.2007 +                return (handles.lookupException(objHandle) == null) ?
325.2008 +                    objVals[off] : null;
325.2009 +            } else {
325.2010 +                return val;
325.2011 +            }
325.2012 +        }
325.2013 +
325.2014 +        /**
325.2015 +         * Reads primitive and object field values from stream.
325.2016 +         */
325.2017 +        void readFields() throws IOException {
325.2018 +            bin.readFully(primVals, 0, primVals.length, false);
325.2019 +
325.2020 +            int oldHandle = passHandle;
325.2021 +            ObjectStreamField[] fields = desc.getFields(false);
325.2022 +            int numPrimFields = fields.length - objVals.length;
325.2023 +            for (int i = 0; i < objVals.length; i++) {
325.2024 +                objVals[i] =
325.2025 +                    readObject0(fields[numPrimFields + i].isUnshared());
325.2026 +                objHandles[i] = passHandle;
325.2027 +            }
325.2028 +            passHandle = oldHandle;
325.2029 +        }
325.2030 +
325.2031 +        /**
325.2032 +         * Returns offset of field with given name and type.  A specified type
325.2033 +         * of null matches all types, Object.class matches all non-primitive
325.2034 +         * types, and any other non-null type matches assignable types only.
325.2035 +         * If no matching field is found in the (incoming) class
325.2036 +         * descriptor but a matching field is present in the associated local
325.2037 +         * class descriptor, returns -1.  Throws IllegalArgumentException if
325.2038 +         * neither incoming nor local class descriptor contains a match.
325.2039 +         */
325.2040 +        private int getFieldOffset(String name, Class type) {
325.2041 +            ObjectStreamField field = desc.getField(name, type);
325.2042 +            if (field != null) {
325.2043 +                return field.getOffset();
325.2044 +            } else if (desc.getLocalDesc().getField(name, type) != null) {
325.2045 +                return -1;
325.2046 +            } else {
325.2047 +                throw new IllegalArgumentException("no such field " + name +
325.2048 +                                                   " with type " + type);
325.2049 +            }
325.2050 +        }
325.2051 +    }
325.2052 +
325.2053 +    /**
325.2054 +     * Prioritized list of callbacks to be performed once object graph has been
325.2055 +     * completely deserialized.
325.2056 +     */
325.2057 +    private static class ValidationList {
325.2058 +
325.2059 +
325.2060 +        /**
325.2061 +         * Creates new (empty) ValidationList.
325.2062 +         */
325.2063 +        ValidationList() {
325.2064 +        }
325.2065 +
325.2066 +        /**
325.2067 +         * Registers callback.  Throws InvalidObjectException if callback
325.2068 +         * object is null.
325.2069 +         */
325.2070 +        void register(ObjectInputValidation obj, int priority)
325.2071 +            throws InvalidObjectException
325.2072 +        {
325.2073 +            if (obj == null) {
325.2074 +                throw new InvalidObjectException("null callback");
325.2075 +            }
325.2076 +            throw new InvalidObjectException("Does not work.");
325.2077 +        }
325.2078 +
325.2079 +        /**
325.2080 +         * Invokes all registered callbacks and clears the callback list.
325.2081 +         * Callbacks with higher priorities are called first; those with equal
325.2082 +         * priorities may be called in any order.  If any of the callbacks
325.2083 +         * throws an InvalidObjectException, the callback process is terminated
325.2084 +         * and the exception propagated upwards.
325.2085 +         */
325.2086 +        void doCallbacks() throws InvalidObjectException {
325.2087 +        }
325.2088 +
325.2089 +        /**
325.2090 +         * Resets the callback list to its initial (empty) state.
325.2091 +         */
325.2092 +        public void clear() {
325.2093 +        }
325.2094 +    }
325.2095 +
325.2096 +    /**
325.2097 +     * Input stream supporting single-byte peek operations.
325.2098 +     */
325.2099 +    private static class PeekInputStream extends InputStream {
325.2100 +
325.2101 +        /** underlying stream */
325.2102 +        private final InputStream in;
325.2103 +        /** peeked byte */
325.2104 +        private int peekb = -1;
325.2105 +
325.2106 +        /**
325.2107 +         * Creates new PeekInputStream on top of given underlying stream.
325.2108 +         */
325.2109 +        PeekInputStream(InputStream in) {
325.2110 +            this.in = in;
325.2111 +        }
325.2112 +
325.2113 +        /**
325.2114 +         * Peeks at next byte value in stream.  Similar to read(), except
325.2115 +         * that it does not consume the read value.
325.2116 +         */
325.2117 +        int peek() throws IOException {
325.2118 +            return (peekb >= 0) ? peekb : (peekb = in.read());
325.2119 +        }
325.2120 +
325.2121 +        public int read() throws IOException {
325.2122 +            if (peekb >= 0) {
325.2123 +                int v = peekb;
325.2124 +                peekb = -1;
325.2125 +                return v;
325.2126 +            } else {
325.2127 +                return in.read();
325.2128 +            }
325.2129 +        }
325.2130 +
325.2131 +        public int read(byte[] b, int off, int len) throws IOException {
325.2132 +            if (len == 0) {
325.2133 +                return 0;
325.2134 +            } else if (peekb < 0) {
325.2135 +                return in.read(b, off, len);
325.2136 +            } else {
325.2137 +                b[off++] = (byte) peekb;
325.2138 +                len--;
325.2139 +                peekb = -1;
325.2140 +                int n = in.read(b, off, len);
325.2141 +                return (n >= 0) ? (n + 1) : 1;
325.2142 +            }
325.2143 +        }
325.2144 +
325.2145 +        void readFully(byte[] b, int off, int len) throws IOException {
325.2146 +            int n = 0;
325.2147 +            while (n < len) {
325.2148 +                int count = read(b, off + n, len - n);
325.2149 +                if (count < 0) {
325.2150 +                    throw new EOFException();
325.2151 +                }
325.2152 +                n += count;
325.2153 +            }
325.2154 +        }
325.2155 +
325.2156 +        public long skip(long n) throws IOException {
325.2157 +            if (n <= 0) {
325.2158 +                return 0;
325.2159 +            }
325.2160 +            int skipped = 0;
325.2161 +            if (peekb >= 0) {
325.2162 +                peekb = -1;
325.2163 +                skipped++;
325.2164 +                n--;
325.2165 +            }
325.2166 +            return skipped + skip(n);
325.2167 +        }
325.2168 +
325.2169 +        public int available() throws IOException {
325.2170 +            return in.available() + ((peekb >= 0) ? 1 : 0);
325.2171 +        }
325.2172 +
325.2173 +        public void close() throws IOException {
325.2174 +            in.close();
325.2175 +        }
325.2176 +    }
325.2177 +
325.2178 +    /**
325.2179 +     * Input stream with two modes: in default mode, inputs data written in the
325.2180 +     * same format as DataOutputStream; in "block data" mode, inputs data
325.2181 +     * bracketed by block data markers (see object serialization specification
325.2182 +     * for details).  Buffering depends on block data mode: when in default
325.2183 +     * mode, no data is buffered in advance; when in block data mode, all data
325.2184 +     * for the current data block is read in at once (and buffered).
325.2185 +     */
325.2186 +    private class BlockDataInputStream
325.2187 +        extends InputStream implements DataInput
325.2188 +    {
325.2189 +        /** maximum data block length */
325.2190 +        private static final int MAX_BLOCK_SIZE = 1024;
325.2191 +        /** maximum data block header length */
325.2192 +        private static final int MAX_HEADER_SIZE = 5;
325.2193 +        /** (tunable) length of char buffer (for reading strings) */
325.2194 +        private static final int CHAR_BUF_SIZE = 256;
325.2195 +        /** readBlockHeader() return value indicating header read may block */
325.2196 +        private static final int HEADER_BLOCKED = -2;
325.2197 +
325.2198 +        /** buffer for reading general/block data */
325.2199 +        private final byte[] buf = new byte[MAX_BLOCK_SIZE];
325.2200 +        /** buffer for reading block data headers */
325.2201 +        private final byte[] hbuf = new byte[MAX_HEADER_SIZE];
325.2202 +        /** char buffer for fast string reads */
325.2203 +        private final char[] cbuf = new char[CHAR_BUF_SIZE];
325.2204 +
325.2205 +        /** block data mode */
325.2206 +        private boolean blkmode = false;
325.2207 +
325.2208 +        // block data state fields; values meaningful only when blkmode true
325.2209 +        /** current offset into buf */
325.2210 +        private int pos = 0;
325.2211 +        /** end offset of valid data in buf, or -1 if no more block data */
325.2212 +        private int end = -1;
325.2213 +        /** number of bytes in current block yet to be read from stream */
325.2214 +        private int unread = 0;
325.2215 +
325.2216 +        /** underlying stream (wrapped in peekable filter stream) */
325.2217 +        private final PeekInputStream in;
325.2218 +        /** loopback stream (for data reads that span data blocks) */
325.2219 +        private final DataInputStream din;
325.2220 +
325.2221 +        /**
325.2222 +         * Creates new BlockDataInputStream on top of given underlying stream.
325.2223 +         * Block data mode is turned off by default.
325.2224 +         */
325.2225 +        BlockDataInputStream(InputStream in) {
325.2226 +            this.in = new PeekInputStream(in);
325.2227 +            din = new DataInputStream(this);
325.2228 +        }
325.2229 +
325.2230 +        /**
325.2231 +         * Sets block data mode to the given mode (true == on, false == off)
325.2232 +         * and returns the previous mode value.  If the new mode is the same as
325.2233 +         * the old mode, no action is taken.  Throws IllegalStateException if
325.2234 +         * block data mode is being switched from on to off while unconsumed
325.2235 +         * block data is still present in the stream.
325.2236 +         */
325.2237 +        boolean setBlockDataMode(boolean newmode) throws IOException {
325.2238 +            if (blkmode == newmode) {
325.2239 +                return blkmode;
325.2240 +            }
325.2241 +            if (newmode) {
325.2242 +                pos = 0;
325.2243 +                end = 0;
325.2244 +                unread = 0;
325.2245 +            } else if (pos < end) {
325.2246 +                throw new IllegalStateException("unread block data");
325.2247 +            }
325.2248 +            blkmode = newmode;
325.2249 +            return !blkmode;
325.2250 +        }
325.2251 +
325.2252 +        /**
325.2253 +         * Returns true if the stream is currently in block data mode, false
325.2254 +         * otherwise.
325.2255 +         */
325.2256 +        boolean getBlockDataMode() {
325.2257 +            return blkmode;
325.2258 +        }
325.2259 +
325.2260 +        /**
325.2261 +         * If in block data mode, skips to the end of the current group of data
325.2262 +         * blocks (but does not unset block data mode).  If not in block data
325.2263 +         * mode, throws an IllegalStateException.
325.2264 +         */
325.2265 +        void skipBlockData() throws IOException {
325.2266 +            if (!blkmode) {
325.2267 +                throw new IllegalStateException("not in block data mode");
325.2268 +            }
325.2269 +            while (end >= 0) {
325.2270 +                refill();
325.2271 +            }
325.2272 +        }
325.2273 +
325.2274 +        /**
325.2275 +         * Attempts to read in the next block data header (if any).  If
325.2276 +         * canBlock is false and a full header cannot be read without possibly
325.2277 +         * blocking, returns HEADER_BLOCKED, else if the next element in the
325.2278 +         * stream is a block data header, returns the block data length
325.2279 +         * specified by the header, else returns -1.
325.2280 +         */
325.2281 +        private int readBlockHeader(boolean canBlock) throws IOException {
325.2282 +            if (defaultDataEnd) {
325.2283 +                /*
325.2284 +                 * Fix for 4360508: stream is currently at the end of a field
325.2285 +                 * value block written via default serialization; since there
325.2286 +                 * is no terminating TC_ENDBLOCKDATA tag, simulate
325.2287 +                 * end-of-custom-data behavior explicitly.
325.2288 +                 */
325.2289 +                return -1;
325.2290 +            }
325.2291 +            try {
325.2292 +                for (;;) {
325.2293 +                    int avail = canBlock ? Integer.MAX_VALUE : in.available();
325.2294 +                    if (avail == 0) {
325.2295 +                        return HEADER_BLOCKED;
325.2296 +                    }
325.2297 +
325.2298 +                    int tc = in.peek();
325.2299 +                    switch (tc) {
325.2300 +                        case TC_BLOCKDATA:
325.2301 +                            if (avail < 2) {
325.2302 +                                return HEADER_BLOCKED;
325.2303 +                            }
325.2304 +                            in.readFully(hbuf, 0, 2);
325.2305 +                            return hbuf[1] & 0xFF;
325.2306 +
325.2307 +                        case TC_BLOCKDATALONG:
325.2308 +                            if (avail < 5) {
325.2309 +                                return HEADER_BLOCKED;
325.2310 +                            }
325.2311 +                            in.readFully(hbuf, 0, 5);
325.2312 +                            int len = Bits.getInt(hbuf, 1);
325.2313 +                            if (len < 0) {
325.2314 +                                throw new StreamCorruptedException(
325.2315 +                                    "illegal block data header length: " +
325.2316 +                                    len);
325.2317 +                            }
325.2318 +                            return len;
325.2319 +
325.2320 +                        /*
325.2321 +                         * TC_RESETs may occur in between data blocks.
325.2322 +                         * Unfortunately, this case must be parsed at a lower
325.2323 +                         * level than other typecodes, since primitive data
325.2324 +                         * reads may span data blocks separated by a TC_RESET.
325.2325 +                         */
325.2326 +                        case TC_RESET:
325.2327 +                            in.read();
325.2328 +                            handleReset();
325.2329 +                            break;
325.2330 +
325.2331 +                        default:
325.2332 +                            if (tc >= 0 && (tc < TC_BASE || tc > TC_MAX)) {
325.2333 +                                throw new StreamCorruptedException(
325.2334 +                                    String.format("invalid type code: %02X",
325.2335 +                                    tc));
325.2336 +                            }
325.2337 +                            return -1;
325.2338 +                    }
325.2339 +                }
325.2340 +            } catch (EOFException ex) {
325.2341 +                throw new StreamCorruptedException(
325.2342 +                    "unexpected EOF while reading block data header");
325.2343 +            }
325.2344 +        }
325.2345 +
325.2346 +        /**
325.2347 +         * Refills internal buffer buf with block data.  Any data in buf at the
325.2348 +         * time of the call is considered consumed.  Sets the pos, end, and
325.2349 +         * unread fields to reflect the new amount of available block data; if
325.2350 +         * the next element in the stream is not a data block, sets pos and
325.2351 +         * unread to 0 and end to -1.
325.2352 +         */
325.2353 +        private void refill() throws IOException {
325.2354 +            try {
325.2355 +                do {
325.2356 +                    pos = 0;
325.2357 +                    if (unread > 0) {
325.2358 +                        int n =
325.2359 +                            in.read(buf, 0, Math.min(unread, MAX_BLOCK_SIZE));
325.2360 +                        if (n >= 0) {
325.2361 +                            end = n;
325.2362 +                            unread -= n;
325.2363 +                        } else {
325.2364 +                            throw new StreamCorruptedException(
325.2365 +                                "unexpected EOF in middle of data block");
325.2366 +                        }
325.2367 +                    } else {
325.2368 +                        int n = readBlockHeader(true);
325.2369 +                        if (n >= 0) {
325.2370 +                            end = 0;
325.2371 +                            unread = n;
325.2372 +                        } else {
325.2373 +                            end = -1;
325.2374 +                            unread = 0;
325.2375 +                        }
325.2376 +                    }
325.2377 +                } while (pos == end);
325.2378 +            } catch (IOException ex) {
325.2379 +                pos = 0;
325.2380 +                end = -1;
325.2381 +                unread = 0;
325.2382 +                throw ex;
325.2383 +            }
325.2384 +        }
325.2385 +
325.2386 +        /**
325.2387 +         * If in block data mode, returns the number of unconsumed bytes
325.2388 +         * remaining in the current data block.  If not in block data mode,
325.2389 +         * throws an IllegalStateException.
325.2390 +         */
325.2391 +        int currentBlockRemaining() {
325.2392 +            if (blkmode) {
325.2393 +                return (end >= 0) ? (end - pos) + unread : 0;
325.2394 +            } else {
325.2395 +                throw new IllegalStateException();
325.2396 +            }
325.2397 +        }
325.2398 +
325.2399 +        /**
325.2400 +         * Peeks at (but does not consume) and returns the next byte value in
325.2401 +         * the stream, or -1 if the end of the stream/block data (if in block
325.2402 +         * data mode) has been reached.
325.2403 +         */
325.2404 +        int peek() throws IOException {
325.2405 +            if (blkmode) {
325.2406 +                if (pos == end) {
325.2407 +                    refill();
325.2408 +                }
325.2409 +                return (end >= 0) ? (buf[pos] & 0xFF) : -1;
325.2410 +            } else {
325.2411 +                return in.peek();
325.2412 +            }
325.2413 +        }
325.2414 +
325.2415 +        /**
325.2416 +         * Peeks at (but does not consume) and returns the next byte value in
325.2417 +         * the stream, or throws EOFException if end of stream/block data has
325.2418 +         * been reached.
325.2419 +         */
325.2420 +        byte peekByte() throws IOException {
325.2421 +            int val = peek();
325.2422 +            if (val < 0) {
325.2423 +                throw new EOFException();
325.2424 +            }
325.2425 +            return (byte) val;
325.2426 +        }
325.2427 +
325.2428 +
325.2429 +        /* ----------------- generic input stream methods ------------------ */
325.2430 +        /*
325.2431 +         * The following methods are equivalent to their counterparts in
325.2432 +         * InputStream, except that they interpret data block boundaries and
325.2433 +         * read the requested data from within data blocks when in block data
325.2434 +         * mode.
325.2435 +         */
325.2436 +
325.2437 +        public int read() throws IOException {
325.2438 +            if (blkmode) {
325.2439 +                if (pos == end) {
325.2440 +                    refill();
325.2441 +                }
325.2442 +                return (end >= 0) ? (buf[pos++] & 0xFF) : -1;
325.2443 +            } else {
325.2444 +                return in.read();
325.2445 +            }
325.2446 +        }
325.2447 +
325.2448 +        public int read(byte[] b, int off, int len) throws IOException {
325.2449 +            return read(b, off, len, false);
325.2450 +        }
325.2451 +
325.2452 +        public long skip(long len) throws IOException {
325.2453 +            long remain = len;
325.2454 +            while (remain > 0) {
325.2455 +                if (blkmode) {
325.2456 +                    if (pos == end) {
325.2457 +                        refill();
325.2458 +                    }
325.2459 +                    if (end < 0) {
325.2460 +                        break;
325.2461 +                    }
325.2462 +                    int nread = (int) Math.min(remain, end - pos);
325.2463 +                    remain -= nread;
325.2464 +                    pos += nread;
325.2465 +                } else {
325.2466 +                    int nread = (int) Math.min(remain, MAX_BLOCK_SIZE);
325.2467 +                    if ((nread = in.read(buf, 0, nread)) < 0) {
325.2468 +                        break;
325.2469 +                    }
325.2470 +                    remain -= nread;
325.2471 +                }
325.2472 +            }
325.2473 +            return len - remain;
325.2474 +        }
325.2475 +
325.2476 +        public int available() throws IOException {
325.2477 +            if (blkmode) {
325.2478 +                if ((pos == end) && (unread == 0)) {
325.2479 +                    int n;
325.2480 +                    while ((n = readBlockHeader(false)) == 0) ;
325.2481 +                    switch (n) {
325.2482 +                        case HEADER_BLOCKED:
325.2483 +                            break;
325.2484 +
325.2485 +                        case -1:
325.2486 +                            pos = 0;
325.2487 +                            end = -1;
325.2488 +                            break;
325.2489 +
325.2490 +                        default:
325.2491 +                            pos = 0;
325.2492 +                            end = 0;
325.2493 +                            unread = n;
325.2494 +                            break;
325.2495 +                    }
325.2496 +                }
325.2497 +                // avoid unnecessary call to in.available() if possible
325.2498 +                int unreadAvail = (unread > 0) ?
325.2499 +                    Math.min(in.available(), unread) : 0;
325.2500 +                return (end >= 0) ? (end - pos) + unreadAvail : 0;
325.2501 +            } else {
325.2502 +                return in.available();
325.2503 +            }
325.2504 +        }
325.2505 +
325.2506 +        public void close() throws IOException {
325.2507 +            if (blkmode) {
325.2508 +                pos = 0;
325.2509 +                end = -1;
325.2510 +                unread = 0;
325.2511 +            }
325.2512 +            in.close();
325.2513 +        }
325.2514 +
325.2515 +        /**
325.2516 +         * Attempts to read len bytes into byte array b at offset off.  Returns
325.2517 +         * the number of bytes read, or -1 if the end of stream/block data has
325.2518 +         * been reached.  If copy is true, reads values into an intermediate
325.2519 +         * buffer before copying them to b (to avoid exposing a reference to
325.2520 +         * b).
325.2521 +         */
325.2522 +        int read(byte[] b, int off, int len, boolean copy) throws IOException {
325.2523 +            if (len == 0) {
325.2524 +                return 0;
325.2525 +            } else if (blkmode) {
325.2526 +                if (pos == end) {
325.2527 +                    refill();
325.2528 +                }
325.2529 +                if (end < 0) {
325.2530 +                    return -1;
325.2531 +                }
325.2532 +                int nread = Math.min(len, end - pos);
325.2533 +                System.arraycopy(buf, pos, b, off, nread);
325.2534 +                pos += nread;
325.2535 +                return nread;
325.2536 +            } else if (copy) {
325.2537 +                int nread = in.read(buf, 0, Math.min(len, MAX_BLOCK_SIZE));
325.2538 +                if (nread > 0) {
325.2539 +                    System.arraycopy(buf, 0, b, off, nread);
325.2540 +                }
325.2541 +                return nread;
325.2542 +            } else {
325.2543 +                return in.read(b, off, len);
325.2544 +            }
325.2545 +        }
325.2546 +
325.2547 +        /* ----------------- primitive data input methods ------------------ */
325.2548 +        /*
325.2549 +         * The following methods are equivalent to their counterparts in
325.2550 +         * DataInputStream, except that they interpret data block boundaries
325.2551 +         * and read the requested data from within data blocks when in block
325.2552 +         * data mode.
325.2553 +         */
325.2554 +
325.2555 +        public void readFully(byte[] b) throws IOException {
325.2556 +            readFully(b, 0, b.length, false);
325.2557 +        }
325.2558 +
325.2559 +        public void readFully(byte[] b, int off, int len) throws IOException {
325.2560 +            readFully(b, off, len, false);
325.2561 +        }
325.2562 +
325.2563 +        public void readFully(byte[] b, int off, int len, boolean copy)
325.2564 +            throws IOException
325.2565 +        {
325.2566 +            while (len > 0) {
325.2567 +                int n = read(b, off, len, copy);
325.2568 +                if (n < 0) {
325.2569 +                    throw new EOFException();
325.2570 +                }
325.2571 +                off += n;
325.2572 +                len -= n;
325.2573 +            }
325.2574 +        }
325.2575 +
325.2576 +        public int skipBytes(int n) throws IOException {
325.2577 +            return din.skipBytes(n);
325.2578 +        }
325.2579 +
325.2580 +        public boolean readBoolean() throws IOException {
325.2581 +            int v = read();
325.2582 +            if (v < 0) {
325.2583 +                throw new EOFException();
325.2584 +            }
325.2585 +            return (v != 0);
325.2586 +        }
325.2587 +
325.2588 +        public byte readByte() throws IOException {
325.2589 +            int v = read();
325.2590 +            if (v < 0) {
325.2591 +                throw new EOFException();
325.2592 +            }
325.2593 +            return (byte) v;
325.2594 +        }
325.2595 +
325.2596 +        public int readUnsignedByte() throws IOException {
325.2597 +            int v = read();
325.2598 +            if (v < 0) {
325.2599 +                throw new EOFException();
325.2600 +            }
325.2601 +            return v;
325.2602 +        }
325.2603 +
325.2604 +        public char readChar() throws IOException {
325.2605 +            if (!blkmode) {
325.2606 +                pos = 0;
325.2607 +                in.readFully(buf, 0, 2);
325.2608 +            } else if (end - pos < 2) {
325.2609 +                return din.readChar();
325.2610 +            }
325.2611 +            char v = Bits.getChar(buf, pos);
325.2612 +            pos += 2;
325.2613 +            return v;
325.2614 +        }
325.2615 +
325.2616 +        public short readShort() throws IOException {
325.2617 +            if (!blkmode) {
325.2618 +                pos = 0;
325.2619 +                in.readFully(buf, 0, 2);
325.2620 +            } else if (end - pos < 2) {
325.2621 +                return din.readShort();
325.2622 +            }
325.2623 +            short v = Bits.getShort(buf, pos);
325.2624 +            pos += 2;
325.2625 +            return v;
325.2626 +        }
325.2627 +
325.2628 +        public int readUnsignedShort() throws IOException {
325.2629 +            if (!blkmode) {
325.2630 +                pos = 0;
325.2631 +                in.readFully(buf, 0, 2);
325.2632 +            } else if (end - pos < 2) {
325.2633 +                return din.readUnsignedShort();
325.2634 +            }
325.2635 +            int v = Bits.getShort(buf, pos) & 0xFFFF;
325.2636 +            pos += 2;
325.2637 +            return v;
325.2638 +        }
325.2639 +
325.2640 +        public int readInt() throws IOException {
325.2641 +            if (!blkmode) {
325.2642 +                pos = 0;
325.2643 +                in.readFully(buf, 0, 4);
325.2644 +            } else if (end - pos < 4) {
325.2645 +                return din.readInt();
325.2646 +            }
325.2647 +            int v = Bits.getInt(buf, pos);
325.2648 +            pos += 4;
325.2649 +            return v;
325.2650 +        }
325.2651 +
325.2652 +        public float readFloat() throws IOException {
325.2653 +            if (!blkmode) {
325.2654 +                pos = 0;
325.2655 +                in.readFully(buf, 0, 4);
325.2656 +            } else if (end - pos < 4) {
325.2657 +                return din.readFloat();
325.2658 +            }
325.2659 +            float v = Bits.getFloat(buf, pos);
325.2660 +            pos += 4;
325.2661 +            return v;
325.2662 +        }
325.2663 +
325.2664 +        public long readLong() throws IOException {
325.2665 +            if (!blkmode) {
325.2666 +                pos = 0;
325.2667 +                in.readFully(buf, 0, 8);
325.2668 +            } else if (end - pos < 8) {
325.2669 +                return din.readLong();
325.2670 +            }
325.2671 +            long v = Bits.getLong(buf, pos);
325.2672 +            pos += 8;
325.2673 +            return v;
325.2674 +        }
325.2675 +
325.2676 +        public double readDouble() throws IOException {
325.2677 +            if (!blkmode) {
325.2678 +                pos = 0;
325.2679 +                in.readFully(buf, 0, 8);
325.2680 +            } else if (end - pos < 8) {
325.2681 +                return din.readDouble();
325.2682 +            }
325.2683 +            double v = Bits.getDouble(buf, pos);
325.2684 +            pos += 8;
325.2685 +            return v;
325.2686 +        }
325.2687 +
325.2688 +        public String readUTF() throws IOException {
325.2689 +            return readUTFBody(readUnsignedShort());
325.2690 +        }
325.2691 +
325.2692 +        public String readLine() throws IOException {
325.2693 +            return din.readLine();      // deprecated, not worth optimizing
325.2694 +        }
325.2695 +
325.2696 +        /* -------------- primitive data array input methods --------------- */
325.2697 +        /*
325.2698 +         * The following methods read in spans of primitive data values.
325.2699 +         * Though equivalent to calling the corresponding primitive read
325.2700 +         * methods repeatedly, these methods are optimized for reading groups
325.2701 +         * of primitive data values more efficiently.
325.2702 +         */
325.2703 +
325.2704 +        void readBooleans(boolean[] v, int off, int len) throws IOException {
325.2705 +            int stop, endoff = off + len;
325.2706 +            while (off < endoff) {
325.2707 +                if (!blkmode) {
325.2708 +                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE);
325.2709 +                    in.readFully(buf, 0, span);
325.2710 +                    stop = off + span;
325.2711 +                    pos = 0;
325.2712 +                } else if (end - pos < 1) {
325.2713 +                    v[off++] = din.readBoolean();
325.2714 +                    continue;
325.2715 +                } else {
325.2716 +                    stop = Math.min(endoff, off + end - pos);
325.2717 +                }
325.2718 +
325.2719 +                while (off < stop) {
325.2720 +                    v[off++] = Bits.getBoolean(buf, pos++);
325.2721 +                }
325.2722 +            }
325.2723 +        }
325.2724 +
325.2725 +        void readChars(char[] v, int off, int len) throws IOException {
325.2726 +            int stop, endoff = off + len;
325.2727 +            while (off < endoff) {
325.2728 +                if (!blkmode) {
325.2729 +                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 1);
325.2730 +                    in.readFully(buf, 0, span << 1);
325.2731 +                    stop = off + span;
325.2732 +                    pos = 0;
325.2733 +                } else if (end - pos < 2) {
325.2734 +                    v[off++] = din.readChar();
325.2735 +                    continue;
325.2736 +                } else {
325.2737 +                    stop = Math.min(endoff, off + ((end - pos) >> 1));
325.2738 +                }
325.2739 +
325.2740 +                while (off < stop) {
325.2741 +                    v[off++] = Bits.getChar(buf, pos);
325.2742 +                    pos += 2;
325.2743 +                }
325.2744 +            }
325.2745 +        }
325.2746 +
325.2747 +        void readShorts(short[] v, int off, int len) throws IOException {
325.2748 +            int stop, endoff = off + len;
325.2749 +            while (off < endoff) {
325.2750 +                if (!blkmode) {
325.2751 +                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 1);
325.2752 +                    in.readFully(buf, 0, span << 1);
325.2753 +                    stop = off + span;
325.2754 +                    pos = 0;
325.2755 +                } else if (end - pos < 2) {
325.2756 +                    v[off++] = din.readShort();
325.2757 +                    continue;
325.2758 +                } else {
325.2759 +                    stop = Math.min(endoff, off + ((end - pos) >> 1));
325.2760 +                }
325.2761 +
325.2762 +                while (off < stop) {
325.2763 +                    v[off++] = Bits.getShort(buf, pos);
325.2764 +                    pos += 2;
325.2765 +                }
325.2766 +            }
325.2767 +        }
325.2768 +
325.2769 +        void readInts(int[] v, int off, int len) throws IOException {
325.2770 +            int stop, endoff = off + len;
325.2771 +            while (off < endoff) {
325.2772 +                if (!blkmode) {
325.2773 +                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
325.2774 +                    in.readFully(buf, 0, span << 2);
325.2775 +                    stop = off + span;
325.2776 +                    pos = 0;
325.2777 +                } else if (end - pos < 4) {
325.2778 +                    v[off++] = din.readInt();
325.2779 +                    continue;
325.2780 +                } else {
325.2781 +                    stop = Math.min(endoff, off + ((end - pos) >> 2));
325.2782 +                }
325.2783 +
325.2784 +                while (off < stop) {
325.2785 +                    v[off++] = Bits.getInt(buf, pos);
325.2786 +                    pos += 4;
325.2787 +                }
325.2788 +            }
325.2789 +        }
325.2790 +
325.2791 +        void readFloats(float[] v, int off, int len) throws IOException {
325.2792 +            int span, endoff = off + len;
325.2793 +            while (off < endoff) {
325.2794 +                if (!blkmode) {
325.2795 +                    span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
325.2796 +                    in.readFully(buf, 0, span << 2);
325.2797 +                    pos = 0;
325.2798 +                } else if (end - pos < 4) {
325.2799 +                    v[off++] = din.readFloat();
325.2800 +                    continue;
325.2801 +                } else {
325.2802 +                    span = Math.min(endoff - off, ((end - pos) >> 2));
325.2803 +                }
325.2804 +
325.2805 +                bytesToFloats(buf, pos, v, off, span);
325.2806 +                off += span;
325.2807 +                pos += span << 2;
325.2808 +            }
325.2809 +        }
325.2810 +
325.2811 +        void readLongs(long[] v, int off, int len) throws IOException {
325.2812 +            int stop, endoff = off + len;
325.2813 +            while (off < endoff) {
325.2814 +                if (!blkmode) {
325.2815 +                    int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
325.2816 +                    in.readFully(buf, 0, span << 3);
325.2817 +                    stop = off + span;
325.2818 +                    pos = 0;
325.2819 +                } else if (end - pos < 8) {
325.2820 +                    v[off++] = din.readLong();
325.2821 +                    continue;
325.2822 +                } else {
325.2823 +                    stop = Math.min(endoff, off + ((end - pos) >> 3));
325.2824 +                }
325.2825 +
325.2826 +                while (off < stop) {
325.2827 +                    v[off++] = Bits.getLong(buf, pos);
325.2828 +                    pos += 8;
325.2829 +                }
325.2830 +            }
325.2831 +        }
325.2832 +
325.2833 +        void readDoubles(double[] v, int off, int len) throws IOException {
325.2834 +            int span, endoff = off + len;
325.2835 +            while (off < endoff) {
325.2836 +                if (!blkmode) {
325.2837 +                    span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
325.2838 +                    in.readFully(buf, 0, span << 3);
325.2839 +                    pos = 0;
325.2840 +                } else if (end - pos < 8) {
325.2841 +                    v[off++] = din.readDouble();
325.2842 +                    continue;
325.2843 +                } else {
325.2844 +                    span = Math.min(endoff - off, ((end - pos) >> 3));
325.2845 +                }
325.2846 +
325.2847 +                bytesToDoubles(buf, pos, v, off, span);
325.2848 +                off += span;
325.2849 +                pos += span << 3;
325.2850 +            }
325.2851 +        }
325.2852 +
325.2853 +        /**
325.2854 +         * Reads in string written in "long" UTF format.  "Long" UTF format is
325.2855 +         * identical to standard UTF, except that it uses an 8 byte header
325.2856 +         * (instead of the standard 2 bytes) to convey the UTF encoding length.
325.2857 +         */
325.2858 +        String readLongUTF() throws IOException {
325.2859 +            return readUTFBody(readLong());
325.2860 +        }
325.2861 +
325.2862 +        /**
325.2863 +         * Reads in the "body" (i.e., the UTF representation minus the 2-byte
325.2864 +         * or 8-byte length header) of a UTF encoding, which occupies the next
325.2865 +         * utflen bytes.
325.2866 +         */
325.2867 +        private String readUTFBody(long utflen) throws IOException {
325.2868 +            StringBuilder sbuf = new StringBuilder();
325.2869 +            if (!blkmode) {
325.2870 +                end = pos = 0;
325.2871 +            }
325.2872 +
325.2873 +            while (utflen > 0) {
325.2874 +                int avail = end - pos;
325.2875 +                if (avail >= 3 || (long) avail == utflen) {
325.2876 +                    utflen -= readUTFSpan(sbuf, utflen);
325.2877 +                } else {
325.2878 +                    if (blkmode) {
325.2879 +                        // near block boundary, read one byte at a time
325.2880 +                        utflen -= readUTFChar(sbuf, utflen);
325.2881 +                    } else {
325.2882 +                        // shift and refill buffer manually
325.2883 +                        if (avail > 0) {
325.2884 +                            System.arraycopy(buf, pos, buf, 0, avail);
325.2885 +                        }
325.2886 +                        pos = 0;
325.2887 +                        end = (int) Math.min(MAX_BLOCK_SIZE, utflen);
325.2888 +                        in.readFully(buf, avail, end - avail);
325.2889 +                    }
325.2890 +                }
325.2891 +            }
325.2892 +
325.2893 +            return sbuf.toString();
325.2894 +        }
325.2895 +
325.2896 +        /**
325.2897 +         * Reads span of UTF-encoded characters out of internal buffer
325.2898 +         * (starting at offset pos and ending at or before offset end),
325.2899 +         * consuming no more than utflen bytes.  Appends read characters to
325.2900 +         * sbuf.  Returns the number of bytes consumed.
325.2901 +         */
325.2902 +        private long readUTFSpan(StringBuilder sbuf, long utflen)
325.2903 +            throws IOException
325.2904 +        {
325.2905 +            int cpos = 0;
325.2906 +            int start = pos;
325.2907 +            int avail = Math.min(end - pos, CHAR_BUF_SIZE);
325.2908 +            // stop short of last char unless all of utf bytes in buffer
325.2909 +            int stop = pos + ((utflen > avail) ? avail - 2 : (int) utflen);
325.2910 +            boolean outOfBounds = false;
325.2911 +
325.2912 +            try {
325.2913 +                while (pos < stop) {
325.2914 +                    int b1, b2, b3;
325.2915 +                    b1 = buf[pos++] & 0xFF;
325.2916 +                    switch (b1 >> 4) {
325.2917 +                        case 0:
325.2918 +                        case 1:
325.2919 +                        case 2:
325.2920 +                        case 3:
325.2921 +                        case 4:
325.2922 +                        case 5:
325.2923 +                        case 6:
325.2924 +                        case 7:   // 1 byte format: 0xxxxxxx
325.2925 +                            cbuf[cpos++] = (char) b1;
325.2926 +                            break;
325.2927 +
325.2928 +                        case 12:
325.2929 +                        case 13:  // 2 byte format: 110xxxxx 10xxxxxx
325.2930 +                            b2 = buf[pos++];
325.2931 +                            if ((b2 & 0xC0) != 0x80) {
325.2932 +                                throw new UTFDataFormatException();
325.2933 +                            }
325.2934 +                            cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) |
325.2935 +                                                   ((b2 & 0x3F) << 0));
325.2936 +                            break;
325.2937 +
325.2938 +                        case 14:  // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
325.2939 +                            b3 = buf[pos + 1];
325.2940 +                            b2 = buf[pos + 0];
325.2941 +                            pos += 2;
325.2942 +                            if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
325.2943 +                                throw new UTFDataFormatException();
325.2944 +                            }
325.2945 +                            cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) |
325.2946 +                                                   ((b2 & 0x3F) << 6) |
325.2947 +                                                   ((b3 & 0x3F) << 0));
325.2948 +                            break;
325.2949 +
325.2950 +                        default:  // 10xx xxxx, 1111 xxxx
325.2951 +                            throw new UTFDataFormatException();
325.2952 +                    }
325.2953 +                }
325.2954 +            } catch (ArrayIndexOutOfBoundsException ex) {
325.2955 +                outOfBounds = true;
325.2956 +            } finally {
325.2957 +                if (outOfBounds || (pos - start) > utflen) {
325.2958 +                    /*
325.2959 +                     * Fix for 4450867: if a malformed utf char causes the
325.2960 +                     * conversion loop to scan past the expected end of the utf
325.2961 +                     * string, only consume the expected number of utf bytes.
325.2962 +                     */
325.2963 +                    pos = start + (int) utflen;
325.2964 +                    throw new UTFDataFormatException();
325.2965 +                }
325.2966 +            }
325.2967 +
325.2968 +            sbuf.append(cbuf, 0, cpos);
325.2969 +            return pos - start;
325.2970 +        }
325.2971 +
325.2972 +        /**
325.2973 +         * Reads in single UTF-encoded character one byte at a time, appends
325.2974 +         * the character to sbuf, and returns the number of bytes consumed.
325.2975 +         * This method is used when reading in UTF strings written in block
325.2976 +         * data mode to handle UTF-encoded characters which (potentially)
325.2977 +         * straddle block-data boundaries.
325.2978 +         */
325.2979 +        private int readUTFChar(StringBuilder sbuf, long utflen)
325.2980 +            throws IOException
325.2981 +        {
325.2982 +            int b1, b2, b3;
325.2983 +            b1 = readByte() & 0xFF;
325.2984 +            switch (b1 >> 4) {
325.2985 +                case 0:
325.2986 +                case 1:
325.2987 +                case 2:
325.2988 +                case 3:
325.2989 +                case 4:
325.2990 +                case 5:
325.2991 +                case 6:
325.2992 +                case 7:     // 1 byte format: 0xxxxxxx
325.2993 +                    sbuf.append((char) b1);
325.2994 +                    return 1;
325.2995 +
325.2996 +                case 12:
325.2997 +                case 13:    // 2 byte format: 110xxxxx 10xxxxxx
325.2998 +                    if (utflen < 2) {
325.2999 +                        throw new UTFDataFormatException();
325.3000 +                    }
325.3001 +                    b2 = readByte();
325.3002 +                    if ((b2 & 0xC0) != 0x80) {
325.3003 +                        throw new UTFDataFormatException();
325.3004 +                    }
325.3005 +                    sbuf.append((char) (((b1 & 0x1F) << 6) |
325.3006 +                                        ((b2 & 0x3F) << 0)));
325.3007 +                    return 2;
325.3008 +
325.3009 +                case 14:    // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
325.3010 +                    if (utflen < 3) {
325.3011 +                        if (utflen == 2) {
325.3012 +                            readByte();         // consume remaining byte
325.3013 +                        }
325.3014 +                        throw new UTFDataFormatException();
325.3015 +                    }
325.3016 +                    b2 = readByte();
325.3017 +                    b3 = readByte();
325.3018 +                    if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
325.3019 +                        throw new UTFDataFormatException();
325.3020 +                    }
325.3021 +                    sbuf.append((char) (((b1 & 0x0F) << 12) |
325.3022 +                                        ((b2 & 0x3F) << 6) |
325.3023 +                                        ((b3 & 0x3F) << 0)));
325.3024 +                    return 3;
325.3025 +
325.3026 +                default:   // 10xx xxxx, 1111 xxxx
325.3027 +                    throw new UTFDataFormatException();
325.3028 +            }
325.3029 +        }
325.3030 +    }
325.3031 +
325.3032 +    /**
325.3033 +     * Unsynchronized table which tracks wire handle to object mappings, as
325.3034 +     * well as ClassNotFoundExceptions associated with deserialized objects.
325.3035 +     * This class implements an exception-propagation algorithm for
325.3036 +     * determining which objects should have ClassNotFoundExceptions associated
325.3037 +     * with them, taking into account cycles and discontinuities (e.g., skipped
325.3038 +     * fields) in the object graph.
325.3039 +     *
325.3040 +     * <p>General use of the table is as follows: during deserialization, a
325.3041 +     * given object is first assigned a handle by calling the assign method.
325.3042 +     * This method leaves the assigned handle in an "open" state, wherein
325.3043 +     * dependencies on the exception status of other handles can be registered
325.3044 +     * by calling the markDependency method, or an exception can be directly
325.3045 +     * associated with the handle by calling markException.  When a handle is
325.3046 +     * tagged with an exception, the HandleTable assumes responsibility for
325.3047 +     * propagating the exception to any other objects which depend
325.3048 +     * (transitively) on the exception-tagged object.
325.3049 +     *
325.3050 +     * <p>Once all exception information/dependencies for the handle have been
325.3051 +     * registered, the handle should be "closed" by calling the finish method
325.3052 +     * on it.  The act of finishing a handle allows the exception propagation
325.3053 +     * algorithm to aggressively prune dependency links, lessening the
325.3054 +     * performance/memory impact of exception tracking.
325.3055 +     *
325.3056 +     * <p>Note that the exception propagation algorithm used depends on handles
325.3057 +     * being assigned/finished in LIFO order; however, for simplicity as well
325.3058 +     * as memory conservation, it does not enforce this constraint.
325.3059 +     */
325.3060 +    // REMIND: add full description of exception propagation algorithm?
325.3061 +    private static class HandleTable {
325.3062 +
325.3063 +        /* status codes indicating whether object has associated exception */
325.3064 +        private static final byte STATUS_OK = 1;
325.3065 +        private static final byte STATUS_UNKNOWN = 2;
325.3066 +        private static final byte STATUS_EXCEPTION = 3;
325.3067 +
325.3068 +        /** array mapping handle -> object status */
325.3069 +        byte[] status;
325.3070 +        /** array mapping handle -> object/exception (depending on status) */
325.3071 +        Object[] entries;
325.3072 +        /** array mapping handle -> list of dependent handles (if any) */
325.3073 +        HandleList[] deps;
325.3074 +        /** lowest unresolved dependency */
325.3075 +        int lowDep = -1;
325.3076 +        /** number of handles in table */
325.3077 +        int size = 0;
325.3078 +
325.3079 +        /**
325.3080 +         * Creates handle table with the given initial capacity.
325.3081 +         */
325.3082 +        HandleTable(int initialCapacity) {
325.3083 +            status = new byte[initialCapacity];
325.3084 +            entries = new Object[initialCapacity];
325.3085 +            deps = new HandleList[initialCapacity];
325.3086 +        }
325.3087 +
325.3088 +        /**
325.3089 +         * Assigns next available handle to given object, and returns assigned
325.3090 +         * handle.  Once object has been completely deserialized (and all
325.3091 +         * dependencies on other objects identified), the handle should be
325.3092 +         * "closed" by passing it to finish().
325.3093 +         */
325.3094 +        int assign(Object obj) {
325.3095 +            if (size >= entries.length) {
325.3096 +                grow();
325.3097 +            }
325.3098 +            status[size] = STATUS_UNKNOWN;
325.3099 +            entries[size] = obj;
325.3100 +            return size++;
325.3101 +        }
325.3102 +
325.3103 +        /**
325.3104 +         * Registers a dependency (in exception status) of one handle on
325.3105 +         * another.  The dependent handle must be "open" (i.e., assigned, but
325.3106 +         * not finished yet).  No action is taken if either dependent or target
325.3107 +         * handle is NULL_HANDLE.
325.3108 +         */
325.3109 +        void markDependency(int dependent, int target) {
325.3110 +            if (dependent == NULL_HANDLE || target == NULL_HANDLE) {
325.3111 +                return;
325.3112 +            }
325.3113 +            switch (status[dependent]) {
325.3114 +
325.3115 +                case STATUS_UNKNOWN:
325.3116 +                    switch (status[target]) {
325.3117 +                        case STATUS_OK:
325.3118 +                            // ignore dependencies on objs with no exception
325.3119 +                            break;
325.3120 +
325.3121 +                        case STATUS_EXCEPTION:
325.3122 +                            // eagerly propagate exception
325.3123 +                            markException(dependent,
325.3124 +                                (ClassNotFoundException) entries[target]);
325.3125 +                            break;
325.3126 +
325.3127 +                        case STATUS_UNKNOWN:
325.3128 +                            // add to dependency list of target
325.3129 +                            if (deps[target] == null) {
325.3130 +                                deps[target] = new HandleList();
325.3131 +                            }
325.3132 +                            deps[target].add(dependent);
325.3133 +
325.3134 +                            // remember lowest unresolved target seen
325.3135 +                            if (lowDep < 0 || lowDep > target) {
325.3136 +                                lowDep = target;
325.3137 +                            }
325.3138 +                            break;
325.3139 +
325.3140 +                        default:
325.3141 +                            throw new InternalError();
325.3142 +                    }
325.3143 +                    break;
325.3144 +
325.3145 +                case STATUS_EXCEPTION:
325.3146 +                    break;
325.3147 +
325.3148 +                default:
325.3149 +                    throw new InternalError();
325.3150 +            }
325.3151 +        }
325.3152 +
325.3153 +        /**
325.3154 +         * Associates a ClassNotFoundException (if one not already associated)
325.3155 +         * with the currently active handle and propagates it to other
325.3156 +         * referencing objects as appropriate.  The specified handle must be
325.3157 +         * "open" (i.e., assigned, but not finished yet).
325.3158 +         */
325.3159 +        void markException(int handle, ClassNotFoundException ex) {
325.3160 +            switch (status[handle]) {
325.3161 +                case STATUS_UNKNOWN:
325.3162 +                    status[handle] = STATUS_EXCEPTION;
325.3163 +                    entries[handle] = ex;
325.3164 +
325.3165 +                    // propagate exception to dependents
325.3166 +                    HandleList dlist = deps[handle];
325.3167 +                    if (dlist != null) {
325.3168 +                        int ndeps = dlist.size();
325.3169 +                        for (int i = 0; i < ndeps; i++) {
325.3170 +                            markException(dlist.get(i), ex);
325.3171 +                        }
325.3172 +                        deps[handle] = null;
325.3173 +                    }
325.3174 +                    break;
325.3175 +
325.3176 +                case STATUS_EXCEPTION:
325.3177 +                    break;
325.3178 +
325.3179 +                default:
325.3180 +                    throw new InternalError();
325.3181 +            }
325.3182 +        }
325.3183 +
325.3184 +        /**
325.3185 +         * Marks given handle as finished, meaning that no new dependencies
325.3186 +         * will be marked for handle.  Calls to the assign and finish methods
325.3187 +         * must occur in LIFO order.
325.3188 +         */
325.3189 +        void finish(int handle) {
325.3190 +            int end;
325.3191 +            if (lowDep < 0) {
325.3192 +                // no pending unknowns, only resolve current handle
325.3193 +                end = handle + 1;
325.3194 +            } else if (lowDep >= handle) {
325.3195 +                // pending unknowns now clearable, resolve all upward handles
325.3196 +                end = size;
325.3197 +                lowDep = -1;
325.3198 +            } else {
325.3199 +                // unresolved backrefs present, can't resolve anything yet
325.3200 +                return;
325.3201 +            }
325.3202 +
325.3203 +            // change STATUS_UNKNOWN -> STATUS_OK in selected span of handles
325.3204 +            for (int i = handle; i < end; i++) {
325.3205 +                switch (status[i]) {
325.3206 +                    case STATUS_UNKNOWN:
325.3207 +                        status[i] = STATUS_OK;
325.3208 +                        deps[i] = null;
325.3209 +                        break;
325.3210 +
325.3211 +                    case STATUS_OK:
325.3212 +                    case STATUS_EXCEPTION:
325.3213 +                        break;
325.3214 +
325.3215 +                    default:
325.3216 +                        throw new InternalError();
325.3217 +                }
325.3218 +            }
325.3219 +        }
325.3220 +
325.3221 +        /**
325.3222 +         * Assigns a new object to the given handle.  The object previously
325.3223 +         * associated with the handle is forgotten.  This method has no effect
325.3224 +         * if the given handle already has an exception associated with it.
325.3225 +         * This method may be called at any time after the handle is assigned.
325.3226 +         */
325.3227 +        void setObject(int handle, Object obj) {
325.3228 +            switch (status[handle]) {
325.3229 +                case STATUS_UNKNOWN:
325.3230 +                case STATUS_OK:
325.3231 +                    entries[handle] = obj;
325.3232 +                    break;
325.3233 +
325.3234 +                case STATUS_EXCEPTION:
325.3235 +                    break;
325.3236 +
325.3237 +                default:
325.3238 +                    throw new InternalError();
325.3239 +            }
325.3240 +        }
325.3241 +
325.3242 +        /**
325.3243 +         * Looks up and returns object associated with the given handle.
325.3244 +         * Returns null if the given handle is NULL_HANDLE, or if it has an
325.3245 +         * associated ClassNotFoundException.
325.3246 +         */
325.3247 +        Object lookupObject(int handle) {
325.3248 +            return (handle != NULL_HANDLE &&
325.3249 +                    status[handle] != STATUS_EXCEPTION) ?
325.3250 +                entries[handle] : null;
325.3251 +        }
325.3252 +
325.3253 +        /**
325.3254 +         * Looks up and returns ClassNotFoundException associated with the
325.3255 +         * given handle.  Returns null if the given handle is NULL_HANDLE, or
325.3256 +         * if there is no ClassNotFoundException associated with the handle.
325.3257 +         */
325.3258 +        ClassNotFoundException lookupException(int handle) {
325.3259 +            return (handle != NULL_HANDLE &&
325.3260 +                    status[handle] == STATUS_EXCEPTION) ?
325.3261 +                (ClassNotFoundException) entries[handle] : null;
325.3262 +        }
325.3263 +
325.3264 +        /**
325.3265 +         * Resets table to its initial state.
325.3266 +         */
325.3267 +        void clear() {
325.3268 +            Arrays.fill(status, 0, size, (byte) 0);
325.3269 +            Arrays.fill(entries, 0, size, null);
325.3270 +            Arrays.fill(deps, 0, size, null);
325.3271 +            lowDep = -1;
325.3272 +            size = 0;
325.3273 +        }
325.3274 +
325.3275 +        /**
325.3276 +         * Returns number of handles registered in table.
325.3277 +         */
325.3278 +        int size() {
325.3279 +            return size;
325.3280 +        }
325.3281 +
325.3282 +        /**
325.3283 +         * Expands capacity of internal arrays.
325.3284 +         */
325.3285 +        private void grow() {
325.3286 +            int newCapacity = (entries.length << 1) + 1;
325.3287 +
325.3288 +            byte[] newStatus = new byte[newCapacity];
325.3289 +            Object[] newEntries = new Object[newCapacity];
325.3290 +            HandleList[] newDeps = new HandleList[newCapacity];
325.3291 +
325.3292 +            System.arraycopy(status, 0, newStatus, 0, size);
325.3293 +            System.arraycopy(entries, 0, newEntries, 0, size);
325.3294 +            System.arraycopy(deps, 0, newDeps, 0, size);
325.3295 +
325.3296 +            status = newStatus;
325.3297 +            entries = newEntries;
325.3298 +            deps = newDeps;
325.3299 +        }
325.3300 +
325.3301 +        /**
325.3302 +         * Simple growable list of (integer) handles.
325.3303 +         */
325.3304 +        private static class HandleList {
325.3305 +            private int[] list = new int[4];
325.3306 +            private int size = 0;
325.3307 +
325.3308 +            public HandleList() {
325.3309 +            }
325.3310 +
325.3311 +            public void add(int handle) {
325.3312 +                if (size >= list.length) {
325.3313 +                    int[] newList = new int[list.length << 1];
325.3314 +                    System.arraycopy(list, 0, newList, 0, list.length);
325.3315 +                    list = newList;
325.3316 +                }
325.3317 +                list[size++] = handle;
325.3318 +            }
325.3319 +
325.3320 +            public int get(int index) {
325.3321 +                if (index >= size) {
325.3322 +                    throw new ArrayIndexOutOfBoundsException();
325.3323 +                }
325.3324 +                return list[index];
325.3325 +            }
325.3326 +
325.3327 +            public int size() {
325.3328 +                return size;
325.3329 +            }
325.3330 +        }
325.3331 +    }
325.3332 +
325.3333 +    /**
325.3334 +     * Method for cloning arrays in case of using unsharing reading
325.3335 +     */
325.3336 +    private static Object cloneArray(Object array) {
325.3337 +        if (array instanceof Object[]) {
325.3338 +            return ((Object[]) array).clone();
325.3339 +        } else if (array instanceof boolean[]) {
325.3340 +            return ((boolean[]) array).clone();
325.3341 +        } else if (array instanceof byte[]) {
325.3342 +            return ((byte[]) array).clone();
325.3343 +        } else if (array instanceof char[]) {
325.3344 +            return ((char[]) array).clone();
325.3345 +        } else if (array instanceof double[]) {
325.3346 +            return ((double[]) array).clone();
325.3347 +        } else if (array instanceof float[]) {
325.3348 +            return ((float[]) array).clone();
325.3349 +        } else if (array instanceof int[]) {
325.3350 +            return ((int[]) array).clone();
325.3351 +        } else if (array instanceof long[]) {
325.3352 +            return ((long[]) array).clone();
325.3353 +        } else if (array instanceof short[]) {
325.3354 +            return ((short[]) array).clone();
325.3355 +        } else {
325.3356 +            throw new AssertionError();
325.3357 +        }
325.3358 +    }
325.3359 +
325.3360 +}
   326.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   326.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectInputValidation.java	Wed Feb 27 11:24:58 2013 +0100
   326.3 @@ -0,0 +1,45 @@
   326.4 +/*
   326.5 + * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
   326.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   326.7 + *
   326.8 + * This code is free software; you can redistribute it and/or modify it
   326.9 + * under the terms of the GNU General Public License version 2 only, as
  326.10 + * published by the Free Software Foundation.  Oracle designates this
  326.11 + * particular file as subject to the "Classpath" exception as provided
  326.12 + * by Oracle in the LICENSE file that accompanied this code.
  326.13 + *
  326.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  326.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  326.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  326.17 + * version 2 for more details (a copy is included in the LICENSE file that
  326.18 + * accompanied this code).
  326.19 + *
  326.20 + * You should have received a copy of the GNU General Public License version
  326.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  326.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  326.23 + *
  326.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  326.25 + * or visit www.oracle.com if you need additional information or have any
  326.26 + * questions.
  326.27 + */
  326.28 +
  326.29 +package java.io;
  326.30 +
  326.31 +/**
  326.32 + * Callback interface to allow validation of objects within a graph.
  326.33 + * Allows an object to be called when a complete graph of objects has
  326.34 + * been deserialized.
  326.35 + *
  326.36 + * @author  unascribed
  326.37 + * @see     ObjectInputStream
  326.38 + * @see     ObjectInputStream#registerValidation(java.io.ObjectInputValidation, int)
  326.39 + * @since   JDK1.1
  326.40 + */
  326.41 +public interface ObjectInputValidation {
  326.42 +    /**
  326.43 +     * Validates the object.
  326.44 +     *
  326.45 +     * @exception InvalidObjectException If the object cannot validate itself.
  326.46 +     */
  326.47 +    public void validateObject() throws InvalidObjectException;
  326.48 +}
   327.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   327.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectOutput.java	Wed Feb 27 11:24:58 2013 +0100
   327.3 @@ -0,0 +1,90 @@
   327.4 +/*
   327.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   327.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   327.7 + *
   327.8 + * This code is free software; you can redistribute it and/or modify it
   327.9 + * under the terms of the GNU General Public License version 2 only, as
  327.10 + * published by the Free Software Foundation.  Oracle designates this
  327.11 + * particular file as subject to the "Classpath" exception as provided
  327.12 + * by Oracle in the LICENSE file that accompanied this code.
  327.13 + *
  327.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  327.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  327.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  327.17 + * version 2 for more details (a copy is included in the LICENSE file that
  327.18 + * accompanied this code).
  327.19 + *
  327.20 + * You should have received a copy of the GNU General Public License version
  327.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  327.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  327.23 + *
  327.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  327.25 + * or visit www.oracle.com if you need additional information or have any
  327.26 + * questions.
  327.27 + */
  327.28 +
  327.29 +package java.io;
  327.30 +
  327.31 +/**
  327.32 + * ObjectOutput extends the DataOutput interface to include writing of objects.
  327.33 + * DataOutput includes methods for output of primitive types, ObjectOutput
  327.34 + * extends that interface to include objects, arrays, and Strings.
  327.35 + *
  327.36 + * @author  unascribed
  327.37 + * @see java.io.InputStream
  327.38 + * @see java.io.ObjectOutputStream
  327.39 + * @see java.io.ObjectInputStream
  327.40 + * @since   JDK1.1
  327.41 + */
  327.42 +public interface ObjectOutput extends DataOutput, AutoCloseable {
  327.43 +    /**
  327.44 +     * Write an object to the underlying storage or stream.  The
  327.45 +     * class that implements this interface defines how the object is
  327.46 +     * written.
  327.47 +     *
  327.48 +     * @param obj the object to be written
  327.49 +     * @exception IOException Any of the usual Input/Output related exceptions.
  327.50 +     */
  327.51 +    public void writeObject(Object obj)
  327.52 +      throws IOException;
  327.53 +
  327.54 +    /**
  327.55 +     * Writes a byte. This method will block until the byte is actually
  327.56 +     * written.
  327.57 +     * @param b the byte
  327.58 +     * @exception IOException If an I/O error has occurred.
  327.59 +     */
  327.60 +    public void write(int b) throws IOException;
  327.61 +
  327.62 +    /**
  327.63 +     * Writes an array of bytes. This method will block until the bytes
  327.64 +     * are actually written.
  327.65 +     * @param b the data to be written
  327.66 +     * @exception IOException If an I/O error has occurred.
  327.67 +     */
  327.68 +    public void write(byte b[]) throws IOException;
  327.69 +
  327.70 +    /**
  327.71 +     * Writes a sub array of bytes.
  327.72 +     * @param b the data to be written
  327.73 +     * @param off       the start offset in the data
  327.74 +     * @param len       the number of bytes that are written
  327.75 +     * @exception IOException If an I/O error has occurred.
  327.76 +     */
  327.77 +    public void write(byte b[], int off, int len) throws IOException;
  327.78 +
  327.79 +    /**
  327.80 +     * Flushes the stream. This will write any buffered
  327.81 +     * output bytes.
  327.82 +     * @exception IOException If an I/O error has occurred.
  327.83 +     */
  327.84 +    public void flush() throws IOException;
  327.85 +
  327.86 +    /**
  327.87 +     * Closes the stream. This method must be called
  327.88 +     * to release any resources associated with the
  327.89 +     * stream.
  327.90 +     * @exception IOException If an I/O error has occurred.
  327.91 +     */
  327.92 +    public void close() throws IOException;
  327.93 +}
   328.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   328.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectOutputStream.java	Wed Feb 27 11:24:58 2013 +0100
   328.3 @@ -0,0 +1,2369 @@
   328.4 +/*
   328.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   328.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   328.7 + *
   328.8 + * This code is free software; you can redistribute it and/or modify it
   328.9 + * under the terms of the GNU General Public License version 2 only, as
  328.10 + * published by the Free Software Foundation.  Oracle designates this
  328.11 + * particular file as subject to the "Classpath" exception as provided
  328.12 + * by Oracle in the LICENSE file that accompanied this code.
  328.13 + *
  328.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  328.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  328.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  328.17 + * version 2 for more details (a copy is included in the LICENSE file that
  328.18 + * accompanied this code).
  328.19 + *
  328.20 + * You should have received a copy of the GNU General Public License version
  328.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  328.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  328.23 + *
  328.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  328.25 + * or visit www.oracle.com if you need additional information or have any
  328.26 + * questions.
  328.27 + */
  328.28 +
  328.29 +package java.io;
  328.30 +
  328.31 +import java.util.ArrayList;
  328.32 +import java.util.Arrays;
  328.33 +import java.util.List;
  328.34 +import org.apidesign.bck2brwsr.emul.lang.System;
  328.35 +
  328.36 +/**
  328.37 + * An ObjectOutputStream writes primitive data types and graphs of Java objects
  328.38 + * to an OutputStream.  The objects can be read (reconstituted) using an
  328.39 + * ObjectInputStream.  Persistent storage of objects can be accomplished by
  328.40 + * using a file for the stream.  If the stream is a network socket stream, the
  328.41 + * objects can be reconstituted on another host or in another process.
  328.42 + *
  328.43 + * <p>Only objects that support the java.io.Serializable interface can be
  328.44 + * written to streams.  The class of each serializable object is encoded
  328.45 + * including the class name and signature of the class, the values of the
  328.46 + * object's fields and arrays, and the closure of any other objects referenced
  328.47 + * from the initial objects.
  328.48 + *
  328.49 + * <p>The method writeObject is used to write an object to the stream.  Any
  328.50 + * object, including Strings and arrays, is written with writeObject. Multiple
  328.51 + * objects or primitives can be written to the stream.  The objects must be
  328.52 + * read back from the corresponding ObjectInputstream with the same types and
  328.53 + * in the same order as they were written.
  328.54 + *
  328.55 + * <p>Primitive data types can also be written to the stream using the
  328.56 + * appropriate methods from DataOutput. Strings can also be written using the
  328.57 + * writeUTF method.
  328.58 + *
  328.59 + * <p>The default serialization mechanism for an object writes the class of the
  328.60 + * object, the class signature, and the values of all non-transient and
  328.61 + * non-static fields.  References to other objects (except in transient or
  328.62 + * static fields) cause those objects to be written also. Multiple references
  328.63 + * to a single object are encoded using a reference sharing mechanism so that
  328.64 + * graphs of objects can be restored to the same shape as when the original was
  328.65 + * written.
  328.66 + *
  328.67 + * <p>For example to write an object that can be read by the example in
  328.68 + * ObjectInputStream:
  328.69 + * <br>
  328.70 + * <pre>
  328.71 + *      FileOutputStream fos = new FileOutputStream("t.tmp");
  328.72 + *      ObjectOutputStream oos = new ObjectOutputStream(fos);
  328.73 + *
  328.74 + *      oos.writeInt(12345);
  328.75 + *      oos.writeObject("Today");
  328.76 + *      oos.writeObject(new Date());
  328.77 + *
  328.78 + *      oos.close();
  328.79 + * </pre>
  328.80 + *
  328.81 + * <p>Classes that require special handling during the serialization and
  328.82 + * deserialization process must implement special methods with these exact
  328.83 + * signatures:
  328.84 + * <br>
  328.85 + * <pre>
  328.86 + * private void readObject(java.io.ObjectInputStream stream)
  328.87 + *     throws IOException, ClassNotFoundException;
  328.88 + * private void writeObject(java.io.ObjectOutputStream stream)
  328.89 + *     throws IOException
  328.90 + * private void readObjectNoData()
  328.91 + *     throws ObjectStreamException;
  328.92 + * </pre>
  328.93 + *
  328.94 + * <p>The writeObject method is responsible for writing the state of the object
  328.95 + * for its particular class so that the corresponding readObject method can
  328.96 + * restore it.  The method does not need to concern itself with the state
  328.97 + * belonging to the object's superclasses or subclasses.  State is saved by
  328.98 + * writing the individual fields to the ObjectOutputStream using the
  328.99 + * writeObject method or by using the methods for primitive data types
 328.100 + * supported by DataOutput.
 328.101 + *
 328.102 + * <p>Serialization does not write out the fields of any object that does not
 328.103 + * implement the java.io.Serializable interface.  Subclasses of Objects that
 328.104 + * are not serializable can be serializable. In this case the non-serializable
 328.105 + * class must have a no-arg constructor to allow its fields to be initialized.
 328.106 + * In this case it is the responsibility of the subclass to save and restore
 328.107 + * the state of the non-serializable class. It is frequently the case that the
 328.108 + * fields of that class are accessible (public, package, or protected) or that
 328.109 + * there are get and set methods that can be used to restore the state.
 328.110 + *
 328.111 + * <p>Serialization of an object can be prevented by implementing writeObject
 328.112 + * and readObject methods that throw the NotSerializableException.  The
 328.113 + * exception will be caught by the ObjectOutputStream and abort the
 328.114 + * serialization process.
 328.115 + *
 328.116 + * <p>Implementing the Externalizable interface allows the object to assume
 328.117 + * complete control over the contents and format of the object's serialized
 328.118 + * form.  The methods of the Externalizable interface, writeExternal and
 328.119 + * readExternal, are called to save and restore the objects state.  When
 328.120 + * implemented by a class they can write and read their own state using all of
 328.121 + * the methods of ObjectOutput and ObjectInput.  It is the responsibility of
 328.122 + * the objects to handle any versioning that occurs.
 328.123 + *
 328.124 + * <p>Enum constants are serialized differently than ordinary serializable or
 328.125 + * externalizable objects.  The serialized form of an enum constant consists
 328.126 + * solely of its name; field values of the constant are not transmitted.  To
 328.127 + * serialize an enum constant, ObjectOutputStream writes the string returned by
 328.128 + * the constant's name method.  Like other serializable or externalizable
 328.129 + * objects, enum constants can function as the targets of back references
 328.130 + * appearing subsequently in the serialization stream.  The process by which
 328.131 + * enum constants are serialized cannot be customized; any class-specific
 328.132 + * writeObject and writeReplace methods defined by enum types are ignored
 328.133 + * during serialization.  Similarly, any serialPersistentFields or
 328.134 + * serialVersionUID field declarations are also ignored--all enum types have a
 328.135 + * fixed serialVersionUID of 0L.
 328.136 + *
 328.137 + * <p>Primitive data, excluding serializable fields and externalizable data, is
 328.138 + * written to the ObjectOutputStream in block-data records. A block data record
 328.139 + * is composed of a header and data. The block data header consists of a marker
 328.140 + * and the number of bytes to follow the header.  Consecutive primitive data
 328.141 + * writes are merged into one block-data record.  The blocking factor used for
 328.142 + * a block-data record will be 1024 bytes.  Each block-data record will be
 328.143 + * filled up to 1024 bytes, or be written whenever there is a termination of
 328.144 + * block-data mode.  Calls to the ObjectOutputStream methods writeObject,
 328.145 + * defaultWriteObject and writeFields initially terminate any existing
 328.146 + * block-data record.
 328.147 + *
 328.148 + * @author      Mike Warres
 328.149 + * @author      Roger Riggs
 328.150 + * @see java.io.DataOutput
 328.151 + * @see java.io.ObjectInputStream
 328.152 + * @see java.io.Serializable
 328.153 + * @see java.io.Externalizable
 328.154 + * @see <a href="../../../platform/serialization/spec/output.html">Object Serialization Specification, Section 2, Object Output Classes</a>
 328.155 + * @since       JDK1.1
 328.156 + */
 328.157 +public class ObjectOutputStream
 328.158 +    extends OutputStream implements ObjectOutput, ObjectStreamConstants
 328.159 +{
 328.160 +    /** filter stream for handling block data conversion */
 328.161 +    private final BlockDataOutputStream bout;
 328.162 +    /** obj -> wire handle map */
 328.163 +    private final HandleTable handles;
 328.164 +    /** obj -> replacement obj map */
 328.165 +    private final ReplaceTable subs;
 328.166 +    /** stream protocol version */
 328.167 +    private int protocol = PROTOCOL_VERSION_2;
 328.168 +    /** recursion depth */
 328.169 +    private int depth;
 328.170 +
 328.171 +    /** buffer for writing primitive field values */
 328.172 +    private byte[] primVals;
 328.173 +
 328.174 +    /** if true, invoke writeObjectOverride() instead of writeObject() */
 328.175 +    private final boolean enableOverride;
 328.176 +    /** if true, invoke replaceObject() */
 328.177 +    private boolean enableReplace;
 328.178 +
 328.179 +    // values below valid only during upcalls to writeObject()/writeExternal()
 328.180 +    /**
 328.181 +     * Context during upcalls to class-defined writeObject methods; holds
 328.182 +     * object currently being serialized and descriptor for current class.
 328.183 +     * Null when not during writeObject upcall.
 328.184 +     */
 328.185 +    private Object curContext;
 328.186 +    /** current PutField object */
 328.187 +    private PutFieldImpl curPut;
 328.188 +
 328.189 +    /** custom storage for debug trace info */
 328.190 +    private final DebugTraceInfoStack debugInfoStack;
 328.191 +
 328.192 +    /**
 328.193 +     * value of "sun.io.serialization.extendedDebugInfo" property,
 328.194 +     * as true or false for extended information about exception's place
 328.195 +     */
 328.196 +    private static final boolean extendedDebugInfo = false;
 328.197 +
 328.198 +    /**
 328.199 +     * Creates an ObjectOutputStream that writes to the specified OutputStream.
 328.200 +     * This constructor writes the serialization stream header to the
 328.201 +     * underlying stream; callers may wish to flush the stream immediately to
 328.202 +     * ensure that constructors for receiving ObjectInputStreams will not block
 328.203 +     * when reading the header.
 328.204 +     *
 328.205 +     * <p>If a security manager is installed, this constructor will check for
 328.206 +     * the "enableSubclassImplementation" SerializablePermission when invoked
 328.207 +     * directly or indirectly by the constructor of a subclass which overrides
 328.208 +     * the ObjectOutputStream.putFields or ObjectOutputStream.writeUnshared
 328.209 +     * methods.
 328.210 +     *
 328.211 +     * @param   out output stream to write to
 328.212 +     * @throws  IOException if an I/O error occurs while writing stream header
 328.213 +     * @throws  SecurityException if untrusted subclass illegally overrides
 328.214 +     *          security-sensitive methods
 328.215 +     * @throws  NullPointerException if <code>out</code> is <code>null</code>
 328.216 +     * @since   1.4
 328.217 +     * @see     ObjectOutputStream#ObjectOutputStream()
 328.218 +     * @see     ObjectOutputStream#putFields()
 328.219 +     * @see     ObjectInputStream#ObjectInputStream(InputStream)
 328.220 +     */
 328.221 +    public ObjectOutputStream(OutputStream out) throws IOException {
 328.222 +        verifySubclass();
 328.223 +        bout = new BlockDataOutputStream(out);
 328.224 +        handles = new HandleTable(10, (float) 3.00);
 328.225 +        subs = new ReplaceTable(10, (float) 3.00);
 328.226 +        enableOverride = false;
 328.227 +        writeStreamHeader();
 328.228 +        bout.setBlockDataMode(true);
 328.229 +        if (extendedDebugInfo) {
 328.230 +            debugInfoStack = new DebugTraceInfoStack();
 328.231 +        } else {
 328.232 +            debugInfoStack = null;
 328.233 +        }
 328.234 +    }
 328.235 +
 328.236 +    /**
 328.237 +     * Provide a way for subclasses that are completely reimplementing
 328.238 +     * ObjectOutputStream to not have to allocate private data just used by
 328.239 +     * this implementation of ObjectOutputStream.
 328.240 +     *
 328.241 +     * <p>If there is a security manager installed, this method first calls the
 328.242 +     * security manager's <code>checkPermission</code> method with a
 328.243 +     * <code>SerializablePermission("enableSubclassImplementation")</code>
 328.244 +     * permission to ensure it's ok to enable subclassing.
 328.245 +     *
 328.246 +     * @throws  SecurityException if a security manager exists and its
 328.247 +     *          <code>checkPermission</code> method denies enabling
 328.248 +     *          subclassing.
 328.249 +     * @see SecurityManager#checkPermission
 328.250 +     * @see java.io.SerializablePermission
 328.251 +     */
 328.252 +    protected ObjectOutputStream() throws IOException, SecurityException {
 328.253 +        throw new SecurityException();
 328.254 +    }
 328.255 +
 328.256 +    /**
 328.257 +     * Specify stream protocol version to use when writing the stream.
 328.258 +     *
 328.259 +     * <p>This routine provides a hook to enable the current version of
 328.260 +     * Serialization to write in a format that is backwards compatible to a
 328.261 +     * previous version of the stream format.
 328.262 +     *
 328.263 +     * <p>Every effort will be made to avoid introducing additional
 328.264 +     * backwards incompatibilities; however, sometimes there is no
 328.265 +     * other alternative.
 328.266 +     *
 328.267 +     * @param   version use ProtocolVersion from java.io.ObjectStreamConstants.
 328.268 +     * @throws  IllegalStateException if called after any objects
 328.269 +     *          have been serialized.
 328.270 +     * @throws  IllegalArgumentException if invalid version is passed in.
 328.271 +     * @throws  IOException if I/O errors occur
 328.272 +     * @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_1
 328.273 +     * @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_2
 328.274 +     * @since   1.2
 328.275 +     */
 328.276 +    public void useProtocolVersion(int version) throws IOException {
 328.277 +        if (handles.size() != 0) {
 328.278 +            // REMIND: implement better check for pristine stream?
 328.279 +            throw new IllegalStateException("stream non-empty");
 328.280 +        }
 328.281 +        switch (version) {
 328.282 +            case PROTOCOL_VERSION_1:
 328.283 +            case PROTOCOL_VERSION_2:
 328.284 +                protocol = version;
 328.285 +                break;
 328.286 +
 328.287 +            default:
 328.288 +                throw new IllegalArgumentException(
 328.289 +                    "unknown version: " + version);
 328.290 +        }
 328.291 +    }
 328.292 +
 328.293 +    /**
 328.294 +     * Write the specified object to the ObjectOutputStream.  The class of the
 328.295 +     * object, the signature of the class, and the values of the non-transient
 328.296 +     * and non-static fields of the class and all of its supertypes are
 328.297 +     * written.  Default serialization for a class can be overridden using the
 328.298 +     * writeObject and the readObject methods.  Objects referenced by this
 328.299 +     * object are written transitively so that a complete equivalent graph of
 328.300 +     * objects can be reconstructed by an ObjectInputStream.
 328.301 +     *
 328.302 +     * <p>Exceptions are thrown for problems with the OutputStream and for
 328.303 +     * classes that should not be serialized.  All exceptions are fatal to the
 328.304 +     * OutputStream, which is left in an indeterminate state, and it is up to
 328.305 +     * the caller to ignore or recover the stream state.
 328.306 +     *
 328.307 +     * @throws  InvalidClassException Something is wrong with a class used by
 328.308 +     *          serialization.
 328.309 +     * @throws  NotSerializableException Some object to be serialized does not
 328.310 +     *          implement the java.io.Serializable interface.
 328.311 +     * @throws  IOException Any exception thrown by the underlying
 328.312 +     *          OutputStream.
 328.313 +     */
 328.314 +    public final void writeObject(Object obj) throws IOException {
 328.315 +        if (enableOverride) {
 328.316 +            writeObjectOverride(obj);
 328.317 +            return;
 328.318 +        }
 328.319 +        try {
 328.320 +            writeObject0(obj, false);
 328.321 +        } catch (IOException ex) {
 328.322 +            if (depth == 0) {
 328.323 +                writeFatalException(ex);
 328.324 +            }
 328.325 +            throw ex;
 328.326 +        }
 328.327 +    }
 328.328 +
 328.329 +    /**
 328.330 +     * Method used by subclasses to override the default writeObject method.
 328.331 +     * This method is called by trusted subclasses of ObjectInputStream that
 328.332 +     * constructed ObjectInputStream using the protected no-arg constructor.
 328.333 +     * The subclass is expected to provide an override method with the modifier
 328.334 +     * "final".
 328.335 +     *
 328.336 +     * @param   obj object to be written to the underlying stream
 328.337 +     * @throws  IOException if there are I/O errors while writing to the
 328.338 +     *          underlying stream
 328.339 +     * @see #ObjectOutputStream()
 328.340 +     * @see #writeObject(Object)
 328.341 +     * @since 1.2
 328.342 +     */
 328.343 +    protected void writeObjectOverride(Object obj) throws IOException {
 328.344 +    }
 328.345 +
 328.346 +    /**
 328.347 +     * Writes an "unshared" object to the ObjectOutputStream.  This method is
 328.348 +     * identical to writeObject, except that it always writes the given object
 328.349 +     * as a new, unique object in the stream (as opposed to a back-reference
 328.350 +     * pointing to a previously serialized instance).  Specifically:
 328.351 +     * <ul>
 328.352 +     *   <li>An object written via writeUnshared is always serialized in the
 328.353 +     *       same manner as a newly appearing object (an object that has not
 328.354 +     *       been written to the stream yet), regardless of whether or not the
 328.355 +     *       object has been written previously.
 328.356 +     *
 328.357 +     *   <li>If writeObject is used to write an object that has been previously
 328.358 +     *       written with writeUnshared, the previous writeUnshared operation
 328.359 +     *       is treated as if it were a write of a separate object.  In other
 328.360 +     *       words, ObjectOutputStream will never generate back-references to
 328.361 +     *       object data written by calls to writeUnshared.
 328.362 +     * </ul>
 328.363 +     * While writing an object via writeUnshared does not in itself guarantee a
 328.364 +     * unique reference to the object when it is deserialized, it allows a
 328.365 +     * single object to be defined multiple times in a stream, so that multiple
 328.366 +     * calls to readUnshared by the receiver will not conflict.  Note that the
 328.367 +     * rules described above only apply to the base-level object written with
 328.368 +     * writeUnshared, and not to any transitively referenced sub-objects in the
 328.369 +     * object graph to be serialized.
 328.370 +     *
 328.371 +     * <p>ObjectOutputStream subclasses which override this method can only be
 328.372 +     * constructed in security contexts possessing the
 328.373 +     * "enableSubclassImplementation" SerializablePermission; any attempt to
 328.374 +     * instantiate such a subclass without this permission will cause a
 328.375 +     * SecurityException to be thrown.
 328.376 +     *
 328.377 +     * @param   obj object to write to stream
 328.378 +     * @throws  NotSerializableException if an object in the graph to be
 328.379 +     *          serialized does not implement the Serializable interface
 328.380 +     * @throws  InvalidClassException if a problem exists with the class of an
 328.381 +     *          object to be serialized
 328.382 +     * @throws  IOException if an I/O error occurs during serialization
 328.383 +     * @since 1.4
 328.384 +     */
 328.385 +    public void writeUnshared(Object obj) throws IOException {
 328.386 +        try {
 328.387 +            writeObject0(obj, true);
 328.388 +        } catch (IOException ex) {
 328.389 +            if (depth == 0) {
 328.390 +                writeFatalException(ex);
 328.391 +            }
 328.392 +            throw ex;
 328.393 +        }
 328.394 +    }
 328.395 +
 328.396 +    /**
 328.397 +     * Write the non-static and non-transient fields of the current class to
 328.398 +     * this stream.  This may only be called from the writeObject method of the
 328.399 +     * class being serialized. It will throw the NotActiveException if it is
 328.400 +     * called otherwise.
 328.401 +     *
 328.402 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.403 +     *          <code>OutputStream</code>
 328.404 +     */
 328.405 +    public void defaultWriteObject() throws IOException {
 328.406 +        if ( curContext == null ) {
 328.407 +            throw new NotActiveException("not in call to writeObject");
 328.408 +        }
 328.409 +        Object curObj = null; // curContext.getObj();
 328.410 +        ObjectStreamClass curDesc = null; // curContext.getDesc();
 328.411 +        bout.setBlockDataMode(false);
 328.412 +        defaultWriteFields(curObj, curDesc);
 328.413 +        bout.setBlockDataMode(true);
 328.414 +    }
 328.415 +
 328.416 +    /**
 328.417 +     * Retrieve the object used to buffer persistent fields to be written to
 328.418 +     * the stream.  The fields will be written to the stream when writeFields
 328.419 +     * method is called.
 328.420 +     *
 328.421 +     * @return  an instance of the class Putfield that holds the serializable
 328.422 +     *          fields
 328.423 +     * @throws  IOException if I/O errors occur
 328.424 +     * @since 1.2
 328.425 +     */
 328.426 +    public ObjectOutputStream.PutField putFields() throws IOException {
 328.427 +        if (curPut == null) {
 328.428 +            if (curContext == null) {
 328.429 +                throw new NotActiveException("not in call to writeObject");
 328.430 +            }
 328.431 +            Object curObj = null; // curContext.getObj();
 328.432 +            ObjectStreamClass curDesc = null; // curContext.getDesc();
 328.433 +            curPut = new PutFieldImpl(curDesc);
 328.434 +        }
 328.435 +        return curPut;
 328.436 +    }
 328.437 +
 328.438 +    /**
 328.439 +     * Write the buffered fields to the stream.
 328.440 +     *
 328.441 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.442 +     *          stream
 328.443 +     * @throws  NotActiveException Called when a classes writeObject method was
 328.444 +     *          not called to write the state of the object.
 328.445 +     * @since 1.2
 328.446 +     */
 328.447 +    public void writeFields() throws IOException {
 328.448 +        if (curPut == null) {
 328.449 +            throw new NotActiveException("no current PutField object");
 328.450 +        }
 328.451 +        bout.setBlockDataMode(false);
 328.452 +        curPut.writeFields();
 328.453 +        bout.setBlockDataMode(true);
 328.454 +    }
 328.455 +
 328.456 +    /**
 328.457 +     * Reset will disregard the state of any objects already written to the
 328.458 +     * stream.  The state is reset to be the same as a new ObjectOutputStream.
 328.459 +     * The current point in the stream is marked as reset so the corresponding
 328.460 +     * ObjectInputStream will be reset at the same point.  Objects previously
 328.461 +     * written to the stream will not be refered to as already being in the
 328.462 +     * stream.  They will be written to the stream again.
 328.463 +     *
 328.464 +     * @throws  IOException if reset() is invoked while serializing an object.
 328.465 +     */
 328.466 +    public void reset() throws IOException {
 328.467 +        if (depth != 0) {
 328.468 +            throw new IOException("stream active");
 328.469 +        }
 328.470 +        bout.setBlockDataMode(false);
 328.471 +        bout.writeByte(TC_RESET);
 328.472 +        clear();
 328.473 +        bout.setBlockDataMode(true);
 328.474 +    }
 328.475 +
 328.476 +    /**
 328.477 +     * Subclasses may implement this method to allow class data to be stored in
 328.478 +     * the stream. By default this method does nothing.  The corresponding
 328.479 +     * method in ObjectInputStream is resolveClass.  This method is called
 328.480 +     * exactly once for each unique class in the stream.  The class name and
 328.481 +     * signature will have already been written to the stream.  This method may
 328.482 +     * make free use of the ObjectOutputStream to save any representation of
 328.483 +     * the class it deems suitable (for example, the bytes of the class file).
 328.484 +     * The resolveClass method in the corresponding subclass of
 328.485 +     * ObjectInputStream must read and use any data or objects written by
 328.486 +     * annotateClass.
 328.487 +     *
 328.488 +     * @param   cl the class to annotate custom data for
 328.489 +     * @throws  IOException Any exception thrown by the underlying
 328.490 +     *          OutputStream.
 328.491 +     */
 328.492 +    protected void annotateClass(Class<?> cl) throws IOException {
 328.493 +    }
 328.494 +
 328.495 +    /**
 328.496 +     * Subclasses may implement this method to store custom data in the stream
 328.497 +     * along with descriptors for dynamic proxy classes.
 328.498 +     *
 328.499 +     * <p>This method is called exactly once for each unique proxy class
 328.500 +     * descriptor in the stream.  The default implementation of this method in
 328.501 +     * <code>ObjectOutputStream</code> does nothing.
 328.502 +     *
 328.503 +     * <p>The corresponding method in <code>ObjectInputStream</code> is
 328.504 +     * <code>resolveProxyClass</code>.  For a given subclass of
 328.505 +     * <code>ObjectOutputStream</code> that overrides this method, the
 328.506 +     * <code>resolveProxyClass</code> method in the corresponding subclass of
 328.507 +     * <code>ObjectInputStream</code> must read any data or objects written by
 328.508 +     * <code>annotateProxyClass</code>.
 328.509 +     *
 328.510 +     * @param   cl the proxy class to annotate custom data for
 328.511 +     * @throws  IOException any exception thrown by the underlying
 328.512 +     *          <code>OutputStream</code>
 328.513 +     * @see ObjectInputStream#resolveProxyClass(String[])
 328.514 +     * @since   1.3
 328.515 +     */
 328.516 +    protected void annotateProxyClass(Class<?> cl) throws IOException {
 328.517 +    }
 328.518 +
 328.519 +    /**
 328.520 +     * This method will allow trusted subclasses of ObjectOutputStream to
 328.521 +     * substitute one object for another during serialization. Replacing
 328.522 +     * objects is disabled until enableReplaceObject is called. The
 328.523 +     * enableReplaceObject method checks that the stream requesting to do
 328.524 +     * replacement can be trusted.  The first occurrence of each object written
 328.525 +     * into the serialization stream is passed to replaceObject.  Subsequent
 328.526 +     * references to the object are replaced by the object returned by the
 328.527 +     * original call to replaceObject.  To ensure that the private state of
 328.528 +     * objects is not unintentionally exposed, only trusted streams may use
 328.529 +     * replaceObject.
 328.530 +     *
 328.531 +     * <p>The ObjectOutputStream.writeObject method takes a parameter of type
 328.532 +     * Object (as opposed to type Serializable) to allow for cases where
 328.533 +     * non-serializable objects are replaced by serializable ones.
 328.534 +     *
 328.535 +     * <p>When a subclass is replacing objects it must insure that either a
 328.536 +     * complementary substitution must be made during deserialization or that
 328.537 +     * the substituted object is compatible with every field where the
 328.538 +     * reference will be stored.  Objects whose type is not a subclass of the
 328.539 +     * type of the field or array element abort the serialization by raising an
 328.540 +     * exception and the object is not be stored.
 328.541 +     *
 328.542 +     * <p>This method is called only once when each object is first
 328.543 +     * encountered.  All subsequent references to the object will be redirected
 328.544 +     * to the new object. This method should return the object to be
 328.545 +     * substituted or the original object.
 328.546 +     *
 328.547 +     * <p>Null can be returned as the object to be substituted, but may cause
 328.548 +     * NullReferenceException in classes that contain references to the
 328.549 +     * original object since they may be expecting an object instead of
 328.550 +     * null.
 328.551 +     *
 328.552 +     * @param   obj the object to be replaced
 328.553 +     * @return  the alternate object that replaced the specified one
 328.554 +     * @throws  IOException Any exception thrown by the underlying
 328.555 +     *          OutputStream.
 328.556 +     */
 328.557 +    protected Object replaceObject(Object obj) throws IOException {
 328.558 +        return obj;
 328.559 +    }
 328.560 +
 328.561 +    /**
 328.562 +     * Enable the stream to do replacement of objects in the stream.  When
 328.563 +     * enabled, the replaceObject method is called for every object being
 328.564 +     * serialized.
 328.565 +     *
 328.566 +     * <p>If <code>enable</code> is true, and there is a security manager
 328.567 +     * installed, this method first calls the security manager's
 328.568 +     * <code>checkPermission</code> method with a
 328.569 +     * <code>SerializablePermission("enableSubstitution")</code> permission to
 328.570 +     * ensure it's ok to enable the stream to do replacement of objects in the
 328.571 +     * stream.
 328.572 +     *
 328.573 +     * @param   enable boolean parameter to enable replacement of objects
 328.574 +     * @return  the previous setting before this method was invoked
 328.575 +     * @throws  SecurityException if a security manager exists and its
 328.576 +     *          <code>checkPermission</code> method denies enabling the stream
 328.577 +     *          to do replacement of objects in the stream.
 328.578 +     * @see SecurityManager#checkPermission
 328.579 +     * @see java.io.SerializablePermission
 328.580 +     */
 328.581 +    protected boolean enableReplaceObject(boolean enable)
 328.582 +        throws SecurityException
 328.583 +    {
 328.584 +        throw new SecurityException();
 328.585 +    }
 328.586 +
 328.587 +    /**
 328.588 +     * The writeStreamHeader method is provided so subclasses can append or
 328.589 +     * prepend their own header to the stream.  It writes the magic number and
 328.590 +     * version to the stream.
 328.591 +     *
 328.592 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.593 +     *          stream
 328.594 +     */
 328.595 +    protected void writeStreamHeader() throws IOException {
 328.596 +        bout.writeShort(STREAM_MAGIC);
 328.597 +        bout.writeShort(STREAM_VERSION);
 328.598 +    }
 328.599 +
 328.600 +    /**
 328.601 +     * Write the specified class descriptor to the ObjectOutputStream.  Class
 328.602 +     * descriptors are used to identify the classes of objects written to the
 328.603 +     * stream.  Subclasses of ObjectOutputStream may override this method to
 328.604 +     * customize the way in which class descriptors are written to the
 328.605 +     * serialization stream.  The corresponding method in ObjectInputStream,
 328.606 +     * <code>readClassDescriptor</code>, should then be overridden to
 328.607 +     * reconstitute the class descriptor from its custom stream representation.
 328.608 +     * By default, this method writes class descriptors according to the format
 328.609 +     * defined in the Object Serialization specification.
 328.610 +     *
 328.611 +     * <p>Note that this method will only be called if the ObjectOutputStream
 328.612 +     * is not using the old serialization stream format (set by calling
 328.613 +     * ObjectOutputStream's <code>useProtocolVersion</code> method).  If this
 328.614 +     * serialization stream is using the old format
 328.615 +     * (<code>PROTOCOL_VERSION_1</code>), the class descriptor will be written
 328.616 +     * internally in a manner that cannot be overridden or customized.
 328.617 +     *
 328.618 +     * @param   desc class descriptor to write to the stream
 328.619 +     * @throws  IOException If an I/O error has occurred.
 328.620 +     * @see java.io.ObjectInputStream#readClassDescriptor()
 328.621 +     * @see #useProtocolVersion(int)
 328.622 +     * @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_1
 328.623 +     * @since 1.3
 328.624 +     */
 328.625 +    protected void writeClassDescriptor(ObjectStreamClass desc)
 328.626 +        throws IOException
 328.627 +    {
 328.628 +        desc.writeNonProxy(this);
 328.629 +    }
 328.630 +
 328.631 +    /**
 328.632 +     * Writes a byte. This method will block until the byte is actually
 328.633 +     * written.
 328.634 +     *
 328.635 +     * @param   val the byte to be written to the stream
 328.636 +     * @throws  IOException If an I/O error has occurred.
 328.637 +     */
 328.638 +    public void write(int val) throws IOException {
 328.639 +        bout.write(val);
 328.640 +    }
 328.641 +
 328.642 +    /**
 328.643 +     * Writes an array of bytes. This method will block until the bytes are
 328.644 +     * actually written.
 328.645 +     *
 328.646 +     * @param   buf the data to be written
 328.647 +     * @throws  IOException If an I/O error has occurred.
 328.648 +     */
 328.649 +    public void write(byte[] buf) throws IOException {
 328.650 +        bout.write(buf, 0, buf.length, false);
 328.651 +    }
 328.652 +
 328.653 +    /**
 328.654 +     * Writes a sub array of bytes.
 328.655 +     *
 328.656 +     * @param   buf the data to be written
 328.657 +     * @param   off the start offset in the data
 328.658 +     * @param   len the number of bytes that are written
 328.659 +     * @throws  IOException If an I/O error has occurred.
 328.660 +     */
 328.661 +    public void write(byte[] buf, int off, int len) throws IOException {
 328.662 +        if (buf == null) {
 328.663 +            throw new NullPointerException();
 328.664 +        }
 328.665 +        int endoff = off + len;
 328.666 +        if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
 328.667 +            throw new IndexOutOfBoundsException();
 328.668 +        }
 328.669 +        bout.write(buf, off, len, false);
 328.670 +    }
 328.671 +
 328.672 +    /**
 328.673 +     * Flushes the stream. This will write any buffered output bytes and flush
 328.674 +     * through to the underlying stream.
 328.675 +     *
 328.676 +     * @throws  IOException If an I/O error has occurred.
 328.677 +     */
 328.678 +    public void flush() throws IOException {
 328.679 +        bout.flush();
 328.680 +    }
 328.681 +
 328.682 +    /**
 328.683 +     * Drain any buffered data in ObjectOutputStream.  Similar to flush but
 328.684 +     * does not propagate the flush to the underlying stream.
 328.685 +     *
 328.686 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.687 +     *          stream
 328.688 +     */
 328.689 +    protected void drain() throws IOException {
 328.690 +        bout.drain();
 328.691 +    }
 328.692 +
 328.693 +    /**
 328.694 +     * Closes the stream. This method must be called to release any resources
 328.695 +     * associated with the stream.
 328.696 +     *
 328.697 +     * @throws  IOException If an I/O error has occurred.
 328.698 +     */
 328.699 +    public void close() throws IOException {
 328.700 +        flush();
 328.701 +        clear();
 328.702 +        bout.close();
 328.703 +    }
 328.704 +
 328.705 +    /**
 328.706 +     * Writes a boolean.
 328.707 +     *
 328.708 +     * @param   val the boolean to be written
 328.709 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.710 +     *          stream
 328.711 +     */
 328.712 +    public void writeBoolean(boolean val) throws IOException {
 328.713 +        bout.writeBoolean(val);
 328.714 +    }
 328.715 +
 328.716 +    /**
 328.717 +     * Writes an 8 bit byte.
 328.718 +     *
 328.719 +     * @param   val the byte value to be written
 328.720 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.721 +     *          stream
 328.722 +     */
 328.723 +    public void writeByte(int val) throws IOException  {
 328.724 +        bout.writeByte(val);
 328.725 +    }
 328.726 +
 328.727 +    /**
 328.728 +     * Writes a 16 bit short.
 328.729 +     *
 328.730 +     * @param   val the short value to be written
 328.731 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.732 +     *          stream
 328.733 +     */
 328.734 +    public void writeShort(int val)  throws IOException {
 328.735 +        bout.writeShort(val);
 328.736 +    }
 328.737 +
 328.738 +    /**
 328.739 +     * Writes a 16 bit char.
 328.740 +     *
 328.741 +     * @param   val the char value to be written
 328.742 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.743 +     *          stream
 328.744 +     */
 328.745 +    public void writeChar(int val)  throws IOException {
 328.746 +        bout.writeChar(val);
 328.747 +    }
 328.748 +
 328.749 +    /**
 328.750 +     * Writes a 32 bit int.
 328.751 +     *
 328.752 +     * @param   val the integer value to be written
 328.753 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.754 +     *          stream
 328.755 +     */
 328.756 +    public void writeInt(int val)  throws IOException {
 328.757 +        bout.writeInt(val);
 328.758 +    }
 328.759 +
 328.760 +    /**
 328.761 +     * Writes a 64 bit long.
 328.762 +     *
 328.763 +     * @param   val the long value to be written
 328.764 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.765 +     *          stream
 328.766 +     */
 328.767 +    public void writeLong(long val)  throws IOException {
 328.768 +        bout.writeLong(val);
 328.769 +    }
 328.770 +
 328.771 +    /**
 328.772 +     * Writes a 32 bit float.
 328.773 +     *
 328.774 +     * @param   val the float value to be written
 328.775 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.776 +     *          stream
 328.777 +     */
 328.778 +    public void writeFloat(float val) throws IOException {
 328.779 +        bout.writeFloat(val);
 328.780 +    }
 328.781 +
 328.782 +    /**
 328.783 +     * Writes a 64 bit double.
 328.784 +     *
 328.785 +     * @param   val the double value to be written
 328.786 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.787 +     *          stream
 328.788 +     */
 328.789 +    public void writeDouble(double val) throws IOException {
 328.790 +        bout.writeDouble(val);
 328.791 +    }
 328.792 +
 328.793 +    /**
 328.794 +     * Writes a String as a sequence of bytes.
 328.795 +     *
 328.796 +     * @param   str the String of bytes to be written
 328.797 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.798 +     *          stream
 328.799 +     */
 328.800 +    public void writeBytes(String str) throws IOException {
 328.801 +        bout.writeBytes(str);
 328.802 +    }
 328.803 +
 328.804 +    /**
 328.805 +     * Writes a String as a sequence of chars.
 328.806 +     *
 328.807 +     * @param   str the String of chars to be written
 328.808 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.809 +     *          stream
 328.810 +     */
 328.811 +    public void writeChars(String str) throws IOException {
 328.812 +        bout.writeChars(str);
 328.813 +    }
 328.814 +
 328.815 +    /**
 328.816 +     * Primitive data write of this String in
 328.817 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
 328.818 +     * format.  Note that there is a
 328.819 +     * significant difference between writing a String into the stream as
 328.820 +     * primitive data or as an Object. A String instance written by writeObject
 328.821 +     * is written into the stream as a String initially. Future writeObject()
 328.822 +     * calls write references to the string into the stream.
 328.823 +     *
 328.824 +     * @param   str the String to be written
 328.825 +     * @throws  IOException if I/O errors occur while writing to the underlying
 328.826 +     *          stream
 328.827 +     */
 328.828 +    public void writeUTF(String str) throws IOException {
 328.829 +        bout.writeUTF(str);
 328.830 +    }
 328.831 +
 328.832 +    /**
 328.833 +     * Provide programmatic access to the persistent fields to be written
 328.834 +     * to ObjectOutput.
 328.835 +     *
 328.836 +     * @since 1.2
 328.837 +     */
 328.838 +    public static abstract class PutField {
 328.839 +
 328.840 +        /**
 328.841 +         * Put the value of the named boolean field into the persistent field.
 328.842 +         *
 328.843 +         * @param  name the name of the serializable field
 328.844 +         * @param  val the value to assign to the field
 328.845 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.846 +         * match the name of a serializable field for the class whose fields
 328.847 +         * are being written, or if the type of the named field is not
 328.848 +         * <code>boolean</code>
 328.849 +         */
 328.850 +        public abstract void put(String name, boolean val);
 328.851 +
 328.852 +        /**
 328.853 +         * Put the value of the named byte field into the persistent field.
 328.854 +         *
 328.855 +         * @param  name the name of the serializable field
 328.856 +         * @param  val the value to assign to the field
 328.857 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.858 +         * match the name of a serializable field for the class whose fields
 328.859 +         * are being written, or if the type of the named field is not
 328.860 +         * <code>byte</code>
 328.861 +         */
 328.862 +        public abstract void put(String name, byte val);
 328.863 +
 328.864 +        /**
 328.865 +         * Put the value of the named char field into the persistent field.
 328.866 +         *
 328.867 +         * @param  name the name of the serializable field
 328.868 +         * @param  val the value to assign to the field
 328.869 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.870 +         * match the name of a serializable field for the class whose fields
 328.871 +         * are being written, or if the type of the named field is not
 328.872 +         * <code>char</code>
 328.873 +         */
 328.874 +        public abstract void put(String name, char val);
 328.875 +
 328.876 +        /**
 328.877 +         * Put the value of the named short field into the persistent field.
 328.878 +         *
 328.879 +         * @param  name the name of the serializable field
 328.880 +         * @param  val the value to assign to the field
 328.881 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.882 +         * match the name of a serializable field for the class whose fields
 328.883 +         * are being written, or if the type of the named field is not
 328.884 +         * <code>short</code>
 328.885 +         */
 328.886 +        public abstract void put(String name, short val);
 328.887 +
 328.888 +        /**
 328.889 +         * Put the value of the named int field into the persistent field.
 328.890 +         *
 328.891 +         * @param  name the name of the serializable field
 328.892 +         * @param  val the value to assign to the field
 328.893 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.894 +         * match the name of a serializable field for the class whose fields
 328.895 +         * are being written, or if the type of the named field is not
 328.896 +         * <code>int</code>
 328.897 +         */
 328.898 +        public abstract void put(String name, int val);
 328.899 +
 328.900 +        /**
 328.901 +         * Put the value of the named long field into the persistent field.
 328.902 +         *
 328.903 +         * @param  name the name of the serializable field
 328.904 +         * @param  val the value to assign to the field
 328.905 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.906 +         * match the name of a serializable field for the class whose fields
 328.907 +         * are being written, or if the type of the named field is not
 328.908 +         * <code>long</code>
 328.909 +         */
 328.910 +        public abstract void put(String name, long val);
 328.911 +
 328.912 +        /**
 328.913 +         * Put the value of the named float field into the persistent field.
 328.914 +         *
 328.915 +         * @param  name the name of the serializable field
 328.916 +         * @param  val the value to assign to the field
 328.917 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.918 +         * match the name of a serializable field for the class whose fields
 328.919 +         * are being written, or if the type of the named field is not
 328.920 +         * <code>float</code>
 328.921 +         */
 328.922 +        public abstract void put(String name, float val);
 328.923 +
 328.924 +        /**
 328.925 +         * Put the value of the named double field into the persistent field.
 328.926 +         *
 328.927 +         * @param  name the name of the serializable field
 328.928 +         * @param  val the value to assign to the field
 328.929 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.930 +         * match the name of a serializable field for the class whose fields
 328.931 +         * are being written, or if the type of the named field is not
 328.932 +         * <code>double</code>
 328.933 +         */
 328.934 +        public abstract void put(String name, double val);
 328.935 +
 328.936 +        /**
 328.937 +         * Put the value of the named Object field into the persistent field.
 328.938 +         *
 328.939 +         * @param  name the name of the serializable field
 328.940 +         * @param  val the value to assign to the field
 328.941 +         *         (which may be <code>null</code>)
 328.942 +         * @throws IllegalArgumentException if <code>name</code> does not
 328.943 +         * match the name of a serializable field for the class whose fields
 328.944 +         * are being written, or if the type of the named field is not a
 328.945 +         * reference type
 328.946 +         */
 328.947 +        public abstract void put(String name, Object val);
 328.948 +
 328.949 +        /**
 328.950 +         * Write the data and fields to the specified ObjectOutput stream,
 328.951 +         * which must be the same stream that produced this
 328.952 +         * <code>PutField</code> object.
 328.953 +         *
 328.954 +         * @param  out the stream to write the data and fields to
 328.955 +         * @throws IOException if I/O errors occur while writing to the
 328.956 +         *         underlying stream
 328.957 +         * @throws IllegalArgumentException if the specified stream is not
 328.958 +         *         the same stream that produced this <code>PutField</code>
 328.959 +         *         object
 328.960 +         * @deprecated This method does not write the values contained by this
 328.961 +         *         <code>PutField</code> object in a proper format, and may
 328.962 +         *         result in corruption of the serialization stream.  The
 328.963 +         *         correct way to write <code>PutField</code> data is by
 328.964 +         *         calling the {@link java.io.ObjectOutputStream#writeFields()}
 328.965 +         *         method.
 328.966 +         */
 328.967 +        @Deprecated
 328.968 +        public abstract void write(ObjectOutput out) throws IOException;
 328.969 +    }
 328.970 +
 328.971 +
 328.972 +    /**
 328.973 +     * Returns protocol version in use.
 328.974 +     */
 328.975 +    int getProtocolVersion() {
 328.976 +        return protocol;
 328.977 +    }
 328.978 +
 328.979 +    /**
 328.980 +     * Writes string without allowing it to be replaced in stream.  Used by
 328.981 +     * ObjectStreamClass to write class descriptor type strings.
 328.982 +     */
 328.983 +    void writeTypeString(String str) throws IOException {
 328.984 +        int handle;
 328.985 +        if (str == null) {
 328.986 +            writeNull();
 328.987 +        } else if ((handle = handles.lookup(str)) != -1) {
 328.988 +            writeHandle(handle);
 328.989 +        } else {
 328.990 +            writeString(str, false);
 328.991 +        }
 328.992 +    }
 328.993 +
 328.994 +    /**
 328.995 +     * Verifies that this (possibly subclass) instance can be constructed
 328.996 +     * without violating security constraints: the subclass must not override
 328.997 +     * security-sensitive non-final methods, or else the
 328.998 +     * "enableSubclassImplementation" SerializablePermission is checked.
 328.999 +     */
328.1000 +    private void verifySubclass() {
328.1001 +        Class cl = getClass();
328.1002 +        if (cl == ObjectOutputStream.class) {
328.1003 +            return;
328.1004 +        }
328.1005 +        throw new SecurityException();
328.1006 +    }
328.1007 +
328.1008 +    /**
328.1009 +     * Clears internal data structures.
328.1010 +     */
328.1011 +    private void clear() {
328.1012 +        subs.clear();
328.1013 +        handles.clear();
328.1014 +    }
328.1015 +
328.1016 +    /**
328.1017 +     * Underlying writeObject/writeUnshared implementation.
328.1018 +     */
328.1019 +    private void writeObject0(Object obj, boolean unshared)
328.1020 +        throws IOException
328.1021 +    {
328.1022 +        boolean oldMode = bout.setBlockDataMode(false);
328.1023 +        depth++;
328.1024 +        try {
328.1025 +            // handle previously written and non-replaceable objects
328.1026 +            int h;
328.1027 +            if ((obj = subs.lookup(obj)) == null) {
328.1028 +                writeNull();
328.1029 +                return;
328.1030 +            } else if (!unshared && (h = handles.lookup(obj)) != -1) {
328.1031 +                writeHandle(h);
328.1032 +                return;
328.1033 +            } else if (obj instanceof Class) {
328.1034 +                writeClass((Class) obj, unshared);
328.1035 +                return;
328.1036 +            } else if (obj instanceof ObjectStreamClass) {
328.1037 +                writeClassDesc((ObjectStreamClass) obj, unshared);
328.1038 +                return;
328.1039 +            }
328.1040 +
328.1041 +            // check for replacement object
328.1042 +            Object orig = obj;
328.1043 +            Class cl = obj.getClass();
328.1044 +            ObjectStreamClass desc;
328.1045 +            for (;;) {
328.1046 +                // REMIND: skip this check for strings/arrays?
328.1047 +                Class repCl;
328.1048 +                desc = ObjectStreamClass.lookup(cl, true);
328.1049 +                if (!desc.hasWriteReplaceMethod() ||
328.1050 +                    (obj = desc.invokeWriteReplace(obj)) == null ||
328.1051 +                    (repCl = obj.getClass()) == cl)
328.1052 +                {
328.1053 +                    break;
328.1054 +                }
328.1055 +                cl = repCl;
328.1056 +            }
328.1057 +            if (enableReplace) {
328.1058 +                Object rep = replaceObject(obj);
328.1059 +                if (rep != obj && rep != null) {
328.1060 +                    cl = rep.getClass();
328.1061 +                    desc = ObjectStreamClass.lookup(cl, true);
328.1062 +                }
328.1063 +                obj = rep;
328.1064 +            }
328.1065 +
328.1066 +            // if object replaced, run through original checks a second time
328.1067 +            if (obj != orig) {
328.1068 +                subs.assign(orig, obj);
328.1069 +                if (obj == null) {
328.1070 +                    writeNull();
328.1071 +                    return;
328.1072 +                } else if (!unshared && (h = handles.lookup(obj)) != -1) {
328.1073 +                    writeHandle(h);
328.1074 +                    return;
328.1075 +                } else if (obj instanceof Class) {
328.1076 +                    writeClass((Class) obj, unshared);
328.1077 +                    return;
328.1078 +                } else if (obj instanceof ObjectStreamClass) {
328.1079 +                    writeClassDesc((ObjectStreamClass) obj, unshared);
328.1080 +                    return;
328.1081 +                }
328.1082 +            }
328.1083 +
328.1084 +            // remaining cases
328.1085 +            if (obj instanceof String) {
328.1086 +                writeString((String) obj, unshared);
328.1087 +            } else if (cl.isArray()) {
328.1088 +                writeArray(obj, desc, unshared);
328.1089 +            } else if (obj instanceof Enum) {
328.1090 +                writeEnum((Enum) obj, desc, unshared);
328.1091 +            } else if (obj instanceof Serializable) {
328.1092 +                writeOrdinaryObject(obj, desc, unshared);
328.1093 +            } else {
328.1094 +                if (extendedDebugInfo) {
328.1095 +                    throw new NotSerializableException(
328.1096 +                        cl.getName() + "\n" + debugInfoStack.toString());
328.1097 +                } else {
328.1098 +                    throw new NotSerializableException(cl.getName());
328.1099 +                }
328.1100 +            }
328.1101 +        } finally {
328.1102 +            depth--;
328.1103 +            bout.setBlockDataMode(oldMode);
328.1104 +        }
328.1105 +    }
328.1106 +
328.1107 +    /**
328.1108 +     * Writes null code to stream.
328.1109 +     */
328.1110 +    private void writeNull() throws IOException {
328.1111 +        bout.writeByte(TC_NULL);
328.1112 +    }
328.1113 +
328.1114 +    /**
328.1115 +     * Writes given object handle to stream.
328.1116 +     */
328.1117 +    private void writeHandle(int handle) throws IOException {
328.1118 +        bout.writeByte(TC_REFERENCE);
328.1119 +        bout.writeInt(baseWireHandle + handle);
328.1120 +    }
328.1121 +
328.1122 +    /**
328.1123 +     * Writes representation of given class to stream.
328.1124 +     */
328.1125 +    private void writeClass(Class cl, boolean unshared) throws IOException {
328.1126 +        bout.writeByte(TC_CLASS);
328.1127 +        writeClassDesc(ObjectStreamClass.lookup(cl, true), false);
328.1128 +        handles.assign(unshared ? null : cl);
328.1129 +    }
328.1130 +
328.1131 +    /**
328.1132 +     * Writes representation of given class descriptor to stream.
328.1133 +     */
328.1134 +    private void writeClassDesc(ObjectStreamClass desc, boolean unshared)
328.1135 +        throws IOException
328.1136 +    {
328.1137 +        int handle;
328.1138 +        if (desc == null) {
328.1139 +            writeNull();
328.1140 +        } else if (!unshared && (handle = handles.lookup(desc)) != -1) {
328.1141 +            writeHandle(handle);
328.1142 +        } else if (desc.isProxy()) {
328.1143 +            writeProxyDesc(desc, unshared);
328.1144 +        } else {
328.1145 +            writeNonProxyDesc(desc, unshared);
328.1146 +        }
328.1147 +    }
328.1148 +
328.1149 +    /**
328.1150 +     * Writes class descriptor representing a dynamic proxy class to stream.
328.1151 +     */
328.1152 +    private void writeProxyDesc(ObjectStreamClass desc, boolean unshared)
328.1153 +        throws IOException
328.1154 +    {
328.1155 +        bout.writeByte(TC_PROXYCLASSDESC);
328.1156 +        handles.assign(unshared ? null : desc);
328.1157 +
328.1158 +        Class cl = desc.forClass();
328.1159 +        Class[] ifaces = cl.getInterfaces();
328.1160 +        bout.writeInt(ifaces.length);
328.1161 +        for (int i = 0; i < ifaces.length; i++) {
328.1162 +            bout.writeUTF(ifaces[i].getName());
328.1163 +        }
328.1164 +
328.1165 +        bout.setBlockDataMode(true);
328.1166 +        annotateProxyClass(cl);
328.1167 +        bout.setBlockDataMode(false);
328.1168 +        bout.writeByte(TC_ENDBLOCKDATA);
328.1169 +
328.1170 +        writeClassDesc(desc.getSuperDesc(), false);
328.1171 +    }
328.1172 +
328.1173 +    /**
328.1174 +     * Writes class descriptor representing a standard (i.e., not a dynamic
328.1175 +     * proxy) class to stream.
328.1176 +     */
328.1177 +    private void writeNonProxyDesc(ObjectStreamClass desc, boolean unshared)
328.1178 +        throws IOException
328.1179 +    {
328.1180 +        bout.writeByte(TC_CLASSDESC);
328.1181 +        handles.assign(unshared ? null : desc);
328.1182 +
328.1183 +        if (protocol == PROTOCOL_VERSION_1) {
328.1184 +            // do not invoke class descriptor write hook with old protocol
328.1185 +            desc.writeNonProxy(this);
328.1186 +        } else {
328.1187 +            writeClassDescriptor(desc);
328.1188 +        }
328.1189 +
328.1190 +        Class cl = desc.forClass();
328.1191 +        bout.setBlockDataMode(true);
328.1192 +        annotateClass(cl);
328.1193 +        bout.setBlockDataMode(false);
328.1194 +        bout.writeByte(TC_ENDBLOCKDATA);
328.1195 +
328.1196 +        writeClassDesc(desc.getSuperDesc(), false);
328.1197 +    }
328.1198 +
328.1199 +    /**
328.1200 +     * Writes given string to stream, using standard or long UTF format
328.1201 +     * depending on string length.
328.1202 +     */
328.1203 +    private void writeString(String str, boolean unshared) throws IOException {
328.1204 +        handles.assign(unshared ? null : str);
328.1205 +        long utflen = bout.getUTFLength(str);
328.1206 +        if (utflen <= 0xFFFF) {
328.1207 +            bout.writeByte(TC_STRING);
328.1208 +            bout.writeUTF(str, utflen);
328.1209 +        } else {
328.1210 +            bout.writeByte(TC_LONGSTRING);
328.1211 +            bout.writeLongUTF(str, utflen);
328.1212 +        }
328.1213 +    }
328.1214 +
328.1215 +    /**
328.1216 +     * Writes given array object to stream.
328.1217 +     */
328.1218 +    private void writeArray(Object array,
328.1219 +                            ObjectStreamClass desc,
328.1220 +                            boolean unshared)
328.1221 +        throws IOException
328.1222 +    {
328.1223 +        bout.writeByte(TC_ARRAY);
328.1224 +        writeClassDesc(desc, false);
328.1225 +        handles.assign(unshared ? null : array);
328.1226 +
328.1227 +        Class ccl = desc.forClass().getComponentType();
328.1228 +        if (ccl.isPrimitive()) {
328.1229 +            if (ccl == Integer.TYPE) {
328.1230 +                int[] ia = (int[]) array;
328.1231 +                bout.writeInt(ia.length);
328.1232 +                bout.writeInts(ia, 0, ia.length);
328.1233 +            } else if (ccl == Byte.TYPE) {
328.1234 +                byte[] ba = (byte[]) array;
328.1235 +                bout.writeInt(ba.length);
328.1236 +                bout.write(ba, 0, ba.length, true);
328.1237 +            } else if (ccl == Long.TYPE) {
328.1238 +                long[] ja = (long[]) array;
328.1239 +                bout.writeInt(ja.length);
328.1240 +                bout.writeLongs(ja, 0, ja.length);
328.1241 +            } else if (ccl == Float.TYPE) {
328.1242 +                float[] fa = (float[]) array;
328.1243 +                bout.writeInt(fa.length);
328.1244 +                bout.writeFloats(fa, 0, fa.length);
328.1245 +            } else if (ccl == Double.TYPE) {
328.1246 +                double[] da = (double[]) array;
328.1247 +                bout.writeInt(da.length);
328.1248 +                bout.writeDoubles(da, 0, da.length);
328.1249 +            } else if (ccl == Short.TYPE) {
328.1250 +                short[] sa = (short[]) array;
328.1251 +                bout.writeInt(sa.length);
328.1252 +                bout.writeShorts(sa, 0, sa.length);
328.1253 +            } else if (ccl == Character.TYPE) {
328.1254 +                char[] ca = (char[]) array;
328.1255 +                bout.writeInt(ca.length);
328.1256 +                bout.writeChars(ca, 0, ca.length);
328.1257 +            } else if (ccl == Boolean.TYPE) {
328.1258 +                boolean[] za = (boolean[]) array;
328.1259 +                bout.writeInt(za.length);
328.1260 +                bout.writeBooleans(za, 0, za.length);
328.1261 +            } else {
328.1262 +                throw new InternalError();
328.1263 +            }
328.1264 +        } else {
328.1265 +            Object[] objs = (Object[]) array;
328.1266 +            int len = objs.length;
328.1267 +            bout.writeInt(len);
328.1268 +            if (extendedDebugInfo) {
328.1269 +                debugInfoStack.push(
328.1270 +                    "array (class \"" + array.getClass().getName() +
328.1271 +                    "\", size: " + len  + ")");
328.1272 +            }
328.1273 +            try {
328.1274 +                for (int i = 0; i < len; i++) {
328.1275 +                    if (extendedDebugInfo) {
328.1276 +                        debugInfoStack.push(
328.1277 +                            "element of array (index: " + i + ")");
328.1278 +                    }
328.1279 +                    try {
328.1280 +                        writeObject0(objs[i], false);
328.1281 +                    } finally {
328.1282 +                        if (extendedDebugInfo) {
328.1283 +                            debugInfoStack.pop();
328.1284 +                        }
328.1285 +                    }
328.1286 +                }
328.1287 +            } finally {
328.1288 +                if (extendedDebugInfo) {
328.1289 +                    debugInfoStack.pop();
328.1290 +                }
328.1291 +            }
328.1292 +        }
328.1293 +    }
328.1294 +
328.1295 +    /**
328.1296 +     * Writes given enum constant to stream.
328.1297 +     */
328.1298 +    private void writeEnum(Enum en,
328.1299 +                           ObjectStreamClass desc,
328.1300 +                           boolean unshared)
328.1301 +        throws IOException
328.1302 +    {
328.1303 +        bout.writeByte(TC_ENUM);
328.1304 +        ObjectStreamClass sdesc = desc.getSuperDesc();
328.1305 +        writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false);
328.1306 +        handles.assign(unshared ? null : en);
328.1307 +        writeString(en.name(), false);
328.1308 +    }
328.1309 +
328.1310 +    /**
328.1311 +     * Writes representation of a "ordinary" (i.e., not a String, Class,
328.1312 +     * ObjectStreamClass, array, or enum constant) serializable object to the
328.1313 +     * stream.
328.1314 +     */
328.1315 +    private void writeOrdinaryObject(Object obj,
328.1316 +                                     ObjectStreamClass desc,
328.1317 +                                     boolean unshared)
328.1318 +        throws IOException
328.1319 +    {
328.1320 +        if (extendedDebugInfo) {
328.1321 +            debugInfoStack.push(
328.1322 +                (depth == 1 ? "root " : "") + "object (class \"" +
328.1323 +                obj.getClass().getName() + "\", " + obj.toString() + ")");
328.1324 +        }
328.1325 +        try {
328.1326 +            desc.checkSerialize();
328.1327 +
328.1328 +            bout.writeByte(TC_OBJECT);
328.1329 +            writeClassDesc(desc, false);
328.1330 +            handles.assign(unshared ? null : obj);
328.1331 +            if (desc.isExternalizable() && !desc.isProxy()) {
328.1332 +                writeExternalData((Externalizable) obj);
328.1333 +            } else {
328.1334 +                writeSerialData(obj, desc);
328.1335 +            }
328.1336 +        } finally {
328.1337 +            if (extendedDebugInfo) {
328.1338 +                debugInfoStack.pop();
328.1339 +            }
328.1340 +        }
328.1341 +    }
328.1342 +
328.1343 +    /**
328.1344 +     * Writes externalizable data of given object by invoking its
328.1345 +     * writeExternal() method.
328.1346 +     */
328.1347 +    private void writeExternalData(Externalizable obj) throws IOException {
328.1348 +        PutFieldImpl oldPut = curPut;
328.1349 +        curPut = null;
328.1350 +
328.1351 +        if (extendedDebugInfo) {
328.1352 +            debugInfoStack.push("writeExternal data");
328.1353 +        }
328.1354 +        Object oldContext = curContext;
328.1355 +        try {
328.1356 +            curContext = null;
328.1357 +            if (protocol == PROTOCOL_VERSION_1) {
328.1358 +                obj.writeExternal(this);
328.1359 +            } else {
328.1360 +                bout.setBlockDataMode(true);
328.1361 +                obj.writeExternal(this);
328.1362 +                bout.setBlockDataMode(false);
328.1363 +                bout.writeByte(TC_ENDBLOCKDATA);
328.1364 +            }
328.1365 +        } finally {
328.1366 +            curContext = oldContext;
328.1367 +            if (extendedDebugInfo) {
328.1368 +                debugInfoStack.pop();
328.1369 +            }
328.1370 +        }
328.1371 +
328.1372 +        curPut = oldPut;
328.1373 +    }
328.1374 +
328.1375 +    /**
328.1376 +     * Writes instance data for each serializable class of given object, from
328.1377 +     * superclass to subclass.
328.1378 +     */
328.1379 +    private void writeSerialData(Object obj, ObjectStreamClass desc)
328.1380 +        throws IOException
328.1381 +    {
328.1382 +        ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
328.1383 +        for (int i = 0; i < slots.length; i++) {
328.1384 +            ObjectStreamClass slotDesc = slots[i].desc;
328.1385 +            if (slotDesc.hasWriteObjectMethod()) {
328.1386 +                PutFieldImpl oldPut = curPut;
328.1387 +                curPut = null;
328.1388 +                Object oldContext = curContext;
328.1389 +
328.1390 +                if (extendedDebugInfo) {
328.1391 +                    debugInfoStack.push(
328.1392 +                        "custom writeObject data (class \"" +
328.1393 +                        slotDesc.getName() + "\")");
328.1394 +                }
328.1395 +                try {
328.1396 +                    curContext = new Object(); //new SerialCallbackContext(obj, slotDesc);
328.1397 +                    bout.setBlockDataMode(true);
328.1398 +                    slotDesc.invokeWriteObject(obj, this);
328.1399 +                    bout.setBlockDataMode(false);
328.1400 +                    bout.writeByte(TC_ENDBLOCKDATA);
328.1401 +                } finally {
328.1402 +                    //curContext.setUsed();
328.1403 +                    curContext = oldContext;
328.1404 +                    if (extendedDebugInfo) {
328.1405 +                        debugInfoStack.pop();
328.1406 +                    }
328.1407 +                }
328.1408 +
328.1409 +                curPut = oldPut;
328.1410 +            } else {
328.1411 +                defaultWriteFields(obj, slotDesc);
328.1412 +            }
328.1413 +        }
328.1414 +    }
328.1415 +
328.1416 +    /**
328.1417 +     * Fetches and writes values of serializable fields of given object to
328.1418 +     * stream.  The given class descriptor specifies which field values to
328.1419 +     * write, and in which order they should be written.
328.1420 +     */
328.1421 +    private void defaultWriteFields(Object obj, ObjectStreamClass desc)
328.1422 +        throws IOException
328.1423 +    {
328.1424 +        // REMIND: perform conservative isInstance check here?
328.1425 +        desc.checkDefaultSerialize();
328.1426 +
328.1427 +        int primDataSize = desc.getPrimDataSize();
328.1428 +        if (primVals == null || primVals.length < primDataSize) {
328.1429 +            primVals = new byte[primDataSize];
328.1430 +        }
328.1431 +        desc.getPrimFieldValues(obj, primVals);
328.1432 +        bout.write(primVals, 0, primDataSize, false);
328.1433 +
328.1434 +        ObjectStreamField[] fields = desc.getFields(false);
328.1435 +        Object[] objVals = new Object[desc.getNumObjFields()];
328.1436 +        int numPrimFields = fields.length - objVals.length;
328.1437 +        desc.getObjFieldValues(obj, objVals);
328.1438 +        for (int i = 0; i < objVals.length; i++) {
328.1439 +            if (extendedDebugInfo) {
328.1440 +                debugInfoStack.push(
328.1441 +                    "field (class \"" + desc.getName() + "\", name: \"" +
328.1442 +                    fields[numPrimFields + i].getName() + "\", type: \"" +
328.1443 +                    fields[numPrimFields + i].getType() + "\")");
328.1444 +            }
328.1445 +            try {
328.1446 +                writeObject0(objVals[i],
328.1447 +                             fields[numPrimFields + i].isUnshared());
328.1448 +            } finally {
328.1449 +                if (extendedDebugInfo) {
328.1450 +                    debugInfoStack.pop();
328.1451 +                }
328.1452 +            }
328.1453 +        }
328.1454 +    }
328.1455 +
328.1456 +    /**
328.1457 +     * Attempts to write to stream fatal IOException that has caused
328.1458 +     * serialization to abort.
328.1459 +     */
328.1460 +    private void writeFatalException(IOException ex) throws IOException {
328.1461 +        /*
328.1462 +         * Note: the serialization specification states that if a second
328.1463 +         * IOException occurs while attempting to serialize the original fatal
328.1464 +         * exception to the stream, then a StreamCorruptedException should be
328.1465 +         * thrown (section 2.1).  However, due to a bug in previous
328.1466 +         * implementations of serialization, StreamCorruptedExceptions were
328.1467 +         * rarely (if ever) actually thrown--the "root" exceptions from
328.1468 +         * underlying streams were thrown instead.  This historical behavior is
328.1469 +         * followed here for consistency.
328.1470 +         */
328.1471 +        clear();
328.1472 +        boolean oldMode = bout.setBlockDataMode(false);
328.1473 +        try {
328.1474 +            bout.writeByte(TC_EXCEPTION);
328.1475 +            writeObject0(ex, false);
328.1476 +            clear();
328.1477 +        } finally {
328.1478 +            bout.setBlockDataMode(oldMode);
328.1479 +        }
328.1480 +    }
328.1481 +
328.1482 +    /**
328.1483 +     * Converts specified span of float values into byte values.
328.1484 +     */
328.1485 +    // REMIND: remove once hotspot inlines Float.floatToIntBits
328.1486 +    private static native void floatsToBytes(float[] src, int srcpos,
328.1487 +                                             byte[] dst, int dstpos,
328.1488 +                                             int nfloats);
328.1489 +
328.1490 +    /**
328.1491 +     * Converts specified span of double values into byte values.
328.1492 +     */
328.1493 +    // REMIND: remove once hotspot inlines Double.doubleToLongBits
328.1494 +    private static native void doublesToBytes(double[] src, int srcpos,
328.1495 +                                              byte[] dst, int dstpos,
328.1496 +                                              int ndoubles);
328.1497 +
328.1498 +    /**
328.1499 +     * Default PutField implementation.
328.1500 +     */
328.1501 +    private class PutFieldImpl extends PutField {
328.1502 +
328.1503 +        /** class descriptor describing serializable fields */
328.1504 +        private final ObjectStreamClass desc;
328.1505 +        /** primitive field values */
328.1506 +        private final byte[] primVals;
328.1507 +        /** object field values */
328.1508 +        private final Object[] objVals;
328.1509 +
328.1510 +        /**
328.1511 +         * Creates PutFieldImpl object for writing fields defined in given
328.1512 +         * class descriptor.
328.1513 +         */
328.1514 +        PutFieldImpl(ObjectStreamClass desc) {
328.1515 +            this.desc = desc;
328.1516 +            primVals = new byte[desc.getPrimDataSize()];
328.1517 +            objVals = new Object[desc.getNumObjFields()];
328.1518 +        }
328.1519 +
328.1520 +        public void put(String name, boolean val) {
328.1521 +            Bits.putBoolean(primVals, getFieldOffset(name, Boolean.TYPE), val);
328.1522 +        }
328.1523 +
328.1524 +        public void put(String name, byte val) {
328.1525 +            primVals[getFieldOffset(name, Byte.TYPE)] = val;
328.1526 +        }
328.1527 +
328.1528 +        public void put(String name, char val) {
328.1529 +            Bits.putChar(primVals, getFieldOffset(name, Character.TYPE), val);
328.1530 +        }
328.1531 +
328.1532 +        public void put(String name, short val) {
328.1533 +            Bits.putShort(primVals, getFieldOffset(name, Short.TYPE), val);
328.1534 +        }
328.1535 +
328.1536 +        public void put(String name, int val) {
328.1537 +            Bits.putInt(primVals, getFieldOffset(name, Integer.TYPE), val);
328.1538 +        }
328.1539 +
328.1540 +        public void put(String name, float val) {
328.1541 +            Bits.putFloat(primVals, getFieldOffset(name, Float.TYPE), val);
328.1542 +        }
328.1543 +
328.1544 +        public void put(String name, long val) {
328.1545 +            Bits.putLong(primVals, getFieldOffset(name, Long.TYPE), val);
328.1546 +        }
328.1547 +
328.1548 +        public void put(String name, double val) {
328.1549 +            Bits.putDouble(primVals, getFieldOffset(name, Double.TYPE), val);
328.1550 +        }
328.1551 +
328.1552 +        public void put(String name, Object val) {
328.1553 +            objVals[getFieldOffset(name, Object.class)] = val;
328.1554 +        }
328.1555 +
328.1556 +        // deprecated in ObjectOutputStream.PutField
328.1557 +        public void write(ObjectOutput out) throws IOException {
328.1558 +            /*
328.1559 +             * Applications should *not* use this method to write PutField
328.1560 +             * data, as it will lead to stream corruption if the PutField
328.1561 +             * object writes any primitive data (since block data mode is not
328.1562 +             * unset/set properly, as is done in OOS.writeFields()).  This
328.1563 +             * broken implementation is being retained solely for behavioral
328.1564 +             * compatibility, in order to support applications which use
328.1565 +             * OOS.PutField.write() for writing only non-primitive data.
328.1566 +             *
328.1567 +             * Serialization of unshared objects is not implemented here since
328.1568 +             * it is not necessary for backwards compatibility; also, unshared
328.1569 +             * semantics may not be supported by the given ObjectOutput
328.1570 +             * instance.  Applications which write unshared objects using the
328.1571 +             * PutField API must use OOS.writeFields().
328.1572 +             */
328.1573 +            if (ObjectOutputStream.this != out) {
328.1574 +                throw new IllegalArgumentException("wrong stream");
328.1575 +            }
328.1576 +            out.write(primVals, 0, primVals.length);
328.1577 +
328.1578 +            ObjectStreamField[] fields = desc.getFields(false);
328.1579 +            int numPrimFields = fields.length - objVals.length;
328.1580 +            // REMIND: warn if numPrimFields > 0?
328.1581 +            for (int i = 0; i < objVals.length; i++) {
328.1582 +                if (fields[numPrimFields + i].isUnshared()) {
328.1583 +                    throw new IOException("cannot write unshared object");
328.1584 +                }
328.1585 +                out.writeObject(objVals[i]);
328.1586 +            }
328.1587 +        }
328.1588 +
328.1589 +        /**
328.1590 +         * Writes buffered primitive data and object fields to stream.
328.1591 +         */
328.1592 +        void writeFields() throws IOException {
328.1593 +            bout.write(primVals, 0, primVals.length, false);
328.1594 +
328.1595 +            ObjectStreamField[] fields = desc.getFields(false);
328.1596 +            int numPrimFields = fields.length - objVals.length;
328.1597 +            for (int i = 0; i < objVals.length; i++) {
328.1598 +                if (extendedDebugInfo) {
328.1599 +                    debugInfoStack.push(
328.1600 +                        "field (class \"" + desc.getName() + "\", name: \"" +
328.1601 +                        fields[numPrimFields + i].getName() + "\", type: \"" +
328.1602 +                        fields[numPrimFields + i].getType() + "\")");
328.1603 +                }
328.1604 +                try {
328.1605 +                    writeObject0(objVals[i],
328.1606 +                                 fields[numPrimFields + i].isUnshared());
328.1607 +                } finally {
328.1608 +                    if (extendedDebugInfo) {
328.1609 +                        debugInfoStack.pop();
328.1610 +                    }
328.1611 +                }
328.1612 +            }
328.1613 +        }
328.1614 +
328.1615 +        /**
328.1616 +         * Returns offset of field with given name and type.  A specified type
328.1617 +         * of null matches all types, Object.class matches all non-primitive
328.1618 +         * types, and any other non-null type matches assignable types only.
328.1619 +         * Throws IllegalArgumentException if no matching field found.
328.1620 +         */
328.1621 +        private int getFieldOffset(String name, Class type) {
328.1622 +            ObjectStreamField field = desc.getField(name, type);
328.1623 +            if (field == null) {
328.1624 +                throw new IllegalArgumentException("no such field " + name +
328.1625 +                                                   " with type " + type);
328.1626 +            }
328.1627 +            return field.getOffset();
328.1628 +        }
328.1629 +    }
328.1630 +
328.1631 +    /**
328.1632 +     * Buffered output stream with two modes: in default mode, outputs data in
328.1633 +     * same format as DataOutputStream; in "block data" mode, outputs data
328.1634 +     * bracketed by block data markers (see object serialization specification
328.1635 +     * for details).
328.1636 +     */
328.1637 +    private static class BlockDataOutputStream
328.1638 +        extends OutputStream implements DataOutput
328.1639 +    {
328.1640 +        /** maximum data block length */
328.1641 +        private static final int MAX_BLOCK_SIZE = 1024;
328.1642 +        /** maximum data block header length */
328.1643 +        private static final int MAX_HEADER_SIZE = 5;
328.1644 +        /** (tunable) length of char buffer (for writing strings) */
328.1645 +        private static final int CHAR_BUF_SIZE = 256;
328.1646 +
328.1647 +        /** buffer for writing general/block data */
328.1648 +        private final byte[] buf = new byte[MAX_BLOCK_SIZE];
328.1649 +        /** buffer for writing block data headers */
328.1650 +        private final byte[] hbuf = new byte[MAX_HEADER_SIZE];
328.1651 +        /** char buffer for fast string writes */
328.1652 +        private final char[] cbuf = new char[CHAR_BUF_SIZE];
328.1653 +
328.1654 +        /** block data mode */
328.1655 +        private boolean blkmode = false;
328.1656 +        /** current offset into buf */
328.1657 +        private int pos = 0;
328.1658 +
328.1659 +        /** underlying output stream */
328.1660 +        private final OutputStream out;
328.1661 +        /** loopback stream (for data writes that span data blocks) */
328.1662 +        private final DataOutputStream dout;
328.1663 +
328.1664 +        /**
328.1665 +         * Creates new BlockDataOutputStream on top of given underlying stream.
328.1666 +         * Block data mode is turned off by default.
328.1667 +         */
328.1668 +        BlockDataOutputStream(OutputStream out) {
328.1669 +            this.out = out;
328.1670 +            dout = new DataOutputStream(this);
328.1671 +        }
328.1672 +
328.1673 +        /**
328.1674 +         * Sets block data mode to the given mode (true == on, false == off)
328.1675 +         * and returns the previous mode value.  If the new mode is the same as
328.1676 +         * the old mode, no action is taken.  If the new mode differs from the
328.1677 +         * old mode, any buffered data is flushed before switching to the new
328.1678 +         * mode.
328.1679 +         */
328.1680 +        boolean setBlockDataMode(boolean mode) throws IOException {
328.1681 +            if (blkmode == mode) {
328.1682 +                return blkmode;
328.1683 +            }
328.1684 +            drain();
328.1685 +            blkmode = mode;
328.1686 +            return !blkmode;
328.1687 +        }
328.1688 +
328.1689 +        /**
328.1690 +         * Returns true if the stream is currently in block data mode, false
328.1691 +         * otherwise.
328.1692 +         */
328.1693 +        boolean getBlockDataMode() {
328.1694 +            return blkmode;
328.1695 +        }
328.1696 +
328.1697 +        /* ----------------- generic output stream methods ----------------- */
328.1698 +        /*
328.1699 +         * The following methods are equivalent to their counterparts in
328.1700 +         * OutputStream, except that they partition written data into data
328.1701 +         * blocks when in block data mode.
328.1702 +         */
328.1703 +
328.1704 +        public void write(int b) throws IOException {
328.1705 +            if (pos >= MAX_BLOCK_SIZE) {
328.1706 +                drain();
328.1707 +            }
328.1708 +            buf[pos++] = (byte) b;
328.1709 +        }
328.1710 +
328.1711 +        public void write(byte[] b) throws IOException {
328.1712 +            write(b, 0, b.length, false);
328.1713 +        }
328.1714 +
328.1715 +        public void write(byte[] b, int off, int len) throws IOException {
328.1716 +            write(b, off, len, false);
328.1717 +        }
328.1718 +
328.1719 +        public void flush() throws IOException {
328.1720 +            drain();
328.1721 +            out.flush();
328.1722 +        }
328.1723 +
328.1724 +        public void close() throws IOException {
328.1725 +            flush();
328.1726 +            out.close();
328.1727 +        }
328.1728 +
328.1729 +        /**
328.1730 +         * Writes specified span of byte values from given array.  If copy is
328.1731 +         * true, copies the values to an intermediate buffer before writing
328.1732 +         * them to underlying stream (to avoid exposing a reference to the
328.1733 +         * original byte array).
328.1734 +         */
328.1735 +        void write(byte[] b, int off, int len, boolean copy)
328.1736 +            throws IOException
328.1737 +        {
328.1738 +            if (!(copy || blkmode)) {           // write directly
328.1739 +                drain();
328.1740 +                out.write(b, off, len);
328.1741 +                return;
328.1742 +            }
328.1743 +
328.1744 +            while (len > 0) {
328.1745 +                if (pos >= MAX_BLOCK_SIZE) {
328.1746 +                    drain();
328.1747 +                }
328.1748 +                if (len >= MAX_BLOCK_SIZE && !copy && pos == 0) {
328.1749 +                    // avoid unnecessary copy
328.1750 +                    writeBlockHeader(MAX_BLOCK_SIZE);
328.1751 +                    out.write(b, off, MAX_BLOCK_SIZE);
328.1752 +                    off += MAX_BLOCK_SIZE;
328.1753 +                    len -= MAX_BLOCK_SIZE;
328.1754 +                } else {
328.1755 +                    int wlen = Math.min(len, MAX_BLOCK_SIZE - pos);
328.1756 +                    System.arraycopy(b, off, buf, pos, wlen);
328.1757 +                    pos += wlen;
328.1758 +                    off += wlen;
328.1759 +                    len -= wlen;
328.1760 +                }
328.1761 +            }
328.1762 +        }
328.1763 +
328.1764 +        /**
328.1765 +         * Writes all buffered data from this stream to the underlying stream,
328.1766 +         * but does not flush underlying stream.
328.1767 +         */
328.1768 +        void drain() throws IOException {
328.1769 +            if (pos == 0) {
328.1770 +                return;
328.1771 +            }
328.1772 +            if (blkmode) {
328.1773 +                writeBlockHeader(pos);
328.1774 +            }
328.1775 +            out.write(buf, 0, pos);
328.1776 +            pos = 0;
328.1777 +        }
328.1778 +
328.1779 +        /**
328.1780 +         * Writes block data header.  Data blocks shorter than 256 bytes are
328.1781 +         * prefixed with a 2-byte header; all others start with a 5-byte
328.1782 +         * header.
328.1783 +         */
328.1784 +        private void writeBlockHeader(int len) throws IOException {
328.1785 +            if (len <= 0xFF) {
328.1786 +                hbuf[0] = TC_BLOCKDATA;
328.1787 +                hbuf[1] = (byte) len;
328.1788 +                out.write(hbuf, 0, 2);
328.1789 +            } else {
328.1790 +                hbuf[0] = TC_BLOCKDATALONG;
328.1791 +                Bits.putInt(hbuf, 1, len);
328.1792 +                out.write(hbuf, 0, 5);
328.1793 +            }
328.1794 +        }
328.1795 +
328.1796 +
328.1797 +        /* ----------------- primitive data output methods ----------------- */
328.1798 +        /*
328.1799 +         * The following methods are equivalent to their counterparts in
328.1800 +         * DataOutputStream, except that they partition written data into data
328.1801 +         * blocks when in block data mode.
328.1802 +         */
328.1803 +
328.1804 +        public void writeBoolean(boolean v) throws IOException {
328.1805 +            if (pos >= MAX_BLOCK_SIZE) {
328.1806 +                drain();
328.1807 +            }
328.1808 +            Bits.putBoolean(buf, pos++, v);
328.1809 +        }
328.1810 +
328.1811 +        public void writeByte(int v) throws IOException {
328.1812 +            if (pos >= MAX_BLOCK_SIZE) {
328.1813 +                drain();
328.1814 +            }
328.1815 +            buf[pos++] = (byte) v;
328.1816 +        }
328.1817 +
328.1818 +        public void writeChar(int v) throws IOException {
328.1819 +            if (pos + 2 <= MAX_BLOCK_SIZE) {
328.1820 +                Bits.putChar(buf, pos, (char) v);
328.1821 +                pos += 2;
328.1822 +            } else {
328.1823 +                dout.writeChar(v);
328.1824 +            }
328.1825 +        }
328.1826 +
328.1827 +        public void writeShort(int v) throws IOException {
328.1828 +            if (pos + 2 <= MAX_BLOCK_SIZE) {
328.1829 +                Bits.putShort(buf, pos, (short) v);
328.1830 +                pos += 2;
328.1831 +            } else {
328.1832 +                dout.writeShort(v);
328.1833 +            }
328.1834 +        }
328.1835 +
328.1836 +        public void writeInt(int v) throws IOException {
328.1837 +            if (pos + 4 <= MAX_BLOCK_SIZE) {
328.1838 +                Bits.putInt(buf, pos, v);
328.1839 +                pos += 4;
328.1840 +            } else {
328.1841 +                dout.writeInt(v);
328.1842 +            }
328.1843 +        }
328.1844 +
328.1845 +        public void writeFloat(float v) throws IOException {
328.1846 +            if (pos + 4 <= MAX_BLOCK_SIZE) {
328.1847 +                Bits.putFloat(buf, pos, v);
328.1848 +                pos += 4;
328.1849 +            } else {
328.1850 +                dout.writeFloat(v);
328.1851 +            }
328.1852 +        }
328.1853 +
328.1854 +        public void writeLong(long v) throws IOException {
328.1855 +            if (pos + 8 <= MAX_BLOCK_SIZE) {
328.1856 +                Bits.putLong(buf, pos, v);
328.1857 +                pos += 8;
328.1858 +            } else {
328.1859 +                dout.writeLong(v);
328.1860 +            }
328.1861 +        }
328.1862 +
328.1863 +        public void writeDouble(double v) throws IOException {
328.1864 +            if (pos + 8 <= MAX_BLOCK_SIZE) {
328.1865 +                Bits.putDouble(buf, pos, v);
328.1866 +                pos += 8;
328.1867 +            } else {
328.1868 +                dout.writeDouble(v);
328.1869 +            }
328.1870 +        }
328.1871 +
328.1872 +        public void writeBytes(String s) throws IOException {
328.1873 +            int endoff = s.length();
328.1874 +            int cpos = 0;
328.1875 +            int csize = 0;
328.1876 +            for (int off = 0; off < endoff; ) {
328.1877 +                if (cpos >= csize) {
328.1878 +                    cpos = 0;
328.1879 +                    csize = Math.min(endoff - off, CHAR_BUF_SIZE);
328.1880 +                    s.getChars(off, off + csize, cbuf, 0);
328.1881 +                }
328.1882 +                if (pos >= MAX_BLOCK_SIZE) {
328.1883 +                    drain();
328.1884 +                }
328.1885 +                int n = Math.min(csize - cpos, MAX_BLOCK_SIZE - pos);
328.1886 +                int stop = pos + n;
328.1887 +                while (pos < stop) {
328.1888 +                    buf[pos++] = (byte) cbuf[cpos++];
328.1889 +                }
328.1890 +                off += n;
328.1891 +            }
328.1892 +        }
328.1893 +
328.1894 +        public void writeChars(String s) throws IOException {
328.1895 +            int endoff = s.length();
328.1896 +            for (int off = 0; off < endoff; ) {
328.1897 +                int csize = Math.min(endoff - off, CHAR_BUF_SIZE);
328.1898 +                s.getChars(off, off + csize, cbuf, 0);
328.1899 +                writeChars(cbuf, 0, csize);
328.1900 +                off += csize;
328.1901 +            }
328.1902 +        }
328.1903 +
328.1904 +        public void writeUTF(String s) throws IOException {
328.1905 +            writeUTF(s, getUTFLength(s));
328.1906 +        }
328.1907 +
328.1908 +
328.1909 +        /* -------------- primitive data array output methods -------------- */
328.1910 +        /*
328.1911 +         * The following methods write out spans of primitive data values.
328.1912 +         * Though equivalent to calling the corresponding primitive write
328.1913 +         * methods repeatedly, these methods are optimized for writing groups
328.1914 +         * of primitive data values more efficiently.
328.1915 +         */
328.1916 +
328.1917 +        void writeBooleans(boolean[] v, int off, int len) throws IOException {
328.1918 +            int endoff = off + len;
328.1919 +            while (off < endoff) {
328.1920 +                if (pos >= MAX_BLOCK_SIZE) {
328.1921 +                    drain();
328.1922 +                }
328.1923 +                int stop = Math.min(endoff, off + (MAX_BLOCK_SIZE - pos));
328.1924 +                while (off < stop) {
328.1925 +                    Bits.putBoolean(buf, pos++, v[off++]);
328.1926 +                }
328.1927 +            }
328.1928 +        }
328.1929 +
328.1930 +        void writeChars(char[] v, int off, int len) throws IOException {
328.1931 +            int limit = MAX_BLOCK_SIZE - 2;
328.1932 +            int endoff = off + len;
328.1933 +            while (off < endoff) {
328.1934 +                if (pos <= limit) {
328.1935 +                    int avail = (MAX_BLOCK_SIZE - pos) >> 1;
328.1936 +                    int stop = Math.min(endoff, off + avail);
328.1937 +                    while (off < stop) {
328.1938 +                        Bits.putChar(buf, pos, v[off++]);
328.1939 +                        pos += 2;
328.1940 +                    }
328.1941 +                } else {
328.1942 +                    dout.writeChar(v[off++]);
328.1943 +                }
328.1944 +            }
328.1945 +        }
328.1946 +
328.1947 +        void writeShorts(short[] v, int off, int len) throws IOException {
328.1948 +            int limit = MAX_BLOCK_SIZE - 2;
328.1949 +            int endoff = off + len;
328.1950 +            while (off < endoff) {
328.1951 +                if (pos <= limit) {
328.1952 +                    int avail = (MAX_BLOCK_SIZE - pos) >> 1;
328.1953 +                    int stop = Math.min(endoff, off + avail);
328.1954 +                    while (off < stop) {
328.1955 +                        Bits.putShort(buf, pos, v[off++]);
328.1956 +                        pos += 2;
328.1957 +                    }
328.1958 +                } else {
328.1959 +                    dout.writeShort(v[off++]);
328.1960 +                }
328.1961 +            }
328.1962 +        }
328.1963 +
328.1964 +        void writeInts(int[] v, int off, int len) throws IOException {
328.1965 +            int limit = MAX_BLOCK_SIZE - 4;
328.1966 +            int endoff = off + len;
328.1967 +            while (off < endoff) {
328.1968 +                if (pos <= limit) {
328.1969 +                    int avail = (MAX_BLOCK_SIZE - pos) >> 2;
328.1970 +                    int stop = Math.min(endoff, off + avail);
328.1971 +                    while (off < stop) {
328.1972 +                        Bits.putInt(buf, pos, v[off++]);
328.1973 +                        pos += 4;
328.1974 +                    }
328.1975 +                } else {
328.1976 +                    dout.writeInt(v[off++]);
328.1977 +                }
328.1978 +            }
328.1979 +        }
328.1980 +
328.1981 +        void writeFloats(float[] v, int off, int len) throws IOException {
328.1982 +            int limit = MAX_BLOCK_SIZE - 4;
328.1983 +            int endoff = off + len;
328.1984 +            while (off < endoff) {
328.1985 +                if (pos <= limit) {
328.1986 +                    int avail = (MAX_BLOCK_SIZE - pos) >> 2;
328.1987 +                    int chunklen = Math.min(endoff - off, avail);
328.1988 +                    floatsToBytes(v, off, buf, pos, chunklen);
328.1989 +                    off += chunklen;
328.1990 +                    pos += chunklen << 2;
328.1991 +                } else {
328.1992 +                    dout.writeFloat(v[off++]);
328.1993 +                }
328.1994 +            }
328.1995 +        }
328.1996 +
328.1997 +        void writeLongs(long[] v, int off, int len) throws IOException {
328.1998 +            int limit = MAX_BLOCK_SIZE - 8;
328.1999 +            int endoff = off + len;
328.2000 +            while (off < endoff) {
328.2001 +                if (pos <= limit) {
328.2002 +                    int avail = (MAX_BLOCK_SIZE - pos) >> 3;
328.2003 +                    int stop = Math.min(endoff, off + avail);
328.2004 +                    while (off < stop) {
328.2005 +                        Bits.putLong(buf, pos, v[off++]);
328.2006 +                        pos += 8;
328.2007 +                    }
328.2008 +                } else {
328.2009 +                    dout.writeLong(v[off++]);
328.2010 +                }
328.2011 +            }
328.2012 +        }
328.2013 +
328.2014 +        void writeDoubles(double[] v, int off, int len) throws IOException {
328.2015 +            int limit = MAX_BLOCK_SIZE - 8;
328.2016 +            int endoff = off + len;
328.2017 +            while (off < endoff) {
328.2018 +                if (pos <= limit) {
328.2019 +                    int avail = (MAX_BLOCK_SIZE - pos) >> 3;
328.2020 +                    int chunklen = Math.min(endoff - off, avail);
328.2021 +                    doublesToBytes(v, off, buf, pos, chunklen);
328.2022 +                    off += chunklen;
328.2023 +                    pos += chunklen << 3;
328.2024 +                } else {
328.2025 +                    dout.writeDouble(v[off++]);
328.2026 +                }
328.2027 +            }
328.2028 +        }
328.2029 +
328.2030 +        /**
328.2031 +         * Returns the length in bytes of the UTF encoding of the given string.
328.2032 +         */
328.2033 +        long getUTFLength(String s) {
328.2034 +            int len = s.length();
328.2035 +            long utflen = 0;
328.2036 +            for (int off = 0; off < len; ) {
328.2037 +                int csize = Math.min(len - off, CHAR_BUF_SIZE);
328.2038 +                s.getChars(off, off + csize, cbuf, 0);
328.2039 +                for (int cpos = 0; cpos < csize; cpos++) {
328.2040 +                    char c = cbuf[cpos];
328.2041 +                    if (c >= 0x0001 && c <= 0x007F) {
328.2042 +                        utflen++;
328.2043 +                    } else if (c > 0x07FF) {
328.2044 +                        utflen += 3;
328.2045 +                    } else {
328.2046 +                        utflen += 2;
328.2047 +                    }
328.2048 +                }
328.2049 +                off += csize;
328.2050 +            }
328.2051 +            return utflen;
328.2052 +        }
328.2053 +
328.2054 +        /**
328.2055 +         * Writes the given string in UTF format.  This method is used in
328.2056 +         * situations where the UTF encoding length of the string is already
328.2057 +         * known; specifying it explicitly avoids a prescan of the string to
328.2058 +         * determine its UTF length.
328.2059 +         */
328.2060 +        void writeUTF(String s, long utflen) throws IOException {
328.2061 +            if (utflen > 0xFFFFL) {
328.2062 +                throw new UTFDataFormatException();
328.2063 +            }
328.2064 +            writeShort((int) utflen);
328.2065 +            if (utflen == (long) s.length()) {
328.2066 +                writeBytes(s);
328.2067 +            } else {
328.2068 +                writeUTFBody(s);
328.2069 +            }
328.2070 +        }
328.2071 +
328.2072 +        /**
328.2073 +         * Writes given string in "long" UTF format.  "Long" UTF format is
328.2074 +         * identical to standard UTF, except that it uses an 8 byte header
328.2075 +         * (instead of the standard 2 bytes) to convey the UTF encoding length.
328.2076 +         */
328.2077 +        void writeLongUTF(String s) throws IOException {
328.2078 +            writeLongUTF(s, getUTFLength(s));
328.2079 +        }
328.2080 +
328.2081 +        /**
328.2082 +         * Writes given string in "long" UTF format, where the UTF encoding
328.2083 +         * length of the string is already known.
328.2084 +         */
328.2085 +        void writeLongUTF(String s, long utflen) throws IOException {
328.2086 +            writeLong(utflen);
328.2087 +            if (utflen == (long) s.length()) {
328.2088 +                writeBytes(s);
328.2089 +            } else {
328.2090 +                writeUTFBody(s);
328.2091 +            }
328.2092 +        }
328.2093 +
328.2094 +        /**
328.2095 +         * Writes the "body" (i.e., the UTF representation minus the 2-byte or
328.2096 +         * 8-byte length header) of the UTF encoding for the given string.
328.2097 +         */
328.2098 +        private void writeUTFBody(String s) throws IOException {
328.2099 +            int limit = MAX_BLOCK_SIZE - 3;
328.2100 +            int len = s.length();
328.2101 +            for (int off = 0; off < len; ) {
328.2102 +                int csize = Math.min(len - off, CHAR_BUF_SIZE);
328.2103 +                s.getChars(off, off + csize, cbuf, 0);
328.2104 +                for (int cpos = 0; cpos < csize; cpos++) {
328.2105 +                    char c = cbuf[cpos];
328.2106 +                    if (pos <= limit) {
328.2107 +                        if (c <= 0x007F && c != 0) {
328.2108 +                            buf[pos++] = (byte) c;
328.2109 +                        } else if (c > 0x07FF) {
328.2110 +                            buf[pos + 2] = (byte) (0x80 | ((c >> 0) & 0x3F));
328.2111 +                            buf[pos + 1] = (byte) (0x80 | ((c >> 6) & 0x3F));
328.2112 +                            buf[pos + 0] = (byte) (0xE0 | ((c >> 12) & 0x0F));
328.2113 +                            pos += 3;
328.2114 +                        } else {
328.2115 +                            buf[pos + 1] = (byte) (0x80 | ((c >> 0) & 0x3F));
328.2116 +                            buf[pos + 0] = (byte) (0xC0 | ((c >> 6) & 0x1F));
328.2117 +                            pos += 2;
328.2118 +                        }
328.2119 +                    } else {    // write one byte at a time to normalize block
328.2120 +                        if (c <= 0x007F && c != 0) {
328.2121 +                            write(c);
328.2122 +                        } else if (c > 0x07FF) {
328.2123 +                            write(0xE0 | ((c >> 12) & 0x0F));
328.2124 +                            write(0x80 | ((c >> 6) & 0x3F));
328.2125 +                            write(0x80 | ((c >> 0) & 0x3F));
328.2126 +                        } else {
328.2127 +                            write(0xC0 | ((c >> 6) & 0x1F));
328.2128 +                            write(0x80 | ((c >> 0) & 0x3F));
328.2129 +                        }
328.2130 +                    }
328.2131 +                }
328.2132 +                off += csize;
328.2133 +            }
328.2134 +        }
328.2135 +    }
328.2136 +
328.2137 +    /**
328.2138 +     * Lightweight identity hash table which maps objects to integer handles,
328.2139 +     * assigned in ascending order.
328.2140 +     */
328.2141 +    private static class HandleTable {
328.2142 +
328.2143 +        /* number of mappings in table/next available handle */
328.2144 +        private int size;
328.2145 +        /* size threshold determining when to expand hash spine */
328.2146 +        private int threshold;
328.2147 +        /* factor for computing size threshold */
328.2148 +        private final float loadFactor;
328.2149 +        /* maps hash value -> candidate handle value */
328.2150 +        private int[] spine;
328.2151 +        /* maps handle value -> next candidate handle value */
328.2152 +        private int[] next;
328.2153 +        /* maps handle value -> associated object */
328.2154 +        private Object[] objs;
328.2155 +
328.2156 +        /**
328.2157 +         * Creates new HandleTable with given capacity and load factor.
328.2158 +         */
328.2159 +        HandleTable(int initialCapacity, float loadFactor) {
328.2160 +            this.loadFactor = loadFactor;
328.2161 +            spine = new int[initialCapacity];
328.2162 +            next = new int[initialCapacity];
328.2163 +            objs = new Object[initialCapacity];
328.2164 +            threshold = (int) (initialCapacity * loadFactor);
328.2165 +            clear();
328.2166 +        }
328.2167 +
328.2168 +        /**
328.2169 +         * Assigns next available handle to given object, and returns handle
328.2170 +         * value.  Handles are assigned in ascending order starting at 0.
328.2171 +         */
328.2172 +        int assign(Object obj) {
328.2173 +            if (size >= next.length) {
328.2174 +                growEntries();
328.2175 +            }
328.2176 +            if (size >= threshold) {
328.2177 +                growSpine();
328.2178 +            }
328.2179 +            insert(obj, size);
328.2180 +            return size++;
328.2181 +        }
328.2182 +
328.2183 +        /**
328.2184 +         * Looks up and returns handle associated with given object, or -1 if
328.2185 +         * no mapping found.
328.2186 +         */
328.2187 +        int lookup(Object obj) {
328.2188 +            if (size == 0) {
328.2189 +                return -1;
328.2190 +            }
328.2191 +            int index = hash(obj) % spine.length;
328.2192 +            for (int i = spine[index]; i >= 0; i = next[i]) {
328.2193 +                if (objs[i] == obj) {
328.2194 +                    return i;
328.2195 +                }
328.2196 +            }
328.2197 +            return -1;
328.2198 +        }
328.2199 +
328.2200 +        /**
328.2201 +         * Resets table to its initial (empty) state.
328.2202 +         */
328.2203 +        void clear() {
328.2204 +            Arrays.fill(spine, -1);
328.2205 +            Arrays.fill(objs, 0, size, null);
328.2206 +            size = 0;
328.2207 +        }
328.2208 +
328.2209 +        /**
328.2210 +         * Returns the number of mappings currently in table.
328.2211 +         */
328.2212 +        int size() {
328.2213 +            return size;
328.2214 +        }
328.2215 +
328.2216 +        /**
328.2217 +         * Inserts mapping object -> handle mapping into table.  Assumes table
328.2218 +         * is large enough to accommodate new mapping.
328.2219 +         */
328.2220 +        private void insert(Object obj, int handle) {
328.2221 +            int index = hash(obj) % spine.length;
328.2222 +            objs[handle] = obj;
328.2223 +            next[handle] = spine[index];
328.2224 +            spine[index] = handle;
328.2225 +        }
328.2226 +
328.2227 +        /**
328.2228 +         * Expands the hash "spine" -- equivalent to increasing the number of
328.2229 +         * buckets in a conventional hash table.
328.2230 +         */
328.2231 +        private void growSpine() {
328.2232 +            spine = new int[(spine.length << 1) + 1];
328.2233 +            threshold = (int) (spine.length * loadFactor);
328.2234 +            Arrays.fill(spine, -1);
328.2235 +            for (int i = 0; i < size; i++) {
328.2236 +                insert(objs[i], i);
328.2237 +            }
328.2238 +        }
328.2239 +
328.2240 +        /**
328.2241 +         * Increases hash table capacity by lengthening entry arrays.
328.2242 +         */
328.2243 +        private void growEntries() {
328.2244 +            int newLength = (next.length << 1) + 1;
328.2245 +            int[] newNext = new int[newLength];
328.2246 +            System.arraycopy(next, 0, newNext, 0, size);
328.2247 +            next = newNext;
328.2248 +
328.2249 +            Object[] newObjs = new Object[newLength];
328.2250 +            System.arraycopy(objs, 0, newObjs, 0, size);
328.2251 +            objs = newObjs;
328.2252 +        }
328.2253 +
328.2254 +        /**
328.2255 +         * Returns hash value for given object.
328.2256 +         */
328.2257 +        private int hash(Object obj) {
328.2258 +            return System.identityHashCode(obj) & 0x7FFFFFFF;
328.2259 +        }
328.2260 +    }
328.2261 +
328.2262 +    /**
328.2263 +     * Lightweight identity hash table which maps objects to replacement
328.2264 +     * objects.
328.2265 +     */
328.2266 +    private static class ReplaceTable {
328.2267 +
328.2268 +        /* maps object -> index */
328.2269 +        private final HandleTable htab;
328.2270 +        /* maps index -> replacement object */
328.2271 +        private Object[] reps;
328.2272 +
328.2273 +        /**
328.2274 +         * Creates new ReplaceTable with given capacity and load factor.
328.2275 +         */
328.2276 +        ReplaceTable(int initialCapacity, float loadFactor) {
328.2277 +            htab = new HandleTable(initialCapacity, loadFactor);
328.2278 +            reps = new Object[initialCapacity];
328.2279 +        }
328.2280 +
328.2281 +        /**
328.2282 +         * Enters mapping from object to replacement object.
328.2283 +         */
328.2284 +        void assign(Object obj, Object rep) {
328.2285 +            int index = htab.assign(obj);
328.2286 +            while (index >= reps.length) {
328.2287 +                grow();
328.2288 +            }
328.2289 +            reps[index] = rep;
328.2290 +        }
328.2291 +
328.2292 +        /**
328.2293 +         * Looks up and returns replacement for given object.  If no
328.2294 +         * replacement is found, returns the lookup object itself.
328.2295 +         */
328.2296 +        Object lookup(Object obj) {
328.2297 +            int index = htab.lookup(obj);
328.2298 +            return (index >= 0) ? reps[index] : obj;
328.2299 +        }
328.2300 +
328.2301 +        /**
328.2302 +         * Resets table to its initial (empty) state.
328.2303 +         */
328.2304 +        void clear() {
328.2305 +            Arrays.fill(reps, 0, htab.size(), null);
328.2306 +            htab.clear();
328.2307 +        }
328.2308 +
328.2309 +        /**
328.2310 +         * Returns the number of mappings currently in table.
328.2311 +         */
328.2312 +        int size() {
328.2313 +            return htab.size();
328.2314 +        }
328.2315 +
328.2316 +        /**
328.2317 +         * Increases table capacity.
328.2318 +         */
328.2319 +        private void grow() {
328.2320 +            Object[] newReps = new Object[(reps.length << 1) + 1];
328.2321 +            System.arraycopy(reps, 0, newReps, 0, reps.length);
328.2322 +            reps = newReps;
328.2323 +        }
328.2324 +    }
328.2325 +
328.2326 +    /**
328.2327 +     * Stack to keep debug information about the state of the
328.2328 +     * serialization process, for embedding in exception messages.
328.2329 +     */
328.2330 +    private static class DebugTraceInfoStack {
328.2331 +        private final List<String> stack;
328.2332 +
328.2333 +        DebugTraceInfoStack() {
328.2334 +            stack = new ArrayList<>();
328.2335 +        }
328.2336 +
328.2337 +        /**
328.2338 +         * Removes all of the elements from enclosed list.
328.2339 +         */
328.2340 +        void clear() {
328.2341 +            stack.clear();
328.2342 +        }
328.2343 +
328.2344 +        /**
328.2345 +         * Removes the object at the top of enclosed list.
328.2346 +         */
328.2347 +        void pop() {
328.2348 +            stack.remove(stack.size()-1);
328.2349 +        }
328.2350 +
328.2351 +        /**
328.2352 +         * Pushes a String onto the top of enclosed list.
328.2353 +         */
328.2354 +        void push(String entry) {
328.2355 +            stack.add("\t- " + entry);
328.2356 +        }
328.2357 +
328.2358 +        /**
328.2359 +         * Returns a string representation of this object
328.2360 +         */
328.2361 +        public String toString() {
328.2362 +            StringBuilder buffer = new StringBuilder();
328.2363 +            if (!stack.isEmpty()) {
328.2364 +                for(int i = stack.size(); i > 0; i-- ) {
328.2365 +                    buffer.append(stack.get(i-1) + ((i != 1) ? "\n" : ""));
328.2366 +                }
328.2367 +            }
328.2368 +            return buffer.toString();
328.2369 +        }
328.2370 +    }
328.2371 +
328.2372 +}
   329.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   329.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectStreamClass.java	Wed Feb 27 11:24:58 2013 +0100
   329.3 @@ -0,0 +1,1396 @@
   329.4 +/*
   329.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
   329.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   329.7 + *
   329.8 + * This code is free software; you can redistribute it and/or modify it
   329.9 + * under the terms of the GNU General Public License version 2 only, as
  329.10 + * published by the Free Software Foundation.  Oracle designates this
  329.11 + * particular file as subject to the "Classpath" exception as provided
  329.12 + * by Oracle in the LICENSE file that accompanied this code.
  329.13 + *
  329.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  329.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  329.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  329.17 + * version 2 for more details (a copy is included in the LICENSE file that
  329.18 + * accompanied this code).
  329.19 + *
  329.20 + * You should have received a copy of the GNU General Public License version
  329.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  329.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  329.23 + *
  329.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  329.25 + * or visit www.oracle.com if you need additional information or have any
  329.26 + * questions.
  329.27 + */
  329.28 +
  329.29 +package java.io;
  329.30 +
  329.31 +import java.lang.ref.Reference;
  329.32 +import java.lang.ref.ReferenceQueue;
  329.33 +import java.lang.ref.SoftReference;
  329.34 +import java.lang.ref.WeakReference;
  329.35 +import java.lang.reflect.Constructor;
  329.36 +import java.lang.reflect.Field;
  329.37 +import java.lang.reflect.InvocationTargetException;
  329.38 +import java.lang.reflect.Member;
  329.39 +import java.lang.reflect.Method;
  329.40 +import java.lang.reflect.Modifier;
  329.41 +import java.lang.reflect.Proxy;
  329.42 +import java.util.ArrayList;
  329.43 +import java.util.Arrays;
  329.44 +import java.util.Collections;
  329.45 +import java.util.Comparator;
  329.46 +import java.util.HashSet;
  329.47 +import java.util.Set;
  329.48 +
  329.49 +/**
  329.50 + * Serialization's descriptor for classes.  It contains the name and
  329.51 + * serialVersionUID of the class.  The ObjectStreamClass for a specific class
  329.52 + * loaded in this Java VM can be found/created using the lookup method.
  329.53 + *
  329.54 + * <p>The algorithm to compute the SerialVersionUID is described in
  329.55 + * <a href="../../../platform/serialization/spec/class.html#4100">Object
  329.56 + * Serialization Specification, Section 4.6, Stream Unique Identifiers</a>.
  329.57 + *
  329.58 + * @author      Mike Warres
  329.59 + * @author      Roger Riggs
  329.60 + * @see ObjectStreamField
  329.61 + * @see <a href="../../../platform/serialization/spec/class.html">Object Serialization Specification, Section 4, Class Descriptors</a>
  329.62 + * @since   JDK1.1
  329.63 + */
  329.64 +public class ObjectStreamClass implements Serializable {
  329.65 +
  329.66 +    /** serialPersistentFields value indicating no serializable fields */
  329.67 +    public static final ObjectStreamField[] NO_FIELDS =
  329.68 +        new ObjectStreamField[0];
  329.69 +
  329.70 +    private static final long serialVersionUID = -6120832682080437368L;
  329.71 +    private static final ObjectStreamField[] serialPersistentFields =
  329.72 +        NO_FIELDS;
  329.73 +
  329.74 +
  329.75 +    /** class associated with this descriptor (if any) */
  329.76 +    private Class<?> cl;
  329.77 +    /** name of class represented by this descriptor */
  329.78 +    private String name;
  329.79 +    /** serialVersionUID of represented class (null if not computed yet) */
  329.80 +    private volatile Long suid;
  329.81 +
  329.82 +    /** true if represents dynamic proxy class */
  329.83 +    private boolean isProxy;
  329.84 +    /** true if represents enum type */
  329.85 +    private boolean isEnum;
  329.86 +    /** true if represented class implements Serializable */
  329.87 +    private boolean serializable;
  329.88 +    /** true if represented class implements Externalizable */
  329.89 +    private boolean externalizable;
  329.90 +    /** true if desc has data written by class-defined writeObject method */
  329.91 +    private boolean hasWriteObjectData;
  329.92 +    /**
  329.93 +     * true if desc has externalizable data written in block data format; this
  329.94 +     * must be true by default to accommodate ObjectInputStream subclasses which
  329.95 +     * override readClassDescriptor() to return class descriptors obtained from
  329.96 +     * ObjectStreamClass.lookup() (see 4461737)
  329.97 +     */
  329.98 +    private boolean hasBlockExternalData = true;
  329.99 +
 329.100 +    /** exception (if any) thrown while attempting to resolve class */
 329.101 +    private ClassNotFoundException resolveEx;
 329.102 +    /** exception (if any) to throw if non-enum deserialization attempted */
 329.103 +    private InvalidClassException deserializeEx;
 329.104 +    /** exception (if any) to throw if non-enum serialization attempted */
 329.105 +    private InvalidClassException serializeEx;
 329.106 +    /** exception (if any) to throw if default serialization attempted */
 329.107 +    private InvalidClassException defaultSerializeEx;
 329.108 +
 329.109 +    /** serializable fields */
 329.110 +    private ObjectStreamField[] fields;
 329.111 +    /** aggregate marshalled size of primitive fields */
 329.112 +    private int primDataSize;
 329.113 +    /** number of non-primitive fields */
 329.114 +    private int numObjFields;
 329.115 +    /** reflector for setting/getting serializable field values */
 329.116 +//    private FieldReflector fieldRefl;
 329.117 +    /** data layout of serialized objects described by this class desc */
 329.118 +    private volatile ClassDataSlot[] dataLayout;
 329.119 +
 329.120 +    /** serialization-appropriate constructor, or null if none */
 329.121 +    private Constructor cons;
 329.122 +    /** class-defined writeObject method, or null if none */
 329.123 +    private Method writeObjectMethod;
 329.124 +    /** class-defined readObject method, or null if none */
 329.125 +    private Method readObjectMethod;
 329.126 +    /** class-defined readObjectNoData method, or null if none */
 329.127 +    private Method readObjectNoDataMethod;
 329.128 +    /** class-defined writeReplace method, or null if none */
 329.129 +    private Method writeReplaceMethod;
 329.130 +    /** class-defined readResolve method, or null if none */
 329.131 +    private Method readResolveMethod;
 329.132 +
 329.133 +    /** local class descriptor for represented class (may point to self) */
 329.134 +    private ObjectStreamClass localDesc;
 329.135 +    /** superclass descriptor appearing in stream */
 329.136 +    private ObjectStreamClass superDesc;
 329.137 +
 329.138 +    /**
 329.139 +     * Initializes native code.
 329.140 +     */
 329.141 +    private static native void initNative();
 329.142 +    static {
 329.143 +        initNative();
 329.144 +    }
 329.145 +
 329.146 +    /**
 329.147 +     * Find the descriptor for a class that can be serialized.  Creates an
 329.148 +     * ObjectStreamClass instance if one does not exist yet for class. Null is
 329.149 +     * returned if the specified class does not implement java.io.Serializable
 329.150 +     * or java.io.Externalizable.
 329.151 +     *
 329.152 +     * @param   cl class for which to get the descriptor
 329.153 +     * @return  the class descriptor for the specified class
 329.154 +     */
 329.155 +    public static ObjectStreamClass lookup(Class<?> cl) {
 329.156 +        return lookup(cl, false);
 329.157 +    }
 329.158 +
 329.159 +    /**
 329.160 +     * Returns the descriptor for any class, regardless of whether it
 329.161 +     * implements {@link Serializable}.
 329.162 +     *
 329.163 +     * @param        cl class for which to get the descriptor
 329.164 +     * @return       the class descriptor for the specified class
 329.165 +     * @since 1.6
 329.166 +     */
 329.167 +    public static ObjectStreamClass lookupAny(Class<?> cl) {
 329.168 +        return lookup(cl, true);
 329.169 +    }
 329.170 +
 329.171 +    /**
 329.172 +     * Returns the name of the class described by this descriptor.
 329.173 +     * This method returns the name of the class in the format that
 329.174 +     * is used by the {@link Class#getName} method.
 329.175 +     *
 329.176 +     * @return a string representing the name of the class
 329.177 +     */
 329.178 +    public String getName() {
 329.179 +        return name;
 329.180 +    }
 329.181 +
 329.182 +    /**
 329.183 +     * Return the serialVersionUID for this class.  The serialVersionUID
 329.184 +     * defines a set of classes all with the same name that have evolved from a
 329.185 +     * common root class and agree to be serialized and deserialized using a
 329.186 +     * common format.  NonSerializable classes have a serialVersionUID of 0L.
 329.187 +     *
 329.188 +     * @return  the SUID of the class described by this descriptor
 329.189 +     */
 329.190 +    public long getSerialVersionUID() {
 329.191 +        // REMIND: synchronize instead of relying on volatile?
 329.192 +        if (suid == null) {
 329.193 +            return computeDefaultSUID(cl);
 329.194 +        }
 329.195 +        return suid.longValue();
 329.196 +    }
 329.197 +
 329.198 +    /**
 329.199 +     * Return the class in the local VM that this version is mapped to.  Null
 329.200 +     * is returned if there is no corresponding local class.
 329.201 +     *
 329.202 +     * @return  the <code>Class</code> instance that this descriptor represents
 329.203 +     */
 329.204 +    public Class<?> forClass() {
 329.205 +        return cl;
 329.206 +    }
 329.207 +
 329.208 +    /**
 329.209 +     * Return an array of the fields of this serializable class.
 329.210 +     *
 329.211 +     * @return  an array containing an element for each persistent field of
 329.212 +     *          this class. Returns an array of length zero if there are no
 329.213 +     *          fields.
 329.214 +     * @since 1.2
 329.215 +     */
 329.216 +    public ObjectStreamField[] getFields() {
 329.217 +        return getFields(true);
 329.218 +    }
 329.219 +
 329.220 +    /**
 329.221 +     * Get the field of this class by name.
 329.222 +     *
 329.223 +     * @param   name the name of the data field to look for
 329.224 +     * @return  The ObjectStreamField object of the named field or null if
 329.225 +     *          there is no such named field.
 329.226 +     */
 329.227 +    public ObjectStreamField getField(String name) {
 329.228 +        return getField(name, null);
 329.229 +    }
 329.230 +
 329.231 +    /**
 329.232 +     * Return a string describing this ObjectStreamClass.
 329.233 +     */
 329.234 +    public String toString() {
 329.235 +        return name + ": static final long serialVersionUID = " +
 329.236 +            getSerialVersionUID() + "L;";
 329.237 +    }
 329.238 +
 329.239 +    /**
 329.240 +     * Looks up and returns class descriptor for given class, or null if class
 329.241 +     * is non-serializable and "all" is set to false.
 329.242 +     *
 329.243 +     * @param   cl class to look up
 329.244 +     * @param   all if true, return descriptors for all classes; if false, only
 329.245 +     *          return descriptors for serializable classes
 329.246 +     */
 329.247 +    static ObjectStreamClass lookup(Class<?> cl, boolean all) {
 329.248 +        if (!(all || Serializable.class.isAssignableFrom(cl))) {
 329.249 +            return null;
 329.250 +        }
 329.251 +        Object entry = null;
 329.252 +        EntryFuture future = null;
 329.253 +        if (entry == null) {
 329.254 +            EntryFuture newEntry = new EntryFuture();
 329.255 +            Reference<?> newRef = new SoftReference<>(newEntry);
 329.256 +            if (entry == null) {
 329.257 +                future = newEntry;
 329.258 +            }
 329.259 +        }
 329.260 +
 329.261 +        if (entry instanceof ObjectStreamClass) {  // check common case first
 329.262 +            return (ObjectStreamClass) entry;
 329.263 +        }
 329.264 +        if (entry instanceof EntryFuture) {
 329.265 +            future = (EntryFuture) entry;
 329.266 +            if (true) {
 329.267 +                /*
 329.268 +                 * Handle nested call situation described by 4803747: waiting
 329.269 +                 * for future value to be set by a lookup() call further up the
 329.270 +                 * stack will result in deadlock, so calculate and set the
 329.271 +                 * future value here instead.
 329.272 +                 */
 329.273 +                entry = null;
 329.274 +            } else {
 329.275 +                entry = future.get();
 329.276 +            }
 329.277 +        }
 329.278 +        if (entry == null) {
 329.279 +            try {
 329.280 +                entry = new ObjectStreamClass(cl);
 329.281 +            } catch (Throwable th) {
 329.282 +                entry = th;
 329.283 +            }
 329.284 +            // nested lookup call already set future
 329.285 +            entry = future.get();
 329.286 +        }
 329.287 +
 329.288 +        if (entry instanceof ObjectStreamClass) {
 329.289 +            return (ObjectStreamClass) entry;
 329.290 +        } else if (entry instanceof RuntimeException) {
 329.291 +            throw (RuntimeException) entry;
 329.292 +        } else if (entry instanceof Error) {
 329.293 +            throw (Error) entry;
 329.294 +        } else {
 329.295 +            throw new InternalError("unexpected entry: " + entry);
 329.296 +        }
 329.297 +    }
 329.298 +
 329.299 +    /**
 329.300 +     * Placeholder used in class descriptor and field reflector lookup tables
 329.301 +     * for an entry in the process of being initialized.  (Internal) callers
 329.302 +     * which receive an EntryFuture belonging to another thread as the result
 329.303 +     * of a lookup should call the get() method of the EntryFuture; this will
 329.304 +     * return the actual entry once it is ready for use and has been set().  To
 329.305 +     * conserve objects, EntryFutures synchronize on themselves.
 329.306 +     */
 329.307 +    private static class EntryFuture {
 329.308 +
 329.309 +        private static final Object unset = new Object();
 329.310 +        private Object entry = unset;
 329.311 +
 329.312 +        /**
 329.313 +         * Attempts to set the value contained by this EntryFuture.  If the
 329.314 +         * EntryFuture's value has not been set already, then the value is
 329.315 +         * saved, any callers blocked in the get() method are notified, and
 329.316 +         * true is returned.  If the value has already been set, then no saving
 329.317 +         * or notification occurs, and false is returned.
 329.318 +         */
 329.319 +        synchronized boolean set(Object entry) {
 329.320 +            if (this.entry != unset) {
 329.321 +                return false;
 329.322 +            }
 329.323 +            this.entry = entry;
 329.324 +            notifyAll();
 329.325 +            return true;
 329.326 +        }
 329.327 +
 329.328 +        /**
 329.329 +         * Returns the value contained by this EntryFuture, blocking if
 329.330 +         * necessary until a value is set.
 329.331 +         */
 329.332 +        synchronized Object get() {
 329.333 +            boolean interrupted = false;
 329.334 +            while (entry == unset) {
 329.335 +                try {
 329.336 +                    wait();
 329.337 +                } catch (InterruptedException ex) {
 329.338 +                    interrupted = true;
 329.339 +                }
 329.340 +            }
 329.341 +            return entry;
 329.342 +        }
 329.343 +    }
 329.344 +
 329.345 +    /**
 329.346 +     * Creates local class descriptor representing given class.
 329.347 +     */
 329.348 +    private ObjectStreamClass(final Class<?> cl) {
 329.349 +        this.cl = cl;
 329.350 +        name = cl.getName();
 329.351 +        isProxy = Proxy.isProxyClass(cl);
 329.352 +        isEnum = Enum.class.isAssignableFrom(cl);
 329.353 +        serializable = Serializable.class.isAssignableFrom(cl);
 329.354 +        externalizable = Externalizable.class.isAssignableFrom(cl);
 329.355 +
 329.356 +        Class<?> superCl = cl.getSuperclass();
 329.357 +        superDesc = (superCl != null) ? lookup(superCl, false) : null;
 329.358 +        localDesc = this;
 329.359 +
 329.360 +        suid = Long.valueOf(0);
 329.361 +        fields = NO_FIELDS;
 329.362 +
 329.363 +
 329.364 +        if (deserializeEx == null) {
 329.365 +            if (isEnum) {
 329.366 +                deserializeEx = new InvalidClassException(name, "enum type");
 329.367 +            } else if (cons == null) {
 329.368 +                deserializeEx = new InvalidClassException(
 329.369 +                    name, "no valid constructor");
 329.370 +            }
 329.371 +        }
 329.372 +        for (int i = 0; i < fields.length; i++) {
 329.373 +            if (fields[i].getField() == null) {
 329.374 +                defaultSerializeEx = new InvalidClassException(
 329.375 +                    name, "unmatched serializable field(s) declared");
 329.376 +            }
 329.377 +        }
 329.378 +    }
 329.379 +
 329.380 +    /**
 329.381 +     * Creates blank class descriptor which should be initialized via a
 329.382 +     * subsequent call to initProxy(), initNonProxy() or readNonProxy().
 329.383 +     */
 329.384 +    ObjectStreamClass() {
 329.385 +    }
 329.386 +
 329.387 +    /**
 329.388 +     * Initializes class descriptor representing a proxy class.
 329.389 +     */
 329.390 +    void initProxy(Class<?> cl,
 329.391 +                   ClassNotFoundException resolveEx,
 329.392 +                   ObjectStreamClass superDesc)
 329.393 +        throws InvalidClassException
 329.394 +    {
 329.395 +        this.cl = cl;
 329.396 +        this.resolveEx = resolveEx;
 329.397 +        this.superDesc = superDesc;
 329.398 +        isProxy = true;
 329.399 +        serializable = true;
 329.400 +        suid = Long.valueOf(0);
 329.401 +        fields = NO_FIELDS;
 329.402 +
 329.403 +        if (cl != null) {
 329.404 +            localDesc = lookup(cl, true);
 329.405 +            if (!localDesc.isProxy) {
 329.406 +                throw new InvalidClassException(
 329.407 +                    "cannot bind proxy descriptor to a non-proxy class");
 329.408 +            }
 329.409 +            name = localDesc.name;
 329.410 +            externalizable = localDesc.externalizable;
 329.411 +            cons = localDesc.cons;
 329.412 +            writeReplaceMethod = localDesc.writeReplaceMethod;
 329.413 +            readResolveMethod = localDesc.readResolveMethod;
 329.414 +            deserializeEx = localDesc.deserializeEx;
 329.415 +        }
 329.416 +    }
 329.417 +
 329.418 +    /**
 329.419 +     * Initializes class descriptor representing a non-proxy class.
 329.420 +     */
 329.421 +    void initNonProxy(ObjectStreamClass model,
 329.422 +                      Class<?> cl,
 329.423 +                      ClassNotFoundException resolveEx,
 329.424 +                      ObjectStreamClass superDesc)
 329.425 +        throws InvalidClassException
 329.426 +    {
 329.427 +        this.cl = cl;
 329.428 +        this.resolveEx = resolveEx;
 329.429 +        this.superDesc = superDesc;
 329.430 +        name = model.name;
 329.431 +        suid = Long.valueOf(model.getSerialVersionUID());
 329.432 +        isProxy = false;
 329.433 +        isEnum = model.isEnum;
 329.434 +        serializable = model.serializable;
 329.435 +        externalizable = model.externalizable;
 329.436 +        hasBlockExternalData = model.hasBlockExternalData;
 329.437 +        hasWriteObjectData = model.hasWriteObjectData;
 329.438 +        fields = model.fields;
 329.439 +        primDataSize = model.primDataSize;
 329.440 +        numObjFields = model.numObjFields;
 329.441 +
 329.442 +        if (cl != null) {
 329.443 +            localDesc = lookup(cl, true);
 329.444 +            if (localDesc.isProxy) {
 329.445 +                throw new InvalidClassException(
 329.446 +                    "cannot bind non-proxy descriptor to a proxy class");
 329.447 +            }
 329.448 +            if (isEnum != localDesc.isEnum) {
 329.449 +                throw new InvalidClassException(isEnum ?
 329.450 +                    "cannot bind enum descriptor to a non-enum class" :
 329.451 +                    "cannot bind non-enum descriptor to an enum class");
 329.452 +            }
 329.453 +
 329.454 +            if (serializable == localDesc.serializable &&
 329.455 +                !cl.isArray() &&
 329.456 +                suid.longValue() != localDesc.getSerialVersionUID())
 329.457 +            {
 329.458 +                throw new InvalidClassException(localDesc.name,
 329.459 +                    "local class incompatible: " +
 329.460 +                    "stream classdesc serialVersionUID = " + suid +
 329.461 +                    ", local class serialVersionUID = " +
 329.462 +                    localDesc.getSerialVersionUID());
 329.463 +            }
 329.464 +
 329.465 +            if (!classNamesEqual(name, localDesc.name)) {
 329.466 +                throw new InvalidClassException(localDesc.name,
 329.467 +                    "local class name incompatible with stream class " +
 329.468 +                    "name \"" + name + "\"");
 329.469 +            }
 329.470 +
 329.471 +            if (!isEnum) {
 329.472 +                if ((serializable == localDesc.serializable) &&
 329.473 +                    (externalizable != localDesc.externalizable))
 329.474 +                {
 329.475 +                    throw new InvalidClassException(localDesc.name,
 329.476 +                        "Serializable incompatible with Externalizable");
 329.477 +                }
 329.478 +
 329.479 +                if ((serializable != localDesc.serializable) ||
 329.480 +                    (externalizable != localDesc.externalizable) ||
 329.481 +                    !(serializable || externalizable))
 329.482 +                {
 329.483 +                    deserializeEx = new InvalidClassException(localDesc.name,
 329.484 +                        "class invalid for deserialization");
 329.485 +                }
 329.486 +            }
 329.487 +
 329.488 +            cons = localDesc.cons;
 329.489 +            writeObjectMethod = localDesc.writeObjectMethod;
 329.490 +            readObjectMethod = localDesc.readObjectMethod;
 329.491 +            readObjectNoDataMethod = localDesc.readObjectNoDataMethod;
 329.492 +            writeReplaceMethod = localDesc.writeReplaceMethod;
 329.493 +            readResolveMethod = localDesc.readResolveMethod;
 329.494 +            if (deserializeEx == null) {
 329.495 +                deserializeEx = localDesc.deserializeEx;
 329.496 +            }
 329.497 +        }
 329.498 +        // reassign to matched fields so as to reflect local unshared settings
 329.499 +        fields = null;
 329.500 +    }
 329.501 +
 329.502 +    /**
 329.503 +     * Reads non-proxy class descriptor information from given input stream.
 329.504 +     * The resulting class descriptor is not fully functional; it can only be
 329.505 +     * used as input to the ObjectInputStream.resolveClass() and
 329.506 +     * ObjectStreamClass.initNonProxy() methods.
 329.507 +     */
 329.508 +    void readNonProxy(ObjectInputStream in)
 329.509 +        throws IOException, ClassNotFoundException
 329.510 +    {
 329.511 +        name = in.readUTF();
 329.512 +        suid = Long.valueOf(in.readLong());
 329.513 +        isProxy = false;
 329.514 +
 329.515 +        byte flags = in.readByte();
 329.516 +        hasWriteObjectData =
 329.517 +            ((flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0);
 329.518 +        hasBlockExternalData =
 329.519 +            ((flags & ObjectStreamConstants.SC_BLOCK_DATA) != 0);
 329.520 +        externalizable =
 329.521 +            ((flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0);
 329.522 +        boolean sflag =
 329.523 +            ((flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0);
 329.524 +        if (externalizable && sflag) {
 329.525 +            throw new InvalidClassException(
 329.526 +                name, "serializable and externalizable flags conflict");
 329.527 +        }
 329.528 +        serializable = externalizable || sflag;
 329.529 +        isEnum = ((flags & ObjectStreamConstants.SC_ENUM) != 0);
 329.530 +        if (isEnum && suid.longValue() != 0L) {
 329.531 +            throw new InvalidClassException(name,
 329.532 +                "enum descriptor has non-zero serialVersionUID: " + suid);
 329.533 +        }
 329.534 +
 329.535 +        int numFields = in.readShort();
 329.536 +        if (isEnum && numFields != 0) {
 329.537 +            throw new InvalidClassException(name,
 329.538 +                "enum descriptor has non-zero field count: " + numFields);
 329.539 +        }
 329.540 +        fields = (numFields > 0) ?
 329.541 +            new ObjectStreamField[numFields] : NO_FIELDS;
 329.542 +        for (int i = 0; i < numFields; i++) {
 329.543 +            char tcode = (char) in.readByte();
 329.544 +            String fname = in.readUTF();
 329.545 +            String signature = ((tcode == 'L') || (tcode == '[')) ?
 329.546 +                in.readTypeString() : new String(new char[] { tcode });
 329.547 +            try {
 329.548 +                fields[i] = new ObjectStreamField(fname, signature, false);
 329.549 +            } catch (RuntimeException e) {
 329.550 +                throw (IOException) new InvalidClassException(name,
 329.551 +                    "invalid descriptor for field " + fname).initCause(e);
 329.552 +            }
 329.553 +        }
 329.554 +        computeFieldOffsets();
 329.555 +    }
 329.556 +
 329.557 +    /**
 329.558 +     * Writes non-proxy class descriptor information to given output stream.
 329.559 +     */
 329.560 +    void writeNonProxy(ObjectOutputStream out) throws IOException {
 329.561 +        out.writeUTF(name);
 329.562 +        out.writeLong(getSerialVersionUID());
 329.563 +
 329.564 +        byte flags = 0;
 329.565 +        if (externalizable) {
 329.566 +            flags |= ObjectStreamConstants.SC_EXTERNALIZABLE;
 329.567 +            int protocol = out.getProtocolVersion();
 329.568 +            if (protocol != ObjectStreamConstants.PROTOCOL_VERSION_1) {
 329.569 +                flags |= ObjectStreamConstants.SC_BLOCK_DATA;
 329.570 +            }
 329.571 +        } else if (serializable) {
 329.572 +            flags |= ObjectStreamConstants.SC_SERIALIZABLE;
 329.573 +        }
 329.574 +        if (hasWriteObjectData) {
 329.575 +            flags |= ObjectStreamConstants.SC_WRITE_METHOD;
 329.576 +        }
 329.577 +        if (isEnum) {
 329.578 +            flags |= ObjectStreamConstants.SC_ENUM;
 329.579 +        }
 329.580 +        out.writeByte(flags);
 329.581 +
 329.582 +        out.writeShort(fields.length);
 329.583 +        for (int i = 0; i < fields.length; i++) {
 329.584 +            ObjectStreamField f = fields[i];
 329.585 +            out.writeByte(f.getTypeCode());
 329.586 +            out.writeUTF(f.getName());
 329.587 +            if (!f.isPrimitive()) {
 329.588 +                out.writeTypeString(f.getTypeString());
 329.589 +            }
 329.590 +        }
 329.591 +    }
 329.592 +
 329.593 +    /**
 329.594 +     * Returns ClassNotFoundException (if any) thrown while attempting to
 329.595 +     * resolve local class corresponding to this class descriptor.
 329.596 +     */
 329.597 +    ClassNotFoundException getResolveException() {
 329.598 +        return resolveEx;
 329.599 +    }
 329.600 +
 329.601 +    /**
 329.602 +     * Throws an InvalidClassException if object instances referencing this
 329.603 +     * class descriptor should not be allowed to deserialize.  This method does
 329.604 +     * not apply to deserialization of enum constants.
 329.605 +     */
 329.606 +    void checkDeserialize() throws InvalidClassException {
 329.607 +        if (deserializeEx != null) {
 329.608 +            InvalidClassException ice =
 329.609 +                new InvalidClassException(deserializeEx.classname,
 329.610 +                                          deserializeEx.getMessage());
 329.611 +            ice.initCause(deserializeEx);
 329.612 +            throw ice;
 329.613 +        }
 329.614 +    }
 329.615 +
 329.616 +    /**
 329.617 +     * Throws an InvalidClassException if objects whose class is represented by
 329.618 +     * this descriptor should not be allowed to serialize.  This method does
 329.619 +     * not apply to serialization of enum constants.
 329.620 +     */
 329.621 +    void checkSerialize() throws InvalidClassException {
 329.622 +        if (serializeEx != null) {
 329.623 +            InvalidClassException ice =
 329.624 +                new InvalidClassException(serializeEx.classname,
 329.625 +                                          serializeEx.getMessage());
 329.626 +            ice.initCause(serializeEx);
 329.627 +            throw ice;
 329.628 +        }
 329.629 +    }
 329.630 +
 329.631 +    /**
 329.632 +     * Throws an InvalidClassException if objects whose class is represented by
 329.633 +     * this descriptor should not be permitted to use default serialization
 329.634 +     * (e.g., if the class declares serializable fields that do not correspond
 329.635 +     * to actual fields, and hence must use the GetField API).  This method
 329.636 +     * does not apply to deserialization of enum constants.
 329.637 +     */
 329.638 +    void checkDefaultSerialize() throws InvalidClassException {
 329.639 +        if (defaultSerializeEx != null) {
 329.640 +            InvalidClassException ice =
 329.641 +                new InvalidClassException(defaultSerializeEx.classname,
 329.642 +                                          defaultSerializeEx.getMessage());
 329.643 +            ice.initCause(defaultSerializeEx);
 329.644 +            throw ice;
 329.645 +        }
 329.646 +    }
 329.647 +
 329.648 +    /**
 329.649 +     * Returns superclass descriptor.  Note that on the receiving side, the
 329.650 +     * superclass descriptor may be bound to a class that is not a superclass
 329.651 +     * of the subclass descriptor's bound class.
 329.652 +     */
 329.653 +    ObjectStreamClass getSuperDesc() {
 329.654 +        return superDesc;
 329.655 +    }
 329.656 +
 329.657 +    /**
 329.658 +     * Returns the "local" class descriptor for the class associated with this
 329.659 +     * class descriptor (i.e., the result of
 329.660 +     * ObjectStreamClass.lookup(this.forClass())) or null if there is no class
 329.661 +     * associated with this descriptor.
 329.662 +     */
 329.663 +    ObjectStreamClass getLocalDesc() {
 329.664 +        return localDesc;
 329.665 +    }
 329.666 +
 329.667 +    /**
 329.668 +     * Returns arrays of ObjectStreamFields representing the serializable
 329.669 +     * fields of the represented class.  If copy is true, a clone of this class
 329.670 +     * descriptor's field array is returned, otherwise the array itself is
 329.671 +     * returned.
 329.672 +     */
 329.673 +    ObjectStreamField[] getFields(boolean copy) {
 329.674 +        return copy ? fields.clone() : fields;
 329.675 +    }
 329.676 +
 329.677 +    /**
 329.678 +     * Looks up a serializable field of the represented class by name and type.
 329.679 +     * A specified type of null matches all types, Object.class matches all
 329.680 +     * non-primitive types, and any other non-null type matches assignable
 329.681 +     * types only.  Returns matching field, or null if no match found.
 329.682 +     */
 329.683 +    ObjectStreamField getField(String name, Class<?> type) {
 329.684 +        for (int i = 0; i < fields.length; i++) {
 329.685 +            ObjectStreamField f = fields[i];
 329.686 +            if (f.getName().equals(name)) {
 329.687 +                if (type == null ||
 329.688 +                    (type == Object.class && !f.isPrimitive()))
 329.689 +                {
 329.690 +                    return f;
 329.691 +                }
 329.692 +                Class<?> ftype = f.getType();
 329.693 +                if (ftype != null && type.isAssignableFrom(ftype)) {
 329.694 +                    return f;
 329.695 +                }
 329.696 +            }
 329.697 +        }
 329.698 +        return null;
 329.699 +    }
 329.700 +
 329.701 +    /**
 329.702 +     * Returns true if class descriptor represents a dynamic proxy class, false
 329.703 +     * otherwise.
 329.704 +     */
 329.705 +    boolean isProxy() {
 329.706 +        return isProxy;
 329.707 +    }
 329.708 +
 329.709 +    /**
 329.710 +     * Returns true if class descriptor represents an enum type, false
 329.711 +     * otherwise.
 329.712 +     */
 329.713 +    boolean isEnum() {
 329.714 +        return isEnum;
 329.715 +    }
 329.716 +
 329.717 +    /**
 329.718 +     * Returns true if represented class implements Externalizable, false
 329.719 +     * otherwise.
 329.720 +     */
 329.721 +    boolean isExternalizable() {
 329.722 +        return externalizable;
 329.723 +    }
 329.724 +
 329.725 +    /**
 329.726 +     * Returns true if represented class implements Serializable, false
 329.727 +     * otherwise.
 329.728 +     */
 329.729 +    boolean isSerializable() {
 329.730 +        return serializable;
 329.731 +    }
 329.732 +
 329.733 +    /**
 329.734 +     * Returns true if class descriptor represents externalizable class that
 329.735 +     * has written its data in 1.2 (block data) format, false otherwise.
 329.736 +     */
 329.737 +    boolean hasBlockExternalData() {
 329.738 +        return hasBlockExternalData;
 329.739 +    }
 329.740 +
 329.741 +    /**
 329.742 +     * Returns true if class descriptor represents serializable (but not
 329.743 +     * externalizable) class which has written its data via a custom
 329.744 +     * writeObject() method, false otherwise.
 329.745 +     */
 329.746 +    boolean hasWriteObjectData() {
 329.747 +        return hasWriteObjectData;
 329.748 +    }
 329.749 +
 329.750 +    /**
 329.751 +     * Returns true if represented class is serializable/externalizable and can
 329.752 +     * be instantiated by the serialization runtime--i.e., if it is
 329.753 +     * externalizable and defines a public no-arg constructor, or if it is
 329.754 +     * non-externalizable and its first non-serializable superclass defines an
 329.755 +     * accessible no-arg constructor.  Otherwise, returns false.
 329.756 +     */
 329.757 +    boolean isInstantiable() {
 329.758 +        return (cons != null);
 329.759 +    }
 329.760 +
 329.761 +    /**
 329.762 +     * Returns true if represented class is serializable (but not
 329.763 +     * externalizable) and defines a conformant writeObject method.  Otherwise,
 329.764 +     * returns false.
 329.765 +     */
 329.766 +    boolean hasWriteObjectMethod() {
 329.767 +        return (writeObjectMethod != null);
 329.768 +    }
 329.769 +
 329.770 +    /**
 329.771 +     * Returns true if represented class is serializable (but not
 329.772 +     * externalizable) and defines a conformant readObject method.  Otherwise,
 329.773 +     * returns false.
 329.774 +     */
 329.775 +    boolean hasReadObjectMethod() {
 329.776 +        return (readObjectMethod != null);
 329.777 +    }
 329.778 +
 329.779 +    /**
 329.780 +     * Returns true if represented class is serializable (but not
 329.781 +     * externalizable) and defines a conformant readObjectNoData method.
 329.782 +     * Otherwise, returns false.
 329.783 +     */
 329.784 +    boolean hasReadObjectNoDataMethod() {
 329.785 +        return (readObjectNoDataMethod != null);
 329.786 +    }
 329.787 +
 329.788 +    /**
 329.789 +     * Returns true if represented class is serializable or externalizable and
 329.790 +     * defines a conformant writeReplace method.  Otherwise, returns false.
 329.791 +     */
 329.792 +    boolean hasWriteReplaceMethod() {
 329.793 +        return (writeReplaceMethod != null);
 329.794 +    }
 329.795 +
 329.796 +    /**
 329.797 +     * Returns true if represented class is serializable or externalizable and
 329.798 +     * defines a conformant readResolve method.  Otherwise, returns false.
 329.799 +     */
 329.800 +    boolean hasReadResolveMethod() {
 329.801 +        return (readResolveMethod != null);
 329.802 +    }
 329.803 +
 329.804 +    /**
 329.805 +     * Creates a new instance of the represented class.  If the class is
 329.806 +     * externalizable, invokes its public no-arg constructor; otherwise, if the
 329.807 +     * class is serializable, invokes the no-arg constructor of the first
 329.808 +     * non-serializable superclass.  Throws UnsupportedOperationException if
 329.809 +     * this class descriptor is not associated with a class, if the associated
 329.810 +     * class is non-serializable or if the appropriate no-arg constructor is
 329.811 +     * inaccessible/unavailable.
 329.812 +     */
 329.813 +    Object newInstance()
 329.814 +        throws InstantiationException, InvocationTargetException,
 329.815 +               UnsupportedOperationException
 329.816 +    {
 329.817 +        if (cons != null) {
 329.818 +            try {
 329.819 +                return cons.newInstance();
 329.820 +            } catch (IllegalAccessException ex) {
 329.821 +                // should not occur, as access checks have been suppressed
 329.822 +                throw new InternalError();
 329.823 +            }
 329.824 +        } else {
 329.825 +            throw new UnsupportedOperationException();
 329.826 +        }
 329.827 +    }
 329.828 +
 329.829 +    /**
 329.830 +     * Invokes the writeObject method of the represented serializable class.
 329.831 +     * Throws UnsupportedOperationException if this class descriptor is not
 329.832 +     * associated with a class, or if the class is externalizable,
 329.833 +     * non-serializable or does not define writeObject.
 329.834 +     */
 329.835 +    void invokeWriteObject(Object obj, ObjectOutputStream out)
 329.836 +        throws IOException, UnsupportedOperationException
 329.837 +    {
 329.838 +        if (writeObjectMethod != null) {
 329.839 +            try {
 329.840 +                writeObjectMethod.invoke(obj, new Object[]{ out });
 329.841 +            } catch (InvocationTargetException ex) {
 329.842 +                Throwable th = ex.getTargetException();
 329.843 +                if (th instanceof IOException) {
 329.844 +                    throw (IOException) th;
 329.845 +                } else {
 329.846 +                    throwMiscException(th);
 329.847 +                }
 329.848 +            } catch (IllegalAccessException ex) {
 329.849 +                // should not occur, as access checks have been suppressed
 329.850 +                throw new InternalError();
 329.851 +            }
 329.852 +        } else {
 329.853 +            throw new UnsupportedOperationException();
 329.854 +        }
 329.855 +    }
 329.856 +
 329.857 +    /**
 329.858 +     * Invokes the readObject method of the represented serializable class.
 329.859 +     * Throws UnsupportedOperationException if this class descriptor is not
 329.860 +     * associated with a class, or if the class is externalizable,
 329.861 +     * non-serializable or does not define readObject.
 329.862 +     */
 329.863 +    void invokeReadObject(Object obj, ObjectInputStream in)
 329.864 +        throws ClassNotFoundException, IOException,
 329.865 +               UnsupportedOperationException
 329.866 +    {
 329.867 +        if (readObjectMethod != null) {
 329.868 +            try {
 329.869 +                readObjectMethod.invoke(obj, new Object[]{ in });
 329.870 +            } catch (InvocationTargetException ex) {
 329.871 +                Throwable th = ex.getTargetException();
 329.872 +                if (th instanceof ClassNotFoundException) {
 329.873 +                    throw (ClassNotFoundException) th;
 329.874 +                } else if (th instanceof IOException) {
 329.875 +                    throw (IOException) th;
 329.876 +                } else {
 329.877 +                    throwMiscException(th);
 329.878 +                }
 329.879 +            } catch (IllegalAccessException ex) {
 329.880 +                // should not occur, as access checks have been suppressed
 329.881 +                throw new InternalError();
 329.882 +            }
 329.883 +        } else {
 329.884 +            throw new UnsupportedOperationException();
 329.885 +        }
 329.886 +    }
 329.887 +
 329.888 +    /**
 329.889 +     * Invokes the readObjectNoData method of the represented serializable
 329.890 +     * class.  Throws UnsupportedOperationException if this class descriptor is
 329.891 +     * not associated with a class, or if the class is externalizable,
 329.892 +     * non-serializable or does not define readObjectNoData.
 329.893 +     */
 329.894 +    void invokeReadObjectNoData(Object obj)
 329.895 +        throws IOException, UnsupportedOperationException
 329.896 +    {
 329.897 +        if (readObjectNoDataMethod != null) {
 329.898 +            try {
 329.899 +                readObjectNoDataMethod.invoke(obj, (Object[]) null);
 329.900 +            } catch (InvocationTargetException ex) {
 329.901 +                Throwable th = ex.getTargetException();
 329.902 +                if (th instanceof ObjectStreamException) {
 329.903 +                    throw (ObjectStreamException) th;
 329.904 +                } else {
 329.905 +                    throwMiscException(th);
 329.906 +                }
 329.907 +            } catch (IllegalAccessException ex) {
 329.908 +                // should not occur, as access checks have been suppressed
 329.909 +                throw new InternalError();
 329.910 +            }
 329.911 +        } else {
 329.912 +            throw new UnsupportedOperationException();
 329.913 +        }
 329.914 +    }
 329.915 +
 329.916 +    /**
 329.917 +     * Invokes the writeReplace method of the represented serializable class and
 329.918 +     * returns the result.  Throws UnsupportedOperationException if this class
 329.919 +     * descriptor is not associated with a class, or if the class is
 329.920 +     * non-serializable or does not define writeReplace.
 329.921 +     */
 329.922 +    Object invokeWriteReplace(Object obj)
 329.923 +        throws IOException, UnsupportedOperationException
 329.924 +    {
 329.925 +        if (writeReplaceMethod != null) {
 329.926 +            try {
 329.927 +                return writeReplaceMethod.invoke(obj, (Object[]) null);
 329.928 +            } catch (InvocationTargetException ex) {
 329.929 +                Throwable th = ex.getTargetException();
 329.930 +                if (th instanceof ObjectStreamException) {
 329.931 +                    throw (ObjectStreamException) th;
 329.932 +                } else {
 329.933 +                    throwMiscException(th);
 329.934 +                    throw new InternalError();  // never reached
 329.935 +                }
 329.936 +            } catch (IllegalAccessException ex) {
 329.937 +                // should not occur, as access checks have been suppressed
 329.938 +                throw new InternalError();
 329.939 +            }
 329.940 +        } else {
 329.941 +            throw new UnsupportedOperationException();
 329.942 +        }
 329.943 +    }
 329.944 +
 329.945 +    /**
 329.946 +     * Invokes the readResolve method of the represented serializable class and
 329.947 +     * returns the result.  Throws UnsupportedOperationException if this class
 329.948 +     * descriptor is not associated with a class, or if the class is
 329.949 +     * non-serializable or does not define readResolve.
 329.950 +     */
 329.951 +    Object invokeReadResolve(Object obj)
 329.952 +        throws IOException, UnsupportedOperationException
 329.953 +    {
 329.954 +        if (readResolveMethod != null) {
 329.955 +            try {
 329.956 +                return readResolveMethod.invoke(obj, (Object[]) null);
 329.957 +            } catch (InvocationTargetException ex) {
 329.958 +                Throwable th = ex.getTargetException();
 329.959 +                if (th instanceof ObjectStreamException) {
 329.960 +                    throw (ObjectStreamException) th;
 329.961 +                } else {
 329.962 +                    throwMiscException(th);
 329.963 +                    throw new InternalError();  // never reached
 329.964 +                }
 329.965 +            } catch (IllegalAccessException ex) {
 329.966 +                // should not occur, as access checks have been suppressed
 329.967 +                throw new InternalError();
 329.968 +            }
 329.969 +        } else {
 329.970 +            throw new UnsupportedOperationException();
 329.971 +        }
 329.972 +    }
 329.973 +
 329.974 +    /**
 329.975 +     * Class representing the portion of an object's serialized form allotted
 329.976 +     * to data described by a given class descriptor.  If "hasData" is false,
 329.977 +     * the object's serialized form does not contain data associated with the
 329.978 +     * class descriptor.
 329.979 +     */
 329.980 +    static class ClassDataSlot {
 329.981 +
 329.982 +        /** class descriptor "occupying" this slot */
 329.983 +        final ObjectStreamClass desc;
 329.984 +        /** true if serialized form includes data for this slot's descriptor */
 329.985 +        final boolean hasData;
 329.986 +
 329.987 +        ClassDataSlot(ObjectStreamClass desc, boolean hasData) {
 329.988 +            this.desc = desc;
 329.989 +            this.hasData = hasData;
 329.990 +        }
 329.991 +    }
 329.992 +
 329.993 +    /**
 329.994 +     * Returns array of ClassDataSlot instances representing the data layout
 329.995 +     * (including superclass data) for serialized objects described by this
 329.996 +     * class descriptor.  ClassDataSlots are ordered by inheritance with those
 329.997 +     * containing "higher" superclasses appearing first.  The final
 329.998 +     * ClassDataSlot contains a reference to this descriptor.
 329.999 +     */
329.1000 +    ClassDataSlot[] getClassDataLayout() throws InvalidClassException {
329.1001 +        // REMIND: synchronize instead of relying on volatile?
329.1002 +        if (dataLayout == null) {
329.1003 +            dataLayout = getClassDataLayout0();
329.1004 +        }
329.1005 +        return dataLayout;
329.1006 +    }
329.1007 +
329.1008 +    private ClassDataSlot[] getClassDataLayout0()
329.1009 +        throws InvalidClassException
329.1010 +    {
329.1011 +        ArrayList<ClassDataSlot> slots = new ArrayList<>();
329.1012 +        Class<?> start = cl, end = cl;
329.1013 +
329.1014 +        // locate closest non-serializable superclass
329.1015 +        while (end != null && Serializable.class.isAssignableFrom(end)) {
329.1016 +            end = end.getSuperclass();
329.1017 +        }
329.1018 +
329.1019 +        for (ObjectStreamClass d = this; d != null; d = d.superDesc) {
329.1020 +
329.1021 +            // search up inheritance hierarchy for class with matching name
329.1022 +            String searchName = (d.cl != null) ? d.cl.getName() : d.name;
329.1023 +            Class<?> match = null;
329.1024 +            for (Class<?> c = start; c != end; c = c.getSuperclass()) {
329.1025 +                if (searchName.equals(c.getName())) {
329.1026 +                    match = c;
329.1027 +                    break;
329.1028 +                }
329.1029 +            }
329.1030 +
329.1031 +            // add "no data" slot for each unmatched class below match
329.1032 +            if (match != null) {
329.1033 +                for (Class<?> c = start; c != match; c = c.getSuperclass()) {
329.1034 +                    slots.add(new ClassDataSlot(
329.1035 +                        ObjectStreamClass.lookup(c, true), false));
329.1036 +                }
329.1037 +                start = match.getSuperclass();
329.1038 +            }
329.1039 +
329.1040 +            // record descriptor/class pairing
329.1041 +            slots.add(new ClassDataSlot(d.getVariantFor(match), true));
329.1042 +        }
329.1043 +
329.1044 +        // add "no data" slot for any leftover unmatched classes
329.1045 +        for (Class<?> c = start; c != end; c = c.getSuperclass()) {
329.1046 +            slots.add(new ClassDataSlot(
329.1047 +                ObjectStreamClass.lookup(c, true), false));
329.1048 +        }
329.1049 +
329.1050 +        // order slots from superclass -> subclass
329.1051 +        Collections.reverse(slots);
329.1052 +        return slots.toArray(new ClassDataSlot[slots.size()]);
329.1053 +    }
329.1054 +
329.1055 +    /**
329.1056 +     * Returns aggregate size (in bytes) of marshalled primitive field values
329.1057 +     * for represented class.
329.1058 +     */
329.1059 +    int getPrimDataSize() {
329.1060 +        return primDataSize;
329.1061 +    }
329.1062 +
329.1063 +    /**
329.1064 +     * Returns number of non-primitive serializable fields of represented
329.1065 +     * class.
329.1066 +     */
329.1067 +    int getNumObjFields() {
329.1068 +        return numObjFields;
329.1069 +    }
329.1070 +
329.1071 +    /**
329.1072 +     * Fetches the serializable primitive field values of object obj and
329.1073 +     * marshals them into byte array buf starting at offset 0.  It is the
329.1074 +     * responsibility of the caller to ensure that obj is of the proper type if
329.1075 +     * non-null.
329.1076 +     */
329.1077 +    void getPrimFieldValues(Object obj, byte[] buf) {
329.1078 +    }
329.1079 +
329.1080 +    /**
329.1081 +     * Sets the serializable primitive fields of object obj using values
329.1082 +     * unmarshalled from byte array buf starting at offset 0.  It is the
329.1083 +     * responsibility of the caller to ensure that obj is of the proper type if
329.1084 +     * non-null.
329.1085 +     */
329.1086 +    void setPrimFieldValues(Object obj, byte[] buf) {
329.1087 +    }
329.1088 +
329.1089 +    /**
329.1090 +     * Fetches the serializable object field values of object obj and stores
329.1091 +     * them in array vals starting at offset 0.  It is the responsibility of
329.1092 +     * the caller to ensure that obj is of the proper type if non-null.
329.1093 +     */
329.1094 +    void getObjFieldValues(Object obj, Object[] vals) {
329.1095 +    }
329.1096 +
329.1097 +    /**
329.1098 +     * Sets the serializable object fields of object obj using values from
329.1099 +     * array vals starting at offset 0.  It is the responsibility of the caller
329.1100 +     * to ensure that obj is of the proper type if non-null.
329.1101 +     */
329.1102 +    void setObjFieldValues(Object obj, Object[] vals) {
329.1103 +    }
329.1104 +
329.1105 +    /**
329.1106 +     * Calculates and sets serializable field offsets, as well as primitive
329.1107 +     * data size and object field count totals.  Throws InvalidClassException
329.1108 +     * if fields are illegally ordered.
329.1109 +     */
329.1110 +    private void computeFieldOffsets() throws InvalidClassException {
329.1111 +        primDataSize = 0;
329.1112 +        numObjFields = 0;
329.1113 +        int firstObjIndex = -1;
329.1114 +
329.1115 +        for (int i = 0; i < fields.length; i++) {
329.1116 +            ObjectStreamField f = fields[i];
329.1117 +            switch (f.getTypeCode()) {
329.1118 +                case 'Z':
329.1119 +                case 'B':
329.1120 +                    f.setOffset(primDataSize++);
329.1121 +                    break;
329.1122 +
329.1123 +                case 'C':
329.1124 +                case 'S':
329.1125 +                    f.setOffset(primDataSize);
329.1126 +                    primDataSize += 2;
329.1127 +                    break;
329.1128 +
329.1129 +                case 'I':
329.1130 +                case 'F':
329.1131 +                    f.setOffset(primDataSize);
329.1132 +                    primDataSize += 4;
329.1133 +                    break;
329.1134 +
329.1135 +                case 'J':
329.1136 +                case 'D':
329.1137 +                    f.setOffset(primDataSize);
329.1138 +                    primDataSize += 8;
329.1139 +                    break;
329.1140 +
329.1141 +                case '[':
329.1142 +                case 'L':
329.1143 +                    f.setOffset(numObjFields++);
329.1144 +                    if (firstObjIndex == -1) {
329.1145 +                        firstObjIndex = i;
329.1146 +                    }
329.1147 +                    break;
329.1148 +
329.1149 +                default:
329.1150 +                    throw new InternalError();
329.1151 +            }
329.1152 +        }
329.1153 +        if (firstObjIndex != -1 &&
329.1154 +            firstObjIndex + numObjFields != fields.length)
329.1155 +        {
329.1156 +            throw new InvalidClassException(name, "illegal field order");
329.1157 +        }
329.1158 +    }
329.1159 +
329.1160 +    /**
329.1161 +     * If given class is the same as the class associated with this class
329.1162 +     * descriptor, returns reference to this class descriptor.  Otherwise,
329.1163 +     * returns variant of this class descriptor bound to given class.
329.1164 +     */
329.1165 +    private ObjectStreamClass getVariantFor(Class<?> cl)
329.1166 +        throws InvalidClassException
329.1167 +    {
329.1168 +        if (this.cl == cl) {
329.1169 +            return this;
329.1170 +        }
329.1171 +        ObjectStreamClass desc = new ObjectStreamClass();
329.1172 +        if (isProxy) {
329.1173 +            desc.initProxy(cl, null, superDesc);
329.1174 +        } else {
329.1175 +            desc.initNonProxy(this, cl, null, superDesc);
329.1176 +        }
329.1177 +        return desc;
329.1178 +    }
329.1179 +
329.1180 +    /**
329.1181 +     * Returns public no-arg constructor of given class, or null if none found.
329.1182 +     * Access checks are disabled on the returned constructor (if any), since
329.1183 +     * the defining class may still be non-public.
329.1184 +     */
329.1185 +    private static Constructor getExternalizableConstructor(Class<?> cl) {
329.1186 +        throw new SecurityException();
329.1187 +    }
329.1188 +
329.1189 +    /**
329.1190 +     * Returns subclass-accessible no-arg constructor of first non-serializable
329.1191 +     * superclass, or null if none found.  Access checks are disabled on the
329.1192 +     * returned constructor (if any).
329.1193 +     */
329.1194 +    private static Constructor getSerializableConstructor(Class<?> cl) {
329.1195 +        Class<?> initCl = cl;
329.1196 +        while (Serializable.class.isAssignableFrom(initCl)) {
329.1197 +            if ((initCl = initCl.getSuperclass()) == null) {
329.1198 +                return null;
329.1199 +            }
329.1200 +        }
329.1201 +        throw new SecurityException();
329.1202 +    }
329.1203 +
329.1204 +    /**
329.1205 +     * Returns non-static, non-abstract method with given signature provided it
329.1206 +     * is defined by or accessible (via inheritance) by the given class, or
329.1207 +     * null if no match found.  Access checks are disabled on the returned
329.1208 +     * method (if any).
329.1209 +     */
329.1210 +    private static Method getInheritableMethod(Class<?> cl, String name,
329.1211 +                                               Class<?>[] argTypes,
329.1212 +                                               Class<?> returnType)
329.1213 +    {
329.1214 +        throw new SecurityException();
329.1215 +    }
329.1216 +
329.1217 +    /**
329.1218 +     * Returns non-static private method with given signature defined by given
329.1219 +     * class, or null if none found.  Access checks are disabled on the
329.1220 +     * returned method (if any).
329.1221 +     */
329.1222 +    private static Method getPrivateMethod(Class<?> cl, String name,
329.1223 +                                           Class<?>[] argTypes,
329.1224 +                                           Class<?> returnType)
329.1225 +    {
329.1226 +        throw new SecurityException();
329.1227 +    }
329.1228 +
329.1229 +    /**
329.1230 +     * Returns true if classes are defined in the same runtime package, false
329.1231 +     * otherwise.
329.1232 +     */
329.1233 +    private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
329.1234 +        return (cl1.getClassLoader() == cl2.getClassLoader() &&
329.1235 +                getPackageName(cl1).equals(getPackageName(cl2)));
329.1236 +    }
329.1237 +
329.1238 +    /**
329.1239 +     * Returns package name of given class.
329.1240 +     */
329.1241 +    private static String getPackageName(Class<?> cl) {
329.1242 +        String s = cl.getName();
329.1243 +        int i = s.lastIndexOf('[');
329.1244 +        if (i >= 0) {
329.1245 +            s = s.substring(i + 2);
329.1246 +        }
329.1247 +        i = s.lastIndexOf('.');
329.1248 +        return (i >= 0) ? s.substring(0, i) : "";
329.1249 +    }
329.1250 +
329.1251 +    /**
329.1252 +     * Compares class names for equality, ignoring package names.  Returns true
329.1253 +     * if class names equal, false otherwise.
329.1254 +     */
329.1255 +    private static boolean classNamesEqual(String name1, String name2) {
329.1256 +        name1 = name1.substring(name1.lastIndexOf('.') + 1);
329.1257 +        name2 = name2.substring(name2.lastIndexOf('.') + 1);
329.1258 +        return name1.equals(name2);
329.1259 +    }
329.1260 +
329.1261 +    /**
329.1262 +     * Returns JVM type signature for given class.
329.1263 +     */
329.1264 +    private static String getClassSignature(Class<?> cl) {
329.1265 +        StringBuilder sbuf = new StringBuilder();
329.1266 +        while (cl.isArray()) {
329.1267 +            sbuf.append('[');
329.1268 +            cl = cl.getComponentType();
329.1269 +        }
329.1270 +        if (cl.isPrimitive()) {
329.1271 +            if (cl == Integer.TYPE) {
329.1272 +                sbuf.append('I');
329.1273 +            } else if (cl == Byte.TYPE) {
329.1274 +                sbuf.append('B');
329.1275 +            } else if (cl == Long.TYPE) {
329.1276 +                sbuf.append('J');
329.1277 +            } else if (cl == Float.TYPE) {
329.1278 +                sbuf.append('F');
329.1279 +            } else if (cl == Double.TYPE) {
329.1280 +                sbuf.append('D');
329.1281 +            } else if (cl == Short.TYPE) {
329.1282 +                sbuf.append('S');
329.1283 +            } else if (cl == Character.TYPE) {
329.1284 +                sbuf.append('C');
329.1285 +            } else if (cl == Boolean.TYPE) {
329.1286 +                sbuf.append('Z');
329.1287 +            } else if (cl == Void.TYPE) {
329.1288 +                sbuf.append('V');
329.1289 +            } else {
329.1290 +                throw new InternalError();
329.1291 +            }
329.1292 +        } else {
329.1293 +            sbuf.append('L' + cl.getName().replace('.', '/') + ';');
329.1294 +        }
329.1295 +        return sbuf.toString();
329.1296 +    }
329.1297 +
329.1298 +    /**
329.1299 +     * Returns JVM type signature for given list of parameters and return type.
329.1300 +     */
329.1301 +    private static String getMethodSignature(Class<?>[] paramTypes,
329.1302 +                                             Class<?> retType)
329.1303 +    {
329.1304 +        StringBuilder sbuf = new StringBuilder();
329.1305 +        sbuf.append('(');
329.1306 +        for (int i = 0; i < paramTypes.length; i++) {
329.1307 +            sbuf.append(getClassSignature(paramTypes[i]));
329.1308 +        }
329.1309 +        sbuf.append(')');
329.1310 +        sbuf.append(getClassSignature(retType));
329.1311 +        return sbuf.toString();
329.1312 +    }
329.1313 +
329.1314 +    /**
329.1315 +     * Convenience method for throwing an exception that is either a
329.1316 +     * RuntimeException, Error, or of some unexpected type (in which case it is
329.1317 +     * wrapped inside an IOException).
329.1318 +     */
329.1319 +    private static void throwMiscException(Throwable th) throws IOException {
329.1320 +        if (th instanceof RuntimeException) {
329.1321 +            throw (RuntimeException) th;
329.1322 +        } else if (th instanceof Error) {
329.1323 +            throw (Error) th;
329.1324 +        } else {
329.1325 +            IOException ex = new IOException("unexpected exception type");
329.1326 +            ex.initCause(th);
329.1327 +            throw ex;
329.1328 +        }
329.1329 +    }
329.1330 +
329.1331 +    /**
329.1332 +     * Returns ObjectStreamField array describing the serializable fields of
329.1333 +     * the given class.  Serializable fields backed by an actual field of the
329.1334 +     * class are represented by ObjectStreamFields with corresponding non-null
329.1335 +     * Field objects.  Throws InvalidClassException if the (explicitly
329.1336 +     * declared) serializable fields are invalid.
329.1337 +     */
329.1338 +    private static ObjectStreamField[] getSerialFields(Class<?> cl)
329.1339 +        throws InvalidClassException
329.1340 +    {
329.1341 +        ObjectStreamField[] fields;
329.1342 +        if (Serializable.class.isAssignableFrom(cl) &&
329.1343 +            !Externalizable.class.isAssignableFrom(cl) &&
329.1344 +            !Proxy.isProxyClass(cl) &&
329.1345 +            !cl.isInterface())
329.1346 +        {
329.1347 +            if ((fields = getDeclaredSerialFields(cl)) == null) {
329.1348 +                fields = getDefaultSerialFields(cl);
329.1349 +            }
329.1350 +            Arrays.sort(fields);
329.1351 +        } else {
329.1352 +            fields = NO_FIELDS;
329.1353 +        }
329.1354 +        return fields;
329.1355 +    }
329.1356 +
329.1357 +    /**
329.1358 +     * Returns serializable fields of given class as defined explicitly by a
329.1359 +     * "serialPersistentFields" field, or null if no appropriate
329.1360 +     * "serialPersistentFields" field is defined.  Serializable fields backed
329.1361 +     * by an actual field of the class are represented by ObjectStreamFields
329.1362 +     * with corresponding non-null Field objects.  For compatibility with past
329.1363 +     * releases, a "serialPersistentFields" field with a null value is
329.1364 +     * considered equivalent to not declaring "serialPersistentFields".  Throws
329.1365 +     * InvalidClassException if the declared serializable fields are
329.1366 +     * invalid--e.g., if multiple fields share the same name.
329.1367 +     */
329.1368 +    private static ObjectStreamField[] getDeclaredSerialFields(Class<?> cl)
329.1369 +        throws InvalidClassException
329.1370 +    {
329.1371 +        throw new SecurityException();
329.1372 +    }
329.1373 +
329.1374 +    /**
329.1375 +     * Returns array of ObjectStreamFields corresponding to all non-static
329.1376 +     * non-transient fields declared by given class.  Each ObjectStreamField
329.1377 +     * contains a Field object for the field it represents.  If no default
329.1378 +     * serializable fields exist, NO_FIELDS is returned.
329.1379 +     */
329.1380 +    private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) {
329.1381 +        throw new SecurityException();
329.1382 +    }
329.1383 +
329.1384 +    /**
329.1385 +     * Returns explicit serial version UID value declared by given class, or
329.1386 +     * null if none.
329.1387 +     */
329.1388 +    private static Long getDeclaredSUID(Class<?> cl) {
329.1389 +        return null;
329.1390 +    }
329.1391 +
329.1392 +    /**
329.1393 +     * Computes the default serial version UID value for the given class.
329.1394 +     */
329.1395 +    private static long computeDefaultSUID(Class<?> cl) {
329.1396 +        throw new SecurityException();
329.1397 +    }
329.1398 +
329.1399 +}
   330.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   330.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectStreamConstants.java	Wed Feb 27 11:24:58 2013 +0100
   330.3 @@ -0,0 +1,215 @@
   330.4 +/*
   330.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   330.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   330.7 + *
   330.8 + * This code is free software; you can redistribute it and/or modify it
   330.9 + * under the terms of the GNU General Public License version 2 only, as
  330.10 + * published by the Free Software Foundation.  Oracle designates this
  330.11 + * particular file as subject to the "Classpath" exception as provided
  330.12 + * by Oracle in the LICENSE file that accompanied this code.
  330.13 + *
  330.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  330.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  330.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  330.17 + * version 2 for more details (a copy is included in the LICENSE file that
  330.18 + * accompanied this code).
  330.19 + *
  330.20 + * You should have received a copy of the GNU General Public License version
  330.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  330.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  330.23 + *
  330.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  330.25 + * or visit www.oracle.com if you need additional information or have any
  330.26 + * questions.
  330.27 + */
  330.28 +
  330.29 +package java.io;
  330.30 +
  330.31 +/**
  330.32 + * Constants written into the Object Serialization Stream.
  330.33 + *
  330.34 + * @author  unascribed
  330.35 + * @since JDK 1.1
  330.36 + */
  330.37 +public interface ObjectStreamConstants {
  330.38 +
  330.39 +    /**
  330.40 +     * Magic number that is written to the stream header.
  330.41 +     */
  330.42 +    final static short STREAM_MAGIC = (short)0xaced;
  330.43 +
  330.44 +    /**
  330.45 +     * Version number that is written to the stream header.
  330.46 +     */
  330.47 +    final static short STREAM_VERSION = 5;
  330.48 +
  330.49 +    /* Each item in the stream is preceded by a tag
  330.50 +     */
  330.51 +
  330.52 +    /**
  330.53 +     * First tag value.
  330.54 +     */
  330.55 +    final static byte TC_BASE = 0x70;
  330.56 +
  330.57 +    /**
  330.58 +     * Null object reference.
  330.59 +     */
  330.60 +    final static byte TC_NULL =         (byte)0x70;
  330.61 +
  330.62 +    /**
  330.63 +     * Reference to an object already written into the stream.
  330.64 +     */
  330.65 +    final static byte TC_REFERENCE =    (byte)0x71;
  330.66 +
  330.67 +    /**
  330.68 +     * new Class Descriptor.
  330.69 +     */
  330.70 +    final static byte TC_CLASSDESC =    (byte)0x72;
  330.71 +
  330.72 +    /**
  330.73 +     * new Object.
  330.74 +     */
  330.75 +    final static byte TC_OBJECT =       (byte)0x73;
  330.76 +
  330.77 +    /**
  330.78 +     * new String.
  330.79 +     */
  330.80 +    final static byte TC_STRING =       (byte)0x74;
  330.81 +
  330.82 +    /**
  330.83 +     * new Array.
  330.84 +     */
  330.85 +    final static byte TC_ARRAY =        (byte)0x75;
  330.86 +
  330.87 +    /**
  330.88 +     * Reference to Class.
  330.89 +     */
  330.90 +    final static byte TC_CLASS =        (byte)0x76;
  330.91 +
  330.92 +    /**
  330.93 +     * Block of optional data. Byte following tag indicates number
  330.94 +     * of bytes in this block data.
  330.95 +     */
  330.96 +    final static byte TC_BLOCKDATA =    (byte)0x77;
  330.97 +
  330.98 +    /**
  330.99 +     * End of optional block data blocks for an object.
 330.100 +     */
 330.101 +    final static byte TC_ENDBLOCKDATA = (byte)0x78;
 330.102 +
 330.103 +    /**
 330.104 +     * Reset stream context. All handles written into stream are reset.
 330.105 +     */
 330.106 +    final static byte TC_RESET =        (byte)0x79;
 330.107 +
 330.108 +    /**
 330.109 +     * long Block data. The long following the tag indicates the
 330.110 +     * number of bytes in this block data.
 330.111 +     */
 330.112 +    final static byte TC_BLOCKDATALONG= (byte)0x7A;
 330.113 +
 330.114 +    /**
 330.115 +     * Exception during write.
 330.116 +     */
 330.117 +    final static byte TC_EXCEPTION =    (byte)0x7B;
 330.118 +
 330.119 +    /**
 330.120 +     * Long string.
 330.121 +     */
 330.122 +    final static byte TC_LONGSTRING =   (byte)0x7C;
 330.123 +
 330.124 +    /**
 330.125 +     * new Proxy Class Descriptor.
 330.126 +     */
 330.127 +    final static byte TC_PROXYCLASSDESC =       (byte)0x7D;
 330.128 +
 330.129 +    /**
 330.130 +     * new Enum constant.
 330.131 +     * @since 1.5
 330.132 +     */
 330.133 +    final static byte TC_ENUM =         (byte)0x7E;
 330.134 +
 330.135 +    /**
 330.136 +     * Last tag value.
 330.137 +     */
 330.138 +    final static byte TC_MAX =          (byte)0x7E;
 330.139 +
 330.140 +    /**
 330.141 +     * First wire handle to be assigned.
 330.142 +     */
 330.143 +    final static int baseWireHandle = 0x7e0000;
 330.144 +
 330.145 +
 330.146 +    /******************************************************/
 330.147 +    /* Bit masks for ObjectStreamClass flag.*/
 330.148 +
 330.149 +    /**
 330.150 +     * Bit mask for ObjectStreamClass flag. Indicates a Serializable class
 330.151 +     * defines its own writeObject method.
 330.152 +     */
 330.153 +    final static byte SC_WRITE_METHOD = 0x01;
 330.154 +
 330.155 +    /**
 330.156 +     * Bit mask for ObjectStreamClass flag. Indicates Externalizable data
 330.157 +     * written in Block Data mode.
 330.158 +     * Added for PROTOCOL_VERSION_2.
 330.159 +     *
 330.160 +     * @see #PROTOCOL_VERSION_2
 330.161 +     * @since 1.2
 330.162 +     */
 330.163 +    final static byte SC_BLOCK_DATA = 0x08;
 330.164 +
 330.165 +    /**
 330.166 +     * Bit mask for ObjectStreamClass flag. Indicates class is Serializable.
 330.167 +     */
 330.168 +    final static byte SC_SERIALIZABLE = 0x02;
 330.169 +
 330.170 +    /**
 330.171 +     * Bit mask for ObjectStreamClass flag. Indicates class is Externalizable.
 330.172 +     */
 330.173 +    final static byte SC_EXTERNALIZABLE = 0x04;
 330.174 +
 330.175 +    /**
 330.176 +     * Bit mask for ObjectStreamClass flag. Indicates class is an enum type.
 330.177 +     * @since 1.5
 330.178 +     */
 330.179 +    final static byte SC_ENUM = 0x10;
 330.180 +
 330.181 +
 330.182 +    /* *******************************************************************/
 330.183 +    /* Security permissions */
 330.184 +
 330.185 +   /**
 330.186 +    * A Stream Protocol Version. <p>
 330.187 +    *
 330.188 +    * All externalizable data is written in JDK 1.1 external data
 330.189 +    * format after calling this method. This version is needed to write
 330.190 +    * streams containing Externalizable data that can be read by
 330.191 +    * pre-JDK 1.1.6 JVMs.
 330.192 +    *
 330.193 +    * @see java.io.ObjectOutputStream#useProtocolVersion(int)
 330.194 +    * @since 1.2
 330.195 +    */
 330.196 +    public final static int PROTOCOL_VERSION_1 = 1;
 330.197 +
 330.198 +
 330.199 +   /**
 330.200 +    * A Stream Protocol Version. <p>
 330.201 +    *
 330.202 +    * This protocol is written by JVM 1.2.
 330.203 +    *
 330.204 +    * Externalizable data is written in block data mode and is
 330.205 +    * terminated with TC_ENDBLOCKDATA. Externalizable classdescriptor
 330.206 +    * flags has SC_BLOCK_DATA enabled. JVM 1.1.6 and greater can
 330.207 +    * read this format change.
 330.208 +    *
 330.209 +    * Enables writing a nonSerializable class descriptor into the
 330.210 +    * stream. The serialVersionUID of a nonSerializable class is
 330.211 +    * set to 0L.
 330.212 +    *
 330.213 +    * @see java.io.ObjectOutputStream#useProtocolVersion(int)
 330.214 +    * @see #SC_BLOCK_DATA
 330.215 +    * @since 1.2
 330.216 +    */
 330.217 +    public final static int PROTOCOL_VERSION_2 = 2;
 330.218 +}
   331.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   331.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectStreamException.java	Wed Feb 27 11:24:58 2013 +0100
   331.3 @@ -0,0 +1,53 @@
   331.4 +/*
   331.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   331.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   331.7 + *
   331.8 + * This code is free software; you can redistribute it and/or modify it
   331.9 + * under the terms of the GNU General Public License version 2 only, as
  331.10 + * published by the Free Software Foundation.  Oracle designates this
  331.11 + * particular file as subject to the "Classpath" exception as provided
  331.12 + * by Oracle in the LICENSE file that accompanied this code.
  331.13 + *
  331.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  331.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  331.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  331.17 + * version 2 for more details (a copy is included in the LICENSE file that
  331.18 + * accompanied this code).
  331.19 + *
  331.20 + * You should have received a copy of the GNU General Public License version
  331.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  331.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  331.23 + *
  331.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  331.25 + * or visit www.oracle.com if you need additional information or have any
  331.26 + * questions.
  331.27 + */
  331.28 +
  331.29 +package java.io;
  331.30 +
  331.31 +/**
  331.32 + * Superclass of all exceptions specific to Object Stream classes.
  331.33 + *
  331.34 + * @author  unascribed
  331.35 + * @since   JDK1.1
  331.36 + */
  331.37 +public abstract class ObjectStreamException extends IOException {
  331.38 +
  331.39 +    private static final long serialVersionUID = 7260898174833392607L;
  331.40 +
  331.41 +    /**
  331.42 +     * Create an ObjectStreamException with the specified argument.
  331.43 +     *
  331.44 +     * @param classname the detailed message for the exception
  331.45 +     */
  331.46 +    protected ObjectStreamException(String classname) {
  331.47 +        super(classname);
  331.48 +    }
  331.49 +
  331.50 +    /**
  331.51 +     * Create an ObjectStreamException.
  331.52 +     */
  331.53 +    protected ObjectStreamException() {
  331.54 +        super();
  331.55 +    }
  331.56 +}
   332.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   332.2 +++ b/rt/emul/compact/src/main/java/java/io/ObjectStreamField.java	Wed Feb 27 11:24:58 2013 +0100
   332.3 @@ -0,0 +1,314 @@
   332.4 +/*
   332.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   332.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   332.7 + *
   332.8 + * This code is free software; you can redistribute it and/or modify it
   332.9 + * under the terms of the GNU General Public License version 2 only, as
  332.10 + * published by the Free Software Foundation.  Oracle designates this
  332.11 + * particular file as subject to the "Classpath" exception as provided
  332.12 + * by Oracle in the LICENSE file that accompanied this code.
  332.13 + *
  332.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  332.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  332.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  332.17 + * version 2 for more details (a copy is included in the LICENSE file that
  332.18 + * accompanied this code).
  332.19 + *
  332.20 + * You should have received a copy of the GNU General Public License version
  332.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  332.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  332.23 + *
  332.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  332.25 + * or visit www.oracle.com if you need additional information or have any
  332.26 + * questions.
  332.27 + */
  332.28 +
  332.29 +package java.io;
  332.30 +
  332.31 +import java.lang.reflect.Field;
  332.32 +
  332.33 +/**
  332.34 + * A description of a Serializable field from a Serializable class.  An array
  332.35 + * of ObjectStreamFields is used to declare the Serializable fields of a class.
  332.36 + *
  332.37 + * @author      Mike Warres
  332.38 + * @author      Roger Riggs
  332.39 + * @see ObjectStreamClass
  332.40 + * @since 1.2
  332.41 + */
  332.42 +public class ObjectStreamField
  332.43 +    implements Comparable<Object>
  332.44 +{
  332.45 +
  332.46 +    /** field name */
  332.47 +    private final String name;
  332.48 +    /** canonical JVM signature of field type */
  332.49 +    private final String signature;
  332.50 +    /** field type (Object.class if unknown non-primitive type) */
  332.51 +    private final Class<?> type;
  332.52 +    /** whether or not to (de)serialize field values as unshared */
  332.53 +    private final boolean unshared;
  332.54 +    /** corresponding reflective field object, if any */
  332.55 +    private final Field field;
  332.56 +    /** offset of field value in enclosing field group */
  332.57 +    private int offset = 0;
  332.58 +
  332.59 +    /**
  332.60 +     * Create a Serializable field with the specified type.  This field should
  332.61 +     * be documented with a <code>serialField</code> tag.
  332.62 +     *
  332.63 +     * @param   name the name of the serializable field
  332.64 +     * @param   type the <code>Class</code> object of the serializable field
  332.65 +     */
  332.66 +    public ObjectStreamField(String name, Class<?> type) {
  332.67 +        this(name, type, false);
  332.68 +    }
  332.69 +
  332.70 +    /**
  332.71 +     * Creates an ObjectStreamField representing a serializable field with the
  332.72 +     * given name and type.  If unshared is false, values of the represented
  332.73 +     * field are serialized and deserialized in the default manner--if the
  332.74 +     * field is non-primitive, object values are serialized and deserialized as
  332.75 +     * if they had been written and read by calls to writeObject and
  332.76 +     * readObject.  If unshared is true, values of the represented field are
  332.77 +     * serialized and deserialized as if they had been written and read by
  332.78 +     * calls to writeUnshared and readUnshared.
  332.79 +     *
  332.80 +     * @param   name field name
  332.81 +     * @param   type field type
  332.82 +     * @param   unshared if false, write/read field values in the same manner
  332.83 +     *          as writeObject/readObject; if true, write/read in the same
  332.84 +     *          manner as writeUnshared/readUnshared
  332.85 +     * @since   1.4
  332.86 +     */
  332.87 +    public ObjectStreamField(String name, Class<?> type, boolean unshared) {
  332.88 +        if (name == null) {
  332.89 +            throw new NullPointerException();
  332.90 +        }
  332.91 +        this.name = name;
  332.92 +        this.type = type;
  332.93 +        this.unshared = unshared;
  332.94 +        signature = getClassSignature(type).intern();
  332.95 +        field = null;
  332.96 +    }
  332.97 +
  332.98 +    /**
  332.99 +     * Creates an ObjectStreamField representing a field with the given name,
 332.100 +     * signature and unshared setting.
 332.101 +     */
 332.102 +    ObjectStreamField(String name, String signature, boolean unshared) {
 332.103 +        if (name == null) {
 332.104 +            throw new NullPointerException();
 332.105 +        }
 332.106 +        this.name = name;
 332.107 +        this.signature = signature.intern();
 332.108 +        this.unshared = unshared;
 332.109 +        field = null;
 332.110 +
 332.111 +        switch (signature.charAt(0)) {
 332.112 +            case 'Z': type = Boolean.TYPE; break;
 332.113 +            case 'B': type = Byte.TYPE; break;
 332.114 +            case 'C': type = Character.TYPE; break;
 332.115 +            case 'S': type = Short.TYPE; break;
 332.116 +            case 'I': type = Integer.TYPE; break;
 332.117 +            case 'J': type = Long.TYPE; break;
 332.118 +            case 'F': type = Float.TYPE; break;
 332.119 +            case 'D': type = Double.TYPE; break;
 332.120 +            case 'L':
 332.121 +            case '[': type = Object.class; break;
 332.122 +            default: throw new IllegalArgumentException("illegal signature");
 332.123 +        }
 332.124 +    }
 332.125 +
 332.126 +    /**
 332.127 +     * Creates an ObjectStreamField representing the given field with the
 332.128 +     * specified unshared setting.  For compatibility with the behavior of
 332.129 +     * earlier serialization implementations, a "showType" parameter is
 332.130 +     * necessary to govern whether or not a getType() call on this
 332.131 +     * ObjectStreamField (if non-primitive) will return Object.class (as
 332.132 +     * opposed to a more specific reference type).
 332.133 +     */
 332.134 +    ObjectStreamField(Field field, boolean unshared, boolean showType) {
 332.135 +        this.field = field;
 332.136 +        this.unshared = unshared;
 332.137 +        name = field.getName();
 332.138 +        Class<?> ftype = field.getType();
 332.139 +        type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
 332.140 +        signature = getClassSignature(ftype).intern();
 332.141 +    }
 332.142 +
 332.143 +    /**
 332.144 +     * Get the name of this field.
 332.145 +     *
 332.146 +     * @return  a <code>String</code> representing the name of the serializable
 332.147 +     *          field
 332.148 +     */
 332.149 +    public String getName() {
 332.150 +        return name;
 332.151 +    }
 332.152 +
 332.153 +    /**
 332.154 +     * Get the type of the field.  If the type is non-primitive and this
 332.155 +     * <code>ObjectStreamField</code> was obtained from a deserialized {@link
 332.156 +     * ObjectStreamClass} instance, then <code>Object.class</code> is returned.
 332.157 +     * Otherwise, the <code>Class</code> object for the type of the field is
 332.158 +     * returned.
 332.159 +     *
 332.160 +     * @return  a <code>Class</code> object representing the type of the
 332.161 +     *          serializable field
 332.162 +     */
 332.163 +    public Class<?> getType() {
 332.164 +        return type;
 332.165 +    }
 332.166 +
 332.167 +    /**
 332.168 +     * Returns character encoding of field type.  The encoding is as follows:
 332.169 +     * <blockquote><pre>
 332.170 +     * B            byte
 332.171 +     * C            char
 332.172 +     * D            double
 332.173 +     * F            float
 332.174 +     * I            int
 332.175 +     * J            long
 332.176 +     * L            class or interface
 332.177 +     * S            short
 332.178 +     * Z            boolean
 332.179 +     * [            array
 332.180 +     * </pre></blockquote>
 332.181 +     *
 332.182 +     * @return  the typecode of the serializable field
 332.183 +     */
 332.184 +    // REMIND: deprecate?
 332.185 +    public char getTypeCode() {
 332.186 +        return signature.charAt(0);
 332.187 +    }
 332.188 +
 332.189 +    /**
 332.190 +     * Return the JVM type signature.
 332.191 +     *
 332.192 +     * @return  null if this field has a primitive type.
 332.193 +     */
 332.194 +    // REMIND: deprecate?
 332.195 +    public String getTypeString() {
 332.196 +        return isPrimitive() ? null : signature;
 332.197 +    }
 332.198 +
 332.199 +    /**
 332.200 +     * Offset of field within instance data.
 332.201 +     *
 332.202 +     * @return  the offset of this field
 332.203 +     * @see #setOffset
 332.204 +     */
 332.205 +    // REMIND: deprecate?
 332.206 +    public int getOffset() {
 332.207 +        return offset;
 332.208 +    }
 332.209 +
 332.210 +    /**
 332.211 +     * Offset within instance data.
 332.212 +     *
 332.213 +     * @param   offset the offset of the field
 332.214 +     * @see #getOffset
 332.215 +     */
 332.216 +    // REMIND: deprecate?
 332.217 +    protected void setOffset(int offset) {
 332.218 +        this.offset = offset;
 332.219 +    }
 332.220 +
 332.221 +    /**
 332.222 +     * Return true if this field has a primitive type.
 332.223 +     *
 332.224 +     * @return  true if and only if this field corresponds to a primitive type
 332.225 +     */
 332.226 +    // REMIND: deprecate?
 332.227 +    public boolean isPrimitive() {
 332.228 +        char tcode = signature.charAt(0);
 332.229 +        return ((tcode != 'L') && (tcode != '['));
 332.230 +    }
 332.231 +
 332.232 +    /**
 332.233 +     * Returns boolean value indicating whether or not the serializable field
 332.234 +     * represented by this ObjectStreamField instance is unshared.
 332.235 +     *
 332.236 +     * @since 1.4
 332.237 +     */
 332.238 +    public boolean isUnshared() {
 332.239 +        return unshared;
 332.240 +    }
 332.241 +
 332.242 +    /**
 332.243 +     * Compare this field with another <code>ObjectStreamField</code>.  Return
 332.244 +     * -1 if this is smaller, 0 if equal, 1 if greater.  Types that are
 332.245 +     * primitives are "smaller" than object types.  If equal, the field names
 332.246 +     * are compared.
 332.247 +     */
 332.248 +    // REMIND: deprecate?
 332.249 +    public int compareTo(Object obj) {
 332.250 +        ObjectStreamField other = (ObjectStreamField) obj;
 332.251 +        boolean isPrim = isPrimitive();
 332.252 +        if (isPrim != other.isPrimitive()) {
 332.253 +            return isPrim ? -1 : 1;
 332.254 +        }
 332.255 +        return name.compareTo(other.name);
 332.256 +    }
 332.257 +
 332.258 +    /**
 332.259 +     * Return a string that describes this field.
 332.260 +     */
 332.261 +    public String toString() {
 332.262 +        return signature + ' ' + name;
 332.263 +    }
 332.264 +
 332.265 +    /**
 332.266 +     * Returns field represented by this ObjectStreamField, or null if
 332.267 +     * ObjectStreamField is not associated with an actual field.
 332.268 +     */
 332.269 +    Field getField() {
 332.270 +        return field;
 332.271 +    }
 332.272 +
 332.273 +    /**
 332.274 +     * Returns JVM type signature of field (similar to getTypeString, except
 332.275 +     * that signature strings are returned for primitive fields as well).
 332.276 +     */
 332.277 +    String getSignature() {
 332.278 +        return signature;
 332.279 +    }
 332.280 +
 332.281 +    /**
 332.282 +     * Returns JVM type signature for given class.
 332.283 +     */
 332.284 +    private static String getClassSignature(Class<?> cl) {
 332.285 +        StringBuilder sbuf = new StringBuilder();
 332.286 +        while (cl.isArray()) {
 332.287 +            sbuf.append('[');
 332.288 +            cl = cl.getComponentType();
 332.289 +        }
 332.290 +        if (cl.isPrimitive()) {
 332.291 +            if (cl == Integer.TYPE) {
 332.292 +                sbuf.append('I');
 332.293 +            } else if (cl == Byte.TYPE) {
 332.294 +                sbuf.append('B');
 332.295 +            } else if (cl == Long.TYPE) {
 332.296 +                sbuf.append('J');
 332.297 +            } else if (cl == Float.TYPE) {
 332.298 +                sbuf.append('F');
 332.299 +            } else if (cl == Double.TYPE) {
 332.300 +                sbuf.append('D');
 332.301 +            } else if (cl == Short.TYPE) {
 332.302 +                sbuf.append('S');
 332.303 +            } else if (cl == Character.TYPE) {
 332.304 +                sbuf.append('C');
 332.305 +            } else if (cl == Boolean.TYPE) {
 332.306 +                sbuf.append('Z');
 332.307 +            } else if (cl == Void.TYPE) {
 332.308 +                sbuf.append('V');
 332.309 +            } else {
 332.310 +                throw new InternalError();
 332.311 +            }
 332.312 +        } else {
 332.313 +            sbuf.append('L' + cl.getName().replace('.', '/') + ';');
 332.314 +        }
 332.315 +        return sbuf.toString();
 332.316 +    }
 332.317 +}
   333.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   333.2 +++ b/rt/emul/compact/src/main/java/java/io/OptionalDataException.java	Wed Feb 27 11:24:58 2013 +0100
   333.3 @@ -0,0 +1,83 @@
   333.4 +/*
   333.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   333.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   333.7 + *
   333.8 + * This code is free software; you can redistribute it and/or modify it
   333.9 + * under the terms of the GNU General Public License version 2 only, as
  333.10 + * published by the Free Software Foundation.  Oracle designates this
  333.11 + * particular file as subject to the "Classpath" exception as provided
  333.12 + * by Oracle in the LICENSE file that accompanied this code.
  333.13 + *
  333.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  333.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  333.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  333.17 + * version 2 for more details (a copy is included in the LICENSE file that
  333.18 + * accompanied this code).
  333.19 + *
  333.20 + * You should have received a copy of the GNU General Public License version
  333.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  333.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  333.23 + *
  333.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  333.25 + * or visit www.oracle.com if you need additional information or have any
  333.26 + * questions.
  333.27 + */
  333.28 +package java.io;
  333.29 +
  333.30 +/**
  333.31 + * Exception indicating the failure of an object read operation due to
  333.32 + * unread primitive data, or the end of data belonging to a serialized
  333.33 + * object in the stream.  This exception may be thrown in two cases:
  333.34 + *
  333.35 + * <ul>
  333.36 + *   <li>An attempt was made to read an object when the next element in the
  333.37 + *       stream is primitive data.  In this case, the OptionalDataException's
  333.38 + *       length field is set to the number of bytes of primitive data
  333.39 + *       immediately readable from the stream, and the eof field is set to
  333.40 + *       false.
  333.41 + *
  333.42 + *   <li>An attempt was made to read past the end of data consumable by a
  333.43 + *       class-defined readObject or readExternal method.  In this case, the
  333.44 + *       OptionalDataException's eof field is set to true, and the length field
  333.45 + *       is set to 0.
  333.46 + * </ul>
  333.47 + *
  333.48 + * @author  unascribed
  333.49 + * @since   JDK1.1
  333.50 + */
  333.51 +public class OptionalDataException extends ObjectStreamException {
  333.52 +
  333.53 +    private static final long serialVersionUID = -8011121865681257820L;
  333.54 +
  333.55 +    /*
  333.56 +     * Create an <code>OptionalDataException</code> with a length.
  333.57 +     */
  333.58 +    OptionalDataException(int len) {
  333.59 +        eof = false;
  333.60 +        length = len;
  333.61 +    }
  333.62 +
  333.63 +    /*
  333.64 +     * Create an <code>OptionalDataException</code> signifying no
  333.65 +     * more primitive data is available.
  333.66 +     */
  333.67 +    OptionalDataException(boolean end) {
  333.68 +        length = 0;
  333.69 +        eof = end;
  333.70 +    }
  333.71 +
  333.72 +    /**
  333.73 +     * The number of bytes of primitive data available to be read
  333.74 +     * in the current buffer.
  333.75 +     *
  333.76 +     * @serial
  333.77 +     */
  333.78 +    public int length;
  333.79 +
  333.80 +    /**
  333.81 +     * True if there is no more data in the buffered part of the stream.
  333.82 +     *
  333.83 +     * @serial
  333.84 +     */
  333.85 +    public boolean eof;
  333.86 +}
   334.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   334.2 +++ b/rt/emul/compact/src/main/java/java/io/OutputStream.java	Wed Feb 27 11:24:58 2013 +0100
   334.3 @@ -0,0 +1,154 @@
   334.4 +/*
   334.5 + * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
   334.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   334.7 + *
   334.8 + * This code is free software; you can redistribute it and/or modify it
   334.9 + * under the terms of the GNU General Public License version 2 only, as
  334.10 + * published by the Free Software Foundation.  Oracle designates this
  334.11 + * particular file as subject to the "Classpath" exception as provided
  334.12 + * by Oracle in the LICENSE file that accompanied this code.
  334.13 + *
  334.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  334.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  334.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  334.17 + * version 2 for more details (a copy is included in the LICENSE file that
  334.18 + * accompanied this code).
  334.19 + *
  334.20 + * You should have received a copy of the GNU General Public License version
  334.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  334.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  334.23 + *
  334.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  334.25 + * or visit www.oracle.com if you need additional information or have any
  334.26 + * questions.
  334.27 + */
  334.28 +
  334.29 +package java.io;
  334.30 +
  334.31 +/**
  334.32 + * This abstract class is the superclass of all classes representing
  334.33 + * an output stream of bytes. An output stream accepts output bytes
  334.34 + * and sends them to some sink.
  334.35 + * <p>
  334.36 + * Applications that need to define a subclass of
  334.37 + * <code>OutputStream</code> must always provide at least a method
  334.38 + * that writes one byte of output.
  334.39 + *
  334.40 + * @author  Arthur van Hoff
  334.41 + * @see     java.io.BufferedOutputStream
  334.42 + * @see     java.io.ByteArrayOutputStream
  334.43 + * @see     java.io.DataOutputStream
  334.44 + * @see     java.io.FilterOutputStream
  334.45 + * @see     java.io.InputStream
  334.46 + * @see     java.io.OutputStream#write(int)
  334.47 + * @since   JDK1.0
  334.48 + */
  334.49 +public abstract class OutputStream implements Closeable, Flushable {
  334.50 +    /**
  334.51 +     * Writes the specified byte to this output stream. The general
  334.52 +     * contract for <code>write</code> is that one byte is written
  334.53 +     * to the output stream. The byte to be written is the eight
  334.54 +     * low-order bits of the argument <code>b</code>. The 24
  334.55 +     * high-order bits of <code>b</code> are ignored.
  334.56 +     * <p>
  334.57 +     * Subclasses of <code>OutputStream</code> must provide an
  334.58 +     * implementation for this method.
  334.59 +     *
  334.60 +     * @param      b   the <code>byte</code>.
  334.61 +     * @exception  IOException  if an I/O error occurs. In particular,
  334.62 +     *             an <code>IOException</code> may be thrown if the
  334.63 +     *             output stream has been closed.
  334.64 +     */
  334.65 +    public abstract void write(int b) throws IOException;
  334.66 +
  334.67 +    /**
  334.68 +     * Writes <code>b.length</code> bytes from the specified byte array
  334.69 +     * to this output stream. The general contract for <code>write(b)</code>
  334.70 +     * is that it should have exactly the same effect as the call
  334.71 +     * <code>write(b, 0, b.length)</code>.
  334.72 +     *
  334.73 +     * @param      b   the data.
  334.74 +     * @exception  IOException  if an I/O error occurs.
  334.75 +     * @see        java.io.OutputStream#write(byte[], int, int)
  334.76 +     */
  334.77 +    public void write(byte b[]) throws IOException {
  334.78 +        write(b, 0, b.length);
  334.79 +    }
  334.80 +
  334.81 +    /**
  334.82 +     * Writes <code>len</code> bytes from the specified byte array
  334.83 +     * starting at offset <code>off</code> to this output stream.
  334.84 +     * The general contract for <code>write(b, off, len)</code> is that
  334.85 +     * some of the bytes in the array <code>b</code> are written to the
  334.86 +     * output stream in order; element <code>b[off]</code> is the first
  334.87 +     * byte written and <code>b[off+len-1]</code> is the last byte written
  334.88 +     * by this operation.
  334.89 +     * <p>
  334.90 +     * The <code>write</code> method of <code>OutputStream</code> calls
  334.91 +     * the write method of one argument on each of the bytes to be
  334.92 +     * written out. Subclasses are encouraged to override this method and
  334.93 +     * provide a more efficient implementation.
  334.94 +     * <p>
  334.95 +     * If <code>b</code> is <code>null</code>, a
  334.96 +     * <code>NullPointerException</code> is thrown.
  334.97 +     * <p>
  334.98 +     * If <code>off</code> is negative, or <code>len</code> is negative, or
  334.99 +     * <code>off+len</code> is greater than the length of the array
 334.100 +     * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
 334.101 +     *
 334.102 +     * @param      b     the data.
 334.103 +     * @param      off   the start offset in the data.
 334.104 +     * @param      len   the number of bytes to write.
 334.105 +     * @exception  IOException  if an I/O error occurs. In particular,
 334.106 +     *             an <code>IOException</code> is thrown if the output
 334.107 +     *             stream is closed.
 334.108 +     */
 334.109 +    public void write(byte b[], int off, int len) throws IOException {
 334.110 +        if (b == null) {
 334.111 +            throw new NullPointerException();
 334.112 +        } else if ((off < 0) || (off > b.length) || (len < 0) ||
 334.113 +                   ((off + len) > b.length) || ((off + len) < 0)) {
 334.114 +            throw new IndexOutOfBoundsException();
 334.115 +        } else if (len == 0) {
 334.116 +            return;
 334.117 +        }
 334.118 +        for (int i = 0 ; i < len ; i++) {
 334.119 +            write(b[off + i]);
 334.120 +        }
 334.121 +    }
 334.122 +
 334.123 +    /**
 334.124 +     * Flushes this output stream and forces any buffered output bytes
 334.125 +     * to be written out. The general contract of <code>flush</code> is
 334.126 +     * that calling it is an indication that, if any bytes previously
 334.127 +     * written have been buffered by the implementation of the output
 334.128 +     * stream, such bytes should immediately be written to their
 334.129 +     * intended destination.
 334.130 +     * <p>
 334.131 +     * If the intended destination of this stream is an abstraction provided by
 334.132 +     * the underlying operating system, for example a file, then flushing the
 334.133 +     * stream guarantees only that bytes previously written to the stream are
 334.134 +     * passed to the operating system for writing; it does not guarantee that
 334.135 +     * they are actually written to a physical device such as a disk drive.
 334.136 +     * <p>
 334.137 +     * The <code>flush</code> method of <code>OutputStream</code> does nothing.
 334.138 +     *
 334.139 +     * @exception  IOException  if an I/O error occurs.
 334.140 +     */
 334.141 +    public void flush() throws IOException {
 334.142 +    }
 334.143 +
 334.144 +    /**
 334.145 +     * Closes this output stream and releases any system resources
 334.146 +     * associated with this stream. The general contract of <code>close</code>
 334.147 +     * is that it closes the output stream. A closed stream cannot perform
 334.148 +     * output operations and cannot be reopened.
 334.149 +     * <p>
 334.150 +     * The <code>close</code> method of <code>OutputStream</code> does nothing.
 334.151 +     *
 334.152 +     * @exception  IOException  if an I/O error occurs.
 334.153 +     */
 334.154 +    public void close() throws IOException {
 334.155 +    }
 334.156 +
 334.157 +}
   335.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   335.2 +++ b/rt/emul/compact/src/main/java/java/io/Reader.java	Wed Feb 27 11:24:58 2013 +0100
   335.3 @@ -0,0 +1,262 @@
   335.4 +/*
   335.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   335.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   335.7 + *
   335.8 + * This code is free software; you can redistribute it and/or modify it
   335.9 + * under the terms of the GNU General Public License version 2 only, as
  335.10 + * published by the Free Software Foundation.  Oracle designates this
  335.11 + * particular file as subject to the "Classpath" exception as provided
  335.12 + * by Oracle in the LICENSE file that accompanied this code.
  335.13 + *
  335.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  335.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  335.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  335.17 + * version 2 for more details (a copy is included in the LICENSE file that
  335.18 + * accompanied this code).
  335.19 + *
  335.20 + * You should have received a copy of the GNU General Public License version
  335.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  335.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  335.23 + *
  335.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  335.25 + * or visit www.oracle.com if you need additional information or have any
  335.26 + * questions.
  335.27 + */
  335.28 +
  335.29 +package java.io;
  335.30 +
  335.31 +
  335.32 +/**
  335.33 + * Abstract class for reading character streams.  The only methods that a
  335.34 + * subclass must implement are read(char[], int, int) and close().  Most
  335.35 + * subclasses, however, will override some of the methods defined here in order
  335.36 + * to provide higher efficiency, additional functionality, or both.
  335.37 + *
  335.38 + *
  335.39 + * @see BufferedReader
  335.40 + * @see   LineNumberReader
  335.41 + * @see CharArrayReader
  335.42 + * @see InputStreamReader
  335.43 + * @see   FileReader
  335.44 + * @see FilterReader
  335.45 + * @see   PushbackReader
  335.46 + * @see PipedReader
  335.47 + * @see StringReader
  335.48 + * @see Writer
  335.49 + *
  335.50 + * @author      Mark Reinhold
  335.51 + * @since       JDK1.1
  335.52 + */
  335.53 +
  335.54 +public abstract class Reader implements Readable, Closeable {
  335.55 +
  335.56 +    /**
  335.57 +     * The object used to synchronize operations on this stream.  For
  335.58 +     * efficiency, a character-stream object may use an object other than
  335.59 +     * itself to protect critical sections.  A subclass should therefore use
  335.60 +     * the object in this field rather than <tt>this</tt> or a synchronized
  335.61 +     * method.
  335.62 +     */
  335.63 +    protected Object lock;
  335.64 +
  335.65 +    /**
  335.66 +     * Creates a new character-stream reader whose critical sections will
  335.67 +     * synchronize on the reader itself.
  335.68 +     */
  335.69 +    protected Reader() {
  335.70 +        this.lock = this;
  335.71 +    }
  335.72 +
  335.73 +    /**
  335.74 +     * Creates a new character-stream reader whose critical sections will
  335.75 +     * synchronize on the given object.
  335.76 +     *
  335.77 +     * @param lock  The Object to synchronize on.
  335.78 +     */
  335.79 +    protected Reader(Object lock) {
  335.80 +        if (lock == null) {
  335.81 +            throw new NullPointerException();
  335.82 +        }
  335.83 +        this.lock = lock;
  335.84 +    }
  335.85 +
  335.86 +    /**
  335.87 +     * Attempts to read characters into the specified character buffer.
  335.88 +     * The buffer is used as a repository of characters as-is: the only
  335.89 +     * changes made are the results of a put operation. No flipping or
  335.90 +     * rewinding of the buffer is performed.
  335.91 +     *
  335.92 +     * @param target the buffer to read characters into
  335.93 +     * @return The number of characters added to the buffer, or
  335.94 +     *         -1 if this source of characters is at its end
  335.95 +     * @throws IOException if an I/O error occurs
  335.96 +     * @throws NullPointerException if target is null
  335.97 +     * @throws ReadOnlyBufferException if target is a read only buffer
  335.98 +     * @since 1.5
  335.99 +     */
 335.100 +//    public int read(java.nio.CharBuffer target) throws IOException {
 335.101 +//        int len = target.remaining();
 335.102 +//        char[] cbuf = new char[len];
 335.103 +//        int n = read(cbuf, 0, len);
 335.104 +//        if (n > 0)
 335.105 +//            target.put(cbuf, 0, n);
 335.106 +//        return n;
 335.107 +//    }
 335.108 +
 335.109 +    /**
 335.110 +     * Reads a single character.  This method will block until a character is
 335.111 +     * available, an I/O error occurs, or the end of the stream is reached.
 335.112 +     *
 335.113 +     * <p> Subclasses that intend to support efficient single-character input
 335.114 +     * should override this method.
 335.115 +     *
 335.116 +     * @return     The character read, as an integer in the range 0 to 65535
 335.117 +     *             (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has
 335.118 +     *             been reached
 335.119 +     *
 335.120 +     * @exception  IOException  If an I/O error occurs
 335.121 +     */
 335.122 +    public int read() throws IOException {
 335.123 +        char cb[] = new char[1];
 335.124 +        if (read(cb, 0, 1) == -1)
 335.125 +            return -1;
 335.126 +        else
 335.127 +            return cb[0];
 335.128 +    }
 335.129 +
 335.130 +    /**
 335.131 +     * Reads characters into an array.  This method will block until some input
 335.132 +     * is available, an I/O error occurs, or the end of the stream is reached.
 335.133 +     *
 335.134 +     * @param       cbuf  Destination buffer
 335.135 +     *
 335.136 +     * @return      The number of characters read, or -1
 335.137 +     *              if the end of the stream
 335.138 +     *              has been reached
 335.139 +     *
 335.140 +     * @exception   IOException  If an I/O error occurs
 335.141 +     */
 335.142 +    public int read(char cbuf[]) throws IOException {
 335.143 +        return read(cbuf, 0, cbuf.length);
 335.144 +    }
 335.145 +
 335.146 +    /**
 335.147 +     * Reads characters into a portion of an array.  This method will block
 335.148 +     * until some input is available, an I/O error occurs, or the end of the
 335.149 +     * stream is reached.
 335.150 +     *
 335.151 +     * @param      cbuf  Destination buffer
 335.152 +     * @param      off   Offset at which to start storing characters
 335.153 +     * @param      len   Maximum number of characters to read
 335.154 +     *
 335.155 +     * @return     The number of characters read, or -1 if the end of the
 335.156 +     *             stream has been reached
 335.157 +     *
 335.158 +     * @exception  IOException  If an I/O error occurs
 335.159 +     */
 335.160 +    abstract public int read(char cbuf[], int off, int len) throws IOException;
 335.161 +
 335.162 +    /** Maximum skip-buffer size */
 335.163 +    private static final int maxSkipBufferSize = 8192;
 335.164 +
 335.165 +    /** Skip buffer, null until allocated */
 335.166 +    private char skipBuffer[] = null;
 335.167 +
 335.168 +    /**
 335.169 +     * Skips characters.  This method will block until some characters are
 335.170 +     * available, an I/O error occurs, or the end of the stream is reached.
 335.171 +     *
 335.172 +     * @param  n  The number of characters to skip
 335.173 +     *
 335.174 +     * @return    The number of characters actually skipped
 335.175 +     *
 335.176 +     * @exception  IllegalArgumentException  If <code>n</code> is negative.
 335.177 +     * @exception  IOException  If an I/O error occurs
 335.178 +     */
 335.179 +    public long skip(long n) throws IOException {
 335.180 +        if (n < 0L)
 335.181 +            throw new IllegalArgumentException("skip value is negative");
 335.182 +        int nn = (int) Math.min(n, maxSkipBufferSize);
 335.183 +        synchronized (lock) {
 335.184 +            if ((skipBuffer == null) || (skipBuffer.length < nn))
 335.185 +                skipBuffer = new char[nn];
 335.186 +            long r = n;
 335.187 +            while (r > 0) {
 335.188 +                int nc = read(skipBuffer, 0, (int)Math.min(r, nn));
 335.189 +                if (nc == -1)
 335.190 +                    break;
 335.191 +                r -= nc;
 335.192 +            }
 335.193 +            return n - r;
 335.194 +        }
 335.195 +    }
 335.196 +
 335.197 +    /**
 335.198 +     * Tells whether this stream is ready to be read.
 335.199 +     *
 335.200 +     * @return True if the next read() is guaranteed not to block for input,
 335.201 +     * false otherwise.  Note that returning false does not guarantee that the
 335.202 +     * next read will block.
 335.203 +     *
 335.204 +     * @exception  IOException  If an I/O error occurs
 335.205 +     */
 335.206 +    public boolean ready() throws IOException {
 335.207 +        return false;
 335.208 +    }
 335.209 +
 335.210 +    /**
 335.211 +     * Tells whether this stream supports the mark() operation. The default
 335.212 +     * implementation always returns false. Subclasses should override this
 335.213 +     * method.
 335.214 +     *
 335.215 +     * @return true if and only if this stream supports the mark operation.
 335.216 +     */
 335.217 +    public boolean markSupported() {
 335.218 +        return false;
 335.219 +    }
 335.220 +
 335.221 +    /**
 335.222 +     * Marks the present position in the stream.  Subsequent calls to reset()
 335.223 +     * will attempt to reposition the stream to this point.  Not all
 335.224 +     * character-input streams support the mark() operation.
 335.225 +     *
 335.226 +     * @param  readAheadLimit  Limit on the number of characters that may be
 335.227 +     *                         read while still preserving the mark.  After
 335.228 +     *                         reading this many characters, attempting to
 335.229 +     *                         reset the stream may fail.
 335.230 +     *
 335.231 +     * @exception  IOException  If the stream does not support mark(),
 335.232 +     *                          or if some other I/O error occurs
 335.233 +     */
 335.234 +    public void mark(int readAheadLimit) throws IOException {
 335.235 +        throw new IOException("mark() not supported");
 335.236 +    }
 335.237 +
 335.238 +    /**
 335.239 +     * Resets the stream.  If the stream has been marked, then attempt to
 335.240 +     * reposition it at the mark.  If the stream has not been marked, then
 335.241 +     * attempt to reset it in some way appropriate to the particular stream,
 335.242 +     * for example by repositioning it to its starting point.  Not all
 335.243 +     * character-input streams support the reset() operation, and some support
 335.244 +     * reset() without supporting mark().
 335.245 +     *
 335.246 +     * @exception  IOException  If the stream has not been marked,
 335.247 +     *                          or if the mark has been invalidated,
 335.248 +     *                          or if the stream does not support reset(),
 335.249 +     *                          or if some other I/O error occurs
 335.250 +     */
 335.251 +    public void reset() throws IOException {
 335.252 +        throw new IOException("reset() not supported");
 335.253 +    }
 335.254 +
 335.255 +    /**
 335.256 +     * Closes the stream and releases any system resources associated with
 335.257 +     * it.  Once the stream has been closed, further read(), ready(),
 335.258 +     * mark(), reset(), or skip() invocations will throw an IOException.
 335.259 +     * Closing a previously closed stream has no effect.
 335.260 +     *
 335.261 +     * @exception  IOException  If an I/O error occurs
 335.262 +     */
 335.263 +     abstract public void close() throws IOException;
 335.264 +
 335.265 +}
   336.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   336.2 +++ b/rt/emul/compact/src/main/java/java/io/StreamCorruptedException.java	Wed Feb 27 11:24:58 2013 +0100
   336.3 @@ -0,0 +1,54 @@
   336.4 +/*
   336.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   336.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   336.7 + *
   336.8 + * This code is free software; you can redistribute it and/or modify it
   336.9 + * under the terms of the GNU General Public License version 2 only, as
  336.10 + * published by the Free Software Foundation.  Oracle designates this
  336.11 + * particular file as subject to the "Classpath" exception as provided
  336.12 + * by Oracle in the LICENSE file that accompanied this code.
  336.13 + *
  336.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  336.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  336.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  336.17 + * version 2 for more details (a copy is included in the LICENSE file that
  336.18 + * accompanied this code).
  336.19 + *
  336.20 + * You should have received a copy of the GNU General Public License version
  336.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  336.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  336.23 + *
  336.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  336.25 + * or visit www.oracle.com if you need additional information or have any
  336.26 + * questions.
  336.27 + */
  336.28 +
  336.29 +package java.io;
  336.30 +
  336.31 +/**
  336.32 + * Thrown when control information that was read from an object stream
  336.33 + * violates internal consistency checks.
  336.34 + *
  336.35 + * @author  unascribed
  336.36 + * @since   JDK1.1
  336.37 + */
  336.38 +public class StreamCorruptedException extends ObjectStreamException {
  336.39 +
  336.40 +    private static final long serialVersionUID = 8983558202217591746L;
  336.41 +
  336.42 +    /**
  336.43 +     * Create a StreamCorruptedException and list a reason why thrown.
  336.44 +     *
  336.45 +     * @param reason  String describing the reason for the exception.
  336.46 +     */
  336.47 +    public StreamCorruptedException(String reason) {
  336.48 +        super(reason);
  336.49 +    }
  336.50 +
  336.51 +    /**
  336.52 +     * Create a StreamCorruptedException and list no reason why thrown.
  336.53 +     */
  336.54 +    public StreamCorruptedException() {
  336.55 +        super();
  336.56 +    }
  336.57 +}
   337.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   337.2 +++ b/rt/emul/compact/src/main/java/java/io/WriteAbortedException.java	Wed Feb 27 11:24:58 2013 +0100
   337.3 @@ -0,0 +1,93 @@
   337.4 +/*
   337.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   337.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   337.7 + *
   337.8 + * This code is free software; you can redistribute it and/or modify it
   337.9 + * under the terms of the GNU General Public License version 2 only, as
  337.10 + * published by the Free Software Foundation.  Oracle designates this
  337.11 + * particular file as subject to the "Classpath" exception as provided
  337.12 + * by Oracle in the LICENSE file that accompanied this code.
  337.13 + *
  337.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  337.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  337.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  337.17 + * version 2 for more details (a copy is included in the LICENSE file that
  337.18 + * accompanied this code).
  337.19 + *
  337.20 + * You should have received a copy of the GNU General Public License version
  337.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  337.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  337.23 + *
  337.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  337.25 + * or visit www.oracle.com if you need additional information or have any
  337.26 + * questions.
  337.27 + */
  337.28 +
  337.29 +package java.io;
  337.30 +
  337.31 +/**
  337.32 + * Signals that one of the ObjectStreamExceptions was thrown during a
  337.33 + * write operation.  Thrown during a read operation when one of the
  337.34 + * ObjectStreamExceptions was thrown during a write operation.  The
  337.35 + * exception that terminated the write can be found in the detail
  337.36 + * field. The stream is reset to it's initial state and all references
  337.37 + * to objects already deserialized are discarded.
  337.38 + *
  337.39 + * <p>As of release 1.4, this exception has been retrofitted to conform to
  337.40 + * the general purpose exception-chaining mechanism.  The "exception causing
  337.41 + * the abort" that is provided at construction time and
  337.42 + * accessed via the public {@link #detail} field is now known as the
  337.43 + * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
  337.44 + * method, as well as the aforementioned "legacy field."
  337.45 + *
  337.46 + * @author  unascribed
  337.47 + * @since   JDK1.1
  337.48 + */
  337.49 +public class WriteAbortedException extends ObjectStreamException {
  337.50 +    private static final long serialVersionUID = -3326426625597282442L;
  337.51 +
  337.52 +    /**
  337.53 +     * Exception that was caught while writing the ObjectStream.
  337.54 +     *
  337.55 +     * <p>This field predates the general-purpose exception chaining facility.
  337.56 +     * The {@link Throwable#getCause()} method is now the preferred means of
  337.57 +     * obtaining this information.
  337.58 +     *
  337.59 +     * @serial
  337.60 +     */
  337.61 +    public Exception detail;
  337.62 +
  337.63 +    /**
  337.64 +     * Constructs a WriteAbortedException with a string describing
  337.65 +     * the exception and the exception causing the abort.
  337.66 +     * @param s   String describing the exception.
  337.67 +     * @param ex  Exception causing the abort.
  337.68 +     */
  337.69 +    public WriteAbortedException(String s, Exception ex) {
  337.70 +        super(s);
  337.71 +        initCause(null);  // Disallow subsequent initCause
  337.72 +        detail = ex;
  337.73 +    }
  337.74 +
  337.75 +    /**
  337.76 +     * Produce the message and include the message from the nested
  337.77 +     * exception, if there is one.
  337.78 +     */
  337.79 +    public String getMessage() {
  337.80 +        if (detail == null)
  337.81 +            return super.getMessage();
  337.82 +        else
  337.83 +            return super.getMessage() + "; " + detail.toString();
  337.84 +    }
  337.85 +
  337.86 +    /**
  337.87 +     * Returns the exception that terminated the operation (the <i>cause</i>).
  337.88 +     *
  337.89 +     * @return  the exception that terminated the operation (the <i>cause</i>),
  337.90 +     *          which may be null.
  337.91 +     * @since   1.4
  337.92 +     */
  337.93 +    public Throwable getCause() {
  337.94 +        return detail;
  337.95 +    }
  337.96 +}
   338.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   338.2 +++ b/rt/emul/compact/src/main/java/java/lang/AbstractMethodError.java	Wed Feb 27 11:24:58 2013 +0100
   338.3 @@ -0,0 +1,58 @@
   338.4 +/*
   338.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   338.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   338.7 + *
   338.8 + * This code is free software; you can redistribute it and/or modify it
   338.9 + * under the terms of the GNU General Public License version 2 only, as
  338.10 + * published by the Free Software Foundation.  Oracle designates this
  338.11 + * particular file as subject to the "Classpath" exception as provided
  338.12 + * by Oracle in the LICENSE file that accompanied this code.
  338.13 + *
  338.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  338.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  338.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  338.17 + * version 2 for more details (a copy is included in the LICENSE file that
  338.18 + * accompanied this code).
  338.19 + *
  338.20 + * You should have received a copy of the GNU General Public License version
  338.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  338.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  338.23 + *
  338.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  338.25 + * or visit www.oracle.com if you need additional information or have any
  338.26 + * questions.
  338.27 + */
  338.28 +
  338.29 +package java.lang;
  338.30 +
  338.31 +/**
  338.32 + * Thrown when an application tries to call an abstract method.
  338.33 + * Normally, this error is caught by the compiler; this error can
  338.34 + * only occur at run time if the definition of some class has
  338.35 + * incompatibly changed since the currently executing method was last
  338.36 + * compiled.
  338.37 + *
  338.38 + * @author  unascribed
  338.39 + * @since   JDK1.0
  338.40 + */
  338.41 +public
  338.42 +class AbstractMethodError extends IncompatibleClassChangeError {
  338.43 +    private static final long serialVersionUID = -1654391082989018462L;
  338.44 +
  338.45 +    /**
  338.46 +     * Constructs an <code>AbstractMethodError</code> with no detail  message.
  338.47 +     */
  338.48 +    public AbstractMethodError() {
  338.49 +        super();
  338.50 +    }
  338.51 +
  338.52 +    /**
  338.53 +     * Constructs an <code>AbstractMethodError</code> with the specified
  338.54 +     * detail message.
  338.55 +     *
  338.56 +     * @param   s   the detail message.
  338.57 +     */
  338.58 +    public AbstractMethodError(String s) {
  338.59 +        super(s);
  338.60 +    }
  338.61 +}
   339.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   339.2 +++ b/rt/emul/compact/src/main/java/java/lang/Cloneable.java	Wed Feb 27 11:24:58 2013 +0100
   339.3 @@ -0,0 +1,54 @@
   339.4 +/*
   339.5 + * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
   339.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   339.7 + *
   339.8 + * This code is free software; you can redistribute it and/or modify it
   339.9 + * under the terms of the GNU General Public License version 2 only, as
  339.10 + * published by the Free Software Foundation.  Oracle designates this
  339.11 + * particular file as subject to the "Classpath" exception as provided
  339.12 + * by Oracle in the LICENSE file that accompanied this code.
  339.13 + *
  339.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  339.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  339.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  339.17 + * version 2 for more details (a copy is included in the LICENSE file that
  339.18 + * accompanied this code).
  339.19 + *
  339.20 + * You should have received a copy of the GNU General Public License version
  339.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  339.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  339.23 + *
  339.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  339.25 + * or visit www.oracle.com if you need additional information or have any
  339.26 + * questions.
  339.27 + */
  339.28 +
  339.29 +package java.lang;
  339.30 +
  339.31 +/**
  339.32 + * A class implements the <code>Cloneable</code> interface to
  339.33 + * indicate to the {@link java.lang.Object#clone()} method that it
  339.34 + * is legal for that method to make a
  339.35 + * field-for-field copy of instances of that class.
  339.36 + * <p>
  339.37 + * Invoking Object's clone method on an instance that does not implement the
  339.38 + * <code>Cloneable</code> interface results in the exception
  339.39 + * <code>CloneNotSupportedException</code> being thrown.
  339.40 + * <p>
  339.41 + * By convention, classes that implement this interface should override
  339.42 + * <tt>Object.clone</tt> (which is protected) with a public method.
  339.43 + * See {@link java.lang.Object#clone()} for details on overriding this
  339.44 + * method.
  339.45 + * <p>
  339.46 + * Note that this interface does <i>not</i> contain the <tt>clone</tt> method.
  339.47 + * Therefore, it is not possible to clone an object merely by virtue of the
  339.48 + * fact that it implements this interface.  Even if the clone method is invoked
  339.49 + * reflectively, there is no guarantee that it will succeed.
  339.50 + *
  339.51 + * @author  unascribed
  339.52 + * @see     java.lang.CloneNotSupportedException
  339.53 + * @see     java.lang.Object#clone()
  339.54 + * @since   JDK1.0
  339.55 + */
  339.56 +public interface Cloneable {
  339.57 +}
   340.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   340.2 +++ b/rt/emul/compact/src/main/java/java/lang/IncompatibleClassChangeError.java	Wed Feb 27 11:24:58 2013 +0100
   340.3 @@ -0,0 +1,57 @@
   340.4 +/*
   340.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   340.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   340.7 + *
   340.8 + * This code is free software; you can redistribute it and/or modify it
   340.9 + * under the terms of the GNU General Public License version 2 only, as
  340.10 + * published by the Free Software Foundation.  Oracle designates this
  340.11 + * particular file as subject to the "Classpath" exception as provided
  340.12 + * by Oracle in the LICENSE file that accompanied this code.
  340.13 + *
  340.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  340.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  340.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  340.17 + * version 2 for more details (a copy is included in the LICENSE file that
  340.18 + * accompanied this code).
  340.19 + *
  340.20 + * You should have received a copy of the GNU General Public License version
  340.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  340.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  340.23 + *
  340.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  340.25 + * or visit www.oracle.com if you need additional information or have any
  340.26 + * questions.
  340.27 + */
  340.28 +
  340.29 +package java.lang;
  340.30 +
  340.31 +/**
  340.32 + * Thrown when an incompatible class change has occurred to some class
  340.33 + * definition. The definition of some class, on which the currently
  340.34 + * executing method depends, has since changed.
  340.35 + *
  340.36 + * @author  unascribed
  340.37 + * @since   JDK1.0
  340.38 + */
  340.39 +public
  340.40 +class IncompatibleClassChangeError extends LinkageError {
  340.41 +    private static final long serialVersionUID = -4914975503642802119L;
  340.42 +
  340.43 +    /**
  340.44 +     * Constructs an <code>IncompatibleClassChangeError</code> with no
  340.45 +     * detail message.
  340.46 +     */
  340.47 +    public IncompatibleClassChangeError () {
  340.48 +        super();
  340.49 +    }
  340.50 +
  340.51 +    /**
  340.52 +     * Constructs an <code>IncompatibleClassChangeError</code> with the
  340.53 +     * specified detail message.
  340.54 +     *
  340.55 +     * @param   s   the detail message.
  340.56 +     */
  340.57 +    public IncompatibleClassChangeError(String s) {
  340.58 +        super(s);
  340.59 +    }
  340.60 +}
   341.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   341.2 +++ b/rt/emul/compact/src/main/java/java/lang/InternalError.java	Wed Feb 27 11:24:58 2013 +0100
   341.3 @@ -0,0 +1,55 @@
   341.4 +/*
   341.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   341.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   341.7 + *
   341.8 + * This code is free software; you can redistribute it and/or modify it
   341.9 + * under the terms of the GNU General Public License version 2 only, as
  341.10 + * published by the Free Software Foundation.  Oracle designates this
  341.11 + * particular file as subject to the "Classpath" exception as provided
  341.12 + * by Oracle in the LICENSE file that accompanied this code.
  341.13 + *
  341.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  341.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  341.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  341.17 + * version 2 for more details (a copy is included in the LICENSE file that
  341.18 + * accompanied this code).
  341.19 + *
  341.20 + * You should have received a copy of the GNU General Public License version
  341.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  341.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  341.23 + *
  341.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  341.25 + * or visit www.oracle.com if you need additional information or have any
  341.26 + * questions.
  341.27 + */
  341.28 +
  341.29 +package java.lang;
  341.30 +
  341.31 +/**
  341.32 + * Thrown to indicate some unexpected internal error has occurred in
  341.33 + * the Java Virtual Machine.
  341.34 + *
  341.35 + * @author  unascribed
  341.36 + * @since   JDK1.0
  341.37 + */
  341.38 +public
  341.39 +class InternalError extends VirtualMachineError {
  341.40 +    private static final long serialVersionUID = -9062593416125562365L;
  341.41 +
  341.42 +    /**
  341.43 +     * Constructs an <code>InternalError</code> with no detail message.
  341.44 +     */
  341.45 +    public InternalError() {
  341.46 +        super();
  341.47 +    }
  341.48 +
  341.49 +    /**
  341.50 +     * Constructs an <code>InternalError</code> with the specified
  341.51 +     * detail message.
  341.52 +     *
  341.53 +     * @param   s   the detail message.
  341.54 +     */
  341.55 +    public InternalError(String s) {
  341.56 +        super(s);
  341.57 +    }
  341.58 +}
   342.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   342.2 +++ b/rt/emul/compact/src/main/java/java/lang/Iterable.java	Wed Feb 27 11:24:58 2013 +0100
   342.3 @@ -0,0 +1,46 @@
   342.4 +/*
   342.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   342.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   342.7 + *
   342.8 + * This code is free software; you can redistribute it and/or modify it
   342.9 + * under the terms of the GNU General Public License version 2 only, as
  342.10 + * published by the Free Software Foundation.  Oracle designates this
  342.11 + * particular file as subject to the "Classpath" exception as provided
  342.12 + * by Oracle in the LICENSE file that accompanied this code.
  342.13 + *
  342.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  342.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  342.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  342.17 + * version 2 for more details (a copy is included in the LICENSE file that
  342.18 + * accompanied this code).
  342.19 + *
  342.20 + * You should have received a copy of the GNU General Public License version
  342.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  342.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  342.23 + *
  342.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  342.25 + * or visit www.oracle.com if you need additional information or have any
  342.26 + * questions.
  342.27 + */
  342.28 +
  342.29 +package java.lang;
  342.30 +
  342.31 +import java.util.Iterator;
  342.32 +
  342.33 +/**
  342.34 + * Implementing this interface allows an object to be the target of
  342.35 + * the "foreach" statement.
  342.36 + *
  342.37 + * @param <T> the type of elements returned by the iterator
  342.38 + *
  342.39 + * @since 1.5
  342.40 + */
  342.41 +public interface Iterable<T> {
  342.42 +
  342.43 +    /**
  342.44 +     * Returns an iterator over a set of elements of type T.
  342.45 +     *
  342.46 +     * @return an Iterator.
  342.47 +     */
  342.48 +    Iterator<T> iterator();
  342.49 +}
   343.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   343.2 +++ b/rt/emul/compact/src/main/java/java/lang/NoSuchFieldError.java	Wed Feb 27 11:24:58 2013 +0100
   343.3 @@ -0,0 +1,59 @@
   343.4 +/*
   343.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   343.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   343.7 + *
   343.8 + * This code is free software; you can redistribute it and/or modify it
   343.9 + * under the terms of the GNU General Public License version 2 only, as
  343.10 + * published by the Free Software Foundation.  Oracle designates this
  343.11 + * particular file as subject to the "Classpath" exception as provided
  343.12 + * by Oracle in the LICENSE file that accompanied this code.
  343.13 + *
  343.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  343.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  343.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  343.17 + * version 2 for more details (a copy is included in the LICENSE file that
  343.18 + * accompanied this code).
  343.19 + *
  343.20 + * You should have received a copy of the GNU General Public License version
  343.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  343.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  343.23 + *
  343.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  343.25 + * or visit www.oracle.com if you need additional information or have any
  343.26 + * questions.
  343.27 + */
  343.28 +
  343.29 +package java.lang;
  343.30 +
  343.31 +/**
  343.32 + * Thrown if an application tries to access or modify a specified
  343.33 + * field of an object, and that object no longer has that field.
  343.34 + * <p>
  343.35 + * Normally, this error is caught by the compiler; this error can
  343.36 + * only occur at run time if the definition of a class has
  343.37 + * incompatibly changed.
  343.38 + *
  343.39 + * @author  unascribed
  343.40 + * @since   JDK1.0
  343.41 + */
  343.42 +public
  343.43 +class NoSuchFieldError extends IncompatibleClassChangeError {
  343.44 +    private static final long serialVersionUID = -3456430195886129035L;
  343.45 +
  343.46 +    /**
  343.47 +     * Constructs a <code>NoSuchFieldError</code> with no detail message.
  343.48 +     */
  343.49 +    public NoSuchFieldError() {
  343.50 +        super();
  343.51 +    }
  343.52 +
  343.53 +    /**
  343.54 +     * Constructs a <code>NoSuchFieldError</code> with the specified
  343.55 +     * detail message.
  343.56 +     *
  343.57 +     * @param   s   the detail message.
  343.58 +     */
  343.59 +    public NoSuchFieldError(String s) {
  343.60 +        super(s);
  343.61 +    }
  343.62 +}
   344.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   344.2 +++ b/rt/emul/compact/src/main/java/java/lang/Readable.java	Wed Feb 27 11:24:58 2013 +0100
   344.3 @@ -0,0 +1,55 @@
   344.4 +/*
   344.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   344.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   344.7 + *
   344.8 + * This code is free software; you can redistribute it and/or modify it
   344.9 + * under the terms of the GNU General Public License version 2 only, as
  344.10 + * published by the Free Software Foundation.  Oracle designates this
  344.11 + * particular file as subject to the "Classpath" exception as provided
  344.12 + * by Oracle in the LICENSE file that accompanied this code.
  344.13 + *
  344.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  344.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  344.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  344.17 + * version 2 for more details (a copy is included in the LICENSE file that
  344.18 + * accompanied this code).
  344.19 + *
  344.20 + * You should have received a copy of the GNU General Public License version
  344.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  344.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  344.23 + *
  344.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  344.25 + * or visit www.oracle.com if you need additional information or have any
  344.26 + * questions.
  344.27 + */
  344.28 +
  344.29 +package java.lang;
  344.30 +
  344.31 +import java.io.IOException;
  344.32 +
  344.33 +/**
  344.34 + * A <tt>Readable</tt> is a source of characters. Characters from
  344.35 + * a <tt>Readable</tt> are made available to callers of the read
  344.36 + * method via a {@link java.nio.CharBuffer CharBuffer}.
  344.37 + *
  344.38 + * @since 1.5
  344.39 + */
  344.40 +
  344.41 +public interface Readable {
  344.42 +
  344.43 +    /**
  344.44 +     * Attempts to read characters into the specified character buffer.
  344.45 +     * The buffer is used as a repository of characters as-is: the only
  344.46 +     * changes made are the results of a put operation. No flipping or
  344.47 +     * rewinding of the buffer is performed.
  344.48 +     *
  344.49 +     * @param cb the buffer to read characters into
  344.50 +     * @return The number of {@code char} values added to the buffer,
  344.51 +     *                 or -1 if this source of characters is at its end
  344.52 +     * @throws IOException if an I/O error occurs
  344.53 +     * @throws NullPointerException if cb is null
  344.54 +     * @throws java.nio.ReadOnlyBufferException if cb is a read only buffer
  344.55 +     */
  344.56 +// XXX:    public int read(java.nio.CharBuffer cb) throws IOException;
  344.57 +
  344.58 +}
   345.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   345.2 +++ b/rt/emul/compact/src/main/java/java/lang/SafeVarargs.java	Wed Feb 27 11:24:58 2013 +0100
   345.3 @@ -0,0 +1,91 @@
   345.4 +/*
   345.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
   345.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   345.7 + *
   345.8 + * This code is free software; you can redistribute it and/or modify it
   345.9 + * under the terms of the GNU General Public License version 2 only, as
  345.10 + * published by the Free Software Foundation.  Oracle designates this
  345.11 + * particular file as subject to the "Classpath" exception as provided
  345.12 + * by Oracle in the LICENSE file that accompanied this code.
  345.13 + *
  345.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  345.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  345.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  345.17 + * version 2 for more details (a copy is included in the LICENSE file that
  345.18 + * accompanied this code).
  345.19 + *
  345.20 + * You should have received a copy of the GNU General Public License version
  345.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  345.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  345.23 + *
  345.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  345.25 + * or visit www.oracle.com if you need additional information or have any
  345.26 + * questions.
  345.27 + */
  345.28 +
  345.29 +package java.lang;
  345.30 +
  345.31 +import java.lang.annotation.*;
  345.32 +
  345.33 +/**
  345.34 + * A programmer assertion that the body of the annotated method or
  345.35 + * constructor does not perform potentially unsafe operations on its
  345.36 + * varargs parameter.  Applying this annotation to a method or
  345.37 + * constructor suppresses unchecked warnings about a
  345.38 + * <i>non-reifiable</i> variable arity (vararg) type and suppresses
  345.39 + * unchecked warnings about parameterized array creation at call
  345.40 + * sites.
  345.41 + *
  345.42 + * <p> In addition to the usage restrictions imposed by its {@link
  345.43 + * Target @Target} meta-annotation, compilers are required to implement
  345.44 + * additional usage restrictions on this annotation type; it is a
  345.45 + * compile-time error if a method or constructor declaration is
  345.46 + * annotated with a {@code @SafeVarargs} annotation, and either:
  345.47 + * <ul>
  345.48 + * <li>  the declaration is a fixed arity method or constructor
  345.49 + *
  345.50 + * <li> the declaration is a variable arity method that is neither
  345.51 + * {@code static} nor {@code final}.
  345.52 + *
  345.53 + * </ul>
  345.54 + *
  345.55 + * <p> Compilers are encouraged to issue warnings when this annotation
  345.56 + * type is applied to a method or constructor declaration where:
  345.57 + *
  345.58 + * <ul>
  345.59 + *
  345.60 + * <li> The variable arity parameter has a reifiable element type,
  345.61 + * which includes primitive types, {@code Object}, and {@code String}.
  345.62 + * (The unchecked warnings this annotation type suppresses already do
  345.63 + * not occur for a reifiable element type.)
  345.64 + *
  345.65 + * <li> The body of the method or constructor declaration performs
  345.66 + * potentially unsafe operations, such as an assignment to an element
  345.67 + * of the variable arity parameter's array that generates an unchecked
  345.68 + * warning.  Some unsafe operations do not trigger an unchecked
  345.69 + * warning.  For example, the aliasing in
  345.70 + *
  345.71 + * <blockquote><pre>
  345.72 + * &#64;SafeVarargs // Not actually safe!
  345.73 + * static void m(List&lt;String&gt;... stringLists) {
  345.74 + *   Object[] array = stringLists;
  345.75 + *   List&lt;Integer&gt; tmpList = Arrays.asList(42);
  345.76 + *   array[0] = tmpList; // Semantically invalid, but compiles without warnings
  345.77 + *   String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime!
  345.78 + * }
  345.79 + * </pre></blockquote>
  345.80 + *
  345.81 + * leads to a {@code ClassCastException} at runtime.
  345.82 + *
  345.83 + * <p>Future versions of the platform may mandate compiler errors for
  345.84 + * such unsafe operations.
  345.85 + *
  345.86 + * </ul>
  345.87 + *
  345.88 + * @jls 4.7 Reifiable Types
  345.89 + * @jls 8.4.1 Formal Parameters
  345.90 + */
  345.91 +@Documented
  345.92 +@Retention(RetentionPolicy.RUNTIME)
  345.93 +@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
  345.94 +public @interface SafeVarargs {}
   346.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   346.2 +++ b/rt/emul/compact/src/main/java/java/lang/SuppressWarnings.java	Wed Feb 27 11:24:58 2013 +0100
   346.3 @@ -0,0 +1,64 @@
   346.4 +/*
   346.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   346.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   346.7 + *
   346.8 + * This code is free software; you can redistribute it and/or modify it
   346.9 + * under the terms of the GNU General Public License version 2 only, as
  346.10 + * published by the Free Software Foundation.  Oracle designates this
  346.11 + * particular file as subject to the "Classpath" exception as provided
  346.12 + * by Oracle in the LICENSE file that accompanied this code.
  346.13 + *
  346.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  346.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  346.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  346.17 + * version 2 for more details (a copy is included in the LICENSE file that
  346.18 + * accompanied this code).
  346.19 + *
  346.20 + * You should have received a copy of the GNU General Public License version
  346.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  346.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  346.23 + *
  346.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  346.25 + * or visit www.oracle.com if you need additional information or have any
  346.26 + * questions.
  346.27 + */
  346.28 +
  346.29 +package java.lang;
  346.30 +
  346.31 +import java.lang.annotation.*;
  346.32 +import static java.lang.annotation.ElementType.*;
  346.33 +
  346.34 +/**
  346.35 + * Indicates that the named compiler warnings should be suppressed in the
  346.36 + * annotated element (and in all program elements contained in the annotated
  346.37 + * element).  Note that the set of warnings suppressed in a given element is
  346.38 + * a superset of the warnings suppressed in all containing elements.  For
  346.39 + * example, if you annotate a class to suppress one warning and annotate a
  346.40 + * method to suppress another, both warnings will be suppressed in the method.
  346.41 + *
  346.42 + * <p>As a matter of style, programmers should always use this annotation
  346.43 + * on the most deeply nested element where it is effective.  If you want to
  346.44 + * suppress a warning in a particular method, you should annotate that
  346.45 + * method rather than its class.
  346.46 + *
  346.47 + * @since 1.5
  346.48 + * @author Josh Bloch
  346.49 + */
  346.50 +@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
  346.51 +@Retention(RetentionPolicy.SOURCE)
  346.52 +public @interface SuppressWarnings {
  346.53 +    /**
  346.54 +     * The set of warnings that are to be suppressed by the compiler in the
  346.55 +     * annotated element.  Duplicate names are permitted.  The second and
  346.56 +     * successive occurrences of a name are ignored.  The presence of
  346.57 +     * unrecognized warning names is <i>not</i> an error: Compilers must
  346.58 +     * ignore any warning names they do not recognize.  They are, however,
  346.59 +     * free to emit a warning if an annotation contains an unrecognized
  346.60 +     * warning name.
  346.61 +     *
  346.62 +     * <p>Compiler vendors should document the warning names they support in
  346.63 +     * conjunction with this annotation type. They are encouraged to cooperate
  346.64 +     * to ensure that the same names work across multiple compilers.
  346.65 +     */
  346.66 +    String[] value();
  346.67 +}
   347.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   347.2 +++ b/rt/emul/compact/src/main/java/java/lang/System.java	Wed Feb 27 11:24:58 2013 +0100
   347.3 @@ -0,0 +1,36 @@
   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 java.lang;
  347.22 +
  347.23 +/** Poor man's re-implementation of most important System methods.
  347.24 + *
  347.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  347.26 + */
  347.27 +public class System {
  347.28 +    private System() {
  347.29 +    }
  347.30 +    
  347.31 +    public static void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count) {
  347.32 +        org.apidesign.bck2brwsr.emul.lang.System.arraycopy(value, srcBegin, dst, dstBegin, count);
  347.33 +    }
  347.34 +    
  347.35 +    public static long currentTimeMillis() {
  347.36 +        return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
  347.37 +    }
  347.38 +    
  347.39 +}
   348.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   348.2 +++ b/rt/emul/compact/src/main/java/java/lang/ref/PhantomReference.java	Wed Feb 27 11:24:58 2013 +0100
   348.3 @@ -0,0 +1,83 @@
   348.4 +/*
   348.5 + * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
   348.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   348.7 + *
   348.8 + * This code is free software; you can redistribute it and/or modify it
   348.9 + * under the terms of the GNU General Public License version 2 only, as
  348.10 + * published by the Free Software Foundation.  Oracle designates this
  348.11 + * particular file as subject to the "Classpath" exception as provided
  348.12 + * by Oracle in the LICENSE file that accompanied this code.
  348.13 + *
  348.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  348.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  348.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  348.17 + * version 2 for more details (a copy is included in the LICENSE file that
  348.18 + * accompanied this code).
  348.19 + *
  348.20 + * You should have received a copy of the GNU General Public License version
  348.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  348.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  348.23 + *
  348.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  348.25 + * or visit www.oracle.com if you need additional information or have any
  348.26 + * questions.
  348.27 + */
  348.28 +
  348.29 +package java.lang.ref;
  348.30 +
  348.31 +
  348.32 +/**
  348.33 + * Phantom reference objects, which are enqueued after the collector
  348.34 + * determines that their referents may otherwise be reclaimed.  Phantom
  348.35 + * references are most often used for scheduling pre-mortem cleanup actions in
  348.36 + * a more flexible way than is possible with the Java finalization mechanism.
  348.37 + *
  348.38 + * <p> If the garbage collector determines at a certain point in time that the
  348.39 + * referent of a phantom reference is <a
  348.40 + * href="package-summary.html#reachability">phantom reachable</a>, then at that
  348.41 + * time or at some later time it will enqueue the reference.
  348.42 + *
  348.43 + * <p> In order to ensure that a reclaimable object remains so, the referent of
  348.44 + * a phantom reference may not be retrieved: The <code>get</code> method of a
  348.45 + * phantom reference always returns <code>null</code>.
  348.46 + *
  348.47 + * <p> Unlike soft and weak references, phantom references are not
  348.48 + * automatically cleared by the garbage collector as they are enqueued.  An
  348.49 + * object that is reachable via phantom references will remain so until all
  348.50 + * such references are cleared or themselves become unreachable.
  348.51 + *
  348.52 + * @author   Mark Reinhold
  348.53 + * @since    1.2
  348.54 + */
  348.55 +
  348.56 +public class PhantomReference<T> extends Reference<T> {
  348.57 +
  348.58 +    /**
  348.59 +     * Returns this reference object's referent.  Because the referent of a
  348.60 +     * phantom reference is always inaccessible, this method always returns
  348.61 +     * <code>null</code>.
  348.62 +     *
  348.63 +     * @return  <code>null</code>
  348.64 +     */
  348.65 +    public T get() {
  348.66 +        return null;
  348.67 +    }
  348.68 +
  348.69 +    /**
  348.70 +     * Creates a new phantom reference that refers to the given object and
  348.71 +     * is registered with the given queue.
  348.72 +     *
  348.73 +     * <p> It is possible to create a phantom reference with a <tt>null</tt>
  348.74 +     * queue, but such a reference is completely useless: Its <tt>get</tt>
  348.75 +     * method will always return null and, since it does not have a queue, it
  348.76 +     * will never be enqueued.
  348.77 +     *
  348.78 +     * @param referent the object the new phantom reference will refer to
  348.79 +     * @param q the queue with which the reference is to be registered,
  348.80 +     *          or <tt>null</tt> if registration is not required
  348.81 +     */
  348.82 +    public PhantomReference(T referent, ReferenceQueue<? super T> q) {
  348.83 +        super(referent, q);
  348.84 +    }
  348.85 +
  348.86 +}
   349.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   349.2 +++ b/rt/emul/compact/src/main/java/java/lang/ref/Reference.java	Wed Feb 27 11:24:58 2013 +0100
   349.3 @@ -0,0 +1,185 @@
   349.4 +/*
   349.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   349.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   349.7 + *
   349.8 + * This code is free software; you can redistribute it and/or modify it
   349.9 + * under the terms of the GNU General Public License version 2 only, as
  349.10 + * published by the Free Software Foundation.  Oracle designates this
  349.11 + * particular file as subject to the "Classpath" exception as provided
  349.12 + * by Oracle in the LICENSE file that accompanied this code.
  349.13 + *
  349.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  349.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  349.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  349.17 + * version 2 for more details (a copy is included in the LICENSE file that
  349.18 + * accompanied this code).
  349.19 + *
  349.20 + * You should have received a copy of the GNU General Public License version
  349.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  349.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  349.23 + *
  349.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  349.25 + * or visit www.oracle.com if you need additional information or have any
  349.26 + * questions.
  349.27 + */
  349.28 +
  349.29 +package java.lang.ref;
  349.30 +
  349.31 +
  349.32 +/**
  349.33 + * Abstract base class for reference objects.  This class defines the
  349.34 + * operations common to all reference objects.  Because reference objects are
  349.35 + * implemented in close cooperation with the garbage collector, this class may
  349.36 + * not be subclassed directly.
  349.37 + *
  349.38 + * @author   Mark Reinhold
  349.39 + * @since    1.2
  349.40 + */
  349.41 +
  349.42 +public abstract class Reference<T> {
  349.43 +
  349.44 +    /* A Reference instance is in one of four possible internal states:
  349.45 +     *
  349.46 +     *     Active: Subject to special treatment by the garbage collector.  Some
  349.47 +     *     time after the collector detects that the reachability of the
  349.48 +     *     referent has changed to the appropriate state, it changes the
  349.49 +     *     instance's state to either Pending or Inactive, depending upon
  349.50 +     *     whether or not the instance was registered with a queue when it was
  349.51 +     *     created.  In the former case it also adds the instance to the
  349.52 +     *     pending-Reference list.  Newly-created instances are Active.
  349.53 +     *
  349.54 +     *     Pending: An element of the pending-Reference list, waiting to be
  349.55 +     *     enqueued by the Reference-handler thread.  Unregistered instances
  349.56 +     *     are never in this state.
  349.57 +     *
  349.58 +     *     Enqueued: An element of the queue with which the instance was
  349.59 +     *     registered when it was created.  When an instance is removed from
  349.60 +     *     its ReferenceQueue, it is made Inactive.  Unregistered instances are
  349.61 +     *     never in this state.
  349.62 +     *
  349.63 +     *     Inactive: Nothing more to do.  Once an instance becomes Inactive its
  349.64 +     *     state will never change again.
  349.65 +     *
  349.66 +     * The state is encoded in the queue and next fields as follows:
  349.67 +     *
  349.68 +     *     Active: queue = ReferenceQueue with which instance is registered, or
  349.69 +     *     ReferenceQueue.NULL if it was not registered with a queue; next =
  349.70 +     *     null.
  349.71 +     *
  349.72 +     *     Pending: queue = ReferenceQueue with which instance is registered;
  349.73 +     *     next = Following instance in queue, or this if at end of list.
  349.74 +     *
  349.75 +     *     Enqueued: queue = ReferenceQueue.ENQUEUED; next = Following instance
  349.76 +     *     in queue, or this if at end of list.
  349.77 +     *
  349.78 +     *     Inactive: queue = ReferenceQueue.NULL; next = this.
  349.79 +     *
  349.80 +     * With this scheme the collector need only examine the next field in order
  349.81 +     * to determine whether a Reference instance requires special treatment: If
  349.82 +     * the next field is null then the instance is active; if it is non-null,
  349.83 +     * then the collector should treat the instance normally.
  349.84 +     *
  349.85 +     * To ensure that concurrent collector can discover active Reference
  349.86 +     * objects without interfering with application threads that may apply
  349.87 +     * the enqueue() method to those objects, collectors should link
  349.88 +     * discovered objects through the discovered field.
  349.89 +     */
  349.90 +
  349.91 +    private T referent;         /* Treated specially by GC */
  349.92 +
  349.93 +    ReferenceQueue<? super T> queue;
  349.94 +
  349.95 +    Reference next;
  349.96 +    transient private Reference<T> discovered;  /* used by VM */
  349.97 +
  349.98 +
  349.99 +    /* Object used to synchronize with the garbage collector.  The collector
 349.100 +     * must acquire this lock at the beginning of each collection cycle.  It is
 349.101 +     * therefore critical that any code holding this lock complete as quickly
 349.102 +     * as possible, allocate no new objects, and avoid calling user code.
 349.103 +     */
 349.104 +    static private class Lock { };
 349.105 +    private static Lock lock = new Lock();
 349.106 +
 349.107 +
 349.108 +    /* List of References waiting to be enqueued.  The collector adds
 349.109 +     * References to this list, while the Reference-handler thread removes
 349.110 +     * them.  This list is protected by the above lock object.
 349.111 +     */
 349.112 +    private static Reference pending = null;
 349.113 +
 349.114 +
 349.115 +
 349.116 +    /* -- Referent accessor and setters -- */
 349.117 +
 349.118 +    /**
 349.119 +     * Returns this reference object's referent.  If this reference object has
 349.120 +     * been cleared, either by the program or by the garbage collector, then
 349.121 +     * this method returns <code>null</code>.
 349.122 +     *
 349.123 +     * @return   The object to which this reference refers, or
 349.124 +     *           <code>null</code> if this reference object has been cleared
 349.125 +     */
 349.126 +    public T get() {
 349.127 +        return this.referent;
 349.128 +    }
 349.129 +
 349.130 +    /**
 349.131 +     * Clears this reference object.  Invoking this method will not cause this
 349.132 +     * object to be enqueued.
 349.133 +     *
 349.134 +     * <p> This method is invoked only by Java code; when the garbage collector
 349.135 +     * clears references it does so directly, without invoking this method.
 349.136 +     */
 349.137 +    public void clear() {
 349.138 +        this.referent = null;
 349.139 +    }
 349.140 +
 349.141 +
 349.142 +    /* -- Queue operations -- */
 349.143 +
 349.144 +    /**
 349.145 +     * Tells whether or not this reference object has been enqueued, either by
 349.146 +     * the program or by the garbage collector.  If this reference object was
 349.147 +     * not registered with a queue when it was created, then this method will
 349.148 +     * always return <code>false</code>.
 349.149 +     *
 349.150 +     * @return   <code>true</code> if and only if this reference object has
 349.151 +     *           been enqueued
 349.152 +     */
 349.153 +    public boolean isEnqueued() {
 349.154 +        /* In terms of the internal states, this predicate actually tests
 349.155 +           whether the instance is either Pending or Enqueued */
 349.156 +        synchronized (this) {
 349.157 +            return (this.queue != ReferenceQueue.NULL) && (this.next != null);
 349.158 +        }
 349.159 +    }
 349.160 +
 349.161 +    /**
 349.162 +     * Adds this reference object to the queue with which it is registered,
 349.163 +     * if any.
 349.164 +     *
 349.165 +     * <p> This method is invoked only by Java code; when the garbage collector
 349.166 +     * enqueues references it does so directly, without invoking this method.
 349.167 +     *
 349.168 +     * @return   <code>true</code> if this reference object was successfully
 349.169 +     *           enqueued; <code>false</code> if it was already enqueued or if
 349.170 +     *           it was not registered with a queue when it was created
 349.171 +     */
 349.172 +    public boolean enqueue() {
 349.173 +        return this.queue.enqueue(this);
 349.174 +    }
 349.175 +
 349.176 +
 349.177 +    /* -- Constructors -- */
 349.178 +
 349.179 +    Reference(T referent) {
 349.180 +        this(referent, null);
 349.181 +    }
 349.182 +
 349.183 +    Reference(T referent, ReferenceQueue<? super T> queue) {
 349.184 +        this.referent = referent;
 349.185 +        this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
 349.186 +    }
 349.187 +
 349.188 +}
   350.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   350.2 +++ b/rt/emul/compact/src/main/java/java/lang/ref/ReferenceQueue.java	Wed Feb 27 11:24:58 2013 +0100
   350.3 @@ -0,0 +1,148 @@
   350.4 +/*
   350.5 + * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
   350.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   350.7 + *
   350.8 + * This code is free software; you can redistribute it and/or modify it
   350.9 + * under the terms of the GNU General Public License version 2 only, as
  350.10 + * published by the Free Software Foundation.  Oracle designates this
  350.11 + * particular file as subject to the "Classpath" exception as provided
  350.12 + * by Oracle in the LICENSE file that accompanied this code.
  350.13 + *
  350.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  350.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  350.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  350.17 + * version 2 for more details (a copy is included in the LICENSE file that
  350.18 + * accompanied this code).
  350.19 + *
  350.20 + * You should have received a copy of the GNU General Public License version
  350.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  350.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  350.23 + *
  350.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  350.25 + * or visit www.oracle.com if you need additional information or have any
  350.26 + * questions.
  350.27 + */
  350.28 +
  350.29 +package java.lang.ref;
  350.30 +
  350.31 +/**
  350.32 + * Reference queues, to which registered reference objects are appended by the
  350.33 + * garbage collector after the appropriate reachability changes are detected.
  350.34 + *
  350.35 + * @author   Mark Reinhold
  350.36 + * @since    1.2
  350.37 + */
  350.38 +
  350.39 +public class ReferenceQueue<T> {
  350.40 +
  350.41 +    /**
  350.42 +     * Constructs a new reference-object queue.
  350.43 +     */
  350.44 +    public ReferenceQueue() { }
  350.45 +
  350.46 +    private static class Null extends ReferenceQueue {
  350.47 +        boolean enqueue(Reference r) {
  350.48 +            return false;
  350.49 +        }
  350.50 +    }
  350.51 +
  350.52 +    static ReferenceQueue NULL = new Null();
  350.53 +    static ReferenceQueue ENQUEUED = new Null();
  350.54 +
  350.55 +    static private class Lock { };
  350.56 +    private Lock lock = new Lock();
  350.57 +    private volatile Reference<? extends T> head = null;
  350.58 +    private long queueLength = 0;
  350.59 +
  350.60 +    boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */
  350.61 +        synchronized (r) {
  350.62 +            if (r.queue == ENQUEUED) return false;
  350.63 +            synchronized (lock) {
  350.64 +                r.queue = ENQUEUED;
  350.65 +                r.next = (head == null) ? r : head;
  350.66 +                head = r;
  350.67 +                queueLength++;
  350.68 +                lock.notifyAll();
  350.69 +                return true;
  350.70 +            }
  350.71 +        }
  350.72 +    }
  350.73 +
  350.74 +    private Reference<? extends T> reallyPoll() {       /* Must hold lock */
  350.75 +        if (head != null) {
  350.76 +            Reference<? extends T> r = head;
  350.77 +            head = (r.next == r) ? null : r.next;
  350.78 +            r.queue = NULL;
  350.79 +            r.next = r;
  350.80 +            queueLength--;
  350.81 +            return r;
  350.82 +        }
  350.83 +        return null;
  350.84 +    }
  350.85 +
  350.86 +    /**
  350.87 +     * Polls this queue to see if a reference object is available.  If one is
  350.88 +     * available without further delay then it is removed from the queue and
  350.89 +     * returned.  Otherwise this method immediately returns <tt>null</tt>.
  350.90 +     *
  350.91 +     * @return  A reference object, if one was immediately available,
  350.92 +     *          otherwise <code>null</code>
  350.93 +     */
  350.94 +    public Reference<? extends T> poll() {
  350.95 +        if (head == null)
  350.96 +            return null;
  350.97 +        synchronized (lock) {
  350.98 +            return reallyPoll();
  350.99 +        }
 350.100 +    }
 350.101 +
 350.102 +    /**
 350.103 +     * Removes the next reference object in this queue, blocking until either
 350.104 +     * one becomes available or the given timeout period expires.
 350.105 +     *
 350.106 +     * <p> This method does not offer real-time guarantees: It schedules the
 350.107 +     * timeout as if by invoking the {@link Object#wait(long)} method.
 350.108 +     *
 350.109 +     * @param  timeout  If positive, block for up to <code>timeout</code>
 350.110 +     *                  milliseconds while waiting for a reference to be
 350.111 +     *                  added to this queue.  If zero, block indefinitely.
 350.112 +     *
 350.113 +     * @return  A reference object, if one was available within the specified
 350.114 +     *          timeout period, otherwise <code>null</code>
 350.115 +     *
 350.116 +     * @throws  IllegalArgumentException
 350.117 +     *          If the value of the timeout argument is negative
 350.118 +     *
 350.119 +     * @throws  InterruptedException
 350.120 +     *          If the timeout wait is interrupted
 350.121 +     */
 350.122 +    public Reference<? extends T> remove(long timeout)
 350.123 +        throws IllegalArgumentException, InterruptedException
 350.124 +    {
 350.125 +        if (timeout < 0) {
 350.126 +            throw new IllegalArgumentException("Negative timeout value");
 350.127 +        }
 350.128 +        synchronized (lock) {
 350.129 +            Reference<? extends T> r = reallyPoll();
 350.130 +            if (r != null) return r;
 350.131 +            for (;;) {
 350.132 +                lock.wait(timeout);
 350.133 +                r = reallyPoll();
 350.134 +                if (r != null) return r;
 350.135 +                if (timeout != 0) return null;
 350.136 +            }
 350.137 +        }
 350.138 +    }
 350.139 +
 350.140 +    /**
 350.141 +     * Removes the next reference object in this queue, blocking until one
 350.142 +     * becomes available.
 350.143 +     *
 350.144 +     * @return A reference object, blocking until one becomes available
 350.145 +     * @throws  InterruptedException  If the wait is interrupted
 350.146 +     */
 350.147 +    public Reference<? extends T> remove() throws InterruptedException {
 350.148 +        return remove(0);
 350.149 +    }
 350.150 +
 350.151 +}
   351.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   351.2 +++ b/rt/emul/compact/src/main/java/java/lang/ref/SoftReference.java	Wed Feb 27 11:24:58 2013 +0100
   351.3 @@ -0,0 +1,118 @@
   351.4 +/*
   351.5 + * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
   351.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   351.7 + *
   351.8 + * This code is free software; you can redistribute it and/or modify it
   351.9 + * under the terms of the GNU General Public License version 2 only, as
  351.10 + * published by the Free Software Foundation.  Oracle designates this
  351.11 + * particular file as subject to the "Classpath" exception as provided
  351.12 + * by Oracle in the LICENSE file that accompanied this code.
  351.13 + *
  351.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  351.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  351.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  351.17 + * version 2 for more details (a copy is included in the LICENSE file that
  351.18 + * accompanied this code).
  351.19 + *
  351.20 + * You should have received a copy of the GNU General Public License version
  351.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  351.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  351.23 + *
  351.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  351.25 + * or visit www.oracle.com if you need additional information or have any
  351.26 + * questions.
  351.27 + */
  351.28 +
  351.29 +package java.lang.ref;
  351.30 +
  351.31 +
  351.32 +/**
  351.33 + * Soft reference objects, which are cleared at the discretion of the garbage
  351.34 + * collector in response to memory demand.  Soft references are most often used
  351.35 + * to implement memory-sensitive caches.
  351.36 + *
  351.37 + * <p> Suppose that the garbage collector determines at a certain point in time
  351.38 + * that an object is <a href="package-summary.html#reachability">softly
  351.39 + * reachable</a>.  At that time it may choose to clear atomically all soft
  351.40 + * references to that object and all soft references to any other
  351.41 + * softly-reachable objects from which that object is reachable through a chain
  351.42 + * of strong references.  At the same time or at some later time it will
  351.43 + * enqueue those newly-cleared soft references that are registered with
  351.44 + * reference queues.
  351.45 + *
  351.46 + * <p> All soft references to softly-reachable objects are guaranteed to have
  351.47 + * been cleared before the virtual machine throws an
  351.48 + * <code>OutOfMemoryError</code>.  Otherwise no constraints are placed upon the
  351.49 + * time at which a soft reference will be cleared or the order in which a set
  351.50 + * of such references to different objects will be cleared.  Virtual machine
  351.51 + * implementations are, however, encouraged to bias against clearing
  351.52 + * recently-created or recently-used soft references.
  351.53 + *
  351.54 + * <p> Direct instances of this class may be used to implement simple caches;
  351.55 + * this class or derived subclasses may also be used in larger data structures
  351.56 + * to implement more sophisticated caches.  As long as the referent of a soft
  351.57 + * reference is strongly reachable, that is, is actually in use, the soft
  351.58 + * reference will not be cleared.  Thus a sophisticated cache can, for example,
  351.59 + * prevent its most recently used entries from being discarded by keeping
  351.60 + * strong referents to those entries, leaving the remaining entries to be
  351.61 + * discarded at the discretion of the garbage collector.
  351.62 + *
  351.63 + * @author   Mark Reinhold
  351.64 + * @since    1.2
  351.65 + */
  351.66 +
  351.67 +public class SoftReference<T> extends Reference<T> {
  351.68 +
  351.69 +    /**
  351.70 +     * Timestamp clock, updated by the garbage collector
  351.71 +     */
  351.72 +    static private long clock;
  351.73 +
  351.74 +    /**
  351.75 +     * Timestamp updated by each invocation of the get method.  The VM may use
  351.76 +     * this field when selecting soft references to be cleared, but it is not
  351.77 +     * required to do so.
  351.78 +     */
  351.79 +    private long timestamp;
  351.80 +
  351.81 +    /**
  351.82 +     * Creates a new soft reference that refers to the given object.  The new
  351.83 +     * reference is not registered with any queue.
  351.84 +     *
  351.85 +     * @param referent object the new soft reference will refer to
  351.86 +     */
  351.87 +    public SoftReference(T referent) {
  351.88 +        super(referent);
  351.89 +        this.timestamp = clock;
  351.90 +    }
  351.91 +
  351.92 +    /**
  351.93 +     * Creates a new soft reference that refers to the given object and is
  351.94 +     * registered with the given queue.
  351.95 +     *
  351.96 +     * @param referent object the new soft reference will refer to
  351.97 +     * @param q the queue with which the reference is to be registered,
  351.98 +     *          or <tt>null</tt> if registration is not required
  351.99 +     *
 351.100 +     */
 351.101 +    public SoftReference(T referent, ReferenceQueue<? super T> q) {
 351.102 +        super(referent, q);
 351.103 +        this.timestamp = clock;
 351.104 +    }
 351.105 +
 351.106 +    /**
 351.107 +     * Returns this reference object's referent.  If this reference object has
 351.108 +     * been cleared, either by the program or by the garbage collector, then
 351.109 +     * this method returns <code>null</code>.
 351.110 +     *
 351.111 +     * @return   The object to which this reference refers, or
 351.112 +     *           <code>null</code> if this reference object has been cleared
 351.113 +     */
 351.114 +    public T get() {
 351.115 +        T o = super.get();
 351.116 +        if (o != null && this.timestamp != clock)
 351.117 +            this.timestamp = clock;
 351.118 +        return o;
 351.119 +    }
 351.120 +
 351.121 +}
   352.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   352.2 +++ b/rt/emul/compact/src/main/java/java/lang/ref/WeakReference.java	Wed Feb 27 11:24:58 2013 +0100
   352.3 @@ -0,0 +1,72 @@
   352.4 +/*
   352.5 + * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
   352.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   352.7 + *
   352.8 + * This code is free software; you can redistribute it and/or modify it
   352.9 + * under the terms of the GNU General Public License version 2 only, as
  352.10 + * published by the Free Software Foundation.  Oracle designates this
  352.11 + * particular file as subject to the "Classpath" exception as provided
  352.12 + * by Oracle in the LICENSE file that accompanied this code.
  352.13 + *
  352.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  352.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  352.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  352.17 + * version 2 for more details (a copy is included in the LICENSE file that
  352.18 + * accompanied this code).
  352.19 + *
  352.20 + * You should have received a copy of the GNU General Public License version
  352.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  352.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  352.23 + *
  352.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  352.25 + * or visit www.oracle.com if you need additional information or have any
  352.26 + * questions.
  352.27 + */
  352.28 +
  352.29 +package java.lang.ref;
  352.30 +
  352.31 +
  352.32 +/**
  352.33 + * Weak reference objects, which do not prevent their referents from being
  352.34 + * made finalizable, finalized, and then reclaimed.  Weak references are most
  352.35 + * often used to implement canonicalizing mappings.
  352.36 + *
  352.37 + * <p> Suppose that the garbage collector determines at a certain point in time
  352.38 + * that an object is <a href="package-summary.html#reachability">weakly
  352.39 + * reachable</a>.  At that time it will atomically clear all weak references to
  352.40 + * that object and all weak references to any other weakly-reachable objects
  352.41 + * from which that object is reachable through a chain of strong and soft
  352.42 + * references.  At the same time it will declare all of the formerly
  352.43 + * weakly-reachable objects to be finalizable.  At the same time or at some
  352.44 + * later time it will enqueue those newly-cleared weak references that are
  352.45 + * registered with reference queues.
  352.46 + *
  352.47 + * @author   Mark Reinhold
  352.48 + * @since    1.2
  352.49 + */
  352.50 +
  352.51 +public class WeakReference<T> extends Reference<T> {
  352.52 +
  352.53 +    /**
  352.54 +     * Creates a new weak reference that refers to the given object.  The new
  352.55 +     * reference is not registered with any queue.
  352.56 +     *
  352.57 +     * @param referent object the new weak reference will refer to
  352.58 +     */
  352.59 +    public WeakReference(T referent) {
  352.60 +        super(referent);
  352.61 +    }
  352.62 +
  352.63 +    /**
  352.64 +     * Creates a new weak reference that refers to the given object and is
  352.65 +     * registered with the given queue.
  352.66 +     *
  352.67 +     * @param referent object the new weak reference will refer to
  352.68 +     * @param q the queue with which the reference is to be registered,
  352.69 +     *          or <tt>null</tt> if registration is not required
  352.70 +     */
  352.71 +    public WeakReference(T referent, ReferenceQueue<? super T> q) {
  352.72 +        super(referent, q);
  352.73 +    }
  352.74 +
  352.75 +}
   353.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   353.2 +++ b/rt/emul/compact/src/main/java/java/lang/ref/package.html	Wed Feb 27 11:24:58 2013 +0100
   353.3 @@ -0,0 +1,147 @@
   353.4 +<!--
   353.5 + Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
   353.6 + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   353.7 +
   353.8 + This code is free software; you can redistribute it and/or modify it
   353.9 + under the terms of the GNU General Public License version 2 only, as
  353.10 + published by the Free Software Foundation.  Oracle designates this
  353.11 + particular file as subject to the "Classpath" exception as provided
  353.12 + by Oracle in the LICENSE file that accompanied this code.
  353.13 +
  353.14 + This code is distributed in the hope that it will be useful, but WITHOUT
  353.15 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  353.16 + FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  353.17 + version 2 for more details (a copy is included in the LICENSE file that
  353.18 + accompanied this code).
  353.19 +
  353.20 + You should have received a copy of the GNU General Public License version
  353.21 + 2 along with this work; if not, write to the Free Software Foundation,
  353.22 + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  353.23 +
  353.24 + Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  353.25 + or visit www.oracle.com if you need additional information or have any
  353.26 + questions.
  353.27 +-->
  353.28 +
  353.29 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  353.30 +<html>
  353.31 +<body bgcolor="white">
  353.32 +
  353.33 +
  353.34 +Provides reference-object classes, which support a limited degree of
  353.35 +interaction with the garbage collector.  A program may use a reference object
  353.36 +to maintain a reference to some other object in such a way that the latter
  353.37 +object may still be reclaimed by the collector.  A program may also arrange to
  353.38 +be notified some time after the collector has determined that the reachability
  353.39 +of a given object has changed.
  353.40 +
  353.41 +
  353.42 +<h2>Package Specification</h2>
  353.43 +
  353.44 +A <em>reference object</em> encapsulates a reference to some other object so
  353.45 +that the reference itself may be examined and manipulated like any other
  353.46 +object.  Three types of reference objects are provided, each weaker than the
  353.47 +last: <em>soft</em>, <em>weak</em>, and <em>phantom</em>.  Each type
  353.48 +corresponds to a different level of reachability, as defined below.  Soft
  353.49 +references are for implementing memory-sensitive caches, weak references are
  353.50 +for implementing canonicalizing mappings that do not prevent their keys (or
  353.51 +values) from being reclaimed, and phantom references are for scheduling
  353.52 +pre-mortem cleanup actions in a more flexible way than is possible with the
  353.53 +Java finalization mechanism.
  353.54 +
  353.55 +<p> Each reference-object type is implemented by a subclass of the abstract
  353.56 +base <code>{@link java.lang.ref.Reference}</code> class.  An instance of one of
  353.57 +these subclasses encapsulates a single reference to a particular object, called
  353.58 +the <em>referent</em>.  Every reference object provides methods for getting and
  353.59 +clearing the reference.  Aside from the clearing operation reference objects
  353.60 +are otherwise immutable, so no <code>set</code> operation is provided.  A
  353.61 +program may further subclass these subclasses, adding whatever fields and
  353.62 +methods are required for its purposes, or it may use these subclasses without
  353.63 +change.
  353.64 +
  353.65 +
  353.66 +<h3>Notification</h3>
  353.67 +
  353.68 +A program may request to be notified of changes in an object's reachability by
  353.69 +<em>registering</em> an appropriate reference object with a <em>reference
  353.70 +queue</em> at the time the reference object is created.  Some time after the
  353.71 +garbage collector determines that the reachability of the referent has changed
  353.72 +to the value corresponding to the type of the reference, it will add the
  353.73 +reference to the associated queue.  At this point, the reference is considered
  353.74 +to be <em>enqueued</em>.  The program may remove references from a queue either
  353.75 +by polling or by blocking until a reference becomes available.  Reference
  353.76 +queues are implemented by the <code>{@link java.lang.ref.ReferenceQueue}</code>
  353.77 +class.
  353.78 +
  353.79 +<p> The relationship between a registered reference object and its queue is
  353.80 +one-sided.  That is, a queue does not keep track of the references that are
  353.81 +registered with it.  If a registered reference becomes unreachable itself, then
  353.82 +it will never be enqueued.  It is the responsibility of the program using
  353.83 +reference objects to ensure that the objects remain reachable for as long as
  353.84 +the program is interested in their referents.
  353.85 +
  353.86 +<p> While some programs will choose to dedicate a thread to removing reference
  353.87 +objects from one or more queues and processing them, this is by no means
  353.88 +necessary.  A tactic that often works well is to examine a reference queue in
  353.89 +the course of performing some other fairly-frequent action.  For example, a
  353.90 +hashtable that uses weak references to implement weak keys could poll its
  353.91 +reference queue each time the table is accessed.  This is how the <code>{@link
  353.92 +java.util.WeakHashMap}</code> class works.  Because the <code>{@link
  353.93 +java.lang.ref.ReferenceQueue#poll ReferenceQueue.poll}</code> method simply
  353.94 +checks an internal data structure, this check will add little overhead to the
  353.95 +hashtable access methods.
  353.96 +
  353.97 +
  353.98 +<h3>Automatically-cleared references</h3>
  353.99 +
 353.100 +Soft and weak references are automatically cleared by the collector before
 353.101 +being added to the queues with which they are registered, if any.  Therefore
 353.102 +soft and weak references need not be registered with a queue in order to be
 353.103 +useful, while phantom references do.  An object that is reachable via phantom
 353.104 +references will remain so until all such references are cleared or themselves
 353.105 +become unreachable.
 353.106 +
 353.107 +
 353.108 +<a name="reachability"></a>
 353.109 +<h3>Reachability</h3>
 353.110 +
 353.111 +Going from strongest to weakest, the different levels of reachability reflect
 353.112 +the life cycle of an object.  They are operationally defined as follows:
 353.113 +
 353.114 +<ul>
 353.115 +
 353.116 +<li> An object is <em>strongly reachable</em> if it can be reached by some
 353.117 +thread without traversing any reference objects.  A newly-created object is
 353.118 +strongly reachable by the thread that created it.
 353.119 +
 353.120 +<li> An object is <em>softly reachable</em> if it is not strongly reachable but
 353.121 +can be reached by traversing a soft reference.
 353.122 +
 353.123 +<li> An object is <em>weakly reachable</em> if it is neither strongly nor
 353.124 +softly reachable but can be reached by traversing a weak reference.  When the
 353.125 +weak references to a weakly-reachable object are cleared, the object becomes
 353.126 +eligible for finalization.
 353.127 +
 353.128 +<li> An object is <em>phantom reachable</em> if it is neither strongly, softly,
 353.129 +nor weakly reachable, it has been finalized, and some phantom reference refers
 353.130 +to it.
 353.131 +
 353.132 +<li> Finally, an object is <em>unreachable</em>, and therefore eligible for
 353.133 +reclamation, when it is not reachable in any of the above ways.
 353.134 +
 353.135 +</ul>
 353.136 +
 353.137 +
 353.138 +@author	  Mark Reinhold
 353.139 +@since	  1.2
 353.140 +
 353.141 +<!--
 353.142 +<h2>Related Documentation</h2>
 353.143 +
 353.144 +For overviews, tutorials, examples, guides, and tool documentation, please see:
 353.145 +<ul>
 353.146 +  <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
 353.147 +</ul>
 353.148 +-->
 353.149 +</body>
 353.150 +</html>
   354.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   354.2 +++ b/rt/emul/compact/src/main/java/java/util/AbstractCollection.java	Wed Feb 27 11:24:58 2013 +0100
   354.3 @@ -0,0 +1,457 @@
   354.4 +/*
   354.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   354.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   354.7 + *
   354.8 + * This code is free software; you can redistribute it and/or modify it
   354.9 + * under the terms of the GNU General Public License version 2 only, as
  354.10 + * published by the Free Software Foundation.  Oracle designates this
  354.11 + * particular file as subject to the "Classpath" exception as provided
  354.12 + * by Oracle in the LICENSE file that accompanied this code.
  354.13 + *
  354.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  354.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  354.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  354.17 + * version 2 for more details (a copy is included in the LICENSE file that
  354.18 + * accompanied this code).
  354.19 + *
  354.20 + * You should have received a copy of the GNU General Public License version
  354.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  354.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  354.23 + *
  354.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  354.25 + * or visit www.oracle.com if you need additional information or have any
  354.26 + * questions.
  354.27 + */
  354.28 +
  354.29 +package java.util;
  354.30 +
  354.31 +/**
  354.32 + * This class provides a skeletal implementation of the <tt>Collection</tt>
  354.33 + * interface, to minimize the effort required to implement this interface. <p>
  354.34 + *
  354.35 + * To implement an unmodifiable collection, the programmer needs only to
  354.36 + * extend this class and provide implementations for the <tt>iterator</tt> and
  354.37 + * <tt>size</tt> methods.  (The iterator returned by the <tt>iterator</tt>
  354.38 + * method must implement <tt>hasNext</tt> and <tt>next</tt>.)<p>
  354.39 + *
  354.40 + * To implement a modifiable collection, the programmer must additionally
  354.41 + * override this class's <tt>add</tt> method (which otherwise throws an
  354.42 + * <tt>UnsupportedOperationException</tt>), and the iterator returned by the
  354.43 + * <tt>iterator</tt> method must additionally implement its <tt>remove</tt>
  354.44 + * method.<p>
  354.45 + *
  354.46 + * The programmer should generally provide a void (no argument) and
  354.47 + * <tt>Collection</tt> constructor, as per the recommendation in the
  354.48 + * <tt>Collection</tt> interface specification.<p>
  354.49 + *
  354.50 + * The documentation for each non-abstract method in this class describes its
  354.51 + * implementation in detail.  Each of these methods may be overridden if
  354.52 + * the collection being implemented admits a more efficient implementation.<p>
  354.53 + *
  354.54 + * This class is a member of the
  354.55 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  354.56 + * Java Collections Framework</a>.
  354.57 + *
  354.58 + * @author  Josh Bloch
  354.59 + * @author  Neal Gafter
  354.60 + * @see Collection
  354.61 + * @since 1.2
  354.62 + */
  354.63 +
  354.64 +public abstract class AbstractCollection<E> implements Collection<E> {
  354.65 +    /**
  354.66 +     * Sole constructor.  (For invocation by subclass constructors, typically
  354.67 +     * implicit.)
  354.68 +     */
  354.69 +    protected AbstractCollection() {
  354.70 +    }
  354.71 +
  354.72 +    // Query Operations
  354.73 +
  354.74 +    /**
  354.75 +     * Returns an iterator over the elements contained in this collection.
  354.76 +     *
  354.77 +     * @return an iterator over the elements contained in this collection
  354.78 +     */
  354.79 +    public abstract Iterator<E> iterator();
  354.80 +
  354.81 +    public abstract int size();
  354.82 +
  354.83 +    /**
  354.84 +     * {@inheritDoc}
  354.85 +     *
  354.86 +     * <p>This implementation returns <tt>size() == 0</tt>.
  354.87 +     */
  354.88 +    public boolean isEmpty() {
  354.89 +        return size() == 0;
  354.90 +    }
  354.91 +
  354.92 +    /**
  354.93 +     * {@inheritDoc}
  354.94 +     *
  354.95 +     * <p>This implementation iterates over the elements in the collection,
  354.96 +     * checking each element in turn for equality with the specified element.
  354.97 +     *
  354.98 +     * @throws ClassCastException   {@inheritDoc}
  354.99 +     * @throws NullPointerException {@inheritDoc}
 354.100 +     */
 354.101 +    public boolean contains(Object o) {
 354.102 +        Iterator<E> it = iterator();
 354.103 +        if (o==null) {
 354.104 +            while (it.hasNext())
 354.105 +                if (it.next()==null)
 354.106 +                    return true;
 354.107 +        } else {
 354.108 +            while (it.hasNext())
 354.109 +                if (o.equals(it.next()))
 354.110 +                    return true;
 354.111 +        }
 354.112 +        return false;
 354.113 +    }
 354.114 +
 354.115 +    /**
 354.116 +     * {@inheritDoc}
 354.117 +     *
 354.118 +     * <p>This implementation returns an array containing all the elements
 354.119 +     * returned by this collection's iterator, in the same order, stored in
 354.120 +     * consecutive elements of the array, starting with index {@code 0}.
 354.121 +     * The length of the returned array is equal to the number of elements
 354.122 +     * returned by the iterator, even if the size of this collection changes
 354.123 +     * during iteration, as might happen if the collection permits
 354.124 +     * concurrent modification during iteration.  The {@code size} method is
 354.125 +     * called only as an optimization hint; the correct result is returned
 354.126 +     * even if the iterator returns a different number of elements.
 354.127 +     *
 354.128 +     * <p>This method is equivalent to:
 354.129 +     *
 354.130 +     *  <pre> {@code
 354.131 +     * List<E> list = new ArrayList<E>(size());
 354.132 +     * for (E e : this)
 354.133 +     *     list.add(e);
 354.134 +     * return list.toArray();
 354.135 +     * }</pre>
 354.136 +     */
 354.137 +    public Object[] toArray() {
 354.138 +        // Estimate size of array; be prepared to see more or fewer elements
 354.139 +        Object[] r = new Object[size()];
 354.140 +        Iterator<E> it = iterator();
 354.141 +        for (int i = 0; i < r.length; i++) {
 354.142 +            if (! it.hasNext()) // fewer elements than expected
 354.143 +                return Arrays.copyOf(r, i);
 354.144 +            r[i] = it.next();
 354.145 +        }
 354.146 +        return it.hasNext() ? finishToArray(r, it) : r;
 354.147 +    }
 354.148 +
 354.149 +    /**
 354.150 +     * {@inheritDoc}
 354.151 +     *
 354.152 +     * <p>This implementation returns an array containing all the elements
 354.153 +     * returned by this collection's iterator in the same order, stored in
 354.154 +     * consecutive elements of the array, starting with index {@code 0}.
 354.155 +     * If the number of elements returned by the iterator is too large to
 354.156 +     * fit into the specified array, then the elements are returned in a
 354.157 +     * newly allocated array with length equal to the number of elements
 354.158 +     * returned by the iterator, even if the size of this collection
 354.159 +     * changes during iteration, as might happen if the collection permits
 354.160 +     * concurrent modification during iteration.  The {@code size} method is
 354.161 +     * called only as an optimization hint; the correct result is returned
 354.162 +     * even if the iterator returns a different number of elements.
 354.163 +     *
 354.164 +     * <p>This method is equivalent to:
 354.165 +     *
 354.166 +     *  <pre> {@code
 354.167 +     * List<E> list = new ArrayList<E>(size());
 354.168 +     * for (E e : this)
 354.169 +     *     list.add(e);
 354.170 +     * return list.toArray(a);
 354.171 +     * }</pre>
 354.172 +     *
 354.173 +     * @throws ArrayStoreException  {@inheritDoc}
 354.174 +     * @throws NullPointerException {@inheritDoc}
 354.175 +     */
 354.176 +    public <T> T[] toArray(T[] a) {
 354.177 +        // Estimate size of array; be prepared to see more or fewer elements
 354.178 +        int size = size();
 354.179 +        T[] r = a.length >= size ? a :
 354.180 +                  (T[])java.lang.reflect.Array
 354.181 +                  .newInstance(a.getClass().getComponentType(), size);
 354.182 +        Iterator<E> it = iterator();
 354.183 +
 354.184 +        for (int i = 0; i < r.length; i++) {
 354.185 +            if (! it.hasNext()) { // fewer elements than expected
 354.186 +                if (a != r)
 354.187 +                    return Arrays.copyOf(r, i);
 354.188 +                r[i] = null; // null-terminate
 354.189 +                return r;
 354.190 +            }
 354.191 +            r[i] = (T)it.next();
 354.192 +        }
 354.193 +        return it.hasNext() ? finishToArray(r, it) : r;
 354.194 +    }
 354.195 +
 354.196 +    /**
 354.197 +     * The maximum size of array to allocate.
 354.198 +     * Some VMs reserve some header words in an array.
 354.199 +     * Attempts to allocate larger arrays may result in
 354.200 +     * OutOfMemoryError: Requested array size exceeds VM limit
 354.201 +     */
 354.202 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 354.203 +
 354.204 +    /**
 354.205 +     * Reallocates the array being used within toArray when the iterator
 354.206 +     * returned more elements than expected, and finishes filling it from
 354.207 +     * the iterator.
 354.208 +     *
 354.209 +     * @param r the array, replete with previously stored elements
 354.210 +     * @param it the in-progress iterator over this collection
 354.211 +     * @return array containing the elements in the given array, plus any
 354.212 +     *         further elements returned by the iterator, trimmed to size
 354.213 +     */
 354.214 +    private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
 354.215 +        int i = r.length;
 354.216 +        while (it.hasNext()) {
 354.217 +            int cap = r.length;
 354.218 +            if (i == cap) {
 354.219 +                int newCap = cap + (cap >> 1) + 1;
 354.220 +                // overflow-conscious code
 354.221 +                if (newCap - MAX_ARRAY_SIZE > 0)
 354.222 +                    newCap = hugeCapacity(cap + 1);
 354.223 +                r = Arrays.copyOf(r, newCap);
 354.224 +            }
 354.225 +            r[i++] = (T)it.next();
 354.226 +        }
 354.227 +        // trim if overallocated
 354.228 +        return (i == r.length) ? r : Arrays.copyOf(r, i);
 354.229 +    }
 354.230 +
 354.231 +    private static int hugeCapacity(int minCapacity) {
 354.232 +        if (minCapacity < 0) // overflow
 354.233 +            throw new OutOfMemoryError
 354.234 +                ("Required array size too large");
 354.235 +        return (minCapacity > MAX_ARRAY_SIZE) ?
 354.236 +            Integer.MAX_VALUE :
 354.237 +            MAX_ARRAY_SIZE;
 354.238 +    }
 354.239 +
 354.240 +    // Modification Operations
 354.241 +
 354.242 +    /**
 354.243 +     * {@inheritDoc}
 354.244 +     *
 354.245 +     * <p>This implementation always throws an
 354.246 +     * <tt>UnsupportedOperationException</tt>.
 354.247 +     *
 354.248 +     * @throws UnsupportedOperationException {@inheritDoc}
 354.249 +     * @throws ClassCastException            {@inheritDoc}
 354.250 +     * @throws NullPointerException          {@inheritDoc}
 354.251 +     * @throws IllegalArgumentException      {@inheritDoc}
 354.252 +     * @throws IllegalStateException         {@inheritDoc}
 354.253 +     */
 354.254 +    public boolean add(E e) {
 354.255 +        throw new UnsupportedOperationException();
 354.256 +    }
 354.257 +
 354.258 +    /**
 354.259 +     * {@inheritDoc}
 354.260 +     *
 354.261 +     * <p>This implementation iterates over the collection looking for the
 354.262 +     * specified element.  If it finds the element, it removes the element
 354.263 +     * from the collection using the iterator's remove method.
 354.264 +     *
 354.265 +     * <p>Note that this implementation throws an
 354.266 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by this
 354.267 +     * collection's iterator method does not implement the <tt>remove</tt>
 354.268 +     * method and this collection contains the specified object.
 354.269 +     *
 354.270 +     * @throws UnsupportedOperationException {@inheritDoc}
 354.271 +     * @throws ClassCastException            {@inheritDoc}
 354.272 +     * @throws NullPointerException          {@inheritDoc}
 354.273 +     */
 354.274 +    public boolean remove(Object o) {
 354.275 +        Iterator<E> it = iterator();
 354.276 +        if (o==null) {
 354.277 +            while (it.hasNext()) {
 354.278 +                if (it.next()==null) {
 354.279 +                    it.remove();
 354.280 +                    return true;
 354.281 +                }
 354.282 +            }
 354.283 +        } else {
 354.284 +            while (it.hasNext()) {
 354.285 +                if (o.equals(it.next())) {
 354.286 +                    it.remove();
 354.287 +                    return true;
 354.288 +                }
 354.289 +            }
 354.290 +        }
 354.291 +        return false;
 354.292 +    }
 354.293 +
 354.294 +
 354.295 +    // Bulk Operations
 354.296 +
 354.297 +    /**
 354.298 +     * {@inheritDoc}
 354.299 +     *
 354.300 +     * <p>This implementation iterates over the specified collection,
 354.301 +     * checking each element returned by the iterator in turn to see
 354.302 +     * if it's contained in this collection.  If all elements are so
 354.303 +     * contained <tt>true</tt> is returned, otherwise <tt>false</tt>.
 354.304 +     *
 354.305 +     * @throws ClassCastException            {@inheritDoc}
 354.306 +     * @throws NullPointerException          {@inheritDoc}
 354.307 +     * @see #contains(Object)
 354.308 +     */
 354.309 +    public boolean containsAll(Collection<?> c) {
 354.310 +        for (Object e : c)
 354.311 +            if (!contains(e))
 354.312 +                return false;
 354.313 +        return true;
 354.314 +    }
 354.315 +
 354.316 +    /**
 354.317 +     * {@inheritDoc}
 354.318 +     *
 354.319 +     * <p>This implementation iterates over the specified collection, and adds
 354.320 +     * each object returned by the iterator to this collection, in turn.
 354.321 +     *
 354.322 +     * <p>Note that this implementation will throw an
 354.323 +     * <tt>UnsupportedOperationException</tt> unless <tt>add</tt> is
 354.324 +     * overridden (assuming the specified collection is non-empty).
 354.325 +     *
 354.326 +     * @throws UnsupportedOperationException {@inheritDoc}
 354.327 +     * @throws ClassCastException            {@inheritDoc}
 354.328 +     * @throws NullPointerException          {@inheritDoc}
 354.329 +     * @throws IllegalArgumentException      {@inheritDoc}
 354.330 +     * @throws IllegalStateException         {@inheritDoc}
 354.331 +     *
 354.332 +     * @see #add(Object)
 354.333 +     */
 354.334 +    public boolean addAll(Collection<? extends E> c) {
 354.335 +        boolean modified = false;
 354.336 +        for (E e : c)
 354.337 +            if (add(e))
 354.338 +                modified = true;
 354.339 +        return modified;
 354.340 +    }
 354.341 +
 354.342 +    /**
 354.343 +     * {@inheritDoc}
 354.344 +     *
 354.345 +     * <p>This implementation iterates over this collection, checking each
 354.346 +     * element returned by the iterator in turn to see if it's contained
 354.347 +     * in the specified collection.  If it's so contained, it's removed from
 354.348 +     * this collection with the iterator's <tt>remove</tt> method.
 354.349 +     *
 354.350 +     * <p>Note that this implementation will throw an
 354.351 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
 354.352 +     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
 354.353 +     * and this collection contains one or more elements in common with the
 354.354 +     * specified collection.
 354.355 +     *
 354.356 +     * @throws UnsupportedOperationException {@inheritDoc}
 354.357 +     * @throws ClassCastException            {@inheritDoc}
 354.358 +     * @throws NullPointerException          {@inheritDoc}
 354.359 +     *
 354.360 +     * @see #remove(Object)
 354.361 +     * @see #contains(Object)
 354.362 +     */
 354.363 +    public boolean removeAll(Collection<?> c) {
 354.364 +        boolean modified = false;
 354.365 +        Iterator<?> it = iterator();
 354.366 +        while (it.hasNext()) {
 354.367 +            if (c.contains(it.next())) {
 354.368 +                it.remove();
 354.369 +                modified = true;
 354.370 +            }
 354.371 +        }
 354.372 +        return modified;
 354.373 +    }
 354.374 +
 354.375 +    /**
 354.376 +     * {@inheritDoc}
 354.377 +     *
 354.378 +     * <p>This implementation iterates over this collection, checking each
 354.379 +     * element returned by the iterator in turn to see if it's contained
 354.380 +     * in the specified collection.  If it's not so contained, it's removed
 354.381 +     * from this collection with the iterator's <tt>remove</tt> method.
 354.382 +     *
 354.383 +     * <p>Note that this implementation will throw an
 354.384 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
 354.385 +     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
 354.386 +     * and this collection contains one or more elements not present in the
 354.387 +     * specified collection.
 354.388 +     *
 354.389 +     * @throws UnsupportedOperationException {@inheritDoc}
 354.390 +     * @throws ClassCastException            {@inheritDoc}
 354.391 +     * @throws NullPointerException          {@inheritDoc}
 354.392 +     *
 354.393 +     * @see #remove(Object)
 354.394 +     * @see #contains(Object)
 354.395 +     */
 354.396 +    public boolean retainAll(Collection<?> c) {
 354.397 +        boolean modified = false;
 354.398 +        Iterator<E> it = iterator();
 354.399 +        while (it.hasNext()) {
 354.400 +            if (!c.contains(it.next())) {
 354.401 +                it.remove();
 354.402 +                modified = true;
 354.403 +            }
 354.404 +        }
 354.405 +        return modified;
 354.406 +    }
 354.407 +
 354.408 +    /**
 354.409 +     * {@inheritDoc}
 354.410 +     *
 354.411 +     * <p>This implementation iterates over this collection, removing each
 354.412 +     * element using the <tt>Iterator.remove</tt> operation.  Most
 354.413 +     * implementations will probably choose to override this method for
 354.414 +     * efficiency.
 354.415 +     *
 354.416 +     * <p>Note that this implementation will throw an
 354.417 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by this
 354.418 +     * collection's <tt>iterator</tt> method does not implement the
 354.419 +     * <tt>remove</tt> method and this collection is non-empty.
 354.420 +     *
 354.421 +     * @throws UnsupportedOperationException {@inheritDoc}
 354.422 +     */
 354.423 +    public void clear() {
 354.424 +        Iterator<E> it = iterator();
 354.425 +        while (it.hasNext()) {
 354.426 +            it.next();
 354.427 +            it.remove();
 354.428 +        }
 354.429 +    }
 354.430 +
 354.431 +
 354.432 +    //  String conversion
 354.433 +
 354.434 +    /**
 354.435 +     * Returns a string representation of this collection.  The string
 354.436 +     * representation consists of a list of the collection's elements in the
 354.437 +     * order they are returned by its iterator, enclosed in square brackets
 354.438 +     * (<tt>"[]"</tt>).  Adjacent elements are separated by the characters
 354.439 +     * <tt>", "</tt> (comma and space).  Elements are converted to strings as
 354.440 +     * by {@link String#valueOf(Object)}.
 354.441 +     *
 354.442 +     * @return a string representation of this collection
 354.443 +     */
 354.444 +    public String toString() {
 354.445 +        Iterator<E> it = iterator();
 354.446 +        if (! it.hasNext())
 354.447 +            return "[]";
 354.448 +
 354.449 +        StringBuilder sb = new StringBuilder();
 354.450 +        sb.append('[');
 354.451 +        for (;;) {
 354.452 +            E e = it.next();
 354.453 +            sb.append(e == this ? "(this Collection)" : e);
 354.454 +            if (! it.hasNext())
 354.455 +                return sb.append(']').toString();
 354.456 +            sb.append(',').append(' ');
 354.457 +        }
 354.458 +    }
 354.459 +
 354.460 +}
   355.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   355.2 +++ b/rt/emul/compact/src/main/java/java/util/AbstractList.java	Wed Feb 27 11:24:58 2013 +0100
   355.3 @@ -0,0 +1,781 @@
   355.4 +/*
   355.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   355.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   355.7 + *
   355.8 + * This code is free software; you can redistribute it and/or modify it
   355.9 + * under the terms of the GNU General Public License version 2 only, as
  355.10 + * published by the Free Software Foundation.  Oracle designates this
  355.11 + * particular file as subject to the "Classpath" exception as provided
  355.12 + * by Oracle in the LICENSE file that accompanied this code.
  355.13 + *
  355.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  355.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  355.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  355.17 + * version 2 for more details (a copy is included in the LICENSE file that
  355.18 + * accompanied this code).
  355.19 + *
  355.20 + * You should have received a copy of the GNU General Public License version
  355.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  355.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  355.23 + *
  355.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  355.25 + * or visit www.oracle.com if you need additional information or have any
  355.26 + * questions.
  355.27 + */
  355.28 +
  355.29 +package java.util;
  355.30 +
  355.31 +/**
  355.32 + * This class provides a skeletal implementation of the {@link List}
  355.33 + * interface to minimize the effort required to implement this interface
  355.34 + * backed by a "random access" data store (such as an array).  For sequential
  355.35 + * access data (such as a linked list), {@link AbstractSequentialList} should
  355.36 + * be used in preference to this class.
  355.37 + *
  355.38 + * <p>To implement an unmodifiable list, the programmer needs only to extend
  355.39 + * this class and provide implementations for the {@link #get(int)} and
  355.40 + * {@link List#size() size()} methods.
  355.41 + *
  355.42 + * <p>To implement a modifiable list, the programmer must additionally
  355.43 + * override the {@link #set(int, Object) set(int, E)} method (which otherwise
  355.44 + * throws an {@code UnsupportedOperationException}).  If the list is
  355.45 + * variable-size the programmer must additionally override the
  355.46 + * {@link #add(int, Object) add(int, E)} and {@link #remove(int)} methods.
  355.47 + *
  355.48 + * <p>The programmer should generally provide a void (no argument) and collection
  355.49 + * constructor, as per the recommendation in the {@link Collection} interface
  355.50 + * specification.
  355.51 + *
  355.52 + * <p>Unlike the other abstract collection implementations, the programmer does
  355.53 + * <i>not</i> have to provide an iterator implementation; the iterator and
  355.54 + * list iterator are implemented by this class, on top of the "random access"
  355.55 + * methods:
  355.56 + * {@link #get(int)},
  355.57 + * {@link #set(int, Object) set(int, E)},
  355.58 + * {@link #add(int, Object) add(int, E)} and
  355.59 + * {@link #remove(int)}.
  355.60 + *
  355.61 + * <p>The documentation for each non-abstract method in this class describes its
  355.62 + * implementation in detail.  Each of these methods may be overridden if the
  355.63 + * collection being implemented admits a more efficient implementation.
  355.64 + *
  355.65 + * <p>This class is a member of the
  355.66 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  355.67 + * Java Collections Framework</a>.
  355.68 + *
  355.69 + * @author  Josh Bloch
  355.70 + * @author  Neal Gafter
  355.71 + * @since 1.2
  355.72 + */
  355.73 +
  355.74 +public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> {
  355.75 +    /**
  355.76 +     * Sole constructor.  (For invocation by subclass constructors, typically
  355.77 +     * implicit.)
  355.78 +     */
  355.79 +    protected AbstractList() {
  355.80 +    }
  355.81 +
  355.82 +    /**
  355.83 +     * Appends the specified element to the end of this list (optional
  355.84 +     * operation).
  355.85 +     *
  355.86 +     * <p>Lists that support this operation may place limitations on what
  355.87 +     * elements may be added to this list.  In particular, some
  355.88 +     * lists will refuse to add null elements, and others will impose
  355.89 +     * restrictions on the type of elements that may be added.  List
  355.90 +     * classes should clearly specify in their documentation any restrictions
  355.91 +     * on what elements may be added.
  355.92 +     *
  355.93 +     * <p>This implementation calls {@code add(size(), e)}.
  355.94 +     *
  355.95 +     * <p>Note that this implementation throws an
  355.96 +     * {@code UnsupportedOperationException} unless
  355.97 +     * {@link #add(int, Object) add(int, E)} is overridden.
  355.98 +     *
  355.99 +     * @param e element to be appended to this list
 355.100 +     * @return {@code true} (as specified by {@link Collection#add})
 355.101 +     * @throws UnsupportedOperationException if the {@code add} operation
 355.102 +     *         is not supported by this list
 355.103 +     * @throws ClassCastException if the class of the specified element
 355.104 +     *         prevents it from being added to this list
 355.105 +     * @throws NullPointerException if the specified element is null and this
 355.106 +     *         list does not permit null elements
 355.107 +     * @throws IllegalArgumentException if some property of this element
 355.108 +     *         prevents it from being added to this list
 355.109 +     */
 355.110 +    public boolean add(E e) {
 355.111 +        add(size(), e);
 355.112 +        return true;
 355.113 +    }
 355.114 +
 355.115 +    /**
 355.116 +     * {@inheritDoc}
 355.117 +     *
 355.118 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 355.119 +     */
 355.120 +    abstract public E get(int index);
 355.121 +
 355.122 +    /**
 355.123 +     * {@inheritDoc}
 355.124 +     *
 355.125 +     * <p>This implementation always throws an
 355.126 +     * {@code UnsupportedOperationException}.
 355.127 +     *
 355.128 +     * @throws UnsupportedOperationException {@inheritDoc}
 355.129 +     * @throws ClassCastException            {@inheritDoc}
 355.130 +     * @throws NullPointerException          {@inheritDoc}
 355.131 +     * @throws IllegalArgumentException      {@inheritDoc}
 355.132 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 355.133 +     */
 355.134 +    public E set(int index, E element) {
 355.135 +        throw new UnsupportedOperationException();
 355.136 +    }
 355.137 +
 355.138 +    /**
 355.139 +     * {@inheritDoc}
 355.140 +     *
 355.141 +     * <p>This implementation always throws an
 355.142 +     * {@code UnsupportedOperationException}.
 355.143 +     *
 355.144 +     * @throws UnsupportedOperationException {@inheritDoc}
 355.145 +     * @throws ClassCastException            {@inheritDoc}
 355.146 +     * @throws NullPointerException          {@inheritDoc}
 355.147 +     * @throws IllegalArgumentException      {@inheritDoc}
 355.148 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 355.149 +     */
 355.150 +    public void add(int index, E element) {
 355.151 +        throw new UnsupportedOperationException();
 355.152 +    }
 355.153 +
 355.154 +    /**
 355.155 +     * {@inheritDoc}
 355.156 +     *
 355.157 +     * <p>This implementation always throws an
 355.158 +     * {@code UnsupportedOperationException}.
 355.159 +     *
 355.160 +     * @throws UnsupportedOperationException {@inheritDoc}
 355.161 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 355.162 +     */
 355.163 +    public E remove(int index) {
 355.164 +        throw new UnsupportedOperationException();
 355.165 +    }
 355.166 +
 355.167 +
 355.168 +    // Search Operations
 355.169 +
 355.170 +    /**
 355.171 +     * {@inheritDoc}
 355.172 +     *
 355.173 +     * <p>This implementation first gets a list iterator (with
 355.174 +     * {@code listIterator()}).  Then, it iterates over the list until the
 355.175 +     * specified element is found or the end of the list is reached.
 355.176 +     *
 355.177 +     * @throws ClassCastException   {@inheritDoc}
 355.178 +     * @throws NullPointerException {@inheritDoc}
 355.179 +     */
 355.180 +    public int indexOf(Object o) {
 355.181 +        ListIterator<E> it = listIterator();
 355.182 +        if (o==null) {
 355.183 +            while (it.hasNext())
 355.184 +                if (it.next()==null)
 355.185 +                    return it.previousIndex();
 355.186 +        } else {
 355.187 +            while (it.hasNext())
 355.188 +                if (o.equals(it.next()))
 355.189 +                    return it.previousIndex();
 355.190 +        }
 355.191 +        return -1;
 355.192 +    }
 355.193 +
 355.194 +    /**
 355.195 +     * {@inheritDoc}
 355.196 +     *
 355.197 +     * <p>This implementation first gets a list iterator that points to the end
 355.198 +     * of the list (with {@code listIterator(size())}).  Then, it iterates
 355.199 +     * backwards over the list until the specified element is found, or the
 355.200 +     * beginning of the list is reached.
 355.201 +     *
 355.202 +     * @throws ClassCastException   {@inheritDoc}
 355.203 +     * @throws NullPointerException {@inheritDoc}
 355.204 +     */
 355.205 +    public int lastIndexOf(Object o) {
 355.206 +        ListIterator<E> it = listIterator(size());
 355.207 +        if (o==null) {
 355.208 +            while (it.hasPrevious())
 355.209 +                if (it.previous()==null)
 355.210 +                    return it.nextIndex();
 355.211 +        } else {
 355.212 +            while (it.hasPrevious())
 355.213 +                if (o.equals(it.previous()))
 355.214 +                    return it.nextIndex();
 355.215 +        }
 355.216 +        return -1;
 355.217 +    }
 355.218 +
 355.219 +
 355.220 +    // Bulk Operations
 355.221 +
 355.222 +    /**
 355.223 +     * Removes all of the elements from this list (optional operation).
 355.224 +     * The list will be empty after this call returns.
 355.225 +     *
 355.226 +     * <p>This implementation calls {@code removeRange(0, size())}.
 355.227 +     *
 355.228 +     * <p>Note that this implementation throws an
 355.229 +     * {@code UnsupportedOperationException} unless {@code remove(int
 355.230 +     * index)} or {@code removeRange(int fromIndex, int toIndex)} is
 355.231 +     * overridden.
 355.232 +     *
 355.233 +     * @throws UnsupportedOperationException if the {@code clear} operation
 355.234 +     *         is not supported by this list
 355.235 +     */
 355.236 +    public void clear() {
 355.237 +        removeRange(0, size());
 355.238 +    }
 355.239 +
 355.240 +    /**
 355.241 +     * {@inheritDoc}
 355.242 +     *
 355.243 +     * <p>This implementation gets an iterator over the specified collection
 355.244 +     * and iterates over it, inserting the elements obtained from the
 355.245 +     * iterator into this list at the appropriate position, one at a time,
 355.246 +     * using {@code add(int, E)}.
 355.247 +     * Many implementations will override this method for efficiency.
 355.248 +     *
 355.249 +     * <p>Note that this implementation throws an
 355.250 +     * {@code UnsupportedOperationException} unless
 355.251 +     * {@link #add(int, Object) add(int, E)} is overridden.
 355.252 +     *
 355.253 +     * @throws UnsupportedOperationException {@inheritDoc}
 355.254 +     * @throws ClassCastException            {@inheritDoc}
 355.255 +     * @throws NullPointerException          {@inheritDoc}
 355.256 +     * @throws IllegalArgumentException      {@inheritDoc}
 355.257 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 355.258 +     */
 355.259 +    public boolean addAll(int index, Collection<? extends E> c) {
 355.260 +        rangeCheckForAdd(index);
 355.261 +        boolean modified = false;
 355.262 +        for (E e : c) {
 355.263 +            add(index++, e);
 355.264 +            modified = true;
 355.265 +        }
 355.266 +        return modified;
 355.267 +    }
 355.268 +
 355.269 +
 355.270 +    // Iterators
 355.271 +
 355.272 +    /**
 355.273 +     * Returns an iterator over the elements in this list in proper sequence.
 355.274 +     *
 355.275 +     * <p>This implementation returns a straightforward implementation of the
 355.276 +     * iterator interface, relying on the backing list's {@code size()},
 355.277 +     * {@code get(int)}, and {@code remove(int)} methods.
 355.278 +     *
 355.279 +     * <p>Note that the iterator returned by this method will throw an
 355.280 +     * {@link UnsupportedOperationException} in response to its
 355.281 +     * {@code remove} method unless the list's {@code remove(int)} method is
 355.282 +     * overridden.
 355.283 +     *
 355.284 +     * <p>This implementation can be made to throw runtime exceptions in the
 355.285 +     * face of concurrent modification, as described in the specification
 355.286 +     * for the (protected) {@link #modCount} field.
 355.287 +     *
 355.288 +     * @return an iterator over the elements in this list in proper sequence
 355.289 +     */
 355.290 +    public Iterator<E> iterator() {
 355.291 +        return new Itr();
 355.292 +    }
 355.293 +
 355.294 +    /**
 355.295 +     * {@inheritDoc}
 355.296 +     *
 355.297 +     * <p>This implementation returns {@code listIterator(0)}.
 355.298 +     *
 355.299 +     * @see #listIterator(int)
 355.300 +     */
 355.301 +    public ListIterator<E> listIterator() {
 355.302 +        return listIterator(0);
 355.303 +    }
 355.304 +
 355.305 +    /**
 355.306 +     * {@inheritDoc}
 355.307 +     *
 355.308 +     * <p>This implementation returns a straightforward implementation of the
 355.309 +     * {@code ListIterator} interface that extends the implementation of the
 355.310 +     * {@code Iterator} interface returned by the {@code iterator()} method.
 355.311 +     * The {@code ListIterator} implementation relies on the backing list's
 355.312 +     * {@code get(int)}, {@code set(int, E)}, {@code add(int, E)}
 355.313 +     * and {@code remove(int)} methods.
 355.314 +     *
 355.315 +     * <p>Note that the list iterator returned by this implementation will
 355.316 +     * throw an {@link UnsupportedOperationException} in response to its
 355.317 +     * {@code remove}, {@code set} and {@code add} methods unless the
 355.318 +     * list's {@code remove(int)}, {@code set(int, E)}, and
 355.319 +     * {@code add(int, E)} methods are overridden.
 355.320 +     *
 355.321 +     * <p>This implementation can be made to throw runtime exceptions in the
 355.322 +     * face of concurrent modification, as described in the specification for
 355.323 +     * the (protected) {@link #modCount} field.
 355.324 +     *
 355.325 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 355.326 +     */
 355.327 +    public ListIterator<E> listIterator(final int index) {
 355.328 +        rangeCheckForAdd(index);
 355.329 +
 355.330 +        return new ListItr(index);
 355.331 +    }
 355.332 +
 355.333 +    private class Itr implements Iterator<E> {
 355.334 +        /**
 355.335 +         * Index of element to be returned by subsequent call to next.
 355.336 +         */
 355.337 +        int cursor = 0;
 355.338 +
 355.339 +        /**
 355.340 +         * Index of element returned by most recent call to next or
 355.341 +         * previous.  Reset to -1 if this element is deleted by a call
 355.342 +         * to remove.
 355.343 +         */
 355.344 +        int lastRet = -1;
 355.345 +
 355.346 +        /**
 355.347 +         * The modCount value that the iterator believes that the backing
 355.348 +         * List should have.  If this expectation is violated, the iterator
 355.349 +         * has detected concurrent modification.
 355.350 +         */
 355.351 +        int expectedModCount = modCount;
 355.352 +
 355.353 +        public boolean hasNext() {
 355.354 +            return cursor != size();
 355.355 +        }
 355.356 +
 355.357 +        public E next() {
 355.358 +            checkForComodification();
 355.359 +            try {
 355.360 +                int i = cursor;
 355.361 +                E next = get(i);
 355.362 +                lastRet = i;
 355.363 +                cursor = i + 1;
 355.364 +                return next;
 355.365 +            } catch (IndexOutOfBoundsException e) {
 355.366 +                checkForComodification();
 355.367 +                throw new NoSuchElementException();
 355.368 +            }
 355.369 +        }
 355.370 +
 355.371 +        public void remove() {
 355.372 +            if (lastRet < 0)
 355.373 +                throw new IllegalStateException();
 355.374 +            checkForComodification();
 355.375 +
 355.376 +            try {
 355.377 +                AbstractList.this.remove(lastRet);
 355.378 +                if (lastRet < cursor)
 355.379 +                    cursor--;
 355.380 +                lastRet = -1;
 355.381 +                expectedModCount = modCount;
 355.382 +            } catch (IndexOutOfBoundsException e) {
 355.383 +                throw new ConcurrentModificationException();
 355.384 +            }
 355.385 +        }
 355.386 +
 355.387 +        final void checkForComodification() {
 355.388 +            if (modCount != expectedModCount)
 355.389 +                throw new ConcurrentModificationException();
 355.390 +        }
 355.391 +    }
 355.392 +
 355.393 +    private class ListItr extends Itr implements ListIterator<E> {
 355.394 +        ListItr(int index) {
 355.395 +            cursor = index;
 355.396 +        }
 355.397 +
 355.398 +        public boolean hasPrevious() {
 355.399 +            return cursor != 0;
 355.400 +        }
 355.401 +
 355.402 +        public E previous() {
 355.403 +            checkForComodification();
 355.404 +            try {
 355.405 +                int i = cursor - 1;
 355.406 +                E previous = get(i);
 355.407 +                lastRet = cursor = i;
 355.408 +                return previous;
 355.409 +            } catch (IndexOutOfBoundsException e) {
 355.410 +                checkForComodification();
 355.411 +                throw new NoSuchElementException();
 355.412 +            }
 355.413 +        }
 355.414 +
 355.415 +        public int nextIndex() {
 355.416 +            return cursor;
 355.417 +        }
 355.418 +
 355.419 +        public int previousIndex() {
 355.420 +            return cursor-1;
 355.421 +        }
 355.422 +
 355.423 +        public void set(E e) {
 355.424 +            if (lastRet < 0)
 355.425 +                throw new IllegalStateException();
 355.426 +            checkForComodification();
 355.427 +
 355.428 +            try {
 355.429 +                AbstractList.this.set(lastRet, e);
 355.430 +                expectedModCount = modCount;
 355.431 +            } catch (IndexOutOfBoundsException ex) {
 355.432 +                throw new ConcurrentModificationException();
 355.433 +            }
 355.434 +        }
 355.435 +
 355.436 +        public void add(E e) {
 355.437 +            checkForComodification();
 355.438 +
 355.439 +            try {
 355.440 +                int i = cursor;
 355.441 +                AbstractList.this.add(i, e);
 355.442 +                lastRet = -1;
 355.443 +                cursor = i + 1;
 355.444 +                expectedModCount = modCount;
 355.445 +            } catch (IndexOutOfBoundsException ex) {
 355.446 +                throw new ConcurrentModificationException();
 355.447 +            }
 355.448 +        }
 355.449 +    }
 355.450 +
 355.451 +    /**
 355.452 +     * {@inheritDoc}
 355.453 +     *
 355.454 +     * <p>This implementation returns a list that subclasses
 355.455 +     * {@code AbstractList}.  The subclass stores, in private fields, the
 355.456 +     * offset of the subList within the backing list, the size of the subList
 355.457 +     * (which can change over its lifetime), and the expected
 355.458 +     * {@code modCount} value of the backing list.  There are two variants
 355.459 +     * of the subclass, one of which implements {@code RandomAccess}.
 355.460 +     * If this list implements {@code RandomAccess} the returned list will
 355.461 +     * be an instance of the subclass that implements {@code RandomAccess}.
 355.462 +     *
 355.463 +     * <p>The subclass's {@code set(int, E)}, {@code get(int)},
 355.464 +     * {@code add(int, E)}, {@code remove(int)}, {@code addAll(int,
 355.465 +     * Collection)} and {@code removeRange(int, int)} methods all
 355.466 +     * delegate to the corresponding methods on the backing abstract list,
 355.467 +     * after bounds-checking the index and adjusting for the offset.  The
 355.468 +     * {@code addAll(Collection c)} method merely returns {@code addAll(size,
 355.469 +     * c)}.
 355.470 +     *
 355.471 +     * <p>The {@code listIterator(int)} method returns a "wrapper object"
 355.472 +     * over a list iterator on the backing list, which is created with the
 355.473 +     * corresponding method on the backing list.  The {@code iterator} method
 355.474 +     * merely returns {@code listIterator()}, and the {@code size} method
 355.475 +     * merely returns the subclass's {@code size} field.
 355.476 +     *
 355.477 +     * <p>All methods first check to see if the actual {@code modCount} of
 355.478 +     * the backing list is equal to its expected value, and throw a
 355.479 +     * {@code ConcurrentModificationException} if it is not.
 355.480 +     *
 355.481 +     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
 355.482 +     *         {@code (fromIndex < 0 || toIndex > size)}
 355.483 +     * @throws IllegalArgumentException if the endpoint indices are out of order
 355.484 +     *         {@code (fromIndex > toIndex)}
 355.485 +     */
 355.486 +    public List<E> subList(int fromIndex, int toIndex) {
 355.487 +        return (this instanceof RandomAccess ?
 355.488 +                new RandomAccessSubList<>(this, fromIndex, toIndex) :
 355.489 +                new SubList<>(this, fromIndex, toIndex));
 355.490 +    }
 355.491 +
 355.492 +    // Comparison and hashing
 355.493 +
 355.494 +    /**
 355.495 +     * Compares the specified object with this list for equality.  Returns
 355.496 +     * {@code true} if and only if the specified object is also a list, both
 355.497 +     * lists have the same size, and all corresponding pairs of elements in
 355.498 +     * the two lists are <i>equal</i>.  (Two elements {@code e1} and
 355.499 +     * {@code e2} are <i>equal</i> if {@code (e1==null ? e2==null :
 355.500 +     * e1.equals(e2))}.)  In other words, two lists are defined to be
 355.501 +     * equal if they contain the same elements in the same order.<p>
 355.502 +     *
 355.503 +     * This implementation first checks if the specified object is this
 355.504 +     * list. If so, it returns {@code true}; if not, it checks if the
 355.505 +     * specified object is a list. If not, it returns {@code false}; if so,
 355.506 +     * it iterates over both lists, comparing corresponding pairs of elements.
 355.507 +     * If any comparison returns {@code false}, this method returns
 355.508 +     * {@code false}.  If either iterator runs out of elements before the
 355.509 +     * other it returns {@code false} (as the lists are of unequal length);
 355.510 +     * otherwise it returns {@code true} when the iterations complete.
 355.511 +     *
 355.512 +     * @param o the object to be compared for equality with this list
 355.513 +     * @return {@code true} if the specified object is equal to this list
 355.514 +     */
 355.515 +    public boolean equals(Object o) {
 355.516 +        if (o == this)
 355.517 +            return true;
 355.518 +        if (!(o instanceof List))
 355.519 +            return false;
 355.520 +
 355.521 +        ListIterator<E> e1 = listIterator();
 355.522 +        ListIterator e2 = ((List) o).listIterator();
 355.523 +        while (e1.hasNext() && e2.hasNext()) {
 355.524 +            E o1 = e1.next();
 355.525 +            Object o2 = e2.next();
 355.526 +            if (!(o1==null ? o2==null : o1.equals(o2)))
 355.527 +                return false;
 355.528 +        }
 355.529 +        return !(e1.hasNext() || e2.hasNext());
 355.530 +    }
 355.531 +
 355.532 +    /**
 355.533 +     * Returns the hash code value for this list.
 355.534 +     *
 355.535 +     * <p>This implementation uses exactly the code that is used to define the
 355.536 +     * list hash function in the documentation for the {@link List#hashCode}
 355.537 +     * method.
 355.538 +     *
 355.539 +     * @return the hash code value for this list
 355.540 +     */
 355.541 +    public int hashCode() {
 355.542 +        int hashCode = 1;
 355.543 +        for (E e : this)
 355.544 +            hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
 355.545 +        return hashCode;
 355.546 +    }
 355.547 +
 355.548 +    /**
 355.549 +     * Removes from this list all of the elements whose index is between
 355.550 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 355.551 +     * Shifts any succeeding elements to the left (reduces their index).
 355.552 +     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 355.553 +     * (If {@code toIndex==fromIndex}, this operation has no effect.)
 355.554 +     *
 355.555 +     * <p>This method is called by the {@code clear} operation on this list
 355.556 +     * and its subLists.  Overriding this method to take advantage of
 355.557 +     * the internals of the list implementation can <i>substantially</i>
 355.558 +     * improve the performance of the {@code clear} operation on this list
 355.559 +     * and its subLists.
 355.560 +     *
 355.561 +     * <p>This implementation gets a list iterator positioned before
 355.562 +     * {@code fromIndex}, and repeatedly calls {@code ListIterator.next}
 355.563 +     * followed by {@code ListIterator.remove} until the entire range has
 355.564 +     * been removed.  <b>Note: if {@code ListIterator.remove} requires linear
 355.565 +     * time, this implementation requires quadratic time.</b>
 355.566 +     *
 355.567 +     * @param fromIndex index of first element to be removed
 355.568 +     * @param toIndex index after last element to be removed
 355.569 +     */
 355.570 +    protected void removeRange(int fromIndex, int toIndex) {
 355.571 +        ListIterator<E> it = listIterator(fromIndex);
 355.572 +        for (int i=0, n=toIndex-fromIndex; i<n; i++) {
 355.573 +            it.next();
 355.574 +            it.remove();
 355.575 +        }
 355.576 +    }
 355.577 +
 355.578 +    /**
 355.579 +     * The number of times this list has been <i>structurally modified</i>.
 355.580 +     * Structural modifications are those that change the size of the
 355.581 +     * list, or otherwise perturb it in such a fashion that iterations in
 355.582 +     * progress may yield incorrect results.
 355.583 +     *
 355.584 +     * <p>This field is used by the iterator and list iterator implementation
 355.585 +     * returned by the {@code iterator} and {@code listIterator} methods.
 355.586 +     * If the value of this field changes unexpectedly, the iterator (or list
 355.587 +     * iterator) will throw a {@code ConcurrentModificationException} in
 355.588 +     * response to the {@code next}, {@code remove}, {@code previous},
 355.589 +     * {@code set} or {@code add} operations.  This provides
 355.590 +     * <i>fail-fast</i> behavior, rather than non-deterministic behavior in
 355.591 +     * the face of concurrent modification during iteration.
 355.592 +     *
 355.593 +     * <p><b>Use of this field by subclasses is optional.</b> If a subclass
 355.594 +     * wishes to provide fail-fast iterators (and list iterators), then it
 355.595 +     * merely has to increment this field in its {@code add(int, E)} and
 355.596 +     * {@code remove(int)} methods (and any other methods that it overrides
 355.597 +     * that result in structural modifications to the list).  A single call to
 355.598 +     * {@code add(int, E)} or {@code remove(int)} must add no more than
 355.599 +     * one to this field, or the iterators (and list iterators) will throw
 355.600 +     * bogus {@code ConcurrentModificationExceptions}.  If an implementation
 355.601 +     * does not wish to provide fail-fast iterators, this field may be
 355.602 +     * ignored.
 355.603 +     */
 355.604 +    protected transient int modCount = 0;
 355.605 +
 355.606 +    private void rangeCheckForAdd(int index) {
 355.607 +        if (index < 0 || index > size())
 355.608 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 355.609 +    }
 355.610 +
 355.611 +    private String outOfBoundsMsg(int index) {
 355.612 +        return "Index: "+index+", Size: "+size();
 355.613 +    }
 355.614 +}
 355.615 +
 355.616 +class SubList<E> extends AbstractList<E> {
 355.617 +    private final AbstractList<E> l;
 355.618 +    private final int offset;
 355.619 +    private int size;
 355.620 +
 355.621 +    SubList(AbstractList<E> list, int fromIndex, int toIndex) {
 355.622 +        if (fromIndex < 0)
 355.623 +            throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
 355.624 +        if (toIndex > list.size())
 355.625 +            throw new IndexOutOfBoundsException("toIndex = " + toIndex);
 355.626 +        if (fromIndex > toIndex)
 355.627 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
 355.628 +                                               ") > toIndex(" + toIndex + ")");
 355.629 +        l = list;
 355.630 +        offset = fromIndex;
 355.631 +        size = toIndex - fromIndex;
 355.632 +        this.modCount = l.modCount;
 355.633 +    }
 355.634 +
 355.635 +    public E set(int index, E element) {
 355.636 +        rangeCheck(index);
 355.637 +        checkForComodification();
 355.638 +        return l.set(index+offset, element);
 355.639 +    }
 355.640 +
 355.641 +    public E get(int index) {
 355.642 +        rangeCheck(index);
 355.643 +        checkForComodification();
 355.644 +        return l.get(index+offset);
 355.645 +    }
 355.646 +
 355.647 +    public int size() {
 355.648 +        checkForComodification();
 355.649 +        return size;
 355.650 +    }
 355.651 +
 355.652 +    public void add(int index, E element) {
 355.653 +        rangeCheckForAdd(index);
 355.654 +        checkForComodification();
 355.655 +        l.add(index+offset, element);
 355.656 +        this.modCount = l.modCount;
 355.657 +        size++;
 355.658 +    }
 355.659 +
 355.660 +    public E remove(int index) {
 355.661 +        rangeCheck(index);
 355.662 +        checkForComodification();
 355.663 +        E result = l.remove(index+offset);
 355.664 +        this.modCount = l.modCount;
 355.665 +        size--;
 355.666 +        return result;
 355.667 +    }
 355.668 +
 355.669 +    protected void removeRange(int fromIndex, int toIndex) {
 355.670 +        checkForComodification();
 355.671 +        l.removeRange(fromIndex+offset, toIndex+offset);
 355.672 +        this.modCount = l.modCount;
 355.673 +        size -= (toIndex-fromIndex);
 355.674 +    }
 355.675 +
 355.676 +    public boolean addAll(Collection<? extends E> c) {
 355.677 +        return addAll(size, c);
 355.678 +    }
 355.679 +
 355.680 +    public boolean addAll(int index, Collection<? extends E> c) {
 355.681 +        rangeCheckForAdd(index);
 355.682 +        int cSize = c.size();
 355.683 +        if (cSize==0)
 355.684 +            return false;
 355.685 +
 355.686 +        checkForComodification();
 355.687 +        l.addAll(offset+index, c);
 355.688 +        this.modCount = l.modCount;
 355.689 +        size += cSize;
 355.690 +        return true;
 355.691 +    }
 355.692 +
 355.693 +    public Iterator<E> iterator() {
 355.694 +        return listIterator();
 355.695 +    }
 355.696 +
 355.697 +    public ListIterator<E> listIterator(final int index) {
 355.698 +        checkForComodification();
 355.699 +        rangeCheckForAdd(index);
 355.700 +
 355.701 +        return new ListIterator<E>() {
 355.702 +            private final ListIterator<E> i = l.listIterator(index+offset);
 355.703 +
 355.704 +            public boolean hasNext() {
 355.705 +                return nextIndex() < size;
 355.706 +            }
 355.707 +
 355.708 +            public E next() {
 355.709 +                if (hasNext())
 355.710 +                    return i.next();
 355.711 +                else
 355.712 +                    throw new NoSuchElementException();
 355.713 +            }
 355.714 +
 355.715 +            public boolean hasPrevious() {
 355.716 +                return previousIndex() >= 0;
 355.717 +            }
 355.718 +
 355.719 +            public E previous() {
 355.720 +                if (hasPrevious())
 355.721 +                    return i.previous();
 355.722 +                else
 355.723 +                    throw new NoSuchElementException();
 355.724 +            }
 355.725 +
 355.726 +            public int nextIndex() {
 355.727 +                return i.nextIndex() - offset;
 355.728 +            }
 355.729 +
 355.730 +            public int previousIndex() {
 355.731 +                return i.previousIndex() - offset;
 355.732 +            }
 355.733 +
 355.734 +            public void remove() {
 355.735 +                i.remove();
 355.736 +                SubList.this.modCount = l.modCount;
 355.737 +                size--;
 355.738 +            }
 355.739 +
 355.740 +            public void set(E e) {
 355.741 +                i.set(e);
 355.742 +            }
 355.743 +
 355.744 +            public void add(E e) {
 355.745 +                i.add(e);
 355.746 +                SubList.this.modCount = l.modCount;
 355.747 +                size++;
 355.748 +            }
 355.749 +        };
 355.750 +    }
 355.751 +
 355.752 +    public List<E> subList(int fromIndex, int toIndex) {
 355.753 +        return new SubList<>(this, fromIndex, toIndex);
 355.754 +    }
 355.755 +
 355.756 +    private void rangeCheck(int index) {
 355.757 +        if (index < 0 || index >= size)
 355.758 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 355.759 +    }
 355.760 +
 355.761 +    private void rangeCheckForAdd(int index) {
 355.762 +        if (index < 0 || index > size)
 355.763 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 355.764 +    }
 355.765 +
 355.766 +    private String outOfBoundsMsg(int index) {
 355.767 +        return "Index: "+index+", Size: "+size;
 355.768 +    }
 355.769 +
 355.770 +    private void checkForComodification() {
 355.771 +        if (this.modCount != l.modCount)
 355.772 +            throw new ConcurrentModificationException();
 355.773 +    }
 355.774 +}
 355.775 +
 355.776 +class RandomAccessSubList<E> extends SubList<E> implements RandomAccess {
 355.777 +    RandomAccessSubList(AbstractList<E> list, int fromIndex, int toIndex) {
 355.778 +        super(list, fromIndex, toIndex);
 355.779 +    }
 355.780 +
 355.781 +    public List<E> subList(int fromIndex, int toIndex) {
 355.782 +        return new RandomAccessSubList<>(this, fromIndex, toIndex);
 355.783 +    }
 355.784 +}
   356.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   356.2 +++ b/rt/emul/compact/src/main/java/java/util/AbstractMap.java	Wed Feb 27 11:24:58 2013 +0100
   356.3 @@ -0,0 +1,822 @@
   356.4 +/*
   356.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   356.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   356.7 + *
   356.8 + * This code is free software; you can redistribute it and/or modify it
   356.9 + * under the terms of the GNU General Public License version 2 only, as
  356.10 + * published by the Free Software Foundation.  Oracle designates this
  356.11 + * particular file as subject to the "Classpath" exception as provided
  356.12 + * by Oracle in the LICENSE file that accompanied this code.
  356.13 + *
  356.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  356.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  356.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  356.17 + * version 2 for more details (a copy is included in the LICENSE file that
  356.18 + * accompanied this code).
  356.19 + *
  356.20 + * You should have received a copy of the GNU General Public License version
  356.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  356.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  356.23 + *
  356.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  356.25 + * or visit www.oracle.com if you need additional information or have any
  356.26 + * questions.
  356.27 + */
  356.28 +
  356.29 +package java.util;
  356.30 +import java.util.Map.Entry;
  356.31 +
  356.32 +/**
  356.33 + * This class provides a skeletal implementation of the <tt>Map</tt>
  356.34 + * interface, to minimize the effort required to implement this interface.
  356.35 + *
  356.36 + * <p>To implement an unmodifiable map, the programmer needs only to extend this
  356.37 + * class and provide an implementation for the <tt>entrySet</tt> method, which
  356.38 + * returns a set-view of the map's mappings.  Typically, the returned set
  356.39 + * will, in turn, be implemented atop <tt>AbstractSet</tt>.  This set should
  356.40 + * not support the <tt>add</tt> or <tt>remove</tt> methods, and its iterator
  356.41 + * should not support the <tt>remove</tt> method.
  356.42 + *
  356.43 + * <p>To implement a modifiable map, the programmer must additionally override
  356.44 + * this class's <tt>put</tt> method (which otherwise throws an
  356.45 + * <tt>UnsupportedOperationException</tt>), and the iterator returned by
  356.46 + * <tt>entrySet().iterator()</tt> must additionally implement its
  356.47 + * <tt>remove</tt> method.
  356.48 + *
  356.49 + * <p>The programmer should generally provide a void (no argument) and map
  356.50 + * constructor, as per the recommendation in the <tt>Map</tt> interface
  356.51 + * specification.
  356.52 + *
  356.53 + * <p>The documentation for each non-abstract method in this class describes its
  356.54 + * implementation in detail.  Each of these methods may be overridden if the
  356.55 + * map being implemented admits a more efficient implementation.
  356.56 + *
  356.57 + * <p>This class is a member of the
  356.58 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  356.59 + * Java Collections Framework</a>.
  356.60 + *
  356.61 + * @param <K> the type of keys maintained by this map
  356.62 + * @param <V> the type of mapped values
  356.63 + *
  356.64 + * @author  Josh Bloch
  356.65 + * @author  Neal Gafter
  356.66 + * @see Map
  356.67 + * @see Collection
  356.68 + * @since 1.2
  356.69 + */
  356.70 +
  356.71 +public abstract class AbstractMap<K,V> implements Map<K,V> {
  356.72 +    /**
  356.73 +     * Sole constructor.  (For invocation by subclass constructors, typically
  356.74 +     * implicit.)
  356.75 +     */
  356.76 +    protected AbstractMap() {
  356.77 +    }
  356.78 +
  356.79 +    // Query Operations
  356.80 +
  356.81 +    /**
  356.82 +     * {@inheritDoc}
  356.83 +     *
  356.84 +     * <p>This implementation returns <tt>entrySet().size()</tt>.
  356.85 +     */
  356.86 +    public int size() {
  356.87 +        return entrySet().size();
  356.88 +    }
  356.89 +
  356.90 +    /**
  356.91 +     * {@inheritDoc}
  356.92 +     *
  356.93 +     * <p>This implementation returns <tt>size() == 0</tt>.
  356.94 +     */
  356.95 +    public boolean isEmpty() {
  356.96 +        return size() == 0;
  356.97 +    }
  356.98 +
  356.99 +    /**
 356.100 +     * {@inheritDoc}
 356.101 +     *
 356.102 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching
 356.103 +     * for an entry with the specified value.  If such an entry is found,
 356.104 +     * <tt>true</tt> is returned.  If the iteration terminates without
 356.105 +     * finding such an entry, <tt>false</tt> is returned.  Note that this
 356.106 +     * implementation requires linear time in the size of the map.
 356.107 +     *
 356.108 +     * @throws ClassCastException   {@inheritDoc}
 356.109 +     * @throws NullPointerException {@inheritDoc}
 356.110 +     */
 356.111 +    public boolean containsValue(Object value) {
 356.112 +        Iterator<Entry<K,V>> i = entrySet().iterator();
 356.113 +        if (value==null) {
 356.114 +            while (i.hasNext()) {
 356.115 +                Entry<K,V> e = i.next();
 356.116 +                if (e.getValue()==null)
 356.117 +                    return true;
 356.118 +            }
 356.119 +        } else {
 356.120 +            while (i.hasNext()) {
 356.121 +                Entry<K,V> e = i.next();
 356.122 +                if (value.equals(e.getValue()))
 356.123 +                    return true;
 356.124 +            }
 356.125 +        }
 356.126 +        return false;
 356.127 +    }
 356.128 +
 356.129 +    /**
 356.130 +     * {@inheritDoc}
 356.131 +     *
 356.132 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching
 356.133 +     * for an entry with the specified key.  If such an entry is found,
 356.134 +     * <tt>true</tt> is returned.  If the iteration terminates without
 356.135 +     * finding such an entry, <tt>false</tt> is returned.  Note that this
 356.136 +     * implementation requires linear time in the size of the map; many
 356.137 +     * implementations will override this method.
 356.138 +     *
 356.139 +     * @throws ClassCastException   {@inheritDoc}
 356.140 +     * @throws NullPointerException {@inheritDoc}
 356.141 +     */
 356.142 +    public boolean containsKey(Object key) {
 356.143 +        Iterator<Map.Entry<K,V>> i = entrySet().iterator();
 356.144 +        if (key==null) {
 356.145 +            while (i.hasNext()) {
 356.146 +                Entry<K,V> e = i.next();
 356.147 +                if (e.getKey()==null)
 356.148 +                    return true;
 356.149 +            }
 356.150 +        } else {
 356.151 +            while (i.hasNext()) {
 356.152 +                Entry<K,V> e = i.next();
 356.153 +                if (key.equals(e.getKey()))
 356.154 +                    return true;
 356.155 +            }
 356.156 +        }
 356.157 +        return false;
 356.158 +    }
 356.159 +
 356.160 +    /**
 356.161 +     * {@inheritDoc}
 356.162 +     *
 356.163 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching
 356.164 +     * for an entry with the specified key.  If such an entry is found,
 356.165 +     * the entry's value is returned.  If the iteration terminates without
 356.166 +     * finding such an entry, <tt>null</tt> is returned.  Note that this
 356.167 +     * implementation requires linear time in the size of the map; many
 356.168 +     * implementations will override this method.
 356.169 +     *
 356.170 +     * @throws ClassCastException            {@inheritDoc}
 356.171 +     * @throws NullPointerException          {@inheritDoc}
 356.172 +     */
 356.173 +    public V get(Object key) {
 356.174 +        Iterator<Entry<K,V>> i = entrySet().iterator();
 356.175 +        if (key==null) {
 356.176 +            while (i.hasNext()) {
 356.177 +                Entry<K,V> e = i.next();
 356.178 +                if (e.getKey()==null)
 356.179 +                    return e.getValue();
 356.180 +            }
 356.181 +        } else {
 356.182 +            while (i.hasNext()) {
 356.183 +                Entry<K,V> e = i.next();
 356.184 +                if (key.equals(e.getKey()))
 356.185 +                    return e.getValue();
 356.186 +            }
 356.187 +        }
 356.188 +        return null;
 356.189 +    }
 356.190 +
 356.191 +
 356.192 +    // Modification Operations
 356.193 +
 356.194 +    /**
 356.195 +     * {@inheritDoc}
 356.196 +     *
 356.197 +     * <p>This implementation always throws an
 356.198 +     * <tt>UnsupportedOperationException</tt>.
 356.199 +     *
 356.200 +     * @throws UnsupportedOperationException {@inheritDoc}
 356.201 +     * @throws ClassCastException            {@inheritDoc}
 356.202 +     * @throws NullPointerException          {@inheritDoc}
 356.203 +     * @throws IllegalArgumentException      {@inheritDoc}
 356.204 +     */
 356.205 +    public V put(K key, V value) {
 356.206 +        throw new UnsupportedOperationException();
 356.207 +    }
 356.208 +
 356.209 +    /**
 356.210 +     * {@inheritDoc}
 356.211 +     *
 356.212 +     * <p>This implementation iterates over <tt>entrySet()</tt> searching for an
 356.213 +     * entry with the specified key.  If such an entry is found, its value is
 356.214 +     * obtained with its <tt>getValue</tt> operation, the entry is removed
 356.215 +     * from the collection (and the backing map) with the iterator's
 356.216 +     * <tt>remove</tt> operation, and the saved value is returned.  If the
 356.217 +     * iteration terminates without finding such an entry, <tt>null</tt> is
 356.218 +     * returned.  Note that this implementation requires linear time in the
 356.219 +     * size of the map; many implementations will override this method.
 356.220 +     *
 356.221 +     * <p>Note that this implementation throws an
 356.222 +     * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
 356.223 +     * iterator does not support the <tt>remove</tt> method and this map
 356.224 +     * contains a mapping for the specified key.
 356.225 +     *
 356.226 +     * @throws UnsupportedOperationException {@inheritDoc}
 356.227 +     * @throws ClassCastException            {@inheritDoc}
 356.228 +     * @throws NullPointerException          {@inheritDoc}
 356.229 +     */
 356.230 +    public V remove(Object key) {
 356.231 +        Iterator<Entry<K,V>> i = entrySet().iterator();
 356.232 +        Entry<K,V> correctEntry = null;
 356.233 +        if (key==null) {
 356.234 +            while (correctEntry==null && i.hasNext()) {
 356.235 +                Entry<K,V> e = i.next();
 356.236 +                if (e.getKey()==null)
 356.237 +                    correctEntry = e;
 356.238 +            }
 356.239 +        } else {
 356.240 +            while (correctEntry==null && i.hasNext()) {
 356.241 +                Entry<K,V> e = i.next();
 356.242 +                if (key.equals(e.getKey()))
 356.243 +                    correctEntry = e;
 356.244 +            }
 356.245 +        }
 356.246 +
 356.247 +        V oldValue = null;
 356.248 +        if (correctEntry !=null) {
 356.249 +            oldValue = correctEntry.getValue();
 356.250 +            i.remove();
 356.251 +        }
 356.252 +        return oldValue;
 356.253 +    }
 356.254 +
 356.255 +
 356.256 +    // Bulk Operations
 356.257 +
 356.258 +    /**
 356.259 +     * {@inheritDoc}
 356.260 +     *
 356.261 +     * <p>This implementation iterates over the specified map's
 356.262 +     * <tt>entrySet()</tt> collection, and calls this map's <tt>put</tt>
 356.263 +     * operation once for each entry returned by the iteration.
 356.264 +     *
 356.265 +     * <p>Note that this implementation throws an
 356.266 +     * <tt>UnsupportedOperationException</tt> if this map does not support
 356.267 +     * the <tt>put</tt> operation and the specified map is nonempty.
 356.268 +     *
 356.269 +     * @throws UnsupportedOperationException {@inheritDoc}
 356.270 +     * @throws ClassCastException            {@inheritDoc}
 356.271 +     * @throws NullPointerException          {@inheritDoc}
 356.272 +     * @throws IllegalArgumentException      {@inheritDoc}
 356.273 +     */
 356.274 +    public void putAll(Map<? extends K, ? extends V> m) {
 356.275 +        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
 356.276 +            put(e.getKey(), e.getValue());
 356.277 +    }
 356.278 +
 356.279 +    /**
 356.280 +     * {@inheritDoc}
 356.281 +     *
 356.282 +     * <p>This implementation calls <tt>entrySet().clear()</tt>.
 356.283 +     *
 356.284 +     * <p>Note that this implementation throws an
 356.285 +     * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
 356.286 +     * does not support the <tt>clear</tt> operation.
 356.287 +     *
 356.288 +     * @throws UnsupportedOperationException {@inheritDoc}
 356.289 +     */
 356.290 +    public void clear() {
 356.291 +        entrySet().clear();
 356.292 +    }
 356.293 +
 356.294 +
 356.295 +    // Views
 356.296 +
 356.297 +    /**
 356.298 +     * Each of these fields are initialized to contain an instance of the
 356.299 +     * appropriate view the first time this view is requested.  The views are
 356.300 +     * stateless, so there's no reason to create more than one of each.
 356.301 +     */
 356.302 +    transient volatile Set<K>        keySet = null;
 356.303 +    transient volatile Collection<V> values = null;
 356.304 +
 356.305 +    /**
 356.306 +     * {@inheritDoc}
 356.307 +     *
 356.308 +     * <p>This implementation returns a set that subclasses {@link AbstractSet}.
 356.309 +     * The subclass's iterator method returns a "wrapper object" over this
 356.310 +     * map's <tt>entrySet()</tt> iterator.  The <tt>size</tt> method
 356.311 +     * delegates to this map's <tt>size</tt> method and the
 356.312 +     * <tt>contains</tt> method delegates to this map's
 356.313 +     * <tt>containsKey</tt> method.
 356.314 +     *
 356.315 +     * <p>The set is created the first time this method is called,
 356.316 +     * and returned in response to all subsequent calls.  No synchronization
 356.317 +     * is performed, so there is a slight chance that multiple calls to this
 356.318 +     * method will not all return the same set.
 356.319 +     */
 356.320 +    public Set<K> keySet() {
 356.321 +        if (keySet == null) {
 356.322 +            keySet = new AbstractSet<K>() {
 356.323 +                public Iterator<K> iterator() {
 356.324 +                    return new Iterator<K>() {
 356.325 +                        private Iterator<Entry<K,V>> i = entrySet().iterator();
 356.326 +
 356.327 +                        public boolean hasNext() {
 356.328 +                            return i.hasNext();
 356.329 +                        }
 356.330 +
 356.331 +                        public K next() {
 356.332 +                            return i.next().getKey();
 356.333 +                        }
 356.334 +
 356.335 +                        public void remove() {
 356.336 +                            i.remove();
 356.337 +                        }
 356.338 +                    };
 356.339 +                }
 356.340 +
 356.341 +                public int size() {
 356.342 +                    return AbstractMap.this.size();
 356.343 +                }
 356.344 +
 356.345 +                public boolean isEmpty() {
 356.346 +                    return AbstractMap.this.isEmpty();
 356.347 +                }
 356.348 +
 356.349 +                public void clear() {
 356.350 +                    AbstractMap.this.clear();
 356.351 +                }
 356.352 +
 356.353 +                public boolean contains(Object k) {
 356.354 +                    return AbstractMap.this.containsKey(k);
 356.355 +                }
 356.356 +            };
 356.357 +        }
 356.358 +        return keySet;
 356.359 +    }
 356.360 +
 356.361 +    /**
 356.362 +     * {@inheritDoc}
 356.363 +     *
 356.364 +     * <p>This implementation returns a collection that subclasses {@link
 356.365 +     * AbstractCollection}.  The subclass's iterator method returns a
 356.366 +     * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
 356.367 +     * The <tt>size</tt> method delegates to this map's <tt>size</tt>
 356.368 +     * method and the <tt>contains</tt> method delegates to this map's
 356.369 +     * <tt>containsValue</tt> method.
 356.370 +     *
 356.371 +     * <p>The collection is created the first time this method is called, and
 356.372 +     * returned in response to all subsequent calls.  No synchronization is
 356.373 +     * performed, so there is a slight chance that multiple calls to this
 356.374 +     * method will not all return the same collection.
 356.375 +     */
 356.376 +    public Collection<V> values() {
 356.377 +        if (values == null) {
 356.378 +            values = new AbstractCollection<V>() {
 356.379 +                public Iterator<V> iterator() {
 356.380 +                    return new Iterator<V>() {
 356.381 +                        private Iterator<Entry<K,V>> i = entrySet().iterator();
 356.382 +
 356.383 +                        public boolean hasNext() {
 356.384 +                            return i.hasNext();
 356.385 +                        }
 356.386 +
 356.387 +                        public V next() {
 356.388 +                            return i.next().getValue();
 356.389 +                        }
 356.390 +
 356.391 +                        public void remove() {
 356.392 +                            i.remove();
 356.393 +                        }
 356.394 +                    };
 356.395 +                }
 356.396 +
 356.397 +                public int size() {
 356.398 +                    return AbstractMap.this.size();
 356.399 +                }
 356.400 +
 356.401 +                public boolean isEmpty() {
 356.402 +                    return AbstractMap.this.isEmpty();
 356.403 +                }
 356.404 +
 356.405 +                public void clear() {
 356.406 +                    AbstractMap.this.clear();
 356.407 +                }
 356.408 +
 356.409 +                public boolean contains(Object v) {
 356.410 +                    return AbstractMap.this.containsValue(v);
 356.411 +                }
 356.412 +            };
 356.413 +        }
 356.414 +        return values;
 356.415 +    }
 356.416 +
 356.417 +    public abstract Set<Entry<K,V>> entrySet();
 356.418 +
 356.419 +
 356.420 +    // Comparison and hashing
 356.421 +
 356.422 +    /**
 356.423 +     * Compares the specified object with this map for equality.  Returns
 356.424 +     * <tt>true</tt> if the given object is also a map and the two maps
 356.425 +     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
 356.426 +     * <tt>m2</tt> represent the same mappings if
 356.427 +     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
 356.428 +     * <tt>equals</tt> method works properly across different implementations
 356.429 +     * of the <tt>Map</tt> interface.
 356.430 +     *
 356.431 +     * <p>This implementation first checks if the specified object is this map;
 356.432 +     * if so it returns <tt>true</tt>.  Then, it checks if the specified
 356.433 +     * object is a map whose size is identical to the size of this map; if
 356.434 +     * not, it returns <tt>false</tt>.  If so, it iterates over this map's
 356.435 +     * <tt>entrySet</tt> collection, and checks that the specified map
 356.436 +     * contains each mapping that this map contains.  If the specified map
 356.437 +     * fails to contain such a mapping, <tt>false</tt> is returned.  If the
 356.438 +     * iteration completes, <tt>true</tt> is returned.
 356.439 +     *
 356.440 +     * @param o object to be compared for equality with this map
 356.441 +     * @return <tt>true</tt> if the specified object is equal to this map
 356.442 +     */
 356.443 +    public boolean equals(Object o) {
 356.444 +        if (o == this)
 356.445 +            return true;
 356.446 +
 356.447 +        if (!(o instanceof Map))
 356.448 +            return false;
 356.449 +        Map<K,V> m = (Map<K,V>) o;
 356.450 +        if (m.size() != size())
 356.451 +            return false;
 356.452 +
 356.453 +        try {
 356.454 +            Iterator<Entry<K,V>> i = entrySet().iterator();
 356.455 +            while (i.hasNext()) {
 356.456 +                Entry<K,V> e = i.next();
 356.457 +                K key = e.getKey();
 356.458 +                V value = e.getValue();
 356.459 +                if (value == null) {
 356.460 +                    if (!(m.get(key)==null && m.containsKey(key)))
 356.461 +                        return false;
 356.462 +                } else {
 356.463 +                    if (!value.equals(m.get(key)))
 356.464 +                        return false;
 356.465 +                }
 356.466 +            }
 356.467 +        } catch (ClassCastException unused) {
 356.468 +            return false;
 356.469 +        } catch (NullPointerException unused) {
 356.470 +            return false;
 356.471 +        }
 356.472 +
 356.473 +        return true;
 356.474 +    }
 356.475 +
 356.476 +    /**
 356.477 +     * Returns the hash code value for this map.  The hash code of a map is
 356.478 +     * defined to be the sum of the hash codes of each entry in the map's
 356.479 +     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
 356.480 +     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
 356.481 +     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
 356.482 +     * {@link Object#hashCode}.
 356.483 +     *
 356.484 +     * <p>This implementation iterates over <tt>entrySet()</tt>, calling
 356.485 +     * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
 356.486 +     * set, and adding up the results.
 356.487 +     *
 356.488 +     * @return the hash code value for this map
 356.489 +     * @see Map.Entry#hashCode()
 356.490 +     * @see Object#equals(Object)
 356.491 +     * @see Set#equals(Object)
 356.492 +     */
 356.493 +    public int hashCode() {
 356.494 +        int h = 0;
 356.495 +        Iterator<Entry<K,V>> i = entrySet().iterator();
 356.496 +        while (i.hasNext())
 356.497 +            h += i.next().hashCode();
 356.498 +        return h;
 356.499 +    }
 356.500 +
 356.501 +    /**
 356.502 +     * Returns a string representation of this map.  The string representation
 356.503 +     * consists of a list of key-value mappings in the order returned by the
 356.504 +     * map's <tt>entrySet</tt> view's iterator, enclosed in braces
 356.505 +     * (<tt>"{}"</tt>).  Adjacent mappings are separated by the characters
 356.506 +     * <tt>", "</tt> (comma and space).  Each key-value mapping is rendered as
 356.507 +     * the key followed by an equals sign (<tt>"="</tt>) followed by the
 356.508 +     * associated value.  Keys and values are converted to strings as by
 356.509 +     * {@link String#valueOf(Object)}.
 356.510 +     *
 356.511 +     * @return a string representation of this map
 356.512 +     */
 356.513 +    public String toString() {
 356.514 +        Iterator<Entry<K,V>> i = entrySet().iterator();
 356.515 +        if (! i.hasNext())
 356.516 +            return "{}";
 356.517 +
 356.518 +        StringBuilder sb = new StringBuilder();
 356.519 +        sb.append('{');
 356.520 +        for (;;) {
 356.521 +            Entry<K,V> e = i.next();
 356.522 +            K key = e.getKey();
 356.523 +            V value = e.getValue();
 356.524 +            sb.append(key   == this ? "(this Map)" : key);
 356.525 +            sb.append('=');
 356.526 +            sb.append(value == this ? "(this Map)" : value);
 356.527 +            if (! i.hasNext())
 356.528 +                return sb.append('}').toString();
 356.529 +            sb.append(',').append(' ');
 356.530 +        }
 356.531 +    }
 356.532 +
 356.533 +    /**
 356.534 +     * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
 356.535 +     * and values themselves are not cloned.
 356.536 +     *
 356.537 +     * @return a shallow copy of this map
 356.538 +     */
 356.539 +    protected Object clone() throws CloneNotSupportedException {
 356.540 +        AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
 356.541 +        result.keySet = null;
 356.542 +        result.values = null;
 356.543 +        return result;
 356.544 +    }
 356.545 +
 356.546 +    /**
 356.547 +     * Utility method for SimpleEntry and SimpleImmutableEntry.
 356.548 +     * Test for equality, checking for nulls.
 356.549 +     */
 356.550 +    private static boolean eq(Object o1, Object o2) {
 356.551 +        return o1 == null ? o2 == null : o1.equals(o2);
 356.552 +    }
 356.553 +
 356.554 +    // Implementation Note: SimpleEntry and SimpleImmutableEntry
 356.555 +    // are distinct unrelated classes, even though they share
 356.556 +    // some code. Since you can't add or subtract final-ness
 356.557 +    // of a field in a subclass, they can't share representations,
 356.558 +    // and the amount of duplicated code is too small to warrant
 356.559 +    // exposing a common abstract class.
 356.560 +
 356.561 +
 356.562 +    /**
 356.563 +     * An Entry maintaining a key and a value.  The value may be
 356.564 +     * changed using the <tt>setValue</tt> method.  This class
 356.565 +     * facilitates the process of building custom map
 356.566 +     * implementations. For example, it may be convenient to return
 356.567 +     * arrays of <tt>SimpleEntry</tt> instances in method
 356.568 +     * <tt>Map.entrySet().toArray</tt>.
 356.569 +     *
 356.570 +     * @since 1.6
 356.571 +     */
 356.572 +    public static class SimpleEntry<K,V>
 356.573 +        implements Entry<K,V>, java.io.Serializable
 356.574 +    {
 356.575 +        private static final long serialVersionUID = -8499721149061103585L;
 356.576 +
 356.577 +        private final K key;
 356.578 +        private V value;
 356.579 +
 356.580 +        /**
 356.581 +         * Creates an entry representing a mapping from the specified
 356.582 +         * key to the specified value.
 356.583 +         *
 356.584 +         * @param key the key represented by this entry
 356.585 +         * @param value the value represented by this entry
 356.586 +         */
 356.587 +        public SimpleEntry(K key, V value) {
 356.588 +            this.key   = key;
 356.589 +            this.value = value;
 356.590 +        }
 356.591 +
 356.592 +        /**
 356.593 +         * Creates an entry representing the same mapping as the
 356.594 +         * specified entry.
 356.595 +         *
 356.596 +         * @param entry the entry to copy
 356.597 +         */
 356.598 +        public SimpleEntry(Entry<? extends K, ? extends V> entry) {
 356.599 +            this.key   = entry.getKey();
 356.600 +            this.value = entry.getValue();
 356.601 +        }
 356.602 +
 356.603 +        /**
 356.604 +         * Returns the key corresponding to this entry.
 356.605 +         *
 356.606 +         * @return the key corresponding to this entry
 356.607 +         */
 356.608 +        public K getKey() {
 356.609 +            return key;
 356.610 +        }
 356.611 +
 356.612 +        /**
 356.613 +         * Returns the value corresponding to this entry.
 356.614 +         *
 356.615 +         * @return the value corresponding to this entry
 356.616 +         */
 356.617 +        public V getValue() {
 356.618 +            return value;
 356.619 +        }
 356.620 +
 356.621 +        /**
 356.622 +         * Replaces the value corresponding to this entry with the specified
 356.623 +         * value.
 356.624 +         *
 356.625 +         * @param value new value to be stored in this entry
 356.626 +         * @return the old value corresponding to the entry
 356.627 +         */
 356.628 +        public V setValue(V value) {
 356.629 +            V oldValue = this.value;
 356.630 +            this.value = value;
 356.631 +            return oldValue;
 356.632 +        }
 356.633 +
 356.634 +        /**
 356.635 +         * Compares the specified object with this entry for equality.
 356.636 +         * Returns {@code true} if the given object is also a map entry and
 356.637 +         * the two entries represent the same mapping.  More formally, two
 356.638 +         * entries {@code e1} and {@code e2} represent the same mapping
 356.639 +         * if<pre>
 356.640 +         *   (e1.getKey()==null ?
 356.641 +         *    e2.getKey()==null :
 356.642 +         *    e1.getKey().equals(e2.getKey()))
 356.643 +         *   &amp;&amp;
 356.644 +         *   (e1.getValue()==null ?
 356.645 +         *    e2.getValue()==null :
 356.646 +         *    e1.getValue().equals(e2.getValue()))</pre>
 356.647 +         * This ensures that the {@code equals} method works properly across
 356.648 +         * different implementations of the {@code Map.Entry} interface.
 356.649 +         *
 356.650 +         * @param o object to be compared for equality with this map entry
 356.651 +         * @return {@code true} if the specified object is equal to this map
 356.652 +         *         entry
 356.653 +         * @see    #hashCode
 356.654 +         */
 356.655 +        public boolean equals(Object o) {
 356.656 +            if (!(o instanceof Map.Entry))
 356.657 +                return false;
 356.658 +            Map.Entry e = (Map.Entry)o;
 356.659 +            return eq(key, e.getKey()) && eq(value, e.getValue());
 356.660 +        }
 356.661 +
 356.662 +        /**
 356.663 +         * Returns the hash code value for this map entry.  The hash code
 356.664 +         * of a map entry {@code e} is defined to be: <pre>
 356.665 +         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
 356.666 +         *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
 356.667 +         * This ensures that {@code e1.equals(e2)} implies that
 356.668 +         * {@code e1.hashCode()==e2.hashCode()} for any two Entries
 356.669 +         * {@code e1} and {@code e2}, as required by the general
 356.670 +         * contract of {@link Object#hashCode}.
 356.671 +         *
 356.672 +         * @return the hash code value for this map entry
 356.673 +         * @see    #equals
 356.674 +         */
 356.675 +        public int hashCode() {
 356.676 +            return (key   == null ? 0 :   key.hashCode()) ^
 356.677 +                   (value == null ? 0 : value.hashCode());
 356.678 +        }
 356.679 +
 356.680 +        /**
 356.681 +         * Returns a String representation of this map entry.  This
 356.682 +         * implementation returns the string representation of this
 356.683 +         * entry's key followed by the equals character ("<tt>=</tt>")
 356.684 +         * followed by the string representation of this entry's value.
 356.685 +         *
 356.686 +         * @return a String representation of this map entry
 356.687 +         */
 356.688 +        public String toString() {
 356.689 +            return key + "=" + value;
 356.690 +        }
 356.691 +
 356.692 +    }
 356.693 +
 356.694 +    /**
 356.695 +     * An Entry maintaining an immutable key and value.  This class
 356.696 +     * does not support method <tt>setValue</tt>.  This class may be
 356.697 +     * convenient in methods that return thread-safe snapshots of
 356.698 +     * key-value mappings.
 356.699 +     *
 356.700 +     * @since 1.6
 356.701 +     */
 356.702 +    public static class SimpleImmutableEntry<K,V>
 356.703 +        implements Entry<K,V>, java.io.Serializable
 356.704 +    {
 356.705 +        private static final long serialVersionUID = 7138329143949025153L;
 356.706 +
 356.707 +        private final K key;
 356.708 +        private final V value;
 356.709 +
 356.710 +        /**
 356.711 +         * Creates an entry representing a mapping from the specified
 356.712 +         * key to the specified value.
 356.713 +         *
 356.714 +         * @param key the key represented by this entry
 356.715 +         * @param value the value represented by this entry
 356.716 +         */
 356.717 +        public SimpleImmutableEntry(K key, V value) {
 356.718 +            this.key   = key;
 356.719 +            this.value = value;
 356.720 +        }
 356.721 +
 356.722 +        /**
 356.723 +         * Creates an entry representing the same mapping as the
 356.724 +         * specified entry.
 356.725 +         *
 356.726 +         * @param entry the entry to copy
 356.727 +         */
 356.728 +        public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) {
 356.729 +            this.key   = entry.getKey();
 356.730 +            this.value = entry.getValue();
 356.731 +        }
 356.732 +
 356.733 +        /**
 356.734 +         * Returns the key corresponding to this entry.
 356.735 +         *
 356.736 +         * @return the key corresponding to this entry
 356.737 +         */
 356.738 +        public K getKey() {
 356.739 +            return key;
 356.740 +        }
 356.741 +
 356.742 +        /**
 356.743 +         * Returns the value corresponding to this entry.
 356.744 +         *
 356.745 +         * @return the value corresponding to this entry
 356.746 +         */
 356.747 +        public V getValue() {
 356.748 +            return value;
 356.749 +        }
 356.750 +
 356.751 +        /**
 356.752 +         * Replaces the value corresponding to this entry with the specified
 356.753 +         * value (optional operation).  This implementation simply throws
 356.754 +         * <tt>UnsupportedOperationException</tt>, as this class implements
 356.755 +         * an <i>immutable</i> map entry.
 356.756 +         *
 356.757 +         * @param value new value to be stored in this entry
 356.758 +         * @return (Does not return)
 356.759 +         * @throws UnsupportedOperationException always
 356.760 +         */
 356.761 +        public V setValue(V value) {
 356.762 +            throw new UnsupportedOperationException();
 356.763 +        }
 356.764 +
 356.765 +        /**
 356.766 +         * Compares the specified object with this entry for equality.
 356.767 +         * Returns {@code true} if the given object is also a map entry and
 356.768 +         * the two entries represent the same mapping.  More formally, two
 356.769 +         * entries {@code e1} and {@code e2} represent the same mapping
 356.770 +         * if<pre>
 356.771 +         *   (e1.getKey()==null ?
 356.772 +         *    e2.getKey()==null :
 356.773 +         *    e1.getKey().equals(e2.getKey()))
 356.774 +         *   &amp;&amp;
 356.775 +         *   (e1.getValue()==null ?
 356.776 +         *    e2.getValue()==null :
 356.777 +         *    e1.getValue().equals(e2.getValue()))</pre>
 356.778 +         * This ensures that the {@code equals} method works properly across
 356.779 +         * different implementations of the {@code Map.Entry} interface.
 356.780 +         *
 356.781 +         * @param o object to be compared for equality with this map entry
 356.782 +         * @return {@code true} if the specified object is equal to this map
 356.783 +         *         entry
 356.784 +         * @see    #hashCode
 356.785 +         */
 356.786 +        public boolean equals(Object o) {
 356.787 +            if (!(o instanceof Map.Entry))
 356.788 +                return false;
 356.789 +            Map.Entry e = (Map.Entry)o;
 356.790 +            return eq(key, e.getKey()) && eq(value, e.getValue());
 356.791 +        }
 356.792 +
 356.793 +        /**
 356.794 +         * Returns the hash code value for this map entry.  The hash code
 356.795 +         * of a map entry {@code e} is defined to be: <pre>
 356.796 +         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
 356.797 +         *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
 356.798 +         * This ensures that {@code e1.equals(e2)} implies that
 356.799 +         * {@code e1.hashCode()==e2.hashCode()} for any two Entries
 356.800 +         * {@code e1} and {@code e2}, as required by the general
 356.801 +         * contract of {@link Object#hashCode}.
 356.802 +         *
 356.803 +         * @return the hash code value for this map entry
 356.804 +         * @see    #equals
 356.805 +         */
 356.806 +        public int hashCode() {
 356.807 +            return (key   == null ? 0 :   key.hashCode()) ^
 356.808 +                   (value == null ? 0 : value.hashCode());
 356.809 +        }
 356.810 +
 356.811 +        /**
 356.812 +         * Returns a String representation of this map entry.  This
 356.813 +         * implementation returns the string representation of this
 356.814 +         * entry's key followed by the equals character ("<tt>=</tt>")
 356.815 +         * followed by the string representation of this entry's value.
 356.816 +         *
 356.817 +         * @return a String representation of this map entry
 356.818 +         */
 356.819 +        public String toString() {
 356.820 +            return key + "=" + value;
 356.821 +        }
 356.822 +
 356.823 +    }
 356.824 +
 356.825 +}
   357.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   357.2 +++ b/rt/emul/compact/src/main/java/java/util/AbstractQueue.java	Wed Feb 27 11:24:58 2013 +0100
   357.3 @@ -0,0 +1,192 @@
   357.4 +/*
   357.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   357.6 + *
   357.7 + * This code is free software; you can redistribute it and/or modify it
   357.8 + * under the terms of the GNU General Public License version 2 only, as
   357.9 + * published by the Free Software Foundation.  Oracle designates this
  357.10 + * particular file as subject to the "Classpath" exception as provided
  357.11 + * by Oracle in the LICENSE file that accompanied this code.
  357.12 + *
  357.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  357.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  357.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  357.16 + * version 2 for more details (a copy is included in the LICENSE file that
  357.17 + * accompanied this code).
  357.18 + *
  357.19 + * You should have received a copy of the GNU General Public License version
  357.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  357.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  357.22 + *
  357.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  357.24 + * or visit www.oracle.com if you need additional information or have any
  357.25 + * questions.
  357.26 + */
  357.27 +
  357.28 +/*
  357.29 + * This file is available under and governed by the GNU General Public
  357.30 + * License version 2 only, as published by the Free Software Foundation.
  357.31 + * However, the following notice accompanied the original version of this
  357.32 + * file:
  357.33 + *
  357.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
  357.35 + * Expert Group and released to the public domain, as explained at
  357.36 + * http://creativecommons.org/publicdomain/zero/1.0/
  357.37 + */
  357.38 +
  357.39 +package java.util;
  357.40 +
  357.41 +/**
  357.42 + * This class provides skeletal implementations of some {@link Queue}
  357.43 + * operations. The implementations in this class are appropriate when
  357.44 + * the base implementation does <em>not</em> allow <tt>null</tt>
  357.45 + * elements.  Methods {@link #add add}, {@link #remove remove}, and
  357.46 + * {@link #element element} are based on {@link #offer offer}, {@link
  357.47 + * #poll poll}, and {@link #peek peek}, respectively, but throw
  357.48 + * exceptions instead of indicating failure via <tt>false</tt> or
  357.49 + * <tt>null</tt> returns.
  357.50 + *
  357.51 + * <p>A <tt>Queue</tt> implementation that extends this class must
  357.52 + * minimally define a method {@link Queue#offer} which does not permit
  357.53 + * insertion of <tt>null</tt> elements, along with methods {@link
  357.54 + * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and
  357.55 + * {@link Collection#iterator}.  Typically, additional methods will be
  357.56 + * overridden as well.  If these requirements cannot be met, consider
  357.57 + * instead subclassing {@link AbstractCollection}.
  357.58 + *
  357.59 + * <p>This class is a member of the
  357.60 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  357.61 + * Java Collections Framework</a>.
  357.62 + *
  357.63 + * @since 1.5
  357.64 + * @author Doug Lea
  357.65 + * @param <E> the type of elements held in this collection
  357.66 + */
  357.67 +public abstract class AbstractQueue<E>
  357.68 +    extends AbstractCollection<E>
  357.69 +    implements Queue<E> {
  357.70 +
  357.71 +    /**
  357.72 +     * Constructor for use by subclasses.
  357.73 +     */
  357.74 +    protected AbstractQueue() {
  357.75 +    }
  357.76 +
  357.77 +    /**
  357.78 +     * Inserts the specified element into this queue if it is possible to do so
  357.79 +     * immediately without violating capacity restrictions, returning
  357.80 +     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
  357.81 +     * if no space is currently available.
  357.82 +     *
  357.83 +     * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds,
  357.84 +     * else throws an <tt>IllegalStateException</tt>.
  357.85 +     *
  357.86 +     * @param e the element to add
  357.87 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
  357.88 +     * @throws IllegalStateException if the element cannot be added at this
  357.89 +     *         time due to capacity restrictions
  357.90 +     * @throws ClassCastException if the class of the specified element
  357.91 +     *         prevents it from being added to this queue
  357.92 +     * @throws NullPointerException if the specified element is null and
  357.93 +     *         this queue does not permit null elements
  357.94 +     * @throws IllegalArgumentException if some property of this element
  357.95 +     *         prevents it from being added to this queue
  357.96 +     */
  357.97 +    public boolean add(E e) {
  357.98 +        if (offer(e))
  357.99 +            return true;
 357.100 +        else
 357.101 +            throw new IllegalStateException("Queue full");
 357.102 +    }
 357.103 +
 357.104 +    /**
 357.105 +     * Retrieves and removes the head of this queue.  This method differs
 357.106 +     * from {@link #poll poll} only in that it throws an exception if this
 357.107 +     * queue is empty.
 357.108 +     *
 357.109 +     * <p>This implementation returns the result of <tt>poll</tt>
 357.110 +     * unless the queue is empty.
 357.111 +     *
 357.112 +     * @return the head of this queue
 357.113 +     * @throws NoSuchElementException if this queue is empty
 357.114 +     */
 357.115 +    public E remove() {
 357.116 +        E x = poll();
 357.117 +        if (x != null)
 357.118 +            return x;
 357.119 +        else
 357.120 +            throw new NoSuchElementException();
 357.121 +    }
 357.122 +
 357.123 +    /**
 357.124 +     * Retrieves, but does not remove, the head of this queue.  This method
 357.125 +     * differs from {@link #peek peek} only in that it throws an exception if
 357.126 +     * this queue is empty.
 357.127 +     *
 357.128 +     * <p>This implementation returns the result of <tt>peek</tt>
 357.129 +     * unless the queue is empty.
 357.130 +     *
 357.131 +     * @return the head of this queue
 357.132 +     * @throws NoSuchElementException if this queue is empty
 357.133 +     */
 357.134 +    public E element() {
 357.135 +        E x = peek();
 357.136 +        if (x != null)
 357.137 +            return x;
 357.138 +        else
 357.139 +            throw new NoSuchElementException();
 357.140 +    }
 357.141 +
 357.142 +    /**
 357.143 +     * Removes all of the elements from this queue.
 357.144 +     * The queue will be empty after this call returns.
 357.145 +     *
 357.146 +     * <p>This implementation repeatedly invokes {@link #poll poll} until it
 357.147 +     * returns <tt>null</tt>.
 357.148 +     */
 357.149 +    public void clear() {
 357.150 +        while (poll() != null)
 357.151 +            ;
 357.152 +    }
 357.153 +
 357.154 +    /**
 357.155 +     * Adds all of the elements in the specified collection to this
 357.156 +     * queue.  Attempts to addAll of a queue to itself result in
 357.157 +     * <tt>IllegalArgumentException</tt>. Further, the behavior of
 357.158 +     * this operation is undefined if the specified collection is
 357.159 +     * modified while the operation is in progress.
 357.160 +     *
 357.161 +     * <p>This implementation iterates over the specified collection,
 357.162 +     * and adds each element returned by the iterator to this
 357.163 +     * queue, in turn.  A runtime exception encountered while
 357.164 +     * trying to add an element (including, in particular, a
 357.165 +     * <tt>null</tt> element) may result in only some of the elements
 357.166 +     * having been successfully added when the associated exception is
 357.167 +     * thrown.
 357.168 +     *
 357.169 +     * @param c collection containing elements to be added to this queue
 357.170 +     * @return <tt>true</tt> if this queue changed as a result of the call
 357.171 +     * @throws ClassCastException if the class of an element of the specified
 357.172 +     *         collection prevents it from being added to this queue
 357.173 +     * @throws NullPointerException if the specified collection contains a
 357.174 +     *         null element and this queue does not permit null elements,
 357.175 +     *         or if the specified collection is null
 357.176 +     * @throws IllegalArgumentException if some property of an element of the
 357.177 +     *         specified collection prevents it from being added to this
 357.178 +     *         queue, or if the specified collection is this queue
 357.179 +     * @throws IllegalStateException if not all the elements can be added at
 357.180 +     *         this time due to insertion restrictions
 357.181 +     * @see #add(Object)
 357.182 +     */
 357.183 +    public boolean addAll(Collection<? extends E> c) {
 357.184 +        if (c == null)
 357.185 +            throw new NullPointerException();
 357.186 +        if (c == this)
 357.187 +            throw new IllegalArgumentException();
 357.188 +        boolean modified = false;
 357.189 +        for (E e : c)
 357.190 +            if (add(e))
 357.191 +                modified = true;
 357.192 +        return modified;
 357.193 +    }
 357.194 +
 357.195 +}
   358.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   358.2 +++ b/rt/emul/compact/src/main/java/java/util/AbstractSequentialList.java	Wed Feb 27 11:24:58 2013 +0100
   358.3 @@ -0,0 +1,253 @@
   358.4 +/*
   358.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   358.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   358.7 + *
   358.8 + * This code is free software; you can redistribute it and/or modify it
   358.9 + * under the terms of the GNU General Public License version 2 only, as
  358.10 + * published by the Free Software Foundation.  Oracle designates this
  358.11 + * particular file as subject to the "Classpath" exception as provided
  358.12 + * by Oracle in the LICENSE file that accompanied this code.
  358.13 + *
  358.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  358.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  358.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  358.17 + * version 2 for more details (a copy is included in the LICENSE file that
  358.18 + * accompanied this code).
  358.19 + *
  358.20 + * You should have received a copy of the GNU General Public License version
  358.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  358.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  358.23 + *
  358.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  358.25 + * or visit www.oracle.com if you need additional information or have any
  358.26 + * questions.
  358.27 + */
  358.28 +
  358.29 +package java.util;
  358.30 +
  358.31 +/**
  358.32 + * This class provides a skeletal implementation of the <tt>List</tt>
  358.33 + * interface to minimize the effort required to implement this interface
  358.34 + * backed by a "sequential access" data store (such as a linked list).  For
  358.35 + * random access data (such as an array), <tt>AbstractList</tt> should be used
  358.36 + * in preference to this class.<p>
  358.37 + *
  358.38 + * This class is the opposite of the <tt>AbstractList</tt> class in the sense
  358.39 + * that it implements the "random access" methods (<tt>get(int index)</tt>,
  358.40 + * <tt>set(int index, E element)</tt>, <tt>add(int index, E element)</tt> and
  358.41 + * <tt>remove(int index)</tt>) on top of the list's list iterator, instead of
  358.42 + * the other way around.<p>
  358.43 + *
  358.44 + * To implement a list the programmer needs only to extend this class and
  358.45 + * provide implementations for the <tt>listIterator</tt> and <tt>size</tt>
  358.46 + * methods.  For an unmodifiable list, the programmer need only implement the
  358.47 + * list iterator's <tt>hasNext</tt>, <tt>next</tt>, <tt>hasPrevious</tt>,
  358.48 + * <tt>previous</tt> and <tt>index</tt> methods.<p>
  358.49 + *
  358.50 + * For a modifiable list the programmer should additionally implement the list
  358.51 + * iterator's <tt>set</tt> method.  For a variable-size list the programmer
  358.52 + * should additionally implement the list iterator's <tt>remove</tt> and
  358.53 + * <tt>add</tt> methods.<p>
  358.54 + *
  358.55 + * The programmer should generally provide a void (no argument) and collection
  358.56 + * constructor, as per the recommendation in the <tt>Collection</tt> interface
  358.57 + * specification.<p>
  358.58 + *
  358.59 + * This class is a member of the
  358.60 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  358.61 + * Java Collections Framework</a>.
  358.62 + *
  358.63 + * @author  Josh Bloch
  358.64 + * @author  Neal Gafter
  358.65 + * @see Collection
  358.66 + * @see List
  358.67 + * @see AbstractList
  358.68 + * @see AbstractCollection
  358.69 + * @since 1.2
  358.70 + */
  358.71 +
  358.72 +public abstract class AbstractSequentialList<E> extends AbstractList<E> {
  358.73 +    /**
  358.74 +     * Sole constructor.  (For invocation by subclass constructors, typically
  358.75 +     * implicit.)
  358.76 +     */
  358.77 +    protected AbstractSequentialList() {
  358.78 +    }
  358.79 +
  358.80 +    /**
  358.81 +     * Returns the element at the specified position in this list.
  358.82 +     *
  358.83 +     * <p>This implementation first gets a list iterator pointing to the
  358.84 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
  358.85 +     * the element using <tt>ListIterator.next</tt> and returns it.
  358.86 +     *
  358.87 +     * @throws IndexOutOfBoundsException {@inheritDoc}
  358.88 +     */
  358.89 +    public E get(int index) {
  358.90 +        try {
  358.91 +            return listIterator(index).next();
  358.92 +        } catch (NoSuchElementException exc) {
  358.93 +            throw new IndexOutOfBoundsException("Index: "+index);
  358.94 +        }
  358.95 +    }
  358.96 +
  358.97 +    /**
  358.98 +     * Replaces the element at the specified position in this list with the
  358.99 +     * specified element (optional operation).
 358.100 +     *
 358.101 +     * <p>This implementation first gets a list iterator pointing to the
 358.102 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
 358.103 +     * the current element using <tt>ListIterator.next</tt> and replaces it
 358.104 +     * with <tt>ListIterator.set</tt>.
 358.105 +     *
 358.106 +     * <p>Note that this implementation will throw an
 358.107 +     * <tt>UnsupportedOperationException</tt> if the list iterator does not
 358.108 +     * implement the <tt>set</tt> operation.
 358.109 +     *
 358.110 +     * @throws UnsupportedOperationException {@inheritDoc}
 358.111 +     * @throws ClassCastException            {@inheritDoc}
 358.112 +     * @throws NullPointerException          {@inheritDoc}
 358.113 +     * @throws IllegalArgumentException      {@inheritDoc}
 358.114 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 358.115 +     */
 358.116 +    public E set(int index, E element) {
 358.117 +        try {
 358.118 +            ListIterator<E> e = listIterator(index);
 358.119 +            E oldVal = e.next();
 358.120 +            e.set(element);
 358.121 +            return oldVal;
 358.122 +        } catch (NoSuchElementException exc) {
 358.123 +            throw new IndexOutOfBoundsException("Index: "+index);
 358.124 +        }
 358.125 +    }
 358.126 +
 358.127 +    /**
 358.128 +     * Inserts the specified element at the specified position in this list
 358.129 +     * (optional operation).  Shifts the element currently at that position
 358.130 +     * (if any) and any subsequent elements to the right (adds one to their
 358.131 +     * indices).
 358.132 +     *
 358.133 +     * <p>This implementation first gets a list iterator pointing to the
 358.134 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it
 358.135 +     * inserts the specified element with <tt>ListIterator.add</tt>.
 358.136 +     *
 358.137 +     * <p>Note that this implementation will throw an
 358.138 +     * <tt>UnsupportedOperationException</tt> if the list iterator does not
 358.139 +     * implement the <tt>add</tt> operation.
 358.140 +     *
 358.141 +     * @throws UnsupportedOperationException {@inheritDoc}
 358.142 +     * @throws ClassCastException            {@inheritDoc}
 358.143 +     * @throws NullPointerException          {@inheritDoc}
 358.144 +     * @throws IllegalArgumentException      {@inheritDoc}
 358.145 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 358.146 +     */
 358.147 +    public void add(int index, E element) {
 358.148 +        try {
 358.149 +            listIterator(index).add(element);
 358.150 +        } catch (NoSuchElementException exc) {
 358.151 +            throw new IndexOutOfBoundsException("Index: "+index);
 358.152 +        }
 358.153 +    }
 358.154 +
 358.155 +    /**
 358.156 +     * Removes the element at the specified position in this list (optional
 358.157 +     * operation).  Shifts any subsequent elements to the left (subtracts one
 358.158 +     * from their indices).  Returns the element that was removed from the
 358.159 +     * list.
 358.160 +     *
 358.161 +     * <p>This implementation first gets a list iterator pointing to the
 358.162 +     * indexed element (with <tt>listIterator(index)</tt>).  Then, it removes
 358.163 +     * the element with <tt>ListIterator.remove</tt>.
 358.164 +     *
 358.165 +     * <p>Note that this implementation will throw an
 358.166 +     * <tt>UnsupportedOperationException</tt> if the list iterator does not
 358.167 +     * implement the <tt>remove</tt> operation.
 358.168 +     *
 358.169 +     * @throws UnsupportedOperationException {@inheritDoc}
 358.170 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 358.171 +     */
 358.172 +    public E remove(int index) {
 358.173 +        try {
 358.174 +            ListIterator<E> e = listIterator(index);
 358.175 +            E outCast = e.next();
 358.176 +            e.remove();
 358.177 +            return outCast;
 358.178 +        } catch (NoSuchElementException exc) {
 358.179 +            throw new IndexOutOfBoundsException("Index: "+index);
 358.180 +        }
 358.181 +    }
 358.182 +
 358.183 +
 358.184 +    // Bulk Operations
 358.185 +
 358.186 +    /**
 358.187 +     * Inserts all of the elements in the specified collection into this
 358.188 +     * list at the specified position (optional operation).  Shifts the
 358.189 +     * element currently at that position (if any) and any subsequent
 358.190 +     * elements to the right (increases their indices).  The new elements
 358.191 +     * will appear in this list in the order that they are returned by the
 358.192 +     * specified collection's iterator.  The behavior of this operation is
 358.193 +     * undefined if the specified collection is modified while the
 358.194 +     * operation is in progress.  (Note that this will occur if the specified
 358.195 +     * collection is this list, and it's nonempty.)
 358.196 +     *
 358.197 +     * <p>This implementation gets an iterator over the specified collection and
 358.198 +     * a list iterator over this list pointing to the indexed element (with
 358.199 +     * <tt>listIterator(index)</tt>).  Then, it iterates over the specified
 358.200 +     * collection, inserting the elements obtained from the iterator into this
 358.201 +     * list, one at a time, using <tt>ListIterator.add</tt> followed by
 358.202 +     * <tt>ListIterator.next</tt> (to skip over the added element).
 358.203 +     *
 358.204 +     * <p>Note that this implementation will throw an
 358.205 +     * <tt>UnsupportedOperationException</tt> if the list iterator returned by
 358.206 +     * the <tt>listIterator</tt> method does not implement the <tt>add</tt>
 358.207 +     * operation.
 358.208 +     *
 358.209 +     * @throws UnsupportedOperationException {@inheritDoc}
 358.210 +     * @throws ClassCastException            {@inheritDoc}
 358.211 +     * @throws NullPointerException          {@inheritDoc}
 358.212 +     * @throws IllegalArgumentException      {@inheritDoc}
 358.213 +     * @throws IndexOutOfBoundsException     {@inheritDoc}
 358.214 +     */
 358.215 +    public boolean addAll(int index, Collection<? extends E> c) {
 358.216 +        try {
 358.217 +            boolean modified = false;
 358.218 +            ListIterator<E> e1 = listIterator(index);
 358.219 +            Iterator<? extends E> e2 = c.iterator();
 358.220 +            while (e2.hasNext()) {
 358.221 +                e1.add(e2.next());
 358.222 +                modified = true;
 358.223 +            }
 358.224 +            return modified;
 358.225 +        } catch (NoSuchElementException exc) {
 358.226 +            throw new IndexOutOfBoundsException("Index: "+index);
 358.227 +        }
 358.228 +    }
 358.229 +
 358.230 +
 358.231 +    // Iterators
 358.232 +
 358.233 +    /**
 358.234 +     * Returns an iterator over the elements in this list (in proper
 358.235 +     * sequence).<p>
 358.236 +     *
 358.237 +     * This implementation merely returns a list iterator over the list.
 358.238 +     *
 358.239 +     * @return an iterator over the elements in this list (in proper sequence)
 358.240 +     */
 358.241 +    public Iterator<E> iterator() {
 358.242 +        return listIterator();
 358.243 +    }
 358.244 +
 358.245 +    /**
 358.246 +     * Returns a list iterator over the elements in this list (in proper
 358.247 +     * sequence).
 358.248 +     *
 358.249 +     * @param  index index of first element to be returned from the list
 358.250 +     *         iterator (by a call to the <code>next</code> method)
 358.251 +     * @return a list iterator over the elements in this list (in proper
 358.252 +     *         sequence)
 358.253 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 358.254 +     */
 358.255 +    public abstract ListIterator<E> listIterator(int index);
 358.256 +}
   359.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   359.2 +++ b/rt/emul/compact/src/main/java/java/util/AbstractSet.java	Wed Feb 27 11:24:58 2013 +0100
   359.3 @@ -0,0 +1,185 @@
   359.4 +/*
   359.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   359.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   359.7 + *
   359.8 + * This code is free software; you can redistribute it and/or modify it
   359.9 + * under the terms of the GNU General Public License version 2 only, as
  359.10 + * published by the Free Software Foundation.  Oracle designates this
  359.11 + * particular file as subject to the "Classpath" exception as provided
  359.12 + * by Oracle in the LICENSE file that accompanied this code.
  359.13 + *
  359.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  359.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  359.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  359.17 + * version 2 for more details (a copy is included in the LICENSE file that
  359.18 + * accompanied this code).
  359.19 + *
  359.20 + * You should have received a copy of the GNU General Public License version
  359.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  359.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  359.23 + *
  359.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  359.25 + * or visit www.oracle.com if you need additional information or have any
  359.26 + * questions.
  359.27 + */
  359.28 +
  359.29 +package java.util;
  359.30 +
  359.31 +/**
  359.32 + * This class provides a skeletal implementation of the <tt>Set</tt>
  359.33 + * interface to minimize the effort required to implement this
  359.34 + * interface. <p>
  359.35 + *
  359.36 + * The process of implementing a set by extending this class is identical
  359.37 + * to that of implementing a Collection by extending AbstractCollection,
  359.38 + * except that all of the methods and constructors in subclasses of this
  359.39 + * class must obey the additional constraints imposed by the <tt>Set</tt>
  359.40 + * interface (for instance, the add method must not permit addition of
  359.41 + * multiple instances of an object to a set).<p>
  359.42 + *
  359.43 + * Note that this class does not override any of the implementations from
  359.44 + * the <tt>AbstractCollection</tt> class.  It merely adds implementations
  359.45 + * for <tt>equals</tt> and <tt>hashCode</tt>.<p>
  359.46 + *
  359.47 + * This class is a member of the
  359.48 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  359.49 + * Java Collections Framework</a>.
  359.50 + *
  359.51 + * @param <E> the type of elements maintained by this set
  359.52 + *
  359.53 + * @author  Josh Bloch
  359.54 + * @author  Neal Gafter
  359.55 + * @see Collection
  359.56 + * @see AbstractCollection
  359.57 + * @see Set
  359.58 + * @since 1.2
  359.59 + */
  359.60 +
  359.61 +public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E> {
  359.62 +    /**
  359.63 +     * Sole constructor.  (For invocation by subclass constructors, typically
  359.64 +     * implicit.)
  359.65 +     */
  359.66 +    protected AbstractSet() {
  359.67 +    }
  359.68 +
  359.69 +    // Comparison and hashing
  359.70 +
  359.71 +    /**
  359.72 +     * Compares the specified object with this set for equality.  Returns
  359.73 +     * <tt>true</tt> if the given object is also a set, the two sets have
  359.74 +     * the same size, and every member of the given set is contained in
  359.75 +     * this set.  This ensures that the <tt>equals</tt> method works
  359.76 +     * properly across different implementations of the <tt>Set</tt>
  359.77 +     * interface.<p>
  359.78 +     *
  359.79 +     * This implementation first checks if the specified object is this
  359.80 +     * set; if so it returns <tt>true</tt>.  Then, it checks if the
  359.81 +     * specified object is a set whose size is identical to the size of
  359.82 +     * this set; if not, it returns false.  If so, it returns
  359.83 +     * <tt>containsAll((Collection) o)</tt>.
  359.84 +     *
  359.85 +     * @param o object to be compared for equality with this set
  359.86 +     * @return <tt>true</tt> if the specified object is equal to this set
  359.87 +     */
  359.88 +    public boolean equals(Object o) {
  359.89 +        if (o == this)
  359.90 +            return true;
  359.91 +
  359.92 +        if (!(o instanceof Set))
  359.93 +            return false;
  359.94 +        Collection c = (Collection) o;
  359.95 +        if (c.size() != size())
  359.96 +            return false;
  359.97 +        try {
  359.98 +            return containsAll(c);
  359.99 +        } catch (ClassCastException unused)   {
 359.100 +            return false;
 359.101 +        } catch (NullPointerException unused) {
 359.102 +            return false;
 359.103 +        }
 359.104 +    }
 359.105 +
 359.106 +    /**
 359.107 +     * Returns the hash code value for this set.  The hash code of a set is
 359.108 +     * defined to be the sum of the hash codes of the elements in the set,
 359.109 +     * where the hash code of a <tt>null</tt> element is defined to be zero.
 359.110 +     * This ensures that <tt>s1.equals(s2)</tt> implies that
 359.111 +     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
 359.112 +     * and <tt>s2</tt>, as required by the general contract of
 359.113 +     * {@link Object#hashCode}.
 359.114 +     *
 359.115 +     * <p>This implementation iterates over the set, calling the
 359.116 +     * <tt>hashCode</tt> method on each element in the set, and adding up
 359.117 +     * the results.
 359.118 +     *
 359.119 +     * @return the hash code value for this set
 359.120 +     * @see Object#equals(Object)
 359.121 +     * @see Set#equals(Object)
 359.122 +     */
 359.123 +    public int hashCode() {
 359.124 +        int h = 0;
 359.125 +        Iterator<E> i = iterator();
 359.126 +        while (i.hasNext()) {
 359.127 +            E obj = i.next();
 359.128 +            if (obj != null)
 359.129 +                h += obj.hashCode();
 359.130 +        }
 359.131 +        return h;
 359.132 +    }
 359.133 +
 359.134 +    /**
 359.135 +     * Removes from this set all of its elements that are contained in the
 359.136 +     * specified collection (optional operation).  If the specified
 359.137 +     * collection is also a set, this operation effectively modifies this
 359.138 +     * set so that its value is the <i>asymmetric set difference</i> of
 359.139 +     * the two sets.
 359.140 +     *
 359.141 +     * <p>This implementation determines which is the smaller of this set
 359.142 +     * and the specified collection, by invoking the <tt>size</tt>
 359.143 +     * method on each.  If this set has fewer elements, then the
 359.144 +     * implementation iterates over this set, checking each element
 359.145 +     * returned by the iterator in turn to see if it is contained in
 359.146 +     * the specified collection.  If it is so contained, it is removed
 359.147 +     * from this set with the iterator's <tt>remove</tt> method.  If
 359.148 +     * the specified collection has fewer elements, then the
 359.149 +     * implementation iterates over the specified collection, removing
 359.150 +     * from this set each element returned by the iterator, using this
 359.151 +     * set's <tt>remove</tt> method.
 359.152 +     *
 359.153 +     * <p>Note that this implementation will throw an
 359.154 +     * <tt>UnsupportedOperationException</tt> if the iterator returned by the
 359.155 +     * <tt>iterator</tt> method does not implement the <tt>remove</tt> method.
 359.156 +     *
 359.157 +     * @param  c collection containing elements to be removed from this set
 359.158 +     * @return <tt>true</tt> if this set changed as a result of the call
 359.159 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 359.160 +     *         is not supported by this set
 359.161 +     * @throws ClassCastException if the class of an element of this set
 359.162 +     *         is incompatible with the specified collection
 359.163 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 359.164 +     * @throws NullPointerException if this set contains a null element and the
 359.165 +     *         specified collection does not permit null elements
 359.166 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
 359.167 +     *         or if the specified collection is null
 359.168 +     * @see #remove(Object)
 359.169 +     * @see #contains(Object)
 359.170 +     */
 359.171 +    public boolean removeAll(Collection<?> c) {
 359.172 +        boolean modified = false;
 359.173 +
 359.174 +        if (size() > c.size()) {
 359.175 +            for (Iterator<?> i = c.iterator(); i.hasNext(); )
 359.176 +                modified |= remove(i.next());
 359.177 +        } else {
 359.178 +            for (Iterator<?> i = iterator(); i.hasNext(); ) {
 359.179 +                if (c.contains(i.next())) {
 359.180 +                    i.remove();
 359.181 +                    modified = true;
 359.182 +                }
 359.183 +            }
 359.184 +        }
 359.185 +        return modified;
 359.186 +    }
 359.187 +
 359.188 +}
   360.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   360.2 +++ b/rt/emul/compact/src/main/java/java/util/ArrayDeque.java	Wed Feb 27 11:24:58 2013 +0100
   360.3 @@ -0,0 +1,830 @@
   360.4 +/*
   360.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   360.6 + *
   360.7 + * This code is free software; you can redistribute it and/or modify it
   360.8 + * under the terms of the GNU General Public License version 2 only, as
   360.9 + * published by the Free Software Foundation.  Oracle designates this
  360.10 + * particular file as subject to the "Classpath" exception as provided
  360.11 + * by Oracle in the LICENSE file that accompanied this code.
  360.12 + *
  360.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  360.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  360.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  360.16 + * version 2 for more details (a copy is included in the LICENSE file that
  360.17 + * accompanied this code).
  360.18 + *
  360.19 + * You should have received a copy of the GNU General Public License version
  360.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  360.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  360.22 + *
  360.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  360.24 + * or visit www.oracle.com if you need additional information or have any
  360.25 + * questions.
  360.26 + */
  360.27 +
  360.28 +/*
  360.29 + * This file is available under and governed by the GNU General Public
  360.30 + * License version 2 only, as published by the Free Software Foundation.
  360.31 + * However, the following notice accompanied the original version of this
  360.32 + * file:
  360.33 + *
  360.34 + * Written by Josh Bloch of Google Inc. and released to the public domain,
  360.35 + * as explained at http://creativecommons.org/publicdomain/zero/1.0/.
  360.36 + */
  360.37 +
  360.38 +package java.util;
  360.39 +import java.io.*;
  360.40 +
  360.41 +/**
  360.42 + * Resizable-array implementation of the {@link Deque} interface.  Array
  360.43 + * deques have no capacity restrictions; they grow as necessary to support
  360.44 + * usage.  They are not thread-safe; in the absence of external
  360.45 + * synchronization, they do not support concurrent access by multiple threads.
  360.46 + * Null elements are prohibited.  This class is likely to be faster than
  360.47 + * {@link Stack} when used as a stack, and faster than {@link LinkedList}
  360.48 + * when used as a queue.
  360.49 + *
  360.50 + * <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
  360.51 + * Exceptions include {@link #remove(Object) remove}, {@link
  360.52 + * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
  360.53 + * removeLastOccurrence}, {@link #contains contains}, {@link #iterator
  360.54 + * iterator.remove()}, and the bulk operations, all of which run in linear
  360.55 + * time.
  360.56 + *
  360.57 + * <p>The iterators returned by this class's <tt>iterator</tt> method are
  360.58 + * <i>fail-fast</i>: If the deque is modified at any time after the iterator
  360.59 + * is created, in any way except through the iterator's own <tt>remove</tt>
  360.60 + * method, the iterator will generally throw a {@link
  360.61 + * ConcurrentModificationException}.  Thus, in the face of concurrent
  360.62 + * modification, the iterator fails quickly and cleanly, rather than risking
  360.63 + * arbitrary, non-deterministic behavior at an undetermined time in the
  360.64 + * future.
  360.65 + *
  360.66 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  360.67 + * as it is, generally speaking, impossible to make any hard guarantees in the
  360.68 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  360.69 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  360.70 + * Therefore, it would be wrong to write a program that depended on this
  360.71 + * exception for its correctness: <i>the fail-fast behavior of iterators
  360.72 + * should be used only to detect bugs.</i>
  360.73 + *
  360.74 + * <p>This class and its iterator implement all of the
  360.75 + * <em>optional</em> methods of the {@link Collection} and {@link
  360.76 + * Iterator} interfaces.
  360.77 + *
  360.78 + * <p>This class is a member of the
  360.79 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  360.80 + * Java Collections Framework</a>.
  360.81 + *
  360.82 + * @author  Josh Bloch and Doug Lea
  360.83 + * @since   1.6
  360.84 + * @param <E> the type of elements held in this collection
  360.85 + */
  360.86 +public class ArrayDeque<E> extends AbstractCollection<E>
  360.87 +                           implements Deque<E>, Cloneable, Serializable
  360.88 +{
  360.89 +    /**
  360.90 +     * The array in which the elements of the deque are stored.
  360.91 +     * The capacity of the deque is the length of this array, which is
  360.92 +     * always a power of two. The array is never allowed to become
  360.93 +     * full, except transiently within an addX method where it is
  360.94 +     * resized (see doubleCapacity) immediately upon becoming full,
  360.95 +     * thus avoiding head and tail wrapping around to equal each
  360.96 +     * other.  We also guarantee that all array cells not holding
  360.97 +     * deque elements are always null.
  360.98 +     */
  360.99 +    private transient E[] elements;
 360.100 +
 360.101 +    /**
 360.102 +     * The index of the element at the head of the deque (which is the
 360.103 +     * element that would be removed by remove() or pop()); or an
 360.104 +     * arbitrary number equal to tail if the deque is empty.
 360.105 +     */
 360.106 +    private transient int head;
 360.107 +
 360.108 +    /**
 360.109 +     * The index at which the next element would be added to the tail
 360.110 +     * of the deque (via addLast(E), add(E), or push(E)).
 360.111 +     */
 360.112 +    private transient int tail;
 360.113 +
 360.114 +    /**
 360.115 +     * The minimum capacity that we'll use for a newly created deque.
 360.116 +     * Must be a power of 2.
 360.117 +     */
 360.118 +    private static final int MIN_INITIAL_CAPACITY = 8;
 360.119 +
 360.120 +    // ******  Array allocation and resizing utilities ******
 360.121 +
 360.122 +    /**
 360.123 +     * Allocate empty array to hold the given number of elements.
 360.124 +     *
 360.125 +     * @param numElements  the number of elements to hold
 360.126 +     */
 360.127 +    private void allocateElements(int numElements) {
 360.128 +        int initialCapacity = MIN_INITIAL_CAPACITY;
 360.129 +        // Find the best power of two to hold elements.
 360.130 +        // Tests "<=" because arrays aren't kept full.
 360.131 +        if (numElements >= initialCapacity) {
 360.132 +            initialCapacity = numElements;
 360.133 +            initialCapacity |= (initialCapacity >>>  1);
 360.134 +            initialCapacity |= (initialCapacity >>>  2);
 360.135 +            initialCapacity |= (initialCapacity >>>  4);
 360.136 +            initialCapacity |= (initialCapacity >>>  8);
 360.137 +            initialCapacity |= (initialCapacity >>> 16);
 360.138 +            initialCapacity++;
 360.139 +
 360.140 +            if (initialCapacity < 0)   // Too many elements, must back off
 360.141 +                initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
 360.142 +        }
 360.143 +        elements = (E[]) new Object[initialCapacity];
 360.144 +    }
 360.145 +
 360.146 +    /**
 360.147 +     * Double the capacity of this deque.  Call only when full, i.e.,
 360.148 +     * when head and tail have wrapped around to become equal.
 360.149 +     */
 360.150 +    private void doubleCapacity() {
 360.151 +        assert head == tail;
 360.152 +        int p = head;
 360.153 +        int n = elements.length;
 360.154 +        int r = n - p; // number of elements to the right of p
 360.155 +        int newCapacity = n << 1;
 360.156 +        if (newCapacity < 0)
 360.157 +            throw new IllegalStateException("Sorry, deque too big");
 360.158 +        Object[] a = new Object[newCapacity];
 360.159 +        System.arraycopy(elements, p, a, 0, r);
 360.160 +        System.arraycopy(elements, 0, a, r, p);
 360.161 +        elements = (E[])a;
 360.162 +        head = 0;
 360.163 +        tail = n;
 360.164 +    }
 360.165 +
 360.166 +    /**
 360.167 +     * Copies the elements from our element array into the specified array,
 360.168 +     * in order (from first to last element in the deque).  It is assumed
 360.169 +     * that the array is large enough to hold all elements in the deque.
 360.170 +     *
 360.171 +     * @return its argument
 360.172 +     */
 360.173 +    private <T> T[] copyElements(T[] a) {
 360.174 +        if (head < tail) {
 360.175 +            System.arraycopy(elements, head, a, 0, size());
 360.176 +        } else if (head > tail) {
 360.177 +            int headPortionLen = elements.length - head;
 360.178 +            System.arraycopy(elements, head, a, 0, headPortionLen);
 360.179 +            System.arraycopy(elements, 0, a, headPortionLen, tail);
 360.180 +        }
 360.181 +        return a;
 360.182 +    }
 360.183 +
 360.184 +    /**
 360.185 +     * Constructs an empty array deque with an initial capacity
 360.186 +     * sufficient to hold 16 elements.
 360.187 +     */
 360.188 +    public ArrayDeque() {
 360.189 +        elements = (E[]) new Object[16];
 360.190 +    }
 360.191 +
 360.192 +    /**
 360.193 +     * Constructs an empty array deque with an initial capacity
 360.194 +     * sufficient to hold the specified number of elements.
 360.195 +     *
 360.196 +     * @param numElements  lower bound on initial capacity of the deque
 360.197 +     */
 360.198 +    public ArrayDeque(int numElements) {
 360.199 +        allocateElements(numElements);
 360.200 +    }
 360.201 +
 360.202 +    /**
 360.203 +     * Constructs a deque containing the elements of the specified
 360.204 +     * collection, in the order they are returned by the collection's
 360.205 +     * iterator.  (The first element returned by the collection's
 360.206 +     * iterator becomes the first element, or <i>front</i> of the
 360.207 +     * deque.)
 360.208 +     *
 360.209 +     * @param c the collection whose elements are to be placed into the deque
 360.210 +     * @throws NullPointerException if the specified collection is null
 360.211 +     */
 360.212 +    public ArrayDeque(Collection<? extends E> c) {
 360.213 +        allocateElements(c.size());
 360.214 +        addAll(c);
 360.215 +    }
 360.216 +
 360.217 +    // The main insertion and extraction methods are addFirst,
 360.218 +    // addLast, pollFirst, pollLast. The other methods are defined in
 360.219 +    // terms of these.
 360.220 +
 360.221 +    /**
 360.222 +     * Inserts the specified element at the front of this deque.
 360.223 +     *
 360.224 +     * @param e the element to add
 360.225 +     * @throws NullPointerException if the specified element is null
 360.226 +     */
 360.227 +    public void addFirst(E e) {
 360.228 +        if (e == null)
 360.229 +            throw new NullPointerException();
 360.230 +        elements[head = (head - 1) & (elements.length - 1)] = e;
 360.231 +        if (head == tail)
 360.232 +            doubleCapacity();
 360.233 +    }
 360.234 +
 360.235 +    /**
 360.236 +     * Inserts the specified element at the end of this deque.
 360.237 +     *
 360.238 +     * <p>This method is equivalent to {@link #add}.
 360.239 +     *
 360.240 +     * @param e the element to add
 360.241 +     * @throws NullPointerException if the specified element is null
 360.242 +     */
 360.243 +    public void addLast(E e) {
 360.244 +        if (e == null)
 360.245 +            throw new NullPointerException();
 360.246 +        elements[tail] = e;
 360.247 +        if ( (tail = (tail + 1) & (elements.length - 1)) == head)
 360.248 +            doubleCapacity();
 360.249 +    }
 360.250 +
 360.251 +    /**
 360.252 +     * Inserts the specified element at the front of this deque.
 360.253 +     *
 360.254 +     * @param e the element to add
 360.255 +     * @return <tt>true</tt> (as specified by {@link Deque#offerFirst})
 360.256 +     * @throws NullPointerException if the specified element is null
 360.257 +     */
 360.258 +    public boolean offerFirst(E e) {
 360.259 +        addFirst(e);
 360.260 +        return true;
 360.261 +    }
 360.262 +
 360.263 +    /**
 360.264 +     * Inserts the specified element at the end of this deque.
 360.265 +     *
 360.266 +     * @param e the element to add
 360.267 +     * @return <tt>true</tt> (as specified by {@link Deque#offerLast})
 360.268 +     * @throws NullPointerException if the specified element is null
 360.269 +     */
 360.270 +    public boolean offerLast(E e) {
 360.271 +        addLast(e);
 360.272 +        return true;
 360.273 +    }
 360.274 +
 360.275 +    /**
 360.276 +     * @throws NoSuchElementException {@inheritDoc}
 360.277 +     */
 360.278 +    public E removeFirst() {
 360.279 +        E x = pollFirst();
 360.280 +        if (x == null)
 360.281 +            throw new NoSuchElementException();
 360.282 +        return x;
 360.283 +    }
 360.284 +
 360.285 +    /**
 360.286 +     * @throws NoSuchElementException {@inheritDoc}
 360.287 +     */
 360.288 +    public E removeLast() {
 360.289 +        E x = pollLast();
 360.290 +        if (x == null)
 360.291 +            throw new NoSuchElementException();
 360.292 +        return x;
 360.293 +    }
 360.294 +
 360.295 +    public E pollFirst() {
 360.296 +        int h = head;
 360.297 +        E result = elements[h]; // Element is null if deque empty
 360.298 +        if (result == null)
 360.299 +            return null;
 360.300 +        elements[h] = null;     // Must null out slot
 360.301 +        head = (h + 1) & (elements.length - 1);
 360.302 +        return result;
 360.303 +    }
 360.304 +
 360.305 +    public E pollLast() {
 360.306 +        int t = (tail - 1) & (elements.length - 1);
 360.307 +        E result = elements[t];
 360.308 +        if (result == null)
 360.309 +            return null;
 360.310 +        elements[t] = null;
 360.311 +        tail = t;
 360.312 +        return result;
 360.313 +    }
 360.314 +
 360.315 +    /**
 360.316 +     * @throws NoSuchElementException {@inheritDoc}
 360.317 +     */
 360.318 +    public E getFirst() {
 360.319 +        E x = elements[head];
 360.320 +        if (x == null)
 360.321 +            throw new NoSuchElementException();
 360.322 +        return x;
 360.323 +    }
 360.324 +
 360.325 +    /**
 360.326 +     * @throws NoSuchElementException {@inheritDoc}
 360.327 +     */
 360.328 +    public E getLast() {
 360.329 +        E x = elements[(tail - 1) & (elements.length - 1)];
 360.330 +        if (x == null)
 360.331 +            throw new NoSuchElementException();
 360.332 +        return x;
 360.333 +    }
 360.334 +
 360.335 +    public E peekFirst() {
 360.336 +        return elements[head]; // elements[head] is null if deque empty
 360.337 +    }
 360.338 +
 360.339 +    public E peekLast() {
 360.340 +        return elements[(tail - 1) & (elements.length - 1)];
 360.341 +    }
 360.342 +
 360.343 +    /**
 360.344 +     * Removes the first occurrence of the specified element in this
 360.345 +     * deque (when traversing the deque from head to tail).
 360.346 +     * If the deque does not contain the element, it is unchanged.
 360.347 +     * More formally, removes the first element <tt>e</tt> such that
 360.348 +     * <tt>o.equals(e)</tt> (if such an element exists).
 360.349 +     * Returns <tt>true</tt> if this deque contained the specified element
 360.350 +     * (or equivalently, if this deque changed as a result of the call).
 360.351 +     *
 360.352 +     * @param o element to be removed from this deque, if present
 360.353 +     * @return <tt>true</tt> if the deque contained the specified element
 360.354 +     */
 360.355 +    public boolean removeFirstOccurrence(Object o) {
 360.356 +        if (o == null)
 360.357 +            return false;
 360.358 +        int mask = elements.length - 1;
 360.359 +        int i = head;
 360.360 +        E x;
 360.361 +        while ( (x = elements[i]) != null) {
 360.362 +            if (o.equals(x)) {
 360.363 +                delete(i);
 360.364 +                return true;
 360.365 +            }
 360.366 +            i = (i + 1) & mask;
 360.367 +        }
 360.368 +        return false;
 360.369 +    }
 360.370 +
 360.371 +    /**
 360.372 +     * Removes the last occurrence of the specified element in this
 360.373 +     * deque (when traversing the deque from head to tail).
 360.374 +     * If the deque does not contain the element, it is unchanged.
 360.375 +     * More formally, removes the last element <tt>e</tt> such that
 360.376 +     * <tt>o.equals(e)</tt> (if such an element exists).
 360.377 +     * Returns <tt>true</tt> if this deque contained the specified element
 360.378 +     * (or equivalently, if this deque changed as a result of the call).
 360.379 +     *
 360.380 +     * @param o element to be removed from this deque, if present
 360.381 +     * @return <tt>true</tt> if the deque contained the specified element
 360.382 +     */
 360.383 +    public boolean removeLastOccurrence(Object o) {
 360.384 +        if (o == null)
 360.385 +            return false;
 360.386 +        int mask = elements.length - 1;
 360.387 +        int i = (tail - 1) & mask;
 360.388 +        E x;
 360.389 +        while ( (x = elements[i]) != null) {
 360.390 +            if (o.equals(x)) {
 360.391 +                delete(i);
 360.392 +                return true;
 360.393 +            }
 360.394 +            i = (i - 1) & mask;
 360.395 +        }
 360.396 +        return false;
 360.397 +    }
 360.398 +
 360.399 +    // *** Queue methods ***
 360.400 +
 360.401 +    /**
 360.402 +     * Inserts the specified element at the end of this deque.
 360.403 +     *
 360.404 +     * <p>This method is equivalent to {@link #addLast}.
 360.405 +     *
 360.406 +     * @param e the element to add
 360.407 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
 360.408 +     * @throws NullPointerException if the specified element is null
 360.409 +     */
 360.410 +    public boolean add(E e) {
 360.411 +        addLast(e);
 360.412 +        return true;
 360.413 +    }
 360.414 +
 360.415 +    /**
 360.416 +     * Inserts the specified element at the end of this deque.
 360.417 +     *
 360.418 +     * <p>This method is equivalent to {@link #offerLast}.
 360.419 +     *
 360.420 +     * @param e the element to add
 360.421 +     * @return <tt>true</tt> (as specified by {@link Queue#offer})
 360.422 +     * @throws NullPointerException if the specified element is null
 360.423 +     */
 360.424 +    public boolean offer(E e) {
 360.425 +        return offerLast(e);
 360.426 +    }
 360.427 +
 360.428 +    /**
 360.429 +     * Retrieves and removes the head of the queue represented by this deque.
 360.430 +     *
 360.431 +     * This method differs from {@link #poll poll} only in that it throws an
 360.432 +     * exception if this deque is empty.
 360.433 +     *
 360.434 +     * <p>This method is equivalent to {@link #removeFirst}.
 360.435 +     *
 360.436 +     * @return the head of the queue represented by this deque
 360.437 +     * @throws NoSuchElementException {@inheritDoc}
 360.438 +     */
 360.439 +    public E remove() {
 360.440 +        return removeFirst();
 360.441 +    }
 360.442 +
 360.443 +    /**
 360.444 +     * Retrieves and removes the head of the queue represented by this deque
 360.445 +     * (in other words, the first element of this deque), or returns
 360.446 +     * <tt>null</tt> if this deque is empty.
 360.447 +     *
 360.448 +     * <p>This method is equivalent to {@link #pollFirst}.
 360.449 +     *
 360.450 +     * @return the head of the queue represented by this deque, or
 360.451 +     *         <tt>null</tt> if this deque is empty
 360.452 +     */
 360.453 +    public E poll() {
 360.454 +        return pollFirst();
 360.455 +    }
 360.456 +
 360.457 +    /**
 360.458 +     * Retrieves, but does not remove, the head of the queue represented by
 360.459 +     * this deque.  This method differs from {@link #peek peek} only in
 360.460 +     * that it throws an exception if this deque is empty.
 360.461 +     *
 360.462 +     * <p>This method is equivalent to {@link #getFirst}.
 360.463 +     *
 360.464 +     * @return the head of the queue represented by this deque
 360.465 +     * @throws NoSuchElementException {@inheritDoc}
 360.466 +     */
 360.467 +    public E element() {
 360.468 +        return getFirst();
 360.469 +    }
 360.470 +
 360.471 +    /**
 360.472 +     * Retrieves, but does not remove, the head of the queue represented by
 360.473 +     * this deque, or returns <tt>null</tt> if this deque is empty.
 360.474 +     *
 360.475 +     * <p>This method is equivalent to {@link #peekFirst}.
 360.476 +     *
 360.477 +     * @return the head of the queue represented by this deque, or
 360.478 +     *         <tt>null</tt> if this deque is empty
 360.479 +     */
 360.480 +    public E peek() {
 360.481 +        return peekFirst();
 360.482 +    }
 360.483 +
 360.484 +    // *** Stack methods ***
 360.485 +
 360.486 +    /**
 360.487 +     * Pushes an element onto the stack represented by this deque.  In other
 360.488 +     * words, inserts the element at the front of this deque.
 360.489 +     *
 360.490 +     * <p>This method is equivalent to {@link #addFirst}.
 360.491 +     *
 360.492 +     * @param e the element to push
 360.493 +     * @throws NullPointerException if the specified element is null
 360.494 +     */
 360.495 +    public void push(E e) {
 360.496 +        addFirst(e);
 360.497 +    }
 360.498 +
 360.499 +    /**
 360.500 +     * Pops an element from the stack represented by this deque.  In other
 360.501 +     * words, removes and returns the first element of this deque.
 360.502 +     *
 360.503 +     * <p>This method is equivalent to {@link #removeFirst()}.
 360.504 +     *
 360.505 +     * @return the element at the front of this deque (which is the top
 360.506 +     *         of the stack represented by this deque)
 360.507 +     * @throws NoSuchElementException {@inheritDoc}
 360.508 +     */
 360.509 +    public E pop() {
 360.510 +        return removeFirst();
 360.511 +    }
 360.512 +
 360.513 +    private void checkInvariants() {
 360.514 +        assert elements[tail] == null;
 360.515 +        assert head == tail ? elements[head] == null :
 360.516 +            (elements[head] != null &&
 360.517 +             elements[(tail - 1) & (elements.length - 1)] != null);
 360.518 +        assert elements[(head - 1) & (elements.length - 1)] == null;
 360.519 +    }
 360.520 +
 360.521 +    /**
 360.522 +     * Removes the element at the specified position in the elements array,
 360.523 +     * adjusting head and tail as necessary.  This can result in motion of
 360.524 +     * elements backwards or forwards in the array.
 360.525 +     *
 360.526 +     * <p>This method is called delete rather than remove to emphasize
 360.527 +     * that its semantics differ from those of {@link List#remove(int)}.
 360.528 +     *
 360.529 +     * @return true if elements moved backwards
 360.530 +     */
 360.531 +    private boolean delete(int i) {
 360.532 +        checkInvariants();
 360.533 +        final E[] elements = this.elements;
 360.534 +        final int mask = elements.length - 1;
 360.535 +        final int h = head;
 360.536 +        final int t = tail;
 360.537 +        final int front = (i - h) & mask;
 360.538 +        final int back  = (t - i) & mask;
 360.539 +
 360.540 +        // Invariant: head <= i < tail mod circularity
 360.541 +        if (front >= ((t - h) & mask))
 360.542 +            throw new ConcurrentModificationException();
 360.543 +
 360.544 +        // Optimize for least element motion
 360.545 +        if (front < back) {
 360.546 +            if (h <= i) {
 360.547 +                System.arraycopy(elements, h, elements, h + 1, front);
 360.548 +            } else { // Wrap around
 360.549 +                System.arraycopy(elements, 0, elements, 1, i);
 360.550 +                elements[0] = elements[mask];
 360.551 +                System.arraycopy(elements, h, elements, h + 1, mask - h);
 360.552 +            }
 360.553 +            elements[h] = null;
 360.554 +            head = (h + 1) & mask;
 360.555 +            return false;
 360.556 +        } else {
 360.557 +            if (i < t) { // Copy the null tail as well
 360.558 +                System.arraycopy(elements, i + 1, elements, i, back);
 360.559 +                tail = t - 1;
 360.560 +            } else { // Wrap around
 360.561 +                System.arraycopy(elements, i + 1, elements, i, mask - i);
 360.562 +                elements[mask] = elements[0];
 360.563 +                System.arraycopy(elements, 1, elements, 0, t);
 360.564 +                tail = (t - 1) & mask;
 360.565 +            }
 360.566 +            return true;
 360.567 +        }
 360.568 +    }
 360.569 +
 360.570 +    // *** Collection Methods ***
 360.571 +
 360.572 +    /**
 360.573 +     * Returns the number of elements in this deque.
 360.574 +     *
 360.575 +     * @return the number of elements in this deque
 360.576 +     */
 360.577 +    public int size() {
 360.578 +        return (tail - head) & (elements.length - 1);
 360.579 +    }
 360.580 +
 360.581 +    /**
 360.582 +     * Returns <tt>true</tt> if this deque contains no elements.
 360.583 +     *
 360.584 +     * @return <tt>true</tt> if this deque contains no elements
 360.585 +     */
 360.586 +    public boolean isEmpty() {
 360.587 +        return head == tail;
 360.588 +    }
 360.589 +
 360.590 +    /**
 360.591 +     * Returns an iterator over the elements in this deque.  The elements
 360.592 +     * will be ordered from first (head) to last (tail).  This is the same
 360.593 +     * order that elements would be dequeued (via successive calls to
 360.594 +     * {@link #remove} or popped (via successive calls to {@link #pop}).
 360.595 +     *
 360.596 +     * @return an iterator over the elements in this deque
 360.597 +     */
 360.598 +    public Iterator<E> iterator() {
 360.599 +        return new DeqIterator();
 360.600 +    }
 360.601 +
 360.602 +    public Iterator<E> descendingIterator() {
 360.603 +        return new DescendingIterator();
 360.604 +    }
 360.605 +
 360.606 +    private class DeqIterator implements Iterator<E> {
 360.607 +        /**
 360.608 +         * Index of element to be returned by subsequent call to next.
 360.609 +         */
 360.610 +        private int cursor = head;
 360.611 +
 360.612 +        /**
 360.613 +         * Tail recorded at construction (also in remove), to stop
 360.614 +         * iterator and also to check for comodification.
 360.615 +         */
 360.616 +        private int fence = tail;
 360.617 +
 360.618 +        /**
 360.619 +         * Index of element returned by most recent call to next.
 360.620 +         * Reset to -1 if element is deleted by a call to remove.
 360.621 +         */
 360.622 +        private int lastRet = -1;
 360.623 +
 360.624 +        public boolean hasNext() {
 360.625 +            return cursor != fence;
 360.626 +        }
 360.627 +
 360.628 +        public E next() {
 360.629 +            if (cursor == fence)
 360.630 +                throw new NoSuchElementException();
 360.631 +            E result = elements[cursor];
 360.632 +            // This check doesn't catch all possible comodifications,
 360.633 +            // but does catch the ones that corrupt traversal
 360.634 +            if (tail != fence || result == null)
 360.635 +                throw new ConcurrentModificationException();
 360.636 +            lastRet = cursor;
 360.637 +            cursor = (cursor + 1) & (elements.length - 1);
 360.638 +            return result;
 360.639 +        }
 360.640 +
 360.641 +        public void remove() {
 360.642 +            if (lastRet < 0)
 360.643 +                throw new IllegalStateException();
 360.644 +            if (delete(lastRet)) { // if left-shifted, undo increment in next()
 360.645 +                cursor = (cursor - 1) & (elements.length - 1);
 360.646 +                fence = tail;
 360.647 +            }
 360.648 +            lastRet = -1;
 360.649 +        }
 360.650 +    }
 360.651 +
 360.652 +    private class DescendingIterator implements Iterator<E> {
 360.653 +        /*
 360.654 +         * This class is nearly a mirror-image of DeqIterator, using
 360.655 +         * tail instead of head for initial cursor, and head instead of
 360.656 +         * tail for fence.
 360.657 +         */
 360.658 +        private int cursor = tail;
 360.659 +        private int fence = head;
 360.660 +        private int lastRet = -1;
 360.661 +
 360.662 +        public boolean hasNext() {
 360.663 +            return cursor != fence;
 360.664 +        }
 360.665 +
 360.666 +        public E next() {
 360.667 +            if (cursor == fence)
 360.668 +                throw new NoSuchElementException();
 360.669 +            cursor = (cursor - 1) & (elements.length - 1);
 360.670 +            E result = elements[cursor];
 360.671 +            if (head != fence || result == null)
 360.672 +                throw new ConcurrentModificationException();
 360.673 +            lastRet = cursor;
 360.674 +            return result;
 360.675 +        }
 360.676 +
 360.677 +        public void remove() {
 360.678 +            if (lastRet < 0)
 360.679 +                throw new IllegalStateException();
 360.680 +            if (!delete(lastRet)) {
 360.681 +                cursor = (cursor + 1) & (elements.length - 1);
 360.682 +                fence = head;
 360.683 +            }
 360.684 +            lastRet = -1;
 360.685 +        }
 360.686 +    }
 360.687 +
 360.688 +    /**
 360.689 +     * Returns <tt>true</tt> if this deque contains the specified element.
 360.690 +     * More formally, returns <tt>true</tt> if and only if this deque contains
 360.691 +     * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
 360.692 +     *
 360.693 +     * @param o object to be checked for containment in this deque
 360.694 +     * @return <tt>true</tt> if this deque contains the specified element
 360.695 +     */
 360.696 +    public boolean contains(Object o) {
 360.697 +        if (o == null)
 360.698 +            return false;
 360.699 +        int mask = elements.length - 1;
 360.700 +        int i = head;
 360.701 +        E x;
 360.702 +        while ( (x = elements[i]) != null) {
 360.703 +            if (o.equals(x))
 360.704 +                return true;
 360.705 +            i = (i + 1) & mask;
 360.706 +        }
 360.707 +        return false;
 360.708 +    }
 360.709 +
 360.710 +    /**
 360.711 +     * Removes a single instance of the specified element from this deque.
 360.712 +     * If the deque does not contain the element, it is unchanged.
 360.713 +     * More formally, removes the first element <tt>e</tt> such that
 360.714 +     * <tt>o.equals(e)</tt> (if such an element exists).
 360.715 +     * Returns <tt>true</tt> if this deque contained the specified element
 360.716 +     * (or equivalently, if this deque changed as a result of the call).
 360.717 +     *
 360.718 +     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
 360.719 +     *
 360.720 +     * @param o element to be removed from this deque, if present
 360.721 +     * @return <tt>true</tt> if this deque contained the specified element
 360.722 +     */
 360.723 +    public boolean remove(Object o) {
 360.724 +        return removeFirstOccurrence(o);
 360.725 +    }
 360.726 +
 360.727 +    /**
 360.728 +     * Removes all of the elements from this deque.
 360.729 +     * The deque will be empty after this call returns.
 360.730 +     */
 360.731 +    public void clear() {
 360.732 +        int h = head;
 360.733 +        int t = tail;
 360.734 +        if (h != t) { // clear all cells
 360.735 +            head = tail = 0;
 360.736 +            int i = h;
 360.737 +            int mask = elements.length - 1;
 360.738 +            do {
 360.739 +                elements[i] = null;
 360.740 +                i = (i + 1) & mask;
 360.741 +            } while (i != t);
 360.742 +        }
 360.743 +    }
 360.744 +
 360.745 +    /**
 360.746 +     * Returns an array containing all of the elements in this deque
 360.747 +     * in proper sequence (from first to last element).
 360.748 +     *
 360.749 +     * <p>The returned array will be "safe" in that no references to it are
 360.750 +     * maintained by this deque.  (In other words, this method must allocate
 360.751 +     * a new array).  The caller is thus free to modify the returned array.
 360.752 +     *
 360.753 +     * <p>This method acts as bridge between array-based and collection-based
 360.754 +     * APIs.
 360.755 +     *
 360.756 +     * @return an array containing all of the elements in this deque
 360.757 +     */
 360.758 +    public Object[] toArray() {
 360.759 +        return copyElements(new Object[size()]);
 360.760 +    }
 360.761 +
 360.762 +    /**
 360.763 +     * Returns an array containing all of the elements in this deque in
 360.764 +     * proper sequence (from first to last element); the runtime type of the
 360.765 +     * returned array is that of the specified array.  If the deque fits in
 360.766 +     * the specified array, it is returned therein.  Otherwise, a new array
 360.767 +     * is allocated with the runtime type of the specified array and the
 360.768 +     * size of this deque.
 360.769 +     *
 360.770 +     * <p>If this deque fits in the specified array with room to spare
 360.771 +     * (i.e., the array has more elements than this deque), the element in
 360.772 +     * the array immediately following the end of the deque is set to
 360.773 +     * <tt>null</tt>.
 360.774 +     *
 360.775 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 360.776 +     * array-based and collection-based APIs.  Further, this method allows
 360.777 +     * precise control over the runtime type of the output array, and may,
 360.778 +     * under certain circumstances, be used to save allocation costs.
 360.779 +     *
 360.780 +     * <p>Suppose <tt>x</tt> is a deque known to contain only strings.
 360.781 +     * The following code can be used to dump the deque into a newly
 360.782 +     * allocated array of <tt>String</tt>:
 360.783 +     *
 360.784 +     * <pre>
 360.785 +     *     String[] y = x.toArray(new String[0]);</pre>
 360.786 +     *
 360.787 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
 360.788 +     * <tt>toArray()</tt>.
 360.789 +     *
 360.790 +     * @param a the array into which the elements of the deque are to
 360.791 +     *          be stored, if it is big enough; otherwise, a new array of the
 360.792 +     *          same runtime type is allocated for this purpose
 360.793 +     * @return an array containing all of the elements in this deque
 360.794 +     * @throws ArrayStoreException if the runtime type of the specified array
 360.795 +     *         is not a supertype of the runtime type of every element in
 360.796 +     *         this deque
 360.797 +     * @throws NullPointerException if the specified array is null
 360.798 +     */
 360.799 +    public <T> T[] toArray(T[] a) {
 360.800 +        int size = size();
 360.801 +        if (a.length < size)
 360.802 +            a = (T[])java.lang.reflect.Array.newInstance(
 360.803 +                    a.getClass().getComponentType(), size);
 360.804 +        copyElements(a);
 360.805 +        if (a.length > size)
 360.806 +            a[size] = null;
 360.807 +        return a;
 360.808 +    }
 360.809 +
 360.810 +    // *** Object methods ***
 360.811 +
 360.812 +    /**
 360.813 +     * Returns a copy of this deque.
 360.814 +     *
 360.815 +     * @return a copy of this deque
 360.816 +     */
 360.817 +    public ArrayDeque<E> clone() {
 360.818 +        try {
 360.819 +            ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
 360.820 +            result.elements = Arrays.copyOf(elements, elements.length);
 360.821 +            return result;
 360.822 +
 360.823 +        } catch (CloneNotSupportedException e) {
 360.824 +            throw new AssertionError();
 360.825 +        }
 360.826 +    }
 360.827 +
 360.828 +    /**
 360.829 +     * Appease the serialization gods.
 360.830 +     */
 360.831 +    private static final long serialVersionUID = 2340985798034038923L;
 360.832 +
 360.833 +}
   361.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   361.2 +++ b/rt/emul/compact/src/main/java/java/util/ArrayList.java	Wed Feb 27 11:24:58 2013 +0100
   361.3 @@ -0,0 +1,1088 @@
   361.4 +/*
   361.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   361.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   361.7 + *
   361.8 + * This code is free software; you can redistribute it and/or modify it
   361.9 + * under the terms of the GNU General Public License version 2 only, as
  361.10 + * published by the Free Software Foundation.  Oracle designates this
  361.11 + * particular file as subject to the "Classpath" exception as provided
  361.12 + * by Oracle in the LICENSE file that accompanied this code.
  361.13 + *
  361.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  361.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  361.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  361.17 + * version 2 for more details (a copy is included in the LICENSE file that
  361.18 + * accompanied this code).
  361.19 + *
  361.20 + * You should have received a copy of the GNU General Public License version
  361.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  361.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  361.23 + *
  361.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  361.25 + * or visit www.oracle.com if you need additional information or have any
  361.26 + * questions.
  361.27 + */
  361.28 +
  361.29 +package java.util;
  361.30 +
  361.31 +
  361.32 +/**
  361.33 + * Resizable-array implementation of the <tt>List</tt> interface.  Implements
  361.34 + * all optional list operations, and permits all elements, including
  361.35 + * <tt>null</tt>.  In addition to implementing the <tt>List</tt> interface,
  361.36 + * this class provides methods to manipulate the size of the array that is
  361.37 + * used internally to store the list.  (This class is roughly equivalent to
  361.38 + * <tt>Vector</tt>, except that it is unsynchronized.)
  361.39 + *
  361.40 + * <p>The <tt>size</tt>, <tt>isEmpty</tt>, <tt>get</tt>, <tt>set</tt>,
  361.41 + * <tt>iterator</tt>, and <tt>listIterator</tt> operations run in constant
  361.42 + * time.  The <tt>add</tt> operation runs in <i>amortized constant time</i>,
  361.43 + * that is, adding n elements requires O(n) time.  All of the other operations
  361.44 + * run in linear time (roughly speaking).  The constant factor is low compared
  361.45 + * to that for the <tt>LinkedList</tt> implementation.
  361.46 + *
  361.47 + * <p>Each <tt>ArrayList</tt> instance has a <i>capacity</i>.  The capacity is
  361.48 + * the size of the array used to store the elements in the list.  It is always
  361.49 + * at least as large as the list size.  As elements are added to an ArrayList,
  361.50 + * its capacity grows automatically.  The details of the growth policy are not
  361.51 + * specified beyond the fact that adding an element has constant amortized
  361.52 + * time cost.
  361.53 + *
  361.54 + * <p>An application can increase the capacity of an <tt>ArrayList</tt> instance
  361.55 + * before adding a large number of elements using the <tt>ensureCapacity</tt>
  361.56 + * operation.  This may reduce the amount of incremental reallocation.
  361.57 + *
  361.58 + * <p><strong>Note that this implementation is not synchronized.</strong>
  361.59 + * If multiple threads access an <tt>ArrayList</tt> instance concurrently,
  361.60 + * and at least one of the threads modifies the list structurally, it
  361.61 + * <i>must</i> be synchronized externally.  (A structural modification is
  361.62 + * any operation that adds or deletes one or more elements, or explicitly
  361.63 + * resizes the backing array; merely setting the value of an element is not
  361.64 + * a structural modification.)  This is typically accomplished by
  361.65 + * synchronizing on some object that naturally encapsulates the list.
  361.66 + *
  361.67 + * If no such object exists, the list should be "wrapped" using the
  361.68 + * {@link Collections#synchronizedList Collections.synchronizedList}
  361.69 + * method.  This is best done at creation time, to prevent accidental
  361.70 + * unsynchronized access to the list:<pre>
  361.71 + *   List list = Collections.synchronizedList(new ArrayList(...));</pre>
  361.72 + *
  361.73 + * <p><a name="fail-fast"/>
  361.74 + * The iterators returned by this class's {@link #iterator() iterator} and
  361.75 + * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
  361.76 + * if the list is structurally modified at any time after the iterator is
  361.77 + * created, in any way except through the iterator's own
  361.78 + * {@link ListIterator#remove() remove} or
  361.79 + * {@link ListIterator#add(Object) add} methods, the iterator will throw a
  361.80 + * {@link ConcurrentModificationException}.  Thus, in the face of
  361.81 + * concurrent modification, the iterator fails quickly and cleanly, rather
  361.82 + * than risking arbitrary, non-deterministic behavior at an undetermined
  361.83 + * time in the future.
  361.84 + *
  361.85 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  361.86 + * as it is, generally speaking, impossible to make any hard guarantees in the
  361.87 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  361.88 + * throw {@code ConcurrentModificationException} on a best-effort basis.
  361.89 + * Therefore, it would be wrong to write a program that depended on this
  361.90 + * exception for its correctness:  <i>the fail-fast behavior of iterators
  361.91 + * should be used only to detect bugs.</i>
  361.92 + *
  361.93 + * <p>This class is a member of the
  361.94 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  361.95 + * Java Collections Framework</a>.
  361.96 + *
  361.97 + * @author  Josh Bloch
  361.98 + * @author  Neal Gafter
  361.99 + * @see     Collection
 361.100 + * @see     List
 361.101 + * @see     LinkedList
 361.102 + * @see     Vector
 361.103 + * @since   1.2
 361.104 + */
 361.105 +
 361.106 +public class ArrayList<E> extends AbstractList<E>
 361.107 +        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
 361.108 +{
 361.109 +    private static final long serialVersionUID = 8683452581122892189L;
 361.110 +
 361.111 +    /**
 361.112 +     * The array buffer into which the elements of the ArrayList are stored.
 361.113 +     * The capacity of the ArrayList is the length of this array buffer.
 361.114 +     */
 361.115 +    private transient Object[] elementData;
 361.116 +
 361.117 +    /**
 361.118 +     * The size of the ArrayList (the number of elements it contains).
 361.119 +     *
 361.120 +     * @serial
 361.121 +     */
 361.122 +    private int size;
 361.123 +
 361.124 +    /**
 361.125 +     * Constructs an empty list with the specified initial capacity.
 361.126 +     *
 361.127 +     * @param  initialCapacity  the initial capacity of the list
 361.128 +     * @throws IllegalArgumentException if the specified initial capacity
 361.129 +     *         is negative
 361.130 +     */
 361.131 +    public ArrayList(int initialCapacity) {
 361.132 +        super();
 361.133 +        if (initialCapacity < 0)
 361.134 +            throw new IllegalArgumentException("Illegal Capacity: "+
 361.135 +                                               initialCapacity);
 361.136 +        this.elementData = new Object[initialCapacity];
 361.137 +    }
 361.138 +
 361.139 +    /**
 361.140 +     * Constructs an empty list with an initial capacity of ten.
 361.141 +     */
 361.142 +    public ArrayList() {
 361.143 +        this(10);
 361.144 +    }
 361.145 +
 361.146 +    /**
 361.147 +     * Constructs a list containing the elements of the specified
 361.148 +     * collection, in the order they are returned by the collection's
 361.149 +     * iterator.
 361.150 +     *
 361.151 +     * @param c the collection whose elements are to be placed into this list
 361.152 +     * @throws NullPointerException if the specified collection is null
 361.153 +     */
 361.154 +    public ArrayList(Collection<? extends E> c) {
 361.155 +        elementData = c.toArray();
 361.156 +        size = elementData.length;
 361.157 +        // c.toArray might (incorrectly) not return Object[] (see 6260652)
 361.158 +        if (elementData.getClass() != Object[].class)
 361.159 +            elementData = Arrays.copyOf(elementData, size, Object[].class);
 361.160 +    }
 361.161 +
 361.162 +    /**
 361.163 +     * Trims the capacity of this <tt>ArrayList</tt> instance to be the
 361.164 +     * list's current size.  An application can use this operation to minimize
 361.165 +     * the storage of an <tt>ArrayList</tt> instance.
 361.166 +     */
 361.167 +    public void trimToSize() {
 361.168 +        modCount++;
 361.169 +        int oldCapacity = elementData.length;
 361.170 +        if (size < oldCapacity) {
 361.171 +            elementData = Arrays.copyOf(elementData, size);
 361.172 +        }
 361.173 +    }
 361.174 +
 361.175 +    /**
 361.176 +     * Increases the capacity of this <tt>ArrayList</tt> instance, if
 361.177 +     * necessary, to ensure that it can hold at least the number of elements
 361.178 +     * specified by the minimum capacity argument.
 361.179 +     *
 361.180 +     * @param   minCapacity   the desired minimum capacity
 361.181 +     */
 361.182 +    public void ensureCapacity(int minCapacity) {
 361.183 +        if (minCapacity > 0)
 361.184 +            ensureCapacityInternal(minCapacity);
 361.185 +    }
 361.186 +
 361.187 +    private void ensureCapacityInternal(int minCapacity) {
 361.188 +        modCount++;
 361.189 +        // overflow-conscious code
 361.190 +        if (minCapacity - elementData.length > 0)
 361.191 +            grow(minCapacity);
 361.192 +    }
 361.193 +
 361.194 +    /**
 361.195 +     * The maximum size of array to allocate.
 361.196 +     * Some VMs reserve some header words in an array.
 361.197 +     * Attempts to allocate larger arrays may result in
 361.198 +     * OutOfMemoryError: Requested array size exceeds VM limit
 361.199 +     */
 361.200 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 361.201 +
 361.202 +    /**
 361.203 +     * Increases the capacity to ensure that it can hold at least the
 361.204 +     * number of elements specified by the minimum capacity argument.
 361.205 +     *
 361.206 +     * @param minCapacity the desired minimum capacity
 361.207 +     */
 361.208 +    private void grow(int minCapacity) {
 361.209 +        // overflow-conscious code
 361.210 +        int oldCapacity = elementData.length;
 361.211 +        int newCapacity = oldCapacity + (oldCapacity >> 1);
 361.212 +        if (newCapacity - minCapacity < 0)
 361.213 +            newCapacity = minCapacity;
 361.214 +        if (newCapacity - MAX_ARRAY_SIZE > 0)
 361.215 +            newCapacity = hugeCapacity(minCapacity);
 361.216 +        // minCapacity is usually close to size, so this is a win:
 361.217 +        elementData = Arrays.copyOf(elementData, newCapacity);
 361.218 +    }
 361.219 +
 361.220 +    private static int hugeCapacity(int minCapacity) {
 361.221 +        if (minCapacity < 0) // overflow
 361.222 +            throw new OutOfMemoryError();
 361.223 +        return (minCapacity > MAX_ARRAY_SIZE) ?
 361.224 +            Integer.MAX_VALUE :
 361.225 +            MAX_ARRAY_SIZE;
 361.226 +    }
 361.227 +
 361.228 +    /**
 361.229 +     * Returns the number of elements in this list.
 361.230 +     *
 361.231 +     * @return the number of elements in this list
 361.232 +     */
 361.233 +    public int size() {
 361.234 +        return size;
 361.235 +    }
 361.236 +
 361.237 +    /**
 361.238 +     * Returns <tt>true</tt> if this list contains no elements.
 361.239 +     *
 361.240 +     * @return <tt>true</tt> if this list contains no elements
 361.241 +     */
 361.242 +    public boolean isEmpty() {
 361.243 +        return size == 0;
 361.244 +    }
 361.245 +
 361.246 +    /**
 361.247 +     * Returns <tt>true</tt> if this list contains the specified element.
 361.248 +     * More formally, returns <tt>true</tt> if and only if this list contains
 361.249 +     * at least one element <tt>e</tt> such that
 361.250 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 361.251 +     *
 361.252 +     * @param o element whose presence in this list is to be tested
 361.253 +     * @return <tt>true</tt> if this list contains the specified element
 361.254 +     */
 361.255 +    public boolean contains(Object o) {
 361.256 +        return indexOf(o) >= 0;
 361.257 +    }
 361.258 +
 361.259 +    /**
 361.260 +     * Returns the index of the first occurrence of the specified element
 361.261 +     * in this list, or -1 if this list does not contain the element.
 361.262 +     * More formally, returns the lowest index <tt>i</tt> such that
 361.263 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 361.264 +     * or -1 if there is no such index.
 361.265 +     */
 361.266 +    public int indexOf(Object o) {
 361.267 +        if (o == null) {
 361.268 +            for (int i = 0; i < size; i++)
 361.269 +                if (elementData[i]==null)
 361.270 +                    return i;
 361.271 +        } else {
 361.272 +            for (int i = 0; i < size; i++)
 361.273 +                if (o.equals(elementData[i]))
 361.274 +                    return i;
 361.275 +        }
 361.276 +        return -1;
 361.277 +    }
 361.278 +
 361.279 +    /**
 361.280 +     * Returns the index of the last occurrence of the specified element
 361.281 +     * in this list, or -1 if this list does not contain the element.
 361.282 +     * More formally, returns the highest index <tt>i</tt> such that
 361.283 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 361.284 +     * or -1 if there is no such index.
 361.285 +     */
 361.286 +    public int lastIndexOf(Object o) {
 361.287 +        if (o == null) {
 361.288 +            for (int i = size-1; i >= 0; i--)
 361.289 +                if (elementData[i]==null)
 361.290 +                    return i;
 361.291 +        } else {
 361.292 +            for (int i = size-1; i >= 0; i--)
 361.293 +                if (o.equals(elementData[i]))
 361.294 +                    return i;
 361.295 +        }
 361.296 +        return -1;
 361.297 +    }
 361.298 +
 361.299 +    /**
 361.300 +     * Returns a shallow copy of this <tt>ArrayList</tt> instance.  (The
 361.301 +     * elements themselves are not copied.)
 361.302 +     *
 361.303 +     * @return a clone of this <tt>ArrayList</tt> instance
 361.304 +     */
 361.305 +    public Object clone() {
 361.306 +        try {
 361.307 +            @SuppressWarnings("unchecked")
 361.308 +                ArrayList<E> v = (ArrayList<E>) super.clone();
 361.309 +            v.elementData = Arrays.copyOf(elementData, size);
 361.310 +            v.modCount = 0;
 361.311 +            return v;
 361.312 +        } catch (CloneNotSupportedException e) {
 361.313 +            // this shouldn't happen, since we are Cloneable
 361.314 +            throw new InternalError();
 361.315 +        }
 361.316 +    }
 361.317 +
 361.318 +    /**
 361.319 +     * Returns an array containing all of the elements in this list
 361.320 +     * in proper sequence (from first to last element).
 361.321 +     *
 361.322 +     * <p>The returned array will be "safe" in that no references to it are
 361.323 +     * maintained by this list.  (In other words, this method must allocate
 361.324 +     * a new array).  The caller is thus free to modify the returned array.
 361.325 +     *
 361.326 +     * <p>This method acts as bridge between array-based and collection-based
 361.327 +     * APIs.
 361.328 +     *
 361.329 +     * @return an array containing all of the elements in this list in
 361.330 +     *         proper sequence
 361.331 +     */
 361.332 +    public Object[] toArray() {
 361.333 +        return Arrays.copyOf(elementData, size);
 361.334 +    }
 361.335 +
 361.336 +    /**
 361.337 +     * Returns an array containing all of the elements in this list in proper
 361.338 +     * sequence (from first to last element); the runtime type of the returned
 361.339 +     * array is that of the specified array.  If the list fits in the
 361.340 +     * specified array, it is returned therein.  Otherwise, a new array is
 361.341 +     * allocated with the runtime type of the specified array and the size of
 361.342 +     * this list.
 361.343 +     *
 361.344 +     * <p>If the list fits in the specified array with room to spare
 361.345 +     * (i.e., the array has more elements than the list), the element in
 361.346 +     * the array immediately following the end of the collection is set to
 361.347 +     * <tt>null</tt>.  (This is useful in determining the length of the
 361.348 +     * list <i>only</i> if the caller knows that the list does not contain
 361.349 +     * any null elements.)
 361.350 +     *
 361.351 +     * @param a the array into which the elements of the list are to
 361.352 +     *          be stored, if it is big enough; otherwise, a new array of the
 361.353 +     *          same runtime type is allocated for this purpose.
 361.354 +     * @return an array containing the elements of the list
 361.355 +     * @throws ArrayStoreException if the runtime type of the specified array
 361.356 +     *         is not a supertype of the runtime type of every element in
 361.357 +     *         this list
 361.358 +     * @throws NullPointerException if the specified array is null
 361.359 +     */
 361.360 +    @SuppressWarnings("unchecked")
 361.361 +    public <T> T[] toArray(T[] a) {
 361.362 +        if (a.length < size)
 361.363 +            // Make a new array of a's runtime type, but my contents:
 361.364 +            return (T[]) Arrays.copyOf(elementData, size, a.getClass());
 361.365 +        System.arraycopy(elementData, 0, a, 0, size);
 361.366 +        if (a.length > size)
 361.367 +            a[size] = null;
 361.368 +        return a;
 361.369 +    }
 361.370 +
 361.371 +    // Positional Access Operations
 361.372 +
 361.373 +    @SuppressWarnings("unchecked")
 361.374 +    E elementData(int index) {
 361.375 +        return (E) elementData[index];
 361.376 +    }
 361.377 +
 361.378 +    /**
 361.379 +     * Returns the element at the specified position in this list.
 361.380 +     *
 361.381 +     * @param  index index of the element to return
 361.382 +     * @return the element at the specified position in this list
 361.383 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.384 +     */
 361.385 +    public E get(int index) {
 361.386 +        rangeCheck(index);
 361.387 +
 361.388 +        return elementData(index);
 361.389 +    }
 361.390 +
 361.391 +    /**
 361.392 +     * Replaces the element at the specified position in this list with
 361.393 +     * the specified element.
 361.394 +     *
 361.395 +     * @param index index of the element to replace
 361.396 +     * @param element element to be stored at the specified position
 361.397 +     * @return the element previously at the specified position
 361.398 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.399 +     */
 361.400 +    public E set(int index, E element) {
 361.401 +        rangeCheck(index);
 361.402 +
 361.403 +        E oldValue = elementData(index);
 361.404 +        elementData[index] = element;
 361.405 +        return oldValue;
 361.406 +    }
 361.407 +
 361.408 +    /**
 361.409 +     * Appends the specified element to the end of this list.
 361.410 +     *
 361.411 +     * @param e element to be appended to this list
 361.412 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
 361.413 +     */
 361.414 +    public boolean add(E e) {
 361.415 +        ensureCapacityInternal(size + 1);  // Increments modCount!!
 361.416 +        elementData[size++] = e;
 361.417 +        return true;
 361.418 +    }
 361.419 +
 361.420 +    /**
 361.421 +     * Inserts the specified element at the specified position in this
 361.422 +     * list. Shifts the element currently at that position (if any) and
 361.423 +     * any subsequent elements to the right (adds one to their indices).
 361.424 +     *
 361.425 +     * @param index index at which the specified element is to be inserted
 361.426 +     * @param element element to be inserted
 361.427 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.428 +     */
 361.429 +    public void add(int index, E element) {
 361.430 +        rangeCheckForAdd(index);
 361.431 +
 361.432 +        ensureCapacityInternal(size + 1);  // Increments modCount!!
 361.433 +        System.arraycopy(elementData, index, elementData, index + 1,
 361.434 +                         size - index);
 361.435 +        elementData[index] = element;
 361.436 +        size++;
 361.437 +    }
 361.438 +
 361.439 +    /**
 361.440 +     * Removes the element at the specified position in this list.
 361.441 +     * Shifts any subsequent elements to the left (subtracts one from their
 361.442 +     * indices).
 361.443 +     *
 361.444 +     * @param index the index of the element to be removed
 361.445 +     * @return the element that was removed from the list
 361.446 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.447 +     */
 361.448 +    public E remove(int index) {
 361.449 +        rangeCheck(index);
 361.450 +
 361.451 +        modCount++;
 361.452 +        E oldValue = elementData(index);
 361.453 +
 361.454 +        int numMoved = size - index - 1;
 361.455 +        if (numMoved > 0)
 361.456 +            System.arraycopy(elementData, index+1, elementData, index,
 361.457 +                             numMoved);
 361.458 +        elementData[--size] = null; // Let gc do its work
 361.459 +
 361.460 +        return oldValue;
 361.461 +    }
 361.462 +
 361.463 +    /**
 361.464 +     * Removes the first occurrence of the specified element from this list,
 361.465 +     * if it is present.  If the list does not contain the element, it is
 361.466 +     * unchanged.  More formally, removes the element with the lowest index
 361.467 +     * <tt>i</tt> such that
 361.468 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
 361.469 +     * (if such an element exists).  Returns <tt>true</tt> if this list
 361.470 +     * contained the specified element (or equivalently, if this list
 361.471 +     * changed as a result of the call).
 361.472 +     *
 361.473 +     * @param o element to be removed from this list, if present
 361.474 +     * @return <tt>true</tt> if this list contained the specified element
 361.475 +     */
 361.476 +    public boolean remove(Object o) {
 361.477 +        if (o == null) {
 361.478 +            for (int index = 0; index < size; index++)
 361.479 +                if (elementData[index] == null) {
 361.480 +                    fastRemove(index);
 361.481 +                    return true;
 361.482 +                }
 361.483 +        } else {
 361.484 +            for (int index = 0; index < size; index++)
 361.485 +                if (o.equals(elementData[index])) {
 361.486 +                    fastRemove(index);
 361.487 +                    return true;
 361.488 +                }
 361.489 +        }
 361.490 +        return false;
 361.491 +    }
 361.492 +
 361.493 +    /*
 361.494 +     * Private remove method that skips bounds checking and does not
 361.495 +     * return the value removed.
 361.496 +     */
 361.497 +    private void fastRemove(int index) {
 361.498 +        modCount++;
 361.499 +        int numMoved = size - index - 1;
 361.500 +        if (numMoved > 0)
 361.501 +            System.arraycopy(elementData, index+1, elementData, index,
 361.502 +                             numMoved);
 361.503 +        elementData[--size] = null; // Let gc do its work
 361.504 +    }
 361.505 +
 361.506 +    /**
 361.507 +     * Removes all of the elements from this list.  The list will
 361.508 +     * be empty after this call returns.
 361.509 +     */
 361.510 +    public void clear() {
 361.511 +        modCount++;
 361.512 +
 361.513 +        // Let gc do its work
 361.514 +        for (int i = 0; i < size; i++)
 361.515 +            elementData[i] = null;
 361.516 +
 361.517 +        size = 0;
 361.518 +    }
 361.519 +
 361.520 +    /**
 361.521 +     * Appends all of the elements in the specified collection to the end of
 361.522 +     * this list, in the order that they are returned by the
 361.523 +     * specified collection's Iterator.  The behavior of this operation is
 361.524 +     * undefined if the specified collection is modified while the operation
 361.525 +     * is in progress.  (This implies that the behavior of this call is
 361.526 +     * undefined if the specified collection is this list, and this
 361.527 +     * list is nonempty.)
 361.528 +     *
 361.529 +     * @param c collection containing elements to be added to this list
 361.530 +     * @return <tt>true</tt> if this list changed as a result of the call
 361.531 +     * @throws NullPointerException if the specified collection is null
 361.532 +     */
 361.533 +    public boolean addAll(Collection<? extends E> c) {
 361.534 +        Object[] a = c.toArray();
 361.535 +        int numNew = a.length;
 361.536 +        ensureCapacityInternal(size + numNew);  // Increments modCount
 361.537 +        System.arraycopy(a, 0, elementData, size, numNew);
 361.538 +        size += numNew;
 361.539 +        return numNew != 0;
 361.540 +    }
 361.541 +
 361.542 +    /**
 361.543 +     * Inserts all of the elements in the specified collection into this
 361.544 +     * list, starting at the specified position.  Shifts the element
 361.545 +     * currently at that position (if any) and any subsequent elements to
 361.546 +     * the right (increases their indices).  The new elements will appear
 361.547 +     * in the list in the order that they are returned by the
 361.548 +     * specified collection's iterator.
 361.549 +     *
 361.550 +     * @param index index at which to insert the first element from the
 361.551 +     *              specified collection
 361.552 +     * @param c collection containing elements to be added to this list
 361.553 +     * @return <tt>true</tt> if this list changed as a result of the call
 361.554 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.555 +     * @throws NullPointerException if the specified collection is null
 361.556 +     */
 361.557 +    public boolean addAll(int index, Collection<? extends E> c) {
 361.558 +        rangeCheckForAdd(index);
 361.559 +
 361.560 +        Object[] a = c.toArray();
 361.561 +        int numNew = a.length;
 361.562 +        ensureCapacityInternal(size + numNew);  // Increments modCount
 361.563 +
 361.564 +        int numMoved = size - index;
 361.565 +        if (numMoved > 0)
 361.566 +            System.arraycopy(elementData, index, elementData, index + numNew,
 361.567 +                             numMoved);
 361.568 +
 361.569 +        System.arraycopy(a, 0, elementData, index, numNew);
 361.570 +        size += numNew;
 361.571 +        return numNew != 0;
 361.572 +    }
 361.573 +
 361.574 +    /**
 361.575 +     * Removes from this list all of the elements whose index is between
 361.576 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 361.577 +     * Shifts any succeeding elements to the left (reduces their index).
 361.578 +     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 361.579 +     * (If {@code toIndex==fromIndex}, this operation has no effect.)
 361.580 +     *
 361.581 +     * @throws IndexOutOfBoundsException if {@code fromIndex} or
 361.582 +     *         {@code toIndex} is out of range
 361.583 +     *         ({@code fromIndex < 0 ||
 361.584 +     *          fromIndex >= size() ||
 361.585 +     *          toIndex > size() ||
 361.586 +     *          toIndex < fromIndex})
 361.587 +     */
 361.588 +    protected void removeRange(int fromIndex, int toIndex) {
 361.589 +        modCount++;
 361.590 +        int numMoved = size - toIndex;
 361.591 +        System.arraycopy(elementData, toIndex, elementData, fromIndex,
 361.592 +                         numMoved);
 361.593 +
 361.594 +        // Let gc do its work
 361.595 +        int newSize = size - (toIndex-fromIndex);
 361.596 +        while (size != newSize)
 361.597 +            elementData[--size] = null;
 361.598 +    }
 361.599 +
 361.600 +    /**
 361.601 +     * Checks if the given index is in range.  If not, throws an appropriate
 361.602 +     * runtime exception.  This method does *not* check if the index is
 361.603 +     * negative: It is always used immediately prior to an array access,
 361.604 +     * which throws an ArrayIndexOutOfBoundsException if index is negative.
 361.605 +     */
 361.606 +    private void rangeCheck(int index) {
 361.607 +        if (index >= size)
 361.608 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 361.609 +    }
 361.610 +
 361.611 +    /**
 361.612 +     * A version of rangeCheck used by add and addAll.
 361.613 +     */
 361.614 +    private void rangeCheckForAdd(int index) {
 361.615 +        if (index > size || index < 0)
 361.616 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 361.617 +    }
 361.618 +
 361.619 +    /**
 361.620 +     * Constructs an IndexOutOfBoundsException detail message.
 361.621 +     * Of the many possible refactorings of the error handling code,
 361.622 +     * this "outlining" performs best with both server and client VMs.
 361.623 +     */
 361.624 +    private String outOfBoundsMsg(int index) {
 361.625 +        return "Index: "+index+", Size: "+size;
 361.626 +    }
 361.627 +
 361.628 +    /**
 361.629 +     * Removes from this list all of its elements that are contained in the
 361.630 +     * specified collection.
 361.631 +     *
 361.632 +     * @param c collection containing elements to be removed from this list
 361.633 +     * @return {@code true} if this list changed as a result of the call
 361.634 +     * @throws ClassCastException if the class of an element of this list
 361.635 +     *         is incompatible with the specified collection
 361.636 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 361.637 +     * @throws NullPointerException if this list contains a null element and the
 361.638 +     *         specified collection does not permit null elements
 361.639 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
 361.640 +     *         or if the specified collection is null
 361.641 +     * @see Collection#contains(Object)
 361.642 +     */
 361.643 +    public boolean removeAll(Collection<?> c) {
 361.644 +        return batchRemove(c, false);
 361.645 +    }
 361.646 +
 361.647 +    /**
 361.648 +     * Retains only the elements in this list that are contained in the
 361.649 +     * specified collection.  In other words, removes from this list all
 361.650 +     * of its elements that are not contained in the specified collection.
 361.651 +     *
 361.652 +     * @param c collection containing elements to be retained in this list
 361.653 +     * @return {@code true} if this list changed as a result of the call
 361.654 +     * @throws ClassCastException if the class of an element of this list
 361.655 +     *         is incompatible with the specified collection
 361.656 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 361.657 +     * @throws NullPointerException if this list contains a null element and the
 361.658 +     *         specified collection does not permit null elements
 361.659 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
 361.660 +     *         or if the specified collection is null
 361.661 +     * @see Collection#contains(Object)
 361.662 +     */
 361.663 +    public boolean retainAll(Collection<?> c) {
 361.664 +        return batchRemove(c, true);
 361.665 +    }
 361.666 +
 361.667 +    private boolean batchRemove(Collection<?> c, boolean complement) {
 361.668 +        final Object[] elementData = this.elementData;
 361.669 +        int r = 0, w = 0;
 361.670 +        boolean modified = false;
 361.671 +        try {
 361.672 +            for (; r < size; r++)
 361.673 +                if (c.contains(elementData[r]) == complement)
 361.674 +                    elementData[w++] = elementData[r];
 361.675 +        } finally {
 361.676 +            // Preserve behavioral compatibility with AbstractCollection,
 361.677 +            // even if c.contains() throws.
 361.678 +            if (r != size) {
 361.679 +                System.arraycopy(elementData, r,
 361.680 +                                 elementData, w,
 361.681 +                                 size - r);
 361.682 +                w += size - r;
 361.683 +            }
 361.684 +            if (w != size) {
 361.685 +                for (int i = w; i < size; i++)
 361.686 +                    elementData[i] = null;
 361.687 +                modCount += size - w;
 361.688 +                size = w;
 361.689 +                modified = true;
 361.690 +            }
 361.691 +        }
 361.692 +        return modified;
 361.693 +    }
 361.694 +
 361.695 +    /**
 361.696 +     * Returns a list iterator over the elements in this list (in proper
 361.697 +     * sequence), starting at the specified position in the list.
 361.698 +     * The specified index indicates the first element that would be
 361.699 +     * returned by an initial call to {@link ListIterator#next next}.
 361.700 +     * An initial call to {@link ListIterator#previous previous} would
 361.701 +     * return the element with the specified index minus one.
 361.702 +     *
 361.703 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 361.704 +     *
 361.705 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.706 +     */
 361.707 +    public ListIterator<E> listIterator(int index) {
 361.708 +        if (index < 0 || index > size)
 361.709 +            throw new IndexOutOfBoundsException("Index: "+index);
 361.710 +        return new ListItr(index);
 361.711 +    }
 361.712 +
 361.713 +    /**
 361.714 +     * Returns a list iterator over the elements in this list (in proper
 361.715 +     * sequence).
 361.716 +     *
 361.717 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 361.718 +     *
 361.719 +     * @see #listIterator(int)
 361.720 +     */
 361.721 +    public ListIterator<E> listIterator() {
 361.722 +        return new ListItr(0);
 361.723 +    }
 361.724 +
 361.725 +    /**
 361.726 +     * Returns an iterator over the elements in this list in proper sequence.
 361.727 +     *
 361.728 +     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
 361.729 +     *
 361.730 +     * @return an iterator over the elements in this list in proper sequence
 361.731 +     */
 361.732 +    public Iterator<E> iterator() {
 361.733 +        return new Itr();
 361.734 +    }
 361.735 +
 361.736 +    /**
 361.737 +     * An optimized version of AbstractList.Itr
 361.738 +     */
 361.739 +    private class Itr implements Iterator<E> {
 361.740 +        int cursor;       // index of next element to return
 361.741 +        int lastRet = -1; // index of last element returned; -1 if no such
 361.742 +        int expectedModCount = modCount;
 361.743 +
 361.744 +        public boolean hasNext() {
 361.745 +            return cursor != size;
 361.746 +        }
 361.747 +
 361.748 +        @SuppressWarnings("unchecked")
 361.749 +        public E next() {
 361.750 +            checkForComodification();
 361.751 +            int i = cursor;
 361.752 +            if (i >= size)
 361.753 +                throw new NoSuchElementException();
 361.754 +            Object[] elementData = ArrayList.this.elementData;
 361.755 +            if (i >= elementData.length)
 361.756 +                throw new ConcurrentModificationException();
 361.757 +            cursor = i + 1;
 361.758 +            return (E) elementData[lastRet = i];
 361.759 +        }
 361.760 +
 361.761 +        public void remove() {
 361.762 +            if (lastRet < 0)
 361.763 +                throw new IllegalStateException();
 361.764 +            checkForComodification();
 361.765 +
 361.766 +            try {
 361.767 +                ArrayList.this.remove(lastRet);
 361.768 +                cursor = lastRet;
 361.769 +                lastRet = -1;
 361.770 +                expectedModCount = modCount;
 361.771 +            } catch (IndexOutOfBoundsException ex) {
 361.772 +                throw new ConcurrentModificationException();
 361.773 +            }
 361.774 +        }
 361.775 +
 361.776 +        final void checkForComodification() {
 361.777 +            if (modCount != expectedModCount)
 361.778 +                throw new ConcurrentModificationException();
 361.779 +        }
 361.780 +    }
 361.781 +
 361.782 +    /**
 361.783 +     * An optimized version of AbstractList.ListItr
 361.784 +     */
 361.785 +    private class ListItr extends Itr implements ListIterator<E> {
 361.786 +        ListItr(int index) {
 361.787 +            super();
 361.788 +            cursor = index;
 361.789 +        }
 361.790 +
 361.791 +        public boolean hasPrevious() {
 361.792 +            return cursor != 0;
 361.793 +        }
 361.794 +
 361.795 +        public int nextIndex() {
 361.796 +            return cursor;
 361.797 +        }
 361.798 +
 361.799 +        public int previousIndex() {
 361.800 +            return cursor - 1;
 361.801 +        }
 361.802 +
 361.803 +        @SuppressWarnings("unchecked")
 361.804 +        public E previous() {
 361.805 +            checkForComodification();
 361.806 +            int i = cursor - 1;
 361.807 +            if (i < 0)
 361.808 +                throw new NoSuchElementException();
 361.809 +            Object[] elementData = ArrayList.this.elementData;
 361.810 +            if (i >= elementData.length)
 361.811 +                throw new ConcurrentModificationException();
 361.812 +            cursor = i;
 361.813 +            return (E) elementData[lastRet = i];
 361.814 +        }
 361.815 +
 361.816 +        public void set(E e) {
 361.817 +            if (lastRet < 0)
 361.818 +                throw new IllegalStateException();
 361.819 +            checkForComodification();
 361.820 +
 361.821 +            try {
 361.822 +                ArrayList.this.set(lastRet, e);
 361.823 +            } catch (IndexOutOfBoundsException ex) {
 361.824 +                throw new ConcurrentModificationException();
 361.825 +            }
 361.826 +        }
 361.827 +
 361.828 +        public void add(E e) {
 361.829 +            checkForComodification();
 361.830 +
 361.831 +            try {
 361.832 +                int i = cursor;
 361.833 +                ArrayList.this.add(i, e);
 361.834 +                cursor = i + 1;
 361.835 +                lastRet = -1;
 361.836 +                expectedModCount = modCount;
 361.837 +            } catch (IndexOutOfBoundsException ex) {
 361.838 +                throw new ConcurrentModificationException();
 361.839 +            }
 361.840 +        }
 361.841 +    }
 361.842 +
 361.843 +    /**
 361.844 +     * Returns a view of the portion of this list between the specified
 361.845 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.  (If
 361.846 +     * {@code fromIndex} and {@code toIndex} are equal, the returned list is
 361.847 +     * empty.)  The returned list is backed by this list, so non-structural
 361.848 +     * changes in the returned list are reflected in this list, and vice-versa.
 361.849 +     * The returned list supports all of the optional list operations.
 361.850 +     *
 361.851 +     * <p>This method eliminates the need for explicit range operations (of
 361.852 +     * the sort that commonly exist for arrays).  Any operation that expects
 361.853 +     * a list can be used as a range operation by passing a subList view
 361.854 +     * instead of a whole list.  For example, the following idiom
 361.855 +     * removes a range of elements from a list:
 361.856 +     * <pre>
 361.857 +     *      list.subList(from, to).clear();
 361.858 +     * </pre>
 361.859 +     * Similar idioms may be constructed for {@link #indexOf(Object)} and
 361.860 +     * {@link #lastIndexOf(Object)}, and all of the algorithms in the
 361.861 +     * {@link Collections} class can be applied to a subList.
 361.862 +     *
 361.863 +     * <p>The semantics of the list returned by this method become undefined if
 361.864 +     * the backing list (i.e., this list) is <i>structurally modified</i> in
 361.865 +     * any way other than via the returned list.  (Structural modifications are
 361.866 +     * those that change the size of this list, or otherwise perturb it in such
 361.867 +     * a fashion that iterations in progress may yield incorrect results.)
 361.868 +     *
 361.869 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 361.870 +     * @throws IllegalArgumentException {@inheritDoc}
 361.871 +     */
 361.872 +    public List<E> subList(int fromIndex, int toIndex) {
 361.873 +        subListRangeCheck(fromIndex, toIndex, size);
 361.874 +        return new SubList(this, 0, fromIndex, toIndex);
 361.875 +    }
 361.876 +
 361.877 +    static void subListRangeCheck(int fromIndex, int toIndex, int size) {
 361.878 +        if (fromIndex < 0)
 361.879 +            throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
 361.880 +        if (toIndex > size)
 361.881 +            throw new IndexOutOfBoundsException("toIndex = " + toIndex);
 361.882 +        if (fromIndex > toIndex)
 361.883 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
 361.884 +                                               ") > toIndex(" + toIndex + ")");
 361.885 +    }
 361.886 +
 361.887 +    private class SubList extends AbstractList<E> implements RandomAccess {
 361.888 +        private final AbstractList<E> parent;
 361.889 +        private final int parentOffset;
 361.890 +        private final int offset;
 361.891 +        int size;
 361.892 +
 361.893 +        SubList(AbstractList<E> parent,
 361.894 +                int offset, int fromIndex, int toIndex) {
 361.895 +            this.parent = parent;
 361.896 +            this.parentOffset = fromIndex;
 361.897 +            this.offset = offset + fromIndex;
 361.898 +            this.size = toIndex - fromIndex;
 361.899 +            this.modCount = ArrayList.this.modCount;
 361.900 +        }
 361.901 +
 361.902 +        public E set(int index, E e) {
 361.903 +            rangeCheck(index);
 361.904 +            checkForComodification();
 361.905 +            E oldValue = ArrayList.this.elementData(offset + index);
 361.906 +            ArrayList.this.elementData[offset + index] = e;
 361.907 +            return oldValue;
 361.908 +        }
 361.909 +
 361.910 +        public E get(int index) {
 361.911 +            rangeCheck(index);
 361.912 +            checkForComodification();
 361.913 +            return ArrayList.this.elementData(offset + index);
 361.914 +        }
 361.915 +
 361.916 +        public int size() {
 361.917 +            checkForComodification();
 361.918 +            return this.size;
 361.919 +        }
 361.920 +
 361.921 +        public void add(int index, E e) {
 361.922 +            rangeCheckForAdd(index);
 361.923 +            checkForComodification();
 361.924 +            parent.add(parentOffset + index, e);
 361.925 +            this.modCount = parent.modCount;
 361.926 +            this.size++;
 361.927 +        }
 361.928 +
 361.929 +        public E remove(int index) {
 361.930 +            rangeCheck(index);
 361.931 +            checkForComodification();
 361.932 +            E result = parent.remove(parentOffset + index);
 361.933 +            this.modCount = parent.modCount;
 361.934 +            this.size--;
 361.935 +            return result;
 361.936 +        }
 361.937 +
 361.938 +        protected void removeRange(int fromIndex, int toIndex) {
 361.939 +            checkForComodification();
 361.940 +            parent.removeRange(parentOffset + fromIndex,
 361.941 +                               parentOffset + toIndex);
 361.942 +            this.modCount = parent.modCount;
 361.943 +            this.size -= toIndex - fromIndex;
 361.944 +        }
 361.945 +
 361.946 +        public boolean addAll(Collection<? extends E> c) {
 361.947 +            return addAll(this.size, c);
 361.948 +        }
 361.949 +
 361.950 +        public boolean addAll(int index, Collection<? extends E> c) {
 361.951 +            rangeCheckForAdd(index);
 361.952 +            int cSize = c.size();
 361.953 +            if (cSize==0)
 361.954 +                return false;
 361.955 +
 361.956 +            checkForComodification();
 361.957 +            parent.addAll(parentOffset + index, c);
 361.958 +            this.modCount = parent.modCount;
 361.959 +            this.size += cSize;
 361.960 +            return true;
 361.961 +        }
 361.962 +
 361.963 +        public Iterator<E> iterator() {
 361.964 +            return listIterator();
 361.965 +        }
 361.966 +
 361.967 +        public ListIterator<E> listIterator(final int index) {
 361.968 +            checkForComodification();
 361.969 +            rangeCheckForAdd(index);
 361.970 +            final int offset = this.offset;
 361.971 +
 361.972 +            return new ListIterator<E>() {
 361.973 +                int cursor = index;
 361.974 +                int lastRet = -1;
 361.975 +                int expectedModCount = ArrayList.this.modCount;
 361.976 +
 361.977 +                public boolean hasNext() {
 361.978 +                    return cursor != SubList.this.size;
 361.979 +                }
 361.980 +
 361.981 +                @SuppressWarnings("unchecked")
 361.982 +                public E next() {
 361.983 +                    checkForComodification();
 361.984 +                    int i = cursor;
 361.985 +                    if (i >= SubList.this.size)
 361.986 +                        throw new NoSuchElementException();
 361.987 +                    Object[] elementData = ArrayList.this.elementData;
 361.988 +                    if (offset + i >= elementData.length)
 361.989 +                        throw new ConcurrentModificationException();
 361.990 +                    cursor = i + 1;
 361.991 +                    return (E) elementData[offset + (lastRet = i)];
 361.992 +                }
 361.993 +
 361.994 +                public boolean hasPrevious() {
 361.995 +                    return cursor != 0;
 361.996 +                }
 361.997 +
 361.998 +                @SuppressWarnings("unchecked")
 361.999 +                public E previous() {
361.1000 +                    checkForComodification();
361.1001 +                    int i = cursor - 1;
361.1002 +                    if (i < 0)
361.1003 +                        throw new NoSuchElementException();
361.1004 +                    Object[] elementData = ArrayList.this.elementData;
361.1005 +                    if (offset + i >= elementData.length)
361.1006 +                        throw new ConcurrentModificationException();
361.1007 +                    cursor = i;
361.1008 +                    return (E) elementData[offset + (lastRet = i)];
361.1009 +                }
361.1010 +
361.1011 +                public int nextIndex() {
361.1012 +                    return cursor;
361.1013 +                }
361.1014 +
361.1015 +                public int previousIndex() {
361.1016 +                    return cursor - 1;
361.1017 +                }
361.1018 +
361.1019 +                public void remove() {
361.1020 +                    if (lastRet < 0)
361.1021 +                        throw new IllegalStateException();
361.1022 +                    checkForComodification();
361.1023 +
361.1024 +                    try {
361.1025 +                        SubList.this.remove(lastRet);
361.1026 +                        cursor = lastRet;
361.1027 +                        lastRet = -1;
361.1028 +                        expectedModCount = ArrayList.this.modCount;
361.1029 +                    } catch (IndexOutOfBoundsException ex) {
361.1030 +                        throw new ConcurrentModificationException();
361.1031 +                    }
361.1032 +                }
361.1033 +
361.1034 +                public void set(E e) {
361.1035 +                    if (lastRet < 0)
361.1036 +                        throw new IllegalStateException();
361.1037 +                    checkForComodification();
361.1038 +
361.1039 +                    try {
361.1040 +                        ArrayList.this.set(offset + lastRet, e);
361.1041 +                    } catch (IndexOutOfBoundsException ex) {
361.1042 +                        throw new ConcurrentModificationException();
361.1043 +                    }
361.1044 +                }
361.1045 +
361.1046 +                public void add(E e) {
361.1047 +                    checkForComodification();
361.1048 +
361.1049 +                    try {
361.1050 +                        int i = cursor;
361.1051 +                        SubList.this.add(i, e);
361.1052 +                        cursor = i + 1;
361.1053 +                        lastRet = -1;
361.1054 +                        expectedModCount = ArrayList.this.modCount;
361.1055 +                    } catch (IndexOutOfBoundsException ex) {
361.1056 +                        throw new ConcurrentModificationException();
361.1057 +                    }
361.1058 +                }
361.1059 +
361.1060 +                final void checkForComodification() {
361.1061 +                    if (expectedModCount != ArrayList.this.modCount)
361.1062 +                        throw new ConcurrentModificationException();
361.1063 +                }
361.1064 +            };
361.1065 +        }
361.1066 +
361.1067 +        public List<E> subList(int fromIndex, int toIndex) {
361.1068 +            subListRangeCheck(fromIndex, toIndex, size);
361.1069 +            return new SubList(this, offset, fromIndex, toIndex);
361.1070 +        }
361.1071 +
361.1072 +        private void rangeCheck(int index) {
361.1073 +            if (index < 0 || index >= this.size)
361.1074 +                throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
361.1075 +        }
361.1076 +
361.1077 +        private void rangeCheckForAdd(int index) {
361.1078 +            if (index < 0 || index > this.size)
361.1079 +                throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
361.1080 +        }
361.1081 +
361.1082 +        private String outOfBoundsMsg(int index) {
361.1083 +            return "Index: "+index+", Size: "+this.size;
361.1084 +        }
361.1085 +
361.1086 +        private void checkForComodification() {
361.1087 +            if (ArrayList.this.modCount != this.modCount)
361.1088 +                throw new ConcurrentModificationException();
361.1089 +        }
361.1090 +    }
361.1091 +}
   362.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   362.2 +++ b/rt/emul/compact/src/main/java/java/util/Arrays.java	Wed Feb 27 11:24:58 2013 +0100
   362.3 @@ -0,0 +1,3670 @@
   362.4 +/*
   362.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   362.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   362.7 + *
   362.8 + * This code is free software; you can redistribute it and/or modify it
   362.9 + * under the terms of the GNU General Public License version 2 only, as
  362.10 + * published by the Free Software Foundation.  Oracle designates this
  362.11 + * particular file as subject to the "Classpath" exception as provided
  362.12 + * by Oracle in the LICENSE file that accompanied this code.
  362.13 + *
  362.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  362.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  362.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  362.17 + * version 2 for more details (a copy is included in the LICENSE file that
  362.18 + * accompanied this code).
  362.19 + *
  362.20 + * You should have received a copy of the GNU General Public License version
  362.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  362.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  362.23 + *
  362.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  362.25 + * or visit www.oracle.com if you need additional information or have any
  362.26 + * questions.
  362.27 + */
  362.28 +
  362.29 +package java.util;
  362.30 +
  362.31 +import java.lang.reflect.*;
  362.32 +
  362.33 +/**
  362.34 + * This class contains various methods for manipulating arrays (such as
  362.35 + * sorting and searching). This class also contains a static factory
  362.36 + * that allows arrays to be viewed as lists.
  362.37 + *
  362.38 + * <p>The methods in this class all throw a {@code NullPointerException},
  362.39 + * if the specified array reference is null, except where noted.
  362.40 + *
  362.41 + * <p>The documentation for the methods contained in this class includes
  362.42 + * briefs description of the <i>implementations</i>. Such descriptions should
  362.43 + * be regarded as <i>implementation notes</i>, rather than parts of the
  362.44 + * <i>specification</i>. Implementors should feel free to substitute other
  362.45 + * algorithms, so long as the specification itself is adhered to. (For
  362.46 + * example, the algorithm used by {@code sort(Object[])} does not have to be
  362.47 + * a MergeSort, but it does have to be <i>stable</i>.)
  362.48 + *
  362.49 + * <p>This class is a member of the
  362.50 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  362.51 + * Java Collections Framework</a>.
  362.52 + *
  362.53 + * @author Josh Bloch
  362.54 + * @author Neal Gafter
  362.55 + * @author John Rose
  362.56 + * @since  1.2
  362.57 + */
  362.58 +public class Arrays {
  362.59 +
  362.60 +    // Suppresses default constructor, ensuring non-instantiability.
  362.61 +    private Arrays() {}
  362.62 +
  362.63 +    /*
  362.64 +     * Sorting of primitive type arrays.
  362.65 +     */
  362.66 +
  362.67 +    /**
  362.68 +     * Sorts the specified array into ascending numerical order.
  362.69 +     *
  362.70 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  362.71 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  362.72 +     * offers O(n log(n)) performance on many data sets that cause other
  362.73 +     * quicksorts to degrade to quadratic performance, and is typically
  362.74 +     * faster than traditional (one-pivot) Quicksort implementations.
  362.75 +     *
  362.76 +     * @param a the array to be sorted
  362.77 +     */
  362.78 +    public static void sort(int[] a) {
  362.79 +        DualPivotQuicksort.sort(a);
  362.80 +    }
  362.81 +
  362.82 +    /**
  362.83 +     * Sorts the specified range of the array into ascending order. The range
  362.84 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
  362.85 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
  362.86 +     * the range to be sorted is empty.
  362.87 +     *
  362.88 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
  362.89 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
  362.90 +     * offers O(n log(n)) performance on many data sets that cause other
  362.91 +     * quicksorts to degrade to quadratic performance, and is typically
  362.92 +     * faster than traditional (one-pivot) Quicksort implementations.
  362.93 +     *
  362.94 +     * @param a the array to be sorted
  362.95 +     * @param fromIndex the index of the first element, inclusive, to be sorted
  362.96 +     * @param toIndex the index of the last element, exclusive, to be sorted
  362.97 +     *
  362.98 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
  362.99 +     * @throws ArrayIndexOutOfBoundsException
 362.100 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.101 +     */
 362.102 +    public static void sort(int[] a, int fromIndex, int toIndex) {
 362.103 +        rangeCheck(a.length, fromIndex, toIndex);
 362.104 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.105 +    }
 362.106 +
 362.107 +    /**
 362.108 +     * Sorts the specified array into ascending numerical order.
 362.109 +     *
 362.110 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.111 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.112 +     * offers O(n log(n)) performance on many data sets that cause other
 362.113 +     * quicksorts to degrade to quadratic performance, and is typically
 362.114 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.115 +     *
 362.116 +     * @param a the array to be sorted
 362.117 +     */
 362.118 +    public static void sort(long[] a) {
 362.119 +        DualPivotQuicksort.sort(a);
 362.120 +    }
 362.121 +
 362.122 +    /**
 362.123 +     * Sorts the specified range of the array into ascending order. The range
 362.124 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
 362.125 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 362.126 +     * the range to be sorted is empty.
 362.127 +     *
 362.128 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.129 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.130 +     * offers O(n log(n)) performance on many data sets that cause other
 362.131 +     * quicksorts to degrade to quadratic performance, and is typically
 362.132 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.133 +     *
 362.134 +     * @param a the array to be sorted
 362.135 +     * @param fromIndex the index of the first element, inclusive, to be sorted
 362.136 +     * @param toIndex the index of the last element, exclusive, to be sorted
 362.137 +     *
 362.138 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
 362.139 +     * @throws ArrayIndexOutOfBoundsException
 362.140 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.141 +     */
 362.142 +    public static void sort(long[] a, int fromIndex, int toIndex) {
 362.143 +        rangeCheck(a.length, fromIndex, toIndex);
 362.144 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.145 +    }
 362.146 +
 362.147 +    /**
 362.148 +     * Sorts the specified array into ascending numerical order.
 362.149 +     *
 362.150 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.151 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.152 +     * offers O(n log(n)) performance on many data sets that cause other
 362.153 +     * quicksorts to degrade to quadratic performance, and is typically
 362.154 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.155 +     *
 362.156 +     * @param a the array to be sorted
 362.157 +     */
 362.158 +    public static void sort(short[] a) {
 362.159 +        DualPivotQuicksort.sort(a);
 362.160 +    }
 362.161 +
 362.162 +    /**
 362.163 +     * Sorts the specified range of the array into ascending order. The range
 362.164 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
 362.165 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 362.166 +     * the range to be sorted is empty.
 362.167 +     *
 362.168 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.169 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.170 +     * offers O(n log(n)) performance on many data sets that cause other
 362.171 +     * quicksorts to degrade to quadratic performance, and is typically
 362.172 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.173 +     *
 362.174 +     * @param a the array to be sorted
 362.175 +     * @param fromIndex the index of the first element, inclusive, to be sorted
 362.176 +     * @param toIndex the index of the last element, exclusive, to be sorted
 362.177 +     *
 362.178 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
 362.179 +     * @throws ArrayIndexOutOfBoundsException
 362.180 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.181 +     */
 362.182 +    public static void sort(short[] a, int fromIndex, int toIndex) {
 362.183 +        rangeCheck(a.length, fromIndex, toIndex);
 362.184 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.185 +    }
 362.186 +
 362.187 +    /**
 362.188 +     * Sorts the specified array into ascending numerical order.
 362.189 +     *
 362.190 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.191 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.192 +     * offers O(n log(n)) performance on many data sets that cause other
 362.193 +     * quicksorts to degrade to quadratic performance, and is typically
 362.194 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.195 +     *
 362.196 +     * @param a the array to be sorted
 362.197 +     */
 362.198 +    public static void sort(char[] a) {
 362.199 +        DualPivotQuicksort.sort(a);
 362.200 +    }
 362.201 +
 362.202 +    /**
 362.203 +     * Sorts the specified range of the array into ascending order. The range
 362.204 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
 362.205 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 362.206 +     * the range to be sorted is empty.
 362.207 +     *
 362.208 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.209 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.210 +     * offers O(n log(n)) performance on many data sets that cause other
 362.211 +     * quicksorts to degrade to quadratic performance, and is typically
 362.212 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.213 +     *
 362.214 +     * @param a the array to be sorted
 362.215 +     * @param fromIndex the index of the first element, inclusive, to be sorted
 362.216 +     * @param toIndex the index of the last element, exclusive, to be sorted
 362.217 +     *
 362.218 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
 362.219 +     * @throws ArrayIndexOutOfBoundsException
 362.220 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.221 +     */
 362.222 +    public static void sort(char[] a, int fromIndex, int toIndex) {
 362.223 +        rangeCheck(a.length, fromIndex, toIndex);
 362.224 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.225 +    }
 362.226 +
 362.227 +    /**
 362.228 +     * Sorts the specified array into ascending numerical order.
 362.229 +     *
 362.230 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.231 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.232 +     * offers O(n log(n)) performance on many data sets that cause other
 362.233 +     * quicksorts to degrade to quadratic performance, and is typically
 362.234 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.235 +     *
 362.236 +     * @param a the array to be sorted
 362.237 +     */
 362.238 +    public static void sort(byte[] a) {
 362.239 +        DualPivotQuicksort.sort(a);
 362.240 +    }
 362.241 +
 362.242 +    /**
 362.243 +     * Sorts the specified range of the array into ascending order. The range
 362.244 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
 362.245 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 362.246 +     * the range to be sorted is empty.
 362.247 +     *
 362.248 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.249 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.250 +     * offers O(n log(n)) performance on many data sets that cause other
 362.251 +     * quicksorts to degrade to quadratic performance, and is typically
 362.252 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.253 +     *
 362.254 +     * @param a the array to be sorted
 362.255 +     * @param fromIndex the index of the first element, inclusive, to be sorted
 362.256 +     * @param toIndex the index of the last element, exclusive, to be sorted
 362.257 +     *
 362.258 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
 362.259 +     * @throws ArrayIndexOutOfBoundsException
 362.260 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.261 +     */
 362.262 +    public static void sort(byte[] a, int fromIndex, int toIndex) {
 362.263 +        rangeCheck(a.length, fromIndex, toIndex);
 362.264 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.265 +    }
 362.266 +
 362.267 +    /**
 362.268 +     * Sorts the specified array into ascending numerical order.
 362.269 +     *
 362.270 +     * <p>The {@code <} relation does not provide a total order on all float
 362.271 +     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
 362.272 +     * value compares neither less than, greater than, nor equal to any value,
 362.273 +     * even itself. This method uses the total order imposed by the method
 362.274 +     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
 362.275 +     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
 362.276 +     * other value and all {@code Float.NaN} values are considered equal.
 362.277 +     *
 362.278 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.279 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.280 +     * offers O(n log(n)) performance on many data sets that cause other
 362.281 +     * quicksorts to degrade to quadratic performance, and is typically
 362.282 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.283 +     *
 362.284 +     * @param a the array to be sorted
 362.285 +     */
 362.286 +    public static void sort(float[] a) {
 362.287 +        DualPivotQuicksort.sort(a);
 362.288 +    }
 362.289 +
 362.290 +    /**
 362.291 +     * Sorts the specified range of the array into ascending order. The range
 362.292 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
 362.293 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 362.294 +     * the range to be sorted is empty.
 362.295 +     *
 362.296 +     * <p>The {@code <} relation does not provide a total order on all float
 362.297 +     * values: {@code -0.0f == 0.0f} is {@code true} and a {@code Float.NaN}
 362.298 +     * value compares neither less than, greater than, nor equal to any value,
 362.299 +     * even itself. This method uses the total order imposed by the method
 362.300 +     * {@link Float#compareTo}: {@code -0.0f} is treated as less than value
 362.301 +     * {@code 0.0f} and {@code Float.NaN} is considered greater than any
 362.302 +     * other value and all {@code Float.NaN} values are considered equal.
 362.303 +     *
 362.304 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.305 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.306 +     * offers O(n log(n)) performance on many data sets that cause other
 362.307 +     * quicksorts to degrade to quadratic performance, and is typically
 362.308 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.309 +     *
 362.310 +     * @param a the array to be sorted
 362.311 +     * @param fromIndex the index of the first element, inclusive, to be sorted
 362.312 +     * @param toIndex the index of the last element, exclusive, to be sorted
 362.313 +     *
 362.314 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
 362.315 +     * @throws ArrayIndexOutOfBoundsException
 362.316 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.317 +     */
 362.318 +    public static void sort(float[] a, int fromIndex, int toIndex) {
 362.319 +        rangeCheck(a.length, fromIndex, toIndex);
 362.320 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.321 +    }
 362.322 +
 362.323 +    /**
 362.324 +     * Sorts the specified array into ascending numerical order.
 362.325 +     *
 362.326 +     * <p>The {@code <} relation does not provide a total order on all double
 362.327 +     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
 362.328 +     * value compares neither less than, greater than, nor equal to any value,
 362.329 +     * even itself. This method uses the total order imposed by the method
 362.330 +     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
 362.331 +     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
 362.332 +     * other value and all {@code Double.NaN} values are considered equal.
 362.333 +     *
 362.334 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.335 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.336 +     * offers O(n log(n)) performance on many data sets that cause other
 362.337 +     * quicksorts to degrade to quadratic performance, and is typically
 362.338 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.339 +     *
 362.340 +     * @param a the array to be sorted
 362.341 +     */
 362.342 +    public static void sort(double[] a) {
 362.343 +        DualPivotQuicksort.sort(a);
 362.344 +    }
 362.345 +
 362.346 +    /**
 362.347 +     * Sorts the specified range of the array into ascending order. The range
 362.348 +     * to be sorted extends from the index {@code fromIndex}, inclusive, to
 362.349 +     * the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
 362.350 +     * the range to be sorted is empty.
 362.351 +     *
 362.352 +     * <p>The {@code <} relation does not provide a total order on all double
 362.353 +     * values: {@code -0.0d == 0.0d} is {@code true} and a {@code Double.NaN}
 362.354 +     * value compares neither less than, greater than, nor equal to any value,
 362.355 +     * even itself. This method uses the total order imposed by the method
 362.356 +     * {@link Double#compareTo}: {@code -0.0d} is treated as less than value
 362.357 +     * {@code 0.0d} and {@code Double.NaN} is considered greater than any
 362.358 +     * other value and all {@code Double.NaN} values are considered equal.
 362.359 +     *
 362.360 +     * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
 362.361 +     * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
 362.362 +     * offers O(n log(n)) performance on many data sets that cause other
 362.363 +     * quicksorts to degrade to quadratic performance, and is typically
 362.364 +     * faster than traditional (one-pivot) Quicksort implementations.
 362.365 +     *
 362.366 +     * @param a the array to be sorted
 362.367 +     * @param fromIndex the index of the first element, inclusive, to be sorted
 362.368 +     * @param toIndex the index of the last element, exclusive, to be sorted
 362.369 +     *
 362.370 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex}
 362.371 +     * @throws ArrayIndexOutOfBoundsException
 362.372 +     *     if {@code fromIndex < 0} or {@code toIndex > a.length}
 362.373 +     */
 362.374 +    public static void sort(double[] a, int fromIndex, int toIndex) {
 362.375 +        rangeCheck(a.length, fromIndex, toIndex);
 362.376 +        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1);
 362.377 +    }
 362.378 +
 362.379 +    /*
 362.380 +     * Sorting of complex type arrays.
 362.381 +     */
 362.382 +
 362.383 +    /**
 362.384 +     * Old merge sort implementation can be selected (for
 362.385 +     * compatibility with broken comparators) using a system property.
 362.386 +     * Cannot be a static boolean in the enclosing class due to
 362.387 +     * circular dependencies. To be removed in a future release.
 362.388 +     */
 362.389 +    static final class LegacyMergeSort {
 362.390 +        private static final boolean userRequested = false;
 362.391 +    }
 362.392 +
 362.393 +    /*
 362.394 +     * If this platform has an optimizing VM, check whether ComparableTimSort
 362.395 +     * offers any performance benefit over TimSort in conjunction with a
 362.396 +     * comparator that returns:
 362.397 +     *    {@code ((Comparable)first).compareTo(Second)}.
 362.398 +     * If not, you are better off deleting ComparableTimSort to
 362.399 +     * eliminate the code duplication.  In other words, the commented
 362.400 +     * out code below is the preferable implementation for sorting
 362.401 +     * arrays of Comparables if it offers sufficient performance.
 362.402 +     */
 362.403 +
 362.404 +//    /**
 362.405 +//     * A comparator that implements the natural ordering of a group of
 362.406 +//     * mutually comparable elements.  Using this comparator saves us
 362.407 +//     * from duplicating most of the code in this file (one version for
 362.408 +//     * Comparables, one for explicit Comparators).
 362.409 +//     */
 362.410 +//    private static final Comparator<Object> NATURAL_ORDER =
 362.411 +//            new Comparator<Object>() {
 362.412 +//        @SuppressWarnings("unchecked")
 362.413 +//        public int compare(Object first, Object second) {
 362.414 +//            return ((Comparable<Object>)first).compareTo(second);
 362.415 +//        }
 362.416 +//    };
 362.417 +//
 362.418 +//    public static void sort(Object[] a) {
 362.419 +//        sort(a, 0, a.length, NATURAL_ORDER);
 362.420 +//    }
 362.421 +//
 362.422 +//    public static void sort(Object[] a, int fromIndex, int toIndex) {
 362.423 +//        sort(a, fromIndex, toIndex, NATURAL_ORDER);
 362.424 +//    }
 362.425 +
 362.426 +    /**
 362.427 +     * Sorts the specified array of objects into ascending order, according
 362.428 +     * to the {@linkplain Comparable natural ordering} of its elements.
 362.429 +     * All elements in the array must implement the {@link Comparable}
 362.430 +     * interface.  Furthermore, all elements in the array must be
 362.431 +     * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)} must
 362.432 +     * not throw a {@code ClassCastException} for any elements {@code e1}
 362.433 +     * and {@code e2} in the array).
 362.434 +     *
 362.435 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
 362.436 +     * not be reordered as a result of the sort.
 362.437 +     *
 362.438 +     * <p>Implementation note: This implementation is a stable, adaptive,
 362.439 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
 362.440 +     * when the input array is partially sorted, while offering the
 362.441 +     * performance of a traditional mergesort when the input array is
 362.442 +     * randomly ordered.  If the input array is nearly sorted, the
 362.443 +     * implementation requires approximately n comparisons.  Temporary
 362.444 +     * storage requirements vary from a small constant for nearly sorted
 362.445 +     * input arrays to n/2 object references for randomly ordered input
 362.446 +     * arrays.
 362.447 +     *
 362.448 +     * <p>The implementation takes equal advantage of ascending and
 362.449 +     * descending order in its input array, and can take advantage of
 362.450 +     * ascending and descending order in different parts of the the same
 362.451 +     * input array.  It is well-suited to merging two or more sorted arrays:
 362.452 +     * simply concatenate the arrays and sort the resulting array.
 362.453 +     *
 362.454 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
 362.455 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
 362.456 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
 362.457 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
 362.458 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
 362.459 +     * January 1993.
 362.460 +     *
 362.461 +     * @param a the array to be sorted
 362.462 +     * @throws ClassCastException if the array contains elements that are not
 362.463 +     *         <i>mutually comparable</i> (for example, strings and integers)
 362.464 +     * @throws IllegalArgumentException (optional) if the natural
 362.465 +     *         ordering of the array elements is found to violate the
 362.466 +     *         {@link Comparable} contract
 362.467 +     */
 362.468 +    public static void sort(Object[] a) {
 362.469 +        if (LegacyMergeSort.userRequested)
 362.470 +            legacyMergeSort(a);
 362.471 +        else
 362.472 +            ComparableTimSort.sort(a);
 362.473 +    }
 362.474 +
 362.475 +    /** To be removed in a future release. */
 362.476 +    private static void legacyMergeSort(Object[] a) {
 362.477 +        Object[] aux = a.clone();
 362.478 +        mergeSort(aux, a, 0, a.length, 0);
 362.479 +    }
 362.480 +
 362.481 +    /**
 362.482 +     * Sorts the specified range of the specified array of objects into
 362.483 +     * ascending order, according to the
 362.484 +     * {@linkplain Comparable natural ordering} of its
 362.485 +     * elements.  The range to be sorted extends from index
 362.486 +     * {@code fromIndex}, inclusive, to index {@code toIndex}, exclusive.
 362.487 +     * (If {@code fromIndex==toIndex}, the range to be sorted is empty.)  All
 362.488 +     * elements in this range must implement the {@link Comparable}
 362.489 +     * interface.  Furthermore, all elements in this range must be <i>mutually
 362.490 +     * comparable</i> (that is, {@code e1.compareTo(e2)} must not throw a
 362.491 +     * {@code ClassCastException} for any elements {@code e1} and
 362.492 +     * {@code e2} in the array).
 362.493 +     *
 362.494 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
 362.495 +     * not be reordered as a result of the sort.
 362.496 +     *
 362.497 +     * <p>Implementation note: This implementation is a stable, adaptive,
 362.498 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
 362.499 +     * when the input array is partially sorted, while offering the
 362.500 +     * performance of a traditional mergesort when the input array is
 362.501 +     * randomly ordered.  If the input array is nearly sorted, the
 362.502 +     * implementation requires approximately n comparisons.  Temporary
 362.503 +     * storage requirements vary from a small constant for nearly sorted
 362.504 +     * input arrays to n/2 object references for randomly ordered input
 362.505 +     * arrays.
 362.506 +     *
 362.507 +     * <p>The implementation takes equal advantage of ascending and
 362.508 +     * descending order in its input array, and can take advantage of
 362.509 +     * ascending and descending order in different parts of the the same
 362.510 +     * input array.  It is well-suited to merging two or more sorted arrays:
 362.511 +     * simply concatenate the arrays and sort the resulting array.
 362.512 +     *
 362.513 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
 362.514 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
 362.515 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
 362.516 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
 362.517 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
 362.518 +     * January 1993.
 362.519 +     *
 362.520 +     * @param a the array to be sorted
 362.521 +     * @param fromIndex the index of the first element (inclusive) to be
 362.522 +     *        sorted
 362.523 +     * @param toIndex the index of the last element (exclusive) to be sorted
 362.524 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
 362.525 +     *         (optional) if the natural ordering of the array elements is
 362.526 +     *         found to violate the {@link Comparable} contract
 362.527 +     * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
 362.528 +     *         {@code toIndex > a.length}
 362.529 +     * @throws ClassCastException if the array contains elements that are
 362.530 +     *         not <i>mutually comparable</i> (for example, strings and
 362.531 +     *         integers).
 362.532 +     */
 362.533 +    public static void sort(Object[] a, int fromIndex, int toIndex) {
 362.534 +        if (LegacyMergeSort.userRequested)
 362.535 +            legacyMergeSort(a, fromIndex, toIndex);
 362.536 +        else
 362.537 +            ComparableTimSort.sort(a, fromIndex, toIndex);
 362.538 +    }
 362.539 +
 362.540 +    /** To be removed in a future release. */
 362.541 +    private static void legacyMergeSort(Object[] a,
 362.542 +                                        int fromIndex, int toIndex) {
 362.543 +        rangeCheck(a.length, fromIndex, toIndex);
 362.544 +        Object[] aux = copyOfRange(a, fromIndex, toIndex);
 362.545 +        mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
 362.546 +    }
 362.547 +
 362.548 +    /**
 362.549 +     * Tuning parameter: list size at or below which insertion sort will be
 362.550 +     * used in preference to mergesort.
 362.551 +     * To be removed in a future release.
 362.552 +     */
 362.553 +    private static final int INSERTIONSORT_THRESHOLD = 7;
 362.554 +
 362.555 +    /**
 362.556 +     * Src is the source array that starts at index 0
 362.557 +     * Dest is the (possibly larger) array destination with a possible offset
 362.558 +     * low is the index in dest to start sorting
 362.559 +     * high is the end index in dest to end sorting
 362.560 +     * off is the offset to generate corresponding low, high in src
 362.561 +     * To be removed in a future release.
 362.562 +     */
 362.563 +    private static void mergeSort(Object[] src,
 362.564 +                                  Object[] dest,
 362.565 +                                  int low,
 362.566 +                                  int high,
 362.567 +                                  int off) {
 362.568 +        int length = high - low;
 362.569 +
 362.570 +        // Insertion sort on smallest arrays
 362.571 +        if (length < INSERTIONSORT_THRESHOLD) {
 362.572 +            for (int i=low; i<high; i++)
 362.573 +                for (int j=i; j>low &&
 362.574 +                         ((Comparable) dest[j-1]).compareTo(dest[j])>0; j--)
 362.575 +                    swap(dest, j, j-1);
 362.576 +            return;
 362.577 +        }
 362.578 +
 362.579 +        // Recursively sort halves of dest into src
 362.580 +        int destLow  = low;
 362.581 +        int destHigh = high;
 362.582 +        low  += off;
 362.583 +        high += off;
 362.584 +        int mid = (low + high) >>> 1;
 362.585 +        mergeSort(dest, src, low, mid, -off);
 362.586 +        mergeSort(dest, src, mid, high, -off);
 362.587 +
 362.588 +        // If list is already sorted, just copy from src to dest.  This is an
 362.589 +        // optimization that results in faster sorts for nearly ordered lists.
 362.590 +        if (((Comparable)src[mid-1]).compareTo(src[mid]) <= 0) {
 362.591 +            System.arraycopy(src, low, dest, destLow, length);
 362.592 +            return;
 362.593 +        }
 362.594 +
 362.595 +        // Merge sorted halves (now in src) into dest
 362.596 +        for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
 362.597 +            if (q >= high || p < mid && ((Comparable)src[p]).compareTo(src[q])<=0)
 362.598 +                dest[i] = src[p++];
 362.599 +            else
 362.600 +                dest[i] = src[q++];
 362.601 +        }
 362.602 +    }
 362.603 +
 362.604 +    /**
 362.605 +     * Swaps x[a] with x[b].
 362.606 +     */
 362.607 +    private static void swap(Object[] x, int a, int b) {
 362.608 +        Object t = x[a];
 362.609 +        x[a] = x[b];
 362.610 +        x[b] = t;
 362.611 +    }
 362.612 +
 362.613 +    /**
 362.614 +     * Sorts the specified array of objects according to the order induced by
 362.615 +     * the specified comparator.  All elements in the array must be
 362.616 +     * <i>mutually comparable</i> by the specified comparator (that is,
 362.617 +     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
 362.618 +     * for any elements {@code e1} and {@code e2} in the array).
 362.619 +     *
 362.620 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
 362.621 +     * not be reordered as a result of the sort.
 362.622 +     *
 362.623 +     * <p>Implementation note: This implementation is a stable, adaptive,
 362.624 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
 362.625 +     * when the input array is partially sorted, while offering the
 362.626 +     * performance of a traditional mergesort when the input array is
 362.627 +     * randomly ordered.  If the input array is nearly sorted, the
 362.628 +     * implementation requires approximately n comparisons.  Temporary
 362.629 +     * storage requirements vary from a small constant for nearly sorted
 362.630 +     * input arrays to n/2 object references for randomly ordered input
 362.631 +     * arrays.
 362.632 +     *
 362.633 +     * <p>The implementation takes equal advantage of ascending and
 362.634 +     * descending order in its input array, and can take advantage of
 362.635 +     * ascending and descending order in different parts of the the same
 362.636 +     * input array.  It is well-suited to merging two or more sorted arrays:
 362.637 +     * simply concatenate the arrays and sort the resulting array.
 362.638 +     *
 362.639 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
 362.640 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
 362.641 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
 362.642 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
 362.643 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
 362.644 +     * January 1993.
 362.645 +     *
 362.646 +     * @param a the array to be sorted
 362.647 +     * @param c the comparator to determine the order of the array.  A
 362.648 +     *        {@code null} value indicates that the elements'
 362.649 +     *        {@linkplain Comparable natural ordering} should be used.
 362.650 +     * @throws ClassCastException if the array contains elements that are
 362.651 +     *         not <i>mutually comparable</i> using the specified comparator
 362.652 +     * @throws IllegalArgumentException (optional) if the comparator is
 362.653 +     *         found to violate the {@link Comparator} contract
 362.654 +     */
 362.655 +    public static <T> void sort(T[] a, Comparator<? super T> c) {
 362.656 +        if (LegacyMergeSort.userRequested)
 362.657 +            legacyMergeSort(a, c);
 362.658 +        else
 362.659 +            TimSort.sort(a, c);
 362.660 +    }
 362.661 +
 362.662 +    /** To be removed in a future release. */
 362.663 +    private static <T> void legacyMergeSort(T[] a, Comparator<? super T> c) {
 362.664 +        T[] aux = a.clone();
 362.665 +        if (c==null)
 362.666 +            mergeSort(aux, a, 0, a.length, 0);
 362.667 +        else
 362.668 +            mergeSort(aux, a, 0, a.length, 0, c);
 362.669 +    }
 362.670 +
 362.671 +    /**
 362.672 +     * Sorts the specified range of the specified array of objects according
 362.673 +     * to the order induced by the specified comparator.  The range to be
 362.674 +     * sorted extends from index {@code fromIndex}, inclusive, to index
 362.675 +     * {@code toIndex}, exclusive.  (If {@code fromIndex==toIndex}, the
 362.676 +     * range to be sorted is empty.)  All elements in the range must be
 362.677 +     * <i>mutually comparable</i> by the specified comparator (that is,
 362.678 +     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
 362.679 +     * for any elements {@code e1} and {@code e2} in the range).
 362.680 +     *
 362.681 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
 362.682 +     * not be reordered as a result of the sort.
 362.683 +     *
 362.684 +     * <p>Implementation note: This implementation is a stable, adaptive,
 362.685 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
 362.686 +     * when the input array is partially sorted, while offering the
 362.687 +     * performance of a traditional mergesort when the input array is
 362.688 +     * randomly ordered.  If the input array is nearly sorted, the
 362.689 +     * implementation requires approximately n comparisons.  Temporary
 362.690 +     * storage requirements vary from a small constant for nearly sorted
 362.691 +     * input arrays to n/2 object references for randomly ordered input
 362.692 +     * arrays.
 362.693 +     *
 362.694 +     * <p>The implementation takes equal advantage of ascending and
 362.695 +     * descending order in its input array, and can take advantage of
 362.696 +     * ascending and descending order in different parts of the the same
 362.697 +     * input array.  It is well-suited to merging two or more sorted arrays:
 362.698 +     * simply concatenate the arrays and sort the resulting array.
 362.699 +     *
 362.700 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
 362.701 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
 362.702 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
 362.703 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
 362.704 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
 362.705 +     * January 1993.
 362.706 +     *
 362.707 +     * @param a the array to be sorted
 362.708 +     * @param fromIndex the index of the first element (inclusive) to be
 362.709 +     *        sorted
 362.710 +     * @param toIndex the index of the last element (exclusive) to be sorted
 362.711 +     * @param c the comparator to determine the order of the array.  A
 362.712 +     *        {@code null} value indicates that the elements'
 362.713 +     *        {@linkplain Comparable natural ordering} should be used.
 362.714 +     * @throws ClassCastException if the array contains elements that are not
 362.715 +     *         <i>mutually comparable</i> using the specified comparator.
 362.716 +     * @throws IllegalArgumentException if {@code fromIndex > toIndex} or
 362.717 +     *         (optional) if the comparator is found to violate the
 362.718 +     *         {@link Comparator} contract
 362.719 +     * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
 362.720 +     *         {@code toIndex > a.length}
 362.721 +     */
 362.722 +    public static <T> void sort(T[] a, int fromIndex, int toIndex,
 362.723 +                                Comparator<? super T> c) {
 362.724 +        if (LegacyMergeSort.userRequested)
 362.725 +            legacyMergeSort(a, fromIndex, toIndex, c);
 362.726 +        else
 362.727 +            TimSort.sort(a, fromIndex, toIndex, c);
 362.728 +    }
 362.729 +
 362.730 +    /** To be removed in a future release. */
 362.731 +    private static <T> void legacyMergeSort(T[] a, int fromIndex, int toIndex,
 362.732 +                                            Comparator<? super T> c) {
 362.733 +        rangeCheck(a.length, fromIndex, toIndex);
 362.734 +        T[] aux = copyOfRange(a, fromIndex, toIndex);
 362.735 +        if (c==null)
 362.736 +            mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
 362.737 +        else
 362.738 +            mergeSort(aux, a, fromIndex, toIndex, -fromIndex, c);
 362.739 +    }
 362.740 +
 362.741 +    /**
 362.742 +     * Src is the source array that starts at index 0
 362.743 +     * Dest is the (possibly larger) array destination with a possible offset
 362.744 +     * low is the index in dest to start sorting
 362.745 +     * high is the end index in dest to end sorting
 362.746 +     * off is the offset into src corresponding to low in dest
 362.747 +     * To be removed in a future release.
 362.748 +     */
 362.749 +    private static void mergeSort(Object[] src,
 362.750 +                                  Object[] dest,
 362.751 +                                  int low, int high, int off,
 362.752 +                                  Comparator c) {
 362.753 +        int length = high - low;
 362.754 +
 362.755 +        // Insertion sort on smallest arrays
 362.756 +        if (length < INSERTIONSORT_THRESHOLD) {
 362.757 +            for (int i=low; i<high; i++)
 362.758 +                for (int j=i; j>low && c.compare(dest[j-1], dest[j])>0; j--)
 362.759 +                    swap(dest, j, j-1);
 362.760 +            return;
 362.761 +        }
 362.762 +
 362.763 +        // Recursively sort halves of dest into src
 362.764 +        int destLow  = low;
 362.765 +        int destHigh = high;
 362.766 +        low  += off;
 362.767 +        high += off;
 362.768 +        int mid = (low + high) >>> 1;
 362.769 +        mergeSort(dest, src, low, mid, -off, c);
 362.770 +        mergeSort(dest, src, mid, high, -off, c);
 362.771 +
 362.772 +        // If list is already sorted, just copy from src to dest.  This is an
 362.773 +        // optimization that results in faster sorts for nearly ordered lists.
 362.774 +        if (c.compare(src[mid-1], src[mid]) <= 0) {
 362.775 +           System.arraycopy(src, low, dest, destLow, length);
 362.776 +           return;
 362.777 +        }
 362.778 +
 362.779 +        // Merge sorted halves (now in src) into dest
 362.780 +        for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
 362.781 +            if (q >= high || p < mid && c.compare(src[p], src[q]) <= 0)
 362.782 +                dest[i] = src[p++];
 362.783 +            else
 362.784 +                dest[i] = src[q++];
 362.785 +        }
 362.786 +    }
 362.787 +
 362.788 +    /**
 362.789 +     * Checks that {@code fromIndex} and {@code toIndex} are in
 362.790 +     * the range and throws an appropriate exception, if they aren't.
 362.791 +     */
 362.792 +    private static void rangeCheck(int length, int fromIndex, int toIndex) {
 362.793 +        if (fromIndex > toIndex) {
 362.794 +            throw new IllegalArgumentException(
 362.795 +                "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
 362.796 +        }
 362.797 +        if (fromIndex < 0) {
 362.798 +            throw new ArrayIndexOutOfBoundsException(fromIndex);
 362.799 +        }
 362.800 +        if (toIndex > length) {
 362.801 +            throw new ArrayIndexOutOfBoundsException(toIndex);
 362.802 +        }
 362.803 +    }
 362.804 +
 362.805 +    // Searching
 362.806 +
 362.807 +    /**
 362.808 +     * Searches the specified array of longs for the specified value using the
 362.809 +     * binary search algorithm.  The array must be sorted (as
 362.810 +     * by the {@link #sort(long[])} method) prior to making this call.  If it
 362.811 +     * is not sorted, the results are undefined.  If the array contains
 362.812 +     * multiple elements with the specified value, there is no guarantee which
 362.813 +     * one will be found.
 362.814 +     *
 362.815 +     * @param a the array to be searched
 362.816 +     * @param key the value to be searched for
 362.817 +     * @return index of the search key, if it is contained in the array;
 362.818 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 362.819 +     *         <i>insertion point</i> is defined as the point at which the
 362.820 +     *         key would be inserted into the array: the index of the first
 362.821 +     *         element greater than the key, or <tt>a.length</tt> if all
 362.822 +     *         elements in the array are less than the specified key.  Note
 362.823 +     *         that this guarantees that the return value will be &gt;= 0 if
 362.824 +     *         and only if the key is found.
 362.825 +     */
 362.826 +    public static int binarySearch(long[] a, long key) {
 362.827 +        return binarySearch0(a, 0, a.length, key);
 362.828 +    }
 362.829 +
 362.830 +    /**
 362.831 +     * Searches a range of
 362.832 +     * the specified array of longs for the specified value using the
 362.833 +     * binary search algorithm.
 362.834 +     * The range must be sorted (as
 362.835 +     * by the {@link #sort(long[], int, int)} method)
 362.836 +     * prior to making this call.  If it
 362.837 +     * is not sorted, the results are undefined.  If the range contains
 362.838 +     * multiple elements with the specified value, there is no guarantee which
 362.839 +     * one will be found.
 362.840 +     *
 362.841 +     * @param a the array to be searched
 362.842 +     * @param fromIndex the index of the first element (inclusive) to be
 362.843 +     *          searched
 362.844 +     * @param toIndex the index of the last element (exclusive) to be searched
 362.845 +     * @param key the value to be searched for
 362.846 +     * @return index of the search key, if it is contained in the array
 362.847 +     *         within the specified range;
 362.848 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 362.849 +     *         <i>insertion point</i> is defined as the point at which the
 362.850 +     *         key would be inserted into the array: the index of the first
 362.851 +     *         element in the range greater than the key,
 362.852 +     *         or <tt>toIndex</tt> if all
 362.853 +     *         elements in the range are less than the specified key.  Note
 362.854 +     *         that this guarantees that the return value will be &gt;= 0 if
 362.855 +     *         and only if the key is found.
 362.856 +     * @throws IllegalArgumentException
 362.857 +     *         if {@code fromIndex > toIndex}
 362.858 +     * @throws ArrayIndexOutOfBoundsException
 362.859 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 362.860 +     * @since 1.6
 362.861 +     */
 362.862 +    public static int binarySearch(long[] a, int fromIndex, int toIndex,
 362.863 +                                   long key) {
 362.864 +        rangeCheck(a.length, fromIndex, toIndex);
 362.865 +        return binarySearch0(a, fromIndex, toIndex, key);
 362.866 +    }
 362.867 +
 362.868 +    // Like public version, but without range checks.
 362.869 +    private static int binarySearch0(long[] a, int fromIndex, int toIndex,
 362.870 +                                     long key) {
 362.871 +        int low = fromIndex;
 362.872 +        int high = toIndex - 1;
 362.873 +
 362.874 +        while (low <= high) {
 362.875 +            int mid = (low + high) >>> 1;
 362.876 +            long midVal = a[mid];
 362.877 +
 362.878 +            if (midVal < key)
 362.879 +                low = mid + 1;
 362.880 +            else if (midVal > key)
 362.881 +                high = mid - 1;
 362.882 +            else
 362.883 +                return mid; // key found
 362.884 +        }
 362.885 +        return -(low + 1);  // key not found.
 362.886 +    }
 362.887 +
 362.888 +    /**
 362.889 +     * Searches the specified array of ints for the specified value using the
 362.890 +     * binary search algorithm.  The array must be sorted (as
 362.891 +     * by the {@link #sort(int[])} method) prior to making this call.  If it
 362.892 +     * is not sorted, the results are undefined.  If the array contains
 362.893 +     * multiple elements with the specified value, there is no guarantee which
 362.894 +     * one will be found.
 362.895 +     *
 362.896 +     * @param a the array to be searched
 362.897 +     * @param key the value to be searched for
 362.898 +     * @return index of the search key, if it is contained in the array;
 362.899 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 362.900 +     *         <i>insertion point</i> is defined as the point at which the
 362.901 +     *         key would be inserted into the array: the index of the first
 362.902 +     *         element greater than the key, or <tt>a.length</tt> if all
 362.903 +     *         elements in the array are less than the specified key.  Note
 362.904 +     *         that this guarantees that the return value will be &gt;= 0 if
 362.905 +     *         and only if the key is found.
 362.906 +     */
 362.907 +    public static int binarySearch(int[] a, int key) {
 362.908 +        return binarySearch0(a, 0, a.length, key);
 362.909 +    }
 362.910 +
 362.911 +    /**
 362.912 +     * Searches a range of
 362.913 +     * the specified array of ints for the specified value using the
 362.914 +     * binary search algorithm.
 362.915 +     * The range must be sorted (as
 362.916 +     * by the {@link #sort(int[], int, int)} method)
 362.917 +     * prior to making this call.  If it
 362.918 +     * is not sorted, the results are undefined.  If the range contains
 362.919 +     * multiple elements with the specified value, there is no guarantee which
 362.920 +     * one will be found.
 362.921 +     *
 362.922 +     * @param a the array to be searched
 362.923 +     * @param fromIndex the index of the first element (inclusive) to be
 362.924 +     *          searched
 362.925 +     * @param toIndex the index of the last element (exclusive) to be searched
 362.926 +     * @param key the value to be searched for
 362.927 +     * @return index of the search key, if it is contained in the array
 362.928 +     *         within the specified range;
 362.929 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 362.930 +     *         <i>insertion point</i> is defined as the point at which the
 362.931 +     *         key would be inserted into the array: the index of the first
 362.932 +     *         element in the range greater than the key,
 362.933 +     *         or <tt>toIndex</tt> if all
 362.934 +     *         elements in the range are less than the specified key.  Note
 362.935 +     *         that this guarantees that the return value will be &gt;= 0 if
 362.936 +     *         and only if the key is found.
 362.937 +     * @throws IllegalArgumentException
 362.938 +     *         if {@code fromIndex > toIndex}
 362.939 +     * @throws ArrayIndexOutOfBoundsException
 362.940 +     *         if {@code fromIndex < 0 or toIndex > a.length}
 362.941 +     * @since 1.6
 362.942 +     */
 362.943 +    public static int binarySearch(int[] a, int fromIndex, int toIndex,
 362.944 +                                   int key) {
 362.945 +        rangeCheck(a.length, fromIndex, toIndex);
 362.946 +        return binarySearch0(a, fromIndex, toIndex, key);
 362.947 +    }
 362.948 +
 362.949 +    // Like public version, but without range checks.
 362.950 +    private static int binarySearch0(int[] a, int fromIndex, int toIndex,
 362.951 +                                     int key) {
 362.952 +        int low = fromIndex;
 362.953 +        int high = toIndex - 1;
 362.954 +
 362.955 +        while (low <= high) {
 362.956 +            int mid = (low + high) >>> 1;
 362.957 +            int midVal = a[mid];
 362.958 +
 362.959 +            if (midVal < key)
 362.960 +                low = mid + 1;
 362.961 +            else if (midVal > key)
 362.962 +                high = mid - 1;
 362.963 +            else
 362.964 +                return mid; // key found
 362.965 +        }
 362.966 +        return -(low + 1);  // key not found.
 362.967 +    }
 362.968 +
 362.969 +    /**
 362.970 +     * Searches the specified array of shorts for the specified value using
 362.971 +     * the binary search algorithm.  The array must be sorted
 362.972 +     * (as by the {@link #sort(short[])} method) prior to making this call.  If
 362.973 +     * it is not sorted, the results are undefined.  If the array contains
 362.974 +     * multiple elements with the specified value, there is no guarantee which
 362.975 +     * one will be found.
 362.976 +     *
 362.977 +     * @param a the array to be searched
 362.978 +     * @param key the value to be searched for
 362.979 +     * @return index of the search key, if it is contained in the array;
 362.980 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 362.981 +     *         <i>insertion point</i> is defined as the point at which the
 362.982 +     *         key would be inserted into the array: the index of the first
 362.983 +     *         element greater than the key, or <tt>a.length</tt> if all
 362.984 +     *         elements in the array are less than the specified key.  Note
 362.985 +     *         that this guarantees that the return value will be &gt;= 0 if
 362.986 +     *         and only if the key is found.
 362.987 +     */
 362.988 +    public static int binarySearch(short[] a, short key) {
 362.989 +        return binarySearch0(a, 0, a.length, key);
 362.990 +    }
 362.991 +
 362.992 +    /**
 362.993 +     * Searches a range of
 362.994 +     * the specified array of shorts for the specified value using
 362.995 +     * the binary search algorithm.
 362.996 +     * The range must be sorted
 362.997 +     * (as by the {@link #sort(short[], int, int)} method)
 362.998 +     * prior to making this call.  If
 362.999 +     * it is not sorted, the results are undefined.  If the range contains
362.1000 +     * multiple elements with the specified value, there is no guarantee which
362.1001 +     * one will be found.
362.1002 +     *
362.1003 +     * @param a the array to be searched
362.1004 +     * @param fromIndex the index of the first element (inclusive) to be
362.1005 +     *          searched
362.1006 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1007 +     * @param key the value to be searched for
362.1008 +     * @return index of the search key, if it is contained in the array
362.1009 +     *         within the specified range;
362.1010 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1011 +     *         <i>insertion point</i> is defined as the point at which the
362.1012 +     *         key would be inserted into the array: the index of the first
362.1013 +     *         element in the range greater than the key,
362.1014 +     *         or <tt>toIndex</tt> if all
362.1015 +     *         elements in the range are less than the specified key.  Note
362.1016 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1017 +     *         and only if the key is found.
362.1018 +     * @throws IllegalArgumentException
362.1019 +     *         if {@code fromIndex > toIndex}
362.1020 +     * @throws ArrayIndexOutOfBoundsException
362.1021 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1022 +     * @since 1.6
362.1023 +     */
362.1024 +    public static int binarySearch(short[] a, int fromIndex, int toIndex,
362.1025 +                                   short key) {
362.1026 +        rangeCheck(a.length, fromIndex, toIndex);
362.1027 +        return binarySearch0(a, fromIndex, toIndex, key);
362.1028 +    }
362.1029 +
362.1030 +    // Like public version, but without range checks.
362.1031 +    private static int binarySearch0(short[] a, int fromIndex, int toIndex,
362.1032 +                                     short key) {
362.1033 +        int low = fromIndex;
362.1034 +        int high = toIndex - 1;
362.1035 +
362.1036 +        while (low <= high) {
362.1037 +            int mid = (low + high) >>> 1;
362.1038 +            short midVal = a[mid];
362.1039 +
362.1040 +            if (midVal < key)
362.1041 +                low = mid + 1;
362.1042 +            else if (midVal > key)
362.1043 +                high = mid - 1;
362.1044 +            else
362.1045 +                return mid; // key found
362.1046 +        }
362.1047 +        return -(low + 1);  // key not found.
362.1048 +    }
362.1049 +
362.1050 +    /**
362.1051 +     * Searches the specified array of chars for the specified value using the
362.1052 +     * binary search algorithm.  The array must be sorted (as
362.1053 +     * by the {@link #sort(char[])} method) prior to making this call.  If it
362.1054 +     * is not sorted, the results are undefined.  If the array contains
362.1055 +     * multiple elements with the specified value, there is no guarantee which
362.1056 +     * one will be found.
362.1057 +     *
362.1058 +     * @param a the array to be searched
362.1059 +     * @param key the value to be searched for
362.1060 +     * @return index of the search key, if it is contained in the array;
362.1061 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1062 +     *         <i>insertion point</i> is defined as the point at which the
362.1063 +     *         key would be inserted into the array: the index of the first
362.1064 +     *         element greater than the key, or <tt>a.length</tt> if all
362.1065 +     *         elements in the array are less than the specified key.  Note
362.1066 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1067 +     *         and only if the key is found.
362.1068 +     */
362.1069 +    public static int binarySearch(char[] a, char key) {
362.1070 +        return binarySearch0(a, 0, a.length, key);
362.1071 +    }
362.1072 +
362.1073 +    /**
362.1074 +     * Searches a range of
362.1075 +     * the specified array of chars for the specified value using the
362.1076 +     * binary search algorithm.
362.1077 +     * The range must be sorted (as
362.1078 +     * by the {@link #sort(char[], int, int)} method)
362.1079 +     * prior to making this call.  If it
362.1080 +     * is not sorted, the results are undefined.  If the range contains
362.1081 +     * multiple elements with the specified value, there is no guarantee which
362.1082 +     * one will be found.
362.1083 +     *
362.1084 +     * @param a the array to be searched
362.1085 +     * @param fromIndex the index of the first element (inclusive) to be
362.1086 +     *          searched
362.1087 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1088 +     * @param key the value to be searched for
362.1089 +     * @return index of the search key, if it is contained in the array
362.1090 +     *         within the specified range;
362.1091 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1092 +     *         <i>insertion point</i> is defined as the point at which the
362.1093 +     *         key would be inserted into the array: the index of the first
362.1094 +     *         element in the range greater than the key,
362.1095 +     *         or <tt>toIndex</tt> if all
362.1096 +     *         elements in the range are less than the specified key.  Note
362.1097 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1098 +     *         and only if the key is found.
362.1099 +     * @throws IllegalArgumentException
362.1100 +     *         if {@code fromIndex > toIndex}
362.1101 +     * @throws ArrayIndexOutOfBoundsException
362.1102 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1103 +     * @since 1.6
362.1104 +     */
362.1105 +    public static int binarySearch(char[] a, int fromIndex, int toIndex,
362.1106 +                                   char key) {
362.1107 +        rangeCheck(a.length, fromIndex, toIndex);
362.1108 +        return binarySearch0(a, fromIndex, toIndex, key);
362.1109 +    }
362.1110 +
362.1111 +    // Like public version, but without range checks.
362.1112 +    private static int binarySearch0(char[] a, int fromIndex, int toIndex,
362.1113 +                                     char key) {
362.1114 +        int low = fromIndex;
362.1115 +        int high = toIndex - 1;
362.1116 +
362.1117 +        while (low <= high) {
362.1118 +            int mid = (low + high) >>> 1;
362.1119 +            char midVal = a[mid];
362.1120 +
362.1121 +            if (midVal < key)
362.1122 +                low = mid + 1;
362.1123 +            else if (midVal > key)
362.1124 +                high = mid - 1;
362.1125 +            else
362.1126 +                return mid; // key found
362.1127 +        }
362.1128 +        return -(low + 1);  // key not found.
362.1129 +    }
362.1130 +
362.1131 +    /**
362.1132 +     * Searches the specified array of bytes for the specified value using the
362.1133 +     * binary search algorithm.  The array must be sorted (as
362.1134 +     * by the {@link #sort(byte[])} method) prior to making this call.  If it
362.1135 +     * is not sorted, the results are undefined.  If the array contains
362.1136 +     * multiple elements with the specified value, there is no guarantee which
362.1137 +     * one will be found.
362.1138 +     *
362.1139 +     * @param a the array to be searched
362.1140 +     * @param key the value to be searched for
362.1141 +     * @return index of the search key, if it is contained in the array;
362.1142 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1143 +     *         <i>insertion point</i> is defined as the point at which the
362.1144 +     *         key would be inserted into the array: the index of the first
362.1145 +     *         element greater than the key, or <tt>a.length</tt> if all
362.1146 +     *         elements in the array are less than the specified key.  Note
362.1147 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1148 +     *         and only if the key is found.
362.1149 +     */
362.1150 +    public static int binarySearch(byte[] a, byte key) {
362.1151 +        return binarySearch0(a, 0, a.length, key);
362.1152 +    }
362.1153 +
362.1154 +    /**
362.1155 +     * Searches a range of
362.1156 +     * the specified array of bytes for the specified value using the
362.1157 +     * binary search algorithm.
362.1158 +     * The range must be sorted (as
362.1159 +     * by the {@link #sort(byte[], int, int)} method)
362.1160 +     * prior to making this call.  If it
362.1161 +     * is not sorted, the results are undefined.  If the range contains
362.1162 +     * multiple elements with the specified value, there is no guarantee which
362.1163 +     * one will be found.
362.1164 +     *
362.1165 +     * @param a the array to be searched
362.1166 +     * @param fromIndex the index of the first element (inclusive) to be
362.1167 +     *          searched
362.1168 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1169 +     * @param key the value to be searched for
362.1170 +     * @return index of the search key, if it is contained in the array
362.1171 +     *         within the specified range;
362.1172 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1173 +     *         <i>insertion point</i> is defined as the point at which the
362.1174 +     *         key would be inserted into the array: the index of the first
362.1175 +     *         element in the range greater than the key,
362.1176 +     *         or <tt>toIndex</tt> if all
362.1177 +     *         elements in the range are less than the specified key.  Note
362.1178 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1179 +     *         and only if the key is found.
362.1180 +     * @throws IllegalArgumentException
362.1181 +     *         if {@code fromIndex > toIndex}
362.1182 +     * @throws ArrayIndexOutOfBoundsException
362.1183 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1184 +     * @since 1.6
362.1185 +     */
362.1186 +    public static int binarySearch(byte[] a, int fromIndex, int toIndex,
362.1187 +                                   byte key) {
362.1188 +        rangeCheck(a.length, fromIndex, toIndex);
362.1189 +        return binarySearch0(a, fromIndex, toIndex, key);
362.1190 +    }
362.1191 +
362.1192 +    // Like public version, but without range checks.
362.1193 +    private static int binarySearch0(byte[] a, int fromIndex, int toIndex,
362.1194 +                                     byte key) {
362.1195 +        int low = fromIndex;
362.1196 +        int high = toIndex - 1;
362.1197 +
362.1198 +        while (low <= high) {
362.1199 +            int mid = (low + high) >>> 1;
362.1200 +            byte midVal = a[mid];
362.1201 +
362.1202 +            if (midVal < key)
362.1203 +                low = mid + 1;
362.1204 +            else if (midVal > key)
362.1205 +                high = mid - 1;
362.1206 +            else
362.1207 +                return mid; // key found
362.1208 +        }
362.1209 +        return -(low + 1);  // key not found.
362.1210 +    }
362.1211 +
362.1212 +    /**
362.1213 +     * Searches the specified array of doubles for the specified value using
362.1214 +     * the binary search algorithm.  The array must be sorted
362.1215 +     * (as by the {@link #sort(double[])} method) prior to making this call.
362.1216 +     * If it is not sorted, the results are undefined.  If the array contains
362.1217 +     * multiple elements with the specified value, there is no guarantee which
362.1218 +     * one will be found.  This method considers all NaN values to be
362.1219 +     * equivalent and equal.
362.1220 +     *
362.1221 +     * @param a the array to be searched
362.1222 +     * @param key the value to be searched for
362.1223 +     * @return index of the search key, if it is contained in the array;
362.1224 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1225 +     *         <i>insertion point</i> is defined as the point at which the
362.1226 +     *         key would be inserted into the array: the index of the first
362.1227 +     *         element greater than the key, or <tt>a.length</tt> if all
362.1228 +     *         elements in the array are less than the specified key.  Note
362.1229 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1230 +     *         and only if the key is found.
362.1231 +     */
362.1232 +    public static int binarySearch(double[] a, double key) {
362.1233 +        return binarySearch0(a, 0, a.length, key);
362.1234 +    }
362.1235 +
362.1236 +    /**
362.1237 +     * Searches a range of
362.1238 +     * the specified array of doubles for the specified value using
362.1239 +     * the binary search algorithm.
362.1240 +     * The range must be sorted
362.1241 +     * (as by the {@link #sort(double[], int, int)} method)
362.1242 +     * prior to making this call.
362.1243 +     * If it is not sorted, the results are undefined.  If the range contains
362.1244 +     * multiple elements with the specified value, there is no guarantee which
362.1245 +     * one will be found.  This method considers all NaN values to be
362.1246 +     * equivalent and equal.
362.1247 +     *
362.1248 +     * @param a the array to be searched
362.1249 +     * @param fromIndex the index of the first element (inclusive) to be
362.1250 +     *          searched
362.1251 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1252 +     * @param key the value to be searched for
362.1253 +     * @return index of the search key, if it is contained in the array
362.1254 +     *         within the specified range;
362.1255 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1256 +     *         <i>insertion point</i> is defined as the point at which the
362.1257 +     *         key would be inserted into the array: the index of the first
362.1258 +     *         element in the range greater than the key,
362.1259 +     *         or <tt>toIndex</tt> if all
362.1260 +     *         elements in the range are less than the specified key.  Note
362.1261 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1262 +     *         and only if the key is found.
362.1263 +     * @throws IllegalArgumentException
362.1264 +     *         if {@code fromIndex > toIndex}
362.1265 +     * @throws ArrayIndexOutOfBoundsException
362.1266 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1267 +     * @since 1.6
362.1268 +     */
362.1269 +    public static int binarySearch(double[] a, int fromIndex, int toIndex,
362.1270 +                                   double key) {
362.1271 +        rangeCheck(a.length, fromIndex, toIndex);
362.1272 +        return binarySearch0(a, fromIndex, toIndex, key);
362.1273 +    }
362.1274 +
362.1275 +    // Like public version, but without range checks.
362.1276 +    private static int binarySearch0(double[] a, int fromIndex, int toIndex,
362.1277 +                                     double key) {
362.1278 +        int low = fromIndex;
362.1279 +        int high = toIndex - 1;
362.1280 +
362.1281 +        while (low <= high) {
362.1282 +            int mid = (low + high) >>> 1;
362.1283 +            double midVal = a[mid];
362.1284 +
362.1285 +            if (midVal < key)
362.1286 +                low = mid + 1;  // Neither val is NaN, thisVal is smaller
362.1287 +            else if (midVal > key)
362.1288 +                high = mid - 1; // Neither val is NaN, thisVal is larger
362.1289 +            else {
362.1290 +                long midBits = Double.doubleToLongBits(midVal);
362.1291 +                long keyBits = Double.doubleToLongBits(key);
362.1292 +                if (midBits == keyBits)     // Values are equal
362.1293 +                    return mid;             // Key found
362.1294 +                else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
362.1295 +                    low = mid + 1;
362.1296 +                else                        // (0.0, -0.0) or (NaN, !NaN)
362.1297 +                    high = mid - 1;
362.1298 +            }
362.1299 +        }
362.1300 +        return -(low + 1);  // key not found.
362.1301 +    }
362.1302 +
362.1303 +    /**
362.1304 +     * Searches the specified array of floats for the specified value using
362.1305 +     * the binary search algorithm. The array must be sorted
362.1306 +     * (as by the {@link #sort(float[])} method) prior to making this call. If
362.1307 +     * it is not sorted, the results are undefined. If the array contains
362.1308 +     * multiple elements with the specified value, there is no guarantee which
362.1309 +     * one will be found. This method considers all NaN values to be
362.1310 +     * equivalent and equal.
362.1311 +     *
362.1312 +     * @param a the array to be searched
362.1313 +     * @param key the value to be searched for
362.1314 +     * @return index of the search key, if it is contained in the array;
362.1315 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The
362.1316 +     *         <i>insertion point</i> is defined as the point at which the
362.1317 +     *         key would be inserted into the array: the index of the first
362.1318 +     *         element greater than the key, or <tt>a.length</tt> if all
362.1319 +     *         elements in the array are less than the specified key. Note
362.1320 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1321 +     *         and only if the key is found.
362.1322 +     */
362.1323 +    public static int binarySearch(float[] a, float key) {
362.1324 +        return binarySearch0(a, 0, a.length, key);
362.1325 +    }
362.1326 +
362.1327 +    /**
362.1328 +     * Searches a range of
362.1329 +     * the specified array of floats for the specified value using
362.1330 +     * the binary search algorithm.
362.1331 +     * The range must be sorted
362.1332 +     * (as by the {@link #sort(float[], int, int)} method)
362.1333 +     * prior to making this call. If
362.1334 +     * it is not sorted, the results are undefined. If the range contains
362.1335 +     * multiple elements with the specified value, there is no guarantee which
362.1336 +     * one will be found. This method considers all NaN values to be
362.1337 +     * equivalent and equal.
362.1338 +     *
362.1339 +     * @param a the array to be searched
362.1340 +     * @param fromIndex the index of the first element (inclusive) to be
362.1341 +     *          searched
362.1342 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1343 +     * @param key the value to be searched for
362.1344 +     * @return index of the search key, if it is contained in the array
362.1345 +     *         within the specified range;
362.1346 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. The
362.1347 +     *         <i>insertion point</i> is defined as the point at which the
362.1348 +     *         key would be inserted into the array: the index of the first
362.1349 +     *         element in the range greater than the key,
362.1350 +     *         or <tt>toIndex</tt> if all
362.1351 +     *         elements in the range are less than the specified key. Note
362.1352 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1353 +     *         and only if the key is found.
362.1354 +     * @throws IllegalArgumentException
362.1355 +     *         if {@code fromIndex > toIndex}
362.1356 +     * @throws ArrayIndexOutOfBoundsException
362.1357 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1358 +     * @since 1.6
362.1359 +     */
362.1360 +    public static int binarySearch(float[] a, int fromIndex, int toIndex,
362.1361 +                                   float key) {
362.1362 +        rangeCheck(a.length, fromIndex, toIndex);
362.1363 +        return binarySearch0(a, fromIndex, toIndex, key);
362.1364 +    }
362.1365 +
362.1366 +    // Like public version, but without range checks.
362.1367 +    private static int binarySearch0(float[] a, int fromIndex, int toIndex,
362.1368 +                                     float key) {
362.1369 +        int low = fromIndex;
362.1370 +        int high = toIndex - 1;
362.1371 +
362.1372 +        while (low <= high) {
362.1373 +            int mid = (low + high) >>> 1;
362.1374 +            float midVal = a[mid];
362.1375 +
362.1376 +            if (midVal < key)
362.1377 +                low = mid + 1;  // Neither val is NaN, thisVal is smaller
362.1378 +            else if (midVal > key)
362.1379 +                high = mid - 1; // Neither val is NaN, thisVal is larger
362.1380 +            else {
362.1381 +                int midBits = Float.floatToIntBits(midVal);
362.1382 +                int keyBits = Float.floatToIntBits(key);
362.1383 +                if (midBits == keyBits)     // Values are equal
362.1384 +                    return mid;             // Key found
362.1385 +                else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
362.1386 +                    low = mid + 1;
362.1387 +                else                        // (0.0, -0.0) or (NaN, !NaN)
362.1388 +                    high = mid - 1;
362.1389 +            }
362.1390 +        }
362.1391 +        return -(low + 1);  // key not found.
362.1392 +    }
362.1393 +
362.1394 +    /**
362.1395 +     * Searches the specified array for the specified object using the binary
362.1396 +     * search algorithm. The array must be sorted into ascending order
362.1397 +     * according to the
362.1398 +     * {@linkplain Comparable natural ordering}
362.1399 +     * of its elements (as by the
362.1400 +     * {@link #sort(Object[])} method) prior to making this call.
362.1401 +     * If it is not sorted, the results are undefined.
362.1402 +     * (If the array contains elements that are not mutually comparable (for
362.1403 +     * example, strings and integers), it <i>cannot</i> be sorted according
362.1404 +     * to the natural ordering of its elements, hence results are undefined.)
362.1405 +     * If the array contains multiple
362.1406 +     * elements equal to the specified object, there is no guarantee which
362.1407 +     * one will be found.
362.1408 +     *
362.1409 +     * @param a the array to be searched
362.1410 +     * @param key the value to be searched for
362.1411 +     * @return index of the search key, if it is contained in the array;
362.1412 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1413 +     *         <i>insertion point</i> is defined as the point at which the
362.1414 +     *         key would be inserted into the array: the index of the first
362.1415 +     *         element greater than the key, or <tt>a.length</tt> if all
362.1416 +     *         elements in the array are less than the specified key.  Note
362.1417 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1418 +     *         and only if the key is found.
362.1419 +     * @throws ClassCastException if the search key is not comparable to the
362.1420 +     *         elements of the array.
362.1421 +     */
362.1422 +    public static int binarySearch(Object[] a, Object key) {
362.1423 +        return binarySearch0(a, 0, a.length, key);
362.1424 +    }
362.1425 +
362.1426 +    /**
362.1427 +     * Searches a range of
362.1428 +     * the specified array for the specified object using the binary
362.1429 +     * search algorithm.
362.1430 +     * The range must be sorted into ascending order
362.1431 +     * according to the
362.1432 +     * {@linkplain Comparable natural ordering}
362.1433 +     * of its elements (as by the
362.1434 +     * {@link #sort(Object[], int, int)} method) prior to making this
362.1435 +     * call.  If it is not sorted, the results are undefined.
362.1436 +     * (If the range contains elements that are not mutually comparable (for
362.1437 +     * example, strings and integers), it <i>cannot</i> be sorted according
362.1438 +     * to the natural ordering of its elements, hence results are undefined.)
362.1439 +     * If the range contains multiple
362.1440 +     * elements equal to the specified object, there is no guarantee which
362.1441 +     * one will be found.
362.1442 +     *
362.1443 +     * @param a the array to be searched
362.1444 +     * @param fromIndex the index of the first element (inclusive) to be
362.1445 +     *          searched
362.1446 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1447 +     * @param key the value to be searched for
362.1448 +     * @return index of the search key, if it is contained in the array
362.1449 +     *         within the specified range;
362.1450 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1451 +     *         <i>insertion point</i> is defined as the point at which the
362.1452 +     *         key would be inserted into the array: the index of the first
362.1453 +     *         element in the range greater than the key,
362.1454 +     *         or <tt>toIndex</tt> if all
362.1455 +     *         elements in the range are less than the specified key.  Note
362.1456 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1457 +     *         and only if the key is found.
362.1458 +     * @throws ClassCastException if the search key is not comparable to the
362.1459 +     *         elements of the array within the specified range.
362.1460 +     * @throws IllegalArgumentException
362.1461 +     *         if {@code fromIndex > toIndex}
362.1462 +     * @throws ArrayIndexOutOfBoundsException
362.1463 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1464 +     * @since 1.6
362.1465 +     */
362.1466 +    public static int binarySearch(Object[] a, int fromIndex, int toIndex,
362.1467 +                                   Object key) {
362.1468 +        rangeCheck(a.length, fromIndex, toIndex);
362.1469 +        return binarySearch0(a, fromIndex, toIndex, key);
362.1470 +    }
362.1471 +
362.1472 +    // Like public version, but without range checks.
362.1473 +    private static int binarySearch0(Object[] a, int fromIndex, int toIndex,
362.1474 +                                     Object key) {
362.1475 +        int low = fromIndex;
362.1476 +        int high = toIndex - 1;
362.1477 +
362.1478 +        while (low <= high) {
362.1479 +            int mid = (low + high) >>> 1;
362.1480 +            Comparable midVal = (Comparable)a[mid];
362.1481 +            int cmp = midVal.compareTo(key);
362.1482 +
362.1483 +            if (cmp < 0)
362.1484 +                low = mid + 1;
362.1485 +            else if (cmp > 0)
362.1486 +                high = mid - 1;
362.1487 +            else
362.1488 +                return mid; // key found
362.1489 +        }
362.1490 +        return -(low + 1);  // key not found.
362.1491 +    }
362.1492 +
362.1493 +    /**
362.1494 +     * Searches the specified array for the specified object using the binary
362.1495 +     * search algorithm.  The array must be sorted into ascending order
362.1496 +     * according to the specified comparator (as by the
362.1497 +     * {@link #sort(Object[], Comparator) sort(T[], Comparator)}
362.1498 +     * method) prior to making this call.  If it is
362.1499 +     * not sorted, the results are undefined.
362.1500 +     * If the array contains multiple
362.1501 +     * elements equal to the specified object, there is no guarantee which one
362.1502 +     * will be found.
362.1503 +     *
362.1504 +     * @param a the array to be searched
362.1505 +     * @param key the value to be searched for
362.1506 +     * @param c the comparator by which the array is ordered.  A
362.1507 +     *        <tt>null</tt> value indicates that the elements'
362.1508 +     *        {@linkplain Comparable natural ordering} should be used.
362.1509 +     * @return index of the search key, if it is contained in the array;
362.1510 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1511 +     *         <i>insertion point</i> is defined as the point at which the
362.1512 +     *         key would be inserted into the array: the index of the first
362.1513 +     *         element greater than the key, or <tt>a.length</tt> if all
362.1514 +     *         elements in the array are less than the specified key.  Note
362.1515 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1516 +     *         and only if the key is found.
362.1517 +     * @throws ClassCastException if the array contains elements that are not
362.1518 +     *         <i>mutually comparable</i> using the specified comparator,
362.1519 +     *         or the search key is not comparable to the
362.1520 +     *         elements of the array using this comparator.
362.1521 +     */
362.1522 +    public static <T> int binarySearch(T[] a, T key, Comparator<? super T> c) {
362.1523 +        return binarySearch0(a, 0, a.length, key, c);
362.1524 +    }
362.1525 +
362.1526 +    /**
362.1527 +     * Searches a range of
362.1528 +     * the specified array for the specified object using the binary
362.1529 +     * search algorithm.
362.1530 +     * The range must be sorted into ascending order
362.1531 +     * according to the specified comparator (as by the
362.1532 +     * {@link #sort(Object[], int, int, Comparator)
362.1533 +     * sort(T[], int, int, Comparator)}
362.1534 +     * method) prior to making this call.
362.1535 +     * If it is not sorted, the results are undefined.
362.1536 +     * If the range contains multiple elements equal to the specified object,
362.1537 +     * there is no guarantee which one will be found.
362.1538 +     *
362.1539 +     * @param a the array to be searched
362.1540 +     * @param fromIndex the index of the first element (inclusive) to be
362.1541 +     *          searched
362.1542 +     * @param toIndex the index of the last element (exclusive) to be searched
362.1543 +     * @param key the value to be searched for
362.1544 +     * @param c the comparator by which the array is ordered.  A
362.1545 +     *        <tt>null</tt> value indicates that the elements'
362.1546 +     *        {@linkplain Comparable natural ordering} should be used.
362.1547 +     * @return index of the search key, if it is contained in the array
362.1548 +     *         within the specified range;
362.1549 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
362.1550 +     *         <i>insertion point</i> is defined as the point at which the
362.1551 +     *         key would be inserted into the array: the index of the first
362.1552 +     *         element in the range greater than the key,
362.1553 +     *         or <tt>toIndex</tt> if all
362.1554 +     *         elements in the range are less than the specified key.  Note
362.1555 +     *         that this guarantees that the return value will be &gt;= 0 if
362.1556 +     *         and only if the key is found.
362.1557 +     * @throws ClassCastException if the range contains elements that are not
362.1558 +     *         <i>mutually comparable</i> using the specified comparator,
362.1559 +     *         or the search key is not comparable to the
362.1560 +     *         elements in the range using this comparator.
362.1561 +     * @throws IllegalArgumentException
362.1562 +     *         if {@code fromIndex > toIndex}
362.1563 +     * @throws ArrayIndexOutOfBoundsException
362.1564 +     *         if {@code fromIndex < 0 or toIndex > a.length}
362.1565 +     * @since 1.6
362.1566 +     */
362.1567 +    public static <T> int binarySearch(T[] a, int fromIndex, int toIndex,
362.1568 +                                       T key, Comparator<? super T> c) {
362.1569 +        rangeCheck(a.length, fromIndex, toIndex);
362.1570 +        return binarySearch0(a, fromIndex, toIndex, key, c);
362.1571 +    }
362.1572 +
362.1573 +    // Like public version, but without range checks.
362.1574 +    private static <T> int binarySearch0(T[] a, int fromIndex, int toIndex,
362.1575 +                                         T key, Comparator<? super T> c) {
362.1576 +        if (c == null) {
362.1577 +            return binarySearch0(a, fromIndex, toIndex, key);
362.1578 +        }
362.1579 +        int low = fromIndex;
362.1580 +        int high = toIndex - 1;
362.1581 +
362.1582 +        while (low <= high) {
362.1583 +            int mid = (low + high) >>> 1;
362.1584 +            T midVal = a[mid];
362.1585 +            int cmp = c.compare(midVal, key);
362.1586 +            if (cmp < 0)
362.1587 +                low = mid + 1;
362.1588 +            else if (cmp > 0)
362.1589 +                high = mid - 1;
362.1590 +            else
362.1591 +                return mid; // key found
362.1592 +        }
362.1593 +        return -(low + 1);  // key not found.
362.1594 +    }
362.1595 +
362.1596 +    // Equality Testing
362.1597 +
362.1598 +    /**
362.1599 +     * Returns <tt>true</tt> if the two specified arrays of longs are
362.1600 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1601 +     * arrays contain the same number of elements, and all corresponding pairs
362.1602 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1603 +     * are equal if they contain the same elements in the same order.  Also,
362.1604 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1605 +     *
362.1606 +     * @param a one array to be tested for equality
362.1607 +     * @param a2 the other array to be tested for equality
362.1608 +     * @return <tt>true</tt> if the two arrays are equal
362.1609 +     */
362.1610 +    public static boolean equals(long[] a, long[] a2) {
362.1611 +        if (a==a2)
362.1612 +            return true;
362.1613 +        if (a==null || a2==null)
362.1614 +            return false;
362.1615 +
362.1616 +        int length = a.length;
362.1617 +        if (a2.length != length)
362.1618 +            return false;
362.1619 +
362.1620 +        for (int i=0; i<length; i++)
362.1621 +            if (a[i] != a2[i])
362.1622 +                return false;
362.1623 +
362.1624 +        return true;
362.1625 +    }
362.1626 +
362.1627 +    /**
362.1628 +     * Returns <tt>true</tt> if the two specified arrays of ints are
362.1629 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1630 +     * arrays contain the same number of elements, and all corresponding pairs
362.1631 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1632 +     * are equal if they contain the same elements in the same order.  Also,
362.1633 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1634 +     *
362.1635 +     * @param a one array to be tested for equality
362.1636 +     * @param a2 the other array to be tested for equality
362.1637 +     * @return <tt>true</tt> if the two arrays are equal
362.1638 +     */
362.1639 +    public static boolean equals(int[] a, int[] a2) {
362.1640 +        if (a==a2)
362.1641 +            return true;
362.1642 +        if (a==null || a2==null)
362.1643 +            return false;
362.1644 +
362.1645 +        int length = a.length;
362.1646 +        if (a2.length != length)
362.1647 +            return false;
362.1648 +
362.1649 +        for (int i=0; i<length; i++)
362.1650 +            if (a[i] != a2[i])
362.1651 +                return false;
362.1652 +
362.1653 +        return true;
362.1654 +    }
362.1655 +
362.1656 +    /**
362.1657 +     * Returns <tt>true</tt> if the two specified arrays of shorts are
362.1658 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1659 +     * arrays contain the same number of elements, and all corresponding pairs
362.1660 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1661 +     * are equal if they contain the same elements in the same order.  Also,
362.1662 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1663 +     *
362.1664 +     * @param a one array to be tested for equality
362.1665 +     * @param a2 the other array to be tested for equality
362.1666 +     * @return <tt>true</tt> if the two arrays are equal
362.1667 +     */
362.1668 +    public static boolean equals(short[] a, short a2[]) {
362.1669 +        if (a==a2)
362.1670 +            return true;
362.1671 +        if (a==null || a2==null)
362.1672 +            return false;
362.1673 +
362.1674 +        int length = a.length;
362.1675 +        if (a2.length != length)
362.1676 +            return false;
362.1677 +
362.1678 +        for (int i=0; i<length; i++)
362.1679 +            if (a[i] != a2[i])
362.1680 +                return false;
362.1681 +
362.1682 +        return true;
362.1683 +    }
362.1684 +
362.1685 +    /**
362.1686 +     * Returns <tt>true</tt> if the two specified arrays of chars are
362.1687 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1688 +     * arrays contain the same number of elements, and all corresponding pairs
362.1689 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1690 +     * are equal if they contain the same elements in the same order.  Also,
362.1691 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1692 +     *
362.1693 +     * @param a one array to be tested for equality
362.1694 +     * @param a2 the other array to be tested for equality
362.1695 +     * @return <tt>true</tt> if the two arrays are equal
362.1696 +     */
362.1697 +    public static boolean equals(char[] a, char[] a2) {
362.1698 +        if (a==a2)
362.1699 +            return true;
362.1700 +        if (a==null || a2==null)
362.1701 +            return false;
362.1702 +
362.1703 +        int length = a.length;
362.1704 +        if (a2.length != length)
362.1705 +            return false;
362.1706 +
362.1707 +        for (int i=0; i<length; i++)
362.1708 +            if (a[i] != a2[i])
362.1709 +                return false;
362.1710 +
362.1711 +        return true;
362.1712 +    }
362.1713 +
362.1714 +    /**
362.1715 +     * Returns <tt>true</tt> if the two specified arrays of bytes are
362.1716 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1717 +     * arrays contain the same number of elements, and all corresponding pairs
362.1718 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1719 +     * are equal if they contain the same elements in the same order.  Also,
362.1720 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1721 +     *
362.1722 +     * @param a one array to be tested for equality
362.1723 +     * @param a2 the other array to be tested for equality
362.1724 +     * @return <tt>true</tt> if the two arrays are equal
362.1725 +     */
362.1726 +    public static boolean equals(byte[] a, byte[] a2) {
362.1727 +        if (a==a2)
362.1728 +            return true;
362.1729 +        if (a==null || a2==null)
362.1730 +            return false;
362.1731 +
362.1732 +        int length = a.length;
362.1733 +        if (a2.length != length)
362.1734 +            return false;
362.1735 +
362.1736 +        for (int i=0; i<length; i++)
362.1737 +            if (a[i] != a2[i])
362.1738 +                return false;
362.1739 +
362.1740 +        return true;
362.1741 +    }
362.1742 +
362.1743 +    /**
362.1744 +     * Returns <tt>true</tt> if the two specified arrays of booleans are
362.1745 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1746 +     * arrays contain the same number of elements, and all corresponding pairs
362.1747 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1748 +     * are equal if they contain the same elements in the same order.  Also,
362.1749 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1750 +     *
362.1751 +     * @param a one array to be tested for equality
362.1752 +     * @param a2 the other array to be tested for equality
362.1753 +     * @return <tt>true</tt> if the two arrays are equal
362.1754 +     */
362.1755 +    public static boolean equals(boolean[] a, boolean[] a2) {
362.1756 +        if (a==a2)
362.1757 +            return true;
362.1758 +        if (a==null || a2==null)
362.1759 +            return false;
362.1760 +
362.1761 +        int length = a.length;
362.1762 +        if (a2.length != length)
362.1763 +            return false;
362.1764 +
362.1765 +        for (int i=0; i<length; i++)
362.1766 +            if (a[i] != a2[i])
362.1767 +                return false;
362.1768 +
362.1769 +        return true;
362.1770 +    }
362.1771 +
362.1772 +    /**
362.1773 +     * Returns <tt>true</tt> if the two specified arrays of doubles are
362.1774 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1775 +     * arrays contain the same number of elements, and all corresponding pairs
362.1776 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1777 +     * are equal if they contain the same elements in the same order.  Also,
362.1778 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1779 +     *
362.1780 +     * Two doubles <tt>d1</tt> and <tt>d2</tt> are considered equal if:
362.1781 +     * <pre>    <tt>new Double(d1).equals(new Double(d2))</tt></pre>
362.1782 +     * (Unlike the <tt>==</tt> operator, this method considers
362.1783 +     * <tt>NaN</tt> equals to itself, and 0.0d unequal to -0.0d.)
362.1784 +     *
362.1785 +     * @param a one array to be tested for equality
362.1786 +     * @param a2 the other array to be tested for equality
362.1787 +     * @return <tt>true</tt> if the two arrays are equal
362.1788 +     * @see Double#equals(Object)
362.1789 +     */
362.1790 +    public static boolean equals(double[] a, double[] a2) {
362.1791 +        if (a==a2)
362.1792 +            return true;
362.1793 +        if (a==null || a2==null)
362.1794 +            return false;
362.1795 +
362.1796 +        int length = a.length;
362.1797 +        if (a2.length != length)
362.1798 +            return false;
362.1799 +
362.1800 +        for (int i=0; i<length; i++)
362.1801 +            if (Double.doubleToLongBits(a[i])!=Double.doubleToLongBits(a2[i]))
362.1802 +                return false;
362.1803 +
362.1804 +        return true;
362.1805 +    }
362.1806 +
362.1807 +    /**
362.1808 +     * Returns <tt>true</tt> if the two specified arrays of floats are
362.1809 +     * <i>equal</i> to one another.  Two arrays are considered equal if both
362.1810 +     * arrays contain the same number of elements, and all corresponding pairs
362.1811 +     * of elements in the two arrays are equal.  In other words, two arrays
362.1812 +     * are equal if they contain the same elements in the same order.  Also,
362.1813 +     * two array references are considered equal if both are <tt>null</tt>.<p>
362.1814 +     *
362.1815 +     * Two floats <tt>f1</tt> and <tt>f2</tt> are considered equal if:
362.1816 +     * <pre>    <tt>new Float(f1).equals(new Float(f2))</tt></pre>
362.1817 +     * (Unlike the <tt>==</tt> operator, this method considers
362.1818 +     * <tt>NaN</tt> equals to itself, and 0.0f unequal to -0.0f.)
362.1819 +     *
362.1820 +     * @param a one array to be tested for equality
362.1821 +     * @param a2 the other array to be tested for equality
362.1822 +     * @return <tt>true</tt> if the two arrays are equal
362.1823 +     * @see Float#equals(Object)
362.1824 +     */
362.1825 +    public static boolean equals(float[] a, float[] a2) {
362.1826 +        if (a==a2)
362.1827 +            return true;
362.1828 +        if (a==null || a2==null)
362.1829 +            return false;
362.1830 +
362.1831 +        int length = a.length;
362.1832 +        if (a2.length != length)
362.1833 +            return false;
362.1834 +
362.1835 +        for (int i=0; i<length; i++)
362.1836 +            if (Float.floatToIntBits(a[i])!=Float.floatToIntBits(a2[i]))
362.1837 +                return false;
362.1838 +
362.1839 +        return true;
362.1840 +    }
362.1841 +
362.1842 +    /**
362.1843 +     * Returns <tt>true</tt> if the two specified arrays of Objects are
362.1844 +     * <i>equal</i> to one another.  The two arrays are considered equal if
362.1845 +     * both arrays contain the same number of elements, and all corresponding
362.1846 +     * pairs of elements in the two arrays are equal.  Two objects <tt>e1</tt>
362.1847 +     * and <tt>e2</tt> are considered <i>equal</i> if <tt>(e1==null ? e2==null
362.1848 +     * : e1.equals(e2))</tt>.  In other words, the two arrays are equal if
362.1849 +     * they contain the same elements in the same order.  Also, two array
362.1850 +     * references are considered equal if both are <tt>null</tt>.<p>
362.1851 +     *
362.1852 +     * @param a one array to be tested for equality
362.1853 +     * @param a2 the other array to be tested for equality
362.1854 +     * @return <tt>true</tt> if the two arrays are equal
362.1855 +     */
362.1856 +    public static boolean equals(Object[] a, Object[] a2) {
362.1857 +        if (a==a2)
362.1858 +            return true;
362.1859 +        if (a==null || a2==null)
362.1860 +            return false;
362.1861 +
362.1862 +        int length = a.length;
362.1863 +        if (a2.length != length)
362.1864 +            return false;
362.1865 +
362.1866 +        for (int i=0; i<length; i++) {
362.1867 +            Object o1 = a[i];
362.1868 +            Object o2 = a2[i];
362.1869 +            if (!(o1==null ? o2==null : o1.equals(o2)))
362.1870 +                return false;
362.1871 +        }
362.1872 +
362.1873 +        return true;
362.1874 +    }
362.1875 +
362.1876 +    // Filling
362.1877 +
362.1878 +    /**
362.1879 +     * Assigns the specified long value to each element of the specified array
362.1880 +     * of longs.
362.1881 +     *
362.1882 +     * @param a the array to be filled
362.1883 +     * @param val the value to be stored in all elements of the array
362.1884 +     */
362.1885 +    public static void fill(long[] a, long val) {
362.1886 +        for (int i = 0, len = a.length; i < len; i++)
362.1887 +            a[i] = val;
362.1888 +    }
362.1889 +
362.1890 +    /**
362.1891 +     * Assigns the specified long value to each element of the specified
362.1892 +     * range of the specified array of longs.  The range to be filled
362.1893 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.1894 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.1895 +     * range to be filled is empty.)
362.1896 +     *
362.1897 +     * @param a the array to be filled
362.1898 +     * @param fromIndex the index of the first element (inclusive) to be
362.1899 +     *        filled with the specified value
362.1900 +     * @param toIndex the index of the last element (exclusive) to be
362.1901 +     *        filled with the specified value
362.1902 +     * @param val the value to be stored in all elements of the array
362.1903 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.1904 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.1905 +     *         <tt>toIndex &gt; a.length</tt>
362.1906 +     */
362.1907 +    public static void fill(long[] a, int fromIndex, int toIndex, long val) {
362.1908 +        rangeCheck(a.length, fromIndex, toIndex);
362.1909 +        for (int i = fromIndex; i < toIndex; i++)
362.1910 +            a[i] = val;
362.1911 +    }
362.1912 +
362.1913 +    /**
362.1914 +     * Assigns the specified int value to each element of the specified array
362.1915 +     * of ints.
362.1916 +     *
362.1917 +     * @param a the array to be filled
362.1918 +     * @param val the value to be stored in all elements of the array
362.1919 +     */
362.1920 +    public static void fill(int[] a, int val) {
362.1921 +        for (int i = 0, len = a.length; i < len; i++)
362.1922 +            a[i] = val;
362.1923 +    }
362.1924 +
362.1925 +    /**
362.1926 +     * Assigns the specified int value to each element of the specified
362.1927 +     * range of the specified array of ints.  The range to be filled
362.1928 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.1929 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.1930 +     * range to be filled is empty.)
362.1931 +     *
362.1932 +     * @param a the array to be filled
362.1933 +     * @param fromIndex the index of the first element (inclusive) to be
362.1934 +     *        filled with the specified value
362.1935 +     * @param toIndex the index of the last element (exclusive) to be
362.1936 +     *        filled with the specified value
362.1937 +     * @param val the value to be stored in all elements of the array
362.1938 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.1939 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.1940 +     *         <tt>toIndex &gt; a.length</tt>
362.1941 +     */
362.1942 +    public static void fill(int[] a, int fromIndex, int toIndex, int val) {
362.1943 +        rangeCheck(a.length, fromIndex, toIndex);
362.1944 +        for (int i = fromIndex; i < toIndex; i++)
362.1945 +            a[i] = val;
362.1946 +    }
362.1947 +
362.1948 +    /**
362.1949 +     * Assigns the specified short value to each element of the specified array
362.1950 +     * of shorts.
362.1951 +     *
362.1952 +     * @param a the array to be filled
362.1953 +     * @param val the value to be stored in all elements of the array
362.1954 +     */
362.1955 +    public static void fill(short[] a, short val) {
362.1956 +        for (int i = 0, len = a.length; i < len; i++)
362.1957 +            a[i] = val;
362.1958 +    }
362.1959 +
362.1960 +    /**
362.1961 +     * Assigns the specified short value to each element of the specified
362.1962 +     * range of the specified array of shorts.  The range to be filled
362.1963 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.1964 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.1965 +     * range to be filled is empty.)
362.1966 +     *
362.1967 +     * @param a the array to be filled
362.1968 +     * @param fromIndex the index of the first element (inclusive) to be
362.1969 +     *        filled with the specified value
362.1970 +     * @param toIndex the index of the last element (exclusive) to be
362.1971 +     *        filled with the specified value
362.1972 +     * @param val the value to be stored in all elements of the array
362.1973 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.1974 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.1975 +     *         <tt>toIndex &gt; a.length</tt>
362.1976 +     */
362.1977 +    public static void fill(short[] a, int fromIndex, int toIndex, short val) {
362.1978 +        rangeCheck(a.length, fromIndex, toIndex);
362.1979 +        for (int i = fromIndex; i < toIndex; i++)
362.1980 +            a[i] = val;
362.1981 +    }
362.1982 +
362.1983 +    /**
362.1984 +     * Assigns the specified char value to each element of the specified array
362.1985 +     * of chars.
362.1986 +     *
362.1987 +     * @param a the array to be filled
362.1988 +     * @param val the value to be stored in all elements of the array
362.1989 +     */
362.1990 +    public static void fill(char[] a, char val) {
362.1991 +        for (int i = 0, len = a.length; i < len; i++)
362.1992 +            a[i] = val;
362.1993 +    }
362.1994 +
362.1995 +    /**
362.1996 +     * Assigns the specified char value to each element of the specified
362.1997 +     * range of the specified array of chars.  The range to be filled
362.1998 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.1999 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.2000 +     * range to be filled is empty.)
362.2001 +     *
362.2002 +     * @param a the array to be filled
362.2003 +     * @param fromIndex the index of the first element (inclusive) to be
362.2004 +     *        filled with the specified value
362.2005 +     * @param toIndex the index of the last element (exclusive) to be
362.2006 +     *        filled with the specified value
362.2007 +     * @param val the value to be stored in all elements of the array
362.2008 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.2009 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.2010 +     *         <tt>toIndex &gt; a.length</tt>
362.2011 +     */
362.2012 +    public static void fill(char[] a, int fromIndex, int toIndex, char val) {
362.2013 +        rangeCheck(a.length, fromIndex, toIndex);
362.2014 +        for (int i = fromIndex; i < toIndex; i++)
362.2015 +            a[i] = val;
362.2016 +    }
362.2017 +
362.2018 +    /**
362.2019 +     * Assigns the specified byte value to each element of the specified array
362.2020 +     * of bytes.
362.2021 +     *
362.2022 +     * @param a the array to be filled
362.2023 +     * @param val the value to be stored in all elements of the array
362.2024 +     */
362.2025 +    public static void fill(byte[] a, byte val) {
362.2026 +        for (int i = 0, len = a.length; i < len; i++)
362.2027 +            a[i] = val;
362.2028 +    }
362.2029 +
362.2030 +    /**
362.2031 +     * Assigns the specified byte value to each element of the specified
362.2032 +     * range of the specified array of bytes.  The range to be filled
362.2033 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.2034 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.2035 +     * range to be filled is empty.)
362.2036 +     *
362.2037 +     * @param a the array to be filled
362.2038 +     * @param fromIndex the index of the first element (inclusive) to be
362.2039 +     *        filled with the specified value
362.2040 +     * @param toIndex the index of the last element (exclusive) to be
362.2041 +     *        filled with the specified value
362.2042 +     * @param val the value to be stored in all elements of the array
362.2043 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.2044 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.2045 +     *         <tt>toIndex &gt; a.length</tt>
362.2046 +     */
362.2047 +    public static void fill(byte[] a, int fromIndex, int toIndex, byte val) {
362.2048 +        rangeCheck(a.length, fromIndex, toIndex);
362.2049 +        for (int i = fromIndex; i < toIndex; i++)
362.2050 +            a[i] = val;
362.2051 +    }
362.2052 +
362.2053 +    /**
362.2054 +     * Assigns the specified boolean value to each element of the specified
362.2055 +     * array of booleans.
362.2056 +     *
362.2057 +     * @param a the array to be filled
362.2058 +     * @param val the value to be stored in all elements of the array
362.2059 +     */
362.2060 +    public static void fill(boolean[] a, boolean val) {
362.2061 +        for (int i = 0, len = a.length; i < len; i++)
362.2062 +            a[i] = val;
362.2063 +    }
362.2064 +
362.2065 +    /**
362.2066 +     * Assigns the specified boolean value to each element of the specified
362.2067 +     * range of the specified array of booleans.  The range to be filled
362.2068 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.2069 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.2070 +     * range to be filled is empty.)
362.2071 +     *
362.2072 +     * @param a the array to be filled
362.2073 +     * @param fromIndex the index of the first element (inclusive) to be
362.2074 +     *        filled with the specified value
362.2075 +     * @param toIndex the index of the last element (exclusive) to be
362.2076 +     *        filled with the specified value
362.2077 +     * @param val the value to be stored in all elements of the array
362.2078 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.2079 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.2080 +     *         <tt>toIndex &gt; a.length</tt>
362.2081 +     */
362.2082 +    public static void fill(boolean[] a, int fromIndex, int toIndex,
362.2083 +                            boolean val) {
362.2084 +        rangeCheck(a.length, fromIndex, toIndex);
362.2085 +        for (int i = fromIndex; i < toIndex; i++)
362.2086 +            a[i] = val;
362.2087 +    }
362.2088 +
362.2089 +    /**
362.2090 +     * Assigns the specified double value to each element of the specified
362.2091 +     * array of doubles.
362.2092 +     *
362.2093 +     * @param a the array to be filled
362.2094 +     * @param val the value to be stored in all elements of the array
362.2095 +     */
362.2096 +    public static void fill(double[] a, double val) {
362.2097 +        for (int i = 0, len = a.length; i < len; i++)
362.2098 +            a[i] = val;
362.2099 +    }
362.2100 +
362.2101 +    /**
362.2102 +     * Assigns the specified double value to each element of the specified
362.2103 +     * range of the specified array of doubles.  The range to be filled
362.2104 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.2105 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.2106 +     * range to be filled is empty.)
362.2107 +     *
362.2108 +     * @param a the array to be filled
362.2109 +     * @param fromIndex the index of the first element (inclusive) to be
362.2110 +     *        filled with the specified value
362.2111 +     * @param toIndex the index of the last element (exclusive) to be
362.2112 +     *        filled with the specified value
362.2113 +     * @param val the value to be stored in all elements of the array
362.2114 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.2115 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.2116 +     *         <tt>toIndex &gt; a.length</tt>
362.2117 +     */
362.2118 +    public static void fill(double[] a, int fromIndex, int toIndex,double val){
362.2119 +        rangeCheck(a.length, fromIndex, toIndex);
362.2120 +        for (int i = fromIndex; i < toIndex; i++)
362.2121 +            a[i] = val;
362.2122 +    }
362.2123 +
362.2124 +    /**
362.2125 +     * Assigns the specified float value to each element of the specified array
362.2126 +     * of floats.
362.2127 +     *
362.2128 +     * @param a the array to be filled
362.2129 +     * @param val the value to be stored in all elements of the array
362.2130 +     */
362.2131 +    public static void fill(float[] a, float val) {
362.2132 +        for (int i = 0, len = a.length; i < len; i++)
362.2133 +            a[i] = val;
362.2134 +    }
362.2135 +
362.2136 +    /**
362.2137 +     * Assigns the specified float value to each element of the specified
362.2138 +     * range of the specified array of floats.  The range to be filled
362.2139 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.2140 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.2141 +     * range to be filled is empty.)
362.2142 +     *
362.2143 +     * @param a the array to be filled
362.2144 +     * @param fromIndex the index of the first element (inclusive) to be
362.2145 +     *        filled with the specified value
362.2146 +     * @param toIndex the index of the last element (exclusive) to be
362.2147 +     *        filled with the specified value
362.2148 +     * @param val the value to be stored in all elements of the array
362.2149 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.2150 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.2151 +     *         <tt>toIndex &gt; a.length</tt>
362.2152 +     */
362.2153 +    public static void fill(float[] a, int fromIndex, int toIndex, float val) {
362.2154 +        rangeCheck(a.length, fromIndex, toIndex);
362.2155 +        for (int i = fromIndex; i < toIndex; i++)
362.2156 +            a[i] = val;
362.2157 +    }
362.2158 +
362.2159 +    /**
362.2160 +     * Assigns the specified Object reference to each element of the specified
362.2161 +     * array of Objects.
362.2162 +     *
362.2163 +     * @param a the array to be filled
362.2164 +     * @param val the value to be stored in all elements of the array
362.2165 +     * @throws ArrayStoreException if the specified value is not of a
362.2166 +     *         runtime type that can be stored in the specified array
362.2167 +     */
362.2168 +    public static void fill(Object[] a, Object val) {
362.2169 +        for (int i = 0, len = a.length; i < len; i++)
362.2170 +            a[i] = val;
362.2171 +    }
362.2172 +
362.2173 +    /**
362.2174 +     * Assigns the specified Object reference to each element of the specified
362.2175 +     * range of the specified array of Objects.  The range to be filled
362.2176 +     * extends from index <tt>fromIndex</tt>, inclusive, to index
362.2177 +     * <tt>toIndex</tt>, exclusive.  (If <tt>fromIndex==toIndex</tt>, the
362.2178 +     * range to be filled is empty.)
362.2179 +     *
362.2180 +     * @param a the array to be filled
362.2181 +     * @param fromIndex the index of the first element (inclusive) to be
362.2182 +     *        filled with the specified value
362.2183 +     * @param toIndex the index of the last element (exclusive) to be
362.2184 +     *        filled with the specified value
362.2185 +     * @param val the value to be stored in all elements of the array
362.2186 +     * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
362.2187 +     * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
362.2188 +     *         <tt>toIndex &gt; a.length</tt>
362.2189 +     * @throws ArrayStoreException if the specified value is not of a
362.2190 +     *         runtime type that can be stored in the specified array
362.2191 +     */
362.2192 +    public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
362.2193 +        rangeCheck(a.length, fromIndex, toIndex);
362.2194 +        for (int i = fromIndex; i < toIndex; i++)
362.2195 +            a[i] = val;
362.2196 +    }
362.2197 +
362.2198 +    // Cloning
362.2199 +
362.2200 +    /**
362.2201 +     * Copies the specified array, truncating or padding with nulls (if necessary)
362.2202 +     * so the copy has the specified length.  For all indices that are
362.2203 +     * valid in both the original array and the copy, the two arrays will
362.2204 +     * contain identical values.  For any indices that are valid in the
362.2205 +     * copy but not the original, the copy will contain <tt>null</tt>.
362.2206 +     * Such indices will exist if and only if the specified length
362.2207 +     * is greater than that of the original array.
362.2208 +     * The resulting array is of exactly the same class as the original array.
362.2209 +     *
362.2210 +     * @param original the array to be copied
362.2211 +     * @param newLength the length of the copy to be returned
362.2212 +     * @return a copy of the original array, truncated or padded with nulls
362.2213 +     *     to obtain the specified length
362.2214 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2215 +     * @throws NullPointerException if <tt>original</tt> is null
362.2216 +     * @since 1.6
362.2217 +     */
362.2218 +    public static <T> T[] copyOf(T[] original, int newLength) {
362.2219 +        return (T[]) copyOf(original, newLength, original.getClass());
362.2220 +    }
362.2221 +
362.2222 +    /**
362.2223 +     * Copies the specified array, truncating or padding with nulls (if necessary)
362.2224 +     * so the copy has the specified length.  For all indices that are
362.2225 +     * valid in both the original array and the copy, the two arrays will
362.2226 +     * contain identical values.  For any indices that are valid in the
362.2227 +     * copy but not the original, the copy will contain <tt>null</tt>.
362.2228 +     * Such indices will exist if and only if the specified length
362.2229 +     * is greater than that of the original array.
362.2230 +     * The resulting array is of the class <tt>newType</tt>.
362.2231 +     *
362.2232 +     * @param original the array to be copied
362.2233 +     * @param newLength the length of the copy to be returned
362.2234 +     * @param newType the class of the copy to be returned
362.2235 +     * @return a copy of the original array, truncated or padded with nulls
362.2236 +     *     to obtain the specified length
362.2237 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2238 +     * @throws NullPointerException if <tt>original</tt> is null
362.2239 +     * @throws ArrayStoreException if an element copied from
362.2240 +     *     <tt>original</tt> is not of a runtime type that can be stored in
362.2241 +     *     an array of class <tt>newType</tt>
362.2242 +     * @since 1.6
362.2243 +     */
362.2244 +    public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
362.2245 +        T[] copy = ((Object)newType == (Object)Object[].class)
362.2246 +            ? (T[]) new Object[newLength]
362.2247 +            : (T[]) Array.newInstance(newType.getComponentType(), newLength);
362.2248 +        System.arraycopy(original, 0, copy, 0,
362.2249 +                         Math.min(original.length, newLength));
362.2250 +        return copy;
362.2251 +    }
362.2252 +
362.2253 +    /**
362.2254 +     * Copies the specified array, truncating or padding with zeros (if necessary)
362.2255 +     * so the copy has the specified length.  For all indices that are
362.2256 +     * valid in both the original array and the copy, the two arrays will
362.2257 +     * contain identical values.  For any indices that are valid in the
362.2258 +     * copy but not the original, the copy will contain <tt>(byte)0</tt>.
362.2259 +     * Such indices will exist if and only if the specified length
362.2260 +     * is greater than that of the original array.
362.2261 +     *
362.2262 +     * @param original the array to be copied
362.2263 +     * @param newLength the length of the copy to be returned
362.2264 +     * @return a copy of the original array, truncated or padded with zeros
362.2265 +     *     to obtain the specified length
362.2266 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2267 +     * @throws NullPointerException if <tt>original</tt> is null
362.2268 +     * @since 1.6
362.2269 +     */
362.2270 +    public static byte[] copyOf(byte[] original, int newLength) {
362.2271 +        byte[] copy = new byte[newLength];
362.2272 +        System.arraycopy(original, 0, copy, 0,
362.2273 +                         Math.min(original.length, newLength));
362.2274 +        return copy;
362.2275 +    }
362.2276 +
362.2277 +    /**
362.2278 +     * Copies the specified array, truncating or padding with zeros (if necessary)
362.2279 +     * so the copy has the specified length.  For all indices that are
362.2280 +     * valid in both the original array and the copy, the two arrays will
362.2281 +     * contain identical values.  For any indices that are valid in the
362.2282 +     * copy but not the original, the copy will contain <tt>(short)0</tt>.
362.2283 +     * Such indices will exist if and only if the specified length
362.2284 +     * is greater than that of the original array.
362.2285 +     *
362.2286 +     * @param original the array to be copied
362.2287 +     * @param newLength the length of the copy to be returned
362.2288 +     * @return a copy of the original array, truncated or padded with zeros
362.2289 +     *     to obtain the specified length
362.2290 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2291 +     * @throws NullPointerException if <tt>original</tt> is null
362.2292 +     * @since 1.6
362.2293 +     */
362.2294 +    public static short[] copyOf(short[] original, int newLength) {
362.2295 +        short[] copy = new short[newLength];
362.2296 +        System.arraycopy(original, 0, copy, 0,
362.2297 +                         Math.min(original.length, newLength));
362.2298 +        return copy;
362.2299 +    }
362.2300 +
362.2301 +    /**
362.2302 +     * Copies the specified array, truncating or padding with zeros (if necessary)
362.2303 +     * so the copy has the specified length.  For all indices that are
362.2304 +     * valid in both the original array and the copy, the two arrays will
362.2305 +     * contain identical values.  For any indices that are valid in the
362.2306 +     * copy but not the original, the copy will contain <tt>0</tt>.
362.2307 +     * Such indices will exist if and only if the specified length
362.2308 +     * is greater than that of the original array.
362.2309 +     *
362.2310 +     * @param original the array to be copied
362.2311 +     * @param newLength the length of the copy to be returned
362.2312 +     * @return a copy of the original array, truncated or padded with zeros
362.2313 +     *     to obtain the specified length
362.2314 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2315 +     * @throws NullPointerException if <tt>original</tt> is null
362.2316 +     * @since 1.6
362.2317 +     */
362.2318 +    public static int[] copyOf(int[] original, int newLength) {
362.2319 +        int[] copy = new int[newLength];
362.2320 +        System.arraycopy(original, 0, copy, 0,
362.2321 +                         Math.min(original.length, newLength));
362.2322 +        return copy;
362.2323 +    }
362.2324 +
362.2325 +    /**
362.2326 +     * Copies the specified array, truncating or padding with zeros (if necessary)
362.2327 +     * so the copy has the specified length.  For all indices that are
362.2328 +     * valid in both the original array and the copy, the two arrays will
362.2329 +     * contain identical values.  For any indices that are valid in the
362.2330 +     * copy but not the original, the copy will contain <tt>0L</tt>.
362.2331 +     * Such indices will exist if and only if the specified length
362.2332 +     * is greater than that of the original array.
362.2333 +     *
362.2334 +     * @param original the array to be copied
362.2335 +     * @param newLength the length of the copy to be returned
362.2336 +     * @return a copy of the original array, truncated or padded with zeros
362.2337 +     *     to obtain the specified length
362.2338 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2339 +     * @throws NullPointerException if <tt>original</tt> is null
362.2340 +     * @since 1.6
362.2341 +     */
362.2342 +    public static long[] copyOf(long[] original, int newLength) {
362.2343 +        long[] copy = new long[newLength];
362.2344 +        System.arraycopy(original, 0, copy, 0,
362.2345 +                         Math.min(original.length, newLength));
362.2346 +        return copy;
362.2347 +    }
362.2348 +
362.2349 +    /**
362.2350 +     * Copies the specified array, truncating or padding with null characters (if necessary)
362.2351 +     * so the copy has the specified length.  For all indices that are valid
362.2352 +     * in both the original array and the copy, the two arrays will contain
362.2353 +     * identical values.  For any indices that are valid in the copy but not
362.2354 +     * the original, the copy will contain <tt>'\\u000'</tt>.  Such indices
362.2355 +     * will exist if and only if the specified length is greater than that of
362.2356 +     * the original array.
362.2357 +     *
362.2358 +     * @param original the array to be copied
362.2359 +     * @param newLength the length of the copy to be returned
362.2360 +     * @return a copy of the original array, truncated or padded with null characters
362.2361 +     *     to obtain the specified length
362.2362 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2363 +     * @throws NullPointerException if <tt>original</tt> is null
362.2364 +     * @since 1.6
362.2365 +     */
362.2366 +    public static char[] copyOf(char[] original, int newLength) {
362.2367 +        char[] copy = new char[newLength];
362.2368 +        System.arraycopy(original, 0, copy, 0,
362.2369 +                         Math.min(original.length, newLength));
362.2370 +        return copy;
362.2371 +    }
362.2372 +
362.2373 +    /**
362.2374 +     * Copies the specified array, truncating or padding with zeros (if necessary)
362.2375 +     * so the copy has the specified length.  For all indices that are
362.2376 +     * valid in both the original array and the copy, the two arrays will
362.2377 +     * contain identical values.  For any indices that are valid in the
362.2378 +     * copy but not the original, the copy will contain <tt>0f</tt>.
362.2379 +     * Such indices will exist if and only if the specified length
362.2380 +     * is greater than that of the original array.
362.2381 +     *
362.2382 +     * @param original the array to be copied
362.2383 +     * @param newLength the length of the copy to be returned
362.2384 +     * @return a copy of the original array, truncated or padded with zeros
362.2385 +     *     to obtain the specified length
362.2386 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2387 +     * @throws NullPointerException if <tt>original</tt> is null
362.2388 +     * @since 1.6
362.2389 +     */
362.2390 +    public static float[] copyOf(float[] original, int newLength) {
362.2391 +        float[] copy = new float[newLength];
362.2392 +        System.arraycopy(original, 0, copy, 0,
362.2393 +                         Math.min(original.length, newLength));
362.2394 +        return copy;
362.2395 +    }
362.2396 +
362.2397 +    /**
362.2398 +     * Copies the specified array, truncating or padding with zeros (if necessary)
362.2399 +     * so the copy has the specified length.  For all indices that are
362.2400 +     * valid in both the original array and the copy, the two arrays will
362.2401 +     * contain identical values.  For any indices that are valid in the
362.2402 +     * copy but not the original, the copy will contain <tt>0d</tt>.
362.2403 +     * Such indices will exist if and only if the specified length
362.2404 +     * is greater than that of the original array.
362.2405 +     *
362.2406 +     * @param original the array to be copied
362.2407 +     * @param newLength the length of the copy to be returned
362.2408 +     * @return a copy of the original array, truncated or padded with zeros
362.2409 +     *     to obtain the specified length
362.2410 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2411 +     * @throws NullPointerException if <tt>original</tt> is null
362.2412 +     * @since 1.6
362.2413 +     */
362.2414 +    public static double[] copyOf(double[] original, int newLength) {
362.2415 +        double[] copy = new double[newLength];
362.2416 +        System.arraycopy(original, 0, copy, 0,
362.2417 +                         Math.min(original.length, newLength));
362.2418 +        return copy;
362.2419 +    }
362.2420 +
362.2421 +    /**
362.2422 +     * Copies the specified array, truncating or padding with <tt>false</tt> (if necessary)
362.2423 +     * so the copy has the specified length.  For all indices that are
362.2424 +     * valid in both the original array and the copy, the two arrays will
362.2425 +     * contain identical values.  For any indices that are valid in the
362.2426 +     * copy but not the original, the copy will contain <tt>false</tt>.
362.2427 +     * Such indices will exist if and only if the specified length
362.2428 +     * is greater than that of the original array.
362.2429 +     *
362.2430 +     * @param original the array to be copied
362.2431 +     * @param newLength the length of the copy to be returned
362.2432 +     * @return a copy of the original array, truncated or padded with false elements
362.2433 +     *     to obtain the specified length
362.2434 +     * @throws NegativeArraySizeException if <tt>newLength</tt> is negative
362.2435 +     * @throws NullPointerException if <tt>original</tt> is null
362.2436 +     * @since 1.6
362.2437 +     */
362.2438 +    public static boolean[] copyOf(boolean[] original, int newLength) {
362.2439 +        boolean[] copy = new boolean[newLength];
362.2440 +        System.arraycopy(original, 0, copy, 0,
362.2441 +                         Math.min(original.length, newLength));
362.2442 +        return copy;
362.2443 +    }
362.2444 +
362.2445 +    /**
362.2446 +     * Copies the specified range of the specified array into a new array.
362.2447 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2448 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2449 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2450 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2451 +     * Values from subsequent elements in the original array are placed into
362.2452 +     * subsequent elements in the copy.  The final index of the range
362.2453 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2454 +     * may be greater than <tt>original.length</tt>, in which case
362.2455 +     * <tt>null</tt> is placed in all elements of the copy whose index is
362.2456 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2457 +     * of the returned array will be <tt>to - from</tt>.
362.2458 +     * <p>
362.2459 +     * The resulting array is of exactly the same class as the original array.
362.2460 +     *
362.2461 +     * @param original the array from which a range is to be copied
362.2462 +     * @param from the initial index of the range to be copied, inclusive
362.2463 +     * @param to the final index of the range to be copied, exclusive.
362.2464 +     *     (This index may lie outside the array.)
362.2465 +     * @return a new array containing the specified range from the original array,
362.2466 +     *     truncated or padded with nulls to obtain the required length
362.2467 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2468 +     *     or {@code from > original.length}
362.2469 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2470 +     * @throws NullPointerException if <tt>original</tt> is null
362.2471 +     * @since 1.6
362.2472 +     */
362.2473 +    public static <T> T[] copyOfRange(T[] original, int from, int to) {
362.2474 +        return copyOfRange(original, from, to, (Class<T[]>) original.getClass());
362.2475 +    }
362.2476 +
362.2477 +    /**
362.2478 +     * Copies the specified range of the specified array into a new array.
362.2479 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2480 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2481 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2482 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2483 +     * Values from subsequent elements in the original array are placed into
362.2484 +     * subsequent elements in the copy.  The final index of the range
362.2485 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2486 +     * may be greater than <tt>original.length</tt>, in which case
362.2487 +     * <tt>null</tt> is placed in all elements of the copy whose index is
362.2488 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2489 +     * of the returned array will be <tt>to - from</tt>.
362.2490 +     * The resulting array is of the class <tt>newType</tt>.
362.2491 +     *
362.2492 +     * @param original the array from which a range is to be copied
362.2493 +     * @param from the initial index of the range to be copied, inclusive
362.2494 +     * @param to the final index of the range to be copied, exclusive.
362.2495 +     *     (This index may lie outside the array.)
362.2496 +     * @param newType the class of the copy to be returned
362.2497 +     * @return a new array containing the specified range from the original array,
362.2498 +     *     truncated or padded with nulls to obtain the required length
362.2499 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2500 +     *     or {@code from > original.length}
362.2501 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2502 +     * @throws NullPointerException if <tt>original</tt> is null
362.2503 +     * @throws ArrayStoreException if an element copied from
362.2504 +     *     <tt>original</tt> is not of a runtime type that can be stored in
362.2505 +     *     an array of class <tt>newType</tt>.
362.2506 +     * @since 1.6
362.2507 +     */
362.2508 +    public static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType) {
362.2509 +        int newLength = to - from;
362.2510 +        if (newLength < 0)
362.2511 +            throw new IllegalArgumentException(from + " > " + to);
362.2512 +        T[] copy = ((Object)newType == (Object)Object[].class)
362.2513 +            ? (T[]) new Object[newLength]
362.2514 +            : (T[]) Array.newInstance(newType.getComponentType(), newLength);
362.2515 +        System.arraycopy(original, from, copy, 0,
362.2516 +                         Math.min(original.length - from, newLength));
362.2517 +        return copy;
362.2518 +    }
362.2519 +
362.2520 +    /**
362.2521 +     * Copies the specified range of the specified array into a new array.
362.2522 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2523 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2524 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2525 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2526 +     * Values from subsequent elements in the original array are placed into
362.2527 +     * subsequent elements in the copy.  The final index of the range
362.2528 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2529 +     * may be greater than <tt>original.length</tt>, in which case
362.2530 +     * <tt>(byte)0</tt> is placed in all elements of the copy whose index is
362.2531 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2532 +     * of the returned array will be <tt>to - from</tt>.
362.2533 +     *
362.2534 +     * @param original the array from which a range is to be copied
362.2535 +     * @param from the initial index of the range to be copied, inclusive
362.2536 +     * @param to the final index of the range to be copied, exclusive.
362.2537 +     *     (This index may lie outside the array.)
362.2538 +     * @return a new array containing the specified range from the original array,
362.2539 +     *     truncated or padded with zeros to obtain the required length
362.2540 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2541 +     *     or {@code from > original.length}
362.2542 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2543 +     * @throws NullPointerException if <tt>original</tt> is null
362.2544 +     * @since 1.6
362.2545 +     */
362.2546 +    public static byte[] copyOfRange(byte[] original, int from, int to) {
362.2547 +        int newLength = to - from;
362.2548 +        if (newLength < 0)
362.2549 +            throw new IllegalArgumentException(from + " > " + to);
362.2550 +        byte[] copy = new byte[newLength];
362.2551 +        System.arraycopy(original, from, copy, 0,
362.2552 +                         Math.min(original.length - from, newLength));
362.2553 +        return copy;
362.2554 +    }
362.2555 +
362.2556 +    /**
362.2557 +     * Copies the specified range of the specified array into a new array.
362.2558 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2559 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2560 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2561 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2562 +     * Values from subsequent elements in the original array are placed into
362.2563 +     * subsequent elements in the copy.  The final index of the range
362.2564 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2565 +     * may be greater than <tt>original.length</tt>, in which case
362.2566 +     * <tt>(short)0</tt> is placed in all elements of the copy whose index is
362.2567 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2568 +     * of the returned array will be <tt>to - from</tt>.
362.2569 +     *
362.2570 +     * @param original the array from which a range is to be copied
362.2571 +     * @param from the initial index of the range to be copied, inclusive
362.2572 +     * @param to the final index of the range to be copied, exclusive.
362.2573 +     *     (This index may lie outside the array.)
362.2574 +     * @return a new array containing the specified range from the original array,
362.2575 +     *     truncated or padded with zeros to obtain the required length
362.2576 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2577 +     *     or {@code from > original.length}
362.2578 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2579 +     * @throws NullPointerException if <tt>original</tt> is null
362.2580 +     * @since 1.6
362.2581 +     */
362.2582 +    public static short[] copyOfRange(short[] original, int from, int to) {
362.2583 +        int newLength = to - from;
362.2584 +        if (newLength < 0)
362.2585 +            throw new IllegalArgumentException(from + " > " + to);
362.2586 +        short[] copy = new short[newLength];
362.2587 +        System.arraycopy(original, from, copy, 0,
362.2588 +                         Math.min(original.length - from, newLength));
362.2589 +        return copy;
362.2590 +    }
362.2591 +
362.2592 +    /**
362.2593 +     * Copies the specified range of the specified array into a new array.
362.2594 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2595 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2596 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2597 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2598 +     * Values from subsequent elements in the original array are placed into
362.2599 +     * subsequent elements in the copy.  The final index of the range
362.2600 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2601 +     * may be greater than <tt>original.length</tt>, in which case
362.2602 +     * <tt>0</tt> is placed in all elements of the copy whose index is
362.2603 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2604 +     * of the returned array will be <tt>to - from</tt>.
362.2605 +     *
362.2606 +     * @param original the array from which a range is to be copied
362.2607 +     * @param from the initial index of the range to be copied, inclusive
362.2608 +     * @param to the final index of the range to be copied, exclusive.
362.2609 +     *     (This index may lie outside the array.)
362.2610 +     * @return a new array containing the specified range from the original array,
362.2611 +     *     truncated or padded with zeros to obtain the required length
362.2612 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2613 +     *     or {@code from > original.length}
362.2614 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2615 +     * @throws NullPointerException if <tt>original</tt> is null
362.2616 +     * @since 1.6
362.2617 +     */
362.2618 +    public static int[] copyOfRange(int[] original, int from, int to) {
362.2619 +        int newLength = to - from;
362.2620 +        if (newLength < 0)
362.2621 +            throw new IllegalArgumentException(from + " > " + to);
362.2622 +        int[] copy = new int[newLength];
362.2623 +        System.arraycopy(original, from, copy, 0,
362.2624 +                         Math.min(original.length - from, newLength));
362.2625 +        return copy;
362.2626 +    }
362.2627 +
362.2628 +    /**
362.2629 +     * Copies the specified range of the specified array into a new array.
362.2630 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2631 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2632 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2633 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2634 +     * Values from subsequent elements in the original array are placed into
362.2635 +     * subsequent elements in the copy.  The final index of the range
362.2636 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2637 +     * may be greater than <tt>original.length</tt>, in which case
362.2638 +     * <tt>0L</tt> is placed in all elements of the copy whose index is
362.2639 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2640 +     * of the returned array will be <tt>to - from</tt>.
362.2641 +     *
362.2642 +     * @param original the array from which a range is to be copied
362.2643 +     * @param from the initial index of the range to be copied, inclusive
362.2644 +     * @param to the final index of the range to be copied, exclusive.
362.2645 +     *     (This index may lie outside the array.)
362.2646 +     * @return a new array containing the specified range from the original array,
362.2647 +     *     truncated or padded with zeros to obtain the required length
362.2648 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2649 +     *     or {@code from > original.length}
362.2650 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2651 +     * @throws NullPointerException if <tt>original</tt> is null
362.2652 +     * @since 1.6
362.2653 +     */
362.2654 +    public static long[] copyOfRange(long[] original, int from, int to) {
362.2655 +        int newLength = to - from;
362.2656 +        if (newLength < 0)
362.2657 +            throw new IllegalArgumentException(from + " > " + to);
362.2658 +        long[] copy = new long[newLength];
362.2659 +        System.arraycopy(original, from, copy, 0,
362.2660 +                         Math.min(original.length - from, newLength));
362.2661 +        return copy;
362.2662 +    }
362.2663 +
362.2664 +    /**
362.2665 +     * Copies the specified range of the specified array into a new array.
362.2666 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2667 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2668 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2669 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2670 +     * Values from subsequent elements in the original array are placed into
362.2671 +     * subsequent elements in the copy.  The final index of the range
362.2672 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2673 +     * may be greater than <tt>original.length</tt>, in which case
362.2674 +     * <tt>'\\u000'</tt> is placed in all elements of the copy whose index is
362.2675 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2676 +     * of the returned array will be <tt>to - from</tt>.
362.2677 +     *
362.2678 +     * @param original the array from which a range is to be copied
362.2679 +     * @param from the initial index of the range to be copied, inclusive
362.2680 +     * @param to the final index of the range to be copied, exclusive.
362.2681 +     *     (This index may lie outside the array.)
362.2682 +     * @return a new array containing the specified range from the original array,
362.2683 +     *     truncated or padded with null characters to obtain the required length
362.2684 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2685 +     *     or {@code from > original.length}
362.2686 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2687 +     * @throws NullPointerException if <tt>original</tt> is null
362.2688 +     * @since 1.6
362.2689 +     */
362.2690 +    public static char[] copyOfRange(char[] original, int from, int to) {
362.2691 +        int newLength = to - from;
362.2692 +        if (newLength < 0)
362.2693 +            throw new IllegalArgumentException(from + " > " + to);
362.2694 +        char[] copy = new char[newLength];
362.2695 +        System.arraycopy(original, from, copy, 0,
362.2696 +                         Math.min(original.length - from, newLength));
362.2697 +        return copy;
362.2698 +    }
362.2699 +
362.2700 +    /**
362.2701 +     * Copies the specified range of the specified array into a new array.
362.2702 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2703 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2704 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2705 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2706 +     * Values from subsequent elements in the original array are placed into
362.2707 +     * subsequent elements in the copy.  The final index of the range
362.2708 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2709 +     * may be greater than <tt>original.length</tt>, in which case
362.2710 +     * <tt>0f</tt> is placed in all elements of the copy whose index is
362.2711 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2712 +     * of the returned array will be <tt>to - from</tt>.
362.2713 +     *
362.2714 +     * @param original the array from which a range is to be copied
362.2715 +     * @param from the initial index of the range to be copied, inclusive
362.2716 +     * @param to the final index of the range to be copied, exclusive.
362.2717 +     *     (This index may lie outside the array.)
362.2718 +     * @return a new array containing the specified range from the original array,
362.2719 +     *     truncated or padded with zeros to obtain the required length
362.2720 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2721 +     *     or {@code from > original.length}
362.2722 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2723 +     * @throws NullPointerException if <tt>original</tt> is null
362.2724 +     * @since 1.6
362.2725 +     */
362.2726 +    public static float[] copyOfRange(float[] original, int from, int to) {
362.2727 +        int newLength = to - from;
362.2728 +        if (newLength < 0)
362.2729 +            throw new IllegalArgumentException(from + " > " + to);
362.2730 +        float[] copy = new float[newLength];
362.2731 +        System.arraycopy(original, from, copy, 0,
362.2732 +                         Math.min(original.length - from, newLength));
362.2733 +        return copy;
362.2734 +    }
362.2735 +
362.2736 +    /**
362.2737 +     * Copies the specified range of the specified array into a new array.
362.2738 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2739 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2740 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2741 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2742 +     * Values from subsequent elements in the original array are placed into
362.2743 +     * subsequent elements in the copy.  The final index of the range
362.2744 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2745 +     * may be greater than <tt>original.length</tt>, in which case
362.2746 +     * <tt>0d</tt> is placed in all elements of the copy whose index is
362.2747 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2748 +     * of the returned array will be <tt>to - from</tt>.
362.2749 +     *
362.2750 +     * @param original the array from which a range is to be copied
362.2751 +     * @param from the initial index of the range to be copied, inclusive
362.2752 +     * @param to the final index of the range to be copied, exclusive.
362.2753 +     *     (This index may lie outside the array.)
362.2754 +     * @return a new array containing the specified range from the original array,
362.2755 +     *     truncated or padded with zeros to obtain the required length
362.2756 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2757 +     *     or {@code from > original.length}
362.2758 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2759 +     * @throws NullPointerException if <tt>original</tt> is null
362.2760 +     * @since 1.6
362.2761 +     */
362.2762 +    public static double[] copyOfRange(double[] original, int from, int to) {
362.2763 +        int newLength = to - from;
362.2764 +        if (newLength < 0)
362.2765 +            throw new IllegalArgumentException(from + " > " + to);
362.2766 +        double[] copy = new double[newLength];
362.2767 +        System.arraycopy(original, from, copy, 0,
362.2768 +                         Math.min(original.length - from, newLength));
362.2769 +        return copy;
362.2770 +    }
362.2771 +
362.2772 +    /**
362.2773 +     * Copies the specified range of the specified array into a new array.
362.2774 +     * The initial index of the range (<tt>from</tt>) must lie between zero
362.2775 +     * and <tt>original.length</tt>, inclusive.  The value at
362.2776 +     * <tt>original[from]</tt> is placed into the initial element of the copy
362.2777 +     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
362.2778 +     * Values from subsequent elements in the original array are placed into
362.2779 +     * subsequent elements in the copy.  The final index of the range
362.2780 +     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
362.2781 +     * may be greater than <tt>original.length</tt>, in which case
362.2782 +     * <tt>false</tt> is placed in all elements of the copy whose index is
362.2783 +     * greater than or equal to <tt>original.length - from</tt>.  The length
362.2784 +     * of the returned array will be <tt>to - from</tt>.
362.2785 +     *
362.2786 +     * @param original the array from which a range is to be copied
362.2787 +     * @param from the initial index of the range to be copied, inclusive
362.2788 +     * @param to the final index of the range to be copied, exclusive.
362.2789 +     *     (This index may lie outside the array.)
362.2790 +     * @return a new array containing the specified range from the original array,
362.2791 +     *     truncated or padded with false elements to obtain the required length
362.2792 +     * @throws ArrayIndexOutOfBoundsException if {@code from < 0}
362.2793 +     *     or {@code from > original.length}
362.2794 +     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
362.2795 +     * @throws NullPointerException if <tt>original</tt> is null
362.2796 +     * @since 1.6
362.2797 +     */
362.2798 +    public static boolean[] copyOfRange(boolean[] original, int from, int to) {
362.2799 +        int newLength = to - from;
362.2800 +        if (newLength < 0)
362.2801 +            throw new IllegalArgumentException(from + " > " + to);
362.2802 +        boolean[] copy = new boolean[newLength];
362.2803 +        System.arraycopy(original, from, copy, 0,
362.2804 +                         Math.min(original.length - from, newLength));
362.2805 +        return copy;
362.2806 +    }
362.2807 +
362.2808 +    // Misc
362.2809 +
362.2810 +    /**
362.2811 +     * Returns a fixed-size list backed by the specified array.  (Changes to
362.2812 +     * the returned list "write through" to the array.)  This method acts
362.2813 +     * as bridge between array-based and collection-based APIs, in
362.2814 +     * combination with {@link Collection#toArray}.  The returned list is
362.2815 +     * serializable and implements {@link RandomAccess}.
362.2816 +     *
362.2817 +     * <p>This method also provides a convenient way to create a fixed-size
362.2818 +     * list initialized to contain several elements:
362.2819 +     * <pre>
362.2820 +     *     List&lt;String&gt; stooges = Arrays.asList("Larry", "Moe", "Curly");
362.2821 +     * </pre>
362.2822 +     *
362.2823 +     * @param a the array by which the list will be backed
362.2824 +     * @return a list view of the specified array
362.2825 +     */
362.2826 +    @SafeVarargs
362.2827 +    public static <T> List<T> asList(T... a) {
362.2828 +        return new ArrayList<>(a);
362.2829 +    }
362.2830 +
362.2831 +    /**
362.2832 +     * @serial include
362.2833 +     */
362.2834 +    private static class ArrayList<E> extends AbstractList<E>
362.2835 +        implements RandomAccess, java.io.Serializable
362.2836 +    {
362.2837 +        private static final long serialVersionUID = -2764017481108945198L;
362.2838 +        private final E[] a;
362.2839 +
362.2840 +        ArrayList(E[] array) {
362.2841 +            if (array==null)
362.2842 +                throw new NullPointerException();
362.2843 +            a = array;
362.2844 +        }
362.2845 +
362.2846 +        public int size() {
362.2847 +            return a.length;
362.2848 +        }
362.2849 +
362.2850 +        public Object[] toArray() {
362.2851 +            return a.clone();
362.2852 +        }
362.2853 +
362.2854 +        public <T> T[] toArray(T[] a) {
362.2855 +            int size = size();
362.2856 +            if (a.length < size)
362.2857 +                return Arrays.copyOf(this.a, size,
362.2858 +                                     (Class<? extends T[]>) a.getClass());
362.2859 +            System.arraycopy(this.a, 0, a, 0, size);
362.2860 +            if (a.length > size)
362.2861 +                a[size] = null;
362.2862 +            return a;
362.2863 +        }
362.2864 +
362.2865 +        public E get(int index) {
362.2866 +            return a[index];
362.2867 +        }
362.2868 +
362.2869 +        public E set(int index, E element) {
362.2870 +            E oldValue = a[index];
362.2871 +            a[index] = element;
362.2872 +            return oldValue;
362.2873 +        }
362.2874 +
362.2875 +        public int indexOf(Object o) {
362.2876 +            if (o==null) {
362.2877 +                for (int i=0; i<a.length; i++)
362.2878 +                    if (a[i]==null)
362.2879 +                        return i;
362.2880 +            } else {
362.2881 +                for (int i=0; i<a.length; i++)
362.2882 +                    if (o.equals(a[i]))
362.2883 +                        return i;
362.2884 +            }
362.2885 +            return -1;
362.2886 +        }
362.2887 +
362.2888 +        public boolean contains(Object o) {
362.2889 +            return indexOf(o) != -1;
362.2890 +        }
362.2891 +    }
362.2892 +
362.2893 +    /**
362.2894 +     * Returns a hash code based on the contents of the specified array.
362.2895 +     * For any two <tt>long</tt> arrays <tt>a</tt> and <tt>b</tt>
362.2896 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.2897 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.2898 +     *
362.2899 +     * <p>The value returned by this method is the same value that would be
362.2900 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.2901 +     * method on a {@link List} containing a sequence of {@link Long}
362.2902 +     * instances representing the elements of <tt>a</tt> in the same order.
362.2903 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.2904 +     *
362.2905 +     * @param a the array whose hash value to compute
362.2906 +     * @return a content-based hash code for <tt>a</tt>
362.2907 +     * @since 1.5
362.2908 +     */
362.2909 +    public static int hashCode(long a[]) {
362.2910 +        if (a == null)
362.2911 +            return 0;
362.2912 +
362.2913 +        int result = 1;
362.2914 +        for (long element : a) {
362.2915 +            int elementHash = (int)(element ^ (element >>> 32));
362.2916 +            result = 31 * result + elementHash;
362.2917 +        }
362.2918 +
362.2919 +        return result;
362.2920 +    }
362.2921 +
362.2922 +    /**
362.2923 +     * Returns a hash code based on the contents of the specified array.
362.2924 +     * For any two non-null <tt>int</tt> arrays <tt>a</tt> and <tt>b</tt>
362.2925 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.2926 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.2927 +     *
362.2928 +     * <p>The value returned by this method is the same value that would be
362.2929 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.2930 +     * method on a {@link List} containing a sequence of {@link Integer}
362.2931 +     * instances representing the elements of <tt>a</tt> in the same order.
362.2932 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.2933 +     *
362.2934 +     * @param a the array whose hash value to compute
362.2935 +     * @return a content-based hash code for <tt>a</tt>
362.2936 +     * @since 1.5
362.2937 +     */
362.2938 +    public static int hashCode(int a[]) {
362.2939 +        if (a == null)
362.2940 +            return 0;
362.2941 +
362.2942 +        int result = 1;
362.2943 +        for (int element : a)
362.2944 +            result = 31 * result + element;
362.2945 +
362.2946 +        return result;
362.2947 +    }
362.2948 +
362.2949 +    /**
362.2950 +     * Returns a hash code based on the contents of the specified array.
362.2951 +     * For any two <tt>short</tt> arrays <tt>a</tt> and <tt>b</tt>
362.2952 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.2953 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.2954 +     *
362.2955 +     * <p>The value returned by this method is the same value that would be
362.2956 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.2957 +     * method on a {@link List} containing a sequence of {@link Short}
362.2958 +     * instances representing the elements of <tt>a</tt> in the same order.
362.2959 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.2960 +     *
362.2961 +     * @param a the array whose hash value to compute
362.2962 +     * @return a content-based hash code for <tt>a</tt>
362.2963 +     * @since 1.5
362.2964 +     */
362.2965 +    public static int hashCode(short a[]) {
362.2966 +        if (a == null)
362.2967 +            return 0;
362.2968 +
362.2969 +        int result = 1;
362.2970 +        for (short element : a)
362.2971 +            result = 31 * result + element;
362.2972 +
362.2973 +        return result;
362.2974 +    }
362.2975 +
362.2976 +    /**
362.2977 +     * Returns a hash code based on the contents of the specified array.
362.2978 +     * For any two <tt>char</tt> arrays <tt>a</tt> and <tt>b</tt>
362.2979 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.2980 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.2981 +     *
362.2982 +     * <p>The value returned by this method is the same value that would be
362.2983 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.2984 +     * method on a {@link List} containing a sequence of {@link Character}
362.2985 +     * instances representing the elements of <tt>a</tt> in the same order.
362.2986 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.2987 +     *
362.2988 +     * @param a the array whose hash value to compute
362.2989 +     * @return a content-based hash code for <tt>a</tt>
362.2990 +     * @since 1.5
362.2991 +     */
362.2992 +    public static int hashCode(char a[]) {
362.2993 +        if (a == null)
362.2994 +            return 0;
362.2995 +
362.2996 +        int result = 1;
362.2997 +        for (char element : a)
362.2998 +            result = 31 * result + element;
362.2999 +
362.3000 +        return result;
362.3001 +    }
362.3002 +
362.3003 +    /**
362.3004 +     * Returns a hash code based on the contents of the specified array.
362.3005 +     * For any two <tt>byte</tt> arrays <tt>a</tt> and <tt>b</tt>
362.3006 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.3007 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.3008 +     *
362.3009 +     * <p>The value returned by this method is the same value that would be
362.3010 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.3011 +     * method on a {@link List} containing a sequence of {@link Byte}
362.3012 +     * instances representing the elements of <tt>a</tt> in the same order.
362.3013 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.3014 +     *
362.3015 +     * @param a the array whose hash value to compute
362.3016 +     * @return a content-based hash code for <tt>a</tt>
362.3017 +     * @since 1.5
362.3018 +     */
362.3019 +    public static int hashCode(byte a[]) {
362.3020 +        if (a == null)
362.3021 +            return 0;
362.3022 +
362.3023 +        int result = 1;
362.3024 +        for (byte element : a)
362.3025 +            result = 31 * result + element;
362.3026 +
362.3027 +        return result;
362.3028 +    }
362.3029 +
362.3030 +    /**
362.3031 +     * Returns a hash code based on the contents of the specified array.
362.3032 +     * For any two <tt>boolean</tt> arrays <tt>a</tt> and <tt>b</tt>
362.3033 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.3034 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.3035 +     *
362.3036 +     * <p>The value returned by this method is the same value that would be
362.3037 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.3038 +     * method on a {@link List} containing a sequence of {@link Boolean}
362.3039 +     * instances representing the elements of <tt>a</tt> in the same order.
362.3040 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.3041 +     *
362.3042 +     * @param a the array whose hash value to compute
362.3043 +     * @return a content-based hash code for <tt>a</tt>
362.3044 +     * @since 1.5
362.3045 +     */
362.3046 +    public static int hashCode(boolean a[]) {
362.3047 +        if (a == null)
362.3048 +            return 0;
362.3049 +
362.3050 +        int result = 1;
362.3051 +        for (boolean element : a)
362.3052 +            result = 31 * result + (element ? 1231 : 1237);
362.3053 +
362.3054 +        return result;
362.3055 +    }
362.3056 +
362.3057 +    /**
362.3058 +     * Returns a hash code based on the contents of the specified array.
362.3059 +     * For any two <tt>float</tt> arrays <tt>a</tt> and <tt>b</tt>
362.3060 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.3061 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.3062 +     *
362.3063 +     * <p>The value returned by this method is the same value that would be
362.3064 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.3065 +     * method on a {@link List} containing a sequence of {@link Float}
362.3066 +     * instances representing the elements of <tt>a</tt> in the same order.
362.3067 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.3068 +     *
362.3069 +     * @param a the array whose hash value to compute
362.3070 +     * @return a content-based hash code for <tt>a</tt>
362.3071 +     * @since 1.5
362.3072 +     */
362.3073 +    public static int hashCode(float a[]) {
362.3074 +        if (a == null)
362.3075 +            return 0;
362.3076 +
362.3077 +        int result = 1;
362.3078 +        for (float element : a)
362.3079 +            result = 31 * result + Float.floatToIntBits(element);
362.3080 +
362.3081 +        return result;
362.3082 +    }
362.3083 +
362.3084 +    /**
362.3085 +     * Returns a hash code based on the contents of the specified array.
362.3086 +     * For any two <tt>double</tt> arrays <tt>a</tt> and <tt>b</tt>
362.3087 +     * such that <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.3088 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.3089 +     *
362.3090 +     * <p>The value returned by this method is the same value that would be
362.3091 +     * obtained by invoking the {@link List#hashCode() <tt>hashCode</tt>}
362.3092 +     * method on a {@link List} containing a sequence of {@link Double}
362.3093 +     * instances representing the elements of <tt>a</tt> in the same order.
362.3094 +     * If <tt>a</tt> is <tt>null</tt>, this method returns 0.
362.3095 +     *
362.3096 +     * @param a the array whose hash value to compute
362.3097 +     * @return a content-based hash code for <tt>a</tt>
362.3098 +     * @since 1.5
362.3099 +     */
362.3100 +    public static int hashCode(double a[]) {
362.3101 +        if (a == null)
362.3102 +            return 0;
362.3103 +
362.3104 +        int result = 1;
362.3105 +        for (double element : a) {
362.3106 +            long bits = Double.doubleToLongBits(element);
362.3107 +            result = 31 * result + (int)(bits ^ (bits >>> 32));
362.3108 +        }
362.3109 +        return result;
362.3110 +    }
362.3111 +
362.3112 +    /**
362.3113 +     * Returns a hash code based on the contents of the specified array.  If
362.3114 +     * the array contains other arrays as elements, the hash code is based on
362.3115 +     * their identities rather than their contents.  It is therefore
362.3116 +     * acceptable to invoke this method on an array that contains itself as an
362.3117 +     * element,  either directly or indirectly through one or more levels of
362.3118 +     * arrays.
362.3119 +     *
362.3120 +     * <p>For any two arrays <tt>a</tt> and <tt>b</tt> such that
362.3121 +     * <tt>Arrays.equals(a, b)</tt>, it is also the case that
362.3122 +     * <tt>Arrays.hashCode(a) == Arrays.hashCode(b)</tt>.
362.3123 +     *
362.3124 +     * <p>The value returned by this method is equal to the value that would
362.3125 +     * be returned by <tt>Arrays.asList(a).hashCode()</tt>, unless <tt>a</tt>
362.3126 +     * is <tt>null</tt>, in which case <tt>0</tt> is returned.
362.3127 +     *
362.3128 +     * @param a the array whose content-based hash code to compute
362.3129 +     * @return a content-based hash code for <tt>a</tt>
362.3130 +     * @see #deepHashCode(Object[])
362.3131 +     * @since 1.5
362.3132 +     */
362.3133 +    public static int hashCode(Object a[]) {
362.3134 +        if (a == null)
362.3135 +            return 0;
362.3136 +
362.3137 +        int result = 1;
362.3138 +
362.3139 +        for (Object element : a)
362.3140 +            result = 31 * result + (element == null ? 0 : element.hashCode());
362.3141 +
362.3142 +        return result;
362.3143 +    }
362.3144 +
362.3145 +    /**
362.3146 +     * Returns a hash code based on the "deep contents" of the specified
362.3147 +     * array.  If the array contains other arrays as elements, the
362.3148 +     * hash code is based on their contents and so on, ad infinitum.
362.3149 +     * It is therefore unacceptable to invoke this method on an array that
362.3150 +     * contains itself as an element, either directly or indirectly through
362.3151 +     * one or more levels of arrays.  The behavior of such an invocation is
362.3152 +     * undefined.
362.3153 +     *
362.3154 +     * <p>For any two arrays <tt>a</tt> and <tt>b</tt> such that
362.3155 +     * <tt>Arrays.deepEquals(a, b)</tt>, it is also the case that
362.3156 +     * <tt>Arrays.deepHashCode(a) == Arrays.deepHashCode(b)</tt>.
362.3157 +     *
362.3158 +     * <p>The computation of the value returned by this method is similar to
362.3159 +     * that of the value returned by {@link List#hashCode()} on a list
362.3160 +     * containing the same elements as <tt>a</tt> in the same order, with one
362.3161 +     * difference: If an element <tt>e</tt> of <tt>a</tt> is itself an array,
362.3162 +     * its hash code is computed not by calling <tt>e.hashCode()</tt>, but as
362.3163 +     * by calling the appropriate overloading of <tt>Arrays.hashCode(e)</tt>
362.3164 +     * if <tt>e</tt> is an array of a primitive type, or as by calling
362.3165 +     * <tt>Arrays.deepHashCode(e)</tt> recursively if <tt>e</tt> is an array
362.3166 +     * of a reference type.  If <tt>a</tt> is <tt>null</tt>, this method
362.3167 +     * returns 0.
362.3168 +     *
362.3169 +     * @param a the array whose deep-content-based hash code to compute
362.3170 +     * @return a deep-content-based hash code for <tt>a</tt>
362.3171 +     * @see #hashCode(Object[])
362.3172 +     * @since 1.5
362.3173 +     */
362.3174 +    public static int deepHashCode(Object a[]) {
362.3175 +        if (a == null)
362.3176 +            return 0;
362.3177 +
362.3178 +        int result = 1;
362.3179 +
362.3180 +        for (Object element : a) {
362.3181 +            int elementHash = 0;
362.3182 +            if (element instanceof Object[])
362.3183 +                elementHash = deepHashCode((Object[]) element);
362.3184 +            else if (element instanceof byte[])
362.3185 +                elementHash = hashCode((byte[]) element);
362.3186 +            else if (element instanceof short[])
362.3187 +                elementHash = hashCode((short[]) element);
362.3188 +            else if (element instanceof int[])
362.3189 +                elementHash = hashCode((int[]) element);
362.3190 +            else if (element instanceof long[])
362.3191 +                elementHash = hashCode((long[]) element);
362.3192 +            else if (element instanceof char[])
362.3193 +                elementHash = hashCode((char[]) element);
362.3194 +            else if (element instanceof float[])
362.3195 +                elementHash = hashCode((float[]) element);
362.3196 +            else if (element instanceof double[])
362.3197 +                elementHash = hashCode((double[]) element);
362.3198 +            else if (element instanceof boolean[])
362.3199 +                elementHash = hashCode((boolean[]) element);
362.3200 +            else if (element != null)
362.3201 +                elementHash = element.hashCode();
362.3202 +
362.3203 +            result = 31 * result + elementHash;
362.3204 +        }
362.3205 +
362.3206 +        return result;
362.3207 +    }
362.3208 +
362.3209 +    /**
362.3210 +     * Returns <tt>true</tt> if the two specified arrays are <i>deeply
362.3211 +     * equal</i> to one another.  Unlike the {@link #equals(Object[],Object[])}
362.3212 +     * method, this method is appropriate for use with nested arrays of
362.3213 +     * arbitrary depth.
362.3214 +     *
362.3215 +     * <p>Two array references are considered deeply equal if both
362.3216 +     * are <tt>null</tt>, or if they refer to arrays that contain the same
362.3217 +     * number of elements and all corresponding pairs of elements in the two
362.3218 +     * arrays are deeply equal.
362.3219 +     *
362.3220 +     * <p>Two possibly <tt>null</tt> elements <tt>e1</tt> and <tt>e2</tt> are
362.3221 +     * deeply equal if any of the following conditions hold:
362.3222 +     * <ul>
362.3223 +     *    <li> <tt>e1</tt> and <tt>e2</tt> are both arrays of object reference
362.3224 +     *         types, and <tt>Arrays.deepEquals(e1, e2) would return true</tt>
362.3225 +     *    <li> <tt>e1</tt> and <tt>e2</tt> are arrays of the same primitive
362.3226 +     *         type, and the appropriate overloading of
362.3227 +     *         <tt>Arrays.equals(e1, e2)</tt> would return true.
362.3228 +     *    <li> <tt>e1 == e2</tt>
362.3229 +     *    <li> <tt>e1.equals(e2)</tt> would return true.
362.3230 +     * </ul>
362.3231 +     * Note that this definition permits <tt>null</tt> elements at any depth.
362.3232 +     *
362.3233 +     * <p>If either of the specified arrays contain themselves as elements
362.3234 +     * either directly or indirectly through one or more levels of arrays,
362.3235 +     * the behavior of this method is undefined.
362.3236 +     *
362.3237 +     * @param a1 one array to be tested for equality
362.3238 +     * @param a2 the other array to be tested for equality
362.3239 +     * @return <tt>true</tt> if the two arrays are equal
362.3240 +     * @see #equals(Object[],Object[])
362.3241 +     * @see Objects#deepEquals(Object, Object)
362.3242 +     * @since 1.5
362.3243 +     */
362.3244 +    public static boolean deepEquals(Object[] a1, Object[] a2) {
362.3245 +        if (a1 == a2)
362.3246 +            return true;
362.3247 +        if (a1 == null || a2==null)
362.3248 +            return false;
362.3249 +        int length = a1.length;
362.3250 +        if (a2.length != length)
362.3251 +            return false;
362.3252 +
362.3253 +        for (int i = 0; i < length; i++) {
362.3254 +            Object e1 = a1[i];
362.3255 +            Object e2 = a2[i];
362.3256 +
362.3257 +            if (e1 == e2)
362.3258 +                continue;
362.3259 +            if (e1 == null)
362.3260 +                return false;
362.3261 +
362.3262 +            // Figure out whether the two elements are equal
362.3263 +            boolean eq = deepEquals0(e1, e2);
362.3264 +
362.3265 +            if (!eq)
362.3266 +                return false;
362.3267 +        }
362.3268 +        return true;
362.3269 +    }
362.3270 +
362.3271 +    static boolean deepEquals0(Object e1, Object e2) {
362.3272 +        assert e1 != null;
362.3273 +        boolean eq;
362.3274 +        if (e1 instanceof Object[] && e2 instanceof Object[])
362.3275 +            eq = deepEquals ((Object[]) e1, (Object[]) e2);
362.3276 +        else if (e1 instanceof byte[] && e2 instanceof byte[])
362.3277 +            eq = equals((byte[]) e1, (byte[]) e2);
362.3278 +        else if (e1 instanceof short[] && e2 instanceof short[])
362.3279 +            eq = equals((short[]) e1, (short[]) e2);
362.3280 +        else if (e1 instanceof int[] && e2 instanceof int[])
362.3281 +            eq = equals((int[]) e1, (int[]) e2);
362.3282 +        else if (e1 instanceof long[] && e2 instanceof long[])
362.3283 +            eq = equals((long[]) e1, (long[]) e2);
362.3284 +        else if (e1 instanceof char[] && e2 instanceof char[])
362.3285 +            eq = equals((char[]) e1, (char[]) e2);
362.3286 +        else if (e1 instanceof float[] && e2 instanceof float[])
362.3287 +            eq = equals((float[]) e1, (float[]) e2);
362.3288 +        else if (e1 instanceof double[] && e2 instanceof double[])
362.3289 +            eq = equals((double[]) e1, (double[]) e2);
362.3290 +        else if (e1 instanceof boolean[] && e2 instanceof boolean[])
362.3291 +            eq = equals((boolean[]) e1, (boolean[]) e2);
362.3292 +        else
362.3293 +            eq = e1.equals(e2);
362.3294 +        return eq;
362.3295 +    }
362.3296 +
362.3297 +    /**
362.3298 +     * Returns a string representation of the contents of the specified array.
362.3299 +     * The string representation consists of a list of the array's elements,
362.3300 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3301 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3302 +     * space).  Elements are converted to strings as by
362.3303 +     * <tt>String.valueOf(long)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
362.3304 +     * is <tt>null</tt>.
362.3305 +     *
362.3306 +     * @param a the array whose string representation to return
362.3307 +     * @return a string representation of <tt>a</tt>
362.3308 +     * @since 1.5
362.3309 +     */
362.3310 +    public static String toString(long[] a) {
362.3311 +        if (a == null)
362.3312 +            return "null";
362.3313 +        int iMax = a.length - 1;
362.3314 +        if (iMax == -1)
362.3315 +            return "[]";
362.3316 +
362.3317 +        StringBuilder b = new StringBuilder();
362.3318 +        b.append('[');
362.3319 +        for (int i = 0; ; i++) {
362.3320 +            b.append(a[i]);
362.3321 +            if (i == iMax)
362.3322 +                return b.append(']').toString();
362.3323 +            b.append(", ");
362.3324 +        }
362.3325 +    }
362.3326 +
362.3327 +    /**
362.3328 +     * Returns a string representation of the contents of the specified array.
362.3329 +     * The string representation consists of a list of the array's elements,
362.3330 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3331 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3332 +     * space).  Elements are converted to strings as by
362.3333 +     * <tt>String.valueOf(int)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt> is
362.3334 +     * <tt>null</tt>.
362.3335 +     *
362.3336 +     * @param a the array whose string representation to return
362.3337 +     * @return a string representation of <tt>a</tt>
362.3338 +     * @since 1.5
362.3339 +     */
362.3340 +    public static String toString(int[] a) {
362.3341 +        if (a == null)
362.3342 +            return "null";
362.3343 +        int iMax = a.length - 1;
362.3344 +        if (iMax == -1)
362.3345 +            return "[]";
362.3346 +
362.3347 +        StringBuilder b = new StringBuilder();
362.3348 +        b.append('[');
362.3349 +        for (int i = 0; ; i++) {
362.3350 +            b.append(a[i]);
362.3351 +            if (i == iMax)
362.3352 +                return b.append(']').toString();
362.3353 +            b.append(", ");
362.3354 +        }
362.3355 +    }
362.3356 +
362.3357 +    /**
362.3358 +     * Returns a string representation of the contents of the specified array.
362.3359 +     * The string representation consists of a list of the array's elements,
362.3360 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3361 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3362 +     * space).  Elements are converted to strings as by
362.3363 +     * <tt>String.valueOf(short)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
362.3364 +     * is <tt>null</tt>.
362.3365 +     *
362.3366 +     * @param a the array whose string representation to return
362.3367 +     * @return a string representation of <tt>a</tt>
362.3368 +     * @since 1.5
362.3369 +     */
362.3370 +    public static String toString(short[] a) {
362.3371 +        if (a == null)
362.3372 +            return "null";
362.3373 +        int iMax = a.length - 1;
362.3374 +        if (iMax == -1)
362.3375 +            return "[]";
362.3376 +
362.3377 +        StringBuilder b = new StringBuilder();
362.3378 +        b.append('[');
362.3379 +        for (int i = 0; ; i++) {
362.3380 +            b.append(a[i]);
362.3381 +            if (i == iMax)
362.3382 +                return b.append(']').toString();
362.3383 +            b.append(", ");
362.3384 +        }
362.3385 +    }
362.3386 +
362.3387 +    /**
362.3388 +     * Returns a string representation of the contents of the specified array.
362.3389 +     * The string representation consists of a list of the array's elements,
362.3390 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3391 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3392 +     * space).  Elements are converted to strings as by
362.3393 +     * <tt>String.valueOf(char)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
362.3394 +     * is <tt>null</tt>.
362.3395 +     *
362.3396 +     * @param a the array whose string representation to return
362.3397 +     * @return a string representation of <tt>a</tt>
362.3398 +     * @since 1.5
362.3399 +     */
362.3400 +    public static String toString(char[] a) {
362.3401 +        if (a == null)
362.3402 +            return "null";
362.3403 +        int iMax = a.length - 1;
362.3404 +        if (iMax == -1)
362.3405 +            return "[]";
362.3406 +
362.3407 +        StringBuilder b = new StringBuilder();
362.3408 +        b.append('[');
362.3409 +        for (int i = 0; ; i++) {
362.3410 +            b.append(a[i]);
362.3411 +            if (i == iMax)
362.3412 +                return b.append(']').toString();
362.3413 +            b.append(", ");
362.3414 +        }
362.3415 +    }
362.3416 +
362.3417 +    /**
362.3418 +     * Returns a string representation of the contents of the specified array.
362.3419 +     * The string representation consists of a list of the array's elements,
362.3420 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements
362.3421 +     * are separated by the characters <tt>", "</tt> (a comma followed
362.3422 +     * by a space).  Elements are converted to strings as by
362.3423 +     * <tt>String.valueOf(byte)</tt>.  Returns <tt>"null"</tt> if
362.3424 +     * <tt>a</tt> is <tt>null</tt>.
362.3425 +     *
362.3426 +     * @param a the array whose string representation to return
362.3427 +     * @return a string representation of <tt>a</tt>
362.3428 +     * @since 1.5
362.3429 +     */
362.3430 +    public static String toString(byte[] a) {
362.3431 +        if (a == null)
362.3432 +            return "null";
362.3433 +        int iMax = a.length - 1;
362.3434 +        if (iMax == -1)
362.3435 +            return "[]";
362.3436 +
362.3437 +        StringBuilder b = new StringBuilder();
362.3438 +        b.append('[');
362.3439 +        for (int i = 0; ; i++) {
362.3440 +            b.append(a[i]);
362.3441 +            if (i == iMax)
362.3442 +                return b.append(']').toString();
362.3443 +            b.append(", ");
362.3444 +        }
362.3445 +    }
362.3446 +
362.3447 +    /**
362.3448 +     * Returns a string representation of the contents of the specified array.
362.3449 +     * The string representation consists of a list of the array's elements,
362.3450 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3451 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3452 +     * space).  Elements are converted to strings as by
362.3453 +     * <tt>String.valueOf(boolean)</tt>.  Returns <tt>"null"</tt> if
362.3454 +     * <tt>a</tt> is <tt>null</tt>.
362.3455 +     *
362.3456 +     * @param a the array whose string representation to return
362.3457 +     * @return a string representation of <tt>a</tt>
362.3458 +     * @since 1.5
362.3459 +     */
362.3460 +    public static String toString(boolean[] a) {
362.3461 +        if (a == null)
362.3462 +            return "null";
362.3463 +        int iMax = a.length - 1;
362.3464 +        if (iMax == -1)
362.3465 +            return "[]";
362.3466 +
362.3467 +        StringBuilder b = new StringBuilder();
362.3468 +        b.append('[');
362.3469 +        for (int i = 0; ; i++) {
362.3470 +            b.append(a[i]);
362.3471 +            if (i == iMax)
362.3472 +                return b.append(']').toString();
362.3473 +            b.append(", ");
362.3474 +        }
362.3475 +    }
362.3476 +
362.3477 +    /**
362.3478 +     * Returns a string representation of the contents of the specified array.
362.3479 +     * The string representation consists of a list of the array's elements,
362.3480 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3481 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3482 +     * space).  Elements are converted to strings as by
362.3483 +     * <tt>String.valueOf(float)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
362.3484 +     * is <tt>null</tt>.
362.3485 +     *
362.3486 +     * @param a the array whose string representation to return
362.3487 +     * @return a string representation of <tt>a</tt>
362.3488 +     * @since 1.5
362.3489 +     */
362.3490 +    public static String toString(float[] a) {
362.3491 +        if (a == null)
362.3492 +            return "null";
362.3493 +
362.3494 +        int iMax = a.length - 1;
362.3495 +        if (iMax == -1)
362.3496 +            return "[]";
362.3497 +
362.3498 +        StringBuilder b = new StringBuilder();
362.3499 +        b.append('[');
362.3500 +        for (int i = 0; ; i++) {
362.3501 +            b.append(a[i]);
362.3502 +            if (i == iMax)
362.3503 +                return b.append(']').toString();
362.3504 +            b.append(", ");
362.3505 +        }
362.3506 +    }
362.3507 +
362.3508 +    /**
362.3509 +     * Returns a string representation of the contents of the specified array.
362.3510 +     * The string representation consists of a list of the array's elements,
362.3511 +     * enclosed in square brackets (<tt>"[]"</tt>).  Adjacent elements are
362.3512 +     * separated by the characters <tt>", "</tt> (a comma followed by a
362.3513 +     * space).  Elements are converted to strings as by
362.3514 +     * <tt>String.valueOf(double)</tt>.  Returns <tt>"null"</tt> if <tt>a</tt>
362.3515 +     * is <tt>null</tt>.
362.3516 +     *
362.3517 +     * @param a the array whose string representation to return
362.3518 +     * @return a string representation of <tt>a</tt>
362.3519 +     * @since 1.5
362.3520 +     */
362.3521 +    public static String toString(double[] a) {
362.3522 +        if (a == null)
362.3523 +            return "null";
362.3524 +        int iMax = a.length - 1;
362.3525 +        if (iMax == -1)
362.3526 +            return "[]";
362.3527 +
362.3528 +        StringBuilder b = new StringBuilder();
362.3529 +        b.append('[');
362.3530 +        for (int i = 0; ; i++) {
362.3531 +            b.append(a[i]);
362.3532 +            if (i == iMax)
362.3533 +                return b.append(']').toString();
362.3534 +            b.append(", ");
362.3535 +        }
362.3536 +    }
362.3537 +
362.3538 +    /**
362.3539 +     * Returns a string representation of the contents of the specified array.
362.3540 +     * If the array contains other arrays as elements, they are converted to
362.3541 +     * strings by the {@link Object#toString} method inherited from
362.3542 +     * <tt>Object</tt>, which describes their <i>identities</i> rather than
362.3543 +     * their contents.
362.3544 +     *
362.3545 +     * <p>The value returned by this method is equal to the value that would
362.3546 +     * be returned by <tt>Arrays.asList(a).toString()</tt>, unless <tt>a</tt>
362.3547 +     * is <tt>null</tt>, in which case <tt>"null"</tt> is returned.
362.3548 +     *
362.3549 +     * @param a the array whose string representation to return
362.3550 +     * @return a string representation of <tt>a</tt>
362.3551 +     * @see #deepToString(Object[])
362.3552 +     * @since 1.5
362.3553 +     */
362.3554 +    public static String toString(Object[] a) {
362.3555 +        if (a == null)
362.3556 +            return "null";
362.3557 +
362.3558 +        int iMax = a.length - 1;
362.3559 +        if (iMax == -1)
362.3560 +            return "[]";
362.3561 +
362.3562 +        StringBuilder b = new StringBuilder();
362.3563 +        b.append('[');
362.3564 +        for (int i = 0; ; i++) {
362.3565 +            b.append(String.valueOf(a[i]));
362.3566 +            if (i == iMax)
362.3567 +                return b.append(']').toString();
362.3568 +            b.append(", ");
362.3569 +        }
362.3570 +    }
362.3571 +
362.3572 +    /**
362.3573 +     * Returns a string representation of the "deep contents" of the specified
362.3574 +     * array.  If the array contains other arrays as elements, the string
362.3575 +     * representation contains their contents and so on.  This method is
362.3576 +     * designed for converting multidimensional arrays to strings.
362.3577 +     *
362.3578 +     * <p>The string representation consists of a list of the array's
362.3579 +     * elements, enclosed in square brackets (<tt>"[]"</tt>).  Adjacent
362.3580 +     * elements are separated by the characters <tt>", "</tt> (a comma
362.3581 +     * followed by a space).  Elements are converted to strings as by
362.3582 +     * <tt>String.valueOf(Object)</tt>, unless they are themselves
362.3583 +     * arrays.
362.3584 +     *
362.3585 +     * <p>If an element <tt>e</tt> is an array of a primitive type, it is
362.3586 +     * converted to a string as by invoking the appropriate overloading of
362.3587 +     * <tt>Arrays.toString(e)</tt>.  If an element <tt>e</tt> is an array of a
362.3588 +     * reference type, it is converted to a string as by invoking
362.3589 +     * this method recursively.
362.3590 +     *
362.3591 +     * <p>To avoid infinite recursion, if the specified array contains itself
362.3592 +     * as an element, or contains an indirect reference to itself through one
362.3593 +     * or more levels of arrays, the self-reference is converted to the string
362.3594 +     * <tt>"[...]"</tt>.  For example, an array containing only a reference
362.3595 +     * to itself would be rendered as <tt>"[[...]]"</tt>.
362.3596 +     *
362.3597 +     * <p>This method returns <tt>"null"</tt> if the specified array
362.3598 +     * is <tt>null</tt>.
362.3599 +     *
362.3600 +     * @param a the array whose string representation to return
362.3601 +     * @return a string representation of <tt>a</tt>
362.3602 +     * @see #toString(Object[])
362.3603 +     * @since 1.5
362.3604 +     */
362.3605 +    public static String deepToString(Object[] a) {
362.3606 +        if (a == null)
362.3607 +            return "null";
362.3608 +
362.3609 +        int bufLen = 20 * a.length;
362.3610 +        if (a.length != 0 && bufLen <= 0)
362.3611 +            bufLen = Integer.MAX_VALUE;
362.3612 +        StringBuilder buf = new StringBuilder(bufLen);
362.3613 +        deepToString(a, buf, new HashSet<Object[]>());
362.3614 +        return buf.toString();
362.3615 +    }
362.3616 +
362.3617 +    private static void deepToString(Object[] a, StringBuilder buf,
362.3618 +                                     Set<Object[]> dejaVu) {
362.3619 +        if (a == null) {
362.3620 +            buf.append("null");
362.3621 +            return;
362.3622 +        }
362.3623 +        int iMax = a.length - 1;
362.3624 +        if (iMax == -1) {
362.3625 +            buf.append("[]");
362.3626 +            return;
362.3627 +        }
362.3628 +
362.3629 +        dejaVu.add(a);
362.3630 +        buf.append('[');
362.3631 +        for (int i = 0; ; i++) {
362.3632 +
362.3633 +            Object element = a[i];
362.3634 +            if (element == null) {
362.3635 +                buf.append("null");
362.3636 +            } else {
362.3637 +                Class eClass = element.getClass();
362.3638 +
362.3639 +                if (eClass.isArray()) {
362.3640 +                    if (eClass == byte[].class)
362.3641 +                        buf.append(toString((byte[]) element));
362.3642 +                    else if (eClass == short[].class)
362.3643 +                        buf.append(toString((short[]) element));
362.3644 +                    else if (eClass == int[].class)
362.3645 +                        buf.append(toString((int[]) element));
362.3646 +                    else if (eClass == long[].class)
362.3647 +                        buf.append(toString((long[]) element));
362.3648 +                    else if (eClass == char[].class)
362.3649 +                        buf.append(toString((char[]) element));
362.3650 +                    else if (eClass == float[].class)
362.3651 +                        buf.append(toString((float[]) element));
362.3652 +                    else if (eClass == double[].class)
362.3653 +                        buf.append(toString((double[]) element));
362.3654 +                    else if (eClass == boolean[].class)
362.3655 +                        buf.append(toString((boolean[]) element));
362.3656 +                    else { // element is an array of object references
362.3657 +                        if (dejaVu.contains(element))
362.3658 +                            buf.append("[...]");
362.3659 +                        else
362.3660 +                            deepToString((Object[])element, buf, dejaVu);
362.3661 +                    }
362.3662 +                } else {  // element is non-null and not an array
362.3663 +                    buf.append(element.toString());
362.3664 +                }
362.3665 +            }
362.3666 +            if (i == iMax)
362.3667 +                break;
362.3668 +            buf.append(", ");
362.3669 +        }
362.3670 +        buf.append(']');
362.3671 +        dejaVu.remove(a);
362.3672 +    }
362.3673 +}
   363.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   363.2 +++ b/rt/emul/compact/src/main/java/java/util/Collection.java	Wed Feb 27 11:24:58 2013 +0100
   363.3 @@ -0,0 +1,456 @@
   363.4 +/*
   363.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   363.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   363.7 + *
   363.8 + * This code is free software; you can redistribute it and/or modify it
   363.9 + * under the terms of the GNU General Public License version 2 only, as
  363.10 + * published by the Free Software Foundation.  Oracle designates this
  363.11 + * particular file as subject to the "Classpath" exception as provided
  363.12 + * by Oracle in the LICENSE file that accompanied this code.
  363.13 + *
  363.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  363.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  363.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  363.17 + * version 2 for more details (a copy is included in the LICENSE file that
  363.18 + * accompanied this code).
  363.19 + *
  363.20 + * You should have received a copy of the GNU General Public License version
  363.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  363.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  363.23 + *
  363.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  363.25 + * or visit www.oracle.com if you need additional information or have any
  363.26 + * questions.
  363.27 + */
  363.28 +
  363.29 +package java.util;
  363.30 +
  363.31 +/**
  363.32 + * The root interface in the <i>collection hierarchy</i>.  A collection
  363.33 + * represents a group of objects, known as its <i>elements</i>.  Some
  363.34 + * collections allow duplicate elements and others do not.  Some are ordered
  363.35 + * and others unordered.  The JDK does not provide any <i>direct</i>
  363.36 + * implementations of this interface: it provides implementations of more
  363.37 + * specific subinterfaces like <tt>Set</tt> and <tt>List</tt>.  This interface
  363.38 + * is typically used to pass collections around and manipulate them where
  363.39 + * maximum generality is desired.
  363.40 + *
  363.41 + * <p><i>Bags</i> or <i>multisets</i> (unordered collections that may contain
  363.42 + * duplicate elements) should implement this interface directly.
  363.43 + *
  363.44 + * <p>All general-purpose <tt>Collection</tt> implementation classes (which
  363.45 + * typically implement <tt>Collection</tt> indirectly through one of its
  363.46 + * subinterfaces) should provide two "standard" constructors: a void (no
  363.47 + * arguments) constructor, which creates an empty collection, and a
  363.48 + * constructor with a single argument of type <tt>Collection</tt>, which
  363.49 + * creates a new collection with the same elements as its argument.  In
  363.50 + * effect, the latter constructor allows the user to copy any collection,
  363.51 + * producing an equivalent collection of the desired implementation type.
  363.52 + * There is no way to enforce this convention (as interfaces cannot contain
  363.53 + * constructors) but all of the general-purpose <tt>Collection</tt>
  363.54 + * implementations in the Java platform libraries comply.
  363.55 + *
  363.56 + * <p>The "destructive" methods contained in this interface, that is, the
  363.57 + * methods that modify the collection on which they operate, are specified to
  363.58 + * throw <tt>UnsupportedOperationException</tt> if this collection does not
  363.59 + * support the operation.  If this is the case, these methods may, but are not
  363.60 + * required to, throw an <tt>UnsupportedOperationException</tt> if the
  363.61 + * invocation would have no effect on the collection.  For example, invoking
  363.62 + * the {@link #addAll(Collection)} method on an unmodifiable collection may,
  363.63 + * but is not required to, throw the exception if the collection to be added
  363.64 + * is empty.
  363.65 + *
  363.66 + * <p><a name="optional-restrictions"/>
  363.67 + * Some collection implementations have restrictions on the elements that
  363.68 + * they may contain.  For example, some implementations prohibit null elements,
  363.69 + * and some have restrictions on the types of their elements.  Attempting to
  363.70 + * add an ineligible element throws an unchecked exception, typically
  363.71 + * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
  363.72 + * to query the presence of an ineligible element may throw an exception,
  363.73 + * or it may simply return false; some implementations will exhibit the former
  363.74 + * behavior and some will exhibit the latter.  More generally, attempting an
  363.75 + * operation on an ineligible element whose completion would not result in
  363.76 + * the insertion of an ineligible element into the collection may throw an
  363.77 + * exception or it may succeed, at the option of the implementation.
  363.78 + * Such exceptions are marked as "optional" in the specification for this
  363.79 + * interface.
  363.80 + *
  363.81 + * <p>It is up to each collection to determine its own synchronization
  363.82 + * policy.  In the absence of a stronger guarantee by the
  363.83 + * implementation, undefined behavior may result from the invocation
  363.84 + * of any method on a collection that is being mutated by another
  363.85 + * thread; this includes direct invocations, passing the collection to
  363.86 + * a method that might perform invocations, and using an existing
  363.87 + * iterator to examine the collection.
  363.88 + *
  363.89 + * <p>Many methods in Collections Framework interfaces are defined in
  363.90 + * terms of the {@link Object#equals(Object) equals} method.  For example,
  363.91 + * the specification for the {@link #contains(Object) contains(Object o)}
  363.92 + * method says: "returns <tt>true</tt> if and only if this collection
  363.93 + * contains at least one element <tt>e</tt> such that
  363.94 + * <tt>(o==null ? e==null : o.equals(e))</tt>."  This specification should
  363.95 + * <i>not</i> be construed to imply that invoking <tt>Collection.contains</tt>
  363.96 + * with a non-null argument <tt>o</tt> will cause <tt>o.equals(e)</tt> to be
  363.97 + * invoked for any element <tt>e</tt>.  Implementations are free to implement
  363.98 + * optimizations whereby the <tt>equals</tt> invocation is avoided, for
  363.99 + * example, by first comparing the hash codes of the two elements.  (The
 363.100 + * {@link Object#hashCode()} specification guarantees that two objects with
 363.101 + * unequal hash codes cannot be equal.)  More generally, implementations of
 363.102 + * the various Collections Framework interfaces are free to take advantage of
 363.103 + * the specified behavior of underlying {@link Object} methods wherever the
 363.104 + * implementor deems it appropriate.
 363.105 + *
 363.106 + * <p>This interface is a member of the
 363.107 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 363.108 + * Java Collections Framework</a>.
 363.109 + *
 363.110 + * @param <E> the type of elements in this collection
 363.111 + *
 363.112 + * @author  Josh Bloch
 363.113 + * @author  Neal Gafter
 363.114 + * @see     Set
 363.115 + * @see     List
 363.116 + * @see     Map
 363.117 + * @see     SortedSet
 363.118 + * @see     SortedMap
 363.119 + * @see     HashSet
 363.120 + * @see     TreeSet
 363.121 + * @see     ArrayList
 363.122 + * @see     LinkedList
 363.123 + * @see     Vector
 363.124 + * @see     Collections
 363.125 + * @see     Arrays
 363.126 + * @see     AbstractCollection
 363.127 + * @since 1.2
 363.128 + */
 363.129 +
 363.130 +public interface Collection<E> extends Iterable<E> {
 363.131 +    // Query Operations
 363.132 +
 363.133 +    /**
 363.134 +     * Returns the number of elements in this collection.  If this collection
 363.135 +     * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
 363.136 +     * <tt>Integer.MAX_VALUE</tt>.
 363.137 +     *
 363.138 +     * @return the number of elements in this collection
 363.139 +     */
 363.140 +    int size();
 363.141 +
 363.142 +    /**
 363.143 +     * Returns <tt>true</tt> if this collection contains no elements.
 363.144 +     *
 363.145 +     * @return <tt>true</tt> if this collection contains no elements
 363.146 +     */
 363.147 +    boolean isEmpty();
 363.148 +
 363.149 +    /**
 363.150 +     * Returns <tt>true</tt> if this collection contains the specified element.
 363.151 +     * More formally, returns <tt>true</tt> if and only if this collection
 363.152 +     * contains at least one element <tt>e</tt> such that
 363.153 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 363.154 +     *
 363.155 +     * @param o element whose presence in this collection is to be tested
 363.156 +     * @return <tt>true</tt> if this collection contains the specified
 363.157 +     *         element
 363.158 +     * @throws ClassCastException if the type of the specified element
 363.159 +     *         is incompatible with this collection
 363.160 +     *         (<a href="#optional-restrictions">optional</a>)
 363.161 +     * @throws NullPointerException if the specified element is null and this
 363.162 +     *         collection does not permit null elements
 363.163 +     *         (<a href="#optional-restrictions">optional</a>)
 363.164 +     */
 363.165 +    boolean contains(Object o);
 363.166 +
 363.167 +    /**
 363.168 +     * Returns an iterator over the elements in this collection.  There are no
 363.169 +     * guarantees concerning the order in which the elements are returned
 363.170 +     * (unless this collection is an instance of some class that provides a
 363.171 +     * guarantee).
 363.172 +     *
 363.173 +     * @return an <tt>Iterator</tt> over the elements in this collection
 363.174 +     */
 363.175 +    Iterator<E> iterator();
 363.176 +
 363.177 +    /**
 363.178 +     * Returns an array containing all of the elements in this collection.
 363.179 +     * If this collection makes any guarantees as to what order its elements
 363.180 +     * are returned by its iterator, this method must return the elements in
 363.181 +     * the same order.
 363.182 +     *
 363.183 +     * <p>The returned array will be "safe" in that no references to it are
 363.184 +     * maintained by this collection.  (In other words, this method must
 363.185 +     * allocate a new array even if this collection is backed by an array).
 363.186 +     * The caller is thus free to modify the returned array.
 363.187 +     *
 363.188 +     * <p>This method acts as bridge between array-based and collection-based
 363.189 +     * APIs.
 363.190 +     *
 363.191 +     * @return an array containing all of the elements in this collection
 363.192 +     */
 363.193 +    Object[] toArray();
 363.194 +
 363.195 +    /**
 363.196 +     * Returns an array containing all of the elements in this collection;
 363.197 +     * the runtime type of the returned array is that of the specified array.
 363.198 +     * If the collection fits in the specified array, it is returned therein.
 363.199 +     * Otherwise, a new array is allocated with the runtime type of the
 363.200 +     * specified array and the size of this collection.
 363.201 +     *
 363.202 +     * <p>If this collection fits in the specified array with room to spare
 363.203 +     * (i.e., the array has more elements than this collection), the element
 363.204 +     * in the array immediately following the end of the collection is set to
 363.205 +     * <tt>null</tt>.  (This is useful in determining the length of this
 363.206 +     * collection <i>only</i> if the caller knows that this collection does
 363.207 +     * not contain any <tt>null</tt> elements.)
 363.208 +     *
 363.209 +     * <p>If this collection makes any guarantees as to what order its elements
 363.210 +     * are returned by its iterator, this method must return the elements in
 363.211 +     * the same order.
 363.212 +     *
 363.213 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 363.214 +     * array-based and collection-based APIs.  Further, this method allows
 363.215 +     * precise control over the runtime type of the output array, and may,
 363.216 +     * under certain circumstances, be used to save allocation costs.
 363.217 +     *
 363.218 +     * <p>Suppose <tt>x</tt> is a collection known to contain only strings.
 363.219 +     * The following code can be used to dump the collection into a newly
 363.220 +     * allocated array of <tt>String</tt>:
 363.221 +     *
 363.222 +     * <pre>
 363.223 +     *     String[] y = x.toArray(new String[0]);</pre>
 363.224 +     *
 363.225 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
 363.226 +     * <tt>toArray()</tt>.
 363.227 +     *
 363.228 +     * @param a the array into which the elements of this collection are to be
 363.229 +     *        stored, if it is big enough; otherwise, a new array of the same
 363.230 +     *        runtime type is allocated for this purpose.
 363.231 +     * @return an array containing all of the elements in this collection
 363.232 +     * @throws ArrayStoreException if the runtime type of the specified array
 363.233 +     *         is not a supertype of the runtime type of every element in
 363.234 +     *         this collection
 363.235 +     * @throws NullPointerException if the specified array is null
 363.236 +     */
 363.237 +    <T> T[] toArray(T[] a);
 363.238 +
 363.239 +    // Modification Operations
 363.240 +
 363.241 +    /**
 363.242 +     * Ensures that this collection contains the specified element (optional
 363.243 +     * operation).  Returns <tt>true</tt> if this collection changed as a
 363.244 +     * result of the call.  (Returns <tt>false</tt> if this collection does
 363.245 +     * not permit duplicates and already contains the specified element.)<p>
 363.246 +     *
 363.247 +     * Collections that support this operation may place limitations on what
 363.248 +     * elements may be added to this collection.  In particular, some
 363.249 +     * collections will refuse to add <tt>null</tt> elements, and others will
 363.250 +     * impose restrictions on the type of elements that may be added.
 363.251 +     * Collection classes should clearly specify in their documentation any
 363.252 +     * restrictions on what elements may be added.<p>
 363.253 +     *
 363.254 +     * If a collection refuses to add a particular element for any reason
 363.255 +     * other than that it already contains the element, it <i>must</i> throw
 363.256 +     * an exception (rather than returning <tt>false</tt>).  This preserves
 363.257 +     * the invariant that a collection always contains the specified element
 363.258 +     * after this call returns.
 363.259 +     *
 363.260 +     * @param e element whose presence in this collection is to be ensured
 363.261 +     * @return <tt>true</tt> if this collection changed as a result of the
 363.262 +     *         call
 363.263 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
 363.264 +     *         is not supported by this collection
 363.265 +     * @throws ClassCastException if the class of the specified element
 363.266 +     *         prevents it from being added to this collection
 363.267 +     * @throws NullPointerException if the specified element is null and this
 363.268 +     *         collection does not permit null elements
 363.269 +     * @throws IllegalArgumentException if some property of the element
 363.270 +     *         prevents it from being added to this collection
 363.271 +     * @throws IllegalStateException if the element cannot be added at this
 363.272 +     *         time due to insertion restrictions
 363.273 +     */
 363.274 +    boolean add(E e);
 363.275 +
 363.276 +    /**
 363.277 +     * Removes a single instance of the specified element from this
 363.278 +     * collection, if it is present (optional operation).  More formally,
 363.279 +     * removes an element <tt>e</tt> such that
 363.280 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
 363.281 +     * this collection contains one or more such elements.  Returns
 363.282 +     * <tt>true</tt> if this collection contained the specified element (or
 363.283 +     * equivalently, if this collection changed as a result of the call).
 363.284 +     *
 363.285 +     * @param o element to be removed from this collection, if present
 363.286 +     * @return <tt>true</tt> if an element was removed as a result of this call
 363.287 +     * @throws ClassCastException if the type of the specified element
 363.288 +     *         is incompatible with this collection
 363.289 +     *         (<a href="#optional-restrictions">optional</a>)
 363.290 +     * @throws NullPointerException if the specified element is null and this
 363.291 +     *         collection does not permit null elements
 363.292 +     *         (<a href="#optional-restrictions">optional</a>)
 363.293 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 363.294 +     *         is not supported by this collection
 363.295 +     */
 363.296 +    boolean remove(Object o);
 363.297 +
 363.298 +
 363.299 +    // Bulk Operations
 363.300 +
 363.301 +    /**
 363.302 +     * Returns <tt>true</tt> if this collection contains all of the elements
 363.303 +     * in the specified collection.
 363.304 +     *
 363.305 +     * @param  c collection to be checked for containment in this collection
 363.306 +     * @return <tt>true</tt> if this collection contains all of the elements
 363.307 +     *         in the specified collection
 363.308 +     * @throws ClassCastException if the types of one or more elements
 363.309 +     *         in the specified collection are incompatible with this
 363.310 +     *         collection
 363.311 +     *         (<a href="#optional-restrictions">optional</a>)
 363.312 +     * @throws NullPointerException if the specified collection contains one
 363.313 +     *         or more null elements and this collection does not permit null
 363.314 +     *         elements
 363.315 +     *         (<a href="#optional-restrictions">optional</a>),
 363.316 +     *         or if the specified collection is null.
 363.317 +     * @see    #contains(Object)
 363.318 +     */
 363.319 +    boolean containsAll(Collection<?> c);
 363.320 +
 363.321 +    /**
 363.322 +     * Adds all of the elements in the specified collection to this collection
 363.323 +     * (optional operation).  The behavior of this operation is undefined if
 363.324 +     * the specified collection is modified while the operation is in progress.
 363.325 +     * (This implies that the behavior of this call is undefined if the
 363.326 +     * specified collection is this collection, and this collection is
 363.327 +     * nonempty.)
 363.328 +     *
 363.329 +     * @param c collection containing elements to be added to this collection
 363.330 +     * @return <tt>true</tt> if this collection changed as a result of the call
 363.331 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 363.332 +     *         is not supported by this collection
 363.333 +     * @throws ClassCastException if the class of an element of the specified
 363.334 +     *         collection prevents it from being added to this collection
 363.335 +     * @throws NullPointerException if the specified collection contains a
 363.336 +     *         null element and this collection does not permit null elements,
 363.337 +     *         or if the specified collection is null
 363.338 +     * @throws IllegalArgumentException if some property of an element of the
 363.339 +     *         specified collection prevents it from being added to this
 363.340 +     *         collection
 363.341 +     * @throws IllegalStateException if not all the elements can be added at
 363.342 +     *         this time due to insertion restrictions
 363.343 +     * @see #add(Object)
 363.344 +     */
 363.345 +    boolean addAll(Collection<? extends E> c);
 363.346 +
 363.347 +    /**
 363.348 +     * Removes all of this collection's elements that are also contained in the
 363.349 +     * specified collection (optional operation).  After this call returns,
 363.350 +     * this collection will contain no elements in common with the specified
 363.351 +     * collection.
 363.352 +     *
 363.353 +     * @param c collection containing elements to be removed from this collection
 363.354 +     * @return <tt>true</tt> if this collection changed as a result of the
 363.355 +     *         call
 363.356 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> method
 363.357 +     *         is not supported by this collection
 363.358 +     * @throws ClassCastException if the types of one or more elements
 363.359 +     *         in this collection are incompatible with the specified
 363.360 +     *         collection
 363.361 +     *         (<a href="#optional-restrictions">optional</a>)
 363.362 +     * @throws NullPointerException if this collection contains one or more
 363.363 +     *         null elements and the specified collection does not support
 363.364 +     *         null elements
 363.365 +     *         (<a href="#optional-restrictions">optional</a>),
 363.366 +     *         or if the specified collection is null
 363.367 +     * @see #remove(Object)
 363.368 +     * @see #contains(Object)
 363.369 +     */
 363.370 +    boolean removeAll(Collection<?> c);
 363.371 +
 363.372 +    /**
 363.373 +     * Retains only the elements in this collection that are contained in the
 363.374 +     * specified collection (optional operation).  In other words, removes from
 363.375 +     * this collection all of its elements that are not contained in the
 363.376 +     * specified collection.
 363.377 +     *
 363.378 +     * @param c collection containing elements to be retained in this collection
 363.379 +     * @return <tt>true</tt> if this collection changed as a result of the call
 363.380 +     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 363.381 +     *         is not supported by this collection
 363.382 +     * @throws ClassCastException if the types of one or more elements
 363.383 +     *         in this collection are incompatible with the specified
 363.384 +     *         collection
 363.385 +     *         (<a href="#optional-restrictions">optional</a>)
 363.386 +     * @throws NullPointerException if this collection contains one or more
 363.387 +     *         null elements and the specified collection does not permit null
 363.388 +     *         elements
 363.389 +     *         (<a href="#optional-restrictions">optional</a>),
 363.390 +     *         or if the specified collection is null
 363.391 +     * @see #remove(Object)
 363.392 +     * @see #contains(Object)
 363.393 +     */
 363.394 +    boolean retainAll(Collection<?> c);
 363.395 +
 363.396 +    /**
 363.397 +     * Removes all of the elements from this collection (optional operation).
 363.398 +     * The collection will be empty after this method returns.
 363.399 +     *
 363.400 +     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
 363.401 +     *         is not supported by this collection
 363.402 +     */
 363.403 +    void clear();
 363.404 +
 363.405 +
 363.406 +    // Comparison and hashing
 363.407 +
 363.408 +    /**
 363.409 +     * Compares the specified object with this collection for equality. <p>
 363.410 +     *
 363.411 +     * While the <tt>Collection</tt> interface adds no stipulations to the
 363.412 +     * general contract for the <tt>Object.equals</tt>, programmers who
 363.413 +     * implement the <tt>Collection</tt> interface "directly" (in other words,
 363.414 +     * create a class that is a <tt>Collection</tt> but is not a <tt>Set</tt>
 363.415 +     * or a <tt>List</tt>) must exercise care if they choose to override the
 363.416 +     * <tt>Object.equals</tt>.  It is not necessary to do so, and the simplest
 363.417 +     * course of action is to rely on <tt>Object</tt>'s implementation, but
 363.418 +     * the implementor may wish to implement a "value comparison" in place of
 363.419 +     * the default "reference comparison."  (The <tt>List</tt> and
 363.420 +     * <tt>Set</tt> interfaces mandate such value comparisons.)<p>
 363.421 +     *
 363.422 +     * The general contract for the <tt>Object.equals</tt> method states that
 363.423 +     * equals must be symmetric (in other words, <tt>a.equals(b)</tt> if and
 363.424 +     * only if <tt>b.equals(a)</tt>).  The contracts for <tt>List.equals</tt>
 363.425 +     * and <tt>Set.equals</tt> state that lists are only equal to other lists,
 363.426 +     * and sets to other sets.  Thus, a custom <tt>equals</tt> method for a
 363.427 +     * collection class that implements neither the <tt>List</tt> nor
 363.428 +     * <tt>Set</tt> interface must return <tt>false</tt> when this collection
 363.429 +     * is compared to any list or set.  (By the same logic, it is not possible
 363.430 +     * to write a class that correctly implements both the <tt>Set</tt> and
 363.431 +     * <tt>List</tt> interfaces.)
 363.432 +     *
 363.433 +     * @param o object to be compared for equality with this collection
 363.434 +     * @return <tt>true</tt> if the specified object is equal to this
 363.435 +     * collection
 363.436 +     *
 363.437 +     * @see Object#equals(Object)
 363.438 +     * @see Set#equals(Object)
 363.439 +     * @see List#equals(Object)
 363.440 +     */
 363.441 +    boolean equals(Object o);
 363.442 +
 363.443 +    /**
 363.444 +     * Returns the hash code value for this collection.  While the
 363.445 +     * <tt>Collection</tt> interface adds no stipulations to the general
 363.446 +     * contract for the <tt>Object.hashCode</tt> method, programmers should
 363.447 +     * take note that any class that overrides the <tt>Object.equals</tt>
 363.448 +     * method must also override the <tt>Object.hashCode</tt> method in order
 363.449 +     * to satisfy the general contract for the <tt>Object.hashCode</tt> method.
 363.450 +     * In particular, <tt>c1.equals(c2)</tt> implies that
 363.451 +     * <tt>c1.hashCode()==c2.hashCode()</tt>.
 363.452 +     *
 363.453 +     * @return the hash code value for this collection
 363.454 +     *
 363.455 +     * @see Object#hashCode()
 363.456 +     * @see Object#equals(Object)
 363.457 +     */
 363.458 +    int hashCode();
 363.459 +}
   364.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   364.2 +++ b/rt/emul/compact/src/main/java/java/util/Collections.java	Wed Feb 27 11:24:58 2013 +0100
   364.3 @@ -0,0 +1,3953 @@
   364.4 +/*
   364.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   364.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   364.7 + *
   364.8 + * This code is free software; you can redistribute it and/or modify it
   364.9 + * under the terms of the GNU General Public License version 2 only, as
  364.10 + * published by the Free Software Foundation.  Oracle designates this
  364.11 + * particular file as subject to the "Classpath" exception as provided
  364.12 + * by Oracle in the LICENSE file that accompanied this code.
  364.13 + *
  364.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  364.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  364.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  364.17 + * version 2 for more details (a copy is included in the LICENSE file that
  364.18 + * accompanied this code).
  364.19 + *
  364.20 + * You should have received a copy of the GNU General Public License version
  364.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  364.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  364.23 + *
  364.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  364.25 + * or visit www.oracle.com if you need additional information or have any
  364.26 + * questions.
  364.27 + */
  364.28 +
  364.29 +package java.util;
  364.30 +import java.io.Serializable;
  364.31 +import java.io.IOException;
  364.32 +import java.lang.reflect.Array;
  364.33 +
  364.34 +/**
  364.35 + * This class consists exclusively of static methods that operate on or return
  364.36 + * collections.  It contains polymorphic algorithms that operate on
  364.37 + * collections, "wrappers", which return a new collection backed by a
  364.38 + * specified collection, and a few other odds and ends.
  364.39 + *
  364.40 + * <p>The methods of this class all throw a <tt>NullPointerException</tt>
  364.41 + * if the collections or class objects provided to them are null.
  364.42 + *
  364.43 + * <p>The documentation for the polymorphic algorithms contained in this class
  364.44 + * generally includes a brief description of the <i>implementation</i>.  Such
  364.45 + * descriptions should be regarded as <i>implementation notes</i>, rather than
  364.46 + * parts of the <i>specification</i>.  Implementors should feel free to
  364.47 + * substitute other algorithms, so long as the specification itself is adhered
  364.48 + * to.  (For example, the algorithm used by <tt>sort</tt> does not have to be
  364.49 + * a mergesort, but it does have to be <i>stable</i>.)
  364.50 + *
  364.51 + * <p>The "destructive" algorithms contained in this class, that is, the
  364.52 + * algorithms that modify the collection on which they operate, are specified
  364.53 + * to throw <tt>UnsupportedOperationException</tt> if the collection does not
  364.54 + * support the appropriate mutation primitive(s), such as the <tt>set</tt>
  364.55 + * method.  These algorithms may, but are not required to, throw this
  364.56 + * exception if an invocation would have no effect on the collection.  For
  364.57 + * example, invoking the <tt>sort</tt> method on an unmodifiable list that is
  364.58 + * already sorted may or may not throw <tt>UnsupportedOperationException</tt>.
  364.59 + *
  364.60 + * <p>This class is a member of the
  364.61 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  364.62 + * Java Collections Framework</a>.
  364.63 + *
  364.64 + * @author  Josh Bloch
  364.65 + * @author  Neal Gafter
  364.66 + * @see     Collection
  364.67 + * @see     Set
  364.68 + * @see     List
  364.69 + * @see     Map
  364.70 + * @since   1.2
  364.71 + */
  364.72 +
  364.73 +public class Collections {
  364.74 +    // Suppresses default constructor, ensuring non-instantiability.
  364.75 +    private Collections() {
  364.76 +    }
  364.77 +
  364.78 +    // Algorithms
  364.79 +
  364.80 +    /*
  364.81 +     * Tuning parameters for algorithms - Many of the List algorithms have
  364.82 +     * two implementations, one of which is appropriate for RandomAccess
  364.83 +     * lists, the other for "sequential."  Often, the random access variant
  364.84 +     * yields better performance on small sequential access lists.  The
  364.85 +     * tuning parameters below determine the cutoff point for what constitutes
  364.86 +     * a "small" sequential access list for each algorithm.  The values below
  364.87 +     * were empirically determined to work well for LinkedList. Hopefully
  364.88 +     * they should be reasonable for other sequential access List
  364.89 +     * implementations.  Those doing performance work on this code would
  364.90 +     * do well to validate the values of these parameters from time to time.
  364.91 +     * (The first word of each tuning parameter name is the algorithm to which
  364.92 +     * it applies.)
  364.93 +     */
  364.94 +    private static final int BINARYSEARCH_THRESHOLD   = 5000;
  364.95 +    private static final int REVERSE_THRESHOLD        =   18;
  364.96 +    private static final int SHUFFLE_THRESHOLD        =    5;
  364.97 +    private static final int FILL_THRESHOLD           =   25;
  364.98 +    private static final int ROTATE_THRESHOLD         =  100;
  364.99 +    private static final int COPY_THRESHOLD           =   10;
 364.100 +    private static final int REPLACEALL_THRESHOLD     =   11;
 364.101 +    private static final int INDEXOFSUBLIST_THRESHOLD =   35;
 364.102 +
 364.103 +    /**
 364.104 +     * Sorts the specified list into ascending order, according to the
 364.105 +     * {@linkplain Comparable natural ordering} of its elements.
 364.106 +     * All elements in the list must implement the {@link Comparable}
 364.107 +     * interface.  Furthermore, all elements in the list must be
 364.108 +     * <i>mutually comparable</i> (that is, {@code e1.compareTo(e2)}
 364.109 +     * must not throw a {@code ClassCastException} for any elements
 364.110 +     * {@code e1} and {@code e2} in the list).
 364.111 +     *
 364.112 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
 364.113 +     * not be reordered as a result of the sort.
 364.114 +     *
 364.115 +     * <p>The specified list must be modifiable, but need not be resizable.
 364.116 +     *
 364.117 +     * <p>Implementation note: This implementation is a stable, adaptive,
 364.118 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
 364.119 +     * when the input array is partially sorted, while offering the
 364.120 +     * performance of a traditional mergesort when the input array is
 364.121 +     * randomly ordered.  If the input array is nearly sorted, the
 364.122 +     * implementation requires approximately n comparisons.  Temporary
 364.123 +     * storage requirements vary from a small constant for nearly sorted
 364.124 +     * input arrays to n/2 object references for randomly ordered input
 364.125 +     * arrays.
 364.126 +     *
 364.127 +     * <p>The implementation takes equal advantage of ascending and
 364.128 +     * descending order in its input array, and can take advantage of
 364.129 +     * ascending and descending order in different parts of the same
 364.130 +     * input array.  It is well-suited to merging two or more sorted arrays:
 364.131 +     * simply concatenate the arrays and sort the resulting array.
 364.132 +     *
 364.133 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
 364.134 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
 364.135 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
 364.136 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
 364.137 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
 364.138 +     * January 1993.
 364.139 +     *
 364.140 +     * <p>This implementation dumps the specified list into an array, sorts
 364.141 +     * the array, and iterates over the list resetting each element
 364.142 +     * from the corresponding position in the array.  This avoids the
 364.143 +     * n<sup>2</sup> log(n) performance that would result from attempting
 364.144 +     * to sort a linked list in place.
 364.145 +     *
 364.146 +     * @param  list the list to be sorted.
 364.147 +     * @throws ClassCastException if the list contains elements that are not
 364.148 +     *         <i>mutually comparable</i> (for example, strings and integers).
 364.149 +     * @throws UnsupportedOperationException if the specified list's
 364.150 +     *         list-iterator does not support the {@code set} operation.
 364.151 +     * @throws IllegalArgumentException (optional) if the implementation
 364.152 +     *         detects that the natural ordering of the list elements is
 364.153 +     *         found to violate the {@link Comparable} contract
 364.154 +     */
 364.155 +    public static <T extends Comparable<? super T>> void sort(List<T> list) {
 364.156 +        Object[] a = list.toArray();
 364.157 +        Arrays.sort(a);
 364.158 +        ListIterator<T> i = list.listIterator();
 364.159 +        for (int j=0; j<a.length; j++) {
 364.160 +            i.next();
 364.161 +            i.set((T)a[j]);
 364.162 +        }
 364.163 +    }
 364.164 +
 364.165 +    /**
 364.166 +     * Sorts the specified list according to the order induced by the
 364.167 +     * specified comparator.  All elements in the list must be <i>mutually
 364.168 +     * comparable</i> using the specified comparator (that is,
 364.169 +     * {@code c.compare(e1, e2)} must not throw a {@code ClassCastException}
 364.170 +     * for any elements {@code e1} and {@code e2} in the list).
 364.171 +     *
 364.172 +     * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will
 364.173 +     * not be reordered as a result of the sort.
 364.174 +     *
 364.175 +     * <p>The specified list must be modifiable, but need not be resizable.
 364.176 +     *
 364.177 +     * <p>Implementation note: This implementation is a stable, adaptive,
 364.178 +     * iterative mergesort that requires far fewer than n lg(n) comparisons
 364.179 +     * when the input array is partially sorted, while offering the
 364.180 +     * performance of a traditional mergesort when the input array is
 364.181 +     * randomly ordered.  If the input array is nearly sorted, the
 364.182 +     * implementation requires approximately n comparisons.  Temporary
 364.183 +     * storage requirements vary from a small constant for nearly sorted
 364.184 +     * input arrays to n/2 object references for randomly ordered input
 364.185 +     * arrays.
 364.186 +     *
 364.187 +     * <p>The implementation takes equal advantage of ascending and
 364.188 +     * descending order in its input array, and can take advantage of
 364.189 +     * ascending and descending order in different parts of the same
 364.190 +     * input array.  It is well-suited to merging two or more sorted arrays:
 364.191 +     * simply concatenate the arrays and sort the resulting array.
 364.192 +     *
 364.193 +     * <p>The implementation was adapted from Tim Peters's list sort for Python
 364.194 +     * (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
 364.195 +     * TimSort</a>).  It uses techiques from Peter McIlroy's "Optimistic
 364.196 +     * Sorting and Information Theoretic Complexity", in Proceedings of the
 364.197 +     * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
 364.198 +     * January 1993.
 364.199 +     *
 364.200 +     * <p>This implementation dumps the specified list into an array, sorts
 364.201 +     * the array, and iterates over the list resetting each element
 364.202 +     * from the corresponding position in the array.  This avoids the
 364.203 +     * n<sup>2</sup> log(n) performance that would result from attempting
 364.204 +     * to sort a linked list in place.
 364.205 +     *
 364.206 +     * @param  list the list to be sorted.
 364.207 +     * @param  c the comparator to determine the order of the list.  A
 364.208 +     *        {@code null} value indicates that the elements' <i>natural
 364.209 +     *        ordering</i> should be used.
 364.210 +     * @throws ClassCastException if the list contains elements that are not
 364.211 +     *         <i>mutually comparable</i> using the specified comparator.
 364.212 +     * @throws UnsupportedOperationException if the specified list's
 364.213 +     *         list-iterator does not support the {@code set} operation.
 364.214 +     * @throws IllegalArgumentException (optional) if the comparator is
 364.215 +     *         found to violate the {@link Comparator} contract
 364.216 +     */
 364.217 +    public static <T> void sort(List<T> list, Comparator<? super T> c) {
 364.218 +        Object[] a = list.toArray();
 364.219 +        Arrays.sort(a, (Comparator)c);
 364.220 +        ListIterator i = list.listIterator();
 364.221 +        for (int j=0; j<a.length; j++) {
 364.222 +            i.next();
 364.223 +            i.set(a[j]);
 364.224 +        }
 364.225 +    }
 364.226 +
 364.227 +
 364.228 +    /**
 364.229 +     * Searches the specified list for the specified object using the binary
 364.230 +     * search algorithm.  The list must be sorted into ascending order
 364.231 +     * according to the {@linkplain Comparable natural ordering} of its
 364.232 +     * elements (as by the {@link #sort(List)} method) prior to making this
 364.233 +     * call.  If it is not sorted, the results are undefined.  If the list
 364.234 +     * contains multiple elements equal to the specified object, there is no
 364.235 +     * guarantee which one will be found.
 364.236 +     *
 364.237 +     * <p>This method runs in log(n) time for a "random access" list (which
 364.238 +     * provides near-constant-time positional access).  If the specified list
 364.239 +     * does not implement the {@link RandomAccess} interface and is large,
 364.240 +     * this method will do an iterator-based binary search that performs
 364.241 +     * O(n) link traversals and O(log n) element comparisons.
 364.242 +     *
 364.243 +     * @param  list the list to be searched.
 364.244 +     * @param  key the key to be searched for.
 364.245 +     * @return the index of the search key, if it is contained in the list;
 364.246 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 364.247 +     *         <i>insertion point</i> is defined as the point at which the
 364.248 +     *         key would be inserted into the list: the index of the first
 364.249 +     *         element greater than the key, or <tt>list.size()</tt> if all
 364.250 +     *         elements in the list are less than the specified key.  Note
 364.251 +     *         that this guarantees that the return value will be &gt;= 0 if
 364.252 +     *         and only if the key is found.
 364.253 +     * @throws ClassCastException if the list contains elements that are not
 364.254 +     *         <i>mutually comparable</i> (for example, strings and
 364.255 +     *         integers), or the search key is not mutually comparable
 364.256 +     *         with the elements of the list.
 364.257 +     */
 364.258 +    public static <T>
 364.259 +    int binarySearch(List<? extends Comparable<? super T>> list, T key) {
 364.260 +        if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
 364.261 +            return Collections.indexedBinarySearch(list, key);
 364.262 +        else
 364.263 +            return Collections.iteratorBinarySearch(list, key);
 364.264 +    }
 364.265 +
 364.266 +    private static <T>
 364.267 +    int indexedBinarySearch(List<? extends Comparable<? super T>> list, T key)
 364.268 +    {
 364.269 +        int low = 0;
 364.270 +        int high = list.size()-1;
 364.271 +
 364.272 +        while (low <= high) {
 364.273 +            int mid = (low + high) >>> 1;
 364.274 +            Comparable<? super T> midVal = list.get(mid);
 364.275 +            int cmp = midVal.compareTo(key);
 364.276 +
 364.277 +            if (cmp < 0)
 364.278 +                low = mid + 1;
 364.279 +            else if (cmp > 0)
 364.280 +                high = mid - 1;
 364.281 +            else
 364.282 +                return mid; // key found
 364.283 +        }
 364.284 +        return -(low + 1);  // key not found
 364.285 +    }
 364.286 +
 364.287 +    private static <T>
 364.288 +    int iteratorBinarySearch(List<? extends Comparable<? super T>> list, T key)
 364.289 +    {
 364.290 +        int low = 0;
 364.291 +        int high = list.size()-1;
 364.292 +        ListIterator<? extends Comparable<? super T>> i = list.listIterator();
 364.293 +
 364.294 +        while (low <= high) {
 364.295 +            int mid = (low + high) >>> 1;
 364.296 +            Comparable<? super T> midVal = get(i, mid);
 364.297 +            int cmp = midVal.compareTo(key);
 364.298 +
 364.299 +            if (cmp < 0)
 364.300 +                low = mid + 1;
 364.301 +            else if (cmp > 0)
 364.302 +                high = mid - 1;
 364.303 +            else
 364.304 +                return mid; // key found
 364.305 +        }
 364.306 +        return -(low + 1);  // key not found
 364.307 +    }
 364.308 +
 364.309 +    /**
 364.310 +     * Gets the ith element from the given list by repositioning the specified
 364.311 +     * list listIterator.
 364.312 +     */
 364.313 +    private static <T> T get(ListIterator<? extends T> i, int index) {
 364.314 +        T obj = null;
 364.315 +        int pos = i.nextIndex();
 364.316 +        if (pos <= index) {
 364.317 +            do {
 364.318 +                obj = i.next();
 364.319 +            } while (pos++ < index);
 364.320 +        } else {
 364.321 +            do {
 364.322 +                obj = i.previous();
 364.323 +            } while (--pos > index);
 364.324 +        }
 364.325 +        return obj;
 364.326 +    }
 364.327 +
 364.328 +    /**
 364.329 +     * Searches the specified list for the specified object using the binary
 364.330 +     * search algorithm.  The list must be sorted into ascending order
 364.331 +     * according to the specified comparator (as by the
 364.332 +     * {@link #sort(List, Comparator) sort(List, Comparator)}
 364.333 +     * method), prior to making this call.  If it is
 364.334 +     * not sorted, the results are undefined.  If the list contains multiple
 364.335 +     * elements equal to the specified object, there is no guarantee which one
 364.336 +     * will be found.
 364.337 +     *
 364.338 +     * <p>This method runs in log(n) time for a "random access" list (which
 364.339 +     * provides near-constant-time positional access).  If the specified list
 364.340 +     * does not implement the {@link RandomAccess} interface and is large,
 364.341 +     * this method will do an iterator-based binary search that performs
 364.342 +     * O(n) link traversals and O(log n) element comparisons.
 364.343 +     *
 364.344 +     * @param  list the list to be searched.
 364.345 +     * @param  key the key to be searched for.
 364.346 +     * @param  c the comparator by which the list is ordered.
 364.347 +     *         A <tt>null</tt> value indicates that the elements'
 364.348 +     *         {@linkplain Comparable natural ordering} should be used.
 364.349 +     * @return the index of the search key, if it is contained in the list;
 364.350 +     *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The
 364.351 +     *         <i>insertion point</i> is defined as the point at which the
 364.352 +     *         key would be inserted into the list: the index of the first
 364.353 +     *         element greater than the key, or <tt>list.size()</tt> if all
 364.354 +     *         elements in the list are less than the specified key.  Note
 364.355 +     *         that this guarantees that the return value will be &gt;= 0 if
 364.356 +     *         and only if the key is found.
 364.357 +     * @throws ClassCastException if the list contains elements that are not
 364.358 +     *         <i>mutually comparable</i> using the specified comparator,
 364.359 +     *         or the search key is not mutually comparable with the
 364.360 +     *         elements of the list using this comparator.
 364.361 +     */
 364.362 +    public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) {
 364.363 +        if (c==null)
 364.364 +            return binarySearch((List) list, key);
 364.365 +
 364.366 +        if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
 364.367 +            return Collections.indexedBinarySearch(list, key, c);
 364.368 +        else
 364.369 +            return Collections.iteratorBinarySearch(list, key, c);
 364.370 +    }
 364.371 +
 364.372 +    private static <T> int indexedBinarySearch(List<? extends T> l, T key, Comparator<? super T> c) {
 364.373 +        int low = 0;
 364.374 +        int high = l.size()-1;
 364.375 +
 364.376 +        while (low <= high) {
 364.377 +            int mid = (low + high) >>> 1;
 364.378 +            T midVal = l.get(mid);
 364.379 +            int cmp = c.compare(midVal, key);
 364.380 +
 364.381 +            if (cmp < 0)
 364.382 +                low = mid + 1;
 364.383 +            else if (cmp > 0)
 364.384 +                high = mid - 1;
 364.385 +            else
 364.386 +                return mid; // key found
 364.387 +        }
 364.388 +        return -(low + 1);  // key not found
 364.389 +    }
 364.390 +
 364.391 +    private static <T> int iteratorBinarySearch(List<? extends T> l, T key, Comparator<? super T> c) {
 364.392 +        int low = 0;
 364.393 +        int high = l.size()-1;
 364.394 +        ListIterator<? extends T> i = l.listIterator();
 364.395 +
 364.396 +        while (low <= high) {
 364.397 +            int mid = (low + high) >>> 1;
 364.398 +            T midVal = get(i, mid);
 364.399 +            int cmp = c.compare(midVal, key);
 364.400 +
 364.401 +            if (cmp < 0)
 364.402 +                low = mid + 1;
 364.403 +            else if (cmp > 0)
 364.404 +                high = mid - 1;
 364.405 +            else
 364.406 +                return mid; // key found
 364.407 +        }
 364.408 +        return -(low + 1);  // key not found
 364.409 +    }
 364.410 +
 364.411 +    private interface SelfComparable extends Comparable<SelfComparable> {}
 364.412 +
 364.413 +
 364.414 +    /**
 364.415 +     * Reverses the order of the elements in the specified list.<p>
 364.416 +     *
 364.417 +     * This method runs in linear time.
 364.418 +     *
 364.419 +     * @param  list the list whose elements are to be reversed.
 364.420 +     * @throws UnsupportedOperationException if the specified list or
 364.421 +     *         its list-iterator does not support the <tt>set</tt> operation.
 364.422 +     */
 364.423 +    public static void reverse(List<?> list) {
 364.424 +        int size = list.size();
 364.425 +        if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
 364.426 +            for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--)
 364.427 +                swap(list, i, j);
 364.428 +        } else {
 364.429 +            ListIterator fwd = list.listIterator();
 364.430 +            ListIterator rev = list.listIterator(size);
 364.431 +            for (int i=0, mid=list.size()>>1; i<mid; i++) {
 364.432 +                Object tmp = fwd.next();
 364.433 +                fwd.set(rev.previous());
 364.434 +                rev.set(tmp);
 364.435 +            }
 364.436 +        }
 364.437 +    }
 364.438 +
 364.439 +    /**
 364.440 +     * Randomly permutes the specified list using a default source of
 364.441 +     * randomness.  All permutations occur with approximately equal
 364.442 +     * likelihood.<p>
 364.443 +     *
 364.444 +     * The hedge "approximately" is used in the foregoing description because
 364.445 +     * default source of randomness is only approximately an unbiased source
 364.446 +     * of independently chosen bits. If it were a perfect source of randomly
 364.447 +     * chosen bits, then the algorithm would choose permutations with perfect
 364.448 +     * uniformity.<p>
 364.449 +     *
 364.450 +     * This implementation traverses the list backwards, from the last element
 364.451 +     * up to the second, repeatedly swapping a randomly selected element into
 364.452 +     * the "current position".  Elements are randomly selected from the
 364.453 +     * portion of the list that runs from the first element to the current
 364.454 +     * position, inclusive.<p>
 364.455 +     *
 364.456 +     * This method runs in linear time.  If the specified list does not
 364.457 +     * implement the {@link RandomAccess} interface and is large, this
 364.458 +     * implementation dumps the specified list into an array before shuffling
 364.459 +     * it, and dumps the shuffled array back into the list.  This avoids the
 364.460 +     * quadratic behavior that would result from shuffling a "sequential
 364.461 +     * access" list in place.
 364.462 +     *
 364.463 +     * @param  list the list to be shuffled.
 364.464 +     * @throws UnsupportedOperationException if the specified list or
 364.465 +     *         its list-iterator does not support the <tt>set</tt> operation.
 364.466 +     */
 364.467 +    public static void shuffle(List<?> list) {
 364.468 +        Random rnd = r;
 364.469 +        if (rnd == null)
 364.470 +            r = rnd = new Random();
 364.471 +        shuffle(list, rnd);
 364.472 +    }
 364.473 +    private static Random r;
 364.474 +
 364.475 +    /**
 364.476 +     * Randomly permute the specified list using the specified source of
 364.477 +     * randomness.  All permutations occur with equal likelihood
 364.478 +     * assuming that the source of randomness is fair.<p>
 364.479 +     *
 364.480 +     * This implementation traverses the list backwards, from the last element
 364.481 +     * up to the second, repeatedly swapping a randomly selected element into
 364.482 +     * the "current position".  Elements are randomly selected from the
 364.483 +     * portion of the list that runs from the first element to the current
 364.484 +     * position, inclusive.<p>
 364.485 +     *
 364.486 +     * This method runs in linear time.  If the specified list does not
 364.487 +     * implement the {@link RandomAccess} interface and is large, this
 364.488 +     * implementation dumps the specified list into an array before shuffling
 364.489 +     * it, and dumps the shuffled array back into the list.  This avoids the
 364.490 +     * quadratic behavior that would result from shuffling a "sequential
 364.491 +     * access" list in place.
 364.492 +     *
 364.493 +     * @param  list the list to be shuffled.
 364.494 +     * @param  rnd the source of randomness to use to shuffle the list.
 364.495 +     * @throws UnsupportedOperationException if the specified list or its
 364.496 +     *         list-iterator does not support the <tt>set</tt> operation.
 364.497 +     */
 364.498 +    public static void shuffle(List<?> list, Random rnd) {
 364.499 +        int size = list.size();
 364.500 +        if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
 364.501 +            for (int i=size; i>1; i--)
 364.502 +                swap(list, i-1, rnd.nextInt(i));
 364.503 +        } else {
 364.504 +            Object arr[] = list.toArray();
 364.505 +
 364.506 +            // Shuffle array
 364.507 +            for (int i=size; i>1; i--)
 364.508 +                swap(arr, i-1, rnd.nextInt(i));
 364.509 +
 364.510 +            // Dump array back into list
 364.511 +            ListIterator it = list.listIterator();
 364.512 +            for (int i=0; i<arr.length; i++) {
 364.513 +                it.next();
 364.514 +                it.set(arr[i]);
 364.515 +            }
 364.516 +        }
 364.517 +    }
 364.518 +
 364.519 +    /**
 364.520 +     * Swaps the elements at the specified positions in the specified list.
 364.521 +     * (If the specified positions are equal, invoking this method leaves
 364.522 +     * the list unchanged.)
 364.523 +     *
 364.524 +     * @param list The list in which to swap elements.
 364.525 +     * @param i the index of one element to be swapped.
 364.526 +     * @param j the index of the other element to be swapped.
 364.527 +     * @throws IndexOutOfBoundsException if either <tt>i</tt> or <tt>j</tt>
 364.528 +     *         is out of range (i &lt; 0 || i &gt;= list.size()
 364.529 +     *         || j &lt; 0 || j &gt;= list.size()).
 364.530 +     * @since 1.4
 364.531 +     */
 364.532 +    public static void swap(List<?> list, int i, int j) {
 364.533 +        final List l = list;
 364.534 +        l.set(i, l.set(j, l.get(i)));
 364.535 +    }
 364.536 +
 364.537 +    /**
 364.538 +     * Swaps the two specified elements in the specified array.
 364.539 +     */
 364.540 +    private static void swap(Object[] arr, int i, int j) {
 364.541 +        Object tmp = arr[i];
 364.542 +        arr[i] = arr[j];
 364.543 +        arr[j] = tmp;
 364.544 +    }
 364.545 +
 364.546 +    /**
 364.547 +     * Replaces all of the elements of the specified list with the specified
 364.548 +     * element. <p>
 364.549 +     *
 364.550 +     * This method runs in linear time.
 364.551 +     *
 364.552 +     * @param  list the list to be filled with the specified element.
 364.553 +     * @param  obj The element with which to fill the specified list.
 364.554 +     * @throws UnsupportedOperationException if the specified list or its
 364.555 +     *         list-iterator does not support the <tt>set</tt> operation.
 364.556 +     */
 364.557 +    public static <T> void fill(List<? super T> list, T obj) {
 364.558 +        int size = list.size();
 364.559 +
 364.560 +        if (size < FILL_THRESHOLD || list instanceof RandomAccess) {
 364.561 +            for (int i=0; i<size; i++)
 364.562 +                list.set(i, obj);
 364.563 +        } else {
 364.564 +            ListIterator<? super T> itr = list.listIterator();
 364.565 +            for (int i=0; i<size; i++) {
 364.566 +                itr.next();
 364.567 +                itr.set(obj);
 364.568 +            }
 364.569 +        }
 364.570 +    }
 364.571 +
 364.572 +    /**
 364.573 +     * Copies all of the elements from one list into another.  After the
 364.574 +     * operation, the index of each copied element in the destination list
 364.575 +     * will be identical to its index in the source list.  The destination
 364.576 +     * list must be at least as long as the source list.  If it is longer, the
 364.577 +     * remaining elements in the destination list are unaffected. <p>
 364.578 +     *
 364.579 +     * This method runs in linear time.
 364.580 +     *
 364.581 +     * @param  dest The destination list.
 364.582 +     * @param  src The source list.
 364.583 +     * @throws IndexOutOfBoundsException if the destination list is too small
 364.584 +     *         to contain the entire source List.
 364.585 +     * @throws UnsupportedOperationException if the destination list's
 364.586 +     *         list-iterator does not support the <tt>set</tt> operation.
 364.587 +     */
 364.588 +    public static <T> void copy(List<? super T> dest, List<? extends T> src) {
 364.589 +        int srcSize = src.size();
 364.590 +        if (srcSize > dest.size())
 364.591 +            throw new IndexOutOfBoundsException("Source does not fit in dest");
 364.592 +
 364.593 +        if (srcSize < COPY_THRESHOLD ||
 364.594 +            (src instanceof RandomAccess && dest instanceof RandomAccess)) {
 364.595 +            for (int i=0; i<srcSize; i++)
 364.596 +                dest.set(i, src.get(i));
 364.597 +        } else {
 364.598 +            ListIterator<? super T> di=dest.listIterator();
 364.599 +            ListIterator<? extends T> si=src.listIterator();
 364.600 +            for (int i=0; i<srcSize; i++) {
 364.601 +                di.next();
 364.602 +                di.set(si.next());
 364.603 +            }
 364.604 +        }
 364.605 +    }
 364.606 +
 364.607 +    /**
 364.608 +     * Returns the minimum element of the given collection, according to the
 364.609 +     * <i>natural ordering</i> of its elements.  All elements in the
 364.610 +     * collection must implement the <tt>Comparable</tt> interface.
 364.611 +     * Furthermore, all elements in the collection must be <i>mutually
 364.612 +     * comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
 364.613 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
 364.614 +     * <tt>e2</tt> in the collection).<p>
 364.615 +     *
 364.616 +     * This method iterates over the entire collection, hence it requires
 364.617 +     * time proportional to the size of the collection.
 364.618 +     *
 364.619 +     * @param  coll the collection whose minimum element is to be determined.
 364.620 +     * @return the minimum element of the given collection, according
 364.621 +     *         to the <i>natural ordering</i> of its elements.
 364.622 +     * @throws ClassCastException if the collection contains elements that are
 364.623 +     *         not <i>mutually comparable</i> (for example, strings and
 364.624 +     *         integers).
 364.625 +     * @throws NoSuchElementException if the collection is empty.
 364.626 +     * @see Comparable
 364.627 +     */
 364.628 +    public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {
 364.629 +        Iterator<? extends T> i = coll.iterator();
 364.630 +        T candidate = i.next();
 364.631 +
 364.632 +        while (i.hasNext()) {
 364.633 +            T next = i.next();
 364.634 +            if (next.compareTo(candidate) < 0)
 364.635 +                candidate = next;
 364.636 +        }
 364.637 +        return candidate;
 364.638 +    }
 364.639 +
 364.640 +    /**
 364.641 +     * Returns the minimum element of the given collection, according to the
 364.642 +     * order induced by the specified comparator.  All elements in the
 364.643 +     * collection must be <i>mutually comparable</i> by the specified
 364.644 +     * comparator (that is, <tt>comp.compare(e1, e2)</tt> must not throw a
 364.645 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
 364.646 +     * <tt>e2</tt> in the collection).<p>
 364.647 +     *
 364.648 +     * This method iterates over the entire collection, hence it requires
 364.649 +     * time proportional to the size of the collection.
 364.650 +     *
 364.651 +     * @param  coll the collection whose minimum element is to be determined.
 364.652 +     * @param  comp the comparator with which to determine the minimum element.
 364.653 +     *         A <tt>null</tt> value indicates that the elements' <i>natural
 364.654 +     *         ordering</i> should be used.
 364.655 +     * @return the minimum element of the given collection, according
 364.656 +     *         to the specified comparator.
 364.657 +     * @throws ClassCastException if the collection contains elements that are
 364.658 +     *         not <i>mutually comparable</i> using the specified comparator.
 364.659 +     * @throws NoSuchElementException if the collection is empty.
 364.660 +     * @see Comparable
 364.661 +     */
 364.662 +    public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
 364.663 +        if (comp==null)
 364.664 +            return (T)min((Collection<SelfComparable>) (Collection) coll);
 364.665 +
 364.666 +        Iterator<? extends T> i = coll.iterator();
 364.667 +        T candidate = i.next();
 364.668 +
 364.669 +        while (i.hasNext()) {
 364.670 +            T next = i.next();
 364.671 +            if (comp.compare(next, candidate) < 0)
 364.672 +                candidate = next;
 364.673 +        }
 364.674 +        return candidate;
 364.675 +    }
 364.676 +
 364.677 +    /**
 364.678 +     * Returns the maximum element of the given collection, according to the
 364.679 +     * <i>natural ordering</i> of its elements.  All elements in the
 364.680 +     * collection must implement the <tt>Comparable</tt> interface.
 364.681 +     * Furthermore, all elements in the collection must be <i>mutually
 364.682 +     * comparable</i> (that is, <tt>e1.compareTo(e2)</tt> must not throw a
 364.683 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
 364.684 +     * <tt>e2</tt> in the collection).<p>
 364.685 +     *
 364.686 +     * This method iterates over the entire collection, hence it requires
 364.687 +     * time proportional to the size of the collection.
 364.688 +     *
 364.689 +     * @param  coll the collection whose maximum element is to be determined.
 364.690 +     * @return the maximum element of the given collection, according
 364.691 +     *         to the <i>natural ordering</i> of its elements.
 364.692 +     * @throws ClassCastException if the collection contains elements that are
 364.693 +     *         not <i>mutually comparable</i> (for example, strings and
 364.694 +     *         integers).
 364.695 +     * @throws NoSuchElementException if the collection is empty.
 364.696 +     * @see Comparable
 364.697 +     */
 364.698 +    public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {
 364.699 +        Iterator<? extends T> i = coll.iterator();
 364.700 +        T candidate = i.next();
 364.701 +
 364.702 +        while (i.hasNext()) {
 364.703 +            T next = i.next();
 364.704 +            if (next.compareTo(candidate) > 0)
 364.705 +                candidate = next;
 364.706 +        }
 364.707 +        return candidate;
 364.708 +    }
 364.709 +
 364.710 +    /**
 364.711 +     * Returns the maximum element of the given collection, according to the
 364.712 +     * order induced by the specified comparator.  All elements in the
 364.713 +     * collection must be <i>mutually comparable</i> by the specified
 364.714 +     * comparator (that is, <tt>comp.compare(e1, e2)</tt> must not throw a
 364.715 +     * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
 364.716 +     * <tt>e2</tt> in the collection).<p>
 364.717 +     *
 364.718 +     * This method iterates over the entire collection, hence it requires
 364.719 +     * time proportional to the size of the collection.
 364.720 +     *
 364.721 +     * @param  coll the collection whose maximum element is to be determined.
 364.722 +     * @param  comp the comparator with which to determine the maximum element.
 364.723 +     *         A <tt>null</tt> value indicates that the elements' <i>natural
 364.724 +     *        ordering</i> should be used.
 364.725 +     * @return the maximum element of the given collection, according
 364.726 +     *         to the specified comparator.
 364.727 +     * @throws ClassCastException if the collection contains elements that are
 364.728 +     *         not <i>mutually comparable</i> using the specified comparator.
 364.729 +     * @throws NoSuchElementException if the collection is empty.
 364.730 +     * @see Comparable
 364.731 +     */
 364.732 +    public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
 364.733 +        if (comp==null)
 364.734 +            return (T)max((Collection<SelfComparable>) (Collection) coll);
 364.735 +
 364.736 +        Iterator<? extends T> i = coll.iterator();
 364.737 +        T candidate = i.next();
 364.738 +
 364.739 +        while (i.hasNext()) {
 364.740 +            T next = i.next();
 364.741 +            if (comp.compare(next, candidate) > 0)
 364.742 +                candidate = next;
 364.743 +        }
 364.744 +        return candidate;
 364.745 +    }
 364.746 +
 364.747 +    /**
 364.748 +     * Rotates the elements in the specified list by the specified distance.
 364.749 +     * After calling this method, the element at index <tt>i</tt> will be
 364.750 +     * the element previously at index <tt>(i - distance)</tt> mod
 364.751 +     * <tt>list.size()</tt>, for all values of <tt>i</tt> between <tt>0</tt>
 364.752 +     * and <tt>list.size()-1</tt>, inclusive.  (This method has no effect on
 364.753 +     * the size of the list.)
 364.754 +     *
 364.755 +     * <p>For example, suppose <tt>list</tt> comprises<tt> [t, a, n, k, s]</tt>.
 364.756 +     * After invoking <tt>Collections.rotate(list, 1)</tt> (or
 364.757 +     * <tt>Collections.rotate(list, -4)</tt>), <tt>list</tt> will comprise
 364.758 +     * <tt>[s, t, a, n, k]</tt>.
 364.759 +     *
 364.760 +     * <p>Note that this method can usefully be applied to sublists to
 364.761 +     * move one or more elements within a list while preserving the
 364.762 +     * order of the remaining elements.  For example, the following idiom
 364.763 +     * moves the element at index <tt>j</tt> forward to position
 364.764 +     * <tt>k</tt> (which must be greater than or equal to <tt>j</tt>):
 364.765 +     * <pre>
 364.766 +     *     Collections.rotate(list.subList(j, k+1), -1);
 364.767 +     * </pre>
 364.768 +     * To make this concrete, suppose <tt>list</tt> comprises
 364.769 +     * <tt>[a, b, c, d, e]</tt>.  To move the element at index <tt>1</tt>
 364.770 +     * (<tt>b</tt>) forward two positions, perform the following invocation:
 364.771 +     * <pre>
 364.772 +     *     Collections.rotate(l.subList(1, 4), -1);
 364.773 +     * </pre>
 364.774 +     * The resulting list is <tt>[a, c, d, b, e]</tt>.
 364.775 +     *
 364.776 +     * <p>To move more than one element forward, increase the absolute value
 364.777 +     * of the rotation distance.  To move elements backward, use a positive
 364.778 +     * shift distance.
 364.779 +     *
 364.780 +     * <p>If the specified list is small or implements the {@link
 364.781 +     * RandomAccess} interface, this implementation exchanges the first
 364.782 +     * element into the location it should go, and then repeatedly exchanges
 364.783 +     * the displaced element into the location it should go until a displaced
 364.784 +     * element is swapped into the first element.  If necessary, the process
 364.785 +     * is repeated on the second and successive elements, until the rotation
 364.786 +     * is complete.  If the specified list is large and doesn't implement the
 364.787 +     * <tt>RandomAccess</tt> interface, this implementation breaks the
 364.788 +     * list into two sublist views around index <tt>-distance mod size</tt>.
 364.789 +     * Then the {@link #reverse(List)} method is invoked on each sublist view,
 364.790 +     * and finally it is invoked on the entire list.  For a more complete
 364.791 +     * description of both algorithms, see Section 2.3 of Jon Bentley's
 364.792 +     * <i>Programming Pearls</i> (Addison-Wesley, 1986).
 364.793 +     *
 364.794 +     * @param list the list to be rotated.
 364.795 +     * @param distance the distance to rotate the list.  There are no
 364.796 +     *        constraints on this value; it may be zero, negative, or
 364.797 +     *        greater than <tt>list.size()</tt>.
 364.798 +     * @throws UnsupportedOperationException if the specified list or
 364.799 +     *         its list-iterator does not support the <tt>set</tt> operation.
 364.800 +     * @since 1.4
 364.801 +     */
 364.802 +    public static void rotate(List<?> list, int distance) {
 364.803 +        if (list instanceof RandomAccess || list.size() < ROTATE_THRESHOLD)
 364.804 +            rotate1(list, distance);
 364.805 +        else
 364.806 +            rotate2(list, distance);
 364.807 +    }
 364.808 +
 364.809 +    private static <T> void rotate1(List<T> list, int distance) {
 364.810 +        int size = list.size();
 364.811 +        if (size == 0)
 364.812 +            return;
 364.813 +        distance = distance % size;
 364.814 +        if (distance < 0)
 364.815 +            distance += size;
 364.816 +        if (distance == 0)
 364.817 +            return;
 364.818 +
 364.819 +        for (int cycleStart = 0, nMoved = 0; nMoved != size; cycleStart++) {
 364.820 +            T displaced = list.get(cycleStart);
 364.821 +            int i = cycleStart;
 364.822 +            do {
 364.823 +                i += distance;
 364.824 +                if (i >= size)
 364.825 +                    i -= size;
 364.826 +                displaced = list.set(i, displaced);
 364.827 +                nMoved ++;
 364.828 +            } while (i != cycleStart);
 364.829 +        }
 364.830 +    }
 364.831 +
 364.832 +    private static void rotate2(List<?> list, int distance) {
 364.833 +        int size = list.size();
 364.834 +        if (size == 0)
 364.835 +            return;
 364.836 +        int mid =  -distance % size;
 364.837 +        if (mid < 0)
 364.838 +            mid += size;
 364.839 +        if (mid == 0)
 364.840 +            return;
 364.841 +
 364.842 +        reverse(list.subList(0, mid));
 364.843 +        reverse(list.subList(mid, size));
 364.844 +        reverse(list);
 364.845 +    }
 364.846 +
 364.847 +    /**
 364.848 +     * Replaces all occurrences of one specified value in a list with another.
 364.849 +     * More formally, replaces with <tt>newVal</tt> each element <tt>e</tt>
 364.850 +     * in <tt>list</tt> such that
 364.851 +     * <tt>(oldVal==null ? e==null : oldVal.equals(e))</tt>.
 364.852 +     * (This method has no effect on the size of the list.)
 364.853 +     *
 364.854 +     * @param list the list in which replacement is to occur.
 364.855 +     * @param oldVal the old value to be replaced.
 364.856 +     * @param newVal the new value with which <tt>oldVal</tt> is to be
 364.857 +     *        replaced.
 364.858 +     * @return <tt>true</tt> if <tt>list</tt> contained one or more elements
 364.859 +     *         <tt>e</tt> such that
 364.860 +     *         <tt>(oldVal==null ?  e==null : oldVal.equals(e))</tt>.
 364.861 +     * @throws UnsupportedOperationException if the specified list or
 364.862 +     *         its list-iterator does not support the <tt>set</tt> operation.
 364.863 +     * @since  1.4
 364.864 +     */
 364.865 +    public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) {
 364.866 +        boolean result = false;
 364.867 +        int size = list.size();
 364.868 +        if (size < REPLACEALL_THRESHOLD || list instanceof RandomAccess) {
 364.869 +            if (oldVal==null) {
 364.870 +                for (int i=0; i<size; i++) {
 364.871 +                    if (list.get(i)==null) {
 364.872 +                        list.set(i, newVal);
 364.873 +                        result = true;
 364.874 +                    }
 364.875 +                }
 364.876 +            } else {
 364.877 +                for (int i=0; i<size; i++) {
 364.878 +                    if (oldVal.equals(list.get(i))) {
 364.879 +                        list.set(i, newVal);
 364.880 +                        result = true;
 364.881 +                    }
 364.882 +                }
 364.883 +            }
 364.884 +        } else {
 364.885 +            ListIterator<T> itr=list.listIterator();
 364.886 +            if (oldVal==null) {
 364.887 +                for (int i=0; i<size; i++) {
 364.888 +                    if (itr.next()==null) {
 364.889 +                        itr.set(newVal);
 364.890 +                        result = true;
 364.891 +                    }
 364.892 +                }
 364.893 +            } else {
 364.894 +                for (int i=0; i<size; i++) {
 364.895 +                    if (oldVal.equals(itr.next())) {
 364.896 +                        itr.set(newVal);
 364.897 +                        result = true;
 364.898 +                    }
 364.899 +                }
 364.900 +            }
 364.901 +        }
 364.902 +        return result;
 364.903 +    }
 364.904 +
 364.905 +    /**
 364.906 +     * Returns the starting position of the first occurrence of the specified
 364.907 +     * target list within the specified source list, or -1 if there is no
 364.908 +     * such occurrence.  More formally, returns the lowest index <tt>i</tt>
 364.909 +     * such that <tt>source.subList(i, i+target.size()).equals(target)</tt>,
 364.910 +     * or -1 if there is no such index.  (Returns -1 if
 364.911 +     * <tt>target.size() > source.size()</tt>.)
 364.912 +     *
 364.913 +     * <p>This implementation uses the "brute force" technique of scanning
 364.914 +     * over the source list, looking for a match with the target at each
 364.915 +     * location in turn.
 364.916 +     *
 364.917 +     * @param source the list in which to search for the first occurrence
 364.918 +     *        of <tt>target</tt>.
 364.919 +     * @param target the list to search for as a subList of <tt>source</tt>.
 364.920 +     * @return the starting position of the first occurrence of the specified
 364.921 +     *         target list within the specified source list, or -1 if there
 364.922 +     *         is no such occurrence.
 364.923 +     * @since  1.4
 364.924 +     */
 364.925 +    public static int indexOfSubList(List<?> source, List<?> target) {
 364.926 +        int sourceSize = source.size();
 364.927 +        int targetSize = target.size();
 364.928 +        int maxCandidate = sourceSize - targetSize;
 364.929 +
 364.930 +        if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
 364.931 +            (source instanceof RandomAccess&&target instanceof RandomAccess)) {
 364.932 +        nextCand:
 364.933 +            for (int candidate = 0; candidate <= maxCandidate; candidate++) {
 364.934 +                for (int i=0, j=candidate; i<targetSize; i++, j++)
 364.935 +                    if (!eq(target.get(i), source.get(j)))
 364.936 +                        continue nextCand;  // Element mismatch, try next cand
 364.937 +                return candidate;  // All elements of candidate matched target
 364.938 +            }
 364.939 +        } else {  // Iterator version of above algorithm
 364.940 +            ListIterator<?> si = source.listIterator();
 364.941 +        nextCand:
 364.942 +            for (int candidate = 0; candidate <= maxCandidate; candidate++) {
 364.943 +                ListIterator<?> ti = target.listIterator();
 364.944 +                for (int i=0; i<targetSize; i++) {
 364.945 +                    if (!eq(ti.next(), si.next())) {
 364.946 +                        // Back up source iterator to next candidate
 364.947 +                        for (int j=0; j<i; j++)
 364.948 +                            si.previous();
 364.949 +                        continue nextCand;
 364.950 +                    }
 364.951 +                }
 364.952 +                return candidate;
 364.953 +            }
 364.954 +        }
 364.955 +        return -1;  // No candidate matched the target
 364.956 +    }
 364.957 +
 364.958 +    /**
 364.959 +     * Returns the starting position of the last occurrence of the specified
 364.960 +     * target list within the specified source list, or -1 if there is no such
 364.961 +     * occurrence.  More formally, returns the highest index <tt>i</tt>
 364.962 +     * such that <tt>source.subList(i, i+target.size()).equals(target)</tt>,
 364.963 +     * or -1 if there is no such index.  (Returns -1 if
 364.964 +     * <tt>target.size() > source.size()</tt>.)
 364.965 +     *
 364.966 +     * <p>This implementation uses the "brute force" technique of iterating
 364.967 +     * over the source list, looking for a match with the target at each
 364.968 +     * location in turn.
 364.969 +     *
 364.970 +     * @param source the list in which to search for the last occurrence
 364.971 +     *        of <tt>target</tt>.
 364.972 +     * @param target the list to search for as a subList of <tt>source</tt>.
 364.973 +     * @return the starting position of the last occurrence of the specified
 364.974 +     *         target list within the specified source list, or -1 if there
 364.975 +     *         is no such occurrence.
 364.976 +     * @since  1.4
 364.977 +     */
 364.978 +    public static int lastIndexOfSubList(List<?> source, List<?> target) {
 364.979 +        int sourceSize = source.size();
 364.980 +        int targetSize = target.size();
 364.981 +        int maxCandidate = sourceSize - targetSize;
 364.982 +
 364.983 +        if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
 364.984 +            source instanceof RandomAccess) {   // Index access version
 364.985 +        nextCand:
 364.986 +            for (int candidate = maxCandidate; candidate >= 0; candidate--) {
 364.987 +                for (int i=0, j=candidate; i<targetSize; i++, j++)
 364.988 +                    if (!eq(target.get(i), source.get(j)))
 364.989 +                        continue nextCand;  // Element mismatch, try next cand
 364.990 +                return candidate;  // All elements of candidate matched target
 364.991 +            }
 364.992 +        } else {  // Iterator version of above algorithm
 364.993 +            if (maxCandidate < 0)
 364.994 +                return -1;
 364.995 +            ListIterator<?> si = source.listIterator(maxCandidate);
 364.996 +        nextCand:
 364.997 +            for (int candidate = maxCandidate; candidate >= 0; candidate--) {
 364.998 +                ListIterator<?> ti = target.listIterator();
 364.999 +                for (int i=0; i<targetSize; i++) {
364.1000 +                    if (!eq(ti.next(), si.next())) {
364.1001 +                        if (candidate != 0) {
364.1002 +                            // Back up source iterator to next candidate
364.1003 +                            for (int j=0; j<=i+1; j++)
364.1004 +                                si.previous();
364.1005 +                        }
364.1006 +                        continue nextCand;
364.1007 +                    }
364.1008 +                }
364.1009 +                return candidate;
364.1010 +            }
364.1011 +        }
364.1012 +        return -1;  // No candidate matched the target
364.1013 +    }
364.1014 +
364.1015 +
364.1016 +    // Unmodifiable Wrappers
364.1017 +
364.1018 +    /**
364.1019 +     * Returns an unmodifiable view of the specified collection.  This method
364.1020 +     * allows modules to provide users with "read-only" access to internal
364.1021 +     * collections.  Query operations on the returned collection "read through"
364.1022 +     * to the specified collection, and attempts to modify the returned
364.1023 +     * collection, whether direct or via its iterator, result in an
364.1024 +     * <tt>UnsupportedOperationException</tt>.<p>
364.1025 +     *
364.1026 +     * The returned collection does <i>not</i> pass the hashCode and equals
364.1027 +     * operations through to the backing collection, but relies on
364.1028 +     * <tt>Object</tt>'s <tt>equals</tt> and <tt>hashCode</tt> methods.  This
364.1029 +     * is necessary to preserve the contracts of these operations in the case
364.1030 +     * that the backing collection is a set or a list.<p>
364.1031 +     *
364.1032 +     * The returned collection will be serializable if the specified collection
364.1033 +     * is serializable.
364.1034 +     *
364.1035 +     * @param  c the collection for which an unmodifiable view is to be
364.1036 +     *         returned.
364.1037 +     * @return an unmodifiable view of the specified collection.
364.1038 +     */
364.1039 +    public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) {
364.1040 +        return new UnmodifiableCollection<>(c);
364.1041 +    }
364.1042 +
364.1043 +    /**
364.1044 +     * @serial include
364.1045 +     */
364.1046 +    static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
364.1047 +        private static final long serialVersionUID = 1820017752578914078L;
364.1048 +
364.1049 +        final Collection<? extends E> c;
364.1050 +
364.1051 +        UnmodifiableCollection(Collection<? extends E> c) {
364.1052 +            if (c==null)
364.1053 +                throw new NullPointerException();
364.1054 +            this.c = c;
364.1055 +        }
364.1056 +
364.1057 +        public int size()                   {return c.size();}
364.1058 +        public boolean isEmpty()            {return c.isEmpty();}
364.1059 +        public boolean contains(Object o)   {return c.contains(o);}
364.1060 +        public Object[] toArray()           {return c.toArray();}
364.1061 +        public <T> T[] toArray(T[] a)       {return c.toArray(a);}
364.1062 +        public String toString()            {return c.toString();}
364.1063 +
364.1064 +        public Iterator<E> iterator() {
364.1065 +            return new Iterator<E>() {
364.1066 +                private final Iterator<? extends E> i = c.iterator();
364.1067 +
364.1068 +                public boolean hasNext() {return i.hasNext();}
364.1069 +                public E next()          {return i.next();}
364.1070 +                public void remove() {
364.1071 +                    throw new UnsupportedOperationException();
364.1072 +                }
364.1073 +            };
364.1074 +        }
364.1075 +
364.1076 +        public boolean add(E e) {
364.1077 +            throw new UnsupportedOperationException();
364.1078 +        }
364.1079 +        public boolean remove(Object o) {
364.1080 +            throw new UnsupportedOperationException();
364.1081 +        }
364.1082 +
364.1083 +        public boolean containsAll(Collection<?> coll) {
364.1084 +            return c.containsAll(coll);
364.1085 +        }
364.1086 +        public boolean addAll(Collection<? extends E> coll) {
364.1087 +            throw new UnsupportedOperationException();
364.1088 +        }
364.1089 +        public boolean removeAll(Collection<?> coll) {
364.1090 +            throw new UnsupportedOperationException();
364.1091 +        }
364.1092 +        public boolean retainAll(Collection<?> coll) {
364.1093 +            throw new UnsupportedOperationException();
364.1094 +        }
364.1095 +        public void clear() {
364.1096 +            throw new UnsupportedOperationException();
364.1097 +        }
364.1098 +    }
364.1099 +
364.1100 +    /**
364.1101 +     * Returns an unmodifiable view of the specified set.  This method allows
364.1102 +     * modules to provide users with "read-only" access to internal sets.
364.1103 +     * Query operations on the returned set "read through" to the specified
364.1104 +     * set, and attempts to modify the returned set, whether direct or via its
364.1105 +     * iterator, result in an <tt>UnsupportedOperationException</tt>.<p>
364.1106 +     *
364.1107 +     * The returned set will be serializable if the specified set
364.1108 +     * is serializable.
364.1109 +     *
364.1110 +     * @param  s the set for which an unmodifiable view is to be returned.
364.1111 +     * @return an unmodifiable view of the specified set.
364.1112 +     */
364.1113 +    public static <T> Set<T> unmodifiableSet(Set<? extends T> s) {
364.1114 +        return new UnmodifiableSet<>(s);
364.1115 +    }
364.1116 +
364.1117 +    /**
364.1118 +     * @serial include
364.1119 +     */
364.1120 +    static class UnmodifiableSet<E> extends UnmodifiableCollection<E>
364.1121 +                                 implements Set<E>, Serializable {
364.1122 +        private static final long serialVersionUID = -9215047833775013803L;
364.1123 +
364.1124 +        UnmodifiableSet(Set<? extends E> s)     {super(s);}
364.1125 +        public boolean equals(Object o) {return o == this || c.equals(o);}
364.1126 +        public int hashCode()           {return c.hashCode();}
364.1127 +    }
364.1128 +
364.1129 +    /**
364.1130 +     * Returns an unmodifiable view of the specified sorted set.  This method
364.1131 +     * allows modules to provide users with "read-only" access to internal
364.1132 +     * sorted sets.  Query operations on the returned sorted set "read
364.1133 +     * through" to the specified sorted set.  Attempts to modify the returned
364.1134 +     * sorted set, whether direct, via its iterator, or via its
364.1135 +     * <tt>subSet</tt>, <tt>headSet</tt>, or <tt>tailSet</tt> views, result in
364.1136 +     * an <tt>UnsupportedOperationException</tt>.<p>
364.1137 +     *
364.1138 +     * The returned sorted set will be serializable if the specified sorted set
364.1139 +     * is serializable.
364.1140 +     *
364.1141 +     * @param s the sorted set for which an unmodifiable view is to be
364.1142 +     *        returned.
364.1143 +     * @return an unmodifiable view of the specified sorted set.
364.1144 +     */
364.1145 +    public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) {
364.1146 +        return new UnmodifiableSortedSet<>(s);
364.1147 +    }
364.1148 +
364.1149 +    /**
364.1150 +     * @serial include
364.1151 +     */
364.1152 +    static class UnmodifiableSortedSet<E>
364.1153 +                             extends UnmodifiableSet<E>
364.1154 +                             implements SortedSet<E>, Serializable {
364.1155 +        private static final long serialVersionUID = -4929149591599911165L;
364.1156 +        private final SortedSet<E> ss;
364.1157 +
364.1158 +        UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
364.1159 +
364.1160 +        public Comparator<? super E> comparator() {return ss.comparator();}
364.1161 +
364.1162 +        public SortedSet<E> subSet(E fromElement, E toElement) {
364.1163 +            return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement));
364.1164 +        }
364.1165 +        public SortedSet<E> headSet(E toElement) {
364.1166 +            return new UnmodifiableSortedSet<>(ss.headSet(toElement));
364.1167 +        }
364.1168 +        public SortedSet<E> tailSet(E fromElement) {
364.1169 +            return new UnmodifiableSortedSet<>(ss.tailSet(fromElement));
364.1170 +        }
364.1171 +
364.1172 +        public E first()                   {return ss.first();}
364.1173 +        public E last()                    {return ss.last();}
364.1174 +    }
364.1175 +
364.1176 +    /**
364.1177 +     * Returns an unmodifiable view of the specified list.  This method allows
364.1178 +     * modules to provide users with "read-only" access to internal
364.1179 +     * lists.  Query operations on the returned list "read through" to the
364.1180 +     * specified list, and attempts to modify the returned list, whether
364.1181 +     * direct or via its iterator, result in an
364.1182 +     * <tt>UnsupportedOperationException</tt>.<p>
364.1183 +     *
364.1184 +     * The returned list will be serializable if the specified list
364.1185 +     * is serializable. Similarly, the returned list will implement
364.1186 +     * {@link RandomAccess} if the specified list does.
364.1187 +     *
364.1188 +     * @param  list the list for which an unmodifiable view is to be returned.
364.1189 +     * @return an unmodifiable view of the specified list.
364.1190 +     */
364.1191 +    public static <T> List<T> unmodifiableList(List<? extends T> list) {
364.1192 +        return (list instanceof RandomAccess ?
364.1193 +                new UnmodifiableRandomAccessList<>(list) :
364.1194 +                new UnmodifiableList<>(list));
364.1195 +    }
364.1196 +
364.1197 +    /**
364.1198 +     * @serial include
364.1199 +     */
364.1200 +    static class UnmodifiableList<E> extends UnmodifiableCollection<E>
364.1201 +                                  implements List<E> {
364.1202 +        private static final long serialVersionUID = -283967356065247728L;
364.1203 +        final List<? extends E> list;
364.1204 +
364.1205 +        UnmodifiableList(List<? extends E> list) {
364.1206 +            super(list);
364.1207 +            this.list = list;
364.1208 +        }
364.1209 +
364.1210 +        public boolean equals(Object o) {return o == this || list.equals(o);}
364.1211 +        public int hashCode()           {return list.hashCode();}
364.1212 +
364.1213 +        public E get(int index) {return list.get(index);}
364.1214 +        public E set(int index, E element) {
364.1215 +            throw new UnsupportedOperationException();
364.1216 +        }
364.1217 +        public void add(int index, E element) {
364.1218 +            throw new UnsupportedOperationException();
364.1219 +        }
364.1220 +        public E remove(int index) {
364.1221 +            throw new UnsupportedOperationException();
364.1222 +        }
364.1223 +        public int indexOf(Object o)            {return list.indexOf(o);}
364.1224 +        public int lastIndexOf(Object o)        {return list.lastIndexOf(o);}
364.1225 +        public boolean addAll(int index, Collection<? extends E> c) {
364.1226 +            throw new UnsupportedOperationException();
364.1227 +        }
364.1228 +        public ListIterator<E> listIterator()   {return listIterator(0);}
364.1229 +
364.1230 +        public ListIterator<E> listIterator(final int index) {
364.1231 +            return new ListIterator<E>() {
364.1232 +                private final ListIterator<? extends E> i
364.1233 +                    = list.listIterator(index);
364.1234 +
364.1235 +                public boolean hasNext()     {return i.hasNext();}
364.1236 +                public E next()              {return i.next();}
364.1237 +                public boolean hasPrevious() {return i.hasPrevious();}
364.1238 +                public E previous()          {return i.previous();}
364.1239 +                public int nextIndex()       {return i.nextIndex();}
364.1240 +                public int previousIndex()   {return i.previousIndex();}
364.1241 +
364.1242 +                public void remove() {
364.1243 +                    throw new UnsupportedOperationException();
364.1244 +                }
364.1245 +                public void set(E e) {
364.1246 +                    throw new UnsupportedOperationException();
364.1247 +                }
364.1248 +                public void add(E e) {
364.1249 +                    throw new UnsupportedOperationException();
364.1250 +                }
364.1251 +            };
364.1252 +        }
364.1253 +
364.1254 +        public List<E> subList(int fromIndex, int toIndex) {
364.1255 +            return new UnmodifiableList<>(list.subList(fromIndex, toIndex));
364.1256 +        }
364.1257 +
364.1258 +        /**
364.1259 +         * UnmodifiableRandomAccessList instances are serialized as
364.1260 +         * UnmodifiableList instances to allow them to be deserialized
364.1261 +         * in pre-1.4 JREs (which do not have UnmodifiableRandomAccessList).
364.1262 +         * This method inverts the transformation.  As a beneficial
364.1263 +         * side-effect, it also grafts the RandomAccess marker onto
364.1264 +         * UnmodifiableList instances that were serialized in pre-1.4 JREs.
364.1265 +         *
364.1266 +         * Note: Unfortunately, UnmodifiableRandomAccessList instances
364.1267 +         * serialized in 1.4.1 and deserialized in 1.4 will become
364.1268 +         * UnmodifiableList instances, as this method was missing in 1.4.
364.1269 +         */
364.1270 +        private Object readResolve() {
364.1271 +            return (list instanceof RandomAccess
364.1272 +                    ? new UnmodifiableRandomAccessList<>(list)
364.1273 +                    : this);
364.1274 +        }
364.1275 +    }
364.1276 +
364.1277 +    /**
364.1278 +     * @serial include
364.1279 +     */
364.1280 +    static class UnmodifiableRandomAccessList<E> extends UnmodifiableList<E>
364.1281 +                                              implements RandomAccess
364.1282 +    {
364.1283 +        UnmodifiableRandomAccessList(List<? extends E> list) {
364.1284 +            super(list);
364.1285 +        }
364.1286 +
364.1287 +        public List<E> subList(int fromIndex, int toIndex) {
364.1288 +            return new UnmodifiableRandomAccessList<>(
364.1289 +                list.subList(fromIndex, toIndex));
364.1290 +        }
364.1291 +
364.1292 +        private static final long serialVersionUID = -2542308836966382001L;
364.1293 +
364.1294 +        /**
364.1295 +         * Allows instances to be deserialized in pre-1.4 JREs (which do
364.1296 +         * not have UnmodifiableRandomAccessList).  UnmodifiableList has
364.1297 +         * a readResolve method that inverts this transformation upon
364.1298 +         * deserialization.
364.1299 +         */
364.1300 +        private Object writeReplace() {
364.1301 +            return new UnmodifiableList<>(list);
364.1302 +        }
364.1303 +    }
364.1304 +
364.1305 +    /**
364.1306 +     * Returns an unmodifiable view of the specified map.  This method
364.1307 +     * allows modules to provide users with "read-only" access to internal
364.1308 +     * maps.  Query operations on the returned map "read through"
364.1309 +     * to the specified map, and attempts to modify the returned
364.1310 +     * map, whether direct or via its collection views, result in an
364.1311 +     * <tt>UnsupportedOperationException</tt>.<p>
364.1312 +     *
364.1313 +     * The returned map will be serializable if the specified map
364.1314 +     * is serializable.
364.1315 +     *
364.1316 +     * @param  m the map for which an unmodifiable view is to be returned.
364.1317 +     * @return an unmodifiable view of the specified map.
364.1318 +     */
364.1319 +    public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m) {
364.1320 +        return new UnmodifiableMap<>(m);
364.1321 +    }
364.1322 +
364.1323 +    /**
364.1324 +     * @serial include
364.1325 +     */
364.1326 +    private static class UnmodifiableMap<K,V> implements Map<K,V>, Serializable {
364.1327 +        private static final long serialVersionUID = -1034234728574286014L;
364.1328 +
364.1329 +        private final Map<? extends K, ? extends V> m;
364.1330 +
364.1331 +        UnmodifiableMap(Map<? extends K, ? extends V> m) {
364.1332 +            if (m==null)
364.1333 +                throw new NullPointerException();
364.1334 +            this.m = m;
364.1335 +        }
364.1336 +
364.1337 +        public int size()                        {return m.size();}
364.1338 +        public boolean isEmpty()                 {return m.isEmpty();}
364.1339 +        public boolean containsKey(Object key)   {return m.containsKey(key);}
364.1340 +        public boolean containsValue(Object val) {return m.containsValue(val);}
364.1341 +        public V get(Object key)                 {return m.get(key);}
364.1342 +
364.1343 +        public V put(K key, V value) {
364.1344 +            throw new UnsupportedOperationException();
364.1345 +        }
364.1346 +        public V remove(Object key) {
364.1347 +            throw new UnsupportedOperationException();
364.1348 +        }
364.1349 +        public void putAll(Map<? extends K, ? extends V> m) {
364.1350 +            throw new UnsupportedOperationException();
364.1351 +        }
364.1352 +        public void clear() {
364.1353 +            throw new UnsupportedOperationException();
364.1354 +        }
364.1355 +
364.1356 +        private transient Set<K> keySet = null;
364.1357 +        private transient Set<Map.Entry<K,V>> entrySet = null;
364.1358 +        private transient Collection<V> values = null;
364.1359 +
364.1360 +        public Set<K> keySet() {
364.1361 +            if (keySet==null)
364.1362 +                keySet = unmodifiableSet(m.keySet());
364.1363 +            return keySet;
364.1364 +        }
364.1365 +
364.1366 +        public Set<Map.Entry<K,V>> entrySet() {
364.1367 +            if (entrySet==null)
364.1368 +                entrySet = new UnmodifiableEntrySet<>(m.entrySet());
364.1369 +            return entrySet;
364.1370 +        }
364.1371 +
364.1372 +        public Collection<V> values() {
364.1373 +            if (values==null)
364.1374 +                values = unmodifiableCollection(m.values());
364.1375 +            return values;
364.1376 +        }
364.1377 +
364.1378 +        public boolean equals(Object o) {return o == this || m.equals(o);}
364.1379 +        public int hashCode()           {return m.hashCode();}
364.1380 +        public String toString()        {return m.toString();}
364.1381 +
364.1382 +        /**
364.1383 +         * We need this class in addition to UnmodifiableSet as
364.1384 +         * Map.Entries themselves permit modification of the backing Map
364.1385 +         * via their setValue operation.  This class is subtle: there are
364.1386 +         * many possible attacks that must be thwarted.
364.1387 +         *
364.1388 +         * @serial include
364.1389 +         */
364.1390 +        static class UnmodifiableEntrySet<K,V>
364.1391 +            extends UnmodifiableSet<Map.Entry<K,V>> {
364.1392 +            private static final long serialVersionUID = 7854390611657943733L;
364.1393 +
364.1394 +            UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
364.1395 +                super((Set)s);
364.1396 +            }
364.1397 +            public Iterator<Map.Entry<K,V>> iterator() {
364.1398 +                return new Iterator<Map.Entry<K,V>>() {
364.1399 +                    private final Iterator<? extends Map.Entry<? extends K, ? extends V>> i = c.iterator();
364.1400 +
364.1401 +                    public boolean hasNext() {
364.1402 +                        return i.hasNext();
364.1403 +                    }
364.1404 +                    public Map.Entry<K,V> next() {
364.1405 +                        return new UnmodifiableEntry<>(i.next());
364.1406 +                    }
364.1407 +                    public void remove() {
364.1408 +                        throw new UnsupportedOperationException();
364.1409 +                    }
364.1410 +                };
364.1411 +            }
364.1412 +
364.1413 +            public Object[] toArray() {
364.1414 +                Object[] a = c.toArray();
364.1415 +                for (int i=0; i<a.length; i++)
364.1416 +                    a[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)a[i]);
364.1417 +                return a;
364.1418 +            }
364.1419 +
364.1420 +            public <T> T[] toArray(T[] a) {
364.1421 +                // We don't pass a to c.toArray, to avoid window of
364.1422 +                // vulnerability wherein an unscrupulous multithreaded client
364.1423 +                // could get his hands on raw (unwrapped) Entries from c.
364.1424 +                Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
364.1425 +
364.1426 +                for (int i=0; i<arr.length; i++)
364.1427 +                    arr[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)arr[i]);
364.1428 +
364.1429 +                if (arr.length > a.length)
364.1430 +                    return (T[])arr;
364.1431 +
364.1432 +                System.arraycopy(arr, 0, a, 0, arr.length);
364.1433 +                if (a.length > arr.length)
364.1434 +                    a[arr.length] = null;
364.1435 +                return a;
364.1436 +            }
364.1437 +
364.1438 +            /**
364.1439 +             * This method is overridden to protect the backing set against
364.1440 +             * an object with a nefarious equals function that senses
364.1441 +             * that the equality-candidate is Map.Entry and calls its
364.1442 +             * setValue method.
364.1443 +             */
364.1444 +            public boolean contains(Object o) {
364.1445 +                if (!(o instanceof Map.Entry))
364.1446 +                    return false;
364.1447 +                return c.contains(
364.1448 +                    new UnmodifiableEntry<>((Map.Entry<?,?>) o));
364.1449 +            }
364.1450 +
364.1451 +            /**
364.1452 +             * The next two methods are overridden to protect against
364.1453 +             * an unscrupulous List whose contains(Object o) method senses
364.1454 +             * when o is a Map.Entry, and calls o.setValue.
364.1455 +             */
364.1456 +            public boolean containsAll(Collection<?> coll) {
364.1457 +                for (Object e : coll) {
364.1458 +                    if (!contains(e)) // Invokes safe contains() above
364.1459 +                        return false;
364.1460 +                }
364.1461 +                return true;
364.1462 +            }
364.1463 +            public boolean equals(Object o) {
364.1464 +                if (o == this)
364.1465 +                    return true;
364.1466 +
364.1467 +                if (!(o instanceof Set))
364.1468 +                    return false;
364.1469 +                Set s = (Set) o;
364.1470 +                if (s.size() != c.size())
364.1471 +                    return false;
364.1472 +                return containsAll(s); // Invokes safe containsAll() above
364.1473 +            }
364.1474 +
364.1475 +            /**
364.1476 +             * This "wrapper class" serves two purposes: it prevents
364.1477 +             * the client from modifying the backing Map, by short-circuiting
364.1478 +             * the setValue method, and it protects the backing Map against
364.1479 +             * an ill-behaved Map.Entry that attempts to modify another
364.1480 +             * Map Entry when asked to perform an equality check.
364.1481 +             */
364.1482 +            private static class UnmodifiableEntry<K,V> implements Map.Entry<K,V> {
364.1483 +                private Map.Entry<? extends K, ? extends V> e;
364.1484 +
364.1485 +                UnmodifiableEntry(Map.Entry<? extends K, ? extends V> e) {this.e = e;}
364.1486 +
364.1487 +                public K getKey()        {return e.getKey();}
364.1488 +                public V getValue()      {return e.getValue();}
364.1489 +                public V setValue(V value) {
364.1490 +                    throw new UnsupportedOperationException();
364.1491 +                }
364.1492 +                public int hashCode()    {return e.hashCode();}
364.1493 +                public boolean equals(Object o) {
364.1494 +                    if (!(o instanceof Map.Entry))
364.1495 +                        return false;
364.1496 +                    Map.Entry t = (Map.Entry)o;
364.1497 +                    return eq(e.getKey(),   t.getKey()) &&
364.1498 +                           eq(e.getValue(), t.getValue());
364.1499 +                }
364.1500 +                public String toString() {return e.toString();}
364.1501 +            }
364.1502 +        }
364.1503 +    }
364.1504 +
364.1505 +    /**
364.1506 +     * Returns an unmodifiable view of the specified sorted map.  This method
364.1507 +     * allows modules to provide users with "read-only" access to internal
364.1508 +     * sorted maps.  Query operations on the returned sorted map "read through"
364.1509 +     * to the specified sorted map.  Attempts to modify the returned
364.1510 +     * sorted map, whether direct, via its collection views, or via its
364.1511 +     * <tt>subMap</tt>, <tt>headMap</tt>, or <tt>tailMap</tt> views, result in
364.1512 +     * an <tt>UnsupportedOperationException</tt>.<p>
364.1513 +     *
364.1514 +     * The returned sorted map will be serializable if the specified sorted map
364.1515 +     * is serializable.
364.1516 +     *
364.1517 +     * @param m the sorted map for which an unmodifiable view is to be
364.1518 +     *        returned.
364.1519 +     * @return an unmodifiable view of the specified sorted map.
364.1520 +     */
364.1521 +    public static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K, ? extends V> m) {
364.1522 +        return new UnmodifiableSortedMap<>(m);
364.1523 +    }
364.1524 +
364.1525 +    /**
364.1526 +     * @serial include
364.1527 +     */
364.1528 +    static class UnmodifiableSortedMap<K,V>
364.1529 +          extends UnmodifiableMap<K,V>
364.1530 +          implements SortedMap<K,V>, Serializable {
364.1531 +        private static final long serialVersionUID = -8806743815996713206L;
364.1532 +
364.1533 +        private final SortedMap<K, ? extends V> sm;
364.1534 +
364.1535 +        UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m;}
364.1536 +
364.1537 +        public Comparator<? super K> comparator() {return sm.comparator();}
364.1538 +
364.1539 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
364.1540 +            return new UnmodifiableSortedMap<>(sm.subMap(fromKey, toKey));
364.1541 +        }
364.1542 +        public SortedMap<K,V> headMap(K toKey) {
364.1543 +            return new UnmodifiableSortedMap<>(sm.headMap(toKey));
364.1544 +        }
364.1545 +        public SortedMap<K,V> tailMap(K fromKey) {
364.1546 +            return new UnmodifiableSortedMap<>(sm.tailMap(fromKey));
364.1547 +        }
364.1548 +
364.1549 +        public K firstKey()           {return sm.firstKey();}
364.1550 +        public K lastKey()            {return sm.lastKey();}
364.1551 +    }
364.1552 +
364.1553 +
364.1554 +    // Synch Wrappers
364.1555 +
364.1556 +    /**
364.1557 +     * Returns a synchronized (thread-safe) collection backed by the specified
364.1558 +     * collection.  In order to guarantee serial access, it is critical that
364.1559 +     * <strong>all</strong> access to the backing collection is accomplished
364.1560 +     * through the returned collection.<p>
364.1561 +     *
364.1562 +     * It is imperative that the user manually synchronize on the returned
364.1563 +     * collection when iterating over it:
364.1564 +     * <pre>
364.1565 +     *  Collection c = Collections.synchronizedCollection(myCollection);
364.1566 +     *     ...
364.1567 +     *  synchronized (c) {
364.1568 +     *      Iterator i = c.iterator(); // Must be in the synchronized block
364.1569 +     *      while (i.hasNext())
364.1570 +     *         foo(i.next());
364.1571 +     *  }
364.1572 +     * </pre>
364.1573 +     * Failure to follow this advice may result in non-deterministic behavior.
364.1574 +     *
364.1575 +     * <p>The returned collection does <i>not</i> pass the <tt>hashCode</tt>
364.1576 +     * and <tt>equals</tt> operations through to the backing collection, but
364.1577 +     * relies on <tt>Object</tt>'s equals and hashCode methods.  This is
364.1578 +     * necessary to preserve the contracts of these operations in the case
364.1579 +     * that the backing collection is a set or a list.<p>
364.1580 +     *
364.1581 +     * The returned collection will be serializable if the specified collection
364.1582 +     * is serializable.
364.1583 +     *
364.1584 +     * @param  c the collection to be "wrapped" in a synchronized collection.
364.1585 +     * @return a synchronized view of the specified collection.
364.1586 +     */
364.1587 +    public static <T> Collection<T> synchronizedCollection(Collection<T> c) {
364.1588 +        return new SynchronizedCollection<>(c);
364.1589 +    }
364.1590 +
364.1591 +    static <T> Collection<T> synchronizedCollection(Collection<T> c, Object mutex) {
364.1592 +        return new SynchronizedCollection<>(c, mutex);
364.1593 +    }
364.1594 +
364.1595 +    /**
364.1596 +     * @serial include
364.1597 +     */
364.1598 +    static class SynchronizedCollection<E> implements Collection<E>, Serializable {
364.1599 +        private static final long serialVersionUID = 3053995032091335093L;
364.1600 +
364.1601 +        final Collection<E> c;  // Backing Collection
364.1602 +        final Object mutex;     // Object on which to synchronize
364.1603 +
364.1604 +        SynchronizedCollection(Collection<E> c) {
364.1605 +            if (c==null)
364.1606 +                throw new NullPointerException();
364.1607 +            this.c = c;
364.1608 +            mutex = this;
364.1609 +        }
364.1610 +        SynchronizedCollection(Collection<E> c, Object mutex) {
364.1611 +            this.c = c;
364.1612 +            this.mutex = mutex;
364.1613 +        }
364.1614 +
364.1615 +        public int size() {
364.1616 +            synchronized (mutex) {return c.size();}
364.1617 +        }
364.1618 +        public boolean isEmpty() {
364.1619 +            synchronized (mutex) {return c.isEmpty();}
364.1620 +        }
364.1621 +        public boolean contains(Object o) {
364.1622 +            synchronized (mutex) {return c.contains(o);}
364.1623 +        }
364.1624 +        public Object[] toArray() {
364.1625 +            synchronized (mutex) {return c.toArray();}
364.1626 +        }
364.1627 +        public <T> T[] toArray(T[] a) {
364.1628 +            synchronized (mutex) {return c.toArray(a);}
364.1629 +        }
364.1630 +
364.1631 +        public Iterator<E> iterator() {
364.1632 +            return c.iterator(); // Must be manually synched by user!
364.1633 +        }
364.1634 +
364.1635 +        public boolean add(E e) {
364.1636 +            synchronized (mutex) {return c.add(e);}
364.1637 +        }
364.1638 +        public boolean remove(Object o) {
364.1639 +            synchronized (mutex) {return c.remove(o);}
364.1640 +        }
364.1641 +
364.1642 +        public boolean containsAll(Collection<?> coll) {
364.1643 +            synchronized (mutex) {return c.containsAll(coll);}
364.1644 +        }
364.1645 +        public boolean addAll(Collection<? extends E> coll) {
364.1646 +            synchronized (mutex) {return c.addAll(coll);}
364.1647 +        }
364.1648 +        public boolean removeAll(Collection<?> coll) {
364.1649 +            synchronized (mutex) {return c.removeAll(coll);}
364.1650 +        }
364.1651 +        public boolean retainAll(Collection<?> coll) {
364.1652 +            synchronized (mutex) {return c.retainAll(coll);}
364.1653 +        }
364.1654 +        public void clear() {
364.1655 +            synchronized (mutex) {c.clear();}
364.1656 +        }
364.1657 +        public String toString() {
364.1658 +            synchronized (mutex) {return c.toString();}
364.1659 +        }
364.1660 +    }
364.1661 +
364.1662 +    /**
364.1663 +     * Returns a synchronized (thread-safe) set backed by the specified
364.1664 +     * set.  In order to guarantee serial access, it is critical that
364.1665 +     * <strong>all</strong> access to the backing set is accomplished
364.1666 +     * through the returned set.<p>
364.1667 +     *
364.1668 +     * It is imperative that the user manually synchronize on the returned
364.1669 +     * set when iterating over it:
364.1670 +     * <pre>
364.1671 +     *  Set s = Collections.synchronizedSet(new HashSet());
364.1672 +     *      ...
364.1673 +     *  synchronized (s) {
364.1674 +     *      Iterator i = s.iterator(); // Must be in the synchronized block
364.1675 +     *      while (i.hasNext())
364.1676 +     *          foo(i.next());
364.1677 +     *  }
364.1678 +     * </pre>
364.1679 +     * Failure to follow this advice may result in non-deterministic behavior.
364.1680 +     *
364.1681 +     * <p>The returned set will be serializable if the specified set is
364.1682 +     * serializable.
364.1683 +     *
364.1684 +     * @param  s the set to be "wrapped" in a synchronized set.
364.1685 +     * @return a synchronized view of the specified set.
364.1686 +     */
364.1687 +    public static <T> Set<T> synchronizedSet(Set<T> s) {
364.1688 +        return new SynchronizedSet<>(s);
364.1689 +    }
364.1690 +
364.1691 +    static <T> Set<T> synchronizedSet(Set<T> s, Object mutex) {
364.1692 +        return new SynchronizedSet<>(s, mutex);
364.1693 +    }
364.1694 +
364.1695 +    /**
364.1696 +     * @serial include
364.1697 +     */
364.1698 +    static class SynchronizedSet<E>
364.1699 +          extends SynchronizedCollection<E>
364.1700 +          implements Set<E> {
364.1701 +        private static final long serialVersionUID = 487447009682186044L;
364.1702 +
364.1703 +        SynchronizedSet(Set<E> s) {
364.1704 +            super(s);
364.1705 +        }
364.1706 +        SynchronizedSet(Set<E> s, Object mutex) {
364.1707 +            super(s, mutex);
364.1708 +        }
364.1709 +
364.1710 +        public boolean equals(Object o) {
364.1711 +            synchronized (mutex) {return c.equals(o);}
364.1712 +        }
364.1713 +        public int hashCode() {
364.1714 +            synchronized (mutex) {return c.hashCode();}
364.1715 +        }
364.1716 +    }
364.1717 +
364.1718 +    /**
364.1719 +     * Returns a synchronized (thread-safe) sorted set backed by the specified
364.1720 +     * sorted set.  In order to guarantee serial access, it is critical that
364.1721 +     * <strong>all</strong> access to the backing sorted set is accomplished
364.1722 +     * through the returned sorted set (or its views).<p>
364.1723 +     *
364.1724 +     * It is imperative that the user manually synchronize on the returned
364.1725 +     * sorted set when iterating over it or any of its <tt>subSet</tt>,
364.1726 +     * <tt>headSet</tt>, or <tt>tailSet</tt> views.
364.1727 +     * <pre>
364.1728 +     *  SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
364.1729 +     *      ...
364.1730 +     *  synchronized (s) {
364.1731 +     *      Iterator i = s.iterator(); // Must be in the synchronized block
364.1732 +     *      while (i.hasNext())
364.1733 +     *          foo(i.next());
364.1734 +     *  }
364.1735 +     * </pre>
364.1736 +     * or:
364.1737 +     * <pre>
364.1738 +     *  SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
364.1739 +     *  SortedSet s2 = s.headSet(foo);
364.1740 +     *      ...
364.1741 +     *  synchronized (s) {  // Note: s, not s2!!!
364.1742 +     *      Iterator i = s2.iterator(); // Must be in the synchronized block
364.1743 +     *      while (i.hasNext())
364.1744 +     *          foo(i.next());
364.1745 +     *  }
364.1746 +     * </pre>
364.1747 +     * Failure to follow this advice may result in non-deterministic behavior.
364.1748 +     *
364.1749 +     * <p>The returned sorted set will be serializable if the specified
364.1750 +     * sorted set is serializable.
364.1751 +     *
364.1752 +     * @param  s the sorted set to be "wrapped" in a synchronized sorted set.
364.1753 +     * @return a synchronized view of the specified sorted set.
364.1754 +     */
364.1755 +    public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s) {
364.1756 +        return new SynchronizedSortedSet<>(s);
364.1757 +    }
364.1758 +
364.1759 +    /**
364.1760 +     * @serial include
364.1761 +     */
364.1762 +    static class SynchronizedSortedSet<E>
364.1763 +        extends SynchronizedSet<E>
364.1764 +        implements SortedSet<E>
364.1765 +    {
364.1766 +        private static final long serialVersionUID = 8695801310862127406L;
364.1767 +
364.1768 +        private final SortedSet<E> ss;
364.1769 +
364.1770 +        SynchronizedSortedSet(SortedSet<E> s) {
364.1771 +            super(s);
364.1772 +            ss = s;
364.1773 +        }
364.1774 +        SynchronizedSortedSet(SortedSet<E> s, Object mutex) {
364.1775 +            super(s, mutex);
364.1776 +            ss = s;
364.1777 +        }
364.1778 +
364.1779 +        public Comparator<? super E> comparator() {
364.1780 +            synchronized (mutex) {return ss.comparator();}
364.1781 +        }
364.1782 +
364.1783 +        public SortedSet<E> subSet(E fromElement, E toElement) {
364.1784 +            synchronized (mutex) {
364.1785 +                return new SynchronizedSortedSet<>(
364.1786 +                    ss.subSet(fromElement, toElement), mutex);
364.1787 +            }
364.1788 +        }
364.1789 +        public SortedSet<E> headSet(E toElement) {
364.1790 +            synchronized (mutex) {
364.1791 +                return new SynchronizedSortedSet<>(ss.headSet(toElement), mutex);
364.1792 +            }
364.1793 +        }
364.1794 +        public SortedSet<E> tailSet(E fromElement) {
364.1795 +            synchronized (mutex) {
364.1796 +               return new SynchronizedSortedSet<>(ss.tailSet(fromElement),mutex);
364.1797 +            }
364.1798 +        }
364.1799 +
364.1800 +        public E first() {
364.1801 +            synchronized (mutex) {return ss.first();}
364.1802 +        }
364.1803 +        public E last() {
364.1804 +            synchronized (mutex) {return ss.last();}
364.1805 +        }
364.1806 +    }
364.1807 +
364.1808 +    /**
364.1809 +     * Returns a synchronized (thread-safe) list backed by the specified
364.1810 +     * list.  In order to guarantee serial access, it is critical that
364.1811 +     * <strong>all</strong> access to the backing list is accomplished
364.1812 +     * through the returned list.<p>
364.1813 +     *
364.1814 +     * It is imperative that the user manually synchronize on the returned
364.1815 +     * list when iterating over it:
364.1816 +     * <pre>
364.1817 +     *  List list = Collections.synchronizedList(new ArrayList());
364.1818 +     *      ...
364.1819 +     *  synchronized (list) {
364.1820 +     *      Iterator i = list.iterator(); // Must be in synchronized block
364.1821 +     *      while (i.hasNext())
364.1822 +     *          foo(i.next());
364.1823 +     *  }
364.1824 +     * </pre>
364.1825 +     * Failure to follow this advice may result in non-deterministic behavior.
364.1826 +     *
364.1827 +     * <p>The returned list will be serializable if the specified list is
364.1828 +     * serializable.
364.1829 +     *
364.1830 +     * @param  list the list to be "wrapped" in a synchronized list.
364.1831 +     * @return a synchronized view of the specified list.
364.1832 +     */
364.1833 +    public static <T> List<T> synchronizedList(List<T> list) {
364.1834 +        return (list instanceof RandomAccess ?
364.1835 +                new SynchronizedRandomAccessList<>(list) :
364.1836 +                new SynchronizedList<>(list));
364.1837 +    }
364.1838 +
364.1839 +    static <T> List<T> synchronizedList(List<T> list, Object mutex) {
364.1840 +        return (list instanceof RandomAccess ?
364.1841 +                new SynchronizedRandomAccessList<>(list, mutex) :
364.1842 +                new SynchronizedList<>(list, mutex));
364.1843 +    }
364.1844 +
364.1845 +    /**
364.1846 +     * @serial include
364.1847 +     */
364.1848 +    static class SynchronizedList<E>
364.1849 +        extends SynchronizedCollection<E>
364.1850 +        implements List<E> {
364.1851 +        private static final long serialVersionUID = -7754090372962971524L;
364.1852 +
364.1853 +        final List<E> list;
364.1854 +
364.1855 +        SynchronizedList(List<E> list) {
364.1856 +            super(list);
364.1857 +            this.list = list;
364.1858 +        }
364.1859 +        SynchronizedList(List<E> list, Object mutex) {
364.1860 +            super(list, mutex);
364.1861 +            this.list = list;
364.1862 +        }
364.1863 +
364.1864 +        public boolean equals(Object o) {
364.1865 +            synchronized (mutex) {return list.equals(o);}
364.1866 +        }
364.1867 +        public int hashCode() {
364.1868 +            synchronized (mutex) {return list.hashCode();}
364.1869 +        }
364.1870 +
364.1871 +        public E get(int index) {
364.1872 +            synchronized (mutex) {return list.get(index);}
364.1873 +        }
364.1874 +        public E set(int index, E element) {
364.1875 +            synchronized (mutex) {return list.set(index, element);}
364.1876 +        }
364.1877 +        public void add(int index, E element) {
364.1878 +            synchronized (mutex) {list.add(index, element);}
364.1879 +        }
364.1880 +        public E remove(int index) {
364.1881 +            synchronized (mutex) {return list.remove(index);}
364.1882 +        }
364.1883 +
364.1884 +        public int indexOf(Object o) {
364.1885 +            synchronized (mutex) {return list.indexOf(o);}
364.1886 +        }
364.1887 +        public int lastIndexOf(Object o) {
364.1888 +            synchronized (mutex) {return list.lastIndexOf(o);}
364.1889 +        }
364.1890 +
364.1891 +        public boolean addAll(int index, Collection<? extends E> c) {
364.1892 +            synchronized (mutex) {return list.addAll(index, c);}
364.1893 +        }
364.1894 +
364.1895 +        public ListIterator<E> listIterator() {
364.1896 +            return list.listIterator(); // Must be manually synched by user
364.1897 +        }
364.1898 +
364.1899 +        public ListIterator<E> listIterator(int index) {
364.1900 +            return list.listIterator(index); // Must be manually synched by user
364.1901 +        }
364.1902 +
364.1903 +        public List<E> subList(int fromIndex, int toIndex) {
364.1904 +            synchronized (mutex) {
364.1905 +                return new SynchronizedList<>(list.subList(fromIndex, toIndex),
364.1906 +                                            mutex);
364.1907 +            }
364.1908 +        }
364.1909 +
364.1910 +        /**
364.1911 +         * SynchronizedRandomAccessList instances are serialized as
364.1912 +         * SynchronizedList instances to allow them to be deserialized
364.1913 +         * in pre-1.4 JREs (which do not have SynchronizedRandomAccessList).
364.1914 +         * This method inverts the transformation.  As a beneficial
364.1915 +         * side-effect, it also grafts the RandomAccess marker onto
364.1916 +         * SynchronizedList instances that were serialized in pre-1.4 JREs.
364.1917 +         *
364.1918 +         * Note: Unfortunately, SynchronizedRandomAccessList instances
364.1919 +         * serialized in 1.4.1 and deserialized in 1.4 will become
364.1920 +         * SynchronizedList instances, as this method was missing in 1.4.
364.1921 +         */
364.1922 +        private Object readResolve() {
364.1923 +            return (list instanceof RandomAccess
364.1924 +                    ? new SynchronizedRandomAccessList<>(list)
364.1925 +                    : this);
364.1926 +        }
364.1927 +    }
364.1928 +
364.1929 +    /**
364.1930 +     * @serial include
364.1931 +     */
364.1932 +    static class SynchronizedRandomAccessList<E>
364.1933 +        extends SynchronizedList<E>
364.1934 +        implements RandomAccess {
364.1935 +
364.1936 +        SynchronizedRandomAccessList(List<E> list) {
364.1937 +            super(list);
364.1938 +        }
364.1939 +
364.1940 +        SynchronizedRandomAccessList(List<E> list, Object mutex) {
364.1941 +            super(list, mutex);
364.1942 +        }
364.1943 +
364.1944 +        public List<E> subList(int fromIndex, int toIndex) {
364.1945 +            synchronized (mutex) {
364.1946 +                return new SynchronizedRandomAccessList<>(
364.1947 +                    list.subList(fromIndex, toIndex), mutex);
364.1948 +            }
364.1949 +        }
364.1950 +
364.1951 +        private static final long serialVersionUID = 1530674583602358482L;
364.1952 +
364.1953 +        /**
364.1954 +         * Allows instances to be deserialized in pre-1.4 JREs (which do
364.1955 +         * not have SynchronizedRandomAccessList).  SynchronizedList has
364.1956 +         * a readResolve method that inverts this transformation upon
364.1957 +         * deserialization.
364.1958 +         */
364.1959 +        private Object writeReplace() {
364.1960 +            return new SynchronizedList<>(list);
364.1961 +        }
364.1962 +    }
364.1963 +
364.1964 +    /**
364.1965 +     * Returns a synchronized (thread-safe) map backed by the specified
364.1966 +     * map.  In order to guarantee serial access, it is critical that
364.1967 +     * <strong>all</strong> access to the backing map is accomplished
364.1968 +     * through the returned map.<p>
364.1969 +     *
364.1970 +     * It is imperative that the user manually synchronize on the returned
364.1971 +     * map when iterating over any of its collection views:
364.1972 +     * <pre>
364.1973 +     *  Map m = Collections.synchronizedMap(new HashMap());
364.1974 +     *      ...
364.1975 +     *  Set s = m.keySet();  // Needn't be in synchronized block
364.1976 +     *      ...
364.1977 +     *  synchronized (m) {  // Synchronizing on m, not s!
364.1978 +     *      Iterator i = s.iterator(); // Must be in synchronized block
364.1979 +     *      while (i.hasNext())
364.1980 +     *          foo(i.next());
364.1981 +     *  }
364.1982 +     * </pre>
364.1983 +     * Failure to follow this advice may result in non-deterministic behavior.
364.1984 +     *
364.1985 +     * <p>The returned map will be serializable if the specified map is
364.1986 +     * serializable.
364.1987 +     *
364.1988 +     * @param  m the map to be "wrapped" in a synchronized map.
364.1989 +     * @return a synchronized view of the specified map.
364.1990 +     */
364.1991 +    public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) {
364.1992 +        return new SynchronizedMap<>(m);
364.1993 +    }
364.1994 +
364.1995 +    /**
364.1996 +     * @serial include
364.1997 +     */
364.1998 +    private static class SynchronizedMap<K,V>
364.1999 +        implements Map<K,V>, Serializable {
364.2000 +        private static final long serialVersionUID = 1978198479659022715L;
364.2001 +
364.2002 +        private final Map<K,V> m;     // Backing Map
364.2003 +        final Object      mutex;        // Object on which to synchronize
364.2004 +
364.2005 +        SynchronizedMap(Map<K,V> m) {
364.2006 +            if (m==null)
364.2007 +                throw new NullPointerException();
364.2008 +            this.m = m;
364.2009 +            mutex = this;
364.2010 +        }
364.2011 +
364.2012 +        SynchronizedMap(Map<K,V> m, Object mutex) {
364.2013 +            this.m = m;
364.2014 +            this.mutex = mutex;
364.2015 +        }
364.2016 +
364.2017 +        public int size() {
364.2018 +            synchronized (mutex) {return m.size();}
364.2019 +        }
364.2020 +        public boolean isEmpty() {
364.2021 +            synchronized (mutex) {return m.isEmpty();}
364.2022 +        }
364.2023 +        public boolean containsKey(Object key) {
364.2024 +            synchronized (mutex) {return m.containsKey(key);}
364.2025 +        }
364.2026 +        public boolean containsValue(Object value) {
364.2027 +            synchronized (mutex) {return m.containsValue(value);}
364.2028 +        }
364.2029 +        public V get(Object key) {
364.2030 +            synchronized (mutex) {return m.get(key);}
364.2031 +        }
364.2032 +
364.2033 +        public V put(K key, V value) {
364.2034 +            synchronized (mutex) {return m.put(key, value);}
364.2035 +        }
364.2036 +        public V remove(Object key) {
364.2037 +            synchronized (mutex) {return m.remove(key);}
364.2038 +        }
364.2039 +        public void putAll(Map<? extends K, ? extends V> map) {
364.2040 +            synchronized (mutex) {m.putAll(map);}
364.2041 +        }
364.2042 +        public void clear() {
364.2043 +            synchronized (mutex) {m.clear();}
364.2044 +        }
364.2045 +
364.2046 +        private transient Set<K> keySet = null;
364.2047 +        private transient Set<Map.Entry<K,V>> entrySet = null;
364.2048 +        private transient Collection<V> values = null;
364.2049 +
364.2050 +        public Set<K> keySet() {
364.2051 +            synchronized (mutex) {
364.2052 +                if (keySet==null)
364.2053 +                    keySet = new SynchronizedSet<>(m.keySet(), mutex);
364.2054 +                return keySet;
364.2055 +            }
364.2056 +        }
364.2057 +
364.2058 +        public Set<Map.Entry<K,V>> entrySet() {
364.2059 +            synchronized (mutex) {
364.2060 +                if (entrySet==null)
364.2061 +                    entrySet = new SynchronizedSet<>(m.entrySet(), mutex);
364.2062 +                return entrySet;
364.2063 +            }
364.2064 +        }
364.2065 +
364.2066 +        public Collection<V> values() {
364.2067 +            synchronized (mutex) {
364.2068 +                if (values==null)
364.2069 +                    values = new SynchronizedCollection<>(m.values(), mutex);
364.2070 +                return values;
364.2071 +            }
364.2072 +        }
364.2073 +
364.2074 +        public boolean equals(Object o) {
364.2075 +            synchronized (mutex) {return m.equals(o);}
364.2076 +        }
364.2077 +        public int hashCode() {
364.2078 +            synchronized (mutex) {return m.hashCode();}
364.2079 +        }
364.2080 +        public String toString() {
364.2081 +            synchronized (mutex) {return m.toString();}
364.2082 +        }
364.2083 +    }
364.2084 +
364.2085 +    /**
364.2086 +     * Returns a synchronized (thread-safe) sorted map backed by the specified
364.2087 +     * sorted map.  In order to guarantee serial access, it is critical that
364.2088 +     * <strong>all</strong> access to the backing sorted map is accomplished
364.2089 +     * through the returned sorted map (or its views).<p>
364.2090 +     *
364.2091 +     * It is imperative that the user manually synchronize on the returned
364.2092 +     * sorted map when iterating over any of its collection views, or the
364.2093 +     * collections views of any of its <tt>subMap</tt>, <tt>headMap</tt> or
364.2094 +     * <tt>tailMap</tt> views.
364.2095 +     * <pre>
364.2096 +     *  SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
364.2097 +     *      ...
364.2098 +     *  Set s = m.keySet();  // Needn't be in synchronized block
364.2099 +     *      ...
364.2100 +     *  synchronized (m) {  // Synchronizing on m, not s!
364.2101 +     *      Iterator i = s.iterator(); // Must be in synchronized block
364.2102 +     *      while (i.hasNext())
364.2103 +     *          foo(i.next());
364.2104 +     *  }
364.2105 +     * </pre>
364.2106 +     * or:
364.2107 +     * <pre>
364.2108 +     *  SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
364.2109 +     *  SortedMap m2 = m.subMap(foo, bar);
364.2110 +     *      ...
364.2111 +     *  Set s2 = m2.keySet();  // Needn't be in synchronized block
364.2112 +     *      ...
364.2113 +     *  synchronized (m) {  // Synchronizing on m, not m2 or s2!
364.2114 +     *      Iterator i = s.iterator(); // Must be in synchronized block
364.2115 +     *      while (i.hasNext())
364.2116 +     *          foo(i.next());
364.2117 +     *  }
364.2118 +     * </pre>
364.2119 +     * Failure to follow this advice may result in non-deterministic behavior.
364.2120 +     *
364.2121 +     * <p>The returned sorted map will be serializable if the specified
364.2122 +     * sorted map is serializable.
364.2123 +     *
364.2124 +     * @param  m the sorted map to be "wrapped" in a synchronized sorted map.
364.2125 +     * @return a synchronized view of the specified sorted map.
364.2126 +     */
364.2127 +    public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m) {
364.2128 +        return new SynchronizedSortedMap<>(m);
364.2129 +    }
364.2130 +
364.2131 +
364.2132 +    /**
364.2133 +     * @serial include
364.2134 +     */
364.2135 +    static class SynchronizedSortedMap<K,V>
364.2136 +        extends SynchronizedMap<K,V>
364.2137 +        implements SortedMap<K,V>
364.2138 +    {
364.2139 +        private static final long serialVersionUID = -8798146769416483793L;
364.2140 +
364.2141 +        private final SortedMap<K,V> sm;
364.2142 +
364.2143 +        SynchronizedSortedMap(SortedMap<K,V> m) {
364.2144 +            super(m);
364.2145 +            sm = m;
364.2146 +        }
364.2147 +        SynchronizedSortedMap(SortedMap<K,V> m, Object mutex) {
364.2148 +            super(m, mutex);
364.2149 +            sm = m;
364.2150 +        }
364.2151 +
364.2152 +        public Comparator<? super K> comparator() {
364.2153 +            synchronized (mutex) {return sm.comparator();}
364.2154 +        }
364.2155 +
364.2156 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
364.2157 +            synchronized (mutex) {
364.2158 +                return new SynchronizedSortedMap<>(
364.2159 +                    sm.subMap(fromKey, toKey), mutex);
364.2160 +            }
364.2161 +        }
364.2162 +        public SortedMap<K,V> headMap(K toKey) {
364.2163 +            synchronized (mutex) {
364.2164 +                return new SynchronizedSortedMap<>(sm.headMap(toKey), mutex);
364.2165 +            }
364.2166 +        }
364.2167 +        public SortedMap<K,V> tailMap(K fromKey) {
364.2168 +            synchronized (mutex) {
364.2169 +               return new SynchronizedSortedMap<>(sm.tailMap(fromKey),mutex);
364.2170 +            }
364.2171 +        }
364.2172 +
364.2173 +        public K firstKey() {
364.2174 +            synchronized (mutex) {return sm.firstKey();}
364.2175 +        }
364.2176 +        public K lastKey() {
364.2177 +            synchronized (mutex) {return sm.lastKey();}
364.2178 +        }
364.2179 +    }
364.2180 +
364.2181 +    // Dynamically typesafe collection wrappers
364.2182 +
364.2183 +    /**
364.2184 +     * Returns a dynamically typesafe view of the specified collection.
364.2185 +     * Any attempt to insert an element of the wrong type will result in an
364.2186 +     * immediate {@link ClassCastException}.  Assuming a collection
364.2187 +     * contains no incorrectly typed elements prior to the time a
364.2188 +     * dynamically typesafe view is generated, and that all subsequent
364.2189 +     * access to the collection takes place through the view, it is
364.2190 +     * <i>guaranteed</i> that the collection cannot contain an incorrectly
364.2191 +     * typed element.
364.2192 +     *
364.2193 +     * <p>The generics mechanism in the language provides compile-time
364.2194 +     * (static) type checking, but it is possible to defeat this mechanism
364.2195 +     * with unchecked casts.  Usually this is not a problem, as the compiler
364.2196 +     * issues warnings on all such unchecked operations.  There are, however,
364.2197 +     * times when static type checking alone is not sufficient.  For example,
364.2198 +     * suppose a collection is passed to a third-party library and it is
364.2199 +     * imperative that the library code not corrupt the collection by
364.2200 +     * inserting an element of the wrong type.
364.2201 +     *
364.2202 +     * <p>Another use of dynamically typesafe views is debugging.  Suppose a
364.2203 +     * program fails with a {@code ClassCastException}, indicating that an
364.2204 +     * incorrectly typed element was put into a parameterized collection.
364.2205 +     * Unfortunately, the exception can occur at any time after the erroneous
364.2206 +     * element is inserted, so it typically provides little or no information
364.2207 +     * as to the real source of the problem.  If the problem is reproducible,
364.2208 +     * one can quickly determine its source by temporarily modifying the
364.2209 +     * program to wrap the collection with a dynamically typesafe view.
364.2210 +     * For example, this declaration:
364.2211 +     *  <pre> {@code
364.2212 +     *     Collection<String> c = new HashSet<String>();
364.2213 +     * }</pre>
364.2214 +     * may be replaced temporarily by this one:
364.2215 +     *  <pre> {@code
364.2216 +     *     Collection<String> c = Collections.checkedCollection(
364.2217 +     *         new HashSet<String>(), String.class);
364.2218 +     * }</pre>
364.2219 +     * Running the program again will cause it to fail at the point where
364.2220 +     * an incorrectly typed element is inserted into the collection, clearly
364.2221 +     * identifying the source of the problem.  Once the problem is fixed, the
364.2222 +     * modified declaration may be reverted back to the original.
364.2223 +     *
364.2224 +     * <p>The returned collection does <i>not</i> pass the hashCode and equals
364.2225 +     * operations through to the backing collection, but relies on
364.2226 +     * {@code Object}'s {@code equals} and {@code hashCode} methods.  This
364.2227 +     * is necessary to preserve the contracts of these operations in the case
364.2228 +     * that the backing collection is a set or a list.
364.2229 +     *
364.2230 +     * <p>The returned collection will be serializable if the specified
364.2231 +     * collection is serializable.
364.2232 +     *
364.2233 +     * <p>Since {@code null} is considered to be a value of any reference
364.2234 +     * type, the returned collection permits insertion of null elements
364.2235 +     * whenever the backing collection does.
364.2236 +     *
364.2237 +     * @param c the collection for which a dynamically typesafe view is to be
364.2238 +     *          returned
364.2239 +     * @param type the type of element that {@code c} is permitted to hold
364.2240 +     * @return a dynamically typesafe view of the specified collection
364.2241 +     * @since 1.5
364.2242 +     */
364.2243 +    public static <E> Collection<E> checkedCollection(Collection<E> c,
364.2244 +                                                      Class<E> type) {
364.2245 +        return new CheckedCollection<>(c, type);
364.2246 +    }
364.2247 +
364.2248 +    @SuppressWarnings("unchecked")
364.2249 +    static <T> T[] zeroLengthArray(Class<T> type) {
364.2250 +        return (T[]) Array.newInstance(type, 0);
364.2251 +    }
364.2252 +
364.2253 +    /**
364.2254 +     * @serial include
364.2255 +     */
364.2256 +    static class CheckedCollection<E> implements Collection<E>, Serializable {
364.2257 +        private static final long serialVersionUID = 1578914078182001775L;
364.2258 +
364.2259 +        final Collection<E> c;
364.2260 +        final Class<E> type;
364.2261 +
364.2262 +        void typeCheck(Object o) {
364.2263 +            if (o != null && !type.isInstance(o))
364.2264 +                throw new ClassCastException(badElementMsg(o));
364.2265 +        }
364.2266 +
364.2267 +        private String badElementMsg(Object o) {
364.2268 +            return "Attempt to insert " + o.getClass() +
364.2269 +                " element into collection with element type " + type;
364.2270 +        }
364.2271 +
364.2272 +        CheckedCollection(Collection<E> c, Class<E> type) {
364.2273 +            if (c==null || type == null)
364.2274 +                throw new NullPointerException();
364.2275 +            this.c = c;
364.2276 +            this.type = type;
364.2277 +        }
364.2278 +
364.2279 +        public int size()                 { return c.size(); }
364.2280 +        public boolean isEmpty()          { return c.isEmpty(); }
364.2281 +        public boolean contains(Object o) { return c.contains(o); }
364.2282 +        public Object[] toArray()         { return c.toArray(); }
364.2283 +        public <T> T[] toArray(T[] a)     { return c.toArray(a); }
364.2284 +        public String toString()          { return c.toString(); }
364.2285 +        public boolean remove(Object o)   { return c.remove(o); }
364.2286 +        public void clear()               {        c.clear(); }
364.2287 +
364.2288 +        public boolean containsAll(Collection<?> coll) {
364.2289 +            return c.containsAll(coll);
364.2290 +        }
364.2291 +        public boolean removeAll(Collection<?> coll) {
364.2292 +            return c.removeAll(coll);
364.2293 +        }
364.2294 +        public boolean retainAll(Collection<?> coll) {
364.2295 +            return c.retainAll(coll);
364.2296 +        }
364.2297 +
364.2298 +        public Iterator<E> iterator() {
364.2299 +            final Iterator<E> it = c.iterator();
364.2300 +            return new Iterator<E>() {
364.2301 +                public boolean hasNext() { return it.hasNext(); }
364.2302 +                public E next()          { return it.next(); }
364.2303 +                public void remove()     {        it.remove(); }};
364.2304 +        }
364.2305 +
364.2306 +        public boolean add(E e) {
364.2307 +            typeCheck(e);
364.2308 +            return c.add(e);
364.2309 +        }
364.2310 +
364.2311 +        private E[] zeroLengthElementArray = null; // Lazily initialized
364.2312 +
364.2313 +        private E[] zeroLengthElementArray() {
364.2314 +            return zeroLengthElementArray != null ? zeroLengthElementArray :
364.2315 +                (zeroLengthElementArray = zeroLengthArray(type));
364.2316 +        }
364.2317 +
364.2318 +        @SuppressWarnings("unchecked")
364.2319 +        Collection<E> checkedCopyOf(Collection<? extends E> coll) {
364.2320 +            Object[] a = null;
364.2321 +            try {
364.2322 +                E[] z = zeroLengthElementArray();
364.2323 +                a = coll.toArray(z);
364.2324 +                // Defend against coll violating the toArray contract
364.2325 +                if (a.getClass() != z.getClass())
364.2326 +                    a = Arrays.copyOf(a, a.length, z.getClass());
364.2327 +            } catch (ArrayStoreException ignore) {
364.2328 +                // To get better and consistent diagnostics,
364.2329 +                // we call typeCheck explicitly on each element.
364.2330 +                // We call clone() to defend against coll retaining a
364.2331 +                // reference to the returned array and storing a bad
364.2332 +                // element into it after it has been type checked.
364.2333 +                a = coll.toArray().clone();
364.2334 +                for (Object o : a)
364.2335 +                    typeCheck(o);
364.2336 +            }
364.2337 +            // A slight abuse of the type system, but safe here.
364.2338 +            return (Collection<E>) Arrays.asList(a);
364.2339 +        }
364.2340 +
364.2341 +        public boolean addAll(Collection<? extends E> coll) {
364.2342 +            // Doing things this way insulates us from concurrent changes
364.2343 +            // in the contents of coll and provides all-or-nothing
364.2344 +            // semantics (which we wouldn't get if we type-checked each
364.2345 +            // element as we added it)
364.2346 +            return c.addAll(checkedCopyOf(coll));
364.2347 +        }
364.2348 +    }
364.2349 +
364.2350 +    /**
364.2351 +     * Returns a dynamically typesafe view of the specified set.
364.2352 +     * Any attempt to insert an element of the wrong type will result in
364.2353 +     * an immediate {@link ClassCastException}.  Assuming a set contains
364.2354 +     * no incorrectly typed elements prior to the time a dynamically typesafe
364.2355 +     * view is generated, and that all subsequent access to the set
364.2356 +     * takes place through the view, it is <i>guaranteed</i> that the
364.2357 +     * set cannot contain an incorrectly typed element.
364.2358 +     *
364.2359 +     * <p>A discussion of the use of dynamically typesafe views may be
364.2360 +     * found in the documentation for the {@link #checkedCollection
364.2361 +     * checkedCollection} method.
364.2362 +     *
364.2363 +     * <p>The returned set will be serializable if the specified set is
364.2364 +     * serializable.
364.2365 +     *
364.2366 +     * <p>Since {@code null} is considered to be a value of any reference
364.2367 +     * type, the returned set permits insertion of null elements whenever
364.2368 +     * the backing set does.
364.2369 +     *
364.2370 +     * @param s the set for which a dynamically typesafe view is to be
364.2371 +     *          returned
364.2372 +     * @param type the type of element that {@code s} is permitted to hold
364.2373 +     * @return a dynamically typesafe view of the specified set
364.2374 +     * @since 1.5
364.2375 +     */
364.2376 +    public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) {
364.2377 +        return new CheckedSet<>(s, type);
364.2378 +    }
364.2379 +
364.2380 +    /**
364.2381 +     * @serial include
364.2382 +     */
364.2383 +    static class CheckedSet<E> extends CheckedCollection<E>
364.2384 +                                 implements Set<E>, Serializable
364.2385 +    {
364.2386 +        private static final long serialVersionUID = 4694047833775013803L;
364.2387 +
364.2388 +        CheckedSet(Set<E> s, Class<E> elementType) { super(s, elementType); }
364.2389 +
364.2390 +        public boolean equals(Object o) { return o == this || c.equals(o); }
364.2391 +        public int hashCode()           { return c.hashCode(); }
364.2392 +    }
364.2393 +
364.2394 +    /**
364.2395 +     * Returns a dynamically typesafe view of the specified sorted set.
364.2396 +     * Any attempt to insert an element of the wrong type will result in an
364.2397 +     * immediate {@link ClassCastException}.  Assuming a sorted set
364.2398 +     * contains no incorrectly typed elements prior to the time a
364.2399 +     * dynamically typesafe view is generated, and that all subsequent
364.2400 +     * access to the sorted set takes place through the view, it is
364.2401 +     * <i>guaranteed</i> that the sorted set cannot contain an incorrectly
364.2402 +     * typed element.
364.2403 +     *
364.2404 +     * <p>A discussion of the use of dynamically typesafe views may be
364.2405 +     * found in the documentation for the {@link #checkedCollection
364.2406 +     * checkedCollection} method.
364.2407 +     *
364.2408 +     * <p>The returned sorted set will be serializable if the specified sorted
364.2409 +     * set is serializable.
364.2410 +     *
364.2411 +     * <p>Since {@code null} is considered to be a value of any reference
364.2412 +     * type, the returned sorted set permits insertion of null elements
364.2413 +     * whenever the backing sorted set does.
364.2414 +     *
364.2415 +     * @param s the sorted set for which a dynamically typesafe view is to be
364.2416 +     *          returned
364.2417 +     * @param type the type of element that {@code s} is permitted to hold
364.2418 +     * @return a dynamically typesafe view of the specified sorted set
364.2419 +     * @since 1.5
364.2420 +     */
364.2421 +    public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s,
364.2422 +                                                    Class<E> type) {
364.2423 +        return new CheckedSortedSet<>(s, type);
364.2424 +    }
364.2425 +
364.2426 +    /**
364.2427 +     * @serial include
364.2428 +     */
364.2429 +    static class CheckedSortedSet<E> extends CheckedSet<E>
364.2430 +        implements SortedSet<E>, Serializable
364.2431 +    {
364.2432 +        private static final long serialVersionUID = 1599911165492914959L;
364.2433 +        private final SortedSet<E> ss;
364.2434 +
364.2435 +        CheckedSortedSet(SortedSet<E> s, Class<E> type) {
364.2436 +            super(s, type);
364.2437 +            ss = s;
364.2438 +        }
364.2439 +
364.2440 +        public Comparator<? super E> comparator() { return ss.comparator(); }
364.2441 +        public E first()                   { return ss.first(); }
364.2442 +        public E last()                    { return ss.last(); }
364.2443 +
364.2444 +        public SortedSet<E> subSet(E fromElement, E toElement) {
364.2445 +            return checkedSortedSet(ss.subSet(fromElement,toElement), type);
364.2446 +        }
364.2447 +        public SortedSet<E> headSet(E toElement) {
364.2448 +            return checkedSortedSet(ss.headSet(toElement), type);
364.2449 +        }
364.2450 +        public SortedSet<E> tailSet(E fromElement) {
364.2451 +            return checkedSortedSet(ss.tailSet(fromElement), type);
364.2452 +        }
364.2453 +    }
364.2454 +
364.2455 +    /**
364.2456 +     * Returns a dynamically typesafe view of the specified list.
364.2457 +     * Any attempt to insert an element of the wrong type will result in
364.2458 +     * an immediate {@link ClassCastException}.  Assuming a list contains
364.2459 +     * no incorrectly typed elements prior to the time a dynamically typesafe
364.2460 +     * view is generated, and that all subsequent access to the list
364.2461 +     * takes place through the view, it is <i>guaranteed</i> that the
364.2462 +     * list cannot contain an incorrectly typed element.
364.2463 +     *
364.2464 +     * <p>A discussion of the use of dynamically typesafe views may be
364.2465 +     * found in the documentation for the {@link #checkedCollection
364.2466 +     * checkedCollection} method.
364.2467 +     *
364.2468 +     * <p>The returned list will be serializable if the specified list
364.2469 +     * is serializable.
364.2470 +     *
364.2471 +     * <p>Since {@code null} is considered to be a value of any reference
364.2472 +     * type, the returned list permits insertion of null elements whenever
364.2473 +     * the backing list does.
364.2474 +     *
364.2475 +     * @param list the list for which a dynamically typesafe view is to be
364.2476 +     *             returned
364.2477 +     * @param type the type of element that {@code list} is permitted to hold
364.2478 +     * @return a dynamically typesafe view of the specified list
364.2479 +     * @since 1.5
364.2480 +     */
364.2481 +    public static <E> List<E> checkedList(List<E> list, Class<E> type) {
364.2482 +        return (list instanceof RandomAccess ?
364.2483 +                new CheckedRandomAccessList<>(list, type) :
364.2484 +                new CheckedList<>(list, type));
364.2485 +    }
364.2486 +
364.2487 +    /**
364.2488 +     * @serial include
364.2489 +     */
364.2490 +    static class CheckedList<E>
364.2491 +        extends CheckedCollection<E>
364.2492 +        implements List<E>
364.2493 +    {
364.2494 +        private static final long serialVersionUID = 65247728283967356L;
364.2495 +        final List<E> list;
364.2496 +
364.2497 +        CheckedList(List<E> list, Class<E> type) {
364.2498 +            super(list, type);
364.2499 +            this.list = list;
364.2500 +        }
364.2501 +
364.2502 +        public boolean equals(Object o)  { return o == this || list.equals(o); }
364.2503 +        public int hashCode()            { return list.hashCode(); }
364.2504 +        public E get(int index)          { return list.get(index); }
364.2505 +        public E remove(int index)       { return list.remove(index); }
364.2506 +        public int indexOf(Object o)     { return list.indexOf(o); }
364.2507 +        public int lastIndexOf(Object o) { return list.lastIndexOf(o); }
364.2508 +
364.2509 +        public E set(int index, E element) {
364.2510 +            typeCheck(element);
364.2511 +            return list.set(index, element);
364.2512 +        }
364.2513 +
364.2514 +        public void add(int index, E element) {
364.2515 +            typeCheck(element);
364.2516 +            list.add(index, element);
364.2517 +        }
364.2518 +
364.2519 +        public boolean addAll(int index, Collection<? extends E> c) {
364.2520 +            return list.addAll(index, checkedCopyOf(c));
364.2521 +        }
364.2522 +        public ListIterator<E> listIterator()   { return listIterator(0); }
364.2523 +
364.2524 +        public ListIterator<E> listIterator(final int index) {
364.2525 +            final ListIterator<E> i = list.listIterator(index);
364.2526 +
364.2527 +            return new ListIterator<E>() {
364.2528 +                public boolean hasNext()     { return i.hasNext(); }
364.2529 +                public E next()              { return i.next(); }
364.2530 +                public boolean hasPrevious() { return i.hasPrevious(); }
364.2531 +                public E previous()          { return i.previous(); }
364.2532 +                public int nextIndex()       { return i.nextIndex(); }
364.2533 +                public int previousIndex()   { return i.previousIndex(); }
364.2534 +                public void remove()         {        i.remove(); }
364.2535 +
364.2536 +                public void set(E e) {
364.2537 +                    typeCheck(e);
364.2538 +                    i.set(e);
364.2539 +                }
364.2540 +
364.2541 +                public void add(E e) {
364.2542 +                    typeCheck(e);
364.2543 +                    i.add(e);
364.2544 +                }
364.2545 +            };
364.2546 +        }
364.2547 +
364.2548 +        public List<E> subList(int fromIndex, int toIndex) {
364.2549 +            return new CheckedList<>(list.subList(fromIndex, toIndex), type);
364.2550 +        }
364.2551 +    }
364.2552 +
364.2553 +    /**
364.2554 +     * @serial include
364.2555 +     */
364.2556 +    static class CheckedRandomAccessList<E> extends CheckedList<E>
364.2557 +                                            implements RandomAccess
364.2558 +    {
364.2559 +        private static final long serialVersionUID = 1638200125423088369L;
364.2560 +
364.2561 +        CheckedRandomAccessList(List<E> list, Class<E> type) {
364.2562 +            super(list, type);
364.2563 +        }
364.2564 +
364.2565 +        public List<E> subList(int fromIndex, int toIndex) {
364.2566 +            return new CheckedRandomAccessList<>(
364.2567 +                list.subList(fromIndex, toIndex), type);
364.2568 +        }
364.2569 +    }
364.2570 +
364.2571 +    /**
364.2572 +     * Returns a dynamically typesafe view of the specified map.
364.2573 +     * Any attempt to insert a mapping whose key or value have the wrong
364.2574 +     * type will result in an immediate {@link ClassCastException}.
364.2575 +     * Similarly, any attempt to modify the value currently associated with
364.2576 +     * a key will result in an immediate {@link ClassCastException},
364.2577 +     * whether the modification is attempted directly through the map
364.2578 +     * itself, or through a {@link Map.Entry} instance obtained from the
364.2579 +     * map's {@link Map#entrySet() entry set} view.
364.2580 +     *
364.2581 +     * <p>Assuming a map contains no incorrectly typed keys or values
364.2582 +     * prior to the time a dynamically typesafe view is generated, and
364.2583 +     * that all subsequent access to the map takes place through the view
364.2584 +     * (or one of its collection views), it is <i>guaranteed</i> that the
364.2585 +     * map cannot contain an incorrectly typed key or value.
364.2586 +     *
364.2587 +     * <p>A discussion of the use of dynamically typesafe views may be
364.2588 +     * found in the documentation for the {@link #checkedCollection
364.2589 +     * checkedCollection} method.
364.2590 +     *
364.2591 +     * <p>The returned map will be serializable if the specified map is
364.2592 +     * serializable.
364.2593 +     *
364.2594 +     * <p>Since {@code null} is considered to be a value of any reference
364.2595 +     * type, the returned map permits insertion of null keys or values
364.2596 +     * whenever the backing map does.
364.2597 +     *
364.2598 +     * @param m the map for which a dynamically typesafe view is to be
364.2599 +     *          returned
364.2600 +     * @param keyType the type of key that {@code m} is permitted to hold
364.2601 +     * @param valueType the type of value that {@code m} is permitted to hold
364.2602 +     * @return a dynamically typesafe view of the specified map
364.2603 +     * @since 1.5
364.2604 +     */
364.2605 +    public static <K, V> Map<K, V> checkedMap(Map<K, V> m,
364.2606 +                                              Class<K> keyType,
364.2607 +                                              Class<V> valueType) {
364.2608 +        return new CheckedMap<>(m, keyType, valueType);
364.2609 +    }
364.2610 +
364.2611 +
364.2612 +    /**
364.2613 +     * @serial include
364.2614 +     */
364.2615 +    private static class CheckedMap<K,V>
364.2616 +        implements Map<K,V>, Serializable
364.2617 +    {
364.2618 +        private static final long serialVersionUID = 5742860141034234728L;
364.2619 +
364.2620 +        private final Map<K, V> m;
364.2621 +        final Class<K> keyType;
364.2622 +        final Class<V> valueType;
364.2623 +
364.2624 +        private void typeCheck(Object key, Object value) {
364.2625 +            if (key != null && !keyType.isInstance(key))
364.2626 +                throw new ClassCastException(badKeyMsg(key));
364.2627 +
364.2628 +            if (value != null && !valueType.isInstance(value))
364.2629 +                throw new ClassCastException(badValueMsg(value));
364.2630 +        }
364.2631 +
364.2632 +        private String badKeyMsg(Object key) {
364.2633 +            return "Attempt to insert " + key.getClass() +
364.2634 +                " key into map with key type " + keyType;
364.2635 +        }
364.2636 +
364.2637 +        private String badValueMsg(Object value) {
364.2638 +            return "Attempt to insert " + value.getClass() +
364.2639 +                " value into map with value type " + valueType;
364.2640 +        }
364.2641 +
364.2642 +        CheckedMap(Map<K, V> m, Class<K> keyType, Class<V> valueType) {
364.2643 +            if (m == null || keyType == null || valueType == null)
364.2644 +                throw new NullPointerException();
364.2645 +            this.m = m;
364.2646 +            this.keyType = keyType;
364.2647 +            this.valueType = valueType;
364.2648 +        }
364.2649 +
364.2650 +        public int size()                      { return m.size(); }
364.2651 +        public boolean isEmpty()               { return m.isEmpty(); }
364.2652 +        public boolean containsKey(Object key) { return m.containsKey(key); }
364.2653 +        public boolean containsValue(Object v) { return m.containsValue(v); }
364.2654 +        public V get(Object key)               { return m.get(key); }
364.2655 +        public V remove(Object key)            { return m.remove(key); }
364.2656 +        public void clear()                    { m.clear(); }
364.2657 +        public Set<K> keySet()                 { return m.keySet(); }
364.2658 +        public Collection<V> values()          { return m.values(); }
364.2659 +        public boolean equals(Object o)        { return o == this || m.equals(o); }
364.2660 +        public int hashCode()                  { return m.hashCode(); }
364.2661 +        public String toString()               { return m.toString(); }
364.2662 +
364.2663 +        public V put(K key, V value) {
364.2664 +            typeCheck(key, value);
364.2665 +            return m.put(key, value);
364.2666 +        }
364.2667 +
364.2668 +        @SuppressWarnings("unchecked")
364.2669 +        public void putAll(Map<? extends K, ? extends V> t) {
364.2670 +            // Satisfy the following goals:
364.2671 +            // - good diagnostics in case of type mismatch
364.2672 +            // - all-or-nothing semantics
364.2673 +            // - protection from malicious t
364.2674 +            // - correct behavior if t is a concurrent map
364.2675 +            Object[] entries = t.entrySet().toArray();
364.2676 +            List<Map.Entry<K,V>> checked = new ArrayList<>(entries.length);
364.2677 +            for (Object o : entries) {
364.2678 +                Map.Entry<?,?> e = (Map.Entry<?,?>) o;
364.2679 +                Object k = e.getKey();
364.2680 +                Object v = e.getValue();
364.2681 +                typeCheck(k, v);
364.2682 +                checked.add(
364.2683 +                    new AbstractMap.SimpleImmutableEntry<>((K) k, (V) v));
364.2684 +            }
364.2685 +            for (Map.Entry<K,V> e : checked)
364.2686 +                m.put(e.getKey(), e.getValue());
364.2687 +        }
364.2688 +
364.2689 +        private transient Set<Map.Entry<K,V>> entrySet = null;
364.2690 +
364.2691 +        public Set<Map.Entry<K,V>> entrySet() {
364.2692 +            if (entrySet==null)
364.2693 +                entrySet = new CheckedEntrySet<>(m.entrySet(), valueType);
364.2694 +            return entrySet;
364.2695 +        }
364.2696 +
364.2697 +        /**
364.2698 +         * We need this class in addition to CheckedSet as Map.Entry permits
364.2699 +         * modification of the backing Map via the setValue operation.  This
364.2700 +         * class is subtle: there are many possible attacks that must be
364.2701 +         * thwarted.
364.2702 +         *
364.2703 +         * @serial exclude
364.2704 +         */
364.2705 +        static class CheckedEntrySet<K,V> implements Set<Map.Entry<K,V>> {
364.2706 +            private final Set<Map.Entry<K,V>> s;
364.2707 +            private final Class<V> valueType;
364.2708 +
364.2709 +            CheckedEntrySet(Set<Map.Entry<K, V>> s, Class<V> valueType) {
364.2710 +                this.s = s;
364.2711 +                this.valueType = valueType;
364.2712 +            }
364.2713 +
364.2714 +            public int size()        { return s.size(); }
364.2715 +            public boolean isEmpty() { return s.isEmpty(); }
364.2716 +            public String toString() { return s.toString(); }
364.2717 +            public int hashCode()    { return s.hashCode(); }
364.2718 +            public void clear()      {        s.clear(); }
364.2719 +
364.2720 +            public boolean add(Map.Entry<K, V> e) {
364.2721 +                throw new UnsupportedOperationException();
364.2722 +            }
364.2723 +            public boolean addAll(Collection<? extends Map.Entry<K, V>> coll) {
364.2724 +                throw new UnsupportedOperationException();
364.2725 +            }
364.2726 +
364.2727 +            public Iterator<Map.Entry<K,V>> iterator() {
364.2728 +                final Iterator<Map.Entry<K, V>> i = s.iterator();
364.2729 +                final Class<V> valueType = this.valueType;
364.2730 +
364.2731 +                return new Iterator<Map.Entry<K,V>>() {
364.2732 +                    public boolean hasNext() { return i.hasNext(); }
364.2733 +                    public void remove()     { i.remove(); }
364.2734 +
364.2735 +                    public Map.Entry<K,V> next() {
364.2736 +                        return checkedEntry(i.next(), valueType);
364.2737 +                    }
364.2738 +                };
364.2739 +            }
364.2740 +
364.2741 +            @SuppressWarnings("unchecked")
364.2742 +            public Object[] toArray() {
364.2743 +                Object[] source = s.toArray();
364.2744 +
364.2745 +                /*
364.2746 +                 * Ensure that we don't get an ArrayStoreException even if
364.2747 +                 * s.toArray returns an array of something other than Object
364.2748 +                 */
364.2749 +                Object[] dest = (CheckedEntry.class.isInstance(
364.2750 +                    source.getClass().getComponentType()) ? source :
364.2751 +                                 new Object[source.length]);
364.2752 +
364.2753 +                for (int i = 0; i < source.length; i++)
364.2754 +                    dest[i] = checkedEntry((Map.Entry<K,V>)source[i],
364.2755 +                                           valueType);
364.2756 +                return dest;
364.2757 +            }
364.2758 +
364.2759 +            @SuppressWarnings("unchecked")
364.2760 +            public <T> T[] toArray(T[] a) {
364.2761 +                // We don't pass a to s.toArray, to avoid window of
364.2762 +                // vulnerability wherein an unscrupulous multithreaded client
364.2763 +                // could get his hands on raw (unwrapped) Entries from s.
364.2764 +                T[] arr = s.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
364.2765 +
364.2766 +                for (int i=0; i<arr.length; i++)
364.2767 +                    arr[i] = (T) checkedEntry((Map.Entry<K,V>)arr[i],
364.2768 +                                              valueType);
364.2769 +                if (arr.length > a.length)
364.2770 +                    return arr;
364.2771 +
364.2772 +                System.arraycopy(arr, 0, a, 0, arr.length);
364.2773 +                if (a.length > arr.length)
364.2774 +                    a[arr.length] = null;
364.2775 +                return a;
364.2776 +            }
364.2777 +
364.2778 +            /**
364.2779 +             * This method is overridden to protect the backing set against
364.2780 +             * an object with a nefarious equals function that senses
364.2781 +             * that the equality-candidate is Map.Entry and calls its
364.2782 +             * setValue method.
364.2783 +             */
364.2784 +            public boolean contains(Object o) {
364.2785 +                if (!(o instanceof Map.Entry))
364.2786 +                    return false;
364.2787 +                Map.Entry<?,?> e = (Map.Entry<?,?>) o;
364.2788 +                return s.contains(
364.2789 +                    (e instanceof CheckedEntry) ? e : checkedEntry(e, valueType));
364.2790 +            }
364.2791 +
364.2792 +            /**
364.2793 +             * The bulk collection methods are overridden to protect
364.2794 +             * against an unscrupulous collection whose contains(Object o)
364.2795 +             * method senses when o is a Map.Entry, and calls o.setValue.
364.2796 +             */
364.2797 +            public boolean containsAll(Collection<?> c) {
364.2798 +                for (Object o : c)
364.2799 +                    if (!contains(o)) // Invokes safe contains() above
364.2800 +                        return false;
364.2801 +                return true;
364.2802 +            }
364.2803 +
364.2804 +            public boolean remove(Object o) {
364.2805 +                if (!(o instanceof Map.Entry))
364.2806 +                    return false;
364.2807 +                return s.remove(new AbstractMap.SimpleImmutableEntry
364.2808 +                                <>((Map.Entry<?,?>)o));
364.2809 +            }
364.2810 +
364.2811 +            public boolean removeAll(Collection<?> c) {
364.2812 +                return batchRemove(c, false);
364.2813 +            }
364.2814 +            public boolean retainAll(Collection<?> c) {
364.2815 +                return batchRemove(c, true);
364.2816 +            }
364.2817 +            private boolean batchRemove(Collection<?> c, boolean complement) {
364.2818 +                boolean modified = false;
364.2819 +                Iterator<Map.Entry<K,V>> it = iterator();
364.2820 +                while (it.hasNext()) {
364.2821 +                    if (c.contains(it.next()) != complement) {
364.2822 +                        it.remove();
364.2823 +                        modified = true;
364.2824 +                    }
364.2825 +                }
364.2826 +                return modified;
364.2827 +            }
364.2828 +
364.2829 +            public boolean equals(Object o) {
364.2830 +                if (o == this)
364.2831 +                    return true;
364.2832 +                if (!(o instanceof Set))
364.2833 +                    return false;
364.2834 +                Set<?> that = (Set<?>) o;
364.2835 +                return that.size() == s.size()
364.2836 +                    && containsAll(that); // Invokes safe containsAll() above
364.2837 +            }
364.2838 +
364.2839 +            static <K,V,T> CheckedEntry<K,V,T> checkedEntry(Map.Entry<K,V> e,
364.2840 +                                                            Class<T> valueType) {
364.2841 +                return new CheckedEntry<>(e, valueType);
364.2842 +            }
364.2843 +
364.2844 +            /**
364.2845 +             * This "wrapper class" serves two purposes: it prevents
364.2846 +             * the client from modifying the backing Map, by short-circuiting
364.2847 +             * the setValue method, and it protects the backing Map against
364.2848 +             * an ill-behaved Map.Entry that attempts to modify another
364.2849 +             * Map.Entry when asked to perform an equality check.
364.2850 +             */
364.2851 +            private static class CheckedEntry<K,V,T> implements Map.Entry<K,V> {
364.2852 +                private final Map.Entry<K, V> e;
364.2853 +                private final Class<T> valueType;
364.2854 +
364.2855 +                CheckedEntry(Map.Entry<K, V> e, Class<T> valueType) {
364.2856 +                    this.e = e;
364.2857 +                    this.valueType = valueType;
364.2858 +                }
364.2859 +
364.2860 +                public K getKey()        { return e.getKey(); }
364.2861 +                public V getValue()      { return e.getValue(); }
364.2862 +                public int hashCode()    { return e.hashCode(); }
364.2863 +                public String toString() { return e.toString(); }
364.2864 +
364.2865 +                public V setValue(V value) {
364.2866 +                    if (value != null && !valueType.isInstance(value))
364.2867 +                        throw new ClassCastException(badValueMsg(value));
364.2868 +                    return e.setValue(value);
364.2869 +                }
364.2870 +
364.2871 +                private String badValueMsg(Object value) {
364.2872 +                    return "Attempt to insert " + value.getClass() +
364.2873 +                        " value into map with value type " + valueType;
364.2874 +                }
364.2875 +
364.2876 +                public boolean equals(Object o) {
364.2877 +                    if (o == this)
364.2878 +                        return true;
364.2879 +                    if (!(o instanceof Map.Entry))
364.2880 +                        return false;
364.2881 +                    return e.equals(new AbstractMap.SimpleImmutableEntry
364.2882 +                                    <>((Map.Entry<?,?>)o));
364.2883 +                }
364.2884 +            }
364.2885 +        }
364.2886 +    }
364.2887 +
364.2888 +    /**
364.2889 +     * Returns a dynamically typesafe view of the specified sorted map.
364.2890 +     * Any attempt to insert a mapping whose key or value have the wrong
364.2891 +     * type will result in an immediate {@link ClassCastException}.
364.2892 +     * Similarly, any attempt to modify the value currently associated with
364.2893 +     * a key will result in an immediate {@link ClassCastException},
364.2894 +     * whether the modification is attempted directly through the map
364.2895 +     * itself, or through a {@link Map.Entry} instance obtained from the
364.2896 +     * map's {@link Map#entrySet() entry set} view.
364.2897 +     *
364.2898 +     * <p>Assuming a map contains no incorrectly typed keys or values
364.2899 +     * prior to the time a dynamically typesafe view is generated, and
364.2900 +     * that all subsequent access to the map takes place through the view
364.2901 +     * (or one of its collection views), it is <i>guaranteed</i> that the
364.2902 +     * map cannot contain an incorrectly typed key or value.
364.2903 +     *
364.2904 +     * <p>A discussion of the use of dynamically typesafe views may be
364.2905 +     * found in the documentation for the {@link #checkedCollection
364.2906 +     * checkedCollection} method.
364.2907 +     *
364.2908 +     * <p>The returned map will be serializable if the specified map is
364.2909 +     * serializable.
364.2910 +     *
364.2911 +     * <p>Since {@code null} is considered to be a value of any reference
364.2912 +     * type, the returned map permits insertion of null keys or values
364.2913 +     * whenever the backing map does.
364.2914 +     *
364.2915 +     * @param m the map for which a dynamically typesafe view is to be
364.2916 +     *          returned
364.2917 +     * @param keyType the type of key that {@code m} is permitted to hold
364.2918 +     * @param valueType the type of value that {@code m} is permitted to hold
364.2919 +     * @return a dynamically typesafe view of the specified map
364.2920 +     * @since 1.5
364.2921 +     */
364.2922 +    public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K, V> m,
364.2923 +                                                        Class<K> keyType,
364.2924 +                                                        Class<V> valueType) {
364.2925 +        return new CheckedSortedMap<>(m, keyType, valueType);
364.2926 +    }
364.2927 +
364.2928 +    /**
364.2929 +     * @serial include
364.2930 +     */
364.2931 +    static class CheckedSortedMap<K,V> extends CheckedMap<K,V>
364.2932 +        implements SortedMap<K,V>, Serializable
364.2933 +    {
364.2934 +        private static final long serialVersionUID = 1599671320688067438L;
364.2935 +
364.2936 +        private final SortedMap<K, V> sm;
364.2937 +
364.2938 +        CheckedSortedMap(SortedMap<K, V> m,
364.2939 +                         Class<K> keyType, Class<V> valueType) {
364.2940 +            super(m, keyType, valueType);
364.2941 +            sm = m;
364.2942 +        }
364.2943 +
364.2944 +        public Comparator<? super K> comparator() { return sm.comparator(); }
364.2945 +        public K firstKey()                       { return sm.firstKey(); }
364.2946 +        public K lastKey()                        { return sm.lastKey(); }
364.2947 +
364.2948 +        public SortedMap<K,V> subMap(K fromKey, K toKey) {
364.2949 +            return checkedSortedMap(sm.subMap(fromKey, toKey),
364.2950 +                                    keyType, valueType);
364.2951 +        }
364.2952 +        public SortedMap<K,V> headMap(K toKey) {
364.2953 +            return checkedSortedMap(sm.headMap(toKey), keyType, valueType);
364.2954 +        }
364.2955 +        public SortedMap<K,V> tailMap(K fromKey) {
364.2956 +            return checkedSortedMap(sm.tailMap(fromKey), keyType, valueType);
364.2957 +        }
364.2958 +    }
364.2959 +
364.2960 +    // Empty collections
364.2961 +
364.2962 +    /**
364.2963 +     * Returns an iterator that has no elements.  More precisely,
364.2964 +     *
364.2965 +     * <ul compact>
364.2966 +     *
364.2967 +     * <li>{@link Iterator#hasNext hasNext} always returns {@code
364.2968 +     * false}.
364.2969 +     *
364.2970 +     * <li>{@link Iterator#next next} always throws {@link
364.2971 +     * NoSuchElementException}.
364.2972 +     *
364.2973 +     * <li>{@link Iterator#remove remove} always throws {@link
364.2974 +     * IllegalStateException}.
364.2975 +     *
364.2976 +     * </ul>
364.2977 +     *
364.2978 +     * <p>Implementations of this method are permitted, but not
364.2979 +     * required, to return the same object from multiple invocations.
364.2980 +     *
364.2981 +     * @return an empty iterator
364.2982 +     * @since 1.7
364.2983 +     */
364.2984 +    @SuppressWarnings("unchecked")
364.2985 +    public static <T> Iterator<T> emptyIterator() {
364.2986 +        return (Iterator<T>) EmptyIterator.EMPTY_ITERATOR;
364.2987 +    }
364.2988 +
364.2989 +    private static class EmptyIterator<E> implements Iterator<E> {
364.2990 +        static final EmptyIterator<Object> EMPTY_ITERATOR
364.2991 +            = new EmptyIterator<>();
364.2992 +
364.2993 +        public boolean hasNext() { return false; }
364.2994 +        public E next() { throw new NoSuchElementException(); }
364.2995 +        public void remove() { throw new IllegalStateException(); }
364.2996 +    }
364.2997 +
364.2998 +    /**
364.2999 +     * Returns a list iterator that has no elements.  More precisely,
364.3000 +     *
364.3001 +     * <ul compact>
364.3002 +     *
364.3003 +     * <li>{@link Iterator#hasNext hasNext} and {@link
364.3004 +     * ListIterator#hasPrevious hasPrevious} always return {@code
364.3005 +     * false}.
364.3006 +     *
364.3007 +     * <li>{@link Iterator#next next} and {@link ListIterator#previous
364.3008 +     * previous} always throw {@link NoSuchElementException}.
364.3009 +     *
364.3010 +     * <li>{@link Iterator#remove remove} and {@link ListIterator#set
364.3011 +     * set} always throw {@link IllegalStateException}.
364.3012 +     *
364.3013 +     * <li>{@link ListIterator#add add} always throws {@link
364.3014 +     * UnsupportedOperationException}.
364.3015 +     *
364.3016 +     * <li>{@link ListIterator#nextIndex nextIndex} always returns
364.3017 +     * {@code 0} .
364.3018 +     *
364.3019 +     * <li>{@link ListIterator#previousIndex previousIndex} always
364.3020 +     * returns {@code -1}.
364.3021 +     *
364.3022 +     * </ul>
364.3023 +     *
364.3024 +     * <p>Implementations of this method are permitted, but not
364.3025 +     * required, to return the same object from multiple invocations.
364.3026 +     *
364.3027 +     * @return an empty list iterator
364.3028 +     * @since 1.7
364.3029 +     */
364.3030 +    @SuppressWarnings("unchecked")
364.3031 +    public static <T> ListIterator<T> emptyListIterator() {
364.3032 +        return (ListIterator<T>) EmptyListIterator.EMPTY_ITERATOR;
364.3033 +    }
364.3034 +
364.3035 +    private static class EmptyListIterator<E>
364.3036 +        extends EmptyIterator<E>
364.3037 +        implements ListIterator<E>
364.3038 +    {
364.3039 +        static final EmptyListIterator<Object> EMPTY_ITERATOR
364.3040 +            = new EmptyListIterator<>();
364.3041 +
364.3042 +        public boolean hasPrevious() { return false; }
364.3043 +        public E previous() { throw new NoSuchElementException(); }
364.3044 +        public int nextIndex()     { return 0; }
364.3045 +        public int previousIndex() { return -1; }
364.3046 +        public void set(E e) { throw new IllegalStateException(); }
364.3047 +        public void add(E e) { throw new UnsupportedOperationException(); }
364.3048 +    }
364.3049 +
364.3050 +    /**
364.3051 +     * Returns an enumeration that has no elements.  More precisely,
364.3052 +     *
364.3053 +     * <ul compact>
364.3054 +     *
364.3055 +     * <li>{@link Enumeration#hasMoreElements hasMoreElements} always
364.3056 +     * returns {@code false}.
364.3057 +     *
364.3058 +     * <li> {@link Enumeration#nextElement nextElement} always throws
364.3059 +     * {@link NoSuchElementException}.
364.3060 +     *
364.3061 +     * </ul>
364.3062 +     *
364.3063 +     * <p>Implementations of this method are permitted, but not
364.3064 +     * required, to return the same object from multiple invocations.
364.3065 +     *
364.3066 +     * @return an empty enumeration
364.3067 +     * @since 1.7
364.3068 +     */
364.3069 +    @SuppressWarnings("unchecked")
364.3070 +    public static <T> Enumeration<T> emptyEnumeration() {
364.3071 +        return (Enumeration<T>) EmptyEnumeration.EMPTY_ENUMERATION;
364.3072 +    }
364.3073 +
364.3074 +    private static class EmptyEnumeration<E> implements Enumeration<E> {
364.3075 +        static final EmptyEnumeration<Object> EMPTY_ENUMERATION
364.3076 +            = new EmptyEnumeration<>();
364.3077 +
364.3078 +        public boolean hasMoreElements() { return false; }
364.3079 +        public E nextElement() { throw new NoSuchElementException(); }
364.3080 +    }
364.3081 +
364.3082 +    /**
364.3083 +     * The empty set (immutable).  This set is serializable.
364.3084 +     *
364.3085 +     * @see #emptySet()
364.3086 +     */
364.3087 +    @SuppressWarnings("unchecked")
364.3088 +    public static final Set EMPTY_SET = new EmptySet<>();
364.3089 +
364.3090 +    /**
364.3091 +     * Returns the empty set (immutable).  This set is serializable.
364.3092 +     * Unlike the like-named field, this method is parameterized.
364.3093 +     *
364.3094 +     * <p>This example illustrates the type-safe way to obtain an empty set:
364.3095 +     * <pre>
364.3096 +     *     Set&lt;String&gt; s = Collections.emptySet();
364.3097 +     * </pre>
364.3098 +     * Implementation note:  Implementations of this method need not
364.3099 +     * create a separate <tt>Set</tt> object for each call.   Using this
364.3100 +     * method is likely to have comparable cost to using the like-named
364.3101 +     * field.  (Unlike this method, the field does not provide type safety.)
364.3102 +     *
364.3103 +     * @see #EMPTY_SET
364.3104 +     * @since 1.5
364.3105 +     */
364.3106 +    @SuppressWarnings("unchecked")
364.3107 +    public static final <T> Set<T> emptySet() {
364.3108 +        return (Set<T>) EMPTY_SET;
364.3109 +    }
364.3110 +
364.3111 +    /**
364.3112 +     * @serial include
364.3113 +     */
364.3114 +    private static class EmptySet<E>
364.3115 +        extends AbstractSet<E>
364.3116 +        implements Serializable
364.3117 +    {
364.3118 +        private static final long serialVersionUID = 1582296315990362920L;
364.3119 +
364.3120 +        public Iterator<E> iterator() { return emptyIterator(); }
364.3121 +
364.3122 +        public int size() {return 0;}
364.3123 +        public boolean isEmpty() {return true;}
364.3124 +
364.3125 +        public boolean contains(Object obj) {return false;}
364.3126 +        public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
364.3127 +
364.3128 +        public Object[] toArray() { return new Object[0]; }
364.3129 +
364.3130 +        public <T> T[] toArray(T[] a) {
364.3131 +            if (a.length > 0)
364.3132 +                a[0] = null;
364.3133 +            return a;
364.3134 +        }
364.3135 +
364.3136 +        // Preserves singleton property
364.3137 +        private Object readResolve() {
364.3138 +            return EMPTY_SET;
364.3139 +        }
364.3140 +    }
364.3141 +
364.3142 +    /**
364.3143 +     * The empty list (immutable).  This list is serializable.
364.3144 +     *
364.3145 +     * @see #emptyList()
364.3146 +     */
364.3147 +    @SuppressWarnings("unchecked")
364.3148 +    public static final List EMPTY_LIST = new EmptyList<>();
364.3149 +
364.3150 +    /**
364.3151 +     * Returns the empty list (immutable).  This list is serializable.
364.3152 +     *
364.3153 +     * <p>This example illustrates the type-safe way to obtain an empty list:
364.3154 +     * <pre>
364.3155 +     *     List&lt;String&gt; s = Collections.emptyList();
364.3156 +     * </pre>
364.3157 +     * Implementation note:  Implementations of this method need not
364.3158 +     * create a separate <tt>List</tt> object for each call.   Using this
364.3159 +     * method is likely to have comparable cost to using the like-named
364.3160 +     * field.  (Unlike this method, the field does not provide type safety.)
364.3161 +     *
364.3162 +     * @see #EMPTY_LIST
364.3163 +     * @since 1.5
364.3164 +     */
364.3165 +    @SuppressWarnings("unchecked")
364.3166 +    public static final <T> List<T> emptyList() {
364.3167 +        return (List<T>) EMPTY_LIST;
364.3168 +    }
364.3169 +
364.3170 +    /**
364.3171 +     * @serial include
364.3172 +     */
364.3173 +    private static class EmptyList<E>
364.3174 +        extends AbstractList<E>
364.3175 +        implements RandomAccess, Serializable {
364.3176 +        private static final long serialVersionUID = 8842843931221139166L;
364.3177 +
364.3178 +        public Iterator<E> iterator() {
364.3179 +            return emptyIterator();
364.3180 +        }
364.3181 +        public ListIterator<E> listIterator() {
364.3182 +            return emptyListIterator();
364.3183 +        }
364.3184 +
364.3185 +        public int size() {return 0;}
364.3186 +        public boolean isEmpty() {return true;}
364.3187 +
364.3188 +        public boolean contains(Object obj) {return false;}
364.3189 +        public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
364.3190 +
364.3191 +        public Object[] toArray() { return new Object[0]; }
364.3192 +
364.3193 +        public <T> T[] toArray(T[] a) {
364.3194 +            if (a.length > 0)
364.3195 +                a[0] = null;
364.3196 +            return a;
364.3197 +        }
364.3198 +
364.3199 +        public E get(int index) {
364.3200 +            throw new IndexOutOfBoundsException("Index: "+index);
364.3201 +        }
364.3202 +
364.3203 +        public boolean equals(Object o) {
364.3204 +            return (o instanceof List) && ((List<?>)o).isEmpty();
364.3205 +        }
364.3206 +
364.3207 +        public int hashCode() { return 1; }
364.3208 +
364.3209 +        // Preserves singleton property
364.3210 +        private Object readResolve() {
364.3211 +            return EMPTY_LIST;
364.3212 +        }
364.3213 +    }
364.3214 +
364.3215 +    /**
364.3216 +     * The empty map (immutable).  This map is serializable.
364.3217 +     *
364.3218 +     * @see #emptyMap()
364.3219 +     * @since 1.3
364.3220 +     */
364.3221 +    @SuppressWarnings("unchecked")
364.3222 +    public static final Map EMPTY_MAP = new EmptyMap<>();
364.3223 +
364.3224 +    /**
364.3225 +     * Returns the empty map (immutable).  This map is serializable.
364.3226 +     *
364.3227 +     * <p>This example illustrates the type-safe way to obtain an empty set:
364.3228 +     * <pre>
364.3229 +     *     Map&lt;String, Date&gt; s = Collections.emptyMap();
364.3230 +     * </pre>
364.3231 +     * Implementation note:  Implementations of this method need not
364.3232 +     * create a separate <tt>Map</tt> object for each call.   Using this
364.3233 +     * method is likely to have comparable cost to using the like-named
364.3234 +     * field.  (Unlike this method, the field does not provide type safety.)
364.3235 +     *
364.3236 +     * @see #EMPTY_MAP
364.3237 +     * @since 1.5
364.3238 +     */
364.3239 +    @SuppressWarnings("unchecked")
364.3240 +    public static final <K,V> Map<K,V> emptyMap() {
364.3241 +        return (Map<K,V>) EMPTY_MAP;
364.3242 +    }
364.3243 +
364.3244 +    /**
364.3245 +     * @serial include
364.3246 +     */
364.3247 +    private static class EmptyMap<K,V>
364.3248 +        extends AbstractMap<K,V>
364.3249 +        implements Serializable
364.3250 +    {
364.3251 +        private static final long serialVersionUID = 6428348081105594320L;
364.3252 +
364.3253 +        public int size()                          {return 0;}
364.3254 +        public boolean isEmpty()                   {return true;}
364.3255 +        public boolean containsKey(Object key)     {return false;}
364.3256 +        public boolean containsValue(Object value) {return false;}
364.3257 +        public V get(Object key)                   {return null;}
364.3258 +        public Set<K> keySet()                     {return emptySet();}
364.3259 +        public Collection<V> values()              {return emptySet();}
364.3260 +        public Set<Map.Entry<K,V>> entrySet()      {return emptySet();}
364.3261 +
364.3262 +        public boolean equals(Object o) {
364.3263 +            return (o instanceof Map) && ((Map<?,?>)o).isEmpty();
364.3264 +        }
364.3265 +
364.3266 +        public int hashCode()                      {return 0;}
364.3267 +
364.3268 +        // Preserves singleton property
364.3269 +        private Object readResolve() {
364.3270 +            return EMPTY_MAP;
364.3271 +        }
364.3272 +    }
364.3273 +
364.3274 +    // Singleton collections
364.3275 +
364.3276 +    /**
364.3277 +     * Returns an immutable set containing only the specified object.
364.3278 +     * The returned set is serializable.
364.3279 +     *
364.3280 +     * @param o the sole object to be stored in the returned set.
364.3281 +     * @return an immutable set containing only the specified object.
364.3282 +     */
364.3283 +    public static <T> Set<T> singleton(T o) {
364.3284 +        return new SingletonSet<>(o);
364.3285 +    }
364.3286 +
364.3287 +    static <E> Iterator<E> singletonIterator(final E e) {
364.3288 +        return new Iterator<E>() {
364.3289 +            private boolean hasNext = true;
364.3290 +            public boolean hasNext() {
364.3291 +                return hasNext;
364.3292 +            }
364.3293 +            public E next() {
364.3294 +                if (hasNext) {
364.3295 +                    hasNext = false;
364.3296 +                    return e;
364.3297 +                }
364.3298 +                throw new NoSuchElementException();
364.3299 +            }
364.3300 +            public void remove() {
364.3301 +                throw new UnsupportedOperationException();
364.3302 +            }
364.3303 +        };
364.3304 +    }
364.3305 +
364.3306 +    /**
364.3307 +     * @serial include
364.3308 +     */
364.3309 +    private static class SingletonSet<E>
364.3310 +        extends AbstractSet<E>
364.3311 +        implements Serializable
364.3312 +    {
364.3313 +        private static final long serialVersionUID = 3193687207550431679L;
364.3314 +
364.3315 +        private final E element;
364.3316 +
364.3317 +        SingletonSet(E e) {element = e;}
364.3318 +
364.3319 +        public Iterator<E> iterator() {
364.3320 +            return singletonIterator(element);
364.3321 +        }
364.3322 +
364.3323 +        public int size() {return 1;}
364.3324 +
364.3325 +        public boolean contains(Object o) {return eq(o, element);}
364.3326 +    }
364.3327 +
364.3328 +    /**
364.3329 +     * Returns an immutable list containing only the specified object.
364.3330 +     * The returned list is serializable.
364.3331 +     *
364.3332 +     * @param o the sole object to be stored in the returned list.
364.3333 +     * @return an immutable list containing only the specified object.
364.3334 +     * @since 1.3
364.3335 +     */
364.3336 +    public static <T> List<T> singletonList(T o) {
364.3337 +        return new SingletonList<>(o);
364.3338 +    }
364.3339 +
364.3340 +    /**
364.3341 +     * @serial include
364.3342 +     */
364.3343 +    private static class SingletonList<E>
364.3344 +        extends AbstractList<E>
364.3345 +        implements RandomAccess, Serializable {
364.3346 +
364.3347 +        private static final long serialVersionUID = 3093736618740652951L;
364.3348 +
364.3349 +        private final E element;
364.3350 +
364.3351 +        SingletonList(E obj)                {element = obj;}
364.3352 +
364.3353 +        public Iterator<E> iterator() {
364.3354 +            return singletonIterator(element);
364.3355 +        }
364.3356 +
364.3357 +        public int size()                   {return 1;}
364.3358 +
364.3359 +        public boolean contains(Object obj) {return eq(obj, element);}
364.3360 +
364.3361 +        public E get(int index) {
364.3362 +            if (index != 0)
364.3363 +              throw new IndexOutOfBoundsException("Index: "+index+", Size: 1");
364.3364 +            return element;
364.3365 +        }
364.3366 +    }
364.3367 +
364.3368 +    /**
364.3369 +     * Returns an immutable map, mapping only the specified key to the
364.3370 +     * specified value.  The returned map is serializable.
364.3371 +     *
364.3372 +     * @param key the sole key to be stored in the returned map.
364.3373 +     * @param value the value to which the returned map maps <tt>key</tt>.
364.3374 +     * @return an immutable map containing only the specified key-value
364.3375 +     *         mapping.
364.3376 +     * @since 1.3
364.3377 +     */
364.3378 +    public static <K,V> Map<K,V> singletonMap(K key, V value) {
364.3379 +        return new SingletonMap<>(key, value);
364.3380 +    }
364.3381 +
364.3382 +    /**
364.3383 +     * @serial include
364.3384 +     */
364.3385 +    private static class SingletonMap<K,V>
364.3386 +          extends AbstractMap<K,V>
364.3387 +          implements Serializable {
364.3388 +        private static final long serialVersionUID = -6979724477215052911L;
364.3389 +
364.3390 +        private final K k;
364.3391 +        private final V v;
364.3392 +
364.3393 +        SingletonMap(K key, V value) {
364.3394 +            k = key;
364.3395 +            v = value;
364.3396 +        }
364.3397 +
364.3398 +        public int size()                          {return 1;}
364.3399 +
364.3400 +        public boolean isEmpty()                   {return false;}
364.3401 +
364.3402 +        public boolean containsKey(Object key)     {return eq(key, k);}
364.3403 +
364.3404 +        public boolean containsValue(Object value) {return eq(value, v);}
364.3405 +
364.3406 +        public V get(Object key)                   {return (eq(key, k) ? v : null);}
364.3407 +
364.3408 +        private transient Set<K> keySet = null;
364.3409 +        private transient Set<Map.Entry<K,V>> entrySet = null;
364.3410 +        private transient Collection<V> values = null;
364.3411 +
364.3412 +        public Set<K> keySet() {
364.3413 +            if (keySet==null)
364.3414 +                keySet = singleton(k);
364.3415 +            return keySet;
364.3416 +        }
364.3417 +
364.3418 +        public Set<Map.Entry<K,V>> entrySet() {
364.3419 +            if (entrySet==null)
364.3420 +                entrySet = Collections.<Map.Entry<K,V>>singleton(
364.3421 +                    new SimpleImmutableEntry<>(k, v));
364.3422 +            return entrySet;
364.3423 +        }
364.3424 +
364.3425 +        public Collection<V> values() {
364.3426 +            if (values==null)
364.3427 +                values = singleton(v);
364.3428 +            return values;
364.3429 +        }
364.3430 +
364.3431 +    }
364.3432 +
364.3433 +    // Miscellaneous
364.3434 +
364.3435 +    /**
364.3436 +     * Returns an immutable list consisting of <tt>n</tt> copies of the
364.3437 +     * specified object.  The newly allocated data object is tiny (it contains
364.3438 +     * a single reference to the data object).  This method is useful in
364.3439 +     * combination with the <tt>List.addAll</tt> method to grow lists.
364.3440 +     * The returned list is serializable.
364.3441 +     *
364.3442 +     * @param  n the number of elements in the returned list.
364.3443 +     * @param  o the element to appear repeatedly in the returned list.
364.3444 +     * @return an immutable list consisting of <tt>n</tt> copies of the
364.3445 +     *         specified object.
364.3446 +     * @throws IllegalArgumentException if {@code n < 0}
364.3447 +     * @see    List#addAll(Collection)
364.3448 +     * @see    List#addAll(int, Collection)
364.3449 +     */
364.3450 +    public static <T> List<T> nCopies(int n, T o) {
364.3451 +        if (n < 0)
364.3452 +            throw new IllegalArgumentException("List length = " + n);
364.3453 +        return new CopiesList<>(n, o);
364.3454 +    }
364.3455 +
364.3456 +    /**
364.3457 +     * @serial include
364.3458 +     */
364.3459 +    private static class CopiesList<E>
364.3460 +        extends AbstractList<E>
364.3461 +        implements RandomAccess, Serializable
364.3462 +    {
364.3463 +        private static final long serialVersionUID = 2739099268398711800L;
364.3464 +
364.3465 +        final int n;
364.3466 +        final E element;
364.3467 +
364.3468 +        CopiesList(int n, E e) {
364.3469 +            assert n >= 0;
364.3470 +            this.n = n;
364.3471 +            element = e;
364.3472 +        }
364.3473 +
364.3474 +        public int size() {
364.3475 +            return n;
364.3476 +        }
364.3477 +
364.3478 +        public boolean contains(Object obj) {
364.3479 +            return n != 0 && eq(obj, element);
364.3480 +        }
364.3481 +
364.3482 +        public int indexOf(Object o) {
364.3483 +            return contains(o) ? 0 : -1;
364.3484 +        }
364.3485 +
364.3486 +        public int lastIndexOf(Object o) {
364.3487 +            return contains(o) ? n - 1 : -1;
364.3488 +        }
364.3489 +
364.3490 +        public E get(int index) {
364.3491 +            if (index < 0 || index >= n)
364.3492 +                throw new IndexOutOfBoundsException("Index: "+index+
364.3493 +                                                    ", Size: "+n);
364.3494 +            return element;
364.3495 +        }
364.3496 +
364.3497 +        public Object[] toArray() {
364.3498 +            final Object[] a = new Object[n];
364.3499 +            if (element != null)
364.3500 +                Arrays.fill(a, 0, n, element);
364.3501 +            return a;
364.3502 +        }
364.3503 +
364.3504 +        public <T> T[] toArray(T[] a) {
364.3505 +            final int n = this.n;
364.3506 +            if (a.length < n) {
364.3507 +                a = (T[])java.lang.reflect.Array
364.3508 +                    .newInstance(a.getClass().getComponentType(), n);
364.3509 +                if (element != null)
364.3510 +                    Arrays.fill(a, 0, n, element);
364.3511 +            } else {
364.3512 +                Arrays.fill(a, 0, n, element);
364.3513 +                if (a.length > n)
364.3514 +                    a[n] = null;
364.3515 +            }
364.3516 +            return a;
364.3517 +        }
364.3518 +
364.3519 +        public List<E> subList(int fromIndex, int toIndex) {
364.3520 +            if (fromIndex < 0)
364.3521 +                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
364.3522 +            if (toIndex > n)
364.3523 +                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
364.3524 +            if (fromIndex > toIndex)
364.3525 +                throw new IllegalArgumentException("fromIndex(" + fromIndex +
364.3526 +                                                   ") > toIndex(" + toIndex + ")");
364.3527 +            return new CopiesList<>(toIndex - fromIndex, element);
364.3528 +        }
364.3529 +    }
364.3530 +
364.3531 +    /**
364.3532 +     * Returns a comparator that imposes the reverse of the <em>natural
364.3533 +     * ordering</em> on a collection of objects that implement the
364.3534 +     * {@code Comparable} interface.  (The natural ordering is the ordering
364.3535 +     * imposed by the objects' own {@code compareTo} method.)  This enables a
364.3536 +     * simple idiom for sorting (or maintaining) collections (or arrays) of
364.3537 +     * objects that implement the {@code Comparable} interface in
364.3538 +     * reverse-natural-order.  For example, suppose {@code a} is an array of
364.3539 +     * strings. Then: <pre>
364.3540 +     *          Arrays.sort(a, Collections.reverseOrder());
364.3541 +     * </pre> sorts the array in reverse-lexicographic (alphabetical) order.<p>
364.3542 +     *
364.3543 +     * The returned comparator is serializable.
364.3544 +     *
364.3545 +     * @return A comparator that imposes the reverse of the <i>natural
364.3546 +     *         ordering</i> on a collection of objects that implement
364.3547 +     *         the <tt>Comparable</tt> interface.
364.3548 +     * @see Comparable
364.3549 +     */
364.3550 +    public static <T> Comparator<T> reverseOrder() {
364.3551 +        return (Comparator<T>) ReverseComparator.REVERSE_ORDER;
364.3552 +    }
364.3553 +
364.3554 +    /**
364.3555 +     * @serial include
364.3556 +     */
364.3557 +    private static class ReverseComparator
364.3558 +        implements Comparator<Comparable<Object>>, Serializable {
364.3559 +
364.3560 +        private static final long serialVersionUID = 7207038068494060240L;
364.3561 +
364.3562 +        static final ReverseComparator REVERSE_ORDER
364.3563 +            = new ReverseComparator();
364.3564 +
364.3565 +        public int compare(Comparable<Object> c1, Comparable<Object> c2) {
364.3566 +            return c2.compareTo(c1);
364.3567 +        }
364.3568 +
364.3569 +        private Object readResolve() { return reverseOrder(); }
364.3570 +    }
364.3571 +
364.3572 +    /**
364.3573 +     * Returns a comparator that imposes the reverse ordering of the specified
364.3574 +     * comparator.  If the specified comparator is {@code null}, this method is
364.3575 +     * equivalent to {@link #reverseOrder()} (in other words, it returns a
364.3576 +     * comparator that imposes the reverse of the <em>natural ordering</em> on
364.3577 +     * a collection of objects that implement the Comparable interface).
364.3578 +     *
364.3579 +     * <p>The returned comparator is serializable (assuming the specified
364.3580 +     * comparator is also serializable or {@code null}).
364.3581 +     *
364.3582 +     * @param cmp a comparator who's ordering is to be reversed by the returned
364.3583 +     * comparator or {@code null}
364.3584 +     * @return A comparator that imposes the reverse ordering of the
364.3585 +     *         specified comparator.
364.3586 +     * @since 1.5
364.3587 +     */
364.3588 +    public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
364.3589 +        if (cmp == null)
364.3590 +            return reverseOrder();
364.3591 +
364.3592 +        if (cmp instanceof ReverseComparator2)
364.3593 +            return ((ReverseComparator2<T>)cmp).cmp;
364.3594 +
364.3595 +        return new ReverseComparator2<>(cmp);
364.3596 +    }
364.3597 +
364.3598 +    /**
364.3599 +     * @serial include
364.3600 +     */
364.3601 +    private static class ReverseComparator2<T> implements Comparator<T>,
364.3602 +        Serializable
364.3603 +    {
364.3604 +        private static final long serialVersionUID = 4374092139857L;
364.3605 +
364.3606 +        /**
364.3607 +         * The comparator specified in the static factory.  This will never
364.3608 +         * be null, as the static factory returns a ReverseComparator
364.3609 +         * instance if its argument is null.
364.3610 +         *
364.3611 +         * @serial
364.3612 +         */
364.3613 +        final Comparator<T> cmp;
364.3614 +
364.3615 +        ReverseComparator2(Comparator<T> cmp) {
364.3616 +            assert cmp != null;
364.3617 +            this.cmp = cmp;
364.3618 +        }
364.3619 +
364.3620 +        public int compare(T t1, T t2) {
364.3621 +            return cmp.compare(t2, t1);
364.3622 +        }
364.3623 +
364.3624 +        public boolean equals(Object o) {
364.3625 +            return (o == this) ||
364.3626 +                (o instanceof ReverseComparator2 &&
364.3627 +                 cmp.equals(((ReverseComparator2)o).cmp));
364.3628 +        }
364.3629 +
364.3630 +        public int hashCode() {
364.3631 +            return cmp.hashCode() ^ Integer.MIN_VALUE;
364.3632 +        }
364.3633 +    }
364.3634 +
364.3635 +    /**
364.3636 +     * Returns an enumeration over the specified collection.  This provides
364.3637 +     * interoperability with legacy APIs that require an enumeration
364.3638 +     * as input.
364.3639 +     *
364.3640 +     * @param c the collection for which an enumeration is to be returned.
364.3641 +     * @return an enumeration over the specified collection.
364.3642 +     * @see Enumeration
364.3643 +     */
364.3644 +    public static <T> Enumeration<T> enumeration(final Collection<T> c) {
364.3645 +        return new Enumeration<T>() {
364.3646 +            private final Iterator<T> i = c.iterator();
364.3647 +
364.3648 +            public boolean hasMoreElements() {
364.3649 +                return i.hasNext();
364.3650 +            }
364.3651 +
364.3652 +            public T nextElement() {
364.3653 +                return i.next();
364.3654 +            }
364.3655 +        };
364.3656 +    }
364.3657 +
364.3658 +    /**
364.3659 +     * Returns an array list containing the elements returned by the
364.3660 +     * specified enumeration in the order they are returned by the
364.3661 +     * enumeration.  This method provides interoperability between
364.3662 +     * legacy APIs that return enumerations and new APIs that require
364.3663 +     * collections.
364.3664 +     *
364.3665 +     * @param e enumeration providing elements for the returned
364.3666 +     *          array list
364.3667 +     * @return an array list containing the elements returned
364.3668 +     *         by the specified enumeration.
364.3669 +     * @since 1.4
364.3670 +     * @see Enumeration
364.3671 +     * @see ArrayList
364.3672 +     */
364.3673 +    public static <T> ArrayList<T> list(Enumeration<T> e) {
364.3674 +        ArrayList<T> l = new ArrayList<>();
364.3675 +        while (e.hasMoreElements())
364.3676 +            l.add(e.nextElement());
364.3677 +        return l;
364.3678 +    }
364.3679 +
364.3680 +    /**
364.3681 +     * Returns true if the specified arguments are equal, or both null.
364.3682 +     */
364.3683 +    static boolean eq(Object o1, Object o2) {
364.3684 +        return o1==null ? o2==null : o1.equals(o2);
364.3685 +    }
364.3686 +
364.3687 +    /**
364.3688 +     * Returns the number of elements in the specified collection equal to the
364.3689 +     * specified object.  More formally, returns the number of elements
364.3690 +     * <tt>e</tt> in the collection such that
364.3691 +     * <tt>(o == null ? e == null : o.equals(e))</tt>.
364.3692 +     *
364.3693 +     * @param c the collection in which to determine the frequency
364.3694 +     *     of <tt>o</tt>
364.3695 +     * @param o the object whose frequency is to be determined
364.3696 +     * @throws NullPointerException if <tt>c</tt> is null
364.3697 +     * @since 1.5
364.3698 +     */
364.3699 +    public static int frequency(Collection<?> c, Object o) {
364.3700 +        int result = 0;
364.3701 +        if (o == null) {
364.3702 +            for (Object e : c)
364.3703 +                if (e == null)
364.3704 +                    result++;
364.3705 +        } else {
364.3706 +            for (Object e : c)
364.3707 +                if (o.equals(e))
364.3708 +                    result++;
364.3709 +        }
364.3710 +        return result;
364.3711 +    }
364.3712 +
364.3713 +    /**
364.3714 +     * Returns {@code true} if the two specified collections have no
364.3715 +     * elements in common.
364.3716 +     *
364.3717 +     * <p>Care must be exercised if this method is used on collections that
364.3718 +     * do not comply with the general contract for {@code Collection}.
364.3719 +     * Implementations may elect to iterate over either collection and test
364.3720 +     * for containment in the other collection (or to perform any equivalent
364.3721 +     * computation).  If either collection uses a nonstandard equality test
364.3722 +     * (as does a {@link SortedSet} whose ordering is not <em>compatible with
364.3723 +     * equals</em>, or the key set of an {@link IdentityHashMap}), both
364.3724 +     * collections must use the same nonstandard equality test, or the
364.3725 +     * result of this method is undefined.
364.3726 +     *
364.3727 +     * <p>Care must also be exercised when using collections that have
364.3728 +     * restrictions on the elements that they may contain. Collection
364.3729 +     * implementations are allowed to throw exceptions for any operation
364.3730 +     * involving elements they deem ineligible. For absolute safety the
364.3731 +     * specified collections should contain only elements which are
364.3732 +     * eligible elements for both collections.
364.3733 +     *
364.3734 +     * <p>Note that it is permissible to pass the same collection in both
364.3735 +     * parameters, in which case the method will return {@code true} if and
364.3736 +     * only if the collection is empty.
364.3737 +     *
364.3738 +     * @param c1 a collection
364.3739 +     * @param c2 a collection
364.3740 +     * @return {@code true} if the two specified collections have no
364.3741 +     * elements in common.
364.3742 +     * @throws NullPointerException if either collection is {@code null}.
364.3743 +     * @throws NullPointerException if one collection contains a {@code null}
364.3744 +     * element and {@code null} is not an eligible element for the other collection.
364.3745 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
364.3746 +     * @throws ClassCastException if one collection contains an element that is
364.3747 +     * of a type which is ineligible for the other collection.
364.3748 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
364.3749 +     * @since 1.5
364.3750 +     */
364.3751 +    public static boolean disjoint(Collection<?> c1, Collection<?> c2) {
364.3752 +        // The collection to be used for contains(). Preference is given to
364.3753 +        // the collection who's contains() has lower O() complexity.
364.3754 +        Collection<?> contains = c2;
364.3755 +        // The collection to be iterated. If the collections' contains() impl
364.3756 +        // are of different O() complexity, the collection with slower
364.3757 +        // contains() will be used for iteration. For collections who's
364.3758 +        // contains() are of the same complexity then best performance is
364.3759 +        // achieved by iterating the smaller collection.
364.3760 +        Collection<?> iterate = c1;
364.3761 +
364.3762 +        // Performance optimization cases. The heuristics:
364.3763 +        //   1. Generally iterate over c1.
364.3764 +        //   2. If c1 is a Set then iterate over c2.
364.3765 +        //   3. If either collection is empty then result is always true.
364.3766 +        //   4. Iterate over the smaller Collection.
364.3767 +        if (c1 instanceof Set) {
364.3768 +            // Use c1 for contains as a Set's contains() is expected to perform
364.3769 +            // better than O(N/2)
364.3770 +            iterate = c2;
364.3771 +            contains = c1;
364.3772 +        } else if (!(c2 instanceof Set)) {
364.3773 +            // Both are mere Collections. Iterate over smaller collection.
364.3774 +            // Example: If c1 contains 3 elements and c2 contains 50 elements and
364.3775 +            // assuming contains() requires ceiling(N/2) comparisons then
364.3776 +            // checking for all c1 elements in c2 would require 75 comparisons
364.3777 +            // (3 * ceiling(50/2)) vs. checking all c2 elements in c1 requiring
364.3778 +            // 100 comparisons (50 * ceiling(3/2)).
364.3779 +            int c1size = c1.size();
364.3780 +            int c2size = c2.size();
364.3781 +            if (c1size == 0 || c2size == 0) {
364.3782 +                // At least one collection is empty. Nothing will match.
364.3783 +                return true;
364.3784 +            }
364.3785 +
364.3786 +            if (c1size > c2size) {
364.3787 +                iterate = c2;
364.3788 +                contains = c1;
364.3789 +            }
364.3790 +        }
364.3791 +
364.3792 +        for (Object e : iterate) {
364.3793 +            if (contains.contains(e)) {
364.3794 +               // Found a common element. Collections are not disjoint.
364.3795 +                return false;
364.3796 +            }
364.3797 +        }
364.3798 +
364.3799 +        // No common elements were found.
364.3800 +        return true;
364.3801 +    }
364.3802 +
364.3803 +    /**
364.3804 +     * Adds all of the specified elements to the specified collection.
364.3805 +     * Elements to be added may be specified individually or as an array.
364.3806 +     * The behavior of this convenience method is identical to that of
364.3807 +     * <tt>c.addAll(Arrays.asList(elements))</tt>, but this method is likely
364.3808 +     * to run significantly faster under most implementations.
364.3809 +     *
364.3810 +     * <p>When elements are specified individually, this method provides a
364.3811 +     * convenient way to add a few elements to an existing collection:
364.3812 +     * <pre>
364.3813 +     *     Collections.addAll(flavors, "Peaches 'n Plutonium", "Rocky Racoon");
364.3814 +     * </pre>
364.3815 +     *
364.3816 +     * @param c the collection into which <tt>elements</tt> are to be inserted
364.3817 +     * @param elements the elements to insert into <tt>c</tt>
364.3818 +     * @return <tt>true</tt> if the collection changed as a result of the call
364.3819 +     * @throws UnsupportedOperationException if <tt>c</tt> does not support
364.3820 +     *         the <tt>add</tt> operation
364.3821 +     * @throws NullPointerException if <tt>elements</tt> contains one or more
364.3822 +     *         null values and <tt>c</tt> does not permit null elements, or
364.3823 +     *         if <tt>c</tt> or <tt>elements</tt> are <tt>null</tt>
364.3824 +     * @throws IllegalArgumentException if some property of a value in
364.3825 +     *         <tt>elements</tt> prevents it from being added to <tt>c</tt>
364.3826 +     * @see Collection#addAll(Collection)
364.3827 +     * @since 1.5
364.3828 +     */
364.3829 +    @SafeVarargs
364.3830 +    public static <T> boolean addAll(Collection<? super T> c, T... elements) {
364.3831 +        boolean result = false;
364.3832 +        for (T element : elements)
364.3833 +            result |= c.add(element);
364.3834 +        return result;
364.3835 +    }
364.3836 +
364.3837 +    /**
364.3838 +     * Returns a set backed by the specified map.  The resulting set displays
364.3839 +     * the same ordering, concurrency, and performance characteristics as the
364.3840 +     * backing map.  In essence, this factory method provides a {@link Set}
364.3841 +     * implementation corresponding to any {@link Map} implementation.  There
364.3842 +     * is no need to use this method on a {@link Map} implementation that
364.3843 +     * already has a corresponding {@link Set} implementation (such as {@link
364.3844 +     * HashMap} or {@link TreeMap}).
364.3845 +     *
364.3846 +     * <p>Each method invocation on the set returned by this method results in
364.3847 +     * exactly one method invocation on the backing map or its <tt>keySet</tt>
364.3848 +     * view, with one exception.  The <tt>addAll</tt> method is implemented
364.3849 +     * as a sequence of <tt>put</tt> invocations on the backing map.
364.3850 +     *
364.3851 +     * <p>The specified map must be empty at the time this method is invoked,
364.3852 +     * and should not be accessed directly after this method returns.  These
364.3853 +     * conditions are ensured if the map is created empty, passed directly
364.3854 +     * to this method, and no reference to the map is retained, as illustrated
364.3855 +     * in the following code fragment:
364.3856 +     * <pre>
364.3857 +     *    Set&lt;Object&gt; weakHashSet = Collections.newSetFromMap(
364.3858 +     *        new WeakHashMap&lt;Object, Boolean&gt;());
364.3859 +     * </pre>
364.3860 +     *
364.3861 +     * @param map the backing map
364.3862 +     * @return the set backed by the map
364.3863 +     * @throws IllegalArgumentException if <tt>map</tt> is not empty
364.3864 +     * @since 1.6
364.3865 +     */
364.3866 +    public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) {
364.3867 +        return new SetFromMap<>(map);
364.3868 +    }
364.3869 +
364.3870 +    /**
364.3871 +     * @serial include
364.3872 +     */
364.3873 +    private static class SetFromMap<E> extends AbstractSet<E>
364.3874 +        implements Set<E>, Serializable
364.3875 +    {
364.3876 +        private final Map<E, Boolean> m;  // The backing map
364.3877 +        private transient Set<E> s;       // Its keySet
364.3878 +
364.3879 +        SetFromMap(Map<E, Boolean> map) {
364.3880 +            if (!map.isEmpty())
364.3881 +                throw new IllegalArgumentException("Map is non-empty");
364.3882 +            m = map;
364.3883 +            s = map.keySet();
364.3884 +        }
364.3885 +
364.3886 +        public void clear()               {        m.clear(); }
364.3887 +        public int size()                 { return m.size(); }
364.3888 +        public boolean isEmpty()          { return m.isEmpty(); }
364.3889 +        public boolean contains(Object o) { return m.containsKey(o); }
364.3890 +        public boolean remove(Object o)   { return m.remove(o) != null; }
364.3891 +        public boolean add(E e) { return m.put(e, Boolean.TRUE) == null; }
364.3892 +        public Iterator<E> iterator()     { return s.iterator(); }
364.3893 +        public Object[] toArray()         { return s.toArray(); }
364.3894 +        public <T> T[] toArray(T[] a)     { return s.toArray(a); }
364.3895 +        public String toString()          { return s.toString(); }
364.3896 +        public int hashCode()             { return s.hashCode(); }
364.3897 +        public boolean equals(Object o)   { return o == this || s.equals(o); }
364.3898 +        public boolean containsAll(Collection<?> c) {return s.containsAll(c);}
364.3899 +        public boolean removeAll(Collection<?> c)   {return s.removeAll(c);}
364.3900 +        public boolean retainAll(Collection<?> c)   {return s.retainAll(c);}
364.3901 +        // addAll is the only inherited implementation
364.3902 +
364.3903 +        private static final long serialVersionUID = 2454657854757543876L;
364.3904 +
364.3905 +    }
364.3906 +
364.3907 +    /**
364.3908 +     * Returns a view of a {@link Deque} as a Last-in-first-out (Lifo)
364.3909 +     * {@link Queue}. Method <tt>add</tt> is mapped to <tt>push</tt>,
364.3910 +     * <tt>remove</tt> is mapped to <tt>pop</tt> and so on. This
364.3911 +     * view can be useful when you would like to use a method
364.3912 +     * requiring a <tt>Queue</tt> but you need Lifo ordering.
364.3913 +     *
364.3914 +     * <p>Each method invocation on the queue returned by this method
364.3915 +     * results in exactly one method invocation on the backing deque, with
364.3916 +     * one exception.  The {@link Queue#addAll addAll} method is
364.3917 +     * implemented as a sequence of {@link Deque#addFirst addFirst}
364.3918 +     * invocations on the backing deque.
364.3919 +     *
364.3920 +     * @param deque the deque
364.3921 +     * @return the queue
364.3922 +     * @since  1.6
364.3923 +     */
364.3924 +    public static <T> Queue<T> asLifoQueue(Deque<T> deque) {
364.3925 +        return new AsLIFOQueue<>(deque);
364.3926 +    }
364.3927 +
364.3928 +    /**
364.3929 +     * @serial include
364.3930 +     */
364.3931 +    static class AsLIFOQueue<E> extends AbstractQueue<E>
364.3932 +        implements Queue<E>, Serializable {
364.3933 +        private static final long serialVersionUID = 1802017725587941708L;
364.3934 +        private final Deque<E> q;
364.3935 +        AsLIFOQueue(Deque<E> q)           { this.q = q; }
364.3936 +        public boolean add(E e)           { q.addFirst(e); return true; }
364.3937 +        public boolean offer(E e)         { return q.offerFirst(e); }
364.3938 +        public E poll()                   { return q.pollFirst(); }
364.3939 +        public E remove()                 { return q.removeFirst(); }
364.3940 +        public E peek()                   { return q.peekFirst(); }
364.3941 +        public E element()                { return q.getFirst(); }
364.3942 +        public void clear()               {        q.clear(); }
364.3943 +        public int size()                 { return q.size(); }
364.3944 +        public boolean isEmpty()          { return q.isEmpty(); }
364.3945 +        public boolean contains(Object o) { return q.contains(o); }
364.3946 +        public boolean remove(Object o)   { return q.remove(o); }
364.3947 +        public Iterator<E> iterator()     { return q.iterator(); }
364.3948 +        public Object[] toArray()         { return q.toArray(); }
364.3949 +        public <T> T[] toArray(T[] a)     { return q.toArray(a); }
364.3950 +        public String toString()          { return q.toString(); }
364.3951 +        public boolean containsAll(Collection<?> c) {return q.containsAll(c);}
364.3952 +        public boolean removeAll(Collection<?> c)   {return q.removeAll(c);}
364.3953 +        public boolean retainAll(Collection<?> c)   {return q.retainAll(c);}
364.3954 +        // We use inherited addAll; forwarding addAll would be wrong
364.3955 +    }
364.3956 +}
   365.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   365.2 +++ b/rt/emul/compact/src/main/java/java/util/ComparableTimSort.java	Wed Feb 27 11:24:58 2013 +0100
   365.3 @@ -0,0 +1,896 @@
   365.4 +/*
   365.5 + * Copyright 2009 Google Inc.  All Rights Reserved.
   365.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   365.7 + *
   365.8 + * This code is free software; you can redistribute it and/or modify it
   365.9 + * under the terms of the GNU General Public License version 2 only, as
  365.10 + * published by the Free Software Foundation.  Oracle designates this
  365.11 + * particular file as subject to the "Classpath" exception as provided
  365.12 + * by Oracle in the LICENSE file that accompanied this code.
  365.13 + *
  365.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  365.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  365.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  365.17 + * version 2 for more details (a copy is included in the LICENSE file that
  365.18 + * accompanied this code).
  365.19 + *
  365.20 + * You should have received a copy of the GNU General Public License version
  365.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  365.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  365.23 + *
  365.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  365.25 + * or visit www.oracle.com if you need additional information or have any
  365.26 + * questions.
  365.27 + */
  365.28 +
  365.29 +package java.util;
  365.30 +
  365.31 +
  365.32 +/**
  365.33 + * This is a near duplicate of {@link TimSort}, modified for use with
  365.34 + * arrays of objects that implement {@link Comparable}, instead of using
  365.35 + * explicit comparators.
  365.36 + *
  365.37 + * <p>If you are using an optimizing VM, you may find that ComparableTimSort
  365.38 + * offers no performance benefit over TimSort in conjunction with a
  365.39 + * comparator that simply returns {@code ((Comparable)first).compareTo(Second)}.
  365.40 + * If this is the case, you are better off deleting ComparableTimSort to
  365.41 + * eliminate the code duplication.  (See Arrays.java for details.)
  365.42 + *
  365.43 + * @author Josh Bloch
  365.44 + */
  365.45 +class ComparableTimSort {
  365.46 +    /**
  365.47 +     * This is the minimum sized sequence that will be merged.  Shorter
  365.48 +     * sequences will be lengthened by calling binarySort.  If the entire
  365.49 +     * array is less than this length, no merges will be performed.
  365.50 +     *
  365.51 +     * This constant should be a power of two.  It was 64 in Tim Peter's C
  365.52 +     * implementation, but 32 was empirically determined to work better in
  365.53 +     * this implementation.  In the unlikely event that you set this constant
  365.54 +     * to be a number that's not a power of two, you'll need to change the
  365.55 +     * {@link #minRunLength} computation.
  365.56 +     *
  365.57 +     * If you decrease this constant, you must change the stackLen
  365.58 +     * computation in the TimSort constructor, or you risk an
  365.59 +     * ArrayOutOfBounds exception.  See listsort.txt for a discussion
  365.60 +     * of the minimum stack length required as a function of the length
  365.61 +     * of the array being sorted and the minimum merge sequence length.
  365.62 +     */
  365.63 +    private static final int MIN_MERGE = 32;
  365.64 +
  365.65 +    /**
  365.66 +     * The array being sorted.
  365.67 +     */
  365.68 +    private final Object[] a;
  365.69 +
  365.70 +    /**
  365.71 +     * When we get into galloping mode, we stay there until both runs win less
  365.72 +     * often than MIN_GALLOP consecutive times.
  365.73 +     */
  365.74 +    private static final int  MIN_GALLOP = 7;
  365.75 +
  365.76 +    /**
  365.77 +     * This controls when we get *into* galloping mode.  It is initialized
  365.78 +     * to MIN_GALLOP.  The mergeLo and mergeHi methods nudge it higher for
  365.79 +     * random data, and lower for highly structured data.
  365.80 +     */
  365.81 +    private int minGallop = MIN_GALLOP;
  365.82 +
  365.83 +    /**
  365.84 +     * Maximum initial size of tmp array, which is used for merging.  The array
  365.85 +     * can grow to accommodate demand.
  365.86 +     *
  365.87 +     * Unlike Tim's original C version, we do not allocate this much storage
  365.88 +     * when sorting smaller arrays.  This change was required for performance.
  365.89 +     */
  365.90 +    private static final int INITIAL_TMP_STORAGE_LENGTH = 256;
  365.91 +
  365.92 +    /**
  365.93 +     * Temp storage for merges.
  365.94 +     */
  365.95 +    private Object[] tmp;
  365.96 +
  365.97 +    /**
  365.98 +     * A stack of pending runs yet to be merged.  Run i starts at
  365.99 +     * address base[i] and extends for len[i] elements.  It's always
 365.100 +     * true (so long as the indices are in bounds) that:
 365.101 +     *
 365.102 +     *     runBase[i] + runLen[i] == runBase[i + 1]
 365.103 +     *
 365.104 +     * so we could cut the storage for this, but it's a minor amount,
 365.105 +     * and keeping all the info explicit simplifies the code.
 365.106 +     */
 365.107 +    private int stackSize = 0;  // Number of pending runs on stack
 365.108 +    private final int[] runBase;
 365.109 +    private final int[] runLen;
 365.110 +
 365.111 +    /**
 365.112 +     * Creates a TimSort instance to maintain the state of an ongoing sort.
 365.113 +     *
 365.114 +     * @param a the array to be sorted
 365.115 +     */
 365.116 +    private ComparableTimSort(Object[] a) {
 365.117 +        this.a = a;
 365.118 +
 365.119 +        // Allocate temp storage (which may be increased later if necessary)
 365.120 +        int len = a.length;
 365.121 +        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
 365.122 +        Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
 365.123 +                                       len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
 365.124 +        tmp = newArray;
 365.125 +
 365.126 +        /*
 365.127 +         * Allocate runs-to-be-merged stack (which cannot be expanded).  The
 365.128 +         * stack length requirements are described in listsort.txt.  The C
 365.129 +         * version always uses the same stack length (85), but this was
 365.130 +         * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
 365.131 +         * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
 365.132 +         * large) stack lengths for smaller arrays.  The "magic numbers" in the
 365.133 +         * computation below must be changed if MIN_MERGE is decreased.  See
 365.134 +         * the MIN_MERGE declaration above for more information.
 365.135 +         */
 365.136 +        int stackLen = (len <    120  ?  5 :
 365.137 +                        len <   1542  ? 10 :
 365.138 +                        len < 119151  ? 19 : 40);
 365.139 +        runBase = new int[stackLen];
 365.140 +        runLen = new int[stackLen];
 365.141 +    }
 365.142 +
 365.143 +    /*
 365.144 +     * The next two methods (which are package private and static) constitute
 365.145 +     * the entire API of this class.  Each of these methods obeys the contract
 365.146 +     * of the public method with the same signature in java.util.Arrays.
 365.147 +     */
 365.148 +
 365.149 +    static void sort(Object[] a) {
 365.150 +          sort(a, 0, a.length);
 365.151 +    }
 365.152 +
 365.153 +    static void sort(Object[] a, int lo, int hi) {
 365.154 +        rangeCheck(a.length, lo, hi);
 365.155 +        int nRemaining  = hi - lo;
 365.156 +        if (nRemaining < 2)
 365.157 +            return;  // Arrays of size 0 and 1 are always sorted
 365.158 +
 365.159 +        // If array is small, do a "mini-TimSort" with no merges
 365.160 +        if (nRemaining < MIN_MERGE) {
 365.161 +            int initRunLen = countRunAndMakeAscending(a, lo, hi);
 365.162 +            binarySort(a, lo, hi, lo + initRunLen);
 365.163 +            return;
 365.164 +        }
 365.165 +
 365.166 +        /**
 365.167 +         * March over the array once, left to right, finding natural runs,
 365.168 +         * extending short natural runs to minRun elements, and merging runs
 365.169 +         * to maintain stack invariant.
 365.170 +         */
 365.171 +        ComparableTimSort ts = new ComparableTimSort(a);
 365.172 +        int minRun = minRunLength(nRemaining);
 365.173 +        do {
 365.174 +            // Identify next run
 365.175 +            int runLen = countRunAndMakeAscending(a, lo, hi);
 365.176 +
 365.177 +            // If run is short, extend to min(minRun, nRemaining)
 365.178 +            if (runLen < minRun) {
 365.179 +                int force = nRemaining <= minRun ? nRemaining : minRun;
 365.180 +                binarySort(a, lo, lo + force, lo + runLen);
 365.181 +                runLen = force;
 365.182 +            }
 365.183 +
 365.184 +            // Push run onto pending-run stack, and maybe merge
 365.185 +            ts.pushRun(lo, runLen);
 365.186 +            ts.mergeCollapse();
 365.187 +
 365.188 +            // Advance to find next run
 365.189 +            lo += runLen;
 365.190 +            nRemaining -= runLen;
 365.191 +        } while (nRemaining != 0);
 365.192 +
 365.193 +        // Merge all remaining runs to complete sort
 365.194 +        assert lo == hi;
 365.195 +        ts.mergeForceCollapse();
 365.196 +        assert ts.stackSize == 1;
 365.197 +    }
 365.198 +
 365.199 +    /**
 365.200 +     * Sorts the specified portion of the specified array using a binary
 365.201 +     * insertion sort.  This is the best method for sorting small numbers
 365.202 +     * of elements.  It requires O(n log n) compares, but O(n^2) data
 365.203 +     * movement (worst case).
 365.204 +     *
 365.205 +     * If the initial part of the specified range is already sorted,
 365.206 +     * this method can take advantage of it: the method assumes that the
 365.207 +     * elements from index {@code lo}, inclusive, to {@code start},
 365.208 +     * exclusive are already sorted.
 365.209 +     *
 365.210 +     * @param a the array in which a range is to be sorted
 365.211 +     * @param lo the index of the first element in the range to be sorted
 365.212 +     * @param hi the index after the last element in the range to be sorted
 365.213 +     * @param start the index of the first element in the range that is
 365.214 +     *        not already known to be sorted ({@code lo <= start <= hi})
 365.215 +     */
 365.216 +    @SuppressWarnings("fallthrough")
 365.217 +    private static void binarySort(Object[] a, int lo, int hi, int start) {
 365.218 +        assert lo <= start && start <= hi;
 365.219 +        if (start == lo)
 365.220 +            start++;
 365.221 +        for ( ; start < hi; start++) {
 365.222 +            @SuppressWarnings("unchecked")
 365.223 +            Comparable<Object> pivot = (Comparable) a[start];
 365.224 +
 365.225 +            // Set left (and right) to the index where a[start] (pivot) belongs
 365.226 +            int left = lo;
 365.227 +            int right = start;
 365.228 +            assert left <= right;
 365.229 +            /*
 365.230 +             * Invariants:
 365.231 +             *   pivot >= all in [lo, left).
 365.232 +             *   pivot <  all in [right, start).
 365.233 +             */
 365.234 +            while (left < right) {
 365.235 +                int mid = (left + right) >>> 1;
 365.236 +                if (pivot.compareTo(a[mid]) < 0)
 365.237 +                    right = mid;
 365.238 +                else
 365.239 +                    left = mid + 1;
 365.240 +            }
 365.241 +            assert left == right;
 365.242 +
 365.243 +            /*
 365.244 +             * The invariants still hold: pivot >= all in [lo, left) and
 365.245 +             * pivot < all in [left, start), so pivot belongs at left.  Note
 365.246 +             * that if there are elements equal to pivot, left points to the
 365.247 +             * first slot after them -- that's why this sort is stable.
 365.248 +             * Slide elements over to make room for pivot.
 365.249 +             */
 365.250 +            int n = start - left;  // The number of elements to move
 365.251 +            // Switch is just an optimization for arraycopy in default case
 365.252 +            switch (n) {
 365.253 +                case 2:  a[left + 2] = a[left + 1];
 365.254 +                case 1:  a[left + 1] = a[left];
 365.255 +                         break;
 365.256 +                default: System.arraycopy(a, left, a, left + 1, n);
 365.257 +            }
 365.258 +            a[left] = pivot;
 365.259 +        }
 365.260 +    }
 365.261 +
 365.262 +    /**
 365.263 +     * Returns the length of the run beginning at the specified position in
 365.264 +     * the specified array and reverses the run if it is descending (ensuring
 365.265 +     * that the run will always be ascending when the method returns).
 365.266 +     *
 365.267 +     * A run is the longest ascending sequence with:
 365.268 +     *
 365.269 +     *    a[lo] <= a[lo + 1] <= a[lo + 2] <= ...
 365.270 +     *
 365.271 +     * or the longest descending sequence with:
 365.272 +     *
 365.273 +     *    a[lo] >  a[lo + 1] >  a[lo + 2] >  ...
 365.274 +     *
 365.275 +     * For its intended use in a stable mergesort, the strictness of the
 365.276 +     * definition of "descending" is needed so that the call can safely
 365.277 +     * reverse a descending sequence without violating stability.
 365.278 +     *
 365.279 +     * @param a the array in which a run is to be counted and possibly reversed
 365.280 +     * @param lo index of the first element in the run
 365.281 +     * @param hi index after the last element that may be contained in the run.
 365.282 +              It is required that {@code lo < hi}.
 365.283 +     * @return  the length of the run beginning at the specified position in
 365.284 +     *          the specified array
 365.285 +     */
 365.286 +    @SuppressWarnings("unchecked")
 365.287 +    private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
 365.288 +        assert lo < hi;
 365.289 +        int runHi = lo + 1;
 365.290 +        if (runHi == hi)
 365.291 +            return 1;
 365.292 +
 365.293 +        // Find end of run, and reverse range if descending
 365.294 +        if (((Comparable) a[runHi++]).compareTo(a[lo]) < 0) { // Descending
 365.295 +            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0)
 365.296 +                runHi++;
 365.297 +            reverseRange(a, lo, runHi);
 365.298 +        } else {                              // Ascending
 365.299 +            while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) >= 0)
 365.300 +                runHi++;
 365.301 +        }
 365.302 +
 365.303 +        return runHi - lo;
 365.304 +    }
 365.305 +
 365.306 +    /**
 365.307 +     * Reverse the specified range of the specified array.
 365.308 +     *
 365.309 +     * @param a the array in which a range is to be reversed
 365.310 +     * @param lo the index of the first element in the range to be reversed
 365.311 +     * @param hi the index after the last element in the range to be reversed
 365.312 +     */
 365.313 +    private static void reverseRange(Object[] a, int lo, int hi) {
 365.314 +        hi--;
 365.315 +        while (lo < hi) {
 365.316 +            Object t = a[lo];
 365.317 +            a[lo++] = a[hi];
 365.318 +            a[hi--] = t;
 365.319 +        }
 365.320 +    }
 365.321 +
 365.322 +    /**
 365.323 +     * Returns the minimum acceptable run length for an array of the specified
 365.324 +     * length. Natural runs shorter than this will be extended with
 365.325 +     * {@link #binarySort}.
 365.326 +     *
 365.327 +     * Roughly speaking, the computation is:
 365.328 +     *
 365.329 +     *  If n < MIN_MERGE, return n (it's too small to bother with fancy stuff).
 365.330 +     *  Else if n is an exact power of 2, return MIN_MERGE/2.
 365.331 +     *  Else return an int k, MIN_MERGE/2 <= k <= MIN_MERGE, such that n/k
 365.332 +     *   is close to, but strictly less than, an exact power of 2.
 365.333 +     *
 365.334 +     * For the rationale, see listsort.txt.
 365.335 +     *
 365.336 +     * @param n the length of the array to be sorted
 365.337 +     * @return the length of the minimum run to be merged
 365.338 +     */
 365.339 +    private static int minRunLength(int n) {
 365.340 +        assert n >= 0;
 365.341 +        int r = 0;      // Becomes 1 if any 1 bits are shifted off
 365.342 +        while (n >= MIN_MERGE) {
 365.343 +            r |= (n & 1);
 365.344 +            n >>= 1;
 365.345 +        }
 365.346 +        return n + r;
 365.347 +    }
 365.348 +
 365.349 +    /**
 365.350 +     * Pushes the specified run onto the pending-run stack.
 365.351 +     *
 365.352 +     * @param runBase index of the first element in the run
 365.353 +     * @param runLen  the number of elements in the run
 365.354 +     */
 365.355 +    private void pushRun(int runBase, int runLen) {
 365.356 +        this.runBase[stackSize] = runBase;
 365.357 +        this.runLen[stackSize] = runLen;
 365.358 +        stackSize++;
 365.359 +    }
 365.360 +
 365.361 +    /**
 365.362 +     * Examines the stack of runs waiting to be merged and merges adjacent runs
 365.363 +     * until the stack invariants are reestablished:
 365.364 +     *
 365.365 +     *     1. runLen[i - 3] > runLen[i - 2] + runLen[i - 1]
 365.366 +     *     2. runLen[i - 2] > runLen[i - 1]
 365.367 +     *
 365.368 +     * This method is called each time a new run is pushed onto the stack,
 365.369 +     * so the invariants are guaranteed to hold for i < stackSize upon
 365.370 +     * entry to the method.
 365.371 +     */
 365.372 +    private void mergeCollapse() {
 365.373 +        while (stackSize > 1) {
 365.374 +            int n = stackSize - 2;
 365.375 +            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
 365.376 +                if (runLen[n - 1] < runLen[n + 1])
 365.377 +                    n--;
 365.378 +                mergeAt(n);
 365.379 +            } else if (runLen[n] <= runLen[n + 1]) {
 365.380 +                mergeAt(n);
 365.381 +            } else {
 365.382 +                break; // Invariant is established
 365.383 +            }
 365.384 +        }
 365.385 +    }
 365.386 +
 365.387 +    /**
 365.388 +     * Merges all runs on the stack until only one remains.  This method is
 365.389 +     * called once, to complete the sort.
 365.390 +     */
 365.391 +    private void mergeForceCollapse() {
 365.392 +        while (stackSize > 1) {
 365.393 +            int n = stackSize - 2;
 365.394 +            if (n > 0 && runLen[n - 1] < runLen[n + 1])
 365.395 +                n--;
 365.396 +            mergeAt(n);
 365.397 +        }
 365.398 +    }
 365.399 +
 365.400 +    /**
 365.401 +     * Merges the two runs at stack indices i and i+1.  Run i must be
 365.402 +     * the penultimate or antepenultimate run on the stack.  In other words,
 365.403 +     * i must be equal to stackSize-2 or stackSize-3.
 365.404 +     *
 365.405 +     * @param i stack index of the first of the two runs to merge
 365.406 +     */
 365.407 +    @SuppressWarnings("unchecked")
 365.408 +    private void mergeAt(int i) {
 365.409 +        assert stackSize >= 2;
 365.410 +        assert i >= 0;
 365.411 +        assert i == stackSize - 2 || i == stackSize - 3;
 365.412 +
 365.413 +        int base1 = runBase[i];
 365.414 +        int len1 = runLen[i];
 365.415 +        int base2 = runBase[i + 1];
 365.416 +        int len2 = runLen[i + 1];
 365.417 +        assert len1 > 0 && len2 > 0;
 365.418 +        assert base1 + len1 == base2;
 365.419 +
 365.420 +        /*
 365.421 +         * Record the length of the combined runs; if i is the 3rd-last
 365.422 +         * run now, also slide over the last run (which isn't involved
 365.423 +         * in this merge).  The current run (i+1) goes away in any case.
 365.424 +         */
 365.425 +        runLen[i] = len1 + len2;
 365.426 +        if (i == stackSize - 3) {
 365.427 +            runBase[i + 1] = runBase[i + 2];
 365.428 +            runLen[i + 1] = runLen[i + 2];
 365.429 +        }
 365.430 +        stackSize--;
 365.431 +
 365.432 +        /*
 365.433 +         * Find where the first element of run2 goes in run1. Prior elements
 365.434 +         * in run1 can be ignored (because they're already in place).
 365.435 +         */
 365.436 +        int k = gallopRight((Comparable<Object>) a[base2], a, base1, len1, 0);
 365.437 +        assert k >= 0;
 365.438 +        base1 += k;
 365.439 +        len1 -= k;
 365.440 +        if (len1 == 0)
 365.441 +            return;
 365.442 +
 365.443 +        /*
 365.444 +         * Find where the last element of run1 goes in run2. Subsequent elements
 365.445 +         * in run2 can be ignored (because they're already in place).
 365.446 +         */
 365.447 +        len2 = gallopLeft((Comparable<Object>) a[base1 + len1 - 1], a,
 365.448 +                base2, len2, len2 - 1);
 365.449 +        assert len2 >= 0;
 365.450 +        if (len2 == 0)
 365.451 +            return;
 365.452 +
 365.453 +        // Merge remaining runs, using tmp array with min(len1, len2) elements
 365.454 +        if (len1 <= len2)
 365.455 +            mergeLo(base1, len1, base2, len2);
 365.456 +        else
 365.457 +            mergeHi(base1, len1, base2, len2);
 365.458 +    }
 365.459 +
 365.460 +    /**
 365.461 +     * Locates the position at which to insert the specified key into the
 365.462 +     * specified sorted range; if the range contains an element equal to key,
 365.463 +     * returns the index of the leftmost equal element.
 365.464 +     *
 365.465 +     * @param key the key whose insertion point to search for
 365.466 +     * @param a the array in which to search
 365.467 +     * @param base the index of the first element in the range
 365.468 +     * @param len the length of the range; must be > 0
 365.469 +     * @param hint the index at which to begin the search, 0 <= hint < n.
 365.470 +     *     The closer hint is to the result, the faster this method will run.
 365.471 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] < key <= a[b + k],
 365.472 +     *    pretending that a[b - 1] is minus infinity and a[b + n] is infinity.
 365.473 +     *    In other words, key belongs at index b + k; or in other words,
 365.474 +     *    the first k elements of a should precede key, and the last n - k
 365.475 +     *    should follow it.
 365.476 +     */
 365.477 +    private static int gallopLeft(Comparable<Object> key, Object[] a,
 365.478 +            int base, int len, int hint) {
 365.479 +        assert len > 0 && hint >= 0 && hint < len;
 365.480 +
 365.481 +        int lastOfs = 0;
 365.482 +        int ofs = 1;
 365.483 +        if (key.compareTo(a[base + hint]) > 0) {
 365.484 +            // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs]
 365.485 +            int maxOfs = len - hint;
 365.486 +            while (ofs < maxOfs && key.compareTo(a[base + hint + ofs]) > 0) {
 365.487 +                lastOfs = ofs;
 365.488 +                ofs = (ofs << 1) + 1;
 365.489 +                if (ofs <= 0)   // int overflow
 365.490 +                    ofs = maxOfs;
 365.491 +            }
 365.492 +            if (ofs > maxOfs)
 365.493 +                ofs = maxOfs;
 365.494 +
 365.495 +            // Make offsets relative to base
 365.496 +            lastOfs += hint;
 365.497 +            ofs += hint;
 365.498 +        } else { // key <= a[base + hint]
 365.499 +            // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs]
 365.500 +            final int maxOfs = hint + 1;
 365.501 +            while (ofs < maxOfs && key.compareTo(a[base + hint - ofs]) <= 0) {
 365.502 +                lastOfs = ofs;
 365.503 +                ofs = (ofs << 1) + 1;
 365.504 +                if (ofs <= 0)   // int overflow
 365.505 +                    ofs = maxOfs;
 365.506 +            }
 365.507 +            if (ofs > maxOfs)
 365.508 +                ofs = maxOfs;
 365.509 +
 365.510 +            // Make offsets relative to base
 365.511 +            int tmp = lastOfs;
 365.512 +            lastOfs = hint - ofs;
 365.513 +            ofs = hint - tmp;
 365.514 +        }
 365.515 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
 365.516 +
 365.517 +        /*
 365.518 +         * Now a[base+lastOfs] < key <= a[base+ofs], so key belongs somewhere
 365.519 +         * to the right of lastOfs but no farther right than ofs.  Do a binary
 365.520 +         * search, with invariant a[base + lastOfs - 1] < key <= a[base + ofs].
 365.521 +         */
 365.522 +        lastOfs++;
 365.523 +        while (lastOfs < ofs) {
 365.524 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
 365.525 +
 365.526 +            if (key.compareTo(a[base + m]) > 0)
 365.527 +                lastOfs = m + 1;  // a[base + m] < key
 365.528 +            else
 365.529 +                ofs = m;          // key <= a[base + m]
 365.530 +        }
 365.531 +        assert lastOfs == ofs;    // so a[base + ofs - 1] < key <= a[base + ofs]
 365.532 +        return ofs;
 365.533 +    }
 365.534 +
 365.535 +    /**
 365.536 +     * Like gallopLeft, except that if the range contains an element equal to
 365.537 +     * key, gallopRight returns the index after the rightmost equal element.
 365.538 +     *
 365.539 +     * @param key the key whose insertion point to search for
 365.540 +     * @param a the array in which to search
 365.541 +     * @param base the index of the first element in the range
 365.542 +     * @param len the length of the range; must be > 0
 365.543 +     * @param hint the index at which to begin the search, 0 <= hint < n.
 365.544 +     *     The closer hint is to the result, the faster this method will run.
 365.545 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
 365.546 +     */
 365.547 +    private static int gallopRight(Comparable<Object> key, Object[] a,
 365.548 +            int base, int len, int hint) {
 365.549 +        assert len > 0 && hint >= 0 && hint < len;
 365.550 +
 365.551 +        int ofs = 1;
 365.552 +        int lastOfs = 0;
 365.553 +        if (key.compareTo(a[base + hint]) < 0) {
 365.554 +            // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs]
 365.555 +            int maxOfs = hint + 1;
 365.556 +            while (ofs < maxOfs && key.compareTo(a[base + hint - ofs]) < 0) {
 365.557 +                lastOfs = ofs;
 365.558 +                ofs = (ofs << 1) + 1;
 365.559 +                if (ofs <= 0)   // int overflow
 365.560 +                    ofs = maxOfs;
 365.561 +            }
 365.562 +            if (ofs > maxOfs)
 365.563 +                ofs = maxOfs;
 365.564 +
 365.565 +            // Make offsets relative to b
 365.566 +            int tmp = lastOfs;
 365.567 +            lastOfs = hint - ofs;
 365.568 +            ofs = hint - tmp;
 365.569 +        } else { // a[b + hint] <= key
 365.570 +            // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs]
 365.571 +            int maxOfs = len - hint;
 365.572 +            while (ofs < maxOfs && key.compareTo(a[base + hint + ofs]) >= 0) {
 365.573 +                lastOfs = ofs;
 365.574 +                ofs = (ofs << 1) + 1;
 365.575 +                if (ofs <= 0)   // int overflow
 365.576 +                    ofs = maxOfs;
 365.577 +            }
 365.578 +            if (ofs > maxOfs)
 365.579 +                ofs = maxOfs;
 365.580 +
 365.581 +            // Make offsets relative to b
 365.582 +            lastOfs += hint;
 365.583 +            ofs += hint;
 365.584 +        }
 365.585 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
 365.586 +
 365.587 +        /*
 365.588 +         * Now a[b + lastOfs] <= key < a[b + ofs], so key belongs somewhere to
 365.589 +         * the right of lastOfs but no farther right than ofs.  Do a binary
 365.590 +         * search, with invariant a[b + lastOfs - 1] <= key < a[b + ofs].
 365.591 +         */
 365.592 +        lastOfs++;
 365.593 +        while (lastOfs < ofs) {
 365.594 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
 365.595 +
 365.596 +            if (key.compareTo(a[base + m]) < 0)
 365.597 +                ofs = m;          // key < a[b + m]
 365.598 +            else
 365.599 +                lastOfs = m + 1;  // a[b + m] <= key
 365.600 +        }
 365.601 +        assert lastOfs == ofs;    // so a[b + ofs - 1] <= key < a[b + ofs]
 365.602 +        return ofs;
 365.603 +    }
 365.604 +
 365.605 +    /**
 365.606 +     * Merges two adjacent runs in place, in a stable fashion.  The first
 365.607 +     * element of the first run must be greater than the first element of the
 365.608 +     * second run (a[base1] > a[base2]), and the last element of the first run
 365.609 +     * (a[base1 + len1-1]) must be greater than all elements of the second run.
 365.610 +     *
 365.611 +     * For performance, this method should be called only when len1 <= len2;
 365.612 +     * its twin, mergeHi should be called if len1 >= len2.  (Either method
 365.613 +     * may be called if len1 == len2.)
 365.614 +     *
 365.615 +     * @param base1 index of first element in first run to be merged
 365.616 +     * @param len1  length of first run to be merged (must be > 0)
 365.617 +     * @param base2 index of first element in second run to be merged
 365.618 +     *        (must be aBase + aLen)
 365.619 +     * @param len2  length of second run to be merged (must be > 0)
 365.620 +     */
 365.621 +    @SuppressWarnings("unchecked")
 365.622 +    private void mergeLo(int base1, int len1, int base2, int len2) {
 365.623 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
 365.624 +
 365.625 +        // Copy first run into temp array
 365.626 +        Object[] a = this.a; // For performance
 365.627 +        Object[] tmp = ensureCapacity(len1);
 365.628 +        System.arraycopy(a, base1, tmp, 0, len1);
 365.629 +
 365.630 +        int cursor1 = 0;       // Indexes into tmp array
 365.631 +        int cursor2 = base2;   // Indexes int a
 365.632 +        int dest = base1;      // Indexes int a
 365.633 +
 365.634 +        // Move first element of second run and deal with degenerate cases
 365.635 +        a[dest++] = a[cursor2++];
 365.636 +        if (--len2 == 0) {
 365.637 +            System.arraycopy(tmp, cursor1, a, dest, len1);
 365.638 +            return;
 365.639 +        }
 365.640 +        if (len1 == 1) {
 365.641 +            System.arraycopy(a, cursor2, a, dest, len2);
 365.642 +            a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
 365.643 +            return;
 365.644 +        }
 365.645 +
 365.646 +        int minGallop = this.minGallop;  // Use local variable for performance
 365.647 +    outer:
 365.648 +        while (true) {
 365.649 +            int count1 = 0; // Number of times in a row that first run won
 365.650 +            int count2 = 0; // Number of times in a row that second run won
 365.651 +
 365.652 +            /*
 365.653 +             * Do the straightforward thing until (if ever) one run starts
 365.654 +             * winning consistently.
 365.655 +             */
 365.656 +            do {
 365.657 +                assert len1 > 1 && len2 > 0;
 365.658 +                if (((Comparable) a[cursor2]).compareTo(tmp[cursor1]) < 0) {
 365.659 +                    a[dest++] = a[cursor2++];
 365.660 +                    count2++;
 365.661 +                    count1 = 0;
 365.662 +                    if (--len2 == 0)
 365.663 +                        break outer;
 365.664 +                } else {
 365.665 +                    a[dest++] = tmp[cursor1++];
 365.666 +                    count1++;
 365.667 +                    count2 = 0;
 365.668 +                    if (--len1 == 1)
 365.669 +                        break outer;
 365.670 +                }
 365.671 +            } while ((count1 | count2) < minGallop);
 365.672 +
 365.673 +            /*
 365.674 +             * One run is winning so consistently that galloping may be a
 365.675 +             * huge win. So try that, and continue galloping until (if ever)
 365.676 +             * neither run appears to be winning consistently anymore.
 365.677 +             */
 365.678 +            do {
 365.679 +                assert len1 > 1 && len2 > 0;
 365.680 +                count1 = gallopRight((Comparable) a[cursor2], tmp, cursor1, len1, 0);
 365.681 +                if (count1 != 0) {
 365.682 +                    System.arraycopy(tmp, cursor1, a, dest, count1);
 365.683 +                    dest += count1;
 365.684 +                    cursor1 += count1;
 365.685 +                    len1 -= count1;
 365.686 +                    if (len1 <= 1)  // len1 == 1 || len1 == 0
 365.687 +                        break outer;
 365.688 +                }
 365.689 +                a[dest++] = a[cursor2++];
 365.690 +                if (--len2 == 0)
 365.691 +                    break outer;
 365.692 +
 365.693 +                count2 = gallopLeft((Comparable) tmp[cursor1], a, cursor2, len2, 0);
 365.694 +                if (count2 != 0) {
 365.695 +                    System.arraycopy(a, cursor2, a, dest, count2);
 365.696 +                    dest += count2;
 365.697 +                    cursor2 += count2;
 365.698 +                    len2 -= count2;
 365.699 +                    if (len2 == 0)
 365.700 +                        break outer;
 365.701 +                }
 365.702 +                a[dest++] = tmp[cursor1++];
 365.703 +                if (--len1 == 1)
 365.704 +                    break outer;
 365.705 +                minGallop--;
 365.706 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
 365.707 +            if (minGallop < 0)
 365.708 +                minGallop = 0;
 365.709 +            minGallop += 2;  // Penalize for leaving gallop mode
 365.710 +        }  // End of "outer" loop
 365.711 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
 365.712 +
 365.713 +        if (len1 == 1) {
 365.714 +            assert len2 > 0;
 365.715 +            System.arraycopy(a, cursor2, a, dest, len2);
 365.716 +            a[dest + len2] = tmp[cursor1]; //  Last elt of run 1 to end of merge
 365.717 +        } else if (len1 == 0) {
 365.718 +            throw new IllegalArgumentException(
 365.719 +                "Comparison method violates its general contract!");
 365.720 +        } else {
 365.721 +            assert len2 == 0;
 365.722 +            assert len1 > 1;
 365.723 +            System.arraycopy(tmp, cursor1, a, dest, len1);
 365.724 +        }
 365.725 +    }
 365.726 +
 365.727 +    /**
 365.728 +     * Like mergeLo, except that this method should be called only if
 365.729 +     * len1 >= len2; mergeLo should be called if len1 <= len2.  (Either method
 365.730 +     * may be called if len1 == len2.)
 365.731 +     *
 365.732 +     * @param base1 index of first element in first run to be merged
 365.733 +     * @param len1  length of first run to be merged (must be > 0)
 365.734 +     * @param base2 index of first element in second run to be merged
 365.735 +     *        (must be aBase + aLen)
 365.736 +     * @param len2  length of second run to be merged (must be > 0)
 365.737 +     */
 365.738 +    @SuppressWarnings("unchecked")
 365.739 +    private void mergeHi(int base1, int len1, int base2, int len2) {
 365.740 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
 365.741 +
 365.742 +        // Copy second run into temp array
 365.743 +        Object[] a = this.a; // For performance
 365.744 +        Object[] tmp = ensureCapacity(len2);
 365.745 +        System.arraycopy(a, base2, tmp, 0, len2);
 365.746 +
 365.747 +        int cursor1 = base1 + len1 - 1;  // Indexes into a
 365.748 +        int cursor2 = len2 - 1;          // Indexes into tmp array
 365.749 +        int dest = base2 + len2 - 1;     // Indexes into a
 365.750 +
 365.751 +        // Move last element of first run and deal with degenerate cases
 365.752 +        a[dest--] = a[cursor1--];
 365.753 +        if (--len1 == 0) {
 365.754 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
 365.755 +            return;
 365.756 +        }
 365.757 +        if (len2 == 1) {
 365.758 +            dest -= len1;
 365.759 +            cursor1 -= len1;
 365.760 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
 365.761 +            a[dest] = tmp[cursor2];
 365.762 +            return;
 365.763 +        }
 365.764 +
 365.765 +        int minGallop = this.minGallop;  // Use local variable for performance
 365.766 +    outer:
 365.767 +        while (true) {
 365.768 +            int count1 = 0; // Number of times in a row that first run won
 365.769 +            int count2 = 0; // Number of times in a row that second run won
 365.770 +
 365.771 +            /*
 365.772 +             * Do the straightforward thing until (if ever) one run
 365.773 +             * appears to win consistently.
 365.774 +             */
 365.775 +            do {
 365.776 +                assert len1 > 0 && len2 > 1;
 365.777 +                if (((Comparable) tmp[cursor2]).compareTo(a[cursor1]) < 0) {
 365.778 +                    a[dest--] = a[cursor1--];
 365.779 +                    count1++;
 365.780 +                    count2 = 0;
 365.781 +                    if (--len1 == 0)
 365.782 +                        break outer;
 365.783 +                } else {
 365.784 +                    a[dest--] = tmp[cursor2--];
 365.785 +                    count2++;
 365.786 +                    count1 = 0;
 365.787 +                    if (--len2 == 1)
 365.788 +                        break outer;
 365.789 +                }
 365.790 +            } while ((count1 | count2) < minGallop);
 365.791 +
 365.792 +            /*
 365.793 +             * One run is winning so consistently that galloping may be a
 365.794 +             * huge win. So try that, and continue galloping until (if ever)
 365.795 +             * neither run appears to be winning consistently anymore.
 365.796 +             */
 365.797 +            do {
 365.798 +                assert len1 > 0 && len2 > 1;
 365.799 +                count1 = len1 - gallopRight((Comparable) tmp[cursor2], a, base1, len1, len1 - 1);
 365.800 +                if (count1 != 0) {
 365.801 +                    dest -= count1;
 365.802 +                    cursor1 -= count1;
 365.803 +                    len1 -= count1;
 365.804 +                    System.arraycopy(a, cursor1 + 1, a, dest + 1, count1);
 365.805 +                    if (len1 == 0)
 365.806 +                        break outer;
 365.807 +                }
 365.808 +                a[dest--] = tmp[cursor2--];
 365.809 +                if (--len2 == 1)
 365.810 +                    break outer;
 365.811 +
 365.812 +                count2 = len2 - gallopLeft((Comparable) a[cursor1], tmp, 0, len2, len2 - 1);
 365.813 +                if (count2 != 0) {
 365.814 +                    dest -= count2;
 365.815 +                    cursor2 -= count2;
 365.816 +                    len2 -= count2;
 365.817 +                    System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
 365.818 +                    if (len2 <= 1)
 365.819 +                        break outer; // len2 == 1 || len2 == 0
 365.820 +                }
 365.821 +                a[dest--] = a[cursor1--];
 365.822 +                if (--len1 == 0)
 365.823 +                    break outer;
 365.824 +                minGallop--;
 365.825 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
 365.826 +            if (minGallop < 0)
 365.827 +                minGallop = 0;
 365.828 +            minGallop += 2;  // Penalize for leaving gallop mode
 365.829 +        }  // End of "outer" loop
 365.830 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
 365.831 +
 365.832 +        if (len2 == 1) {
 365.833 +            assert len1 > 0;
 365.834 +            dest -= len1;
 365.835 +            cursor1 -= len1;
 365.836 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
 365.837 +            a[dest] = tmp[cursor2];  // Move first elt of run2 to front of merge
 365.838 +        } else if (len2 == 0) {
 365.839 +            throw new IllegalArgumentException(
 365.840 +                "Comparison method violates its general contract!");
 365.841 +        } else {
 365.842 +            assert len1 == 0;
 365.843 +            assert len2 > 0;
 365.844 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
 365.845 +        }
 365.846 +    }
 365.847 +
 365.848 +    /**
 365.849 +     * Ensures that the external array tmp has at least the specified
 365.850 +     * number of elements, increasing its size if necessary.  The size
 365.851 +     * increases exponentially to ensure amortized linear time complexity.
 365.852 +     *
 365.853 +     * @param minCapacity the minimum required capacity of the tmp array
 365.854 +     * @return tmp, whether or not it grew
 365.855 +     */
 365.856 +    private Object[]  ensureCapacity(int minCapacity) {
 365.857 +        if (tmp.length < minCapacity) {
 365.858 +            // Compute smallest power of 2 > minCapacity
 365.859 +            int newSize = minCapacity;
 365.860 +            newSize |= newSize >> 1;
 365.861 +            newSize |= newSize >> 2;
 365.862 +            newSize |= newSize >> 4;
 365.863 +            newSize |= newSize >> 8;
 365.864 +            newSize |= newSize >> 16;
 365.865 +            newSize++;
 365.866 +
 365.867 +            if (newSize < 0) // Not bloody likely!
 365.868 +                newSize = minCapacity;
 365.869 +            else
 365.870 +                newSize = Math.min(newSize, a.length >>> 1);
 365.871 +
 365.872 +            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
 365.873 +            Object[] newArray = new Object[newSize];
 365.874 +            tmp = newArray;
 365.875 +        }
 365.876 +        return tmp;
 365.877 +    }
 365.878 +
 365.879 +    /**
 365.880 +     * Checks that fromIndex and toIndex are in range, and throws an
 365.881 +     * appropriate exception if they aren't.
 365.882 +     *
 365.883 +     * @param arrayLen the length of the array
 365.884 +     * @param fromIndex the index of the first element of the range
 365.885 +     * @param toIndex the index after the last element of the range
 365.886 +     * @throws IllegalArgumentException if fromIndex > toIndex
 365.887 +     * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
 365.888 +     *         or toIndex > arrayLen
 365.889 +     */
 365.890 +    private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
 365.891 +        if (fromIndex > toIndex)
 365.892 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
 365.893 +                       ") > toIndex(" + toIndex+")");
 365.894 +        if (fromIndex < 0)
 365.895 +            throw new ArrayIndexOutOfBoundsException(fromIndex);
 365.896 +        if (toIndex > arrayLen)
 365.897 +            throw new ArrayIndexOutOfBoundsException(toIndex);
 365.898 +    }
 365.899 +}
   366.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   366.2 +++ b/rt/emul/compact/src/main/java/java/util/ConcurrentModificationException.java	Wed Feb 27 11:24:58 2013 +0100
   366.3 @@ -0,0 +1,123 @@
   366.4 +/*
   366.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   366.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   366.7 + *
   366.8 + * This code is free software; you can redistribute it and/or modify it
   366.9 + * under the terms of the GNU General Public License version 2 only, as
  366.10 + * published by the Free Software Foundation.  Oracle designates this
  366.11 + * particular file as subject to the "Classpath" exception as provided
  366.12 + * by Oracle in the LICENSE file that accompanied this code.
  366.13 + *
  366.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  366.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  366.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  366.17 + * version 2 for more details (a copy is included in the LICENSE file that
  366.18 + * accompanied this code).
  366.19 + *
  366.20 + * You should have received a copy of the GNU General Public License version
  366.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  366.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  366.23 + *
  366.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  366.25 + * or visit www.oracle.com if you need additional information or have any
  366.26 + * questions.
  366.27 + */
  366.28 +
  366.29 +package java.util;
  366.30 +
  366.31 +/**
  366.32 + * This exception may be thrown by methods that have detected concurrent
  366.33 + * modification of an object when such modification is not permissible.
  366.34 + * <p>
  366.35 + * For example, it is not generally permissible for one thread to modify a Collection
  366.36 + * while another thread is iterating over it.  In general, the results of the
  366.37 + * iteration are undefined under these circumstances.  Some Iterator
  366.38 + * implementations (including those of all the general purpose collection implementations
  366.39 + * provided by the JRE) may choose to throw this exception if this behavior is
  366.40 + * detected.  Iterators that do this are known as <i>fail-fast</i> iterators,
  366.41 + * as they fail quickly and cleanly, rather that risking arbitrary,
  366.42 + * non-deterministic behavior at an undetermined time in the future.
  366.43 + * <p>
  366.44 + * Note that this exception does not always indicate that an object has
  366.45 + * been concurrently modified by a <i>different</i> thread.  If a single
  366.46 + * thread issues a sequence of method invocations that violates the
  366.47 + * contract of an object, the object may throw this exception.  For
  366.48 + * example, if a thread modifies a collection directly while it is
  366.49 + * iterating over the collection with a fail-fast iterator, the iterator
  366.50 + * will throw this exception.
  366.51 + *
  366.52 + * <p>Note that fail-fast behavior cannot be guaranteed as it is, generally
  366.53 + * speaking, impossible to make any hard guarantees in the presence of
  366.54 + * unsynchronized concurrent modification.  Fail-fast operations
  366.55 + * throw {@code ConcurrentModificationException} on a best-effort basis.
  366.56 + * Therefore, it would be wrong to write a program that depended on this
  366.57 + * exception for its correctness: <i>{@code ConcurrentModificationException}
  366.58 + * should be used only to detect bugs.</i>
  366.59 + *
  366.60 + * @author  Josh Bloch
  366.61 + * @see     Collection
  366.62 + * @see     Iterator
  366.63 + * @see     ListIterator
  366.64 + * @see     Vector
  366.65 + * @see     LinkedList
  366.66 + * @see     HashSet
  366.67 + * @see     Hashtable
  366.68 + * @see     TreeMap
  366.69 + * @see     AbstractList
  366.70 + * @since   1.2
  366.71 + */
  366.72 +public class ConcurrentModificationException extends RuntimeException {
  366.73 +    private static final long serialVersionUID = -3666751008965953603L;
  366.74 +
  366.75 +    /**
  366.76 +     * Constructs a ConcurrentModificationException with no
  366.77 +     * detail message.
  366.78 +     */
  366.79 +    public ConcurrentModificationException() {
  366.80 +    }
  366.81 +
  366.82 +    /**
  366.83 +     * Constructs a {@code ConcurrentModificationException} with the
  366.84 +     * specified detail message.
  366.85 +     *
  366.86 +     * @param message the detail message pertaining to this exception.
  366.87 +     */
  366.88 +    public ConcurrentModificationException(String message) {
  366.89 +        super(message);
  366.90 +    }
  366.91 +
  366.92 +    /**
  366.93 +     * Constructs a new exception with the specified cause and a detail
  366.94 +     * message of {@code (cause==null ? null : cause.toString())} (which
  366.95 +     * typically contains the class and detail message of {@code cause}.
  366.96 +     *
  366.97 +     * @param  cause the cause (which is saved for later retrieval by the
  366.98 +     *         {@link Throwable#getCause()} method).  (A {@code null} value is
  366.99 +     *         permitted, and indicates that the cause is nonexistent or
 366.100 +     *         unknown.)
 366.101 +     * @since  1.7
 366.102 +     */
 366.103 +    public ConcurrentModificationException(Throwable cause) {
 366.104 +        super(cause);
 366.105 +    }
 366.106 +
 366.107 +    /**
 366.108 +     * Constructs a new exception with the specified detail message and
 366.109 +     * cause.
 366.110 +     *
 366.111 +     * <p>Note that the detail message associated with <code>cause</code> is
 366.112 +     * <i>not</i> automatically incorporated in this exception's detail
 366.113 +     * message.
 366.114 +     *
 366.115 +     * @param  message the detail message (which is saved for later retrieval
 366.116 +     *         by the {@link Throwable#getMessage()} method).
 366.117 +     * @param  cause the cause (which is saved for later retrieval by the
 366.118 +     *         {@link Throwable#getCause()} method).  (A {@code null} value
 366.119 +     *         is permitted, and indicates that the cause is nonexistent or
 366.120 +     *         unknown.)
 366.121 +     * @since 1.7
 366.122 +     */
 366.123 +    public ConcurrentModificationException(String message, Throwable cause) {
 366.124 +        super(message, cause);
 366.125 +    }
 366.126 +}
   367.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   367.2 +++ b/rt/emul/compact/src/main/java/java/util/Deque.java	Wed Feb 27 11:24:58 2013 +0100
   367.3 @@ -0,0 +1,584 @@
   367.4 +/*
   367.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   367.6 + *
   367.7 + * This code is free software; you can redistribute it and/or modify it
   367.8 + * under the terms of the GNU General Public License version 2 only, as
   367.9 + * published by the Free Software Foundation.  Oracle designates this
  367.10 + * particular file as subject to the "Classpath" exception as provided
  367.11 + * by Oracle in the LICENSE file that accompanied this code.
  367.12 + *
  367.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  367.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  367.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  367.16 + * version 2 for more details (a copy is included in the LICENSE file that
  367.17 + * accompanied this code).
  367.18 + *
  367.19 + * You should have received a copy of the GNU General Public License version
  367.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  367.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  367.22 + *
  367.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  367.24 + * or visit www.oracle.com if you need additional information or have any
  367.25 + * questions.
  367.26 + */
  367.27 +
  367.28 +/*
  367.29 + * This file is available under and governed by the GNU General Public
  367.30 + * License version 2 only, as published by the Free Software Foundation.
  367.31 + * However, the following notice accompanied the original version of this
  367.32 + * file:
  367.33 + *
  367.34 + * Written by Doug Lea and Josh Bloch with assistance from members of
  367.35 + * JCP JSR-166 Expert Group and released to the public domain, as explained
  367.36 + * at http://creativecommons.org/publicdomain/zero/1.0/
  367.37 + */
  367.38 +
  367.39 +package java.util;
  367.40 +
  367.41 +/**
  367.42 + * A linear collection that supports element insertion and removal at
  367.43 + * both ends.  The name <i>deque</i> is short for "double ended queue"
  367.44 + * and is usually pronounced "deck".  Most <tt>Deque</tt>
  367.45 + * implementations place no fixed limits on the number of elements
  367.46 + * they may contain, but this interface supports capacity-restricted
  367.47 + * deques as well as those with no fixed size limit.
  367.48 + *
  367.49 + * <p>This interface defines methods to access the elements at both
  367.50 + * ends of the deque.  Methods are provided to insert, remove, and
  367.51 + * examine the element.  Each of these methods exists in two forms:
  367.52 + * one throws an exception if the operation fails, the other returns a
  367.53 + * special value (either <tt>null</tt> or <tt>false</tt>, depending on
  367.54 + * the operation).  The latter form of the insert operation is
  367.55 + * designed specifically for use with capacity-restricted
  367.56 + * <tt>Deque</tt> implementations; in most implementations, insert
  367.57 + * operations cannot fail.
  367.58 + *
  367.59 + * <p>The twelve methods described above are summarized in the
  367.60 + * following table:
  367.61 + *
  367.62 + * <p>
  367.63 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
  367.64 + *  <tr>
  367.65 + *    <td></td>
  367.66 + *    <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
  367.67 + *    <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
  367.68 + *  </tr>
  367.69 + *  <tr>
  367.70 + *    <td></td>
  367.71 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
  367.72 + *    <td ALIGN=CENTER><em>Special value</em></td>
  367.73 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
  367.74 + *    <td ALIGN=CENTER><em>Special value</em></td>
  367.75 + *  </tr>
  367.76 + *  <tr>
  367.77 + *    <td><b>Insert</b></td>
  367.78 + *    <td>{@link #addFirst addFirst(e)}</td>
  367.79 + *    <td>{@link #offerFirst offerFirst(e)}</td>
  367.80 + *    <td>{@link #addLast addLast(e)}</td>
  367.81 + *    <td>{@link #offerLast offerLast(e)}</td>
  367.82 + *  </tr>
  367.83 + *  <tr>
  367.84 + *    <td><b>Remove</b></td>
  367.85 + *    <td>{@link #removeFirst removeFirst()}</td>
  367.86 + *    <td>{@link #pollFirst pollFirst()}</td>
  367.87 + *    <td>{@link #removeLast removeLast()}</td>
  367.88 + *    <td>{@link #pollLast pollLast()}</td>
  367.89 + *  </tr>
  367.90 + *  <tr>
  367.91 + *    <td><b>Examine</b></td>
  367.92 + *    <td>{@link #getFirst getFirst()}</td>
  367.93 + *    <td>{@link #peekFirst peekFirst()}</td>
  367.94 + *    <td>{@link #getLast getLast()}</td>
  367.95 + *    <td>{@link #peekLast peekLast()}</td>
  367.96 + *  </tr>
  367.97 + * </table>
  367.98 + *
  367.99 + * <p>This interface extends the {@link Queue} interface.  When a deque is
 367.100 + * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are
 367.101 + * added at the end of the deque and removed from the beginning.  The methods
 367.102 + * inherited from the <tt>Queue</tt> interface are precisely equivalent to
 367.103 + * <tt>Deque</tt> methods as indicated in the following table:
 367.104 + *
 367.105 + * <p>
 367.106 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
 367.107 + *  <tr>
 367.108 + *    <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
 367.109 + *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
 367.110 + *  </tr>
 367.111 + *  <tr>
 367.112 + *    <td>{@link java.util.Queue#add add(e)}</td>
 367.113 + *    <td>{@link #addLast addLast(e)}</td>
 367.114 + *  </tr>
 367.115 + *  <tr>
 367.116 + *    <td>{@link java.util.Queue#offer offer(e)}</td>
 367.117 + *    <td>{@link #offerLast offerLast(e)}</td>
 367.118 + *  </tr>
 367.119 + *  <tr>
 367.120 + *    <td>{@link java.util.Queue#remove remove()}</td>
 367.121 + *    <td>{@link #removeFirst removeFirst()}</td>
 367.122 + *  </tr>
 367.123 + *  <tr>
 367.124 + *    <td>{@link java.util.Queue#poll poll()}</td>
 367.125 + *    <td>{@link #pollFirst pollFirst()}</td>
 367.126 + *  </tr>
 367.127 + *  <tr>
 367.128 + *    <td>{@link java.util.Queue#element element()}</td>
 367.129 + *    <td>{@link #getFirst getFirst()}</td>
 367.130 + *  </tr>
 367.131 + *  <tr>
 367.132 + *    <td>{@link java.util.Queue#peek peek()}</td>
 367.133 + *    <td>{@link #peek peekFirst()}</td>
 367.134 + *  </tr>
 367.135 + * </table>
 367.136 + *
 367.137 + * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks.  This
 367.138 + * interface should be used in preference to the legacy {@link Stack} class.
 367.139 + * When a deque is used as a stack, elements are pushed and popped from the
 367.140 + * beginning of the deque.  Stack methods are precisely equivalent to
 367.141 + * <tt>Deque</tt> methods as indicated in the table below:
 367.142 + *
 367.143 + * <p>
 367.144 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
 367.145 + *  <tr>
 367.146 + *    <td ALIGN=CENTER> <b>Stack Method</b></td>
 367.147 + *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
 367.148 + *  </tr>
 367.149 + *  <tr>
 367.150 + *    <td>{@link #push push(e)}</td>
 367.151 + *    <td>{@link #addFirst addFirst(e)}</td>
 367.152 + *  </tr>
 367.153 + *  <tr>
 367.154 + *    <td>{@link #pop pop()}</td>
 367.155 + *    <td>{@link #removeFirst removeFirst()}</td>
 367.156 + *  </tr>
 367.157 + *  <tr>
 367.158 + *    <td>{@link #peek peek()}</td>
 367.159 + *    <td>{@link #peekFirst peekFirst()}</td>
 367.160 + *  </tr>
 367.161 + * </table>
 367.162 + *
 367.163 + * <p>Note that the {@link #peek peek} method works equally well when
 367.164 + * a deque is used as a queue or a stack; in either case, elements are
 367.165 + * drawn from the beginning of the deque.
 367.166 + *
 367.167 + * <p>This interface provides two methods to remove interior
 367.168 + * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
 367.169 + * {@link #removeLastOccurrence removeLastOccurrence}.
 367.170 + *
 367.171 + * <p>Unlike the {@link List} interface, this interface does not
 367.172 + * provide support for indexed access to elements.
 367.173 + *
 367.174 + * <p>While <tt>Deque</tt> implementations are not strictly required
 367.175 + * to prohibit the insertion of null elements, they are strongly
 367.176 + * encouraged to do so.  Users of any <tt>Deque</tt> implementations
 367.177 + * that do allow null elements are strongly encouraged <i>not</i> to
 367.178 + * take advantage of the ability to insert nulls.  This is so because
 367.179 + * <tt>null</tt> is used as a special return value by various methods
 367.180 + * to indicated that the deque is empty.
 367.181 + *
 367.182 + * <p><tt>Deque</tt> implementations generally do not define
 367.183 + * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
 367.184 + * methods, but instead inherit the identity-based versions from class
 367.185 + * <tt>Object</tt>.
 367.186 + *
 367.187 + * <p>This interface is a member of the <a
 367.188 + * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
 367.189 + * Framework</a>.
 367.190 + *
 367.191 + * @author Doug Lea
 367.192 + * @author Josh Bloch
 367.193 + * @since  1.6
 367.194 + * @param <E> the type of elements held in this collection
 367.195 + */
 367.196 +
 367.197 +public interface Deque<E> extends Queue<E> {
 367.198 +    /**
 367.199 +     * Inserts the specified element at the front of this deque if it is
 367.200 +     * possible to do so immediately without violating capacity restrictions.
 367.201 +     * When using a capacity-restricted deque, it is generally preferable to
 367.202 +     * use method {@link #offerFirst}.
 367.203 +     *
 367.204 +     * @param e the element to add
 367.205 +     * @throws IllegalStateException if the element cannot be added at this
 367.206 +     *         time due to capacity restrictions
 367.207 +     * @throws ClassCastException if the class of the specified element
 367.208 +     *         prevents it from being added to this deque
 367.209 +     * @throws NullPointerException if the specified element is null and this
 367.210 +     *         deque does not permit null elements
 367.211 +     * @throws IllegalArgumentException if some property of the specified
 367.212 +     *         element prevents it from being added to this deque
 367.213 +     */
 367.214 +    void addFirst(E e);
 367.215 +
 367.216 +    /**
 367.217 +     * Inserts the specified element at the end of this deque if it is
 367.218 +     * possible to do so immediately without violating capacity restrictions.
 367.219 +     * When using a capacity-restricted deque, it is generally preferable to
 367.220 +     * use method {@link #offerLast}.
 367.221 +     *
 367.222 +     * <p>This method is equivalent to {@link #add}.
 367.223 +     *
 367.224 +     * @param e the element to add
 367.225 +     * @throws IllegalStateException if the element cannot be added at this
 367.226 +     *         time due to capacity restrictions
 367.227 +     * @throws ClassCastException if the class of the specified element
 367.228 +     *         prevents it from being added to this deque
 367.229 +     * @throws NullPointerException if the specified element is null and this
 367.230 +     *         deque does not permit null elements
 367.231 +     * @throws IllegalArgumentException if some property of the specified
 367.232 +     *         element prevents it from being added to this deque
 367.233 +     */
 367.234 +    void addLast(E e);
 367.235 +
 367.236 +    /**
 367.237 +     * Inserts the specified element at the front of this deque unless it would
 367.238 +     * violate capacity restrictions.  When using a capacity-restricted deque,
 367.239 +     * this method is generally preferable to the {@link #addFirst} method,
 367.240 +     * which can fail to insert an element only by throwing an exception.
 367.241 +     *
 367.242 +     * @param e the element to add
 367.243 +     * @return <tt>true</tt> if the element was added to this deque, else
 367.244 +     *         <tt>false</tt>
 367.245 +     * @throws ClassCastException if the class of the specified element
 367.246 +     *         prevents it from being added to this deque
 367.247 +     * @throws NullPointerException if the specified element is null and this
 367.248 +     *         deque does not permit null elements
 367.249 +     * @throws IllegalArgumentException if some property of the specified
 367.250 +     *         element prevents it from being added to this deque
 367.251 +     */
 367.252 +    boolean offerFirst(E e);
 367.253 +
 367.254 +    /**
 367.255 +     * Inserts the specified element at the end of this deque unless it would
 367.256 +     * violate capacity restrictions.  When using a capacity-restricted deque,
 367.257 +     * this method is generally preferable to the {@link #addLast} method,
 367.258 +     * which can fail to insert an element only by throwing an exception.
 367.259 +     *
 367.260 +     * @param e the element to add
 367.261 +     * @return <tt>true</tt> if the element was added to this deque, else
 367.262 +     *         <tt>false</tt>
 367.263 +     * @throws ClassCastException if the class of the specified element
 367.264 +     *         prevents it from being added to this deque
 367.265 +     * @throws NullPointerException if the specified element is null and this
 367.266 +     *         deque does not permit null elements
 367.267 +     * @throws IllegalArgumentException if some property of the specified
 367.268 +     *         element prevents it from being added to this deque
 367.269 +     */
 367.270 +    boolean offerLast(E e);
 367.271 +
 367.272 +    /**
 367.273 +     * Retrieves and removes the first element of this deque.  This method
 367.274 +     * differs from {@link #pollFirst pollFirst} only in that it throws an
 367.275 +     * exception if this deque is empty.
 367.276 +     *
 367.277 +     * @return the head of this deque
 367.278 +     * @throws NoSuchElementException if this deque is empty
 367.279 +     */
 367.280 +    E removeFirst();
 367.281 +
 367.282 +    /**
 367.283 +     * Retrieves and removes the last element of this deque.  This method
 367.284 +     * differs from {@link #pollLast pollLast} only in that it throws an
 367.285 +     * exception if this deque is empty.
 367.286 +     *
 367.287 +     * @return the tail of this deque
 367.288 +     * @throws NoSuchElementException if this deque is empty
 367.289 +     */
 367.290 +    E removeLast();
 367.291 +
 367.292 +    /**
 367.293 +     * Retrieves and removes the first element of this deque,
 367.294 +     * or returns <tt>null</tt> if this deque is empty.
 367.295 +     *
 367.296 +     * @return the head of this deque, or <tt>null</tt> if this deque is empty
 367.297 +     */
 367.298 +    E pollFirst();
 367.299 +
 367.300 +    /**
 367.301 +     * Retrieves and removes the last element of this deque,
 367.302 +     * or returns <tt>null</tt> if this deque is empty.
 367.303 +     *
 367.304 +     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
 367.305 +     */
 367.306 +    E pollLast();
 367.307 +
 367.308 +    /**
 367.309 +     * Retrieves, but does not remove, the first element of this deque.
 367.310 +     *
 367.311 +     * This method differs from {@link #peekFirst peekFirst} only in that it
 367.312 +     * throws an exception if this deque is empty.
 367.313 +     *
 367.314 +     * @return the head of this deque
 367.315 +     * @throws NoSuchElementException if this deque is empty
 367.316 +     */
 367.317 +    E getFirst();
 367.318 +
 367.319 +    /**
 367.320 +     * Retrieves, but does not remove, the last element of this deque.
 367.321 +     * This method differs from {@link #peekLast peekLast} only in that it
 367.322 +     * throws an exception if this deque is empty.
 367.323 +     *
 367.324 +     * @return the tail of this deque
 367.325 +     * @throws NoSuchElementException if this deque is empty
 367.326 +     */
 367.327 +    E getLast();
 367.328 +
 367.329 +    /**
 367.330 +     * Retrieves, but does not remove, the first element of this deque,
 367.331 +     * or returns <tt>null</tt> if this deque is empty.
 367.332 +     *
 367.333 +     * @return the head of this deque, or <tt>null</tt> if this deque is empty
 367.334 +     */
 367.335 +    E peekFirst();
 367.336 +
 367.337 +    /**
 367.338 +     * Retrieves, but does not remove, the last element of this deque,
 367.339 +     * or returns <tt>null</tt> if this deque is empty.
 367.340 +     *
 367.341 +     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
 367.342 +     */
 367.343 +    E peekLast();
 367.344 +
 367.345 +    /**
 367.346 +     * Removes the first occurrence of the specified element from this deque.
 367.347 +     * If the deque does not contain the element, it is unchanged.
 367.348 +     * More formally, removes the first element <tt>e</tt> such that
 367.349 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 367.350 +     * (if such an element exists).
 367.351 +     * Returns <tt>true</tt> if this deque contained the specified element
 367.352 +     * (or equivalently, if this deque changed as a result of the call).
 367.353 +     *
 367.354 +     * @param o element to be removed from this deque, if present
 367.355 +     * @return <tt>true</tt> if an element was removed as a result of this call
 367.356 +     * @throws ClassCastException if the class of the specified element
 367.357 +     *         is incompatible with this deque
 367.358 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.359 +     * @throws NullPointerException if the specified element is null and this
 367.360 +     *         deque does not permit null elements
 367.361 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.362 +     */
 367.363 +    boolean removeFirstOccurrence(Object o);
 367.364 +
 367.365 +    /**
 367.366 +     * Removes the last occurrence of the specified element from this deque.
 367.367 +     * If the deque does not contain the element, it is unchanged.
 367.368 +     * More formally, removes the last element <tt>e</tt> such that
 367.369 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 367.370 +     * (if such an element exists).
 367.371 +     * Returns <tt>true</tt> if this deque contained the specified element
 367.372 +     * (or equivalently, if this deque changed as a result of the call).
 367.373 +     *
 367.374 +     * @param o element to be removed from this deque, if present
 367.375 +     * @return <tt>true</tt> if an element was removed as a result of this call
 367.376 +     * @throws ClassCastException if the class of the specified element
 367.377 +     *         is incompatible with this deque
 367.378 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.379 +     * @throws NullPointerException if the specified element is null and this
 367.380 +     *         deque does not permit null elements
 367.381 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.382 +     */
 367.383 +    boolean removeLastOccurrence(Object o);
 367.384 +
 367.385 +    // *** Queue methods ***
 367.386 +
 367.387 +    /**
 367.388 +     * Inserts the specified element into the queue represented by this deque
 367.389 +     * (in other words, at the tail of this deque) if it is possible to do so
 367.390 +     * immediately without violating capacity restrictions, returning
 367.391 +     * <tt>true</tt> upon success and throwing an
 367.392 +     * <tt>IllegalStateException</tt> if no space is currently available.
 367.393 +     * When using a capacity-restricted deque, it is generally preferable to
 367.394 +     * use {@link #offer(Object) offer}.
 367.395 +     *
 367.396 +     * <p>This method is equivalent to {@link #addLast}.
 367.397 +     *
 367.398 +     * @param e the element to add
 367.399 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
 367.400 +     * @throws IllegalStateException if the element cannot be added at this
 367.401 +     *         time due to capacity restrictions
 367.402 +     * @throws ClassCastException if the class of the specified element
 367.403 +     *         prevents it from being added to this deque
 367.404 +     * @throws NullPointerException if the specified element is null and this
 367.405 +     *         deque does not permit null elements
 367.406 +     * @throws IllegalArgumentException if some property of the specified
 367.407 +     *         element prevents it from being added to this deque
 367.408 +     */
 367.409 +    boolean add(E e);
 367.410 +
 367.411 +    /**
 367.412 +     * Inserts the specified element into the queue represented by this deque
 367.413 +     * (in other words, at the tail of this deque) if it is possible to do so
 367.414 +     * immediately without violating capacity restrictions, returning
 367.415 +     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
 367.416 +     * available.  When using a capacity-restricted deque, this method is
 367.417 +     * generally preferable to the {@link #add} method, which can fail to
 367.418 +     * insert an element only by throwing an exception.
 367.419 +     *
 367.420 +     * <p>This method is equivalent to {@link #offerLast}.
 367.421 +     *
 367.422 +     * @param e the element to add
 367.423 +     * @return <tt>true</tt> if the element was added to this deque, else
 367.424 +     *         <tt>false</tt>
 367.425 +     * @throws ClassCastException if the class of the specified element
 367.426 +     *         prevents it from being added to this deque
 367.427 +     * @throws NullPointerException if the specified element is null and this
 367.428 +     *         deque does not permit null elements
 367.429 +     * @throws IllegalArgumentException if some property of the specified
 367.430 +     *         element prevents it from being added to this deque
 367.431 +     */
 367.432 +    boolean offer(E e);
 367.433 +
 367.434 +    /**
 367.435 +     * Retrieves and removes the head of the queue represented by this deque
 367.436 +     * (in other words, the first element of this deque).
 367.437 +     * This method differs from {@link #poll poll} only in that it throws an
 367.438 +     * exception if this deque is empty.
 367.439 +     *
 367.440 +     * <p>This method is equivalent to {@link #removeFirst()}.
 367.441 +     *
 367.442 +     * @return the head of the queue represented by this deque
 367.443 +     * @throws NoSuchElementException if this deque is empty
 367.444 +     */
 367.445 +    E remove();
 367.446 +
 367.447 +    /**
 367.448 +     * Retrieves and removes the head of the queue represented by this deque
 367.449 +     * (in other words, the first element of this deque), or returns
 367.450 +     * <tt>null</tt> if this deque is empty.
 367.451 +     *
 367.452 +     * <p>This method is equivalent to {@link #pollFirst()}.
 367.453 +     *
 367.454 +     * @return the first element of this deque, or <tt>null</tt> if
 367.455 +     *         this deque is empty
 367.456 +     */
 367.457 +    E poll();
 367.458 +
 367.459 +    /**
 367.460 +     * Retrieves, but does not remove, the head of the queue represented by
 367.461 +     * this deque (in other words, the first element of this deque).
 367.462 +     * This method differs from {@link #peek peek} only in that it throws an
 367.463 +     * exception if this deque is empty.
 367.464 +     *
 367.465 +     * <p>This method is equivalent to {@link #getFirst()}.
 367.466 +     *
 367.467 +     * @return the head of the queue represented by this deque
 367.468 +     * @throws NoSuchElementException if this deque is empty
 367.469 +     */
 367.470 +    E element();
 367.471 +
 367.472 +    /**
 367.473 +     * Retrieves, but does not remove, the head of the queue represented by
 367.474 +     * this deque (in other words, the first element of this deque), or
 367.475 +     * returns <tt>null</tt> if this deque is empty.
 367.476 +     *
 367.477 +     * <p>This method is equivalent to {@link #peekFirst()}.
 367.478 +     *
 367.479 +     * @return the head of the queue represented by this deque, or
 367.480 +     *         <tt>null</tt> if this deque is empty
 367.481 +     */
 367.482 +    E peek();
 367.483 +
 367.484 +
 367.485 +    // *** Stack methods ***
 367.486 +
 367.487 +    /**
 367.488 +     * Pushes an element onto the stack represented by this deque (in other
 367.489 +     * words, at the head of this deque) if it is possible to do so
 367.490 +     * immediately without violating capacity restrictions, returning
 367.491 +     * <tt>true</tt> upon success and throwing an
 367.492 +     * <tt>IllegalStateException</tt> if no space is currently available.
 367.493 +     *
 367.494 +     * <p>This method is equivalent to {@link #addFirst}.
 367.495 +     *
 367.496 +     * @param e the element to push
 367.497 +     * @throws IllegalStateException if the element cannot be added at this
 367.498 +     *         time due to capacity restrictions
 367.499 +     * @throws ClassCastException if the class of the specified element
 367.500 +     *         prevents it from being added to this deque
 367.501 +     * @throws NullPointerException if the specified element is null and this
 367.502 +     *         deque does not permit null elements
 367.503 +     * @throws IllegalArgumentException if some property of the specified
 367.504 +     *         element prevents it from being added to this deque
 367.505 +     */
 367.506 +    void push(E e);
 367.507 +
 367.508 +    /**
 367.509 +     * Pops an element from the stack represented by this deque.  In other
 367.510 +     * words, removes and returns the first element of this deque.
 367.511 +     *
 367.512 +     * <p>This method is equivalent to {@link #removeFirst()}.
 367.513 +     *
 367.514 +     * @return the element at the front of this deque (which is the top
 367.515 +     *         of the stack represented by this deque)
 367.516 +     * @throws NoSuchElementException if this deque is empty
 367.517 +     */
 367.518 +    E pop();
 367.519 +
 367.520 +
 367.521 +    // *** Collection methods ***
 367.522 +
 367.523 +    /**
 367.524 +     * Removes the first occurrence of the specified element from this deque.
 367.525 +     * If the deque does not contain the element, it is unchanged.
 367.526 +     * More formally, removes the first element <tt>e</tt> such that
 367.527 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 367.528 +     * (if such an element exists).
 367.529 +     * Returns <tt>true</tt> if this deque contained the specified element
 367.530 +     * (or equivalently, if this deque changed as a result of the call).
 367.531 +     *
 367.532 +     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
 367.533 +     *
 367.534 +     * @param o element to be removed from this deque, if present
 367.535 +     * @return <tt>true</tt> if an element was removed as a result of this call
 367.536 +     * @throws ClassCastException if the class of the specified element
 367.537 +     *         is incompatible with this deque
 367.538 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.539 +     * @throws NullPointerException if the specified element is null and this
 367.540 +     *         deque does not permit null elements
 367.541 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.542 +     */
 367.543 +    boolean remove(Object o);
 367.544 +
 367.545 +    /**
 367.546 +     * Returns <tt>true</tt> if this deque contains the specified element.
 367.547 +     * More formally, returns <tt>true</tt> if and only if this deque contains
 367.548 +     * at least one element <tt>e</tt> such that
 367.549 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 367.550 +     *
 367.551 +     * @param o element whose presence in this deque is to be tested
 367.552 +     * @return <tt>true</tt> if this deque contains the specified element
 367.553 +     * @throws ClassCastException if the type of the specified element
 367.554 +     *         is incompatible with this deque
 367.555 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.556 +     * @throws NullPointerException if the specified element is null and this
 367.557 +     *         deque does not permit null elements
 367.558 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 367.559 +     */
 367.560 +    boolean contains(Object o);
 367.561 +
 367.562 +    /**
 367.563 +     * Returns the number of elements in this deque.
 367.564 +     *
 367.565 +     * @return the number of elements in this deque
 367.566 +     */
 367.567 +    public int size();
 367.568 +
 367.569 +    /**
 367.570 +     * Returns an iterator over the elements in this deque in proper sequence.
 367.571 +     * The elements will be returned in order from first (head) to last (tail).
 367.572 +     *
 367.573 +     * @return an iterator over the elements in this deque in proper sequence
 367.574 +     */
 367.575 +    Iterator<E> iterator();
 367.576 +
 367.577 +    /**
 367.578 +     * Returns an iterator over the elements in this deque in reverse
 367.579 +     * sequential order.  The elements will be returned in order from
 367.580 +     * last (tail) to first (head).
 367.581 +     *
 367.582 +     * @return an iterator over the elements in this deque in reverse
 367.583 +     * sequence
 367.584 +     */
 367.585 +    Iterator<E> descendingIterator();
 367.586 +
 367.587 +}
   368.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   368.2 +++ b/rt/emul/compact/src/main/java/java/util/Dictionary.java	Wed Feb 27 11:24:58 2013 +0100
   368.3 @@ -0,0 +1,155 @@
   368.4 +/*
   368.5 + * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
   368.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   368.7 + *
   368.8 + * This code is free software; you can redistribute it and/or modify it
   368.9 + * under the terms of the GNU General Public License version 2 only, as
  368.10 + * published by the Free Software Foundation.  Oracle designates this
  368.11 + * particular file as subject to the "Classpath" exception as provided
  368.12 + * by Oracle in the LICENSE file that accompanied this code.
  368.13 + *
  368.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  368.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  368.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  368.17 + * version 2 for more details (a copy is included in the LICENSE file that
  368.18 + * accompanied this code).
  368.19 + *
  368.20 + * You should have received a copy of the GNU General Public License version
  368.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  368.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  368.23 + *
  368.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  368.25 + * or visit www.oracle.com if you need additional information or have any
  368.26 + * questions.
  368.27 + */
  368.28 +
  368.29 +package java.util;
  368.30 +
  368.31 +/**
  368.32 + * The <code>Dictionary</code> class is the abstract parent of any
  368.33 + * class, such as <code>Hashtable</code>, which maps keys to values.
  368.34 + * Every key and every value is an object. In any one <tt>Dictionary</tt>
  368.35 + * object, every key is associated with at most one value. Given a
  368.36 + * <tt>Dictionary</tt> and a key, the associated element can be looked up.
  368.37 + * Any non-<code>null</code> object can be used as a key and as a value.
  368.38 + * <p>
  368.39 + * As a rule, the <code>equals</code> method should be used by
  368.40 + * implementations of this class to decide if two keys are the same.
  368.41 + * <p>
  368.42 + * <strong>NOTE: This class is obsolete.  New implementations should
  368.43 + * implement the Map interface, rather than extending this class.</strong>
  368.44 + *
  368.45 + * @author  unascribed
  368.46 + * @see     java.util.Map
  368.47 + * @see     java.lang.Object#equals(java.lang.Object)
  368.48 + * @see     java.lang.Object#hashCode()
  368.49 + * @see     java.util.Hashtable
  368.50 + * @since   JDK1.0
  368.51 + */
  368.52 +public abstract
  368.53 +class Dictionary<K,V> {
  368.54 +    /**
  368.55 +     * Sole constructor.  (For invocation by subclass constructors, typically
  368.56 +     * implicit.)
  368.57 +     */
  368.58 +    public Dictionary() {
  368.59 +    }
  368.60 +
  368.61 +    /**
  368.62 +     * Returns the number of entries (distinct keys) in this dictionary.
  368.63 +     *
  368.64 +     * @return  the number of keys in this dictionary.
  368.65 +     */
  368.66 +    abstract public int size();
  368.67 +
  368.68 +    /**
  368.69 +     * Tests if this dictionary maps no keys to value. The general contract
  368.70 +     * for the <tt>isEmpty</tt> method is that the result is true if and only
  368.71 +     * if this dictionary contains no entries.
  368.72 +     *
  368.73 +     * @return  <code>true</code> if this dictionary maps no keys to values;
  368.74 +     *          <code>false</code> otherwise.
  368.75 +     */
  368.76 +    abstract public boolean isEmpty();
  368.77 +
  368.78 +    /**
  368.79 +     * Returns an enumeration of the keys in this dictionary. The general
  368.80 +     * contract for the keys method is that an <tt>Enumeration</tt> object
  368.81 +     * is returned that will generate all the keys for which this dictionary
  368.82 +     * contains entries.
  368.83 +     *
  368.84 +     * @return  an enumeration of the keys in this dictionary.
  368.85 +     * @see     java.util.Dictionary#elements()
  368.86 +     * @see     java.util.Enumeration
  368.87 +     */
  368.88 +    abstract public Enumeration<K> keys();
  368.89 +
  368.90 +    /**
  368.91 +     * Returns an enumeration of the values in this dictionary. The general
  368.92 +     * contract for the <tt>elements</tt> method is that an
  368.93 +     * <tt>Enumeration</tt> is returned that will generate all the elements
  368.94 +     * contained in entries in this dictionary.
  368.95 +     *
  368.96 +     * @return  an enumeration of the values in this dictionary.
  368.97 +     * @see     java.util.Dictionary#keys()
  368.98 +     * @see     java.util.Enumeration
  368.99 +     */
 368.100 +    abstract public Enumeration<V> elements();
 368.101 +
 368.102 +    /**
 368.103 +     * Returns the value to which the key is mapped in this dictionary.
 368.104 +     * The general contract for the <tt>isEmpty</tt> method is that if this
 368.105 +     * dictionary contains an entry for the specified key, the associated
 368.106 +     * value is returned; otherwise, <tt>null</tt> is returned.
 368.107 +     *
 368.108 +     * @return  the value to which the key is mapped in this dictionary;
 368.109 +     * @param   key   a key in this dictionary.
 368.110 +     *          <code>null</code> if the key is not mapped to any value in
 368.111 +     *          this dictionary.
 368.112 +     * @exception NullPointerException if the <tt>key</tt> is <tt>null</tt>.
 368.113 +     * @see     java.util.Dictionary#put(java.lang.Object, java.lang.Object)
 368.114 +     */
 368.115 +    abstract public V get(Object key);
 368.116 +
 368.117 +    /**
 368.118 +     * Maps the specified <code>key</code> to the specified
 368.119 +     * <code>value</code> in this dictionary. Neither the key nor the
 368.120 +     * value can be <code>null</code>.
 368.121 +     * <p>
 368.122 +     * If this dictionary already contains an entry for the specified
 368.123 +     * <tt>key</tt>, the value already in this dictionary for that
 368.124 +     * <tt>key</tt> is returned, after modifying the entry to contain the
 368.125 +     *  new element. <p>If this dictionary does not already have an entry
 368.126 +     *  for the specified <tt>key</tt>, an entry is created for the
 368.127 +     *  specified <tt>key</tt> and <tt>value</tt>, and <tt>null</tt> is
 368.128 +     *  returned.
 368.129 +     * <p>
 368.130 +     * The <code>value</code> can be retrieved by calling the
 368.131 +     * <code>get</code> method with a <code>key</code> that is equal to
 368.132 +     * the original <code>key</code>.
 368.133 +     *
 368.134 +     * @param      key     the hashtable key.
 368.135 +     * @param      value   the value.
 368.136 +     * @return     the previous value to which the <code>key</code> was mapped
 368.137 +     *             in this dictionary, or <code>null</code> if the key did not
 368.138 +     *             have a previous mapping.
 368.139 +     * @exception  NullPointerException  if the <code>key</code> or
 368.140 +     *               <code>value</code> is <code>null</code>.
 368.141 +     * @see        java.lang.Object#equals(java.lang.Object)
 368.142 +     * @see        java.util.Dictionary#get(java.lang.Object)
 368.143 +     */
 368.144 +    abstract public V put(K key, V value);
 368.145 +
 368.146 +    /**
 368.147 +     * Removes the <code>key</code> (and its corresponding
 368.148 +     * <code>value</code>) from this dictionary. This method does nothing
 368.149 +     * if the <code>key</code> is not in this dictionary.
 368.150 +     *
 368.151 +     * @param   key   the key that needs to be removed.
 368.152 +     * @return  the value to which the <code>key</code> had been mapped in this
 368.153 +     *          dictionary, or <code>null</code> if the key did not have a
 368.154 +     *          mapping.
 368.155 +     * @exception NullPointerException if <tt>key</tt> is <tt>null</tt>.
 368.156 +     */
 368.157 +    abstract public V remove(Object key);
 368.158 +}
   369.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   369.2 +++ b/rt/emul/compact/src/main/java/java/util/DualPivotQuicksort.java	Wed Feb 27 11:24:58 2013 +0100
   369.3 @@ -0,0 +1,3018 @@
   369.4 +/*
   369.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   369.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   369.7 + *
   369.8 + * This code is free software; you can redistribute it and/or modify it
   369.9 + * under the terms of the GNU General Public License version 2 only, as
  369.10 + * published by the Free Software Foundation.  Oracle designates this
  369.11 + * particular file as subject to the "Classpath" exception as provided
  369.12 + * by Oracle in the LICENSE file that accompanied this code.
  369.13 + *
  369.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  369.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  369.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  369.17 + * version 2 for more details (a copy is included in the LICENSE file that
  369.18 + * accompanied this code).
  369.19 + *
  369.20 + * You should have received a copy of the GNU General Public License version
  369.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  369.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  369.23 + *
  369.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  369.25 + * or visit www.oracle.com if you need additional information or have any
  369.26 + * questions.
  369.27 + */
  369.28 +
  369.29 +package java.util;
  369.30 +
  369.31 +/**
  369.32 + * This class implements the Dual-Pivot Quicksort algorithm by
  369.33 + * Vladimir Yaroslavskiy, Jon Bentley, and Josh Bloch. The algorithm
  369.34 + * offers O(n log(n)) performance on many data sets that cause other
  369.35 + * quicksorts to degrade to quadratic performance, and is typically
  369.36 + * faster than traditional (one-pivot) Quicksort implementations.
  369.37 + *
  369.38 + * @author Vladimir Yaroslavskiy
  369.39 + * @author Jon Bentley
  369.40 + * @author Josh Bloch
  369.41 + *
  369.42 + * @version 2011.02.11 m765.827.12i:5\7pm
  369.43 + * @since 1.7
  369.44 + */
  369.45 +final class DualPivotQuicksort {
  369.46 +
  369.47 +    /**
  369.48 +     * Prevents instantiation.
  369.49 +     */
  369.50 +    private DualPivotQuicksort() {}
  369.51 +
  369.52 +    /*
  369.53 +     * Tuning parameters.
  369.54 +     */
  369.55 +
  369.56 +    /**
  369.57 +     * The maximum number of runs in merge sort.
  369.58 +     */
  369.59 +    private static final int MAX_RUN_COUNT = 67;
  369.60 +
  369.61 +    /**
  369.62 +     * The maximum length of run in merge sort.
  369.63 +     */
  369.64 +    private static final int MAX_RUN_LENGTH = 33;
  369.65 +
  369.66 +    /**
  369.67 +     * If the length of an array to be sorted is less than this
  369.68 +     * constant, Quicksort is used in preference to merge sort.
  369.69 +     */
  369.70 +    private static final int QUICKSORT_THRESHOLD = 286;
  369.71 +
  369.72 +    /**
  369.73 +     * If the length of an array to be sorted is less than this
  369.74 +     * constant, insertion sort is used in preference to Quicksort.
  369.75 +     */
  369.76 +    private static final int INSERTION_SORT_THRESHOLD = 47;
  369.77 +
  369.78 +    /**
  369.79 +     * If the length of a byte array to be sorted is greater than this
  369.80 +     * constant, counting sort is used in preference to insertion sort.
  369.81 +     */
  369.82 +    private static final int COUNTING_SORT_THRESHOLD_FOR_BYTE = 29;
  369.83 +
  369.84 +    /**
  369.85 +     * If the length of a short or char array to be sorted is greater
  369.86 +     * than this constant, counting sort is used in preference to Quicksort.
  369.87 +     */
  369.88 +    private static final int COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR = 3200;
  369.89 +
  369.90 +    /*
  369.91 +     * Sorting methods for seven primitive types.
  369.92 +     */
  369.93 +
  369.94 +    /**
  369.95 +     * Sorts the specified array.
  369.96 +     *
  369.97 +     * @param a the array to be sorted
  369.98 +     */
  369.99 +    public static void sort(int[] a) {
 369.100 +        sort(a, 0, a.length - 1);
 369.101 +    }
 369.102 +
 369.103 +    /**
 369.104 +     * Sorts the specified range of the array.
 369.105 +     *
 369.106 +     * @param a the array to be sorted
 369.107 +     * @param left the index of the first element, inclusive, to be sorted
 369.108 +     * @param right the index of the last element, inclusive, to be sorted
 369.109 +     */
 369.110 +    public static void sort(int[] a, int left, int right) {
 369.111 +        // Use Quicksort on small arrays
 369.112 +        if (right - left < QUICKSORT_THRESHOLD) {
 369.113 +            sort(a, left, right, true);
 369.114 +            return;
 369.115 +        }
 369.116 +
 369.117 +        /*
 369.118 +         * Index run[i] is the start of i-th run
 369.119 +         * (ascending or descending sequence).
 369.120 +         */
 369.121 +        int[] run = new int[MAX_RUN_COUNT + 1];
 369.122 +        int count = 0; run[0] = left;
 369.123 +
 369.124 +        // Check if the array is nearly sorted
 369.125 +        for (int k = left; k < right; run[count] = k) {
 369.126 +            if (a[k] < a[k + 1]) { // ascending
 369.127 +                while (++k <= right && a[k - 1] <= a[k]);
 369.128 +            } else if (a[k] > a[k + 1]) { // descending
 369.129 +                while (++k <= right && a[k - 1] >= a[k]);
 369.130 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 369.131 +                    int t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 369.132 +                }
 369.133 +            } else { // equal
 369.134 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 369.135 +                    if (--m == 0) {
 369.136 +                        sort(a, left, right, true);
 369.137 +                        return;
 369.138 +                    }
 369.139 +                }
 369.140 +            }
 369.141 +
 369.142 +            /*
 369.143 +             * The array is not highly structured,
 369.144 +             * use Quicksort instead of merge sort.
 369.145 +             */
 369.146 +            if (++count == MAX_RUN_COUNT) {
 369.147 +                sort(a, left, right, true);
 369.148 +                return;
 369.149 +            }
 369.150 +        }
 369.151 +
 369.152 +        // Check special cases
 369.153 +        if (run[count] == right++) { // The last run contains one element
 369.154 +            run[++count] = right;
 369.155 +        } else if (count == 1) { // The array is already sorted
 369.156 +            return;
 369.157 +        }
 369.158 +
 369.159 +        /*
 369.160 +         * Create temporary array, which is used for merging.
 369.161 +         * Implementation note: variable "right" is increased by 1.
 369.162 +         */
 369.163 +        int[] b; byte odd = 0;
 369.164 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 369.165 +
 369.166 +        if (odd == 0) {
 369.167 +            b = a; a = new int[b.length];
 369.168 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
 369.169 +        } else {
 369.170 +            b = new int[a.length];
 369.171 +        }
 369.172 +
 369.173 +        // Merging
 369.174 +        for (int last; count > 1; count = last) {
 369.175 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
 369.176 +                int hi = run[k], mi = run[k - 1];
 369.177 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 369.178 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
 369.179 +                        b[i] = a[p++];
 369.180 +                    } else {
 369.181 +                        b[i] = a[q++];
 369.182 +                    }
 369.183 +                }
 369.184 +                run[++last] = hi;
 369.185 +            }
 369.186 +            if ((count & 1) != 0) {
 369.187 +                for (int i = right, lo = run[count - 1]; --i >= lo;
 369.188 +                    b[i] = a[i]
 369.189 +                );
 369.190 +                run[++last] = right;
 369.191 +            }
 369.192 +            int[] t = a; a = b; b = t;
 369.193 +        }
 369.194 +    }
 369.195 +
 369.196 +    /**
 369.197 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 369.198 +     *
 369.199 +     * @param a the array to be sorted
 369.200 +     * @param left the index of the first element, inclusive, to be sorted
 369.201 +     * @param right the index of the last element, inclusive, to be sorted
 369.202 +     * @param leftmost indicates if this part is the leftmost in the range
 369.203 +     */
 369.204 +    private static void sort(int[] a, int left, int right, boolean leftmost) {
 369.205 +        int length = right - left + 1;
 369.206 +
 369.207 +        // Use insertion sort on tiny arrays
 369.208 +        if (length < INSERTION_SORT_THRESHOLD) {
 369.209 +            if (leftmost) {
 369.210 +                /*
 369.211 +                 * Traditional (without sentinel) insertion sort,
 369.212 +                 * optimized for server VM, is used in case of
 369.213 +                 * the leftmost part.
 369.214 +                 */
 369.215 +                for (int i = left, j = i; i < right; j = ++i) {
 369.216 +                    int ai = a[i + 1];
 369.217 +                    while (ai < a[j]) {
 369.218 +                        a[j + 1] = a[j];
 369.219 +                        if (j-- == left) {
 369.220 +                            break;
 369.221 +                        }
 369.222 +                    }
 369.223 +                    a[j + 1] = ai;
 369.224 +                }
 369.225 +            } else {
 369.226 +                /*
 369.227 +                 * Skip the longest ascending sequence.
 369.228 +                 */
 369.229 +                do {
 369.230 +                    if (left >= right) {
 369.231 +                        return;
 369.232 +                    }
 369.233 +                } while (a[++left] >= a[left - 1]);
 369.234 +
 369.235 +                /*
 369.236 +                 * Every element from adjoining part plays the role
 369.237 +                 * of sentinel, therefore this allows us to avoid the
 369.238 +                 * left range check on each iteration. Moreover, we use
 369.239 +                 * the more optimized algorithm, so called pair insertion
 369.240 +                 * sort, which is faster (in the context of Quicksort)
 369.241 +                 * than traditional implementation of insertion sort.
 369.242 +                 */
 369.243 +                for (int k = left; ++left <= right; k = ++left) {
 369.244 +                    int a1 = a[k], a2 = a[left];
 369.245 +
 369.246 +                    if (a1 < a2) {
 369.247 +                        a2 = a1; a1 = a[left];
 369.248 +                    }
 369.249 +                    while (a1 < a[--k]) {
 369.250 +                        a[k + 2] = a[k];
 369.251 +                    }
 369.252 +                    a[++k + 1] = a1;
 369.253 +
 369.254 +                    while (a2 < a[--k]) {
 369.255 +                        a[k + 1] = a[k];
 369.256 +                    }
 369.257 +                    a[k + 1] = a2;
 369.258 +                }
 369.259 +                int last = a[right];
 369.260 +
 369.261 +                while (last < a[--right]) {
 369.262 +                    a[right + 1] = a[right];
 369.263 +                }
 369.264 +                a[right + 1] = last;
 369.265 +            }
 369.266 +            return;
 369.267 +        }
 369.268 +
 369.269 +        // Inexpensive approximation of length / 7
 369.270 +        int seventh = (length >> 3) + (length >> 6) + 1;
 369.271 +
 369.272 +        /*
 369.273 +         * Sort five evenly spaced elements around (and including) the
 369.274 +         * center element in the range. These elements will be used for
 369.275 +         * pivot selection as described below. The choice for spacing
 369.276 +         * these elements was empirically determined to work well on
 369.277 +         * a wide variety of inputs.
 369.278 +         */
 369.279 +        int e3 = (left + right) >>> 1; // The midpoint
 369.280 +        int e2 = e3 - seventh;
 369.281 +        int e1 = e2 - seventh;
 369.282 +        int e4 = e3 + seventh;
 369.283 +        int e5 = e4 + seventh;
 369.284 +
 369.285 +        // Sort these elements using insertion sort
 369.286 +        if (a[e2] < a[e1]) { int t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 369.287 +
 369.288 +        if (a[e3] < a[e2]) { int t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 369.289 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 369.290 +        }
 369.291 +        if (a[e4] < a[e3]) { int t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 369.292 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 369.293 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 369.294 +            }
 369.295 +        }
 369.296 +        if (a[e5] < a[e4]) { int t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 369.297 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 369.298 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 369.299 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 369.300 +                }
 369.301 +            }
 369.302 +        }
 369.303 +
 369.304 +        // Pointers
 369.305 +        int less  = left;  // The index of the first element of center part
 369.306 +        int great = right; // The index before the first element of right part
 369.307 +
 369.308 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 369.309 +            /*
 369.310 +             * Use the second and fourth of the five sorted elements as pivots.
 369.311 +             * These values are inexpensive approximations of the first and
 369.312 +             * second terciles of the array. Note that pivot1 <= pivot2.
 369.313 +             */
 369.314 +            int pivot1 = a[e2];
 369.315 +            int pivot2 = a[e4];
 369.316 +
 369.317 +            /*
 369.318 +             * The first and the last elements to be sorted are moved to the
 369.319 +             * locations formerly occupied by the pivots. When partitioning
 369.320 +             * is complete, the pivots are swapped back into their final
 369.321 +             * positions, and excluded from subsequent sorting.
 369.322 +             */
 369.323 +            a[e2] = a[left];
 369.324 +            a[e4] = a[right];
 369.325 +
 369.326 +            /*
 369.327 +             * Skip elements, which are less or greater than pivot values.
 369.328 +             */
 369.329 +            while (a[++less] < pivot1);
 369.330 +            while (a[--great] > pivot2);
 369.331 +
 369.332 +            /*
 369.333 +             * Partitioning:
 369.334 +             *
 369.335 +             *   left part           center part                   right part
 369.336 +             * +--------------------------------------------------------------+
 369.337 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 369.338 +             * +--------------------------------------------------------------+
 369.339 +             *               ^                          ^       ^
 369.340 +             *               |                          |       |
 369.341 +             *              less                        k     great
 369.342 +             *
 369.343 +             * Invariants:
 369.344 +             *
 369.345 +             *              all in (left, less)   < pivot1
 369.346 +             *    pivot1 <= all in [less, k)     <= pivot2
 369.347 +             *              all in (great, right) > pivot2
 369.348 +             *
 369.349 +             * Pointer k is the first index of ?-part.
 369.350 +             */
 369.351 +            outer:
 369.352 +            for (int k = less - 1; ++k <= great; ) {
 369.353 +                int ak = a[k];
 369.354 +                if (ak < pivot1) { // Move a[k] to left part
 369.355 +                    a[k] = a[less];
 369.356 +                    /*
 369.357 +                     * Here and below we use "a[i] = b; i++;" instead
 369.358 +                     * of "a[i++] = b;" due to performance issue.
 369.359 +                     */
 369.360 +                    a[less] = ak;
 369.361 +                    ++less;
 369.362 +                } else if (ak > pivot2) { // Move a[k] to right part
 369.363 +                    while (a[great] > pivot2) {
 369.364 +                        if (great-- == k) {
 369.365 +                            break outer;
 369.366 +                        }
 369.367 +                    }
 369.368 +                    if (a[great] < pivot1) { // a[great] <= pivot2
 369.369 +                        a[k] = a[less];
 369.370 +                        a[less] = a[great];
 369.371 +                        ++less;
 369.372 +                    } else { // pivot1 <= a[great] <= pivot2
 369.373 +                        a[k] = a[great];
 369.374 +                    }
 369.375 +                    /*
 369.376 +                     * Here and below we use "a[i] = b; i--;" instead
 369.377 +                     * of "a[i--] = b;" due to performance issue.
 369.378 +                     */
 369.379 +                    a[great] = ak;
 369.380 +                    --great;
 369.381 +                }
 369.382 +            }
 369.383 +
 369.384 +            // Swap pivots into their final positions
 369.385 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 369.386 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 369.387 +
 369.388 +            // Sort left and right parts recursively, excluding known pivots
 369.389 +            sort(a, left, less - 2, leftmost);
 369.390 +            sort(a, great + 2, right, false);
 369.391 +
 369.392 +            /*
 369.393 +             * If center part is too large (comprises > 4/7 of the array),
 369.394 +             * swap internal pivot values to ends.
 369.395 +             */
 369.396 +            if (less < e1 && e5 < great) {
 369.397 +                /*
 369.398 +                 * Skip elements, which are equal to pivot values.
 369.399 +                 */
 369.400 +                while (a[less] == pivot1) {
 369.401 +                    ++less;
 369.402 +                }
 369.403 +
 369.404 +                while (a[great] == pivot2) {
 369.405 +                    --great;
 369.406 +                }
 369.407 +
 369.408 +                /*
 369.409 +                 * Partitioning:
 369.410 +                 *
 369.411 +                 *   left part         center part                  right part
 369.412 +                 * +----------------------------------------------------------+
 369.413 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 369.414 +                 * +----------------------------------------------------------+
 369.415 +                 *              ^                        ^       ^
 369.416 +                 *              |                        |       |
 369.417 +                 *             less                      k     great
 369.418 +                 *
 369.419 +                 * Invariants:
 369.420 +                 *
 369.421 +                 *              all in (*,  less) == pivot1
 369.422 +                 *     pivot1 < all in [less,  k)  < pivot2
 369.423 +                 *              all in (great, *) == pivot2
 369.424 +                 *
 369.425 +                 * Pointer k is the first index of ?-part.
 369.426 +                 */
 369.427 +                outer:
 369.428 +                for (int k = less - 1; ++k <= great; ) {
 369.429 +                    int ak = a[k];
 369.430 +                    if (ak == pivot1) { // Move a[k] to left part
 369.431 +                        a[k] = a[less];
 369.432 +                        a[less] = ak;
 369.433 +                        ++less;
 369.434 +                    } else if (ak == pivot2) { // Move a[k] to right part
 369.435 +                        while (a[great] == pivot2) {
 369.436 +                            if (great-- == k) {
 369.437 +                                break outer;
 369.438 +                            }
 369.439 +                        }
 369.440 +                        if (a[great] == pivot1) { // a[great] < pivot2
 369.441 +                            a[k] = a[less];
 369.442 +                            /*
 369.443 +                             * Even though a[great] equals to pivot1, the
 369.444 +                             * assignment a[less] = pivot1 may be incorrect,
 369.445 +                             * if a[great] and pivot1 are floating-point zeros
 369.446 +                             * of different signs. Therefore in float and
 369.447 +                             * double sorting methods we have to use more
 369.448 +                             * accurate assignment a[less] = a[great].
 369.449 +                             */
 369.450 +                            a[less] = pivot1;
 369.451 +                            ++less;
 369.452 +                        } else { // pivot1 < a[great] < pivot2
 369.453 +                            a[k] = a[great];
 369.454 +                        }
 369.455 +                        a[great] = ak;
 369.456 +                        --great;
 369.457 +                    }
 369.458 +                }
 369.459 +            }
 369.460 +
 369.461 +            // Sort center part recursively
 369.462 +            sort(a, less, great, false);
 369.463 +
 369.464 +        } else { // Partitioning with one pivot
 369.465 +            /*
 369.466 +             * Use the third of the five sorted elements as pivot.
 369.467 +             * This value is inexpensive approximation of the median.
 369.468 +             */
 369.469 +            int pivot = a[e3];
 369.470 +
 369.471 +            /*
 369.472 +             * Partitioning degenerates to the traditional 3-way
 369.473 +             * (or "Dutch National Flag") schema:
 369.474 +             *
 369.475 +             *   left part    center part              right part
 369.476 +             * +-------------------------------------------------+
 369.477 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 369.478 +             * +-------------------------------------------------+
 369.479 +             *              ^              ^        ^
 369.480 +             *              |              |        |
 369.481 +             *             less            k      great
 369.482 +             *
 369.483 +             * Invariants:
 369.484 +             *
 369.485 +             *   all in (left, less)   < pivot
 369.486 +             *   all in [less, k)     == pivot
 369.487 +             *   all in (great, right) > pivot
 369.488 +             *
 369.489 +             * Pointer k is the first index of ?-part.
 369.490 +             */
 369.491 +            for (int k = less; k <= great; ++k) {
 369.492 +                if (a[k] == pivot) {
 369.493 +                    continue;
 369.494 +                }
 369.495 +                int ak = a[k];
 369.496 +                if (ak < pivot) { // Move a[k] to left part
 369.497 +                    a[k] = a[less];
 369.498 +                    a[less] = ak;
 369.499 +                    ++less;
 369.500 +                } else { // a[k] > pivot - Move a[k] to right part
 369.501 +                    while (a[great] > pivot) {
 369.502 +                        --great;
 369.503 +                    }
 369.504 +                    if (a[great] < pivot) { // a[great] <= pivot
 369.505 +                        a[k] = a[less];
 369.506 +                        a[less] = a[great];
 369.507 +                        ++less;
 369.508 +                    } else { // a[great] == pivot
 369.509 +                        /*
 369.510 +                         * Even though a[great] equals to pivot, the
 369.511 +                         * assignment a[k] = pivot may be incorrect,
 369.512 +                         * if a[great] and pivot are floating-point
 369.513 +                         * zeros of different signs. Therefore in float
 369.514 +                         * and double sorting methods we have to use
 369.515 +                         * more accurate assignment a[k] = a[great].
 369.516 +                         */
 369.517 +                        a[k] = pivot;
 369.518 +                    }
 369.519 +                    a[great] = ak;
 369.520 +                    --great;
 369.521 +                }
 369.522 +            }
 369.523 +
 369.524 +            /*
 369.525 +             * Sort left and right parts recursively.
 369.526 +             * All elements from center part are equal
 369.527 +             * and, therefore, already sorted.
 369.528 +             */
 369.529 +            sort(a, left, less - 1, leftmost);
 369.530 +            sort(a, great + 1, right, false);
 369.531 +        }
 369.532 +    }
 369.533 +
 369.534 +    /**
 369.535 +     * Sorts the specified array.
 369.536 +     *
 369.537 +     * @param a the array to be sorted
 369.538 +     */
 369.539 +    public static void sort(long[] a) {
 369.540 +        sort(a, 0, a.length - 1);
 369.541 +    }
 369.542 +
 369.543 +    /**
 369.544 +     * Sorts the specified range of the array.
 369.545 +     *
 369.546 +     * @param a the array to be sorted
 369.547 +     * @param left the index of the first element, inclusive, to be sorted
 369.548 +     * @param right the index of the last element, inclusive, to be sorted
 369.549 +     */
 369.550 +    public static void sort(long[] a, int left, int right) {
 369.551 +        // Use Quicksort on small arrays
 369.552 +        if (right - left < QUICKSORT_THRESHOLD) {
 369.553 +            sort(a, left, right, true);
 369.554 +            return;
 369.555 +        }
 369.556 +
 369.557 +        /*
 369.558 +         * Index run[i] is the start of i-th run
 369.559 +         * (ascending or descending sequence).
 369.560 +         */
 369.561 +        int[] run = new int[MAX_RUN_COUNT + 1];
 369.562 +        int count = 0; run[0] = left;
 369.563 +
 369.564 +        // Check if the array is nearly sorted
 369.565 +        for (int k = left; k < right; run[count] = k) {
 369.566 +            if (a[k] < a[k + 1]) { // ascending
 369.567 +                while (++k <= right && a[k - 1] <= a[k]);
 369.568 +            } else if (a[k] > a[k + 1]) { // descending
 369.569 +                while (++k <= right && a[k - 1] >= a[k]);
 369.570 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
 369.571 +                    long t = a[lo]; a[lo] = a[hi]; a[hi] = t;
 369.572 +                }
 369.573 +            } else { // equal
 369.574 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
 369.575 +                    if (--m == 0) {
 369.576 +                        sort(a, left, right, true);
 369.577 +                        return;
 369.578 +                    }
 369.579 +                }
 369.580 +            }
 369.581 +
 369.582 +            /*
 369.583 +             * The array is not highly structured,
 369.584 +             * use Quicksort instead of merge sort.
 369.585 +             */
 369.586 +            if (++count == MAX_RUN_COUNT) {
 369.587 +                sort(a, left, right, true);
 369.588 +                return;
 369.589 +            }
 369.590 +        }
 369.591 +
 369.592 +        // Check special cases
 369.593 +        if (run[count] == right++) { // The last run contains one element
 369.594 +            run[++count] = right;
 369.595 +        } else if (count == 1) { // The array is already sorted
 369.596 +            return;
 369.597 +        }
 369.598 +
 369.599 +        /*
 369.600 +         * Create temporary array, which is used for merging.
 369.601 +         * Implementation note: variable "right" is increased by 1.
 369.602 +         */
 369.603 +        long[] b; byte odd = 0;
 369.604 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
 369.605 +
 369.606 +        if (odd == 0) {
 369.607 +            b = a; a = new long[b.length];
 369.608 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
 369.609 +        } else {
 369.610 +            b = new long[a.length];
 369.611 +        }
 369.612 +
 369.613 +        // Merging
 369.614 +        for (int last; count > 1; count = last) {
 369.615 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
 369.616 +                int hi = run[k], mi = run[k - 1];
 369.617 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
 369.618 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
 369.619 +                        b[i] = a[p++];
 369.620 +                    } else {
 369.621 +                        b[i] = a[q++];
 369.622 +                    }
 369.623 +                }
 369.624 +                run[++last] = hi;
 369.625 +            }
 369.626 +            if ((count & 1) != 0) {
 369.627 +                for (int i = right, lo = run[count - 1]; --i >= lo;
 369.628 +                    b[i] = a[i]
 369.629 +                );
 369.630 +                run[++last] = right;
 369.631 +            }
 369.632 +            long[] t = a; a = b; b = t;
 369.633 +        }
 369.634 +    }
 369.635 +
 369.636 +    /**
 369.637 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
 369.638 +     *
 369.639 +     * @param a the array to be sorted
 369.640 +     * @param left the index of the first element, inclusive, to be sorted
 369.641 +     * @param right the index of the last element, inclusive, to be sorted
 369.642 +     * @param leftmost indicates if this part is the leftmost in the range
 369.643 +     */
 369.644 +    private static void sort(long[] a, int left, int right, boolean leftmost) {
 369.645 +        int length = right - left + 1;
 369.646 +
 369.647 +        // Use insertion sort on tiny arrays
 369.648 +        if (length < INSERTION_SORT_THRESHOLD) {
 369.649 +            if (leftmost) {
 369.650 +                /*
 369.651 +                 * Traditional (without sentinel) insertion sort,
 369.652 +                 * optimized for server VM, is used in case of
 369.653 +                 * the leftmost part.
 369.654 +                 */
 369.655 +                for (int i = left, j = i; i < right; j = ++i) {
 369.656 +                    long ai = a[i + 1];
 369.657 +                    while (ai < a[j]) {
 369.658 +                        a[j + 1] = a[j];
 369.659 +                        if (j-- == left) {
 369.660 +                            break;
 369.661 +                        }
 369.662 +                    }
 369.663 +                    a[j + 1] = ai;
 369.664 +                }
 369.665 +            } else {
 369.666 +                /*
 369.667 +                 * Skip the longest ascending sequence.
 369.668 +                 */
 369.669 +                do {
 369.670 +                    if (left >= right) {
 369.671 +                        return;
 369.672 +                    }
 369.673 +                } while (a[++left] >= a[left - 1]);
 369.674 +
 369.675 +                /*
 369.676 +                 * Every element from adjoining part plays the role
 369.677 +                 * of sentinel, therefore this allows us to avoid the
 369.678 +                 * left range check on each iteration. Moreover, we use
 369.679 +                 * the more optimized algorithm, so called pair insertion
 369.680 +                 * sort, which is faster (in the context of Quicksort)
 369.681 +                 * than traditional implementation of insertion sort.
 369.682 +                 */
 369.683 +                for (int k = left; ++left <= right; k = ++left) {
 369.684 +                    long a1 = a[k], a2 = a[left];
 369.685 +
 369.686 +                    if (a1 < a2) {
 369.687 +                        a2 = a1; a1 = a[left];
 369.688 +                    }
 369.689 +                    while (a1 < a[--k]) {
 369.690 +                        a[k + 2] = a[k];
 369.691 +                    }
 369.692 +                    a[++k + 1] = a1;
 369.693 +
 369.694 +                    while (a2 < a[--k]) {
 369.695 +                        a[k + 1] = a[k];
 369.696 +                    }
 369.697 +                    a[k + 1] = a2;
 369.698 +                }
 369.699 +                long last = a[right];
 369.700 +
 369.701 +                while (last < a[--right]) {
 369.702 +                    a[right + 1] = a[right];
 369.703 +                }
 369.704 +                a[right + 1] = last;
 369.705 +            }
 369.706 +            return;
 369.707 +        }
 369.708 +
 369.709 +        // Inexpensive approximation of length / 7
 369.710 +        int seventh = (length >> 3) + (length >> 6) + 1;
 369.711 +
 369.712 +        /*
 369.713 +         * Sort five evenly spaced elements around (and including) the
 369.714 +         * center element in the range. These elements will be used for
 369.715 +         * pivot selection as described below. The choice for spacing
 369.716 +         * these elements was empirically determined to work well on
 369.717 +         * a wide variety of inputs.
 369.718 +         */
 369.719 +        int e3 = (left + right) >>> 1; // The midpoint
 369.720 +        int e2 = e3 - seventh;
 369.721 +        int e1 = e2 - seventh;
 369.722 +        int e4 = e3 + seventh;
 369.723 +        int e5 = e4 + seventh;
 369.724 +
 369.725 +        // Sort these elements using insertion sort
 369.726 +        if (a[e2] < a[e1]) { long t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
 369.727 +
 369.728 +        if (a[e3] < a[e2]) { long t = a[e3]; a[e3] = a[e2]; a[e2] = t;
 369.729 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 369.730 +        }
 369.731 +        if (a[e4] < a[e3]) { long t = a[e4]; a[e4] = a[e3]; a[e3] = t;
 369.732 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 369.733 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 369.734 +            }
 369.735 +        }
 369.736 +        if (a[e5] < a[e4]) { long t = a[e5]; a[e5] = a[e4]; a[e4] = t;
 369.737 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
 369.738 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
 369.739 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
 369.740 +                }
 369.741 +            }
 369.742 +        }
 369.743 +
 369.744 +        // Pointers
 369.745 +        int less  = left;  // The index of the first element of center part
 369.746 +        int great = right; // The index before the first element of right part
 369.747 +
 369.748 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
 369.749 +            /*
 369.750 +             * Use the second and fourth of the five sorted elements as pivots.
 369.751 +             * These values are inexpensive approximations of the first and
 369.752 +             * second terciles of the array. Note that pivot1 <= pivot2.
 369.753 +             */
 369.754 +            long pivot1 = a[e2];
 369.755 +            long pivot2 = a[e4];
 369.756 +
 369.757 +            /*
 369.758 +             * The first and the last elements to be sorted are moved to the
 369.759 +             * locations formerly occupied by the pivots. When partitioning
 369.760 +             * is complete, the pivots are swapped back into their final
 369.761 +             * positions, and excluded from subsequent sorting.
 369.762 +             */
 369.763 +            a[e2] = a[left];
 369.764 +            a[e4] = a[right];
 369.765 +
 369.766 +            /*
 369.767 +             * Skip elements, which are less or greater than pivot values.
 369.768 +             */
 369.769 +            while (a[++less] < pivot1);
 369.770 +            while (a[--great] > pivot2);
 369.771 +
 369.772 +            /*
 369.773 +             * Partitioning:
 369.774 +             *
 369.775 +             *   left part           center part                   right part
 369.776 +             * +--------------------------------------------------------------+
 369.777 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
 369.778 +             * +--------------------------------------------------------------+
 369.779 +             *               ^                          ^       ^
 369.780 +             *               |                          |       |
 369.781 +             *              less                        k     great
 369.782 +             *
 369.783 +             * Invariants:
 369.784 +             *
 369.785 +             *              all in (left, less)   < pivot1
 369.786 +             *    pivot1 <= all in [less, k)     <= pivot2
 369.787 +             *              all in (great, right) > pivot2
 369.788 +             *
 369.789 +             * Pointer k is the first index of ?-part.
 369.790 +             */
 369.791 +            outer:
 369.792 +            for (int k = less - 1; ++k <= great; ) {
 369.793 +                long ak = a[k];
 369.794 +                if (ak < pivot1) { // Move a[k] to left part
 369.795 +                    a[k] = a[less];
 369.796 +                    /*
 369.797 +                     * Here and below we use "a[i] = b; i++;" instead
 369.798 +                     * of "a[i++] = b;" due to performance issue.
 369.799 +                     */
 369.800 +                    a[less] = ak;
 369.801 +                    ++less;
 369.802 +                } else if (ak > pivot2) { // Move a[k] to right part
 369.803 +                    while (a[great] > pivot2) {
 369.804 +                        if (great-- == k) {
 369.805 +                            break outer;
 369.806 +                        }
 369.807 +                    }
 369.808 +                    if (a[great] < pivot1) { // a[great] <= pivot2
 369.809 +                        a[k] = a[less];
 369.810 +                        a[less] = a[great];
 369.811 +                        ++less;
 369.812 +                    } else { // pivot1 <= a[great] <= pivot2
 369.813 +                        a[k] = a[great];
 369.814 +                    }
 369.815 +                    /*
 369.816 +                     * Here and below we use "a[i] = b; i--;" instead
 369.817 +                     * of "a[i--] = b;" due to performance issue.
 369.818 +                     */
 369.819 +                    a[great] = ak;
 369.820 +                    --great;
 369.821 +                }
 369.822 +            }
 369.823 +
 369.824 +            // Swap pivots into their final positions
 369.825 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
 369.826 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
 369.827 +
 369.828 +            // Sort left and right parts recursively, excluding known pivots
 369.829 +            sort(a, left, less - 2, leftmost);
 369.830 +            sort(a, great + 2, right, false);
 369.831 +
 369.832 +            /*
 369.833 +             * If center part is too large (comprises > 4/7 of the array),
 369.834 +             * swap internal pivot values to ends.
 369.835 +             */
 369.836 +            if (less < e1 && e5 < great) {
 369.837 +                /*
 369.838 +                 * Skip elements, which are equal to pivot values.
 369.839 +                 */
 369.840 +                while (a[less] == pivot1) {
 369.841 +                    ++less;
 369.842 +                }
 369.843 +
 369.844 +                while (a[great] == pivot2) {
 369.845 +                    --great;
 369.846 +                }
 369.847 +
 369.848 +                /*
 369.849 +                 * Partitioning:
 369.850 +                 *
 369.851 +                 *   left part         center part                  right part
 369.852 +                 * +----------------------------------------------------------+
 369.853 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
 369.854 +                 * +----------------------------------------------------------+
 369.855 +                 *              ^                        ^       ^
 369.856 +                 *              |                        |       |
 369.857 +                 *             less                      k     great
 369.858 +                 *
 369.859 +                 * Invariants:
 369.860 +                 *
 369.861 +                 *              all in (*,  less) == pivot1
 369.862 +                 *     pivot1 < all in [less,  k)  < pivot2
 369.863 +                 *              all in (great, *) == pivot2
 369.864 +                 *
 369.865 +                 * Pointer k is the first index of ?-part.
 369.866 +                 */
 369.867 +                outer:
 369.868 +                for (int k = less - 1; ++k <= great; ) {
 369.869 +                    long ak = a[k];
 369.870 +                    if (ak == pivot1) { // Move a[k] to left part
 369.871 +                        a[k] = a[less];
 369.872 +                        a[less] = ak;
 369.873 +                        ++less;
 369.874 +                    } else if (ak == pivot2) { // Move a[k] to right part
 369.875 +                        while (a[great] == pivot2) {
 369.876 +                            if (great-- == k) {
 369.877 +                                break outer;
 369.878 +                            }
 369.879 +                        }
 369.880 +                        if (a[great] == pivot1) { // a[great] < pivot2
 369.881 +                            a[k] = a[less];
 369.882 +                            /*
 369.883 +                             * Even though a[great] equals to pivot1, the
 369.884 +                             * assignment a[less] = pivot1 may be incorrect,
 369.885 +                             * if a[great] and pivot1 are floating-point zeros
 369.886 +                             * of different signs. Therefore in float and
 369.887 +                             * double sorting methods we have to use more
 369.888 +                             * accurate assignment a[less] = a[great].
 369.889 +                             */
 369.890 +                            a[less] = pivot1;
 369.891 +                            ++less;
 369.892 +                        } else { // pivot1 < a[great] < pivot2
 369.893 +                            a[k] = a[great];
 369.894 +                        }
 369.895 +                        a[great] = ak;
 369.896 +                        --great;
 369.897 +                    }
 369.898 +                }
 369.899 +            }
 369.900 +
 369.901 +            // Sort center part recursively
 369.902 +            sort(a, less, great, false);
 369.903 +
 369.904 +        } else { // Partitioning with one pivot
 369.905 +            /*
 369.906 +             * Use the third of the five sorted elements as pivot.
 369.907 +             * This value is inexpensive approximation of the median.
 369.908 +             */
 369.909 +            long pivot = a[e3];
 369.910 +
 369.911 +            /*
 369.912 +             * Partitioning degenerates to the traditional 3-way
 369.913 +             * (or "Dutch National Flag") schema:
 369.914 +             *
 369.915 +             *   left part    center part              right part
 369.916 +             * +-------------------------------------------------+
 369.917 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
 369.918 +             * +-------------------------------------------------+
 369.919 +             *              ^              ^        ^
 369.920 +             *              |              |        |
 369.921 +             *             less            k      great
 369.922 +             *
 369.923 +             * Invariants:
 369.924 +             *
 369.925 +             *   all in (left, less)   < pivot
 369.926 +             *   all in [less, k)     == pivot
 369.927 +             *   all in (great, right) > pivot
 369.928 +             *
 369.929 +             * Pointer k is the first index of ?-part.
 369.930 +             */
 369.931 +            for (int k = less; k <= great; ++k) {
 369.932 +                if (a[k] == pivot) {
 369.933 +                    continue;
 369.934 +                }
 369.935 +                long ak = a[k];
 369.936 +                if (ak < pivot) { // Move a[k] to left part
 369.937 +                    a[k] = a[less];
 369.938 +                    a[less] = ak;
 369.939 +                    ++less;
 369.940 +                } else { // a[k] > pivot - Move a[k] to right part
 369.941 +                    while (a[great] > pivot) {
 369.942 +                        --great;
 369.943 +                    }
 369.944 +                    if (a[great] < pivot) { // a[great] <= pivot
 369.945 +                        a[k] = a[less];
 369.946 +                        a[less] = a[great];
 369.947 +                        ++less;
 369.948 +                    } else { // a[great] == pivot
 369.949 +                        /*
 369.950 +                         * Even though a[great] equals to pivot, the
 369.951 +                         * assignment a[k] = pivot may be incorrect,
 369.952 +                         * if a[great] and pivot are floating-point
 369.953 +                         * zeros of different signs. Therefore in float
 369.954 +                         * and double sorting methods we have to use
 369.955 +                         * more accurate assignment a[k] = a[great].
 369.956 +                         */
 369.957 +                        a[k] = pivot;
 369.958 +                    }
 369.959 +                    a[great] = ak;
 369.960 +                    --great;
 369.961 +                }
 369.962 +            }
 369.963 +
 369.964 +            /*
 369.965 +             * Sort left and right parts recursively.
 369.966 +             * All elements from center part are equal
 369.967 +             * and, therefore, already sorted.
 369.968 +             */
 369.969 +            sort(a, left, less - 1, leftmost);
 369.970 +            sort(a, great + 1, right, false);
 369.971 +        }
 369.972 +    }
 369.973 +
 369.974 +    /**
 369.975 +     * Sorts the specified array.
 369.976 +     *
 369.977 +     * @param a the array to be sorted
 369.978 +     */
 369.979 +    public static void sort(short[] a) {
 369.980 +        sort(a, 0, a.length - 1);
 369.981 +    }
 369.982 +
 369.983 +    /**
 369.984 +     * Sorts the specified range of the array.
 369.985 +     *
 369.986 +     * @param a the array to be sorted
 369.987 +     * @param left the index of the first element, inclusive, to be sorted
 369.988 +     * @param right the index of the last element, inclusive, to be sorted
 369.989 +     */
 369.990 +    public static void sort(short[] a, int left, int right) {
 369.991 +        // Use counting sort on large arrays
 369.992 +        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
 369.993 +            int[] count = new int[NUM_SHORT_VALUES];
 369.994 +
 369.995 +            for (int i = left - 1; ++i <= right;
 369.996 +                count[a[i] - Short.MIN_VALUE]++
 369.997 +            );
 369.998 +            for (int i = NUM_SHORT_VALUES, k = right + 1; k > left; ) {
 369.999 +                while (count[--i] == 0);
369.1000 +                short value = (short) (i + Short.MIN_VALUE);
369.1001 +                int s = count[i];
369.1002 +
369.1003 +                do {
369.1004 +                    a[--k] = value;
369.1005 +                } while (--s > 0);
369.1006 +            }
369.1007 +        } else { // Use Dual-Pivot Quicksort on small arrays
369.1008 +            doSort(a, left, right);
369.1009 +        }
369.1010 +    }
369.1011 +
369.1012 +    /** The number of distinct short values. */
369.1013 +    private static final int NUM_SHORT_VALUES = 1 << 16;
369.1014 +
369.1015 +    /**
369.1016 +     * Sorts the specified range of the array.
369.1017 +     *
369.1018 +     * @param a the array to be sorted
369.1019 +     * @param left the index of the first element, inclusive, to be sorted
369.1020 +     * @param right the index of the last element, inclusive, to be sorted
369.1021 +     */
369.1022 +    private static void doSort(short[] a, int left, int right) {
369.1023 +        // Use Quicksort on small arrays
369.1024 +        if (right - left < QUICKSORT_THRESHOLD) {
369.1025 +            sort(a, left, right, true);
369.1026 +            return;
369.1027 +        }
369.1028 +
369.1029 +        /*
369.1030 +         * Index run[i] is the start of i-th run
369.1031 +         * (ascending or descending sequence).
369.1032 +         */
369.1033 +        int[] run = new int[MAX_RUN_COUNT + 1];
369.1034 +        int count = 0; run[0] = left;
369.1035 +
369.1036 +        // Check if the array is nearly sorted
369.1037 +        for (int k = left; k < right; run[count] = k) {
369.1038 +            if (a[k] < a[k + 1]) { // ascending
369.1039 +                while (++k <= right && a[k - 1] <= a[k]);
369.1040 +            } else if (a[k] > a[k + 1]) { // descending
369.1041 +                while (++k <= right && a[k - 1] >= a[k]);
369.1042 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
369.1043 +                    short t = a[lo]; a[lo] = a[hi]; a[hi] = t;
369.1044 +                }
369.1045 +            } else { // equal
369.1046 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
369.1047 +                    if (--m == 0) {
369.1048 +                        sort(a, left, right, true);
369.1049 +                        return;
369.1050 +                    }
369.1051 +                }
369.1052 +            }
369.1053 +
369.1054 +            /*
369.1055 +             * The array is not highly structured,
369.1056 +             * use Quicksort instead of merge sort.
369.1057 +             */
369.1058 +            if (++count == MAX_RUN_COUNT) {
369.1059 +                sort(a, left, right, true);
369.1060 +                return;
369.1061 +            }
369.1062 +        }
369.1063 +
369.1064 +        // Check special cases
369.1065 +        if (run[count] == right++) { // The last run contains one element
369.1066 +            run[++count] = right;
369.1067 +        } else if (count == 1) { // The array is already sorted
369.1068 +            return;
369.1069 +        }
369.1070 +
369.1071 +        /*
369.1072 +         * Create temporary array, which is used for merging.
369.1073 +         * Implementation note: variable "right" is increased by 1.
369.1074 +         */
369.1075 +        short[] b; byte odd = 0;
369.1076 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
369.1077 +
369.1078 +        if (odd == 0) {
369.1079 +            b = a; a = new short[b.length];
369.1080 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
369.1081 +        } else {
369.1082 +            b = new short[a.length];
369.1083 +        }
369.1084 +
369.1085 +        // Merging
369.1086 +        for (int last; count > 1; count = last) {
369.1087 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
369.1088 +                int hi = run[k], mi = run[k - 1];
369.1089 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
369.1090 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
369.1091 +                        b[i] = a[p++];
369.1092 +                    } else {
369.1093 +                        b[i] = a[q++];
369.1094 +                    }
369.1095 +                }
369.1096 +                run[++last] = hi;
369.1097 +            }
369.1098 +            if ((count & 1) != 0) {
369.1099 +                for (int i = right, lo = run[count - 1]; --i >= lo;
369.1100 +                    b[i] = a[i]
369.1101 +                );
369.1102 +                run[++last] = right;
369.1103 +            }
369.1104 +            short[] t = a; a = b; b = t;
369.1105 +        }
369.1106 +    }
369.1107 +
369.1108 +    /**
369.1109 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
369.1110 +     *
369.1111 +     * @param a the array to be sorted
369.1112 +     * @param left the index of the first element, inclusive, to be sorted
369.1113 +     * @param right the index of the last element, inclusive, to be sorted
369.1114 +     * @param leftmost indicates if this part is the leftmost in the range
369.1115 +     */
369.1116 +    private static void sort(short[] a, int left, int right, boolean leftmost) {
369.1117 +        int length = right - left + 1;
369.1118 +
369.1119 +        // Use insertion sort on tiny arrays
369.1120 +        if (length < INSERTION_SORT_THRESHOLD) {
369.1121 +            if (leftmost) {
369.1122 +                /*
369.1123 +                 * Traditional (without sentinel) insertion sort,
369.1124 +                 * optimized for server VM, is used in case of
369.1125 +                 * the leftmost part.
369.1126 +                 */
369.1127 +                for (int i = left, j = i; i < right; j = ++i) {
369.1128 +                    short ai = a[i + 1];
369.1129 +                    while (ai < a[j]) {
369.1130 +                        a[j + 1] = a[j];
369.1131 +                        if (j-- == left) {
369.1132 +                            break;
369.1133 +                        }
369.1134 +                    }
369.1135 +                    a[j + 1] = ai;
369.1136 +                }
369.1137 +            } else {
369.1138 +                /*
369.1139 +                 * Skip the longest ascending sequence.
369.1140 +                 */
369.1141 +                do {
369.1142 +                    if (left >= right) {
369.1143 +                        return;
369.1144 +                    }
369.1145 +                } while (a[++left] >= a[left - 1]);
369.1146 +
369.1147 +                /*
369.1148 +                 * Every element from adjoining part plays the role
369.1149 +                 * of sentinel, therefore this allows us to avoid the
369.1150 +                 * left range check on each iteration. Moreover, we use
369.1151 +                 * the more optimized algorithm, so called pair insertion
369.1152 +                 * sort, which is faster (in the context of Quicksort)
369.1153 +                 * than traditional implementation of insertion sort.
369.1154 +                 */
369.1155 +                for (int k = left; ++left <= right; k = ++left) {
369.1156 +                    short a1 = a[k], a2 = a[left];
369.1157 +
369.1158 +                    if (a1 < a2) {
369.1159 +                        a2 = a1; a1 = a[left];
369.1160 +                    }
369.1161 +                    while (a1 < a[--k]) {
369.1162 +                        a[k + 2] = a[k];
369.1163 +                    }
369.1164 +                    a[++k + 1] = a1;
369.1165 +
369.1166 +                    while (a2 < a[--k]) {
369.1167 +                        a[k + 1] = a[k];
369.1168 +                    }
369.1169 +                    a[k + 1] = a2;
369.1170 +                }
369.1171 +                short last = a[right];
369.1172 +
369.1173 +                while (last < a[--right]) {
369.1174 +                    a[right + 1] = a[right];
369.1175 +                }
369.1176 +                a[right + 1] = last;
369.1177 +            }
369.1178 +            return;
369.1179 +        }
369.1180 +
369.1181 +        // Inexpensive approximation of length / 7
369.1182 +        int seventh = (length >> 3) + (length >> 6) + 1;
369.1183 +
369.1184 +        /*
369.1185 +         * Sort five evenly spaced elements around (and including) the
369.1186 +         * center element in the range. These elements will be used for
369.1187 +         * pivot selection as described below. The choice for spacing
369.1188 +         * these elements was empirically determined to work well on
369.1189 +         * a wide variety of inputs.
369.1190 +         */
369.1191 +        int e3 = (left + right) >>> 1; // The midpoint
369.1192 +        int e2 = e3 - seventh;
369.1193 +        int e1 = e2 - seventh;
369.1194 +        int e4 = e3 + seventh;
369.1195 +        int e5 = e4 + seventh;
369.1196 +
369.1197 +        // Sort these elements using insertion sort
369.1198 +        if (a[e2] < a[e1]) { short t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
369.1199 +
369.1200 +        if (a[e3] < a[e2]) { short t = a[e3]; a[e3] = a[e2]; a[e2] = t;
369.1201 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.1202 +        }
369.1203 +        if (a[e4] < a[e3]) { short t = a[e4]; a[e4] = a[e3]; a[e3] = t;
369.1204 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.1205 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.1206 +            }
369.1207 +        }
369.1208 +        if (a[e5] < a[e4]) { short t = a[e5]; a[e5] = a[e4]; a[e4] = t;
369.1209 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
369.1210 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.1211 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.1212 +                }
369.1213 +            }
369.1214 +        }
369.1215 +
369.1216 +        // Pointers
369.1217 +        int less  = left;  // The index of the first element of center part
369.1218 +        int great = right; // The index before the first element of right part
369.1219 +
369.1220 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
369.1221 +            /*
369.1222 +             * Use the second and fourth of the five sorted elements as pivots.
369.1223 +             * These values are inexpensive approximations of the first and
369.1224 +             * second terciles of the array. Note that pivot1 <= pivot2.
369.1225 +             */
369.1226 +            short pivot1 = a[e2];
369.1227 +            short pivot2 = a[e4];
369.1228 +
369.1229 +            /*
369.1230 +             * The first and the last elements to be sorted are moved to the
369.1231 +             * locations formerly occupied by the pivots. When partitioning
369.1232 +             * is complete, the pivots are swapped back into their final
369.1233 +             * positions, and excluded from subsequent sorting.
369.1234 +             */
369.1235 +            a[e2] = a[left];
369.1236 +            a[e4] = a[right];
369.1237 +
369.1238 +            /*
369.1239 +             * Skip elements, which are less or greater than pivot values.
369.1240 +             */
369.1241 +            while (a[++less] < pivot1);
369.1242 +            while (a[--great] > pivot2);
369.1243 +
369.1244 +            /*
369.1245 +             * Partitioning:
369.1246 +             *
369.1247 +             *   left part           center part                   right part
369.1248 +             * +--------------------------------------------------------------+
369.1249 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
369.1250 +             * +--------------------------------------------------------------+
369.1251 +             *               ^                          ^       ^
369.1252 +             *               |                          |       |
369.1253 +             *              less                        k     great
369.1254 +             *
369.1255 +             * Invariants:
369.1256 +             *
369.1257 +             *              all in (left, less)   < pivot1
369.1258 +             *    pivot1 <= all in [less, k)     <= pivot2
369.1259 +             *              all in (great, right) > pivot2
369.1260 +             *
369.1261 +             * Pointer k is the first index of ?-part.
369.1262 +             */
369.1263 +            outer:
369.1264 +            for (int k = less - 1; ++k <= great; ) {
369.1265 +                short ak = a[k];
369.1266 +                if (ak < pivot1) { // Move a[k] to left part
369.1267 +                    a[k] = a[less];
369.1268 +                    /*
369.1269 +                     * Here and below we use "a[i] = b; i++;" instead
369.1270 +                     * of "a[i++] = b;" due to performance issue.
369.1271 +                     */
369.1272 +                    a[less] = ak;
369.1273 +                    ++less;
369.1274 +                } else if (ak > pivot2) { // Move a[k] to right part
369.1275 +                    while (a[great] > pivot2) {
369.1276 +                        if (great-- == k) {
369.1277 +                            break outer;
369.1278 +                        }
369.1279 +                    }
369.1280 +                    if (a[great] < pivot1) { // a[great] <= pivot2
369.1281 +                        a[k] = a[less];
369.1282 +                        a[less] = a[great];
369.1283 +                        ++less;
369.1284 +                    } else { // pivot1 <= a[great] <= pivot2
369.1285 +                        a[k] = a[great];
369.1286 +                    }
369.1287 +                    /*
369.1288 +                     * Here and below we use "a[i] = b; i--;" instead
369.1289 +                     * of "a[i--] = b;" due to performance issue.
369.1290 +                     */
369.1291 +                    a[great] = ak;
369.1292 +                    --great;
369.1293 +                }
369.1294 +            }
369.1295 +
369.1296 +            // Swap pivots into their final positions
369.1297 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
369.1298 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
369.1299 +
369.1300 +            // Sort left and right parts recursively, excluding known pivots
369.1301 +            sort(a, left, less - 2, leftmost);
369.1302 +            sort(a, great + 2, right, false);
369.1303 +
369.1304 +            /*
369.1305 +             * If center part is too large (comprises > 4/7 of the array),
369.1306 +             * swap internal pivot values to ends.
369.1307 +             */
369.1308 +            if (less < e1 && e5 < great) {
369.1309 +                /*
369.1310 +                 * Skip elements, which are equal to pivot values.
369.1311 +                 */
369.1312 +                while (a[less] == pivot1) {
369.1313 +                    ++less;
369.1314 +                }
369.1315 +
369.1316 +                while (a[great] == pivot2) {
369.1317 +                    --great;
369.1318 +                }
369.1319 +
369.1320 +                /*
369.1321 +                 * Partitioning:
369.1322 +                 *
369.1323 +                 *   left part         center part                  right part
369.1324 +                 * +----------------------------------------------------------+
369.1325 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
369.1326 +                 * +----------------------------------------------------------+
369.1327 +                 *              ^                        ^       ^
369.1328 +                 *              |                        |       |
369.1329 +                 *             less                      k     great
369.1330 +                 *
369.1331 +                 * Invariants:
369.1332 +                 *
369.1333 +                 *              all in (*,  less) == pivot1
369.1334 +                 *     pivot1 < all in [less,  k)  < pivot2
369.1335 +                 *              all in (great, *) == pivot2
369.1336 +                 *
369.1337 +                 * Pointer k is the first index of ?-part.
369.1338 +                 */
369.1339 +                outer:
369.1340 +                for (int k = less - 1; ++k <= great; ) {
369.1341 +                    short ak = a[k];
369.1342 +                    if (ak == pivot1) { // Move a[k] to left part
369.1343 +                        a[k] = a[less];
369.1344 +                        a[less] = ak;
369.1345 +                        ++less;
369.1346 +                    } else if (ak == pivot2) { // Move a[k] to right part
369.1347 +                        while (a[great] == pivot2) {
369.1348 +                            if (great-- == k) {
369.1349 +                                break outer;
369.1350 +                            }
369.1351 +                        }
369.1352 +                        if (a[great] == pivot1) { // a[great] < pivot2
369.1353 +                            a[k] = a[less];
369.1354 +                            /*
369.1355 +                             * Even though a[great] equals to pivot1, the
369.1356 +                             * assignment a[less] = pivot1 may be incorrect,
369.1357 +                             * if a[great] and pivot1 are floating-point zeros
369.1358 +                             * of different signs. Therefore in float and
369.1359 +                             * double sorting methods we have to use more
369.1360 +                             * accurate assignment a[less] = a[great].
369.1361 +                             */
369.1362 +                            a[less] = pivot1;
369.1363 +                            ++less;
369.1364 +                        } else { // pivot1 < a[great] < pivot2
369.1365 +                            a[k] = a[great];
369.1366 +                        }
369.1367 +                        a[great] = ak;
369.1368 +                        --great;
369.1369 +                    }
369.1370 +                }
369.1371 +            }
369.1372 +
369.1373 +            // Sort center part recursively
369.1374 +            sort(a, less, great, false);
369.1375 +
369.1376 +        } else { // Partitioning with one pivot
369.1377 +            /*
369.1378 +             * Use the third of the five sorted elements as pivot.
369.1379 +             * This value is inexpensive approximation of the median.
369.1380 +             */
369.1381 +            short pivot = a[e3];
369.1382 +
369.1383 +            /*
369.1384 +             * Partitioning degenerates to the traditional 3-way
369.1385 +             * (or "Dutch National Flag") schema:
369.1386 +             *
369.1387 +             *   left part    center part              right part
369.1388 +             * +-------------------------------------------------+
369.1389 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
369.1390 +             * +-------------------------------------------------+
369.1391 +             *              ^              ^        ^
369.1392 +             *              |              |        |
369.1393 +             *             less            k      great
369.1394 +             *
369.1395 +             * Invariants:
369.1396 +             *
369.1397 +             *   all in (left, less)   < pivot
369.1398 +             *   all in [less, k)     == pivot
369.1399 +             *   all in (great, right) > pivot
369.1400 +             *
369.1401 +             * Pointer k is the first index of ?-part.
369.1402 +             */
369.1403 +            for (int k = less; k <= great; ++k) {
369.1404 +                if (a[k] == pivot) {
369.1405 +                    continue;
369.1406 +                }
369.1407 +                short ak = a[k];
369.1408 +                if (ak < pivot) { // Move a[k] to left part
369.1409 +                    a[k] = a[less];
369.1410 +                    a[less] = ak;
369.1411 +                    ++less;
369.1412 +                } else { // a[k] > pivot - Move a[k] to right part
369.1413 +                    while (a[great] > pivot) {
369.1414 +                        --great;
369.1415 +                    }
369.1416 +                    if (a[great] < pivot) { // a[great] <= pivot
369.1417 +                        a[k] = a[less];
369.1418 +                        a[less] = a[great];
369.1419 +                        ++less;
369.1420 +                    } else { // a[great] == pivot
369.1421 +                        /*
369.1422 +                         * Even though a[great] equals to pivot, the
369.1423 +                         * assignment a[k] = pivot may be incorrect,
369.1424 +                         * if a[great] and pivot are floating-point
369.1425 +                         * zeros of different signs. Therefore in float
369.1426 +                         * and double sorting methods we have to use
369.1427 +                         * more accurate assignment a[k] = a[great].
369.1428 +                         */
369.1429 +                        a[k] = pivot;
369.1430 +                    }
369.1431 +                    a[great] = ak;
369.1432 +                    --great;
369.1433 +                }
369.1434 +            }
369.1435 +
369.1436 +            /*
369.1437 +             * Sort left and right parts recursively.
369.1438 +             * All elements from center part are equal
369.1439 +             * and, therefore, already sorted.
369.1440 +             */
369.1441 +            sort(a, left, less - 1, leftmost);
369.1442 +            sort(a, great + 1, right, false);
369.1443 +        }
369.1444 +    }
369.1445 +
369.1446 +    /**
369.1447 +     * Sorts the specified array.
369.1448 +     *
369.1449 +     * @param a the array to be sorted
369.1450 +     */
369.1451 +    public static void sort(char[] a) {
369.1452 +        sort(a, 0, a.length - 1);
369.1453 +    }
369.1454 +
369.1455 +    /**
369.1456 +     * Sorts the specified range of the array.
369.1457 +     *
369.1458 +     * @param a the array to be sorted
369.1459 +     * @param left the index of the first element, inclusive, to be sorted
369.1460 +     * @param right the index of the last element, inclusive, to be sorted
369.1461 +     */
369.1462 +    public static void sort(char[] a, int left, int right) {
369.1463 +        // Use counting sort on large arrays
369.1464 +        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
369.1465 +            int[] count = new int[NUM_CHAR_VALUES];
369.1466 +
369.1467 +            for (int i = left - 1; ++i <= right;
369.1468 +                count[a[i]]++
369.1469 +            );
369.1470 +            for (int i = NUM_CHAR_VALUES, k = right + 1; k > left; ) {
369.1471 +                while (count[--i] == 0);
369.1472 +                char value = (char) i;
369.1473 +                int s = count[i];
369.1474 +
369.1475 +                do {
369.1476 +                    a[--k] = value;
369.1477 +                } while (--s > 0);
369.1478 +            }
369.1479 +        } else { // Use Dual-Pivot Quicksort on small arrays
369.1480 +            doSort(a, left, right);
369.1481 +        }
369.1482 +    }
369.1483 +
369.1484 +    /** The number of distinct char values. */
369.1485 +    private static final int NUM_CHAR_VALUES = 1 << 16;
369.1486 +
369.1487 +    /**
369.1488 +     * Sorts the specified range of the array.
369.1489 +     *
369.1490 +     * @param a the array to be sorted
369.1491 +     * @param left the index of the first element, inclusive, to be sorted
369.1492 +     * @param right the index of the last element, inclusive, to be sorted
369.1493 +     */
369.1494 +    private static void doSort(char[] a, int left, int right) {
369.1495 +        // Use Quicksort on small arrays
369.1496 +        if (right - left < QUICKSORT_THRESHOLD) {
369.1497 +            sort(a, left, right, true);
369.1498 +            return;
369.1499 +        }
369.1500 +
369.1501 +        /*
369.1502 +         * Index run[i] is the start of i-th run
369.1503 +         * (ascending or descending sequence).
369.1504 +         */
369.1505 +        int[] run = new int[MAX_RUN_COUNT + 1];
369.1506 +        int count = 0; run[0] = left;
369.1507 +
369.1508 +        // Check if the array is nearly sorted
369.1509 +        for (int k = left; k < right; run[count] = k) {
369.1510 +            if (a[k] < a[k + 1]) { // ascending
369.1511 +                while (++k <= right && a[k - 1] <= a[k]);
369.1512 +            } else if (a[k] > a[k + 1]) { // descending
369.1513 +                while (++k <= right && a[k - 1] >= a[k]);
369.1514 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
369.1515 +                    char t = a[lo]; a[lo] = a[hi]; a[hi] = t;
369.1516 +                }
369.1517 +            } else { // equal
369.1518 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
369.1519 +                    if (--m == 0) {
369.1520 +                        sort(a, left, right, true);
369.1521 +                        return;
369.1522 +                    }
369.1523 +                }
369.1524 +            }
369.1525 +
369.1526 +            /*
369.1527 +             * The array is not highly structured,
369.1528 +             * use Quicksort instead of merge sort.
369.1529 +             */
369.1530 +            if (++count == MAX_RUN_COUNT) {
369.1531 +                sort(a, left, right, true);
369.1532 +                return;
369.1533 +            }
369.1534 +        }
369.1535 +
369.1536 +        // Check special cases
369.1537 +        if (run[count] == right++) { // The last run contains one element
369.1538 +            run[++count] = right;
369.1539 +        } else if (count == 1) { // The array is already sorted
369.1540 +            return;
369.1541 +        }
369.1542 +
369.1543 +        /*
369.1544 +         * Create temporary array, which is used for merging.
369.1545 +         * Implementation note: variable "right" is increased by 1.
369.1546 +         */
369.1547 +        char[] b; byte odd = 0;
369.1548 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
369.1549 +
369.1550 +        if (odd == 0) {
369.1551 +            b = a; a = new char[b.length];
369.1552 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
369.1553 +        } else {
369.1554 +            b = new char[a.length];
369.1555 +        }
369.1556 +
369.1557 +        // Merging
369.1558 +        for (int last; count > 1; count = last) {
369.1559 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
369.1560 +                int hi = run[k], mi = run[k - 1];
369.1561 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
369.1562 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
369.1563 +                        b[i] = a[p++];
369.1564 +                    } else {
369.1565 +                        b[i] = a[q++];
369.1566 +                    }
369.1567 +                }
369.1568 +                run[++last] = hi;
369.1569 +            }
369.1570 +            if ((count & 1) != 0) {
369.1571 +                for (int i = right, lo = run[count - 1]; --i >= lo;
369.1572 +                    b[i] = a[i]
369.1573 +                );
369.1574 +                run[++last] = right;
369.1575 +            }
369.1576 +            char[] t = a; a = b; b = t;
369.1577 +        }
369.1578 +    }
369.1579 +
369.1580 +    /**
369.1581 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
369.1582 +     *
369.1583 +     * @param a the array to be sorted
369.1584 +     * @param left the index of the first element, inclusive, to be sorted
369.1585 +     * @param right the index of the last element, inclusive, to be sorted
369.1586 +     * @param leftmost indicates if this part is the leftmost in the range
369.1587 +     */
369.1588 +    private static void sort(char[] a, int left, int right, boolean leftmost) {
369.1589 +        int length = right - left + 1;
369.1590 +
369.1591 +        // Use insertion sort on tiny arrays
369.1592 +        if (length < INSERTION_SORT_THRESHOLD) {
369.1593 +            if (leftmost) {
369.1594 +                /*
369.1595 +                 * Traditional (without sentinel) insertion sort,
369.1596 +                 * optimized for server VM, is used in case of
369.1597 +                 * the leftmost part.
369.1598 +                 */
369.1599 +                for (int i = left, j = i; i < right; j = ++i) {
369.1600 +                    char ai = a[i + 1];
369.1601 +                    while (ai < a[j]) {
369.1602 +                        a[j + 1] = a[j];
369.1603 +                        if (j-- == left) {
369.1604 +                            break;
369.1605 +                        }
369.1606 +                    }
369.1607 +                    a[j + 1] = ai;
369.1608 +                }
369.1609 +            } else {
369.1610 +                /*
369.1611 +                 * Skip the longest ascending sequence.
369.1612 +                 */
369.1613 +                do {
369.1614 +                    if (left >= right) {
369.1615 +                        return;
369.1616 +                    }
369.1617 +                } while (a[++left] >= a[left - 1]);
369.1618 +
369.1619 +                /*
369.1620 +                 * Every element from adjoining part plays the role
369.1621 +                 * of sentinel, therefore this allows us to avoid the
369.1622 +                 * left range check on each iteration. Moreover, we use
369.1623 +                 * the more optimized algorithm, so called pair insertion
369.1624 +                 * sort, which is faster (in the context of Quicksort)
369.1625 +                 * than traditional implementation of insertion sort.
369.1626 +                 */
369.1627 +                for (int k = left; ++left <= right; k = ++left) {
369.1628 +                    char a1 = a[k], a2 = a[left];
369.1629 +
369.1630 +                    if (a1 < a2) {
369.1631 +                        a2 = a1; a1 = a[left];
369.1632 +                    }
369.1633 +                    while (a1 < a[--k]) {
369.1634 +                        a[k + 2] = a[k];
369.1635 +                    }
369.1636 +                    a[++k + 1] = a1;
369.1637 +
369.1638 +                    while (a2 < a[--k]) {
369.1639 +                        a[k + 1] = a[k];
369.1640 +                    }
369.1641 +                    a[k + 1] = a2;
369.1642 +                }
369.1643 +                char last = a[right];
369.1644 +
369.1645 +                while (last < a[--right]) {
369.1646 +                    a[right + 1] = a[right];
369.1647 +                }
369.1648 +                a[right + 1] = last;
369.1649 +            }
369.1650 +            return;
369.1651 +        }
369.1652 +
369.1653 +        // Inexpensive approximation of length / 7
369.1654 +        int seventh = (length >> 3) + (length >> 6) + 1;
369.1655 +
369.1656 +        /*
369.1657 +         * Sort five evenly spaced elements around (and including) the
369.1658 +         * center element in the range. These elements will be used for
369.1659 +         * pivot selection as described below. The choice for spacing
369.1660 +         * these elements was empirically determined to work well on
369.1661 +         * a wide variety of inputs.
369.1662 +         */
369.1663 +        int e3 = (left + right) >>> 1; // The midpoint
369.1664 +        int e2 = e3 - seventh;
369.1665 +        int e1 = e2 - seventh;
369.1666 +        int e4 = e3 + seventh;
369.1667 +        int e5 = e4 + seventh;
369.1668 +
369.1669 +        // Sort these elements using insertion sort
369.1670 +        if (a[e2] < a[e1]) { char t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
369.1671 +
369.1672 +        if (a[e3] < a[e2]) { char t = a[e3]; a[e3] = a[e2]; a[e2] = t;
369.1673 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.1674 +        }
369.1675 +        if (a[e4] < a[e3]) { char t = a[e4]; a[e4] = a[e3]; a[e3] = t;
369.1676 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.1677 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.1678 +            }
369.1679 +        }
369.1680 +        if (a[e5] < a[e4]) { char t = a[e5]; a[e5] = a[e4]; a[e4] = t;
369.1681 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
369.1682 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.1683 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.1684 +                }
369.1685 +            }
369.1686 +        }
369.1687 +
369.1688 +        // Pointers
369.1689 +        int less  = left;  // The index of the first element of center part
369.1690 +        int great = right; // The index before the first element of right part
369.1691 +
369.1692 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
369.1693 +            /*
369.1694 +             * Use the second and fourth of the five sorted elements as pivots.
369.1695 +             * These values are inexpensive approximations of the first and
369.1696 +             * second terciles of the array. Note that pivot1 <= pivot2.
369.1697 +             */
369.1698 +            char pivot1 = a[e2];
369.1699 +            char pivot2 = a[e4];
369.1700 +
369.1701 +            /*
369.1702 +             * The first and the last elements to be sorted are moved to the
369.1703 +             * locations formerly occupied by the pivots. When partitioning
369.1704 +             * is complete, the pivots are swapped back into their final
369.1705 +             * positions, and excluded from subsequent sorting.
369.1706 +             */
369.1707 +            a[e2] = a[left];
369.1708 +            a[e4] = a[right];
369.1709 +
369.1710 +            /*
369.1711 +             * Skip elements, which are less or greater than pivot values.
369.1712 +             */
369.1713 +            while (a[++less] < pivot1);
369.1714 +            while (a[--great] > pivot2);
369.1715 +
369.1716 +            /*
369.1717 +             * Partitioning:
369.1718 +             *
369.1719 +             *   left part           center part                   right part
369.1720 +             * +--------------------------------------------------------------+
369.1721 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
369.1722 +             * +--------------------------------------------------------------+
369.1723 +             *               ^                          ^       ^
369.1724 +             *               |                          |       |
369.1725 +             *              less                        k     great
369.1726 +             *
369.1727 +             * Invariants:
369.1728 +             *
369.1729 +             *              all in (left, less)   < pivot1
369.1730 +             *    pivot1 <= all in [less, k)     <= pivot2
369.1731 +             *              all in (great, right) > pivot2
369.1732 +             *
369.1733 +             * Pointer k is the first index of ?-part.
369.1734 +             */
369.1735 +            outer:
369.1736 +            for (int k = less - 1; ++k <= great; ) {
369.1737 +                char ak = a[k];
369.1738 +                if (ak < pivot1) { // Move a[k] to left part
369.1739 +                    a[k] = a[less];
369.1740 +                    /*
369.1741 +                     * Here and below we use "a[i] = b; i++;" instead
369.1742 +                     * of "a[i++] = b;" due to performance issue.
369.1743 +                     */
369.1744 +                    a[less] = ak;
369.1745 +                    ++less;
369.1746 +                } else if (ak > pivot2) { // Move a[k] to right part
369.1747 +                    while (a[great] > pivot2) {
369.1748 +                        if (great-- == k) {
369.1749 +                            break outer;
369.1750 +                        }
369.1751 +                    }
369.1752 +                    if (a[great] < pivot1) { // a[great] <= pivot2
369.1753 +                        a[k] = a[less];
369.1754 +                        a[less] = a[great];
369.1755 +                        ++less;
369.1756 +                    } else { // pivot1 <= a[great] <= pivot2
369.1757 +                        a[k] = a[great];
369.1758 +                    }
369.1759 +                    /*
369.1760 +                     * Here and below we use "a[i] = b; i--;" instead
369.1761 +                     * of "a[i--] = b;" due to performance issue.
369.1762 +                     */
369.1763 +                    a[great] = ak;
369.1764 +                    --great;
369.1765 +                }
369.1766 +            }
369.1767 +
369.1768 +            // Swap pivots into their final positions
369.1769 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
369.1770 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
369.1771 +
369.1772 +            // Sort left and right parts recursively, excluding known pivots
369.1773 +            sort(a, left, less - 2, leftmost);
369.1774 +            sort(a, great + 2, right, false);
369.1775 +
369.1776 +            /*
369.1777 +             * If center part is too large (comprises > 4/7 of the array),
369.1778 +             * swap internal pivot values to ends.
369.1779 +             */
369.1780 +            if (less < e1 && e5 < great) {
369.1781 +                /*
369.1782 +                 * Skip elements, which are equal to pivot values.
369.1783 +                 */
369.1784 +                while (a[less] == pivot1) {
369.1785 +                    ++less;
369.1786 +                }
369.1787 +
369.1788 +                while (a[great] == pivot2) {
369.1789 +                    --great;
369.1790 +                }
369.1791 +
369.1792 +                /*
369.1793 +                 * Partitioning:
369.1794 +                 *
369.1795 +                 *   left part         center part                  right part
369.1796 +                 * +----------------------------------------------------------+
369.1797 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
369.1798 +                 * +----------------------------------------------------------+
369.1799 +                 *              ^                        ^       ^
369.1800 +                 *              |                        |       |
369.1801 +                 *             less                      k     great
369.1802 +                 *
369.1803 +                 * Invariants:
369.1804 +                 *
369.1805 +                 *              all in (*,  less) == pivot1
369.1806 +                 *     pivot1 < all in [less,  k)  < pivot2
369.1807 +                 *              all in (great, *) == pivot2
369.1808 +                 *
369.1809 +                 * Pointer k is the first index of ?-part.
369.1810 +                 */
369.1811 +                outer:
369.1812 +                for (int k = less - 1; ++k <= great; ) {
369.1813 +                    char ak = a[k];
369.1814 +                    if (ak == pivot1) { // Move a[k] to left part
369.1815 +                        a[k] = a[less];
369.1816 +                        a[less] = ak;
369.1817 +                        ++less;
369.1818 +                    } else if (ak == pivot2) { // Move a[k] to right part
369.1819 +                        while (a[great] == pivot2) {
369.1820 +                            if (great-- == k) {
369.1821 +                                break outer;
369.1822 +                            }
369.1823 +                        }
369.1824 +                        if (a[great] == pivot1) { // a[great] < pivot2
369.1825 +                            a[k] = a[less];
369.1826 +                            /*
369.1827 +                             * Even though a[great] equals to pivot1, the
369.1828 +                             * assignment a[less] = pivot1 may be incorrect,
369.1829 +                             * if a[great] and pivot1 are floating-point zeros
369.1830 +                             * of different signs. Therefore in float and
369.1831 +                             * double sorting methods we have to use more
369.1832 +                             * accurate assignment a[less] = a[great].
369.1833 +                             */
369.1834 +                            a[less] = pivot1;
369.1835 +                            ++less;
369.1836 +                        } else { // pivot1 < a[great] < pivot2
369.1837 +                            a[k] = a[great];
369.1838 +                        }
369.1839 +                        a[great] = ak;
369.1840 +                        --great;
369.1841 +                    }
369.1842 +                }
369.1843 +            }
369.1844 +
369.1845 +            // Sort center part recursively
369.1846 +            sort(a, less, great, false);
369.1847 +
369.1848 +        } else { // Partitioning with one pivot
369.1849 +            /*
369.1850 +             * Use the third of the five sorted elements as pivot.
369.1851 +             * This value is inexpensive approximation of the median.
369.1852 +             */
369.1853 +            char pivot = a[e3];
369.1854 +
369.1855 +            /*
369.1856 +             * Partitioning degenerates to the traditional 3-way
369.1857 +             * (or "Dutch National Flag") schema:
369.1858 +             *
369.1859 +             *   left part    center part              right part
369.1860 +             * +-------------------------------------------------+
369.1861 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
369.1862 +             * +-------------------------------------------------+
369.1863 +             *              ^              ^        ^
369.1864 +             *              |              |        |
369.1865 +             *             less            k      great
369.1866 +             *
369.1867 +             * Invariants:
369.1868 +             *
369.1869 +             *   all in (left, less)   < pivot
369.1870 +             *   all in [less, k)     == pivot
369.1871 +             *   all in (great, right) > pivot
369.1872 +             *
369.1873 +             * Pointer k is the first index of ?-part.
369.1874 +             */
369.1875 +            for (int k = less; k <= great; ++k) {
369.1876 +                if (a[k] == pivot) {
369.1877 +                    continue;
369.1878 +                }
369.1879 +                char ak = a[k];
369.1880 +                if (ak < pivot) { // Move a[k] to left part
369.1881 +                    a[k] = a[less];
369.1882 +                    a[less] = ak;
369.1883 +                    ++less;
369.1884 +                } else { // a[k] > pivot - Move a[k] to right part
369.1885 +                    while (a[great] > pivot) {
369.1886 +                        --great;
369.1887 +                    }
369.1888 +                    if (a[great] < pivot) { // a[great] <= pivot
369.1889 +                        a[k] = a[less];
369.1890 +                        a[less] = a[great];
369.1891 +                        ++less;
369.1892 +                    } else { // a[great] == pivot
369.1893 +                        /*
369.1894 +                         * Even though a[great] equals to pivot, the
369.1895 +                         * assignment a[k] = pivot may be incorrect,
369.1896 +                         * if a[great] and pivot are floating-point
369.1897 +                         * zeros of different signs. Therefore in float
369.1898 +                         * and double sorting methods we have to use
369.1899 +                         * more accurate assignment a[k] = a[great].
369.1900 +                         */
369.1901 +                        a[k] = pivot;
369.1902 +                    }
369.1903 +                    a[great] = ak;
369.1904 +                    --great;
369.1905 +                }
369.1906 +            }
369.1907 +
369.1908 +            /*
369.1909 +             * Sort left and right parts recursively.
369.1910 +             * All elements from center part are equal
369.1911 +             * and, therefore, already sorted.
369.1912 +             */
369.1913 +            sort(a, left, less - 1, leftmost);
369.1914 +            sort(a, great + 1, right, false);
369.1915 +        }
369.1916 +    }
369.1917 +
369.1918 +    /** The number of distinct byte values. */
369.1919 +    private static final int NUM_BYTE_VALUES = 1 << 8;
369.1920 +
369.1921 +    /**
369.1922 +     * Sorts the specified array.
369.1923 +     *
369.1924 +     * @param a the array to be sorted
369.1925 +     */
369.1926 +    public static void sort(byte[] a) {
369.1927 +        sort(a, 0, a.length - 1);
369.1928 +    }
369.1929 +
369.1930 +    /**
369.1931 +     * Sorts the specified range of the array.
369.1932 +     *
369.1933 +     * @param a the array to be sorted
369.1934 +     * @param left the index of the first element, inclusive, to be sorted
369.1935 +     * @param right the index of the last element, inclusive, to be sorted
369.1936 +     */
369.1937 +    public static void sort(byte[] a, int left, int right) {
369.1938 +        // Use counting sort on large arrays
369.1939 +        if (right - left > COUNTING_SORT_THRESHOLD_FOR_BYTE) {
369.1940 +            int[] count = new int[NUM_BYTE_VALUES];
369.1941 +
369.1942 +            for (int i = left - 1; ++i <= right;
369.1943 +                count[a[i] - Byte.MIN_VALUE]++
369.1944 +            );
369.1945 +            for (int i = NUM_BYTE_VALUES, k = right + 1; k > left; ) {
369.1946 +                while (count[--i] == 0);
369.1947 +                byte value = (byte) (i + Byte.MIN_VALUE);
369.1948 +                int s = count[i];
369.1949 +
369.1950 +                do {
369.1951 +                    a[--k] = value;
369.1952 +                } while (--s > 0);
369.1953 +            }
369.1954 +        } else { // Use insertion sort on small arrays
369.1955 +            for (int i = left, j = i; i < right; j = ++i) {
369.1956 +                byte ai = a[i + 1];
369.1957 +                while (ai < a[j]) {
369.1958 +                    a[j + 1] = a[j];
369.1959 +                    if (j-- == left) {
369.1960 +                        break;
369.1961 +                    }
369.1962 +                }
369.1963 +                a[j + 1] = ai;
369.1964 +            }
369.1965 +        }
369.1966 +    }
369.1967 +
369.1968 +    /**
369.1969 +     * Sorts the specified array.
369.1970 +     *
369.1971 +     * @param a the array to be sorted
369.1972 +     */
369.1973 +    public static void sort(float[] a) {
369.1974 +        sort(a, 0, a.length - 1);
369.1975 +    }
369.1976 +
369.1977 +    /**
369.1978 +     * Sorts the specified range of the array.
369.1979 +     *
369.1980 +     * @param a the array to be sorted
369.1981 +     * @param left the index of the first element, inclusive, to be sorted
369.1982 +     * @param right the index of the last element, inclusive, to be sorted
369.1983 +     */
369.1984 +    public static void sort(float[] a, int left, int right) {
369.1985 +        /*
369.1986 +         * Phase 1: Move NaNs to the end of the array.
369.1987 +         */
369.1988 +        while (left <= right && Float.isNaN(a[right])) {
369.1989 +            --right;
369.1990 +        }
369.1991 +        for (int k = right; --k >= left; ) {
369.1992 +            float ak = a[k];
369.1993 +            if (ak != ak) { // a[k] is NaN
369.1994 +                a[k] = a[right];
369.1995 +                a[right] = ak;
369.1996 +                --right;
369.1997 +            }
369.1998 +        }
369.1999 +
369.2000 +        /*
369.2001 +         * Phase 2: Sort everything except NaNs (which are already in place).
369.2002 +         */
369.2003 +        doSort(a, left, right);
369.2004 +
369.2005 +        /*
369.2006 +         * Phase 3: Place negative zeros before positive zeros.
369.2007 +         */
369.2008 +        int hi = right;
369.2009 +
369.2010 +        /*
369.2011 +         * Find the first zero, or first positive, or last negative element.
369.2012 +         */
369.2013 +        while (left < hi) {
369.2014 +            int middle = (left + hi) >>> 1;
369.2015 +            float middleValue = a[middle];
369.2016 +
369.2017 +            if (middleValue < 0.0f) {
369.2018 +                left = middle + 1;
369.2019 +            } else {
369.2020 +                hi = middle;
369.2021 +            }
369.2022 +        }
369.2023 +
369.2024 +        /*
369.2025 +         * Skip the last negative value (if any) or all leading negative zeros.
369.2026 +         */
369.2027 +        while (left <= right && Float.floatToRawIntBits(a[left]) < 0) {
369.2028 +            ++left;
369.2029 +        }
369.2030 +
369.2031 +        /*
369.2032 +         * Move negative zeros to the beginning of the sub-range.
369.2033 +         *
369.2034 +         * Partitioning:
369.2035 +         *
369.2036 +         * +----------------------------------------------------+
369.2037 +         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
369.2038 +         * +----------------------------------------------------+
369.2039 +         *              ^          ^         ^
369.2040 +         *              |          |         |
369.2041 +         *             left        p         k
369.2042 +         *
369.2043 +         * Invariants:
369.2044 +         *
369.2045 +         *   all in (*,  left)  <  0.0
369.2046 +         *   all in [left,  p) == -0.0
369.2047 +         *   all in [p,     k) ==  0.0
369.2048 +         *   all in [k, right] >=  0.0
369.2049 +         *
369.2050 +         * Pointer k is the first index of ?-part.
369.2051 +         */
369.2052 +        for (int k = left, p = left - 1; ++k <= right; ) {
369.2053 +            float ak = a[k];
369.2054 +            if (ak != 0.0f) {
369.2055 +                break;
369.2056 +            }
369.2057 +            if (Float.floatToRawIntBits(ak) < 0) { // ak is -0.0f
369.2058 +                a[k] = 0.0f;
369.2059 +                a[++p] = -0.0f;
369.2060 +            }
369.2061 +        }
369.2062 +    }
369.2063 +
369.2064 +    /**
369.2065 +     * Sorts the specified range of the array.
369.2066 +     *
369.2067 +     * @param a the array to be sorted
369.2068 +     * @param left the index of the first element, inclusive, to be sorted
369.2069 +     * @param right the index of the last element, inclusive, to be sorted
369.2070 +     */
369.2071 +    private static void doSort(float[] a, int left, int right) {
369.2072 +        // Use Quicksort on small arrays
369.2073 +        if (right - left < QUICKSORT_THRESHOLD) {
369.2074 +            sort(a, left, right, true);
369.2075 +            return;
369.2076 +        }
369.2077 +
369.2078 +        /*
369.2079 +         * Index run[i] is the start of i-th run
369.2080 +         * (ascending or descending sequence).
369.2081 +         */
369.2082 +        int[] run = new int[MAX_RUN_COUNT + 1];
369.2083 +        int count = 0; run[0] = left;
369.2084 +
369.2085 +        // Check if the array is nearly sorted
369.2086 +        for (int k = left; k < right; run[count] = k) {
369.2087 +            if (a[k] < a[k + 1]) { // ascending
369.2088 +                while (++k <= right && a[k - 1] <= a[k]);
369.2089 +            } else if (a[k] > a[k + 1]) { // descending
369.2090 +                while (++k <= right && a[k - 1] >= a[k]);
369.2091 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
369.2092 +                    float t = a[lo]; a[lo] = a[hi]; a[hi] = t;
369.2093 +                }
369.2094 +            } else { // equal
369.2095 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
369.2096 +                    if (--m == 0) {
369.2097 +                        sort(a, left, right, true);
369.2098 +                        return;
369.2099 +                    }
369.2100 +                }
369.2101 +            }
369.2102 +
369.2103 +            /*
369.2104 +             * The array is not highly structured,
369.2105 +             * use Quicksort instead of merge sort.
369.2106 +             */
369.2107 +            if (++count == MAX_RUN_COUNT) {
369.2108 +                sort(a, left, right, true);
369.2109 +                return;
369.2110 +            }
369.2111 +        }
369.2112 +
369.2113 +        // Check special cases
369.2114 +        if (run[count] == right++) { // The last run contains one element
369.2115 +            run[++count] = right;
369.2116 +        } else if (count == 1) { // The array is already sorted
369.2117 +            return;
369.2118 +        }
369.2119 +
369.2120 +        /*
369.2121 +         * Create temporary array, which is used for merging.
369.2122 +         * Implementation note: variable "right" is increased by 1.
369.2123 +         */
369.2124 +        float[] b; byte odd = 0;
369.2125 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
369.2126 +
369.2127 +        if (odd == 0) {
369.2128 +            b = a; a = new float[b.length];
369.2129 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
369.2130 +        } else {
369.2131 +            b = new float[a.length];
369.2132 +        }
369.2133 +
369.2134 +        // Merging
369.2135 +        for (int last; count > 1; count = last) {
369.2136 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
369.2137 +                int hi = run[k], mi = run[k - 1];
369.2138 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
369.2139 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
369.2140 +                        b[i] = a[p++];
369.2141 +                    } else {
369.2142 +                        b[i] = a[q++];
369.2143 +                    }
369.2144 +                }
369.2145 +                run[++last] = hi;
369.2146 +            }
369.2147 +            if ((count & 1) != 0) {
369.2148 +                for (int i = right, lo = run[count - 1]; --i >= lo;
369.2149 +                    b[i] = a[i]
369.2150 +                );
369.2151 +                run[++last] = right;
369.2152 +            }
369.2153 +            float[] t = a; a = b; b = t;
369.2154 +        }
369.2155 +    }
369.2156 +
369.2157 +    /**
369.2158 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
369.2159 +     *
369.2160 +     * @param a the array to be sorted
369.2161 +     * @param left the index of the first element, inclusive, to be sorted
369.2162 +     * @param right the index of the last element, inclusive, to be sorted
369.2163 +     * @param leftmost indicates if this part is the leftmost in the range
369.2164 +     */
369.2165 +    private static void sort(float[] a, int left, int right, boolean leftmost) {
369.2166 +        int length = right - left + 1;
369.2167 +
369.2168 +        // Use insertion sort on tiny arrays
369.2169 +        if (length < INSERTION_SORT_THRESHOLD) {
369.2170 +            if (leftmost) {
369.2171 +                /*
369.2172 +                 * Traditional (without sentinel) insertion sort,
369.2173 +                 * optimized for server VM, is used in case of
369.2174 +                 * the leftmost part.
369.2175 +                 */
369.2176 +                for (int i = left, j = i; i < right; j = ++i) {
369.2177 +                    float ai = a[i + 1];
369.2178 +                    while (ai < a[j]) {
369.2179 +                        a[j + 1] = a[j];
369.2180 +                        if (j-- == left) {
369.2181 +                            break;
369.2182 +                        }
369.2183 +                    }
369.2184 +                    a[j + 1] = ai;
369.2185 +                }
369.2186 +            } else {
369.2187 +                /*
369.2188 +                 * Skip the longest ascending sequence.
369.2189 +                 */
369.2190 +                do {
369.2191 +                    if (left >= right) {
369.2192 +                        return;
369.2193 +                    }
369.2194 +                } while (a[++left] >= a[left - 1]);
369.2195 +
369.2196 +                /*
369.2197 +                 * Every element from adjoining part plays the role
369.2198 +                 * of sentinel, therefore this allows us to avoid the
369.2199 +                 * left range check on each iteration. Moreover, we use
369.2200 +                 * the more optimized algorithm, so called pair insertion
369.2201 +                 * sort, which is faster (in the context of Quicksort)
369.2202 +                 * than traditional implementation of insertion sort.
369.2203 +                 */
369.2204 +                for (int k = left; ++left <= right; k = ++left) {
369.2205 +                    float a1 = a[k], a2 = a[left];
369.2206 +
369.2207 +                    if (a1 < a2) {
369.2208 +                        a2 = a1; a1 = a[left];
369.2209 +                    }
369.2210 +                    while (a1 < a[--k]) {
369.2211 +                        a[k + 2] = a[k];
369.2212 +                    }
369.2213 +                    a[++k + 1] = a1;
369.2214 +
369.2215 +                    while (a2 < a[--k]) {
369.2216 +                        a[k + 1] = a[k];
369.2217 +                    }
369.2218 +                    a[k + 1] = a2;
369.2219 +                }
369.2220 +                float last = a[right];
369.2221 +
369.2222 +                while (last < a[--right]) {
369.2223 +                    a[right + 1] = a[right];
369.2224 +                }
369.2225 +                a[right + 1] = last;
369.2226 +            }
369.2227 +            return;
369.2228 +        }
369.2229 +
369.2230 +        // Inexpensive approximation of length / 7
369.2231 +        int seventh = (length >> 3) + (length >> 6) + 1;
369.2232 +
369.2233 +        /*
369.2234 +         * Sort five evenly spaced elements around (and including) the
369.2235 +         * center element in the range. These elements will be used for
369.2236 +         * pivot selection as described below. The choice for spacing
369.2237 +         * these elements was empirically determined to work well on
369.2238 +         * a wide variety of inputs.
369.2239 +         */
369.2240 +        int e3 = (left + right) >>> 1; // The midpoint
369.2241 +        int e2 = e3 - seventh;
369.2242 +        int e1 = e2 - seventh;
369.2243 +        int e4 = e3 + seventh;
369.2244 +        int e5 = e4 + seventh;
369.2245 +
369.2246 +        // Sort these elements using insertion sort
369.2247 +        if (a[e2] < a[e1]) { float t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
369.2248 +
369.2249 +        if (a[e3] < a[e2]) { float t = a[e3]; a[e3] = a[e2]; a[e2] = t;
369.2250 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.2251 +        }
369.2252 +        if (a[e4] < a[e3]) { float t = a[e4]; a[e4] = a[e3]; a[e3] = t;
369.2253 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.2254 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.2255 +            }
369.2256 +        }
369.2257 +        if (a[e5] < a[e4]) { float t = a[e5]; a[e5] = a[e4]; a[e4] = t;
369.2258 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
369.2259 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.2260 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.2261 +                }
369.2262 +            }
369.2263 +        }
369.2264 +
369.2265 +        // Pointers
369.2266 +        int less  = left;  // The index of the first element of center part
369.2267 +        int great = right; // The index before the first element of right part
369.2268 +
369.2269 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
369.2270 +            /*
369.2271 +             * Use the second and fourth of the five sorted elements as pivots.
369.2272 +             * These values are inexpensive approximations of the first and
369.2273 +             * second terciles of the array. Note that pivot1 <= pivot2.
369.2274 +             */
369.2275 +            float pivot1 = a[e2];
369.2276 +            float pivot2 = a[e4];
369.2277 +
369.2278 +            /*
369.2279 +             * The first and the last elements to be sorted are moved to the
369.2280 +             * locations formerly occupied by the pivots. When partitioning
369.2281 +             * is complete, the pivots are swapped back into their final
369.2282 +             * positions, and excluded from subsequent sorting.
369.2283 +             */
369.2284 +            a[e2] = a[left];
369.2285 +            a[e4] = a[right];
369.2286 +
369.2287 +            /*
369.2288 +             * Skip elements, which are less or greater than pivot values.
369.2289 +             */
369.2290 +            while (a[++less] < pivot1);
369.2291 +            while (a[--great] > pivot2);
369.2292 +
369.2293 +            /*
369.2294 +             * Partitioning:
369.2295 +             *
369.2296 +             *   left part           center part                   right part
369.2297 +             * +--------------------------------------------------------------+
369.2298 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
369.2299 +             * +--------------------------------------------------------------+
369.2300 +             *               ^                          ^       ^
369.2301 +             *               |                          |       |
369.2302 +             *              less                        k     great
369.2303 +             *
369.2304 +             * Invariants:
369.2305 +             *
369.2306 +             *              all in (left, less)   < pivot1
369.2307 +             *    pivot1 <= all in [less, k)     <= pivot2
369.2308 +             *              all in (great, right) > pivot2
369.2309 +             *
369.2310 +             * Pointer k is the first index of ?-part.
369.2311 +             */
369.2312 +            outer:
369.2313 +            for (int k = less - 1; ++k <= great; ) {
369.2314 +                float ak = a[k];
369.2315 +                if (ak < pivot1) { // Move a[k] to left part
369.2316 +                    a[k] = a[less];
369.2317 +                    /*
369.2318 +                     * Here and below we use "a[i] = b; i++;" instead
369.2319 +                     * of "a[i++] = b;" due to performance issue.
369.2320 +                     */
369.2321 +                    a[less] = ak;
369.2322 +                    ++less;
369.2323 +                } else if (ak > pivot2) { // Move a[k] to right part
369.2324 +                    while (a[great] > pivot2) {
369.2325 +                        if (great-- == k) {
369.2326 +                            break outer;
369.2327 +                        }
369.2328 +                    }
369.2329 +                    if (a[great] < pivot1) { // a[great] <= pivot2
369.2330 +                        a[k] = a[less];
369.2331 +                        a[less] = a[great];
369.2332 +                        ++less;
369.2333 +                    } else { // pivot1 <= a[great] <= pivot2
369.2334 +                        a[k] = a[great];
369.2335 +                    }
369.2336 +                    /*
369.2337 +                     * Here and below we use "a[i] = b; i--;" instead
369.2338 +                     * of "a[i--] = b;" due to performance issue.
369.2339 +                     */
369.2340 +                    a[great] = ak;
369.2341 +                    --great;
369.2342 +                }
369.2343 +            }
369.2344 +
369.2345 +            // Swap pivots into their final positions
369.2346 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
369.2347 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
369.2348 +
369.2349 +            // Sort left and right parts recursively, excluding known pivots
369.2350 +            sort(a, left, less - 2, leftmost);
369.2351 +            sort(a, great + 2, right, false);
369.2352 +
369.2353 +            /*
369.2354 +             * If center part is too large (comprises > 4/7 of the array),
369.2355 +             * swap internal pivot values to ends.
369.2356 +             */
369.2357 +            if (less < e1 && e5 < great) {
369.2358 +                /*
369.2359 +                 * Skip elements, which are equal to pivot values.
369.2360 +                 */
369.2361 +                while (a[less] == pivot1) {
369.2362 +                    ++less;
369.2363 +                }
369.2364 +
369.2365 +                while (a[great] == pivot2) {
369.2366 +                    --great;
369.2367 +                }
369.2368 +
369.2369 +                /*
369.2370 +                 * Partitioning:
369.2371 +                 *
369.2372 +                 *   left part         center part                  right part
369.2373 +                 * +----------------------------------------------------------+
369.2374 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
369.2375 +                 * +----------------------------------------------------------+
369.2376 +                 *              ^                        ^       ^
369.2377 +                 *              |                        |       |
369.2378 +                 *             less                      k     great
369.2379 +                 *
369.2380 +                 * Invariants:
369.2381 +                 *
369.2382 +                 *              all in (*,  less) == pivot1
369.2383 +                 *     pivot1 < all in [less,  k)  < pivot2
369.2384 +                 *              all in (great, *) == pivot2
369.2385 +                 *
369.2386 +                 * Pointer k is the first index of ?-part.
369.2387 +                 */
369.2388 +                outer:
369.2389 +                for (int k = less - 1; ++k <= great; ) {
369.2390 +                    float ak = a[k];
369.2391 +                    if (ak == pivot1) { // Move a[k] to left part
369.2392 +                        a[k] = a[less];
369.2393 +                        a[less] = ak;
369.2394 +                        ++less;
369.2395 +                    } else if (ak == pivot2) { // Move a[k] to right part
369.2396 +                        while (a[great] == pivot2) {
369.2397 +                            if (great-- == k) {
369.2398 +                                break outer;
369.2399 +                            }
369.2400 +                        }
369.2401 +                        if (a[great] == pivot1) { // a[great] < pivot2
369.2402 +                            a[k] = a[less];
369.2403 +                            /*
369.2404 +                             * Even though a[great] equals to pivot1, the
369.2405 +                             * assignment a[less] = pivot1 may be incorrect,
369.2406 +                             * if a[great] and pivot1 are floating-point zeros
369.2407 +                             * of different signs. Therefore in float and
369.2408 +                             * double sorting methods we have to use more
369.2409 +                             * accurate assignment a[less] = a[great].
369.2410 +                             */
369.2411 +                            a[less] = a[great];
369.2412 +                            ++less;
369.2413 +                        } else { // pivot1 < a[great] < pivot2
369.2414 +                            a[k] = a[great];
369.2415 +                        }
369.2416 +                        a[great] = ak;
369.2417 +                        --great;
369.2418 +                    }
369.2419 +                }
369.2420 +            }
369.2421 +
369.2422 +            // Sort center part recursively
369.2423 +            sort(a, less, great, false);
369.2424 +
369.2425 +        } else { // Partitioning with one pivot
369.2426 +            /*
369.2427 +             * Use the third of the five sorted elements as pivot.
369.2428 +             * This value is inexpensive approximation of the median.
369.2429 +             */
369.2430 +            float pivot = a[e3];
369.2431 +
369.2432 +            /*
369.2433 +             * Partitioning degenerates to the traditional 3-way
369.2434 +             * (or "Dutch National Flag") schema:
369.2435 +             *
369.2436 +             *   left part    center part              right part
369.2437 +             * +-------------------------------------------------+
369.2438 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
369.2439 +             * +-------------------------------------------------+
369.2440 +             *              ^              ^        ^
369.2441 +             *              |              |        |
369.2442 +             *             less            k      great
369.2443 +             *
369.2444 +             * Invariants:
369.2445 +             *
369.2446 +             *   all in (left, less)   < pivot
369.2447 +             *   all in [less, k)     == pivot
369.2448 +             *   all in (great, right) > pivot
369.2449 +             *
369.2450 +             * Pointer k is the first index of ?-part.
369.2451 +             */
369.2452 +            for (int k = less; k <= great; ++k) {
369.2453 +                if (a[k] == pivot) {
369.2454 +                    continue;
369.2455 +                }
369.2456 +                float ak = a[k];
369.2457 +                if (ak < pivot) { // Move a[k] to left part
369.2458 +                    a[k] = a[less];
369.2459 +                    a[less] = ak;
369.2460 +                    ++less;
369.2461 +                } else { // a[k] > pivot - Move a[k] to right part
369.2462 +                    while (a[great] > pivot) {
369.2463 +                        --great;
369.2464 +                    }
369.2465 +                    if (a[great] < pivot) { // a[great] <= pivot
369.2466 +                        a[k] = a[less];
369.2467 +                        a[less] = a[great];
369.2468 +                        ++less;
369.2469 +                    } else { // a[great] == pivot
369.2470 +                        /*
369.2471 +                         * Even though a[great] equals to pivot, the
369.2472 +                         * assignment a[k] = pivot may be incorrect,
369.2473 +                         * if a[great] and pivot are floating-point
369.2474 +                         * zeros of different signs. Therefore in float
369.2475 +                         * and double sorting methods we have to use
369.2476 +                         * more accurate assignment a[k] = a[great].
369.2477 +                         */
369.2478 +                        a[k] = a[great];
369.2479 +                    }
369.2480 +                    a[great] = ak;
369.2481 +                    --great;
369.2482 +                }
369.2483 +            }
369.2484 +
369.2485 +            /*
369.2486 +             * Sort left and right parts recursively.
369.2487 +             * All elements from center part are equal
369.2488 +             * and, therefore, already sorted.
369.2489 +             */
369.2490 +            sort(a, left, less - 1, leftmost);
369.2491 +            sort(a, great + 1, right, false);
369.2492 +        }
369.2493 +    }
369.2494 +
369.2495 +    /**
369.2496 +     * Sorts the specified array.
369.2497 +     *
369.2498 +     * @param a the array to be sorted
369.2499 +     */
369.2500 +    public static void sort(double[] a) {
369.2501 +        sort(a, 0, a.length - 1);
369.2502 +    }
369.2503 +
369.2504 +    /**
369.2505 +     * Sorts the specified range of the array.
369.2506 +     *
369.2507 +     * @param a the array to be sorted
369.2508 +     * @param left the index of the first element, inclusive, to be sorted
369.2509 +     * @param right the index of the last element, inclusive, to be sorted
369.2510 +     */
369.2511 +    public static void sort(double[] a, int left, int right) {
369.2512 +        /*
369.2513 +         * Phase 1: Move NaNs to the end of the array.
369.2514 +         */
369.2515 +        while (left <= right && Double.isNaN(a[right])) {
369.2516 +            --right;
369.2517 +        }
369.2518 +        for (int k = right; --k >= left; ) {
369.2519 +            double ak = a[k];
369.2520 +            if (ak != ak) { // a[k] is NaN
369.2521 +                a[k] = a[right];
369.2522 +                a[right] = ak;
369.2523 +                --right;
369.2524 +            }
369.2525 +        }
369.2526 +
369.2527 +        /*
369.2528 +         * Phase 2: Sort everything except NaNs (which are already in place).
369.2529 +         */
369.2530 +        doSort(a, left, right);
369.2531 +
369.2532 +        /*
369.2533 +         * Phase 3: Place negative zeros before positive zeros.
369.2534 +         */
369.2535 +        int hi = right;
369.2536 +
369.2537 +        /*
369.2538 +         * Find the first zero, or first positive, or last negative element.
369.2539 +         */
369.2540 +        while (left < hi) {
369.2541 +            int middle = (left + hi) >>> 1;
369.2542 +            double middleValue = a[middle];
369.2543 +
369.2544 +            if (middleValue < 0.0d) {
369.2545 +                left = middle + 1;
369.2546 +            } else {
369.2547 +                hi = middle;
369.2548 +            }
369.2549 +        }
369.2550 +
369.2551 +        /*
369.2552 +         * Skip the last negative value (if any) or all leading negative zeros.
369.2553 +         */
369.2554 +        while (left <= right && Double.doubleToRawLongBits(a[left]) < 0) {
369.2555 +            ++left;
369.2556 +        }
369.2557 +
369.2558 +        /*
369.2559 +         * Move negative zeros to the beginning of the sub-range.
369.2560 +         *
369.2561 +         * Partitioning:
369.2562 +         *
369.2563 +         * +----------------------------------------------------+
369.2564 +         * |   < 0.0   |   -0.0   |   0.0   |   ?  ( >= 0.0 )   |
369.2565 +         * +----------------------------------------------------+
369.2566 +         *              ^          ^         ^
369.2567 +         *              |          |         |
369.2568 +         *             left        p         k
369.2569 +         *
369.2570 +         * Invariants:
369.2571 +         *
369.2572 +         *   all in (*,  left)  <  0.0
369.2573 +         *   all in [left,  p) == -0.0
369.2574 +         *   all in [p,     k) ==  0.0
369.2575 +         *   all in [k, right] >=  0.0
369.2576 +         *
369.2577 +         * Pointer k is the first index of ?-part.
369.2578 +         */
369.2579 +        for (int k = left, p = left - 1; ++k <= right; ) {
369.2580 +            double ak = a[k];
369.2581 +            if (ak != 0.0d) {
369.2582 +                break;
369.2583 +            }
369.2584 +            if (Double.doubleToRawLongBits(ak) < 0) { // ak is -0.0d
369.2585 +                a[k] = 0.0d;
369.2586 +                a[++p] = -0.0d;
369.2587 +            }
369.2588 +        }
369.2589 +    }
369.2590 +
369.2591 +    /**
369.2592 +     * Sorts the specified range of the array.
369.2593 +     *
369.2594 +     * @param a the array to be sorted
369.2595 +     * @param left the index of the first element, inclusive, to be sorted
369.2596 +     * @param right the index of the last element, inclusive, to be sorted
369.2597 +     */
369.2598 +    private static void doSort(double[] a, int left, int right) {
369.2599 +        // Use Quicksort on small arrays
369.2600 +        if (right - left < QUICKSORT_THRESHOLD) {
369.2601 +            sort(a, left, right, true);
369.2602 +            return;
369.2603 +        }
369.2604 +
369.2605 +        /*
369.2606 +         * Index run[i] is the start of i-th run
369.2607 +         * (ascending or descending sequence).
369.2608 +         */
369.2609 +        int[] run = new int[MAX_RUN_COUNT + 1];
369.2610 +        int count = 0; run[0] = left;
369.2611 +
369.2612 +        // Check if the array is nearly sorted
369.2613 +        for (int k = left; k < right; run[count] = k) {
369.2614 +            if (a[k] < a[k + 1]) { // ascending
369.2615 +                while (++k <= right && a[k - 1] <= a[k]);
369.2616 +            } else if (a[k] > a[k + 1]) { // descending
369.2617 +                while (++k <= right && a[k - 1] >= a[k]);
369.2618 +                for (int lo = run[count] - 1, hi = k; ++lo < --hi; ) {
369.2619 +                    double t = a[lo]; a[lo] = a[hi]; a[hi] = t;
369.2620 +                }
369.2621 +            } else { // equal
369.2622 +                for (int m = MAX_RUN_LENGTH; ++k <= right && a[k - 1] == a[k]; ) {
369.2623 +                    if (--m == 0) {
369.2624 +                        sort(a, left, right, true);
369.2625 +                        return;
369.2626 +                    }
369.2627 +                }
369.2628 +            }
369.2629 +
369.2630 +            /*
369.2631 +             * The array is not highly structured,
369.2632 +             * use Quicksort instead of merge sort.
369.2633 +             */
369.2634 +            if (++count == MAX_RUN_COUNT) {
369.2635 +                sort(a, left, right, true);
369.2636 +                return;
369.2637 +            }
369.2638 +        }
369.2639 +
369.2640 +        // Check special cases
369.2641 +        if (run[count] == right++) { // The last run contains one element
369.2642 +            run[++count] = right;
369.2643 +        } else if (count == 1) { // The array is already sorted
369.2644 +            return;
369.2645 +        }
369.2646 +
369.2647 +        /*
369.2648 +         * Create temporary array, which is used for merging.
369.2649 +         * Implementation note: variable "right" is increased by 1.
369.2650 +         */
369.2651 +        double[] b; byte odd = 0;
369.2652 +        for (int n = 1; (n <<= 1) < count; odd ^= 1);
369.2653 +
369.2654 +        if (odd == 0) {
369.2655 +            b = a; a = new double[b.length];
369.2656 +            for (int i = left - 1; ++i < right; a[i] = b[i]);
369.2657 +        } else {
369.2658 +            b = new double[a.length];
369.2659 +        }
369.2660 +
369.2661 +        // Merging
369.2662 +        for (int last; count > 1; count = last) {
369.2663 +            for (int k = (last = 0) + 2; k <= count; k += 2) {
369.2664 +                int hi = run[k], mi = run[k - 1];
369.2665 +                for (int i = run[k - 2], p = i, q = mi; i < hi; ++i) {
369.2666 +                    if (q >= hi || p < mi && a[p] <= a[q]) {
369.2667 +                        b[i] = a[p++];
369.2668 +                    } else {
369.2669 +                        b[i] = a[q++];
369.2670 +                    }
369.2671 +                }
369.2672 +                run[++last] = hi;
369.2673 +            }
369.2674 +            if ((count & 1) != 0) {
369.2675 +                for (int i = right, lo = run[count - 1]; --i >= lo;
369.2676 +                    b[i] = a[i]
369.2677 +                );
369.2678 +                run[++last] = right;
369.2679 +            }
369.2680 +            double[] t = a; a = b; b = t;
369.2681 +        }
369.2682 +    }
369.2683 +
369.2684 +    /**
369.2685 +     * Sorts the specified range of the array by Dual-Pivot Quicksort.
369.2686 +     *
369.2687 +     * @param a the array to be sorted
369.2688 +     * @param left the index of the first element, inclusive, to be sorted
369.2689 +     * @param right the index of the last element, inclusive, to be sorted
369.2690 +     * @param leftmost indicates if this part is the leftmost in the range
369.2691 +     */
369.2692 +    private static void sort(double[] a, int left, int right, boolean leftmost) {
369.2693 +        int length = right - left + 1;
369.2694 +
369.2695 +        // Use insertion sort on tiny arrays
369.2696 +        if (length < INSERTION_SORT_THRESHOLD) {
369.2697 +            if (leftmost) {
369.2698 +                /*
369.2699 +                 * Traditional (without sentinel) insertion sort,
369.2700 +                 * optimized for server VM, is used in case of
369.2701 +                 * the leftmost part.
369.2702 +                 */
369.2703 +                for (int i = left, j = i; i < right; j = ++i) {
369.2704 +                    double ai = a[i + 1];
369.2705 +                    while (ai < a[j]) {
369.2706 +                        a[j + 1] = a[j];
369.2707 +                        if (j-- == left) {
369.2708 +                            break;
369.2709 +                        }
369.2710 +                    }
369.2711 +                    a[j + 1] = ai;
369.2712 +                }
369.2713 +            } else {
369.2714 +                /*
369.2715 +                 * Skip the longest ascending sequence.
369.2716 +                 */
369.2717 +                do {
369.2718 +                    if (left >= right) {
369.2719 +                        return;
369.2720 +                    }
369.2721 +                } while (a[++left] >= a[left - 1]);
369.2722 +
369.2723 +                /*
369.2724 +                 * Every element from adjoining part plays the role
369.2725 +                 * of sentinel, therefore this allows us to avoid the
369.2726 +                 * left range check on each iteration. Moreover, we use
369.2727 +                 * the more optimized algorithm, so called pair insertion
369.2728 +                 * sort, which is faster (in the context of Quicksort)
369.2729 +                 * than traditional implementation of insertion sort.
369.2730 +                 */
369.2731 +                for (int k = left; ++left <= right; k = ++left) {
369.2732 +                    double a1 = a[k], a2 = a[left];
369.2733 +
369.2734 +                    if (a1 < a2) {
369.2735 +                        a2 = a1; a1 = a[left];
369.2736 +                    }
369.2737 +                    while (a1 < a[--k]) {
369.2738 +                        a[k + 2] = a[k];
369.2739 +                    }
369.2740 +                    a[++k + 1] = a1;
369.2741 +
369.2742 +                    while (a2 < a[--k]) {
369.2743 +                        a[k + 1] = a[k];
369.2744 +                    }
369.2745 +                    a[k + 1] = a2;
369.2746 +                }
369.2747 +                double last = a[right];
369.2748 +
369.2749 +                while (last < a[--right]) {
369.2750 +                    a[right + 1] = a[right];
369.2751 +                }
369.2752 +                a[right + 1] = last;
369.2753 +            }
369.2754 +            return;
369.2755 +        }
369.2756 +
369.2757 +        // Inexpensive approximation of length / 7
369.2758 +        int seventh = (length >> 3) + (length >> 6) + 1;
369.2759 +
369.2760 +        /*
369.2761 +         * Sort five evenly spaced elements around (and including) the
369.2762 +         * center element in the range. These elements will be used for
369.2763 +         * pivot selection as described below. The choice for spacing
369.2764 +         * these elements was empirically determined to work well on
369.2765 +         * a wide variety of inputs.
369.2766 +         */
369.2767 +        int e3 = (left + right) >>> 1; // The midpoint
369.2768 +        int e2 = e3 - seventh;
369.2769 +        int e1 = e2 - seventh;
369.2770 +        int e4 = e3 + seventh;
369.2771 +        int e5 = e4 + seventh;
369.2772 +
369.2773 +        // Sort these elements using insertion sort
369.2774 +        if (a[e2] < a[e1]) { double t = a[e2]; a[e2] = a[e1]; a[e1] = t; }
369.2775 +
369.2776 +        if (a[e3] < a[e2]) { double t = a[e3]; a[e3] = a[e2]; a[e2] = t;
369.2777 +            if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.2778 +        }
369.2779 +        if (a[e4] < a[e3]) { double t = a[e4]; a[e4] = a[e3]; a[e3] = t;
369.2780 +            if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.2781 +                if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.2782 +            }
369.2783 +        }
369.2784 +        if (a[e5] < a[e4]) { double t = a[e5]; a[e5] = a[e4]; a[e4] = t;
369.2785 +            if (t < a[e3]) { a[e4] = a[e3]; a[e3] = t;
369.2786 +                if (t < a[e2]) { a[e3] = a[e2]; a[e2] = t;
369.2787 +                    if (t < a[e1]) { a[e2] = a[e1]; a[e1] = t; }
369.2788 +                }
369.2789 +            }
369.2790 +        }
369.2791 +
369.2792 +        // Pointers
369.2793 +        int less  = left;  // The index of the first element of center part
369.2794 +        int great = right; // The index before the first element of right part
369.2795 +
369.2796 +        if (a[e1] != a[e2] && a[e2] != a[e3] && a[e3] != a[e4] && a[e4] != a[e5]) {
369.2797 +            /*
369.2798 +             * Use the second and fourth of the five sorted elements as pivots.
369.2799 +             * These values are inexpensive approximations of the first and
369.2800 +             * second terciles of the array. Note that pivot1 <= pivot2.
369.2801 +             */
369.2802 +            double pivot1 = a[e2];
369.2803 +            double pivot2 = a[e4];
369.2804 +
369.2805 +            /*
369.2806 +             * The first and the last elements to be sorted are moved to the
369.2807 +             * locations formerly occupied by the pivots. When partitioning
369.2808 +             * is complete, the pivots are swapped back into their final
369.2809 +             * positions, and excluded from subsequent sorting.
369.2810 +             */
369.2811 +            a[e2] = a[left];
369.2812 +            a[e4] = a[right];
369.2813 +
369.2814 +            /*
369.2815 +             * Skip elements, which are less or greater than pivot values.
369.2816 +             */
369.2817 +            while (a[++less] < pivot1);
369.2818 +            while (a[--great] > pivot2);
369.2819 +
369.2820 +            /*
369.2821 +             * Partitioning:
369.2822 +             *
369.2823 +             *   left part           center part                   right part
369.2824 +             * +--------------------------------------------------------------+
369.2825 +             * |  < pivot1  |  pivot1 <= && <= pivot2  |    ?    |  > pivot2  |
369.2826 +             * +--------------------------------------------------------------+
369.2827 +             *               ^                          ^       ^
369.2828 +             *               |                          |       |
369.2829 +             *              less                        k     great
369.2830 +             *
369.2831 +             * Invariants:
369.2832 +             *
369.2833 +             *              all in (left, less)   < pivot1
369.2834 +             *    pivot1 <= all in [less, k)     <= pivot2
369.2835 +             *              all in (great, right) > pivot2
369.2836 +             *
369.2837 +             * Pointer k is the first index of ?-part.
369.2838 +             */
369.2839 +            outer:
369.2840 +            for (int k = less - 1; ++k <= great; ) {
369.2841 +                double ak = a[k];
369.2842 +                if (ak < pivot1) { // Move a[k] to left part
369.2843 +                    a[k] = a[less];
369.2844 +                    /*
369.2845 +                     * Here and below we use "a[i] = b; i++;" instead
369.2846 +                     * of "a[i++] = b;" due to performance issue.
369.2847 +                     */
369.2848 +                    a[less] = ak;
369.2849 +                    ++less;
369.2850 +                } else if (ak > pivot2) { // Move a[k] to right part
369.2851 +                    while (a[great] > pivot2) {
369.2852 +                        if (great-- == k) {
369.2853 +                            break outer;
369.2854 +                        }
369.2855 +                    }
369.2856 +                    if (a[great] < pivot1) { // a[great] <= pivot2
369.2857 +                        a[k] = a[less];
369.2858 +                        a[less] = a[great];
369.2859 +                        ++less;
369.2860 +                    } else { // pivot1 <= a[great] <= pivot2
369.2861 +                        a[k] = a[great];
369.2862 +                    }
369.2863 +                    /*
369.2864 +                     * Here and below we use "a[i] = b; i--;" instead
369.2865 +                     * of "a[i--] = b;" due to performance issue.
369.2866 +                     */
369.2867 +                    a[great] = ak;
369.2868 +                    --great;
369.2869 +                }
369.2870 +            }
369.2871 +
369.2872 +            // Swap pivots into their final positions
369.2873 +            a[left]  = a[less  - 1]; a[less  - 1] = pivot1;
369.2874 +            a[right] = a[great + 1]; a[great + 1] = pivot2;
369.2875 +
369.2876 +            // Sort left and right parts recursively, excluding known pivots
369.2877 +            sort(a, left, less - 2, leftmost);
369.2878 +            sort(a, great + 2, right, false);
369.2879 +
369.2880 +            /*
369.2881 +             * If center part is too large (comprises > 4/7 of the array),
369.2882 +             * swap internal pivot values to ends.
369.2883 +             */
369.2884 +            if (less < e1 && e5 < great) {
369.2885 +                /*
369.2886 +                 * Skip elements, which are equal to pivot values.
369.2887 +                 */
369.2888 +                while (a[less] == pivot1) {
369.2889 +                    ++less;
369.2890 +                }
369.2891 +
369.2892 +                while (a[great] == pivot2) {
369.2893 +                    --great;
369.2894 +                }
369.2895 +
369.2896 +                /*
369.2897 +                 * Partitioning:
369.2898 +                 *
369.2899 +                 *   left part         center part                  right part
369.2900 +                 * +----------------------------------------------------------+
369.2901 +                 * | == pivot1 |  pivot1 < && < pivot2  |    ?    | == pivot2 |
369.2902 +                 * +----------------------------------------------------------+
369.2903 +                 *              ^                        ^       ^
369.2904 +                 *              |                        |       |
369.2905 +                 *             less                      k     great
369.2906 +                 *
369.2907 +                 * Invariants:
369.2908 +                 *
369.2909 +                 *              all in (*,  less) == pivot1
369.2910 +                 *     pivot1 < all in [less,  k)  < pivot2
369.2911 +                 *              all in (great, *) == pivot2
369.2912 +                 *
369.2913 +                 * Pointer k is the first index of ?-part.
369.2914 +                 */
369.2915 +                outer:
369.2916 +                for (int k = less - 1; ++k <= great; ) {
369.2917 +                    double ak = a[k];
369.2918 +                    if (ak == pivot1) { // Move a[k] to left part
369.2919 +                        a[k] = a[less];
369.2920 +                        a[less] = ak;
369.2921 +                        ++less;
369.2922 +                    } else if (ak == pivot2) { // Move a[k] to right part
369.2923 +                        while (a[great] == pivot2) {
369.2924 +                            if (great-- == k) {
369.2925 +                                break outer;
369.2926 +                            }
369.2927 +                        }
369.2928 +                        if (a[great] == pivot1) { // a[great] < pivot2
369.2929 +                            a[k] = a[less];
369.2930 +                            /*
369.2931 +                             * Even though a[great] equals to pivot1, the
369.2932 +                             * assignment a[less] = pivot1 may be incorrect,
369.2933 +                             * if a[great] and pivot1 are floating-point zeros
369.2934 +                             * of different signs. Therefore in float and
369.2935 +                             * double sorting methods we have to use more
369.2936 +                             * accurate assignment a[less] = a[great].
369.2937 +                             */
369.2938 +                            a[less] = a[great];
369.2939 +                            ++less;
369.2940 +                        } else { // pivot1 < a[great] < pivot2
369.2941 +                            a[k] = a[great];
369.2942 +                        }
369.2943 +                        a[great] = ak;
369.2944 +                        --great;
369.2945 +                    }
369.2946 +                }
369.2947 +            }
369.2948 +
369.2949 +            // Sort center part recursively
369.2950 +            sort(a, less, great, false);
369.2951 +
369.2952 +        } else { // Partitioning with one pivot
369.2953 +            /*
369.2954 +             * Use the third of the five sorted elements as pivot.
369.2955 +             * This value is inexpensive approximation of the median.
369.2956 +             */
369.2957 +            double pivot = a[e3];
369.2958 +
369.2959 +            /*
369.2960 +             * Partitioning degenerates to the traditional 3-way
369.2961 +             * (or "Dutch National Flag") schema:
369.2962 +             *
369.2963 +             *   left part    center part              right part
369.2964 +             * +-------------------------------------------------+
369.2965 +             * |  < pivot  |   == pivot   |     ?    |  > pivot  |
369.2966 +             * +-------------------------------------------------+
369.2967 +             *              ^              ^        ^
369.2968 +             *              |              |        |
369.2969 +             *             less            k      great
369.2970 +             *
369.2971 +             * Invariants:
369.2972 +             *
369.2973 +             *   all in (left, less)   < pivot
369.2974 +             *   all in [less, k)     == pivot
369.2975 +             *   all in (great, right) > pivot
369.2976 +             *
369.2977 +             * Pointer k is the first index of ?-part.
369.2978 +             */
369.2979 +            for (int k = less; k <= great; ++k) {
369.2980 +                if (a[k] == pivot) {
369.2981 +                    continue;
369.2982 +                }
369.2983 +                double ak = a[k];
369.2984 +                if (ak < pivot) { // Move a[k] to left part
369.2985 +                    a[k] = a[less];
369.2986 +                    a[less] = ak;
369.2987 +                    ++less;
369.2988 +                } else { // a[k] > pivot - Move a[k] to right part
369.2989 +                    while (a[great] > pivot) {
369.2990 +                        --great;
369.2991 +                    }
369.2992 +                    if (a[great] < pivot) { // a[great] <= pivot
369.2993 +                        a[k] = a[less];
369.2994 +                        a[less] = a[great];
369.2995 +                        ++less;
369.2996 +                    } else { // a[great] == pivot
369.2997 +                        /*
369.2998 +                         * Even though a[great] equals to pivot, the
369.2999 +                         * assignment a[k] = pivot may be incorrect,
369.3000 +                         * if a[great] and pivot are floating-point
369.3001 +                         * zeros of different signs. Therefore in float
369.3002 +                         * and double sorting methods we have to use
369.3003 +                         * more accurate assignment a[k] = a[great].
369.3004 +                         */
369.3005 +                        a[k] = a[great];
369.3006 +                    }
369.3007 +                    a[great] = ak;
369.3008 +                    --great;
369.3009 +                }
369.3010 +            }
369.3011 +
369.3012 +            /*
369.3013 +             * Sort left and right parts recursively.
369.3014 +             * All elements from center part are equal
369.3015 +             * and, therefore, already sorted.
369.3016 +             */
369.3017 +            sort(a, left, less - 1, leftmost);
369.3018 +            sort(a, great + 1, right, false);
369.3019 +        }
369.3020 +    }
369.3021 +}
   370.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   370.2 +++ b/rt/emul/compact/src/main/java/java/util/EmptyStackException.java	Wed Feb 27 11:24:58 2013 +0100
   370.3 @@ -0,0 +1,46 @@
   370.4 +/*
   370.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   370.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   370.7 + *
   370.8 + * This code is free software; you can redistribute it and/or modify it
   370.9 + * under the terms of the GNU General Public License version 2 only, as
  370.10 + * published by the Free Software Foundation.  Oracle designates this
  370.11 + * particular file as subject to the "Classpath" exception as provided
  370.12 + * by Oracle in the LICENSE file that accompanied this code.
  370.13 + *
  370.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  370.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  370.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  370.17 + * version 2 for more details (a copy is included in the LICENSE file that
  370.18 + * accompanied this code).
  370.19 + *
  370.20 + * You should have received a copy of the GNU General Public License version
  370.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  370.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  370.23 + *
  370.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  370.25 + * or visit www.oracle.com if you need additional information or have any
  370.26 + * questions.
  370.27 + */
  370.28 +
  370.29 +package java.util;
  370.30 +
  370.31 +/**
  370.32 + * Thrown by methods in the <code>Stack</code> class to indicate
  370.33 + * that the stack is empty.
  370.34 + *
  370.35 + * @author  Jonathan Payne
  370.36 + * @see     java.util.Stack
  370.37 + * @since   JDK1.0
  370.38 + */
  370.39 +public
  370.40 +class EmptyStackException extends RuntimeException {
  370.41 +    private static final long serialVersionUID = 5084686378493302095L;
  370.42 +
  370.43 +    /**
  370.44 +     * Constructs a new <code>EmptyStackException</code> with <tt>null</tt>
  370.45 +     * as its error message string.
  370.46 +     */
  370.47 +    public EmptyStackException() {
  370.48 +    }
  370.49 +}
   371.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   371.2 +++ b/rt/emul/compact/src/main/java/java/util/EventListener.java	Wed Feb 27 11:24:58 2013 +0100
   371.3 @@ -0,0 +1,33 @@
   371.4 +/*
   371.5 + * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
   371.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   371.7 + *
   371.8 + * This code is free software; you can redistribute it and/or modify it
   371.9 + * under the terms of the GNU General Public License version 2 only, as
  371.10 + * published by the Free Software Foundation.  Oracle designates this
  371.11 + * particular file as subject to the "Classpath" exception as provided
  371.12 + * by Oracle in the LICENSE file that accompanied this code.
  371.13 + *
  371.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  371.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  371.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  371.17 + * version 2 for more details (a copy is included in the LICENSE file that
  371.18 + * accompanied this code).
  371.19 + *
  371.20 + * You should have received a copy of the GNU General Public License version
  371.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  371.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  371.23 + *
  371.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  371.25 + * or visit www.oracle.com if you need additional information or have any
  371.26 + * questions.
  371.27 + */
  371.28 +
  371.29 +package java.util;
  371.30 +
  371.31 +/**
  371.32 + * A tagging interface that all event listener interfaces must extend.
  371.33 + * @since JDK1.1
  371.34 + */
  371.35 +public interface EventListener {
  371.36 +}
   372.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   372.2 +++ b/rt/emul/compact/src/main/java/java/util/EventListenerProxy.java	Wed Feb 27 11:24:58 2013 +0100
   372.3 @@ -0,0 +1,75 @@
   372.4 +/*
   372.5 + * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
   372.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   372.7 + *
   372.8 + * This code is free software; you can redistribute it and/or modify it
   372.9 + * under the terms of the GNU General Public License version 2 only, as
  372.10 + * published by the Free Software Foundation.  Oracle designates this
  372.11 + * particular file as subject to the "Classpath" exception as provided
  372.12 + * by Oracle in the LICENSE file that accompanied this code.
  372.13 + *
  372.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  372.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  372.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  372.17 + * version 2 for more details (a copy is included in the LICENSE file that
  372.18 + * accompanied this code).
  372.19 + *
  372.20 + * You should have received a copy of the GNU General Public License version
  372.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  372.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  372.23 + *
  372.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  372.25 + * or visit www.oracle.com if you need additional information or have any
  372.26 + * questions.
  372.27 + */
  372.28 +
  372.29 +package java.util;
  372.30 +
  372.31 +/**
  372.32 + * An abstract wrapper class for an {@code EventListener} class
  372.33 + * which associates a set of additional parameters with the listener.
  372.34 + * Subclasses must provide the storage and accessor methods
  372.35 + * for the additional arguments or parameters.
  372.36 + * <p>
  372.37 + * For example, a bean which supports named properties
  372.38 + * would have a two argument method signature for adding
  372.39 + * a {@code PropertyChangeListener} for a property:
  372.40 + * <pre>
  372.41 + * public void addPropertyChangeListener(String propertyName,
  372.42 + *                                       PropertyChangeListener listener)
  372.43 + * </pre>
  372.44 + * If the bean also implemented the zero argument get listener method:
  372.45 + * <pre>
  372.46 + * public PropertyChangeListener[] getPropertyChangeListeners()
  372.47 + * </pre>
  372.48 + * then the array may contain inner {@code PropertyChangeListeners}
  372.49 + * which are also {@code PropertyChangeListenerProxy} objects.
  372.50 + * <p>
  372.51 + * If the calling method is interested in retrieving the named property
  372.52 + * then it would have to test the element to see if it is a proxy class.
  372.53 + *
  372.54 + * @since 1.4
  372.55 + */
  372.56 +public abstract class EventListenerProxy<T extends EventListener>
  372.57 +        implements EventListener {
  372.58 +
  372.59 +    private final T listener;
  372.60 +
  372.61 +    /**
  372.62 +     * Creates a proxy for the specified listener.
  372.63 +     *
  372.64 +     * @param listener  the listener object
  372.65 +     */
  372.66 +    public EventListenerProxy(T listener) {
  372.67 +        this.listener = listener;
  372.68 +    }
  372.69 +
  372.70 +    /**
  372.71 +     * Returns the listener associated with the proxy.
  372.72 +     *
  372.73 +     * @return  the listener associated with the proxy
  372.74 +     */
  372.75 +    public T getListener() {
  372.76 +        return this.listener;
  372.77 +    }
  372.78 +}
   373.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   373.2 +++ b/rt/emul/compact/src/main/java/java/util/EventObject.java	Wed Feb 27 11:24:58 2013 +0100
   373.3 @@ -0,0 +1,78 @@
   373.4 +/*
   373.5 + * Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
   373.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   373.7 + *
   373.8 + * This code is free software; you can redistribute it and/or modify it
   373.9 + * under the terms of the GNU General Public License version 2 only, as
  373.10 + * published by the Free Software Foundation.  Oracle designates this
  373.11 + * particular file as subject to the "Classpath" exception as provided
  373.12 + * by Oracle in the LICENSE file that accompanied this code.
  373.13 + *
  373.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  373.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  373.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  373.17 + * version 2 for more details (a copy is included in the LICENSE file that
  373.18 + * accompanied this code).
  373.19 + *
  373.20 + * You should have received a copy of the GNU General Public License version
  373.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  373.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  373.23 + *
  373.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  373.25 + * or visit www.oracle.com if you need additional information or have any
  373.26 + * questions.
  373.27 + */
  373.28 +
  373.29 +package java.util;
  373.30 +
  373.31 +/**
  373.32 + * <p>
  373.33 + * The root class from which all event state objects shall be derived.
  373.34 + * <p>
  373.35 + * All Events are constructed with a reference to the object, the "source",
  373.36 + * that is logically deemed to be the object upon which the Event in question
  373.37 + * initially occurred upon.
  373.38 + *
  373.39 + * @since JDK1.1
  373.40 + */
  373.41 +
  373.42 +public class EventObject implements java.io.Serializable {
  373.43 +
  373.44 +    private static final long serialVersionUID = 5516075349620653480L;
  373.45 +
  373.46 +    /**
  373.47 +     * The object on which the Event initially occurred.
  373.48 +     */
  373.49 +    protected transient Object  source;
  373.50 +
  373.51 +    /**
  373.52 +     * Constructs a prototypical Event.
  373.53 +     *
  373.54 +     * @param    source    The object on which the Event initially occurred.
  373.55 +     * @exception  IllegalArgumentException  if source is null.
  373.56 +     */
  373.57 +    public EventObject(Object source) {
  373.58 +        if (source == null)
  373.59 +            throw new IllegalArgumentException("null source");
  373.60 +
  373.61 +        this.source = source;
  373.62 +    }
  373.63 +
  373.64 +    /**
  373.65 +     * The object on which the Event initially occurred.
  373.66 +     *
  373.67 +     * @return   The object on which the Event initially occurred.
  373.68 +     */
  373.69 +    public Object getSource() {
  373.70 +        return source;
  373.71 +    }
  373.72 +
  373.73 +    /**
  373.74 +     * Returns a String representation of this EventObject.
  373.75 +     *
  373.76 +     * @return  A a String representation of this EventObject.
  373.77 +     */
  373.78 +    public String toString() {
  373.79 +        return getClass().getName() + "[source=" + source + "]";
  373.80 +    }
  373.81 +}
   374.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   374.2 +++ b/rt/emul/compact/src/main/java/java/util/HashMap.java	Wed Feb 27 11:24:58 2013 +0100
   374.3 @@ -0,0 +1,990 @@
   374.4 +/*
   374.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   374.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   374.7 + *
   374.8 + * This code is free software; you can redistribute it and/or modify it
   374.9 + * under the terms of the GNU General Public License version 2 only, as
  374.10 + * published by the Free Software Foundation.  Oracle designates this
  374.11 + * particular file as subject to the "Classpath" exception as provided
  374.12 + * by Oracle in the LICENSE file that accompanied this code.
  374.13 + *
  374.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  374.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  374.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  374.17 + * version 2 for more details (a copy is included in the LICENSE file that
  374.18 + * accompanied this code).
  374.19 + *
  374.20 + * You should have received a copy of the GNU General Public License version
  374.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  374.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  374.23 + *
  374.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  374.25 + * or visit www.oracle.com if you need additional information or have any
  374.26 + * questions.
  374.27 + */
  374.28 +
  374.29 +package java.util;
  374.30 +import java.io.*;
  374.31 +
  374.32 +/**
  374.33 + * Hash table based implementation of the <tt>Map</tt> interface.  This
  374.34 + * implementation provides all of the optional map operations, and permits
  374.35 + * <tt>null</tt> values and the <tt>null</tt> key.  (The <tt>HashMap</tt>
  374.36 + * class is roughly equivalent to <tt>Hashtable</tt>, except that it is
  374.37 + * unsynchronized and permits nulls.)  This class makes no guarantees as to
  374.38 + * the order of the map; in particular, it does not guarantee that the order
  374.39 + * will remain constant over time.
  374.40 + *
  374.41 + * <p>This implementation provides constant-time performance for the basic
  374.42 + * operations (<tt>get</tt> and <tt>put</tt>), assuming the hash function
  374.43 + * disperses the elements properly among the buckets.  Iteration over
  374.44 + * collection views requires time proportional to the "capacity" of the
  374.45 + * <tt>HashMap</tt> instance (the number of buckets) plus its size (the number
  374.46 + * of key-value mappings).  Thus, it's very important not to set the initial
  374.47 + * capacity too high (or the load factor too low) if iteration performance is
  374.48 + * important.
  374.49 + *
  374.50 + * <p>An instance of <tt>HashMap</tt> has two parameters that affect its
  374.51 + * performance: <i>initial capacity</i> and <i>load factor</i>.  The
  374.52 + * <i>capacity</i> is the number of buckets in the hash table, and the initial
  374.53 + * capacity is simply the capacity at the time the hash table is created.  The
  374.54 + * <i>load factor</i> is a measure of how full the hash table is allowed to
  374.55 + * get before its capacity is automatically increased.  When the number of
  374.56 + * entries in the hash table exceeds the product of the load factor and the
  374.57 + * current capacity, the hash table is <i>rehashed</i> (that is, internal data
  374.58 + * structures are rebuilt) so that the hash table has approximately twice the
  374.59 + * number of buckets.
  374.60 + *
  374.61 + * <p>As a general rule, the default load factor (.75) offers a good tradeoff
  374.62 + * between time and space costs.  Higher values decrease the space overhead
  374.63 + * but increase the lookup cost (reflected in most of the operations of the
  374.64 + * <tt>HashMap</tt> class, including <tt>get</tt> and <tt>put</tt>).  The
  374.65 + * expected number of entries in the map and its load factor should be taken
  374.66 + * into account when setting its initial capacity, so as to minimize the
  374.67 + * number of rehash operations.  If the initial capacity is greater
  374.68 + * than the maximum number of entries divided by the load factor, no
  374.69 + * rehash operations will ever occur.
  374.70 + *
  374.71 + * <p>If many mappings are to be stored in a <tt>HashMap</tt> instance,
  374.72 + * creating it with a sufficiently large capacity will allow the mappings to
  374.73 + * be stored more efficiently than letting it perform automatic rehashing as
  374.74 + * needed to grow the table.
  374.75 + *
  374.76 + * <p><strong>Note that this implementation is not synchronized.</strong>
  374.77 + * If multiple threads access a hash map concurrently, and at least one of
  374.78 + * the threads modifies the map structurally, it <i>must</i> be
  374.79 + * synchronized externally.  (A structural modification is any operation
  374.80 + * that adds or deletes one or more mappings; merely changing the value
  374.81 + * associated with a key that an instance already contains is not a
  374.82 + * structural modification.)  This is typically accomplished by
  374.83 + * synchronizing on some object that naturally encapsulates the map.
  374.84 + *
  374.85 + * If no such object exists, the map should be "wrapped" using the
  374.86 + * {@link Collections#synchronizedMap Collections.synchronizedMap}
  374.87 + * method.  This is best done at creation time, to prevent accidental
  374.88 + * unsynchronized access to the map:<pre>
  374.89 + *   Map m = Collections.synchronizedMap(new HashMap(...));</pre>
  374.90 + *
  374.91 + * <p>The iterators returned by all of this class's "collection view methods"
  374.92 + * are <i>fail-fast</i>: if the map is structurally modified at any time after
  374.93 + * the iterator is created, in any way except through the iterator's own
  374.94 + * <tt>remove</tt> method, the iterator will throw a
  374.95 + * {@link ConcurrentModificationException}.  Thus, in the face of concurrent
  374.96 + * modification, the iterator fails quickly and cleanly, rather than risking
  374.97 + * arbitrary, non-deterministic behavior at an undetermined time in the
  374.98 + * future.
  374.99 + *
 374.100 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
 374.101 + * as it is, generally speaking, impossible to make any hard guarantees in the
 374.102 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
 374.103 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
 374.104 + * Therefore, it would be wrong to write a program that depended on this
 374.105 + * exception for its correctness: <i>the fail-fast behavior of iterators
 374.106 + * should be used only to detect bugs.</i>
 374.107 + *
 374.108 + * <p>This class is a member of the
 374.109 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 374.110 + * Java Collections Framework</a>.
 374.111 + *
 374.112 + * @param <K> the type of keys maintained by this map
 374.113 + * @param <V> the type of mapped values
 374.114 + *
 374.115 + * @author  Doug Lea
 374.116 + * @author  Josh Bloch
 374.117 + * @author  Arthur van Hoff
 374.118 + * @author  Neal Gafter
 374.119 + * @see     Object#hashCode()
 374.120 + * @see     Collection
 374.121 + * @see     Map
 374.122 + * @see     TreeMap
 374.123 + * @see     Hashtable
 374.124 + * @since   1.2
 374.125 + */
 374.126 +
 374.127 +public class HashMap<K,V>
 374.128 +    extends AbstractMap<K,V>
 374.129 +    implements Map<K,V>, Cloneable, Serializable
 374.130 +{
 374.131 +
 374.132 +    /**
 374.133 +     * The default initial capacity - MUST be a power of two.
 374.134 +     */
 374.135 +    static final int DEFAULT_INITIAL_CAPACITY = 16;
 374.136 +
 374.137 +    /**
 374.138 +     * The maximum capacity, used if a higher value is implicitly specified
 374.139 +     * by either of the constructors with arguments.
 374.140 +     * MUST be a power of two <= 1<<30.
 374.141 +     */
 374.142 +    static final int MAXIMUM_CAPACITY = 1 << 30;
 374.143 +
 374.144 +    /**
 374.145 +     * The load factor used when none specified in constructor.
 374.146 +     */
 374.147 +    static final float DEFAULT_LOAD_FACTOR = 0.75f;
 374.148 +
 374.149 +    /**
 374.150 +     * The table, resized as necessary. Length MUST Always be a power of two.
 374.151 +     */
 374.152 +    transient Entry[] table;
 374.153 +
 374.154 +    /**
 374.155 +     * The number of key-value mappings contained in this map.
 374.156 +     */
 374.157 +    transient int size;
 374.158 +
 374.159 +    /**
 374.160 +     * The next size value at which to resize (capacity * load factor).
 374.161 +     * @serial
 374.162 +     */
 374.163 +    int threshold;
 374.164 +
 374.165 +    /**
 374.166 +     * The load factor for the hash table.
 374.167 +     *
 374.168 +     * @serial
 374.169 +     */
 374.170 +    final float loadFactor;
 374.171 +
 374.172 +    /**
 374.173 +     * The number of times this HashMap has been structurally modified
 374.174 +     * Structural modifications are those that change the number of mappings in
 374.175 +     * the HashMap or otherwise modify its internal structure (e.g.,
 374.176 +     * rehash).  This field is used to make iterators on Collection-views of
 374.177 +     * the HashMap fail-fast.  (See ConcurrentModificationException).
 374.178 +     */
 374.179 +    transient int modCount;
 374.180 +
 374.181 +    /**
 374.182 +     * Constructs an empty <tt>HashMap</tt> with the specified initial
 374.183 +     * capacity and load factor.
 374.184 +     *
 374.185 +     * @param  initialCapacity the initial capacity
 374.186 +     * @param  loadFactor      the load factor
 374.187 +     * @throws IllegalArgumentException if the initial capacity is negative
 374.188 +     *         or the load factor is nonpositive
 374.189 +     */
 374.190 +    public HashMap(int initialCapacity, float loadFactor) {
 374.191 +        if (initialCapacity < 0)
 374.192 +            throw new IllegalArgumentException("Illegal initial capacity: " +
 374.193 +                                               initialCapacity);
 374.194 +        if (initialCapacity > MAXIMUM_CAPACITY)
 374.195 +            initialCapacity = MAXIMUM_CAPACITY;
 374.196 +        if (loadFactor <= 0 || Float.isNaN(loadFactor))
 374.197 +            throw new IllegalArgumentException("Illegal load factor: " +
 374.198 +                                               loadFactor);
 374.199 +
 374.200 +        // Find a power of 2 >= initialCapacity
 374.201 +        int capacity = 1;
 374.202 +        while (capacity < initialCapacity)
 374.203 +            capacity <<= 1;
 374.204 +
 374.205 +        this.loadFactor = loadFactor;
 374.206 +        threshold = (int)(capacity * loadFactor);
 374.207 +        table = new Entry[capacity];
 374.208 +        init();
 374.209 +    }
 374.210 +
 374.211 +    /**
 374.212 +     * Constructs an empty <tt>HashMap</tt> with the specified initial
 374.213 +     * capacity and the default load factor (0.75).
 374.214 +     *
 374.215 +     * @param  initialCapacity the initial capacity.
 374.216 +     * @throws IllegalArgumentException if the initial capacity is negative.
 374.217 +     */
 374.218 +    public HashMap(int initialCapacity) {
 374.219 +        this(initialCapacity, DEFAULT_LOAD_FACTOR);
 374.220 +    }
 374.221 +
 374.222 +    /**
 374.223 +     * Constructs an empty <tt>HashMap</tt> with the default initial capacity
 374.224 +     * (16) and the default load factor (0.75).
 374.225 +     */
 374.226 +    public HashMap() {
 374.227 +        this.loadFactor = DEFAULT_LOAD_FACTOR;
 374.228 +        threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
 374.229 +        table = new Entry[DEFAULT_INITIAL_CAPACITY];
 374.230 +        init();
 374.231 +    }
 374.232 +
 374.233 +    /**
 374.234 +     * Constructs a new <tt>HashMap</tt> with the same mappings as the
 374.235 +     * specified <tt>Map</tt>.  The <tt>HashMap</tt> is created with
 374.236 +     * default load factor (0.75) and an initial capacity sufficient to
 374.237 +     * hold the mappings in the specified <tt>Map</tt>.
 374.238 +     *
 374.239 +     * @param   m the map whose mappings are to be placed in this map
 374.240 +     * @throws  NullPointerException if the specified map is null
 374.241 +     */
 374.242 +    public HashMap(Map<? extends K, ? extends V> m) {
 374.243 +        this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1,
 374.244 +                      DEFAULT_INITIAL_CAPACITY), DEFAULT_LOAD_FACTOR);
 374.245 +        putAllForCreate(m);
 374.246 +    }
 374.247 +
 374.248 +    // internal utilities
 374.249 +
 374.250 +    /**
 374.251 +     * Initialization hook for subclasses. This method is called
 374.252 +     * in all constructors and pseudo-constructors (clone, readObject)
 374.253 +     * after HashMap has been initialized but before any entries have
 374.254 +     * been inserted.  (In the absence of this method, readObject would
 374.255 +     * require explicit knowledge of subclasses.)
 374.256 +     */
 374.257 +    void init() {
 374.258 +    }
 374.259 +
 374.260 +    /**
 374.261 +     * Applies a supplemental hash function to a given hashCode, which
 374.262 +     * defends against poor quality hash functions.  This is critical
 374.263 +     * because HashMap uses power-of-two length hash tables, that
 374.264 +     * otherwise encounter collisions for hashCodes that do not differ
 374.265 +     * in lower bits. Note: Null keys always map to hash 0, thus index 0.
 374.266 +     */
 374.267 +    static int hash(int h) {
 374.268 +        // This function ensures that hashCodes that differ only by
 374.269 +        // constant multiples at each bit position have a bounded
 374.270 +        // number of collisions (approximately 8 at default load factor).
 374.271 +        h ^= (h >>> 20) ^ (h >>> 12);
 374.272 +        return h ^ (h >>> 7) ^ (h >>> 4);
 374.273 +    }
 374.274 +
 374.275 +    /**
 374.276 +     * Returns index for hash code h.
 374.277 +     */
 374.278 +    static int indexFor(int h, int length) {
 374.279 +        return h & (length-1);
 374.280 +    }
 374.281 +
 374.282 +    /**
 374.283 +     * Returns the number of key-value mappings in this map.
 374.284 +     *
 374.285 +     * @return the number of key-value mappings in this map
 374.286 +     */
 374.287 +    public int size() {
 374.288 +        return size;
 374.289 +    }
 374.290 +
 374.291 +    /**
 374.292 +     * Returns <tt>true</tt> if this map contains no key-value mappings.
 374.293 +     *
 374.294 +     * @return <tt>true</tt> if this map contains no key-value mappings
 374.295 +     */
 374.296 +    public boolean isEmpty() {
 374.297 +        return size == 0;
 374.298 +    }
 374.299 +
 374.300 +    /**
 374.301 +     * Returns the value to which the specified key is mapped,
 374.302 +     * or {@code null} if this map contains no mapping for the key.
 374.303 +     *
 374.304 +     * <p>More formally, if this map contains a mapping from a key
 374.305 +     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
 374.306 +     * key.equals(k))}, then this method returns {@code v}; otherwise
 374.307 +     * it returns {@code null}.  (There can be at most one such mapping.)
 374.308 +     *
 374.309 +     * <p>A return value of {@code null} does not <i>necessarily</i>
 374.310 +     * indicate that the map contains no mapping for the key; it's also
 374.311 +     * possible that the map explicitly maps the key to {@code null}.
 374.312 +     * The {@link #containsKey containsKey} operation may be used to
 374.313 +     * distinguish these two cases.
 374.314 +     *
 374.315 +     * @see #put(Object, Object)
 374.316 +     */
 374.317 +    public V get(Object key) {
 374.318 +        if (key == null)
 374.319 +            return getForNullKey();
 374.320 +        int hash = hash(key.hashCode());
 374.321 +        for (Entry<K,V> e = table[indexFor(hash, table.length)];
 374.322 +             e != null;
 374.323 +             e = e.next) {
 374.324 +            Object k;
 374.325 +            if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
 374.326 +                return e.value;
 374.327 +        }
 374.328 +        return null;
 374.329 +    }
 374.330 +
 374.331 +    /**
 374.332 +     * Offloaded version of get() to look up null keys.  Null keys map
 374.333 +     * to index 0.  This null case is split out into separate methods
 374.334 +     * for the sake of performance in the two most commonly used
 374.335 +     * operations (get and put), but incorporated with conditionals in
 374.336 +     * others.
 374.337 +     */
 374.338 +    private V getForNullKey() {
 374.339 +        for (Entry<K,V> e = table[0]; e != null; e = e.next) {
 374.340 +            if (e.key == null)
 374.341 +                return e.value;
 374.342 +        }
 374.343 +        return null;
 374.344 +    }
 374.345 +
 374.346 +    /**
 374.347 +     * Returns <tt>true</tt> if this map contains a mapping for the
 374.348 +     * specified key.
 374.349 +     *
 374.350 +     * @param   key   The key whose presence in this map is to be tested
 374.351 +     * @return <tt>true</tt> if this map contains a mapping for the specified
 374.352 +     * key.
 374.353 +     */
 374.354 +    public boolean containsKey(Object key) {
 374.355 +        return getEntry(key) != null;
 374.356 +    }
 374.357 +
 374.358 +    /**
 374.359 +     * Returns the entry associated with the specified key in the
 374.360 +     * HashMap.  Returns null if the HashMap contains no mapping
 374.361 +     * for the key.
 374.362 +     */
 374.363 +    final Entry<K,V> getEntry(Object key) {
 374.364 +        int hash = (key == null) ? 0 : hash(key.hashCode());
 374.365 +        for (Entry<K,V> e = table[indexFor(hash, table.length)];
 374.366 +             e != null;
 374.367 +             e = e.next) {
 374.368 +            Object k;
 374.369 +            if (e.hash == hash &&
 374.370 +                ((k = e.key) == key || (key != null && key.equals(k))))
 374.371 +                return e;
 374.372 +        }
 374.373 +        return null;
 374.374 +    }
 374.375 +
 374.376 +
 374.377 +    /**
 374.378 +     * Associates the specified value with the specified key in this map.
 374.379 +     * If the map previously contained a mapping for the key, the old
 374.380 +     * value is replaced.
 374.381 +     *
 374.382 +     * @param key key with which the specified value is to be associated
 374.383 +     * @param value value to be associated with the specified key
 374.384 +     * @return the previous value associated with <tt>key</tt>, or
 374.385 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 374.386 +     *         (A <tt>null</tt> return can also indicate that the map
 374.387 +     *         previously associated <tt>null</tt> with <tt>key</tt>.)
 374.388 +     */
 374.389 +    public V put(K key, V value) {
 374.390 +        if (key == null)
 374.391 +            return putForNullKey(value);
 374.392 +        int hash = hash(key.hashCode());
 374.393 +        int i = indexFor(hash, table.length);
 374.394 +        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
 374.395 +            Object k;
 374.396 +            if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
 374.397 +                V oldValue = e.value;
 374.398 +                e.value = value;
 374.399 +                e.recordAccess(this);
 374.400 +                return oldValue;
 374.401 +            }
 374.402 +        }
 374.403 +
 374.404 +        modCount++;
 374.405 +        addEntry(hash, key, value, i);
 374.406 +        return null;
 374.407 +    }
 374.408 +
 374.409 +    /**
 374.410 +     * Offloaded version of put for null keys
 374.411 +     */
 374.412 +    private V putForNullKey(V value) {
 374.413 +        for (Entry<K,V> e = table[0]; e != null; e = e.next) {
 374.414 +            if (e.key == null) {
 374.415 +                V oldValue = e.value;
 374.416 +                e.value = value;
 374.417 +                e.recordAccess(this);
 374.418 +                return oldValue;
 374.419 +            }
 374.420 +        }
 374.421 +        modCount++;
 374.422 +        addEntry(0, null, value, 0);
 374.423 +        return null;
 374.424 +    }
 374.425 +
 374.426 +    /**
 374.427 +     * This method is used instead of put by constructors and
 374.428 +     * pseudoconstructors (clone, readObject).  It does not resize the table,
 374.429 +     * check for comodification, etc.  It calls createEntry rather than
 374.430 +     * addEntry.
 374.431 +     */
 374.432 +    private void putForCreate(K key, V value) {
 374.433 +        int hash = (key == null) ? 0 : hash(key.hashCode());
 374.434 +        int i = indexFor(hash, table.length);
 374.435 +
 374.436 +        /**
 374.437 +         * Look for preexisting entry for key.  This will never happen for
 374.438 +         * clone or deserialize.  It will only happen for construction if the
 374.439 +         * input Map is a sorted map whose ordering is inconsistent w/ equals.
 374.440 +         */
 374.441 +        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
 374.442 +            Object k;
 374.443 +            if (e.hash == hash &&
 374.444 +                ((k = e.key) == key || (key != null && key.equals(k)))) {
 374.445 +                e.value = value;
 374.446 +                return;
 374.447 +            }
 374.448 +        }
 374.449 +
 374.450 +        createEntry(hash, key, value, i);
 374.451 +    }
 374.452 +
 374.453 +    private void putAllForCreate(Map<? extends K, ? extends V> m) {
 374.454 +        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
 374.455 +            putForCreate(e.getKey(), e.getValue());
 374.456 +    }
 374.457 +
 374.458 +    /**
 374.459 +     * Rehashes the contents of this map into a new array with a
 374.460 +     * larger capacity.  This method is called automatically when the
 374.461 +     * number of keys in this map reaches its threshold.
 374.462 +     *
 374.463 +     * If current capacity is MAXIMUM_CAPACITY, this method does not
 374.464 +     * resize the map, but sets threshold to Integer.MAX_VALUE.
 374.465 +     * This has the effect of preventing future calls.
 374.466 +     *
 374.467 +     * @param newCapacity the new capacity, MUST be a power of two;
 374.468 +     *        must be greater than current capacity unless current
 374.469 +     *        capacity is MAXIMUM_CAPACITY (in which case value
 374.470 +     *        is irrelevant).
 374.471 +     */
 374.472 +    void resize(int newCapacity) {
 374.473 +        Entry[] oldTable = table;
 374.474 +        int oldCapacity = oldTable.length;
 374.475 +        if (oldCapacity == MAXIMUM_CAPACITY) {
 374.476 +            threshold = Integer.MAX_VALUE;
 374.477 +            return;
 374.478 +        }
 374.479 +
 374.480 +        Entry[] newTable = new Entry[newCapacity];
 374.481 +        transfer(newTable);
 374.482 +        table = newTable;
 374.483 +        threshold = (int)(newCapacity * loadFactor);
 374.484 +    }
 374.485 +
 374.486 +    /**
 374.487 +     * Transfers all entries from current table to newTable.
 374.488 +     */
 374.489 +    void transfer(Entry[] newTable) {
 374.490 +        Entry[] src = table;
 374.491 +        int newCapacity = newTable.length;
 374.492 +        for (int j = 0; j < src.length; j++) {
 374.493 +            Entry<K,V> e = src[j];
 374.494 +            if (e != null) {
 374.495 +                src[j] = null;
 374.496 +                do {
 374.497 +                    Entry<K,V> next = e.next;
 374.498 +                    int i = indexFor(e.hash, newCapacity);
 374.499 +                    e.next = newTable[i];
 374.500 +                    newTable[i] = e;
 374.501 +                    e = next;
 374.502 +                } while (e != null);
 374.503 +            }
 374.504 +        }
 374.505 +    }
 374.506 +
 374.507 +    /**
 374.508 +     * Copies all of the mappings from the specified map to this map.
 374.509 +     * These mappings will replace any mappings that this map had for
 374.510 +     * any of the keys currently in the specified map.
 374.511 +     *
 374.512 +     * @param m mappings to be stored in this map
 374.513 +     * @throws NullPointerException if the specified map is null
 374.514 +     */
 374.515 +    public void putAll(Map<? extends K, ? extends V> m) {
 374.516 +        int numKeysToBeAdded = m.size();
 374.517 +        if (numKeysToBeAdded == 0)
 374.518 +            return;
 374.519 +
 374.520 +        /*
 374.521 +         * Expand the map if the map if the number of mappings to be added
 374.522 +         * is greater than or equal to threshold.  This is conservative; the
 374.523 +         * obvious condition is (m.size() + size) >= threshold, but this
 374.524 +         * condition could result in a map with twice the appropriate capacity,
 374.525 +         * if the keys to be added overlap with the keys already in this map.
 374.526 +         * By using the conservative calculation, we subject ourself
 374.527 +         * to at most one extra resize.
 374.528 +         */
 374.529 +        if (numKeysToBeAdded > threshold) {
 374.530 +            int targetCapacity = (int)(numKeysToBeAdded / loadFactor + 1);
 374.531 +            if (targetCapacity > MAXIMUM_CAPACITY)
 374.532 +                targetCapacity = MAXIMUM_CAPACITY;
 374.533 +            int newCapacity = table.length;
 374.534 +            while (newCapacity < targetCapacity)
 374.535 +                newCapacity <<= 1;
 374.536 +            if (newCapacity > table.length)
 374.537 +                resize(newCapacity);
 374.538 +        }
 374.539 +
 374.540 +        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
 374.541 +            put(e.getKey(), e.getValue());
 374.542 +    }
 374.543 +
 374.544 +    /**
 374.545 +     * Removes the mapping for the specified key from this map if present.
 374.546 +     *
 374.547 +     * @param  key key whose mapping is to be removed from the map
 374.548 +     * @return the previous value associated with <tt>key</tt>, or
 374.549 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 374.550 +     *         (A <tt>null</tt> return can also indicate that the map
 374.551 +     *         previously associated <tt>null</tt> with <tt>key</tt>.)
 374.552 +     */
 374.553 +    public V remove(Object key) {
 374.554 +        Entry<K,V> e = removeEntryForKey(key);
 374.555 +        return (e == null ? null : e.value);
 374.556 +    }
 374.557 +
 374.558 +    /**
 374.559 +     * Removes and returns the entry associated with the specified key
 374.560 +     * in the HashMap.  Returns null if the HashMap contains no mapping
 374.561 +     * for this key.
 374.562 +     */
 374.563 +    final Entry<K,V> removeEntryForKey(Object key) {
 374.564 +        int hash = (key == null) ? 0 : hash(key.hashCode());
 374.565 +        int i = indexFor(hash, table.length);
 374.566 +        Entry<K,V> prev = table[i];
 374.567 +        Entry<K,V> e = prev;
 374.568 +
 374.569 +        while (e != null) {
 374.570 +            Entry<K,V> next = e.next;
 374.571 +            Object k;
 374.572 +            if (e.hash == hash &&
 374.573 +                ((k = e.key) == key || (key != null && key.equals(k)))) {
 374.574 +                modCount++;
 374.575 +                size--;
 374.576 +                if (prev == e)
 374.577 +                    table[i] = next;
 374.578 +                else
 374.579 +                    prev.next = next;
 374.580 +                e.recordRemoval(this);
 374.581 +                return e;
 374.582 +            }
 374.583 +            prev = e;
 374.584 +            e = next;
 374.585 +        }
 374.586 +
 374.587 +        return e;
 374.588 +    }
 374.589 +
 374.590 +    /**
 374.591 +     * Special version of remove for EntrySet.
 374.592 +     */
 374.593 +    final Entry<K,V> removeMapping(Object o) {
 374.594 +        if (!(o instanceof Map.Entry))
 374.595 +            return null;
 374.596 +
 374.597 +        Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
 374.598 +        Object key = entry.getKey();
 374.599 +        int hash = (key == null) ? 0 : hash(key.hashCode());
 374.600 +        int i = indexFor(hash, table.length);
 374.601 +        Entry<K,V> prev = table[i];
 374.602 +        Entry<K,V> e = prev;
 374.603 +
 374.604 +        while (e != null) {
 374.605 +            Entry<K,V> next = e.next;
 374.606 +            if (e.hash == hash && e.equals(entry)) {
 374.607 +                modCount++;
 374.608 +                size--;
 374.609 +                if (prev == e)
 374.610 +                    table[i] = next;
 374.611 +                else
 374.612 +                    prev.next = next;
 374.613 +                e.recordRemoval(this);
 374.614 +                return e;
 374.615 +            }
 374.616 +            prev = e;
 374.617 +            e = next;
 374.618 +        }
 374.619 +
 374.620 +        return e;
 374.621 +    }
 374.622 +
 374.623 +    /**
 374.624 +     * Removes all of the mappings from this map.
 374.625 +     * The map will be empty after this call returns.
 374.626 +     */
 374.627 +    public void clear() {
 374.628 +        modCount++;
 374.629 +        Entry[] tab = table;
 374.630 +        for (int i = 0; i < tab.length; i++)
 374.631 +            tab[i] = null;
 374.632 +        size = 0;
 374.633 +    }
 374.634 +
 374.635 +    /**
 374.636 +     * Returns <tt>true</tt> if this map maps one or more keys to the
 374.637 +     * specified value.
 374.638 +     *
 374.639 +     * @param value value whose presence in this map is to be tested
 374.640 +     * @return <tt>true</tt> if this map maps one or more keys to the
 374.641 +     *         specified value
 374.642 +     */
 374.643 +    public boolean containsValue(Object value) {
 374.644 +        if (value == null)
 374.645 +            return containsNullValue();
 374.646 +
 374.647 +        Entry[] tab = table;
 374.648 +        for (int i = 0; i < tab.length ; i++)
 374.649 +            for (Entry e = tab[i] ; e != null ; e = e.next)
 374.650 +                if (value.equals(e.value))
 374.651 +                    return true;
 374.652 +        return false;
 374.653 +    }
 374.654 +
 374.655 +    /**
 374.656 +     * Special-case code for containsValue with null argument
 374.657 +     */
 374.658 +    private boolean containsNullValue() {
 374.659 +        Entry[] tab = table;
 374.660 +        for (int i = 0; i < tab.length ; i++)
 374.661 +            for (Entry e = tab[i] ; e != null ; e = e.next)
 374.662 +                if (e.value == null)
 374.663 +                    return true;
 374.664 +        return false;
 374.665 +    }
 374.666 +
 374.667 +    /**
 374.668 +     * Returns a shallow copy of this <tt>HashMap</tt> instance: the keys and
 374.669 +     * values themselves are not cloned.
 374.670 +     *
 374.671 +     * @return a shallow copy of this map
 374.672 +     */
 374.673 +    public Object clone() {
 374.674 +        HashMap<K,V> result = null;
 374.675 +        try {
 374.676 +            result = (HashMap<K,V>)super.clone();
 374.677 +        } catch (CloneNotSupportedException e) {
 374.678 +            // assert false;
 374.679 +        }
 374.680 +        result.table = new Entry[table.length];
 374.681 +        result.entrySet = null;
 374.682 +        result.modCount = 0;
 374.683 +        result.size = 0;
 374.684 +        result.init();
 374.685 +        result.putAllForCreate(this);
 374.686 +
 374.687 +        return result;
 374.688 +    }
 374.689 +
 374.690 +    static class Entry<K,V> implements Map.Entry<K,V> {
 374.691 +        final K key;
 374.692 +        V value;
 374.693 +        Entry<K,V> next;
 374.694 +        final int hash;
 374.695 +
 374.696 +        /**
 374.697 +         * Creates new entry.
 374.698 +         */
 374.699 +        Entry(int h, K k, V v, Entry<K,V> n) {
 374.700 +            value = v;
 374.701 +            next = n;
 374.702 +            key = k;
 374.703 +            hash = h;
 374.704 +        }
 374.705 +
 374.706 +        public final K getKey() {
 374.707 +            return key;
 374.708 +        }
 374.709 +
 374.710 +        public final V getValue() {
 374.711 +            return value;
 374.712 +        }
 374.713 +
 374.714 +        public final V setValue(V newValue) {
 374.715 +            V oldValue = value;
 374.716 +            value = newValue;
 374.717 +            return oldValue;
 374.718 +        }
 374.719 +
 374.720 +        public final boolean equals(Object o) {
 374.721 +            if (!(o instanceof Map.Entry))
 374.722 +                return false;
 374.723 +            Map.Entry e = (Map.Entry)o;
 374.724 +            Object k1 = getKey();
 374.725 +            Object k2 = e.getKey();
 374.726 +            if (k1 == k2 || (k1 != null && k1.equals(k2))) {
 374.727 +                Object v1 = getValue();
 374.728 +                Object v2 = e.getValue();
 374.729 +                if (v1 == v2 || (v1 != null && v1.equals(v2)))
 374.730 +                    return true;
 374.731 +            }
 374.732 +            return false;
 374.733 +        }
 374.734 +
 374.735 +        public final int hashCode() {
 374.736 +            return (key==null   ? 0 : key.hashCode()) ^
 374.737 +                   (value==null ? 0 : value.hashCode());
 374.738 +        }
 374.739 +
 374.740 +        public final String toString() {
 374.741 +            return getKey() + "=" + getValue();
 374.742 +        }
 374.743 +
 374.744 +        /**
 374.745 +         * This method is invoked whenever the value in an entry is
 374.746 +         * overwritten by an invocation of put(k,v) for a key k that's already
 374.747 +         * in the HashMap.
 374.748 +         */
 374.749 +        void recordAccess(HashMap<K,V> m) {
 374.750 +        }
 374.751 +
 374.752 +        /**
 374.753 +         * This method is invoked whenever the entry is
 374.754 +         * removed from the table.
 374.755 +         */
 374.756 +        void recordRemoval(HashMap<K,V> m) {
 374.757 +        }
 374.758 +    }
 374.759 +
 374.760 +    /**
 374.761 +     * Adds a new entry with the specified key, value and hash code to
 374.762 +     * the specified bucket.  It is the responsibility of this
 374.763 +     * method to resize the table if appropriate.
 374.764 +     *
 374.765 +     * Subclass overrides this to alter the behavior of put method.
 374.766 +     */
 374.767 +    void addEntry(int hash, K key, V value, int bucketIndex) {
 374.768 +        Entry<K,V> e = table[bucketIndex];
 374.769 +        table[bucketIndex] = new Entry<>(hash, key, value, e);
 374.770 +        if (size++ >= threshold)
 374.771 +            resize(2 * table.length);
 374.772 +    }
 374.773 +
 374.774 +    /**
 374.775 +     * Like addEntry except that this version is used when creating entries
 374.776 +     * as part of Map construction or "pseudo-construction" (cloning,
 374.777 +     * deserialization).  This version needn't worry about resizing the table.
 374.778 +     *
 374.779 +     * Subclass overrides this to alter the behavior of HashMap(Map),
 374.780 +     * clone, and readObject.
 374.781 +     */
 374.782 +    void createEntry(int hash, K key, V value, int bucketIndex) {
 374.783 +        Entry<K,V> e = table[bucketIndex];
 374.784 +        table[bucketIndex] = new Entry<>(hash, key, value, e);
 374.785 +        size++;
 374.786 +    }
 374.787 +
 374.788 +    private abstract class HashIterator<E> implements Iterator<E> {
 374.789 +        Entry<K,V> next;        // next entry to return
 374.790 +        int expectedModCount;   // For fast-fail
 374.791 +        int index;              // current slot
 374.792 +        Entry<K,V> current;     // current entry
 374.793 +
 374.794 +        HashIterator() {
 374.795 +            expectedModCount = modCount;
 374.796 +            if (size > 0) { // advance to first entry
 374.797 +                Entry[] t = table;
 374.798 +                while (index < t.length && (next = t[index++]) == null)
 374.799 +                    ;
 374.800 +            }
 374.801 +        }
 374.802 +
 374.803 +        public final boolean hasNext() {
 374.804 +            return next != null;
 374.805 +        }
 374.806 +
 374.807 +        final Entry<K,V> nextEntry() {
 374.808 +            if (modCount != expectedModCount)
 374.809 +                throw new ConcurrentModificationException();
 374.810 +            Entry<K,V> e = next;
 374.811 +            if (e == null)
 374.812 +                throw new NoSuchElementException();
 374.813 +
 374.814 +            if ((next = e.next) == null) {
 374.815 +                Entry[] t = table;
 374.816 +                while (index < t.length && (next = t[index++]) == null)
 374.817 +                    ;
 374.818 +            }
 374.819 +            current = e;
 374.820 +            return e;
 374.821 +        }
 374.822 +
 374.823 +        public void remove() {
 374.824 +            if (current == null)
 374.825 +                throw new IllegalStateException();
 374.826 +            if (modCount != expectedModCount)
 374.827 +                throw new ConcurrentModificationException();
 374.828 +            Object k = current.key;
 374.829 +            current = null;
 374.830 +            HashMap.this.removeEntryForKey(k);
 374.831 +            expectedModCount = modCount;
 374.832 +        }
 374.833 +
 374.834 +    }
 374.835 +
 374.836 +    private final class ValueIterator extends HashIterator<V> {
 374.837 +        public V next() {
 374.838 +            return nextEntry().value;
 374.839 +        }
 374.840 +    }
 374.841 +
 374.842 +    private final class KeyIterator extends HashIterator<K> {
 374.843 +        public K next() {
 374.844 +            return nextEntry().getKey();
 374.845 +        }
 374.846 +    }
 374.847 +
 374.848 +    private final class EntryIterator extends HashIterator<Map.Entry<K,V>> {
 374.849 +        public Map.Entry<K,V> next() {
 374.850 +            return nextEntry();
 374.851 +        }
 374.852 +    }
 374.853 +
 374.854 +    // Subclass overrides these to alter behavior of views' iterator() method
 374.855 +    Iterator<K> newKeyIterator()   {
 374.856 +        return new KeyIterator();
 374.857 +    }
 374.858 +    Iterator<V> newValueIterator()   {
 374.859 +        return new ValueIterator();
 374.860 +    }
 374.861 +    Iterator<Map.Entry<K,V>> newEntryIterator()   {
 374.862 +        return new EntryIterator();
 374.863 +    }
 374.864 +
 374.865 +
 374.866 +    // Views
 374.867 +
 374.868 +    private transient Set<Map.Entry<K,V>> entrySet = null;
 374.869 +
 374.870 +    /**
 374.871 +     * Returns a {@link Set} view of the keys contained in this map.
 374.872 +     * The set is backed by the map, so changes to the map are
 374.873 +     * reflected in the set, and vice-versa.  If the map is modified
 374.874 +     * while an iteration over the set is in progress (except through
 374.875 +     * the iterator's own <tt>remove</tt> operation), the results of
 374.876 +     * the iteration are undefined.  The set supports element removal,
 374.877 +     * which removes the corresponding mapping from the map, via the
 374.878 +     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
 374.879 +     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
 374.880 +     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
 374.881 +     * operations.
 374.882 +     */
 374.883 +    public Set<K> keySet() {
 374.884 +        Set<K> ks = keySet;
 374.885 +        return (ks != null ? ks : (keySet = new KeySet()));
 374.886 +    }
 374.887 +
 374.888 +    private final class KeySet extends AbstractSet<K> {
 374.889 +        public Iterator<K> iterator() {
 374.890 +            return newKeyIterator();
 374.891 +        }
 374.892 +        public int size() {
 374.893 +            return size;
 374.894 +        }
 374.895 +        public boolean contains(Object o) {
 374.896 +            return containsKey(o);
 374.897 +        }
 374.898 +        public boolean remove(Object o) {
 374.899 +            return HashMap.this.removeEntryForKey(o) != null;
 374.900 +        }
 374.901 +        public void clear() {
 374.902 +            HashMap.this.clear();
 374.903 +        }
 374.904 +    }
 374.905 +
 374.906 +    /**
 374.907 +     * Returns a {@link Collection} view of the values contained in this map.
 374.908 +     * The collection is backed by the map, so changes to the map are
 374.909 +     * reflected in the collection, and vice-versa.  If the map is
 374.910 +     * modified while an iteration over the collection is in progress
 374.911 +     * (except through the iterator's own <tt>remove</tt> operation),
 374.912 +     * the results of the iteration are undefined.  The collection
 374.913 +     * supports element removal, which removes the corresponding
 374.914 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
 374.915 +     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
 374.916 +     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
 374.917 +     * support the <tt>add</tt> or <tt>addAll</tt> operations.
 374.918 +     */
 374.919 +    public Collection<V> values() {
 374.920 +        Collection<V> vs = values;
 374.921 +        return (vs != null ? vs : (values = new Values()));
 374.922 +    }
 374.923 +
 374.924 +    private final class Values extends AbstractCollection<V> {
 374.925 +        public Iterator<V> iterator() {
 374.926 +            return newValueIterator();
 374.927 +        }
 374.928 +        public int size() {
 374.929 +            return size;
 374.930 +        }
 374.931 +        public boolean contains(Object o) {
 374.932 +            return containsValue(o);
 374.933 +        }
 374.934 +        public void clear() {
 374.935 +            HashMap.this.clear();
 374.936 +        }
 374.937 +    }
 374.938 +
 374.939 +    /**
 374.940 +     * Returns a {@link Set} view of the mappings contained in this map.
 374.941 +     * The set is backed by the map, so changes to the map are
 374.942 +     * reflected in the set, and vice-versa.  If the map is modified
 374.943 +     * while an iteration over the set is in progress (except through
 374.944 +     * the iterator's own <tt>remove</tt> operation, or through the
 374.945 +     * <tt>setValue</tt> operation on a map entry returned by the
 374.946 +     * iterator) the results of the iteration are undefined.  The set
 374.947 +     * supports element removal, which removes the corresponding
 374.948 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
 374.949 +     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
 374.950 +     * <tt>clear</tt> operations.  It does not support the
 374.951 +     * <tt>add</tt> or <tt>addAll</tt> operations.
 374.952 +     *
 374.953 +     * @return a set view of the mappings contained in this map
 374.954 +     */
 374.955 +    public Set<Map.Entry<K,V>> entrySet() {
 374.956 +        return entrySet0();
 374.957 +    }
 374.958 +
 374.959 +    private Set<Map.Entry<K,V>> entrySet0() {
 374.960 +        Set<Map.Entry<K,V>> es = entrySet;
 374.961 +        return es != null ? es : (entrySet = new EntrySet());
 374.962 +    }
 374.963 +
 374.964 +    private final class EntrySet extends AbstractSet<Map.Entry<K,V>> {
 374.965 +        public Iterator<Map.Entry<K,V>> iterator() {
 374.966 +            return newEntryIterator();
 374.967 +        }
 374.968 +        public boolean contains(Object o) {
 374.969 +            if (!(o instanceof Map.Entry))
 374.970 +                return false;
 374.971 +            Map.Entry<K,V> e = (Map.Entry<K,V>) o;
 374.972 +            Entry<K,V> candidate = getEntry(e.getKey());
 374.973 +            return candidate != null && candidate.equals(e);
 374.974 +        }
 374.975 +        public boolean remove(Object o) {
 374.976 +            return removeMapping(o) != null;
 374.977 +        }
 374.978 +        public int size() {
 374.979 +            return size;
 374.980 +        }
 374.981 +        public void clear() {
 374.982 +            HashMap.this.clear();
 374.983 +        }
 374.984 +    }
 374.985 +
 374.986 +
 374.987 +    private static final long serialVersionUID = 362498820763181265L;
 374.988 +
 374.989 +
 374.990 +    // These methods are used when serializing HashSets
 374.991 +    int   capacity()     { return table.length; }
 374.992 +    float loadFactor()   { return loadFactor;   }
 374.993 +}
   375.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   375.2 +++ b/rt/emul/compact/src/main/java/java/util/HashSet.java	Wed Feb 27 11:24:58 2013 +0100
   375.3 @@ -0,0 +1,260 @@
   375.4 +/*
   375.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   375.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   375.7 + *
   375.8 + * This code is free software; you can redistribute it and/or modify it
   375.9 + * under the terms of the GNU General Public License version 2 only, as
  375.10 + * published by the Free Software Foundation.  Oracle designates this
  375.11 + * particular file as subject to the "Classpath" exception as provided
  375.12 + * by Oracle in the LICENSE file that accompanied this code.
  375.13 + *
  375.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  375.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  375.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  375.17 + * version 2 for more details (a copy is included in the LICENSE file that
  375.18 + * accompanied this code).
  375.19 + *
  375.20 + * You should have received a copy of the GNU General Public License version
  375.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  375.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  375.23 + *
  375.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  375.25 + * or visit www.oracle.com if you need additional information or have any
  375.26 + * questions.
  375.27 + */
  375.28 +
  375.29 +package java.util;
  375.30 +
  375.31 +/**
  375.32 + * This class implements the <tt>Set</tt> interface, backed by a hash table
  375.33 + * (actually a <tt>HashMap</tt> instance).  It makes no guarantees as to the
  375.34 + * iteration order of the set; in particular, it does not guarantee that the
  375.35 + * order will remain constant over time.  This class permits the <tt>null</tt>
  375.36 + * element.
  375.37 + *
  375.38 + * <p>This class offers constant time performance for the basic operations
  375.39 + * (<tt>add</tt>, <tt>remove</tt>, <tt>contains</tt> and <tt>size</tt>),
  375.40 + * assuming the hash function disperses the elements properly among the
  375.41 + * buckets.  Iterating over this set requires time proportional to the sum of
  375.42 + * the <tt>HashSet</tt> instance's size (the number of elements) plus the
  375.43 + * "capacity" of the backing <tt>HashMap</tt> instance (the number of
  375.44 + * buckets).  Thus, it's very important not to set the initial capacity too
  375.45 + * high (or the load factor too low) if iteration performance is important.
  375.46 + *
  375.47 + * <p><strong>Note that this implementation is not synchronized.</strong>
  375.48 + * If multiple threads access a hash set concurrently, and at least one of
  375.49 + * the threads modifies the set, it <i>must</i> be synchronized externally.
  375.50 + * This is typically accomplished by synchronizing on some object that
  375.51 + * naturally encapsulates the set.
  375.52 + *
  375.53 + * If no such object exists, the set should be "wrapped" using the
  375.54 + * {@link Collections#synchronizedSet Collections.synchronizedSet}
  375.55 + * method.  This is best done at creation time, to prevent accidental
  375.56 + * unsynchronized access to the set:<pre>
  375.57 + *   Set s = Collections.synchronizedSet(new HashSet(...));</pre>
  375.58 + *
  375.59 + * <p>The iterators returned by this class's <tt>iterator</tt> method are
  375.60 + * <i>fail-fast</i>: if the set is modified at any time after the iterator is
  375.61 + * created, in any way except through the iterator's own <tt>remove</tt>
  375.62 + * method, the Iterator throws a {@link ConcurrentModificationException}.
  375.63 + * Thus, in the face of concurrent modification, the iterator fails quickly
  375.64 + * and cleanly, rather than risking arbitrary, non-deterministic behavior at
  375.65 + * an undetermined time in the future.
  375.66 + *
  375.67 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  375.68 + * as it is, generally speaking, impossible to make any hard guarantees in the
  375.69 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  375.70 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
  375.71 + * Therefore, it would be wrong to write a program that depended on this
  375.72 + * exception for its correctness: <i>the fail-fast behavior of iterators
  375.73 + * should be used only to detect bugs.</i>
  375.74 + *
  375.75 + * <p>This class is a member of the
  375.76 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  375.77 + * Java Collections Framework</a>.
  375.78 + *
  375.79 + * @param <E> the type of elements maintained by this set
  375.80 + *
  375.81 + * @author  Josh Bloch
  375.82 + * @author  Neal Gafter
  375.83 + * @see     Collection
  375.84 + * @see     Set
  375.85 + * @see     TreeSet
  375.86 + * @see     HashMap
  375.87 + * @since   1.2
  375.88 + */
  375.89 +
  375.90 +public class HashSet<E>
  375.91 +    extends AbstractSet<E>
  375.92 +    implements Set<E>, Cloneable, java.io.Serializable
  375.93 +{
  375.94 +    static final long serialVersionUID = -5024744406713321676L;
  375.95 +
  375.96 +    private transient HashMap<E,Object> map;
  375.97 +
  375.98 +    // Dummy value to associate with an Object in the backing Map
  375.99 +    private static final Object PRESENT = new Object();
 375.100 +
 375.101 +    /**
 375.102 +     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
 375.103 +     * default initial capacity (16) and load factor (0.75).
 375.104 +     */
 375.105 +    public HashSet() {
 375.106 +        map = new HashMap<>();
 375.107 +    }
 375.108 +
 375.109 +    /**
 375.110 +     * Constructs a new set containing the elements in the specified
 375.111 +     * collection.  The <tt>HashMap</tt> is created with default load factor
 375.112 +     * (0.75) and an initial capacity sufficient to contain the elements in
 375.113 +     * the specified collection.
 375.114 +     *
 375.115 +     * @param c the collection whose elements are to be placed into this set
 375.116 +     * @throws NullPointerException if the specified collection is null
 375.117 +     */
 375.118 +    public HashSet(Collection<? extends E> c) {
 375.119 +        map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16));
 375.120 +        addAll(c);
 375.121 +    }
 375.122 +
 375.123 +    /**
 375.124 +     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
 375.125 +     * the specified initial capacity and the specified load factor.
 375.126 +     *
 375.127 +     * @param      initialCapacity   the initial capacity of the hash map
 375.128 +     * @param      loadFactor        the load factor of the hash map
 375.129 +     * @throws     IllegalArgumentException if the initial capacity is less
 375.130 +     *             than zero, or if the load factor is nonpositive
 375.131 +     */
 375.132 +    public HashSet(int initialCapacity, float loadFactor) {
 375.133 +        map = new HashMap<>(initialCapacity, loadFactor);
 375.134 +    }
 375.135 +
 375.136 +    /**
 375.137 +     * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
 375.138 +     * the specified initial capacity and default load factor (0.75).
 375.139 +     *
 375.140 +     * @param      initialCapacity   the initial capacity of the hash table
 375.141 +     * @throws     IllegalArgumentException if the initial capacity is less
 375.142 +     *             than zero
 375.143 +     */
 375.144 +    public HashSet(int initialCapacity) {
 375.145 +        map = new HashMap<>(initialCapacity);
 375.146 +    }
 375.147 +
 375.148 +    /**
 375.149 +     * Constructs a new, empty linked hash set.  (This package private
 375.150 +     * constructor is only used by LinkedHashSet.) The backing
 375.151 +     * HashMap instance is a LinkedHashMap with the specified initial
 375.152 +     * capacity and the specified load factor.
 375.153 +     *
 375.154 +     * @param      initialCapacity   the initial capacity of the hash map
 375.155 +     * @param      loadFactor        the load factor of the hash map
 375.156 +     * @param      dummy             ignored (distinguishes this
 375.157 +     *             constructor from other int, float constructor.)
 375.158 +     * @throws     IllegalArgumentException if the initial capacity is less
 375.159 +     *             than zero, or if the load factor is nonpositive
 375.160 +     */
 375.161 +    HashSet(int initialCapacity, float loadFactor, boolean dummy) {
 375.162 +        map = new LinkedHashMap<>(initialCapacity, loadFactor);
 375.163 +    }
 375.164 +
 375.165 +    /**
 375.166 +     * Returns an iterator over the elements in this set.  The elements
 375.167 +     * are returned in no particular order.
 375.168 +     *
 375.169 +     * @return an Iterator over the elements in this set
 375.170 +     * @see ConcurrentModificationException
 375.171 +     */
 375.172 +    public Iterator<E> iterator() {
 375.173 +        return map.keySet().iterator();
 375.174 +    }
 375.175 +
 375.176 +    /**
 375.177 +     * Returns the number of elements in this set (its cardinality).
 375.178 +     *
 375.179 +     * @return the number of elements in this set (its cardinality)
 375.180 +     */
 375.181 +    public int size() {
 375.182 +        return map.size();
 375.183 +    }
 375.184 +
 375.185 +    /**
 375.186 +     * Returns <tt>true</tt> if this set contains no elements.
 375.187 +     *
 375.188 +     * @return <tt>true</tt> if this set contains no elements
 375.189 +     */
 375.190 +    public boolean isEmpty() {
 375.191 +        return map.isEmpty();
 375.192 +    }
 375.193 +
 375.194 +    /**
 375.195 +     * Returns <tt>true</tt> if this set contains the specified element.
 375.196 +     * More formally, returns <tt>true</tt> if and only if this set
 375.197 +     * contains an element <tt>e</tt> such that
 375.198 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 375.199 +     *
 375.200 +     * @param o element whose presence in this set is to be tested
 375.201 +     * @return <tt>true</tt> if this set contains the specified element
 375.202 +     */
 375.203 +    public boolean contains(Object o) {
 375.204 +        return map.containsKey(o);
 375.205 +    }
 375.206 +
 375.207 +    /**
 375.208 +     * Adds the specified element to this set if it is not already present.
 375.209 +     * More formally, adds the specified element <tt>e</tt> to this set if
 375.210 +     * this set contains no element <tt>e2</tt> such that
 375.211 +     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
 375.212 +     * If this set already contains the element, the call leaves the set
 375.213 +     * unchanged and returns <tt>false</tt>.
 375.214 +     *
 375.215 +     * @param e element to be added to this set
 375.216 +     * @return <tt>true</tt> if this set did not already contain the specified
 375.217 +     * element
 375.218 +     */
 375.219 +    public boolean add(E e) {
 375.220 +        return map.put(e, PRESENT)==null;
 375.221 +    }
 375.222 +
 375.223 +    /**
 375.224 +     * Removes the specified element from this set if it is present.
 375.225 +     * More formally, removes an element <tt>e</tt> such that
 375.226 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>,
 375.227 +     * if this set contains such an element.  Returns <tt>true</tt> if
 375.228 +     * this set contained the element (or equivalently, if this set
 375.229 +     * changed as a result of the call).  (This set will not contain the
 375.230 +     * element once the call returns.)
 375.231 +     *
 375.232 +     * @param o object to be removed from this set, if present
 375.233 +     * @return <tt>true</tt> if the set contained the specified element
 375.234 +     */
 375.235 +    public boolean remove(Object o) {
 375.236 +        return map.remove(o)==PRESENT;
 375.237 +    }
 375.238 +
 375.239 +    /**
 375.240 +     * Removes all of the elements from this set.
 375.241 +     * The set will be empty after this call returns.
 375.242 +     */
 375.243 +    public void clear() {
 375.244 +        map.clear();
 375.245 +    }
 375.246 +
 375.247 +    /**
 375.248 +     * Returns a shallow copy of this <tt>HashSet</tt> instance: the elements
 375.249 +     * themselves are not cloned.
 375.250 +     *
 375.251 +     * @return a shallow copy of this set
 375.252 +     */
 375.253 +    public Object clone() {
 375.254 +        try {
 375.255 +            HashSet<E> newSet = (HashSet<E>) super.clone();
 375.256 +            newSet.map = (HashMap<E, Object>) map.clone();
 375.257 +            return newSet;
 375.258 +        } catch (CloneNotSupportedException e) {
 375.259 +            throw new InternalError();
 375.260 +        }
 375.261 +    }
 375.262 +
 375.263 +}
   376.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   376.2 +++ b/rt/emul/compact/src/main/java/java/util/Hashtable.java	Wed Feb 27 11:24:58 2013 +0100
   376.3 @@ -0,0 +1,1005 @@
   376.4 +/*
   376.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   376.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   376.7 + *
   376.8 + * This code is free software; you can redistribute it and/or modify it
   376.9 + * under the terms of the GNU General Public License version 2 only, as
  376.10 + * published by the Free Software Foundation.  Oracle designates this
  376.11 + * particular file as subject to the "Classpath" exception as provided
  376.12 + * by Oracle in the LICENSE file that accompanied this code.
  376.13 + *
  376.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  376.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  376.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  376.17 + * version 2 for more details (a copy is included in the LICENSE file that
  376.18 + * accompanied this code).
  376.19 + *
  376.20 + * You should have received a copy of the GNU General Public License version
  376.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  376.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  376.23 + *
  376.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  376.25 + * or visit www.oracle.com if you need additional information or have any
  376.26 + * questions.
  376.27 + */
  376.28 +
  376.29 +package java.util;
  376.30 +import java.io.*;
  376.31 +
  376.32 +/**
  376.33 + * This class implements a hash table, which maps keys to values. Any
  376.34 + * non-<code>null</code> object can be used as a key or as a value. <p>
  376.35 + *
  376.36 + * To successfully store and retrieve objects from a hashtable, the
  376.37 + * objects used as keys must implement the <code>hashCode</code>
  376.38 + * method and the <code>equals</code> method. <p>
  376.39 + *
  376.40 + * An instance of <code>Hashtable</code> has two parameters that affect its
  376.41 + * performance: <i>initial capacity</i> and <i>load factor</i>.  The
  376.42 + * <i>capacity</i> is the number of <i>buckets</i> in the hash table, and the
  376.43 + * <i>initial capacity</i> is simply the capacity at the time the hash table
  376.44 + * is created.  Note that the hash table is <i>open</i>: in the case of a "hash
  376.45 + * collision", a single bucket stores multiple entries, which must be searched
  376.46 + * sequentially.  The <i>load factor</i> is a measure of how full the hash
  376.47 + * table is allowed to get before its capacity is automatically increased.
  376.48 + * The initial capacity and load factor parameters are merely hints to
  376.49 + * the implementation.  The exact details as to when and whether the rehash
  376.50 + * method is invoked are implementation-dependent.<p>
  376.51 + *
  376.52 + * Generally, the default load factor (.75) offers a good tradeoff between
  376.53 + * time and space costs.  Higher values decrease the space overhead but
  376.54 + * increase the time cost to look up an entry (which is reflected in most
  376.55 + * <tt>Hashtable</tt> operations, including <tt>get</tt> and <tt>put</tt>).<p>
  376.56 + *
  376.57 + * The initial capacity controls a tradeoff between wasted space and the
  376.58 + * need for <code>rehash</code> operations, which are time-consuming.
  376.59 + * No <code>rehash</code> operations will <i>ever</i> occur if the initial
  376.60 + * capacity is greater than the maximum number of entries the
  376.61 + * <tt>Hashtable</tt> will contain divided by its load factor.  However,
  376.62 + * setting the initial capacity too high can waste space.<p>
  376.63 + *
  376.64 + * If many entries are to be made into a <code>Hashtable</code>,
  376.65 + * creating it with a sufficiently large capacity may allow the
  376.66 + * entries to be inserted more efficiently than letting it perform
  376.67 + * automatic rehashing as needed to grow the table. <p>
  376.68 + *
  376.69 + * This example creates a hashtable of numbers. It uses the names of
  376.70 + * the numbers as keys:
  376.71 + * <pre>   {@code
  376.72 + *   Hashtable<String, Integer> numbers
  376.73 + *     = new Hashtable<String, Integer>();
  376.74 + *   numbers.put("one", 1);
  376.75 + *   numbers.put("two", 2);
  376.76 + *   numbers.put("three", 3);}</pre>
  376.77 + *
  376.78 + * <p>To retrieve a number, use the following code:
  376.79 + * <pre>   {@code
  376.80 + *   Integer n = numbers.get("two");
  376.81 + *   if (n != null) {
  376.82 + *     System.out.println("two = " + n);
  376.83 + *   }}</pre>
  376.84 + *
  376.85 + * <p>The iterators returned by the <tt>iterator</tt> method of the collections
  376.86 + * returned by all of this class's "collection view methods" are
  376.87 + * <em>fail-fast</em>: if the Hashtable is structurally modified at any time
  376.88 + * after the iterator is created, in any way except through the iterator's own
  376.89 + * <tt>remove</tt> method, the iterator will throw a {@link
  376.90 + * ConcurrentModificationException}.  Thus, in the face of concurrent
  376.91 + * modification, the iterator fails quickly and cleanly, rather than risking
  376.92 + * arbitrary, non-deterministic behavior at an undetermined time in the future.
  376.93 + * The Enumerations returned by Hashtable's keys and elements methods are
  376.94 + * <em>not</em> fail-fast.
  376.95 + *
  376.96 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  376.97 + * as it is, generally speaking, impossible to make any hard guarantees in the
  376.98 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  376.99 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
 376.100 + * Therefore, it would be wrong to write a program that depended on this
 376.101 + * exception for its correctness: <i>the fail-fast behavior of iterators
 376.102 + * should be used only to detect bugs.</i>
 376.103 + *
 376.104 + * <p>As of the Java 2 platform v1.2, this class was retrofitted to
 376.105 + * implement the {@link Map} interface, making it a member of the
 376.106 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 376.107 + *
 376.108 + * Java Collections Framework</a>.  Unlike the new collection
 376.109 + * implementations, {@code Hashtable} is synchronized.  If a
 376.110 + * thread-safe implementation is not needed, it is recommended to use
 376.111 + * {@link HashMap} in place of {@code Hashtable}.  If a thread-safe
 376.112 + * highly-concurrent implementation is desired, then it is recommended
 376.113 + * to use {@link java.util.concurrent.ConcurrentHashMap} in place of
 376.114 + * {@code Hashtable}.
 376.115 + *
 376.116 + * @author  Arthur van Hoff
 376.117 + * @author  Josh Bloch
 376.118 + * @author  Neal Gafter
 376.119 + * @see     Object#equals(java.lang.Object)
 376.120 + * @see     Object#hashCode()
 376.121 + * @see     Hashtable#rehash()
 376.122 + * @see     Collection
 376.123 + * @see     Map
 376.124 + * @see     HashMap
 376.125 + * @see     TreeMap
 376.126 + * @since JDK1.0
 376.127 + */
 376.128 +public class Hashtable<K,V>
 376.129 +    extends Dictionary<K,V>
 376.130 +    implements Map<K,V>, Cloneable, java.io.Serializable {
 376.131 +
 376.132 +    /**
 376.133 +     * The hash table data.
 376.134 +     */
 376.135 +    private transient Entry[] table;
 376.136 +
 376.137 +    /**
 376.138 +     * The total number of entries in the hash table.
 376.139 +     */
 376.140 +    private transient int count;
 376.141 +
 376.142 +    /**
 376.143 +     * The table is rehashed when its size exceeds this threshold.  (The
 376.144 +     * value of this field is (int)(capacity * loadFactor).)
 376.145 +     *
 376.146 +     * @serial
 376.147 +     */
 376.148 +    private int threshold;
 376.149 +
 376.150 +    /**
 376.151 +     * The load factor for the hashtable.
 376.152 +     *
 376.153 +     * @serial
 376.154 +     */
 376.155 +    private float loadFactor;
 376.156 +
 376.157 +    /**
 376.158 +     * The number of times this Hashtable has been structurally modified
 376.159 +     * Structural modifications are those that change the number of entries in
 376.160 +     * the Hashtable or otherwise modify its internal structure (e.g.,
 376.161 +     * rehash).  This field is used to make iterators on Collection-views of
 376.162 +     * the Hashtable fail-fast.  (See ConcurrentModificationException).
 376.163 +     */
 376.164 +    private transient int modCount = 0;
 376.165 +
 376.166 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 376.167 +    private static final long serialVersionUID = 1421746759512286392L;
 376.168 +
 376.169 +    /**
 376.170 +     * Constructs a new, empty hashtable with the specified initial
 376.171 +     * capacity and the specified load factor.
 376.172 +     *
 376.173 +     * @param      initialCapacity   the initial capacity of the hashtable.
 376.174 +     * @param      loadFactor        the load factor of the hashtable.
 376.175 +     * @exception  IllegalArgumentException  if the initial capacity is less
 376.176 +     *             than zero, or if the load factor is nonpositive.
 376.177 +     */
 376.178 +    public Hashtable(int initialCapacity, float loadFactor) {
 376.179 +        if (initialCapacity < 0)
 376.180 +            throw new IllegalArgumentException("Illegal Capacity: "+
 376.181 +                                               initialCapacity);
 376.182 +        if (loadFactor <= 0 || Float.isNaN(loadFactor))
 376.183 +            throw new IllegalArgumentException("Illegal Load: "+loadFactor);
 376.184 +
 376.185 +        if (initialCapacity==0)
 376.186 +            initialCapacity = 1;
 376.187 +        this.loadFactor = loadFactor;
 376.188 +        table = new Entry[initialCapacity];
 376.189 +        threshold = (int)(initialCapacity * loadFactor);
 376.190 +    }
 376.191 +
 376.192 +    /**
 376.193 +     * Constructs a new, empty hashtable with the specified initial capacity
 376.194 +     * and default load factor (0.75).
 376.195 +     *
 376.196 +     * @param     initialCapacity   the initial capacity of the hashtable.
 376.197 +     * @exception IllegalArgumentException if the initial capacity is less
 376.198 +     *              than zero.
 376.199 +     */
 376.200 +    public Hashtable(int initialCapacity) {
 376.201 +        this(initialCapacity, 0.75f);
 376.202 +    }
 376.203 +
 376.204 +    /**
 376.205 +     * Constructs a new, empty hashtable with a default initial capacity (11)
 376.206 +     * and load factor (0.75).
 376.207 +     */
 376.208 +    public Hashtable() {
 376.209 +        this(11, 0.75f);
 376.210 +    }
 376.211 +
 376.212 +    /**
 376.213 +     * Constructs a new hashtable with the same mappings as the given
 376.214 +     * Map.  The hashtable is created with an initial capacity sufficient to
 376.215 +     * hold the mappings in the given Map and a default load factor (0.75).
 376.216 +     *
 376.217 +     * @param t the map whose mappings are to be placed in this map.
 376.218 +     * @throws NullPointerException if the specified map is null.
 376.219 +     * @since   1.2
 376.220 +     */
 376.221 +    public Hashtable(Map<? extends K, ? extends V> t) {
 376.222 +        this(Math.max(2*t.size(), 11), 0.75f);
 376.223 +        putAll(t);
 376.224 +    }
 376.225 +
 376.226 +    /**
 376.227 +     * Returns the number of keys in this hashtable.
 376.228 +     *
 376.229 +     * @return  the number of keys in this hashtable.
 376.230 +     */
 376.231 +    public synchronized int size() {
 376.232 +        return count;
 376.233 +    }
 376.234 +
 376.235 +    /**
 376.236 +     * Tests if this hashtable maps no keys to values.
 376.237 +     *
 376.238 +     * @return  <code>true</code> if this hashtable maps no keys to values;
 376.239 +     *          <code>false</code> otherwise.
 376.240 +     */
 376.241 +    public synchronized boolean isEmpty() {
 376.242 +        return count == 0;
 376.243 +    }
 376.244 +
 376.245 +    /**
 376.246 +     * Returns an enumeration of the keys in this hashtable.
 376.247 +     *
 376.248 +     * @return  an enumeration of the keys in this hashtable.
 376.249 +     * @see     Enumeration
 376.250 +     * @see     #elements()
 376.251 +     * @see     #keySet()
 376.252 +     * @see     Map
 376.253 +     */
 376.254 +    public synchronized Enumeration<K> keys() {
 376.255 +        return this.<K>getEnumeration(KEYS);
 376.256 +    }
 376.257 +
 376.258 +    /**
 376.259 +     * Returns an enumeration of the values in this hashtable.
 376.260 +     * Use the Enumeration methods on the returned object to fetch the elements
 376.261 +     * sequentially.
 376.262 +     *
 376.263 +     * @return  an enumeration of the values in this hashtable.
 376.264 +     * @see     java.util.Enumeration
 376.265 +     * @see     #keys()
 376.266 +     * @see     #values()
 376.267 +     * @see     Map
 376.268 +     */
 376.269 +    public synchronized Enumeration<V> elements() {
 376.270 +        return this.<V>getEnumeration(VALUES);
 376.271 +    }
 376.272 +
 376.273 +    /**
 376.274 +     * Tests if some key maps into the specified value in this hashtable.
 376.275 +     * This operation is more expensive than the {@link #containsKey
 376.276 +     * containsKey} method.
 376.277 +     *
 376.278 +     * <p>Note that this method is identical in functionality to
 376.279 +     * {@link #containsValue containsValue}, (which is part of the
 376.280 +     * {@link Map} interface in the collections framework).
 376.281 +     *
 376.282 +     * @param      value   a value to search for
 376.283 +     * @return     <code>true</code> if and only if some key maps to the
 376.284 +     *             <code>value</code> argument in this hashtable as
 376.285 +     *             determined by the <tt>equals</tt> method;
 376.286 +     *             <code>false</code> otherwise.
 376.287 +     * @exception  NullPointerException  if the value is <code>null</code>
 376.288 +     */
 376.289 +    public synchronized boolean contains(Object value) {
 376.290 +        if (value == null) {
 376.291 +            throw new NullPointerException();
 376.292 +        }
 376.293 +
 376.294 +        Entry tab[] = table;
 376.295 +        for (int i = tab.length ; i-- > 0 ;) {
 376.296 +            for (Entry<K,V> e = tab[i] ; e != null ; e = e.next) {
 376.297 +                if (e.value.equals(value)) {
 376.298 +                    return true;
 376.299 +                }
 376.300 +            }
 376.301 +        }
 376.302 +        return false;
 376.303 +    }
 376.304 +
 376.305 +    /**
 376.306 +     * Returns true if this hashtable maps one or more keys to this value.
 376.307 +     *
 376.308 +     * <p>Note that this method is identical in functionality to {@link
 376.309 +     * #contains contains} (which predates the {@link Map} interface).
 376.310 +     *
 376.311 +     * @param value value whose presence in this hashtable is to be tested
 376.312 +     * @return <tt>true</tt> if this map maps one or more keys to the
 376.313 +     *         specified value
 376.314 +     * @throws NullPointerException  if the value is <code>null</code>
 376.315 +     * @since 1.2
 376.316 +     */
 376.317 +    public boolean containsValue(Object value) {
 376.318 +        return contains(value);
 376.319 +    }
 376.320 +
 376.321 +    /**
 376.322 +     * Tests if the specified object is a key in this hashtable.
 376.323 +     *
 376.324 +     * @param   key   possible key
 376.325 +     * @return  <code>true</code> if and only if the specified object
 376.326 +     *          is a key in this hashtable, as determined by the
 376.327 +     *          <tt>equals</tt> method; <code>false</code> otherwise.
 376.328 +     * @throws  NullPointerException  if the key is <code>null</code>
 376.329 +     * @see     #contains(Object)
 376.330 +     */
 376.331 +    public synchronized boolean containsKey(Object key) {
 376.332 +        Entry tab[] = table;
 376.333 +        int hash = key.hashCode();
 376.334 +        int index = (hash & 0x7FFFFFFF) % tab.length;
 376.335 +        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
 376.336 +            if ((e.hash == hash) && e.key.equals(key)) {
 376.337 +                return true;
 376.338 +            }
 376.339 +        }
 376.340 +        return false;
 376.341 +    }
 376.342 +
 376.343 +    /**
 376.344 +     * Returns the value to which the specified key is mapped,
 376.345 +     * or {@code null} if this map contains no mapping for the key.
 376.346 +     *
 376.347 +     * <p>More formally, if this map contains a mapping from a key
 376.348 +     * {@code k} to a value {@code v} such that {@code (key.equals(k))},
 376.349 +     * then this method returns {@code v}; otherwise it returns
 376.350 +     * {@code null}.  (There can be at most one such mapping.)
 376.351 +     *
 376.352 +     * @param key the key whose associated value is to be returned
 376.353 +     * @return the value to which the specified key is mapped, or
 376.354 +     *         {@code null} if this map contains no mapping for the key
 376.355 +     * @throws NullPointerException if the specified key is null
 376.356 +     * @see     #put(Object, Object)
 376.357 +     */
 376.358 +    public synchronized V get(Object key) {
 376.359 +        Entry tab[] = table;
 376.360 +        int hash = key.hashCode();
 376.361 +        int index = (hash & 0x7FFFFFFF) % tab.length;
 376.362 +        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
 376.363 +            if ((e.hash == hash) && e.key.equals(key)) {
 376.364 +                return e.value;
 376.365 +            }
 376.366 +        }
 376.367 +        return null;
 376.368 +    }
 376.369 +
 376.370 +    /**
 376.371 +     * The maximum size of array to allocate.
 376.372 +     * Some VMs reserve some header words in an array.
 376.373 +     * Attempts to allocate larger arrays may result in
 376.374 +     * OutOfMemoryError: Requested array size exceeds VM limit
 376.375 +     */
 376.376 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 376.377 +
 376.378 +    /**
 376.379 +     * Increases the capacity of and internally reorganizes this
 376.380 +     * hashtable, in order to accommodate and access its entries more
 376.381 +     * efficiently.  This method is called automatically when the
 376.382 +     * number of keys in the hashtable exceeds this hashtable's capacity
 376.383 +     * and load factor.
 376.384 +     */
 376.385 +    protected void rehash() {
 376.386 +        int oldCapacity = table.length;
 376.387 +        Entry[] oldMap = table;
 376.388 +
 376.389 +        // overflow-conscious code
 376.390 +        int newCapacity = (oldCapacity << 1) + 1;
 376.391 +        if (newCapacity - MAX_ARRAY_SIZE > 0) {
 376.392 +            if (oldCapacity == MAX_ARRAY_SIZE)
 376.393 +                // Keep running with MAX_ARRAY_SIZE buckets
 376.394 +                return;
 376.395 +            newCapacity = MAX_ARRAY_SIZE;
 376.396 +        }
 376.397 +        Entry[] newMap = new Entry[newCapacity];
 376.398 +
 376.399 +        modCount++;
 376.400 +        threshold = (int)(newCapacity * loadFactor);
 376.401 +        table = newMap;
 376.402 +
 376.403 +        for (int i = oldCapacity ; i-- > 0 ;) {
 376.404 +            for (Entry<K,V> old = oldMap[i] ; old != null ; ) {
 376.405 +                Entry<K,V> e = old;
 376.406 +                old = old.next;
 376.407 +
 376.408 +                int index = (e.hash & 0x7FFFFFFF) % newCapacity;
 376.409 +                e.next = newMap[index];
 376.410 +                newMap[index] = e;
 376.411 +            }
 376.412 +        }
 376.413 +    }
 376.414 +
 376.415 +    /**
 376.416 +     * Maps the specified <code>key</code> to the specified
 376.417 +     * <code>value</code> in this hashtable. Neither the key nor the
 376.418 +     * value can be <code>null</code>. <p>
 376.419 +     *
 376.420 +     * The value can be retrieved by calling the <code>get</code> method
 376.421 +     * with a key that is equal to the original key.
 376.422 +     *
 376.423 +     * @param      key     the hashtable key
 376.424 +     * @param      value   the value
 376.425 +     * @return     the previous value of the specified key in this hashtable,
 376.426 +     *             or <code>null</code> if it did not have one
 376.427 +     * @exception  NullPointerException  if the key or value is
 376.428 +     *               <code>null</code>
 376.429 +     * @see     Object#equals(Object)
 376.430 +     * @see     #get(Object)
 376.431 +     */
 376.432 +    public synchronized V put(K key, V value) {
 376.433 +        // Make sure the value is not null
 376.434 +        if (value == null) {
 376.435 +            throw new NullPointerException();
 376.436 +        }
 376.437 +
 376.438 +        // Makes sure the key is not already in the hashtable.
 376.439 +        Entry tab[] = table;
 376.440 +        int hash = key.hashCode();
 376.441 +        int index = (hash & 0x7FFFFFFF) % tab.length;
 376.442 +        for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
 376.443 +            if ((e.hash == hash) && e.key.equals(key)) {
 376.444 +                V old = e.value;
 376.445 +                e.value = value;
 376.446 +                return old;
 376.447 +            }
 376.448 +        }
 376.449 +
 376.450 +        modCount++;
 376.451 +        if (count >= threshold) {
 376.452 +            // Rehash the table if the threshold is exceeded
 376.453 +            rehash();
 376.454 +
 376.455 +            tab = table;
 376.456 +            index = (hash & 0x7FFFFFFF) % tab.length;
 376.457 +        }
 376.458 +
 376.459 +        // Creates the new entry.
 376.460 +        Entry<K,V> e = tab[index];
 376.461 +        tab[index] = new Entry<>(hash, key, value, e);
 376.462 +        count++;
 376.463 +        return null;
 376.464 +    }
 376.465 +
 376.466 +    /**
 376.467 +     * Removes the key (and its corresponding value) from this
 376.468 +     * hashtable. This method does nothing if the key is not in the hashtable.
 376.469 +     *
 376.470 +     * @param   key   the key that needs to be removed
 376.471 +     * @return  the value to which the key had been mapped in this hashtable,
 376.472 +     *          or <code>null</code> if the key did not have a mapping
 376.473 +     * @throws  NullPointerException  if the key is <code>null</code>
 376.474 +     */
 376.475 +    public synchronized V remove(Object key) {
 376.476 +        Entry tab[] = table;
 376.477 +        int hash = key.hashCode();
 376.478 +        int index = (hash & 0x7FFFFFFF) % tab.length;
 376.479 +        for (Entry<K,V> e = tab[index], prev = null ; e != null ; prev = e, e = e.next) {
 376.480 +            if ((e.hash == hash) && e.key.equals(key)) {
 376.481 +                modCount++;
 376.482 +                if (prev != null) {
 376.483 +                    prev.next = e.next;
 376.484 +                } else {
 376.485 +                    tab[index] = e.next;
 376.486 +                }
 376.487 +                count--;
 376.488 +                V oldValue = e.value;
 376.489 +                e.value = null;
 376.490 +                return oldValue;
 376.491 +            }
 376.492 +        }
 376.493 +        return null;
 376.494 +    }
 376.495 +
 376.496 +    /**
 376.497 +     * Copies all of the mappings from the specified map to this hashtable.
 376.498 +     * These mappings will replace any mappings that this hashtable had for any
 376.499 +     * of the keys currently in the specified map.
 376.500 +     *
 376.501 +     * @param t mappings to be stored in this map
 376.502 +     * @throws NullPointerException if the specified map is null
 376.503 +     * @since 1.2
 376.504 +     */
 376.505 +    public synchronized void putAll(Map<? extends K, ? extends V> t) {
 376.506 +        for (Map.Entry<? extends K, ? extends V> e : t.entrySet())
 376.507 +            put(e.getKey(), e.getValue());
 376.508 +    }
 376.509 +
 376.510 +    /**
 376.511 +     * Clears this hashtable so that it contains no keys.
 376.512 +     */
 376.513 +    public synchronized void clear() {
 376.514 +        Entry tab[] = table;
 376.515 +        modCount++;
 376.516 +        for (int index = tab.length; --index >= 0; )
 376.517 +            tab[index] = null;
 376.518 +        count = 0;
 376.519 +    }
 376.520 +
 376.521 +    /**
 376.522 +     * Creates a shallow copy of this hashtable. All the structure of the
 376.523 +     * hashtable itself is copied, but the keys and values are not cloned.
 376.524 +     * This is a relatively expensive operation.
 376.525 +     *
 376.526 +     * @return  a clone of the hashtable
 376.527 +     */
 376.528 +    public synchronized Object clone() {
 376.529 +        try {
 376.530 +            Hashtable<K,V> t = (Hashtable<K,V>) super.clone();
 376.531 +            t.table = new Entry[table.length];
 376.532 +            for (int i = table.length ; i-- > 0 ; ) {
 376.533 +                t.table[i] = (table[i] != null)
 376.534 +                    ? (Entry<K,V>) table[i].clone() : null;
 376.535 +            }
 376.536 +            t.keySet = null;
 376.537 +            t.entrySet = null;
 376.538 +            t.values = null;
 376.539 +            t.modCount = 0;
 376.540 +            return t;
 376.541 +        } catch (CloneNotSupportedException e) {
 376.542 +            // this shouldn't happen, since we are Cloneable
 376.543 +            throw new InternalError();
 376.544 +        }
 376.545 +    }
 376.546 +
 376.547 +    /**
 376.548 +     * Returns a string representation of this <tt>Hashtable</tt> object
 376.549 +     * in the form of a set of entries, enclosed in braces and separated
 376.550 +     * by the ASCII characters "<tt>,&nbsp;</tt>" (comma and space). Each
 376.551 +     * entry is rendered as the key, an equals sign <tt>=</tt>, and the
 376.552 +     * associated element, where the <tt>toString</tt> method is used to
 376.553 +     * convert the key and element to strings.
 376.554 +     *
 376.555 +     * @return  a string representation of this hashtable
 376.556 +     */
 376.557 +    public synchronized String toString() {
 376.558 +        int max = size() - 1;
 376.559 +        if (max == -1)
 376.560 +            return "{}";
 376.561 +
 376.562 +        StringBuilder sb = new StringBuilder();
 376.563 +        Iterator<Map.Entry<K,V>> it = entrySet().iterator();
 376.564 +
 376.565 +        sb.append('{');
 376.566 +        for (int i = 0; ; i++) {
 376.567 +            Map.Entry<K,V> e = it.next();
 376.568 +            K key = e.getKey();
 376.569 +            V value = e.getValue();
 376.570 +            sb.append(key   == this ? "(this Map)" : key.toString());
 376.571 +            sb.append('=');
 376.572 +            sb.append(value == this ? "(this Map)" : value.toString());
 376.573 +
 376.574 +            if (i == max)
 376.575 +                return sb.append('}').toString();
 376.576 +            sb.append(", ");
 376.577 +        }
 376.578 +    }
 376.579 +
 376.580 +
 376.581 +    private <T> Enumeration<T> getEnumeration(int type) {
 376.582 +        if (count == 0) {
 376.583 +            return Collections.emptyEnumeration();
 376.584 +        } else {
 376.585 +            return new Enumerator<>(type, false);
 376.586 +        }
 376.587 +    }
 376.588 +
 376.589 +    private <T> Iterator<T> getIterator(int type) {
 376.590 +        if (count == 0) {
 376.591 +            return Collections.emptyIterator();
 376.592 +        } else {
 376.593 +            return new Enumerator<>(type, true);
 376.594 +        }
 376.595 +    }
 376.596 +
 376.597 +    // Views
 376.598 +
 376.599 +    /**
 376.600 +     * Each of these fields are initialized to contain an instance of the
 376.601 +     * appropriate view the first time this view is requested.  The views are
 376.602 +     * stateless, so there's no reason to create more than one of each.
 376.603 +     */
 376.604 +    private transient volatile Set<K> keySet = null;
 376.605 +    private transient volatile Set<Map.Entry<K,V>> entrySet = null;
 376.606 +    private transient volatile Collection<V> values = null;
 376.607 +
 376.608 +    /**
 376.609 +     * Returns a {@link Set} view of the keys contained in this map.
 376.610 +     * The set is backed by the map, so changes to the map are
 376.611 +     * reflected in the set, and vice-versa.  If the map is modified
 376.612 +     * while an iteration over the set is in progress (except through
 376.613 +     * the iterator's own <tt>remove</tt> operation), the results of
 376.614 +     * the iteration are undefined.  The set supports element removal,
 376.615 +     * which removes the corresponding mapping from the map, via the
 376.616 +     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
 376.617 +     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
 376.618 +     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
 376.619 +     * operations.
 376.620 +     *
 376.621 +     * @since 1.2
 376.622 +     */
 376.623 +    public Set<K> keySet() {
 376.624 +        if (keySet == null)
 376.625 +            keySet = Collections.synchronizedSet(new KeySet(), this);
 376.626 +        return keySet;
 376.627 +    }
 376.628 +
 376.629 +    private class KeySet extends AbstractSet<K> {
 376.630 +        public Iterator<K> iterator() {
 376.631 +            return getIterator(KEYS);
 376.632 +        }
 376.633 +        public int size() {
 376.634 +            return count;
 376.635 +        }
 376.636 +        public boolean contains(Object o) {
 376.637 +            return containsKey(o);
 376.638 +        }
 376.639 +        public boolean remove(Object o) {
 376.640 +            return Hashtable.this.remove(o) != null;
 376.641 +        }
 376.642 +        public void clear() {
 376.643 +            Hashtable.this.clear();
 376.644 +        }
 376.645 +    }
 376.646 +
 376.647 +    /**
 376.648 +     * Returns a {@link Set} view of the mappings contained in this map.
 376.649 +     * The set is backed by the map, so changes to the map are
 376.650 +     * reflected in the set, and vice-versa.  If the map is modified
 376.651 +     * while an iteration over the set is in progress (except through
 376.652 +     * the iterator's own <tt>remove</tt> operation, or through the
 376.653 +     * <tt>setValue</tt> operation on a map entry returned by the
 376.654 +     * iterator) the results of the iteration are undefined.  The set
 376.655 +     * supports element removal, which removes the corresponding
 376.656 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
 376.657 +     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
 376.658 +     * <tt>clear</tt> operations.  It does not support the
 376.659 +     * <tt>add</tt> or <tt>addAll</tt> operations.
 376.660 +     *
 376.661 +     * @since 1.2
 376.662 +     */
 376.663 +    public Set<Map.Entry<K,V>> entrySet() {
 376.664 +        if (entrySet==null)
 376.665 +            entrySet = Collections.synchronizedSet(new EntrySet(), this);
 376.666 +        return entrySet;
 376.667 +    }
 376.668 +
 376.669 +    private class EntrySet extends AbstractSet<Map.Entry<K,V>> {
 376.670 +        public Iterator<Map.Entry<K,V>> iterator() {
 376.671 +            return getIterator(ENTRIES);
 376.672 +        }
 376.673 +
 376.674 +        public boolean add(Map.Entry<K,V> o) {
 376.675 +            return super.add(o);
 376.676 +        }
 376.677 +
 376.678 +        public boolean contains(Object o) {
 376.679 +            if (!(o instanceof Map.Entry))
 376.680 +                return false;
 376.681 +            Map.Entry entry = (Map.Entry)o;
 376.682 +            Object key = entry.getKey();
 376.683 +            Entry[] tab = table;
 376.684 +            int hash = key.hashCode();
 376.685 +            int index = (hash & 0x7FFFFFFF) % tab.length;
 376.686 +
 376.687 +            for (Entry e = tab[index]; e != null; e = e.next)
 376.688 +                if (e.hash==hash && e.equals(entry))
 376.689 +                    return true;
 376.690 +            return false;
 376.691 +        }
 376.692 +
 376.693 +        public boolean remove(Object o) {
 376.694 +            if (!(o instanceof Map.Entry))
 376.695 +                return false;
 376.696 +            Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
 376.697 +            K key = entry.getKey();
 376.698 +            Entry[] tab = table;
 376.699 +            int hash = key.hashCode();
 376.700 +            int index = (hash & 0x7FFFFFFF) % tab.length;
 376.701 +
 376.702 +            for (Entry<K,V> e = tab[index], prev = null; e != null;
 376.703 +                 prev = e, e = e.next) {
 376.704 +                if (e.hash==hash && e.equals(entry)) {
 376.705 +                    modCount++;
 376.706 +                    if (prev != null)
 376.707 +                        prev.next = e.next;
 376.708 +                    else
 376.709 +                        tab[index] = e.next;
 376.710 +
 376.711 +                    count--;
 376.712 +                    e.value = null;
 376.713 +                    return true;
 376.714 +                }
 376.715 +            }
 376.716 +            return false;
 376.717 +        }
 376.718 +
 376.719 +        public int size() {
 376.720 +            return count;
 376.721 +        }
 376.722 +
 376.723 +        public void clear() {
 376.724 +            Hashtable.this.clear();
 376.725 +        }
 376.726 +    }
 376.727 +
 376.728 +    /**
 376.729 +     * Returns a {@link Collection} view of the values contained in this map.
 376.730 +     * The collection is backed by the map, so changes to the map are
 376.731 +     * reflected in the collection, and vice-versa.  If the map is
 376.732 +     * modified while an iteration over the collection is in progress
 376.733 +     * (except through the iterator's own <tt>remove</tt> operation),
 376.734 +     * the results of the iteration are undefined.  The collection
 376.735 +     * supports element removal, which removes the corresponding
 376.736 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
 376.737 +     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
 376.738 +     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
 376.739 +     * support the <tt>add</tt> or <tt>addAll</tt> operations.
 376.740 +     *
 376.741 +     * @since 1.2
 376.742 +     */
 376.743 +    public Collection<V> values() {
 376.744 +        if (values==null)
 376.745 +            values = Collections.synchronizedCollection(new ValueCollection(),
 376.746 +                                                        this);
 376.747 +        return values;
 376.748 +    }
 376.749 +
 376.750 +    private class ValueCollection extends AbstractCollection<V> {
 376.751 +        public Iterator<V> iterator() {
 376.752 +            return getIterator(VALUES);
 376.753 +        }
 376.754 +        public int size() {
 376.755 +            return count;
 376.756 +        }
 376.757 +        public boolean contains(Object o) {
 376.758 +            return containsValue(o);
 376.759 +        }
 376.760 +        public void clear() {
 376.761 +            Hashtable.this.clear();
 376.762 +        }
 376.763 +    }
 376.764 +
 376.765 +    // Comparison and hashing
 376.766 +
 376.767 +    /**
 376.768 +     * Compares the specified Object with this Map for equality,
 376.769 +     * as per the definition in the Map interface.
 376.770 +     *
 376.771 +     * @param  o object to be compared for equality with this hashtable
 376.772 +     * @return true if the specified Object is equal to this Map
 376.773 +     * @see Map#equals(Object)
 376.774 +     * @since 1.2
 376.775 +     */
 376.776 +    public synchronized boolean equals(Object o) {
 376.777 +        if (o == this)
 376.778 +            return true;
 376.779 +
 376.780 +        if (!(o instanceof Map))
 376.781 +            return false;
 376.782 +        Map<K,V> t = (Map<K,V>) o;
 376.783 +        if (t.size() != size())
 376.784 +            return false;
 376.785 +
 376.786 +        try {
 376.787 +            Iterator<Map.Entry<K,V>> i = entrySet().iterator();
 376.788 +            while (i.hasNext()) {
 376.789 +                Map.Entry<K,V> e = i.next();
 376.790 +                K key = e.getKey();
 376.791 +                V value = e.getValue();
 376.792 +                if (value == null) {
 376.793 +                    if (!(t.get(key)==null && t.containsKey(key)))
 376.794 +                        return false;
 376.795 +                } else {
 376.796 +                    if (!value.equals(t.get(key)))
 376.797 +                        return false;
 376.798 +                }
 376.799 +            }
 376.800 +        } catch (ClassCastException unused)   {
 376.801 +            return false;
 376.802 +        } catch (NullPointerException unused) {
 376.803 +            return false;
 376.804 +        }
 376.805 +
 376.806 +        return true;
 376.807 +    }
 376.808 +
 376.809 +    /**
 376.810 +     * Returns the hash code value for this Map as per the definition in the
 376.811 +     * Map interface.
 376.812 +     *
 376.813 +     * @see Map#hashCode()
 376.814 +     * @since 1.2
 376.815 +     */
 376.816 +    public synchronized int hashCode() {
 376.817 +        /*
 376.818 +         * This code detects the recursion caused by computing the hash code
 376.819 +         * of a self-referential hash table and prevents the stack overflow
 376.820 +         * that would otherwise result.  This allows certain 1.1-era
 376.821 +         * applets with self-referential hash tables to work.  This code
 376.822 +         * abuses the loadFactor field to do double-duty as a hashCode
 376.823 +         * in progress flag, so as not to worsen the space performance.
 376.824 +         * A negative load factor indicates that hash code computation is
 376.825 +         * in progress.
 376.826 +         */
 376.827 +        int h = 0;
 376.828 +        if (count == 0 || loadFactor < 0)
 376.829 +            return h;  // Returns zero
 376.830 +
 376.831 +        loadFactor = -loadFactor;  // Mark hashCode computation in progress
 376.832 +        Entry[] tab = table;
 376.833 +        for (int i = 0; i < tab.length; i++)
 376.834 +            for (Entry e = tab[i]; e != null; e = e.next)
 376.835 +                h += e.key.hashCode() ^ e.value.hashCode();
 376.836 +        loadFactor = -loadFactor;  // Mark hashCode computation complete
 376.837 +
 376.838 +        return h;
 376.839 +    }
 376.840 +
 376.841 +    /**
 376.842 +     * Hashtable collision list.
 376.843 +     */
 376.844 +    private static class Entry<K,V> implements Map.Entry<K,V> {
 376.845 +        int hash;
 376.846 +        K key;
 376.847 +        V value;
 376.848 +        Entry<K,V> next;
 376.849 +
 376.850 +        protected Entry(int hash, K key, V value, Entry<K,V> next) {
 376.851 +            this.hash = hash;
 376.852 +            this.key = key;
 376.853 +            this.value = value;
 376.854 +            this.next = next;
 376.855 +        }
 376.856 +
 376.857 +        protected Object clone() {
 376.858 +            return new Entry<>(hash, key, value,
 376.859 +                                  (next==null ? null : (Entry<K,V>) next.clone()));
 376.860 +        }
 376.861 +
 376.862 +        // Map.Entry Ops
 376.863 +
 376.864 +        public K getKey() {
 376.865 +            return key;
 376.866 +        }
 376.867 +
 376.868 +        public V getValue() {
 376.869 +            return value;
 376.870 +        }
 376.871 +
 376.872 +        public V setValue(V value) {
 376.873 +            if (value == null)
 376.874 +                throw new NullPointerException();
 376.875 +
 376.876 +            V oldValue = this.value;
 376.877 +            this.value = value;
 376.878 +            return oldValue;
 376.879 +        }
 376.880 +
 376.881 +        public boolean equals(Object o) {
 376.882 +            if (!(o instanceof Map.Entry))
 376.883 +                return false;
 376.884 +            Map.Entry e = (Map.Entry)o;
 376.885 +
 376.886 +            return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
 376.887 +               (value==null ? e.getValue()==null : value.equals(e.getValue()));
 376.888 +        }
 376.889 +
 376.890 +        public int hashCode() {
 376.891 +            return hash ^ (value==null ? 0 : value.hashCode());
 376.892 +        }
 376.893 +
 376.894 +        public String toString() {
 376.895 +            return key.toString()+"="+value.toString();
 376.896 +        }
 376.897 +    }
 376.898 +
 376.899 +    // Types of Enumerations/Iterations
 376.900 +    private static final int KEYS = 0;
 376.901 +    private static final int VALUES = 1;
 376.902 +    private static final int ENTRIES = 2;
 376.903 +
 376.904 +    /**
 376.905 +     * A hashtable enumerator class.  This class implements both the
 376.906 +     * Enumeration and Iterator interfaces, but individual instances
 376.907 +     * can be created with the Iterator methods disabled.  This is necessary
 376.908 +     * to avoid unintentionally increasing the capabilities granted a user
 376.909 +     * by passing an Enumeration.
 376.910 +     */
 376.911 +    private class Enumerator<T> implements Enumeration<T>, Iterator<T> {
 376.912 +        Entry[] table = Hashtable.this.table;
 376.913 +        int index = table.length;
 376.914 +        Entry<K,V> entry = null;
 376.915 +        Entry<K,V> lastReturned = null;
 376.916 +        int type;
 376.917 +
 376.918 +        /**
 376.919 +         * Indicates whether this Enumerator is serving as an Iterator
 376.920 +         * or an Enumeration.  (true -> Iterator).
 376.921 +         */
 376.922 +        boolean iterator;
 376.923 +
 376.924 +        /**
 376.925 +         * The modCount value that the iterator believes that the backing
 376.926 +         * Hashtable should have.  If this expectation is violated, the iterator
 376.927 +         * has detected concurrent modification.
 376.928 +         */
 376.929 +        protected int expectedModCount = modCount;
 376.930 +
 376.931 +        Enumerator(int type, boolean iterator) {
 376.932 +            this.type = type;
 376.933 +            this.iterator = iterator;
 376.934 +        }
 376.935 +
 376.936 +        public boolean hasMoreElements() {
 376.937 +            Entry<K,V> e = entry;
 376.938 +            int i = index;
 376.939 +            Entry[] t = table;
 376.940 +            /* Use locals for faster loop iteration */
 376.941 +            while (e == null && i > 0) {
 376.942 +                e = t[--i];
 376.943 +            }
 376.944 +            entry = e;
 376.945 +            index = i;
 376.946 +            return e != null;
 376.947 +        }
 376.948 +
 376.949 +        public T nextElement() {
 376.950 +            Entry<K,V> et = entry;
 376.951 +            int i = index;
 376.952 +            Entry[] t = table;
 376.953 +            /* Use locals for faster loop iteration */
 376.954 +            while (et == null && i > 0) {
 376.955 +                et = t[--i];
 376.956 +            }
 376.957 +            entry = et;
 376.958 +            index = i;
 376.959 +            if (et != null) {
 376.960 +                Entry<K,V> e = lastReturned = entry;
 376.961 +                entry = e.next;
 376.962 +                return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e);
 376.963 +            }
 376.964 +            throw new NoSuchElementException("Hashtable Enumerator");
 376.965 +        }
 376.966 +
 376.967 +        // Iterator methods
 376.968 +        public boolean hasNext() {
 376.969 +            return hasMoreElements();
 376.970 +        }
 376.971 +
 376.972 +        public T next() {
 376.973 +            if (modCount != expectedModCount)
 376.974 +                throw new ConcurrentModificationException();
 376.975 +            return nextElement();
 376.976 +        }
 376.977 +
 376.978 +        public void remove() {
 376.979 +            if (!iterator)
 376.980 +                throw new UnsupportedOperationException();
 376.981 +            if (lastReturned == null)
 376.982 +                throw new IllegalStateException("Hashtable Enumerator");
 376.983 +            if (modCount != expectedModCount)
 376.984 +                throw new ConcurrentModificationException();
 376.985 +
 376.986 +            synchronized(Hashtable.this) {
 376.987 +                Entry[] tab = Hashtable.this.table;
 376.988 +                int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
 376.989 +
 376.990 +                for (Entry<K,V> e = tab[index], prev = null; e != null;
 376.991 +                     prev = e, e = e.next) {
 376.992 +                    if (e == lastReturned) {
 376.993 +                        modCount++;
 376.994 +                        expectedModCount++;
 376.995 +                        if (prev == null)
 376.996 +                            tab[index] = e.next;
 376.997 +                        else
 376.998 +                            prev.next = e.next;
 376.999 +                        count--;
376.1000 +                        lastReturned = null;
376.1001 +                        return;
376.1002 +                    }
376.1003 +                }
376.1004 +                throw new ConcurrentModificationException();
376.1005 +            }
376.1006 +        }
376.1007 +    }
376.1008 +}
   377.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   377.2 +++ b/rt/emul/compact/src/main/java/java/util/Iterator.java	Wed Feb 27 11:24:58 2013 +0100
   377.3 @@ -0,0 +1,87 @@
   377.4 +/*
   377.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   377.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   377.7 + *
   377.8 + * This code is free software; you can redistribute it and/or modify it
   377.9 + * under the terms of the GNU General Public License version 2 only, as
  377.10 + * published by the Free Software Foundation.  Oracle designates this
  377.11 + * particular file as subject to the "Classpath" exception as provided
  377.12 + * by Oracle in the LICENSE file that accompanied this code.
  377.13 + *
  377.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  377.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  377.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  377.17 + * version 2 for more details (a copy is included in the LICENSE file that
  377.18 + * accompanied this code).
  377.19 + *
  377.20 + * You should have received a copy of the GNU General Public License version
  377.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  377.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  377.23 + *
  377.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  377.25 + * or visit www.oracle.com if you need additional information or have any
  377.26 + * questions.
  377.27 + */
  377.28 +
  377.29 +package java.util;
  377.30 +
  377.31 +/**
  377.32 + * An iterator over a collection.  {@code Iterator} takes the place of
  377.33 + * {@link Enumeration} in the Java Collections Framework.  Iterators
  377.34 + * differ from enumerations in two ways:
  377.35 + *
  377.36 + * <ul>
  377.37 + *      <li> Iterators allow the caller to remove elements from the
  377.38 + *           underlying collection during the iteration with well-defined
  377.39 + *           semantics.
  377.40 + *      <li> Method names have been improved.
  377.41 + * </ul>
  377.42 + *
  377.43 + * <p>This interface is a member of the
  377.44 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  377.45 + * Java Collections Framework</a>.
  377.46 + *
  377.47 + * @param <E> the type of elements returned by this iterator
  377.48 + *
  377.49 + * @author  Josh Bloch
  377.50 + * @see Collection
  377.51 + * @see ListIterator
  377.52 + * @see Iterable
  377.53 + * @since 1.2
  377.54 + */
  377.55 +public interface Iterator<E> {
  377.56 +    /**
  377.57 +     * Returns {@code true} if the iteration has more elements.
  377.58 +     * (In other words, returns {@code true} if {@link #next} would
  377.59 +     * return an element rather than throwing an exception.)
  377.60 +     *
  377.61 +     * @return {@code true} if the iteration has more elements
  377.62 +     */
  377.63 +    boolean hasNext();
  377.64 +
  377.65 +    /**
  377.66 +     * Returns the next element in the iteration.
  377.67 +     *
  377.68 +     * @return the next element in the iteration
  377.69 +     * @throws NoSuchElementException if the iteration has no more elements
  377.70 +     */
  377.71 +    E next();
  377.72 +
  377.73 +    /**
  377.74 +     * Removes from the underlying collection the last element returned
  377.75 +     * by this iterator (optional operation).  This method can be called
  377.76 +     * only once per call to {@link #next}.  The behavior of an iterator
  377.77 +     * is unspecified if the underlying collection is modified while the
  377.78 +     * iteration is in progress in any way other than by calling this
  377.79 +     * method.
  377.80 +     *
  377.81 +     * @throws UnsupportedOperationException if the {@code remove}
  377.82 +     *         operation is not supported by this iterator
  377.83 +     *
  377.84 +     * @throws IllegalStateException if the {@code next} method has not
  377.85 +     *         yet been called, or the {@code remove} method has already
  377.86 +     *         been called after the last call to the {@code next}
  377.87 +     *         method
  377.88 +     */
  377.89 +    void remove();
  377.90 +}
   378.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   378.2 +++ b/rt/emul/compact/src/main/java/java/util/LinkedHashMap.java	Wed Feb 27 11:24:58 2013 +0100
   378.3 @@ -0,0 +1,491 @@
   378.4 +/*
   378.5 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   378.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   378.7 + *
   378.8 + * This code is free software; you can redistribute it and/or modify it
   378.9 + * under the terms of the GNU General Public License version 2 only, as
  378.10 + * published by the Free Software Foundation.  Oracle designates this
  378.11 + * particular file as subject to the "Classpath" exception as provided
  378.12 + * by Oracle in the LICENSE file that accompanied this code.
  378.13 + *
  378.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  378.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  378.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  378.17 + * version 2 for more details (a copy is included in the LICENSE file that
  378.18 + * accompanied this code).
  378.19 + *
  378.20 + * You should have received a copy of the GNU General Public License version
  378.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  378.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  378.23 + *
  378.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  378.25 + * or visit www.oracle.com if you need additional information or have any
  378.26 + * questions.
  378.27 + */
  378.28 +
  378.29 +package java.util;
  378.30 +import java.io.*;
  378.31 +
  378.32 +/**
  378.33 + * <p>Hash table and linked list implementation of the <tt>Map</tt> interface,
  378.34 + * with predictable iteration order.  This implementation differs from
  378.35 + * <tt>HashMap</tt> in that it maintains a doubly-linked list running through
  378.36 + * all of its entries.  This linked list defines the iteration ordering,
  378.37 + * which is normally the order in which keys were inserted into the map
  378.38 + * (<i>insertion-order</i>).  Note that insertion order is not affected
  378.39 + * if a key is <i>re-inserted</i> into the map.  (A key <tt>k</tt> is
  378.40 + * reinserted into a map <tt>m</tt> if <tt>m.put(k, v)</tt> is invoked when
  378.41 + * <tt>m.containsKey(k)</tt> would return <tt>true</tt> immediately prior to
  378.42 + * the invocation.)
  378.43 + *
  378.44 + * <p>This implementation spares its clients from the unspecified, generally
  378.45 + * chaotic ordering provided by {@link HashMap} (and {@link Hashtable}),
  378.46 + * without incurring the increased cost associated with {@link TreeMap}.  It
  378.47 + * can be used to produce a copy of a map that has the same order as the
  378.48 + * original, regardless of the original map's implementation:
  378.49 + * <pre>
  378.50 + *     void foo(Map m) {
  378.51 + *         Map copy = new LinkedHashMap(m);
  378.52 + *         ...
  378.53 + *     }
  378.54 + * </pre>
  378.55 + * This technique is particularly useful if a module takes a map on input,
  378.56 + * copies it, and later returns results whose order is determined by that of
  378.57 + * the copy.  (Clients generally appreciate having things returned in the same
  378.58 + * order they were presented.)
  378.59 + *
  378.60 + * <p>A special {@link #LinkedHashMap(int,float,boolean) constructor} is
  378.61 + * provided to create a linked hash map whose order of iteration is the order
  378.62 + * in which its entries were last accessed, from least-recently accessed to
  378.63 + * most-recently (<i>access-order</i>).  This kind of map is well-suited to
  378.64 + * building LRU caches.  Invoking the <tt>put</tt> or <tt>get</tt> method
  378.65 + * results in an access to the corresponding entry (assuming it exists after
  378.66 + * the invocation completes).  The <tt>putAll</tt> method generates one entry
  378.67 + * access for each mapping in the specified map, in the order that key-value
  378.68 + * mappings are provided by the specified map's entry set iterator.  <i>No
  378.69 + * other methods generate entry accesses.</i> In particular, operations on
  378.70 + * collection-views do <i>not</i> affect the order of iteration of the backing
  378.71 + * map.
  378.72 + *
  378.73 + * <p>The {@link #removeEldestEntry(Map.Entry)} method may be overridden to
  378.74 + * impose a policy for removing stale mappings automatically when new mappings
  378.75 + * are added to the map.
  378.76 + *
  378.77 + * <p>This class provides all of the optional <tt>Map</tt> operations, and
  378.78 + * permits null elements.  Like <tt>HashMap</tt>, it provides constant-time
  378.79 + * performance for the basic operations (<tt>add</tt>, <tt>contains</tt> and
  378.80 + * <tt>remove</tt>), assuming the hash function disperses elements
  378.81 + * properly among the buckets.  Performance is likely to be just slightly
  378.82 + * below that of <tt>HashMap</tt>, due to the added expense of maintaining the
  378.83 + * linked list, with one exception: Iteration over the collection-views
  378.84 + * of a <tt>LinkedHashMap</tt> requires time proportional to the <i>size</i>
  378.85 + * of the map, regardless of its capacity.  Iteration over a <tt>HashMap</tt>
  378.86 + * is likely to be more expensive, requiring time proportional to its
  378.87 + * <i>capacity</i>.
  378.88 + *
  378.89 + * <p>A linked hash map has two parameters that affect its performance:
  378.90 + * <i>initial capacity</i> and <i>load factor</i>.  They are defined precisely
  378.91 + * as for <tt>HashMap</tt>.  Note, however, that the penalty for choosing an
  378.92 + * excessively high value for initial capacity is less severe for this class
  378.93 + * than for <tt>HashMap</tt>, as iteration times for this class are unaffected
  378.94 + * by capacity.
  378.95 + *
  378.96 + * <p><strong>Note that this implementation is not synchronized.</strong>
  378.97 + * If multiple threads access a linked hash map concurrently, and at least
  378.98 + * one of the threads modifies the map structurally, it <em>must</em> be
  378.99 + * synchronized externally.  This is typically accomplished by
 378.100 + * synchronizing on some object that naturally encapsulates the map.
 378.101 + *
 378.102 + * If no such object exists, the map should be "wrapped" using the
 378.103 + * {@link Collections#synchronizedMap Collections.synchronizedMap}
 378.104 + * method.  This is best done at creation time, to prevent accidental
 378.105 + * unsynchronized access to the map:<pre>
 378.106 + *   Map m = Collections.synchronizedMap(new LinkedHashMap(...));</pre>
 378.107 + *
 378.108 + * A structural modification is any operation that adds or deletes one or more
 378.109 + * mappings or, in the case of access-ordered linked hash maps, affects
 378.110 + * iteration order.  In insertion-ordered linked hash maps, merely changing
 378.111 + * the value associated with a key that is already contained in the map is not
 378.112 + * a structural modification.  <strong>In access-ordered linked hash maps,
 378.113 + * merely querying the map with <tt>get</tt> is a structural
 378.114 + * modification.</strong>)
 378.115 + *
 378.116 + * <p>The iterators returned by the <tt>iterator</tt> method of the collections
 378.117 + * returned by all of this class's collection view methods are
 378.118 + * <em>fail-fast</em>: if the map is structurally modified at any time after
 378.119 + * the iterator is created, in any way except through the iterator's own
 378.120 + * <tt>remove</tt> method, the iterator will throw a {@link
 378.121 + * ConcurrentModificationException}.  Thus, in the face of concurrent
 378.122 + * modification, the iterator fails quickly and cleanly, rather than risking
 378.123 + * arbitrary, non-deterministic behavior at an undetermined time in the future.
 378.124 + *
 378.125 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
 378.126 + * as it is, generally speaking, impossible to make any hard guarantees in the
 378.127 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
 378.128 + * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
 378.129 + * Therefore, it would be wrong to write a program that depended on this
 378.130 + * exception for its correctness:   <i>the fail-fast behavior of iterators
 378.131 + * should be used only to detect bugs.</i>
 378.132 + *
 378.133 + * <p>This class is a member of the
 378.134 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 378.135 + * Java Collections Framework</a>.
 378.136 + *
 378.137 + * @param <K> the type of keys maintained by this map
 378.138 + * @param <V> the type of mapped values
 378.139 + *
 378.140 + * @author  Josh Bloch
 378.141 + * @see     Object#hashCode()
 378.142 + * @see     Collection
 378.143 + * @see     Map
 378.144 + * @see     HashMap
 378.145 + * @see     TreeMap
 378.146 + * @see     Hashtable
 378.147 + * @since   1.4
 378.148 + */
 378.149 +
 378.150 +public class LinkedHashMap<K,V>
 378.151 +    extends HashMap<K,V>
 378.152 +    implements Map<K,V>
 378.153 +{
 378.154 +
 378.155 +    private static final long serialVersionUID = 3801124242820219131L;
 378.156 +
 378.157 +    /**
 378.158 +     * The head of the doubly linked list.
 378.159 +     */
 378.160 +    private transient Entry<K,V> header;
 378.161 +
 378.162 +    /**
 378.163 +     * The iteration ordering method for this linked hash map: <tt>true</tt>
 378.164 +     * for access-order, <tt>false</tt> for insertion-order.
 378.165 +     *
 378.166 +     * @serial
 378.167 +     */
 378.168 +    private final boolean accessOrder;
 378.169 +
 378.170 +    /**
 378.171 +     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
 378.172 +     * with the specified initial capacity and load factor.
 378.173 +     *
 378.174 +     * @param  initialCapacity the initial capacity
 378.175 +     * @param  loadFactor      the load factor
 378.176 +     * @throws IllegalArgumentException if the initial capacity is negative
 378.177 +     *         or the load factor is nonpositive
 378.178 +     */
 378.179 +    public LinkedHashMap(int initialCapacity, float loadFactor) {
 378.180 +        super(initialCapacity, loadFactor);
 378.181 +        accessOrder = false;
 378.182 +    }
 378.183 +
 378.184 +    /**
 378.185 +     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
 378.186 +     * with the specified initial capacity and a default load factor (0.75).
 378.187 +     *
 378.188 +     * @param  initialCapacity the initial capacity
 378.189 +     * @throws IllegalArgumentException if the initial capacity is negative
 378.190 +     */
 378.191 +    public LinkedHashMap(int initialCapacity) {
 378.192 +        super(initialCapacity);
 378.193 +        accessOrder = false;
 378.194 +    }
 378.195 +
 378.196 +    /**
 378.197 +     * Constructs an empty insertion-ordered <tt>LinkedHashMap</tt> instance
 378.198 +     * with the default initial capacity (16) and load factor (0.75).
 378.199 +     */
 378.200 +    public LinkedHashMap() {
 378.201 +        super();
 378.202 +        accessOrder = false;
 378.203 +    }
 378.204 +
 378.205 +    /**
 378.206 +     * Constructs an insertion-ordered <tt>LinkedHashMap</tt> instance with
 378.207 +     * the same mappings as the specified map.  The <tt>LinkedHashMap</tt>
 378.208 +     * instance is created with a default load factor (0.75) and an initial
 378.209 +     * capacity sufficient to hold the mappings in the specified map.
 378.210 +     *
 378.211 +     * @param  m the map whose mappings are to be placed in this map
 378.212 +     * @throws NullPointerException if the specified map is null
 378.213 +     */
 378.214 +    public LinkedHashMap(Map<? extends K, ? extends V> m) {
 378.215 +        super(m);
 378.216 +        accessOrder = false;
 378.217 +    }
 378.218 +
 378.219 +    /**
 378.220 +     * Constructs an empty <tt>LinkedHashMap</tt> instance with the
 378.221 +     * specified initial capacity, load factor and ordering mode.
 378.222 +     *
 378.223 +     * @param  initialCapacity the initial capacity
 378.224 +     * @param  loadFactor      the load factor
 378.225 +     * @param  accessOrder     the ordering mode - <tt>true</tt> for
 378.226 +     *         access-order, <tt>false</tt> for insertion-order
 378.227 +     * @throws IllegalArgumentException if the initial capacity is negative
 378.228 +     *         or the load factor is nonpositive
 378.229 +     */
 378.230 +    public LinkedHashMap(int initialCapacity,
 378.231 +                         float loadFactor,
 378.232 +                         boolean accessOrder) {
 378.233 +        super(initialCapacity, loadFactor);
 378.234 +        this.accessOrder = accessOrder;
 378.235 +    }
 378.236 +
 378.237 +    /**
 378.238 +     * Called by superclass constructors and pseudoconstructors (clone,
 378.239 +     * readObject) before any entries are inserted into the map.  Initializes
 378.240 +     * the chain.
 378.241 +     */
 378.242 +    void init() {
 378.243 +        header = new Entry<>(-1, null, null, null);
 378.244 +        header.before = header.after = header;
 378.245 +    }
 378.246 +
 378.247 +    /**
 378.248 +     * Transfers all entries to new table array.  This method is called
 378.249 +     * by superclass resize.  It is overridden for performance, as it is
 378.250 +     * faster to iterate using our linked list.
 378.251 +     */
 378.252 +    void transfer(HashMap.Entry[] newTable) {
 378.253 +        int newCapacity = newTable.length;
 378.254 +        for (Entry<K,V> e = header.after; e != header; e = e.after) {
 378.255 +            int index = indexFor(e.hash, newCapacity);
 378.256 +            e.next = newTable[index];
 378.257 +            newTable[index] = e;
 378.258 +        }
 378.259 +    }
 378.260 +
 378.261 +
 378.262 +    /**
 378.263 +     * Returns <tt>true</tt> if this map maps one or more keys to the
 378.264 +     * specified value.
 378.265 +     *
 378.266 +     * @param value value whose presence in this map is to be tested
 378.267 +     * @return <tt>true</tt> if this map maps one or more keys to the
 378.268 +     *         specified value
 378.269 +     */
 378.270 +    public boolean containsValue(Object value) {
 378.271 +        // Overridden to take advantage of faster iterator
 378.272 +        if (value==null) {
 378.273 +            for (Entry e = header.after; e != header; e = e.after)
 378.274 +                if (e.value==null)
 378.275 +                    return true;
 378.276 +        } else {
 378.277 +            for (Entry e = header.after; e != header; e = e.after)
 378.278 +                if (value.equals(e.value))
 378.279 +                    return true;
 378.280 +        }
 378.281 +        return false;
 378.282 +    }
 378.283 +
 378.284 +    /**
 378.285 +     * Returns the value to which the specified key is mapped,
 378.286 +     * or {@code null} if this map contains no mapping for the key.
 378.287 +     *
 378.288 +     * <p>More formally, if this map contains a mapping from a key
 378.289 +     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
 378.290 +     * key.equals(k))}, then this method returns {@code v}; otherwise
 378.291 +     * it returns {@code null}.  (There can be at most one such mapping.)
 378.292 +     *
 378.293 +     * <p>A return value of {@code null} does not <i>necessarily</i>
 378.294 +     * indicate that the map contains no mapping for the key; it's also
 378.295 +     * possible that the map explicitly maps the key to {@code null}.
 378.296 +     * The {@link #containsKey containsKey} operation may be used to
 378.297 +     * distinguish these two cases.
 378.298 +     */
 378.299 +    public V get(Object key) {
 378.300 +        Entry<K,V> e = (Entry<K,V>)getEntry(key);
 378.301 +        if (e == null)
 378.302 +            return null;
 378.303 +        e.recordAccess(this);
 378.304 +        return e.value;
 378.305 +    }
 378.306 +
 378.307 +    /**
 378.308 +     * Removes all of the mappings from this map.
 378.309 +     * The map will be empty after this call returns.
 378.310 +     */
 378.311 +    public void clear() {
 378.312 +        super.clear();
 378.313 +        header.before = header.after = header;
 378.314 +    }
 378.315 +
 378.316 +    /**
 378.317 +     * LinkedHashMap entry.
 378.318 +     */
 378.319 +    private static class Entry<K,V> extends HashMap.Entry<K,V> {
 378.320 +        // These fields comprise the doubly linked list used for iteration.
 378.321 +        Entry<K,V> before, after;
 378.322 +
 378.323 +        Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
 378.324 +            super(hash, key, value, next);
 378.325 +        }
 378.326 +
 378.327 +        /**
 378.328 +         * Removes this entry from the linked list.
 378.329 +         */
 378.330 +        private void remove() {
 378.331 +            before.after = after;
 378.332 +            after.before = before;
 378.333 +        }
 378.334 +
 378.335 +        /**
 378.336 +         * Inserts this entry before the specified existing entry in the list.
 378.337 +         */
 378.338 +        private void addBefore(Entry<K,V> existingEntry) {
 378.339 +            after  = existingEntry;
 378.340 +            before = existingEntry.before;
 378.341 +            before.after = this;
 378.342 +            after.before = this;
 378.343 +        }
 378.344 +
 378.345 +        /**
 378.346 +         * This method is invoked by the superclass whenever the value
 378.347 +         * of a pre-existing entry is read by Map.get or modified by Map.set.
 378.348 +         * If the enclosing Map is access-ordered, it moves the entry
 378.349 +         * to the end of the list; otherwise, it does nothing.
 378.350 +         */
 378.351 +        void recordAccess(HashMap<K,V> m) {
 378.352 +            LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;
 378.353 +            if (lm.accessOrder) {
 378.354 +                lm.modCount++;
 378.355 +                remove();
 378.356 +                addBefore(lm.header);
 378.357 +            }
 378.358 +        }
 378.359 +
 378.360 +        void recordRemoval(HashMap<K,V> m) {
 378.361 +            remove();
 378.362 +        }
 378.363 +    }
 378.364 +
 378.365 +    private abstract class LinkedHashIterator<T> implements Iterator<T> {
 378.366 +        Entry<K,V> nextEntry    = header.after;
 378.367 +        Entry<K,V> lastReturned = null;
 378.368 +
 378.369 +        /**
 378.370 +         * The modCount value that the iterator believes that the backing
 378.371 +         * List should have.  If this expectation is violated, the iterator
 378.372 +         * has detected concurrent modification.
 378.373 +         */
 378.374 +        int expectedModCount = modCount;
 378.375 +
 378.376 +        public boolean hasNext() {
 378.377 +            return nextEntry != header;
 378.378 +        }
 378.379 +
 378.380 +        public void remove() {
 378.381 +            if (lastReturned == null)
 378.382 +                throw new IllegalStateException();
 378.383 +            if (modCount != expectedModCount)
 378.384 +                throw new ConcurrentModificationException();
 378.385 +
 378.386 +            LinkedHashMap.this.remove(lastReturned.key);
 378.387 +            lastReturned = null;
 378.388 +            expectedModCount = modCount;
 378.389 +        }
 378.390 +
 378.391 +        Entry<K,V> nextEntry() {
 378.392 +            if (modCount != expectedModCount)
 378.393 +                throw new ConcurrentModificationException();
 378.394 +            if (nextEntry == header)
 378.395 +                throw new NoSuchElementException();
 378.396 +
 378.397 +            Entry<K,V> e = lastReturned = nextEntry;
 378.398 +            nextEntry = e.after;
 378.399 +            return e;
 378.400 +        }
 378.401 +    }
 378.402 +
 378.403 +    private class KeyIterator extends LinkedHashIterator<K> {
 378.404 +        public K next() { return nextEntry().getKey(); }
 378.405 +    }
 378.406 +
 378.407 +    private class ValueIterator extends LinkedHashIterator<V> {
 378.408 +        public V next() { return nextEntry().value; }
 378.409 +    }
 378.410 +
 378.411 +    private class EntryIterator extends LinkedHashIterator<Map.Entry<K,V>> {
 378.412 +        public Map.Entry<K,V> next() { return nextEntry(); }
 378.413 +    }
 378.414 +
 378.415 +    // These Overrides alter the behavior of superclass view iterator() methods
 378.416 +    Iterator<K> newKeyIterator()   { return new KeyIterator();   }
 378.417 +    Iterator<V> newValueIterator() { return new ValueIterator(); }
 378.418 +    Iterator<Map.Entry<K,V>> newEntryIterator() { return new EntryIterator(); }
 378.419 +
 378.420 +    /**
 378.421 +     * This override alters behavior of superclass put method. It causes newly
 378.422 +     * allocated entry to get inserted at the end of the linked list and
 378.423 +     * removes the eldest entry if appropriate.
 378.424 +     */
 378.425 +    void addEntry(int hash, K key, V value, int bucketIndex) {
 378.426 +        createEntry(hash, key, value, bucketIndex);
 378.427 +
 378.428 +        // Remove eldest entry if instructed, else grow capacity if appropriate
 378.429 +        Entry<K,V> eldest = header.after;
 378.430 +        if (removeEldestEntry(eldest)) {
 378.431 +            removeEntryForKey(eldest.key);
 378.432 +        } else {
 378.433 +            if (size >= threshold)
 378.434 +                resize(2 * table.length);
 378.435 +        }
 378.436 +    }
 378.437 +
 378.438 +    /**
 378.439 +     * This override differs from addEntry in that it doesn't resize the
 378.440 +     * table or remove the eldest entry.
 378.441 +     */
 378.442 +    void createEntry(int hash, K key, V value, int bucketIndex) {
 378.443 +        HashMap.Entry<K,V> old = table[bucketIndex];
 378.444 +        Entry<K,V> e = new Entry<>(hash, key, value, old);
 378.445 +        table[bucketIndex] = e;
 378.446 +        e.addBefore(header);
 378.447 +        size++;
 378.448 +    }
 378.449 +
 378.450 +    /**
 378.451 +     * Returns <tt>true</tt> if this map should remove its eldest entry.
 378.452 +     * This method is invoked by <tt>put</tt> and <tt>putAll</tt> after
 378.453 +     * inserting a new entry into the map.  It provides the implementor
 378.454 +     * with the opportunity to remove the eldest entry each time a new one
 378.455 +     * is added.  This is useful if the map represents a cache: it allows
 378.456 +     * the map to reduce memory consumption by deleting stale entries.
 378.457 +     *
 378.458 +     * <p>Sample use: this override will allow the map to grow up to 100
 378.459 +     * entries and then delete the eldest entry each time a new entry is
 378.460 +     * added, maintaining a steady state of 100 entries.
 378.461 +     * <pre>
 378.462 +     *     private static final int MAX_ENTRIES = 100;
 378.463 +     *
 378.464 +     *     protected boolean removeEldestEntry(Map.Entry eldest) {
 378.465 +     *        return size() > MAX_ENTRIES;
 378.466 +     *     }
 378.467 +     * </pre>
 378.468 +     *
 378.469 +     * <p>This method typically does not modify the map in any way,
 378.470 +     * instead allowing the map to modify itself as directed by its
 378.471 +     * return value.  It <i>is</i> permitted for this method to modify
 378.472 +     * the map directly, but if it does so, it <i>must</i> return
 378.473 +     * <tt>false</tt> (indicating that the map should not attempt any
 378.474 +     * further modification).  The effects of returning <tt>true</tt>
 378.475 +     * after modifying the map from within this method are unspecified.
 378.476 +     *
 378.477 +     * <p>This implementation merely returns <tt>false</tt> (so that this
 378.478 +     * map acts like a normal map - the eldest element is never removed).
 378.479 +     *
 378.480 +     * @param    eldest The least recently inserted entry in the map, or if
 378.481 +     *           this is an access-ordered map, the least recently accessed
 378.482 +     *           entry.  This is the entry that will be removed it this
 378.483 +     *           method returns <tt>true</tt>.  If the map was empty prior
 378.484 +     *           to the <tt>put</tt> or <tt>putAll</tt> invocation resulting
 378.485 +     *           in this invocation, this will be the entry that was just
 378.486 +     *           inserted; in other words, if the map contains a single
 378.487 +     *           entry, the eldest entry is also the newest.
 378.488 +     * @return   <tt>true</tt> if the eldest entry should be removed
 378.489 +     *           from the map; <tt>false</tt> if it should be retained.
 378.490 +     */
 378.491 +    protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
 378.492 +        return false;
 378.493 +    }
 378.494 +}
   379.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   379.2 +++ b/rt/emul/compact/src/main/java/java/util/LinkedList.java	Wed Feb 27 11:24:58 2013 +0100
   379.3 @@ -0,0 +1,1100 @@
   379.4 +/*
   379.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   379.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   379.7 + *
   379.8 + * This code is free software; you can redistribute it and/or modify it
   379.9 + * under the terms of the GNU General Public License version 2 only, as
  379.10 + * published by the Free Software Foundation.  Oracle designates this
  379.11 + * particular file as subject to the "Classpath" exception as provided
  379.12 + * by Oracle in the LICENSE file that accompanied this code.
  379.13 + *
  379.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  379.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  379.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  379.17 + * version 2 for more details (a copy is included in the LICENSE file that
  379.18 + * accompanied this code).
  379.19 + *
  379.20 + * You should have received a copy of the GNU General Public License version
  379.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  379.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  379.23 + *
  379.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  379.25 + * or visit www.oracle.com if you need additional information or have any
  379.26 + * questions.
  379.27 + */
  379.28 +
  379.29 +package java.util;
  379.30 +
  379.31 +/**
  379.32 + * Doubly-linked list implementation of the {@code List} and {@code Deque}
  379.33 + * interfaces.  Implements all optional list operations, and permits all
  379.34 + * elements (including {@code null}).
  379.35 + *
  379.36 + * <p>All of the operations perform as could be expected for a doubly-linked
  379.37 + * list.  Operations that index into the list will traverse the list from
  379.38 + * the beginning or the end, whichever is closer to the specified index.
  379.39 + *
  379.40 + * <p><strong>Note that this implementation is not synchronized.</strong>
  379.41 + * If multiple threads access a linked list concurrently, and at least
  379.42 + * one of the threads modifies the list structurally, it <i>must</i> be
  379.43 + * synchronized externally.  (A structural modification is any operation
  379.44 + * that adds or deletes one or more elements; merely setting the value of
  379.45 + * an element is not a structural modification.)  This is typically
  379.46 + * accomplished by synchronizing on some object that naturally
  379.47 + * encapsulates the list.
  379.48 + *
  379.49 + * If no such object exists, the list should be "wrapped" using the
  379.50 + * {@link Collections#synchronizedList Collections.synchronizedList}
  379.51 + * method.  This is best done at creation time, to prevent accidental
  379.52 + * unsynchronized access to the list:<pre>
  379.53 + *   List list = Collections.synchronizedList(new LinkedList(...));</pre>
  379.54 + *
  379.55 + * <p>The iterators returned by this class's {@code iterator} and
  379.56 + * {@code listIterator} methods are <i>fail-fast</i>: if the list is
  379.57 + * structurally modified at any time after the iterator is created, in
  379.58 + * any way except through the Iterator's own {@code remove} or
  379.59 + * {@code add} methods, the iterator will throw a {@link
  379.60 + * ConcurrentModificationException}.  Thus, in the face of concurrent
  379.61 + * modification, the iterator fails quickly and cleanly, rather than
  379.62 + * risking arbitrary, non-deterministic behavior at an undetermined
  379.63 + * time in the future.
  379.64 + *
  379.65 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  379.66 + * as it is, generally speaking, impossible to make any hard guarantees in the
  379.67 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  379.68 + * throw {@code ConcurrentModificationException} on a best-effort basis.
  379.69 + * Therefore, it would be wrong to write a program that depended on this
  379.70 + * exception for its correctness:   <i>the fail-fast behavior of iterators
  379.71 + * should be used only to detect bugs.</i>
  379.72 + *
  379.73 + * <p>This class is a member of the
  379.74 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  379.75 + * Java Collections Framework</a>.
  379.76 + *
  379.77 + * @author  Josh Bloch
  379.78 + * @see     List
  379.79 + * @see     ArrayList
  379.80 + * @since 1.2
  379.81 + * @param <E> the type of elements held in this collection
  379.82 + */
  379.83 +
  379.84 +public class LinkedList<E>
  379.85 +    extends AbstractSequentialList<E>
  379.86 +    implements List<E>, Deque<E>, Cloneable, java.io.Serializable
  379.87 +{
  379.88 +    transient int size = 0;
  379.89 +
  379.90 +    /**
  379.91 +     * Pointer to first node.
  379.92 +     * Invariant: (first == null && last == null) ||
  379.93 +     *            (first.prev == null && first.item != null)
  379.94 +     */
  379.95 +    transient Node<E> first;
  379.96 +
  379.97 +    /**
  379.98 +     * Pointer to last node.
  379.99 +     * Invariant: (first == null && last == null) ||
 379.100 +     *            (last.next == null && last.item != null)
 379.101 +     */
 379.102 +    transient Node<E> last;
 379.103 +
 379.104 +    /**
 379.105 +     * Constructs an empty list.
 379.106 +     */
 379.107 +    public LinkedList() {
 379.108 +    }
 379.109 +
 379.110 +    /**
 379.111 +     * Constructs a list containing the elements of the specified
 379.112 +     * collection, in the order they are returned by the collection's
 379.113 +     * iterator.
 379.114 +     *
 379.115 +     * @param  c the collection whose elements are to be placed into this list
 379.116 +     * @throws NullPointerException if the specified collection is null
 379.117 +     */
 379.118 +    public LinkedList(Collection<? extends E> c) {
 379.119 +        this();
 379.120 +        addAll(c);
 379.121 +    }
 379.122 +
 379.123 +    /**
 379.124 +     * Links e as first element.
 379.125 +     */
 379.126 +    private void linkFirst(E e) {
 379.127 +        final Node<E> f = first;
 379.128 +        final Node<E> newNode = new Node<>(null, e, f);
 379.129 +        first = newNode;
 379.130 +        if (f == null)
 379.131 +            last = newNode;
 379.132 +        else
 379.133 +            f.prev = newNode;
 379.134 +        size++;
 379.135 +        modCount++;
 379.136 +    }
 379.137 +
 379.138 +    /**
 379.139 +     * Links e as last element.
 379.140 +     */
 379.141 +    void linkLast(E e) {
 379.142 +        final Node<E> l = last;
 379.143 +        final Node<E> newNode = new Node<>(l, e, null);
 379.144 +        last = newNode;
 379.145 +        if (l == null)
 379.146 +            first = newNode;
 379.147 +        else
 379.148 +            l.next = newNode;
 379.149 +        size++;
 379.150 +        modCount++;
 379.151 +    }
 379.152 +
 379.153 +    /**
 379.154 +     * Inserts element e before non-null Node succ.
 379.155 +     */
 379.156 +    void linkBefore(E e, Node<E> succ) {
 379.157 +        // assert succ != null;
 379.158 +        final Node<E> pred = succ.prev;
 379.159 +        final Node<E> newNode = new Node<>(pred, e, succ);
 379.160 +        succ.prev = newNode;
 379.161 +        if (pred == null)
 379.162 +            first = newNode;
 379.163 +        else
 379.164 +            pred.next = newNode;
 379.165 +        size++;
 379.166 +        modCount++;
 379.167 +    }
 379.168 +
 379.169 +    /**
 379.170 +     * Unlinks non-null first node f.
 379.171 +     */
 379.172 +    private E unlinkFirst(Node<E> f) {
 379.173 +        // assert f == first && f != null;
 379.174 +        final E element = f.item;
 379.175 +        final Node<E> next = f.next;
 379.176 +        f.item = null;
 379.177 +        f.next = null; // help GC
 379.178 +        first = next;
 379.179 +        if (next == null)
 379.180 +            last = null;
 379.181 +        else
 379.182 +            next.prev = null;
 379.183 +        size--;
 379.184 +        modCount++;
 379.185 +        return element;
 379.186 +    }
 379.187 +
 379.188 +    /**
 379.189 +     * Unlinks non-null last node l.
 379.190 +     */
 379.191 +    private E unlinkLast(Node<E> l) {
 379.192 +        // assert l == last && l != null;
 379.193 +        final E element = l.item;
 379.194 +        final Node<E> prev = l.prev;
 379.195 +        l.item = null;
 379.196 +        l.prev = null; // help GC
 379.197 +        last = prev;
 379.198 +        if (prev == null)
 379.199 +            first = null;
 379.200 +        else
 379.201 +            prev.next = null;
 379.202 +        size--;
 379.203 +        modCount++;
 379.204 +        return element;
 379.205 +    }
 379.206 +
 379.207 +    /**
 379.208 +     * Unlinks non-null node x.
 379.209 +     */
 379.210 +    E unlink(Node<E> x) {
 379.211 +        // assert x != null;
 379.212 +        final E element = x.item;
 379.213 +        final Node<E> next = x.next;
 379.214 +        final Node<E> prev = x.prev;
 379.215 +
 379.216 +        if (prev == null) {
 379.217 +            first = next;
 379.218 +        } else {
 379.219 +            prev.next = next;
 379.220 +            x.prev = null;
 379.221 +        }
 379.222 +
 379.223 +        if (next == null) {
 379.224 +            last = prev;
 379.225 +        } else {
 379.226 +            next.prev = prev;
 379.227 +            x.next = null;
 379.228 +        }
 379.229 +
 379.230 +        x.item = null;
 379.231 +        size--;
 379.232 +        modCount++;
 379.233 +        return element;
 379.234 +    }
 379.235 +
 379.236 +    /**
 379.237 +     * Returns the first element in this list.
 379.238 +     *
 379.239 +     * @return the first element in this list
 379.240 +     * @throws NoSuchElementException if this list is empty
 379.241 +     */
 379.242 +    public E getFirst() {
 379.243 +        final Node<E> f = first;
 379.244 +        if (f == null)
 379.245 +            throw new NoSuchElementException();
 379.246 +        return f.item;
 379.247 +    }
 379.248 +
 379.249 +    /**
 379.250 +     * Returns the last element in this list.
 379.251 +     *
 379.252 +     * @return the last element in this list
 379.253 +     * @throws NoSuchElementException if this list is empty
 379.254 +     */
 379.255 +    public E getLast() {
 379.256 +        final Node<E> l = last;
 379.257 +        if (l == null)
 379.258 +            throw new NoSuchElementException();
 379.259 +        return l.item;
 379.260 +    }
 379.261 +
 379.262 +    /**
 379.263 +     * Removes and returns the first element from this list.
 379.264 +     *
 379.265 +     * @return the first element from this list
 379.266 +     * @throws NoSuchElementException if this list is empty
 379.267 +     */
 379.268 +    public E removeFirst() {
 379.269 +        final Node<E> f = first;
 379.270 +        if (f == null)
 379.271 +            throw new NoSuchElementException();
 379.272 +        return unlinkFirst(f);
 379.273 +    }
 379.274 +
 379.275 +    /**
 379.276 +     * Removes and returns the last element from this list.
 379.277 +     *
 379.278 +     * @return the last element from this list
 379.279 +     * @throws NoSuchElementException if this list is empty
 379.280 +     */
 379.281 +    public E removeLast() {
 379.282 +        final Node<E> l = last;
 379.283 +        if (l == null)
 379.284 +            throw new NoSuchElementException();
 379.285 +        return unlinkLast(l);
 379.286 +    }
 379.287 +
 379.288 +    /**
 379.289 +     * Inserts the specified element at the beginning of this list.
 379.290 +     *
 379.291 +     * @param e the element to add
 379.292 +     */
 379.293 +    public void addFirst(E e) {
 379.294 +        linkFirst(e);
 379.295 +    }
 379.296 +
 379.297 +    /**
 379.298 +     * Appends the specified element to the end of this list.
 379.299 +     *
 379.300 +     * <p>This method is equivalent to {@link #add}.
 379.301 +     *
 379.302 +     * @param e the element to add
 379.303 +     */
 379.304 +    public void addLast(E e) {
 379.305 +        linkLast(e);
 379.306 +    }
 379.307 +
 379.308 +    /**
 379.309 +     * Returns {@code true} if this list contains the specified element.
 379.310 +     * More formally, returns {@code true} if and only if this list contains
 379.311 +     * at least one element {@code e} such that
 379.312 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 379.313 +     *
 379.314 +     * @param o element whose presence in this list is to be tested
 379.315 +     * @return {@code true} if this list contains the specified element
 379.316 +     */
 379.317 +    public boolean contains(Object o) {
 379.318 +        return indexOf(o) != -1;
 379.319 +    }
 379.320 +
 379.321 +    /**
 379.322 +     * Returns the number of elements in this list.
 379.323 +     *
 379.324 +     * @return the number of elements in this list
 379.325 +     */
 379.326 +    public int size() {
 379.327 +        return size;
 379.328 +    }
 379.329 +
 379.330 +    /**
 379.331 +     * Appends the specified element to the end of this list.
 379.332 +     *
 379.333 +     * <p>This method is equivalent to {@link #addLast}.
 379.334 +     *
 379.335 +     * @param e element to be appended to this list
 379.336 +     * @return {@code true} (as specified by {@link Collection#add})
 379.337 +     */
 379.338 +    public boolean add(E e) {
 379.339 +        linkLast(e);
 379.340 +        return true;
 379.341 +    }
 379.342 +
 379.343 +    /**
 379.344 +     * Removes the first occurrence of the specified element from this list,
 379.345 +     * if it is present.  If this list does not contain the element, it is
 379.346 +     * unchanged.  More formally, removes the element with the lowest index
 379.347 +     * {@code i} such that
 379.348 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
 379.349 +     * (if such an element exists).  Returns {@code true} if this list
 379.350 +     * contained the specified element (or equivalently, if this list
 379.351 +     * changed as a result of the call).
 379.352 +     *
 379.353 +     * @param o element to be removed from this list, if present
 379.354 +     * @return {@code true} if this list contained the specified element
 379.355 +     */
 379.356 +    public boolean remove(Object o) {
 379.357 +        if (o == null) {
 379.358 +            for (Node<E> x = first; x != null; x = x.next) {
 379.359 +                if (x.item == null) {
 379.360 +                    unlink(x);
 379.361 +                    return true;
 379.362 +                }
 379.363 +            }
 379.364 +        } else {
 379.365 +            for (Node<E> x = first; x != null; x = x.next) {
 379.366 +                if (o.equals(x.item)) {
 379.367 +                    unlink(x);
 379.368 +                    return true;
 379.369 +                }
 379.370 +            }
 379.371 +        }
 379.372 +        return false;
 379.373 +    }
 379.374 +
 379.375 +    /**
 379.376 +     * Appends all of the elements in the specified collection to the end of
 379.377 +     * this list, in the order that they are returned by the specified
 379.378 +     * collection's iterator.  The behavior of this operation is undefined if
 379.379 +     * the specified collection is modified while the operation is in
 379.380 +     * progress.  (Note that this will occur if the specified collection is
 379.381 +     * this list, and it's nonempty.)
 379.382 +     *
 379.383 +     * @param c collection containing elements to be added to this list
 379.384 +     * @return {@code true} if this list changed as a result of the call
 379.385 +     * @throws NullPointerException if the specified collection is null
 379.386 +     */
 379.387 +    public boolean addAll(Collection<? extends E> c) {
 379.388 +        return addAll(size, c);
 379.389 +    }
 379.390 +
 379.391 +    /**
 379.392 +     * Inserts all of the elements in the specified collection into this
 379.393 +     * list, starting at the specified position.  Shifts the element
 379.394 +     * currently at that position (if any) and any subsequent elements to
 379.395 +     * the right (increases their indices).  The new elements will appear
 379.396 +     * in the list in the order that they are returned by the
 379.397 +     * specified collection's iterator.
 379.398 +     *
 379.399 +     * @param index index at which to insert the first element
 379.400 +     *              from the specified collection
 379.401 +     * @param c collection containing elements to be added to this list
 379.402 +     * @return {@code true} if this list changed as a result of the call
 379.403 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 379.404 +     * @throws NullPointerException if the specified collection is null
 379.405 +     */
 379.406 +    public boolean addAll(int index, Collection<? extends E> c) {
 379.407 +        checkPositionIndex(index);
 379.408 +
 379.409 +        Object[] a = c.toArray();
 379.410 +        int numNew = a.length;
 379.411 +        if (numNew == 0)
 379.412 +            return false;
 379.413 +
 379.414 +        Node<E> pred, succ;
 379.415 +        if (index == size) {
 379.416 +            succ = null;
 379.417 +            pred = last;
 379.418 +        } else {
 379.419 +            succ = node(index);
 379.420 +            pred = succ.prev;
 379.421 +        }
 379.422 +
 379.423 +        for (Object o : a) {
 379.424 +            @SuppressWarnings("unchecked") E e = (E) o;
 379.425 +            Node<E> newNode = new Node<>(pred, e, null);
 379.426 +            if (pred == null)
 379.427 +                first = newNode;
 379.428 +            else
 379.429 +                pred.next = newNode;
 379.430 +            pred = newNode;
 379.431 +        }
 379.432 +
 379.433 +        if (succ == null) {
 379.434 +            last = pred;
 379.435 +        } else {
 379.436 +            pred.next = succ;
 379.437 +            succ.prev = pred;
 379.438 +        }
 379.439 +
 379.440 +        size += numNew;
 379.441 +        modCount++;
 379.442 +        return true;
 379.443 +    }
 379.444 +
 379.445 +    /**
 379.446 +     * Removes all of the elements from this list.
 379.447 +     * The list will be empty after this call returns.
 379.448 +     */
 379.449 +    public void clear() {
 379.450 +        // Clearing all of the links between nodes is "unnecessary", but:
 379.451 +        // - helps a generational GC if the discarded nodes inhabit
 379.452 +        //   more than one generation
 379.453 +        // - is sure to free memory even if there is a reachable Iterator
 379.454 +        for (Node<E> x = first; x != null; ) {
 379.455 +            Node<E> next = x.next;
 379.456 +            x.item = null;
 379.457 +            x.next = null;
 379.458 +            x.prev = null;
 379.459 +            x = next;
 379.460 +        }
 379.461 +        first = last = null;
 379.462 +        size = 0;
 379.463 +        modCount++;
 379.464 +    }
 379.465 +
 379.466 +
 379.467 +    // Positional Access Operations
 379.468 +
 379.469 +    /**
 379.470 +     * Returns the element at the specified position in this list.
 379.471 +     *
 379.472 +     * @param index index of the element to return
 379.473 +     * @return the element at the specified position in this list
 379.474 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 379.475 +     */
 379.476 +    public E get(int index) {
 379.477 +        checkElementIndex(index);
 379.478 +        return node(index).item;
 379.479 +    }
 379.480 +
 379.481 +    /**
 379.482 +     * Replaces the element at the specified position in this list with the
 379.483 +     * specified element.
 379.484 +     *
 379.485 +     * @param index index of the element to replace
 379.486 +     * @param element element to be stored at the specified position
 379.487 +     * @return the element previously at the specified position
 379.488 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 379.489 +     */
 379.490 +    public E set(int index, E element) {
 379.491 +        checkElementIndex(index);
 379.492 +        Node<E> x = node(index);
 379.493 +        E oldVal = x.item;
 379.494 +        x.item = element;
 379.495 +        return oldVal;
 379.496 +    }
 379.497 +
 379.498 +    /**
 379.499 +     * Inserts the specified element at the specified position in this list.
 379.500 +     * Shifts the element currently at that position (if any) and any
 379.501 +     * subsequent elements to the right (adds one to their indices).
 379.502 +     *
 379.503 +     * @param index index at which the specified element is to be inserted
 379.504 +     * @param element element to be inserted
 379.505 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 379.506 +     */
 379.507 +    public void add(int index, E element) {
 379.508 +        checkPositionIndex(index);
 379.509 +
 379.510 +        if (index == size)
 379.511 +            linkLast(element);
 379.512 +        else
 379.513 +            linkBefore(element, node(index));
 379.514 +    }
 379.515 +
 379.516 +    /**
 379.517 +     * Removes the element at the specified position in this list.  Shifts any
 379.518 +     * subsequent elements to the left (subtracts one from their indices).
 379.519 +     * Returns the element that was removed from the list.
 379.520 +     *
 379.521 +     * @param index the index of the element to be removed
 379.522 +     * @return the element previously at the specified position
 379.523 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 379.524 +     */
 379.525 +    public E remove(int index) {
 379.526 +        checkElementIndex(index);
 379.527 +        return unlink(node(index));
 379.528 +    }
 379.529 +
 379.530 +    /**
 379.531 +     * Tells if the argument is the index of an existing element.
 379.532 +     */
 379.533 +    private boolean isElementIndex(int index) {
 379.534 +        return index >= 0 && index < size;
 379.535 +    }
 379.536 +
 379.537 +    /**
 379.538 +     * Tells if the argument is the index of a valid position for an
 379.539 +     * iterator or an add operation.
 379.540 +     */
 379.541 +    private boolean isPositionIndex(int index) {
 379.542 +        return index >= 0 && index <= size;
 379.543 +    }
 379.544 +
 379.545 +    /**
 379.546 +     * Constructs an IndexOutOfBoundsException detail message.
 379.547 +     * Of the many possible refactorings of the error handling code,
 379.548 +     * this "outlining" performs best with both server and client VMs.
 379.549 +     */
 379.550 +    private String outOfBoundsMsg(int index) {
 379.551 +        return "Index: "+index+", Size: "+size;
 379.552 +    }
 379.553 +
 379.554 +    private void checkElementIndex(int index) {
 379.555 +        if (!isElementIndex(index))
 379.556 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 379.557 +    }
 379.558 +
 379.559 +    private void checkPositionIndex(int index) {
 379.560 +        if (!isPositionIndex(index))
 379.561 +            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
 379.562 +    }
 379.563 +
 379.564 +    /**
 379.565 +     * Returns the (non-null) Node at the specified element index.
 379.566 +     */
 379.567 +    Node<E> node(int index) {
 379.568 +        // assert isElementIndex(index);
 379.569 +
 379.570 +        if (index < (size >> 1)) {
 379.571 +            Node<E> x = first;
 379.572 +            for (int i = 0; i < index; i++)
 379.573 +                x = x.next;
 379.574 +            return x;
 379.575 +        } else {
 379.576 +            Node<E> x = last;
 379.577 +            for (int i = size - 1; i > index; i--)
 379.578 +                x = x.prev;
 379.579 +            return x;
 379.580 +        }
 379.581 +    }
 379.582 +
 379.583 +    // Search Operations
 379.584 +
 379.585 +    /**
 379.586 +     * Returns the index of the first occurrence of the specified element
 379.587 +     * in this list, or -1 if this list does not contain the element.
 379.588 +     * More formally, returns the lowest index {@code i} such that
 379.589 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 379.590 +     * or -1 if there is no such index.
 379.591 +     *
 379.592 +     * @param o element to search for
 379.593 +     * @return the index of the first occurrence of the specified element in
 379.594 +     *         this list, or -1 if this list does not contain the element
 379.595 +     */
 379.596 +    public int indexOf(Object o) {
 379.597 +        int index = 0;
 379.598 +        if (o == null) {
 379.599 +            for (Node<E> x = first; x != null; x = x.next) {
 379.600 +                if (x.item == null)
 379.601 +                    return index;
 379.602 +                index++;
 379.603 +            }
 379.604 +        } else {
 379.605 +            for (Node<E> x = first; x != null; x = x.next) {
 379.606 +                if (o.equals(x.item))
 379.607 +                    return index;
 379.608 +                index++;
 379.609 +            }
 379.610 +        }
 379.611 +        return -1;
 379.612 +    }
 379.613 +
 379.614 +    /**
 379.615 +     * Returns the index of the last occurrence of the specified element
 379.616 +     * in this list, or -1 if this list does not contain the element.
 379.617 +     * More formally, returns the highest index {@code i} such that
 379.618 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 379.619 +     * or -1 if there is no such index.
 379.620 +     *
 379.621 +     * @param o element to search for
 379.622 +     * @return the index of the last occurrence of the specified element in
 379.623 +     *         this list, or -1 if this list does not contain the element
 379.624 +     */
 379.625 +    public int lastIndexOf(Object o) {
 379.626 +        int index = size;
 379.627 +        if (o == null) {
 379.628 +            for (Node<E> x = last; x != null; x = x.prev) {
 379.629 +                index--;
 379.630 +                if (x.item == null)
 379.631 +                    return index;
 379.632 +            }
 379.633 +        } else {
 379.634 +            for (Node<E> x = last; x != null; x = x.prev) {
 379.635 +                index--;
 379.636 +                if (o.equals(x.item))
 379.637 +                    return index;
 379.638 +            }
 379.639 +        }
 379.640 +        return -1;
 379.641 +    }
 379.642 +
 379.643 +    // Queue operations.
 379.644 +
 379.645 +    /**
 379.646 +     * Retrieves, but does not remove, the head (first element) of this list.
 379.647 +     *
 379.648 +     * @return the head of this list, or {@code null} if this list is empty
 379.649 +     * @since 1.5
 379.650 +     */
 379.651 +    public E peek() {
 379.652 +        final Node<E> f = first;
 379.653 +        return (f == null) ? null : f.item;
 379.654 +    }
 379.655 +
 379.656 +    /**
 379.657 +     * Retrieves, but does not remove, the head (first element) of this list.
 379.658 +     *
 379.659 +     * @return the head of this list
 379.660 +     * @throws NoSuchElementException if this list is empty
 379.661 +     * @since 1.5
 379.662 +     */
 379.663 +    public E element() {
 379.664 +        return getFirst();
 379.665 +    }
 379.666 +
 379.667 +    /**
 379.668 +     * Retrieves and removes the head (first element) of this list.
 379.669 +     *
 379.670 +     * @return the head of this list, or {@code null} if this list is empty
 379.671 +     * @since 1.5
 379.672 +     */
 379.673 +    public E poll() {
 379.674 +        final Node<E> f = first;
 379.675 +        return (f == null) ? null : unlinkFirst(f);
 379.676 +    }
 379.677 +
 379.678 +    /**
 379.679 +     * Retrieves and removes the head (first element) of this list.
 379.680 +     *
 379.681 +     * @return the head of this list
 379.682 +     * @throws NoSuchElementException if this list is empty
 379.683 +     * @since 1.5
 379.684 +     */
 379.685 +    public E remove() {
 379.686 +        return removeFirst();
 379.687 +    }
 379.688 +
 379.689 +    /**
 379.690 +     * Adds the specified element as the tail (last element) of this list.
 379.691 +     *
 379.692 +     * @param e the element to add
 379.693 +     * @return {@code true} (as specified by {@link Queue#offer})
 379.694 +     * @since 1.5
 379.695 +     */
 379.696 +    public boolean offer(E e) {
 379.697 +        return add(e);
 379.698 +    }
 379.699 +
 379.700 +    // Deque operations
 379.701 +    /**
 379.702 +     * Inserts the specified element at the front of this list.
 379.703 +     *
 379.704 +     * @param e the element to insert
 379.705 +     * @return {@code true} (as specified by {@link Deque#offerFirst})
 379.706 +     * @since 1.6
 379.707 +     */
 379.708 +    public boolean offerFirst(E e) {
 379.709 +        addFirst(e);
 379.710 +        return true;
 379.711 +    }
 379.712 +
 379.713 +    /**
 379.714 +     * Inserts the specified element at the end of this list.
 379.715 +     *
 379.716 +     * @param e the element to insert
 379.717 +     * @return {@code true} (as specified by {@link Deque#offerLast})
 379.718 +     * @since 1.6
 379.719 +     */
 379.720 +    public boolean offerLast(E e) {
 379.721 +        addLast(e);
 379.722 +        return true;
 379.723 +    }
 379.724 +
 379.725 +    /**
 379.726 +     * Retrieves, but does not remove, the first element of this list,
 379.727 +     * or returns {@code null} if this list is empty.
 379.728 +     *
 379.729 +     * @return the first element of this list, or {@code null}
 379.730 +     *         if this list is empty
 379.731 +     * @since 1.6
 379.732 +     */
 379.733 +    public E peekFirst() {
 379.734 +        final Node<E> f = first;
 379.735 +        return (f == null) ? null : f.item;
 379.736 +     }
 379.737 +
 379.738 +    /**
 379.739 +     * Retrieves, but does not remove, the last element of this list,
 379.740 +     * or returns {@code null} if this list is empty.
 379.741 +     *
 379.742 +     * @return the last element of this list, or {@code null}
 379.743 +     *         if this list is empty
 379.744 +     * @since 1.6
 379.745 +     */
 379.746 +    public E peekLast() {
 379.747 +        final Node<E> l = last;
 379.748 +        return (l == null) ? null : l.item;
 379.749 +    }
 379.750 +
 379.751 +    /**
 379.752 +     * Retrieves and removes the first element of this list,
 379.753 +     * or returns {@code null} if this list is empty.
 379.754 +     *
 379.755 +     * @return the first element of this list, or {@code null} if
 379.756 +     *     this list is empty
 379.757 +     * @since 1.6
 379.758 +     */
 379.759 +    public E pollFirst() {
 379.760 +        final Node<E> f = first;
 379.761 +        return (f == null) ? null : unlinkFirst(f);
 379.762 +    }
 379.763 +
 379.764 +    /**
 379.765 +     * Retrieves and removes the last element of this list,
 379.766 +     * or returns {@code null} if this list is empty.
 379.767 +     *
 379.768 +     * @return the last element of this list, or {@code null} if
 379.769 +     *     this list is empty
 379.770 +     * @since 1.6
 379.771 +     */
 379.772 +    public E pollLast() {
 379.773 +        final Node<E> l = last;
 379.774 +        return (l == null) ? null : unlinkLast(l);
 379.775 +    }
 379.776 +
 379.777 +    /**
 379.778 +     * Pushes an element onto the stack represented by this list.  In other
 379.779 +     * words, inserts the element at the front of this list.
 379.780 +     *
 379.781 +     * <p>This method is equivalent to {@link #addFirst}.
 379.782 +     *
 379.783 +     * @param e the element to push
 379.784 +     * @since 1.6
 379.785 +     */
 379.786 +    public void push(E e) {
 379.787 +        addFirst(e);
 379.788 +    }
 379.789 +
 379.790 +    /**
 379.791 +     * Pops an element from the stack represented by this list.  In other
 379.792 +     * words, removes and returns the first element of this list.
 379.793 +     *
 379.794 +     * <p>This method is equivalent to {@link #removeFirst()}.
 379.795 +     *
 379.796 +     * @return the element at the front of this list (which is the top
 379.797 +     *         of the stack represented by this list)
 379.798 +     * @throws NoSuchElementException if this list is empty
 379.799 +     * @since 1.6
 379.800 +     */
 379.801 +    public E pop() {
 379.802 +        return removeFirst();
 379.803 +    }
 379.804 +
 379.805 +    /**
 379.806 +     * Removes the first occurrence of the specified element in this
 379.807 +     * list (when traversing the list from head to tail).  If the list
 379.808 +     * does not contain the element, it is unchanged.
 379.809 +     *
 379.810 +     * @param o element to be removed from this list, if present
 379.811 +     * @return {@code true} if the list contained the specified element
 379.812 +     * @since 1.6
 379.813 +     */
 379.814 +    public boolean removeFirstOccurrence(Object o) {
 379.815 +        return remove(o);
 379.816 +    }
 379.817 +
 379.818 +    /**
 379.819 +     * Removes the last occurrence of the specified element in this
 379.820 +     * list (when traversing the list from head to tail).  If the list
 379.821 +     * does not contain the element, it is unchanged.
 379.822 +     *
 379.823 +     * @param o element to be removed from this list, if present
 379.824 +     * @return {@code true} if the list contained the specified element
 379.825 +     * @since 1.6
 379.826 +     */
 379.827 +    public boolean removeLastOccurrence(Object o) {
 379.828 +        if (o == null) {
 379.829 +            for (Node<E> x = last; x != null; x = x.prev) {
 379.830 +                if (x.item == null) {
 379.831 +                    unlink(x);
 379.832 +                    return true;
 379.833 +                }
 379.834 +            }
 379.835 +        } else {
 379.836 +            for (Node<E> x = last; x != null; x = x.prev) {
 379.837 +                if (o.equals(x.item)) {
 379.838 +                    unlink(x);
 379.839 +                    return true;
 379.840 +                }
 379.841 +            }
 379.842 +        }
 379.843 +        return false;
 379.844 +    }
 379.845 +
 379.846 +    /**
 379.847 +     * Returns a list-iterator of the elements in this list (in proper
 379.848 +     * sequence), starting at the specified position in the list.
 379.849 +     * Obeys the general contract of {@code List.listIterator(int)}.<p>
 379.850 +     *
 379.851 +     * The list-iterator is <i>fail-fast</i>: if the list is structurally
 379.852 +     * modified at any time after the Iterator is created, in any way except
 379.853 +     * through the list-iterator's own {@code remove} or {@code add}
 379.854 +     * methods, the list-iterator will throw a
 379.855 +     * {@code ConcurrentModificationException}.  Thus, in the face of
 379.856 +     * concurrent modification, the iterator fails quickly and cleanly, rather
 379.857 +     * than risking arbitrary, non-deterministic behavior at an undetermined
 379.858 +     * time in the future.
 379.859 +     *
 379.860 +     * @param index index of the first element to be returned from the
 379.861 +     *              list-iterator (by a call to {@code next})
 379.862 +     * @return a ListIterator of the elements in this list (in proper
 379.863 +     *         sequence), starting at the specified position in the list
 379.864 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 379.865 +     * @see List#listIterator(int)
 379.866 +     */
 379.867 +    public ListIterator<E> listIterator(int index) {
 379.868 +        checkPositionIndex(index);
 379.869 +        return new ListItr(index);
 379.870 +    }
 379.871 +
 379.872 +    private class ListItr implements ListIterator<E> {
 379.873 +        private Node<E> lastReturned = null;
 379.874 +        private Node<E> next;
 379.875 +        private int nextIndex;
 379.876 +        private int expectedModCount = modCount;
 379.877 +
 379.878 +        ListItr(int index) {
 379.879 +            // assert isPositionIndex(index);
 379.880 +            next = (index == size) ? null : node(index);
 379.881 +            nextIndex = index;
 379.882 +        }
 379.883 +
 379.884 +        public boolean hasNext() {
 379.885 +            return nextIndex < size;
 379.886 +        }
 379.887 +
 379.888 +        public E next() {
 379.889 +            checkForComodification();
 379.890 +            if (!hasNext())
 379.891 +                throw new NoSuchElementException();
 379.892 +
 379.893 +            lastReturned = next;
 379.894 +            next = next.next;
 379.895 +            nextIndex++;
 379.896 +            return lastReturned.item;
 379.897 +        }
 379.898 +
 379.899 +        public boolean hasPrevious() {
 379.900 +            return nextIndex > 0;
 379.901 +        }
 379.902 +
 379.903 +        public E previous() {
 379.904 +            checkForComodification();
 379.905 +            if (!hasPrevious())
 379.906 +                throw new NoSuchElementException();
 379.907 +
 379.908 +            lastReturned = next = (next == null) ? last : next.prev;
 379.909 +            nextIndex--;
 379.910 +            return lastReturned.item;
 379.911 +        }
 379.912 +
 379.913 +        public int nextIndex() {
 379.914 +            return nextIndex;
 379.915 +        }
 379.916 +
 379.917 +        public int previousIndex() {
 379.918 +            return nextIndex - 1;
 379.919 +        }
 379.920 +
 379.921 +        public void remove() {
 379.922 +            checkForComodification();
 379.923 +            if (lastReturned == null)
 379.924 +                throw new IllegalStateException();
 379.925 +
 379.926 +            Node<E> lastNext = lastReturned.next;
 379.927 +            unlink(lastReturned);
 379.928 +            if (next == lastReturned)
 379.929 +                next = lastNext;
 379.930 +            else
 379.931 +                nextIndex--;
 379.932 +            lastReturned = null;
 379.933 +            expectedModCount++;
 379.934 +        }
 379.935 +
 379.936 +        public void set(E e) {
 379.937 +            if (lastReturned == null)
 379.938 +                throw new IllegalStateException();
 379.939 +            checkForComodification();
 379.940 +            lastReturned.item = e;
 379.941 +        }
 379.942 +
 379.943 +        public void add(E e) {
 379.944 +            checkForComodification();
 379.945 +            lastReturned = null;
 379.946 +            if (next == null)
 379.947 +                linkLast(e);
 379.948 +            else
 379.949 +                linkBefore(e, next);
 379.950 +            nextIndex++;
 379.951 +            expectedModCount++;
 379.952 +        }
 379.953 +
 379.954 +        final void checkForComodification() {
 379.955 +            if (modCount != expectedModCount)
 379.956 +                throw new ConcurrentModificationException();
 379.957 +        }
 379.958 +    }
 379.959 +
 379.960 +    private static class Node<E> {
 379.961 +        E item;
 379.962 +        Node<E> next;
 379.963 +        Node<E> prev;
 379.964 +
 379.965 +        Node(Node<E> prev, E element, Node<E> next) {
 379.966 +            this.item = element;
 379.967 +            this.next = next;
 379.968 +            this.prev = prev;
 379.969 +        }
 379.970 +    }
 379.971 +
 379.972 +    /**
 379.973 +     * @since 1.6
 379.974 +     */
 379.975 +    public Iterator<E> descendingIterator() {
 379.976 +        return new DescendingIterator();
 379.977 +    }
 379.978 +
 379.979 +    /**
 379.980 +     * Adapter to provide descending iterators via ListItr.previous
 379.981 +     */
 379.982 +    private class DescendingIterator implements Iterator<E> {
 379.983 +        private final ListItr itr = new ListItr(size());
 379.984 +        public boolean hasNext() {
 379.985 +            return itr.hasPrevious();
 379.986 +        }
 379.987 +        public E next() {
 379.988 +            return itr.previous();
 379.989 +        }
 379.990 +        public void remove() {
 379.991 +            itr.remove();
 379.992 +        }
 379.993 +    }
 379.994 +
 379.995 +    @SuppressWarnings("unchecked")
 379.996 +    private LinkedList<E> superClone() {
 379.997 +        try {
 379.998 +            return (LinkedList<E>) super.clone();
 379.999 +        } catch (CloneNotSupportedException e) {
379.1000 +            throw new InternalError();
379.1001 +        }
379.1002 +    }
379.1003 +
379.1004 +    /**
379.1005 +     * Returns a shallow copy of this {@code LinkedList}. (The elements
379.1006 +     * themselves are not cloned.)
379.1007 +     *
379.1008 +     * @return a shallow copy of this {@code LinkedList} instance
379.1009 +     */
379.1010 +    public Object clone() {
379.1011 +        LinkedList<E> clone = superClone();
379.1012 +
379.1013 +        // Put clone into "virgin" state
379.1014 +        clone.first = clone.last = null;
379.1015 +        clone.size = 0;
379.1016 +        clone.modCount = 0;
379.1017 +
379.1018 +        // Initialize clone with our elements
379.1019 +        for (Node<E> x = first; x != null; x = x.next)
379.1020 +            clone.add(x.item);
379.1021 +
379.1022 +        return clone;
379.1023 +    }
379.1024 +
379.1025 +    /**
379.1026 +     * Returns an array containing all of the elements in this list
379.1027 +     * in proper sequence (from first to last element).
379.1028 +     *
379.1029 +     * <p>The returned array will be "safe" in that no references to it are
379.1030 +     * maintained by this list.  (In other words, this method must allocate
379.1031 +     * a new array).  The caller is thus free to modify the returned array.
379.1032 +     *
379.1033 +     * <p>This method acts as bridge between array-based and collection-based
379.1034 +     * APIs.
379.1035 +     *
379.1036 +     * @return an array containing all of the elements in this list
379.1037 +     *         in proper sequence
379.1038 +     */
379.1039 +    public Object[] toArray() {
379.1040 +        Object[] result = new Object[size];
379.1041 +        int i = 0;
379.1042 +        for (Node<E> x = first; x != null; x = x.next)
379.1043 +            result[i++] = x.item;
379.1044 +        return result;
379.1045 +    }
379.1046 +
379.1047 +    /**
379.1048 +     * Returns an array containing all of the elements in this list in
379.1049 +     * proper sequence (from first to last element); the runtime type of
379.1050 +     * the returned array is that of the specified array.  If the list fits
379.1051 +     * in the specified array, it is returned therein.  Otherwise, a new
379.1052 +     * array is allocated with the runtime type of the specified array and
379.1053 +     * the size of this list.
379.1054 +     *
379.1055 +     * <p>If the list fits in the specified array with room to spare (i.e.,
379.1056 +     * the array has more elements than the list), the element in the array
379.1057 +     * immediately following the end of the list is set to {@code null}.
379.1058 +     * (This is useful in determining the length of the list <i>only</i> if
379.1059 +     * the caller knows that the list does not contain any null elements.)
379.1060 +     *
379.1061 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
379.1062 +     * array-based and collection-based APIs.  Further, this method allows
379.1063 +     * precise control over the runtime type of the output array, and may,
379.1064 +     * under certain circumstances, be used to save allocation costs.
379.1065 +     *
379.1066 +     * <p>Suppose {@code x} is a list known to contain only strings.
379.1067 +     * The following code can be used to dump the list into a newly
379.1068 +     * allocated array of {@code String}:
379.1069 +     *
379.1070 +     * <pre>
379.1071 +     *     String[] y = x.toArray(new String[0]);</pre>
379.1072 +     *
379.1073 +     * Note that {@code toArray(new Object[0])} is identical in function to
379.1074 +     * {@code toArray()}.
379.1075 +     *
379.1076 +     * @param a the array into which the elements of the list are to
379.1077 +     *          be stored, if it is big enough; otherwise, a new array of the
379.1078 +     *          same runtime type is allocated for this purpose.
379.1079 +     * @return an array containing the elements of the list
379.1080 +     * @throws ArrayStoreException if the runtime type of the specified array
379.1081 +     *         is not a supertype of the runtime type of every element in
379.1082 +     *         this list
379.1083 +     * @throws NullPointerException if the specified array is null
379.1084 +     */
379.1085 +    @SuppressWarnings("unchecked")
379.1086 +    public <T> T[] toArray(T[] a) {
379.1087 +        if (a.length < size)
379.1088 +            a = (T[])java.lang.reflect.Array.newInstance(
379.1089 +                                a.getClass().getComponentType(), size);
379.1090 +        int i = 0;
379.1091 +        Object[] result = a;
379.1092 +        for (Node<E> x = first; x != null; x = x.next)
379.1093 +            result[i++] = x.item;
379.1094 +
379.1095 +        if (a.length > size)
379.1096 +            a[size] = null;
379.1097 +
379.1098 +        return a;
379.1099 +    }
379.1100 +
379.1101 +    private static final long serialVersionUID = 876323262645176354L;
379.1102 +
379.1103 +}
   380.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   380.2 +++ b/rt/emul/compact/src/main/java/java/util/List.java	Wed Feb 27 11:24:58 2013 +0100
   380.3 @@ -0,0 +1,600 @@
   380.4 +/*
   380.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   380.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   380.7 + *
   380.8 + * This code is free software; you can redistribute it and/or modify it
   380.9 + * under the terms of the GNU General Public License version 2 only, as
  380.10 + * published by the Free Software Foundation.  Oracle designates this
  380.11 + * particular file as subject to the "Classpath" exception as provided
  380.12 + * by Oracle in the LICENSE file that accompanied this code.
  380.13 + *
  380.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  380.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  380.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  380.17 + * version 2 for more details (a copy is included in the LICENSE file that
  380.18 + * accompanied this code).
  380.19 + *
  380.20 + * You should have received a copy of the GNU General Public License version
  380.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  380.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  380.23 + *
  380.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  380.25 + * or visit www.oracle.com if you need additional information or have any
  380.26 + * questions.
  380.27 + */
  380.28 +
  380.29 +package java.util;
  380.30 +
  380.31 +/**
  380.32 + * An ordered collection (also known as a <i>sequence</i>).  The user of this
  380.33 + * interface has precise control over where in the list each element is
  380.34 + * inserted.  The user can access elements by their integer index (position in
  380.35 + * the list), and search for elements in the list.<p>
  380.36 + *
  380.37 + * Unlike sets, lists typically allow duplicate elements.  More formally,
  380.38 + * lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt>
  380.39 + * such that <tt>e1.equals(e2)</tt>, and they typically allow multiple
  380.40 + * null elements if they allow null elements at all.  It is not inconceivable
  380.41 + * that someone might wish to implement a list that prohibits duplicates, by
  380.42 + * throwing runtime exceptions when the user attempts to insert them, but we
  380.43 + * expect this usage to be rare.<p>
  380.44 + *
  380.45 + * The <tt>List</tt> interface places additional stipulations, beyond those
  380.46 + * specified in the <tt>Collection</tt> interface, on the contracts of the
  380.47 + * <tt>iterator</tt>, <tt>add</tt>, <tt>remove</tt>, <tt>equals</tt>, and
  380.48 + * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
  380.49 + * also included here for convenience.<p>
  380.50 + *
  380.51 + * The <tt>List</tt> interface provides four methods for positional (indexed)
  380.52 + * access to list elements.  Lists (like Java arrays) are zero based.  Note
  380.53 + * that these operations may execute in time proportional to the index value
  380.54 + * for some implementations (the <tt>LinkedList</tt> class, for
  380.55 + * example). Thus, iterating over the elements in a list is typically
  380.56 + * preferable to indexing through it if the caller does not know the
  380.57 + * implementation.<p>
  380.58 + *
  380.59 + * The <tt>List</tt> interface provides a special iterator, called a
  380.60 + * <tt>ListIterator</tt>, that allows element insertion and replacement, and
  380.61 + * bidirectional access in addition to the normal operations that the
  380.62 + * <tt>Iterator</tt> interface provides.  A method is provided to obtain a
  380.63 + * list iterator that starts at a specified position in the list.<p>
  380.64 + *
  380.65 + * The <tt>List</tt> interface provides two methods to search for a specified
  380.66 + * object.  From a performance standpoint, these methods should be used with
  380.67 + * caution.  In many implementations they will perform costly linear
  380.68 + * searches.<p>
  380.69 + *
  380.70 + * The <tt>List</tt> interface provides two methods to efficiently insert and
  380.71 + * remove multiple elements at an arbitrary point in the list.<p>
  380.72 + *
  380.73 + * Note: While it is permissible for lists to contain themselves as elements,
  380.74 + * extreme caution is advised: the <tt>equals</tt> and <tt>hashCode</tt>
  380.75 + * methods are no longer well defined on such a list.
  380.76 + *
  380.77 + * <p>Some list implementations have restrictions on the elements that
  380.78 + * they may contain.  For example, some implementations prohibit null elements,
  380.79 + * and some have restrictions on the types of their elements.  Attempting to
  380.80 + * add an ineligible element throws an unchecked exception, typically
  380.81 + * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
  380.82 + * to query the presence of an ineligible element may throw an exception,
  380.83 + * or it may simply return false; some implementations will exhibit the former
  380.84 + * behavior and some will exhibit the latter.  More generally, attempting an
  380.85 + * operation on an ineligible element whose completion would not result in
  380.86 + * the insertion of an ineligible element into the list may throw an
  380.87 + * exception or it may succeed, at the option of the implementation.
  380.88 + * Such exceptions are marked as "optional" in the specification for this
  380.89 + * interface.
  380.90 + *
  380.91 + * <p>This interface is a member of the
  380.92 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  380.93 + * Java Collections Framework</a>.
  380.94 + *
  380.95 + * @param <E> the type of elements in this list
  380.96 + *
  380.97 + * @author  Josh Bloch
  380.98 + * @author  Neal Gafter
  380.99 + * @see Collection
 380.100 + * @see Set
 380.101 + * @see ArrayList
 380.102 + * @see LinkedList
 380.103 + * @see Vector
 380.104 + * @see Arrays#asList(Object[])
 380.105 + * @see Collections#nCopies(int, Object)
 380.106 + * @see Collections#EMPTY_LIST
 380.107 + * @see AbstractList
 380.108 + * @see AbstractSequentialList
 380.109 + * @since 1.2
 380.110 + */
 380.111 +
 380.112 +public interface List<E> extends Collection<E> {
 380.113 +    // Query Operations
 380.114 +
 380.115 +    /**
 380.116 +     * Returns the number of elements in this list.  If this list contains
 380.117 +     * more than <tt>Integer.MAX_VALUE</tt> elements, returns
 380.118 +     * <tt>Integer.MAX_VALUE</tt>.
 380.119 +     *
 380.120 +     * @return the number of elements in this list
 380.121 +     */
 380.122 +    int size();
 380.123 +
 380.124 +    /**
 380.125 +     * Returns <tt>true</tt> if this list contains no elements.
 380.126 +     *
 380.127 +     * @return <tt>true</tt> if this list contains no elements
 380.128 +     */
 380.129 +    boolean isEmpty();
 380.130 +
 380.131 +    /**
 380.132 +     * Returns <tt>true</tt> if this list contains the specified element.
 380.133 +     * More formally, returns <tt>true</tt> if and only if this list contains
 380.134 +     * at least one element <tt>e</tt> such that
 380.135 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 380.136 +     *
 380.137 +     * @param o element whose presence in this list is to be tested
 380.138 +     * @return <tt>true</tt> if this list contains the specified element
 380.139 +     * @throws ClassCastException if the type of the specified element
 380.140 +     *         is incompatible with this list
 380.141 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.142 +     * @throws NullPointerException if the specified element is null and this
 380.143 +     *         list does not permit null elements
 380.144 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.145 +     */
 380.146 +    boolean contains(Object o);
 380.147 +
 380.148 +    /**
 380.149 +     * Returns an iterator over the elements in this list in proper sequence.
 380.150 +     *
 380.151 +     * @return an iterator over the elements in this list in proper sequence
 380.152 +     */
 380.153 +    Iterator<E> iterator();
 380.154 +
 380.155 +    /**
 380.156 +     * Returns an array containing all of the elements in this list in proper
 380.157 +     * sequence (from first to last element).
 380.158 +     *
 380.159 +     * <p>The returned array will be "safe" in that no references to it are
 380.160 +     * maintained by this list.  (In other words, this method must
 380.161 +     * allocate a new array even if this list is backed by an array).
 380.162 +     * The caller is thus free to modify the returned array.
 380.163 +     *
 380.164 +     * <p>This method acts as bridge between array-based and collection-based
 380.165 +     * APIs.
 380.166 +     *
 380.167 +     * @return an array containing all of the elements in this list in proper
 380.168 +     *         sequence
 380.169 +     * @see Arrays#asList(Object[])
 380.170 +     */
 380.171 +    Object[] toArray();
 380.172 +
 380.173 +    /**
 380.174 +     * Returns an array containing all of the elements in this list in
 380.175 +     * proper sequence (from first to last element); the runtime type of
 380.176 +     * the returned array is that of the specified array.  If the list fits
 380.177 +     * in the specified array, it is returned therein.  Otherwise, a new
 380.178 +     * array is allocated with the runtime type of the specified array and
 380.179 +     * the size of this list.
 380.180 +     *
 380.181 +     * <p>If the list fits in the specified array with room to spare (i.e.,
 380.182 +     * the array has more elements than the list), the element in the array
 380.183 +     * immediately following the end of the list is set to <tt>null</tt>.
 380.184 +     * (This is useful in determining the length of the list <i>only</i> if
 380.185 +     * the caller knows that the list does not contain any null elements.)
 380.186 +     *
 380.187 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 380.188 +     * array-based and collection-based APIs.  Further, this method allows
 380.189 +     * precise control over the runtime type of the output array, and may,
 380.190 +     * under certain circumstances, be used to save allocation costs.
 380.191 +     *
 380.192 +     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
 380.193 +     * The following code can be used to dump the list into a newly
 380.194 +     * allocated array of <tt>String</tt>:
 380.195 +     *
 380.196 +     * <pre>
 380.197 +     *     String[] y = x.toArray(new String[0]);</pre>
 380.198 +     *
 380.199 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
 380.200 +     * <tt>toArray()</tt>.
 380.201 +     *
 380.202 +     * @param a the array into which the elements of this list are to
 380.203 +     *          be stored, if it is big enough; otherwise, a new array of the
 380.204 +     *          same runtime type is allocated for this purpose.
 380.205 +     * @return an array containing the elements of this list
 380.206 +     * @throws ArrayStoreException if the runtime type of the specified array
 380.207 +     *         is not a supertype of the runtime type of every element in
 380.208 +     *         this list
 380.209 +     * @throws NullPointerException if the specified array is null
 380.210 +     */
 380.211 +    <T> T[] toArray(T[] a);
 380.212 +
 380.213 +
 380.214 +    // Modification Operations
 380.215 +
 380.216 +    /**
 380.217 +     * Appends the specified element to the end of this list (optional
 380.218 +     * operation).
 380.219 +     *
 380.220 +     * <p>Lists that support this operation may place limitations on what
 380.221 +     * elements may be added to this list.  In particular, some
 380.222 +     * lists will refuse to add null elements, and others will impose
 380.223 +     * restrictions on the type of elements that may be added.  List
 380.224 +     * classes should clearly specify in their documentation any restrictions
 380.225 +     * on what elements may be added.
 380.226 +     *
 380.227 +     * @param e element to be appended to this list
 380.228 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
 380.229 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
 380.230 +     *         is not supported by this list
 380.231 +     * @throws ClassCastException if the class of the specified element
 380.232 +     *         prevents it from being added to this list
 380.233 +     * @throws NullPointerException if the specified element is null and this
 380.234 +     *         list does not permit null elements
 380.235 +     * @throws IllegalArgumentException if some property of this element
 380.236 +     *         prevents it from being added to this list
 380.237 +     */
 380.238 +    boolean add(E e);
 380.239 +
 380.240 +    /**
 380.241 +     * Removes the first occurrence of the specified element from this list,
 380.242 +     * if it is present (optional operation).  If this list does not contain
 380.243 +     * the element, it is unchanged.  More formally, removes the element with
 380.244 +     * the lowest index <tt>i</tt> such that
 380.245 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
 380.246 +     * (if such an element exists).  Returns <tt>true</tt> if this list
 380.247 +     * contained the specified element (or equivalently, if this list changed
 380.248 +     * as a result of the call).
 380.249 +     *
 380.250 +     * @param o element to be removed from this list, if present
 380.251 +     * @return <tt>true</tt> if this list contained the specified element
 380.252 +     * @throws ClassCastException if the type of the specified element
 380.253 +     *         is incompatible with this list
 380.254 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.255 +     * @throws NullPointerException if the specified element is null and this
 380.256 +     *         list does not permit null elements
 380.257 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.258 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 380.259 +     *         is not supported by this list
 380.260 +     */
 380.261 +    boolean remove(Object o);
 380.262 +
 380.263 +
 380.264 +    // Bulk Modification Operations
 380.265 +
 380.266 +    /**
 380.267 +     * Returns <tt>true</tt> if this list contains all of the elements of the
 380.268 +     * specified collection.
 380.269 +     *
 380.270 +     * @param  c collection to be checked for containment in this list
 380.271 +     * @return <tt>true</tt> if this list contains all of the elements of the
 380.272 +     *         specified collection
 380.273 +     * @throws ClassCastException if the types of one or more elements
 380.274 +     *         in the specified collection are incompatible with this
 380.275 +     *         list
 380.276 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.277 +     * @throws NullPointerException if the specified collection contains one
 380.278 +     *         or more null elements and this list does not permit null
 380.279 +     *         elements
 380.280 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 380.281 +     *         or if the specified collection is null
 380.282 +     * @see #contains(Object)
 380.283 +     */
 380.284 +    boolean containsAll(Collection<?> c);
 380.285 +
 380.286 +    /**
 380.287 +     * Appends all of the elements in the specified collection to the end of
 380.288 +     * this list, in the order that they are returned by the specified
 380.289 +     * collection's iterator (optional operation).  The behavior of this
 380.290 +     * operation is undefined if the specified collection is modified while
 380.291 +     * the operation is in progress.  (Note that this will occur if the
 380.292 +     * specified collection is this list, and it's nonempty.)
 380.293 +     *
 380.294 +     * @param c collection containing elements to be added to this list
 380.295 +     * @return <tt>true</tt> if this list changed as a result of the call
 380.296 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 380.297 +     *         is not supported by this list
 380.298 +     * @throws ClassCastException if the class of an element of the specified
 380.299 +     *         collection prevents it from being added to this list
 380.300 +     * @throws NullPointerException if the specified collection contains one
 380.301 +     *         or more null elements and this list does not permit null
 380.302 +     *         elements, or if the specified collection is null
 380.303 +     * @throws IllegalArgumentException if some property of an element of the
 380.304 +     *         specified collection prevents it from being added to this list
 380.305 +     * @see #add(Object)
 380.306 +     */
 380.307 +    boolean addAll(Collection<? extends E> c);
 380.308 +
 380.309 +    /**
 380.310 +     * Inserts all of the elements in the specified collection into this
 380.311 +     * list at the specified position (optional operation).  Shifts the
 380.312 +     * element currently at that position (if any) and any subsequent
 380.313 +     * elements to the right (increases their indices).  The new elements
 380.314 +     * will appear in this list in the order that they are returned by the
 380.315 +     * specified collection's iterator.  The behavior of this operation is
 380.316 +     * undefined if the specified collection is modified while the
 380.317 +     * operation is in progress.  (Note that this will occur if the specified
 380.318 +     * collection is this list, and it's nonempty.)
 380.319 +     *
 380.320 +     * @param index index at which to insert the first element from the
 380.321 +     *              specified collection
 380.322 +     * @param c collection containing elements to be added to this list
 380.323 +     * @return <tt>true</tt> if this list changed as a result of the call
 380.324 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 380.325 +     *         is not supported by this list
 380.326 +     * @throws ClassCastException if the class of an element of the specified
 380.327 +     *         collection prevents it from being added to this list
 380.328 +     * @throws NullPointerException if the specified collection contains one
 380.329 +     *         or more null elements and this list does not permit null
 380.330 +     *         elements, or if the specified collection is null
 380.331 +     * @throws IllegalArgumentException if some property of an element of the
 380.332 +     *         specified collection prevents it from being added to this list
 380.333 +     * @throws IndexOutOfBoundsException if the index is out of range
 380.334 +     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
 380.335 +     */
 380.336 +    boolean addAll(int index, Collection<? extends E> c);
 380.337 +
 380.338 +    /**
 380.339 +     * Removes from this list all of its elements that are contained in the
 380.340 +     * specified collection (optional operation).
 380.341 +     *
 380.342 +     * @param c collection containing elements to be removed from this list
 380.343 +     * @return <tt>true</tt> if this list changed as a result of the call
 380.344 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 380.345 +     *         is not supported by this list
 380.346 +     * @throws ClassCastException if the class of an element of this list
 380.347 +     *         is incompatible with the specified collection
 380.348 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.349 +     * @throws NullPointerException if this list contains a null element and the
 380.350 +     *         specified collection does not permit null elements
 380.351 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 380.352 +     *         or if the specified collection is null
 380.353 +     * @see #remove(Object)
 380.354 +     * @see #contains(Object)
 380.355 +     */
 380.356 +    boolean removeAll(Collection<?> c);
 380.357 +
 380.358 +    /**
 380.359 +     * Retains only the elements in this list that are contained in the
 380.360 +     * specified collection (optional operation).  In other words, removes
 380.361 +     * from this list all of its elements that are not contained in the
 380.362 +     * specified collection.
 380.363 +     *
 380.364 +     * @param c collection containing elements to be retained in this list
 380.365 +     * @return <tt>true</tt> if this list changed as a result of the call
 380.366 +     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 380.367 +     *         is not supported by this list
 380.368 +     * @throws ClassCastException if the class of an element of this list
 380.369 +     *         is incompatible with the specified collection
 380.370 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 380.371 +     * @throws NullPointerException if this list contains a null element and the
 380.372 +     *         specified collection does not permit null elements
 380.373 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 380.374 +     *         or if the specified collection is null
 380.375 +     * @see #remove(Object)
 380.376 +     * @see #contains(Object)
 380.377 +     */
 380.378 +    boolean retainAll(Collection<?> c);
 380.379 +
 380.380 +    /**
 380.381 +     * Removes all of the elements from this list (optional operation).
 380.382 +     * The list will be empty after this call returns.
 380.383 +     *
 380.384 +     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
 380.385 +     *         is not supported by this list
 380.386 +     */
 380.387 +    void clear();
 380.388 +
 380.389 +
 380.390 +    // Comparison and hashing
 380.391 +
 380.392 +    /**
 380.393 +     * Compares the specified object with this list for equality.  Returns
 380.394 +     * <tt>true</tt> if and only if the specified object is also a list, both
 380.395 +     * lists have the same size, and all corresponding pairs of elements in
 380.396 +     * the two lists are <i>equal</i>.  (Two elements <tt>e1</tt> and
 380.397 +     * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
 380.398 +     * e1.equals(e2))</tt>.)  In other words, two lists are defined to be
 380.399 +     * equal if they contain the same elements in the same order.  This
 380.400 +     * definition ensures that the equals method works properly across
 380.401 +     * different implementations of the <tt>List</tt> interface.
 380.402 +     *
 380.403 +     * @param o the object to be compared for equality with this list
 380.404 +     * @return <tt>true</tt> if the specified object is equal to this list
 380.405 +     */
 380.406 +    boolean equals(Object o);
 380.407 +
 380.408 +    /**
 380.409 +     * Returns the hash code value for this list.  The hash code of a list
 380.410 +     * is defined to be the result of the following calculation:
 380.411 +     * <pre>
 380.412 +     *  int hashCode = 1;
 380.413 +     *  for (E e : list)
 380.414 +     *      hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
 380.415 +     * </pre>
 380.416 +     * This ensures that <tt>list1.equals(list2)</tt> implies that
 380.417 +     * <tt>list1.hashCode()==list2.hashCode()</tt> for any two lists,
 380.418 +     * <tt>list1</tt> and <tt>list2</tt>, as required by the general
 380.419 +     * contract of {@link Object#hashCode}.
 380.420 +     *
 380.421 +     * @return the hash code value for this list
 380.422 +     * @see Object#equals(Object)
 380.423 +     * @see #equals(Object)
 380.424 +     */
 380.425 +    int hashCode();
 380.426 +
 380.427 +
 380.428 +    // Positional Access Operations
 380.429 +
 380.430 +    /**
 380.431 +     * Returns the element at the specified position in this list.
 380.432 +     *
 380.433 +     * @param index index of the element to return
 380.434 +     * @return the element at the specified position in this list
 380.435 +     * @throws IndexOutOfBoundsException if the index is out of range
 380.436 +     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
 380.437 +     */
 380.438 +    E get(int index);
 380.439 +
 380.440 +    /**
 380.441 +     * Replaces the element at the specified position in this list with the
 380.442 +     * specified element (optional operation).
 380.443 +     *
 380.444 +     * @param index index of the element to replace
 380.445 +     * @param element element to be stored at the specified position
 380.446 +     * @return the element previously at the specified position
 380.447 +     * @throws UnsupportedOperationException if the <tt>set</tt> operation
 380.448 +     *         is not supported by this list
 380.449 +     * @throws ClassCastException if the class of the specified element
 380.450 +     *         prevents it from being added to this list
 380.451 +     * @throws NullPointerException if the specified element is null and
 380.452 +     *         this list does not permit null elements
 380.453 +     * @throws IllegalArgumentException if some property of the specified
 380.454 +     *         element prevents it from being added to this list
 380.455 +     * @throws IndexOutOfBoundsException if the index is out of range
 380.456 +     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
 380.457 +     */
 380.458 +    E set(int index, E element);
 380.459 +
 380.460 +    /**
 380.461 +     * Inserts the specified element at the specified position in this list
 380.462 +     * (optional operation).  Shifts the element currently at that position
 380.463 +     * (if any) and any subsequent elements to the right (adds one to their
 380.464 +     * indices).
 380.465 +     *
 380.466 +     * @param index index at which the specified element is to be inserted
 380.467 +     * @param element element to be inserted
 380.468 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
 380.469 +     *         is not supported by this list
 380.470 +     * @throws ClassCastException if the class of the specified element
 380.471 +     *         prevents it from being added to this list
 380.472 +     * @throws NullPointerException if the specified element is null and
 380.473 +     *         this list does not permit null elements
 380.474 +     * @throws IllegalArgumentException if some property of the specified
 380.475 +     *         element prevents it from being added to this list
 380.476 +     * @throws IndexOutOfBoundsException if the index is out of range
 380.477 +     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
 380.478 +     */
 380.479 +    void add(int index, E element);
 380.480 +
 380.481 +    /**
 380.482 +     * Removes the element at the specified position in this list (optional
 380.483 +     * operation).  Shifts any subsequent elements to the left (subtracts one
 380.484 +     * from their indices).  Returns the element that was removed from the
 380.485 +     * list.
 380.486 +     *
 380.487 +     * @param index the index of the element to be removed
 380.488 +     * @return the element previously at the specified position
 380.489 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 380.490 +     *         is not supported by this list
 380.491 +     * @throws IndexOutOfBoundsException if the index is out of range
 380.492 +     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
 380.493 +     */
 380.494 +    E remove(int index);
 380.495 +
 380.496 +
 380.497 +    // Search Operations
 380.498 +
 380.499 +    /**
 380.500 +     * Returns the index of the first occurrence of the specified element
 380.501 +     * in this list, or -1 if this list does not contain the element.
 380.502 +     * More formally, returns the lowest index <tt>i</tt> such that
 380.503 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 380.504 +     * or -1 if there is no such index.
 380.505 +     *
 380.506 +     * @param o element to search for
 380.507 +     * @return the index of the first occurrence of the specified element in
 380.508 +     *         this list, or -1 if this list does not contain the element
 380.509 +     * @throws ClassCastException if the type of the specified element
 380.510 +     *         is incompatible with this list
 380.511 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
 380.512 +     * @throws NullPointerException if the specified element is null and this
 380.513 +     *         list does not permit null elements
 380.514 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
 380.515 +     */
 380.516 +    int indexOf(Object o);
 380.517 +
 380.518 +    /**
 380.519 +     * Returns the index of the last occurrence of the specified element
 380.520 +     * in this list, or -1 if this list does not contain the element.
 380.521 +     * More formally, returns the highest index <tt>i</tt> such that
 380.522 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 380.523 +     * or -1 if there is no such index.
 380.524 +     *
 380.525 +     * @param o element to search for
 380.526 +     * @return the index of the last occurrence of the specified element in
 380.527 +     *         this list, or -1 if this list does not contain the element
 380.528 +     * @throws ClassCastException if the type of the specified element
 380.529 +     *         is incompatible with this list
 380.530 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
 380.531 +     * @throws NullPointerException if the specified element is null and this
 380.532 +     *         list does not permit null elements
 380.533 +     *         (<a href="Collection.html#optional-restrictions">optional</a>)
 380.534 +     */
 380.535 +    int lastIndexOf(Object o);
 380.536 +
 380.537 +
 380.538 +    // List Iterators
 380.539 +
 380.540 +    /**
 380.541 +     * Returns a list iterator over the elements in this list (in proper
 380.542 +     * sequence).
 380.543 +     *
 380.544 +     * @return a list iterator over the elements in this list (in proper
 380.545 +     *         sequence)
 380.546 +     */
 380.547 +    ListIterator<E> listIterator();
 380.548 +
 380.549 +    /**
 380.550 +     * Returns a list iterator over the elements in this list (in proper
 380.551 +     * sequence), starting at the specified position in the list.
 380.552 +     * The specified index indicates the first element that would be
 380.553 +     * returned by an initial call to {@link ListIterator#next next}.
 380.554 +     * An initial call to {@link ListIterator#previous previous} would
 380.555 +     * return the element with the specified index minus one.
 380.556 +     *
 380.557 +     * @param index index of the first element to be returned from the
 380.558 +     *        list iterator (by a call to {@link ListIterator#next next})
 380.559 +     * @return a list iterator over the elements in this list (in proper
 380.560 +     *         sequence), starting at the specified position in the list
 380.561 +     * @throws IndexOutOfBoundsException if the index is out of range
 380.562 +     *         ({@code index < 0 || index > size()})
 380.563 +     */
 380.564 +    ListIterator<E> listIterator(int index);
 380.565 +
 380.566 +    // View
 380.567 +
 380.568 +    /**
 380.569 +     * Returns a view of the portion of this list between the specified
 380.570 +     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.  (If
 380.571 +     * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is
 380.572 +     * empty.)  The returned list is backed by this list, so non-structural
 380.573 +     * changes in the returned list are reflected in this list, and vice-versa.
 380.574 +     * The returned list supports all of the optional list operations supported
 380.575 +     * by this list.<p>
 380.576 +     *
 380.577 +     * This method eliminates the need for explicit range operations (of
 380.578 +     * the sort that commonly exist for arrays).  Any operation that expects
 380.579 +     * a list can be used as a range operation by passing a subList view
 380.580 +     * instead of a whole list.  For example, the following idiom
 380.581 +     * removes a range of elements from a list:
 380.582 +     * <pre>
 380.583 +     *      list.subList(from, to).clear();
 380.584 +     * </pre>
 380.585 +     * Similar idioms may be constructed for <tt>indexOf</tt> and
 380.586 +     * <tt>lastIndexOf</tt>, and all of the algorithms in the
 380.587 +     * <tt>Collections</tt> class can be applied to a subList.<p>
 380.588 +     *
 380.589 +     * The semantics of the list returned by this method become undefined if
 380.590 +     * the backing list (i.e., this list) is <i>structurally modified</i> in
 380.591 +     * any way other than via the returned list.  (Structural modifications are
 380.592 +     * those that change the size of this list, or otherwise perturb it in such
 380.593 +     * a fashion that iterations in progress may yield incorrect results.)
 380.594 +     *
 380.595 +     * @param fromIndex low endpoint (inclusive) of the subList
 380.596 +     * @param toIndex high endpoint (exclusive) of the subList
 380.597 +     * @return a view of the specified range within this list
 380.598 +     * @throws IndexOutOfBoundsException for an illegal endpoint index value
 380.599 +     *         (<tt>fromIndex &lt; 0 || toIndex &gt; size ||
 380.600 +     *         fromIndex &gt; toIndex</tt>)
 380.601 +     */
 380.602 +    List<E> subList(int fromIndex, int toIndex);
 380.603 +}
   381.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   381.2 +++ b/rt/emul/compact/src/main/java/java/util/ListIterator.java	Wed Feb 27 11:24:58 2013 +0100
   381.3 @@ -0,0 +1,195 @@
   381.4 +/*
   381.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
   381.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   381.7 + *
   381.8 + * This code is free software; you can redistribute it and/or modify it
   381.9 + * under the terms of the GNU General Public License version 2 only, as
  381.10 + * published by the Free Software Foundation.  Oracle designates this
  381.11 + * particular file as subject to the "Classpath" exception as provided
  381.12 + * by Oracle in the LICENSE file that accompanied this code.
  381.13 + *
  381.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  381.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  381.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  381.17 + * version 2 for more details (a copy is included in the LICENSE file that
  381.18 + * accompanied this code).
  381.19 + *
  381.20 + * You should have received a copy of the GNU General Public License version
  381.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  381.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  381.23 + *
  381.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  381.25 + * or visit www.oracle.com if you need additional information or have any
  381.26 + * questions.
  381.27 + */
  381.28 +
  381.29 +package java.util;
  381.30 +
  381.31 +/**
  381.32 + * An iterator for lists that allows the programmer
  381.33 + * to traverse the list in either direction, modify
  381.34 + * the list during iteration, and obtain the iterator's
  381.35 + * current position in the list. A {@code ListIterator}
  381.36 + * has no current element; its <I>cursor position</I> always
  381.37 + * lies between the element that would be returned by a call
  381.38 + * to {@code previous()} and the element that would be
  381.39 + * returned by a call to {@code next()}.
  381.40 + * An iterator for a list of length {@code n} has {@code n+1} possible
  381.41 + * cursor positions, as illustrated by the carets ({@code ^}) below:
  381.42 + * <PRE>
  381.43 + *                      Element(0)   Element(1)   Element(2)   ... Element(n-1)
  381.44 + * cursor positions:  ^            ^            ^            ^                  ^
  381.45 + * </PRE>
  381.46 + * Note that the {@link #remove} and {@link #set(Object)} methods are
  381.47 + * <i>not</i> defined in terms of the cursor position;  they are defined to
  381.48 + * operate on the last element returned by a call to {@link #next} or
  381.49 + * {@link #previous()}.
  381.50 + *
  381.51 + * <p>This interface is a member of the
  381.52 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  381.53 + * Java Collections Framework</a>.
  381.54 + *
  381.55 + * @author  Josh Bloch
  381.56 + * @see Collection
  381.57 + * @see List
  381.58 + * @see Iterator
  381.59 + * @see Enumeration
  381.60 + * @see List#listIterator()
  381.61 + * @since   1.2
  381.62 + */
  381.63 +public interface ListIterator<E> extends Iterator<E> {
  381.64 +    // Query Operations
  381.65 +
  381.66 +    /**
  381.67 +     * Returns {@code true} if this list iterator has more elements when
  381.68 +     * traversing the list in the forward direction. (In other words,
  381.69 +     * returns {@code true} if {@link #next} would return an element rather
  381.70 +     * than throwing an exception.)
  381.71 +     *
  381.72 +     * @return {@code true} if the list iterator has more elements when
  381.73 +     *         traversing the list in the forward direction
  381.74 +     */
  381.75 +    boolean hasNext();
  381.76 +
  381.77 +    /**
  381.78 +     * Returns the next element in the list and advances the cursor position.
  381.79 +     * This method may be called repeatedly to iterate through the list,
  381.80 +     * or intermixed with calls to {@link #previous} to go back and forth.
  381.81 +     * (Note that alternating calls to {@code next} and {@code previous}
  381.82 +     * will return the same element repeatedly.)
  381.83 +     *
  381.84 +     * @return the next element in the list
  381.85 +     * @throws NoSuchElementException if the iteration has no next element
  381.86 +     */
  381.87 +    E next();
  381.88 +
  381.89 +    /**
  381.90 +     * Returns {@code true} if this list iterator has more elements when
  381.91 +     * traversing the list in the reverse direction.  (In other words,
  381.92 +     * returns {@code true} if {@link #previous} would return an element
  381.93 +     * rather than throwing an exception.)
  381.94 +     *
  381.95 +     * @return {@code true} if the list iterator has more elements when
  381.96 +     *         traversing the list in the reverse direction
  381.97 +     */
  381.98 +    boolean hasPrevious();
  381.99 +
 381.100 +    /**
 381.101 +     * Returns the previous element in the list and moves the cursor
 381.102 +     * position backwards.  This method may be called repeatedly to
 381.103 +     * iterate through the list backwards, or intermixed with calls to
 381.104 +     * {@link #next} to go back and forth.  (Note that alternating calls
 381.105 +     * to {@code next} and {@code previous} will return the same
 381.106 +     * element repeatedly.)
 381.107 +     *
 381.108 +     * @return the previous element in the list
 381.109 +     * @throws NoSuchElementException if the iteration has no previous
 381.110 +     *         element
 381.111 +     */
 381.112 +    E previous();
 381.113 +
 381.114 +    /**
 381.115 +     * Returns the index of the element that would be returned by a
 381.116 +     * subsequent call to {@link #next}. (Returns list size if the list
 381.117 +     * iterator is at the end of the list.)
 381.118 +     *
 381.119 +     * @return the index of the element that would be returned by a
 381.120 +     *         subsequent call to {@code next}, or list size if the list
 381.121 +     *         iterator is at the end of the list
 381.122 +     */
 381.123 +    int nextIndex();
 381.124 +
 381.125 +    /**
 381.126 +     * Returns the index of the element that would be returned by a
 381.127 +     * subsequent call to {@link #previous}. (Returns -1 if the list
 381.128 +     * iterator is at the beginning of the list.)
 381.129 +     *
 381.130 +     * @return the index of the element that would be returned by a
 381.131 +     *         subsequent call to {@code previous}, or -1 if the list
 381.132 +     *         iterator is at the beginning of the list
 381.133 +     */
 381.134 +    int previousIndex();
 381.135 +
 381.136 +
 381.137 +    // Modification Operations
 381.138 +
 381.139 +    /**
 381.140 +     * Removes from the list the last element that was returned by {@link
 381.141 +     * #next} or {@link #previous} (optional operation).  This call can
 381.142 +     * only be made once per call to {@code next} or {@code previous}.
 381.143 +     * It can be made only if {@link #add} has not been
 381.144 +     * called after the last call to {@code next} or {@code previous}.
 381.145 +     *
 381.146 +     * @throws UnsupportedOperationException if the {@code remove}
 381.147 +     *         operation is not supported by this list iterator
 381.148 +     * @throws IllegalStateException if neither {@code next} nor
 381.149 +     *         {@code previous} have been called, or {@code remove} or
 381.150 +     *         {@code add} have been called after the last call to
 381.151 +     *         {@code next} or {@code previous}
 381.152 +     */
 381.153 +    void remove();
 381.154 +
 381.155 +    /**
 381.156 +     * Replaces the last element returned by {@link #next} or
 381.157 +     * {@link #previous} with the specified element (optional operation).
 381.158 +     * This call can be made only if neither {@link #remove} nor {@link
 381.159 +     * #add} have been called after the last call to {@code next} or
 381.160 +     * {@code previous}.
 381.161 +     *
 381.162 +     * @param e the element with which to replace the last element returned by
 381.163 +     *          {@code next} or {@code previous}
 381.164 +     * @throws UnsupportedOperationException if the {@code set} operation
 381.165 +     *         is not supported by this list iterator
 381.166 +     * @throws ClassCastException if the class of the specified element
 381.167 +     *         prevents it from being added to this list
 381.168 +     * @throws IllegalArgumentException if some aspect of the specified
 381.169 +     *         element prevents it from being added to this list
 381.170 +     * @throws IllegalStateException if neither {@code next} nor
 381.171 +     *         {@code previous} have been called, or {@code remove} or
 381.172 +     *         {@code add} have been called after the last call to
 381.173 +     *         {@code next} or {@code previous}
 381.174 +     */
 381.175 +    void set(E e);
 381.176 +
 381.177 +    /**
 381.178 +     * Inserts the specified element into the list (optional operation).
 381.179 +     * The element is inserted immediately before the element that
 381.180 +     * would be returned by {@link #next}, if any, and after the element
 381.181 +     * that would be returned by {@link #previous}, if any.  (If the
 381.182 +     * list contains no elements, the new element becomes the sole element
 381.183 +     * on the list.)  The new element is inserted before the implicit
 381.184 +     * cursor: a subsequent call to {@code next} would be unaffected, and a
 381.185 +     * subsequent call to {@code previous} would return the new element.
 381.186 +     * (This call increases by one the value that would be returned by a
 381.187 +     * call to {@code nextIndex} or {@code previousIndex}.)
 381.188 +     *
 381.189 +     * @param e the element to insert
 381.190 +     * @throws UnsupportedOperationException if the {@code add} method is
 381.191 +     *         not supported by this list iterator
 381.192 +     * @throws ClassCastException if the class of the specified element
 381.193 +     *         prevents it from being added to this list
 381.194 +     * @throws IllegalArgumentException if some aspect of this element
 381.195 +     *         prevents it from being added to this list
 381.196 +     */
 381.197 +    void add(E e);
 381.198 +}
   382.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   382.2 +++ b/rt/emul/compact/src/main/java/java/util/Map.java	Wed Feb 27 11:24:58 2013 +0100
   382.3 @@ -0,0 +1,478 @@
   382.4 +/*
   382.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   382.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   382.7 + *
   382.8 + * This code is free software; you can redistribute it and/or modify it
   382.9 + * under the terms of the GNU General Public License version 2 only, as
  382.10 + * published by the Free Software Foundation.  Oracle designates this
  382.11 + * particular file as subject to the "Classpath" exception as provided
  382.12 + * by Oracle in the LICENSE file that accompanied this code.
  382.13 + *
  382.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  382.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  382.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  382.17 + * version 2 for more details (a copy is included in the LICENSE file that
  382.18 + * accompanied this code).
  382.19 + *
  382.20 + * You should have received a copy of the GNU General Public License version
  382.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  382.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  382.23 + *
  382.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  382.25 + * or visit www.oracle.com if you need additional information or have any
  382.26 + * questions.
  382.27 + */
  382.28 +
  382.29 +package java.util;
  382.30 +
  382.31 +/**
  382.32 + * An object that maps keys to values.  A map cannot contain duplicate keys;
  382.33 + * each key can map to at most one value.
  382.34 + *
  382.35 + * <p>This interface takes the place of the <tt>Dictionary</tt> class, which
  382.36 + * was a totally abstract class rather than an interface.
  382.37 + *
  382.38 + * <p>The <tt>Map</tt> interface provides three <i>collection views</i>, which
  382.39 + * allow a map's contents to be viewed as a set of keys, collection of values,
  382.40 + * or set of key-value mappings.  The <i>order</i> of a map is defined as
  382.41 + * the order in which the iterators on the map's collection views return their
  382.42 + * elements.  Some map implementations, like the <tt>TreeMap</tt> class, make
  382.43 + * specific guarantees as to their order; others, like the <tt>HashMap</tt>
  382.44 + * class, do not.
  382.45 + *
  382.46 + * <p>Note: great care must be exercised if mutable objects are used as map
  382.47 + * keys.  The behavior of a map is not specified if the value of an object is
  382.48 + * changed in a manner that affects <tt>equals</tt> comparisons while the
  382.49 + * object is a key in the map.  A special case of this prohibition is that it
  382.50 + * is not permissible for a map to contain itself as a key.  While it is
  382.51 + * permissible for a map to contain itself as a value, extreme caution is
  382.52 + * advised: the <tt>equals</tt> and <tt>hashCode</tt> methods are no longer
  382.53 + * well defined on such a map.
  382.54 + *
  382.55 + * <p>All general-purpose map implementation classes should provide two
  382.56 + * "standard" constructors: a void (no arguments) constructor which creates an
  382.57 + * empty map, and a constructor with a single argument of type <tt>Map</tt>,
  382.58 + * which creates a new map with the same key-value mappings as its argument.
  382.59 + * In effect, the latter constructor allows the user to copy any map,
  382.60 + * producing an equivalent map of the desired class.  There is no way to
  382.61 + * enforce this recommendation (as interfaces cannot contain constructors) but
  382.62 + * all of the general-purpose map implementations in the JDK comply.
  382.63 + *
  382.64 + * <p>The "destructive" methods contained in this interface, that is, the
  382.65 + * methods that modify the map on which they operate, are specified to throw
  382.66 + * <tt>UnsupportedOperationException</tt> if this map does not support the
  382.67 + * operation.  If this is the case, these methods may, but are not required
  382.68 + * to, throw an <tt>UnsupportedOperationException</tt> if the invocation would
  382.69 + * have no effect on the map.  For example, invoking the {@link #putAll(Map)}
  382.70 + * method on an unmodifiable map may, but is not required to, throw the
  382.71 + * exception if the map whose mappings are to be "superimposed" is empty.
  382.72 + *
  382.73 + * <p>Some map implementations have restrictions on the keys and values they
  382.74 + * may contain.  For example, some implementations prohibit null keys and
  382.75 + * values, and some have restrictions on the types of their keys.  Attempting
  382.76 + * to insert an ineligible key or value throws an unchecked exception,
  382.77 + * typically <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.
  382.78 + * Attempting to query the presence of an ineligible key or value may throw an
  382.79 + * exception, or it may simply return false; some implementations will exhibit
  382.80 + * the former behavior and some will exhibit the latter.  More generally,
  382.81 + * attempting an operation on an ineligible key or value whose completion
  382.82 + * would not result in the insertion of an ineligible element into the map may
  382.83 + * throw an exception or it may succeed, at the option of the implementation.
  382.84 + * Such exceptions are marked as "optional" in the specification for this
  382.85 + * interface.
  382.86 + *
  382.87 + * <p>This interface is a member of the
  382.88 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  382.89 + * Java Collections Framework</a>.
  382.90 + *
  382.91 + * <p>Many methods in Collections Framework interfaces are defined
  382.92 + * in terms of the {@link Object#equals(Object) equals} method.  For
  382.93 + * example, the specification for the {@link #containsKey(Object)
  382.94 + * containsKey(Object key)} method says: "returns <tt>true</tt> if and
  382.95 + * only if this map contains a mapping for a key <tt>k</tt> such that
  382.96 + * <tt>(key==null ? k==null : key.equals(k))</tt>." This specification should
  382.97 + * <i>not</i> be construed to imply that invoking <tt>Map.containsKey</tt>
  382.98 + * with a non-null argument <tt>key</tt> will cause <tt>key.equals(k)</tt> to
  382.99 + * be invoked for any key <tt>k</tt>.  Implementations are free to
 382.100 + * implement optimizations whereby the <tt>equals</tt> invocation is avoided,
 382.101 + * for example, by first comparing the hash codes of the two keys.  (The
 382.102 + * {@link Object#hashCode()} specification guarantees that two objects with
 382.103 + * unequal hash codes cannot be equal.)  More generally, implementations of
 382.104 + * the various Collections Framework interfaces are free to take advantage of
 382.105 + * the specified behavior of underlying {@link Object} methods wherever the
 382.106 + * implementor deems it appropriate.
 382.107 + *
 382.108 + * @param <K> the type of keys maintained by this map
 382.109 + * @param <V> the type of mapped values
 382.110 + *
 382.111 + * @author  Josh Bloch
 382.112 + * @see HashMap
 382.113 + * @see TreeMap
 382.114 + * @see Hashtable
 382.115 + * @see SortedMap
 382.116 + * @see Collection
 382.117 + * @see Set
 382.118 + * @since 1.2
 382.119 + */
 382.120 +public interface Map<K,V> {
 382.121 +    // Query Operations
 382.122 +
 382.123 +    /**
 382.124 +     * Returns the number of key-value mappings in this map.  If the
 382.125 +     * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
 382.126 +     * <tt>Integer.MAX_VALUE</tt>.
 382.127 +     *
 382.128 +     * @return the number of key-value mappings in this map
 382.129 +     */
 382.130 +    int size();
 382.131 +
 382.132 +    /**
 382.133 +     * Returns <tt>true</tt> if this map contains no key-value mappings.
 382.134 +     *
 382.135 +     * @return <tt>true</tt> if this map contains no key-value mappings
 382.136 +     */
 382.137 +    boolean isEmpty();
 382.138 +
 382.139 +    /**
 382.140 +     * Returns <tt>true</tt> if this map contains a mapping for the specified
 382.141 +     * key.  More formally, returns <tt>true</tt> if and only if
 382.142 +     * this map contains a mapping for a key <tt>k</tt> such that
 382.143 +     * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
 382.144 +     * at most one such mapping.)
 382.145 +     *
 382.146 +     * @param key key whose presence in this map is to be tested
 382.147 +     * @return <tt>true</tt> if this map contains a mapping for the specified
 382.148 +     *         key
 382.149 +     * @throws ClassCastException if the key is of an inappropriate type for
 382.150 +     *         this map
 382.151 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.152 +     * @throws NullPointerException if the specified key is null and this map
 382.153 +     *         does not permit null keys
 382.154 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.155 +     */
 382.156 +    boolean containsKey(Object key);
 382.157 +
 382.158 +    /**
 382.159 +     * Returns <tt>true</tt> if this map maps one or more keys to the
 382.160 +     * specified value.  More formally, returns <tt>true</tt> if and only if
 382.161 +     * this map contains at least one mapping to a value <tt>v</tt> such that
 382.162 +     * <tt>(value==null ? v==null : value.equals(v))</tt>.  This operation
 382.163 +     * will probably require time linear in the map size for most
 382.164 +     * implementations of the <tt>Map</tt> interface.
 382.165 +     *
 382.166 +     * @param value value whose presence in this map is to be tested
 382.167 +     * @return <tt>true</tt> if this map maps one or more keys to the
 382.168 +     *         specified value
 382.169 +     * @throws ClassCastException if the value is of an inappropriate type for
 382.170 +     *         this map
 382.171 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.172 +     * @throws NullPointerException if the specified value is null and this
 382.173 +     *         map does not permit null values
 382.174 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.175 +     */
 382.176 +    boolean containsValue(Object value);
 382.177 +
 382.178 +    /**
 382.179 +     * Returns the value to which the specified key is mapped,
 382.180 +     * or {@code null} if this map contains no mapping for the key.
 382.181 +     *
 382.182 +     * <p>More formally, if this map contains a mapping from a key
 382.183 +     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
 382.184 +     * key.equals(k))}, then this method returns {@code v}; otherwise
 382.185 +     * it returns {@code null}.  (There can be at most one such mapping.)
 382.186 +     *
 382.187 +     * <p>If this map permits null values, then a return value of
 382.188 +     * {@code null} does not <i>necessarily</i> indicate that the map
 382.189 +     * contains no mapping for the key; it's also possible that the map
 382.190 +     * explicitly maps the key to {@code null}.  The {@link #containsKey
 382.191 +     * containsKey} operation may be used to distinguish these two cases.
 382.192 +     *
 382.193 +     * @param key the key whose associated value is to be returned
 382.194 +     * @return the value to which the specified key is mapped, or
 382.195 +     *         {@code null} if this map contains no mapping for the key
 382.196 +     * @throws ClassCastException if the key is of an inappropriate type for
 382.197 +     *         this map
 382.198 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.199 +     * @throws NullPointerException if the specified key is null and this map
 382.200 +     *         does not permit null keys
 382.201 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.202 +     */
 382.203 +    V get(Object key);
 382.204 +
 382.205 +    // Modification Operations
 382.206 +
 382.207 +    /**
 382.208 +     * Associates the specified value with the specified key in this map
 382.209 +     * (optional operation).  If the map previously contained a mapping for
 382.210 +     * the key, the old value is replaced by the specified value.  (A map
 382.211 +     * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
 382.212 +     * if {@link #containsKey(Object) m.containsKey(k)} would return
 382.213 +     * <tt>true</tt>.)
 382.214 +     *
 382.215 +     * @param key key with which the specified value is to be associated
 382.216 +     * @param value value to be associated with the specified key
 382.217 +     * @return the previous value associated with <tt>key</tt>, or
 382.218 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 382.219 +     *         (A <tt>null</tt> return can also indicate that the map
 382.220 +     *         previously associated <tt>null</tt> with <tt>key</tt>,
 382.221 +     *         if the implementation supports <tt>null</tt> values.)
 382.222 +     * @throws UnsupportedOperationException if the <tt>put</tt> operation
 382.223 +     *         is not supported by this map
 382.224 +     * @throws ClassCastException if the class of the specified key or value
 382.225 +     *         prevents it from being stored in this map
 382.226 +     * @throws NullPointerException if the specified key or value is null
 382.227 +     *         and this map does not permit null keys or values
 382.228 +     * @throws IllegalArgumentException if some property of the specified key
 382.229 +     *         or value prevents it from being stored in this map
 382.230 +     */
 382.231 +    V put(K key, V value);
 382.232 +
 382.233 +    /**
 382.234 +     * Removes the mapping for a key from this map if it is present
 382.235 +     * (optional operation).   More formally, if this map contains a mapping
 382.236 +     * from key <tt>k</tt> to value <tt>v</tt> such that
 382.237 +     * <code>(key==null ?  k==null : key.equals(k))</code>, that mapping
 382.238 +     * is removed.  (The map can contain at most one such mapping.)
 382.239 +     *
 382.240 +     * <p>Returns the value to which this map previously associated the key,
 382.241 +     * or <tt>null</tt> if the map contained no mapping for the key.
 382.242 +     *
 382.243 +     * <p>If this map permits null values, then a return value of
 382.244 +     * <tt>null</tt> does not <i>necessarily</i> indicate that the map
 382.245 +     * contained no mapping for the key; it's also possible that the map
 382.246 +     * explicitly mapped the key to <tt>null</tt>.
 382.247 +     *
 382.248 +     * <p>The map will not contain a mapping for the specified key once the
 382.249 +     * call returns.
 382.250 +     *
 382.251 +     * @param key key whose mapping is to be removed from the map
 382.252 +     * @return the previous value associated with <tt>key</tt>, or
 382.253 +     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 382.254 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 382.255 +     *         is not supported by this map
 382.256 +     * @throws ClassCastException if the key is of an inappropriate type for
 382.257 +     *         this map
 382.258 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.259 +     * @throws NullPointerException if the specified key is null and this
 382.260 +     *         map does not permit null keys
 382.261 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 382.262 +     */
 382.263 +    V remove(Object key);
 382.264 +
 382.265 +
 382.266 +    // Bulk Operations
 382.267 +
 382.268 +    /**
 382.269 +     * Copies all of the mappings from the specified map to this map
 382.270 +     * (optional operation).  The effect of this call is equivalent to that
 382.271 +     * of calling {@link #put(Object,Object) put(k, v)} on this map once
 382.272 +     * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
 382.273 +     * specified map.  The behavior of this operation is undefined if the
 382.274 +     * specified map is modified while the operation is in progress.
 382.275 +     *
 382.276 +     * @param m mappings to be stored in this map
 382.277 +     * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
 382.278 +     *         is not supported by this map
 382.279 +     * @throws ClassCastException if the class of a key or value in the
 382.280 +     *         specified map prevents it from being stored in this map
 382.281 +     * @throws NullPointerException if the specified map is null, or if
 382.282 +     *         this map does not permit null keys or values, and the
 382.283 +     *         specified map contains null keys or values
 382.284 +     * @throws IllegalArgumentException if some property of a key or value in
 382.285 +     *         the specified map prevents it from being stored in this map
 382.286 +     */
 382.287 +    void putAll(Map<? extends K, ? extends V> m);
 382.288 +
 382.289 +    /**
 382.290 +     * Removes all of the mappings from this map (optional operation).
 382.291 +     * The map will be empty after this call returns.
 382.292 +     *
 382.293 +     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
 382.294 +     *         is not supported by this map
 382.295 +     */
 382.296 +    void clear();
 382.297 +
 382.298 +
 382.299 +    // Views
 382.300 +
 382.301 +    /**
 382.302 +     * Returns a {@link Set} view of the keys contained in this map.
 382.303 +     * The set is backed by the map, so changes to the map are
 382.304 +     * reflected in the set, and vice-versa.  If the map is modified
 382.305 +     * while an iteration over the set is in progress (except through
 382.306 +     * the iterator's own <tt>remove</tt> operation), the results of
 382.307 +     * the iteration are undefined.  The set supports element removal,
 382.308 +     * which removes the corresponding mapping from the map, via the
 382.309 +     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
 382.310 +     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
 382.311 +     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
 382.312 +     * operations.
 382.313 +     *
 382.314 +     * @return a set view of the keys contained in this map
 382.315 +     */
 382.316 +    Set<K> keySet();
 382.317 +
 382.318 +    /**
 382.319 +     * Returns a {@link Collection} view of the values contained in this map.
 382.320 +     * The collection is backed by the map, so changes to the map are
 382.321 +     * reflected in the collection, and vice-versa.  If the map is
 382.322 +     * modified while an iteration over the collection is in progress
 382.323 +     * (except through the iterator's own <tt>remove</tt> operation),
 382.324 +     * the results of the iteration are undefined.  The collection
 382.325 +     * supports element removal, which removes the corresponding
 382.326 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
 382.327 +     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
 382.328 +     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
 382.329 +     * support the <tt>add</tt> or <tt>addAll</tt> operations.
 382.330 +     *
 382.331 +     * @return a collection view of the values contained in this map
 382.332 +     */
 382.333 +    Collection<V> values();
 382.334 +
 382.335 +    /**
 382.336 +     * Returns a {@link Set} view of the mappings contained in this map.
 382.337 +     * The set is backed by the map, so changes to the map are
 382.338 +     * reflected in the set, and vice-versa.  If the map is modified
 382.339 +     * while an iteration over the set is in progress (except through
 382.340 +     * the iterator's own <tt>remove</tt> operation, or through the
 382.341 +     * <tt>setValue</tt> operation on a map entry returned by the
 382.342 +     * iterator) the results of the iteration are undefined.  The set
 382.343 +     * supports element removal, which removes the corresponding
 382.344 +     * mapping from the map, via the <tt>Iterator.remove</tt>,
 382.345 +     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
 382.346 +     * <tt>clear</tt> operations.  It does not support the
 382.347 +     * <tt>add</tt> or <tt>addAll</tt> operations.
 382.348 +     *
 382.349 +     * @return a set view of the mappings contained in this map
 382.350 +     */
 382.351 +    Set<Map.Entry<K, V>> entrySet();
 382.352 +
 382.353 +    /**
 382.354 +     * A map entry (key-value pair).  The <tt>Map.entrySet</tt> method returns
 382.355 +     * a collection-view of the map, whose elements are of this class.  The
 382.356 +     * <i>only</i> way to obtain a reference to a map entry is from the
 382.357 +     * iterator of this collection-view.  These <tt>Map.Entry</tt> objects are
 382.358 +     * valid <i>only</i> for the duration of the iteration; more formally,
 382.359 +     * the behavior of a map entry is undefined if the backing map has been
 382.360 +     * modified after the entry was returned by the iterator, except through
 382.361 +     * the <tt>setValue</tt> operation on the map entry.
 382.362 +     *
 382.363 +     * @see Map#entrySet()
 382.364 +     * @since 1.2
 382.365 +     */
 382.366 +    interface Entry<K,V> {
 382.367 +        /**
 382.368 +         * Returns the key corresponding to this entry.
 382.369 +         *
 382.370 +         * @return the key corresponding to this entry
 382.371 +         * @throws IllegalStateException implementations may, but are not
 382.372 +         *         required to, throw this exception if the entry has been
 382.373 +         *         removed from the backing map.
 382.374 +         */
 382.375 +        K getKey();
 382.376 +
 382.377 +        /**
 382.378 +         * Returns the value corresponding to this entry.  If the mapping
 382.379 +         * has been removed from the backing map (by the iterator's
 382.380 +         * <tt>remove</tt> operation), the results of this call are undefined.
 382.381 +         *
 382.382 +         * @return the value corresponding to this entry
 382.383 +         * @throws IllegalStateException implementations may, but are not
 382.384 +         *         required to, throw this exception if the entry has been
 382.385 +         *         removed from the backing map.
 382.386 +         */
 382.387 +        V getValue();
 382.388 +
 382.389 +        /**
 382.390 +         * Replaces the value corresponding to this entry with the specified
 382.391 +         * value (optional operation).  (Writes through to the map.)  The
 382.392 +         * behavior of this call is undefined if the mapping has already been
 382.393 +         * removed from the map (by the iterator's <tt>remove</tt> operation).
 382.394 +         *
 382.395 +         * @param value new value to be stored in this entry
 382.396 +         * @return old value corresponding to the entry
 382.397 +         * @throws UnsupportedOperationException if the <tt>put</tt> operation
 382.398 +         *         is not supported by the backing map
 382.399 +         * @throws ClassCastException if the class of the specified value
 382.400 +         *         prevents it from being stored in the backing map
 382.401 +         * @throws NullPointerException if the backing map does not permit
 382.402 +         *         null values, and the specified value is null
 382.403 +         * @throws IllegalArgumentException if some property of this value
 382.404 +         *         prevents it from being stored in the backing map
 382.405 +         * @throws IllegalStateException implementations may, but are not
 382.406 +         *         required to, throw this exception if the entry has been
 382.407 +         *         removed from the backing map.
 382.408 +         */
 382.409 +        V setValue(V value);
 382.410 +
 382.411 +        /**
 382.412 +         * Compares the specified object with this entry for equality.
 382.413 +         * Returns <tt>true</tt> if the given object is also a map entry and
 382.414 +         * the two entries represent the same mapping.  More formally, two
 382.415 +         * entries <tt>e1</tt> and <tt>e2</tt> represent the same mapping
 382.416 +         * if<pre>
 382.417 +         *     (e1.getKey()==null ?
 382.418 +         *      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &amp;&amp;
 382.419 +         *     (e1.getValue()==null ?
 382.420 +         *      e2.getValue()==null : e1.getValue().equals(e2.getValue()))
 382.421 +         * </pre>
 382.422 +         * This ensures that the <tt>equals</tt> method works properly across
 382.423 +         * different implementations of the <tt>Map.Entry</tt> interface.
 382.424 +         *
 382.425 +         * @param o object to be compared for equality with this map entry
 382.426 +         * @return <tt>true</tt> if the specified object is equal to this map
 382.427 +         *         entry
 382.428 +         */
 382.429 +        boolean equals(Object o);
 382.430 +
 382.431 +        /**
 382.432 +         * Returns the hash code value for this map entry.  The hash code
 382.433 +         * of a map entry <tt>e</tt> is defined to be: <pre>
 382.434 +         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
 382.435 +         *     (e.getValue()==null ? 0 : e.getValue().hashCode())
 382.436 +         * </pre>
 382.437 +         * This ensures that <tt>e1.equals(e2)</tt> implies that
 382.438 +         * <tt>e1.hashCode()==e2.hashCode()</tt> for any two Entries
 382.439 +         * <tt>e1</tt> and <tt>e2</tt>, as required by the general
 382.440 +         * contract of <tt>Object.hashCode</tt>.
 382.441 +         *
 382.442 +         * @return the hash code value for this map entry
 382.443 +         * @see Object#hashCode()
 382.444 +         * @see Object#equals(Object)
 382.445 +         * @see #equals(Object)
 382.446 +         */
 382.447 +        int hashCode();
 382.448 +    }
 382.449 +
 382.450 +    // Comparison and hashing
 382.451 +
 382.452 +    /**
 382.453 +     * Compares the specified object with this map for equality.  Returns
 382.454 +     * <tt>true</tt> if the given object is also a map and the two maps
 382.455 +     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
 382.456 +     * <tt>m2</tt> represent the same mappings if
 382.457 +     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
 382.458 +     * <tt>equals</tt> method works properly across different implementations
 382.459 +     * of the <tt>Map</tt> interface.
 382.460 +     *
 382.461 +     * @param o object to be compared for equality with this map
 382.462 +     * @return <tt>true</tt> if the specified object is equal to this map
 382.463 +     */
 382.464 +    boolean equals(Object o);
 382.465 +
 382.466 +    /**
 382.467 +     * Returns the hash code value for this map.  The hash code of a map is
 382.468 +     * defined to be the sum of the hash codes of each entry in the map's
 382.469 +     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
 382.470 +     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
 382.471 +     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
 382.472 +     * {@link Object#hashCode}.
 382.473 +     *
 382.474 +     * @return the hash code value for this map
 382.475 +     * @see Map.Entry#hashCode()
 382.476 +     * @see Object#equals(Object)
 382.477 +     * @see #equals(Object)
 382.478 +     */
 382.479 +    int hashCode();
 382.480 +
 382.481 +}
   383.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   383.2 +++ b/rt/emul/compact/src/main/java/java/util/Objects.java	Wed Feb 27 11:24:58 2013 +0100
   383.3 @@ -0,0 +1,229 @@
   383.4 +/*
   383.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   383.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   383.7 + *
   383.8 + * This code is free software; you can redistribute it and/or modify it
   383.9 + * under the terms of the GNU General Public License version 2 only, as
  383.10 + * published by the Free Software Foundation.  Oracle designates this
  383.11 + * particular file as subject to the "Classpath" exception as provided
  383.12 + * by Oracle in the LICENSE file that accompanied this code.
  383.13 + *
  383.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  383.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  383.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  383.17 + * version 2 for more details (a copy is included in the LICENSE file that
  383.18 + * accompanied this code).
  383.19 + *
  383.20 + * You should have received a copy of the GNU General Public License version
  383.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  383.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  383.23 + *
  383.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  383.25 + * or visit www.oracle.com if you need additional information or have any
  383.26 + * questions.
  383.27 + */
  383.28 +
  383.29 +package java.util;
  383.30 +
  383.31 +/**
  383.32 + * This class consists of {@code static} utility methods for operating
  383.33 + * on objects.  These utilities include {@code null}-safe or {@code
  383.34 + * null}-tolerant methods for computing the hash code of an object,
  383.35 + * returning a string for an object, and comparing two objects.
  383.36 + *
  383.37 + * @since 1.7
  383.38 + */
  383.39 +public final class Objects {
  383.40 +    private Objects() {
  383.41 +        throw new AssertionError("No java.util.Objects instances for you!");
  383.42 +    }
  383.43 +
  383.44 +    /**
  383.45 +     * Returns {@code true} if the arguments are equal to each other
  383.46 +     * and {@code false} otherwise.
  383.47 +     * Consequently, if both arguments are {@code null}, {@code true}
  383.48 +     * is returned and if exactly one argument is {@code null}, {@code
  383.49 +     * false} is returned.  Otherwise, equality is determined by using
  383.50 +     * the {@link Object#equals equals} method of the first
  383.51 +     * argument.
  383.52 +     *
  383.53 +     * @param a an object
  383.54 +     * @param b an object to be compared with {@code a} for equality
  383.55 +     * @return {@code true} if the arguments are equal to each other
  383.56 +     * and {@code false} otherwise
  383.57 +     * @see Object#equals(Object)
  383.58 +     */
  383.59 +    public static boolean equals(Object a, Object b) {
  383.60 +        return (a == b) || (a != null && a.equals(b));
  383.61 +    }
  383.62 +
  383.63 +   /**
  383.64 +    * Returns {@code true} if the arguments are deeply equal to each other
  383.65 +    * and {@code false} otherwise.
  383.66 +    *
  383.67 +    * Two {@code null} values are deeply equal.  If both arguments are
  383.68 +    * arrays, the algorithm in {@link Arrays#deepEquals(Object[],
  383.69 +    * Object[]) Arrays.deepEquals} is used to determine equality.
  383.70 +    * Otherwise, equality is determined by using the {@link
  383.71 +    * Object#equals equals} method of the first argument.
  383.72 +    *
  383.73 +    * @param a an object
  383.74 +    * @param b an object to be compared with {@code a} for deep equality
  383.75 +    * @return {@code true} if the arguments are deeply equal to each other
  383.76 +    * and {@code false} otherwise
  383.77 +    * @see Arrays#deepEquals(Object[], Object[])
  383.78 +    * @see Objects#equals(Object, Object)
  383.79 +    */
  383.80 +    public static boolean deepEquals(Object a, Object b) {
  383.81 +        if (a == b)
  383.82 +            return true;
  383.83 +        else if (a == null || b == null)
  383.84 +            return false;
  383.85 +        else
  383.86 +            return Arrays.deepEquals0(a, b);
  383.87 +    }
  383.88 +
  383.89 +    /**
  383.90 +     * Returns the hash code of a non-{@code null} argument and 0 for
  383.91 +     * a {@code null} argument.
  383.92 +     *
  383.93 +     * @param o an object
  383.94 +     * @return the hash code of a non-{@code null} argument and 0 for
  383.95 +     * a {@code null} argument
  383.96 +     * @see Object#hashCode
  383.97 +     */
  383.98 +    public static int hashCode(Object o) {
  383.99 +        return o != null ? o.hashCode() : 0;
 383.100 +    }
 383.101 +
 383.102 +   /**
 383.103 +    * Generates a hash code for a sequence of input values. The hash
 383.104 +    * code is generated as if all the input values were placed into an
 383.105 +    * array, and that array were hashed by calling {@link
 383.106 +    * Arrays#hashCode(Object[])}.
 383.107 +    *
 383.108 +    * <p>This method is useful for implementing {@link
 383.109 +    * Object#hashCode()} on objects containing multiple fields. For
 383.110 +    * example, if an object that has three fields, {@code x}, {@code
 383.111 +    * y}, and {@code z}, one could write:
 383.112 +    *
 383.113 +    * <blockquote><pre>
 383.114 +    * &#064;Override public int hashCode() {
 383.115 +    *     return Objects.hash(x, y, z);
 383.116 +    * }
 383.117 +    * </pre></blockquote>
 383.118 +    *
 383.119 +    * <b>Warning: When a single object reference is supplied, the returned
 383.120 +    * value does not equal the hash code of that object reference.</b> This
 383.121 +    * value can be computed by calling {@link #hashCode(Object)}.
 383.122 +    *
 383.123 +    * @param values the values to be hashed
 383.124 +    * @return a hash value of the sequence of input values
 383.125 +    * @see Arrays#hashCode(Object[])
 383.126 +    * @see List#hashCode
 383.127 +    */
 383.128 +    public static int hash(Object... values) {
 383.129 +        return Arrays.hashCode(values);
 383.130 +    }
 383.131 +
 383.132 +    /**
 383.133 +     * Returns the result of calling {@code toString} for a non-{@code
 383.134 +     * null} argument and {@code "null"} for a {@code null} argument.
 383.135 +     *
 383.136 +     * @param o an object
 383.137 +     * @return the result of calling {@code toString} for a non-{@code
 383.138 +     * null} argument and {@code "null"} for a {@code null} argument
 383.139 +     * @see Object#toString
 383.140 +     * @see String#valueOf(Object)
 383.141 +     */
 383.142 +    public static String toString(Object o) {
 383.143 +        return String.valueOf(o);
 383.144 +    }
 383.145 +
 383.146 +    /**
 383.147 +     * Returns the result of calling {@code toString} on the first
 383.148 +     * argument if the first argument is not {@code null} and returns
 383.149 +     * the second argument otherwise.
 383.150 +     *
 383.151 +     * @param o an object
 383.152 +     * @param nullDefault string to return if the first argument is
 383.153 +     *        {@code null}
 383.154 +     * @return the result of calling {@code toString} on the first
 383.155 +     * argument if it is not {@code null} and the second argument
 383.156 +     * otherwise.
 383.157 +     * @see Objects#toString(Object)
 383.158 +     */
 383.159 +    public static String toString(Object o, String nullDefault) {
 383.160 +        return (o != null) ? o.toString() : nullDefault;
 383.161 +    }
 383.162 +
 383.163 +    /**
 383.164 +     * Returns 0 if the arguments are identical and {@code
 383.165 +     * c.compare(a, b)} otherwise.
 383.166 +     * Consequently, if both arguments are {@code null} 0
 383.167 +     * is returned.
 383.168 +     *
 383.169 +     * <p>Note that if one of the arguments is {@code null}, a {@code
 383.170 +     * NullPointerException} may or may not be thrown depending on
 383.171 +     * what ordering policy, if any, the {@link Comparator Comparator}
 383.172 +     * chooses to have for {@code null} values.
 383.173 +     *
 383.174 +     * @param <T> the type of the objects being compared
 383.175 +     * @param a an object
 383.176 +     * @param b an object to be compared with {@code a}
 383.177 +     * @param c the {@code Comparator} to compare the first two arguments
 383.178 +     * @return 0 if the arguments are identical and {@code
 383.179 +     * c.compare(a, b)} otherwise.
 383.180 +     * @see Comparable
 383.181 +     * @see Comparator
 383.182 +     */
 383.183 +    public static <T> int compare(T a, T b, Comparator<? super T> c) {
 383.184 +        return (a == b) ? 0 :  c.compare(a, b);
 383.185 +    }
 383.186 +
 383.187 +    /**
 383.188 +     * Checks that the specified object reference is not {@code null}. This
 383.189 +     * method is designed primarily for doing parameter validation in methods
 383.190 +     * and constructors, as demonstrated below:
 383.191 +     * <blockquote><pre>
 383.192 +     * public Foo(Bar bar) {
 383.193 +     *     this.bar = Objects.requireNonNull(bar);
 383.194 +     * }
 383.195 +     * </pre></blockquote>
 383.196 +     *
 383.197 +     * @param obj the object reference to check for nullity
 383.198 +     * @param <T> the type of the reference
 383.199 +     * @return {@code obj} if not {@code null}
 383.200 +     * @throws NullPointerException if {@code obj} is {@code null}
 383.201 +     */
 383.202 +    public static <T> T requireNonNull(T obj) {
 383.203 +        if (obj == null)
 383.204 +            throw new NullPointerException();
 383.205 +        return obj;
 383.206 +    }
 383.207 +
 383.208 +    /**
 383.209 +     * Checks that the specified object reference is not {@code null} and
 383.210 +     * throws a customized {@link NullPointerException} if it is. This method
 383.211 +     * is designed primarily for doing parameter validation in methods and
 383.212 +     * constructors with multiple parameters, as demonstrated below:
 383.213 +     * <blockquote><pre>
 383.214 +     * public Foo(Bar bar, Baz baz) {
 383.215 +     *     this.bar = Objects.requireNonNull(bar, "bar must not be null");
 383.216 +     *     this.baz = Objects.requireNonNull(baz, "baz must not be null");
 383.217 +     * }
 383.218 +     * </pre></blockquote>
 383.219 +     *
 383.220 +     * @param obj     the object reference to check for nullity
 383.221 +     * @param message detail message to be used in the event that a {@code
 383.222 +     *                NullPointerException} is thrown
 383.223 +     * @param <T> the type of the reference
 383.224 +     * @return {@code obj} if not {@code null}
 383.225 +     * @throws NullPointerException if {@code obj} is {@code null}
 383.226 +     */
 383.227 +    public static <T> T requireNonNull(T obj, String message) {
 383.228 +        if (obj == null)
 383.229 +            throw new NullPointerException(message);
 383.230 +        return obj;
 383.231 +    }
 383.232 +}
   384.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   384.2 +++ b/rt/emul/compact/src/main/java/java/util/PriorityQueue.java	Wed Feb 27 11:24:58 2013 +0100
   384.3 @@ -0,0 +1,731 @@
   384.4 +/*
   384.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   384.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   384.7 + *
   384.8 + * This code is free software; you can redistribute it and/or modify it
   384.9 + * under the terms of the GNU General Public License version 2 only, as
  384.10 + * published by the Free Software Foundation.  Oracle designates this
  384.11 + * particular file as subject to the "Classpath" exception as provided
  384.12 + * by Oracle in the LICENSE file that accompanied this code.
  384.13 + *
  384.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  384.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  384.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  384.17 + * version 2 for more details (a copy is included in the LICENSE file that
  384.18 + * accompanied this code).
  384.19 + *
  384.20 + * You should have received a copy of the GNU General Public License version
  384.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  384.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  384.23 + *
  384.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  384.25 + * or visit www.oracle.com if you need additional information or have any
  384.26 + * questions.
  384.27 + */
  384.28 +
  384.29 +package java.util;
  384.30 +
  384.31 +
  384.32 +/**
  384.33 + * An unbounded priority {@linkplain Queue queue} based on a priority heap.
  384.34 + * The elements of the priority queue are ordered according to their
  384.35 + * {@linkplain Comparable natural ordering}, or by a {@link Comparator}
  384.36 + * provided at queue construction time, depending on which constructor is
  384.37 + * used.  A priority queue does not permit {@code null} elements.
  384.38 + * A priority queue relying on natural ordering also does not permit
  384.39 + * insertion of non-comparable objects (doing so may result in
  384.40 + * {@code ClassCastException}).
  384.41 + *
  384.42 + * <p>The <em>head</em> of this queue is the <em>least</em> element
  384.43 + * with respect to the specified ordering.  If multiple elements are
  384.44 + * tied for least value, the head is one of those elements -- ties are
  384.45 + * broken arbitrarily.  The queue retrieval operations {@code poll},
  384.46 + * {@code remove}, {@code peek}, and {@code element} access the
  384.47 + * element at the head of the queue.
  384.48 + *
  384.49 + * <p>A priority queue is unbounded, but has an internal
  384.50 + * <i>capacity</i> governing the size of an array used to store the
  384.51 + * elements on the queue.  It is always at least as large as the queue
  384.52 + * size.  As elements are added to a priority queue, its capacity
  384.53 + * grows automatically.  The details of the growth policy are not
  384.54 + * specified.
  384.55 + *
  384.56 + * <p>This class and its iterator implement all of the
  384.57 + * <em>optional</em> methods of the {@link Collection} and {@link
  384.58 + * Iterator} interfaces.  The Iterator provided in method {@link
  384.59 + * #iterator()} is <em>not</em> guaranteed to traverse the elements of
  384.60 + * the priority queue in any particular order. If you need ordered
  384.61 + * traversal, consider using {@code Arrays.sort(pq.toArray())}.
  384.62 + *
  384.63 + * <p> <strong>Note that this implementation is not synchronized.</strong>
  384.64 + * Multiple threads should not access a {@code PriorityQueue}
  384.65 + * instance concurrently if any of the threads modifies the queue.
  384.66 + * Instead, use the thread-safe {@link
  384.67 + * java.util.concurrent.PriorityBlockingQueue} class.
  384.68 + *
  384.69 + * <p>Implementation note: this implementation provides
  384.70 + * O(log(n)) time for the enqueing and dequeing methods
  384.71 + * ({@code offer}, {@code poll}, {@code remove()} and {@code add});
  384.72 + * linear time for the {@code remove(Object)} and {@code contains(Object)}
  384.73 + * methods; and constant time for the retrieval methods
  384.74 + * ({@code peek}, {@code element}, and {@code size}).
  384.75 + *
  384.76 + * <p>This class is a member of the
  384.77 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  384.78 + * Java Collections Framework</a>.
  384.79 + *
  384.80 + * @since 1.5
  384.81 + * @author Josh Bloch, Doug Lea
  384.82 + * @param <E> the type of elements held in this collection
  384.83 + */
  384.84 +public class PriorityQueue<E> extends AbstractQueue<E>
  384.85 +    implements java.io.Serializable {
  384.86 +
  384.87 +    private static final long serialVersionUID = -7720805057305804111L;
  384.88 +
  384.89 +    private static final int DEFAULT_INITIAL_CAPACITY = 11;
  384.90 +
  384.91 +    /**
  384.92 +     * Priority queue represented as a balanced binary heap: the two
  384.93 +     * children of queue[n] are queue[2*n+1] and queue[2*(n+1)].  The
  384.94 +     * priority queue is ordered by comparator, or by the elements'
  384.95 +     * natural ordering, if comparator is null: For each node n in the
  384.96 +     * heap and each descendant d of n, n <= d.  The element with the
  384.97 +     * lowest value is in queue[0], assuming the queue is nonempty.
  384.98 +     */
  384.99 +    private transient Object[] queue;
 384.100 +
 384.101 +    /**
 384.102 +     * The number of elements in the priority queue.
 384.103 +     */
 384.104 +    private int size = 0;
 384.105 +
 384.106 +    /**
 384.107 +     * The comparator, or null if priority queue uses elements'
 384.108 +     * natural ordering.
 384.109 +     */
 384.110 +    private final Comparator<? super E> comparator;
 384.111 +
 384.112 +    /**
 384.113 +     * The number of times this priority queue has been
 384.114 +     * <i>structurally modified</i>.  See AbstractList for gory details.
 384.115 +     */
 384.116 +    private transient int modCount = 0;
 384.117 +
 384.118 +    /**
 384.119 +     * Creates a {@code PriorityQueue} with the default initial
 384.120 +     * capacity (11) that orders its elements according to their
 384.121 +     * {@linkplain Comparable natural ordering}.
 384.122 +     */
 384.123 +    public PriorityQueue() {
 384.124 +        this(DEFAULT_INITIAL_CAPACITY, null);
 384.125 +    }
 384.126 +
 384.127 +    /**
 384.128 +     * Creates a {@code PriorityQueue} with the specified initial
 384.129 +     * capacity that orders its elements according to their
 384.130 +     * {@linkplain Comparable natural ordering}.
 384.131 +     *
 384.132 +     * @param initialCapacity the initial capacity for this priority queue
 384.133 +     * @throws IllegalArgumentException if {@code initialCapacity} is less
 384.134 +     *         than 1
 384.135 +     */
 384.136 +    public PriorityQueue(int initialCapacity) {
 384.137 +        this(initialCapacity, null);
 384.138 +    }
 384.139 +
 384.140 +    /**
 384.141 +     * Creates a {@code PriorityQueue} with the specified initial capacity
 384.142 +     * that orders its elements according to the specified comparator.
 384.143 +     *
 384.144 +     * @param  initialCapacity the initial capacity for this priority queue
 384.145 +     * @param  comparator the comparator that will be used to order this
 384.146 +     *         priority queue.  If {@code null}, the {@linkplain Comparable
 384.147 +     *         natural ordering} of the elements will be used.
 384.148 +     * @throws IllegalArgumentException if {@code initialCapacity} is
 384.149 +     *         less than 1
 384.150 +     */
 384.151 +    public PriorityQueue(int initialCapacity,
 384.152 +                         Comparator<? super E> comparator) {
 384.153 +        // Note: This restriction of at least one is not actually needed,
 384.154 +        // but continues for 1.5 compatibility
 384.155 +        if (initialCapacity < 1)
 384.156 +            throw new IllegalArgumentException();
 384.157 +        this.queue = new Object[initialCapacity];
 384.158 +        this.comparator = comparator;
 384.159 +    }
 384.160 +
 384.161 +    /**
 384.162 +     * Creates a {@code PriorityQueue} containing the elements in the
 384.163 +     * specified collection.  If the specified collection is an instance of
 384.164 +     * a {@link SortedSet} or is another {@code PriorityQueue}, this
 384.165 +     * priority queue will be ordered according to the same ordering.
 384.166 +     * Otherwise, this priority queue will be ordered according to the
 384.167 +     * {@linkplain Comparable natural ordering} of its elements.
 384.168 +     *
 384.169 +     * @param  c the collection whose elements are to be placed
 384.170 +     *         into this priority queue
 384.171 +     * @throws ClassCastException if elements of the specified collection
 384.172 +     *         cannot be compared to one another according to the priority
 384.173 +     *         queue's ordering
 384.174 +     * @throws NullPointerException if the specified collection or any
 384.175 +     *         of its elements are null
 384.176 +     */
 384.177 +    @SuppressWarnings("unchecked")
 384.178 +    public PriorityQueue(Collection<? extends E> c) {
 384.179 +        if (c instanceof SortedSet<?>) {
 384.180 +            SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
 384.181 +            this.comparator = (Comparator<? super E>) ss.comparator();
 384.182 +            initElementsFromCollection(ss);
 384.183 +        }
 384.184 +        else if (c instanceof PriorityQueue<?>) {
 384.185 +            PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c;
 384.186 +            this.comparator = (Comparator<? super E>) pq.comparator();
 384.187 +            initFromPriorityQueue(pq);
 384.188 +        }
 384.189 +        else {
 384.190 +            this.comparator = null;
 384.191 +            initFromCollection(c);
 384.192 +        }
 384.193 +    }
 384.194 +
 384.195 +    /**
 384.196 +     * Creates a {@code PriorityQueue} containing the elements in the
 384.197 +     * specified priority queue.  This priority queue will be
 384.198 +     * ordered according to the same ordering as the given priority
 384.199 +     * queue.
 384.200 +     *
 384.201 +     * @param  c the priority queue whose elements are to be placed
 384.202 +     *         into this priority queue
 384.203 +     * @throws ClassCastException if elements of {@code c} cannot be
 384.204 +     *         compared to one another according to {@code c}'s
 384.205 +     *         ordering
 384.206 +     * @throws NullPointerException if the specified priority queue or any
 384.207 +     *         of its elements are null
 384.208 +     */
 384.209 +    @SuppressWarnings("unchecked")
 384.210 +    public PriorityQueue(PriorityQueue<? extends E> c) {
 384.211 +        this.comparator = (Comparator<? super E>) c.comparator();
 384.212 +        initFromPriorityQueue(c);
 384.213 +    }
 384.214 +
 384.215 +    /**
 384.216 +     * Creates a {@code PriorityQueue} containing the elements in the
 384.217 +     * specified sorted set.   This priority queue will be ordered
 384.218 +     * according to the same ordering as the given sorted set.
 384.219 +     *
 384.220 +     * @param  c the sorted set whose elements are to be placed
 384.221 +     *         into this priority queue
 384.222 +     * @throws ClassCastException if elements of the specified sorted
 384.223 +     *         set cannot be compared to one another according to the
 384.224 +     *         sorted set's ordering
 384.225 +     * @throws NullPointerException if the specified sorted set or any
 384.226 +     *         of its elements are null
 384.227 +     */
 384.228 +    @SuppressWarnings("unchecked")
 384.229 +    public PriorityQueue(SortedSet<? extends E> c) {
 384.230 +        this.comparator = (Comparator<? super E>) c.comparator();
 384.231 +        initElementsFromCollection(c);
 384.232 +    }
 384.233 +
 384.234 +    private void initFromPriorityQueue(PriorityQueue<? extends E> c) {
 384.235 +        if (c.getClass() == PriorityQueue.class) {
 384.236 +            this.queue = c.toArray();
 384.237 +            this.size = c.size();
 384.238 +        } else {
 384.239 +            initFromCollection(c);
 384.240 +        }
 384.241 +    }
 384.242 +
 384.243 +    private void initElementsFromCollection(Collection<? extends E> c) {
 384.244 +        Object[] a = c.toArray();
 384.245 +        // If c.toArray incorrectly doesn't return Object[], copy it.
 384.246 +        if (a.getClass() != Object[].class)
 384.247 +            a = Arrays.copyOf(a, a.length, Object[].class);
 384.248 +        int len = a.length;
 384.249 +        if (len == 1 || this.comparator != null)
 384.250 +            for (int i = 0; i < len; i++)
 384.251 +                if (a[i] == null)
 384.252 +                    throw new NullPointerException();
 384.253 +        this.queue = a;
 384.254 +        this.size = a.length;
 384.255 +    }
 384.256 +
 384.257 +    /**
 384.258 +     * Initializes queue array with elements from the given Collection.
 384.259 +     *
 384.260 +     * @param c the collection
 384.261 +     */
 384.262 +    private void initFromCollection(Collection<? extends E> c) {
 384.263 +        initElementsFromCollection(c);
 384.264 +        heapify();
 384.265 +    }
 384.266 +
 384.267 +    /**
 384.268 +     * The maximum size of array to allocate.
 384.269 +     * Some VMs reserve some header words in an array.
 384.270 +     * Attempts to allocate larger arrays may result in
 384.271 +     * OutOfMemoryError: Requested array size exceeds VM limit
 384.272 +     */
 384.273 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 384.274 +
 384.275 +    /**
 384.276 +     * Increases the capacity of the array.
 384.277 +     *
 384.278 +     * @param minCapacity the desired minimum capacity
 384.279 +     */
 384.280 +    private void grow(int minCapacity) {
 384.281 +        int oldCapacity = queue.length;
 384.282 +        // Double size if small; else grow by 50%
 384.283 +        int newCapacity = oldCapacity + ((oldCapacity < 64) ?
 384.284 +                                         (oldCapacity + 2) :
 384.285 +                                         (oldCapacity >> 1));
 384.286 +        // overflow-conscious code
 384.287 +        if (newCapacity - MAX_ARRAY_SIZE > 0)
 384.288 +            newCapacity = hugeCapacity(minCapacity);
 384.289 +        queue = Arrays.copyOf(queue, newCapacity);
 384.290 +    }
 384.291 +
 384.292 +    private static int hugeCapacity(int minCapacity) {
 384.293 +        if (minCapacity < 0) // overflow
 384.294 +            throw new OutOfMemoryError();
 384.295 +        return (minCapacity > MAX_ARRAY_SIZE) ?
 384.296 +            Integer.MAX_VALUE :
 384.297 +            MAX_ARRAY_SIZE;
 384.298 +    }
 384.299 +
 384.300 +    /**
 384.301 +     * Inserts the specified element into this priority queue.
 384.302 +     *
 384.303 +     * @return {@code true} (as specified by {@link Collection#add})
 384.304 +     * @throws ClassCastException if the specified element cannot be
 384.305 +     *         compared with elements currently in this priority queue
 384.306 +     *         according to the priority queue's ordering
 384.307 +     * @throws NullPointerException if the specified element is null
 384.308 +     */
 384.309 +    public boolean add(E e) {
 384.310 +        return offer(e);
 384.311 +    }
 384.312 +
 384.313 +    /**
 384.314 +     * Inserts the specified element into this priority queue.
 384.315 +     *
 384.316 +     * @return {@code true} (as specified by {@link Queue#offer})
 384.317 +     * @throws ClassCastException if the specified element cannot be
 384.318 +     *         compared with elements currently in this priority queue
 384.319 +     *         according to the priority queue's ordering
 384.320 +     * @throws NullPointerException if the specified element is null
 384.321 +     */
 384.322 +    public boolean offer(E e) {
 384.323 +        if (e == null)
 384.324 +            throw new NullPointerException();
 384.325 +        modCount++;
 384.326 +        int i = size;
 384.327 +        if (i >= queue.length)
 384.328 +            grow(i + 1);
 384.329 +        size = i + 1;
 384.330 +        if (i == 0)
 384.331 +            queue[0] = e;
 384.332 +        else
 384.333 +            siftUp(i, e);
 384.334 +        return true;
 384.335 +    }
 384.336 +
 384.337 +    public E peek() {
 384.338 +        if (size == 0)
 384.339 +            return null;
 384.340 +        return (E) queue[0];
 384.341 +    }
 384.342 +
 384.343 +    private int indexOf(Object o) {
 384.344 +        if (o != null) {
 384.345 +            for (int i = 0; i < size; i++)
 384.346 +                if (o.equals(queue[i]))
 384.347 +                    return i;
 384.348 +        }
 384.349 +        return -1;
 384.350 +    }
 384.351 +
 384.352 +    /**
 384.353 +     * Removes a single instance of the specified element from this queue,
 384.354 +     * if it is present.  More formally, removes an element {@code e} such
 384.355 +     * that {@code o.equals(e)}, if this queue contains one or more such
 384.356 +     * elements.  Returns {@code true} if and only if this queue contained
 384.357 +     * the specified element (or equivalently, if this queue changed as a
 384.358 +     * result of the call).
 384.359 +     *
 384.360 +     * @param o element to be removed from this queue, if present
 384.361 +     * @return {@code true} if this queue changed as a result of the call
 384.362 +     */
 384.363 +    public boolean remove(Object o) {
 384.364 +        int i = indexOf(o);
 384.365 +        if (i == -1)
 384.366 +            return false;
 384.367 +        else {
 384.368 +            removeAt(i);
 384.369 +            return true;
 384.370 +        }
 384.371 +    }
 384.372 +
 384.373 +    /**
 384.374 +     * Version of remove using reference equality, not equals.
 384.375 +     * Needed by iterator.remove.
 384.376 +     *
 384.377 +     * @param o element to be removed from this queue, if present
 384.378 +     * @return {@code true} if removed
 384.379 +     */
 384.380 +    boolean removeEq(Object o) {
 384.381 +        for (int i = 0; i < size; i++) {
 384.382 +            if (o == queue[i]) {
 384.383 +                removeAt(i);
 384.384 +                return true;
 384.385 +            }
 384.386 +        }
 384.387 +        return false;
 384.388 +    }
 384.389 +
 384.390 +    /**
 384.391 +     * Returns {@code true} if this queue contains the specified element.
 384.392 +     * More formally, returns {@code true} if and only if this queue contains
 384.393 +     * at least one element {@code e} such that {@code o.equals(e)}.
 384.394 +     *
 384.395 +     * @param o object to be checked for containment in this queue
 384.396 +     * @return {@code true} if this queue contains the specified element
 384.397 +     */
 384.398 +    public boolean contains(Object o) {
 384.399 +        return indexOf(o) != -1;
 384.400 +    }
 384.401 +
 384.402 +    /**
 384.403 +     * Returns an array containing all of the elements in this queue.
 384.404 +     * The elements are in no particular order.
 384.405 +     *
 384.406 +     * <p>The returned array will be "safe" in that no references to it are
 384.407 +     * maintained by this queue.  (In other words, this method must allocate
 384.408 +     * a new array).  The caller is thus free to modify the returned array.
 384.409 +     *
 384.410 +     * <p>This method acts as bridge between array-based and collection-based
 384.411 +     * APIs.
 384.412 +     *
 384.413 +     * @return an array containing all of the elements in this queue
 384.414 +     */
 384.415 +    public Object[] toArray() {
 384.416 +        return Arrays.copyOf(queue, size);
 384.417 +    }
 384.418 +
 384.419 +    /**
 384.420 +     * Returns an array containing all of the elements in this queue; the
 384.421 +     * runtime type of the returned array is that of the specified array.
 384.422 +     * The returned array elements are in no particular order.
 384.423 +     * If the queue fits in the specified array, it is returned therein.
 384.424 +     * Otherwise, a new array is allocated with the runtime type of the
 384.425 +     * specified array and the size of this queue.
 384.426 +     *
 384.427 +     * <p>If the queue fits in the specified array with room to spare
 384.428 +     * (i.e., the array has more elements than the queue), the element in
 384.429 +     * the array immediately following the end of the collection is set to
 384.430 +     * {@code null}.
 384.431 +     *
 384.432 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 384.433 +     * array-based and collection-based APIs.  Further, this method allows
 384.434 +     * precise control over the runtime type of the output array, and may,
 384.435 +     * under certain circumstances, be used to save allocation costs.
 384.436 +     *
 384.437 +     * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
 384.438 +     * The following code can be used to dump the queue into a newly
 384.439 +     * allocated array of <tt>String</tt>:
 384.440 +     *
 384.441 +     * <pre>
 384.442 +     *     String[] y = x.toArray(new String[0]);</pre>
 384.443 +     *
 384.444 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
 384.445 +     * <tt>toArray()</tt>.
 384.446 +     *
 384.447 +     * @param a the array into which the elements of the queue are to
 384.448 +     *          be stored, if it is big enough; otherwise, a new array of the
 384.449 +     *          same runtime type is allocated for this purpose.
 384.450 +     * @return an array containing all of the elements in this queue
 384.451 +     * @throws ArrayStoreException if the runtime type of the specified array
 384.452 +     *         is not a supertype of the runtime type of every element in
 384.453 +     *         this queue
 384.454 +     * @throws NullPointerException if the specified array is null
 384.455 +     */
 384.456 +    public <T> T[] toArray(T[] a) {
 384.457 +        if (a.length < size)
 384.458 +            // Make a new array of a's runtime type, but my contents:
 384.459 +            return (T[]) Arrays.copyOf(queue, size, a.getClass());
 384.460 +        System.arraycopy(queue, 0, a, 0, size);
 384.461 +        if (a.length > size)
 384.462 +            a[size] = null;
 384.463 +        return a;
 384.464 +    }
 384.465 +
 384.466 +    /**
 384.467 +     * Returns an iterator over the elements in this queue. The iterator
 384.468 +     * does not return the elements in any particular order.
 384.469 +     *
 384.470 +     * @return an iterator over the elements in this queue
 384.471 +     */
 384.472 +    public Iterator<E> iterator() {
 384.473 +        return new Itr();
 384.474 +    }
 384.475 +
 384.476 +    private final class Itr implements Iterator<E> {
 384.477 +        /**
 384.478 +         * Index (into queue array) of element to be returned by
 384.479 +         * subsequent call to next.
 384.480 +         */
 384.481 +        private int cursor = 0;
 384.482 +
 384.483 +        /**
 384.484 +         * Index of element returned by most recent call to next,
 384.485 +         * unless that element came from the forgetMeNot list.
 384.486 +         * Set to -1 if element is deleted by a call to remove.
 384.487 +         */
 384.488 +        private int lastRet = -1;
 384.489 +
 384.490 +        /**
 384.491 +         * A queue of elements that were moved from the unvisited portion of
 384.492 +         * the heap into the visited portion as a result of "unlucky" element
 384.493 +         * removals during the iteration.  (Unlucky element removals are those
 384.494 +         * that require a siftup instead of a siftdown.)  We must visit all of
 384.495 +         * the elements in this list to complete the iteration.  We do this
 384.496 +         * after we've completed the "normal" iteration.
 384.497 +         *
 384.498 +         * We expect that most iterations, even those involving removals,
 384.499 +         * will not need to store elements in this field.
 384.500 +         */
 384.501 +        private ArrayDeque<E> forgetMeNot = null;
 384.502 +
 384.503 +        /**
 384.504 +         * Element returned by the most recent call to next iff that
 384.505 +         * element was drawn from the forgetMeNot list.
 384.506 +         */
 384.507 +        private E lastRetElt = null;
 384.508 +
 384.509 +        /**
 384.510 +         * The modCount value that the iterator believes that the backing
 384.511 +         * Queue should have.  If this expectation is violated, the iterator
 384.512 +         * has detected concurrent modification.
 384.513 +         */
 384.514 +        private int expectedModCount = modCount;
 384.515 +
 384.516 +        public boolean hasNext() {
 384.517 +            return cursor < size ||
 384.518 +                (forgetMeNot != null && !forgetMeNot.isEmpty());
 384.519 +        }
 384.520 +
 384.521 +        public E next() {
 384.522 +            if (expectedModCount != modCount)
 384.523 +                throw new ConcurrentModificationException();
 384.524 +            if (cursor < size)
 384.525 +                return (E) queue[lastRet = cursor++];
 384.526 +            if (forgetMeNot != null) {
 384.527 +                lastRet = -1;
 384.528 +                lastRetElt = forgetMeNot.poll();
 384.529 +                if (lastRetElt != null)
 384.530 +                    return lastRetElt;
 384.531 +            }
 384.532 +            throw new NoSuchElementException();
 384.533 +        }
 384.534 +
 384.535 +        public void remove() {
 384.536 +            if (expectedModCount != modCount)
 384.537 +                throw new ConcurrentModificationException();
 384.538 +            if (lastRet != -1) {
 384.539 +                E moved = PriorityQueue.this.removeAt(lastRet);
 384.540 +                lastRet = -1;
 384.541 +                if (moved == null)
 384.542 +                    cursor--;
 384.543 +                else {
 384.544 +                    if (forgetMeNot == null)
 384.545 +                        forgetMeNot = new ArrayDeque<>();
 384.546 +                    forgetMeNot.add(moved);
 384.547 +                }
 384.548 +            } else if (lastRetElt != null) {
 384.549 +                PriorityQueue.this.removeEq(lastRetElt);
 384.550 +                lastRetElt = null;
 384.551 +            } else {
 384.552 +                throw new IllegalStateException();
 384.553 +            }
 384.554 +            expectedModCount = modCount;
 384.555 +        }
 384.556 +    }
 384.557 +
 384.558 +    public int size() {
 384.559 +        return size;
 384.560 +    }
 384.561 +
 384.562 +    /**
 384.563 +     * Removes all of the elements from this priority queue.
 384.564 +     * The queue will be empty after this call returns.
 384.565 +     */
 384.566 +    public void clear() {
 384.567 +        modCount++;
 384.568 +        for (int i = 0; i < size; i++)
 384.569 +            queue[i] = null;
 384.570 +        size = 0;
 384.571 +    }
 384.572 +
 384.573 +    public E poll() {
 384.574 +        if (size == 0)
 384.575 +            return null;
 384.576 +        int s = --size;
 384.577 +        modCount++;
 384.578 +        E result = (E) queue[0];
 384.579 +        E x = (E) queue[s];
 384.580 +        queue[s] = null;
 384.581 +        if (s != 0)
 384.582 +            siftDown(0, x);
 384.583 +        return result;
 384.584 +    }
 384.585 +
 384.586 +    /**
 384.587 +     * Removes the ith element from queue.
 384.588 +     *
 384.589 +     * Normally this method leaves the elements at up to i-1,
 384.590 +     * inclusive, untouched.  Under these circumstances, it returns
 384.591 +     * null.  Occasionally, in order to maintain the heap invariant,
 384.592 +     * it must swap a later element of the list with one earlier than
 384.593 +     * i.  Under these circumstances, this method returns the element
 384.594 +     * that was previously at the end of the list and is now at some
 384.595 +     * position before i. This fact is used by iterator.remove so as to
 384.596 +     * avoid missing traversing elements.
 384.597 +     */
 384.598 +    private E removeAt(int i) {
 384.599 +        assert i >= 0 && i < size;
 384.600 +        modCount++;
 384.601 +        int s = --size;
 384.602 +        if (s == i) // removed last element
 384.603 +            queue[i] = null;
 384.604 +        else {
 384.605 +            E moved = (E) queue[s];
 384.606 +            queue[s] = null;
 384.607 +            siftDown(i, moved);
 384.608 +            if (queue[i] == moved) {
 384.609 +                siftUp(i, moved);
 384.610 +                if (queue[i] != moved)
 384.611 +                    return moved;
 384.612 +            }
 384.613 +        }
 384.614 +        return null;
 384.615 +    }
 384.616 +
 384.617 +    /**
 384.618 +     * Inserts item x at position k, maintaining heap invariant by
 384.619 +     * promoting x up the tree until it is greater than or equal to
 384.620 +     * its parent, or is the root.
 384.621 +     *
 384.622 +     * To simplify and speed up coercions and comparisons. the
 384.623 +     * Comparable and Comparator versions are separated into different
 384.624 +     * methods that are otherwise identical. (Similarly for siftDown.)
 384.625 +     *
 384.626 +     * @param k the position to fill
 384.627 +     * @param x the item to insert
 384.628 +     */
 384.629 +    private void siftUp(int k, E x) {
 384.630 +        if (comparator != null)
 384.631 +            siftUpUsingComparator(k, x);
 384.632 +        else
 384.633 +            siftUpComparable(k, x);
 384.634 +    }
 384.635 +
 384.636 +    private void siftUpComparable(int k, E x) {
 384.637 +        Comparable<? super E> key = (Comparable<? super E>) x;
 384.638 +        while (k > 0) {
 384.639 +            int parent = (k - 1) >>> 1;
 384.640 +            Object e = queue[parent];
 384.641 +            if (key.compareTo((E) e) >= 0)
 384.642 +                break;
 384.643 +            queue[k] = e;
 384.644 +            k = parent;
 384.645 +        }
 384.646 +        queue[k] = key;
 384.647 +    }
 384.648 +
 384.649 +    private void siftUpUsingComparator(int k, E x) {
 384.650 +        while (k > 0) {
 384.651 +            int parent = (k - 1) >>> 1;
 384.652 +            Object e = queue[parent];
 384.653 +            if (comparator.compare(x, (E) e) >= 0)
 384.654 +                break;
 384.655 +            queue[k] = e;
 384.656 +            k = parent;
 384.657 +        }
 384.658 +        queue[k] = x;
 384.659 +    }
 384.660 +
 384.661 +    /**
 384.662 +     * Inserts item x at position k, maintaining heap invariant by
 384.663 +     * demoting x down the tree repeatedly until it is less than or
 384.664 +     * equal to its children or is a leaf.
 384.665 +     *
 384.666 +     * @param k the position to fill
 384.667 +     * @param x the item to insert
 384.668 +     */
 384.669 +    private void siftDown(int k, E x) {
 384.670 +        if (comparator != null)
 384.671 +            siftDownUsingComparator(k, x);
 384.672 +        else
 384.673 +            siftDownComparable(k, x);
 384.674 +    }
 384.675 +
 384.676 +    private void siftDownComparable(int k, E x) {
 384.677 +        Comparable<? super E> key = (Comparable<? super E>)x;
 384.678 +        int half = size >>> 1;        // loop while a non-leaf
 384.679 +        while (k < half) {
 384.680 +            int child = (k << 1) + 1; // assume left child is least
 384.681 +            Object c = queue[child];
 384.682 +            int right = child + 1;
 384.683 +            if (right < size &&
 384.684 +                ((Comparable<? super E>) c).compareTo((E) queue[right]) > 0)
 384.685 +                c = queue[child = right];
 384.686 +            if (key.compareTo((E) c) <= 0)
 384.687 +                break;
 384.688 +            queue[k] = c;
 384.689 +            k = child;
 384.690 +        }
 384.691 +        queue[k] = key;
 384.692 +    }
 384.693 +
 384.694 +    private void siftDownUsingComparator(int k, E x) {
 384.695 +        int half = size >>> 1;
 384.696 +        while (k < half) {
 384.697 +            int child = (k << 1) + 1;
 384.698 +            Object c = queue[child];
 384.699 +            int right = child + 1;
 384.700 +            if (right < size &&
 384.701 +                comparator.compare((E) c, (E) queue[right]) > 0)
 384.702 +                c = queue[child = right];
 384.703 +            if (comparator.compare(x, (E) c) <= 0)
 384.704 +                break;
 384.705 +            queue[k] = c;
 384.706 +            k = child;
 384.707 +        }
 384.708 +        queue[k] = x;
 384.709 +    }
 384.710 +
 384.711 +    /**
 384.712 +     * Establishes the heap invariant (described above) in the entire tree,
 384.713 +     * assuming nothing about the order of the elements prior to the call.
 384.714 +     */
 384.715 +    private void heapify() {
 384.716 +        for (int i = (size >>> 1) - 1; i >= 0; i--)
 384.717 +            siftDown(i, (E) queue[i]);
 384.718 +    }
 384.719 +
 384.720 +    /**
 384.721 +     * Returns the comparator used to order the elements in this
 384.722 +     * queue, or {@code null} if this queue is sorted according to
 384.723 +     * the {@linkplain Comparable natural ordering} of its elements.
 384.724 +     *
 384.725 +     * @return the comparator used to order this queue, or
 384.726 +     *         {@code null} if this queue is sorted according to the
 384.727 +     *         natural ordering of its elements
 384.728 +     */
 384.729 +    public Comparator<? super E> comparator() {
 384.730 +        return comparator;
 384.731 +    }
 384.732 +
 384.733 +
 384.734 +}
   385.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   385.2 +++ b/rt/emul/compact/src/main/java/java/util/Queue.java	Wed Feb 27 11:24:58 2013 +0100
   385.3 @@ -0,0 +1,218 @@
   385.4 +/*
   385.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   385.6 + *
   385.7 + * This code is free software; you can redistribute it and/or modify it
   385.8 + * under the terms of the GNU General Public License version 2 only, as
   385.9 + * published by the Free Software Foundation.  Oracle designates this
  385.10 + * particular file as subject to the "Classpath" exception as provided
  385.11 + * by Oracle in the LICENSE file that accompanied this code.
  385.12 + *
  385.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  385.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  385.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  385.16 + * version 2 for more details (a copy is included in the LICENSE file that
  385.17 + * accompanied this code).
  385.18 + *
  385.19 + * You should have received a copy of the GNU General Public License version
  385.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  385.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  385.22 + *
  385.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  385.24 + * or visit www.oracle.com if you need additional information or have any
  385.25 + * questions.
  385.26 + */
  385.27 +
  385.28 +/*
  385.29 + * This file is available under and governed by the GNU General Public
  385.30 + * License version 2 only, as published by the Free Software Foundation.
  385.31 + * However, the following notice accompanied the original version of this
  385.32 + * file:
  385.33 + *
  385.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
  385.35 + * Expert Group and released to the public domain, as explained at
  385.36 + * http://creativecommons.org/publicdomain/zero/1.0/
  385.37 + */
  385.38 +
  385.39 +package java.util;
  385.40 +
  385.41 +/**
  385.42 + * A collection designed for holding elements prior to processing.
  385.43 + * Besides basic {@link java.util.Collection Collection} operations,
  385.44 + * queues provide additional insertion, extraction, and inspection
  385.45 + * operations.  Each of these methods exists in two forms: one throws
  385.46 + * an exception if the operation fails, the other returns a special
  385.47 + * value (either <tt>null</tt> or <tt>false</tt>, depending on the
  385.48 + * operation).  The latter form of the insert operation is designed
  385.49 + * specifically for use with capacity-restricted <tt>Queue</tt>
  385.50 + * implementations; in most implementations, insert operations cannot
  385.51 + * fail.
  385.52 + *
  385.53 + * <p>
  385.54 + * <table BORDER CELLPADDING=3 CELLSPACING=1>
  385.55 + *  <tr>
  385.56 + *    <td></td>
  385.57 + *    <td ALIGN=CENTER><em>Throws exception</em></td>
  385.58 + *    <td ALIGN=CENTER><em>Returns special value</em></td>
  385.59 + *  </tr>
  385.60 + *  <tr>
  385.61 + *    <td><b>Insert</b></td>
  385.62 + *    <td>{@link #add add(e)}</td>
  385.63 + *    <td>{@link #offer offer(e)}</td>
  385.64 + *  </tr>
  385.65 + *  <tr>
  385.66 + *    <td><b>Remove</b></td>
  385.67 + *    <td>{@link #remove remove()}</td>
  385.68 + *    <td>{@link #poll poll()}</td>
  385.69 + *  </tr>
  385.70 + *  <tr>
  385.71 + *    <td><b>Examine</b></td>
  385.72 + *    <td>{@link #element element()}</td>
  385.73 + *    <td>{@link #peek peek()}</td>
  385.74 + *  </tr>
  385.75 + * </table>
  385.76 + *
  385.77 + * <p>Queues typically, but do not necessarily, order elements in a
  385.78 + * FIFO (first-in-first-out) manner.  Among the exceptions are
  385.79 + * priority queues, which order elements according to a supplied
  385.80 + * comparator, or the elements' natural ordering, and LIFO queues (or
  385.81 + * stacks) which order the elements LIFO (last-in-first-out).
  385.82 + * Whatever the ordering used, the <em>head</em> of the queue is that
  385.83 + * element which would be removed by a call to {@link #remove() } or
  385.84 + * {@link #poll()}.  In a FIFO queue, all new elements are inserted at
  385.85 + * the <em> tail</em> of the queue. Other kinds of queues may use
  385.86 + * different placement rules.  Every <tt>Queue</tt> implementation
  385.87 + * must specify its ordering properties.
  385.88 + *
  385.89 + * <p>The {@link #offer offer} method inserts an element if possible,
  385.90 + * otherwise returning <tt>false</tt>.  This differs from the {@link
  385.91 + * java.util.Collection#add Collection.add} method, which can fail to
  385.92 + * add an element only by throwing an unchecked exception.  The
  385.93 + * <tt>offer</tt> method is designed for use when failure is a normal,
  385.94 + * rather than exceptional occurrence, for example, in fixed-capacity
  385.95 + * (or &quot;bounded&quot;) queues.
  385.96 + *
  385.97 + * <p>The {@link #remove()} and {@link #poll()} methods remove and
  385.98 + * return the head of the queue.
  385.99 + * Exactly which element is removed from the queue is a
 385.100 + * function of the queue's ordering policy, which differs from
 385.101 + * implementation to implementation. The <tt>remove()</tt> and
 385.102 + * <tt>poll()</tt> methods differ only in their behavior when the
 385.103 + * queue is empty: the <tt>remove()</tt> method throws an exception,
 385.104 + * while the <tt>poll()</tt> method returns <tt>null</tt>.
 385.105 + *
 385.106 + * <p>The {@link #element()} and {@link #peek()} methods return, but do
 385.107 + * not remove, the head of the queue.
 385.108 + *
 385.109 + * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
 385.110 + * methods</i>, which are common in concurrent programming.  These methods,
 385.111 + * which wait for elements to appear or for space to become available, are
 385.112 + * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
 385.113 + * extends this interface.
 385.114 + *
 385.115 + * <p><tt>Queue</tt> implementations generally do not allow insertion
 385.116 + * of <tt>null</tt> elements, although some implementations, such as
 385.117 + * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
 385.118 + * Even in the implementations that permit it, <tt>null</tt> should
 385.119 + * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also
 385.120 + * used as a special return value by the <tt>poll</tt> method to
 385.121 + * indicate that the queue contains no elements.
 385.122 + *
 385.123 + * <p><tt>Queue</tt> implementations generally do not define
 385.124 + * element-based versions of methods <tt>equals</tt> and
 385.125 + * <tt>hashCode</tt> but instead inherit the identity based versions
 385.126 + * from class <tt>Object</tt>, because element-based equality is not
 385.127 + * always well-defined for queues with the same elements but different
 385.128 + * ordering properties.
 385.129 + *
 385.130 + *
 385.131 + * <p>This interface is a member of the
 385.132 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 385.133 + * Java Collections Framework</a>.
 385.134 + *
 385.135 + * @see java.util.Collection
 385.136 + * @see LinkedList
 385.137 + * @see PriorityQueue
 385.138 + * @see java.util.concurrent.LinkedBlockingQueue
 385.139 + * @see java.util.concurrent.BlockingQueue
 385.140 + * @see java.util.concurrent.ArrayBlockingQueue
 385.141 + * @see java.util.concurrent.LinkedBlockingQueue
 385.142 + * @see java.util.concurrent.PriorityBlockingQueue
 385.143 + * @since 1.5
 385.144 + * @author Doug Lea
 385.145 + * @param <E> the type of elements held in this collection
 385.146 + */
 385.147 +public interface Queue<E> extends Collection<E> {
 385.148 +    /**
 385.149 +     * Inserts the specified element into this queue if it is possible to do so
 385.150 +     * immediately without violating capacity restrictions, returning
 385.151 +     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
 385.152 +     * if no space is currently available.
 385.153 +     *
 385.154 +     * @param e the element to add
 385.155 +     * @return <tt>true</tt> (as specified by {@link Collection#add})
 385.156 +     * @throws IllegalStateException if the element cannot be added at this
 385.157 +     *         time due to capacity restrictions
 385.158 +     * @throws ClassCastException if the class of the specified element
 385.159 +     *         prevents it from being added to this queue
 385.160 +     * @throws NullPointerException if the specified element is null and
 385.161 +     *         this queue does not permit null elements
 385.162 +     * @throws IllegalArgumentException if some property of this element
 385.163 +     *         prevents it from being added to this queue
 385.164 +     */
 385.165 +    boolean add(E e);
 385.166 +
 385.167 +    /**
 385.168 +     * Inserts the specified element into this queue if it is possible to do
 385.169 +     * so immediately without violating capacity restrictions.
 385.170 +     * When using a capacity-restricted queue, this method is generally
 385.171 +     * preferable to {@link #add}, which can fail to insert an element only
 385.172 +     * by throwing an exception.
 385.173 +     *
 385.174 +     * @param e the element to add
 385.175 +     * @return <tt>true</tt> if the element was added to this queue, else
 385.176 +     *         <tt>false</tt>
 385.177 +     * @throws ClassCastException if the class of the specified element
 385.178 +     *         prevents it from being added to this queue
 385.179 +     * @throws NullPointerException if the specified element is null and
 385.180 +     *         this queue does not permit null elements
 385.181 +     * @throws IllegalArgumentException if some property of this element
 385.182 +     *         prevents it from being added to this queue
 385.183 +     */
 385.184 +    boolean offer(E e);
 385.185 +
 385.186 +    /**
 385.187 +     * Retrieves and removes the head of this queue.  This method differs
 385.188 +     * from {@link #poll poll} only in that it throws an exception if this
 385.189 +     * queue is empty.
 385.190 +     *
 385.191 +     * @return the head of this queue
 385.192 +     * @throws NoSuchElementException if this queue is empty
 385.193 +     */
 385.194 +    E remove();
 385.195 +
 385.196 +    /**
 385.197 +     * Retrieves and removes the head of this queue,
 385.198 +     * or returns <tt>null</tt> if this queue is empty.
 385.199 +     *
 385.200 +     * @return the head of this queue, or <tt>null</tt> if this queue is empty
 385.201 +     */
 385.202 +    E poll();
 385.203 +
 385.204 +    /**
 385.205 +     * Retrieves, but does not remove, the head of this queue.  This method
 385.206 +     * differs from {@link #peek peek} only in that it throws an exception
 385.207 +     * if this queue is empty.
 385.208 +     *
 385.209 +     * @return the head of this queue
 385.210 +     * @throws NoSuchElementException if this queue is empty
 385.211 +     */
 385.212 +    E element();
 385.213 +
 385.214 +    /**
 385.215 +     * Retrieves, but does not remove, the head of this queue,
 385.216 +     * or returns <tt>null</tt> if this queue is empty.
 385.217 +     *
 385.218 +     * @return the head of this queue, or <tt>null</tt> if this queue is empty
 385.219 +     */
 385.220 +    E peek();
 385.221 +}
   386.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   386.2 +++ b/rt/emul/compact/src/main/java/java/util/Random.java	Wed Feb 27 11:24:58 2013 +0100
   386.3 @@ -0,0 +1,503 @@
   386.4 +/*
   386.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
   386.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   386.7 + *
   386.8 + * This code is free software; you can redistribute it and/or modify it
   386.9 + * under the terms of the GNU General Public License version 2 only, as
  386.10 + * published by the Free Software Foundation.  Oracle designates this
  386.11 + * particular file as subject to the "Classpath" exception as provided
  386.12 + * by Oracle in the LICENSE file that accompanied this code.
  386.13 + *
  386.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  386.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  386.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  386.17 + * version 2 for more details (a copy is included in the LICENSE file that
  386.18 + * accompanied this code).
  386.19 + *
  386.20 + * You should have received a copy of the GNU General Public License version
  386.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  386.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  386.23 + *
  386.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  386.25 + * or visit www.oracle.com if you need additional information or have any
  386.26 + * questions.
  386.27 + */
  386.28 +
  386.29 +package java.util;
  386.30 +
  386.31 +import org.apidesign.bck2brwsr.emul.lang.System;
  386.32 +
  386.33 +/**
  386.34 + * An instance of this class is used to generate a stream of
  386.35 + * pseudorandom numbers. The class uses a 48-bit seed, which is
  386.36 + * modified using a linear congruential formula. (See Donald Knuth,
  386.37 + * <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
  386.38 + * <p>
  386.39 + * If two instances of {@code Random} are created with the same
  386.40 + * seed, and the same sequence of method calls is made for each, they
  386.41 + * will generate and return identical sequences of numbers. In order to
  386.42 + * guarantee this property, particular algorithms are specified for the
  386.43 + * class {@code Random}. Java implementations must use all the algorithms
  386.44 + * shown here for the class {@code Random}, for the sake of absolute
  386.45 + * portability of Java code. However, subclasses of class {@code Random}
  386.46 + * are permitted to use other algorithms, so long as they adhere to the
  386.47 + * general contracts for all the methods.
  386.48 + * <p>
  386.49 + * The algorithms implemented by class {@code Random} use a
  386.50 + * {@code protected} utility method that on each invocation can supply
  386.51 + * up to 32 pseudorandomly generated bits.
  386.52 + * <p>
  386.53 + * Many applications will find the method {@link Math#random} simpler to use.
  386.54 + *
  386.55 + * <p>Instances of {@code java.util.Random} are threadsafe.
  386.56 + * However, the concurrent use of the same {@code java.util.Random}
  386.57 + * instance across threads may encounter contention and consequent
  386.58 + * poor performance. Consider instead using
  386.59 + * {@link java.util.concurrent.ThreadLocalRandom} in multithreaded
  386.60 + * designs.
  386.61 + *
  386.62 + * <p>Instances of {@code java.util.Random} are not cryptographically
  386.63 + * secure.  Consider instead using {@link java.security.SecureRandom} to
  386.64 + * get a cryptographically secure pseudo-random number generator for use
  386.65 + * by security-sensitive applications.
  386.66 + *
  386.67 + * @author  Frank Yellin
  386.68 + * @since   1.0
  386.69 + */
  386.70 +public
  386.71 +class Random implements java.io.Serializable {
  386.72 +    /** use serialVersionUID from JDK 1.1 for interoperability */
  386.73 +    static final long serialVersionUID = 3905348978240129619L;
  386.74 +
  386.75 +    /**
  386.76 +     * The internal state associated with this pseudorandom number generator.
  386.77 +     * (The specs for the methods in this class describe the ongoing
  386.78 +     * computation of this value.)
  386.79 +     */
  386.80 +    private long seed;
  386.81 +
  386.82 +    private static final long multiplier = 0x5DEECE66DL;
  386.83 +    private static final long addend = 0xBL;
  386.84 +    private static final long mask = (1L << 48) - 1;
  386.85 +
  386.86 +    /**
  386.87 +     * Creates a new random number generator. This constructor sets
  386.88 +     * the seed of the random number generator to a value very likely
  386.89 +     * to be distinct from any other invocation of this constructor.
  386.90 +     */
  386.91 +    public Random() {
  386.92 +        this(seedUniquifier() ^ System.nanoTime());
  386.93 +    }
  386.94 +    
  386.95 +    private static synchronized long seedUniquifier() {
  386.96 +        // L'Ecuyer, "Tables of Linear Congruential Generators of
  386.97 +        // Different Sizes and Good Lattice Structure", 1999
  386.98 +        long current = seedUniquifier;
  386.99 +        long next = current * 181783497276652981L;
 386.100 +        seedUniquifier = next;
 386.101 +        return next;
 386.102 +    }
 386.103 +
 386.104 +    private static long seedUniquifier = 8682522807148012L;
 386.105 +
 386.106 +    /**
 386.107 +     * Creates a new random number generator using a single {@code long} seed.
 386.108 +     * The seed is the initial value of the internal state of the pseudorandom
 386.109 +     * number generator which is maintained by method {@link #next}.
 386.110 +     *
 386.111 +     * <p>The invocation {@code new Random(seed)} is equivalent to:
 386.112 +     *  <pre> {@code
 386.113 +     * Random rnd = new Random();
 386.114 +     * rnd.setSeed(seed);}</pre>
 386.115 +     *
 386.116 +     * @param seed the initial seed
 386.117 +     * @see   #setSeed(long)
 386.118 +     */
 386.119 +    public Random(long seed) {
 386.120 +        this.seed = initialScramble(seed);
 386.121 +    }
 386.122 +
 386.123 +    private static long initialScramble(long seed) {
 386.124 +        return (seed ^ multiplier) & mask;
 386.125 +    }
 386.126 +
 386.127 +    /**
 386.128 +     * Sets the seed of this random number generator using a single
 386.129 +     * {@code long} seed. The general contract of {@code setSeed} is
 386.130 +     * that it alters the state of this random number generator object
 386.131 +     * so as to be in exactly the same state as if it had just been
 386.132 +     * created with the argument {@code seed} as a seed. The method
 386.133 +     * {@code setSeed} is implemented by class {@code Random} by
 386.134 +     * atomically updating the seed to
 386.135 +     *  <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre>
 386.136 +     * and clearing the {@code haveNextNextGaussian} flag used by {@link
 386.137 +     * #nextGaussian}.
 386.138 +     *
 386.139 +     * <p>The implementation of {@code setSeed} by class {@code Random}
 386.140 +     * happens to use only 48 bits of the given seed. In general, however,
 386.141 +     * an overriding method may use all 64 bits of the {@code long}
 386.142 +     * argument as a seed value.
 386.143 +     *
 386.144 +     * @param seed the initial seed
 386.145 +     */
 386.146 +    synchronized public void setSeed(long seed) {
 386.147 +        this.seed = initialScramble(seed);
 386.148 +        haveNextNextGaussian = false;
 386.149 +    }
 386.150 +
 386.151 +    /**
 386.152 +     * Generates the next pseudorandom number. Subclasses should
 386.153 +     * override this, as this is used by all other methods.
 386.154 +     *
 386.155 +     * <p>The general contract of {@code next} is that it returns an
 386.156 +     * {@code int} value and if the argument {@code bits} is between
 386.157 +     * {@code 1} and {@code 32} (inclusive), then that many low-order
 386.158 +     * bits of the returned value will be (approximately) independently
 386.159 +     * chosen bit values, each of which is (approximately) equally
 386.160 +     * likely to be {@code 0} or {@code 1}. The method {@code next} is
 386.161 +     * implemented by class {@code Random} by atomically updating the seed to
 386.162 +     *  <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
 386.163 +     * and returning
 386.164 +     *  <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
 386.165 +     *
 386.166 +     * This is a linear congruential pseudorandom number generator, as
 386.167 +     * defined by D. H. Lehmer and described by Donald E. Knuth in
 386.168 +     * <i>The Art of Computer Programming,</i> Volume 3:
 386.169 +     * <i>Seminumerical Algorithms</i>, section 3.2.1.
 386.170 +     *
 386.171 +     * @param  bits random bits
 386.172 +     * @return the next pseudorandom value from this random number
 386.173 +     *         generator's sequence
 386.174 +     * @since  1.1
 386.175 +     */
 386.176 +    protected synchronized int next(int bits) {
 386.177 +        long oldseed, nextseed;
 386.178 +        long seed = this.seed;
 386.179 +        oldseed = seed;
 386.180 +        nextseed = (oldseed * multiplier + addend) & mask;
 386.181 +        this.seed = nextseed;
 386.182 +        return (int)(nextseed >>> (48 - bits));
 386.183 +    }
 386.184 +
 386.185 +    /**
 386.186 +     * Generates random bytes and places them into a user-supplied
 386.187 +     * byte array.  The number of random bytes produced is equal to
 386.188 +     * the length of the byte array.
 386.189 +     *
 386.190 +     * <p>The method {@code nextBytes} is implemented by class {@code Random}
 386.191 +     * as if by:
 386.192 +     *  <pre> {@code
 386.193 +     * public void nextBytes(byte[] bytes) {
 386.194 +     *   for (int i = 0; i < bytes.length; )
 386.195 +     *     for (int rnd = nextInt(), n = Math.min(bytes.length - i, 4);
 386.196 +     *          n-- > 0; rnd >>= 8)
 386.197 +     *       bytes[i++] = (byte)rnd;
 386.198 +     * }}</pre>
 386.199 +     *
 386.200 +     * @param  bytes the byte array to fill with random bytes
 386.201 +     * @throws NullPointerException if the byte array is null
 386.202 +     * @since  1.1
 386.203 +     */
 386.204 +    public void nextBytes(byte[] bytes) {
 386.205 +        for (int i = 0, len = bytes.length; i < len; )
 386.206 +            for (int rnd = nextInt(),
 386.207 +                     n = Math.min(len - i, Integer.SIZE/Byte.SIZE);
 386.208 +                 n-- > 0; rnd >>= Byte.SIZE)
 386.209 +                bytes[i++] = (byte)rnd;
 386.210 +    }
 386.211 +
 386.212 +    /**
 386.213 +     * Returns the next pseudorandom, uniformly distributed {@code int}
 386.214 +     * value from this random number generator's sequence. The general
 386.215 +     * contract of {@code nextInt} is that one {@code int} value is
 386.216 +     * pseudorandomly generated and returned. All 2<font size="-1"><sup>32
 386.217 +     * </sup></font> possible {@code int} values are produced with
 386.218 +     * (approximately) equal probability.
 386.219 +     *
 386.220 +     * <p>The method {@code nextInt} is implemented by class {@code Random}
 386.221 +     * as if by:
 386.222 +     *  <pre> {@code
 386.223 +     * public int nextInt() {
 386.224 +     *   return next(32);
 386.225 +     * }}</pre>
 386.226 +     *
 386.227 +     * @return the next pseudorandom, uniformly distributed {@code int}
 386.228 +     *         value from this random number generator's sequence
 386.229 +     */
 386.230 +    public int nextInt() {
 386.231 +        return next(32);
 386.232 +    }
 386.233 +
 386.234 +    /**
 386.235 +     * Returns a pseudorandom, uniformly distributed {@code int} value
 386.236 +     * between 0 (inclusive) and the specified value (exclusive), drawn from
 386.237 +     * this random number generator's sequence.  The general contract of
 386.238 +     * {@code nextInt} is that one {@code int} value in the specified range
 386.239 +     * is pseudorandomly generated and returned.  All {@code n} possible
 386.240 +     * {@code int} values are produced with (approximately) equal
 386.241 +     * probability.  The method {@code nextInt(int n)} is implemented by
 386.242 +     * class {@code Random} as if by:
 386.243 +     *  <pre> {@code
 386.244 +     * public int nextInt(int n) {
 386.245 +     *   if (n <= 0)
 386.246 +     *     throw new IllegalArgumentException("n must be positive");
 386.247 +     *
 386.248 +     *   if ((n & -n) == n)  // i.e., n is a power of 2
 386.249 +     *     return (int)((n * (long)next(31)) >> 31);
 386.250 +     *
 386.251 +     *   int bits, val;
 386.252 +     *   do {
 386.253 +     *       bits = next(31);
 386.254 +     *       val = bits % n;
 386.255 +     *   } while (bits - val + (n-1) < 0);
 386.256 +     *   return val;
 386.257 +     * }}</pre>
 386.258 +     *
 386.259 +     * <p>The hedge "approximately" is used in the foregoing description only
 386.260 +     * because the next method is only approximately an unbiased source of
 386.261 +     * independently chosen bits.  If it were a perfect source of randomly
 386.262 +     * chosen bits, then the algorithm shown would choose {@code int}
 386.263 +     * values from the stated range with perfect uniformity.
 386.264 +     * <p>
 386.265 +     * The algorithm is slightly tricky.  It rejects values that would result
 386.266 +     * in an uneven distribution (due to the fact that 2^31 is not divisible
 386.267 +     * by n). The probability of a value being rejected depends on n.  The
 386.268 +     * worst case is n=2^30+1, for which the probability of a reject is 1/2,
 386.269 +     * and the expected number of iterations before the loop terminates is 2.
 386.270 +     * <p>
 386.271 +     * The algorithm treats the case where n is a power of two specially: it
 386.272 +     * returns the correct number of high-order bits from the underlying
 386.273 +     * pseudo-random number generator.  In the absence of special treatment,
 386.274 +     * the correct number of <i>low-order</i> bits would be returned.  Linear
 386.275 +     * congruential pseudo-random number generators such as the one
 386.276 +     * implemented by this class are known to have short periods in the
 386.277 +     * sequence of values of their low-order bits.  Thus, this special case
 386.278 +     * greatly increases the length of the sequence of values returned by
 386.279 +     * successive calls to this method if n is a small power of two.
 386.280 +     *
 386.281 +     * @param n the bound on the random number to be returned.  Must be
 386.282 +     *        positive.
 386.283 +     * @return the next pseudorandom, uniformly distributed {@code int}
 386.284 +     *         value between {@code 0} (inclusive) and {@code n} (exclusive)
 386.285 +     *         from this random number generator's sequence
 386.286 +     * @throws IllegalArgumentException if n is not positive
 386.287 +     * @since 1.2
 386.288 +     */
 386.289 +
 386.290 +    public int nextInt(int n) {
 386.291 +        if (n <= 0)
 386.292 +            throw new IllegalArgumentException("n must be positive");
 386.293 +
 386.294 +        if ((n & -n) == n)  // i.e., n is a power of 2
 386.295 +            return (int)((n * (long)next(31)) >> 31);
 386.296 +
 386.297 +        int bits, val;
 386.298 +        do {
 386.299 +            bits = next(31);
 386.300 +            val = bits % n;
 386.301 +        } while (bits - val + (n-1) < 0);
 386.302 +        return val;
 386.303 +    }
 386.304 +
 386.305 +    /**
 386.306 +     * Returns the next pseudorandom, uniformly distributed {@code long}
 386.307 +     * value from this random number generator's sequence. The general
 386.308 +     * contract of {@code nextLong} is that one {@code long} value is
 386.309 +     * pseudorandomly generated and returned.
 386.310 +     *
 386.311 +     * <p>The method {@code nextLong} is implemented by class {@code Random}
 386.312 +     * as if by:
 386.313 +     *  <pre> {@code
 386.314 +     * public long nextLong() {
 386.315 +     *   return ((long)next(32) << 32) + next(32);
 386.316 +     * }}</pre>
 386.317 +     *
 386.318 +     * Because class {@code Random} uses a seed with only 48 bits,
 386.319 +     * this algorithm will not return all possible {@code long} values.
 386.320 +     *
 386.321 +     * @return the next pseudorandom, uniformly distributed {@code long}
 386.322 +     *         value from this random number generator's sequence
 386.323 +     */
 386.324 +    public long nextLong() {
 386.325 +        // it's okay that the bottom word remains signed.
 386.326 +        return ((long)(next(32)) << 32) + next(32);
 386.327 +    }
 386.328 +
 386.329 +    /**
 386.330 +     * Returns the next pseudorandom, uniformly distributed
 386.331 +     * {@code boolean} value from this random number generator's
 386.332 +     * sequence. The general contract of {@code nextBoolean} is that one
 386.333 +     * {@code boolean} value is pseudorandomly generated and returned.  The
 386.334 +     * values {@code true} and {@code false} are produced with
 386.335 +     * (approximately) equal probability.
 386.336 +     *
 386.337 +     * <p>The method {@code nextBoolean} is implemented by class {@code Random}
 386.338 +     * as if by:
 386.339 +     *  <pre> {@code
 386.340 +     * public boolean nextBoolean() {
 386.341 +     *   return next(1) != 0;
 386.342 +     * }}</pre>
 386.343 +     *
 386.344 +     * @return the next pseudorandom, uniformly distributed
 386.345 +     *         {@code boolean} value from this random number generator's
 386.346 +     *         sequence
 386.347 +     * @since 1.2
 386.348 +     */
 386.349 +    public boolean nextBoolean() {
 386.350 +        return next(1) != 0;
 386.351 +    }
 386.352 +
 386.353 +    /**
 386.354 +     * Returns the next pseudorandom, uniformly distributed {@code float}
 386.355 +     * value between {@code 0.0} and {@code 1.0} from this random
 386.356 +     * number generator's sequence.
 386.357 +     *
 386.358 +     * <p>The general contract of {@code nextFloat} is that one
 386.359 +     * {@code float} value, chosen (approximately) uniformly from the
 386.360 +     * range {@code 0.0f} (inclusive) to {@code 1.0f} (exclusive), is
 386.361 +     * pseudorandomly generated and returned. All 2<font
 386.362 +     * size="-1"><sup>24</sup></font> possible {@code float} values
 386.363 +     * of the form <i>m&nbsp;x&nbsp</i>2<font
 386.364 +     * size="-1"><sup>-24</sup></font>, where <i>m</i> is a positive
 386.365 +     * integer less than 2<font size="-1"><sup>24</sup> </font>, are
 386.366 +     * produced with (approximately) equal probability.
 386.367 +     *
 386.368 +     * <p>The method {@code nextFloat} is implemented by class {@code Random}
 386.369 +     * as if by:
 386.370 +     *  <pre> {@code
 386.371 +     * public float nextFloat() {
 386.372 +     *   return next(24) / ((float)(1 << 24));
 386.373 +     * }}</pre>
 386.374 +     *
 386.375 +     * <p>The hedge "approximately" is used in the foregoing description only
 386.376 +     * because the next method is only approximately an unbiased source of
 386.377 +     * independently chosen bits. If it were a perfect source of randomly
 386.378 +     * chosen bits, then the algorithm shown would choose {@code float}
 386.379 +     * values from the stated range with perfect uniformity.<p>
 386.380 +     * [In early versions of Java, the result was incorrectly calculated as:
 386.381 +     *  <pre> {@code
 386.382 +     *   return next(30) / ((float)(1 << 30));}</pre>
 386.383 +     * This might seem to be equivalent, if not better, but in fact it
 386.384 +     * introduced a slight nonuniformity because of the bias in the rounding
 386.385 +     * of floating-point numbers: it was slightly more likely that the
 386.386 +     * low-order bit of the significand would be 0 than that it would be 1.]
 386.387 +     *
 386.388 +     * @return the next pseudorandom, uniformly distributed {@code float}
 386.389 +     *         value between {@code 0.0} and {@code 1.0} from this
 386.390 +     *         random number generator's sequence
 386.391 +     */
 386.392 +    public float nextFloat() {
 386.393 +        return next(24) / ((float)(1 << 24));
 386.394 +    }
 386.395 +
 386.396 +    /**
 386.397 +     * Returns the next pseudorandom, uniformly distributed
 386.398 +     * {@code double} value between {@code 0.0} and
 386.399 +     * {@code 1.0} from this random number generator's sequence.
 386.400 +     *
 386.401 +     * <p>The general contract of {@code nextDouble} is that one
 386.402 +     * {@code double} value, chosen (approximately) uniformly from the
 386.403 +     * range {@code 0.0d} (inclusive) to {@code 1.0d} (exclusive), is
 386.404 +     * pseudorandomly generated and returned.
 386.405 +     *
 386.406 +     * <p>The method {@code nextDouble} is implemented by class {@code Random}
 386.407 +     * as if by:
 386.408 +     *  <pre> {@code
 386.409 +     * public double nextDouble() {
 386.410 +     *   return (((long)next(26) << 27) + next(27))
 386.411 +     *     / (double)(1L << 53);
 386.412 +     * }}</pre>
 386.413 +     *
 386.414 +     * <p>The hedge "approximately" is used in the foregoing description only
 386.415 +     * because the {@code next} method is only approximately an unbiased
 386.416 +     * source of independently chosen bits. If it were a perfect source of
 386.417 +     * randomly chosen bits, then the algorithm shown would choose
 386.418 +     * {@code double} values from the stated range with perfect uniformity.
 386.419 +     * <p>[In early versions of Java, the result was incorrectly calculated as:
 386.420 +     *  <pre> {@code
 386.421 +     *   return (((long)next(27) << 27) + next(27))
 386.422 +     *     / (double)(1L << 54);}</pre>
 386.423 +     * This might seem to be equivalent, if not better, but in fact it
 386.424 +     * introduced a large nonuniformity because of the bias in the rounding
 386.425 +     * of floating-point numbers: it was three times as likely that the
 386.426 +     * low-order bit of the significand would be 0 than that it would be 1!
 386.427 +     * This nonuniformity probably doesn't matter much in practice, but we
 386.428 +     * strive for perfection.]
 386.429 +     *
 386.430 +     * @return the next pseudorandom, uniformly distributed {@code double}
 386.431 +     *         value between {@code 0.0} and {@code 1.0} from this
 386.432 +     *         random number generator's sequence
 386.433 +     * @see Math#random
 386.434 +     */
 386.435 +    public double nextDouble() {
 386.436 +        return (((long)(next(26)) << 27) + next(27))
 386.437 +            / (double)(1L << 53);
 386.438 +    }
 386.439 +
 386.440 +    private double nextNextGaussian;
 386.441 +    private boolean haveNextNextGaussian = false;
 386.442 +
 386.443 +    /**
 386.444 +     * Returns the next pseudorandom, Gaussian ("normally") distributed
 386.445 +     * {@code double} value with mean {@code 0.0} and standard
 386.446 +     * deviation {@code 1.0} from this random number generator's sequence.
 386.447 +     * <p>
 386.448 +     * The general contract of {@code nextGaussian} is that one
 386.449 +     * {@code double} value, chosen from (approximately) the usual
 386.450 +     * normal distribution with mean {@code 0.0} and standard deviation
 386.451 +     * {@code 1.0}, is pseudorandomly generated and returned.
 386.452 +     *
 386.453 +     * <p>The method {@code nextGaussian} is implemented by class
 386.454 +     * {@code Random} as if by a threadsafe version of the following:
 386.455 +     *  <pre> {@code
 386.456 +     * private double nextNextGaussian;
 386.457 +     * private boolean haveNextNextGaussian = false;
 386.458 +     *
 386.459 +     * public double nextGaussian() {
 386.460 +     *   if (haveNextNextGaussian) {
 386.461 +     *     haveNextNextGaussian = false;
 386.462 +     *     return nextNextGaussian;
 386.463 +     *   } else {
 386.464 +     *     double v1, v2, s;
 386.465 +     *     do {
 386.466 +     *       v1 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
 386.467 +     *       v2 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
 386.468 +     *       s = v1 * v1 + v2 * v2;
 386.469 +     *     } while (s >= 1 || s == 0);
 386.470 +     *     double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s);
 386.471 +     *     nextNextGaussian = v2 * multiplier;
 386.472 +     *     haveNextNextGaussian = true;
 386.473 +     *     return v1 * multiplier;
 386.474 +     *   }
 386.475 +     * }}</pre>
 386.476 +     * This uses the <i>polar method</i> of G. E. P. Box, M. E. Muller, and
 386.477 +     * G. Marsaglia, as described by Donald E. Knuth in <i>The Art of
 386.478 +     * Computer Programming</i>, Volume 3: <i>Seminumerical Algorithms</i>,
 386.479 +     * section 3.4.1, subsection C, algorithm P. Note that it generates two
 386.480 +     * independent values at the cost of only one call to {@code StrictMath.log}
 386.481 +     * and one call to {@code StrictMath.sqrt}.
 386.482 +     *
 386.483 +     * @return the next pseudorandom, Gaussian ("normally") distributed
 386.484 +     *         {@code double} value with mean {@code 0.0} and
 386.485 +     *         standard deviation {@code 1.0} from this random number
 386.486 +     *         generator's sequence
 386.487 +     */
 386.488 +    synchronized public double nextGaussian() {
 386.489 +        // See Knuth, ACP, Section 3.4.1 Algorithm C.
 386.490 +        if (haveNextNextGaussian) {
 386.491 +            haveNextNextGaussian = false;
 386.492 +            return nextNextGaussian;
 386.493 +        } else {
 386.494 +            double v1, v2, s;
 386.495 +            do {
 386.496 +                v1 = 2 * nextDouble() - 1; // between -1 and 1
 386.497 +                v2 = 2 * nextDouble() - 1; // between -1 and 1
 386.498 +                s = v1 * v1 + v2 * v2;
 386.499 +            } while (s >= 1 || s == 0);
 386.500 +            double multiplier = Math.sqrt(-2 * Math.log(s)/s);
 386.501 +            nextNextGaussian = v2 * multiplier;
 386.502 +            haveNextNextGaussian = true;
 386.503 +            return v1 * multiplier;
 386.504 +        }
 386.505 +    }
 386.506 +}
   387.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   387.2 +++ b/rt/emul/compact/src/main/java/java/util/RandomAccess.java	Wed Feb 27 11:24:58 2013 +0100
   387.3 @@ -0,0 +1,68 @@
   387.4 +/*
   387.5 + * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
   387.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   387.7 + *
   387.8 + * This code is free software; you can redistribute it and/or modify it
   387.9 + * under the terms of the GNU General Public License version 2 only, as
  387.10 + * published by the Free Software Foundation.  Oracle designates this
  387.11 + * particular file as subject to the "Classpath" exception as provided
  387.12 + * by Oracle in the LICENSE file that accompanied this code.
  387.13 + *
  387.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  387.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  387.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  387.17 + * version 2 for more details (a copy is included in the LICENSE file that
  387.18 + * accompanied this code).
  387.19 + *
  387.20 + * You should have received a copy of the GNU General Public License version
  387.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  387.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  387.23 + *
  387.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  387.25 + * or visit www.oracle.com if you need additional information or have any
  387.26 + * questions.
  387.27 + */
  387.28 +
  387.29 +package java.util;
  387.30 +
  387.31 +/**
  387.32 + * Marker interface used by <tt>List</tt> implementations to indicate that
  387.33 + * they support fast (generally constant time) random access.  The primary
  387.34 + * purpose of this interface is to allow generic algorithms to alter their
  387.35 + * behavior to provide good performance when applied to either random or
  387.36 + * sequential access lists.
  387.37 + *
  387.38 + * <p>The best algorithms for manipulating random access lists (such as
  387.39 + * <tt>ArrayList</tt>) can produce quadratic behavior when applied to
  387.40 + * sequential access lists (such as <tt>LinkedList</tt>).  Generic list
  387.41 + * algorithms are encouraged to check whether the given list is an
  387.42 + * <tt>instanceof</tt> this interface before applying an algorithm that would
  387.43 + * provide poor performance if it were applied to a sequential access list,
  387.44 + * and to alter their behavior if necessary to guarantee acceptable
  387.45 + * performance.
  387.46 + *
  387.47 + * <p>It is recognized that the distinction between random and sequential
  387.48 + * access is often fuzzy.  For example, some <tt>List</tt> implementations
  387.49 + * provide asymptotically linear access times if they get huge, but constant
  387.50 + * access times in practice.  Such a <tt>List</tt> implementation
  387.51 + * should generally implement this interface.  As a rule of thumb, a
  387.52 + * <tt>List</tt> implementation should implement this interface if,
  387.53 + * for typical instances of the class, this loop:
  387.54 + * <pre>
  387.55 + *     for (int i=0, n=list.size(); i &lt; n; i++)
  387.56 + *         list.get(i);
  387.57 + * </pre>
  387.58 + * runs faster than this loop:
  387.59 + * <pre>
  387.60 + *     for (Iterator i=list.iterator(); i.hasNext(); )
  387.61 + *         i.next();
  387.62 + * </pre>
  387.63 + *
  387.64 + * <p>This interface is a member of the
  387.65 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  387.66 + * Java Collections Framework</a>.
  387.67 + *
  387.68 + * @since 1.4
  387.69 + */
  387.70 +public interface RandomAccess {
  387.71 +}
   388.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   388.2 +++ b/rt/emul/compact/src/main/java/java/util/ServiceConfigurationError.java	Wed Feb 27 11:24:58 2013 +0100
   388.3 @@ -0,0 +1,87 @@
   388.4 +/*
   388.5 + * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
   388.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   388.7 + *
   388.8 + * This code is free software; you can redistribute it and/or modify it
   388.9 + * under the terms of the GNU General Public License version 2 only, as
  388.10 + * published by the Free Software Foundation.  Oracle designates this
  388.11 + * particular file as subject to the "Classpath" exception as provided
  388.12 + * by Oracle in the LICENSE file that accompanied this code.
  388.13 + *
  388.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  388.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  388.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  388.17 + * version 2 for more details (a copy is included in the LICENSE file that
  388.18 + * accompanied this code).
  388.19 + *
  388.20 + * You should have received a copy of the GNU General Public License version
  388.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  388.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  388.23 + *
  388.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  388.25 + * or visit www.oracle.com if you need additional information or have any
  388.26 + * questions.
  388.27 + */
  388.28 +
  388.29 +package java.util;
  388.30 +
  388.31 +
  388.32 +/**
  388.33 + * Error thrown when something goes wrong while loading a service provider.
  388.34 + *
  388.35 + * <p> This error will be thrown in the following situations:
  388.36 + *
  388.37 + * <ul>
  388.38 + *
  388.39 + *   <li> The format of a provider-configuration file violates the <a
  388.40 + *   href="ServiceLoader.html#format">specification</a>; </li>
  388.41 + *
  388.42 + *   <li> An {@link java.io.IOException IOException} occurs while reading a
  388.43 + *   provider-configuration file; </li>
  388.44 + *
  388.45 + *   <li> A concrete provider class named in a provider-configuration file
  388.46 + *   cannot be found; </li>
  388.47 + *
  388.48 + *   <li> A concrete provider class is not a subclass of the service class;
  388.49 + *   </li>
  388.50 + *
  388.51 + *   <li> A concrete provider class cannot be instantiated; or
  388.52 + *
  388.53 + *   <li> Some other kind of error occurs. </li>
  388.54 + *
  388.55 + * </ul>
  388.56 + *
  388.57 + *
  388.58 + * @author Mark Reinhold
  388.59 + * @since 1.6
  388.60 + */
  388.61 +
  388.62 +public class ServiceConfigurationError
  388.63 +    extends Error
  388.64 +{
  388.65 +
  388.66 +    private static final long serialVersionUID = 74132770414881L;
  388.67 +
  388.68 +    /**
  388.69 +     * Constructs a new instance with the specified message.
  388.70 +     *
  388.71 +     * @param  msg  The message, or <tt>null</tt> if there is no message
  388.72 +     *
  388.73 +     */
  388.74 +    public ServiceConfigurationError(String msg) {
  388.75 +        super(msg);
  388.76 +    }
  388.77 +
  388.78 +    /**
  388.79 +     * Constructs a new instance with the specified message and cause.
  388.80 +     *
  388.81 +     * @param  msg  The message, or <tt>null</tt> if there is no message
  388.82 +     *
  388.83 +     * @param  cause  The cause, or <tt>null</tt> if the cause is nonexistent
  388.84 +     *                or unknown
  388.85 +     */
  388.86 +    public ServiceConfigurationError(String msg, Throwable cause) {
  388.87 +        super(msg, cause);
  388.88 +    }
  388.89 +
  388.90 +}
   389.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   389.2 +++ b/rt/emul/compact/src/main/java/java/util/ServiceLoader.java	Wed Feb 27 11:24:58 2013 +0100
   389.3 @@ -0,0 +1,538 @@
   389.4 +/*
   389.5 + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   389.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   389.7 + *
   389.8 + * This code is free software; you can redistribute it and/or modify it
   389.9 + * under the terms of the GNU General Public License version 2 only, as
  389.10 + * published by the Free Software Foundation.  Oracle designates this
  389.11 + * particular file as subject to the "Classpath" exception as provided
  389.12 + * by Oracle in the LICENSE file that accompanied this code.
  389.13 + *
  389.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  389.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  389.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  389.17 + * version 2 for more details (a copy is included in the LICENSE file that
  389.18 + * accompanied this code).
  389.19 + *
  389.20 + * You should have received a copy of the GNU General Public License version
  389.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  389.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  389.23 + *
  389.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  389.25 + * or visit www.oracle.com if you need additional information or have any
  389.26 + * questions.
  389.27 + */
  389.28 +
  389.29 +package java.util;
  389.30 +
  389.31 +import java.io.BufferedReader;
  389.32 +import java.io.IOException;
  389.33 +import java.io.InputStream;
  389.34 +import java.io.InputStreamReader;
  389.35 +import java.net.URL;
  389.36 +import java.util.ArrayList;
  389.37 +import java.util.Enumeration;
  389.38 +import java.util.Iterator;
  389.39 +import java.util.List;
  389.40 +import java.util.NoSuchElementException;
  389.41 +
  389.42 +
  389.43 +/**
  389.44 + * A simple service-provider loading facility.
  389.45 + *
  389.46 + * <p> A <i>service</i> is a well-known set of interfaces and (usually
  389.47 + * abstract) classes.  A <i>service provider</i> is a specific implementation
  389.48 + * of a service.  The classes in a provider typically implement the interfaces
  389.49 + * and subclass the classes defined in the service itself.  Service providers
  389.50 + * can be installed in an implementation of the Java platform in the form of
  389.51 + * extensions, that is, jar files placed into any of the usual extension
  389.52 + * directories.  Providers can also be made available by adding them to the
  389.53 + * application's class path or by some other platform-specific means.
  389.54 + *
  389.55 + * <p> For the purpose of loading, a service is represented by a single type,
  389.56 + * that is, a single interface or abstract class.  (A concrete class can be
  389.57 + * used, but this is not recommended.)  A provider of a given service contains
  389.58 + * one or more concrete classes that extend this <i>service type</i> with data
  389.59 + * and code specific to the provider.  The <i>provider class</i> is typically
  389.60 + * not the entire provider itself but rather a proxy which contains enough
  389.61 + * information to decide whether the provider is able to satisfy a particular
  389.62 + * request together with code that can create the actual provider on demand.
  389.63 + * The details of provider classes tend to be highly service-specific; no
  389.64 + * single class or interface could possibly unify them, so no such type is
  389.65 + * defined here.  The only requirement enforced by this facility is that
  389.66 + * provider classes must have a zero-argument constructor so that they can be
  389.67 + * instantiated during loading.
  389.68 + *
  389.69 + * <p><a name="format"> A service provider is identified by placing a
  389.70 + * <i>provider-configuration file</i> in the resource directory
  389.71 + * <tt>META-INF/services</tt>.  The file's name is the fully-qualified <a
  389.72 + * href="../lang/ClassLoader.html#name">binary name</a> of the service's type.
  389.73 + * The file contains a list of fully-qualified binary names of concrete
  389.74 + * provider classes, one per line.  Space and tab characters surrounding each
  389.75 + * name, as well as blank lines, are ignored.  The comment character is
  389.76 + * <tt>'#'</tt> (<tt>'&#92;u0023'</tt>, <font size="-1">NUMBER SIGN</font>); on
  389.77 + * each line all characters following the first comment character are ignored.
  389.78 + * The file must be encoded in UTF-8.
  389.79 + *
  389.80 + * <p> If a particular concrete provider class is named in more than one
  389.81 + * configuration file, or is named in the same configuration file more than
  389.82 + * once, then the duplicates are ignored.  The configuration file naming a
  389.83 + * particular provider need not be in the same jar file or other distribution
  389.84 + * unit as the provider itself.  The provider must be accessible from the same
  389.85 + * class loader that was initially queried to locate the configuration file;
  389.86 + * note that this is not necessarily the class loader from which the file was
  389.87 + * actually loaded.
  389.88 + *
  389.89 + * <p> Providers are located and instantiated lazily, that is, on demand.  A
  389.90 + * service loader maintains a cache of the providers that have been loaded so
  389.91 + * far.  Each invocation of the {@link #iterator iterator} method returns an
  389.92 + * iterator that first yields all of the elements of the cache, in
  389.93 + * instantiation order, and then lazily locates and instantiates any remaining
  389.94 + * providers, adding each one to the cache in turn.  The cache can be cleared
  389.95 + * via the {@link #reload reload} method.
  389.96 + *
  389.97 + * <p> Service loaders always execute in the security context of the caller.
  389.98 + * Trusted system code should typically invoke the methods in this class, and
  389.99 + * the methods of the iterators which they return, from within a privileged
 389.100 + * security context.
 389.101 + *
 389.102 + * <p> Instances of this class are not safe for use by multiple concurrent
 389.103 + * threads.
 389.104 + *
 389.105 + * <p> Unless otherwise specified, passing a <tt>null</tt> argument to any
 389.106 + * method in this class will cause a {@link NullPointerException} to be thrown.
 389.107 + *
 389.108 + *
 389.109 + * <p><span style="font-weight: bold; padding-right: 1em">Example</span>
 389.110 + * Suppose we have a service type <tt>com.example.CodecSet</tt> which is
 389.111 + * intended to represent sets of encoder/decoder pairs for some protocol.  In
 389.112 + * this case it is an abstract class with two abstract methods:
 389.113 + *
 389.114 + * <blockquote><pre>
 389.115 + * public abstract Encoder getEncoder(String encodingName);
 389.116 + * public abstract Decoder getDecoder(String encodingName);</pre></blockquote>
 389.117 + *
 389.118 + * Each method returns an appropriate object or <tt>null</tt> if the provider
 389.119 + * does not support the given encoding.  Typical providers support more than
 389.120 + * one encoding.
 389.121 + *
 389.122 + * <p> If <tt>com.example.impl.StandardCodecs</tt> is an implementation of the
 389.123 + * <tt>CodecSet</tt> service then its jar file also contains a file named
 389.124 + *
 389.125 + * <blockquote><pre>
 389.126 + * META-INF/services/com.example.CodecSet</pre></blockquote>
 389.127 + *
 389.128 + * <p> This file contains the single line:
 389.129 + *
 389.130 + * <blockquote><pre>
 389.131 + * com.example.impl.StandardCodecs    # Standard codecs</pre></blockquote>
 389.132 + *
 389.133 + * <p> The <tt>CodecSet</tt> class creates and saves a single service instance
 389.134 + * at initialization:
 389.135 + *
 389.136 + * <blockquote><pre>
 389.137 + * private static ServiceLoader&lt;CodecSet&gt; codecSetLoader
 389.138 + *     = ServiceLoader.load(CodecSet.class);</pre></blockquote>
 389.139 + *
 389.140 + * <p> To locate an encoder for a given encoding name it defines a static
 389.141 + * factory method which iterates through the known and available providers,
 389.142 + * returning only when it has located a suitable encoder or has run out of
 389.143 + * providers.
 389.144 + *
 389.145 + * <blockquote><pre>
 389.146 + * public static Encoder getEncoder(String encodingName) {
 389.147 + *     for (CodecSet cp : codecSetLoader) {
 389.148 + *         Encoder enc = cp.getEncoder(encodingName);
 389.149 + *         if (enc != null)
 389.150 + *             return enc;
 389.151 + *     }
 389.152 + *     return null;
 389.153 + * }</pre></blockquote>
 389.154 + *
 389.155 + * <p> A <tt>getDecoder</tt> method is defined similarly.
 389.156 + *
 389.157 + *
 389.158 + * <p><span style="font-weight: bold; padding-right: 1em">Usage Note</span> If
 389.159 + * the class path of a class loader that is used for provider loading includes
 389.160 + * remote network URLs then those URLs will be dereferenced in the process of
 389.161 + * searching for provider-configuration files.
 389.162 + *
 389.163 + * <p> This activity is normal, although it may cause puzzling entries to be
 389.164 + * created in web-server logs.  If a web server is not configured correctly,
 389.165 + * however, then this activity may cause the provider-loading algorithm to fail
 389.166 + * spuriously.
 389.167 + *
 389.168 + * <p> A web server should return an HTTP 404 (Not Found) response when a
 389.169 + * requested resource does not exist.  Sometimes, however, web servers are
 389.170 + * erroneously configured to return an HTTP 200 (OK) response along with a
 389.171 + * helpful HTML error page in such cases.  This will cause a {@link
 389.172 + * ServiceConfigurationError} to be thrown when this class attempts to parse
 389.173 + * the HTML page as a provider-configuration file.  The best solution to this
 389.174 + * problem is to fix the misconfigured web server to return the correct
 389.175 + * response code (HTTP 404) along with the HTML error page.
 389.176 + *
 389.177 + * @param  <S>
 389.178 + *         The type of the service to be loaded by this loader
 389.179 + *
 389.180 + * @author Mark Reinhold
 389.181 + * @since 1.6
 389.182 + */
 389.183 +
 389.184 +public final class ServiceLoader<S>
 389.185 +    implements Iterable<S>
 389.186 +{
 389.187 +
 389.188 +    private static final String PREFIX = "META-INF/services/";
 389.189 +
 389.190 +    // The class or interface representing the service being loaded
 389.191 +    private Class<S> service;
 389.192 +
 389.193 +    // The class loader used to locate, load, and instantiate providers
 389.194 +    private ClassLoader loader;
 389.195 +
 389.196 +    // Cached providers, in instantiation order
 389.197 +    private LinkedHashMap<String,S> providers = new LinkedHashMap<>();
 389.198 +
 389.199 +    // The current lazy-lookup iterator
 389.200 +    private LazyIterator lookupIterator;
 389.201 +
 389.202 +    /**
 389.203 +     * Clear this loader's provider cache so that all providers will be
 389.204 +     * reloaded.
 389.205 +     *
 389.206 +     * <p> After invoking this method, subsequent invocations of the {@link
 389.207 +     * #iterator() iterator} method will lazily look up and instantiate
 389.208 +     * providers from scratch, just as is done by a newly-created loader.
 389.209 +     *
 389.210 +     * <p> This method is intended for use in situations in which new providers
 389.211 +     * can be installed into a running Java virtual machine.
 389.212 +     */
 389.213 +    public void reload() {
 389.214 +        providers.clear();
 389.215 +        lookupIterator = new LazyIterator(service, loader);
 389.216 +    }
 389.217 +
 389.218 +    private ServiceLoader(Class<S> svc, ClassLoader cl) {
 389.219 +        service = svc;
 389.220 +        loader = cl;
 389.221 +        reload();
 389.222 +    }
 389.223 +
 389.224 +    private static void fail(Class service, String msg, Throwable cause)
 389.225 +        throws ServiceConfigurationError
 389.226 +    {
 389.227 +        throw new ServiceConfigurationError(service.getName() + ": " + msg,
 389.228 +                                            cause);
 389.229 +    }
 389.230 +
 389.231 +    private static void fail(Class service, String msg)
 389.232 +        throws ServiceConfigurationError
 389.233 +    {
 389.234 +        throw new ServiceConfigurationError(service.getName() + ": " + msg);
 389.235 +    }
 389.236 +
 389.237 +    private static void fail(Class service, URL u, int line, String msg)
 389.238 +        throws ServiceConfigurationError
 389.239 +    {
 389.240 +        fail(service, u + ":" + line + ": " + msg);
 389.241 +    }
 389.242 +
 389.243 +    // Parse a single line from the given configuration file, adding the name
 389.244 +    // on the line to the names list.
 389.245 +    //
 389.246 +    private int parseLine(Class service, URL u, BufferedReader r, int lc,
 389.247 +                          List<String> names)
 389.248 +        throws IOException, ServiceConfigurationError
 389.249 +    {
 389.250 +        String ln = r.readLine();
 389.251 +        if (ln == null) {
 389.252 +            return -1;
 389.253 +        }
 389.254 +        int ci = ln.indexOf('#');
 389.255 +        if (ci >= 0) ln = ln.substring(0, ci);
 389.256 +        ln = ln.trim();
 389.257 +        int n = ln.length();
 389.258 +        if (n != 0) {
 389.259 +            if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
 389.260 +                fail(service, u, lc, "Illegal configuration-file syntax");
 389.261 +            int cp = ln.codePointAt(0);
 389.262 +            if (!Character.isJavaIdentifierStart(cp))
 389.263 +                fail(service, u, lc, "Illegal provider-class name: " + ln);
 389.264 +            for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
 389.265 +                cp = ln.codePointAt(i);
 389.266 +                if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
 389.267 +                    fail(service, u, lc, "Illegal provider-class name: " + ln);
 389.268 +            }
 389.269 +            if (!providers.containsKey(ln) && !names.contains(ln))
 389.270 +                names.add(ln);
 389.271 +        }
 389.272 +        return lc + 1;
 389.273 +    }
 389.274 +
 389.275 +    // Parse the content of the given URL as a provider-configuration file.
 389.276 +    //
 389.277 +    // @param  service
 389.278 +    //         The service type for which providers are being sought;
 389.279 +    //         used to construct error detail strings
 389.280 +    //
 389.281 +    // @param  u
 389.282 +    //         The URL naming the configuration file to be parsed
 389.283 +    //
 389.284 +    // @return A (possibly empty) iterator that will yield the provider-class
 389.285 +    //         names in the given configuration file that are not yet members
 389.286 +    //         of the returned set
 389.287 +    //
 389.288 +    // @throws ServiceConfigurationError
 389.289 +    //         If an I/O error occurs while reading from the given URL, or
 389.290 +    //         if a configuration-file format error is detected
 389.291 +    //
 389.292 +    private Iterator<String> parse(Class service, URL u)
 389.293 +        throws ServiceConfigurationError
 389.294 +    {
 389.295 +        InputStream in = null;
 389.296 +        BufferedReader r = null;
 389.297 +        ArrayList<String> names = new ArrayList<>();
 389.298 +        try {
 389.299 +            in = u.openStream();
 389.300 +            r = new BufferedReader(new InputStreamReader(in, "utf-8"));
 389.301 +            int lc = 1;
 389.302 +            while ((lc = parseLine(service, u, r, lc, names)) >= 0);
 389.303 +        } catch (IOException x) {
 389.304 +            fail(service, "Error reading configuration file", x);
 389.305 +        } finally {
 389.306 +            try {
 389.307 +                if (r != null) r.close();
 389.308 +                if (in != null) in.close();
 389.309 +            } catch (IOException y) {
 389.310 +                fail(service, "Error closing configuration file", y);
 389.311 +            }
 389.312 +        }
 389.313 +        return names.iterator();
 389.314 +    }
 389.315 +
 389.316 +    // Private inner class implementing fully-lazy provider lookup
 389.317 +    //
 389.318 +    private class LazyIterator
 389.319 +        implements Iterator<S>
 389.320 +    {
 389.321 +
 389.322 +        Class<S> service;
 389.323 +        ClassLoader loader;
 389.324 +        Enumeration<URL> configs = null;
 389.325 +        Iterator<String> pending = null;
 389.326 +        String nextName = null;
 389.327 +
 389.328 +        private LazyIterator(Class<S> service, ClassLoader loader) {
 389.329 +            this.service = service;
 389.330 +            this.loader = loader;
 389.331 +        }
 389.332 +
 389.333 +        public boolean hasNext() {
 389.334 +            if (nextName != null) {
 389.335 +                return true;
 389.336 +            }
 389.337 +            if (configs == null) {
 389.338 +                try {
 389.339 +                    String fullName = PREFIX + service.getName();
 389.340 +                    if (loader == null)
 389.341 +                        configs = ClassLoader.getSystemResources(fullName);
 389.342 +                    else
 389.343 +                        configs = loader.getResources(fullName);
 389.344 +                } catch (IOException x) {
 389.345 +                    fail(service, "Error locating configuration files", x);
 389.346 +                }
 389.347 +            }
 389.348 +            while ((pending == null) || !pending.hasNext()) {
 389.349 +                if (!configs.hasMoreElements()) {
 389.350 +                    return false;
 389.351 +                }
 389.352 +                pending = parse(service, configs.nextElement());
 389.353 +            }
 389.354 +            nextName = pending.next();
 389.355 +            return true;
 389.356 +        }
 389.357 +
 389.358 +        public S next() {
 389.359 +            if (!hasNext()) {
 389.360 +                throw new NoSuchElementException();
 389.361 +            }
 389.362 +            String cn = nextName;
 389.363 +            nextName = null;
 389.364 +            try {
 389.365 +                S p = service.cast(Class.forName(cn, true, loader)
 389.366 +                                   .newInstance());
 389.367 +                providers.put(cn, p);
 389.368 +                return p;
 389.369 +            } catch (ClassNotFoundException x) {
 389.370 +                fail(service,
 389.371 +                     "Provider " + cn + " not found");
 389.372 +            } catch (Throwable x) {
 389.373 +                fail(service,
 389.374 +                     "Provider " + cn + " could not be instantiated: " + x,
 389.375 +                     x);
 389.376 +            }
 389.377 +            throw new Error();          // This cannot happen
 389.378 +        }
 389.379 +
 389.380 +        public void remove() {
 389.381 +            throw new UnsupportedOperationException();
 389.382 +        }
 389.383 +
 389.384 +    }
 389.385 +
 389.386 +    /**
 389.387 +     * Lazily loads the available providers of this loader's service.
 389.388 +     *
 389.389 +     * <p> The iterator returned by this method first yields all of the
 389.390 +     * elements of the provider cache, in instantiation order.  It then lazily
 389.391 +     * loads and instantiates any remaining providers, adding each one to the
 389.392 +     * cache in turn.
 389.393 +     *
 389.394 +     * <p> To achieve laziness the actual work of parsing the available
 389.395 +     * provider-configuration files and instantiating providers must be done by
 389.396 +     * the iterator itself.  Its {@link java.util.Iterator#hasNext hasNext} and
 389.397 +     * {@link java.util.Iterator#next next} methods can therefore throw a
 389.398 +     * {@link ServiceConfigurationError} if a provider-configuration file
 389.399 +     * violates the specified format, or if it names a provider class that
 389.400 +     * cannot be found and instantiated, or if the result of instantiating the
 389.401 +     * class is not assignable to the service type, or if any other kind of
 389.402 +     * exception or error is thrown as the next provider is located and
 389.403 +     * instantiated.  To write robust code it is only necessary to catch {@link
 389.404 +     * ServiceConfigurationError} when using a service iterator.
 389.405 +     *
 389.406 +     * <p> If such an error is thrown then subsequent invocations of the
 389.407 +     * iterator will make a best effort to locate and instantiate the next
 389.408 +     * available provider, but in general such recovery cannot be guaranteed.
 389.409 +     *
 389.410 +     * <blockquote style="font-size: smaller; line-height: 1.2"><span
 389.411 +     * style="padding-right: 1em; font-weight: bold">Design Note</span>
 389.412 +     * Throwing an error in these cases may seem extreme.  The rationale for
 389.413 +     * this behavior is that a malformed provider-configuration file, like a
 389.414 +     * malformed class file, indicates a serious problem with the way the Java
 389.415 +     * virtual machine is configured or is being used.  As such it is
 389.416 +     * preferable to throw an error rather than try to recover or, even worse,
 389.417 +     * fail silently.</blockquote>
 389.418 +     *
 389.419 +     * <p> The iterator returned by this method does not support removal.
 389.420 +     * Invoking its {@link java.util.Iterator#remove() remove} method will
 389.421 +     * cause an {@link UnsupportedOperationException} to be thrown.
 389.422 +     *
 389.423 +     * @return  An iterator that lazily loads providers for this loader's
 389.424 +     *          service
 389.425 +     */
 389.426 +    public Iterator<S> iterator() {
 389.427 +        return new Iterator<S>() {
 389.428 +
 389.429 +            Iterator<Map.Entry<String,S>> knownProviders
 389.430 +                = providers.entrySet().iterator();
 389.431 +
 389.432 +            public boolean hasNext() {
 389.433 +                if (knownProviders.hasNext())
 389.434 +                    return true;
 389.435 +                return lookupIterator.hasNext();
 389.436 +            }
 389.437 +
 389.438 +            public S next() {
 389.439 +                if (knownProviders.hasNext())
 389.440 +                    return knownProviders.next().getValue();
 389.441 +                return lookupIterator.next();
 389.442 +            }
 389.443 +
 389.444 +            public void remove() {
 389.445 +                throw new UnsupportedOperationException();
 389.446 +            }
 389.447 +
 389.448 +        };
 389.449 +    }
 389.450 +
 389.451 +    /**
 389.452 +     * Creates a new service loader for the given service type and class
 389.453 +     * loader.
 389.454 +     *
 389.455 +     * @param  service
 389.456 +     *         The interface or abstract class representing the service
 389.457 +     *
 389.458 +     * @param  loader
 389.459 +     *         The class loader to be used to load provider-configuration files
 389.460 +     *         and provider classes, or <tt>null</tt> if the system class
 389.461 +     *         loader (or, failing that, the bootstrap class loader) is to be
 389.462 +     *         used
 389.463 +     *
 389.464 +     * @return A new service loader
 389.465 +     */
 389.466 +    public static <S> ServiceLoader<S> load(Class<S> service,
 389.467 +                                            ClassLoader loader)
 389.468 +    {
 389.469 +        return new ServiceLoader<>(service, loader);
 389.470 +    }
 389.471 +
 389.472 +    /**
 389.473 +     * Creates a new service loader for the given service type, using the
 389.474 +     * current thread's {@linkplain java.lang.Thread#getContextClassLoader
 389.475 +     * context class loader}.
 389.476 +     *
 389.477 +     * <p> An invocation of this convenience method of the form
 389.478 +     *
 389.479 +     * <blockquote><pre>
 389.480 +     * ServiceLoader.load(<i>service</i>)</pre></blockquote>
 389.481 +     *
 389.482 +     * is equivalent to
 389.483 +     *
 389.484 +     * <blockquote><pre>
 389.485 +     * ServiceLoader.load(<i>service</i>,
 389.486 +     *                    Thread.currentThread().getContextClassLoader())</pre></blockquote>
 389.487 +     *
 389.488 +     * @param  service
 389.489 +     *         The interface or abstract class representing the service
 389.490 +     *
 389.491 +     * @return A new service loader
 389.492 +     */
 389.493 +    public static <S> ServiceLoader<S> load(Class<S> service) {
 389.494 +        ClassLoader cl = null; // XXX: Thread.currentThread().getContextClassLoader();
 389.495 +        return ServiceLoader.load(service, cl);
 389.496 +    }
 389.497 +
 389.498 +    /**
 389.499 +     * Creates a new service loader for the given service type, using the
 389.500 +     * extension class loader.
 389.501 +     *
 389.502 +     * <p> This convenience method simply locates the extension class loader,
 389.503 +     * call it <tt><i>extClassLoader</i></tt>, and then returns
 389.504 +     *
 389.505 +     * <blockquote><pre>
 389.506 +     * ServiceLoader.load(<i>service</i>, <i>extClassLoader</i>)</pre></blockquote>
 389.507 +     *
 389.508 +     * <p> If the extension class loader cannot be found then the system class
 389.509 +     * loader is used; if there is no system class loader then the bootstrap
 389.510 +     * class loader is used.
 389.511 +     *
 389.512 +     * <p> This method is intended for use when only installed providers are
 389.513 +     * desired.  The resulting service will only find and load providers that
 389.514 +     * have been installed into the current Java virtual machine; providers on
 389.515 +     * the application's class path will be ignored.
 389.516 +     *
 389.517 +     * @param  service
 389.518 +     *         The interface or abstract class representing the service
 389.519 +     *
 389.520 +     * @return A new service loader
 389.521 +     */
 389.522 +    public static <S> ServiceLoader<S> loadInstalled(Class<S> service) {
 389.523 +        ClassLoader cl = ClassLoader.getSystemClassLoader();
 389.524 +        ClassLoader prev = null;
 389.525 +        while (cl != null) {
 389.526 +            prev = cl;
 389.527 +            cl = cl.getParent();
 389.528 +        }
 389.529 +        return ServiceLoader.load(service, prev);
 389.530 +    }
 389.531 +
 389.532 +    /**
 389.533 +     * Returns a string describing this service.
 389.534 +     *
 389.535 +     * @return  A descriptive string
 389.536 +     */
 389.537 +    public String toString() {
 389.538 +        return "java.util.ServiceLoader[" + service.getName() + "]";
 389.539 +    }
 389.540 +
 389.541 +}
   390.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   390.2 +++ b/rt/emul/compact/src/main/java/java/util/Set.java	Wed Feb 27 11:24:58 2013 +0100
   390.3 @@ -0,0 +1,385 @@
   390.4 +/*
   390.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   390.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   390.7 + *
   390.8 + * This code is free software; you can redistribute it and/or modify it
   390.9 + * under the terms of the GNU General Public License version 2 only, as
  390.10 + * published by the Free Software Foundation.  Oracle designates this
  390.11 + * particular file as subject to the "Classpath" exception as provided
  390.12 + * by Oracle in the LICENSE file that accompanied this code.
  390.13 + *
  390.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  390.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  390.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  390.17 + * version 2 for more details (a copy is included in the LICENSE file that
  390.18 + * accompanied this code).
  390.19 + *
  390.20 + * You should have received a copy of the GNU General Public License version
  390.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  390.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  390.23 + *
  390.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  390.25 + * or visit www.oracle.com if you need additional information or have any
  390.26 + * questions.
  390.27 + */
  390.28 +
  390.29 +package java.util;
  390.30 +
  390.31 +/**
  390.32 + * A collection that contains no duplicate elements.  More formally, sets
  390.33 + * contain no pair of elements <code>e1</code> and <code>e2</code> such that
  390.34 + * <code>e1.equals(e2)</code>, and at most one null element.  As implied by
  390.35 + * its name, this interface models the mathematical <i>set</i> abstraction.
  390.36 + *
  390.37 + * <p>The <tt>Set</tt> interface places additional stipulations, beyond those
  390.38 + * inherited from the <tt>Collection</tt> interface, on the contracts of all
  390.39 + * constructors and on the contracts of the <tt>add</tt>, <tt>equals</tt> and
  390.40 + * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
  390.41 + * also included here for convenience.  (The specifications accompanying these
  390.42 + * declarations have been tailored to the <tt>Set</tt> interface, but they do
  390.43 + * not contain any additional stipulations.)
  390.44 + *
  390.45 + * <p>The additional stipulation on constructors is, not surprisingly,
  390.46 + * that all constructors must create a set that contains no duplicate elements
  390.47 + * (as defined above).
  390.48 + *
  390.49 + * <p>Note: Great care must be exercised if mutable objects are used as set
  390.50 + * elements.  The behavior of a set is not specified if the value of an object
  390.51 + * is changed in a manner that affects <tt>equals</tt> comparisons while the
  390.52 + * object is an element in the set.  A special case of this prohibition is
  390.53 + * that it is not permissible for a set to contain itself as an element.
  390.54 + *
  390.55 + * <p>Some set implementations have restrictions on the elements that
  390.56 + * they may contain.  For example, some implementations prohibit null elements,
  390.57 + * and some have restrictions on the types of their elements.  Attempting to
  390.58 + * add an ineligible element throws an unchecked exception, typically
  390.59 + * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
  390.60 + * to query the presence of an ineligible element may throw an exception,
  390.61 + * or it may simply return false; some implementations will exhibit the former
  390.62 + * behavior and some will exhibit the latter.  More generally, attempting an
  390.63 + * operation on an ineligible element whose completion would not result in
  390.64 + * the insertion of an ineligible element into the set may throw an
  390.65 + * exception or it may succeed, at the option of the implementation.
  390.66 + * Such exceptions are marked as "optional" in the specification for this
  390.67 + * interface.
  390.68 + *
  390.69 + * <p>This interface is a member of the
  390.70 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  390.71 + * Java Collections Framework</a>.
  390.72 + *
  390.73 + * @param <E> the type of elements maintained by this set
  390.74 + *
  390.75 + * @author  Josh Bloch
  390.76 + * @author  Neal Gafter
  390.77 + * @see Collection
  390.78 + * @see List
  390.79 + * @see SortedSet
  390.80 + * @see HashSet
  390.81 + * @see TreeSet
  390.82 + * @see AbstractSet
  390.83 + * @see Collections#singleton(java.lang.Object)
  390.84 + * @see Collections#EMPTY_SET
  390.85 + * @since 1.2
  390.86 + */
  390.87 +
  390.88 +public interface Set<E> extends Collection<E> {
  390.89 +    // Query Operations
  390.90 +
  390.91 +    /**
  390.92 +     * Returns the number of elements in this set (its cardinality).  If this
  390.93 +     * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
  390.94 +     * <tt>Integer.MAX_VALUE</tt>.
  390.95 +     *
  390.96 +     * @return the number of elements in this set (its cardinality)
  390.97 +     */
  390.98 +    int size();
  390.99 +
 390.100 +    /**
 390.101 +     * Returns <tt>true</tt> if this set contains no elements.
 390.102 +     *
 390.103 +     * @return <tt>true</tt> if this set contains no elements
 390.104 +     */
 390.105 +    boolean isEmpty();
 390.106 +
 390.107 +    /**
 390.108 +     * Returns <tt>true</tt> if this set contains the specified element.
 390.109 +     * More formally, returns <tt>true</tt> if and only if this set
 390.110 +     * contains an element <tt>e</tt> such that
 390.111 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 390.112 +     *
 390.113 +     * @param o element whose presence in this set is to be tested
 390.114 +     * @return <tt>true</tt> if this set contains the specified element
 390.115 +     * @throws ClassCastException if the type of the specified element
 390.116 +     *         is incompatible with this set
 390.117 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.118 +     * @throws NullPointerException if the specified element is null and this
 390.119 +     *         set does not permit null elements
 390.120 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.121 +     */
 390.122 +    boolean contains(Object o);
 390.123 +
 390.124 +    /**
 390.125 +     * Returns an iterator over the elements in this set.  The elements are
 390.126 +     * returned in no particular order (unless this set is an instance of some
 390.127 +     * class that provides a guarantee).
 390.128 +     *
 390.129 +     * @return an iterator over the elements in this set
 390.130 +     */
 390.131 +    Iterator<E> iterator();
 390.132 +
 390.133 +    /**
 390.134 +     * Returns an array containing all of the elements in this set.
 390.135 +     * If this set makes any guarantees as to what order its elements
 390.136 +     * are returned by its iterator, this method must return the
 390.137 +     * elements in the same order.
 390.138 +     *
 390.139 +     * <p>The returned array will be "safe" in that no references to it
 390.140 +     * are maintained by this set.  (In other words, this method must
 390.141 +     * allocate a new array even if this set is backed by an array).
 390.142 +     * The caller is thus free to modify the returned array.
 390.143 +     *
 390.144 +     * <p>This method acts as bridge between array-based and collection-based
 390.145 +     * APIs.
 390.146 +     *
 390.147 +     * @return an array containing all the elements in this set
 390.148 +     */
 390.149 +    Object[] toArray();
 390.150 +
 390.151 +    /**
 390.152 +     * Returns an array containing all of the elements in this set; the
 390.153 +     * runtime type of the returned array is that of the specified array.
 390.154 +     * If the set fits in the specified array, it is returned therein.
 390.155 +     * Otherwise, a new array is allocated with the runtime type of the
 390.156 +     * specified array and the size of this set.
 390.157 +     *
 390.158 +     * <p>If this set fits in the specified array with room to spare
 390.159 +     * (i.e., the array has more elements than this set), the element in
 390.160 +     * the array immediately following the end of the set is set to
 390.161 +     * <tt>null</tt>.  (This is useful in determining the length of this
 390.162 +     * set <i>only</i> if the caller knows that this set does not contain
 390.163 +     * any null elements.)
 390.164 +     *
 390.165 +     * <p>If this set makes any guarantees as to what order its elements
 390.166 +     * are returned by its iterator, this method must return the elements
 390.167 +     * in the same order.
 390.168 +     *
 390.169 +     * <p>Like the {@link #toArray()} method, this method acts as bridge between
 390.170 +     * array-based and collection-based APIs.  Further, this method allows
 390.171 +     * precise control over the runtime type of the output array, and may,
 390.172 +     * under certain circumstances, be used to save allocation costs.
 390.173 +     *
 390.174 +     * <p>Suppose <tt>x</tt> is a set known to contain only strings.
 390.175 +     * The following code can be used to dump the set into a newly allocated
 390.176 +     * array of <tt>String</tt>:
 390.177 +     *
 390.178 +     * <pre>
 390.179 +     *     String[] y = x.toArray(new String[0]);</pre>
 390.180 +     *
 390.181 +     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
 390.182 +     * <tt>toArray()</tt>.
 390.183 +     *
 390.184 +     * @param a the array into which the elements of this set are to be
 390.185 +     *        stored, if it is big enough; otherwise, a new array of the same
 390.186 +     *        runtime type is allocated for this purpose.
 390.187 +     * @return an array containing all the elements in this set
 390.188 +     * @throws ArrayStoreException if the runtime type of the specified array
 390.189 +     *         is not a supertype of the runtime type of every element in this
 390.190 +     *         set
 390.191 +     * @throws NullPointerException if the specified array is null
 390.192 +     */
 390.193 +    <T> T[] toArray(T[] a);
 390.194 +
 390.195 +
 390.196 +    // Modification Operations
 390.197 +
 390.198 +    /**
 390.199 +     * Adds the specified element to this set if it is not already present
 390.200 +     * (optional operation).  More formally, adds the specified element
 390.201 +     * <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
 390.202 +     * such that
 390.203 +     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
 390.204 +     * If this set already contains the element, the call leaves the set
 390.205 +     * unchanged and returns <tt>false</tt>.  In combination with the
 390.206 +     * restriction on constructors, this ensures that sets never contain
 390.207 +     * duplicate elements.
 390.208 +     *
 390.209 +     * <p>The stipulation above does not imply that sets must accept all
 390.210 +     * elements; sets may refuse to add any particular element, including
 390.211 +     * <tt>null</tt>, and throw an exception, as described in the
 390.212 +     * specification for {@link Collection#add Collection.add}.
 390.213 +     * Individual set implementations should clearly document any
 390.214 +     * restrictions on the elements that they may contain.
 390.215 +     *
 390.216 +     * @param e element to be added to this set
 390.217 +     * @return <tt>true</tt> if this set did not already contain the specified
 390.218 +     *         element
 390.219 +     * @throws UnsupportedOperationException if the <tt>add</tt> operation
 390.220 +     *         is not supported by this set
 390.221 +     * @throws ClassCastException if the class of the specified element
 390.222 +     *         prevents it from being added to this set
 390.223 +     * @throws NullPointerException if the specified element is null and this
 390.224 +     *         set does not permit null elements
 390.225 +     * @throws IllegalArgumentException if some property of the specified element
 390.226 +     *         prevents it from being added to this set
 390.227 +     */
 390.228 +    boolean add(E e);
 390.229 +
 390.230 +
 390.231 +    /**
 390.232 +     * Removes the specified element from this set if it is present
 390.233 +     * (optional operation).  More formally, removes an element <tt>e</tt>
 390.234 +     * such that
 390.235 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
 390.236 +     * this set contains such an element.  Returns <tt>true</tt> if this set
 390.237 +     * contained the element (or equivalently, if this set changed as a
 390.238 +     * result of the call).  (This set will not contain the element once the
 390.239 +     * call returns.)
 390.240 +     *
 390.241 +     * @param o object to be removed from this set, if present
 390.242 +     * @return <tt>true</tt> if this set contained the specified element
 390.243 +     * @throws ClassCastException if the type of the specified element
 390.244 +     *         is incompatible with this set
 390.245 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.246 +     * @throws NullPointerException if the specified element is null and this
 390.247 +     *         set does not permit null elements
 390.248 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.249 +     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 390.250 +     *         is not supported by this set
 390.251 +     */
 390.252 +    boolean remove(Object o);
 390.253 +
 390.254 +
 390.255 +    // Bulk Operations
 390.256 +
 390.257 +    /**
 390.258 +     * Returns <tt>true</tt> if this set contains all of the elements of the
 390.259 +     * specified collection.  If the specified collection is also a set, this
 390.260 +     * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
 390.261 +     *
 390.262 +     * @param  c collection to be checked for containment in this set
 390.263 +     * @return <tt>true</tt> if this set contains all of the elements of the
 390.264 +     *         specified collection
 390.265 +     * @throws ClassCastException if the types of one or more elements
 390.266 +     *         in the specified collection are incompatible with this
 390.267 +     *         set
 390.268 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.269 +     * @throws NullPointerException if the specified collection contains one
 390.270 +     *         or more null elements and this set does not permit null
 390.271 +     *         elements
 390.272 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
 390.273 +     *         or if the specified collection is null
 390.274 +     * @see    #contains(Object)
 390.275 +     */
 390.276 +    boolean containsAll(Collection<?> c);
 390.277 +
 390.278 +    /**
 390.279 +     * Adds all of the elements in the specified collection to this set if
 390.280 +     * they're not already present (optional operation).  If the specified
 390.281 +     * collection is also a set, the <tt>addAll</tt> operation effectively
 390.282 +     * modifies this set so that its value is the <i>union</i> of the two
 390.283 +     * sets.  The behavior of this operation is undefined if the specified
 390.284 +     * collection is modified while the operation is in progress.
 390.285 +     *
 390.286 +     * @param  c collection containing elements to be added to this set
 390.287 +     * @return <tt>true</tt> if this set changed as a result of the call
 390.288 +     *
 390.289 +     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
 390.290 +     *         is not supported by this set
 390.291 +     * @throws ClassCastException if the class of an element of the
 390.292 +     *         specified collection prevents it from being added to this set
 390.293 +     * @throws NullPointerException if the specified collection contains one
 390.294 +     *         or more null elements and this set does not permit null
 390.295 +     *         elements, or if the specified collection is null
 390.296 +     * @throws IllegalArgumentException if some property of an element of the
 390.297 +     *         specified collection prevents it from being added to this set
 390.298 +     * @see #add(Object)
 390.299 +     */
 390.300 +    boolean addAll(Collection<? extends E> c);
 390.301 +
 390.302 +    /**
 390.303 +     * Retains only the elements in this set that are contained in the
 390.304 +     * specified collection (optional operation).  In other words, removes
 390.305 +     * from this set all of its elements that are not contained in the
 390.306 +     * specified collection.  If the specified collection is also a set, this
 390.307 +     * operation effectively modifies this set so that its value is the
 390.308 +     * <i>intersection</i> of the two sets.
 390.309 +     *
 390.310 +     * @param  c collection containing elements to be retained in this set
 390.311 +     * @return <tt>true</tt> if this set changed as a result of the call
 390.312 +     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
 390.313 +     *         is not supported by this set
 390.314 +     * @throws ClassCastException if the class of an element of this set
 390.315 +     *         is incompatible with the specified collection
 390.316 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.317 +     * @throws NullPointerException if this set contains a null element and the
 390.318 +     *         specified collection does not permit null elements
 390.319 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 390.320 +     *         or if the specified collection is null
 390.321 +     * @see #remove(Object)
 390.322 +     */
 390.323 +    boolean retainAll(Collection<?> c);
 390.324 +
 390.325 +    /**
 390.326 +     * Removes from this set all of its elements that are contained in the
 390.327 +     * specified collection (optional operation).  If the specified
 390.328 +     * collection is also a set, this operation effectively modifies this
 390.329 +     * set so that its value is the <i>asymmetric set difference</i> of
 390.330 +     * the two sets.
 390.331 +     *
 390.332 +     * @param  c collection containing elements to be removed from this set
 390.333 +     * @return <tt>true</tt> if this set changed as a result of the call
 390.334 +     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 390.335 +     *         is not supported by this set
 390.336 +     * @throws ClassCastException if the class of an element of this set
 390.337 +     *         is incompatible with the specified collection
 390.338 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 390.339 +     * @throws NullPointerException if this set contains a null element and the
 390.340 +     *         specified collection does not permit null elements
 390.341 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 390.342 +     *         or if the specified collection is null
 390.343 +     * @see #remove(Object)
 390.344 +     * @see #contains(Object)
 390.345 +     */
 390.346 +    boolean removeAll(Collection<?> c);
 390.347 +
 390.348 +    /**
 390.349 +     * Removes all of the elements from this set (optional operation).
 390.350 +     * The set will be empty after this call returns.
 390.351 +     *
 390.352 +     * @throws UnsupportedOperationException if the <tt>clear</tt> method
 390.353 +     *         is not supported by this set
 390.354 +     */
 390.355 +    void clear();
 390.356 +
 390.357 +
 390.358 +    // Comparison and hashing
 390.359 +
 390.360 +    /**
 390.361 +     * Compares the specified object with this set for equality.  Returns
 390.362 +     * <tt>true</tt> if the specified object is also a set, the two sets
 390.363 +     * have the same size, and every member of the specified set is
 390.364 +     * contained in this set (or equivalently, every member of this set is
 390.365 +     * contained in the specified set).  This definition ensures that the
 390.366 +     * equals method works properly across different implementations of the
 390.367 +     * set interface.
 390.368 +     *
 390.369 +     * @param o object to be compared for equality with this set
 390.370 +     * @return <tt>true</tt> if the specified object is equal to this set
 390.371 +     */
 390.372 +    boolean equals(Object o);
 390.373 +
 390.374 +    /**
 390.375 +     * Returns the hash code value for this set.  The hash code of a set is
 390.376 +     * defined to be the sum of the hash codes of the elements in the set,
 390.377 +     * where the hash code of a <tt>null</tt> element is defined to be zero.
 390.378 +     * This ensures that <tt>s1.equals(s2)</tt> implies that
 390.379 +     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
 390.380 +     * and <tt>s2</tt>, as required by the general contract of
 390.381 +     * {@link Object#hashCode}.
 390.382 +     *
 390.383 +     * @return the hash code value for this set
 390.384 +     * @see Object#equals(Object)
 390.385 +     * @see Set#equals(Object)
 390.386 +     */
 390.387 +    int hashCode();
 390.388 +}
   391.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   391.2 +++ b/rt/emul/compact/src/main/java/java/util/SortedMap.java	Wed Feb 27 11:24:58 2013 +0100
   391.3 @@ -0,0 +1,284 @@
   391.4 +/*
   391.5 + * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
   391.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   391.7 + *
   391.8 + * This code is free software; you can redistribute it and/or modify it
   391.9 + * under the terms of the GNU General Public License version 2 only, as
  391.10 + * published by the Free Software Foundation.  Oracle designates this
  391.11 + * particular file as subject to the "Classpath" exception as provided
  391.12 + * by Oracle in the LICENSE file that accompanied this code.
  391.13 + *
  391.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  391.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  391.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  391.17 + * version 2 for more details (a copy is included in the LICENSE file that
  391.18 + * accompanied this code).
  391.19 + *
  391.20 + * You should have received a copy of the GNU General Public License version
  391.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  391.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  391.23 + *
  391.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  391.25 + * or visit www.oracle.com if you need additional information or have any
  391.26 + * questions.
  391.27 + */
  391.28 +
  391.29 +package java.util;
  391.30 +
  391.31 +/**
  391.32 + * A {@link Map} that further provides a <em>total ordering</em> on its keys.
  391.33 + * The map is ordered according to the {@linkplain Comparable natural
  391.34 + * ordering} of its keys, or by a {@link Comparator} typically
  391.35 + * provided at sorted map creation time.  This order is reflected when
  391.36 + * iterating over the sorted map's collection views (returned by the
  391.37 + * {@code entrySet}, {@code keySet} and {@code values} methods).
  391.38 + * Several additional operations are provided to take advantage of the
  391.39 + * ordering.  (This interface is the map analogue of {@link SortedSet}.)
  391.40 + *
  391.41 + * <p>All keys inserted into a sorted map must implement the {@code Comparable}
  391.42 + * interface (or be accepted by the specified comparator).  Furthermore, all
  391.43 + * such keys must be <em>mutually comparable</em>: {@code k1.compareTo(k2)} (or
  391.44 + * {@code comparator.compare(k1, k2)}) must not throw a
  391.45 + * {@code ClassCastException} for any keys {@code k1} and {@code k2} in
  391.46 + * the sorted map.  Attempts to violate this restriction will cause the
  391.47 + * offending method or constructor invocation to throw a
  391.48 + * {@code ClassCastException}.
  391.49 + *
  391.50 + * <p>Note that the ordering maintained by a sorted map (whether or not an
  391.51 + * explicit comparator is provided) must be <em>consistent with equals</em> if
  391.52 + * the sorted map is to correctly implement the {@code Map} interface.  (See
  391.53 + * the {@code Comparable} interface or {@code Comparator} interface for a
  391.54 + * precise definition of <em>consistent with equals</em>.)  This is so because
  391.55 + * the {@code Map} interface is defined in terms of the {@code equals}
  391.56 + * operation, but a sorted map performs all key comparisons using its
  391.57 + * {@code compareTo} (or {@code compare}) method, so two keys that are
  391.58 + * deemed equal by this method are, from the standpoint of the sorted map,
  391.59 + * equal.  The behavior of a tree map <em>is</em> well-defined even if its
  391.60 + * ordering is inconsistent with equals; it just fails to obey the general
  391.61 + * contract of the {@code Map} interface.
  391.62 + *
  391.63 + * <p>All general-purpose sorted map implementation classes should provide four
  391.64 + * "standard" constructors. It is not possible to enforce this recommendation
  391.65 + * though as required constructors cannot be specified by interfaces. The
  391.66 + * expected "standard" constructors for all sorted map implementations are:
  391.67 + * <ol>
  391.68 + *   <li>A void (no arguments) constructor, which creates an empty sorted map
  391.69 + *   sorted according to the natural ordering of its keys.</li>
  391.70 + *   <li>A constructor with a single argument of type {@code Comparator}, which
  391.71 + *   creates an empty sorted map sorted according to the specified comparator.</li>
  391.72 + *   <li>A constructor with a single argument of type {@code Map}, which creates
  391.73 + *   a new map with the same key-value mappings as its argument, sorted
  391.74 + *   according to the keys' natural ordering.</li>
  391.75 + *   <li>A constructor with a single argument of type {@code SortedMap}, which
  391.76 + *   creates a new sorted map with the same key-value mappings and the same
  391.77 + *   ordering as the input sorted map.</li>
  391.78 + * </ol>
  391.79 + *
  391.80 + * <p><strong>Note</strong>: several methods return submaps with restricted key
  391.81 + * ranges. Such ranges are <em>half-open</em>, that is, they include their low
  391.82 + * endpoint but not their high endpoint (where applicable).  If you need a
  391.83 + * <em>closed range</em> (which includes both endpoints), and the key type
  391.84 + * allows for calculation of the successor of a given key, merely request
  391.85 + * the subrange from {@code lowEndpoint} to
  391.86 + * {@code successor(highEndpoint)}.  For example, suppose that {@code m}
  391.87 + * is a map whose keys are strings.  The following idiom obtains a view
  391.88 + * containing all of the key-value mappings in {@code m} whose keys are
  391.89 + * between {@code low} and {@code high}, inclusive:<pre>
  391.90 + *   SortedMap&lt;String, V&gt; sub = m.subMap(low, high+"\0");</pre>
  391.91 + *
  391.92 + * A similar technique can be used to generate an <em>open range</em>
  391.93 + * (which contains neither endpoint).  The following idiom obtains a
  391.94 + * view containing all of the key-value mappings in {@code m} whose keys
  391.95 + * are between {@code low} and {@code high}, exclusive:<pre>
  391.96 + *   SortedMap&lt;String, V&gt; sub = m.subMap(low+"\0", high);</pre>
  391.97 + *
  391.98 + * <p>This interface is a member of the
  391.99 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 391.100 + * Java Collections Framework</a>.
 391.101 + *
 391.102 + * @param <K> the type of keys maintained by this map
 391.103 + * @param <V> the type of mapped values
 391.104 + *
 391.105 + * @author  Josh Bloch
 391.106 + * @see Map
 391.107 + * @see TreeMap
 391.108 + * @see SortedSet
 391.109 + * @see Comparator
 391.110 + * @see Comparable
 391.111 + * @see Collection
 391.112 + * @see ClassCastException
 391.113 + * @since 1.2
 391.114 + */
 391.115 +
 391.116 +public interface SortedMap<K,V> extends Map<K,V> {
 391.117 +    /**
 391.118 +     * Returns the comparator used to order the keys in this map, or
 391.119 +     * {@code null} if this map uses the {@linkplain Comparable
 391.120 +     * natural ordering} of its keys.
 391.121 +     *
 391.122 +     * @return the comparator used to order the keys in this map,
 391.123 +     *         or {@code null} if this map uses the natural ordering
 391.124 +     *         of its keys
 391.125 +     */
 391.126 +    Comparator<? super K> comparator();
 391.127 +
 391.128 +    /**
 391.129 +     * Returns a view of the portion of this map whose keys range from
 391.130 +     * {@code fromKey}, inclusive, to {@code toKey}, exclusive.  (If
 391.131 +     * {@code fromKey} and {@code toKey} are equal, the returned map
 391.132 +     * is empty.)  The returned map is backed by this map, so changes
 391.133 +     * in the returned map are reflected in this map, and vice-versa.
 391.134 +     * The returned map supports all optional map operations that this
 391.135 +     * map supports.
 391.136 +     *
 391.137 +     * <p>The returned map will throw an {@code IllegalArgumentException}
 391.138 +     * on an attempt to insert a key outside its range.
 391.139 +     *
 391.140 +     * @param fromKey low endpoint (inclusive) of the keys in the returned map
 391.141 +     * @param toKey high endpoint (exclusive) of the keys in the returned map
 391.142 +     * @return a view of the portion of this map whose keys range from
 391.143 +     *         {@code fromKey}, inclusive, to {@code toKey}, exclusive
 391.144 +     * @throws ClassCastException if {@code fromKey} and {@code toKey}
 391.145 +     *         cannot be compared to one another using this map's comparator
 391.146 +     *         (or, if the map has no comparator, using natural ordering).
 391.147 +     *         Implementations may, but are not required to, throw this
 391.148 +     *         exception if {@code fromKey} or {@code toKey}
 391.149 +     *         cannot be compared to keys currently in the map.
 391.150 +     * @throws NullPointerException if {@code fromKey} or {@code toKey}
 391.151 +     *         is null and this map does not permit null keys
 391.152 +     * @throws IllegalArgumentException if {@code fromKey} is greater than
 391.153 +     *         {@code toKey}; or if this map itself has a restricted
 391.154 +     *         range, and {@code fromKey} or {@code toKey} lies
 391.155 +     *         outside the bounds of the range
 391.156 +     */
 391.157 +    SortedMap<K,V> subMap(K fromKey, K toKey);
 391.158 +
 391.159 +    /**
 391.160 +     * Returns a view of the portion of this map whose keys are
 391.161 +     * strictly less than {@code toKey}.  The returned map is backed
 391.162 +     * by this map, so changes in the returned map are reflected in
 391.163 +     * this map, and vice-versa.  The returned map supports all
 391.164 +     * optional map operations that this map supports.
 391.165 +     *
 391.166 +     * <p>The returned map will throw an {@code IllegalArgumentException}
 391.167 +     * on an attempt to insert a key outside its range.
 391.168 +     *
 391.169 +     * @param toKey high endpoint (exclusive) of the keys in the returned map
 391.170 +     * @return a view of the portion of this map whose keys are strictly
 391.171 +     *         less than {@code toKey}
 391.172 +     * @throws ClassCastException if {@code toKey} is not compatible
 391.173 +     *         with this map's comparator (or, if the map has no comparator,
 391.174 +     *         if {@code toKey} does not implement {@link Comparable}).
 391.175 +     *         Implementations may, but are not required to, throw this
 391.176 +     *         exception if {@code toKey} cannot be compared to keys
 391.177 +     *         currently in the map.
 391.178 +     * @throws NullPointerException if {@code toKey} is null and
 391.179 +     *         this map does not permit null keys
 391.180 +     * @throws IllegalArgumentException if this map itself has a
 391.181 +     *         restricted range, and {@code toKey} lies outside the
 391.182 +     *         bounds of the range
 391.183 +     */
 391.184 +    SortedMap<K,V> headMap(K toKey);
 391.185 +
 391.186 +    /**
 391.187 +     * Returns a view of the portion of this map whose keys are
 391.188 +     * greater than or equal to {@code fromKey}.  The returned map is
 391.189 +     * backed by this map, so changes in the returned map are
 391.190 +     * reflected in this map, and vice-versa.  The returned map
 391.191 +     * supports all optional map operations that this map supports.
 391.192 +     *
 391.193 +     * <p>The returned map will throw an {@code IllegalArgumentException}
 391.194 +     * on an attempt to insert a key outside its range.
 391.195 +     *
 391.196 +     * @param fromKey low endpoint (inclusive) of the keys in the returned map
 391.197 +     * @return a view of the portion of this map whose keys are greater
 391.198 +     *         than or equal to {@code fromKey}
 391.199 +     * @throws ClassCastException if {@code fromKey} is not compatible
 391.200 +     *         with this map's comparator (or, if the map has no comparator,
 391.201 +     *         if {@code fromKey} does not implement {@link Comparable}).
 391.202 +     *         Implementations may, but are not required to, throw this
 391.203 +     *         exception if {@code fromKey} cannot be compared to keys
 391.204 +     *         currently in the map.
 391.205 +     * @throws NullPointerException if {@code fromKey} is null and
 391.206 +     *         this map does not permit null keys
 391.207 +     * @throws IllegalArgumentException if this map itself has a
 391.208 +     *         restricted range, and {@code fromKey} lies outside the
 391.209 +     *         bounds of the range
 391.210 +     */
 391.211 +    SortedMap<K,V> tailMap(K fromKey);
 391.212 +
 391.213 +    /**
 391.214 +     * Returns the first (lowest) key currently in this map.
 391.215 +     *
 391.216 +     * @return the first (lowest) key currently in this map
 391.217 +     * @throws NoSuchElementException if this map is empty
 391.218 +     */
 391.219 +    K firstKey();
 391.220 +
 391.221 +    /**
 391.222 +     * Returns the last (highest) key currently in this map.
 391.223 +     *
 391.224 +     * @return the last (highest) key currently in this map
 391.225 +     * @throws NoSuchElementException if this map is empty
 391.226 +     */
 391.227 +    K lastKey();
 391.228 +
 391.229 +    /**
 391.230 +     * Returns a {@link Set} view of the keys contained in this map.
 391.231 +     * The set's iterator returns the keys in ascending order.
 391.232 +     * The set is backed by the map, so changes to the map are
 391.233 +     * reflected in the set, and vice-versa.  If the map is modified
 391.234 +     * while an iteration over the set is in progress (except through
 391.235 +     * the iterator's own {@code remove} operation), the results of
 391.236 +     * the iteration are undefined.  The set supports element removal,
 391.237 +     * which removes the corresponding mapping from the map, via the
 391.238 +     * {@code Iterator.remove}, {@code Set.remove},
 391.239 +     * {@code removeAll}, {@code retainAll}, and {@code clear}
 391.240 +     * operations.  It does not support the {@code add} or {@code addAll}
 391.241 +     * operations.
 391.242 +     *
 391.243 +     * @return a set view of the keys contained in this map, sorted in
 391.244 +     *         ascending order
 391.245 +     */
 391.246 +    Set<K> keySet();
 391.247 +
 391.248 +    /**
 391.249 +     * Returns a {@link Collection} view of the values contained in this map.
 391.250 +     * The collection's iterator returns the values in ascending order
 391.251 +     * of the corresponding keys.
 391.252 +     * The collection is backed by the map, so changes to the map are
 391.253 +     * reflected in the collection, and vice-versa.  If the map is
 391.254 +     * modified while an iteration over the collection is in progress
 391.255 +     * (except through the iterator's own {@code remove} operation),
 391.256 +     * the results of the iteration are undefined.  The collection
 391.257 +     * supports element removal, which removes the corresponding
 391.258 +     * mapping from the map, via the {@code Iterator.remove},
 391.259 +     * {@code Collection.remove}, {@code removeAll},
 391.260 +     * {@code retainAll} and {@code clear} operations.  It does not
 391.261 +     * support the {@code add} or {@code addAll} operations.
 391.262 +     *
 391.263 +     * @return a collection view of the values contained in this map,
 391.264 +     *         sorted in ascending key order
 391.265 +     */
 391.266 +    Collection<V> values();
 391.267 +
 391.268 +    /**
 391.269 +     * Returns a {@link Set} view of the mappings contained in this map.
 391.270 +     * The set's iterator returns the entries in ascending key order.
 391.271 +     * The set is backed by the map, so changes to the map are
 391.272 +     * reflected in the set, and vice-versa.  If the map is modified
 391.273 +     * while an iteration over the set is in progress (except through
 391.274 +     * the iterator's own {@code remove} operation, or through the
 391.275 +     * {@code setValue} operation on a map entry returned by the
 391.276 +     * iterator) the results of the iteration are undefined.  The set
 391.277 +     * supports element removal, which removes the corresponding
 391.278 +     * mapping from the map, via the {@code Iterator.remove},
 391.279 +     * {@code Set.remove}, {@code removeAll}, {@code retainAll} and
 391.280 +     * {@code clear} operations.  It does not support the
 391.281 +     * {@code add} or {@code addAll} operations.
 391.282 +     *
 391.283 +     * @return a set view of the mappings contained in this map,
 391.284 +     *         sorted in ascending key order
 391.285 +     */
 391.286 +    Set<Map.Entry<K, V>> entrySet();
 391.287 +}
   392.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   392.2 +++ b/rt/emul/compact/src/main/java/java/util/SortedSet.java	Wed Feb 27 11:24:58 2013 +0100
   392.3 @@ -0,0 +1,222 @@
   392.4 +/*
   392.5 + * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
   392.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   392.7 + *
   392.8 + * This code is free software; you can redistribute it and/or modify it
   392.9 + * under the terms of the GNU General Public License version 2 only, as
  392.10 + * published by the Free Software Foundation.  Oracle designates this
  392.11 + * particular file as subject to the "Classpath" exception as provided
  392.12 + * by Oracle in the LICENSE file that accompanied this code.
  392.13 + *
  392.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  392.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  392.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  392.17 + * version 2 for more details (a copy is included in the LICENSE file that
  392.18 + * accompanied this code).
  392.19 + *
  392.20 + * You should have received a copy of the GNU General Public License version
  392.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  392.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  392.23 + *
  392.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  392.25 + * or visit www.oracle.com if you need additional information or have any
  392.26 + * questions.
  392.27 + */
  392.28 +
  392.29 +package java.util;
  392.30 +
  392.31 +/**
  392.32 + * A {@link Set} that further provides a <i>total ordering</i> on its elements.
  392.33 + * The elements are ordered using their {@linkplain Comparable natural
  392.34 + * ordering}, or by a {@link Comparator} typically provided at sorted
  392.35 + * set creation time.  The set's iterator will traverse the set in
  392.36 + * ascending element order. Several additional operations are provided
  392.37 + * to take advantage of the ordering.  (This interface is the set
  392.38 + * analogue of {@link SortedMap}.)
  392.39 + *
  392.40 + * <p>All elements inserted into a sorted set must implement the <tt>Comparable</tt>
  392.41 + * interface (or be accepted by the specified comparator).  Furthermore, all
  392.42 + * such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt>
  392.43 + * (or <tt>comparator.compare(e1, e2)</tt>) must not throw a
  392.44 + * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in
  392.45 + * the sorted set.  Attempts to violate this restriction will cause the
  392.46 + * offending method or constructor invocation to throw a
  392.47 + * <tt>ClassCastException</tt>.
  392.48 + *
  392.49 + * <p>Note that the ordering maintained by a sorted set (whether or not an
  392.50 + * explicit comparator is provided) must be <i>consistent with equals</i> if
  392.51 + * the sorted set is to correctly implement the <tt>Set</tt> interface.  (See
  392.52 + * the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a
  392.53 + * precise definition of <i>consistent with equals</i>.)  This is so because
  392.54 + * the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt>
  392.55 + * operation, but a sorted set performs all element comparisons using its
  392.56 + * <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are
  392.57 + * deemed equal by this method are, from the standpoint of the sorted set,
  392.58 + * equal.  The behavior of a sorted set <i>is</i> well-defined even if its
  392.59 + * ordering is inconsistent with equals; it just fails to obey the general
  392.60 + * contract of the <tt>Set</tt> interface.
  392.61 + *
  392.62 + * <p>All general-purpose sorted set implementation classes should
  392.63 + * provide four "standard" constructors: 1) A void (no arguments)
  392.64 + * constructor, which creates an empty sorted set sorted according to
  392.65 + * the natural ordering of its elements.  2) A constructor with a
  392.66 + * single argument of type <tt>Comparator</tt>, which creates an empty
  392.67 + * sorted set sorted according to the specified comparator.  3) A
  392.68 + * constructor with a single argument of type <tt>Collection</tt>,
  392.69 + * which creates a new sorted set with the same elements as its
  392.70 + * argument, sorted according to the natural ordering of the elements.
  392.71 + * 4) A constructor with a single argument of type <tt>SortedSet</tt>,
  392.72 + * which creates a new sorted set with the same elements and the same
  392.73 + * ordering as the input sorted set.  There is no way to enforce this
  392.74 + * recommendation, as interfaces cannot contain constructors.
  392.75 + *
  392.76 + * <p>Note: several methods return subsets with restricted ranges.
  392.77 + * Such ranges are <i>half-open</i>, that is, they include their low
  392.78 + * endpoint but not their high endpoint (where applicable).
  392.79 + * If you need a <i>closed range</i> (which includes both endpoints), and
  392.80 + * the element type allows for calculation of the successor of a given
  392.81 + * value, merely request the subrange from <tt>lowEndpoint</tt> to
  392.82 + * <tt>successor(highEndpoint)</tt>.  For example, suppose that <tt>s</tt>
  392.83 + * is a sorted set of strings.  The following idiom obtains a view
  392.84 + * containing all of the strings in <tt>s</tt> from <tt>low</tt> to
  392.85 + * <tt>high</tt>, inclusive:<pre>
  392.86 + *   SortedSet&lt;String&gt; sub = s.subSet(low, high+"\0");</pre>
  392.87 + *
  392.88 + * A similar technique can be used to generate an <i>open range</i> (which
  392.89 + * contains neither endpoint).  The following idiom obtains a view
  392.90 + * containing all of the Strings in <tt>s</tt> from <tt>low</tt> to
  392.91 + * <tt>high</tt>, exclusive:<pre>
  392.92 + *   SortedSet&lt;String&gt; sub = s.subSet(low+"\0", high);</pre>
  392.93 + *
  392.94 + * <p>This interface is a member of the
  392.95 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  392.96 + * Java Collections Framework</a>.
  392.97 + *
  392.98 + * @param <E> the type of elements maintained by this set
  392.99 + *
 392.100 + * @author  Josh Bloch
 392.101 + * @see Set
 392.102 + * @see TreeSet
 392.103 + * @see SortedMap
 392.104 + * @see Collection
 392.105 + * @see Comparable
 392.106 + * @see Comparator
 392.107 + * @see ClassCastException
 392.108 + * @since 1.2
 392.109 + */
 392.110 +
 392.111 +public interface SortedSet<E> extends Set<E> {
 392.112 +    /**
 392.113 +     * Returns the comparator used to order the elements in this set,
 392.114 +     * or <tt>null</tt> if this set uses the {@linkplain Comparable
 392.115 +     * natural ordering} of its elements.
 392.116 +     *
 392.117 +     * @return the comparator used to order the elements in this set,
 392.118 +     *         or <tt>null</tt> if this set uses the natural ordering
 392.119 +     *         of its elements
 392.120 +     */
 392.121 +    Comparator<? super E> comparator();
 392.122 +
 392.123 +    /**
 392.124 +     * Returns a view of the portion of this set whose elements range
 392.125 +     * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
 392.126 +     * exclusive.  (If <tt>fromElement</tt> and <tt>toElement</tt> are
 392.127 +     * equal, the returned set is empty.)  The returned set is backed
 392.128 +     * by this set, so changes in the returned set are reflected in
 392.129 +     * this set, and vice-versa.  The returned set supports all
 392.130 +     * optional set operations that this set supports.
 392.131 +     *
 392.132 +     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 392.133 +     * on an attempt to insert an element outside its range.
 392.134 +     *
 392.135 +     * @param fromElement low endpoint (inclusive) of the returned set
 392.136 +     * @param toElement high endpoint (exclusive) of the returned set
 392.137 +     * @return a view of the portion of this set whose elements range from
 392.138 +     *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
 392.139 +     * @throws ClassCastException if <tt>fromElement</tt> and
 392.140 +     *         <tt>toElement</tt> cannot be compared to one another using this
 392.141 +     *         set's comparator (or, if the set has no comparator, using
 392.142 +     *         natural ordering).  Implementations may, but are not required
 392.143 +     *         to, throw this exception if <tt>fromElement</tt> or
 392.144 +     *         <tt>toElement</tt> cannot be compared to elements currently in
 392.145 +     *         the set.
 392.146 +     * @throws NullPointerException if <tt>fromElement</tt> or
 392.147 +     *         <tt>toElement</tt> is null and this set does not permit null
 392.148 +     *         elements
 392.149 +     * @throws IllegalArgumentException if <tt>fromElement</tt> is
 392.150 +     *         greater than <tt>toElement</tt>; or if this set itself
 392.151 +     *         has a restricted range, and <tt>fromElement</tt> or
 392.152 +     *         <tt>toElement</tt> lies outside the bounds of the range
 392.153 +     */
 392.154 +    SortedSet<E> subSet(E fromElement, E toElement);
 392.155 +
 392.156 +    /**
 392.157 +     * Returns a view of the portion of this set whose elements are
 392.158 +     * strictly less than <tt>toElement</tt>.  The returned set is
 392.159 +     * backed by this set, so changes in the returned set are
 392.160 +     * reflected in this set, and vice-versa.  The returned set
 392.161 +     * supports all optional set operations that this set supports.
 392.162 +     *
 392.163 +     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 392.164 +     * on an attempt to insert an element outside its range.
 392.165 +     *
 392.166 +     * @param toElement high endpoint (exclusive) of the returned set
 392.167 +     * @return a view of the portion of this set whose elements are strictly
 392.168 +     *         less than <tt>toElement</tt>
 392.169 +     * @throws ClassCastException if <tt>toElement</tt> is not compatible
 392.170 +     *         with this set's comparator (or, if the set has no comparator,
 392.171 +     *         if <tt>toElement</tt> does not implement {@link Comparable}).
 392.172 +     *         Implementations may, but are not required to, throw this
 392.173 +     *         exception if <tt>toElement</tt> cannot be compared to elements
 392.174 +     *         currently in the set.
 392.175 +     * @throws NullPointerException if <tt>toElement</tt> is null and
 392.176 +     *         this set does not permit null elements
 392.177 +     * @throws IllegalArgumentException if this set itself has a
 392.178 +     *         restricted range, and <tt>toElement</tt> lies outside the
 392.179 +     *         bounds of the range
 392.180 +     */
 392.181 +    SortedSet<E> headSet(E toElement);
 392.182 +
 392.183 +    /**
 392.184 +     * Returns a view of the portion of this set whose elements are
 392.185 +     * greater than or equal to <tt>fromElement</tt>.  The returned
 392.186 +     * set is backed by this set, so changes in the returned set are
 392.187 +     * reflected in this set, and vice-versa.  The returned set
 392.188 +     * supports all optional set operations that this set supports.
 392.189 +     *
 392.190 +     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 392.191 +     * on an attempt to insert an element outside its range.
 392.192 +     *
 392.193 +     * @param fromElement low endpoint (inclusive) of the returned set
 392.194 +     * @return a view of the portion of this set whose elements are greater
 392.195 +     *         than or equal to <tt>fromElement</tt>
 392.196 +     * @throws ClassCastException if <tt>fromElement</tt> is not compatible
 392.197 +     *         with this set's comparator (or, if the set has no comparator,
 392.198 +     *         if <tt>fromElement</tt> does not implement {@link Comparable}).
 392.199 +     *         Implementations may, but are not required to, throw this
 392.200 +     *         exception if <tt>fromElement</tt> cannot be compared to elements
 392.201 +     *         currently in the set.
 392.202 +     * @throws NullPointerException if <tt>fromElement</tt> is null
 392.203 +     *         and this set does not permit null elements
 392.204 +     * @throws IllegalArgumentException if this set itself has a
 392.205 +     *         restricted range, and <tt>fromElement</tt> lies outside the
 392.206 +     *         bounds of the range
 392.207 +     */
 392.208 +    SortedSet<E> tailSet(E fromElement);
 392.209 +
 392.210 +    /**
 392.211 +     * Returns the first (lowest) element currently in this set.
 392.212 +     *
 392.213 +     * @return the first (lowest) element currently in this set
 392.214 +     * @throws NoSuchElementException if this set is empty
 392.215 +     */
 392.216 +    E first();
 392.217 +
 392.218 +    /**
 392.219 +     * Returns the last (highest) element currently in this set.
 392.220 +     *
 392.221 +     * @return the last (highest) element currently in this set
 392.222 +     * @throws NoSuchElementException if this set is empty
 392.223 +     */
 392.224 +    E last();
 392.225 +}
   393.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   393.2 +++ b/rt/emul/compact/src/main/java/java/util/Stack.java	Wed Feb 27 11:24:58 2013 +0100
   393.3 @@ -0,0 +1,141 @@
   393.4 +/*
   393.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   393.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   393.7 + *
   393.8 + * This code is free software; you can redistribute it and/or modify it
   393.9 + * under the terms of the GNU General Public License version 2 only, as
  393.10 + * published by the Free Software Foundation.  Oracle designates this
  393.11 + * particular file as subject to the "Classpath" exception as provided
  393.12 + * by Oracle in the LICENSE file that accompanied this code.
  393.13 + *
  393.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  393.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  393.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  393.17 + * version 2 for more details (a copy is included in the LICENSE file that
  393.18 + * accompanied this code).
  393.19 + *
  393.20 + * You should have received a copy of the GNU General Public License version
  393.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  393.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  393.23 + *
  393.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  393.25 + * or visit www.oracle.com if you need additional information or have any
  393.26 + * questions.
  393.27 + */
  393.28 +
  393.29 +package java.util;
  393.30 +
  393.31 +/**
  393.32 + * The <code>Stack</code> class represents a last-in-first-out
  393.33 + * (LIFO) stack of objects. It extends class <tt>Vector</tt> with five
  393.34 + * operations that allow a vector to be treated as a stack. The usual
  393.35 + * <tt>push</tt> and <tt>pop</tt> operations are provided, as well as a
  393.36 + * method to <tt>peek</tt> at the top item on the stack, a method to test
  393.37 + * for whether the stack is <tt>empty</tt>, and a method to <tt>search</tt>
  393.38 + * the stack for an item and discover how far it is from the top.
  393.39 + * <p>
  393.40 + * When a stack is first created, it contains no items.
  393.41 + *
  393.42 + * <p>A more complete and consistent set of LIFO stack operations is
  393.43 + * provided by the {@link Deque} interface and its implementations, which
  393.44 + * should be used in preference to this class.  For example:
  393.45 + * <pre>   {@code
  393.46 + *   Deque<Integer> stack = new ArrayDeque<Integer>();}</pre>
  393.47 + *
  393.48 + * @author  Jonathan Payne
  393.49 + * @since   JDK1.0
  393.50 + */
  393.51 +public
  393.52 +class Stack<E> extends Vector<E> {
  393.53 +    /**
  393.54 +     * Creates an empty Stack.
  393.55 +     */
  393.56 +    public Stack() {
  393.57 +    }
  393.58 +
  393.59 +    /**
  393.60 +     * Pushes an item onto the top of this stack. This has exactly
  393.61 +     * the same effect as:
  393.62 +     * <blockquote><pre>
  393.63 +     * addElement(item)</pre></blockquote>
  393.64 +     *
  393.65 +     * @param   item   the item to be pushed onto this stack.
  393.66 +     * @return  the <code>item</code> argument.
  393.67 +     * @see     java.util.Vector#addElement
  393.68 +     */
  393.69 +    public E push(E item) {
  393.70 +        addElement(item);
  393.71 +
  393.72 +        return item;
  393.73 +    }
  393.74 +
  393.75 +    /**
  393.76 +     * Removes the object at the top of this stack and returns that
  393.77 +     * object as the value of this function.
  393.78 +     *
  393.79 +     * @return  The object at the top of this stack (the last item
  393.80 +     *          of the <tt>Vector</tt> object).
  393.81 +     * @throws  EmptyStackException  if this stack is empty.
  393.82 +     */
  393.83 +    public synchronized E pop() {
  393.84 +        E       obj;
  393.85 +        int     len = size();
  393.86 +
  393.87 +        obj = peek();
  393.88 +        removeElementAt(len - 1);
  393.89 +
  393.90 +        return obj;
  393.91 +    }
  393.92 +
  393.93 +    /**
  393.94 +     * Looks at the object at the top of this stack without removing it
  393.95 +     * from the stack.
  393.96 +     *
  393.97 +     * @return  the object at the top of this stack (the last item
  393.98 +     *          of the <tt>Vector</tt> object).
  393.99 +     * @throws  EmptyStackException  if this stack is empty.
 393.100 +     */
 393.101 +    public synchronized E peek() {
 393.102 +        int     len = size();
 393.103 +
 393.104 +        if (len == 0)
 393.105 +            throw new EmptyStackException();
 393.106 +        return elementAt(len - 1);
 393.107 +    }
 393.108 +
 393.109 +    /**
 393.110 +     * Tests if this stack is empty.
 393.111 +     *
 393.112 +     * @return  <code>true</code> if and only if this stack contains
 393.113 +     *          no items; <code>false</code> otherwise.
 393.114 +     */
 393.115 +    public boolean empty() {
 393.116 +        return size() == 0;
 393.117 +    }
 393.118 +
 393.119 +    /**
 393.120 +     * Returns the 1-based position where an object is on this stack.
 393.121 +     * If the object <tt>o</tt> occurs as an item in this stack, this
 393.122 +     * method returns the distance from the top of the stack of the
 393.123 +     * occurrence nearest the top of the stack; the topmost item on the
 393.124 +     * stack is considered to be at distance <tt>1</tt>. The <tt>equals</tt>
 393.125 +     * method is used to compare <tt>o</tt> to the
 393.126 +     * items in this stack.
 393.127 +     *
 393.128 +     * @param   o   the desired object.
 393.129 +     * @return  the 1-based position from the top of the stack where
 393.130 +     *          the object is located; the return value <code>-1</code>
 393.131 +     *          indicates that the object is not on the stack.
 393.132 +     */
 393.133 +    public synchronized int search(Object o) {
 393.134 +        int i = lastIndexOf(o);
 393.135 +
 393.136 +        if (i >= 0) {
 393.137 +            return size() - i;
 393.138 +        }
 393.139 +        return -1;
 393.140 +    }
 393.141 +
 393.142 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 393.143 +    private static final long serialVersionUID = 1224463164541339165L;
 393.144 +}
   394.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   394.2 +++ b/rt/emul/compact/src/main/java/java/util/StringTokenizer.java	Wed Feb 27 11:24:58 2013 +0100
   394.3 @@ -0,0 +1,431 @@
   394.4 +/*
   394.5 + * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
   394.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   394.7 + *
   394.8 + * This code is free software; you can redistribute it and/or modify it
   394.9 + * under the terms of the GNU General Public License version 2 only, as
  394.10 + * published by the Free Software Foundation.  Oracle designates this
  394.11 + * particular file as subject to the "Classpath" exception as provided
  394.12 + * by Oracle in the LICENSE file that accompanied this code.
  394.13 + *
  394.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  394.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  394.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  394.17 + * version 2 for more details (a copy is included in the LICENSE file that
  394.18 + * accompanied this code).
  394.19 + *
  394.20 + * You should have received a copy of the GNU General Public License version
  394.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  394.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  394.23 + *
  394.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  394.25 + * or visit www.oracle.com if you need additional information or have any
  394.26 + * questions.
  394.27 + */
  394.28 +
  394.29 +package java.util;
  394.30 +
  394.31 +import java.lang.*;
  394.32 +
  394.33 +/**
  394.34 + * The string tokenizer class allows an application to break a
  394.35 + * string into tokens. The tokenization method is much simpler than
  394.36 + * the one used by the <code>StreamTokenizer</code> class. The
  394.37 + * <code>StringTokenizer</code> methods do not distinguish among
  394.38 + * identifiers, numbers, and quoted strings, nor do they recognize
  394.39 + * and skip comments.
  394.40 + * <p>
  394.41 + * The set of delimiters (the characters that separate tokens) may
  394.42 + * be specified either at creation time or on a per-token basis.
  394.43 + * <p>
  394.44 + * An instance of <code>StringTokenizer</code> behaves in one of two
  394.45 + * ways, depending on whether it was created with the
  394.46 + * <code>returnDelims</code> flag having the value <code>true</code>
  394.47 + * or <code>false</code>:
  394.48 + * <ul>
  394.49 + * <li>If the flag is <code>false</code>, delimiter characters serve to
  394.50 + *     separate tokens. A token is a maximal sequence of consecutive
  394.51 + *     characters that are not delimiters.
  394.52 + * <li>If the flag is <code>true</code>, delimiter characters are themselves
  394.53 + *     considered to be tokens. A token is thus either one delimiter
  394.54 + *     character, or a maximal sequence of consecutive characters that are
  394.55 + *     not delimiters.
  394.56 + * </ul><p>
  394.57 + * A <tt>StringTokenizer</tt> object internally maintains a current
  394.58 + * position within the string to be tokenized. Some operations advance this
  394.59 + * current position past the characters processed.<p>
  394.60 + * A token is returned by taking a substring of the string that was used to
  394.61 + * create the <tt>StringTokenizer</tt> object.
  394.62 + * <p>
  394.63 + * The following is one example of the use of the tokenizer. The code:
  394.64 + * <blockquote><pre>
  394.65 + *     StringTokenizer st = new StringTokenizer("this is a test");
  394.66 + *     while (st.hasMoreTokens()) {
  394.67 + *         System.out.println(st.nextToken());
  394.68 + *     }
  394.69 + * </pre></blockquote>
  394.70 + * <p>
  394.71 + * prints the following output:
  394.72 + * <blockquote><pre>
  394.73 + *     this
  394.74 + *     is
  394.75 + *     a
  394.76 + *     test
  394.77 + * </pre></blockquote>
  394.78 + *
  394.79 + * <p>
  394.80 + * <tt>StringTokenizer</tt> is a legacy class that is retained for
  394.81 + * compatibility reasons although its use is discouraged in new code. It is
  394.82 + * recommended that anyone seeking this functionality use the <tt>split</tt>
  394.83 + * method of <tt>String</tt> or the java.util.regex package instead.
  394.84 + * <p>
  394.85 + * The following example illustrates how the <tt>String.split</tt>
  394.86 + * method can be used to break up a string into its basic tokens:
  394.87 + * <blockquote><pre>
  394.88 + *     String[] result = "this is a test".split("\\s");
  394.89 + *     for (int x=0; x&lt;result.length; x++)
  394.90 + *         System.out.println(result[x]);
  394.91 + * </pre></blockquote>
  394.92 + * <p>
  394.93 + * prints the following output:
  394.94 + * <blockquote><pre>
  394.95 + *     this
  394.96 + *     is
  394.97 + *     a
  394.98 + *     test
  394.99 + * </pre></blockquote>
 394.100 + *
 394.101 + * @author  unascribed
 394.102 + * @see     java.io.StreamTokenizer
 394.103 + * @since   JDK1.0
 394.104 + */
 394.105 +public
 394.106 +class StringTokenizer implements Enumeration<Object> {
 394.107 +    private int currentPosition;
 394.108 +    private int newPosition;
 394.109 +    private int maxPosition;
 394.110 +    private String str;
 394.111 +    private String delimiters;
 394.112 +    private boolean retDelims;
 394.113 +    private boolean delimsChanged;
 394.114 +
 394.115 +    /**
 394.116 +     * maxDelimCodePoint stores the value of the delimiter character with the
 394.117 +     * highest value. It is used to optimize the detection of delimiter
 394.118 +     * characters.
 394.119 +     *
 394.120 +     * It is unlikely to provide any optimization benefit in the
 394.121 +     * hasSurrogates case because most string characters will be
 394.122 +     * smaller than the limit, but we keep it so that the two code
 394.123 +     * paths remain similar.
 394.124 +     */
 394.125 +    private int maxDelimCodePoint;
 394.126 +
 394.127 +    /**
 394.128 +     * If delimiters include any surrogates (including surrogate
 394.129 +     * pairs), hasSurrogates is true and the tokenizer uses the
 394.130 +     * different code path. This is because String.indexOf(int)
 394.131 +     * doesn't handle unpaired surrogates as a single character.
 394.132 +     */
 394.133 +    private boolean hasSurrogates = false;
 394.134 +
 394.135 +    /**
 394.136 +     * When hasSurrogates is true, delimiters are converted to code
 394.137 +     * points and isDelimiter(int) is used to determine if the given
 394.138 +     * codepoint is a delimiter.
 394.139 +     */
 394.140 +    private int[] delimiterCodePoints;
 394.141 +
 394.142 +    /**
 394.143 +     * Set maxDelimCodePoint to the highest char in the delimiter set.
 394.144 +     */
 394.145 +    private void setMaxDelimCodePoint() {
 394.146 +        if (delimiters == null) {
 394.147 +            maxDelimCodePoint = 0;
 394.148 +            return;
 394.149 +        }
 394.150 +
 394.151 +        int m = 0;
 394.152 +        int c;
 394.153 +        int count = 0;
 394.154 +        for (int i = 0; i < delimiters.length(); i += Character.charCount(c)) {
 394.155 +            c = delimiters.charAt(i);
 394.156 +            if (c >= Character.MIN_HIGH_SURROGATE && c <= Character.MAX_LOW_SURROGATE) {
 394.157 +                c = delimiters.codePointAt(i);
 394.158 +                hasSurrogates = true;
 394.159 +            }
 394.160 +            if (m < c)
 394.161 +                m = c;
 394.162 +            count++;
 394.163 +        }
 394.164 +        maxDelimCodePoint = m;
 394.165 +
 394.166 +        if (hasSurrogates) {
 394.167 +            delimiterCodePoints = new int[count];
 394.168 +            for (int i = 0, j = 0; i < count; i++, j += Character.charCount(c)) {
 394.169 +                c = delimiters.codePointAt(j);
 394.170 +                delimiterCodePoints[i] = c;
 394.171 +            }
 394.172 +        }
 394.173 +    }
 394.174 +
 394.175 +    /**
 394.176 +     * Constructs a string tokenizer for the specified string. All
 394.177 +     * characters in the <code>delim</code> argument are the delimiters
 394.178 +     * for separating tokens.
 394.179 +     * <p>
 394.180 +     * If the <code>returnDelims</code> flag is <code>true</code>, then
 394.181 +     * the delimiter characters are also returned as tokens. Each
 394.182 +     * delimiter is returned as a string of length one. If the flag is
 394.183 +     * <code>false</code>, the delimiter characters are skipped and only
 394.184 +     * serve as separators between tokens.
 394.185 +     * <p>
 394.186 +     * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does
 394.187 +     * not throw an exception. However, trying to invoke other methods on the
 394.188 +     * resulting <tt>StringTokenizer</tt> may result in a
 394.189 +     * <tt>NullPointerException</tt>.
 394.190 +     *
 394.191 +     * @param   str            a string to be parsed.
 394.192 +     * @param   delim          the delimiters.
 394.193 +     * @param   returnDelims   flag indicating whether to return the delimiters
 394.194 +     *                         as tokens.
 394.195 +     * @exception NullPointerException if str is <CODE>null</CODE>
 394.196 +     */
 394.197 +    public StringTokenizer(String str, String delim, boolean returnDelims) {
 394.198 +        currentPosition = 0;
 394.199 +        newPosition = -1;
 394.200 +        delimsChanged = false;
 394.201 +        this.str = str;
 394.202 +        maxPosition = str.length();
 394.203 +        delimiters = delim;
 394.204 +        retDelims = returnDelims;
 394.205 +        setMaxDelimCodePoint();
 394.206 +    }
 394.207 +
 394.208 +    /**
 394.209 +     * Constructs a string tokenizer for the specified string. The
 394.210 +     * characters in the <code>delim</code> argument are the delimiters
 394.211 +     * for separating tokens. Delimiter characters themselves will not
 394.212 +     * be treated as tokens.
 394.213 +     * <p>
 394.214 +     * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does
 394.215 +     * not throw an exception. However, trying to invoke other methods on the
 394.216 +     * resulting <tt>StringTokenizer</tt> may result in a
 394.217 +     * <tt>NullPointerException</tt>.
 394.218 +     *
 394.219 +     * @param   str     a string to be parsed.
 394.220 +     * @param   delim   the delimiters.
 394.221 +     * @exception NullPointerException if str is <CODE>null</CODE>
 394.222 +     */
 394.223 +    public StringTokenizer(String str, String delim) {
 394.224 +        this(str, delim, false);
 394.225 +    }
 394.226 +
 394.227 +    /**
 394.228 +     * Constructs a string tokenizer for the specified string. The
 394.229 +     * tokenizer uses the default delimiter set, which is
 394.230 +     * <code>"&nbsp;&#92;t&#92;n&#92;r&#92;f"</code>: the space character,
 394.231 +     * the tab character, the newline character, the carriage-return character,
 394.232 +     * and the form-feed character. Delimiter characters themselves will
 394.233 +     * not be treated as tokens.
 394.234 +     *
 394.235 +     * @param   str   a string to be parsed.
 394.236 +     * @exception NullPointerException if str is <CODE>null</CODE>
 394.237 +     */
 394.238 +    public StringTokenizer(String str) {
 394.239 +        this(str, " \t\n\r\f", false);
 394.240 +    }
 394.241 +
 394.242 +    /**
 394.243 +     * Skips delimiters starting from the specified position. If retDelims
 394.244 +     * is false, returns the index of the first non-delimiter character at or
 394.245 +     * after startPos. If retDelims is true, startPos is returned.
 394.246 +     */
 394.247 +    private int skipDelimiters(int startPos) {
 394.248 +        if (delimiters == null)
 394.249 +            throw new NullPointerException();
 394.250 +
 394.251 +        int position = startPos;
 394.252 +        while (!retDelims && position < maxPosition) {
 394.253 +            if (!hasSurrogates) {
 394.254 +                char c = str.charAt(position);
 394.255 +                if ((c > maxDelimCodePoint) || (delimiters.indexOf(c) < 0))
 394.256 +                    break;
 394.257 +                position++;
 394.258 +            } else {
 394.259 +                int c = str.codePointAt(position);
 394.260 +                if ((c > maxDelimCodePoint) || !isDelimiter(c)) {
 394.261 +                    break;
 394.262 +                }
 394.263 +                position += Character.charCount(c);
 394.264 +            }
 394.265 +        }
 394.266 +        return position;
 394.267 +    }
 394.268 +
 394.269 +    /**
 394.270 +     * Skips ahead from startPos and returns the index of the next delimiter
 394.271 +     * character encountered, or maxPosition if no such delimiter is found.
 394.272 +     */
 394.273 +    private int scanToken(int startPos) {
 394.274 +        int position = startPos;
 394.275 +        while (position < maxPosition) {
 394.276 +            if (!hasSurrogates) {
 394.277 +                char c = str.charAt(position);
 394.278 +                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
 394.279 +                    break;
 394.280 +                position++;
 394.281 +            } else {
 394.282 +                int c = str.codePointAt(position);
 394.283 +                if ((c <= maxDelimCodePoint) && isDelimiter(c))
 394.284 +                    break;
 394.285 +                position += Character.charCount(c);
 394.286 +            }
 394.287 +        }
 394.288 +        if (retDelims && (startPos == position)) {
 394.289 +            if (!hasSurrogates) {
 394.290 +                char c = str.charAt(position);
 394.291 +                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
 394.292 +                    position++;
 394.293 +            } else {
 394.294 +                int c = str.codePointAt(position);
 394.295 +                if ((c <= maxDelimCodePoint) && isDelimiter(c))
 394.296 +                    position += Character.charCount(c);
 394.297 +            }
 394.298 +        }
 394.299 +        return position;
 394.300 +    }
 394.301 +
 394.302 +    private boolean isDelimiter(int codePoint) {
 394.303 +        for (int i = 0; i < delimiterCodePoints.length; i++) {
 394.304 +            if (delimiterCodePoints[i] == codePoint) {
 394.305 +                return true;
 394.306 +            }
 394.307 +        }
 394.308 +        return false;
 394.309 +    }
 394.310 +
 394.311 +    /**
 394.312 +     * Tests if there are more tokens available from this tokenizer's string.
 394.313 +     * If this method returns <tt>true</tt>, then a subsequent call to
 394.314 +     * <tt>nextToken</tt> with no argument will successfully return a token.
 394.315 +     *
 394.316 +     * @return  <code>true</code> if and only if there is at least one token
 394.317 +     *          in the string after the current position; <code>false</code>
 394.318 +     *          otherwise.
 394.319 +     */
 394.320 +    public boolean hasMoreTokens() {
 394.321 +        /*
 394.322 +         * Temporarily store this position and use it in the following
 394.323 +         * nextToken() method only if the delimiters haven't been changed in
 394.324 +         * that nextToken() invocation.
 394.325 +         */
 394.326 +        newPosition = skipDelimiters(currentPosition);
 394.327 +        return (newPosition < maxPosition);
 394.328 +    }
 394.329 +
 394.330 +    /**
 394.331 +     * Returns the next token from this string tokenizer.
 394.332 +     *
 394.333 +     * @return     the next token from this string tokenizer.
 394.334 +     * @exception  NoSuchElementException  if there are no more tokens in this
 394.335 +     *               tokenizer's string.
 394.336 +     */
 394.337 +    public String nextToken() {
 394.338 +        /*
 394.339 +         * If next position already computed in hasMoreElements() and
 394.340 +         * delimiters have changed between the computation and this invocation,
 394.341 +         * then use the computed value.
 394.342 +         */
 394.343 +
 394.344 +        currentPosition = (newPosition >= 0 && !delimsChanged) ?
 394.345 +            newPosition : skipDelimiters(currentPosition);
 394.346 +
 394.347 +        /* Reset these anyway */
 394.348 +        delimsChanged = false;
 394.349 +        newPosition = -1;
 394.350 +
 394.351 +        if (currentPosition >= maxPosition)
 394.352 +            throw new NoSuchElementException();
 394.353 +        int start = currentPosition;
 394.354 +        currentPosition = scanToken(currentPosition);
 394.355 +        return str.substring(start, currentPosition);
 394.356 +    }
 394.357 +
 394.358 +    /**
 394.359 +     * Returns the next token in this string tokenizer's string. First,
 394.360 +     * the set of characters considered to be delimiters by this
 394.361 +     * <tt>StringTokenizer</tt> object is changed to be the characters in
 394.362 +     * the string <tt>delim</tt>. Then the next token in the string
 394.363 +     * after the current position is returned. The current position is
 394.364 +     * advanced beyond the recognized token.  The new delimiter set
 394.365 +     * remains the default after this call.
 394.366 +     *
 394.367 +     * @param      delim   the new delimiters.
 394.368 +     * @return     the next token, after switching to the new delimiter set.
 394.369 +     * @exception  NoSuchElementException  if there are no more tokens in this
 394.370 +     *               tokenizer's string.
 394.371 +     * @exception NullPointerException if delim is <CODE>null</CODE>
 394.372 +     */
 394.373 +    public String nextToken(String delim) {
 394.374 +        delimiters = delim;
 394.375 +
 394.376 +        /* delimiter string specified, so set the appropriate flag. */
 394.377 +        delimsChanged = true;
 394.378 +
 394.379 +        setMaxDelimCodePoint();
 394.380 +        return nextToken();
 394.381 +    }
 394.382 +
 394.383 +    /**
 394.384 +     * Returns the same value as the <code>hasMoreTokens</code>
 394.385 +     * method. It exists so that this class can implement the
 394.386 +     * <code>Enumeration</code> interface.
 394.387 +     *
 394.388 +     * @return  <code>true</code> if there are more tokens;
 394.389 +     *          <code>false</code> otherwise.
 394.390 +     * @see     java.util.Enumeration
 394.391 +     * @see     java.util.StringTokenizer#hasMoreTokens()
 394.392 +     */
 394.393 +    public boolean hasMoreElements() {
 394.394 +        return hasMoreTokens();
 394.395 +    }
 394.396 +
 394.397 +    /**
 394.398 +     * Returns the same value as the <code>nextToken</code> method,
 394.399 +     * except that its declared return value is <code>Object</code> rather than
 394.400 +     * <code>String</code>. It exists so that this class can implement the
 394.401 +     * <code>Enumeration</code> interface.
 394.402 +     *
 394.403 +     * @return     the next token in the string.
 394.404 +     * @exception  NoSuchElementException  if there are no more tokens in this
 394.405 +     *               tokenizer's string.
 394.406 +     * @see        java.util.Enumeration
 394.407 +     * @see        java.util.StringTokenizer#nextToken()
 394.408 +     */
 394.409 +    public Object nextElement() {
 394.410 +        return nextToken();
 394.411 +    }
 394.412 +
 394.413 +    /**
 394.414 +     * Calculates the number of times that this tokenizer's
 394.415 +     * <code>nextToken</code> method can be called before it generates an
 394.416 +     * exception. The current position is not advanced.
 394.417 +     *
 394.418 +     * @return  the number of tokens remaining in the string using the current
 394.419 +     *          delimiter set.
 394.420 +     * @see     java.util.StringTokenizer#nextToken()
 394.421 +     */
 394.422 +    public int countTokens() {
 394.423 +        int count = 0;
 394.424 +        int currpos = currentPosition;
 394.425 +        while (currpos < maxPosition) {
 394.426 +            currpos = skipDelimiters(currpos);
 394.427 +            if (currpos >= maxPosition)
 394.428 +                break;
 394.429 +            currpos = scanToken(currpos);
 394.430 +            count++;
 394.431 +        }
 394.432 +        return count;
 394.433 +    }
 394.434 +}
   395.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   395.2 +++ b/rt/emul/compact/src/main/java/java/util/TimSort.java	Wed Feb 27 11:24:58 2013 +0100
   395.3 @@ -0,0 +1,929 @@
   395.4 +/*
   395.5 + * Copyright 2009 Google Inc.  All Rights Reserved.
   395.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   395.7 + *
   395.8 + * This code is free software; you can redistribute it and/or modify it
   395.9 + * under the terms of the GNU General Public License version 2 only, as
  395.10 + * published by the Free Software Foundation.  Oracle designates this
  395.11 + * particular file as subject to the "Classpath" exception as provided
  395.12 + * by Oracle in the LICENSE file that accompanied this code.
  395.13 + *
  395.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  395.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  395.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  395.17 + * version 2 for more details (a copy is included in the LICENSE file that
  395.18 + * accompanied this code).
  395.19 + *
  395.20 + * You should have received a copy of the GNU General Public License version
  395.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  395.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  395.23 + *
  395.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  395.25 + * or visit www.oracle.com if you need additional information or have any
  395.26 + * questions.
  395.27 + */
  395.28 +
  395.29 +package java.util;
  395.30 +
  395.31 +
  395.32 +/**
  395.33 + * A stable, adaptive, iterative mergesort that requires far fewer than
  395.34 + * n lg(n) comparisons when running on partially sorted arrays, while
  395.35 + * offering performance comparable to a traditional mergesort when run
  395.36 + * on random arrays.  Like all proper mergesorts, this sort is stable and
  395.37 + * runs O(n log n) time (worst case).  In the worst case, this sort requires
  395.38 + * temporary storage space for n/2 object references; in the best case,
  395.39 + * it requires only a small constant amount of space.
  395.40 + *
  395.41 + * This implementation was adapted from Tim Peters's list sort for
  395.42 + * Python, which is described in detail here:
  395.43 + *
  395.44 + *   http://svn.python.org/projects/python/trunk/Objects/listsort.txt
  395.45 + *
  395.46 + * Tim's C code may be found here:
  395.47 + *
  395.48 + *   http://svn.python.org/projects/python/trunk/Objects/listobject.c
  395.49 + *
  395.50 + * The underlying techniques are described in this paper (and may have
  395.51 + * even earlier origins):
  395.52 + *
  395.53 + *  "Optimistic Sorting and Information Theoretic Complexity"
  395.54 + *  Peter McIlroy
  395.55 + *  SODA (Fourth Annual ACM-SIAM Symposium on Discrete Algorithms),
  395.56 + *  pp 467-474, Austin, Texas, 25-27 January 1993.
  395.57 + *
  395.58 + * While the API to this class consists solely of static methods, it is
  395.59 + * (privately) instantiable; a TimSort instance holds the state of an ongoing
  395.60 + * sort, assuming the input array is large enough to warrant the full-blown
  395.61 + * TimSort. Small arrays are sorted in place, using a binary insertion sort.
  395.62 + *
  395.63 + * @author Josh Bloch
  395.64 + */
  395.65 +class TimSort<T> {
  395.66 +    /**
  395.67 +     * This is the minimum sized sequence that will be merged.  Shorter
  395.68 +     * sequences will be lengthened by calling binarySort.  If the entire
  395.69 +     * array is less than this length, no merges will be performed.
  395.70 +     *
  395.71 +     * This constant should be a power of two.  It was 64 in Tim Peter's C
  395.72 +     * implementation, but 32 was empirically determined to work better in
  395.73 +     * this implementation.  In the unlikely event that you set this constant
  395.74 +     * to be a number that's not a power of two, you'll need to change the
  395.75 +     * {@link #minRunLength} computation.
  395.76 +     *
  395.77 +     * If you decrease this constant, you must change the stackLen
  395.78 +     * computation in the TimSort constructor, or you risk an
  395.79 +     * ArrayOutOfBounds exception.  See listsort.txt for a discussion
  395.80 +     * of the minimum stack length required as a function of the length
  395.81 +     * of the array being sorted and the minimum merge sequence length.
  395.82 +     */
  395.83 +    private static final int MIN_MERGE = 32;
  395.84 +
  395.85 +    /**
  395.86 +     * The array being sorted.
  395.87 +     */
  395.88 +    private final T[] a;
  395.89 +
  395.90 +    /**
  395.91 +     * The comparator for this sort.
  395.92 +     */
  395.93 +    private final Comparator<? super T> c;
  395.94 +
  395.95 +    /**
  395.96 +     * When we get into galloping mode, we stay there until both runs win less
  395.97 +     * often than MIN_GALLOP consecutive times.
  395.98 +     */
  395.99 +    private static final int  MIN_GALLOP = 7;
 395.100 +
 395.101 +    /**
 395.102 +     * This controls when we get *into* galloping mode.  It is initialized
 395.103 +     * to MIN_GALLOP.  The mergeLo and mergeHi methods nudge it higher for
 395.104 +     * random data, and lower for highly structured data.
 395.105 +     */
 395.106 +    private int minGallop = MIN_GALLOP;
 395.107 +
 395.108 +    /**
 395.109 +     * Maximum initial size of tmp array, which is used for merging.  The array
 395.110 +     * can grow to accommodate demand.
 395.111 +     *
 395.112 +     * Unlike Tim's original C version, we do not allocate this much storage
 395.113 +     * when sorting smaller arrays.  This change was required for performance.
 395.114 +     */
 395.115 +    private static final int INITIAL_TMP_STORAGE_LENGTH = 256;
 395.116 +
 395.117 +    /**
 395.118 +     * Temp storage for merges.
 395.119 +     */
 395.120 +    private T[] tmp; // Actual runtime type will be Object[], regardless of T
 395.121 +
 395.122 +    /**
 395.123 +     * A stack of pending runs yet to be merged.  Run i starts at
 395.124 +     * address base[i] and extends for len[i] elements.  It's always
 395.125 +     * true (so long as the indices are in bounds) that:
 395.126 +     *
 395.127 +     *     runBase[i] + runLen[i] == runBase[i + 1]
 395.128 +     *
 395.129 +     * so we could cut the storage for this, but it's a minor amount,
 395.130 +     * and keeping all the info explicit simplifies the code.
 395.131 +     */
 395.132 +    private int stackSize = 0;  // Number of pending runs on stack
 395.133 +    private final int[] runBase;
 395.134 +    private final int[] runLen;
 395.135 +
 395.136 +    /**
 395.137 +     * Creates a TimSort instance to maintain the state of an ongoing sort.
 395.138 +     *
 395.139 +     * @param a the array to be sorted
 395.140 +     * @param c the comparator to determine the order of the sort
 395.141 +     */
 395.142 +    private TimSort(T[] a, Comparator<? super T> c) {
 395.143 +        this.a = a;
 395.144 +        this.c = c;
 395.145 +
 395.146 +        // Allocate temp storage (which may be increased later if necessary)
 395.147 +        int len = a.length;
 395.148 +        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
 395.149 +        T[] newArray = (T[]) new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
 395.150 +                                        len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
 395.151 +        tmp = newArray;
 395.152 +
 395.153 +        /*
 395.154 +         * Allocate runs-to-be-merged stack (which cannot be expanded).  The
 395.155 +         * stack length requirements are described in listsort.txt.  The C
 395.156 +         * version always uses the same stack length (85), but this was
 395.157 +         * measured to be too expensive when sorting "mid-sized" arrays (e.g.,
 395.158 +         * 100 elements) in Java.  Therefore, we use smaller (but sufficiently
 395.159 +         * large) stack lengths for smaller arrays.  The "magic numbers" in the
 395.160 +         * computation below must be changed if MIN_MERGE is decreased.  See
 395.161 +         * the MIN_MERGE declaration above for more information.
 395.162 +         */
 395.163 +        int stackLen = (len <    120  ?  5 :
 395.164 +                        len <   1542  ? 10 :
 395.165 +                        len < 119151  ? 19 : 40);
 395.166 +        runBase = new int[stackLen];
 395.167 +        runLen = new int[stackLen];
 395.168 +    }
 395.169 +
 395.170 +    /*
 395.171 +     * The next two methods (which are package private and static) constitute
 395.172 +     * the entire API of this class.  Each of these methods obeys the contract
 395.173 +     * of the public method with the same signature in java.util.Arrays.
 395.174 +     */
 395.175 +
 395.176 +    static <T> void sort(T[] a, Comparator<? super T> c) {
 395.177 +        sort(a, 0, a.length, c);
 395.178 +    }
 395.179 +
 395.180 +    static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c) {
 395.181 +        if (c == null) {
 395.182 +            Arrays.sort(a, lo, hi);
 395.183 +            return;
 395.184 +        }
 395.185 +
 395.186 +        rangeCheck(a.length, lo, hi);
 395.187 +        int nRemaining  = hi - lo;
 395.188 +        if (nRemaining < 2)
 395.189 +            return;  // Arrays of size 0 and 1 are always sorted
 395.190 +
 395.191 +        // If array is small, do a "mini-TimSort" with no merges
 395.192 +        if (nRemaining < MIN_MERGE) {
 395.193 +            int initRunLen = countRunAndMakeAscending(a, lo, hi, c);
 395.194 +            binarySort(a, lo, hi, lo + initRunLen, c);
 395.195 +            return;
 395.196 +        }
 395.197 +
 395.198 +        /**
 395.199 +         * March over the array once, left to right, finding natural runs,
 395.200 +         * extending short natural runs to minRun elements, and merging runs
 395.201 +         * to maintain stack invariant.
 395.202 +         */
 395.203 +        TimSort<T> ts = new TimSort<>(a, c);
 395.204 +        int minRun = minRunLength(nRemaining);
 395.205 +        do {
 395.206 +            // Identify next run
 395.207 +            int runLen = countRunAndMakeAscending(a, lo, hi, c);
 395.208 +
 395.209 +            // If run is short, extend to min(minRun, nRemaining)
 395.210 +            if (runLen < minRun) {
 395.211 +                int force = nRemaining <= minRun ? nRemaining : minRun;
 395.212 +                binarySort(a, lo, lo + force, lo + runLen, c);
 395.213 +                runLen = force;
 395.214 +            }
 395.215 +
 395.216 +            // Push run onto pending-run stack, and maybe merge
 395.217 +            ts.pushRun(lo, runLen);
 395.218 +            ts.mergeCollapse();
 395.219 +
 395.220 +            // Advance to find next run
 395.221 +            lo += runLen;
 395.222 +            nRemaining -= runLen;
 395.223 +        } while (nRemaining != 0);
 395.224 +
 395.225 +        // Merge all remaining runs to complete sort
 395.226 +        assert lo == hi;
 395.227 +        ts.mergeForceCollapse();
 395.228 +        assert ts.stackSize == 1;
 395.229 +    }
 395.230 +
 395.231 +    /**
 395.232 +     * Sorts the specified portion of the specified array using a binary
 395.233 +     * insertion sort.  This is the best method for sorting small numbers
 395.234 +     * of elements.  It requires O(n log n) compares, but O(n^2) data
 395.235 +     * movement (worst case).
 395.236 +     *
 395.237 +     * If the initial part of the specified range is already sorted,
 395.238 +     * this method can take advantage of it: the method assumes that the
 395.239 +     * elements from index {@code lo}, inclusive, to {@code start},
 395.240 +     * exclusive are already sorted.
 395.241 +     *
 395.242 +     * @param a the array in which a range is to be sorted
 395.243 +     * @param lo the index of the first element in the range to be sorted
 395.244 +     * @param hi the index after the last element in the range to be sorted
 395.245 +     * @param start the index of the first element in the range that is
 395.246 +     *        not already known to be sorted ({@code lo <= start <= hi})
 395.247 +     * @param c comparator to used for the sort
 395.248 +     */
 395.249 +    @SuppressWarnings("fallthrough")
 395.250 +    private static <T> void binarySort(T[] a, int lo, int hi, int start,
 395.251 +                                       Comparator<? super T> c) {
 395.252 +        assert lo <= start && start <= hi;
 395.253 +        if (start == lo)
 395.254 +            start++;
 395.255 +        for ( ; start < hi; start++) {
 395.256 +            T pivot = a[start];
 395.257 +
 395.258 +            // Set left (and right) to the index where a[start] (pivot) belongs
 395.259 +            int left = lo;
 395.260 +            int right = start;
 395.261 +            assert left <= right;
 395.262 +            /*
 395.263 +             * Invariants:
 395.264 +             *   pivot >= all in [lo, left).
 395.265 +             *   pivot <  all in [right, start).
 395.266 +             */
 395.267 +            while (left < right) {
 395.268 +                int mid = (left + right) >>> 1;
 395.269 +                if (c.compare(pivot, a[mid]) < 0)
 395.270 +                    right = mid;
 395.271 +                else
 395.272 +                    left = mid + 1;
 395.273 +            }
 395.274 +            assert left == right;
 395.275 +
 395.276 +            /*
 395.277 +             * The invariants still hold: pivot >= all in [lo, left) and
 395.278 +             * pivot < all in [left, start), so pivot belongs at left.  Note
 395.279 +             * that if there are elements equal to pivot, left points to the
 395.280 +             * first slot after them -- that's why this sort is stable.
 395.281 +             * Slide elements over to make room for pivot.
 395.282 +             */
 395.283 +            int n = start - left;  // The number of elements to move
 395.284 +            // Switch is just an optimization for arraycopy in default case
 395.285 +            switch (n) {
 395.286 +                case 2:  a[left + 2] = a[left + 1];
 395.287 +                case 1:  a[left + 1] = a[left];
 395.288 +                         break;
 395.289 +                default: System.arraycopy(a, left, a, left + 1, n);
 395.290 +            }
 395.291 +            a[left] = pivot;
 395.292 +        }
 395.293 +    }
 395.294 +
 395.295 +    /**
 395.296 +     * Returns the length of the run beginning at the specified position in
 395.297 +     * the specified array and reverses the run if it is descending (ensuring
 395.298 +     * that the run will always be ascending when the method returns).
 395.299 +     *
 395.300 +     * A run is the longest ascending sequence with:
 395.301 +     *
 395.302 +     *    a[lo] <= a[lo + 1] <= a[lo + 2] <= ...
 395.303 +     *
 395.304 +     * or the longest descending sequence with:
 395.305 +     *
 395.306 +     *    a[lo] >  a[lo + 1] >  a[lo + 2] >  ...
 395.307 +     *
 395.308 +     * For its intended use in a stable mergesort, the strictness of the
 395.309 +     * definition of "descending" is needed so that the call can safely
 395.310 +     * reverse a descending sequence without violating stability.
 395.311 +     *
 395.312 +     * @param a the array in which a run is to be counted and possibly reversed
 395.313 +     * @param lo index of the first element in the run
 395.314 +     * @param hi index after the last element that may be contained in the run.
 395.315 +              It is required that {@code lo < hi}.
 395.316 +     * @param c the comparator to used for the sort
 395.317 +     * @return  the length of the run beginning at the specified position in
 395.318 +     *          the specified array
 395.319 +     */
 395.320 +    private static <T> int countRunAndMakeAscending(T[] a, int lo, int hi,
 395.321 +                                                    Comparator<? super T> c) {
 395.322 +        assert lo < hi;
 395.323 +        int runHi = lo + 1;
 395.324 +        if (runHi == hi)
 395.325 +            return 1;
 395.326 +
 395.327 +        // Find end of run, and reverse range if descending
 395.328 +        if (c.compare(a[runHi++], a[lo]) < 0) { // Descending
 395.329 +            while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0)
 395.330 +                runHi++;
 395.331 +            reverseRange(a, lo, runHi);
 395.332 +        } else {                              // Ascending
 395.333 +            while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) >= 0)
 395.334 +                runHi++;
 395.335 +        }
 395.336 +
 395.337 +        return runHi - lo;
 395.338 +    }
 395.339 +
 395.340 +    /**
 395.341 +     * Reverse the specified range of the specified array.
 395.342 +     *
 395.343 +     * @param a the array in which a range is to be reversed
 395.344 +     * @param lo the index of the first element in the range to be reversed
 395.345 +     * @param hi the index after the last element in the range to be reversed
 395.346 +     */
 395.347 +    private static void reverseRange(Object[] a, int lo, int hi) {
 395.348 +        hi--;
 395.349 +        while (lo < hi) {
 395.350 +            Object t = a[lo];
 395.351 +            a[lo++] = a[hi];
 395.352 +            a[hi--] = t;
 395.353 +        }
 395.354 +    }
 395.355 +
 395.356 +    /**
 395.357 +     * Returns the minimum acceptable run length for an array of the specified
 395.358 +     * length. Natural runs shorter than this will be extended with
 395.359 +     * {@link #binarySort}.
 395.360 +     *
 395.361 +     * Roughly speaking, the computation is:
 395.362 +     *
 395.363 +     *  If n < MIN_MERGE, return n (it's too small to bother with fancy stuff).
 395.364 +     *  Else if n is an exact power of 2, return MIN_MERGE/2.
 395.365 +     *  Else return an int k, MIN_MERGE/2 <= k <= MIN_MERGE, such that n/k
 395.366 +     *   is close to, but strictly less than, an exact power of 2.
 395.367 +     *
 395.368 +     * For the rationale, see listsort.txt.
 395.369 +     *
 395.370 +     * @param n the length of the array to be sorted
 395.371 +     * @return the length of the minimum run to be merged
 395.372 +     */
 395.373 +    private static int minRunLength(int n) {
 395.374 +        assert n >= 0;
 395.375 +        int r = 0;      // Becomes 1 if any 1 bits are shifted off
 395.376 +        while (n >= MIN_MERGE) {
 395.377 +            r |= (n & 1);
 395.378 +            n >>= 1;
 395.379 +        }
 395.380 +        return n + r;
 395.381 +    }
 395.382 +
 395.383 +    /**
 395.384 +     * Pushes the specified run onto the pending-run stack.
 395.385 +     *
 395.386 +     * @param runBase index of the first element in the run
 395.387 +     * @param runLen  the number of elements in the run
 395.388 +     */
 395.389 +    private void pushRun(int runBase, int runLen) {
 395.390 +        this.runBase[stackSize] = runBase;
 395.391 +        this.runLen[stackSize] = runLen;
 395.392 +        stackSize++;
 395.393 +    }
 395.394 +
 395.395 +    /**
 395.396 +     * Examines the stack of runs waiting to be merged and merges adjacent runs
 395.397 +     * until the stack invariants are reestablished:
 395.398 +     *
 395.399 +     *     1. runLen[i - 3] > runLen[i - 2] + runLen[i - 1]
 395.400 +     *     2. runLen[i - 2] > runLen[i - 1]
 395.401 +     *
 395.402 +     * This method is called each time a new run is pushed onto the stack,
 395.403 +     * so the invariants are guaranteed to hold for i < stackSize upon
 395.404 +     * entry to the method.
 395.405 +     */
 395.406 +    private void mergeCollapse() {
 395.407 +        while (stackSize > 1) {
 395.408 +            int n = stackSize - 2;
 395.409 +            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
 395.410 +                if (runLen[n - 1] < runLen[n + 1])
 395.411 +                    n--;
 395.412 +                mergeAt(n);
 395.413 +            } else if (runLen[n] <= runLen[n + 1]) {
 395.414 +                mergeAt(n);
 395.415 +            } else {
 395.416 +                break; // Invariant is established
 395.417 +            }
 395.418 +        }
 395.419 +    }
 395.420 +
 395.421 +    /**
 395.422 +     * Merges all runs on the stack until only one remains.  This method is
 395.423 +     * called once, to complete the sort.
 395.424 +     */
 395.425 +    private void mergeForceCollapse() {
 395.426 +        while (stackSize > 1) {
 395.427 +            int n = stackSize - 2;
 395.428 +            if (n > 0 && runLen[n - 1] < runLen[n + 1])
 395.429 +                n--;
 395.430 +            mergeAt(n);
 395.431 +        }
 395.432 +    }
 395.433 +
 395.434 +    /**
 395.435 +     * Merges the two runs at stack indices i and i+1.  Run i must be
 395.436 +     * the penultimate or antepenultimate run on the stack.  In other words,
 395.437 +     * i must be equal to stackSize-2 or stackSize-3.
 395.438 +     *
 395.439 +     * @param i stack index of the first of the two runs to merge
 395.440 +     */
 395.441 +    private void mergeAt(int i) {
 395.442 +        assert stackSize >= 2;
 395.443 +        assert i >= 0;
 395.444 +        assert i == stackSize - 2 || i == stackSize - 3;
 395.445 +
 395.446 +        int base1 = runBase[i];
 395.447 +        int len1 = runLen[i];
 395.448 +        int base2 = runBase[i + 1];
 395.449 +        int len2 = runLen[i + 1];
 395.450 +        assert len1 > 0 && len2 > 0;
 395.451 +        assert base1 + len1 == base2;
 395.452 +
 395.453 +        /*
 395.454 +         * Record the length of the combined runs; if i is the 3rd-last
 395.455 +         * run now, also slide over the last run (which isn't involved
 395.456 +         * in this merge).  The current run (i+1) goes away in any case.
 395.457 +         */
 395.458 +        runLen[i] = len1 + len2;
 395.459 +        if (i == stackSize - 3) {
 395.460 +            runBase[i + 1] = runBase[i + 2];
 395.461 +            runLen[i + 1] = runLen[i + 2];
 395.462 +        }
 395.463 +        stackSize--;
 395.464 +
 395.465 +        /*
 395.466 +         * Find where the first element of run2 goes in run1. Prior elements
 395.467 +         * in run1 can be ignored (because they're already in place).
 395.468 +         */
 395.469 +        int k = gallopRight(a[base2], a, base1, len1, 0, c);
 395.470 +        assert k >= 0;
 395.471 +        base1 += k;
 395.472 +        len1 -= k;
 395.473 +        if (len1 == 0)
 395.474 +            return;
 395.475 +
 395.476 +        /*
 395.477 +         * Find where the last element of run1 goes in run2. Subsequent elements
 395.478 +         * in run2 can be ignored (because they're already in place).
 395.479 +         */
 395.480 +        len2 = gallopLeft(a[base1 + len1 - 1], a, base2, len2, len2 - 1, c);
 395.481 +        assert len2 >= 0;
 395.482 +        if (len2 == 0)
 395.483 +            return;
 395.484 +
 395.485 +        // Merge remaining runs, using tmp array with min(len1, len2) elements
 395.486 +        if (len1 <= len2)
 395.487 +            mergeLo(base1, len1, base2, len2);
 395.488 +        else
 395.489 +            mergeHi(base1, len1, base2, len2);
 395.490 +    }
 395.491 +
 395.492 +    /**
 395.493 +     * Locates the position at which to insert the specified key into the
 395.494 +     * specified sorted range; if the range contains an element equal to key,
 395.495 +     * returns the index of the leftmost equal element.
 395.496 +     *
 395.497 +     * @param key the key whose insertion point to search for
 395.498 +     * @param a the array in which to search
 395.499 +     * @param base the index of the first element in the range
 395.500 +     * @param len the length of the range; must be > 0
 395.501 +     * @param hint the index at which to begin the search, 0 <= hint < n.
 395.502 +     *     The closer hint is to the result, the faster this method will run.
 395.503 +     * @param c the comparator used to order the range, and to search
 395.504 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] < key <= a[b + k],
 395.505 +     *    pretending that a[b - 1] is minus infinity and a[b + n] is infinity.
 395.506 +     *    In other words, key belongs at index b + k; or in other words,
 395.507 +     *    the first k elements of a should precede key, and the last n - k
 395.508 +     *    should follow it.
 395.509 +     */
 395.510 +    private static <T> int gallopLeft(T key, T[] a, int base, int len, int hint,
 395.511 +                                      Comparator<? super T> c) {
 395.512 +        assert len > 0 && hint >= 0 && hint < len;
 395.513 +        int lastOfs = 0;
 395.514 +        int ofs = 1;
 395.515 +        if (c.compare(key, a[base + hint]) > 0) {
 395.516 +            // Gallop right until a[base+hint+lastOfs] < key <= a[base+hint+ofs]
 395.517 +            int maxOfs = len - hint;
 395.518 +            while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) > 0) {
 395.519 +                lastOfs = ofs;
 395.520 +                ofs = (ofs << 1) + 1;
 395.521 +                if (ofs <= 0)   // int overflow
 395.522 +                    ofs = maxOfs;
 395.523 +            }
 395.524 +            if (ofs > maxOfs)
 395.525 +                ofs = maxOfs;
 395.526 +
 395.527 +            // Make offsets relative to base
 395.528 +            lastOfs += hint;
 395.529 +            ofs += hint;
 395.530 +        } else { // key <= a[base + hint]
 395.531 +            // Gallop left until a[base+hint-ofs] < key <= a[base+hint-lastOfs]
 395.532 +            final int maxOfs = hint + 1;
 395.533 +            while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) <= 0) {
 395.534 +                lastOfs = ofs;
 395.535 +                ofs = (ofs << 1) + 1;
 395.536 +                if (ofs <= 0)   // int overflow
 395.537 +                    ofs = maxOfs;
 395.538 +            }
 395.539 +            if (ofs > maxOfs)
 395.540 +                ofs = maxOfs;
 395.541 +
 395.542 +            // Make offsets relative to base
 395.543 +            int tmp = lastOfs;
 395.544 +            lastOfs = hint - ofs;
 395.545 +            ofs = hint - tmp;
 395.546 +        }
 395.547 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
 395.548 +
 395.549 +        /*
 395.550 +         * Now a[base+lastOfs] < key <= a[base+ofs], so key belongs somewhere
 395.551 +         * to the right of lastOfs but no farther right than ofs.  Do a binary
 395.552 +         * search, with invariant a[base + lastOfs - 1] < key <= a[base + ofs].
 395.553 +         */
 395.554 +        lastOfs++;
 395.555 +        while (lastOfs < ofs) {
 395.556 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
 395.557 +
 395.558 +            if (c.compare(key, a[base + m]) > 0)
 395.559 +                lastOfs = m + 1;  // a[base + m] < key
 395.560 +            else
 395.561 +                ofs = m;          // key <= a[base + m]
 395.562 +        }
 395.563 +        assert lastOfs == ofs;    // so a[base + ofs - 1] < key <= a[base + ofs]
 395.564 +        return ofs;
 395.565 +    }
 395.566 +
 395.567 +    /**
 395.568 +     * Like gallopLeft, except that if the range contains an element equal to
 395.569 +     * key, gallopRight returns the index after the rightmost equal element.
 395.570 +     *
 395.571 +     * @param key the key whose insertion point to search for
 395.572 +     * @param a the array in which to search
 395.573 +     * @param base the index of the first element in the range
 395.574 +     * @param len the length of the range; must be > 0
 395.575 +     * @param hint the index at which to begin the search, 0 <= hint < n.
 395.576 +     *     The closer hint is to the result, the faster this method will run.
 395.577 +     * @param c the comparator used to order the range, and to search
 395.578 +     * @return the int k,  0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
 395.579 +     */
 395.580 +    private static <T> int gallopRight(T key, T[] a, int base, int len,
 395.581 +                                       int hint, Comparator<? super T> c) {
 395.582 +        assert len > 0 && hint >= 0 && hint < len;
 395.583 +
 395.584 +        int ofs = 1;
 395.585 +        int lastOfs = 0;
 395.586 +        if (c.compare(key, a[base + hint]) < 0) {
 395.587 +            // Gallop left until a[b+hint - ofs] <= key < a[b+hint - lastOfs]
 395.588 +            int maxOfs = hint + 1;
 395.589 +            while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) < 0) {
 395.590 +                lastOfs = ofs;
 395.591 +                ofs = (ofs << 1) + 1;
 395.592 +                if (ofs <= 0)   // int overflow
 395.593 +                    ofs = maxOfs;
 395.594 +            }
 395.595 +            if (ofs > maxOfs)
 395.596 +                ofs = maxOfs;
 395.597 +
 395.598 +            // Make offsets relative to b
 395.599 +            int tmp = lastOfs;
 395.600 +            lastOfs = hint - ofs;
 395.601 +            ofs = hint - tmp;
 395.602 +        } else { // a[b + hint] <= key
 395.603 +            // Gallop right until a[b+hint + lastOfs] <= key < a[b+hint + ofs]
 395.604 +            int maxOfs = len - hint;
 395.605 +            while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) >= 0) {
 395.606 +                lastOfs = ofs;
 395.607 +                ofs = (ofs << 1) + 1;
 395.608 +                if (ofs <= 0)   // int overflow
 395.609 +                    ofs = maxOfs;
 395.610 +            }
 395.611 +            if (ofs > maxOfs)
 395.612 +                ofs = maxOfs;
 395.613 +
 395.614 +            // Make offsets relative to b
 395.615 +            lastOfs += hint;
 395.616 +            ofs += hint;
 395.617 +        }
 395.618 +        assert -1 <= lastOfs && lastOfs < ofs && ofs <= len;
 395.619 +
 395.620 +        /*
 395.621 +         * Now a[b + lastOfs] <= key < a[b + ofs], so key belongs somewhere to
 395.622 +         * the right of lastOfs but no farther right than ofs.  Do a binary
 395.623 +         * search, with invariant a[b + lastOfs - 1] <= key < a[b + ofs].
 395.624 +         */
 395.625 +        lastOfs++;
 395.626 +        while (lastOfs < ofs) {
 395.627 +            int m = lastOfs + ((ofs - lastOfs) >>> 1);
 395.628 +
 395.629 +            if (c.compare(key, a[base + m]) < 0)
 395.630 +                ofs = m;          // key < a[b + m]
 395.631 +            else
 395.632 +                lastOfs = m + 1;  // a[b + m] <= key
 395.633 +        }
 395.634 +        assert lastOfs == ofs;    // so a[b + ofs - 1] <= key < a[b + ofs]
 395.635 +        return ofs;
 395.636 +    }
 395.637 +
 395.638 +    /**
 395.639 +     * Merges two adjacent runs in place, in a stable fashion.  The first
 395.640 +     * element of the first run must be greater than the first element of the
 395.641 +     * second run (a[base1] > a[base2]), and the last element of the first run
 395.642 +     * (a[base1 + len1-1]) must be greater than all elements of the second run.
 395.643 +     *
 395.644 +     * For performance, this method should be called only when len1 <= len2;
 395.645 +     * its twin, mergeHi should be called if len1 >= len2.  (Either method
 395.646 +     * may be called if len1 == len2.)
 395.647 +     *
 395.648 +     * @param base1 index of first element in first run to be merged
 395.649 +     * @param len1  length of first run to be merged (must be > 0)
 395.650 +     * @param base2 index of first element in second run to be merged
 395.651 +     *        (must be aBase + aLen)
 395.652 +     * @param len2  length of second run to be merged (must be > 0)
 395.653 +     */
 395.654 +    private void mergeLo(int base1, int len1, int base2, int len2) {
 395.655 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
 395.656 +
 395.657 +        // Copy first run into temp array
 395.658 +        T[] a = this.a; // For performance
 395.659 +        T[] tmp = ensureCapacity(len1);
 395.660 +        System.arraycopy(a, base1, tmp, 0, len1);
 395.661 +
 395.662 +        int cursor1 = 0;       // Indexes into tmp array
 395.663 +        int cursor2 = base2;   // Indexes int a
 395.664 +        int dest = base1;      // Indexes int a
 395.665 +
 395.666 +        // Move first element of second run and deal with degenerate cases
 395.667 +        a[dest++] = a[cursor2++];
 395.668 +        if (--len2 == 0) {
 395.669 +            System.arraycopy(tmp, cursor1, a, dest, len1);
 395.670 +            return;
 395.671 +        }
 395.672 +        if (len1 == 1) {
 395.673 +            System.arraycopy(a, cursor2, a, dest, len2);
 395.674 +            a[dest + len2] = tmp[cursor1]; // Last elt of run 1 to end of merge
 395.675 +            return;
 395.676 +        }
 395.677 +
 395.678 +        Comparator<? super T> c = this.c;  // Use local variable for performance
 395.679 +        int minGallop = this.minGallop;    //  "    "       "     "      "
 395.680 +    outer:
 395.681 +        while (true) {
 395.682 +            int count1 = 0; // Number of times in a row that first run won
 395.683 +            int count2 = 0; // Number of times in a row that second run won
 395.684 +
 395.685 +            /*
 395.686 +             * Do the straightforward thing until (if ever) one run starts
 395.687 +             * winning consistently.
 395.688 +             */
 395.689 +            do {
 395.690 +                assert len1 > 1 && len2 > 0;
 395.691 +                if (c.compare(a[cursor2], tmp[cursor1]) < 0) {
 395.692 +                    a[dest++] = a[cursor2++];
 395.693 +                    count2++;
 395.694 +                    count1 = 0;
 395.695 +                    if (--len2 == 0)
 395.696 +                        break outer;
 395.697 +                } else {
 395.698 +                    a[dest++] = tmp[cursor1++];
 395.699 +                    count1++;
 395.700 +                    count2 = 0;
 395.701 +                    if (--len1 == 1)
 395.702 +                        break outer;
 395.703 +                }
 395.704 +            } while ((count1 | count2) < minGallop);
 395.705 +
 395.706 +            /*
 395.707 +             * One run is winning so consistently that galloping may be a
 395.708 +             * huge win. So try that, and continue galloping until (if ever)
 395.709 +             * neither run appears to be winning consistently anymore.
 395.710 +             */
 395.711 +            do {
 395.712 +                assert len1 > 1 && len2 > 0;
 395.713 +                count1 = gallopRight(a[cursor2], tmp, cursor1, len1, 0, c);
 395.714 +                if (count1 != 0) {
 395.715 +                    System.arraycopy(tmp, cursor1, a, dest, count1);
 395.716 +                    dest += count1;
 395.717 +                    cursor1 += count1;
 395.718 +                    len1 -= count1;
 395.719 +                    if (len1 <= 1) // len1 == 1 || len1 == 0
 395.720 +                        break outer;
 395.721 +                }
 395.722 +                a[dest++] = a[cursor2++];
 395.723 +                if (--len2 == 0)
 395.724 +                    break outer;
 395.725 +
 395.726 +                count2 = gallopLeft(tmp[cursor1], a, cursor2, len2, 0, c);
 395.727 +                if (count2 != 0) {
 395.728 +                    System.arraycopy(a, cursor2, a, dest, count2);
 395.729 +                    dest += count2;
 395.730 +                    cursor2 += count2;
 395.731 +                    len2 -= count2;
 395.732 +                    if (len2 == 0)
 395.733 +                        break outer;
 395.734 +                }
 395.735 +                a[dest++] = tmp[cursor1++];
 395.736 +                if (--len1 == 1)
 395.737 +                    break outer;
 395.738 +                minGallop--;
 395.739 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
 395.740 +            if (minGallop < 0)
 395.741 +                minGallop = 0;
 395.742 +            minGallop += 2;  // Penalize for leaving gallop mode
 395.743 +        }  // End of "outer" loop
 395.744 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
 395.745 +
 395.746 +        if (len1 == 1) {
 395.747 +            assert len2 > 0;
 395.748 +            System.arraycopy(a, cursor2, a, dest, len2);
 395.749 +            a[dest + len2] = tmp[cursor1]; //  Last elt of run 1 to end of merge
 395.750 +        } else if (len1 == 0) {
 395.751 +            throw new IllegalArgumentException(
 395.752 +                "Comparison method violates its general contract!");
 395.753 +        } else {
 395.754 +            assert len2 == 0;
 395.755 +            assert len1 > 1;
 395.756 +            System.arraycopy(tmp, cursor1, a, dest, len1);
 395.757 +        }
 395.758 +    }
 395.759 +
 395.760 +    /**
 395.761 +     * Like mergeLo, except that this method should be called only if
 395.762 +     * len1 >= len2; mergeLo should be called if len1 <= len2.  (Either method
 395.763 +     * may be called if len1 == len2.)
 395.764 +     *
 395.765 +     * @param base1 index of first element in first run to be merged
 395.766 +     * @param len1  length of first run to be merged (must be > 0)
 395.767 +     * @param base2 index of first element in second run to be merged
 395.768 +     *        (must be aBase + aLen)
 395.769 +     * @param len2  length of second run to be merged (must be > 0)
 395.770 +     */
 395.771 +    private void mergeHi(int base1, int len1, int base2, int len2) {
 395.772 +        assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
 395.773 +
 395.774 +        // Copy second run into temp array
 395.775 +        T[] a = this.a; // For performance
 395.776 +        T[] tmp = ensureCapacity(len2);
 395.777 +        System.arraycopy(a, base2, tmp, 0, len2);
 395.778 +
 395.779 +        int cursor1 = base1 + len1 - 1;  // Indexes into a
 395.780 +        int cursor2 = len2 - 1;          // Indexes into tmp array
 395.781 +        int dest = base2 + len2 - 1;     // Indexes into a
 395.782 +
 395.783 +        // Move last element of first run and deal with degenerate cases
 395.784 +        a[dest--] = a[cursor1--];
 395.785 +        if (--len1 == 0) {
 395.786 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
 395.787 +            return;
 395.788 +        }
 395.789 +        if (len2 == 1) {
 395.790 +            dest -= len1;
 395.791 +            cursor1 -= len1;
 395.792 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
 395.793 +            a[dest] = tmp[cursor2];
 395.794 +            return;
 395.795 +        }
 395.796 +
 395.797 +        Comparator<? super T> c = this.c;  // Use local variable for performance
 395.798 +        int minGallop = this.minGallop;    //  "    "       "     "      "
 395.799 +    outer:
 395.800 +        while (true) {
 395.801 +            int count1 = 0; // Number of times in a row that first run won
 395.802 +            int count2 = 0; // Number of times in a row that second run won
 395.803 +
 395.804 +            /*
 395.805 +             * Do the straightforward thing until (if ever) one run
 395.806 +             * appears to win consistently.
 395.807 +             */
 395.808 +            do {
 395.809 +                assert len1 > 0 && len2 > 1;
 395.810 +                if (c.compare(tmp[cursor2], a[cursor1]) < 0) {
 395.811 +                    a[dest--] = a[cursor1--];
 395.812 +                    count1++;
 395.813 +                    count2 = 0;
 395.814 +                    if (--len1 == 0)
 395.815 +                        break outer;
 395.816 +                } else {
 395.817 +                    a[dest--] = tmp[cursor2--];
 395.818 +                    count2++;
 395.819 +                    count1 = 0;
 395.820 +                    if (--len2 == 1)
 395.821 +                        break outer;
 395.822 +                }
 395.823 +            } while ((count1 | count2) < minGallop);
 395.824 +
 395.825 +            /*
 395.826 +             * One run is winning so consistently that galloping may be a
 395.827 +             * huge win. So try that, and continue galloping until (if ever)
 395.828 +             * neither run appears to be winning consistently anymore.
 395.829 +             */
 395.830 +            do {
 395.831 +                assert len1 > 0 && len2 > 1;
 395.832 +                count1 = len1 - gallopRight(tmp[cursor2], a, base1, len1, len1 - 1, c);
 395.833 +                if (count1 != 0) {
 395.834 +                    dest -= count1;
 395.835 +                    cursor1 -= count1;
 395.836 +                    len1 -= count1;
 395.837 +                    System.arraycopy(a, cursor1 + 1, a, dest + 1, count1);
 395.838 +                    if (len1 == 0)
 395.839 +                        break outer;
 395.840 +                }
 395.841 +                a[dest--] = tmp[cursor2--];
 395.842 +                if (--len2 == 1)
 395.843 +                    break outer;
 395.844 +
 395.845 +                count2 = len2 - gallopLeft(a[cursor1], tmp, 0, len2, len2 - 1, c);
 395.846 +                if (count2 != 0) {
 395.847 +                    dest -= count2;
 395.848 +                    cursor2 -= count2;
 395.849 +                    len2 -= count2;
 395.850 +                    System.arraycopy(tmp, cursor2 + 1, a, dest + 1, count2);
 395.851 +                    if (len2 <= 1)  // len2 == 1 || len2 == 0
 395.852 +                        break outer;
 395.853 +                }
 395.854 +                a[dest--] = a[cursor1--];
 395.855 +                if (--len1 == 0)
 395.856 +                    break outer;
 395.857 +                minGallop--;
 395.858 +            } while (count1 >= MIN_GALLOP | count2 >= MIN_GALLOP);
 395.859 +            if (minGallop < 0)
 395.860 +                minGallop = 0;
 395.861 +            minGallop += 2;  // Penalize for leaving gallop mode
 395.862 +        }  // End of "outer" loop
 395.863 +        this.minGallop = minGallop < 1 ? 1 : minGallop;  // Write back to field
 395.864 +
 395.865 +        if (len2 == 1) {
 395.866 +            assert len1 > 0;
 395.867 +            dest -= len1;
 395.868 +            cursor1 -= len1;
 395.869 +            System.arraycopy(a, cursor1 + 1, a, dest + 1, len1);
 395.870 +            a[dest] = tmp[cursor2];  // Move first elt of run2 to front of merge
 395.871 +        } else if (len2 == 0) {
 395.872 +            throw new IllegalArgumentException(
 395.873 +                "Comparison method violates its general contract!");
 395.874 +        } else {
 395.875 +            assert len1 == 0;
 395.876 +            assert len2 > 0;
 395.877 +            System.arraycopy(tmp, 0, a, dest - (len2 - 1), len2);
 395.878 +        }
 395.879 +    }
 395.880 +
 395.881 +    /**
 395.882 +     * Ensures that the external array tmp has at least the specified
 395.883 +     * number of elements, increasing its size if necessary.  The size
 395.884 +     * increases exponentially to ensure amortized linear time complexity.
 395.885 +     *
 395.886 +     * @param minCapacity the minimum required capacity of the tmp array
 395.887 +     * @return tmp, whether or not it grew
 395.888 +     */
 395.889 +    private T[] ensureCapacity(int minCapacity) {
 395.890 +        if (tmp.length < minCapacity) {
 395.891 +            // Compute smallest power of 2 > minCapacity
 395.892 +            int newSize = minCapacity;
 395.893 +            newSize |= newSize >> 1;
 395.894 +            newSize |= newSize >> 2;
 395.895 +            newSize |= newSize >> 4;
 395.896 +            newSize |= newSize >> 8;
 395.897 +            newSize |= newSize >> 16;
 395.898 +            newSize++;
 395.899 +
 395.900 +            if (newSize < 0) // Not bloody likely!
 395.901 +                newSize = minCapacity;
 395.902 +            else
 395.903 +                newSize = Math.min(newSize, a.length >>> 1);
 395.904 +
 395.905 +            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
 395.906 +            T[] newArray = (T[]) new Object[newSize];
 395.907 +            tmp = newArray;
 395.908 +        }
 395.909 +        return tmp;
 395.910 +    }
 395.911 +
 395.912 +    /**
 395.913 +     * Checks that fromIndex and toIndex are in range, and throws an
 395.914 +     * appropriate exception if they aren't.
 395.915 +     *
 395.916 +     * @param arrayLen the length of the array
 395.917 +     * @param fromIndex the index of the first element of the range
 395.918 +     * @param toIndex the index after the last element of the range
 395.919 +     * @throws IllegalArgumentException if fromIndex > toIndex
 395.920 +     * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
 395.921 +     *         or toIndex > arrayLen
 395.922 +     */
 395.923 +    private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
 395.924 +        if (fromIndex > toIndex)
 395.925 +            throw new IllegalArgumentException("fromIndex(" + fromIndex +
 395.926 +                       ") > toIndex(" + toIndex+")");
 395.927 +        if (fromIndex < 0)
 395.928 +            throw new ArrayIndexOutOfBoundsException(fromIndex);
 395.929 +        if (toIndex > arrayLen)
 395.930 +            throw new ArrayIndexOutOfBoundsException(toIndex);
 395.931 +    }
 395.932 +}
   396.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   396.2 +++ b/rt/emul/compact/src/main/java/java/util/Vector.java	Wed Feb 27 11:24:58 2013 +0100
   396.3 @@ -0,0 +1,1194 @@
   396.4 +/*
   396.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   396.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   396.7 + *
   396.8 + * This code is free software; you can redistribute it and/or modify it
   396.9 + * under the terms of the GNU General Public License version 2 only, as
  396.10 + * published by the Free Software Foundation.  Oracle designates this
  396.11 + * particular file as subject to the "Classpath" exception as provided
  396.12 + * by Oracle in the LICENSE file that accompanied this code.
  396.13 + *
  396.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  396.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  396.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  396.17 + * version 2 for more details (a copy is included in the LICENSE file that
  396.18 + * accompanied this code).
  396.19 + *
  396.20 + * You should have received a copy of the GNU General Public License version
  396.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  396.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  396.23 + *
  396.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  396.25 + * or visit www.oracle.com if you need additional information or have any
  396.26 + * questions.
  396.27 + */
  396.28 +
  396.29 +package java.util;
  396.30 +
  396.31 +
  396.32 +/**
  396.33 + * The {@code Vector} class implements a growable array of
  396.34 + * objects. Like an array, it contains components that can be
  396.35 + * accessed using an integer index. However, the size of a
  396.36 + * {@code Vector} can grow or shrink as needed to accommodate
  396.37 + * adding and removing items after the {@code Vector} has been created.
  396.38 + *
  396.39 + * <p>Each vector tries to optimize storage management by maintaining a
  396.40 + * {@code capacity} and a {@code capacityIncrement}. The
  396.41 + * {@code capacity} is always at least as large as the vector
  396.42 + * size; it is usually larger because as components are added to the
  396.43 + * vector, the vector's storage increases in chunks the size of
  396.44 + * {@code capacityIncrement}. An application can increase the
  396.45 + * capacity of a vector before inserting a large number of
  396.46 + * components; this reduces the amount of incremental reallocation.
  396.47 + *
  396.48 + * <p><a name="fail-fast"/>
  396.49 + * The iterators returned by this class's {@link #iterator() iterator} and
  396.50 + * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
  396.51 + * if the vector is structurally modified at any time after the iterator is
  396.52 + * created, in any way except through the iterator's own
  396.53 + * {@link ListIterator#remove() remove} or
  396.54 + * {@link ListIterator#add(Object) add} methods, the iterator will throw a
  396.55 + * {@link ConcurrentModificationException}.  Thus, in the face of
  396.56 + * concurrent modification, the iterator fails quickly and cleanly, rather
  396.57 + * than risking arbitrary, non-deterministic behavior at an undetermined
  396.58 + * time in the future.  The {@link Enumeration Enumerations} returned by
  396.59 + * the {@link #elements() elements} method are <em>not</em> fail-fast.
  396.60 + *
  396.61 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
  396.62 + * as it is, generally speaking, impossible to make any hard guarantees in the
  396.63 + * presence of unsynchronized concurrent modification.  Fail-fast iterators
  396.64 + * throw {@code ConcurrentModificationException} on a best-effort basis.
  396.65 + * Therefore, it would be wrong to write a program that depended on this
  396.66 + * exception for its correctness:  <i>the fail-fast behavior of iterators
  396.67 + * should be used only to detect bugs.</i>
  396.68 + *
  396.69 + * <p>As of the Java 2 platform v1.2, this class was retrofitted to
  396.70 + * implement the {@link List} interface, making it a member of the
  396.71 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  396.72 + * Java Collections Framework</a>.  Unlike the new collection
  396.73 + * implementations, {@code Vector} is synchronized.  If a thread-safe
  396.74 + * implementation is not needed, it is recommended to use {@link
  396.75 + * ArrayList} in place of {@code Vector}.
  396.76 + *
  396.77 + * @author  Lee Boynton
  396.78 + * @author  Jonathan Payne
  396.79 + * @see Collection
  396.80 + * @see LinkedList
  396.81 + * @since   JDK1.0
  396.82 + */
  396.83 +public class Vector<E>
  396.84 +    extends AbstractList<E>
  396.85 +    implements List<E>, RandomAccess, Cloneable, java.io.Serializable
  396.86 +{
  396.87 +    /**
  396.88 +     * The array buffer into which the components of the vector are
  396.89 +     * stored. The capacity of the vector is the length of this array buffer,
  396.90 +     * and is at least large enough to contain all the vector's elements.
  396.91 +     *
  396.92 +     * <p>Any array elements following the last element in the Vector are null.
  396.93 +     *
  396.94 +     * @serial
  396.95 +     */
  396.96 +    protected Object[] elementData;
  396.97 +
  396.98 +    /**
  396.99 +     * The number of valid components in this {@code Vector} object.
 396.100 +     * Components {@code elementData[0]} through
 396.101 +     * {@code elementData[elementCount-1]} are the actual items.
 396.102 +     *
 396.103 +     * @serial
 396.104 +     */
 396.105 +    protected int elementCount;
 396.106 +
 396.107 +    /**
 396.108 +     * The amount by which the capacity of the vector is automatically
 396.109 +     * incremented when its size becomes greater than its capacity.  If
 396.110 +     * the capacity increment is less than or equal to zero, the capacity
 396.111 +     * of the vector is doubled each time it needs to grow.
 396.112 +     *
 396.113 +     * @serial
 396.114 +     */
 396.115 +    protected int capacityIncrement;
 396.116 +
 396.117 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 396.118 +    private static final long serialVersionUID = -2767605614048989439L;
 396.119 +
 396.120 +    /**
 396.121 +     * Constructs an empty vector with the specified initial capacity and
 396.122 +     * capacity increment.
 396.123 +     *
 396.124 +     * @param   initialCapacity     the initial capacity of the vector
 396.125 +     * @param   capacityIncrement   the amount by which the capacity is
 396.126 +     *                              increased when the vector overflows
 396.127 +     * @throws IllegalArgumentException if the specified initial capacity
 396.128 +     *         is negative
 396.129 +     */
 396.130 +    public Vector(int initialCapacity, int capacityIncrement) {
 396.131 +        super();
 396.132 +        if (initialCapacity < 0)
 396.133 +            throw new IllegalArgumentException("Illegal Capacity: "+
 396.134 +                                               initialCapacity);
 396.135 +        this.elementData = new Object[initialCapacity];
 396.136 +        this.capacityIncrement = capacityIncrement;
 396.137 +    }
 396.138 +
 396.139 +    /**
 396.140 +     * Constructs an empty vector with the specified initial capacity and
 396.141 +     * with its capacity increment equal to zero.
 396.142 +     *
 396.143 +     * @param   initialCapacity   the initial capacity of the vector
 396.144 +     * @throws IllegalArgumentException if the specified initial capacity
 396.145 +     *         is negative
 396.146 +     */
 396.147 +    public Vector(int initialCapacity) {
 396.148 +        this(initialCapacity, 0);
 396.149 +    }
 396.150 +
 396.151 +    /**
 396.152 +     * Constructs an empty vector so that its internal data array
 396.153 +     * has size {@code 10} and its standard capacity increment is
 396.154 +     * zero.
 396.155 +     */
 396.156 +    public Vector() {
 396.157 +        this(10);
 396.158 +    }
 396.159 +
 396.160 +    /**
 396.161 +     * Constructs a vector containing the elements of the specified
 396.162 +     * collection, in the order they are returned by the collection's
 396.163 +     * iterator.
 396.164 +     *
 396.165 +     * @param c the collection whose elements are to be placed into this
 396.166 +     *       vector
 396.167 +     * @throws NullPointerException if the specified collection is null
 396.168 +     * @since   1.2
 396.169 +     */
 396.170 +    public Vector(Collection<? extends E> c) {
 396.171 +        elementData = c.toArray();
 396.172 +        elementCount = elementData.length;
 396.173 +        // c.toArray might (incorrectly) not return Object[] (see 6260652)
 396.174 +        if (elementData.getClass() != Object[].class)
 396.175 +            elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
 396.176 +    }
 396.177 +
 396.178 +    /**
 396.179 +     * Copies the components of this vector into the specified array.
 396.180 +     * The item at index {@code k} in this vector is copied into
 396.181 +     * component {@code k} of {@code anArray}.
 396.182 +     *
 396.183 +     * @param  anArray the array into which the components get copied
 396.184 +     * @throws NullPointerException if the given array is null
 396.185 +     * @throws IndexOutOfBoundsException if the specified array is not
 396.186 +     *         large enough to hold all the components of this vector
 396.187 +     * @throws ArrayStoreException if a component of this vector is not of
 396.188 +     *         a runtime type that can be stored in the specified array
 396.189 +     * @see #toArray(Object[])
 396.190 +     */
 396.191 +    public synchronized void copyInto(Object[] anArray) {
 396.192 +        System.arraycopy(elementData, 0, anArray, 0, elementCount);
 396.193 +    }
 396.194 +
 396.195 +    /**
 396.196 +     * Trims the capacity of this vector to be the vector's current
 396.197 +     * size. If the capacity of this vector is larger than its current
 396.198 +     * size, then the capacity is changed to equal the size by replacing
 396.199 +     * its internal data array, kept in the field {@code elementData},
 396.200 +     * with a smaller one. An application can use this operation to
 396.201 +     * minimize the storage of a vector.
 396.202 +     */
 396.203 +    public synchronized void trimToSize() {
 396.204 +        modCount++;
 396.205 +        int oldCapacity = elementData.length;
 396.206 +        if (elementCount < oldCapacity) {
 396.207 +            elementData = Arrays.copyOf(elementData, elementCount);
 396.208 +        }
 396.209 +    }
 396.210 +
 396.211 +    /**
 396.212 +     * Increases the capacity of this vector, if necessary, to ensure
 396.213 +     * that it can hold at least the number of components specified by
 396.214 +     * the minimum capacity argument.
 396.215 +     *
 396.216 +     * <p>If the current capacity of this vector is less than
 396.217 +     * {@code minCapacity}, then its capacity is increased by replacing its
 396.218 +     * internal data array, kept in the field {@code elementData}, with a
 396.219 +     * larger one.  The size of the new data array will be the old size plus
 396.220 +     * {@code capacityIncrement}, unless the value of
 396.221 +     * {@code capacityIncrement} is less than or equal to zero, in which case
 396.222 +     * the new capacity will be twice the old capacity; but if this new size
 396.223 +     * is still smaller than {@code minCapacity}, then the new capacity will
 396.224 +     * be {@code minCapacity}.
 396.225 +     *
 396.226 +     * @param minCapacity the desired minimum capacity
 396.227 +     */
 396.228 +    public synchronized void ensureCapacity(int minCapacity) {
 396.229 +        if (minCapacity > 0) {
 396.230 +            modCount++;
 396.231 +            ensureCapacityHelper(minCapacity);
 396.232 +        }
 396.233 +    }
 396.234 +
 396.235 +    /**
 396.236 +     * This implements the unsynchronized semantics of ensureCapacity.
 396.237 +     * Synchronized methods in this class can internally call this
 396.238 +     * method for ensuring capacity without incurring the cost of an
 396.239 +     * extra synchronization.
 396.240 +     *
 396.241 +     * @see #ensureCapacity(int)
 396.242 +     */
 396.243 +    private void ensureCapacityHelper(int minCapacity) {
 396.244 +        // overflow-conscious code
 396.245 +        if (minCapacity - elementData.length > 0)
 396.246 +            grow(minCapacity);
 396.247 +    }
 396.248 +
 396.249 +    /**
 396.250 +     * The maximum size of array to allocate.
 396.251 +     * Some VMs reserve some header words in an array.
 396.252 +     * Attempts to allocate larger arrays may result in
 396.253 +     * OutOfMemoryError: Requested array size exceeds VM limit
 396.254 +     */
 396.255 +    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 396.256 +
 396.257 +    private void grow(int minCapacity) {
 396.258 +        // overflow-conscious code
 396.259 +        int oldCapacity = elementData.length;
 396.260 +        int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
 396.261 +                                         capacityIncrement : oldCapacity);
 396.262 +        if (newCapacity - minCapacity < 0)
 396.263 +            newCapacity = minCapacity;
 396.264 +        if (newCapacity - MAX_ARRAY_SIZE > 0)
 396.265 +            newCapacity = hugeCapacity(minCapacity);
 396.266 +        elementData = Arrays.copyOf(elementData, newCapacity);
 396.267 +    }
 396.268 +
 396.269 +    private static int hugeCapacity(int minCapacity) {
 396.270 +        if (minCapacity < 0) // overflow
 396.271 +            throw new OutOfMemoryError();
 396.272 +        return (minCapacity > MAX_ARRAY_SIZE) ?
 396.273 +            Integer.MAX_VALUE :
 396.274 +            MAX_ARRAY_SIZE;
 396.275 +    }
 396.276 +
 396.277 +    /**
 396.278 +     * Sets the size of this vector. If the new size is greater than the
 396.279 +     * current size, new {@code null} items are added to the end of
 396.280 +     * the vector. If the new size is less than the current size, all
 396.281 +     * components at index {@code newSize} and greater are discarded.
 396.282 +     *
 396.283 +     * @param  newSize   the new size of this vector
 396.284 +     * @throws ArrayIndexOutOfBoundsException if the new size is negative
 396.285 +     */
 396.286 +    public synchronized void setSize(int newSize) {
 396.287 +        modCount++;
 396.288 +        if (newSize > elementCount) {
 396.289 +            ensureCapacityHelper(newSize);
 396.290 +        } else {
 396.291 +            for (int i = newSize ; i < elementCount ; i++) {
 396.292 +                elementData[i] = null;
 396.293 +            }
 396.294 +        }
 396.295 +        elementCount = newSize;
 396.296 +    }
 396.297 +
 396.298 +    /**
 396.299 +     * Returns the current capacity of this vector.
 396.300 +     *
 396.301 +     * @return  the current capacity (the length of its internal
 396.302 +     *          data array, kept in the field {@code elementData}
 396.303 +     *          of this vector)
 396.304 +     */
 396.305 +    public synchronized int capacity() {
 396.306 +        return elementData.length;
 396.307 +    }
 396.308 +
 396.309 +    /**
 396.310 +     * Returns the number of components in this vector.
 396.311 +     *
 396.312 +     * @return  the number of components in this vector
 396.313 +     */
 396.314 +    public synchronized int size() {
 396.315 +        return elementCount;
 396.316 +    }
 396.317 +
 396.318 +    /**
 396.319 +     * Tests if this vector has no components.
 396.320 +     *
 396.321 +     * @return  {@code true} if and only if this vector has
 396.322 +     *          no components, that is, its size is zero;
 396.323 +     *          {@code false} otherwise.
 396.324 +     */
 396.325 +    public synchronized boolean isEmpty() {
 396.326 +        return elementCount == 0;
 396.327 +    }
 396.328 +
 396.329 +    /**
 396.330 +     * Returns an enumeration of the components of this vector. The
 396.331 +     * returned {@code Enumeration} object will generate all items in
 396.332 +     * this vector. The first item generated is the item at index {@code 0},
 396.333 +     * then the item at index {@code 1}, and so on.
 396.334 +     *
 396.335 +     * @return  an enumeration of the components of this vector
 396.336 +     * @see     Iterator
 396.337 +     */
 396.338 +    public Enumeration<E> elements() {
 396.339 +        return new Enumeration<E>() {
 396.340 +            int count = 0;
 396.341 +
 396.342 +            public boolean hasMoreElements() {
 396.343 +                return count < elementCount;
 396.344 +            }
 396.345 +
 396.346 +            public E nextElement() {
 396.347 +                synchronized (Vector.this) {
 396.348 +                    if (count < elementCount) {
 396.349 +                        return elementData(count++);
 396.350 +                    }
 396.351 +                }
 396.352 +                throw new NoSuchElementException("Vector Enumeration");
 396.353 +            }
 396.354 +        };
 396.355 +    }
 396.356 +
 396.357 +    /**
 396.358 +     * Returns {@code true} if this vector contains the specified element.
 396.359 +     * More formally, returns {@code true} if and only if this vector
 396.360 +     * contains at least one element {@code e} such that
 396.361 +     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 396.362 +     *
 396.363 +     * @param o element whose presence in this vector is to be tested
 396.364 +     * @return {@code true} if this vector contains the specified element
 396.365 +     */
 396.366 +    public boolean contains(Object o) {
 396.367 +        return indexOf(o, 0) >= 0;
 396.368 +    }
 396.369 +
 396.370 +    /**
 396.371 +     * Returns the index of the first occurrence of the specified element
 396.372 +     * in this vector, or -1 if this vector does not contain the element.
 396.373 +     * More formally, returns the lowest index {@code i} such that
 396.374 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 396.375 +     * or -1 if there is no such index.
 396.376 +     *
 396.377 +     * @param o element to search for
 396.378 +     * @return the index of the first occurrence of the specified element in
 396.379 +     *         this vector, or -1 if this vector does not contain the element
 396.380 +     */
 396.381 +    public int indexOf(Object o) {
 396.382 +        return indexOf(o, 0);
 396.383 +    }
 396.384 +
 396.385 +    /**
 396.386 +     * Returns the index of the first occurrence of the specified element in
 396.387 +     * this vector, searching forwards from {@code index}, or returns -1 if
 396.388 +     * the element is not found.
 396.389 +     * More formally, returns the lowest index {@code i} such that
 396.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>,
 396.391 +     * or -1 if there is no such index.
 396.392 +     *
 396.393 +     * @param o element to search for
 396.394 +     * @param index index to start searching from
 396.395 +     * @return the index of the first occurrence of the element in
 396.396 +     *         this vector at position {@code index} or later in the vector;
 396.397 +     *         {@code -1} if the element is not found.
 396.398 +     * @throws IndexOutOfBoundsException if the specified index is negative
 396.399 +     * @see     Object#equals(Object)
 396.400 +     */
 396.401 +    public synchronized int indexOf(Object o, int index) {
 396.402 +        if (o == null) {
 396.403 +            for (int i = index ; i < elementCount ; i++)
 396.404 +                if (elementData[i]==null)
 396.405 +                    return i;
 396.406 +        } else {
 396.407 +            for (int i = index ; i < elementCount ; i++)
 396.408 +                if (o.equals(elementData[i]))
 396.409 +                    return i;
 396.410 +        }
 396.411 +        return -1;
 396.412 +    }
 396.413 +
 396.414 +    /**
 396.415 +     * Returns the index of the last occurrence of the specified element
 396.416 +     * in this vector, or -1 if this vector does not contain the element.
 396.417 +     * More formally, returns the highest index {@code i} such that
 396.418 +     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
 396.419 +     * or -1 if there is no such index.
 396.420 +     *
 396.421 +     * @param o element to search for
 396.422 +     * @return the index of the last occurrence of the specified element in
 396.423 +     *         this vector, or -1 if this vector does not contain the element
 396.424 +     */
 396.425 +    public synchronized int lastIndexOf(Object o) {
 396.426 +        return lastIndexOf(o, elementCount-1);
 396.427 +    }
 396.428 +
 396.429 +    /**
 396.430 +     * Returns the index of the last occurrence of the specified element in
 396.431 +     * this vector, searching backwards from {@code index}, or returns -1 if
 396.432 +     * the element is not found.
 396.433 +     * More formally, returns the highest index {@code i} such that
 396.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>,
 396.435 +     * or -1 if there is no such index.
 396.436 +     *
 396.437 +     * @param o element to search for
 396.438 +     * @param index index to start searching backwards from
 396.439 +     * @return the index of the last occurrence of the element at position
 396.440 +     *         less than or equal to {@code index} in this vector;
 396.441 +     *         -1 if the element is not found.
 396.442 +     * @throws IndexOutOfBoundsException if the specified index is greater
 396.443 +     *         than or equal to the current size of this vector
 396.444 +     */
 396.445 +    public synchronized int lastIndexOf(Object o, int index) {
 396.446 +        if (index >= elementCount)
 396.447 +            throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
 396.448 +
 396.449 +        if (o == null) {
 396.450 +            for (int i = index; i >= 0; i--)
 396.451 +                if (elementData[i]==null)
 396.452 +                    return i;
 396.453 +        } else {
 396.454 +            for (int i = index; i >= 0; i--)
 396.455 +                if (o.equals(elementData[i]))
 396.456 +                    return i;
 396.457 +        }
 396.458 +        return -1;
 396.459 +    }
 396.460 +
 396.461 +    /**
 396.462 +     * Returns the component at the specified index.
 396.463 +     *
 396.464 +     * <p>This method is identical in functionality to the {@link #get(int)}
 396.465 +     * method (which is part of the {@link List} interface).
 396.466 +     *
 396.467 +     * @param      index   an index into this vector
 396.468 +     * @return     the component at the specified index
 396.469 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.470 +     *         ({@code index < 0 || index >= size()})
 396.471 +     */
 396.472 +    public synchronized E elementAt(int index) {
 396.473 +        if (index >= elementCount) {
 396.474 +            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
 396.475 +        }
 396.476 +
 396.477 +        return elementData(index);
 396.478 +    }
 396.479 +
 396.480 +    /**
 396.481 +     * Returns the first component (the item at index {@code 0}) of
 396.482 +     * this vector.
 396.483 +     *
 396.484 +     * @return     the first component of this vector
 396.485 +     * @throws NoSuchElementException if this vector has no components
 396.486 +     */
 396.487 +    public synchronized E firstElement() {
 396.488 +        if (elementCount == 0) {
 396.489 +            throw new NoSuchElementException();
 396.490 +        }
 396.491 +        return elementData(0);
 396.492 +    }
 396.493 +
 396.494 +    /**
 396.495 +     * Returns the last component of the vector.
 396.496 +     *
 396.497 +     * @return  the last component of the vector, i.e., the component at index
 396.498 +     *          <code>size()&nbsp;-&nbsp;1</code>.
 396.499 +     * @throws NoSuchElementException if this vector is empty
 396.500 +     */
 396.501 +    public synchronized E lastElement() {
 396.502 +        if (elementCount == 0) {
 396.503 +            throw new NoSuchElementException();
 396.504 +        }
 396.505 +        return elementData(elementCount - 1);
 396.506 +    }
 396.507 +
 396.508 +    /**
 396.509 +     * Sets the component at the specified {@code index} of this
 396.510 +     * vector to be the specified object. The previous component at that
 396.511 +     * position is discarded.
 396.512 +     *
 396.513 +     * <p>The index must be a value greater than or equal to {@code 0}
 396.514 +     * and less than the current size of the vector.
 396.515 +     *
 396.516 +     * <p>This method is identical in functionality to the
 396.517 +     * {@link #set(int, Object) set(int, E)}
 396.518 +     * method (which is part of the {@link List} interface). Note that the
 396.519 +     * {@code set} method reverses the order of the parameters, to more closely
 396.520 +     * match array usage.  Note also that the {@code set} method returns the
 396.521 +     * old value that was stored at the specified position.
 396.522 +     *
 396.523 +     * @param      obj     what the component is to be set to
 396.524 +     * @param      index   the specified index
 396.525 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.526 +     *         ({@code index < 0 || index >= size()})
 396.527 +     */
 396.528 +    public synchronized void setElementAt(E obj, int index) {
 396.529 +        if (index >= elementCount) {
 396.530 +            throw new ArrayIndexOutOfBoundsException(index + " >= " +
 396.531 +                                                     elementCount);
 396.532 +        }
 396.533 +        elementData[index] = obj;
 396.534 +    }
 396.535 +
 396.536 +    /**
 396.537 +     * Deletes the component at the specified index. Each component in
 396.538 +     * this vector with an index greater or equal to the specified
 396.539 +     * {@code index} is shifted downward to have an index one
 396.540 +     * smaller than the value it had previously. The size of this vector
 396.541 +     * is decreased by {@code 1}.
 396.542 +     *
 396.543 +     * <p>The index must be a value greater than or equal to {@code 0}
 396.544 +     * and less than the current size of the vector.
 396.545 +     *
 396.546 +     * <p>This method is identical in functionality to the {@link #remove(int)}
 396.547 +     * method (which is part of the {@link List} interface).  Note that the
 396.548 +     * {@code remove} method returns the old value that was stored at the
 396.549 +     * specified position.
 396.550 +     *
 396.551 +     * @param      index   the index of the object to remove
 396.552 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.553 +     *         ({@code index < 0 || index >= size()})
 396.554 +     */
 396.555 +    public synchronized void removeElementAt(int index) {
 396.556 +        modCount++;
 396.557 +        if (index >= elementCount) {
 396.558 +            throw new ArrayIndexOutOfBoundsException(index + " >= " +
 396.559 +                                                     elementCount);
 396.560 +        }
 396.561 +        else if (index < 0) {
 396.562 +            throw new ArrayIndexOutOfBoundsException(index);
 396.563 +        }
 396.564 +        int j = elementCount - index - 1;
 396.565 +        if (j > 0) {
 396.566 +            System.arraycopy(elementData, index + 1, elementData, index, j);
 396.567 +        }
 396.568 +        elementCount--;
 396.569 +        elementData[elementCount] = null; /* to let gc do its work */
 396.570 +    }
 396.571 +
 396.572 +    /**
 396.573 +     * Inserts the specified object as a component in this vector at the
 396.574 +     * specified {@code index}. Each component in this vector with
 396.575 +     * an index greater or equal to the specified {@code index} is
 396.576 +     * shifted upward to have an index one greater than the value it had
 396.577 +     * previously.
 396.578 +     *
 396.579 +     * <p>The index must be a value greater than or equal to {@code 0}
 396.580 +     * and less than or equal to the current size of the vector. (If the
 396.581 +     * index is equal to the current size of the vector, the new element
 396.582 +     * is appended to the Vector.)
 396.583 +     *
 396.584 +     * <p>This method is identical in functionality to the
 396.585 +     * {@link #add(int, Object) add(int, E)}
 396.586 +     * method (which is part of the {@link List} interface).  Note that the
 396.587 +     * {@code add} method reverses the order of the parameters, to more closely
 396.588 +     * match array usage.
 396.589 +     *
 396.590 +     * @param      obj     the component to insert
 396.591 +     * @param      index   where to insert the new component
 396.592 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.593 +     *         ({@code index < 0 || index > size()})
 396.594 +     */
 396.595 +    public synchronized void insertElementAt(E obj, int index) {
 396.596 +        modCount++;
 396.597 +        if (index > elementCount) {
 396.598 +            throw new ArrayIndexOutOfBoundsException(index
 396.599 +                                                     + " > " + elementCount);
 396.600 +        }
 396.601 +        ensureCapacityHelper(elementCount + 1);
 396.602 +        System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
 396.603 +        elementData[index] = obj;
 396.604 +        elementCount++;
 396.605 +    }
 396.606 +
 396.607 +    /**
 396.608 +     * Adds the specified component to the end of this vector,
 396.609 +     * increasing its size by one. The capacity of this vector is
 396.610 +     * increased if its size becomes greater than its capacity.
 396.611 +     *
 396.612 +     * <p>This method is identical in functionality to the
 396.613 +     * {@link #add(Object) add(E)}
 396.614 +     * method (which is part of the {@link List} interface).
 396.615 +     *
 396.616 +     * @param   obj   the component to be added
 396.617 +     */
 396.618 +    public synchronized void addElement(E obj) {
 396.619 +        modCount++;
 396.620 +        ensureCapacityHelper(elementCount + 1);
 396.621 +        elementData[elementCount++] = obj;
 396.622 +    }
 396.623 +
 396.624 +    /**
 396.625 +     * Removes the first (lowest-indexed) occurrence of the argument
 396.626 +     * from this vector. If the object is found in this vector, each
 396.627 +     * component in the vector with an index greater or equal to the
 396.628 +     * object's index is shifted downward to have an index one smaller
 396.629 +     * than the value it had previously.
 396.630 +     *
 396.631 +     * <p>This method is identical in functionality to the
 396.632 +     * {@link #remove(Object)} method (which is part of the
 396.633 +     * {@link List} interface).
 396.634 +     *
 396.635 +     * @param   obj   the component to be removed
 396.636 +     * @return  {@code true} if the argument was a component of this
 396.637 +     *          vector; {@code false} otherwise.
 396.638 +     */
 396.639 +    public synchronized boolean removeElement(Object obj) {
 396.640 +        modCount++;
 396.641 +        int i = indexOf(obj);
 396.642 +        if (i >= 0) {
 396.643 +            removeElementAt(i);
 396.644 +            return true;
 396.645 +        }
 396.646 +        return false;
 396.647 +    }
 396.648 +
 396.649 +    /**
 396.650 +     * Removes all components from this vector and sets its size to zero.
 396.651 +     *
 396.652 +     * <p>This method is identical in functionality to the {@link #clear}
 396.653 +     * method (which is part of the {@link List} interface).
 396.654 +     */
 396.655 +    public synchronized void removeAllElements() {
 396.656 +        modCount++;
 396.657 +        // Let gc do its work
 396.658 +        for (int i = 0; i < elementCount; i++)
 396.659 +            elementData[i] = null;
 396.660 +
 396.661 +        elementCount = 0;
 396.662 +    }
 396.663 +
 396.664 +    /**
 396.665 +     * Returns a clone of this vector. The copy will contain a
 396.666 +     * reference to a clone of the internal data array, not a reference
 396.667 +     * to the original internal data array of this {@code Vector} object.
 396.668 +     *
 396.669 +     * @return  a clone of this vector
 396.670 +     */
 396.671 +    public synchronized Object clone() {
 396.672 +        try {
 396.673 +            @SuppressWarnings("unchecked")
 396.674 +                Vector<E> v = (Vector<E>) super.clone();
 396.675 +            v.elementData = Arrays.copyOf(elementData, elementCount);
 396.676 +            v.modCount = 0;
 396.677 +            return v;
 396.678 +        } catch (CloneNotSupportedException e) {
 396.679 +            // this shouldn't happen, since we are Cloneable
 396.680 +            throw new InternalError();
 396.681 +        }
 396.682 +    }
 396.683 +
 396.684 +    /**
 396.685 +     * Returns an array containing all of the elements in this Vector
 396.686 +     * in the correct order.
 396.687 +     *
 396.688 +     * @since 1.2
 396.689 +     */
 396.690 +    public synchronized Object[] toArray() {
 396.691 +        return Arrays.copyOf(elementData, elementCount);
 396.692 +    }
 396.693 +
 396.694 +    /**
 396.695 +     * Returns an array containing all of the elements in this Vector in the
 396.696 +     * correct order; the runtime type of the returned array is that of the
 396.697 +     * specified array.  If the Vector fits in the specified array, it is
 396.698 +     * returned therein.  Otherwise, a new array is allocated with the runtime
 396.699 +     * type of the specified array and the size of this Vector.
 396.700 +     *
 396.701 +     * <p>If the Vector fits in the specified array with room to spare
 396.702 +     * (i.e., the array has more elements than the Vector),
 396.703 +     * the element in the array immediately following the end of the
 396.704 +     * Vector is set to null.  (This is useful in determining the length
 396.705 +     * of the Vector <em>only</em> if the caller knows that the Vector
 396.706 +     * does not contain any null elements.)
 396.707 +     *
 396.708 +     * @param a the array into which the elements of the Vector are to
 396.709 +     *          be stored, if it is big enough; otherwise, a new array of the
 396.710 +     *          same runtime type is allocated for this purpose.
 396.711 +     * @return an array containing the elements of the Vector
 396.712 +     * @throws ArrayStoreException if the runtime type of a is not a supertype
 396.713 +     * of the runtime type of every element in this Vector
 396.714 +     * @throws NullPointerException if the given array is null
 396.715 +     * @since 1.2
 396.716 +     */
 396.717 +    @SuppressWarnings("unchecked")
 396.718 +    public synchronized <T> T[] toArray(T[] a) {
 396.719 +        if (a.length < elementCount)
 396.720 +            return (T[]) Arrays.copyOf(elementData, elementCount, a.getClass());
 396.721 +
 396.722 +        System.arraycopy(elementData, 0, a, 0, elementCount);
 396.723 +
 396.724 +        if (a.length > elementCount)
 396.725 +            a[elementCount] = null;
 396.726 +
 396.727 +        return a;
 396.728 +    }
 396.729 +
 396.730 +    // Positional Access Operations
 396.731 +
 396.732 +    @SuppressWarnings("unchecked")
 396.733 +    E elementData(int index) {
 396.734 +        return (E) elementData[index];
 396.735 +    }
 396.736 +
 396.737 +    /**
 396.738 +     * Returns the element at the specified position in this Vector.
 396.739 +     *
 396.740 +     * @param index index of the element to return
 396.741 +     * @return object at the specified index
 396.742 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.743 +     *            ({@code index < 0 || index >= size()})
 396.744 +     * @since 1.2
 396.745 +     */
 396.746 +    public synchronized E get(int index) {
 396.747 +        if (index >= elementCount)
 396.748 +            throw new ArrayIndexOutOfBoundsException(index);
 396.749 +
 396.750 +        return elementData(index);
 396.751 +    }
 396.752 +
 396.753 +    /**
 396.754 +     * Replaces the element at the specified position in this Vector with the
 396.755 +     * specified element.
 396.756 +     *
 396.757 +     * @param index index of the element to replace
 396.758 +     * @param element element to be stored at the specified position
 396.759 +     * @return the element previously at the specified position
 396.760 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.761 +     *         ({@code index < 0 || index >= size()})
 396.762 +     * @since 1.2
 396.763 +     */
 396.764 +    public synchronized E set(int index, E element) {
 396.765 +        if (index >= elementCount)
 396.766 +            throw new ArrayIndexOutOfBoundsException(index);
 396.767 +
 396.768 +        E oldValue = elementData(index);
 396.769 +        elementData[index] = element;
 396.770 +        return oldValue;
 396.771 +    }
 396.772 +
 396.773 +    /**
 396.774 +     * Appends the specified element to the end of this Vector.
 396.775 +     *
 396.776 +     * @param e element to be appended to this Vector
 396.777 +     * @return {@code true} (as specified by {@link Collection#add})
 396.778 +     * @since 1.2
 396.779 +     */
 396.780 +    public synchronized boolean add(E e) {
 396.781 +        modCount++;
 396.782 +        ensureCapacityHelper(elementCount + 1);
 396.783 +        elementData[elementCount++] = e;
 396.784 +        return true;
 396.785 +    }
 396.786 +
 396.787 +    /**
 396.788 +     * Removes the first occurrence of the specified element in this Vector
 396.789 +     * If the Vector does not contain the element, it is unchanged.  More
 396.790 +     * formally, removes the element with the lowest index i such that
 396.791 +     * {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
 396.792 +     * an element exists).
 396.793 +     *
 396.794 +     * @param o element to be removed from this Vector, if present
 396.795 +     * @return true if the Vector contained the specified element
 396.796 +     * @since 1.2
 396.797 +     */
 396.798 +    public boolean remove(Object o) {
 396.799 +        return removeElement(o);
 396.800 +    }
 396.801 +
 396.802 +    /**
 396.803 +     * Inserts the specified element at the specified position in this Vector.
 396.804 +     * Shifts the element currently at that position (if any) and any
 396.805 +     * subsequent elements to the right (adds one to their indices).
 396.806 +     *
 396.807 +     * @param index index at which the specified element is to be inserted
 396.808 +     * @param element element to be inserted
 396.809 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.810 +     *         ({@code index < 0 || index > size()})
 396.811 +     * @since 1.2
 396.812 +     */
 396.813 +    public void add(int index, E element) {
 396.814 +        insertElementAt(element, index);
 396.815 +    }
 396.816 +
 396.817 +    /**
 396.818 +     * Removes the element at the specified position in this Vector.
 396.819 +     * Shifts any subsequent elements to the left (subtracts one from their
 396.820 +     * indices).  Returns the element that was removed from the Vector.
 396.821 +     *
 396.822 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.823 +     *         ({@code index < 0 || index >= size()})
 396.824 +     * @param index the index of the element to be removed
 396.825 +     * @return element that was removed
 396.826 +     * @since 1.2
 396.827 +     */
 396.828 +    public synchronized E remove(int index) {
 396.829 +        modCount++;
 396.830 +        if (index >= elementCount)
 396.831 +            throw new ArrayIndexOutOfBoundsException(index);
 396.832 +        E oldValue = elementData(index);
 396.833 +
 396.834 +        int numMoved = elementCount - index - 1;
 396.835 +        if (numMoved > 0)
 396.836 +            System.arraycopy(elementData, index+1, elementData, index,
 396.837 +                             numMoved);
 396.838 +        elementData[--elementCount] = null; // Let gc do its work
 396.839 +
 396.840 +        return oldValue;
 396.841 +    }
 396.842 +
 396.843 +    /**
 396.844 +     * Removes all of the elements from this Vector.  The Vector will
 396.845 +     * be empty after this call returns (unless it throws an exception).
 396.846 +     *
 396.847 +     * @since 1.2
 396.848 +     */
 396.849 +    public void clear() {
 396.850 +        removeAllElements();
 396.851 +    }
 396.852 +
 396.853 +    // Bulk Operations
 396.854 +
 396.855 +    /**
 396.856 +     * Returns true if this Vector contains all of the elements in the
 396.857 +     * specified Collection.
 396.858 +     *
 396.859 +     * @param   c a collection whose elements will be tested for containment
 396.860 +     *          in this Vector
 396.861 +     * @return true if this Vector contains all of the elements in the
 396.862 +     *         specified collection
 396.863 +     * @throws NullPointerException if the specified collection is null
 396.864 +     */
 396.865 +    public synchronized boolean containsAll(Collection<?> c) {
 396.866 +        return super.containsAll(c);
 396.867 +    }
 396.868 +
 396.869 +    /**
 396.870 +     * Appends all of the elements in the specified Collection to the end of
 396.871 +     * this Vector, in the order that they are returned by the specified
 396.872 +     * Collection's Iterator.  The behavior of this operation is undefined if
 396.873 +     * the specified Collection is modified while the operation is in progress.
 396.874 +     * (This implies that the behavior of this call is undefined if the
 396.875 +     * specified Collection is this Vector, and this Vector is nonempty.)
 396.876 +     *
 396.877 +     * @param c elements to be inserted into this Vector
 396.878 +     * @return {@code true} if this Vector changed as a result of the call
 396.879 +     * @throws NullPointerException if the specified collection is null
 396.880 +     * @since 1.2
 396.881 +     */
 396.882 +    public synchronized boolean addAll(Collection<? extends E> c) {
 396.883 +        modCount++;
 396.884 +        Object[] a = c.toArray();
 396.885 +        int numNew = a.length;
 396.886 +        ensureCapacityHelper(elementCount + numNew);
 396.887 +        System.arraycopy(a, 0, elementData, elementCount, numNew);
 396.888 +        elementCount += numNew;
 396.889 +        return numNew != 0;
 396.890 +    }
 396.891 +
 396.892 +    /**
 396.893 +     * Removes from this Vector all of its elements that are contained in the
 396.894 +     * specified Collection.
 396.895 +     *
 396.896 +     * @param c a collection of elements to be removed from the Vector
 396.897 +     * @return true if this Vector changed as a result of the call
 396.898 +     * @throws ClassCastException if the types of one or more elements
 396.899 +     *         in this vector are incompatible with the specified
 396.900 +     *         collection
 396.901 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 396.902 +     * @throws NullPointerException if this vector contains one or more null
 396.903 +     *         elements and the specified collection does not support null
 396.904 +     *         elements
 396.905 +     * (<a href="Collection.html#optional-restrictions">optional</a>),
 396.906 +     *         or if the specified collection is null
 396.907 +     * @since 1.2
 396.908 +     */
 396.909 +    public synchronized boolean removeAll(Collection<?> c) {
 396.910 +        return super.removeAll(c);
 396.911 +    }
 396.912 +
 396.913 +    /**
 396.914 +     * Retains only the elements in this Vector that are contained in the
 396.915 +     * specified Collection.  In other words, removes from this Vector all
 396.916 +     * of its elements that are not contained in the specified Collection.
 396.917 +     *
 396.918 +     * @param c a collection of elements to be retained in this Vector
 396.919 +     *          (all other elements are removed)
 396.920 +     * @return true if this Vector changed as a result of the call
 396.921 +     * @throws ClassCastException if the types of one or more elements
 396.922 +     *         in this vector are incompatible with the specified
 396.923 +     *         collection
 396.924 +     * (<a href="Collection.html#optional-restrictions">optional</a>)
 396.925 +     * @throws NullPointerException if this vector contains one or more null
 396.926 +     *         elements and the specified collection does not support null
 396.927 +     *         elements
 396.928 +     *         (<a href="Collection.html#optional-restrictions">optional</a>),
 396.929 +     *         or if the specified collection is null
 396.930 +     * @since 1.2
 396.931 +     */
 396.932 +    public synchronized boolean retainAll(Collection<?> c) {
 396.933 +        return super.retainAll(c);
 396.934 +    }
 396.935 +
 396.936 +    /**
 396.937 +     * Inserts all of the elements in the specified Collection into this
 396.938 +     * Vector at the specified position.  Shifts the element currently at
 396.939 +     * that position (if any) and any subsequent elements to the right
 396.940 +     * (increases their indices).  The new elements will appear in the Vector
 396.941 +     * in the order that they are returned by the specified Collection's
 396.942 +     * iterator.
 396.943 +     *
 396.944 +     * @param index index at which to insert the first element from the
 396.945 +     *              specified collection
 396.946 +     * @param c elements to be inserted into this Vector
 396.947 +     * @return {@code true} if this Vector changed as a result of the call
 396.948 +     * @throws ArrayIndexOutOfBoundsException if the index is out of range
 396.949 +     *         ({@code index < 0 || index > size()})
 396.950 +     * @throws NullPointerException if the specified collection is null
 396.951 +     * @since 1.2
 396.952 +     */
 396.953 +    public synchronized boolean addAll(int index, Collection<? extends E> c) {
 396.954 +        modCount++;
 396.955 +        if (index < 0 || index > elementCount)
 396.956 +            throw new ArrayIndexOutOfBoundsException(index);
 396.957 +
 396.958 +        Object[] a = c.toArray();
 396.959 +        int numNew = a.length;
 396.960 +        ensureCapacityHelper(elementCount + numNew);
 396.961 +
 396.962 +        int numMoved = elementCount - index;
 396.963 +        if (numMoved > 0)
 396.964 +            System.arraycopy(elementData, index, elementData, index + numNew,
 396.965 +                             numMoved);
 396.966 +
 396.967 +        System.arraycopy(a, 0, elementData, index, numNew);
 396.968 +        elementCount += numNew;
 396.969 +        return numNew != 0;
 396.970 +    }
 396.971 +
 396.972 +    /**
 396.973 +     * Compares the specified Object with this Vector for equality.  Returns
 396.974 +     * true if and only if the specified Object is also a List, both Lists
 396.975 +     * have the same size, and all corresponding pairs of elements in the two
 396.976 +     * Lists are <em>equal</em>.  (Two elements {@code e1} and
 396.977 +     * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
 396.978 +     * e1.equals(e2))}.)  In other words, two Lists are defined to be
 396.979 +     * equal if they contain the same elements in the same order.
 396.980 +     *
 396.981 +     * @param o the Object to be compared for equality with this Vector
 396.982 +     * @return true if the specified Object is equal to this Vector
 396.983 +     */
 396.984 +    public synchronized boolean equals(Object o) {
 396.985 +        return super.equals(o);
 396.986 +    }
 396.987 +
 396.988 +    /**
 396.989 +     * Returns the hash code value for this Vector.
 396.990 +     */
 396.991 +    public synchronized int hashCode() {
 396.992 +        return super.hashCode();
 396.993 +    }
 396.994 +
 396.995 +    /**
 396.996 +     * Returns a string representation of this Vector, containing
 396.997 +     * the String representation of each element.
 396.998 +     */
 396.999 +    public synchronized String toString() {
396.1000 +        return super.toString();
396.1001 +    }
396.1002 +
396.1003 +    /**
396.1004 +     * Returns a view of the portion of this List between fromIndex,
396.1005 +     * inclusive, and toIndex, exclusive.  (If fromIndex and toIndex are
396.1006 +     * equal, the returned List is empty.)  The returned List is backed by this
396.1007 +     * List, so changes in the returned List are reflected in this List, and
396.1008 +     * vice-versa.  The returned List supports all of the optional List
396.1009 +     * operations supported by this List.
396.1010 +     *
396.1011 +     * <p>This method eliminates the need for explicit range operations (of
396.1012 +     * the sort that commonly exist for arrays).  Any operation that expects
396.1013 +     * a List can be used as a range operation by operating on a subList view
396.1014 +     * instead of a whole List.  For example, the following idiom
396.1015 +     * removes a range of elements from a List:
396.1016 +     * <pre>
396.1017 +     *      list.subList(from, to).clear();
396.1018 +     * </pre>
396.1019 +     * Similar idioms may be constructed for indexOf and lastIndexOf,
396.1020 +     * and all of the algorithms in the Collections class can be applied to
396.1021 +     * a subList.
396.1022 +     *
396.1023 +     * <p>The semantics of the List returned by this method become undefined if
396.1024 +     * the backing list (i.e., this List) is <i>structurally modified</i> in
396.1025 +     * any way other than via the returned List.  (Structural modifications are
396.1026 +     * those that change the size of the List, or otherwise perturb it in such
396.1027 +     * a fashion that iterations in progress may yield incorrect results.)
396.1028 +     *
396.1029 +     * @param fromIndex low endpoint (inclusive) of the subList
396.1030 +     * @param toIndex high endpoint (exclusive) of the subList
396.1031 +     * @return a view of the specified range within this List
396.1032 +     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
396.1033 +     *         {@code (fromIndex < 0 || toIndex > size)}
396.1034 +     * @throws IllegalArgumentException if the endpoint indices are out of order
396.1035 +     *         {@code (fromIndex > toIndex)}
396.1036 +     */
396.1037 +    public synchronized List<E> subList(int fromIndex, int toIndex) {
396.1038 +        return Collections.synchronizedList(super.subList(fromIndex, toIndex),
396.1039 +                                            this);
396.1040 +    }
396.1041 +
396.1042 +    /**
396.1043 +     * Removes from this list all of the elements whose index is between
396.1044 +     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
396.1045 +     * Shifts any succeeding elements to the left (reduces their index).
396.1046 +     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
396.1047 +     * (If {@code toIndex==fromIndex}, this operation has no effect.)
396.1048 +     */
396.1049 +    protected synchronized void removeRange(int fromIndex, int toIndex) {
396.1050 +        modCount++;
396.1051 +        int numMoved = elementCount - toIndex;
396.1052 +        System.arraycopy(elementData, toIndex, elementData, fromIndex,
396.1053 +                         numMoved);
396.1054 +
396.1055 +        // Let gc do its work
396.1056 +        int newElementCount = elementCount - (toIndex-fromIndex);
396.1057 +        while (elementCount != newElementCount)
396.1058 +            elementData[--elementCount] = null;
396.1059 +    }
396.1060 +
396.1061 +    /**
396.1062 +     * Returns a list iterator over the elements in this list (in proper
396.1063 +     * sequence), starting at the specified position in the list.
396.1064 +     * The specified index indicates the first element that would be
396.1065 +     * returned by an initial call to {@link ListIterator#next next}.
396.1066 +     * An initial call to {@link ListIterator#previous previous} would
396.1067 +     * return the element with the specified index minus one.
396.1068 +     *
396.1069 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
396.1070 +     *
396.1071 +     * @throws IndexOutOfBoundsException {@inheritDoc}
396.1072 +     */
396.1073 +    public synchronized ListIterator<E> listIterator(int index) {
396.1074 +        if (index < 0 || index > elementCount)
396.1075 +            throw new IndexOutOfBoundsException("Index: "+index);
396.1076 +        return new ListItr(index);
396.1077 +    }
396.1078 +
396.1079 +    /**
396.1080 +     * Returns a list iterator over the elements in this list (in proper
396.1081 +     * sequence).
396.1082 +     *
396.1083 +     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
396.1084 +     *
396.1085 +     * @see #listIterator(int)
396.1086 +     */
396.1087 +    public synchronized ListIterator<E> listIterator() {
396.1088 +        return new ListItr(0);
396.1089 +    }
396.1090 +
396.1091 +    /**
396.1092 +     * Returns an iterator over the elements in this list in proper sequence.
396.1093 +     *
396.1094 +     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
396.1095 +     *
396.1096 +     * @return an iterator over the elements in this list in proper sequence
396.1097 +     */
396.1098 +    public synchronized Iterator<E> iterator() {
396.1099 +        return new Itr();
396.1100 +    }
396.1101 +
396.1102 +    /**
396.1103 +     * An optimized version of AbstractList.Itr
396.1104 +     */
396.1105 +    private class Itr implements Iterator<E> {
396.1106 +        int cursor;       // index of next element to return
396.1107 +        int lastRet = -1; // index of last element returned; -1 if no such
396.1108 +        int expectedModCount = modCount;
396.1109 +
396.1110 +        public boolean hasNext() {
396.1111 +            // Racy but within spec, since modifications are checked
396.1112 +            // within or after synchronization in next/previous
396.1113 +            return cursor != elementCount;
396.1114 +        }
396.1115 +
396.1116 +        public E next() {
396.1117 +            synchronized (Vector.this) {
396.1118 +                checkForComodification();
396.1119 +                int i = cursor;
396.1120 +                if (i >= elementCount)
396.1121 +                    throw new NoSuchElementException();
396.1122 +                cursor = i + 1;
396.1123 +                return elementData(lastRet = i);
396.1124 +            }
396.1125 +        }
396.1126 +
396.1127 +        public void remove() {
396.1128 +            if (lastRet == -1)
396.1129 +                throw new IllegalStateException();
396.1130 +            synchronized (Vector.this) {
396.1131 +                checkForComodification();
396.1132 +                Vector.this.remove(lastRet);
396.1133 +                expectedModCount = modCount;
396.1134 +            }
396.1135 +            cursor = lastRet;
396.1136 +            lastRet = -1;
396.1137 +        }
396.1138 +
396.1139 +        final void checkForComodification() {
396.1140 +            if (modCount != expectedModCount)
396.1141 +                throw new ConcurrentModificationException();
396.1142 +        }
396.1143 +    }
396.1144 +
396.1145 +    /**
396.1146 +     * An optimized version of AbstractList.ListItr
396.1147 +     */
396.1148 +    final class ListItr extends Itr implements ListIterator<E> {
396.1149 +        ListItr(int index) {
396.1150 +            super();
396.1151 +            cursor = index;
396.1152 +        }
396.1153 +
396.1154 +        public boolean hasPrevious() {
396.1155 +            return cursor != 0;
396.1156 +        }
396.1157 +
396.1158 +        public int nextIndex() {
396.1159 +            return cursor;
396.1160 +        }
396.1161 +
396.1162 +        public int previousIndex() {
396.1163 +            return cursor - 1;
396.1164 +        }
396.1165 +
396.1166 +        public E previous() {
396.1167 +            synchronized (Vector.this) {
396.1168 +                checkForComodification();
396.1169 +                int i = cursor - 1;
396.1170 +                if (i < 0)
396.1171 +                    throw new NoSuchElementException();
396.1172 +                cursor = i;
396.1173 +                return elementData(lastRet = i);
396.1174 +            }
396.1175 +        }
396.1176 +
396.1177 +        public void set(E e) {
396.1178 +            if (lastRet == -1)
396.1179 +                throw new IllegalStateException();
396.1180 +            synchronized (Vector.this) {
396.1181 +                checkForComodification();
396.1182 +                Vector.this.set(lastRet, e);
396.1183 +            }
396.1184 +        }
396.1185 +
396.1186 +        public void add(E e) {
396.1187 +            int i = cursor;
396.1188 +            synchronized (Vector.this) {
396.1189 +                checkForComodification();
396.1190 +                Vector.this.add(i, e);
396.1191 +                expectedModCount = modCount;
396.1192 +            }
396.1193 +            cursor = i + 1;
396.1194 +            lastRet = -1;
396.1195 +        }
396.1196 +    }
396.1197 +}
   397.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   397.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/Callable.java	Wed Feb 27 11:24:58 2013 +0100
   397.3 @@ -0,0 +1,65 @@
   397.4 +/*
   397.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   397.6 + *
   397.7 + * This code is free software; you can redistribute it and/or modify it
   397.8 + * under the terms of the GNU General Public License version 2 only, as
   397.9 + * published by the Free Software Foundation.  Oracle designates this
  397.10 + * particular file as subject to the "Classpath" exception as provided
  397.11 + * by Oracle in the LICENSE file that accompanied this code.
  397.12 + *
  397.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  397.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  397.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  397.16 + * version 2 for more details (a copy is included in the LICENSE file that
  397.17 + * accompanied this code).
  397.18 + *
  397.19 + * You should have received a copy of the GNU General Public License version
  397.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  397.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  397.22 + *
  397.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  397.24 + * or visit www.oracle.com if you need additional information or have any
  397.25 + * questions.
  397.26 + */
  397.27 +
  397.28 +/*
  397.29 + * This file is available under and governed by the GNU General Public
  397.30 + * License version 2 only, as published by the Free Software Foundation.
  397.31 + * However, the following notice accompanied the original version of this
  397.32 + * file:
  397.33 + *
  397.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
  397.35 + * Expert Group and released to the public domain, as explained at
  397.36 + * http://creativecommons.org/publicdomain/zero/1.0/
  397.37 + */
  397.38 +
  397.39 +package java.util.concurrent;
  397.40 +
  397.41 +/**
  397.42 + * A task that returns a result and may throw an exception.
  397.43 + * Implementors define a single method with no arguments called
  397.44 + * <tt>call</tt>.
  397.45 + *
  397.46 + * <p>The <tt>Callable</tt> interface is similar to {@link
  397.47 + * java.lang.Runnable}, in that both are designed for classes whose
  397.48 + * instances are potentially executed by another thread.  A
  397.49 + * <tt>Runnable</tt>, however, does not return a result and cannot
  397.50 + * throw a checked exception.
  397.51 + *
  397.52 + * <p> The {@link Executors} class contains utility methods to
  397.53 + * convert from other common forms to <tt>Callable</tt> classes.
  397.54 + *
  397.55 + * @see Executor
  397.56 + * @since 1.5
  397.57 + * @author Doug Lea
  397.58 + * @param <V> the result type of method <tt>call</tt>
  397.59 + */
  397.60 +public interface Callable<V> {
  397.61 +    /**
  397.62 +     * Computes a result, or throws an exception if unable to do so.
  397.63 +     *
  397.64 +     * @return computed result
  397.65 +     * @throws Exception if unable to compute a result
  397.66 +     */
  397.67 +    V call() throws Exception;
  397.68 +}
   398.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   398.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/TimeUnit.java	Wed Feb 27 11:24:58 2013 +0100
   398.3 @@ -0,0 +1,367 @@
   398.4 +/*
   398.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   398.6 + *
   398.7 + * This code is free software; you can redistribute it and/or modify it
   398.8 + * under the terms of the GNU General Public License version 2 only, as
   398.9 + * published by the Free Software Foundation.  Oracle designates this
  398.10 + * particular file as subject to the "Classpath" exception as provided
  398.11 + * by Oracle in the LICENSE file that accompanied this code.
  398.12 + *
  398.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  398.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  398.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  398.16 + * version 2 for more details (a copy is included in the LICENSE file that
  398.17 + * accompanied this code).
  398.18 + *
  398.19 + * You should have received a copy of the GNU General Public License version
  398.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  398.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  398.22 + *
  398.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  398.24 + * or visit www.oracle.com if you need additional information or have any
  398.25 + * questions.
  398.26 + */
  398.27 +
  398.28 +/*
  398.29 + * This file is available under and governed by the GNU General Public
  398.30 + * License version 2 only, as published by the Free Software Foundation.
  398.31 + * However, the following notice accompanied the original version of this
  398.32 + * file:
  398.33 + *
  398.34 + * Written by Doug Lea with assistance from members of JCP JSR-166
  398.35 + * Expert Group and released to the public domain, as explained at
  398.36 + * http://creativecommons.org/publicdomain/zero/1.0/
  398.37 + */
  398.38 +
  398.39 +package java.util.concurrent;
  398.40 +
  398.41 +/**
  398.42 + * A <tt>TimeUnit</tt> represents time durations at a given unit of
  398.43 + * granularity and provides utility methods to convert across units,
  398.44 + * and to perform timing and delay operations in these units.  A
  398.45 + * <tt>TimeUnit</tt> does not maintain time information, but only
  398.46 + * helps organize and use time representations that may be maintained
  398.47 + * separately across various contexts.  A nanosecond is defined as one
  398.48 + * thousandth of a microsecond, a microsecond as one thousandth of a
  398.49 + * millisecond, a millisecond as one thousandth of a second, a minute
  398.50 + * as sixty seconds, an hour as sixty minutes, and a day as twenty four
  398.51 + * hours.
  398.52 + *
  398.53 + * <p>A <tt>TimeUnit</tt> is mainly used to inform time-based methods
  398.54 + * how a given timing parameter should be interpreted. For example,
  398.55 + * the following code will timeout in 50 milliseconds if the {@link
  398.56 + * java.util.concurrent.locks.Lock lock} is not available:
  398.57 + *
  398.58 + * <pre>  Lock lock = ...;
  398.59 + *  if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...
  398.60 + * </pre>
  398.61 + * while this code will timeout in 50 seconds:
  398.62 + * <pre>
  398.63 + *  Lock lock = ...;
  398.64 + *  if (lock.tryLock(50L, TimeUnit.SECONDS)) ...
  398.65 + * </pre>
  398.66 + *
  398.67 + * Note however, that there is no guarantee that a particular timeout
  398.68 + * implementation will be able to notice the passage of time at the
  398.69 + * same granularity as the given <tt>TimeUnit</tt>.
  398.70 + *
  398.71 + * @since 1.5
  398.72 + * @author Doug Lea
  398.73 + */
  398.74 +public enum TimeUnit {
  398.75 +    NANOSECONDS {
  398.76 +        public long toNanos(long d)   { return d; }
  398.77 +        public long toMicros(long d)  { return d/(C1/C0); }
  398.78 +        public long toMillis(long d)  { return d/(C2/C0); }
  398.79 +        public long toSeconds(long d) { return d/(C3/C0); }
  398.80 +        public long toMinutes(long d) { return d/(C4/C0); }
  398.81 +        public long toHours(long d)   { return d/(C5/C0); }
  398.82 +        public long toDays(long d)    { return d/(C6/C0); }
  398.83 +        public long convert(long d, TimeUnit u) { return u.toNanos(d); }
  398.84 +        int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
  398.85 +    },
  398.86 +    MICROSECONDS {
  398.87 +        public long toNanos(long d)   { return x(d, C1/C0, MAX/(C1/C0)); }
  398.88 +        public long toMicros(long d)  { return d; }
  398.89 +        public long toMillis(long d)  { return d/(C2/C1); }
  398.90 +        public long toSeconds(long d) { return d/(C3/C1); }
  398.91 +        public long toMinutes(long d) { return d/(C4/C1); }
  398.92 +        public long toHours(long d)   { return d/(C5/C1); }
  398.93 +        public long toDays(long d)    { return d/(C6/C1); }
  398.94 +        public long convert(long d, TimeUnit u) { return u.toMicros(d); }
  398.95 +        int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
  398.96 +    },
  398.97 +    MILLISECONDS {
  398.98 +        public long toNanos(long d)   { return x(d, C2/C0, MAX/(C2/C0)); }
  398.99 +        public long toMicros(long d)  { return x(d, C2/C1, MAX/(C2/C1)); }
 398.100 +        public long toMillis(long d)  { return d; }
 398.101 +        public long toSeconds(long d) { return d/(C3/C2); }
 398.102 +        public long toMinutes(long d) { return d/(C4/C2); }
 398.103 +        public long toHours(long d)   { return d/(C5/C2); }
 398.104 +        public long toDays(long d)    { return d/(C6/C2); }
 398.105 +        public long convert(long d, TimeUnit u) { return u.toMillis(d); }
 398.106 +        int excessNanos(long d, long m) { return 0; }
 398.107 +    },
 398.108 +    SECONDS {
 398.109 +        public long toNanos(long d)   { return x(d, C3/C0, MAX/(C3/C0)); }
 398.110 +        public long toMicros(long d)  { return x(d, C3/C1, MAX/(C3/C1)); }
 398.111 +        public long toMillis(long d)  { return x(d, C3/C2, MAX/(C3/C2)); }
 398.112 +        public long toSeconds(long d) { return d; }
 398.113 +        public long toMinutes(long d) { return d/(C4/C3); }
 398.114 +        public long toHours(long d)   { return d/(C5/C3); }
 398.115 +        public long toDays(long d)    { return d/(C6/C3); }
 398.116 +        public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
 398.117 +        int excessNanos(long d, long m) { return 0; }
 398.118 +    },
 398.119 +    MINUTES {
 398.120 +        public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
 398.121 +        public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
 398.122 +        public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
 398.123 +        public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); }
 398.124 +        public long toMinutes(long d) { return d; }
 398.125 +        public long toHours(long d)   { return d/(C5/C4); }
 398.126 +        public long toDays(long d)    { return d/(C6/C4); }
 398.127 +        public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
 398.128 +        int excessNanos(long d, long m) { return 0; }
 398.129 +    },
 398.130 +    HOURS {
 398.131 +        public long toNanos(long d)   { return x(d, C5/C0, MAX/(C5/C0)); }
 398.132 +        public long toMicros(long d)  { return x(d, C5/C1, MAX/(C5/C1)); }
 398.133 +        public long toMillis(long d)  { return x(d, C5/C2, MAX/(C5/C2)); }
 398.134 +        public long toSeconds(long d) { return x(d, C5/C3, MAX/(C5/C3)); }
 398.135 +        public long toMinutes(long d) { return x(d, C5/C4, MAX/(C5/C4)); }
 398.136 +        public long toHours(long d)   { return d; }
 398.137 +        public long toDays(long d)    { return d/(C6/C5); }
 398.138 +        public long convert(long d, TimeUnit u) { return u.toHours(d); }
 398.139 +        int excessNanos(long d, long m) { return 0; }
 398.140 +    },
 398.141 +    DAYS {
 398.142 +        public long toNanos(long d)   { return x(d, C6/C0, MAX/(C6/C0)); }
 398.143 +        public long toMicros(long d)  { return x(d, C6/C1, MAX/(C6/C1)); }
 398.144 +        public long toMillis(long d)  { return x(d, C6/C2, MAX/(C6/C2)); }
 398.145 +        public long toSeconds(long d) { return x(d, C6/C3, MAX/(C6/C3)); }
 398.146 +        public long toMinutes(long d) { return x(d, C6/C4, MAX/(C6/C4)); }
 398.147 +        public long toHours(long d)   { return x(d, C6/C5, MAX/(C6/C5)); }
 398.148 +        public long toDays(long d)    { return d; }
 398.149 +        public long convert(long d, TimeUnit u) { return u.toDays(d); }
 398.150 +        int excessNanos(long d, long m) { return 0; }
 398.151 +    };
 398.152 +
 398.153 +    // Handy constants for conversion methods
 398.154 +    static final long C0 = 1L;
 398.155 +    static final long C1 = C0 * 1000L;
 398.156 +    static final long C2 = C1 * 1000L;
 398.157 +    static final long C3 = C2 * 1000L;
 398.158 +    static final long C4 = C3 * 60L;
 398.159 +    static final long C5 = C4 * 60L;
 398.160 +    static final long C6 = C5 * 24L;
 398.161 +
 398.162 +    static final long MAX = Long.MAX_VALUE;
 398.163 +
 398.164 +    /**
 398.165 +     * Scale d by m, checking for overflow.
 398.166 +     * This has a short name to make above code more readable.
 398.167 +     */
 398.168 +    static long x(long d, long m, long over) {
 398.169 +        if (d >  over) return Long.MAX_VALUE;
 398.170 +        if (d < -over) return Long.MIN_VALUE;
 398.171 +        return d * m;
 398.172 +    }
 398.173 +
 398.174 +    // To maintain full signature compatibility with 1.5, and to improve the
 398.175 +    // clarity of the generated javadoc (see 6287639: Abstract methods in
 398.176 +    // enum classes should not be listed as abstract), method convert
 398.177 +    // etc. are not declared abstract but otherwise act as abstract methods.
 398.178 +
 398.179 +    /**
 398.180 +     * Convert the given time duration in the given unit to this
 398.181 +     * unit.  Conversions from finer to coarser granularities
 398.182 +     * truncate, so lose precision. For example converting
 398.183 +     * <tt>999</tt> milliseconds to seconds results in
 398.184 +     * <tt>0</tt>. Conversions from coarser to finer granularities
 398.185 +     * with arguments that would numerically overflow saturate to
 398.186 +     * <tt>Long.MIN_VALUE</tt> if negative or <tt>Long.MAX_VALUE</tt>
 398.187 +     * if positive.
 398.188 +     *
 398.189 +     * <p>For example, to convert 10 minutes to milliseconds, use:
 398.190 +     * <tt>TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)</tt>
 398.191 +     *
 398.192 +     * @param sourceDuration the time duration in the given <tt>sourceUnit</tt>
 398.193 +     * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
 398.194 +     * @return the converted duration in this unit,
 398.195 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.196 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.197 +     */
 398.198 +    public long convert(long sourceDuration, TimeUnit sourceUnit) {
 398.199 +        throw new AbstractMethodError();
 398.200 +    }
 398.201 +
 398.202 +    /**
 398.203 +     * Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>.
 398.204 +     * @param duration the duration
 398.205 +     * @return the converted duration,
 398.206 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.207 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.208 +     * @see #convert
 398.209 +     */
 398.210 +    public long toNanos(long duration) {
 398.211 +        throw new AbstractMethodError();
 398.212 +    }
 398.213 +
 398.214 +    /**
 398.215 +     * Equivalent to <tt>MICROSECONDS.convert(duration, this)</tt>.
 398.216 +     * @param duration the duration
 398.217 +     * @return the converted duration,
 398.218 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.219 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.220 +     * @see #convert
 398.221 +     */
 398.222 +    public long toMicros(long duration) {
 398.223 +        throw new AbstractMethodError();
 398.224 +    }
 398.225 +
 398.226 +    /**
 398.227 +     * Equivalent to <tt>MILLISECONDS.convert(duration, this)</tt>.
 398.228 +     * @param duration the duration
 398.229 +     * @return the converted duration,
 398.230 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.231 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.232 +     * @see #convert
 398.233 +     */
 398.234 +    public long toMillis(long duration) {
 398.235 +        throw new AbstractMethodError();
 398.236 +    }
 398.237 +
 398.238 +    /**
 398.239 +     * Equivalent to <tt>SECONDS.convert(duration, this)</tt>.
 398.240 +     * @param duration the duration
 398.241 +     * @return the converted duration,
 398.242 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.243 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.244 +     * @see #convert
 398.245 +     */
 398.246 +    public long toSeconds(long duration) {
 398.247 +        throw new AbstractMethodError();
 398.248 +    }
 398.249 +
 398.250 +    /**
 398.251 +     * Equivalent to <tt>MINUTES.convert(duration, this)</tt>.
 398.252 +     * @param duration the duration
 398.253 +     * @return the converted duration,
 398.254 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.255 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.256 +     * @see #convert
 398.257 +     * @since 1.6
 398.258 +     */
 398.259 +    public long toMinutes(long duration) {
 398.260 +        throw new AbstractMethodError();
 398.261 +    }
 398.262 +
 398.263 +    /**
 398.264 +     * Equivalent to <tt>HOURS.convert(duration, this)</tt>.
 398.265 +     * @param duration the duration
 398.266 +     * @return the converted duration,
 398.267 +     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
 398.268 +     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
 398.269 +     * @see #convert
 398.270 +     * @since 1.6
 398.271 +     */
 398.272 +    public long toHours(long duration) {
 398.273 +        throw new AbstractMethodError();
 398.274 +    }
 398.275 +
 398.276 +    /**
 398.277 +     * Equivalent to <tt>DAYS.convert(duration, this)</tt>.
 398.278 +     * @param duration the duration
 398.279 +     * @return the converted duration
 398.280 +     * @see #convert
 398.281 +     * @since 1.6
 398.282 +     */
 398.283 +    public long toDays(long duration) {
 398.284 +        throw new AbstractMethodError();
 398.285 +    }
 398.286 +
 398.287 +    /**
 398.288 +     * Utility to compute the excess-nanosecond argument to wait,
 398.289 +     * sleep, join.
 398.290 +     * @param d the duration
 398.291 +     * @param m the number of milliseconds
 398.292 +     * @return the number of nanoseconds
 398.293 +     */
 398.294 +    abstract int excessNanos(long d, long m);
 398.295 +
 398.296 +    /**
 398.297 +     * Performs a timed {@link Object#wait(long, int) Object.wait}
 398.298 +     * using this time unit.
 398.299 +     * This is a convenience method that converts timeout arguments
 398.300 +     * into the form required by the <tt>Object.wait</tt> method.
 398.301 +     *
 398.302 +     * <p>For example, you could implement a blocking <tt>poll</tt>
 398.303 +     * method (see {@link BlockingQueue#poll BlockingQueue.poll})
 398.304 +     * using:
 398.305 +     *
 398.306 +     *  <pre> {@code
 398.307 +     * public synchronized Object poll(long timeout, TimeUnit unit)
 398.308 +     *     throws InterruptedException {
 398.309 +     *   while (empty) {
 398.310 +     *     unit.timedWait(this, timeout);
 398.311 +     *     ...
 398.312 +     *   }
 398.313 +     * }}</pre>
 398.314 +     *
 398.315 +     * @param obj the object to wait on
 398.316 +     * @param timeout the maximum time to wait. If less than
 398.317 +     * or equal to zero, do not wait at all.
 398.318 +     * @throws InterruptedException if interrupted while waiting
 398.319 +     */
 398.320 +    public void timedWait(Object obj, long timeout)
 398.321 +            throws InterruptedException {
 398.322 +        if (timeout > 0) {
 398.323 +            long ms = toMillis(timeout);
 398.324 +            int ns = excessNanos(timeout, ms);
 398.325 +            obj.wait(ms, ns);
 398.326 +        }
 398.327 +    }
 398.328 +
 398.329 +    /**
 398.330 +     * Performs a timed {@link Thread#join(long, int) Thread.join}
 398.331 +     * using this time unit.
 398.332 +     * This is a convenience method that converts time arguments into the
 398.333 +     * form required by the <tt>Thread.join</tt> method.
 398.334 +     *
 398.335 +     * @param thread the thread to wait for
 398.336 +     * @param timeout the maximum time to wait. If less than
 398.337 +     * or equal to zero, do not wait at all.
 398.338 +     * @throws InterruptedException if interrupted while waiting
 398.339 +     */
 398.340 +//    public void timedJoin(Thread thread, long timeout)
 398.341 +//            throws InterruptedException {
 398.342 +//        if (timeout > 0) {
 398.343 +//            long ms = toMillis(timeout);
 398.344 +//            int ns = excessNanos(timeout, ms);
 398.345 +//            thread.join(ms, ns);
 398.346 +//        }
 398.347 +//    }
 398.348 +
 398.349 +    /**
 398.350 +     * Performs a {@link Thread#sleep(long, int) Thread.sleep} using
 398.351 +     * this time unit.
 398.352 +     * This is a convenience method that converts time arguments into the
 398.353 +     * form required by the <tt>Thread.sleep</tt> method.
 398.354 +     *
 398.355 +     * @param timeout the minimum time to sleep. If less than
 398.356 +     * or equal to zero, do not sleep at all.
 398.357 +     * @throws InterruptedException if interrupted while sleeping
 398.358 +     */
 398.359 +    public void sleep(long timeout) throws InterruptedException {
 398.360 +        if (timeout > 0) {
 398.361 +            long ms = toMillis(timeout);
 398.362 +            int ns = excessNanos(timeout, ms);
 398.363 +            Object o = new Object();
 398.364 +            synchronized (o) {
 398.365 +                o.wait(ms, ns);
 398.366 +            }
 398.367 +        }
 398.368 +    }
 398.369 +
 398.370 +}
   399.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   399.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java	Wed Feb 27 11:24:58 2013 +0100
   399.3 @@ -0,0 +1,107 @@
   399.4 +/**
   399.5 + * Back 2 Browser Bytecode Translator
   399.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   399.7 + *
   399.8 + * This program is free software: you can redistribute it and/or modify
   399.9 + * it under the terms of the GNU General Public License as published by
  399.10 + * the Free Software Foundation, version 2 of the License.
  399.11 + *
  399.12 + * This program is distributed in the hope that it will be useful,
  399.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  399.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  399.15 + * GNU General Public License for more details.
  399.16 + *
  399.17 + * You should have received a copy of the GNU General Public License
  399.18 + * along with this program. Look for COPYING file in the top folder.
  399.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  399.20 + */
  399.21 +package org.apidesign.bck2brwsr.compact.tck;
  399.22 +
  399.23 +import java.util.ArrayList;
  399.24 +import java.util.Arrays;
  399.25 +import java.util.Collection;
  399.26 +import java.util.Comparator;
  399.27 +import java.util.HashMap;
  399.28 +import java.util.HashSet;
  399.29 +import java.util.List;
  399.30 +import java.util.Map;
  399.31 +import java.util.Map.Entry;
  399.32 +import java.util.Vector;
  399.33 +import org.apidesign.bck2brwsr.vmtest.Compare;
  399.34 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  399.35 +import org.testng.annotations.Factory;
  399.36 +
  399.37 +/**
  399.38 + *
  399.39 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  399.40 + */
  399.41 +public class CollectionsTest {
  399.42 +    @Compare public String sortStringsInArray() {
  399.43 +        List<String> list = new ArrayList<>();
  399.44 +        list.add("one");
  399.45 +        list.add("two");
  399.46 +        list.add("three");
  399.47 +        list.add("four");
  399.48 +        list.add("five");
  399.49 +        list.add("six");
  399.50 +        list.add("seven");
  399.51 +        list.add("eight");
  399.52 +        list.add("nine");
  399.53 +        list.add("ten");
  399.54 +        
  399.55 +        String[] arr = list.toArray(new String[list.size()]);
  399.56 +        Arrays.sort(arr);
  399.57 +        
  399.58 +        return Arrays.asList(arr).toString();
  399.59 +    }
  399.60 +    
  399.61 +    @Compare public String sortStringsInHashSet() {
  399.62 +        Collection<String> list = new HashSet<>();
  399.63 +        list.add("one");
  399.64 +        list.add("two");
  399.65 +        list.add("three");
  399.66 +        list.add("four");
  399.67 +        list.add("five");
  399.68 +        list.add("six");
  399.69 +        list.add("seven");
  399.70 +        list.add("eight");
  399.71 +        list.add("nine");
  399.72 +        list.add("ten");
  399.73 +        
  399.74 +        String[] arr = list.toArray(new String[0]);
  399.75 +        Arrays.sort(arr);
  399.76 +        
  399.77 +        return Arrays.asList(arr).toString();
  399.78 +    }
  399.79 +
  399.80 +    @SuppressWarnings("unchecked")
  399.81 +    @Compare public String sortStringsInHashMapWithComparator() {
  399.82 +        class C implements Comparator<Map.Entry<String,Integer>> {
  399.83 +            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
  399.84 +                return o1.getKey().compareTo(o2.getKey());
  399.85 +            }
  399.86 +        }
  399.87 +        
  399.88 +        Map<String,Integer> map = new HashMap<>();
  399.89 +        map.put("one", 1);
  399.90 +        map.put("two", 2);
  399.91 +        map.put("three", 3);
  399.92 +        map.put("four", 4);
  399.93 +        map.put("five", 5);
  399.94 +        map.put("six", 6);
  399.95 +        map.put("seven", 7);
  399.96 +        map.put("eight", 8);
  399.97 +        map.put("nine", 9);
  399.98 +        map.put("ten", 10);
  399.99 +        
 399.100 +        List<Entry<String,Integer>> arr = new Vector<>();
 399.101 +        arr.addAll(map.entrySet());
 399.102 +        return arr.toString();
 399.103 +    }
 399.104 +    
 399.105 +    @Factory
 399.106 +    public static Object[] create() {
 399.107 +        return VMTest.create(CollectionsTest.class);
 399.108 +    }
 399.109 +    
 399.110 +}
   400.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   400.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java	Wed Feb 27 11:24:58 2013 +0100
   400.3 @@ -0,0 +1,84 @@
   400.4 +/**
   400.5 + * Back 2 Browser Bytecode Translator
   400.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   400.7 + *
   400.8 + * This program is free software: you can redistribute it and/or modify
   400.9 + * it under the terms of the GNU General Public License as published by
  400.10 + * the Free Software Foundation, version 2 of the License.
  400.11 + *
  400.12 + * This program is distributed in the hope that it will be useful,
  400.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  400.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  400.15 + * GNU General Public License for more details.
  400.16 + *
  400.17 + * You should have received a copy of the GNU General Public License
  400.18 + * along with this program. Look for COPYING file in the top folder.
  400.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  400.20 + */
  400.21 +package org.apidesign.bck2brwsr.compact.tck;
  400.22 +
  400.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  400.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  400.25 +import org.testng.annotations.Factory;
  400.26 +
  400.27 +
  400.28 +public class JFXIssuesTest {
  400.29 +    private abstract class Application {
  400.30 +        public abstract int getID();
  400.31 +    }
  400.32 +    
  400.33 +    private class MyApplication extends Application {
  400.34 +
  400.35 +        @Override
  400.36 +        public int getID() {
  400.37 +            return 1;
  400.38 +        }
  400.39 +        
  400.40 +    } 
  400.41 +    
  400.42 +    @Compare public boolean isClassAssignable() {
  400.43 +        return Application.class.isAssignableFrom(MyApplication.class);
  400.44 +    }
  400.45 +
  400.46 +    @Compare public boolean isNaN() {
  400.47 +        return Double.isNaN(Double.NaN);
  400.48 +    }
  400.49 +
  400.50 +    @Compare public boolean isInfinite() {
  400.51 +        return Float.isInfinite(Float.NEGATIVE_INFINITY);
  400.52 +    }
  400.53 +
  400.54 +    @Compare public boolean areTimesEqual() {
  400.55 +        long l1 = System.currentTimeMillis();
  400.56 +        long l2 = l1 + 0;
  400.57 +
  400.58 +        return l1 == l2;
  400.59 +    }
  400.60 +    
  400.61 +    @Compare public boolean roundOnDouble() {
  400.62 +        long l1 = Math.round(System.currentTimeMillis() / 1.1);
  400.63 +        long l2 = l1 + 0;
  400.64 +        
  400.65 +        return l1 == l2;
  400.66 +    }
  400.67 +
  400.68 +    private static long val = 1238078409318L;
  400.69 +    
  400.70 +    @Compare public int valueConvertedToString() {
  400.71 +        return (int) val++;
  400.72 +    }
  400.73 +    
  400.74 +    @Compare public boolean roundOnFloat() {
  400.75 +        final float f = System.currentTimeMillis() / 1.1f;
  400.76 +        int l1 = Math.round(f);
  400.77 +        int l2 = l1 + 0;
  400.78 +        
  400.79 +        assert l1 == l2 : "Round " + l1 + " == " + l2;
  400.80 +        
  400.81 +        return l1 == l2;
  400.82 +    }
  400.83 +    
  400.84 +    @Factory public static Object[] create() {
  400.85 +        return VMTest.create(JFXIssuesTest.class);
  400.86 +    }
  400.87 +}
   401.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   401.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/RandomTest.java	Wed Feb 27 11:24:58 2013 +0100
   401.3 @@ -0,0 +1,40 @@
   401.4 +/**
   401.5 + * Back 2 Browser Bytecode Translator
   401.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   401.7 + *
   401.8 + * This program is free software: you can redistribute it and/or modify
   401.9 + * it under the terms of the GNU General Public License as published by
  401.10 + * the Free Software Foundation, version 2 of the License.
  401.11 + *
  401.12 + * This program is distributed in the hope that it will be useful,
  401.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  401.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  401.15 + * GNU General Public License for more details.
  401.16 + *
  401.17 + * You should have received a copy of the GNU General Public License
  401.18 + * along with this program. Look for COPYING file in the top folder.
  401.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  401.20 + */
  401.21 +package org.apidesign.bck2brwsr.compact.tck;
  401.22 +
  401.23 +import java.util.Random;
  401.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
  401.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  401.26 +import org.testng.annotations.Factory;
  401.27 +
  401.28 +/**
  401.29 + *
  401.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  401.31 + */
  401.32 +public class RandomTest {
  401.33 +    @Compare public boolean canInstantiateRandom() {
  401.34 +        Random r = new Random();
  401.35 +        r.nextInt();
  401.36 +        return r != null;
  401.37 +    }
  401.38 +
  401.39 +    
  401.40 +    @Factory public static Object[] create() {
  401.41 +        return VMTest.create(RandomTest.class);
  401.42 +    }
  401.43 +}
   402.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   402.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java	Wed Feb 27 11:24:58 2013 +0100
   402.3 @@ -0,0 +1,61 @@
   402.4 +/**
   402.5 + * Back 2 Browser Bytecode Translator
   402.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   402.7 + *
   402.8 + * This program is free software: you can redistribute it and/or modify
   402.9 + * it under the terms of the GNU General Public License as published by
  402.10 + * the Free Software Foundation, version 2 of the License.
  402.11 + *
  402.12 + * This program is distributed in the hope that it will be useful,
  402.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  402.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  402.15 + * GNU General Public License for more details.
  402.16 + *
  402.17 + * You should have received a copy of the GNU General Public License
  402.18 + * along with this program. Look for COPYING file in the top folder.
  402.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  402.20 + */
  402.21 +package org.apidesign.bck2brwsr.compact.tck;
  402.22 +
  402.23 +import java.io.ByteArrayInputStream;
  402.24 +import java.io.IOException;
  402.25 +import java.io.InputStreamReader;
  402.26 +import java.io.UnsupportedEncodingException;
  402.27 +import java.util.Arrays;
  402.28 +import org.apidesign.bck2brwsr.vmtest.Compare;
  402.29 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  402.30 +import org.testng.annotations.Factory;
  402.31 +
  402.32 +/**
  402.33 + *
  402.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  402.35 + */
  402.36 +public class ReaderTest {
  402.37 +    @Compare public String readUTFString() throws IOException {
  402.38 +        byte[] arr = { 
  402.39 +            (byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91, 
  402.40 +            (byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61, 
  402.41 +            (byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59, 
  402.42 +            (byte)-120 
  402.43 +        };
  402.44 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  402.45 +        InputStreamReader r = new InputStreamReader(is, "UTF-8");
  402.46 +        
  402.47 +        StringBuilder sb = new StringBuilder();
  402.48 +        for (;;) {
  402.49 +            int ch = r.read();
  402.50 +            if (ch == -1) {
  402.51 +                break;
  402.52 +            }
  402.53 +            sb.append((char)ch);
  402.54 +        }
  402.55 +        return sb.toString().toString();
  402.56 +    }
  402.57 +    @Compare public String stringToBytes() throws UnsupportedEncodingException {
  402.58 +        return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8"));
  402.59 +    }
  402.60 +    
  402.61 +    @Factory public static Object[] create() {
  402.62 +        return VMTest.create(ReaderTest.class);
  402.63 +    }
  402.64 +}
   403.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   403.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ServiceLoaderTest.java	Wed Feb 27 11:24:58 2013 +0100
   403.3 @@ -0,0 +1,61 @@
   403.4 +/**
   403.5 + * Back 2 Browser Bytecode Translator
   403.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   403.7 + *
   403.8 + * This program is free software: you can redistribute it and/or modify
   403.9 + * it under the terms of the GNU General Public License as published by
  403.10 + * the Free Software Foundation, version 2 of the License.
  403.11 + *
  403.12 + * This program is distributed in the hope that it will be useful,
  403.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  403.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  403.15 + * GNU General Public License for more details.
  403.16 + *
  403.17 + * You should have received a copy of the GNU General Public License
  403.18 + * along with this program. Look for COPYING file in the top folder.
  403.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  403.20 + */
  403.21 +package org.apidesign.bck2brwsr.compact.tck;
  403.22 +
  403.23 +import java.io.IOException;
  403.24 +import java.util.ServiceLoader;
  403.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
  403.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  403.27 +import org.openide.util.lookup.ServiceProvider;
  403.28 +import org.testng.annotations.Factory;
  403.29 +
  403.30 +/**
  403.31 + *
  403.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  403.33 + */
  403.34 +public class ServiceLoaderTest {
  403.35 +    @Compare//(scripting = false) 
  403.36 +    public Object findsIOException() {
  403.37 +//      delayStart();
  403.38 +        for (IOException e : ServiceLoader.load(IOException.class)) {
  403.39 +            return "Found service: " + e.getClass().getName();
  403.40 +        }
  403.41 +        return null;
  403.42 +    }
  403.43 +/*    
  403.44 +    @org.apidesign.bck2brwsr.core.JavaScriptBody(args = { "a" }, body = "alert(a);")
  403.45 +    private static void alert(String a) {
  403.46 +    }
  403.47 +    private void delayStart() {
  403.48 +        for (int i = 0; i < 10; i++) {
  403.49 +            alert("State: " + i);
  403.50 +            for (int j = 0; j < 493208409; j++) ;
  403.51 +        }
  403.52 +    }
  403.53 +*/
  403.54 +    
  403.55 +    @Factory
  403.56 +    public static Object[] create() {
  403.57 +        return VMTest.create(ServiceLoaderTest.class);
  403.58 +    }
  403.59 +
  403.60 +    
  403.61 +    @ServiceProvider(service = IOException.class)
  403.62 +    public static class MyException extends IOException {
  403.63 +    }
  403.64 +}
   404.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   404.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipArchive.java	Wed Feb 27 11:24:58 2013 +0100
   404.3 @@ -0,0 +1,154 @@
   404.4 +/**
   404.5 + * Back 2 Browser Bytecode Translator
   404.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   404.7 + *
   404.8 + * This program is free software: you can redistribute it and/or modify
   404.9 + * it under the terms of the GNU General Public License as published by
  404.10 + * the Free Software Foundation, version 2 of the License.
  404.11 + *
  404.12 + * This program is distributed in the hope that it will be useful,
  404.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  404.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  404.15 + * GNU General Public License for more details.
  404.16 + *
  404.17 + * You should have received a copy of the GNU General Public License
  404.18 + * along with this program. Look for COPYING file in the top folder.
  404.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  404.20 + */
  404.21 +package org.apidesign.bck2brwsr.compact.tck;
  404.22 +
  404.23 +import java.io.ByteArrayOutputStream;
  404.24 +import java.io.IOException;
  404.25 +import java.io.InputStream;
  404.26 +import java.util.Arrays;
  404.27 +import java.util.LinkedHashMap;
  404.28 +import java.util.Map;
  404.29 +import java.util.Objects;
  404.30 +import java.util.zip.ZipEntry;
  404.31 +import org.apidesign.bck2brwsr.emul.zip.ZipInputStream;
  404.32 +
  404.33 +/**
  404.34 + *
  404.35 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  404.36 + */
  404.37 +final class ZipArchive {
  404.38 +    private final Map<String, byte[]> entries = new LinkedHashMap<>();
  404.39 +
  404.40 +    public static ZipArchive createZip(InputStream is) throws IOException {
  404.41 +        ZipArchive a = new ZipArchive();
  404.42 +        readZip(is, a);
  404.43 +        return a;
  404.44 +    }
  404.45 +
  404.46 +    public static ZipArchive createReal(InputStream is) throws IOException {
  404.47 +        ZipArchive a = new ZipArchive();
  404.48 +        realZip(is, a);
  404.49 +        return a;
  404.50 +    }
  404.51 +
  404.52 +    /**
  404.53 +     * Registers entry name and data
  404.54 +     */
  404.55 +    final void register(String entry, InputStream is) throws IOException {
  404.56 +        ByteArrayOutputStream os = new ByteArrayOutputStream();
  404.57 +        for (;;) {
  404.58 +            int ch = is.read();
  404.59 +            if (ch == -1) {
  404.60 +                break;
  404.61 +            }
  404.62 +            os.write(ch);
  404.63 +        }
  404.64 +        os.close();
  404.65 +        entries.put(entry, os.toByteArray());
  404.66 +    }
  404.67 +
  404.68 +    @Override
  404.69 +    public int hashCode() {
  404.70 +        return entries.hashCode();
  404.71 +    }
  404.72 +
  404.73 +    @Override
  404.74 +    public boolean equals(Object obj) {
  404.75 +        if (obj == null) {
  404.76 +            return false;
  404.77 +        }
  404.78 +        if (getClass() != obj.getClass()) {
  404.79 +            return false;
  404.80 +        }
  404.81 +        final ZipArchive other = (ZipArchive) obj;
  404.82 +        if (!Objects.deepEquals(this.entries, other.entries)) {
  404.83 +            return false;
  404.84 +        }
  404.85 +        return true;
  404.86 +    }
  404.87 +
  404.88 +    @Override
  404.89 +    public String toString() {
  404.90 +        StringBuilder sb = new StringBuilder();
  404.91 +        for (Map.Entry<String, byte[]> en : entries.entrySet()) {
  404.92 +            String string = en.getKey();
  404.93 +            byte[] bs = en.getValue();
  404.94 +            sb.append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
  404.95 +        }
  404.96 +        return sb.toString();
  404.97 +    }
  404.98 +
  404.99 +    public void assertEquals(ZipArchive zip, String msg) {
 404.100 +        boolean ok = true;
 404.101 +        StringBuilder sb = new StringBuilder();
 404.102 +        sb.append(msg);
 404.103 +        for (Map.Entry<String, byte[]> en : entries.entrySet()) {
 404.104 +            String string = en.getKey();
 404.105 +            byte[] bs = en.getValue();
 404.106 +            byte[] other = zip.entries.get(string);
 404.107 +            sb.append("\n");
 404.108 +            if (other == null) {
 404.109 +                sb.append("EXTRA ").append(string).append(" = ").append(Arrays.toString(bs));
 404.110 +                ok = false;
 404.111 +                continue;
 404.112 +            }
 404.113 +            if (Arrays.equals(bs, other)) {
 404.114 +                sb.append("OK    ").append(string);
 404.115 +                continue;
 404.116 +            } else {
 404.117 +                sb.append("DIFF  ").append(string).append(" = ").append(Arrays.toString(bs)).append("\n");
 404.118 +                sb.append("    TO").append(string).append(" = ").append(Arrays.toString(other)).append("\n");
 404.119 +                ok = false;
 404.120 +                continue;
 404.121 +            }
 404.122 +        }
 404.123 +        for (Map.Entry<String, byte[]> entry : zip.entries.entrySet()) {
 404.124 +            String string = entry.getKey();
 404.125 +            if (entries.get(string) == null) {
 404.126 +                sb.append("MISS  ").append(string).append(" = ").append(Arrays.toString(entry.getValue()));
 404.127 +                ok = false;
 404.128 +            }
 404.129 +        }
 404.130 +        if (!ok) {
 404.131 +            assert false : sb.toString();
 404.132 +        }
 404.133 +    }
 404.134 +
 404.135 +    public static void readZip(InputStream is, ZipArchive data) throws IOException {
 404.136 +        ZipInputStream zip = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(is);
 404.137 +        for (;;) {
 404.138 +            ZipEntry en = zip.getNextEntry();
 404.139 +            if (en == null) {
 404.140 +                return;
 404.141 +            }
 404.142 +            data.register(en.getName(), zip);
 404.143 +        }
 404.144 +    }
 404.145 +
 404.146 +    public static void realZip(InputStream is, ZipArchive data) throws IOException {
 404.147 +        java.util.zip.ZipInputStream zip = new java.util.zip.ZipInputStream(is);
 404.148 +        for (;;) {
 404.149 +            ZipEntry en = zip.getNextEntry();
 404.150 +            if (en == null) {
 404.151 +                return;
 404.152 +            }
 404.153 +            data.register(en.getName(), zip);
 404.154 +        }
 404.155 +    }
 404.156 +    
 404.157 +}
   405.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   405.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipCompatibilityTest.java	Wed Feb 27 11:24:58 2013 +0100
   405.3 @@ -0,0 +1,42 @@
   405.4 +/**
   405.5 + * Back 2 Browser Bytecode Translator
   405.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   405.7 + *
   405.8 + * This program is free software: you can redistribute it and/or modify
   405.9 + * it under the terms of the GNU General Public License as published by
  405.10 + * the Free Software Foundation, version 2 of the License.
  405.11 + *
  405.12 + * This program is distributed in the hope that it will be useful,
  405.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  405.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  405.15 + * GNU General Public License for more details.
  405.16 + *
  405.17 + * You should have received a copy of the GNU General Public License
  405.18 + * along with this program. Look for COPYING file in the top folder.
  405.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  405.20 + */
  405.21 +package org.apidesign.bck2brwsr.compact.tck;
  405.22 +
  405.23 +import java.io.IOException;
  405.24 +import java.io.InputStream;
  405.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
  405.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  405.27 +import org.testng.annotations.Factory;
  405.28 +
  405.29 +/**
  405.30 + *
  405.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  405.32 + */
  405.33 +public class ZipCompatibilityTest {
  405.34 +    @Compare
  405.35 +    public String testDemoStaticCalculator() throws IOException {
  405.36 +        InputStream is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
  405.37 +        ZipArchive zip = ZipArchive.createZip(is);
  405.38 +        return zip.toString();
  405.39 +    }
  405.40 +    
  405.41 +    @Factory
  405.42 +    public static Object[] create() {
  405.43 +        return VMTest.create(ZipCompatibilityTest.class);
  405.44 +    }
  405.45 +}
   406.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   406.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ZipVsJzLibTest.java	Wed Feb 27 11:24:58 2013 +0100
   406.3 @@ -0,0 +1,39 @@
   406.4 +/**
   406.5 + * Back 2 Browser Bytecode Translator
   406.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   406.7 + *
   406.8 + * This program is free software: you can redistribute it and/or modify
   406.9 + * it under the terms of the GNU General Public License as published by
  406.10 + * the Free Software Foundation, version 2 of the License.
  406.11 + *
  406.12 + * This program is distributed in the hope that it will be useful,
  406.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  406.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  406.15 + * GNU General Public License for more details.
  406.16 + *
  406.17 + * You should have received a copy of the GNU General Public License
  406.18 + * along with this program. Look for COPYING file in the top folder.
  406.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  406.20 + */
  406.21 +package org.apidesign.bck2brwsr.compact.tck;
  406.22 +
  406.23 +import java.io.IOException;
  406.24 +import java.io.InputStream;
  406.25 +import org.testng.annotations.Test;
  406.26 +
  406.27 +/**
  406.28 + *
  406.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  406.30 + */
  406.31 +public class ZipVsJzLibTest {
  406.32 +    @Test public void r() throws IOException {
  406.33 +        InputStream is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
  406.34 +        ZipArchive zip = ZipArchive.createZip(is);
  406.35 +        
  406.36 +        is = getClass().getResourceAsStream("demo.static.calculator-0.3-SNAPSHOT.jar");
  406.37 +        ZipArchive real = ZipArchive.createReal(is);
  406.38 +        
  406.39 +        real.assertEquals(zip, "Are they the same?");
  406.40 +    }
  406.41 +    
  406.42 +}
   407.1 Binary file rt/emul/compact/src/test/resources/org/apidesign/bck2brwsr/compact/tck/demo.static.calculator-0.3-SNAPSHOT.jar has changed
   408.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   408.2 +++ b/rt/emul/mini/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   408.3 @@ -0,0 +1,48 @@
   408.4 +<?xml version="1.0"?>
   408.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"
   408.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   408.7 +  <modelVersion>4.0.0</modelVersion>
   408.8 +  <parent>
   408.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  408.10 +    <artifactId>emul.pom</artifactId>
  408.11 +    <version>0.3-SNAPSHOT</version>
  408.12 +  </parent>
  408.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  408.14 +  <artifactId>emul.mini</artifactId>
  408.15 +  <version>0.3-SNAPSHOT</version>
  408.16 +  <name>Minimal API Profile</name>
  408.17 +  <url>http://maven.apache.org</url>
  408.18 +  <properties>
  408.19 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  408.20 +  </properties>
  408.21 +  <dependencies>
  408.22 +    <dependency>
  408.23 +      <groupId>org.apidesign.bck2brwsr</groupId>
  408.24 +      <artifactId>core</artifactId>
  408.25 +      <version>0.3-SNAPSHOT</version>
  408.26 +      <type>jar</type>
  408.27 +    </dependency>
  408.28 +    <dependency>
  408.29 +      <groupId>org.testng</groupId>
  408.30 +      <artifactId>testng</artifactId>
  408.31 +      <version>6.5.2</version>
  408.32 +      <scope>test</scope>
  408.33 +    </dependency>
  408.34 +  </dependencies>
  408.35 +  <build>
  408.36 +      <plugins>
  408.37 +          <plugin>
  408.38 +              <groupId>org.apache.maven.plugins</groupId>
  408.39 +              <artifactId>maven-compiler-plugin</artifactId>
  408.40 +              <version>2.5.1</version>
  408.41 +              <configuration>
  408.42 +                  <compilerArguments>
  408.43 +                      <bootclasspath>netbeans.ignore.jdk.bootsclasspath</bootclasspath>
  408.44 +                  </compilerArguments>
  408.45 +                 <source>1.7</source>
  408.46 +                 <target>1.7</target>
  408.47 +              </configuration>
  408.48 +          </plugin>
  408.49 +      </plugins>
  408.50 +  </build>
  408.51 +</project>
   409.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   409.2 +++ b/rt/emul/mini/src/main/java/java/io/ByteArrayInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   409.3 @@ -0,0 +1,285 @@
   409.4 +/*
   409.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   409.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   409.7 + *
   409.8 + * This code is free software; you can redistribute it and/or modify it
   409.9 + * under the terms of the GNU General Public License version 2 only, as
  409.10 + * published by the Free Software Foundation.  Oracle designates this
  409.11 + * particular file as subject to the "Classpath" exception as provided
  409.12 + * by Oracle in the LICENSE file that accompanied this code.
  409.13 + *
  409.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  409.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  409.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  409.17 + * version 2 for more details (a copy is included in the LICENSE file that
  409.18 + * accompanied this code).
  409.19 + *
  409.20 + * You should have received a copy of the GNU General Public License version
  409.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  409.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  409.23 + *
  409.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  409.25 + * or visit www.oracle.com if you need additional information or have any
  409.26 + * questions.
  409.27 + */
  409.28 +
  409.29 +package java.io;
  409.30 +
  409.31 +import org.apidesign.bck2brwsr.emul.lang.System;
  409.32 +
  409.33 +/**
  409.34 + * A <code>ByteArrayInputStream</code> contains
  409.35 + * an internal buffer that contains bytes that
  409.36 + * may be read from the stream. An internal
  409.37 + * counter keeps track of the next byte to
  409.38 + * be supplied by the <code>read</code> method.
  409.39 + * <p>
  409.40 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
  409.41 + * this class can be called after the stream has been closed without
  409.42 + * generating an <tt>IOException</tt>.
  409.43 + *
  409.44 + * @author  Arthur van Hoff
  409.45 + * @see     java.io.StringBufferInputStream
  409.46 + * @since   JDK1.0
  409.47 + */
  409.48 +public
  409.49 +class ByteArrayInputStream extends InputStream {
  409.50 +
  409.51 +    /**
  409.52 +     * An array of bytes that was provided
  409.53 +     * by the creator of the stream. Elements <code>buf[0]</code>
  409.54 +     * through <code>buf[count-1]</code> are the
  409.55 +     * only bytes that can ever be read from the
  409.56 +     * stream;  element <code>buf[pos]</code> is
  409.57 +     * the next byte to be read.
  409.58 +     */
  409.59 +    protected byte buf[];
  409.60 +
  409.61 +    /**
  409.62 +     * The index of the next character to read from the input stream buffer.
  409.63 +     * This value should always be nonnegative
  409.64 +     * and not larger than the value of <code>count</code>.
  409.65 +     * The next byte to be read from the input stream buffer
  409.66 +     * will be <code>buf[pos]</code>.
  409.67 +     */
  409.68 +    protected int pos;
  409.69 +
  409.70 +    /**
  409.71 +     * The currently marked position in the stream.
  409.72 +     * ByteArrayInputStream objects are marked at position zero by
  409.73 +     * default when constructed.  They may be marked at another
  409.74 +     * position within the buffer by the <code>mark()</code> method.
  409.75 +     * The current buffer position is set to this point by the
  409.76 +     * <code>reset()</code> method.
  409.77 +     * <p>
  409.78 +     * If no mark has been set, then the value of mark is the offset
  409.79 +     * passed to the constructor (or 0 if the offset was not supplied).
  409.80 +     *
  409.81 +     * @since   JDK1.1
  409.82 +     */
  409.83 +    protected int mark = 0;
  409.84 +
  409.85 +    /**
  409.86 +     * The index one greater than the last valid character in the input
  409.87 +     * stream buffer.
  409.88 +     * This value should always be nonnegative
  409.89 +     * and not larger than the length of <code>buf</code>.
  409.90 +     * It  is one greater than the position of
  409.91 +     * the last byte within <code>buf</code> that
  409.92 +     * can ever be read  from the input stream buffer.
  409.93 +     */
  409.94 +    protected int count;
  409.95 +
  409.96 +    /**
  409.97 +     * Creates a <code>ByteArrayInputStream</code>
  409.98 +     * so that it  uses <code>buf</code> as its
  409.99 +     * buffer array.
 409.100 +     * The buffer array is not copied.
 409.101 +     * The initial value of <code>pos</code>
 409.102 +     * is <code>0</code> and the initial value
 409.103 +     * of  <code>count</code> is the length of
 409.104 +     * <code>buf</code>.
 409.105 +     *
 409.106 +     * @param   buf   the input buffer.
 409.107 +     */
 409.108 +    public ByteArrayInputStream(byte buf[]) {
 409.109 +        this.buf = buf;
 409.110 +        this.pos = 0;
 409.111 +        this.count = buf.length;
 409.112 +    }
 409.113 +
 409.114 +    /**
 409.115 +     * Creates <code>ByteArrayInputStream</code>
 409.116 +     * that uses <code>buf</code> as its
 409.117 +     * buffer array. The initial value of <code>pos</code>
 409.118 +     * is <code>offset</code> and the initial value
 409.119 +     * of <code>count</code> is the minimum of <code>offset+length</code>
 409.120 +     * and <code>buf.length</code>.
 409.121 +     * The buffer array is not copied. The buffer's mark is
 409.122 +     * set to the specified offset.
 409.123 +     *
 409.124 +     * @param   buf      the input buffer.
 409.125 +     * @param   offset   the offset in the buffer of the first byte to read.
 409.126 +     * @param   length   the maximum number of bytes to read from the buffer.
 409.127 +     */
 409.128 +    public ByteArrayInputStream(byte buf[], int offset, int length) {
 409.129 +        this.buf = buf;
 409.130 +        this.pos = offset;
 409.131 +        this.count = Math.min(offset + length, buf.length);
 409.132 +        this.mark = offset;
 409.133 +    }
 409.134 +
 409.135 +    /**
 409.136 +     * Reads the next byte of data from this input stream. The value
 409.137 +     * byte is returned as an <code>int</code> in the range
 409.138 +     * <code>0</code> to <code>255</code>. If no byte is available
 409.139 +     * because the end of the stream has been reached, the value
 409.140 +     * <code>-1</code> is returned.
 409.141 +     * <p>
 409.142 +     * This <code>read</code> method
 409.143 +     * cannot block.
 409.144 +     *
 409.145 +     * @return  the next byte of data, or <code>-1</code> if the end of the
 409.146 +     *          stream has been reached.
 409.147 +     */
 409.148 +    public synchronized int read() {
 409.149 +        return (pos < count) ? (buf[pos++] & 0xff) : -1;
 409.150 +    }
 409.151 +
 409.152 +    /**
 409.153 +     * Reads up to <code>len</code> bytes of data into an array of bytes
 409.154 +     * from this input stream.
 409.155 +     * If <code>pos</code> equals <code>count</code>,
 409.156 +     * then <code>-1</code> is returned to indicate
 409.157 +     * end of file. Otherwise, the  number <code>k</code>
 409.158 +     * of bytes read is equal to the smaller of
 409.159 +     * <code>len</code> and <code>count-pos</code>.
 409.160 +     * If <code>k</code> is positive, then bytes
 409.161 +     * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
 409.162 +     * are copied into <code>b[off]</code>  through
 409.163 +     * <code>b[off+k-1]</code> in the manner performed
 409.164 +     * by <code>System.arraycopy</code>. The
 409.165 +     * value <code>k</code> is added into <code>pos</code>
 409.166 +     * and <code>k</code> is returned.
 409.167 +     * <p>
 409.168 +     * This <code>read</code> method cannot block.
 409.169 +     *
 409.170 +     * @param   b     the buffer into which the data is read.
 409.171 +     * @param   off   the start offset in the destination array <code>b</code>
 409.172 +     * @param   len   the maximum number of bytes read.
 409.173 +     * @return  the total number of bytes read into the buffer, or
 409.174 +     *          <code>-1</code> if there is no more data because the end of
 409.175 +     *          the stream has been reached.
 409.176 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 409.177 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 409.178 +     * <code>len</code> is negative, or <code>len</code> is greater than
 409.179 +     * <code>b.length - off</code>
 409.180 +     */
 409.181 +    public synchronized int read(byte b[], int off, int len) {
 409.182 +        if (b == null) {
 409.183 +            throw new NullPointerException();
 409.184 +        } else if (off < 0 || len < 0 || len > b.length - off) {
 409.185 +            throw new IndexOutOfBoundsException();
 409.186 +        }
 409.187 +
 409.188 +        if (pos >= count) {
 409.189 +            return -1;
 409.190 +        }
 409.191 +
 409.192 +        int avail = count - pos;
 409.193 +        if (len > avail) {
 409.194 +            len = avail;
 409.195 +        }
 409.196 +        if (len <= 0) {
 409.197 +            return 0;
 409.198 +        }
 409.199 +        System.arraycopy(buf, pos, b, off, len);
 409.200 +        pos += len;
 409.201 +        return len;
 409.202 +    }
 409.203 +
 409.204 +    /**
 409.205 +     * Skips <code>n</code> bytes of input from this input stream. Fewer
 409.206 +     * bytes might be skipped if the end of the input stream is reached.
 409.207 +     * The actual number <code>k</code>
 409.208 +     * of bytes to be skipped is equal to the smaller
 409.209 +     * of <code>n</code> and  <code>count-pos</code>.
 409.210 +     * The value <code>k</code> is added into <code>pos</code>
 409.211 +     * and <code>k</code> is returned.
 409.212 +     *
 409.213 +     * @param   n   the number of bytes to be skipped.
 409.214 +     * @return  the actual number of bytes skipped.
 409.215 +     */
 409.216 +    public synchronized long skip(long n) {
 409.217 +        long k = count - pos;
 409.218 +        if (n < k) {
 409.219 +            k = n < 0 ? 0 : n;
 409.220 +        }
 409.221 +
 409.222 +        pos += k;
 409.223 +        return k;
 409.224 +    }
 409.225 +
 409.226 +    /**
 409.227 +     * Returns the number of remaining bytes that can be read (or skipped over)
 409.228 +     * from this input stream.
 409.229 +     * <p>
 409.230 +     * The value returned is <code>count&nbsp;- pos</code>,
 409.231 +     * which is the number of bytes remaining to be read from the input buffer.
 409.232 +     *
 409.233 +     * @return  the number of remaining bytes that can be read (or skipped
 409.234 +     *          over) from this input stream without blocking.
 409.235 +     */
 409.236 +    public synchronized int available() {
 409.237 +        return count - pos;
 409.238 +    }
 409.239 +
 409.240 +    /**
 409.241 +     * Tests if this <code>InputStream</code> supports mark/reset. The
 409.242 +     * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
 409.243 +     * always returns <code>true</code>.
 409.244 +     *
 409.245 +     * @since   JDK1.1
 409.246 +     */
 409.247 +    public boolean markSupported() {
 409.248 +        return true;
 409.249 +    }
 409.250 +
 409.251 +    /**
 409.252 +     * Set the current marked position in the stream.
 409.253 +     * ByteArrayInputStream objects are marked at position zero by
 409.254 +     * default when constructed.  They may be marked at another
 409.255 +     * position within the buffer by this method.
 409.256 +     * <p>
 409.257 +     * If no mark has been set, then the value of the mark is the
 409.258 +     * offset passed to the constructor (or 0 if the offset was not
 409.259 +     * supplied).
 409.260 +     *
 409.261 +     * <p> Note: The <code>readAheadLimit</code> for this class
 409.262 +     *  has no meaning.
 409.263 +     *
 409.264 +     * @since   JDK1.1
 409.265 +     */
 409.266 +    public void mark(int readAheadLimit) {
 409.267 +        mark = pos;
 409.268 +    }
 409.269 +
 409.270 +    /**
 409.271 +     * Resets the buffer to the marked position.  The marked position
 409.272 +     * is 0 unless another position was marked or an offset was specified
 409.273 +     * in the constructor.
 409.274 +     */
 409.275 +    public synchronized void reset() {
 409.276 +        pos = mark;
 409.277 +    }
 409.278 +
 409.279 +    /**
 409.280 +     * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
 409.281 +     * this class can be called after the stream has been closed without
 409.282 +     * generating an <tt>IOException</tt>.
 409.283 +     * <p>
 409.284 +     */
 409.285 +    public void close() throws IOException {
 409.286 +    }
 409.287 +
 409.288 +}
   410.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   410.2 +++ b/rt/emul/mini/src/main/java/java/io/Closeable.java	Wed Feb 27 11:24:58 2013 +0100
   410.3 @@ -0,0 +1,48 @@
   410.4 +/*
   410.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   410.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   410.7 + *
   410.8 + * This code is free software; you can redistribute it and/or modify it
   410.9 + * under the terms of the GNU General Public License version 2 only, as
  410.10 + * published by the Free Software Foundation.  Oracle designates this
  410.11 + * particular file as subject to the "Classpath" exception as provided
  410.12 + * by Oracle in the LICENSE file that accompanied this code.
  410.13 + *
  410.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  410.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  410.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  410.17 + * version 2 for more details (a copy is included in the LICENSE file that
  410.18 + * accompanied this code).
  410.19 + *
  410.20 + * You should have received a copy of the GNU General Public License version
  410.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  410.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  410.23 + *
  410.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  410.25 + * or visit www.oracle.com if you need additional information or have any
  410.26 + * questions.
  410.27 + */
  410.28 +
  410.29 +package java.io;
  410.30 +
  410.31 +import java.io.IOException;
  410.32 +
  410.33 +/**
  410.34 + * A {@code Closeable} is a source or destination of data that can be closed.
  410.35 + * The close method is invoked to release resources that the object is
  410.36 + * holding (such as open files).
  410.37 + *
  410.38 + * @since 1.5
  410.39 + */
  410.40 +
  410.41 +public interface Closeable extends AutoCloseable {
  410.42 +
  410.43 +    /**
  410.44 +     * Closes this stream and releases any system resources associated
  410.45 +     * with it. If the stream is already closed then invoking this
  410.46 +     * method has no effect.
  410.47 +     *
  410.48 +     * @throws IOException if an I/O error occurs
  410.49 +     */
  410.50 +    public void close() throws IOException;
  410.51 +}
   411.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   411.2 +++ b/rt/emul/mini/src/main/java/java/io/DataInput.java	Wed Feb 27 11:24:58 2013 +0100
   411.3 @@ -0,0 +1,635 @@
   411.4 +/*
   411.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
   411.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   411.7 + *
   411.8 + * This code is free software; you can redistribute it and/or modify it
   411.9 + * under the terms of the GNU General Public License version 2 only, as
  411.10 + * published by the Free Software Foundation.  Oracle designates this
  411.11 + * particular file as subject to the "Classpath" exception as provided
  411.12 + * by Oracle in the LICENSE file that accompanied this code.
  411.13 + *
  411.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  411.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  411.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  411.17 + * version 2 for more details (a copy is included in the LICENSE file that
  411.18 + * accompanied this code).
  411.19 + *
  411.20 + * You should have received a copy of the GNU General Public License version
  411.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  411.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  411.23 + *
  411.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  411.25 + * or visit www.oracle.com if you need additional information or have any
  411.26 + * questions.
  411.27 + */
  411.28 +
  411.29 +package java.io;
  411.30 +
  411.31 +/**
  411.32 + * The <code>DataInput</code> interface provides
  411.33 + * for reading bytes from a binary stream and
  411.34 + * reconstructing from them data in any of
  411.35 + * the Java primitive types. There is also
  411.36 + * a
  411.37 + * facility for reconstructing a <code>String</code>
  411.38 + * from data in
  411.39 + * <a href="#modified-utf-8">modified UTF-8</a>
  411.40 + * format.
  411.41 + * <p>
  411.42 + * It is generally true of all the reading
  411.43 + * routines in this interface that if end of
  411.44 + * file is reached before the desired number
  411.45 + * of bytes has been read, an <code>EOFException</code>
  411.46 + * (which is a kind of <code>IOException</code>)
  411.47 + * is thrown. If any byte cannot be read for
  411.48 + * any reason other than end of file, an <code>IOException</code>
  411.49 + * other than <code>EOFException</code> is
  411.50 + * thrown. In particular, an <code>IOException</code>
  411.51 + * may be thrown if the input stream has been
  411.52 + * closed.
  411.53 + *
  411.54 + * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
  411.55 + * <p>
  411.56 + * Implementations of the DataInput and DataOutput interfaces represent
  411.57 + * Unicode strings in a format that is a slight modification of UTF-8.
  411.58 + * (For information regarding the standard UTF-8 format, see section
  411.59 + * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
  411.60 + * 4.0</i>).
  411.61 + * Note that in the following tables, the most significant bit appears in the
  411.62 + * far left-hand column.
  411.63 + * <p>
  411.64 + * All characters in the range <code>'&#92;u0001'</code> to
  411.65 + * <code>'&#92;u007F'</code> are represented by a single byte:
  411.66 + *
  411.67 + * <blockquote>
  411.68 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  411.69 + *          summary="Bit values and bytes">
  411.70 + *     <tr>
  411.71 + *       <td></td>
  411.72 + *       <th id="bit">Bit Values</th>
  411.73 + *     </tr>
  411.74 + *     <tr>
  411.75 + *       <th id="byte1">Byte 1</th>
  411.76 + *       <td>
  411.77 + *         <table border="1" cellspacing="0" width="100%">
  411.78 + *           <tr>
  411.79 + *             <td width="12%"><center>0</center>
  411.80 + *             <td colspan="7"><center>bits 6-0</center>
  411.81 + *           </tr>
  411.82 + *         </table>
  411.83 + *       </td>
  411.84 + *     </tr>
  411.85 + *   </table>
  411.86 + * </blockquote>
  411.87 + *
  411.88 + * <p>
  411.89 + * The null character <code>'&#92;u0000'</code> and characters in the
  411.90 + * range <code>'&#92;u0080'</code> to <code>'&#92;u07FF'</code> are
  411.91 + * represented by a pair of bytes:
  411.92 + *
  411.93 + * <blockquote>
  411.94 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
  411.95 + *          summary="Bit values and bytes">
  411.96 + *     <tr>
  411.97 + *       <td></td>
  411.98 + *       <th id="bit">Bit Values</th>
  411.99 + *     </tr>
 411.100 + *     <tr>
 411.101 + *       <th id="byte1">Byte 1</th>
 411.102 + *       <td>
 411.103 + *         <table border="1" cellspacing="0" width="100%">
 411.104 + *           <tr>
 411.105 + *             <td width="12%"><center>1</center>
 411.106 + *             <td width="13%"><center>1</center>
 411.107 + *             <td width="12%"><center>0</center>
 411.108 + *             <td colspan="5"><center>bits 10-6</center>
 411.109 + *           </tr>
 411.110 + *         </table>
 411.111 + *       </td>
 411.112 + *     </tr>
 411.113 + *     <tr>
 411.114 + *       <th id="byte2">Byte 2</th>
 411.115 + *       <td>
 411.116 + *         <table border="1" cellspacing="0" width="100%">
 411.117 + *           <tr>
 411.118 + *             <td width="12%"><center>1</center>
 411.119 + *             <td width="13%"><center>0</center>
 411.120 + *             <td colspan="6"><center>bits 5-0</center>
 411.121 + *           </tr>
 411.122 + *         </table>
 411.123 + *       </td>
 411.124 + *     </tr>
 411.125 + *   </table>
 411.126 + *  </blockquote>
 411.127 + *
 411.128 + * <br>
 411.129 + * <code>char</code> values in the range <code>'&#92;u0800'</code> to
 411.130 + * <code>'&#92;uFFFF'</code> are represented by three bytes:
 411.131 + *
 411.132 + * <blockquote>
 411.133 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
 411.134 + *          summary="Bit values and bytes">
 411.135 + *     <tr>
 411.136 + *       <td></td>
 411.137 + *       <th id="bit">Bit Values</th>
 411.138 + *     </tr>
 411.139 + *     <tr>
 411.140 + *       <th id="byte1">Byte 1</th>
 411.141 + *       <td>
 411.142 + *         <table border="1" cellspacing="0" width="100%">
 411.143 + *           <tr>
 411.144 + *             <td width="12%"><center>1</center>
 411.145 + *             <td width="13%"><center>1</center>
 411.146 + *             <td width="12%"><center>1</center>
 411.147 + *             <td width="13%"><center>0</center>
 411.148 + *             <td colspan="4"><center>bits 15-12</center>
 411.149 + *           </tr>
 411.150 + *         </table>
 411.151 + *       </td>
 411.152 + *     </tr>
 411.153 + *     <tr>
 411.154 + *       <th id="byte2">Byte 2</th>
 411.155 + *       <td>
 411.156 + *         <table border="1" cellspacing="0" width="100%">
 411.157 + *           <tr>
 411.158 + *             <td width="12%"><center>1</center>
 411.159 + *             <td width="13%"><center>0</center>
 411.160 + *             <td colspan="6"><center>bits 11-6</center>
 411.161 + *           </tr>
 411.162 + *         </table>
 411.163 + *       </td>
 411.164 + *     </tr>
 411.165 + *     <tr>
 411.166 + *       <th id="byte3">Byte 3</th>
 411.167 + *       <td>
 411.168 + *         <table border="1" cellspacing="0" width="100%">
 411.169 + *           <tr>
 411.170 + *             <td width="12%"><center>1</center>
 411.171 + *             <td width="13%"><center>0</center>
 411.172 + *             <td colspan="6"><center>bits 5-0</center>
 411.173 + *           </tr>
 411.174 + *         </table>
 411.175 + *       </td>
 411.176 + *     </tr>
 411.177 + *   </table>
 411.178 + *  </blockquote>
 411.179 + *
 411.180 + * <p>
 411.181 + * The differences between this format and the
 411.182 + * standard UTF-8 format are the following:
 411.183 + * <ul>
 411.184 + * <li>The null byte <code>'&#92;u0000'</code> is encoded in 2-byte format
 411.185 + *     rather than 1-byte, so that the encoded strings never have
 411.186 + *     embedded nulls.
 411.187 + * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
 411.188 + * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
 411.189 + *     are represented in the form of surrogate pairs.
 411.190 + * </ul>
 411.191 + * @author  Frank Yellin
 411.192 + * @see     java.io.DataInputStream
 411.193 + * @see     java.io.DataOutput
 411.194 + * @since   JDK1.0
 411.195 + */
 411.196 +public
 411.197 +interface DataInput {
 411.198 +    /**
 411.199 +     * Reads some bytes from an input
 411.200 +     * stream and stores them into the buffer
 411.201 +     * array <code>b</code>. The number of bytes
 411.202 +     * read is equal
 411.203 +     * to the length of <code>b</code>.
 411.204 +     * <p>
 411.205 +     * This method blocks until one of the
 411.206 +     * following conditions occurs:<p>
 411.207 +     * <ul>
 411.208 +     * <li><code>b.length</code>
 411.209 +     * bytes of input data are available, in which
 411.210 +     * case a normal return is made.
 411.211 +     *
 411.212 +     * <li>End of
 411.213 +     * file is detected, in which case an <code>EOFException</code>
 411.214 +     * is thrown.
 411.215 +     *
 411.216 +     * <li>An I/O error occurs, in
 411.217 +     * which case an <code>IOException</code> other
 411.218 +     * than <code>EOFException</code> is thrown.
 411.219 +     * </ul>
 411.220 +     * <p>
 411.221 +     * If <code>b</code> is <code>null</code>,
 411.222 +     * a <code>NullPointerException</code> is thrown.
 411.223 +     * If <code>b.length</code> is zero, then
 411.224 +     * no bytes are read. Otherwise, the first
 411.225 +     * byte read is stored into element <code>b[0]</code>,
 411.226 +     * the next one into <code>b[1]</code>, and
 411.227 +     * so on.
 411.228 +     * If an exception is thrown from
 411.229 +     * this method, then it may be that some but
 411.230 +     * not all bytes of <code>b</code> have been
 411.231 +     * updated with data from the input stream.
 411.232 +     *
 411.233 +     * @param     b   the buffer into which the data is read.
 411.234 +     * @exception  EOFException  if this stream reaches the end before reading
 411.235 +     *               all the bytes.
 411.236 +     * @exception  IOException   if an I/O error occurs.
 411.237 +     */
 411.238 +    void readFully(byte b[]) throws IOException;
 411.239 +
 411.240 +    /**
 411.241 +     *
 411.242 +     * Reads <code>len</code>
 411.243 +     * bytes from
 411.244 +     * an input stream.
 411.245 +     * <p>
 411.246 +     * This method
 411.247 +     * blocks until one of the following conditions
 411.248 +     * occurs:<p>
 411.249 +     * <ul>
 411.250 +     * <li><code>len</code> bytes
 411.251 +     * of input data are available, in which case
 411.252 +     * a normal return is made.
 411.253 +     *
 411.254 +     * <li>End of file
 411.255 +     * is detected, in which case an <code>EOFException</code>
 411.256 +     * is thrown.
 411.257 +     *
 411.258 +     * <li>An I/O error occurs, in
 411.259 +     * which case an <code>IOException</code> other
 411.260 +     * than <code>EOFException</code> is thrown.
 411.261 +     * </ul>
 411.262 +     * <p>
 411.263 +     * If <code>b</code> is <code>null</code>,
 411.264 +     * a <code>NullPointerException</code> is thrown.
 411.265 +     * If <code>off</code> is negative, or <code>len</code>
 411.266 +     * is negative, or <code>off+len</code> is
 411.267 +     * greater than the length of the array <code>b</code>,
 411.268 +     * then an <code>IndexOutOfBoundsException</code>
 411.269 +     * is thrown.
 411.270 +     * If <code>len</code> is zero,
 411.271 +     * then no bytes are read. Otherwise, the first
 411.272 +     * byte read is stored into element <code>b[off]</code>,
 411.273 +     * the next one into <code>b[off+1]</code>,
 411.274 +     * and so on. The number of bytes read is,
 411.275 +     * at most, equal to <code>len</code>.
 411.276 +     *
 411.277 +     * @param     b   the buffer into which the data is read.
 411.278 +     * @param off  an int specifying the offset into the data.
 411.279 +     * @param len  an int specifying the number of bytes to read.
 411.280 +     * @exception  EOFException  if this stream reaches the end before reading
 411.281 +     *               all the bytes.
 411.282 +     * @exception  IOException   if an I/O error occurs.
 411.283 +     */
 411.284 +    void readFully(byte b[], int off, int len) throws IOException;
 411.285 +
 411.286 +    /**
 411.287 +     * Makes an attempt to skip over
 411.288 +     * <code>n</code> bytes
 411.289 +     * of data from the input
 411.290 +     * stream, discarding the skipped bytes. However,
 411.291 +     * it may skip
 411.292 +     * over some smaller number of
 411.293 +     * bytes, possibly zero. This may result from
 411.294 +     * any of a
 411.295 +     * number of conditions; reaching
 411.296 +     * end of file before <code>n</code> bytes
 411.297 +     * have been skipped is
 411.298 +     * only one possibility.
 411.299 +     * This method never throws an <code>EOFException</code>.
 411.300 +     * The actual
 411.301 +     * number of bytes skipped is returned.
 411.302 +     *
 411.303 +     * @param      n   the number of bytes to be skipped.
 411.304 +     * @return     the number of bytes actually skipped.
 411.305 +     * @exception  IOException   if an I/O error occurs.
 411.306 +     */
 411.307 +    int skipBytes(int n) throws IOException;
 411.308 +
 411.309 +    /**
 411.310 +     * Reads one input byte and returns
 411.311 +     * <code>true</code> if that byte is nonzero,
 411.312 +     * <code>false</code> if that byte is zero.
 411.313 +     * This method is suitable for reading
 411.314 +     * the byte written by the <code>writeBoolean</code>
 411.315 +     * method of interface <code>DataOutput</code>.
 411.316 +     *
 411.317 +     * @return     the <code>boolean</code> value read.
 411.318 +     * @exception  EOFException  if this stream reaches the end before reading
 411.319 +     *               all the bytes.
 411.320 +     * @exception  IOException   if an I/O error occurs.
 411.321 +     */
 411.322 +    boolean readBoolean() throws IOException;
 411.323 +
 411.324 +    /**
 411.325 +     * Reads and returns one input byte.
 411.326 +     * The byte is treated as a signed value in
 411.327 +     * the range <code>-128</code> through <code>127</code>,
 411.328 +     * inclusive.
 411.329 +     * This method is suitable for
 411.330 +     * reading the byte written by the <code>writeByte</code>
 411.331 +     * method of interface <code>DataOutput</code>.
 411.332 +     *
 411.333 +     * @return     the 8-bit value read.
 411.334 +     * @exception  EOFException  if this stream reaches the end before reading
 411.335 +     *               all the bytes.
 411.336 +     * @exception  IOException   if an I/O error occurs.
 411.337 +     */
 411.338 +    byte readByte() throws IOException;
 411.339 +
 411.340 +    /**
 411.341 +     * Reads one input byte, zero-extends
 411.342 +     * it to type <code>int</code>, and returns
 411.343 +     * the result, which is therefore in the range
 411.344 +     * <code>0</code>
 411.345 +     * through <code>255</code>.
 411.346 +     * This method is suitable for reading
 411.347 +     * the byte written by the <code>writeByte</code>
 411.348 +     * method of interface <code>DataOutput</code>
 411.349 +     * if the argument to <code>writeByte</code>
 411.350 +     * was intended to be a value in the range
 411.351 +     * <code>0</code> through <code>255</code>.
 411.352 +     *
 411.353 +     * @return     the unsigned 8-bit value read.
 411.354 +     * @exception  EOFException  if this stream reaches the end before reading
 411.355 +     *               all the bytes.
 411.356 +     * @exception  IOException   if an I/O error occurs.
 411.357 +     */
 411.358 +    int readUnsignedByte() throws IOException;
 411.359 +
 411.360 +    /**
 411.361 +     * Reads two input bytes and returns
 411.362 +     * a <code>short</code> value. Let <code>a</code>
 411.363 +     * be the first byte read and <code>b</code>
 411.364 +     * be the second byte. The value
 411.365 +     * returned
 411.366 +     * is:
 411.367 +     * <p><pre><code>(short)((a &lt;&lt; 8) | (b &amp; 0xff))
 411.368 +     * </code></pre>
 411.369 +     * This method
 411.370 +     * is suitable for reading the bytes written
 411.371 +     * by the <code>writeShort</code> method of
 411.372 +     * interface <code>DataOutput</code>.
 411.373 +     *
 411.374 +     * @return     the 16-bit value read.
 411.375 +     * @exception  EOFException  if this stream reaches the end before reading
 411.376 +     *               all the bytes.
 411.377 +     * @exception  IOException   if an I/O error occurs.
 411.378 +     */
 411.379 +    short readShort() throws IOException;
 411.380 +
 411.381 +    /**
 411.382 +     * Reads two input bytes and returns
 411.383 +     * an <code>int</code> value in the range <code>0</code>
 411.384 +     * through <code>65535</code>. Let <code>a</code>
 411.385 +     * be the first byte read and
 411.386 +     * <code>b</code>
 411.387 +     * be the second byte. The value returned is:
 411.388 +     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
 411.389 +     * </code></pre>
 411.390 +     * This method is suitable for reading the bytes
 411.391 +     * written by the <code>writeShort</code> method
 411.392 +     * of interface <code>DataOutput</code>  if
 411.393 +     * the argument to <code>writeShort</code>
 411.394 +     * was intended to be a value in the range
 411.395 +     * <code>0</code> through <code>65535</code>.
 411.396 +     *
 411.397 +     * @return     the unsigned 16-bit value read.
 411.398 +     * @exception  EOFException  if this stream reaches the end before reading
 411.399 +     *               all the bytes.
 411.400 +     * @exception  IOException   if an I/O error occurs.
 411.401 +     */
 411.402 +    int readUnsignedShort() throws IOException;
 411.403 +
 411.404 +    /**
 411.405 +     * Reads two input bytes and returns a <code>char</code> value.
 411.406 +     * Let <code>a</code>
 411.407 +     * be the first byte read and <code>b</code>
 411.408 +     * be the second byte. The value
 411.409 +     * returned is:
 411.410 +     * <p><pre><code>(char)((a &lt;&lt; 8) | (b &amp; 0xff))
 411.411 +     * </code></pre>
 411.412 +     * This method
 411.413 +     * is suitable for reading bytes written by
 411.414 +     * the <code>writeChar</code> method of interface
 411.415 +     * <code>DataOutput</code>.
 411.416 +     *
 411.417 +     * @return     the <code>char</code> value read.
 411.418 +     * @exception  EOFException  if this stream reaches the end before reading
 411.419 +     *               all the bytes.
 411.420 +     * @exception  IOException   if an I/O error occurs.
 411.421 +     */
 411.422 +    char readChar() throws IOException;
 411.423 +
 411.424 +    /**
 411.425 +     * Reads four input bytes and returns an
 411.426 +     * <code>int</code> value. Let <code>a-d</code>
 411.427 +     * be the first through fourth bytes read. The value returned is:
 411.428 +     * <p><pre>
 411.429 +     * <code>
 411.430 +     * (((a &amp; 0xff) &lt;&lt; 24) | ((b &amp; 0xff) &lt;&lt; 16) |
 411.431 +     * &#32;((c &amp; 0xff) &lt;&lt; 8) | (d &amp; 0xff))
 411.432 +     * </code></pre>
 411.433 +     * This method is suitable
 411.434 +     * for reading bytes written by the <code>writeInt</code>
 411.435 +     * method of interface <code>DataOutput</code>.
 411.436 +     *
 411.437 +     * @return     the <code>int</code> value read.
 411.438 +     * @exception  EOFException  if this stream reaches the end before reading
 411.439 +     *               all the bytes.
 411.440 +     * @exception  IOException   if an I/O error occurs.
 411.441 +     */
 411.442 +    int readInt() throws IOException;
 411.443 +
 411.444 +    /**
 411.445 +     * Reads eight input bytes and returns
 411.446 +     * a <code>long</code> value. Let <code>a-h</code>
 411.447 +     * be the first through eighth bytes read.
 411.448 +     * The value returned is:
 411.449 +     * <p><pre> <code>
 411.450 +     * (((long)(a &amp; 0xff) &lt;&lt; 56) |
 411.451 +     *  ((long)(b &amp; 0xff) &lt;&lt; 48) |
 411.452 +     *  ((long)(c &amp; 0xff) &lt;&lt; 40) |
 411.453 +     *  ((long)(d &amp; 0xff) &lt;&lt; 32) |
 411.454 +     *  ((long)(e &amp; 0xff) &lt;&lt; 24) |
 411.455 +     *  ((long)(f &amp; 0xff) &lt;&lt; 16) |
 411.456 +     *  ((long)(g &amp; 0xff) &lt;&lt;  8) |
 411.457 +     *  ((long)(h &amp; 0xff)))
 411.458 +     * </code></pre>
 411.459 +     * <p>
 411.460 +     * This method is suitable
 411.461 +     * for reading bytes written by the <code>writeLong</code>
 411.462 +     * method of interface <code>DataOutput</code>.
 411.463 +     *
 411.464 +     * @return     the <code>long</code> value read.
 411.465 +     * @exception  EOFException  if this stream reaches the end before reading
 411.466 +     *               all the bytes.
 411.467 +     * @exception  IOException   if an I/O error occurs.
 411.468 +     */
 411.469 +    long readLong() throws IOException;
 411.470 +
 411.471 +    /**
 411.472 +     * Reads four input bytes and returns
 411.473 +     * a <code>float</code> value. It does this
 411.474 +     * by first constructing an <code>int</code>
 411.475 +     * value in exactly the manner
 411.476 +     * of the <code>readInt</code>
 411.477 +     * method, then converting this <code>int</code>
 411.478 +     * value to a <code>float</code> in
 411.479 +     * exactly the manner of the method <code>Float.intBitsToFloat</code>.
 411.480 +     * This method is suitable for reading
 411.481 +     * bytes written by the <code>writeFloat</code>
 411.482 +     * method of interface <code>DataOutput</code>.
 411.483 +     *
 411.484 +     * @return     the <code>float</code> value read.
 411.485 +     * @exception  EOFException  if this stream reaches the end before reading
 411.486 +     *               all the bytes.
 411.487 +     * @exception  IOException   if an I/O error occurs.
 411.488 +     */
 411.489 +    float readFloat() throws IOException;
 411.490 +
 411.491 +    /**
 411.492 +     * Reads eight input bytes and returns
 411.493 +     * a <code>double</code> value. It does this
 411.494 +     * by first constructing a <code>long</code>
 411.495 +     * value in exactly the manner
 411.496 +     * of the <code>readlong</code>
 411.497 +     * method, then converting this <code>long</code>
 411.498 +     * value to a <code>double</code> in exactly
 411.499 +     * the manner of the method <code>Double.longBitsToDouble</code>.
 411.500 +     * This method is suitable for reading
 411.501 +     * bytes written by the <code>writeDouble</code>
 411.502 +     * method of interface <code>DataOutput</code>.
 411.503 +     *
 411.504 +     * @return     the <code>double</code> value read.
 411.505 +     * @exception  EOFException  if this stream reaches the end before reading
 411.506 +     *               all the bytes.
 411.507 +     * @exception  IOException   if an I/O error occurs.
 411.508 +     */
 411.509 +    double readDouble() throws IOException;
 411.510 +
 411.511 +    /**
 411.512 +     * Reads the next line of text from the input stream.
 411.513 +     * It reads successive bytes, converting
 411.514 +     * each byte separately into a character,
 411.515 +     * until it encounters a line terminator or
 411.516 +     * end of
 411.517 +     * file; the characters read are then
 411.518 +     * returned as a <code>String</code>. Note
 411.519 +     * that because this
 411.520 +     * method processes bytes,
 411.521 +     * it does not support input of the full Unicode
 411.522 +     * character set.
 411.523 +     * <p>
 411.524 +     * If end of file is encountered
 411.525 +     * before even one byte can be read, then <code>null</code>
 411.526 +     * is returned. Otherwise, each byte that is
 411.527 +     * read is converted to type <code>char</code>
 411.528 +     * by zero-extension. If the character <code>'\n'</code>
 411.529 +     * is encountered, it is discarded and reading
 411.530 +     * ceases. If the character <code>'\r'</code>
 411.531 +     * is encountered, it is discarded and, if
 411.532 +     * the following byte converts &#32;to the
 411.533 +     * character <code>'\n'</code>, then that is
 411.534 +     * discarded also; reading then ceases. If
 411.535 +     * end of file is encountered before either
 411.536 +     * of the characters <code>'\n'</code> and
 411.537 +     * <code>'\r'</code> is encountered, reading
 411.538 +     * ceases. Once reading has ceased, a <code>String</code>
 411.539 +     * is returned that contains all the characters
 411.540 +     * read and not discarded, taken in order.
 411.541 +     * Note that every character in this string
 411.542 +     * will have a value less than <code>&#92;u0100</code>,
 411.543 +     * that is, <code>(char)256</code>.
 411.544 +     *
 411.545 +     * @return the next line of text from the input stream,
 411.546 +     *         or <CODE>null</CODE> if the end of file is
 411.547 +     *         encountered before a byte can be read.
 411.548 +     * @exception  IOException  if an I/O error occurs.
 411.549 +     */
 411.550 +    String readLine() throws IOException;
 411.551 +
 411.552 +    /**
 411.553 +     * Reads in a string that has been encoded using a
 411.554 +     * <a href="#modified-utf-8">modified UTF-8</a>
 411.555 +     * format.
 411.556 +     * The general contract of <code>readUTF</code>
 411.557 +     * is that it reads a representation of a Unicode
 411.558 +     * character string encoded in modified
 411.559 +     * UTF-8 format; this string of characters
 411.560 +     * is then returned as a <code>String</code>.
 411.561 +     * <p>
 411.562 +     * First, two bytes are read and used to
 411.563 +     * construct an unsigned 16-bit integer in
 411.564 +     * exactly the manner of the <code>readUnsignedShort</code>
 411.565 +     * method . This integer value is called the
 411.566 +     * <i>UTF length</i> and specifies the number
 411.567 +     * of additional bytes to be read. These bytes
 411.568 +     * are then converted to characters by considering
 411.569 +     * them in groups. The length of each group
 411.570 +     * is computed from the value of the first
 411.571 +     * byte of the group. The byte following a
 411.572 +     * group, if any, is the first byte of the
 411.573 +     * next group.
 411.574 +     * <p>
 411.575 +     * If the first byte of a group
 411.576 +     * matches the bit pattern <code>0xxxxxxx</code>
 411.577 +     * (where <code>x</code> means "may be <code>0</code>
 411.578 +     * or <code>1</code>"), then the group consists
 411.579 +     * of just that byte. The byte is zero-extended
 411.580 +     * to form a character.
 411.581 +     * <p>
 411.582 +     * If the first byte
 411.583 +     * of a group matches the bit pattern <code>110xxxxx</code>,
 411.584 +     * then the group consists of that byte <code>a</code>
 411.585 +     * and a second byte <code>b</code>. If there
 411.586 +     * is no byte <code>b</code> (because byte
 411.587 +     * <code>a</code> was the last of the bytes
 411.588 +     * to be read), or if byte <code>b</code> does
 411.589 +     * not match the bit pattern <code>10xxxxxx</code>,
 411.590 +     * then a <code>UTFDataFormatException</code>
 411.591 +     * is thrown. Otherwise, the group is converted
 411.592 +     * to the character:<p>
 411.593 +     * <pre><code>(char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
 411.594 +     * </code></pre>
 411.595 +     * If the first byte of a group
 411.596 +     * matches the bit pattern <code>1110xxxx</code>,
 411.597 +     * then the group consists of that byte <code>a</code>
 411.598 +     * and two more bytes <code>b</code> and <code>c</code>.
 411.599 +     * If there is no byte <code>c</code> (because
 411.600 +     * byte <code>a</code> was one of the last
 411.601 +     * two of the bytes to be read), or either
 411.602 +     * byte <code>b</code> or byte <code>c</code>
 411.603 +     * does not match the bit pattern <code>10xxxxxx</code>,
 411.604 +     * then a <code>UTFDataFormatException</code>
 411.605 +     * is thrown. Otherwise, the group is converted
 411.606 +     * to the character:<p>
 411.607 +     * <pre><code>
 411.608 +     * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
 411.609 +     * </code></pre>
 411.610 +     * If the first byte of a group matches the
 411.611 +     * pattern <code>1111xxxx</code> or the pattern
 411.612 +     * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
 411.613 +     * is thrown.
 411.614 +     * <p>
 411.615 +     * If end of file is encountered
 411.616 +     * at any time during this entire process,
 411.617 +     * then an <code>EOFException</code> is thrown.
 411.618 +     * <p>
 411.619 +     * After every group has been converted to
 411.620 +     * a character by this process, the characters
 411.621 +     * are gathered, in the same order in which
 411.622 +     * their corresponding groups were read from
 411.623 +     * the input stream, to form a <code>String</code>,
 411.624 +     * which is returned.
 411.625 +     * <p>
 411.626 +     * The <code>writeUTF</code>
 411.627 +     * method of interface <code>DataOutput</code>
 411.628 +     * may be used to write data that is suitable
 411.629 +     * for reading by this method.
 411.630 +     * @return     a Unicode string.
 411.631 +     * @exception  EOFException            if this stream reaches the end
 411.632 +     *               before reading all the bytes.
 411.633 +     * @exception  IOException             if an I/O error occurs.
 411.634 +     * @exception  UTFDataFormatException  if the bytes do not represent a
 411.635 +     *               valid modified UTF-8 encoding of a string.
 411.636 +     */
 411.637 +    String readUTF() throws IOException;
 411.638 +}
   412.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   412.2 +++ b/rt/emul/mini/src/main/java/java/io/DataInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   412.3 @@ -0,0 +1,700 @@
   412.4 +/*
   412.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   412.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   412.7 + *
   412.8 + * This code is free software; you can redistribute it and/or modify it
   412.9 + * under the terms of the GNU General Public License version 2 only, as
  412.10 + * published by the Free Software Foundation.  Oracle designates this
  412.11 + * particular file as subject to the "Classpath" exception as provided
  412.12 + * by Oracle in the LICENSE file that accompanied this code.
  412.13 + *
  412.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  412.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  412.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  412.17 + * version 2 for more details (a copy is included in the LICENSE file that
  412.18 + * accompanied this code).
  412.19 + *
  412.20 + * You should have received a copy of the GNU General Public License version
  412.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  412.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  412.23 + *
  412.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  412.25 + * or visit www.oracle.com if you need additional information or have any
  412.26 + * questions.
  412.27 + */
  412.28 +
  412.29 +package java.io;
  412.30 +
  412.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  412.32 +import org.apidesign.bck2brwsr.emul.lang.System;
  412.33 +
  412.34 +/**
  412.35 + * A data input stream lets an application read primitive Java data
  412.36 + * types from an underlying input stream in a machine-independent
  412.37 + * way. An application uses a data output stream to write data that
  412.38 + * can later be read by a data input stream.
  412.39 + * <p>
  412.40 + * DataInputStream is not necessarily safe for multithreaded access.
  412.41 + * Thread safety is optional and is the responsibility of users of
  412.42 + * methods in this class.
  412.43 + *
  412.44 + * @author  Arthur van Hoff
  412.45 + * @see     java.io.DataOutputStream
  412.46 + * @since   JDK1.0
  412.47 + */
  412.48 +public
  412.49 +class DataInputStream extends FilterInputStream implements DataInput {
  412.50 +
  412.51 +    /**
  412.52 +     * Creates a DataInputStream that uses the specified
  412.53 +     * underlying InputStream.
  412.54 +     *
  412.55 +     * @param  in   the specified input stream
  412.56 +     */
  412.57 +    public DataInputStream(InputStream in) {
  412.58 +        super(in);
  412.59 +    }
  412.60 +
  412.61 +    /**
  412.62 +     * working arrays initialized on demand by readUTF
  412.63 +     */
  412.64 +    private byte bytearr[] = new byte[80];
  412.65 +    private char chararr[] = new char[80];
  412.66 +
  412.67 +    /**
  412.68 +     * Reads some number of bytes from the contained input stream and
  412.69 +     * stores them into the buffer array <code>b</code>. The number of
  412.70 +     * bytes actually read is returned as an integer. This method blocks
  412.71 +     * until input data is available, end of file is detected, or an
  412.72 +     * exception is thrown.
  412.73 +     *
  412.74 +     * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
  412.75 +     * thrown. If the length of <code>b</code> is zero, then no bytes are
  412.76 +     * read and <code>0</code> is returned; otherwise, there is an attempt
  412.77 +     * to read at least one byte. If no byte is available because the
  412.78 +     * stream is at end of file, the value <code>-1</code> is returned;
  412.79 +     * otherwise, at least one byte is read and stored into <code>b</code>.
  412.80 +     *
  412.81 +     * <p>The first byte read is stored into element <code>b[0]</code>, the
  412.82 +     * next one into <code>b[1]</code>, and so on. The number of bytes read
  412.83 +     * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
  412.84 +     * be the number of bytes actually read; these bytes will be stored in
  412.85 +     * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
  412.86 +     * elements <code>b[k]</code> through <code>b[b.length-1]</code>
  412.87 +     * unaffected.
  412.88 +     *
  412.89 +     * <p>The <code>read(b)</code> method has the same effect as:
  412.90 +     * <blockquote><pre>
  412.91 +     * read(b, 0, b.length)
  412.92 +     * </pre></blockquote>
  412.93 +     *
  412.94 +     * @param      b   the buffer into which the data is read.
  412.95 +     * @return     the total number of bytes read into the buffer, or
  412.96 +     *             <code>-1</code> if there is no more data because the end
  412.97 +     *             of the stream has been reached.
  412.98 +     * @exception  IOException if the first byte cannot be read for any reason
  412.99 +     * other than end of file, the stream has been closed and the underlying
 412.100 +     * input stream does not support reading after close, or another I/O
 412.101 +     * error occurs.
 412.102 +     * @see        java.io.FilterInputStream#in
 412.103 +     * @see        java.io.InputStream#read(byte[], int, int)
 412.104 +     */
 412.105 +    public final int read(byte b[]) throws IOException {
 412.106 +        return in.read(b, 0, b.length);
 412.107 +    }
 412.108 +
 412.109 +    /**
 412.110 +     * Reads up to <code>len</code> bytes of data from the contained
 412.111 +     * input stream into an array of bytes.  An attempt is made to read
 412.112 +     * as many as <code>len</code> bytes, but a smaller number may be read,
 412.113 +     * possibly zero. The number of bytes actually read is returned as an
 412.114 +     * integer.
 412.115 +     *
 412.116 +     * <p> This method blocks until input data is available, end of file is
 412.117 +     * detected, or an exception is thrown.
 412.118 +     *
 412.119 +     * <p> If <code>len</code> is zero, then no bytes are read and
 412.120 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
 412.121 +     * least one byte. If no byte is available because the stream is at end of
 412.122 +     * file, the value <code>-1</code> is returned; otherwise, at least one
 412.123 +     * byte is read and stored into <code>b</code>.
 412.124 +     *
 412.125 +     * <p> The first byte read is stored into element <code>b[off]</code>, the
 412.126 +     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
 412.127 +     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
 412.128 +     * bytes actually read; these bytes will be stored in elements
 412.129 +     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
 412.130 +     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
 412.131 +     * <code>b[off+len-1]</code> unaffected.
 412.132 +     *
 412.133 +     * <p> In every case, elements <code>b[0]</code> through
 412.134 +     * <code>b[off]</code> and elements <code>b[off+len]</code> through
 412.135 +     * <code>b[b.length-1]</code> are unaffected.
 412.136 +     *
 412.137 +     * @param      b     the buffer into which the data is read.
 412.138 +     * @param off the start offset in the destination array <code>b</code>
 412.139 +     * @param      len   the maximum number of bytes read.
 412.140 +     * @return     the total number of bytes read into the buffer, or
 412.141 +     *             <code>-1</code> if there is no more data because the end
 412.142 +     *             of the stream has been reached.
 412.143 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 412.144 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 412.145 +     * <code>len</code> is negative, or <code>len</code> is greater than
 412.146 +     * <code>b.length - off</code>
 412.147 +     * @exception  IOException if the first byte cannot be read for any reason
 412.148 +     * other than end of file, the stream has been closed and the underlying
 412.149 +     * input stream does not support reading after close, or another I/O
 412.150 +     * error occurs.
 412.151 +     * @see        java.io.FilterInputStream#in
 412.152 +     * @see        java.io.InputStream#read(byte[], int, int)
 412.153 +     */
 412.154 +    public final int read(byte b[], int off, int len) throws IOException {
 412.155 +        return in.read(b, off, len);
 412.156 +    }
 412.157 +
 412.158 +    /**
 412.159 +     * See the general contract of the <code>readFully</code>
 412.160 +     * method of <code>DataInput</code>.
 412.161 +     * <p>
 412.162 +     * Bytes
 412.163 +     * for this operation are read from the contained
 412.164 +     * input stream.
 412.165 +     *
 412.166 +     * @param      b   the buffer into which the data is read.
 412.167 +     * @exception  EOFException  if this input stream reaches the end before
 412.168 +     *             reading all the bytes.
 412.169 +     * @exception  IOException   the stream has been closed and the contained
 412.170 +     *             input stream does not support reading after close, or
 412.171 +     *             another I/O error occurs.
 412.172 +     * @see        java.io.FilterInputStream#in
 412.173 +     */
 412.174 +    public final void readFully(byte b[]) throws IOException {
 412.175 +        readFully(b, 0, b.length);
 412.176 +    }
 412.177 +
 412.178 +    /**
 412.179 +     * See the general contract of the <code>readFully</code>
 412.180 +     * method of <code>DataInput</code>.
 412.181 +     * <p>
 412.182 +     * Bytes
 412.183 +     * for this operation are read from the contained
 412.184 +     * input stream.
 412.185 +     *
 412.186 +     * @param      b     the buffer into which the data is read.
 412.187 +     * @param      off   the start offset of the data.
 412.188 +     * @param      len   the number of bytes to read.
 412.189 +     * @exception  EOFException  if this input stream reaches the end before
 412.190 +     *               reading all the bytes.
 412.191 +     * @exception  IOException   the stream has been closed and the contained
 412.192 +     *             input stream does not support reading after close, or
 412.193 +     *             another I/O error occurs.
 412.194 +     * @see        java.io.FilterInputStream#in
 412.195 +     */
 412.196 +    public final void readFully(byte b[], int off, int len) throws IOException {
 412.197 +        if (len < 0)
 412.198 +            throw new IndexOutOfBoundsException();
 412.199 +        int n = 0;
 412.200 +        while (n < len) {
 412.201 +            int count = in.read(b, off + n, len - n);
 412.202 +            if (count < 0)
 412.203 +                throw new EOFException();
 412.204 +            n += count;
 412.205 +        }
 412.206 +    }
 412.207 +
 412.208 +    /**
 412.209 +     * See the general contract of the <code>skipBytes</code>
 412.210 +     * method of <code>DataInput</code>.
 412.211 +     * <p>
 412.212 +     * Bytes for this operation are read from the contained
 412.213 +     * input stream.
 412.214 +     *
 412.215 +     * @param      n   the number of bytes to be skipped.
 412.216 +     * @return     the actual number of bytes skipped.
 412.217 +     * @exception  IOException  if the contained input stream does not support
 412.218 +     *             seek, or the stream has been closed and
 412.219 +     *             the contained input stream does not support
 412.220 +     *             reading after close, or another I/O error occurs.
 412.221 +     */
 412.222 +    public final int skipBytes(int n) throws IOException {
 412.223 +        int total = 0;
 412.224 +        int cur = 0;
 412.225 +
 412.226 +        while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
 412.227 +            total += cur;
 412.228 +        }
 412.229 +
 412.230 +        return total;
 412.231 +    }
 412.232 +
 412.233 +    /**
 412.234 +     * See the general contract of the <code>readBoolean</code>
 412.235 +     * method of <code>DataInput</code>.
 412.236 +     * <p>
 412.237 +     * Bytes for this operation are read from the contained
 412.238 +     * input stream.
 412.239 +     *
 412.240 +     * @return     the <code>boolean</code> value read.
 412.241 +     * @exception  EOFException  if this input stream has reached the end.
 412.242 +     * @exception  IOException   the stream has been closed and the contained
 412.243 +     *             input stream does not support reading after close, or
 412.244 +     *             another I/O error occurs.
 412.245 +     * @see        java.io.FilterInputStream#in
 412.246 +     */
 412.247 +    public final boolean readBoolean() throws IOException {
 412.248 +        int ch = in.read();
 412.249 +        if (ch < 0)
 412.250 +            throw new EOFException();
 412.251 +        return (ch != 0);
 412.252 +    }
 412.253 +
 412.254 +    /**
 412.255 +     * See the general contract of the <code>readByte</code>
 412.256 +     * method of <code>DataInput</code>.
 412.257 +     * <p>
 412.258 +     * Bytes
 412.259 +     * for this operation are read from the contained
 412.260 +     * input stream.
 412.261 +     *
 412.262 +     * @return     the next byte of this input stream as a signed 8-bit
 412.263 +     *             <code>byte</code>.
 412.264 +     * @exception  EOFException  if this input stream has reached the end.
 412.265 +     * @exception  IOException   the stream has been closed and the contained
 412.266 +     *             input stream does not support reading after close, or
 412.267 +     *             another I/O error occurs.
 412.268 +     * @see        java.io.FilterInputStream#in
 412.269 +     */
 412.270 +    public final byte readByte() throws IOException {
 412.271 +        int ch = in.read();
 412.272 +        if (ch < 0)
 412.273 +            throw new EOFException();
 412.274 +        return (byte)(ch);
 412.275 +    }
 412.276 +
 412.277 +    /**
 412.278 +     * See the general contract of the <code>readUnsignedByte</code>
 412.279 +     * method of <code>DataInput</code>.
 412.280 +     * <p>
 412.281 +     * Bytes
 412.282 +     * for this operation are read from the contained
 412.283 +     * input stream.
 412.284 +     *
 412.285 +     * @return     the next byte of this input stream, interpreted as an
 412.286 +     *             unsigned 8-bit number.
 412.287 +     * @exception  EOFException  if this input stream has reached the end.
 412.288 +     * @exception  IOException   the stream has been closed and the contained
 412.289 +     *             input stream does not support reading after close, or
 412.290 +     *             another I/O error occurs.
 412.291 +     * @see         java.io.FilterInputStream#in
 412.292 +     */
 412.293 +    public final int readUnsignedByte() throws IOException {
 412.294 +        int ch = in.read();
 412.295 +        if (ch < 0)
 412.296 +            throw new EOFException();
 412.297 +        return ch;
 412.298 +    }
 412.299 +
 412.300 +    /**
 412.301 +     * See the general contract of the <code>readShort</code>
 412.302 +     * method of <code>DataInput</code>.
 412.303 +     * <p>
 412.304 +     * Bytes
 412.305 +     * for this operation are read from the contained
 412.306 +     * input stream.
 412.307 +     *
 412.308 +     * @return     the next two bytes of this input stream, interpreted as a
 412.309 +     *             signed 16-bit number.
 412.310 +     * @exception  EOFException  if this input stream reaches the end before
 412.311 +     *               reading two bytes.
 412.312 +     * @exception  IOException   the stream has been closed and the contained
 412.313 +     *             input stream does not support reading after close, or
 412.314 +     *             another I/O error occurs.
 412.315 +     * @see        java.io.FilterInputStream#in
 412.316 +     */
 412.317 +    public final short readShort() throws IOException {
 412.318 +        int ch1 = in.read();
 412.319 +        int ch2 = in.read();
 412.320 +        if ((ch1 | ch2) < 0)
 412.321 +            throw new EOFException();
 412.322 +        return (short)((ch1 << 8) + (ch2 << 0));
 412.323 +    }
 412.324 +
 412.325 +    /**
 412.326 +     * See the general contract of the <code>readUnsignedShort</code>
 412.327 +     * method of <code>DataInput</code>.
 412.328 +     * <p>
 412.329 +     * Bytes
 412.330 +     * for this operation are read from the contained
 412.331 +     * input stream.
 412.332 +     *
 412.333 +     * @return     the next two bytes of this input stream, interpreted as an
 412.334 +     *             unsigned 16-bit integer.
 412.335 +     * @exception  EOFException  if this input stream reaches the end before
 412.336 +     *             reading two bytes.
 412.337 +     * @exception  IOException   the stream has been closed and the contained
 412.338 +     *             input stream does not support reading after close, or
 412.339 +     *             another I/O error occurs.
 412.340 +     * @see        java.io.FilterInputStream#in
 412.341 +     */
 412.342 +    public final int readUnsignedShort() throws IOException {
 412.343 +        int ch1 = in.read();
 412.344 +        int ch2 = in.read();
 412.345 +        if ((ch1 | ch2) < 0)
 412.346 +            throw new EOFException();
 412.347 +        return (ch1 << 8) + (ch2 << 0);
 412.348 +    }
 412.349 +
 412.350 +    /**
 412.351 +     * See the general contract of the <code>readChar</code>
 412.352 +     * method of <code>DataInput</code>.
 412.353 +     * <p>
 412.354 +     * Bytes
 412.355 +     * for this operation are read from the contained
 412.356 +     * input stream.
 412.357 +     *
 412.358 +     * @return     the next two bytes of this input stream, interpreted as a
 412.359 +     *             <code>char</code>.
 412.360 +     * @exception  EOFException  if this input stream reaches the end before
 412.361 +     *               reading two bytes.
 412.362 +     * @exception  IOException   the stream has been closed and the contained
 412.363 +     *             input stream does not support reading after close, or
 412.364 +     *             another I/O error occurs.
 412.365 +     * @see        java.io.FilterInputStream#in
 412.366 +     */
 412.367 +    public final char readChar() throws IOException {
 412.368 +        int ch1 = in.read();
 412.369 +        int ch2 = in.read();
 412.370 +        if ((ch1 | ch2) < 0)
 412.371 +            throw new EOFException();
 412.372 +        return (char)((ch1 << 8) + (ch2 << 0));
 412.373 +    }
 412.374 +
 412.375 +    /**
 412.376 +     * See the general contract of the <code>readInt</code>
 412.377 +     * method of <code>DataInput</code>.
 412.378 +     * <p>
 412.379 +     * Bytes
 412.380 +     * for this operation are read from the contained
 412.381 +     * input stream.
 412.382 +     *
 412.383 +     * @return     the next four bytes of this input stream, interpreted as an
 412.384 +     *             <code>int</code>.
 412.385 +     * @exception  EOFException  if this input stream reaches the end before
 412.386 +     *               reading four bytes.
 412.387 +     * @exception  IOException   the stream has been closed and the contained
 412.388 +     *             input stream does not support reading after close, or
 412.389 +     *             another I/O error occurs.
 412.390 +     * @see        java.io.FilterInputStream#in
 412.391 +     */
 412.392 +    public final int readInt() throws IOException {
 412.393 +        int ch1 = in.read();
 412.394 +        int ch2 = in.read();
 412.395 +        int ch3 = in.read();
 412.396 +        int ch4 = in.read();
 412.397 +        if ((ch1 | ch2 | ch3 | ch4) < 0)
 412.398 +            throw new EOFException();
 412.399 +        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
 412.400 +    }
 412.401 +
 412.402 +    private byte readBuffer[] = new byte[8];
 412.403 +
 412.404 +    /**
 412.405 +     * See the general contract of the <code>readLong</code>
 412.406 +     * method of <code>DataInput</code>.
 412.407 +     * <p>
 412.408 +     * Bytes
 412.409 +     * for this operation are read from the contained
 412.410 +     * input stream.
 412.411 +     *
 412.412 +     * @return     the next eight bytes of this input stream, interpreted as a
 412.413 +     *             <code>long</code>.
 412.414 +     * @exception  EOFException  if this input stream reaches the end before
 412.415 +     *               reading eight bytes.
 412.416 +     * @exception  IOException   the stream has been closed and the contained
 412.417 +     *             input stream does not support reading after close, or
 412.418 +     *             another I/O error occurs.
 412.419 +     * @see        java.io.FilterInputStream#in
 412.420 +     */
 412.421 +    public final long readLong() throws IOException {
 412.422 +        readFully(readBuffer, 0, 8);
 412.423 +        return (((long)readBuffer[0] << 56) +
 412.424 +                ((long)(readBuffer[1] & 255) << 48) +
 412.425 +                ((long)(readBuffer[2] & 255) << 40) +
 412.426 +                ((long)(readBuffer[3] & 255) << 32) +
 412.427 +                ((long)(readBuffer[4] & 255) << 24) +
 412.428 +                ((readBuffer[5] & 255) << 16) +
 412.429 +                ((readBuffer[6] & 255) <<  8) +
 412.430 +                ((readBuffer[7] & 255) <<  0));
 412.431 +    }
 412.432 +
 412.433 +    /**
 412.434 +     * See the general contract of the <code>readFloat</code>
 412.435 +     * method of <code>DataInput</code>.
 412.436 +     * <p>
 412.437 +     * Bytes
 412.438 +     * for this operation are read from the contained
 412.439 +     * input stream.
 412.440 +     *
 412.441 +     * @return     the next four bytes of this input stream, interpreted as a
 412.442 +     *             <code>float</code>.
 412.443 +     * @exception  EOFException  if this input stream reaches the end before
 412.444 +     *               reading four bytes.
 412.445 +     * @exception  IOException   the stream has been closed and the contained
 412.446 +     *             input stream does not support reading after close, or
 412.447 +     *             another I/O error occurs.
 412.448 +     * @see        java.io.DataInputStream#readInt()
 412.449 +     * @see        java.lang.Float#intBitsToFloat(int)
 412.450 +     */
 412.451 +    public final float readFloat() throws IOException {
 412.452 +        return Float.intBitsToFloat(readInt());
 412.453 +    }
 412.454 +
 412.455 +    /**
 412.456 +     * See the general contract of the <code>readDouble</code>
 412.457 +     * method of <code>DataInput</code>.
 412.458 +     * <p>
 412.459 +     * Bytes
 412.460 +     * for this operation are read from the contained
 412.461 +     * input stream.
 412.462 +     *
 412.463 +     * @return     the next eight bytes of this input stream, interpreted as a
 412.464 +     *             <code>double</code>.
 412.465 +     * @exception  EOFException  if this input stream reaches the end before
 412.466 +     *               reading eight bytes.
 412.467 +     * @exception  IOException   the stream has been closed and the contained
 412.468 +     *             input stream does not support reading after close, or
 412.469 +     *             another I/O error occurs.
 412.470 +     * @see        java.io.DataInputStream#readLong()
 412.471 +     * @see        java.lang.Double#longBitsToDouble(long)
 412.472 +     */
 412.473 +    public final double readDouble() throws IOException {
 412.474 +        int hi = readInt();
 412.475 +        int low = readInt();
 412.476 +        return toDouble(hi, low);
 412.477 +    }
 412.478 +    
 412.479 +    @JavaScriptBody(args={ "hi", "low" },
 412.480 +        body=
 412.481 +          "if (low == 0) {\n"
 412.482 +        + "  if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
 412.483 +        + "  if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
 412.484 +        + "}\n"
 412.485 +        + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
 412.486 +        + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
 412.487 +        + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
 412.488 +        + "var e = (hi >> 20) & 0x7ff;\n"
 412.489 +        + "var to32 = low >> 0;\n"
 412.490 +        + "if (e === 0) {\n"
 412.491 +        + "  if (to32 & 0x80000000) {\n"
 412.492 +        + "    hi = hi << 1 + 1; low = low << 1;\n"
 412.493 +        + "  } else {\n"
 412.494 +        + "    hi = hi << 1; low = low << 1;\n"
 412.495 +        + "  }\n" 
 412.496 +        + "} else {\n"
 412.497 +        + "    hi = (hi & 0xfffff) | 0x100000;\n"
 412.498 +        + "}\n"
 412.499 +        + "to32 = low >> 0;\n"
 412.500 +        + "var m = Math.pow(2.0, 32) * hi + to32;\n"
 412.501 +        + "var r = s * m * Math.pow(2.0, e - 1075);\n"
 412.502 +        + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
 412.503 +        + "return r;\n"
 412.504 +    )
 412.505 +    private static double toDouble(int hi, int low) {
 412.506 +        long both = hi;
 412.507 +        both = (both << 32) & low;
 412.508 +        return Double.doubleToLongBits(both);
 412.509 +    }
 412.510 +
 412.511 +    private char lineBuffer[];
 412.512 +
 412.513 +    /**
 412.514 +     * See the general contract of the <code>readLine</code>
 412.515 +     * method of <code>DataInput</code>.
 412.516 +     * <p>
 412.517 +     * Bytes
 412.518 +     * for this operation are read from the contained
 412.519 +     * input stream.
 412.520 +     *
 412.521 +     * @deprecated This method does not properly convert bytes to characters.
 412.522 +     * As of JDK&nbsp;1.1, the preferred way to read lines of text is via the
 412.523 +     * <code>BufferedReader.readLine()</code> method.  Programs that use the
 412.524 +     * <code>DataInputStream</code> class to read lines can be converted to use
 412.525 +     * the <code>BufferedReader</code> class by replacing code of the form:
 412.526 +     * <blockquote><pre>
 412.527 +     *     DataInputStream d =&nbsp;new&nbsp;DataInputStream(in);
 412.528 +     * </pre></blockquote>
 412.529 +     * with:
 412.530 +     * <blockquote><pre>
 412.531 +     *     BufferedReader d
 412.532 +     *          =&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(in));
 412.533 +     * </pre></blockquote>
 412.534 +     *
 412.535 +     * @return     the next line of text from this input stream.
 412.536 +     * @exception  IOException  if an I/O error occurs.
 412.537 +     * @see        java.io.BufferedReader#readLine()
 412.538 +     * @see        java.io.FilterInputStream#in
 412.539 +     */
 412.540 +    @Deprecated
 412.541 +    public final String readLine() throws IOException {
 412.542 +        char buf[] = lineBuffer;
 412.543 +
 412.544 +        if (buf == null) {
 412.545 +            buf = lineBuffer = new char[128];
 412.546 +        }
 412.547 +
 412.548 +        int room = buf.length;
 412.549 +        int offset = 0;
 412.550 +        int c;
 412.551 +
 412.552 +loop:   while (true) {
 412.553 +            switch (c = in.read()) {
 412.554 +              case -1:
 412.555 +              case '\n':
 412.556 +                break loop;
 412.557 +
 412.558 +              case '\r':
 412.559 +                int c2 = in.read();
 412.560 +                if ((c2 != '\n') && (c2 != -1)) {
 412.561 +                    if (!(in instanceof PushbackInputStream)) {
 412.562 +                        this.in = new PushbackInputStream(in);
 412.563 +                    }
 412.564 +                    ((PushbackInputStream)in).unread(c2);
 412.565 +                }
 412.566 +                break loop;
 412.567 +
 412.568 +              default:
 412.569 +                if (--room < 0) {
 412.570 +                    buf = new char[offset + 128];
 412.571 +                    room = buf.length - offset - 1;
 412.572 +                    System.arraycopy(lineBuffer, 0, buf, 0, offset);
 412.573 +                    lineBuffer = buf;
 412.574 +                }
 412.575 +                buf[offset++] = (char) c;
 412.576 +                break;
 412.577 +            }
 412.578 +        }
 412.579 +        if ((c == -1) && (offset == 0)) {
 412.580 +            return null;
 412.581 +        }
 412.582 +        return String.copyValueOf(buf, 0, offset);
 412.583 +    }
 412.584 +
 412.585 +    /**
 412.586 +     * See the general contract of the <code>readUTF</code>
 412.587 +     * method of <code>DataInput</code>.
 412.588 +     * <p>
 412.589 +     * Bytes
 412.590 +     * for this operation are read from the contained
 412.591 +     * input stream.
 412.592 +     *
 412.593 +     * @return     a Unicode string.
 412.594 +     * @exception  EOFException  if this input stream reaches the end before
 412.595 +     *               reading all the bytes.
 412.596 +     * @exception  IOException   the stream has been closed and the contained
 412.597 +     *             input stream does not support reading after close, or
 412.598 +     *             another I/O error occurs.
 412.599 +     * @exception  UTFDataFormatException if the bytes do not represent a valid
 412.600 +     *             modified UTF-8 encoding of a string.
 412.601 +     * @see        java.io.DataInputStream#readUTF(java.io.DataInput)
 412.602 +     */
 412.603 +    public final String readUTF() throws IOException {
 412.604 +        return readUTF(this);
 412.605 +    }
 412.606 +
 412.607 +    /**
 412.608 +     * Reads from the
 412.609 +     * stream <code>in</code> a representation
 412.610 +     * of a Unicode  character string encoded in
 412.611 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
 412.612 +     * this string of characters is then returned as a <code>String</code>.
 412.613 +     * The details of the modified UTF-8 representation
 412.614 +     * are  exactly the same as for the <code>readUTF</code>
 412.615 +     * method of <code>DataInput</code>.
 412.616 +     *
 412.617 +     * @param      in   a data input stream.
 412.618 +     * @return     a Unicode string.
 412.619 +     * @exception  EOFException            if the input stream reaches the end
 412.620 +     *               before all the bytes.
 412.621 +     * @exception  IOException   the stream has been closed and the contained
 412.622 +     *             input stream does not support reading after close, or
 412.623 +     *             another I/O error occurs.
 412.624 +     * @exception  UTFDataFormatException  if the bytes do not represent a
 412.625 +     *               valid modified UTF-8 encoding of a Unicode string.
 412.626 +     * @see        java.io.DataInputStream#readUnsignedShort()
 412.627 +     */
 412.628 +    public final static String readUTF(DataInput in) throws IOException {
 412.629 +        int utflen = in.readUnsignedShort();
 412.630 +        byte[] bytearr = null;
 412.631 +        char[] chararr = null;
 412.632 +        if (in instanceof DataInputStream) {
 412.633 +            DataInputStream dis = (DataInputStream)in;
 412.634 +            if (dis.bytearr.length < utflen){
 412.635 +                dis.bytearr = new byte[utflen*2];
 412.636 +                dis.chararr = new char[utflen*2];
 412.637 +            }
 412.638 +            chararr = dis.chararr;
 412.639 +            bytearr = dis.bytearr;
 412.640 +        } else {
 412.641 +            bytearr = new byte[utflen];
 412.642 +            chararr = new char[utflen];
 412.643 +        }
 412.644 +
 412.645 +        int c, char2, char3;
 412.646 +        int count = 0;
 412.647 +        int chararr_count=0;
 412.648 +
 412.649 +        in.readFully(bytearr, 0, utflen);
 412.650 +
 412.651 +        while (count < utflen) {
 412.652 +            c = (int) bytearr[count] & 0xff;
 412.653 +            if (c > 127) break;
 412.654 +            count++;
 412.655 +            chararr[chararr_count++]=(char)c;
 412.656 +        }
 412.657 +
 412.658 +        while (count < utflen) {
 412.659 +            c = (int) bytearr[count] & 0xff;
 412.660 +            switch (c >> 4) {
 412.661 +                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
 412.662 +                    /* 0xxxxxxx*/
 412.663 +                    count++;
 412.664 +                    chararr[chararr_count++]=(char)c;
 412.665 +                    break;
 412.666 +                case 12: case 13:
 412.667 +                    /* 110x xxxx   10xx xxxx*/
 412.668 +                    count += 2;
 412.669 +                    if (count > utflen)
 412.670 +                        throw new UTFDataFormatException(
 412.671 +                            "malformed input: partial character at end");
 412.672 +                    char2 = (int) bytearr[count-1];
 412.673 +                    if ((char2 & 0xC0) != 0x80)
 412.674 +                        throw new UTFDataFormatException(
 412.675 +                            "malformed input around byte " + count);
 412.676 +                    chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
 412.677 +                                                    (char2 & 0x3F));
 412.678 +                    break;
 412.679 +                case 14:
 412.680 +                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
 412.681 +                    count += 3;
 412.682 +                    if (count > utflen)
 412.683 +                        throw new UTFDataFormatException(
 412.684 +                            "malformed input: partial character at end");
 412.685 +                    char2 = (int) bytearr[count-2];
 412.686 +                    char3 = (int) bytearr[count-1];
 412.687 +                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
 412.688 +                        throw new UTFDataFormatException(
 412.689 +                            "malformed input around byte " + (count-1));
 412.690 +                    chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
 412.691 +                                                    ((char2 & 0x3F) << 6)  |
 412.692 +                                                    ((char3 & 0x3F) << 0));
 412.693 +                    break;
 412.694 +                default:
 412.695 +                    /* 10xx xxxx,  1111 xxxx */
 412.696 +                    throw new UTFDataFormatException(
 412.697 +                        "malformed input around byte " + count);
 412.698 +            }
 412.699 +        }
 412.700 +        // The number of chars produced may be less than utflen
 412.701 +        return new String(chararr, 0, chararr_count);
 412.702 +    }
 412.703 +}
   413.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   413.2 +++ b/rt/emul/mini/src/main/java/java/io/EOFException.java	Wed Feb 27 11:24:58 2013 +0100
   413.3 @@ -0,0 +1,65 @@
   413.4 +/*
   413.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   413.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   413.7 + *
   413.8 + * This code is free software; you can redistribute it and/or modify it
   413.9 + * under the terms of the GNU General Public License version 2 only, as
  413.10 + * published by the Free Software Foundation.  Oracle designates this
  413.11 + * particular file as subject to the "Classpath" exception as provided
  413.12 + * by Oracle in the LICENSE file that accompanied this code.
  413.13 + *
  413.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  413.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  413.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  413.17 + * version 2 for more details (a copy is included in the LICENSE file that
  413.18 + * accompanied this code).
  413.19 + *
  413.20 + * You should have received a copy of the GNU General Public License version
  413.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  413.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  413.23 + *
  413.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  413.25 + * or visit www.oracle.com if you need additional information or have any
  413.26 + * questions.
  413.27 + */
  413.28 +
  413.29 +package java.io;
  413.30 +
  413.31 +/**
  413.32 + * Signals that an end of file or end of stream has been reached
  413.33 + * unexpectedly during input.
  413.34 + * <p>
  413.35 + * This exception is mainly used by data input streams to signal end of
  413.36 + * stream. Note that many other input operations return a special value on
  413.37 + * end of stream rather than throwing an exception.
  413.38 + * <p>
  413.39 + *
  413.40 + * @author  Frank Yellin
  413.41 + * @see     java.io.DataInputStream
  413.42 + * @see     java.io.IOException
  413.43 + * @since   JDK1.0
  413.44 + */
  413.45 +public
  413.46 +class EOFException extends IOException {
  413.47 +    private static final long serialVersionUID = 6433858223774886977L;
  413.48 +
  413.49 +    /**
  413.50 +     * Constructs an <code>EOFException</code> with <code>null</code>
  413.51 +     * as its error detail message.
  413.52 +     */
  413.53 +    public EOFException() {
  413.54 +        super();
  413.55 +    }
  413.56 +
  413.57 +    /**
  413.58 +     * Constructs an <code>EOFException</code> with the specified detail
  413.59 +     * message. The string <code>s</code> may later be retrieved by the
  413.60 +     * <code>{@link java.lang.Throwable#getMessage}</code> method of class
  413.61 +     * <code>java.lang.Throwable</code>.
  413.62 +     *
  413.63 +     * @param   s   the detail message.
  413.64 +     */
  413.65 +    public EOFException(String s) {
  413.66 +        super(s);
  413.67 +    }
  413.68 +}
   414.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   414.2 +++ b/rt/emul/mini/src/main/java/java/io/FilterInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   414.3 @@ -0,0 +1,245 @@
   414.4 +/*
   414.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   414.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   414.7 + *
   414.8 + * This code is free software; you can redistribute it and/or modify it
   414.9 + * under the terms of the GNU General Public License version 2 only, as
  414.10 + * published by the Free Software Foundation.  Oracle designates this
  414.11 + * particular file as subject to the "Classpath" exception as provided
  414.12 + * by Oracle in the LICENSE file that accompanied this code.
  414.13 + *
  414.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  414.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  414.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  414.17 + * version 2 for more details (a copy is included in the LICENSE file that
  414.18 + * accompanied this code).
  414.19 + *
  414.20 + * You should have received a copy of the GNU General Public License version
  414.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  414.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  414.23 + *
  414.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  414.25 + * or visit www.oracle.com if you need additional information or have any
  414.26 + * questions.
  414.27 + */
  414.28 +
  414.29 +package java.io;
  414.30 +
  414.31 +/**
  414.32 + * A <code>FilterInputStream</code> contains
  414.33 + * some other input stream, which it uses as
  414.34 + * its  basic source of data, possibly transforming
  414.35 + * the data along the way or providing  additional
  414.36 + * functionality. The class <code>FilterInputStream</code>
  414.37 + * itself simply overrides all  methods of
  414.38 + * <code>InputStream</code> with versions that
  414.39 + * pass all requests to the contained  input
  414.40 + * stream. Subclasses of <code>FilterInputStream</code>
  414.41 + * may further override some of  these methods
  414.42 + * and may also provide additional methods
  414.43 + * and fields.
  414.44 + *
  414.45 + * @author  Jonathan Payne
  414.46 + * @since   JDK1.0
  414.47 + */
  414.48 +public
  414.49 +class FilterInputStream extends InputStream {
  414.50 +    /**
  414.51 +     * The input stream to be filtered.
  414.52 +     */
  414.53 +    protected volatile InputStream in;
  414.54 +
  414.55 +    /**
  414.56 +     * Creates a <code>FilterInputStream</code>
  414.57 +     * by assigning the  argument <code>in</code>
  414.58 +     * to the field <code>this.in</code> so as
  414.59 +     * to remember it for later use.
  414.60 +     *
  414.61 +     * @param   in   the underlying input stream, or <code>null</code> if
  414.62 +     *          this instance is to be created without an underlying stream.
  414.63 +     */
  414.64 +    protected FilterInputStream(InputStream in) {
  414.65 +        this.in = in;
  414.66 +    }
  414.67 +
  414.68 +    /**
  414.69 +     * Reads the next byte of data from this input stream. The value
  414.70 +     * byte is returned as an <code>int</code> in the range
  414.71 +     * <code>0</code> to <code>255</code>. If no byte is available
  414.72 +     * because the end of the stream has been reached, the value
  414.73 +     * <code>-1</code> is returned. This method blocks until input data
  414.74 +     * is available, the end of the stream is detected, or an exception
  414.75 +     * is thrown.
  414.76 +     * <p>
  414.77 +     * This method
  414.78 +     * simply performs <code>in.read()</code> and returns the result.
  414.79 +     *
  414.80 +     * @return     the next byte of data, or <code>-1</code> if the end of the
  414.81 +     *             stream is reached.
  414.82 +     * @exception  IOException  if an I/O error occurs.
  414.83 +     * @see        java.io.FilterInputStream#in
  414.84 +     */
  414.85 +    public int read() throws IOException {
  414.86 +        return in.read();
  414.87 +    }
  414.88 +
  414.89 +    /**
  414.90 +     * Reads up to <code>byte.length</code> bytes of data from this
  414.91 +     * input stream into an array of bytes. This method blocks until some
  414.92 +     * input is available.
  414.93 +     * <p>
  414.94 +     * This method simply performs the call
  414.95 +     * <code>read(b, 0, b.length)</code> and returns
  414.96 +     * the  result. It is important that it does
  414.97 +     * <i>not</i> do <code>in.read(b)</code> instead;
  414.98 +     * certain subclasses of  <code>FilterInputStream</code>
  414.99 +     * depend on the implementation strategy actually
 414.100 +     * used.
 414.101 +     *
 414.102 +     * @param      b   the buffer into which the data is read.
 414.103 +     * @return     the total number of bytes read into the buffer, or
 414.104 +     *             <code>-1</code> if there is no more data because the end of
 414.105 +     *             the stream has been reached.
 414.106 +     * @exception  IOException  if an I/O error occurs.
 414.107 +     * @see        java.io.FilterInputStream#read(byte[], int, int)
 414.108 +     */
 414.109 +    public int read(byte b[]) throws IOException {
 414.110 +        return read(b, 0, b.length);
 414.111 +    }
 414.112 +
 414.113 +    /**
 414.114 +     * Reads up to <code>len</code> bytes of data from this input stream
 414.115 +     * into an array of bytes. If <code>len</code> is not zero, the method
 414.116 +     * blocks until some input is available; otherwise, no
 414.117 +     * bytes are read and <code>0</code> is returned.
 414.118 +     * <p>
 414.119 +     * This method simply performs <code>in.read(b, off, len)</code>
 414.120 +     * and returns the result.
 414.121 +     *
 414.122 +     * @param      b     the buffer into which the data is read.
 414.123 +     * @param      off   the start offset in the destination array <code>b</code>
 414.124 +     * @param      len   the maximum number of bytes read.
 414.125 +     * @return     the total number of bytes read into the buffer, or
 414.126 +     *             <code>-1</code> if there is no more data because the end of
 414.127 +     *             the stream has been reached.
 414.128 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 414.129 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 414.130 +     * <code>len</code> is negative, or <code>len</code> is greater than
 414.131 +     * <code>b.length - off</code>
 414.132 +     * @exception  IOException  if an I/O error occurs.
 414.133 +     * @see        java.io.FilterInputStream#in
 414.134 +     */
 414.135 +    public int read(byte b[], int off, int len) throws IOException {
 414.136 +        return in.read(b, off, len);
 414.137 +    }
 414.138 +
 414.139 +    /**
 414.140 +     * Skips over and discards <code>n</code> bytes of data from the
 414.141 +     * input stream. The <code>skip</code> method may, for a variety of
 414.142 +     * reasons, end up skipping over some smaller number of bytes,
 414.143 +     * possibly <code>0</code>. The actual number of bytes skipped is
 414.144 +     * returned.
 414.145 +     * <p>
 414.146 +     * This method simply performs <code>in.skip(n)</code>.
 414.147 +     *
 414.148 +     * @param      n   the number of bytes to be skipped.
 414.149 +     * @return     the actual number of bytes skipped.
 414.150 +     * @exception  IOException  if the stream does not support seek,
 414.151 +     *                          or if some other I/O error occurs.
 414.152 +     */
 414.153 +    public long skip(long n) throws IOException {
 414.154 +        return in.skip(n);
 414.155 +    }
 414.156 +
 414.157 +    /**
 414.158 +     * Returns an estimate of the number of bytes that can be read (or
 414.159 +     * skipped over) from this input stream without blocking by the next
 414.160 +     * caller of a method for this input stream. The next caller might be
 414.161 +     * the same thread or another thread.  A single read or skip of this
 414.162 +     * many bytes will not block, but may read or skip fewer bytes.
 414.163 +     * <p>
 414.164 +     * This method returns the result of {@link #in in}.available().
 414.165 +     *
 414.166 +     * @return     an estimate of the number of bytes that can be read (or skipped
 414.167 +     *             over) from this input stream without blocking.
 414.168 +     * @exception  IOException  if an I/O error occurs.
 414.169 +     */
 414.170 +    public int available() throws IOException {
 414.171 +        return in.available();
 414.172 +    }
 414.173 +
 414.174 +    /**
 414.175 +     * Closes this input stream and releases any system resources
 414.176 +     * associated with the stream.
 414.177 +     * This
 414.178 +     * method simply performs <code>in.close()</code>.
 414.179 +     *
 414.180 +     * @exception  IOException  if an I/O error occurs.
 414.181 +     * @see        java.io.FilterInputStream#in
 414.182 +     */
 414.183 +    public void close() throws IOException {
 414.184 +        in.close();
 414.185 +    }
 414.186 +
 414.187 +    /**
 414.188 +     * Marks the current position in this input stream. A subsequent
 414.189 +     * call to the <code>reset</code> method repositions this stream at
 414.190 +     * the last marked position so that subsequent reads re-read the same bytes.
 414.191 +     * <p>
 414.192 +     * The <code>readlimit</code> argument tells this input stream to
 414.193 +     * allow that many bytes to be read before the mark position gets
 414.194 +     * invalidated.
 414.195 +     * <p>
 414.196 +     * This method simply performs <code>in.mark(readlimit)</code>.
 414.197 +     *
 414.198 +     * @param   readlimit   the maximum limit of bytes that can be read before
 414.199 +     *                      the mark position becomes invalid.
 414.200 +     * @see     java.io.FilterInputStream#in
 414.201 +     * @see     java.io.FilterInputStream#reset()
 414.202 +     */
 414.203 +    public synchronized void mark(int readlimit) {
 414.204 +        in.mark(readlimit);
 414.205 +    }
 414.206 +
 414.207 +    /**
 414.208 +     * Repositions this stream to the position at the time the
 414.209 +     * <code>mark</code> method was last called on this input stream.
 414.210 +     * <p>
 414.211 +     * This method
 414.212 +     * simply performs <code>in.reset()</code>.
 414.213 +     * <p>
 414.214 +     * Stream marks are intended to be used in
 414.215 +     * situations where you need to read ahead a little to see what's in
 414.216 +     * the stream. Often this is most easily done by invoking some
 414.217 +     * general parser. If the stream is of the type handled by the
 414.218 +     * parse, it just chugs along happily. If the stream is not of
 414.219 +     * that type, the parser should toss an exception when it fails.
 414.220 +     * If this happens within readlimit bytes, it allows the outer
 414.221 +     * code to reset the stream and try another parser.
 414.222 +     *
 414.223 +     * @exception  IOException  if the stream has not been marked or if the
 414.224 +     *               mark has been invalidated.
 414.225 +     * @see        java.io.FilterInputStream#in
 414.226 +     * @see        java.io.FilterInputStream#mark(int)
 414.227 +     */
 414.228 +    public synchronized void reset() throws IOException {
 414.229 +        in.reset();
 414.230 +    }
 414.231 +
 414.232 +    /**
 414.233 +     * Tests if this input stream supports the <code>mark</code>
 414.234 +     * and <code>reset</code> methods.
 414.235 +     * This method
 414.236 +     * simply performs <code>in.markSupported()</code>.
 414.237 +     *
 414.238 +     * @return  <code>true</code> if this stream type supports the
 414.239 +     *          <code>mark</code> and <code>reset</code> method;
 414.240 +     *          <code>false</code> otherwise.
 414.241 +     * @see     java.io.FilterInputStream#in
 414.242 +     * @see     java.io.InputStream#mark(int)
 414.243 +     * @see     java.io.InputStream#reset()
 414.244 +     */
 414.245 +    public boolean markSupported() {
 414.246 +        return in.markSupported();
 414.247 +    }
 414.248 +}
   415.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   415.2 +++ b/rt/emul/mini/src/main/java/java/io/IOException.java	Wed Feb 27 11:24:58 2013 +0100
   415.3 @@ -0,0 +1,101 @@
   415.4 +/*
   415.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   415.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   415.7 + *
   415.8 + * This code is free software; you can redistribute it and/or modify it
   415.9 + * under the terms of the GNU General Public License version 2 only, as
  415.10 + * published by the Free Software Foundation.  Oracle designates this
  415.11 + * particular file as subject to the "Classpath" exception as provided
  415.12 + * by Oracle in the LICENSE file that accompanied this code.
  415.13 + *
  415.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  415.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  415.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  415.17 + * version 2 for more details (a copy is included in the LICENSE file that
  415.18 + * accompanied this code).
  415.19 + *
  415.20 + * You should have received a copy of the GNU General Public License version
  415.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  415.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  415.23 + *
  415.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  415.25 + * or visit www.oracle.com if you need additional information or have any
  415.26 + * questions.
  415.27 + */
  415.28 +
  415.29 +package java.io;
  415.30 +
  415.31 +/**
  415.32 + * Signals that an I/O exception of some sort has occurred. This
  415.33 + * class is the general class of exceptions produced by failed or
  415.34 + * interrupted I/O operations.
  415.35 + *
  415.36 + * @author  unascribed
  415.37 + * @see     java.io.InputStream
  415.38 + * @see     java.io.OutputStream
  415.39 + * @since   JDK1.0
  415.40 + */
  415.41 +public
  415.42 +class IOException extends Exception {
  415.43 +    static final long serialVersionUID = 7818375828146090155L;
  415.44 +
  415.45 +    /**
  415.46 +     * Constructs an {@code IOException} with {@code null}
  415.47 +     * as its error detail message.
  415.48 +     */
  415.49 +    public IOException() {
  415.50 +        super();
  415.51 +    }
  415.52 +
  415.53 +    /**
  415.54 +     * Constructs an {@code IOException} with the specified detail message.
  415.55 +     *
  415.56 +     * @param message
  415.57 +     *        The detail message (which is saved for later retrieval
  415.58 +     *        by the {@link #getMessage()} method)
  415.59 +     */
  415.60 +    public IOException(String message) {
  415.61 +        super(message);
  415.62 +    }
  415.63 +
  415.64 +    /**
  415.65 +     * Constructs an {@code IOException} with the specified detail message
  415.66 +     * and cause.
  415.67 +     *
  415.68 +     * <p> Note that the detail message associated with {@code cause} is
  415.69 +     * <i>not</i> automatically incorporated into this exception's detail
  415.70 +     * message.
  415.71 +     *
  415.72 +     * @param message
  415.73 +     *        The detail message (which is saved for later retrieval
  415.74 +     *        by the {@link #getMessage()} method)
  415.75 +     *
  415.76 +     * @param cause
  415.77 +     *        The cause (which is saved for later retrieval by the
  415.78 +     *        {@link #getCause()} method).  (A null value is permitted,
  415.79 +     *        and indicates that the cause is nonexistent or unknown.)
  415.80 +     *
  415.81 +     * @since 1.6
  415.82 +     */
  415.83 +    public IOException(String message, Throwable cause) {
  415.84 +        super(message, cause);
  415.85 +    }
  415.86 +
  415.87 +    /**
  415.88 +     * Constructs an {@code IOException} with the specified cause and a
  415.89 +     * detail message of {@code (cause==null ? null : cause.toString())}
  415.90 +     * (which typically contains the class and detail message of {@code cause}).
  415.91 +     * This constructor is useful for IO exceptions that are little more
  415.92 +     * than wrappers for other throwables.
  415.93 +     *
  415.94 +     * @param cause
  415.95 +     *        The cause (which is saved for later retrieval by the
  415.96 +     *        {@link #getCause()} method).  (A null value is permitted,
  415.97 +     *        and indicates that the cause is nonexistent or unknown.)
  415.98 +     *
  415.99 +     * @since 1.6
 415.100 +     */
 415.101 +    public IOException(Throwable cause) {
 415.102 +        super(cause);
 415.103 +    }
 415.104 +}
   416.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   416.2 +++ b/rt/emul/mini/src/main/java/java/io/InputStream.java	Wed Feb 27 11:24:58 2013 +0100
   416.3 @@ -0,0 +1,370 @@
   416.4 +/*
   416.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   416.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   416.7 + *
   416.8 + * This code is free software; you can redistribute it and/or modify it
   416.9 + * under the terms of the GNU General Public License version 2 only, as
  416.10 + * published by the Free Software Foundation.  Oracle designates this
  416.11 + * particular file as subject to the "Classpath" exception as provided
  416.12 + * by Oracle in the LICENSE file that accompanied this code.
  416.13 + *
  416.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  416.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  416.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  416.17 + * version 2 for more details (a copy is included in the LICENSE file that
  416.18 + * accompanied this code).
  416.19 + *
  416.20 + * You should have received a copy of the GNU General Public License version
  416.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  416.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  416.23 + *
  416.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  416.25 + * or visit www.oracle.com if you need additional information or have any
  416.26 + * questions.
  416.27 + */
  416.28 +
  416.29 +package java.io;
  416.30 +
  416.31 +/**
  416.32 + * This abstract class is the superclass of all classes representing
  416.33 + * an input stream of bytes.
  416.34 + *
  416.35 + * <p> Applications that need to define a subclass of <code>InputStream</code>
  416.36 + * must always provide a method that returns the next byte of input.
  416.37 + *
  416.38 + * @author  Arthur van Hoff
  416.39 + * @see     java.io.BufferedInputStream
  416.40 + * @see     java.io.ByteArrayInputStream
  416.41 + * @see     java.io.DataInputStream
  416.42 + * @see     java.io.FilterInputStream
  416.43 + * @see     java.io.InputStream#read()
  416.44 + * @see     java.io.OutputStream
  416.45 + * @see     java.io.PushbackInputStream
  416.46 + * @since   JDK1.0
  416.47 + */
  416.48 +public abstract class InputStream implements Closeable {
  416.49 +
  416.50 +    // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
  416.51 +    private static final int SKIP_BUFFER_SIZE = 2048;
  416.52 +    // skipBuffer is initialized in skip(long), if needed.
  416.53 +    private static byte[] skipBuffer;
  416.54 +
  416.55 +    /**
  416.56 +     * Reads the next byte of data from the input stream. The value byte is
  416.57 +     * returned as an <code>int</code> in the range <code>0</code> to
  416.58 +     * <code>255</code>. If no byte is available because the end of the stream
  416.59 +     * has been reached, the value <code>-1</code> is returned. This method
  416.60 +     * blocks until input data is available, the end of the stream is detected,
  416.61 +     * or an exception is thrown.
  416.62 +     *
  416.63 +     * <p> A subclass must provide an implementation of this method.
  416.64 +     *
  416.65 +     * @return     the next byte of data, or <code>-1</code> if the end of the
  416.66 +     *             stream is reached.
  416.67 +     * @exception  IOException  if an I/O error occurs.
  416.68 +     */
  416.69 +    public abstract int read() throws IOException;
  416.70 +
  416.71 +    /**
  416.72 +     * Reads some number of bytes from the input stream and stores them into
  416.73 +     * the buffer array <code>b</code>. The number of bytes actually read is
  416.74 +     * returned as an integer.  This method blocks until input data is
  416.75 +     * available, end of file is detected, or an exception is thrown.
  416.76 +     *
  416.77 +     * <p> If the length of <code>b</code> is zero, then no bytes are read and
  416.78 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
  416.79 +     * least one byte. If no byte is available because the stream is at the
  416.80 +     * end of the file, the value <code>-1</code> is returned; otherwise, at
  416.81 +     * least one byte is read and stored into <code>b</code>.
  416.82 +     *
  416.83 +     * <p> The first byte read is stored into element <code>b[0]</code>, the
  416.84 +     * next one into <code>b[1]</code>, and so on. The number of bytes read is,
  416.85 +     * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
  416.86 +     * number of bytes actually read; these bytes will be stored in elements
  416.87 +     * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
  416.88 +     * leaving elements <code>b[</code><i>k</i><code>]</code> through
  416.89 +     * <code>b[b.length-1]</code> unaffected.
  416.90 +     *
  416.91 +     * <p> The <code>read(b)</code> method for class <code>InputStream</code>
  416.92 +     * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
  416.93 +     *
  416.94 +     * @param      b   the buffer into which the data is read.
  416.95 +     * @return     the total number of bytes read into the buffer, or
  416.96 +     *             <code>-1</code> if there is no more data because the end of
  416.97 +     *             the stream has been reached.
  416.98 +     * @exception  IOException  If the first byte cannot be read for any reason
  416.99 +     * other than the end of the file, if the input stream has been closed, or
 416.100 +     * if some other I/O error occurs.
 416.101 +     * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
 416.102 +     * @see        java.io.InputStream#read(byte[], int, int)
 416.103 +     */
 416.104 +    public int read(byte b[]) throws IOException {
 416.105 +        return read(b, 0, b.length);
 416.106 +    }
 416.107 +
 416.108 +    /**
 416.109 +     * Reads up to <code>len</code> bytes of data from the input stream into
 416.110 +     * an array of bytes.  An attempt is made to read as many as
 416.111 +     * <code>len</code> bytes, but a smaller number may be read.
 416.112 +     * The number of bytes actually read is returned as an integer.
 416.113 +     *
 416.114 +     * <p> This method blocks until input data is available, end of file is
 416.115 +     * detected, or an exception is thrown.
 416.116 +     *
 416.117 +     * <p> If <code>len</code> is zero, then no bytes are read and
 416.118 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
 416.119 +     * least one byte. If no byte is available because the stream is at end of
 416.120 +     * file, the value <code>-1</code> is returned; otherwise, at least one
 416.121 +     * byte is read and stored into <code>b</code>.
 416.122 +     *
 416.123 +     * <p> The first byte read is stored into element <code>b[off]</code>, the
 416.124 +     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
 416.125 +     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
 416.126 +     * bytes actually read; these bytes will be stored in elements
 416.127 +     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
 416.128 +     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
 416.129 +     * <code>b[off+len-1]</code> unaffected.
 416.130 +     *
 416.131 +     * <p> In every case, elements <code>b[0]</code> through
 416.132 +     * <code>b[off]</code> and elements <code>b[off+len]</code> through
 416.133 +     * <code>b[b.length-1]</code> are unaffected.
 416.134 +     *
 416.135 +     * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
 416.136 +     * for class <code>InputStream</code> simply calls the method
 416.137 +     * <code>read()</code> repeatedly. If the first such call results in an
 416.138 +     * <code>IOException</code>, that exception is returned from the call to
 416.139 +     * the <code>read(b,</code> <code>off,</code> <code>len)</code> method.  If
 416.140 +     * any subsequent call to <code>read()</code> results in a
 416.141 +     * <code>IOException</code>, the exception is caught and treated as if it
 416.142 +     * were end of file; the bytes read up to that point are stored into
 416.143 +     * <code>b</code> and the number of bytes read before the exception
 416.144 +     * occurred is returned. The default implementation of this method blocks
 416.145 +     * until the requested amount of input data <code>len</code> has been read,
 416.146 +     * end of file is detected, or an exception is thrown. Subclasses are encouraged
 416.147 +     * to provide a more efficient implementation of this method.
 416.148 +     *
 416.149 +     * @param      b     the buffer into which the data is read.
 416.150 +     * @param      off   the start offset in array <code>b</code>
 416.151 +     *                   at which the data is written.
 416.152 +     * @param      len   the maximum number of bytes to read.
 416.153 +     * @return     the total number of bytes read into the buffer, or
 416.154 +     *             <code>-1</code> if there is no more data because the end of
 416.155 +     *             the stream has been reached.
 416.156 +     * @exception  IOException If the first byte cannot be read for any reason
 416.157 +     * other than end of file, or if the input stream has been closed, or if
 416.158 +     * some other I/O error occurs.
 416.159 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 416.160 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 416.161 +     * <code>len</code> is negative, or <code>len</code> is greater than
 416.162 +     * <code>b.length - off</code>
 416.163 +     * @see        java.io.InputStream#read()
 416.164 +     */
 416.165 +    public int read(byte b[], int off, int len) throws IOException {
 416.166 +        if (b == null) {
 416.167 +            throw new NullPointerException();
 416.168 +        } else if (off < 0 || len < 0 || len > b.length - off) {
 416.169 +            throw new IndexOutOfBoundsException();
 416.170 +        } else if (len == 0) {
 416.171 +            return 0;
 416.172 +        }
 416.173 +
 416.174 +        int c = read();
 416.175 +        if (c == -1) {
 416.176 +            return -1;
 416.177 +        }
 416.178 +        b[off] = (byte)c;
 416.179 +
 416.180 +        int i = 1;
 416.181 +        try {
 416.182 +            for (; i < len ; i++) {
 416.183 +                c = read();
 416.184 +                if (c == -1) {
 416.185 +                    break;
 416.186 +                }
 416.187 +                b[off + i] = (byte)c;
 416.188 +            }
 416.189 +        } catch (IOException ee) {
 416.190 +        }
 416.191 +        return i;
 416.192 +    }
 416.193 +
 416.194 +    /**
 416.195 +     * Skips over and discards <code>n</code> bytes of data from this input
 416.196 +     * stream. The <code>skip</code> method may, for a variety of reasons, end
 416.197 +     * up skipping over some smaller number of bytes, possibly <code>0</code>.
 416.198 +     * This may result from any of a number of conditions; reaching end of file
 416.199 +     * before <code>n</code> bytes have been skipped is only one possibility.
 416.200 +     * The actual number of bytes skipped is returned.  If <code>n</code> is
 416.201 +     * negative, no bytes are skipped.
 416.202 +     *
 416.203 +     * <p> The <code>skip</code> method of this class creates a
 416.204 +     * byte array and then repeatedly reads into it until <code>n</code> bytes
 416.205 +     * have been read or the end of the stream has been reached. Subclasses are
 416.206 +     * encouraged to provide a more efficient implementation of this method.
 416.207 +     * For instance, the implementation may depend on the ability to seek.
 416.208 +     *
 416.209 +     * @param      n   the number of bytes to be skipped.
 416.210 +     * @return     the actual number of bytes skipped.
 416.211 +     * @exception  IOException  if the stream does not support seek,
 416.212 +     *                          or if some other I/O error occurs.
 416.213 +     */
 416.214 +    public long skip(long n) throws IOException {
 416.215 +
 416.216 +        long remaining = n;
 416.217 +        int nr;
 416.218 +        if (skipBuffer == null)
 416.219 +            skipBuffer = new byte[SKIP_BUFFER_SIZE];
 416.220 +
 416.221 +        byte[] localSkipBuffer = skipBuffer;
 416.222 +
 416.223 +        if (n <= 0) {
 416.224 +            return 0;
 416.225 +        }
 416.226 +
 416.227 +        while (remaining > 0) {
 416.228 +            nr = read(localSkipBuffer, 0,
 416.229 +                      (int) Math.min(SKIP_BUFFER_SIZE, remaining));
 416.230 +            if (nr < 0) {
 416.231 +                break;
 416.232 +            }
 416.233 +            remaining -= nr;
 416.234 +        }
 416.235 +
 416.236 +        return n - remaining;
 416.237 +    }
 416.238 +
 416.239 +    /**
 416.240 +     * Returns an estimate of the number of bytes that can be read (or
 416.241 +     * skipped over) from this input stream without blocking by the next
 416.242 +     * invocation of a method for this input stream. The next invocation
 416.243 +     * might be the same thread or another thread.  A single read or skip of this
 416.244 +     * many bytes will not block, but may read or skip fewer bytes.
 416.245 +     *
 416.246 +     * <p> Note that while some implementations of {@code InputStream} will return
 416.247 +     * the total number of bytes in the stream, many will not.  It is
 416.248 +     * never correct to use the return value of this method to allocate
 416.249 +     * a buffer intended to hold all data in this stream.
 416.250 +     *
 416.251 +     * <p> A subclass' implementation of this method may choose to throw an
 416.252 +     * {@link IOException} if this input stream has been closed by
 416.253 +     * invoking the {@link #close()} method.
 416.254 +     *
 416.255 +     * <p> The {@code available} method for class {@code InputStream} always
 416.256 +     * returns {@code 0}.
 416.257 +     *
 416.258 +     * <p> This method should be overridden by subclasses.
 416.259 +     *
 416.260 +     * @return     an estimate of the number of bytes that can be read (or skipped
 416.261 +     *             over) from this input stream without blocking or {@code 0} when
 416.262 +     *             it reaches the end of the input stream.
 416.263 +     * @exception  IOException if an I/O error occurs.
 416.264 +     */
 416.265 +    public int available() throws IOException {
 416.266 +        return 0;
 416.267 +    }
 416.268 +
 416.269 +    /**
 416.270 +     * Closes this input stream and releases any system resources associated
 416.271 +     * with the stream.
 416.272 +     *
 416.273 +     * <p> The <code>close</code> method of <code>InputStream</code> does
 416.274 +     * nothing.
 416.275 +     *
 416.276 +     * @exception  IOException  if an I/O error occurs.
 416.277 +     */
 416.278 +    public void close() throws IOException {}
 416.279 +
 416.280 +    /**
 416.281 +     * Marks the current position in this input stream. A subsequent call to
 416.282 +     * the <code>reset</code> method repositions this stream at the last marked
 416.283 +     * position so that subsequent reads re-read the same bytes.
 416.284 +     *
 416.285 +     * <p> The <code>readlimit</code> arguments tells this input stream to
 416.286 +     * allow that many bytes to be read before the mark position gets
 416.287 +     * invalidated.
 416.288 +     *
 416.289 +     * <p> The general contract of <code>mark</code> is that, if the method
 416.290 +     * <code>markSupported</code> returns <code>true</code>, the stream somehow
 416.291 +     * remembers all the bytes read after the call to <code>mark</code> and
 416.292 +     * stands ready to supply those same bytes again if and whenever the method
 416.293 +     * <code>reset</code> is called.  However, the stream is not required to
 416.294 +     * remember any data at all if more than <code>readlimit</code> bytes are
 416.295 +     * read from the stream before <code>reset</code> is called.
 416.296 +     *
 416.297 +     * <p> Marking a closed stream should not have any effect on the stream.
 416.298 +     *
 416.299 +     * <p> The <code>mark</code> method of <code>InputStream</code> does
 416.300 +     * nothing.
 416.301 +     *
 416.302 +     * @param   readlimit   the maximum limit of bytes that can be read before
 416.303 +     *                      the mark position becomes invalid.
 416.304 +     * @see     java.io.InputStream#reset()
 416.305 +     */
 416.306 +    public synchronized void mark(int readlimit) {}
 416.307 +
 416.308 +    /**
 416.309 +     * Repositions this stream to the position at the time the
 416.310 +     * <code>mark</code> method was last called on this input stream.
 416.311 +     *
 416.312 +     * <p> The general contract of <code>reset</code> is:
 416.313 +     *
 416.314 +     * <p><ul>
 416.315 +     *
 416.316 +     * <li> If the method <code>markSupported</code> returns
 416.317 +     * <code>true</code>, then:
 416.318 +     *
 416.319 +     *     <ul><li> If the method <code>mark</code> has not been called since
 416.320 +     *     the stream was created, or the number of bytes read from the stream
 416.321 +     *     since <code>mark</code> was last called is larger than the argument
 416.322 +     *     to <code>mark</code> at that last call, then an
 416.323 +     *     <code>IOException</code> might be thrown.
 416.324 +     *
 416.325 +     *     <li> If such an <code>IOException</code> is not thrown, then the
 416.326 +     *     stream is reset to a state such that all the bytes read since the
 416.327 +     *     most recent call to <code>mark</code> (or since the start of the
 416.328 +     *     file, if <code>mark</code> has not been called) will be resupplied
 416.329 +     *     to subsequent callers of the <code>read</code> method, followed by
 416.330 +     *     any bytes that otherwise would have been the next input data as of
 416.331 +     *     the time of the call to <code>reset</code>. </ul>
 416.332 +     *
 416.333 +     * <li> If the method <code>markSupported</code> returns
 416.334 +     * <code>false</code>, then:
 416.335 +     *
 416.336 +     *     <ul><li> The call to <code>reset</code> may throw an
 416.337 +     *     <code>IOException</code>.
 416.338 +     *
 416.339 +     *     <li> If an <code>IOException</code> is not thrown, then the stream
 416.340 +     *     is reset to a fixed state that depends on the particular type of the
 416.341 +     *     input stream and how it was created. The bytes that will be supplied
 416.342 +     *     to subsequent callers of the <code>read</code> method depend on the
 416.343 +     *     particular type of the input stream. </ul></ul>
 416.344 +     *
 416.345 +     * <p>The method <code>reset</code> for class <code>InputStream</code>
 416.346 +     * does nothing except throw an <code>IOException</code>.
 416.347 +     *
 416.348 +     * @exception  IOException  if this stream has not been marked or if the
 416.349 +     *               mark has been invalidated.
 416.350 +     * @see     java.io.InputStream#mark(int)
 416.351 +     * @see     java.io.IOException
 416.352 +     */
 416.353 +    public synchronized void reset() throws IOException {
 416.354 +        throw new IOException("mark/reset not supported");
 416.355 +    }
 416.356 +
 416.357 +    /**
 416.358 +     * Tests if this input stream supports the <code>mark</code> and
 416.359 +     * <code>reset</code> methods. Whether or not <code>mark</code> and
 416.360 +     * <code>reset</code> are supported is an invariant property of a
 416.361 +     * particular input stream instance. The <code>markSupported</code> method
 416.362 +     * of <code>InputStream</code> returns <code>false</code>.
 416.363 +     *
 416.364 +     * @return  <code>true</code> if this stream instance supports the mark
 416.365 +     *          and reset methods; <code>false</code> otherwise.
 416.366 +     * @see     java.io.InputStream#mark(int)
 416.367 +     * @see     java.io.InputStream#reset()
 416.368 +     */
 416.369 +    public boolean markSupported() {
 416.370 +        return false;
 416.371 +    }
 416.372 +
 416.373 +}
   417.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   417.2 +++ b/rt/emul/mini/src/main/java/java/io/PushbackInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   417.3 @@ -0,0 +1,385 @@
   417.4 +/*
   417.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   417.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   417.7 + *
   417.8 + * This code is free software; you can redistribute it and/or modify it
   417.9 + * under the terms of the GNU General Public License version 2 only, as
  417.10 + * published by the Free Software Foundation.  Oracle designates this
  417.11 + * particular file as subject to the "Classpath" exception as provided
  417.12 + * by Oracle in the LICENSE file that accompanied this code.
  417.13 + *
  417.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  417.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  417.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  417.17 + * version 2 for more details (a copy is included in the LICENSE file that
  417.18 + * accompanied this code).
  417.19 + *
  417.20 + * You should have received a copy of the GNU General Public License version
  417.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  417.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  417.23 + *
  417.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  417.25 + * or visit www.oracle.com if you need additional information or have any
  417.26 + * questions.
  417.27 + */
  417.28 +
  417.29 +package java.io;
  417.30 +
  417.31 +import org.apidesign.bck2brwsr.emul.lang.System;
  417.32 +
  417.33 +/**
  417.34 + * A <code>PushbackInputStream</code> adds
  417.35 + * functionality to another input stream, namely
  417.36 + * the  ability to "push back" or "unread"
  417.37 + * one byte. This is useful in situations where
  417.38 + * it is  convenient for a fragment of code
  417.39 + * to read an indefinite number of data bytes
  417.40 + * that  are delimited by a particular byte
  417.41 + * value; after reading the terminating byte,
  417.42 + * the  code fragment can "unread" it, so that
  417.43 + * the next read operation on the input stream
  417.44 + * will reread the byte that was pushed back.
  417.45 + * For example, bytes representing the  characters
  417.46 + * constituting an identifier might be terminated
  417.47 + * by a byte representing an  operator character;
  417.48 + * a method whose job is to read just an identifier
  417.49 + * can read until it  sees the operator and
  417.50 + * then push the operator back to be re-read.
  417.51 + *
  417.52 + * @author  David Connelly
  417.53 + * @author  Jonathan Payne
  417.54 + * @since   JDK1.0
  417.55 + */
  417.56 +public
  417.57 +class PushbackInputStream extends FilterInputStream {
  417.58 +    /**
  417.59 +     * The pushback buffer.
  417.60 +     * @since   JDK1.1
  417.61 +     */
  417.62 +    protected byte[] buf;
  417.63 +
  417.64 +    /**
  417.65 +     * The position within the pushback buffer from which the next byte will
  417.66 +     * be read.  When the buffer is empty, <code>pos</code> is equal to
  417.67 +     * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
  417.68 +     * equal to zero.
  417.69 +     *
  417.70 +     * @since   JDK1.1
  417.71 +     */
  417.72 +    protected int pos;
  417.73 +
  417.74 +    /**
  417.75 +     * Check to make sure that this stream has not been closed
  417.76 +     */
  417.77 +    private void ensureOpen() throws IOException {
  417.78 +        if (in == null)
  417.79 +            throw new IOException("Stream closed");
  417.80 +    }
  417.81 +
  417.82 +    /**
  417.83 +     * Creates a <code>PushbackInputStream</code>
  417.84 +     * with a pushback buffer of the specified <code>size</code>,
  417.85 +     * and saves its  argument, the input stream
  417.86 +     * <code>in</code>, for later use. Initially,
  417.87 +     * there is no pushed-back byte  (the field
  417.88 +     * <code>pushBack</code> is initialized to
  417.89 +     * <code>-1</code>).
  417.90 +     *
  417.91 +     * @param  in    the input stream from which bytes will be read.
  417.92 +     * @param  size  the size of the pushback buffer.
  417.93 +     * @exception IllegalArgumentException if size is <= 0
  417.94 +     * @since  JDK1.1
  417.95 +     */
  417.96 +    public PushbackInputStream(InputStream in, int size) {
  417.97 +        super(in);
  417.98 +        if (size <= 0) {
  417.99 +            throw new IllegalArgumentException("size <= 0");
 417.100 +        }
 417.101 +        this.buf = new byte[size];
 417.102 +        this.pos = size;
 417.103 +    }
 417.104 +
 417.105 +    /**
 417.106 +     * Creates a <code>PushbackInputStream</code>
 417.107 +     * and saves its  argument, the input stream
 417.108 +     * <code>in</code>, for later use. Initially,
 417.109 +     * there is no pushed-back byte  (the field
 417.110 +     * <code>pushBack</code> is initialized to
 417.111 +     * <code>-1</code>).
 417.112 +     *
 417.113 +     * @param   in   the input stream from which bytes will be read.
 417.114 +     */
 417.115 +    public PushbackInputStream(InputStream in) {
 417.116 +        this(in, 1);
 417.117 +    }
 417.118 +
 417.119 +    /**
 417.120 +     * Reads the next byte of data from this input stream. The value
 417.121 +     * byte is returned as an <code>int</code> in the range
 417.122 +     * <code>0</code> to <code>255</code>. If no byte is available
 417.123 +     * because the end of the stream has been reached, the value
 417.124 +     * <code>-1</code> is returned. This method blocks until input data
 417.125 +     * is available, the end of the stream is detected, or an exception
 417.126 +     * is thrown.
 417.127 +     *
 417.128 +     * <p> This method returns the most recently pushed-back byte, if there is
 417.129 +     * one, and otherwise calls the <code>read</code> method of its underlying
 417.130 +     * input stream and returns whatever value that method returns.
 417.131 +     *
 417.132 +     * @return     the next byte of data, or <code>-1</code> if the end of the
 417.133 +     *             stream has been reached.
 417.134 +     * @exception  IOException  if this input stream has been closed by
 417.135 +     *             invoking its {@link #close()} method,
 417.136 +     *             or an I/O error occurs.
 417.137 +     * @see        java.io.InputStream#read()
 417.138 +     */
 417.139 +    public int read() throws IOException {
 417.140 +        ensureOpen();
 417.141 +        if (pos < buf.length) {
 417.142 +            return buf[pos++] & 0xff;
 417.143 +        }
 417.144 +        return super.read();
 417.145 +    }
 417.146 +
 417.147 +    /**
 417.148 +     * Reads up to <code>len</code> bytes of data from this input stream into
 417.149 +     * an array of bytes.  This method first reads any pushed-back bytes; after
 417.150 +     * that, if fewer than <code>len</code> bytes have been read then it
 417.151 +     * reads from the underlying input stream. If <code>len</code> is not zero, the method
 417.152 +     * blocks until at least 1 byte of input is available; otherwise, no
 417.153 +     * bytes are read and <code>0</code> is returned.
 417.154 +     *
 417.155 +     * @param      b     the buffer into which the data is read.
 417.156 +     * @param      off   the start offset in the destination array <code>b</code>
 417.157 +     * @param      len   the maximum number of bytes read.
 417.158 +     * @return     the total number of bytes read into the buffer, or
 417.159 +     *             <code>-1</code> if there is no more data because the end of
 417.160 +     *             the stream has been reached.
 417.161 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 417.162 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 417.163 +     * <code>len</code> is negative, or <code>len</code> is greater than
 417.164 +     * <code>b.length - off</code>
 417.165 +     * @exception  IOException  if this input stream has been closed by
 417.166 +     *             invoking its {@link #close()} method,
 417.167 +     *             or an I/O error occurs.
 417.168 +     * @see        java.io.InputStream#read(byte[], int, int)
 417.169 +     */
 417.170 +    public int read(byte[] b, int off, int len) throws IOException {
 417.171 +        ensureOpen();
 417.172 +        if (b == null) {
 417.173 +            throw new NullPointerException();
 417.174 +        } else if (off < 0 || len < 0 || len > b.length - off) {
 417.175 +            throw new IndexOutOfBoundsException();
 417.176 +        } else if (len == 0) {
 417.177 +            return 0;
 417.178 +        }
 417.179 +
 417.180 +        int avail = buf.length - pos;
 417.181 +        if (avail > 0) {
 417.182 +            if (len < avail) {
 417.183 +                avail = len;
 417.184 +            }
 417.185 +            System.arraycopy(buf, pos, b, off, avail);
 417.186 +            pos += avail;
 417.187 +            off += avail;
 417.188 +            len -= avail;
 417.189 +        }
 417.190 +        if (len > 0) {
 417.191 +            len = super.read(b, off, len);
 417.192 +            if (len == -1) {
 417.193 +                return avail == 0 ? -1 : avail;
 417.194 +            }
 417.195 +            return avail + len;
 417.196 +        }
 417.197 +        return avail;
 417.198 +    }
 417.199 +
 417.200 +    /**
 417.201 +     * Pushes back a byte by copying it to the front of the pushback buffer.
 417.202 +     * After this method returns, the next byte to be read will have the value
 417.203 +     * <code>(byte)b</code>.
 417.204 +     *
 417.205 +     * @param      b   the <code>int</code> value whose low-order
 417.206 +     *                  byte is to be pushed back.
 417.207 +     * @exception IOException If there is not enough room in the pushback
 417.208 +     *            buffer for the byte, or this input stream has been closed by
 417.209 +     *            invoking its {@link #close()} method.
 417.210 +     */
 417.211 +    public void unread(int b) throws IOException {
 417.212 +        ensureOpen();
 417.213 +        if (pos == 0) {
 417.214 +            throw new IOException("Push back buffer is full");
 417.215 +        }
 417.216 +        buf[--pos] = (byte)b;
 417.217 +    }
 417.218 +
 417.219 +    /**
 417.220 +     * Pushes back a portion of an array of bytes by copying it to the front
 417.221 +     * of the pushback buffer.  After this method returns, the next byte to be
 417.222 +     * read will have the value <code>b[off]</code>, the byte after that will
 417.223 +     * have the value <code>b[off+1]</code>, and so forth.
 417.224 +     *
 417.225 +     * @param b the byte array to push back.
 417.226 +     * @param off the start offset of the data.
 417.227 +     * @param len the number of bytes to push back.
 417.228 +     * @exception IOException If there is not enough room in the pushback
 417.229 +     *            buffer for the specified number of bytes,
 417.230 +     *            or this input stream has been closed by
 417.231 +     *            invoking its {@link #close()} method.
 417.232 +     * @since     JDK1.1
 417.233 +     */
 417.234 +    public void unread(byte[] b, int off, int len) throws IOException {
 417.235 +        ensureOpen();
 417.236 +        if (len > pos) {
 417.237 +            throw new IOException("Push back buffer is full");
 417.238 +        }
 417.239 +        pos -= len;
 417.240 +        System.arraycopy(b, off, buf, pos, len);
 417.241 +    }
 417.242 +
 417.243 +    /**
 417.244 +     * Pushes back an array of bytes by copying it to the front of the
 417.245 +     * pushback buffer.  After this method returns, the next byte to be read
 417.246 +     * will have the value <code>b[0]</code>, the byte after that will have the
 417.247 +     * value <code>b[1]</code>, and so forth.
 417.248 +     *
 417.249 +     * @param b the byte array to push back
 417.250 +     * @exception IOException If there is not enough room in the pushback
 417.251 +     *            buffer for the specified number of bytes,
 417.252 +     *            or this input stream has been closed by
 417.253 +     *            invoking its {@link #close()} method.
 417.254 +     * @since     JDK1.1
 417.255 +     */
 417.256 +    public void unread(byte[] b) throws IOException {
 417.257 +        unread(b, 0, b.length);
 417.258 +    }
 417.259 +
 417.260 +    /**
 417.261 +     * Returns an estimate of the number of bytes that can be read (or
 417.262 +     * skipped over) from this input stream without blocking by the next
 417.263 +     * invocation of a method for this input stream. The next invocation might be
 417.264 +     * the same thread or another thread.  A single read or skip of this
 417.265 +     * many bytes will not block, but may read or skip fewer bytes.
 417.266 +     *
 417.267 +     * <p> The method returns the sum of the number of bytes that have been
 417.268 +     * pushed back and the value returned by {@link
 417.269 +     * java.io.FilterInputStream#available available}.
 417.270 +     *
 417.271 +     * @return     the number of bytes that can be read (or skipped over) from
 417.272 +     *             the input stream without blocking.
 417.273 +     * @exception  IOException  if this input stream has been closed by
 417.274 +     *             invoking its {@link #close()} method,
 417.275 +     *             or an I/O error occurs.
 417.276 +     * @see        java.io.FilterInputStream#in
 417.277 +     * @see        java.io.InputStream#available()
 417.278 +     */
 417.279 +    public int available() throws IOException {
 417.280 +        ensureOpen();
 417.281 +        int n = buf.length - pos;
 417.282 +        int avail = super.available();
 417.283 +        return n > (Integer.MAX_VALUE - avail)
 417.284 +                    ? Integer.MAX_VALUE
 417.285 +                    : n + avail;
 417.286 +    }
 417.287 +
 417.288 +    /**
 417.289 +     * Skips over and discards <code>n</code> bytes of data from this
 417.290 +     * input stream. The <code>skip</code> method may, for a variety of
 417.291 +     * reasons, end up skipping over some smaller number of bytes,
 417.292 +     * possibly zero.  If <code>n</code> is negative, no bytes are skipped.
 417.293 +     *
 417.294 +     * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
 417.295 +     * first skips over the bytes in the pushback buffer, if any.  It then
 417.296 +     * calls the <code>skip</code> method of the underlying input stream if
 417.297 +     * more bytes need to be skipped.  The actual number of bytes skipped
 417.298 +     * is returned.
 417.299 +     *
 417.300 +     * @param      n  {@inheritDoc}
 417.301 +     * @return     {@inheritDoc}
 417.302 +     * @exception  IOException  if the stream does not support seek,
 417.303 +     *            or the stream has been closed by
 417.304 +     *            invoking its {@link #close()} method,
 417.305 +     *            or an I/O error occurs.
 417.306 +     * @see        java.io.FilterInputStream#in
 417.307 +     * @see        java.io.InputStream#skip(long n)
 417.308 +     * @since      1.2
 417.309 +     */
 417.310 +    public long skip(long n) throws IOException {
 417.311 +        ensureOpen();
 417.312 +        if (n <= 0) {
 417.313 +            return 0;
 417.314 +        }
 417.315 +
 417.316 +        long pskip = buf.length - pos;
 417.317 +        if (pskip > 0) {
 417.318 +            if (n < pskip) {
 417.319 +                pskip = n;
 417.320 +            }
 417.321 +            pos += pskip;
 417.322 +            n -= pskip;
 417.323 +        }
 417.324 +        if (n > 0) {
 417.325 +            pskip += super.skip(n);
 417.326 +        }
 417.327 +        return pskip;
 417.328 +    }
 417.329 +
 417.330 +    /**
 417.331 +     * Tests if this input stream supports the <code>mark</code> and
 417.332 +     * <code>reset</code> methods, which it does not.
 417.333 +     *
 417.334 +     * @return   <code>false</code>, since this class does not support the
 417.335 +     *           <code>mark</code> and <code>reset</code> methods.
 417.336 +     * @see     java.io.InputStream#mark(int)
 417.337 +     * @see     java.io.InputStream#reset()
 417.338 +     */
 417.339 +    public boolean markSupported() {
 417.340 +        return false;
 417.341 +    }
 417.342 +
 417.343 +    /**
 417.344 +     * Marks the current position in this input stream.
 417.345 +     *
 417.346 +     * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
 417.347 +     * does nothing.
 417.348 +     *
 417.349 +     * @param   readlimit   the maximum limit of bytes that can be read before
 417.350 +     *                      the mark position becomes invalid.
 417.351 +     * @see     java.io.InputStream#reset()
 417.352 +     */
 417.353 +    public synchronized void mark(int readlimit) {
 417.354 +    }
 417.355 +
 417.356 +    /**
 417.357 +     * Repositions this stream to the position at the time the
 417.358 +     * <code>mark</code> method was last called on this input stream.
 417.359 +     *
 417.360 +     * <p> The method <code>reset</code> for class
 417.361 +     * <code>PushbackInputStream</code> does nothing except throw an
 417.362 +     * <code>IOException</code>.
 417.363 +     *
 417.364 +     * @exception  IOException  if this method is invoked.
 417.365 +     * @see     java.io.InputStream#mark(int)
 417.366 +     * @see     java.io.IOException
 417.367 +     */
 417.368 +    public synchronized void reset() throws IOException {
 417.369 +        throw new IOException("mark/reset not supported");
 417.370 +    }
 417.371 +
 417.372 +    /**
 417.373 +     * Closes this input stream and releases any system resources
 417.374 +     * associated with the stream.
 417.375 +     * Once the stream has been closed, further read(), unread(),
 417.376 +     * available(), reset(), or skip() invocations will throw an IOException.
 417.377 +     * Closing a previously closed stream has no effect.
 417.378 +     *
 417.379 +     * @exception  IOException  if an I/O error occurs.
 417.380 +     */
 417.381 +    public synchronized void close() throws IOException {
 417.382 +        if (in == null)
 417.383 +            return;
 417.384 +        in.close();
 417.385 +        in = null;
 417.386 +        buf = null;
 417.387 +    }
 417.388 +}
   418.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   418.2 +++ b/rt/emul/mini/src/main/java/java/io/Serializable.java	Wed Feb 27 11:24:58 2013 +0100
   418.3 @@ -0,0 +1,170 @@
   418.4 +/*
   418.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
   418.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   418.7 + *
   418.8 + * This code is free software; you can redistribute it and/or modify it
   418.9 + * under the terms of the GNU General Public License version 2 only, as
  418.10 + * published by the Free Software Foundation.  Oracle designates this
  418.11 + * particular file as subject to the "Classpath" exception as provided
  418.12 + * by Oracle in the LICENSE file that accompanied this code.
  418.13 + *
  418.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  418.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  418.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  418.17 + * version 2 for more details (a copy is included in the LICENSE file that
  418.18 + * accompanied this code).
  418.19 + *
  418.20 + * You should have received a copy of the GNU General Public License version
  418.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  418.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  418.23 + *
  418.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  418.25 + * or visit www.oracle.com if you need additional information or have any
  418.26 + * questions.
  418.27 + */
  418.28 +
  418.29 +package java.io;
  418.30 +
  418.31 +/**
  418.32 + * Serializability of a class is enabled by the class implementing the
  418.33 + * java.io.Serializable interface. Classes that do not implement this
  418.34 + * interface will not have any of their state serialized or
  418.35 + * deserialized.  All subtypes of a serializable class are themselves
  418.36 + * serializable.  The serialization interface has no methods or fields
  418.37 + * and serves only to identify the semantics of being serializable. <p>
  418.38 + *
  418.39 + * To allow subtypes of non-serializable classes to be serialized, the
  418.40 + * subtype may assume responsibility for saving and restoring the
  418.41 + * state of the supertype's public, protected, and (if accessible)
  418.42 + * package fields.  The subtype may assume this responsibility only if
  418.43 + * the class it extends has an accessible no-arg constructor to
  418.44 + * initialize the class's state.  It is an error to declare a class
  418.45 + * Serializable if this is not the case.  The error will be detected at
  418.46 + * runtime. <p>
  418.47 + *
  418.48 + * During deserialization, the fields of non-serializable classes will
  418.49 + * be initialized using the public or protected no-arg constructor of
  418.50 + * the class.  A no-arg constructor must be accessible to the subclass
  418.51 + * that is serializable.  The fields of serializable subclasses will
  418.52 + * be restored from the stream. <p>
  418.53 + *
  418.54 + * When traversing a graph, an object may be encountered that does not
  418.55 + * support the Serializable interface. In this case the
  418.56 + * NotSerializableException will be thrown and will identify the class
  418.57 + * of the non-serializable object. <p>
  418.58 + *
  418.59 + * Classes that require special handling during the serialization and
  418.60 + * deserialization process must implement special methods with these exact
  418.61 + * signatures: <p>
  418.62 + *
  418.63 + * <PRE>
  418.64 + * private void writeObject(java.io.ObjectOutputStream out)
  418.65 + *     throws IOException
  418.66 + * private void readObject(java.io.ObjectInputStream in)
  418.67 + *     throws IOException, ClassNotFoundException;
  418.68 + * private void readObjectNoData()
  418.69 + *     throws ObjectStreamException;
  418.70 + * </PRE>
  418.71 + *
  418.72 + * <p>The writeObject method is responsible for writing the state of the
  418.73 + * object for its particular class so that the corresponding
  418.74 + * readObject method can restore it.  The default mechanism for saving
  418.75 + * the Object's fields can be invoked by calling
  418.76 + * out.defaultWriteObject. The method does not need to concern
  418.77 + * itself with the state belonging to its superclasses or subclasses.
  418.78 + * State is saved by writing the individual fields to the
  418.79 + * ObjectOutputStream using the writeObject method or by using the
  418.80 + * methods for primitive data types supported by DataOutput.
  418.81 + *
  418.82 + * <p>The readObject method is responsible for reading from the stream and
  418.83 + * restoring the classes fields. It may call in.defaultReadObject to invoke
  418.84 + * the default mechanism for restoring the object's non-static and
  418.85 + * non-transient fields.  The defaultReadObject method uses information in
  418.86 + * the stream to assign the fields of the object saved in the stream with the
  418.87 + * correspondingly named fields in the current object.  This handles the case
  418.88 + * when the class has evolved to add new fields. The method does not need to
  418.89 + * concern itself with the state belonging to its superclasses or subclasses.
  418.90 + * State is saved by writing the individual fields to the
  418.91 + * ObjectOutputStream using the writeObject method or by using the
  418.92 + * methods for primitive data types supported by DataOutput.
  418.93 + *
  418.94 + * <p>The readObjectNoData method is responsible for initializing the state of
  418.95 + * the object for its particular class in the event that the serialization
  418.96 + * stream does not list the given class as a superclass of the object being
  418.97 + * deserialized.  This may occur in cases where the receiving party uses a
  418.98 + * different version of the deserialized instance's class than the sending
  418.99 + * party, and the receiver's version extends classes that are not extended by
 418.100 + * the sender's version.  This may also occur if the serialization stream has
 418.101 + * been tampered; hence, readObjectNoData is useful for initializing
 418.102 + * deserialized objects properly despite a "hostile" or incomplete source
 418.103 + * stream.
 418.104 + *
 418.105 + * <p>Serializable classes that need to designate an alternative object to be
 418.106 + * used when writing an object to the stream should implement this
 418.107 + * special method with the exact signature: <p>
 418.108 + *
 418.109 + * <PRE>
 418.110 + * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
 418.111 + * </PRE><p>
 418.112 + *
 418.113 + * This writeReplace method is invoked by serialization if the method
 418.114 + * exists and it would be accessible from a method defined within the
 418.115 + * class of the object being serialized. Thus, the method can have private,
 418.116 + * protected and package-private access. Subclass access to this method
 418.117 + * follows java accessibility rules. <p>
 418.118 + *
 418.119 + * Classes that need to designate a replacement when an instance of it
 418.120 + * is read from the stream should implement this special method with the
 418.121 + * exact signature.<p>
 418.122 + *
 418.123 + * <PRE>
 418.124 + * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
 418.125 + * </PRE><p>
 418.126 + *
 418.127 + * This readResolve method follows the same invocation rules and
 418.128 + * accessibility rules as writeReplace.<p>
 418.129 + *
 418.130 + * The serialization runtime associates with each serializable class a version
 418.131 + * number, called a serialVersionUID, which is used during deserialization to
 418.132 + * verify that the sender and receiver of a serialized object have loaded
 418.133 + * classes for that object that are compatible with respect to serialization.
 418.134 + * If the receiver has loaded a class for the object that has a different
 418.135 + * serialVersionUID than that of the corresponding sender's class, then
 418.136 + * deserialization will result in an {@link InvalidClassException}.  A
 418.137 + * serializable class can declare its own serialVersionUID explicitly by
 418.138 + * declaring a field named <code>"serialVersionUID"</code> that must be static,
 418.139 + * final, and of type <code>long</code>:<p>
 418.140 + *
 418.141 + * <PRE>
 418.142 + * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
 418.143 + * </PRE>
 418.144 + *
 418.145 + * If a serializable class does not explicitly declare a serialVersionUID, then
 418.146 + * the serialization runtime will calculate a default serialVersionUID value
 418.147 + * for that class based on various aspects of the class, as described in the
 418.148 + * Java(TM) Object Serialization Specification.  However, it is <em>strongly
 418.149 + * recommended</em> that all serializable classes explicitly declare
 418.150 + * serialVersionUID values, since the default serialVersionUID computation is
 418.151 + * highly sensitive to class details that may vary depending on compiler
 418.152 + * implementations, and can thus result in unexpected
 418.153 + * <code>InvalidClassException</code>s during deserialization.  Therefore, to
 418.154 + * guarantee a consistent serialVersionUID value across different java compiler
 418.155 + * implementations, a serializable class must declare an explicit
 418.156 + * serialVersionUID value.  It is also strongly advised that explicit
 418.157 + * serialVersionUID declarations use the <code>private</code> modifier where
 418.158 + * possible, since such declarations apply only to the immediately declaring
 418.159 + * class--serialVersionUID fields are not useful as inherited members. Array
 418.160 + * classes cannot declare an explicit serialVersionUID, so they always have
 418.161 + * the default computed value, but the requirement for matching
 418.162 + * serialVersionUID values is waived for array classes.
 418.163 + *
 418.164 + * @author  unascribed
 418.165 + * @see java.io.ObjectOutputStream
 418.166 + * @see java.io.ObjectInputStream
 418.167 + * @see java.io.ObjectOutput
 418.168 + * @see java.io.ObjectInput
 418.169 + * @see java.io.Externalizable
 418.170 + * @since   JDK1.1
 418.171 + */
 418.172 +public interface Serializable {
 418.173 +}
   419.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   419.2 +++ b/rt/emul/mini/src/main/java/java/io/UTFDataFormatException.java	Wed Feb 27 11:24:58 2013 +0100
   419.3 @@ -0,0 +1,69 @@
   419.4 +/*
   419.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   419.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   419.7 + *
   419.8 + * This code is free software; you can redistribute it and/or modify it
   419.9 + * under the terms of the GNU General Public License version 2 only, as
  419.10 + * published by the Free Software Foundation.  Oracle designates this
  419.11 + * particular file as subject to the "Classpath" exception as provided
  419.12 + * by Oracle in the LICENSE file that accompanied this code.
  419.13 + *
  419.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  419.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  419.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  419.17 + * version 2 for more details (a copy is included in the LICENSE file that
  419.18 + * accompanied this code).
  419.19 + *
  419.20 + * You should have received a copy of the GNU General Public License version
  419.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  419.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  419.23 + *
  419.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  419.25 + * or visit www.oracle.com if you need additional information or have any
  419.26 + * questions.
  419.27 + */
  419.28 +
  419.29 +package java.io;
  419.30 +
  419.31 +/**
  419.32 + * Signals that a malformed string in
  419.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
  419.34 + * format has been read in a data
  419.35 + * input stream or by any class that implements the data input
  419.36 + * interface.
  419.37 + * See the
  419.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
  419.39 + * class description for the format in
  419.40 + * which modified UTF-8 strings are read and written.
  419.41 + *
  419.42 + * @author  Frank Yellin
  419.43 + * @see     java.io.DataInput
  419.44 + * @see     java.io.DataInputStream#readUTF(java.io.DataInput)
  419.45 + * @see     java.io.IOException
  419.46 + * @since   JDK1.0
  419.47 + */
  419.48 +public
  419.49 +class UTFDataFormatException extends IOException {
  419.50 +    private static final long serialVersionUID = 420743449228280612L;
  419.51 +
  419.52 +    /**
  419.53 +     * Constructs a <code>UTFDataFormatException</code> with
  419.54 +     * <code>null</code> as its error detail message.
  419.55 +     */
  419.56 +    public UTFDataFormatException() {
  419.57 +        super();
  419.58 +    }
  419.59 +
  419.60 +    /**
  419.61 +     * Constructs a <code>UTFDataFormatException</code> with the
  419.62 +     * specified detail message. The string <code>s</code> can be
  419.63 +     * retrieved later by the
  419.64 +     * <code>{@link java.lang.Throwable#getMessage}</code>
  419.65 +     * method of class <code>java.lang.Throwable</code>.
  419.66 +     *
  419.67 +     * @param   s   the detail message.
  419.68 +     */
  419.69 +    public UTFDataFormatException(String s) {
  419.70 +        super(s);
  419.71 +    }
  419.72 +}
   420.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   420.2 +++ b/rt/emul/mini/src/main/java/java/io/UnsupportedEncodingException.java	Wed Feb 27 11:24:58 2013 +0100
   420.3 @@ -0,0 +1,52 @@
   420.4 +/*
   420.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   420.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   420.7 + *
   420.8 + * This code is free software; you can redistribute it and/or modify it
   420.9 + * under the terms of the GNU General Public License version 2 only, as
  420.10 + * published by the Free Software Foundation.  Oracle designates this
  420.11 + * particular file as subject to the "Classpath" exception as provided
  420.12 + * by Oracle in the LICENSE file that accompanied this code.
  420.13 + *
  420.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  420.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  420.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  420.17 + * version 2 for more details (a copy is included in the LICENSE file that
  420.18 + * accompanied this code).
  420.19 + *
  420.20 + * You should have received a copy of the GNU General Public License version
  420.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  420.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  420.23 + *
  420.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  420.25 + * or visit www.oracle.com if you need additional information or have any
  420.26 + * questions.
  420.27 + */
  420.28 +package java.io;
  420.29 +
  420.30 +/**
  420.31 + * The Character Encoding is not supported.
  420.32 + *
  420.33 + * @author  Asmus Freytag
  420.34 + * @since   JDK1.1
  420.35 + */
  420.36 +public class UnsupportedEncodingException
  420.37 +    extends IOException
  420.38 +{
  420.39 +    private static final long serialVersionUID = -4274276298326136670L;
  420.40 +
  420.41 +    /**
  420.42 +     * Constructs an UnsupportedEncodingException without a detail message.
  420.43 +     */
  420.44 +    public UnsupportedEncodingException() {
  420.45 +        super();
  420.46 +    }
  420.47 +
  420.48 +    /**
  420.49 +     * Constructs an UnsupportedEncodingException with a detail message.
  420.50 +     * @param s Describes the reason for the exception.
  420.51 +     */
  420.52 +    public UnsupportedEncodingException(String s) {
  420.53 +        super(s);
  420.54 +    }
  420.55 +}
   421.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   421.2 +++ b/rt/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java	Wed Feb 27 11:24:58 2013 +0100
   421.3 @@ -0,0 +1,1414 @@
   421.4 +/*
   421.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   421.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   421.7 + *
   421.8 + * This code is free software; you can redistribute it and/or modify it
   421.9 + * under the terms of the GNU General Public License version 2 only, as
  421.10 + * published by the Free Software Foundation.  Oracle designates this
  421.11 + * particular file as subject to the "Classpath" exception as provided
  421.12 + * by Oracle in the LICENSE file that accompanied this code.
  421.13 + *
  421.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  421.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  421.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  421.17 + * version 2 for more details (a copy is included in the LICENSE file that
  421.18 + * accompanied this code).
  421.19 + *
  421.20 + * You should have received a copy of the GNU General Public License version
  421.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  421.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  421.23 + *
  421.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  421.25 + * or visit www.oracle.com if you need additional information or have any
  421.26 + * questions.
  421.27 + */
  421.28 +
  421.29 +package java.lang;
  421.30 +
  421.31 +import org.apidesign.bck2brwsr.emul.lang.System;
  421.32 +
  421.33 +/**
  421.34 + * A mutable sequence of characters.
  421.35 + * <p>
  421.36 + * Implements a modifiable string. At any point in time it contains some
  421.37 + * particular sequence of characters, but the length and content of the
  421.38 + * sequence can be changed through certain method calls.
  421.39 + *
  421.40 + * @author      Michael McCloskey
  421.41 + * @author      Martin Buchholz
  421.42 + * @author      Ulf Zibis
  421.43 + * @since       1.5
  421.44 + */
  421.45 +abstract class AbstractStringBuilder implements Appendable, CharSequence {
  421.46 +    /**
  421.47 +     * The value is used for character storage.
  421.48 +     */
  421.49 +    char[] value;
  421.50 +
  421.51 +    /**
  421.52 +     * The count is the number of characters used.
  421.53 +     */
  421.54 +    int count;
  421.55 +
  421.56 +    /**
  421.57 +     * This no-arg constructor is necessary for serialization of subclasses.
  421.58 +     */
  421.59 +    AbstractStringBuilder() {
  421.60 +    }
  421.61 +
  421.62 +    /**
  421.63 +     * Creates an AbstractStringBuilder of the specified capacity.
  421.64 +     */
  421.65 +    AbstractStringBuilder(int capacity) {
  421.66 +        value = new char[capacity];
  421.67 +    }
  421.68 +
  421.69 +    /**
  421.70 +     * Returns the length (character count).
  421.71 +     *
  421.72 +     * @return  the length of the sequence of characters currently
  421.73 +     *          represented by this object
  421.74 +     */
  421.75 +    public int length() {
  421.76 +        return count;
  421.77 +    }
  421.78 +
  421.79 +    /**
  421.80 +     * Returns the current capacity. The capacity is the amount of storage
  421.81 +     * available for newly inserted characters, beyond which an allocation
  421.82 +     * will occur.
  421.83 +     *
  421.84 +     * @return  the current capacity
  421.85 +     */
  421.86 +    public int capacity() {
  421.87 +        return value.length;
  421.88 +    }
  421.89 +
  421.90 +    /**
  421.91 +     * Ensures that the capacity is at least equal to the specified minimum.
  421.92 +     * If the current capacity is less than the argument, then a new internal
  421.93 +     * array is allocated with greater capacity. The new capacity is the
  421.94 +     * larger of:
  421.95 +     * <ul>
  421.96 +     * <li>The <code>minimumCapacity</code> argument.
  421.97 +     * <li>Twice the old capacity, plus <code>2</code>.
  421.98 +     * </ul>
  421.99 +     * If the <code>minimumCapacity</code> argument is nonpositive, this
 421.100 +     * method takes no action and simply returns.
 421.101 +     *
 421.102 +     * @param   minimumCapacity   the minimum desired capacity.
 421.103 +     */
 421.104 +    public void ensureCapacity(int minimumCapacity) {
 421.105 +        if (minimumCapacity > 0)
 421.106 +            ensureCapacityInternal(minimumCapacity);
 421.107 +    }
 421.108 +
 421.109 +    /**
 421.110 +     * This method has the same contract as ensureCapacity, but is
 421.111 +     * never synchronized.
 421.112 +     */
 421.113 +    private void ensureCapacityInternal(int minimumCapacity) {
 421.114 +        // overflow-conscious code
 421.115 +        if (minimumCapacity - value.length > 0)
 421.116 +            expandCapacity(minimumCapacity);
 421.117 +    }
 421.118 +
 421.119 +    /**
 421.120 +     * This implements the expansion semantics of ensureCapacity with no
 421.121 +     * size check or synchronization.
 421.122 +     */
 421.123 +    void expandCapacity(int minimumCapacity) {
 421.124 +        int newCapacity = value.length * 2 + 2;
 421.125 +        if (newCapacity - minimumCapacity < 0)
 421.126 +            newCapacity = minimumCapacity;
 421.127 +        if (newCapacity < 0) {
 421.128 +            if (minimumCapacity < 0) // overflow
 421.129 +                throw new OutOfMemoryError();
 421.130 +            newCapacity = Integer.MAX_VALUE;
 421.131 +        }
 421.132 +        value = copyOf(value, newCapacity);
 421.133 +    }
 421.134 +
 421.135 +    /**
 421.136 +     * Attempts to reduce storage used for the character sequence.
 421.137 +     * If the buffer is larger than necessary to hold its current sequence of
 421.138 +     * characters, then it may be resized to become more space efficient.
 421.139 +     * Calling this method may, but is not required to, affect the value
 421.140 +     * returned by a subsequent call to the {@link #capacity()} method.
 421.141 +     */
 421.142 +    public void trimToSize() {
 421.143 +        if (count < value.length) {
 421.144 +            value = copyOf(value, count);
 421.145 +        }
 421.146 +    }
 421.147 +
 421.148 +    /**
 421.149 +     * Sets the length of the character sequence.
 421.150 +     * The sequence is changed to a new character sequence
 421.151 +     * whose length is specified by the argument. For every nonnegative
 421.152 +     * index <i>k</i> less than <code>newLength</code>, the character at
 421.153 +     * index <i>k</i> in the new character sequence is the same as the
 421.154 +     * character at index <i>k</i> in the old sequence if <i>k</i> is less
 421.155 +     * than the length of the old character sequence; otherwise, it is the
 421.156 +     * null character <code>'&#92;u0000'</code>.
 421.157 +     *
 421.158 +     * In other words, if the <code>newLength</code> argument is less than
 421.159 +     * the current length, the length is changed to the specified length.
 421.160 +     * <p>
 421.161 +     * If the <code>newLength</code> argument is greater than or equal
 421.162 +     * to the current length, sufficient null characters
 421.163 +     * (<code>'&#92;u0000'</code>) are appended so that
 421.164 +     * length becomes the <code>newLength</code> argument.
 421.165 +     * <p>
 421.166 +     * The <code>newLength</code> argument must be greater than or equal
 421.167 +     * to <code>0</code>.
 421.168 +     *
 421.169 +     * @param      newLength   the new length
 421.170 +     * @throws     IndexOutOfBoundsException  if the
 421.171 +     *               <code>newLength</code> argument is negative.
 421.172 +     */
 421.173 +    public void setLength(int newLength) {
 421.174 +        if (newLength < 0)
 421.175 +            throw new StringIndexOutOfBoundsException(newLength);
 421.176 +        ensureCapacityInternal(newLength);
 421.177 +
 421.178 +        if (count < newLength) {
 421.179 +            for (; count < newLength; count++)
 421.180 +                value[count] = '\0';
 421.181 +        } else {
 421.182 +            count = newLength;
 421.183 +        }
 421.184 +    }
 421.185 +
 421.186 +    /**
 421.187 +     * Returns the <code>char</code> value in this sequence at the specified index.
 421.188 +     * The first <code>char</code> value is at index <code>0</code>, the next at index
 421.189 +     * <code>1</code>, and so on, as in array indexing.
 421.190 +     * <p>
 421.191 +     * The index argument must be greater than or equal to
 421.192 +     * <code>0</code>, and less than the length of this sequence.
 421.193 +     *
 421.194 +     * <p>If the <code>char</code> value specified by the index is a
 421.195 +     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 421.196 +     * value is returned.
 421.197 +     *
 421.198 +     * @param      index   the index of the desired <code>char</code> value.
 421.199 +     * @return     the <code>char</code> value at the specified index.
 421.200 +     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 421.201 +     *             negative or greater than or equal to <code>length()</code>.
 421.202 +     */
 421.203 +    public char charAt(int index) {
 421.204 +        if ((index < 0) || (index >= count))
 421.205 +            throw new StringIndexOutOfBoundsException(index);
 421.206 +        return value[index];
 421.207 +    }
 421.208 +
 421.209 +    /**
 421.210 +     * Returns the character (Unicode code point) at the specified
 421.211 +     * index. The index refers to <code>char</code> values
 421.212 +     * (Unicode code units) and ranges from <code>0</code> to
 421.213 +     * {@link #length()}<code> - 1</code>.
 421.214 +     *
 421.215 +     * <p> If the <code>char</code> value specified at the given index
 421.216 +     * is in the high-surrogate range, the following index is less
 421.217 +     * than the length of this sequence, and the
 421.218 +     * <code>char</code> value at the following index is in the
 421.219 +     * low-surrogate range, then the supplementary code point
 421.220 +     * corresponding to this surrogate pair is returned. Otherwise,
 421.221 +     * the <code>char</code> value at the given index is returned.
 421.222 +     *
 421.223 +     * @param      index the index to the <code>char</code> values
 421.224 +     * @return     the code point value of the character at the
 421.225 +     *             <code>index</code>
 421.226 +     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 421.227 +     *             argument is negative or not less than the length of this
 421.228 +     *             sequence.
 421.229 +     */
 421.230 +    public int codePointAt(int index) {
 421.231 +        if ((index < 0) || (index >= count)) {
 421.232 +            throw new StringIndexOutOfBoundsException(index);
 421.233 +        }
 421.234 +        return Character.codePointAt(value, index);
 421.235 +    }
 421.236 +
 421.237 +    /**
 421.238 +     * Returns the character (Unicode code point) before the specified
 421.239 +     * index. The index refers to <code>char</code> values
 421.240 +     * (Unicode code units) and ranges from <code>1</code> to {@link
 421.241 +     * #length()}.
 421.242 +     *
 421.243 +     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 421.244 +     * is in the low-surrogate range, <code>(index - 2)</code> is not
 421.245 +     * negative, and the <code>char</code> value at <code>(index -
 421.246 +     * 2)</code> is in the high-surrogate range, then the
 421.247 +     * supplementary code point value of the surrogate pair is
 421.248 +     * returned. If the <code>char</code> value at <code>index -
 421.249 +     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 421.250 +     * surrogate value is returned.
 421.251 +     *
 421.252 +     * @param     index the index following the code point that should be returned
 421.253 +     * @return    the Unicode code point value before the given index.
 421.254 +     * @exception IndexOutOfBoundsException if the <code>index</code>
 421.255 +     *            argument is less than 1 or greater than the length
 421.256 +     *            of this sequence.
 421.257 +     */
 421.258 +    public int codePointBefore(int index) {
 421.259 +        int i = index - 1;
 421.260 +        if ((i < 0) || (i >= count)) {
 421.261 +            throw new StringIndexOutOfBoundsException(index);
 421.262 +        }
 421.263 +        return Character.codePointBefore(value, index);
 421.264 +    }
 421.265 +
 421.266 +    /**
 421.267 +     * Returns the number of Unicode code points in the specified text
 421.268 +     * range of this sequence. The text range begins at the specified
 421.269 +     * <code>beginIndex</code> and extends to the <code>char</code> at
 421.270 +     * index <code>endIndex - 1</code>. Thus the length (in
 421.271 +     * <code>char</code>s) of the text range is
 421.272 +     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 421.273 +     * this sequence count as one code point each.
 421.274 +     *
 421.275 +     * @param beginIndex the index to the first <code>char</code> of
 421.276 +     * the text range.
 421.277 +     * @param endIndex the index after the last <code>char</code> of
 421.278 +     * the text range.
 421.279 +     * @return the number of Unicode code points in the specified text
 421.280 +     * range
 421.281 +     * @exception IndexOutOfBoundsException if the
 421.282 +     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 421.283 +     * is larger than the length of this sequence, or
 421.284 +     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 421.285 +     */
 421.286 +    public int codePointCount(int beginIndex, int endIndex) {
 421.287 +        if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
 421.288 +            throw new IndexOutOfBoundsException();
 421.289 +        }
 421.290 +        return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
 421.291 +    }
 421.292 +
 421.293 +    /**
 421.294 +     * Returns the index within this sequence that is offset from the
 421.295 +     * given <code>index</code> by <code>codePointOffset</code> code
 421.296 +     * points. Unpaired surrogates within the text range given by
 421.297 +     * <code>index</code> and <code>codePointOffset</code> count as
 421.298 +     * one code point each.
 421.299 +     *
 421.300 +     * @param index the index to be offset
 421.301 +     * @param codePointOffset the offset in code points
 421.302 +     * @return the index within this sequence
 421.303 +     * @exception IndexOutOfBoundsException if <code>index</code>
 421.304 +     *   is negative or larger then the length of this sequence,
 421.305 +     *   or if <code>codePointOffset</code> is positive and the subsequence
 421.306 +     *   starting with <code>index</code> has fewer than
 421.307 +     *   <code>codePointOffset</code> code points,
 421.308 +     *   or if <code>codePointOffset</code> is negative and the subsequence
 421.309 +     *   before <code>index</code> has fewer than the absolute value of
 421.310 +     *   <code>codePointOffset</code> code points.
 421.311 +     */
 421.312 +    public int offsetByCodePoints(int index, int codePointOffset) {
 421.313 +        if (index < 0 || index > count) {
 421.314 +            throw new IndexOutOfBoundsException();
 421.315 +        }
 421.316 +        return Character.offsetByCodePointsImpl(value, 0, count,
 421.317 +                                                index, codePointOffset);
 421.318 +    }
 421.319 +
 421.320 +    /**
 421.321 +     * Characters are copied from this sequence into the
 421.322 +     * destination character array <code>dst</code>. The first character to
 421.323 +     * be copied is at index <code>srcBegin</code>; the last character to
 421.324 +     * be copied is at index <code>srcEnd-1</code>. The total number of
 421.325 +     * characters to be copied is <code>srcEnd-srcBegin</code>. The
 421.326 +     * characters are copied into the subarray of <code>dst</code> starting
 421.327 +     * at index <code>dstBegin</code> and ending at index:
 421.328 +     * <p><blockquote><pre>
 421.329 +     * dstbegin + (srcEnd-srcBegin) - 1
 421.330 +     * </pre></blockquote>
 421.331 +     *
 421.332 +     * @param      srcBegin   start copying at this offset.
 421.333 +     * @param      srcEnd     stop copying at this offset.
 421.334 +     * @param      dst        the array to copy the data into.
 421.335 +     * @param      dstBegin   offset into <code>dst</code>.
 421.336 +     * @throws     NullPointerException if <code>dst</code> is
 421.337 +     *             <code>null</code>.
 421.338 +     * @throws     IndexOutOfBoundsException  if any of the following is true:
 421.339 +     *             <ul>
 421.340 +     *             <li><code>srcBegin</code> is negative
 421.341 +     *             <li><code>dstBegin</code> is negative
 421.342 +     *             <li>the <code>srcBegin</code> argument is greater than
 421.343 +     *             the <code>srcEnd</code> argument.
 421.344 +     *             <li><code>srcEnd</code> is greater than
 421.345 +     *             <code>this.length()</code>.
 421.346 +     *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
 421.347 +     *             <code>dst.length</code>
 421.348 +     *             </ul>
 421.349 +     */
 421.350 +    public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
 421.351 +    {
 421.352 +        if (srcBegin < 0)
 421.353 +            throw new StringIndexOutOfBoundsException(srcBegin);
 421.354 +        if ((srcEnd < 0) || (srcEnd > count))
 421.355 +            throw new StringIndexOutOfBoundsException(srcEnd);
 421.356 +        if (srcBegin > srcEnd)
 421.357 +            throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
 421.358 +        System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
 421.359 +    }
 421.360 +
 421.361 +    /**
 421.362 +     * The character at the specified index is set to <code>ch</code>. This
 421.363 +     * sequence is altered to represent a new character sequence that is
 421.364 +     * identical to the old character sequence, except that it contains the
 421.365 +     * character <code>ch</code> at position <code>index</code>.
 421.366 +     * <p>
 421.367 +     * The index argument must be greater than or equal to
 421.368 +     * <code>0</code>, and less than the length of this sequence.
 421.369 +     *
 421.370 +     * @param      index   the index of the character to modify.
 421.371 +     * @param      ch      the new character.
 421.372 +     * @throws     IndexOutOfBoundsException  if <code>index</code> is
 421.373 +     *             negative or greater than or equal to <code>length()</code>.
 421.374 +     */
 421.375 +    public void setCharAt(int index, char ch) {
 421.376 +        if ((index < 0) || (index >= count))
 421.377 +            throw new StringIndexOutOfBoundsException(index);
 421.378 +        value[index] = ch;
 421.379 +    }
 421.380 +
 421.381 +    /**
 421.382 +     * Appends the string representation of the {@code Object} argument.
 421.383 +     * <p>
 421.384 +     * The overall effect is exactly as if the argument were converted
 421.385 +     * to a string by the method {@link String#valueOf(Object)},
 421.386 +     * and the characters of that string were then
 421.387 +     * {@link #append(String) appended} to this character sequence.
 421.388 +     *
 421.389 +     * @param   obj   an {@code Object}.
 421.390 +     * @return  a reference to this object.
 421.391 +     */
 421.392 +    public AbstractStringBuilder append(Object obj) {
 421.393 +        return append(String.valueOf(obj));
 421.394 +    }
 421.395 +
 421.396 +    /**
 421.397 +     * Appends the specified string to this character sequence.
 421.398 +     * <p>
 421.399 +     * The characters of the {@code String} argument are appended, in
 421.400 +     * order, increasing the length of this sequence by the length of the
 421.401 +     * argument. If {@code str} is {@code null}, then the four
 421.402 +     * characters {@code "null"} are appended.
 421.403 +     * <p>
 421.404 +     * Let <i>n</i> be the length of this character sequence just prior to
 421.405 +     * execution of the {@code append} method. Then the character at
 421.406 +     * index <i>k</i> in the new character sequence is equal to the character
 421.407 +     * at index <i>k</i> in the old character sequence, if <i>k</i> is less
 421.408 +     * than <i>n</i>; otherwise, it is equal to the character at index
 421.409 +     * <i>k-n</i> in the argument {@code str}.
 421.410 +     *
 421.411 +     * @param   str   a string.
 421.412 +     * @return  a reference to this object.
 421.413 +     */
 421.414 +    public AbstractStringBuilder append(String str) {
 421.415 +        if (str == null) str = "null";
 421.416 +        int len = str.length();
 421.417 +        ensureCapacityInternal(count + len);
 421.418 +        str.getChars(0, len, value, count);
 421.419 +        count += len;
 421.420 +        return this;
 421.421 +    }
 421.422 +
 421.423 +    // Documentation in subclasses because of synchro difference
 421.424 +    public AbstractStringBuilder append(StringBuffer sb) {
 421.425 +        if (sb == null)
 421.426 +            return append("null");
 421.427 +        int len = sb.length();
 421.428 +        ensureCapacityInternal(count + len);
 421.429 +        sb.getChars(0, len, value, count);
 421.430 +        count += len;
 421.431 +        return this;
 421.432 +    }
 421.433 +
 421.434 +    // Documentation in subclasses because of synchro difference
 421.435 +    public AbstractStringBuilder append(CharSequence s) {
 421.436 +        if (s == null)
 421.437 +            s = "null";
 421.438 +        if (s instanceof String)
 421.439 +            return this.append((String)s);
 421.440 +        if (s instanceof StringBuffer)
 421.441 +            return this.append((StringBuffer)s);
 421.442 +        return this.append(s, 0, s.length());
 421.443 +    }
 421.444 +
 421.445 +    /**
 421.446 +     * Appends a subsequence of the specified {@code CharSequence} to this
 421.447 +     * sequence.
 421.448 +     * <p>
 421.449 +     * Characters of the argument {@code s}, starting at
 421.450 +     * index {@code start}, are appended, in order, to the contents of
 421.451 +     * this sequence up to the (exclusive) index {@code end}. The length
 421.452 +     * of this sequence is increased by the value of {@code end - start}.
 421.453 +     * <p>
 421.454 +     * Let <i>n</i> be the length of this character sequence just prior to
 421.455 +     * execution of the {@code append} method. Then the character at
 421.456 +     * index <i>k</i> in this character sequence becomes equal to the
 421.457 +     * character at index <i>k</i> in this sequence, if <i>k</i> is less than
 421.458 +     * <i>n</i>; otherwise, it is equal to the character at index
 421.459 +     * <i>k+start-n</i> in the argument {@code s}.
 421.460 +     * <p>
 421.461 +     * If {@code s} is {@code null}, then this method appends
 421.462 +     * characters as if the s parameter was a sequence containing the four
 421.463 +     * characters {@code "null"}.
 421.464 +     *
 421.465 +     * @param   s the sequence to append.
 421.466 +     * @param   start   the starting index of the subsequence to be appended.
 421.467 +     * @param   end     the end index of the subsequence to be appended.
 421.468 +     * @return  a reference to this object.
 421.469 +     * @throws     IndexOutOfBoundsException if
 421.470 +     *             {@code start} is negative, or
 421.471 +     *             {@code start} is greater than {@code end} or
 421.472 +     *             {@code end} is greater than {@code s.length()}
 421.473 +     */
 421.474 +    public AbstractStringBuilder append(CharSequence s, int start, int end) {
 421.475 +        if (s == null)
 421.476 +            s = "null";
 421.477 +        if ((start < 0) || (start > end) || (end > s.length()))
 421.478 +            throw new IndexOutOfBoundsException(
 421.479 +                "start " + start + ", end " + end + ", s.length() "
 421.480 +                + s.length());
 421.481 +        int len = end - start;
 421.482 +        ensureCapacityInternal(count + len);
 421.483 +        for (int i = start, j = count; i < end; i++, j++)
 421.484 +            value[j] = s.charAt(i);
 421.485 +        count += len;
 421.486 +        return this;
 421.487 +    }
 421.488 +
 421.489 +    /**
 421.490 +     * Appends the string representation of the {@code char} array
 421.491 +     * argument to this sequence.
 421.492 +     * <p>
 421.493 +     * The characters of the array argument are appended, in order, to
 421.494 +     * the contents of this sequence. The length of this sequence
 421.495 +     * increases by the length of the argument.
 421.496 +     * <p>
 421.497 +     * The overall effect is exactly as if the argument were converted
 421.498 +     * to a string by the method {@link String#valueOf(char[])},
 421.499 +     * and the characters of that string were then
 421.500 +     * {@link #append(String) appended} to this character sequence.
 421.501 +     *
 421.502 +     * @param   str   the characters to be appended.
 421.503 +     * @return  a reference to this object.
 421.504 +     */
 421.505 +    public AbstractStringBuilder append(char[] str) {
 421.506 +        int len = str.length;
 421.507 +        ensureCapacityInternal(count + len);
 421.508 +        System.arraycopy(str, 0, value, count, len);
 421.509 +        count += len;
 421.510 +        return this;
 421.511 +    }
 421.512 +
 421.513 +    /**
 421.514 +     * Appends the string representation of a subarray of the
 421.515 +     * {@code char} array argument to this sequence.
 421.516 +     * <p>
 421.517 +     * Characters of the {@code char} array {@code str}, starting at
 421.518 +     * index {@code offset}, are appended, in order, to the contents
 421.519 +     * of this sequence. The length of this sequence increases
 421.520 +     * by the value of {@code len}.
 421.521 +     * <p>
 421.522 +     * The overall effect is exactly as if the arguments were converted
 421.523 +     * to a string by the method {@link String#valueOf(char[],int,int)},
 421.524 +     * and the characters of that string were then
 421.525 +     * {@link #append(String) appended} to this character sequence.
 421.526 +     *
 421.527 +     * @param   str      the characters to be appended.
 421.528 +     * @param   offset   the index of the first {@code char} to append.
 421.529 +     * @param   len      the number of {@code char}s to append.
 421.530 +     * @return  a reference to this object.
 421.531 +     * @throws IndexOutOfBoundsException
 421.532 +     *         if {@code offset < 0} or {@code len < 0}
 421.533 +     *         or {@code offset+len > str.length}
 421.534 +     */
 421.535 +    public AbstractStringBuilder append(char str[], int offset, int len) {
 421.536 +        if (len > 0)                // let arraycopy report AIOOBE for len < 0
 421.537 +            ensureCapacityInternal(count + len);
 421.538 +        System.arraycopy(str, offset, value, count, len);
 421.539 +        count += len;
 421.540 +        return this;
 421.541 +    }
 421.542 +
 421.543 +    /**
 421.544 +     * Appends the string representation of the {@code boolean}
 421.545 +     * argument to the sequence.
 421.546 +     * <p>
 421.547 +     * The overall effect is exactly as if the argument were converted
 421.548 +     * to a string by the method {@link String#valueOf(boolean)},
 421.549 +     * and the characters of that string were then
 421.550 +     * {@link #append(String) appended} to this character sequence.
 421.551 +     *
 421.552 +     * @param   b   a {@code boolean}.
 421.553 +     * @return  a reference to this object.
 421.554 +     */
 421.555 +    public AbstractStringBuilder append(boolean b) {
 421.556 +        if (b) {
 421.557 +            ensureCapacityInternal(count + 4);
 421.558 +            value[count++] = 't';
 421.559 +            value[count++] = 'r';
 421.560 +            value[count++] = 'u';
 421.561 +            value[count++] = 'e';
 421.562 +        } else {
 421.563 +            ensureCapacityInternal(count + 5);
 421.564 +            value[count++] = 'f';
 421.565 +            value[count++] = 'a';
 421.566 +            value[count++] = 'l';
 421.567 +            value[count++] = 's';
 421.568 +            value[count++] = 'e';
 421.569 +        }
 421.570 +        return this;
 421.571 +    }
 421.572 +
 421.573 +    /**
 421.574 +     * Appends the string representation of the {@code char}
 421.575 +     * argument to this sequence.
 421.576 +     * <p>
 421.577 +     * The argument is appended to the contents of this sequence.
 421.578 +     * The length of this sequence increases by {@code 1}.
 421.579 +     * <p>
 421.580 +     * The overall effect is exactly as if the argument were converted
 421.581 +     * to a string by the method {@link String#valueOf(char)},
 421.582 +     * and the character in that string were then
 421.583 +     * {@link #append(String) appended} to this character sequence.
 421.584 +     *
 421.585 +     * @param   c   a {@code char}.
 421.586 +     * @return  a reference to this object.
 421.587 +     */
 421.588 +    public AbstractStringBuilder append(char c) {
 421.589 +        ensureCapacityInternal(count + 1);
 421.590 +        value[count++] = c;
 421.591 +        return this;
 421.592 +    }
 421.593 +
 421.594 +    /**
 421.595 +     * Appends the string representation of the {@code int}
 421.596 +     * argument to this sequence.
 421.597 +     * <p>
 421.598 +     * The overall effect is exactly as if the argument were converted
 421.599 +     * to a string by the method {@link String#valueOf(int)},
 421.600 +     * and the characters of that string were then
 421.601 +     * {@link #append(String) appended} to this character sequence.
 421.602 +     *
 421.603 +     * @param   i   an {@code int}.
 421.604 +     * @return  a reference to this object.
 421.605 +     */
 421.606 +    public AbstractStringBuilder append(int i) {
 421.607 +        return append(Integer.toString(i));
 421.608 +    }
 421.609 +
 421.610 +    /**
 421.611 +     * Appends the string representation of the {@code long}
 421.612 +     * argument to this sequence.
 421.613 +     * <p>
 421.614 +     * The overall effect is exactly as if the argument were converted
 421.615 +     * to a string by the method {@link String#valueOf(long)},
 421.616 +     * and the characters of that string were then
 421.617 +     * {@link #append(String) appended} to this character sequence.
 421.618 +     *
 421.619 +     * @param   l   a {@code long}.
 421.620 +     * @return  a reference to this object.
 421.621 +     */
 421.622 +    public AbstractStringBuilder append(long l) {
 421.623 +        if (l == Long.MIN_VALUE) {
 421.624 +            append("-9223372036854775808");
 421.625 +            return this;
 421.626 +        }
 421.627 +        int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
 421.628 +                                     : Long.stringSize(l);
 421.629 +        int spaceNeeded = count + appendedLength;
 421.630 +        ensureCapacityInternal(spaceNeeded);
 421.631 +        Long.getChars(l, spaceNeeded, value);
 421.632 +        count = spaceNeeded;
 421.633 +        return this;
 421.634 +    }
 421.635 +
 421.636 +    /**
 421.637 +     * Appends the string representation of the {@code float}
 421.638 +     * argument to this sequence.
 421.639 +     * <p>
 421.640 +     * The overall effect is exactly as if the argument were converted
 421.641 +     * to a string by the method {@link String#valueOf(float)},
 421.642 +     * and the characters of that string were then
 421.643 +     * {@link #append(String) appended} to this character sequence.
 421.644 +     *
 421.645 +     * @param   f   a {@code float}.
 421.646 +     * @return  a reference to this object.
 421.647 +     */
 421.648 +    public AbstractStringBuilder append(float f) {
 421.649 +        return append(Float.toString(f));
 421.650 +    }
 421.651 +
 421.652 +    /**
 421.653 +     * Appends the string representation of the {@code double}
 421.654 +     * argument to this sequence.
 421.655 +     * <p>
 421.656 +     * The overall effect is exactly as if the argument were converted
 421.657 +     * to a string by the method {@link String#valueOf(double)},
 421.658 +     * and the characters of that string were then
 421.659 +     * {@link #append(String) appended} to this character sequence.
 421.660 +     *
 421.661 +     * @param   d   a {@code double}.
 421.662 +     * @return  a reference to this object.
 421.663 +     */
 421.664 +    public AbstractStringBuilder append(double d) {
 421.665 +        return append(Double.toString(d));
 421.666 +    }
 421.667 +
 421.668 +    /**
 421.669 +     * Removes the characters in a substring of this sequence.
 421.670 +     * The substring begins at the specified {@code start} and extends to
 421.671 +     * the character at index {@code end - 1} or to the end of the
 421.672 +     * sequence if no such character exists. If
 421.673 +     * {@code start} is equal to {@code end}, no changes are made.
 421.674 +     *
 421.675 +     * @param      start  The beginning index, inclusive.
 421.676 +     * @param      end    The ending index, exclusive.
 421.677 +     * @return     This object.
 421.678 +     * @throws     StringIndexOutOfBoundsException  if {@code start}
 421.679 +     *             is negative, greater than {@code length()}, or
 421.680 +     *             greater than {@code end}.
 421.681 +     */
 421.682 +    public AbstractStringBuilder delete(int start, int end) {
 421.683 +        if (start < 0)
 421.684 +            throw new StringIndexOutOfBoundsException(start);
 421.685 +        if (end > count)
 421.686 +            end = count;
 421.687 +        if (start > end)
 421.688 +            throw new StringIndexOutOfBoundsException();
 421.689 +        int len = end - start;
 421.690 +        if (len > 0) {
 421.691 +            System.arraycopy(value, start+len, value, start, count-end);
 421.692 +            count -= len;
 421.693 +        }
 421.694 +        return this;
 421.695 +    }
 421.696 +
 421.697 +    /**
 421.698 +     * Appends the string representation of the {@code codePoint}
 421.699 +     * argument to this sequence.
 421.700 +     *
 421.701 +     * <p> The argument is appended to the contents of this sequence.
 421.702 +     * The length of this sequence increases by
 421.703 +     * {@link Character#charCount(int) Character.charCount(codePoint)}.
 421.704 +     *
 421.705 +     * <p> The overall effect is exactly as if the argument were
 421.706 +     * converted to a {@code char} array by the method
 421.707 +     * {@link Character#toChars(int)} and the character in that array
 421.708 +     * were then {@link #append(char[]) appended} to this character
 421.709 +     * sequence.
 421.710 +     *
 421.711 +     * @param   codePoint   a Unicode code point
 421.712 +     * @return  a reference to this object.
 421.713 +     * @exception IllegalArgumentException if the specified
 421.714 +     * {@code codePoint} isn't a valid Unicode code point
 421.715 +     */
 421.716 +    public AbstractStringBuilder appendCodePoint(int codePoint) {
 421.717 +        final int count = this.count;
 421.718 +
 421.719 +        if (Character.isBmpCodePoint(codePoint)) {
 421.720 +            ensureCapacityInternal(count + 1);
 421.721 +            value[count] = (char) codePoint;
 421.722 +            this.count = count + 1;
 421.723 +        } else if (Character.isValidCodePoint(codePoint)) {
 421.724 +            ensureCapacityInternal(count + 2);
 421.725 +            Character.toSurrogates(codePoint, value, count);
 421.726 +            this.count = count + 2;
 421.727 +        } else {
 421.728 +            throw new IllegalArgumentException();
 421.729 +        }
 421.730 +        return this;
 421.731 +    }
 421.732 +
 421.733 +    /**
 421.734 +     * Removes the <code>char</code> at the specified position in this
 421.735 +     * sequence. This sequence is shortened by one <code>char</code>.
 421.736 +     *
 421.737 +     * <p>Note: If the character at the given index is a supplementary
 421.738 +     * character, this method does not remove the entire character. If
 421.739 +     * correct handling of supplementary characters is required,
 421.740 +     * determine the number of <code>char</code>s to remove by calling
 421.741 +     * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
 421.742 +     * where <code>thisSequence</code> is this sequence.
 421.743 +     *
 421.744 +     * @param       index  Index of <code>char</code> to remove
 421.745 +     * @return      This object.
 421.746 +     * @throws      StringIndexOutOfBoundsException  if the <code>index</code>
 421.747 +     *              is negative or greater than or equal to
 421.748 +     *              <code>length()</code>.
 421.749 +     */
 421.750 +    public AbstractStringBuilder deleteCharAt(int index) {
 421.751 +        if ((index < 0) || (index >= count))
 421.752 +            throw new StringIndexOutOfBoundsException(index);
 421.753 +        System.arraycopy(value, index+1, value, index, count-index-1);
 421.754 +        count--;
 421.755 +        return this;
 421.756 +    }
 421.757 +
 421.758 +    /**
 421.759 +     * Replaces the characters in a substring of this sequence
 421.760 +     * with characters in the specified <code>String</code>. The substring
 421.761 +     * begins at the specified <code>start</code> and extends to the character
 421.762 +     * at index <code>end - 1</code> or to the end of the
 421.763 +     * sequence if no such character exists. First the
 421.764 +     * characters in the substring are removed and then the specified
 421.765 +     * <code>String</code> is inserted at <code>start</code>. (This
 421.766 +     * sequence will be lengthened to accommodate the
 421.767 +     * specified String if necessary.)
 421.768 +     *
 421.769 +     * @param      start    The beginning index, inclusive.
 421.770 +     * @param      end      The ending index, exclusive.
 421.771 +     * @param      str   String that will replace previous contents.
 421.772 +     * @return     This object.
 421.773 +     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 421.774 +     *             is negative, greater than <code>length()</code>, or
 421.775 +     *             greater than <code>end</code>.
 421.776 +     */
 421.777 +    public AbstractStringBuilder replace(int start, int end, String str) {
 421.778 +        if (start < 0)
 421.779 +            throw new StringIndexOutOfBoundsException(start);
 421.780 +        if (start > count)
 421.781 +            throw new StringIndexOutOfBoundsException("start > length()");
 421.782 +        if (start > end)
 421.783 +            throw new StringIndexOutOfBoundsException("start > end");
 421.784 +
 421.785 +        if (end > count)
 421.786 +            end = count;
 421.787 +        int len = str.length();
 421.788 +        int newCount = count + len - (end - start);
 421.789 +        ensureCapacityInternal(newCount);
 421.790 +
 421.791 +        System.arraycopy(value, end, value, start + len, count - end);
 421.792 +        str.getChars(value, start);
 421.793 +        count = newCount;
 421.794 +        return this;
 421.795 +    }
 421.796 +
 421.797 +    /**
 421.798 +     * Returns a new <code>String</code> that contains a subsequence of
 421.799 +     * characters currently contained in this character sequence. The
 421.800 +     * substring begins at the specified index and extends to the end of
 421.801 +     * this sequence.
 421.802 +     *
 421.803 +     * @param      start    The beginning index, inclusive.
 421.804 +     * @return     The new string.
 421.805 +     * @throws     StringIndexOutOfBoundsException  if <code>start</code> is
 421.806 +     *             less than zero, or greater than the length of this object.
 421.807 +     */
 421.808 +    public String substring(int start) {
 421.809 +        return substring(start, count);
 421.810 +    }
 421.811 +
 421.812 +    /**
 421.813 +     * Returns a new character sequence that is a subsequence of this sequence.
 421.814 +     *
 421.815 +     * <p> An invocation of this method of the form
 421.816 +     *
 421.817 +     * <blockquote><pre>
 421.818 +     * sb.subSequence(begin,&nbsp;end)</pre></blockquote>
 421.819 +     *
 421.820 +     * behaves in exactly the same way as the invocation
 421.821 +     *
 421.822 +     * <blockquote><pre>
 421.823 +     * sb.substring(begin,&nbsp;end)</pre></blockquote>
 421.824 +     *
 421.825 +     * This method is provided so that this class can
 421.826 +     * implement the {@link CharSequence} interface. </p>
 421.827 +     *
 421.828 +     * @param      start   the start index, inclusive.
 421.829 +     * @param      end     the end index, exclusive.
 421.830 +     * @return     the specified subsequence.
 421.831 +     *
 421.832 +     * @throws  IndexOutOfBoundsException
 421.833 +     *          if <tt>start</tt> or <tt>end</tt> are negative,
 421.834 +     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 421.835 +     *          or if <tt>start</tt> is greater than <tt>end</tt>
 421.836 +     * @spec JSR-51
 421.837 +     */
 421.838 +    public CharSequence subSequence(int start, int end) {
 421.839 +        return substring(start, end);
 421.840 +    }
 421.841 +
 421.842 +    /**
 421.843 +     * Returns a new <code>String</code> that contains a subsequence of
 421.844 +     * characters currently contained in this sequence. The
 421.845 +     * substring begins at the specified <code>start</code> and
 421.846 +     * extends to the character at index <code>end - 1</code>.
 421.847 +     *
 421.848 +     * @param      start    The beginning index, inclusive.
 421.849 +     * @param      end      The ending index, exclusive.
 421.850 +     * @return     The new string.
 421.851 +     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
 421.852 +     *             or <code>end</code> are negative or greater than
 421.853 +     *             <code>length()</code>, or <code>start</code> is
 421.854 +     *             greater than <code>end</code>.
 421.855 +     */
 421.856 +    public String substring(int start, int end) {
 421.857 +        if (start < 0)
 421.858 +            throw new StringIndexOutOfBoundsException(start);
 421.859 +        if (end > count)
 421.860 +            throw new StringIndexOutOfBoundsException(end);
 421.861 +        if (start > end)
 421.862 +            throw new StringIndexOutOfBoundsException(end - start);
 421.863 +        return new String(value, start, end - start);
 421.864 +    }
 421.865 +
 421.866 +    /**
 421.867 +     * Inserts the string representation of a subarray of the {@code str}
 421.868 +     * array argument into this sequence. The subarray begins at the
 421.869 +     * specified {@code offset} and extends {@code len} {@code char}s.
 421.870 +     * The characters of the subarray are inserted into this sequence at
 421.871 +     * the position indicated by {@code index}. The length of this
 421.872 +     * sequence increases by {@code len} {@code char}s.
 421.873 +     *
 421.874 +     * @param      index    position at which to insert subarray.
 421.875 +     * @param      str       A {@code char} array.
 421.876 +     * @param      offset   the index of the first {@code char} in subarray to
 421.877 +     *             be inserted.
 421.878 +     * @param      len      the number of {@code char}s in the subarray to
 421.879 +     *             be inserted.
 421.880 +     * @return     This object
 421.881 +     * @throws     StringIndexOutOfBoundsException  if {@code index}
 421.882 +     *             is negative or greater than {@code length()}, or
 421.883 +     *             {@code offset} or {@code len} are negative, or
 421.884 +     *             {@code (offset+len)} is greater than
 421.885 +     *             {@code str.length}.
 421.886 +     */
 421.887 +    public AbstractStringBuilder insert(int index, char[] str, int offset,
 421.888 +                                        int len)
 421.889 +    {
 421.890 +        if ((index < 0) || (index > length()))
 421.891 +            throw new StringIndexOutOfBoundsException(index);
 421.892 +        if ((offset < 0) || (len < 0) || (offset > str.length - len))
 421.893 +            throw new StringIndexOutOfBoundsException(
 421.894 +                "offset " + offset + ", len " + len + ", str.length "
 421.895 +                + str.length);
 421.896 +        ensureCapacityInternal(count + len);
 421.897 +        System.arraycopy(value, index, value, index + len, count - index);
 421.898 +        System.arraycopy(str, offset, value, index, len);
 421.899 +        count += len;
 421.900 +        return this;
 421.901 +    }
 421.902 +
 421.903 +    /**
 421.904 +     * Inserts the string representation of the {@code Object}
 421.905 +     * argument into this character sequence.
 421.906 +     * <p>
 421.907 +     * The overall effect is exactly as if the second argument were
 421.908 +     * converted to a string by the method {@link String#valueOf(Object)},
 421.909 +     * and the characters of that string were then
 421.910 +     * {@link #insert(int,String) inserted} into this character
 421.911 +     * sequence at the indicated offset.
 421.912 +     * <p>
 421.913 +     * The {@code offset} argument must be greater than or equal to
 421.914 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 421.915 +     * of this sequence.
 421.916 +     *
 421.917 +     * @param      offset   the offset.
 421.918 +     * @param      obj      an {@code Object}.
 421.919 +     * @return     a reference to this object.
 421.920 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 421.921 +     */
 421.922 +    public AbstractStringBuilder insert(int offset, Object obj) {
 421.923 +        return insert(offset, String.valueOf(obj));
 421.924 +    }
 421.925 +
 421.926 +    /**
 421.927 +     * Inserts the string into this character sequence.
 421.928 +     * <p>
 421.929 +     * The characters of the {@code String} argument are inserted, in
 421.930 +     * order, into this sequence at the indicated offset, moving up any
 421.931 +     * characters originally above that position and increasing the length
 421.932 +     * of this sequence by the length of the argument. If
 421.933 +     * {@code str} is {@code null}, then the four characters
 421.934 +     * {@code "null"} are inserted into this sequence.
 421.935 +     * <p>
 421.936 +     * The character at index <i>k</i> in the new character sequence is
 421.937 +     * equal to:
 421.938 +     * <ul>
 421.939 +     * <li>the character at index <i>k</i> in the old character sequence, if
 421.940 +     * <i>k</i> is less than {@code offset}
 421.941 +     * <li>the character at index <i>k</i>{@code -offset} in the
 421.942 +     * argument {@code str}, if <i>k</i> is not less than
 421.943 +     * {@code offset} but is less than {@code offset+str.length()}
 421.944 +     * <li>the character at index <i>k</i>{@code -str.length()} in the
 421.945 +     * old character sequence, if <i>k</i> is not less than
 421.946 +     * {@code offset+str.length()}
 421.947 +     * </ul><p>
 421.948 +     * The {@code offset} argument must be greater than or equal to
 421.949 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 421.950 +     * of this sequence.
 421.951 +     *
 421.952 +     * @param      offset   the offset.
 421.953 +     * @param      str      a string.
 421.954 +     * @return     a reference to this object.
 421.955 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 421.956 +     */
 421.957 +    public AbstractStringBuilder insert(int offset, String str) {
 421.958 +        if ((offset < 0) || (offset > length()))
 421.959 +            throw new StringIndexOutOfBoundsException(offset);
 421.960 +        if (str == null)
 421.961 +            str = "null";
 421.962 +        int len = str.length();
 421.963 +        ensureCapacityInternal(count + len);
 421.964 +        System.arraycopy(value, offset, value, offset + len, count - offset);
 421.965 +        str.getChars(value, offset);
 421.966 +        count += len;
 421.967 +        return this;
 421.968 +    }
 421.969 +
 421.970 +    /**
 421.971 +     * Inserts the string representation of the {@code char} array
 421.972 +     * argument into this sequence.
 421.973 +     * <p>
 421.974 +     * The characters of the array argument are inserted into the
 421.975 +     * contents of this sequence at the position indicated by
 421.976 +     * {@code offset}. The length of this sequence increases by
 421.977 +     * the length of the argument.
 421.978 +     * <p>
 421.979 +     * The overall effect is exactly as if the second argument were
 421.980 +     * converted to a string by the method {@link String#valueOf(char[])},
 421.981 +     * and the characters of that string were then
 421.982 +     * {@link #insert(int,String) inserted} into this character
 421.983 +     * sequence at the indicated offset.
 421.984 +     * <p>
 421.985 +     * The {@code offset} argument must be greater than or equal to
 421.986 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
 421.987 +     * of this sequence.
 421.988 +     *
 421.989 +     * @param      offset   the offset.
 421.990 +     * @param      str      a character array.
 421.991 +     * @return     a reference to this object.
 421.992 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
 421.993 +     */
 421.994 +    public AbstractStringBuilder insert(int offset, char[] str) {
 421.995 +        if ((offset < 0) || (offset > length()))
 421.996 +            throw new StringIndexOutOfBoundsException(offset);
 421.997 +        int len = str.length;
 421.998 +        ensureCapacityInternal(count + len);
 421.999 +        System.arraycopy(value, offset, value, offset + len, count - offset);
421.1000 +        System.arraycopy(str, 0, value, offset, len);
421.1001 +        count += len;
421.1002 +        return this;
421.1003 +    }
421.1004 +
421.1005 +    /**
421.1006 +     * Inserts the specified {@code CharSequence} into this sequence.
421.1007 +     * <p>
421.1008 +     * The characters of the {@code CharSequence} argument are inserted,
421.1009 +     * in order, into this sequence at the indicated offset, moving up
421.1010 +     * any characters originally above that position and increasing the length
421.1011 +     * of this sequence by the length of the argument s.
421.1012 +     * <p>
421.1013 +     * The result of this method is exactly the same as if it were an
421.1014 +     * invocation of this object's
421.1015 +     * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
421.1016 +     * method.
421.1017 +     *
421.1018 +     * <p>If {@code s} is {@code null}, then the four characters
421.1019 +     * {@code "null"} are inserted into this sequence.
421.1020 +     *
421.1021 +     * @param      dstOffset   the offset.
421.1022 +     * @param      s the sequence to be inserted
421.1023 +     * @return     a reference to this object.
421.1024 +     * @throws     IndexOutOfBoundsException  if the offset is invalid.
421.1025 +     */
421.1026 +    public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
421.1027 +        if (s == null)
421.1028 +            s = "null";
421.1029 +        if (s instanceof String)
421.1030 +            return this.insert(dstOffset, (String)s);
421.1031 +        return this.insert(dstOffset, s, 0, s.length());
421.1032 +    }
421.1033 +
421.1034 +    /**
421.1035 +     * Inserts a subsequence of the specified {@code CharSequence} into
421.1036 +     * this sequence.
421.1037 +     * <p>
421.1038 +     * The subsequence of the argument {@code s} specified by
421.1039 +     * {@code start} and {@code end} are inserted,
421.1040 +     * in order, into this sequence at the specified destination offset, moving
421.1041 +     * up any characters originally above that position. The length of this
421.1042 +     * sequence is increased by {@code end - start}.
421.1043 +     * <p>
421.1044 +     * The character at index <i>k</i> in this sequence becomes equal to:
421.1045 +     * <ul>
421.1046 +     * <li>the character at index <i>k</i> in this sequence, if
421.1047 +     * <i>k</i> is less than {@code dstOffset}
421.1048 +     * <li>the character at index <i>k</i>{@code +start-dstOffset} in
421.1049 +     * the argument {@code s}, if <i>k</i> is greater than or equal to
421.1050 +     * {@code dstOffset} but is less than {@code dstOffset+end-start}
421.1051 +     * <li>the character at index <i>k</i>{@code -(end-start)} in this
421.1052 +     * sequence, if <i>k</i> is greater than or equal to
421.1053 +     * {@code dstOffset+end-start}
421.1054 +     * </ul><p>
421.1055 +     * The {@code dstOffset} argument must be greater than or equal to
421.1056 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1057 +     * of this sequence.
421.1058 +     * <p>The start argument must be nonnegative, and not greater than
421.1059 +     * {@code end}.
421.1060 +     * <p>The end argument must be greater than or equal to
421.1061 +     * {@code start}, and less than or equal to the length of s.
421.1062 +     *
421.1063 +     * <p>If {@code s} is {@code null}, then this method inserts
421.1064 +     * characters as if the s parameter was a sequence containing the four
421.1065 +     * characters {@code "null"}.
421.1066 +     *
421.1067 +     * @param      dstOffset   the offset in this sequence.
421.1068 +     * @param      s       the sequence to be inserted.
421.1069 +     * @param      start   the starting index of the subsequence to be inserted.
421.1070 +     * @param      end     the end index of the subsequence to be inserted.
421.1071 +     * @return     a reference to this object.
421.1072 +     * @throws     IndexOutOfBoundsException  if {@code dstOffset}
421.1073 +     *             is negative or greater than {@code this.length()}, or
421.1074 +     *              {@code start} or {@code end} are negative, or
421.1075 +     *              {@code start} is greater than {@code end} or
421.1076 +     *              {@code end} is greater than {@code s.length()}
421.1077 +     */
421.1078 +     public AbstractStringBuilder insert(int dstOffset, CharSequence s,
421.1079 +                                         int start, int end) {
421.1080 +        if (s == null)
421.1081 +            s = "null";
421.1082 +        if ((dstOffset < 0) || (dstOffset > this.length()))
421.1083 +            throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
421.1084 +        if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
421.1085 +            throw new IndexOutOfBoundsException(
421.1086 +                "start " + start + ", end " + end + ", s.length() "
421.1087 +                + s.length());
421.1088 +        int len = end - start;
421.1089 +        ensureCapacityInternal(count + len);
421.1090 +        System.arraycopy(value, dstOffset, value, dstOffset + len,
421.1091 +                         count - dstOffset);
421.1092 +        for (int i=start; i<end; i++)
421.1093 +            value[dstOffset++] = s.charAt(i);
421.1094 +        count += len;
421.1095 +        return this;
421.1096 +    }
421.1097 +
421.1098 +    /**
421.1099 +     * Inserts the string representation of the {@code boolean}
421.1100 +     * argument into this sequence.
421.1101 +     * <p>
421.1102 +     * The overall effect is exactly as if the second argument were
421.1103 +     * converted to a string by the method {@link String#valueOf(boolean)},
421.1104 +     * and the characters of that string were then
421.1105 +     * {@link #insert(int,String) inserted} into this character
421.1106 +     * sequence at the indicated offset.
421.1107 +     * <p>
421.1108 +     * The {@code offset} argument must be greater than or equal to
421.1109 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1110 +     * of this sequence.
421.1111 +     *
421.1112 +     * @param      offset   the offset.
421.1113 +     * @param      b        a {@code boolean}.
421.1114 +     * @return     a reference to this object.
421.1115 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
421.1116 +     */
421.1117 +    public AbstractStringBuilder insert(int offset, boolean b) {
421.1118 +        return insert(offset, String.valueOf(b));
421.1119 +    }
421.1120 +
421.1121 +    /**
421.1122 +     * Inserts the string representation of the {@code char}
421.1123 +     * argument into this sequence.
421.1124 +     * <p>
421.1125 +     * The overall effect is exactly as if the second argument were
421.1126 +     * converted to a string by the method {@link String#valueOf(char)},
421.1127 +     * and the character in that string were then
421.1128 +     * {@link #insert(int,String) inserted} into this character
421.1129 +     * sequence at the indicated offset.
421.1130 +     * <p>
421.1131 +     * The {@code offset} argument must be greater than or equal to
421.1132 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1133 +     * of this sequence.
421.1134 +     *
421.1135 +     * @param      offset   the offset.
421.1136 +     * @param      c        a {@code char}.
421.1137 +     * @return     a reference to this object.
421.1138 +     * @throws     IndexOutOfBoundsException  if the offset is invalid.
421.1139 +     */
421.1140 +    public AbstractStringBuilder insert(int offset, char c) {
421.1141 +        ensureCapacityInternal(count + 1);
421.1142 +        System.arraycopy(value, offset, value, offset + 1, count - offset);
421.1143 +        value[offset] = c;
421.1144 +        count += 1;
421.1145 +        return this;
421.1146 +    }
421.1147 +
421.1148 +    /**
421.1149 +     * Inserts the string representation of the second {@code int}
421.1150 +     * argument into this sequence.
421.1151 +     * <p>
421.1152 +     * The overall effect is exactly as if the second argument were
421.1153 +     * converted to a string by the method {@link String#valueOf(int)},
421.1154 +     * and the characters of that string were then
421.1155 +     * {@link #insert(int,String) inserted} into this character
421.1156 +     * sequence at the indicated offset.
421.1157 +     * <p>
421.1158 +     * The {@code offset} argument must be greater than or equal to
421.1159 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1160 +     * of this sequence.
421.1161 +     *
421.1162 +     * @param      offset   the offset.
421.1163 +     * @param      i        an {@code int}.
421.1164 +     * @return     a reference to this object.
421.1165 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
421.1166 +     */
421.1167 +    public AbstractStringBuilder insert(int offset, int i) {
421.1168 +        return insert(offset, String.valueOf(i));
421.1169 +    }
421.1170 +
421.1171 +    /**
421.1172 +     * Inserts the string representation of the {@code long}
421.1173 +     * argument into this sequence.
421.1174 +     * <p>
421.1175 +     * The overall effect is exactly as if the second argument were
421.1176 +     * converted to a string by the method {@link String#valueOf(long)},
421.1177 +     * and the characters of that string were then
421.1178 +     * {@link #insert(int,String) inserted} into this character
421.1179 +     * sequence at the indicated offset.
421.1180 +     * <p>
421.1181 +     * The {@code offset} argument must be greater than or equal to
421.1182 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1183 +     * of this sequence.
421.1184 +     *
421.1185 +     * @param      offset   the offset.
421.1186 +     * @param      l        a {@code long}.
421.1187 +     * @return     a reference to this object.
421.1188 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
421.1189 +     */
421.1190 +    public AbstractStringBuilder insert(int offset, long l) {
421.1191 +        return insert(offset, String.valueOf(l));
421.1192 +    }
421.1193 +
421.1194 +    /**
421.1195 +     * Inserts the string representation of the {@code float}
421.1196 +     * argument into this sequence.
421.1197 +     * <p>
421.1198 +     * The overall effect is exactly as if the second argument were
421.1199 +     * converted to a string by the method {@link String#valueOf(float)},
421.1200 +     * and the characters of that string were then
421.1201 +     * {@link #insert(int,String) inserted} into this character
421.1202 +     * sequence at the indicated offset.
421.1203 +     * <p>
421.1204 +     * The {@code offset} argument must be greater than or equal to
421.1205 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1206 +     * of this sequence.
421.1207 +     *
421.1208 +     * @param      offset   the offset.
421.1209 +     * @param      f        a {@code float}.
421.1210 +     * @return     a reference to this object.
421.1211 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
421.1212 +     */
421.1213 +    public AbstractStringBuilder insert(int offset, float f) {
421.1214 +        return insert(offset, String.valueOf(f));
421.1215 +    }
421.1216 +
421.1217 +    /**
421.1218 +     * Inserts the string representation of the {@code double}
421.1219 +     * argument into this sequence.
421.1220 +     * <p>
421.1221 +     * The overall effect is exactly as if the second argument were
421.1222 +     * converted to a string by the method {@link String#valueOf(double)},
421.1223 +     * and the characters of that string were then
421.1224 +     * {@link #insert(int,String) inserted} into this character
421.1225 +     * sequence at the indicated offset.
421.1226 +     * <p>
421.1227 +     * The {@code offset} argument must be greater than or equal to
421.1228 +     * {@code 0}, and less than or equal to the {@linkplain #length() length}
421.1229 +     * of this sequence.
421.1230 +     *
421.1231 +     * @param      offset   the offset.
421.1232 +     * @param      d        a {@code double}.
421.1233 +     * @return     a reference to this object.
421.1234 +     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
421.1235 +     */
421.1236 +    public AbstractStringBuilder insert(int offset, double d) {
421.1237 +        return insert(offset, String.valueOf(d));
421.1238 +    }
421.1239 +
421.1240 +    /**
421.1241 +     * Returns the index within this string of the first occurrence of the
421.1242 +     * specified substring. The integer returned is the smallest value
421.1243 +     * <i>k</i> such that:
421.1244 +     * <blockquote><pre>
421.1245 +     * this.toString().startsWith(str, <i>k</i>)
421.1246 +     * </pre></blockquote>
421.1247 +     * is <code>true</code>.
421.1248 +     *
421.1249 +     * @param   str   any string.
421.1250 +     * @return  if the string argument occurs as a substring within this
421.1251 +     *          object, then the index of the first character of the first
421.1252 +     *          such substring is returned; if it does not occur as a
421.1253 +     *          substring, <code>-1</code> is returned.
421.1254 +     * @throws  java.lang.NullPointerException if <code>str</code> is
421.1255 +     *          <code>null</code>.
421.1256 +     */
421.1257 +    public int indexOf(String str) {
421.1258 +        return indexOf(str, 0);
421.1259 +    }
421.1260 +
421.1261 +    /**
421.1262 +     * Returns the index within this string of the first occurrence of the
421.1263 +     * specified substring, starting at the specified index.  The integer
421.1264 +     * returned is the smallest value <tt>k</tt> for which:
421.1265 +     * <blockquote><pre>
421.1266 +     *     k >= Math.min(fromIndex, str.length()) &&
421.1267 +     *                   this.toString().startsWith(str, k)
421.1268 +     * </pre></blockquote>
421.1269 +     * If no such value of <i>k</i> exists, then -1 is returned.
421.1270 +     *
421.1271 +     * @param   str         the substring for which to search.
421.1272 +     * @param   fromIndex   the index from which to start the search.
421.1273 +     * @return  the index within this string of the first occurrence of the
421.1274 +     *          specified substring, starting at the specified index.
421.1275 +     * @throws  java.lang.NullPointerException if <code>str</code> is
421.1276 +     *            <code>null</code>.
421.1277 +     */
421.1278 +    public int indexOf(String str, int fromIndex) {
421.1279 +        return toString().indexOf(str, fromIndex);
421.1280 +    }
421.1281 +
421.1282 +    /**
421.1283 +     * Returns the index within this string of the rightmost occurrence
421.1284 +     * of the specified substring.  The rightmost empty string "" is
421.1285 +     * considered to occur at the index value <code>this.length()</code>.
421.1286 +     * The returned index is the largest value <i>k</i> such that
421.1287 +     * <blockquote><pre>
421.1288 +     * this.toString().startsWith(str, k)
421.1289 +     * </pre></blockquote>
421.1290 +     * is true.
421.1291 +     *
421.1292 +     * @param   str   the substring to search for.
421.1293 +     * @return  if the string argument occurs one or more times as a substring
421.1294 +     *          within this object, then the index of the first character of
421.1295 +     *          the last such substring is returned. If it does not occur as
421.1296 +     *          a substring, <code>-1</code> is returned.
421.1297 +     * @throws  java.lang.NullPointerException  if <code>str</code> is
421.1298 +     *          <code>null</code>.
421.1299 +     */
421.1300 +    public int lastIndexOf(String str) {
421.1301 +        return lastIndexOf(str, count);
421.1302 +    }
421.1303 +
421.1304 +    /**
421.1305 +     * Returns the index within this string of the last occurrence of the
421.1306 +     * specified substring. The integer returned is the largest value <i>k</i>
421.1307 +     * such that:
421.1308 +     * <blockquote><pre>
421.1309 +     *     k <= Math.min(fromIndex, str.length()) &&
421.1310 +     *                   this.toString().startsWith(str, k)
421.1311 +     * </pre></blockquote>
421.1312 +     * If no such value of <i>k</i> exists, then -1 is returned.
421.1313 +     *
421.1314 +     * @param   str         the substring to search for.
421.1315 +     * @param   fromIndex   the index to start the search from.
421.1316 +     * @return  the index within this sequence of the last occurrence of the
421.1317 +     *          specified substring.
421.1318 +     * @throws  java.lang.NullPointerException if <code>str</code> is
421.1319 +     *          <code>null</code>.
421.1320 +     */
421.1321 +    public int lastIndexOf(String str, int fromIndex) {
421.1322 +        return String.lastIndexOf(value, 0, count,
421.1323 +                              str.toCharArray(), 0, str.length(), fromIndex);
421.1324 +    }
421.1325 +
421.1326 +    /**
421.1327 +     * Causes this character sequence to be replaced by the reverse of
421.1328 +     * the sequence. If there are any surrogate pairs included in the
421.1329 +     * sequence, these are treated as single characters for the
421.1330 +     * reverse operation. Thus, the order of the high-low surrogates
421.1331 +     * is never reversed.
421.1332 +     *
421.1333 +     * Let <i>n</i> be the character length of this character sequence
421.1334 +     * (not the length in <code>char</code> values) just prior to
421.1335 +     * execution of the <code>reverse</code> method. Then the
421.1336 +     * character at index <i>k</i> in the new character sequence is
421.1337 +     * equal to the character at index <i>n-k-1</i> in the old
421.1338 +     * character sequence.
421.1339 +     *
421.1340 +     * <p>Note that the reverse operation may result in producing
421.1341 +     * surrogate pairs that were unpaired low-surrogates and
421.1342 +     * high-surrogates before the operation. For example, reversing
421.1343 +     * "&#92;uDC00&#92;uD800" produces "&#92;uD800&#92;uDC00" which is
421.1344 +     * a valid surrogate pair.
421.1345 +     *
421.1346 +     * @return  a reference to this object.
421.1347 +     */
421.1348 +    public AbstractStringBuilder reverse() {
421.1349 +        boolean hasSurrogate = false;
421.1350 +        int n = count - 1;
421.1351 +        for (int j = (n-1) >> 1; j >= 0; --j) {
421.1352 +            char temp = value[j];
421.1353 +            char temp2 = value[n - j];
421.1354 +            if (!hasSurrogate) {
421.1355 +                hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
421.1356 +                    || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
421.1357 +            }
421.1358 +            value[j] = temp2;
421.1359 +            value[n - j] = temp;
421.1360 +        }
421.1361 +        if (hasSurrogate) {
421.1362 +            // Reverse back all valid surrogate pairs
421.1363 +            for (int i = 0; i < count - 1; i++) {
421.1364 +                char c2 = value[i];
421.1365 +                if (Character.isLowSurrogate(c2)) {
421.1366 +                    char c1 = value[i + 1];
421.1367 +                    if (Character.isHighSurrogate(c1)) {
421.1368 +                        value[i++] = c1;
421.1369 +                        value[i] = c2;
421.1370 +                    }
421.1371 +                }
421.1372 +            }
421.1373 +        }
421.1374 +        return this;
421.1375 +    }
421.1376 +
421.1377 +    /**
421.1378 +     * Returns a string representing the data in this sequence.
421.1379 +     * A new <code>String</code> object is allocated and initialized to
421.1380 +     * contain the character sequence currently represented by this
421.1381 +     * object. This <code>String</code> is then returned. Subsequent
421.1382 +     * changes to this sequence do not affect the contents of the
421.1383 +     * <code>String</code>.
421.1384 +     *
421.1385 +     * @return  a string representation of this sequence of characters.
421.1386 +     */
421.1387 +    public abstract String toString();
421.1388 +
421.1389 +    /**
421.1390 +     * Needed by <tt>String</tt> for the contentEquals method.
421.1391 +     */
421.1392 +    final char[] getValue() {
421.1393 +        return value;
421.1394 +    }
421.1395 +
421.1396 +    static char[] copyOfRange(char[] original, int from, int to) {
421.1397 +        int newLength = to - from;
421.1398 +        if (newLength < 0) {
421.1399 +            throw new IllegalArgumentException(from + " > " + to);
421.1400 +        }
421.1401 +        char[] copy = new char[newLength];
421.1402 +        System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
421.1403 +        return copy;
421.1404 +    }
421.1405 +
421.1406 +    // access system property
421.1407 +    static String getProperty(String nm) {
421.1408 +        return null;
421.1409 +    }
421.1410 +
421.1411 +    static char[] copyOf(char[] original, int newLength) {
421.1412 +        char[] copy = new char[newLength];
421.1413 +        System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
421.1414 +        return copy;
421.1415 +    }
421.1416 +    
421.1417 +}
   422.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   422.2 +++ b/rt/emul/mini/src/main/java/java/lang/Appendable.java	Wed Feb 27 11:24:58 2013 +0100
   422.3 @@ -0,0 +1,121 @@
   422.4 +/*
   422.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   422.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   422.7 + *
   422.8 + * This code is free software; you can redistribute it and/or modify it
   422.9 + * under the terms of the GNU General Public License version 2 only, as
  422.10 + * published by the Free Software Foundation.  Oracle designates this
  422.11 + * particular file as subject to the "Classpath" exception as provided
  422.12 + * by Oracle in the LICENSE file that accompanied this code.
  422.13 + *
  422.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  422.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  422.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  422.17 + * version 2 for more details (a copy is included in the LICENSE file that
  422.18 + * accompanied this code).
  422.19 + *
  422.20 + * You should have received a copy of the GNU General Public License version
  422.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  422.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  422.23 + *
  422.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  422.25 + * or visit www.oracle.com if you need additional information or have any
  422.26 + * questions.
  422.27 + */
  422.28 +
  422.29 +package java.lang;
  422.30 +
  422.31 +import java.io.IOException;
  422.32 +
  422.33 +/**
  422.34 + * An object to which <tt>char</tt> sequences and values can be appended.  The
  422.35 + * <tt>Appendable</tt> interface must be implemented by any class whose
  422.36 + * instances are intended to receive formatted output from a {@link
  422.37 + * java.util.Formatter}.
  422.38 + *
  422.39 + * <p> The characters to be appended should be valid Unicode characters as
  422.40 + * described in <a href="Character.html#unicode">Unicode Character
  422.41 + * Representation</a>.  Note that supplementary characters may be composed of
  422.42 + * multiple 16-bit <tt>char</tt> values.
  422.43 + *
  422.44 + * <p> Appendables are not necessarily safe for multithreaded access.  Thread
  422.45 + * safety is the responsibility of classes that extend and implement this
  422.46 + * interface.
  422.47 + *
  422.48 + * <p> Since this interface may be implemented by existing classes
  422.49 + * with different styles of error handling there is no guarantee that
  422.50 + * errors will be propagated to the invoker.
  422.51 + *
  422.52 + * @since 1.5
  422.53 + */
  422.54 +public interface Appendable {
  422.55 +
  422.56 +    /**
  422.57 +     * Appends the specified character sequence to this <tt>Appendable</tt>.
  422.58 +     *
  422.59 +     * <p> Depending on which class implements the character sequence
  422.60 +     * <tt>csq</tt>, the entire sequence may not be appended.  For
  422.61 +     * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
  422.62 +     * the subsequence to append is defined by the buffer's position and limit.
  422.63 +     *
  422.64 +     * @param  csq
  422.65 +     *         The character sequence to append.  If <tt>csq</tt> is
  422.66 +     *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
  422.67 +     *         appended to this Appendable.
  422.68 +     *
  422.69 +     * @return  A reference to this <tt>Appendable</tt>
  422.70 +     *
  422.71 +     * @throws  IOException
  422.72 +     *          If an I/O error occurs
  422.73 +     */
  422.74 +    Appendable append(CharSequence csq) throws IOException;
  422.75 +
  422.76 +    /**
  422.77 +     * Appends a subsequence of the specified character sequence to this
  422.78 +     * <tt>Appendable</tt>.
  422.79 +     *
  422.80 +     * <p> An invocation of this method of the form <tt>out.append(csq, start,
  422.81 +     * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
  422.82 +     * exactly the same way as the invocation
  422.83 +     *
  422.84 +     * <pre>
  422.85 +     *     out.append(csq.subSequence(start, end)) </pre>
  422.86 +     *
  422.87 +     * @param  csq
  422.88 +     *         The character sequence from which a subsequence will be
  422.89 +     *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
  422.90 +     *         will be appended as if <tt>csq</tt> contained the four
  422.91 +     *         characters <tt>"null"</tt>.
  422.92 +     *
  422.93 +     * @param  start
  422.94 +     *         The index of the first character in the subsequence
  422.95 +     *
  422.96 +     * @param  end
  422.97 +     *         The index of the character following the last character in the
  422.98 +     *         subsequence
  422.99 +     *
 422.100 +     * @return  A reference to this <tt>Appendable</tt>
 422.101 +     *
 422.102 +     * @throws  IndexOutOfBoundsException
 422.103 +     *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
 422.104 +     *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
 422.105 +     *          <tt>csq.length()</tt>
 422.106 +     *
 422.107 +     * @throws  IOException
 422.108 +     *          If an I/O error occurs
 422.109 +     */
 422.110 +    Appendable append(CharSequence csq, int start, int end) throws IOException;
 422.111 +
 422.112 +    /**
 422.113 +     * Appends the specified character to this <tt>Appendable</tt>.
 422.114 +     *
 422.115 +     * @param  c
 422.116 +     *         The character to append
 422.117 +     *
 422.118 +     * @return  A reference to this <tt>Appendable</tt>
 422.119 +     *
 422.120 +     * @throws  IOException
 422.121 +     *          If an I/O error occurs
 422.122 +     */
 422.123 +    Appendable append(char c) throws IOException;
 422.124 +}
   423.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   423.2 +++ b/rt/emul/mini/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java	Wed Feb 27 11:24:58 2013 +0100
   423.3 @@ -0,0 +1,67 @@
   423.4 +/*
   423.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   423.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   423.7 + *
   423.8 + * This code is free software; you can redistribute it and/or modify it
   423.9 + * under the terms of the GNU General Public License version 2 only, as
  423.10 + * published by the Free Software Foundation.  Oracle designates this
  423.11 + * particular file as subject to the "Classpath" exception as provided
  423.12 + * by Oracle in the LICENSE file that accompanied this code.
  423.13 + *
  423.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  423.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  423.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  423.17 + * version 2 for more details (a copy is included in the LICENSE file that
  423.18 + * accompanied this code).
  423.19 + *
  423.20 + * You should have received a copy of the GNU General Public License version
  423.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  423.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  423.23 + *
  423.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  423.25 + * or visit www.oracle.com if you need additional information or have any
  423.26 + * questions.
  423.27 + */
  423.28 +
  423.29 +package java.lang;
  423.30 +
  423.31 +/**
  423.32 + * Thrown to indicate that an array has been accessed with an
  423.33 + * illegal index. The index is either negative or greater than or
  423.34 + * equal to the size of the array.
  423.35 + *
  423.36 + * @author  unascribed
  423.37 + * @since   JDK1.0
  423.38 + */
  423.39 +public
  423.40 +class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
  423.41 +    private static final long serialVersionUID = -5116101128118950844L;
  423.42 +
  423.43 +    /**
  423.44 +     * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
  423.45 +     * detail message.
  423.46 +     */
  423.47 +    public ArrayIndexOutOfBoundsException() {
  423.48 +        super();
  423.49 +    }
  423.50 +
  423.51 +    /**
  423.52 +     * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
  423.53 +     * class with an argument indicating the illegal index.
  423.54 +     *
  423.55 +     * @param   index   the illegal index.
  423.56 +     */
  423.57 +    public ArrayIndexOutOfBoundsException(int index) {
  423.58 +        super("Array index out of range: " + index);
  423.59 +    }
  423.60 +
  423.61 +    /**
  423.62 +     * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
  423.63 +     * with the specified detail message.
  423.64 +     *
  423.65 +     * @param   s   the detail message.
  423.66 +     */
  423.67 +    public ArrayIndexOutOfBoundsException(String s) {
  423.68 +        super(s);
  423.69 +    }
  423.70 +}
   424.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   424.2 +++ b/rt/emul/mini/src/main/java/java/lang/ArrayStoreException.java	Wed Feb 27 11:24:58 2013 +0100
   424.3 @@ -0,0 +1,60 @@
   424.4 +/*
   424.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   424.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   424.7 + *
   424.8 + * This code is free software; you can redistribute it and/or modify it
   424.9 + * under the terms of the GNU General Public License version 2 only, as
  424.10 + * published by the Free Software Foundation.  Oracle designates this
  424.11 + * particular file as subject to the "Classpath" exception as provided
  424.12 + * by Oracle in the LICENSE file that accompanied this code.
  424.13 + *
  424.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  424.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  424.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  424.17 + * version 2 for more details (a copy is included in the LICENSE file that
  424.18 + * accompanied this code).
  424.19 + *
  424.20 + * You should have received a copy of the GNU General Public License version
  424.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  424.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  424.23 + *
  424.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  424.25 + * or visit www.oracle.com if you need additional information or have any
  424.26 + * questions.
  424.27 + */
  424.28 +
  424.29 +package java.lang;
  424.30 +
  424.31 +/**
  424.32 + * Thrown to indicate that an attempt has been made to store the
  424.33 + * wrong type of object into an array of objects. For example, the
  424.34 + * following code generates an <code>ArrayStoreException</code>:
  424.35 + * <p><blockquote><pre>
  424.36 + *     Object x[] = new String[3];
  424.37 + *     x[0] = new Integer(0);
  424.38 + * </pre></blockquote>
  424.39 + *
  424.40 + * @author  unascribed
  424.41 + * @since   JDK1.0
  424.42 + */
  424.43 +public
  424.44 +class ArrayStoreException extends RuntimeException {
  424.45 +    private static final long serialVersionUID = -4522193890499838241L;
  424.46 +
  424.47 +    /**
  424.48 +     * Constructs an <code>ArrayStoreException</code> with no detail message.
  424.49 +     */
  424.50 +    public ArrayStoreException() {
  424.51 +        super();
  424.52 +    }
  424.53 +
  424.54 +    /**
  424.55 +     * Constructs an <code>ArrayStoreException</code> with the specified
  424.56 +     * detail message.
  424.57 +     *
  424.58 +     * @param   s   the detail message.
  424.59 +     */
  424.60 +    public ArrayStoreException(String s) {
  424.61 +        super(s);
  424.62 +    }
  424.63 +}
   425.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   425.2 +++ b/rt/emul/mini/src/main/java/java/lang/AssertionError.java	Wed Feb 27 11:24:58 2013 +0100
   425.3 @@ -0,0 +1,167 @@
   425.4 +/*
   425.5 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   425.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   425.7 + *
   425.8 + * This code is free software; you can redistribute it and/or modify it
   425.9 + * under the terms of the GNU General Public License version 2 only, as
  425.10 + * published by the Free Software Foundation.  Oracle designates this
  425.11 + * particular file as subject to the "Classpath" exception as provided
  425.12 + * by Oracle in the LICENSE file that accompanied this code.
  425.13 + *
  425.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  425.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  425.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  425.17 + * version 2 for more details (a copy is included in the LICENSE file that
  425.18 + * accompanied this code).
  425.19 + *
  425.20 + * You should have received a copy of the GNU General Public License version
  425.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  425.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  425.23 + *
  425.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  425.25 + * or visit www.oracle.com if you need additional information or have any
  425.26 + * questions.
  425.27 + */
  425.28 +
  425.29 +package java.lang;
  425.30 +
  425.31 +/**
  425.32 + * Thrown to indicate that an assertion has failed.
  425.33 + *
  425.34 + * <p>The seven one-argument public constructors provided by this
  425.35 + * class ensure that the assertion error returned by the invocation:
  425.36 + * <pre>
  425.37 + *     new AssertionError(<i>expression</i>)
  425.38 + * </pre>
  425.39 + * has as its detail message the <i>string conversion</i> of
  425.40 + * <i>expression</i> (as defined in section 15.18.1.1 of
  425.41 + * <cite>The Java&trade; Language Specification</cite>),
  425.42 + * regardless of the type of <i>expression</i>.
  425.43 + *
  425.44 + * @since   1.4
  425.45 + */
  425.46 +public class AssertionError extends Error {
  425.47 +    private static final long serialVersionUID = -5013299493970297370L;
  425.48 +
  425.49 +    /**
  425.50 +     * Constructs an AssertionError with no detail message.
  425.51 +     */
  425.52 +    public AssertionError() {
  425.53 +    }
  425.54 +
  425.55 +    /**
  425.56 +     * This internal constructor does no processing on its string argument,
  425.57 +     * even if it is a null reference.  The public constructors will
  425.58 +     * never call this constructor with a null argument.
  425.59 +     */
  425.60 +    private AssertionError(String detailMessage) {
  425.61 +        super(detailMessage);
  425.62 +    }
  425.63 +
  425.64 +    /**
  425.65 +     * Constructs an AssertionError with its detail message derived
  425.66 +     * from the specified object, which is converted to a string as
  425.67 +     * defined in section 15.18.1.1 of
  425.68 +     * <cite>The Java&trade; Language Specification</cite>.
  425.69 +     *<p>
  425.70 +     * If the specified object is an instance of {@code Throwable}, it
  425.71 +     * becomes the <i>cause</i> of the newly constructed assertion error.
  425.72 +     *
  425.73 +     * @param detailMessage value to be used in constructing detail message
  425.74 +     * @see   Throwable#getCause()
  425.75 +     */
  425.76 +    public AssertionError(Object detailMessage) {
  425.77 +        this("" +  detailMessage);
  425.78 +        if (detailMessage instanceof Throwable)
  425.79 +            initCause((Throwable) detailMessage);
  425.80 +    }
  425.81 +
  425.82 +    /**
  425.83 +     * Constructs an AssertionError with its detail message derived
  425.84 +     * from the specified <code>boolean</code>, which is converted to
  425.85 +     * a string as defined in section 15.18.1.1 of
  425.86 +     * <cite>The Java&trade; Language Specification</cite>.
  425.87 +     *
  425.88 +     * @param detailMessage value to be used in constructing detail message
  425.89 +     */
  425.90 +    public AssertionError(boolean detailMessage) {
  425.91 +        this("" +  detailMessage);
  425.92 +    }
  425.93 +
  425.94 +    /**
  425.95 +     * Constructs an AssertionError with its detail message derived
  425.96 +     * from the specified <code>char</code>, which is converted to a
  425.97 +     * string as defined in section 15.18.1.1 of
  425.98 +     * <cite>The Java&trade; Language Specification</cite>.
  425.99 +     *
 425.100 +     * @param detailMessage value to be used in constructing detail message
 425.101 +     */
 425.102 +    public AssertionError(char detailMessage) {
 425.103 +        this("" +  detailMessage);
 425.104 +    }
 425.105 +
 425.106 +    /**
 425.107 +     * Constructs an AssertionError with its detail message derived
 425.108 +     * from the specified <code>int</code>, which is converted to a
 425.109 +     * string as defined in section 15.18.1.1 of
 425.110 +     * <cite>The Java&trade; Language Specification</cite>.
 425.111 +     *
 425.112 +     * @param detailMessage value to be used in constructing detail message
 425.113 +     */
 425.114 +    public AssertionError(int detailMessage) {
 425.115 +        this("" +  detailMessage);
 425.116 +    }
 425.117 +
 425.118 +    /**
 425.119 +     * Constructs an AssertionError with its detail message derived
 425.120 +     * from the specified <code>long</code>, which is converted to a
 425.121 +     * string as defined in section 15.18.1.1 of
 425.122 +     * <cite>The Java&trade; Language Specification</cite>.
 425.123 +     *
 425.124 +     * @param detailMessage value to be used in constructing detail message
 425.125 +     */
 425.126 +    public AssertionError(long detailMessage) {
 425.127 +        this("" +  detailMessage);
 425.128 +    }
 425.129 +
 425.130 +    /**
 425.131 +     * Constructs an AssertionError with its detail message derived
 425.132 +     * from the specified <code>float</code>, which is converted to a
 425.133 +     * string as defined in section 15.18.1.1 of
 425.134 +     * <cite>The Java&trade; Language Specification</cite>.
 425.135 +     *
 425.136 +     * @param detailMessage value to be used in constructing detail message
 425.137 +     */
 425.138 +    public AssertionError(float detailMessage) {
 425.139 +        this("" +  detailMessage);
 425.140 +    }
 425.141 +
 425.142 +    /**
 425.143 +     * Constructs an AssertionError with its detail message derived
 425.144 +     * from the specified <code>double</code>, which is converted to a
 425.145 +     * string as defined in section 15.18.1.1 of
 425.146 +     * <cite>The Java&trade; Language Specification</cite>.
 425.147 +     *
 425.148 +     * @param detailMessage value to be used in constructing detail message
 425.149 +     */
 425.150 +    public AssertionError(double detailMessage) {
 425.151 +        this("" +  detailMessage);
 425.152 +    }
 425.153 +
 425.154 +    /**
 425.155 +     * Constructs a new {@code AssertionError} with the specified
 425.156 +     * detail message and cause.
 425.157 +     *
 425.158 +     * <p>Note that the detail message associated with
 425.159 +     * {@code cause} is <i>not</i> automatically incorporated in
 425.160 +     * this error's detail message.
 425.161 +     *
 425.162 +     * @param  message the detail message, may be {@code null}
 425.163 +     * @param  cause the cause, may be {@code null}
 425.164 +     *
 425.165 +     * @since 1.7
 425.166 +     */
 425.167 +    public AssertionError(String message, Throwable cause) {
 425.168 +        super(message, cause);
 425.169 +    }
 425.170 +}
   426.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   426.2 +++ b/rt/emul/mini/src/main/java/java/lang/AutoCloseable.java	Wed Feb 27 11:24:58 2013 +0100
   426.3 @@ -0,0 +1,72 @@
   426.4 +/*
   426.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   426.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   426.7 + *
   426.8 + * This code is free software; you can redistribute it and/or modify it
   426.9 + * under the terms of the GNU General Public License version 2 only, as
  426.10 + * published by the Free Software Foundation.  Oracle designates this
  426.11 + * particular file as subject to the "Classpath" exception as provided
  426.12 + * by Oracle in the LICENSE file that accompanied this code.
  426.13 + *
  426.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  426.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  426.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  426.17 + * version 2 for more details (a copy is included in the LICENSE file that
  426.18 + * accompanied this code).
  426.19 + *
  426.20 + * You should have received a copy of the GNU General Public License version
  426.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  426.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  426.23 + *
  426.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  426.25 + * or visit www.oracle.com if you need additional information or have any
  426.26 + * questions.
  426.27 + */
  426.28 +
  426.29 +package java.lang;
  426.30 +
  426.31 +/**
  426.32 + * A resource that must be closed when it is no longer needed.
  426.33 + *
  426.34 + * @author Josh Bloch
  426.35 + * @since 1.7
  426.36 + */
  426.37 +public interface AutoCloseable {
  426.38 +    /**
  426.39 +     * Closes this resource, relinquishing any underlying resources.
  426.40 +     * This method is invoked automatically on objects managed by the
  426.41 +     * {@code try}-with-resources statement.
  426.42 +     *
  426.43 +     * <p>While this interface method is declared to throw {@code
  426.44 +     * Exception}, implementers are <em>strongly</em> encouraged to
  426.45 +     * declare concrete implementations of the {@code close} method to
  426.46 +     * throw more specific exceptions, or to throw no exception at all
  426.47 +     * if the close operation cannot fail.
  426.48 +     *
  426.49 +     * <p><em>Implementers of this interface are also strongly advised
  426.50 +     * to not have the {@code close} method throw {@link
  426.51 +     * InterruptedException}.</em>
  426.52 +     *
  426.53 +     * This exception interacts with a thread's interrupted status,
  426.54 +     * and runtime misbehavior is likely to occur if an {@code
  426.55 +     * InterruptedException} is {@linkplain Throwable#addSuppressed
  426.56 +     * suppressed}.
  426.57 +     *
  426.58 +     * More generally, if it would cause problems for an
  426.59 +     * exception to be suppressed, the {@code AutoCloseable.close}
  426.60 +     * method should not throw it.
  426.61 +     *
  426.62 +     * <p>Note that unlike the {@link java.io.Closeable#close close}
  426.63 +     * method of {@link java.io.Closeable}, this {@code close} method
  426.64 +     * is <em>not</em> required to be idempotent.  In other words,
  426.65 +     * calling this {@code close} method more than once may have some
  426.66 +     * visible side effect, unlike {@code Closeable.close} which is
  426.67 +     * required to have no effect if called more than once.
  426.68 +     *
  426.69 +     * However, implementers of this interface are strongly encouraged
  426.70 +     * to make their {@code close} methods idempotent.
  426.71 +     *
  426.72 +     * @throws Exception if this resource cannot be closed
  426.73 +     */
  426.74 +    void close() throws Exception;
  426.75 +}
   427.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   427.2 +++ b/rt/emul/mini/src/main/java/java/lang/Boolean.java	Wed Feb 27 11:24:58 2013 +0100
   427.3 @@ -0,0 +1,282 @@
   427.4 +/*
   427.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
   427.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   427.7 + *
   427.8 + * This code is free software; you can redistribute it and/or modify it
   427.9 + * under the terms of the GNU General Public License version 2 only, as
  427.10 + * published by the Free Software Foundation.  Oracle designates this
  427.11 + * particular file as subject to the "Classpath" exception as provided
  427.12 + * by Oracle in the LICENSE file that accompanied this code.
  427.13 + *
  427.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  427.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  427.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  427.17 + * version 2 for more details (a copy is included in the LICENSE file that
  427.18 + * accompanied this code).
  427.19 + *
  427.20 + * You should have received a copy of the GNU General Public License version
  427.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  427.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  427.23 + *
  427.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  427.25 + * or visit www.oracle.com if you need additional information or have any
  427.26 + * questions.
  427.27 + */
  427.28 +
  427.29 +package java.lang;
  427.30 +
  427.31 +/**
  427.32 + * The Boolean class wraps a value of the primitive type
  427.33 + * {@code boolean} in an object. An object of type
  427.34 + * {@code Boolean} contains a single field whose type is
  427.35 + * {@code boolean}.
  427.36 + * <p>
  427.37 + * In addition, this class provides many methods for
  427.38 + * converting a {@code boolean} to a {@code String} and a
  427.39 + * {@code String} to a {@code boolean}, as well as other
  427.40 + * constants and methods useful when dealing with a
  427.41 + * {@code boolean}.
  427.42 + *
  427.43 + * @author  Arthur van Hoff
  427.44 + * @since   JDK1.0
  427.45 + */
  427.46 +public final class Boolean implements java.io.Serializable,
  427.47 +                                      Comparable<Boolean>
  427.48 +{
  427.49 +    /**
  427.50 +     * The {@code Boolean} object corresponding to the primitive
  427.51 +     * value {@code true}.
  427.52 +     */
  427.53 +    public static final Boolean TRUE = new Boolean(true);
  427.54 +
  427.55 +    /**
  427.56 +     * The {@code Boolean} object corresponding to the primitive
  427.57 +     * value {@code false}.
  427.58 +     */
  427.59 +    public static final Boolean FALSE = new Boolean(false);
  427.60 +
  427.61 +    /**
  427.62 +     * The Class object representing the primitive type boolean.
  427.63 +     *
  427.64 +     * @since   JDK1.1
  427.65 +     */
  427.66 +    public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
  427.67 +
  427.68 +    /**
  427.69 +     * The value of the Boolean.
  427.70 +     *
  427.71 +     * @serial
  427.72 +     */
  427.73 +    private final boolean value;
  427.74 +
  427.75 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  427.76 +    private static final long serialVersionUID = -3665804199014368530L;
  427.77 +
  427.78 +    /**
  427.79 +     * Allocates a {@code Boolean} object representing the
  427.80 +     * {@code value} argument.
  427.81 +     *
  427.82 +     * <p><b>Note: It is rarely appropriate to use this constructor.
  427.83 +     * Unless a <i>new</i> instance is required, the static factory
  427.84 +     * {@link #valueOf(boolean)} is generally a better choice. It is
  427.85 +     * likely to yield significantly better space and time performance.</b>
  427.86 +     *
  427.87 +     * @param   value   the value of the {@code Boolean}.
  427.88 +     */
  427.89 +    public Boolean(boolean value) {
  427.90 +        this.value = value;
  427.91 +    }
  427.92 +
  427.93 +    /**
  427.94 +     * Allocates a {@code Boolean} object representing the value
  427.95 +     * {@code true} if the string argument is not {@code null}
  427.96 +     * and is equal, ignoring case, to the string {@code "true"}.
  427.97 +     * Otherwise, allocate a {@code Boolean} object representing the
  427.98 +     * value {@code false}. Examples:<p>
  427.99 +     * {@code new Boolean("True")} produces a {@code Boolean} object
 427.100 +     * that represents {@code true}.<br>
 427.101 +     * {@code new Boolean("yes")} produces a {@code Boolean} object
 427.102 +     * that represents {@code false}.
 427.103 +     *
 427.104 +     * @param   s   the string to be converted to a {@code Boolean}.
 427.105 +     */
 427.106 +    public Boolean(String s) {
 427.107 +        this(toBoolean(s));
 427.108 +    }
 427.109 +
 427.110 +    /**
 427.111 +     * Parses the string argument as a boolean.  The {@code boolean}
 427.112 +     * returned represents the value {@code true} if the string argument
 427.113 +     * is not {@code null} and is equal, ignoring case, to the string
 427.114 +     * {@code "true"}. <p>
 427.115 +     * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
 427.116 +     * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
 427.117 +     *
 427.118 +     * @param      s   the {@code String} containing the boolean
 427.119 +     *                 representation to be parsed
 427.120 +     * @return     the boolean represented by the string argument
 427.121 +     * @since 1.5
 427.122 +     */
 427.123 +    public static boolean parseBoolean(String s) {
 427.124 +        return toBoolean(s);
 427.125 +    }
 427.126 +
 427.127 +    /**
 427.128 +     * Returns the value of this {@code Boolean} object as a boolean
 427.129 +     * primitive.
 427.130 +     *
 427.131 +     * @return  the primitive {@code boolean} value of this object.
 427.132 +     */
 427.133 +    public boolean booleanValue() {
 427.134 +        return value;
 427.135 +    }
 427.136 +
 427.137 +    /**
 427.138 +     * Returns a {@code Boolean} instance representing the specified
 427.139 +     * {@code boolean} value.  If the specified {@code boolean} value
 427.140 +     * is {@code true}, this method returns {@code Boolean.TRUE};
 427.141 +     * if it is {@code false}, this method returns {@code Boolean.FALSE}.
 427.142 +     * If a new {@code Boolean} instance is not required, this method
 427.143 +     * should generally be used in preference to the constructor
 427.144 +     * {@link #Boolean(boolean)}, as this method is likely to yield
 427.145 +     * significantly better space and time performance.
 427.146 +     *
 427.147 +     * @param  b a boolean value.
 427.148 +     * @return a {@code Boolean} instance representing {@code b}.
 427.149 +     * @since  1.4
 427.150 +     */
 427.151 +    public static Boolean valueOf(boolean b) {
 427.152 +        return (b ? TRUE : FALSE);
 427.153 +    }
 427.154 +
 427.155 +    /**
 427.156 +     * Returns a {@code Boolean} with a value represented by the
 427.157 +     * specified string.  The {@code Boolean} returned represents a
 427.158 +     * true value if the string argument is not {@code null}
 427.159 +     * and is equal, ignoring case, to the string {@code "true"}.
 427.160 +     *
 427.161 +     * @param   s   a string.
 427.162 +     * @return  the {@code Boolean} value represented by the string.
 427.163 +     */
 427.164 +    public static Boolean valueOf(String s) {
 427.165 +        return toBoolean(s) ? TRUE : FALSE;
 427.166 +    }
 427.167 +
 427.168 +    /**
 427.169 +     * Returns a {@code String} object representing the specified
 427.170 +     * boolean.  If the specified boolean is {@code true}, then
 427.171 +     * the string {@code "true"} will be returned, otherwise the
 427.172 +     * string {@code "false"} will be returned.
 427.173 +     *
 427.174 +     * @param b the boolean to be converted
 427.175 +     * @return the string representation of the specified {@code boolean}
 427.176 +     * @since 1.4
 427.177 +     */
 427.178 +    public static String toString(boolean b) {
 427.179 +        return b ? "true" : "false";
 427.180 +    }
 427.181 +
 427.182 +    /**
 427.183 +     * Returns a {@code String} object representing this Boolean's
 427.184 +     * value.  If this object represents the value {@code true},
 427.185 +     * a string equal to {@code "true"} is returned. Otherwise, a
 427.186 +     * string equal to {@code "false"} is returned.
 427.187 +     *
 427.188 +     * @return  a string representation of this object.
 427.189 +     */
 427.190 +    public String toString() {
 427.191 +        return value ? "true" : "false";
 427.192 +    }
 427.193 +
 427.194 +    /**
 427.195 +     * Returns a hash code for this {@code Boolean} object.
 427.196 +     *
 427.197 +     * @return  the integer {@code 1231} if this object represents
 427.198 +     * {@code true}; returns the integer {@code 1237} if this
 427.199 +     * object represents {@code false}.
 427.200 +     */
 427.201 +    public int hashCode() {
 427.202 +        return value ? 1231 : 1237;
 427.203 +    }
 427.204 +
 427.205 +    /**
 427.206 +     * Returns {@code true} if and only if the argument is not
 427.207 +     * {@code null} and is a {@code Boolean} object that
 427.208 +     * represents the same {@code boolean} value as this object.
 427.209 +     *
 427.210 +     * @param   obj   the object to compare with.
 427.211 +     * @return  {@code true} if the Boolean objects represent the
 427.212 +     *          same value; {@code false} otherwise.
 427.213 +     */
 427.214 +    public boolean equals(Object obj) {
 427.215 +        if (obj instanceof Boolean) {
 427.216 +            return value == ((Boolean)obj).booleanValue();
 427.217 +        }
 427.218 +        return false;
 427.219 +    }
 427.220 +
 427.221 +    /**
 427.222 +     * Returns {@code true} if and only if the system property
 427.223 +     * named by the argument exists and is equal to the string
 427.224 +     * {@code "true"}. (Beginning with version 1.0.2 of the
 427.225 +     * Java<small><sup>TM</sup></small> platform, the test of
 427.226 +     * this string is case insensitive.) A system property is accessible
 427.227 +     * through {@code getProperty}, a method defined by the
 427.228 +     * {@code System} class.
 427.229 +     * <p>
 427.230 +     * If there is no property with the specified name, or if the specified
 427.231 +     * name is empty or null, then {@code false} is returned.
 427.232 +     *
 427.233 +     * @param   name   the system property name.
 427.234 +     * @return  the {@code boolean} value of the system property.
 427.235 +     * @see     java.lang.System#getProperty(java.lang.String)
 427.236 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 427.237 +     */
 427.238 +    public static boolean getBoolean(String name) {
 427.239 +        boolean result = false;
 427.240 +        try {
 427.241 +            result = toBoolean(AbstractStringBuilder.getProperty(name));
 427.242 +        } catch (IllegalArgumentException e) {
 427.243 +        } catch (NullPointerException e) {
 427.244 +        }
 427.245 +        return result;
 427.246 +    }
 427.247 +
 427.248 +    /**
 427.249 +     * Compares this {@code Boolean} instance with another.
 427.250 +     *
 427.251 +     * @param   b the {@code Boolean} instance to be compared
 427.252 +     * @return  zero if this object represents the same boolean value as the
 427.253 +     *          argument; a positive value if this object represents true
 427.254 +     *          and the argument represents false; and a negative value if
 427.255 +     *          this object represents false and the argument represents true
 427.256 +     * @throws  NullPointerException if the argument is {@code null}
 427.257 +     * @see     Comparable
 427.258 +     * @since  1.5
 427.259 +     */
 427.260 +    public int compareTo(Boolean b) {
 427.261 +        return compare(this.value, b.value);
 427.262 +    }
 427.263 +
 427.264 +    /**
 427.265 +     * Compares two {@code boolean} values.
 427.266 +     * The value returned is identical to what would be returned by:
 427.267 +     * <pre>
 427.268 +     *    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
 427.269 +     * </pre>
 427.270 +     *
 427.271 +     * @param  x the first {@code boolean} to compare
 427.272 +     * @param  y the second {@code boolean} to compare
 427.273 +     * @return the value {@code 0} if {@code x == y};
 427.274 +     *         a value less than {@code 0} if {@code !x && y}; and
 427.275 +     *         a value greater than {@code 0} if {@code x && !y}
 427.276 +     * @since 1.7
 427.277 +     */
 427.278 +    public static int compare(boolean x, boolean y) {
 427.279 +        return (x == y) ? 0 : (x ? 1 : -1);
 427.280 +    }
 427.281 +
 427.282 +    private static boolean toBoolean(String name) {
 427.283 +        return ((name != null) && name.equalsIgnoreCase("true"));
 427.284 +    }
 427.285 +}
   428.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   428.2 +++ b/rt/emul/mini/src/main/java/java/lang/Byte.java	Wed Feb 27 11:24:58 2013 +0100
   428.3 @@ -0,0 +1,452 @@
   428.4 +/*
   428.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   428.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   428.7 + *
   428.8 + * This code is free software; you can redistribute it and/or modify it
   428.9 + * under the terms of the GNU General Public License version 2 only, as
  428.10 + * published by the Free Software Foundation.  Oracle designates this
  428.11 + * particular file as subject to the "Classpath" exception as provided
  428.12 + * by Oracle in the LICENSE file that accompanied this code.
  428.13 + *
  428.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  428.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  428.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  428.17 + * version 2 for more details (a copy is included in the LICENSE file that
  428.18 + * accompanied this code).
  428.19 + *
  428.20 + * You should have received a copy of the GNU General Public License version
  428.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  428.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  428.23 + *
  428.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  428.25 + * or visit www.oracle.com if you need additional information or have any
  428.26 + * questions.
  428.27 + */
  428.28 +
  428.29 +package java.lang;
  428.30 +
  428.31 +/**
  428.32 + *
  428.33 + * The {@code Byte} class wraps a value of primitive type {@code byte}
  428.34 + * in an object.  An object of type {@code Byte} contains a single
  428.35 + * field whose type is {@code byte}.
  428.36 + *
  428.37 + * <p>In addition, this class provides several methods for converting
  428.38 + * a {@code byte} to a {@code String} and a {@code String} to a {@code
  428.39 + * byte}, as well as other constants and methods useful when dealing
  428.40 + * with a {@code byte}.
  428.41 + *
  428.42 + * @author  Nakul Saraiya
  428.43 + * @author  Joseph D. Darcy
  428.44 + * @see     java.lang.Number
  428.45 + * @since   JDK1.1
  428.46 + */
  428.47 +public final class Byte extends Number implements Comparable<Byte> {
  428.48 +
  428.49 +    /**
  428.50 +     * A constant holding the minimum value a {@code byte} can
  428.51 +     * have, -2<sup>7</sup>.
  428.52 +     */
  428.53 +    public static final byte   MIN_VALUE = -128;
  428.54 +
  428.55 +    /**
  428.56 +     * A constant holding the maximum value a {@code byte} can
  428.57 +     * have, 2<sup>7</sup>-1.
  428.58 +     */
  428.59 +    public static final byte   MAX_VALUE = 127;
  428.60 +
  428.61 +    /**
  428.62 +     * The {@code Class} instance representing the primitive type
  428.63 +     * {@code byte}.
  428.64 +     */
  428.65 +    public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
  428.66 +
  428.67 +    /**
  428.68 +     * Returns a new {@code String} object representing the
  428.69 +     * specified {@code byte}. The radix is assumed to be 10.
  428.70 +     *
  428.71 +     * @param b the {@code byte} to be converted
  428.72 +     * @return the string representation of the specified {@code byte}
  428.73 +     * @see java.lang.Integer#toString(int)
  428.74 +     */
  428.75 +    public static String toString(byte b) {
  428.76 +        return Integer.toString((int)b, 10);
  428.77 +    }
  428.78 +
  428.79 +    private static class ByteCache {
  428.80 +        private ByteCache(){}
  428.81 +
  428.82 +        static final Byte cache[] = new Byte[-(-128) + 127 + 1];
  428.83 +
  428.84 +        static {
  428.85 +            for(int i = 0; i < cache.length; i++)
  428.86 +                cache[i] = new Byte((byte)(i - 128));
  428.87 +        }
  428.88 +    }
  428.89 +
  428.90 +    /**
  428.91 +     * Returns a {@code Byte} instance representing the specified
  428.92 +     * {@code byte} value.
  428.93 +     * If a new {@code Byte} instance is not required, this method
  428.94 +     * should generally be used in preference to the constructor
  428.95 +     * {@link #Byte(byte)}, as this method is likely to yield
  428.96 +     * significantly better space and time performance since
  428.97 +     * all byte values are cached.
  428.98 +     *
  428.99 +     * @param  b a byte value.
 428.100 +     * @return a {@code Byte} instance representing {@code b}.
 428.101 +     * @since  1.5
 428.102 +     */
 428.103 +    public static Byte valueOf(byte b) {
 428.104 +        final int offset = 128;
 428.105 +        return ByteCache.cache[(int)b + offset];
 428.106 +    }
 428.107 +
 428.108 +    /**
 428.109 +     * Parses the string argument as a signed {@code byte} in the
 428.110 +     * radix specified by the second argument. The characters in the
 428.111 +     * string must all be digits, of the specified radix (as
 428.112 +     * determined by whether {@link java.lang.Character#digit(char,
 428.113 +     * int)} returns a nonnegative value) except that the first
 428.114 +     * character may be an ASCII minus sign {@code '-'}
 428.115 +     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 428.116 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 428.117 +     * indicate a positive value.  The resulting {@code byte} value is
 428.118 +     * returned.
 428.119 +     *
 428.120 +     * <p>An exception of type {@code NumberFormatException} is
 428.121 +     * thrown if any of the following situations occurs:
 428.122 +     * <ul>
 428.123 +     * <li> The first argument is {@code null} or is a string of
 428.124 +     * length zero.
 428.125 +     *
 428.126 +     * <li> The radix is either smaller than {@link
 428.127 +     * java.lang.Character#MIN_RADIX} or larger than {@link
 428.128 +     * java.lang.Character#MAX_RADIX}.
 428.129 +     *
 428.130 +     * <li> Any character of the string is not a digit of the
 428.131 +     * specified radix, except that the first character may be a minus
 428.132 +     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 428.133 +     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 428.134 +     * string is longer than length 1.
 428.135 +     *
 428.136 +     * <li> The value represented by the string is not a value of type
 428.137 +     * {@code byte}.
 428.138 +     * </ul>
 428.139 +     *
 428.140 +     * @param s         the {@code String} containing the
 428.141 +     *                  {@code byte}
 428.142 +     *                  representation to be parsed
 428.143 +     * @param radix     the radix to be used while parsing {@code s}
 428.144 +     * @return          the {@code byte} value represented by the string
 428.145 +     *                   argument in the specified radix
 428.146 +     * @throws          NumberFormatException If the string does
 428.147 +     *                  not contain a parsable {@code byte}.
 428.148 +     */
 428.149 +    public static byte parseByte(String s, int radix)
 428.150 +        throws NumberFormatException {
 428.151 +        int i = Integer.parseInt(s, radix);
 428.152 +        if (i < MIN_VALUE || i > MAX_VALUE)
 428.153 +            throw new NumberFormatException(
 428.154 +                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 428.155 +        return (byte)i;
 428.156 +    }
 428.157 +
 428.158 +    /**
 428.159 +     * Parses the string argument as a signed decimal {@code
 428.160 +     * byte}. The characters in the string must all be decimal digits,
 428.161 +     * except that the first character may be an ASCII minus sign
 428.162 +     * {@code '-'} (<code>'&#92;u002D'</code>) to indicate a negative
 428.163 +     * value or an ASCII plus sign {@code '+'}
 428.164 +     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 428.165 +     * resulting {@code byte} value is returned, exactly as if the
 428.166 +     * argument and the radix 10 were given as arguments to the {@link
 428.167 +     * #parseByte(java.lang.String, int)} method.
 428.168 +     *
 428.169 +     * @param s         a {@code String} containing the
 428.170 +     *                  {@code byte} representation to be parsed
 428.171 +     * @return          the {@code byte} value represented by the
 428.172 +     *                  argument in decimal
 428.173 +     * @throws          NumberFormatException if the string does not
 428.174 +     *                  contain a parsable {@code byte}.
 428.175 +     */
 428.176 +    public static byte parseByte(String s) throws NumberFormatException {
 428.177 +        return parseByte(s, 10);
 428.178 +    }
 428.179 +
 428.180 +    /**
 428.181 +     * Returns a {@code Byte} object holding the value
 428.182 +     * extracted from the specified {@code String} when parsed
 428.183 +     * with the radix given by the second argument. The first argument
 428.184 +     * is interpreted as representing a signed {@code byte} in
 428.185 +     * the radix specified by the second argument, exactly as if the
 428.186 +     * argument were given to the {@link #parseByte(java.lang.String,
 428.187 +     * int)} method. The result is a {@code Byte} object that
 428.188 +     * represents the {@code byte} value specified by the string.
 428.189 +     *
 428.190 +     * <p> In other words, this method returns a {@code Byte} object
 428.191 +     * equal to the value of:
 428.192 +     *
 428.193 +     * <blockquote>
 428.194 +     * {@code new Byte(Byte.parseByte(s, radix))}
 428.195 +     * </blockquote>
 428.196 +     *
 428.197 +     * @param s         the string to be parsed
 428.198 +     * @param radix     the radix to be used in interpreting {@code s}
 428.199 +     * @return          a {@code Byte} object holding the value
 428.200 +     *                  represented by the string argument in the
 428.201 +     *                  specified radix.
 428.202 +     * @throws          NumberFormatException If the {@code String} does
 428.203 +     *                  not contain a parsable {@code byte}.
 428.204 +     */
 428.205 +    public static Byte valueOf(String s, int radix)
 428.206 +        throws NumberFormatException {
 428.207 +        return valueOf(parseByte(s, radix));
 428.208 +    }
 428.209 +
 428.210 +    /**
 428.211 +     * Returns a {@code Byte} object holding the value
 428.212 +     * given by the specified {@code String}. The argument is
 428.213 +     * interpreted as representing a signed decimal {@code byte},
 428.214 +     * exactly as if the argument were given to the {@link
 428.215 +     * #parseByte(java.lang.String)} method. The result is a
 428.216 +     * {@code Byte} object that represents the {@code byte}
 428.217 +     * value specified by the string.
 428.218 +     *
 428.219 +     * <p> In other words, this method returns a {@code Byte} object
 428.220 +     * equal to the value of:
 428.221 +     *
 428.222 +     * <blockquote>
 428.223 +     * {@code new Byte(Byte.parseByte(s))}
 428.224 +     * </blockquote>
 428.225 +     *
 428.226 +     * @param s         the string to be parsed
 428.227 +     * @return          a {@code Byte} object holding the value
 428.228 +     *                  represented by the string argument
 428.229 +     * @throws          NumberFormatException If the {@code String} does
 428.230 +     *                  not contain a parsable {@code byte}.
 428.231 +     */
 428.232 +    public static Byte valueOf(String s) throws NumberFormatException {
 428.233 +        return valueOf(s, 10);
 428.234 +    }
 428.235 +
 428.236 +    /**
 428.237 +     * Decodes a {@code String} into a {@code Byte}.
 428.238 +     * Accepts decimal, hexadecimal, and octal numbers given by
 428.239 +     * the following grammar:
 428.240 +     *
 428.241 +     * <blockquote>
 428.242 +     * <dl>
 428.243 +     * <dt><i>DecodableString:</i>
 428.244 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 428.245 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 428.246 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 428.247 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 428.248 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 428.249 +     * <p>
 428.250 +     * <dt><i>Sign:</i>
 428.251 +     * <dd>{@code -}
 428.252 +     * <dd>{@code +}
 428.253 +     * </dl>
 428.254 +     * </blockquote>
 428.255 +     *
 428.256 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 428.257 +     * are as defined in section 3.10.1 of
 428.258 +     * <cite>The Java&trade; Language Specification</cite>,
 428.259 +     * except that underscores are not accepted between digits.
 428.260 +     *
 428.261 +     * <p>The sequence of characters following an optional
 428.262 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 428.263 +     * "{@code #}", or leading zero) is parsed as by the {@code
 428.264 +     * Byte.parseByte} method with the indicated radix (10, 16, or 8).
 428.265 +     * This sequence of characters must represent a positive value or
 428.266 +     * a {@link NumberFormatException} will be thrown.  The result is
 428.267 +     * negated if first character of the specified {@code String} is
 428.268 +     * the minus sign.  No whitespace characters are permitted in the
 428.269 +     * {@code String}.
 428.270 +     *
 428.271 +     * @param     nm the {@code String} to decode.
 428.272 +     * @return   a {@code Byte} object holding the {@code byte}
 428.273 +     *          value represented by {@code nm}
 428.274 +     * @throws  NumberFormatException  if the {@code String} does not
 428.275 +     *            contain a parsable {@code byte}.
 428.276 +     * @see java.lang.Byte#parseByte(java.lang.String, int)
 428.277 +     */
 428.278 +    public static Byte decode(String nm) throws NumberFormatException {
 428.279 +        int i = Integer.decode(nm);
 428.280 +        if (i < MIN_VALUE || i > MAX_VALUE)
 428.281 +            throw new NumberFormatException(
 428.282 +                    "Value " + i + " out of range from input " + nm);
 428.283 +        return valueOf((byte)i);
 428.284 +    }
 428.285 +
 428.286 +    /**
 428.287 +     * The value of the {@code Byte}.
 428.288 +     *
 428.289 +     * @serial
 428.290 +     */
 428.291 +    private final byte value;
 428.292 +
 428.293 +    /**
 428.294 +     * Constructs a newly allocated {@code Byte} object that
 428.295 +     * represents the specified {@code byte} value.
 428.296 +     *
 428.297 +     * @param value     the value to be represented by the
 428.298 +     *                  {@code Byte}.
 428.299 +     */
 428.300 +    public Byte(byte value) {
 428.301 +        this.value = value;
 428.302 +    }
 428.303 +
 428.304 +    /**
 428.305 +     * Constructs a newly allocated {@code Byte} object that
 428.306 +     * represents the {@code byte} value indicated by the
 428.307 +     * {@code String} parameter. The string is converted to a
 428.308 +     * {@code byte} value in exactly the manner used by the
 428.309 +     * {@code parseByte} method for radix 10.
 428.310 +     *
 428.311 +     * @param s         the {@code String} to be converted to a
 428.312 +     *                  {@code Byte}
 428.313 +     * @throws           NumberFormatException If the {@code String}
 428.314 +     *                  does not contain a parsable {@code byte}.
 428.315 +     * @see        java.lang.Byte#parseByte(java.lang.String, int)
 428.316 +     */
 428.317 +    public Byte(String s) throws NumberFormatException {
 428.318 +        this.value = parseByte(s, 10);
 428.319 +    }
 428.320 +
 428.321 +    /**
 428.322 +     * Returns the value of this {@code Byte} as a
 428.323 +     * {@code byte}.
 428.324 +     */
 428.325 +    public byte byteValue() {
 428.326 +        return value;
 428.327 +    }
 428.328 +
 428.329 +    /**
 428.330 +     * Returns the value of this {@code Byte} as a
 428.331 +     * {@code short}.
 428.332 +     */
 428.333 +    public short shortValue() {
 428.334 +        return (short)value;
 428.335 +    }
 428.336 +
 428.337 +    /**
 428.338 +     * Returns the value of this {@code Byte} as an
 428.339 +     * {@code int}.
 428.340 +     */
 428.341 +    public int intValue() {
 428.342 +        return (int)value;
 428.343 +    }
 428.344 +
 428.345 +    /**
 428.346 +     * Returns the value of this {@code Byte} as a
 428.347 +     * {@code long}.
 428.348 +     */
 428.349 +    public long longValue() {
 428.350 +        return (long)value;
 428.351 +    }
 428.352 +
 428.353 +    /**
 428.354 +     * Returns the value of this {@code Byte} as a
 428.355 +     * {@code float}.
 428.356 +     */
 428.357 +    public float floatValue() {
 428.358 +        return (float)value;
 428.359 +    }
 428.360 +
 428.361 +    /**
 428.362 +     * Returns the value of this {@code Byte} as a
 428.363 +     * {@code double}.
 428.364 +     */
 428.365 +    public double doubleValue() {
 428.366 +        return (double)value;
 428.367 +    }
 428.368 +
 428.369 +    /**
 428.370 +     * Returns a {@code String} object representing this
 428.371 +     * {@code Byte}'s value.  The value is converted to signed
 428.372 +     * decimal representation and returned as a string, exactly as if
 428.373 +     * the {@code byte} value were given as an argument to the
 428.374 +     * {@link java.lang.Byte#toString(byte)} method.
 428.375 +     *
 428.376 +     * @return  a string representation of the value of this object in
 428.377 +     *          base&nbsp;10.
 428.378 +     */
 428.379 +    public String toString() {
 428.380 +        return Integer.toString((int)value);
 428.381 +    }
 428.382 +
 428.383 +    /**
 428.384 +     * Returns a hash code for this {@code Byte}; equal to the result
 428.385 +     * of invoking {@code intValue()}.
 428.386 +     *
 428.387 +     * @return a hash code value for this {@code Byte}
 428.388 +     */
 428.389 +    public int hashCode() {
 428.390 +        return (int)value;
 428.391 +    }
 428.392 +
 428.393 +    /**
 428.394 +     * Compares this object to the specified object.  The result is
 428.395 +     * {@code true} if and only if the argument is not
 428.396 +     * {@code null} and is a {@code Byte} object that
 428.397 +     * contains the same {@code byte} value as this object.
 428.398 +     *
 428.399 +     * @param obj       the object to compare with
 428.400 +     * @return          {@code true} if the objects are the same;
 428.401 +     *                  {@code false} otherwise.
 428.402 +     */
 428.403 +    public boolean equals(Object obj) {
 428.404 +        if (obj instanceof Byte) {
 428.405 +            return value == ((Byte)obj).byteValue();
 428.406 +        }
 428.407 +        return false;
 428.408 +    }
 428.409 +
 428.410 +    /**
 428.411 +     * Compares two {@code Byte} objects numerically.
 428.412 +     *
 428.413 +     * @param   anotherByte   the {@code Byte} to be compared.
 428.414 +     * @return  the value {@code 0} if this {@code Byte} is
 428.415 +     *          equal to the argument {@code Byte}; a value less than
 428.416 +     *          {@code 0} if this {@code Byte} is numerically less
 428.417 +     *          than the argument {@code Byte}; and a value greater than
 428.418 +     *           {@code 0} if this {@code Byte} is numerically
 428.419 +     *           greater than the argument {@code Byte} (signed
 428.420 +     *           comparison).
 428.421 +     * @since   1.2
 428.422 +     */
 428.423 +    public int compareTo(Byte anotherByte) {
 428.424 +        return compare(this.value, anotherByte.value);
 428.425 +    }
 428.426 +
 428.427 +    /**
 428.428 +     * Compares two {@code byte} values numerically.
 428.429 +     * The value returned is identical to what would be returned by:
 428.430 +     * <pre>
 428.431 +     *    Byte.valueOf(x).compareTo(Byte.valueOf(y))
 428.432 +     * </pre>
 428.433 +     *
 428.434 +     * @param  x the first {@code byte} to compare
 428.435 +     * @param  y the second {@code byte} to compare
 428.436 +     * @return the value {@code 0} if {@code x == y};
 428.437 +     *         a value less than {@code 0} if {@code x < y}; and
 428.438 +     *         a value greater than {@code 0} if {@code x > y}
 428.439 +     * @since 1.7
 428.440 +     */
 428.441 +    public static int compare(byte x, byte y) {
 428.442 +        return x - y;
 428.443 +    }
 428.444 +
 428.445 +    /**
 428.446 +     * The number of bits used to represent a {@code byte} value in two's
 428.447 +     * complement binary form.
 428.448 +     *
 428.449 +     * @since 1.5
 428.450 +     */
 428.451 +    public static final int SIZE = 8;
 428.452 +
 428.453 +    /** use serialVersionUID from JDK 1.1. for interoperability */
 428.454 +    private static final long serialVersionUID = -7183698231559129828L;
 428.455 +}
   429.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   429.2 +++ b/rt/emul/mini/src/main/java/java/lang/CharSequence.java	Wed Feb 27 11:24:58 2013 +0100
   429.3 @@ -0,0 +1,111 @@
   429.4 +/*
   429.5 + * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
   429.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   429.7 + *
   429.8 + * This code is free software; you can redistribute it and/or modify it
   429.9 + * under the terms of the GNU General Public License version 2 only, as
  429.10 + * published by the Free Software Foundation.  Oracle designates this
  429.11 + * particular file as subject to the "Classpath" exception as provided
  429.12 + * by Oracle in the LICENSE file that accompanied this code.
  429.13 + *
  429.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  429.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  429.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  429.17 + * version 2 for more details (a copy is included in the LICENSE file that
  429.18 + * accompanied this code).
  429.19 + *
  429.20 + * You should have received a copy of the GNU General Public License version
  429.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  429.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  429.23 + *
  429.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  429.25 + * or visit www.oracle.com if you need additional information or have any
  429.26 + * questions.
  429.27 + */
  429.28 +
  429.29 +package java.lang;
  429.30 +
  429.31 +
  429.32 +/**
  429.33 + * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
  429.34 + * interface provides uniform, read-only access to many different kinds of
  429.35 + * <code>char</code> sequences.
  429.36 + * A <code>char</code> value represents a character in the <i>Basic
  429.37 + * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
  429.38 + * href="Character.html#unicode">Unicode Character Representation</a> for details.
  429.39 + *
  429.40 + * <p> This interface does not refine the general contracts of the {@link
  429.41 + * java.lang.Object#equals(java.lang.Object) equals} and {@link
  429.42 + * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
  429.43 + * objects that implement <tt>CharSequence</tt> is therefore, in general,
  429.44 + * undefined.  Each object may be implemented by a different class, and there
  429.45 + * is no guarantee that each class will be capable of testing its instances
  429.46 + * for equality with those of the other.  It is therefore inappropriate to use
  429.47 + * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
  429.48 + * a map. </p>
  429.49 + *
  429.50 + * @author Mike McCloskey
  429.51 + * @since 1.4
  429.52 + * @spec JSR-51
  429.53 + */
  429.54 +
  429.55 +public interface CharSequence {
  429.56 +
  429.57 +    /**
  429.58 +     * Returns the length of this character sequence.  The length is the number
  429.59 +     * of 16-bit <code>char</code>s in the sequence.</p>
  429.60 +     *
  429.61 +     * @return  the number of <code>char</code>s in this sequence
  429.62 +     */
  429.63 +    int length();
  429.64 +
  429.65 +    /**
  429.66 +     * Returns the <code>char</code> value at the specified index.  An index ranges from zero
  429.67 +     * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
  429.68 +     * index zero, the next at index one, and so on, as for array
  429.69 +     * indexing. </p>
  429.70 +     *
  429.71 +     * <p>If the <code>char</code> value specified by the index is a
  429.72 +     * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
  429.73 +     * value is returned.
  429.74 +     *
  429.75 +     * @param   index   the index of the <code>char</code> value to be returned
  429.76 +     *
  429.77 +     * @return  the specified <code>char</code> value
  429.78 +     *
  429.79 +     * @throws  IndexOutOfBoundsException
  429.80 +     *          if the <tt>index</tt> argument is negative or not less than
  429.81 +     *          <tt>length()</tt>
  429.82 +     */
  429.83 +    char charAt(int index);
  429.84 +
  429.85 +    /**
  429.86 +     * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
  429.87 +     * The subsequence starts with the <code>char</code> value at the specified index and
  429.88 +     * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
  429.89 +     * (in <code>char</code>s) of the
  429.90 +     * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
  429.91 +     * then an empty sequence is returned. </p>
  429.92 +     *
  429.93 +     * @param   start   the start index, inclusive
  429.94 +     * @param   end     the end index, exclusive
  429.95 +     *
  429.96 +     * @return  the specified subsequence
  429.97 +     *
  429.98 +     * @throws  IndexOutOfBoundsException
  429.99 +     *          if <tt>start</tt> or <tt>end</tt> are negative,
 429.100 +     *          if <tt>end</tt> is greater than <tt>length()</tt>,
 429.101 +     *          or if <tt>start</tt> is greater than <tt>end</tt>
 429.102 +     */
 429.103 +    CharSequence subSequence(int start, int end);
 429.104 +
 429.105 +    /**
 429.106 +     * Returns a string containing the characters in this sequence in the same
 429.107 +     * order as this sequence.  The length of the string will be the length of
 429.108 +     * this sequence. </p>
 429.109 +     *
 429.110 +     * @return  a string consisting of exactly this sequence of characters
 429.111 +     */
 429.112 +    public String toString();
 429.113 +
 429.114 +}
   430.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   430.2 +++ b/rt/emul/mini/src/main/java/java/lang/Character.java	Wed Feb 27 11:24:58 2013 +0100
   430.3 @@ -0,0 +1,2519 @@
   430.4 +/*
   430.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
   430.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   430.7 + *
   430.8 + * This code is free software; you can redistribute it and/or modify it
   430.9 + * under the terms of the GNU General Public License version 2 only, as
  430.10 + * published by the Free Software Foundation.  Oracle designates this
  430.11 + * particular file as subject to the "Classpath" exception as provided
  430.12 + * by Oracle in the LICENSE file that accompanied this code.
  430.13 + *
  430.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  430.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  430.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  430.17 + * version 2 for more details (a copy is included in the LICENSE file that
  430.18 + * accompanied this code).
  430.19 + *
  430.20 + * You should have received a copy of the GNU General Public License version
  430.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  430.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  430.23 + *
  430.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  430.25 + * or visit www.oracle.com if you need additional information or have any
  430.26 + * questions.
  430.27 + */
  430.28 +
  430.29 +package java.lang;
  430.30 +
  430.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  430.32 +
  430.33 +/**
  430.34 + * The {@code Character} class wraps a value of the primitive
  430.35 + * type {@code char} in an object. An object of type
  430.36 + * {@code Character} contains a single field whose type is
  430.37 + * {@code char}.
  430.38 + * <p>
  430.39 + * In addition, this class provides several methods for determining
  430.40 + * a character's category (lowercase letter, digit, etc.) and for converting
  430.41 + * characters from uppercase to lowercase and vice versa.
  430.42 + * <p>
  430.43 + * Character information is based on the Unicode Standard, version 6.0.0.
  430.44 + * <p>
  430.45 + * The methods and data of class {@code Character} are defined by
  430.46 + * the information in the <i>UnicodeData</i> file that is part of the
  430.47 + * Unicode Character Database maintained by the Unicode
  430.48 + * Consortium. This file specifies various properties including name
  430.49 + * and general category for every defined Unicode code point or
  430.50 + * character range.
  430.51 + * <p>
  430.52 + * The file and its description are available from the Unicode Consortium at:
  430.53 + * <ul>
  430.54 + * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
  430.55 + * </ul>
  430.56 + *
  430.57 + * <h4><a name="unicode">Unicode Character Representations</a></h4>
  430.58 + *
  430.59 + * <p>The {@code char} data type (and therefore the value that a
  430.60 + * {@code Character} object encapsulates) are based on the
  430.61 + * original Unicode specification, which defined characters as
  430.62 + * fixed-width 16-bit entities. The Unicode Standard has since been
  430.63 + * changed to allow for characters whose representation requires more
  430.64 + * than 16 bits.  The range of legal <em>code point</em>s is now
  430.65 + * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
  430.66 + * (Refer to the <a
  430.67 + * href="http://www.unicode.org/reports/tr27/#notation"><i>
  430.68 + * definition</i></a> of the U+<i>n</i> notation in the Unicode
  430.69 + * Standard.)
  430.70 + *
  430.71 + * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
  430.72 + * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
  430.73 + * <a name="supplementary">Characters</a> whose code points are greater
  430.74 + * than U+FFFF are called <em>supplementary character</em>s.  The Java
  430.75 + * platform uses the UTF-16 representation in {@code char} arrays and
  430.76 + * in the {@code String} and {@code StringBuffer} classes. In
  430.77 + * this representation, supplementary characters are represented as a pair
  430.78 + * of {@code char} values, the first from the <em>high-surrogates</em>
  430.79 + * range, (&#92;uD800-&#92;uDBFF), the second from the
  430.80 + * <em>low-surrogates</em> range (&#92;uDC00-&#92;uDFFF).
  430.81 + *
  430.82 + * <p>A {@code char} value, therefore, represents Basic
  430.83 + * Multilingual Plane (BMP) code points, including the surrogate
  430.84 + * code points, or code units of the UTF-16 encoding. An
  430.85 + * {@code int} value represents all Unicode code points,
  430.86 + * including supplementary code points. The lower (least significant)
  430.87 + * 21 bits of {@code int} are used to represent Unicode code
  430.88 + * points and the upper (most significant) 11 bits must be zero.
  430.89 + * Unless otherwise specified, the behavior with respect to
  430.90 + * supplementary characters and surrogate {@code char} values is
  430.91 + * as follows:
  430.92 + *
  430.93 + * <ul>
  430.94 + * <li>The methods that only accept a {@code char} value cannot support
  430.95 + * supplementary characters. They treat {@code char} values from the
  430.96 + * surrogate ranges as undefined characters. For example,
  430.97 + * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
  430.98 + * this specific value if followed by any low-surrogate value in a string
  430.99 + * would represent a letter.
 430.100 + *
 430.101 + * <li>The methods that accept an {@code int} value support all
 430.102 + * Unicode characters, including supplementary characters. For
 430.103 + * example, {@code Character.isLetter(0x2F81A)} returns
 430.104 + * {@code true} because the code point value represents a letter
 430.105 + * (a CJK ideograph).
 430.106 + * </ul>
 430.107 + *
 430.108 + * <p>In the Java SE API documentation, <em>Unicode code point</em> is
 430.109 + * used for character values in the range between U+0000 and U+10FFFF,
 430.110 + * and <em>Unicode code unit</em> is used for 16-bit
 430.111 + * {@code char} values that are code units of the <em>UTF-16</em>
 430.112 + * encoding. For more information on Unicode terminology, refer to the
 430.113 + * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
 430.114 + *
 430.115 + * @author  Lee Boynton
 430.116 + * @author  Guy Steele
 430.117 + * @author  Akira Tanaka
 430.118 + * @author  Martin Buchholz
 430.119 + * @author  Ulf Zibis
 430.120 + * @since   1.0
 430.121 + */
 430.122 +public final
 430.123 +class Character implements java.io.Serializable, Comparable<Character> {
 430.124 +    /**
 430.125 +     * The minimum radix available for conversion to and from strings.
 430.126 +     * The constant value of this field is the smallest value permitted
 430.127 +     * for the radix argument in radix-conversion methods such as the
 430.128 +     * {@code digit} method, the {@code forDigit} method, and the
 430.129 +     * {@code toString} method of class {@code Integer}.
 430.130 +     *
 430.131 +     * @see     Character#digit(char, int)
 430.132 +     * @see     Character#forDigit(int, int)
 430.133 +     * @see     Integer#toString(int, int)
 430.134 +     * @see     Integer#valueOf(String)
 430.135 +     */
 430.136 +    public static final int MIN_RADIX = 2;
 430.137 +
 430.138 +    /**
 430.139 +     * The maximum radix available for conversion to and from strings.
 430.140 +     * The constant value of this field is the largest value permitted
 430.141 +     * for the radix argument in radix-conversion methods such as the
 430.142 +     * {@code digit} method, the {@code forDigit} method, and the
 430.143 +     * {@code toString} method of class {@code Integer}.
 430.144 +     *
 430.145 +     * @see     Character#digit(char, int)
 430.146 +     * @see     Character#forDigit(int, int)
 430.147 +     * @see     Integer#toString(int, int)
 430.148 +     * @see     Integer#valueOf(String)
 430.149 +     */
 430.150 +    public static final int MAX_RADIX = 36;
 430.151 +
 430.152 +    /**
 430.153 +     * The constant value of this field is the smallest value of type
 430.154 +     * {@code char}, {@code '\u005Cu0000'}.
 430.155 +     *
 430.156 +     * @since   1.0.2
 430.157 +     */
 430.158 +    public static final char MIN_VALUE = '\u0000';
 430.159 +
 430.160 +    /**
 430.161 +     * The constant value of this field is the largest value of type
 430.162 +     * {@code char}, {@code '\u005CuFFFF'}.
 430.163 +     *
 430.164 +     * @since   1.0.2
 430.165 +     */
 430.166 +    public static final char MAX_VALUE = '\uFFFF';
 430.167 +
 430.168 +    /**
 430.169 +     * The {@code Class} instance representing the primitive type
 430.170 +     * {@code char}.
 430.171 +     *
 430.172 +     * @since   1.1
 430.173 +     */
 430.174 +    public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
 430.175 +
 430.176 +    /*
 430.177 +     * Normative general types
 430.178 +     */
 430.179 +
 430.180 +    /*
 430.181 +     * General character types
 430.182 +     */
 430.183 +
 430.184 +    /**
 430.185 +     * General category "Cn" in the Unicode specification.
 430.186 +     * @since   1.1
 430.187 +     */
 430.188 +    public static final byte UNASSIGNED = 0;
 430.189 +
 430.190 +    /**
 430.191 +     * General category "Lu" in the Unicode specification.
 430.192 +     * @since   1.1
 430.193 +     */
 430.194 +    public static final byte UPPERCASE_LETTER = 1;
 430.195 +
 430.196 +    /**
 430.197 +     * General category "Ll" in the Unicode specification.
 430.198 +     * @since   1.1
 430.199 +     */
 430.200 +    public static final byte LOWERCASE_LETTER = 2;
 430.201 +
 430.202 +    /**
 430.203 +     * General category "Lt" in the Unicode specification.
 430.204 +     * @since   1.1
 430.205 +     */
 430.206 +    public static final byte TITLECASE_LETTER = 3;
 430.207 +
 430.208 +    /**
 430.209 +     * General category "Lm" in the Unicode specification.
 430.210 +     * @since   1.1
 430.211 +     */
 430.212 +    public static final byte MODIFIER_LETTER = 4;
 430.213 +
 430.214 +    /**
 430.215 +     * General category "Lo" in the Unicode specification.
 430.216 +     * @since   1.1
 430.217 +     */
 430.218 +    public static final byte OTHER_LETTER = 5;
 430.219 +
 430.220 +    /**
 430.221 +     * General category "Mn" in the Unicode specification.
 430.222 +     * @since   1.1
 430.223 +     */
 430.224 +    public static final byte NON_SPACING_MARK = 6;
 430.225 +
 430.226 +    /**
 430.227 +     * General category "Me" in the Unicode specification.
 430.228 +     * @since   1.1
 430.229 +     */
 430.230 +    public static final byte ENCLOSING_MARK = 7;
 430.231 +
 430.232 +    /**
 430.233 +     * General category "Mc" in the Unicode specification.
 430.234 +     * @since   1.1
 430.235 +     */
 430.236 +    public static final byte COMBINING_SPACING_MARK = 8;
 430.237 +
 430.238 +    /**
 430.239 +     * General category "Nd" in the Unicode specification.
 430.240 +     * @since   1.1
 430.241 +     */
 430.242 +    public static final byte DECIMAL_DIGIT_NUMBER        = 9;
 430.243 +
 430.244 +    /**
 430.245 +     * General category "Nl" in the Unicode specification.
 430.246 +     * @since   1.1
 430.247 +     */
 430.248 +    public static final byte LETTER_NUMBER = 10;
 430.249 +
 430.250 +    /**
 430.251 +     * General category "No" in the Unicode specification.
 430.252 +     * @since   1.1
 430.253 +     */
 430.254 +    public static final byte OTHER_NUMBER = 11;
 430.255 +
 430.256 +    /**
 430.257 +     * General category "Zs" in the Unicode specification.
 430.258 +     * @since   1.1
 430.259 +     */
 430.260 +    public static final byte SPACE_SEPARATOR = 12;
 430.261 +
 430.262 +    /**
 430.263 +     * General category "Zl" in the Unicode specification.
 430.264 +     * @since   1.1
 430.265 +     */
 430.266 +    public static final byte LINE_SEPARATOR = 13;
 430.267 +
 430.268 +    /**
 430.269 +     * General category "Zp" in the Unicode specification.
 430.270 +     * @since   1.1
 430.271 +     */
 430.272 +    public static final byte PARAGRAPH_SEPARATOR = 14;
 430.273 +
 430.274 +    /**
 430.275 +     * General category "Cc" in the Unicode specification.
 430.276 +     * @since   1.1
 430.277 +     */
 430.278 +    public static final byte CONTROL = 15;
 430.279 +
 430.280 +    /**
 430.281 +     * General category "Cf" in the Unicode specification.
 430.282 +     * @since   1.1
 430.283 +     */
 430.284 +    public static final byte FORMAT = 16;
 430.285 +
 430.286 +    /**
 430.287 +     * General category "Co" in the Unicode specification.
 430.288 +     * @since   1.1
 430.289 +     */
 430.290 +    public static final byte PRIVATE_USE = 18;
 430.291 +
 430.292 +    /**
 430.293 +     * General category "Cs" in the Unicode specification.
 430.294 +     * @since   1.1
 430.295 +     */
 430.296 +    public static final byte SURROGATE = 19;
 430.297 +
 430.298 +    /**
 430.299 +     * General category "Pd" in the Unicode specification.
 430.300 +     * @since   1.1
 430.301 +     */
 430.302 +    public static final byte DASH_PUNCTUATION = 20;
 430.303 +
 430.304 +    /**
 430.305 +     * General category "Ps" in the Unicode specification.
 430.306 +     * @since   1.1
 430.307 +     */
 430.308 +    public static final byte START_PUNCTUATION = 21;
 430.309 +
 430.310 +    /**
 430.311 +     * General category "Pe" in the Unicode specification.
 430.312 +     * @since   1.1
 430.313 +     */
 430.314 +    public static final byte END_PUNCTUATION = 22;
 430.315 +
 430.316 +    /**
 430.317 +     * General category "Pc" in the Unicode specification.
 430.318 +     * @since   1.1
 430.319 +     */
 430.320 +    public static final byte CONNECTOR_PUNCTUATION = 23;
 430.321 +
 430.322 +    /**
 430.323 +     * General category "Po" in the Unicode specification.
 430.324 +     * @since   1.1
 430.325 +     */
 430.326 +    public static final byte OTHER_PUNCTUATION = 24;
 430.327 +
 430.328 +    /**
 430.329 +     * General category "Sm" in the Unicode specification.
 430.330 +     * @since   1.1
 430.331 +     */
 430.332 +    public static final byte MATH_SYMBOL = 25;
 430.333 +
 430.334 +    /**
 430.335 +     * General category "Sc" in the Unicode specification.
 430.336 +     * @since   1.1
 430.337 +     */
 430.338 +    public static final byte CURRENCY_SYMBOL = 26;
 430.339 +
 430.340 +    /**
 430.341 +     * General category "Sk" in the Unicode specification.
 430.342 +     * @since   1.1
 430.343 +     */
 430.344 +    public static final byte MODIFIER_SYMBOL = 27;
 430.345 +
 430.346 +    /**
 430.347 +     * General category "So" in the Unicode specification.
 430.348 +     * @since   1.1
 430.349 +     */
 430.350 +    public static final byte OTHER_SYMBOL = 28;
 430.351 +
 430.352 +    /**
 430.353 +     * General category "Pi" in the Unicode specification.
 430.354 +     * @since   1.4
 430.355 +     */
 430.356 +    public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
 430.357 +
 430.358 +    /**
 430.359 +     * General category "Pf" in the Unicode specification.
 430.360 +     * @since   1.4
 430.361 +     */
 430.362 +    public static final byte FINAL_QUOTE_PUNCTUATION = 30;
 430.363 +
 430.364 +    /**
 430.365 +     * Error flag. Use int (code point) to avoid confusion with U+FFFF.
 430.366 +     */
 430.367 +    static final int ERROR = 0xFFFFFFFF;
 430.368 +
 430.369 +
 430.370 +    /**
 430.371 +     * Undefined bidirectional character type. Undefined {@code char}
 430.372 +     * values have undefined directionality in the Unicode specification.
 430.373 +     * @since 1.4
 430.374 +     */
 430.375 +    public static final byte DIRECTIONALITY_UNDEFINED = -1;
 430.376 +
 430.377 +    /**
 430.378 +     * Strong bidirectional character type "L" in the Unicode specification.
 430.379 +     * @since 1.4
 430.380 +     */
 430.381 +    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
 430.382 +
 430.383 +    /**
 430.384 +     * Strong bidirectional character type "R" in the Unicode specification.
 430.385 +     * @since 1.4
 430.386 +     */
 430.387 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
 430.388 +
 430.389 +    /**
 430.390 +    * Strong bidirectional character type "AL" in the Unicode specification.
 430.391 +     * @since 1.4
 430.392 +     */
 430.393 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
 430.394 +
 430.395 +    /**
 430.396 +     * Weak bidirectional character type "EN" in the Unicode specification.
 430.397 +     * @since 1.4
 430.398 +     */
 430.399 +    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
 430.400 +
 430.401 +    /**
 430.402 +     * Weak bidirectional character type "ES" in the Unicode specification.
 430.403 +     * @since 1.4
 430.404 +     */
 430.405 +    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
 430.406 +
 430.407 +    /**
 430.408 +     * Weak bidirectional character type "ET" in the Unicode specification.
 430.409 +     * @since 1.4
 430.410 +     */
 430.411 +    public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
 430.412 +
 430.413 +    /**
 430.414 +     * Weak bidirectional character type "AN" in the Unicode specification.
 430.415 +     * @since 1.4
 430.416 +     */
 430.417 +    public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
 430.418 +
 430.419 +    /**
 430.420 +     * Weak bidirectional character type "CS" in the Unicode specification.
 430.421 +     * @since 1.4
 430.422 +     */
 430.423 +    public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
 430.424 +
 430.425 +    /**
 430.426 +     * Weak bidirectional character type "NSM" in the Unicode specification.
 430.427 +     * @since 1.4
 430.428 +     */
 430.429 +    public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
 430.430 +
 430.431 +    /**
 430.432 +     * Weak bidirectional character type "BN" in the Unicode specification.
 430.433 +     * @since 1.4
 430.434 +     */
 430.435 +    public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
 430.436 +
 430.437 +    /**
 430.438 +     * Neutral bidirectional character type "B" in the Unicode specification.
 430.439 +     * @since 1.4
 430.440 +     */
 430.441 +    public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
 430.442 +
 430.443 +    /**
 430.444 +     * Neutral bidirectional character type "S" in the Unicode specification.
 430.445 +     * @since 1.4
 430.446 +     */
 430.447 +    public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
 430.448 +
 430.449 +    /**
 430.450 +     * Neutral bidirectional character type "WS" in the Unicode specification.
 430.451 +     * @since 1.4
 430.452 +     */
 430.453 +    public static final byte DIRECTIONALITY_WHITESPACE = 12;
 430.454 +
 430.455 +    /**
 430.456 +     * Neutral bidirectional character type "ON" in the Unicode specification.
 430.457 +     * @since 1.4
 430.458 +     */
 430.459 +    public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
 430.460 +
 430.461 +    /**
 430.462 +     * Strong bidirectional character type "LRE" in the Unicode specification.
 430.463 +     * @since 1.4
 430.464 +     */
 430.465 +    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
 430.466 +
 430.467 +    /**
 430.468 +     * Strong bidirectional character type "LRO" in the Unicode specification.
 430.469 +     * @since 1.4
 430.470 +     */
 430.471 +    public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
 430.472 +
 430.473 +    /**
 430.474 +     * Strong bidirectional character type "RLE" in the Unicode specification.
 430.475 +     * @since 1.4
 430.476 +     */
 430.477 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
 430.478 +
 430.479 +    /**
 430.480 +     * Strong bidirectional character type "RLO" in the Unicode specification.
 430.481 +     * @since 1.4
 430.482 +     */
 430.483 +    public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
 430.484 +
 430.485 +    /**
 430.486 +     * Weak bidirectional character type "PDF" in the Unicode specification.
 430.487 +     * @since 1.4
 430.488 +     */
 430.489 +    public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
 430.490 +
 430.491 +    /**
 430.492 +     * The minimum value of a
 430.493 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 430.494 +     * Unicode high-surrogate code unit</a>
 430.495 +     * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
 430.496 +     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 430.497 +     *
 430.498 +     * @since 1.5
 430.499 +     */
 430.500 +    public static final char MIN_HIGH_SURROGATE = '\uD800';
 430.501 +
 430.502 +    /**
 430.503 +     * The maximum value of a
 430.504 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 430.505 +     * Unicode high-surrogate code unit</a>
 430.506 +     * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
 430.507 +     * A high-surrogate is also known as a <i>leading-surrogate</i>.
 430.508 +     *
 430.509 +     * @since 1.5
 430.510 +     */
 430.511 +    public static final char MAX_HIGH_SURROGATE = '\uDBFF';
 430.512 +
 430.513 +    /**
 430.514 +     * The minimum value of a
 430.515 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 430.516 +     * Unicode low-surrogate code unit</a>
 430.517 +     * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
 430.518 +     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 430.519 +     *
 430.520 +     * @since 1.5
 430.521 +     */
 430.522 +    public static final char MIN_LOW_SURROGATE  = '\uDC00';
 430.523 +
 430.524 +    /**
 430.525 +     * The maximum value of a
 430.526 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 430.527 +     * Unicode low-surrogate code unit</a>
 430.528 +     * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 430.529 +     * A low-surrogate is also known as a <i>trailing-surrogate</i>.
 430.530 +     *
 430.531 +     * @since 1.5
 430.532 +     */
 430.533 +    public static final char MAX_LOW_SURROGATE  = '\uDFFF';
 430.534 +
 430.535 +    /**
 430.536 +     * The minimum value of a Unicode surrogate code unit in the
 430.537 +     * UTF-16 encoding, constant {@code '\u005CuD800'}.
 430.538 +     *
 430.539 +     * @since 1.5
 430.540 +     */
 430.541 +    public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
 430.542 +
 430.543 +    /**
 430.544 +     * The maximum value of a Unicode surrogate code unit in the
 430.545 +     * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
 430.546 +     *
 430.547 +     * @since 1.5
 430.548 +     */
 430.549 +    public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
 430.550 +
 430.551 +    /**
 430.552 +     * The minimum value of a
 430.553 +     * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
 430.554 +     * Unicode supplementary code point</a>, constant {@code U+10000}.
 430.555 +     *
 430.556 +     * @since 1.5
 430.557 +     */
 430.558 +    public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
 430.559 +
 430.560 +    /**
 430.561 +     * The minimum value of a
 430.562 +     * <a href="http://www.unicode.org/glossary/#code_point">
 430.563 +     * Unicode code point</a>, constant {@code U+0000}.
 430.564 +     *
 430.565 +     * @since 1.5
 430.566 +     */
 430.567 +    public static final int MIN_CODE_POINT = 0x000000;
 430.568 +
 430.569 +    /**
 430.570 +     * The maximum value of a
 430.571 +     * <a href="http://www.unicode.org/glossary/#code_point">
 430.572 +     * Unicode code point</a>, constant {@code U+10FFFF}.
 430.573 +     *
 430.574 +     * @since 1.5
 430.575 +     */
 430.576 +    public static final int MAX_CODE_POINT = 0X10FFFF;
 430.577 +
 430.578 +
 430.579 +    /**
 430.580 +     * Instances of this class represent particular subsets of the Unicode
 430.581 +     * character set.  The only family of subsets defined in the
 430.582 +     * {@code Character} class is {@link Character.UnicodeBlock}.
 430.583 +     * Other portions of the Java API may define other subsets for their
 430.584 +     * own purposes.
 430.585 +     *
 430.586 +     * @since 1.2
 430.587 +     */
 430.588 +    public static class Subset  {
 430.589 +
 430.590 +        private String name;
 430.591 +
 430.592 +        /**
 430.593 +         * Constructs a new {@code Subset} instance.
 430.594 +         *
 430.595 +         * @param  name  The name of this subset
 430.596 +         * @exception NullPointerException if name is {@code null}
 430.597 +         */
 430.598 +        protected Subset(String name) {
 430.599 +            if (name == null) {
 430.600 +                throw new NullPointerException("name");
 430.601 +            }
 430.602 +            this.name = name;
 430.603 +        }
 430.604 +
 430.605 +        /**
 430.606 +         * Compares two {@code Subset} objects for equality.
 430.607 +         * This method returns {@code true} if and only if
 430.608 +         * {@code this} and the argument refer to the same
 430.609 +         * object; since this method is {@code final}, this
 430.610 +         * guarantee holds for all subclasses.
 430.611 +         */
 430.612 +        public final boolean equals(Object obj) {
 430.613 +            return (this == obj);
 430.614 +        }
 430.615 +
 430.616 +        /**
 430.617 +         * Returns the standard hash code as defined by the
 430.618 +         * {@link Object#hashCode} method.  This method
 430.619 +         * is {@code final} in order to ensure that the
 430.620 +         * {@code equals} and {@code hashCode} methods will
 430.621 +         * be consistent in all subclasses.
 430.622 +         */
 430.623 +        public final int hashCode() {
 430.624 +            return super.hashCode();
 430.625 +        }
 430.626 +
 430.627 +        /**
 430.628 +         * Returns the name of this subset.
 430.629 +         */
 430.630 +        public final String toString() {
 430.631 +            return name;
 430.632 +        }
 430.633 +    }
 430.634 +
 430.635 +    // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
 430.636 +    // for the latest specification of Unicode Blocks.
 430.637 +
 430.638 +
 430.639 +    /**
 430.640 +     * The value of the {@code Character}.
 430.641 +     *
 430.642 +     * @serial
 430.643 +     */
 430.644 +    private final char value;
 430.645 +
 430.646 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 430.647 +    private static final long serialVersionUID = 3786198910865385080L;
 430.648 +
 430.649 +    /**
 430.650 +     * Constructs a newly allocated {@code Character} object that
 430.651 +     * represents the specified {@code char} value.
 430.652 +     *
 430.653 +     * @param  value   the value to be represented by the
 430.654 +     *                  {@code Character} object.
 430.655 +     */
 430.656 +    public Character(char value) {
 430.657 +        this.value = value;
 430.658 +    }
 430.659 +
 430.660 +    private static class CharacterCache {
 430.661 +        private CharacterCache(){}
 430.662 +
 430.663 +        static final Character cache[] = new Character[127 + 1];
 430.664 +
 430.665 +        static {
 430.666 +            for (int i = 0; i < cache.length; i++)
 430.667 +                cache[i] = new Character((char)i);
 430.668 +        }
 430.669 +    }
 430.670 +
 430.671 +    /**
 430.672 +     * Returns a <tt>Character</tt> instance representing the specified
 430.673 +     * <tt>char</tt> value.
 430.674 +     * If a new <tt>Character</tt> instance is not required, this method
 430.675 +     * should generally be used in preference to the constructor
 430.676 +     * {@link #Character(char)}, as this method is likely to yield
 430.677 +     * significantly better space and time performance by caching
 430.678 +     * frequently requested values.
 430.679 +     *
 430.680 +     * This method will always cache values in the range {@code
 430.681 +     * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
 430.682 +     * cache other values outside of this range.
 430.683 +     *
 430.684 +     * @param  c a char value.
 430.685 +     * @return a <tt>Character</tt> instance representing <tt>c</tt>.
 430.686 +     * @since  1.5
 430.687 +     */
 430.688 +    public static Character valueOf(char c) {
 430.689 +        if (c <= 127) { // must cache
 430.690 +            return CharacterCache.cache[(int)c];
 430.691 +        }
 430.692 +        return new Character(c);
 430.693 +    }
 430.694 +
 430.695 +    /**
 430.696 +     * Returns the value of this {@code Character} object.
 430.697 +     * @return  the primitive {@code char} value represented by
 430.698 +     *          this object.
 430.699 +     */
 430.700 +    public char charValue() {
 430.701 +        return value;
 430.702 +    }
 430.703 +
 430.704 +    /**
 430.705 +     * Returns a hash code for this {@code Character}; equal to the result
 430.706 +     * of invoking {@code charValue()}.
 430.707 +     *
 430.708 +     * @return a hash code value for this {@code Character}
 430.709 +     */
 430.710 +    public int hashCode() {
 430.711 +        return (int)value;
 430.712 +    }
 430.713 +
 430.714 +    /**
 430.715 +     * Compares this object against the specified object.
 430.716 +     * The result is {@code true} if and only if the argument is not
 430.717 +     * {@code null} and is a {@code Character} object that
 430.718 +     * represents the same {@code char} value as this object.
 430.719 +     *
 430.720 +     * @param   obj   the object to compare with.
 430.721 +     * @return  {@code true} if the objects are the same;
 430.722 +     *          {@code false} otherwise.
 430.723 +     */
 430.724 +    public boolean equals(Object obj) {
 430.725 +        if (obj instanceof Character) {
 430.726 +            return value == ((Character)obj).charValue();
 430.727 +        }
 430.728 +        return false;
 430.729 +    }
 430.730 +
 430.731 +    /**
 430.732 +     * Returns a {@code String} object representing this
 430.733 +     * {@code Character}'s value.  The result is a string of
 430.734 +     * length 1 whose sole component is the primitive
 430.735 +     * {@code char} value represented by this
 430.736 +     * {@code Character} object.
 430.737 +     *
 430.738 +     * @return  a string representation of this object.
 430.739 +     */
 430.740 +    public String toString() {
 430.741 +        char buf[] = {value};
 430.742 +        return String.valueOf(buf);
 430.743 +    }
 430.744 +
 430.745 +    /**
 430.746 +     * Returns a {@code String} object representing the
 430.747 +     * specified {@code char}.  The result is a string of length
 430.748 +     * 1 consisting solely of the specified {@code char}.
 430.749 +     *
 430.750 +     * @param c the {@code char} to be converted
 430.751 +     * @return the string representation of the specified {@code char}
 430.752 +     * @since 1.4
 430.753 +     */
 430.754 +    public static String toString(char c) {
 430.755 +        return String.valueOf(c);
 430.756 +    }
 430.757 +
 430.758 +    /**
 430.759 +     * Determines whether the specified code point is a valid
 430.760 +     * <a href="http://www.unicode.org/glossary/#code_point">
 430.761 +     * Unicode code point value</a>.
 430.762 +     *
 430.763 +     * @param  codePoint the Unicode code point to be tested
 430.764 +     * @return {@code true} if the specified code point value is between
 430.765 +     *         {@link #MIN_CODE_POINT} and
 430.766 +     *         {@link #MAX_CODE_POINT} inclusive;
 430.767 +     *         {@code false} otherwise.
 430.768 +     * @since  1.5
 430.769 +     */
 430.770 +    public static boolean isValidCodePoint(int codePoint) {
 430.771 +        // Optimized form of:
 430.772 +        //     codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
 430.773 +        int plane = codePoint >>> 16;
 430.774 +        return plane < ((MAX_CODE_POINT + 1) >>> 16);
 430.775 +    }
 430.776 +
 430.777 +    /**
 430.778 +     * Determines whether the specified character (Unicode code point)
 430.779 +     * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
 430.780 +     * Such code points can be represented using a single {@code char}.
 430.781 +     *
 430.782 +     * @param  codePoint the character (Unicode code point) to be tested
 430.783 +     * @return {@code true} if the specified code point is between
 430.784 +     *         {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
 430.785 +     *         {@code false} otherwise.
 430.786 +     * @since  1.7
 430.787 +     */
 430.788 +    public static boolean isBmpCodePoint(int codePoint) {
 430.789 +        return codePoint >>> 16 == 0;
 430.790 +        // Optimized form of:
 430.791 +        //     codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
 430.792 +        // We consistently use logical shift (>>>) to facilitate
 430.793 +        // additional runtime optimizations.
 430.794 +    }
 430.795 +
 430.796 +    /**
 430.797 +     * Determines whether the specified character (Unicode code point)
 430.798 +     * is in the <a href="#supplementary">supplementary character</a> range.
 430.799 +     *
 430.800 +     * @param  codePoint the character (Unicode code point) to be tested
 430.801 +     * @return {@code true} if the specified code point is between
 430.802 +     *         {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
 430.803 +     *         {@link #MAX_CODE_POINT} inclusive;
 430.804 +     *         {@code false} otherwise.
 430.805 +     * @since  1.5
 430.806 +     */
 430.807 +    public static boolean isSupplementaryCodePoint(int codePoint) {
 430.808 +        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
 430.809 +            && codePoint <  MAX_CODE_POINT + 1;
 430.810 +    }
 430.811 +
 430.812 +    /**
 430.813 +     * Determines if the given {@code char} value is a
 430.814 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
 430.815 +     * Unicode high-surrogate code unit</a>
 430.816 +     * (also known as <i>leading-surrogate code unit</i>).
 430.817 +     *
 430.818 +     * <p>Such values do not represent characters by themselves,
 430.819 +     * but are used in the representation of
 430.820 +     * <a href="#supplementary">supplementary characters</a>
 430.821 +     * in the UTF-16 encoding.
 430.822 +     *
 430.823 +     * @param  ch the {@code char} value to be tested.
 430.824 +     * @return {@code true} if the {@code char} value is between
 430.825 +     *         {@link #MIN_HIGH_SURROGATE} and
 430.826 +     *         {@link #MAX_HIGH_SURROGATE} inclusive;
 430.827 +     *         {@code false} otherwise.
 430.828 +     * @see    Character#isLowSurrogate(char)
 430.829 +     * @see    Character.UnicodeBlock#of(int)
 430.830 +     * @since  1.5
 430.831 +     */
 430.832 +    public static boolean isHighSurrogate(char ch) {
 430.833 +        // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
 430.834 +        return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
 430.835 +    }
 430.836 +
 430.837 +    /**
 430.838 +     * Determines if the given {@code char} value is a
 430.839 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
 430.840 +     * Unicode low-surrogate code unit</a>
 430.841 +     * (also known as <i>trailing-surrogate code unit</i>).
 430.842 +     *
 430.843 +     * <p>Such values do not represent characters by themselves,
 430.844 +     * but are used in the representation of
 430.845 +     * <a href="#supplementary">supplementary characters</a>
 430.846 +     * in the UTF-16 encoding.
 430.847 +     *
 430.848 +     * @param  ch the {@code char} value to be tested.
 430.849 +     * @return {@code true} if the {@code char} value is between
 430.850 +     *         {@link #MIN_LOW_SURROGATE} and
 430.851 +     *         {@link #MAX_LOW_SURROGATE} inclusive;
 430.852 +     *         {@code false} otherwise.
 430.853 +     * @see    Character#isHighSurrogate(char)
 430.854 +     * @since  1.5
 430.855 +     */
 430.856 +    public static boolean isLowSurrogate(char ch) {
 430.857 +        return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
 430.858 +    }
 430.859 +
 430.860 +    /**
 430.861 +     * Determines if the given {@code char} value is a Unicode
 430.862 +     * <i>surrogate code unit</i>.
 430.863 +     *
 430.864 +     * <p>Such values do not represent characters by themselves,
 430.865 +     * but are used in the representation of
 430.866 +     * <a href="#supplementary">supplementary characters</a>
 430.867 +     * in the UTF-16 encoding.
 430.868 +     *
 430.869 +     * <p>A char value is a surrogate code unit if and only if it is either
 430.870 +     * a {@linkplain #isLowSurrogate(char) low-surrogate code unit} or
 430.871 +     * a {@linkplain #isHighSurrogate(char) high-surrogate code unit}.
 430.872 +     *
 430.873 +     * @param  ch the {@code char} value to be tested.
 430.874 +     * @return {@code true} if the {@code char} value is between
 430.875 +     *         {@link #MIN_SURROGATE} and
 430.876 +     *         {@link #MAX_SURROGATE} inclusive;
 430.877 +     *         {@code false} otherwise.
 430.878 +     * @since  1.7
 430.879 +     */
 430.880 +    public static boolean isSurrogate(char ch) {
 430.881 +        return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
 430.882 +    }
 430.883 +
 430.884 +    /**
 430.885 +     * Determines whether the specified pair of {@code char}
 430.886 +     * values is a valid
 430.887 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
 430.888 +     * Unicode surrogate pair</a>.
 430.889 +
 430.890 +     * <p>This method is equivalent to the expression:
 430.891 +     * <blockquote><pre>
 430.892 +     * isHighSurrogate(high) && isLowSurrogate(low)
 430.893 +     * </pre></blockquote>
 430.894 +     *
 430.895 +     * @param  high the high-surrogate code value to be tested
 430.896 +     * @param  low the low-surrogate code value to be tested
 430.897 +     * @return {@code true} if the specified high and
 430.898 +     * low-surrogate code values represent a valid surrogate pair;
 430.899 +     * {@code false} otherwise.
 430.900 +     * @since  1.5
 430.901 +     */
 430.902 +    public static boolean isSurrogatePair(char high, char low) {
 430.903 +        return isHighSurrogate(high) && isLowSurrogate(low);
 430.904 +    }
 430.905 +
 430.906 +    /**
 430.907 +     * Determines the number of {@code char} values needed to
 430.908 +     * represent the specified character (Unicode code point). If the
 430.909 +     * specified character is equal to or greater than 0x10000, then
 430.910 +     * the method returns 2. Otherwise, the method returns 1.
 430.911 +     *
 430.912 +     * <p>This method doesn't validate the specified character to be a
 430.913 +     * valid Unicode code point. The caller must validate the
 430.914 +     * character value using {@link #isValidCodePoint(int) isValidCodePoint}
 430.915 +     * if necessary.
 430.916 +     *
 430.917 +     * @param   codePoint the character (Unicode code point) to be tested.
 430.918 +     * @return  2 if the character is a valid supplementary character; 1 otherwise.
 430.919 +     * @see     Character#isSupplementaryCodePoint(int)
 430.920 +     * @since   1.5
 430.921 +     */
 430.922 +    public static int charCount(int codePoint) {
 430.923 +        return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
 430.924 +    }
 430.925 +
 430.926 +    /**
 430.927 +     * Converts the specified surrogate pair to its supplementary code
 430.928 +     * point value. This method does not validate the specified
 430.929 +     * surrogate pair. The caller must validate it using {@link
 430.930 +     * #isSurrogatePair(char, char) isSurrogatePair} if necessary.
 430.931 +     *
 430.932 +     * @param  high the high-surrogate code unit
 430.933 +     * @param  low the low-surrogate code unit
 430.934 +     * @return the supplementary code point composed from the
 430.935 +     *         specified surrogate pair.
 430.936 +     * @since  1.5
 430.937 +     */
 430.938 +    public static int toCodePoint(char high, char low) {
 430.939 +        // Optimized form of:
 430.940 +        // return ((high - MIN_HIGH_SURROGATE) << 10)
 430.941 +        //         + (low - MIN_LOW_SURROGATE)
 430.942 +        //         + MIN_SUPPLEMENTARY_CODE_POINT;
 430.943 +        return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT
 430.944 +                                       - (MIN_HIGH_SURROGATE << 10)
 430.945 +                                       - MIN_LOW_SURROGATE);
 430.946 +    }
 430.947 +
 430.948 +    /**
 430.949 +     * Returns the code point at the given index of the
 430.950 +     * {@code CharSequence}. If the {@code char} value at
 430.951 +     * the given index in the {@code CharSequence} is in the
 430.952 +     * high-surrogate range, the following index is less than the
 430.953 +     * length of the {@code CharSequence}, and the
 430.954 +     * {@code char} value at the following index is in the
 430.955 +     * low-surrogate range, then the supplementary code point
 430.956 +     * corresponding to this surrogate pair is returned. Otherwise,
 430.957 +     * the {@code char} value at the given index is returned.
 430.958 +     *
 430.959 +     * @param seq a sequence of {@code char} values (Unicode code
 430.960 +     * units)
 430.961 +     * @param index the index to the {@code char} values (Unicode
 430.962 +     * code units) in {@code seq} to be converted
 430.963 +     * @return the Unicode code point at the given index
 430.964 +     * @exception NullPointerException if {@code seq} is null.
 430.965 +     * @exception IndexOutOfBoundsException if the value
 430.966 +     * {@code index} is negative or not less than
 430.967 +     * {@link CharSequence#length() seq.length()}.
 430.968 +     * @since  1.5
 430.969 +     */
 430.970 +    public static int codePointAt(CharSequence seq, int index) {
 430.971 +        char c1 = seq.charAt(index++);
 430.972 +        if (isHighSurrogate(c1)) {
 430.973 +            if (index < seq.length()) {
 430.974 +                char c2 = seq.charAt(index);
 430.975 +                if (isLowSurrogate(c2)) {
 430.976 +                    return toCodePoint(c1, c2);
 430.977 +                }
 430.978 +            }
 430.979 +        }
 430.980 +        return c1;
 430.981 +    }
 430.982 +
 430.983 +    /**
 430.984 +     * Returns the code point at the given index of the
 430.985 +     * {@code char} array. If the {@code char} value at
 430.986 +     * the given index in the {@code char} array is in the
 430.987 +     * high-surrogate range, the following index is less than the
 430.988 +     * length of the {@code char} array, and the
 430.989 +     * {@code char} value at the following index is in the
 430.990 +     * low-surrogate range, then the supplementary code point
 430.991 +     * corresponding to this surrogate pair is returned. Otherwise,
 430.992 +     * the {@code char} value at the given index is returned.
 430.993 +     *
 430.994 +     * @param a the {@code char} array
 430.995 +     * @param index the index to the {@code char} values (Unicode
 430.996 +     * code units) in the {@code char} array to be converted
 430.997 +     * @return the Unicode code point at the given index
 430.998 +     * @exception NullPointerException if {@code a} is null.
 430.999 +     * @exception IndexOutOfBoundsException if the value
430.1000 +     * {@code index} is negative or not less than
430.1001 +     * the length of the {@code char} array.
430.1002 +     * @since  1.5
430.1003 +     */
430.1004 +    public static int codePointAt(char[] a, int index) {
430.1005 +        return codePointAtImpl(a, index, a.length);
430.1006 +    }
430.1007 +
430.1008 +    /**
430.1009 +     * Returns the code point at the given index of the
430.1010 +     * {@code char} array, where only array elements with
430.1011 +     * {@code index} less than {@code limit} can be used. If
430.1012 +     * the {@code char} value at the given index in the
430.1013 +     * {@code char} array is in the high-surrogate range, the
430.1014 +     * following index is less than the {@code limit}, and the
430.1015 +     * {@code char} value at the following index is in the
430.1016 +     * low-surrogate range, then the supplementary code point
430.1017 +     * corresponding to this surrogate pair is returned. Otherwise,
430.1018 +     * the {@code char} value at the given index is returned.
430.1019 +     *
430.1020 +     * @param a the {@code char} array
430.1021 +     * @param index the index to the {@code char} values (Unicode
430.1022 +     * code units) in the {@code char} array to be converted
430.1023 +     * @param limit the index after the last array element that
430.1024 +     * can be used in the {@code char} array
430.1025 +     * @return the Unicode code point at the given index
430.1026 +     * @exception NullPointerException if {@code a} is null.
430.1027 +     * @exception IndexOutOfBoundsException if the {@code index}
430.1028 +     * argument is negative or not less than the {@code limit}
430.1029 +     * argument, or if the {@code limit} argument is negative or
430.1030 +     * greater than the length of the {@code char} array.
430.1031 +     * @since  1.5
430.1032 +     */
430.1033 +    public static int codePointAt(char[] a, int index, int limit) {
430.1034 +        if (index >= limit || limit < 0 || limit > a.length) {
430.1035 +            throw new IndexOutOfBoundsException();
430.1036 +        }
430.1037 +        return codePointAtImpl(a, index, limit);
430.1038 +    }
430.1039 +
430.1040 +    // throws ArrayIndexOutofBoundsException if index out of bounds
430.1041 +    static int codePointAtImpl(char[] a, int index, int limit) {
430.1042 +        char c1 = a[index++];
430.1043 +        if (isHighSurrogate(c1)) {
430.1044 +            if (index < limit) {
430.1045 +                char c2 = a[index];
430.1046 +                if (isLowSurrogate(c2)) {
430.1047 +                    return toCodePoint(c1, c2);
430.1048 +                }
430.1049 +            }
430.1050 +        }
430.1051 +        return c1;
430.1052 +    }
430.1053 +
430.1054 +    /**
430.1055 +     * Returns the code point preceding the given index of the
430.1056 +     * {@code CharSequence}. If the {@code char} value at
430.1057 +     * {@code (index - 1)} in the {@code CharSequence} is in
430.1058 +     * the low-surrogate range, {@code (index - 2)} is not
430.1059 +     * negative, and the {@code char} value at {@code (index - 2)}
430.1060 +     * in the {@code CharSequence} is in the
430.1061 +     * high-surrogate range, then the supplementary code point
430.1062 +     * corresponding to this surrogate pair is returned. Otherwise,
430.1063 +     * the {@code char} value at {@code (index - 1)} is
430.1064 +     * returned.
430.1065 +     *
430.1066 +     * @param seq the {@code CharSequence} instance
430.1067 +     * @param index the index following the code point that should be returned
430.1068 +     * @return the Unicode code point value before the given index.
430.1069 +     * @exception NullPointerException if {@code seq} is null.
430.1070 +     * @exception IndexOutOfBoundsException if the {@code index}
430.1071 +     * argument is less than 1 or greater than {@link
430.1072 +     * CharSequence#length() seq.length()}.
430.1073 +     * @since  1.5
430.1074 +     */
430.1075 +    public static int codePointBefore(CharSequence seq, int index) {
430.1076 +        char c2 = seq.charAt(--index);
430.1077 +        if (isLowSurrogate(c2)) {
430.1078 +            if (index > 0) {
430.1079 +                char c1 = seq.charAt(--index);
430.1080 +                if (isHighSurrogate(c1)) {
430.1081 +                    return toCodePoint(c1, c2);
430.1082 +                }
430.1083 +            }
430.1084 +        }
430.1085 +        return c2;
430.1086 +    }
430.1087 +
430.1088 +    /**
430.1089 +     * Returns the code point preceding the given index of the
430.1090 +     * {@code char} array. If the {@code char} value at
430.1091 +     * {@code (index - 1)} in the {@code char} array is in
430.1092 +     * the low-surrogate range, {@code (index - 2)} is not
430.1093 +     * negative, and the {@code char} value at {@code (index - 2)}
430.1094 +     * in the {@code char} array is in the
430.1095 +     * high-surrogate range, then the supplementary code point
430.1096 +     * corresponding to this surrogate pair is returned. Otherwise,
430.1097 +     * the {@code char} value at {@code (index - 1)} is
430.1098 +     * returned.
430.1099 +     *
430.1100 +     * @param a the {@code char} array
430.1101 +     * @param index the index following the code point that should be returned
430.1102 +     * @return the Unicode code point value before the given index.
430.1103 +     * @exception NullPointerException if {@code a} is null.
430.1104 +     * @exception IndexOutOfBoundsException if the {@code index}
430.1105 +     * argument is less than 1 or greater than the length of the
430.1106 +     * {@code char} array
430.1107 +     * @since  1.5
430.1108 +     */
430.1109 +    public static int codePointBefore(char[] a, int index) {
430.1110 +        return codePointBeforeImpl(a, index, 0);
430.1111 +    }
430.1112 +
430.1113 +    /**
430.1114 +     * Returns the code point preceding the given index of the
430.1115 +     * {@code char} array, where only array elements with
430.1116 +     * {@code index} greater than or equal to {@code start}
430.1117 +     * can be used. If the {@code char} value at {@code (index - 1)}
430.1118 +     * in the {@code char} array is in the
430.1119 +     * low-surrogate range, {@code (index - 2)} is not less than
430.1120 +     * {@code start}, and the {@code char} value at
430.1121 +     * {@code (index - 2)} in the {@code char} array is in
430.1122 +     * the high-surrogate range, then the supplementary code point
430.1123 +     * corresponding to this surrogate pair is returned. Otherwise,
430.1124 +     * the {@code char} value at {@code (index - 1)} is
430.1125 +     * returned.
430.1126 +     *
430.1127 +     * @param a the {@code char} array
430.1128 +     * @param index the index following the code point that should be returned
430.1129 +     * @param start the index of the first array element in the
430.1130 +     * {@code char} array
430.1131 +     * @return the Unicode code point value before the given index.
430.1132 +     * @exception NullPointerException if {@code a} is null.
430.1133 +     * @exception IndexOutOfBoundsException if the {@code index}
430.1134 +     * argument is not greater than the {@code start} argument or
430.1135 +     * is greater than the length of the {@code char} array, or
430.1136 +     * if the {@code start} argument is negative or not less than
430.1137 +     * the length of the {@code char} array.
430.1138 +     * @since  1.5
430.1139 +     */
430.1140 +    public static int codePointBefore(char[] a, int index, int start) {
430.1141 +        if (index <= start || start < 0 || start >= a.length) {
430.1142 +            throw new IndexOutOfBoundsException();
430.1143 +        }
430.1144 +        return codePointBeforeImpl(a, index, start);
430.1145 +    }
430.1146 +
430.1147 +    // throws ArrayIndexOutofBoundsException if index-1 out of bounds
430.1148 +    static int codePointBeforeImpl(char[] a, int index, int start) {
430.1149 +        char c2 = a[--index];
430.1150 +        if (isLowSurrogate(c2)) {
430.1151 +            if (index > start) {
430.1152 +                char c1 = a[--index];
430.1153 +                if (isHighSurrogate(c1)) {
430.1154 +                    return toCodePoint(c1, c2);
430.1155 +                }
430.1156 +            }
430.1157 +        }
430.1158 +        return c2;
430.1159 +    }
430.1160 +
430.1161 +    /**
430.1162 +     * Returns the leading surrogate (a
430.1163 +     * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
430.1164 +     * high surrogate code unit</a>) of the
430.1165 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
430.1166 +     * surrogate pair</a>
430.1167 +     * representing the specified supplementary character (Unicode
430.1168 +     * code point) in the UTF-16 encoding.  If the specified character
430.1169 +     * is not a
430.1170 +     * <a href="Character.html#supplementary">supplementary character</a>,
430.1171 +     * an unspecified {@code char} is returned.
430.1172 +     *
430.1173 +     * <p>If
430.1174 +     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
430.1175 +     * is {@code true}, then
430.1176 +     * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
430.1177 +     * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
430.1178 +     * are also always {@code true}.
430.1179 +     *
430.1180 +     * @param   codePoint a supplementary character (Unicode code point)
430.1181 +     * @return  the leading surrogate code unit used to represent the
430.1182 +     *          character in the UTF-16 encoding
430.1183 +     * @since   1.7
430.1184 +     */
430.1185 +    public static char highSurrogate(int codePoint) {
430.1186 +        return (char) ((codePoint >>> 10)
430.1187 +            + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
430.1188 +    }
430.1189 +
430.1190 +    /**
430.1191 +     * Returns the trailing surrogate (a
430.1192 +     * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
430.1193 +     * low surrogate code unit</a>) of the
430.1194 +     * <a href="http://www.unicode.org/glossary/#surrogate_pair">
430.1195 +     * surrogate pair</a>
430.1196 +     * representing the specified supplementary character (Unicode
430.1197 +     * code point) in the UTF-16 encoding.  If the specified character
430.1198 +     * is not a
430.1199 +     * <a href="Character.html#supplementary">supplementary character</a>,
430.1200 +     * an unspecified {@code char} is returned.
430.1201 +     *
430.1202 +     * <p>If
430.1203 +     * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
430.1204 +     * is {@code true}, then
430.1205 +     * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
430.1206 +     * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
430.1207 +     * are also always {@code true}.
430.1208 +     *
430.1209 +     * @param   codePoint a supplementary character (Unicode code point)
430.1210 +     * @return  the trailing surrogate code unit used to represent the
430.1211 +     *          character in the UTF-16 encoding
430.1212 +     * @since   1.7
430.1213 +     */
430.1214 +    public static char lowSurrogate(int codePoint) {
430.1215 +        return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
430.1216 +    }
430.1217 +
430.1218 +    /**
430.1219 +     * Converts the specified character (Unicode code point) to its
430.1220 +     * UTF-16 representation. If the specified code point is a BMP
430.1221 +     * (Basic Multilingual Plane or Plane 0) value, the same value is
430.1222 +     * stored in {@code dst[dstIndex]}, and 1 is returned. If the
430.1223 +     * specified code point is a supplementary character, its
430.1224 +     * surrogate values are stored in {@code dst[dstIndex]}
430.1225 +     * (high-surrogate) and {@code dst[dstIndex+1]}
430.1226 +     * (low-surrogate), and 2 is returned.
430.1227 +     *
430.1228 +     * @param  codePoint the character (Unicode code point) to be converted.
430.1229 +     * @param  dst an array of {@code char} in which the
430.1230 +     * {@code codePoint}'s UTF-16 value is stored.
430.1231 +     * @param dstIndex the start index into the {@code dst}
430.1232 +     * array where the converted value is stored.
430.1233 +     * @return 1 if the code point is a BMP code point, 2 if the
430.1234 +     * code point is a supplementary code point.
430.1235 +     * @exception IllegalArgumentException if the specified
430.1236 +     * {@code codePoint} is not a valid Unicode code point.
430.1237 +     * @exception NullPointerException if the specified {@code dst} is null.
430.1238 +     * @exception IndexOutOfBoundsException if {@code dstIndex}
430.1239 +     * is negative or not less than {@code dst.length}, or if
430.1240 +     * {@code dst} at {@code dstIndex} doesn't have enough
430.1241 +     * array element(s) to store the resulting {@code char}
430.1242 +     * value(s). (If {@code dstIndex} is equal to
430.1243 +     * {@code dst.length-1} and the specified
430.1244 +     * {@code codePoint} is a supplementary character, the
430.1245 +     * high-surrogate value is not stored in
430.1246 +     * {@code dst[dstIndex]}.)
430.1247 +     * @since  1.5
430.1248 +     */
430.1249 +    public static int toChars(int codePoint, char[] dst, int dstIndex) {
430.1250 +        if (isBmpCodePoint(codePoint)) {
430.1251 +            dst[dstIndex] = (char) codePoint;
430.1252 +            return 1;
430.1253 +        } else if (isValidCodePoint(codePoint)) {
430.1254 +            toSurrogates(codePoint, dst, dstIndex);
430.1255 +            return 2;
430.1256 +        } else {
430.1257 +            throw new IllegalArgumentException();
430.1258 +        }
430.1259 +    }
430.1260 +
430.1261 +    /**
430.1262 +     * Converts the specified character (Unicode code point) to its
430.1263 +     * UTF-16 representation stored in a {@code char} array. If
430.1264 +     * the specified code point is a BMP (Basic Multilingual Plane or
430.1265 +     * Plane 0) value, the resulting {@code char} array has
430.1266 +     * the same value as {@code codePoint}. If the specified code
430.1267 +     * point is a supplementary code point, the resulting
430.1268 +     * {@code char} array has the corresponding surrogate pair.
430.1269 +     *
430.1270 +     * @param  codePoint a Unicode code point
430.1271 +     * @return a {@code char} array having
430.1272 +     *         {@code codePoint}'s UTF-16 representation.
430.1273 +     * @exception IllegalArgumentException if the specified
430.1274 +     * {@code codePoint} is not a valid Unicode code point.
430.1275 +     * @since  1.5
430.1276 +     */
430.1277 +    public static char[] toChars(int codePoint) {
430.1278 +        if (isBmpCodePoint(codePoint)) {
430.1279 +            return new char[] { (char) codePoint };
430.1280 +        } else if (isValidCodePoint(codePoint)) {
430.1281 +            char[] result = new char[2];
430.1282 +            toSurrogates(codePoint, result, 0);
430.1283 +            return result;
430.1284 +        } else {
430.1285 +            throw new IllegalArgumentException();
430.1286 +        }
430.1287 +    }
430.1288 +
430.1289 +    static void toSurrogates(int codePoint, char[] dst, int index) {
430.1290 +        // We write elements "backwards" to guarantee all-or-nothing
430.1291 +        dst[index+1] = lowSurrogate(codePoint);
430.1292 +        dst[index] = highSurrogate(codePoint);
430.1293 +    }
430.1294 +
430.1295 +    /**
430.1296 +     * Returns the number of Unicode code points in the text range of
430.1297 +     * the specified char sequence. The text range begins at the
430.1298 +     * specified {@code beginIndex} and extends to the
430.1299 +     * {@code char} at index {@code endIndex - 1}. Thus the
430.1300 +     * length (in {@code char}s) of the text range is
430.1301 +     * {@code endIndex-beginIndex}. Unpaired surrogates within
430.1302 +     * the text range count as one code point each.
430.1303 +     *
430.1304 +     * @param seq the char sequence
430.1305 +     * @param beginIndex the index to the first {@code char} of
430.1306 +     * the text range.
430.1307 +     * @param endIndex the index after the last {@code char} of
430.1308 +     * the text range.
430.1309 +     * @return the number of Unicode code points in the specified text
430.1310 +     * range
430.1311 +     * @exception NullPointerException if {@code seq} is null.
430.1312 +     * @exception IndexOutOfBoundsException if the
430.1313 +     * {@code beginIndex} is negative, or {@code endIndex}
430.1314 +     * is larger than the length of the given sequence, or
430.1315 +     * {@code beginIndex} is larger than {@code endIndex}.
430.1316 +     * @since  1.5
430.1317 +     */
430.1318 +    public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) {
430.1319 +        int length = seq.length();
430.1320 +        if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
430.1321 +            throw new IndexOutOfBoundsException();
430.1322 +        }
430.1323 +        int n = endIndex - beginIndex;
430.1324 +        for (int i = beginIndex; i < endIndex; ) {
430.1325 +            if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
430.1326 +                isLowSurrogate(seq.charAt(i))) {
430.1327 +                n--;
430.1328 +                i++;
430.1329 +            }
430.1330 +        }
430.1331 +        return n;
430.1332 +    }
430.1333 +
430.1334 +    /**
430.1335 +     * Returns the number of Unicode code points in a subarray of the
430.1336 +     * {@code char} array argument. The {@code offset}
430.1337 +     * argument is the index of the first {@code char} of the
430.1338 +     * subarray and the {@code count} argument specifies the
430.1339 +     * length of the subarray in {@code char}s. Unpaired
430.1340 +     * surrogates within the subarray count as one code point each.
430.1341 +     *
430.1342 +     * @param a the {@code char} array
430.1343 +     * @param offset the index of the first {@code char} in the
430.1344 +     * given {@code char} array
430.1345 +     * @param count the length of the subarray in {@code char}s
430.1346 +     * @return the number of Unicode code points in the specified subarray
430.1347 +     * @exception NullPointerException if {@code a} is null.
430.1348 +     * @exception IndexOutOfBoundsException if {@code offset} or
430.1349 +     * {@code count} is negative, or if {@code offset +
430.1350 +     * count} is larger than the length of the given array.
430.1351 +     * @since  1.5
430.1352 +     */
430.1353 +    public static int codePointCount(char[] a, int offset, int count) {
430.1354 +        if (count > a.length - offset || offset < 0 || count < 0) {
430.1355 +            throw new IndexOutOfBoundsException();
430.1356 +        }
430.1357 +        return codePointCountImpl(a, offset, count);
430.1358 +    }
430.1359 +
430.1360 +    static int codePointCountImpl(char[] a, int offset, int count) {
430.1361 +        int endIndex = offset + count;
430.1362 +        int n = count;
430.1363 +        for (int i = offset; i < endIndex; ) {
430.1364 +            if (isHighSurrogate(a[i++]) && i < endIndex &&
430.1365 +                isLowSurrogate(a[i])) {
430.1366 +                n--;
430.1367 +                i++;
430.1368 +            }
430.1369 +        }
430.1370 +        return n;
430.1371 +    }
430.1372 +
430.1373 +    /**
430.1374 +     * Returns the index within the given char sequence that is offset
430.1375 +     * from the given {@code index} by {@code codePointOffset}
430.1376 +     * code points. Unpaired surrogates within the text range given by
430.1377 +     * {@code index} and {@code codePointOffset} count as
430.1378 +     * one code point each.
430.1379 +     *
430.1380 +     * @param seq the char sequence
430.1381 +     * @param index the index to be offset
430.1382 +     * @param codePointOffset the offset in code points
430.1383 +     * @return the index within the char sequence
430.1384 +     * @exception NullPointerException if {@code seq} is null.
430.1385 +     * @exception IndexOutOfBoundsException if {@code index}
430.1386 +     *   is negative or larger then the length of the char sequence,
430.1387 +     *   or if {@code codePointOffset} is positive and the
430.1388 +     *   subsequence starting with {@code index} has fewer than
430.1389 +     *   {@code codePointOffset} code points, or if
430.1390 +     *   {@code codePointOffset} is negative and the subsequence
430.1391 +     *   before {@code index} has fewer than the absolute value
430.1392 +     *   of {@code codePointOffset} code points.
430.1393 +     * @since 1.5
430.1394 +     */
430.1395 +    public static int offsetByCodePoints(CharSequence seq, int index,
430.1396 +                                         int codePointOffset) {
430.1397 +        int length = seq.length();
430.1398 +        if (index < 0 || index > length) {
430.1399 +            throw new IndexOutOfBoundsException();
430.1400 +        }
430.1401 +
430.1402 +        int x = index;
430.1403 +        if (codePointOffset >= 0) {
430.1404 +            int i;
430.1405 +            for (i = 0; x < length && i < codePointOffset; i++) {
430.1406 +                if (isHighSurrogate(seq.charAt(x++)) && x < length &&
430.1407 +                    isLowSurrogate(seq.charAt(x))) {
430.1408 +                    x++;
430.1409 +                }
430.1410 +            }
430.1411 +            if (i < codePointOffset) {
430.1412 +                throw new IndexOutOfBoundsException();
430.1413 +            }
430.1414 +        } else {
430.1415 +            int i;
430.1416 +            for (i = codePointOffset; x > 0 && i < 0; i++) {
430.1417 +                if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
430.1418 +                    isHighSurrogate(seq.charAt(x-1))) {
430.1419 +                    x--;
430.1420 +                }
430.1421 +            }
430.1422 +            if (i < 0) {
430.1423 +                throw new IndexOutOfBoundsException();
430.1424 +            }
430.1425 +        }
430.1426 +        return x;
430.1427 +    }
430.1428 +
430.1429 +    /**
430.1430 +     * Returns the index within the given {@code char} subarray
430.1431 +     * that is offset from the given {@code index} by
430.1432 +     * {@code codePointOffset} code points. The
430.1433 +     * {@code start} and {@code count} arguments specify a
430.1434 +     * subarray of the {@code char} array. Unpaired surrogates
430.1435 +     * within the text range given by {@code index} and
430.1436 +     * {@code codePointOffset} count as one code point each.
430.1437 +     *
430.1438 +     * @param a the {@code char} array
430.1439 +     * @param start the index of the first {@code char} of the
430.1440 +     * subarray
430.1441 +     * @param count the length of the subarray in {@code char}s
430.1442 +     * @param index the index to be offset
430.1443 +     * @param codePointOffset the offset in code points
430.1444 +     * @return the index within the subarray
430.1445 +     * @exception NullPointerException if {@code a} is null.
430.1446 +     * @exception IndexOutOfBoundsException
430.1447 +     *   if {@code start} or {@code count} is negative,
430.1448 +     *   or if {@code start + count} is larger than the length of
430.1449 +     *   the given array,
430.1450 +     *   or if {@code index} is less than {@code start} or
430.1451 +     *   larger then {@code start + count},
430.1452 +     *   or if {@code codePointOffset} is positive and the text range
430.1453 +     *   starting with {@code index} and ending with {@code start + count - 1}
430.1454 +     *   has fewer than {@code codePointOffset} code
430.1455 +     *   points,
430.1456 +     *   or if {@code codePointOffset} is negative and the text range
430.1457 +     *   starting with {@code start} and ending with {@code index - 1}
430.1458 +     *   has fewer than the absolute value of
430.1459 +     *   {@code codePointOffset} code points.
430.1460 +     * @since 1.5
430.1461 +     */
430.1462 +    public static int offsetByCodePoints(char[] a, int start, int count,
430.1463 +                                         int index, int codePointOffset) {
430.1464 +        if (count > a.length-start || start < 0 || count < 0
430.1465 +            || index < start || index > start+count) {
430.1466 +            throw new IndexOutOfBoundsException();
430.1467 +        }
430.1468 +        return offsetByCodePointsImpl(a, start, count, index, codePointOffset);
430.1469 +    }
430.1470 +
430.1471 +    static int offsetByCodePointsImpl(char[]a, int start, int count,
430.1472 +                                      int index, int codePointOffset) {
430.1473 +        int x = index;
430.1474 +        if (codePointOffset >= 0) {
430.1475 +            int limit = start + count;
430.1476 +            int i;
430.1477 +            for (i = 0; x < limit && i < codePointOffset; i++) {
430.1478 +                if (isHighSurrogate(a[x++]) && x < limit &&
430.1479 +                    isLowSurrogate(a[x])) {
430.1480 +                    x++;
430.1481 +                }
430.1482 +            }
430.1483 +            if (i < codePointOffset) {
430.1484 +                throw new IndexOutOfBoundsException();
430.1485 +            }
430.1486 +        } else {
430.1487 +            int i;
430.1488 +            for (i = codePointOffset; x > start && i < 0; i++) {
430.1489 +                if (isLowSurrogate(a[--x]) && x > start &&
430.1490 +                    isHighSurrogate(a[x-1])) {
430.1491 +                    x--;
430.1492 +                }
430.1493 +            }
430.1494 +            if (i < 0) {
430.1495 +                throw new IndexOutOfBoundsException();
430.1496 +            }
430.1497 +        }
430.1498 +        return x;
430.1499 +    }
430.1500 +
430.1501 +    /**
430.1502 +     * Determines if the specified character is a lowercase character.
430.1503 +     * <p>
430.1504 +     * A character is lowercase if its general category type, provided
430.1505 +     * by {@code Character.getType(ch)}, is
430.1506 +     * {@code LOWERCASE_LETTER}, or it has contributory property
430.1507 +     * Other_Lowercase as defined by the Unicode Standard.
430.1508 +     * <p>
430.1509 +     * The following are examples of lowercase characters:
430.1510 +     * <p><blockquote><pre>
430.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
430.1512 +     * '&#92;u00DF' '&#92;u00E0' '&#92;u00E1' '&#92;u00E2' '&#92;u00E3' '&#92;u00E4' '&#92;u00E5' '&#92;u00E6'
430.1513 +     * '&#92;u00E7' '&#92;u00E8' '&#92;u00E9' '&#92;u00EA' '&#92;u00EB' '&#92;u00EC' '&#92;u00ED' '&#92;u00EE'
430.1514 +     * '&#92;u00EF' '&#92;u00F0' '&#92;u00F1' '&#92;u00F2' '&#92;u00F3' '&#92;u00F4' '&#92;u00F5' '&#92;u00F6'
430.1515 +     * '&#92;u00F8' '&#92;u00F9' '&#92;u00FA' '&#92;u00FB' '&#92;u00FC' '&#92;u00FD' '&#92;u00FE' '&#92;u00FF'
430.1516 +     * </pre></blockquote>
430.1517 +     * <p> Many other Unicode characters are lowercase too.
430.1518 +     *
430.1519 +     * <p><b>Note:</b> This method cannot handle <a
430.1520 +     * href="#supplementary"> supplementary characters</a>. To support
430.1521 +     * all Unicode characters, including supplementary characters, use
430.1522 +     * the {@link #isLowerCase(int)} method.
430.1523 +     *
430.1524 +     * @param   ch   the character to be tested.
430.1525 +     * @return  {@code true} if the character is lowercase;
430.1526 +     *          {@code false} otherwise.
430.1527 +     * @see     Character#isLowerCase(char)
430.1528 +     * @see     Character#isTitleCase(char)
430.1529 +     * @see     Character#toLowerCase(char)
430.1530 +     * @see     Character#getType(char)
430.1531 +     */
430.1532 +    public static boolean isLowerCase(char ch) {
430.1533 +        return ch == toLowerCase(ch);
430.1534 +    }
430.1535 +
430.1536 +    /**
430.1537 +     * Determines if the specified character is an uppercase character.
430.1538 +     * <p>
430.1539 +     * A character is uppercase if its general category type, provided by
430.1540 +     * {@code Character.getType(ch)}, is {@code UPPERCASE_LETTER}.
430.1541 +     * or it has contributory property Other_Uppercase as defined by the Unicode Standard.
430.1542 +     * <p>
430.1543 +     * The following are examples of uppercase characters:
430.1544 +     * <p><blockquote><pre>
430.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
430.1546 +     * '&#92;u00C0' '&#92;u00C1' '&#92;u00C2' '&#92;u00C3' '&#92;u00C4' '&#92;u00C5' '&#92;u00C6' '&#92;u00C7'
430.1547 +     * '&#92;u00C8' '&#92;u00C9' '&#92;u00CA' '&#92;u00CB' '&#92;u00CC' '&#92;u00CD' '&#92;u00CE' '&#92;u00CF'
430.1548 +     * '&#92;u00D0' '&#92;u00D1' '&#92;u00D2' '&#92;u00D3' '&#92;u00D4' '&#92;u00D5' '&#92;u00D6' '&#92;u00D8'
430.1549 +     * '&#92;u00D9' '&#92;u00DA' '&#92;u00DB' '&#92;u00DC' '&#92;u00DD' '&#92;u00DE'
430.1550 +     * </pre></blockquote>
430.1551 +     * <p> Many other Unicode characters are uppercase too.<p>
430.1552 +     *
430.1553 +     * <p><b>Note:</b> This method cannot handle <a
430.1554 +     * href="#supplementary"> supplementary characters</a>. To support
430.1555 +     * all Unicode characters, including supplementary characters, use
430.1556 +     * the {@link #isUpperCase(int)} method.
430.1557 +     *
430.1558 +     * @param   ch   the character to be tested.
430.1559 +     * @return  {@code true} if the character is uppercase;
430.1560 +     *          {@code false} otherwise.
430.1561 +     * @see     Character#isLowerCase(char)
430.1562 +     * @see     Character#isTitleCase(char)
430.1563 +     * @see     Character#toUpperCase(char)
430.1564 +     * @see     Character#getType(char)
430.1565 +     * @since   1.0
430.1566 +     */
430.1567 +    public static boolean isUpperCase(char ch) {
430.1568 +        return ch == toUpperCase(ch);
430.1569 +    }
430.1570 +
430.1571 +    /**
430.1572 +     * Determines if the specified character is a titlecase character.
430.1573 +     * <p>
430.1574 +     * A character is a titlecase character if its general
430.1575 +     * category type, provided by {@code Character.getType(ch)},
430.1576 +     * is {@code TITLECASE_LETTER}.
430.1577 +     * <p>
430.1578 +     * Some characters look like pairs of Latin letters. For example, there
430.1579 +     * is an uppercase letter that looks like "LJ" and has a corresponding
430.1580 +     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
430.1581 +     * is the appropriate form to use when rendering a word in lowercase
430.1582 +     * with initial capitals, as for a book title.
430.1583 +     * <p>
430.1584 +     * These are some of the Unicode characters for which this method returns
430.1585 +     * {@code true}:
430.1586 +     * <ul>
430.1587 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
430.1588 +     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
430.1589 +     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
430.1590 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
430.1591 +     * </ul>
430.1592 +     * <p> Many other Unicode characters are titlecase too.<p>
430.1593 +     *
430.1594 +     * <p><b>Note:</b> This method cannot handle <a
430.1595 +     * href="#supplementary"> supplementary characters</a>. To support
430.1596 +     * all Unicode characters, including supplementary characters, use
430.1597 +     * the {@link #isTitleCase(int)} method.
430.1598 +     *
430.1599 +     * @param   ch   the character to be tested.
430.1600 +     * @return  {@code true} if the character is titlecase;
430.1601 +     *          {@code false} otherwise.
430.1602 +     * @see     Character#isLowerCase(char)
430.1603 +     * @see     Character#isUpperCase(char)
430.1604 +     * @see     Character#toTitleCase(char)
430.1605 +     * @see     Character#getType(char)
430.1606 +     * @since   1.0.2
430.1607 +     */
430.1608 +    public static boolean isTitleCase(char ch) {
430.1609 +        return isTitleCase((int)ch);
430.1610 +    }
430.1611 +
430.1612 +    /**
430.1613 +     * Determines if the specified character (Unicode code point) is a titlecase character.
430.1614 +     * <p>
430.1615 +     * A character is a titlecase character if its general
430.1616 +     * category type, provided by {@link Character#getType(int) getType(codePoint)},
430.1617 +     * is {@code TITLECASE_LETTER}.
430.1618 +     * <p>
430.1619 +     * Some characters look like pairs of Latin letters. For example, there
430.1620 +     * is an uppercase letter that looks like "LJ" and has a corresponding
430.1621 +     * lowercase letter that looks like "lj". A third form, which looks like "Lj",
430.1622 +     * is the appropriate form to use when rendering a word in lowercase
430.1623 +     * with initial capitals, as for a book title.
430.1624 +     * <p>
430.1625 +     * These are some of the Unicode characters for which this method returns
430.1626 +     * {@code true}:
430.1627 +     * <ul>
430.1628 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
430.1629 +     * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
430.1630 +     * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
430.1631 +     * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
430.1632 +     * </ul>
430.1633 +     * <p> Many other Unicode characters are titlecase too.<p>
430.1634 +     *
430.1635 +     * @param   codePoint the character (Unicode code point) to be tested.
430.1636 +     * @return  {@code true} if the character is titlecase;
430.1637 +     *          {@code false} otherwise.
430.1638 +     * @see     Character#isLowerCase(int)
430.1639 +     * @see     Character#isUpperCase(int)
430.1640 +     * @see     Character#toTitleCase(int)
430.1641 +     * @see     Character#getType(int)
430.1642 +     * @since   1.5
430.1643 +     */
430.1644 +    public static boolean isTitleCase(int codePoint) {
430.1645 +        return getType(codePoint) == Character.TITLECASE_LETTER;
430.1646 +    }
430.1647 +
430.1648 +    /**
430.1649 +     * Determines if the specified character is a digit.
430.1650 +     * <p>
430.1651 +     * A character is a digit if its general category type, provided
430.1652 +     * by {@code Character.getType(ch)}, is
430.1653 +     * {@code DECIMAL_DIGIT_NUMBER}.
430.1654 +     * <p>
430.1655 +     * Some Unicode character ranges that contain digits:
430.1656 +     * <ul>
430.1657 +     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
430.1658 +     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
430.1659 +     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
430.1660 +     *     Arabic-Indic digits
430.1661 +     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
430.1662 +     *     Extended Arabic-Indic digits
430.1663 +     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
430.1664 +     *     Devanagari digits
430.1665 +     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
430.1666 +     *     Fullwidth digits
430.1667 +     * </ul>
430.1668 +     *
430.1669 +     * Many other character ranges contain digits as well.
430.1670 +     *
430.1671 +     * <p><b>Note:</b> This method cannot handle <a
430.1672 +     * href="#supplementary"> supplementary characters</a>. To support
430.1673 +     * all Unicode characters, including supplementary characters, use
430.1674 +     * the {@link #isDigit(int)} method.
430.1675 +     *
430.1676 +     * @param   ch   the character to be tested.
430.1677 +     * @return  {@code true} if the character is a digit;
430.1678 +     *          {@code false} otherwise.
430.1679 +     * @see     Character#digit(char, int)
430.1680 +     * @see     Character#forDigit(int, int)
430.1681 +     * @see     Character#getType(char)
430.1682 +     */
430.1683 +    public static boolean isDigit(char ch) {
430.1684 +        return String.valueOf(ch).matches("\\d");
430.1685 +    }
430.1686 +
430.1687 +    /**
430.1688 +     * Determines if the specified character (Unicode code point) is a digit.
430.1689 +     * <p>
430.1690 +     * A character is a digit if its general category type, provided
430.1691 +     * by {@link Character#getType(int) getType(codePoint)}, is
430.1692 +     * {@code DECIMAL_DIGIT_NUMBER}.
430.1693 +     * <p>
430.1694 +     * Some Unicode character ranges that contain digits:
430.1695 +     * <ul>
430.1696 +     * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
430.1697 +     *     ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
430.1698 +     * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
430.1699 +     *     Arabic-Indic digits
430.1700 +     * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
430.1701 +     *     Extended Arabic-Indic digits
430.1702 +     * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
430.1703 +     *     Devanagari digits
430.1704 +     * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
430.1705 +     *     Fullwidth digits
430.1706 +     * </ul>
430.1707 +     *
430.1708 +     * Many other character ranges contain digits as well.
430.1709 +     *
430.1710 +     * @param   codePoint the character (Unicode code point) to be tested.
430.1711 +     * @return  {@code true} if the character is a digit;
430.1712 +     *          {@code false} otherwise.
430.1713 +     * @see     Character#forDigit(int, int)
430.1714 +     * @see     Character#getType(int)
430.1715 +     * @since   1.5
430.1716 +     */
430.1717 +    public static boolean isDigit(int codePoint) {
430.1718 +        return fromCodeChars(codePoint).matches("\\d");
430.1719 +    }
430.1720 +    
430.1721 +    @JavaScriptBody(args = "c", body = "return String.fromCharCode(c);")
430.1722 +    private native static String fromCodeChars(int codePoint);
430.1723 +
430.1724 +    /**
430.1725 +     * Determines if a character is defined in Unicode.
430.1726 +     * <p>
430.1727 +     * A character is defined if at least one of the following is true:
430.1728 +     * <ul>
430.1729 +     * <li>It has an entry in the UnicodeData file.
430.1730 +     * <li>It has a value in a range defined by the UnicodeData file.
430.1731 +     * </ul>
430.1732 +     *
430.1733 +     * <p><b>Note:</b> This method cannot handle <a
430.1734 +     * href="#supplementary"> supplementary characters</a>. To support
430.1735 +     * all Unicode characters, including supplementary characters, use
430.1736 +     * the {@link #isDefined(int)} method.
430.1737 +     *
430.1738 +     * @param   ch   the character to be tested
430.1739 +     * @return  {@code true} if the character has a defined meaning
430.1740 +     *          in Unicode; {@code false} otherwise.
430.1741 +     * @see     Character#isDigit(char)
430.1742 +     * @see     Character#isLetter(char)
430.1743 +     * @see     Character#isLetterOrDigit(char)
430.1744 +     * @see     Character#isLowerCase(char)
430.1745 +     * @see     Character#isTitleCase(char)
430.1746 +     * @see     Character#isUpperCase(char)
430.1747 +     * @since   1.0.2
430.1748 +     */
430.1749 +    public static boolean isDefined(char ch) {
430.1750 +        return isDefined((int)ch);
430.1751 +    }
430.1752 +
430.1753 +    /**
430.1754 +     * Determines if a character (Unicode code point) is defined in Unicode.
430.1755 +     * <p>
430.1756 +     * A character is defined if at least one of the following is true:
430.1757 +     * <ul>
430.1758 +     * <li>It has an entry in the UnicodeData file.
430.1759 +     * <li>It has a value in a range defined by the UnicodeData file.
430.1760 +     * </ul>
430.1761 +     *
430.1762 +     * @param   codePoint the character (Unicode code point) to be tested.
430.1763 +     * @return  {@code true} if the character has a defined meaning
430.1764 +     *          in Unicode; {@code false} otherwise.
430.1765 +     * @see     Character#isDigit(int)
430.1766 +     * @see     Character#isLetter(int)
430.1767 +     * @see     Character#isLetterOrDigit(int)
430.1768 +     * @see     Character#isLowerCase(int)
430.1769 +     * @see     Character#isTitleCase(int)
430.1770 +     * @see     Character#isUpperCase(int)
430.1771 +     * @since   1.5
430.1772 +     */
430.1773 +    public static boolean isDefined(int codePoint) {
430.1774 +        return getType(codePoint) != Character.UNASSIGNED;
430.1775 +    }
430.1776 +
430.1777 +    /**
430.1778 +     * Determines if the specified character is a letter.
430.1779 +     * <p>
430.1780 +     * A character is considered to be a letter if its general
430.1781 +     * category type, provided by {@code Character.getType(ch)},
430.1782 +     * is any of the following:
430.1783 +     * <ul>
430.1784 +     * <li> {@code UPPERCASE_LETTER}
430.1785 +     * <li> {@code LOWERCASE_LETTER}
430.1786 +     * <li> {@code TITLECASE_LETTER}
430.1787 +     * <li> {@code MODIFIER_LETTER}
430.1788 +     * <li> {@code OTHER_LETTER}
430.1789 +     * </ul>
430.1790 +     *
430.1791 +     * Not all letters have case. Many characters are
430.1792 +     * letters but are neither uppercase nor lowercase nor titlecase.
430.1793 +     *
430.1794 +     * <p><b>Note:</b> This method cannot handle <a
430.1795 +     * href="#supplementary"> supplementary characters</a>. To support
430.1796 +     * all Unicode characters, including supplementary characters, use
430.1797 +     * the {@link #isLetter(int)} method.
430.1798 +     *
430.1799 +     * @param   ch   the character to be tested.
430.1800 +     * @return  {@code true} if the character is a letter;
430.1801 +     *          {@code false} otherwise.
430.1802 +     * @see     Character#isDigit(char)
430.1803 +     * @see     Character#isJavaIdentifierStart(char)
430.1804 +     * @see     Character#isJavaLetter(char)
430.1805 +     * @see     Character#isJavaLetterOrDigit(char)
430.1806 +     * @see     Character#isLetterOrDigit(char)
430.1807 +     * @see     Character#isLowerCase(char)
430.1808 +     * @see     Character#isTitleCase(char)
430.1809 +     * @see     Character#isUnicodeIdentifierStart(char)
430.1810 +     * @see     Character#isUpperCase(char)
430.1811 +     */
430.1812 +    public static boolean isLetter(char ch) {
430.1813 +        return String.valueOf(ch).matches("\\w") && !isDigit(ch);
430.1814 +    }
430.1815 +
430.1816 +    /**
430.1817 +     * Determines if the specified character (Unicode code point) is a letter.
430.1818 +     * <p>
430.1819 +     * A character is considered to be a letter if its general
430.1820 +     * category type, provided by {@link Character#getType(int) getType(codePoint)},
430.1821 +     * is any of the following:
430.1822 +     * <ul>
430.1823 +     * <li> {@code UPPERCASE_LETTER}
430.1824 +     * <li> {@code LOWERCASE_LETTER}
430.1825 +     * <li> {@code TITLECASE_LETTER}
430.1826 +     * <li> {@code MODIFIER_LETTER}
430.1827 +     * <li> {@code OTHER_LETTER}
430.1828 +     * </ul>
430.1829 +     *
430.1830 +     * Not all letters have case. Many characters are
430.1831 +     * letters but are neither uppercase nor lowercase nor titlecase.
430.1832 +     *
430.1833 +     * @param   codePoint the character (Unicode code point) to be tested.
430.1834 +     * @return  {@code true} if the character is a letter;
430.1835 +     *          {@code false} otherwise.
430.1836 +     * @see     Character#isDigit(int)
430.1837 +     * @see     Character#isJavaIdentifierStart(int)
430.1838 +     * @see     Character#isLetterOrDigit(int)
430.1839 +     * @see     Character#isLowerCase(int)
430.1840 +     * @see     Character#isTitleCase(int)
430.1841 +     * @see     Character#isUnicodeIdentifierStart(int)
430.1842 +     * @see     Character#isUpperCase(int)
430.1843 +     * @since   1.5
430.1844 +     */
430.1845 +    public static boolean isLetter(int codePoint) {
430.1846 +        return fromCodeChars(codePoint).matches("\\w") && !isDigit(codePoint);
430.1847 +    }
430.1848 +
430.1849 +    /**
430.1850 +     * Determines if the specified character is a letter or digit.
430.1851 +     * <p>
430.1852 +     * A character is considered to be a letter or digit if either
430.1853 +     * {@code Character.isLetter(char ch)} or
430.1854 +     * {@code Character.isDigit(char ch)} returns
430.1855 +     * {@code true} for the character.
430.1856 +     *
430.1857 +     * <p><b>Note:</b> This method cannot handle <a
430.1858 +     * href="#supplementary"> supplementary characters</a>. To support
430.1859 +     * all Unicode characters, including supplementary characters, use
430.1860 +     * the {@link #isLetterOrDigit(int)} method.
430.1861 +     *
430.1862 +     * @param   ch   the character to be tested.
430.1863 +     * @return  {@code true} if the character is a letter or digit;
430.1864 +     *          {@code false} otherwise.
430.1865 +     * @see     Character#isDigit(char)
430.1866 +     * @see     Character#isJavaIdentifierPart(char)
430.1867 +     * @see     Character#isJavaLetter(char)
430.1868 +     * @see     Character#isJavaLetterOrDigit(char)
430.1869 +     * @see     Character#isLetter(char)
430.1870 +     * @see     Character#isUnicodeIdentifierPart(char)
430.1871 +     * @since   1.0.2
430.1872 +     */
430.1873 +    public static boolean isLetterOrDigit(char ch) {
430.1874 +        return String.valueOf(ch).matches("\\w");
430.1875 +    }
430.1876 +
430.1877 +    /**
430.1878 +     * Determines if the specified character (Unicode code point) is a letter or digit.
430.1879 +     * <p>
430.1880 +     * A character is considered to be a letter or digit if either
430.1881 +     * {@link #isLetter(int) isLetter(codePoint)} or
430.1882 +     * {@link #isDigit(int) isDigit(codePoint)} returns
430.1883 +     * {@code true} for the character.
430.1884 +     *
430.1885 +     * @param   codePoint the character (Unicode code point) to be tested.
430.1886 +     * @return  {@code true} if the character is a letter or digit;
430.1887 +     *          {@code false} otherwise.
430.1888 +     * @see     Character#isDigit(int)
430.1889 +     * @see     Character#isJavaIdentifierPart(int)
430.1890 +     * @see     Character#isLetter(int)
430.1891 +     * @see     Character#isUnicodeIdentifierPart(int)
430.1892 +     * @since   1.5
430.1893 +     */
430.1894 +    public static boolean isLetterOrDigit(int codePoint) {
430.1895 +        return fromCodeChars(codePoint).matches("\\w");
430.1896 +    }
430.1897 +    
430.1898 +    static int getType(int x) {
430.1899 +        throw new UnsupportedOperationException();
430.1900 +    }
430.1901 + 
430.1902 +    /**
430.1903 +     * Determines if the specified character is
430.1904 +     * permissible as the first character in a Java identifier.
430.1905 +     * <p>
430.1906 +     * A character may start a Java identifier if and only if
430.1907 +     * one of the following conditions is true:
430.1908 +     * <ul>
430.1909 +     * <li> {@link #isLetter(char) isLetter(ch)} returns {@code true}
430.1910 +     * <li> {@link #getType(char) getType(ch)} returns {@code LETTER_NUMBER}
430.1911 +     * <li> {@code ch} is a currency symbol (such as {@code '$'})
430.1912 +     * <li> {@code ch} is a connecting punctuation character (such as {@code '_'}).
430.1913 +     * </ul>
430.1914 +     *
430.1915 +     * <p><b>Note:</b> This method cannot handle <a
430.1916 +     * href="#supplementary"> supplementary characters</a>. To support
430.1917 +     * all Unicode characters, including supplementary characters, use
430.1918 +     * the {@link #isJavaIdentifierStart(int)} method.
430.1919 +     *
430.1920 +     * @param   ch the character to be tested.
430.1921 +     * @return  {@code true} if the character may start a Java identifier;
430.1922 +     *          {@code false} otherwise.
430.1923 +     * @see     Character#isJavaIdentifierPart(char)
430.1924 +     * @see     Character#isLetter(char)
430.1925 +     * @see     Character#isUnicodeIdentifierStart(char)
430.1926 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
430.1927 +     * @since   1.1
430.1928 +     */
430.1929 +    public static boolean isJavaIdentifierStart(char ch) {
430.1930 +        return isJavaIdentifierStart((int)ch);
430.1931 +    }
430.1932 +
430.1933 +    /**
430.1934 +     * Determines if the character (Unicode code point) is
430.1935 +     * permissible as the first character in a Java identifier.
430.1936 +     * <p>
430.1937 +     * A character may start a Java identifier if and only if
430.1938 +     * one of the following conditions is true:
430.1939 +     * <ul>
430.1940 +     * <li> {@link #isLetter(int) isLetter(codePoint)}
430.1941 +     *      returns {@code true}
430.1942 +     * <li> {@link #getType(int) getType(codePoint)}
430.1943 +     *      returns {@code LETTER_NUMBER}
430.1944 +     * <li> the referenced character is a currency symbol (such as {@code '$'})
430.1945 +     * <li> the referenced character is a connecting punctuation character
430.1946 +     *      (such as {@code '_'}).
430.1947 +     * </ul>
430.1948 +     *
430.1949 +     * @param   codePoint the character (Unicode code point) to be tested.
430.1950 +     * @return  {@code true} if the character may start a Java identifier;
430.1951 +     *          {@code false} otherwise.
430.1952 +     * @see     Character#isJavaIdentifierPart(int)
430.1953 +     * @see     Character#isLetter(int)
430.1954 +     * @see     Character#isUnicodeIdentifierStart(int)
430.1955 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
430.1956 +     * @since   1.5
430.1957 +     */
430.1958 +    public static boolean isJavaIdentifierStart(int codePoint) {
430.1959 +        return 
430.1960 +            ('A' <= codePoint && codePoint <= 'Z') ||
430.1961 +            ('a' <= codePoint && codePoint <= 'z');
430.1962 +    }
430.1963 +
430.1964 +    /**
430.1965 +     * Determines if the specified character may be part of a Java
430.1966 +     * identifier as other than the first character.
430.1967 +     * <p>
430.1968 +     * A character may be part of a Java identifier if any of the following
430.1969 +     * are true:
430.1970 +     * <ul>
430.1971 +     * <li>  it is a letter
430.1972 +     * <li>  it is a currency symbol (such as {@code '$'})
430.1973 +     * <li>  it is a connecting punctuation character (such as {@code '_'})
430.1974 +     * <li>  it is a digit
430.1975 +     * <li>  it is a numeric letter (such as a Roman numeral character)
430.1976 +     * <li>  it is a combining mark
430.1977 +     * <li>  it is a non-spacing mark
430.1978 +     * <li> {@code isIdentifierIgnorable} returns
430.1979 +     * {@code true} for the character
430.1980 +     * </ul>
430.1981 +     *
430.1982 +     * <p><b>Note:</b> This method cannot handle <a
430.1983 +     * href="#supplementary"> supplementary characters</a>. To support
430.1984 +     * all Unicode characters, including supplementary characters, use
430.1985 +     * the {@link #isJavaIdentifierPart(int)} method.
430.1986 +     *
430.1987 +     * @param   ch      the character to be tested.
430.1988 +     * @return {@code true} if the character may be part of a
430.1989 +     *          Java identifier; {@code false} otherwise.
430.1990 +     * @see     Character#isIdentifierIgnorable(char)
430.1991 +     * @see     Character#isJavaIdentifierStart(char)
430.1992 +     * @see     Character#isLetterOrDigit(char)
430.1993 +     * @see     Character#isUnicodeIdentifierPart(char)
430.1994 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
430.1995 +     * @since   1.1
430.1996 +     */
430.1997 +    public static boolean isJavaIdentifierPart(char ch) {
430.1998 +        return isJavaIdentifierPart((int)ch);
430.1999 +    }
430.2000 +
430.2001 +    /**
430.2002 +     * Determines if the character (Unicode code point) may be part of a Java
430.2003 +     * identifier as other than the first character.
430.2004 +     * <p>
430.2005 +     * A character may be part of a Java identifier if any of the following
430.2006 +     * are true:
430.2007 +     * <ul>
430.2008 +     * <li>  it is a letter
430.2009 +     * <li>  it is a currency symbol (such as {@code '$'})
430.2010 +     * <li>  it is a connecting punctuation character (such as {@code '_'})
430.2011 +     * <li>  it is a digit
430.2012 +     * <li>  it is a numeric letter (such as a Roman numeral character)
430.2013 +     * <li>  it is a combining mark
430.2014 +     * <li>  it is a non-spacing mark
430.2015 +     * <li> {@link #isIdentifierIgnorable(int)
430.2016 +     * isIdentifierIgnorable(codePoint)} returns {@code true} for
430.2017 +     * the character
430.2018 +     * </ul>
430.2019 +     *
430.2020 +     * @param   codePoint the character (Unicode code point) to be tested.
430.2021 +     * @return {@code true} if the character may be part of a
430.2022 +     *          Java identifier; {@code false} otherwise.
430.2023 +     * @see     Character#isIdentifierIgnorable(int)
430.2024 +     * @see     Character#isJavaIdentifierStart(int)
430.2025 +     * @see     Character#isLetterOrDigit(int)
430.2026 +     * @see     Character#isUnicodeIdentifierPart(int)
430.2027 +     * @see     javax.lang.model.SourceVersion#isIdentifier(CharSequence)
430.2028 +     * @since   1.5
430.2029 +     */
430.2030 +    public static boolean isJavaIdentifierPart(int codePoint) {
430.2031 +        return isJavaIdentifierStart(codePoint) ||
430.2032 +            ('0' <= codePoint && codePoint <= '9') || codePoint == '$';
430.2033 +    }
430.2034 +   
430.2035 +    /**
430.2036 +     * Converts the character argument to lowercase using case
430.2037 +     * mapping information from the UnicodeData file.
430.2038 +     * <p>
430.2039 +     * Note that
430.2040 +     * {@code Character.isLowerCase(Character.toLowerCase(ch))}
430.2041 +     * does not always return {@code true} for some ranges of
430.2042 +     * characters, particularly those that are symbols or ideographs.
430.2043 +     *
430.2044 +     * <p>In general, {@link String#toLowerCase()} should be used to map
430.2045 +     * characters to lowercase. {@code String} case mapping methods
430.2046 +     * have several benefits over {@code Character} case mapping methods.
430.2047 +     * {@code String} case mapping methods can perform locale-sensitive
430.2048 +     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
430.2049 +     * the {@code Character} case mapping methods cannot.
430.2050 +     *
430.2051 +     * <p><b>Note:</b> This method cannot handle <a
430.2052 +     * href="#supplementary"> supplementary characters</a>. To support
430.2053 +     * all Unicode characters, including supplementary characters, use
430.2054 +     * the {@link #toLowerCase(int)} method.
430.2055 +     *
430.2056 +     * @param   ch   the character to be converted.
430.2057 +     * @return  the lowercase equivalent of the character, if any;
430.2058 +     *          otherwise, the character itself.
430.2059 +     * @see     Character#isLowerCase(char)
430.2060 +     * @see     String#toLowerCase()
430.2061 +     */
430.2062 +    public static char toLowerCase(char ch) {
430.2063 +        return String.valueOf(ch).toLowerCase().charAt(0);
430.2064 +    }
430.2065 +
430.2066 +    /**
430.2067 +     * Converts the character argument to uppercase using case mapping
430.2068 +     * information from the UnicodeData file.
430.2069 +     * <p>
430.2070 +     * Note that
430.2071 +     * {@code Character.isUpperCase(Character.toUpperCase(ch))}
430.2072 +     * does not always return {@code true} for some ranges of
430.2073 +     * characters, particularly those that are symbols or ideographs.
430.2074 +     *
430.2075 +     * <p>In general, {@link String#toUpperCase()} should be used to map
430.2076 +     * characters to uppercase. {@code String} case mapping methods
430.2077 +     * have several benefits over {@code Character} case mapping methods.
430.2078 +     * {@code String} case mapping methods can perform locale-sensitive
430.2079 +     * mappings, context-sensitive mappings, and 1:M character mappings, whereas
430.2080 +     * the {@code Character} case mapping methods cannot.
430.2081 +     *
430.2082 +     * <p><b>Note:</b> This method cannot handle <a
430.2083 +     * href="#supplementary"> supplementary characters</a>. To support
430.2084 +     * all Unicode characters, including supplementary characters, use
430.2085 +     * the {@link #toUpperCase(int)} method.
430.2086 +     *
430.2087 +     * @param   ch   the character to be converted.
430.2088 +     * @return  the uppercase equivalent of the character, if any;
430.2089 +     *          otherwise, the character itself.
430.2090 +     * @see     Character#isUpperCase(char)
430.2091 +     * @see     String#toUpperCase()
430.2092 +     */
430.2093 +    public static char toUpperCase(char ch) {
430.2094 +        return String.valueOf(ch).toUpperCase().charAt(0);
430.2095 +    }
430.2096 +
430.2097 +    /**
430.2098 +     * Returns the numeric value of the character {@code ch} in the
430.2099 +     * specified radix.
430.2100 +     * <p>
430.2101 +     * If the radix is not in the range {@code MIN_RADIX} &le;
430.2102 +     * {@code radix} &le; {@code MAX_RADIX} or if the
430.2103 +     * value of {@code ch} is not a valid digit in the specified
430.2104 +     * radix, {@code -1} is returned. A character is a valid digit
430.2105 +     * if at least one of the following is true:
430.2106 +     * <ul>
430.2107 +     * <li>The method {@code isDigit} is {@code true} of the character
430.2108 +     *     and the Unicode decimal digit value of the character (or its
430.2109 +     *     single-character decomposition) is less than the specified radix.
430.2110 +     *     In this case the decimal digit value is returned.
430.2111 +     * <li>The character is one of the uppercase Latin letters
430.2112 +     *     {@code 'A'} through {@code 'Z'} and its code is less than
430.2113 +     *     {@code radix + 'A' - 10}.
430.2114 +     *     In this case, {@code ch - 'A' + 10}
430.2115 +     *     is returned.
430.2116 +     * <li>The character is one of the lowercase Latin letters
430.2117 +     *     {@code 'a'} through {@code 'z'} and its code is less than
430.2118 +     *     {@code radix + 'a' - 10}.
430.2119 +     *     In this case, {@code ch - 'a' + 10}
430.2120 +     *     is returned.
430.2121 +     * <li>The character is one of the fullwidth uppercase Latin letters A
430.2122 +     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
430.2123 +     *     and its code is less than
430.2124 +     *     {@code radix + '\u005CuFF21' - 10}.
430.2125 +     *     In this case, {@code ch - '\u005CuFF21' + 10}
430.2126 +     *     is returned.
430.2127 +     * <li>The character is one of the fullwidth lowercase Latin letters a
430.2128 +     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
430.2129 +     *     and its code is less than
430.2130 +     *     {@code radix + '\u005CuFF41' - 10}.
430.2131 +     *     In this case, {@code ch - '\u005CuFF41' + 10}
430.2132 +     *     is returned.
430.2133 +     * </ul>
430.2134 +     *
430.2135 +     * <p><b>Note:</b> This method cannot handle <a
430.2136 +     * href="#supplementary"> supplementary characters</a>. To support
430.2137 +     * all Unicode characters, including supplementary characters, use
430.2138 +     * the {@link #digit(int, int)} method.
430.2139 +     *
430.2140 +     * @param   ch      the character to be converted.
430.2141 +     * @param   radix   the radix.
430.2142 +     * @return  the numeric value represented by the character in the
430.2143 +     *          specified radix.
430.2144 +     * @see     Character#forDigit(int, int)
430.2145 +     * @see     Character#isDigit(char)
430.2146 +     */
430.2147 +    public static int digit(char ch, int radix) {
430.2148 +        return digit((int)ch, radix);
430.2149 +    }
430.2150 +
430.2151 +    /**
430.2152 +     * Returns the numeric value of the specified character (Unicode
430.2153 +     * code point) in the specified radix.
430.2154 +     *
430.2155 +     * <p>If the radix is not in the range {@code MIN_RADIX} &le;
430.2156 +     * {@code radix} &le; {@code MAX_RADIX} or if the
430.2157 +     * character is not a valid digit in the specified
430.2158 +     * radix, {@code -1} is returned. A character is a valid digit
430.2159 +     * if at least one of the following is true:
430.2160 +     * <ul>
430.2161 +     * <li>The method {@link #isDigit(int) isDigit(codePoint)} is {@code true} of the character
430.2162 +     *     and the Unicode decimal digit value of the character (or its
430.2163 +     *     single-character decomposition) is less than the specified radix.
430.2164 +     *     In this case the decimal digit value is returned.
430.2165 +     * <li>The character is one of the uppercase Latin letters
430.2166 +     *     {@code 'A'} through {@code 'Z'} and its code is less than
430.2167 +     *     {@code radix + 'A' - 10}.
430.2168 +     *     In this case, {@code codePoint - 'A' + 10}
430.2169 +     *     is returned.
430.2170 +     * <li>The character is one of the lowercase Latin letters
430.2171 +     *     {@code 'a'} through {@code 'z'} and its code is less than
430.2172 +     *     {@code radix + 'a' - 10}.
430.2173 +     *     In this case, {@code codePoint - 'a' + 10}
430.2174 +     *     is returned.
430.2175 +     * <li>The character is one of the fullwidth uppercase Latin letters A
430.2176 +     *     ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
430.2177 +     *     and its code is less than
430.2178 +     *     {@code radix + '\u005CuFF21' - 10}.
430.2179 +     *     In this case,
430.2180 +     *     {@code codePoint - '\u005CuFF21' + 10}
430.2181 +     *     is returned.
430.2182 +     * <li>The character is one of the fullwidth lowercase Latin letters a
430.2183 +     *     ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
430.2184 +     *     and its code is less than
430.2185 +     *     {@code radix + '\u005CuFF41'- 10}.
430.2186 +     *     In this case,
430.2187 +     *     {@code codePoint - '\u005CuFF41' + 10}
430.2188 +     *     is returned.
430.2189 +     * </ul>
430.2190 +     *
430.2191 +     * @param   codePoint the character (Unicode code point) to be converted.
430.2192 +     * @param   radix   the radix.
430.2193 +     * @return  the numeric value represented by the character in the
430.2194 +     *          specified radix.
430.2195 +     * @see     Character#forDigit(int, int)
430.2196 +     * @see     Character#isDigit(int)
430.2197 +     * @since   1.5
430.2198 +     */
430.2199 +    @JavaScriptBody(args = { "codePoint", "radix" }, body=
430.2200 +        "var x = parseInt(String.fromCharCode(codePoint), radix);\n"
430.2201 +      + "return isNaN(x) ? -1 : x;"
430.2202 +    )
430.2203 +    public static int digit(int codePoint, int radix) {
430.2204 +        throw new UnsupportedOperationException();
430.2205 +    }
430.2206 +
430.2207 +    /**
430.2208 +     * Returns the {@code int} value that the specified Unicode
430.2209 +     * character represents. For example, the character
430.2210 +     * {@code '\u005Cu216C'} (the roman numeral fifty) will return
430.2211 +     * an int with a value of 50.
430.2212 +     * <p>
430.2213 +     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
430.2214 +     * {@code '\u005Cu005A'}), lowercase
430.2215 +     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
430.2216 +     * full width variant ({@code '\u005CuFF21'} through
430.2217 +     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
430.2218 +     * {@code '\u005CuFF5A'}) forms have numeric values from 10
430.2219 +     * through 35. This is independent of the Unicode specification,
430.2220 +     * which does not assign numeric values to these {@code char}
430.2221 +     * values.
430.2222 +     * <p>
430.2223 +     * If the character does not have a numeric value, then -1 is returned.
430.2224 +     * If the character has a numeric value that cannot be represented as a
430.2225 +     * nonnegative integer (for example, a fractional value), then -2
430.2226 +     * is returned.
430.2227 +     *
430.2228 +     * <p><b>Note:</b> This method cannot handle <a
430.2229 +     * href="#supplementary"> supplementary characters</a>. To support
430.2230 +     * all Unicode characters, including supplementary characters, use
430.2231 +     * the {@link #getNumericValue(int)} method.
430.2232 +     *
430.2233 +     * @param   ch      the character to be converted.
430.2234 +     * @return  the numeric value of the character, as a nonnegative {@code int}
430.2235 +     *           value; -2 if the character has a numeric value that is not a
430.2236 +     *          nonnegative integer; -1 if the character has no numeric value.
430.2237 +     * @see     Character#forDigit(int, int)
430.2238 +     * @see     Character#isDigit(char)
430.2239 +     * @since   1.1
430.2240 +     */
430.2241 +    public static int getNumericValue(char ch) {
430.2242 +        return getNumericValue((int)ch);
430.2243 +    }
430.2244 +
430.2245 +    /**
430.2246 +     * Returns the {@code int} value that the specified
430.2247 +     * character (Unicode code point) represents. For example, the character
430.2248 +     * {@code '\u005Cu216C'} (the Roman numeral fifty) will return
430.2249 +     * an {@code int} with a value of 50.
430.2250 +     * <p>
430.2251 +     * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
430.2252 +     * {@code '\u005Cu005A'}), lowercase
430.2253 +     * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
430.2254 +     * full width variant ({@code '\u005CuFF21'} through
430.2255 +     * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
430.2256 +     * {@code '\u005CuFF5A'}) forms have numeric values from 10
430.2257 +     * through 35. This is independent of the Unicode specification,
430.2258 +     * which does not assign numeric values to these {@code char}
430.2259 +     * values.
430.2260 +     * <p>
430.2261 +     * If the character does not have a numeric value, then -1 is returned.
430.2262 +     * If the character has a numeric value that cannot be represented as a
430.2263 +     * nonnegative integer (for example, a fractional value), then -2
430.2264 +     * is returned.
430.2265 +     *
430.2266 +     * @param   codePoint the character (Unicode code point) to be converted.
430.2267 +     * @return  the numeric value of the character, as a nonnegative {@code int}
430.2268 +     *          value; -2 if the character has a numeric value that is not a
430.2269 +     *          nonnegative integer; -1 if the character has no numeric value.
430.2270 +     * @see     Character#forDigit(int, int)
430.2271 +     * @see     Character#isDigit(int)
430.2272 +     * @since   1.5
430.2273 +     */
430.2274 +    public static int getNumericValue(int codePoint) {
430.2275 +        throw new UnsupportedOperationException();
430.2276 +    }
430.2277 +
430.2278 +    /**
430.2279 +     * Determines if the specified character is ISO-LATIN-1 white space.
430.2280 +     * This method returns {@code true} for the following five
430.2281 +     * characters only:
430.2282 +     * <table>
430.2283 +     * <tr><td>{@code '\t'}</td>            <td>{@code U+0009}</td>
430.2284 +     *     <td>{@code HORIZONTAL TABULATION}</td></tr>
430.2285 +     * <tr><td>{@code '\n'}</td>            <td>{@code U+000A}</td>
430.2286 +     *     <td>{@code NEW LINE}</td></tr>
430.2287 +     * <tr><td>{@code '\f'}</td>            <td>{@code U+000C}</td>
430.2288 +     *     <td>{@code FORM FEED}</td></tr>
430.2289 +     * <tr><td>{@code '\r'}</td>            <td>{@code U+000D}</td>
430.2290 +     *     <td>{@code CARRIAGE RETURN}</td></tr>
430.2291 +     * <tr><td>{@code '&nbsp;'}</td>  <td>{@code U+0020}</td>
430.2292 +     *     <td>{@code SPACE}</td></tr>
430.2293 +     * </table>
430.2294 +     *
430.2295 +     * @param      ch   the character to be tested.
430.2296 +     * @return     {@code true} if the character is ISO-LATIN-1 white
430.2297 +     *             space; {@code false} otherwise.
430.2298 +     * @see        Character#isSpaceChar(char)
430.2299 +     * @see        Character#isWhitespace(char)
430.2300 +     * @deprecated Replaced by isWhitespace(char).
430.2301 +     */
430.2302 +    @Deprecated
430.2303 +    public static boolean isSpace(char ch) {
430.2304 +        return (ch <= 0x0020) &&
430.2305 +            (((((1L << 0x0009) |
430.2306 +            (1L << 0x000A) |
430.2307 +            (1L << 0x000C) |
430.2308 +            (1L << 0x000D) |
430.2309 +            (1L << 0x0020)) >> ch) & 1L) != 0);
430.2310 +    }
430.2311 +
430.2312 +
430.2313 +
430.2314 +    /**
430.2315 +     * Determines if the specified character is white space according to Java.
430.2316 +     * A character is a Java whitespace character if and only if it satisfies
430.2317 +     * one of the following criteria:
430.2318 +     * <ul>
430.2319 +     * <li> It is a Unicode space character ({@code SPACE_SEPARATOR},
430.2320 +     *      {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})
430.2321 +     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
430.2322 +     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
430.2323 +     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
430.2324 +     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
430.2325 +     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
430.2326 +     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
430.2327 +     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
430.2328 +     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
430.2329 +     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
430.2330 +     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
430.2331 +     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
430.2332 +     * </ul>
430.2333 +     *
430.2334 +     * <p><b>Note:</b> This method cannot handle <a
430.2335 +     * href="#supplementary"> supplementary characters</a>. To support
430.2336 +     * all Unicode characters, including supplementary characters, use
430.2337 +     * the {@link #isWhitespace(int)} method.
430.2338 +     *
430.2339 +     * @param   ch the character to be tested.
430.2340 +     * @return  {@code true} if the character is a Java whitespace
430.2341 +     *          character; {@code false} otherwise.
430.2342 +     * @see     Character#isSpaceChar(char)
430.2343 +     * @since   1.1
430.2344 +     */
430.2345 +    public static boolean isWhitespace(char ch) {
430.2346 +        return isWhitespace((int)ch);
430.2347 +    }
430.2348 +
430.2349 +    /**
430.2350 +     * Determines if the specified character (Unicode code point) is
430.2351 +     * white space according to Java.  A character is a Java
430.2352 +     * whitespace character if and only if it satisfies one of the
430.2353 +     * following criteria:
430.2354 +     * <ul>
430.2355 +     * <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},
430.2356 +     *      {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})
430.2357 +     *      but is not also a non-breaking space ({@code '\u005Cu00A0'},
430.2358 +     *      {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
430.2359 +     * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
430.2360 +     * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
430.2361 +     * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
430.2362 +     * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
430.2363 +     * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
430.2364 +     * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
430.2365 +     * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
430.2366 +     * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
430.2367 +     * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
430.2368 +     * </ul>
430.2369 +     * <p>
430.2370 +     *
430.2371 +     * @param   codePoint the character (Unicode code point) to be tested.
430.2372 +     * @return  {@code true} if the character is a Java whitespace
430.2373 +     *          character; {@code false} otherwise.
430.2374 +     * @see     Character#isSpaceChar(int)
430.2375 +     * @since   1.5
430.2376 +     */
430.2377 +    public static boolean isWhitespace(int codePoint) {
430.2378 +        throw new UnsupportedOperationException();
430.2379 +    }
430.2380 +
430.2381 +    /**
430.2382 +     * Determines if the specified character is an ISO control
430.2383 +     * character.  A character is considered to be an ISO control
430.2384 +     * character if its code is in the range {@code '\u005Cu0000'}
430.2385 +     * through {@code '\u005Cu001F'} or in the range
430.2386 +     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
430.2387 +     *
430.2388 +     * <p><b>Note:</b> This method cannot handle <a
430.2389 +     * href="#supplementary"> supplementary characters</a>. To support
430.2390 +     * all Unicode characters, including supplementary characters, use
430.2391 +     * the {@link #isISOControl(int)} method.
430.2392 +     *
430.2393 +     * @param   ch      the character to be tested.
430.2394 +     * @return  {@code true} if the character is an ISO control character;
430.2395 +     *          {@code false} otherwise.
430.2396 +     *
430.2397 +     * @see     Character#isSpaceChar(char)
430.2398 +     * @see     Character#isWhitespace(char)
430.2399 +     * @since   1.1
430.2400 +     */
430.2401 +    public static boolean isISOControl(char ch) {
430.2402 +        return isISOControl((int)ch);
430.2403 +    }
430.2404 +
430.2405 +    /**
430.2406 +     * Determines if the referenced character (Unicode code point) is an ISO control
430.2407 +     * character.  A character is considered to be an ISO control
430.2408 +     * character if its code is in the range {@code '\u005Cu0000'}
430.2409 +     * through {@code '\u005Cu001F'} or in the range
430.2410 +     * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
430.2411 +     *
430.2412 +     * @param   codePoint the character (Unicode code point) to be tested.
430.2413 +     * @return  {@code true} if the character is an ISO control character;
430.2414 +     *          {@code false} otherwise.
430.2415 +     * @see     Character#isSpaceChar(int)
430.2416 +     * @see     Character#isWhitespace(int)
430.2417 +     * @since   1.5
430.2418 +     */
430.2419 +    public static boolean isISOControl(int codePoint) {
430.2420 +        // Optimized form of:
430.2421 +        //     (codePoint >= 0x00 && codePoint <= 0x1F) ||
430.2422 +        //     (codePoint >= 0x7F && codePoint <= 0x9F);
430.2423 +        return codePoint <= 0x9F &&
430.2424 +            (codePoint >= 0x7F || (codePoint >>> 5 == 0));
430.2425 +    }
430.2426 +
430.2427 +    /**
430.2428 +     * Determines the character representation for a specific digit in
430.2429 +     * the specified radix. If the value of {@code radix} is not a
430.2430 +     * valid radix, or the value of {@code digit} is not a valid
430.2431 +     * digit in the specified radix, the null character
430.2432 +     * ({@code '\u005Cu0000'}) is returned.
430.2433 +     * <p>
430.2434 +     * The {@code radix} argument is valid if it is greater than or
430.2435 +     * equal to {@code MIN_RADIX} and less than or equal to
430.2436 +     * {@code MAX_RADIX}. The {@code digit} argument is valid if
430.2437 +     * {@code 0 <= digit < radix}.
430.2438 +     * <p>
430.2439 +     * If the digit is less than 10, then
430.2440 +     * {@code '0' + digit} is returned. Otherwise, the value
430.2441 +     * {@code 'a' + digit - 10} is returned.
430.2442 +     *
430.2443 +     * @param   digit   the number to convert to a character.
430.2444 +     * @param   radix   the radix.
430.2445 +     * @return  the {@code char} representation of the specified digit
430.2446 +     *          in the specified radix.
430.2447 +     * @see     Character#MIN_RADIX
430.2448 +     * @see     Character#MAX_RADIX
430.2449 +     * @see     Character#digit(char, int)
430.2450 +     */
430.2451 +    public static char forDigit(int digit, int radix) {
430.2452 +        if ((digit >= radix) || (digit < 0)) {
430.2453 +            return '\0';
430.2454 +        }
430.2455 +        if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
430.2456 +            return '\0';
430.2457 +        }
430.2458 +        if (digit < 10) {
430.2459 +            return (char)('0' + digit);
430.2460 +        }
430.2461 +        return (char)('a' - 10 + digit);
430.2462 +    }
430.2463 +
430.2464 +    /**
430.2465 +     * Compares two {@code Character} objects numerically.
430.2466 +     *
430.2467 +     * @param   anotherCharacter   the {@code Character} to be compared.
430.2468 +
430.2469 +     * @return  the value {@code 0} if the argument {@code Character}
430.2470 +     *          is equal to this {@code Character}; a value less than
430.2471 +     *          {@code 0} if this {@code Character} is numerically less
430.2472 +     *          than the {@code Character} argument; and a value greater than
430.2473 +     *          {@code 0} if this {@code Character} is numerically greater
430.2474 +     *          than the {@code Character} argument (unsigned comparison).
430.2475 +     *          Note that this is strictly a numerical comparison; it is not
430.2476 +     *          locale-dependent.
430.2477 +     * @since   1.2
430.2478 +     */
430.2479 +    public int compareTo(Character anotherCharacter) {
430.2480 +        return compare(this.value, anotherCharacter.value);
430.2481 +    }
430.2482 +
430.2483 +    /**
430.2484 +     * Compares two {@code char} values numerically.
430.2485 +     * The value returned is identical to what would be returned by:
430.2486 +     * <pre>
430.2487 +     *    Character.valueOf(x).compareTo(Character.valueOf(y))
430.2488 +     * </pre>
430.2489 +     *
430.2490 +     * @param  x the first {@code char} to compare
430.2491 +     * @param  y the second {@code char} to compare
430.2492 +     * @return the value {@code 0} if {@code x == y};
430.2493 +     *         a value less than {@code 0} if {@code x < y}; and
430.2494 +     *         a value greater than {@code 0} if {@code x > y}
430.2495 +     * @since 1.7
430.2496 +     */
430.2497 +    public static int compare(char x, char y) {
430.2498 +        return x - y;
430.2499 +    }
430.2500 +
430.2501 +
430.2502 +    /**
430.2503 +     * The number of bits used to represent a <tt>char</tt> value in unsigned
430.2504 +     * binary form, constant {@code 16}.
430.2505 +     *
430.2506 +     * @since 1.5
430.2507 +     */
430.2508 +    public static final int SIZE = 16;
430.2509 +
430.2510 +    /**
430.2511 +     * Returns the value obtained by reversing the order of the bytes in the
430.2512 +     * specified <tt>char</tt> value.
430.2513 +     *
430.2514 +     * @return the value obtained by reversing (or, equivalently, swapping)
430.2515 +     *     the bytes in the specified <tt>char</tt> value.
430.2516 +     * @since 1.5
430.2517 +     */
430.2518 +    public static char reverseBytes(char ch) {
430.2519 +        return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
430.2520 +    }
430.2521 +
430.2522 +}
   431.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   431.2 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java	Wed Feb 27 11:24:58 2013 +0100
   431.3 @@ -0,0 +1,1390 @@
   431.4 +/*
   431.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   431.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   431.7 + *
   431.8 + * This code is free software; you can redistribute it and/or modify it
   431.9 + * under the terms of the GNU General Public License version 2 only, as
  431.10 + * published by the Free Software Foundation.  Oracle designates this
  431.11 + * particular file as subject to the "Classpath" exception as provided
  431.12 + * by Oracle in the LICENSE file that accompanied this code.
  431.13 + *
  431.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  431.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  431.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  431.17 + * version 2 for more details (a copy is included in the LICENSE file that
  431.18 + * accompanied this code).
  431.19 + *
  431.20 + * You should have received a copy of the GNU General Public License version
  431.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  431.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  431.23 + *
  431.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  431.25 + * or visit www.oracle.com if you need additional information or have any
  431.26 + * questions.
  431.27 + */
  431.28 +
  431.29 +package java.lang;
  431.30 +
  431.31 +import java.io.ByteArrayInputStream;
  431.32 +import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
  431.33 +import java.io.InputStream;
  431.34 +import java.lang.annotation.Annotation;
  431.35 +import java.lang.reflect.Field;
  431.36 +import java.lang.reflect.Method;
  431.37 +import java.lang.reflect.TypeVariable;
  431.38 +import java.net.URL;
  431.39 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  431.40 +import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
  431.41 +
  431.42 +/**
  431.43 + * Instances of the class {@code Class} represent classes and
  431.44 + * interfaces in a running Java application.  An enum is a kind of
  431.45 + * class and an annotation is a kind of interface.  Every array also
  431.46 + * belongs to a class that is reflected as a {@code Class} object
  431.47 + * that is shared by all arrays with the same element type and number
  431.48 + * of dimensions.  The primitive Java types ({@code boolean},
  431.49 + * {@code byte}, {@code char}, {@code short},
  431.50 + * {@code int}, {@code long}, {@code float}, and
  431.51 + * {@code double}), and the keyword {@code void} are also
  431.52 + * represented as {@code Class} objects.
  431.53 + *
  431.54 + * <p> {@code Class} has no public constructor. Instead {@code Class}
  431.55 + * objects are constructed automatically by the Java Virtual Machine as classes
  431.56 + * are loaded and by calls to the {@code defineClass} method in the class
  431.57 + * loader.
  431.58 + *
  431.59 + * <p> The following example uses a {@code Class} object to print the
  431.60 + * class name of an object:
  431.61 + *
  431.62 + * <p> <blockquote><pre>
  431.63 + *     void printClassName(Object obj) {
  431.64 + *         System.out.println("The class of " + obj +
  431.65 + *                            " is " + obj.getClass().getName());
  431.66 + *     }
  431.67 + * </pre></blockquote>
  431.68 + *
  431.69 + * <p> It is also possible to get the {@code Class} object for a named
  431.70 + * type (or for void) using a class literal.  See Section 15.8.2 of
  431.71 + * <cite>The Java&trade; Language Specification</cite>.
  431.72 + * For example:
  431.73 + *
  431.74 + * <p> <blockquote>
  431.75 + *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
  431.76 + * </blockquote>
  431.77 + *
  431.78 + * @param <T> the type of the class modeled by this {@code Class}
  431.79 + * object.  For example, the type of {@code String.class} is {@code
  431.80 + * Class<String>}.  Use {@code Class<?>} if the class being modeled is
  431.81 + * unknown.
  431.82 + *
  431.83 + * @author  unascribed
  431.84 + * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
  431.85 + * @since   JDK1.0
  431.86 + */
  431.87 +public final
  431.88 +    class Class<T> implements java.io.Serializable,
  431.89 +                              java.lang.reflect.GenericDeclaration,
  431.90 +                              java.lang.reflect.Type,
  431.91 +                              java.lang.reflect.AnnotatedElement {
  431.92 +    private static final int ANNOTATION= 0x00002000;
  431.93 +    private static final int ENUM      = 0x00004000;
  431.94 +    private static final int SYNTHETIC = 0x00001000;
  431.95 +
  431.96 +    /*
  431.97 +     * Constructor. Only the Java Virtual Machine creates Class
  431.98 +     * objects.
  431.99 +     */
 431.100 +    private Class() {}
 431.101 +
 431.102 +
 431.103 +    /**
 431.104 +     * Converts the object to a string. The string representation is the
 431.105 +     * string "class" or "interface", followed by a space, and then by the
 431.106 +     * fully qualified name of the class in the format returned by
 431.107 +     * {@code getName}.  If this {@code Class} object represents a
 431.108 +     * primitive type, this method returns the name of the primitive type.  If
 431.109 +     * this {@code Class} object represents void this method returns
 431.110 +     * "void".
 431.111 +     *
 431.112 +     * @return a string representation of this class object.
 431.113 +     */
 431.114 +    public String toString() {
 431.115 +        return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
 431.116 +            + getName();
 431.117 +    }
 431.118 +
 431.119 +
 431.120 +    /**
 431.121 +     * Returns the {@code Class} object associated with the class or
 431.122 +     * interface with the given string name.  Invoking this method is
 431.123 +     * equivalent to:
 431.124 +     *
 431.125 +     * <blockquote>
 431.126 +     *  {@code Class.forName(className, true, currentLoader)}
 431.127 +     * </blockquote>
 431.128 +     *
 431.129 +     * where {@code currentLoader} denotes the defining class loader of
 431.130 +     * the current class.
 431.131 +     *
 431.132 +     * <p> For example, the following code fragment returns the
 431.133 +     * runtime {@code Class} descriptor for the class named
 431.134 +     * {@code java.lang.Thread}:
 431.135 +     *
 431.136 +     * <blockquote>
 431.137 +     *   {@code Class t = Class.forName("java.lang.Thread")}
 431.138 +     * </blockquote>
 431.139 +     * <p>
 431.140 +     * A call to {@code forName("X")} causes the class named
 431.141 +     * {@code X} to be initialized.
 431.142 +     *
 431.143 +     * @param      className   the fully qualified name of the desired class.
 431.144 +     * @return     the {@code Class} object for the class with the
 431.145 +     *             specified name.
 431.146 +     * @exception LinkageError if the linkage fails
 431.147 +     * @exception ExceptionInInitializerError if the initialization provoked
 431.148 +     *            by this method fails
 431.149 +     * @exception ClassNotFoundException if the class cannot be located
 431.150 +     */
 431.151 +    public static Class<?> forName(String className)
 431.152 +    throws ClassNotFoundException {
 431.153 +        if (className.startsWith("[")) {
 431.154 +            Class<?> arrType = defineArray(className);
 431.155 +            Class<?> c = arrType;
 431.156 +            while (c != null && c.isArray()) {
 431.157 +                c = c.getComponentType0(); // verify component type is sane
 431.158 +            }
 431.159 +            return arrType;
 431.160 +        }
 431.161 +        Class<?> c = loadCls(className, className.replace('.', '_'));
 431.162 +        if (c == null) {
 431.163 +            throw new ClassNotFoundException(className);
 431.164 +        }
 431.165 +        return c;
 431.166 +    }
 431.167 +
 431.168 +
 431.169 +    /**
 431.170 +     * Returns the {@code Class} object associated with the class or
 431.171 +     * interface with the given string name, using the given class loader.
 431.172 +     * Given the fully qualified name for a class or interface (in the same
 431.173 +     * format returned by {@code getName}) this method attempts to
 431.174 +     * locate, load, and link the class or interface.  The specified class
 431.175 +     * loader is used to load the class or interface.  If the parameter
 431.176 +     * {@code loader} is null, the class is loaded through the bootstrap
 431.177 +     * class loader.  The class is initialized only if the
 431.178 +     * {@code initialize} parameter is {@code true} and if it has
 431.179 +     * not been initialized earlier.
 431.180 +     *
 431.181 +     * <p> If {@code name} denotes a primitive type or void, an attempt
 431.182 +     * will be made to locate a user-defined class in the unnamed package whose
 431.183 +     * name is {@code name}. Therefore, this method cannot be used to
 431.184 +     * obtain any of the {@code Class} objects representing primitive
 431.185 +     * types or void.
 431.186 +     *
 431.187 +     * <p> If {@code name} denotes an array class, the component type of
 431.188 +     * the array class is loaded but not initialized.
 431.189 +     *
 431.190 +     * <p> For example, in an instance method the expression:
 431.191 +     *
 431.192 +     * <blockquote>
 431.193 +     *  {@code Class.forName("Foo")}
 431.194 +     * </blockquote>
 431.195 +     *
 431.196 +     * is equivalent to:
 431.197 +     *
 431.198 +     * <blockquote>
 431.199 +     *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
 431.200 +     * </blockquote>
 431.201 +     *
 431.202 +     * Note that this method throws errors related to loading, linking or
 431.203 +     * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
 431.204 +     * Java Language Specification</em>.
 431.205 +     * Note that this method does not check whether the requested class
 431.206 +     * is accessible to its caller.
 431.207 +     *
 431.208 +     * <p> If the {@code loader} is {@code null}, and a security
 431.209 +     * manager is present, and the caller's class loader is not null, then this
 431.210 +     * method calls the security manager's {@code checkPermission} method
 431.211 +     * with a {@code RuntimePermission("getClassLoader")} permission to
 431.212 +     * ensure it's ok to access the bootstrap class loader.
 431.213 +     *
 431.214 +     * @param name       fully qualified name of the desired class
 431.215 +     * @param initialize whether the class must be initialized
 431.216 +     * @param loader     class loader from which the class must be loaded
 431.217 +     * @return           class object representing the desired class
 431.218 +     *
 431.219 +     * @exception LinkageError if the linkage fails
 431.220 +     * @exception ExceptionInInitializerError if the initialization provoked
 431.221 +     *            by this method fails
 431.222 +     * @exception ClassNotFoundException if the class cannot be located by
 431.223 +     *            the specified class loader
 431.224 +     *
 431.225 +     * @see       java.lang.Class#forName(String)
 431.226 +     * @see       java.lang.ClassLoader
 431.227 +     * @since     1.2
 431.228 +     */
 431.229 +    public static Class<?> forName(String name, boolean initialize,
 431.230 +                                   ClassLoader loader)
 431.231 +        throws ClassNotFoundException
 431.232 +    {
 431.233 +        return forName(name);
 431.234 +    }
 431.235 +    
 431.236 +    @JavaScriptBody(args = {"n", "c" }, body =
 431.237 +        "if (!vm[c]) {\n"
 431.238 +      + "  if (vm.loadClass) {\n"
 431.239 +      + "    vm.loadClass(n);\n"
 431.240 +      + "  }\n"
 431.241 +      + "  if (!vm[c]) return null;\n"
 431.242 +      + "}\n"
 431.243 +      + "vm[c](false);"
 431.244 +      + "return vm[c].$class;"
 431.245 +    )
 431.246 +    private static native Class<?> loadCls(String n, String c);
 431.247 +
 431.248 +
 431.249 +    /**
 431.250 +     * Creates a new instance of the class represented by this {@code Class}
 431.251 +     * object.  The class is instantiated as if by a {@code new}
 431.252 +     * expression with an empty argument list.  The class is initialized if it
 431.253 +     * has not already been initialized.
 431.254 +     *
 431.255 +     * <p>Note that this method propagates any exception thrown by the
 431.256 +     * nullary constructor, including a checked exception.  Use of
 431.257 +     * this method effectively bypasses the compile-time exception
 431.258 +     * checking that would otherwise be performed by the compiler.
 431.259 +     * The {@link
 431.260 +     * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
 431.261 +     * Constructor.newInstance} method avoids this problem by wrapping
 431.262 +     * any exception thrown by the constructor in a (checked) {@link
 431.263 +     * java.lang.reflect.InvocationTargetException}.
 431.264 +     *
 431.265 +     * @return     a newly allocated instance of the class represented by this
 431.266 +     *             object.
 431.267 +     * @exception  IllegalAccessException  if the class or its nullary
 431.268 +     *               constructor is not accessible.
 431.269 +     * @exception  InstantiationException
 431.270 +     *               if this {@code Class} represents an abstract class,
 431.271 +     *               an interface, an array class, a primitive type, or void;
 431.272 +     *               or if the class has no nullary constructor;
 431.273 +     *               or if the instantiation fails for some other reason.
 431.274 +     * @exception  ExceptionInInitializerError if the initialization
 431.275 +     *               provoked by this method fails.
 431.276 +     * @exception  SecurityException
 431.277 +     *             If a security manager, <i>s</i>, is present and any of the
 431.278 +     *             following conditions is met:
 431.279 +     *
 431.280 +     *             <ul>
 431.281 +     *
 431.282 +     *             <li> invocation of
 431.283 +     *             {@link SecurityManager#checkMemberAccess
 431.284 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 431.285 +     *             creation of new instances of this class
 431.286 +     *
 431.287 +     *             <li> the caller's class loader is not the same as or an
 431.288 +     *             ancestor of the class loader for the current class and
 431.289 +     *             invocation of {@link SecurityManager#checkPackageAccess
 431.290 +     *             s.checkPackageAccess()} denies access to the package
 431.291 +     *             of this class
 431.292 +     *
 431.293 +     *             </ul>
 431.294 +     *
 431.295 +     */
 431.296 +    @JavaScriptBody(args = { "self", "illegal" }, body =
 431.297 +          "\nvar c = self.cnstr;"
 431.298 +        + "\nif (c['cons__V']) {"
 431.299 +        + "\n  if ((c.cons__V.access & 0x1) != 0) {"
 431.300 +        + "\n    var inst = c();"
 431.301 +        + "\n    c.cons__V.call(inst);"
 431.302 +        + "\n    return inst;"
 431.303 +        + "\n  }"
 431.304 +        + "\n  return illegal;"
 431.305 +        + "\n}"
 431.306 +        + "\nreturn null;"
 431.307 +    )
 431.308 +    private static native Object newInstance0(Class<?> self, Object illegal);
 431.309 +    
 431.310 +    public T newInstance()
 431.311 +        throws InstantiationException, IllegalAccessException
 431.312 +    {
 431.313 +        Object illegal = new Object();
 431.314 +        Object inst = newInstance0(this, illegal);
 431.315 +        if (inst == null) {
 431.316 +            throw new InstantiationException(getName());
 431.317 +        }
 431.318 +        if (inst == illegal) {
 431.319 +            throw new IllegalAccessException();
 431.320 +        }
 431.321 +        return (T)inst;
 431.322 +    }
 431.323 +
 431.324 +    /**
 431.325 +     * Determines if the specified {@code Object} is assignment-compatible
 431.326 +     * with the object represented by this {@code Class}.  This method is
 431.327 +     * the dynamic equivalent of the Java language {@code instanceof}
 431.328 +     * operator. The method returns {@code true} if the specified
 431.329 +     * {@code Object} argument is non-null and can be cast to the
 431.330 +     * reference type represented by this {@code Class} object without
 431.331 +     * raising a {@code ClassCastException.} It returns {@code false}
 431.332 +     * otherwise.
 431.333 +     *
 431.334 +     * <p> Specifically, if this {@code Class} object represents a
 431.335 +     * declared class, this method returns {@code true} if the specified
 431.336 +     * {@code Object} argument is an instance of the represented class (or
 431.337 +     * of any of its subclasses); it returns {@code false} otherwise. If
 431.338 +     * this {@code Class} object represents an array class, this method
 431.339 +     * returns {@code true} if the specified {@code Object} argument
 431.340 +     * can be converted to an object of the array class by an identity
 431.341 +     * conversion or by a widening reference conversion; it returns
 431.342 +     * {@code false} otherwise. If this {@code Class} object
 431.343 +     * represents an interface, this method returns {@code true} if the
 431.344 +     * class or any superclass of the specified {@code Object} argument
 431.345 +     * implements this interface; it returns {@code false} otherwise. If
 431.346 +     * this {@code Class} object represents a primitive type, this method
 431.347 +     * returns {@code false}.
 431.348 +     *
 431.349 +     * @param   obj the object to check
 431.350 +     * @return  true if {@code obj} is an instance of this class
 431.351 +     *
 431.352 +     * @since JDK1.1
 431.353 +     */
 431.354 +    public boolean isInstance(Object obj) {
 431.355 +        if (obj == null) {
 431.356 +            return false;
 431.357 +        }
 431.358 +        if (isArray()) {
 431.359 +            return isAssignableFrom(obj.getClass());
 431.360 +        }
 431.361 +        
 431.362 +        String prop = "$instOf_" + getName().replace('.', '_');
 431.363 +        return hasProperty(obj, prop);
 431.364 +    }
 431.365 +    
 431.366 +    @JavaScriptBody(args = { "who", "prop" }, body = 
 431.367 +        "if (who[prop]) return true; else return false;"
 431.368 +    )
 431.369 +    private static native boolean hasProperty(Object who, String prop);
 431.370 +
 431.371 +
 431.372 +    /**
 431.373 +     * Determines if the class or interface represented by this
 431.374 +     * {@code Class} object is either the same as, or is a superclass or
 431.375 +     * superinterface of, the class or interface represented by the specified
 431.376 +     * {@code Class} parameter. It returns {@code true} if so;
 431.377 +     * otherwise it returns {@code false}. If this {@code Class}
 431.378 +     * object represents a primitive type, this method returns
 431.379 +     * {@code true} if the specified {@code Class} parameter is
 431.380 +     * exactly this {@code Class} object; otherwise it returns
 431.381 +     * {@code false}.
 431.382 +     *
 431.383 +     * <p> Specifically, this method tests whether the type represented by the
 431.384 +     * specified {@code Class} parameter can be converted to the type
 431.385 +     * represented by this {@code Class} object via an identity conversion
 431.386 +     * or via a widening reference conversion. See <em>The Java Language
 431.387 +     * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
 431.388 +     *
 431.389 +     * @param cls the {@code Class} object to be checked
 431.390 +     * @return the {@code boolean} value indicating whether objects of the
 431.391 +     * type {@code cls} can be assigned to objects of this class
 431.392 +     * @exception NullPointerException if the specified Class parameter is
 431.393 +     *            null.
 431.394 +     * @since JDK1.1
 431.395 +     */
 431.396 +    public boolean isAssignableFrom(Class<?> cls) {
 431.397 +        if (this == cls) {
 431.398 +            return true;
 431.399 +        }
 431.400 +        
 431.401 +        if (isArray()) {
 431.402 +            final Class<?> cmpType = cls.getComponentType();
 431.403 +            if (isPrimitive()) {
 431.404 +                return this == cmpType;
 431.405 +            }
 431.406 +            return cmpType != null && getComponentType().isAssignableFrom(cmpType);
 431.407 +        }
 431.408 +        String prop = "$instOf_" + getName().replace('.', '_');
 431.409 +        return hasCnstrProperty(cls, prop);
 431.410 +    }
 431.411 +
 431.412 +    @JavaScriptBody(args = { "who", "prop" }, body = 
 431.413 +        "if (who.cnstr.prototype[prop]) return true; else return false;"
 431.414 +    )
 431.415 +    private static native boolean hasCnstrProperty(Object who, String prop);
 431.416 +    
 431.417 +    
 431.418 +    /**
 431.419 +     * Determines if the specified {@code Class} object represents an
 431.420 +     * interface type.
 431.421 +     *
 431.422 +     * @return  {@code true} if this object represents an interface;
 431.423 +     *          {@code false} otherwise.
 431.424 +     */
 431.425 +    public boolean isInterface() {
 431.426 +        return (getAccess() & 0x200) != 0;
 431.427 +    }
 431.428 +    
 431.429 +    @JavaScriptBody(args = {}, body = "return this.access;")
 431.430 +    private native int getAccess();
 431.431 +
 431.432 +
 431.433 +    /**
 431.434 +     * Determines if this {@code Class} object represents an array class.
 431.435 +     *
 431.436 +     * @return  {@code true} if this object represents an array class;
 431.437 +     *          {@code false} otherwise.
 431.438 +     * @since   JDK1.1
 431.439 +     */
 431.440 +    public boolean isArray() {
 431.441 +        return hasProperty(this, "array"); // NOI18N
 431.442 +    }
 431.443 +
 431.444 +
 431.445 +    /**
 431.446 +     * Determines if the specified {@code Class} object represents a
 431.447 +     * primitive type.
 431.448 +     *
 431.449 +     * <p> There are nine predefined {@code Class} objects to represent
 431.450 +     * the eight primitive types and void.  These are created by the Java
 431.451 +     * Virtual Machine, and have the same names as the primitive types that
 431.452 +     * they represent, namely {@code boolean}, {@code byte},
 431.453 +     * {@code char}, {@code short}, {@code int},
 431.454 +     * {@code long}, {@code float}, and {@code double}.
 431.455 +     *
 431.456 +     * <p> These objects may only be accessed via the following public static
 431.457 +     * final variables, and are the only {@code Class} objects for which
 431.458 +     * this method returns {@code true}.
 431.459 +     *
 431.460 +     * @return true if and only if this class represents a primitive type
 431.461 +     *
 431.462 +     * @see     java.lang.Boolean#TYPE
 431.463 +     * @see     java.lang.Character#TYPE
 431.464 +     * @see     java.lang.Byte#TYPE
 431.465 +     * @see     java.lang.Short#TYPE
 431.466 +     * @see     java.lang.Integer#TYPE
 431.467 +     * @see     java.lang.Long#TYPE
 431.468 +     * @see     java.lang.Float#TYPE
 431.469 +     * @see     java.lang.Double#TYPE
 431.470 +     * @see     java.lang.Void#TYPE
 431.471 +     * @since JDK1.1
 431.472 +     */
 431.473 +    @JavaScriptBody(args = {}, body = 
 431.474 +           "if (this.primitive) return true;"
 431.475 +        + "else return false;"
 431.476 +    )
 431.477 +    public native boolean isPrimitive();
 431.478 +
 431.479 +    /**
 431.480 +     * Returns true if this {@code Class} object represents an annotation
 431.481 +     * type.  Note that if this method returns true, {@link #isInterface()}
 431.482 +     * would also return true, as all annotation types are also interfaces.
 431.483 +     *
 431.484 +     * @return {@code true} if this class object represents an annotation
 431.485 +     *      type; {@code false} otherwise
 431.486 +     * @since 1.5
 431.487 +     */
 431.488 +    public boolean isAnnotation() {
 431.489 +        return (getModifiers() & ANNOTATION) != 0;
 431.490 +    }
 431.491 +
 431.492 +    /**
 431.493 +     * Returns {@code true} if this class is a synthetic class;
 431.494 +     * returns {@code false} otherwise.
 431.495 +     * @return {@code true} if and only if this class is a synthetic class as
 431.496 +     *         defined by the Java Language Specification.
 431.497 +     * @since 1.5
 431.498 +     */
 431.499 +    public boolean isSynthetic() {
 431.500 +        return (getModifiers() & SYNTHETIC) != 0;
 431.501 +    }
 431.502 +
 431.503 +    /**
 431.504 +     * Returns the  name of the entity (class, interface, array class,
 431.505 +     * primitive type, or void) represented by this {@code Class} object,
 431.506 +     * as a {@code String}.
 431.507 +     *
 431.508 +     * <p> If this class object represents a reference type that is not an
 431.509 +     * array type then the binary name of the class is returned, as specified
 431.510 +     * by
 431.511 +     * <cite>The Java&trade; Language Specification</cite>.
 431.512 +     *
 431.513 +     * <p> If this class object represents a primitive type or void, then the
 431.514 +     * name returned is a {@code String} equal to the Java language
 431.515 +     * keyword corresponding to the primitive type or void.
 431.516 +     *
 431.517 +     * <p> If this class object represents a class of arrays, then the internal
 431.518 +     * form of the name consists of the name of the element type preceded by
 431.519 +     * one or more '{@code [}' characters representing the depth of the array
 431.520 +     * nesting.  The encoding of element type names is as follows:
 431.521 +     *
 431.522 +     * <blockquote><table summary="Element types and encodings">
 431.523 +     * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
 431.524 +     * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
 431.525 +     * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
 431.526 +     * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
 431.527 +     * <tr><td> class or interface
 431.528 +     *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
 431.529 +     * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
 431.530 +     * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
 431.531 +     * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
 431.532 +     * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
 431.533 +     * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
 431.534 +     * </table></blockquote>
 431.535 +     *
 431.536 +     * <p> The class or interface name <i>classname</i> is the binary name of
 431.537 +     * the class specified above.
 431.538 +     *
 431.539 +     * <p> Examples:
 431.540 +     * <blockquote><pre>
 431.541 +     * String.class.getName()
 431.542 +     *     returns "java.lang.String"
 431.543 +     * byte.class.getName()
 431.544 +     *     returns "byte"
 431.545 +     * (new Object[3]).getClass().getName()
 431.546 +     *     returns "[Ljava.lang.Object;"
 431.547 +     * (new int[3][4][5][6][7][8][9]).getClass().getName()
 431.548 +     *     returns "[[[[[[[I"
 431.549 +     * </pre></blockquote>
 431.550 +     *
 431.551 +     * @return  the name of the class or interface
 431.552 +     *          represented by this object.
 431.553 +     */
 431.554 +    public String getName() {
 431.555 +        return jvmName().replace('/', '.');
 431.556 +    }
 431.557 +
 431.558 +    @JavaScriptBody(args = {}, body = "return this.jvmName;")
 431.559 +    private native String jvmName();
 431.560 +
 431.561 +    
 431.562 +    /**
 431.563 +     * Returns an array of {@code TypeVariable} objects that represent the
 431.564 +     * type variables declared by the generic declaration represented by this
 431.565 +     * {@code GenericDeclaration} object, in declaration order.  Returns an
 431.566 +     * array of length 0 if the underlying generic declaration declares no type
 431.567 +     * variables.
 431.568 +     *
 431.569 +     * @return an array of {@code TypeVariable} objects that represent
 431.570 +     *     the type variables declared by this generic declaration
 431.571 +     * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 431.572 +     *     signature of this generic declaration does not conform to
 431.573 +     *     the format specified in
 431.574 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 431.575 +     * @since 1.5
 431.576 +     */
 431.577 +    public TypeVariable<Class<T>>[] getTypeParameters() {
 431.578 +        throw new UnsupportedOperationException();
 431.579 +    }
 431.580 + 
 431.581 +    /**
 431.582 +     * Returns the {@code Class} representing the superclass of the entity
 431.583 +     * (class, interface, primitive type or void) represented by this
 431.584 +     * {@code Class}.  If this {@code Class} represents either the
 431.585 +     * {@code Object} class, an interface, a primitive type, or void, then
 431.586 +     * null is returned.  If this object represents an array class then the
 431.587 +     * {@code Class} object representing the {@code Object} class is
 431.588 +     * returned.
 431.589 +     *
 431.590 +     * @return the superclass of the class represented by this object.
 431.591 +     */
 431.592 +    @JavaScriptBody(args = {}, body = "return this.superclass;")
 431.593 +    public native Class<? super T> getSuperclass();
 431.594 +
 431.595 +    /**
 431.596 +     * Returns the Java language modifiers for this class or interface, encoded
 431.597 +     * in an integer. The modifiers consist of the Java Virtual Machine's
 431.598 +     * constants for {@code public}, {@code protected},
 431.599 +     * {@code private}, {@code final}, {@code static},
 431.600 +     * {@code abstract} and {@code interface}; they should be decoded
 431.601 +     * using the methods of class {@code Modifier}.
 431.602 +     *
 431.603 +     * <p> If the underlying class is an array class, then its
 431.604 +     * {@code public}, {@code private} and {@code protected}
 431.605 +     * modifiers are the same as those of its component type.  If this
 431.606 +     * {@code Class} represents a primitive type or void, its
 431.607 +     * {@code public} modifier is always {@code true}, and its
 431.608 +     * {@code protected} and {@code private} modifiers are always
 431.609 +     * {@code false}. If this object represents an array class, a
 431.610 +     * primitive type or void, then its {@code final} modifier is always
 431.611 +     * {@code true} and its interface modifier is always
 431.612 +     * {@code false}. The values of its other modifiers are not determined
 431.613 +     * by this specification.
 431.614 +     *
 431.615 +     * <p> The modifier encodings are defined in <em>The Java Virtual Machine
 431.616 +     * Specification</em>, table 4.1.
 431.617 +     *
 431.618 +     * @return the {@code int} representing the modifiers for this class
 431.619 +     * @see     java.lang.reflect.Modifier
 431.620 +     * @since JDK1.1
 431.621 +     */
 431.622 +    public int getModifiers() {
 431.623 +        return getAccess();
 431.624 +    }
 431.625 +
 431.626 +
 431.627 +    /**
 431.628 +     * Returns the simple name of the underlying class as given in the
 431.629 +     * source code. Returns an empty string if the underlying class is
 431.630 +     * anonymous.
 431.631 +     *
 431.632 +     * <p>The simple name of an array is the simple name of the
 431.633 +     * component type with "[]" appended.  In particular the simple
 431.634 +     * name of an array whose component type is anonymous is "[]".
 431.635 +     *
 431.636 +     * @return the simple name of the underlying class
 431.637 +     * @since 1.5
 431.638 +     */
 431.639 +    public String getSimpleName() {
 431.640 +        if (isArray())
 431.641 +            return getComponentType().getSimpleName()+"[]";
 431.642 +
 431.643 +        String simpleName = getSimpleBinaryName();
 431.644 +        if (simpleName == null) { // top level class
 431.645 +            simpleName = getName();
 431.646 +            return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
 431.647 +        }
 431.648 +        // According to JLS3 "Binary Compatibility" (13.1) the binary
 431.649 +        // name of non-package classes (not top level) is the binary
 431.650 +        // name of the immediately enclosing class followed by a '$' followed by:
 431.651 +        // (for nested and inner classes): the simple name.
 431.652 +        // (for local classes): 1 or more digits followed by the simple name.
 431.653 +        // (for anonymous classes): 1 or more digits.
 431.654 +
 431.655 +        // Since getSimpleBinaryName() will strip the binary name of
 431.656 +        // the immediatly enclosing class, we are now looking at a
 431.657 +        // string that matches the regular expression "\$[0-9]*"
 431.658 +        // followed by a simple name (considering the simple of an
 431.659 +        // anonymous class to be the empty string).
 431.660 +
 431.661 +        // Remove leading "\$[0-9]*" from the name
 431.662 +        int length = simpleName.length();
 431.663 +        if (length < 1 || simpleName.charAt(0) != '$')
 431.664 +            throw new IllegalStateException("Malformed class name");
 431.665 +        int index = 1;
 431.666 +        while (index < length && isAsciiDigit(simpleName.charAt(index)))
 431.667 +            index++;
 431.668 +        // Eventually, this is the empty string iff this is an anonymous class
 431.669 +        return simpleName.substring(index);
 431.670 +    }
 431.671 +
 431.672 +    /**
 431.673 +     * Returns the "simple binary name" of the underlying class, i.e.,
 431.674 +     * the binary name without the leading enclosing class name.
 431.675 +     * Returns {@code null} if the underlying class is a top level
 431.676 +     * class.
 431.677 +     */
 431.678 +    private String getSimpleBinaryName() {
 431.679 +        Class<?> enclosingClass = null; // XXX getEnclosingClass();
 431.680 +        if (enclosingClass == null) // top level class
 431.681 +            return null;
 431.682 +        // Otherwise, strip the enclosing class' name
 431.683 +        try {
 431.684 +            return getName().substring(enclosingClass.getName().length());
 431.685 +        } catch (IndexOutOfBoundsException ex) {
 431.686 +            throw new IllegalStateException("Malformed class name");
 431.687 +        }
 431.688 +    }
 431.689 +
 431.690 +    /**
 431.691 +     * Returns an array containing {@code Field} objects reflecting all
 431.692 +     * the accessible public fields of the class or interface represented by
 431.693 +     * this {@code Class} object.  The elements in the array returned are
 431.694 +     * not sorted and are not in any particular order.  This method returns an
 431.695 +     * array of length 0 if the class or interface has no accessible public
 431.696 +     * fields, or if it represents an array class, a primitive type, or void.
 431.697 +     *
 431.698 +     * <p> Specifically, if this {@code Class} object represents a class,
 431.699 +     * this method returns the public fields of this class and of all its
 431.700 +     * superclasses.  If this {@code Class} object represents an
 431.701 +     * interface, this method returns the fields of this interface and of all
 431.702 +     * its superinterfaces.
 431.703 +     *
 431.704 +     * <p> The implicit length field for array class is not reflected by this
 431.705 +     * method. User code should use the methods of class {@code Array} to
 431.706 +     * manipulate arrays.
 431.707 +     *
 431.708 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 431.709 +     *
 431.710 +     * @return the array of {@code Field} objects representing the
 431.711 +     * public fields
 431.712 +     * @exception  SecurityException
 431.713 +     *             If a security manager, <i>s</i>, is present and any of the
 431.714 +     *             following conditions is met:
 431.715 +     *
 431.716 +     *             <ul>
 431.717 +     *
 431.718 +     *             <li> invocation of
 431.719 +     *             {@link SecurityManager#checkMemberAccess
 431.720 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 431.721 +     *             access to the fields within this class
 431.722 +     *
 431.723 +     *             <li> the caller's class loader is not the same as or an
 431.724 +     *             ancestor of the class loader for the current class and
 431.725 +     *             invocation of {@link SecurityManager#checkPackageAccess
 431.726 +     *             s.checkPackageAccess()} denies access to the package
 431.727 +     *             of this class
 431.728 +     *
 431.729 +     *             </ul>
 431.730 +     *
 431.731 +     * @since JDK1.1
 431.732 +     */
 431.733 +    public Field[] getFields() throws SecurityException {
 431.734 +        throw new SecurityException();
 431.735 +    }
 431.736 +
 431.737 +    /**
 431.738 +     * Returns an array containing {@code Method} objects reflecting all
 431.739 +     * the public <em>member</em> methods of the class or interface represented
 431.740 +     * by this {@code Class} object, including those declared by the class
 431.741 +     * or interface and those inherited from superclasses and
 431.742 +     * superinterfaces.  Array classes return all the (public) member methods
 431.743 +     * inherited from the {@code Object} class.  The elements in the array
 431.744 +     * returned are not sorted and are not in any particular order.  This
 431.745 +     * method returns an array of length 0 if this {@code Class} object
 431.746 +     * represents a class or interface that has no public member methods, or if
 431.747 +     * this {@code Class} object represents a primitive type or void.
 431.748 +     *
 431.749 +     * <p> The class initialization method {@code <clinit>} is not
 431.750 +     * included in the returned array. If the class declares multiple public
 431.751 +     * member methods with the same parameter types, they are all included in
 431.752 +     * the returned array.
 431.753 +     *
 431.754 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 431.755 +     *
 431.756 +     * @return the array of {@code Method} objects representing the
 431.757 +     * public methods of this class
 431.758 +     * @exception  SecurityException
 431.759 +     *             If a security manager, <i>s</i>, is present and any of the
 431.760 +     *             following conditions is met:
 431.761 +     *
 431.762 +     *             <ul>
 431.763 +     *
 431.764 +     *             <li> invocation of
 431.765 +     *             {@link SecurityManager#checkMemberAccess
 431.766 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 431.767 +     *             access to the methods within this class
 431.768 +     *
 431.769 +     *             <li> the caller's class loader is not the same as or an
 431.770 +     *             ancestor of the class loader for the current class and
 431.771 +     *             invocation of {@link SecurityManager#checkPackageAccess
 431.772 +     *             s.checkPackageAccess()} denies access to the package
 431.773 +     *             of this class
 431.774 +     *
 431.775 +     *             </ul>
 431.776 +     *
 431.777 +     * @since JDK1.1
 431.778 +     */
 431.779 +    public Method[] getMethods() throws SecurityException {
 431.780 +        return MethodImpl.findMethods(this, 0x01);
 431.781 +    }
 431.782 +
 431.783 +    /**
 431.784 +     * Returns a {@code Field} object that reflects the specified public
 431.785 +     * member field of the class or interface represented by this
 431.786 +     * {@code Class} object. The {@code name} parameter is a
 431.787 +     * {@code String} specifying the simple name of the desired field.
 431.788 +     *
 431.789 +     * <p> The field to be reflected is determined by the algorithm that
 431.790 +     * follows.  Let C be the class represented by this object:
 431.791 +     * <OL>
 431.792 +     * <LI> If C declares a public field with the name specified, that is the
 431.793 +     *      field to be reflected.</LI>
 431.794 +     * <LI> If no field was found in step 1 above, this algorithm is applied
 431.795 +     *      recursively to each direct superinterface of C. The direct
 431.796 +     *      superinterfaces are searched in the order they were declared.</LI>
 431.797 +     * <LI> If no field was found in steps 1 and 2 above, and C has a
 431.798 +     *      superclass S, then this algorithm is invoked recursively upon S.
 431.799 +     *      If C has no superclass, then a {@code NoSuchFieldException}
 431.800 +     *      is thrown.</LI>
 431.801 +     * </OL>
 431.802 +     *
 431.803 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
 431.804 +     *
 431.805 +     * @param name the field name
 431.806 +     * @return  the {@code Field} object of this class specified by
 431.807 +     * {@code name}
 431.808 +     * @exception NoSuchFieldException if a field with the specified name is
 431.809 +     *              not found.
 431.810 +     * @exception NullPointerException if {@code name} is {@code null}
 431.811 +     * @exception  SecurityException
 431.812 +     *             If a security manager, <i>s</i>, is present and any of the
 431.813 +     *             following conditions is met:
 431.814 +     *
 431.815 +     *             <ul>
 431.816 +     *
 431.817 +     *             <li> invocation of
 431.818 +     *             {@link SecurityManager#checkMemberAccess
 431.819 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 431.820 +     *             access to the field
 431.821 +     *
 431.822 +     *             <li> the caller's class loader is not the same as or an
 431.823 +     *             ancestor of the class loader for the current class and
 431.824 +     *             invocation of {@link SecurityManager#checkPackageAccess
 431.825 +     *             s.checkPackageAccess()} denies access to the package
 431.826 +     *             of this class
 431.827 +     *
 431.828 +     *             </ul>
 431.829 +     *
 431.830 +     * @since JDK1.1
 431.831 +     */
 431.832 +    public Field getField(String name)
 431.833 +        throws SecurityException {
 431.834 +        throw new SecurityException();
 431.835 +    }
 431.836 +    
 431.837 +    
 431.838 +    /**
 431.839 +     * Returns a {@code Method} object that reflects the specified public
 431.840 +     * member method of the class or interface represented by this
 431.841 +     * {@code Class} object. The {@code name} parameter is a
 431.842 +     * {@code String} specifying the simple name of the desired method. The
 431.843 +     * {@code parameterTypes} parameter is an array of {@code Class}
 431.844 +     * objects that identify the method's formal parameter types, in declared
 431.845 +     * order. If {@code parameterTypes} is {@code null}, it is
 431.846 +     * treated as if it were an empty array.
 431.847 +     *
 431.848 +     * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
 431.849 +     * {@code NoSuchMethodException} is raised. Otherwise, the method to
 431.850 +     * be reflected is determined by the algorithm that follows.  Let C be the
 431.851 +     * class represented by this object:
 431.852 +     * <OL>
 431.853 +     * <LI> C is searched for any <I>matching methods</I>. If no matching
 431.854 +     *      method is found, the algorithm of step 1 is invoked recursively on
 431.855 +     *      the superclass of C.</LI>
 431.856 +     * <LI> If no method was found in step 1 above, the superinterfaces of C
 431.857 +     *      are searched for a matching method. If any such method is found, it
 431.858 +     *      is reflected.</LI>
 431.859 +     * </OL>
 431.860 +     *
 431.861 +     * To find a matching method in a class C:&nbsp; If C declares exactly one
 431.862 +     * public method with the specified name and exactly the same formal
 431.863 +     * parameter types, that is the method reflected. If more than one such
 431.864 +     * method is found in C, and one of these methods has a return type that is
 431.865 +     * more specific than any of the others, that method is reflected;
 431.866 +     * otherwise one of the methods is chosen arbitrarily.
 431.867 +     *
 431.868 +     * <p>Note that there may be more than one matching method in a
 431.869 +     * class because while the Java language forbids a class to
 431.870 +     * declare multiple methods with the same signature but different
 431.871 +     * return types, the Java virtual machine does not.  This
 431.872 +     * increased flexibility in the virtual machine can be used to
 431.873 +     * implement various language features.  For example, covariant
 431.874 +     * returns can be implemented with {@linkplain
 431.875 +     * java.lang.reflect.Method#isBridge bridge methods}; the bridge
 431.876 +     * method and the method being overridden would have the same
 431.877 +     * signature but different return types.
 431.878 +     *
 431.879 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
 431.880 +     *
 431.881 +     * @param name the name of the method
 431.882 +     * @param parameterTypes the list of parameters
 431.883 +     * @return the {@code Method} object that matches the specified
 431.884 +     * {@code name} and {@code parameterTypes}
 431.885 +     * @exception NoSuchMethodException if a matching method is not found
 431.886 +     *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
 431.887 +     * @exception NullPointerException if {@code name} is {@code null}
 431.888 +     * @exception  SecurityException
 431.889 +     *             If a security manager, <i>s</i>, is present and any of the
 431.890 +     *             following conditions is met:
 431.891 +     *
 431.892 +     *             <ul>
 431.893 +     *
 431.894 +     *             <li> invocation of
 431.895 +     *             {@link SecurityManager#checkMemberAccess
 431.896 +     *             s.checkMemberAccess(this, Member.PUBLIC)} denies
 431.897 +     *             access to the method
 431.898 +     *
 431.899 +     *             <li> the caller's class loader is not the same as or an
 431.900 +     *             ancestor of the class loader for the current class and
 431.901 +     *             invocation of {@link SecurityManager#checkPackageAccess
 431.902 +     *             s.checkPackageAccess()} denies access to the package
 431.903 +     *             of this class
 431.904 +     *
 431.905 +     *             </ul>
 431.906 +     *
 431.907 +     * @since JDK1.1
 431.908 +     */
 431.909 +    public Method getMethod(String name, Class<?>... parameterTypes)
 431.910 +        throws SecurityException, NoSuchMethodException {
 431.911 +        Method m = MethodImpl.findMethod(this, name, parameterTypes);
 431.912 +        if (m == null) {
 431.913 +            StringBuilder sb = new StringBuilder();
 431.914 +            sb.append(getName()).append('.').append(name).append('(');
 431.915 +            String sep = "";
 431.916 +            for (int i = 0; i < parameterTypes.length; i++) {
 431.917 +                sb.append(sep).append(parameterTypes[i].getName());
 431.918 +                sep = ", ";
 431.919 +            }
 431.920 +            sb.append(')');
 431.921 +            throw new NoSuchMethodException(sb.toString());
 431.922 +        }
 431.923 +        return m;
 431.924 +    }
 431.925 +    
 431.926 +    /**
 431.927 +     * Returns an array of {@code Method} objects reflecting all the
 431.928 +     * methods declared by the class or interface represented by this
 431.929 +     * {@code Class} object. This includes public, protected, default
 431.930 +     * (package) access, and private methods, but excludes inherited methods.
 431.931 +     * The elements in the array returned are not sorted and are not in any
 431.932 +     * particular order.  This method returns an array of length 0 if the class
 431.933 +     * or interface declares no methods, or if this {@code Class} object
 431.934 +     * represents a primitive type, an array class, or void.  The class
 431.935 +     * initialization method {@code <clinit>} is not included in the
 431.936 +     * returned array. If the class declares multiple public member methods
 431.937 +     * with the same parameter types, they are all included in the returned
 431.938 +     * array.
 431.939 +     *
 431.940 +     * <p> See <em>The Java Language Specification</em>, section 8.2.
 431.941 +     *
 431.942 +     * @return    the array of {@code Method} objects representing all the
 431.943 +     * declared methods of this class
 431.944 +     * @exception  SecurityException
 431.945 +     *             If a security manager, <i>s</i>, is present and any of the
 431.946 +     *             following conditions is met:
 431.947 +     *
 431.948 +     *             <ul>
 431.949 +     *
 431.950 +     *             <li> invocation of
 431.951 +     *             {@link SecurityManager#checkMemberAccess
 431.952 +     *             s.checkMemberAccess(this, Member.DECLARED)} denies
 431.953 +     *             access to the declared methods within this class
 431.954 +     *
 431.955 +     *             <li> the caller's class loader is not the same as or an
 431.956 +     *             ancestor of the class loader for the current class and
 431.957 +     *             invocation of {@link SecurityManager#checkPackageAccess
 431.958 +     *             s.checkPackageAccess()} denies access to the package
 431.959 +     *             of this class
 431.960 +     *
 431.961 +     *             </ul>
 431.962 +     *
 431.963 +     * @since JDK1.1
 431.964 +     */
 431.965 +    public Method[] getDeclaredMethods() throws SecurityException {
 431.966 +        throw new SecurityException();
 431.967 +    }
 431.968 +    
 431.969 +    /**
 431.970 +     * Character.isDigit answers {@code true} to some non-ascii
 431.971 +     * digits.  This one does not.
 431.972 +     */
 431.973 +    private static boolean isAsciiDigit(char c) {
 431.974 +        return '0' <= c && c <= '9';
 431.975 +    }
 431.976 +
 431.977 +    /**
 431.978 +     * Returns the canonical name of the underlying class as
 431.979 +     * defined by the Java Language Specification.  Returns null if
 431.980 +     * the underlying class does not have a canonical name (i.e., if
 431.981 +     * it is a local or anonymous class or an array whose component
 431.982 +     * type does not have a canonical name).
 431.983 +     * @return the canonical name of the underlying class if it exists, and
 431.984 +     * {@code null} otherwise.
 431.985 +     * @since 1.5
 431.986 +     */
 431.987 +    public String getCanonicalName() {
 431.988 +        if (isArray()) {
 431.989 +            String canonicalName = getComponentType().getCanonicalName();
 431.990 +            if (canonicalName != null)
 431.991 +                return canonicalName + "[]";
 431.992 +            else
 431.993 +                return null;
 431.994 +        }
 431.995 +//        if (isLocalOrAnonymousClass())
 431.996 +//            return null;
 431.997 +//        Class<?> enclosingClass = getEnclosingClass();
 431.998 +        Class<?> enclosingClass = null;
 431.999 +        if (enclosingClass == null) { // top level class
431.1000 +            return getName();
431.1001 +        } else {
431.1002 +            String enclosingName = enclosingClass.getCanonicalName();
431.1003 +            if (enclosingName == null)
431.1004 +                return null;
431.1005 +            return enclosingName + "." + getSimpleName();
431.1006 +        }
431.1007 +    }
431.1008 +
431.1009 +    /**
431.1010 +     * Finds a resource with a given name.  The rules for searching resources
431.1011 +     * associated with a given class are implemented by the defining
431.1012 +     * {@linkplain ClassLoader class loader} of the class.  This method
431.1013 +     * delegates to this object's class loader.  If this object was loaded by
431.1014 +     * the bootstrap class loader, the method delegates to {@link
431.1015 +     * ClassLoader#getSystemResourceAsStream}.
431.1016 +     *
431.1017 +     * <p> Before delegation, an absolute resource name is constructed from the
431.1018 +     * given resource name using this algorithm:
431.1019 +     *
431.1020 +     * <ul>
431.1021 +     *
431.1022 +     * <li> If the {@code name} begins with a {@code '/'}
431.1023 +     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
431.1024 +     * portion of the {@code name} following the {@code '/'}.
431.1025 +     *
431.1026 +     * <li> Otherwise, the absolute name is of the following form:
431.1027 +     *
431.1028 +     * <blockquote>
431.1029 +     *   {@code modified_package_name/name}
431.1030 +     * </blockquote>
431.1031 +     *
431.1032 +     * <p> Where the {@code modified_package_name} is the package name of this
431.1033 +     * object with {@code '/'} substituted for {@code '.'}
431.1034 +     * (<tt>'&#92;u002e'</tt>).
431.1035 +     *
431.1036 +     * </ul>
431.1037 +     *
431.1038 +     * @param  name name of the desired resource
431.1039 +     * @return      A {@link java.io.InputStream} object or {@code null} if
431.1040 +     *              no resource with this name is found
431.1041 +     * @throws  NullPointerException If {@code name} is {@code null}
431.1042 +     * @since  JDK1.1
431.1043 +     */
431.1044 +     public InputStream getResourceAsStream(String name) {
431.1045 +        name = resolveName(name);
431.1046 +        byte[] arr = getResourceAsStream0(name);
431.1047 +        return arr == null ? null : new ByteArrayInputStream(arr);
431.1048 +     }
431.1049 +     
431.1050 +     @JavaScriptBody(args = "name", body = 
431.1051 +         "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
431.1052 +     )
431.1053 +     private static native byte[] getResourceAsStream0(String name);
431.1054 +
431.1055 +    /**
431.1056 +     * Finds a resource with a given name.  The rules for searching resources
431.1057 +     * associated with a given class are implemented by the defining
431.1058 +     * {@linkplain ClassLoader class loader} of the class.  This method
431.1059 +     * delegates to this object's class loader.  If this object was loaded by
431.1060 +     * the bootstrap class loader, the method delegates to {@link
431.1061 +     * ClassLoader#getSystemResource}.
431.1062 +     *
431.1063 +     * <p> Before delegation, an absolute resource name is constructed from the
431.1064 +     * given resource name using this algorithm:
431.1065 +     *
431.1066 +     * <ul>
431.1067 +     *
431.1068 +     * <li> If the {@code name} begins with a {@code '/'}
431.1069 +     * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
431.1070 +     * portion of the {@code name} following the {@code '/'}.
431.1071 +     *
431.1072 +     * <li> Otherwise, the absolute name is of the following form:
431.1073 +     *
431.1074 +     * <blockquote>
431.1075 +     *   {@code modified_package_name/name}
431.1076 +     * </blockquote>
431.1077 +     *
431.1078 +     * <p> Where the {@code modified_package_name} is the package name of this
431.1079 +     * object with {@code '/'} substituted for {@code '.'}
431.1080 +     * (<tt>'&#92;u002e'</tt>).
431.1081 +     *
431.1082 +     * </ul>
431.1083 +     *
431.1084 +     * @param  name name of the desired resource
431.1085 +     * @return      A  {@link java.net.URL} object or {@code null} if no
431.1086 +     *              resource with this name is found
431.1087 +     * @since  JDK1.1
431.1088 +     */
431.1089 +    public java.net.URL getResource(String name) {
431.1090 +        InputStream is = getResourceAsStream(name);
431.1091 +        return is == null ? null : newResourceURL(URL.class, "res:/" + name, is);
431.1092 +    }
431.1093 +    
431.1094 +    @JavaScriptBody(args = { "url", "spec", "is" }, body = 
431.1095 +        "var u = url.cnstr(true);\n"
431.1096 +      + "u.constructor.cons__VLjava_lang_String_2Ljava_io_InputStream_2.call(u, spec, is);\n"
431.1097 +      + "return u;"
431.1098 +    )
431.1099 +    private static native URL newResourceURL(Class<URL> url, String spec, InputStream is);
431.1100 +
431.1101 +   /**
431.1102 +     * Add a package name prefix if the name is not absolute Remove leading "/"
431.1103 +     * if name is absolute
431.1104 +     */
431.1105 +    private String resolveName(String name) {
431.1106 +        if (name == null) {
431.1107 +            return name;
431.1108 +        }
431.1109 +        if (!name.startsWith("/")) {
431.1110 +            Class<?> c = this;
431.1111 +            while (c.isArray()) {
431.1112 +                c = c.getComponentType();
431.1113 +            }
431.1114 +            String baseName = c.getName();
431.1115 +            int index = baseName.lastIndexOf('.');
431.1116 +            if (index != -1) {
431.1117 +                name = baseName.substring(0, index).replace('.', '/')
431.1118 +                    +"/"+name;
431.1119 +            }
431.1120 +        } else {
431.1121 +            name = name.substring(1);
431.1122 +        }
431.1123 +        return name;
431.1124 +    }
431.1125 +    
431.1126 +    /**
431.1127 +     * Returns the class loader for the class.  Some implementations may use
431.1128 +     * null to represent the bootstrap class loader. This method will return
431.1129 +     * null in such implementations if this class was loaded by the bootstrap
431.1130 +     * class loader.
431.1131 +     *
431.1132 +     * <p> If a security manager is present, and the caller's class loader is
431.1133 +     * not null and the caller's class loader is not the same as or an ancestor of
431.1134 +     * the class loader for the class whose class loader is requested, then
431.1135 +     * this method calls the security manager's {@code checkPermission}
431.1136 +     * method with a {@code RuntimePermission("getClassLoader")}
431.1137 +     * permission to ensure it's ok to access the class loader for the class.
431.1138 +     *
431.1139 +     * <p>If this object
431.1140 +     * represents a primitive type or void, null is returned.
431.1141 +     *
431.1142 +     * @return  the class loader that loaded the class or interface
431.1143 +     *          represented by this object.
431.1144 +     * @throws SecurityException
431.1145 +     *    if a security manager exists and its
431.1146 +     *    {@code checkPermission} method denies
431.1147 +     *    access to the class loader for the class.
431.1148 +     * @see java.lang.ClassLoader
431.1149 +     * @see SecurityManager#checkPermission
431.1150 +     * @see java.lang.RuntimePermission
431.1151 +     */
431.1152 +    public ClassLoader getClassLoader() {
431.1153 +        throw new SecurityException();
431.1154 +    }
431.1155 +
431.1156 +    /**
431.1157 +     * Determines the interfaces implemented by the class or interface
431.1158 +     * represented by this object.
431.1159 +     *
431.1160 +     * <p> If this object represents a class, the return value is an array
431.1161 +     * containing objects representing all interfaces implemented by the
431.1162 +     * class. The order of the interface objects in the array corresponds to
431.1163 +     * the order of the interface names in the {@code implements} clause
431.1164 +     * of the declaration of the class represented by this object. For
431.1165 +     * example, given the declaration:
431.1166 +     * <blockquote>
431.1167 +     * {@code class Shimmer implements FloorWax, DessertTopping { ... }}
431.1168 +     * </blockquote>
431.1169 +     * suppose the value of {@code s} is an instance of
431.1170 +     * {@code Shimmer}; the value of the expression:
431.1171 +     * <blockquote>
431.1172 +     * {@code s.getClass().getInterfaces()[0]}
431.1173 +     * </blockquote>
431.1174 +     * is the {@code Class} object that represents interface
431.1175 +     * {@code FloorWax}; and the value of:
431.1176 +     * <blockquote>
431.1177 +     * {@code s.getClass().getInterfaces()[1]}
431.1178 +     * </blockquote>
431.1179 +     * is the {@code Class} object that represents interface
431.1180 +     * {@code DessertTopping}.
431.1181 +     *
431.1182 +     * <p> If this object represents an interface, the array contains objects
431.1183 +     * representing all interfaces extended by the interface. The order of the
431.1184 +     * interface objects in the array corresponds to the order of the interface
431.1185 +     * names in the {@code extends} clause of the declaration of the
431.1186 +     * interface represented by this object.
431.1187 +     *
431.1188 +     * <p> If this object represents a class or interface that implements no
431.1189 +     * interfaces, the method returns an array of length 0.
431.1190 +     *
431.1191 +     * <p> If this object represents a primitive type or void, the method
431.1192 +     * returns an array of length 0.
431.1193 +     *
431.1194 +     * @return an array of interfaces implemented by this class.
431.1195 +     */
431.1196 +    public native Class<?>[] getInterfaces();
431.1197 +    
431.1198 +    /**
431.1199 +     * Returns the {@code Class} representing the component type of an
431.1200 +     * array.  If this class does not represent an array class this method
431.1201 +     * returns null.
431.1202 +     *
431.1203 +     * @return the {@code Class} representing the component type of this
431.1204 +     * class if this class is an array
431.1205 +     * @see     java.lang.reflect.Array
431.1206 +     * @since JDK1.1
431.1207 +     */
431.1208 +    public Class<?> getComponentType() {
431.1209 +        if (isArray()) {
431.1210 +            try {
431.1211 +                return getComponentType0();
431.1212 +            } catch (ClassNotFoundException cnfe) {
431.1213 +                throw new IllegalStateException(cnfe);
431.1214 +            }
431.1215 +        }
431.1216 +        return null;
431.1217 +    }
431.1218 +
431.1219 +    private Class<?> getComponentType0() throws ClassNotFoundException {
431.1220 +        String n = getName().substring(1);
431.1221 +        switch (n.charAt(0)) {
431.1222 +            case 'L': 
431.1223 +                n = n.substring(1, n.length() - 1);
431.1224 +                return Class.forName(n);
431.1225 +            case 'I':
431.1226 +                return Integer.TYPE;
431.1227 +            case 'J':
431.1228 +                return Long.TYPE;
431.1229 +            case 'D':
431.1230 +                return Double.TYPE;
431.1231 +            case 'F':
431.1232 +                return Float.TYPE;
431.1233 +            case 'B':
431.1234 +                return Byte.TYPE;
431.1235 +            case 'Z':
431.1236 +                return Boolean.TYPE;
431.1237 +            case 'S':
431.1238 +                return Short.TYPE;
431.1239 +            case 'V':
431.1240 +                return Void.TYPE;
431.1241 +            case 'C':
431.1242 +                return Character.TYPE;
431.1243 +            case '[':
431.1244 +                return defineArray(n);
431.1245 +            default:
431.1246 +                throw new ClassNotFoundException("Unknown component type of " + getName());
431.1247 +        }
431.1248 +    }
431.1249 +    
431.1250 +    @JavaScriptBody(args = { "sig" }, body = 
431.1251 +        "var c = Array[sig];\n" +
431.1252 +        "if (c) return c;\n" +
431.1253 +        "c = vm.java_lang_Class(true);\n" +
431.1254 +        "c.jvmName = sig;\n" +
431.1255 +        "c.superclass = vm.java_lang_Object(false).$class;\n" +
431.1256 +        "c.array = true;\n" +
431.1257 +        "Array[sig] = c;\n" +
431.1258 +        "return c;"
431.1259 +    )
431.1260 +    private static native Class<?> defineArray(String sig);
431.1261 +    
431.1262 +    /**
431.1263 +     * Returns true if and only if this class was declared as an enum in the
431.1264 +     * source code.
431.1265 +     *
431.1266 +     * @return true if and only if this class was declared as an enum in the
431.1267 +     *     source code
431.1268 +     * @since 1.5
431.1269 +     */
431.1270 +    public boolean isEnum() {
431.1271 +        // An enum must both directly extend java.lang.Enum and have
431.1272 +        // the ENUM bit set; classes for specialized enum constants
431.1273 +        // don't do the former.
431.1274 +        return (this.getModifiers() & ENUM) != 0 &&
431.1275 +        this.getSuperclass() == java.lang.Enum.class;
431.1276 +    }
431.1277 +
431.1278 +    /**
431.1279 +     * Casts an object to the class or interface represented
431.1280 +     * by this {@code Class} object.
431.1281 +     *
431.1282 +     * @param obj the object to be cast
431.1283 +     * @return the object after casting, or null if obj is null
431.1284 +     *
431.1285 +     * @throws ClassCastException if the object is not
431.1286 +     * null and is not assignable to the type T.
431.1287 +     *
431.1288 +     * @since 1.5
431.1289 +     */
431.1290 +    public T cast(Object obj) {
431.1291 +        if (obj != null && !isInstance(obj))
431.1292 +            throw new ClassCastException(cannotCastMsg(obj));
431.1293 +        return (T) obj;
431.1294 +    }
431.1295 +
431.1296 +    private String cannotCastMsg(Object obj) {
431.1297 +        return "Cannot cast " + obj.getClass().getName() + " to " + getName();
431.1298 +    }
431.1299 +
431.1300 +    /**
431.1301 +     * Casts this {@code Class} object to represent a subclass of the class
431.1302 +     * represented by the specified class object.  Checks that that the cast
431.1303 +     * is valid, and throws a {@code ClassCastException} if it is not.  If
431.1304 +     * this method succeeds, it always returns a reference to this class object.
431.1305 +     *
431.1306 +     * <p>This method is useful when a client needs to "narrow" the type of
431.1307 +     * a {@code Class} object to pass it to an API that restricts the
431.1308 +     * {@code Class} objects that it is willing to accept.  A cast would
431.1309 +     * generate a compile-time warning, as the correctness of the cast
431.1310 +     * could not be checked at runtime (because generic types are implemented
431.1311 +     * by erasure).
431.1312 +     *
431.1313 +     * @return this {@code Class} object, cast to represent a subclass of
431.1314 +     *    the specified class object.
431.1315 +     * @throws ClassCastException if this {@code Class} object does not
431.1316 +     *    represent a subclass of the specified class (here "subclass" includes
431.1317 +     *    the class itself).
431.1318 +     * @since 1.5
431.1319 +     */
431.1320 +    public <U> Class<? extends U> asSubclass(Class<U> clazz) {
431.1321 +        if (clazz.isAssignableFrom(this))
431.1322 +            return (Class<? extends U>) this;
431.1323 +        else
431.1324 +            throw new ClassCastException(this.toString());
431.1325 +    }
431.1326 +
431.1327 +    @JavaScriptBody(args = { "ac" }, 
431.1328 +        body = 
431.1329 +          "if (this.anno) {"
431.1330 +        + "  return this.anno['L' + ac.jvmName + ';'];"
431.1331 +        + "} else return null;"
431.1332 +    )
431.1333 +    private Object getAnnotationData(Class<?> annotationClass) {
431.1334 +        throw new UnsupportedOperationException();
431.1335 +    }
431.1336 +    /**
431.1337 +     * @throws NullPointerException {@inheritDoc}
431.1338 +     * @since 1.5
431.1339 +     */
431.1340 +    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
431.1341 +        Object data = getAnnotationData(annotationClass);
431.1342 +        return data == null ? null : AnnotationImpl.create(annotationClass, data);
431.1343 +    }
431.1344 +
431.1345 +    /**
431.1346 +     * @throws NullPointerException {@inheritDoc}
431.1347 +     * @since 1.5
431.1348 +     */
431.1349 +    @JavaScriptBody(args = { "ac" }, 
431.1350 +        body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
431.1351 +        + "else return false;"
431.1352 +    )
431.1353 +    public boolean isAnnotationPresent(
431.1354 +        Class<? extends Annotation> annotationClass) {
431.1355 +        if (annotationClass == null)
431.1356 +            throw new NullPointerException();
431.1357 +
431.1358 +        return getAnnotation(annotationClass) != null;
431.1359 +    }
431.1360 +
431.1361 +    @JavaScriptBody(args = {}, body = "return this.anno;")
431.1362 +    private Object getAnnotationData() {
431.1363 +        throw new UnsupportedOperationException();
431.1364 +    }
431.1365 +
431.1366 +    /**
431.1367 +     * @since 1.5
431.1368 +     */
431.1369 +    public Annotation[] getAnnotations() {
431.1370 +        Object data = getAnnotationData();
431.1371 +        return data == null ? new Annotation[0] : AnnotationImpl.create(data);
431.1372 +    }
431.1373 +
431.1374 +    /**
431.1375 +     * @since 1.5
431.1376 +     */
431.1377 +    public Annotation[] getDeclaredAnnotations()  {
431.1378 +        throw new UnsupportedOperationException();
431.1379 +    }
431.1380 +
431.1381 +    @JavaScriptBody(args = "type", body = ""
431.1382 +        + "var c = vm.java_lang_Class(true);"
431.1383 +        + "c.jvmName = type;"
431.1384 +        + "c.primitive = true;"
431.1385 +        + "return c;"
431.1386 +    )
431.1387 +    native static Class getPrimitiveClass(String type);
431.1388 +
431.1389 +    @JavaScriptBody(args = {}, body = 
431.1390 +        "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
431.1391 +    )
431.1392 +    public native boolean desiredAssertionStatus();
431.1393 +}
   432.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   432.2 +++ b/rt/emul/mini/src/main/java/java/lang/ClassCastException.java	Wed Feb 27 11:24:58 2013 +0100
   432.3 @@ -0,0 +1,60 @@
   432.4 +/*
   432.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   432.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   432.7 + *
   432.8 + * This code is free software; you can redistribute it and/or modify it
   432.9 + * under the terms of the GNU General Public License version 2 only, as
  432.10 + * published by the Free Software Foundation.  Oracle designates this
  432.11 + * particular file as subject to the "Classpath" exception as provided
  432.12 + * by Oracle in the LICENSE file that accompanied this code.
  432.13 + *
  432.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  432.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  432.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  432.17 + * version 2 for more details (a copy is included in the LICENSE file that
  432.18 + * accompanied this code).
  432.19 + *
  432.20 + * You should have received a copy of the GNU General Public License version
  432.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  432.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  432.23 + *
  432.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  432.25 + * or visit www.oracle.com if you need additional information or have any
  432.26 + * questions.
  432.27 + */
  432.28 +
  432.29 +package java.lang;
  432.30 +
  432.31 +/**
  432.32 + * Thrown to indicate that the code has attempted to cast an object
  432.33 + * to a subclass of which it is not an instance. For example, the
  432.34 + * following code generates a <code>ClassCastException</code>:
  432.35 + * <p><blockquote><pre>
  432.36 + *     Object x = new Integer(0);
  432.37 + *     System.out.println((String)x);
  432.38 + * </pre></blockquote>
  432.39 + *
  432.40 + * @author  unascribed
  432.41 + * @since   JDK1.0
  432.42 + */
  432.43 +public
  432.44 +class ClassCastException extends RuntimeException {
  432.45 +    private static final long serialVersionUID = -9223365651070458532L;
  432.46 +
  432.47 +    /**
  432.48 +     * Constructs a <code>ClassCastException</code> with no detail message.
  432.49 +     */
  432.50 +    public ClassCastException() {
  432.51 +        super();
  432.52 +    }
  432.53 +
  432.54 +    /**
  432.55 +     * Constructs a <code>ClassCastException</code> with the specified
  432.56 +     * detail message.
  432.57 +     *
  432.58 +     * @param   s   the detail message.
  432.59 +     */
  432.60 +    public ClassCastException(String s) {
  432.61 +        super(s);
  432.62 +    }
  432.63 +}
   433.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   433.2 +++ b/rt/emul/mini/src/main/java/java/lang/ClassFormatError.java	Wed Feb 27 11:24:58 2013 +0100
   433.3 @@ -0,0 +1,56 @@
   433.4 +/*
   433.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   433.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   433.7 + *
   433.8 + * This code is free software; you can redistribute it and/or modify it
   433.9 + * under the terms of the GNU General Public License version 2 only, as
  433.10 + * published by the Free Software Foundation.  Oracle designates this
  433.11 + * particular file as subject to the "Classpath" exception as provided
  433.12 + * by Oracle in the LICENSE file that accompanied this code.
  433.13 + *
  433.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  433.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  433.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  433.17 + * version 2 for more details (a copy is included in the LICENSE file that
  433.18 + * accompanied this code).
  433.19 + *
  433.20 + * You should have received a copy of the GNU General Public License version
  433.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  433.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  433.23 + *
  433.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  433.25 + * or visit www.oracle.com if you need additional information or have any
  433.26 + * questions.
  433.27 + */
  433.28 +
  433.29 +package java.lang;
  433.30 +
  433.31 +/**
  433.32 + * Thrown when the Java Virtual Machine attempts to read a class
  433.33 + * file and determines that the file is malformed or otherwise cannot
  433.34 + * be interpreted as a class file.
  433.35 + *
  433.36 + * @author  unascribed
  433.37 + * @since   JDK1.0
  433.38 + */
  433.39 +public
  433.40 +class ClassFormatError extends LinkageError {
  433.41 +    private static final long serialVersionUID = -8420114879011949195L;
  433.42 +
  433.43 +    /**
  433.44 +     * Constructs a <code>ClassFormatError</code> with no detail message.
  433.45 +     */
  433.46 +    public ClassFormatError() {
  433.47 +        super();
  433.48 +    }
  433.49 +
  433.50 +    /**
  433.51 +     * Constructs a <code>ClassFormatError</code> with the specified
  433.52 +     * detail message.
  433.53 +     *
  433.54 +     * @param   s   the detail message.
  433.55 +     */
  433.56 +    public ClassFormatError(String s) {
  433.57 +        super(s);
  433.58 +    }
  433.59 +}
   434.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   434.2 +++ b/rt/emul/mini/src/main/java/java/lang/ClassLoader.java	Wed Feb 27 11:24:58 2013 +0100
   434.3 @@ -0,0 +1,936 @@
   434.4 +/*
   434.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   434.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   434.7 + *
   434.8 + * This code is free software; you can redistribute it and/or modify it
   434.9 + * under the terms of the GNU General Public License version 2 only, as
  434.10 + * published by the Free Software Foundation.  Oracle designates this
  434.11 + * particular file as subject to the "Classpath" exception as provided
  434.12 + * by Oracle in the LICENSE file that accompanied this code.
  434.13 + *
  434.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  434.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  434.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  434.17 + * version 2 for more details (a copy is included in the LICENSE file that
  434.18 + * accompanied this code).
  434.19 + *
  434.20 + * You should have received a copy of the GNU General Public License version
  434.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  434.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  434.23 + *
  434.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  434.25 + * or visit www.oracle.com if you need additional information or have any
  434.26 + * questions.
  434.27 + */
  434.28 +package java.lang;
  434.29 +
  434.30 +import java.io.InputStream;
  434.31 +import java.io.IOException;
  434.32 +import java.net.URL;
  434.33 +import java.util.Enumeration;
  434.34 +import java.util.NoSuchElementException;
  434.35 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  434.36 +
  434.37 +/**
  434.38 + * A class loader is an object that is responsible for loading classes. The
  434.39 + * class <tt>ClassLoader</tt> is an abstract class.  Given the <a
  434.40 + * href="#name">binary name</a> of a class, a class loader should attempt to
  434.41 + * locate or generate data that constitutes a definition for the class.  A
  434.42 + * typical strategy is to transform the name into a file name and then read a
  434.43 + * "class file" of that name from a file system.
  434.44 + *
  434.45 + * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
  434.46 + * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
  434.47 + * it.
  434.48 + *
  434.49 + * <p> <tt>Class</tt> objects for array classes are not created by class
  434.50 + * loaders, but are created automatically as required by the Java runtime.
  434.51 + * The class loader for an array class, as returned by {@link
  434.52 + * Class#getClassLoader()} is the same as the class loader for its element
  434.53 + * type; if the element type is a primitive type, then the array class has no
  434.54 + * class loader.
  434.55 + *
  434.56 + * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
  434.57 + * extend the manner in which the Java virtual machine dynamically loads
  434.58 + * classes.
  434.59 + *
  434.60 + * <p> Class loaders may typically be used by security managers to indicate
  434.61 + * security domains.
  434.62 + *
  434.63 + * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
  434.64 + * classes and resources.  Each instance of <tt>ClassLoader</tt> has an
  434.65 + * associated parent class loader.  When requested to find a class or
  434.66 + * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
  434.67 + * class or resource to its parent class loader before attempting to find the
  434.68 + * class or resource itself.  The virtual machine's built-in class loader,
  434.69 + * called the "bootstrap class loader", does not itself have a parent but may
  434.70 + * serve as the parent of a <tt>ClassLoader</tt> instance.
  434.71 + *
  434.72 + * <p> Class loaders that support concurrent loading of classes are known as
  434.73 + * <em>parallel capable</em> class loaders and are required to register
  434.74 + * themselves at their class initialization time by invoking the
  434.75 + * {@link
  434.76 + * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
  434.77 + * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
  434.78 + * capable by default. However, its subclasses still need to register themselves
  434.79 + * if they are parallel capable. <br>
  434.80 + * In environments in which the delegation model is not strictly
  434.81 + * hierarchical, class loaders need to be parallel capable, otherwise class
  434.82 + * loading can lead to deadlocks because the loader lock is held for the
  434.83 + * duration of the class loading process (see {@link #loadClass
  434.84 + * <tt>loadClass</tt>} methods).
  434.85 + *
  434.86 + * <p> Normally, the Java virtual machine loads classes from the local file
  434.87 + * system in a platform-dependent manner.  For example, on UNIX systems, the
  434.88 + * virtual machine loads classes from the directory defined by the
  434.89 + * <tt>CLASSPATH</tt> environment variable.
  434.90 + *
  434.91 + * <p> However, some classes may not originate from a file; they may originate
  434.92 + * from other sources, such as the network, or they could be constructed by an
  434.93 + * application.  The method {@link #defineClass(String, byte[], int, int)
  434.94 + * <tt>defineClass</tt>} converts an array of bytes into an instance of class
  434.95 + * <tt>Class</tt>. Instances of this newly defined class can be created using
  434.96 + * {@link Class#newInstance <tt>Class.newInstance</tt>}.
  434.97 + *
  434.98 + * <p> The methods and constructors of objects created by a class loader may
  434.99 + * reference other classes.  To determine the class(es) referred to, the Java
 434.100 + * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
 434.101 + * the class loader that originally created the class.
 434.102 + *
 434.103 + * <p> For example, an application could create a network class loader to
 434.104 + * download class files from a server.  Sample code might look like:
 434.105 + *
 434.106 + * <blockquote><pre>
 434.107 + *   ClassLoader loader&nbsp;= new NetworkClassLoader(host,&nbsp;port);
 434.108 + *   Object main&nbsp;= loader.loadClass("Main", true).newInstance();
 434.109 + *       &nbsp;.&nbsp;.&nbsp;.
 434.110 + * </pre></blockquote>
 434.111 + *
 434.112 + * <p> The network class loader subclass must define the methods {@link
 434.113 + * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
 434.114 + * from the network.  Once it has downloaded the bytes that make up the class,
 434.115 + * it should use the method {@link #defineClass <tt>defineClass</tt>} to
 434.116 + * create a class instance.  A sample implementation is:
 434.117 + *
 434.118 + * <blockquote><pre>
 434.119 + *     class NetworkClassLoader extends ClassLoader {
 434.120 + *         String host;
 434.121 + *         int port;
 434.122 + *
 434.123 + *         public Class findClass(String name) {
 434.124 + *             byte[] b = loadClassData(name);
 434.125 + *             return defineClass(name, b, 0, b.length);
 434.126 + *         }
 434.127 + *
 434.128 + *         private byte[] loadClassData(String name) {
 434.129 + *             // load the class data from the connection
 434.130 + *             &nbsp;.&nbsp;.&nbsp;.
 434.131 + *         }
 434.132 + *     }
 434.133 + * </pre></blockquote>
 434.134 + *
 434.135 + * <h4> <a name="name">Binary names</a> </h4>
 434.136 + *
 434.137 + * <p> Any class name provided as a {@link String} parameter to methods in
 434.138 + * <tt>ClassLoader</tt> must be a binary name as defined by
 434.139 + * <cite>The Java&trade; Language Specification</cite>.
 434.140 + *
 434.141 + * <p> Examples of valid class names include:
 434.142 + * <blockquote><pre>
 434.143 + *   "java.lang.String"
 434.144 + *   "javax.swing.JSpinner$DefaultEditor"
 434.145 + *   "java.security.KeyStore$Builder$FileBuilder$1"
 434.146 + *   "java.net.URLClassLoader$3$1"
 434.147 + * </pre></blockquote>
 434.148 + *
 434.149 + * @see      #resolveClass(Class)
 434.150 + * @since 1.0
 434.151 + */
 434.152 +public abstract class ClassLoader {
 434.153 +
 434.154 +    @JavaScriptBody(args = {}, body = "")
 434.155 +    private static native void registerNatives();
 434.156 +    static {
 434.157 +        registerNatives();
 434.158 +    }
 434.159 +
 434.160 +    // The parent class loader for delegation
 434.161 +    // Note: VM hardcoded the offset of this field, thus all new fields
 434.162 +    // must be added *after* it.
 434.163 +    private final ClassLoader parent;
 434.164 +
 434.165 +
 434.166 +    /**
 434.167 +     * Creates a new class loader using the specified parent class loader for
 434.168 +     * delegation.
 434.169 +     *
 434.170 +     * <p> If there is a security manager, its {@link
 434.171 +     * SecurityManager#checkCreateClassLoader()
 434.172 +     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 434.173 +     * a security exception.  </p>
 434.174 +     *
 434.175 +     * @param  parent
 434.176 +     *         The parent class loader
 434.177 +     *
 434.178 +     * @throws  SecurityException
 434.179 +     *          If a security manager exists and its
 434.180 +     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 434.181 +     *          of a new class loader.
 434.182 +     *
 434.183 +     * @since  1.2
 434.184 +     */
 434.185 +    protected ClassLoader(ClassLoader parent) {
 434.186 +        throw new SecurityException();
 434.187 +    }
 434.188 +
 434.189 +    /**
 434.190 +     * Creates a new class loader using the <tt>ClassLoader</tt> returned by
 434.191 +     * the method {@link #getSystemClassLoader()
 434.192 +     * <tt>getSystemClassLoader()</tt>} as the parent class loader.
 434.193 +     *
 434.194 +     * <p> If there is a security manager, its {@link
 434.195 +     * SecurityManager#checkCreateClassLoader()
 434.196 +     * <tt>checkCreateClassLoader</tt>} method is invoked.  This may result in
 434.197 +     * a security exception.  </p>
 434.198 +     *
 434.199 +     * @throws  SecurityException
 434.200 +     *          If a security manager exists and its
 434.201 +     *          <tt>checkCreateClassLoader</tt> method doesn't allow creation
 434.202 +     *          of a new class loader.
 434.203 +     */
 434.204 +    protected ClassLoader() {
 434.205 +        throw new SecurityException();
 434.206 +    }
 434.207 +
 434.208 +    // -- Class --
 434.209 +
 434.210 +    /**
 434.211 +     * Loads the class with the specified <a href="#name">binary name</a>.
 434.212 +     * This method searches for classes in the same manner as the {@link
 434.213 +     * #loadClass(String, boolean)} method.  It is invoked by the Java virtual
 434.214 +     * machine to resolve class references.  Invoking this method is equivalent
 434.215 +     * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
 434.216 +     * false)</tt>}.  </p>
 434.217 +     *
 434.218 +     * @param  name
 434.219 +     *         The <a href="#name">binary name</a> of the class
 434.220 +     *
 434.221 +     * @return  The resulting <tt>Class</tt> object
 434.222 +     *
 434.223 +     * @throws  ClassNotFoundException
 434.224 +     *          If the class was not found
 434.225 +     */
 434.226 +    public Class<?> loadClass(String name) throws ClassNotFoundException {
 434.227 +        return loadClass(name, false);
 434.228 +    }
 434.229 +
 434.230 +    /**
 434.231 +     * Loads the class with the specified <a href="#name">binary name</a>.  The
 434.232 +     * default implementation of this method searches for classes in the
 434.233 +     * following order:
 434.234 +     *
 434.235 +     * <p><ol>
 434.236 +     *
 434.237 +     *   <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
 434.238 +     *   has already been loaded.  </p></li>
 434.239 +     *
 434.240 +     *   <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
 434.241 +     *   on the parent class loader.  If the parent is <tt>null</tt> the class
 434.242 +     *   loader built-in to the virtual machine is used, instead.  </p></li>
 434.243 +     *
 434.244 +     *   <li><p> Invoke the {@link #findClass(String)} method to find the
 434.245 +     *   class.  </p></li>
 434.246 +     *
 434.247 +     * </ol>
 434.248 +     *
 434.249 +     * <p> If the class was found using the above steps, and the
 434.250 +     * <tt>resolve</tt> flag is true, this method will then invoke the {@link
 434.251 +     * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
 434.252 +     *
 434.253 +     * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
 434.254 +     * #findClass(String)}, rather than this method.  </p>
 434.255 +     *
 434.256 +     * <p> Unless overridden, this method synchronizes on the result of
 434.257 +     * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
 434.258 +     * during the entire class loading process.
 434.259 +     *
 434.260 +     * @param  name
 434.261 +     *         The <a href="#name">binary name</a> of the class
 434.262 +     *
 434.263 +     * @param  resolve
 434.264 +     *         If <tt>true</tt> then resolve the class
 434.265 +     *
 434.266 +     * @return  The resulting <tt>Class</tt> object
 434.267 +     *
 434.268 +     * @throws  ClassNotFoundException
 434.269 +     *          If the class could not be found
 434.270 +     */
 434.271 +    protected Class<?> loadClass(String name, boolean resolve)
 434.272 +        throws ClassNotFoundException
 434.273 +    {
 434.274 +        synchronized (getClassLoadingLock(name)) {
 434.275 +            // First, check if the class has already been loaded
 434.276 +            Class c = findLoadedClass(name);
 434.277 +            if (c == null) {
 434.278 +                try {
 434.279 +                    if (parent != null) {
 434.280 +                        c = parent.loadClass(name, false);
 434.281 +                    } else {
 434.282 +                        c = findBootstrapClassOrNull(name);
 434.283 +                    }
 434.284 +                } catch (ClassNotFoundException e) {
 434.285 +                    // ClassNotFoundException thrown if class not found
 434.286 +                    // from the non-null parent class loader
 434.287 +                }
 434.288 +
 434.289 +                if (c == null) {
 434.290 +                    // If still not found, then invoke findClass in order
 434.291 +                    // to find the class.
 434.292 +                    c = findClass(name);
 434.293 +
 434.294 +//                    // this is the defining class loader; record the stats
 434.295 +//                    sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
 434.296 +//                    sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
 434.297 +//                    sun.misc.PerfCounter.getFindClasses().increment();
 434.298 +                }
 434.299 +            }
 434.300 +            if (resolve) {
 434.301 +                resolveClass(c);
 434.302 +            }
 434.303 +            return c;
 434.304 +        }
 434.305 +    }
 434.306 +
 434.307 +    /**
 434.308 +     * Returns the lock object for class loading operations.
 434.309 +     * For backward compatibility, the default implementation of this method
 434.310 +     * behaves as follows. If this ClassLoader object is registered as
 434.311 +     * parallel capable, the method returns a dedicated object associated
 434.312 +     * with the specified class name. Otherwise, the method returns this
 434.313 +     * ClassLoader object. </p>
 434.314 +     *
 434.315 +     * @param  className
 434.316 +     *         The name of the to-be-loaded class
 434.317 +     *
 434.318 +     * @return the lock for class loading operations
 434.319 +     *
 434.320 +     * @throws NullPointerException
 434.321 +     *         If registered as parallel capable and <tt>className</tt> is null
 434.322 +     *
 434.323 +     * @see #loadClass(String, boolean)
 434.324 +     *
 434.325 +     * @since  1.7
 434.326 +     */
 434.327 +    protected Object getClassLoadingLock(String className) {
 434.328 +        Object lock = this;
 434.329 +        return lock;
 434.330 +    }
 434.331 +
 434.332 +    /**
 434.333 +     * Finds the class with the specified <a href="#name">binary name</a>.
 434.334 +     * This method should be overridden by class loader implementations that
 434.335 +     * follow the delegation model for loading classes, and will be invoked by
 434.336 +     * the {@link #loadClass <tt>loadClass</tt>} method after checking the
 434.337 +     * parent class loader for the requested class.  The default implementation
 434.338 +     * throws a <tt>ClassNotFoundException</tt>.  </p>
 434.339 +     *
 434.340 +     * @param  name
 434.341 +     *         The <a href="#name">binary name</a> of the class
 434.342 +     *
 434.343 +     * @return  The resulting <tt>Class</tt> object
 434.344 +     *
 434.345 +     * @throws  ClassNotFoundException
 434.346 +     *          If the class could not be found
 434.347 +     *
 434.348 +     * @since  1.2
 434.349 +     */
 434.350 +    protected Class<?> findClass(String name) throws ClassNotFoundException {
 434.351 +        throw new ClassNotFoundException(name);
 434.352 +    }
 434.353 +
 434.354 +    /**
 434.355 +     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 434.356 +     * Before the <tt>Class</tt> can be used it must be resolved.  This method
 434.357 +     * is deprecated in favor of the version that takes a <a
 434.358 +     * href="#name">binary name</a> as its first argument, and is more secure.
 434.359 +     *
 434.360 +     * @param  b
 434.361 +     *         The bytes that make up the class data.  The bytes in positions
 434.362 +     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 434.363 +     *         of a valid class file as defined by
 434.364 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 434.365 +     *
 434.366 +     * @param  off
 434.367 +     *         The start offset in <tt>b</tt> of the class data
 434.368 +     *
 434.369 +     * @param  len
 434.370 +     *         The length of the class data
 434.371 +     *
 434.372 +     * @return  The <tt>Class</tt> object that was created from the specified
 434.373 +     *          class data
 434.374 +     *
 434.375 +     * @throws  ClassFormatError
 434.376 +     *          If the data did not contain a valid class
 434.377 +     *
 434.378 +     * @throws  IndexOutOfBoundsException
 434.379 +     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 434.380 +     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 434.381 +     *
 434.382 +     * @throws  SecurityException
 434.383 +     *          If an attempt is made to add this class to a package that
 434.384 +     *          contains classes that were signed by a different set of
 434.385 +     *          certificates than this class, or if an attempt is made
 434.386 +     *          to define a class in a package with a fully-qualified name
 434.387 +     *          that starts with "{@code java.}".
 434.388 +     *
 434.389 +     * @see  #loadClass(String, boolean)
 434.390 +     * @see  #resolveClass(Class)
 434.391 +     *
 434.392 +     * @deprecated  Replaced by {@link #defineClass(String, byte[], int, int)
 434.393 +     * defineClass(String, byte[], int, int)}
 434.394 +     */
 434.395 +    @Deprecated
 434.396 +    protected final Class<?> defineClass(byte[] b, int off, int len)
 434.397 +        throws ClassFormatError
 434.398 +    {
 434.399 +        throw new SecurityException();
 434.400 +    }
 434.401 +
 434.402 +    /**
 434.403 +     * Converts an array of bytes into an instance of class <tt>Class</tt>.
 434.404 +     * Before the <tt>Class</tt> can be used it must be resolved.
 434.405 +     *
 434.406 +     * <p> This method assigns a default {@link java.security.ProtectionDomain
 434.407 +     * <tt>ProtectionDomain</tt>} to the newly defined class.  The
 434.408 +     * <tt>ProtectionDomain</tt> is effectively granted the same set of
 434.409 +     * permissions returned when {@link
 434.410 +     * java.security.Policy#getPermissions(java.security.CodeSource)
 434.411 +     * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
 434.412 +     * is invoked.  The default domain is created on the first invocation of
 434.413 +     * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
 434.414 +     * and re-used on subsequent invocations.
 434.415 +     *
 434.416 +     * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
 434.417 +     * the {@link #defineClass(String, byte[], int, int,
 434.418 +     * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
 434.419 +     * <tt>ProtectionDomain</tt> as one of its arguments.  </p>
 434.420 +     *
 434.421 +     * @param  name
 434.422 +     *         The expected <a href="#name">binary name</a> of the class, or
 434.423 +     *         <tt>null</tt> if not known
 434.424 +     *
 434.425 +     * @param  b
 434.426 +     *         The bytes that make up the class data.  The bytes in positions
 434.427 +     *         <tt>off</tt> through <tt>off+len-1</tt> should have the format
 434.428 +     *         of a valid class file as defined by
 434.429 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 434.430 +     *
 434.431 +     * @param  off
 434.432 +     *         The start offset in <tt>b</tt> of the class data
 434.433 +     *
 434.434 +     * @param  len
 434.435 +     *         The length of the class data
 434.436 +     *
 434.437 +     * @return  The <tt>Class</tt> object that was created from the specified
 434.438 +     *          class data.
 434.439 +     *
 434.440 +     * @throws  ClassFormatError
 434.441 +     *          If the data did not contain a valid class
 434.442 +     *
 434.443 +     * @throws  IndexOutOfBoundsException
 434.444 +     *          If either <tt>off</tt> or <tt>len</tt> is negative, or if
 434.445 +     *          <tt>off+len</tt> is greater than <tt>b.length</tt>.
 434.446 +     *
 434.447 +     * @throws  SecurityException
 434.448 +     *          If an attempt is made to add this class to a package that
 434.449 +     *          contains classes that were signed by a different set of
 434.450 +     *          certificates than this class (which is unsigned), or if
 434.451 +     *          <tt>name</tt> begins with "<tt>java.</tt>".
 434.452 +     *
 434.453 +     * @see  #loadClass(String, boolean)
 434.454 +     * @see  #resolveClass(Class)
 434.455 +     * @see  java.security.CodeSource
 434.456 +     * @see  java.security.SecureClassLoader
 434.457 +     *
 434.458 +     * @since  1.1
 434.459 +     */
 434.460 +    protected final Class<?> defineClass(String name, byte[] b, int off, int len)
 434.461 +        throws ClassFormatError
 434.462 +    {
 434.463 +        throw new SecurityException();
 434.464 +    }
 434.465 +
 434.466 +    /**
 434.467 +     * Links the specified class.  This (misleadingly named) method may be
 434.468 +     * used by a class loader to link a class.  If the class <tt>c</tt> has
 434.469 +     * already been linked, then this method simply returns. Otherwise, the
 434.470 +     * class is linked as described in the "Execution" chapter of
 434.471 +     * <cite>The Java&trade; Language Specification</cite>.
 434.472 +     * </p>
 434.473 +     *
 434.474 +     * @param  c
 434.475 +     *         The class to link
 434.476 +     *
 434.477 +     * @throws  NullPointerException
 434.478 +     *          If <tt>c</tt> is <tt>null</tt>.
 434.479 +     *
 434.480 +     * @see  #defineClass(String, byte[], int, int)
 434.481 +     */
 434.482 +    protected final void resolveClass(Class<?> c) {
 434.483 +        resolveClass0(c);
 434.484 +    }
 434.485 +
 434.486 +    private native void resolveClass0(Class c);
 434.487 +
 434.488 +
 434.489 +    /**
 434.490 +     * Returns the class with the given <a href="#name">binary name</a> if this
 434.491 +     * loader has been recorded by the Java virtual machine as an initiating
 434.492 +     * loader of a class with that <a href="#name">binary name</a>.  Otherwise
 434.493 +     * <tt>null</tt> is returned.  </p>
 434.494 +     *
 434.495 +     * @param  name
 434.496 +     *         The <a href="#name">binary name</a> of the class
 434.497 +     *
 434.498 +     * @return  The <tt>Class</tt> object, or <tt>null</tt> if the class has
 434.499 +     *          not been loaded
 434.500 +     *
 434.501 +     * @since  1.1
 434.502 +     */
 434.503 +    protected final Class<?> findLoadedClass(String name) {
 434.504 +        if (!checkName(name))
 434.505 +            return null;
 434.506 +        return findLoadedClass0(name);
 434.507 +    }
 434.508 +
 434.509 +    private native final Class findLoadedClass0(String name);
 434.510 +
 434.511 +    /**
 434.512 +     * Sets the signers of a class.  This should be invoked after defining a
 434.513 +     * class.  </p>
 434.514 +     *
 434.515 +     * @param  c
 434.516 +     *         The <tt>Class</tt> object
 434.517 +     *
 434.518 +     * @param  signers
 434.519 +     *         The signers for the class
 434.520 +     *
 434.521 +     * @since  1.1
 434.522 +     */
 434.523 +    protected final void setSigners(Class<?> c, Object[] signers) {
 434.524 +        //c.setSigners(signers);
 434.525 +        throw new UnsupportedOperationException();
 434.526 +    }
 434.527 +
 434.528 +
 434.529 +    // -- Resource --
 434.530 +
 434.531 +    /**
 434.532 +     * Finds the resource with the given name.  A resource is some data
 434.533 +     * (images, audio, text, etc) that can be accessed by class code in a way
 434.534 +     * that is independent of the location of the code.
 434.535 +     *
 434.536 +     * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
 434.537 +     * identifies the resource.
 434.538 +     *
 434.539 +     * <p> This method will first search the parent class loader for the
 434.540 +     * resource; if the parent is <tt>null</tt> the path of the class loader
 434.541 +     * built-in to the virtual machine is searched.  That failing, this method
 434.542 +     * will invoke {@link #findResource(String)} to find the resource.  </p>
 434.543 +     *
 434.544 +     * @param  name
 434.545 +     *         The resource name
 434.546 +     *
 434.547 +     * @return  A <tt>URL</tt> object for reading the resource, or
 434.548 +     *          <tt>null</tt> if the resource could not be found or the invoker
 434.549 +     *          doesn't have adequate  privileges to get the resource.
 434.550 +     *
 434.551 +     * @since  1.1
 434.552 +     */
 434.553 +    public URL getResource(String name) {
 434.554 +        URL url;
 434.555 +        if (parent != null) {
 434.556 +            url = parent.getResource(name);
 434.557 +        } else {
 434.558 +            url = getBootstrapResource(name);
 434.559 +        }
 434.560 +        if (url == null) {
 434.561 +            url = findResource(name);
 434.562 +        }
 434.563 +        return url;
 434.564 +    }
 434.565 +
 434.566 +    /**
 434.567 +     * Finds all the resources with the given name. A resource is some data
 434.568 +     * (images, audio, text, etc) that can be accessed by class code in a way
 434.569 +     * that is independent of the location of the code.
 434.570 +     *
 434.571 +     * <p>The name of a resource is a <tt>/</tt>-separated path name that
 434.572 +     * identifies the resource.
 434.573 +     *
 434.574 +     * <p> The search order is described in the documentation for {@link
 434.575 +     * #getResource(String)}.  </p>
 434.576 +     *
 434.577 +     * @param  name
 434.578 +     *         The resource name
 434.579 +     *
 434.580 +     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 434.581 +     *          the resource.  If no resources could  be found, the enumeration
 434.582 +     *          will be empty.  Resources that the class loader doesn't have
 434.583 +     *          access to will not be in the enumeration.
 434.584 +     *
 434.585 +     * @throws  IOException
 434.586 +     *          If I/O errors occur
 434.587 +     *
 434.588 +     * @see  #findResources(String)
 434.589 +     *
 434.590 +     * @since  1.2
 434.591 +     */
 434.592 +    public Enumeration<URL> getResources(String name) throws IOException {
 434.593 +        Enumeration[] tmp = new Enumeration[2];
 434.594 +        if (parent != null) {
 434.595 +            tmp[0] = parent.getResources(name);
 434.596 +        } else {
 434.597 +            tmp[0] = getBootstrapResources(name);
 434.598 +        }
 434.599 +        tmp[1] = findResources(name);
 434.600 +
 434.601 +        return new CompoundEnumeration(tmp);
 434.602 +    }
 434.603 +
 434.604 +    /**
 434.605 +     * Finds the resource with the given name. Class loader implementations
 434.606 +     * should override this method to specify where to find resources.  </p>
 434.607 +     *
 434.608 +     * @param  name
 434.609 +     *         The resource name
 434.610 +     *
 434.611 +     * @return  A <tt>URL</tt> object for reading the resource, or
 434.612 +     *          <tt>null</tt> if the resource could not be found
 434.613 +     *
 434.614 +     * @since  1.2
 434.615 +     */
 434.616 +    protected URL findResource(String name) {
 434.617 +        return null;
 434.618 +    }
 434.619 +
 434.620 +    /**
 434.621 +     * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
 434.622 +     * representing all the resources with the given name. Class loader
 434.623 +     * implementations should override this method to specify where to load
 434.624 +     * resources from.  </p>
 434.625 +     *
 434.626 +     * @param  name
 434.627 +     *         The resource name
 434.628 +     *
 434.629 +     * @return  An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
 434.630 +     *          the resources
 434.631 +     *
 434.632 +     * @throws  IOException
 434.633 +     *          If I/O errors occur
 434.634 +     *
 434.635 +     * @since  1.2
 434.636 +     */
 434.637 +    protected Enumeration<URL> findResources(String name) throws IOException {
 434.638 +        return new CompoundEnumeration(new Enumeration[0]);
 434.639 +    }
 434.640 +
 434.641 +    // index 0: java.lang.ClassLoader.class
 434.642 +    // index 1: the immediate caller of index 0.
 434.643 +    // index 2: the immediate caller of index 1.
 434.644 +    private static native Class<? extends ClassLoader> getCaller(int index);
 434.645 +
 434.646 +    /**
 434.647 +     * Registers the caller as parallel capable.</p>
 434.648 +     * The registration succeeds if and only if all of the following
 434.649 +     * conditions are met: <br>
 434.650 +     * 1. no instance of the caller has been created</p>
 434.651 +     * 2. all of the super classes (except class Object) of the caller are
 434.652 +     * registered as parallel capable</p>
 434.653 +     * Note that once a class loader is registered as parallel capable, there
 434.654 +     * is no way to change it back. </p>
 434.655 +     *
 434.656 +     * @return  true if the caller is successfully registered as
 434.657 +     *          parallel capable and false if otherwise.
 434.658 +     *
 434.659 +     * @since   1.7
 434.660 +     */
 434.661 +//    protected static boolean registerAsParallelCapable() {
 434.662 +//        return false;
 434.663 +//    }
 434.664 +
 434.665 +    /**
 434.666 +     * Find a resource of the specified name from the search path used to load
 434.667 +     * classes.  This method locates the resource through the system class
 434.668 +     * loader (see {@link #getSystemClassLoader()}).  </p>
 434.669 +     *
 434.670 +     * @param  name
 434.671 +     *         The resource name
 434.672 +     *
 434.673 +     * @return  A {@link java.net.URL <tt>URL</tt>} object for reading the
 434.674 +     *          resource, or <tt>null</tt> if the resource could not be found
 434.675 +     *
 434.676 +     * @since  1.1
 434.677 +     */
 434.678 +    public static URL getSystemResource(String name) {
 434.679 +        ClassLoader system = getSystemClassLoader();
 434.680 +        if (system == null) {
 434.681 +            return getBootstrapResource(name);
 434.682 +        }
 434.683 +        return system.getResource(name);
 434.684 +    }
 434.685 +
 434.686 +    /**
 434.687 +     * Finds all resources of the specified name from the search path used to
 434.688 +     * load classes.  The resources thus found are returned as an
 434.689 +     * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
 434.690 +     * java.net.URL <tt>URL</tt>} objects.
 434.691 +     *
 434.692 +     * <p> The search order is described in the documentation for {@link
 434.693 +     * #getSystemResource(String)}.  </p>
 434.694 +     *
 434.695 +     * @param  name
 434.696 +     *         The resource name
 434.697 +     *
 434.698 +     * @return  An enumeration of resource {@link java.net.URL <tt>URL</tt>}
 434.699 +     *          objects
 434.700 +     *
 434.701 +     * @throws  IOException
 434.702 +     *          If I/O errors occur
 434.703 +
 434.704 +     * @since  1.2
 434.705 +     */
 434.706 +    public static Enumeration<URL> getSystemResources(String name)
 434.707 +        throws IOException
 434.708 +    {
 434.709 +        ClassLoader system = null; // getSystemClassLoader();
 434.710 +        if (system == null) {
 434.711 +            return getBootstrapResources(name);
 434.712 +        }
 434.713 +        return system.getResources(name);
 434.714 +    }
 434.715 +
 434.716 +
 434.717 +
 434.718 +    /**
 434.719 +     * Returns an input stream for reading the specified resource.
 434.720 +     *
 434.721 +     * <p> The search order is described in the documentation for {@link
 434.722 +     * #getResource(String)}.  </p>
 434.723 +     *
 434.724 +     * @param  name
 434.725 +     *         The resource name
 434.726 +     *
 434.727 +     * @return  An input stream for reading the resource, or <tt>null</tt>
 434.728 +     *          if the resource could not be found
 434.729 +     *
 434.730 +     * @since  1.1
 434.731 +     */
 434.732 +    public InputStream getResourceAsStream(String name) {
 434.733 +        URL url = getResource(name);
 434.734 +        try {
 434.735 +            return url != null ? url.openStream() : null;
 434.736 +        } catch (IOException e) {
 434.737 +            return null;
 434.738 +        }
 434.739 +    }
 434.740 +
 434.741 +    /**
 434.742 +     * Open for reading, a resource of the specified name from the search path
 434.743 +     * used to load classes.  This method locates the resource through the
 434.744 +     * system class loader (see {@link #getSystemClassLoader()}).  </p>
 434.745 +     *
 434.746 +     * @param  name
 434.747 +     *         The resource name
 434.748 +     *
 434.749 +     * @return  An input stream for reading the resource, or <tt>null</tt>
 434.750 +     *          if the resource could not be found
 434.751 +     *
 434.752 +     * @since  1.1
 434.753 +     */
 434.754 +    public static InputStream getSystemResourceAsStream(String name) {
 434.755 +        URL url = getSystemResource(name);
 434.756 +        try {
 434.757 +            return url != null ? url.openStream() : null;
 434.758 +        } catch (IOException e) {
 434.759 +            return null;
 434.760 +        }
 434.761 +    }
 434.762 +
 434.763 +
 434.764 +    // -- Hierarchy --
 434.765 +
 434.766 +    /**
 434.767 +     * Returns the parent class loader for delegation. Some implementations may
 434.768 +     * use <tt>null</tt> to represent the bootstrap class loader. This method
 434.769 +     * will return <tt>null</tt> in such implementations if this class loader's
 434.770 +     * parent is the bootstrap class loader.
 434.771 +     *
 434.772 +     * <p> If a security manager is present, and the invoker's class loader is
 434.773 +     * not <tt>null</tt> and is not an ancestor of this class loader, then this
 434.774 +     * method invokes the security manager's {@link
 434.775 +     * SecurityManager#checkPermission(java.security.Permission)
 434.776 +     * <tt>checkPermission</tt>} method with a {@link
 434.777 +     * RuntimePermission#RuntimePermission(String)
 434.778 +     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 434.779 +     * access to the parent class loader is permitted.  If not, a
 434.780 +     * <tt>SecurityException</tt> will be thrown.  </p>
 434.781 +     *
 434.782 +     * @return  The parent <tt>ClassLoader</tt>
 434.783 +     *
 434.784 +     * @throws  SecurityException
 434.785 +     *          If a security manager exists and its <tt>checkPermission</tt>
 434.786 +     *          method doesn't allow access to this class loader's parent class
 434.787 +     *          loader.
 434.788 +     *
 434.789 +     * @since  1.2
 434.790 +     */
 434.791 +    public final ClassLoader getParent() {
 434.792 +        throw new SecurityException();
 434.793 +    }
 434.794 +
 434.795 +    /**
 434.796 +     * Returns the system class loader for delegation.  This is the default
 434.797 +     * delegation parent for new <tt>ClassLoader</tt> instances, and is
 434.798 +     * typically the class loader used to start the application.
 434.799 +     *
 434.800 +     * <p> This method is first invoked early in the runtime's startup
 434.801 +     * sequence, at which point it creates the system class loader and sets it
 434.802 +     * as the context class loader of the invoking <tt>Thread</tt>.
 434.803 +     *
 434.804 +     * <p> The default system class loader is an implementation-dependent
 434.805 +     * instance of this class.
 434.806 +     *
 434.807 +     * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
 434.808 +     * when this method is first invoked then the value of that property is
 434.809 +     * taken to be the name of a class that will be returned as the system
 434.810 +     * class loader.  The class is loaded using the default system class loader
 434.811 +     * and must define a public constructor that takes a single parameter of
 434.812 +     * type <tt>ClassLoader</tt> which is used as the delegation parent.  An
 434.813 +     * instance is then created using this constructor with the default system
 434.814 +     * class loader as the parameter.  The resulting class loader is defined
 434.815 +     * to be the system class loader.
 434.816 +     *
 434.817 +     * <p> If a security manager is present, and the invoker's class loader is
 434.818 +     * not <tt>null</tt> and the invoker's class loader is not the same as or
 434.819 +     * an ancestor of the system class loader, then this method invokes the
 434.820 +     * security manager's {@link
 434.821 +     * SecurityManager#checkPermission(java.security.Permission)
 434.822 +     * <tt>checkPermission</tt>} method with a {@link
 434.823 +     * RuntimePermission#RuntimePermission(String)
 434.824 +     * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
 434.825 +     * access to the system class loader.  If not, a
 434.826 +     * <tt>SecurityException</tt> will be thrown.  </p>
 434.827 +     *
 434.828 +     * @return  The system <tt>ClassLoader</tt> for delegation, or
 434.829 +     *          <tt>null</tt> if none
 434.830 +     *
 434.831 +     * @throws  SecurityException
 434.832 +     *          If a security manager exists and its <tt>checkPermission</tt>
 434.833 +     *          method doesn't allow access to the system class loader.
 434.834 +     *
 434.835 +     * @throws  IllegalStateException
 434.836 +     *          If invoked recursively during the construction of the class
 434.837 +     *          loader specified by the "<tt>java.system.class.loader</tt>"
 434.838 +     *          property.
 434.839 +     *
 434.840 +     * @throws  Error
 434.841 +     *          If the system property "<tt>java.system.class.loader</tt>"
 434.842 +     *          is defined but the named class could not be loaded, the
 434.843 +     *          provider class does not define the required constructor, or an
 434.844 +     *          exception is thrown by that constructor when it is invoked. The
 434.845 +     *          underlying cause of the error can be retrieved via the
 434.846 +     *          {@link Throwable#getCause()} method.
 434.847 +     *
 434.848 +     * @revised  1.4
 434.849 +     */
 434.850 +    public static ClassLoader getSystemClassLoader() {
 434.851 +        throw new SecurityException();
 434.852 +    }
 434.853 +
 434.854 +    // Returns true if the specified class loader can be found in this class
 434.855 +    // loader's delegation chain.
 434.856 +    boolean isAncestor(ClassLoader cl) {
 434.857 +        ClassLoader acl = this;
 434.858 +        do {
 434.859 +            acl = acl.parent;
 434.860 +            if (cl == acl) {
 434.861 +                return true;
 434.862 +            }
 434.863 +        } while (acl != null);
 434.864 +        return false;
 434.865 +    }
 434.866 +
 434.867 +    private boolean checkName(String name) {
 434.868 +        throw new UnsupportedOperationException(); 
 434.869 +    }
 434.870 +
 434.871 +    private Class findBootstrapClassOrNull(String name) {
 434.872 +        throw new UnsupportedOperationException();
 434.873 +    }
 434.874 +
 434.875 +    private static URL getBootstrapResource(String name) {
 434.876 +        throw new UnsupportedOperationException();
 434.877 +    }
 434.878 +
 434.879 +    private static Enumeration<URL> getBootstrapResources(String name) {
 434.880 +        URL u = Object.class.getResource("/" + name);
 434.881 +        return new OneOrZeroEnum(u);
 434.882 +    }
 434.883 +    
 434.884 +    private static class OneOrZeroEnum implements Enumeration<URL> {
 434.885 +        private URL u;
 434.886 +
 434.887 +        public OneOrZeroEnum(URL u) {
 434.888 +            this.u = u;
 434.889 +        }
 434.890 +
 434.891 +        public boolean hasMoreElements() {
 434.892 +            return u != null;
 434.893 +        }
 434.894 +
 434.895 +        public URL nextElement() {
 434.896 +            URL r = u;
 434.897 +            if (r == null) {
 434.898 +                throw new NoSuchElementException();
 434.899 +            }
 434.900 +            u = null;
 434.901 +            return r;
 434.902 +        }
 434.903 +    }
 434.904 +
 434.905 +    private static class CompoundEnumeration implements Enumeration<URL> {
 434.906 +        private URL next;
 434.907 +        private int index;
 434.908 +        private final Enumeration[] arr;
 434.909 +
 434.910 +        public CompoundEnumeration(Enumeration[] arr) {
 434.911 +            this.arr = arr;
 434.912 +            this.index = 0;
 434.913 +        }
 434.914 +
 434.915 +        public boolean hasMoreElements() {
 434.916 +            if (next == null) {
 434.917 +                if (arr[index].hasMoreElements()) {
 434.918 +                    next = (URL) arr[index].nextElement();
 434.919 +                } else {
 434.920 +                    if (index < arr.length) {
 434.921 +                        index++;
 434.922 +                        return hasMoreElements();
 434.923 +                    }
 434.924 +                }
 434.925 +            }
 434.926 +            return next != null;
 434.927 +        }
 434.928 +
 434.929 +        public URL nextElement() {
 434.930 +            if (!hasMoreElements()) {
 434.931 +                throw new NoSuchElementException();
 434.932 +            }
 434.933 +            URL r = next;
 434.934 +            next = null;
 434.935 +            return r;
 434.936 +        }
 434.937 +        
 434.938 +    }
 434.939 +}
   435.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   435.2 +++ b/rt/emul/mini/src/main/java/java/lang/ClassNotFoundException.java	Wed Feb 27 11:24:58 2013 +0100
   435.3 @@ -0,0 +1,125 @@
   435.4 +/*
   435.5 + * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
   435.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   435.7 + *
   435.8 + * This code is free software; you can redistribute it and/or modify it
   435.9 + * under the terms of the GNU General Public License version 2 only, as
  435.10 + * published by the Free Software Foundation.  Oracle designates this
  435.11 + * particular file as subject to the "Classpath" exception as provided
  435.12 + * by Oracle in the LICENSE file that accompanied this code.
  435.13 + *
  435.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  435.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  435.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  435.17 + * version 2 for more details (a copy is included in the LICENSE file that
  435.18 + * accompanied this code).
  435.19 + *
  435.20 + * You should have received a copy of the GNU General Public License version
  435.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  435.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  435.23 + *
  435.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  435.25 + * or visit www.oracle.com if you need additional information or have any
  435.26 + * questions.
  435.27 + */
  435.28 +
  435.29 +package java.lang;
  435.30 +
  435.31 +/**
  435.32 + * Thrown when an application tries to load in a class through its
  435.33 + * string name using:
  435.34 + * <ul>
  435.35 + * <li>The <code>forName</code> method in class <code>Class</code>.
  435.36 + * <li>The <code>findSystemClass</code> method in class
  435.37 + *     <code>ClassLoader</code> .
  435.38 + * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
  435.39 + * </ul>
  435.40 + * <p>
  435.41 + * but no definition for the class with the specified name could be found.
  435.42 + *
  435.43 + * <p>As of release 1.4, this exception has been retrofitted to conform to
  435.44 + * the general purpose exception-chaining mechanism.  The "optional exception
  435.45 + * that was raised while loading the class" that may be provided at
  435.46 + * construction time and accessed via the {@link #getException()} method is
  435.47 + * now known as the <i>cause</i>, and may be accessed via the {@link
  435.48 + * Throwable#getCause()} method, as well as the aforementioned "legacy method."
  435.49 + *
  435.50 + * @author  unascribed
  435.51 + * @see     java.lang.Class#forName(java.lang.String)
  435.52 + * @see     java.lang.ClassLoader#findSystemClass(java.lang.String)
  435.53 + * @see     java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  435.54 + * @since   JDK1.0
  435.55 + */
  435.56 +public class ClassNotFoundException extends ReflectiveOperationException {
  435.57 +    /**
  435.58 +     * use serialVersionUID from JDK 1.1.X for interoperability
  435.59 +     */
  435.60 +     private static final long serialVersionUID = 9176873029745254542L;
  435.61 +
  435.62 +    /**
  435.63 +     * This field holds the exception ex if the
  435.64 +     * ClassNotFoundException(String s, Throwable ex) constructor was
  435.65 +     * used to instantiate the object
  435.66 +     * @serial
  435.67 +     * @since 1.2
  435.68 +     */
  435.69 +    private Throwable ex;
  435.70 +
  435.71 +    /**
  435.72 +     * Constructs a <code>ClassNotFoundException</code> with no detail message.
  435.73 +     */
  435.74 +    public ClassNotFoundException() {
  435.75 +        super((Throwable)null);  // Disallow initCause
  435.76 +    }
  435.77 +
  435.78 +    /**
  435.79 +     * Constructs a <code>ClassNotFoundException</code> with the
  435.80 +     * specified detail message.
  435.81 +     *
  435.82 +     * @param   s   the detail message.
  435.83 +     */
  435.84 +    public ClassNotFoundException(String s) {
  435.85 +        super(s, null);  //  Disallow initCause
  435.86 +    }
  435.87 +
  435.88 +    /**
  435.89 +     * Constructs a <code>ClassNotFoundException</code> with the
  435.90 +     * specified detail message and optional exception that was
  435.91 +     * raised while loading the class.
  435.92 +     *
  435.93 +     * @param s the detail message
  435.94 +     * @param ex the exception that was raised while loading the class
  435.95 +     * @since 1.2
  435.96 +     */
  435.97 +    public ClassNotFoundException(String s, Throwable ex) {
  435.98 +        super(s, null);  //  Disallow initCause
  435.99 +        this.ex = ex;
 435.100 +    }
 435.101 +
 435.102 +    /**
 435.103 +     * Returns the exception that was raised if an error occurred while
 435.104 +     * attempting to load the class. Otherwise, returns <tt>null</tt>.
 435.105 +     *
 435.106 +     * <p>This method predates the general-purpose exception chaining facility.
 435.107 +     * The {@link Throwable#getCause()} method is now the preferred means of
 435.108 +     * obtaining this information.
 435.109 +     *
 435.110 +     * @return the <code>Exception</code> that was raised while loading a class
 435.111 +     * @since 1.2
 435.112 +     */
 435.113 +    public Throwable getException() {
 435.114 +        return ex;
 435.115 +    }
 435.116 +
 435.117 +    /**
 435.118 +     * Returns the cause of this exception (the exception that was raised
 435.119 +     * if an error occurred while attempting to load the class; otherwise
 435.120 +     * <tt>null</tt>).
 435.121 +     *
 435.122 +     * @return  the cause of this exception.
 435.123 +     * @since   1.4
 435.124 +     */
 435.125 +    public Throwable getCause() {
 435.126 +        return ex;
 435.127 +    }
 435.128 +}
   436.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   436.2 +++ b/rt/emul/mini/src/main/java/java/lang/CloneNotSupportedException.java	Wed Feb 27 11:24:58 2013 +0100
   436.3 @@ -0,0 +1,65 @@
   436.4 +/*
   436.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   436.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   436.7 + *
   436.8 + * This code is free software; you can redistribute it and/or modify it
   436.9 + * under the terms of the GNU General Public License version 2 only, as
  436.10 + * published by the Free Software Foundation.  Oracle designates this
  436.11 + * particular file as subject to the "Classpath" exception as provided
  436.12 + * by Oracle in the LICENSE file that accompanied this code.
  436.13 + *
  436.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  436.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  436.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  436.17 + * version 2 for more details (a copy is included in the LICENSE file that
  436.18 + * accompanied this code).
  436.19 + *
  436.20 + * You should have received a copy of the GNU General Public License version
  436.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  436.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  436.23 + *
  436.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  436.25 + * or visit www.oracle.com if you need additional information or have any
  436.26 + * questions.
  436.27 + */
  436.28 +
  436.29 +package java.lang;
  436.30 +
  436.31 +/**
  436.32 + * Thrown to indicate that the <code>clone</code> method in class
  436.33 + * <code>Object</code> has been called to clone an object, but that
  436.34 + * the object's class does not implement the <code>Cloneable</code>
  436.35 + * interface.
  436.36 + * <p>
  436.37 + * Applications that override the <code>clone</code> method can also
  436.38 + * throw this exception to indicate that an object could not or
  436.39 + * should not be cloned.
  436.40 + *
  436.41 + * @author  unascribed
  436.42 + * @see     java.lang.Cloneable
  436.43 + * @see     java.lang.Object#clone()
  436.44 + * @since   JDK1.0
  436.45 + */
  436.46 +
  436.47 +public
  436.48 +class CloneNotSupportedException extends Exception {
  436.49 +    private static final long serialVersionUID = 5195511250079656443L;
  436.50 +
  436.51 +    /**
  436.52 +     * Constructs a <code>CloneNotSupportedException</code> with no
  436.53 +     * detail message.
  436.54 +     */
  436.55 +    public CloneNotSupportedException() {
  436.56 +        super();
  436.57 +    }
  436.58 +
  436.59 +    /**
  436.60 +     * Constructs a <code>CloneNotSupportedException</code> with the
  436.61 +     * specified detail message.
  436.62 +     *
  436.63 +     * @param   s   the detail message.
  436.64 +     */
  436.65 +    public CloneNotSupportedException(String s) {
  436.66 +        super(s);
  436.67 +    }
  436.68 +}
   437.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   437.2 +++ b/rt/emul/mini/src/main/java/java/lang/Cloneable.java	Wed Feb 27 11:24:58 2013 +0100
   437.3 @@ -0,0 +1,54 @@
   437.4 +/*
   437.5 + * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
   437.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   437.7 + *
   437.8 + * This code is free software; you can redistribute it and/or modify it
   437.9 + * under the terms of the GNU General Public License version 2 only, as
  437.10 + * published by the Free Software Foundation.  Oracle designates this
  437.11 + * particular file as subject to the "Classpath" exception as provided
  437.12 + * by Oracle in the LICENSE file that accompanied this code.
  437.13 + *
  437.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  437.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  437.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  437.17 + * version 2 for more details (a copy is included in the LICENSE file that
  437.18 + * accompanied this code).
  437.19 + *
  437.20 + * You should have received a copy of the GNU General Public License version
  437.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  437.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  437.23 + *
  437.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  437.25 + * or visit www.oracle.com if you need additional information or have any
  437.26 + * questions.
  437.27 + */
  437.28 +
  437.29 +package java.lang;
  437.30 +
  437.31 +/**
  437.32 + * A class implements the <code>Cloneable</code> interface to
  437.33 + * indicate to the {@link java.lang.Object#clone()} method that it
  437.34 + * is legal for that method to make a
  437.35 + * field-for-field copy of instances of that class.
  437.36 + * <p>
  437.37 + * Invoking Object's clone method on an instance that does not implement the
  437.38 + * <code>Cloneable</code> interface results in the exception
  437.39 + * <code>CloneNotSupportedException</code> being thrown.
  437.40 + * <p>
  437.41 + * By convention, classes that implement this interface should override
  437.42 + * <tt>Object.clone</tt> (which is protected) with a public method.
  437.43 + * See {@link java.lang.Object#clone()} for details on overriding this
  437.44 + * method.
  437.45 + * <p>
  437.46 + * Note that this interface does <i>not</i> contain the <tt>clone</tt> method.
  437.47 + * Therefore, it is not possible to clone an object merely by virtue of the
  437.48 + * fact that it implements this interface.  Even if the clone method is invoked
  437.49 + * reflectively, there is no guarantee that it will succeed.
  437.50 + *
  437.51 + * @author  unascribed
  437.52 + * @see     java.lang.CloneNotSupportedException
  437.53 + * @see     java.lang.Object#clone()
  437.54 + * @since   JDK1.0
  437.55 + */
  437.56 +public interface Cloneable {
  437.57 +}
   438.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   438.2 +++ b/rt/emul/mini/src/main/java/java/lang/Comparable.java	Wed Feb 27 11:24:58 2013 +0100
   438.3 @@ -0,0 +1,137 @@
   438.4 +/*
   438.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
   438.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   438.7 + *
   438.8 + * This code is free software; you can redistribute it and/or modify it
   438.9 + * under the terms of the GNU General Public License version 2 only, as
  438.10 + * published by the Free Software Foundation.  Oracle designates this
  438.11 + * particular file as subject to the "Classpath" exception as provided
  438.12 + * by Oracle in the LICENSE file that accompanied this code.
  438.13 + *
  438.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  438.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  438.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  438.17 + * version 2 for more details (a copy is included in the LICENSE file that
  438.18 + * accompanied this code).
  438.19 + *
  438.20 + * You should have received a copy of the GNU General Public License version
  438.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  438.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  438.23 + *
  438.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  438.25 + * or visit www.oracle.com if you need additional information or have any
  438.26 + * questions.
  438.27 + */
  438.28 +
  438.29 +package java.lang;
  438.30 +
  438.31 +/**
  438.32 + * This interface imposes a total ordering on the objects of each class that
  438.33 + * implements it.  This ordering is referred to as the class's <i>natural
  438.34 + * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
  438.35 + * its <i>natural comparison method</i>.<p>
  438.36 + *
  438.37 + * Lists (and arrays) of objects that implement this interface can be sorted
  438.38 + * automatically by {@link Collections#sort(List) Collections.sort} (and
  438.39 + * {@link Arrays#sort(Object[]) Arrays.sort}).  Objects that implement this
  438.40 + * interface can be used as keys in a {@linkplain SortedMap sorted map} or as
  438.41 + * elements in a {@linkplain SortedSet sorted set}, without the need to
  438.42 + * specify a {@linkplain Comparator comparator}.<p>
  438.43 + *
  438.44 + * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
  438.45 + * with equals</i> if and only if <tt>e1.compareTo(e2) == 0</tt> has
  438.46 + * the same boolean value as <tt>e1.equals(e2)</tt> for every
  438.47 + * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>.  Note that <tt>null</tt>
  438.48 + * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
  438.49 + * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
  438.50 + * returns <tt>false</tt>.<p>
  438.51 + *
  438.52 + * It is strongly recommended (though not required) that natural orderings be
  438.53 + * consistent with equals.  This is so because sorted sets (and sorted maps)
  438.54 + * without explicit comparators behave "strangely" when they are used with
  438.55 + * elements (or keys) whose natural ordering is inconsistent with equals.  In
  438.56 + * particular, such a sorted set (or sorted map) violates the general contract
  438.57 + * for set (or map), which is defined in terms of the <tt>equals</tt>
  438.58 + * method.<p>
  438.59 + *
  438.60 + * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
  438.61 + * <tt>(!a.equals(b) && a.compareTo(b) == 0)</tt> to a sorted
  438.62 + * set that does not use an explicit comparator, the second <tt>add</tt>
  438.63 + * operation returns false (and the size of the sorted set does not increase)
  438.64 + * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
  438.65 + * perspective.<p>
  438.66 + *
  438.67 + * Virtually all Java core classes that implement <tt>Comparable</tt> have natural
  438.68 + * orderings that are consistent with equals.  One exception is
  438.69 + * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
  438.70 + * <tt>BigDecimal</tt> objects with equal values and different precisions
  438.71 + * (such as 4.0 and 4.00).<p>
  438.72 + *
  438.73 + * For the mathematically inclined, the <i>relation</i> that defines
  438.74 + * the natural ordering on a given class C is:<pre>
  438.75 + *       {(x, y) such that x.compareTo(y) &lt;= 0}.
  438.76 + * </pre> The <i>quotient</i> for this total order is: <pre>
  438.77 + *       {(x, y) such that x.compareTo(y) == 0}.
  438.78 + * </pre>
  438.79 + *
  438.80 + * It follows immediately from the contract for <tt>compareTo</tt> that the
  438.81 + * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
  438.82 + * natural ordering is a <i>total order</i> on <tt>C</tt>.  When we say that a
  438.83 + * class's natural ordering is <i>consistent with equals</i>, we mean that the
  438.84 + * quotient for the natural ordering is the equivalence relation defined by
  438.85 + * the class's {@link Object#equals(Object) equals(Object)} method:<pre>
  438.86 + *     {(x, y) such that x.equals(y)}. </pre><p>
  438.87 + *
  438.88 + * This interface is a member of the
  438.89 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  438.90 + * Java Collections Framework</a>.
  438.91 + *
  438.92 + * @param <T> the type of objects that this object may be compared to
  438.93 + *
  438.94 + * @author  Josh Bloch
  438.95 + * @see java.util.Comparator
  438.96 + * @since 1.2
  438.97 + */
  438.98 +
  438.99 +public interface Comparable<T> {
 438.100 +    /**
 438.101 +     * Compares this object with the specified object for order.  Returns a
 438.102 +     * negative integer, zero, or a positive integer as this object is less
 438.103 +     * than, equal to, or greater than the specified object.
 438.104 +     *
 438.105 +     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
 438.106 +     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 438.107 +     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
 438.108 +     * <tt>y.compareTo(x)</tt> throws an exception.)
 438.109 +     *
 438.110 +     * <p>The implementor must also ensure that the relation is transitive:
 438.111 +     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
 438.112 +     * <tt>x.compareTo(z)&gt;0</tt>.
 438.113 +     *
 438.114 +     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
 438.115 +     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
 438.116 +     * all <tt>z</tt>.
 438.117 +     *
 438.118 +     * <p>It is strongly recommended, but <i>not</i> strictly required that
 438.119 +     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
 438.120 +     * class that implements the <tt>Comparable</tt> interface and violates
 438.121 +     * this condition should clearly indicate this fact.  The recommended
 438.122 +     * language is "Note: this class has a natural ordering that is
 438.123 +     * inconsistent with equals."
 438.124 +     *
 438.125 +     * <p>In the foregoing description, the notation
 438.126 +     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 438.127 +     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 438.128 +     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 438.129 +     * <i>expression</i> is negative, zero or positive.
 438.130 +     *
 438.131 +     * @param   o the object to be compared.
 438.132 +     * @return  a negative integer, zero, or a positive integer as this object
 438.133 +     *          is less than, equal to, or greater than the specified object.
 438.134 +     *
 438.135 +     * @throws NullPointerException if the specified object is null
 438.136 +     * @throws ClassCastException if the specified object's type prevents it
 438.137 +     *         from being compared to this object.
 438.138 +     */
 438.139 +    public int compareTo(T o);
 438.140 +}
   439.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   439.2 +++ b/rt/emul/mini/src/main/java/java/lang/Deprecated.java	Wed Feb 27 11:24:58 2013 +0100
   439.3 @@ -0,0 +1,44 @@
   439.4 +/*
   439.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   439.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   439.7 + *
   439.8 + * This code is free software; you can redistribute it and/or modify it
   439.9 + * under the terms of the GNU General Public License version 2 only, as
  439.10 + * published by the Free Software Foundation.  Oracle designates this
  439.11 + * particular file as subject to the "Classpath" exception as provided
  439.12 + * by Oracle in the LICENSE file that accompanied this code.
  439.13 + *
  439.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  439.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  439.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  439.17 + * version 2 for more details (a copy is included in the LICENSE file that
  439.18 + * accompanied this code).
  439.19 + *
  439.20 + * You should have received a copy of the GNU General Public License version
  439.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  439.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  439.23 + *
  439.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  439.25 + * or visit www.oracle.com if you need additional information or have any
  439.26 + * questions.
  439.27 + */
  439.28 +
  439.29 +package java.lang;
  439.30 +
  439.31 +import java.lang.annotation.*;
  439.32 +import static java.lang.annotation.ElementType.*;
  439.33 +
  439.34 +/**
  439.35 + * A program element annotated &#64;Deprecated is one that programmers
  439.36 + * are discouraged from using, typically because it is dangerous,
  439.37 + * or because a better alternative exists.  Compilers warn when a
  439.38 + * deprecated program element is used or overridden in non-deprecated code.
  439.39 + *
  439.40 + * @author  Neal Gafter
  439.41 + * @since 1.5
  439.42 + */
  439.43 +@Documented
  439.44 +@Retention(RetentionPolicy.RUNTIME)
  439.45 +@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
  439.46 +public @interface Deprecated {
  439.47 +}
   440.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   440.2 +++ b/rt/emul/mini/src/main/java/java/lang/Double.java	Wed Feb 27 11:24:58 2013 +0100
   440.3 @@ -0,0 +1,994 @@
   440.4 +/*
   440.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   440.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   440.7 + *
   440.8 + * This code is free software; you can redistribute it and/or modify it
   440.9 + * under the terms of the GNU General Public License version 2 only, as
  440.10 + * published by the Free Software Foundation.  Oracle designates this
  440.11 + * particular file as subject to the "Classpath" exception as provided
  440.12 + * by Oracle in the LICENSE file that accompanied this code.
  440.13 + *
  440.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  440.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  440.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  440.17 + * version 2 for more details (a copy is included in the LICENSE file that
  440.18 + * accompanied this code).
  440.19 + *
  440.20 + * You should have received a copy of the GNU General Public License version
  440.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  440.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  440.23 + *
  440.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  440.25 + * or visit www.oracle.com if you need additional information or have any
  440.26 + * questions.
  440.27 + */
  440.28 +
  440.29 +package java.lang;
  440.30 +
  440.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  440.32 +
  440.33 +/**
  440.34 + * The {@code Double} class wraps a value of the primitive type
  440.35 + * {@code double} in an object. An object of type
  440.36 + * {@code Double} contains a single field whose type is
  440.37 + * {@code double}.
  440.38 + *
  440.39 + * <p>In addition, this class provides several methods for converting a
  440.40 + * {@code double} to a {@code String} and a
  440.41 + * {@code String} to a {@code double}, as well as other
  440.42 + * constants and methods useful when dealing with a
  440.43 + * {@code double}.
  440.44 + *
  440.45 + * @author  Lee Boynton
  440.46 + * @author  Arthur van Hoff
  440.47 + * @author  Joseph D. Darcy
  440.48 + * @since JDK1.0
  440.49 + */
  440.50 +public final class Double extends Number implements Comparable<Double> {
  440.51 +    /**
  440.52 +     * A constant holding the positive infinity of type
  440.53 +     * {@code double}. It is equal to the value returned by
  440.54 +     * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
  440.55 +     */
  440.56 +    public static final double POSITIVE_INFINITY = 1.0 / 0.0;
  440.57 +
  440.58 +    /**
  440.59 +     * A constant holding the negative infinity of type
  440.60 +     * {@code double}. It is equal to the value returned by
  440.61 +     * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
  440.62 +     */
  440.63 +    public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
  440.64 +
  440.65 +    /**
  440.66 +     * A constant holding a Not-a-Number (NaN) value of type
  440.67 +     * {@code double}. It is equivalent to the value returned by
  440.68 +     * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
  440.69 +     */
  440.70 +    public static final double NaN = 0.0d / 0.0;
  440.71 +
  440.72 +    /**
  440.73 +     * A constant holding the largest positive finite value of type
  440.74 +     * {@code double},
  440.75 +     * (2-2<sup>-52</sup>)&middot;2<sup>1023</sup>.  It is equal to
  440.76 +     * the hexadecimal floating-point literal
  440.77 +     * {@code 0x1.fffffffffffffP+1023} and also equal to
  440.78 +     * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
  440.79 +     */
  440.80 +    public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
  440.81 +
  440.82 +    /**
  440.83 +     * A constant holding the smallest positive normal value of type
  440.84 +     * {@code double}, 2<sup>-1022</sup>.  It is equal to the
  440.85 +     * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
  440.86 +     * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
  440.87 +     *
  440.88 +     * @since 1.6
  440.89 +     */
  440.90 +    public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
  440.91 +
  440.92 +    /**
  440.93 +     * A constant holding the smallest positive nonzero value of type
  440.94 +     * {@code double}, 2<sup>-1074</sup>. It is equal to the
  440.95 +     * hexadecimal floating-point literal
  440.96 +     * {@code 0x0.0000000000001P-1022} and also equal to
  440.97 +     * {@code Double.longBitsToDouble(0x1L)}.
  440.98 +     */
  440.99 +    public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
 440.100 +
 440.101 +    /**
 440.102 +     * Maximum exponent a finite {@code double} variable may have.
 440.103 +     * It is equal to the value returned by
 440.104 +     * {@code Math.getExponent(Double.MAX_VALUE)}.
 440.105 +     *
 440.106 +     * @since 1.6
 440.107 +     */
 440.108 +    public static final int MAX_EXPONENT = 1023;
 440.109 +
 440.110 +    /**
 440.111 +     * Minimum exponent a normalized {@code double} variable may
 440.112 +     * have.  It is equal to the value returned by
 440.113 +     * {@code Math.getExponent(Double.MIN_NORMAL)}.
 440.114 +     *
 440.115 +     * @since 1.6
 440.116 +     */
 440.117 +    public static final int MIN_EXPONENT = -1022;
 440.118 +
 440.119 +    /**
 440.120 +     * The number of bits used to represent a {@code double} value.
 440.121 +     *
 440.122 +     * @since 1.5
 440.123 +     */
 440.124 +    public static final int SIZE = 64;
 440.125 +
 440.126 +    /**
 440.127 +     * The {@code Class} instance representing the primitive type
 440.128 +     * {@code double}.
 440.129 +     *
 440.130 +     * @since JDK1.1
 440.131 +     */
 440.132 +    public static final Class<Double>   TYPE = (Class<Double>) Class.getPrimitiveClass("double");
 440.133 +
 440.134 +    /**
 440.135 +     * Returns a string representation of the {@code double}
 440.136 +     * argument. All characters mentioned below are ASCII characters.
 440.137 +     * <ul>
 440.138 +     * <li>If the argument is NaN, the result is the string
 440.139 +     *     "{@code NaN}".
 440.140 +     * <li>Otherwise, the result is a string that represents the sign and
 440.141 +     * magnitude (absolute value) of the argument. If the sign is negative,
 440.142 +     * the first character of the result is '{@code -}'
 440.143 +     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 440.144 +     * appears in the result. As for the magnitude <i>m</i>:
 440.145 +     * <ul>
 440.146 +     * <li>If <i>m</i> is infinity, it is represented by the characters
 440.147 +     * {@code "Infinity"}; thus, positive infinity produces the result
 440.148 +     * {@code "Infinity"} and negative infinity produces the result
 440.149 +     * {@code "-Infinity"}.
 440.150 +     *
 440.151 +     * <li>If <i>m</i> is zero, it is represented by the characters
 440.152 +     * {@code "0.0"}; thus, negative zero produces the result
 440.153 +     * {@code "-0.0"} and positive zero produces the result
 440.154 +     * {@code "0.0"}.
 440.155 +     *
 440.156 +     * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
 440.157 +     * than 10<sup>7</sup>, then it is represented as the integer part of
 440.158 +     * <i>m</i>, in decimal form with no leading zeroes, followed by
 440.159 +     * '{@code .}' (<code>'&#92;u002E'</code>), followed by one or
 440.160 +     * more decimal digits representing the fractional part of <i>m</i>.
 440.161 +     *
 440.162 +     * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 440.163 +     * equal to 10<sup>7</sup>, then it is represented in so-called
 440.164 +     * "computerized scientific notation." Let <i>n</i> be the unique
 440.165 +     * integer such that 10<sup><i>n</i></sup> &le; <i>m</i> {@literal <}
 440.166 +     * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
 440.167 +     * mathematically exact quotient of <i>m</i> and
 440.168 +     * 10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10. The
 440.169 +     * magnitude is then represented as the integer part of <i>a</i>,
 440.170 +     * as a single decimal digit, followed by '{@code .}'
 440.171 +     * (<code>'&#92;u002E'</code>), followed by decimal digits
 440.172 +     * representing the fractional part of <i>a</i>, followed by the
 440.173 +     * letter '{@code E}' (<code>'&#92;u0045'</code>), followed
 440.174 +     * by a representation of <i>n</i> as a decimal integer, as
 440.175 +     * produced by the method {@link Integer#toString(int)}.
 440.176 +     * </ul>
 440.177 +     * </ul>
 440.178 +     * How many digits must be printed for the fractional part of
 440.179 +     * <i>m</i> or <i>a</i>? There must be at least one digit to represent
 440.180 +     * the fractional part, and beyond that as many, but only as many, more
 440.181 +     * digits as are needed to uniquely distinguish the argument value from
 440.182 +     * adjacent values of type {@code double}. That is, suppose that
 440.183 +     * <i>x</i> is the exact mathematical value represented by the decimal
 440.184 +     * representation produced by this method for a finite nonzero argument
 440.185 +     * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
 440.186 +     * to <i>x</i>; or if two {@code double} values are equally close
 440.187 +     * to <i>x</i>, then <i>d</i> must be one of them and the least
 440.188 +     * significant bit of the significand of <i>d</i> must be {@code 0}.
 440.189 +     *
 440.190 +     * <p>To create localized string representations of a floating-point
 440.191 +     * value, use subclasses of {@link java.text.NumberFormat}.
 440.192 +     *
 440.193 +     * @param   d   the {@code double} to be converted.
 440.194 +     * @return a string representation of the argument.
 440.195 +     */
 440.196 +    @JavaScriptBody(args="d", body="var r = d.toString();"
 440.197 +        + "if (isFinite(d) && (r.indexOf('.') === -1)) r = r + '.0';"
 440.198 +        + "return r;")
 440.199 +    public static String toString(double d) {
 440.200 +        throw new UnsupportedOperationException();
 440.201 +    }
 440.202 +
 440.203 +    /**
 440.204 +     * Returns a hexadecimal string representation of the
 440.205 +     * {@code double} argument. All characters mentioned below
 440.206 +     * are ASCII characters.
 440.207 +     *
 440.208 +     * <ul>
 440.209 +     * <li>If the argument is NaN, the result is the string
 440.210 +     *     "{@code NaN}".
 440.211 +     * <li>Otherwise, the result is a string that represents the sign
 440.212 +     * and magnitude of the argument. If the sign is negative, the
 440.213 +     * first character of the result is '{@code -}'
 440.214 +     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign
 440.215 +     * character appears in the result. As for the magnitude <i>m</i>:
 440.216 +     *
 440.217 +     * <ul>
 440.218 +     * <li>If <i>m</i> is infinity, it is represented by the string
 440.219 +     * {@code "Infinity"}; thus, positive infinity produces the
 440.220 +     * result {@code "Infinity"} and negative infinity produces
 440.221 +     * the result {@code "-Infinity"}.
 440.222 +     *
 440.223 +     * <li>If <i>m</i> is zero, it is represented by the string
 440.224 +     * {@code "0x0.0p0"}; thus, negative zero produces the result
 440.225 +     * {@code "-0x0.0p0"} and positive zero produces the result
 440.226 +     * {@code "0x0.0p0"}.
 440.227 +     *
 440.228 +     * <li>If <i>m</i> is a {@code double} value with a
 440.229 +     * normalized representation, substrings are used to represent the
 440.230 +     * significand and exponent fields.  The significand is
 440.231 +     * represented by the characters {@code "0x1."}
 440.232 +     * followed by a lowercase hexadecimal representation of the rest
 440.233 +     * of the significand as a fraction.  Trailing zeros in the
 440.234 +     * hexadecimal representation are removed unless all the digits
 440.235 +     * are zero, in which case a single zero is used. Next, the
 440.236 +     * exponent is represented by {@code "p"} followed
 440.237 +     * by a decimal string of the unbiased exponent as if produced by
 440.238 +     * a call to {@link Integer#toString(int) Integer.toString} on the
 440.239 +     * exponent value.
 440.240 +     *
 440.241 +     * <li>If <i>m</i> is a {@code double} value with a subnormal
 440.242 +     * representation, the significand is represented by the
 440.243 +     * characters {@code "0x0."} followed by a
 440.244 +     * hexadecimal representation of the rest of the significand as a
 440.245 +     * fraction.  Trailing zeros in the hexadecimal representation are
 440.246 +     * removed. Next, the exponent is represented by
 440.247 +     * {@code "p-1022"}.  Note that there must be at
 440.248 +     * least one nonzero digit in a subnormal significand.
 440.249 +     *
 440.250 +     * </ul>
 440.251 +     *
 440.252 +     * </ul>
 440.253 +     *
 440.254 +     * <table border>
 440.255 +     * <caption><h3>Examples</h3></caption>
 440.256 +     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 440.257 +     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 440.258 +     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 440.259 +     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 440.260 +     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 440.261 +     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 440.262 +     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 440.263 +     * <tr><td>{@code Double.MAX_VALUE}</td>
 440.264 +     *     <td>{@code 0x1.fffffffffffffp1023}</td>
 440.265 +     * <tr><td>{@code Minimum Normal Value}</td>
 440.266 +     *     <td>{@code 0x1.0p-1022}</td>
 440.267 +     * <tr><td>{@code Maximum Subnormal Value}</td>
 440.268 +     *     <td>{@code 0x0.fffffffffffffp-1022}</td>
 440.269 +     * <tr><td>{@code Double.MIN_VALUE}</td>
 440.270 +     *     <td>{@code 0x0.0000000000001p-1022}</td>
 440.271 +     * </table>
 440.272 +     * @param   d   the {@code double} to be converted.
 440.273 +     * @return a hex string representation of the argument.
 440.274 +     * @since 1.5
 440.275 +     * @author Joseph D. Darcy
 440.276 +     */
 440.277 +    public static String toHexString(double d) {
 440.278 +        throw new UnsupportedOperationException();
 440.279 +//        /*
 440.280 +//         * Modeled after the "a" conversion specifier in C99, section
 440.281 +//         * 7.19.6.1; however, the output of this method is more
 440.282 +//         * tightly specified.
 440.283 +//         */
 440.284 +//        if (!FpUtils.isFinite(d) )
 440.285 +//            // For infinity and NaN, use the decimal output.
 440.286 +//            return Double.toString(d);
 440.287 +//        else {
 440.288 +//            // Initialized to maximum size of output.
 440.289 +//            StringBuffer answer = new StringBuffer(24);
 440.290 +//
 440.291 +//            if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
 440.292 +//                answer.append("-");                  // so append sign info
 440.293 +//
 440.294 +//            answer.append("0x");
 440.295 +//
 440.296 +//            d = Math.abs(d);
 440.297 +//
 440.298 +//            if(d == 0.0) {
 440.299 +//                answer.append("0.0p0");
 440.300 +//            }
 440.301 +//            else {
 440.302 +//                boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
 440.303 +//
 440.304 +//                // Isolate significand bits and OR in a high-order bit
 440.305 +//                // so that the string representation has a known
 440.306 +//                // length.
 440.307 +//                long signifBits = (Double.doubleToLongBits(d)
 440.308 +//                                   & DoubleConsts.SIGNIF_BIT_MASK) |
 440.309 +//                    0x1000000000000000L;
 440.310 +//
 440.311 +//                // Subnormal values have a 0 implicit bit; normal
 440.312 +//                // values have a 1 implicit bit.
 440.313 +//                answer.append(subnormal ? "0." : "1.");
 440.314 +//
 440.315 +//                // Isolate the low-order 13 digits of the hex
 440.316 +//                // representation.  If all the digits are zero,
 440.317 +//                // replace with a single 0; otherwise, remove all
 440.318 +//                // trailing zeros.
 440.319 +//                String signif = Long.toHexString(signifBits).substring(3,16);
 440.320 +//                answer.append(signif.equals("0000000000000") ? // 13 zeros
 440.321 +//                              "0":
 440.322 +//                              signif.replaceFirst("0{1,12}$", ""));
 440.323 +//
 440.324 +//                // If the value is subnormal, use the E_min exponent
 440.325 +//                // value for double; otherwise, extract and report d's
 440.326 +//                // exponent (the representation of a subnormal uses
 440.327 +//                // E_min -1).
 440.328 +//                answer.append("p" + (subnormal ?
 440.329 +//                               DoubleConsts.MIN_EXPONENT:
 440.330 +//                               FpUtils.getExponent(d) ));
 440.331 +//            }
 440.332 +//            return answer.toString();
 440.333 +//        }
 440.334 +    }
 440.335 +
 440.336 +    /**
 440.337 +     * Returns a {@code Double} object holding the
 440.338 +     * {@code double} value represented by the argument string
 440.339 +     * {@code s}.
 440.340 +     *
 440.341 +     * <p>If {@code s} is {@code null}, then a
 440.342 +     * {@code NullPointerException} is thrown.
 440.343 +     *
 440.344 +     * <p>Leading and trailing whitespace characters in {@code s}
 440.345 +     * are ignored.  Whitespace is removed as if by the {@link
 440.346 +     * String#trim} method; that is, both ASCII space and control
 440.347 +     * characters are removed. The rest of {@code s} should
 440.348 +     * constitute a <i>FloatValue</i> as described by the lexical
 440.349 +     * syntax rules:
 440.350 +     *
 440.351 +     * <blockquote>
 440.352 +     * <dl>
 440.353 +     * <dt><i>FloatValue:</i>
 440.354 +     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 440.355 +     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 440.356 +     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 440.357 +     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 440.358 +     * <dd><i>SignedInteger</i>
 440.359 +     * </dl>
 440.360 +     *
 440.361 +     * <p>
 440.362 +     *
 440.363 +     * <dl>
 440.364 +     * <dt><i>HexFloatingPointLiteral</i>:
 440.365 +     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 440.366 +     * </dl>
 440.367 +     *
 440.368 +     * <p>
 440.369 +     *
 440.370 +     * <dl>
 440.371 +     * <dt><i>HexSignificand:</i>
 440.372 +     * <dd><i>HexNumeral</i>
 440.373 +     * <dd><i>HexNumeral</i> {@code .}
 440.374 +     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 440.375 +     *     </i>{@code .}<i> HexDigits</i>
 440.376 +     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 440.377 +     *     </i>{@code .} <i>HexDigits</i>
 440.378 +     * </dl>
 440.379 +     *
 440.380 +     * <p>
 440.381 +     *
 440.382 +     * <dl>
 440.383 +     * <dt><i>BinaryExponent:</i>
 440.384 +     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 440.385 +     * </dl>
 440.386 +     *
 440.387 +     * <p>
 440.388 +     *
 440.389 +     * <dl>
 440.390 +     * <dt><i>BinaryExponentIndicator:</i>
 440.391 +     * <dd>{@code p}
 440.392 +     * <dd>{@code P}
 440.393 +     * </dl>
 440.394 +     *
 440.395 +     * </blockquote>
 440.396 +     *
 440.397 +     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 440.398 +     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 440.399 +     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 440.400 +     * sections of
 440.401 +     * <cite>The Java&trade; Language Specification</cite>,
 440.402 +     * except that underscores are not accepted between digits.
 440.403 +     * If {@code s} does not have the form of
 440.404 +     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 440.405 +     * is thrown. Otherwise, {@code s} is regarded as
 440.406 +     * representing an exact decimal value in the usual
 440.407 +     * "computerized scientific notation" or as an exact
 440.408 +     * hexadecimal value; this exact numerical value is then
 440.409 +     * conceptually converted to an "infinitely precise"
 440.410 +     * binary value that is then rounded to type {@code double}
 440.411 +     * by the usual round-to-nearest rule of IEEE 754 floating-point
 440.412 +     * arithmetic, which includes preserving the sign of a zero
 440.413 +     * value.
 440.414 +     *
 440.415 +     * Note that the round-to-nearest rule also implies overflow and
 440.416 +     * underflow behaviour; if the exact value of {@code s} is large
 440.417 +     * enough in magnitude (greater than or equal to ({@link
 440.418 +     * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
 440.419 +     * rounding to {@code double} will result in an infinity and if the
 440.420 +     * exact value of {@code s} is small enough in magnitude (less
 440.421 +     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 440.422 +     * result in a zero.
 440.423 +     *
 440.424 +     * Finally, after rounding a {@code Double} object representing
 440.425 +     * this {@code double} value is returned.
 440.426 +     *
 440.427 +     * <p> To interpret localized string representations of a
 440.428 +     * floating-point value, use subclasses of {@link
 440.429 +     * java.text.NumberFormat}.
 440.430 +     *
 440.431 +     * <p>Note that trailing format specifiers, specifiers that
 440.432 +     * determine the type of a floating-point literal
 440.433 +     * ({@code 1.0f} is a {@code float} value;
 440.434 +     * {@code 1.0d} is a {@code double} value), do
 440.435 +     * <em>not</em> influence the results of this method.  In other
 440.436 +     * words, the numerical value of the input string is converted
 440.437 +     * directly to the target floating-point type.  The two-step
 440.438 +     * sequence of conversions, string to {@code float} followed
 440.439 +     * by {@code float} to {@code double}, is <em>not</em>
 440.440 +     * equivalent to converting a string directly to
 440.441 +     * {@code double}. For example, the {@code float}
 440.442 +     * literal {@code 0.1f} is equal to the {@code double}
 440.443 +     * value {@code 0.10000000149011612}; the {@code float}
 440.444 +     * literal {@code 0.1f} represents a different numerical
 440.445 +     * value than the {@code double} literal
 440.446 +     * {@code 0.1}. (The numerical value 0.1 cannot be exactly
 440.447 +     * represented in a binary floating-point number.)
 440.448 +     *
 440.449 +     * <p>To avoid calling this method on an invalid string and having
 440.450 +     * a {@code NumberFormatException} be thrown, the regular
 440.451 +     * expression below can be used to screen the input string:
 440.452 +     *
 440.453 +     * <code>
 440.454 +     * <pre>
 440.455 +     *  final String Digits     = "(\\p{Digit}+)";
 440.456 +     *  final String HexDigits  = "(\\p{XDigit}+)";
 440.457 +     *  // an exponent is 'e' or 'E' followed by an optionally
 440.458 +     *  // signed decimal integer.
 440.459 +     *  final String Exp        = "[eE][+-]?"+Digits;
 440.460 +     *  final String fpRegex    =
 440.461 +     *      ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
 440.462 +     *       "[+-]?(" + // Optional sign character
 440.463 +     *       "NaN|" +           // "NaN" string
 440.464 +     *       "Infinity|" +      // "Infinity" string
 440.465 +     *
 440.466 +     *       // A decimal floating-point string representing a finite positive
 440.467 +     *       // number without a leading sign has at most five basic pieces:
 440.468 +     *       // Digits . Digits ExponentPart FloatTypeSuffix
 440.469 +     *       //
 440.470 +     *       // Since this method allows integer-only strings as input
 440.471 +     *       // in addition to strings of floating-point literals, the
 440.472 +     *       // two sub-patterns below are simplifications of the grammar
 440.473 +     *       // productions from section 3.10.2 of
 440.474 +     *       // <cite>The Java&trade; Language Specification</cite>.
 440.475 +     *
 440.476 +     *       // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
 440.477 +     *       "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
 440.478 +     *
 440.479 +     *       // . Digits ExponentPart_opt FloatTypeSuffix_opt
 440.480 +     *       "(\\.("+Digits+")("+Exp+")?)|"+
 440.481 +     *
 440.482 +     *       // Hexadecimal strings
 440.483 +     *       "((" +
 440.484 +     *        // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
 440.485 +     *        "(0[xX]" + HexDigits + "(\\.)?)|" +
 440.486 +     *
 440.487 +     *        // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
 440.488 +     *        "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
 440.489 +     *
 440.490 +     *        ")[pP][+-]?" + Digits + "))" +
 440.491 +     *       "[fFdD]?))" +
 440.492 +     *       "[\\x00-\\x20]*");// Optional trailing "whitespace"
 440.493 +     *
 440.494 +     *  if (Pattern.matches(fpRegex, myString))
 440.495 +     *      Double.valueOf(myString); // Will not throw NumberFormatException
 440.496 +     *  else {
 440.497 +     *      // Perform suitable alternative action
 440.498 +     *  }
 440.499 +     * </pre>
 440.500 +     * </code>
 440.501 +     *
 440.502 +     * @param      s   the string to be parsed.
 440.503 +     * @return     a {@code Double} object holding the value
 440.504 +     *             represented by the {@code String} argument.
 440.505 +     * @throws     NumberFormatException  if the string does not contain a
 440.506 +     *             parsable number.
 440.507 +     */
 440.508 +    @JavaScriptBody(args="s", body="return parseFloat(s);")
 440.509 +    public static Double valueOf(String s) throws NumberFormatException {
 440.510 +        throw new UnsupportedOperationException();
 440.511 +//        return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
 440.512 +    }
 440.513 +
 440.514 +    /**
 440.515 +     * Returns a {@code Double} instance representing the specified
 440.516 +     * {@code double} value.
 440.517 +     * If a new {@code Double} instance is not required, this method
 440.518 +     * should generally be used in preference to the constructor
 440.519 +     * {@link #Double(double)}, as this method is likely to yield
 440.520 +     * significantly better space and time performance by caching
 440.521 +     * frequently requested values.
 440.522 +     *
 440.523 +     * @param  d a double value.
 440.524 +     * @return a {@code Double} instance representing {@code d}.
 440.525 +     * @since  1.5
 440.526 +     */
 440.527 +    public static Double valueOf(double d) {
 440.528 +        return new Double(d);
 440.529 +    }
 440.530 +
 440.531 +    /**
 440.532 +     * Returns a new {@code double} initialized to the value
 440.533 +     * represented by the specified {@code String}, as performed
 440.534 +     * by the {@code valueOf} method of class
 440.535 +     * {@code Double}.
 440.536 +     *
 440.537 +     * @param  s   the string to be parsed.
 440.538 +     * @return the {@code double} value represented by the string
 440.539 +     *         argument.
 440.540 +     * @throws NullPointerException  if the string is null
 440.541 +     * @throws NumberFormatException if the string does not contain
 440.542 +     *         a parsable {@code double}.
 440.543 +     * @see    java.lang.Double#valueOf(String)
 440.544 +     * @since 1.2
 440.545 +     */
 440.546 +    @JavaScriptBody(args="s", body="return parseFloat(s);")
 440.547 +    public static double parseDouble(String s) throws NumberFormatException {
 440.548 +        throw new UnsupportedOperationException();
 440.549 +//        return FloatingDecimal.readJavaFormatString(s).doubleValue();
 440.550 +    }
 440.551 +
 440.552 +    /**
 440.553 +     * Returns {@code true} if the specified number is a
 440.554 +     * Not-a-Number (NaN) value, {@code false} otherwise.
 440.555 +     *
 440.556 +     * @param   v   the value to be tested.
 440.557 +     * @return  {@code true} if the value of the argument is NaN;
 440.558 +     *          {@code false} otherwise.
 440.559 +     */
 440.560 +    static public boolean isNaN(double v) {
 440.561 +        return (v != v);
 440.562 +    }
 440.563 +
 440.564 +    /**
 440.565 +     * Returns {@code true} if the specified number is infinitely
 440.566 +     * large in magnitude, {@code false} otherwise.
 440.567 +     *
 440.568 +     * @param   v   the value to be tested.
 440.569 +     * @return  {@code true} if the value of the argument is positive
 440.570 +     *          infinity or negative infinity; {@code false} otherwise.
 440.571 +     */
 440.572 +    static public boolean isInfinite(double v) {
 440.573 +        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 440.574 +    }
 440.575 +
 440.576 +    /**
 440.577 +     * The value of the Double.
 440.578 +     *
 440.579 +     * @serial
 440.580 +     */
 440.581 +    private final double value;
 440.582 +
 440.583 +    /**
 440.584 +     * Constructs a newly allocated {@code Double} object that
 440.585 +     * represents the primitive {@code double} argument.
 440.586 +     *
 440.587 +     * @param   value   the value to be represented by the {@code Double}.
 440.588 +     */
 440.589 +    public Double(double value) {
 440.590 +        this.value = value;
 440.591 +    }
 440.592 +
 440.593 +    /**
 440.594 +     * Constructs a newly allocated {@code Double} object that
 440.595 +     * represents the floating-point value of type {@code double}
 440.596 +     * represented by the string. The string is converted to a
 440.597 +     * {@code double} value as if by the {@code valueOf} method.
 440.598 +     *
 440.599 +     * @param  s  a string to be converted to a {@code Double}.
 440.600 +     * @throws    NumberFormatException  if the string does not contain a
 440.601 +     *            parsable number.
 440.602 +     * @see       java.lang.Double#valueOf(java.lang.String)
 440.603 +     */
 440.604 +    public Double(String s) throws NumberFormatException {
 440.605 +        // REMIND: this is inefficient
 440.606 +        this(valueOf(s).doubleValue());
 440.607 +    }
 440.608 +
 440.609 +    /**
 440.610 +     * Returns {@code true} if this {@code Double} value is
 440.611 +     * a Not-a-Number (NaN), {@code false} otherwise.
 440.612 +     *
 440.613 +     * @return  {@code true} if the value represented by this object is
 440.614 +     *          NaN; {@code false} otherwise.
 440.615 +     */
 440.616 +    public boolean isNaN() {
 440.617 +        return isNaN(value);
 440.618 +    }
 440.619 +
 440.620 +    /**
 440.621 +     * Returns {@code true} if this {@code Double} value is
 440.622 +     * infinitely large in magnitude, {@code false} otherwise.
 440.623 +     *
 440.624 +     * @return  {@code true} if the value represented by this object is
 440.625 +     *          positive infinity or negative infinity;
 440.626 +     *          {@code false} otherwise.
 440.627 +     */
 440.628 +    public boolean isInfinite() {
 440.629 +        return isInfinite(value);
 440.630 +    }
 440.631 +
 440.632 +    /**
 440.633 +     * Returns a string representation of this {@code Double} object.
 440.634 +     * The primitive {@code double} value represented by this
 440.635 +     * object is converted to a string exactly as if by the method
 440.636 +     * {@code toString} of one argument.
 440.637 +     *
 440.638 +     * @return  a {@code String} representation of this object.
 440.639 +     * @see java.lang.Double#toString(double)
 440.640 +     */
 440.641 +    public String toString() {
 440.642 +        return toString(value);
 440.643 +    }
 440.644 +
 440.645 +    /**
 440.646 +     * Returns the value of this {@code Double} as a {@code byte} (by
 440.647 +     * casting to a {@code byte}).
 440.648 +     *
 440.649 +     * @return  the {@code double} value represented by this object
 440.650 +     *          converted to type {@code byte}
 440.651 +     * @since JDK1.1
 440.652 +     */
 440.653 +    public byte byteValue() {
 440.654 +        return (byte)value;
 440.655 +    }
 440.656 +
 440.657 +    /**
 440.658 +     * Returns the value of this {@code Double} as a
 440.659 +     * {@code short} (by casting to a {@code short}).
 440.660 +     *
 440.661 +     * @return  the {@code double} value represented by this object
 440.662 +     *          converted to type {@code short}
 440.663 +     * @since JDK1.1
 440.664 +     */
 440.665 +    public short shortValue() {
 440.666 +        return (short)value;
 440.667 +    }
 440.668 +
 440.669 +    /**
 440.670 +     * Returns the value of this {@code Double} as an
 440.671 +     * {@code int} (by casting to type {@code int}).
 440.672 +     *
 440.673 +     * @return  the {@code double} value represented by this object
 440.674 +     *          converted to type {@code int}
 440.675 +     */
 440.676 +    public int intValue() {
 440.677 +        return (int)value;
 440.678 +    }
 440.679 +
 440.680 +    /**
 440.681 +     * Returns the value of this {@code Double} as a
 440.682 +     * {@code long} (by casting to type {@code long}).
 440.683 +     *
 440.684 +     * @return  the {@code double} value represented by this object
 440.685 +     *          converted to type {@code long}
 440.686 +     */
 440.687 +    public long longValue() {
 440.688 +        return (long)value;
 440.689 +    }
 440.690 +
 440.691 +    /**
 440.692 +     * Returns the {@code float} value of this
 440.693 +     * {@code Double} object.
 440.694 +     *
 440.695 +     * @return  the {@code double} value represented by this object
 440.696 +     *          converted to type {@code float}
 440.697 +     * @since JDK1.0
 440.698 +     */
 440.699 +    public float floatValue() {
 440.700 +        return (float)value;
 440.701 +    }
 440.702 +
 440.703 +    /**
 440.704 +     * Returns the {@code double} value of this
 440.705 +     * {@code Double} object.
 440.706 +     *
 440.707 +     * @return the {@code double} value represented by this object
 440.708 +     */
 440.709 +    public double doubleValue() {
 440.710 +        return (double)value;
 440.711 +    }
 440.712 +
 440.713 +    /**
 440.714 +     * Returns a hash code for this {@code Double} object. The
 440.715 +     * result is the exclusive OR of the two halves of the
 440.716 +     * {@code long} integer bit representation, exactly as
 440.717 +     * produced by the method {@link #doubleToLongBits(double)}, of
 440.718 +     * the primitive {@code double} value represented by this
 440.719 +     * {@code Double} object. That is, the hash code is the value
 440.720 +     * of the expression:
 440.721 +     *
 440.722 +     * <blockquote>
 440.723 +     *  {@code (int)(v^(v>>>32))}
 440.724 +     * </blockquote>
 440.725 +     *
 440.726 +     * where {@code v} is defined by:
 440.727 +     *
 440.728 +     * <blockquote>
 440.729 +     *  {@code long v = Double.doubleToLongBits(this.doubleValue());}
 440.730 +     * </blockquote>
 440.731 +     *
 440.732 +     * @return  a {@code hash code} value for this object.
 440.733 +     */
 440.734 +    public int hashCode() {
 440.735 +        long bits = doubleToLongBits(value);
 440.736 +        return (int)(bits ^ (bits >>> 32));
 440.737 +    }
 440.738 +
 440.739 +    /**
 440.740 +     * Compares this object against the specified object.  The result
 440.741 +     * is {@code true} if and only if the argument is not
 440.742 +     * {@code null} and is a {@code Double} object that
 440.743 +     * represents a {@code double} that has the same value as the
 440.744 +     * {@code double} represented by this object. For this
 440.745 +     * purpose, two {@code double} values are considered to be
 440.746 +     * the same if and only if the method {@link
 440.747 +     * #doubleToLongBits(double)} returns the identical
 440.748 +     * {@code long} value when applied to each.
 440.749 +     *
 440.750 +     * <p>Note that in most cases, for two instances of class
 440.751 +     * {@code Double}, {@code d1} and {@code d2}, the
 440.752 +     * value of {@code d1.equals(d2)} is {@code true} if and
 440.753 +     * only if
 440.754 +     *
 440.755 +     * <blockquote>
 440.756 +     *  {@code d1.doubleValue() == d2.doubleValue()}
 440.757 +     * </blockquote>
 440.758 +     *
 440.759 +     * <p>also has the value {@code true}. However, there are two
 440.760 +     * exceptions:
 440.761 +     * <ul>
 440.762 +     * <li>If {@code d1} and {@code d2} both represent
 440.763 +     *     {@code Double.NaN}, then the {@code equals} method
 440.764 +     *     returns {@code true}, even though
 440.765 +     *     {@code Double.NaN==Double.NaN} has the value
 440.766 +     *     {@code false}.
 440.767 +     * <li>If {@code d1} represents {@code +0.0} while
 440.768 +     *     {@code d2} represents {@code -0.0}, or vice versa,
 440.769 +     *     the {@code equal} test has the value {@code false},
 440.770 +     *     even though {@code +0.0==-0.0} has the value {@code true}.
 440.771 +     * </ul>
 440.772 +     * This definition allows hash tables to operate properly.
 440.773 +     * @param   obj   the object to compare with.
 440.774 +     * @return  {@code true} if the objects are the same;
 440.775 +     *          {@code false} otherwise.
 440.776 +     * @see java.lang.Double#doubleToLongBits(double)
 440.777 +     */
 440.778 +    public boolean equals(Object obj) {
 440.779 +        return (obj instanceof Double)
 440.780 +               && (((Double)obj).value) == value;
 440.781 +    }
 440.782 +
 440.783 +    /**
 440.784 +     * Returns a representation of the specified floating-point value
 440.785 +     * according to the IEEE 754 floating-point "double
 440.786 +     * format" bit layout.
 440.787 +     *
 440.788 +     * <p>Bit 63 (the bit that is selected by the mask
 440.789 +     * {@code 0x8000000000000000L}) represents the sign of the
 440.790 +     * floating-point number. Bits
 440.791 +     * 62-52 (the bits that are selected by the mask
 440.792 +     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 440.793 +     * (the bits that are selected by the mask
 440.794 +     * {@code 0x000fffffffffffffL}) represent the significand
 440.795 +     * (sometimes called the mantissa) of the floating-point number.
 440.796 +     *
 440.797 +     * <p>If the argument is positive infinity, the result is
 440.798 +     * {@code 0x7ff0000000000000L}.
 440.799 +     *
 440.800 +     * <p>If the argument is negative infinity, the result is
 440.801 +     * {@code 0xfff0000000000000L}.
 440.802 +     *
 440.803 +     * <p>If the argument is NaN, the result is
 440.804 +     * {@code 0x7ff8000000000000L}.
 440.805 +     *
 440.806 +     * <p>In all cases, the result is a {@code long} integer that, when
 440.807 +     * given to the {@link #longBitsToDouble(long)} method, will produce a
 440.808 +     * floating-point value the same as the argument to
 440.809 +     * {@code doubleToLongBits} (except all NaN values are
 440.810 +     * collapsed to a single "canonical" NaN value).
 440.811 +     *
 440.812 +     * @param   value   a {@code double} precision floating-point number.
 440.813 +     * @return the bits that represent the floating-point number.
 440.814 +     */
 440.815 +    public static long doubleToLongBits(double value) {
 440.816 +        throw new UnsupportedOperationException();
 440.817 +//        long result = doubleToRawLongBits(value);
 440.818 +//        // Check for NaN based on values of bit fields, maximum
 440.819 +//        // exponent and nonzero significand.
 440.820 +//        if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
 440.821 +//              DoubleConsts.EXP_BIT_MASK) &&
 440.822 +//             (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
 440.823 +//            result = 0x7ff8000000000000L;
 440.824 +//        return result;
 440.825 +    }
 440.826 +
 440.827 +    /**
 440.828 +     * Returns a representation of the specified floating-point value
 440.829 +     * according to the IEEE 754 floating-point "double
 440.830 +     * format" bit layout, preserving Not-a-Number (NaN) values.
 440.831 +     *
 440.832 +     * <p>Bit 63 (the bit that is selected by the mask
 440.833 +     * {@code 0x8000000000000000L}) represents the sign of the
 440.834 +     * floating-point number. Bits
 440.835 +     * 62-52 (the bits that are selected by the mask
 440.836 +     * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
 440.837 +     * (the bits that are selected by the mask
 440.838 +     * {@code 0x000fffffffffffffL}) represent the significand
 440.839 +     * (sometimes called the mantissa) of the floating-point number.
 440.840 +     *
 440.841 +     * <p>If the argument is positive infinity, the result is
 440.842 +     * {@code 0x7ff0000000000000L}.
 440.843 +     *
 440.844 +     * <p>If the argument is negative infinity, the result is
 440.845 +     * {@code 0xfff0000000000000L}.
 440.846 +     *
 440.847 +     * <p>If the argument is NaN, the result is the {@code long}
 440.848 +     * integer representing the actual NaN value.  Unlike the
 440.849 +     * {@code doubleToLongBits} method,
 440.850 +     * {@code doubleToRawLongBits} does not collapse all the bit
 440.851 +     * patterns encoding a NaN to a single "canonical" NaN
 440.852 +     * value.
 440.853 +     *
 440.854 +     * <p>In all cases, the result is a {@code long} integer that,
 440.855 +     * when given to the {@link #longBitsToDouble(long)} method, will
 440.856 +     * produce a floating-point value the same as the argument to
 440.857 +     * {@code doubleToRawLongBits}.
 440.858 +     *
 440.859 +     * @param   value   a {@code double} precision floating-point number.
 440.860 +     * @return the bits that represent the floating-point number.
 440.861 +     * @since 1.3
 440.862 +     */
 440.863 +    public static native long doubleToRawLongBits(double value);
 440.864 +
 440.865 +    /**
 440.866 +     * Returns the {@code double} value corresponding to a given
 440.867 +     * bit representation.
 440.868 +     * The argument is considered to be a representation of a
 440.869 +     * floating-point value according to the IEEE 754 floating-point
 440.870 +     * "double format" bit layout.
 440.871 +     *
 440.872 +     * <p>If the argument is {@code 0x7ff0000000000000L}, the result
 440.873 +     * is positive infinity.
 440.874 +     *
 440.875 +     * <p>If the argument is {@code 0xfff0000000000000L}, the result
 440.876 +     * is negative infinity.
 440.877 +     *
 440.878 +     * <p>If the argument is any value in the range
 440.879 +     * {@code 0x7ff0000000000001L} through
 440.880 +     * {@code 0x7fffffffffffffffL} or in the range
 440.881 +     * {@code 0xfff0000000000001L} through
 440.882 +     * {@code 0xffffffffffffffffL}, the result is a NaN.  No IEEE
 440.883 +     * 754 floating-point operation provided by Java can distinguish
 440.884 +     * between two NaN values of the same type with different bit
 440.885 +     * patterns.  Distinct values of NaN are only distinguishable by
 440.886 +     * use of the {@code Double.doubleToRawLongBits} method.
 440.887 +     *
 440.888 +     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 440.889 +     * values that can be computed from the argument:
 440.890 +     *
 440.891 +     * <blockquote><pre>
 440.892 +     * int s = ((bits &gt;&gt; 63) == 0) ? 1 : -1;
 440.893 +     * int e = (int)((bits &gt;&gt; 52) & 0x7ffL);
 440.894 +     * long m = (e == 0) ?
 440.895 +     *                 (bits & 0xfffffffffffffL) &lt;&lt; 1 :
 440.896 +     *                 (bits & 0xfffffffffffffL) | 0x10000000000000L;
 440.897 +     * </pre></blockquote>
 440.898 +     *
 440.899 +     * Then the floating-point result equals the value of the mathematical
 440.900 +     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-1075</sup>.
 440.901 +     *
 440.902 +     * <p>Note that this method may not be able to return a
 440.903 +     * {@code double} NaN with exactly same bit pattern as the
 440.904 +     * {@code long} argument.  IEEE 754 distinguishes between two
 440.905 +     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 440.906 +     * differences between the two kinds of NaN are generally not
 440.907 +     * visible in Java.  Arithmetic operations on signaling NaNs turn
 440.908 +     * them into quiet NaNs with a different, but often similar, bit
 440.909 +     * pattern.  However, on some processors merely copying a
 440.910 +     * signaling NaN also performs that conversion.  In particular,
 440.911 +     * copying a signaling NaN to return it to the calling method
 440.912 +     * may perform this conversion.  So {@code longBitsToDouble}
 440.913 +     * may not be able to return a {@code double} with a
 440.914 +     * signaling NaN bit pattern.  Consequently, for some
 440.915 +     * {@code long} values,
 440.916 +     * {@code doubleToRawLongBits(longBitsToDouble(start))} may
 440.917 +     * <i>not</i> equal {@code start}.  Moreover, which
 440.918 +     * particular bit patterns represent signaling NaNs is platform
 440.919 +     * dependent; although all NaN bit patterns, quiet or signaling,
 440.920 +     * must be in the NaN range identified above.
 440.921 +     *
 440.922 +     * @param   bits   any {@code long} integer.
 440.923 +     * @return  the {@code double} floating-point value with the same
 440.924 +     *          bit pattern.
 440.925 +     */
 440.926 +    public static native double longBitsToDouble(long bits);
 440.927 +
 440.928 +    /**
 440.929 +     * Compares two {@code Double} objects numerically.  There
 440.930 +     * are two ways in which comparisons performed by this method
 440.931 +     * differ from those performed by the Java language numerical
 440.932 +     * comparison operators ({@code <, <=, ==, >=, >})
 440.933 +     * when applied to primitive {@code double} values:
 440.934 +     * <ul><li>
 440.935 +     *          {@code Double.NaN} is considered by this method
 440.936 +     *          to be equal to itself and greater than all other
 440.937 +     *          {@code double} values (including
 440.938 +     *          {@code Double.POSITIVE_INFINITY}).
 440.939 +     * <li>
 440.940 +     *          {@code 0.0d} is considered by this method to be greater
 440.941 +     *          than {@code -0.0d}.
 440.942 +     * </ul>
 440.943 +     * This ensures that the <i>natural ordering</i> of
 440.944 +     * {@code Double} objects imposed by this method is <i>consistent
 440.945 +     * with equals</i>.
 440.946 +     *
 440.947 +     * @param   anotherDouble   the {@code Double} to be compared.
 440.948 +     * @return  the value {@code 0} if {@code anotherDouble} is
 440.949 +     *          numerically equal to this {@code Double}; a value
 440.950 +     *          less than {@code 0} if this {@code Double}
 440.951 +     *          is numerically less than {@code anotherDouble};
 440.952 +     *          and a value greater than {@code 0} if this
 440.953 +     *          {@code Double} is numerically greater than
 440.954 +     *          {@code anotherDouble}.
 440.955 +     *
 440.956 +     * @since   1.2
 440.957 +     */
 440.958 +    public int compareTo(Double anotherDouble) {
 440.959 +        return Double.compare(value, anotherDouble.value);
 440.960 +    }
 440.961 +
 440.962 +    /**
 440.963 +     * Compares the two specified {@code double} values. The sign
 440.964 +     * of the integer value returned is the same as that of the
 440.965 +     * integer that would be returned by the call:
 440.966 +     * <pre>
 440.967 +     *    new Double(d1).compareTo(new Double(d2))
 440.968 +     * </pre>
 440.969 +     *
 440.970 +     * @param   d1        the first {@code double} to compare
 440.971 +     * @param   d2        the second {@code double} to compare
 440.972 +     * @return  the value {@code 0} if {@code d1} is
 440.973 +     *          numerically equal to {@code d2}; a value less than
 440.974 +     *          {@code 0} if {@code d1} is numerically less than
 440.975 +     *          {@code d2}; and a value greater than {@code 0}
 440.976 +     *          if {@code d1} is numerically greater than
 440.977 +     *          {@code d2}.
 440.978 +     * @since 1.4
 440.979 +     */
 440.980 +    public static int compare(double d1, double d2) {
 440.981 +        if (d1 < d2)
 440.982 +            return -1;           // Neither val is NaN, thisVal is smaller
 440.983 +        if (d1 > d2)
 440.984 +            return 1;            // Neither val is NaN, thisVal is larger
 440.985 +
 440.986 +        // Cannot use doubleToRawLongBits because of possibility of NaNs.
 440.987 +        long thisBits    = Double.doubleToLongBits(d1);
 440.988 +        long anotherBits = Double.doubleToLongBits(d2);
 440.989 +
 440.990 +        return (thisBits == anotherBits ?  0 : // Values are equal
 440.991 +                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 440.992 +                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 440.993 +    }
 440.994 +
 440.995 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 440.996 +    private static final long serialVersionUID = -9172774392245257468L;
 440.997 +}
   441.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   441.2 +++ b/rt/emul/mini/src/main/java/java/lang/Enum.java	Wed Feb 27 11:24:58 2013 +0100
   441.3 @@ -0,0 +1,254 @@
   441.4 +/*
   441.5 + * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
   441.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   441.7 + *
   441.8 + * This code is free software; you can redistribute it and/or modify it
   441.9 + * under the terms of the GNU General Public License version 2 only, as
  441.10 + * published by the Free Software Foundation.  Oracle designates this
  441.11 + * particular file as subject to the "Classpath" exception as provided
  441.12 + * by Oracle in the LICENSE file that accompanied this code.
  441.13 + *
  441.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  441.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  441.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  441.17 + * version 2 for more details (a copy is included in the LICENSE file that
  441.18 + * accompanied this code).
  441.19 + *
  441.20 + * You should have received a copy of the GNU General Public License version
  441.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  441.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  441.23 + *
  441.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  441.25 + * or visit www.oracle.com if you need additional information or have any
  441.26 + * questions.
  441.27 + */
  441.28 +
  441.29 +package java.lang;
  441.30 +
  441.31 +import java.io.Serializable;
  441.32 +import java.io.IOException;
  441.33 +
  441.34 +/**
  441.35 + * This is the common base class of all Java language enumeration types.
  441.36 + *
  441.37 + * More information about enums, including descriptions of the
  441.38 + * implicitly declared methods synthesized by the compiler, can be
  441.39 + * found in section 8.9 of
  441.40 + * <cite>The Java&trade; Language Specification</cite>.
  441.41 + *
  441.42 + * <p> Note that when using an enumeration type as the type of a set
  441.43 + * or as the type of the keys in a map, specialized and efficient
  441.44 + * {@linkplain java.util.EnumSet set} and {@linkplain
  441.45 + * java.util.EnumMap map} implementations are available.
  441.46 + *
  441.47 + * @param <E> The enum type subclass
  441.48 + * @author  Josh Bloch
  441.49 + * @author  Neal Gafter
  441.50 + * @see     Class#getEnumConstants()
  441.51 + * @see     java.util.EnumSet
  441.52 + * @see     java.util.EnumMap
  441.53 + * @since   1.5
  441.54 + */
  441.55 +public abstract class Enum<E extends Enum<E>>
  441.56 +        implements Comparable<E>, Serializable {
  441.57 +    /**
  441.58 +     * The name of this enum constant, as declared in the enum declaration.
  441.59 +     * Most programmers should use the {@link #toString} method rather than
  441.60 +     * accessing this field.
  441.61 +     */
  441.62 +    private final String name;
  441.63 +
  441.64 +    /**
  441.65 +     * Returns the name of this enum constant, exactly as declared in its
  441.66 +     * enum declaration.
  441.67 +     *
  441.68 +     * <b>Most programmers should use the {@link #toString} method in
  441.69 +     * preference to this one, as the toString method may return
  441.70 +     * a more user-friendly name.</b>  This method is designed primarily for
  441.71 +     * use in specialized situations where correctness depends on getting the
  441.72 +     * exact name, which will not vary from release to release.
  441.73 +     *
  441.74 +     * @return the name of this enum constant
  441.75 +     */
  441.76 +    public final String name() {
  441.77 +        return name;
  441.78 +    }
  441.79 +
  441.80 +    /**
  441.81 +     * The ordinal of this enumeration constant (its position
  441.82 +     * in the enum declaration, where the initial constant is assigned
  441.83 +     * an ordinal of zero).
  441.84 +     *
  441.85 +     * Most programmers will have no use for this field.  It is designed
  441.86 +     * for use by sophisticated enum-based data structures, such as
  441.87 +     * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  441.88 +     */
  441.89 +    private final int ordinal;
  441.90 +
  441.91 +    /**
  441.92 +     * Returns the ordinal of this enumeration constant (its position
  441.93 +     * in its enum declaration, where the initial constant is assigned
  441.94 +     * an ordinal of zero).
  441.95 +     *
  441.96 +     * Most programmers will have no use for this method.  It is
  441.97 +     * designed for use by sophisticated enum-based data structures, such
  441.98 +     * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  441.99 +     *
 441.100 +     * @return the ordinal of this enumeration constant
 441.101 +     */
 441.102 +    public final int ordinal() {
 441.103 +        return ordinal;
 441.104 +    }
 441.105 +
 441.106 +    /**
 441.107 +     * Sole constructor.  Programmers cannot invoke this constructor.
 441.108 +     * It is for use by code emitted by the compiler in response to
 441.109 +     * enum type declarations.
 441.110 +     *
 441.111 +     * @param name - The name of this enum constant, which is the identifier
 441.112 +     *               used to declare it.
 441.113 +     * @param ordinal - The ordinal of this enumeration constant (its position
 441.114 +     *         in the enum declaration, where the initial constant is assigned
 441.115 +     *         an ordinal of zero).
 441.116 +     */
 441.117 +    protected Enum(String name, int ordinal) {
 441.118 +        this.name = name;
 441.119 +        this.ordinal = ordinal;
 441.120 +    }
 441.121 +
 441.122 +    /**
 441.123 +     * Returns the name of this enum constant, as contained in the
 441.124 +     * declaration.  This method may be overridden, though it typically
 441.125 +     * isn't necessary or desirable.  An enum type should override this
 441.126 +     * method when a more "programmer-friendly" string form exists.
 441.127 +     *
 441.128 +     * @return the name of this enum constant
 441.129 +     */
 441.130 +    public String toString() {
 441.131 +        return name;
 441.132 +    }
 441.133 +
 441.134 +    /**
 441.135 +     * Returns true if the specified object is equal to this
 441.136 +     * enum constant.
 441.137 +     *
 441.138 +     * @param other the object to be compared for equality with this object.
 441.139 +     * @return  true if the specified object is equal to this
 441.140 +     *          enum constant.
 441.141 +     */
 441.142 +    public final boolean equals(Object other) {
 441.143 +        return this==other;
 441.144 +    }
 441.145 +
 441.146 +    /**
 441.147 +     * Returns a hash code for this enum constant.
 441.148 +     *
 441.149 +     * @return a hash code for this enum constant.
 441.150 +     */
 441.151 +    public final int hashCode() {
 441.152 +        return super.hashCode();
 441.153 +    }
 441.154 +
 441.155 +    /**
 441.156 +     * Throws CloneNotSupportedException.  This guarantees that enums
 441.157 +     * are never cloned, which is necessary to preserve their "singleton"
 441.158 +     * status.
 441.159 +     *
 441.160 +     * @return (never returns)
 441.161 +     */
 441.162 +    protected final Object clone() throws CloneNotSupportedException {
 441.163 +        throw new CloneNotSupportedException();
 441.164 +    }
 441.165 +
 441.166 +    /**
 441.167 +     * Compares this enum with the specified object for order.  Returns a
 441.168 +     * negative integer, zero, or a positive integer as this object is less
 441.169 +     * than, equal to, or greater than the specified object.
 441.170 +     *
 441.171 +     * Enum constants are only comparable to other enum constants of the
 441.172 +     * same enum type.  The natural order implemented by this
 441.173 +     * method is the order in which the constants are declared.
 441.174 +     */
 441.175 +    public final int compareTo(E o) {
 441.176 +        Enum other = (Enum)o;
 441.177 +        Enum self = this;
 441.178 +        if (self.getClass() != other.getClass() && // optimization
 441.179 +            self.getDeclaringClass() != other.getDeclaringClass())
 441.180 +            throw new ClassCastException();
 441.181 +        return self.ordinal - other.ordinal;
 441.182 +    }
 441.183 +
 441.184 +    /**
 441.185 +     * Returns the Class object corresponding to this enum constant's
 441.186 +     * enum type.  Two enum constants e1 and  e2 are of the
 441.187 +     * same enum type if and only if
 441.188 +     *   e1.getDeclaringClass() == e2.getDeclaringClass().
 441.189 +     * (The value returned by this method may differ from the one returned
 441.190 +     * by the {@link Object#getClass} method for enum constants with
 441.191 +     * constant-specific class bodies.)
 441.192 +     *
 441.193 +     * @return the Class object corresponding to this enum constant's
 441.194 +     *     enum type
 441.195 +     */
 441.196 +    public final Class<E> getDeclaringClass() {
 441.197 +        Class clazz = getClass();
 441.198 +        Class zuper = clazz.getSuperclass();
 441.199 +        return (zuper == Enum.class) ? clazz : zuper;
 441.200 +    }
 441.201 +
 441.202 +    /**
 441.203 +     * Returns the enum constant of the specified enum type with the
 441.204 +     * specified name.  The name must match exactly an identifier used
 441.205 +     * to declare an enum constant in this type.  (Extraneous whitespace
 441.206 +     * characters are not permitted.)
 441.207 +     *
 441.208 +     * <p>Note that for a particular enum type {@code T}, the
 441.209 +     * implicitly declared {@code public static T valueOf(String)}
 441.210 +     * method on that enum may be used instead of this method to map
 441.211 +     * from a name to the corresponding enum constant.  All the
 441.212 +     * constants of an enum type can be obtained by calling the
 441.213 +     * implicit {@code public static T[] values()} method of that
 441.214 +     * type.
 441.215 +     *
 441.216 +     * @param <T> The enum type whose constant is to be returned
 441.217 +     * @param enumType the {@code Class} object of the enum type from which
 441.218 +     *      to return a constant
 441.219 +     * @param name the name of the constant to return
 441.220 +     * @return the enum constant of the specified enum type with the
 441.221 +     *      specified name
 441.222 +     * @throws IllegalArgumentException if the specified enum type has
 441.223 +     *         no constant with the specified name, or the specified
 441.224 +     *         class object does not represent an enum type
 441.225 +     * @throws NullPointerException if {@code enumType} or {@code name}
 441.226 +     *         is null
 441.227 +     * @since 1.5
 441.228 +     */
 441.229 +    public static <T extends Enum<T>> T valueOf(Class<T> enumType,
 441.230 +                                                String name) {
 441.231 +        throw new UnsupportedOperationException();
 441.232 +//        T result = enumType.enumConstantDirectory().get(name);
 441.233 +//        if (result != null)
 441.234 +//            return result;
 441.235 +//        if (name == null)
 441.236 +//            throw new NullPointerException("Name is null");
 441.237 +//        throw new IllegalArgumentException(
 441.238 +//            "No enum constant " + enumType.getCanonicalName() + "." + name);
 441.239 +    }
 441.240 +
 441.241 +    /**
 441.242 +     * enum classes cannot have finalize methods.
 441.243 +     */
 441.244 +    protected final void finalize() { }
 441.245 +
 441.246 +    /**
 441.247 +     * prevent default deserialization
 441.248 +     */
 441.249 +//    private void readObject(ObjectInputStream in) throws IOException,
 441.250 +//        ClassNotFoundException {
 441.251 +//        throw new InvalidObjectException("can't deserialize enum");
 441.252 +//    }
 441.253 +//
 441.254 +//    private void readObjectNoData() throws ObjectStreamException {
 441.255 +//        throw new InvalidObjectException("can't deserialize enum");
 441.256 +//    }
 441.257 +}
   442.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   442.2 +++ b/rt/emul/mini/src/main/java/java/lang/Error.java	Wed Feb 27 11:24:58 2013 +0100
   442.3 @@ -0,0 +1,128 @@
   442.4 +/*
   442.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   442.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   442.7 + *
   442.8 + * This code is free software; you can redistribute it and/or modify it
   442.9 + * under the terms of the GNU General Public License version 2 only, as
  442.10 + * published by the Free Software Foundation.  Oracle designates this
  442.11 + * particular file as subject to the "Classpath" exception as provided
  442.12 + * by Oracle in the LICENSE file that accompanied this code.
  442.13 + *
  442.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  442.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  442.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  442.17 + * version 2 for more details (a copy is included in the LICENSE file that
  442.18 + * accompanied this code).
  442.19 + *
  442.20 + * You should have received a copy of the GNU General Public License version
  442.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  442.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  442.23 + *
  442.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  442.25 + * or visit www.oracle.com if you need additional information or have any
  442.26 + * questions.
  442.27 + */
  442.28 +
  442.29 +package java.lang;
  442.30 +
  442.31 +/**
  442.32 + * An {@code Error} is a subclass of {@code Throwable}
  442.33 + * that indicates serious problems that a reasonable application
  442.34 + * should not try to catch. Most such errors are abnormal conditions.
  442.35 + * The {@code ThreadDeath} error, though a "normal" condition,
  442.36 + * is also a subclass of {@code Error} because most applications
  442.37 + * should not try to catch it.
  442.38 + * <p>
  442.39 + * A method is not required to declare in its {@code throws}
  442.40 + * clause any subclasses of {@code Error} that might be thrown
  442.41 + * during the execution of the method but not caught, since these
  442.42 + * errors are abnormal conditions that should never occur.
  442.43 + *
  442.44 + * That is, {@code Error} and its subclasses are regarded as unchecked
  442.45 + * exceptions for the purposes of compile-time checking of exceptions.
  442.46 + *
  442.47 + * @author  Frank Yellin
  442.48 + * @see     java.lang.ThreadDeath
  442.49 + * @jls 11.2 Compile-Time Checking of Exceptions
  442.50 + * @since   JDK1.0
  442.51 + */
  442.52 +public class Error extends Throwable {
  442.53 +    static final long serialVersionUID = 4980196508277280342L;
  442.54 +
  442.55 +    /**
  442.56 +     * Constructs a new error with {@code null} as its detail message.
  442.57 +     * The cause is not initialized, and may subsequently be initialized by a
  442.58 +     * call to {@link #initCause}.
  442.59 +     */
  442.60 +    public Error() {
  442.61 +        super();
  442.62 +    }
  442.63 +
  442.64 +    /**
  442.65 +     * Constructs a new error with the specified detail message.  The
  442.66 +     * cause is not initialized, and may subsequently be initialized by
  442.67 +     * a call to {@link #initCause}.
  442.68 +     *
  442.69 +     * @param   message   the detail message. The detail message is saved for
  442.70 +     *          later retrieval by the {@link #getMessage()} method.
  442.71 +     */
  442.72 +    public Error(String message) {
  442.73 +        super(message);
  442.74 +    }
  442.75 +
  442.76 +    /**
  442.77 +     * Constructs a new error with the specified detail message and
  442.78 +     * cause.  <p>Note that the detail message associated with
  442.79 +     * {@code cause} is <i>not</i> automatically incorporated in
  442.80 +     * this error's detail message.
  442.81 +     *
  442.82 +     * @param  message the detail message (which is saved for later retrieval
  442.83 +     *         by the {@link #getMessage()} method).
  442.84 +     * @param  cause the cause (which is saved for later retrieval by the
  442.85 +     *         {@link #getCause()} method).  (A {@code null} value is
  442.86 +     *         permitted, and indicates that the cause is nonexistent or
  442.87 +     *         unknown.)
  442.88 +     * @since  1.4
  442.89 +     */
  442.90 +    public Error(String message, Throwable cause) {
  442.91 +        super(message, cause);
  442.92 +    }
  442.93 +
  442.94 +    /**
  442.95 +     * Constructs a new error with the specified cause and a detail
  442.96 +     * message of {@code (cause==null ? null : cause.toString())} (which
  442.97 +     * typically contains the class and detail message of {@code cause}).
  442.98 +     * This constructor is useful for errors that are little more than
  442.99 +     * wrappers for other throwables.
 442.100 +     *
 442.101 +     * @param  cause the cause (which is saved for later retrieval by the
 442.102 +     *         {@link #getCause()} method).  (A {@code null} value is
 442.103 +     *         permitted, and indicates that the cause is nonexistent or
 442.104 +     *         unknown.)
 442.105 +     * @since  1.4
 442.106 +     */
 442.107 +    public Error(Throwable cause) {
 442.108 +        super(cause);
 442.109 +    }
 442.110 +
 442.111 +    /**
 442.112 +     * Constructs a new error with the specified detail message,
 442.113 +     * cause, suppression enabled or disabled, and writable stack
 442.114 +     * trace enabled or disabled.
 442.115 +     *
 442.116 +     * @param  message the detail message.
 442.117 +     * @param cause the cause.  (A {@code null} value is permitted,
 442.118 +     * and indicates that the cause is nonexistent or unknown.)
 442.119 +     * @param enableSuppression whether or not suppression is enabled
 442.120 +     *                          or disabled
 442.121 +     * @param writableStackTrace whether or not the stack trace should
 442.122 +     *                           be writable
 442.123 +     *
 442.124 +     * @since 1.7
 442.125 +     */
 442.126 +    protected Error(String message, Throwable cause,
 442.127 +                    boolean enableSuppression,
 442.128 +                    boolean writableStackTrace) {
 442.129 +        super(message, cause, enableSuppression, writableStackTrace);
 442.130 +    }
 442.131 +}
   443.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   443.2 +++ b/rt/emul/mini/src/main/java/java/lang/Exception.java	Wed Feb 27 11:24:58 2013 +0100
   443.3 @@ -0,0 +1,124 @@
   443.4 +/*
   443.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   443.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   443.7 + *
   443.8 + * This code is free software; you can redistribute it and/or modify it
   443.9 + * under the terms of the GNU General Public License version 2 only, as
  443.10 + * published by the Free Software Foundation.  Oracle designates this
  443.11 + * particular file as subject to the "Classpath" exception as provided
  443.12 + * by Oracle in the LICENSE file that accompanied this code.
  443.13 + *
  443.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  443.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  443.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  443.17 + * version 2 for more details (a copy is included in the LICENSE file that
  443.18 + * accompanied this code).
  443.19 + *
  443.20 + * You should have received a copy of the GNU General Public License version
  443.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  443.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  443.23 + *
  443.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  443.25 + * or visit www.oracle.com if you need additional information or have any
  443.26 + * questions.
  443.27 + */
  443.28 +
  443.29 +package java.lang;
  443.30 +
  443.31 +/**
  443.32 + * The class {@code Exception} and its subclasses are a form of
  443.33 + * {@code Throwable} that indicates conditions that a reasonable
  443.34 + * application might want to catch.
  443.35 + *
  443.36 + * <p>The class {@code Exception} and any subclasses that are not also
  443.37 + * subclasses of {@link RuntimeException} are <em>checked
  443.38 + * exceptions</em>.  Checked exceptions need to be declared in a
  443.39 + * method or constructor's {@code throws} clause if they can be thrown
  443.40 + * by the execution of the method or constructor and propagate outside
  443.41 + * the method or constructor boundary.
  443.42 + *
  443.43 + * @author  Frank Yellin
  443.44 + * @see     java.lang.Error
  443.45 + * @jls 11.2 Compile-Time Checking of Exceptions
  443.46 + * @since   JDK1.0
  443.47 + */
  443.48 +public class Exception extends Throwable {
  443.49 +    static final long serialVersionUID = -3387516993124229948L;
  443.50 +
  443.51 +    /**
  443.52 +     * Constructs a new exception with {@code null} as its detail message.
  443.53 +     * The cause is not initialized, and may subsequently be initialized by a
  443.54 +     * call to {@link #initCause}.
  443.55 +     */
  443.56 +    public Exception() {
  443.57 +        super();
  443.58 +    }
  443.59 +
  443.60 +    /**
  443.61 +     * Constructs a new exception with the specified detail message.  The
  443.62 +     * cause is not initialized, and may subsequently be initialized by
  443.63 +     * a call to {@link #initCause}.
  443.64 +     *
  443.65 +     * @param   message   the detail message. The detail message is saved for
  443.66 +     *          later retrieval by the {@link #getMessage()} method.
  443.67 +     */
  443.68 +    public Exception(String message) {
  443.69 +        super(message);
  443.70 +    }
  443.71 +
  443.72 +    /**
  443.73 +     * Constructs a new exception with the specified detail message and
  443.74 +     * cause.  <p>Note that the detail message associated with
  443.75 +     * {@code cause} is <i>not</i> automatically incorporated in
  443.76 +     * this exception's detail message.
  443.77 +     *
  443.78 +     * @param  message the detail message (which is saved for later retrieval
  443.79 +     *         by the {@link #getMessage()} method).
  443.80 +     * @param  cause the cause (which is saved for later retrieval by the
  443.81 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  443.82 +     *         permitted, and indicates that the cause is nonexistent or
  443.83 +     *         unknown.)
  443.84 +     * @since  1.4
  443.85 +     */
  443.86 +    public Exception(String message, Throwable cause) {
  443.87 +        super(message, cause);
  443.88 +    }
  443.89 +
  443.90 +    /**
  443.91 +     * Constructs a new exception with the specified cause and a detail
  443.92 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  443.93 +     * typically contains the class and detail message of <tt>cause</tt>).
  443.94 +     * This constructor is useful for exceptions that are little more than
  443.95 +     * wrappers for other throwables (for example, {@link
  443.96 +     * java.security.PrivilegedActionException}).
  443.97 +     *
  443.98 +     * @param  cause the cause (which is saved for later retrieval by the
  443.99 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
 443.100 +     *         permitted, and indicates that the cause is nonexistent or
 443.101 +     *         unknown.)
 443.102 +     * @since  1.4
 443.103 +     */
 443.104 +    public Exception(Throwable cause) {
 443.105 +        super(cause);
 443.106 +    }
 443.107 +
 443.108 +    /**
 443.109 +     * Constructs a new exception with the specified detail message,
 443.110 +     * cause, suppression enabled or disabled, and writable stack
 443.111 +     * trace enabled or disabled.
 443.112 +     *
 443.113 +     * @param  message the detail message.
 443.114 +     * @param cause the cause.  (A {@code null} value is permitted,
 443.115 +     * and indicates that the cause is nonexistent or unknown.)
 443.116 +     * @param enableSuppression whether or not suppression is enabled
 443.117 +     *                          or disabled
 443.118 +     * @param writableStackTrace whether or not the stack trace should
 443.119 +     *                           be writable
 443.120 +     * @since 1.7
 443.121 +     */
 443.122 +    protected Exception(String message, Throwable cause,
 443.123 +                        boolean enableSuppression,
 443.124 +                        boolean writableStackTrace) {
 443.125 +        super(message, cause, enableSuppression, writableStackTrace);
 443.126 +    }
 443.127 +}
   444.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   444.2 +++ b/rt/emul/mini/src/main/java/java/lang/Float.java	Wed Feb 27 11:24:58 2013 +0100
   444.3 @@ -0,0 +1,909 @@
   444.4 +/*
   444.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   444.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   444.7 + *
   444.8 + * This code is free software; you can redistribute it and/or modify it
   444.9 + * under the terms of the GNU General Public License version 2 only, as
  444.10 + * published by the Free Software Foundation.  Oracle designates this
  444.11 + * particular file as subject to the "Classpath" exception as provided
  444.12 + * by Oracle in the LICENSE file that accompanied this code.
  444.13 + *
  444.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  444.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  444.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  444.17 + * version 2 for more details (a copy is included in the LICENSE file that
  444.18 + * accompanied this code).
  444.19 + *
  444.20 + * You should have received a copy of the GNU General Public License version
  444.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  444.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  444.23 + *
  444.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  444.25 + * or visit www.oracle.com if you need additional information or have any
  444.26 + * questions.
  444.27 + */
  444.28 +
  444.29 +package java.lang;
  444.30 +
  444.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  444.32 +
  444.33 +/**
  444.34 + * The {@code Float} class wraps a value of primitive type
  444.35 + * {@code float} in an object. An object of type
  444.36 + * {@code Float} contains a single field whose type is
  444.37 + * {@code float}.
  444.38 + *
  444.39 + * <p>In addition, this class provides several methods for converting a
  444.40 + * {@code float} to a {@code String} and a
  444.41 + * {@code String} to a {@code float}, as well as other
  444.42 + * constants and methods useful when dealing with a
  444.43 + * {@code float}.
  444.44 + *
  444.45 + * @author  Lee Boynton
  444.46 + * @author  Arthur van Hoff
  444.47 + * @author  Joseph D. Darcy
  444.48 + * @since JDK1.0
  444.49 + */
  444.50 +public final class Float extends Number implements Comparable<Float> {
  444.51 +    /**
  444.52 +     * A constant holding the positive infinity of type
  444.53 +     * {@code float}. It is equal to the value returned by
  444.54 +     * {@code Float.intBitsToFloat(0x7f800000)}.
  444.55 +     */
  444.56 +    public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  444.57 +
  444.58 +    /**
  444.59 +     * A constant holding the negative infinity of type
  444.60 +     * {@code float}. It is equal to the value returned by
  444.61 +     * {@code Float.intBitsToFloat(0xff800000)}.
  444.62 +     */
  444.63 +    public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  444.64 +
  444.65 +    /**
  444.66 +     * A constant holding a Not-a-Number (NaN) value of type
  444.67 +     * {@code float}.  It is equivalent to the value returned by
  444.68 +     * {@code Float.intBitsToFloat(0x7fc00000)}.
  444.69 +     */
  444.70 +    public static final float NaN = 0.0f / 0.0f;
  444.71 +
  444.72 +    /**
  444.73 +     * A constant holding the largest positive finite value of type
  444.74 +     * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
  444.75 +     * It is equal to the hexadecimal floating-point literal
  444.76 +     * {@code 0x1.fffffeP+127f} and also equal to
  444.77 +     * {@code Float.intBitsToFloat(0x7f7fffff)}.
  444.78 +     */
  444.79 +    public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
  444.80 +
  444.81 +    /**
  444.82 +     * A constant holding the smallest positive normal value of type
  444.83 +     * {@code float}, 2<sup>-126</sup>.  It is equal to the
  444.84 +     * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
  444.85 +     * equal to {@code Float.intBitsToFloat(0x00800000)}.
  444.86 +     *
  444.87 +     * @since 1.6
  444.88 +     */
  444.89 +    public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
  444.90 +
  444.91 +    /**
  444.92 +     * A constant holding the smallest positive nonzero value of type
  444.93 +     * {@code float}, 2<sup>-149</sup>. It is equal to the
  444.94 +     * hexadecimal floating-point literal {@code 0x0.000002P-126f}
  444.95 +     * and also equal to {@code Float.intBitsToFloat(0x1)}.
  444.96 +     */
  444.97 +    public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
  444.98 +
  444.99 +    /**
 444.100 +     * Maximum exponent a finite {@code float} variable may have.  It
 444.101 +     * is equal to the value returned by {@code
 444.102 +     * Math.getExponent(Float.MAX_VALUE)}.
 444.103 +     *
 444.104 +     * @since 1.6
 444.105 +     */
 444.106 +    public static final int MAX_EXPONENT = 127;
 444.107 +
 444.108 +    /**
 444.109 +     * Minimum exponent a normalized {@code float} variable may have.
 444.110 +     * It is equal to the value returned by {@code
 444.111 +     * Math.getExponent(Float.MIN_NORMAL)}.
 444.112 +     *
 444.113 +     * @since 1.6
 444.114 +     */
 444.115 +    public static final int MIN_EXPONENT = -126;
 444.116 +
 444.117 +    /**
 444.118 +     * The number of bits used to represent a {@code float} value.
 444.119 +     *
 444.120 +     * @since 1.5
 444.121 +     */
 444.122 +    public static final int SIZE = 32;
 444.123 +
 444.124 +    /**
 444.125 +     * The {@code Class} instance representing the primitive type
 444.126 +     * {@code float}.
 444.127 +     *
 444.128 +     * @since JDK1.1
 444.129 +     */
 444.130 +    public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
 444.131 +
 444.132 +    /**
 444.133 +     * Returns a string representation of the {@code float}
 444.134 +     * argument. All characters mentioned below are ASCII characters.
 444.135 +     * <ul>
 444.136 +     * <li>If the argument is NaN, the result is the string
 444.137 +     * "{@code NaN}".
 444.138 +     * <li>Otherwise, the result is a string that represents the sign and
 444.139 +     *     magnitude (absolute value) of the argument. If the sign is
 444.140 +     *     negative, the first character of the result is
 444.141 +     *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
 444.142 +     *     positive, no sign character appears in the result. As for
 444.143 +     *     the magnitude <i>m</i>:
 444.144 +     * <ul>
 444.145 +     * <li>If <i>m</i> is infinity, it is represented by the characters
 444.146 +     *     {@code "Infinity"}; thus, positive infinity produces
 444.147 +     *     the result {@code "Infinity"} and negative infinity
 444.148 +     *     produces the result {@code "-Infinity"}.
 444.149 +     * <li>If <i>m</i> is zero, it is represented by the characters
 444.150 +     *     {@code "0.0"}; thus, negative zero produces the result
 444.151 +     *     {@code "-0.0"} and positive zero produces the result
 444.152 +     *     {@code "0.0"}.
 444.153 +     * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
 444.154 +     *      less than 10<sup>7</sup>, then it is represented as the
 444.155 +     *      integer part of <i>m</i>, in decimal form with no leading
 444.156 +     *      zeroes, followed by '{@code .}'
 444.157 +     *      (<code>'&#92;u002E'</code>), followed by one or more
 444.158 +     *      decimal digits representing the fractional part of
 444.159 +     *      <i>m</i>.
 444.160 +     * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
 444.161 +     *      equal to 10<sup>7</sup>, then it is represented in
 444.162 +     *      so-called "computerized scientific notation." Let <i>n</i>
 444.163 +     *      be the unique integer such that 10<sup><i>n</i> </sup>&le;
 444.164 +     *      <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
 444.165 +     *      be the mathematically exact quotient of <i>m</i> and
 444.166 +     *      10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10.
 444.167 +     *      The magnitude is then represented as the integer part of
 444.168 +     *      <i>a</i>, as a single decimal digit, followed by
 444.169 +     *      '{@code .}' (<code>'&#92;u002E'</code>), followed by
 444.170 +     *      decimal digits representing the fractional part of
 444.171 +     *      <i>a</i>, followed by the letter '{@code E}'
 444.172 +     *      (<code>'&#92;u0045'</code>), followed by a representation
 444.173 +     *      of <i>n</i> as a decimal integer, as produced by the
 444.174 +     *      method {@link java.lang.Integer#toString(int)}.
 444.175 +     *
 444.176 +     * </ul>
 444.177 +     * </ul>
 444.178 +     * How many digits must be printed for the fractional part of
 444.179 +     * <i>m</i> or <i>a</i>? There must be at least one digit
 444.180 +     * to represent the fractional part, and beyond that as many, but
 444.181 +     * only as many, more digits as are needed to uniquely distinguish
 444.182 +     * the argument value from adjacent values of type
 444.183 +     * {@code float}. That is, suppose that <i>x</i> is the
 444.184 +     * exact mathematical value represented by the decimal
 444.185 +     * representation produced by this method for a finite nonzero
 444.186 +     * argument <i>f</i>. Then <i>f</i> must be the {@code float}
 444.187 +     * value nearest to <i>x</i>; or, if two {@code float} values are
 444.188 +     * equally close to <i>x</i>, then <i>f</i> must be one of
 444.189 +     * them and the least significant bit of the significand of
 444.190 +     * <i>f</i> must be {@code 0}.
 444.191 +     *
 444.192 +     * <p>To create localized string representations of a floating-point
 444.193 +     * value, use subclasses of {@link java.text.NumberFormat}.
 444.194 +     *
 444.195 +     * @param   f   the float to be converted.
 444.196 +     * @return a string representation of the argument.
 444.197 +     */
 444.198 +    public static String toString(float f) {
 444.199 +        return Double.toString(f);
 444.200 +    }
 444.201 +
 444.202 +    /**
 444.203 +     * Returns a hexadecimal string representation of the
 444.204 +     * {@code float} argument. All characters mentioned below are
 444.205 +     * ASCII characters.
 444.206 +     *
 444.207 +     * <ul>
 444.208 +     * <li>If the argument is NaN, the result is the string
 444.209 +     *     "{@code NaN}".
 444.210 +     * <li>Otherwise, the result is a string that represents the sign and
 444.211 +     * magnitude (absolute value) of the argument. If the sign is negative,
 444.212 +     * the first character of the result is '{@code -}'
 444.213 +     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
 444.214 +     * appears in the result. As for the magnitude <i>m</i>:
 444.215 +     *
 444.216 +     * <ul>
 444.217 +     * <li>If <i>m</i> is infinity, it is represented by the string
 444.218 +     * {@code "Infinity"}; thus, positive infinity produces the
 444.219 +     * result {@code "Infinity"} and negative infinity produces
 444.220 +     * the result {@code "-Infinity"}.
 444.221 +     *
 444.222 +     * <li>If <i>m</i> is zero, it is represented by the string
 444.223 +     * {@code "0x0.0p0"}; thus, negative zero produces the result
 444.224 +     * {@code "-0x0.0p0"} and positive zero produces the result
 444.225 +     * {@code "0x0.0p0"}.
 444.226 +     *
 444.227 +     * <li>If <i>m</i> is a {@code float} value with a
 444.228 +     * normalized representation, substrings are used to represent the
 444.229 +     * significand and exponent fields.  The significand is
 444.230 +     * represented by the characters {@code "0x1."}
 444.231 +     * followed by a lowercase hexadecimal representation of the rest
 444.232 +     * of the significand as a fraction.  Trailing zeros in the
 444.233 +     * hexadecimal representation are removed unless all the digits
 444.234 +     * are zero, in which case a single zero is used. Next, the
 444.235 +     * exponent is represented by {@code "p"} followed
 444.236 +     * by a decimal string of the unbiased exponent as if produced by
 444.237 +     * a call to {@link Integer#toString(int) Integer.toString} on the
 444.238 +     * exponent value.
 444.239 +     *
 444.240 +     * <li>If <i>m</i> is a {@code float} value with a subnormal
 444.241 +     * representation, the significand is represented by the
 444.242 +     * characters {@code "0x0."} followed by a
 444.243 +     * hexadecimal representation of the rest of the significand as a
 444.244 +     * fraction.  Trailing zeros in the hexadecimal representation are
 444.245 +     * removed. Next, the exponent is represented by
 444.246 +     * {@code "p-126"}.  Note that there must be at
 444.247 +     * least one nonzero digit in a subnormal significand.
 444.248 +     *
 444.249 +     * </ul>
 444.250 +     *
 444.251 +     * </ul>
 444.252 +     *
 444.253 +     * <table border>
 444.254 +     * <caption><h3>Examples</h3></caption>
 444.255 +     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
 444.256 +     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
 444.257 +     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
 444.258 +     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
 444.259 +     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
 444.260 +     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
 444.261 +     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
 444.262 +     * <tr><td>{@code Float.MAX_VALUE}</td>
 444.263 +     *     <td>{@code 0x1.fffffep127}</td>
 444.264 +     * <tr><td>{@code Minimum Normal Value}</td>
 444.265 +     *     <td>{@code 0x1.0p-126}</td>
 444.266 +     * <tr><td>{@code Maximum Subnormal Value}</td>
 444.267 +     *     <td>{@code 0x0.fffffep-126}</td>
 444.268 +     * <tr><td>{@code Float.MIN_VALUE}</td>
 444.269 +     *     <td>{@code 0x0.000002p-126}</td>
 444.270 +     * </table>
 444.271 +     * @param   f   the {@code float} to be converted.
 444.272 +     * @return a hex string representation of the argument.
 444.273 +     * @since 1.5
 444.274 +     * @author Joseph D. Darcy
 444.275 +     */
 444.276 +    public static String toHexString(float f) {
 444.277 +        throw new UnsupportedOperationException();
 444.278 +//        if (Math.abs(f) < FloatConsts.MIN_NORMAL
 444.279 +//            &&  f != 0.0f ) {// float subnormal
 444.280 +//            // Adjust exponent to create subnormal double, then
 444.281 +//            // replace subnormal double exponent with subnormal float
 444.282 +//            // exponent
 444.283 +//            String s = Double.toHexString(FpUtils.scalb((double)f,
 444.284 +//                                                        /* -1022+126 */
 444.285 +//                                                        DoubleConsts.MIN_EXPONENT-
 444.286 +//                                                        FloatConsts.MIN_EXPONENT));
 444.287 +//            return s.replaceFirst("p-1022$", "p-126");
 444.288 +//        }
 444.289 +//        else // double string will be the same as float string
 444.290 +//            return Double.toHexString(f);
 444.291 +    }
 444.292 +
 444.293 +    /**
 444.294 +     * Returns a {@code Float} object holding the
 444.295 +     * {@code float} value represented by the argument string
 444.296 +     * {@code s}.
 444.297 +     *
 444.298 +     * <p>If {@code s} is {@code null}, then a
 444.299 +     * {@code NullPointerException} is thrown.
 444.300 +     *
 444.301 +     * <p>Leading and trailing whitespace characters in {@code s}
 444.302 +     * are ignored.  Whitespace is removed as if by the {@link
 444.303 +     * String#trim} method; that is, both ASCII space and control
 444.304 +     * characters are removed. The rest of {@code s} should
 444.305 +     * constitute a <i>FloatValue</i> as described by the lexical
 444.306 +     * syntax rules:
 444.307 +     *
 444.308 +     * <blockquote>
 444.309 +     * <dl>
 444.310 +     * <dt><i>FloatValue:</i>
 444.311 +     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
 444.312 +     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
 444.313 +     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
 444.314 +     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
 444.315 +     * <dd><i>SignedInteger</i>
 444.316 +     * </dl>
 444.317 +     *
 444.318 +     * <p>
 444.319 +     *
 444.320 +     * <dl>
 444.321 +     * <dt><i>HexFloatingPointLiteral</i>:
 444.322 +     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
 444.323 +     * </dl>
 444.324 +     *
 444.325 +     * <p>
 444.326 +     *
 444.327 +     * <dl>
 444.328 +     * <dt><i>HexSignificand:</i>
 444.329 +     * <dd><i>HexNumeral</i>
 444.330 +     * <dd><i>HexNumeral</i> {@code .}
 444.331 +     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
 444.332 +     *     </i>{@code .}<i> HexDigits</i>
 444.333 +     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
 444.334 +     *     </i>{@code .} <i>HexDigits</i>
 444.335 +     * </dl>
 444.336 +     *
 444.337 +     * <p>
 444.338 +     *
 444.339 +     * <dl>
 444.340 +     * <dt><i>BinaryExponent:</i>
 444.341 +     * <dd><i>BinaryExponentIndicator SignedInteger</i>
 444.342 +     * </dl>
 444.343 +     *
 444.344 +     * <p>
 444.345 +     *
 444.346 +     * <dl>
 444.347 +     * <dt><i>BinaryExponentIndicator:</i>
 444.348 +     * <dd>{@code p}
 444.349 +     * <dd>{@code P}
 444.350 +     * </dl>
 444.351 +     *
 444.352 +     * </blockquote>
 444.353 +     *
 444.354 +     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 444.355 +     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 444.356 +     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 444.357 +     * sections of
 444.358 +     * <cite>The Java&trade; Language Specification</cite>,
 444.359 +     * except that underscores are not accepted between digits.
 444.360 +     * If {@code s} does not have the form of
 444.361 +     * a <i>FloatValue</i>, then a {@code NumberFormatException}
 444.362 +     * is thrown. Otherwise, {@code s} is regarded as
 444.363 +     * representing an exact decimal value in the usual
 444.364 +     * "computerized scientific notation" or as an exact
 444.365 +     * hexadecimal value; this exact numerical value is then
 444.366 +     * conceptually converted to an "infinitely precise"
 444.367 +     * binary value that is then rounded to type {@code float}
 444.368 +     * by the usual round-to-nearest rule of IEEE 754 floating-point
 444.369 +     * arithmetic, which includes preserving the sign of a zero
 444.370 +     * value.
 444.371 +     *
 444.372 +     * Note that the round-to-nearest rule also implies overflow and
 444.373 +     * underflow behaviour; if the exact value of {@code s} is large
 444.374 +     * enough in magnitude (greater than or equal to ({@link
 444.375 +     * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
 444.376 +     * rounding to {@code float} will result in an infinity and if the
 444.377 +     * exact value of {@code s} is small enough in magnitude (less
 444.378 +     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 444.379 +     * result in a zero.
 444.380 +     *
 444.381 +     * Finally, after rounding a {@code Float} object representing
 444.382 +     * this {@code float} value is returned.
 444.383 +     *
 444.384 +     * <p>To interpret localized string representations of a
 444.385 +     * floating-point value, use subclasses of {@link
 444.386 +     * java.text.NumberFormat}.
 444.387 +     *
 444.388 +     * <p>Note that trailing format specifiers, specifiers that
 444.389 +     * determine the type of a floating-point literal
 444.390 +     * ({@code 1.0f} is a {@code float} value;
 444.391 +     * {@code 1.0d} is a {@code double} value), do
 444.392 +     * <em>not</em> influence the results of this method.  In other
 444.393 +     * words, the numerical value of the input string is converted
 444.394 +     * directly to the target floating-point type.  In general, the
 444.395 +     * two-step sequence of conversions, string to {@code double}
 444.396 +     * followed by {@code double} to {@code float}, is
 444.397 +     * <em>not</em> equivalent to converting a string directly to
 444.398 +     * {@code float}.  For example, if first converted to an
 444.399 +     * intermediate {@code double} and then to
 444.400 +     * {@code float}, the string<br>
 444.401 +     * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
 444.402 +     * results in the {@code float} value
 444.403 +     * {@code 1.0000002f}; if the string is converted directly to
 444.404 +     * {@code float}, <code>1.000000<b>1</b>f</code> results.
 444.405 +     *
 444.406 +     * <p>To avoid calling this method on an invalid string and having
 444.407 +     * a {@code NumberFormatException} be thrown, the documentation
 444.408 +     * for {@link Double#valueOf Double.valueOf} lists a regular
 444.409 +     * expression which can be used to screen the input.
 444.410 +     *
 444.411 +     * @param   s   the string to be parsed.
 444.412 +     * @return  a {@code Float} object holding the value
 444.413 +     *          represented by the {@code String} argument.
 444.414 +     * @throws  NumberFormatException  if the string does not contain a
 444.415 +     *          parsable number.
 444.416 +     */
 444.417 +    public static Float valueOf(String s) throws NumberFormatException {
 444.418 +        throw new UnsupportedOperationException();
 444.419 +//        return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
 444.420 +    }
 444.421 +
 444.422 +    /**
 444.423 +     * Returns a {@code Float} instance representing the specified
 444.424 +     * {@code float} value.
 444.425 +     * If a new {@code Float} instance is not required, this method
 444.426 +     * should generally be used in preference to the constructor
 444.427 +     * {@link #Float(float)}, as this method is likely to yield
 444.428 +     * significantly better space and time performance by caching
 444.429 +     * frequently requested values.
 444.430 +     *
 444.431 +     * @param  f a float value.
 444.432 +     * @return a {@code Float} instance representing {@code f}.
 444.433 +     * @since  1.5
 444.434 +     */
 444.435 +    public static Float valueOf(float f) {
 444.436 +        return new Float(f);
 444.437 +    }
 444.438 +
 444.439 +    /**
 444.440 +     * Returns a new {@code float} initialized to the value
 444.441 +     * represented by the specified {@code String}, as performed
 444.442 +     * by the {@code valueOf} method of class {@code Float}.
 444.443 +     *
 444.444 +     * @param  s the string to be parsed.
 444.445 +     * @return the {@code float} value represented by the string
 444.446 +     *         argument.
 444.447 +     * @throws NullPointerException  if the string is null
 444.448 +     * @throws NumberFormatException if the string does not contain a
 444.449 +     *               parsable {@code float}.
 444.450 +     * @see    java.lang.Float#valueOf(String)
 444.451 +     * @since 1.2
 444.452 +     */
 444.453 +    public static float parseFloat(String s) throws NumberFormatException {
 444.454 +        throw new UnsupportedOperationException();
 444.455 +//        return FloatingDecimal.readJavaFormatString(s).floatValue();
 444.456 +    }
 444.457 +
 444.458 +    /**
 444.459 +     * Returns {@code true} if the specified number is a
 444.460 +     * Not-a-Number (NaN) value, {@code false} otherwise.
 444.461 +     *
 444.462 +     * @param   v   the value to be tested.
 444.463 +     * @return  {@code true} if the argument is NaN;
 444.464 +     *          {@code false} otherwise.
 444.465 +     */
 444.466 +    static public boolean isNaN(float v) {
 444.467 +        return (v != v);
 444.468 +    }
 444.469 +
 444.470 +    /**
 444.471 +     * Returns {@code true} if the specified number is infinitely
 444.472 +     * large in magnitude, {@code false} otherwise.
 444.473 +     *
 444.474 +     * @param   v   the value to be tested.
 444.475 +     * @return  {@code true} if the argument is positive infinity or
 444.476 +     *          negative infinity; {@code false} otherwise.
 444.477 +     */
 444.478 +    static public boolean isInfinite(float v) {
 444.479 +        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
 444.480 +    }
 444.481 +
 444.482 +    /**
 444.483 +     * The value of the Float.
 444.484 +     *
 444.485 +     * @serial
 444.486 +     */
 444.487 +    private final float value;
 444.488 +
 444.489 +    /**
 444.490 +     * Constructs a newly allocated {@code Float} object that
 444.491 +     * represents the primitive {@code float} argument.
 444.492 +     *
 444.493 +     * @param   value   the value to be represented by the {@code Float}.
 444.494 +     */
 444.495 +    public Float(float value) {
 444.496 +        this.value = value;
 444.497 +    }
 444.498 +
 444.499 +    /**
 444.500 +     * Constructs a newly allocated {@code Float} object that
 444.501 +     * represents the argument converted to type {@code float}.
 444.502 +     *
 444.503 +     * @param   value   the value to be represented by the {@code Float}.
 444.504 +     */
 444.505 +    public Float(double value) {
 444.506 +        this.value = (float)value;
 444.507 +    }
 444.508 +
 444.509 +    /**
 444.510 +     * Constructs a newly allocated {@code Float} object that
 444.511 +     * represents the floating-point value of type {@code float}
 444.512 +     * represented by the string. The string is converted to a
 444.513 +     * {@code float} value as if by the {@code valueOf} method.
 444.514 +     *
 444.515 +     * @param      s   a string to be converted to a {@code Float}.
 444.516 +     * @throws  NumberFormatException  if the string does not contain a
 444.517 +     *               parsable number.
 444.518 +     * @see        java.lang.Float#valueOf(java.lang.String)
 444.519 +     */
 444.520 +    public Float(String s) throws NumberFormatException {
 444.521 +        // REMIND: this is inefficient
 444.522 +        this(valueOf(s).floatValue());
 444.523 +    }
 444.524 +
 444.525 +    /**
 444.526 +     * Returns {@code true} if this {@code Float} value is a
 444.527 +     * Not-a-Number (NaN), {@code false} otherwise.
 444.528 +     *
 444.529 +     * @return  {@code true} if the value represented by this object is
 444.530 +     *          NaN; {@code false} otherwise.
 444.531 +     */
 444.532 +    public boolean isNaN() {
 444.533 +        return isNaN(value);
 444.534 +    }
 444.535 +
 444.536 +    /**
 444.537 +     * Returns {@code true} if this {@code Float} value is
 444.538 +     * infinitely large in magnitude, {@code false} otherwise.
 444.539 +     *
 444.540 +     * @return  {@code true} if the value represented by this object is
 444.541 +     *          positive infinity or negative infinity;
 444.542 +     *          {@code false} otherwise.
 444.543 +     */
 444.544 +    public boolean isInfinite() {
 444.545 +        return isInfinite(value);
 444.546 +    }
 444.547 +
 444.548 +    /**
 444.549 +     * Returns a string representation of this {@code Float} object.
 444.550 +     * The primitive {@code float} value represented by this object
 444.551 +     * is converted to a {@code String} exactly as if by the method
 444.552 +     * {@code toString} of one argument.
 444.553 +     *
 444.554 +     * @return  a {@code String} representation of this object.
 444.555 +     * @see java.lang.Float#toString(float)
 444.556 +     */
 444.557 +    public String toString() {
 444.558 +        return Float.toString(value);
 444.559 +    }
 444.560 +
 444.561 +    /**
 444.562 +     * Returns the value of this {@code Float} as a {@code byte} (by
 444.563 +     * casting to a {@code byte}).
 444.564 +     *
 444.565 +     * @return  the {@code float} value represented by this object
 444.566 +     *          converted to type {@code byte}
 444.567 +     */
 444.568 +    public byte byteValue() {
 444.569 +        return (byte)value;
 444.570 +    }
 444.571 +
 444.572 +    /**
 444.573 +     * Returns the value of this {@code Float} as a {@code short} (by
 444.574 +     * casting to a {@code short}).
 444.575 +     *
 444.576 +     * @return  the {@code float} value represented by this object
 444.577 +     *          converted to type {@code short}
 444.578 +     * @since JDK1.1
 444.579 +     */
 444.580 +    public short shortValue() {
 444.581 +        return (short)value;
 444.582 +    }
 444.583 +
 444.584 +    /**
 444.585 +     * Returns the value of this {@code Float} as an {@code int} (by
 444.586 +     * casting to type {@code int}).
 444.587 +     *
 444.588 +     * @return  the {@code float} value represented by this object
 444.589 +     *          converted to type {@code int}
 444.590 +     */
 444.591 +    public int intValue() {
 444.592 +        return (int)value;
 444.593 +    }
 444.594 +
 444.595 +    /**
 444.596 +     * Returns value of this {@code Float} as a {@code long} (by
 444.597 +     * casting to type {@code long}).
 444.598 +     *
 444.599 +     * @return  the {@code float} value represented by this object
 444.600 +     *          converted to type {@code long}
 444.601 +     */
 444.602 +    public long longValue() {
 444.603 +        return (long)value;
 444.604 +    }
 444.605 +
 444.606 +    /**
 444.607 +     * Returns the {@code float} value of this {@code Float} object.
 444.608 +     *
 444.609 +     * @return the {@code float} value represented by this object
 444.610 +     */
 444.611 +    public float floatValue() {
 444.612 +        return value;
 444.613 +    }
 444.614 +
 444.615 +    /**
 444.616 +     * Returns the {@code double} value of this {@code Float} object.
 444.617 +     *
 444.618 +     * @return the {@code float} value represented by this
 444.619 +     *         object is converted to type {@code double} and the
 444.620 +     *         result of the conversion is returned.
 444.621 +     */
 444.622 +    public double doubleValue() {
 444.623 +        return (double)value;
 444.624 +    }
 444.625 +
 444.626 +    /**
 444.627 +     * Returns a hash code for this {@code Float} object. The
 444.628 +     * result is the integer bit representation, exactly as produced
 444.629 +     * by the method {@link #floatToIntBits(float)}, of the primitive
 444.630 +     * {@code float} value represented by this {@code Float}
 444.631 +     * object.
 444.632 +     *
 444.633 +     * @return a hash code value for this object.
 444.634 +     */
 444.635 +    public int hashCode() {
 444.636 +        return floatToIntBits(value);
 444.637 +    }
 444.638 +
 444.639 +    /**
 444.640 +
 444.641 +     * Compares this object against the specified object.  The result
 444.642 +     * is {@code true} if and only if the argument is not
 444.643 +     * {@code null} and is a {@code Float} object that
 444.644 +     * represents a {@code float} with the same value as the
 444.645 +     * {@code float} represented by this object. For this
 444.646 +     * purpose, two {@code float} values are considered to be the
 444.647 +     * same if and only if the method {@link #floatToIntBits(float)}
 444.648 +     * returns the identical {@code int} value when applied to
 444.649 +     * each.
 444.650 +     *
 444.651 +     * <p>Note that in most cases, for two instances of class
 444.652 +     * {@code Float}, {@code f1} and {@code f2}, the value
 444.653 +     * of {@code f1.equals(f2)} is {@code true} if and only if
 444.654 +     *
 444.655 +     * <blockquote><pre>
 444.656 +     *   f1.floatValue() == f2.floatValue()
 444.657 +     * </pre></blockquote>
 444.658 +     *
 444.659 +     * <p>also has the value {@code true}. However, there are two exceptions:
 444.660 +     * <ul>
 444.661 +     * <li>If {@code f1} and {@code f2} both represent
 444.662 +     *     {@code Float.NaN}, then the {@code equals} method returns
 444.663 +     *     {@code true}, even though {@code Float.NaN==Float.NaN}
 444.664 +     *     has the value {@code false}.
 444.665 +     * <li>If {@code f1} represents {@code +0.0f} while
 444.666 +     *     {@code f2} represents {@code -0.0f}, or vice
 444.667 +     *     versa, the {@code equal} test has the value
 444.668 +     *     {@code false}, even though {@code 0.0f==-0.0f}
 444.669 +     *     has the value {@code true}.
 444.670 +     * </ul>
 444.671 +     *
 444.672 +     * This definition allows hash tables to operate properly.
 444.673 +     *
 444.674 +     * @param obj the object to be compared
 444.675 +     * @return  {@code true} if the objects are the same;
 444.676 +     *          {@code false} otherwise.
 444.677 +     * @see java.lang.Float#floatToIntBits(float)
 444.678 +     */
 444.679 +    public boolean equals(Object obj) {
 444.680 +        return (obj instanceof Float)
 444.681 +               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
 444.682 +    }
 444.683 +
 444.684 +    /**
 444.685 +     * Returns a representation of the specified floating-point value
 444.686 +     * according to the IEEE 754 floating-point "single format" bit
 444.687 +     * layout.
 444.688 +     *
 444.689 +     * <p>Bit 31 (the bit that is selected by the mask
 444.690 +     * {@code 0x80000000}) represents the sign of the floating-point
 444.691 +     * number.
 444.692 +     * Bits 30-23 (the bits that are selected by the mask
 444.693 +     * {@code 0x7f800000}) represent the exponent.
 444.694 +     * Bits 22-0 (the bits that are selected by the mask
 444.695 +     * {@code 0x007fffff}) represent the significand (sometimes called
 444.696 +     * the mantissa) of the floating-point number.
 444.697 +     *
 444.698 +     * <p>If the argument is positive infinity, the result is
 444.699 +     * {@code 0x7f800000}.
 444.700 +     *
 444.701 +     * <p>If the argument is negative infinity, the result is
 444.702 +     * {@code 0xff800000}.
 444.703 +     *
 444.704 +     * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
 444.705 +     *
 444.706 +     * <p>In all cases, the result is an integer that, when given to the
 444.707 +     * {@link #intBitsToFloat(int)} method, will produce a floating-point
 444.708 +     * value the same as the argument to {@code floatToIntBits}
 444.709 +     * (except all NaN values are collapsed to a single
 444.710 +     * "canonical" NaN value).
 444.711 +     *
 444.712 +     * @param   value   a floating-point number.
 444.713 +     * @return the bits that represent the floating-point number.
 444.714 +     */
 444.715 +    public static int floatToIntBits(float value) {
 444.716 +        throw new UnsupportedOperationException();
 444.717 +//        int result = floatToRawIntBits(value);
 444.718 +//        // Check for NaN based on values of bit fields, maximum
 444.719 +//        // exponent and nonzero significand.
 444.720 +//        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
 444.721 +//              FloatConsts.EXP_BIT_MASK) &&
 444.722 +//             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
 444.723 +//            result = 0x7fc00000;
 444.724 +//        return result;
 444.725 +    }
 444.726 +
 444.727 +    /**
 444.728 +     * Returns a representation of the specified floating-point value
 444.729 +     * according to the IEEE 754 floating-point "single format" bit
 444.730 +     * layout, preserving Not-a-Number (NaN) values.
 444.731 +     *
 444.732 +     * <p>Bit 31 (the bit that is selected by the mask
 444.733 +     * {@code 0x80000000}) represents the sign of the floating-point
 444.734 +     * number.
 444.735 +     * Bits 30-23 (the bits that are selected by the mask
 444.736 +     * {@code 0x7f800000}) represent the exponent.
 444.737 +     * Bits 22-0 (the bits that are selected by the mask
 444.738 +     * {@code 0x007fffff}) represent the significand (sometimes called
 444.739 +     * the mantissa) of the floating-point number.
 444.740 +     *
 444.741 +     * <p>If the argument is positive infinity, the result is
 444.742 +     * {@code 0x7f800000}.
 444.743 +     *
 444.744 +     * <p>If the argument is negative infinity, the result is
 444.745 +     * {@code 0xff800000}.
 444.746 +     *
 444.747 +     * <p>If the argument is NaN, the result is the integer representing
 444.748 +     * the actual NaN value.  Unlike the {@code floatToIntBits}
 444.749 +     * method, {@code floatToRawIntBits} does not collapse all the
 444.750 +     * bit patterns encoding a NaN to a single "canonical"
 444.751 +     * NaN value.
 444.752 +     *
 444.753 +     * <p>In all cases, the result is an integer that, when given to the
 444.754 +     * {@link #intBitsToFloat(int)} method, will produce a
 444.755 +     * floating-point value the same as the argument to
 444.756 +     * {@code floatToRawIntBits}.
 444.757 +     *
 444.758 +     * @param   value   a floating-point number.
 444.759 +     * @return the bits that represent the floating-point number.
 444.760 +     * @since 1.3
 444.761 +     */
 444.762 +    public static native int floatToRawIntBits(float value);
 444.763 +
 444.764 +    /**
 444.765 +     * Returns the {@code float} value corresponding to a given
 444.766 +     * bit representation.
 444.767 +     * The argument is considered to be a representation of a
 444.768 +     * floating-point value according to the IEEE 754 floating-point
 444.769 +     * "single format" bit layout.
 444.770 +     *
 444.771 +     * <p>If the argument is {@code 0x7f800000}, the result is positive
 444.772 +     * infinity.
 444.773 +     *
 444.774 +     * <p>If the argument is {@code 0xff800000}, the result is negative
 444.775 +     * infinity.
 444.776 +     *
 444.777 +     * <p>If the argument is any value in the range
 444.778 +     * {@code 0x7f800001} through {@code 0x7fffffff} or in
 444.779 +     * the range {@code 0xff800001} through
 444.780 +     * {@code 0xffffffff}, the result is a NaN.  No IEEE 754
 444.781 +     * floating-point operation provided by Java can distinguish
 444.782 +     * between two NaN values of the same type with different bit
 444.783 +     * patterns.  Distinct values of NaN are only distinguishable by
 444.784 +     * use of the {@code Float.floatToRawIntBits} method.
 444.785 +     *
 444.786 +     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
 444.787 +     * values that can be computed from the argument:
 444.788 +     *
 444.789 +     * <blockquote><pre>
 444.790 +     * int s = ((bits &gt;&gt; 31) == 0) ? 1 : -1;
 444.791 +     * int e = ((bits &gt;&gt; 23) & 0xff);
 444.792 +     * int m = (e == 0) ?
 444.793 +     *                 (bits & 0x7fffff) &lt;&lt; 1 :
 444.794 +     *                 (bits & 0x7fffff) | 0x800000;
 444.795 +     * </pre></blockquote>
 444.796 +     *
 444.797 +     * Then the floating-point result equals the value of the mathematical
 444.798 +     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-150</sup>.
 444.799 +     *
 444.800 +     * <p>Note that this method may not be able to return a
 444.801 +     * {@code float} NaN with exactly same bit pattern as the
 444.802 +     * {@code int} argument.  IEEE 754 distinguishes between two
 444.803 +     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
 444.804 +     * differences between the two kinds of NaN are generally not
 444.805 +     * visible in Java.  Arithmetic operations on signaling NaNs turn
 444.806 +     * them into quiet NaNs with a different, but often similar, bit
 444.807 +     * pattern.  However, on some processors merely copying a
 444.808 +     * signaling NaN also performs that conversion.  In particular,
 444.809 +     * copying a signaling NaN to return it to the calling method may
 444.810 +     * perform this conversion.  So {@code intBitsToFloat} may
 444.811 +     * not be able to return a {@code float} with a signaling NaN
 444.812 +     * bit pattern.  Consequently, for some {@code int} values,
 444.813 +     * {@code floatToRawIntBits(intBitsToFloat(start))} may
 444.814 +     * <i>not</i> equal {@code start}.  Moreover, which
 444.815 +     * particular bit patterns represent signaling NaNs is platform
 444.816 +     * dependent; although all NaN bit patterns, quiet or signaling,
 444.817 +     * must be in the NaN range identified above.
 444.818 +     *
 444.819 +     * @param   bits   an integer.
 444.820 +     * @return  the {@code float} floating-point value with the same bit
 444.821 +     *          pattern.
 444.822 +     */
 444.823 +    @JavaScriptBody(args = "bits",
 444.824 +        body = 
 444.825 +          "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
 444.826 +        + "var e = ((bits >> 23) & 0xff);\n"
 444.827 +        + "if (e === 0xff) {\n"
 444.828 +        + "    if ((bits & 0x7fffff) === 0) {\n"
 444.829 +        + "        return (s > 0) ? Number.POSITIVE_INFINITY"
 444.830 +                              + " : Number.NEGATIVE_INFINITY;\n"
 444.831 +        + "    }\n"
 444.832 +        + "    return Number.NaN;\n"
 444.833 +        + "}\n"
 444.834 +        + "var m = (e == 0) ?\n"
 444.835 +        + "  (bits & 0x7fffff) << 1 :\n"
 444.836 +        + "  (bits & 0x7fffff) | 0x800000;\n"
 444.837 +        + "return s * m * Math.pow(2.0, e - 150);\n"
 444.838 +    )
 444.839 +    public static native float intBitsToFloat(int bits);
 444.840 +
 444.841 +    /**
 444.842 +     * Compares two {@code Float} objects numerically.  There are
 444.843 +     * two ways in which comparisons performed by this method differ
 444.844 +     * from those performed by the Java language numerical comparison
 444.845 +     * operators ({@code <, <=, ==, >=, >}) when
 444.846 +     * applied to primitive {@code float} values:
 444.847 +     *
 444.848 +     * <ul><li>
 444.849 +     *          {@code Float.NaN} is considered by this method to
 444.850 +     *          be equal to itself and greater than all other
 444.851 +     *          {@code float} values
 444.852 +     *          (including {@code Float.POSITIVE_INFINITY}).
 444.853 +     * <li>
 444.854 +     *          {@code 0.0f} is considered by this method to be greater
 444.855 +     *          than {@code -0.0f}.
 444.856 +     * </ul>
 444.857 +     *
 444.858 +     * This ensures that the <i>natural ordering</i> of {@code Float}
 444.859 +     * objects imposed by this method is <i>consistent with equals</i>.
 444.860 +     *
 444.861 +     * @param   anotherFloat   the {@code Float} to be compared.
 444.862 +     * @return  the value {@code 0} if {@code anotherFloat} is
 444.863 +     *          numerically equal to this {@code Float}; a value
 444.864 +     *          less than {@code 0} if this {@code Float}
 444.865 +     *          is numerically less than {@code anotherFloat};
 444.866 +     *          and a value greater than {@code 0} if this
 444.867 +     *          {@code Float} is numerically greater than
 444.868 +     *          {@code anotherFloat}.
 444.869 +     *
 444.870 +     * @since   1.2
 444.871 +     * @see Comparable#compareTo(Object)
 444.872 +     */
 444.873 +    public int compareTo(Float anotherFloat) {
 444.874 +        return Float.compare(value, anotherFloat.value);
 444.875 +    }
 444.876 +
 444.877 +    /**
 444.878 +     * Compares the two specified {@code float} values. The sign
 444.879 +     * of the integer value returned is the same as that of the
 444.880 +     * integer that would be returned by the call:
 444.881 +     * <pre>
 444.882 +     *    new Float(f1).compareTo(new Float(f2))
 444.883 +     * </pre>
 444.884 +     *
 444.885 +     * @param   f1        the first {@code float} to compare.
 444.886 +     * @param   f2        the second {@code float} to compare.
 444.887 +     * @return  the value {@code 0} if {@code f1} is
 444.888 +     *          numerically equal to {@code f2}; a value less than
 444.889 +     *          {@code 0} if {@code f1} is numerically less than
 444.890 +     *          {@code f2}; and a value greater than {@code 0}
 444.891 +     *          if {@code f1} is numerically greater than
 444.892 +     *          {@code f2}.
 444.893 +     * @since 1.4
 444.894 +     */
 444.895 +    public static int compare(float f1, float f2) {
 444.896 +        if (f1 < f2)
 444.897 +            return -1;           // Neither val is NaN, thisVal is smaller
 444.898 +        if (f1 > f2)
 444.899 +            return 1;            // Neither val is NaN, thisVal is larger
 444.900 +
 444.901 +        // Cannot use floatToRawIntBits because of possibility of NaNs.
 444.902 +        int thisBits    = Float.floatToIntBits(f1);
 444.903 +        int anotherBits = Float.floatToIntBits(f2);
 444.904 +
 444.905 +        return (thisBits == anotherBits ?  0 : // Values are equal
 444.906 +                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
 444.907 +                 1));                          // (0.0, -0.0) or (NaN, !NaN)
 444.908 +    }
 444.909 +
 444.910 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 444.911 +    private static final long serialVersionUID = -2671257302660747028L;
 444.912 +}
   445.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   445.2 +++ b/rt/emul/mini/src/main/java/java/lang/IllegalAccessError.java	Wed Feb 27 11:24:58 2013 +0100
   445.3 @@ -0,0 +1,58 @@
   445.4 +/*
   445.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   445.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   445.7 + *
   445.8 + * This code is free software; you can redistribute it and/or modify it
   445.9 + * under the terms of the GNU General Public License version 2 only, as
  445.10 + * published by the Free Software Foundation.  Oracle designates this
  445.11 + * particular file as subject to the "Classpath" exception as provided
  445.12 + * by Oracle in the LICENSE file that accompanied this code.
  445.13 + *
  445.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  445.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  445.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  445.17 + * version 2 for more details (a copy is included in the LICENSE file that
  445.18 + * accompanied this code).
  445.19 + *
  445.20 + * You should have received a copy of the GNU General Public License version
  445.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  445.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  445.23 + *
  445.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  445.25 + * or visit www.oracle.com if you need additional information or have any
  445.26 + * questions.
  445.27 + */
  445.28 +
  445.29 +package java.lang;
  445.30 +
  445.31 +/**
  445.32 + * Thrown if an application attempts to access or modify a field, or
  445.33 + * to call a method that it does not have access to.
  445.34 + * <p>
  445.35 + * Normally, this error is caught by the compiler; this error can
  445.36 + * only occur at run time if the definition of a class has
  445.37 + * incompatibly changed.
  445.38 + *
  445.39 + * @author  unascribed
  445.40 + * @since   JDK1.0
  445.41 + */
  445.42 +public class IllegalAccessError extends IncompatibleClassChangeError {
  445.43 +    private static final long serialVersionUID = -8988904074992417891L;
  445.44 +
  445.45 +    /**
  445.46 +     * Constructs an <code>IllegalAccessError</code> with no detail message.
  445.47 +     */
  445.48 +    public IllegalAccessError() {
  445.49 +        super();
  445.50 +    }
  445.51 +
  445.52 +    /**
  445.53 +     * Constructs an <code>IllegalAccessError</code> with the specified
  445.54 +     * detail message.
  445.55 +     *
  445.56 +     * @param   s   the detail message.
  445.57 +     */
  445.58 +    public IllegalAccessError(String s) {
  445.59 +        super(s);
  445.60 +    }
  445.61 +}
   446.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   446.2 +++ b/rt/emul/mini/src/main/java/java/lang/IllegalAccessException.java	Wed Feb 27 11:24:58 2013 +0100
   446.3 @@ -0,0 +1,78 @@
   446.4 +/*
   446.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   446.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   446.7 + *
   446.8 + * This code is free software; you can redistribute it and/or modify it
   446.9 + * under the terms of the GNU General Public License version 2 only, as
  446.10 + * published by the Free Software Foundation.  Oracle designates this
  446.11 + * particular file as subject to the "Classpath" exception as provided
  446.12 + * by Oracle in the LICENSE file that accompanied this code.
  446.13 + *
  446.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  446.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  446.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  446.17 + * version 2 for more details (a copy is included in the LICENSE file that
  446.18 + * accompanied this code).
  446.19 + *
  446.20 + * You should have received a copy of the GNU General Public License version
  446.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  446.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  446.23 + *
  446.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  446.25 + * or visit www.oracle.com if you need additional information or have any
  446.26 + * questions.
  446.27 + */
  446.28 +
  446.29 +package java.lang;
  446.30 +
  446.31 +/**
  446.32 + * An IllegalAccessException is thrown when an application tries
  446.33 + * to reflectively create an instance (other than an array),
  446.34 + * set or get a field, or invoke a method, but the currently
  446.35 + * executing method does not have access to the definition of
  446.36 + * the specified class, field, method or constructor.
  446.37 + *
  446.38 + * @author  unascribed
  446.39 + * @see     Class#newInstance()
  446.40 + * @see     java.lang.reflect.Field#set(Object, Object)
  446.41 + * @see     java.lang.reflect.Field#setBoolean(Object, boolean)
  446.42 + * @see     java.lang.reflect.Field#setByte(Object, byte)
  446.43 + * @see     java.lang.reflect.Field#setShort(Object, short)
  446.44 + * @see     java.lang.reflect.Field#setChar(Object, char)
  446.45 + * @see     java.lang.reflect.Field#setInt(Object, int)
  446.46 + * @see     java.lang.reflect.Field#setLong(Object, long)
  446.47 + * @see     java.lang.reflect.Field#setFloat(Object, float)
  446.48 + * @see     java.lang.reflect.Field#setDouble(Object, double)
  446.49 + * @see     java.lang.reflect.Field#get(Object)
  446.50 + * @see     java.lang.reflect.Field#getBoolean(Object)
  446.51 + * @see     java.lang.reflect.Field#getByte(Object)
  446.52 + * @see     java.lang.reflect.Field#getShort(Object)
  446.53 + * @see     java.lang.reflect.Field#getChar(Object)
  446.54 + * @see     java.lang.reflect.Field#getInt(Object)
  446.55 + * @see     java.lang.reflect.Field#getLong(Object)
  446.56 + * @see     java.lang.reflect.Field#getFloat(Object)
  446.57 + * @see     java.lang.reflect.Field#getDouble(Object)
  446.58 + * @see     java.lang.reflect.Method#invoke(Object, Object[])
  446.59 + * @see     java.lang.reflect.Constructor#newInstance(Object[])
  446.60 + * @since   JDK1.0
  446.61 + */
  446.62 +public class IllegalAccessException extends ReflectiveOperationException {
  446.63 +    private static final long serialVersionUID = 6616958222490762034L;
  446.64 +
  446.65 +    /**
  446.66 +     * Constructs an <code>IllegalAccessException</code> without a
  446.67 +     * detail message.
  446.68 +     */
  446.69 +    public IllegalAccessException() {
  446.70 +        super();
  446.71 +    }
  446.72 +
  446.73 +    /**
  446.74 +     * Constructs an <code>IllegalAccessException</code> with a detail message.
  446.75 +     *
  446.76 +     * @param   s   the detail message.
  446.77 +     */
  446.78 +    public IllegalAccessException(String s) {
  446.79 +        super(s);
  446.80 +    }
  446.81 +}
   447.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   447.2 +++ b/rt/emul/mini/src/main/java/java/lang/IllegalArgumentException.java	Wed Feb 27 11:24:58 2013 +0100
   447.3 @@ -0,0 +1,95 @@
   447.4 +/*
   447.5 + * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
   447.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   447.7 + *
   447.8 + * This code is free software; you can redistribute it and/or modify it
   447.9 + * under the terms of the GNU General Public License version 2 only, as
  447.10 + * published by the Free Software Foundation.  Oracle designates this
  447.11 + * particular file as subject to the "Classpath" exception as provided
  447.12 + * by Oracle in the LICENSE file that accompanied this code.
  447.13 + *
  447.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  447.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  447.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  447.17 + * version 2 for more details (a copy is included in the LICENSE file that
  447.18 + * accompanied this code).
  447.19 + *
  447.20 + * You should have received a copy of the GNU General Public License version
  447.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  447.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  447.23 + *
  447.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  447.25 + * or visit www.oracle.com if you need additional information or have any
  447.26 + * questions.
  447.27 + */
  447.28 +
  447.29 +package java.lang;
  447.30 +
  447.31 +/**
  447.32 + * Thrown to indicate that a method has been passed an illegal or
  447.33 + * inappropriate argument.
  447.34 + *
  447.35 + * @author  unascribed
  447.36 + * @see     java.lang.Thread#setPriority(int)
  447.37 + * @since   JDK1.0
  447.38 + */
  447.39 +public
  447.40 +class IllegalArgumentException extends RuntimeException {
  447.41 +    /**
  447.42 +     * Constructs an <code>IllegalArgumentException</code> with no
  447.43 +     * detail message.
  447.44 +     */
  447.45 +    public IllegalArgumentException() {
  447.46 +        super();
  447.47 +    }
  447.48 +
  447.49 +    /**
  447.50 +     * Constructs an <code>IllegalArgumentException</code> with the
  447.51 +     * specified detail message.
  447.52 +     *
  447.53 +     * @param   s   the detail message.
  447.54 +     */
  447.55 +    public IllegalArgumentException(String s) {
  447.56 +        super(s);
  447.57 +    }
  447.58 +
  447.59 +    /**
  447.60 +     * Constructs a new exception with the specified detail message and
  447.61 +     * cause.
  447.62 +     *
  447.63 +     * <p>Note that the detail message associated with <code>cause</code> is
  447.64 +     * <i>not</i> automatically incorporated in this exception's detail
  447.65 +     * message.
  447.66 +     *
  447.67 +     * @param  message the detail message (which is saved for later retrieval
  447.68 +     *         by the {@link Throwable#getMessage()} method).
  447.69 +     * @param  cause the cause (which is saved for later retrieval by the
  447.70 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  447.71 +     *         is permitted, and indicates that the cause is nonexistent or
  447.72 +     *         unknown.)
  447.73 +     * @since 1.5
  447.74 +     */
  447.75 +    public IllegalArgumentException(String message, Throwable cause) {
  447.76 +        super(message, cause);
  447.77 +    }
  447.78 +
  447.79 +    /**
  447.80 +     * Constructs a new exception with the specified cause and a detail
  447.81 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  447.82 +     * typically contains the class and detail message of <tt>cause</tt>).
  447.83 +     * This constructor is useful for exceptions that are little more than
  447.84 +     * wrappers for other throwables (for example, {@link
  447.85 +     * java.security.PrivilegedActionException}).
  447.86 +     *
  447.87 +     * @param  cause the cause (which is saved for later retrieval by the
  447.88 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  447.89 +     *         permitted, and indicates that the cause is nonexistent or
  447.90 +     *         unknown.)
  447.91 +     * @since  1.5
  447.92 +     */
  447.93 +    public IllegalArgumentException(Throwable cause) {
  447.94 +        super(cause);
  447.95 +    }
  447.96 +
  447.97 +    private static final long serialVersionUID = -5365630128856068164L;
  447.98 +}
   448.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   448.2 +++ b/rt/emul/mini/src/main/java/java/lang/IllegalStateException.java	Wed Feb 27 11:24:58 2013 +0100
   448.3 @@ -0,0 +1,97 @@
   448.4 +/*
   448.5 + * Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
   448.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   448.7 + *
   448.8 + * This code is free software; you can redistribute it and/or modify it
   448.9 + * under the terms of the GNU General Public License version 2 only, as
  448.10 + * published by the Free Software Foundation.  Oracle designates this
  448.11 + * particular file as subject to the "Classpath" exception as provided
  448.12 + * by Oracle in the LICENSE file that accompanied this code.
  448.13 + *
  448.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  448.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  448.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  448.17 + * version 2 for more details (a copy is included in the LICENSE file that
  448.18 + * accompanied this code).
  448.19 + *
  448.20 + * You should have received a copy of the GNU General Public License version
  448.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  448.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  448.23 + *
  448.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  448.25 + * or visit www.oracle.com if you need additional information or have any
  448.26 + * questions.
  448.27 + */
  448.28 +
  448.29 +package java.lang;
  448.30 +
  448.31 +/**
  448.32 + * Signals that a method has been invoked at an illegal or
  448.33 + * inappropriate time.  In other words, the Java environment or
  448.34 + * Java application is not in an appropriate state for the requested
  448.35 + * operation.
  448.36 + *
  448.37 + * @author  Jonni Kanerva
  448.38 + * @since   JDK1.1
  448.39 + */
  448.40 +public
  448.41 +class IllegalStateException extends RuntimeException {
  448.42 +    /**
  448.43 +     * Constructs an IllegalStateException with no detail message.
  448.44 +     * A detail message is a String that describes this particular exception.
  448.45 +     */
  448.46 +    public IllegalStateException() {
  448.47 +        super();
  448.48 +    }
  448.49 +
  448.50 +    /**
  448.51 +     * Constructs an IllegalStateException with the specified detail
  448.52 +     * message.  A detail message is a String that describes this particular
  448.53 +     * exception.
  448.54 +     *
  448.55 +     * @param s the String that contains a detailed message
  448.56 +     */
  448.57 +    public IllegalStateException(String s) {
  448.58 +        super(s);
  448.59 +    }
  448.60 +
  448.61 +    /**
  448.62 +     * Constructs a new exception with the specified detail message and
  448.63 +     * cause.
  448.64 +     *
  448.65 +     * <p>Note that the detail message associated with <code>cause</code> is
  448.66 +     * <i>not</i> automatically incorporated in this exception's detail
  448.67 +     * message.
  448.68 +     *
  448.69 +     * @param  message the detail message (which is saved for later retrieval
  448.70 +     *         by the {@link Throwable#getMessage()} method).
  448.71 +     * @param  cause the cause (which is saved for later retrieval by the
  448.72 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  448.73 +     *         is permitted, and indicates that the cause is nonexistent or
  448.74 +     *         unknown.)
  448.75 +     * @since 1.5
  448.76 +     */
  448.77 +    public IllegalStateException(String message, Throwable cause) {
  448.78 +        super(message, cause);
  448.79 +    }
  448.80 +
  448.81 +    /**
  448.82 +     * Constructs a new exception with the specified cause and a detail
  448.83 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  448.84 +     * typically contains the class and detail message of <tt>cause</tt>).
  448.85 +     * This constructor is useful for exceptions that are little more than
  448.86 +     * wrappers for other throwables (for example, {@link
  448.87 +     * java.security.PrivilegedActionException}).
  448.88 +     *
  448.89 +     * @param  cause the cause (which is saved for later retrieval by the
  448.90 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  448.91 +     *         permitted, and indicates that the cause is nonexistent or
  448.92 +     *         unknown.)
  448.93 +     * @since  1.5
  448.94 +     */
  448.95 +    public IllegalStateException(Throwable cause) {
  448.96 +        super(cause);
  448.97 +    }
  448.98 +
  448.99 +    static final long serialVersionUID = -1848914673093119416L;
 448.100 +}
   449.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   449.2 +++ b/rt/emul/mini/src/main/java/java/lang/IncompatibleClassChangeError.java	Wed Feb 27 11:24:58 2013 +0100
   449.3 @@ -0,0 +1,57 @@
   449.4 +/*
   449.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   449.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   449.7 + *
   449.8 + * This code is free software; you can redistribute it and/or modify it
   449.9 + * under the terms of the GNU General Public License version 2 only, as
  449.10 + * published by the Free Software Foundation.  Oracle designates this
  449.11 + * particular file as subject to the "Classpath" exception as provided
  449.12 + * by Oracle in the LICENSE file that accompanied this code.
  449.13 + *
  449.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  449.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  449.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  449.17 + * version 2 for more details (a copy is included in the LICENSE file that
  449.18 + * accompanied this code).
  449.19 + *
  449.20 + * You should have received a copy of the GNU General Public License version
  449.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  449.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  449.23 + *
  449.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  449.25 + * or visit www.oracle.com if you need additional information or have any
  449.26 + * questions.
  449.27 + */
  449.28 +
  449.29 +package java.lang;
  449.30 +
  449.31 +/**
  449.32 + * Thrown when an incompatible class change has occurred to some class
  449.33 + * definition. The definition of some class, on which the currently
  449.34 + * executing method depends, has since changed.
  449.35 + *
  449.36 + * @author  unascribed
  449.37 + * @since   JDK1.0
  449.38 + */
  449.39 +public
  449.40 +class IncompatibleClassChangeError extends LinkageError {
  449.41 +    private static final long serialVersionUID = -4914975503642802119L;
  449.42 +
  449.43 +    /**
  449.44 +     * Constructs an <code>IncompatibleClassChangeError</code> with no
  449.45 +     * detail message.
  449.46 +     */
  449.47 +    public IncompatibleClassChangeError () {
  449.48 +        super();
  449.49 +    }
  449.50 +
  449.51 +    /**
  449.52 +     * Constructs an <code>IncompatibleClassChangeError</code> with the
  449.53 +     * specified detail message.
  449.54 +     *
  449.55 +     * @param   s   the detail message.
  449.56 +     */
  449.57 +    public IncompatibleClassChangeError(String s) {
  449.58 +        super(s);
  449.59 +    }
  449.60 +}
   450.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   450.2 +++ b/rt/emul/mini/src/main/java/java/lang/IndexOutOfBoundsException.java	Wed Feb 27 11:24:58 2013 +0100
   450.3 @@ -0,0 +1,58 @@
   450.4 +/*
   450.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   450.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   450.7 + *
   450.8 + * This code is free software; you can redistribute it and/or modify it
   450.9 + * under the terms of the GNU General Public License version 2 only, as
  450.10 + * published by the Free Software Foundation.  Oracle designates this
  450.11 + * particular file as subject to the "Classpath" exception as provided
  450.12 + * by Oracle in the LICENSE file that accompanied this code.
  450.13 + *
  450.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  450.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  450.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  450.17 + * version 2 for more details (a copy is included in the LICENSE file that
  450.18 + * accompanied this code).
  450.19 + *
  450.20 + * You should have received a copy of the GNU General Public License version
  450.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  450.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  450.23 + *
  450.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  450.25 + * or visit www.oracle.com if you need additional information or have any
  450.26 + * questions.
  450.27 + */
  450.28 +
  450.29 +package java.lang;
  450.30 +
  450.31 +/**
  450.32 + * Thrown to indicate that an index of some sort (such as to an array, to a
  450.33 + * string, or to a vector) is out of range.
  450.34 + * <p>
  450.35 + * Applications can subclass this class to indicate similar exceptions.
  450.36 + *
  450.37 + * @author  Frank Yellin
  450.38 + * @since   JDK1.0
  450.39 + */
  450.40 +public
  450.41 +class IndexOutOfBoundsException extends RuntimeException {
  450.42 +    private static final long serialVersionUID = 234122996006267687L;
  450.43 +
  450.44 +    /**
  450.45 +     * Constructs an <code>IndexOutOfBoundsException</code> with no
  450.46 +     * detail message.
  450.47 +     */
  450.48 +    public IndexOutOfBoundsException() {
  450.49 +        super();
  450.50 +    }
  450.51 +
  450.52 +    /**
  450.53 +     * Constructs an <code>IndexOutOfBoundsException</code> with the
  450.54 +     * specified detail message.
  450.55 +     *
  450.56 +     * @param   s   the detail message.
  450.57 +     */
  450.58 +    public IndexOutOfBoundsException(String s) {
  450.59 +        super(s);
  450.60 +    }
  450.61 +}
   451.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   451.2 +++ b/rt/emul/mini/src/main/java/java/lang/InstantiationException.java	Wed Feb 27 11:24:58 2013 +0100
   451.3 @@ -0,0 +1,65 @@
   451.4 +/*
   451.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   451.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   451.7 + *
   451.8 + * This code is free software; you can redistribute it and/or modify it
   451.9 + * under the terms of the GNU General Public License version 2 only, as
  451.10 + * published by the Free Software Foundation.  Oracle designates this
  451.11 + * particular file as subject to the "Classpath" exception as provided
  451.12 + * by Oracle in the LICENSE file that accompanied this code.
  451.13 + *
  451.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  451.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  451.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  451.17 + * version 2 for more details (a copy is included in the LICENSE file that
  451.18 + * accompanied this code).
  451.19 + *
  451.20 + * You should have received a copy of the GNU General Public License version
  451.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  451.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  451.23 + *
  451.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  451.25 + * or visit www.oracle.com if you need additional information or have any
  451.26 + * questions.
  451.27 + */
  451.28 +
  451.29 +package java.lang;
  451.30 +
  451.31 +/**
  451.32 + * Thrown when an application tries to create an instance of a class
  451.33 + * using the {@code newInstance} method in class
  451.34 + * {@code Class}, but the specified class object cannot be
  451.35 + * instantiated.  The instantiation can fail for a variety of
  451.36 + * reasons including but not limited to:
  451.37 + *
  451.38 + * <ul>
  451.39 + * <li> the class object represents an abstract class, an interface,
  451.40 + *      an array class, a primitive type, or {@code void}
  451.41 + * <li> the class has no nullary constructor
  451.42 + *</ul>
  451.43 + *
  451.44 + * @author  unascribed
  451.45 + * @see     java.lang.Class#newInstance()
  451.46 + * @since   JDK1.0
  451.47 + */
  451.48 +public
  451.49 +class InstantiationException extends ReflectiveOperationException {
  451.50 +    private static final long serialVersionUID = -8441929162975509110L;
  451.51 +
  451.52 +    /**
  451.53 +     * Constructs an {@code InstantiationException} with no detail message.
  451.54 +     */
  451.55 +    public InstantiationException() {
  451.56 +        super();
  451.57 +    }
  451.58 +
  451.59 +    /**
  451.60 +     * Constructs an {@code InstantiationException} with the
  451.61 +     * specified detail message.
  451.62 +     *
  451.63 +     * @param   s   the detail message.
  451.64 +     */
  451.65 +    public InstantiationException(String s) {
  451.66 +        super(s);
  451.67 +    }
  451.68 +}
   452.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   452.2 +++ b/rt/emul/mini/src/main/java/java/lang/Integer.java	Wed Feb 27 11:24:58 2013 +0100
   452.3 @@ -0,0 +1,1246 @@
   452.4 +/*
   452.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   452.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   452.7 + *
   452.8 + * This code is free software; you can redistribute it and/or modify it
   452.9 + * under the terms of the GNU General Public License version 2 only, as
  452.10 + * published by the Free Software Foundation.  Oracle designates this
  452.11 + * particular file as subject to the "Classpath" exception as provided
  452.12 + * by Oracle in the LICENSE file that accompanied this code.
  452.13 + *
  452.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  452.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  452.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  452.17 + * version 2 for more details (a copy is included in the LICENSE file that
  452.18 + * accompanied this code).
  452.19 + *
  452.20 + * You should have received a copy of the GNU General Public License version
  452.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  452.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  452.23 + *
  452.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  452.25 + * or visit www.oracle.com if you need additional information or have any
  452.26 + * questions.
  452.27 + */
  452.28 +
  452.29 +package java.lang;
  452.30 +
  452.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  452.32 +
  452.33 +/**
  452.34 + * The {@code Integer} class wraps a value of the primitive type
  452.35 + * {@code int} in an object. An object of type {@code Integer}
  452.36 + * contains a single field whose type is {@code int}.
  452.37 + *
  452.38 + * <p>In addition, this class provides several methods for converting
  452.39 + * an {@code int} to a {@code String} and a {@code String} to an
  452.40 + * {@code int}, as well as other constants and methods useful when
  452.41 + * dealing with an {@code int}.
  452.42 + *
  452.43 + * <p>Implementation note: The implementations of the "bit twiddling"
  452.44 + * methods (such as {@link #highestOneBit(int) highestOneBit} and
  452.45 + * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  452.46 + * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  452.47 + * Delight</i>, (Addison Wesley, 2002).
  452.48 + *
  452.49 + * @author  Lee Boynton
  452.50 + * @author  Arthur van Hoff
  452.51 + * @author  Josh Bloch
  452.52 + * @author  Joseph D. Darcy
  452.53 + * @since JDK1.0
  452.54 + */
  452.55 +public final class Integer extends Number implements Comparable<Integer> {
  452.56 +    /**
  452.57 +     * A constant holding the minimum value an {@code int} can
  452.58 +     * have, -2<sup>31</sup>.
  452.59 +     */
  452.60 +    public static final int   MIN_VALUE = 0x80000000;
  452.61 +
  452.62 +    /**
  452.63 +     * A constant holding the maximum value an {@code int} can
  452.64 +     * have, 2<sup>31</sup>-1.
  452.65 +     */
  452.66 +    public static final int   MAX_VALUE = 0x7fffffff;
  452.67 +
  452.68 +    /**
  452.69 +     * The {@code Class} instance representing the primitive type
  452.70 +     * {@code int}.
  452.71 +     *
  452.72 +     * @since   JDK1.1
  452.73 +     */
  452.74 +    public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
  452.75 +
  452.76 +    /**
  452.77 +     * All possible chars for representing a number as a String
  452.78 +     */
  452.79 +    final static char[] digits = {
  452.80 +        '0' , '1' , '2' , '3' , '4' , '5' ,
  452.81 +        '6' , '7' , '8' , '9' , 'a' , 'b' ,
  452.82 +        'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
  452.83 +        'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
  452.84 +        'o' , 'p' , 'q' , 'r' , 's' , 't' ,
  452.85 +        'u' , 'v' , 'w' , 'x' , 'y' , 'z'
  452.86 +    };
  452.87 +
  452.88 +    /**
  452.89 +     * Returns a string representation of the first argument in the
  452.90 +     * radix specified by the second argument.
  452.91 +     *
  452.92 +     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  452.93 +     * or larger than {@code Character.MAX_RADIX}, then the radix
  452.94 +     * {@code 10} is used instead.
  452.95 +     *
  452.96 +     * <p>If the first argument is negative, the first element of the
  452.97 +     * result is the ASCII minus character {@code '-'}
  452.98 +     * (<code>'&#92;u002D'</code>). If the first argument is not
  452.99 +     * negative, no sign character appears in the result.
 452.100 +     *
 452.101 +     * <p>The remaining characters of the result represent the magnitude
 452.102 +     * of the first argument. If the magnitude is zero, it is
 452.103 +     * represented by a single zero character {@code '0'}
 452.104 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 452.105 +     * the representation of the magnitude will not be the zero
 452.106 +     * character.  The following ASCII characters are used as digits:
 452.107 +     *
 452.108 +     * <blockquote>
 452.109 +     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
 452.110 +     * </blockquote>
 452.111 +     *
 452.112 +     * These are <code>'&#92;u0030'</code> through
 452.113 +     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 452.114 +     * <code>'&#92;u007A'</code>. If {@code radix} is
 452.115 +     * <var>N</var>, then the first <var>N</var> of these characters
 452.116 +     * are used as radix-<var>N</var> digits in the order shown. Thus,
 452.117 +     * the digits for hexadecimal (radix 16) are
 452.118 +     * {@code 0123456789abcdef}. If uppercase letters are
 452.119 +     * desired, the {@link java.lang.String#toUpperCase()} method may
 452.120 +     * be called on the result:
 452.121 +     *
 452.122 +     * <blockquote>
 452.123 +     *  {@code Integer.toString(n, 16).toUpperCase()}
 452.124 +     * </blockquote>
 452.125 +     *
 452.126 +     * @param   i       an integer to be converted to a string.
 452.127 +     * @param   radix   the radix to use in the string representation.
 452.128 +     * @return  a string representation of the argument in the specified radix.
 452.129 +     * @see     java.lang.Character#MAX_RADIX
 452.130 +     * @see     java.lang.Character#MIN_RADIX
 452.131 +     */
 452.132 +    public static String toString(int i, int radix) {
 452.133 +
 452.134 +        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 452.135 +            radix = 10;
 452.136 +
 452.137 +        /* Use the faster version */
 452.138 +        if (radix == 10) {
 452.139 +            return toString(i);
 452.140 +        }
 452.141 +
 452.142 +        char buf[] = new char[33];
 452.143 +        boolean negative = (i < 0);
 452.144 +        int charPos = 32;
 452.145 +
 452.146 +        if (!negative) {
 452.147 +            i = -i;
 452.148 +        }
 452.149 +
 452.150 +        while (i <= -radix) {
 452.151 +            buf[charPos--] = digits[-(i % radix)];
 452.152 +            i = i / radix;
 452.153 +        }
 452.154 +        buf[charPos] = digits[-i];
 452.155 +
 452.156 +        if (negative) {
 452.157 +            buf[--charPos] = '-';
 452.158 +        }
 452.159 +
 452.160 +        return new String(buf, charPos, (33 - charPos));
 452.161 +    }
 452.162 +
 452.163 +    /**
 452.164 +     * Returns a string representation of the integer argument as an
 452.165 +     * unsigned integer in base&nbsp;16.
 452.166 +     *
 452.167 +     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 452.168 +     * if the argument is negative; otherwise, it is equal to the
 452.169 +     * argument.  This value is converted to a string of ASCII digits
 452.170 +     * in hexadecimal (base&nbsp;16) with no extra leading
 452.171 +     * {@code 0}s. If the unsigned magnitude is zero, it is
 452.172 +     * represented by a single zero character {@code '0'}
 452.173 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 452.174 +     * the representation of the unsigned magnitude will not be the
 452.175 +     * zero character. The following characters are used as
 452.176 +     * hexadecimal digits:
 452.177 +     *
 452.178 +     * <blockquote>
 452.179 +     *  {@code 0123456789abcdef}
 452.180 +     * </blockquote>
 452.181 +     *
 452.182 +     * These are the characters <code>'&#92;u0030'</code> through
 452.183 +     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 452.184 +     * <code>'&#92;u0066'</code>. If uppercase letters are
 452.185 +     * desired, the {@link java.lang.String#toUpperCase()} method may
 452.186 +     * be called on the result:
 452.187 +     *
 452.188 +     * <blockquote>
 452.189 +     *  {@code Integer.toHexString(n).toUpperCase()}
 452.190 +     * </blockquote>
 452.191 +     *
 452.192 +     * @param   i   an integer to be converted to a string.
 452.193 +     * @return  the string representation of the unsigned integer value
 452.194 +     *          represented by the argument in hexadecimal (base&nbsp;16).
 452.195 +     * @since   JDK1.0.2
 452.196 +     */
 452.197 +    public static String toHexString(int i) {
 452.198 +        return toUnsignedString(i, 4);
 452.199 +    }
 452.200 +
 452.201 +    /**
 452.202 +     * Returns a string representation of the integer argument as an
 452.203 +     * unsigned integer in base&nbsp;8.
 452.204 +     *
 452.205 +     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 452.206 +     * if the argument is negative; otherwise, it is equal to the
 452.207 +     * argument.  This value is converted to a string of ASCII digits
 452.208 +     * in octal (base&nbsp;8) with no extra leading {@code 0}s.
 452.209 +     *
 452.210 +     * <p>If the unsigned magnitude is zero, it is represented by a
 452.211 +     * single zero character {@code '0'}
 452.212 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 452.213 +     * the representation of the unsigned magnitude will not be the
 452.214 +     * zero character. The following characters are used as octal
 452.215 +     * digits:
 452.216 +     *
 452.217 +     * <blockquote>
 452.218 +     * {@code 01234567}
 452.219 +     * </blockquote>
 452.220 +     *
 452.221 +     * These are the characters <code>'&#92;u0030'</code> through
 452.222 +     * <code>'&#92;u0037'</code>.
 452.223 +     *
 452.224 +     * @param   i   an integer to be converted to a string.
 452.225 +     * @return  the string representation of the unsigned integer value
 452.226 +     *          represented by the argument in octal (base&nbsp;8).
 452.227 +     * @since   JDK1.0.2
 452.228 +     */
 452.229 +    public static String toOctalString(int i) {
 452.230 +        return toUnsignedString(i, 3);
 452.231 +    }
 452.232 +
 452.233 +    /**
 452.234 +     * Returns a string representation of the integer argument as an
 452.235 +     * unsigned integer in base&nbsp;2.
 452.236 +     *
 452.237 +     * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
 452.238 +     * if the argument is negative; otherwise it is equal to the
 452.239 +     * argument.  This value is converted to a string of ASCII digits
 452.240 +     * in binary (base&nbsp;2) with no extra leading {@code 0}s.
 452.241 +     * If the unsigned magnitude is zero, it is represented by a
 452.242 +     * single zero character {@code '0'}
 452.243 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 452.244 +     * the representation of the unsigned magnitude will not be the
 452.245 +     * zero character. The characters {@code '0'}
 452.246 +     * (<code>'&#92;u0030'</code>) and {@code '1'}
 452.247 +     * (<code>'&#92;u0031'</code>) are used as binary digits.
 452.248 +     *
 452.249 +     * @param   i   an integer to be converted to a string.
 452.250 +     * @return  the string representation of the unsigned integer value
 452.251 +     *          represented by the argument in binary (base&nbsp;2).
 452.252 +     * @since   JDK1.0.2
 452.253 +     */
 452.254 +    public static String toBinaryString(int i) {
 452.255 +        return toUnsignedString(i, 1);
 452.256 +    }
 452.257 +
 452.258 +    /**
 452.259 +     * Convert the integer to an unsigned number.
 452.260 +     */
 452.261 +    private static String toUnsignedString(int i, int shift) {
 452.262 +        char[] buf = new char[32];
 452.263 +        int charPos = 32;
 452.264 +        int radix = 1 << shift;
 452.265 +        int mask = radix - 1;
 452.266 +        do {
 452.267 +            buf[--charPos] = digits[i & mask];
 452.268 +            i >>>= shift;
 452.269 +        } while (i != 0);
 452.270 +
 452.271 +        return new String(buf, charPos, (32 - charPos));
 452.272 +    }
 452.273 +
 452.274 +
 452.275 +    final static char [] DigitTens = {
 452.276 +        '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
 452.277 +        '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
 452.278 +        '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
 452.279 +        '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
 452.280 +        '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
 452.281 +        '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
 452.282 +        '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
 452.283 +        '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
 452.284 +        '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
 452.285 +        '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
 452.286 +        } ;
 452.287 +
 452.288 +    final static char [] DigitOnes = {
 452.289 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.290 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.291 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.292 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.293 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.294 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.295 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.296 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.297 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.298 +        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 452.299 +        } ;
 452.300 +
 452.301 +        // I use the "invariant division by multiplication" trick to
 452.302 +        // accelerate Integer.toString.  In particular we want to
 452.303 +        // avoid division by 10.
 452.304 +        //
 452.305 +        // The "trick" has roughly the same performance characteristics
 452.306 +        // as the "classic" Integer.toString code on a non-JIT VM.
 452.307 +        // The trick avoids .rem and .div calls but has a longer code
 452.308 +        // path and is thus dominated by dispatch overhead.  In the
 452.309 +        // JIT case the dispatch overhead doesn't exist and the
 452.310 +        // "trick" is considerably faster than the classic code.
 452.311 +        //
 452.312 +        // TODO-FIXME: convert (x * 52429) into the equiv shift-add
 452.313 +        // sequence.
 452.314 +        //
 452.315 +        // RE:  Division by Invariant Integers using Multiplication
 452.316 +        //      T Gralund, P Montgomery
 452.317 +        //      ACM PLDI 1994
 452.318 +        //
 452.319 +
 452.320 +    /**
 452.321 +     * Returns a {@code String} object representing the
 452.322 +     * specified integer. The argument is converted to signed decimal
 452.323 +     * representation and returned as a string, exactly as if the
 452.324 +     * argument and radix 10 were given as arguments to the {@link
 452.325 +     * #toString(int, int)} method.
 452.326 +     *
 452.327 +     * @param   i   an integer to be converted.
 452.328 +     * @return  a string representation of the argument in base&nbsp;10.
 452.329 +     */
 452.330 +    @JavaScriptBody(args = "i", body = "return i.toString();")
 452.331 +    public static String toString(int i) {
 452.332 +        if (i == Integer.MIN_VALUE)
 452.333 +            return "-2147483648";
 452.334 +        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 452.335 +        char[] buf = new char[size];
 452.336 +        getChars(i, size, buf);
 452.337 +        return new String(buf, 0, size);
 452.338 +    }
 452.339 +
 452.340 +    /**
 452.341 +     * Places characters representing the integer i into the
 452.342 +     * character array buf. The characters are placed into
 452.343 +     * the buffer backwards starting with the least significant
 452.344 +     * digit at the specified index (exclusive), and working
 452.345 +     * backwards from there.
 452.346 +     *
 452.347 +     * Will fail if i == Integer.MIN_VALUE
 452.348 +     */
 452.349 +    static void getChars(int i, int index, char[] buf) {
 452.350 +        int q, r;
 452.351 +        int charPos = index;
 452.352 +        char sign = 0;
 452.353 +
 452.354 +        if (i < 0) {
 452.355 +            sign = '-';
 452.356 +            i = -i;
 452.357 +        }
 452.358 +
 452.359 +        // Generate two digits per iteration
 452.360 +        while (i >= 65536) {
 452.361 +            q = i / 100;
 452.362 +        // really: r = i - (q * 100);
 452.363 +            r = i - ((q << 6) + (q << 5) + (q << 2));
 452.364 +            i = q;
 452.365 +            buf [--charPos] = DigitOnes[r];
 452.366 +            buf [--charPos] = DigitTens[r];
 452.367 +        }
 452.368 +
 452.369 +        // Fall thru to fast mode for smaller numbers
 452.370 +        // assert(i <= 65536, i);
 452.371 +        for (;;) {
 452.372 +            q = (i * 52429) >>> (16+3);
 452.373 +            r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
 452.374 +            buf [--charPos] = digits [r];
 452.375 +            i = q;
 452.376 +            if (i == 0) break;
 452.377 +        }
 452.378 +        if (sign != 0) {
 452.379 +            buf [--charPos] = sign;
 452.380 +        }
 452.381 +    }
 452.382 +
 452.383 +    final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
 452.384 +                                      99999999, 999999999, Integer.MAX_VALUE };
 452.385 +
 452.386 +    // Requires positive x
 452.387 +    static int stringSize(int x) {
 452.388 +        for (int i=0; ; i++)
 452.389 +            if (x <= sizeTable[i])
 452.390 +                return i+1;
 452.391 +    }
 452.392 +
 452.393 +    /**
 452.394 +     * Parses the string argument as a signed integer in the radix
 452.395 +     * specified by the second argument. The characters in the string
 452.396 +     * must all be digits of the specified radix (as determined by
 452.397 +     * whether {@link java.lang.Character#digit(char, int)} returns a
 452.398 +     * nonnegative value), except that the first character may be an
 452.399 +     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 452.400 +     * indicate a negative value or an ASCII plus sign {@code '+'}
 452.401 +     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 452.402 +     * resulting integer value is returned.
 452.403 +     *
 452.404 +     * <p>An exception of type {@code NumberFormatException} is
 452.405 +     * thrown if any of the following situations occurs:
 452.406 +     * <ul>
 452.407 +     * <li>The first argument is {@code null} or is a string of
 452.408 +     * length zero.
 452.409 +     *
 452.410 +     * <li>The radix is either smaller than
 452.411 +     * {@link java.lang.Character#MIN_RADIX} or
 452.412 +     * larger than {@link java.lang.Character#MAX_RADIX}.
 452.413 +     *
 452.414 +     * <li>Any character of the string is not a digit of the specified
 452.415 +     * radix, except that the first character may be a minus sign
 452.416 +     * {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 452.417 +     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 452.418 +     * string is longer than length 1.
 452.419 +     *
 452.420 +     * <li>The value represented by the string is not a value of type
 452.421 +     * {@code int}.
 452.422 +     * </ul>
 452.423 +     *
 452.424 +     * <p>Examples:
 452.425 +     * <blockquote><pre>
 452.426 +     * parseInt("0", 10) returns 0
 452.427 +     * parseInt("473", 10) returns 473
 452.428 +     * parseInt("+42", 10) returns 42
 452.429 +     * parseInt("-0", 10) returns 0
 452.430 +     * parseInt("-FF", 16) returns -255
 452.431 +     * parseInt("1100110", 2) returns 102
 452.432 +     * parseInt("2147483647", 10) returns 2147483647
 452.433 +     * parseInt("-2147483648", 10) returns -2147483648
 452.434 +     * parseInt("2147483648", 10) throws a NumberFormatException
 452.435 +     * parseInt("99", 8) throws a NumberFormatException
 452.436 +     * parseInt("Kona", 10) throws a NumberFormatException
 452.437 +     * parseInt("Kona", 27) returns 411787
 452.438 +     * </pre></blockquote>
 452.439 +     *
 452.440 +     * @param      s   the {@code String} containing the integer
 452.441 +     *                  representation to be parsed
 452.442 +     * @param      radix   the radix to be used while parsing {@code s}.
 452.443 +     * @return     the integer represented by the string argument in the
 452.444 +     *             specified radix.
 452.445 +     * @exception  NumberFormatException if the {@code String}
 452.446 +     *             does not contain a parsable {@code int}.
 452.447 +     */
 452.448 +    @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
 452.449 +    public static int parseInt(String s, int radix)
 452.450 +                throws NumberFormatException
 452.451 +    {
 452.452 +        /*
 452.453 +         * WARNING: This method may be invoked early during VM initialization
 452.454 +         * before IntegerCache is initialized. Care must be taken to not use
 452.455 +         * the valueOf method.
 452.456 +         */
 452.457 +
 452.458 +        if (s == null) {
 452.459 +            throw new NumberFormatException("null");
 452.460 +        }
 452.461 +
 452.462 +        if (radix < Character.MIN_RADIX) {
 452.463 +            throw new NumberFormatException("radix " + radix +
 452.464 +                                            " less than Character.MIN_RADIX");
 452.465 +        }
 452.466 +
 452.467 +        if (radix > Character.MAX_RADIX) {
 452.468 +            throw new NumberFormatException("radix " + radix +
 452.469 +                                            " greater than Character.MAX_RADIX");
 452.470 +        }
 452.471 +
 452.472 +        int result = 0;
 452.473 +        boolean negative = false;
 452.474 +        int i = 0, len = s.length();
 452.475 +        int limit = -Integer.MAX_VALUE;
 452.476 +        int multmin;
 452.477 +        int digit;
 452.478 +
 452.479 +        if (len > 0) {
 452.480 +            char firstChar = s.charAt(0);
 452.481 +            if (firstChar < '0') { // Possible leading "+" or "-"
 452.482 +                if (firstChar == '-') {
 452.483 +                    negative = true;
 452.484 +                    limit = Integer.MIN_VALUE;
 452.485 +                } else if (firstChar != '+')
 452.486 +                    throw NumberFormatException.forInputString(s);
 452.487 +
 452.488 +                if (len == 1) // Cannot have lone "+" or "-"
 452.489 +                    throw NumberFormatException.forInputString(s);
 452.490 +                i++;
 452.491 +            }
 452.492 +            multmin = limit / radix;
 452.493 +            while (i < len) {
 452.494 +                // Accumulating negatively avoids surprises near MAX_VALUE
 452.495 +                digit = Character.digit(s.charAt(i++),radix);
 452.496 +                if (digit < 0) {
 452.497 +                    throw NumberFormatException.forInputString(s);
 452.498 +                }
 452.499 +                if (result < multmin) {
 452.500 +                    throw NumberFormatException.forInputString(s);
 452.501 +                }
 452.502 +                result *= radix;
 452.503 +                if (result < limit + digit) {
 452.504 +                    throw NumberFormatException.forInputString(s);
 452.505 +                }
 452.506 +                result -= digit;
 452.507 +            }
 452.508 +        } else {
 452.509 +            throw NumberFormatException.forInputString(s);
 452.510 +        }
 452.511 +        return negative ? result : -result;
 452.512 +    }
 452.513 +
 452.514 +    /**
 452.515 +     * Parses the string argument as a signed decimal integer. The
 452.516 +     * characters in the string must all be decimal digits, except
 452.517 +     * that the first character may be an ASCII minus sign {@code '-'}
 452.518 +     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
 452.519 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 452.520 +     * indicate a positive value. The resulting integer value is
 452.521 +     * returned, exactly as if the argument and the radix 10 were
 452.522 +     * given as arguments to the {@link #parseInt(java.lang.String,
 452.523 +     * int)} method.
 452.524 +     *
 452.525 +     * @param s    a {@code String} containing the {@code int}
 452.526 +     *             representation to be parsed
 452.527 +     * @return     the integer value represented by the argument in decimal.
 452.528 +     * @exception  NumberFormatException  if the string does not contain a
 452.529 +     *               parsable integer.
 452.530 +     */
 452.531 +    public static int parseInt(String s) throws NumberFormatException {
 452.532 +        return parseInt(s,10);
 452.533 +    }
 452.534 +
 452.535 +    /**
 452.536 +     * Returns an {@code Integer} object holding the value
 452.537 +     * extracted from the specified {@code String} when parsed
 452.538 +     * with the radix given by the second argument. The first argument
 452.539 +     * is interpreted as representing a signed integer in the radix
 452.540 +     * specified by the second argument, exactly as if the arguments
 452.541 +     * were given to the {@link #parseInt(java.lang.String, int)}
 452.542 +     * method. The result is an {@code Integer} object that
 452.543 +     * represents the integer value specified by the string.
 452.544 +     *
 452.545 +     * <p>In other words, this method returns an {@code Integer}
 452.546 +     * object equal to the value of:
 452.547 +     *
 452.548 +     * <blockquote>
 452.549 +     *  {@code new Integer(Integer.parseInt(s, radix))}
 452.550 +     * </blockquote>
 452.551 +     *
 452.552 +     * @param      s   the string to be parsed.
 452.553 +     * @param      radix the radix to be used in interpreting {@code s}
 452.554 +     * @return     an {@code Integer} object holding the value
 452.555 +     *             represented by the string argument in the specified
 452.556 +     *             radix.
 452.557 +     * @exception NumberFormatException if the {@code String}
 452.558 +     *            does not contain a parsable {@code int}.
 452.559 +     */
 452.560 +    public static Integer valueOf(String s, int radix) throws NumberFormatException {
 452.561 +        return Integer.valueOf(parseInt(s,radix));
 452.562 +    }
 452.563 +
 452.564 +    /**
 452.565 +     * Returns an {@code Integer} object holding the
 452.566 +     * value of the specified {@code String}. The argument is
 452.567 +     * interpreted as representing a signed decimal integer, exactly
 452.568 +     * as if the argument were given to the {@link
 452.569 +     * #parseInt(java.lang.String)} method. The result is an
 452.570 +     * {@code Integer} object that represents the integer value
 452.571 +     * specified by the string.
 452.572 +     *
 452.573 +     * <p>In other words, this method returns an {@code Integer}
 452.574 +     * object equal to the value of:
 452.575 +     *
 452.576 +     * <blockquote>
 452.577 +     *  {@code new Integer(Integer.parseInt(s))}
 452.578 +     * </blockquote>
 452.579 +     *
 452.580 +     * @param      s   the string to be parsed.
 452.581 +     * @return     an {@code Integer} object holding the value
 452.582 +     *             represented by the string argument.
 452.583 +     * @exception  NumberFormatException  if the string cannot be parsed
 452.584 +     *             as an integer.
 452.585 +     */
 452.586 +    public static Integer valueOf(String s) throws NumberFormatException {
 452.587 +        return Integer.valueOf(parseInt(s, 10));
 452.588 +    }
 452.589 +
 452.590 +    /**
 452.591 +     * Cache to support the object identity semantics of autoboxing for values between
 452.592 +     * -128 and 127 (inclusive) as required by JLS.
 452.593 +     *
 452.594 +     * The cache is initialized on first usage.  The size of the cache
 452.595 +     * may be controlled by the -XX:AutoBoxCacheMax=<size> option.
 452.596 +     * During VM initialization, java.lang.Integer.IntegerCache.high property
 452.597 +     * may be set and saved in the private system properties in the
 452.598 +     * sun.misc.VM class.
 452.599 +     */
 452.600 +
 452.601 +    private static class IntegerCache {
 452.602 +        static final int low = -128;
 452.603 +        static final int high;
 452.604 +        static final Integer cache[];
 452.605 +
 452.606 +        static {
 452.607 +            // high value may be configured by property
 452.608 +            int h = 127;
 452.609 +            String integerCacheHighPropValue =
 452.610 +                AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
 452.611 +            if (integerCacheHighPropValue != null) {
 452.612 +                int i = parseInt(integerCacheHighPropValue);
 452.613 +                i = Math.max(i, 127);
 452.614 +                // Maximum array size is Integer.MAX_VALUE
 452.615 +                h = Math.min(i, Integer.MAX_VALUE - (-low));
 452.616 +            }
 452.617 +            high = h;
 452.618 +
 452.619 +            cache = new Integer[(high - low) + 1];
 452.620 +            int j = low;
 452.621 +            for(int k = 0; k < cache.length; k++)
 452.622 +                cache[k] = new Integer(j++);
 452.623 +        }
 452.624 +
 452.625 +        private IntegerCache() {}
 452.626 +    }
 452.627 +
 452.628 +    /**
 452.629 +     * Returns an {@code Integer} instance representing the specified
 452.630 +     * {@code int} value.  If a new {@code Integer} instance is not
 452.631 +     * required, this method should generally be used in preference to
 452.632 +     * the constructor {@link #Integer(int)}, as this method is likely
 452.633 +     * to yield significantly better space and time performance by
 452.634 +     * caching frequently requested values.
 452.635 +     *
 452.636 +     * This method will always cache values in the range -128 to 127,
 452.637 +     * inclusive, and may cache other values outside of this range.
 452.638 +     *
 452.639 +     * @param  i an {@code int} value.
 452.640 +     * @return an {@code Integer} instance representing {@code i}.
 452.641 +     * @since  1.5
 452.642 +     */
 452.643 +    public static Integer valueOf(int i) {
 452.644 +        //assert IntegerCache.high >= 127;
 452.645 +        if (i >= IntegerCache.low && i <= IntegerCache.high)
 452.646 +            return IntegerCache.cache[i + (-IntegerCache.low)];
 452.647 +        return new Integer(i);
 452.648 +    }
 452.649 +
 452.650 +    /**
 452.651 +     * The value of the {@code Integer}.
 452.652 +     *
 452.653 +     * @serial
 452.654 +     */
 452.655 +    private final int value;
 452.656 +
 452.657 +    /**
 452.658 +     * Constructs a newly allocated {@code Integer} object that
 452.659 +     * represents the specified {@code int} value.
 452.660 +     *
 452.661 +     * @param   value   the value to be represented by the
 452.662 +     *                  {@code Integer} object.
 452.663 +     */
 452.664 +    public Integer(int value) {
 452.665 +        this.value = value;
 452.666 +    }
 452.667 +
 452.668 +    /**
 452.669 +     * Constructs a newly allocated {@code Integer} object that
 452.670 +     * represents the {@code int} value indicated by the
 452.671 +     * {@code String} parameter. The string is converted to an
 452.672 +     * {@code int} value in exactly the manner used by the
 452.673 +     * {@code parseInt} method for radix 10.
 452.674 +     *
 452.675 +     * @param      s   the {@code String} to be converted to an
 452.676 +     *                 {@code Integer}.
 452.677 +     * @exception  NumberFormatException  if the {@code String} does not
 452.678 +     *               contain a parsable integer.
 452.679 +     * @see        java.lang.Integer#parseInt(java.lang.String, int)
 452.680 +     */
 452.681 +    public Integer(String s) throws NumberFormatException {
 452.682 +        this.value = parseInt(s, 10);
 452.683 +    }
 452.684 +
 452.685 +    /**
 452.686 +     * Returns the value of this {@code Integer} as a
 452.687 +     * {@code byte}.
 452.688 +     */
 452.689 +    public byte byteValue() {
 452.690 +        return (byte)value;
 452.691 +    }
 452.692 +
 452.693 +    /**
 452.694 +     * Returns the value of this {@code Integer} as a
 452.695 +     * {@code short}.
 452.696 +     */
 452.697 +    public short shortValue() {
 452.698 +        return (short)value;
 452.699 +    }
 452.700 +
 452.701 +    /**
 452.702 +     * Returns the value of this {@code Integer} as an
 452.703 +     * {@code int}.
 452.704 +     */
 452.705 +    public int intValue() {
 452.706 +        return value;
 452.707 +    }
 452.708 +
 452.709 +    /**
 452.710 +     * Returns the value of this {@code Integer} as a
 452.711 +     * {@code long}.
 452.712 +     */
 452.713 +    public long longValue() {
 452.714 +        return (long)value;
 452.715 +    }
 452.716 +
 452.717 +    /**
 452.718 +     * Returns the value of this {@code Integer} as a
 452.719 +     * {@code float}.
 452.720 +     */
 452.721 +    public float floatValue() {
 452.722 +        return (float)value;
 452.723 +    }
 452.724 +
 452.725 +    /**
 452.726 +     * Returns the value of this {@code Integer} as a
 452.727 +     * {@code double}.
 452.728 +     */
 452.729 +    public double doubleValue() {
 452.730 +        return (double)value;
 452.731 +    }
 452.732 +
 452.733 +    /**
 452.734 +     * Returns a {@code String} object representing this
 452.735 +     * {@code Integer}'s value. The value is converted to signed
 452.736 +     * decimal representation and returned as a string, exactly as if
 452.737 +     * the integer value were given as an argument to the {@link
 452.738 +     * java.lang.Integer#toString(int)} method.
 452.739 +     *
 452.740 +     * @return  a string representation of the value of this object in
 452.741 +     *          base&nbsp;10.
 452.742 +     */
 452.743 +    public String toString() {
 452.744 +        return toString(value);
 452.745 +    }
 452.746 +
 452.747 +    /**
 452.748 +     * Returns a hash code for this {@code Integer}.
 452.749 +     *
 452.750 +     * @return  a hash code value for this object, equal to the
 452.751 +     *          primitive {@code int} value represented by this
 452.752 +     *          {@code Integer} object.
 452.753 +     */
 452.754 +    public int hashCode() {
 452.755 +        return value;
 452.756 +    }
 452.757 +
 452.758 +    /**
 452.759 +     * Compares this object to the specified object.  The result is
 452.760 +     * {@code true} if and only if the argument is not
 452.761 +     * {@code null} and is an {@code Integer} object that
 452.762 +     * contains the same {@code int} value as this object.
 452.763 +     *
 452.764 +     * @param   obj   the object to compare with.
 452.765 +     * @return  {@code true} if the objects are the same;
 452.766 +     *          {@code false} otherwise.
 452.767 +     */
 452.768 +    public boolean equals(Object obj) {
 452.769 +        if (obj instanceof Integer) {
 452.770 +            return value == ((Integer)obj).intValue();
 452.771 +        }
 452.772 +        return false;
 452.773 +    }
 452.774 +
 452.775 +    /**
 452.776 +     * Determines the integer value of the system property with the
 452.777 +     * specified name.
 452.778 +     *
 452.779 +     * <p>The first argument is treated as the name of a system property.
 452.780 +     * System properties are accessible through the
 452.781 +     * {@link java.lang.System#getProperty(java.lang.String)} method. The
 452.782 +     * string value of this property is then interpreted as an integer
 452.783 +     * value and an {@code Integer} object representing this value is
 452.784 +     * returned. Details of possible numeric formats can be found with
 452.785 +     * the definition of {@code getProperty}.
 452.786 +     *
 452.787 +     * <p>If there is no property with the specified name, if the specified name
 452.788 +     * is empty or {@code null}, or if the property does not have
 452.789 +     * the correct numeric format, then {@code null} is returned.
 452.790 +     *
 452.791 +     * <p>In other words, this method returns an {@code Integer}
 452.792 +     * object equal to the value of:
 452.793 +     *
 452.794 +     * <blockquote>
 452.795 +     *  {@code getInteger(nm, null)}
 452.796 +     * </blockquote>
 452.797 +     *
 452.798 +     * @param   nm   property name.
 452.799 +     * @return  the {@code Integer} value of the property.
 452.800 +     * @see     java.lang.System#getProperty(java.lang.String)
 452.801 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 452.802 +     */
 452.803 +    public static Integer getInteger(String nm) {
 452.804 +        return getInteger(nm, null);
 452.805 +    }
 452.806 +
 452.807 +    /**
 452.808 +     * Determines the integer value of the system property with the
 452.809 +     * specified name.
 452.810 +     *
 452.811 +     * <p>The first argument is treated as the name of a system property.
 452.812 +     * System properties are accessible through the {@link
 452.813 +     * java.lang.System#getProperty(java.lang.String)} method. The
 452.814 +     * string value of this property is then interpreted as an integer
 452.815 +     * value and an {@code Integer} object representing this value is
 452.816 +     * returned. Details of possible numeric formats can be found with
 452.817 +     * the definition of {@code getProperty}.
 452.818 +     *
 452.819 +     * <p>The second argument is the default value. An {@code Integer} object
 452.820 +     * that represents the value of the second argument is returned if there
 452.821 +     * is no property of the specified name, if the property does not have
 452.822 +     * the correct numeric format, or if the specified name is empty or
 452.823 +     * {@code null}.
 452.824 +     *
 452.825 +     * <p>In other words, this method returns an {@code Integer} object
 452.826 +     * equal to the value of:
 452.827 +     *
 452.828 +     * <blockquote>
 452.829 +     *  {@code getInteger(nm, new Integer(val))}
 452.830 +     * </blockquote>
 452.831 +     *
 452.832 +     * but in practice it may be implemented in a manner such as:
 452.833 +     *
 452.834 +     * <blockquote><pre>
 452.835 +     * Integer result = getInteger(nm, null);
 452.836 +     * return (result == null) ? new Integer(val) : result;
 452.837 +     * </pre></blockquote>
 452.838 +     *
 452.839 +     * to avoid the unnecessary allocation of an {@code Integer}
 452.840 +     * object when the default value is not needed.
 452.841 +     *
 452.842 +     * @param   nm   property name.
 452.843 +     * @param   val   default value.
 452.844 +     * @return  the {@code Integer} value of the property.
 452.845 +     * @see     java.lang.System#getProperty(java.lang.String)
 452.846 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 452.847 +     */
 452.848 +    public static Integer getInteger(String nm, int val) {
 452.849 +        Integer result = getInteger(nm, null);
 452.850 +        return (result == null) ? Integer.valueOf(val) : result;
 452.851 +    }
 452.852 +
 452.853 +    /**
 452.854 +     * Returns the integer value of the system property with the
 452.855 +     * specified name.  The first argument is treated as the name of a
 452.856 +     * system property.  System properties are accessible through the
 452.857 +     * {@link java.lang.System#getProperty(java.lang.String)} method.
 452.858 +     * The string value of this property is then interpreted as an
 452.859 +     * integer value, as per the {@code Integer.decode} method,
 452.860 +     * and an {@code Integer} object representing this value is
 452.861 +     * returned.
 452.862 +     *
 452.863 +     * <ul><li>If the property value begins with the two ASCII characters
 452.864 +     *         {@code 0x} or the ASCII character {@code #}, not
 452.865 +     *      followed by a minus sign, then the rest of it is parsed as a
 452.866 +     *      hexadecimal integer exactly as by the method
 452.867 +     *      {@link #valueOf(java.lang.String, int)} with radix 16.
 452.868 +     * <li>If the property value begins with the ASCII character
 452.869 +     *     {@code 0} followed by another character, it is parsed as an
 452.870 +     *     octal integer exactly as by the method
 452.871 +     *     {@link #valueOf(java.lang.String, int)} with radix 8.
 452.872 +     * <li>Otherwise, the property value is parsed as a decimal integer
 452.873 +     * exactly as by the method {@link #valueOf(java.lang.String, int)}
 452.874 +     * with radix 10.
 452.875 +     * </ul>
 452.876 +     *
 452.877 +     * <p>The second argument is the default value. The default value is
 452.878 +     * returned if there is no property of the specified name, if the
 452.879 +     * property does not have the correct numeric format, or if the
 452.880 +     * specified name is empty or {@code null}.
 452.881 +     *
 452.882 +     * @param   nm   property name.
 452.883 +     * @param   val   default value.
 452.884 +     * @return  the {@code Integer} value of the property.
 452.885 +     * @see     java.lang.System#getProperty(java.lang.String)
 452.886 +     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 452.887 +     * @see java.lang.Integer#decode
 452.888 +     */
 452.889 +    public static Integer getInteger(String nm, Integer val) {
 452.890 +        String v = null;
 452.891 +        try {
 452.892 +            v = AbstractStringBuilder.getProperty(nm);
 452.893 +        } catch (IllegalArgumentException e) {
 452.894 +        } catch (NullPointerException e) {
 452.895 +        }
 452.896 +        if (v != null) {
 452.897 +            try {
 452.898 +                return Integer.decode(v);
 452.899 +            } catch (NumberFormatException e) {
 452.900 +            }
 452.901 +        }
 452.902 +        return val;
 452.903 +    }
 452.904 +
 452.905 +    /**
 452.906 +     * Decodes a {@code String} into an {@code Integer}.
 452.907 +     * Accepts decimal, hexadecimal, and octal numbers given
 452.908 +     * by the following grammar:
 452.909 +     *
 452.910 +     * <blockquote>
 452.911 +     * <dl>
 452.912 +     * <dt><i>DecodableString:</i>
 452.913 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 452.914 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 452.915 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 452.916 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 452.917 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 452.918 +     * <p>
 452.919 +     * <dt><i>Sign:</i>
 452.920 +     * <dd>{@code -}
 452.921 +     * <dd>{@code +}
 452.922 +     * </dl>
 452.923 +     * </blockquote>
 452.924 +     *
 452.925 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 452.926 +     * are as defined in section 3.10.1 of
 452.927 +     * <cite>The Java&trade; Language Specification</cite>,
 452.928 +     * except that underscores are not accepted between digits.
 452.929 +     *
 452.930 +     * <p>The sequence of characters following an optional
 452.931 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 452.932 +     * "{@code #}", or leading zero) is parsed as by the {@code
 452.933 +     * Integer.parseInt} method with the indicated radix (10, 16, or
 452.934 +     * 8).  This sequence of characters must represent a positive
 452.935 +     * value or a {@link NumberFormatException} will be thrown.  The
 452.936 +     * result is negated if first character of the specified {@code
 452.937 +     * String} is the minus sign.  No whitespace characters are
 452.938 +     * permitted in the {@code String}.
 452.939 +     *
 452.940 +     * @param     nm the {@code String} to decode.
 452.941 +     * @return    an {@code Integer} object holding the {@code int}
 452.942 +     *             value represented by {@code nm}
 452.943 +     * @exception NumberFormatException  if the {@code String} does not
 452.944 +     *            contain a parsable integer.
 452.945 +     * @see java.lang.Integer#parseInt(java.lang.String, int)
 452.946 +     */
 452.947 +    public static Integer decode(String nm) throws NumberFormatException {
 452.948 +        int radix = 10;
 452.949 +        int index = 0;
 452.950 +        boolean negative = false;
 452.951 +        Integer result;
 452.952 +
 452.953 +        if (nm.length() == 0)
 452.954 +            throw new NumberFormatException("Zero length string");
 452.955 +        char firstChar = nm.charAt(0);
 452.956 +        // Handle sign, if present
 452.957 +        if (firstChar == '-') {
 452.958 +            negative = true;
 452.959 +            index++;
 452.960 +        } else if (firstChar == '+')
 452.961 +            index++;
 452.962 +
 452.963 +        // Handle radix specifier, if present
 452.964 +        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 452.965 +            index += 2;
 452.966 +            radix = 16;
 452.967 +        }
 452.968 +        else if (nm.startsWith("#", index)) {
 452.969 +            index ++;
 452.970 +            radix = 16;
 452.971 +        }
 452.972 +        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 452.973 +            index ++;
 452.974 +            radix = 8;
 452.975 +        }
 452.976 +
 452.977 +        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 452.978 +            throw new NumberFormatException("Sign character in wrong position");
 452.979 +
 452.980 +        try {
 452.981 +            result = Integer.valueOf(nm.substring(index), radix);
 452.982 +            result = negative ? Integer.valueOf(-result.intValue()) : result;
 452.983 +        } catch (NumberFormatException e) {
 452.984 +            // If number is Integer.MIN_VALUE, we'll end up here. The next line
 452.985 +            // handles this case, and causes any genuine format error to be
 452.986 +            // rethrown.
 452.987 +            String constant = negative ? ("-" + nm.substring(index))
 452.988 +                                       : nm.substring(index);
 452.989 +            result = Integer.valueOf(constant, radix);
 452.990 +        }
 452.991 +        return result;
 452.992 +    }
 452.993 +
 452.994 +    /**
 452.995 +     * Compares two {@code Integer} objects numerically.
 452.996 +     *
 452.997 +     * @param   anotherInteger   the {@code Integer} to be compared.
 452.998 +     * @return  the value {@code 0} if this {@code Integer} is
 452.999 +     *          equal to the argument {@code Integer}; a value less than
452.1000 +     *          {@code 0} if this {@code Integer} is numerically less
452.1001 +     *          than the argument {@code Integer}; and a value greater
452.1002 +     *          than {@code 0} if this {@code Integer} is numerically
452.1003 +     *           greater than the argument {@code Integer} (signed
452.1004 +     *           comparison).
452.1005 +     * @since   1.2
452.1006 +     */
452.1007 +    public int compareTo(Integer anotherInteger) {
452.1008 +        return compare(this.value, anotherInteger.value);
452.1009 +    }
452.1010 +
452.1011 +    /**
452.1012 +     * Compares two {@code int} values numerically.
452.1013 +     * The value returned is identical to what would be returned by:
452.1014 +     * <pre>
452.1015 +     *    Integer.valueOf(x).compareTo(Integer.valueOf(y))
452.1016 +     * </pre>
452.1017 +     *
452.1018 +     * @param  x the first {@code int} to compare
452.1019 +     * @param  y the second {@code int} to compare
452.1020 +     * @return the value {@code 0} if {@code x == y};
452.1021 +     *         a value less than {@code 0} if {@code x < y}; and
452.1022 +     *         a value greater than {@code 0} if {@code x > y}
452.1023 +     * @since 1.7
452.1024 +     */
452.1025 +    public static int compare(int x, int y) {
452.1026 +        return (x < y) ? -1 : ((x == y) ? 0 : 1);
452.1027 +    }
452.1028 +
452.1029 +
452.1030 +    // Bit twiddling
452.1031 +
452.1032 +    /**
452.1033 +     * The number of bits used to represent an {@code int} value in two's
452.1034 +     * complement binary form.
452.1035 +     *
452.1036 +     * @since 1.5
452.1037 +     */
452.1038 +    public static final int SIZE = 32;
452.1039 +
452.1040 +    /**
452.1041 +     * Returns an {@code int} value with at most a single one-bit, in the
452.1042 +     * position of the highest-order ("leftmost") one-bit in the specified
452.1043 +     * {@code int} value.  Returns zero if the specified value has no
452.1044 +     * one-bits in its two's complement binary representation, that is, if it
452.1045 +     * is equal to zero.
452.1046 +     *
452.1047 +     * @return an {@code int} value with a single one-bit, in the position
452.1048 +     *     of the highest-order one-bit in the specified value, or zero if
452.1049 +     *     the specified value is itself equal to zero.
452.1050 +     * @since 1.5
452.1051 +     */
452.1052 +    public static int highestOneBit(int i) {
452.1053 +        // HD, Figure 3-1
452.1054 +        i |= (i >>  1);
452.1055 +        i |= (i >>  2);
452.1056 +        i |= (i >>  4);
452.1057 +        i |= (i >>  8);
452.1058 +        i |= (i >> 16);
452.1059 +        return i - (i >>> 1);
452.1060 +    }
452.1061 +
452.1062 +    /**
452.1063 +     * Returns an {@code int} value with at most a single one-bit, in the
452.1064 +     * position of the lowest-order ("rightmost") one-bit in the specified
452.1065 +     * {@code int} value.  Returns zero if the specified value has no
452.1066 +     * one-bits in its two's complement binary representation, that is, if it
452.1067 +     * is equal to zero.
452.1068 +     *
452.1069 +     * @return an {@code int} value with a single one-bit, in the position
452.1070 +     *     of the lowest-order one-bit in the specified value, or zero if
452.1071 +     *     the specified value is itself equal to zero.
452.1072 +     * @since 1.5
452.1073 +     */
452.1074 +    public static int lowestOneBit(int i) {
452.1075 +        // HD, Section 2-1
452.1076 +        return i & -i;
452.1077 +    }
452.1078 +
452.1079 +    /**
452.1080 +     * Returns the number of zero bits preceding the highest-order
452.1081 +     * ("leftmost") one-bit in the two's complement binary representation
452.1082 +     * of the specified {@code int} value.  Returns 32 if the
452.1083 +     * specified value has no one-bits in its two's complement representation,
452.1084 +     * in other words if it is equal to zero.
452.1085 +     *
452.1086 +     * <p>Note that this method is closely related to the logarithm base 2.
452.1087 +     * For all positive {@code int} values x:
452.1088 +     * <ul>
452.1089 +     * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
452.1090 +     * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
452.1091 +     * </ul>
452.1092 +     *
452.1093 +     * @return the number of zero bits preceding the highest-order
452.1094 +     *     ("leftmost") one-bit in the two's complement binary representation
452.1095 +     *     of the specified {@code int} value, or 32 if the value
452.1096 +     *     is equal to zero.
452.1097 +     * @since 1.5
452.1098 +     */
452.1099 +    public static int numberOfLeadingZeros(int i) {
452.1100 +        // HD, Figure 5-6
452.1101 +        if (i == 0)
452.1102 +            return 32;
452.1103 +        int n = 1;
452.1104 +        if (i >>> 16 == 0) { n += 16; i <<= 16; }
452.1105 +        if (i >>> 24 == 0) { n +=  8; i <<=  8; }
452.1106 +        if (i >>> 28 == 0) { n +=  4; i <<=  4; }
452.1107 +        if (i >>> 30 == 0) { n +=  2; i <<=  2; }
452.1108 +        n -= i >>> 31;
452.1109 +        return n;
452.1110 +    }
452.1111 +
452.1112 +    /**
452.1113 +     * Returns the number of zero bits following the lowest-order ("rightmost")
452.1114 +     * one-bit in the two's complement binary representation of the specified
452.1115 +     * {@code int} value.  Returns 32 if the specified value has no
452.1116 +     * one-bits in its two's complement representation, in other words if it is
452.1117 +     * equal to zero.
452.1118 +     *
452.1119 +     * @return the number of zero bits following the lowest-order ("rightmost")
452.1120 +     *     one-bit in the two's complement binary representation of the
452.1121 +     *     specified {@code int} value, or 32 if the value is equal
452.1122 +     *     to zero.
452.1123 +     * @since 1.5
452.1124 +     */
452.1125 +    public static int numberOfTrailingZeros(int i) {
452.1126 +        // HD, Figure 5-14
452.1127 +        int y;
452.1128 +        if (i == 0) return 32;
452.1129 +        int n = 31;
452.1130 +        y = i <<16; if (y != 0) { n = n -16; i = y; }
452.1131 +        y = i << 8; if (y != 0) { n = n - 8; i = y; }
452.1132 +        y = i << 4; if (y != 0) { n = n - 4; i = y; }
452.1133 +        y = i << 2; if (y != 0) { n = n - 2; i = y; }
452.1134 +        return n - ((i << 1) >>> 31);
452.1135 +    }
452.1136 +
452.1137 +    /**
452.1138 +     * Returns the number of one-bits in the two's complement binary
452.1139 +     * representation of the specified {@code int} value.  This function is
452.1140 +     * sometimes referred to as the <i>population count</i>.
452.1141 +     *
452.1142 +     * @return the number of one-bits in the two's complement binary
452.1143 +     *     representation of the specified {@code int} value.
452.1144 +     * @since 1.5
452.1145 +     */
452.1146 +    public static int bitCount(int i) {
452.1147 +        // HD, Figure 5-2
452.1148 +        i = i - ((i >>> 1) & 0x55555555);
452.1149 +        i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
452.1150 +        i = (i + (i >>> 4)) & 0x0f0f0f0f;
452.1151 +        i = i + (i >>> 8);
452.1152 +        i = i + (i >>> 16);
452.1153 +        return i & 0x3f;
452.1154 +    }
452.1155 +
452.1156 +    /**
452.1157 +     * Returns the value obtained by rotating the two's complement binary
452.1158 +     * representation of the specified {@code int} value left by the
452.1159 +     * specified number of bits.  (Bits shifted out of the left hand, or
452.1160 +     * high-order, side reenter on the right, or low-order.)
452.1161 +     *
452.1162 +     * <p>Note that left rotation with a negative distance is equivalent to
452.1163 +     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
452.1164 +     * distance)}.  Note also that rotation by any multiple of 32 is a
452.1165 +     * no-op, so all but the last five bits of the rotation distance can be
452.1166 +     * ignored, even if the distance is negative: {@code rotateLeft(val,
452.1167 +     * distance) == rotateLeft(val, distance & 0x1F)}.
452.1168 +     *
452.1169 +     * @return the value obtained by rotating the two's complement binary
452.1170 +     *     representation of the specified {@code int} value left by the
452.1171 +     *     specified number of bits.
452.1172 +     * @since 1.5
452.1173 +     */
452.1174 +    public static int rotateLeft(int i, int distance) {
452.1175 +        return (i << distance) | (i >>> -distance);
452.1176 +    }
452.1177 +
452.1178 +    /**
452.1179 +     * Returns the value obtained by rotating the two's complement binary
452.1180 +     * representation of the specified {@code int} value right by the
452.1181 +     * specified number of bits.  (Bits shifted out of the right hand, or
452.1182 +     * low-order, side reenter on the left, or high-order.)
452.1183 +     *
452.1184 +     * <p>Note that right rotation with a negative distance is equivalent to
452.1185 +     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
452.1186 +     * distance)}.  Note also that rotation by any multiple of 32 is a
452.1187 +     * no-op, so all but the last five bits of the rotation distance can be
452.1188 +     * ignored, even if the distance is negative: {@code rotateRight(val,
452.1189 +     * distance) == rotateRight(val, distance & 0x1F)}.
452.1190 +     *
452.1191 +     * @return the value obtained by rotating the two's complement binary
452.1192 +     *     representation of the specified {@code int} value right by the
452.1193 +     *     specified number of bits.
452.1194 +     * @since 1.5
452.1195 +     */
452.1196 +    public static int rotateRight(int i, int distance) {
452.1197 +        return (i >>> distance) | (i << -distance);
452.1198 +    }
452.1199 +
452.1200 +    /**
452.1201 +     * Returns the value obtained by reversing the order of the bits in the
452.1202 +     * two's complement binary representation of the specified {@code int}
452.1203 +     * value.
452.1204 +     *
452.1205 +     * @return the value obtained by reversing order of the bits in the
452.1206 +     *     specified {@code int} value.
452.1207 +     * @since 1.5
452.1208 +     */
452.1209 +    public static int reverse(int i) {
452.1210 +        // HD, Figure 7-1
452.1211 +        i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
452.1212 +        i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
452.1213 +        i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
452.1214 +        i = (i << 24) | ((i & 0xff00) << 8) |
452.1215 +            ((i >>> 8) & 0xff00) | (i >>> 24);
452.1216 +        return i;
452.1217 +    }
452.1218 +
452.1219 +    /**
452.1220 +     * Returns the signum function of the specified {@code int} value.  (The
452.1221 +     * return value is -1 if the specified value is negative; 0 if the
452.1222 +     * specified value is zero; and 1 if the specified value is positive.)
452.1223 +     *
452.1224 +     * @return the signum function of the specified {@code int} value.
452.1225 +     * @since 1.5
452.1226 +     */
452.1227 +    public static int signum(int i) {
452.1228 +        // HD, Section 2-7
452.1229 +        return (i >> 31) | (-i >>> 31);
452.1230 +    }
452.1231 +
452.1232 +    /**
452.1233 +     * Returns the value obtained by reversing the order of the bytes in the
452.1234 +     * two's complement representation of the specified {@code int} value.
452.1235 +     *
452.1236 +     * @return the value obtained by reversing the bytes in the specified
452.1237 +     *     {@code int} value.
452.1238 +     * @since 1.5
452.1239 +     */
452.1240 +    public static int reverseBytes(int i) {
452.1241 +        return ((i >>> 24)           ) |
452.1242 +               ((i >>   8) &   0xFF00) |
452.1243 +               ((i <<   8) & 0xFF0000) |
452.1244 +               ((i << 24));
452.1245 +    }
452.1246 +
452.1247 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
452.1248 +    private static final long serialVersionUID = 1360826667806852920L;
452.1249 +}
   453.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   453.2 +++ b/rt/emul/mini/src/main/java/java/lang/InterruptedException.java	Wed Feb 27 11:24:58 2013 +0100
   453.3 @@ -0,0 +1,69 @@
   453.4 +/*
   453.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   453.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   453.7 + *
   453.8 + * This code is free software; you can redistribute it and/or modify it
   453.9 + * under the terms of the GNU General Public License version 2 only, as
  453.10 + * published by the Free Software Foundation.  Oracle designates this
  453.11 + * particular file as subject to the "Classpath" exception as provided
  453.12 + * by Oracle in the LICENSE file that accompanied this code.
  453.13 + *
  453.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  453.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  453.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  453.17 + * version 2 for more details (a copy is included in the LICENSE file that
  453.18 + * accompanied this code).
  453.19 + *
  453.20 + * You should have received a copy of the GNU General Public License version
  453.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  453.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  453.23 + *
  453.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  453.25 + * or visit www.oracle.com if you need additional information or have any
  453.26 + * questions.
  453.27 + */
  453.28 +
  453.29 +package java.lang;
  453.30 +
  453.31 +/**
  453.32 + * Thrown when a thread is waiting, sleeping, or otherwise occupied,
  453.33 + * and the thread is interrupted, either before or during the activity.
  453.34 + * Occasionally a method may wish to test whether the current
  453.35 + * thread has been interrupted, and if so, to immediately throw
  453.36 + * this exception.  The following code can be used to achieve
  453.37 + * this effect:
  453.38 + * <pre>
  453.39 + *  if (Thread.interrupted())  // Clears interrupted status!
  453.40 + *      throw new InterruptedException();
  453.41 + * </pre>
  453.42 + *
  453.43 + * @author  Frank Yellin
  453.44 + * @see     java.lang.Object#wait()
  453.45 + * @see     java.lang.Object#wait(long)
  453.46 + * @see     java.lang.Object#wait(long, int)
  453.47 + * @see     java.lang.Thread#sleep(long)
  453.48 + * @see     java.lang.Thread#interrupt()
  453.49 + * @see     java.lang.Thread#interrupted()
  453.50 + * @since   JDK1.0
  453.51 + */
  453.52 +public
  453.53 +class InterruptedException extends Exception {
  453.54 +    private static final long serialVersionUID = 6700697376100628473L;
  453.55 +
  453.56 +    /**
  453.57 +     * Constructs an <code>InterruptedException</code> with no detail  message.
  453.58 +     */
  453.59 +    public InterruptedException() {
  453.60 +        super();
  453.61 +    }
  453.62 +
  453.63 +    /**
  453.64 +     * Constructs an <code>InterruptedException</code> with the
  453.65 +     * specified detail message.
  453.66 +     *
  453.67 +     * @param   s   the detail message.
  453.68 +     */
  453.69 +    public InterruptedException(String s) {
  453.70 +        super(s);
  453.71 +    }
  453.72 +}
   454.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   454.2 +++ b/rt/emul/mini/src/main/java/java/lang/LinkageError.java	Wed Feb 27 11:24:58 2013 +0100
   454.3 @@ -0,0 +1,69 @@
   454.4 +/*
   454.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
   454.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   454.7 + *
   454.8 + * This code is free software; you can redistribute it and/or modify it
   454.9 + * under the terms of the GNU General Public License version 2 only, as
  454.10 + * published by the Free Software Foundation.  Oracle designates this
  454.11 + * particular file as subject to the "Classpath" exception as provided
  454.12 + * by Oracle in the LICENSE file that accompanied this code.
  454.13 + *
  454.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  454.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  454.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  454.17 + * version 2 for more details (a copy is included in the LICENSE file that
  454.18 + * accompanied this code).
  454.19 + *
  454.20 + * You should have received a copy of the GNU General Public License version
  454.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  454.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  454.23 + *
  454.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  454.25 + * or visit www.oracle.com if you need additional information or have any
  454.26 + * questions.
  454.27 + */
  454.28 +
  454.29 +package java.lang;
  454.30 +
  454.31 +/**
  454.32 + * Subclasses of {@code LinkageError} indicate that a class has
  454.33 + * some dependency on another class; however, the latter class has
  454.34 + * incompatibly changed after the compilation of the former class.
  454.35 + *
  454.36 + *
  454.37 + * @author  Frank Yellin
  454.38 + * @since   JDK1.0
  454.39 + */
  454.40 +public
  454.41 +class LinkageError extends Error {
  454.42 +    private static final long serialVersionUID = 3579600108157160122L;
  454.43 +
  454.44 +    /**
  454.45 +     * Constructs a {@code LinkageError} with no detail message.
  454.46 +     */
  454.47 +    public LinkageError() {
  454.48 +        super();
  454.49 +    }
  454.50 +
  454.51 +    /**
  454.52 +     * Constructs a {@code LinkageError} with the specified detail
  454.53 +     * message.
  454.54 +     *
  454.55 +     * @param   s   the detail message.
  454.56 +     */
  454.57 +    public LinkageError(String s) {
  454.58 +        super(s);
  454.59 +    }
  454.60 +
  454.61 +    /**
  454.62 +     * Constructs a {@code LinkageError} with the specified detail
  454.63 +     * message and cause.
  454.64 +     *
  454.65 +     * @param s     the detail message.
  454.66 +     * @param cause the cause, may be {@code null}
  454.67 +     * @since 1.7
  454.68 +     */
  454.69 +    public LinkageError(String s, Throwable cause) {
  454.70 +        super(s, cause);
  454.71 +    }
  454.72 +}
   455.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   455.2 +++ b/rt/emul/mini/src/main/java/java/lang/Long.java	Wed Feb 27 11:24:58 2013 +0100
   455.3 @@ -0,0 +1,1202 @@
   455.4 +/*
   455.5 + * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
   455.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   455.7 + *
   455.8 + * This code is free software; you can redistribute it and/or modify it
   455.9 + * under the terms of the GNU General Public License version 2 only, as
  455.10 + * published by the Free Software Foundation.  Oracle designates this
  455.11 + * particular file as subject to the "Classpath" exception as provided
  455.12 + * by Oracle in the LICENSE file that accompanied this code.
  455.13 + *
  455.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  455.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  455.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  455.17 + * version 2 for more details (a copy is included in the LICENSE file that
  455.18 + * accompanied this code).
  455.19 + *
  455.20 + * You should have received a copy of the GNU General Public License version
  455.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  455.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  455.23 + *
  455.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  455.25 + * or visit www.oracle.com if you need additional information or have any
  455.26 + * questions.
  455.27 + */
  455.28 +
  455.29 +package java.lang;
  455.30 +
  455.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  455.32 +
  455.33 +/**
  455.34 + * The {@code Long} class wraps a value of the primitive type {@code
  455.35 + * long} in an object. An object of type {@code Long} contains a
  455.36 + * single field whose type is {@code long}.
  455.37 + *
  455.38 + * <p> In addition, this class provides several methods for converting
  455.39 + * a {@code long} to a {@code String} and a {@code String} to a {@code
  455.40 + * long}, as well as other constants and methods useful when dealing
  455.41 + * with a {@code long}.
  455.42 + *
  455.43 + * <p>Implementation note: The implementations of the "bit twiddling"
  455.44 + * methods (such as {@link #highestOneBit(long) highestOneBit} and
  455.45 + * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
  455.46 + * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  455.47 + * Delight</i>, (Addison Wesley, 2002).
  455.48 + *
  455.49 + * @author  Lee Boynton
  455.50 + * @author  Arthur van Hoff
  455.51 + * @author  Josh Bloch
  455.52 + * @author  Joseph D. Darcy
  455.53 + * @since   JDK1.0
  455.54 + */
  455.55 +public final class Long extends Number implements Comparable<Long> {
  455.56 +    /**
  455.57 +     * A constant holding the minimum value a {@code long} can
  455.58 +     * have, -2<sup>63</sup>.
  455.59 +     */
  455.60 +    public static final long MIN_VALUE = 0x8000000000000000L;
  455.61 +
  455.62 +    /**
  455.63 +     * A constant holding the maximum value a {@code long} can
  455.64 +     * have, 2<sup>63</sup>-1.
  455.65 +     */
  455.66 +    public static final long MAX_VALUE = 0x7fffffffffffffffL;
  455.67 +
  455.68 +    /**
  455.69 +     * The {@code Class} instance representing the primitive type
  455.70 +     * {@code long}.
  455.71 +     *
  455.72 +     * @since   JDK1.1
  455.73 +     */
  455.74 +    public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
  455.75 +
  455.76 +    /**
  455.77 +     * Returns a string representation of the first argument in the
  455.78 +     * radix specified by the second argument.
  455.79 +     *
  455.80 +     * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  455.81 +     * or larger than {@code Character.MAX_RADIX}, then the radix
  455.82 +     * {@code 10} is used instead.
  455.83 +     *
  455.84 +     * <p>If the first argument is negative, the first element of the
  455.85 +     * result is the ASCII minus sign {@code '-'}
  455.86 +     * (<code>'&#92;u002d'</code>). If the first argument is not
  455.87 +     * negative, no sign character appears in the result.
  455.88 +     *
  455.89 +     * <p>The remaining characters of the result represent the magnitude
  455.90 +     * of the first argument. If the magnitude is zero, it is
  455.91 +     * represented by a single zero character {@code '0'}
  455.92 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
  455.93 +     * the representation of the magnitude will not be the zero
  455.94 +     * character.  The following ASCII characters are used as digits:
  455.95 +     *
  455.96 +     * <blockquote>
  455.97 +     *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
  455.98 +     * </blockquote>
  455.99 +     *
 455.100 +     * These are <code>'&#92;u0030'</code> through
 455.101 +     * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
 455.102 +     * <code>'&#92;u007a'</code>. If {@code radix} is
 455.103 +     * <var>N</var>, then the first <var>N</var> of these characters
 455.104 +     * are used as radix-<var>N</var> digits in the order shown. Thus,
 455.105 +     * the digits for hexadecimal (radix 16) are
 455.106 +     * {@code 0123456789abcdef}. If uppercase letters are
 455.107 +     * desired, the {@link java.lang.String#toUpperCase()} method may
 455.108 +     * be called on the result:
 455.109 +     *
 455.110 +     * <blockquote>
 455.111 +     *  {@code Long.toString(n, 16).toUpperCase()}
 455.112 +     * </blockquote>
 455.113 +     *
 455.114 +     * @param   i       a {@code long} to be converted to a string.
 455.115 +     * @param   radix   the radix to use in the string representation.
 455.116 +     * @return  a string representation of the argument in the specified radix.
 455.117 +     * @see     java.lang.Character#MAX_RADIX
 455.118 +     * @see     java.lang.Character#MIN_RADIX
 455.119 +     */
 455.120 +    public static String toString(long i, int radix) {
 455.121 +        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
 455.122 +            radix = 10;
 455.123 +        if (radix == 10)
 455.124 +            return toString(i);
 455.125 +        char[] buf = new char[65];
 455.126 +        int charPos = 64;
 455.127 +        boolean negative = (i < 0);
 455.128 +
 455.129 +        if (!negative) {
 455.130 +            i = -i;
 455.131 +        }
 455.132 +
 455.133 +        while (i <= -radix) {
 455.134 +            buf[charPos--] = Integer.digits[(int)(-(i % radix))];
 455.135 +            i = i / radix;
 455.136 +        }
 455.137 +        buf[charPos] = Integer.digits[(int)(-i)];
 455.138 +
 455.139 +        if (negative) {
 455.140 +            buf[--charPos] = '-';
 455.141 +        }
 455.142 +
 455.143 +        return new String(buf, charPos, (65 - charPos));
 455.144 +    }
 455.145 +
 455.146 +    /**
 455.147 +     * Returns a string representation of the {@code long}
 455.148 +     * argument as an unsigned integer in base&nbsp;16.
 455.149 +     *
 455.150 +     * <p>The unsigned {@code long} value is the argument plus
 455.151 +     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 455.152 +     * equal to the argument.  This value is converted to a string of
 455.153 +     * ASCII digits in hexadecimal (base&nbsp;16) with no extra
 455.154 +     * leading {@code 0}s.  If the unsigned magnitude is zero, it
 455.155 +     * is represented by a single zero character {@code '0'}
 455.156 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 455.157 +     * the representation of the unsigned magnitude will not be the
 455.158 +     * zero character. The following characters are used as
 455.159 +     * hexadecimal digits:
 455.160 +     *
 455.161 +     * <blockquote>
 455.162 +     *  {@code 0123456789abcdef}
 455.163 +     * </blockquote>
 455.164 +     *
 455.165 +     * These are the characters <code>'&#92;u0030'</code> through
 455.166 +     * <code>'&#92;u0039'</code> and  <code>'&#92;u0061'</code> through
 455.167 +     * <code>'&#92;u0066'</code>.  If uppercase letters are desired,
 455.168 +     * the {@link java.lang.String#toUpperCase()} method may be called
 455.169 +     * on the result:
 455.170 +     *
 455.171 +     * <blockquote>
 455.172 +     *  {@code Long.toHexString(n).toUpperCase()}
 455.173 +     * </blockquote>
 455.174 +     *
 455.175 +     * @param   i   a {@code long} to be converted to a string.
 455.176 +     * @return  the string representation of the unsigned {@code long}
 455.177 +     *          value represented by the argument in hexadecimal
 455.178 +     *          (base&nbsp;16).
 455.179 +     * @since   JDK 1.0.2
 455.180 +     */
 455.181 +    public static String toHexString(long i) {
 455.182 +        return toUnsignedString(i, 4);
 455.183 +    }
 455.184 +
 455.185 +    /**
 455.186 +     * Returns a string representation of the {@code long}
 455.187 +     * argument as an unsigned integer in base&nbsp;8.
 455.188 +     *
 455.189 +     * <p>The unsigned {@code long} value is the argument plus
 455.190 +     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 455.191 +     * equal to the argument.  This value is converted to a string of
 455.192 +     * ASCII digits in octal (base&nbsp;8) with no extra leading
 455.193 +     * {@code 0}s.
 455.194 +     *
 455.195 +     * <p>If the unsigned magnitude is zero, it is represented by a
 455.196 +     * single zero character {@code '0'}
 455.197 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 455.198 +     * the representation of the unsigned magnitude will not be the
 455.199 +     * zero character. The following characters are used as octal
 455.200 +     * digits:
 455.201 +     *
 455.202 +     * <blockquote>
 455.203 +     *  {@code 01234567}
 455.204 +     * </blockquote>
 455.205 +     *
 455.206 +     * These are the characters <code>'&#92;u0030'</code> through
 455.207 +     * <code>'&#92;u0037'</code>.
 455.208 +     *
 455.209 +     * @param   i   a {@code long} to be converted to a string.
 455.210 +     * @return  the string representation of the unsigned {@code long}
 455.211 +     *          value represented by the argument in octal (base&nbsp;8).
 455.212 +     * @since   JDK 1.0.2
 455.213 +     */
 455.214 +    public static String toOctalString(long i) {
 455.215 +        return toUnsignedString(i, 3);
 455.216 +    }
 455.217 +
 455.218 +    /**
 455.219 +     * Returns a string representation of the {@code long}
 455.220 +     * argument as an unsigned integer in base&nbsp;2.
 455.221 +     *
 455.222 +     * <p>The unsigned {@code long} value is the argument plus
 455.223 +     * 2<sup>64</sup> if the argument is negative; otherwise, it is
 455.224 +     * equal to the argument.  This value is converted to a string of
 455.225 +     * ASCII digits in binary (base&nbsp;2) with no extra leading
 455.226 +     * {@code 0}s.  If the unsigned magnitude is zero, it is
 455.227 +     * represented by a single zero character {@code '0'}
 455.228 +     * (<code>'&#92;u0030'</code>); otherwise, the first character of
 455.229 +     * the representation of the unsigned magnitude will not be the
 455.230 +     * zero character. The characters {@code '0'}
 455.231 +     * (<code>'&#92;u0030'</code>) and {@code '1'}
 455.232 +     * (<code>'&#92;u0031'</code>) are used as binary digits.
 455.233 +     *
 455.234 +     * @param   i   a {@code long} to be converted to a string.
 455.235 +     * @return  the string representation of the unsigned {@code long}
 455.236 +     *          value represented by the argument in binary (base&nbsp;2).
 455.237 +     * @since   JDK 1.0.2
 455.238 +     */
 455.239 +    public static String toBinaryString(long i) {
 455.240 +        return toUnsignedString(i, 1);
 455.241 +    }
 455.242 +
 455.243 +    /**
 455.244 +     * Convert the integer to an unsigned number.
 455.245 +     */
 455.246 +    private static String toUnsignedString(long i, int shift) {
 455.247 +        char[] buf = new char[64];
 455.248 +        int charPos = 64;
 455.249 +        int radix = 1 << shift;
 455.250 +        long mask = radix - 1;
 455.251 +        do {
 455.252 +            buf[--charPos] = Integer.digits[(int)(i & mask)];
 455.253 +            i >>>= shift;
 455.254 +        } while (i != 0);
 455.255 +        return new String(buf, charPos, (64 - charPos));
 455.256 +    }
 455.257 +
 455.258 +    /**
 455.259 +     * Returns a {@code String} object representing the specified
 455.260 +     * {@code long}.  The argument is converted to signed decimal
 455.261 +     * representation and returned as a string, exactly as if the
 455.262 +     * argument and the radix 10 were given as arguments to the {@link
 455.263 +     * #toString(long, int)} method.
 455.264 +     *
 455.265 +     * @param   i   a {@code long} to be converted.
 455.266 +     * @return  a string representation of the argument in base&nbsp;10.
 455.267 +     */
 455.268 +    @JavaScriptBody(args = "i", body = "return i.toExactString();")
 455.269 +    public static String toString(long i) {
 455.270 +        if (i == Long.MIN_VALUE)
 455.271 +            return "-9223372036854775808";
 455.272 +        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
 455.273 +        char[] buf = new char[size];
 455.274 +        getChars(i, size, buf);
 455.275 +        return new String(buf, 0, size);
 455.276 +    }
 455.277 +
 455.278 +    /**
 455.279 +     * Places characters representing the integer i into the
 455.280 +     * character array buf. The characters are placed into
 455.281 +     * the buffer backwards starting with the least significant
 455.282 +     * digit at the specified index (exclusive), and working
 455.283 +     * backwards from there.
 455.284 +     *
 455.285 +     * Will fail if i == Long.MIN_VALUE
 455.286 +     */
 455.287 +    static void getChars(long i, int index, char[] buf) {
 455.288 +        long q;
 455.289 +        int r;
 455.290 +        int charPos = index;
 455.291 +        char sign = 0;
 455.292 +
 455.293 +        if (i < 0) {
 455.294 +            sign = '-';
 455.295 +            i = -i;
 455.296 +        }
 455.297 +
 455.298 +        // Get 2 digits/iteration using longs until quotient fits into an int
 455.299 +        while (i > Integer.MAX_VALUE) {
 455.300 +            q = i / 100;
 455.301 +            // really: r = i - (q * 100);
 455.302 +            r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
 455.303 +            i = q;
 455.304 +            buf[--charPos] = Integer.DigitOnes[r];
 455.305 +            buf[--charPos] = Integer.DigitTens[r];
 455.306 +        }
 455.307 +
 455.308 +        // Get 2 digits/iteration using ints
 455.309 +        int q2;
 455.310 +        int i2 = (int)i;
 455.311 +        while (i2 >= 65536) {
 455.312 +            q2 = i2 / 100;
 455.313 +            // really: r = i2 - (q * 100);
 455.314 +            r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
 455.315 +            i2 = q2;
 455.316 +            buf[--charPos] = Integer.DigitOnes[r];
 455.317 +            buf[--charPos] = Integer.DigitTens[r];
 455.318 +        }
 455.319 +
 455.320 +        // Fall thru to fast mode for smaller numbers
 455.321 +        // assert(i2 <= 65536, i2);
 455.322 +        for (;;) {
 455.323 +            q2 = (i2 * 52429) >>> (16+3);
 455.324 +            r = i2 - ((q2 << 3) + (q2 << 1));  // r = i2-(q2*10) ...
 455.325 +            buf[--charPos] = Integer.digits[r];
 455.326 +            i2 = q2;
 455.327 +            if (i2 == 0) break;
 455.328 +        }
 455.329 +        if (sign != 0) {
 455.330 +            buf[--charPos] = sign;
 455.331 +        }
 455.332 +    }
 455.333 +
 455.334 +    // Requires positive x
 455.335 +    static int stringSize(long x) {
 455.336 +        long p = 10;
 455.337 +        for (int i=1; i<19; i++) {
 455.338 +            if (x < p)
 455.339 +                return i;
 455.340 +            p = 10*p;
 455.341 +        }
 455.342 +        return 19;
 455.343 +    }
 455.344 +
 455.345 +    /**
 455.346 +     * Parses the string argument as a signed {@code long} in the
 455.347 +     * radix specified by the second argument. The characters in the
 455.348 +     * string must all be digits of the specified radix (as determined
 455.349 +     * by whether {@link java.lang.Character#digit(char, int)} returns
 455.350 +     * a nonnegative value), except that the first character may be an
 455.351 +     * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
 455.352 +     * indicate a negative value or an ASCII plus sign {@code '+'}
 455.353 +     * (<code>'&#92;u002B'</code>) to indicate a positive value. The
 455.354 +     * resulting {@code long} value is returned.
 455.355 +     *
 455.356 +     * <p>Note that neither the character {@code L}
 455.357 +     * (<code>'&#92;u004C'</code>) nor {@code l}
 455.358 +     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 455.359 +     * of the string as a type indicator, as would be permitted in
 455.360 +     * Java programming language source code - except that either
 455.361 +     * {@code L} or {@code l} may appear as a digit for a
 455.362 +     * radix greater than 22.
 455.363 +     *
 455.364 +     * <p>An exception of type {@code NumberFormatException} is
 455.365 +     * thrown if any of the following situations occurs:
 455.366 +     * <ul>
 455.367 +     *
 455.368 +     * <li>The first argument is {@code null} or is a string of
 455.369 +     * length zero.
 455.370 +     *
 455.371 +     * <li>The {@code radix} is either smaller than {@link
 455.372 +     * java.lang.Character#MIN_RADIX} or larger than {@link
 455.373 +     * java.lang.Character#MAX_RADIX}.
 455.374 +     *
 455.375 +     * <li>Any character of the string is not a digit of the specified
 455.376 +     * radix, except that the first character may be a minus sign
 455.377 +     * {@code '-'} (<code>'&#92;u002d'</code>) or plus sign {@code
 455.378 +     * '+'} (<code>'&#92;u002B'</code>) provided that the string is
 455.379 +     * longer than length 1.
 455.380 +     *
 455.381 +     * <li>The value represented by the string is not a value of type
 455.382 +     *      {@code long}.
 455.383 +     * </ul>
 455.384 +     *
 455.385 +     * <p>Examples:
 455.386 +     * <blockquote><pre>
 455.387 +     * parseLong("0", 10) returns 0L
 455.388 +     * parseLong("473", 10) returns 473L
 455.389 +     * parseLong("+42", 10) returns 42L
 455.390 +     * parseLong("-0", 10) returns 0L
 455.391 +     * parseLong("-FF", 16) returns -255L
 455.392 +     * parseLong("1100110", 2) returns 102L
 455.393 +     * parseLong("99", 8) throws a NumberFormatException
 455.394 +     * parseLong("Hazelnut", 10) throws a NumberFormatException
 455.395 +     * parseLong("Hazelnut", 36) returns 1356099454469L
 455.396 +     * </pre></blockquote>
 455.397 +     *
 455.398 +     * @param      s       the {@code String} containing the
 455.399 +     *                     {@code long} representation to be parsed.
 455.400 +     * @param      radix   the radix to be used while parsing {@code s}.
 455.401 +     * @return     the {@code long} represented by the string argument in
 455.402 +     *             the specified radix.
 455.403 +     * @throws     NumberFormatException  if the string does not contain a
 455.404 +     *             parsable {@code long}.
 455.405 +     */
 455.406 +    public static long parseLong(String s, int radix)
 455.407 +              throws NumberFormatException
 455.408 +    {
 455.409 +        if (s == null) {
 455.410 +            throw new NumberFormatException("null");
 455.411 +        }
 455.412 +
 455.413 +        if (radix < Character.MIN_RADIX) {
 455.414 +            throw new NumberFormatException("radix " + radix +
 455.415 +                                            " less than Character.MIN_RADIX");
 455.416 +        }
 455.417 +        if (radix > Character.MAX_RADIX) {
 455.418 +            throw new NumberFormatException("radix " + radix +
 455.419 +                                            " greater than Character.MAX_RADIX");
 455.420 +        }
 455.421 +
 455.422 +        long result = 0;
 455.423 +        boolean negative = false;
 455.424 +        int i = 0, len = s.length();
 455.425 +        long limit = -Long.MAX_VALUE;
 455.426 +        long multmin;
 455.427 +        int digit;
 455.428 +
 455.429 +        if (len > 0) {
 455.430 +            char firstChar = s.charAt(0);
 455.431 +            if (firstChar < '0') { // Possible leading "+" or "-"
 455.432 +                if (firstChar == '-') {
 455.433 +                    negative = true;
 455.434 +                    limit = Long.MIN_VALUE;
 455.435 +                } else if (firstChar != '+')
 455.436 +                    throw NumberFormatException.forInputString(s);
 455.437 +
 455.438 +                if (len == 1) // Cannot have lone "+" or "-"
 455.439 +                    throw NumberFormatException.forInputString(s);
 455.440 +                i++;
 455.441 +            }
 455.442 +            multmin = limit / radix;
 455.443 +            while (i < len) {
 455.444 +                // Accumulating negatively avoids surprises near MAX_VALUE
 455.445 +                digit = Character.digit(s.charAt(i++),radix);
 455.446 +                if (digit < 0) {
 455.447 +                    throw NumberFormatException.forInputString(s);
 455.448 +                }
 455.449 +                if (result < multmin) {
 455.450 +                    throw NumberFormatException.forInputString(s);
 455.451 +                }
 455.452 +                result *= radix;
 455.453 +                if (result < limit + digit) {
 455.454 +                    throw NumberFormatException.forInputString(s);
 455.455 +                }
 455.456 +                result -= digit;
 455.457 +            }
 455.458 +        } else {
 455.459 +            throw NumberFormatException.forInputString(s);
 455.460 +        }
 455.461 +        return negative ? result : -result;
 455.462 +    }
 455.463 +
 455.464 +    /**
 455.465 +     * Parses the string argument as a signed decimal {@code long}.
 455.466 +     * The characters in the string must all be decimal digits, except
 455.467 +     * that the first character may be an ASCII minus sign {@code '-'}
 455.468 +     * (<code>&#92;u002D'</code>) to indicate a negative value or an
 455.469 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
 455.470 +     * indicate a positive value. The resulting {@code long} value is
 455.471 +     * returned, exactly as if the argument and the radix {@code 10}
 455.472 +     * were given as arguments to the {@link
 455.473 +     * #parseLong(java.lang.String, int)} method.
 455.474 +     *
 455.475 +     * <p>Note that neither the character {@code L}
 455.476 +     * (<code>'&#92;u004C'</code>) nor {@code l}
 455.477 +     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 455.478 +     * of the string as a type indicator, as would be permitted in
 455.479 +     * Java programming language source code.
 455.480 +     *
 455.481 +     * @param      s   a {@code String} containing the {@code long}
 455.482 +     *             representation to be parsed
 455.483 +     * @return     the {@code long} represented by the argument in
 455.484 +     *             decimal.
 455.485 +     * @throws     NumberFormatException  if the string does not contain a
 455.486 +     *             parsable {@code long}.
 455.487 +     */
 455.488 +    public static long parseLong(String s) throws NumberFormatException {
 455.489 +        return parseLong(s, 10);
 455.490 +    }
 455.491 +
 455.492 +    /**
 455.493 +     * Returns a {@code Long} object holding the value
 455.494 +     * extracted from the specified {@code String} when parsed
 455.495 +     * with the radix given by the second argument.  The first
 455.496 +     * argument is interpreted as representing a signed
 455.497 +     * {@code long} in the radix specified by the second
 455.498 +     * argument, exactly as if the arguments were given to the {@link
 455.499 +     * #parseLong(java.lang.String, int)} method. The result is a
 455.500 +     * {@code Long} object that represents the {@code long}
 455.501 +     * value specified by the string.
 455.502 +     *
 455.503 +     * <p>In other words, this method returns a {@code Long} object equal
 455.504 +     * to the value of:
 455.505 +     *
 455.506 +     * <blockquote>
 455.507 +     *  {@code new Long(Long.parseLong(s, radix))}
 455.508 +     * </blockquote>
 455.509 +     *
 455.510 +     * @param      s       the string to be parsed
 455.511 +     * @param      radix   the radix to be used in interpreting {@code s}
 455.512 +     * @return     a {@code Long} object holding the value
 455.513 +     *             represented by the string argument in the specified
 455.514 +     *             radix.
 455.515 +     * @throws     NumberFormatException  If the {@code String} does not
 455.516 +     *             contain a parsable {@code long}.
 455.517 +     */
 455.518 +    public static Long valueOf(String s, int radix) throws NumberFormatException {
 455.519 +        return Long.valueOf(parseLong(s, radix));
 455.520 +    }
 455.521 +
 455.522 +    /**
 455.523 +     * Returns a {@code Long} object holding the value
 455.524 +     * of the specified {@code String}. The argument is
 455.525 +     * interpreted as representing a signed decimal {@code long},
 455.526 +     * exactly as if the argument were given to the {@link
 455.527 +     * #parseLong(java.lang.String)} method. The result is a
 455.528 +     * {@code Long} object that represents the integer value
 455.529 +     * specified by the string.
 455.530 +     *
 455.531 +     * <p>In other words, this method returns a {@code Long} object
 455.532 +     * equal to the value of:
 455.533 +     *
 455.534 +     * <blockquote>
 455.535 +     *  {@code new Long(Long.parseLong(s))}
 455.536 +     * </blockquote>
 455.537 +     *
 455.538 +     * @param      s   the string to be parsed.
 455.539 +     * @return     a {@code Long} object holding the value
 455.540 +     *             represented by the string argument.
 455.541 +     * @throws     NumberFormatException  If the string cannot be parsed
 455.542 +     *             as a {@code long}.
 455.543 +     */
 455.544 +    public static Long valueOf(String s) throws NumberFormatException
 455.545 +    {
 455.546 +        return Long.valueOf(parseLong(s, 10));
 455.547 +    }
 455.548 +
 455.549 +    private static class LongCache {
 455.550 +        private LongCache(){}
 455.551 +
 455.552 +        static final Long cache[] = new Long[-(-128) + 127 + 1];
 455.553 +
 455.554 +        static {
 455.555 +            for(int i = 0; i < cache.length; i++)
 455.556 +                cache[i] = new Long(i - 128);
 455.557 +        }
 455.558 +    }
 455.559 +
 455.560 +    /**
 455.561 +     * Returns a {@code Long} instance representing the specified
 455.562 +     * {@code long} value.
 455.563 +     * If a new {@code Long} instance is not required, this method
 455.564 +     * should generally be used in preference to the constructor
 455.565 +     * {@link #Long(long)}, as this method is likely to yield
 455.566 +     * significantly better space and time performance by caching
 455.567 +     * frequently requested values.
 455.568 +     *
 455.569 +     * Note that unlike the {@linkplain Integer#valueOf(int)
 455.570 +     * corresponding method} in the {@code Integer} class, this method
 455.571 +     * is <em>not</em> required to cache values within a particular
 455.572 +     * range.
 455.573 +     *
 455.574 +     * @param  l a long value.
 455.575 +     * @return a {@code Long} instance representing {@code l}.
 455.576 +     * @since  1.5
 455.577 +     */
 455.578 +    public static Long valueOf(long l) {
 455.579 +        final int offset = 128;
 455.580 +        if (l >= -128 && l <= 127) { // will cache
 455.581 +            return LongCache.cache[(int)l + offset];
 455.582 +        }
 455.583 +        return new Long(l);
 455.584 +    }
 455.585 +
 455.586 +    /**
 455.587 +     * Decodes a {@code String} into a {@code Long}.
 455.588 +     * Accepts decimal, hexadecimal, and octal numbers given by the
 455.589 +     * following grammar:
 455.590 +     *
 455.591 +     * <blockquote>
 455.592 +     * <dl>
 455.593 +     * <dt><i>DecodableString:</i>
 455.594 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 455.595 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 455.596 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 455.597 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 455.598 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 455.599 +     * <p>
 455.600 +     * <dt><i>Sign:</i>
 455.601 +     * <dd>{@code -}
 455.602 +     * <dd>{@code +}
 455.603 +     * </dl>
 455.604 +     * </blockquote>
 455.605 +     *
 455.606 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 455.607 +     * are as defined in section 3.10.1 of
 455.608 +     * <cite>The Java&trade; Language Specification</cite>,
 455.609 +     * except that underscores are not accepted between digits.
 455.610 +     *
 455.611 +     * <p>The sequence of characters following an optional
 455.612 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 455.613 +     * "{@code #}", or leading zero) is parsed as by the {@code
 455.614 +     * Long.parseLong} method with the indicated radix (10, 16, or 8).
 455.615 +     * This sequence of characters must represent a positive value or
 455.616 +     * a {@link NumberFormatException} will be thrown.  The result is
 455.617 +     * negated if first character of the specified {@code String} is
 455.618 +     * the minus sign.  No whitespace characters are permitted in the
 455.619 +     * {@code String}.
 455.620 +     *
 455.621 +     * @param     nm the {@code String} to decode.
 455.622 +     * @return    a {@code Long} object holding the {@code long}
 455.623 +     *            value represented by {@code nm}
 455.624 +     * @throws    NumberFormatException  if the {@code String} does not
 455.625 +     *            contain a parsable {@code long}.
 455.626 +     * @see java.lang.Long#parseLong(String, int)
 455.627 +     * @since 1.2
 455.628 +     */
 455.629 +    public static Long decode(String nm) throws NumberFormatException {
 455.630 +        int radix = 10;
 455.631 +        int index = 0;
 455.632 +        boolean negative = false;
 455.633 +        Long result;
 455.634 +
 455.635 +        if (nm.length() == 0)
 455.636 +            throw new NumberFormatException("Zero length string");
 455.637 +        char firstChar = nm.charAt(0);
 455.638 +        // Handle sign, if present
 455.639 +        if (firstChar == '-') {
 455.640 +            negative = true;
 455.641 +            index++;
 455.642 +        } else if (firstChar == '+')
 455.643 +            index++;
 455.644 +
 455.645 +        // Handle radix specifier, if present
 455.646 +        if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
 455.647 +            index += 2;
 455.648 +            radix = 16;
 455.649 +        }
 455.650 +        else if (nm.startsWith("#", index)) {
 455.651 +            index ++;
 455.652 +            radix = 16;
 455.653 +        }
 455.654 +        else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
 455.655 +            index ++;
 455.656 +            radix = 8;
 455.657 +        }
 455.658 +
 455.659 +        if (nm.startsWith("-", index) || nm.startsWith("+", index))
 455.660 +            throw new NumberFormatException("Sign character in wrong position");
 455.661 +
 455.662 +        try {
 455.663 +            result = Long.valueOf(nm.substring(index), radix);
 455.664 +            result = negative ? Long.valueOf(-result.longValue()) : result;
 455.665 +        } catch (NumberFormatException e) {
 455.666 +            // If number is Long.MIN_VALUE, we'll end up here. The next line
 455.667 +            // handles this case, and causes any genuine format error to be
 455.668 +            // rethrown.
 455.669 +            String constant = negative ? ("-" + nm.substring(index))
 455.670 +                                       : nm.substring(index);
 455.671 +            result = Long.valueOf(constant, radix);
 455.672 +        }
 455.673 +        return result;
 455.674 +    }
 455.675 +
 455.676 +    /**
 455.677 +     * The value of the {@code Long}.
 455.678 +     *
 455.679 +     * @serial
 455.680 +     */
 455.681 +    private final long value;
 455.682 +
 455.683 +    /**
 455.684 +     * Constructs a newly allocated {@code Long} object that
 455.685 +     * represents the specified {@code long} argument.
 455.686 +     *
 455.687 +     * @param   value   the value to be represented by the
 455.688 +     *          {@code Long} object.
 455.689 +     */
 455.690 +    public Long(long value) {
 455.691 +        this.value = value;
 455.692 +    }
 455.693 +
 455.694 +    /**
 455.695 +     * Constructs a newly allocated {@code Long} object that
 455.696 +     * represents the {@code long} value indicated by the
 455.697 +     * {@code String} parameter. The string is converted to a
 455.698 +     * {@code long} value in exactly the manner used by the
 455.699 +     * {@code parseLong} method for radix 10.
 455.700 +     *
 455.701 +     * @param      s   the {@code String} to be converted to a
 455.702 +     *             {@code Long}.
 455.703 +     * @throws     NumberFormatException  if the {@code String} does not
 455.704 +     *             contain a parsable {@code long}.
 455.705 +     * @see        java.lang.Long#parseLong(java.lang.String, int)
 455.706 +     */
 455.707 +    public Long(String s) throws NumberFormatException {
 455.708 +        this.value = parseLong(s, 10);
 455.709 +    }
 455.710 +
 455.711 +    /**
 455.712 +     * Returns the value of this {@code Long} as a
 455.713 +     * {@code byte}.
 455.714 +     */
 455.715 +    public byte byteValue() {
 455.716 +        return (byte)value;
 455.717 +    }
 455.718 +
 455.719 +    /**
 455.720 +     * Returns the value of this {@code Long} as a
 455.721 +     * {@code short}.
 455.722 +     */
 455.723 +    public short shortValue() {
 455.724 +        return (short)value;
 455.725 +    }
 455.726 +
 455.727 +    /**
 455.728 +     * Returns the value of this {@code Long} as an
 455.729 +     * {@code int}.
 455.730 +     */
 455.731 +    public int intValue() {
 455.732 +        return (int)value;
 455.733 +    }
 455.734 +
 455.735 +    /**
 455.736 +     * Returns the value of this {@code Long} as a
 455.737 +     * {@code long} value.
 455.738 +     */
 455.739 +    public long longValue() {
 455.740 +        return (long)value;
 455.741 +    }
 455.742 +
 455.743 +    /**
 455.744 +     * Returns the value of this {@code Long} as a
 455.745 +     * {@code float}.
 455.746 +     */
 455.747 +    public float floatValue() {
 455.748 +        return (float)value;
 455.749 +    }
 455.750 +
 455.751 +    /**
 455.752 +     * Returns the value of this {@code Long} as a
 455.753 +     * {@code double}.
 455.754 +     */
 455.755 +    public double doubleValue() {
 455.756 +        return (double)value;
 455.757 +    }
 455.758 +
 455.759 +    /**
 455.760 +     * Returns a {@code String} object representing this
 455.761 +     * {@code Long}'s value.  The value is converted to signed
 455.762 +     * decimal representation and returned as a string, exactly as if
 455.763 +     * the {@code long} value were given as an argument to the
 455.764 +     * {@link java.lang.Long#toString(long)} method.
 455.765 +     *
 455.766 +     * @return  a string representation of the value of this object in
 455.767 +     *          base&nbsp;10.
 455.768 +     */
 455.769 +    public String toString() {
 455.770 +        return toString(value);
 455.771 +    }
 455.772 +
 455.773 +    /**
 455.774 +     * Returns a hash code for this {@code Long}. The result is
 455.775 +     * the exclusive OR of the two halves of the primitive
 455.776 +     * {@code long} value held by this {@code Long}
 455.777 +     * object. That is, the hashcode is the value of the expression:
 455.778 +     *
 455.779 +     * <blockquote>
 455.780 +     *  {@code (int)(this.longValue()^(this.longValue()>>>32))}
 455.781 +     * </blockquote>
 455.782 +     *
 455.783 +     * @return  a hash code value for this object.
 455.784 +     */
 455.785 +    public int hashCode() {
 455.786 +        return (int)(value ^ (value >>> 32));
 455.787 +    }
 455.788 +
 455.789 +    /**
 455.790 +     * Compares this object to the specified object.  The result is
 455.791 +     * {@code true} if and only if the argument is not
 455.792 +     * {@code null} and is a {@code Long} object that
 455.793 +     * contains the same {@code long} value as this object.
 455.794 +     *
 455.795 +     * @param   obj   the object to compare with.
 455.796 +     * @return  {@code true} if the objects are the same;
 455.797 +     *          {@code false} otherwise.
 455.798 +     */
 455.799 +    public boolean equals(Object obj) {
 455.800 +        if (obj instanceof Long) {
 455.801 +            return value == ((Long)obj).longValue();
 455.802 +        }
 455.803 +        return false;
 455.804 +    }
 455.805 +
 455.806 +    /**
 455.807 +     * Determines the {@code long} value of the system property
 455.808 +     * with the specified name.
 455.809 +     *
 455.810 +     * <p>The first argument is treated as the name of a system property.
 455.811 +     * System properties are accessible through the {@link
 455.812 +     * java.lang.System#getProperty(java.lang.String)} method. The
 455.813 +     * string value of this property is then interpreted as a
 455.814 +     * {@code long} value and a {@code Long} object
 455.815 +     * representing this value is returned.  Details of possible
 455.816 +     * numeric formats can be found with the definition of
 455.817 +     * {@code getProperty}.
 455.818 +     *
 455.819 +     * <p>If there is no property with the specified name, if the
 455.820 +     * specified name is empty or {@code null}, or if the
 455.821 +     * property does not have the correct numeric format, then
 455.822 +     * {@code null} is returned.
 455.823 +     *
 455.824 +     * <p>In other words, this method returns a {@code Long} object equal to
 455.825 +     * the value of:
 455.826 +     *
 455.827 +     * <blockquote>
 455.828 +     *  {@code getLong(nm, null)}
 455.829 +     * </blockquote>
 455.830 +     *
 455.831 +     * @param   nm   property name.
 455.832 +     * @return  the {@code Long} value of the property.
 455.833 +     * @see     java.lang.System#getProperty(java.lang.String)
 455.834 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 455.835 +     */
 455.836 +    public static Long getLong(String nm) {
 455.837 +        return getLong(nm, null);
 455.838 +    }
 455.839 +
 455.840 +    /**
 455.841 +     * Determines the {@code long} value of the system property
 455.842 +     * with the specified name.
 455.843 +     *
 455.844 +     * <p>The first argument is treated as the name of a system property.
 455.845 +     * System properties are accessible through the {@link
 455.846 +     * java.lang.System#getProperty(java.lang.String)} method. The
 455.847 +     * string value of this property is then interpreted as a
 455.848 +     * {@code long} value and a {@code Long} object
 455.849 +     * representing this value is returned.  Details of possible
 455.850 +     * numeric formats can be found with the definition of
 455.851 +     * {@code getProperty}.
 455.852 +     *
 455.853 +     * <p>The second argument is the default value. A {@code Long} object
 455.854 +     * that represents the value of the second argument is returned if there
 455.855 +     * is no property of the specified name, if the property does not have
 455.856 +     * the correct numeric format, or if the specified name is empty or null.
 455.857 +     *
 455.858 +     * <p>In other words, this method returns a {@code Long} object equal
 455.859 +     * to the value of:
 455.860 +     *
 455.861 +     * <blockquote>
 455.862 +     *  {@code getLong(nm, new Long(val))}
 455.863 +     * </blockquote>
 455.864 +     *
 455.865 +     * but in practice it may be implemented in a manner such as:
 455.866 +     *
 455.867 +     * <blockquote><pre>
 455.868 +     * Long result = getLong(nm, null);
 455.869 +     * return (result == null) ? new Long(val) : result;
 455.870 +     * </pre></blockquote>
 455.871 +     *
 455.872 +     * to avoid the unnecessary allocation of a {@code Long} object when
 455.873 +     * the default value is not needed.
 455.874 +     *
 455.875 +     * @param   nm    property name.
 455.876 +     * @param   val   default value.
 455.877 +     * @return  the {@code Long} value of the property.
 455.878 +     * @see     java.lang.System#getProperty(java.lang.String)
 455.879 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 455.880 +     */
 455.881 +    public static Long getLong(String nm, long val) {
 455.882 +        Long result = Long.getLong(nm, null);
 455.883 +        return (result == null) ? Long.valueOf(val) : result;
 455.884 +    }
 455.885 +
 455.886 +    /**
 455.887 +     * Returns the {@code long} value of the system property with
 455.888 +     * the specified name.  The first argument is treated as the name
 455.889 +     * of a system property.  System properties are accessible through
 455.890 +     * the {@link java.lang.System#getProperty(java.lang.String)}
 455.891 +     * method. The string value of this property is then interpreted
 455.892 +     * as a {@code long} value, as per the
 455.893 +     * {@code Long.decode} method, and a {@code Long} object
 455.894 +     * representing this value is returned.
 455.895 +     *
 455.896 +     * <ul>
 455.897 +     * <li>If the property value begins with the two ASCII characters
 455.898 +     * {@code 0x} or the ASCII character {@code #}, not followed by
 455.899 +     * a minus sign, then the rest of it is parsed as a hexadecimal integer
 455.900 +     * exactly as for the method {@link #valueOf(java.lang.String, int)}
 455.901 +     * with radix 16.
 455.902 +     * <li>If the property value begins with the ASCII character
 455.903 +     * {@code 0} followed by another character, it is parsed as
 455.904 +     * an octal integer exactly as by the method {@link
 455.905 +     * #valueOf(java.lang.String, int)} with radix 8.
 455.906 +     * <li>Otherwise the property value is parsed as a decimal
 455.907 +     * integer exactly as by the method
 455.908 +     * {@link #valueOf(java.lang.String, int)} with radix 10.
 455.909 +     * </ul>
 455.910 +     *
 455.911 +     * <p>Note that, in every case, neither {@code L}
 455.912 +     * (<code>'&#92;u004C'</code>) nor {@code l}
 455.913 +     * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 455.914 +     * of the property value as a type indicator, as would be
 455.915 +     * permitted in Java programming language source code.
 455.916 +     *
 455.917 +     * <p>The second argument is the default value. The default value is
 455.918 +     * returned if there is no property of the specified name, if the
 455.919 +     * property does not have the correct numeric format, or if the
 455.920 +     * specified name is empty or {@code null}.
 455.921 +     *
 455.922 +     * @param   nm   property name.
 455.923 +     * @param   val   default value.
 455.924 +     * @return  the {@code Long} value of the property.
 455.925 +     * @see     java.lang.System#getProperty(java.lang.String)
 455.926 +     * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
 455.927 +     * @see java.lang.Long#decode
 455.928 +     */
 455.929 +    public static Long getLong(String nm, Long val) {
 455.930 +        String v = null;
 455.931 +        try {
 455.932 +            v = AbstractStringBuilder.getProperty(nm);
 455.933 +        } catch (IllegalArgumentException e) {
 455.934 +        } catch (NullPointerException e) {
 455.935 +        }
 455.936 +        if (v != null) {
 455.937 +            try {
 455.938 +                return Long.decode(v);
 455.939 +            } catch (NumberFormatException e) {
 455.940 +            }
 455.941 +        }
 455.942 +        return val;
 455.943 +    }
 455.944 +
 455.945 +    /**
 455.946 +     * Compares two {@code Long} objects numerically.
 455.947 +     *
 455.948 +     * @param   anotherLong   the {@code Long} to be compared.
 455.949 +     * @return  the value {@code 0} if this {@code Long} is
 455.950 +     *          equal to the argument {@code Long}; a value less than
 455.951 +     *          {@code 0} if this {@code Long} is numerically less
 455.952 +     *          than the argument {@code Long}; and a value greater
 455.953 +     *          than {@code 0} if this {@code Long} is numerically
 455.954 +     *           greater than the argument {@code Long} (signed
 455.955 +     *           comparison).
 455.956 +     * @since   1.2
 455.957 +     */
 455.958 +    public int compareTo(Long anotherLong) {
 455.959 +        return compare(this.value, anotherLong.value);
 455.960 +    }
 455.961 +
 455.962 +    /**
 455.963 +     * Compares two {@code long} values numerically.
 455.964 +     * The value returned is identical to what would be returned by:
 455.965 +     * <pre>
 455.966 +     *    Long.valueOf(x).compareTo(Long.valueOf(y))
 455.967 +     * </pre>
 455.968 +     *
 455.969 +     * @param  x the first {@code long} to compare
 455.970 +     * @param  y the second {@code long} to compare
 455.971 +     * @return the value {@code 0} if {@code x == y};
 455.972 +     *         a value less than {@code 0} if {@code x < y}; and
 455.973 +     *         a value greater than {@code 0} if {@code x > y}
 455.974 +     * @since 1.7
 455.975 +     */
 455.976 +    public static int compare(long x, long y) {
 455.977 +        return (x < y) ? -1 : ((x == y) ? 0 : 1);
 455.978 +    }
 455.979 +
 455.980 +
 455.981 +    // Bit Twiddling
 455.982 +
 455.983 +    /**
 455.984 +     * The number of bits used to represent a {@code long} value in two's
 455.985 +     * complement binary form.
 455.986 +     *
 455.987 +     * @since 1.5
 455.988 +     */
 455.989 +    public static final int SIZE = 64;
 455.990 +
 455.991 +    /**
 455.992 +     * Returns a {@code long} value with at most a single one-bit, in the
 455.993 +     * position of the highest-order ("leftmost") one-bit in the specified
 455.994 +     * {@code long} value.  Returns zero if the specified value has no
 455.995 +     * one-bits in its two's complement binary representation, that is, if it
 455.996 +     * is equal to zero.
 455.997 +     *
 455.998 +     * @return a {@code long} value with a single one-bit, in the position
 455.999 +     *     of the highest-order one-bit in the specified value, or zero if
455.1000 +     *     the specified value is itself equal to zero.
455.1001 +     * @since 1.5
455.1002 +     */
455.1003 +    public static long highestOneBit(long i) {
455.1004 +        // HD, Figure 3-1
455.1005 +        i |= (i >>  1);
455.1006 +        i |= (i >>  2);
455.1007 +        i |= (i >>  4);
455.1008 +        i |= (i >>  8);
455.1009 +        i |= (i >> 16);
455.1010 +        i |= (i >> 32);
455.1011 +        return i - (i >>> 1);
455.1012 +    }
455.1013 +
455.1014 +    /**
455.1015 +     * Returns a {@code long} value with at most a single one-bit, in the
455.1016 +     * position of the lowest-order ("rightmost") one-bit in the specified
455.1017 +     * {@code long} value.  Returns zero if the specified value has no
455.1018 +     * one-bits in its two's complement binary representation, that is, if it
455.1019 +     * is equal to zero.
455.1020 +     *
455.1021 +     * @return a {@code long} value with a single one-bit, in the position
455.1022 +     *     of the lowest-order one-bit in the specified value, or zero if
455.1023 +     *     the specified value is itself equal to zero.
455.1024 +     * @since 1.5
455.1025 +     */
455.1026 +    public static long lowestOneBit(long i) {
455.1027 +        // HD, Section 2-1
455.1028 +        return i & -i;
455.1029 +    }
455.1030 +
455.1031 +    /**
455.1032 +     * Returns the number of zero bits preceding the highest-order
455.1033 +     * ("leftmost") one-bit in the two's complement binary representation
455.1034 +     * of the specified {@code long} value.  Returns 64 if the
455.1035 +     * specified value has no one-bits in its two's complement representation,
455.1036 +     * in other words if it is equal to zero.
455.1037 +     *
455.1038 +     * <p>Note that this method is closely related to the logarithm base 2.
455.1039 +     * For all positive {@code long} values x:
455.1040 +     * <ul>
455.1041 +     * <li>floor(log<sub>2</sub>(x)) = {@code 63 - numberOfLeadingZeros(x)}
455.1042 +     * <li>ceil(log<sub>2</sub>(x)) = {@code 64 - numberOfLeadingZeros(x - 1)}
455.1043 +     * </ul>
455.1044 +     *
455.1045 +     * @return the number of zero bits preceding the highest-order
455.1046 +     *     ("leftmost") one-bit in the two's complement binary representation
455.1047 +     *     of the specified {@code long} value, or 64 if the value
455.1048 +     *     is equal to zero.
455.1049 +     * @since 1.5
455.1050 +     */
455.1051 +    public static int numberOfLeadingZeros(long i) {
455.1052 +        // HD, Figure 5-6
455.1053 +         if (i == 0)
455.1054 +            return 64;
455.1055 +        int n = 1;
455.1056 +        int x = (int)(i >>> 32);
455.1057 +        if (x == 0) { n += 32; x = (int)i; }
455.1058 +        if (x >>> 16 == 0) { n += 16; x <<= 16; }
455.1059 +        if (x >>> 24 == 0) { n +=  8; x <<=  8; }
455.1060 +        if (x >>> 28 == 0) { n +=  4; x <<=  4; }
455.1061 +        if (x >>> 30 == 0) { n +=  2; x <<=  2; }
455.1062 +        n -= x >>> 31;
455.1063 +        return n;
455.1064 +    }
455.1065 +
455.1066 +    /**
455.1067 +     * Returns the number of zero bits following the lowest-order ("rightmost")
455.1068 +     * one-bit in the two's complement binary representation of the specified
455.1069 +     * {@code long} value.  Returns 64 if the specified value has no
455.1070 +     * one-bits in its two's complement representation, in other words if it is
455.1071 +     * equal to zero.
455.1072 +     *
455.1073 +     * @return the number of zero bits following the lowest-order ("rightmost")
455.1074 +     *     one-bit in the two's complement binary representation of the
455.1075 +     *     specified {@code long} value, or 64 if the value is equal
455.1076 +     *     to zero.
455.1077 +     * @since 1.5
455.1078 +     */
455.1079 +    public static int numberOfTrailingZeros(long i) {
455.1080 +        // HD, Figure 5-14
455.1081 +        int x, y;
455.1082 +        if (i == 0) return 64;
455.1083 +        int n = 63;
455.1084 +        y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
455.1085 +        y = x <<16; if (y != 0) { n = n -16; x = y; }
455.1086 +        y = x << 8; if (y != 0) { n = n - 8; x = y; }
455.1087 +        y = x << 4; if (y != 0) { n = n - 4; x = y; }
455.1088 +        y = x << 2; if (y != 0) { n = n - 2; x = y; }
455.1089 +        return n - ((x << 1) >>> 31);
455.1090 +    }
455.1091 +
455.1092 +    /**
455.1093 +     * Returns the number of one-bits in the two's complement binary
455.1094 +     * representation of the specified {@code long} value.  This function is
455.1095 +     * sometimes referred to as the <i>population count</i>.
455.1096 +     *
455.1097 +     * @return the number of one-bits in the two's complement binary
455.1098 +     *     representation of the specified {@code long} value.
455.1099 +     * @since 1.5
455.1100 +     */
455.1101 +     public static int bitCount(long i) {
455.1102 +        // HD, Figure 5-14
455.1103 +        i = i - ((i >>> 1) & 0x5555555555555555L);
455.1104 +        i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
455.1105 +        i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
455.1106 +        i = i + (i >>> 8);
455.1107 +        i = i + (i >>> 16);
455.1108 +        i = i + (i >>> 32);
455.1109 +        return (int)i & 0x7f;
455.1110 +     }
455.1111 +
455.1112 +    /**
455.1113 +     * Returns the value obtained by rotating the two's complement binary
455.1114 +     * representation of the specified {@code long} value left by the
455.1115 +     * specified number of bits.  (Bits shifted out of the left hand, or
455.1116 +     * high-order, side reenter on the right, or low-order.)
455.1117 +     *
455.1118 +     * <p>Note that left rotation with a negative distance is equivalent to
455.1119 +     * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
455.1120 +     * distance)}.  Note also that rotation by any multiple of 64 is a
455.1121 +     * no-op, so all but the last six bits of the rotation distance can be
455.1122 +     * ignored, even if the distance is negative: {@code rotateLeft(val,
455.1123 +     * distance) == rotateLeft(val, distance & 0x3F)}.
455.1124 +     *
455.1125 +     * @return the value obtained by rotating the two's complement binary
455.1126 +     *     representation of the specified {@code long} value left by the
455.1127 +     *     specified number of bits.
455.1128 +     * @since 1.5
455.1129 +     */
455.1130 +    public static long rotateLeft(long i, int distance) {
455.1131 +        return (i << distance) | (i >>> -distance);
455.1132 +    }
455.1133 +
455.1134 +    /**
455.1135 +     * Returns the value obtained by rotating the two's complement binary
455.1136 +     * representation of the specified {@code long} value right by the
455.1137 +     * specified number of bits.  (Bits shifted out of the right hand, or
455.1138 +     * low-order, side reenter on the left, or high-order.)
455.1139 +     *
455.1140 +     * <p>Note that right rotation with a negative distance is equivalent to
455.1141 +     * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
455.1142 +     * distance)}.  Note also that rotation by any multiple of 64 is a
455.1143 +     * no-op, so all but the last six bits of the rotation distance can be
455.1144 +     * ignored, even if the distance is negative: {@code rotateRight(val,
455.1145 +     * distance) == rotateRight(val, distance & 0x3F)}.
455.1146 +     *
455.1147 +     * @return the value obtained by rotating the two's complement binary
455.1148 +     *     representation of the specified {@code long} value right by the
455.1149 +     *     specified number of bits.
455.1150 +     * @since 1.5
455.1151 +     */
455.1152 +    public static long rotateRight(long i, int distance) {
455.1153 +        return (i >>> distance) | (i << -distance);
455.1154 +    }
455.1155 +
455.1156 +    /**
455.1157 +     * Returns the value obtained by reversing the order of the bits in the
455.1158 +     * two's complement binary representation of the specified {@code long}
455.1159 +     * value.
455.1160 +     *
455.1161 +     * @return the value obtained by reversing order of the bits in the
455.1162 +     *     specified {@code long} value.
455.1163 +     * @since 1.5
455.1164 +     */
455.1165 +    public static long reverse(long i) {
455.1166 +        // HD, Figure 7-1
455.1167 +        i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
455.1168 +        i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
455.1169 +        i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
455.1170 +        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
455.1171 +        i = (i << 48) | ((i & 0xffff0000L) << 16) |
455.1172 +            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
455.1173 +        return i;
455.1174 +    }
455.1175 +
455.1176 +    /**
455.1177 +     * Returns the signum function of the specified {@code long} value.  (The
455.1178 +     * return value is -1 if the specified value is negative; 0 if the
455.1179 +     * specified value is zero; and 1 if the specified value is positive.)
455.1180 +     *
455.1181 +     * @return the signum function of the specified {@code long} value.
455.1182 +     * @since 1.5
455.1183 +     */
455.1184 +    public static int signum(long i) {
455.1185 +        // HD, Section 2-7
455.1186 +        return (int) ((i >> 63) | (-i >>> 63));
455.1187 +    }
455.1188 +
455.1189 +    /**
455.1190 +     * Returns the value obtained by reversing the order of the bytes in the
455.1191 +     * two's complement representation of the specified {@code long} value.
455.1192 +     *
455.1193 +     * @return the value obtained by reversing the bytes in the specified
455.1194 +     *     {@code long} value.
455.1195 +     * @since 1.5
455.1196 +     */
455.1197 +    public static long reverseBytes(long i) {
455.1198 +        i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
455.1199 +        return (i << 48) | ((i & 0xffff0000L) << 16) |
455.1200 +            ((i >>> 16) & 0xffff0000L) | (i >>> 48);
455.1201 +    }
455.1202 +
455.1203 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
455.1204 +    private static final long serialVersionUID = 4290774380558885855L;
455.1205 +}
   456.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   456.2 +++ b/rt/emul/mini/src/main/java/java/lang/Math.java	Wed Feb 27 11:24:58 2013 +0100
   456.3 @@ -0,0 +1,1311 @@
   456.4 +/*
   456.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   456.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   456.7 + *
   456.8 + * This code is free software; you can redistribute it and/or modify it
   456.9 + * under the terms of the GNU General Public License version 2 only, as
  456.10 + * published by the Free Software Foundation.  Oracle designates this
  456.11 + * particular file as subject to the "Classpath" exception as provided
  456.12 + * by Oracle in the LICENSE file that accompanied this code.
  456.13 + *
  456.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  456.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  456.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  456.17 + * version 2 for more details (a copy is included in the LICENSE file that
  456.18 + * accompanied this code).
  456.19 + *
  456.20 + * You should have received a copy of the GNU General Public License version
  456.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  456.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  456.23 + *
  456.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  456.25 + * or visit www.oracle.com if you need additional information or have any
  456.26 + * questions.
  456.27 + */
  456.28 +
  456.29 +package java.lang;
  456.30 +
  456.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  456.32 +
  456.33 +
  456.34 +/**
  456.35 + * The class {@code Math} contains methods for performing basic
  456.36 + * numeric operations such as the elementary exponential, logarithm,
  456.37 + * square root, and trigonometric functions.
  456.38 + *
  456.39 + * <p>Unlike some of the numeric methods of class
  456.40 + * {@code StrictMath}, all implementations of the equivalent
  456.41 + * functions of class {@code Math} are not defined to return the
  456.42 + * bit-for-bit same results.  This relaxation permits
  456.43 + * better-performing implementations where strict reproducibility is
  456.44 + * not required.
  456.45 + *
  456.46 + * <p>By default many of the {@code Math} methods simply call
  456.47 + * the equivalent method in {@code StrictMath} for their
  456.48 + * implementation.  Code generators are encouraged to use
  456.49 + * platform-specific native libraries or microprocessor instructions,
  456.50 + * where available, to provide higher-performance implementations of
  456.51 + * {@code Math} methods.  Such higher-performance
  456.52 + * implementations still must conform to the specification for
  456.53 + * {@code Math}.
  456.54 + *
  456.55 + * <p>The quality of implementation specifications concern two
  456.56 + * properties, accuracy of the returned result and monotonicity of the
  456.57 + * method.  Accuracy of the floating-point {@code Math} methods
  456.58 + * is measured in terms of <i>ulps</i>, units in the last place.  For
  456.59 + * a given floating-point format, an ulp of a specific real number
  456.60 + * value is the distance between the two floating-point values
  456.61 + * bracketing that numerical value.  When discussing the accuracy of a
  456.62 + * method as a whole rather than at a specific argument, the number of
  456.63 + * ulps cited is for the worst-case error at any argument.  If a
  456.64 + * method always has an error less than 0.5 ulps, the method always
  456.65 + * returns the floating-point number nearest the exact result; such a
  456.66 + * method is <i>correctly rounded</i>.  A correctly rounded method is
  456.67 + * generally the best a floating-point approximation can be; however,
  456.68 + * it is impractical for many floating-point methods to be correctly
  456.69 + * rounded.  Instead, for the {@code Math} class, a larger error
  456.70 + * bound of 1 or 2 ulps is allowed for certain methods.  Informally,
  456.71 + * with a 1 ulp error bound, when the exact result is a representable
  456.72 + * number, the exact result should be returned as the computed result;
  456.73 + * otherwise, either of the two floating-point values which bracket
  456.74 + * the exact result may be returned.  For exact results large in
  456.75 + * magnitude, one of the endpoints of the bracket may be infinite.
  456.76 + * Besides accuracy at individual arguments, maintaining proper
  456.77 + * relations between the method at different arguments is also
  456.78 + * important.  Therefore, most methods with more than 0.5 ulp errors
  456.79 + * are required to be <i>semi-monotonic</i>: whenever the mathematical
  456.80 + * function is non-decreasing, so is the floating-point approximation,
  456.81 + * likewise, whenever the mathematical function is non-increasing, so
  456.82 + * is the floating-point approximation.  Not all approximations that
  456.83 + * have 1 ulp accuracy will automatically meet the monotonicity
  456.84 + * requirements.
  456.85 + *
  456.86 + * @author  unascribed
  456.87 + * @author  Joseph D. Darcy
  456.88 + * @since   JDK1.0
  456.89 + */
  456.90 +
  456.91 +public final class Math {
  456.92 +
  456.93 +    /**
  456.94 +     * Don't let anyone instantiate this class.
  456.95 +     */
  456.96 +    private Math() {}
  456.97 +
  456.98 +    /**
  456.99 +     * The {@code double} value that is closer than any other to
 456.100 +     * <i>e</i>, the base of the natural logarithms.
 456.101 +     */
 456.102 +    public static final double E = 2.7182818284590452354;
 456.103 +
 456.104 +    /**
 456.105 +     * The {@code double} value that is closer than any other to
 456.106 +     * <i>pi</i>, the ratio of the circumference of a circle to its
 456.107 +     * diameter.
 456.108 +     */
 456.109 +    public static final double PI = 3.14159265358979323846;
 456.110 +
 456.111 +    /**
 456.112 +     * Returns the trigonometric sine of an angle.  Special cases:
 456.113 +     * <ul><li>If the argument is NaN or an infinity, then the
 456.114 +     * result is NaN.
 456.115 +     * <li>If the argument is zero, then the result is a zero with the
 456.116 +     * same sign as the argument.</ul>
 456.117 +     *
 456.118 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.119 +     * Results must be semi-monotonic.
 456.120 +     *
 456.121 +     * @param   a   an angle, in radians.
 456.122 +     * @return  the sine of the argument.
 456.123 +     */
 456.124 +    @JavaScriptBody(args="a", body="return Math.sin(a);")
 456.125 +    public static double sin(double a) {
 456.126 +        throw new UnsupportedOperationException();
 456.127 +    }
 456.128 +
 456.129 +    /**
 456.130 +     * Returns the trigonometric cosine of an angle. Special cases:
 456.131 +     * <ul><li>If the argument is NaN or an infinity, then the
 456.132 +     * result is NaN.</ul>
 456.133 +     *
 456.134 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.135 +     * Results must be semi-monotonic.
 456.136 +     *
 456.137 +     * @param   a   an angle, in radians.
 456.138 +     * @return  the cosine of the argument.
 456.139 +     */
 456.140 +    @JavaScriptBody(args="a", body="return Math.cos(a);")
 456.141 +    public static double cos(double a) {
 456.142 +        throw new UnsupportedOperationException();
 456.143 +    }
 456.144 +
 456.145 +    /**
 456.146 +     * Returns the trigonometric tangent of an angle.  Special cases:
 456.147 +     * <ul><li>If the argument is NaN or an infinity, then the result
 456.148 +     * is NaN.
 456.149 +     * <li>If the argument is zero, then the result is a zero with the
 456.150 +     * same sign as the argument.</ul>
 456.151 +     *
 456.152 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.153 +     * Results must be semi-monotonic.
 456.154 +     *
 456.155 +     * @param   a   an angle, in radians.
 456.156 +     * @return  the tangent of the argument.
 456.157 +     */
 456.158 +    @JavaScriptBody(args="a", body="return Math.tan(a);")
 456.159 +    public static double tan(double a) {
 456.160 +        throw new UnsupportedOperationException();
 456.161 +    }
 456.162 +
 456.163 +    /**
 456.164 +     * Returns the arc sine of a value; the returned angle is in the
 456.165 +     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 456.166 +     * <ul><li>If the argument is NaN or its absolute value is greater
 456.167 +     * than 1, then the result is NaN.
 456.168 +     * <li>If the argument is zero, then the result is a zero with the
 456.169 +     * same sign as the argument.</ul>
 456.170 +     *
 456.171 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.172 +     * Results must be semi-monotonic.
 456.173 +     *
 456.174 +     * @param   a   the value whose arc sine is to be returned.
 456.175 +     * @return  the arc sine of the argument.
 456.176 +     */
 456.177 +    @JavaScriptBody(args="a", body="return Math.asin(a);")
 456.178 +    public static double asin(double a) {
 456.179 +        throw new UnsupportedOperationException();
 456.180 +    }
 456.181 +
 456.182 +    /**
 456.183 +     * Returns the arc cosine of a value; the returned angle is in the
 456.184 +     * range 0.0 through <i>pi</i>.  Special case:
 456.185 +     * <ul><li>If the argument is NaN or its absolute value is greater
 456.186 +     * than 1, then the result is NaN.</ul>
 456.187 +     *
 456.188 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.189 +     * Results must be semi-monotonic.
 456.190 +     *
 456.191 +     * @param   a   the value whose arc cosine is to be returned.
 456.192 +     * @return  the arc cosine of the argument.
 456.193 +     */
 456.194 +    @JavaScriptBody(args="a", body="return Math.acos(a);")
 456.195 +    public static double acos(double a) {
 456.196 +        throw new UnsupportedOperationException();
 456.197 +    }
 456.198 +
 456.199 +    /**
 456.200 +     * Returns the arc tangent of a value; the returned angle is in the
 456.201 +     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 456.202 +     * <ul><li>If the argument is NaN, then the result is NaN.
 456.203 +     * <li>If the argument is zero, then the result is a zero with the
 456.204 +     * same sign as the argument.</ul>
 456.205 +     *
 456.206 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.207 +     * Results must be semi-monotonic.
 456.208 +     *
 456.209 +     * @param   a   the value whose arc tangent is to be returned.
 456.210 +     * @return  the arc tangent of the argument.
 456.211 +     */
 456.212 +    @JavaScriptBody(args="a", body="return Math.atan(a);")
 456.213 +    public static double atan(double a) {
 456.214 +        throw new UnsupportedOperationException();
 456.215 +    }
 456.216 +
 456.217 +    /**
 456.218 +     * Converts an angle measured in degrees to an approximately
 456.219 +     * equivalent angle measured in radians.  The conversion from
 456.220 +     * degrees to radians is generally inexact.
 456.221 +     *
 456.222 +     * @param   angdeg   an angle, in degrees
 456.223 +     * @return  the measurement of the angle {@code angdeg}
 456.224 +     *          in radians.
 456.225 +     * @since   1.2
 456.226 +     */
 456.227 +    public static double toRadians(double angdeg) {
 456.228 +        return angdeg / 180.0 * PI;
 456.229 +    }
 456.230 +
 456.231 +    /**
 456.232 +     * Converts an angle measured in radians to an approximately
 456.233 +     * equivalent angle measured in degrees.  The conversion from
 456.234 +     * radians to degrees is generally inexact; users should
 456.235 +     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
 456.236 +     * equal {@code 0.0}.
 456.237 +     *
 456.238 +     * @param   angrad   an angle, in radians
 456.239 +     * @return  the measurement of the angle {@code angrad}
 456.240 +     *          in degrees.
 456.241 +     * @since   1.2
 456.242 +     */
 456.243 +    public static double toDegrees(double angrad) {
 456.244 +        return angrad * 180.0 / PI;
 456.245 +    }
 456.246 +
 456.247 +    /**
 456.248 +     * Returns Euler's number <i>e</i> raised to the power of a
 456.249 +     * {@code double} value.  Special cases:
 456.250 +     * <ul><li>If the argument is NaN, the result is NaN.
 456.251 +     * <li>If the argument is positive infinity, then the result is
 456.252 +     * positive infinity.
 456.253 +     * <li>If the argument is negative infinity, then the result is
 456.254 +     * positive zero.</ul>
 456.255 +     *
 456.256 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.257 +     * Results must be semi-monotonic.
 456.258 +     *
 456.259 +     * @param   a   the exponent to raise <i>e</i> to.
 456.260 +     * @return  the value <i>e</i><sup>{@code a}</sup>,
 456.261 +     *          where <i>e</i> is the base of the natural logarithms.
 456.262 +     */
 456.263 +    @JavaScriptBody(args="a", body="return Math.exp(a);")
 456.264 +    public static double exp(double a) {
 456.265 +        throw new UnsupportedOperationException();
 456.266 +    }
 456.267 +
 456.268 +    /**
 456.269 +     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
 456.270 +     * value.  Special cases:
 456.271 +     * <ul><li>If the argument is NaN or less than zero, then the result
 456.272 +     * is NaN.
 456.273 +     * <li>If the argument is positive infinity, then the result is
 456.274 +     * positive infinity.
 456.275 +     * <li>If the argument is positive zero or negative zero, then the
 456.276 +     * result is negative infinity.</ul>
 456.277 +     *
 456.278 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.279 +     * Results must be semi-monotonic.
 456.280 +     *
 456.281 +     * @param   a   a value
 456.282 +     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
 456.283 +     *          {@code a}.
 456.284 +     */
 456.285 +    @JavaScriptBody(args="a", body="return Math.log(a);")
 456.286 +    public static double log(double a) {
 456.287 +        throw new UnsupportedOperationException();
 456.288 +    }
 456.289 +
 456.290 +    /**
 456.291 +     * Returns the base 10 logarithm of a {@code double} value.
 456.292 +     * Special cases:
 456.293 +     *
 456.294 +     * <ul><li>If the argument is NaN or less than zero, then the result
 456.295 +     * is NaN.
 456.296 +     * <li>If the argument is positive infinity, then the result is
 456.297 +     * positive infinity.
 456.298 +     * <li>If the argument is positive zero or negative zero, then the
 456.299 +     * result is negative infinity.
 456.300 +     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
 456.301 +     * integer <i>n</i>, then the result is <i>n</i>.
 456.302 +     * </ul>
 456.303 +     *
 456.304 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.305 +     * Results must be semi-monotonic.
 456.306 +     *
 456.307 +     * @param   a   a value
 456.308 +     * @return  the base 10 logarithm of  {@code a}.
 456.309 +     * @since 1.5
 456.310 +     */
 456.311 +    @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
 456.312 +    public static double log10(double a) {
 456.313 +        throw new UnsupportedOperationException();
 456.314 +    }
 456.315 +
 456.316 +    /**
 456.317 +     * Returns the correctly rounded positive square root of a
 456.318 +     * {@code double} value.
 456.319 +     * Special cases:
 456.320 +     * <ul><li>If the argument is NaN or less than zero, then the result
 456.321 +     * is NaN.
 456.322 +     * <li>If the argument is positive infinity, then the result is positive
 456.323 +     * infinity.
 456.324 +     * <li>If the argument is positive zero or negative zero, then the
 456.325 +     * result is the same as the argument.</ul>
 456.326 +     * Otherwise, the result is the {@code double} value closest to
 456.327 +     * the true mathematical square root of the argument value.
 456.328 +     *
 456.329 +     * @param   a   a value.
 456.330 +     * @return  the positive square root of {@code a}.
 456.331 +     *          If the argument is NaN or less than zero, the result is NaN.
 456.332 +     */
 456.333 +    @JavaScriptBody(args="a", body="return Math.sqrt(a);")
 456.334 +    public static double sqrt(double a) {
 456.335 +        throw new UnsupportedOperationException();
 456.336 +    }
 456.337 +
 456.338 +    /**
 456.339 +     * Returns the smallest (closest to negative infinity)
 456.340 +     * {@code double} value that is greater than or equal to the
 456.341 +     * argument and is equal to a mathematical integer. Special cases:
 456.342 +     * <ul><li>If the argument value is already equal to a
 456.343 +     * mathematical integer, then the result is the same as the
 456.344 +     * argument.  <li>If the argument is NaN or an infinity or
 456.345 +     * positive zero or negative zero, then the result is the same as
 456.346 +     * the argument.  <li>If the argument value is less than zero but
 456.347 +     * greater than -1.0, then the result is negative zero.</ul> Note
 456.348 +     * that the value of {@code Math.ceil(x)} is exactly the
 456.349 +     * value of {@code -Math.floor(-x)}.
 456.350 +     *
 456.351 +     *
 456.352 +     * @param   a   a value.
 456.353 +     * @return  the smallest (closest to negative infinity)
 456.354 +     *          floating-point value that is greater than or equal to
 456.355 +     *          the argument and is equal to a mathematical integer.
 456.356 +     */
 456.357 +    @JavaScriptBody(args="a", body="return Math.ceil(a);")
 456.358 +    public static double ceil(double a) {
 456.359 +        throw new UnsupportedOperationException();
 456.360 +    }
 456.361 +
 456.362 +    /**
 456.363 +     * Returns the largest (closest to positive infinity)
 456.364 +     * {@code double} value that is less than or equal to the
 456.365 +     * argument and is equal to a mathematical integer. Special cases:
 456.366 +     * <ul><li>If the argument value is already equal to a
 456.367 +     * mathematical integer, then the result is the same as the
 456.368 +     * argument.  <li>If the argument is NaN or an infinity or
 456.369 +     * positive zero or negative zero, then the result is the same as
 456.370 +     * the argument.</ul>
 456.371 +     *
 456.372 +     * @param   a   a value.
 456.373 +     * @return  the largest (closest to positive infinity)
 456.374 +     *          floating-point value that less than or equal to the argument
 456.375 +     *          and is equal to a mathematical integer.
 456.376 +     */
 456.377 +    @JavaScriptBody(args="a", body="return Math.floor(a);")
 456.378 +    public static double floor(double a) {
 456.379 +        throw new UnsupportedOperationException();
 456.380 +    }
 456.381 +    /**
 456.382 +     * Computes the remainder operation on two arguments as prescribed
 456.383 +     * by the IEEE 754 standard.
 456.384 +     * The remainder value is mathematically equal to
 456.385 +     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
 456.386 +     * where <i>n</i> is the mathematical integer closest to the exact
 456.387 +     * mathematical value of the quotient {@code f1/f2}, and if two
 456.388 +     * mathematical integers are equally close to {@code f1/f2},
 456.389 +     * then <i>n</i> is the integer that is even. If the remainder is
 456.390 +     * zero, its sign is the same as the sign of the first argument.
 456.391 +     * Special cases:
 456.392 +     * <ul><li>If either argument is NaN, or the first argument is infinite,
 456.393 +     * or the second argument is positive zero or negative zero, then the
 456.394 +     * result is NaN.
 456.395 +     * <li>If the first argument is finite and the second argument is
 456.396 +     * infinite, then the result is the same as the first argument.</ul>
 456.397 +     *
 456.398 +     * @param   f1   the dividend.
 456.399 +     * @param   f2   the divisor.
 456.400 +     * @return  the remainder when {@code f1} is divided by
 456.401 +     *          {@code f2}.
 456.402 +     */
 456.403 +    public static double IEEEremainder(double f1, double f2) {
 456.404 +        return f1 - (f2 * Math.round(f1 / f2));
 456.405 +    }
 456.406 +
 456.407 +    /**
 456.408 +     * Returns the {@code double} value that is closest in value
 456.409 +     * to the argument and is equal to a mathematical integer. If two
 456.410 +     * {@code double} values that are mathematical integers are
 456.411 +     * equally close, the result is the integer value that is
 456.412 +     * even. Special cases:
 456.413 +     * <ul><li>If the argument value is already equal to a mathematical
 456.414 +     * integer, then the result is the same as the argument.
 456.415 +     * <li>If the argument is NaN or an infinity or positive zero or negative
 456.416 +     * zero, then the result is the same as the argument.</ul>
 456.417 +     *
 456.418 +     * @param   a   a {@code double} value.
 456.419 +     * @return  the closest floating-point value to {@code a} that is
 456.420 +     *          equal to a mathematical integer.
 456.421 +     */
 456.422 +    public static double rint(double a) {
 456.423 +        double ceil = ceil(a);
 456.424 +        double floor = floor(a);
 456.425 +        
 456.426 +        double dc = ceil - a;
 456.427 +        double df = a - floor;
 456.428 +        
 456.429 +        if (dc < df) {
 456.430 +            return ceil;
 456.431 +        } else if (dc > df) {
 456.432 +            return floor;
 456.433 +        }
 456.434 +        
 456.435 +        int tenC = (int) (ceil % 10.0);
 456.436 +        
 456.437 +        if (tenC % 2 == 0) {
 456.438 +            return ceil;
 456.439 +        } else {
 456.440 +            return floor;
 456.441 +        }
 456.442 +    }
 456.443 +
 456.444 +    /**
 456.445 +     * Returns the angle <i>theta</i> from the conversion of rectangular
 456.446 +     * coordinates ({@code x},&nbsp;{@code y}) to polar
 456.447 +     * coordinates (r,&nbsp;<i>theta</i>).
 456.448 +     * This method computes the phase <i>theta</i> by computing an arc tangent
 456.449 +     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
 456.450 +     * cases:
 456.451 +     * <ul><li>If either argument is NaN, then the result is NaN.
 456.452 +     * <li>If the first argument is positive zero and the second argument
 456.453 +     * is positive, or the first argument is positive and finite and the
 456.454 +     * second argument is positive infinity, then the result is positive
 456.455 +     * zero.
 456.456 +     * <li>If the first argument is negative zero and the second argument
 456.457 +     * is positive, or the first argument is negative and finite and the
 456.458 +     * second argument is positive infinity, then the result is negative zero.
 456.459 +     * <li>If the first argument is positive zero and the second argument
 456.460 +     * is negative, or the first argument is positive and finite and the
 456.461 +     * second argument is negative infinity, then the result is the
 456.462 +     * {@code double} value closest to <i>pi</i>.
 456.463 +     * <li>If the first argument is negative zero and the second argument
 456.464 +     * is negative, or the first argument is negative and finite and the
 456.465 +     * second argument is negative infinity, then the result is the
 456.466 +     * {@code double} value closest to -<i>pi</i>.
 456.467 +     * <li>If the first argument is positive and the second argument is
 456.468 +     * positive zero or negative zero, or the first argument is positive
 456.469 +     * infinity and the second argument is finite, then the result is the
 456.470 +     * {@code double} value closest to <i>pi</i>/2.
 456.471 +     * <li>If the first argument is negative and the second argument is
 456.472 +     * positive zero or negative zero, or the first argument is negative
 456.473 +     * infinity and the second argument is finite, then the result is the
 456.474 +     * {@code double} value closest to -<i>pi</i>/2.
 456.475 +     * <li>If both arguments are positive infinity, then the result is the
 456.476 +     * {@code double} value closest to <i>pi</i>/4.
 456.477 +     * <li>If the first argument is positive infinity and the second argument
 456.478 +     * is negative infinity, then the result is the {@code double}
 456.479 +     * value closest to 3*<i>pi</i>/4.
 456.480 +     * <li>If the first argument is negative infinity and the second argument
 456.481 +     * is positive infinity, then the result is the {@code double} value
 456.482 +     * closest to -<i>pi</i>/4.
 456.483 +     * <li>If both arguments are negative infinity, then the result is the
 456.484 +     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
 456.485 +     *
 456.486 +     * <p>The computed result must be within 2 ulps of the exact result.
 456.487 +     * Results must be semi-monotonic.
 456.488 +     *
 456.489 +     * @param   y   the ordinate coordinate
 456.490 +     * @param   x   the abscissa coordinate
 456.491 +     * @return  the <i>theta</i> component of the point
 456.492 +     *          (<i>r</i>,&nbsp;<i>theta</i>)
 456.493 +     *          in polar coordinates that corresponds to the point
 456.494 +     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
 456.495 +     */
 456.496 +    @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
 456.497 +    public static double atan2(double y, double x) {
 456.498 +        throw new UnsupportedOperationException();
 456.499 +    }
 456.500 +
 456.501 +    /**
 456.502 +     * Returns the value of the first argument raised to the power of the
 456.503 +     * second argument. Special cases:
 456.504 +     *
 456.505 +     * <ul><li>If the second argument is positive or negative zero, then the
 456.506 +     * result is 1.0.
 456.507 +     * <li>If the second argument is 1.0, then the result is the same as the
 456.508 +     * first argument.
 456.509 +     * <li>If the second argument is NaN, then the result is NaN.
 456.510 +     * <li>If the first argument is NaN and the second argument is nonzero,
 456.511 +     * then the result is NaN.
 456.512 +     *
 456.513 +     * <li>If
 456.514 +     * <ul>
 456.515 +     * <li>the absolute value of the first argument is greater than 1
 456.516 +     * and the second argument is positive infinity, or
 456.517 +     * <li>the absolute value of the first argument is less than 1 and
 456.518 +     * the second argument is negative infinity,
 456.519 +     * </ul>
 456.520 +     * then the result is positive infinity.
 456.521 +     *
 456.522 +     * <li>If
 456.523 +     * <ul>
 456.524 +     * <li>the absolute value of the first argument is greater than 1 and
 456.525 +     * the second argument is negative infinity, or
 456.526 +     * <li>the absolute value of the
 456.527 +     * first argument is less than 1 and the second argument is positive
 456.528 +     * infinity,
 456.529 +     * </ul>
 456.530 +     * then the result is positive zero.
 456.531 +     *
 456.532 +     * <li>If the absolute value of the first argument equals 1 and the
 456.533 +     * second argument is infinite, then the result is NaN.
 456.534 +     *
 456.535 +     * <li>If
 456.536 +     * <ul>
 456.537 +     * <li>the first argument is positive zero and the second argument
 456.538 +     * is greater than zero, or
 456.539 +     * <li>the first argument is positive infinity and the second
 456.540 +     * argument is less than zero,
 456.541 +     * </ul>
 456.542 +     * then the result is positive zero.
 456.543 +     *
 456.544 +     * <li>If
 456.545 +     * <ul>
 456.546 +     * <li>the first argument is positive zero and the second argument
 456.547 +     * is less than zero, or
 456.548 +     * <li>the first argument is positive infinity and the second
 456.549 +     * argument is greater than zero,
 456.550 +     * </ul>
 456.551 +     * then the result is positive infinity.
 456.552 +     *
 456.553 +     * <li>If
 456.554 +     * <ul>
 456.555 +     * <li>the first argument is negative zero and the second argument
 456.556 +     * is greater than zero but not a finite odd integer, or
 456.557 +     * <li>the first argument is negative infinity and the second
 456.558 +     * argument is less than zero but not a finite odd integer,
 456.559 +     * </ul>
 456.560 +     * then the result is positive zero.
 456.561 +     *
 456.562 +     * <li>If
 456.563 +     * <ul>
 456.564 +     * <li>the first argument is negative zero and the second argument
 456.565 +     * is a positive finite odd integer, or
 456.566 +     * <li>the first argument is negative infinity and the second
 456.567 +     * argument is a negative finite odd integer,
 456.568 +     * </ul>
 456.569 +     * then the result is negative zero.
 456.570 +     *
 456.571 +     * <li>If
 456.572 +     * <ul>
 456.573 +     * <li>the first argument is negative zero and the second argument
 456.574 +     * is less than zero but not a finite odd integer, or
 456.575 +     * <li>the first argument is negative infinity and the second
 456.576 +     * argument is greater than zero but not a finite odd integer,
 456.577 +     * </ul>
 456.578 +     * then the result is positive infinity.
 456.579 +     *
 456.580 +     * <li>If
 456.581 +     * <ul>
 456.582 +     * <li>the first argument is negative zero and the second argument
 456.583 +     * is a negative finite odd integer, or
 456.584 +     * <li>the first argument is negative infinity and the second
 456.585 +     * argument is a positive finite odd integer,
 456.586 +     * </ul>
 456.587 +     * then the result is negative infinity.
 456.588 +     *
 456.589 +     * <li>If the first argument is finite and less than zero
 456.590 +     * <ul>
 456.591 +     * <li> if the second argument is a finite even integer, the
 456.592 +     * result is equal to the result of raising the absolute value of
 456.593 +     * the first argument to the power of the second argument
 456.594 +     *
 456.595 +     * <li>if the second argument is a finite odd integer, the result
 456.596 +     * is equal to the negative of the result of raising the absolute
 456.597 +     * value of the first argument to the power of the second
 456.598 +     * argument
 456.599 +     *
 456.600 +     * <li>if the second argument is finite and not an integer, then
 456.601 +     * the result is NaN.
 456.602 +     * </ul>
 456.603 +     *
 456.604 +     * <li>If both arguments are integers, then the result is exactly equal
 456.605 +     * to the mathematical result of raising the first argument to the power
 456.606 +     * of the second argument if that result can in fact be represented
 456.607 +     * exactly as a {@code double} value.</ul>
 456.608 +     *
 456.609 +     * <p>(In the foregoing descriptions, a floating-point value is
 456.610 +     * considered to be an integer if and only if it is finite and a
 456.611 +     * fixed point of the method {@link #ceil ceil} or,
 456.612 +     * equivalently, a fixed point of the method {@link #floor
 456.613 +     * floor}. A value is a fixed point of a one-argument
 456.614 +     * method if and only if the result of applying the method to the
 456.615 +     * value is equal to the value.)
 456.616 +     *
 456.617 +     * <p>The computed result must be within 1 ulp of the exact result.
 456.618 +     * Results must be semi-monotonic.
 456.619 +     *
 456.620 +     * @param   a   the base.
 456.621 +     * @param   b   the exponent.
 456.622 +     * @return  the value {@code a}<sup>{@code b}</sup>.
 456.623 +     */
 456.624 +    @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
 456.625 +    public static double pow(double a, double b) {
 456.626 +        throw new UnsupportedOperationException();
 456.627 +    }
 456.628 +
 456.629 +    /**
 456.630 +     * Returns the closest {@code int} to the argument, with ties
 456.631 +     * rounding up.
 456.632 +     *
 456.633 +     * <p>
 456.634 +     * Special cases:
 456.635 +     * <ul><li>If the argument is NaN, the result is 0.
 456.636 +     * <li>If the argument is negative infinity or any value less than or
 456.637 +     * equal to the value of {@code Integer.MIN_VALUE}, the result is
 456.638 +     * equal to the value of {@code Integer.MIN_VALUE}.
 456.639 +     * <li>If the argument is positive infinity or any value greater than or
 456.640 +     * equal to the value of {@code Integer.MAX_VALUE}, the result is
 456.641 +     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
 456.642 +     *
 456.643 +     * @param   a   a floating-point value to be rounded to an integer.
 456.644 +     * @return  the value of the argument rounded to the nearest
 456.645 +     *          {@code int} value.
 456.646 +     * @see     java.lang.Integer#MAX_VALUE
 456.647 +     * @see     java.lang.Integer#MIN_VALUE
 456.648 +     */
 456.649 +    public static int round(float a) {
 456.650 +        return (int)roundDbl(a);
 456.651 +    }
 456.652 +
 456.653 +    /**
 456.654 +     * Returns the closest {@code long} to the argument, with ties
 456.655 +     * rounding up.
 456.656 +     *
 456.657 +     * <p>Special cases:
 456.658 +     * <ul><li>If the argument is NaN, the result is 0.
 456.659 +     * <li>If the argument is negative infinity or any value less than or
 456.660 +     * equal to the value of {@code Long.MIN_VALUE}, the result is
 456.661 +     * equal to the value of {@code Long.MIN_VALUE}.
 456.662 +     * <li>If the argument is positive infinity or any value greater than or
 456.663 +     * equal to the value of {@code Long.MAX_VALUE}, the result is
 456.664 +     * equal to the value of {@code Long.MAX_VALUE}.</ul>
 456.665 +     *
 456.666 +     * @param   a   a floating-point value to be rounded to a
 456.667 +     *          {@code long}.
 456.668 +     * @return  the value of the argument rounded to the nearest
 456.669 +     *          {@code long} value.
 456.670 +     * @see     java.lang.Long#MAX_VALUE
 456.671 +     * @see     java.lang.Long#MIN_VALUE
 456.672 +     */
 456.673 +    public static long round(double a) {
 456.674 +        return (long)roundDbl(a);
 456.675 +    }
 456.676 +    
 456.677 +    @JavaScriptBody(args="a", body="return Math.round(a);")
 456.678 +    private static native double roundDbl(double d);
 456.679 +
 456.680 +//    private static Random randomNumberGenerator;
 456.681 +//
 456.682 +//    private static synchronized Random initRNG() {
 456.683 +//        Random rnd = randomNumberGenerator;
 456.684 +//        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
 456.685 +//    }
 456.686 +
 456.687 +    /**
 456.688 +     * Returns a {@code double} value with a positive sign, greater
 456.689 +     * than or equal to {@code 0.0} and less than {@code 1.0}.
 456.690 +     * Returned values are chosen pseudorandomly with (approximately)
 456.691 +     * uniform distribution from that range.
 456.692 +     *
 456.693 +     * <p>When this method is first called, it creates a single new
 456.694 +     * pseudorandom-number generator, exactly as if by the expression
 456.695 +     *
 456.696 +     * <blockquote>{@code new java.util.Random()}</blockquote>
 456.697 +     *
 456.698 +     * This new pseudorandom-number generator is used thereafter for
 456.699 +     * all calls to this method and is used nowhere else.
 456.700 +     *
 456.701 +     * <p>This method is properly synchronized to allow correct use by
 456.702 +     * more than one thread. However, if many threads need to generate
 456.703 +     * pseudorandom numbers at a great rate, it may reduce contention
 456.704 +     * for each thread to have its own pseudorandom-number generator.
 456.705 +     *
 456.706 +     * @return  a pseudorandom {@code double} greater than or equal
 456.707 +     * to {@code 0.0} and less than {@code 1.0}.
 456.708 +     * @see Random#nextDouble()
 456.709 +     */
 456.710 +    @JavaScriptBody(args={}, body="return Math.random();")
 456.711 +    public static double random() {
 456.712 +        throw new UnsupportedOperationException();
 456.713 +    }
 456.714 +
 456.715 +    /**
 456.716 +     * Returns the absolute value of an {@code int} value.
 456.717 +     * If the argument is not negative, the argument is returned.
 456.718 +     * If the argument is negative, the negation of the argument is returned.
 456.719 +     *
 456.720 +     * <p>Note that if the argument is equal to the value of
 456.721 +     * {@link Integer#MIN_VALUE}, the most negative representable
 456.722 +     * {@code int} value, the result is that same value, which is
 456.723 +     * negative.
 456.724 +     *
 456.725 +     * @param   a   the argument whose absolute value is to be determined
 456.726 +     * @return  the absolute value of the argument.
 456.727 +     */
 456.728 +    public static int abs(int a) {
 456.729 +        return (a < 0) ? -a : a;
 456.730 +    }
 456.731 +
 456.732 +    /**
 456.733 +     * Returns the absolute value of a {@code long} value.
 456.734 +     * If the argument is not negative, the argument is returned.
 456.735 +     * If the argument is negative, the negation of the argument is returned.
 456.736 +     *
 456.737 +     * <p>Note that if the argument is equal to the value of
 456.738 +     * {@link Long#MIN_VALUE}, the most negative representable
 456.739 +     * {@code long} value, the result is that same value, which
 456.740 +     * is negative.
 456.741 +     *
 456.742 +     * @param   a   the argument whose absolute value is to be determined
 456.743 +     * @return  the absolute value of the argument.
 456.744 +     */
 456.745 +    public static long abs(long a) {
 456.746 +        return (a < 0) ? -a : a;
 456.747 +    }
 456.748 +
 456.749 +    /**
 456.750 +     * Returns the absolute value of a {@code float} value.
 456.751 +     * If the argument is not negative, the argument is returned.
 456.752 +     * If the argument is negative, the negation of the argument is returned.
 456.753 +     * Special cases:
 456.754 +     * <ul><li>If the argument is positive zero or negative zero, the
 456.755 +     * result is positive zero.
 456.756 +     * <li>If the argument is infinite, the result is positive infinity.
 456.757 +     * <li>If the argument is NaN, the result is NaN.</ul>
 456.758 +     * In other words, the result is the same as the value of the expression:
 456.759 +     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
 456.760 +     *
 456.761 +     * @param   a   the argument whose absolute value is to be determined
 456.762 +     * @return  the absolute value of the argument.
 456.763 +     */
 456.764 +    public static float abs(float a) {
 456.765 +        return (a <= 0.0F) ? 0.0F - a : a;
 456.766 +    }
 456.767 +
 456.768 +    /**
 456.769 +     * Returns the absolute value of a {@code double} value.
 456.770 +     * If the argument is not negative, the argument is returned.
 456.771 +     * If the argument is negative, the negation of the argument is returned.
 456.772 +     * Special cases:
 456.773 +     * <ul><li>If the argument is positive zero or negative zero, the result
 456.774 +     * is positive zero.
 456.775 +     * <li>If the argument is infinite, the result is positive infinity.
 456.776 +     * <li>If the argument is NaN, the result is NaN.</ul>
 456.777 +     * In other words, the result is the same as the value of the expression:
 456.778 +     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
 456.779 +     *
 456.780 +     * @param   a   the argument whose absolute value is to be determined
 456.781 +     * @return  the absolute value of the argument.
 456.782 +     */
 456.783 +    public static double abs(double a) {
 456.784 +        return (a <= 0.0D) ? 0.0D - a : a;
 456.785 +    }
 456.786 +
 456.787 +    /**
 456.788 +     * Returns the greater of two {@code int} values. That is, the
 456.789 +     * result is the argument closer to the value of
 456.790 +     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
 456.791 +     * the result is that same value.
 456.792 +     *
 456.793 +     * @param   a   an argument.
 456.794 +     * @param   b   another argument.
 456.795 +     * @return  the larger of {@code a} and {@code b}.
 456.796 +     */
 456.797 +    public static int max(int a, int b) {
 456.798 +        return (a >= b) ? a : b;
 456.799 +    }
 456.800 +
 456.801 +    /**
 456.802 +     * Returns the greater of two {@code long} values. That is, the
 456.803 +     * result is the argument closer to the value of
 456.804 +     * {@link Long#MAX_VALUE}. If the arguments have the same value,
 456.805 +     * the result is that same value.
 456.806 +     *
 456.807 +     * @param   a   an argument.
 456.808 +     * @param   b   another argument.
 456.809 +     * @return  the larger of {@code a} and {@code b}.
 456.810 +     */
 456.811 +    public static long max(long a, long b) {
 456.812 +        return (a >= b) ? a : b;
 456.813 +    }
 456.814 +
 456.815 +    /**
 456.816 +     * Returns the greater of two {@code float} values.  That is,
 456.817 +     * the result is the argument closer to positive infinity. If the
 456.818 +     * arguments have the same value, the result is that same
 456.819 +     * value. If either value is NaN, then the result is NaN.  Unlike
 456.820 +     * the numerical comparison operators, this method considers
 456.821 +     * negative zero to be strictly smaller than positive zero. If one
 456.822 +     * argument is positive zero and the other negative zero, the
 456.823 +     * result is positive zero.
 456.824 +     *
 456.825 +     * @param   a   an argument.
 456.826 +     * @param   b   another argument.
 456.827 +     * @return  the larger of {@code a} and {@code b}.
 456.828 +     */
 456.829 +    @JavaScriptBody(args={"a", "b"},
 456.830 +        body="return Math.max(a,b);"
 456.831 +    )
 456.832 +    public static float max(float a, float b) {
 456.833 +        throw new UnsupportedOperationException();
 456.834 +    }
 456.835 +
 456.836 +    /**
 456.837 +     * Returns the greater of two {@code double} values.  That
 456.838 +     * is, the result is the argument closer to positive infinity. If
 456.839 +     * the arguments have the same value, the result is that same
 456.840 +     * value. If either value is NaN, then the result is NaN.  Unlike
 456.841 +     * the numerical comparison operators, this method considers
 456.842 +     * negative zero to be strictly smaller than positive zero. If one
 456.843 +     * argument is positive zero and the other negative zero, the
 456.844 +     * result is positive zero.
 456.845 +     *
 456.846 +     * @param   a   an argument.
 456.847 +     * @param   b   another argument.
 456.848 +     * @return  the larger of {@code a} and {@code b}.
 456.849 +     */
 456.850 +    @JavaScriptBody(args={"a", "b"},
 456.851 +        body="return Math.max(a,b);"
 456.852 +    )
 456.853 +    public static double max(double a, double b) {
 456.854 +        throw new UnsupportedOperationException();
 456.855 +    }
 456.856 +
 456.857 +    /**
 456.858 +     * Returns the smaller of two {@code int} values. That is,
 456.859 +     * the result the argument closer to the value of
 456.860 +     * {@link Integer#MIN_VALUE}.  If the arguments have the same
 456.861 +     * value, the result is that same value.
 456.862 +     *
 456.863 +     * @param   a   an argument.
 456.864 +     * @param   b   another argument.
 456.865 +     * @return  the smaller of {@code a} and {@code b}.
 456.866 +     */
 456.867 +    public static int min(int a, int b) {
 456.868 +        return (a <= b) ? a : b;
 456.869 +    }
 456.870 +
 456.871 +    /**
 456.872 +     * Returns the smaller of two {@code long} values. That is,
 456.873 +     * the result is the argument closer to the value of
 456.874 +     * {@link Long#MIN_VALUE}. If the arguments have the same
 456.875 +     * value, the result is that same value.
 456.876 +     *
 456.877 +     * @param   a   an argument.
 456.878 +     * @param   b   another argument.
 456.879 +     * @return  the smaller of {@code a} and {@code b}.
 456.880 +     */
 456.881 +    public static long min(long a, long b) {
 456.882 +        return (a <= b) ? a : b;
 456.883 +    }
 456.884 +
 456.885 +    /**
 456.886 +     * Returns the smaller of two {@code float} values.  That is,
 456.887 +     * the result is the value closer to negative infinity. If the
 456.888 +     * arguments have the same value, the result is that same
 456.889 +     * value. If either value is NaN, then the result is NaN.  Unlike
 456.890 +     * the numerical comparison operators, this method considers
 456.891 +     * negative zero to be strictly smaller than positive zero.  If
 456.892 +     * one argument is positive zero and the other is negative zero,
 456.893 +     * the result is negative zero.
 456.894 +     *
 456.895 +     * @param   a   an argument.
 456.896 +     * @param   b   another argument.
 456.897 +     * @return  the smaller of {@code a} and {@code b}.
 456.898 +     */
 456.899 +    @JavaScriptBody(args={"a", "b"},
 456.900 +        body="return Math.min(a,b);"
 456.901 +    )
 456.902 +    public static float min(float a, float b) {
 456.903 +        throw new UnsupportedOperationException();
 456.904 +    }
 456.905 +
 456.906 +    /**
 456.907 +     * Returns the smaller of two {@code double} values.  That
 456.908 +     * is, the result is the value closer to negative infinity. If the
 456.909 +     * arguments have the same value, the result is that same
 456.910 +     * value. If either value is NaN, then the result is NaN.  Unlike
 456.911 +     * the numerical comparison operators, this method considers
 456.912 +     * negative zero to be strictly smaller than positive zero. If one
 456.913 +     * argument is positive zero and the other is negative zero, the
 456.914 +     * result is negative zero.
 456.915 +     *
 456.916 +     * @param   a   an argument.
 456.917 +     * @param   b   another argument.
 456.918 +     * @return  the smaller of {@code a} and {@code b}.
 456.919 +     */
 456.920 +    @JavaScriptBody(args={"a", "b"},
 456.921 +        body="return Math.min(a,b);"
 456.922 +    )
 456.923 +    public static double min(double a, double b) {
 456.924 +        throw new UnsupportedOperationException();
 456.925 +    }
 456.926 +
 456.927 +    /**
 456.928 +     * Returns the size of an ulp of the argument.  An ulp of a
 456.929 +     * {@code double} value is the positive distance between this
 456.930 +     * floating-point value and the {@code double} value next
 456.931 +     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 456.932 +     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 456.933 +     *
 456.934 +     * <p>Special Cases:
 456.935 +     * <ul>
 456.936 +     * <li> If the argument is NaN, then the result is NaN.
 456.937 +     * <li> If the argument is positive or negative infinity, then the
 456.938 +     * result is positive infinity.
 456.939 +     * <li> If the argument is positive or negative zero, then the result is
 456.940 +     * {@code Double.MIN_VALUE}.
 456.941 +     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
 456.942 +     * the result is equal to 2<sup>971</sup>.
 456.943 +     * </ul>
 456.944 +     *
 456.945 +     * @param d the floating-point value whose ulp is to be returned
 456.946 +     * @return the size of an ulp of the argument
 456.947 +     * @author Joseph D. Darcy
 456.948 +     * @since 1.5
 456.949 +     */
 456.950 +//    public static double ulp(double d) {
 456.951 +//        return sun.misc.FpUtils.ulp(d);
 456.952 +//    }
 456.953 +
 456.954 +    /**
 456.955 +     * Returns the size of an ulp of the argument.  An ulp of a
 456.956 +     * {@code float} value is the positive distance between this
 456.957 +     * floating-point value and the {@code float} value next
 456.958 +     * larger in magnitude.  Note that for non-NaN <i>x</i>,
 456.959 +     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
 456.960 +     *
 456.961 +     * <p>Special Cases:
 456.962 +     * <ul>
 456.963 +     * <li> If the argument is NaN, then the result is NaN.
 456.964 +     * <li> If the argument is positive or negative infinity, then the
 456.965 +     * result is positive infinity.
 456.966 +     * <li> If the argument is positive or negative zero, then the result is
 456.967 +     * {@code Float.MIN_VALUE}.
 456.968 +     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
 456.969 +     * the result is equal to 2<sup>104</sup>.
 456.970 +     * </ul>
 456.971 +     *
 456.972 +     * @param f the floating-point value whose ulp is to be returned
 456.973 +     * @return the size of an ulp of the argument
 456.974 +     * @author Joseph D. Darcy
 456.975 +     * @since 1.5
 456.976 +     */
 456.977 +//    public static float ulp(float f) {
 456.978 +//        return sun.misc.FpUtils.ulp(f);
 456.979 +//    }
 456.980 +
 456.981 +    /**
 456.982 +     * Returns the signum function of the argument; zero if the argument
 456.983 +     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
 456.984 +     * argument is less than zero.
 456.985 +     *
 456.986 +     * <p>Special Cases:
 456.987 +     * <ul>
 456.988 +     * <li> If the argument is NaN, then the result is NaN.
 456.989 +     * <li> If the argument is positive zero or negative zero, then the
 456.990 +     *      result is the same as the argument.
 456.991 +     * </ul>
 456.992 +     *
 456.993 +     * @param d the floating-point value whose signum is to be returned
 456.994 +     * @return the signum function of the argument
 456.995 +     * @author Joseph D. Darcy
 456.996 +     * @since 1.5
 456.997 +     */
 456.998 +    public static double signum(double d) {
 456.999 +        if (d < 0.0) { return -1.0; }
456.1000 +        if (d > 0.0) { return 1.0; }
456.1001 +        return d;
456.1002 +    }
456.1003 +
456.1004 +    /**
456.1005 +     * Returns the signum function of the argument; zero if the argument
456.1006 +     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
456.1007 +     * argument is less than zero.
456.1008 +     *
456.1009 +     * <p>Special Cases:
456.1010 +     * <ul>
456.1011 +     * <li> If the argument is NaN, then the result is NaN.
456.1012 +     * <li> If the argument is positive zero or negative zero, then the
456.1013 +     *      result is the same as the argument.
456.1014 +     * </ul>
456.1015 +     *
456.1016 +     * @param f the floating-point value whose signum is to be returned
456.1017 +     * @return the signum function of the argument
456.1018 +     * @author Joseph D. Darcy
456.1019 +     * @since 1.5
456.1020 +     */
456.1021 +    public static float signum(float f) {
456.1022 +        if (f < 0.0f) { return -1.0f; }
456.1023 +        if (f > 0.0f) { return 1.0f; }
456.1024 +        return f;
456.1025 +    }
456.1026 +
456.1027 +    /**
456.1028 +     * Returns the first floating-point argument with the sign of the
456.1029 +     * second floating-point argument.  Note that unlike the {@link
456.1030 +     * StrictMath#copySign(double, double) StrictMath.copySign}
456.1031 +     * method, this method does not require NaN {@code sign}
456.1032 +     * arguments to be treated as positive values; implementations are
456.1033 +     * permitted to treat some NaN arguments as positive and other NaN
456.1034 +     * arguments as negative to allow greater performance.
456.1035 +     *
456.1036 +     * @param magnitude  the parameter providing the magnitude of the result
456.1037 +     * @param sign   the parameter providing the sign of the result
456.1038 +     * @return a value with the magnitude of {@code magnitude}
456.1039 +     * and the sign of {@code sign}.
456.1040 +     * @since 1.6
456.1041 +     */
456.1042 +//    public static double copySign(double magnitude, double sign) {
456.1043 +//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
456.1044 +//    }
456.1045 +
456.1046 +    /**
456.1047 +     * Returns the first floating-point argument with the sign of the
456.1048 +     * second floating-point argument.  Note that unlike the {@link
456.1049 +     * StrictMath#copySign(float, float) StrictMath.copySign}
456.1050 +     * method, this method does not require NaN {@code sign}
456.1051 +     * arguments to be treated as positive values; implementations are
456.1052 +     * permitted to treat some NaN arguments as positive and other NaN
456.1053 +     * arguments as negative to allow greater performance.
456.1054 +     *
456.1055 +     * @param magnitude  the parameter providing the magnitude of the result
456.1056 +     * @param sign   the parameter providing the sign of the result
456.1057 +     * @return a value with the magnitude of {@code magnitude}
456.1058 +     * and the sign of {@code sign}.
456.1059 +     * @since 1.6
456.1060 +     */
456.1061 +//    public static float copySign(float magnitude, float sign) {
456.1062 +//        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
456.1063 +//    }
456.1064 +
456.1065 +    /**
456.1066 +     * Returns the unbiased exponent used in the representation of a
456.1067 +     * {@code float}.  Special cases:
456.1068 +     *
456.1069 +     * <ul>
456.1070 +     * <li>If the argument is NaN or infinite, then the result is
456.1071 +     * {@link Float#MAX_EXPONENT} + 1.
456.1072 +     * <li>If the argument is zero or subnormal, then the result is
456.1073 +     * {@link Float#MIN_EXPONENT} -1.
456.1074 +     * </ul>
456.1075 +     * @param f a {@code float} value
456.1076 +     * @return the unbiased exponent of the argument
456.1077 +     * @since 1.6
456.1078 +     */
456.1079 +//    public static int getExponent(float f) {
456.1080 +//        return sun.misc.FpUtils.getExponent(f);
456.1081 +//    }
456.1082 +
456.1083 +    /**
456.1084 +     * Returns the unbiased exponent used in the representation of a
456.1085 +     * {@code double}.  Special cases:
456.1086 +     *
456.1087 +     * <ul>
456.1088 +     * <li>If the argument is NaN or infinite, then the result is
456.1089 +     * {@link Double#MAX_EXPONENT} + 1.
456.1090 +     * <li>If the argument is zero or subnormal, then the result is
456.1091 +     * {@link Double#MIN_EXPONENT} -1.
456.1092 +     * </ul>
456.1093 +     * @param d a {@code double} value
456.1094 +     * @return the unbiased exponent of the argument
456.1095 +     * @since 1.6
456.1096 +     */
456.1097 +//    public static int getExponent(double d) {
456.1098 +//        return sun.misc.FpUtils.getExponent(d);
456.1099 +//    }
456.1100 +
456.1101 +    /**
456.1102 +     * Returns the floating-point number adjacent to the first
456.1103 +     * argument in the direction of the second argument.  If both
456.1104 +     * arguments compare as equal the second argument is returned.
456.1105 +     *
456.1106 +     * <p>
456.1107 +     * Special cases:
456.1108 +     * <ul>
456.1109 +     * <li> If either argument is a NaN, then NaN is returned.
456.1110 +     *
456.1111 +     * <li> If both arguments are signed zeros, {@code direction}
456.1112 +     * is returned unchanged (as implied by the requirement of
456.1113 +     * returning the second argument if the arguments compare as
456.1114 +     * equal).
456.1115 +     *
456.1116 +     * <li> If {@code start} is
456.1117 +     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
456.1118 +     * has a value such that the result should have a smaller
456.1119 +     * magnitude, then a zero with the same sign as {@code start}
456.1120 +     * is returned.
456.1121 +     *
456.1122 +     * <li> If {@code start} is infinite and
456.1123 +     * {@code direction} has a value such that the result should
456.1124 +     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
456.1125 +     * same sign as {@code start} is returned.
456.1126 +     *
456.1127 +     * <li> If {@code start} is equal to &plusmn;
456.1128 +     * {@link Double#MAX_VALUE} and {@code direction} has a
456.1129 +     * value such that the result should have a larger magnitude, an
456.1130 +     * infinity with same sign as {@code start} is returned.
456.1131 +     * </ul>
456.1132 +     *
456.1133 +     * @param start  starting floating-point value
456.1134 +     * @param direction value indicating which of
456.1135 +     * {@code start}'s neighbors or {@code start} should
456.1136 +     * be returned
456.1137 +     * @return The floating-point number adjacent to {@code start} in the
456.1138 +     * direction of {@code direction}.
456.1139 +     * @since 1.6
456.1140 +     */
456.1141 +//    public static double nextAfter(double start, double direction) {
456.1142 +//        return sun.misc.FpUtils.nextAfter(start, direction);
456.1143 +//    }
456.1144 +
456.1145 +    /**
456.1146 +     * Returns the floating-point number adjacent to the first
456.1147 +     * argument in the direction of the second argument.  If both
456.1148 +     * arguments compare as equal a value equivalent to the second argument
456.1149 +     * is returned.
456.1150 +     *
456.1151 +     * <p>
456.1152 +     * Special cases:
456.1153 +     * <ul>
456.1154 +     * <li> If either argument is a NaN, then NaN is returned.
456.1155 +     *
456.1156 +     * <li> If both arguments are signed zeros, a value equivalent
456.1157 +     * to {@code direction} is returned.
456.1158 +     *
456.1159 +     * <li> If {@code start} is
456.1160 +     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
456.1161 +     * has a value such that the result should have a smaller
456.1162 +     * magnitude, then a zero with the same sign as {@code start}
456.1163 +     * is returned.
456.1164 +     *
456.1165 +     * <li> If {@code start} is infinite and
456.1166 +     * {@code direction} has a value such that the result should
456.1167 +     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
456.1168 +     * same sign as {@code start} is returned.
456.1169 +     *
456.1170 +     * <li> If {@code start} is equal to &plusmn;
456.1171 +     * {@link Float#MAX_VALUE} and {@code direction} has a
456.1172 +     * value such that the result should have a larger magnitude, an
456.1173 +     * infinity with same sign as {@code start} is returned.
456.1174 +     * </ul>
456.1175 +     *
456.1176 +     * @param start  starting floating-point value
456.1177 +     * @param direction value indicating which of
456.1178 +     * {@code start}'s neighbors or {@code start} should
456.1179 +     * be returned
456.1180 +     * @return The floating-point number adjacent to {@code start} in the
456.1181 +     * direction of {@code direction}.
456.1182 +     * @since 1.6
456.1183 +     */
456.1184 +//    public static float nextAfter(float start, double direction) {
456.1185 +//        return sun.misc.FpUtils.nextAfter(start, direction);
456.1186 +//    }
456.1187 +
456.1188 +    /**
456.1189 +     * Returns the floating-point value adjacent to {@code d} in
456.1190 +     * the direction of positive infinity.  This method is
456.1191 +     * semantically equivalent to {@code nextAfter(d,
456.1192 +     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
456.1193 +     * implementation may run faster than its equivalent
456.1194 +     * {@code nextAfter} call.
456.1195 +     *
456.1196 +     * <p>Special Cases:
456.1197 +     * <ul>
456.1198 +     * <li> If the argument is NaN, the result is NaN.
456.1199 +     *
456.1200 +     * <li> If the argument is positive infinity, the result is
456.1201 +     * positive infinity.
456.1202 +     *
456.1203 +     * <li> If the argument is zero, the result is
456.1204 +     * {@link Double#MIN_VALUE}
456.1205 +     *
456.1206 +     * </ul>
456.1207 +     *
456.1208 +     * @param d starting floating-point value
456.1209 +     * @return The adjacent floating-point value closer to positive
456.1210 +     * infinity.
456.1211 +     * @since 1.6
456.1212 +     */
456.1213 +//    public static double nextUp(double d) {
456.1214 +//        return sun.misc.FpUtils.nextUp(d);
456.1215 +//    }
456.1216 +
456.1217 +    /**
456.1218 +     * Returns the floating-point value adjacent to {@code f} in
456.1219 +     * the direction of positive infinity.  This method is
456.1220 +     * semantically equivalent to {@code nextAfter(f,
456.1221 +     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
456.1222 +     * implementation may run faster than its equivalent
456.1223 +     * {@code nextAfter} call.
456.1224 +     *
456.1225 +     * <p>Special Cases:
456.1226 +     * <ul>
456.1227 +     * <li> If the argument is NaN, the result is NaN.
456.1228 +     *
456.1229 +     * <li> If the argument is positive infinity, the result is
456.1230 +     * positive infinity.
456.1231 +     *
456.1232 +     * <li> If the argument is zero, the result is
456.1233 +     * {@link Float#MIN_VALUE}
456.1234 +     *
456.1235 +     * </ul>
456.1236 +     *
456.1237 +     * @param f starting floating-point value
456.1238 +     * @return The adjacent floating-point value closer to positive
456.1239 +     * infinity.
456.1240 +     * @since 1.6
456.1241 +     */
456.1242 +//    public static float nextUp(float f) {
456.1243 +//        return sun.misc.FpUtils.nextUp(f);
456.1244 +//    }
456.1245 +
456.1246 +
456.1247 +    /**
456.1248 +     * Return {@code d} &times;
456.1249 +     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
456.1250 +     * by a single correctly rounded floating-point multiply to a
456.1251 +     * member of the double value set.  See the Java
456.1252 +     * Language Specification for a discussion of floating-point
456.1253 +     * value sets.  If the exponent of the result is between {@link
456.1254 +     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
456.1255 +     * answer is calculated exactly.  If the exponent of the result
456.1256 +     * would be larger than {@code Double.MAX_EXPONENT}, an
456.1257 +     * infinity is returned.  Note that if the result is subnormal,
456.1258 +     * precision may be lost; that is, when {@code scalb(x, n)}
456.1259 +     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
456.1260 +     * <i>x</i>.  When the result is non-NaN, the result has the same
456.1261 +     * sign as {@code d}.
456.1262 +     *
456.1263 +     * <p>Special cases:
456.1264 +     * <ul>
456.1265 +     * <li> If the first argument is NaN, NaN is returned.
456.1266 +     * <li> If the first argument is infinite, then an infinity of the
456.1267 +     * same sign is returned.
456.1268 +     * <li> If the first argument is zero, then a zero of the same
456.1269 +     * sign is returned.
456.1270 +     * </ul>
456.1271 +     *
456.1272 +     * @param d number to be scaled by a power of two.
456.1273 +     * @param scaleFactor power of 2 used to scale {@code d}
456.1274 +     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
456.1275 +     * @since 1.6
456.1276 +     */
456.1277 +//    public static double scalb(double d, int scaleFactor) {
456.1278 +//        return sun.misc.FpUtils.scalb(d, scaleFactor);
456.1279 +//    }
456.1280 +
456.1281 +    /**
456.1282 +     * Return {@code f} &times;
456.1283 +     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
456.1284 +     * by a single correctly rounded floating-point multiply to a
456.1285 +     * member of the float value set.  See the Java
456.1286 +     * Language Specification for a discussion of floating-point
456.1287 +     * value sets.  If the exponent of the result is between {@link
456.1288 +     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
456.1289 +     * answer is calculated exactly.  If the exponent of the result
456.1290 +     * would be larger than {@code Float.MAX_EXPONENT}, an
456.1291 +     * infinity is returned.  Note that if the result is subnormal,
456.1292 +     * precision may be lost; that is, when {@code scalb(x, n)}
456.1293 +     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
456.1294 +     * <i>x</i>.  When the result is non-NaN, the result has the same
456.1295 +     * sign as {@code f}.
456.1296 +     *
456.1297 +     * <p>Special cases:
456.1298 +     * <ul>
456.1299 +     * <li> If the first argument is NaN, NaN is returned.
456.1300 +     * <li> If the first argument is infinite, then an infinity of the
456.1301 +     * same sign is returned.
456.1302 +     * <li> If the first argument is zero, then a zero of the same
456.1303 +     * sign is returned.
456.1304 +     * </ul>
456.1305 +     *
456.1306 +     * @param f number to be scaled by a power of two.
456.1307 +     * @param scaleFactor power of 2 used to scale {@code f}
456.1308 +     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
456.1309 +     * @since 1.6
456.1310 +     */
456.1311 +//    public static float scalb(float f, int scaleFactor) {
456.1312 +//        return sun.misc.FpUtils.scalb(f, scaleFactor);
456.1313 +//    }
456.1314 +}
   457.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   457.2 +++ b/rt/emul/mini/src/main/java/java/lang/NegativeArraySizeException.java	Wed Feb 27 11:24:58 2013 +0100
   457.3 @@ -0,0 +1,55 @@
   457.4 +/*
   457.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   457.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   457.7 + *
   457.8 + * This code is free software; you can redistribute it and/or modify it
   457.9 + * under the terms of the GNU General Public License version 2 only, as
  457.10 + * published by the Free Software Foundation.  Oracle designates this
  457.11 + * particular file as subject to the "Classpath" exception as provided
  457.12 + * by Oracle in the LICENSE file that accompanied this code.
  457.13 + *
  457.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  457.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  457.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  457.17 + * version 2 for more details (a copy is included in the LICENSE file that
  457.18 + * accompanied this code).
  457.19 + *
  457.20 + * You should have received a copy of the GNU General Public License version
  457.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  457.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  457.23 + *
  457.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  457.25 + * or visit www.oracle.com if you need additional information or have any
  457.26 + * questions.
  457.27 + */
  457.28 +
  457.29 +package java.lang;
  457.30 +
  457.31 +/**
  457.32 + * Thrown if an application tries to create an array with negative size.
  457.33 + *
  457.34 + * @author  unascribed
  457.35 + * @since   JDK1.0
  457.36 + */
  457.37 +public
  457.38 +class NegativeArraySizeException extends RuntimeException {
  457.39 +    private static final long serialVersionUID = -8960118058596991861L;
  457.40 +
  457.41 +    /**
  457.42 +     * Constructs a <code>NegativeArraySizeException</code> with no
  457.43 +     * detail message.
  457.44 +     */
  457.45 +    public NegativeArraySizeException() {
  457.46 +        super();
  457.47 +    }
  457.48 +
  457.49 +    /**
  457.50 +     * Constructs a <code>NegativeArraySizeException</code> with the
  457.51 +     * specified detail message.
  457.52 +     *
  457.53 +     * @param   s   the detail message.
  457.54 +     */
  457.55 +    public NegativeArraySizeException(String s) {
  457.56 +        super(s);
  457.57 +    }
  457.58 +}
   458.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   458.2 +++ b/rt/emul/mini/src/main/java/java/lang/NoSuchMethodException.java	Wed Feb 27 11:24:58 2013 +0100
   458.3 @@ -0,0 +1,53 @@
   458.4 +/*
   458.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   458.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   458.7 + *
   458.8 + * This code is free software; you can redistribute it and/or modify it
   458.9 + * under the terms of the GNU General Public License version 2 only, as
  458.10 + * published by the Free Software Foundation.  Oracle designates this
  458.11 + * particular file as subject to the "Classpath" exception as provided
  458.12 + * by Oracle in the LICENSE file that accompanied this code.
  458.13 + *
  458.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  458.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  458.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  458.17 + * version 2 for more details (a copy is included in the LICENSE file that
  458.18 + * accompanied this code).
  458.19 + *
  458.20 + * You should have received a copy of the GNU General Public License version
  458.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  458.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  458.23 + *
  458.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  458.25 + * or visit www.oracle.com if you need additional information or have any
  458.26 + * questions.
  458.27 + */
  458.28 +
  458.29 +package java.lang;
  458.30 +
  458.31 +/**
  458.32 + * Thrown when a particular method cannot be found.
  458.33 + *
  458.34 + * @author     unascribed
  458.35 + * @since      JDK1.0
  458.36 + */
  458.37 +public
  458.38 +class NoSuchMethodException extends ReflectiveOperationException {
  458.39 +    private static final long serialVersionUID = 5034388446362600923L;
  458.40 +
  458.41 +    /**
  458.42 +     * Constructs a <code>NoSuchMethodException</code> without a detail message.
  458.43 +     */
  458.44 +    public NoSuchMethodException() {
  458.45 +        super();
  458.46 +    }
  458.47 +
  458.48 +    /**
  458.49 +     * Constructs a <code>NoSuchMethodException</code> with a detail message.
  458.50 +     *
  458.51 +     * @param      s   the detail message.
  458.52 +     */
  458.53 +    public NoSuchMethodException(String s) {
  458.54 +        super(s);
  458.55 +    }
  458.56 +}
   459.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   459.2 +++ b/rt/emul/mini/src/main/java/java/lang/NullPointerException.java	Wed Feb 27 11:24:58 2013 +0100
   459.3 @@ -0,0 +1,72 @@
   459.4 +/*
   459.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   459.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   459.7 + *
   459.8 + * This code is free software; you can redistribute it and/or modify it
   459.9 + * under the terms of the GNU General Public License version 2 only, as
  459.10 + * published by the Free Software Foundation.  Oracle designates this
  459.11 + * particular file as subject to the "Classpath" exception as provided
  459.12 + * by Oracle in the LICENSE file that accompanied this code.
  459.13 + *
  459.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  459.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  459.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  459.17 + * version 2 for more details (a copy is included in the LICENSE file that
  459.18 + * accompanied this code).
  459.19 + *
  459.20 + * You should have received a copy of the GNU General Public License version
  459.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  459.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  459.23 + *
  459.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  459.25 + * or visit www.oracle.com if you need additional information or have any
  459.26 + * questions.
  459.27 + */
  459.28 +
  459.29 +package java.lang;
  459.30 +
  459.31 +/**
  459.32 + * Thrown when an application attempts to use {@code null} in a
  459.33 + * case where an object is required. These include:
  459.34 + * <ul>
  459.35 + * <li>Calling the instance method of a {@code null} object.
  459.36 + * <li>Accessing or modifying the field of a {@code null} object.
  459.37 + * <li>Taking the length of {@code null} as if it were an array.
  459.38 + * <li>Accessing or modifying the slots of {@code null} as if it
  459.39 + *     were an array.
  459.40 + * <li>Throwing {@code null} as if it were a {@code Throwable}
  459.41 + *     value.
  459.42 + * </ul>
  459.43 + * <p>
  459.44 + * Applications should throw instances of this class to indicate
  459.45 + * other illegal uses of the {@code null} object.
  459.46 + *
  459.47 + * {@code NullPointerException} objects may be constructed by the
  459.48 + * virtual machine as if {@linkplain Throwable#Throwable(String,
  459.49 + * Throwable, boolean, boolean) suppression were disabled and/or the
  459.50 + * stack trace was not writable}.
  459.51 + *
  459.52 + * @author  unascribed
  459.53 + * @since   JDK1.0
  459.54 + */
  459.55 +public
  459.56 +class NullPointerException extends RuntimeException {
  459.57 +    private static final long serialVersionUID = 5162710183389028792L;
  459.58 +
  459.59 +    /**
  459.60 +     * Constructs a {@code NullPointerException} with no detail message.
  459.61 +     */
  459.62 +    public NullPointerException() {
  459.63 +        super();
  459.64 +    }
  459.65 +
  459.66 +    /**
  459.67 +     * Constructs a {@code NullPointerException} with the specified
  459.68 +     * detail message.
  459.69 +     *
  459.70 +     * @param   s   the detail message.
  459.71 +     */
  459.72 +    public NullPointerException(String s) {
  459.73 +        super(s);
  459.74 +    }
  459.75 +}
   460.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   460.2 +++ b/rt/emul/mini/src/main/java/java/lang/Number.java	Wed Feb 27 11:24:58 2013 +0100
   460.3 @@ -0,0 +1,118 @@
   460.4 +/*
   460.5 + * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
   460.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   460.7 + *
   460.8 + * This code is free software; you can redistribute it and/or modify it
   460.9 + * under the terms of the GNU General Public License version 2 only, as
  460.10 + * published by the Free Software Foundation.  Oracle designates this
  460.11 + * particular file as subject to the "Classpath" exception as provided
  460.12 + * by Oracle in the LICENSE file that accompanied this code.
  460.13 + *
  460.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  460.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  460.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  460.17 + * version 2 for more details (a copy is included in the LICENSE file that
  460.18 + * accompanied this code).
  460.19 + *
  460.20 + * You should have received a copy of the GNU General Public License version
  460.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  460.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  460.23 + *
  460.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  460.25 + * or visit www.oracle.com if you need additional information or have any
  460.26 + * questions.
  460.27 + */
  460.28 +
  460.29 +package java.lang;
  460.30 +
  460.31 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  460.32 +
  460.33 +/**
  460.34 + * The abstract class <code>Number</code> is the superclass of classes
  460.35 + * <code>BigDecimal</code>, <code>BigInteger</code>,
  460.36 + * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
  460.37 + * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
  460.38 + * <p>
  460.39 + * Subclasses of <code>Number</code> must provide methods to convert
  460.40 + * the represented numeric value to <code>byte</code>, <code>double</code>,
  460.41 + * <code>float</code>, <code>int</code>, <code>long</code>, and
  460.42 + * <code>short</code>.
  460.43 + *
  460.44 + * @author      Lee Boynton
  460.45 + * @author      Arthur van Hoff
  460.46 + * @see     java.lang.Byte
  460.47 + * @see     java.lang.Double
  460.48 + * @see     java.lang.Float
  460.49 + * @see     java.lang.Integer
  460.50 + * @see     java.lang.Long
  460.51 + * @see     java.lang.Short
  460.52 + * @since   JDK1.0
  460.53 + */
  460.54 +@ExtraJavaScript(
  460.55 +    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js",
  460.56 +    processByteCode=true
  460.57 +)
  460.58 +public abstract class Number implements java.io.Serializable {
  460.59 +    /**
  460.60 +     * Returns the value of the specified number as an <code>int</code>.
  460.61 +     * This may involve rounding or truncation.
  460.62 +     *
  460.63 +     * @return  the numeric value represented by this object after conversion
  460.64 +     *          to type <code>int</code>.
  460.65 +     */
  460.66 +    public abstract int intValue();
  460.67 +
  460.68 +    /**
  460.69 +     * Returns the value of the specified number as a <code>long</code>.
  460.70 +     * This may involve rounding or truncation.
  460.71 +     *
  460.72 +     * @return  the numeric value represented by this object after conversion
  460.73 +     *          to type <code>long</code>.
  460.74 +     */
  460.75 +    public abstract long longValue();
  460.76 +
  460.77 +    /**
  460.78 +     * Returns the value of the specified number as a <code>float</code>.
  460.79 +     * This may involve rounding.
  460.80 +     *
  460.81 +     * @return  the numeric value represented by this object after conversion
  460.82 +     *          to type <code>float</code>.
  460.83 +     */
  460.84 +    public abstract float floatValue();
  460.85 +
  460.86 +    /**
  460.87 +     * Returns the value of the specified number as a <code>double</code>.
  460.88 +     * This may involve rounding.
  460.89 +     *
  460.90 +     * @return  the numeric value represented by this object after conversion
  460.91 +     *          to type <code>double</code>.
  460.92 +     */
  460.93 +    public abstract double doubleValue();
  460.94 +
  460.95 +    /**
  460.96 +     * Returns the value of the specified number as a <code>byte</code>.
  460.97 +     * This may involve rounding or truncation.
  460.98 +     *
  460.99 +     * @return  the numeric value represented by this object after conversion
 460.100 +     *          to type <code>byte</code>.
 460.101 +     * @since   JDK1.1
 460.102 +     */
 460.103 +    public byte byteValue() {
 460.104 +        return (byte)intValue();
 460.105 +    }
 460.106 +
 460.107 +    /**
 460.108 +     * Returns the value of the specified number as a <code>short</code>.
 460.109 +     * This may involve rounding or truncation.
 460.110 +     *
 460.111 +     * @return  the numeric value represented by this object after conversion
 460.112 +     *          to type <code>short</code>.
 460.113 +     * @since   JDK1.1
 460.114 +     */
 460.115 +    public short shortValue() {
 460.116 +        return (short)intValue();
 460.117 +    }
 460.118 +
 460.119 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 460.120 +    private static final long serialVersionUID = -8742448824652078965L;
 460.121 +}
   461.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   461.2 +++ b/rt/emul/mini/src/main/java/java/lang/NumberFormatException.java	Wed Feb 27 11:24:58 2013 +0100
   461.3 @@ -0,0 +1,67 @@
   461.4 +/*
   461.5 + * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
   461.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   461.7 + *
   461.8 + * This code is free software; you can redistribute it and/or modify it
   461.9 + * under the terms of the GNU General Public License version 2 only, as
  461.10 + * published by the Free Software Foundation.  Oracle designates this
  461.11 + * particular file as subject to the "Classpath" exception as provided
  461.12 + * by Oracle in the LICENSE file that accompanied this code.
  461.13 + *
  461.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  461.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  461.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  461.17 + * version 2 for more details (a copy is included in the LICENSE file that
  461.18 + * accompanied this code).
  461.19 + *
  461.20 + * You should have received a copy of the GNU General Public License version
  461.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  461.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  461.23 + *
  461.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  461.25 + * or visit www.oracle.com if you need additional information or have any
  461.26 + * questions.
  461.27 + */
  461.28 +
  461.29 +package java.lang;
  461.30 +
  461.31 +/**
  461.32 + * Thrown to indicate that the application has attempted to convert
  461.33 + * a string to one of the numeric types, but that the string does not
  461.34 + * have the appropriate format.
  461.35 + *
  461.36 + * @author  unascribed
  461.37 + * @see     java.lang.Integer#toString()
  461.38 + * @since   JDK1.0
  461.39 + */
  461.40 +public
  461.41 +class NumberFormatException extends IllegalArgumentException {
  461.42 +    static final long serialVersionUID = -2848938806368998894L;
  461.43 +
  461.44 +    /**
  461.45 +     * Constructs a <code>NumberFormatException</code> with no detail message.
  461.46 +     */
  461.47 +    public NumberFormatException () {
  461.48 +        super();
  461.49 +    }
  461.50 +
  461.51 +    /**
  461.52 +     * Constructs a <code>NumberFormatException</code> with the
  461.53 +     * specified detail message.
  461.54 +     *
  461.55 +     * @param   s   the detail message.
  461.56 +     */
  461.57 +    public NumberFormatException (String s) {
  461.58 +        super (s);
  461.59 +    }
  461.60 +
  461.61 +    /**
  461.62 +     * Factory method for making a <code>NumberFormatException</code>
  461.63 +     * given the specified input which caused the error.
  461.64 +     *
  461.65 +     * @param   s   the input causing the error
  461.66 +     */
  461.67 +    static NumberFormatException forInputString(String s) {
  461.68 +        return new NumberFormatException("For input string: \"" + s + "\"");
  461.69 +    }
  461.70 +}
   462.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   462.2 +++ b/rt/emul/mini/src/main/java/java/lang/Object.java	Wed Feb 27 11:24:58 2013 +0100
   462.3 @@ -0,0 +1,595 @@
   462.4 +/*
   462.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   462.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   462.7 + *
   462.8 + * This code is free software; you can redistribute it and/or modify it
   462.9 + * under the terms of the GNU General Public License version 2 only, as
  462.10 + * published by the Free Software Foundation.  Oracle designates this
  462.11 + * particular file as subject to the "Classpath" exception as provided
  462.12 + * by Oracle in the LICENSE file that accompanied this code.
  462.13 + *
  462.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  462.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  462.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  462.17 + * version 2 for more details (a copy is included in the LICENSE file that
  462.18 + * accompanied this code).
  462.19 + *
  462.20 + * You should have received a copy of the GNU General Public License version
  462.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  462.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  462.23 + *
  462.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  462.25 + * or visit www.oracle.com if you need additional information or have any
  462.26 + * questions.
  462.27 + */
  462.28 +
  462.29 +package java.lang;
  462.30 +
  462.31 +import java.lang.reflect.Array;
  462.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  462.33 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  462.34 +
  462.35 +/**
  462.36 + * Class {@code Object} is the root of the class hierarchy.
  462.37 + * Every class has {@code Object} as a superclass. All objects,
  462.38 + * including arrays, implement the methods of this class.
  462.39 + *
  462.40 + * @author  unascribed
  462.41 + * @see     java.lang.Class
  462.42 + * @since   JDK1.0
  462.43 + */
  462.44 +@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
  462.45 +public class Object {
  462.46 +
  462.47 +    private static void registerNatives() {
  462.48 +        try {
  462.49 +            Array.get(null, 0);
  462.50 +        } catch (Throwable ex) {
  462.51 +            // ignore
  462.52 +        }
  462.53 +    }
  462.54 +    static {
  462.55 +        registerNatives();
  462.56 +    }
  462.57 +
  462.58 +    /**
  462.59 +     * Returns the runtime class of this {@code Object}. The returned
  462.60 +     * {@code Class} object is the object that is locked by {@code
  462.61 +     * static synchronized} methods of the represented class.
  462.62 +     *
  462.63 +     * <p><b>The actual result type is {@code Class<? extends |X|>}
  462.64 +     * where {@code |X|} is the erasure of the static type of the
  462.65 +     * expression on which {@code getClass} is called.</b> For
  462.66 +     * example, no cast is required in this code fragment:</p>
  462.67 +     *
  462.68 +     * <p>
  462.69 +     * {@code Number n = 0;                             }<br>
  462.70 +     * {@code Class<? extends Number> c = n.getClass(); }
  462.71 +     * </p>
  462.72 +     *
  462.73 +     * @return The {@code Class} object that represents the runtime
  462.74 +     *         class of this object.
  462.75 +     * @see    Class Literals, section 15.8.2 of
  462.76 +     *         <cite>The Java&trade; Language Specification</cite>.
  462.77 +     */
  462.78 +    @JavaScriptBody(args={}, body="return this.constructor.$class;")
  462.79 +    public final native Class<?> getClass();
  462.80 +
  462.81 +    /**
  462.82 +     * Returns a hash code value for the object. This method is
  462.83 +     * supported for the benefit of hash tables such as those provided by
  462.84 +     * {@link java.util.HashMap}.
  462.85 +     * <p>
  462.86 +     * The general contract of {@code hashCode} is:
  462.87 +     * <ul>
  462.88 +     * <li>Whenever it is invoked on the same object more than once during
  462.89 +     *     an execution of a Java application, the {@code hashCode} method
  462.90 +     *     must consistently return the same integer, provided no information
  462.91 +     *     used in {@code equals} comparisons on the object is modified.
  462.92 +     *     This integer need not remain consistent from one execution of an
  462.93 +     *     application to another execution of the same application.
  462.94 +     * <li>If two objects are equal according to the {@code equals(Object)}
  462.95 +     *     method, then calling the {@code hashCode} method on each of
  462.96 +     *     the two objects must produce the same integer result.
  462.97 +     * <li>It is <em>not</em> required that if two objects are unequal
  462.98 +     *     according to the {@link java.lang.Object#equals(java.lang.Object)}
  462.99 +     *     method, then calling the {@code hashCode} method on each of the
 462.100 +     *     two objects must produce distinct integer results.  However, the
 462.101 +     *     programmer should be aware that producing distinct integer results
 462.102 +     *     for unequal objects may improve the performance of hash tables.
 462.103 +     * </ul>
 462.104 +     * <p>
 462.105 +     * As much as is reasonably practical, the hashCode method defined by
 462.106 +     * class {@code Object} does return distinct integers for distinct
 462.107 +     * objects. (This is typically implemented by converting the internal
 462.108 +     * address of the object into an integer, but this implementation
 462.109 +     * technique is not required by the
 462.110 +     * Java<font size="-2"><sup>TM</sup></font> programming language.)
 462.111 +     *
 462.112 +     * @return  a hash code value for this object.
 462.113 +     * @see     java.lang.Object#equals(java.lang.Object)
 462.114 +     * @see     java.lang.System#identityHashCode
 462.115 +     */
 462.116 +    @JavaScriptBody(args = {}, body = 
 462.117 +        "if (this.$hashCode) return this.$hashCode;\n"
 462.118 +        + "var h = this.computeHashCode__I();\n"
 462.119 +        + "return this.$hashCode = h & h;"
 462.120 +    )
 462.121 +    public native int hashCode();
 462.122 +
 462.123 +    @JavaScriptBody(args = {}, body = "return Math.random() * Math.pow(2, 32);")
 462.124 +    native int computeHashCode();
 462.125 +    
 462.126 +    /**
 462.127 +     * Indicates whether some other object is "equal to" this one.
 462.128 +     * <p>
 462.129 +     * The {@code equals} method implements an equivalence relation
 462.130 +     * on non-null object references:
 462.131 +     * <ul>
 462.132 +     * <li>It is <i>reflexive</i>: for any non-null reference value
 462.133 +     *     {@code x}, {@code x.equals(x)} should return
 462.134 +     *     {@code true}.
 462.135 +     * <li>It is <i>symmetric</i>: for any non-null reference values
 462.136 +     *     {@code x} and {@code y}, {@code x.equals(y)}
 462.137 +     *     should return {@code true} if and only if
 462.138 +     *     {@code y.equals(x)} returns {@code true}.
 462.139 +     * <li>It is <i>transitive</i>: for any non-null reference values
 462.140 +     *     {@code x}, {@code y}, and {@code z}, if
 462.141 +     *     {@code x.equals(y)} returns {@code true} and
 462.142 +     *     {@code y.equals(z)} returns {@code true}, then
 462.143 +     *     {@code x.equals(z)} should return {@code true}.
 462.144 +     * <li>It is <i>consistent</i>: for any non-null reference values
 462.145 +     *     {@code x} and {@code y}, multiple invocations of
 462.146 +     *     {@code x.equals(y)} consistently return {@code true}
 462.147 +     *     or consistently return {@code false}, provided no
 462.148 +     *     information used in {@code equals} comparisons on the
 462.149 +     *     objects is modified.
 462.150 +     * <li>For any non-null reference value {@code x},
 462.151 +     *     {@code x.equals(null)} should return {@code false}.
 462.152 +     * </ul>
 462.153 +     * <p>
 462.154 +     * The {@code equals} method for class {@code Object} implements
 462.155 +     * the most discriminating possible equivalence relation on objects;
 462.156 +     * that is, for any non-null reference values {@code x} and
 462.157 +     * {@code y}, this method returns {@code true} if and only
 462.158 +     * if {@code x} and {@code y} refer to the same object
 462.159 +     * ({@code x == y} has the value {@code true}).
 462.160 +     * <p>
 462.161 +     * Note that it is generally necessary to override the {@code hashCode}
 462.162 +     * method whenever this method is overridden, so as to maintain the
 462.163 +     * general contract for the {@code hashCode} method, which states
 462.164 +     * that equal objects must have equal hash codes.
 462.165 +     *
 462.166 +     * @param   obj   the reference object with which to compare.
 462.167 +     * @return  {@code true} if this object is the same as the obj
 462.168 +     *          argument; {@code false} otherwise.
 462.169 +     * @see     #hashCode()
 462.170 +     * @see     java.util.HashMap
 462.171 +     */
 462.172 +    public boolean equals(Object obj) {
 462.173 +        return (this == obj);
 462.174 +    }
 462.175 +
 462.176 +    /**
 462.177 +     * Creates and returns a copy of this object.  The precise meaning
 462.178 +     * of "copy" may depend on the class of the object. The general
 462.179 +     * intent is that, for any object {@code x}, the expression:
 462.180 +     * <blockquote>
 462.181 +     * <pre>
 462.182 +     * x.clone() != x</pre></blockquote>
 462.183 +     * will be true, and that the expression:
 462.184 +     * <blockquote>
 462.185 +     * <pre>
 462.186 +     * x.clone().getClass() == x.getClass()</pre></blockquote>
 462.187 +     * will be {@code true}, but these are not absolute requirements.
 462.188 +     * While it is typically the case that:
 462.189 +     * <blockquote>
 462.190 +     * <pre>
 462.191 +     * x.clone().equals(x)</pre></blockquote>
 462.192 +     * will be {@code true}, this is not an absolute requirement.
 462.193 +     * <p>
 462.194 +     * By convention, the returned object should be obtained by calling
 462.195 +     * {@code super.clone}.  If a class and all of its superclasses (except
 462.196 +     * {@code Object}) obey this convention, it will be the case that
 462.197 +     * {@code x.clone().getClass() == x.getClass()}.
 462.198 +     * <p>
 462.199 +     * By convention, the object returned by this method should be independent
 462.200 +     * of this object (which is being cloned).  To achieve this independence,
 462.201 +     * it may be necessary to modify one or more fields of the object returned
 462.202 +     * by {@code super.clone} before returning it.  Typically, this means
 462.203 +     * copying any mutable objects that comprise the internal "deep structure"
 462.204 +     * of the object being cloned and replacing the references to these
 462.205 +     * objects with references to the copies.  If a class contains only
 462.206 +     * primitive fields or references to immutable objects, then it is usually
 462.207 +     * the case that no fields in the object returned by {@code super.clone}
 462.208 +     * need to be modified.
 462.209 +     * <p>
 462.210 +     * The method {@code clone} for class {@code Object} performs a
 462.211 +     * specific cloning operation. First, if the class of this object does
 462.212 +     * not implement the interface {@code Cloneable}, then a
 462.213 +     * {@code CloneNotSupportedException} is thrown. Note that all arrays
 462.214 +     * are considered to implement the interface {@code Cloneable} and that
 462.215 +     * the return type of the {@code clone} method of an array type {@code T[]}
 462.216 +     * is {@code T[]} where T is any reference or primitive type.
 462.217 +     * Otherwise, this method creates a new instance of the class of this
 462.218 +     * object and initializes all its fields with exactly the contents of
 462.219 +     * the corresponding fields of this object, as if by assignment; the
 462.220 +     * contents of the fields are not themselves cloned. Thus, this method
 462.221 +     * performs a "shallow copy" of this object, not a "deep copy" operation.
 462.222 +     * <p>
 462.223 +     * The class {@code Object} does not itself implement the interface
 462.224 +     * {@code Cloneable}, so calling the {@code clone} method on an object
 462.225 +     * whose class is {@code Object} will result in throwing an
 462.226 +     * exception at run time.
 462.227 +     *
 462.228 +     * @return     a clone of this instance.
 462.229 +     * @exception  CloneNotSupportedException  if the object's class does not
 462.230 +     *               support the {@code Cloneable} interface. Subclasses
 462.231 +     *               that override the {@code clone} method can also
 462.232 +     *               throw this exception to indicate that an instance cannot
 462.233 +     *               be cloned.
 462.234 +     * @see java.lang.Cloneable
 462.235 +     */
 462.236 +    protected Object clone() throws CloneNotSupportedException {
 462.237 +        Object ret = clone(this);
 462.238 +        if (ret == null) {
 462.239 +            throw new CloneNotSupportedException(getClass().getName());
 462.240 +        }
 462.241 +        return ret;
 462.242 +    }
 462.243 +
 462.244 +    @JavaScriptBody(args = "self", body = 
 462.245 +          "\nif (!self.$instOf_java_lang_Cloneable) {"
 462.246 +        + "\n  return null;"
 462.247 +        + "\n} else {"
 462.248 +        + "\n  var clone = self.constructor(true);"
 462.249 +        + "\n  var props = Object.getOwnPropertyNames(self);"
 462.250 +        + "\n  for (var i = 0; i < props.length; i++) {"
 462.251 +        + "\n    var p = props[i];"
 462.252 +        + "\n    clone[p] = self[p];"
 462.253 +        + "\n  };"
 462.254 +        + "\n  return clone;"
 462.255 +        + "\n}"
 462.256 +    )
 462.257 +    private static native Object clone(Object self) throws CloneNotSupportedException;
 462.258 +
 462.259 +    /**
 462.260 +     * Returns a string representation of the object. In general, the
 462.261 +     * {@code toString} method returns a string that
 462.262 +     * "textually represents" this object. The result should
 462.263 +     * be a concise but informative representation that is easy for a
 462.264 +     * person to read.
 462.265 +     * It is recommended that all subclasses override this method.
 462.266 +     * <p>
 462.267 +     * The {@code toString} method for class {@code Object}
 462.268 +     * returns a string consisting of the name of the class of which the
 462.269 +     * object is an instance, the at-sign character `{@code @}', and
 462.270 +     * the unsigned hexadecimal representation of the hash code of the
 462.271 +     * object. In other words, this method returns a string equal to the
 462.272 +     * value of:
 462.273 +     * <blockquote>
 462.274 +     * <pre>
 462.275 +     * getClass().getName() + '@' + Integer.toHexString(hashCode())
 462.276 +     * </pre></blockquote>
 462.277 +     *
 462.278 +     * @return  a string representation of the object.
 462.279 +     */
 462.280 +    public String toString() {
 462.281 +        return getClass().getName() + "@" + Integer.toHexString(hashCode());
 462.282 +    }
 462.283 +
 462.284 +    /**
 462.285 +     * Wakes up a single thread that is waiting on this object's
 462.286 +     * monitor. If any threads are waiting on this object, one of them
 462.287 +     * is chosen to be awakened. The choice is arbitrary and occurs at
 462.288 +     * the discretion of the implementation. A thread waits on an object's
 462.289 +     * monitor by calling one of the {@code wait} methods.
 462.290 +     * <p>
 462.291 +     * The awakened thread will not be able to proceed until the current
 462.292 +     * thread relinquishes the lock on this object. The awakened thread will
 462.293 +     * compete in the usual manner with any other threads that might be
 462.294 +     * actively competing to synchronize on this object; for example, the
 462.295 +     * awakened thread enjoys no reliable privilege or disadvantage in being
 462.296 +     * the next thread to lock this object.
 462.297 +     * <p>
 462.298 +     * This method should only be called by a thread that is the owner
 462.299 +     * of this object's monitor. A thread becomes the owner of the
 462.300 +     * object's monitor in one of three ways:
 462.301 +     * <ul>
 462.302 +     * <li>By executing a synchronized instance method of that object.
 462.303 +     * <li>By executing the body of a {@code synchronized} statement
 462.304 +     *     that synchronizes on the object.
 462.305 +     * <li>For objects of type {@code Class,} by executing a
 462.306 +     *     synchronized static method of that class.
 462.307 +     * </ul>
 462.308 +     * <p>
 462.309 +     * Only one thread at a time can own an object's monitor.
 462.310 +     *
 462.311 +     * @exception  IllegalMonitorStateException  if the current thread is not
 462.312 +     *               the owner of this object's monitor.
 462.313 +     * @see        java.lang.Object#notifyAll()
 462.314 +     * @see        java.lang.Object#wait()
 462.315 +     */
 462.316 +    public final native void notify();
 462.317 +
 462.318 +    /**
 462.319 +     * Wakes up all threads that are waiting on this object's monitor. A
 462.320 +     * thread waits on an object's monitor by calling one of the
 462.321 +     * {@code wait} methods.
 462.322 +     * <p>
 462.323 +     * The awakened threads will not be able to proceed until the current
 462.324 +     * thread relinquishes the lock on this object. The awakened threads
 462.325 +     * will compete in the usual manner with any other threads that might
 462.326 +     * be actively competing to synchronize on this object; for example,
 462.327 +     * the awakened threads enjoy no reliable privilege or disadvantage in
 462.328 +     * being the next thread to lock this object.
 462.329 +     * <p>
 462.330 +     * This method should only be called by a thread that is the owner
 462.331 +     * of this object's monitor. See the {@code notify} method for a
 462.332 +     * description of the ways in which a thread can become the owner of
 462.333 +     * a monitor.
 462.334 +     *
 462.335 +     * @exception  IllegalMonitorStateException  if the current thread is not
 462.336 +     *               the owner of this object's monitor.
 462.337 +     * @see        java.lang.Object#notify()
 462.338 +     * @see        java.lang.Object#wait()
 462.339 +     */
 462.340 +    public final native void notifyAll();
 462.341 +
 462.342 +    /**
 462.343 +     * Causes the current thread to wait until either another thread invokes the
 462.344 +     * {@link java.lang.Object#notify()} method or the
 462.345 +     * {@link java.lang.Object#notifyAll()} method for this object, or a
 462.346 +     * specified amount of time has elapsed.
 462.347 +     * <p>
 462.348 +     * The current thread must own this object's monitor.
 462.349 +     * <p>
 462.350 +     * This method causes the current thread (call it <var>T</var>) to
 462.351 +     * place itself in the wait set for this object and then to relinquish
 462.352 +     * any and all synchronization claims on this object. Thread <var>T</var>
 462.353 +     * becomes disabled for thread scheduling purposes and lies dormant
 462.354 +     * until one of four things happens:
 462.355 +     * <ul>
 462.356 +     * <li>Some other thread invokes the {@code notify} method for this
 462.357 +     * object and thread <var>T</var> happens to be arbitrarily chosen as
 462.358 +     * the thread to be awakened.
 462.359 +     * <li>Some other thread invokes the {@code notifyAll} method for this
 462.360 +     * object.
 462.361 +     * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
 462.362 +     * thread <var>T</var>.
 462.363 +     * <li>The specified amount of real time has elapsed, more or less.  If
 462.364 +     * {@code timeout} is zero, however, then real time is not taken into
 462.365 +     * consideration and the thread simply waits until notified.
 462.366 +     * </ul>
 462.367 +     * The thread <var>T</var> is then removed from the wait set for this
 462.368 +     * object and re-enabled for thread scheduling. It then competes in the
 462.369 +     * usual manner with other threads for the right to synchronize on the
 462.370 +     * object; once it has gained control of the object, all its
 462.371 +     * synchronization claims on the object are restored to the status quo
 462.372 +     * ante - that is, to the situation as of the time that the {@code wait}
 462.373 +     * method was invoked. Thread <var>T</var> then returns from the
 462.374 +     * invocation of the {@code wait} method. Thus, on return from the
 462.375 +     * {@code wait} method, the synchronization state of the object and of
 462.376 +     * thread {@code T} is exactly as it was when the {@code wait} method
 462.377 +     * was invoked.
 462.378 +     * <p>
 462.379 +     * A thread can also wake up without being notified, interrupted, or
 462.380 +     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
 462.381 +     * occur in practice, applications must guard against it by testing for
 462.382 +     * the condition that should have caused the thread to be awakened, and
 462.383 +     * continuing to wait if the condition is not satisfied.  In other words,
 462.384 +     * waits should always occur in loops, like this one:
 462.385 +     * <pre>
 462.386 +     *     synchronized (obj) {
 462.387 +     *         while (&lt;condition does not hold&gt;)
 462.388 +     *             obj.wait(timeout);
 462.389 +     *         ... // Perform action appropriate to condition
 462.390 +     *     }
 462.391 +     * </pre>
 462.392 +     * (For more information on this topic, see Section 3.2.3 in Doug Lea's
 462.393 +     * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
 462.394 +     * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
 462.395 +     * Language Guide" (Addison-Wesley, 2001).
 462.396 +     *
 462.397 +     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
 462.398 +     * interrupted} by any thread before or while it is waiting, then an
 462.399 +     * {@code InterruptedException} is thrown.  This exception is not
 462.400 +     * thrown until the lock status of this object has been restored as
 462.401 +     * described above.
 462.402 +     *
 462.403 +     * <p>
 462.404 +     * Note that the {@code wait} method, as it places the current thread
 462.405 +     * into the wait set for this object, unlocks only this object; any
 462.406 +     * other objects on which the current thread may be synchronized remain
 462.407 +     * locked while the thread waits.
 462.408 +     * <p>
 462.409 +     * This method should only be called by a thread that is the owner
 462.410 +     * of this object's monitor. See the {@code notify} method for a
 462.411 +     * description of the ways in which a thread can become the owner of
 462.412 +     * a monitor.
 462.413 +     *
 462.414 +     * @param      timeout   the maximum time to wait in milliseconds.
 462.415 +     * @exception  IllegalArgumentException      if the value of timeout is
 462.416 +     *               negative.
 462.417 +     * @exception  IllegalMonitorStateException  if the current thread is not
 462.418 +     *               the owner of the object's monitor.
 462.419 +     * @exception  InterruptedException if any thread interrupted the
 462.420 +     *             current thread before or while the current thread
 462.421 +     *             was waiting for a notification.  The <i>interrupted
 462.422 +     *             status</i> of the current thread is cleared when
 462.423 +     *             this exception is thrown.
 462.424 +     * @see        java.lang.Object#notify()
 462.425 +     * @see        java.lang.Object#notifyAll()
 462.426 +     */
 462.427 +    public final native void wait(long timeout) throws InterruptedException;
 462.428 +
 462.429 +    /**
 462.430 +     * Causes the current thread to wait until another thread invokes the
 462.431 +     * {@link java.lang.Object#notify()} method or the
 462.432 +     * {@link java.lang.Object#notifyAll()} method for this object, or
 462.433 +     * some other thread interrupts the current thread, or a certain
 462.434 +     * amount of real time has elapsed.
 462.435 +     * <p>
 462.436 +     * This method is similar to the {@code wait} method of one
 462.437 +     * argument, but it allows finer control over the amount of time to
 462.438 +     * wait for a notification before giving up. The amount of real time,
 462.439 +     * measured in nanoseconds, is given by:
 462.440 +     * <blockquote>
 462.441 +     * <pre>
 462.442 +     * 1000000*timeout+nanos</pre></blockquote>
 462.443 +     * <p>
 462.444 +     * In all other respects, this method does the same thing as the
 462.445 +     * method {@link #wait(long)} of one argument. In particular,
 462.446 +     * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
 462.447 +     * <p>
 462.448 +     * The current thread must own this object's monitor. The thread
 462.449 +     * releases ownership of this monitor and waits until either of the
 462.450 +     * following two conditions has occurred:
 462.451 +     * <ul>
 462.452 +     * <li>Another thread notifies threads waiting on this object's monitor
 462.453 +     *     to wake up either through a call to the {@code notify} method
 462.454 +     *     or the {@code notifyAll} method.
 462.455 +     * <li>The timeout period, specified by {@code timeout}
 462.456 +     *     milliseconds plus {@code nanos} nanoseconds arguments, has
 462.457 +     *     elapsed.
 462.458 +     * </ul>
 462.459 +     * <p>
 462.460 +     * The thread then waits until it can re-obtain ownership of the
 462.461 +     * monitor and resumes execution.
 462.462 +     * <p>
 462.463 +     * As in the one argument version, interrupts and spurious wakeups are
 462.464 +     * possible, and this method should always be used in a loop:
 462.465 +     * <pre>
 462.466 +     *     synchronized (obj) {
 462.467 +     *         while (&lt;condition does not hold&gt;)
 462.468 +     *             obj.wait(timeout, nanos);
 462.469 +     *         ... // Perform action appropriate to condition
 462.470 +     *     }
 462.471 +     * </pre>
 462.472 +     * This method should only be called by a thread that is the owner
 462.473 +     * of this object's monitor. See the {@code notify} method for a
 462.474 +     * description of the ways in which a thread can become the owner of
 462.475 +     * a monitor.
 462.476 +     *
 462.477 +     * @param      timeout   the maximum time to wait in milliseconds.
 462.478 +     * @param      nanos      additional time, in nanoseconds range
 462.479 +     *                       0-999999.
 462.480 +     * @exception  IllegalArgumentException      if the value of timeout is
 462.481 +     *                      negative or the value of nanos is
 462.482 +     *                      not in the range 0-999999.
 462.483 +     * @exception  IllegalMonitorStateException  if the current thread is not
 462.484 +     *               the owner of this object's monitor.
 462.485 +     * @exception  InterruptedException if any thread interrupted the
 462.486 +     *             current thread before or while the current thread
 462.487 +     *             was waiting for a notification.  The <i>interrupted
 462.488 +     *             status</i> of the current thread is cleared when
 462.489 +     *             this exception is thrown.
 462.490 +     */
 462.491 +    public final void wait(long timeout, int nanos) throws InterruptedException {
 462.492 +        if (timeout < 0) {
 462.493 +            throw new IllegalArgumentException("timeout value is negative");
 462.494 +        }
 462.495 +
 462.496 +        if (nanos < 0 || nanos > 999999) {
 462.497 +            throw new IllegalArgumentException(
 462.498 +                                "nanosecond timeout value out of range");
 462.499 +        }
 462.500 +
 462.501 +        if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
 462.502 +            timeout++;
 462.503 +        }
 462.504 +
 462.505 +        wait(timeout);
 462.506 +    }
 462.507 +
 462.508 +    /**
 462.509 +     * Causes the current thread to wait until another thread invokes the
 462.510 +     * {@link java.lang.Object#notify()} method or the
 462.511 +     * {@link java.lang.Object#notifyAll()} method for this object.
 462.512 +     * In other words, this method behaves exactly as if it simply
 462.513 +     * performs the call {@code wait(0)}.
 462.514 +     * <p>
 462.515 +     * The current thread must own this object's monitor. The thread
 462.516 +     * releases ownership of this monitor and waits until another thread
 462.517 +     * notifies threads waiting on this object's monitor to wake up
 462.518 +     * either through a call to the {@code notify} method or the
 462.519 +     * {@code notifyAll} method. The thread then waits until it can
 462.520 +     * re-obtain ownership of the monitor and resumes execution.
 462.521 +     * <p>
 462.522 +     * As in the one argument version, interrupts and spurious wakeups are
 462.523 +     * possible, and this method should always be used in a loop:
 462.524 +     * <pre>
 462.525 +     *     synchronized (obj) {
 462.526 +     *         while (&lt;condition does not hold&gt;)
 462.527 +     *             obj.wait();
 462.528 +     *         ... // Perform action appropriate to condition
 462.529 +     *     }
 462.530 +     * </pre>
 462.531 +     * This method should only be called by a thread that is the owner
 462.532 +     * of this object's monitor. See the {@code notify} method for a
 462.533 +     * description of the ways in which a thread can become the owner of
 462.534 +     * a monitor.
 462.535 +     *
 462.536 +     * @exception  IllegalMonitorStateException  if the current thread is not
 462.537 +     *               the owner of the object's monitor.
 462.538 +     * @exception  InterruptedException if any thread interrupted the
 462.539 +     *             current thread before or while the current thread
 462.540 +     *             was waiting for a notification.  The <i>interrupted
 462.541 +     *             status</i> of the current thread is cleared when
 462.542 +     *             this exception is thrown.
 462.543 +     * @see        java.lang.Object#notify()
 462.544 +     * @see        java.lang.Object#notifyAll()
 462.545 +     */
 462.546 +    public final void wait() throws InterruptedException {
 462.547 +        wait(0);
 462.548 +    }
 462.549 +
 462.550 +    /**
 462.551 +     * Called by the garbage collector on an object when garbage collection
 462.552 +     * determines that there are no more references to the object.
 462.553 +     * A subclass overrides the {@code finalize} method to dispose of
 462.554 +     * system resources or to perform other cleanup.
 462.555 +     * <p>
 462.556 +     * The general contract of {@code finalize} is that it is invoked
 462.557 +     * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
 462.558 +     * machine has determined that there is no longer any
 462.559 +     * means by which this object can be accessed by any thread that has
 462.560 +     * not yet died, except as a result of an action taken by the
 462.561 +     * finalization of some other object or class which is ready to be
 462.562 +     * finalized. The {@code finalize} method may take any action, including
 462.563 +     * making this object available again to other threads; the usual purpose
 462.564 +     * of {@code finalize}, however, is to perform cleanup actions before
 462.565 +     * the object is irrevocably discarded. For example, the finalize method
 462.566 +     * for an object that represents an input/output connection might perform
 462.567 +     * explicit I/O transactions to break the connection before the object is
 462.568 +     * permanently discarded.
 462.569 +     * <p>
 462.570 +     * The {@code finalize} method of class {@code Object} performs no
 462.571 +     * special action; it simply returns normally. Subclasses of
 462.572 +     * {@code Object} may override this definition.
 462.573 +     * <p>
 462.574 +     * The Java programming language does not guarantee which thread will
 462.575 +     * invoke the {@code finalize} method for any given object. It is
 462.576 +     * guaranteed, however, that the thread that invokes finalize will not
 462.577 +     * be holding any user-visible synchronization locks when finalize is
 462.578 +     * invoked. If an uncaught exception is thrown by the finalize method,
 462.579 +     * the exception is ignored and finalization of that object terminates.
 462.580 +     * <p>
 462.581 +     * After the {@code finalize} method has been invoked for an object, no
 462.582 +     * further action is taken until the Java virtual machine has again
 462.583 +     * determined that there is no longer any means by which this object can
 462.584 +     * be accessed by any thread that has not yet died, including possible
 462.585 +     * actions by other objects or classes which are ready to be finalized,
 462.586 +     * at which point the object may be discarded.
 462.587 +     * <p>
 462.588 +     * The {@code finalize} method is never invoked more than once by a Java
 462.589 +     * virtual machine for any given object.
 462.590 +     * <p>
 462.591 +     * Any exception thrown by the {@code finalize} method causes
 462.592 +     * the finalization of this object to be halted, but is otherwise
 462.593 +     * ignored.
 462.594 +     *
 462.595 +     * @throws Throwable the {@code Exception} raised by this method
 462.596 +     */
 462.597 +    protected void finalize() throws Throwable { }
 462.598 +}
   463.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   463.2 +++ b/rt/emul/mini/src/main/java/java/lang/OutOfMemoryError.java	Wed Feb 27 11:24:58 2013 +0100
   463.3 @@ -0,0 +1,60 @@
   463.4 +/*
   463.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   463.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   463.7 + *
   463.8 + * This code is free software; you can redistribute it and/or modify it
   463.9 + * under the terms of the GNU General Public License version 2 only, as
  463.10 + * published by the Free Software Foundation.  Oracle designates this
  463.11 + * particular file as subject to the "Classpath" exception as provided
  463.12 + * by Oracle in the LICENSE file that accompanied this code.
  463.13 + *
  463.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  463.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  463.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  463.17 + * version 2 for more details (a copy is included in the LICENSE file that
  463.18 + * accompanied this code).
  463.19 + *
  463.20 + * You should have received a copy of the GNU General Public License version
  463.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  463.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  463.23 + *
  463.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  463.25 + * or visit www.oracle.com if you need additional information or have any
  463.26 + * questions.
  463.27 + */
  463.28 +
  463.29 +package java.lang;
  463.30 +
  463.31 +/**
  463.32 + * Thrown when the Java Virtual Machine cannot allocate an object
  463.33 + * because it is out of memory, and no more memory could be made
  463.34 + * available by the garbage collector.
  463.35 + *
  463.36 + * {@code OutOfMemoryError} objects may be constructed by the virtual
  463.37 + * machine as if {@linkplain Throwable#Throwable(String, Throwable,
  463.38 + * boolean, boolean) suppression were disabled and/or the stack trace was not
  463.39 + * writable}.
  463.40 + *
  463.41 + * @author  unascribed
  463.42 + * @since   JDK1.0
  463.43 + */
  463.44 +public class OutOfMemoryError extends VirtualMachineError {
  463.45 +    private static final long serialVersionUID = 8228564086184010517L;
  463.46 +
  463.47 +    /**
  463.48 +     * Constructs an {@code OutOfMemoryError} with no detail message.
  463.49 +     */
  463.50 +    public OutOfMemoryError() {
  463.51 +        super();
  463.52 +    }
  463.53 +
  463.54 +    /**
  463.55 +     * Constructs an {@code OutOfMemoryError} with the specified
  463.56 +     * detail message.
  463.57 +     *
  463.58 +     * @param   s   the detail message.
  463.59 +     */
  463.60 +    public OutOfMemoryError(String s) {
  463.61 +        super(s);
  463.62 +    }
  463.63 +}
   464.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   464.2 +++ b/rt/emul/mini/src/main/java/java/lang/Override.java	Wed Feb 27 11:24:58 2013 +0100
   464.3 @@ -0,0 +1,52 @@
   464.4 +/*
   464.5 + * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
   464.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   464.7 + *
   464.8 + * This code is free software; you can redistribute it and/or modify it
   464.9 + * under the terms of the GNU General Public License version 2 only, as
  464.10 + * published by the Free Software Foundation.  Oracle designates this
  464.11 + * particular file as subject to the "Classpath" exception as provided
  464.12 + * by Oracle in the LICENSE file that accompanied this code.
  464.13 + *
  464.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  464.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  464.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  464.17 + * version 2 for more details (a copy is included in the LICENSE file that
  464.18 + * accompanied this code).
  464.19 + *
  464.20 + * You should have received a copy of the GNU General Public License version
  464.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  464.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  464.23 + *
  464.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  464.25 + * or visit www.oracle.com if you need additional information or have any
  464.26 + * questions.
  464.27 + */
  464.28 +
  464.29 +package java.lang;
  464.30 +
  464.31 +import java.lang.annotation.*;
  464.32 +
  464.33 +/**
  464.34 + * Indicates that a method declaration is intended to override a
  464.35 + * method declaration in a supertype. If a method is annotated with
  464.36 + * this annotation type compilers are required to generate an error
  464.37 + * message unless at least one of the following conditions hold:
  464.38 + *
  464.39 + * <ul><li>
  464.40 + * The method does override or implement a method declared in a
  464.41 + * supertype.
  464.42 + * </li><li>
  464.43 + * The method has a signature that is override-equivalent to that of
  464.44 + * any public method declared in {@linkplain Object}.
  464.45 + * </li></ul>
  464.46 + *
  464.47 + * @author  Peter von der Ah&eacute;
  464.48 + * @author  Joshua Bloch
  464.49 + * @jls 9.6.1.4 Override
  464.50 + * @since 1.5
  464.51 + */
  464.52 +@Target(ElementType.METHOD)
  464.53 +@Retention(RetentionPolicy.SOURCE)
  464.54 +public @interface Override {
  464.55 +}
   465.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   465.2 +++ b/rt/emul/mini/src/main/java/java/lang/ReflectiveOperationException.java	Wed Feb 27 11:24:58 2013 +0100
   465.3 @@ -0,0 +1,91 @@
   465.4 +/*
   465.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   465.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   465.7 + *
   465.8 + * This code is free software; you can redistribute it and/or modify it
   465.9 + * under the terms of the GNU General Public License version 2 only, as
  465.10 + * published by the Free Software Foundation.  Oracle designates this
  465.11 + * particular file as subject to the "Classpath" exception as provided
  465.12 + * by Oracle in the LICENSE file that accompanied this code.
  465.13 + *
  465.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  465.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  465.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  465.17 + * version 2 for more details (a copy is included in the LICENSE file that
  465.18 + * accompanied this code).
  465.19 + *
  465.20 + * You should have received a copy of the GNU General Public License version
  465.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  465.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  465.23 + *
  465.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  465.25 + * or visit www.oracle.com if you need additional information or have any
  465.26 + * questions.
  465.27 + */
  465.28 +
  465.29 +package java.lang;
  465.30 +
  465.31 +/**
  465.32 + * Common superclass of exceptions thrown by reflective operations in
  465.33 + * core reflection.
  465.34 + *
  465.35 + * @see LinkageError
  465.36 + * @since 1.7
  465.37 + */
  465.38 +public class ReflectiveOperationException extends Exception {
  465.39 +    static final long serialVersionUID = 123456789L;
  465.40 +
  465.41 +    /**
  465.42 +     * Constructs a new exception with {@code null} as its detail
  465.43 +     * message.  The cause is not initialized, and may subsequently be
  465.44 +     * initialized by a call to {@link #initCause}.
  465.45 +     */
  465.46 +    public ReflectiveOperationException() {
  465.47 +        super();
  465.48 +    }
  465.49 +
  465.50 +    /**
  465.51 +     * Constructs a new exception with the specified detail message.
  465.52 +     * The cause is not initialized, and may subsequently be
  465.53 +     * initialized by a call to {@link #initCause}.
  465.54 +     *
  465.55 +     * @param   message   the detail message. The detail message is saved for
  465.56 +     *          later retrieval by the {@link #getMessage()} method.
  465.57 +     */
  465.58 +    public ReflectiveOperationException(String message) {
  465.59 +        super(message);
  465.60 +    }
  465.61 +
  465.62 +    /**
  465.63 +     * Constructs a new exception with the specified detail message
  465.64 +     * and cause.
  465.65 +     *
  465.66 +     * <p>Note that the detail message associated with
  465.67 +     * {@code cause} is <em>not</em> automatically incorporated in
  465.68 +     * this exception's detail message.
  465.69 +     *
  465.70 +     * @param  message the detail message (which is saved for later retrieval
  465.71 +     *         by the {@link #getMessage()} method).
  465.72 +     * @param  cause the cause (which is saved for later retrieval by the
  465.73 +     *         {@link #getCause()} method).  (A {@code null} value is
  465.74 +     *         permitted, and indicates that the cause is nonexistent or
  465.75 +     *         unknown.)
  465.76 +     */
  465.77 +    public ReflectiveOperationException(String message, Throwable cause) {
  465.78 +        super(message, cause);
  465.79 +    }
  465.80 +
  465.81 +    /**
  465.82 +     * Constructs a new exception with the specified cause and a detail
  465.83 +     * message of {@code (cause==null ? null : cause.toString())} (which
  465.84 +     * typically contains the class and detail message of {@code cause}).
  465.85 +     *
  465.86 +     * @param  cause the cause (which is saved for later retrieval by the
  465.87 +     *         {@link #getCause()} method).  (A {@code null} value is
  465.88 +     *         permitted, and indicates that the cause is nonexistent or
  465.89 +     *         unknown.)
  465.90 +     */
  465.91 +    public ReflectiveOperationException(Throwable cause) {
  465.92 +        super(cause);
  465.93 +    }
  465.94 +}
   466.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   466.2 +++ b/rt/emul/mini/src/main/java/java/lang/Runnable.java	Wed Feb 27 11:24:58 2013 +0100
   466.3 @@ -0,0 +1,69 @@
   466.4 +/*
   466.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
   466.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   466.7 + *
   466.8 + * This code is free software; you can redistribute it and/or modify it
   466.9 + * under the terms of the GNU General Public License version 2 only, as
  466.10 + * published by the Free Software Foundation.  Oracle designates this
  466.11 + * particular file as subject to the "Classpath" exception as provided
  466.12 + * by Oracle in the LICENSE file that accompanied this code.
  466.13 + *
  466.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  466.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  466.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  466.17 + * version 2 for more details (a copy is included in the LICENSE file that
  466.18 + * accompanied this code).
  466.19 + *
  466.20 + * You should have received a copy of the GNU General Public License version
  466.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  466.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  466.23 + *
  466.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  466.25 + * or visit www.oracle.com if you need additional information or have any
  466.26 + * questions.
  466.27 + */
  466.28 +
  466.29 +package java.lang;
  466.30 +
  466.31 +/**
  466.32 + * The <code>Runnable</code> interface should be implemented by any
  466.33 + * class whose instances are intended to be executed by a thread. The
  466.34 + * class must define a method of no arguments called <code>run</code>.
  466.35 + * <p>
  466.36 + * This interface is designed to provide a common protocol for objects that
  466.37 + * wish to execute code while they are active. For example,
  466.38 + * <code>Runnable</code> is implemented by class <code>Thread</code>.
  466.39 + * Being active simply means that a thread has been started and has not
  466.40 + * yet been stopped.
  466.41 + * <p>
  466.42 + * In addition, <code>Runnable</code> provides the means for a class to be
  466.43 + * active while not subclassing <code>Thread</code>. A class that implements
  466.44 + * <code>Runnable</code> can run without subclassing <code>Thread</code>
  466.45 + * by instantiating a <code>Thread</code> instance and passing itself in
  466.46 + * as the target.  In most cases, the <code>Runnable</code> interface should
  466.47 + * be used if you are only planning to override the <code>run()</code>
  466.48 + * method and no other <code>Thread</code> methods.
  466.49 + * This is important because classes should not be subclassed
  466.50 + * unless the programmer intends on modifying or enhancing the fundamental
  466.51 + * behavior of the class.
  466.52 + *
  466.53 + * @author  Arthur van Hoff
  466.54 + * @see     java.lang.Thread
  466.55 + * @see     java.util.concurrent.Callable
  466.56 + * @since   JDK1.0
  466.57 + */
  466.58 +public
  466.59 +interface Runnable {
  466.60 +    /**
  466.61 +     * When an object implementing interface <code>Runnable</code> is used
  466.62 +     * to create a thread, starting the thread causes the object's
  466.63 +     * <code>run</code> method to be called in that separately executing
  466.64 +     * thread.
  466.65 +     * <p>
  466.66 +     * The general contract of the method <code>run</code> is that it may
  466.67 +     * take any action whatsoever.
  466.68 +     *
  466.69 +     * @see     java.lang.Thread#run()
  466.70 +     */
  466.71 +    public abstract void run();
  466.72 +}
   467.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   467.2 +++ b/rt/emul/mini/src/main/java/java/lang/RuntimeException.java	Wed Feb 27 11:24:58 2013 +0100
   467.3 @@ -0,0 +1,119 @@
   467.4 +/*
   467.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   467.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   467.7 + *
   467.8 + * This code is free software; you can redistribute it and/or modify it
   467.9 + * under the terms of the GNU General Public License version 2 only, as
  467.10 + * published by the Free Software Foundation.  Oracle designates this
  467.11 + * particular file as subject to the "Classpath" exception as provided
  467.12 + * by Oracle in the LICENSE file that accompanied this code.
  467.13 + *
  467.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  467.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  467.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  467.17 + * version 2 for more details (a copy is included in the LICENSE file that
  467.18 + * accompanied this code).
  467.19 + *
  467.20 + * You should have received a copy of the GNU General Public License version
  467.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  467.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  467.23 + *
  467.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  467.25 + * or visit www.oracle.com if you need additional information or have any
  467.26 + * questions.
  467.27 + */
  467.28 +
  467.29 +package java.lang;
  467.30 +
  467.31 +/**
  467.32 + * {@code RuntimeException} is the superclass of those
  467.33 + * exceptions that can be thrown during the normal operation of the
  467.34 + * Java Virtual Machine.
  467.35 + *
  467.36 + * <p>{@code RuntimeException} and its subclasses are <em>unchecked
  467.37 + * exceptions</em>.  Unchecked exceptions do <em>not</em> need to be
  467.38 + * declared in a method or constructor's {@code throws} clause if they
  467.39 + * can be thrown by the execution of the method or constructor and
  467.40 + * propagate outside the method or constructor boundary.
  467.41 + *
  467.42 + * @author  Frank Yellin
  467.43 + * @jls 11.2 Compile-Time Checking of Exceptions
  467.44 + * @since   JDK1.0
  467.45 + */
  467.46 +public class RuntimeException extends Exception {
  467.47 +    static final long serialVersionUID = -7034897190745766939L;
  467.48 +
  467.49 +    /** Constructs a new runtime exception with {@code null} as its
  467.50 +     * detail message.  The cause is not initialized, and may subsequently be
  467.51 +     * initialized by a call to {@link #initCause}.
  467.52 +     */
  467.53 +    public RuntimeException() {
  467.54 +        super();
  467.55 +    }
  467.56 +
  467.57 +    /** Constructs a new runtime exception with the specified detail message.
  467.58 +     * The cause is not initialized, and may subsequently be initialized by a
  467.59 +     * call to {@link #initCause}.
  467.60 +     *
  467.61 +     * @param   message   the detail message. The detail message is saved for
  467.62 +     *          later retrieval by the {@link #getMessage()} method.
  467.63 +     */
  467.64 +    public RuntimeException(String message) {
  467.65 +        super(message);
  467.66 +    }
  467.67 +
  467.68 +    /**
  467.69 +     * Constructs a new runtime exception with the specified detail message and
  467.70 +     * cause.  <p>Note that the detail message associated with
  467.71 +     * {@code cause} is <i>not</i> automatically incorporated in
  467.72 +     * this runtime exception's detail message.
  467.73 +     *
  467.74 +     * @param  message the detail message (which is saved for later retrieval
  467.75 +     *         by the {@link #getMessage()} method).
  467.76 +     * @param  cause the cause (which is saved for later retrieval by the
  467.77 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  467.78 +     *         permitted, and indicates that the cause is nonexistent or
  467.79 +     *         unknown.)
  467.80 +     * @since  1.4
  467.81 +     */
  467.82 +    public RuntimeException(String message, Throwable cause) {
  467.83 +        super(message, cause);
  467.84 +    }
  467.85 +
  467.86 +    /** Constructs a new runtime exception with the specified cause and a
  467.87 +     * detail message of <tt>(cause==null ? null : cause.toString())</tt>
  467.88 +     * (which typically contains the class and detail message of
  467.89 +     * <tt>cause</tt>).  This constructor is useful for runtime exceptions
  467.90 +     * that are little more than wrappers for other throwables.
  467.91 +     *
  467.92 +     * @param  cause the cause (which is saved for later retrieval by the
  467.93 +     *         {@link #getCause()} method).  (A <tt>null</tt> value is
  467.94 +     *         permitted, and indicates that the cause is nonexistent or
  467.95 +     *         unknown.)
  467.96 +     * @since  1.4
  467.97 +     */
  467.98 +    public RuntimeException(Throwable cause) {
  467.99 +        super(cause);
 467.100 +    }
 467.101 +
 467.102 +    /**
 467.103 +     * Constructs a new runtime exception with the specified detail
 467.104 +     * message, cause, suppression enabled or disabled, and writable
 467.105 +     * stack trace enabled or disabled.
 467.106 +     *
 467.107 +     * @param  message the detail message.
 467.108 +     * @param cause the cause.  (A {@code null} value is permitted,
 467.109 +     * and indicates that the cause is nonexistent or unknown.)
 467.110 +     * @param enableSuppression whether or not suppression is enabled
 467.111 +     *                          or disabled
 467.112 +     * @param writableStackTrace whether or not the stack trace should
 467.113 +     *                           be writable
 467.114 +     *
 467.115 +     * @since 1.7
 467.116 +     */
 467.117 +    protected RuntimeException(String message, Throwable cause,
 467.118 +                               boolean enableSuppression,
 467.119 +                               boolean writableStackTrace) {
 467.120 +        super(message, cause, enableSuppression, writableStackTrace);
 467.121 +    }
 467.122 +}
   468.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   468.2 +++ b/rt/emul/mini/src/main/java/java/lang/SecurityException.java	Wed Feb 27 11:24:58 2013 +0100
   468.3 @@ -0,0 +1,84 @@
   468.4 +/*
   468.5 + * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
   468.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   468.7 + *
   468.8 + * This code is free software; you can redistribute it and/or modify it
   468.9 + * under the terms of the GNU General Public License version 2 only, as
  468.10 + * published by the Free Software Foundation.  Oracle designates this
  468.11 + * particular file as subject to the "Classpath" exception as provided
  468.12 + * by Oracle in the LICENSE file that accompanied this code.
  468.13 + *
  468.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  468.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  468.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  468.17 + * version 2 for more details (a copy is included in the LICENSE file that
  468.18 + * accompanied this code).
  468.19 + *
  468.20 + * You should have received a copy of the GNU General Public License version
  468.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  468.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  468.23 + *
  468.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  468.25 + * or visit www.oracle.com if you need additional information or have any
  468.26 + * questions.
  468.27 + */
  468.28 +package java.lang;
  468.29 +
  468.30 +/**
  468.31 + * Thrown by the security manager to indicate a security violation.
  468.32 + *
  468.33 + * @author  unascribed
  468.34 + * @see     java.lang.SecurityManager
  468.35 + * @since   JDK1.0
  468.36 + */
  468.37 +public class SecurityException extends RuntimeException {
  468.38 +
  468.39 +    private static final long serialVersionUID = 6878364983674394167L;
  468.40 +
  468.41 +    /**
  468.42 +     * Constructs a <code>SecurityException</code> with no detail  message.
  468.43 +     */
  468.44 +    public SecurityException() {
  468.45 +        super();
  468.46 +    }
  468.47 +
  468.48 +    /**
  468.49 +     * Constructs a <code>SecurityException</code> with the specified
  468.50 +     * detail message.
  468.51 +     *
  468.52 +     * @param   s   the detail message.
  468.53 +     */
  468.54 +    public SecurityException(String s) {
  468.55 +        super(s);
  468.56 +    }
  468.57 +
  468.58 +    /**
  468.59 +     * Creates a <code>SecurityException</code> with the specified
  468.60 +     * detail message and cause.
  468.61 +     *
  468.62 +     * @param message the detail message (which is saved for later retrieval
  468.63 +     *        by the {@link #getMessage()} method).
  468.64 +     * @param cause the cause (which is saved for later retrieval by the
  468.65 +     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  468.66 +     *        and indicates that the cause is nonexistent or unknown.)
  468.67 +     * @since 1.5
  468.68 +     */
  468.69 +    public SecurityException(String message, Throwable cause) {
  468.70 +        super(message, cause);
  468.71 +    }
  468.72 +
  468.73 +    /**
  468.74 +     * Creates a <code>SecurityException</code> with the specified cause
  468.75 +     * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
  468.76 +     * (which typically contains the class and detail message of
  468.77 +     * <tt>cause</tt>).
  468.78 +     *
  468.79 +     * @param cause the cause (which is saved for later retrieval by the
  468.80 +     *        {@link #getCause()} method).  (A <tt>null</tt> value is permitted,
  468.81 +     *        and indicates that the cause is nonexistent or unknown.)
  468.82 +     * @since 1.5
  468.83 +     */
  468.84 +    public SecurityException(Throwable cause) {
  468.85 +        super(cause);
  468.86 +    }
  468.87 +}
   469.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   469.2 +++ b/rt/emul/mini/src/main/java/java/lang/Short.java	Wed Feb 27 11:24:58 2013 +0100
   469.3 @@ -0,0 +1,468 @@
   469.4 +/*
   469.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   469.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   469.7 + *
   469.8 + * This code is free software; you can redistribute it and/or modify it
   469.9 + * under the terms of the GNU General Public License version 2 only, as
  469.10 + * published by the Free Software Foundation.  Oracle designates this
  469.11 + * particular file as subject to the "Classpath" exception as provided
  469.12 + * by Oracle in the LICENSE file that accompanied this code.
  469.13 + *
  469.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  469.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  469.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  469.17 + * version 2 for more details (a copy is included in the LICENSE file that
  469.18 + * accompanied this code).
  469.19 + *
  469.20 + * You should have received a copy of the GNU General Public License version
  469.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  469.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  469.23 + *
  469.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  469.25 + * or visit www.oracle.com if you need additional information or have any
  469.26 + * questions.
  469.27 + */
  469.28 +
  469.29 +package java.lang;
  469.30 +
  469.31 +/**
  469.32 + * The {@code Short} class wraps a value of primitive type {@code
  469.33 + * short} in an object.  An object of type {@code Short} contains a
  469.34 + * single field whose type is {@code short}.
  469.35 + *
  469.36 + * <p>In addition, this class provides several methods for converting
  469.37 + * a {@code short} to a {@code String} and a {@code String} to a
  469.38 + * {@code short}, as well as other constants and methods useful when
  469.39 + * dealing with a {@code short}.
  469.40 + *
  469.41 + * @author  Nakul Saraiya
  469.42 + * @author  Joseph D. Darcy
  469.43 + * @see     java.lang.Number
  469.44 + * @since   JDK1.1
  469.45 + */
  469.46 +public final class Short extends Number implements Comparable<Short> {
  469.47 +
  469.48 +    /**
  469.49 +     * A constant holding the minimum value a {@code short} can
  469.50 +     * have, -2<sup>15</sup>.
  469.51 +     */
  469.52 +    public static final short   MIN_VALUE = -32768;
  469.53 +
  469.54 +    /**
  469.55 +     * A constant holding the maximum value a {@code short} can
  469.56 +     * have, 2<sup>15</sup>-1.
  469.57 +     */
  469.58 +    public static final short   MAX_VALUE = 32767;
  469.59 +
  469.60 +    /**
  469.61 +     * The {@code Class} instance representing the primitive type
  469.62 +     * {@code short}.
  469.63 +     */
  469.64 +    public static final Class<Short>    TYPE = (Class<Short>) Class.getPrimitiveClass("short");
  469.65 +
  469.66 +    /**
  469.67 +     * Returns a new {@code String} object representing the
  469.68 +     * specified {@code short}. The radix is assumed to be 10.
  469.69 +     *
  469.70 +     * @param s the {@code short} to be converted
  469.71 +     * @return the string representation of the specified {@code short}
  469.72 +     * @see java.lang.Integer#toString(int)
  469.73 +     */
  469.74 +    public static String toString(short s) {
  469.75 +        return Integer.toString((int)s, 10);
  469.76 +    }
  469.77 +
  469.78 +    /**
  469.79 +     * Parses the string argument as a signed {@code short} in the
  469.80 +     * radix specified by the second argument. The characters in the
  469.81 +     * string must all be digits, of the specified radix (as
  469.82 +     * determined by whether {@link java.lang.Character#digit(char,
  469.83 +     * int)} returns a nonnegative value) except that the first
  469.84 +     * character may be an ASCII minus sign {@code '-'}
  469.85 +     * (<code>'&#92;u002D'</code>) to indicate a negative value or an
  469.86 +     * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
  469.87 +     * indicate a positive value.  The resulting {@code short} value
  469.88 +     * is returned.
  469.89 +     *
  469.90 +     * <p>An exception of type {@code NumberFormatException} is
  469.91 +     * thrown if any of the following situations occurs:
  469.92 +     * <ul>
  469.93 +     * <li> The first argument is {@code null} or is a string of
  469.94 +     * length zero.
  469.95 +     *
  469.96 +     * <li> The radix is either smaller than {@link
  469.97 +     * java.lang.Character#MIN_RADIX} or larger than {@link
  469.98 +     * java.lang.Character#MAX_RADIX}.
  469.99 +     *
 469.100 +     * <li> Any character of the string is not a digit of the
 469.101 +     * specified radix, except that the first character may be a minus
 469.102 +     * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
 469.103 +     * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
 469.104 +     * string is longer than length 1.
 469.105 +     *
 469.106 +     * <li> The value represented by the string is not a value of type
 469.107 +     * {@code short}.
 469.108 +     * </ul>
 469.109 +     *
 469.110 +     * @param s         the {@code String} containing the
 469.111 +     *                  {@code short} representation to be parsed
 469.112 +     * @param radix     the radix to be used while parsing {@code s}
 469.113 +     * @return          the {@code short} represented by the string
 469.114 +     *                  argument in the specified radix.
 469.115 +     * @throws          NumberFormatException If the {@code String}
 469.116 +     *                  does not contain a parsable {@code short}.
 469.117 +     */
 469.118 +    public static short parseShort(String s, int radix)
 469.119 +        throws NumberFormatException {
 469.120 +        int i = Integer.parseInt(s, radix);
 469.121 +        if (i < MIN_VALUE || i > MAX_VALUE)
 469.122 +            throw new NumberFormatException(
 469.123 +                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
 469.124 +        return (short)i;
 469.125 +    }
 469.126 +
 469.127 +    /**
 469.128 +     * Parses the string argument as a signed decimal {@code
 469.129 +     * short}. The characters in the string must all be decimal
 469.130 +     * digits, except that the first character may be an ASCII minus
 469.131 +     * sign {@code '-'} (<code>'&#92;u002D'</code>) to indicate a
 469.132 +     * negative value or an ASCII plus sign {@code '+'}
 469.133 +     * (<code>'&#92;u002B'</code>) to indicate a positive value.  The
 469.134 +     * resulting {@code short} value is returned, exactly as if the
 469.135 +     * argument and the radix 10 were given as arguments to the {@link
 469.136 +     * #parseShort(java.lang.String, int)} method.
 469.137 +     *
 469.138 +     * @param s a {@code String} containing the {@code short}
 469.139 +     *          representation to be parsed
 469.140 +     * @return  the {@code short} value represented by the
 469.141 +     *          argument in decimal.
 469.142 +     * @throws  NumberFormatException If the string does not
 469.143 +     *          contain a parsable {@code short}.
 469.144 +     */
 469.145 +    public static short parseShort(String s) throws NumberFormatException {
 469.146 +        return parseShort(s, 10);
 469.147 +    }
 469.148 +
 469.149 +    /**
 469.150 +     * Returns a {@code Short} object holding the value
 469.151 +     * extracted from the specified {@code String} when parsed
 469.152 +     * with the radix given by the second argument. The first argument
 469.153 +     * is interpreted as representing a signed {@code short} in
 469.154 +     * the radix specified by the second argument, exactly as if the
 469.155 +     * argument were given to the {@link #parseShort(java.lang.String,
 469.156 +     * int)} method. The result is a {@code Short} object that
 469.157 +     * represents the {@code short} value specified by the string.
 469.158 +     *
 469.159 +     * <p>In other words, this method returns a {@code Short} object
 469.160 +     * equal to the value of:
 469.161 +     *
 469.162 +     * <blockquote>
 469.163 +     *  {@code new Short(Short.parseShort(s, radix))}
 469.164 +     * </blockquote>
 469.165 +     *
 469.166 +     * @param s         the string to be parsed
 469.167 +     * @param radix     the radix to be used in interpreting {@code s}
 469.168 +     * @return          a {@code Short} object holding the value
 469.169 +     *                  represented by the string argument in the
 469.170 +     *                  specified radix.
 469.171 +     * @throws          NumberFormatException If the {@code String} does
 469.172 +     *                  not contain a parsable {@code short}.
 469.173 +     */
 469.174 +    public static Short valueOf(String s, int radix)
 469.175 +        throws NumberFormatException {
 469.176 +        return valueOf(parseShort(s, radix));
 469.177 +    }
 469.178 +
 469.179 +    /**
 469.180 +     * Returns a {@code Short} object holding the
 469.181 +     * value given by the specified {@code String}. The argument
 469.182 +     * is interpreted as representing a signed decimal
 469.183 +     * {@code short}, exactly as if the argument were given to
 469.184 +     * the {@link #parseShort(java.lang.String)} method. The result is
 469.185 +     * a {@code Short} object that represents the
 469.186 +     * {@code short} value specified by the string.
 469.187 +     *
 469.188 +     * <p>In other words, this method returns a {@code Short} object
 469.189 +     * equal to the value of:
 469.190 +     *
 469.191 +     * <blockquote>
 469.192 +     *  {@code new Short(Short.parseShort(s))}
 469.193 +     * </blockquote>
 469.194 +     *
 469.195 +     * @param s the string to be parsed
 469.196 +     * @return  a {@code Short} object holding the value
 469.197 +     *          represented by the string argument
 469.198 +     * @throws  NumberFormatException If the {@code String} does
 469.199 +     *          not contain a parsable {@code short}.
 469.200 +     */
 469.201 +    public static Short valueOf(String s) throws NumberFormatException {
 469.202 +        return valueOf(s, 10);
 469.203 +    }
 469.204 +
 469.205 +    private static class ShortCache {
 469.206 +        private ShortCache(){}
 469.207 +
 469.208 +        static final Short cache[] = new Short[-(-128) + 127 + 1];
 469.209 +
 469.210 +        static {
 469.211 +            for(int i = 0; i < cache.length; i++)
 469.212 +                cache[i] = new Short((short)(i - 128));
 469.213 +        }
 469.214 +    }
 469.215 +
 469.216 +    /**
 469.217 +     * Returns a {@code Short} instance representing the specified
 469.218 +     * {@code short} value.
 469.219 +     * If a new {@code Short} instance is not required, this method
 469.220 +     * should generally be used in preference to the constructor
 469.221 +     * {@link #Short(short)}, as this method is likely to yield
 469.222 +     * significantly better space and time performance by caching
 469.223 +     * frequently requested values.
 469.224 +     *
 469.225 +     * This method will always cache values in the range -128 to 127,
 469.226 +     * inclusive, and may cache other values outside of this range.
 469.227 +     *
 469.228 +     * @param  s a short value.
 469.229 +     * @return a {@code Short} instance representing {@code s}.
 469.230 +     * @since  1.5
 469.231 +     */
 469.232 +    public static Short valueOf(short s) {
 469.233 +        final int offset = 128;
 469.234 +        int sAsInt = s;
 469.235 +        if (sAsInt >= -128 && sAsInt <= 127) { // must cache
 469.236 +            return ShortCache.cache[sAsInt + offset];
 469.237 +        }
 469.238 +        return new Short(s);
 469.239 +    }
 469.240 +
 469.241 +    /**
 469.242 +     * Decodes a {@code String} into a {@code Short}.
 469.243 +     * Accepts decimal, hexadecimal, and octal numbers given by
 469.244 +     * the following grammar:
 469.245 +     *
 469.246 +     * <blockquote>
 469.247 +     * <dl>
 469.248 +     * <dt><i>DecodableString:</i>
 469.249 +     * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
 469.250 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
 469.251 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
 469.252 +     * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
 469.253 +     * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
 469.254 +     * <p>
 469.255 +     * <dt><i>Sign:</i>
 469.256 +     * <dd>{@code -}
 469.257 +     * <dd>{@code +}
 469.258 +     * </dl>
 469.259 +     * </blockquote>
 469.260 +     *
 469.261 +     * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
 469.262 +     * are as defined in section 3.10.1 of
 469.263 +     * <cite>The Java&trade; Language Specification</cite>,
 469.264 +     * except that underscores are not accepted between digits.
 469.265 +     *
 469.266 +     * <p>The sequence of characters following an optional
 469.267 +     * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
 469.268 +     * "{@code #}", or leading zero) is parsed as by the {@code
 469.269 +     * Short.parseShort} method with the indicated radix (10, 16, or
 469.270 +     * 8).  This sequence of characters must represent a positive
 469.271 +     * value or a {@link NumberFormatException} will be thrown.  The
 469.272 +     * result is negated if first character of the specified {@code
 469.273 +     * String} is the minus sign.  No whitespace characters are
 469.274 +     * permitted in the {@code String}.
 469.275 +     *
 469.276 +     * @param     nm the {@code String} to decode.
 469.277 +     * @return    a {@code Short} object holding the {@code short}
 469.278 +     *            value represented by {@code nm}
 469.279 +     * @throws    NumberFormatException  if the {@code String} does not
 469.280 +     *            contain a parsable {@code short}.
 469.281 +     * @see java.lang.Short#parseShort(java.lang.String, int)
 469.282 +     */
 469.283 +    public static Short decode(String nm) throws NumberFormatException {
 469.284 +        int i = Integer.decode(nm);
 469.285 +        if (i < MIN_VALUE || i > MAX_VALUE)
 469.286 +            throw new NumberFormatException(
 469.287 +                    "Value " + i + " out of range from input " + nm);
 469.288 +        return valueOf((short)i);
 469.289 +    }
 469.290 +
 469.291 +    /**
 469.292 +     * The value of the {@code Short}.
 469.293 +     *
 469.294 +     * @serial
 469.295 +     */
 469.296 +    private final short value;
 469.297 +
 469.298 +    /**
 469.299 +     * Constructs a newly allocated {@code Short} object that
 469.300 +     * represents the specified {@code short} value.
 469.301 +     *
 469.302 +     * @param value     the value to be represented by the
 469.303 +     *                  {@code Short}.
 469.304 +     */
 469.305 +    public Short(short value) {
 469.306 +        this.value = value;
 469.307 +    }
 469.308 +
 469.309 +    /**
 469.310 +     * Constructs a newly allocated {@code Short} object that
 469.311 +     * represents the {@code short} value indicated by the
 469.312 +     * {@code String} parameter. The string is converted to a
 469.313 +     * {@code short} value in exactly the manner used by the
 469.314 +     * {@code parseShort} method for radix 10.
 469.315 +     *
 469.316 +     * @param s the {@code String} to be converted to a
 469.317 +     *          {@code Short}
 469.318 +     * @throws  NumberFormatException If the {@code String}
 469.319 +     *          does not contain a parsable {@code short}.
 469.320 +     * @see     java.lang.Short#parseShort(java.lang.String, int)
 469.321 +     */
 469.322 +    public Short(String s) throws NumberFormatException {
 469.323 +        this.value = parseShort(s, 10);
 469.324 +    }
 469.325 +
 469.326 +    /**
 469.327 +     * Returns the value of this {@code Short} as a
 469.328 +     * {@code byte}.
 469.329 +     */
 469.330 +    public byte byteValue() {
 469.331 +        return (byte)value;
 469.332 +    }
 469.333 +
 469.334 +    /**
 469.335 +     * Returns the value of this {@code Short} as a
 469.336 +     * {@code short}.
 469.337 +     */
 469.338 +    public short shortValue() {
 469.339 +        return value;
 469.340 +    }
 469.341 +
 469.342 +    /**
 469.343 +     * Returns the value of this {@code Short} as an
 469.344 +     * {@code int}.
 469.345 +     */
 469.346 +    public int intValue() {
 469.347 +        return (int)value;
 469.348 +    }
 469.349 +
 469.350 +    /**
 469.351 +     * Returns the value of this {@code Short} as a
 469.352 +     * {@code long}.
 469.353 +     */
 469.354 +    public long longValue() {
 469.355 +        return (long)value;
 469.356 +    }
 469.357 +
 469.358 +    /**
 469.359 +     * Returns the value of this {@code Short} as a
 469.360 +     * {@code float}.
 469.361 +     */
 469.362 +    public float floatValue() {
 469.363 +        return (float)value;
 469.364 +    }
 469.365 +
 469.366 +    /**
 469.367 +     * Returns the value of this {@code Short} as a
 469.368 +     * {@code double}.
 469.369 +     */
 469.370 +    public double doubleValue() {
 469.371 +        return (double)value;
 469.372 +    }
 469.373 +
 469.374 +    /**
 469.375 +     * Returns a {@code String} object representing this
 469.376 +     * {@code Short}'s value.  The value is converted to signed
 469.377 +     * decimal representation and returned as a string, exactly as if
 469.378 +     * the {@code short} value were given as an argument to the
 469.379 +     * {@link java.lang.Short#toString(short)} method.
 469.380 +     *
 469.381 +     * @return  a string representation of the value of this object in
 469.382 +     *          base&nbsp;10.
 469.383 +     */
 469.384 +    public String toString() {
 469.385 +        return Integer.toString((int)value);
 469.386 +    }
 469.387 +
 469.388 +    /**
 469.389 +     * Returns a hash code for this {@code Short}; equal to the result
 469.390 +     * of invoking {@code intValue()}.
 469.391 +     *
 469.392 +     * @return a hash code value for this {@code Short}
 469.393 +     */
 469.394 +    public int hashCode() {
 469.395 +        return (int)value;
 469.396 +    }
 469.397 +
 469.398 +    /**
 469.399 +     * Compares this object to the specified object.  The result is
 469.400 +     * {@code true} if and only if the argument is not
 469.401 +     * {@code null} and is a {@code Short} object that
 469.402 +     * contains the same {@code short} value as this object.
 469.403 +     *
 469.404 +     * @param obj       the object to compare with
 469.405 +     * @return          {@code true} if the objects are the same;
 469.406 +     *                  {@code false} otherwise.
 469.407 +     */
 469.408 +    public boolean equals(Object obj) {
 469.409 +        if (obj instanceof Short) {
 469.410 +            return value == ((Short)obj).shortValue();
 469.411 +        }
 469.412 +        return false;
 469.413 +    }
 469.414 +
 469.415 +    /**
 469.416 +     * Compares two {@code Short} objects numerically.
 469.417 +     *
 469.418 +     * @param   anotherShort   the {@code Short} to be compared.
 469.419 +     * @return  the value {@code 0} if this {@code Short} is
 469.420 +     *          equal to the argument {@code Short}; a value less than
 469.421 +     *          {@code 0} if this {@code Short} is numerically less
 469.422 +     *          than the argument {@code Short}; and a value greater than
 469.423 +     *           {@code 0} if this {@code Short} is numerically
 469.424 +     *           greater than the argument {@code Short} (signed
 469.425 +     *           comparison).
 469.426 +     * @since   1.2
 469.427 +     */
 469.428 +    public int compareTo(Short anotherShort) {
 469.429 +        return compare(this.value, anotherShort.value);
 469.430 +    }
 469.431 +
 469.432 +    /**
 469.433 +     * Compares two {@code short} values numerically.
 469.434 +     * The value returned is identical to what would be returned by:
 469.435 +     * <pre>
 469.436 +     *    Short.valueOf(x).compareTo(Short.valueOf(y))
 469.437 +     * </pre>
 469.438 +     *
 469.439 +     * @param  x the first {@code short} to compare
 469.440 +     * @param  y the second {@code short} to compare
 469.441 +     * @return the value {@code 0} if {@code x == y};
 469.442 +     *         a value less than {@code 0} if {@code x < y}; and
 469.443 +     *         a value greater than {@code 0} if {@code x > y}
 469.444 +     * @since 1.7
 469.445 +     */
 469.446 +    public static int compare(short x, short y) {
 469.447 +        return x - y;
 469.448 +    }
 469.449 +
 469.450 +    /**
 469.451 +     * The number of bits used to represent a {@code short} value in two's
 469.452 +     * complement binary form.
 469.453 +     * @since 1.5
 469.454 +     */
 469.455 +    public static final int SIZE = 16;
 469.456 +
 469.457 +    /**
 469.458 +     * Returns the value obtained by reversing the order of the bytes in the
 469.459 +     * two's complement representation of the specified {@code short} value.
 469.460 +     *
 469.461 +     * @return the value obtained by reversing (or, equivalently, swapping)
 469.462 +     *     the bytes in the specified {@code short} value.
 469.463 +     * @since 1.5
 469.464 +     */
 469.465 +    public static short reverseBytes(short i) {
 469.466 +        return (short) (((i & 0xFF00) >> 8) | (i << 8));
 469.467 +    }
 469.468 +
 469.469 +    /** use serialVersionUID from JDK 1.1. for interoperability */
 469.470 +    private static final long serialVersionUID = 7515723908773894738L;
 469.471 +}
   470.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   470.2 +++ b/rt/emul/mini/src/main/java/java/lang/StackTraceElement.java	Wed Feb 27 11:24:58 2013 +0100
   470.3 @@ -0,0 +1,223 @@
   470.4 +/*
   470.5 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
   470.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   470.7 + *
   470.8 + * This code is free software; you can redistribute it and/or modify it
   470.9 + * under the terms of the GNU General Public License version 2 only, as
  470.10 + * published by the Free Software Foundation.  Oracle designates this
  470.11 + * particular file as subject to the "Classpath" exception as provided
  470.12 + * by Oracle in the LICENSE file that accompanied this code.
  470.13 + *
  470.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  470.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  470.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  470.17 + * version 2 for more details (a copy is included in the LICENSE file that
  470.18 + * accompanied this code).
  470.19 + *
  470.20 + * You should have received a copy of the GNU General Public License version
  470.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  470.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  470.23 + *
  470.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  470.25 + * or visit www.oracle.com if you need additional information or have any
  470.26 + * questions.
  470.27 + */
  470.28 +
  470.29 +package java.lang;
  470.30 +
  470.31 +/**
  470.32 + * An element in a stack trace, as returned by {@link
  470.33 + * Throwable#getStackTrace()}.  Each element represents a single stack frame.
  470.34 + * All stack frames except for the one at the top of the stack represent
  470.35 + * a method invocation.  The frame at the top of the stack represents the
  470.36 + * execution point at which the stack trace was generated.  Typically,
  470.37 + * this is the point at which the throwable corresponding to the stack trace
  470.38 + * was created.
  470.39 + *
  470.40 + * @since  1.4
  470.41 + * @author Josh Bloch
  470.42 + */
  470.43 +public final class StackTraceElement implements java.io.Serializable {
  470.44 +    // Normally initialized by VM (public constructor added in 1.5)
  470.45 +    private String declaringClass;
  470.46 +    private String methodName;
  470.47 +    private String fileName;
  470.48 +    private int    lineNumber;
  470.49 +
  470.50 +    /**
  470.51 +     * Creates a stack trace element representing the specified execution
  470.52 +     * point.
  470.53 +     *
  470.54 +     * @param declaringClass the fully qualified name of the class containing
  470.55 +     *        the execution point represented by the stack trace element
  470.56 +     * @param methodName the name of the method containing the execution point
  470.57 +     *        represented by the stack trace element
  470.58 +     * @param fileName the name of the file containing the execution point
  470.59 +     *         represented by the stack trace element, or {@code null} if
  470.60 +     *         this information is unavailable
  470.61 +     * @param lineNumber the line number of the source line containing the
  470.62 +     *         execution point represented by this stack trace element, or
  470.63 +     *         a negative number if this information is unavailable. A value
  470.64 +     *         of -2 indicates that the method containing the execution point
  470.65 +     *         is a native method
  470.66 +     * @throws NullPointerException if {@code declaringClass} or
  470.67 +     *         {@code methodName} is null
  470.68 +     * @since 1.5
  470.69 +     */
  470.70 +    public StackTraceElement(String declaringClass, String methodName,
  470.71 +                             String fileName, int lineNumber) {
  470.72 +        this.declaringClass = declaringClass;
  470.73 +        this.methodName     = methodName;
  470.74 +        this.fileName       = fileName;
  470.75 +        this.lineNumber     = lineNumber;
  470.76 +    }
  470.77 +
  470.78 +    /**
  470.79 +     * Returns the name of the source file containing the execution point
  470.80 +     * represented by this stack trace element.  Generally, this corresponds
  470.81 +     * to the {@code SourceFile} attribute of the relevant {@code class}
  470.82 +     * file (as per <i>The Java Virtual Machine Specification</i>, Section
  470.83 +     * 4.7.7).  In some systems, the name may refer to some source code unit
  470.84 +     * other than a file, such as an entry in source repository.
  470.85 +     *
  470.86 +     * @return the name of the file containing the execution point
  470.87 +     *         represented by this stack trace element, or {@code null} if
  470.88 +     *         this information is unavailable.
  470.89 +     */
  470.90 +    public String getFileName() {
  470.91 +        return fileName;
  470.92 +    }
  470.93 +
  470.94 +    /**
  470.95 +     * Returns the line number of the source line containing the execution
  470.96 +     * point represented by this stack trace element.  Generally, this is
  470.97 +     * derived from the {@code LineNumberTable} attribute of the relevant
  470.98 +     * {@code class} file (as per <i>The Java Virtual Machine
  470.99 +     * Specification</i>, Section 4.7.8).
 470.100 +     *
 470.101 +     * @return the line number of the source line containing the execution
 470.102 +     *         point represented by this stack trace element, or a negative
 470.103 +     *         number if this information is unavailable.
 470.104 +     */
 470.105 +    public int getLineNumber() {
 470.106 +        return lineNumber;
 470.107 +    }
 470.108 +
 470.109 +    /**
 470.110 +     * Returns the fully qualified name of the class containing the
 470.111 +     * execution point represented by this stack trace element.
 470.112 +     *
 470.113 +     * @return the fully qualified name of the {@code Class} containing
 470.114 +     *         the execution point represented by this stack trace element.
 470.115 +     */
 470.116 +    public String getClassName() {
 470.117 +        return declaringClass;
 470.118 +    }
 470.119 +
 470.120 +    /**
 470.121 +     * Returns the name of the method containing the execution point
 470.122 +     * represented by this stack trace element.  If the execution point is
 470.123 +     * contained in an instance or class initializer, this method will return
 470.124 +     * the appropriate <i>special method name</i>, {@code <init>} or
 470.125 +     * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
 470.126 +     * Machine Specification</i>.
 470.127 +     *
 470.128 +     * @return the name of the method containing the execution point
 470.129 +     *         represented by this stack trace element.
 470.130 +     */
 470.131 +    public String getMethodName() {
 470.132 +        return methodName;
 470.133 +    }
 470.134 +
 470.135 +    /**
 470.136 +     * Returns true if the method containing the execution point
 470.137 +     * represented by this stack trace element is a native method.
 470.138 +     *
 470.139 +     * @return {@code true} if the method containing the execution point
 470.140 +     *         represented by this stack trace element is a native method.
 470.141 +     */
 470.142 +    public boolean isNativeMethod() {
 470.143 +        return lineNumber == -2;
 470.144 +    }
 470.145 +
 470.146 +    /**
 470.147 +     * Returns a string representation of this stack trace element.  The
 470.148 +     * format of this string depends on the implementation, but the following
 470.149 +     * examples may be regarded as typical:
 470.150 +     * <ul>
 470.151 +     * <li>
 470.152 +     *   {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
 470.153 +     *   is the <i>fully-qualified name</i> of the class containing the
 470.154 +     *   execution point represented by this stack trace element,
 470.155 +     *   {@code "mash"} is the name of the method containing the execution
 470.156 +     *   point, {@code "MyClass.java"} is the source file containing the
 470.157 +     *   execution point, and {@code "9"} is the line number of the source
 470.158 +     *   line containing the execution point.
 470.159 +     * <li>
 470.160 +     *   {@code "MyClass.mash(MyClass.java)"} - As above, but the line
 470.161 +     *   number is unavailable.
 470.162 +     * <li>
 470.163 +     *   {@code "MyClass.mash(Unknown Source)"} - As above, but neither
 470.164 +     *   the file name nor the line  number are available.
 470.165 +     * <li>
 470.166 +     *   {@code "MyClass.mash(Native Method)"} - As above, but neither
 470.167 +     *   the file name nor the line  number are available, and the method
 470.168 +     *   containing the execution point is known to be a native method.
 470.169 +     * </ul>
 470.170 +     * @see    Throwable#printStackTrace()
 470.171 +     */
 470.172 +    public String toString() {
 470.173 +        return getClassName() + "." + methodName +
 470.174 +            (isNativeMethod() ? "(Native Method)" :
 470.175 +             (fileName != null && lineNumber >= 0 ?
 470.176 +              "(" + fileName + ":" + lineNumber + ")" :
 470.177 +              (fileName != null ?  "("+fileName+")" : "(Unknown Source)")));
 470.178 +    }
 470.179 +
 470.180 +    /**
 470.181 +     * Returns true if the specified object is another
 470.182 +     * {@code StackTraceElement} instance representing the same execution
 470.183 +     * point as this instance.  Two stack trace elements {@code a} and
 470.184 +     * {@code b} are equal if and only if:
 470.185 +     * <pre>
 470.186 +     *     equals(a.getFileName(), b.getFileName()) &&
 470.187 +     *     a.getLineNumber() == b.getLineNumber()) &&
 470.188 +     *     equals(a.getClassName(), b.getClassName()) &&
 470.189 +     *     equals(a.getMethodName(), b.getMethodName())
 470.190 +     * </pre>
 470.191 +     * where {@code equals} has the semantics of {@link
 470.192 +     * java.util.Objects#equals(Object, Object) Objects.equals}.
 470.193 +     *
 470.194 +     * @param  obj the object to be compared with this stack trace element.
 470.195 +     * @return true if the specified object is another
 470.196 +     *         {@code StackTraceElement} instance representing the same
 470.197 +     *         execution point as this instance.
 470.198 +     */
 470.199 +    public boolean equals(Object obj) {
 470.200 +        if (obj==this)
 470.201 +            return true;
 470.202 +        if (!(obj instanceof StackTraceElement))
 470.203 +            return false;
 470.204 +        StackTraceElement e = (StackTraceElement)obj;
 470.205 +        return e.declaringClass.equals(declaringClass) &&
 470.206 +            e.lineNumber == lineNumber &&
 470.207 +            equals(methodName, e.methodName) &&
 470.208 +            equals(fileName, e.fileName);
 470.209 +    }
 470.210 +
 470.211 +    /**
 470.212 +     * Returns a hash code value for this stack trace element.
 470.213 +     */
 470.214 +    public int hashCode() {
 470.215 +        int result = 31*declaringClass.hashCode() + methodName.hashCode();
 470.216 +        result = 31*result + (fileName == null ? 0 : fileName.hashCode());
 470.217 +        result = 31*result + lineNumber;
 470.218 +        return result;
 470.219 +    }
 470.220 +    
 470.221 +    private static boolean equals(Object a, Object b) {
 470.222 +        return (a == b) || (a != null && a.equals(b));
 470.223 +    }
 470.224 +
 470.225 +    private static final long serialVersionUID = 6992337162326171013L;
 470.226 +}
   471.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   471.2 +++ b/rt/emul/mini/src/main/java/java/lang/String.java	Wed Feb 27 11:24:58 2013 +0100
   471.3 @@ -0,0 +1,3079 @@
   471.4 +/*
   471.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   471.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   471.7 + *
   471.8 + * This code is free software; you can redistribute it and/or modify it
   471.9 + * under the terms of the GNU General Public License version 2 only, as
  471.10 + * published by the Free Software Foundation.  Oracle designates this
  471.11 + * particular file as subject to the "Classpath" exception as provided
  471.12 + * by Oracle in the LICENSE file that accompanied this code.
  471.13 + *
  471.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  471.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  471.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  471.17 + * version 2 for more details (a copy is included in the LICENSE file that
  471.18 + * accompanied this code).
  471.19 + *
  471.20 + * You should have received a copy of the GNU General Public License version
  471.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  471.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  471.23 + *
  471.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  471.25 + * or visit www.oracle.com if you need additional information or have any
  471.26 + * questions.
  471.27 + */
  471.28 +
  471.29 +package java.lang;
  471.30 +
  471.31 +import java.io.UnsupportedEncodingException;
  471.32 +import java.util.Comparator;
  471.33 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  471.34 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  471.35 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  471.36 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  471.37 +import org.apidesign.bck2brwsr.emul.lang.System;
  471.38 +
  471.39 +/**
  471.40 + * The <code>String</code> class represents character strings. All
  471.41 + * string literals in Java programs, such as <code>"abc"</code>, are
  471.42 + * implemented as instances of this class.
  471.43 + * <p>
  471.44 + * Strings are constant; their values cannot be changed after they
  471.45 + * are created. String buffers support mutable strings.
  471.46 + * Because String objects are immutable they can be shared. For example:
  471.47 + * <p><blockquote><pre>
  471.48 + *     String str = "abc";
  471.49 + * </pre></blockquote><p>
  471.50 + * is equivalent to:
  471.51 + * <p><blockquote><pre>
  471.52 + *     char data[] = {'a', 'b', 'c'};
  471.53 + *     String str = new String(data);
  471.54 + * </pre></blockquote><p>
  471.55 + * Here are some more examples of how strings can be used:
  471.56 + * <p><blockquote><pre>
  471.57 + *     System.out.println("abc");
  471.58 + *     String cde = "cde";
  471.59 + *     System.out.println("abc" + cde);
  471.60 + *     String c = "abc".substring(2,3);
  471.61 + *     String d = cde.substring(1, 2);
  471.62 + * </pre></blockquote>
  471.63 + * <p>
  471.64 + * The class <code>String</code> includes methods for examining
  471.65 + * individual characters of the sequence, for comparing strings, for
  471.66 + * searching strings, for extracting substrings, and for creating a
  471.67 + * copy of a string with all characters translated to uppercase or to
  471.68 + * lowercase. Case mapping is based on the Unicode Standard version
  471.69 + * specified by the {@link java.lang.Character Character} class.
  471.70 + * <p>
  471.71 + * The Java language provides special support for the string
  471.72 + * concatenation operator (&nbsp;+&nbsp;), and for conversion of
  471.73 + * other objects to strings. String concatenation is implemented
  471.74 + * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
  471.75 + * class and its <code>append</code> method.
  471.76 + * String conversions are implemented through the method
  471.77 + * <code>toString</code>, defined by <code>Object</code> and
  471.78 + * inherited by all classes in Java. For additional information on
  471.79 + * string concatenation and conversion, see Gosling, Joy, and Steele,
  471.80 + * <i>The Java Language Specification</i>.
  471.81 + *
  471.82 + * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
  471.83 + * or method in this class will cause a {@link NullPointerException} to be
  471.84 + * thrown.
  471.85 + *
  471.86 + * <p>A <code>String</code> represents a string in the UTF-16 format
  471.87 + * in which <em>supplementary characters</em> are represented by <em>surrogate
  471.88 + * pairs</em> (see the section <a href="Character.html#unicode">Unicode
  471.89 + * Character Representations</a> in the <code>Character</code> class for
  471.90 + * more information).
  471.91 + * Index values refer to <code>char</code> code units, so a supplementary
  471.92 + * character uses two positions in a <code>String</code>.
  471.93 + * <p>The <code>String</code> class provides methods for dealing with
  471.94 + * Unicode code points (i.e., characters), in addition to those for
  471.95 + * dealing with Unicode code units (i.e., <code>char</code> values).
  471.96 + *
  471.97 + * @author  Lee Boynton
  471.98 + * @author  Arthur van Hoff
  471.99 + * @author  Martin Buchholz
 471.100 + * @author  Ulf Zibis
 471.101 + * @see     java.lang.Object#toString()
 471.102 + * @see     java.lang.StringBuffer
 471.103 + * @see     java.lang.StringBuilder
 471.104 + * @see     java.nio.charset.Charset
 471.105 + * @since   JDK1.0
 471.106 + */
 471.107 +
 471.108 +@ExtraJavaScript(
 471.109 +    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js",
 471.110 +    processByteCode=true
 471.111 +)
 471.112 +@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
 471.113 +public final class String
 471.114 +    implements java.io.Serializable, Comparable<String>, CharSequence
 471.115 +{
 471.116 +    /** real string to delegate to */
 471.117 +    private Object r;
 471.118 +
 471.119 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 471.120 +    private static final long serialVersionUID = -6849794470754667710L;
 471.121 +    
 471.122 +    @JavaScriptOnly(name="toString", value="String.prototype._r")
 471.123 +    private static void jsToString() {
 471.124 +    }
 471.125 +    
 471.126 +    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 471.127 +    private static void jsValudOf() {
 471.128 +    }
 471.129 +
 471.130 +    /**
 471.131 +     * Class String is special cased within the Serialization Stream Protocol.
 471.132 +     *
 471.133 +     * A String instance is written initially into an ObjectOutputStream in the
 471.134 +     * following format:
 471.135 +     * <pre>
 471.136 +     *      <code>TC_STRING</code> (utf String)
 471.137 +     * </pre>
 471.138 +     * The String is written by method <code>DataOutput.writeUTF</code>.
 471.139 +     * A new handle is generated to  refer to all future references to the
 471.140 +     * string instance within the stream.
 471.141 +     */
 471.142 +//    private static final ObjectStreamField[] serialPersistentFields =
 471.143 +//        new ObjectStreamField[0];
 471.144 +
 471.145 +    /**
 471.146 +     * Initializes a newly created {@code String} object so that it represents
 471.147 +     * an empty character sequence.  Note that use of this constructor is
 471.148 +     * unnecessary since Strings are immutable.
 471.149 +     */
 471.150 +    public String() {
 471.151 +        this.r = "";
 471.152 +    }
 471.153 +
 471.154 +    /**
 471.155 +     * Initializes a newly created {@code String} object so that it represents
 471.156 +     * the same sequence of characters as the argument; in other words, the
 471.157 +     * newly created string is a copy of the argument string. Unless an
 471.158 +     * explicit copy of {@code original} is needed, use of this constructor is
 471.159 +     * unnecessary since Strings are immutable.
 471.160 +     *
 471.161 +     * @param  original
 471.162 +     *         A {@code String}
 471.163 +     */
 471.164 +    public String(String original) {
 471.165 +        this.r = original.toString();
 471.166 +    }
 471.167 +
 471.168 +    /**
 471.169 +     * Allocates a new {@code String} so that it represents the sequence of
 471.170 +     * characters currently contained in the character array argument. The
 471.171 +     * contents of the character array are copied; subsequent modification of
 471.172 +     * the character array does not affect the newly created string.
 471.173 +     *
 471.174 +     * @param  value
 471.175 +     *         The initial value of the string
 471.176 +     */
 471.177 +    @JavaScriptBody(args = { "charArr" }, body=
 471.178 +        "for (var i = 0; i < charArr.length; i++) {\n"
 471.179 +      + "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
 471.180 +      + "}\n"
 471.181 +      + "this._r(charArr.join(''));\n"
 471.182 +    )
 471.183 +    public String(char value[]) {
 471.184 +    }
 471.185 +
 471.186 +    /**
 471.187 +     * Allocates a new {@code String} that contains characters from a subarray
 471.188 +     * of the character array argument. The {@code offset} argument is the
 471.189 +     * index of the first character of the subarray and the {@code count}
 471.190 +     * argument specifies the length of the subarray. The contents of the
 471.191 +     * subarray are copied; subsequent modification of the character array does
 471.192 +     * not affect the newly created string.
 471.193 +     *
 471.194 +     * @param  value
 471.195 +     *         Array that is the source of characters
 471.196 +     *
 471.197 +     * @param  offset
 471.198 +     *         The initial offset
 471.199 +     *
 471.200 +     * @param  count
 471.201 +     *         The length
 471.202 +     *
 471.203 +     * @throws  IndexOutOfBoundsException
 471.204 +     *          If the {@code offset} and {@code count} arguments index
 471.205 +     *          characters outside the bounds of the {@code value} array
 471.206 +     */
 471.207 +    public String(char value[], int offset, int count) {
 471.208 +        initFromCharArray(value, offset, count);
 471.209 +    }
 471.210 +    
 471.211 +    @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
 471.212 +        "var up = off + cnt;\n" +
 471.213 +        "for (var i = off; i < up; i++) {\n" +
 471.214 +        "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
 471.215 +        "}\n" +
 471.216 +        "this._r(charArr.slice(off, up).join(\"\"));\n"
 471.217 +    )
 471.218 +    private native void initFromCharArray(char value[], int offset, int count);
 471.219 +
 471.220 +    /**
 471.221 +     * Allocates a new {@code String} that contains characters from a subarray
 471.222 +     * of the <a href="Character.html#unicode">Unicode code point</a> array
 471.223 +     * argument.  The {@code offset} argument is the index of the first code
 471.224 +     * point of the subarray and the {@code count} argument specifies the
 471.225 +     * length of the subarray.  The contents of the subarray are converted to
 471.226 +     * {@code char}s; subsequent modification of the {@code int} array does not
 471.227 +     * affect the newly created string.
 471.228 +     *
 471.229 +     * @param  codePoints
 471.230 +     *         Array that is the source of Unicode code points
 471.231 +     *
 471.232 +     * @param  offset
 471.233 +     *         The initial offset
 471.234 +     *
 471.235 +     * @param  count
 471.236 +     *         The length
 471.237 +     *
 471.238 +     * @throws  IllegalArgumentException
 471.239 +     *          If any invalid Unicode code point is found in {@code
 471.240 +     *          codePoints}
 471.241 +     *
 471.242 +     * @throws  IndexOutOfBoundsException
 471.243 +     *          If the {@code offset} and {@code count} arguments index
 471.244 +     *          characters outside the bounds of the {@code codePoints} array
 471.245 +     *
 471.246 +     * @since  1.5
 471.247 +     */
 471.248 +    public String(int[] codePoints, int offset, int count) {
 471.249 +        if (offset < 0) {
 471.250 +            throw new StringIndexOutOfBoundsException(offset);
 471.251 +        }
 471.252 +        if (count < 0) {
 471.253 +            throw new StringIndexOutOfBoundsException(count);
 471.254 +        }
 471.255 +        // Note: offset or count might be near -1>>>1.
 471.256 +        if (offset > codePoints.length - count) {
 471.257 +            throw new StringIndexOutOfBoundsException(offset + count);
 471.258 +        }
 471.259 +
 471.260 +        final int end = offset + count;
 471.261 +
 471.262 +        // Pass 1: Compute precise size of char[]
 471.263 +        int n = count;
 471.264 +        for (int i = offset; i < end; i++) {
 471.265 +            int c = codePoints[i];
 471.266 +            if (Character.isBmpCodePoint(c))
 471.267 +                continue;
 471.268 +            else if (Character.isValidCodePoint(c))
 471.269 +                n++;
 471.270 +            else throw new IllegalArgumentException(Integer.toString(c));
 471.271 +        }
 471.272 +
 471.273 +        // Pass 2: Allocate and fill in char[]
 471.274 +        final char[] v = new char[n];
 471.275 +
 471.276 +        for (int i = offset, j = 0; i < end; i++, j++) {
 471.277 +            int c = codePoints[i];
 471.278 +            if (Character.isBmpCodePoint(c))
 471.279 +                v[j] = (char) c;
 471.280 +            else
 471.281 +                Character.toSurrogates(c, v, j++);
 471.282 +        }
 471.283 +
 471.284 +        this.r = new String(v, 0, n);
 471.285 +    }
 471.286 +
 471.287 +    /**
 471.288 +     * Allocates a new {@code String} constructed from a subarray of an array
 471.289 +     * of 8-bit integer values.
 471.290 +     *
 471.291 +     * <p> The {@code offset} argument is the index of the first byte of the
 471.292 +     * subarray, and the {@code count} argument specifies the length of the
 471.293 +     * subarray.
 471.294 +     *
 471.295 +     * <p> Each {@code byte} in the subarray is converted to a {@code char} as
 471.296 +     * specified in the method above.
 471.297 +     *
 471.298 +     * @deprecated This method does not properly convert bytes into characters.
 471.299 +     * As of JDK&nbsp;1.1, the preferred way to do this is via the
 471.300 +     * {@code String} constructors that take a {@link
 471.301 +     * java.nio.charset.Charset}, charset name, or that use the platform's
 471.302 +     * default charset.
 471.303 +     *
 471.304 +     * @param  ascii
 471.305 +     *         The bytes to be converted to characters
 471.306 +     *
 471.307 +     * @param  hibyte
 471.308 +     *         The top 8 bits of each 16-bit Unicode code unit
 471.309 +     *
 471.310 +     * @param  offset
 471.311 +     *         The initial offset
 471.312 +     * @param  count
 471.313 +     *         The length
 471.314 +     *
 471.315 +     * @throws  IndexOutOfBoundsException
 471.316 +     *          If the {@code offset} or {@code count} argument is invalid
 471.317 +     *
 471.318 +     * @see  #String(byte[], int)
 471.319 +     * @see  #String(byte[], int, int, java.lang.String)
 471.320 +     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 471.321 +     * @see  #String(byte[], int, int)
 471.322 +     * @see  #String(byte[], java.lang.String)
 471.323 +     * @see  #String(byte[], java.nio.charset.Charset)
 471.324 +     * @see  #String(byte[])
 471.325 +     */
 471.326 +    @Deprecated
 471.327 +    public String(byte ascii[], int hibyte, int offset, int count) {
 471.328 +        checkBounds(ascii, offset, count);
 471.329 +        char value[] = new char[count];
 471.330 +
 471.331 +        if (hibyte == 0) {
 471.332 +            for (int i = count ; i-- > 0 ;) {
 471.333 +                value[i] = (char) (ascii[i + offset] & 0xff);
 471.334 +            }
 471.335 +        } else {
 471.336 +            hibyte <<= 8;
 471.337 +            for (int i = count ; i-- > 0 ;) {
 471.338 +                value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
 471.339 +            }
 471.340 +        }
 471.341 +        initFromCharArray(value, offset, count);
 471.342 +    }
 471.343 +
 471.344 +    /**
 471.345 +     * Allocates a new {@code String} containing characters constructed from
 471.346 +     * an array of 8-bit integer values. Each character <i>c</i>in the
 471.347 +     * resulting string is constructed from the corresponding component
 471.348 +     * <i>b</i> in the byte array such that:
 471.349 +     *
 471.350 +     * <blockquote><pre>
 471.351 +     *     <b><i>c</i></b> == (char)(((hibyte &amp; 0xff) &lt;&lt; 8)
 471.352 +     *                         | (<b><i>b</i></b> &amp; 0xff))
 471.353 +     * </pre></blockquote>
 471.354 +     *
 471.355 +     * @deprecated  This method does not properly convert bytes into
 471.356 +     * characters.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 471.357 +     * {@code String} constructors that take a {@link
 471.358 +     * java.nio.charset.Charset}, charset name, or that use the platform's
 471.359 +     * default charset.
 471.360 +     *
 471.361 +     * @param  ascii
 471.362 +     *         The bytes to be converted to characters
 471.363 +     *
 471.364 +     * @param  hibyte
 471.365 +     *         The top 8 bits of each 16-bit Unicode code unit
 471.366 +     *
 471.367 +     * @see  #String(byte[], int, int, java.lang.String)
 471.368 +     * @see  #String(byte[], int, int, java.nio.charset.Charset)
 471.369 +     * @see  #String(byte[], int, int)
 471.370 +     * @see  #String(byte[], java.lang.String)
 471.371 +     * @see  #String(byte[], java.nio.charset.Charset)
 471.372 +     * @see  #String(byte[])
 471.373 +     */
 471.374 +    @Deprecated
 471.375 +    public String(byte ascii[], int hibyte) {
 471.376 +        this(ascii, hibyte, 0, ascii.length);
 471.377 +    }
 471.378 +
 471.379 +    /* Common private utility method used to bounds check the byte array
 471.380 +     * and requested offset & length values used by the String(byte[],..)
 471.381 +     * constructors.
 471.382 +     */
 471.383 +    private static void checkBounds(byte[] bytes, int offset, int length) {
 471.384 +        if (length < 0)
 471.385 +            throw new StringIndexOutOfBoundsException(length);
 471.386 +        if (offset < 0)
 471.387 +            throw new StringIndexOutOfBoundsException(offset);
 471.388 +        if (offset > bytes.length - length)
 471.389 +            throw new StringIndexOutOfBoundsException(offset + length);
 471.390 +    }
 471.391 +
 471.392 +    /**
 471.393 +     * Constructs a new {@code String} by decoding the specified subarray of
 471.394 +     * bytes using the specified charset.  The length of the new {@code String}
 471.395 +     * is a function of the charset, and hence may not be equal to the length
 471.396 +     * of the subarray.
 471.397 +     *
 471.398 +     * <p> The behavior of this constructor when the given bytes are not valid
 471.399 +     * in the given charset is unspecified.  The {@link
 471.400 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 471.401 +     * over the decoding process is required.
 471.402 +     *
 471.403 +     * @param  bytes
 471.404 +     *         The bytes to be decoded into characters
 471.405 +     *
 471.406 +     * @param  offset
 471.407 +     *         The index of the first byte to decode
 471.408 +     *
 471.409 +     * @param  length
 471.410 +     *         The number of bytes to decode
 471.411 +
 471.412 +     * @param  charsetName
 471.413 +     *         The name of a supported {@linkplain java.nio.charset.Charset
 471.414 +     *         charset}
 471.415 +     *
 471.416 +     * @throws  UnsupportedEncodingException
 471.417 +     *          If the named charset is not supported
 471.418 +     *
 471.419 +     * @throws  IndexOutOfBoundsException
 471.420 +     *          If the {@code offset} and {@code length} arguments index
 471.421 +     *          characters outside the bounds of the {@code bytes} array
 471.422 +     *
 471.423 +     * @since  JDK1.1
 471.424 +     */
 471.425 +    public String(byte bytes[], int offset, int length, String charsetName)
 471.426 +        throws UnsupportedEncodingException
 471.427 +    {
 471.428 +        this(checkUTF8(bytes, charsetName), offset, length);
 471.429 +    }
 471.430 +
 471.431 +    /**
 471.432 +     * Constructs a new {@code String} by decoding the specified subarray of
 471.433 +     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 471.434 +     * The length of the new {@code String} is a function of the charset, and
 471.435 +     * hence may not be equal to the length of the subarray.
 471.436 +     *
 471.437 +     * <p> This method always replaces malformed-input and unmappable-character
 471.438 +     * sequences with this charset's default replacement string.  The {@link
 471.439 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 471.440 +     * over the decoding process is required.
 471.441 +     *
 471.442 +     * @param  bytes
 471.443 +     *         The bytes to be decoded into characters
 471.444 +     *
 471.445 +     * @param  offset
 471.446 +     *         The index of the first byte to decode
 471.447 +     *
 471.448 +     * @param  length
 471.449 +     *         The number of bytes to decode
 471.450 +     *
 471.451 +     * @param  charset
 471.452 +     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 471.453 +     *         decode the {@code bytes}
 471.454 +     *
 471.455 +     * @throws  IndexOutOfBoundsException
 471.456 +     *          If the {@code offset} and {@code length} arguments index
 471.457 +     *          characters outside the bounds of the {@code bytes} array
 471.458 +     *
 471.459 +     * @since  1.6
 471.460 +     */
 471.461 +    /* don't want dependnecy on Charset
 471.462 +    public String(byte bytes[], int offset, int length, Charset charset) {
 471.463 +        if (charset == null)
 471.464 +            throw new NullPointerException("charset");
 471.465 +        checkBounds(bytes, offset, length);
 471.466 +        char[] v = StringCoding.decode(charset, bytes, offset, length);
 471.467 +        this.offset = 0;
 471.468 +        this.count = v.length;
 471.469 +        this.value = v;
 471.470 +    }
 471.471 +    */
 471.472 +
 471.473 +    /**
 471.474 +     * Constructs a new {@code String} by decoding the specified array of bytes
 471.475 +     * using the specified {@linkplain java.nio.charset.Charset charset}.  The
 471.476 +     * length of the new {@code String} is a function of the charset, and hence
 471.477 +     * may not be equal to the length of the byte array.
 471.478 +     *
 471.479 +     * <p> The behavior of this constructor when the given bytes are not valid
 471.480 +     * in the given charset is unspecified.  The {@link
 471.481 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 471.482 +     * over the decoding process is required.
 471.483 +     *
 471.484 +     * @param  bytes
 471.485 +     *         The bytes to be decoded into characters
 471.486 +     *
 471.487 +     * @param  charsetName
 471.488 +     *         The name of a supported {@linkplain java.nio.charset.Charset
 471.489 +     *         charset}
 471.490 +     *
 471.491 +     * @throws  UnsupportedEncodingException
 471.492 +     *          If the named charset is not supported
 471.493 +     *
 471.494 +     * @since  JDK1.1
 471.495 +     */
 471.496 +    public String(byte bytes[], String charsetName)
 471.497 +        throws UnsupportedEncodingException
 471.498 +    {
 471.499 +        this(bytes, 0, bytes.length, charsetName);
 471.500 +    }
 471.501 +
 471.502 +    /**
 471.503 +     * Constructs a new {@code String} by decoding the specified array of
 471.504 +     * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
 471.505 +     * The length of the new {@code String} is a function of the charset, and
 471.506 +     * hence may not be equal to the length of the byte array.
 471.507 +     *
 471.508 +     * <p> This method always replaces malformed-input and unmappable-character
 471.509 +     * sequences with this charset's default replacement string.  The {@link
 471.510 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 471.511 +     * over the decoding process is required.
 471.512 +     *
 471.513 +     * @param  bytes
 471.514 +     *         The bytes to be decoded into characters
 471.515 +     *
 471.516 +     * @param  charset
 471.517 +     *         The {@linkplain java.nio.charset.Charset charset} to be used to
 471.518 +     *         decode the {@code bytes}
 471.519 +     *
 471.520 +     * @since  1.6
 471.521 +     */
 471.522 +    /* don't want dep on Charset
 471.523 +    public String(byte bytes[], Charset charset) {
 471.524 +        this(bytes, 0, bytes.length, charset);
 471.525 +    }
 471.526 +    */
 471.527 +
 471.528 +    /**
 471.529 +     * Constructs a new {@code String} by decoding the specified subarray of
 471.530 +     * bytes using the platform's default charset.  The length of the new
 471.531 +     * {@code String} is a function of the charset, and hence may not be equal
 471.532 +     * to the length of the subarray.
 471.533 +     *
 471.534 +     * <p> The behavior of this constructor when the given bytes are not valid
 471.535 +     * in the default charset is unspecified.  The {@link
 471.536 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 471.537 +     * over the decoding process is required.
 471.538 +     *
 471.539 +     * @param  bytes
 471.540 +     *         The bytes to be decoded into characters
 471.541 +     *
 471.542 +     * @param  offset
 471.543 +     *         The index of the first byte to decode
 471.544 +     *
 471.545 +     * @param  length
 471.546 +     *         The number of bytes to decode
 471.547 +     *
 471.548 +     * @throws  IndexOutOfBoundsException
 471.549 +     *          If the {@code offset} and the {@code length} arguments index
 471.550 +     *          characters outside the bounds of the {@code bytes} array
 471.551 +     *
 471.552 +     * @since  JDK1.1
 471.553 +     */
 471.554 +    public String(byte bytes[], int offset, int length) {
 471.555 +        checkBounds(bytes, offset, length);
 471.556 +        char[] v  = new char[length];
 471.557 +        int[] at = { offset };
 471.558 +        int end = offset + length;
 471.559 +        int chlen = 0;
 471.560 +        while (at[0] < end) {
 471.561 +            int ch = nextChar(bytes, at);
 471.562 +            v[chlen++] = (char)ch;
 471.563 +        }
 471.564 +        initFromCharArray(v, 0, chlen);
 471.565 +    }
 471.566 +
 471.567 +    /**
 471.568 +     * Constructs a new {@code String} by decoding the specified array of bytes
 471.569 +     * using the platform's default charset.  The length of the new {@code
 471.570 +     * String} is a function of the charset, and hence may not be equal to the
 471.571 +     * length of the byte array.
 471.572 +     *
 471.573 +     * <p> The behavior of this constructor when the given bytes are not valid
 471.574 +     * in the default charset is unspecified.  The {@link
 471.575 +     * java.nio.charset.CharsetDecoder} class should be used when more control
 471.576 +     * over the decoding process is required.
 471.577 +     *
 471.578 +     * @param  bytes
 471.579 +     *         The bytes to be decoded into characters
 471.580 +     *
 471.581 +     * @since  JDK1.1
 471.582 +     */
 471.583 +    public String(byte bytes[]) {
 471.584 +        this(bytes, 0, bytes.length);
 471.585 +    }
 471.586 +
 471.587 +    /**
 471.588 +     * Allocates a new string that contains the sequence of characters
 471.589 +     * currently contained in the string buffer argument. The contents of the
 471.590 +     * string buffer are copied; subsequent modification of the string buffer
 471.591 +     * does not affect the newly created string.
 471.592 +     *
 471.593 +     * @param  buffer
 471.594 +     *         A {@code StringBuffer}
 471.595 +     */
 471.596 +    public String(StringBuffer buffer) {
 471.597 +        this.r = buffer.toString();
 471.598 +    }
 471.599 +
 471.600 +    /**
 471.601 +     * Allocates a new string that contains the sequence of characters
 471.602 +     * currently contained in the string builder argument. The contents of the
 471.603 +     * string builder are copied; subsequent modification of the string builder
 471.604 +     * does not affect the newly created string.
 471.605 +     *
 471.606 +     * <p> This constructor is provided to ease migration to {@code
 471.607 +     * StringBuilder}. Obtaining a string from a string builder via the {@code
 471.608 +     * toString} method is likely to run faster and is generally preferred.
 471.609 +     *
 471.610 +     * @param   builder
 471.611 +     *          A {@code StringBuilder}
 471.612 +     *
 471.613 +     * @since  1.5
 471.614 +     */
 471.615 +    public String(StringBuilder builder) {
 471.616 +        this.r = builder.toString();
 471.617 +    }
 471.618 +
 471.619 +    /**
 471.620 +     * Returns the length of this string.
 471.621 +     * The length is equal to the number of <a href="Character.html#unicode">Unicode
 471.622 +     * code units</a> in the string.
 471.623 +     *
 471.624 +     * @return  the length of the sequence of characters represented by this
 471.625 +     *          object.
 471.626 +     */
 471.627 +    @JavaScriptBody(args = {}, body = "return this.toString().length;")
 471.628 +    public int length() {
 471.629 +        throw new UnsupportedOperationException();
 471.630 +    }
 471.631 +
 471.632 +    /**
 471.633 +     * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
 471.634 +     *
 471.635 +     * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
 471.636 +     * <tt>false</tt>
 471.637 +     *
 471.638 +     * @since 1.6
 471.639 +     */
 471.640 +    @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
 471.641 +    public boolean isEmpty() {
 471.642 +        return length() == 0;
 471.643 +    }
 471.644 +
 471.645 +    /**
 471.646 +     * Returns the <code>char</code> value at the
 471.647 +     * specified index. An index ranges from <code>0</code> to
 471.648 +     * <code>length() - 1</code>. The first <code>char</code> value of the sequence
 471.649 +     * is at index <code>0</code>, the next at index <code>1</code>,
 471.650 +     * and so on, as for array indexing.
 471.651 +     *
 471.652 +     * <p>If the <code>char</code> value specified by the index is a
 471.653 +     * <a href="Character.html#unicode">surrogate</a>, the surrogate
 471.654 +     * value is returned.
 471.655 +     *
 471.656 +     * @param      index   the index of the <code>char</code> value.
 471.657 +     * @return     the <code>char</code> value at the specified index of this string.
 471.658 +     *             The first <code>char</code> value is at index <code>0</code>.
 471.659 +     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 471.660 +     *             argument is negative or not less than the length of this
 471.661 +     *             string.
 471.662 +     */
 471.663 +    @JavaScriptBody(args = { "index" }, 
 471.664 +        body = "return this.toString().charCodeAt(index);"
 471.665 +    )
 471.666 +    public char charAt(int index) {
 471.667 +        throw new UnsupportedOperationException();
 471.668 +    }
 471.669 +
 471.670 +    /**
 471.671 +     * Returns the character (Unicode code point) at the specified
 471.672 +     * index. The index refers to <code>char</code> values
 471.673 +     * (Unicode code units) and ranges from <code>0</code> to
 471.674 +     * {@link #length()}<code> - 1</code>.
 471.675 +     *
 471.676 +     * <p> If the <code>char</code> value specified at the given index
 471.677 +     * is in the high-surrogate range, the following index is less
 471.678 +     * than the length of this <code>String</code>, and the
 471.679 +     * <code>char</code> value at the following index is in the
 471.680 +     * low-surrogate range, then the supplementary code point
 471.681 +     * corresponding to this surrogate pair is returned. Otherwise,
 471.682 +     * the <code>char</code> value at the given index is returned.
 471.683 +     *
 471.684 +     * @param      index the index to the <code>char</code> values
 471.685 +     * @return     the code point value of the character at the
 471.686 +     *             <code>index</code>
 471.687 +     * @exception  IndexOutOfBoundsException  if the <code>index</code>
 471.688 +     *             argument is negative or not less than the length of this
 471.689 +     *             string.
 471.690 +     * @since      1.5
 471.691 +     */
 471.692 +    public int codePointAt(int index) {
 471.693 +        if ((index < 0) || (index >= length())) {
 471.694 +            throw new StringIndexOutOfBoundsException(index);
 471.695 +        }
 471.696 +        return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
 471.697 +    }
 471.698 +
 471.699 +    /**
 471.700 +     * Returns the character (Unicode code point) before the specified
 471.701 +     * index. The index refers to <code>char</code> values
 471.702 +     * (Unicode code units) and ranges from <code>1</code> to {@link
 471.703 +     * CharSequence#length() length}.
 471.704 +     *
 471.705 +     * <p> If the <code>char</code> value at <code>(index - 1)</code>
 471.706 +     * is in the low-surrogate range, <code>(index - 2)</code> is not
 471.707 +     * negative, and the <code>char</code> value at <code>(index -
 471.708 +     * 2)</code> is in the high-surrogate range, then the
 471.709 +     * supplementary code point value of the surrogate pair is
 471.710 +     * returned. If the <code>char</code> value at <code>index -
 471.711 +     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
 471.712 +     * surrogate value is returned.
 471.713 +     *
 471.714 +     * @param     index the index following the code point that should be returned
 471.715 +     * @return    the Unicode code point value before the given index.
 471.716 +     * @exception IndexOutOfBoundsException if the <code>index</code>
 471.717 +     *            argument is less than 1 or greater than the length
 471.718 +     *            of this string.
 471.719 +     * @since     1.5
 471.720 +     */
 471.721 +    public int codePointBefore(int index) {
 471.722 +        int i = index - 1;
 471.723 +        if ((i < 0) || (i >= length())) {
 471.724 +            throw new StringIndexOutOfBoundsException(index);
 471.725 +        }
 471.726 +        return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
 471.727 +    }
 471.728 +
 471.729 +    /**
 471.730 +     * Returns the number of Unicode code points in the specified text
 471.731 +     * range of this <code>String</code>. The text range begins at the
 471.732 +     * specified <code>beginIndex</code> and extends to the
 471.733 +     * <code>char</code> at index <code>endIndex - 1</code>. Thus the
 471.734 +     * length (in <code>char</code>s) of the text range is
 471.735 +     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
 471.736 +     * the text range count as one code point each.
 471.737 +     *
 471.738 +     * @param beginIndex the index to the first <code>char</code> of
 471.739 +     * the text range.
 471.740 +     * @param endIndex the index after the last <code>char</code> of
 471.741 +     * the text range.
 471.742 +     * @return the number of Unicode code points in the specified text
 471.743 +     * range
 471.744 +     * @exception IndexOutOfBoundsException if the
 471.745 +     * <code>beginIndex</code> is negative, or <code>endIndex</code>
 471.746 +     * is larger than the length of this <code>String</code>, or
 471.747 +     * <code>beginIndex</code> is larger than <code>endIndex</code>.
 471.748 +     * @since  1.5
 471.749 +     */
 471.750 +    public int codePointCount(int beginIndex, int endIndex) {
 471.751 +        if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
 471.752 +            throw new IndexOutOfBoundsException();
 471.753 +        }
 471.754 +        return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
 471.755 +    }
 471.756 +
 471.757 +    /**
 471.758 +     * Returns the index within this <code>String</code> that is
 471.759 +     * offset from the given <code>index</code> by
 471.760 +     * <code>codePointOffset</code> code points. Unpaired surrogates
 471.761 +     * within the text range given by <code>index</code> and
 471.762 +     * <code>codePointOffset</code> count as one code point each.
 471.763 +     *
 471.764 +     * @param index the index to be offset
 471.765 +     * @param codePointOffset the offset in code points
 471.766 +     * @return the index within this <code>String</code>
 471.767 +     * @exception IndexOutOfBoundsException if <code>index</code>
 471.768 +     *   is negative or larger then the length of this
 471.769 +     *   <code>String</code>, or if <code>codePointOffset</code> is positive
 471.770 +     *   and the substring starting with <code>index</code> has fewer
 471.771 +     *   than <code>codePointOffset</code> code points,
 471.772 +     *   or if <code>codePointOffset</code> is negative and the substring
 471.773 +     *   before <code>index</code> has fewer than the absolute value
 471.774 +     *   of <code>codePointOffset</code> code points.
 471.775 +     * @since 1.5
 471.776 +     */
 471.777 +    public int offsetByCodePoints(int index, int codePointOffset) {
 471.778 +        if (index < 0 || index > length()) {
 471.779 +            throw new IndexOutOfBoundsException();
 471.780 +        }
 471.781 +        return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
 471.782 +                                                offset()+index, codePointOffset) - offset();
 471.783 +    }
 471.784 +
 471.785 +    /**
 471.786 +     * Copy characters from this string into dst starting at dstBegin.
 471.787 +     * This method doesn't perform any range checking.
 471.788 +     */
 471.789 +    @JavaScriptBody(args = { "arr", "to" }, body = 
 471.790 +        "var s = this.toString();\n" +
 471.791 +        "for (var i = 0; i < s.length; i++) {\n" +
 471.792 +        "   arr[to++] = s[i];\n" +
 471.793 +        "}"
 471.794 +    )
 471.795 +    void getChars(char dst[], int dstBegin) {
 471.796 +        System.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
 471.797 +    }
 471.798 +
 471.799 +    /**
 471.800 +     * Copies characters from this string into the destination character
 471.801 +     * array.
 471.802 +     * <p>
 471.803 +     * The first character to be copied is at index <code>srcBegin</code>;
 471.804 +     * the last character to be copied is at index <code>srcEnd-1</code>
 471.805 +     * (thus the total number of characters to be copied is
 471.806 +     * <code>srcEnd-srcBegin</code>). The characters are copied into the
 471.807 +     * subarray of <code>dst</code> starting at index <code>dstBegin</code>
 471.808 +     * and ending at index:
 471.809 +     * <p><blockquote><pre>
 471.810 +     *     dstbegin + (srcEnd-srcBegin) - 1
 471.811 +     * </pre></blockquote>
 471.812 +     *
 471.813 +     * @param      srcBegin   index of the first character in the string
 471.814 +     *                        to copy.
 471.815 +     * @param      srcEnd     index after the last character in the string
 471.816 +     *                        to copy.
 471.817 +     * @param      dst        the destination array.
 471.818 +     * @param      dstBegin   the start offset in the destination array.
 471.819 +     * @exception IndexOutOfBoundsException If any of the following
 471.820 +     *            is true:
 471.821 +     *            <ul><li><code>srcBegin</code> is negative.
 471.822 +     *            <li><code>srcBegin</code> is greater than <code>srcEnd</code>
 471.823 +     *            <li><code>srcEnd</code> is greater than the length of this
 471.824 +     *                string
 471.825 +     *            <li><code>dstBegin</code> is negative
 471.826 +     *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
 471.827 +     *                <code>dst.length</code></ul>
 471.828 +     */
 471.829 +    @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
 471.830 +        "var s = this.toString();\n" +
 471.831 +        "while (beg < end) {\n" +
 471.832 +        "  arr[dst++] = s.charCodeAt(beg++);\n" +
 471.833 +        "}\n"
 471.834 +    )
 471.835 +    public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
 471.836 +        if (srcBegin < 0) {
 471.837 +            throw new StringIndexOutOfBoundsException(srcBegin);
 471.838 +        }
 471.839 +        if (srcEnd > length()) {
 471.840 +            throw new StringIndexOutOfBoundsException(srcEnd);
 471.841 +        }
 471.842 +        if (srcBegin > srcEnd) {
 471.843 +            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 471.844 +        }
 471.845 +        System.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
 471.846 +             srcEnd - srcBegin);
 471.847 +    }
 471.848 +
 471.849 +    /**
 471.850 +     * Copies characters from this string into the destination byte array. Each
 471.851 +     * byte receives the 8 low-order bits of the corresponding character. The
 471.852 +     * eight high-order bits of each character are not copied and do not
 471.853 +     * participate in the transfer in any way.
 471.854 +     *
 471.855 +     * <p> The first character to be copied is at index {@code srcBegin}; the
 471.856 +     * last character to be copied is at index {@code srcEnd-1}.  The total
 471.857 +     * number of characters to be copied is {@code srcEnd-srcBegin}. The
 471.858 +     * characters, converted to bytes, are copied into the subarray of {@code
 471.859 +     * dst} starting at index {@code dstBegin} and ending at index:
 471.860 +     *
 471.861 +     * <blockquote><pre>
 471.862 +     *     dstbegin + (srcEnd-srcBegin) - 1
 471.863 +     * </pre></blockquote>
 471.864 +     *
 471.865 +     * @deprecated  This method does not properly convert characters into
 471.866 +     * bytes.  As of JDK&nbsp;1.1, the preferred way to do this is via the
 471.867 +     * {@link #getBytes()} method, which uses the platform's default charset.
 471.868 +     *
 471.869 +     * @param  srcBegin
 471.870 +     *         Index of the first character in the string to copy
 471.871 +     *
 471.872 +     * @param  srcEnd
 471.873 +     *         Index after the last character in the string to copy
 471.874 +     *
 471.875 +     * @param  dst
 471.876 +     *         The destination array
 471.877 +     *
 471.878 +     * @param  dstBegin
 471.879 +     *         The start offset in the destination array
 471.880 +     *
 471.881 +     * @throws  IndexOutOfBoundsException
 471.882 +     *          If any of the following is true:
 471.883 +     *          <ul>
 471.884 +     *            <li> {@code srcBegin} is negative
 471.885 +     *            <li> {@code srcBegin} is greater than {@code srcEnd}
 471.886 +     *            <li> {@code srcEnd} is greater than the length of this String
 471.887 +     *            <li> {@code dstBegin} is negative
 471.888 +     *            <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
 471.889 +     *                 dst.length}
 471.890 +     *          </ul>
 471.891 +     */
 471.892 +    @Deprecated
 471.893 +    public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
 471.894 +        if (srcBegin < 0) {
 471.895 +            throw new StringIndexOutOfBoundsException(srcBegin);
 471.896 +        }
 471.897 +        if (srcEnd > length()) {
 471.898 +            throw new StringIndexOutOfBoundsException(srcEnd);
 471.899 +        }
 471.900 +        if (srcBegin > srcEnd) {
 471.901 +            throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
 471.902 +        }
 471.903 +        int j = dstBegin;
 471.904 +        int n = offset() + srcEnd;
 471.905 +        int i = offset() + srcBegin;
 471.906 +        char[] val = toCharArray();   /* avoid getfield opcode */
 471.907 +
 471.908 +        while (i < n) {
 471.909 +            dst[j++] = (byte)val[i++];
 471.910 +        }
 471.911 +    }
 471.912 +
 471.913 +    /**
 471.914 +     * Encodes this {@code String} into a sequence of bytes using the named
 471.915 +     * charset, storing the result into a new byte array.
 471.916 +     *
 471.917 +     * <p> The behavior of this method when this string cannot be encoded in
 471.918 +     * the given charset is unspecified.  The {@link
 471.919 +     * java.nio.charset.CharsetEncoder} class should be used when more control
 471.920 +     * over the encoding process is required.
 471.921 +     *
 471.922 +     * @param  charsetName
 471.923 +     *         The name of a supported {@linkplain java.nio.charset.Charset
 471.924 +     *         charset}
 471.925 +     *
 471.926 +     * @return  The resultant byte array
 471.927 +     *
 471.928 +     * @throws  UnsupportedEncodingException
 471.929 +     *          If the named charset is not supported
 471.930 +     *
 471.931 +     * @since  JDK1.1
 471.932 +     */
 471.933 +    public byte[] getBytes(String charsetName)
 471.934 +        throws UnsupportedEncodingException
 471.935 +    {
 471.936 +        checkUTF8(null, charsetName);
 471.937 +        return getBytes();
 471.938 +    }
 471.939 +
 471.940 +    /**
 471.941 +     * Encodes this {@code String} into a sequence of bytes using the given
 471.942 +     * {@linkplain java.nio.charset.Charset charset}, storing the result into a
 471.943 +     * new byte array.
 471.944 +     *
 471.945 +     * <p> This method always replaces malformed-input and unmappable-character
 471.946 +     * sequences with this charset's default replacement byte array.  The
 471.947 +     * {@link java.nio.charset.CharsetEncoder} class should be used when more
 471.948 +     * control over the encoding process is required.
 471.949 +     *
 471.950 +     * @param  charset
 471.951 +     *         The {@linkplain java.nio.charset.Charset} to be used to encode
 471.952 +     *         the {@code String}
 471.953 +     *
 471.954 +     * @return  The resultant byte array
 471.955 +     *
 471.956 +     * @since  1.6
 471.957 +     */
 471.958 +    /* don't want dep on Charset
 471.959 +    public byte[] getBytes(Charset charset) {
 471.960 +        if (charset == null) throw new NullPointerException();
 471.961 +        return StringCoding.encode(charset, value, offset, count);
 471.962 +    }
 471.963 +    */
 471.964 +
 471.965 +    /**
 471.966 +     * Encodes this {@code String} into a sequence of bytes using the
 471.967 +     * platform's default charset, storing the result into a new byte array.
 471.968 +     *
 471.969 +     * <p> The behavior of this method when this string cannot be encoded in
 471.970 +     * the default charset is unspecified.  The {@link
 471.971 +     * java.nio.charset.CharsetEncoder} class should be used when more control
 471.972 +     * over the encoding process is required.
 471.973 +     *
 471.974 +     * @return  The resultant byte array
 471.975 +     *
 471.976 +     * @since      JDK1.1
 471.977 +     */
 471.978 +    public byte[] getBytes() {
 471.979 +        int len = length();
 471.980 +        byte[] arr = new byte[len];
 471.981 +        for (int i = 0, j = 0; j < len; j++) {
 471.982 +            final int v = charAt(j);
 471.983 +            if (v < 128) {
 471.984 +                arr[i++] = (byte) v;
 471.985 +                continue;
 471.986 +            }
 471.987 +            if (v < 0x0800) {
 471.988 +                arr = System.expandArray(arr, i + 1);
 471.989 +                arr[i++] = (byte) (0xC0 | (v >> 6));
 471.990 +                arr[i++] = (byte) (0x80 | (0x3F & v));
 471.991 +                continue;
 471.992 +            }
 471.993 +            arr = System.expandArray(arr, i + 2);
 471.994 +            arr[i++] = (byte) (0xE0 | (v >> 12));
 471.995 +            arr[i++] = (byte) (0x80 | ((v >> 6) & 0x7F));
 471.996 +            arr[i++] = (byte) (0x80 | (0x3F & v));
 471.997 +        }
 471.998 +        return arr;
 471.999 +    }
471.1000 +
471.1001 +    /**
471.1002 +     * Compares this string to the specified object.  The result is {@code
471.1003 +     * true} if and only if the argument is not {@code null} and is a {@code
471.1004 +     * String} object that represents the same sequence of characters as this
471.1005 +     * object.
471.1006 +     *
471.1007 +     * @param  anObject
471.1008 +     *         The object to compare this {@code String} against
471.1009 +     *
471.1010 +     * @return  {@code true} if the given object represents a {@code String}
471.1011 +     *          equivalent to this string, {@code false} otherwise
471.1012 +     *
471.1013 +     * @see  #compareTo(String)
471.1014 +     * @see  #equalsIgnoreCase(String)
471.1015 +     */
471.1016 +    @JavaScriptBody(args = { "obj" }, body = 
471.1017 +        "return obj != null && obj.$instOf_java_lang_String && "
471.1018 +        + "this.toString() === obj.toString();"
471.1019 +    )
471.1020 +    public boolean equals(Object anObject) {
471.1021 +        if (this == anObject) {
471.1022 +            return true;
471.1023 +        }
471.1024 +        if (anObject instanceof String) {
471.1025 +            String anotherString = (String)anObject;
471.1026 +            int n = length();
471.1027 +            if (n == anotherString.length()) {
471.1028 +                char v1[] = toCharArray();
471.1029 +                char v2[] = anotherString.toCharArray();
471.1030 +                int i = offset();
471.1031 +                int j = anotherString.offset();
471.1032 +                while (n-- != 0) {
471.1033 +                    if (v1[i++] != v2[j++])
471.1034 +                        return false;
471.1035 +                }
471.1036 +                return true;
471.1037 +            }
471.1038 +        }
471.1039 +        return false;
471.1040 +    }
471.1041 +
471.1042 +    /**
471.1043 +     * Compares this string to the specified {@code StringBuffer}.  The result
471.1044 +     * is {@code true} if and only if this {@code String} represents the same
471.1045 +     * sequence of characters as the specified {@code StringBuffer}.
471.1046 +     *
471.1047 +     * @param  sb
471.1048 +     *         The {@code StringBuffer} to compare this {@code String} against
471.1049 +     *
471.1050 +     * @return  {@code true} if this {@code String} represents the same
471.1051 +     *          sequence of characters as the specified {@code StringBuffer},
471.1052 +     *          {@code false} otherwise
471.1053 +     *
471.1054 +     * @since  1.4
471.1055 +     */
471.1056 +    public boolean contentEquals(StringBuffer sb) {
471.1057 +        synchronized(sb) {
471.1058 +            return contentEquals((CharSequence)sb);
471.1059 +        }
471.1060 +    }
471.1061 +
471.1062 +    /**
471.1063 +     * Compares this string to the specified {@code CharSequence}.  The result
471.1064 +     * is {@code true} if and only if this {@code String} represents the same
471.1065 +     * sequence of char values as the specified sequence.
471.1066 +     *
471.1067 +     * @param  cs
471.1068 +     *         The sequence to compare this {@code String} against
471.1069 +     *
471.1070 +     * @return  {@code true} if this {@code String} represents the same
471.1071 +     *          sequence of char values as the specified sequence, {@code
471.1072 +     *          false} otherwise
471.1073 +     *
471.1074 +     * @since  1.5
471.1075 +     */
471.1076 +    public boolean contentEquals(CharSequence cs) {
471.1077 +        if (length() != cs.length())
471.1078 +            return false;
471.1079 +        // Argument is a StringBuffer, StringBuilder
471.1080 +        if (cs instanceof AbstractStringBuilder) {
471.1081 +            char v1[] = toCharArray();
471.1082 +            char v2[] = ((AbstractStringBuilder)cs).getValue();
471.1083 +            int i = offset();
471.1084 +            int j = 0;
471.1085 +            int n = length();
471.1086 +            while (n-- != 0) {
471.1087 +                if (v1[i++] != v2[j++])
471.1088 +                    return false;
471.1089 +            }
471.1090 +            return true;
471.1091 +        }
471.1092 +        // Argument is a String
471.1093 +        if (cs.equals(this))
471.1094 +            return true;
471.1095 +        // Argument is a generic CharSequence
471.1096 +        char v1[] = toCharArray();
471.1097 +        int i = offset();
471.1098 +        int j = 0;
471.1099 +        int n = length();
471.1100 +        while (n-- != 0) {
471.1101 +            if (v1[i++] != cs.charAt(j++))
471.1102 +                return false;
471.1103 +        }
471.1104 +        return true;
471.1105 +    }
471.1106 +
471.1107 +    /**
471.1108 +     * Compares this {@code String} to another {@code String}, ignoring case
471.1109 +     * considerations.  Two strings are considered equal ignoring case if they
471.1110 +     * are of the same length and corresponding characters in the two strings
471.1111 +     * are equal ignoring case.
471.1112 +     *
471.1113 +     * <p> Two characters {@code c1} and {@code c2} are considered the same
471.1114 +     * ignoring case if at least one of the following is true:
471.1115 +     * <ul>
471.1116 +     *   <li> The two characters are the same (as compared by the
471.1117 +     *        {@code ==} operator)
471.1118 +     *   <li> Applying the method {@link
471.1119 +     *        java.lang.Character#toUpperCase(char)} to each character
471.1120 +     *        produces the same result
471.1121 +     *   <li> Applying the method {@link
471.1122 +     *        java.lang.Character#toLowerCase(char)} to each character
471.1123 +     *        produces the same result
471.1124 +     * </ul>
471.1125 +     *
471.1126 +     * @param  anotherString
471.1127 +     *         The {@code String} to compare this {@code String} against
471.1128 +     *
471.1129 +     * @return  {@code true} if the argument is not {@code null} and it
471.1130 +     *          represents an equivalent {@code String} ignoring case; {@code
471.1131 +     *          false} otherwise
471.1132 +     *
471.1133 +     * @see  #equals(Object)
471.1134 +     */
471.1135 +    public boolean equalsIgnoreCase(String anotherString) {
471.1136 +        return (this == anotherString) ? true :
471.1137 +               (anotherString != null) && (anotherString.length() == length()) &&
471.1138 +               regionMatches(true, 0, anotherString, 0, length());
471.1139 +    }
471.1140 +
471.1141 +    /**
471.1142 +     * Compares two strings lexicographically.
471.1143 +     * The comparison is based on the Unicode value of each character in
471.1144 +     * the strings. The character sequence represented by this
471.1145 +     * <code>String</code> object is compared lexicographically to the
471.1146 +     * character sequence represented by the argument string. The result is
471.1147 +     * a negative integer if this <code>String</code> object
471.1148 +     * lexicographically precedes the argument string. The result is a
471.1149 +     * positive integer if this <code>String</code> object lexicographically
471.1150 +     * follows the argument string. The result is zero if the strings
471.1151 +     * are equal; <code>compareTo</code> returns <code>0</code> exactly when
471.1152 +     * the {@link #equals(Object)} method would return <code>true</code>.
471.1153 +     * <p>
471.1154 +     * This is the definition of lexicographic ordering. If two strings are
471.1155 +     * different, then either they have different characters at some index
471.1156 +     * that is a valid index for both strings, or their lengths are different,
471.1157 +     * or both. If they have different characters at one or more index
471.1158 +     * positions, let <i>k</i> be the smallest such index; then the string
471.1159 +     * whose character at position <i>k</i> has the smaller value, as
471.1160 +     * determined by using the &lt; operator, lexicographically precedes the
471.1161 +     * other string. In this case, <code>compareTo</code> returns the
471.1162 +     * difference of the two character values at position <code>k</code> in
471.1163 +     * the two string -- that is, the value:
471.1164 +     * <blockquote><pre>
471.1165 +     * this.charAt(k)-anotherString.charAt(k)
471.1166 +     * </pre></blockquote>
471.1167 +     * If there is no index position at which they differ, then the shorter
471.1168 +     * string lexicographically precedes the longer string. In this case,
471.1169 +     * <code>compareTo</code> returns the difference of the lengths of the
471.1170 +     * strings -- that is, the value:
471.1171 +     * <blockquote><pre>
471.1172 +     * this.length()-anotherString.length()
471.1173 +     * </pre></blockquote>
471.1174 +     *
471.1175 +     * @param   anotherString   the <code>String</code> to be compared.
471.1176 +     * @return  the value <code>0</code> if the argument string is equal to
471.1177 +     *          this string; a value less than <code>0</code> if this string
471.1178 +     *          is lexicographically less than the string argument; and a
471.1179 +     *          value greater than <code>0</code> if this string is
471.1180 +     *          lexicographically greater than the string argument.
471.1181 +     */
471.1182 +    public int compareTo(String anotherString) {
471.1183 +        int len1 = length();
471.1184 +        int len2 = anotherString.length();
471.1185 +        int n = Math.min(len1, len2);
471.1186 +        char v1[] = toCharArray();
471.1187 +        char v2[] = anotherString.toCharArray();
471.1188 +        int i = offset();
471.1189 +        int j = anotherString.offset();
471.1190 +
471.1191 +        if (i == j) {
471.1192 +            int k = i;
471.1193 +            int lim = n + i;
471.1194 +            while (k < lim) {
471.1195 +                char c1 = v1[k];
471.1196 +                char c2 = v2[k];
471.1197 +                if (c1 != c2) {
471.1198 +                    return c1 - c2;
471.1199 +                }
471.1200 +                k++;
471.1201 +            }
471.1202 +        } else {
471.1203 +            while (n-- != 0) {
471.1204 +                char c1 = v1[i++];
471.1205 +                char c2 = v2[j++];
471.1206 +                if (c1 != c2) {
471.1207 +                    return c1 - c2;
471.1208 +                }
471.1209 +            }
471.1210 +        }
471.1211 +        return len1 - len2;
471.1212 +    }
471.1213 +
471.1214 +    /**
471.1215 +     * A Comparator that orders <code>String</code> objects as by
471.1216 +     * <code>compareToIgnoreCase</code>. This comparator is serializable.
471.1217 +     * <p>
471.1218 +     * Note that this Comparator does <em>not</em> take locale into account,
471.1219 +     * and will result in an unsatisfactory ordering for certain locales.
471.1220 +     * The java.text package provides <em>Collators</em> to allow
471.1221 +     * locale-sensitive ordering.
471.1222 +     *
471.1223 +     * @see     java.text.Collator#compare(String, String)
471.1224 +     * @since   1.2
471.1225 +     */
471.1226 +    public static final Comparator<String> CASE_INSENSITIVE_ORDER
471.1227 +                                         = new CaseInsensitiveComparator();
471.1228 +
471.1229 +    private static int offset() {
471.1230 +        return 0;
471.1231 +    }
471.1232 +
471.1233 +    private static class CaseInsensitiveComparator
471.1234 +                         implements Comparator<String>, java.io.Serializable {
471.1235 +        // use serialVersionUID from JDK 1.2.2 for interoperability
471.1236 +        private static final long serialVersionUID = 8575799808933029326L;
471.1237 +
471.1238 +        public int compare(String s1, String s2) {
471.1239 +            int n1 = s1.length();
471.1240 +            int n2 = s2.length();
471.1241 +            int min = Math.min(n1, n2);
471.1242 +            for (int i = 0; i < min; i++) {
471.1243 +                char c1 = s1.charAt(i);
471.1244 +                char c2 = s2.charAt(i);
471.1245 +                if (c1 != c2) {
471.1246 +                    c1 = Character.toUpperCase(c1);
471.1247 +                    c2 = Character.toUpperCase(c2);
471.1248 +                    if (c1 != c2) {
471.1249 +                        c1 = Character.toLowerCase(c1);
471.1250 +                        c2 = Character.toLowerCase(c2);
471.1251 +                        if (c1 != c2) {
471.1252 +                            // No overflow because of numeric promotion
471.1253 +                            return c1 - c2;
471.1254 +                        }
471.1255 +                    }
471.1256 +                }
471.1257 +            }
471.1258 +            return n1 - n2;
471.1259 +        }
471.1260 +    }
471.1261 +
471.1262 +    /**
471.1263 +     * Compares two strings lexicographically, ignoring case
471.1264 +     * differences. This method returns an integer whose sign is that of
471.1265 +     * calling <code>compareTo</code> with normalized versions of the strings
471.1266 +     * where case differences have been eliminated by calling
471.1267 +     * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
471.1268 +     * each character.
471.1269 +     * <p>
471.1270 +     * Note that this method does <em>not</em> take locale into account,
471.1271 +     * and will result in an unsatisfactory ordering for certain locales.
471.1272 +     * The java.text package provides <em>collators</em> to allow
471.1273 +     * locale-sensitive ordering.
471.1274 +     *
471.1275 +     * @param   str   the <code>String</code> to be compared.
471.1276 +     * @return  a negative integer, zero, or a positive integer as the
471.1277 +     *          specified String is greater than, equal to, or less
471.1278 +     *          than this String, ignoring case considerations.
471.1279 +     * @see     java.text.Collator#compare(String, String)
471.1280 +     * @since   1.2
471.1281 +     */
471.1282 +    public int compareToIgnoreCase(String str) {
471.1283 +        return CASE_INSENSITIVE_ORDER.compare(this, str);
471.1284 +    }
471.1285 +
471.1286 +    /**
471.1287 +     * Tests if two string regions are equal.
471.1288 +     * <p>
471.1289 +     * A substring of this <tt>String</tt> object is compared to a substring
471.1290 +     * of the argument other. The result is true if these substrings
471.1291 +     * represent identical character sequences. The substring of this
471.1292 +     * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
471.1293 +     * and has length <tt>len</tt>. The substring of other to be compared
471.1294 +     * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
471.1295 +     * result is <tt>false</tt> if and only if at least one of the following
471.1296 +     * is true:
471.1297 +     * <ul><li><tt>toffset</tt> is negative.
471.1298 +     * <li><tt>ooffset</tt> is negative.
471.1299 +     * <li><tt>toffset+len</tt> is greater than the length of this
471.1300 +     * <tt>String</tt> object.
471.1301 +     * <li><tt>ooffset+len</tt> is greater than the length of the other
471.1302 +     * argument.
471.1303 +     * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
471.1304 +     * such that:
471.1305 +     * <tt>this.charAt(toffset+<i>k</i>)&nbsp;!=&nbsp;other.charAt(ooffset+<i>k</i>)</tt>
471.1306 +     * </ul>
471.1307 +     *
471.1308 +     * @param   toffset   the starting offset of the subregion in this string.
471.1309 +     * @param   other     the string argument.
471.1310 +     * @param   ooffset   the starting offset of the subregion in the string
471.1311 +     *                    argument.
471.1312 +     * @param   len       the number of characters to compare.
471.1313 +     * @return  <code>true</code> if the specified subregion of this string
471.1314 +     *          exactly matches the specified subregion of the string argument;
471.1315 +     *          <code>false</code> otherwise.
471.1316 +     */
471.1317 +    public boolean regionMatches(int toffset, String other, int ooffset,
471.1318 +                                 int len) {
471.1319 +        char ta[] = toCharArray();
471.1320 +        int to = offset() + toffset;
471.1321 +        char pa[] = other.toCharArray();
471.1322 +        int po = other.offset() + ooffset;
471.1323 +        // Note: toffset, ooffset, or len might be near -1>>>1.
471.1324 +        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
471.1325 +            || (ooffset > (long)other.length() - len)) {
471.1326 +            return false;
471.1327 +        }
471.1328 +        while (len-- > 0) {
471.1329 +            if (ta[to++] != pa[po++]) {
471.1330 +                return false;
471.1331 +            }
471.1332 +        }
471.1333 +        return true;
471.1334 +    }
471.1335 +
471.1336 +    /**
471.1337 +     * Tests if two string regions are equal.
471.1338 +     * <p>
471.1339 +     * A substring of this <tt>String</tt> object is compared to a substring
471.1340 +     * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
471.1341 +     * substrings represent character sequences that are the same, ignoring
471.1342 +     * case if and only if <tt>ignoreCase</tt> is true. The substring of
471.1343 +     * this <tt>String</tt> object to be compared begins at index
471.1344 +     * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
471.1345 +     * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
471.1346 +     * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
471.1347 +     * at least one of the following is true:
471.1348 +     * <ul><li><tt>toffset</tt> is negative.
471.1349 +     * <li><tt>ooffset</tt> is negative.
471.1350 +     * <li><tt>toffset+len</tt> is greater than the length of this
471.1351 +     * <tt>String</tt> object.
471.1352 +     * <li><tt>ooffset+len</tt> is greater than the length of the other
471.1353 +     * argument.
471.1354 +     * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
471.1355 +     * integer <i>k</i> less than <tt>len</tt> such that:
471.1356 +     * <blockquote><pre>
471.1357 +     * this.charAt(toffset+k) != other.charAt(ooffset+k)
471.1358 +     * </pre></blockquote>
471.1359 +     * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
471.1360 +     * integer <i>k</i> less than <tt>len</tt> such that:
471.1361 +     * <blockquote><pre>
471.1362 +     * Character.toLowerCase(this.charAt(toffset+k)) !=
471.1363 +               Character.toLowerCase(other.charAt(ooffset+k))
471.1364 +     * </pre></blockquote>
471.1365 +     * and:
471.1366 +     * <blockquote><pre>
471.1367 +     * Character.toUpperCase(this.charAt(toffset+k)) !=
471.1368 +     *         Character.toUpperCase(other.charAt(ooffset+k))
471.1369 +     * </pre></blockquote>
471.1370 +     * </ul>
471.1371 +     *
471.1372 +     * @param   ignoreCase   if <code>true</code>, ignore case when comparing
471.1373 +     *                       characters.
471.1374 +     * @param   toffset      the starting offset of the subregion in this
471.1375 +     *                       string.
471.1376 +     * @param   other        the string argument.
471.1377 +     * @param   ooffset      the starting offset of the subregion in the string
471.1378 +     *                       argument.
471.1379 +     * @param   len          the number of characters to compare.
471.1380 +     * @return  <code>true</code> if the specified subregion of this string
471.1381 +     *          matches the specified subregion of the string argument;
471.1382 +     *          <code>false</code> otherwise. Whether the matching is exact
471.1383 +     *          or case insensitive depends on the <code>ignoreCase</code>
471.1384 +     *          argument.
471.1385 +     */
471.1386 +    public boolean regionMatches(boolean ignoreCase, int toffset,
471.1387 +                           String other, int ooffset, int len) {
471.1388 +        char ta[] = toCharArray();
471.1389 +        int to = offset() + toffset;
471.1390 +        char pa[] = other.toCharArray();
471.1391 +        int po = other.offset() + ooffset;
471.1392 +        // Note: toffset, ooffset, or len might be near -1>>>1.
471.1393 +        if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
471.1394 +                (ooffset > (long)other.length() - len)) {
471.1395 +            return false;
471.1396 +        }
471.1397 +        while (len-- > 0) {
471.1398 +            char c1 = ta[to++];
471.1399 +            char c2 = pa[po++];
471.1400 +            if (c1 == c2) {
471.1401 +                continue;
471.1402 +            }
471.1403 +            if (ignoreCase) {
471.1404 +                // If characters don't match but case may be ignored,
471.1405 +                // try converting both characters to uppercase.
471.1406 +                // If the results match, then the comparison scan should
471.1407 +                // continue.
471.1408 +                char u1 = Character.toUpperCase(c1);
471.1409 +                char u2 = Character.toUpperCase(c2);
471.1410 +                if (u1 == u2) {
471.1411 +                    continue;
471.1412 +                }
471.1413 +                // Unfortunately, conversion to uppercase does not work properly
471.1414 +                // for the Georgian alphabet, which has strange rules about case
471.1415 +                // conversion.  So we need to make one last check before
471.1416 +                // exiting.
471.1417 +                if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
471.1418 +                    continue;
471.1419 +                }
471.1420 +            }
471.1421 +            return false;
471.1422 +        }
471.1423 +        return true;
471.1424 +    }
471.1425 +
471.1426 +    /**
471.1427 +     * Tests if the substring of this string beginning at the
471.1428 +     * specified index starts with the specified prefix.
471.1429 +     *
471.1430 +     * @param   prefix    the prefix.
471.1431 +     * @param   toffset   where to begin looking in this string.
471.1432 +     * @return  <code>true</code> if the character sequence represented by the
471.1433 +     *          argument is a prefix of the substring of this object starting
471.1434 +     *          at index <code>toffset</code>; <code>false</code> otherwise.
471.1435 +     *          The result is <code>false</code> if <code>toffset</code> is
471.1436 +     *          negative or greater than the length of this
471.1437 +     *          <code>String</code> object; otherwise the result is the same
471.1438 +     *          as the result of the expression
471.1439 +     *          <pre>
471.1440 +     *          this.substring(toffset).startsWith(prefix)
471.1441 +     *          </pre>
471.1442 +     */
471.1443 +    @JavaScriptBody(args = { "find", "from" }, body=
471.1444 +        "find = find.toString();\n" +
471.1445 +        "return this.toString().substring(from, from + find.length) === find;\n"
471.1446 +    )
471.1447 +    public boolean startsWith(String prefix, int toffset) {
471.1448 +        char ta[] = toCharArray();
471.1449 +        int to = offset() + toffset;
471.1450 +        char pa[] = prefix.toCharArray();
471.1451 +        int po = prefix.offset();
471.1452 +        int pc = prefix.length();
471.1453 +        // Note: toffset might be near -1>>>1.
471.1454 +        if ((toffset < 0) || (toffset > length() - pc)) {
471.1455 +            return false;
471.1456 +        }
471.1457 +        while (--pc >= 0) {
471.1458 +            if (ta[to++] != pa[po++]) {
471.1459 +                return false;
471.1460 +            }
471.1461 +        }
471.1462 +        return true;
471.1463 +    }
471.1464 +
471.1465 +    /**
471.1466 +     * Tests if this string starts with the specified prefix.
471.1467 +     *
471.1468 +     * @param   prefix   the prefix.
471.1469 +     * @return  <code>true</code> if the character sequence represented by the
471.1470 +     *          argument is a prefix of the character sequence represented by
471.1471 +     *          this string; <code>false</code> otherwise.
471.1472 +     *          Note also that <code>true</code> will be returned if the
471.1473 +     *          argument is an empty string or is equal to this
471.1474 +     *          <code>String</code> object as determined by the
471.1475 +     *          {@link #equals(Object)} method.
471.1476 +     * @since   1. 0
471.1477 +     */
471.1478 +    public boolean startsWith(String prefix) {
471.1479 +        return startsWith(prefix, 0);
471.1480 +    }
471.1481 +
471.1482 +    /**
471.1483 +     * Tests if this string ends with the specified suffix.
471.1484 +     *
471.1485 +     * @param   suffix   the suffix.
471.1486 +     * @return  <code>true</code> if the character sequence represented by the
471.1487 +     *          argument is a suffix of the character sequence represented by
471.1488 +     *          this object; <code>false</code> otherwise. Note that the
471.1489 +     *          result will be <code>true</code> if the argument is the
471.1490 +     *          empty string or is equal to this <code>String</code> object
471.1491 +     *          as determined by the {@link #equals(Object)} method.
471.1492 +     */
471.1493 +    public boolean endsWith(String suffix) {
471.1494 +        return startsWith(suffix, length() - suffix.length());
471.1495 +    }
471.1496 +
471.1497 +    /**
471.1498 +     * Returns a hash code for this string. The hash code for a
471.1499 +     * <code>String</code> object is computed as
471.1500 +     * <blockquote><pre>
471.1501 +     * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
471.1502 +     * </pre></blockquote>
471.1503 +     * using <code>int</code> arithmetic, where <code>s[i]</code> is the
471.1504 +     * <i>i</i>th character of the string, <code>n</code> is the length of
471.1505 +     * the string, and <code>^</code> indicates exponentiation.
471.1506 +     * (The hash value of the empty string is zero.)
471.1507 +     *
471.1508 +     * @return  a hash code value for this object.
471.1509 +     */
471.1510 +    public int hashCode() {
471.1511 +        return super.hashCode();
471.1512 +    }
471.1513 +    int computeHashCode() {
471.1514 +        int h = 0;
471.1515 +        if (h == 0 && length() > 0) {
471.1516 +            int off = offset();
471.1517 +            int len = length();
471.1518 +
471.1519 +            for (int i = 0; i < len; i++) {
471.1520 +                h = 31*h + charAt(off++);
471.1521 +            }
471.1522 +        }
471.1523 +        return h;
471.1524 +    }
471.1525 +
471.1526 +    /**
471.1527 +     * Returns the index within this string of the first occurrence of
471.1528 +     * the specified character. If a character with value
471.1529 +     * <code>ch</code> occurs in the character sequence represented by
471.1530 +     * this <code>String</code> object, then the index (in Unicode
471.1531 +     * code units) of the first such occurrence is returned. For
471.1532 +     * values of <code>ch</code> in the range from 0 to 0xFFFF
471.1533 +     * (inclusive), this is the smallest value <i>k</i> such that:
471.1534 +     * <blockquote><pre>
471.1535 +     * this.charAt(<i>k</i>) == ch
471.1536 +     * </pre></blockquote>
471.1537 +     * is true. For other values of <code>ch</code>, it is the
471.1538 +     * smallest value <i>k</i> such that:
471.1539 +     * <blockquote><pre>
471.1540 +     * this.codePointAt(<i>k</i>) == ch
471.1541 +     * </pre></blockquote>
471.1542 +     * is true. In either case, if no such character occurs in this
471.1543 +     * string, then <code>-1</code> is returned.
471.1544 +     *
471.1545 +     * @param   ch   a character (Unicode code point).
471.1546 +     * @return  the index of the first occurrence of the character in the
471.1547 +     *          character sequence represented by this object, or
471.1548 +     *          <code>-1</code> if the character does not occur.
471.1549 +     */
471.1550 +    public int indexOf(int ch) {
471.1551 +        return indexOf(ch, 0);
471.1552 +    }
471.1553 +
471.1554 +    /**
471.1555 +     * Returns the index within this string of the first occurrence of the
471.1556 +     * specified character, starting the search at the specified index.
471.1557 +     * <p>
471.1558 +     * If a character with value <code>ch</code> occurs in the
471.1559 +     * character sequence represented by this <code>String</code>
471.1560 +     * object at an index no smaller than <code>fromIndex</code>, then
471.1561 +     * the index of the first such occurrence is returned. For values
471.1562 +     * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
471.1563 +     * this is the smallest value <i>k</i> such that:
471.1564 +     * <blockquote><pre>
471.1565 +     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
471.1566 +     * </pre></blockquote>
471.1567 +     * is true. For other values of <code>ch</code>, it is the
471.1568 +     * smallest value <i>k</i> such that:
471.1569 +     * <blockquote><pre>
471.1570 +     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &gt;= fromIndex)
471.1571 +     * </pre></blockquote>
471.1572 +     * is true. In either case, if no such character occurs in this
471.1573 +     * string at or after position <code>fromIndex</code>, then
471.1574 +     * <code>-1</code> is returned.
471.1575 +     *
471.1576 +     * <p>
471.1577 +     * There is no restriction on the value of <code>fromIndex</code>. If it
471.1578 +     * is negative, it has the same effect as if it were zero: this entire
471.1579 +     * string may be searched. If it is greater than the length of this
471.1580 +     * string, it has the same effect as if it were equal to the length of
471.1581 +     * this string: <code>-1</code> is returned.
471.1582 +     *
471.1583 +     * <p>All indices are specified in <code>char</code> values
471.1584 +     * (Unicode code units).
471.1585 +     *
471.1586 +     * @param   ch          a character (Unicode code point).
471.1587 +     * @param   fromIndex   the index to start the search from.
471.1588 +     * @return  the index of the first occurrence of the character in the
471.1589 +     *          character sequence represented by this object that is greater
471.1590 +     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
471.1591 +     *          if the character does not occur.
471.1592 +     */
471.1593 +    @JavaScriptBody(args = { "ch", "from" }, body = 
471.1594 +        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
471.1595 +        "return this.toString().indexOf(ch, from);\n"
471.1596 +    )
471.1597 +    public int indexOf(int ch, int fromIndex) {
471.1598 +        if (fromIndex < 0) {
471.1599 +            fromIndex = 0;
471.1600 +        } else if (fromIndex >= length()) {
471.1601 +            // Note: fromIndex might be near -1>>>1.
471.1602 +            return -1;
471.1603 +        }
471.1604 +
471.1605 +        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
471.1606 +            // handle most cases here (ch is a BMP code point or a
471.1607 +            // negative value (invalid code point))
471.1608 +            final char[] value = this.toCharArray();
471.1609 +            final int offset = this.offset();
471.1610 +            final int max = offset + length();
471.1611 +            for (int i = offset + fromIndex; i < max ; i++) {
471.1612 +                if (value[i] == ch) {
471.1613 +                    return i - offset;
471.1614 +                }
471.1615 +            }
471.1616 +            return -1;
471.1617 +        } else {
471.1618 +            return indexOfSupplementary(ch, fromIndex);
471.1619 +        }
471.1620 +    }
471.1621 +
471.1622 +    /**
471.1623 +     * Handles (rare) calls of indexOf with a supplementary character.
471.1624 +     */
471.1625 +    private int indexOfSupplementary(int ch, int fromIndex) {
471.1626 +        if (Character.isValidCodePoint(ch)) {
471.1627 +            final char[] value = this.toCharArray();
471.1628 +            final int offset = this.offset();
471.1629 +            final char hi = Character.highSurrogate(ch);
471.1630 +            final char lo = Character.lowSurrogate(ch);
471.1631 +            final int max = offset + length() - 1;
471.1632 +            for (int i = offset + fromIndex; i < max; i++) {
471.1633 +                if (value[i] == hi && value[i+1] == lo) {
471.1634 +                    return i - offset;
471.1635 +                }
471.1636 +            }
471.1637 +        }
471.1638 +        return -1;
471.1639 +    }
471.1640 +
471.1641 +    /**
471.1642 +     * Returns the index within this string of the last occurrence of
471.1643 +     * the specified character. For values of <code>ch</code> in the
471.1644 +     * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
471.1645 +     * units) returned is the largest value <i>k</i> such that:
471.1646 +     * <blockquote><pre>
471.1647 +     * this.charAt(<i>k</i>) == ch
471.1648 +     * </pre></blockquote>
471.1649 +     * is true. For other values of <code>ch</code>, it is the
471.1650 +     * largest value <i>k</i> such that:
471.1651 +     * <blockquote><pre>
471.1652 +     * this.codePointAt(<i>k</i>) == ch
471.1653 +     * </pre></blockquote>
471.1654 +     * is true.  In either case, if no such character occurs in this
471.1655 +     * string, then <code>-1</code> is returned.  The
471.1656 +     * <code>String</code> is searched backwards starting at the last
471.1657 +     * character.
471.1658 +     *
471.1659 +     * @param   ch   a character (Unicode code point).
471.1660 +     * @return  the index of the last occurrence of the character in the
471.1661 +     *          character sequence represented by this object, or
471.1662 +     *          <code>-1</code> if the character does not occur.
471.1663 +     */
471.1664 +    public int lastIndexOf(int ch) {
471.1665 +        return lastIndexOf(ch, length() - 1);
471.1666 +    }
471.1667 +
471.1668 +    /**
471.1669 +     * Returns the index within this string of the last occurrence of
471.1670 +     * the specified character, searching backward starting at the
471.1671 +     * specified index. For values of <code>ch</code> in the range
471.1672 +     * from 0 to 0xFFFF (inclusive), the index returned is the largest
471.1673 +     * value <i>k</i> such that:
471.1674 +     * <blockquote><pre>
471.1675 +     * (this.charAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
471.1676 +     * </pre></blockquote>
471.1677 +     * is true. For other values of <code>ch</code>, it is the
471.1678 +     * largest value <i>k</i> such that:
471.1679 +     * <blockquote><pre>
471.1680 +     * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> &lt;= fromIndex)
471.1681 +     * </pre></blockquote>
471.1682 +     * is true. In either case, if no such character occurs in this
471.1683 +     * string at or before position <code>fromIndex</code>, then
471.1684 +     * <code>-1</code> is returned.
471.1685 +     *
471.1686 +     * <p>All indices are specified in <code>char</code> values
471.1687 +     * (Unicode code units).
471.1688 +     *
471.1689 +     * @param   ch          a character (Unicode code point).
471.1690 +     * @param   fromIndex   the index to start the search from. There is no
471.1691 +     *          restriction on the value of <code>fromIndex</code>. If it is
471.1692 +     *          greater than or equal to the length of this string, it has
471.1693 +     *          the same effect as if it were equal to one less than the
471.1694 +     *          length of this string: this entire string may be searched.
471.1695 +     *          If it is negative, it has the same effect as if it were -1:
471.1696 +     *          -1 is returned.
471.1697 +     * @return  the index of the last occurrence of the character in the
471.1698 +     *          character sequence represented by this object that is less
471.1699 +     *          than or equal to <code>fromIndex</code>, or <code>-1</code>
471.1700 +     *          if the character does not occur before that point.
471.1701 +     */
471.1702 +    @JavaScriptBody(args = { "ch", "from" }, body = 
471.1703 +        "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
471.1704 +        "return this.toString().lastIndexOf(ch, from);"
471.1705 +    )
471.1706 +    public int lastIndexOf(int ch, int fromIndex) {
471.1707 +        if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
471.1708 +            // handle most cases here (ch is a BMP code point or a
471.1709 +            // negative value (invalid code point))
471.1710 +            final char[] value = this.toCharArray();
471.1711 +            final int offset = this.offset();
471.1712 +            int i = offset + Math.min(fromIndex, length() - 1);
471.1713 +            for (; i >= offset ; i--) {
471.1714 +                if (value[i] == ch) {
471.1715 +                    return i - offset;
471.1716 +                }
471.1717 +            }
471.1718 +            return -1;
471.1719 +        } else {
471.1720 +            return lastIndexOfSupplementary(ch, fromIndex);
471.1721 +        }
471.1722 +    }
471.1723 +
471.1724 +    /**
471.1725 +     * Handles (rare) calls of lastIndexOf with a supplementary character.
471.1726 +     */
471.1727 +    private int lastIndexOfSupplementary(int ch, int fromIndex) {
471.1728 +        if (Character.isValidCodePoint(ch)) {
471.1729 +            final char[] value = this.toCharArray();
471.1730 +            final int offset = this.offset();
471.1731 +            char hi = Character.highSurrogate(ch);
471.1732 +            char lo = Character.lowSurrogate(ch);
471.1733 +            int i = offset + Math.min(fromIndex, length() - 2);
471.1734 +            for (; i >= offset; i--) {
471.1735 +                if (value[i] == hi && value[i+1] == lo) {
471.1736 +                    return i - offset;
471.1737 +                }
471.1738 +            }
471.1739 +        }
471.1740 +        return -1;
471.1741 +    }
471.1742 +
471.1743 +    /**
471.1744 +     * Returns the index within this string of the first occurrence of the
471.1745 +     * specified substring.
471.1746 +     *
471.1747 +     * <p>The returned index is the smallest value <i>k</i> for which:
471.1748 +     * <blockquote><pre>
471.1749 +     * this.startsWith(str, <i>k</i>)
471.1750 +     * </pre></blockquote>
471.1751 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
471.1752 +     *
471.1753 +     * @param   str   the substring to search for.
471.1754 +     * @return  the index of the first occurrence of the specified substring,
471.1755 +     *          or {@code -1} if there is no such occurrence.
471.1756 +     */
471.1757 +    public int indexOf(String str) {
471.1758 +        return indexOf(str, 0);
471.1759 +    }
471.1760 +
471.1761 +    /**
471.1762 +     * Returns the index within this string of the first occurrence of the
471.1763 +     * specified substring, starting at the specified index.
471.1764 +     *
471.1765 +     * <p>The returned index is the smallest value <i>k</i> for which:
471.1766 +     * <blockquote><pre>
471.1767 +     * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
471.1768 +     * </pre></blockquote>
471.1769 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
471.1770 +     *
471.1771 +     * @param   str         the substring to search for.
471.1772 +     * @param   fromIndex   the index from which to start the search.
471.1773 +     * @return  the index of the first occurrence of the specified substring,
471.1774 +     *          starting at the specified index,
471.1775 +     *          or {@code -1} if there is no such occurrence.
471.1776 +     */
471.1777 +    @JavaScriptBody(args = { "str", "fromIndex" }, body =
471.1778 +        "return this.toString().indexOf(str.toString(), fromIndex);"
471.1779 +    )
471.1780 +    public native int indexOf(String str, int fromIndex);
471.1781 +
471.1782 +    /**
471.1783 +     * Returns the index within this string of the last occurrence of the
471.1784 +     * specified substring.  The last occurrence of the empty string ""
471.1785 +     * is considered to occur at the index value {@code this.length()}.
471.1786 +     *
471.1787 +     * <p>The returned index is the largest value <i>k</i> for which:
471.1788 +     * <blockquote><pre>
471.1789 +     * this.startsWith(str, <i>k</i>)
471.1790 +     * </pre></blockquote>
471.1791 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
471.1792 +     *
471.1793 +     * @param   str   the substring to search for.
471.1794 +     * @return  the index of the last occurrence of the specified substring,
471.1795 +     *          or {@code -1} if there is no such occurrence.
471.1796 +     */
471.1797 +    public int lastIndexOf(String str) {
471.1798 +        return lastIndexOf(str, length());
471.1799 +    }
471.1800 +
471.1801 +    /**
471.1802 +     * Returns the index within this string of the last occurrence of the
471.1803 +     * specified substring, searching backward starting at the specified index.
471.1804 +     *
471.1805 +     * <p>The returned index is the largest value <i>k</i> for which:
471.1806 +     * <blockquote><pre>
471.1807 +     * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
471.1808 +     * </pre></blockquote>
471.1809 +     * If no such value of <i>k</i> exists, then {@code -1} is returned.
471.1810 +     *
471.1811 +     * @param   str         the substring to search for.
471.1812 +     * @param   fromIndex   the index to start the search from.
471.1813 +     * @return  the index of the last occurrence of the specified substring,
471.1814 +     *          searching backward from the specified index,
471.1815 +     *          or {@code -1} if there is no such occurrence.
471.1816 +     */
471.1817 +    @JavaScriptBody(args = { "s", "from" }, body = 
471.1818 +        "return this.toString().lastIndexOf(s.toString(), from);"
471.1819 +    )
471.1820 +    public int lastIndexOf(String str, int fromIndex) {
471.1821 +        return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
471.1822 +    }
471.1823 +
471.1824 +    /**
471.1825 +     * Code shared by String and StringBuffer to do searches. The
471.1826 +     * source is the character array being searched, and the target
471.1827 +     * is the string being searched for.
471.1828 +     *
471.1829 +     * @param   source       the characters being searched.
471.1830 +     * @param   sourceOffset offset of the source string.
471.1831 +     * @param   sourceCount  count of the source string.
471.1832 +     * @param   target       the characters being searched for.
471.1833 +     * @param   targetOffset offset of the target string.
471.1834 +     * @param   targetCount  count of the target string.
471.1835 +     * @param   fromIndex    the index to begin searching from.
471.1836 +     */
471.1837 +    static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
471.1838 +                           char[] target, int targetOffset, int targetCount,
471.1839 +                           int fromIndex) {
471.1840 +        /*
471.1841 +         * Check arguments; return immediately where possible. For
471.1842 +         * consistency, don't check for null str.
471.1843 +         */
471.1844 +        int rightIndex = sourceCount - targetCount;
471.1845 +        if (fromIndex < 0) {
471.1846 +            return -1;
471.1847 +        }
471.1848 +        if (fromIndex > rightIndex) {
471.1849 +            fromIndex = rightIndex;
471.1850 +        }
471.1851 +        /* Empty string always matches. */
471.1852 +        if (targetCount == 0) {
471.1853 +            return fromIndex;
471.1854 +        }
471.1855 +
471.1856 +        int strLastIndex = targetOffset + targetCount - 1;
471.1857 +        char strLastChar = target[strLastIndex];
471.1858 +        int min = sourceOffset + targetCount - 1;
471.1859 +        int i = min + fromIndex;
471.1860 +
471.1861 +    startSearchForLastChar:
471.1862 +        while (true) {
471.1863 +            while (i >= min && source[i] != strLastChar) {
471.1864 +                i--;
471.1865 +            }
471.1866 +            if (i < min) {
471.1867 +                return -1;
471.1868 +            }
471.1869 +            int j = i - 1;
471.1870 +            int start = j - (targetCount - 1);
471.1871 +            int k = strLastIndex - 1;
471.1872 +
471.1873 +            while (j > start) {
471.1874 +                if (source[j--] != target[k--]) {
471.1875 +                    i--;
471.1876 +                    continue startSearchForLastChar;
471.1877 +                }
471.1878 +            }
471.1879 +            return start - sourceOffset + 1;
471.1880 +        }
471.1881 +    }
471.1882 +
471.1883 +    /**
471.1884 +     * Returns a new string that is a substring of this string. The
471.1885 +     * substring begins with the character at the specified index and
471.1886 +     * extends to the end of this string. <p>
471.1887 +     * Examples:
471.1888 +     * <blockquote><pre>
471.1889 +     * "unhappy".substring(2) returns "happy"
471.1890 +     * "Harbison".substring(3) returns "bison"
471.1891 +     * "emptiness".substring(9) returns "" (an empty string)
471.1892 +     * </pre></blockquote>
471.1893 +     *
471.1894 +     * @param      beginIndex   the beginning index, inclusive.
471.1895 +     * @return     the specified substring.
471.1896 +     * @exception  IndexOutOfBoundsException  if
471.1897 +     *             <code>beginIndex</code> is negative or larger than the
471.1898 +     *             length of this <code>String</code> object.
471.1899 +     */
471.1900 +    public String substring(int beginIndex) {
471.1901 +        return substring(beginIndex, length());
471.1902 +    }
471.1903 +
471.1904 +    /**
471.1905 +     * Returns a new string that is a substring of this string. The
471.1906 +     * substring begins at the specified <code>beginIndex</code> and
471.1907 +     * extends to the character at index <code>endIndex - 1</code>.
471.1908 +     * Thus the length of the substring is <code>endIndex-beginIndex</code>.
471.1909 +     * <p>
471.1910 +     * Examples:
471.1911 +     * <blockquote><pre>
471.1912 +     * "hamburger".substring(4, 8) returns "urge"
471.1913 +     * "smiles".substring(1, 5) returns "mile"
471.1914 +     * </pre></blockquote>
471.1915 +     *
471.1916 +     * @param      beginIndex   the beginning index, inclusive.
471.1917 +     * @param      endIndex     the ending index, exclusive.
471.1918 +     * @return     the specified substring.
471.1919 +     * @exception  IndexOutOfBoundsException  if the
471.1920 +     *             <code>beginIndex</code> is negative, or
471.1921 +     *             <code>endIndex</code> is larger than the length of
471.1922 +     *             this <code>String</code> object, or
471.1923 +     *             <code>beginIndex</code> is larger than
471.1924 +     *             <code>endIndex</code>.
471.1925 +     */
471.1926 +    @JavaScriptBody(args = { "beginIndex", "endIndex" }, body = 
471.1927 +        "return this.toString().substring(beginIndex, endIndex);"
471.1928 +    )
471.1929 +    public String substring(int beginIndex, int endIndex) {
471.1930 +        if (beginIndex < 0) {
471.1931 +            throw new StringIndexOutOfBoundsException(beginIndex);
471.1932 +        }
471.1933 +        if (endIndex > length()) {
471.1934 +            throw new StringIndexOutOfBoundsException(endIndex);
471.1935 +        }
471.1936 +        if (beginIndex > endIndex) {
471.1937 +            throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
471.1938 +        }
471.1939 +        return ((beginIndex == 0) && (endIndex == length())) ? this :
471.1940 +            new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
471.1941 +    }
471.1942 +
471.1943 +    /**
471.1944 +     * Returns a new character sequence that is a subsequence of this sequence.
471.1945 +     *
471.1946 +     * <p> An invocation of this method of the form
471.1947 +     *
471.1948 +     * <blockquote><pre>
471.1949 +     * str.subSequence(begin,&nbsp;end)</pre></blockquote>
471.1950 +     *
471.1951 +     * behaves in exactly the same way as the invocation
471.1952 +     *
471.1953 +     * <blockquote><pre>
471.1954 +     * str.substring(begin,&nbsp;end)</pre></blockquote>
471.1955 +     *
471.1956 +     * This method is defined so that the <tt>String</tt> class can implement
471.1957 +     * the {@link CharSequence} interface. </p>
471.1958 +     *
471.1959 +     * @param      beginIndex   the begin index, inclusive.
471.1960 +     * @param      endIndex     the end index, exclusive.
471.1961 +     * @return     the specified subsequence.
471.1962 +     *
471.1963 +     * @throws  IndexOutOfBoundsException
471.1964 +     *          if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
471.1965 +     *          if <tt>endIndex</tt> is greater than <tt>length()</tt>,
471.1966 +     *          or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
471.1967 +     *
471.1968 +     * @since 1.4
471.1969 +     * @spec JSR-51
471.1970 +     */
471.1971 +    public CharSequence subSequence(int beginIndex, int endIndex) {
471.1972 +        return this.substring(beginIndex, endIndex);
471.1973 +    }
471.1974 +
471.1975 +    /**
471.1976 +     * Concatenates the specified string to the end of this string.
471.1977 +     * <p>
471.1978 +     * If the length of the argument string is <code>0</code>, then this
471.1979 +     * <code>String</code> object is returned. Otherwise, a new
471.1980 +     * <code>String</code> object is created, representing a character
471.1981 +     * sequence that is the concatenation of the character sequence
471.1982 +     * represented by this <code>String</code> object and the character
471.1983 +     * sequence represented by the argument string.<p>
471.1984 +     * Examples:
471.1985 +     * <blockquote><pre>
471.1986 +     * "cares".concat("s") returns "caress"
471.1987 +     * "to".concat("get").concat("her") returns "together"
471.1988 +     * </pre></blockquote>
471.1989 +     *
471.1990 +     * @param   str   the <code>String</code> that is concatenated to the end
471.1991 +     *                of this <code>String</code>.
471.1992 +     * @return  a string that represents the concatenation of this object's
471.1993 +     *          characters followed by the string argument's characters.
471.1994 +     */
471.1995 +    public String concat(String str) {
471.1996 +        int otherLen = str.length();
471.1997 +        if (otherLen == 0) {
471.1998 +            return this;
471.1999 +        }
471.2000 +        char buf[] = new char[length() + otherLen];
471.2001 +        getChars(0, length(), buf, 0);
471.2002 +        str.getChars(0, otherLen, buf, length());
471.2003 +        return new String(buf, 0, length() + otherLen);
471.2004 +    }
471.2005 +
471.2006 +    /**
471.2007 +     * Returns a new string resulting from replacing all occurrences of
471.2008 +     * <code>oldChar</code> in this string with <code>newChar</code>.
471.2009 +     * <p>
471.2010 +     * If the character <code>oldChar</code> does not occur in the
471.2011 +     * character sequence represented by this <code>String</code> object,
471.2012 +     * then a reference to this <code>String</code> object is returned.
471.2013 +     * Otherwise, a new <code>String</code> object is created that
471.2014 +     * represents a character sequence identical to the character sequence
471.2015 +     * represented by this <code>String</code> object, except that every
471.2016 +     * occurrence of <code>oldChar</code> is replaced by an occurrence
471.2017 +     * of <code>newChar</code>.
471.2018 +     * <p>
471.2019 +     * Examples:
471.2020 +     * <blockquote><pre>
471.2021 +     * "mesquite in your cellar".replace('e', 'o')
471.2022 +     *         returns "mosquito in your collar"
471.2023 +     * "the war of baronets".replace('r', 'y')
471.2024 +     *         returns "the way of bayonets"
471.2025 +     * "sparring with a purple porpoise".replace('p', 't')
471.2026 +     *         returns "starring with a turtle tortoise"
471.2027 +     * "JonL".replace('q', 'x') returns "JonL" (no change)
471.2028 +     * </pre></blockquote>
471.2029 +     *
471.2030 +     * @param   oldChar   the old character.
471.2031 +     * @param   newChar   the new character.
471.2032 +     * @return  a string derived from this string by replacing every
471.2033 +     *          occurrence of <code>oldChar</code> with <code>newChar</code>.
471.2034 +     */
471.2035 +    @JavaScriptBody(args = { "arg1", "arg2" }, body =
471.2036 +        "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
471.2037 +        "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
471.2038 +        "var s = this.toString();\n" +
471.2039 +        "for (;;) {\n" +
471.2040 +        "  var ret = s.replace(arg1, arg2);\n" +
471.2041 +        "  if (ret === s) {\n" +
471.2042 +        "    return ret;\n" +
471.2043 +        "  }\n" +
471.2044 +        "  s = ret;\n" +
471.2045 +        "}"
471.2046 +    )
471.2047 +    public String replace(char oldChar, char newChar) {
471.2048 +        if (oldChar != newChar) {
471.2049 +            int len = length();
471.2050 +            int i = -1;
471.2051 +            char[] val = toCharArray(); /* avoid getfield opcode */
471.2052 +            int off = offset();   /* avoid getfield opcode */
471.2053 +
471.2054 +            while (++i < len) {
471.2055 +                if (val[off + i] == oldChar) {
471.2056 +                    break;
471.2057 +                }
471.2058 +            }
471.2059 +            if (i < len) {
471.2060 +                char buf[] = new char[len];
471.2061 +                for (int j = 0 ; j < i ; j++) {
471.2062 +                    buf[j] = val[off+j];
471.2063 +                }
471.2064 +                while (i < len) {
471.2065 +                    char c = val[off + i];
471.2066 +                    buf[i] = (c == oldChar) ? newChar : c;
471.2067 +                    i++;
471.2068 +                }
471.2069 +                return new String(buf, 0, len);
471.2070 +            }
471.2071 +        }
471.2072 +        return this;
471.2073 +    }
471.2074 +
471.2075 +    /**
471.2076 +     * Tells whether or not this string matches the given <a
471.2077 +     * href="../util/regex/Pattern.html#sum">regular expression</a>.
471.2078 +     *
471.2079 +     * <p> An invocation of this method of the form
471.2080 +     * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
471.2081 +     * same result as the expression
471.2082 +     *
471.2083 +     * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
471.2084 +     * java.util.regex.Pattern#matches(String,CharSequence)
471.2085 +     * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
471.2086 +     *
471.2087 +     * @param   regex
471.2088 +     *          the regular expression to which this string is to be matched
471.2089 +     *
471.2090 +     * @return  <tt>true</tt> if, and only if, this string matches the
471.2091 +     *          given regular expression
471.2092 +     *
471.2093 +     * @throws  PatternSyntaxException
471.2094 +     *          if the regular expression's syntax is invalid
471.2095 +     *
471.2096 +     * @see java.util.regex.Pattern
471.2097 +     *
471.2098 +     * @since 1.4
471.2099 +     * @spec JSR-51
471.2100 +     */
471.2101 +    @JavaScriptBody(args = { "regex" }, body = 
471.2102 +          "var self = this.toString();\n"
471.2103 +        + "var re = new RegExp(regex.toString());\n"
471.2104 +        + "var r = re.exec(self);\n"
471.2105 +        + "return r != null && r.length > 0 && self.length == r[0].length;"
471.2106 +    )
471.2107 +    public boolean matches(String regex) {
471.2108 +        throw new UnsupportedOperationException();
471.2109 +    }
471.2110 +
471.2111 +    /**
471.2112 +     * Returns true if and only if this string contains the specified
471.2113 +     * sequence of char values.
471.2114 +     *
471.2115 +     * @param s the sequence to search for
471.2116 +     * @return true if this string contains <code>s</code>, false otherwise
471.2117 +     * @throws NullPointerException if <code>s</code> is <code>null</code>
471.2118 +     * @since 1.5
471.2119 +     */
471.2120 +    public boolean contains(CharSequence s) {
471.2121 +        return indexOf(s.toString()) > -1;
471.2122 +    }
471.2123 +
471.2124 +    /**
471.2125 +     * Replaces the first substring of this string that matches the given <a
471.2126 +     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
471.2127 +     * given replacement.
471.2128 +     *
471.2129 +     * <p> An invocation of this method of the form
471.2130 +     * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
471.2131 +     * yields exactly the same result as the expression
471.2132 +     *
471.2133 +     * <blockquote><tt>
471.2134 +     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
471.2135 +     * compile}(</tt><i>regex</i><tt>).{@link
471.2136 +     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
471.2137 +     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
471.2138 +     * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
471.2139 +     *
471.2140 +     *<p>
471.2141 +     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
471.2142 +     * replacement string may cause the results to be different than if it were
471.2143 +     * being treated as a literal replacement string; see
471.2144 +     * {@link java.util.regex.Matcher#replaceFirst}.
471.2145 +     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
471.2146 +     * meaning of these characters, if desired.
471.2147 +     *
471.2148 +     * @param   regex
471.2149 +     *          the regular expression to which this string is to be matched
471.2150 +     * @param   replacement
471.2151 +     *          the string to be substituted for the first match
471.2152 +     *
471.2153 +     * @return  The resulting <tt>String</tt>
471.2154 +     *
471.2155 +     * @throws  PatternSyntaxException
471.2156 +     *          if the regular expression's syntax is invalid
471.2157 +     *
471.2158 +     * @see java.util.regex.Pattern
471.2159 +     *
471.2160 +     * @since 1.4
471.2161 +     * @spec JSR-51
471.2162 +     */
471.2163 +    public String replaceFirst(String regex, String replacement) {
471.2164 +        throw new UnsupportedOperationException();
471.2165 +    }
471.2166 +
471.2167 +    /**
471.2168 +     * Replaces each substring of this string that matches the given <a
471.2169 +     * href="../util/regex/Pattern.html#sum">regular expression</a> with the
471.2170 +     * given replacement.
471.2171 +     *
471.2172 +     * <p> An invocation of this method of the form
471.2173 +     * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
471.2174 +     * yields exactly the same result as the expression
471.2175 +     *
471.2176 +     * <blockquote><tt>
471.2177 +     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
471.2178 +     * compile}(</tt><i>regex</i><tt>).{@link
471.2179 +     * java.util.regex.Pattern#matcher(java.lang.CharSequence)
471.2180 +     * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
471.2181 +     * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
471.2182 +     *
471.2183 +     *<p>
471.2184 +     * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
471.2185 +     * replacement string may cause the results to be different than if it were
471.2186 +     * being treated as a literal replacement string; see
471.2187 +     * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
471.2188 +     * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
471.2189 +     * meaning of these characters, if desired.
471.2190 +     *
471.2191 +     * @param   regex
471.2192 +     *          the regular expression to which this string is to be matched
471.2193 +     * @param   replacement
471.2194 +     *          the string to be substituted for each match
471.2195 +     *
471.2196 +     * @return  The resulting <tt>String</tt>
471.2197 +     *
471.2198 +     * @throws  PatternSyntaxException
471.2199 +     *          if the regular expression's syntax is invalid
471.2200 +     *
471.2201 +     * @see java.util.regex.Pattern
471.2202 +     *
471.2203 +     * @since 1.4
471.2204 +     * @spec JSR-51
471.2205 +     */
471.2206 +    public String replaceAll(String regex, String replacement) {
471.2207 +        throw new UnsupportedOperationException();
471.2208 +    }
471.2209 +
471.2210 +    /**
471.2211 +     * Replaces each substring of this string that matches the literal target
471.2212 +     * sequence with the specified literal replacement sequence. The
471.2213 +     * replacement proceeds from the beginning of the string to the end, for
471.2214 +     * example, replacing "aa" with "b" in the string "aaa" will result in
471.2215 +     * "ba" rather than "ab".
471.2216 +     *
471.2217 +     * @param  target The sequence of char values to be replaced
471.2218 +     * @param  replacement The replacement sequence of char values
471.2219 +     * @return  The resulting string
471.2220 +     * @throws NullPointerException if <code>target</code> or
471.2221 +     *         <code>replacement</code> is <code>null</code>.
471.2222 +     * @since 1.5
471.2223 +     */
471.2224 +    public String replace(CharSequence target, CharSequence replacement) {
471.2225 +        throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
471.2226 +    }
471.2227 +
471.2228 +    /**
471.2229 +     * Splits this string around matches of the given
471.2230 +     * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
471.2231 +     *
471.2232 +     * <p> The array returned by this method contains each substring of this
471.2233 +     * string that is terminated by another substring that matches the given
471.2234 +     * expression or is terminated by the end of the string.  The substrings in
471.2235 +     * the array are in the order in which they occur in this string.  If the
471.2236 +     * expression does not match any part of the input then the resulting array
471.2237 +     * has just one element, namely this string.
471.2238 +     *
471.2239 +     * <p> The <tt>limit</tt> parameter controls the number of times the
471.2240 +     * pattern is applied and therefore affects the length of the resulting
471.2241 +     * array.  If the limit <i>n</i> is greater than zero then the pattern
471.2242 +     * will be applied at most <i>n</i>&nbsp;-&nbsp;1 times, the array's
471.2243 +     * length will be no greater than <i>n</i>, and the array's last entry
471.2244 +     * will contain all input beyond the last matched delimiter.  If <i>n</i>
471.2245 +     * is non-positive then the pattern will be applied as many times as
471.2246 +     * possible and the array can have any length.  If <i>n</i> is zero then
471.2247 +     * the pattern will be applied as many times as possible, the array can
471.2248 +     * have any length, and trailing empty strings will be discarded.
471.2249 +     *
471.2250 +     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
471.2251 +     * following results with these parameters:
471.2252 +     *
471.2253 +     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
471.2254 +     * <tr>
471.2255 +     *     <th>Regex</th>
471.2256 +     *     <th>Limit</th>
471.2257 +     *     <th>Result</th>
471.2258 +     * </tr>
471.2259 +     * <tr><td align=center>:</td>
471.2260 +     *     <td align=center>2</td>
471.2261 +     *     <td><tt>{ "boo", "and:foo" }</tt></td></tr>
471.2262 +     * <tr><td align=center>:</td>
471.2263 +     *     <td align=center>5</td>
471.2264 +     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
471.2265 +     * <tr><td align=center>:</td>
471.2266 +     *     <td align=center>-2</td>
471.2267 +     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
471.2268 +     * <tr><td align=center>o</td>
471.2269 +     *     <td align=center>5</td>
471.2270 +     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
471.2271 +     * <tr><td align=center>o</td>
471.2272 +     *     <td align=center>-2</td>
471.2273 +     *     <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
471.2274 +     * <tr><td align=center>o</td>
471.2275 +     *     <td align=center>0</td>
471.2276 +     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
471.2277 +     * </table></blockquote>
471.2278 +     *
471.2279 +     * <p> An invocation of this method of the form
471.2280 +     * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
471.2281 +     * yields the same result as the expression
471.2282 +     *
471.2283 +     * <blockquote>
471.2284 +     * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
471.2285 +     * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
471.2286 +     * java.util.regex.Pattern#split(java.lang.CharSequence,int)
471.2287 +     * split}<tt>(</tt><i>str</i><tt>,</tt>&nbsp;<i>n</i><tt>)</tt>
471.2288 +     * </blockquote>
471.2289 +     *
471.2290 +     *
471.2291 +     * @param  regex
471.2292 +     *         the delimiting regular expression
471.2293 +     *
471.2294 +     * @param  limit
471.2295 +     *         the result threshold, as described above
471.2296 +     *
471.2297 +     * @return  the array of strings computed by splitting this string
471.2298 +     *          around matches of the given regular expression
471.2299 +     *
471.2300 +     * @throws  PatternSyntaxException
471.2301 +     *          if the regular expression's syntax is invalid
471.2302 +     *
471.2303 +     * @see java.util.regex.Pattern
471.2304 +     *
471.2305 +     * @since 1.4
471.2306 +     * @spec JSR-51
471.2307 +     */
471.2308 +    public String[] split(String regex, int limit) {
471.2309 +        throw new UnsupportedOperationException("Needs regexp");
471.2310 +    }
471.2311 +
471.2312 +    /**
471.2313 +     * Splits this string around matches of the given <a
471.2314 +     * href="../util/regex/Pattern.html#sum">regular expression</a>.
471.2315 +     *
471.2316 +     * <p> This method works as if by invoking the two-argument {@link
471.2317 +     * #split(String, int) split} method with the given expression and a limit
471.2318 +     * argument of zero.  Trailing empty strings are therefore not included in
471.2319 +     * the resulting array.
471.2320 +     *
471.2321 +     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
471.2322 +     * results with these expressions:
471.2323 +     *
471.2324 +     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
471.2325 +     * <tr>
471.2326 +     *  <th>Regex</th>
471.2327 +     *  <th>Result</th>
471.2328 +     * </tr>
471.2329 +     * <tr><td align=center>:</td>
471.2330 +     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
471.2331 +     * <tr><td align=center>o</td>
471.2332 +     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
471.2333 +     * </table></blockquote>
471.2334 +     *
471.2335 +     *
471.2336 +     * @param  regex
471.2337 +     *         the delimiting regular expression
471.2338 +     *
471.2339 +     * @return  the array of strings computed by splitting this string
471.2340 +     *          around matches of the given regular expression
471.2341 +     *
471.2342 +     * @throws  PatternSyntaxException
471.2343 +     *          if the regular expression's syntax is invalid
471.2344 +     *
471.2345 +     * @see java.util.regex.Pattern
471.2346 +     *
471.2347 +     * @since 1.4
471.2348 +     * @spec JSR-51
471.2349 +     */
471.2350 +    public String[] split(String regex) {
471.2351 +        return split(regex, 0);
471.2352 +    }
471.2353 +
471.2354 +    /**
471.2355 +     * Converts all of the characters in this <code>String</code> to lower
471.2356 +     * case using the rules of the given <code>Locale</code>.  Case mapping is based
471.2357 +     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
471.2358 +     * class. Since case mappings are not always 1:1 char mappings, the resulting
471.2359 +     * <code>String</code> may be a different length than the original <code>String</code>.
471.2360 +     * <p>
471.2361 +     * Examples of lowercase  mappings are in the following table:
471.2362 +     * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
471.2363 +     * <tr>
471.2364 +     *   <th>Language Code of Locale</th>
471.2365 +     *   <th>Upper Case</th>
471.2366 +     *   <th>Lower Case</th>
471.2367 +     *   <th>Description</th>
471.2368 +     * </tr>
471.2369 +     * <tr>
471.2370 +     *   <td>tr (Turkish)</td>
471.2371 +     *   <td>&#92;u0130</td>
471.2372 +     *   <td>&#92;u0069</td>
471.2373 +     *   <td>capital letter I with dot above -&gt; small letter i</td>
471.2374 +     * </tr>
471.2375 +     * <tr>
471.2376 +     *   <td>tr (Turkish)</td>
471.2377 +     *   <td>&#92;u0049</td>
471.2378 +     *   <td>&#92;u0131</td>
471.2379 +     *   <td>capital letter I -&gt; small letter dotless i </td>
471.2380 +     * </tr>
471.2381 +     * <tr>
471.2382 +     *   <td>(all)</td>
471.2383 +     *   <td>French Fries</td>
471.2384 +     *   <td>french fries</td>
471.2385 +     *   <td>lowercased all chars in String</td>
471.2386 +     * </tr>
471.2387 +     * <tr>
471.2388 +     *   <td>(all)</td>
471.2389 +     *   <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
471.2390 +     *       <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
471.2391 +     *       <img src="doc-files/capsigma.gif" alt="capsigma"></td>
471.2392 +     *   <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
471.2393 +     *       <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
471.2394 +     *       <img src="doc-files/sigma1.gif" alt="sigma"></td>
471.2395 +     *   <td>lowercased all chars in String</td>
471.2396 +     * </tr>
471.2397 +     * </table>
471.2398 +     *
471.2399 +     * @param locale use the case transformation rules for this locale
471.2400 +     * @return the <code>String</code>, converted to lowercase.
471.2401 +     * @see     java.lang.String#toLowerCase()
471.2402 +     * @see     java.lang.String#toUpperCase()
471.2403 +     * @see     java.lang.String#toUpperCase(Locale)
471.2404 +     * @since   1.1
471.2405 +     */
471.2406 +//    public String toLowerCase(Locale locale) {
471.2407 +//        if (locale == null) {
471.2408 +//            throw new NullPointerException();
471.2409 +//        }
471.2410 +//
471.2411 +//        int     firstUpper;
471.2412 +//
471.2413 +//        /* Now check if there are any characters that need to be changed. */
471.2414 +//        scan: {
471.2415 +//            for (firstUpper = 0 ; firstUpper < count; ) {
471.2416 +//                char c = value[offset+firstUpper];
471.2417 +//                if ((c >= Character.MIN_HIGH_SURROGATE) &&
471.2418 +//                    (c <= Character.MAX_HIGH_SURROGATE)) {
471.2419 +//                    int supplChar = codePointAt(firstUpper);
471.2420 +//                    if (supplChar != Character.toLowerCase(supplChar)) {
471.2421 +//                        break scan;
471.2422 +//                    }
471.2423 +//                    firstUpper += Character.charCount(supplChar);
471.2424 +//                } else {
471.2425 +//                    if (c != Character.toLowerCase(c)) {
471.2426 +//                        break scan;
471.2427 +//                    }
471.2428 +//                    firstUpper++;
471.2429 +//                }
471.2430 +//            }
471.2431 +//            return this;
471.2432 +//        }
471.2433 +//
471.2434 +//        char[]  result = new char[count];
471.2435 +//        int     resultOffset = 0;  /* result may grow, so i+resultOffset
471.2436 +//                                    * is the write location in result */
471.2437 +//
471.2438 +//        /* Just copy the first few lowerCase characters. */
471.2439 +//        System.arraycopy(value, offset, result, 0, firstUpper);
471.2440 +//
471.2441 +//        String lang = locale.getLanguage();
471.2442 +//        boolean localeDependent =
471.2443 +//            (lang == "tr" || lang == "az" || lang == "lt");
471.2444 +//        char[] lowerCharArray;
471.2445 +//        int lowerChar;
471.2446 +//        int srcChar;
471.2447 +//        int srcCount;
471.2448 +//        for (int i = firstUpper; i < count; i += srcCount) {
471.2449 +//            srcChar = (int)value[offset+i];
471.2450 +//            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
471.2451 +//                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
471.2452 +//                srcChar = codePointAt(i);
471.2453 +//                srcCount = Character.charCount(srcChar);
471.2454 +//            } else {
471.2455 +//                srcCount = 1;
471.2456 +//            }
471.2457 +//            if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
471.2458 +//                lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
471.2459 +//            } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
471.2460 +//                lowerChar = Character.ERROR;
471.2461 +//            } else {
471.2462 +//                lowerChar = Character.toLowerCase(srcChar);
471.2463 +//            }
471.2464 +//            if ((lowerChar == Character.ERROR) ||
471.2465 +//                (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
471.2466 +//                if (lowerChar == Character.ERROR) {
471.2467 +//                     if (!localeDependent && srcChar == '\u0130') {
471.2468 +//                         lowerCharArray =
471.2469 +//                             ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
471.2470 +//                     } else {
471.2471 +//                        lowerCharArray =
471.2472 +//                            ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
471.2473 +//                     }
471.2474 +//                } else if (srcCount == 2) {
471.2475 +//                    resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
471.2476 +//                    continue;
471.2477 +//                } else {
471.2478 +//                    lowerCharArray = Character.toChars(lowerChar);
471.2479 +//                }
471.2480 +//
471.2481 +//                /* Grow result if needed */
471.2482 +//                int mapLen = lowerCharArray.length;
471.2483 +//                if (mapLen > srcCount) {
471.2484 +//                    char[] result2 = new char[result.length + mapLen - srcCount];
471.2485 +//                    System.arraycopy(result, 0, result2, 0,
471.2486 +//                        i + resultOffset);
471.2487 +//                    result = result2;
471.2488 +//                }
471.2489 +//                for (int x=0; x<mapLen; ++x) {
471.2490 +//                    result[i+resultOffset+x] = lowerCharArray[x];
471.2491 +//                }
471.2492 +//                resultOffset += (mapLen - srcCount);
471.2493 +//            } else {
471.2494 +//                result[i+resultOffset] = (char)lowerChar;
471.2495 +//            }
471.2496 +//        }
471.2497 +//        return new String(0, count+resultOffset, result);
471.2498 +//    }
471.2499 +
471.2500 +    /**
471.2501 +     * Converts all of the characters in this <code>String</code> to lower
471.2502 +     * case using the rules of the default locale. This is equivalent to calling
471.2503 +     * <code>toLowerCase(Locale.getDefault())</code>.
471.2504 +     * <p>
471.2505 +     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
471.2506 +     * results if used for strings that are intended to be interpreted locale
471.2507 +     * independently.
471.2508 +     * Examples are programming language identifiers, protocol keys, and HTML
471.2509 +     * tags.
471.2510 +     * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
471.2511 +     * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
471.2512 +     * LATIN SMALL LETTER DOTLESS I character.
471.2513 +     * To obtain correct results for locale insensitive strings, use
471.2514 +     * <code>toLowerCase(Locale.ENGLISH)</code>.
471.2515 +     * <p>
471.2516 +     * @return  the <code>String</code>, converted to lowercase.
471.2517 +     * @see     java.lang.String#toLowerCase(Locale)
471.2518 +     */
471.2519 +    @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
471.2520 +    public String toLowerCase() {
471.2521 +        throw new UnsupportedOperationException("Should be supported but without connection to locale");
471.2522 +    }
471.2523 +
471.2524 +    /**
471.2525 +     * Converts all of the characters in this <code>String</code> to upper
471.2526 +     * case using the rules of the given <code>Locale</code>. Case mapping is based
471.2527 +     * on the Unicode Standard version specified by the {@link java.lang.Character Character}
471.2528 +     * class. Since case mappings are not always 1:1 char mappings, the resulting
471.2529 +     * <code>String</code> may be a different length than the original <code>String</code>.
471.2530 +     * <p>
471.2531 +     * Examples of locale-sensitive and 1:M case mappings are in the following table.
471.2532 +     * <p>
471.2533 +     * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
471.2534 +     * <tr>
471.2535 +     *   <th>Language Code of Locale</th>
471.2536 +     *   <th>Lower Case</th>
471.2537 +     *   <th>Upper Case</th>
471.2538 +     *   <th>Description</th>
471.2539 +     * </tr>
471.2540 +     * <tr>
471.2541 +     *   <td>tr (Turkish)</td>
471.2542 +     *   <td>&#92;u0069</td>
471.2543 +     *   <td>&#92;u0130</td>
471.2544 +     *   <td>small letter i -&gt; capital letter I with dot above</td>
471.2545 +     * </tr>
471.2546 +     * <tr>
471.2547 +     *   <td>tr (Turkish)</td>
471.2548 +     *   <td>&#92;u0131</td>
471.2549 +     *   <td>&#92;u0049</td>
471.2550 +     *   <td>small letter dotless i -&gt; capital letter I</td>
471.2551 +     * </tr>
471.2552 +     * <tr>
471.2553 +     *   <td>(all)</td>
471.2554 +     *   <td>&#92;u00df</td>
471.2555 +     *   <td>&#92;u0053 &#92;u0053</td>
471.2556 +     *   <td>small letter sharp s -&gt; two letters: SS</td>
471.2557 +     * </tr>
471.2558 +     * <tr>
471.2559 +     *   <td>(all)</td>
471.2560 +     *   <td>Fahrvergn&uuml;gen</td>
471.2561 +     *   <td>FAHRVERGN&Uuml;GEN</td>
471.2562 +     *   <td></td>
471.2563 +     * </tr>
471.2564 +     * </table>
471.2565 +     * @param locale use the case transformation rules for this locale
471.2566 +     * @return the <code>String</code>, converted to uppercase.
471.2567 +     * @see     java.lang.String#toUpperCase()
471.2568 +     * @see     java.lang.String#toLowerCase()
471.2569 +     * @see     java.lang.String#toLowerCase(Locale)
471.2570 +     * @since   1.1
471.2571 +     */
471.2572 +    /* not for javascript 
471.2573 +    public String toUpperCase(Locale locale) {
471.2574 +        if (locale == null) {
471.2575 +            throw new NullPointerException();
471.2576 +        }
471.2577 +
471.2578 +        int     firstLower;
471.2579 +
471.2580 +        // Now check if there are any characters that need to be changed. 
471.2581 +        scan: {
471.2582 +            for (firstLower = 0 ; firstLower < count; ) {
471.2583 +                int c = (int)value[offset+firstLower];
471.2584 +                int srcCount;
471.2585 +                if ((c >= Character.MIN_HIGH_SURROGATE) &&
471.2586 +                    (c <= Character.MAX_HIGH_SURROGATE)) {
471.2587 +                    c = codePointAt(firstLower);
471.2588 +                    srcCount = Character.charCount(c);
471.2589 +                } else {
471.2590 +                    srcCount = 1;
471.2591 +                }
471.2592 +                int upperCaseChar = Character.toUpperCaseEx(c);
471.2593 +                if ((upperCaseChar == Character.ERROR) ||
471.2594 +                    (c != upperCaseChar)) {
471.2595 +                    break scan;
471.2596 +                }
471.2597 +                firstLower += srcCount;
471.2598 +            }
471.2599 +            return this;
471.2600 +        }
471.2601 +
471.2602 +        char[]  result       = new char[count]; /* may grow *
471.2603 +        int     resultOffset = 0;  /* result may grow, so i+resultOffset
471.2604 +                                    * is the write location in result *
471.2605 +
471.2606 +        /* Just copy the first few upperCase characters. *
471.2607 +        System.arraycopy(value, offset, result, 0, firstLower);
471.2608 +
471.2609 +        String lang = locale.getLanguage();
471.2610 +        boolean localeDependent =
471.2611 +            (lang == "tr" || lang == "az" || lang == "lt");
471.2612 +        char[] upperCharArray;
471.2613 +        int upperChar;
471.2614 +        int srcChar;
471.2615 +        int srcCount;
471.2616 +        for (int i = firstLower; i < count; i += srcCount) {
471.2617 +            srcChar = (int)value[offset+i];
471.2618 +            if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
471.2619 +                (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
471.2620 +                srcChar = codePointAt(i);
471.2621 +                srcCount = Character.charCount(srcChar);
471.2622 +            } else {
471.2623 +                srcCount = 1;
471.2624 +            }
471.2625 +            if (localeDependent) {
471.2626 +                upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
471.2627 +            } else {
471.2628 +                upperChar = Character.toUpperCaseEx(srcChar);
471.2629 +            }
471.2630 +            if ((upperChar == Character.ERROR) ||
471.2631 +                (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
471.2632 +                if (upperChar == Character.ERROR) {
471.2633 +                    if (localeDependent) {
471.2634 +                        upperCharArray =
471.2635 +                            ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
471.2636 +                    } else {
471.2637 +                        upperCharArray = Character.toUpperCaseCharArray(srcChar);
471.2638 +                    }
471.2639 +                } else if (srcCount == 2) {
471.2640 +                    resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
471.2641 +                    continue;
471.2642 +                } else {
471.2643 +                    upperCharArray = Character.toChars(upperChar);
471.2644 +                }
471.2645 +
471.2646 +                /* Grow result if needed *
471.2647 +                int mapLen = upperCharArray.length;
471.2648 +                if (mapLen > srcCount) {
471.2649 +                    char[] result2 = new char[result.length + mapLen - srcCount];
471.2650 +                    System.arraycopy(result, 0, result2, 0,
471.2651 +                        i + resultOffset);
471.2652 +                    result = result2;
471.2653 +                }
471.2654 +                for (int x=0; x<mapLen; ++x) {
471.2655 +                    result[i+resultOffset+x] = upperCharArray[x];
471.2656 +                }
471.2657 +                resultOffset += (mapLen - srcCount);
471.2658 +            } else {
471.2659 +                result[i+resultOffset] = (char)upperChar;
471.2660 +            }
471.2661 +        }
471.2662 +        return new String(0, count+resultOffset, result);
471.2663 +    }
471.2664 +    */
471.2665 +
471.2666 +    /**
471.2667 +     * Converts all of the characters in this <code>String</code> to upper
471.2668 +     * case using the rules of the default locale. This method is equivalent to
471.2669 +     * <code>toUpperCase(Locale.getDefault())</code>.
471.2670 +     * <p>
471.2671 +     * <b>Note:</b> This method is locale sensitive, and may produce unexpected
471.2672 +     * results if used for strings that are intended to be interpreted locale
471.2673 +     * independently.
471.2674 +     * Examples are programming language identifiers, protocol keys, and HTML
471.2675 +     * tags.
471.2676 +     * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
471.2677 +     * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
471.2678 +     * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
471.2679 +     * To obtain correct results for locale insensitive strings, use
471.2680 +     * <code>toUpperCase(Locale.ENGLISH)</code>.
471.2681 +     * <p>
471.2682 +     * @return  the <code>String</code>, converted to uppercase.
471.2683 +     * @see     java.lang.String#toUpperCase(Locale)
471.2684 +     */
471.2685 +    @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
471.2686 +    public String toUpperCase() {
471.2687 +        throw new UnsupportedOperationException();
471.2688 +    }
471.2689 +
471.2690 +    /**
471.2691 +     * Returns a copy of the string, with leading and trailing whitespace
471.2692 +     * omitted.
471.2693 +     * <p>
471.2694 +     * If this <code>String</code> object represents an empty character
471.2695 +     * sequence, or the first and last characters of character sequence
471.2696 +     * represented by this <code>String</code> object both have codes
471.2697 +     * greater than <code>'&#92;u0020'</code> (the space character), then a
471.2698 +     * reference to this <code>String</code> object is returned.
471.2699 +     * <p>
471.2700 +     * Otherwise, if there is no character with a code greater than
471.2701 +     * <code>'&#92;u0020'</code> in the string, then a new
471.2702 +     * <code>String</code> object representing an empty string is created
471.2703 +     * and returned.
471.2704 +     * <p>
471.2705 +     * Otherwise, let <i>k</i> be the index of the first character in the
471.2706 +     * string whose code is greater than <code>'&#92;u0020'</code>, and let
471.2707 +     * <i>m</i> be the index of the last character in the string whose code
471.2708 +     * is greater than <code>'&#92;u0020'</code>. A new <code>String</code>
471.2709 +     * object is created, representing the substring of this string that
471.2710 +     * begins with the character at index <i>k</i> and ends with the
471.2711 +     * character at index <i>m</i>-that is, the result of
471.2712 +     * <code>this.substring(<i>k</i>,&nbsp;<i>m</i>+1)</code>.
471.2713 +     * <p>
471.2714 +     * This method may be used to trim whitespace (as defined above) from
471.2715 +     * the beginning and end of a string.
471.2716 +     *
471.2717 +     * @return  A copy of this string with leading and trailing white
471.2718 +     *          space removed, or this string if it has no leading or
471.2719 +     *          trailing white space.
471.2720 +     */
471.2721 +    public String trim() {
471.2722 +        int len = length();
471.2723 +        int st = 0;
471.2724 +        int off = offset();      /* avoid getfield opcode */
471.2725 +        char[] val = toCharArray();    /* avoid getfield opcode */
471.2726 +
471.2727 +        while ((st < len) && (val[off + st] <= ' ')) {
471.2728 +            st++;
471.2729 +        }
471.2730 +        while ((st < len) && (val[off + len - 1] <= ' ')) {
471.2731 +            len--;
471.2732 +        }
471.2733 +        return ((st > 0) || (len < length())) ? substring(st, len) : this;
471.2734 +    }
471.2735 +
471.2736 +    /**
471.2737 +     * This object (which is already a string!) is itself returned.
471.2738 +     *
471.2739 +     * @return  the string itself.
471.2740 +     */
471.2741 +    @JavaScriptBody(args = {}, body = "return this.toString();")
471.2742 +    public String toString() {
471.2743 +        return this;
471.2744 +    }
471.2745 +
471.2746 +    /**
471.2747 +     * Converts this string to a new character array.
471.2748 +     *
471.2749 +     * @return  a newly allocated character array whose length is the length
471.2750 +     *          of this string and whose contents are initialized to contain
471.2751 +     *          the character sequence represented by this string.
471.2752 +     */
471.2753 +    public char[] toCharArray() {
471.2754 +        char result[] = new char[length()];
471.2755 +        getChars(0, length(), result, 0);
471.2756 +        return result;
471.2757 +    }
471.2758 +
471.2759 +    /**
471.2760 +     * Returns a formatted string using the specified format string and
471.2761 +     * arguments.
471.2762 +     *
471.2763 +     * <p> The locale always used is the one returned by {@link
471.2764 +     * java.util.Locale#getDefault() Locale.getDefault()}.
471.2765 +     *
471.2766 +     * @param  format
471.2767 +     *         A <a href="../util/Formatter.html#syntax">format string</a>
471.2768 +     *
471.2769 +     * @param  args
471.2770 +     *         Arguments referenced by the format specifiers in the format
471.2771 +     *         string.  If there are more arguments than format specifiers, the
471.2772 +     *         extra arguments are ignored.  The number of arguments is
471.2773 +     *         variable and may be zero.  The maximum number of arguments is
471.2774 +     *         limited by the maximum dimension of a Java array as defined by
471.2775 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
471.2776 +     *         The behaviour on a
471.2777 +     *         <tt>null</tt> argument depends on the <a
471.2778 +     *         href="../util/Formatter.html#syntax">conversion</a>.
471.2779 +     *
471.2780 +     * @throws  IllegalFormatException
471.2781 +     *          If a format string contains an illegal syntax, a format
471.2782 +     *          specifier that is incompatible with the given arguments,
471.2783 +     *          insufficient arguments given the format string, or other
471.2784 +     *          illegal conditions.  For specification of all possible
471.2785 +     *          formatting errors, see the <a
471.2786 +     *          href="../util/Formatter.html#detail">Details</a> section of the
471.2787 +     *          formatter class specification.
471.2788 +     *
471.2789 +     * @throws  NullPointerException
471.2790 +     *          If the <tt>format</tt> is <tt>null</tt>
471.2791 +     *
471.2792 +     * @return  A formatted string
471.2793 +     *
471.2794 +     * @see  java.util.Formatter
471.2795 +     * @since  1.5
471.2796 +     */
471.2797 +    public static String format(String format, Object ... args) {
471.2798 +        throw new UnsupportedOperationException();
471.2799 +    }
471.2800 +
471.2801 +    /**
471.2802 +     * Returns a formatted string using the specified locale, format string,
471.2803 +     * and arguments.
471.2804 +     *
471.2805 +     * @param  l
471.2806 +     *         The {@linkplain java.util.Locale locale} to apply during
471.2807 +     *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
471.2808 +     *         is applied.
471.2809 +     *
471.2810 +     * @param  format
471.2811 +     *         A <a href="../util/Formatter.html#syntax">format string</a>
471.2812 +     *
471.2813 +     * @param  args
471.2814 +     *         Arguments referenced by the format specifiers in the format
471.2815 +     *         string.  If there are more arguments than format specifiers, the
471.2816 +     *         extra arguments are ignored.  The number of arguments is
471.2817 +     *         variable and may be zero.  The maximum number of arguments is
471.2818 +     *         limited by the maximum dimension of a Java array as defined by
471.2819 +     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
471.2820 +     *         The behaviour on a
471.2821 +     *         <tt>null</tt> argument depends on the <a
471.2822 +     *         href="../util/Formatter.html#syntax">conversion</a>.
471.2823 +     *
471.2824 +     * @throws  IllegalFormatException
471.2825 +     *          If a format string contains an illegal syntax, a format
471.2826 +     *          specifier that is incompatible with the given arguments,
471.2827 +     *          insufficient arguments given the format string, or other
471.2828 +     *          illegal conditions.  For specification of all possible
471.2829 +     *          formatting errors, see the <a
471.2830 +     *          href="../util/Formatter.html#detail">Details</a> section of the
471.2831 +     *          formatter class specification
471.2832 +     *
471.2833 +     * @throws  NullPointerException
471.2834 +     *          If the <tt>format</tt> is <tt>null</tt>
471.2835 +     *
471.2836 +     * @return  A formatted string
471.2837 +     *
471.2838 +     * @see  java.util.Formatter
471.2839 +     * @since  1.5
471.2840 +     */
471.2841 +//    public static String format(Locale l, String format, Object ... args) {
471.2842 +//        return new Formatter(l).format(format, args).toString();
471.2843 +//    }
471.2844 +
471.2845 +    /**
471.2846 +     * Returns the string representation of the <code>Object</code> argument.
471.2847 +     *
471.2848 +     * @param   obj   an <code>Object</code>.
471.2849 +     * @return  if the argument is <code>null</code>, then a string equal to
471.2850 +     *          <code>"null"</code>; otherwise, the value of
471.2851 +     *          <code>obj.toString()</code> is returned.
471.2852 +     * @see     java.lang.Object#toString()
471.2853 +     */
471.2854 +    public static String valueOf(Object obj) {
471.2855 +        return (obj == null) ? "null" : obj.toString();
471.2856 +    }
471.2857 +
471.2858 +    /**
471.2859 +     * Returns the string representation of the <code>char</code> array
471.2860 +     * argument. The contents of the character array are copied; subsequent
471.2861 +     * modification of the character array does not affect the newly
471.2862 +     * created string.
471.2863 +     *
471.2864 +     * @param   data   a <code>char</code> array.
471.2865 +     * @return  a newly allocated string representing the same sequence of
471.2866 +     *          characters contained in the character array argument.
471.2867 +     */
471.2868 +    public static String valueOf(char data[]) {
471.2869 +        return new String(data);
471.2870 +    }
471.2871 +
471.2872 +    /**
471.2873 +     * Returns the string representation of a specific subarray of the
471.2874 +     * <code>char</code> array argument.
471.2875 +     * <p>
471.2876 +     * The <code>offset</code> argument is the index of the first
471.2877 +     * character of the subarray. The <code>count</code> argument
471.2878 +     * specifies the length of the subarray. The contents of the subarray
471.2879 +     * are copied; subsequent modification of the character array does not
471.2880 +     * affect the newly created string.
471.2881 +     *
471.2882 +     * @param   data     the character array.
471.2883 +     * @param   offset   the initial offset into the value of the
471.2884 +     *                  <code>String</code>.
471.2885 +     * @param   count    the length of the value of the <code>String</code>.
471.2886 +     * @return  a string representing the sequence of characters contained
471.2887 +     *          in the subarray of the character array argument.
471.2888 +     * @exception IndexOutOfBoundsException if <code>offset</code> is
471.2889 +     *          negative, or <code>count</code> is negative, or
471.2890 +     *          <code>offset+count</code> is larger than
471.2891 +     *          <code>data.length</code>.
471.2892 +     */
471.2893 +    public static String valueOf(char data[], int offset, int count) {
471.2894 +        return new String(data, offset, count);
471.2895 +    }
471.2896 +
471.2897 +    /**
471.2898 +     * Returns a String that represents the character sequence in the
471.2899 +     * array specified.
471.2900 +     *
471.2901 +     * @param   data     the character array.
471.2902 +     * @param   offset   initial offset of the subarray.
471.2903 +     * @param   count    length of the subarray.
471.2904 +     * @return  a <code>String</code> that contains the characters of the
471.2905 +     *          specified subarray of the character array.
471.2906 +     */
471.2907 +    public static String copyValueOf(char data[], int offset, int count) {
471.2908 +        // All public String constructors now copy the data.
471.2909 +        return new String(data, offset, count);
471.2910 +    }
471.2911 +
471.2912 +    /**
471.2913 +     * Returns a String that represents the character sequence in the
471.2914 +     * array specified.
471.2915 +     *
471.2916 +     * @param   data   the character array.
471.2917 +     * @return  a <code>String</code> that contains the characters of the
471.2918 +     *          character array.
471.2919 +     */
471.2920 +    public static String copyValueOf(char data[]) {
471.2921 +        return copyValueOf(data, 0, data.length);
471.2922 +    }
471.2923 +
471.2924 +    /**
471.2925 +     * Returns the string representation of the <code>boolean</code> argument.
471.2926 +     *
471.2927 +     * @param   b   a <code>boolean</code>.
471.2928 +     * @return  if the argument is <code>true</code>, a string equal to
471.2929 +     *          <code>"true"</code> is returned; otherwise, a string equal to
471.2930 +     *          <code>"false"</code> is returned.
471.2931 +     */
471.2932 +    public static String valueOf(boolean b) {
471.2933 +        return b ? "true" : "false";
471.2934 +    }
471.2935 +
471.2936 +    /**
471.2937 +     * Returns the string representation of the <code>char</code>
471.2938 +     * argument.
471.2939 +     *
471.2940 +     * @param   c   a <code>char</code>.
471.2941 +     * @return  a string of length <code>1</code> containing
471.2942 +     *          as its single character the argument <code>c</code>.
471.2943 +     */
471.2944 +    public static String valueOf(char c) {
471.2945 +        char data[] = {c};
471.2946 +        return new String(data, 0, 1);
471.2947 +    }
471.2948 +
471.2949 +    /**
471.2950 +     * Returns the string representation of the <code>int</code> argument.
471.2951 +     * <p>
471.2952 +     * The representation is exactly the one returned by the
471.2953 +     * <code>Integer.toString</code> method of one argument.
471.2954 +     *
471.2955 +     * @param   i   an <code>int</code>.
471.2956 +     * @return  a string representation of the <code>int</code> argument.
471.2957 +     * @see     java.lang.Integer#toString(int, int)
471.2958 +     */
471.2959 +    public static String valueOf(int i) {
471.2960 +        return Integer.toString(i);
471.2961 +    }
471.2962 +
471.2963 +    /**
471.2964 +     * Returns the string representation of the <code>long</code> argument.
471.2965 +     * <p>
471.2966 +     * The representation is exactly the one returned by the
471.2967 +     * <code>Long.toString</code> method of one argument.
471.2968 +     *
471.2969 +     * @param   l   a <code>long</code>.
471.2970 +     * @return  a string representation of the <code>long</code> argument.
471.2971 +     * @see     java.lang.Long#toString(long)
471.2972 +     */
471.2973 +    public static String valueOf(long l) {
471.2974 +        return Long.toString(l);
471.2975 +    }
471.2976 +
471.2977 +    /**
471.2978 +     * Returns the string representation of the <code>float</code> argument.
471.2979 +     * <p>
471.2980 +     * The representation is exactly the one returned by the
471.2981 +     * <code>Float.toString</code> method of one argument.
471.2982 +     *
471.2983 +     * @param   f   a <code>float</code>.
471.2984 +     * @return  a string representation of the <code>float</code> argument.
471.2985 +     * @see     java.lang.Float#toString(float)
471.2986 +     */
471.2987 +    public static String valueOf(float f) {
471.2988 +        return Float.toString(f);
471.2989 +    }
471.2990 +
471.2991 +    /**
471.2992 +     * Returns the string representation of the <code>double</code> argument.
471.2993 +     * <p>
471.2994 +     * The representation is exactly the one returned by the
471.2995 +     * <code>Double.toString</code> method of one argument.
471.2996 +     *
471.2997 +     * @param   d   a <code>double</code>.
471.2998 +     * @return  a  string representation of the <code>double</code> argument.
471.2999 +     * @see     java.lang.Double#toString(double)
471.3000 +     */
471.3001 +    public static String valueOf(double d) {
471.3002 +        return Double.toString(d);
471.3003 +    }
471.3004 +
471.3005 +    /**
471.3006 +     * Returns a canonical representation for the string object.
471.3007 +     * <p>
471.3008 +     * A pool of strings, initially empty, is maintained privately by the
471.3009 +     * class <code>String</code>.
471.3010 +     * <p>
471.3011 +     * When the intern method is invoked, if the pool already contains a
471.3012 +     * string equal to this <code>String</code> object as determined by
471.3013 +     * the {@link #equals(Object)} method, then the string from the pool is
471.3014 +     * returned. Otherwise, this <code>String</code> object is added to the
471.3015 +     * pool and a reference to this <code>String</code> object is returned.
471.3016 +     * <p>
471.3017 +     * It follows that for any two strings <code>s</code> and <code>t</code>,
471.3018 +     * <code>s.intern()&nbsp;==&nbsp;t.intern()</code> is <code>true</code>
471.3019 +     * if and only if <code>s.equals(t)</code> is <code>true</code>.
471.3020 +     * <p>
471.3021 +     * All literal strings and string-valued constant expressions are
471.3022 +     * interned. String literals are defined in section 3.10.5 of the
471.3023 +     * <cite>The Java&trade; Language Specification</cite>.
471.3024 +     *
471.3025 +     * @return  a string that has the same contents as this string, but is
471.3026 +     *          guaranteed to be from a pool of unique strings.
471.3027 +     */
471.3028 +    public native String intern();
471.3029 +    
471.3030 +    
471.3031 +    private static <T> T checkUTF8(T data, String charsetName)
471.3032 +        throws UnsupportedEncodingException {
471.3033 +        if (charsetName == null) {
471.3034 +            throw new NullPointerException("charsetName");
471.3035 +        }
471.3036 +        if (!charsetName.equalsIgnoreCase("UTF-8")
471.3037 +            && !charsetName.equalsIgnoreCase("UTF8")) {
471.3038 +            throw new UnsupportedEncodingException(charsetName);
471.3039 +        }
471.3040 +        return data;
471.3041 +    }
471.3042 +    
471.3043 +    private static int nextChar(byte[] arr, int[] index) throws IndexOutOfBoundsException {
471.3044 +        int c = arr[index[0]++] & 0xff;
471.3045 +        switch (c >> 4) {
471.3046 +            case 0:
471.3047 +            case 1:
471.3048 +            case 2:
471.3049 +            case 3:
471.3050 +            case 4:
471.3051 +            case 5:
471.3052 +            case 6:
471.3053 +            case 7:
471.3054 +                /* 0xxxxxxx*/
471.3055 +                return c;
471.3056 +            case 12:
471.3057 +            case 13: {
471.3058 +                /* 110x xxxx   10xx xxxx*/
471.3059 +                int char2 = (int) arr[index[0]++];
471.3060 +                if ((char2 & 0xC0) != 0x80) {
471.3061 +                    throw new IndexOutOfBoundsException("malformed input");
471.3062 +                }
471.3063 +                return (((c & 0x1F) << 6) | (char2 & 0x3F));
471.3064 +            }
471.3065 +            case 14: {
471.3066 +                /* 1110 xxxx  10xx xxxx  10xx xxxx */
471.3067 +                int char2 = arr[index[0]++];
471.3068 +                int char3 = arr[index[0]++];
471.3069 +                if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
471.3070 +                    throw new IndexOutOfBoundsException("malformed input");
471.3071 +                }
471.3072 +                return (((c & 0x0F) << 12)
471.3073 +                    | ((char2 & 0x3F) << 6)
471.3074 +                    | ((char3 & 0x3F) << 0));
471.3075 +            }
471.3076 +            default:
471.3077 +                /* 10xx xxxx,  1111 xxxx */
471.3078 +                throw new IndexOutOfBoundsException("malformed input");
471.3079 +        }
471.3080 +        
471.3081 +    }
471.3082 +}
   472.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   472.2 +++ b/rt/emul/mini/src/main/java/java/lang/StringBuffer.java	Wed Feb 27 11:24:58 2013 +0100
   472.3 @@ -0,0 +1,604 @@
   472.4 +/*
   472.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   472.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   472.7 + *
   472.8 + * This code is free software; you can redistribute it and/or modify it
   472.9 + * under the terms of the GNU General Public License version 2 only, as
  472.10 + * published by the Free Software Foundation.  Oracle designates this
  472.11 + * particular file as subject to the "Classpath" exception as provided
  472.12 + * by Oracle in the LICENSE file that accompanied this code.
  472.13 + *
  472.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  472.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  472.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  472.17 + * version 2 for more details (a copy is included in the LICENSE file that
  472.18 + * accompanied this code).
  472.19 + *
  472.20 + * You should have received a copy of the GNU General Public License version
  472.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  472.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  472.23 + *
  472.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  472.25 + * or visit www.oracle.com if you need additional information or have any
  472.26 + * questions.
  472.27 + */
  472.28 +
  472.29 +package java.lang;
  472.30 +
  472.31 +
  472.32 +/**
  472.33 + * A thread-safe, mutable sequence of characters.
  472.34 + * A string buffer is like a {@link String}, but can be modified. At any
  472.35 + * point in time it contains some particular sequence of characters, but
  472.36 + * the length and content of the sequence can be changed through certain
  472.37 + * method calls.
  472.38 + * <p>
  472.39 + * String buffers are safe for use by multiple threads. The methods
  472.40 + * are synchronized where necessary so that all the operations on any
  472.41 + * particular instance behave as if they occur in some serial order
  472.42 + * that is consistent with the order of the method calls made by each of
  472.43 + * the individual threads involved.
  472.44 + * <p>
  472.45 + * The principal operations on a <code>StringBuffer</code> are the
  472.46 + * <code>append</code> and <code>insert</code> methods, which are
  472.47 + * overloaded so as to accept data of any type. Each effectively
  472.48 + * converts a given datum to a string and then appends or inserts the
  472.49 + * characters of that string to the string buffer. The
  472.50 + * <code>append</code> method always adds these characters at the end
  472.51 + * of the buffer; the <code>insert</code> method adds the characters at
  472.52 + * a specified point.
  472.53 + * <p>
  472.54 + * For example, if <code>z</code> refers to a string buffer object
  472.55 + * whose current contents are "<code>start</code>", then
  472.56 + * the method call <code>z.append("le")</code> would cause the string
  472.57 + * buffer to contain "<code>startle</code>", whereas
  472.58 + * <code>z.insert(4, "le")</code> would alter the string buffer to
  472.59 + * contain "<code>starlet</code>".
  472.60 + * <p>
  472.61 + * In general, if sb refers to an instance of a <code>StringBuffer</code>,
  472.62 + * then <code>sb.append(x)</code> has the same effect as
  472.63 + * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  472.64 + * <p>
  472.65 + * Whenever an operation occurs involving a source sequence (such as
  472.66 + * appending or inserting from a source sequence) this class synchronizes
  472.67 + * only on the string buffer performing the operation, not on the source.
  472.68 + * <p>
  472.69 + * Every string buffer has a capacity. As long as the length of the
  472.70 + * character sequence contained in the string buffer does not exceed
  472.71 + * the capacity, it is not necessary to allocate a new internal
  472.72 + * buffer array. If the internal buffer overflows, it is
  472.73 + * automatically made larger.
  472.74 + *
  472.75 + * As of  release JDK 5, this class has been supplemented with an equivalent
  472.76 + * class designed for use by a single thread, {@link StringBuilder}.  The
  472.77 + * <tt>StringBuilder</tt> class should generally be used in preference to
  472.78 + * this one, as it supports all of the same operations but it is faster, as
  472.79 + * it performs no synchronization.
  472.80 + *
  472.81 + * @author      Arthur van Hoff
  472.82 + * @see     java.lang.StringBuilder
  472.83 + * @see     java.lang.String
  472.84 + * @since   JDK1.0
  472.85 + */
  472.86 + public final class StringBuffer
  472.87 +    extends AbstractStringBuilder
  472.88 +    implements java.io.Serializable, CharSequence
  472.89 +{
  472.90 +
  472.91 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
  472.92 +    static final long serialVersionUID = 3388685877147921107L;
  472.93 +
  472.94 +    /**
  472.95 +     * Constructs a string buffer with no characters in it and an
  472.96 +     * initial capacity of 16 characters.
  472.97 +     */
  472.98 +    public StringBuffer() {
  472.99 +        super(16);
 472.100 +    }
 472.101 +
 472.102 +    /**
 472.103 +     * Constructs a string buffer with no characters in it and
 472.104 +     * the specified initial capacity.
 472.105 +     *
 472.106 +     * @param      capacity  the initial capacity.
 472.107 +     * @exception  NegativeArraySizeException  if the <code>capacity</code>
 472.108 +     *               argument is less than <code>0</code>.
 472.109 +     */
 472.110 +    public StringBuffer(int capacity) {
 472.111 +        super(capacity);
 472.112 +    }
 472.113 +
 472.114 +    /**
 472.115 +     * Constructs a string buffer initialized to the contents of the
 472.116 +     * specified string. The initial capacity of the string buffer is
 472.117 +     * <code>16</code> plus the length of the string argument.
 472.118 +     *
 472.119 +     * @param   str   the initial contents of the buffer.
 472.120 +     * @exception NullPointerException if <code>str</code> is <code>null</code>
 472.121 +     */
 472.122 +    public StringBuffer(String str) {
 472.123 +        super(str.length() + 16);
 472.124 +        append(str);
 472.125 +    }
 472.126 +
 472.127 +    /**
 472.128 +     * Constructs a string buffer that contains the same characters
 472.129 +     * as the specified <code>CharSequence</code>. The initial capacity of
 472.130 +     * the string buffer is <code>16</code> plus the length of the
 472.131 +     * <code>CharSequence</code> argument.
 472.132 +     * <p>
 472.133 +     * If the length of the specified <code>CharSequence</code> is
 472.134 +     * less than or equal to zero, then an empty buffer of capacity
 472.135 +     * <code>16</code> is returned.
 472.136 +     *
 472.137 +     * @param      seq   the sequence to copy.
 472.138 +     * @exception NullPointerException if <code>seq</code> is <code>null</code>
 472.139 +     * @since 1.5
 472.140 +     */
 472.141 +    public StringBuffer(CharSequence seq) {
 472.142 +        this(seq.length() + 16);
 472.143 +        append(seq);
 472.144 +    }
 472.145 +
 472.146 +    public synchronized int length() {
 472.147 +        return count;
 472.148 +    }
 472.149 +
 472.150 +    public synchronized int capacity() {
 472.151 +        return value.length;
 472.152 +    }
 472.153 +
 472.154 +
 472.155 +    public synchronized void ensureCapacity(int minimumCapacity) {
 472.156 +        if (minimumCapacity > value.length) {
 472.157 +            expandCapacity(minimumCapacity);
 472.158 +        }
 472.159 +    }
 472.160 +
 472.161 +    /**
 472.162 +     * @since      1.5
 472.163 +     */
 472.164 +    public synchronized void trimToSize() {
 472.165 +        super.trimToSize();
 472.166 +    }
 472.167 +
 472.168 +    /**
 472.169 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.170 +     * @see        #length()
 472.171 +     */
 472.172 +    public synchronized void setLength(int newLength) {
 472.173 +        super.setLength(newLength);
 472.174 +    }
 472.175 +
 472.176 +    /**
 472.177 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.178 +     * @see        #length()
 472.179 +     */
 472.180 +    public synchronized char charAt(int index) {
 472.181 +        if ((index < 0) || (index >= count))
 472.182 +            throw new StringIndexOutOfBoundsException(index);
 472.183 +        return value[index];
 472.184 +    }
 472.185 +
 472.186 +    /**
 472.187 +     * @since      1.5
 472.188 +     */
 472.189 +    public synchronized int codePointAt(int index) {
 472.190 +        return super.codePointAt(index);
 472.191 +    }
 472.192 +
 472.193 +    /**
 472.194 +     * @since     1.5
 472.195 +     */
 472.196 +    public synchronized int codePointBefore(int index) {
 472.197 +        return super.codePointBefore(index);
 472.198 +    }
 472.199 +
 472.200 +    /**
 472.201 +     * @since     1.5
 472.202 +     */
 472.203 +    public synchronized int codePointCount(int beginIndex, int endIndex) {
 472.204 +        return super.codePointCount(beginIndex, endIndex);
 472.205 +    }
 472.206 +
 472.207 +    /**
 472.208 +     * @since     1.5
 472.209 +     */
 472.210 +    public synchronized int offsetByCodePoints(int index, int codePointOffset) {
 472.211 +        return super.offsetByCodePoints(index, codePointOffset);
 472.212 +    }
 472.213 +
 472.214 +    /**
 472.215 +     * @throws NullPointerException {@inheritDoc}
 472.216 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.217 +     */
 472.218 +    public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
 472.219 +                                      int dstBegin)
 472.220 +    {
 472.221 +        super.getChars(srcBegin, srcEnd, dst, dstBegin);
 472.222 +    }
 472.223 +
 472.224 +    /**
 472.225 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.226 +     * @see        #length()
 472.227 +     */
 472.228 +    public synchronized void setCharAt(int index, char ch) {
 472.229 +        if ((index < 0) || (index >= count))
 472.230 +            throw new StringIndexOutOfBoundsException(index);
 472.231 +        value[index] = ch;
 472.232 +    }
 472.233 +
 472.234 +    public synchronized StringBuffer append(Object obj) {
 472.235 +        super.append(String.valueOf(obj));
 472.236 +        return this;
 472.237 +    }
 472.238 +
 472.239 +    public synchronized StringBuffer append(String str) {
 472.240 +        super.append(str);
 472.241 +        return this;
 472.242 +    }
 472.243 +
 472.244 +    /**
 472.245 +     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 472.246 +     * <p>
 472.247 +     * The characters of the <tt>StringBuffer</tt> argument are appended,
 472.248 +     * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
 472.249 +     * length of this <tt>StringBuffer</tt> by the length of the argument.
 472.250 +     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 472.251 +     * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
 472.252 +     * <p>
 472.253 +     * Let <i>n</i> be the length of the old character sequence, the one
 472.254 +     * contained in the <tt>StringBuffer</tt> just prior to execution of the
 472.255 +     * <tt>append</tt> method. Then the character at index <i>k</i> in
 472.256 +     * the new character sequence is equal to the character at index <i>k</i>
 472.257 +     * in the old character sequence, if <i>k</i> is less than <i>n</i>;
 472.258 +     * otherwise, it is equal to the character at index <i>k-n</i> in the
 472.259 +     * argument <code>sb</code>.
 472.260 +     * <p>
 472.261 +     * This method synchronizes on <code>this</code> (the destination)
 472.262 +     * object but does not synchronize on the source (<code>sb</code>).
 472.263 +     *
 472.264 +     * @param   sb   the <tt>StringBuffer</tt> to append.
 472.265 +     * @return  a reference to this object.
 472.266 +     * @since 1.4
 472.267 +     */
 472.268 +    public synchronized StringBuffer append(StringBuffer sb) {
 472.269 +        super.append(sb);
 472.270 +        return this;
 472.271 +    }
 472.272 +
 472.273 +
 472.274 +    /**
 472.275 +     * Appends the specified <code>CharSequence</code> to this
 472.276 +     * sequence.
 472.277 +     * <p>
 472.278 +     * The characters of the <code>CharSequence</code> argument are appended,
 472.279 +     * in order, increasing the length of this sequence by the length of the
 472.280 +     * argument.
 472.281 +     *
 472.282 +     * <p>The result of this method is exactly the same as if it were an
 472.283 +     * invocation of this.append(s, 0, s.length());
 472.284 +     *
 472.285 +     * <p>This method synchronizes on this (the destination)
 472.286 +     * object but does not synchronize on the source (<code>s</code>).
 472.287 +     *
 472.288 +     * <p>If <code>s</code> is <code>null</code>, then the four characters
 472.289 +     * <code>"null"</code> are appended.
 472.290 +     *
 472.291 +     * @param   s the <code>CharSequence</code> to append.
 472.292 +     * @return  a reference to this object.
 472.293 +     * @since 1.5
 472.294 +     */
 472.295 +    public StringBuffer append(CharSequence s) {
 472.296 +        // Note, synchronization achieved via other invocations
 472.297 +        if (s == null)
 472.298 +            s = "null";
 472.299 +        if (s instanceof String)
 472.300 +            return this.append((String)s);
 472.301 +        if (s instanceof StringBuffer)
 472.302 +            return this.append((StringBuffer)s);
 472.303 +        return this.append(s, 0, s.length());
 472.304 +    }
 472.305 +
 472.306 +    /**
 472.307 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.308 +     * @since      1.5
 472.309 +     */
 472.310 +    public synchronized StringBuffer append(CharSequence s, int start, int end)
 472.311 +    {
 472.312 +        super.append(s, start, end);
 472.313 +        return this;
 472.314 +    }
 472.315 +
 472.316 +    public synchronized StringBuffer append(char[] str) {
 472.317 +        super.append(str);
 472.318 +        return this;
 472.319 +    }
 472.320 +
 472.321 +    /**
 472.322 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.323 +     */
 472.324 +    public synchronized StringBuffer append(char[] str, int offset, int len) {
 472.325 +        super.append(str, offset, len);
 472.326 +        return this;
 472.327 +    }
 472.328 +
 472.329 +    public synchronized StringBuffer append(boolean b) {
 472.330 +        super.append(b);
 472.331 +        return this;
 472.332 +    }
 472.333 +
 472.334 +    public synchronized StringBuffer append(char c) {
 472.335 +        super.append(c);
 472.336 +        return this;
 472.337 +    }
 472.338 +
 472.339 +    public synchronized StringBuffer append(int i) {
 472.340 +        super.append(i);
 472.341 +        return this;
 472.342 +    }
 472.343 +
 472.344 +    /**
 472.345 +     * @since 1.5
 472.346 +     */
 472.347 +    public synchronized StringBuffer appendCodePoint(int codePoint) {
 472.348 +        super.appendCodePoint(codePoint);
 472.349 +        return this;
 472.350 +    }
 472.351 +
 472.352 +    public synchronized StringBuffer append(long lng) {
 472.353 +        super.append(lng);
 472.354 +        return this;
 472.355 +    }
 472.356 +
 472.357 +    public synchronized StringBuffer append(float f) {
 472.358 +        super.append(f);
 472.359 +        return this;
 472.360 +    }
 472.361 +
 472.362 +    public synchronized StringBuffer append(double d) {
 472.363 +        super.append(d);
 472.364 +        return this;
 472.365 +    }
 472.366 +
 472.367 +    /**
 472.368 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.369 +     * @since      1.2
 472.370 +     */
 472.371 +    public synchronized StringBuffer delete(int start, int end) {
 472.372 +        super.delete(start, end);
 472.373 +        return this;
 472.374 +    }
 472.375 +
 472.376 +    /**
 472.377 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.378 +     * @since      1.2
 472.379 +     */
 472.380 +    public synchronized StringBuffer deleteCharAt(int index) {
 472.381 +        super.deleteCharAt(index);
 472.382 +        return this;
 472.383 +    }
 472.384 +
 472.385 +    /**
 472.386 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.387 +     * @since      1.2
 472.388 +     */
 472.389 +    public synchronized StringBuffer replace(int start, int end, String str) {
 472.390 +        super.replace(start, end, str);
 472.391 +        return this;
 472.392 +    }
 472.393 +
 472.394 +    /**
 472.395 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.396 +     * @since      1.2
 472.397 +     */
 472.398 +    public synchronized String substring(int start) {
 472.399 +        return substring(start, count);
 472.400 +    }
 472.401 +
 472.402 +    /**
 472.403 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.404 +     * @since      1.4
 472.405 +     */
 472.406 +    public synchronized CharSequence subSequence(int start, int end) {
 472.407 +        return super.substring(start, end);
 472.408 +    }
 472.409 +
 472.410 +    /**
 472.411 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.412 +     * @since      1.2
 472.413 +     */
 472.414 +    public synchronized String substring(int start, int end) {
 472.415 +        return super.substring(start, end);
 472.416 +    }
 472.417 +
 472.418 +    /**
 472.419 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.420 +     * @since      1.2
 472.421 +     */
 472.422 +    public synchronized StringBuffer insert(int index, char[] str, int offset,
 472.423 +                                            int len)
 472.424 +    {
 472.425 +        super.insert(index, str, offset, len);
 472.426 +        return this;
 472.427 +    }
 472.428 +
 472.429 +    /**
 472.430 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.431 +     */
 472.432 +    public synchronized StringBuffer insert(int offset, Object obj) {
 472.433 +        super.insert(offset, String.valueOf(obj));
 472.434 +        return this;
 472.435 +    }
 472.436 +
 472.437 +    /**
 472.438 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.439 +     */
 472.440 +    public synchronized StringBuffer insert(int offset, String str) {
 472.441 +        super.insert(offset, str);
 472.442 +        return this;
 472.443 +    }
 472.444 +
 472.445 +    /**
 472.446 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.447 +     */
 472.448 +    public synchronized StringBuffer insert(int offset, char[] str) {
 472.449 +        super.insert(offset, str);
 472.450 +        return this;
 472.451 +    }
 472.452 +
 472.453 +    /**
 472.454 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.455 +     * @since      1.5
 472.456 +     */
 472.457 +    public StringBuffer insert(int dstOffset, CharSequence s) {
 472.458 +        // Note, synchronization achieved via other invocations
 472.459 +        if (s == null)
 472.460 +            s = "null";
 472.461 +        if (s instanceof String)
 472.462 +            return this.insert(dstOffset, (String)s);
 472.463 +        return this.insert(dstOffset, s, 0, s.length());
 472.464 +    }
 472.465 +
 472.466 +    /**
 472.467 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.468 +     * @since      1.5
 472.469 +     */
 472.470 +    public synchronized StringBuffer insert(int dstOffset, CharSequence s,
 472.471 +                                            int start, int end)
 472.472 +    {
 472.473 +        super.insert(dstOffset, s, start, end);
 472.474 +        return this;
 472.475 +    }
 472.476 +
 472.477 +    /**
 472.478 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.479 +     */
 472.480 +    public StringBuffer insert(int offset, boolean b) {
 472.481 +        return insert(offset, String.valueOf(b));
 472.482 +    }
 472.483 +
 472.484 +    /**
 472.485 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 472.486 +     */
 472.487 +    public synchronized StringBuffer insert(int offset, char c) {
 472.488 +        super.insert(offset, c);
 472.489 +        return this;
 472.490 +    }
 472.491 +
 472.492 +    /**
 472.493 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.494 +     */
 472.495 +    public StringBuffer insert(int offset, int i) {
 472.496 +        return insert(offset, String.valueOf(i));
 472.497 +    }
 472.498 +
 472.499 +    /**
 472.500 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.501 +     */
 472.502 +    public StringBuffer insert(int offset, long l) {
 472.503 +        return insert(offset, String.valueOf(l));
 472.504 +    }
 472.505 +
 472.506 +    /**
 472.507 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.508 +     */
 472.509 +    public StringBuffer insert(int offset, float f) {
 472.510 +        return insert(offset, String.valueOf(f));
 472.511 +    }
 472.512 +
 472.513 +    /**
 472.514 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 472.515 +     */
 472.516 +    public StringBuffer insert(int offset, double d) {
 472.517 +        return insert(offset, String.valueOf(d));
 472.518 +    }
 472.519 +
 472.520 +    /**
 472.521 +     * @throws NullPointerException {@inheritDoc}
 472.522 +     * @since      1.4
 472.523 +     */
 472.524 +    public int indexOf(String str) {
 472.525 +        return indexOf(str, 0);
 472.526 +    }
 472.527 +
 472.528 +    /**
 472.529 +     * @throws NullPointerException {@inheritDoc}
 472.530 +     * @since      1.4
 472.531 +     */
 472.532 +    public synchronized int indexOf(String str, int fromIndex) {
 472.533 +        return super.indexOf(str, fromIndex);
 472.534 +    }
 472.535 +
 472.536 +    /**
 472.537 +     * @throws NullPointerException {@inheritDoc}
 472.538 +     * @since      1.4
 472.539 +     */
 472.540 +    public int lastIndexOf(String str) {
 472.541 +        // Note, synchronization achieved via other invocations
 472.542 +        return lastIndexOf(str, count);
 472.543 +    }
 472.544 +
 472.545 +    /**
 472.546 +     * @throws NullPointerException {@inheritDoc}
 472.547 +     * @since      1.4
 472.548 +     */
 472.549 +    public synchronized int lastIndexOf(String str, int fromIndex) {
 472.550 +        return String.lastIndexOf(value, 0, count,
 472.551 +                              str.toCharArray(), 0, str.length(), fromIndex);
 472.552 +    }
 472.553 +
 472.554 +    /**
 472.555 +     * @since   JDK1.0.2
 472.556 +     */
 472.557 +    public synchronized StringBuffer reverse() {
 472.558 +        super.reverse();
 472.559 +        return this;
 472.560 +    }
 472.561 +
 472.562 +    public synchronized String toString() {
 472.563 +        return new String(value, 0, count);
 472.564 +    }
 472.565 +
 472.566 +//    /**
 472.567 +//     * Serializable fields for StringBuffer.
 472.568 +//     *
 472.569 +//     * @serialField value  char[]
 472.570 +//     *              The backing character array of this StringBuffer.
 472.571 +//     * @serialField count int
 472.572 +//     *              The number of characters in this StringBuffer.
 472.573 +//     * @serialField shared  boolean
 472.574 +//     *              A flag indicating whether the backing array is shared.
 472.575 +//     *              The value is ignored upon deserialization.
 472.576 +//     */
 472.577 +//    private static final java.io.ObjectStreamField[] serialPersistentFields =
 472.578 +//    {
 472.579 +//        new java.io.ObjectStreamField("value", char[].class),
 472.580 +//        new java.io.ObjectStreamField("count", Integer.TYPE),
 472.581 +//        new java.io.ObjectStreamField("shared", Boolean.TYPE),
 472.582 +//    };
 472.583 +//
 472.584 +//    /**
 472.585 +//     * readObject is called to restore the state of the StringBuffer from
 472.586 +//     * a stream.
 472.587 +//     */
 472.588 +//    private synchronized void writeObject(java.io.ObjectOutputStream s)
 472.589 +//        throws java.io.IOException {
 472.590 +//        java.io.ObjectOutputStream.PutField fields = s.putFields();
 472.591 +//        fields.put("value", value);
 472.592 +//        fields.put("count", count);
 472.593 +//        fields.put("shared", false);
 472.594 +//        s.writeFields();
 472.595 +//    }
 472.596 +//
 472.597 +//    /**
 472.598 +//     * readObject is called to restore the state of the StringBuffer from
 472.599 +//     * a stream.
 472.600 +//     */
 472.601 +//    private void readObject(java.io.ObjectInputStream s)
 472.602 +//        throws java.io.IOException, ClassNotFoundException {
 472.603 +//        java.io.ObjectInputStream.GetField fields = s.readFields();
 472.604 +//        value = (char[])fields.get("value", null);
 472.605 +//        count = fields.get("count", 0);
 472.606 +//    }
 472.607 +}
   473.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   473.2 +++ b/rt/emul/mini/src/main/java/java/lang/StringBuilder.java	Wed Feb 27 11:24:58 2013 +0100
   473.3 @@ -0,0 +1,436 @@
   473.4 +/*
   473.5 + * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
   473.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   473.7 + *
   473.8 + * This code is free software; you can redistribute it and/or modify it
   473.9 + * under the terms of the GNU General Public License version 2 only, as
  473.10 + * published by the Free Software Foundation.  Oracle designates this
  473.11 + * particular file as subject to the "Classpath" exception as provided
  473.12 + * by Oracle in the LICENSE file that accompanied this code.
  473.13 + *
  473.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  473.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  473.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  473.17 + * version 2 for more details (a copy is included in the LICENSE file that
  473.18 + * accompanied this code).
  473.19 + *
  473.20 + * You should have received a copy of the GNU General Public License version
  473.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  473.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  473.23 + *
  473.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  473.25 + * or visit www.oracle.com if you need additional information or have any
  473.26 + * questions.
  473.27 + */
  473.28 +
  473.29 +package java.lang;
  473.30 +
  473.31 +
  473.32 +/**
  473.33 + * A mutable sequence of characters.  This class provides an API compatible
  473.34 + * with <code>StringBuffer</code>, but with no guarantee of synchronization.
  473.35 + * This class is designed for use as a drop-in replacement for
  473.36 + * <code>StringBuffer</code> in places where the string buffer was being
  473.37 + * used by a single thread (as is generally the case).   Where possible,
  473.38 + * it is recommended that this class be used in preference to
  473.39 + * <code>StringBuffer</code> as it will be faster under most implementations.
  473.40 + *
  473.41 + * <p>The principal operations on a <code>StringBuilder</code> are the
  473.42 + * <code>append</code> and <code>insert</code> methods, which are
  473.43 + * overloaded so as to accept data of any type. Each effectively
  473.44 + * converts a given datum to a string and then appends or inserts the
  473.45 + * characters of that string to the string builder. The
  473.46 + * <code>append</code> method always adds these characters at the end
  473.47 + * of the builder; the <code>insert</code> method adds the characters at
  473.48 + * a specified point.
  473.49 + * <p>
  473.50 + * For example, if <code>z</code> refers to a string builder object
  473.51 + * whose current contents are "<code>start</code>", then
  473.52 + * the method call <code>z.append("le")</code> would cause the string
  473.53 + * builder to contain "<code>startle</code>", whereas
  473.54 + * <code>z.insert(4, "le")</code> would alter the string builder to
  473.55 + * contain "<code>starlet</code>".
  473.56 + * <p>
  473.57 + * In general, if sb refers to an instance of a <code>StringBuilder</code>,
  473.58 + * then <code>sb.append(x)</code> has the same effect as
  473.59 + * <code>sb.insert(sb.length(),&nbsp;x)</code>.
  473.60 + *
  473.61 + * Every string builder has a capacity. As long as the length of the
  473.62 + * character sequence contained in the string builder does not exceed
  473.63 + * the capacity, it is not necessary to allocate a new internal
  473.64 + * buffer. If the internal buffer overflows, it is automatically made larger.
  473.65 + *
  473.66 + * <p>Instances of <code>StringBuilder</code> are not safe for
  473.67 + * use by multiple threads. If such synchronization is required then it is
  473.68 + * recommended that {@link java.lang.StringBuffer} be used.
  473.69 + *
  473.70 + * @author      Michael McCloskey
  473.71 + * @see         java.lang.StringBuffer
  473.72 + * @see         java.lang.String
  473.73 + * @since       1.5
  473.74 + */
  473.75 +public final class StringBuilder
  473.76 +    extends AbstractStringBuilder
  473.77 +    implements java.io.Serializable, CharSequence
  473.78 +{
  473.79 +
  473.80 +    /** use serialVersionUID for interoperability */
  473.81 +    static final long serialVersionUID = 4383685877147921099L;
  473.82 +
  473.83 +    /**
  473.84 +     * Constructs a string builder with no characters in it and an
  473.85 +     * initial capacity of 16 characters.
  473.86 +     */
  473.87 +    public StringBuilder() {
  473.88 +        super(16);
  473.89 +    }
  473.90 +
  473.91 +    /**
  473.92 +     * Constructs a string builder with no characters in it and an
  473.93 +     * initial capacity specified by the <code>capacity</code> argument.
  473.94 +     *
  473.95 +     * @param      capacity  the initial capacity.
  473.96 +     * @throws     NegativeArraySizeException  if the <code>capacity</code>
  473.97 +     *               argument is less than <code>0</code>.
  473.98 +     */
  473.99 +    public StringBuilder(int capacity) {
 473.100 +        super(capacity);
 473.101 +    }
 473.102 +
 473.103 +    /**
 473.104 +     * Constructs a string builder initialized to the contents of the
 473.105 +     * specified string. The initial capacity of the string builder is
 473.106 +     * <code>16</code> plus the length of the string argument.
 473.107 +     *
 473.108 +     * @param   str   the initial contents of the buffer.
 473.109 +     * @throws    NullPointerException if <code>str</code> is <code>null</code>
 473.110 +     */
 473.111 +    public StringBuilder(String str) {
 473.112 +        super(str.length() + 16);
 473.113 +        append(str);
 473.114 +    }
 473.115 +
 473.116 +    /**
 473.117 +     * Constructs a string builder that contains the same characters
 473.118 +     * as the specified <code>CharSequence</code>. The initial capacity of
 473.119 +     * the string builder is <code>16</code> plus the length of the
 473.120 +     * <code>CharSequence</code> argument.
 473.121 +     *
 473.122 +     * @param      seq   the sequence to copy.
 473.123 +     * @throws    NullPointerException if <code>seq</code> is <code>null</code>
 473.124 +     */
 473.125 +    public StringBuilder(CharSequence seq) {
 473.126 +        this(seq.length() + 16);
 473.127 +        append(seq);
 473.128 +    }
 473.129 +
 473.130 +    public StringBuilder append(Object obj) {
 473.131 +        return append(String.valueOf(obj));
 473.132 +    }
 473.133 +
 473.134 +    public StringBuilder append(String str) {
 473.135 +        super.append(str);
 473.136 +        return this;
 473.137 +    }
 473.138 +
 473.139 +    // Appends the specified string builder to this sequence.
 473.140 +    private StringBuilder append(StringBuilder sb) {
 473.141 +        if (sb == null)
 473.142 +            return append("null");
 473.143 +        int len = sb.length();
 473.144 +        int newcount = count + len;
 473.145 +        if (newcount > value.length)
 473.146 +            expandCapacity(newcount);
 473.147 +        sb.getChars(0, len, value, count);
 473.148 +        count = newcount;
 473.149 +        return this;
 473.150 +    }
 473.151 +
 473.152 +    /**
 473.153 +     * Appends the specified <tt>StringBuffer</tt> to this sequence.
 473.154 +     * <p>
 473.155 +     * The characters of the <tt>StringBuffer</tt> argument are appended,
 473.156 +     * in order, to this sequence, increasing the
 473.157 +     * length of this sequence by the length of the argument.
 473.158 +     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
 473.159 +     * <tt>"null"</tt> are appended to this sequence.
 473.160 +     * <p>
 473.161 +     * Let <i>n</i> be the length of this character sequence just prior to
 473.162 +     * execution of the <tt>append</tt> method. Then the character at index
 473.163 +     * <i>k</i> in the new character sequence is equal to the character at
 473.164 +     * index <i>k</i> in the old character sequence, if <i>k</i> is less than
 473.165 +     * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
 473.166 +     * in the argument <code>sb</code>.
 473.167 +     *
 473.168 +     * @param   sb   the <tt>StringBuffer</tt> to append.
 473.169 +     * @return  a reference to this object.
 473.170 +     */
 473.171 +    public StringBuilder append(StringBuffer sb) {
 473.172 +        super.append(sb);
 473.173 +        return this;
 473.174 +    }
 473.175 +
 473.176 +    /**
 473.177 +     */
 473.178 +    public StringBuilder append(CharSequence s) {
 473.179 +        if (s == null)
 473.180 +            s = "null";
 473.181 +        if (s instanceof String)
 473.182 +            return this.append((String)s);
 473.183 +        if (s instanceof StringBuffer)
 473.184 +            return this.append((StringBuffer)s);
 473.185 +        if (s instanceof StringBuilder)
 473.186 +            return this.append((StringBuilder)s);
 473.187 +        return this.append(s, 0, s.length());
 473.188 +    }
 473.189 +
 473.190 +    /**
 473.191 +     * @throws     IndexOutOfBoundsException {@inheritDoc}
 473.192 +     */
 473.193 +    public StringBuilder append(CharSequence s, int start, int end) {
 473.194 +        super.append(s, start, end);
 473.195 +        return this;
 473.196 +    }
 473.197 +
 473.198 +    public StringBuilder append(char[] str) {
 473.199 +        super.append(str);
 473.200 +        return this;
 473.201 +    }
 473.202 +
 473.203 +    /**
 473.204 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 473.205 +     */
 473.206 +    public StringBuilder append(char[] str, int offset, int len) {
 473.207 +        super.append(str, offset, len);
 473.208 +        return this;
 473.209 +    }
 473.210 +
 473.211 +    public StringBuilder append(boolean b) {
 473.212 +        super.append(b);
 473.213 +        return this;
 473.214 +    }
 473.215 +
 473.216 +    public StringBuilder append(char c) {
 473.217 +        super.append(c);
 473.218 +        return this;
 473.219 +    }
 473.220 +
 473.221 +    public StringBuilder append(int i) {
 473.222 +        super.append(i);
 473.223 +        return this;
 473.224 +    }
 473.225 +
 473.226 +    public StringBuilder append(long lng) {
 473.227 +        super.append(lng);
 473.228 +        return this;
 473.229 +    }
 473.230 +
 473.231 +    public StringBuilder append(float f) {
 473.232 +        super.append(f);
 473.233 +        return this;
 473.234 +    }
 473.235 +
 473.236 +    public StringBuilder append(double d) {
 473.237 +        super.append(d);
 473.238 +        return this;
 473.239 +    }
 473.240 +
 473.241 +    /**
 473.242 +     * @since 1.5
 473.243 +     */
 473.244 +    public StringBuilder appendCodePoint(int codePoint) {
 473.245 +        super.appendCodePoint(codePoint);
 473.246 +        return this;
 473.247 +    }
 473.248 +
 473.249 +    /**
 473.250 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.251 +     */
 473.252 +    public StringBuilder delete(int start, int end) {
 473.253 +        super.delete(start, end);
 473.254 +        return this;
 473.255 +    }
 473.256 +
 473.257 +    /**
 473.258 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.259 +     */
 473.260 +    public StringBuilder deleteCharAt(int index) {
 473.261 +        super.deleteCharAt(index);
 473.262 +        return this;
 473.263 +    }
 473.264 +
 473.265 +    /**
 473.266 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.267 +     */
 473.268 +    public StringBuilder replace(int start, int end, String str) {
 473.269 +        super.replace(start, end, str);
 473.270 +        return this;
 473.271 +    }
 473.272 +
 473.273 +    /**
 473.274 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.275 +     */
 473.276 +    public StringBuilder insert(int index, char[] str, int offset,
 473.277 +                                int len)
 473.278 +    {
 473.279 +        super.insert(index, str, offset, len);
 473.280 +        return this;
 473.281 +    }
 473.282 +
 473.283 +    /**
 473.284 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.285 +     */
 473.286 +    public StringBuilder insert(int offset, Object obj) {
 473.287 +        return insert(offset, String.valueOf(obj));
 473.288 +    }
 473.289 +
 473.290 +    /**
 473.291 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.292 +     */
 473.293 +    public StringBuilder insert(int offset, String str) {
 473.294 +        super.insert(offset, str);
 473.295 +        return this;
 473.296 +    }
 473.297 +
 473.298 +    /**
 473.299 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.300 +     */
 473.301 +    public StringBuilder insert(int offset, char[] str) {
 473.302 +        super.insert(offset, str);
 473.303 +        return this;
 473.304 +    }
 473.305 +
 473.306 +    /**
 473.307 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 473.308 +     */
 473.309 +    public StringBuilder insert(int dstOffset, CharSequence s) {
 473.310 +        if (s == null)
 473.311 +            s = "null";
 473.312 +        if (s instanceof String)
 473.313 +            return this.insert(dstOffset, (String)s);
 473.314 +        return this.insert(dstOffset, s, 0, s.length());
 473.315 +    }
 473.316 +
 473.317 +    /**
 473.318 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 473.319 +     */
 473.320 +    public StringBuilder insert(int dstOffset, CharSequence s,
 473.321 +                                int start, int end)
 473.322 +    {
 473.323 +        super.insert(dstOffset, s, start, end);
 473.324 +        return this;
 473.325 +    }
 473.326 +
 473.327 +    /**
 473.328 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.329 +     */
 473.330 +    public StringBuilder insert(int offset, boolean b) {
 473.331 +        super.insert(offset, b);
 473.332 +        return this;
 473.333 +    }
 473.334 +
 473.335 +    /**
 473.336 +     * @throws IndexOutOfBoundsException {@inheritDoc}
 473.337 +     */
 473.338 +    public StringBuilder insert(int offset, char c) {
 473.339 +        super.insert(offset, c);
 473.340 +        return this;
 473.341 +    }
 473.342 +
 473.343 +    /**
 473.344 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.345 +     */
 473.346 +    public StringBuilder insert(int offset, int i) {
 473.347 +        return insert(offset, String.valueOf(i));
 473.348 +    }
 473.349 +
 473.350 +    /**
 473.351 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.352 +     */
 473.353 +    public StringBuilder insert(int offset, long l) {
 473.354 +        return insert(offset, String.valueOf(l));
 473.355 +    }
 473.356 +
 473.357 +    /**
 473.358 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.359 +     */
 473.360 +    public StringBuilder insert(int offset, float f) {
 473.361 +        return insert(offset, String.valueOf(f));
 473.362 +    }
 473.363 +
 473.364 +    /**
 473.365 +     * @throws StringIndexOutOfBoundsException {@inheritDoc}
 473.366 +     */
 473.367 +    public StringBuilder insert(int offset, double d) {
 473.368 +        return insert(offset, String.valueOf(d));
 473.369 +    }
 473.370 +
 473.371 +    /**
 473.372 +     * @throws NullPointerException {@inheritDoc}
 473.373 +     */
 473.374 +    public int indexOf(String str) {
 473.375 +        return indexOf(str, 0);
 473.376 +    }
 473.377 +
 473.378 +    /**
 473.379 +     * @throws NullPointerException {@inheritDoc}
 473.380 +     */
 473.381 +    public int indexOf(String str, int fromIndex) {
 473.382 +        return super.indexOf(str, fromIndex);
 473.383 +    }
 473.384 +
 473.385 +    /**
 473.386 +     * @throws NullPointerException {@inheritDoc}
 473.387 +     */
 473.388 +    public int lastIndexOf(String str) {
 473.389 +        return lastIndexOf(str, count);
 473.390 +    }
 473.391 +
 473.392 +    /**
 473.393 +     * @throws NullPointerException {@inheritDoc}
 473.394 +     */
 473.395 +    public int lastIndexOf(String str, int fromIndex) {
 473.396 +        return String.lastIndexOf(value, 0, count,
 473.397 +                              str.toCharArray(), 0, str.length(), fromIndex);
 473.398 +    }
 473.399 +
 473.400 +    public StringBuilder reverse() {
 473.401 +        super.reverse();
 473.402 +        return this;
 473.403 +    }
 473.404 +
 473.405 +    public String toString() {
 473.406 +        // Create a copy, don't share the array
 473.407 +        return new String(value, 0, count);
 473.408 +    }
 473.409 +
 473.410 +    /**
 473.411 +     * Save the state of the <tt>StringBuilder</tt> instance to a stream
 473.412 +     * (that is, serialize it).
 473.413 +     *
 473.414 +     * @serialData the number of characters currently stored in the string
 473.415 +     *             builder (<tt>int</tt>), followed by the characters in the
 473.416 +     *             string builder (<tt>char[]</tt>).   The length of the
 473.417 +     *             <tt>char</tt> array may be greater than the number of
 473.418 +     *             characters currently stored in the string builder, in which
 473.419 +     *             case extra characters are ignored.
 473.420 +     */
 473.421 +//    private void writeObject(java.io.ObjectOutputStream s)
 473.422 +//        throws java.io.IOException {
 473.423 +//        s.defaultWriteObject();
 473.424 +//        s.writeInt(count);
 473.425 +//        s.writeObject(value);
 473.426 +//    }
 473.427 +
 473.428 +    /**
 473.429 +     * readObject is called to restore the state of the StringBuffer from
 473.430 +     * a stream.
 473.431 +     */
 473.432 +//    private void readObject(java.io.ObjectInputStream s)
 473.433 +//        throws java.io.IOException, ClassNotFoundException {
 473.434 +//        s.defaultReadObject();
 473.435 +//        count = s.readInt();
 473.436 +//        value = (char[]) s.readObject();
 473.437 +//    }
 473.438 +
 473.439 +}
   474.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   474.2 +++ b/rt/emul/mini/src/main/java/java/lang/StringIndexOutOfBoundsException.java	Wed Feb 27 11:24:58 2013 +0100
   474.3 @@ -0,0 +1,71 @@
   474.4 +/*
   474.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   474.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   474.7 + *
   474.8 + * This code is free software; you can redistribute it and/or modify it
   474.9 + * under the terms of the GNU General Public License version 2 only, as
  474.10 + * published by the Free Software Foundation.  Oracle designates this
  474.11 + * particular file as subject to the "Classpath" exception as provided
  474.12 + * by Oracle in the LICENSE file that accompanied this code.
  474.13 + *
  474.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  474.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  474.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  474.17 + * version 2 for more details (a copy is included in the LICENSE file that
  474.18 + * accompanied this code).
  474.19 + *
  474.20 + * You should have received a copy of the GNU General Public License version
  474.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  474.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  474.23 + *
  474.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  474.25 + * or visit www.oracle.com if you need additional information or have any
  474.26 + * questions.
  474.27 + */
  474.28 +
  474.29 +package java.lang;
  474.30 +
  474.31 +/**
  474.32 + * Thrown by <code>String</code> methods to indicate that an index
  474.33 + * is either negative or greater than the size of the string.  For
  474.34 + * some methods such as the charAt method, this exception also is
  474.35 + * thrown when the index is equal to the size of the string.
  474.36 + *
  474.37 + * @author  unascribed
  474.38 + * @see     java.lang.String#charAt(int)
  474.39 + * @since   JDK1.0
  474.40 + */
  474.41 +public
  474.42 +class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
  474.43 +    private static final long serialVersionUID = -6762910422159637258L;
  474.44 +
  474.45 +    /**
  474.46 +     * Constructs a <code>StringIndexOutOfBoundsException</code> with no
  474.47 +     * detail message.
  474.48 +     *
  474.49 +     * @since   JDK1.0.
  474.50 +     */
  474.51 +    public StringIndexOutOfBoundsException() {
  474.52 +        super();
  474.53 +    }
  474.54 +
  474.55 +    /**
  474.56 +     * Constructs a <code>StringIndexOutOfBoundsException</code> with
  474.57 +     * the specified detail message.
  474.58 +     *
  474.59 +     * @param   s   the detail message.
  474.60 +     */
  474.61 +    public StringIndexOutOfBoundsException(String s) {
  474.62 +        super(s);
  474.63 +    }
  474.64 +
  474.65 +    /**
  474.66 +     * Constructs a new <code>StringIndexOutOfBoundsException</code>
  474.67 +     * class with an argument indicating the illegal index.
  474.68 +     *
  474.69 +     * @param   index   the illegal index.
  474.70 +     */
  474.71 +    public StringIndexOutOfBoundsException(int index) {
  474.72 +        super("String index out of range: " + index);
  474.73 +    }
  474.74 +}
   475.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   475.2 +++ b/rt/emul/mini/src/main/java/java/lang/Throwable.java	Wed Feb 27 11:24:58 2013 +0100
   475.3 @@ -0,0 +1,1088 @@
   475.4 +/*
   475.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   475.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   475.7 + *
   475.8 + * This code is free software; you can redistribute it and/or modify it
   475.9 + * under the terms of the GNU General Public License version 2 only, as
  475.10 + * published by the Free Software Foundation.  Oracle designates this
  475.11 + * particular file as subject to the "Classpath" exception as provided
  475.12 + * by Oracle in the LICENSE file that accompanied this code.
  475.13 + *
  475.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  475.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  475.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  475.17 + * version 2 for more details (a copy is included in the LICENSE file that
  475.18 + * accompanied this code).
  475.19 + *
  475.20 + * You should have received a copy of the GNU General Public License version
  475.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  475.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  475.23 + *
  475.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  475.25 + * or visit www.oracle.com if you need additional information or have any
  475.26 + * questions.
  475.27 + */
  475.28 +
  475.29 +package java.lang;
  475.30 +import  java.io.*;
  475.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  475.32 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
  475.33 +
  475.34 +/**
  475.35 + * The {@code Throwable} class is the superclass of all errors and
  475.36 + * exceptions in the Java language. Only objects that are instances of this
  475.37 + * class (or one of its subclasses) are thrown by the Java Virtual Machine or
  475.38 + * can be thrown by the Java {@code throw} statement. Similarly, only
  475.39 + * this class or one of its subclasses can be the argument type in a
  475.40 + * {@code catch} clause.
  475.41 + *
  475.42 + * For the purposes of compile-time checking of exceptions, {@code
  475.43 + * Throwable} and any subclass of {@code Throwable} that is not also a
  475.44 + * subclass of either {@link RuntimeException} or {@link Error} are
  475.45 + * regarded as checked exceptions.
  475.46 + *
  475.47 + * <p>Instances of two subclasses, {@link java.lang.Error} and
  475.48 + * {@link java.lang.Exception}, are conventionally used to indicate
  475.49 + * that exceptional situations have occurred. Typically, these instances
  475.50 + * are freshly created in the context of the exceptional situation so
  475.51 + * as to include relevant information (such as stack trace data).
  475.52 + *
  475.53 + * <p>A throwable contains a snapshot of the execution stack of its
  475.54 + * thread at the time it was created. It can also contain a message
  475.55 + * string that gives more information about the error. Over time, a
  475.56 + * throwable can {@linkplain Throwable#addSuppressed suppress} other
  475.57 + * throwables from being propagated.  Finally, the throwable can also
  475.58 + * contain a <i>cause</i>: another throwable that caused this
  475.59 + * throwable to be constructed.  The recording of this causal information
  475.60 + * is referred to as the <i>chained exception</i> facility, as the
  475.61 + * cause can, itself, have a cause, and so on, leading to a "chain" of
  475.62 + * exceptions, each caused by another.
  475.63 + *
  475.64 + * <p>One reason that a throwable may have a cause is that the class that
  475.65 + * throws it is built atop a lower layered abstraction, and an operation on
  475.66 + * the upper layer fails due to a failure in the lower layer.  It would be bad
  475.67 + * design to let the throwable thrown by the lower layer propagate outward, as
  475.68 + * it is generally unrelated to the abstraction provided by the upper layer.
  475.69 + * Further, doing so would tie the API of the upper layer to the details of
  475.70 + * its implementation, assuming the lower layer's exception was a checked
  475.71 + * exception.  Throwing a "wrapped exception" (i.e., an exception containing a
  475.72 + * cause) allows the upper layer to communicate the details of the failure to
  475.73 + * its caller without incurring either of these shortcomings.  It preserves
  475.74 + * the flexibility to change the implementation of the upper layer without
  475.75 + * changing its API (in particular, the set of exceptions thrown by its
  475.76 + * methods).
  475.77 + *
  475.78 + * <p>A second reason that a throwable may have a cause is that the method
  475.79 + * that throws it must conform to a general-purpose interface that does not
  475.80 + * permit the method to throw the cause directly.  For example, suppose
  475.81 + * a persistent collection conforms to the {@link java.util.Collection
  475.82 + * Collection} interface, and that its persistence is implemented atop
  475.83 + * {@code java.io}.  Suppose the internals of the {@code add} method
  475.84 + * can throw an {@link java.io.IOException IOException}.  The implementation
  475.85 + * can communicate the details of the {@code IOException} to its caller
  475.86 + * while conforming to the {@code Collection} interface by wrapping the
  475.87 + * {@code IOException} in an appropriate unchecked exception.  (The
  475.88 + * specification for the persistent collection should indicate that it is
  475.89 + * capable of throwing such exceptions.)
  475.90 + *
  475.91 + * <p>A cause can be associated with a throwable in two ways: via a
  475.92 + * constructor that takes the cause as an argument, or via the
  475.93 + * {@link #initCause(Throwable)} method.  New throwable classes that
  475.94 + * wish to allow causes to be associated with them should provide constructors
  475.95 + * that take a cause and delegate (perhaps indirectly) to one of the
  475.96 + * {@code Throwable} constructors that takes a cause.
  475.97 + *
  475.98 + * Because the {@code initCause} method is public, it allows a cause to be
  475.99 + * associated with any throwable, even a "legacy throwable" whose
 475.100 + * implementation predates the addition of the exception chaining mechanism to
 475.101 + * {@code Throwable}.
 475.102 + *
 475.103 + * <p>By convention, class {@code Throwable} and its subclasses have two
 475.104 + * constructors, one that takes no arguments and one that takes a
 475.105 + * {@code String} argument that can be used to produce a detail message.
 475.106 + * Further, those subclasses that might likely have a cause associated with
 475.107 + * them should have two more constructors, one that takes a
 475.108 + * {@code Throwable} (the cause), and one that takes a
 475.109 + * {@code String} (the detail message) and a {@code Throwable} (the
 475.110 + * cause).
 475.111 + *
 475.112 + * @author  unascribed
 475.113 + * @author  Josh Bloch (Added exception chaining and programmatic access to
 475.114 + *          stack trace in 1.4.)
 475.115 + * @jls 11.2 Compile-Time Checking of Exceptions
 475.116 + * @since JDK1.0
 475.117 + */
 475.118 +public class Throwable implements Serializable {
 475.119 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
 475.120 +    private static final long serialVersionUID = -3042686055658047285L;
 475.121 +
 475.122 +    /**
 475.123 +     * Native code saves some indication of the stack backtrace in this slot.
 475.124 +     */
 475.125 +    private transient Object backtrace;
 475.126 +
 475.127 +    /**
 475.128 +     * Specific details about the Throwable.  For example, for
 475.129 +     * {@code FileNotFoundException}, this contains the name of
 475.130 +     * the file that could not be found.
 475.131 +     *
 475.132 +     * @serial
 475.133 +     */
 475.134 +    private String detailMessage;
 475.135 +
 475.136 +
 475.137 +    /**
 475.138 +     * Holder class to defer initializing sentinel objects only used
 475.139 +     * for serialization.
 475.140 +     */
 475.141 +    private static class SentinelHolder {
 475.142 +        /**
 475.143 +         * {@linkplain #setStackTrace(StackTraceElement[]) Setting the
 475.144 +         * stack trace} to a one-element array containing this sentinel
 475.145 +         * value indicates future attempts to set the stack trace will be
 475.146 +         * ignored.  The sentinal is equal to the result of calling:<br>
 475.147 +         * {@code new StackTraceElement("", "", null, Integer.MIN_VALUE)}
 475.148 +         */
 475.149 +        public static final StackTraceElement STACK_TRACE_ELEMENT_SENTINEL =
 475.150 +            new StackTraceElement("", "", null, Integer.MIN_VALUE);
 475.151 +
 475.152 +        /**
 475.153 +         * Sentinel value used in the serial form to indicate an immutable
 475.154 +         * stack trace.
 475.155 +         */
 475.156 +        public static final StackTraceElement[] STACK_TRACE_SENTINEL =
 475.157 +            new StackTraceElement[] {STACK_TRACE_ELEMENT_SENTINEL};
 475.158 +    }
 475.159 +
 475.160 +    /**
 475.161 +     * A shared value for an empty stack.
 475.162 +     */
 475.163 +    private static final StackTraceElement[] UNASSIGNED_STACK = new StackTraceElement[0];
 475.164 +
 475.165 +    /*
 475.166 +     * To allow Throwable objects to be made immutable and safely
 475.167 +     * reused by the JVM, such as OutOfMemoryErrors, fields of
 475.168 +     * Throwable that are writable in response to user actions, cause,
 475.169 +     * stackTrace, and suppressedExceptions obey the following
 475.170 +     * protocol:
 475.171 +     *
 475.172 +     * 1) The fields are initialized to a non-null sentinel value
 475.173 +     * which indicates the value has logically not been set.
 475.174 +     *
 475.175 +     * 2) Writing a null to the field indicates further writes
 475.176 +     * are forbidden
 475.177 +     *
 475.178 +     * 3) The sentinel value may be replaced with another non-null
 475.179 +     * value.
 475.180 +     *
 475.181 +     * For example, implementations of the HotSpot JVM have
 475.182 +     * preallocated OutOfMemoryError objects to provide for better
 475.183 +     * diagnosability of that situation.  These objects are created
 475.184 +     * without calling the constructor for that class and the fields
 475.185 +     * in question are initialized to null.  To support this
 475.186 +     * capability, any new fields added to Throwable that require
 475.187 +     * being initialized to a non-null value require a coordinated JVM
 475.188 +     * change.
 475.189 +     */
 475.190 +
 475.191 +    /**
 475.192 +     * The throwable that caused this throwable to get thrown, or null if this
 475.193 +     * throwable was not caused by another throwable, or if the causative
 475.194 +     * throwable is unknown.  If this field is equal to this throwable itself,
 475.195 +     * it indicates that the cause of this throwable has not yet been
 475.196 +     * initialized.
 475.197 +     *
 475.198 +     * @serial
 475.199 +     * @since 1.4
 475.200 +     */
 475.201 +    private Throwable cause = this;
 475.202 +
 475.203 +    /**
 475.204 +     * The stack trace, as returned by {@link #getStackTrace()}.
 475.205 +     *
 475.206 +     * The field is initialized to a zero-length array.  A {@code
 475.207 +     * null} value of this field indicates subsequent calls to {@link
 475.208 +     * #setStackTrace(StackTraceElement[])} and {@link
 475.209 +     * #fillInStackTrace()} will be be no-ops.
 475.210 +     *
 475.211 +     * @serial
 475.212 +     * @since 1.4
 475.213 +     */
 475.214 +    private StackTraceElement[] stackTrace = UNASSIGNED_STACK;
 475.215 +
 475.216 +    // Setting this static field introduces an acceptable
 475.217 +    // initialization dependency on a few java.util classes.
 475.218 +// I don't think this dependency is acceptable
 475.219 +//    private static final List<Throwable> SUPPRESSED_SENTINEL =
 475.220 +//        Collections.unmodifiableList(new ArrayList<Throwable>(0));
 475.221 +
 475.222 +    /**
 475.223 +     * The list of suppressed exceptions, as returned by {@link
 475.224 +     * #getSuppressed()}.  The list is initialized to a zero-element
 475.225 +     * unmodifiable sentinel list.  When a serialized Throwable is
 475.226 +     * read in, if the {@code suppressedExceptions} field points to a
 475.227 +     * zero-element list, the field is reset to the sentinel value.
 475.228 +     *
 475.229 +     * @serial
 475.230 +     * @since 1.7
 475.231 +     */
 475.232 +//    private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
 475.233 +
 475.234 +    /** Message for trying to suppress a null exception. */
 475.235 +    private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
 475.236 +
 475.237 +    /** Message for trying to suppress oneself. */
 475.238 +    private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
 475.239 +
 475.240 +    /** Caption  for labeling causative exception stack traces */
 475.241 +    @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
 475.242 +    private static void jsToString() {
 475.243 +    }
 475.244 +    
 475.245 +    @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
 475.246 +    private static void jsValudOf() {
 475.247 +    }
 475.248 +    private static final String CAUSE_CAPTION = "Caused by: ";
 475.249 +
 475.250 +    /** Caption for labeling suppressed exception stack traces */
 475.251 +    private static final String SUPPRESSED_CAPTION = "Suppressed: ";
 475.252 +
 475.253 +    /**
 475.254 +     * Constructs a new throwable with {@code null} as its detail message.
 475.255 +     * The cause is not initialized, and may subsequently be initialized by a
 475.256 +     * call to {@link #initCause}.
 475.257 +     *
 475.258 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 475.259 +     * the stack trace data in the newly created throwable.
 475.260 +     */
 475.261 +    public Throwable() {
 475.262 +        fillInStackTrace();
 475.263 +    }
 475.264 +
 475.265 +    /**
 475.266 +     * Constructs a new throwable with the specified detail message.  The
 475.267 +     * cause is not initialized, and may subsequently be initialized by
 475.268 +     * a call to {@link #initCause}.
 475.269 +     *
 475.270 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 475.271 +     * the stack trace data in the newly created throwable.
 475.272 +     *
 475.273 +     * @param   message   the detail message. The detail message is saved for
 475.274 +     *          later retrieval by the {@link #getMessage()} method.
 475.275 +     */
 475.276 +    public Throwable(String message) {
 475.277 +        fillInStackTrace();
 475.278 +        detailMessage = message;
 475.279 +    }
 475.280 +
 475.281 +    /**
 475.282 +     * Constructs a new throwable with the specified detail message and
 475.283 +     * cause.  <p>Note that the detail message associated with
 475.284 +     * {@code cause} is <i>not</i> automatically incorporated in
 475.285 +     * this throwable's detail message.
 475.286 +     *
 475.287 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 475.288 +     * the stack trace data in the newly created throwable.
 475.289 +     *
 475.290 +     * @param  message the detail message (which is saved for later retrieval
 475.291 +     *         by the {@link #getMessage()} method).
 475.292 +     * @param  cause the cause (which is saved for later retrieval by the
 475.293 +     *         {@link #getCause()} method).  (A {@code null} value is
 475.294 +     *         permitted, and indicates that the cause is nonexistent or
 475.295 +     *         unknown.)
 475.296 +     * @since  1.4
 475.297 +     */
 475.298 +    public Throwable(String message, Throwable cause) {
 475.299 +        fillInStackTrace();
 475.300 +        detailMessage = message;
 475.301 +        this.cause = cause;
 475.302 +    }
 475.303 +
 475.304 +    /**
 475.305 +     * Constructs a new throwable with the specified cause and a detail
 475.306 +     * message of {@code (cause==null ? null : cause.toString())} (which
 475.307 +     * typically contains the class and detail message of {@code cause}).
 475.308 +     * This constructor is useful for throwables that are little more than
 475.309 +     * wrappers for other throwables (for example, {@link
 475.310 +     * java.security.PrivilegedActionException}).
 475.311 +     *
 475.312 +     * <p>The {@link #fillInStackTrace()} method is called to initialize
 475.313 +     * the stack trace data in the newly created throwable.
 475.314 +     *
 475.315 +     * @param  cause the cause (which is saved for later retrieval by the
 475.316 +     *         {@link #getCause()} method).  (A {@code null} value is
 475.317 +     *         permitted, and indicates that the cause is nonexistent or
 475.318 +     *         unknown.)
 475.319 +     * @since  1.4
 475.320 +     */
 475.321 +    public Throwable(Throwable cause) {
 475.322 +        fillInStackTrace();
 475.323 +        detailMessage = (cause==null ? null : cause.toString());
 475.324 +        this.cause = cause;
 475.325 +    }
 475.326 +
 475.327 +    /**
 475.328 +     * Constructs a new throwable with the specified detail message,
 475.329 +     * cause, {@linkplain #addSuppressed suppression} enabled or
 475.330 +     * disabled, and writable stack trace enabled or disabled.  If
 475.331 +     * suppression is disabled, {@link #getSuppressed} for this object
 475.332 +     * will return a zero-length array and calls to {@link
 475.333 +     * #addSuppressed} that would otherwise append an exception to the
 475.334 +     * suppressed list will have no effect.  If the writable stack
 475.335 +     * trace is false, this constructor will not call {@link
 475.336 +     * #fillInStackTrace()}, a {@code null} will be written to the
 475.337 +     * {@code stackTrace} field, and subsequent calls to {@code
 475.338 +     * fillInStackTrace} and {@link
 475.339 +     * #setStackTrace(StackTraceElement[])} will not set the stack
 475.340 +     * trace.  If the writable stack trace is false, {@link
 475.341 +     * #getStackTrace} will return a zero length array.
 475.342 +     *
 475.343 +     * <p>Note that the other constructors of {@code Throwable} treat
 475.344 +     * suppression as being enabled and the stack trace as being
 475.345 +     * writable.  Subclasses of {@code Throwable} should document any
 475.346 +     * conditions under which suppression is disabled and document
 475.347 +     * conditions under which the stack trace is not writable.
 475.348 +     * Disabling of suppression should only occur in exceptional
 475.349 +     * circumstances where special requirements exist, such as a
 475.350 +     * virtual machine reusing exception objects under low-memory
 475.351 +     * situations.  Circumstances where a given exception object is
 475.352 +     * repeatedly caught and rethrown, such as to implement control
 475.353 +     * flow between two sub-systems, is another situation where
 475.354 +     * immutable throwable objects would be appropriate.
 475.355 +     *
 475.356 +     * @param  message the detail message.
 475.357 +     * @param cause the cause.  (A {@code null} value is permitted,
 475.358 +     * and indicates that the cause is nonexistent or unknown.)
 475.359 +     * @param enableSuppression whether or not suppression is enabled or disabled
 475.360 +     * @param writableStackTrace whether or not the stack trace should be
 475.361 +     *                           writable
 475.362 +     *
 475.363 +     * @see OutOfMemoryError
 475.364 +     * @see NullPointerException
 475.365 +     * @see ArithmeticException
 475.366 +     * @since 1.7
 475.367 +     */
 475.368 +    protected Throwable(String message, Throwable cause,
 475.369 +                        boolean enableSuppression,
 475.370 +                        boolean writableStackTrace) {
 475.371 +        if (writableStackTrace) {
 475.372 +            fillInStackTrace();
 475.373 +        } else {
 475.374 +            stackTrace = null;
 475.375 +        }
 475.376 +        detailMessage = message;
 475.377 +        this.cause = cause;
 475.378 +//        if (!enableSuppression)
 475.379 +//            suppressedExceptions = null;
 475.380 +    }
 475.381 +
 475.382 +    /**
 475.383 +     * Returns the detail message string of this throwable.
 475.384 +     *
 475.385 +     * @return  the detail message string of this {@code Throwable} instance
 475.386 +     *          (which may be {@code null}).
 475.387 +     */
 475.388 +    public String getMessage() {
 475.389 +        return detailMessage;
 475.390 +    }
 475.391 +
 475.392 +    /**
 475.393 +     * Creates a localized description of this throwable.
 475.394 +     * Subclasses may override this method in order to produce a
 475.395 +     * locale-specific message.  For subclasses that do not override this
 475.396 +     * method, the default implementation returns the same result as
 475.397 +     * {@code getMessage()}.
 475.398 +     *
 475.399 +     * @return  The localized description of this throwable.
 475.400 +     * @since   JDK1.1
 475.401 +     */
 475.402 +    public String getLocalizedMessage() {
 475.403 +        return getMessage();
 475.404 +    }
 475.405 +
 475.406 +    /**
 475.407 +     * Returns the cause of this throwable or {@code null} if the
 475.408 +     * cause is nonexistent or unknown.  (The cause is the throwable that
 475.409 +     * caused this throwable to get thrown.)
 475.410 +     *
 475.411 +     * <p>This implementation returns the cause that was supplied via one of
 475.412 +     * the constructors requiring a {@code Throwable}, or that was set after
 475.413 +     * creation with the {@link #initCause(Throwable)} method.  While it is
 475.414 +     * typically unnecessary to override this method, a subclass can override
 475.415 +     * it to return a cause set by some other means.  This is appropriate for
 475.416 +     * a "legacy chained throwable" that predates the addition of chained
 475.417 +     * exceptions to {@code Throwable}.  Note that it is <i>not</i>
 475.418 +     * necessary to override any of the {@code PrintStackTrace} methods,
 475.419 +     * all of which invoke the {@code getCause} method to determine the
 475.420 +     * cause of a throwable.
 475.421 +     *
 475.422 +     * @return  the cause of this throwable or {@code null} if the
 475.423 +     *          cause is nonexistent or unknown.
 475.424 +     * @since 1.4
 475.425 +     */
 475.426 +    public synchronized Throwable getCause() {
 475.427 +        return (cause==this ? null : cause);
 475.428 +    }
 475.429 +
 475.430 +    /**
 475.431 +     * Initializes the <i>cause</i> of this throwable to the specified value.
 475.432 +     * (The cause is the throwable that caused this throwable to get thrown.)
 475.433 +     *
 475.434 +     * <p>This method can be called at most once.  It is generally called from
 475.435 +     * within the constructor, or immediately after creating the
 475.436 +     * throwable.  If this throwable was created
 475.437 +     * with {@link #Throwable(Throwable)} or
 475.438 +     * {@link #Throwable(String,Throwable)}, this method cannot be called
 475.439 +     * even once.
 475.440 +     *
 475.441 +     * <p>An example of using this method on a legacy throwable type
 475.442 +     * without other support for setting the cause is:
 475.443 +     *
 475.444 +     * <pre>
 475.445 +     * try {
 475.446 +     *     lowLevelOp();
 475.447 +     * } catch (LowLevelException le) {
 475.448 +     *     throw (HighLevelException)
 475.449 +     *           new HighLevelException().initCause(le); // Legacy constructor
 475.450 +     * }
 475.451 +     * </pre>
 475.452 +     *
 475.453 +     * @param  cause the cause (which is saved for later retrieval by the
 475.454 +     *         {@link #getCause()} method).  (A {@code null} value is
 475.455 +     *         permitted, and indicates that the cause is nonexistent or
 475.456 +     *         unknown.)
 475.457 +     * @return  a reference to this {@code Throwable} instance.
 475.458 +     * @throws IllegalArgumentException if {@code cause} is this
 475.459 +     *         throwable.  (A throwable cannot be its own cause.)
 475.460 +     * @throws IllegalStateException if this throwable was
 475.461 +     *         created with {@link #Throwable(Throwable)} or
 475.462 +     *         {@link #Throwable(String,Throwable)}, or this method has already
 475.463 +     *         been called on this throwable.
 475.464 +     * @since  1.4
 475.465 +     */
 475.466 +    public synchronized Throwable initCause(Throwable cause) {
 475.467 +        if (this.cause != this)
 475.468 +            throw new IllegalStateException("Can't overwrite cause");
 475.469 +        if (cause == this)
 475.470 +            throw new IllegalArgumentException("Self-causation not permitted");
 475.471 +        this.cause = cause;
 475.472 +        return this;
 475.473 +    }
 475.474 +
 475.475 +    /**
 475.476 +     * Returns a short description of this throwable.
 475.477 +     * The result is the concatenation of:
 475.478 +     * <ul>
 475.479 +     * <li> the {@linkplain Class#getName() name} of the class of this object
 475.480 +     * <li> ": " (a colon and a space)
 475.481 +     * <li> the result of invoking this object's {@link #getLocalizedMessage}
 475.482 +     *      method
 475.483 +     * </ul>
 475.484 +     * If {@code getLocalizedMessage} returns {@code null}, then just
 475.485 +     * the class name is returned.
 475.486 +     *
 475.487 +     * @return a string representation of this throwable.
 475.488 +     */
 475.489 +    public String toString() {
 475.490 +        String s = getClass().getName();
 475.491 +        String message = getLocalizedMessage();
 475.492 +        return (message != null) ? (s + ": " + message) : s;
 475.493 +    }
 475.494 +
 475.495 +    /**
 475.496 +     * Prints this throwable and its backtrace to the
 475.497 +     * standard error stream. This method prints a stack trace for this
 475.498 +     * {@code Throwable} object on the error output stream that is
 475.499 +     * the value of the field {@code System.err}. The first line of
 475.500 +     * output contains the result of the {@link #toString()} method for
 475.501 +     * this object.  Remaining lines represent data previously recorded by
 475.502 +     * the method {@link #fillInStackTrace()}. The format of this
 475.503 +     * information depends on the implementation, but the following
 475.504 +     * example may be regarded as typical:
 475.505 +     * <blockquote><pre>
 475.506 +     * java.lang.NullPointerException
 475.507 +     *         at MyClass.mash(MyClass.java:9)
 475.508 +     *         at MyClass.crunch(MyClass.java:6)
 475.509 +     *         at MyClass.main(MyClass.java:3)
 475.510 +     * </pre></blockquote>
 475.511 +     * This example was produced by running the program:
 475.512 +     * <pre>
 475.513 +     * class MyClass {
 475.514 +     *     public static void main(String[] args) {
 475.515 +     *         crunch(null);
 475.516 +     *     }
 475.517 +     *     static void crunch(int[] a) {
 475.518 +     *         mash(a);
 475.519 +     *     }
 475.520 +     *     static void mash(int[] b) {
 475.521 +     *         System.out.println(b[0]);
 475.522 +     *     }
 475.523 +     * }
 475.524 +     * </pre>
 475.525 +     * The backtrace for a throwable with an initialized, non-null cause
 475.526 +     * should generally include the backtrace for the cause.  The format
 475.527 +     * of this information depends on the implementation, but the following
 475.528 +     * example may be regarded as typical:
 475.529 +     * <pre>
 475.530 +     * HighLevelException: MidLevelException: LowLevelException
 475.531 +     *         at Junk.a(Junk.java:13)
 475.532 +     *         at Junk.main(Junk.java:4)
 475.533 +     * Caused by: MidLevelException: LowLevelException
 475.534 +     *         at Junk.c(Junk.java:23)
 475.535 +     *         at Junk.b(Junk.java:17)
 475.536 +     *         at Junk.a(Junk.java:11)
 475.537 +     *         ... 1 more
 475.538 +     * Caused by: LowLevelException
 475.539 +     *         at Junk.e(Junk.java:30)
 475.540 +     *         at Junk.d(Junk.java:27)
 475.541 +     *         at Junk.c(Junk.java:21)
 475.542 +     *         ... 3 more
 475.543 +     * </pre>
 475.544 +     * Note the presence of lines containing the characters {@code "..."}.
 475.545 +     * These lines indicate that the remainder of the stack trace for this
 475.546 +     * exception matches the indicated number of frames from the bottom of the
 475.547 +     * stack trace of the exception that was caused by this exception (the
 475.548 +     * "enclosing" exception).  This shorthand can greatly reduce the length
 475.549 +     * of the output in the common case where a wrapped exception is thrown
 475.550 +     * from same method as the "causative exception" is caught.  The above
 475.551 +     * example was produced by running the program:
 475.552 +     * <pre>
 475.553 +     * public class Junk {
 475.554 +     *     public static void main(String args[]) {
 475.555 +     *         try {
 475.556 +     *             a();
 475.557 +     *         } catch(HighLevelException e) {
 475.558 +     *             e.printStackTrace();
 475.559 +     *         }
 475.560 +     *     }
 475.561 +     *     static void a() throws HighLevelException {
 475.562 +     *         try {
 475.563 +     *             b();
 475.564 +     *         } catch(MidLevelException e) {
 475.565 +     *             throw new HighLevelException(e);
 475.566 +     *         }
 475.567 +     *     }
 475.568 +     *     static void b() throws MidLevelException {
 475.569 +     *         c();
 475.570 +     *     }
 475.571 +     *     static void c() throws MidLevelException {
 475.572 +     *         try {
 475.573 +     *             d();
 475.574 +     *         } catch(LowLevelException e) {
 475.575 +     *             throw new MidLevelException(e);
 475.576 +     *         }
 475.577 +     *     }
 475.578 +     *     static void d() throws LowLevelException {
 475.579 +     *        e();
 475.580 +     *     }
 475.581 +     *     static void e() throws LowLevelException {
 475.582 +     *         throw new LowLevelException();
 475.583 +     *     }
 475.584 +     * }
 475.585 +     *
 475.586 +     * class HighLevelException extends Exception {
 475.587 +     *     HighLevelException(Throwable cause) { super(cause); }
 475.588 +     * }
 475.589 +     *
 475.590 +     * class MidLevelException extends Exception {
 475.591 +     *     MidLevelException(Throwable cause)  { super(cause); }
 475.592 +     * }
 475.593 +     *
 475.594 +     * class LowLevelException extends Exception {
 475.595 +     * }
 475.596 +     * </pre>
 475.597 +     * As of release 7, the platform supports the notion of
 475.598 +     * <i>suppressed exceptions</i> (in conjunction with the {@code
 475.599 +     * try}-with-resources statement). Any exceptions that were
 475.600 +     * suppressed in order to deliver an exception are printed out
 475.601 +     * beneath the stack trace.  The format of this information
 475.602 +     * depends on the implementation, but the following example may be
 475.603 +     * regarded as typical:
 475.604 +     *
 475.605 +     * <pre>
 475.606 +     * Exception in thread "main" java.lang.Exception: Something happened
 475.607 +     *  at Foo.bar(Foo.java:10)
 475.608 +     *  at Foo.main(Foo.java:5)
 475.609 +     *  Suppressed: Resource$CloseFailException: Resource ID = 0
 475.610 +     *          at Resource.close(Resource.java:26)
 475.611 +     *          at Foo.bar(Foo.java:9)
 475.612 +     *          ... 1 more
 475.613 +     * </pre>
 475.614 +     * Note that the "... n more" notation is used on suppressed exceptions
 475.615 +     * just at it is used on causes. Unlike causes, suppressed exceptions are
 475.616 +     * indented beyond their "containing exceptions."
 475.617 +     *
 475.618 +     * <p>An exception can have both a cause and one or more suppressed
 475.619 +     * exceptions:
 475.620 +     * <pre>
 475.621 +     * Exception in thread "main" java.lang.Exception: Main block
 475.622 +     *  at Foo3.main(Foo3.java:7)
 475.623 +     *  Suppressed: Resource$CloseFailException: Resource ID = 2
 475.624 +     *          at Resource.close(Resource.java:26)
 475.625 +     *          at Foo3.main(Foo3.java:5)
 475.626 +     *  Suppressed: Resource$CloseFailException: Resource ID = 1
 475.627 +     *          at Resource.close(Resource.java:26)
 475.628 +     *          at Foo3.main(Foo3.java:5)
 475.629 +     * Caused by: java.lang.Exception: I did it
 475.630 +     *  at Foo3.main(Foo3.java:8)
 475.631 +     * </pre>
 475.632 +     * Likewise, a suppressed exception can have a cause:
 475.633 +     * <pre>
 475.634 +     * Exception in thread "main" java.lang.Exception: Main block
 475.635 +     *  at Foo4.main(Foo4.java:6)
 475.636 +     *  Suppressed: Resource2$CloseFailException: Resource ID = 1
 475.637 +     *          at Resource2.close(Resource2.java:20)
 475.638 +     *          at Foo4.main(Foo4.java:5)
 475.639 +     *  Caused by: java.lang.Exception: Rats, you caught me
 475.640 +     *          at Resource2$CloseFailException.<init>(Resource2.java:45)
 475.641 +     *          ... 2 more
 475.642 +     * </pre>
 475.643 +     */
 475.644 +//    public void printStackTrace() {
 475.645 +//        printStackTrace(System.err);
 475.646 +//    }
 475.647 +//
 475.648 +//    /**
 475.649 +//     * Prints this throwable and its backtrace to the specified print stream.
 475.650 +//     *
 475.651 +//     * @param s {@code PrintStream} to use for output
 475.652 +//     */
 475.653 +//    public void printStackTrace(PrintStream s) {
 475.654 +//        printStackTrace(new WrappedPrintStream(s));
 475.655 +//    }
 475.656 +//
 475.657 +//    private void printStackTrace(PrintStreamOrWriter s) {
 475.658 +//        // Guard against malicious overrides of Throwable.equals by
 475.659 +//        // using a Set with identity equality semantics.
 475.660 +////        Set<Throwable> dejaVu =
 475.661 +////            Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
 475.662 +////        dejaVu.add(this);
 475.663 +//
 475.664 +//        synchronized (s.lock()) {
 475.665 +//            // Print our stack trace
 475.666 +//            s.println(this);
 475.667 +//            StackTraceElement[] trace = getOurStackTrace();
 475.668 +//            for (StackTraceElement traceElement : trace)
 475.669 +//                s.println("\tat " + traceElement);
 475.670 +//
 475.671 +//            // Print suppressed exceptions, if any
 475.672 +////            for (Throwable se : getSuppressed())
 475.673 +////                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
 475.674 +//
 475.675 +//            // Print cause, if any
 475.676 +//            Throwable ourCause = getCause();
 475.677 +////            if (ourCause != null)
 475.678 +////                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
 475.679 +//        }
 475.680 +//    }
 475.681 +//
 475.682 +//    /**
 475.683 +//     * Print our stack trace as an enclosed exception for the specified
 475.684 +//     * stack trace.
 475.685 +//     */
 475.686 +//    private void printEnclosedStackTrace(PrintStreamOrWriter s,
 475.687 +//                                         StackTraceElement[] enclosingTrace,
 475.688 +//                                         String caption,
 475.689 +//                                         String prefix,
 475.690 +//                                         Object dejaVu) {
 475.691 +//        assert Thread.holdsLock(s.lock());
 475.692 +//        {
 475.693 +//            // Compute number of frames in common between this and enclosing trace
 475.694 +//            StackTraceElement[] trace = getOurStackTrace();
 475.695 +//            int m = trace.length - 1;
 475.696 +//            int n = enclosingTrace.length - 1;
 475.697 +//            while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
 475.698 +//                m--; n--;
 475.699 +//            }
 475.700 +//            int framesInCommon = trace.length - 1 - m;
 475.701 +//
 475.702 +//            // Print our stack trace
 475.703 +//            s.println(prefix + caption + this);
 475.704 +//            for (int i = 0; i <= m; i++)
 475.705 +//                s.println(prefix + "\tat " + trace[i]);
 475.706 +//            if (framesInCommon != 0)
 475.707 +//                s.println(prefix + "\t... " + framesInCommon + " more");
 475.708 +//
 475.709 +//            // Print suppressed exceptions, if any
 475.710 +//            for (Throwable se : getSuppressed())
 475.711 +//                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
 475.712 +//                                           prefix +"\t", dejaVu);
 475.713 +//
 475.714 +//            // Print cause, if any
 475.715 +//            Throwable ourCause = getCause();
 475.716 +//            if (ourCause != null)
 475.717 +//                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
 475.718 +//        }
 475.719 +//    }
 475.720 +//
 475.721 +//    /**
 475.722 +//     * Prints this throwable and its backtrace to the specified
 475.723 +//     * print writer.
 475.724 +//     *
 475.725 +//     * @param s {@code PrintWriter} to use for output
 475.726 +//     * @since   JDK1.1
 475.727 +//     */
 475.728 +//    public void printStackTrace(PrintWriter s) {
 475.729 +//        printStackTrace(new WrappedPrintWriter(s));
 475.730 +//    }
 475.731 +//
 475.732 +//    /**
 475.733 +//     * Wrapper class for PrintStream and PrintWriter to enable a single
 475.734 +//     * implementation of printStackTrace.
 475.735 +//     */
 475.736 +//    private abstract static class PrintStreamOrWriter {
 475.737 +//        /** Returns the object to be locked when using this StreamOrWriter */
 475.738 +//        abstract Object lock();
 475.739 +//
 475.740 +//        /** Prints the specified string as a line on this StreamOrWriter */
 475.741 +//        abstract void println(Object o);
 475.742 +//    }
 475.743 +//
 475.744 +//    private static class WrappedPrintStream extends PrintStreamOrWriter {
 475.745 +//        private final PrintStream printStream;
 475.746 +//
 475.747 +//        WrappedPrintStream(PrintStream printStream) {
 475.748 +//            this.printStream = printStream;
 475.749 +//        }
 475.750 +//
 475.751 +//        Object lock() {
 475.752 +//            return printStream;
 475.753 +//        }
 475.754 +//
 475.755 +//        void println(Object o) {
 475.756 +//            printStream.println(o);
 475.757 +//        }
 475.758 +//    }
 475.759 +//
 475.760 +//    private static class WrappedPrintWriter extends PrintStreamOrWriter {
 475.761 +//        private final PrintWriter printWriter;
 475.762 +//
 475.763 +//        WrappedPrintWriter(PrintWriter printWriter) {
 475.764 +//            this.printWriter = printWriter;
 475.765 +//        }
 475.766 +//
 475.767 +//        Object lock() {
 475.768 +//            return printWriter;
 475.769 +//        }
 475.770 +//
 475.771 +//        void println(Object o) {
 475.772 +//            printWriter.println(o);
 475.773 +//        }
 475.774 +//    }
 475.775 +
 475.776 +    /**
 475.777 +     * Fills in the execution stack trace. This method records within this
 475.778 +     * {@code Throwable} object information about the current state of
 475.779 +     * the stack frames for the current thread.
 475.780 +     *
 475.781 +     * <p>If the stack trace of this {@code Throwable} {@linkplain
 475.782 +     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 475.783 +     * writable}, calling this method has no effect.
 475.784 +     *
 475.785 +     * @return  a reference to this {@code Throwable} instance.
 475.786 +     * @see     java.lang.Throwable#printStackTrace()
 475.787 +     */
 475.788 +    public synchronized Throwable fillInStackTrace() {
 475.789 +        if (stackTrace != null ||
 475.790 +            backtrace != null /* Out of protocol state */ ) {
 475.791 +            fillInStackTrace(0);
 475.792 +            stackTrace = UNASSIGNED_STACK;
 475.793 +        }
 475.794 +        return this;
 475.795 +    }
 475.796 +
 475.797 +    @JavaScriptBody(args = { "dummy" }, body = "")
 475.798 +    private native Throwable fillInStackTrace(int dummy);
 475.799 +
 475.800 +    /**
 475.801 +     * Provides programmatic access to the stack trace information printed by
 475.802 +     * {@link #printStackTrace()}.  Returns an array of stack trace elements,
 475.803 +     * each representing one stack frame.  The zeroth element of the array
 475.804 +     * (assuming the array's length is non-zero) represents the top of the
 475.805 +     * stack, which is the last method invocation in the sequence.  Typically,
 475.806 +     * this is the point at which this throwable was created and thrown.
 475.807 +     * The last element of the array (assuming the array's length is non-zero)
 475.808 +     * represents the bottom of the stack, which is the first method invocation
 475.809 +     * in the sequence.
 475.810 +     *
 475.811 +     * <p>Some virtual machines may, under some circumstances, omit one
 475.812 +     * or more stack frames from the stack trace.  In the extreme case,
 475.813 +     * a virtual machine that has no stack trace information concerning
 475.814 +     * this throwable is permitted to return a zero-length array from this
 475.815 +     * method.  Generally speaking, the array returned by this method will
 475.816 +     * contain one element for every frame that would be printed by
 475.817 +     * {@code printStackTrace}.  Writes to the returned array do not
 475.818 +     * affect future calls to this method.
 475.819 +     *
 475.820 +     * @return an array of stack trace elements representing the stack trace
 475.821 +     *         pertaining to this throwable.
 475.822 +     * @since  1.4
 475.823 +     */
 475.824 +    public StackTraceElement[] getStackTrace() {
 475.825 +        return getOurStackTrace().clone();
 475.826 +    }
 475.827 +
 475.828 +    private synchronized StackTraceElement[] getOurStackTrace() {
 475.829 +        // Initialize stack trace field with information from
 475.830 +        // backtrace if this is the first call to this method
 475.831 +        if (stackTrace == UNASSIGNED_STACK ||
 475.832 +            (stackTrace == null && backtrace != null) /* Out of protocol state */) {
 475.833 +            int depth = getStackTraceDepth();
 475.834 +            stackTrace = new StackTraceElement[depth];
 475.835 +            for (int i=0; i < depth; i++)
 475.836 +                stackTrace[i] = getStackTraceElement(i);
 475.837 +        } else if (stackTrace == null) {
 475.838 +            return UNASSIGNED_STACK;
 475.839 +        }
 475.840 +        return stackTrace;
 475.841 +    }
 475.842 +
 475.843 +    /**
 475.844 +     * Sets the stack trace elements that will be returned by
 475.845 +     * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
 475.846 +     * and related methods.
 475.847 +     *
 475.848 +     * This method, which is designed for use by RPC frameworks and other
 475.849 +     * advanced systems, allows the client to override the default
 475.850 +     * stack trace that is either generated by {@link #fillInStackTrace()}
 475.851 +     * when a throwable is constructed or deserialized when a throwable is
 475.852 +     * read from a serialization stream.
 475.853 +     *
 475.854 +     * <p>If the stack trace of this {@code Throwable} {@linkplain
 475.855 +     * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 475.856 +     * writable}, calling this method has no effect other than
 475.857 +     * validating its argument.
 475.858 +     *
 475.859 +     * @param   stackTrace the stack trace elements to be associated with
 475.860 +     * this {@code Throwable}.  The specified array is copied by this
 475.861 +     * call; changes in the specified array after the method invocation
 475.862 +     * returns will have no affect on this {@code Throwable}'s stack
 475.863 +     * trace.
 475.864 +     *
 475.865 +     * @throws NullPointerException if {@code stackTrace} is
 475.866 +     *         {@code null} or if any of the elements of
 475.867 +     *         {@code stackTrace} are {@code null}
 475.868 +     *
 475.869 +     * @since  1.4
 475.870 +     */
 475.871 +    public void setStackTrace(StackTraceElement[] stackTrace) {
 475.872 +        // Validate argument
 475.873 +        StackTraceElement[] defensiveCopy = stackTrace.clone();
 475.874 +        for (int i = 0; i < defensiveCopy.length; i++) {
 475.875 +            if (defensiveCopy[i] == null)
 475.876 +                throw new NullPointerException("stackTrace[" + i + "]");
 475.877 +        }
 475.878 +
 475.879 +        synchronized (this) {
 475.880 +            if (this.stackTrace == null && // Immutable stack
 475.881 +                backtrace == null) // Test for out of protocol state
 475.882 +                return;
 475.883 +            this.stackTrace = defensiveCopy;
 475.884 +        }
 475.885 +    }
 475.886 +
 475.887 +    /**
 475.888 +     * Returns the number of elements in the stack trace (or 0 if the stack
 475.889 +     * trace is unavailable).
 475.890 +     *
 475.891 +     * package-protection for use by SharedSecrets.
 475.892 +     */
 475.893 +    native int getStackTraceDepth();
 475.894 +
 475.895 +    /**
 475.896 +     * Returns the specified element of the stack trace.
 475.897 +     *
 475.898 +     * package-protection for use by SharedSecrets.
 475.899 +     *
 475.900 +     * @param index index of the element to return.
 475.901 +     * @throws IndexOutOfBoundsException if {@code index < 0 ||
 475.902 +     *         index >= getStackTraceDepth() }
 475.903 +     */
 475.904 +    native StackTraceElement getStackTraceElement(int index);
 475.905 +
 475.906 +    /**
 475.907 +     * Reads a {@code Throwable} from a stream, enforcing
 475.908 +     * well-formedness constraints on fields.  Null entries and
 475.909 +     * self-pointers are not allowed in the list of {@code
 475.910 +     * suppressedExceptions}.  Null entries are not allowed for stack
 475.911 +     * trace elements.  A null stack trace in the serial form results
 475.912 +     * in a zero-length stack element array. A single-element stack
 475.913 +     * trace whose entry is equal to {@code new StackTraceElement("",
 475.914 +     * "", null, Integer.MIN_VALUE)} results in a {@code null} {@code
 475.915 +     * stackTrace} field.
 475.916 +     *
 475.917 +     * Note that there are no constraints on the value the {@code
 475.918 +     * cause} field can hold; both {@code null} and {@code this} are
 475.919 +     * valid values for the field.
 475.920 +     */
 475.921 +//    private void readObject(ObjectInputStream s)
 475.922 +//        throws IOException, ClassNotFoundException {
 475.923 +//        s.defaultReadObject();     // read in all fields
 475.924 +//        if (suppressedExceptions != null) {
 475.925 +//            List<Throwable> suppressed = null;
 475.926 +//            if (suppressedExceptions.isEmpty()) {
 475.927 +//                // Use the sentinel for a zero-length list
 475.928 +//                suppressed = SUPPRESSED_SENTINEL;
 475.929 +//            } else { // Copy Throwables to new list
 475.930 +//                suppressed = new ArrayList<Throwable>(1);
 475.931 +//                for (Throwable t : suppressedExceptions) {
 475.932 +//                    // Enforce constraints on suppressed exceptions in
 475.933 +//                    // case of corrupt or malicious stream.
 475.934 +//                    if (t == null)
 475.935 +//                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
 475.936 +//                    if (t == this)
 475.937 +//                        throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
 475.938 +//                    suppressed.add(t);
 475.939 +//                }
 475.940 +//            }
 475.941 +//            suppressedExceptions = suppressed;
 475.942 +//        } // else a null suppressedExceptions field remains null
 475.943 +//
 475.944 +//        /*
 475.945 +//         * For zero-length stack traces, use a clone of
 475.946 +//         * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
 475.947 +//         * allow identity comparison against UNASSIGNED_STACK in
 475.948 +//         * getOurStackTrace.  The identity of UNASSIGNED_STACK in
 475.949 +//         * stackTrace indicates to the getOurStackTrace method that
 475.950 +//         * the stackTrace needs to be constructed from the information
 475.951 +//         * in backtrace.
 475.952 +//         */
 475.953 +//        if (stackTrace != null) {
 475.954 +//            if (stackTrace.length == 0) {
 475.955 +//                stackTrace = UNASSIGNED_STACK.clone();
 475.956 +//            }  else if (stackTrace.length == 1 &&
 475.957 +//                        // Check for the marker of an immutable stack trace
 475.958 +//                        SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
 475.959 +//                stackTrace = null;
 475.960 +//            } else { // Verify stack trace elements are non-null.
 475.961 +//                for(StackTraceElement ste : stackTrace) {
 475.962 +//                    if (ste == null)
 475.963 +//                        throw new NullPointerException("null StackTraceElement in serial stream. ");
 475.964 +//                }
 475.965 +//            }
 475.966 +//        } else {
 475.967 +//            // A null stackTrace field in the serial form can result
 475.968 +//            // from an exception serialized without that field in
 475.969 +//            // older JDK releases; treat such exceptions as having
 475.970 +//            // empty stack traces.
 475.971 +//            stackTrace = UNASSIGNED_STACK.clone();
 475.972 +//        }
 475.973 +//    }
 475.974 +
 475.975 +    /**
 475.976 +     * Write a {@code Throwable} object to a stream.
 475.977 +     *
 475.978 +     * A {@code null} stack trace field is represented in the serial
 475.979 +     * form as a one-element array whose element is equal to {@code
 475.980 +     * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
 475.981 +     */
 475.982 +//    private synchronized void writeObject(ObjectOutputStream s)
 475.983 +//        throws IOException {
 475.984 +//        // Ensure that the stackTrace field is initialized to a
 475.985 +//        // non-null value, if appropriate.  As of JDK 7, a null stack
 475.986 +//        // trace field is a valid value indicating the stack trace
 475.987 +//        // should not be set.
 475.988 +//        getOurStackTrace();
 475.989 +//
 475.990 +//        StackTraceElement[] oldStackTrace = stackTrace;
 475.991 +//        try {
 475.992 +//            if (stackTrace == null)
 475.993 +//                stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
 475.994 +//            s.defaultWriteObject();
 475.995 +//        } finally {
 475.996 +//            stackTrace = oldStackTrace;
 475.997 +//        }
 475.998 +//    }
 475.999 +
475.1000 +    /**
475.1001 +     * Appends the specified exception to the exceptions that were
475.1002 +     * suppressed in order to deliver this exception. This method is
475.1003 +     * thread-safe and typically called (automatically and implicitly)
475.1004 +     * by the {@code try}-with-resources statement.
475.1005 +     *
475.1006 +     * <p>The suppression behavior is enabled <em>unless</em> disabled
475.1007 +     * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
475.1008 +     * a constructor}.  When suppression is disabled, this method does
475.1009 +     * nothing other than to validate its argument.
475.1010 +     *
475.1011 +     * <p>Note that when one exception {@linkplain
475.1012 +     * #initCause(Throwable) causes} another exception, the first
475.1013 +     * exception is usually caught and then the second exception is
475.1014 +     * thrown in response.  In other words, there is a causal
475.1015 +     * connection between the two exceptions.
475.1016 +     *
475.1017 +     * In contrast, there are situations where two independent
475.1018 +     * exceptions can be thrown in sibling code blocks, in particular
475.1019 +     * in the {@code try} block of a {@code try}-with-resources
475.1020 +     * statement and the compiler-generated {@code finally} block
475.1021 +     * which closes the resource.
475.1022 +     *
475.1023 +     * In these situations, only one of the thrown exceptions can be
475.1024 +     * propagated.  In the {@code try}-with-resources statement, when
475.1025 +     * there are two such exceptions, the exception originating from
475.1026 +     * the {@code try} block is propagated and the exception from the
475.1027 +     * {@code finally} block is added to the list of exceptions
475.1028 +     * suppressed by the exception from the {@code try} block.  As an
475.1029 +     * exception unwinds the stack, it can accumulate multiple
475.1030 +     * suppressed exceptions.
475.1031 +     *
475.1032 +     * <p>An exception may have suppressed exceptions while also being
475.1033 +     * caused by another exception.  Whether or not an exception has a
475.1034 +     * cause is semantically known at the time of its creation, unlike
475.1035 +     * whether or not an exception will suppress other exceptions
475.1036 +     * which is typically only determined after an exception is
475.1037 +     * thrown.
475.1038 +     *
475.1039 +     * <p>Note that programmer written code is also able to take
475.1040 +     * advantage of calling this method in situations where there are
475.1041 +     * multiple sibling exceptions and only one can be propagated.
475.1042 +     *
475.1043 +     * @param exception the exception to be added to the list of
475.1044 +     *        suppressed exceptions
475.1045 +     * @throws IllegalArgumentException if {@code exception} is this
475.1046 +     *         throwable; a throwable cannot suppress itself.
475.1047 +     * @throws NullPointerException if {@code exception} is {@code null}
475.1048 +     * @since 1.7
475.1049 +     */
475.1050 +    public final synchronized void addSuppressed(Throwable exception) {
475.1051 +        if (exception == this)
475.1052 +            throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
475.1053 +
475.1054 +        if (exception == null)
475.1055 +            throw new NullPointerException(NULL_CAUSE_MESSAGE);
475.1056 +
475.1057 +//        if (suppressedExceptions == null) // Suppressed exceptions not recorded
475.1058 +//            return;
475.1059 +//
475.1060 +//        if (suppressedExceptions == SUPPRESSED_SENTINEL)
475.1061 +//            suppressedExceptions = new ArrayList<Throwable>(1);
475.1062 +//
475.1063 +//        suppressedExceptions.add(exception);
475.1064 +    }
475.1065 +
475.1066 +    private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
475.1067 +
475.1068 +    /**
475.1069 +     * Returns an array containing all of the exceptions that were
475.1070 +     * suppressed, typically by the {@code try}-with-resources
475.1071 +     * statement, in order to deliver this exception.
475.1072 +     *
475.1073 +     * If no exceptions were suppressed or {@linkplain
475.1074 +     * #Throwable(String, Throwable, boolean, boolean) suppression is
475.1075 +     * disabled}, an empty array is returned.  This method is
475.1076 +     * thread-safe.  Writes to the returned array do not affect future
475.1077 +     * calls to this method.
475.1078 +     *
475.1079 +     * @return an array containing all of the exceptions that were
475.1080 +     *         suppressed to deliver this exception.
475.1081 +     * @since 1.7
475.1082 +     */
475.1083 +    public final synchronized Throwable[] getSuppressed() {
475.1084 +        return new Throwable[0];
475.1085 +//        if (suppressedExceptions == SUPPRESSED_SENTINEL ||
475.1086 +//            suppressedExceptions == null)
475.1087 +//            return EMPTY_THROWABLE_ARRAY;
475.1088 +//        else
475.1089 +//            return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
475.1090 +    }
475.1091 +}
   476.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   476.2 +++ b/rt/emul/mini/src/main/java/java/lang/VirtualMachineError.java	Wed Feb 27 11:24:58 2013 +0100
   476.3 @@ -0,0 +1,54 @@
   476.4 +/*
   476.5 + * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
   476.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   476.7 + *
   476.8 + * This code is free software; you can redistribute it and/or modify it
   476.9 + * under the terms of the GNU General Public License version 2 only, as
  476.10 + * published by the Free Software Foundation.  Oracle designates this
  476.11 + * particular file as subject to the "Classpath" exception as provided
  476.12 + * by Oracle in the LICENSE file that accompanied this code.
  476.13 + *
  476.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  476.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  476.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  476.17 + * version 2 for more details (a copy is included in the LICENSE file that
  476.18 + * accompanied this code).
  476.19 + *
  476.20 + * You should have received a copy of the GNU General Public License version
  476.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  476.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  476.23 + *
  476.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  476.25 + * or visit www.oracle.com if you need additional information or have any
  476.26 + * questions.
  476.27 + */
  476.28 +
  476.29 +package java.lang;
  476.30 +
  476.31 +/**
  476.32 + * Thrown to indicate that the Java Virtual Machine is broken or has
  476.33 + * run out of resources necessary for it to continue operating.
  476.34 + *
  476.35 + *
  476.36 + * @author  Frank Yellin
  476.37 + * @since   JDK1.0
  476.38 + */
  476.39 +abstract public
  476.40 +class VirtualMachineError extends Error {
  476.41 +    /**
  476.42 +     * Constructs a <code>VirtualMachineError</code> with no detail message.
  476.43 +     */
  476.44 +    public VirtualMachineError() {
  476.45 +        super();
  476.46 +    }
  476.47 +
  476.48 +    /**
  476.49 +     * Constructs a <code>VirtualMachineError</code> with the specified
  476.50 +     * detail message.
  476.51 +     *
  476.52 +     * @param   s   the detail message.
  476.53 +     */
  476.54 +    public VirtualMachineError(String s) {
  476.55 +        super(s);
  476.56 +    }
  476.57 +}
   477.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   477.2 +++ b/rt/emul/mini/src/main/java/java/lang/Void.java	Wed Feb 27 11:24:58 2013 +0100
   477.3 @@ -0,0 +1,49 @@
   477.4 +/*
   477.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   477.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   477.7 + *
   477.8 + * This code is free software; you can redistribute it and/or modify it
   477.9 + * under the terms of the GNU General Public License version 2 only, as
  477.10 + * published by the Free Software Foundation.  Oracle designates this
  477.11 + * particular file as subject to the "Classpath" exception as provided
  477.12 + * by Oracle in the LICENSE file that accompanied this code.
  477.13 + *
  477.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  477.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  477.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  477.17 + * version 2 for more details (a copy is included in the LICENSE file that
  477.18 + * accompanied this code).
  477.19 + *
  477.20 + * You should have received a copy of the GNU General Public License version
  477.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  477.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  477.23 + *
  477.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  477.25 + * or visit www.oracle.com if you need additional information or have any
  477.26 + * questions.
  477.27 + */
  477.28 +
  477.29 +package java.lang;
  477.30 +
  477.31 +/**
  477.32 + * The {@code Void} class is an uninstantiable placeholder class to hold a
  477.33 + * reference to the {@code Class} object representing the Java keyword
  477.34 + * void.
  477.35 + *
  477.36 + * @author  unascribed
  477.37 + * @since   JDK1.1
  477.38 + */
  477.39 +public final
  477.40 +class Void {
  477.41 +
  477.42 +    /**
  477.43 +     * The {@code Class} object representing the pseudo-type corresponding to
  477.44 +     * the keyword {@code void}.
  477.45 +     */
  477.46 +    public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
  477.47 +
  477.48 +    /*
  477.49 +     * The Void class cannot be instantiated.
  477.50 +     */
  477.51 +    private Void() {}
  477.52 +}
   478.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   478.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/Annotation.java	Wed Feb 27 11:24:58 2013 +0100
   478.3 @@ -0,0 +1,131 @@
   478.4 +/*
   478.5 + * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
   478.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   478.7 + *
   478.8 + * This code is free software; you can redistribute it and/or modify it
   478.9 + * under the terms of the GNU General Public License version 2 only, as
  478.10 + * published by the Free Software Foundation.  Oracle designates this
  478.11 + * particular file as subject to the "Classpath" exception as provided
  478.12 + * by Oracle in the LICENSE file that accompanied this code.
  478.13 + *
  478.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  478.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  478.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  478.17 + * version 2 for more details (a copy is included in the LICENSE file that
  478.18 + * accompanied this code).
  478.19 + *
  478.20 + * You should have received a copy of the GNU General Public License version
  478.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  478.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  478.23 + *
  478.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  478.25 + * or visit www.oracle.com if you need additional information or have any
  478.26 + * questions.
  478.27 + */
  478.28 +
  478.29 +package java.lang.annotation;
  478.30 +
  478.31 +/**
  478.32 + * The common interface extended by all annotation types.  Note that an
  478.33 + * interface that manually extends this one does <i>not</i> define
  478.34 + * an annotation type.  Also note that this interface does not itself
  478.35 + * define an annotation type.
  478.36 + *
  478.37 + * More information about annotation types can be found in section 9.6 of
  478.38 + * <cite>The Java&trade; Language Specification</cite>.
  478.39 + *
  478.40 + * @author  Josh Bloch
  478.41 + * @since   1.5
  478.42 + */
  478.43 +public interface Annotation {
  478.44 +    /**
  478.45 +     * Returns true if the specified object represents an annotation
  478.46 +     * that is logically equivalent to this one.  In other words,
  478.47 +     * returns true if the specified object is an instance of the same
  478.48 +     * annotation type as this instance, all of whose members are equal
  478.49 +     * to the corresponding member of this annotation, as defined below:
  478.50 +     * <ul>
  478.51 +     *    <li>Two corresponding primitive typed members whose values are
  478.52 +     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
  478.53 +     *    unless their type is <tt>float</tt> or <tt>double</tt>.
  478.54 +     *
  478.55 +     *    <li>Two corresponding <tt>float</tt> members whose values
  478.56 +     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  478.57 +     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
  478.58 +     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  478.59 +     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
  478.60 +     *
  478.61 +     *    <li>Two corresponding <tt>double</tt> members whose values
  478.62 +     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  478.63 +     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
  478.64 +     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  478.65 +     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
  478.66 +     *
  478.67 +     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
  478.68 +     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
  478.69 +     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
  478.70 +     *    definition is recursive for annotation typed members.)
  478.71 +     *
  478.72 +     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
  478.73 +     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
  478.74 +     *    appropriate overloading of {@link java.util.Arrays#equals}.
  478.75 +     * </ul>
  478.76 +     *
  478.77 +     * @return true if the specified object represents an annotation
  478.78 +     *     that is logically equivalent to this one, otherwise false
  478.79 +     */
  478.80 +    boolean equals(Object obj);
  478.81 +
  478.82 +    /**
  478.83 +     * Returns the hash code of this annotation, as defined below:
  478.84 +     *
  478.85 +     * <p>The hash code of an annotation is the sum of the hash codes
  478.86 +     * of its members (including those with default values), as defined
  478.87 +     * below:
  478.88 +     *
  478.89 +     * The hash code of an annotation member is (127 times the hash code
  478.90 +     * of the member-name as computed by {@link String#hashCode()}) XOR
  478.91 +     * the hash code of the member-value, as defined below:
  478.92 +     *
  478.93 +     * <p>The hash code of a member-value depends on its type:
  478.94 +     * <ul>
  478.95 +     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
  478.96 +     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
  478.97 +     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
  478.98 +     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
  478.99 +     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
 478.100 +     *     {@link Long}, {@link Short}, or {@link Boolean}).
 478.101 +     *
 478.102 +     * <li>The hash code of a string, enum, class, or annotation member-value
 478.103 +     I     <tt><i>v</i></tt> is computed as by calling
 478.104 +     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
 478.105 +     *     member values, this is a recursive definition.)
 478.106 +     *
 478.107 +     * <li>The hash code of an array member-value is computed by calling
 478.108 +     *     the appropriate overloading of
 478.109 +     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
 478.110 +     *     on the value.  (There is one overloading for each primitive
 478.111 +     *     type, and one for object reference types.)
 478.112 +     * </ul>
 478.113 +     *
 478.114 +     * @return the hash code of this annotation
 478.115 +     */
 478.116 +    int hashCode();
 478.117 +
 478.118 +    /**
 478.119 +     * Returns a string representation of this annotation.  The details
 478.120 +     * of the representation are implementation-dependent, but the following
 478.121 +     * may be regarded as typical:
 478.122 +     * <pre>
 478.123 +     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
 478.124 +     * </pre>
 478.125 +     *
 478.126 +     * @return a string representation of this annotation
 478.127 +     */
 478.128 +    String toString();
 478.129 +
 478.130 +    /**
 478.131 +     * Returns the annotation type of this annotation.
 478.132 +     */
 478.133 +    Class<? extends Annotation> annotationType();
 478.134 +}
   479.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   479.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/Documented.java	Wed Feb 27 11:24:58 2013 +0100
   479.3 @@ -0,0 +1,43 @@
   479.4 +/*
   479.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   479.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   479.7 + *
   479.8 + * This code is free software; you can redistribute it and/or modify it
   479.9 + * under the terms of the GNU General Public License version 2 only, as
  479.10 + * published by the Free Software Foundation.  Oracle designates this
  479.11 + * particular file as subject to the "Classpath" exception as provided
  479.12 + * by Oracle in the LICENSE file that accompanied this code.
  479.13 + *
  479.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  479.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  479.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  479.17 + * version 2 for more details (a copy is included in the LICENSE file that
  479.18 + * accompanied this code).
  479.19 + *
  479.20 + * You should have received a copy of the GNU General Public License version
  479.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  479.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  479.23 + *
  479.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  479.25 + * or visit www.oracle.com if you need additional information or have any
  479.26 + * questions.
  479.27 + */
  479.28 +
  479.29 +package java.lang.annotation;
  479.30 +
  479.31 +/**
  479.32 + * Indicates that annotations with a type are to be documented by javadoc
  479.33 + * and similar tools by default.  This type should be used to annotate the
  479.34 + * declarations of types whose annotations affect the use of annotated
  479.35 + * elements by their clients.  If a type declaration is annotated with
  479.36 + * Documented, its annotations become part of the public API
  479.37 + * of the annotated elements.
  479.38 + *
  479.39 + * @author  Joshua Bloch
  479.40 + * @since 1.5
  479.41 + */
  479.42 +@Documented
  479.43 +@Retention(RetentionPolicy.RUNTIME)
  479.44 +@Target(ElementType.ANNOTATION_TYPE)
  479.45 +public @interface Documented {
  479.46 +}
   480.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   480.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/ElementType.java	Wed Feb 27 11:24:58 2013 +0100
   480.3 @@ -0,0 +1,63 @@
   480.4 +/*
   480.5 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   480.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   480.7 + *
   480.8 + * This code is free software; you can redistribute it and/or modify it
   480.9 + * under the terms of the GNU General Public License version 2 only, as
  480.10 + * published by the Free Software Foundation.  Oracle designates this
  480.11 + * particular file as subject to the "Classpath" exception as provided
  480.12 + * by Oracle in the LICENSE file that accompanied this code.
  480.13 + *
  480.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  480.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  480.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  480.17 + * version 2 for more details (a copy is included in the LICENSE file that
  480.18 + * accompanied this code).
  480.19 + *
  480.20 + * You should have received a copy of the GNU General Public License version
  480.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  480.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  480.23 + *
  480.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  480.25 + * or visit www.oracle.com if you need additional information or have any
  480.26 + * questions.
  480.27 + */
  480.28 +
  480.29 +package java.lang.annotation;
  480.30 +
  480.31 +/**
  480.32 + * A program element type.  The constants of this enumerated type
  480.33 + * provide a simple classification of the declared elements in a
  480.34 + * Java program.
  480.35 + *
  480.36 + * <p>These constants are used with the {@link Target} meta-annotation type
  480.37 + * to specify where it is legal to use an annotation type.
  480.38 + *
  480.39 + * @author  Joshua Bloch
  480.40 + * @since 1.5
  480.41 + */
  480.42 +public enum ElementType {
  480.43 +    /** Class, interface (including annotation type), or enum declaration */
  480.44 +    TYPE,
  480.45 +
  480.46 +    /** Field declaration (includes enum constants) */
  480.47 +    FIELD,
  480.48 +
  480.49 +    /** Method declaration */
  480.50 +    METHOD,
  480.51 +
  480.52 +    /** Parameter declaration */
  480.53 +    PARAMETER,
  480.54 +
  480.55 +    /** Constructor declaration */
  480.56 +    CONSTRUCTOR,
  480.57 +
  480.58 +    /** Local variable declaration */
  480.59 +    LOCAL_VARIABLE,
  480.60 +
  480.61 +    /** Annotation type declaration */
  480.62 +    ANNOTATION_TYPE,
  480.63 +
  480.64 +    /** Package declaration */
  480.65 +    PACKAGE
  480.66 +}
   481.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   481.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/Retention.java	Wed Feb 27 11:24:58 2013 +0100
   481.3 @@ -0,0 +1,47 @@
   481.4 +/*
   481.5 + * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
   481.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   481.7 + *
   481.8 + * This code is free software; you can redistribute it and/or modify it
   481.9 + * under the terms of the GNU General Public License version 2 only, as
  481.10 + * published by the Free Software Foundation.  Oracle designates this
  481.11 + * particular file as subject to the "Classpath" exception as provided
  481.12 + * by Oracle in the LICENSE file that accompanied this code.
  481.13 + *
  481.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  481.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  481.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  481.17 + * version 2 for more details (a copy is included in the LICENSE file that
  481.18 + * accompanied this code).
  481.19 + *
  481.20 + * You should have received a copy of the GNU General Public License version
  481.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  481.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  481.23 + *
  481.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  481.25 + * or visit www.oracle.com if you need additional information or have any
  481.26 + * questions.
  481.27 + */
  481.28 +
  481.29 +package java.lang.annotation;
  481.30 +
  481.31 +/**
  481.32 + * Indicates how long annotations with the annotated type are to
  481.33 + * be retained.  If no Retention annotation is present on
  481.34 + * an annotation type declaration, the retention policy defaults to
  481.35 + * {@code RetentionPolicy.CLASS}.
  481.36 + *
  481.37 + * <p>A Retention meta-annotation has effect only if the
  481.38 + * meta-annotated type is used directly for annotation.  It has no
  481.39 + * effect if the meta-annotated type is used as a member type in
  481.40 + * another annotation type.
  481.41 + *
  481.42 + * @author  Joshua Bloch
  481.43 + * @since 1.5
  481.44 + */
  481.45 +@Documented
  481.46 +@Retention(RetentionPolicy.RUNTIME)
  481.47 +@Target(ElementType.ANNOTATION_TYPE)
  481.48 +public @interface Retention {
  481.49 +    RetentionPolicy value();
  481.50 +}
   482.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   482.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/RetentionPolicy.java	Wed Feb 27 11:24:58 2013 +0100
   482.3 @@ -0,0 +1,57 @@
   482.4 +/*
   482.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   482.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   482.7 + *
   482.8 + * This code is free software; you can redistribute it and/or modify it
   482.9 + * under the terms of the GNU General Public License version 2 only, as
  482.10 + * published by the Free Software Foundation.  Oracle designates this
  482.11 + * particular file as subject to the "Classpath" exception as provided
  482.12 + * by Oracle in the LICENSE file that accompanied this code.
  482.13 + *
  482.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  482.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  482.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  482.17 + * version 2 for more details (a copy is included in the LICENSE file that
  482.18 + * accompanied this code).
  482.19 + *
  482.20 + * You should have received a copy of the GNU General Public License version
  482.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  482.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  482.23 + *
  482.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  482.25 + * or visit www.oracle.com if you need additional information or have any
  482.26 + * questions.
  482.27 + */
  482.28 +
  482.29 +package java.lang.annotation;
  482.30 +
  482.31 +/**
  482.32 + * Annotation retention policy.  The constants of this enumerated type
  482.33 + * describe the various policies for retaining annotations.  They are used
  482.34 + * in conjunction with the {@link Retention} meta-annotation type to specify
  482.35 + * how long annotations are to be retained.
  482.36 + *
  482.37 + * @author  Joshua Bloch
  482.38 + * @since 1.5
  482.39 + */
  482.40 +public enum RetentionPolicy {
  482.41 +    /**
  482.42 +     * Annotations are to be discarded by the compiler.
  482.43 +     */
  482.44 +    SOURCE,
  482.45 +
  482.46 +    /**
  482.47 +     * Annotations are to be recorded in the class file by the compiler
  482.48 +     * but need not be retained by the VM at run time.  This is the default
  482.49 +     * behavior.
  482.50 +     */
  482.51 +    CLASS,
  482.52 +
  482.53 +    /**
  482.54 +     * Annotations are to be recorded in the class file by the compiler and
  482.55 +     * retained by the VM at run time, so they may be read reflectively.
  482.56 +     *
  482.57 +     * @see java.lang.reflect.AnnotatedElement
  482.58 +     */
  482.59 +    RUNTIME
  482.60 +}
   483.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   483.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/Target.java	Wed Feb 27 11:24:58 2013 +0100
   483.3 @@ -0,0 +1,68 @@
   483.4 +/*
   483.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   483.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   483.7 + *
   483.8 + * This code is free software; you can redistribute it and/or modify it
   483.9 + * under the terms of the GNU General Public License version 2 only, as
  483.10 + * published by the Free Software Foundation.  Oracle designates this
  483.11 + * particular file as subject to the "Classpath" exception as provided
  483.12 + * by Oracle in the LICENSE file that accompanied this code.
  483.13 + *
  483.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  483.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  483.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  483.17 + * version 2 for more details (a copy is included in the LICENSE file that
  483.18 + * accompanied this code).
  483.19 + *
  483.20 + * You should have received a copy of the GNU General Public License version
  483.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  483.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  483.23 + *
  483.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  483.25 + * or visit www.oracle.com if you need additional information or have any
  483.26 + * questions.
  483.27 + */
  483.28 +
  483.29 +package java.lang.annotation;
  483.30 +
  483.31 +/**
  483.32 + * Indicates the kinds of program element to which an annotation type
  483.33 + * is applicable.  If a Target meta-annotation is not present on an
  483.34 + * annotation type declaration, the declared type may be used on any
  483.35 + * program element.  If such a meta-annotation is present, the compiler
  483.36 + * will enforce the specified usage restriction.
  483.37 + *
  483.38 + * For example, this meta-annotation indicates that the declared type is
  483.39 + * itself a meta-annotation type.  It can only be used on annotation type
  483.40 + * declarations:
  483.41 + * <pre>
  483.42 + *    &#064;Target(ElementType.ANNOTATION_TYPE)
  483.43 + *    public &#064;interface MetaAnnotationType {
  483.44 + *        ...
  483.45 + *    }
  483.46 + * </pre>
  483.47 + * This meta-annotation indicates that the declared type is intended solely
  483.48 + * for use as a member type in complex annotation type declarations.  It
  483.49 + * cannot be used to annotate anything directly:
  483.50 + * <pre>
  483.51 + *    &#064;Target({})
  483.52 + *    public &#064;interface MemberType {
  483.53 + *        ...
  483.54 + *    }
  483.55 + * </pre>
  483.56 + * It is a compile-time error for a single ElementType constant to
  483.57 + * appear more than once in a Target annotation.  For example, the
  483.58 + * following meta-annotation is illegal:
  483.59 + * <pre>
  483.60 + *    &#064;Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
  483.61 + *    public &#064;interface Bogus {
  483.62 + *        ...
  483.63 + *    }
  483.64 + * </pre>
  483.65 + */
  483.66 +@Documented
  483.67 +@Retention(RetentionPolicy.RUNTIME)
  483.68 +@Target(ElementType.ANNOTATION_TYPE)
  483.69 +public @interface Target {
  483.70 +    ElementType[] value();
  483.71 +}
   484.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   484.2 +++ b/rt/emul/mini/src/main/java/java/lang/annotation/UnsupportedOperationException.java	Wed Feb 27 11:24:58 2013 +0100
   484.3 @@ -0,0 +1,94 @@
   484.4 +/*
   484.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   484.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   484.7 + *
   484.8 + * This code is free software; you can redistribute it and/or modify it
   484.9 + * under the terms of the GNU General Public License version 2 only, as
  484.10 + * published by the Free Software Foundation.  Oracle designates this
  484.11 + * particular file as subject to the "Classpath" exception as provided
  484.12 + * by Oracle in the LICENSE file that accompanied this code.
  484.13 + *
  484.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  484.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  484.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  484.17 + * version 2 for more details (a copy is included in the LICENSE file that
  484.18 + * accompanied this code).
  484.19 + *
  484.20 + * You should have received a copy of the GNU General Public License version
  484.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  484.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  484.23 + *
  484.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  484.25 + * or visit www.oracle.com if you need additional information or have any
  484.26 + * questions.
  484.27 + */
  484.28 +
  484.29 +package java.lang;
  484.30 +
  484.31 +/**
  484.32 + * Thrown to indicate that the requested operation is not supported.<p>
  484.33 + *
  484.34 + * This class is a member of the
  484.35 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  484.36 + * Java Collections Framework</a>.
  484.37 + *
  484.38 + * @author  Josh Bloch
  484.39 + * @since   1.2
  484.40 + */
  484.41 +public class UnsupportedOperationException extends RuntimeException {
  484.42 +    /**
  484.43 +     * Constructs an UnsupportedOperationException with no detail message.
  484.44 +     */
  484.45 +    public UnsupportedOperationException() {
  484.46 +    }
  484.47 +
  484.48 +    /**
  484.49 +     * Constructs an UnsupportedOperationException with the specified
  484.50 +     * detail message.
  484.51 +     *
  484.52 +     * @param message the detail message
  484.53 +     */
  484.54 +    public UnsupportedOperationException(String message) {
  484.55 +        super(message);
  484.56 +    }
  484.57 +
  484.58 +    /**
  484.59 +     * Constructs a new exception with the specified detail message and
  484.60 +     * cause.
  484.61 +     *
  484.62 +     * <p>Note that the detail message associated with <code>cause</code> is
  484.63 +     * <i>not</i> automatically incorporated in this exception's detail
  484.64 +     * message.
  484.65 +     *
  484.66 +     * @param  message the detail message (which is saved for later retrieval
  484.67 +     *         by the {@link Throwable#getMessage()} method).
  484.68 +     * @param  cause the cause (which is saved for later retrieval by the
  484.69 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value
  484.70 +     *         is permitted, and indicates that the cause is nonexistent or
  484.71 +     *         unknown.)
  484.72 +     * @since 1.5
  484.73 +     */
  484.74 +    public UnsupportedOperationException(String message, Throwable cause) {
  484.75 +        super(message, cause);
  484.76 +    }
  484.77 +
  484.78 +    /**
  484.79 +     * Constructs a new exception with the specified cause and a detail
  484.80 +     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
  484.81 +     * typically contains the class and detail message of <tt>cause</tt>).
  484.82 +     * This constructor is useful for exceptions that are little more than
  484.83 +     * wrappers for other throwables (for example, {@link
  484.84 +     * java.security.PrivilegedActionException}).
  484.85 +     *
  484.86 +     * @param  cause the cause (which is saved for later retrieval by the
  484.87 +     *         {@link Throwable#getCause()} method).  (A <tt>null</tt> value is
  484.88 +     *         permitted, and indicates that the cause is nonexistent or
  484.89 +     *         unknown.)
  484.90 +     * @since  1.5
  484.91 +     */
  484.92 +    public UnsupportedOperationException(Throwable cause) {
  484.93 +        super(cause);
  484.94 +    }
  484.95 +
  484.96 +    static final long serialVersionUID = -1242599979055084673L;
  484.97 +}
   485.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   485.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/AccessibleObject.java	Wed Feb 27 11:24:58 2013 +0100
   485.3 @@ -0,0 +1,167 @@
   485.4 +/*
   485.5 + * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
   485.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   485.7 + *
   485.8 + * This code is free software; you can redistribute it and/or modify it
   485.9 + * under the terms of the GNU General Public License version 2 only, as
  485.10 + * published by the Free Software Foundation.  Oracle designates this
  485.11 + * particular file as subject to the "Classpath" exception as provided
  485.12 + * by Oracle in the LICENSE file that accompanied this code.
  485.13 + *
  485.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  485.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  485.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  485.17 + * version 2 for more details (a copy is included in the LICENSE file that
  485.18 + * accompanied this code).
  485.19 + *
  485.20 + * You should have received a copy of the GNU General Public License version
  485.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  485.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  485.23 + *
  485.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  485.25 + * or visit www.oracle.com if you need additional information or have any
  485.26 + * questions.
  485.27 + */
  485.28 +
  485.29 +package java.lang.reflect;
  485.30 +
  485.31 +import java.lang.annotation.Annotation;
  485.32 +
  485.33 +/**
  485.34 + * The AccessibleObject class is the base class for Field, Method and
  485.35 + * Constructor objects.  It provides the ability to flag a reflected
  485.36 + * object as suppressing default Java language access control checks
  485.37 + * when it is used.  The access checks--for public, default (package)
  485.38 + * access, protected, and private members--are performed when Fields,
  485.39 + * Methods or Constructors are used to set or get fields, to invoke
  485.40 + * methods, or to create and initialize new instances of classes,
  485.41 + * respectively.
  485.42 + *
  485.43 + * <p>Setting the {@code accessible} flag in a reflected object
  485.44 + * permits sophisticated applications with sufficient privilege, such
  485.45 + * as Java Object Serialization or other persistence mechanisms, to
  485.46 + * manipulate objects in a manner that would normally be prohibited.
  485.47 + *
  485.48 + * <p>By default, a reflected object is <em>not</em> accessible.
  485.49 + *
  485.50 + * @see Field
  485.51 + * @see Method
  485.52 + * @see Constructor
  485.53 + * @see ReflectPermission
  485.54 + *
  485.55 + * @since 1.2
  485.56 + */
  485.57 +public class AccessibleObject implements AnnotatedElement {
  485.58 +
  485.59 +    /**
  485.60 +     * Convenience method to set the {@code accessible} flag for an
  485.61 +     * array of objects with a single security check (for efficiency).
  485.62 +     *
  485.63 +     * <p>First, if there is a security manager, its
  485.64 +     * {@code checkPermission} method is called with a
  485.65 +     * {@code ReflectPermission("suppressAccessChecks")} permission.
  485.66 +     *
  485.67 +     * <p>A {@code SecurityException} is raised if {@code flag} is
  485.68 +     * {@code true} but accessibility of any of the elements of the input
  485.69 +     * {@code array} may not be changed (for example, if the element
  485.70 +     * object is a {@link Constructor} object for the class {@link
  485.71 +     * java.lang.Class}).  In the event of such a SecurityException, the
  485.72 +     * accessibility of objects is set to {@code flag} for array elements
  485.73 +     * upto (and excluding) the element for which the exception occurred; the
  485.74 +     * accessibility of elements beyond (and including) the element for which
  485.75 +     * the exception occurred is unchanged.
  485.76 +     *
  485.77 +     * @param array the array of AccessibleObjects
  485.78 +     * @param flag  the new value for the {@code accessible} flag
  485.79 +     *              in each object
  485.80 +     * @throws SecurityException if the request is denied.
  485.81 +     * @see SecurityManager#checkPermission
  485.82 +     * @see java.lang.RuntimePermission
  485.83 +     */
  485.84 +    public static void setAccessible(AccessibleObject[] array, boolean flag)
  485.85 +        throws SecurityException {
  485.86 +        throw new SecurityException();
  485.87 +    }
  485.88 +
  485.89 +    /**
  485.90 +     * Set the {@code accessible} flag for this object to
  485.91 +     * the indicated boolean value.  A value of {@code true} indicates that
  485.92 +     * the reflected object should suppress Java language access
  485.93 +     * checking when it is used.  A value of {@code false} indicates
  485.94 +     * that the reflected object should enforce Java language access checks.
  485.95 +     *
  485.96 +     * <p>First, if there is a security manager, its
  485.97 +     * {@code checkPermission} method is called with a
  485.98 +     * {@code ReflectPermission("suppressAccessChecks")} permission.
  485.99 +     *
 485.100 +     * <p>A {@code SecurityException} is raised if {@code flag} is
 485.101 +     * {@code true} but accessibility of this object may not be changed
 485.102 +     * (for example, if this element object is a {@link Constructor} object for
 485.103 +     * the class {@link java.lang.Class}).
 485.104 +     *
 485.105 +     * <p>A {@code SecurityException} is raised if this object is a {@link
 485.106 +     * java.lang.reflect.Constructor} object for the class
 485.107 +     * {@code java.lang.Class}, and {@code flag} is true.
 485.108 +     *
 485.109 +     * @param flag the new value for the {@code accessible} flag
 485.110 +     * @throws SecurityException if the request is denied.
 485.111 +     * @see SecurityManager#checkPermission
 485.112 +     * @see java.lang.RuntimePermission
 485.113 +     */
 485.114 +    public void setAccessible(boolean flag) throws SecurityException {
 485.115 +        throw new SecurityException();
 485.116 +    }
 485.117 +
 485.118 +    /**
 485.119 +     * Get the value of the {@code accessible} flag for this object.
 485.120 +     *
 485.121 +     * @return the value of the object's {@code accessible} flag
 485.122 +     */
 485.123 +    public boolean isAccessible() {
 485.124 +        return override;
 485.125 +    }
 485.126 +
 485.127 +    /**
 485.128 +     * Constructor: only used by the Java Virtual Machine.
 485.129 +     */
 485.130 +    protected AccessibleObject() {}
 485.131 +
 485.132 +    // Indicates whether language-level access checks are overridden
 485.133 +    // by this object. Initializes to "false". This field is used by
 485.134 +    // Field, Method, and Constructor.
 485.135 +    //
 485.136 +    // NOTE: for security purposes, this field must not be visible
 485.137 +    // outside this package.
 485.138 +    boolean override;
 485.139 +
 485.140 +    /**
 485.141 +     * @throws NullPointerException {@inheritDoc}
 485.142 +     * @since 1.5
 485.143 +     */
 485.144 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 485.145 +        throw new AssertionError("All subclasses should override this method");
 485.146 +    }
 485.147 +
 485.148 +    /**
 485.149 +     * @throws NullPointerException {@inheritDoc}
 485.150 +     * @since 1.5
 485.151 +     */
 485.152 +    public boolean isAnnotationPresent(
 485.153 +        Class<? extends Annotation> annotationClass) {
 485.154 +        return getAnnotation(annotationClass) != null;
 485.155 +    }
 485.156 +
 485.157 +    /**
 485.158 +     * @since 1.5
 485.159 +     */
 485.160 +    public Annotation[] getAnnotations() {
 485.161 +        return getDeclaredAnnotations();
 485.162 +    }
 485.163 +
 485.164 +    /**
 485.165 +     * @since 1.5
 485.166 +     */
 485.167 +    public Annotation[] getDeclaredAnnotations()  {
 485.168 +        throw new AssertionError("All subclasses should override this method");
 485.169 +    }
 485.170 +}
   486.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   486.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java	Wed Feb 27 11:24:58 2013 +0100
   486.3 @@ -0,0 +1,112 @@
   486.4 +/*
   486.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
   486.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   486.7 + *
   486.8 + * This code is free software; you can redistribute it and/or modify it
   486.9 + * under the terms of the GNU General Public License version 2 only, as
  486.10 + * published by the Free Software Foundation.  Oracle designates this
  486.11 + * particular file as subject to the "Classpath" exception as provided
  486.12 + * by Oracle in the LICENSE file that accompanied this code.
  486.13 + *
  486.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  486.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  486.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  486.17 + * version 2 for more details (a copy is included in the LICENSE file that
  486.18 + * accompanied this code).
  486.19 + *
  486.20 + * You should have received a copy of the GNU General Public License version
  486.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  486.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  486.23 + *
  486.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  486.25 + * or visit www.oracle.com if you need additional information or have any
  486.26 + * questions.
  486.27 + */
  486.28 +
  486.29 +package java.lang.reflect;
  486.30 +
  486.31 +import java.lang.annotation.Annotation;
  486.32 +
  486.33 +/**
  486.34 + * Represents an annotated element of the program currently running in this
  486.35 + * VM.  This interface allows annotations to be read reflectively.  All
  486.36 + * annotations returned by methods in this interface are immutable and
  486.37 + * serializable.  It is permissible for the caller to modify the
  486.38 + * arrays returned by accessors for array-valued enum members; it will
  486.39 + * have no affect on the arrays returned to other callers.
  486.40 + *
  486.41 + * <p>If an annotation returned by a method in this interface contains
  486.42 + * (directly or indirectly) a {@link Class}-valued member referring to
  486.43 + * a class that is not accessible in this VM, attempting to read the class
  486.44 + * by calling the relevant Class-returning method on the returned annotation
  486.45 + * will result in a {@link TypeNotPresentException}.
  486.46 + *
  486.47 + * <p>Similarly, attempting to read an enum-valued member will result in
  486.48 + * a {@link EnumConstantNotPresentException} if the enum constant in the
  486.49 + * annotation is no longer present in the enum type.
  486.50 + *
  486.51 + * <p>Finally, Attempting to read a member whose definition has evolved
  486.52 + * incompatibly will result in a {@link
  486.53 + * java.lang.annotation.AnnotationTypeMismatchException} or an
  486.54 + * {@link java.lang.annotation.IncompleteAnnotationException}.
  486.55 + *
  486.56 + * @see java.lang.EnumConstantNotPresentException
  486.57 + * @see java.lang.TypeNotPresentException
  486.58 + * @see java.lang.annotation.AnnotationFormatError
  486.59 + * @see java.lang.annotation.AnnotationTypeMismatchException
  486.60 + * @see java.lang.annotation.IncompleteAnnotationException
  486.61 + * @since 1.5
  486.62 + * @author Josh Bloch
  486.63 + */
  486.64 +public interface AnnotatedElement {
  486.65 +    /**
  486.66 +     * Returns true if an annotation for the specified type
  486.67 +     * is present on this element, else false.  This method
  486.68 +     * is designed primarily for convenient access to marker annotations.
  486.69 +     *
  486.70 +     * @param annotationClass the Class object corresponding to the
  486.71 +     *        annotation type
  486.72 +     * @return true if an annotation for the specified annotation
  486.73 +     *     type is present on this element, else false
  486.74 +     * @throws NullPointerException if the given annotation class is null
  486.75 +     * @since 1.5
  486.76 +     */
  486.77 +     boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
  486.78 +
  486.79 +   /**
  486.80 +     * Returns this element's annotation for the specified type if
  486.81 +     * such an annotation is present, else null.
  486.82 +     *
  486.83 +     * @param annotationClass the Class object corresponding to the
  486.84 +     *        annotation type
  486.85 +     * @return this element's annotation for the specified annotation type if
  486.86 +     *     present on this element, else null
  486.87 +     * @throws NullPointerException if the given annotation class is null
  486.88 +     * @since 1.5
  486.89 +     */
  486.90 +    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
  486.91 +
  486.92 +    /**
  486.93 +     * Returns all annotations present on this element.  (Returns an array
  486.94 +     * of length zero if this element has no annotations.)  The caller of
  486.95 +     * this method is free to modify the returned array; it will have no
  486.96 +     * effect on the arrays returned to other callers.
  486.97 +     *
  486.98 +     * @return all annotations present on this element
  486.99 +     * @since 1.5
 486.100 +     */
 486.101 +    Annotation[] getAnnotations();
 486.102 +
 486.103 +    /**
 486.104 +     * Returns all annotations that are directly present on this
 486.105 +     * element.  Unlike the other methods in this interface, this method
 486.106 +     * ignores inherited annotations.  (Returns an array of length zero if
 486.107 +     * no annotations are directly present on this element.)  The caller of
 486.108 +     * this method is free to modify the returned array; it will have no
 486.109 +     * effect on the arrays returned to other callers.
 486.110 +     *
 486.111 +     * @return All annotations directly present on this element
 486.112 +     * @since 1.5
 486.113 +     */
 486.114 +    Annotation[] getDeclaredAnnotations();
 486.115 +}
   487.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   487.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Array.java	Wed Feb 27 11:24:58 2013 +0100
   487.3 @@ -0,0 +1,663 @@
   487.4 +/*
   487.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   487.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   487.7 + *
   487.8 + * This code is free software; you can redistribute it and/or modify it
   487.9 + * under the terms of the GNU General Public License version 2 only, as
  487.10 + * published by the Free Software Foundation.  Oracle designates this
  487.11 + * particular file as subject to the "Classpath" exception as provided
  487.12 + * by Oracle in the LICENSE file that accompanied this code.
  487.13 + *
  487.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  487.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  487.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  487.17 + * version 2 for more details (a copy is included in the LICENSE file that
  487.18 + * accompanied this code).
  487.19 + *
  487.20 + * You should have received a copy of the GNU General Public License version
  487.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  487.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  487.23 + *
  487.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  487.25 + * or visit www.oracle.com if you need additional information or have any
  487.26 + * questions.
  487.27 + */
  487.28 +
  487.29 +package java.lang.reflect;
  487.30 +
  487.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  487.32 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  487.33 +
  487.34 +/**
  487.35 + * The {@code Array} class provides static methods to dynamically create and
  487.36 + * access Java arrays.
  487.37 + *
  487.38 + * <p>{@code Array} permits widening conversions to occur during a get or set
  487.39 + * operation, but throws an {@code IllegalArgumentException} if a narrowing
  487.40 + * conversion would occur.
  487.41 + *
  487.42 + * @author Nakul Saraiya
  487.43 + */
  487.44 +@JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
  487.45 +public final
  487.46 +class Array {
  487.47 +
  487.48 +    /**
  487.49 +     * Constructor.  Class Array is not instantiable.
  487.50 +     */
  487.51 +    private Array() {}
  487.52 +
  487.53 +    /**
  487.54 +     * Creates a new array with the specified component type and
  487.55 +     * length.
  487.56 +     * Invoking this method is equivalent to creating an array
  487.57 +     * as follows:
  487.58 +     * <blockquote>
  487.59 +     * <pre>
  487.60 +     * int[] x = {length};
  487.61 +     * Array.newInstance(componentType, x);
  487.62 +     * </pre>
  487.63 +     * </blockquote>
  487.64 +     *
  487.65 +     * @param componentType the {@code Class} object representing the
  487.66 +     * component type of the new array
  487.67 +     * @param length the length of the new array
  487.68 +     * @return the new array
  487.69 +     * @exception NullPointerException if the specified
  487.70 +     * {@code componentType} parameter is null
  487.71 +     * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
  487.72 +     * @exception NegativeArraySizeException if the specified {@code length}
  487.73 +     * is negative
  487.74 +     */
  487.75 +    public static Object newInstance(Class<?> componentType, int length)
  487.76 +    throws NegativeArraySizeException {
  487.77 +        if (length < 0) {
  487.78 +            throw new NegativeArraySizeException();
  487.79 +        }
  487.80 +        String sig = findSignature(componentType);
  487.81 +        return newArray(componentType.isPrimitive(), sig, length);
  487.82 +    }
  487.83 +    
  487.84 +    private static String findSignature(Class<?> type) {
  487.85 +        if (type == Integer.TYPE) {
  487.86 +            return "[I";
  487.87 +        }
  487.88 +        if (type == Long.TYPE) {
  487.89 +            return "[J";
  487.90 +        }
  487.91 +        if (type == Double.TYPE) {
  487.92 +            return "[D";
  487.93 +        }
  487.94 +        if (type == Float.TYPE) {
  487.95 +            return "[F";
  487.96 +        }
  487.97 +        if (type == Byte.TYPE) {
  487.98 +            return "[B";
  487.99 +        }
 487.100 +        if (type == Boolean.TYPE) {
 487.101 +            return "[Z";
 487.102 +        }
 487.103 +        if (type == Short.TYPE) {
 487.104 +            return "[S";
 487.105 +        }
 487.106 +        if (type == Character.TYPE) {
 487.107 +            return "[C";
 487.108 +        }
 487.109 +        if (type.getName().equals("void")) {
 487.110 +            throw new IllegalStateException("Can't create array for " + type);
 487.111 +        }
 487.112 +        return "[L" + type.getName() + ";";
 487.113 +    }
 487.114 +    /**
 487.115 +     * Creates a new array
 487.116 +     * with the specified component type and dimensions.
 487.117 +     * If {@code componentType}
 487.118 +     * represents a non-array class or interface, the new array
 487.119 +     * has {@code dimensions.length} dimensions and
 487.120 +     * {@code componentType} as its component type. If
 487.121 +     * {@code componentType} represents an array class, the
 487.122 +     * number of dimensions of the new array is equal to the sum
 487.123 +     * of {@code dimensions.length} and the number of
 487.124 +     * dimensions of {@code componentType}. In this case, the
 487.125 +     * component type of the new array is the component type of
 487.126 +     * {@code componentType}.
 487.127 +     *
 487.128 +     * <p>The number of dimensions of the new array must not
 487.129 +     * exceed the number of array dimensions supported by the
 487.130 +     * implementation (typically 255).
 487.131 +     *
 487.132 +     * @param componentType the {@code Class} object representing the component
 487.133 +     * type of the new array
 487.134 +     * @param dimensions an array of {@code int} representing the dimensions of
 487.135 +     * the new array
 487.136 +     * @return the new array
 487.137 +     * @exception NullPointerException if the specified
 487.138 +     * {@code componentType} argument is null
 487.139 +     * @exception IllegalArgumentException if the specified {@code dimensions}
 487.140 +     * argument is a zero-dimensional array, or if the number of
 487.141 +     * requested dimensions exceeds the limit on the number of array dimensions
 487.142 +     * supported by the implementation (typically 255), or if componentType
 487.143 +     * is {@link Void#TYPE}.
 487.144 +     * @exception NegativeArraySizeException if any of the components in
 487.145 +     * the specified {@code dimensions} argument is negative.
 487.146 +     */
 487.147 +    public static Object newInstance(Class<?> componentType, int... dimensions)
 487.148 +        throws IllegalArgumentException, NegativeArraySizeException {
 487.149 +        StringBuilder sig = new StringBuilder();
 487.150 +        for (int i = 1; i < dimensions.length; i++) {
 487.151 +            sig.append('[');
 487.152 +        }
 487.153 +        sig.append(findSignature(componentType));
 487.154 +        return multiNewArray(sig.toString(), dimensions, 0);
 487.155 +    }
 487.156 +
 487.157 +    /**
 487.158 +     * Returns the length of the specified array object, as an {@code int}.
 487.159 +     *
 487.160 +     * @param array the array
 487.161 +     * @return the length of the array
 487.162 +     * @exception IllegalArgumentException if the object argument is not
 487.163 +     * an array
 487.164 +     */
 487.165 +    public static int getLength(Object array)
 487.166 +    throws IllegalArgumentException {
 487.167 +        if (!array.getClass().isArray()) {
 487.168 +            throw new IllegalArgumentException("Argument is not an array");
 487.169 +        }
 487.170 +        return length(array);
 487.171 +    }
 487.172 +    
 487.173 +    @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
 487.174 +    private static native int length(Object arr);
 487.175 +
 487.176 +    /**
 487.177 +     * Returns the value of the indexed component in the specified
 487.178 +     * array object.  The value is automatically wrapped in an object
 487.179 +     * if it has a primitive type.
 487.180 +     *
 487.181 +     * @param array the array
 487.182 +     * @param index the index
 487.183 +     * @return the (possibly wrapped) value of the indexed component in
 487.184 +     * the specified array
 487.185 +     * @exception NullPointerException If the specified object is null
 487.186 +     * @exception IllegalArgumentException If the specified object is not
 487.187 +     * an array
 487.188 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.189 +     * argument is negative, or if it is greater than or equal to the
 487.190 +     * length of the specified array
 487.191 +     */
 487.192 +    public static Object get(Object array, int index)
 487.193 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.194 +        final Class<?> t = array.getClass().getComponentType();
 487.195 +        if (t.isPrimitive()) {
 487.196 +            return fromPrimitive(t, array, index);
 487.197 +        } else {
 487.198 +            return ((Object[])array)[index];
 487.199 +        }
 487.200 +    }
 487.201 +
 487.202 +    /**
 487.203 +     * Returns the value of the indexed component in the specified
 487.204 +     * array object, as a {@code boolean}.
 487.205 +     *
 487.206 +     * @param array the array
 487.207 +     * @param index the index
 487.208 +     * @return the value of the indexed component in the specified array
 487.209 +     * @exception NullPointerException If the specified object is null
 487.210 +     * @exception IllegalArgumentException If the specified object is not
 487.211 +     * an array, or if the indexed element cannot be converted to the
 487.212 +     * return type by an identity or widening conversion
 487.213 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.214 +     * argument is negative, or if it is greater than or equal to the
 487.215 +     * length of the specified array
 487.216 +     * @see Array#get
 487.217 +     */
 487.218 +    public static native boolean getBoolean(Object array, int index)
 487.219 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 487.220 +
 487.221 +    /**
 487.222 +     * Returns the value of the indexed component in the specified
 487.223 +     * array object, as a {@code byte}.
 487.224 +     *
 487.225 +     * @param array the array
 487.226 +     * @param index the index
 487.227 +     * @return the value of the indexed component in the specified array
 487.228 +     * @exception NullPointerException If the specified object is null
 487.229 +     * @exception IllegalArgumentException If the specified object is not
 487.230 +     * an array, or if the indexed element cannot be converted to the
 487.231 +     * return type by an identity or widening conversion
 487.232 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.233 +     * argument is negative, or if it is greater than or equal to the
 487.234 +     * length of the specified array
 487.235 +     * @see Array#get
 487.236 +     */
 487.237 +    public static byte getByte(Object array, int index)
 487.238 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.239 +        if (array.getClass().getComponentType() != Byte.TYPE) {
 487.240 +            throw new IllegalArgumentException();
 487.241 +        }
 487.242 +        byte[] arr = (byte[]) array;
 487.243 +        return arr[index];
 487.244 +    }
 487.245 +
 487.246 +    /**
 487.247 +     * Returns the value of the indexed component in the specified
 487.248 +     * array object, as a {@code char}.
 487.249 +     *
 487.250 +     * @param array the array
 487.251 +     * @param index the index
 487.252 +     * @return the value of the indexed component in the specified array
 487.253 +     * @exception NullPointerException If the specified object is null
 487.254 +     * @exception IllegalArgumentException If the specified object is not
 487.255 +     * an array, or if the indexed element cannot be converted to the
 487.256 +     * return type by an identity or widening conversion
 487.257 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.258 +     * argument is negative, or if it is greater than or equal to the
 487.259 +     * length of the specified array
 487.260 +     * @see Array#get
 487.261 +     */
 487.262 +    public static native char getChar(Object array, int index)
 487.263 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 487.264 +
 487.265 +    /**
 487.266 +     * Returns the value of the indexed component in the specified
 487.267 +     * array object, as a {@code short}.
 487.268 +     *
 487.269 +     * @param array the array
 487.270 +     * @param index the index
 487.271 +     * @return the value of the indexed component in the specified array
 487.272 +     * @exception NullPointerException If the specified object is null
 487.273 +     * @exception IllegalArgumentException If the specified object is not
 487.274 +     * an array, or if the indexed element cannot be converted to the
 487.275 +     * return type by an identity or widening conversion
 487.276 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.277 +     * argument is negative, or if it is greater than or equal to the
 487.278 +     * length of the specified array
 487.279 +     * @see Array#get
 487.280 +     */
 487.281 +    public static short getShort(Object array, int index)
 487.282 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.283 +        final Class<?> t = array.getClass().getComponentType();
 487.284 +        if (t == Short.TYPE) {
 487.285 +            short[] arr = (short[]) array;
 487.286 +            return arr[index];
 487.287 +        }
 487.288 +        return getByte(array, index);
 487.289 +    }
 487.290 +
 487.291 +    /**
 487.292 +     * Returns the value of the indexed component in the specified
 487.293 +     * array object, as an {@code int}.
 487.294 +     *
 487.295 +     * @param array the array
 487.296 +     * @param index the index
 487.297 +     * @return the value of the indexed component in the specified array
 487.298 +     * @exception NullPointerException If the specified object is null
 487.299 +     * @exception IllegalArgumentException If the specified object is not
 487.300 +     * an array, or if the indexed element cannot be converted to the
 487.301 +     * return type by an identity or widening conversion
 487.302 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.303 +     * argument is negative, or if it is greater than or equal to the
 487.304 +     * length of the specified array
 487.305 +     * @see Array#get
 487.306 +     */
 487.307 +    public static int getInt(Object array, int index) 
 487.308 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.309 +        final Class<?> t = array.getClass().getComponentType();
 487.310 +        if (t == Integer.TYPE) {
 487.311 +            int[] arr = (int[]) array;
 487.312 +            return arr[index];
 487.313 +        }
 487.314 +        return getShort(array, index);
 487.315 +    }
 487.316 +
 487.317 +    /**
 487.318 +     * Returns the value of the indexed component in the specified
 487.319 +     * array object, as a {@code long}.
 487.320 +     *
 487.321 +     * @param array the array
 487.322 +     * @param index the index
 487.323 +     * @return the value of the indexed component in the specified array
 487.324 +     * @exception NullPointerException If the specified object is null
 487.325 +     * @exception IllegalArgumentException If the specified object is not
 487.326 +     * an array, or if the indexed element cannot be converted to the
 487.327 +     * return type by an identity or widening conversion
 487.328 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.329 +     * argument is negative, or if it is greater than or equal to the
 487.330 +     * length of the specified array
 487.331 +     * @see Array#get
 487.332 +     */
 487.333 +    public static long getLong(Object array, int index)
 487.334 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.335 +        final Class<?> t = array.getClass().getComponentType();
 487.336 +        if (t == Long.TYPE) {
 487.337 +            long[] arr = (long[]) array;
 487.338 +            return arr[index];
 487.339 +        }
 487.340 +        return getInt(array, index);
 487.341 +    }
 487.342 +
 487.343 +    /**
 487.344 +     * Returns the value of the indexed component in the specified
 487.345 +     * array object, as a {@code float}.
 487.346 +     *
 487.347 +     * @param array the array
 487.348 +     * @param index the index
 487.349 +     * @return the value of the indexed component in the specified array
 487.350 +     * @exception NullPointerException If the specified object is null
 487.351 +     * @exception IllegalArgumentException If the specified object is not
 487.352 +     * an array, or if the indexed element cannot be converted to the
 487.353 +     * return type by an identity or widening conversion
 487.354 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.355 +     * argument is negative, or if it is greater than or equal to the
 487.356 +     * length of the specified array
 487.357 +     * @see Array#get
 487.358 +     */
 487.359 +    public static float getFloat(Object array, int index)
 487.360 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.361 +        final Class<?> t = array.getClass().getComponentType();
 487.362 +        if (t == Float.TYPE) {
 487.363 +            float[] arr = (float[]) array;
 487.364 +            return arr[index];
 487.365 +        }
 487.366 +        return getLong(array, index);
 487.367 +    }
 487.368 +
 487.369 +    /**
 487.370 +     * Returns the value of the indexed component in the specified
 487.371 +     * array object, as a {@code double}.
 487.372 +     *
 487.373 +     * @param array the array
 487.374 +     * @param index the index
 487.375 +     * @return the value of the indexed component in the specified array
 487.376 +     * @exception NullPointerException If the specified object is null
 487.377 +     * @exception IllegalArgumentException If the specified object is not
 487.378 +     * an array, or if the indexed element cannot be converted to the
 487.379 +     * return type by an identity or widening conversion
 487.380 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.381 +     * argument is negative, or if it is greater than or equal to the
 487.382 +     * length of the specified array
 487.383 +     * @see Array#get
 487.384 +     */
 487.385 +    public static double getDouble(Object array, int index)
 487.386 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.387 +        final Class<?> t = array.getClass().getComponentType();
 487.388 +        if (t == Double.TYPE) {
 487.389 +            double[] arr = (double[]) array;
 487.390 +            return arr[index];
 487.391 +        }
 487.392 +        return getFloat(array, index);
 487.393 +    }
 487.394 +
 487.395 +    /**
 487.396 +     * Sets the value of the indexed component of the specified array
 487.397 +     * object to the specified new value.  The new value is first
 487.398 +     * automatically unwrapped if the array has a primitive component
 487.399 +     * type.
 487.400 +     * @param array the array
 487.401 +     * @param index the index into the array
 487.402 +     * @param value the new value of the indexed component
 487.403 +     * @exception NullPointerException If the specified object argument
 487.404 +     * is null
 487.405 +     * @exception IllegalArgumentException If the specified object argument
 487.406 +     * is not an array, or if the array component type is primitive and
 487.407 +     * an unwrapping conversion fails
 487.408 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.409 +     * argument is negative, or if it is greater than or equal to
 487.410 +     * the length of the specified array
 487.411 +     */
 487.412 +    public static void set(Object array, int index, Object value)
 487.413 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.414 +        if (array.getClass().getComponentType().isPrimitive()) {
 487.415 +            throw new IllegalArgumentException();
 487.416 +        } else {
 487.417 +            Object[] arr = (Object[])array;
 487.418 +            arr[index] = value;
 487.419 +        }
 487.420 +    }
 487.421 +
 487.422 +    /**
 487.423 +     * Sets the value of the indexed component of the specified array
 487.424 +     * object to the specified {@code boolean} value.
 487.425 +     * @param array the array
 487.426 +     * @param index the index into the array
 487.427 +     * @param z the new value of the indexed component
 487.428 +     * @exception NullPointerException If the specified object argument
 487.429 +     * is null
 487.430 +     * @exception IllegalArgumentException If the specified object argument
 487.431 +     * is not an array, or if the specified value cannot be converted
 487.432 +     * to the underlying array's component type by an identity or a
 487.433 +     * primitive widening conversion
 487.434 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.435 +     * argument is negative, or if it is greater than or equal to
 487.436 +     * the length of the specified array
 487.437 +     * @see Array#set
 487.438 +     */
 487.439 +    public static native void setBoolean(Object array, int index, boolean z)
 487.440 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 487.441 +
 487.442 +    /**
 487.443 +     * Sets the value of the indexed component of the specified array
 487.444 +     * object to the specified {@code byte} value.
 487.445 +     * @param array the array
 487.446 +     * @param index the index into the array
 487.447 +     * @param b the new value of the indexed component
 487.448 +     * @exception NullPointerException If the specified object argument
 487.449 +     * is null
 487.450 +     * @exception IllegalArgumentException If the specified object argument
 487.451 +     * is not an array, or if the specified value cannot be converted
 487.452 +     * to the underlying array's component type by an identity or a
 487.453 +     * primitive widening conversion
 487.454 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.455 +     * argument is negative, or if it is greater than or equal to
 487.456 +     * the length of the specified array
 487.457 +     * @see Array#set
 487.458 +     */
 487.459 +    public static void setByte(Object array, int index, byte b)
 487.460 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.461 +        Class<?> t = array.getClass().getComponentType();
 487.462 +        if (t == Byte.TYPE) {
 487.463 +            byte[] arr = (byte[]) array;
 487.464 +            arr[index] = b;
 487.465 +        } else {
 487.466 +            setShort(array, index, b);
 487.467 +        }
 487.468 +    }
 487.469 +
 487.470 +    /**
 487.471 +     * Sets the value of the indexed component of the specified array
 487.472 +     * object to the specified {@code char} value.
 487.473 +     * @param array the array
 487.474 +     * @param index the index into the array
 487.475 +     * @param c the new value of the indexed component
 487.476 +     * @exception NullPointerException If the specified object argument
 487.477 +     * is null
 487.478 +     * @exception IllegalArgumentException If the specified object argument
 487.479 +     * is not an array, or if the specified value cannot be converted
 487.480 +     * to the underlying array's component type by an identity or a
 487.481 +     * primitive widening conversion
 487.482 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.483 +     * argument is negative, or if it is greater than or equal to
 487.484 +     * the length of the specified array
 487.485 +     * @see Array#set
 487.486 +     */
 487.487 +    public static native void setChar(Object array, int index, char c)
 487.488 +        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
 487.489 +
 487.490 +    /**
 487.491 +     * Sets the value of the indexed component of the specified array
 487.492 +     * object to the specified {@code short} value.
 487.493 +     * @param array the array
 487.494 +     * @param index the index into the array
 487.495 +     * @param s the new value of the indexed component
 487.496 +     * @exception NullPointerException If the specified object argument
 487.497 +     * is null
 487.498 +     * @exception IllegalArgumentException If the specified object argument
 487.499 +     * is not an array, or if the specified value cannot be converted
 487.500 +     * to the underlying array's component type by an identity or a
 487.501 +     * primitive widening conversion
 487.502 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.503 +     * argument is negative, or if it is greater than or equal to
 487.504 +     * the length of the specified array
 487.505 +     * @see Array#set
 487.506 +     */
 487.507 +    public static void setShort(Object array, int index, short s)
 487.508 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.509 +        Class<?> t = array.getClass().getComponentType();
 487.510 +        if (t == Short.TYPE) {
 487.511 +            short[] arr = (short[]) array;
 487.512 +            arr[index] = s;
 487.513 +        } else {
 487.514 +            setInt(array, index, s);
 487.515 +        }
 487.516 +        
 487.517 +    }
 487.518 +    
 487.519 +    /**
 487.520 +     * Sets the value of the indexed component of the specified array
 487.521 +     * object to the specified {@code int} value.
 487.522 +     * @param array the array
 487.523 +     * @param index the index into the array
 487.524 +     * @param i the new value of the indexed component
 487.525 +     * @exception NullPointerException If the specified object argument
 487.526 +     * is null
 487.527 +     * @exception IllegalArgumentException If the specified object argument
 487.528 +     * is not an array, or if the specified value cannot be converted
 487.529 +     * to the underlying array's component type by an identity or a
 487.530 +     * primitive widening conversion
 487.531 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.532 +     * argument is negative, or if it is greater than or equal to
 487.533 +     * the length of the specified array
 487.534 +     * @see Array#set
 487.535 +     */
 487.536 +    public static void setInt(Object array, int index, int i)
 487.537 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.538 +        Class<?> t = array.getClass().getComponentType();
 487.539 +        if (t == Integer.TYPE) {
 487.540 +            int[] arr = (int[]) array;
 487.541 +            arr[index] = i;
 487.542 +        } else {
 487.543 +            setLong(array, index, i);
 487.544 +        }
 487.545 +    }
 487.546 +
 487.547 +    /**
 487.548 +     * Sets the value of the indexed component of the specified array
 487.549 +     * object to the specified {@code long} value.
 487.550 +     * @param array the array
 487.551 +     * @param index the index into the array
 487.552 +     * @param l the new value of the indexed component
 487.553 +     * @exception NullPointerException If the specified object argument
 487.554 +     * is null
 487.555 +     * @exception IllegalArgumentException If the specified object argument
 487.556 +     * is not an array, or if the specified value cannot be converted
 487.557 +     * to the underlying array's component type by an identity or a
 487.558 +     * primitive widening conversion
 487.559 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.560 +     * argument is negative, or if it is greater than or equal to
 487.561 +     * the length of the specified array
 487.562 +     * @see Array#set
 487.563 +     */
 487.564 +    public static void setLong(Object array, int index, long l)
 487.565 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.566 +        Class<?> t = array.getClass().getComponentType();
 487.567 +        if (t == Long.TYPE) {
 487.568 +            long[] arr = (long[]) array;
 487.569 +            arr[index] = l;
 487.570 +        } else {
 487.571 +            setFloat(array, index, l);
 487.572 +        }
 487.573 +    }
 487.574 +
 487.575 +    /**
 487.576 +     * Sets the value of the indexed component of the specified array
 487.577 +     * object to the specified {@code float} value.
 487.578 +     * @param array the array
 487.579 +     * @param index the index into the array
 487.580 +     * @param f the new value of the indexed component
 487.581 +     * @exception NullPointerException If the specified object argument
 487.582 +     * is null
 487.583 +     * @exception IllegalArgumentException If the specified object argument
 487.584 +     * is not an array, or if the specified value cannot be converted
 487.585 +     * to the underlying array's component type by an identity or a
 487.586 +     * primitive widening conversion
 487.587 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.588 +     * argument is negative, or if it is greater than or equal to
 487.589 +     * the length of the specified array
 487.590 +     * @see Array#set
 487.591 +     */
 487.592 +    public static void setFloat(Object array, int index, float f)
 487.593 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.594 +        Class<?> t = array.getClass().getComponentType();
 487.595 +        if (t == Float.TYPE) {
 487.596 +            float[] arr = (float[])array;
 487.597 +            arr[index] = f;
 487.598 +        } else {
 487.599 +            setDouble(array, index, f);
 487.600 +        }
 487.601 +    }
 487.602 +
 487.603 +    /**
 487.604 +     * Sets the value of the indexed component of the specified array
 487.605 +     * object to the specified {@code double} value.
 487.606 +     * @param array the array
 487.607 +     * @param index the index into the array
 487.608 +     * @param d the new value of the indexed component
 487.609 +     * @exception NullPointerException If the specified object argument
 487.610 +     * is null
 487.611 +     * @exception IllegalArgumentException If the specified object argument
 487.612 +     * is not an array, or if the specified value cannot be converted
 487.613 +     * to the underlying array's component type by an identity or a
 487.614 +     * primitive widening conversion
 487.615 +     * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
 487.616 +     * argument is negative, or if it is greater than or equal to
 487.617 +     * the length of the specified array
 487.618 +     * @see Array#set
 487.619 +     */
 487.620 +    public static void setDouble(Object array, int index, double d)
 487.621 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
 487.622 +        Class<?> t = array.getClass().getComponentType();
 487.623 +        if (t == Double.TYPE) {
 487.624 +            double[] arr = (double[])array;
 487.625 +            arr[index] = d;
 487.626 +        } else {
 487.627 +            throw new IllegalArgumentException("argument type mismatch");
 487.628 +        }
 487.629 +    }
 487.630 +
 487.631 +    /*
 487.632 +     * Private
 487.633 +     */
 487.634 +
 487.635 +    @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
 487.636 +          "var arr = new Array(length);\n"
 487.637 +        + "var value = primitive ? 0 : null;\n"
 487.638 +        + "for(var i = 0; i < length; i++) arr[i] = value;\n"
 487.639 +        + "arr.jvmName = sig;\n"
 487.640 +        + "return arr;"
 487.641 +    )
 487.642 +    private static native Object newArray(boolean primitive, String sig, int length);
 487.643 +
 487.644 +    private static Object multiNewArray(String sig, int[] dims, int index)
 487.645 +    throws IllegalArgumentException, NegativeArraySizeException {
 487.646 +        if (dims.length == index + 1) {
 487.647 +            return newArray(sig.length() == 2, sig, dims[index]);
 487.648 +        }
 487.649 +        Object arr = newArray(false, sig, dims[index]);
 487.650 +        String compsig = sig.substring(1);
 487.651 +        int len = getLength(arr);
 487.652 +        for (int i = 0; i < len; i++) {
 487.653 +            setArray(arr, i, multiNewArray(compsig, dims, index + 1));
 487.654 +        }
 487.655 +        return arr;
 487.656 +    }
 487.657 +    private static Object fromPrimitive(Class<?> t, Object array, int index) {
 487.658 +        return Method.fromPrimitive(t, atArray(array, index));
 487.659 +    }
 487.660 +    
 487.661 +    @JavaScriptBody(args = { "array", "index" }, body = "return array[index];")
 487.662 +    private static native Object atArray(Object array, int index);
 487.663 +
 487.664 +    @JavaScriptBody(args = { "array", "index", "v" }, body = "array[index] = v;")
 487.665 +    private static native Object setArray(Object array, int index, Object v);
 487.666 +}
   488.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   488.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Constructor.java	Wed Feb 27 11:24:58 2013 +0100
   488.3 @@ -0,0 +1,567 @@
   488.4 +/*
   488.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
   488.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   488.7 + *
   488.8 + * This code is free software; you can redistribute it and/or modify it
   488.9 + * under the terms of the GNU General Public License version 2 only, as
  488.10 + * published by the Free Software Foundation.  Oracle designates this
  488.11 + * particular file as subject to the "Classpath" exception as provided
  488.12 + * by Oracle in the LICENSE file that accompanied this code.
  488.13 + *
  488.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  488.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  488.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  488.17 + * version 2 for more details (a copy is included in the LICENSE file that
  488.18 + * accompanied this code).
  488.19 + *
  488.20 + * You should have received a copy of the GNU General Public License version
  488.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  488.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  488.23 + *
  488.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  488.25 + * or visit www.oracle.com if you need additional information or have any
  488.26 + * questions.
  488.27 + */
  488.28 +
  488.29 +package java.lang.reflect;
  488.30 +
  488.31 +import java.lang.annotation.Annotation;
  488.32 +import org.apidesign.bck2brwsr.emul.reflect.TypeProvider;
  488.33 +
  488.34 +/**
  488.35 + * {@code Constructor} provides information about, and access to, a single
  488.36 + * constructor for a class.
  488.37 + *
  488.38 + * <p>{@code Constructor} permits widening conversions to occur when matching the
  488.39 + * actual parameters to newInstance() with the underlying
  488.40 + * constructor's formal parameters, but throws an
  488.41 + * {@code IllegalArgumentException} if a narrowing conversion would occur.
  488.42 + *
  488.43 + * @param <T> the class in which the constructor is declared
  488.44 + *
  488.45 + * @see Member
  488.46 + * @see java.lang.Class
  488.47 + * @see java.lang.Class#getConstructors()
  488.48 + * @see java.lang.Class#getConstructor(Class[])
  488.49 + * @see java.lang.Class#getDeclaredConstructors()
  488.50 + *
  488.51 + * @author      Kenneth Russell
  488.52 + * @author      Nakul Saraiya
  488.53 + */
  488.54 +public final
  488.55 +    class Constructor<T> extends AccessibleObject implements
  488.56 +                                                    GenericDeclaration,
  488.57 +                                                    Member {
  488.58 +
  488.59 +    private Class<T>            clazz;
  488.60 +    private int                 slot;
  488.61 +    private Class<?>[]          parameterTypes;
  488.62 +    private Class<?>[]          exceptionTypes;
  488.63 +    private int                 modifiers;
  488.64 +    // Generics and annotations support
  488.65 +    private transient String    signature;
  488.66 +    private byte[]              annotations;
  488.67 +    private byte[]              parameterAnnotations;
  488.68 +
  488.69 +
  488.70 +    // For sharing of ConstructorAccessors. This branching structure
  488.71 +    // is currently only two levels deep (i.e., one root Constructor
  488.72 +    // and potentially many Constructor objects pointing to it.)
  488.73 +    private Constructor<T>      root;
  488.74 +
  488.75 +    /**
  488.76 +     * Package-private constructor used by ReflectAccess to enable
  488.77 +     * instantiation of these objects in Java code from the java.lang
  488.78 +     * package via sun.reflect.LangReflectAccess.
  488.79 +     */
  488.80 +    Constructor(Class<T> declaringClass,
  488.81 +                Class<?>[] parameterTypes,
  488.82 +                Class<?>[] checkedExceptions,
  488.83 +                int modifiers,
  488.84 +                int slot,
  488.85 +                String signature,
  488.86 +                byte[] annotations,
  488.87 +                byte[] parameterAnnotations)
  488.88 +    {
  488.89 +        this.clazz = declaringClass;
  488.90 +        this.parameterTypes = parameterTypes;
  488.91 +        this.exceptionTypes = checkedExceptions;
  488.92 +        this.modifiers = modifiers;
  488.93 +        this.slot = slot;
  488.94 +        this.signature = signature;
  488.95 +        this.annotations = annotations;
  488.96 +        this.parameterAnnotations = parameterAnnotations;
  488.97 +    }
  488.98 +
  488.99 +    /**
 488.100 +     * Package-private routine (exposed to java.lang.Class via
 488.101 +     * ReflectAccess) which returns a copy of this Constructor. The copy's
 488.102 +     * "root" field points to this Constructor.
 488.103 +     */
 488.104 +    Constructor<T> copy() {
 488.105 +        return this;
 488.106 +    }
 488.107 +
 488.108 +    /**
 488.109 +     * Returns the {@code Class} object representing the class that declares
 488.110 +     * the constructor represented by this {@code Constructor} object.
 488.111 +     */
 488.112 +    public Class<T> getDeclaringClass() {
 488.113 +        return clazz;
 488.114 +    }
 488.115 +
 488.116 +    /**
 488.117 +     * Returns the name of this constructor, as a string.  This is
 488.118 +     * the binary name of the constructor's declaring class.
 488.119 +     */
 488.120 +    public String getName() {
 488.121 +        return getDeclaringClass().getName();
 488.122 +    }
 488.123 +
 488.124 +    /**
 488.125 +     * Returns the Java language modifiers for the constructor
 488.126 +     * represented by this {@code Constructor} object, as an integer. The
 488.127 +     * {@code Modifier} class should be used to decode the modifiers.
 488.128 +     *
 488.129 +     * @see Modifier
 488.130 +     */
 488.131 +    public int getModifiers() {
 488.132 +        return modifiers;
 488.133 +    }
 488.134 +
 488.135 +    /**
 488.136 +     * Returns an array of {@code TypeVariable} objects that represent the
 488.137 +     * type variables declared by the generic declaration represented by this
 488.138 +     * {@code GenericDeclaration} object, in declaration order.  Returns an
 488.139 +     * array of length 0 if the underlying generic declaration declares no type
 488.140 +     * variables.
 488.141 +     *
 488.142 +     * @return an array of {@code TypeVariable} objects that represent
 488.143 +     *     the type variables declared by this generic declaration
 488.144 +     * @throws GenericSignatureFormatError if the generic
 488.145 +     *     signature of this generic declaration does not conform to
 488.146 +     *     the format specified in
 488.147 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 488.148 +     * @since 1.5
 488.149 +     */
 488.150 +    public TypeVariable<Constructor<T>>[] getTypeParameters() {
 488.151 +        return TypeProvider.getDefault().getTypeParameters(this);
 488.152 +    }
 488.153 +
 488.154 +
 488.155 +    /**
 488.156 +     * Returns an array of {@code Class} objects that represent the formal
 488.157 +     * parameter types, in declaration order, of the constructor
 488.158 +     * represented by this {@code Constructor} object.  Returns an array of
 488.159 +     * length 0 if the underlying constructor takes no parameters.
 488.160 +     *
 488.161 +     * @return the parameter types for the constructor this object
 488.162 +     * represents
 488.163 +     */
 488.164 +    public Class<?>[] getParameterTypes() {
 488.165 +        return (Class<?>[]) parameterTypes.clone();
 488.166 +    }
 488.167 +
 488.168 +
 488.169 +    /**
 488.170 +     * Returns an array of {@code Type} objects that represent the formal
 488.171 +     * parameter types, in declaration order, of the method represented by
 488.172 +     * this {@code Constructor} object. Returns an array of length 0 if the
 488.173 +     * underlying method takes no parameters.
 488.174 +     *
 488.175 +     * <p>If a formal parameter type is a parameterized type,
 488.176 +     * the {@code Type} object returned for it must accurately reflect
 488.177 +     * the actual type parameters used in the source code.
 488.178 +     *
 488.179 +     * <p>If a formal parameter type is a type variable or a parameterized
 488.180 +     * type, it is created. Otherwise, it is resolved.
 488.181 +     *
 488.182 +     * @return an array of {@code Type}s that represent the formal
 488.183 +     *     parameter types of the underlying method, in declaration order
 488.184 +     * @throws GenericSignatureFormatError
 488.185 +     *     if the generic method signature does not conform to the format
 488.186 +     *     specified in
 488.187 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 488.188 +     * @throws TypeNotPresentException if any of the parameter
 488.189 +     *     types of the underlying method refers to a non-existent type
 488.190 +     *     declaration
 488.191 +     * @throws MalformedParameterizedTypeException if any of
 488.192 +     *     the underlying method's parameter types refer to a parameterized
 488.193 +     *     type that cannot be instantiated for any reason
 488.194 +     * @since 1.5
 488.195 +     */
 488.196 +    public Type[] getGenericParameterTypes() {
 488.197 +        return TypeProvider.getDefault().getGenericParameterTypes(this);
 488.198 +    }
 488.199 +
 488.200 +
 488.201 +    /**
 488.202 +     * Returns an array of {@code Class} objects that represent the types
 488.203 +     * of exceptions declared to be thrown by the underlying constructor
 488.204 +     * represented by this {@code Constructor} object.  Returns an array of
 488.205 +     * length 0 if the constructor declares no exceptions in its {@code throws} clause.
 488.206 +     *
 488.207 +     * @return the exception types declared as being thrown by the
 488.208 +     * constructor this object represents
 488.209 +     */
 488.210 +    public Class<?>[] getExceptionTypes() {
 488.211 +        return (Class<?>[])exceptionTypes.clone();
 488.212 +    }
 488.213 +
 488.214 +
 488.215 +    /**
 488.216 +     * Returns an array of {@code Type} objects that represent the
 488.217 +     * exceptions declared to be thrown by this {@code Constructor} object.
 488.218 +     * Returns an array of length 0 if the underlying method declares
 488.219 +     * no exceptions in its {@code throws} clause.
 488.220 +     *
 488.221 +     * <p>If an exception type is a type variable or a parameterized
 488.222 +     * type, it is created. Otherwise, it is resolved.
 488.223 +     *
 488.224 +     * @return an array of Types that represent the exception types
 488.225 +     *     thrown by the underlying method
 488.226 +     * @throws GenericSignatureFormatError
 488.227 +     *     if the generic method signature does not conform to the format
 488.228 +     *     specified in
 488.229 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 488.230 +     * @throws TypeNotPresentException if the underlying method's
 488.231 +     *     {@code throws} clause refers to a non-existent type declaration
 488.232 +     * @throws MalformedParameterizedTypeException if
 488.233 +     *     the underlying method's {@code throws} clause refers to a
 488.234 +     *     parameterized type that cannot be instantiated for any reason
 488.235 +     * @since 1.5
 488.236 +     */
 488.237 +      public Type[] getGenericExceptionTypes() {
 488.238 +          return TypeProvider.getDefault().getGenericExceptionTypes(this);
 488.239 +      }
 488.240 +
 488.241 +    /**
 488.242 +     * Compares this {@code Constructor} against the specified object.
 488.243 +     * Returns true if the objects are the same.  Two {@code Constructor} objects are
 488.244 +     * the same if they were declared by the same class and have the
 488.245 +     * same formal parameter types.
 488.246 +     */
 488.247 +    public boolean equals(Object obj) {
 488.248 +        if (obj != null && obj instanceof Constructor) {
 488.249 +            Constructor<?> other = (Constructor<?>)obj;
 488.250 +            if (getDeclaringClass() == other.getDeclaringClass()) {
 488.251 +                /* Avoid unnecessary cloning */
 488.252 +                Class<?>[] params1 = parameterTypes;
 488.253 +                Class<?>[] params2 = other.parameterTypes;
 488.254 +                if (params1.length == params2.length) {
 488.255 +                    for (int i = 0; i < params1.length; i++) {
 488.256 +                        if (params1[i] != params2[i])
 488.257 +                            return false;
 488.258 +                    }
 488.259 +                    return true;
 488.260 +                }
 488.261 +            }
 488.262 +        }
 488.263 +        return false;
 488.264 +    }
 488.265 +
 488.266 +    /**
 488.267 +     * Returns a hashcode for this {@code Constructor}. The hashcode is
 488.268 +     * the same as the hashcode for the underlying constructor's
 488.269 +     * declaring class name.
 488.270 +     */
 488.271 +    public int hashCode() {
 488.272 +        return getDeclaringClass().getName().hashCode();
 488.273 +    }
 488.274 +
 488.275 +    /**
 488.276 +     * Returns a string describing this {@code Constructor}.  The string is
 488.277 +     * formatted as the constructor access modifiers, if any,
 488.278 +     * followed by the fully-qualified name of the declaring class,
 488.279 +     * followed by a parenthesized, comma-separated list of the
 488.280 +     * constructor's formal parameter types.  For example:
 488.281 +     * <pre>
 488.282 +     *    public java.util.Hashtable(int,float)
 488.283 +     * </pre>
 488.284 +     *
 488.285 +     * <p>The only possible modifiers for constructors are the access
 488.286 +     * modifiers {@code public}, {@code protected} or
 488.287 +     * {@code private}.  Only one of these may appear, or none if the
 488.288 +     * constructor has default (package) access.
 488.289 +     */
 488.290 +    public String toString() {
 488.291 +        try {
 488.292 +            StringBuffer sb = new StringBuffer();
 488.293 +            int mod = getModifiers() & Modifier.constructorModifiers();
 488.294 +            if (mod != 0) {
 488.295 +                sb.append(Modifier.toString(mod) + " ");
 488.296 +            }
 488.297 +            sb.append(Field.getTypeName(getDeclaringClass()));
 488.298 +            sb.append("(");
 488.299 +            Class<?>[] params = parameterTypes; // avoid clone
 488.300 +            for (int j = 0; j < params.length; j++) {
 488.301 +                sb.append(Field.getTypeName(params[j]));
 488.302 +                if (j < (params.length - 1))
 488.303 +                    sb.append(",");
 488.304 +            }
 488.305 +            sb.append(")");
 488.306 +            Class<?>[] exceptions = exceptionTypes; // avoid clone
 488.307 +            if (exceptions.length > 0) {
 488.308 +                sb.append(" throws ");
 488.309 +                for (int k = 0; k < exceptions.length; k++) {
 488.310 +                    sb.append(exceptions[k].getName());
 488.311 +                    if (k < (exceptions.length - 1))
 488.312 +                        sb.append(",");
 488.313 +                }
 488.314 +            }
 488.315 +            return sb.toString();
 488.316 +        } catch (Exception e) {
 488.317 +            return "<" + e + ">";
 488.318 +        }
 488.319 +    }
 488.320 +
 488.321 +    /**
 488.322 +     * Returns a string describing this {@code Constructor},
 488.323 +     * including type parameters.  The string is formatted as the
 488.324 +     * constructor access modifiers, if any, followed by an
 488.325 +     * angle-bracketed comma separated list of the constructor's type
 488.326 +     * parameters, if any, followed by the fully-qualified name of the
 488.327 +     * declaring class, followed by a parenthesized, comma-separated
 488.328 +     * list of the constructor's generic formal parameter types.
 488.329 +     *
 488.330 +     * If this constructor was declared to take a variable number of
 488.331 +     * arguments, instead of denoting the last parameter as
 488.332 +     * "<tt><i>Type</i>[]</tt>", it is denoted as
 488.333 +     * "<tt><i>Type</i>...</tt>".
 488.334 +     *
 488.335 +     * A space is used to separate access modifiers from one another
 488.336 +     * and from the type parameters or return type.  If there are no
 488.337 +     * type parameters, the type parameter list is elided; if the type
 488.338 +     * parameter list is present, a space separates the list from the
 488.339 +     * class name.  If the constructor is declared to throw
 488.340 +     * exceptions, the parameter list is followed by a space, followed
 488.341 +     * by the word "{@code throws}" followed by a
 488.342 +     * comma-separated list of the thrown exception types.
 488.343 +     *
 488.344 +     * <p>The only possible modifiers for constructors are the access
 488.345 +     * modifiers {@code public}, {@code protected} or
 488.346 +     * {@code private}.  Only one of these may appear, or none if the
 488.347 +     * constructor has default (package) access.
 488.348 +     *
 488.349 +     * @return a string describing this {@code Constructor},
 488.350 +     * include type parameters
 488.351 +     *
 488.352 +     * @since 1.5
 488.353 +     */
 488.354 +    public String toGenericString() {
 488.355 +        try {
 488.356 +            StringBuilder sb = new StringBuilder();
 488.357 +            int mod = getModifiers() & Modifier.constructorModifiers();
 488.358 +            if (mod != 0) {
 488.359 +                sb.append(Modifier.toString(mod) + " ");
 488.360 +            }
 488.361 +            TypeVariable<?>[] typeparms = getTypeParameters();
 488.362 +            if (typeparms.length > 0) {
 488.363 +                boolean first = true;
 488.364 +                sb.append("<");
 488.365 +                for(TypeVariable<?> typeparm: typeparms) {
 488.366 +                    if (!first)
 488.367 +                        sb.append(",");
 488.368 +                    // Class objects can't occur here; no need to test
 488.369 +                    // and call Class.getName().
 488.370 +                    sb.append(typeparm.toString());
 488.371 +                    first = false;
 488.372 +                }
 488.373 +                sb.append("> ");
 488.374 +            }
 488.375 +            sb.append(Field.getTypeName(getDeclaringClass()));
 488.376 +            sb.append("(");
 488.377 +            Type[] params = getGenericParameterTypes();
 488.378 +            for (int j = 0; j < params.length; j++) {
 488.379 +                String param = (params[j] instanceof Class<?>)?
 488.380 +                    Field.getTypeName((Class<?>)params[j]):
 488.381 +                    (params[j].toString());
 488.382 +                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 488.383 +                    param = param.replaceFirst("\\[\\]$", "...");
 488.384 +                sb.append(param);
 488.385 +                if (j < (params.length - 1))
 488.386 +                    sb.append(",");
 488.387 +            }
 488.388 +            sb.append(")");
 488.389 +            Type[] exceptions = getGenericExceptionTypes();
 488.390 +            if (exceptions.length > 0) {
 488.391 +                sb.append(" throws ");
 488.392 +                for (int k = 0; k < exceptions.length; k++) {
 488.393 +                    sb.append((exceptions[k] instanceof Class)?
 488.394 +                              ((Class<?>)exceptions[k]).getName():
 488.395 +                              exceptions[k].toString());
 488.396 +                    if (k < (exceptions.length - 1))
 488.397 +                        sb.append(",");
 488.398 +                }
 488.399 +            }
 488.400 +            return sb.toString();
 488.401 +        } catch (Exception e) {
 488.402 +            return "<" + e + ">";
 488.403 +        }
 488.404 +    }
 488.405 +
 488.406 +    /**
 488.407 +     * Uses the constructor represented by this {@code Constructor} object to
 488.408 +     * create and initialize a new instance of the constructor's
 488.409 +     * declaring class, with the specified initialization parameters.
 488.410 +     * Individual parameters are automatically unwrapped to match
 488.411 +     * primitive formal parameters, and both primitive and reference
 488.412 +     * parameters are subject to method invocation conversions as necessary.
 488.413 +     *
 488.414 +     * <p>If the number of formal parameters required by the underlying constructor
 488.415 +     * is 0, the supplied {@code initargs} array may be of length 0 or null.
 488.416 +     *
 488.417 +     * <p>If the constructor's declaring class is an inner class in a
 488.418 +     * non-static context, the first argument to the constructor needs
 488.419 +     * to be the enclosing instance; see section 15.9.3 of
 488.420 +     * <cite>The Java&trade; Language Specification</cite>.
 488.421 +     *
 488.422 +     * <p>If the required access and argument checks succeed and the
 488.423 +     * instantiation will proceed, the constructor's declaring class
 488.424 +     * is initialized if it has not already been initialized.
 488.425 +     *
 488.426 +     * <p>If the constructor completes normally, returns the newly
 488.427 +     * created and initialized instance.
 488.428 +     *
 488.429 +     * @param initargs array of objects to be passed as arguments to
 488.430 +     * the constructor call; values of primitive types are wrapped in
 488.431 +     * a wrapper object of the appropriate type (e.g. a {@code float}
 488.432 +     * in a {@link java.lang.Float Float})
 488.433 +     *
 488.434 +     * @return a new object created by calling the constructor
 488.435 +     * this object represents
 488.436 +     *
 488.437 +     * @exception IllegalAccessException    if this {@code Constructor} object
 488.438 +     *              is enforcing Java language access control and the underlying
 488.439 +     *              constructor is inaccessible.
 488.440 +     * @exception IllegalArgumentException  if the number of actual
 488.441 +     *              and formal parameters differ; if an unwrapping
 488.442 +     *              conversion for primitive arguments fails; or if,
 488.443 +     *              after possible unwrapping, a parameter value
 488.444 +     *              cannot be converted to the corresponding formal
 488.445 +     *              parameter type by a method invocation conversion; if
 488.446 +     *              this constructor pertains to an enum type.
 488.447 +     * @exception InstantiationException    if the class that declares the
 488.448 +     *              underlying constructor represents an abstract class.
 488.449 +     * @exception InvocationTargetException if the underlying constructor
 488.450 +     *              throws an exception.
 488.451 +     * @exception ExceptionInInitializerError if the initialization provoked
 488.452 +     *              by this method fails.
 488.453 +     */
 488.454 +    public T newInstance(Object ... initargs)
 488.455 +        throws InstantiationException, IllegalAccessException,
 488.456 +               IllegalArgumentException, InvocationTargetException
 488.457 +    {
 488.458 +        throw new SecurityException();
 488.459 +    }
 488.460 +
 488.461 +    /**
 488.462 +     * Returns {@code true} if this constructor was declared to take
 488.463 +     * a variable number of arguments; returns {@code false}
 488.464 +     * otherwise.
 488.465 +     *
 488.466 +     * @return {@code true} if an only if this constructor was declared to
 488.467 +     * take a variable number of arguments.
 488.468 +     * @since 1.5
 488.469 +     */
 488.470 +    public boolean isVarArgs() {
 488.471 +        return (getModifiers() & Modifier.VARARGS) != 0;
 488.472 +    }
 488.473 +
 488.474 +    /**
 488.475 +     * Returns {@code true} if this constructor is a synthetic
 488.476 +     * constructor; returns {@code false} otherwise.
 488.477 +     *
 488.478 +     * @return true if and only if this constructor is a synthetic
 488.479 +     * constructor as defined by
 488.480 +     * <cite>The Java&trade; Language Specification</cite>.
 488.481 +     * @since 1.5
 488.482 +     */
 488.483 +    public boolean isSynthetic() {
 488.484 +        return Modifier.isSynthetic(getModifiers());
 488.485 +    }
 488.486 +
 488.487 +    int getSlot() {
 488.488 +        return slot;
 488.489 +    }
 488.490 +
 488.491 +   String getSignature() {
 488.492 +            return signature;
 488.493 +   }
 488.494 +
 488.495 +    byte[] getRawAnnotations() {
 488.496 +        return annotations;
 488.497 +    }
 488.498 +
 488.499 +    byte[] getRawParameterAnnotations() {
 488.500 +        return parameterAnnotations;
 488.501 +    }
 488.502 +
 488.503 +    /**
 488.504 +     * @throws NullPointerException {@inheritDoc}
 488.505 +     * @since 1.5
 488.506 +     */
 488.507 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 488.508 +        if (annotationClass == null)
 488.509 +            throw new NullPointerException();
 488.510 +
 488.511 +        return null; // XXX (T) declaredAnnotations().get(annotationClass);
 488.512 +    }
 488.513 +
 488.514 +    /**
 488.515 +     * @since 1.5
 488.516 +     */
 488.517 +    public Annotation[] getDeclaredAnnotations()  {
 488.518 +        return new Annotation[0]; // XXX AnnotationParser.toArray(declaredAnnotations());
 488.519 +    }
 488.520 +
 488.521 +    /**
 488.522 +     * Returns an array of arrays that represent the annotations on the formal
 488.523 +     * parameters, in declaration order, of the method represented by
 488.524 +     * this {@code Constructor} object. (Returns an array of length zero if the
 488.525 +     * underlying method is parameterless.  If the method has one or more
 488.526 +     * parameters, a nested array of length zero is returned for each parameter
 488.527 +     * with no annotations.) The annotation objects contained in the returned
 488.528 +     * arrays are serializable.  The caller of this method is free to modify
 488.529 +     * the returned arrays; it will have no effect on the arrays returned to
 488.530 +     * other callers.
 488.531 +     *
 488.532 +     * @return an array of arrays that represent the annotations on the formal
 488.533 +     *    parameters, in declaration order, of the method represented by this
 488.534 +     *    Constructor object
 488.535 +     * @since 1.5
 488.536 +     */
 488.537 +    public Annotation[][] getParameterAnnotations() {
 488.538 +        int numParameters = parameterTypes.length;
 488.539 +        if (parameterAnnotations == null)
 488.540 +            return new Annotation[numParameters][0];
 488.541 +        
 488.542 +        return new Annotation[numParameters][0]; // XXX
 488.543 +/*
 488.544 +        Annotation[][] result = AnnotationParser.parseParameterAnnotations(
 488.545 +            parameterAnnotations,
 488.546 +            sun.misc.SharedSecrets.getJavaLangAccess().
 488.547 +                getConstantPool(getDeclaringClass()),
 488.548 +            getDeclaringClass());
 488.549 +        if (result.length != numParameters) {
 488.550 +            Class<?> declaringClass = getDeclaringClass();
 488.551 +            if (declaringClass.isEnum() ||
 488.552 +                declaringClass.isAnonymousClass() ||
 488.553 +                declaringClass.isLocalClass() )
 488.554 +                ; // Can't do reliable parameter counting
 488.555 +            else {
 488.556 +                if (!declaringClass.isMemberClass() || // top-level
 488.557 +                    // Check for the enclosing instance parameter for
 488.558 +                    // non-static member classes
 488.559 +                    (declaringClass.isMemberClass() &&
 488.560 +                     ((declaringClass.getModifiers() & Modifier.STATIC) == 0)  &&
 488.561 +                     result.length + 1 != numParameters) ) {
 488.562 +                    throw new AnnotationFormatError(
 488.563 +                              "Parameter annotations don't match number of parameters");
 488.564 +                }
 488.565 +            }
 488.566 +        }
 488.567 +        return result;
 488.568 +        */
 488.569 +    }
 488.570 +}
   489.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   489.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Field.java	Wed Feb 27 11:24:58 2013 +0100
   489.3 @@ -0,0 +1,953 @@
   489.4 +/*
   489.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   489.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   489.7 + *
   489.8 + * This code is free software; you can redistribute it and/or modify it
   489.9 + * under the terms of the GNU General Public License version 2 only, as
  489.10 + * published by the Free Software Foundation.  Oracle designates this
  489.11 + * particular file as subject to the "Classpath" exception as provided
  489.12 + * by Oracle in the LICENSE file that accompanied this code.
  489.13 + *
  489.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  489.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  489.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  489.17 + * version 2 for more details (a copy is included in the LICENSE file that
  489.18 + * accompanied this code).
  489.19 + *
  489.20 + * You should have received a copy of the GNU General Public License version
  489.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  489.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  489.23 + *
  489.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  489.25 + * or visit www.oracle.com if you need additional information or have any
  489.26 + * questions.
  489.27 + */
  489.28 +
  489.29 +package java.lang.reflect;
  489.30 +
  489.31 +import java.lang.annotation.Annotation;
  489.32 +
  489.33 +
  489.34 +/**
  489.35 + * A {@code Field} provides information about, and dynamic access to, a
  489.36 + * single field of a class or an interface.  The reflected field may
  489.37 + * be a class (static) field or an instance field.
  489.38 + *
  489.39 + * <p>A {@code Field} permits widening conversions to occur during a get or
  489.40 + * set access operation, but throws an {@code IllegalArgumentException} if a
  489.41 + * narrowing conversion would occur.
  489.42 + *
  489.43 + * @see Member
  489.44 + * @see java.lang.Class
  489.45 + * @see java.lang.Class#getFields()
  489.46 + * @see java.lang.Class#getField(String)
  489.47 + * @see java.lang.Class#getDeclaredFields()
  489.48 + * @see java.lang.Class#getDeclaredField(String)
  489.49 + *
  489.50 + * @author Kenneth Russell
  489.51 + * @author Nakul Saraiya
  489.52 + */
  489.53 +public final
  489.54 +class Field extends AccessibleObject implements Member {
  489.55 +
  489.56 +    private Class<?>            clazz;
  489.57 +    private int                 slot;
  489.58 +    // This is guaranteed to be interned by the VM in the 1.4
  489.59 +    // reflection implementation
  489.60 +    private String              name;
  489.61 +    private Class<?>            type;
  489.62 +    private int                 modifiers;
  489.63 +    // Generics and annotations support
  489.64 +    private transient String    signature;
  489.65 +    private byte[]              annotations;
  489.66 +    // For sharing of FieldAccessors. This branching structure is
  489.67 +    // currently only two levels deep (i.e., one root Field and
  489.68 +    // potentially many Field objects pointing to it.)
  489.69 +    private Field               root;
  489.70 +
  489.71 +    // Generics infrastructure
  489.72 +
  489.73 +    private String getGenericSignature() {return signature;}
  489.74 +
  489.75 +
  489.76 +    /**
  489.77 +     * Package-private constructor used by ReflectAccess to enable
  489.78 +     * instantiation of these objects in Java code from the java.lang
  489.79 +     * package via sun.reflect.LangReflectAccess.
  489.80 +     */
  489.81 +    Field(Class<?> declaringClass,
  489.82 +          String name,
  489.83 +          Class<?> type,
  489.84 +          int modifiers,
  489.85 +          int slot,
  489.86 +          String signature,
  489.87 +          byte[] annotations)
  489.88 +    {
  489.89 +        this.clazz = declaringClass;
  489.90 +        this.name = name;
  489.91 +        this.type = type;
  489.92 +        this.modifiers = modifiers;
  489.93 +        this.slot = slot;
  489.94 +        this.signature = signature;
  489.95 +        this.annotations = annotations;
  489.96 +    }
  489.97 +
  489.98 +    /**
  489.99 +     * Package-private routine (exposed to java.lang.Class via
 489.100 +     * ReflectAccess) which returns a copy of this Field. The copy's
 489.101 +     * "root" field points to this Field.
 489.102 +     */
 489.103 +    Field copy() {
 489.104 +        // This routine enables sharing of FieldAccessor objects
 489.105 +        // among Field objects which refer to the same underlying
 489.106 +        // method in the VM. (All of this contortion is only necessary
 489.107 +        // because of the "accessibility" bit in AccessibleObject,
 489.108 +        // which implicitly requires that new java.lang.reflect
 489.109 +        // objects be fabricated for each reflective call on Class
 489.110 +        // objects.)
 489.111 +        Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
 489.112 +        res.root = this;
 489.113 +        return res;
 489.114 +    }
 489.115 +
 489.116 +    /**
 489.117 +     * Returns the {@code Class} object representing the class or interface
 489.118 +     * that declares the field represented by this {@code Field} object.
 489.119 +     */
 489.120 +    public Class<?> getDeclaringClass() {
 489.121 +        return clazz;
 489.122 +    }
 489.123 +
 489.124 +    /**
 489.125 +     * Returns the name of the field represented by this {@code Field} object.
 489.126 +     */
 489.127 +    public String getName() {
 489.128 +        return name;
 489.129 +    }
 489.130 +
 489.131 +    /**
 489.132 +     * Returns the Java language modifiers for the field represented
 489.133 +     * by this {@code Field} object, as an integer. The {@code Modifier} class should
 489.134 +     * be used to decode the modifiers.
 489.135 +     *
 489.136 +     * @see Modifier
 489.137 +     */
 489.138 +    public int getModifiers() {
 489.139 +        return modifiers;
 489.140 +    }
 489.141 +
 489.142 +    /**
 489.143 +     * Returns {@code true} if this field represents an element of
 489.144 +     * an enumerated type; returns {@code false} otherwise.
 489.145 +     *
 489.146 +     * @return {@code true} if and only if this field represents an element of
 489.147 +     * an enumerated type.
 489.148 +     * @since 1.5
 489.149 +     */
 489.150 +    public boolean isEnumConstant() {
 489.151 +        return (getModifiers() & Modifier.ENUM) != 0;
 489.152 +    }
 489.153 +
 489.154 +    /**
 489.155 +     * Returns {@code true} if this field is a synthetic
 489.156 +     * field; returns {@code false} otherwise.
 489.157 +     *
 489.158 +     * @return true if and only if this field is a synthetic
 489.159 +     * field as defined by the Java Language Specification.
 489.160 +     * @since 1.5
 489.161 +     */
 489.162 +    public boolean isSynthetic() {
 489.163 +        return Modifier.isSynthetic(getModifiers());
 489.164 +    }
 489.165 +
 489.166 +    /**
 489.167 +     * Returns a {@code Class} object that identifies the
 489.168 +     * declared type for the field represented by this
 489.169 +     * {@code Field} object.
 489.170 +     *
 489.171 +     * @return a {@code Class} object identifying the declared
 489.172 +     * type of the field represented by this object
 489.173 +     */
 489.174 +    public Class<?> getType() {
 489.175 +        return type;
 489.176 +    }
 489.177 +
 489.178 +    /**
 489.179 +     * Returns a {@code Type} object that represents the declared type for
 489.180 +     * the field represented by this {@code Field} object.
 489.181 +     *
 489.182 +     * <p>If the {@code Type} is a parameterized type, the
 489.183 +     * {@code Type} object returned must accurately reflect the
 489.184 +     * actual type parameters used in the source code.
 489.185 +     *
 489.186 +     * <p>If the type of the underlying field is a type variable or a
 489.187 +     * parameterized type, it is created. Otherwise, it is resolved.
 489.188 +     *
 489.189 +     * @return a {@code Type} object that represents the declared type for
 489.190 +     *     the field represented by this {@code Field} object
 489.191 +     * @throws GenericSignatureFormatError if the generic field
 489.192 +     *     signature does not conform to the format specified in
 489.193 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 489.194 +     * @throws TypeNotPresentException if the generic type
 489.195 +     *     signature of the underlying field refers to a non-existent
 489.196 +     *     type declaration
 489.197 +     * @throws MalformedParameterizedTypeException if the generic
 489.198 +     *     signature of the underlying field refers to a parameterized type
 489.199 +     *     that cannot be instantiated for any reason
 489.200 +     * @since 1.5
 489.201 +     */
 489.202 +    public Type getGenericType() {
 489.203 +        throw new UnsupportedOperationException();
 489.204 +    }
 489.205 +
 489.206 +
 489.207 +    /**
 489.208 +     * Compares this {@code Field} against the specified object.  Returns
 489.209 +     * true if the objects are the same.  Two {@code Field} objects are the same if
 489.210 +     * they were declared by the same class and have the same name
 489.211 +     * and type.
 489.212 +     */
 489.213 +    public boolean equals(Object obj) {
 489.214 +        if (obj != null && obj instanceof Field) {
 489.215 +            Field other = (Field)obj;
 489.216 +            return (getDeclaringClass() == other.getDeclaringClass())
 489.217 +                && (getName() == other.getName())
 489.218 +                && (getType() == other.getType());
 489.219 +        }
 489.220 +        return false;
 489.221 +    }
 489.222 +
 489.223 +    /**
 489.224 +     * Returns a hashcode for this {@code Field}.  This is computed as the
 489.225 +     * exclusive-or of the hashcodes for the underlying field's
 489.226 +     * declaring class name and its name.
 489.227 +     */
 489.228 +    public int hashCode() {
 489.229 +        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 489.230 +    }
 489.231 +
 489.232 +    /**
 489.233 +     * Returns a string describing this {@code Field}.  The format is
 489.234 +     * the access modifiers for the field, if any, followed
 489.235 +     * by the field type, followed by a space, followed by
 489.236 +     * the fully-qualified name of the class declaring the field,
 489.237 +     * followed by a period, followed by the name of the field.
 489.238 +     * For example:
 489.239 +     * <pre>
 489.240 +     *    public static final int java.lang.Thread.MIN_PRIORITY
 489.241 +     *    private int java.io.FileDescriptor.fd
 489.242 +     * </pre>
 489.243 +     *
 489.244 +     * <p>The modifiers are placed in canonical order as specified by
 489.245 +     * "The Java Language Specification".  This is {@code public},
 489.246 +     * {@code protected} or {@code private} first, and then other
 489.247 +     * modifiers in the following order: {@code static}, {@code final},
 489.248 +     * {@code transient}, {@code volatile}.
 489.249 +     */
 489.250 +    public String toString() {
 489.251 +        int mod = getModifiers();
 489.252 +        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 489.253 +            + getTypeName(getType()) + " "
 489.254 +            + getTypeName(getDeclaringClass()) + "."
 489.255 +            + getName());
 489.256 +    }
 489.257 +
 489.258 +    /**
 489.259 +     * Returns a string describing this {@code Field}, including
 489.260 +     * its generic type.  The format is the access modifiers for the
 489.261 +     * field, if any, followed by the generic field type, followed by
 489.262 +     * a space, followed by the fully-qualified name of the class
 489.263 +     * declaring the field, followed by a period, followed by the name
 489.264 +     * of the field.
 489.265 +     *
 489.266 +     * <p>The modifiers are placed in canonical order as specified by
 489.267 +     * "The Java Language Specification".  This is {@code public},
 489.268 +     * {@code protected} or {@code private} first, and then other
 489.269 +     * modifiers in the following order: {@code static}, {@code final},
 489.270 +     * {@code transient}, {@code volatile}.
 489.271 +     *
 489.272 +     * @return a string describing this {@code Field}, including
 489.273 +     * its generic type
 489.274 +     *
 489.275 +     * @since 1.5
 489.276 +     */
 489.277 +    public String toGenericString() {
 489.278 +        int mod = getModifiers();
 489.279 +        Type fieldType = getGenericType();
 489.280 +        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
 489.281 +            +  ((fieldType instanceof Class) ?
 489.282 +                getTypeName((Class)fieldType): fieldType.toString())+ " "
 489.283 +            + getTypeName(getDeclaringClass()) + "."
 489.284 +            + getName());
 489.285 +    }
 489.286 +
 489.287 +    /**
 489.288 +     * Returns the value of the field represented by this {@code Field}, on
 489.289 +     * the specified object. The value is automatically wrapped in an
 489.290 +     * object if it has a primitive type.
 489.291 +     *
 489.292 +     * <p>The underlying field's value is obtained as follows:
 489.293 +     *
 489.294 +     * <p>If the underlying field is a static field, the {@code obj} argument
 489.295 +     * is ignored; it may be null.
 489.296 +     *
 489.297 +     * <p>Otherwise, the underlying field is an instance field.  If the
 489.298 +     * specified {@code obj} argument is null, the method throws a
 489.299 +     * {@code NullPointerException}. If the specified object is not an
 489.300 +     * instance of the class or interface declaring the underlying
 489.301 +     * field, the method throws an {@code IllegalArgumentException}.
 489.302 +     *
 489.303 +     * <p>If this {@code Field} object is enforcing Java language access control, and
 489.304 +     * the underlying field is inaccessible, the method throws an
 489.305 +     * {@code IllegalAccessException}.
 489.306 +     * If the underlying field is static, the class that declared the
 489.307 +     * field is initialized if it has not already been initialized.
 489.308 +     *
 489.309 +     * <p>Otherwise, the value is retrieved from the underlying instance
 489.310 +     * or static field.  If the field has a primitive type, the value
 489.311 +     * is wrapped in an object before being returned, otherwise it is
 489.312 +     * returned as is.
 489.313 +     *
 489.314 +     * <p>If the field is hidden in the type of {@code obj},
 489.315 +     * the field's value is obtained according to the preceding rules.
 489.316 +     *
 489.317 +     * @param obj object from which the represented field's value is
 489.318 +     * to be extracted
 489.319 +     * @return the value of the represented field in object
 489.320 +     * {@code obj}; primitive values are wrapped in an appropriate
 489.321 +     * object before being returned
 489.322 +     *
 489.323 +     * @exception IllegalAccessException    if this {@code Field} object
 489.324 +     *              is enforcing Java language access control and the underlying
 489.325 +     *              field is inaccessible.
 489.326 +     * @exception IllegalArgumentException  if the specified object is not an
 489.327 +     *              instance of the class or interface declaring the underlying
 489.328 +     *              field (or a subclass or implementor thereof).
 489.329 +     * @exception NullPointerException      if the specified object is null
 489.330 +     *              and the field is an instance field.
 489.331 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.332 +     *              by this method fails.
 489.333 +     */
 489.334 +    public Object get(Object obj)
 489.335 +        throws IllegalArgumentException, IllegalAccessException
 489.336 +    {
 489.337 +        return getFieldAccessor(obj).get(obj);
 489.338 +    }
 489.339 +
 489.340 +    /**
 489.341 +     * Gets the value of a static or instance {@code boolean} field.
 489.342 +     *
 489.343 +     * @param obj the object to extract the {@code boolean} value
 489.344 +     * from
 489.345 +     * @return the value of the {@code boolean} field
 489.346 +     *
 489.347 +     * @exception IllegalAccessException    if this {@code Field} object
 489.348 +     *              is enforcing Java language access control and the underlying
 489.349 +     *              field is inaccessible.
 489.350 +     * @exception IllegalArgumentException  if the specified object is not
 489.351 +     *              an instance of the class or interface declaring the
 489.352 +     *              underlying field (or a subclass or implementor
 489.353 +     *              thereof), or if the field value cannot be
 489.354 +     *              converted to the type {@code boolean} by a
 489.355 +     *              widening conversion.
 489.356 +     * @exception NullPointerException      if the specified object is null
 489.357 +     *              and the field is an instance field.
 489.358 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.359 +     *              by this method fails.
 489.360 +     * @see       Field#get
 489.361 +     */
 489.362 +    public boolean getBoolean(Object obj)
 489.363 +        throws IllegalArgumentException, IllegalAccessException
 489.364 +    {
 489.365 +        return getFieldAccessor(obj).getBoolean(obj);
 489.366 +    }
 489.367 +
 489.368 +    /**
 489.369 +     * Gets the value of a static or instance {@code byte} field.
 489.370 +     *
 489.371 +     * @param obj the object to extract the {@code byte} value
 489.372 +     * from
 489.373 +     * @return the value of the {@code byte} field
 489.374 +     *
 489.375 +     * @exception IllegalAccessException    if this {@code Field} object
 489.376 +     *              is enforcing Java language access control and the underlying
 489.377 +     *              field is inaccessible.
 489.378 +     * @exception IllegalArgumentException  if the specified object is not
 489.379 +     *              an instance of the class or interface declaring the
 489.380 +     *              underlying field (or a subclass or implementor
 489.381 +     *              thereof), or if the field value cannot be
 489.382 +     *              converted to the type {@code byte} by a
 489.383 +     *              widening conversion.
 489.384 +     * @exception NullPointerException      if the specified object is null
 489.385 +     *              and the field is an instance field.
 489.386 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.387 +     *              by this method fails.
 489.388 +     * @see       Field#get
 489.389 +     */
 489.390 +    public byte getByte(Object obj)
 489.391 +        throws IllegalArgumentException, IllegalAccessException
 489.392 +    {
 489.393 +        return getFieldAccessor(obj).getByte(obj);
 489.394 +    }
 489.395 +
 489.396 +    /**
 489.397 +     * Gets the value of a static or instance field of type
 489.398 +     * {@code char} or of another primitive type convertible to
 489.399 +     * type {@code char} via a widening conversion.
 489.400 +     *
 489.401 +     * @param obj the object to extract the {@code char} value
 489.402 +     * from
 489.403 +     * @return the value of the field converted to type {@code char}
 489.404 +     *
 489.405 +     * @exception IllegalAccessException    if this {@code Field} object
 489.406 +     *              is enforcing Java language access control and the underlying
 489.407 +     *              field is inaccessible.
 489.408 +     * @exception IllegalArgumentException  if the specified object is not
 489.409 +     *              an instance of the class or interface declaring the
 489.410 +     *              underlying field (or a subclass or implementor
 489.411 +     *              thereof), or if the field value cannot be
 489.412 +     *              converted to the type {@code char} by a
 489.413 +     *              widening conversion.
 489.414 +     * @exception NullPointerException      if the specified object is null
 489.415 +     *              and the field is an instance field.
 489.416 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.417 +     *              by this method fails.
 489.418 +     * @see Field#get
 489.419 +     */
 489.420 +    public char getChar(Object obj)
 489.421 +        throws IllegalArgumentException, IllegalAccessException
 489.422 +    {
 489.423 +        return getFieldAccessor(obj).getChar(obj);
 489.424 +    }
 489.425 +
 489.426 +    /**
 489.427 +     * Gets the value of a static or instance field of type
 489.428 +     * {@code short} or of another primitive type convertible to
 489.429 +     * type {@code short} via a widening conversion.
 489.430 +     *
 489.431 +     * @param obj the object to extract the {@code short} value
 489.432 +     * from
 489.433 +     * @return the value of the field converted to type {@code short}
 489.434 +     *
 489.435 +     * @exception IllegalAccessException    if this {@code Field} object
 489.436 +     *              is enforcing Java language access control and the underlying
 489.437 +     *              field is inaccessible.
 489.438 +     * @exception IllegalArgumentException  if the specified object is not
 489.439 +     *              an instance of the class or interface declaring the
 489.440 +     *              underlying field (or a subclass or implementor
 489.441 +     *              thereof), or if the field value cannot be
 489.442 +     *              converted to the type {@code short} by a
 489.443 +     *              widening conversion.
 489.444 +     * @exception NullPointerException      if the specified object is null
 489.445 +     *              and the field is an instance field.
 489.446 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.447 +     *              by this method fails.
 489.448 +     * @see       Field#get
 489.449 +     */
 489.450 +    public short getShort(Object obj)
 489.451 +        throws IllegalArgumentException, IllegalAccessException
 489.452 +    {
 489.453 +        return getFieldAccessor(obj).getShort(obj);
 489.454 +    }
 489.455 +
 489.456 +    /**
 489.457 +     * Gets the value of a static or instance field of type
 489.458 +     * {@code int} or of another primitive type convertible to
 489.459 +     * type {@code int} via a widening conversion.
 489.460 +     *
 489.461 +     * @param obj the object to extract the {@code int} value
 489.462 +     * from
 489.463 +     * @return the value of the field converted to type {@code int}
 489.464 +     *
 489.465 +     * @exception IllegalAccessException    if this {@code Field} object
 489.466 +     *              is enforcing Java language access control and the underlying
 489.467 +     *              field is inaccessible.
 489.468 +     * @exception IllegalArgumentException  if the specified object is not
 489.469 +     *              an instance of the class or interface declaring the
 489.470 +     *              underlying field (or a subclass or implementor
 489.471 +     *              thereof), or if the field value cannot be
 489.472 +     *              converted to the type {@code int} by a
 489.473 +     *              widening conversion.
 489.474 +     * @exception NullPointerException      if the specified object is null
 489.475 +     *              and the field is an instance field.
 489.476 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.477 +     *              by this method fails.
 489.478 +     * @see       Field#get
 489.479 +     */
 489.480 +    public int getInt(Object obj)
 489.481 +        throws IllegalArgumentException, IllegalAccessException
 489.482 +    {
 489.483 +        return getFieldAccessor(obj).getInt(obj);
 489.484 +    }
 489.485 +
 489.486 +    /**
 489.487 +     * Gets the value of a static or instance field of type
 489.488 +     * {@code long} or of another primitive type convertible to
 489.489 +     * type {@code long} via a widening conversion.
 489.490 +     *
 489.491 +     * @param obj the object to extract the {@code long} value
 489.492 +     * from
 489.493 +     * @return the value of the field converted to type {@code long}
 489.494 +     *
 489.495 +     * @exception IllegalAccessException    if this {@code Field} object
 489.496 +     *              is enforcing Java language access control and the underlying
 489.497 +     *              field is inaccessible.
 489.498 +     * @exception IllegalArgumentException  if the specified object is not
 489.499 +     *              an instance of the class or interface declaring the
 489.500 +     *              underlying field (or a subclass or implementor
 489.501 +     *              thereof), or if the field value cannot be
 489.502 +     *              converted to the type {@code long} by a
 489.503 +     *              widening conversion.
 489.504 +     * @exception NullPointerException      if the specified object is null
 489.505 +     *              and the field is an instance field.
 489.506 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.507 +     *              by this method fails.
 489.508 +     * @see       Field#get
 489.509 +     */
 489.510 +    public long getLong(Object obj)
 489.511 +        throws IllegalArgumentException, IllegalAccessException
 489.512 +    {
 489.513 +        return getFieldAccessor(obj).getLong(obj);
 489.514 +    }
 489.515 +
 489.516 +    /**
 489.517 +     * Gets the value of a static or instance field of type
 489.518 +     * {@code float} or of another primitive type convertible to
 489.519 +     * type {@code float} via a widening conversion.
 489.520 +     *
 489.521 +     * @param obj the object to extract the {@code float} value
 489.522 +     * from
 489.523 +     * @return the value of the field converted to type {@code float}
 489.524 +     *
 489.525 +     * @exception IllegalAccessException    if this {@code Field} object
 489.526 +     *              is enforcing Java language access control and the underlying
 489.527 +     *              field is inaccessible.
 489.528 +     * @exception IllegalArgumentException  if the specified object is not
 489.529 +     *              an instance of the class or interface declaring the
 489.530 +     *              underlying field (or a subclass or implementor
 489.531 +     *              thereof), or if the field value cannot be
 489.532 +     *              converted to the type {@code float} by a
 489.533 +     *              widening conversion.
 489.534 +     * @exception NullPointerException      if the specified object is null
 489.535 +     *              and the field is an instance field.
 489.536 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.537 +     *              by this method fails.
 489.538 +     * @see Field#get
 489.539 +     */
 489.540 +    public float getFloat(Object obj)
 489.541 +        throws IllegalArgumentException, IllegalAccessException
 489.542 +    {
 489.543 +        return getFieldAccessor(obj).getFloat(obj);
 489.544 +    }
 489.545 +
 489.546 +    /**
 489.547 +     * Gets the value of a static or instance field of type
 489.548 +     * {@code double} or of another primitive type convertible to
 489.549 +     * type {@code double} via a widening conversion.
 489.550 +     *
 489.551 +     * @param obj the object to extract the {@code double} value
 489.552 +     * from
 489.553 +     * @return the value of the field converted to type {@code double}
 489.554 +     *
 489.555 +     * @exception IllegalAccessException    if this {@code Field} object
 489.556 +     *              is enforcing Java language access control and the underlying
 489.557 +     *              field is inaccessible.
 489.558 +     * @exception IllegalArgumentException  if the specified object is not
 489.559 +     *              an instance of the class or interface declaring the
 489.560 +     *              underlying field (or a subclass or implementor
 489.561 +     *              thereof), or if the field value cannot be
 489.562 +     *              converted to the type {@code double} by a
 489.563 +     *              widening conversion.
 489.564 +     * @exception NullPointerException      if the specified object is null
 489.565 +     *              and the field is an instance field.
 489.566 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.567 +     *              by this method fails.
 489.568 +     * @see       Field#get
 489.569 +     */
 489.570 +    public double getDouble(Object obj)
 489.571 +        throws IllegalArgumentException, IllegalAccessException
 489.572 +    {
 489.573 +        return getFieldAccessor(obj).getDouble(obj);
 489.574 +    }
 489.575 +
 489.576 +    /**
 489.577 +     * Sets the field represented by this {@code Field} object on the
 489.578 +     * specified object argument to the specified new value. The new
 489.579 +     * value is automatically unwrapped if the underlying field has a
 489.580 +     * primitive type.
 489.581 +     *
 489.582 +     * <p>The operation proceeds as follows:
 489.583 +     *
 489.584 +     * <p>If the underlying field is static, the {@code obj} argument is
 489.585 +     * ignored; it may be null.
 489.586 +     *
 489.587 +     * <p>Otherwise the underlying field is an instance field.  If the
 489.588 +     * specified object argument is null, the method throws a
 489.589 +     * {@code NullPointerException}.  If the specified object argument is not
 489.590 +     * an instance of the class or interface declaring the underlying
 489.591 +     * field, the method throws an {@code IllegalArgumentException}.
 489.592 +     *
 489.593 +     * <p>If this {@code Field} object is enforcing Java language access control, and
 489.594 +     * the underlying field is inaccessible, the method throws an
 489.595 +     * {@code IllegalAccessException}.
 489.596 +     *
 489.597 +     * <p>If the underlying field is final, the method throws an
 489.598 +     * {@code IllegalAccessException} unless {@code setAccessible(true)}
 489.599 +     * has succeeded for this {@code Field} object
 489.600 +     * and the field is non-static. Setting a final field in this way
 489.601 +     * is meaningful only during deserialization or reconstruction of
 489.602 +     * instances of classes with blank final fields, before they are
 489.603 +     * made available for access by other parts of a program. Use in
 489.604 +     * any other context may have unpredictable effects, including cases
 489.605 +     * in which other parts of a program continue to use the original
 489.606 +     * value of this field.
 489.607 +     *
 489.608 +     * <p>If the underlying field is of a primitive type, an unwrapping
 489.609 +     * conversion is attempted to convert the new value to a value of
 489.610 +     * a primitive type.  If this attempt fails, the method throws an
 489.611 +     * {@code IllegalArgumentException}.
 489.612 +     *
 489.613 +     * <p>If, after possible unwrapping, the new value cannot be
 489.614 +     * converted to the type of the underlying field by an identity or
 489.615 +     * widening conversion, the method throws an
 489.616 +     * {@code IllegalArgumentException}.
 489.617 +     *
 489.618 +     * <p>If the underlying field is static, the class that declared the
 489.619 +     * field is initialized if it has not already been initialized.
 489.620 +     *
 489.621 +     * <p>The field is set to the possibly unwrapped and widened new value.
 489.622 +     *
 489.623 +     * <p>If the field is hidden in the type of {@code obj},
 489.624 +     * the field's value is set according to the preceding rules.
 489.625 +     *
 489.626 +     * @param obj the object whose field should be modified
 489.627 +     * @param value the new value for the field of {@code obj}
 489.628 +     * being modified
 489.629 +     *
 489.630 +     * @exception IllegalAccessException    if this {@code Field} object
 489.631 +     *              is enforcing Java language access control and the underlying
 489.632 +     *              field is either inaccessible or final.
 489.633 +     * @exception IllegalArgumentException  if the specified object is not an
 489.634 +     *              instance of the class or interface declaring the underlying
 489.635 +     *              field (or a subclass or implementor thereof),
 489.636 +     *              or if an unwrapping conversion fails.
 489.637 +     * @exception NullPointerException      if the specified object is null
 489.638 +     *              and the field is an instance field.
 489.639 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.640 +     *              by this method fails.
 489.641 +     */
 489.642 +    public void set(Object obj, Object value)
 489.643 +        throws IllegalArgumentException, IllegalAccessException
 489.644 +    {
 489.645 +        getFieldAccessor(obj).set(obj, value);
 489.646 +    }
 489.647 +
 489.648 +    /**
 489.649 +     * Sets the value of a field as a {@code boolean} on the specified object.
 489.650 +     * This method is equivalent to
 489.651 +     * {@code set(obj, zObj)},
 489.652 +     * where {@code zObj} is a {@code Boolean} object and
 489.653 +     * {@code zObj.booleanValue() == z}.
 489.654 +     *
 489.655 +     * @param obj the object whose field should be modified
 489.656 +     * @param z   the new value for the field of {@code obj}
 489.657 +     * being modified
 489.658 +     *
 489.659 +     * @exception IllegalAccessException    if this {@code Field} object
 489.660 +     *              is enforcing Java language access control and the underlying
 489.661 +     *              field is either inaccessible or final.
 489.662 +     * @exception IllegalArgumentException  if the specified object is not an
 489.663 +     *              instance of the class or interface declaring the underlying
 489.664 +     *              field (or a subclass or implementor thereof),
 489.665 +     *              or if an unwrapping conversion fails.
 489.666 +     * @exception NullPointerException      if the specified object is null
 489.667 +     *              and the field is an instance field.
 489.668 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.669 +     *              by this method fails.
 489.670 +     * @see       Field#set
 489.671 +     */
 489.672 +    public void setBoolean(Object obj, boolean z)
 489.673 +        throws IllegalArgumentException, IllegalAccessException
 489.674 +    {
 489.675 +        getFieldAccessor(obj).setBoolean(obj, z);
 489.676 +    }
 489.677 +
 489.678 +    /**
 489.679 +     * Sets the value of a field as a {@code byte} on the specified object.
 489.680 +     * This method is equivalent to
 489.681 +     * {@code set(obj, bObj)},
 489.682 +     * where {@code bObj} is a {@code Byte} object and
 489.683 +     * {@code bObj.byteValue() == b}.
 489.684 +     *
 489.685 +     * @param obj the object whose field should be modified
 489.686 +     * @param b   the new value for the field of {@code obj}
 489.687 +     * being modified
 489.688 +     *
 489.689 +     * @exception IllegalAccessException    if this {@code Field} object
 489.690 +     *              is enforcing Java language access control and the underlying
 489.691 +     *              field is either inaccessible or final.
 489.692 +     * @exception IllegalArgumentException  if the specified object is not an
 489.693 +     *              instance of the class or interface declaring the underlying
 489.694 +     *              field (or a subclass or implementor thereof),
 489.695 +     *              or if an unwrapping conversion fails.
 489.696 +     * @exception NullPointerException      if the specified object is null
 489.697 +     *              and the field is an instance field.
 489.698 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.699 +     *              by this method fails.
 489.700 +     * @see       Field#set
 489.701 +     */
 489.702 +    public void setByte(Object obj, byte b)
 489.703 +        throws IllegalArgumentException, IllegalAccessException
 489.704 +    {
 489.705 +        getFieldAccessor(obj).setByte(obj, b);
 489.706 +    }
 489.707 +
 489.708 +    /**
 489.709 +     * Sets the value of a field as a {@code char} on the specified object.
 489.710 +     * This method is equivalent to
 489.711 +     * {@code set(obj, cObj)},
 489.712 +     * where {@code cObj} is a {@code Character} object and
 489.713 +     * {@code cObj.charValue() == c}.
 489.714 +     *
 489.715 +     * @param obj the object whose field should be modified
 489.716 +     * @param c   the new value for the field of {@code obj}
 489.717 +     * being modified
 489.718 +     *
 489.719 +     * @exception IllegalAccessException    if this {@code Field} object
 489.720 +     *              is enforcing Java language access control and the underlying
 489.721 +     *              field is either inaccessible or final.
 489.722 +     * @exception IllegalArgumentException  if the specified object is not an
 489.723 +     *              instance of the class or interface declaring the underlying
 489.724 +     *              field (or a subclass or implementor thereof),
 489.725 +     *              or if an unwrapping conversion fails.
 489.726 +     * @exception NullPointerException      if the specified object is null
 489.727 +     *              and the field is an instance field.
 489.728 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.729 +     *              by this method fails.
 489.730 +     * @see       Field#set
 489.731 +     */
 489.732 +    public void setChar(Object obj, char c)
 489.733 +        throws IllegalArgumentException, IllegalAccessException
 489.734 +    {
 489.735 +        getFieldAccessor(obj).setChar(obj, c);
 489.736 +    }
 489.737 +
 489.738 +    /**
 489.739 +     * Sets the value of a field as a {@code short} on the specified object.
 489.740 +     * This method is equivalent to
 489.741 +     * {@code set(obj, sObj)},
 489.742 +     * where {@code sObj} is a {@code Short} object and
 489.743 +     * {@code sObj.shortValue() == s}.
 489.744 +     *
 489.745 +     * @param obj the object whose field should be modified
 489.746 +     * @param s   the new value for the field of {@code obj}
 489.747 +     * being modified
 489.748 +     *
 489.749 +     * @exception IllegalAccessException    if this {@code Field} object
 489.750 +     *              is enforcing Java language access control and the underlying
 489.751 +     *              field is either inaccessible or final.
 489.752 +     * @exception IllegalArgumentException  if the specified object is not an
 489.753 +     *              instance of the class or interface declaring the underlying
 489.754 +     *              field (or a subclass or implementor thereof),
 489.755 +     *              or if an unwrapping conversion fails.
 489.756 +     * @exception NullPointerException      if the specified object is null
 489.757 +     *              and the field is an instance field.
 489.758 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.759 +     *              by this method fails.
 489.760 +     * @see       Field#set
 489.761 +     */
 489.762 +    public void setShort(Object obj, short s)
 489.763 +        throws IllegalArgumentException, IllegalAccessException
 489.764 +    {
 489.765 +        getFieldAccessor(obj).setShort(obj, s);
 489.766 +    }
 489.767 +
 489.768 +    /**
 489.769 +     * Sets the value of a field as an {@code int} on the specified object.
 489.770 +     * This method is equivalent to
 489.771 +     * {@code set(obj, iObj)},
 489.772 +     * where {@code iObj} is a {@code Integer} object and
 489.773 +     * {@code iObj.intValue() == i}.
 489.774 +     *
 489.775 +     * @param obj the object whose field should be modified
 489.776 +     * @param i   the new value for the field of {@code obj}
 489.777 +     * being modified
 489.778 +     *
 489.779 +     * @exception IllegalAccessException    if this {@code Field} object
 489.780 +     *              is enforcing Java language access control and the underlying
 489.781 +     *              field is either inaccessible or final.
 489.782 +     * @exception IllegalArgumentException  if the specified object is not an
 489.783 +     *              instance of the class or interface declaring the underlying
 489.784 +     *              field (or a subclass or implementor thereof),
 489.785 +     *              or if an unwrapping conversion fails.
 489.786 +     * @exception NullPointerException      if the specified object is null
 489.787 +     *              and the field is an instance field.
 489.788 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.789 +     *              by this method fails.
 489.790 +     * @see       Field#set
 489.791 +     */
 489.792 +    public void setInt(Object obj, int i)
 489.793 +        throws IllegalArgumentException, IllegalAccessException
 489.794 +    {
 489.795 +        getFieldAccessor(obj).setInt(obj, i);
 489.796 +    }
 489.797 +
 489.798 +    /**
 489.799 +     * Sets the value of a field as a {@code long} on the specified object.
 489.800 +     * This method is equivalent to
 489.801 +     * {@code set(obj, lObj)},
 489.802 +     * where {@code lObj} is a {@code Long} object and
 489.803 +     * {@code lObj.longValue() == l}.
 489.804 +     *
 489.805 +     * @param obj the object whose field should be modified
 489.806 +     * @param l   the new value for the field of {@code obj}
 489.807 +     * being modified
 489.808 +     *
 489.809 +     * @exception IllegalAccessException    if this {@code Field} object
 489.810 +     *              is enforcing Java language access control and the underlying
 489.811 +     *              field is either inaccessible or final.
 489.812 +     * @exception IllegalArgumentException  if the specified object is not an
 489.813 +     *              instance of the class or interface declaring the underlying
 489.814 +     *              field (or a subclass or implementor thereof),
 489.815 +     *              or if an unwrapping conversion fails.
 489.816 +     * @exception NullPointerException      if the specified object is null
 489.817 +     *              and the field is an instance field.
 489.818 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.819 +     *              by this method fails.
 489.820 +     * @see       Field#set
 489.821 +     */
 489.822 +    public void setLong(Object obj, long l)
 489.823 +        throws IllegalArgumentException, IllegalAccessException
 489.824 +    {
 489.825 +        getFieldAccessor(obj).setLong(obj, l);
 489.826 +    }
 489.827 +
 489.828 +    /**
 489.829 +     * Sets the value of a field as a {@code float} on the specified object.
 489.830 +     * This method is equivalent to
 489.831 +     * {@code set(obj, fObj)},
 489.832 +     * where {@code fObj} is a {@code Float} object and
 489.833 +     * {@code fObj.floatValue() == f}.
 489.834 +     *
 489.835 +     * @param obj the object whose field should be modified
 489.836 +     * @param f   the new value for the field of {@code obj}
 489.837 +     * being modified
 489.838 +     *
 489.839 +     * @exception IllegalAccessException    if this {@code Field} object
 489.840 +     *              is enforcing Java language access control and the underlying
 489.841 +     *              field is either inaccessible or final.
 489.842 +     * @exception IllegalArgumentException  if the specified object is not an
 489.843 +     *              instance of the class or interface declaring the underlying
 489.844 +     *              field (or a subclass or implementor thereof),
 489.845 +     *              or if an unwrapping conversion fails.
 489.846 +     * @exception NullPointerException      if the specified object is null
 489.847 +     *              and the field is an instance field.
 489.848 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.849 +     *              by this method fails.
 489.850 +     * @see       Field#set
 489.851 +     */
 489.852 +    public void setFloat(Object obj, float f)
 489.853 +        throws IllegalArgumentException, IllegalAccessException
 489.854 +    {
 489.855 +        getFieldAccessor(obj).setFloat(obj, f);
 489.856 +    }
 489.857 +
 489.858 +    /**
 489.859 +     * Sets the value of a field as a {@code double} on the specified object.
 489.860 +     * This method is equivalent to
 489.861 +     * {@code set(obj, dObj)},
 489.862 +     * where {@code dObj} is a {@code Double} object and
 489.863 +     * {@code dObj.doubleValue() == d}.
 489.864 +     *
 489.865 +     * @param obj the object whose field should be modified
 489.866 +     * @param d   the new value for the field of {@code obj}
 489.867 +     * being modified
 489.868 +     *
 489.869 +     * @exception IllegalAccessException    if this {@code Field} object
 489.870 +     *              is enforcing Java language access control and the underlying
 489.871 +     *              field is either inaccessible or final.
 489.872 +     * @exception IllegalArgumentException  if the specified object is not an
 489.873 +     *              instance of the class or interface declaring the underlying
 489.874 +     *              field (or a subclass or implementor thereof),
 489.875 +     *              or if an unwrapping conversion fails.
 489.876 +     * @exception NullPointerException      if the specified object is null
 489.877 +     *              and the field is an instance field.
 489.878 +     * @exception ExceptionInInitializerError if the initialization provoked
 489.879 +     *              by this method fails.
 489.880 +     * @see       Field#set
 489.881 +     */
 489.882 +    public void setDouble(Object obj, double d)
 489.883 +        throws IllegalArgumentException, IllegalAccessException
 489.884 +    {
 489.885 +        getFieldAccessor(obj).setDouble(obj, d);
 489.886 +    }
 489.887 +
 489.888 +    // Convenience routine which performs security checks
 489.889 +    private FieldAccessor getFieldAccessor(Object obj)
 489.890 +        throws IllegalAccessException
 489.891 +    {
 489.892 +        throw new SecurityException();
 489.893 +    }
 489.894 +    
 489.895 +    private static abstract class FieldAccessor {
 489.896 +        abstract void setShort(Object obj, short s);
 489.897 +        abstract void setInt(Object obj, int i);
 489.898 +        abstract void setChar(Object obj, char c);
 489.899 +        abstract void setByte(Object obj, byte b);
 489.900 +        abstract void setBoolean(Object obj, boolean z);
 489.901 +        abstract void set(Object obj, Object value);
 489.902 +        abstract double getDouble(Object obj);
 489.903 +        abstract void setLong(Object obj, long l);
 489.904 +        abstract void setFloat(Object obj, float f);
 489.905 +        abstract void setDouble(Object obj, double d);
 489.906 +        abstract long getLong(Object obj);
 489.907 +        abstract int getInt(Object obj);
 489.908 +        abstract short getShort(Object obj);
 489.909 +        abstract char getChar(Object obj);
 489.910 +        abstract byte getByte(Object obj);
 489.911 +        abstract boolean getBoolean(Object obj);
 489.912 +        abstract Object get(Object obj);
 489.913 +        abstract float getFloat(Object obj);
 489.914 +    }
 489.915 +
 489.916 +    /*
 489.917 +     * Utility routine to paper over array type names
 489.918 +     */
 489.919 +    static String getTypeName(Class<?> type) {
 489.920 +        if (type.isArray()) {
 489.921 +            try {
 489.922 +                Class<?> cl = type;
 489.923 +                int dimensions = 0;
 489.924 +                while (cl.isArray()) {
 489.925 +                    dimensions++;
 489.926 +                    cl = cl.getComponentType();
 489.927 +                }
 489.928 +                StringBuffer sb = new StringBuffer();
 489.929 +                sb.append(cl.getName());
 489.930 +                for (int i = 0; i < dimensions; i++) {
 489.931 +                    sb.append("[]");
 489.932 +                }
 489.933 +                return sb.toString();
 489.934 +            } catch (Throwable e) { /*FALLTHRU*/ }
 489.935 +        }
 489.936 +        return type.getName();
 489.937 +    }
 489.938 +
 489.939 +    /**
 489.940 +     * @throws NullPointerException {@inheritDoc}
 489.941 +     * @since 1.5
 489.942 +     */
 489.943 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 489.944 +        if (annotationClass == null)
 489.945 +            throw new NullPointerException();
 489.946 +
 489.947 +        throw new UnsupportedOperationException();
 489.948 +    }
 489.949 +
 489.950 +    /**
 489.951 +     * @since 1.5
 489.952 +     */
 489.953 +    public Annotation[] getDeclaredAnnotations()  {
 489.954 +        throw new UnsupportedOperationException();
 489.955 +    }
 489.956 +}
   490.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   490.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/GenericDeclaration.java	Wed Feb 27 11:24:58 2013 +0100
   490.3 @@ -0,0 +1,49 @@
   490.4 +/*
   490.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   490.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   490.7 + *
   490.8 + * This code is free software; you can redistribute it and/or modify it
   490.9 + * under the terms of the GNU General Public License version 2 only, as
  490.10 + * published by the Free Software Foundation.  Oracle designates this
  490.11 + * particular file as subject to the "Classpath" exception as provided
  490.12 + * by Oracle in the LICENSE file that accompanied this code.
  490.13 + *
  490.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  490.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  490.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  490.17 + * version 2 for more details (a copy is included in the LICENSE file that
  490.18 + * accompanied this code).
  490.19 + *
  490.20 + * You should have received a copy of the GNU General Public License version
  490.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  490.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  490.23 + *
  490.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  490.25 + * or visit www.oracle.com if you need additional information or have any
  490.26 + * questions.
  490.27 + */
  490.28 +
  490.29 +package java.lang.reflect;
  490.30 +
  490.31 +/**
  490.32 + * A common interface for all entities that declare type variables.
  490.33 + *
  490.34 + * @since 1.5
  490.35 + */
  490.36 +public interface GenericDeclaration {
  490.37 +    /**
  490.38 +     * Returns an array of {@code TypeVariable} objects that
  490.39 +     * represent the type variables declared by the generic
  490.40 +     * declaration represented by this {@code GenericDeclaration}
  490.41 +     * object, in declaration order.  Returns an array of length 0 if
  490.42 +     * the underlying generic declaration declares no type variables.
  490.43 +     *
  490.44 +     * @return an array of {@code TypeVariable} objects that represent
  490.45 +     *     the type variables declared by this generic declaration
  490.46 +     * @throws GenericSignatureFormatError if the generic
  490.47 +     *     signature of this generic declaration does not conform to
  490.48 +     *     the format specified in
  490.49 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
  490.50 +     */
  490.51 +    public TypeVariable<?>[] getTypeParameters();
  490.52 +}
   491.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   491.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/InvocationHandler.java	Wed Feb 27 11:24:58 2013 +0100
   491.3 @@ -0,0 +1,95 @@
   491.4 +/*
   491.5 + * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
   491.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   491.7 + *
   491.8 + * This code is free software; you can redistribute it and/or modify it
   491.9 + * under the terms of the GNU General Public License version 2 only, as
  491.10 + * published by the Free Software Foundation.  Oracle designates this
  491.11 + * particular file as subject to the "Classpath" exception as provided
  491.12 + * by Oracle in the LICENSE file that accompanied this code.
  491.13 + *
  491.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  491.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  491.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  491.17 + * version 2 for more details (a copy is included in the LICENSE file that
  491.18 + * accompanied this code).
  491.19 + *
  491.20 + * You should have received a copy of the GNU General Public License version
  491.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  491.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  491.23 + *
  491.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  491.25 + * or visit www.oracle.com if you need additional information or have any
  491.26 + * questions.
  491.27 + */
  491.28 +
  491.29 +package java.lang.reflect;
  491.30 +
  491.31 +/**
  491.32 + * {@code InvocationHandler} is the interface implemented by
  491.33 + * the <i>invocation handler</i> of a proxy instance.
  491.34 + *
  491.35 + * <p>Each proxy instance has an associated invocation handler.
  491.36 + * When a method is invoked on a proxy instance, the method
  491.37 + * invocation is encoded and dispatched to the {@code invoke}
  491.38 + * method of its invocation handler.
  491.39 + *
  491.40 + * @author      Peter Jones
  491.41 + * @see         Proxy
  491.42 + * @since       1.3
  491.43 + */
  491.44 +public interface InvocationHandler {
  491.45 +
  491.46 +    /**
  491.47 +     * Processes a method invocation on a proxy instance and returns
  491.48 +     * the result.  This method will be invoked on an invocation handler
  491.49 +     * when a method is invoked on a proxy instance that it is
  491.50 +     * associated with.
  491.51 +     *
  491.52 +     * @param   proxy the proxy instance that the method was invoked on
  491.53 +     *
  491.54 +     * @param   method the {@code Method} instance corresponding to
  491.55 +     * the interface method invoked on the proxy instance.  The declaring
  491.56 +     * class of the {@code Method} object will be the interface that
  491.57 +     * the method was declared in, which may be a superinterface of the
  491.58 +     * proxy interface that the proxy class inherits the method through.
  491.59 +     *
  491.60 +     * @param   args an array of objects containing the values of the
  491.61 +     * arguments passed in the method invocation on the proxy instance,
  491.62 +     * or {@code null} if interface method takes no arguments.
  491.63 +     * Arguments of primitive types are wrapped in instances of the
  491.64 +     * appropriate primitive wrapper class, such as
  491.65 +     * {@code java.lang.Integer} or {@code java.lang.Boolean}.
  491.66 +     *
  491.67 +     * @return  the value to return from the method invocation on the
  491.68 +     * proxy instance.  If the declared return type of the interface
  491.69 +     * method is a primitive type, then the value returned by
  491.70 +     * this method must be an instance of the corresponding primitive
  491.71 +     * wrapper class; otherwise, it must be a type assignable to the
  491.72 +     * declared return type.  If the value returned by this method is
  491.73 +     * {@code null} and the interface method's return type is
  491.74 +     * primitive, then a {@code NullPointerException} will be
  491.75 +     * thrown by the method invocation on the proxy instance.  If the
  491.76 +     * value returned by this method is otherwise not compatible with
  491.77 +     * the interface method's declared return type as described above,
  491.78 +     * a {@code ClassCastException} will be thrown by the method
  491.79 +     * invocation on the proxy instance.
  491.80 +     *
  491.81 +     * @throws  Throwable the exception to throw from the method
  491.82 +     * invocation on the proxy instance.  The exception's type must be
  491.83 +     * assignable either to any of the exception types declared in the
  491.84 +     * {@code throws} clause of the interface method or to the
  491.85 +     * unchecked exception types {@code java.lang.RuntimeException}
  491.86 +     * or {@code java.lang.Error}.  If a checked exception is
  491.87 +     * thrown by this method that is not assignable to any of the
  491.88 +     * exception types declared in the {@code throws} clause of
  491.89 +     * the interface method, then an
  491.90 +     * {@link UndeclaredThrowableException} containing the
  491.91 +     * exception that was thrown by this method will be thrown by the
  491.92 +     * method invocation on the proxy instance.
  491.93 +     *
  491.94 +     * @see     UndeclaredThrowableException
  491.95 +     */
  491.96 +    public Object invoke(Object proxy, Method method, Object[] args)
  491.97 +        throws Throwable;
  491.98 +}
   492.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   492.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/InvocationTargetException.java	Wed Feb 27 11:24:58 2013 +0100
   492.3 @@ -0,0 +1,111 @@
   492.4 +/*
   492.5 + * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
   492.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   492.7 + *
   492.8 + * This code is free software; you can redistribute it and/or modify it
   492.9 + * under the terms of the GNU General Public License version 2 only, as
  492.10 + * published by the Free Software Foundation.  Oracle designates this
  492.11 + * particular file as subject to the "Classpath" exception as provided
  492.12 + * by Oracle in the LICENSE file that accompanied this code.
  492.13 + *
  492.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  492.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  492.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  492.17 + * version 2 for more details (a copy is included in the LICENSE file that
  492.18 + * accompanied this code).
  492.19 + *
  492.20 + * You should have received a copy of the GNU General Public License version
  492.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  492.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  492.23 + *
  492.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  492.25 + * or visit www.oracle.com if you need additional information or have any
  492.26 + * questions.
  492.27 + */
  492.28 +
  492.29 +package java.lang.reflect;
  492.30 +
  492.31 +/**
  492.32 + * InvocationTargetException is a checked exception that wraps
  492.33 + * an exception thrown by an invoked method or constructor.
  492.34 + *
  492.35 + * <p>As of release 1.4, this exception has been retrofitted to conform to
  492.36 + * the general purpose exception-chaining mechanism.  The "target exception"
  492.37 + * that is provided at construction time and accessed via the
  492.38 + * {@link #getTargetException()} method is now known as the <i>cause</i>,
  492.39 + * and may be accessed via the {@link Throwable#getCause()} method,
  492.40 + * as well as the aforementioned "legacy method."
  492.41 + *
  492.42 + * @see Method
  492.43 + * @see Constructor
  492.44 + */
  492.45 +public class InvocationTargetException extends ReflectiveOperationException {
  492.46 +    /**
  492.47 +     * Use serialVersionUID from JDK 1.1.X for interoperability
  492.48 +     */
  492.49 +    private static final long serialVersionUID = 4085088731926701167L;
  492.50 +
  492.51 +     /**
  492.52 +     * This field holds the target if the
  492.53 +     * InvocationTargetException(Throwable target) constructor was
  492.54 +     * used to instantiate the object
  492.55 +     *
  492.56 +     * @serial
  492.57 +     *
  492.58 +     */
  492.59 +    private Throwable target;
  492.60 +
  492.61 +    /**
  492.62 +     * Constructs an {@code InvocationTargetException} with
  492.63 +     * {@code null} as the target exception.
  492.64 +     */
  492.65 +    protected InvocationTargetException() {
  492.66 +        super((Throwable)null);  // Disallow initCause
  492.67 +    }
  492.68 +
  492.69 +    /**
  492.70 +     * Constructs a InvocationTargetException with a target exception.
  492.71 +     *
  492.72 +     * @param target the target exception
  492.73 +     */
  492.74 +    public InvocationTargetException(Throwable target) {
  492.75 +        super((Throwable)null);  // Disallow initCause
  492.76 +        this.target = target;
  492.77 +    }
  492.78 +
  492.79 +    /**
  492.80 +     * Constructs a InvocationTargetException with a target exception
  492.81 +     * and a detail message.
  492.82 +     *
  492.83 +     * @param target the target exception
  492.84 +     * @param s      the detail message
  492.85 +     */
  492.86 +    public InvocationTargetException(Throwable target, String s) {
  492.87 +        super(s, null);  // Disallow initCause
  492.88 +        this.target = target;
  492.89 +    }
  492.90 +
  492.91 +    /**
  492.92 +     * Get the thrown target exception.
  492.93 +     *
  492.94 +     * <p>This method predates the general-purpose exception chaining facility.
  492.95 +     * The {@link Throwable#getCause()} method is now the preferred means of
  492.96 +     * obtaining this information.
  492.97 +     *
  492.98 +     * @return the thrown target exception (cause of this exception).
  492.99 +     */
 492.100 +    public Throwable getTargetException() {
 492.101 +        return target;
 492.102 +    }
 492.103 +
 492.104 +    /**
 492.105 +     * Returns the cause of this exception (the thrown target exception,
 492.106 +     * which may be {@code null}).
 492.107 +     *
 492.108 +     * @return  the cause of this exception.
 492.109 +     * @since   1.4
 492.110 +     */
 492.111 +    public Throwable getCause() {
 492.112 +        return target;
 492.113 +    }
 492.114 +}
   493.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   493.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Member.java	Wed Feb 27 11:24:58 2013 +0100
   493.3 @@ -0,0 +1,93 @@
   493.4 +/*
   493.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   493.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   493.7 + *
   493.8 + * This code is free software; you can redistribute it and/or modify it
   493.9 + * under the terms of the GNU General Public License version 2 only, as
  493.10 + * published by the Free Software Foundation.  Oracle designates this
  493.11 + * particular file as subject to the "Classpath" exception as provided
  493.12 + * by Oracle in the LICENSE file that accompanied this code.
  493.13 + *
  493.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  493.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  493.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  493.17 + * version 2 for more details (a copy is included in the LICENSE file that
  493.18 + * accompanied this code).
  493.19 + *
  493.20 + * You should have received a copy of the GNU General Public License version
  493.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  493.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  493.23 + *
  493.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  493.25 + * or visit www.oracle.com if you need additional information or have any
  493.26 + * questions.
  493.27 + */
  493.28 +
  493.29 +package java.lang.reflect;
  493.30 +
  493.31 +/**
  493.32 + * Member is an interface that reflects identifying information about
  493.33 + * a single member (a field or a method) or a constructor.
  493.34 + *
  493.35 + * @see java.lang.Class
  493.36 + * @see Field
  493.37 + * @see Method
  493.38 + * @see Constructor
  493.39 + *
  493.40 + * @author Nakul Saraiya
  493.41 + */
  493.42 +public
  493.43 +interface Member {
  493.44 +
  493.45 +    /**
  493.46 +     * Identifies the set of all public members of a class or interface,
  493.47 +     * including inherited members.
  493.48 +     * @see java.lang.SecurityManager#checkMemberAccess
  493.49 +     */
  493.50 +    public static final int PUBLIC = 0;
  493.51 +
  493.52 +    /**
  493.53 +     * Identifies the set of declared members of a class or interface.
  493.54 +     * Inherited members are not included.
  493.55 +     * @see java.lang.SecurityManager#checkMemberAccess
  493.56 +     */
  493.57 +    public static final int DECLARED = 1;
  493.58 +
  493.59 +    /**
  493.60 +     * Returns the Class object representing the class or interface
  493.61 +     * that declares the member or constructor represented by this Member.
  493.62 +     *
  493.63 +     * @return an object representing the declaring class of the
  493.64 +     * underlying member
  493.65 +     */
  493.66 +    public Class<?> getDeclaringClass();
  493.67 +
  493.68 +    /**
  493.69 +     * Returns the simple name of the underlying member or constructor
  493.70 +     * represented by this Member.
  493.71 +     *
  493.72 +     * @return the simple name of the underlying member
  493.73 +     */
  493.74 +    public String getName();
  493.75 +
  493.76 +    /**
  493.77 +     * Returns the Java language modifiers for the member or
  493.78 +     * constructor represented by this Member, as an integer.  The
  493.79 +     * Modifier class should be used to decode the modifiers in
  493.80 +     * the integer.
  493.81 +     *
  493.82 +     * @return the Java language modifiers for the underlying member
  493.83 +     * @see Modifier
  493.84 +     */
  493.85 +    public int getModifiers();
  493.86 +
  493.87 +    /**
  493.88 +     * Returns {@code true} if this member was introduced by
  493.89 +     * the compiler; returns {@code false} otherwise.
  493.90 +     *
  493.91 +     * @return true if and only if this member was introduced by
  493.92 +     * the compiler.
  493.93 +     * @since 1.5
  493.94 +     */
  493.95 +    public boolean isSynthetic();
  493.96 +}
   494.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   494.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Method.java	Wed Feb 27 11:24:58 2013 +0100
   494.3 @@ -0,0 +1,721 @@
   494.4 +/*
   494.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   494.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   494.7 + *
   494.8 + * This code is free software; you can redistribute it and/or modify it
   494.9 + * under the terms of the GNU General Public License version 2 only, as
  494.10 + * published by the Free Software Foundation.  Oracle designates this
  494.11 + * particular file as subject to the "Classpath" exception as provided
  494.12 + * by Oracle in the LICENSE file that accompanied this code.
  494.13 + *
  494.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  494.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  494.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  494.17 + * version 2 for more details (a copy is included in the LICENSE file that
  494.18 + * accompanied this code).
  494.19 + *
  494.20 + * You should have received a copy of the GNU General Public License version
  494.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  494.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  494.23 + *
  494.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  494.25 + * or visit www.oracle.com if you need additional information or have any
  494.26 + * questions.
  494.27 + */
  494.28 +
  494.29 +package java.lang.reflect;
  494.30 +
  494.31 +import java.lang.annotation.Annotation;
  494.32 +import java.util.Enumeration;
  494.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  494.34 +import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
  494.35 +import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
  494.36 +
  494.37 +/**
  494.38 + * A {@code Method} provides information about, and access to, a single method
  494.39 + * on a class or interface.  The reflected method may be a class method
  494.40 + * or an instance method (including an abstract method).
  494.41 + *
  494.42 + * <p>A {@code Method} permits widening conversions to occur when matching the
  494.43 + * actual parameters to invoke with the underlying method's formal
  494.44 + * parameters, but it throws an {@code IllegalArgumentException} if a
  494.45 + * narrowing conversion would occur.
  494.46 + *
  494.47 + * @see Member
  494.48 + * @see java.lang.Class
  494.49 + * @see java.lang.Class#getMethods()
  494.50 + * @see java.lang.Class#getMethod(String, Class[])
  494.51 + * @see java.lang.Class#getDeclaredMethods()
  494.52 + * @see java.lang.Class#getDeclaredMethod(String, Class[])
  494.53 + *
  494.54 + * @author Kenneth Russell
  494.55 + * @author Nakul Saraiya
  494.56 + */
  494.57 +public final
  494.58 +    class Method extends AccessibleObject implements GenericDeclaration,
  494.59 +                                                     Member {
  494.60 +    private final Class<?> clazz;
  494.61 +    private final String name;
  494.62 +    private final Object data;
  494.63 +    private final String sig;
  494.64 +
  494.65 +   // Generics infrastructure
  494.66 +
  494.67 +    private String getGenericSignature() {return null;}
  494.68 +
  494.69 +    /**
  494.70 +     * Package-private constructor used by ReflectAccess to enable
  494.71 +     * instantiation of these objects in Java code from the java.lang
  494.72 +     * package via sun.reflect.LangReflectAccess.
  494.73 +     */
  494.74 +    Method(Class<?> declaringClass, String name, Object data, String sig)
  494.75 +    {
  494.76 +        this.clazz = declaringClass;
  494.77 +        this.name = name;
  494.78 +        this.data = data;
  494.79 +        this.sig = sig;
  494.80 +    }
  494.81 +
  494.82 +    /**
  494.83 +     * Package-private routine (exposed to java.lang.Class via
  494.84 +     * ReflectAccess) which returns a copy of this Method. The copy's
  494.85 +     * "root" field points to this Method.
  494.86 +     */
  494.87 +    Method copy() {
  494.88 +        return this;
  494.89 +    }
  494.90 +
  494.91 +    /**
  494.92 +     * Returns the {@code Class} object representing the class or interface
  494.93 +     * that declares the method represented by this {@code Method} object.
  494.94 +     */
  494.95 +    public Class<?> getDeclaringClass() {
  494.96 +        return clazz;
  494.97 +    }
  494.98 +
  494.99 +    /**
 494.100 +     * Returns the name of the method represented by this {@code Method}
 494.101 +     * object, as a {@code String}.
 494.102 +     */
 494.103 +    public String getName() {
 494.104 +        return name;
 494.105 +    }
 494.106 +
 494.107 +    /**
 494.108 +     * Returns the Java language modifiers for the method represented
 494.109 +     * by this {@code Method} object, as an integer. The {@code Modifier} class should
 494.110 +     * be used to decode the modifiers.
 494.111 +     *
 494.112 +     * @see Modifier
 494.113 +     */
 494.114 +    public int getModifiers() {
 494.115 +        return getAccess(data);
 494.116 +    }
 494.117 +    
 494.118 +    @JavaScriptBody(args = "self", body = "return self.access;")
 494.119 +    private static native int getAccess(Object self);
 494.120 +    
 494.121 +    /**
 494.122 +     * Returns an array of {@code TypeVariable} objects that represent the
 494.123 +     * type variables declared by the generic declaration represented by this
 494.124 +     * {@code GenericDeclaration} object, in declaration order.  Returns an
 494.125 +     * array of length 0 if the underlying generic declaration declares no type
 494.126 +     * variables.
 494.127 +     *
 494.128 +     * @return an array of {@code TypeVariable} objects that represent
 494.129 +     *     the type variables declared by this generic declaration
 494.130 +     * @throws GenericSignatureFormatError if the generic
 494.131 +     *     signature of this generic declaration does not conform to
 494.132 +     *     the format specified in
 494.133 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 494.134 +     * @since 1.5
 494.135 +     */
 494.136 +    public TypeVariable<Method>[] getTypeParameters() {
 494.137 +        throw new UnsupportedOperationException();
 494.138 +    }
 494.139 +
 494.140 +    /**
 494.141 +     * Returns a {@code Class} object that represents the formal return type
 494.142 +     * of the method represented by this {@code Method} object.
 494.143 +     *
 494.144 +     * @return the return type for the method this object represents
 494.145 +     */
 494.146 +    public Class<?> getReturnType() {
 494.147 +        return MethodImpl.signatureParser(sig).nextElement();
 494.148 +    }
 494.149 +
 494.150 +    /**
 494.151 +     * Returns a {@code Type} object that represents the formal return
 494.152 +     * type of the method represented by this {@code Method} object.
 494.153 +     *
 494.154 +     * <p>If the return type is a parameterized type,
 494.155 +     * the {@code Type} object returned must accurately reflect
 494.156 +     * the actual type parameters used in the source code.
 494.157 +     *
 494.158 +     * <p>If the return type is a type variable or a parameterized type, it
 494.159 +     * is created. Otherwise, it is resolved.
 494.160 +     *
 494.161 +     * @return  a {@code Type} object that represents the formal return
 494.162 +     *     type of the underlying  method
 494.163 +     * @throws GenericSignatureFormatError
 494.164 +     *     if the generic method signature does not conform to the format
 494.165 +     *     specified in
 494.166 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 494.167 +     * @throws TypeNotPresentException if the underlying method's
 494.168 +     *     return type refers to a non-existent type declaration
 494.169 +     * @throws MalformedParameterizedTypeException if the
 494.170 +     *     underlying method's return typed refers to a parameterized
 494.171 +     *     type that cannot be instantiated for any reason
 494.172 +     * @since 1.5
 494.173 +     */
 494.174 +    public Type getGenericReturnType() {
 494.175 +        throw new UnsupportedOperationException();
 494.176 +    }
 494.177 +
 494.178 +
 494.179 +    /**
 494.180 +     * Returns an array of {@code Class} objects that represent the formal
 494.181 +     * parameter types, in declaration order, of the method
 494.182 +     * represented by this {@code Method} object.  Returns an array of length
 494.183 +     * 0 if the underlying method takes no parameters.
 494.184 +     *
 494.185 +     * @return the parameter types for the method this object
 494.186 +     * represents
 494.187 +     */
 494.188 +    public Class<?>[] getParameterTypes() {
 494.189 +        Class[] arr = new Class[MethodImpl.signatureElements(sig) - 1];
 494.190 +        Enumeration<Class> en = MethodImpl.signatureParser(sig);
 494.191 +        en.nextElement(); // return type
 494.192 +        for (int i = 0; i < arr.length; i++) {
 494.193 +            arr[i] = en.nextElement();
 494.194 +        }
 494.195 +        return arr;
 494.196 +    }
 494.197 +
 494.198 +    /**
 494.199 +     * Returns an array of {@code Type} objects that represent the formal
 494.200 +     * parameter types, in declaration order, of the method represented by
 494.201 +     * this {@code Method} object. Returns an array of length 0 if the
 494.202 +     * underlying method takes no parameters.
 494.203 +     *
 494.204 +     * <p>If a formal parameter type is a parameterized type,
 494.205 +     * the {@code Type} object returned for it must accurately reflect
 494.206 +     * the actual type parameters used in the source code.
 494.207 +     *
 494.208 +     * <p>If a formal parameter type is a type variable or a parameterized
 494.209 +     * type, it is created. Otherwise, it is resolved.
 494.210 +     *
 494.211 +     * @return an array of Types that represent the formal
 494.212 +     *     parameter types of the underlying method, in declaration order
 494.213 +     * @throws GenericSignatureFormatError
 494.214 +     *     if the generic method signature does not conform to the format
 494.215 +     *     specified in
 494.216 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 494.217 +     * @throws TypeNotPresentException if any of the parameter
 494.218 +     *     types of the underlying method refers to a non-existent type
 494.219 +     *     declaration
 494.220 +     * @throws MalformedParameterizedTypeException if any of
 494.221 +     *     the underlying method's parameter types refer to a parameterized
 494.222 +     *     type that cannot be instantiated for any reason
 494.223 +     * @since 1.5
 494.224 +     */
 494.225 +    public Type[] getGenericParameterTypes() {
 494.226 +        throw new UnsupportedOperationException();
 494.227 +    }
 494.228 +
 494.229 +
 494.230 +    /**
 494.231 +     * Returns an array of {@code Class} objects that represent
 494.232 +     * the types of the exceptions declared to be thrown
 494.233 +     * by the underlying method
 494.234 +     * represented by this {@code Method} object.  Returns an array of length
 494.235 +     * 0 if the method declares no exceptions in its {@code throws} clause.
 494.236 +     *
 494.237 +     * @return the exception types declared as being thrown by the
 494.238 +     * method this object represents
 494.239 +     */
 494.240 +    public Class<?>[] getExceptionTypes() {
 494.241 +        throw new UnsupportedOperationException();
 494.242 +        //return (Class<?>[]) exceptionTypes.clone();
 494.243 +    }
 494.244 +
 494.245 +    /**
 494.246 +     * Returns an array of {@code Type} objects that represent the
 494.247 +     * exceptions declared to be thrown by this {@code Method} object.
 494.248 +     * Returns an array of length 0 if the underlying method declares
 494.249 +     * no exceptions in its {@code throws} clause.
 494.250 +     *
 494.251 +     * <p>If an exception type is a type variable or a parameterized
 494.252 +     * type, it is created. Otherwise, it is resolved.
 494.253 +     *
 494.254 +     * @return an array of Types that represent the exception types
 494.255 +     *     thrown by the underlying method
 494.256 +     * @throws GenericSignatureFormatError
 494.257 +     *     if the generic method signature does not conform to the format
 494.258 +     *     specified in
 494.259 +     *     <cite>The Java&trade; Virtual Machine Specification</cite>
 494.260 +     * @throws TypeNotPresentException if the underlying method's
 494.261 +     *     {@code throws} clause refers to a non-existent type declaration
 494.262 +     * @throws MalformedParameterizedTypeException if
 494.263 +     *     the underlying method's {@code throws} clause refers to a
 494.264 +     *     parameterized type that cannot be instantiated for any reason
 494.265 +     * @since 1.5
 494.266 +     */
 494.267 +      public Type[] getGenericExceptionTypes() {
 494.268 +        throw new UnsupportedOperationException();
 494.269 +      }
 494.270 +
 494.271 +    /**
 494.272 +     * Compares this {@code Method} against the specified object.  Returns
 494.273 +     * true if the objects are the same.  Two {@code Methods} are the same if
 494.274 +     * they were declared by the same class and have the same name
 494.275 +     * and formal parameter types and return type.
 494.276 +     */
 494.277 +    public boolean equals(Object obj) {
 494.278 +        if (obj != null && obj instanceof Method) {
 494.279 +            Method other = (Method)obj;
 494.280 +            return data == other.data;
 494.281 +        }
 494.282 +        return false;
 494.283 +    }
 494.284 +
 494.285 +    /**
 494.286 +     * Returns a hashcode for this {@code Method}.  The hashcode is computed
 494.287 +     * as the exclusive-or of the hashcodes for the underlying
 494.288 +     * method's declaring class name and the method's name.
 494.289 +     */
 494.290 +    public int hashCode() {
 494.291 +        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 494.292 +    }
 494.293 +
 494.294 +    /**
 494.295 +     * Returns a string describing this {@code Method}.  The string is
 494.296 +     * formatted as the method access modifiers, if any, followed by
 494.297 +     * the method return type, followed by a space, followed by the
 494.298 +     * class declaring the method, followed by a period, followed by
 494.299 +     * the method name, followed by a parenthesized, comma-separated
 494.300 +     * list of the method's formal parameter types. If the method
 494.301 +     * throws checked exceptions, the parameter list is followed by a
 494.302 +     * space, followed by the word throws followed by a
 494.303 +     * comma-separated list of the thrown exception types.
 494.304 +     * For example:
 494.305 +     * <pre>
 494.306 +     *    public boolean java.lang.Object.equals(java.lang.Object)
 494.307 +     * </pre>
 494.308 +     *
 494.309 +     * <p>The access modifiers are placed in canonical order as
 494.310 +     * specified by "The Java Language Specification".  This is
 494.311 +     * {@code public}, {@code protected} or {@code private} first,
 494.312 +     * and then other modifiers in the following order:
 494.313 +     * {@code abstract}, {@code static}, {@code final},
 494.314 +     * {@code synchronized}, {@code native}, {@code strictfp}.
 494.315 +     */
 494.316 +    public String toString() {
 494.317 +        try {
 494.318 +            StringBuilder sb = new StringBuilder();
 494.319 +            int mod = getModifiers() & Modifier.methodModifiers();
 494.320 +            if (mod != 0) {
 494.321 +                sb.append(Modifier.toString(mod)).append(' ');
 494.322 +            }
 494.323 +            sb.append(Field.getTypeName(getReturnType())).append(' ');
 494.324 +            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 494.325 +            sb.append(getName()).append('(');
 494.326 +            Class<?>[] params = getParameterTypes(); // avoid clone
 494.327 +            for (int j = 0; j < params.length; j++) {
 494.328 +                sb.append(Field.getTypeName(params[j]));
 494.329 +                if (j < (params.length - 1))
 494.330 +                    sb.append(',');
 494.331 +            }
 494.332 +            sb.append(')');
 494.333 +            /*
 494.334 +            Class<?>[] exceptions = exceptionTypes; // avoid clone
 494.335 +            if (exceptions.length > 0) {
 494.336 +                sb.append(" throws ");
 494.337 +                for (int k = 0; k < exceptions.length; k++) {
 494.338 +                    sb.append(exceptions[k].getName());
 494.339 +                    if (k < (exceptions.length - 1))
 494.340 +                        sb.append(',');
 494.341 +                }
 494.342 +            }
 494.343 +            */
 494.344 +            return sb.toString();
 494.345 +        } catch (Exception e) {
 494.346 +            return "<" + e + ">";
 494.347 +        }
 494.348 +    }
 494.349 +
 494.350 +    /**
 494.351 +     * Returns a string describing this {@code Method}, including
 494.352 +     * type parameters.  The string is formatted as the method access
 494.353 +     * modifiers, if any, followed by an angle-bracketed
 494.354 +     * comma-separated list of the method's type parameters, if any,
 494.355 +     * followed by the method's generic return type, followed by a
 494.356 +     * space, followed by the class declaring the method, followed by
 494.357 +     * a period, followed by the method name, followed by a
 494.358 +     * parenthesized, comma-separated list of the method's generic
 494.359 +     * formal parameter types.
 494.360 +     *
 494.361 +     * If this method was declared to take a variable number of
 494.362 +     * arguments, instead of denoting the last parameter as
 494.363 +     * "<tt><i>Type</i>[]</tt>", it is denoted as
 494.364 +     * "<tt><i>Type</i>...</tt>".
 494.365 +     *
 494.366 +     * A space is used to separate access modifiers from one another
 494.367 +     * and from the type parameters or return type.  If there are no
 494.368 +     * type parameters, the type parameter list is elided; if the type
 494.369 +     * parameter list is present, a space separates the list from the
 494.370 +     * class name.  If the method is declared to throw exceptions, the
 494.371 +     * parameter list is followed by a space, followed by the word
 494.372 +     * throws followed by a comma-separated list of the generic thrown
 494.373 +     * exception types.  If there are no type parameters, the type
 494.374 +     * parameter list is elided.
 494.375 +     *
 494.376 +     * <p>The access modifiers are placed in canonical order as
 494.377 +     * specified by "The Java Language Specification".  This is
 494.378 +     * {@code public}, {@code protected} or {@code private} first,
 494.379 +     * and then other modifiers in the following order:
 494.380 +     * {@code abstract}, {@code static}, {@code final},
 494.381 +     * {@code synchronized}, {@code native}, {@code strictfp}.
 494.382 +     *
 494.383 +     * @return a string describing this {@code Method},
 494.384 +     * include type parameters
 494.385 +     *
 494.386 +     * @since 1.5
 494.387 +     */
 494.388 +    public String toGenericString() {
 494.389 +        try {
 494.390 +            StringBuilder sb = new StringBuilder();
 494.391 +            int mod = getModifiers() & Modifier.methodModifiers();
 494.392 +            if (mod != 0) {
 494.393 +                sb.append(Modifier.toString(mod)).append(' ');
 494.394 +            }
 494.395 +            TypeVariable<?>[] typeparms = getTypeParameters();
 494.396 +            if (typeparms.length > 0) {
 494.397 +                boolean first = true;
 494.398 +                sb.append('<');
 494.399 +                for(TypeVariable<?> typeparm: typeparms) {
 494.400 +                    if (!first)
 494.401 +                        sb.append(',');
 494.402 +                    // Class objects can't occur here; no need to test
 494.403 +                    // and call Class.getName().
 494.404 +                    sb.append(typeparm.toString());
 494.405 +                    first = false;
 494.406 +                }
 494.407 +                sb.append("> ");
 494.408 +            }
 494.409 +
 494.410 +            Type genRetType = getGenericReturnType();
 494.411 +            sb.append( ((genRetType instanceof Class<?>)?
 494.412 +                        Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
 494.413 +                    .append(' ');
 494.414 +
 494.415 +            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 494.416 +            sb.append(getName()).append('(');
 494.417 +            Type[] params = getGenericParameterTypes();
 494.418 +            for (int j = 0; j < params.length; j++) {
 494.419 +                String param = (params[j] instanceof Class)?
 494.420 +                    Field.getTypeName((Class)params[j]):
 494.421 +                    (params[j].toString());
 494.422 +                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 494.423 +                    param = param.replaceFirst("\\[\\]$", "...");
 494.424 +                sb.append(param);
 494.425 +                if (j < (params.length - 1))
 494.426 +                    sb.append(',');
 494.427 +            }
 494.428 +            sb.append(')');
 494.429 +            Type[] exceptions = getGenericExceptionTypes();
 494.430 +            if (exceptions.length > 0) {
 494.431 +                sb.append(" throws ");
 494.432 +                for (int k = 0; k < exceptions.length; k++) {
 494.433 +                    sb.append((exceptions[k] instanceof Class)?
 494.434 +                              ((Class)exceptions[k]).getName():
 494.435 +                              exceptions[k].toString());
 494.436 +                    if (k < (exceptions.length - 1))
 494.437 +                        sb.append(',');
 494.438 +                }
 494.439 +            }
 494.440 +            return sb.toString();
 494.441 +        } catch (Exception e) {
 494.442 +            return "<" + e + ">";
 494.443 +        }
 494.444 +    }
 494.445 +
 494.446 +    /**
 494.447 +     * Invokes the underlying method represented by this {@code Method}
 494.448 +     * object, on the specified object with the specified parameters.
 494.449 +     * Individual parameters are automatically unwrapped to match
 494.450 +     * primitive formal parameters, and both primitive and reference
 494.451 +     * parameters are subject to method invocation conversions as
 494.452 +     * necessary.
 494.453 +     *
 494.454 +     * <p>If the underlying method is static, then the specified {@code obj}
 494.455 +     * argument is ignored. It may be null.
 494.456 +     *
 494.457 +     * <p>If the number of formal parameters required by the underlying method is
 494.458 +     * 0, the supplied {@code args} array may be of length 0 or null.
 494.459 +     *
 494.460 +     * <p>If the underlying method is an instance method, it is invoked
 494.461 +     * using dynamic method lookup as documented in The Java Language
 494.462 +     * Specification, Second Edition, section 15.12.4.4; in particular,
 494.463 +     * overriding based on the runtime type of the target object will occur.
 494.464 +     *
 494.465 +     * <p>If the underlying method is static, the class that declared
 494.466 +     * the method is initialized if it has not already been initialized.
 494.467 +     *
 494.468 +     * <p>If the method completes normally, the value it returns is
 494.469 +     * returned to the caller of invoke; if the value has a primitive
 494.470 +     * type, it is first appropriately wrapped in an object. However,
 494.471 +     * if the value has the type of an array of a primitive type, the
 494.472 +     * elements of the array are <i>not</i> wrapped in objects; in
 494.473 +     * other words, an array of primitive type is returned.  If the
 494.474 +     * underlying method return type is void, the invocation returns
 494.475 +     * null.
 494.476 +     *
 494.477 +     * @param obj  the object the underlying method is invoked from
 494.478 +     * @param args the arguments used for the method call
 494.479 +     * @return the result of dispatching the method represented by
 494.480 +     * this object on {@code obj} with parameters
 494.481 +     * {@code args}
 494.482 +     *
 494.483 +     * @exception IllegalAccessException    if this {@code Method} object
 494.484 +     *              is enforcing Java language access control and the underlying
 494.485 +     *              method is inaccessible.
 494.486 +     * @exception IllegalArgumentException  if the method is an
 494.487 +     *              instance method and the specified object argument
 494.488 +     *              is not an instance of the class or interface
 494.489 +     *              declaring the underlying method (or of a subclass
 494.490 +     *              or implementor thereof); if the number of actual
 494.491 +     *              and formal parameters differ; if an unwrapping
 494.492 +     *              conversion for primitive arguments fails; or if,
 494.493 +     *              after possible unwrapping, a parameter value
 494.494 +     *              cannot be converted to the corresponding formal
 494.495 +     *              parameter type by a method invocation conversion.
 494.496 +     * @exception InvocationTargetException if the underlying method
 494.497 +     *              throws an exception.
 494.498 +     * @exception NullPointerException      if the specified object is null
 494.499 +     *              and the method is an instance method.
 494.500 +     * @exception ExceptionInInitializerError if the initialization
 494.501 +     * provoked by this method fails.
 494.502 +     */
 494.503 +    public Object invoke(Object obj, Object... args)
 494.504 +        throws IllegalAccessException, IllegalArgumentException,
 494.505 +           InvocationTargetException
 494.506 +    {
 494.507 +        final boolean isStatic = (getModifiers() & Modifier.STATIC) == 0;
 494.508 +        if (isStatic && obj == null) {
 494.509 +            throw new NullPointerException();
 494.510 +        }
 494.511 +        Class[] types = getParameterTypes();
 494.512 +        if (types.length != args.length) {
 494.513 +            throw new IllegalArgumentException("Types len " + types.length + " args: " + args.length);
 494.514 +        } else {
 494.515 +            args = args.clone();
 494.516 +            for (int i = 0; i < types.length; i++) {
 494.517 +                Class c = types[i];
 494.518 +                if (c.isPrimitive()) {
 494.519 +                    args[i] = toPrimitive(c, args[i]);
 494.520 +                }
 494.521 +            }
 494.522 +        }
 494.523 +        Object res = invoke0(isStatic, this, obj, args);
 494.524 +        if (getReturnType().isPrimitive()) {
 494.525 +            res = fromPrimitive(getReturnType(), res);
 494.526 +        }
 494.527 +        return res;
 494.528 +    }
 494.529 +    
 494.530 +    @JavaScriptBody(args = { "st", "method", "self", "args" }, body =
 494.531 +          "var p;\n"
 494.532 +        + "if (st) {\n"
 494.533 +        + "  p = new Array(1);\n"
 494.534 +        + "  p[0] = self;\n"
 494.535 +        + "  p = p.concat(args);\n"
 494.536 +        + "} else {\n"
 494.537 +        + "  p = args;\n"
 494.538 +        + "}\n"
 494.539 +        + "return method._data().apply(self, p);\n"
 494.540 +    )
 494.541 +    private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
 494.542 +
 494.543 +    static Object fromPrimitive(Class<?> type, Object o) {
 494.544 +        if (type == Integer.TYPE) {
 494.545 +            return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
 494.546 +        }
 494.547 +        if (type == Long.TYPE) {
 494.548 +            return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
 494.549 +        }
 494.550 +        if (type == Double.TYPE) {
 494.551 +            return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
 494.552 +        }
 494.553 +        if (type == Float.TYPE) {
 494.554 +            return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
 494.555 +        }
 494.556 +        if (type == Byte.TYPE) {
 494.557 +            return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
 494.558 +        }
 494.559 +        if (type == Boolean.TYPE) {
 494.560 +            return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
 494.561 +        }
 494.562 +        if (type == Short.TYPE) {
 494.563 +            return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
 494.564 +        }
 494.565 +        if (type == Character.TYPE) {
 494.566 +            return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
 494.567 +        }
 494.568 +        if (type.getName().equals("void")) {
 494.569 +            return null;
 494.570 +        }
 494.571 +        throw new IllegalStateException("Can't convert " + o);
 494.572 +    }
 494.573 +    
 494.574 +    @JavaScriptBody(args = { "cls", "m", "o" }, 
 494.575 +        body = "return cls.cnstr(false)[m](o);"
 494.576 +    )
 494.577 +    private static native Integer fromRaw(Class<?> cls, String m, Object o);
 494.578 +
 494.579 +    private static Object toPrimitive(Class<?> type, Object o) {
 494.580 +        if (type == Integer.TYPE) {
 494.581 +            return toRaw("intValue__I", o);
 494.582 +        }
 494.583 +        if (type == Long.TYPE) {
 494.584 +            return toRaw("longValue__J", o);
 494.585 +        }
 494.586 +        if (type == Double.TYPE) {
 494.587 +            return toRaw("doubleValue__D", o);
 494.588 +        }
 494.589 +        if (type == Float.TYPE) {
 494.590 +            return toRaw("floatValue__F", o);
 494.591 +        }
 494.592 +        if (type == Byte.TYPE) {
 494.593 +            return toRaw("byteValue__B", o);
 494.594 +        }
 494.595 +        if (type == Boolean.TYPE) {
 494.596 +            return toRaw("booleanValue__Z", o);
 494.597 +        }
 494.598 +        if (type == Short.TYPE) {
 494.599 +            return toRaw("shortValue__S", o);
 494.600 +        }
 494.601 +        if (type == Character.TYPE) {
 494.602 +            return toRaw("charValue__C", o);
 494.603 +        }
 494.604 +        if (type.getName().equals("void")) {
 494.605 +            return o;
 494.606 +        }
 494.607 +        throw new IllegalStateException("Can't convert " + o);
 494.608 +    }
 494.609 +    
 494.610 +    @JavaScriptBody(args = { "m", "o" }, 
 494.611 +        body = "return o[m](o);"
 494.612 +    )
 494.613 +    private static native Object toRaw(String m, Object o);
 494.614 +    
 494.615 +    /**
 494.616 +     * Returns {@code true} if this method is a bridge
 494.617 +     * method; returns {@code false} otherwise.
 494.618 +     *
 494.619 +     * @return true if and only if this method is a bridge
 494.620 +     * method as defined by the Java Language Specification.
 494.621 +     * @since 1.5
 494.622 +     */
 494.623 +    public boolean isBridge() {
 494.624 +        return (getModifiers() & Modifier.BRIDGE) != 0;
 494.625 +    }
 494.626 +
 494.627 +    /**
 494.628 +     * Returns {@code true} if this method was declared to take
 494.629 +     * a variable number of arguments; returns {@code false}
 494.630 +     * otherwise.
 494.631 +     *
 494.632 +     * @return {@code true} if an only if this method was declared to
 494.633 +     * take a variable number of arguments.
 494.634 +     * @since 1.5
 494.635 +     */
 494.636 +    public boolean isVarArgs() {
 494.637 +        return (getModifiers() & Modifier.VARARGS) != 0;
 494.638 +    }
 494.639 +
 494.640 +    /**
 494.641 +     * Returns {@code true} if this method is a synthetic
 494.642 +     * method; returns {@code false} otherwise.
 494.643 +     *
 494.644 +     * @return true if and only if this method is a synthetic
 494.645 +     * method as defined by the Java Language Specification.
 494.646 +     * @since 1.5
 494.647 +     */
 494.648 +    public boolean isSynthetic() {
 494.649 +        return Modifier.isSynthetic(getModifiers());
 494.650 +    }
 494.651 +
 494.652 +    @JavaScriptBody(args = { "ac" }, 
 494.653 +        body = 
 494.654 +          "var a = this._data().anno;"
 494.655 +        + "if (a) {"
 494.656 +        + "  return a['L' + ac.jvmName + ';'];"
 494.657 +        + "} else return null;"
 494.658 +    )
 494.659 +    private Object getAnnotationData(Class<?> annotationClass) {
 494.660 +        throw new UnsupportedOperationException();
 494.661 +    }
 494.662 +    
 494.663 +    /**
 494.664 +     * @throws NullPointerException {@inheritDoc}
 494.665 +     * @since 1.5
 494.666 +     */
 494.667 +    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 494.668 +        Object data = getAnnotationData(annotationClass);
 494.669 +        return data == null ? null : AnnotationImpl.create(annotationClass, data);
 494.670 +    }
 494.671 +
 494.672 +    /**
 494.673 +     * @since 1.5
 494.674 +     */
 494.675 +    public Annotation[] getDeclaredAnnotations()  {
 494.676 +        throw new UnsupportedOperationException();
 494.677 +    }
 494.678 +
 494.679 +    /**
 494.680 +     * Returns the default value for the annotation member represented by
 494.681 +     * this {@code Method} instance.  If the member is of a primitive type,
 494.682 +     * an instance of the corresponding wrapper type is returned. Returns
 494.683 +     * null if no default is associated with the member, or if the method
 494.684 +     * instance does not represent a declared member of an annotation type.
 494.685 +     *
 494.686 +     * @return the default value for the annotation member represented
 494.687 +     *     by this {@code Method} instance.
 494.688 +     * @throws TypeNotPresentException if the annotation is of type
 494.689 +     *     {@link Class} and no definition can be found for the
 494.690 +     *     default class value.
 494.691 +     * @since  1.5
 494.692 +     */
 494.693 +    public Object getDefaultValue() {
 494.694 +        throw new UnsupportedOperationException();
 494.695 +    }
 494.696 +
 494.697 +    /**
 494.698 +     * Returns an array of arrays that represent the annotations on the formal
 494.699 +     * parameters, in declaration order, of the method represented by
 494.700 +     * this {@code Method} object. (Returns an array of length zero if the
 494.701 +     * underlying method is parameterless.  If the method has one or more
 494.702 +     * parameters, a nested array of length zero is returned for each parameter
 494.703 +     * with no annotations.) The annotation objects contained in the returned
 494.704 +     * arrays are serializable.  The caller of this method is free to modify
 494.705 +     * the returned arrays; it will have no effect on the arrays returned to
 494.706 +     * other callers.
 494.707 +     *
 494.708 +     * @return an array of arrays that represent the annotations on the formal
 494.709 +     *    parameters, in declaration order, of the method represented by this
 494.710 +     *    Method object
 494.711 +     * @since 1.5
 494.712 +     */
 494.713 +    public Annotation[][] getParameterAnnotations() {
 494.714 +        throw new UnsupportedOperationException();
 494.715 +    }
 494.716 +
 494.717 +    static {
 494.718 +        MethodImpl.INSTANCE = new MethodImpl() {
 494.719 +            protected Method create(Class<?> declaringClass, String name, Object data, String sig) {
 494.720 +                return new Method(declaringClass, name, data, sig);
 494.721 +            }
 494.722 +        };
 494.723 +    }
 494.724 +}
   495.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   495.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Modifier.java	Wed Feb 27 11:24:58 2013 +0100
   495.3 @@ -0,0 +1,437 @@
   495.4 +/*
   495.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   495.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   495.7 + *
   495.8 + * This code is free software; you can redistribute it and/or modify it
   495.9 + * under the terms of the GNU General Public License version 2 only, as
  495.10 + * published by the Free Software Foundation.  Oracle designates this
  495.11 + * particular file as subject to the "Classpath" exception as provided
  495.12 + * by Oracle in the LICENSE file that accompanied this code.
  495.13 + *
  495.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  495.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  495.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  495.17 + * version 2 for more details (a copy is included in the LICENSE file that
  495.18 + * accompanied this code).
  495.19 + *
  495.20 + * You should have received a copy of the GNU General Public License version
  495.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  495.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  495.23 + *
  495.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  495.25 + * or visit www.oracle.com if you need additional information or have any
  495.26 + * questions.
  495.27 + */
  495.28 +
  495.29 +package java.lang.reflect;
  495.30 +
  495.31 +/**
  495.32 + * The Modifier class provides {@code static} methods and
  495.33 + * constants to decode class and member access modifiers.  The sets of
  495.34 + * modifiers are represented as integers with distinct bit positions
  495.35 + * representing different modifiers.  The values for the constants
  495.36 + * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  495.37 + * <cite>The Java&trade; Virtual Machine Specification</cite>.
  495.38 + *
  495.39 + * @see Class#getModifiers()
  495.40 + * @see Member#getModifiers()
  495.41 + *
  495.42 + * @author Nakul Saraiya
  495.43 + * @author Kenneth Russell
  495.44 + */
  495.45 +public
  495.46 +class Modifier {
  495.47 +
  495.48 +    /**
  495.49 +     * Return {@code true} if the integer argument includes the
  495.50 +     * {@code public} modifier, {@code false} otherwise.
  495.51 +     *
  495.52 +     * @param   mod a set of modifiers
  495.53 +     * @return {@code true} if {@code mod} includes the
  495.54 +     * {@code public} modifier; {@code false} otherwise.
  495.55 +     */
  495.56 +    public static boolean isPublic(int mod) {
  495.57 +        return (mod & PUBLIC) != 0;
  495.58 +    }
  495.59 +
  495.60 +    /**
  495.61 +     * Return {@code true} if the integer argument includes the
  495.62 +     * {@code private} modifier, {@code false} otherwise.
  495.63 +     *
  495.64 +     * @param   mod a set of modifiers
  495.65 +     * @return {@code true} if {@code mod} includes the
  495.66 +     * {@code private} modifier; {@code false} otherwise.
  495.67 +     */
  495.68 +    public static boolean isPrivate(int mod) {
  495.69 +        return (mod & PRIVATE) != 0;
  495.70 +    }
  495.71 +
  495.72 +    /**
  495.73 +     * Return {@code true} if the integer argument includes the
  495.74 +     * {@code protected} modifier, {@code false} otherwise.
  495.75 +     *
  495.76 +     * @param   mod a set of modifiers
  495.77 +     * @return {@code true} if {@code mod} includes the
  495.78 +     * {@code protected} modifier; {@code false} otherwise.
  495.79 +     */
  495.80 +    public static boolean isProtected(int mod) {
  495.81 +        return (mod & PROTECTED) != 0;
  495.82 +    }
  495.83 +
  495.84 +    /**
  495.85 +     * Return {@code true} if the integer argument includes the
  495.86 +     * {@code static} modifier, {@code false} otherwise.
  495.87 +     *
  495.88 +     * @param   mod a set of modifiers
  495.89 +     * @return {@code true} if {@code mod} includes the
  495.90 +     * {@code static} modifier; {@code false} otherwise.
  495.91 +     */
  495.92 +    public static boolean isStatic(int mod) {
  495.93 +        return (mod & STATIC) != 0;
  495.94 +    }
  495.95 +
  495.96 +    /**
  495.97 +     * Return {@code true} if the integer argument includes the
  495.98 +     * {@code final} modifier, {@code false} otherwise.
  495.99 +     *
 495.100 +     * @param   mod a set of modifiers
 495.101 +     * @return {@code true} if {@code mod} includes the
 495.102 +     * {@code final} modifier; {@code false} otherwise.
 495.103 +     */
 495.104 +    public static boolean isFinal(int mod) {
 495.105 +        return (mod & FINAL) != 0;
 495.106 +    }
 495.107 +
 495.108 +    /**
 495.109 +     * Return {@code true} if the integer argument includes the
 495.110 +     * {@code synchronized} modifier, {@code false} otherwise.
 495.111 +     *
 495.112 +     * @param   mod a set of modifiers
 495.113 +     * @return {@code true} if {@code mod} includes the
 495.114 +     * {@code synchronized} modifier; {@code false} otherwise.
 495.115 +     */
 495.116 +    public static boolean isSynchronized(int mod) {
 495.117 +        return (mod & SYNCHRONIZED) != 0;
 495.118 +    }
 495.119 +
 495.120 +    /**
 495.121 +     * Return {@code true} if the integer argument includes the
 495.122 +     * {@code volatile} modifier, {@code false} otherwise.
 495.123 +     *
 495.124 +     * @param   mod a set of modifiers
 495.125 +     * @return {@code true} if {@code mod} includes the
 495.126 +     * {@code volatile} modifier; {@code false} otherwise.
 495.127 +     */
 495.128 +    public static boolean isVolatile(int mod) {
 495.129 +        return (mod & VOLATILE) != 0;
 495.130 +    }
 495.131 +
 495.132 +    /**
 495.133 +     * Return {@code true} if the integer argument includes the
 495.134 +     * {@code transient} modifier, {@code false} otherwise.
 495.135 +     *
 495.136 +     * @param   mod a set of modifiers
 495.137 +     * @return {@code true} if {@code mod} includes the
 495.138 +     * {@code transient} modifier; {@code false} otherwise.
 495.139 +     */
 495.140 +    public static boolean isTransient(int mod) {
 495.141 +        return (mod & TRANSIENT) != 0;
 495.142 +    }
 495.143 +
 495.144 +    /**
 495.145 +     * Return {@code true} if the integer argument includes the
 495.146 +     * {@code native} modifier, {@code false} otherwise.
 495.147 +     *
 495.148 +     * @param   mod a set of modifiers
 495.149 +     * @return {@code true} if {@code mod} includes the
 495.150 +     * {@code native} modifier; {@code false} otherwise.
 495.151 +     */
 495.152 +    public static boolean isNative(int mod) {
 495.153 +        return (mod & NATIVE) != 0;
 495.154 +    }
 495.155 +
 495.156 +    /**
 495.157 +     * Return {@code true} if the integer argument includes the
 495.158 +     * {@code interface} modifier, {@code false} otherwise.
 495.159 +     *
 495.160 +     * @param   mod a set of modifiers
 495.161 +     * @return {@code true} if {@code mod} includes the
 495.162 +     * {@code interface} modifier; {@code false} otherwise.
 495.163 +     */
 495.164 +    public static boolean isInterface(int mod) {
 495.165 +        return (mod & INTERFACE) != 0;
 495.166 +    }
 495.167 +
 495.168 +    /**
 495.169 +     * Return {@code true} if the integer argument includes the
 495.170 +     * {@code abstract} modifier, {@code false} otherwise.
 495.171 +     *
 495.172 +     * @param   mod a set of modifiers
 495.173 +     * @return {@code true} if {@code mod} includes the
 495.174 +     * {@code abstract} modifier; {@code false} otherwise.
 495.175 +     */
 495.176 +    public static boolean isAbstract(int mod) {
 495.177 +        return (mod & ABSTRACT) != 0;
 495.178 +    }
 495.179 +
 495.180 +    /**
 495.181 +     * Return {@code true} if the integer argument includes the
 495.182 +     * {@code strictfp} modifier, {@code false} otherwise.
 495.183 +     *
 495.184 +     * @param   mod a set of modifiers
 495.185 +     * @return {@code true} if {@code mod} includes the
 495.186 +     * {@code strictfp} modifier; {@code false} otherwise.
 495.187 +     */
 495.188 +    public static boolean isStrict(int mod) {
 495.189 +        return (mod & STRICT) != 0;
 495.190 +    }
 495.191 +
 495.192 +    /**
 495.193 +     * Return a string describing the access modifier flags in
 495.194 +     * the specified modifier. For example:
 495.195 +     * <blockquote><pre>
 495.196 +     *    public final synchronized strictfp
 495.197 +     * </pre></blockquote>
 495.198 +     * The modifier names are returned in an order consistent with the
 495.199 +     * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
 495.200 +     * <cite>The Java&trade; Language Specification</cite>.
 495.201 +     * The full modifier ordering used by this method is:
 495.202 +     * <blockquote> {@code
 495.203 +     * public protected private abstract static final transient
 495.204 +     * volatile synchronized native strictfp
 495.205 +     * interface } </blockquote>
 495.206 +     * The {@code interface} modifier discussed in this class is
 495.207 +     * not a true modifier in the Java language and it appears after
 495.208 +     * all other modifiers listed by this method.  This method may
 495.209 +     * return a string of modifiers that are not valid modifiers of a
 495.210 +     * Java entity; in other words, no checking is done on the
 495.211 +     * possible validity of the combination of modifiers represented
 495.212 +     * by the input.
 495.213 +     *
 495.214 +     * Note that to perform such checking for a known kind of entity,
 495.215 +     * such as a constructor or method, first AND the argument of
 495.216 +     * {@code toString} with the appropriate mask from a method like
 495.217 +     * {@link #constructorModifiers} or {@link #methodModifiers}.
 495.218 +     *
 495.219 +     * @param   mod a set of modifiers
 495.220 +     * @return  a string representation of the set of modifiers
 495.221 +     * represented by {@code mod}
 495.222 +     */
 495.223 +    public static String toString(int mod) {
 495.224 +        StringBuffer sb = new StringBuffer();
 495.225 +        int len;
 495.226 +
 495.227 +        if ((mod & PUBLIC) != 0)        sb.append("public ");
 495.228 +        if ((mod & PROTECTED) != 0)     sb.append("protected ");
 495.229 +        if ((mod & PRIVATE) != 0)       sb.append("private ");
 495.230 +
 495.231 +        /* Canonical order */
 495.232 +        if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
 495.233 +        if ((mod & STATIC) != 0)        sb.append("static ");
 495.234 +        if ((mod & FINAL) != 0)         sb.append("final ");
 495.235 +        if ((mod & TRANSIENT) != 0)     sb.append("transient ");
 495.236 +        if ((mod & VOLATILE) != 0)      sb.append("volatile ");
 495.237 +        if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
 495.238 +        if ((mod & NATIVE) != 0)        sb.append("native ");
 495.239 +        if ((mod & STRICT) != 0)        sb.append("strictfp ");
 495.240 +        if ((mod & INTERFACE) != 0)     sb.append("interface ");
 495.241 +
 495.242 +        if ((len = sb.length()) > 0)    /* trim trailing space */
 495.243 +            return sb.toString().substring(0, len-1);
 495.244 +        return "";
 495.245 +    }
 495.246 +
 495.247 +    /*
 495.248 +     * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
 495.249 +     * <cite>The Java&trade; Virtual Machine Specification</cite>
 495.250 +     */
 495.251 +
 495.252 +    /**
 495.253 +     * The {@code int} value representing the {@code public}
 495.254 +     * modifier.
 495.255 +     */
 495.256 +    public static final int PUBLIC           = 0x00000001;
 495.257 +
 495.258 +    /**
 495.259 +     * The {@code int} value representing the {@code private}
 495.260 +     * modifier.
 495.261 +     */
 495.262 +    public static final int PRIVATE          = 0x00000002;
 495.263 +
 495.264 +    /**
 495.265 +     * The {@code int} value representing the {@code protected}
 495.266 +     * modifier.
 495.267 +     */
 495.268 +    public static final int PROTECTED        = 0x00000004;
 495.269 +
 495.270 +    /**
 495.271 +     * The {@code int} value representing the {@code static}
 495.272 +     * modifier.
 495.273 +     */
 495.274 +    public static final int STATIC           = 0x00000008;
 495.275 +
 495.276 +    /**
 495.277 +     * The {@code int} value representing the {@code final}
 495.278 +     * modifier.
 495.279 +     */
 495.280 +    public static final int FINAL            = 0x00000010;
 495.281 +
 495.282 +    /**
 495.283 +     * The {@code int} value representing the {@code synchronized}
 495.284 +     * modifier.
 495.285 +     */
 495.286 +    public static final int SYNCHRONIZED     = 0x00000020;
 495.287 +
 495.288 +    /**
 495.289 +     * The {@code int} value representing the {@code volatile}
 495.290 +     * modifier.
 495.291 +     */
 495.292 +    public static final int VOLATILE         = 0x00000040;
 495.293 +
 495.294 +    /**
 495.295 +     * The {@code int} value representing the {@code transient}
 495.296 +     * modifier.
 495.297 +     */
 495.298 +    public static final int TRANSIENT        = 0x00000080;
 495.299 +
 495.300 +    /**
 495.301 +     * The {@code int} value representing the {@code native}
 495.302 +     * modifier.
 495.303 +     */
 495.304 +    public static final int NATIVE           = 0x00000100;
 495.305 +
 495.306 +    /**
 495.307 +     * The {@code int} value representing the {@code interface}
 495.308 +     * modifier.
 495.309 +     */
 495.310 +    public static final int INTERFACE        = 0x00000200;
 495.311 +
 495.312 +    /**
 495.313 +     * The {@code int} value representing the {@code abstract}
 495.314 +     * modifier.
 495.315 +     */
 495.316 +    public static final int ABSTRACT         = 0x00000400;
 495.317 +
 495.318 +    /**
 495.319 +     * The {@code int} value representing the {@code strictfp}
 495.320 +     * modifier.
 495.321 +     */
 495.322 +    public static final int STRICT           = 0x00000800;
 495.323 +
 495.324 +    // Bits not (yet) exposed in the public API either because they
 495.325 +    // have different meanings for fields and methods and there is no
 495.326 +    // way to distinguish between the two in this class, or because
 495.327 +    // they are not Java programming language keywords
 495.328 +    static final int BRIDGE    = 0x00000040;
 495.329 +    static final int VARARGS   = 0x00000080;
 495.330 +    static final int SYNTHETIC = 0x00001000;
 495.331 +    static final int ANNOTATION= 0x00002000;
 495.332 +    static final int ENUM      = 0x00004000;
 495.333 +    static boolean isSynthetic(int mod) {
 495.334 +      return (mod & SYNTHETIC) != 0;
 495.335 +    }
 495.336 +
 495.337 +    /**
 495.338 +     * See JLSv3 section 8.1.1.
 495.339 +     */
 495.340 +    private static final int CLASS_MODIFIERS =
 495.341 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 495.342 +        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 495.343 +        Modifier.STRICT;
 495.344 +
 495.345 +    /**
 495.346 +     * See JLSv3 section 9.1.1.
 495.347 +     */
 495.348 +    private static final int INTERFACE_MODIFIERS =
 495.349 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 495.350 +        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.STRICT;
 495.351 +
 495.352 +
 495.353 +    /**
 495.354 +     * See JLSv3 section 8.8.3.
 495.355 +     */
 495.356 +    private static final int CONSTRUCTOR_MODIFIERS =
 495.357 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE;
 495.358 +
 495.359 +    /**
 495.360 +     * See JLSv3 section 8.4.3.
 495.361 +     */
 495.362 +    private static final int METHOD_MODIFIERS =
 495.363 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 495.364 +        Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
 495.365 +        Modifier.SYNCHRONIZED   | Modifier.NATIVE       | Modifier.STRICT;
 495.366 +
 495.367 +    /**
 495.368 +     * See JLSv3 section 8.3.1.
 495.369 +     */
 495.370 +    private static final int FIELD_MODIFIERS =
 495.371 +        Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
 495.372 +        Modifier.STATIC         | Modifier.FINAL        | Modifier.TRANSIENT |
 495.373 +        Modifier.VOLATILE;
 495.374 +
 495.375 +    /**
 495.376 +     * Return an {@code int} value OR-ing together the source language
 495.377 +     * modifiers that can be applied to a class.
 495.378 +     * @return an {@code int} value OR-ing together the source language
 495.379 +     * modifiers that can be applied to a class.
 495.380 +     *
 495.381 +     * @jls 8.1.1 Class Modifiers
 495.382 +     * @since 1.7
 495.383 +     */
 495.384 +    public static int classModifiers() {
 495.385 +        return CLASS_MODIFIERS;
 495.386 +    }
 495.387 +
 495.388 +    /**
 495.389 +     * Return an {@code int} value OR-ing together the source language
 495.390 +     * modifiers that can be applied to an interface.
 495.391 +     * @return an {@code int} value OR-ing together the source language
 495.392 +     * modifiers that can be applied to an inteface.
 495.393 +     *
 495.394 +     * @jls 9.1.1 Interface Modifiers
 495.395 +     * @since 1.7
 495.396 +     */
 495.397 +    public static int interfaceModifiers() {
 495.398 +        return INTERFACE_MODIFIERS;
 495.399 +    }
 495.400 +
 495.401 +    /**
 495.402 +     * Return an {@code int} value OR-ing together the source language
 495.403 +     * modifiers that can be applied to a constructor.
 495.404 +     * @return an {@code int} value OR-ing together the source language
 495.405 +     * modifiers that can be applied to a constructor.
 495.406 +     *
 495.407 +     * @jls 8.8.3 Constructor Modifiers
 495.408 +     * @since 1.7
 495.409 +     */
 495.410 +    public static int constructorModifiers() {
 495.411 +        return CONSTRUCTOR_MODIFIERS;
 495.412 +    }
 495.413 +
 495.414 +    /**
 495.415 +     * Return an {@code int} value OR-ing together the source language
 495.416 +     * modifiers that can be applied to a method.
 495.417 +     * @return an {@code int} value OR-ing together the source language
 495.418 +     * modifiers that can be applied to a method.
 495.419 +     *
 495.420 +     * @jls 8.4.3 Method Modifiers
 495.421 +     * @since 1.7
 495.422 +     */
 495.423 +    public static int methodModifiers() {
 495.424 +        return METHOD_MODIFIERS;
 495.425 +    }
 495.426 +
 495.427 +
 495.428 +    /**
 495.429 +     * Return an {@code int} value OR-ing together the source language
 495.430 +     * modifiers that can be applied to a field.
 495.431 +     * @return an {@code int} value OR-ing together the source language
 495.432 +     * modifiers that can be applied to a field.
 495.433 +     *
 495.434 +     * @jls 8.3.1 Field Modifiers
 495.435 +     * @since 1.7
 495.436 +     */
 495.437 +    public static int fieldModifiers() {
 495.438 +        return FIELD_MODIFIERS;
 495.439 +    }
 495.440 +}
   496.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   496.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Proxy.java	Wed Feb 27 11:24:58 2013 +0100
   496.3 @@ -0,0 +1,407 @@
   496.4 +/*
   496.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
   496.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   496.7 + *
   496.8 + * This code is free software; you can redistribute it and/or modify it
   496.9 + * under the terms of the GNU General Public License version 2 only, as
  496.10 + * published by the Free Software Foundation.  Oracle designates this
  496.11 + * particular file as subject to the "Classpath" exception as provided
  496.12 + * by Oracle in the LICENSE file that accompanied this code.
  496.13 + *
  496.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  496.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  496.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  496.17 + * version 2 for more details (a copy is included in the LICENSE file that
  496.18 + * accompanied this code).
  496.19 + *
  496.20 + * You should have received a copy of the GNU General Public License version
  496.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  496.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  496.23 + *
  496.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  496.25 + * or visit www.oracle.com if you need additional information or have any
  496.26 + * questions.
  496.27 + */
  496.28 +
  496.29 +package java.lang.reflect;
  496.30 +
  496.31 +
  496.32 +/**
  496.33 + * {@code Proxy} provides static methods for creating dynamic proxy
  496.34 + * classes and instances, and it is also the superclass of all
  496.35 + * dynamic proxy classes created by those methods.
  496.36 + *
  496.37 + * <p>To create a proxy for some interface {@code Foo}:
  496.38 + * <pre>
  496.39 + *     InvocationHandler handler = new MyInvocationHandler(...);
  496.40 + *     Class proxyClass = Proxy.getProxyClass(
  496.41 + *         Foo.class.getClassLoader(), new Class[] { Foo.class });
  496.42 + *     Foo f = (Foo) proxyClass.
  496.43 + *         getConstructor(new Class[] { InvocationHandler.class }).
  496.44 + *         newInstance(new Object[] { handler });
  496.45 + * </pre>
  496.46 + * or more simply:
  496.47 + * <pre>
  496.48 + *     Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
  496.49 + *                                          new Class[] { Foo.class },
  496.50 + *                                          handler);
  496.51 + * </pre>
  496.52 + *
  496.53 + * <p>A <i>dynamic proxy class</i> (simply referred to as a <i>proxy
  496.54 + * class</i> below) is a class that implements a list of interfaces
  496.55 + * specified at runtime when the class is created, with behavior as
  496.56 + * described below.
  496.57 + *
  496.58 + * A <i>proxy interface</i> is such an interface that is implemented
  496.59 + * by a proxy class.
  496.60 + *
  496.61 + * A <i>proxy instance</i> is an instance of a proxy class.
  496.62 + *
  496.63 + * Each proxy instance has an associated <i>invocation handler</i>
  496.64 + * object, which implements the interface {@link InvocationHandler}.
  496.65 + * A method invocation on a proxy instance through one of its proxy
  496.66 + * interfaces will be dispatched to the {@link InvocationHandler#invoke
  496.67 + * invoke} method of the instance's invocation handler, passing the proxy
  496.68 + * instance, a {@code java.lang.reflect.Method} object identifying
  496.69 + * the method that was invoked, and an array of type {@code Object}
  496.70 + * containing the arguments.  The invocation handler processes the
  496.71 + * encoded method invocation as appropriate and the result that it
  496.72 + * returns will be returned as the result of the method invocation on
  496.73 + * the proxy instance.
  496.74 + *
  496.75 + * <p>A proxy class has the following properties:
  496.76 + *
  496.77 + * <ul>
  496.78 + * <li>Proxy classes are public, final, and not abstract.
  496.79 + *
  496.80 + * <li>The unqualified name of a proxy class is unspecified.  The space
  496.81 + * of class names that begin with the string {@code "$Proxy"}
  496.82 + * should be, however, reserved for proxy classes.
  496.83 + *
  496.84 + * <li>A proxy class extends {@code java.lang.reflect.Proxy}.
  496.85 + *
  496.86 + * <li>A proxy class implements exactly the interfaces specified at its
  496.87 + * creation, in the same order.
  496.88 + *
  496.89 + * <li>If a proxy class implements a non-public interface, then it will
  496.90 + * be defined in the same package as that interface.  Otherwise, the
  496.91 + * package of a proxy class is also unspecified.  Note that package
  496.92 + * sealing will not prevent a proxy class from being successfully defined
  496.93 + * in a particular package at runtime, and neither will classes already
  496.94 + * defined by the same class loader and the same package with particular
  496.95 + * signers.
  496.96 + *
  496.97 + * <li>Since a proxy class implements all of the interfaces specified at
  496.98 + * its creation, invoking {@code getInterfaces} on its
  496.99 + * {@code Class} object will return an array containing the same
 496.100 + * list of interfaces (in the order specified at its creation), invoking
 496.101 + * {@code getMethods} on its {@code Class} object will return
 496.102 + * an array of {@code Method} objects that include all of the
 496.103 + * methods in those interfaces, and invoking {@code getMethod} will
 496.104 + * find methods in the proxy interfaces as would be expected.
 496.105 + *
 496.106 + * <li>The {@link Proxy#isProxyClass Proxy.isProxyClass} method will
 496.107 + * return true if it is passed a proxy class-- a class returned by
 496.108 + * {@code Proxy.getProxyClass} or the class of an object returned by
 496.109 + * {@code Proxy.newProxyInstance}-- and false otherwise.
 496.110 + *
 496.111 + * <li>The {@code java.security.ProtectionDomain} of a proxy class
 496.112 + * is the same as that of system classes loaded by the bootstrap class
 496.113 + * loader, such as {@code java.lang.Object}, because the code for a
 496.114 + * proxy class is generated by trusted system code.  This protection
 496.115 + * domain will typically be granted
 496.116 + * {@code java.security.AllPermission}.
 496.117 + *
 496.118 + * <li>Each proxy class has one public constructor that takes one argument,
 496.119 + * an implementation of the interface {@link InvocationHandler}, to set
 496.120 + * the invocation handler for a proxy instance.  Rather than having to use
 496.121 + * the reflection API to access the public constructor, a proxy instance
 496.122 + * can be also be created by calling the {@link Proxy#newProxyInstance
 496.123 + * Proxy.newProxyInstance} method, which combines the actions of calling
 496.124 + * {@link Proxy#getProxyClass Proxy.getProxyClass} with invoking the
 496.125 + * constructor with an invocation handler.
 496.126 + * </ul>
 496.127 + *
 496.128 + * <p>A proxy instance has the following properties:
 496.129 + *
 496.130 + * <ul>
 496.131 + * <li>Given a proxy instance {@code proxy} and one of the
 496.132 + * interfaces implemented by its proxy class {@code Foo}, the
 496.133 + * following expression will return true:
 496.134 + * <pre>
 496.135 + *     {@code proxy instanceof Foo}
 496.136 + * </pre>
 496.137 + * and the following cast operation will succeed (rather than throwing
 496.138 + * a {@code ClassCastException}):
 496.139 + * <pre>
 496.140 + *     {@code (Foo) proxy}
 496.141 + * </pre>
 496.142 + *
 496.143 + * <li>Each proxy instance has an associated invocation handler, the one
 496.144 + * that was passed to its constructor.  The static
 496.145 + * {@link Proxy#getInvocationHandler Proxy.getInvocationHandler} method
 496.146 + * will return the invocation handler associated with the proxy instance
 496.147 + * passed as its argument.
 496.148 + *
 496.149 + * <li>An interface method invocation on a proxy instance will be
 496.150 + * encoded and dispatched to the invocation handler's {@link
 496.151 + * InvocationHandler#invoke invoke} method as described in the
 496.152 + * documentation for that method.
 496.153 + *
 496.154 + * <li>An invocation of the {@code hashCode},
 496.155 + * {@code equals}, or {@code toString} methods declared in
 496.156 + * {@code java.lang.Object} on a proxy instance will be encoded and
 496.157 + * dispatched to the invocation handler's {@code invoke} method in
 496.158 + * the same manner as interface method invocations are encoded and
 496.159 + * dispatched, as described above.  The declaring class of the
 496.160 + * {@code Method} object passed to {@code invoke} will be
 496.161 + * {@code java.lang.Object}.  Other public methods of a proxy
 496.162 + * instance inherited from {@code java.lang.Object} are not
 496.163 + * overridden by a proxy class, so invocations of those methods behave
 496.164 + * like they do for instances of {@code java.lang.Object}.
 496.165 + * </ul>
 496.166 + *
 496.167 + * <h3>Methods Duplicated in Multiple Proxy Interfaces</h3>
 496.168 + *
 496.169 + * <p>When two or more interfaces of a proxy class contain a method with
 496.170 + * the same name and parameter signature, the order of the proxy class's
 496.171 + * interfaces becomes significant.  When such a <i>duplicate method</i>
 496.172 + * is invoked on a proxy instance, the {@code Method} object passed
 496.173 + * to the invocation handler will not necessarily be the one whose
 496.174 + * declaring class is assignable from the reference type of the interface
 496.175 + * that the proxy's method was invoked through.  This limitation exists
 496.176 + * because the corresponding method implementation in the generated proxy
 496.177 + * class cannot determine which interface it was invoked through.
 496.178 + * Therefore, when a duplicate method is invoked on a proxy instance,
 496.179 + * the {@code Method} object for the method in the foremost interface
 496.180 + * that contains the method (either directly or inherited through a
 496.181 + * superinterface) in the proxy class's list of interfaces is passed to
 496.182 + * the invocation handler's {@code invoke} method, regardless of the
 496.183 + * reference type through which the method invocation occurred.
 496.184 + *
 496.185 + * <p>If a proxy interface contains a method with the same name and
 496.186 + * parameter signature as the {@code hashCode}, {@code equals},
 496.187 + * or {@code toString} methods of {@code java.lang.Object},
 496.188 + * when such a method is invoked on a proxy instance, the
 496.189 + * {@code Method} object passed to the invocation handler will have
 496.190 + * {@code java.lang.Object} as its declaring class.  In other words,
 496.191 + * the public, non-final methods of {@code java.lang.Object}
 496.192 + * logically precede all of the proxy interfaces for the determination of
 496.193 + * which {@code Method} object to pass to the invocation handler.
 496.194 + *
 496.195 + * <p>Note also that when a duplicate method is dispatched to an
 496.196 + * invocation handler, the {@code invoke} method may only throw
 496.197 + * checked exception types that are assignable to one of the exception
 496.198 + * types in the {@code throws} clause of the method in <i>all</i> of
 496.199 + * the proxy interfaces that it can be invoked through.  If the
 496.200 + * {@code invoke} method throws a checked exception that is not
 496.201 + * assignable to any of the exception types declared by the method in one
 496.202 + * of the proxy interfaces that it can be invoked through, then an
 496.203 + * unchecked {@code UndeclaredThrowableException} will be thrown by
 496.204 + * the invocation on the proxy instance.  This restriction means that not
 496.205 + * all of the exception types returned by invoking
 496.206 + * {@code getExceptionTypes} on the {@code Method} object
 496.207 + * passed to the {@code invoke} method can necessarily be thrown
 496.208 + * successfully by the {@code invoke} method.
 496.209 + *
 496.210 + * @author      Peter Jones
 496.211 + * @see         InvocationHandler
 496.212 + * @since       1.3
 496.213 + */
 496.214 +public class Proxy implements java.io.Serializable {
 496.215 +
 496.216 +    private static final long serialVersionUID = -2222568056686623797L;
 496.217 +
 496.218 +
 496.219 +
 496.220 +    /**
 496.221 +     * the invocation handler for this proxy instance.
 496.222 +     * @serial
 496.223 +     */
 496.224 +    protected InvocationHandler h;
 496.225 +
 496.226 +    /**
 496.227 +     * Prohibits instantiation.
 496.228 +     */
 496.229 +    private Proxy() {
 496.230 +    }
 496.231 +
 496.232 +    /**
 496.233 +     * Constructs a new {@code Proxy} instance from a subclass
 496.234 +     * (typically, a dynamic proxy class) with the specified value
 496.235 +     * for its invocation handler.
 496.236 +     *
 496.237 +     * @param   h the invocation handler for this proxy instance
 496.238 +     */
 496.239 +    protected Proxy(InvocationHandler h) {
 496.240 +        this.h = h;
 496.241 +    }
 496.242 +
 496.243 +    /**
 496.244 +     * Returns the {@code java.lang.Class} object for a proxy class
 496.245 +     * given a class loader and an array of interfaces.  The proxy class
 496.246 +     * will be defined by the specified class loader and will implement
 496.247 +     * all of the supplied interfaces.  If a proxy class for the same
 496.248 +     * permutation of interfaces has already been defined by the class
 496.249 +     * loader, then the existing proxy class will be returned; otherwise,
 496.250 +     * a proxy class for those interfaces will be generated dynamically
 496.251 +     * and defined by the class loader.
 496.252 +     *
 496.253 +     * <p>There are several restrictions on the parameters that may be
 496.254 +     * passed to {@code Proxy.getProxyClass}:
 496.255 +     *
 496.256 +     * <ul>
 496.257 +     * <li>All of the {@code Class} objects in the
 496.258 +     * {@code interfaces} array must represent interfaces, not
 496.259 +     * classes or primitive types.
 496.260 +     *
 496.261 +     * <li>No two elements in the {@code interfaces} array may
 496.262 +     * refer to identical {@code Class} objects.
 496.263 +     *
 496.264 +     * <li>All of the interface types must be visible by name through the
 496.265 +     * specified class loader.  In other words, for class loader
 496.266 +     * {@code cl} and every interface {@code i}, the following
 496.267 +     * expression must be true:
 496.268 +     * <pre>
 496.269 +     *     Class.forName(i.getName(), false, cl) == i
 496.270 +     * </pre>
 496.271 +     *
 496.272 +     * <li>All non-public interfaces must be in the same package;
 496.273 +     * otherwise, it would not be possible for the proxy class to
 496.274 +     * implement all of the interfaces, regardless of what package it is
 496.275 +     * defined in.
 496.276 +     *
 496.277 +     * <li>For any set of member methods of the specified interfaces
 496.278 +     * that have the same signature:
 496.279 +     * <ul>
 496.280 +     * <li>If the return type of any of the methods is a primitive
 496.281 +     * type or void, then all of the methods must have that same
 496.282 +     * return type.
 496.283 +     * <li>Otherwise, one of the methods must have a return type that
 496.284 +     * is assignable to all of the return types of the rest of the
 496.285 +     * methods.
 496.286 +     * </ul>
 496.287 +     *
 496.288 +     * <li>The resulting proxy class must not exceed any limits imposed
 496.289 +     * on classes by the virtual machine.  For example, the VM may limit
 496.290 +     * the number of interfaces that a class may implement to 65535; in
 496.291 +     * that case, the size of the {@code interfaces} array must not
 496.292 +     * exceed 65535.
 496.293 +     * </ul>
 496.294 +     *
 496.295 +     * <p>If any of these restrictions are violated,
 496.296 +     * {@code Proxy.getProxyClass} will throw an
 496.297 +     * {@code IllegalArgumentException}.  If the {@code interfaces}
 496.298 +     * array argument or any of its elements are {@code null}, a
 496.299 +     * {@code NullPointerException} will be thrown.
 496.300 +     *
 496.301 +     * <p>Note that the order of the specified proxy interfaces is
 496.302 +     * significant: two requests for a proxy class with the same combination
 496.303 +     * of interfaces but in a different order will result in two distinct
 496.304 +     * proxy classes.
 496.305 +     *
 496.306 +     * @param   loader the class loader to define the proxy class
 496.307 +     * @param   interfaces the list of interfaces for the proxy class
 496.308 +     *          to implement
 496.309 +     * @return  a proxy class that is defined in the specified class loader
 496.310 +     *          and that implements the specified interfaces
 496.311 +     * @throws  IllegalArgumentException if any of the restrictions on the
 496.312 +     *          parameters that may be passed to {@code getProxyClass}
 496.313 +     *          are violated
 496.314 +     * @throws  NullPointerException if the {@code interfaces} array
 496.315 +     *          argument or any of its elements are {@code null}
 496.316 +     */
 496.317 +    public static Class<?> getProxyClass(ClassLoader loader,
 496.318 +                                         Class<?>... interfaces)
 496.319 +        throws IllegalArgumentException
 496.320 +    {
 496.321 +        throw new IllegalArgumentException();
 496.322 +    }
 496.323 +
 496.324 +    /**
 496.325 +     * Returns an instance of a proxy class for the specified interfaces
 496.326 +     * that dispatches method invocations to the specified invocation
 496.327 +     * handler.  This method is equivalent to:
 496.328 +     * <pre>
 496.329 +     *     Proxy.getProxyClass(loader, interfaces).
 496.330 +     *         getConstructor(new Class[] { InvocationHandler.class }).
 496.331 +     *         newInstance(new Object[] { handler });
 496.332 +     * </pre>
 496.333 +     *
 496.334 +     * <p>{@code Proxy.newProxyInstance} throws
 496.335 +     * {@code IllegalArgumentException} for the same reasons that
 496.336 +     * {@code Proxy.getProxyClass} does.
 496.337 +     *
 496.338 +     * @param   loader the class loader to define the proxy class
 496.339 +     * @param   interfaces the list of interfaces for the proxy class
 496.340 +     *          to implement
 496.341 +     * @param   h the invocation handler to dispatch method invocations to
 496.342 +     * @return  a proxy instance with the specified invocation handler of a
 496.343 +     *          proxy class that is defined by the specified class loader
 496.344 +     *          and that implements the specified interfaces
 496.345 +     * @throws  IllegalArgumentException if any of the restrictions on the
 496.346 +     *          parameters that may be passed to {@code getProxyClass}
 496.347 +     *          are violated
 496.348 +     * @throws  NullPointerException if the {@code interfaces} array
 496.349 +     *          argument or any of its elements are {@code null}, or
 496.350 +     *          if the invocation handler, {@code h}, is
 496.351 +     *          {@code null}
 496.352 +     */
 496.353 +    public static Object newProxyInstance(ClassLoader loader,
 496.354 +                                          Class<?>[] interfaces,
 496.355 +                                          InvocationHandler h)
 496.356 +        throws IllegalArgumentException
 496.357 +    {
 496.358 +        if (h == null) {
 496.359 +            throw new NullPointerException();
 496.360 +        }
 496.361 +        throw new IllegalArgumentException();
 496.362 +    }
 496.363 +
 496.364 +    /**
 496.365 +     * Returns true if and only if the specified class was dynamically
 496.366 +     * generated to be a proxy class using the {@code getProxyClass}
 496.367 +     * method or the {@code newProxyInstance} method.
 496.368 +     *
 496.369 +     * <p>The reliability of this method is important for the ability
 496.370 +     * to use it to make security decisions, so its implementation should
 496.371 +     * not just test if the class in question extends {@code Proxy}.
 496.372 +     *
 496.373 +     * @param   cl the class to test
 496.374 +     * @return  {@code true} if the class is a proxy class and
 496.375 +     *          {@code false} otherwise
 496.376 +     * @throws  NullPointerException if {@code cl} is {@code null}
 496.377 +     */
 496.378 +    public static boolean isProxyClass(Class<?> cl) {
 496.379 +        if (cl == null) {
 496.380 +            throw new NullPointerException();
 496.381 +        }
 496.382 +
 496.383 +        return false;
 496.384 +    }
 496.385 +
 496.386 +    /**
 496.387 +     * Returns the invocation handler for the specified proxy instance.
 496.388 +     *
 496.389 +     * @param   proxy the proxy instance to return the invocation handler for
 496.390 +     * @return  the invocation handler for the proxy instance
 496.391 +     * @throws  IllegalArgumentException if the argument is not a
 496.392 +     *          proxy instance
 496.393 +     */
 496.394 +    public static InvocationHandler getInvocationHandler(Object proxy)
 496.395 +        throws IllegalArgumentException
 496.396 +    {
 496.397 +        /*
 496.398 +         * Verify that the object is actually a proxy instance.
 496.399 +         */
 496.400 +        if (!isProxyClass(proxy.getClass())) {
 496.401 +            throw new IllegalArgumentException("not a proxy instance");
 496.402 +        }
 496.403 +
 496.404 +        Proxy p = (Proxy) proxy;
 496.405 +        return p.h;
 496.406 +    }
 496.407 +
 496.408 +    private static native Class defineClass0(ClassLoader loader, String name,
 496.409 +                                             byte[] b, int off, int len);
 496.410 +}
   497.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   497.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Type.java	Wed Feb 27 11:24:58 2013 +0100
   497.3 @@ -0,0 +1,37 @@
   497.4 +/*
   497.5 + * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   497.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   497.7 + *
   497.8 + * This code is free software; you can redistribute it and/or modify it
   497.9 + * under the terms of the GNU General Public License version 2 only, as
  497.10 + * published by the Free Software Foundation.  Oracle designates this
  497.11 + * particular file as subject to the "Classpath" exception as provided
  497.12 + * by Oracle in the LICENSE file that accompanied this code.
  497.13 + *
  497.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  497.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  497.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  497.17 + * version 2 for more details (a copy is included in the LICENSE file that
  497.18 + * accompanied this code).
  497.19 + *
  497.20 + * You should have received a copy of the GNU General Public License version
  497.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  497.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  497.23 + *
  497.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  497.25 + * or visit www.oracle.com if you need additional information or have any
  497.26 + * questions.
  497.27 + */
  497.28 +
  497.29 +package java.lang.reflect;
  497.30 +
  497.31 +/**
  497.32 + * Type is the common superinterface for all types in the Java
  497.33 + * programming language. These include raw types, parameterized types,
  497.34 + * array types, type variables and primitive types.
  497.35 + *
  497.36 + * @since 1.5
  497.37 + */
  497.38 +
  497.39 +public interface Type {
  497.40 +}
   498.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   498.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/TypeVariable.java	Wed Feb 27 11:24:58 2013 +0100
   498.3 @@ -0,0 +1,89 @@
   498.4 +/*
   498.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
   498.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   498.7 + *
   498.8 + * This code is free software; you can redistribute it and/or modify it
   498.9 + * under the terms of the GNU General Public License version 2 only, as
  498.10 + * published by the Free Software Foundation.  Oracle designates this
  498.11 + * particular file as subject to the "Classpath" exception as provided
  498.12 + * by Oracle in the LICENSE file that accompanied this code.
  498.13 + *
  498.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  498.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  498.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  498.17 + * version 2 for more details (a copy is included in the LICENSE file that
  498.18 + * accompanied this code).
  498.19 + *
  498.20 + * You should have received a copy of the GNU General Public License version
  498.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  498.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  498.23 + *
  498.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  498.25 + * or visit www.oracle.com if you need additional information or have any
  498.26 + * questions.
  498.27 + */
  498.28 +
  498.29 +package java.lang.reflect;
  498.30 +
  498.31 +/**
  498.32 + * TypeVariable is the common superinterface for type variables of kinds.
  498.33 + * A type variable is created the first time it is needed by a reflective
  498.34 + * method, as specified in this package.  If a type variable t is referenced
  498.35 + * by a type (i.e, class, interface or annotation type) T, and T is declared
  498.36 + * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
  498.37 + * requires the resolution (see JVMS 5) of the ith enclosing class of T,
  498.38 + * for i = 0 to n, inclusive. Creating a type variable must not cause the
  498.39 + * creation of its bounds. Repeated creation of a type variable has no effect.
  498.40 + *
  498.41 + * <p>Multiple objects may be instantiated at run-time to
  498.42 + * represent a given type variable. Even though a type variable is
  498.43 + * created only once, this does not imply any requirement to cache
  498.44 + * instances representing the type variable. However, all instances
  498.45 + * representing a type variable must be equal() to each other.
  498.46 + * As a consequence, users of type variables must not rely on the identity
  498.47 + * of instances of classes implementing this interface.
  498.48 + *
  498.49 + * @param <D> the type of generic declaration that declared the
  498.50 + * underlying type variable.
  498.51 + *
  498.52 + * @since 1.5
  498.53 + */
  498.54 +public interface TypeVariable<D extends GenericDeclaration> extends Type {
  498.55 +    /**
  498.56 +     * Returns an array of {@code Type} objects representing the
  498.57 +     * upper bound(s) of this type variable.  Note that if no upper bound is
  498.58 +     * explicitly declared, the upper bound is {@code Object}.
  498.59 +     *
  498.60 +     * <p>For each upper bound B: <ul> <li>if B is a parameterized
  498.61 +     * type or a type variable, it is created, (see {@link
  498.62 +     * java.lang.reflect.ParameterizedType ParameterizedType} for the
  498.63 +     * details of the creation process for parameterized types).
  498.64 +     * <li>Otherwise, B is resolved.  </ul>
  498.65 +     *
  498.66 +     * @throws TypeNotPresentException  if any of the
  498.67 +     *     bounds refers to a non-existent type declaration
  498.68 +     * @throws MalformedParameterizedTypeException if any of the
  498.69 +     *     bounds refer to a parameterized type that cannot be instantiated
  498.70 +     *     for any reason
  498.71 +     * @return an array of {@code Type}s representing the upper
  498.72 +     *     bound(s) of this type variable
  498.73 +    */
  498.74 +    Type[] getBounds();
  498.75 +
  498.76 +    /**
  498.77 +     * Returns the {@code GenericDeclaration} object representing the
  498.78 +     * generic declaration declared this type variable.
  498.79 +     *
  498.80 +     * @return the generic declaration declared for this type variable.
  498.81 +     *
  498.82 +     * @since 1.5
  498.83 +     */
  498.84 +    D getGenericDeclaration();
  498.85 +
  498.86 +    /**
  498.87 +     * Returns the name of this type variable, as it occurs in the source code.
  498.88 +     *
  498.89 +     * @return the name of this type variable, as it appears in the source code
  498.90 +     */
  498.91 +    String getName();
  498.92 +}
   499.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   499.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/UndeclaredThrowableException.java	Wed Feb 27 11:24:58 2013 +0100
   499.3 @@ -0,0 +1,119 @@
   499.4 +/*
   499.5 + * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
   499.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   499.7 + *
   499.8 + * This code is free software; you can redistribute it and/or modify it
   499.9 + * under the terms of the GNU General Public License version 2 only, as
  499.10 + * published by the Free Software Foundation.  Oracle designates this
  499.11 + * particular file as subject to the "Classpath" exception as provided
  499.12 + * by Oracle in the LICENSE file that accompanied this code.
  499.13 + *
  499.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  499.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  499.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  499.17 + * version 2 for more details (a copy is included in the LICENSE file that
  499.18 + * accompanied this code).
  499.19 + *
  499.20 + * You should have received a copy of the GNU General Public License version
  499.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  499.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  499.23 + *
  499.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  499.25 + * or visit www.oracle.com if you need additional information or have any
  499.26 + * questions.
  499.27 + */
  499.28 +
  499.29 +package java.lang.reflect;
  499.30 +
  499.31 +/**
  499.32 + * Thrown by a method invocation on a proxy instance if its invocation
  499.33 + * handler's {@link InvocationHandler#invoke invoke} method throws a
  499.34 + * checked exception (a {@code Throwable} that is not assignable
  499.35 + * to {@code RuntimeException} or {@code Error}) that
  499.36 + * is not assignable to any of the exception types declared in the
  499.37 + * {@code throws} clause of the method that was invoked on the
  499.38 + * proxy instance and dispatched to the invocation handler.
  499.39 + *
  499.40 + * <p>An {@code UndeclaredThrowableException} instance contains
  499.41 + * the undeclared checked exception that was thrown by the invocation
  499.42 + * handler, and it can be retrieved with the
  499.43 + * {@code getUndeclaredThrowable()} method.
  499.44 + * {@code UndeclaredThrowableException} extends
  499.45 + * {@code RuntimeException}, so it is an unchecked exception
  499.46 + * that wraps a checked exception.
  499.47 + *
  499.48 + * <p>As of release 1.4, this exception has been retrofitted to
  499.49 + * conform to the general purpose exception-chaining mechanism.  The
  499.50 + * "undeclared checked exception that was thrown by the invocation
  499.51 + * handler" that may be provided at construction time and accessed via
  499.52 + * the {@link #getUndeclaredThrowable()} method is now known as the
  499.53 + * <i>cause</i>, and may be accessed via the {@link
  499.54 + * Throwable#getCause()} method, as well as the aforementioned "legacy
  499.55 + * method."
  499.56 + *
  499.57 + * @author      Peter Jones
  499.58 + * @see         InvocationHandler
  499.59 + * @since       1.3
  499.60 + */
  499.61 +public class UndeclaredThrowableException extends RuntimeException {
  499.62 +    static final long serialVersionUID = 330127114055056639L;
  499.63 +
  499.64 +    /**
  499.65 +     * the undeclared checked exception that was thrown
  499.66 +     * @serial
  499.67 +     */
  499.68 +    private Throwable undeclaredThrowable;
  499.69 +
  499.70 +    /**
  499.71 +     * Constructs an {@code UndeclaredThrowableException} with the
  499.72 +     * specified {@code Throwable}.
  499.73 +     *
  499.74 +     * @param   undeclaredThrowable the undeclared checked exception
  499.75 +     *          that was thrown
  499.76 +     */
  499.77 +    public UndeclaredThrowableException(Throwable undeclaredThrowable) {
  499.78 +        super((Throwable) null);  // Disallow initCause
  499.79 +        this.undeclaredThrowable = undeclaredThrowable;
  499.80 +    }
  499.81 +
  499.82 +    /**
  499.83 +     * Constructs an {@code UndeclaredThrowableException} with the
  499.84 +     * specified {@code Throwable} and a detail message.
  499.85 +     *
  499.86 +     * @param   undeclaredThrowable the undeclared checked exception
  499.87 +     *          that was thrown
  499.88 +     * @param   s the detail message
  499.89 +     */
  499.90 +    public UndeclaredThrowableException(Throwable undeclaredThrowable,
  499.91 +                                        String s)
  499.92 +    {
  499.93 +        super(s, null);  // Disallow initCause
  499.94 +        this.undeclaredThrowable = undeclaredThrowable;
  499.95 +    }
  499.96 +
  499.97 +    /**
  499.98 +     * Returns the {@code Throwable} instance wrapped in this
  499.99 +     * {@code UndeclaredThrowableException}, which may be {@code null}.
 499.100 +     *
 499.101 +     * <p>This method predates the general-purpose exception chaining facility.
 499.102 +     * The {@link Throwable#getCause()} method is now the preferred means of
 499.103 +     * obtaining this information.
 499.104 +     *
 499.105 +     * @return the undeclared checked exception that was thrown
 499.106 +     */
 499.107 +    public Throwable getUndeclaredThrowable() {
 499.108 +        return undeclaredThrowable;
 499.109 +    }
 499.110 +
 499.111 +    /**
 499.112 +     * Returns the cause of this exception (the {@code Throwable}
 499.113 +     * instance wrapped in this {@code UndeclaredThrowableException},
 499.114 +     * which may be {@code null}).
 499.115 +     *
 499.116 +     * @return  the cause of this exception.
 499.117 +     * @since   1.4
 499.118 +     */
 499.119 +    public Throwable getCause() {
 499.120 +        return undeclaredThrowable;
 499.121 +    }
 499.122 +}
   500.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   500.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/package-info.java	Wed Feb 27 11:24:58 2013 +0100
   500.3 @@ -0,0 +1,49 @@
   500.4 +/*
   500.5 + * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
   500.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   500.7 + *
   500.8 + * This code is free software; you can redistribute it and/or modify it
   500.9 + * under the terms of the GNU General Public License version 2 only, as
  500.10 + * published by the Free Software Foundation.  Oracle designates this
  500.11 + * particular file as subject to the "Classpath" exception as provided
  500.12 + * by Oracle in the LICENSE file that accompanied this code.
  500.13 + *
  500.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  500.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  500.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  500.17 + * version 2 for more details (a copy is included in the LICENSE file that
  500.18 + * accompanied this code).
  500.19 + *
  500.20 + * You should have received a copy of the GNU General Public License version
  500.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  500.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  500.23 + *
  500.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  500.25 + * or visit www.oracle.com if you need additional information or have any
  500.26 + * questions.
  500.27 + */
  500.28 +
  500.29 +/**
  500.30 + * Provides classes and interfaces for obtaining reflective
  500.31 + * information about classes and objects.  Reflection allows
  500.32 + * programmatic access to information about the fields, methods and
  500.33 + * constructors of loaded classes, and the use of reflected fields,
  500.34 + * methods, and constructors to operate on their underlying
  500.35 + * counterparts, within security restrictions.
  500.36 + *
  500.37 + * <p>{@code AccessibleObject} allows suppression of access checks if
  500.38 + * the necessary {@code ReflectPermission} is available.
  500.39 + *
  500.40 + * <p>{@code Array} provides static methods to dynamically create and
  500.41 + * access arrays.
  500.42 + *
  500.43 + * <p>Classes in this package, along with {@code java.lang.Class}
  500.44 + * accommodate applications such as debuggers, interpreters, object
  500.45 + * inspectors, class browsers, and services such as Object
  500.46 + * Serialization and JavaBeans that need access to either the public
  500.47 + * members of a target object (based on its runtime class) or the
  500.48 + * members declared by a given class.
  500.49 + *
  500.50 + * @since JDK1.1
  500.51 + */
  500.52 +package java.lang.reflect;
   501.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   501.2 +++ b/rt/emul/mini/src/main/java/java/net/MalformedURLException.java	Wed Feb 27 11:24:58 2013 +0100
   501.3 @@ -0,0 +1,56 @@
   501.4 +/*
   501.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   501.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   501.7 + *
   501.8 + * This code is free software; you can redistribute it and/or modify it
   501.9 + * under the terms of the GNU General Public License version 2 only, as
  501.10 + * published by the Free Software Foundation.  Oracle designates this
  501.11 + * particular file as subject to the "Classpath" exception as provided
  501.12 + * by Oracle in the LICENSE file that accompanied this code.
  501.13 + *
  501.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  501.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  501.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  501.17 + * version 2 for more details (a copy is included in the LICENSE file that
  501.18 + * accompanied this code).
  501.19 + *
  501.20 + * You should have received a copy of the GNU General Public License version
  501.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  501.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  501.23 + *
  501.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  501.25 + * or visit www.oracle.com if you need additional information or have any
  501.26 + * questions.
  501.27 + */
  501.28 +
  501.29 +package java.net;
  501.30 +
  501.31 +import java.io.IOException;
  501.32 +
  501.33 +/**
  501.34 + * Thrown to indicate that a malformed URL has occurred. Either no
  501.35 + * legal protocol could be found in a specification string or the
  501.36 + * string could not be parsed.
  501.37 + *
  501.38 + * @author  Arthur van Hoff
  501.39 + * @since   JDK1.0
  501.40 + */
  501.41 +public class MalformedURLException extends IOException {
  501.42 +    private static final long serialVersionUID = -182787522200415866L;
  501.43 +
  501.44 +    /**
  501.45 +     * Constructs a <code>MalformedURLException</code> with no detail message.
  501.46 +     */
  501.47 +    public MalformedURLException() {
  501.48 +    }
  501.49 +
  501.50 +    /**
  501.51 +     * Constructs a <code>MalformedURLException</code> with the
  501.52 +     * specified detail message.
  501.53 +     *
  501.54 +     * @param   msg   the detail message.
  501.55 +     */
  501.56 +    public MalformedURLException(String msg) {
  501.57 +        super(msg);
  501.58 +    }
  501.59 +}
   502.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   502.2 +++ b/rt/emul/mini/src/main/java/java/net/URL.java	Wed Feb 27 11:24:58 2013 +0100
   502.3 @@ -0,0 +1,1090 @@
   502.4 +/*
   502.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
   502.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   502.7 + *
   502.8 + * This code is free software; you can redistribute it and/or modify it
   502.9 + * under the terms of the GNU General Public License version 2 only, as
  502.10 + * published by the Free Software Foundation.  Oracle designates this
  502.11 + * particular file as subject to the "Classpath" exception as provided
  502.12 + * by Oracle in the LICENSE file that accompanied this code.
  502.13 + *
  502.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  502.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  502.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  502.17 + * version 2 for more details (a copy is included in the LICENSE file that
  502.18 + * accompanied this code).
  502.19 + *
  502.20 + * You should have received a copy of the GNU General Public License version
  502.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  502.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  502.23 + *
  502.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  502.25 + * or visit www.oracle.com if you need additional information or have any
  502.26 + * questions.
  502.27 + */
  502.28 +
  502.29 +package java.net;
  502.30 +
  502.31 +import java.io.ByteArrayInputStream;
  502.32 +import java.io.IOException;
  502.33 +import java.io.InputStream;
  502.34 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  502.35 +
  502.36 +
  502.37 +/**
  502.38 + * Class <code>URL</code> represents a Uniform Resource
  502.39 + * Locator, a pointer to a "resource" on the World
  502.40 + * Wide Web. A resource can be something as simple as a file or a
  502.41 + * directory, or it can be a reference to a more complicated object,
  502.42 + * such as a query to a database or to a search engine. More
  502.43 + * information on the types of URLs and their formats can be found at:
  502.44 + * <blockquote>
  502.45 + *     <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
  502.46 + *    <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
  502.47 + * </blockquote>
  502.48 + * <p>
  502.49 + * In general, a URL can be broken into several parts. The previous
  502.50 + * example of a URL indicates that the protocol to use is
  502.51 + * <code>http</code> (HyperText Transfer Protocol) and that the
  502.52 + * information resides on a host machine named
  502.53 + * <code>www.socs.uts.edu.au</code>. The information on that host
  502.54 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
  502.55 + * meaning of this name on the host machine is both protocol
  502.56 + * dependent and host dependent. The information normally resides in
  502.57 + * a file, but it could be generated on the fly. This component of
  502.58 + * the URL is called the <i>path</i> component.
  502.59 + * <p>
  502.60 + * A URL can optionally specify a "port", which is the
  502.61 + * port number to which the TCP connection is made on the remote host
  502.62 + * machine. If the port is not specified, the default port for
  502.63 + * the protocol is used instead. For example, the default port for
  502.64 + * <code>http</code> is <code>80</code>. An alternative port could be
  502.65 + * specified as:
  502.66 + * <blockquote><pre>
  502.67 + *     http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
  502.68 + * </pre></blockquote>
  502.69 + * <p>
  502.70 + * The syntax of <code>URL</code> is defined by  <a
  502.71 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
  502.72 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
  502.73 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
  502.74 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
  502.75 + * also supports scope_ids. The syntax and usage of scope_ids is described
  502.76 + * <a href="Inet6Address.html#scoped">here</a>.
  502.77 + * <p>
  502.78 + * A URL may have appended to it a "fragment", also known
  502.79 + * as a "ref" or a "reference". The fragment is indicated by the sharp
  502.80 + * sign character "#" followed by more characters. For example,
  502.81 + * <blockquote><pre>
  502.82 + *     http://java.sun.com/index.html#chapter1
  502.83 + * </pre></blockquote>
  502.84 + * <p>
  502.85 + * This fragment is not technically part of the URL. Rather, it
  502.86 + * indicates that after the specified resource is retrieved, the
  502.87 + * application is specifically interested in that part of the
  502.88 + * document that has the tag <code>chapter1</code> attached to it. The
  502.89 + * meaning of a tag is resource specific.
  502.90 + * <p>
  502.91 + * An application can also specify a "relative URL",
  502.92 + * which contains only enough information to reach the resource
  502.93 + * relative to another URL. Relative URLs are frequently used within
  502.94 + * HTML pages. For example, if the contents of the URL:
  502.95 + * <blockquote><pre>
  502.96 + *     http://java.sun.com/index.html
  502.97 + * </pre></blockquote>
  502.98 + * contained within it the relative URL:
  502.99 + * <blockquote><pre>
 502.100 + *     FAQ.html
 502.101 + * </pre></blockquote>
 502.102 + * it would be a shorthand for:
 502.103 + * <blockquote><pre>
 502.104 + *     http://java.sun.com/FAQ.html
 502.105 + * </pre></blockquote>
 502.106 + * <p>
 502.107 + * The relative URL need not specify all the components of a URL. If
 502.108 + * the protocol, host name, or port number is missing, the value is
 502.109 + * inherited from the fully specified URL. The file component must be
 502.110 + * specified. The optional fragment is not inherited.
 502.111 + * <p>
 502.112 + * The URL class does not itself encode or decode any URL components
 502.113 + * according to the escaping mechanism defined in RFC2396. It is the
 502.114 + * responsibility of the caller to encode any fields, which need to be
 502.115 + * escaped prior to calling URL, and also to decode any escaped fields,
 502.116 + * that are returned from URL. Furthermore, because URL has no knowledge
 502.117 + * of URL escaping, it does not recognise equivalence between the encoded
 502.118 + * or decoded form of the same URL. For example, the two URLs:<br>
 502.119 + * <pre>    http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
 502.120 + * would be considered not equal to each other.
 502.121 + * <p>
 502.122 + * Note, the {@link java.net.URI} class does perform escaping of its
 502.123 + * component fields in certain circumstances. The recommended way
 502.124 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
 502.125 + * and to convert between these two classes using {@link #toURI()} and
 502.126 + * {@link URI#toURL()}.
 502.127 + * <p>
 502.128 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
 502.129 + * used, but only for HTML form encoding, which is not the same
 502.130 + * as the encoding scheme defined in RFC2396.
 502.131 + *
 502.132 + * @author  James Gosling
 502.133 + * @since JDK1.0
 502.134 + */
 502.135 +public final class URL implements java.io.Serializable {
 502.136 +
 502.137 +    static final long serialVersionUID = -7627629688361524110L;
 502.138 +
 502.139 +    /**
 502.140 +     * The property which specifies the package prefix list to be scanned
 502.141 +     * for protocol handlers.  The value of this property (if any) should
 502.142 +     * be a vertical bar delimited list of package names to search through
 502.143 +     * for a protocol handler to load.  The policy of this class is that
 502.144 +     * all protocol handlers will be in a class called <protocolname>.Handler,
 502.145 +     * and each package in the list is examined in turn for a matching
 502.146 +     * handler.  If none are found (or the property is not specified), the
 502.147 +     * default package prefix, sun.net.www.protocol, is used.  The search
 502.148 +     * proceeds from the first package in the list to the last and stops
 502.149 +     * when a match is found.
 502.150 +     */
 502.151 +    private static final String protocolPathProp = "java.protocol.handler.pkgs";
 502.152 +
 502.153 +    /**
 502.154 +     * The protocol to use (ftp, http, nntp, ... etc.) .
 502.155 +     * @serial
 502.156 +     */
 502.157 +    private String protocol;
 502.158 +
 502.159 +    /**
 502.160 +     * The host name to connect to.
 502.161 +     * @serial
 502.162 +     */
 502.163 +    private String host;
 502.164 +
 502.165 +    /**
 502.166 +     * The protocol port to connect to.
 502.167 +     * @serial
 502.168 +     */
 502.169 +    private int port = -1;
 502.170 +
 502.171 +    /**
 502.172 +     * The specified file name on that host. <code>file</code> is
 502.173 +     * defined as <code>path[?query]</code>
 502.174 +     * @serial
 502.175 +     */
 502.176 +    private String file;
 502.177 +
 502.178 +    /**
 502.179 +     * The query part of this URL.
 502.180 +     */
 502.181 +    private transient String query;
 502.182 +
 502.183 +    /**
 502.184 +     * The authority part of this URL.
 502.185 +     * @serial
 502.186 +     */
 502.187 +    private String authority;
 502.188 +
 502.189 +    /**
 502.190 +     * The path part of this URL.
 502.191 +     */
 502.192 +    private transient String path;
 502.193 +
 502.194 +    /**
 502.195 +     * The userinfo part of this URL.
 502.196 +     */
 502.197 +    private transient String userInfo;
 502.198 +
 502.199 +    /**
 502.200 +     * # reference.
 502.201 +     * @serial
 502.202 +     */
 502.203 +    private String ref;
 502.204 +
 502.205 +    /**
 502.206 +     * The host's IP address, used in equals and hashCode.
 502.207 +     * Computed on demand. An uninitialized or unknown hostAddress is null.
 502.208 +     */
 502.209 +    transient Object hostAddress;
 502.210 +
 502.211 +    /**
 502.212 +     * The URLStreamHandler for this URL.
 502.213 +     */
 502.214 +    transient URLStreamHandler handler;
 502.215 +
 502.216 +    /* Our hash code.
 502.217 +     * @serial
 502.218 +     */
 502.219 +    private int hashCode = -1;
 502.220 +    
 502.221 +    /** input stream associated with the URL */
 502.222 +    private InputStream is;
 502.223 +
 502.224 +    /**
 502.225 +     * Creates a <code>URL</code> object from the specified
 502.226 +     * <code>protocol</code>, <code>host</code>, <code>port</code>
 502.227 +     * number, and <code>file</code>.<p>
 502.228 +     *
 502.229 +     * <code>host</code> can be expressed as a host name or a literal
 502.230 +     * IP address. If IPv6 literal address is used, it should be
 502.231 +     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
 502.232 +     * specified by <a
 502.233 +     * href="http://www.ietf.org/rfc/rfc2732.txt">RFC&nbsp;2732</a>;
 502.234 +     * However, the literal IPv6 address format defined in <a
 502.235 +     * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
 502.236 +     * Version 6 Addressing Architecture</i></a> is also accepted.<p>
 502.237 +     *
 502.238 +     * Specifying a <code>port</code> number of <code>-1</code>
 502.239 +     * indicates that the URL should use the default port for the
 502.240 +     * protocol.<p>
 502.241 +     *
 502.242 +     * If this is the first URL object being created with the specified
 502.243 +     * protocol, a <i>stream protocol handler</i> object, an instance of
 502.244 +     * class <code>URLStreamHandler</code>, is created for that protocol:
 502.245 +     * <ol>
 502.246 +     * <li>If the application has previously set up an instance of
 502.247 +     *     <code>URLStreamHandlerFactory</code> as the stream handler factory,
 502.248 +     *     then the <code>createURLStreamHandler</code> method of that instance
 502.249 +     *     is called with the protocol string as an argument to create the
 502.250 +     *     stream protocol handler.
 502.251 +     * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
 502.252 +     *     or if the factory's <code>createURLStreamHandler</code> method
 502.253 +     *     returns <code>null</code>, then the constructor finds the
 502.254 +     *     value of the system property:
 502.255 +     *     <blockquote><pre>
 502.256 +     *         java.protocol.handler.pkgs
 502.257 +     *     </pre></blockquote>
 502.258 +     *     If the value of that system property is not <code>null</code>,
 502.259 +     *     it is interpreted as a list of packages separated by a vertical
 502.260 +     *     slash character '<code>|</code>'. The constructor tries to load
 502.261 +     *     the class named:
 502.262 +     *     <blockquote><pre>
 502.263 +     *         &lt;<i>package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 502.264 +     *     </pre></blockquote>
 502.265 +     *     where &lt;<i>package</i>&gt; is replaced by the name of the package
 502.266 +     *     and &lt;<i>protocol</i>&gt; is replaced by the name of the protocol.
 502.267 +     *     If this class does not exist, or if the class exists but it is not
 502.268 +     *     a subclass of <code>URLStreamHandler</code>, then the next package
 502.269 +     *     in the list is tried.
 502.270 +     * <li>If the previous step fails to find a protocol handler, then the
 502.271 +     *     constructor tries to load from a system default package.
 502.272 +     *     <blockquote><pre>
 502.273 +     *         &lt;<i>system default package</i>&gt;.&lt;<i>protocol</i>&gt;.Handler
 502.274 +     *     </pre></blockquote>
 502.275 +     *     If this class does not exist, or if the class exists but it is not a
 502.276 +     *     subclass of <code>URLStreamHandler</code>, then a
 502.277 +     *     <code>MalformedURLException</code> is thrown.
 502.278 +     * </ol>
 502.279 +     *
 502.280 +     * <p>Protocol handlers for the following protocols are guaranteed
 502.281 +     * to exist on the search path :-
 502.282 +     * <blockquote><pre>
 502.283 +     *     http, https, ftp, file, and jar
 502.284 +     * </pre></blockquote>
 502.285 +     * Protocol handlers for additional protocols may also be
 502.286 +     * available.
 502.287 +     *
 502.288 +     * <p>No validation of the inputs is performed by this constructor.
 502.289 +     *
 502.290 +     * @param      protocol   the name of the protocol to use.
 502.291 +     * @param      host       the name of the host.
 502.292 +     * @param      port       the port number on the host.
 502.293 +     * @param      file       the file on the host
 502.294 +     * @exception  MalformedURLException  if an unknown protocol is specified.
 502.295 +     * @see        java.lang.System#getProperty(java.lang.String)
 502.296 +     * @see        java.net.URL#setURLStreamHandlerFactory(
 502.297 +     *                  java.net.URLStreamHandlerFactory)
 502.298 +     * @see        java.net.URLStreamHandler
 502.299 +     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 502.300 +     *                  java.lang.String)
 502.301 +     */
 502.302 +    public URL(String protocol, String host, int port, String file)
 502.303 +        throws MalformedURLException
 502.304 +    {
 502.305 +        this(protocol, host, port, file, null);
 502.306 +    }
 502.307 +
 502.308 +    /**
 502.309 +     * Creates a URL from the specified <code>protocol</code>
 502.310 +     * name, <code>host</code> name, and <code>file</code> name. The
 502.311 +     * default port for the specified protocol is used.
 502.312 +     * <p>
 502.313 +     * This method is equivalent to calling the four-argument
 502.314 +     * constructor with the arguments being <code>protocol</code>,
 502.315 +     * <code>host</code>, <code>-1</code>, and <code>file</code>.
 502.316 +     *
 502.317 +     * No validation of the inputs is performed by this constructor.
 502.318 +     *
 502.319 +     * @param      protocol   the name of the protocol to use.
 502.320 +     * @param      host       the name of the host.
 502.321 +     * @param      file       the file on the host.
 502.322 +     * @exception  MalformedURLException  if an unknown protocol is specified.
 502.323 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 502.324 +     *                  int, java.lang.String)
 502.325 +     */
 502.326 +    public URL(String protocol, String host, String file)
 502.327 +            throws MalformedURLException {
 502.328 +        this(protocol, host, -1, file);
 502.329 +    }
 502.330 +
 502.331 +    /**
 502.332 +     * Creates a <code>URL</code> object from the specified
 502.333 +     * <code>protocol</code>, <code>host</code>, <code>port</code>
 502.334 +     * number, <code>file</code>, and <code>handler</code>. Specifying
 502.335 +     * a <code>port</code> number of <code>-1</code> indicates that
 502.336 +     * the URL should use the default port for the protocol. Specifying
 502.337 +     * a <code>handler</code> of <code>null</code> indicates that the URL
 502.338 +     * should use a default stream handler for the protocol, as outlined
 502.339 +     * for:
 502.340 +     *     java.net.URL#URL(java.lang.String, java.lang.String, int,
 502.341 +     *                      java.lang.String)
 502.342 +     *
 502.343 +     * <p>If the handler is not null and there is a security manager,
 502.344 +     * the security manager's <code>checkPermission</code>
 502.345 +     * method is called with a
 502.346 +     * <code>NetPermission("specifyStreamHandler")</code> permission.
 502.347 +     * This may result in a SecurityException.
 502.348 +     *
 502.349 +     * No validation of the inputs is performed by this constructor.
 502.350 +     *
 502.351 +     * @param      protocol   the name of the protocol to use.
 502.352 +     * @param      host       the name of the host.
 502.353 +     * @param      port       the port number on the host.
 502.354 +     * @param      file       the file on the host
 502.355 +     * @param      handler    the stream handler for the URL.
 502.356 +     * @exception  MalformedURLException  if an unknown protocol is specified.
 502.357 +     * @exception  SecurityException
 502.358 +     *        if a security manager exists and its
 502.359 +     *        <code>checkPermission</code> method doesn't allow
 502.360 +     *        specifying a stream handler explicitly.
 502.361 +     * @see        java.lang.System#getProperty(java.lang.String)
 502.362 +     * @see        java.net.URL#setURLStreamHandlerFactory(
 502.363 +     *                  java.net.URLStreamHandlerFactory)
 502.364 +     * @see        java.net.URLStreamHandler
 502.365 +     * @see        java.net.URLStreamHandlerFactory#createURLStreamHandler(
 502.366 +     *                  java.lang.String)
 502.367 +     * @see        SecurityManager#checkPermission
 502.368 +     * @see        java.net.NetPermission
 502.369 +     */
 502.370 +    public URL(String protocol, String host, int port, String file,
 502.371 +               URLStreamHandler handler) throws MalformedURLException {
 502.372 +        if (handler != null) {
 502.373 +            throw new SecurityException();
 502.374 +        }
 502.375 +
 502.376 +        protocol = protocol.toLowerCase();
 502.377 +        this.protocol = protocol;
 502.378 +        if (host != null) {
 502.379 +
 502.380 +            /**
 502.381 +             * if host is a literal IPv6 address,
 502.382 +             * we will make it conform to RFC 2732
 502.383 +             */
 502.384 +            if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
 502.385 +                host = "["+host+"]";
 502.386 +            }
 502.387 +            this.host = host;
 502.388 +
 502.389 +            if (port < -1) {
 502.390 +                throw new MalformedURLException("Invalid port number :" +
 502.391 +                                                    port);
 502.392 +            }
 502.393 +            this.port = port;
 502.394 +            authority = (port == -1) ? host : host + ":" + port;
 502.395 +        }
 502.396 +
 502.397 +        Parts parts = new Parts(file);
 502.398 +        path = parts.getPath();
 502.399 +        query = parts.getQuery();
 502.400 +
 502.401 +        if (query != null) {
 502.402 +            this.file = path + "?" + query;
 502.403 +        } else {
 502.404 +            this.file = path;
 502.405 +        }
 502.406 +        ref = parts.getRef();
 502.407 +
 502.408 +        // Note: we don't do validation of the URL here. Too risky to change
 502.409 +        // right now, but worth considering for future reference. -br
 502.410 +        if (handler == null &&
 502.411 +            (handler = getURLStreamHandler(protocol)) == null) {
 502.412 +            throw new MalformedURLException("unknown protocol: " + protocol);
 502.413 +        }
 502.414 +        this.handler = handler;
 502.415 +    }
 502.416 +
 502.417 +    /**
 502.418 +     * Creates a <code>URL</code> object from the <code>String</code>
 502.419 +     * representation.
 502.420 +     * <p>
 502.421 +     * This constructor is equivalent to a call to the two-argument
 502.422 +     * constructor with a <code>null</code> first argument.
 502.423 +     *
 502.424 +     * @param      spec   the <code>String</code> to parse as a URL.
 502.425 +     * @exception  MalformedURLException  if no protocol is specified, or an
 502.426 +     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 502.427 +     * @see        java.net.URL#URL(java.net.URL, java.lang.String)
 502.428 +     */
 502.429 +    public URL(String spec) throws MalformedURLException {
 502.430 +        this(null, spec);
 502.431 +    }
 502.432 +    
 502.433 +    private URL(String spec, InputStream is) throws MalformedURLException {
 502.434 +        this(null, spec);
 502.435 +        this.is = is;
 502.436 +    }
 502.437 +
 502.438 +    /**
 502.439 +     * Creates a URL by parsing the given spec within a specified context.
 502.440 +     *
 502.441 +     * The new URL is created from the given context URL and the spec
 502.442 +     * argument as described in
 502.443 +     * RFC2396 &quot;Uniform Resource Identifiers : Generic * Syntax&quot; :
 502.444 +     * <blockquote><pre>
 502.445 +     *          &lt;scheme&gt;://&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;
 502.446 +     * </pre></blockquote>
 502.447 +     * The reference is parsed into the scheme, authority, path, query and
 502.448 +     * fragment parts. If the path component is empty and the scheme,
 502.449 +     * authority, and query components are undefined, then the new URL is a
 502.450 +     * reference to the current document. Otherwise, the fragment and query
 502.451 +     * parts present in the spec are used in the new URL.
 502.452 +     * <p>
 502.453 +     * If the scheme component is defined in the given spec and does not match
 502.454 +     * the scheme of the context, then the new URL is created as an absolute
 502.455 +     * URL based on the spec alone. Otherwise the scheme component is inherited
 502.456 +     * from the context URL.
 502.457 +     * <p>
 502.458 +     * If the authority component is present in the spec then the spec is
 502.459 +     * treated as absolute and the spec authority and path will replace the
 502.460 +     * context authority and path. If the authority component is absent in the
 502.461 +     * spec then the authority of the new URL will be inherited from the
 502.462 +     * context.
 502.463 +     * <p>
 502.464 +     * If the spec's path component begins with a slash character
 502.465 +     * &quot;/&quot; then the
 502.466 +     * path is treated as absolute and the spec path replaces the context path.
 502.467 +     * <p>
 502.468 +     * Otherwise, the path is treated as a relative path and is appended to the
 502.469 +     * context path, as described in RFC2396. Also, in this case,
 502.470 +     * the path is canonicalized through the removal of directory
 502.471 +     * changes made by occurences of &quot;..&quot; and &quot;.&quot;.
 502.472 +     * <p>
 502.473 +     * For a more detailed description of URL parsing, refer to RFC2396.
 502.474 +     *
 502.475 +     * @param      context   the context in which to parse the specification.
 502.476 +     * @param      spec      the <code>String</code> to parse as a URL.
 502.477 +     * @exception  MalformedURLException  if no protocol is specified, or an
 502.478 +     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 502.479 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 502.480 +     *                  int, java.lang.String)
 502.481 +     * @see        java.net.URLStreamHandler
 502.482 +     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 502.483 +     *                  java.lang.String, int, int)
 502.484 +     */
 502.485 +    public URL(URL context, String spec) throws MalformedURLException {
 502.486 +        this(context, spec, null);
 502.487 +    }
 502.488 +
 502.489 +    /**
 502.490 +     * Creates a URL by parsing the given spec with the specified handler
 502.491 +     * within a specified context. If the handler is null, the parsing
 502.492 +     * occurs as with the two argument constructor.
 502.493 +     *
 502.494 +     * @param      context   the context in which to parse the specification.
 502.495 +     * @param      spec      the <code>String</code> to parse as a URL.
 502.496 +     * @param      handler   the stream handler for the URL.
 502.497 +     * @exception  MalformedURLException  if no protocol is specified, or an
 502.498 +     *               unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
 502.499 +     * @exception  SecurityException
 502.500 +     *        if a security manager exists and its
 502.501 +     *        <code>checkPermission</code> method doesn't allow
 502.502 +     *        specifying a stream handler.
 502.503 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 502.504 +     *                  int, java.lang.String)
 502.505 +     * @see        java.net.URLStreamHandler
 502.506 +     * @see        java.net.URLStreamHandler#parseURL(java.net.URL,
 502.507 +     *                  java.lang.String, int, int)
 502.508 +     */
 502.509 +    public URL(URL context, String spec, URLStreamHandler handler)
 502.510 +        throws MalformedURLException
 502.511 +    {
 502.512 +        this(findContext(context), spec, handler != null);
 502.513 +    }
 502.514 +    
 502.515 +    private URL(URL context, String spec, boolean ishandler)
 502.516 +    throws MalformedURLException {
 502.517 +        // Check for permission to specify a handler
 502.518 +        if (ishandler) {
 502.519 +            throw new SecurityException();
 502.520 +        }
 502.521 +        URLStreamHandler handler = null;
 502.522 +        
 502.523 +        String original = spec;
 502.524 +        int i, limit, c;
 502.525 +        int start = 0;
 502.526 +        String newProtocol = null;
 502.527 +        boolean aRef=false;
 502.528 +        boolean isRelative = false;
 502.529 +
 502.530 +
 502.531 +        try {
 502.532 +            limit = spec.length();
 502.533 +            while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
 502.534 +                limit--;        //eliminate trailing whitespace
 502.535 +            }
 502.536 +            while ((start < limit) && (spec.charAt(start) <= ' ')) {
 502.537 +                start++;        // eliminate leading whitespace
 502.538 +            }
 502.539 +
 502.540 +            if (spec.regionMatches(true, start, "url:", 0, 4)) {
 502.541 +                start += 4;
 502.542 +            }
 502.543 +            if (start < spec.length() && spec.charAt(start) == '#') {
 502.544 +                /* we're assuming this is a ref relative to the context URL.
 502.545 +                 * This means protocols cannot start w/ '#', but we must parse
 502.546 +                 * ref URL's like: "hello:there" w/ a ':' in them.
 502.547 +                 */
 502.548 +                aRef=true;
 502.549 +            }
 502.550 +            for (i = start ; !aRef && (i < limit) &&
 502.551 +                     ((c = spec.charAt(i)) != '/') ; i++) {
 502.552 +                if (c == ':') {
 502.553 +
 502.554 +                    String s = spec.substring(start, i).toLowerCase();
 502.555 +                    if (isValidProtocol(s)) {
 502.556 +                        newProtocol = s;
 502.557 +                        start = i + 1;
 502.558 +                    }
 502.559 +                    break;
 502.560 +                }
 502.561 +            }
 502.562 +
 502.563 +            // Only use our context if the protocols match.
 502.564 +            protocol = newProtocol;
 502.565 +            if ((context != null) && ((newProtocol == null) ||
 502.566 +                            newProtocol.equalsIgnoreCase(context.protocol))) {
 502.567 +                // inherit the protocol handler from the context
 502.568 +                // if not specified to the constructor
 502.569 +                if (handler == null) {
 502.570 +                    handler = context.handler;
 502.571 +                }
 502.572 +
 502.573 +                // If the context is a hierarchical URL scheme and the spec
 502.574 +                // contains a matching scheme then maintain backwards
 502.575 +                // compatibility and treat it as if the spec didn't contain
 502.576 +                // the scheme; see 5.2.3 of RFC2396
 502.577 +                if (context.path != null && context.path.startsWith("/"))
 502.578 +                    newProtocol = null;
 502.579 +
 502.580 +                if (newProtocol == null) {
 502.581 +                    protocol = context.protocol;
 502.582 +                    authority = context.authority;
 502.583 +                    userInfo = context.userInfo;
 502.584 +                    host = context.host;
 502.585 +                    port = context.port;
 502.586 +                    file = context.file;
 502.587 +                    path = context.path;
 502.588 +                    isRelative = true;
 502.589 +                }
 502.590 +            }
 502.591 +
 502.592 +            if (protocol == null) {
 502.593 +                throw new MalformedURLException("no protocol: "+original);
 502.594 +            }
 502.595 +
 502.596 +            // Get the protocol handler if not specified or the protocol
 502.597 +            // of the context could not be used
 502.598 +            if (handler == null &&
 502.599 +                (handler = getURLStreamHandler(protocol)) == null) {
 502.600 +                throw new MalformedURLException("unknown protocol: "+protocol);
 502.601 +            }
 502.602 +            this.handler = handler;
 502.603 +
 502.604 +            i = spec.indexOf('#', start);
 502.605 +            if (i >= 0) {
 502.606 +//thrw(protocol + " hnd: " + handler.getClass().getName() + " i: " + i);
 502.607 +                ref = spec.substring(i + 1, limit);
 502.608 +                limit = i;
 502.609 +            }
 502.610 +
 502.611 +            /*
 502.612 +             * Handle special case inheritance of query and fragment
 502.613 +             * implied by RFC2396 section 5.2.2.
 502.614 +             */
 502.615 +            if (isRelative && start == limit) {
 502.616 +                query = context.query;
 502.617 +                if (ref == null) {
 502.618 +                    ref = context.ref;
 502.619 +                }
 502.620 +            }
 502.621 +
 502.622 +            handler.parseURL(this, spec, start, limit);
 502.623 +
 502.624 +        } catch(MalformedURLException e) {
 502.625 +            throw e;
 502.626 +        } catch(Exception e) {
 502.627 +            MalformedURLException exception = new MalformedURLException(e.getMessage());
 502.628 +            exception.initCause(e);
 502.629 +            throw exception;
 502.630 +        }
 502.631 +    }
 502.632 +    
 502.633 +    /*
 502.634 +     * Returns true if specified string is a valid protocol name.
 502.635 +     */
 502.636 +    private boolean isValidProtocol(String protocol) {
 502.637 +        int len = protocol.length();
 502.638 +        if (len < 1)
 502.639 +            return false;
 502.640 +        char c = protocol.charAt(0);
 502.641 +        if (!Character.isLetter(c))
 502.642 +            return false;
 502.643 +        for (int i = 1; i < len; i++) {
 502.644 +            c = protocol.charAt(i);
 502.645 +            if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
 502.646 +                c != '-') {
 502.647 +                return false;
 502.648 +            }
 502.649 +        }
 502.650 +        return true;
 502.651 +    }
 502.652 +
 502.653 +    /**
 502.654 +     * Sets the fields of the URL. This is not a public method so that
 502.655 +     * only URLStreamHandlers can modify URL fields. URLs are
 502.656 +     * otherwise constant.
 502.657 +     *
 502.658 +     * @param protocol the name of the protocol to use
 502.659 +     * @param host the name of the host
 502.660 +       @param port the port number on the host
 502.661 +     * @param file the file on the host
 502.662 +     * @param ref the internal reference in the URL
 502.663 +     */
 502.664 +    protected void set(String protocol, String host,
 502.665 +                       int port, String file, String ref) {
 502.666 +        synchronized (this) {
 502.667 +            this.protocol = protocol;
 502.668 +            this.host = host;
 502.669 +            authority = port == -1 ? host : host + ":" + port;
 502.670 +            this.port = port;
 502.671 +            this.file = file;
 502.672 +            this.ref = ref;
 502.673 +            /* This is very important. We must recompute this after the
 502.674 +             * URL has been changed. */
 502.675 +            hashCode = -1;
 502.676 +            hostAddress = null;
 502.677 +            int q = file.lastIndexOf('?');
 502.678 +            if (q != -1) {
 502.679 +                query = file.substring(q+1);
 502.680 +                path = file.substring(0, q);
 502.681 +            } else
 502.682 +                path = file;
 502.683 +        }
 502.684 +    }
 502.685 +
 502.686 +    /**
 502.687 +     * Sets the specified 8 fields of the URL. This is not a public method so
 502.688 +     * that only URLStreamHandlers can modify URL fields. URLs are otherwise
 502.689 +     * constant.
 502.690 +     *
 502.691 +     * @param protocol the name of the protocol to use
 502.692 +     * @param host the name of the host
 502.693 +     * @param port the port number on the host
 502.694 +     * @param authority the authority part for the url
 502.695 +     * @param userInfo the username and password
 502.696 +     * @param path the file on the host
 502.697 +     * @param ref the internal reference in the URL
 502.698 +     * @param query the query part of this URL
 502.699 +     * @since 1.3
 502.700 +     */
 502.701 +    protected void set(String protocol, String host, int port,
 502.702 +                       String authority, String userInfo, String path,
 502.703 +                       String query, String ref) {
 502.704 +        synchronized (this) {
 502.705 +            this.protocol = protocol;
 502.706 +            this.host = host;
 502.707 +            this.port = port;
 502.708 +            this.file = query == null ? path : path + "?" + query;
 502.709 +            this.userInfo = userInfo;
 502.710 +            this.path = path;
 502.711 +            this.ref = ref;
 502.712 +            /* This is very important. We must recompute this after the
 502.713 +             * URL has been changed. */
 502.714 +            hashCode = -1;
 502.715 +            hostAddress = null;
 502.716 +            this.query = query;
 502.717 +            this.authority = authority;
 502.718 +        }
 502.719 +    }
 502.720 +
 502.721 +    /**
 502.722 +     * Gets the query part of this <code>URL</code>.
 502.723 +     *
 502.724 +     * @return  the query part of this <code>URL</code>,
 502.725 +     * or <CODE>null</CODE> if one does not exist
 502.726 +     * @since 1.3
 502.727 +     */
 502.728 +    public String getQuery() {
 502.729 +        return query;
 502.730 +    }
 502.731 +
 502.732 +    /**
 502.733 +     * Gets the path part of this <code>URL</code>.
 502.734 +     *
 502.735 +     * @return  the path part of this <code>URL</code>, or an
 502.736 +     * empty string if one does not exist
 502.737 +     * @since 1.3
 502.738 +     */
 502.739 +    public String getPath() {
 502.740 +        return path;
 502.741 +    }
 502.742 +
 502.743 +    /**
 502.744 +     * Gets the userInfo part of this <code>URL</code>.
 502.745 +     *
 502.746 +     * @return  the userInfo part of this <code>URL</code>, or
 502.747 +     * <CODE>null</CODE> if one does not exist
 502.748 +     * @since 1.3
 502.749 +     */
 502.750 +    public String getUserInfo() {
 502.751 +        return userInfo;
 502.752 +    }
 502.753 +
 502.754 +    /**
 502.755 +     * Gets the authority part of this <code>URL</code>.
 502.756 +     *
 502.757 +     * @return  the authority part of this <code>URL</code>
 502.758 +     * @since 1.3
 502.759 +     */
 502.760 +    public String getAuthority() {
 502.761 +        return authority;
 502.762 +    }
 502.763 +
 502.764 +    /**
 502.765 +     * Gets the port number of this <code>URL</code>.
 502.766 +     *
 502.767 +     * @return  the port number, or -1 if the port is not set
 502.768 +     */
 502.769 +    public int getPort() {
 502.770 +        return port;
 502.771 +    }
 502.772 +
 502.773 +    /**
 502.774 +     * Gets the default port number of the protocol associated
 502.775 +     * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
 502.776 +     * for the URL do not define a default port number,
 502.777 +     * then -1 is returned.
 502.778 +     *
 502.779 +     * @return  the port number
 502.780 +     * @since 1.4
 502.781 +     */
 502.782 +    public int getDefaultPort() {
 502.783 +        return handler.getDefaultPort();
 502.784 +    }
 502.785 +
 502.786 +    /**
 502.787 +     * Gets the protocol name of this <code>URL</code>.
 502.788 +     *
 502.789 +     * @return  the protocol of this <code>URL</code>.
 502.790 +     */
 502.791 +    public String getProtocol() {
 502.792 +        return protocol;
 502.793 +    }
 502.794 +
 502.795 +    /**
 502.796 +     * Gets the host name of this <code>URL</code>, if applicable.
 502.797 +     * The format of the host conforms to RFC 2732, i.e. for a
 502.798 +     * literal IPv6 address, this method will return the IPv6 address
 502.799 +     * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
 502.800 +     *
 502.801 +     * @return  the host name of this <code>URL</code>.
 502.802 +     */
 502.803 +    public String getHost() {
 502.804 +        return host;
 502.805 +    }
 502.806 +
 502.807 +    /**
 502.808 +     * Gets the file name of this <code>URL</code>.
 502.809 +     * The returned file portion will be
 502.810 +     * the same as <CODE>getPath()</CODE>, plus the concatenation of
 502.811 +     * the value of <CODE>getQuery()</CODE>, if any. If there is
 502.812 +     * no query portion, this method and <CODE>getPath()</CODE> will
 502.813 +     * return identical results.
 502.814 +     *
 502.815 +     * @return  the file name of this <code>URL</code>,
 502.816 +     * or an empty string if one does not exist
 502.817 +     */
 502.818 +    public String getFile() {
 502.819 +        return file;
 502.820 +    }
 502.821 +
 502.822 +    /**
 502.823 +     * Gets the anchor (also known as the "reference") of this
 502.824 +     * <code>URL</code>.
 502.825 +     *
 502.826 +     * @return  the anchor (also known as the "reference") of this
 502.827 +     *          <code>URL</code>, or <CODE>null</CODE> if one does not exist
 502.828 +     */
 502.829 +    public String getRef() {
 502.830 +        return ref;
 502.831 +    }
 502.832 +
 502.833 +    /**
 502.834 +     * Compares this URL for equality with another object.<p>
 502.835 +     *
 502.836 +     * If the given object is not a URL then this method immediately returns
 502.837 +     * <code>false</code>.<p>
 502.838 +     *
 502.839 +     * Two URL objects are equal if they have the same protocol, reference
 502.840 +     * equivalent hosts, have the same port number on the host, and the same
 502.841 +     * file and fragment of the file.<p>
 502.842 +     *
 502.843 +     * Two hosts are considered equivalent if both host names can be resolved
 502.844 +     * into the same IP addresses; else if either host name can't be
 502.845 +     * resolved, the host names must be equal without regard to case; or both
 502.846 +     * host names equal to null.<p>
 502.847 +     *
 502.848 +     * Since hosts comparison requires name resolution, this operation is a
 502.849 +     * blocking operation. <p>
 502.850 +     *
 502.851 +     * Note: The defined behavior for <code>equals</code> is known to
 502.852 +     * be inconsistent with virtual hosting in HTTP.
 502.853 +     *
 502.854 +     * @param   obj   the URL to compare against.
 502.855 +     * @return  <code>true</code> if the objects are the same;
 502.856 +     *          <code>false</code> otherwise.
 502.857 +     */
 502.858 +    public boolean equals(Object obj) {
 502.859 +        if (!(obj instanceof URL))
 502.860 +            return false;
 502.861 +        URL u2 = (URL)obj;
 502.862 +
 502.863 +        return handler.equals(this, u2);
 502.864 +    }
 502.865 +
 502.866 +    /**
 502.867 +     * Creates an integer suitable for hash table indexing.<p>
 502.868 +     *
 502.869 +     * The hash code is based upon all the URL components relevant for URL
 502.870 +     * comparison. As such, this operation is a blocking operation.<p>
 502.871 +     *
 502.872 +     * @return  a hash code for this <code>URL</code>.
 502.873 +     */
 502.874 +    public synchronized int hashCode() {
 502.875 +        if (hashCode != -1)
 502.876 +            return hashCode;
 502.877 +
 502.878 +        hashCode = handler.hashCode(this);
 502.879 +        return hashCode;
 502.880 +    }
 502.881 +
 502.882 +    /**
 502.883 +     * Compares two URLs, excluding the fragment component.<p>
 502.884 +     *
 502.885 +     * Returns <code>true</code> if this <code>URL</code> and the
 502.886 +     * <code>other</code> argument are equal without taking the
 502.887 +     * fragment component into consideration.
 502.888 +     *
 502.889 +     * @param   other   the <code>URL</code> to compare against.
 502.890 +     * @return  <code>true</code> if they reference the same remote object;
 502.891 +     *          <code>false</code> otherwise.
 502.892 +     */
 502.893 +    public boolean sameFile(URL other) {
 502.894 +        return handler.sameFile(this, other);
 502.895 +    }
 502.896 +
 502.897 +    /**
 502.898 +     * Constructs a string representation of this <code>URL</code>. The
 502.899 +     * string is created by calling the <code>toExternalForm</code>
 502.900 +     * method of the stream protocol handler for this object.
 502.901 +     *
 502.902 +     * @return  a string representation of this object.
 502.903 +     * @see     java.net.URL#URL(java.lang.String, java.lang.String, int,
 502.904 +     *                  java.lang.String)
 502.905 +     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 502.906 +     */
 502.907 +    public String toString() {
 502.908 +        return toExternalForm();
 502.909 +    }
 502.910 +
 502.911 +    /**
 502.912 +     * Constructs a string representation of this <code>URL</code>. The
 502.913 +     * string is created by calling the <code>toExternalForm</code>
 502.914 +     * method of the stream protocol handler for this object.
 502.915 +     *
 502.916 +     * @return  a string representation of this object.
 502.917 +     * @see     java.net.URL#URL(java.lang.String, java.lang.String,
 502.918 +     *                  int, java.lang.String)
 502.919 +     * @see     java.net.URLStreamHandler#toExternalForm(java.net.URL)
 502.920 +     */
 502.921 +    public String toExternalForm() {
 502.922 +        return handler.toExternalForm(this);
 502.923 +    }
 502.924 +
 502.925 +    /**
 502.926 +     * Returns a {@link java.net.URLConnection URLConnection} instance that
 502.927 +     * represents a connection to the remote object referred to by the
 502.928 +     * {@code URL}.
 502.929 +     *
 502.930 +     * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
 502.931 +     * created every time when invoking the
 502.932 +     * {@linkplain java.net.URLStreamHandler#openConnection(URL)
 502.933 +     * URLStreamHandler.openConnection(URL)} method of the protocol handler for
 502.934 +     * this URL.</P>
 502.935 +     *
 502.936 +     * <P>It should be noted that a URLConnection instance does not establish
 502.937 +     * the actual network connection on creation. This will happen only when
 502.938 +     * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
 502.939 +     *
 502.940 +     * <P>If for the URL's protocol (such as HTTP or JAR), there
 502.941 +     * exists a public, specialized URLConnection subclass belonging
 502.942 +     * to one of the following packages or one of their subpackages:
 502.943 +     * java.lang, java.io, java.util, java.net, the connection
 502.944 +     * returned will be of that subclass. For example, for HTTP an
 502.945 +     * HttpURLConnection will be returned, and for JAR a
 502.946 +     * JarURLConnection will be returned.</P>
 502.947 +     *
 502.948 +     * @return     a {@link java.net.URLConnection URLConnection} linking
 502.949 +     *             to the URL.
 502.950 +     * @exception  IOException  if an I/O exception occurs.
 502.951 +     * @see        java.net.URL#URL(java.lang.String, java.lang.String,
 502.952 +     *             int, java.lang.String)
 502.953 +     */
 502.954 +//    public URLConnection openConnection() throws java.io.IOException {
 502.955 +//        return handler.openConnection(this);
 502.956 +//    }
 502.957 +
 502.958 +
 502.959 +    /**
 502.960 +     * Opens a connection to this <code>URL</code> and returns an
 502.961 +     * <code>InputStream</code> for reading from that connection. This
 502.962 +     * method is a shorthand for:
 502.963 +     * <blockquote><pre>
 502.964 +     *     openConnection().getInputStream()
 502.965 +     * </pre></blockquote>
 502.966 +     *
 502.967 +     * @return     an input stream for reading from the URL connection.
 502.968 +     * @exception  IOException  if an I/O exception occurs.
 502.969 +     * @see        java.net.URL#openConnection()
 502.970 +     * @see        java.net.URLConnection#getInputStream()
 502.971 +     */
 502.972 +    public final InputStream openStream() throws java.io.IOException {
 502.973 +        if (is != null) {
 502.974 +            return is;
 502.975 +        }
 502.976 +        byte[] arr = (byte[]) getContent(new Class[] { byte[].class });
 502.977 +        if (arr == null) {
 502.978 +            throw new IOException();
 502.979 +        }
 502.980 +        return new ByteArrayInputStream(arr);
 502.981 +    }
 502.982 +
 502.983 +    /**
 502.984 +     * Gets the contents of this URL. This method is a shorthand for:
 502.985 +     * <blockquote><pre>
 502.986 +     *     openConnection().getContent()
 502.987 +     * </pre></blockquote>
 502.988 +     *
 502.989 +     * @return     the contents of this URL.
 502.990 +     * @exception  IOException  if an I/O exception occurs.
 502.991 +     * @see        java.net.URLConnection#getContent()
 502.992 +     */
 502.993 +    public final Object getContent() throws java.io.IOException {
 502.994 +        return loadText(toExternalForm());
 502.995 +    }
 502.996 +    
 502.997 +    @JavaScriptBody(args = "url", body = ""
 502.998 +        + "var request = new XMLHttpRequest();\n"
 502.999 +        + "request.open('GET', url, false);\n"
502.1000 +        + "request.send();\n"
502.1001 +        + "return request.responseText;\n"
502.1002 +    )
502.1003 +    private static native String loadText(String url) throws IOException;
502.1004 +
502.1005 +    @JavaScriptBody(args = { "url", "arr" }, body = ""
502.1006 +        + "var request = new XMLHttpRequest();\n"
502.1007 +        + "request.open('GET', url, false);\n"
502.1008 +        + "request.overrideMimeType('text\\/plain; charset=x-user-defined');\n"
502.1009 +        + "request.send();\n"
502.1010 +        + "var t = request.responseText;\n"
502.1011 +        + "for (var i = 0; i < t.length; i++) arr.push(t.charCodeAt(i) & 0xff);\n"
502.1012 +        + "return arr;\n"
502.1013 +    )
502.1014 +    private static native Object loadBytes(String url, byte[] arr) throws IOException;
502.1015 +
502.1016 +    /**
502.1017 +     * Gets the contents of this URL. This method is a shorthand for:
502.1018 +     * <blockquote><pre>
502.1019 +     *     openConnection().getContent(Class[])
502.1020 +     * </pre></blockquote>
502.1021 +     *
502.1022 +     * @param classes an array of Java types
502.1023 +     * @return     the content object of this URL that is the first match of
502.1024 +     *               the types specified in the classes array.
502.1025 +     *               null if none of the requested types are supported.
502.1026 +     * @exception  IOException  if an I/O exception occurs.
502.1027 +     * @see        java.net.URLConnection#getContent(Class[])
502.1028 +     * @since 1.3
502.1029 +     */
502.1030 +    public final Object getContent(Class[] classes)
502.1031 +    throws java.io.IOException {
502.1032 +        for (Class<?> c : classes) {
502.1033 +            if (c == String.class) {
502.1034 +                return loadText(toExternalForm());
502.1035 +            }
502.1036 +            if (c == byte[].class) {
502.1037 +                return loadBytes(toExternalForm(), new byte[0]);
502.1038 +            }
502.1039 +        }
502.1040 +        return null;
502.1041 +    }
502.1042 +
502.1043 +    static URLStreamHandler getURLStreamHandler(String protocol) {
502.1044 +        URLStreamHandler universal = new URLStreamHandler() {};
502.1045 +        return universal;
502.1046 +    }
502.1047 +
502.1048 +    private static URL findContext(URL context) throws MalformedURLException {
502.1049 +        if (context == null) {
502.1050 +            String base = findBaseURL();
502.1051 +            if (base != null) {
502.1052 +                context = new URL(null, base, false);
502.1053 +            }
502.1054 +        }
502.1055 +        return context;
502.1056 +    }
502.1057 +    
502.1058 +    @JavaScriptBody(args = {}, body = 
502.1059 +          "if (typeof window !== 'object') return null;\n"
502.1060 +        + "if (!window.location) return null;\n"
502.1061 +        + "if (!window.location.href) return null;\n"
502.1062 +        + "return window.location.href;\n"
502.1063 +    )
502.1064 +    private static native String findBaseURL();
502.1065 +}
502.1066 +class Parts {
502.1067 +    String path, query, ref;
502.1068 +
502.1069 +    Parts(String file) {
502.1070 +        int ind = file.indexOf('#');
502.1071 +        ref = ind < 0 ? null: file.substring(ind + 1);
502.1072 +        file = ind < 0 ? file: file.substring(0, ind);
502.1073 +        int q = file.lastIndexOf('?');
502.1074 +        if (q != -1) {
502.1075 +            query = file.substring(q+1);
502.1076 +            path = file.substring(0, q);
502.1077 +        } else {
502.1078 +            path = file;
502.1079 +        }
502.1080 +    }
502.1081 +
502.1082 +    String getPath() {
502.1083 +        return path;
502.1084 +    }
502.1085 +
502.1086 +    String getQuery() {
502.1087 +        return query;
502.1088 +    }
502.1089 +
502.1090 +    String getRef() {
502.1091 +        return ref;
502.1092 +    }
502.1093 +}
   503.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   503.2 +++ b/rt/emul/mini/src/main/java/java/net/URLStreamHandler.java	Wed Feb 27 11:24:58 2013 +0100
   503.3 @@ -0,0 +1,568 @@
   503.4 +/*
   503.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
   503.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   503.7 + *
   503.8 + * This code is free software; you can redistribute it and/or modify it
   503.9 + * under the terms of the GNU General Public License version 2 only, as
  503.10 + * published by the Free Software Foundation.  Oracle designates this
  503.11 + * particular file as subject to the "Classpath" exception as provided
  503.12 + * by Oracle in the LICENSE file that accompanied this code.
  503.13 + *
  503.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  503.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  503.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  503.17 + * version 2 for more details (a copy is included in the LICENSE file that
  503.18 + * accompanied this code).
  503.19 + *
  503.20 + * You should have received a copy of the GNU General Public License version
  503.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  503.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  503.23 + *
  503.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  503.25 + * or visit www.oracle.com if you need additional information or have any
  503.26 + * questions.
  503.27 + */
  503.28 +
  503.29 +package java.net;
  503.30 +
  503.31 +
  503.32 +/**
  503.33 + * The abstract class <code>URLStreamHandler</code> is the common
  503.34 + * superclass for all stream protocol handlers. A stream protocol
  503.35 + * handler knows how to make a connection for a particular protocol
  503.36 + * type, such as <code>http</code>, <code>ftp</code>, or
  503.37 + * <code>gopher</code>.
  503.38 + * <p>
  503.39 + * In most cases, an instance of a <code>URLStreamHandler</code>
  503.40 + * subclass is not created directly by an application. Rather, the
  503.41 + * first time a protocol name is encountered when constructing a
  503.42 + * <code>URL</code>, the appropriate stream protocol handler is
  503.43 + * automatically loaded.
  503.44 + *
  503.45 + * @author  James Gosling
  503.46 + * @see     java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
  503.47 + * @since   JDK1.0
  503.48 + */
  503.49 +public abstract class URLStreamHandler {
  503.50 +    /**
  503.51 +     * Opens a connection to the object referenced by the
  503.52 +     * <code>URL</code> argument.
  503.53 +     * This method should be overridden by a subclass.
  503.54 +     *
  503.55 +     * <p>If for the handler's protocol (such as HTTP or JAR), there
  503.56 +     * exists a public, specialized URLConnection subclass belonging
  503.57 +     * to one of the following packages or one of their subpackages:
  503.58 +     * java.lang, java.io, java.util, java.net, the connection
  503.59 +     * returned will be of that subclass. For example, for HTTP an
  503.60 +     * HttpURLConnection will be returned, and for JAR a
  503.61 +     * JarURLConnection will be returned.
  503.62 +     *
  503.63 +     * @param      u   the URL that this connects to.
  503.64 +     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
  503.65 +     * @exception  IOException  if an I/O error occurs while opening the
  503.66 +     *               connection.
  503.67 +     */
  503.68 +//    abstract protected URLConnection openConnection(URL u) throws IOException;
  503.69 +
  503.70 +    /**
  503.71 +     * Same as openConnection(URL), except that the connection will be
  503.72 +     * made through the specified proxy; Protocol handlers that do not
  503.73 +     * support proxying will ignore the proxy parameter and make a
  503.74 +     * normal connection.
  503.75 +     *
  503.76 +     * Calling this method preempts the system's default ProxySelector
  503.77 +     * settings.
  503.78 +     *
  503.79 +     * @param      u   the URL that this connects to.
  503.80 +     * @param      p   the proxy through which the connection will be made.
  503.81 +     *                 If direct connection is desired, Proxy.NO_PROXY
  503.82 +     *                 should be specified.
  503.83 +     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
  503.84 +     * @exception  IOException  if an I/O error occurs while opening the
  503.85 +     *               connection.
  503.86 +     * @exception  IllegalArgumentException if either u or p is null,
  503.87 +     *               or p has the wrong type.
  503.88 +     * @exception  UnsupportedOperationException if the subclass that
  503.89 +     *               implements the protocol doesn't support this method.
  503.90 +     * @since      1.5
  503.91 +     */
  503.92 +//    protected URLConnection openConnection(URL u, Proxy p) throws IOException {
  503.93 +//        throw new UnsupportedOperationException("Method not implemented.");
  503.94 +//    }
  503.95 +
  503.96 +    /**
  503.97 +     * Parses the string representation of a <code>URL</code> into a
  503.98 +     * <code>URL</code> object.
  503.99 +     * <p>
 503.100 +     * If there is any inherited context, then it has already been
 503.101 +     * copied into the <code>URL</code> argument.
 503.102 +     * <p>
 503.103 +     * The <code>parseURL</code> method of <code>URLStreamHandler</code>
 503.104 +     * parses the string representation as if it were an
 503.105 +     * <code>http</code> specification. Most URL protocol families have a
 503.106 +     * similar parsing. A stream protocol handler for a protocol that has
 503.107 +     * a different syntax must override this routine.
 503.108 +     *
 503.109 +     * @param   u       the <code>URL</code> to receive the result of parsing
 503.110 +     *                  the spec.
 503.111 +     * @param   spec    the <code>String</code> representing the URL that
 503.112 +     *                  must be parsed.
 503.113 +     * @param   start   the character index at which to begin parsing. This is
 503.114 +     *                  just past the '<code>:</code>' (if there is one) that
 503.115 +     *                  specifies the determination of the protocol name.
 503.116 +     * @param   limit   the character position to stop parsing at. This is the
 503.117 +     *                  end of the string or the position of the
 503.118 +     *                  "<code>#</code>" character, if present. All information
 503.119 +     *                  after the sharp sign indicates an anchor.
 503.120 +     */
 503.121 +    protected void parseURL(URL u, String spec, int start, int limit) {
 503.122 +        // These fields may receive context content if this was relative URL
 503.123 +        String protocol = u.getProtocol();
 503.124 +        String authority = u.getAuthority();
 503.125 +        String userInfo = u.getUserInfo();
 503.126 +        String host = u.getHost();
 503.127 +        int port = u.getPort();
 503.128 +        String path = u.getPath();
 503.129 +        String query = u.getQuery();
 503.130 +
 503.131 +        // This field has already been parsed
 503.132 +        String ref = u.getRef();
 503.133 +
 503.134 +        boolean isRelPath = false;
 503.135 +        boolean queryOnly = false;
 503.136 +
 503.137 +// FIX: should not assume query if opaque
 503.138 +        // Strip off the query part
 503.139 +        if (start < limit) {
 503.140 +            int queryStart = spec.indexOf('?');
 503.141 +            queryOnly = queryStart == start;
 503.142 +            if ((queryStart != -1) && (queryStart < limit)) {
 503.143 +                query = spec.substring(queryStart+1, limit);
 503.144 +                if (limit > queryStart)
 503.145 +                    limit = queryStart;
 503.146 +                spec = spec.substring(0, queryStart);
 503.147 +            }
 503.148 +        }
 503.149 +
 503.150 +        int i = 0;
 503.151 +        // Parse the authority part if any
 503.152 +        boolean isUNCName = (start <= limit - 4) &&
 503.153 +                        (spec.charAt(start) == '/') &&
 503.154 +                        (spec.charAt(start + 1) == '/') &&
 503.155 +                        (spec.charAt(start + 2) == '/') &&
 503.156 +                        (spec.charAt(start + 3) == '/');
 503.157 +        if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
 503.158 +            (spec.charAt(start + 1) == '/')) {
 503.159 +            start += 2;
 503.160 +            i = spec.indexOf('/', start);
 503.161 +            if (i < 0) {
 503.162 +                i = spec.indexOf('?', start);
 503.163 +                if (i < 0)
 503.164 +                    i = limit;
 503.165 +            }
 503.166 +
 503.167 +            host = authority = spec.substring(start, i);
 503.168 +
 503.169 +            int ind = authority.indexOf('@');
 503.170 +            if (ind != -1) {
 503.171 +                userInfo = authority.substring(0, ind);
 503.172 +                host = authority.substring(ind+1);
 503.173 +            } else {
 503.174 +                userInfo = null;
 503.175 +            }
 503.176 +            if (host != null) {
 503.177 +                // If the host is surrounded by [ and ] then its an IPv6
 503.178 +                // literal address as specified in RFC2732
 503.179 +                if (host.length()>0 && (host.charAt(0) == '[')) {
 503.180 +                    if ((ind = host.indexOf(']')) > 2) {
 503.181 +
 503.182 +                        String nhost = host ;
 503.183 +                        host = nhost.substring(0,ind+1);
 503.184 +//                        if (!IPAddressUtil.
 503.185 +//                            isIPv6LiteralAddress(host.substring(1, ind))) {
 503.186 +//                            throw new IllegalArgumentException(
 503.187 +//                                "Invalid host: "+ host);
 503.188 +//                        }
 503.189 +
 503.190 +                        port = -1 ;
 503.191 +                        if (nhost.length() > ind+1) {
 503.192 +                            if (nhost.charAt(ind+1) == ':') {
 503.193 +                                ++ind ;
 503.194 +                                // port can be null according to RFC2396
 503.195 +                                if (nhost.length() > (ind + 1)) {
 503.196 +                                    port = Integer.parseInt(nhost.substring(ind+1));
 503.197 +                                }
 503.198 +                            } else {
 503.199 +                                throw new IllegalArgumentException(
 503.200 +                                    "Invalid authority field: " + authority);
 503.201 +                            }
 503.202 +                        }
 503.203 +                    } else {
 503.204 +                        throw new IllegalArgumentException(
 503.205 +                            "Invalid authority field: " + authority);
 503.206 +                    }
 503.207 +                } else {
 503.208 +                    ind = host.indexOf(':');
 503.209 +                    port = -1;
 503.210 +                    if (ind >= 0) {
 503.211 +                        // port can be null according to RFC2396
 503.212 +                        if (host.length() > (ind + 1)) {
 503.213 +                            port = Integer.parseInt(host.substring(ind + 1));
 503.214 +                        }
 503.215 +                        host = host.substring(0, ind);
 503.216 +                    }
 503.217 +                }
 503.218 +            } else {
 503.219 +                host = "";
 503.220 +            }
 503.221 +            if (port < -1)
 503.222 +                throw new IllegalArgumentException("Invalid port number :" +
 503.223 +                                                   port);
 503.224 +            start = i;
 503.225 +            // If the authority is defined then the path is defined by the
 503.226 +            // spec only; See RFC 2396 Section 5.2.4.
 503.227 +            if (authority != null && authority.length() > 0)
 503.228 +                path = "";
 503.229 +        }
 503.230 +
 503.231 +        if (host == null) {
 503.232 +            host = "";
 503.233 +        }
 503.234 +
 503.235 +        // Parse the file path if any
 503.236 +        if (start < limit) {
 503.237 +            if (spec.charAt(start) == '/') {
 503.238 +                path = spec.substring(start, limit);
 503.239 +            } else if (path != null && path.length() > 0) {
 503.240 +                isRelPath = true;
 503.241 +                int ind = path.lastIndexOf('/');
 503.242 +                String seperator = "";
 503.243 +                if (ind == -1 && authority != null)
 503.244 +                    seperator = "/";
 503.245 +                path = path.substring(0, ind + 1) + seperator +
 503.246 +                         spec.substring(start, limit);
 503.247 +
 503.248 +            } else {
 503.249 +                String seperator = (authority != null) ? "/" : "";
 503.250 +                path = seperator + spec.substring(start, limit);
 503.251 +            }
 503.252 +        } else if (queryOnly && path != null) {
 503.253 +            int ind = path.lastIndexOf('/');
 503.254 +            if (ind < 0)
 503.255 +                ind = 0;
 503.256 +            path = path.substring(0, ind) + "/";
 503.257 +        }
 503.258 +        if (path == null)
 503.259 +            path = "";
 503.260 +
 503.261 +        if (isRelPath) {
 503.262 +            // Remove embedded /./
 503.263 +            while ((i = path.indexOf("/./")) >= 0) {
 503.264 +                path = path.substring(0, i) + path.substring(i + 2);
 503.265 +            }
 503.266 +            // Remove embedded /../ if possible
 503.267 +            i = 0;
 503.268 +            while ((i = path.indexOf("/../", i)) >= 0) {
 503.269 +                /*
 503.270 +                 * A "/../" will cancel the previous segment and itself,
 503.271 +                 * unless that segment is a "/../" itself
 503.272 +                 * i.e. "/a/b/../c" becomes "/a/c"
 503.273 +                 * but "/../../a" should stay unchanged
 503.274 +                 */
 503.275 +                if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
 503.276 +                    (path.indexOf("/../", limit) != 0)) {
 503.277 +                    path = path.substring(0, limit) + path.substring(i + 3);
 503.278 +                    i = 0;
 503.279 +                } else {
 503.280 +                    i = i + 3;
 503.281 +                }
 503.282 +            }
 503.283 +            // Remove trailing .. if possible
 503.284 +            while (path.endsWith("/..")) {
 503.285 +                i = path.indexOf("/..");
 503.286 +                if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
 503.287 +                    path = path.substring(0, limit+1);
 503.288 +                } else {
 503.289 +                    break;
 503.290 +                }
 503.291 +            }
 503.292 +            // Remove starting .
 503.293 +            if (path.startsWith("./") && path.length() > 2)
 503.294 +                path = path.substring(2);
 503.295 +
 503.296 +            // Remove trailing .
 503.297 +            if (path.endsWith("/."))
 503.298 +                path = path.substring(0, path.length() -1);
 503.299 +        }
 503.300 +
 503.301 +        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
 503.302 +    }
 503.303 +
 503.304 +    /**
 503.305 +     * Returns the default port for a URL parsed by this handler. This method
 503.306 +     * is meant to be overidden by handlers with default port numbers.
 503.307 +     * @return the default port for a <code>URL</code> parsed by this handler.
 503.308 +     * @since 1.3
 503.309 +     */
 503.310 +    protected int getDefaultPort() {
 503.311 +        return -1;
 503.312 +    }
 503.313 +
 503.314 +    /**
 503.315 +     * Provides the default equals calculation. May be overidden by handlers
 503.316 +     * for other protocols that have different requirements for equals().
 503.317 +     * This method requires that none of its arguments is null. This is
 503.318 +     * guaranteed by the fact that it is only called by java.net.URL class.
 503.319 +     * @param u1 a URL object
 503.320 +     * @param u2 a URL object
 503.321 +     * @return <tt>true</tt> if the two urls are
 503.322 +     * considered equal, ie. they refer to the same
 503.323 +     * fragment in the same file.
 503.324 +     * @since 1.3
 503.325 +     */
 503.326 +    protected boolean equals(URL u1, URL u2) {
 503.327 +        String ref1 = u1.getRef();
 503.328 +        String ref2 = u2.getRef();
 503.329 +        return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
 503.330 +               sameFile(u1, u2);
 503.331 +    }
 503.332 +
 503.333 +    /**
 503.334 +     * Provides the default hash calculation. May be overidden by handlers for
 503.335 +     * other protocols that have different requirements for hashCode
 503.336 +     * calculation.
 503.337 +     * @param u a URL object
 503.338 +     * @return an <tt>int</tt> suitable for hash table indexing
 503.339 +     * @since 1.3
 503.340 +     */
 503.341 +    protected int hashCode(URL u) {
 503.342 +        int h = 0;
 503.343 +
 503.344 +        // Generate the protocol part.
 503.345 +        String protocol = u.getProtocol();
 503.346 +        if (protocol != null)
 503.347 +            h += protocol.hashCode();
 503.348 +
 503.349 +        // Generate the host part.
 503.350 +        Object addr = getHostAddress(u);
 503.351 +        if (addr != null) {
 503.352 +            h += addr.hashCode();
 503.353 +        } else {
 503.354 +            String host = u.getHost();
 503.355 +            if (host != null)
 503.356 +                h += host.toLowerCase().hashCode();
 503.357 +        }
 503.358 +
 503.359 +        // Generate the file part.
 503.360 +        String file = u.getFile();
 503.361 +        if (file != null)
 503.362 +            h += file.hashCode();
 503.363 +
 503.364 +        // Generate the port part.
 503.365 +        if (u.getPort() == -1)
 503.366 +            h += getDefaultPort();
 503.367 +        else
 503.368 +            h += u.getPort();
 503.369 +
 503.370 +        // Generate the ref part.
 503.371 +        String ref = u.getRef();
 503.372 +        if (ref != null)
 503.373 +            h += ref.hashCode();
 503.374 +
 503.375 +        return h;
 503.376 +    }
 503.377 +
 503.378 +    /**
 503.379 +     * Compare two urls to see whether they refer to the same file,
 503.380 +     * i.e., having the same protocol, host, port, and path.
 503.381 +     * This method requires that none of its arguments is null. This is
 503.382 +     * guaranteed by the fact that it is only called indirectly
 503.383 +     * by java.net.URL class.
 503.384 +     * @param u1 a URL object
 503.385 +     * @param u2 a URL object
 503.386 +     * @return true if u1 and u2 refer to the same file
 503.387 +     * @since 1.3
 503.388 +     */
 503.389 +    protected boolean sameFile(URL u1, URL u2) {
 503.390 +        // Compare the protocols.
 503.391 +        if (!((u1.getProtocol() == u2.getProtocol()) ||
 503.392 +              (u1.getProtocol() != null &&
 503.393 +               u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
 503.394 +            return false;
 503.395 +
 503.396 +        // Compare the files.
 503.397 +        if (!(u1.getFile() == u2.getFile() ||
 503.398 +              (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
 503.399 +            return false;
 503.400 +
 503.401 +        // Compare the ports.
 503.402 +        int port1, port2;
 503.403 +        port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
 503.404 +        port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
 503.405 +        if (port1 != port2)
 503.406 +            return false;
 503.407 +
 503.408 +        // Compare the hosts.
 503.409 +        if (!hostsEqual(u1, u2))
 503.410 +            return false;
 503.411 +
 503.412 +        return true;
 503.413 +    }
 503.414 +
 503.415 +    /**
 503.416 +     * Get the IP address of our host. An empty host field or a DNS failure
 503.417 +     * will result in a null return.
 503.418 +     *
 503.419 +     * @param u a URL object
 503.420 +     * @return an <code>InetAddress</code> representing the host
 503.421 +     * IP address.
 503.422 +     * @since 1.3
 503.423 +     */
 503.424 +    private synchronized Object getHostAddress(URL u) {
 503.425 +        return u.hostAddress;
 503.426 +    }
 503.427 +
 503.428 +    /**
 503.429 +     * Compares the host components of two URLs.
 503.430 +     * @param u1 the URL of the first host to compare
 503.431 +     * @param u2 the URL of the second host to compare
 503.432 +     * @return  <tt>true</tt> if and only if they
 503.433 +     * are equal, <tt>false</tt> otherwise.
 503.434 +     * @since 1.3
 503.435 +     */
 503.436 +    protected boolean hostsEqual(URL u1, URL u2) {
 503.437 +        Object a1 = getHostAddress(u1);
 503.438 +        Object a2 = getHostAddress(u2);
 503.439 +        // if we have internet address for both, compare them
 503.440 +        if (a1 != null && a2 != null) {
 503.441 +            return a1.equals(a2);
 503.442 +        // else, if both have host names, compare them
 503.443 +        } else if (u1.getHost() != null && u2.getHost() != null)
 503.444 +            return u1.getHost().equalsIgnoreCase(u2.getHost());
 503.445 +         else
 503.446 +            return u1.getHost() == null && u2.getHost() == null;
 503.447 +    }
 503.448 +
 503.449 +    /**
 503.450 +     * Converts a <code>URL</code> of a specific protocol to a
 503.451 +     * <code>String</code>.
 503.452 +     *
 503.453 +     * @param   u   the URL.
 503.454 +     * @return  a string representation of the <code>URL</code> argument.
 503.455 +     */
 503.456 +    protected String toExternalForm(URL u) {
 503.457 +
 503.458 +        // pre-compute length of StringBuffer
 503.459 +        int len = u.getProtocol().length() + 1;
 503.460 +        if (u.getAuthority() != null && u.getAuthority().length() > 0)
 503.461 +            len += 2 + u.getAuthority().length();
 503.462 +        if (u.getPath() != null) {
 503.463 +            len += u.getPath().length();
 503.464 +        }
 503.465 +        if (u.getQuery() != null) {
 503.466 +            len += 1 + u.getQuery().length();
 503.467 +        }
 503.468 +        if (u.getRef() != null)
 503.469 +            len += 1 + u.getRef().length();
 503.470 +
 503.471 +        StringBuffer result = new StringBuffer(len);
 503.472 +        result.append(u.getProtocol());
 503.473 +        result.append(":");
 503.474 +        if (u.getAuthority() != null && u.getAuthority().length() > 0) {
 503.475 +            result.append("//");
 503.476 +            result.append(u.getAuthority());
 503.477 +        }
 503.478 +        if (u.getPath() != null) {
 503.479 +            result.append(u.getPath());
 503.480 +        }
 503.481 +        if (u.getQuery() != null) {
 503.482 +            result.append('?');
 503.483 +            result.append(u.getQuery());
 503.484 +        }
 503.485 +        if (u.getRef() != null) {
 503.486 +            result.append("#");
 503.487 +            result.append(u.getRef());
 503.488 +        }
 503.489 +        return result.toString();
 503.490 +    }
 503.491 +
 503.492 +    /**
 503.493 +     * Sets the fields of the <code>URL</code> argument to the indicated values.
 503.494 +     * Only classes derived from URLStreamHandler are supposed to be able
 503.495 +     * to call the set method on a URL.
 503.496 +     *
 503.497 +     * @param   u         the URL to modify.
 503.498 +     * @param   protocol  the protocol name.
 503.499 +     * @param   host      the remote host value for the URL.
 503.500 +     * @param   port      the port on the remote machine.
 503.501 +     * @param   authority the authority part for the URL.
 503.502 +     * @param   userInfo the userInfo part of the URL.
 503.503 +     * @param   path      the path component of the URL.
 503.504 +     * @param   query     the query part for the URL.
 503.505 +     * @param   ref       the reference.
 503.506 +     * @exception       SecurityException       if the protocol handler of the URL is
 503.507 +     *                                  different from this one
 503.508 +     * @see     java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
 503.509 +     * @since 1.3
 503.510 +     */
 503.511 +       protected void setURL(URL u, String protocol, String host, int port,
 503.512 +                             String authority, String userInfo, String path,
 503.513 +                             String query, String ref) {
 503.514 +        if (this != u.handler) {
 503.515 +            throw new SecurityException("handler for url different from " +
 503.516 +                                        "this handler");
 503.517 +        }
 503.518 +        // ensure that no one can reset the protocol on a given URL.
 503.519 +        u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
 503.520 +    }
 503.521 +
 503.522 +    /**
 503.523 +     * Sets the fields of the <code>URL</code> argument to the indicated values.
 503.524 +     * Only classes derived from URLStreamHandler are supposed to be able
 503.525 +     * to call the set method on a URL.
 503.526 +     *
 503.527 +     * @param   u         the URL to modify.
 503.528 +     * @param   protocol  the protocol name. This value is ignored since 1.2.
 503.529 +     * @param   host      the remote host value for the URL.
 503.530 +     * @param   port      the port on the remote machine.
 503.531 +     * @param   file      the file.
 503.532 +     * @param   ref       the reference.
 503.533 +     * @exception       SecurityException       if the protocol handler of the URL is
 503.534 +     *                                  different from this one
 503.535 +     * @deprecated Use setURL(URL, String, String, int, String, String, String,
 503.536 +     *             String);
 503.537 +     */
 503.538 +    @Deprecated
 503.539 +    protected void setURL(URL u, String protocol, String host, int port,
 503.540 +                          String file, String ref) {
 503.541 +        /*
 503.542 +         * Only old URL handlers call this, so assume that the host
 503.543 +         * field might contain "user:passwd@host". Fix as necessary.
 503.544 +         */
 503.545 +        String authority = null;
 503.546 +        String userInfo = null;
 503.547 +        if (host != null && host.length() != 0) {
 503.548 +            authority = (port == -1) ? host : host + ":" + port;
 503.549 +            int at = host.lastIndexOf('@');
 503.550 +            if (at != -1) {
 503.551 +                userInfo = host.substring(0, at);
 503.552 +                host = host.substring(at+1);
 503.553 +            }
 503.554 +        }
 503.555 +
 503.556 +        /*
 503.557 +         * Assume file might contain query part. Fix as necessary.
 503.558 +         */
 503.559 +        String path = null;
 503.560 +        String query = null;
 503.561 +        if (file != null) {
 503.562 +            int q = file.lastIndexOf('?');
 503.563 +            if (q != -1) {
 503.564 +                query = file.substring(q+1);
 503.565 +                path = file.substring(0, q);
 503.566 +            } else
 503.567 +                path = file;
 503.568 +        }
 503.569 +        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
 503.570 +    }
 503.571 +}
   504.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   504.2 +++ b/rt/emul/mini/src/main/java/java/util/Comparator.java	Wed Feb 27 11:24:58 2013 +0100
   504.3 @@ -0,0 +1,168 @@
   504.4 +/*
   504.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
   504.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   504.7 + *
   504.8 + * This code is free software; you can redistribute it and/or modify it
   504.9 + * under the terms of the GNU General Public License version 2 only, as
  504.10 + * published by the Free Software Foundation.  Oracle designates this
  504.11 + * particular file as subject to the "Classpath" exception as provided
  504.12 + * by Oracle in the LICENSE file that accompanied this code.
  504.13 + *
  504.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  504.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  504.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  504.17 + * version 2 for more details (a copy is included in the LICENSE file that
  504.18 + * accompanied this code).
  504.19 + *
  504.20 + * You should have received a copy of the GNU General Public License version
  504.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  504.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  504.23 + *
  504.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  504.25 + * or visit www.oracle.com if you need additional information or have any
  504.26 + * questions.
  504.27 + */
  504.28 +
  504.29 +package java.util;
  504.30 +
  504.31 +/**
  504.32 + * A comparison function, which imposes a <i>total ordering</i> on some
  504.33 + * collection of objects.  Comparators can be passed to a sort method (such
  504.34 + * as {@link Collections#sort(List,Comparator) Collections.sort} or {@link
  504.35 + * Arrays#sort(Object[],Comparator) Arrays.sort}) to allow precise control
  504.36 + * over the sort order.  Comparators can also be used to control the order of
  504.37 + * certain data structures (such as {@link SortedSet sorted sets} or {@link
  504.38 + * SortedMap sorted maps}), or to provide an ordering for collections of
  504.39 + * objects that don't have a {@link Comparable natural ordering}.<p>
  504.40 + *
  504.41 + * The ordering imposed by a comparator <tt>c</tt> on a set of elements
  504.42 + * <tt>S</tt> is said to be <i>consistent with equals</i> if and only if
  504.43 + * <tt>c.compare(e1, e2)==0</tt> has the same boolean value as
  504.44 + * <tt>e1.equals(e2)</tt> for every <tt>e1</tt> and <tt>e2</tt> in
  504.45 + * <tt>S</tt>.<p>
  504.46 + *
  504.47 + * Caution should be exercised when using a comparator capable of imposing an
  504.48 + * ordering inconsistent with equals to order a sorted set (or sorted map).
  504.49 + * Suppose a sorted set (or sorted map) with an explicit comparator <tt>c</tt>
  504.50 + * is used with elements (or keys) drawn from a set <tt>S</tt>.  If the
  504.51 + * ordering imposed by <tt>c</tt> on <tt>S</tt> is inconsistent with equals,
  504.52 + * the sorted set (or sorted map) will behave "strangely."  In particular the
  504.53 + * sorted set (or sorted map) will violate the general contract for set (or
  504.54 + * map), which is defined in terms of <tt>equals</tt>.<p>
  504.55 + *
  504.56 + * For example, suppose one adds two elements {@code a} and {@code b} such that
  504.57 + * {@code (a.equals(b) && c.compare(a, b) != 0)}
  504.58 + * to an empty {@code TreeSet} with comparator {@code c}.
  504.59 + * The second {@code add} operation will return
  504.60 + * true (and the size of the tree set will increase) because {@code a} and
  504.61 + * {@code b} are not equivalent from the tree set's perspective, even though
  504.62 + * this is contrary to the specification of the
  504.63 + * {@link Set#add Set.add} method.<p>
  504.64 + *
  504.65 + * Note: It is generally a good idea for comparators to also implement
  504.66 + * <tt>java.io.Serializable</tt>, as they may be used as ordering methods in
  504.67 + * serializable data structures (like {@link TreeSet}, {@link TreeMap}).  In
  504.68 + * order for the data structure to serialize successfully, the comparator (if
  504.69 + * provided) must implement <tt>Serializable</tt>.<p>
  504.70 + *
  504.71 + * For the mathematically inclined, the <i>relation</i> that defines the
  504.72 + * <i>imposed ordering</i> that a given comparator <tt>c</tt> imposes on a
  504.73 + * given set of objects <tt>S</tt> is:<pre>
  504.74 + *       {(x, y) such that c.compare(x, y) &lt;= 0}.
  504.75 + * </pre> The <i>quotient</i> for this total order is:<pre>
  504.76 + *       {(x, y) such that c.compare(x, y) == 0}.
  504.77 + * </pre>
  504.78 + *
  504.79 + * It follows immediately from the contract for <tt>compare</tt> that the
  504.80 + * quotient is an <i>equivalence relation</i> on <tt>S</tt>, and that the
  504.81 + * imposed ordering is a <i>total order</i> on <tt>S</tt>.  When we say that
  504.82 + * the ordering imposed by <tt>c</tt> on <tt>S</tt> is <i>consistent with
  504.83 + * equals</i>, we mean that the quotient for the ordering is the equivalence
  504.84 + * relation defined by the objects' {@link Object#equals(Object)
  504.85 + * equals(Object)} method(s):<pre>
  504.86 + *     {(x, y) such that x.equals(y)}. </pre>
  504.87 + *
  504.88 + * <p>Unlike {@code Comparable}, a comparator may optionally permit
  504.89 + * comparison of null arguments, while maintaining the requirements for
  504.90 + * an equivalence relation.
  504.91 + *
  504.92 + * <p>This interface is a member of the
  504.93 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
  504.94 + * Java Collections Framework</a>.
  504.95 + *
  504.96 + * @param <T> the type of objects that may be compared by this comparator
  504.97 + *
  504.98 + * @author  Josh Bloch
  504.99 + * @author  Neal Gafter
 504.100 + * @see Comparable
 504.101 + * @see java.io.Serializable
 504.102 + * @since 1.2
 504.103 + */
 504.104 +
 504.105 +public interface Comparator<T> {
 504.106 +    /**
 504.107 +     * Compares its two arguments for order.  Returns a negative integer,
 504.108 +     * zero, or a positive integer as the first argument is less than, equal
 504.109 +     * to, or greater than the second.<p>
 504.110 +     *
 504.111 +     * In the foregoing description, the notation
 504.112 +     * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
 504.113 +     * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
 504.114 +     * <tt>0</tt>, or <tt>1</tt> according to whether the value of
 504.115 +     * <i>expression</i> is negative, zero or positive.<p>
 504.116 +     *
 504.117 +     * The implementor must ensure that <tt>sgn(compare(x, y)) ==
 504.118 +     * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 504.119 +     * implies that <tt>compare(x, y)</tt> must throw an exception if and only
 504.120 +     * if <tt>compare(y, x)</tt> throws an exception.)<p>
 504.121 +     *
 504.122 +     * The implementor must also ensure that the relation is transitive:
 504.123 +     * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
 504.124 +     * <tt>compare(x, z)&gt;0</tt>.<p>
 504.125 +     *
 504.126 +     * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
 504.127 +     * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
 504.128 +     * <tt>z</tt>.<p>
 504.129 +     *
 504.130 +     * It is generally the case, but <i>not</i> strictly required that
 504.131 +     * <tt>(compare(x, y)==0) == (x.equals(y))</tt>.  Generally speaking,
 504.132 +     * any comparator that violates this condition should clearly indicate
 504.133 +     * this fact.  The recommended language is "Note: this comparator
 504.134 +     * imposes orderings that are inconsistent with equals."
 504.135 +     *
 504.136 +     * @param o1 the first object to be compared.
 504.137 +     * @param o2 the second object to be compared.
 504.138 +     * @return a negative integer, zero, or a positive integer as the
 504.139 +     *         first argument is less than, equal to, or greater than the
 504.140 +     *         second.
 504.141 +     * @throws NullPointerException if an argument is null and this
 504.142 +     *         comparator does not permit null arguments
 504.143 +     * @throws ClassCastException if the arguments' types prevent them from
 504.144 +     *         being compared by this comparator.
 504.145 +     */
 504.146 +    int compare(T o1, T o2);
 504.147 +
 504.148 +    /**
 504.149 +     * Indicates whether some other object is &quot;equal to&quot; this
 504.150 +     * comparator.  This method must obey the general contract of
 504.151 +     * {@link Object#equals(Object)}.  Additionally, this method can return
 504.152 +     * <tt>true</tt> <i>only</i> if the specified object is also a comparator
 504.153 +     * and it imposes the same ordering as this comparator.  Thus,
 504.154 +     * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
 504.155 +     * o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
 504.156 +     * <tt>o1</tt> and <tt>o2</tt>.<p>
 504.157 +     *
 504.158 +     * Note that it is <i>always</i> safe <i>not</i> to override
 504.159 +     * <tt>Object.equals(Object)</tt>.  However, overriding this method may,
 504.160 +     * in some cases, improve performance by allowing programs to determine
 504.161 +     * that two distinct comparators impose the same order.
 504.162 +     *
 504.163 +     * @param   obj   the reference object with which to compare.
 504.164 +     * @return  <code>true</code> only if the specified object is also
 504.165 +     *          a comparator and it imposes the same ordering as this
 504.166 +     *          comparator.
 504.167 +     * @see Object#equals(Object)
 504.168 +     * @see Object#hashCode()
 504.169 +     */
 504.170 +    boolean equals(Object obj);
 504.171 +}
   505.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   505.2 +++ b/rt/emul/mini/src/main/java/java/util/Enumeration.java	Wed Feb 27 11:24:58 2013 +0100
   505.3 @@ -0,0 +1,79 @@
   505.4 +/*
   505.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
   505.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   505.7 + *
   505.8 + * This code is free software; you can redistribute it and/or modify it
   505.9 + * under the terms of the GNU General Public License version 2 only, as
  505.10 + * published by the Free Software Foundation.  Oracle designates this
  505.11 + * particular file as subject to the "Classpath" exception as provided
  505.12 + * by Oracle in the LICENSE file that accompanied this code.
  505.13 + *
  505.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  505.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  505.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  505.17 + * version 2 for more details (a copy is included in the LICENSE file that
  505.18 + * accompanied this code).
  505.19 + *
  505.20 + * You should have received a copy of the GNU General Public License version
  505.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  505.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  505.23 + *
  505.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  505.25 + * or visit www.oracle.com if you need additional information or have any
  505.26 + * questions.
  505.27 + */
  505.28 +
  505.29 +package java.util;
  505.30 +
  505.31 +/**
  505.32 + * An object that implements the Enumeration interface generates a
  505.33 + * series of elements, one at a time. Successive calls to the
  505.34 + * <code>nextElement</code> method return successive elements of the
  505.35 + * series.
  505.36 + * <p>
  505.37 + * For example, to print all elements of a <tt>Vector&lt;E&gt;</tt> <i>v</i>:
  505.38 + * <pre>
  505.39 + *   for (Enumeration&lt;E&gt; e = v.elements(); e.hasMoreElements();)
  505.40 + *       System.out.println(e.nextElement());</pre>
  505.41 + * <p>
  505.42 + * Methods are provided to enumerate through the elements of a
  505.43 + * vector, the keys of a hashtable, and the values in a hashtable.
  505.44 + * Enumerations are also used to specify the input streams to a
  505.45 + * <code>SequenceInputStream</code>.
  505.46 + * <p>
  505.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
  505.48 + * interface.  In addition, Iterator adds an optional remove operation, and
  505.49 + * has shorter method names.  New implementations should consider using
  505.50 + * Iterator in preference to Enumeration.
  505.51 + *
  505.52 + * @see     java.util.Iterator
  505.53 + * @see     java.io.SequenceInputStream
  505.54 + * @see     java.util.Enumeration#nextElement()
  505.55 + * @see     java.util.Hashtable
  505.56 + * @see     java.util.Hashtable#elements()
  505.57 + * @see     java.util.Hashtable#keys()
  505.58 + * @see     java.util.Vector
  505.59 + * @see     java.util.Vector#elements()
  505.60 + *
  505.61 + * @author  Lee Boynton
  505.62 + * @since   JDK1.0
  505.63 + */
  505.64 +public interface Enumeration<E> {
  505.65 +    /**
  505.66 +     * Tests if this enumeration contains more elements.
  505.67 +     *
  505.68 +     * @return  <code>true</code> if and only if this enumeration object
  505.69 +     *           contains at least one more element to provide;
  505.70 +     *          <code>false</code> otherwise.
  505.71 +     */
  505.72 +    boolean hasMoreElements();
  505.73 +
  505.74 +    /**
  505.75 +     * Returns the next element of this enumeration if this enumeration
  505.76 +     * object has at least one more element to provide.
  505.77 +     *
  505.78 +     * @return     the next element of this enumeration.
  505.79 +     * @exception  NoSuchElementException  if no more elements exist.
  505.80 +     */
  505.81 +    E nextElement();
  505.82 +}
   506.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   506.2 +++ b/rt/emul/mini/src/main/java/java/util/NoSuchElementException.java	Wed Feb 27 11:24:58 2013 +0100
   506.3 @@ -0,0 +1,60 @@
   506.4 +/*
   506.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
   506.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   506.7 + *
   506.8 + * This code is free software; you can redistribute it and/or modify it
   506.9 + * under the terms of the GNU General Public License version 2 only, as
  506.10 + * published by the Free Software Foundation.  Oracle designates this
  506.11 + * particular file as subject to the "Classpath" exception as provided
  506.12 + * by Oracle in the LICENSE file that accompanied this code.
  506.13 + *
  506.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  506.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  506.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  506.17 + * version 2 for more details (a copy is included in the LICENSE file that
  506.18 + * accompanied this code).
  506.19 + *
  506.20 + * You should have received a copy of the GNU General Public License version
  506.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  506.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  506.23 + *
  506.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  506.25 + * or visit www.oracle.com if you need additional information or have any
  506.26 + * questions.
  506.27 + */
  506.28 +
  506.29 +package java.util;
  506.30 +
  506.31 +/**
  506.32 + * Thrown by the <code>nextElement</code> method of an
  506.33 + * <code>Enumeration</code> to indicate that there are no more
  506.34 + * elements in the enumeration.
  506.35 + *
  506.36 + * @author  unascribed
  506.37 + * @see     java.util.Enumeration
  506.38 + * @see     java.util.Enumeration#nextElement()
  506.39 + * @since   JDK1.0
  506.40 + */
  506.41 +public
  506.42 +class NoSuchElementException extends RuntimeException {
  506.43 +    private static final long serialVersionUID = 6769829250639411880L;
  506.44 +
  506.45 +    /**
  506.46 +     * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
  506.47 +     * as its error message string.
  506.48 +     */
  506.49 +    public NoSuchElementException() {
  506.50 +        super();
  506.51 +    }
  506.52 +
  506.53 +    /**
  506.54 +     * Constructs a <code>NoSuchElementException</code>, saving a reference
  506.55 +     * to the error message string <tt>s</tt> for later retrieval by the
  506.56 +     * <tt>getMessage</tt> method.
  506.57 +     *
  506.58 +     * @param   s   the detail message.
  506.59 +     */
  506.60 +    public NoSuchElementException(String s) {
  506.61 +        super(s);
  506.62 +    }
  506.63 +}
   507.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   507.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/Adler32.java	Wed Feb 27 11:24:58 2013 +0100
   507.3 @@ -0,0 +1,205 @@
   507.4 +/* Adler32.java - Computes Adler32 data checksum of a data stream
   507.5 +   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
   507.6 +
   507.7 +This file is part of GNU Classpath.
   507.8 +
   507.9 +GNU Classpath is free software; you can redistribute it and/or modify
  507.10 +it under the terms of the GNU General Public License as published by
  507.11 +the Free Software Foundation; either version 2, or (at your option)
  507.12 +any later version.
  507.13 +
  507.14 +GNU Classpath is distributed in the hope that it will be useful, but
  507.15 +WITHOUT ANY WARRANTY; without even the implied warranty of
  507.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  507.17 +General Public License for more details.
  507.18 +
  507.19 +You should have received a copy of the GNU General Public License
  507.20 +along with GNU Classpath; see the file COPYING.  If not, write to the
  507.21 +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  507.22 +02111-1307 USA.
  507.23 +
  507.24 +Linking this library statically or dynamically with other modules is
  507.25 +making a combined work based on this library.  Thus, the terms and
  507.26 +conditions of the GNU General Public License cover the whole
  507.27 +combination.
  507.28 +
  507.29 +As a special exception, the copyright holders of this library give you
  507.30 +permission to link this library with independent modules to produce an
  507.31 +executable, regardless of the license terms of these independent
  507.32 +modules, and to copy and distribute the resulting executable under
  507.33 +terms of your choice, provided that you also meet, for each linked
  507.34 +independent module, the terms and conditions of the license of that
  507.35 +module.  An independent module is a module which is not derived from
  507.36 +or based on this library.  If you modify this library, you may extend
  507.37 +this exception to your version of the library, but you are not
  507.38 +obligated to do so.  If you do not wish to do so, delete this
  507.39 +exception statement from your version. */
  507.40 +
  507.41 +package java.util.zip;
  507.42 +
  507.43 +/*
  507.44 + * Written using on-line Java Platform 1.2 API Specification, as well
  507.45 + * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
  507.46 + * The actual Adler32 algorithm is taken from RFC 1950.
  507.47 + * Status:  Believed complete and correct.
  507.48 + */
  507.49 +
  507.50 +/**
  507.51 + * Computes Adler32 checksum for a stream of data. An Adler32 
  507.52 + * checksum is not as reliable as a CRC32 checksum, but a lot faster to 
  507.53 + * compute.
  507.54 + *<p>
  507.55 + * The specification for Adler32 may be found in RFC 1950.
  507.56 + * (ZLIB Compressed Data Format Specification version 3.3)
  507.57 + *<p>
  507.58 + *<p>
  507.59 + * From that document:
  507.60 + *<p>
  507.61 + *      "ADLER32 (Adler-32 checksum)
  507.62 + *       This contains a checksum value of the uncompressed data
  507.63 + *       (excluding any dictionary data) computed according to Adler-32
  507.64 + *       algorithm. This algorithm is a 32-bit extension and improvement
  507.65 + *       of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
  507.66 + *       standard. 
  507.67 + *<p>
  507.68 + *       Adler-32 is composed of two sums accumulated per byte: s1 is
  507.69 + *       the sum of all bytes, s2 is the sum of all s1 values. Both sums
  507.70 + *       are done modulo 65521. s1 is initialized to 1, s2 to zero.  The
  507.71 + *       Adler-32 checksum is stored as s2*65536 + s1 in most-
  507.72 + *       significant-byte first (network) order."
  507.73 + *<p>
  507.74 + * "8.2. The Adler-32 algorithm
  507.75 + *<p>
  507.76 + *    The Adler-32 algorithm is much faster than the CRC32 algorithm yet
  507.77 + *    still provides an extremely low probability of undetected errors.
  507.78 + *<p>
  507.79 + *    The modulo on unsigned long accumulators can be delayed for 5552
  507.80 + *    bytes, so the modulo operation time is negligible.  If the bytes
  507.81 + *    are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
  507.82 + *    and order sensitive, unlike the first sum, which is just a
  507.83 + *    checksum.  That 65521 is prime is important to avoid a possible
  507.84 + *    large class of two-byte errors that leave the check unchanged.
  507.85 + *    (The Fletcher checksum uses 255, which is not prime and which also
  507.86 + *    makes the Fletcher check insensitive to single byte changes 0 <->
  507.87 + *    255.)
  507.88 + *<p>
  507.89 + *    The sum s1 is initialized to 1 instead of zero to make the length
  507.90 + *    of the sequence part of s2, so that the length does not have to be
  507.91 + *   checked separately. (Any sequence of zeroes has a Fletcher
  507.92 + *    checksum of zero.)"
  507.93 + *
  507.94 + * @author John Leuner, Per Bothner
  507.95 + * @since JDK 1.1
  507.96 + *
  507.97 + * @see InflaterInputStream
  507.98 + * @see DeflaterOutputStream
  507.99 + */
 507.100 +public class Adler32 implements Checksum
 507.101 +{
 507.102 +
 507.103 +  /** largest prime smaller than 65536 */
 507.104 +  private static final int BASE = 65521;
 507.105 +
 507.106 +  private int checksum; //we do all in int.
 507.107 +
 507.108 +  //Note that java doesn't have unsigned integers,
 507.109 +  //so we have to be careful with what arithmetic 
 507.110 +  //we do. We return the checksum as a long to 
 507.111 +  //avoid sign confusion.
 507.112 +
 507.113 +  /**
 507.114 +   * Creates a new instance of the <code>Adler32</code> class. 
 507.115 +   * The checksum starts off with a value of 1. 
 507.116 +   */
 507.117 +  public Adler32 ()
 507.118 +  {
 507.119 +    reset();
 507.120 +  }
 507.121 +
 507.122 +  /**
 507.123 +   * Resets the Adler32 checksum to the initial value.
 507.124 +   */
 507.125 +  public void reset () 
 507.126 +  {
 507.127 +    checksum = 1; //Initialize to 1    
 507.128 +  }
 507.129 +
 507.130 +  /**
 507.131 +   * Updates the checksum with the byte b. 
 507.132 +   *
 507.133 +   * @param bval the data value to add. The high byte of the int is ignored.
 507.134 +   */
 507.135 +  public void update (int bval)
 507.136 +  {
 507.137 +    //We could make a length 1 byte array and call update again, but I
 507.138 +    //would rather not have that overhead
 507.139 +    int s1 = checksum & 0xffff;
 507.140 +    int s2 = checksum >>> 16;
 507.141 +    
 507.142 +    s1 = (s1 + (bval & 0xFF)) % BASE;
 507.143 +    s2 = (s1 + s2) % BASE;
 507.144 +    
 507.145 +    checksum = (s2 << 16) + s1;
 507.146 +  }
 507.147 +
 507.148 +  /**
 507.149 +   * Updates the checksum with the bytes taken from the array. 
 507.150 +   * 
 507.151 +   * @param buffer an array of bytes
 507.152 +   */
 507.153 +  public void update (byte[] buffer)
 507.154 +  {
 507.155 +    update(buffer, 0, buffer.length);
 507.156 +  }
 507.157 +
 507.158 +  /**
 507.159 +   * Updates the checksum with the bytes taken from the array. 
 507.160 +   * 
 507.161 +   * @param buf an array of bytes
 507.162 +   * @param off the start of the data used for this update
 507.163 +   * @param len the number of bytes to use for this update
 507.164 +   */
 507.165 +  public void update (byte[] buf, int off, int len)
 507.166 +  {
 507.167 +    //(By Per Bothner)
 507.168 +    int s1 = checksum & 0xffff;
 507.169 +    int s2 = checksum >>> 16;
 507.170 +
 507.171 +    while (len > 0)
 507.172 +      {
 507.173 +	// We can defer the modulo operation:
 507.174 +	// s1 maximally grows from 65521 to 65521 + 255 * 3800
 507.175 +	// s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
 507.176 +	int n = 3800;
 507.177 +	if (n > len)
 507.178 +	  n = len;
 507.179 +	len -= n;
 507.180 +	while (--n >= 0)
 507.181 +	  {
 507.182 +	    s1 = s1 + (buf[off++] & 0xFF);
 507.183 +	    s2 = s2 + s1;
 507.184 +	  }
 507.185 +	s1 %= BASE;
 507.186 +	s2 %= BASE;
 507.187 +      }
 507.188 +
 507.189 +    /*Old implementation, borrowed from somewhere:
 507.190 +    int n;
 507.191 +    
 507.192 +    while (len-- > 0) {
 507.193 +
 507.194 +      s1 = (s1 + (bs[offset++] & 0xff)) % BASE; 
 507.195 +      s2 = (s2 + s1) % BASE;
 507.196 +    }*/
 507.197 +    
 507.198 +    checksum = (s2 << 16) | s1;
 507.199 +  }
 507.200 +
 507.201 +  /**
 507.202 +   * Returns the Adler32 data checksum computed so far.
 507.203 +   */
 507.204 +  public long getValue()
 507.205 +  {
 507.206 +    return (long) checksum & 0xffffffffL;
 507.207 +  }
 507.208 +}
   508.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   508.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/CRC32.java	Wed Feb 27 11:24:58 2013 +0100
   508.3 @@ -0,0 +1,132 @@
   508.4 +/* CRC32.java - Computes CRC32 data checksum of a data stream
   508.5 +   Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
   508.6 +
   508.7 +This file is part of GNU Classpath.
   508.8 +
   508.9 +GNU Classpath is free software; you can redistribute it and/or modify
  508.10 +it under the terms of the GNU General Public License as published by
  508.11 +the Free Software Foundation; either version 2, or (at your option)
  508.12 +any later version.
  508.13 +
  508.14 +GNU Classpath is distributed in the hope that it will be useful, but
  508.15 +WITHOUT ANY WARRANTY; without even the implied warranty of
  508.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  508.17 +General Public License for more details.
  508.18 +
  508.19 +You should have received a copy of the GNU General Public License
  508.20 +along with GNU Classpath; see the file COPYING.  If not, write to the
  508.21 +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  508.22 +02111-1307 USA.
  508.23 +
  508.24 +Linking this library statically or dynamically with other modules is
  508.25 +making a combined work based on this library.  Thus, the terms and
  508.26 +conditions of the GNU General Public License cover the whole
  508.27 +combination.
  508.28 +
  508.29 +As a special exception, the copyright holders of this library give you
  508.30 +permission to link this library with independent modules to produce an
  508.31 +executable, regardless of the license terms of these independent
  508.32 +modules, and to copy and distribute the resulting executable under
  508.33 +terms of your choice, provided that you also meet, for each linked
  508.34 +independent module, the terms and conditions of the license of that
  508.35 +module.  An independent module is a module which is not derived from
  508.36 +or based on this library.  If you modify this library, you may extend
  508.37 +this exception to your version of the library, but you are not
  508.38 +obligated to do so.  If you do not wish to do so, delete this
  508.39 +exception statement from your version. */
  508.40 +
  508.41 +package java.util.zip;
  508.42 +
  508.43 +/*
  508.44 + * Written using on-line Java Platform 1.2 API Specification, as well
  508.45 + * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
  508.46 + * The actual CRC32 algorithm is taken from RFC 1952.
  508.47 + * Status:  Believed complete and correct.
  508.48 + */
  508.49 +
  508.50 +/**
  508.51 + * Computes CRC32 data checksum of a data stream.
  508.52 + * The actual CRC32 algorithm is described in RFC 1952
  508.53 + * (GZIP file format specification version 4.3).
  508.54 + * Can be used to get the CRC32 over a stream if used with checked input/output
  508.55 + * streams.
  508.56 + *
  508.57 + * @see InflaterInputStream
  508.58 + * @see DeflaterOutputStream
  508.59 + *
  508.60 + * @author Per Bothner
  508.61 + * @date April 1, 1999.
  508.62 + */
  508.63 +public class CRC32 implements Checksum
  508.64 +{
  508.65 +  /** The crc data checksum so far. */
  508.66 +  private int crc = 0;
  508.67 +
  508.68 +  /** The fast CRC table. Computed once when the CRC32 class is loaded. */
  508.69 +  private static int[] crc_table = make_crc_table();
  508.70 +
  508.71 +  /** Make the table for a fast CRC. */
  508.72 +  private static int[] make_crc_table ()
  508.73 +  {
  508.74 +    int[] crc_table = new int[256];
  508.75 +    for (int n = 0; n < 256; n++)
  508.76 +      {
  508.77 +	int c = n;
  508.78 +	for (int k = 8;  --k >= 0; )
  508.79 +	  {
  508.80 +	    if ((c & 1) != 0)
  508.81 +	      c = 0xedb88320 ^ (c >>> 1);
  508.82 +	    else
  508.83 +	      c = c >>> 1;
  508.84 +	  }
  508.85 +	crc_table[n] = c;
  508.86 +      }
  508.87 +    return crc_table;
  508.88 +  }
  508.89 +
  508.90 +  /**
  508.91 +   * Returns the CRC32 data checksum computed so far.
  508.92 +   */
  508.93 +  public long getValue ()
  508.94 +  {
  508.95 +    return (long) crc & 0xffffffffL;
  508.96 +  }
  508.97 +
  508.98 +  /**
  508.99 +   * Resets the CRC32 data checksum as if no update was ever called.
 508.100 +   */
 508.101 +  public void reset () { crc = 0; }
 508.102 +
 508.103 +  /**
 508.104 +   * Updates the checksum with the int bval. 
 508.105 +   *
 508.106 +   * @param bval (the byte is taken as the lower 8 bits of bval)
 508.107 +   */
 508.108 +
 508.109 +  public void update (int bval)
 508.110 +  {
 508.111 +    int c = ~crc;
 508.112 +    c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
 508.113 +    crc = ~c;
 508.114 +  }
 508.115 +
 508.116 +  /**
 508.117 +   * Adds the byte array to the data checksum.
 508.118 +   *
 508.119 +   * @param buf the buffer which contains the data
 508.120 +   * @param off the offset in the buffer where the data starts
 508.121 +   * @param len the length of the data
 508.122 +   */
 508.123 +  public void update (byte[] buf, int off, int len)
 508.124 +  {
 508.125 +    int c = ~crc;
 508.126 +    while (--len >= 0)
 508.127 +      c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
 508.128 +    crc = ~c;
 508.129 +  }
 508.130 +
 508.131 +  /**
 508.132 +   * Adds the complete byte array to the data checksum.
 508.133 +   */
 508.134 +  public void update (byte[] buf) { update(buf, 0, buf.length); }
 508.135 +}
   509.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   509.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/Checksum.java	Wed Feb 27 11:24:58 2013 +0100
   509.3 @@ -0,0 +1,60 @@
   509.4 +/*
   509.5 + * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
   509.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   509.7 + *
   509.8 + * This code is free software; you can redistribute it and/or modify it
   509.9 + * under the terms of the GNU General Public License version 2 only, as
  509.10 + * published by the Free Software Foundation.  Oracle designates this
  509.11 + * particular file as subject to the "Classpath" exception as provided
  509.12 + * by Oracle in the LICENSE file that accompanied this code.
  509.13 + *
  509.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  509.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  509.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  509.17 + * version 2 for more details (a copy is included in the LICENSE file that
  509.18 + * accompanied this code).
  509.19 + *
  509.20 + * You should have received a copy of the GNU General Public License version
  509.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  509.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  509.23 + *
  509.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  509.25 + * or visit www.oracle.com if you need additional information or have any
  509.26 + * questions.
  509.27 + */
  509.28 +
  509.29 +package java.util.zip;
  509.30 +
  509.31 +/**
  509.32 + * An interface representing a data checksum.
  509.33 + *
  509.34 + * @author      David Connelly
  509.35 + */
  509.36 +public
  509.37 +interface Checksum {
  509.38 +    /**
  509.39 +     * Updates the current checksum with the specified byte.
  509.40 +     *
  509.41 +     * @param b the byte to update the checksum with
  509.42 +     */
  509.43 +    public void update(int b);
  509.44 +
  509.45 +    /**
  509.46 +     * Updates the current checksum with the specified array of bytes.
  509.47 +     * @param b the byte array to update the checksum with
  509.48 +     * @param off the start offset of the data
  509.49 +     * @param len the number of bytes to use for the update
  509.50 +     */
  509.51 +    public void update(byte[] b, int off, int len);
  509.52 +
  509.53 +    /**
  509.54 +     * Returns the current checksum value.
  509.55 +     * @return the current checksum value
  509.56 +     */
  509.57 +    public long getValue();
  509.58 +
  509.59 +    /**
  509.60 +     * Resets the checksum to its initial value.
  509.61 +     */
  509.62 +    public void reset();
  509.63 +}
   510.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   510.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/DataFormatException.java	Wed Feb 27 11:24:58 2013 +0100
   510.3 @@ -0,0 +1,52 @@
   510.4 +/*
   510.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   510.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   510.7 + *
   510.8 + * This code is free software; you can redistribute it and/or modify it
   510.9 + * under the terms of the GNU General Public License version 2 only, as
  510.10 + * published by the Free Software Foundation.  Oracle designates this
  510.11 + * particular file as subject to the "Classpath" exception as provided
  510.12 + * by Oracle in the LICENSE file that accompanied this code.
  510.13 + *
  510.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  510.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  510.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  510.17 + * version 2 for more details (a copy is included in the LICENSE file that
  510.18 + * accompanied this code).
  510.19 + *
  510.20 + * You should have received a copy of the GNU General Public License version
  510.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  510.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  510.23 + *
  510.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  510.25 + * or visit www.oracle.com if you need additional information or have any
  510.26 + * questions.
  510.27 + */
  510.28 +
  510.29 +package java.util.zip;
  510.30 +
  510.31 +/**
  510.32 + * Signals that a data format error has occurred.
  510.33 + *
  510.34 + * @author      David Connelly
  510.35 + */
  510.36 +public
  510.37 +class DataFormatException extends Exception {
  510.38 +    private static final long serialVersionUID = 2219632870893641452L;
  510.39 +
  510.40 +    /**
  510.41 +     * Constructs a DataFormatException with no detail message.
  510.42 +     */
  510.43 +    public DataFormatException() {
  510.44 +        super();
  510.45 +    }
  510.46 +
  510.47 +    /**
  510.48 +     * Constructs a DataFormatException with the specified detail message.
  510.49 +     * A detail message is a String that describes this particular exception.
  510.50 +     * @param s the String containing a detail message
  510.51 +     */
  510.52 +    public DataFormatException(String s) {
  510.53 +        super(s);
  510.54 +    }
  510.55 +}
   511.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   511.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/Inflater.java	Wed Feb 27 11:24:58 2013 +0100
   511.3 @@ -0,0 +1,310 @@
   511.4 +/*
   511.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
   511.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   511.7 + *
   511.8 + * This code is free software; you can redistribute it and/or modify it
   511.9 + * under the terms of the GNU General Public License version 2 only, as
  511.10 + * published by the Free Software Foundation.  Oracle designates this
  511.11 + * particular file as subject to the "Classpath" exception as provided
  511.12 + * by Oracle in the LICENSE file that accompanied this code.
  511.13 + *
  511.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  511.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  511.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  511.17 + * version 2 for more details (a copy is included in the LICENSE file that
  511.18 + * accompanied this code).
  511.19 + *
  511.20 + * You should have received a copy of the GNU General Public License version
  511.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  511.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  511.23 + *
  511.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  511.25 + * or visit www.oracle.com if you need additional information or have any
  511.26 + * questions.
  511.27 + */
  511.28 +
  511.29 +package java.util.zip;
  511.30 +
  511.31 +/**
  511.32 + * This class provides support for general purpose decompression using the
  511.33 + * popular ZLIB compression library. The ZLIB compression library was
  511.34 + * initially developed as part of the PNG graphics standard and is not
  511.35 + * protected by patents. It is fully described in the specifications at
  511.36 + * the <a href="package-summary.html#package_description">java.util.zip
  511.37 + * package description</a>.
  511.38 + *
  511.39 + * <p>The following code fragment demonstrates a trivial compression
  511.40 + * and decompression of a string using <tt>Deflater</tt> and
  511.41 + * <tt>Inflater</tt>.
  511.42 + *
  511.43 + * <blockquote><pre>
  511.44 + * try {
  511.45 + *     // Encode a String into bytes
  511.46 + *     String inputString = "blahblahblah\u20AC\u20AC";
  511.47 + *     byte[] input = inputString.getBytes("UTF-8");
  511.48 + *
  511.49 + *     // Compress the bytes
  511.50 + *     byte[] output = new byte[100];
  511.51 + *     Deflater compresser = new Deflater();
  511.52 + *     compresser.setInput(input);
  511.53 + *     compresser.finish();
  511.54 + *     int compressedDataLength = compresser.deflate(output);
  511.55 + *
  511.56 + *     // Decompress the bytes
  511.57 + *     Inflater decompresser = new Inflater();
  511.58 + *     decompresser.setInput(output, 0, compressedDataLength);
  511.59 + *     byte[] result = new byte[100];
  511.60 + *     int resultLength = decompresser.inflate(result);
  511.61 + *     decompresser.end();
  511.62 + *
  511.63 + *     // Decode the bytes into a String
  511.64 + *     String outputString = new String(result, 0, resultLength, "UTF-8");
  511.65 + * } catch(java.io.UnsupportedEncodingException ex) {
  511.66 + *     // handle
  511.67 + * } catch (java.util.zip.DataFormatException ex) {
  511.68 + *     // handle
  511.69 + * }
  511.70 + * </pre></blockquote>
  511.71 + *
  511.72 + * @see         Deflater
  511.73 + * @author      David Connelly
  511.74 + *
  511.75 + */
  511.76 +public
  511.77 +class Inflater {
  511.78 +    private final org.apidesign.bck2brwsr.emul.zip.Inflater impl;
  511.79 +    
  511.80 +    /**
  511.81 +     * Creates a new decompressor. If the parameter 'nowrap' is true then
  511.82 +     * the ZLIB header and checksum fields will not be used. This provides
  511.83 +     * compatibility with the compression format used by both GZIP and PKZIP.
  511.84 +     * <p>
  511.85 +     * Note: When using the 'nowrap' option it is also necessary to provide
  511.86 +     * an extra "dummy" byte as input. This is required by the ZLIB native
  511.87 +     * library in order to support certain optimizations.
  511.88 +     *
  511.89 +     * @param nowrap if true then support GZIP compatible compression
  511.90 +     */
  511.91 +    public Inflater(boolean nowrap) {
  511.92 +        if (getClass() == org.apidesign.bck2brwsr.emul.zip.Inflater.class) {
  511.93 +            impl = null;
  511.94 +        } else {
  511.95 +            impl = new org.apidesign.bck2brwsr.emul.zip.Inflater(nowrap);
  511.96 +        }
  511.97 +    }
  511.98 +
  511.99 +    /**
 511.100 +     * Creates a new decompressor.
 511.101 +     */
 511.102 +    public Inflater() {
 511.103 +        this(false);
 511.104 +    }
 511.105 +
 511.106 +    /**
 511.107 +     * Sets input data for decompression. Should be called whenever
 511.108 +     * needsInput() returns true indicating that more input data is
 511.109 +     * required.
 511.110 +     * @param b the input data bytes
 511.111 +     * @param off the start offset of the input data
 511.112 +     * @param len the length of the input data
 511.113 +     * @see Inflater#needsInput
 511.114 +     */
 511.115 +    public void setInput(byte[] b, int off, int len) {
 511.116 +        impl.setInput(b, off, len);
 511.117 +    }
 511.118 +
 511.119 +    /**
 511.120 +     * Sets input data for decompression. Should be called whenever
 511.121 +     * needsInput() returns true indicating that more input data is
 511.122 +     * required.
 511.123 +     * @param b the input data bytes
 511.124 +     * @see Inflater#needsInput
 511.125 +     */
 511.126 +    public void setInput(byte[] b) {
 511.127 +        impl.setInput(b);
 511.128 +    }
 511.129 +
 511.130 +    /**
 511.131 +     * Sets the preset dictionary to the given array of bytes. Should be
 511.132 +     * called when inflate() returns 0 and needsDictionary() returns true
 511.133 +     * indicating that a preset dictionary is required. The method getAdler()
 511.134 +     * can be used to get the Adler-32 value of the dictionary needed.
 511.135 +     * @param b the dictionary data bytes
 511.136 +     * @param off the start offset of the data
 511.137 +     * @param len the length of the data
 511.138 +     * @see Inflater#needsDictionary
 511.139 +     * @see Inflater#getAdler
 511.140 +     */
 511.141 +    public void setDictionary(byte[] b, int off, int len) {
 511.142 +        impl.setDictionary(b, off, len);
 511.143 +    }
 511.144 +
 511.145 +    /**
 511.146 +     * Sets the preset dictionary to the given array of bytes. Should be
 511.147 +     * called when inflate() returns 0 and needsDictionary() returns true
 511.148 +     * indicating that a preset dictionary is required. The method getAdler()
 511.149 +     * can be used to get the Adler-32 value of the dictionary needed.
 511.150 +     * @param b the dictionary data bytes
 511.151 +     * @see Inflater#needsDictionary
 511.152 +     * @see Inflater#getAdler
 511.153 +     */
 511.154 +    public void setDictionary(byte[] b) {
 511.155 +        impl.setDictionary(b);
 511.156 +    }
 511.157 +
 511.158 +    /**
 511.159 +     * Returns the total number of bytes remaining in the input buffer.
 511.160 +     * This can be used to find out what bytes still remain in the input
 511.161 +     * buffer after decompression has finished.
 511.162 +     * @return the total number of bytes remaining in the input buffer
 511.163 +     */
 511.164 +    public int getRemaining() {
 511.165 +        return impl.getRemaining();
 511.166 +    }
 511.167 +
 511.168 +    /**
 511.169 +     * Returns true if no data remains in the input buffer. This can
 511.170 +     * be used to determine if #setInput should be called in order
 511.171 +     * to provide more input.
 511.172 +     * @return true if no data remains in the input buffer
 511.173 +     */
 511.174 +    public boolean needsInput() {
 511.175 +        return impl.needsInput();
 511.176 +    }
 511.177 +
 511.178 +    /**
 511.179 +     * Returns true if a preset dictionary is needed for decompression.
 511.180 +     * @return true if a preset dictionary is needed for decompression
 511.181 +     * @see Inflater#setDictionary
 511.182 +     */
 511.183 +    public boolean needsDictionary() {
 511.184 +        return impl.needsDictionary();
 511.185 +    }
 511.186 +
 511.187 +    /**
 511.188 +     * Returns true if the end of the compressed data stream has been
 511.189 +     * reached.
 511.190 +     * @return true if the end of the compressed data stream has been
 511.191 +     * reached
 511.192 +     */
 511.193 +    public boolean finished() {
 511.194 +        return impl.finished();
 511.195 +    }
 511.196 +
 511.197 +    /**
 511.198 +     * Uncompresses bytes into specified buffer. Returns actual number
 511.199 +     * of bytes uncompressed. A return value of 0 indicates that
 511.200 +     * needsInput() or needsDictionary() should be called in order to
 511.201 +     * determine if more input data or a preset dictionary is required.
 511.202 +     * In the latter case, getAdler() can be used to get the Adler-32
 511.203 +     * value of the dictionary required.
 511.204 +     * @param b the buffer for the uncompressed data
 511.205 +     * @param off the start offset of the data
 511.206 +     * @param len the maximum number of uncompressed bytes
 511.207 +     * @return the actual number of uncompressed bytes
 511.208 +     * @exception DataFormatException if the compressed data format is invalid
 511.209 +     * @see Inflater#needsInput
 511.210 +     * @see Inflater#needsDictionary
 511.211 +     */
 511.212 +    public int inflate(byte[] b, int off, int len)
 511.213 +        throws DataFormatException
 511.214 +    {
 511.215 +        return impl.inflate(b, off, len);
 511.216 +    }
 511.217 +
 511.218 +    /**
 511.219 +     * Uncompresses bytes into specified buffer. Returns actual number
 511.220 +     * of bytes uncompressed. A return value of 0 indicates that
 511.221 +     * needsInput() or needsDictionary() should be called in order to
 511.222 +     * determine if more input data or a preset dictionary is required.
 511.223 +     * In the latter case, getAdler() can be used to get the Adler-32
 511.224 +     * value of the dictionary required.
 511.225 +     * @param b the buffer for the uncompressed data
 511.226 +     * @return the actual number of uncompressed bytes
 511.227 +     * @exception DataFormatException if the compressed data format is invalid
 511.228 +     * @see Inflater#needsInput
 511.229 +     * @see Inflater#needsDictionary
 511.230 +     */
 511.231 +    public int inflate(byte[] b) throws DataFormatException {
 511.232 +        return impl.inflate(b);
 511.233 +    }
 511.234 +
 511.235 +    /**
 511.236 +     * Returns the ADLER-32 value of the uncompressed data.
 511.237 +     * @return the ADLER-32 value of the uncompressed data
 511.238 +     */
 511.239 +    public int getAdler() {
 511.240 +        return impl.getAdler();
 511.241 +    }
 511.242 +
 511.243 +    /**
 511.244 +     * Returns the total number of compressed bytes input so far.
 511.245 +     *
 511.246 +     * <p>Since the number of bytes may be greater than
 511.247 +     * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
 511.248 +     * the preferred means of obtaining this information.</p>
 511.249 +     *
 511.250 +     * @return the total number of compressed bytes input so far
 511.251 +     */
 511.252 +    public int getTotalIn() {
 511.253 +        return impl.getTotalIn();
 511.254 +    }
 511.255 +
 511.256 +    /**
 511.257 +     * Returns the total number of compressed bytes input so far.</p>
 511.258 +     *
 511.259 +     * @return the total (non-negative) number of compressed bytes input so far
 511.260 +     * @since 1.5
 511.261 +     */
 511.262 +    public long getBytesRead() {
 511.263 +        return impl.getBytesRead();
 511.264 +    }
 511.265 +
 511.266 +    /**
 511.267 +     * Returns the total number of uncompressed bytes output so far.
 511.268 +     *
 511.269 +     * <p>Since the number of bytes may be greater than
 511.270 +     * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
 511.271 +     * the preferred means of obtaining this information.</p>
 511.272 +     *
 511.273 +     * @return the total number of uncompressed bytes output so far
 511.274 +     */
 511.275 +    public int getTotalOut() {
 511.276 +        return impl.getTotalOut();
 511.277 +    }
 511.278 +
 511.279 +    /**
 511.280 +     * Returns the total number of uncompressed bytes output so far.</p>
 511.281 +     *
 511.282 +     * @return the total (non-negative) number of uncompressed bytes output so far
 511.283 +     * @since 1.5
 511.284 +     */
 511.285 +    public long getBytesWritten() {
 511.286 +        return impl.getBytesWritten();
 511.287 +    }
 511.288 +
 511.289 +    /**
 511.290 +     * Resets inflater so that a new set of input data can be processed.
 511.291 +     */
 511.292 +    public void reset() {
 511.293 +        impl.reset();
 511.294 +    }
 511.295 +
 511.296 +    /**
 511.297 +     * Closes the decompressor and discards any unprocessed input.
 511.298 +     * This method should be called when the decompressor is no longer
 511.299 +     * being used, but will also be called automatically by the finalize()
 511.300 +     * method. Once this method is called, the behavior of the Inflater
 511.301 +     * object is undefined.
 511.302 +     */
 511.303 +    public void end() {
 511.304 +        impl.end();
 511.305 +    }
 511.306 +
 511.307 +    /**
 511.308 +     * Closes the decompressor when garbage is collected.
 511.309 +     */
 511.310 +    protected void finalize() {
 511.311 +        end();
 511.312 +    }
 511.313 +}
   512.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   512.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/InflaterInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   512.3 @@ -0,0 +1,288 @@
   512.4 +/*
   512.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   512.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   512.7 + *
   512.8 + * This code is free software; you can redistribute it and/or modify it
   512.9 + * under the terms of the GNU General Public License version 2 only, as
  512.10 + * published by the Free Software Foundation.  Oracle designates this
  512.11 + * particular file as subject to the "Classpath" exception as provided
  512.12 + * by Oracle in the LICENSE file that accompanied this code.
  512.13 + *
  512.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  512.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  512.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  512.17 + * version 2 for more details (a copy is included in the LICENSE file that
  512.18 + * accompanied this code).
  512.19 + *
  512.20 + * You should have received a copy of the GNU General Public License version
  512.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  512.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  512.23 + *
  512.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  512.25 + * or visit www.oracle.com if you need additional information or have any
  512.26 + * questions.
  512.27 + */
  512.28 +
  512.29 +package java.util.zip;
  512.30 +
  512.31 +import java.io.FilterInputStream;
  512.32 +import java.io.InputStream;
  512.33 +import java.io.IOException;
  512.34 +import java.io.EOFException;
  512.35 +
  512.36 +/**
  512.37 + * This class implements a stream filter for uncompressing data in the
  512.38 + * "deflate" compression format. It is also used as the basis for other
  512.39 + * decompression filters, such as GZIPInputStream.
  512.40 + *
  512.41 + * @see         Inflater
  512.42 + * @author      David Connelly
  512.43 + */
  512.44 +public
  512.45 +class InflaterInputStream extends FilterInputStream {
  512.46 +    /**
  512.47 +     * Decompressor for this stream.
  512.48 +     */
  512.49 +    protected Inflater inf;
  512.50 +
  512.51 +    /**
  512.52 +     * Input buffer for decompression.
  512.53 +     */
  512.54 +    protected byte[] buf;
  512.55 +
  512.56 +    /**
  512.57 +     * Length of input buffer.
  512.58 +     */
  512.59 +    protected int len;
  512.60 +
  512.61 +    private boolean closed = false;
  512.62 +    // this flag is set to true after EOF has reached
  512.63 +    private boolean reachEOF = false;
  512.64 +
  512.65 +    /**
  512.66 +     * Check to make sure that this stream has not been closed
  512.67 +     */
  512.68 +    private void ensureOpen() throws IOException {
  512.69 +        if (closed) {
  512.70 +            throw new IOException("Stream closed");
  512.71 +        }
  512.72 +    }
  512.73 +
  512.74 +
  512.75 +    /**
  512.76 +     * Creates a new input stream with the specified decompressor and
  512.77 +     * buffer size.
  512.78 +     * @param in the input stream
  512.79 +     * @param inf the decompressor ("inflater")
  512.80 +     * @param size the input buffer size
  512.81 +     * @exception IllegalArgumentException if size is <= 0
  512.82 +     */
  512.83 +    public InflaterInputStream(InputStream in, Inflater inf, int size) {
  512.84 +        super(in);
  512.85 +        if (in == null || inf == null) {
  512.86 +            throw new NullPointerException();
  512.87 +        } else if (size <= 0) {
  512.88 +            throw new IllegalArgumentException("buffer size <= 0");
  512.89 +        }
  512.90 +        this.inf = inf;
  512.91 +        buf = new byte[size];
  512.92 +    }
  512.93 +
  512.94 +    /**
  512.95 +     * Creates a new input stream with the specified decompressor and a
  512.96 +     * default buffer size.
  512.97 +     * @param in the input stream
  512.98 +     * @param inf the decompressor ("inflater")
  512.99 +     */
 512.100 +    public InflaterInputStream(InputStream in, Inflater inf) {
 512.101 +        this(in, inf, 512);
 512.102 +    }
 512.103 +
 512.104 +    boolean usesDefaultInflater = false;
 512.105 +
 512.106 +    /**
 512.107 +     * Creates a new input stream with a default decompressor and buffer size.
 512.108 +     * @param in the input stream
 512.109 +     */
 512.110 +    public InflaterInputStream(InputStream in) {
 512.111 +        this(in, new Inflater());
 512.112 +        usesDefaultInflater = true;
 512.113 +    }
 512.114 +
 512.115 +    private byte[] singleByteBuf = new byte[1];
 512.116 +
 512.117 +    /**
 512.118 +     * Reads a byte of uncompressed data. This method will block until
 512.119 +     * enough input is available for decompression.
 512.120 +     * @return the byte read, or -1 if end of compressed input is reached
 512.121 +     * @exception IOException if an I/O error has occurred
 512.122 +     */
 512.123 +    public int read() throws IOException {
 512.124 +        ensureOpen();
 512.125 +        return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff;
 512.126 +    }
 512.127 +
 512.128 +    /**
 512.129 +     * Reads uncompressed data into an array of bytes. If <code>len</code> is not
 512.130 +     * zero, the method will block until some input can be decompressed; otherwise,
 512.131 +     * no bytes are read and <code>0</code> is returned.
 512.132 +     * @param b the buffer into which the data is read
 512.133 +     * @param off the start offset in the destination array <code>b</code>
 512.134 +     * @param len the maximum number of bytes read
 512.135 +     * @return the actual number of bytes read, or -1 if the end of the
 512.136 +     *         compressed input is reached or a preset dictionary is needed
 512.137 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 512.138 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 512.139 +     * <code>len</code> is negative, or <code>len</code> is greater than
 512.140 +     * <code>b.length - off</code>
 512.141 +     * @exception ZipException if a ZIP format error has occurred
 512.142 +     * @exception IOException if an I/O error has occurred
 512.143 +     */
 512.144 +    public int read(byte[] b, int off, int len) throws IOException {
 512.145 +        ensureOpen();
 512.146 +        if (b == null) {
 512.147 +            throw new NullPointerException();
 512.148 +        } else if (off < 0 || len < 0 || len > b.length - off) {
 512.149 +            throw new IndexOutOfBoundsException();
 512.150 +        } else if (len == 0) {
 512.151 +            return 0;
 512.152 +        }
 512.153 +        try {
 512.154 +            int n;
 512.155 +            while ((n = inf.inflate(b, off, len)) == 0) {
 512.156 +                if (inf.finished() || inf.needsDictionary()) {
 512.157 +                    reachEOF = true;
 512.158 +                    return -1;
 512.159 +                }
 512.160 +                if (inf.needsInput()) {
 512.161 +                    fill();
 512.162 +                }
 512.163 +            }
 512.164 +            return n;
 512.165 +        } catch (DataFormatException e) {
 512.166 +            String s = e.getMessage();
 512.167 +            throw new ZipException(s != null ? s : "Invalid ZLIB data format");
 512.168 +        }
 512.169 +    }
 512.170 +
 512.171 +    /**
 512.172 +     * Returns 0 after EOF has been reached, otherwise always return 1.
 512.173 +     * <p>
 512.174 +     * Programs should not count on this method to return the actual number
 512.175 +     * of bytes that could be read without blocking.
 512.176 +     *
 512.177 +     * @return     1 before EOF and 0 after EOF.
 512.178 +     * @exception  IOException  if an I/O error occurs.
 512.179 +     *
 512.180 +     */
 512.181 +    public int available() throws IOException {
 512.182 +        ensureOpen();
 512.183 +        if (reachEOF) {
 512.184 +            return 0;
 512.185 +        } else {
 512.186 +            return 1;
 512.187 +        }
 512.188 +    }
 512.189 +
 512.190 +    private byte[] b = new byte[512];
 512.191 +
 512.192 +    /**
 512.193 +     * Skips specified number of bytes of uncompressed data.
 512.194 +     * @param n the number of bytes to skip
 512.195 +     * @return the actual number of bytes skipped.
 512.196 +     * @exception IOException if an I/O error has occurred
 512.197 +     * @exception IllegalArgumentException if n < 0
 512.198 +     */
 512.199 +    public long skip(long n) throws IOException {
 512.200 +        if (n < 0) {
 512.201 +            throw new IllegalArgumentException("negative skip length");
 512.202 +        }
 512.203 +        ensureOpen();
 512.204 +        int max = (int)Math.min(n, Integer.MAX_VALUE);
 512.205 +        int total = 0;
 512.206 +        while (total < max) {
 512.207 +            int len = max - total;
 512.208 +            if (len > b.length) {
 512.209 +                len = b.length;
 512.210 +            }
 512.211 +            len = read(b, 0, len);
 512.212 +            if (len == -1) {
 512.213 +                reachEOF = true;
 512.214 +                break;
 512.215 +            }
 512.216 +            total += len;
 512.217 +        }
 512.218 +        return total;
 512.219 +    }
 512.220 +
 512.221 +    /**
 512.222 +     * Closes this input stream and releases any system resources associated
 512.223 +     * with the stream.
 512.224 +     * @exception IOException if an I/O error has occurred
 512.225 +     */
 512.226 +    public void close() throws IOException {
 512.227 +        if (!closed) {
 512.228 +            if (usesDefaultInflater)
 512.229 +                inf.end();
 512.230 +            in.close();
 512.231 +            closed = true;
 512.232 +        }
 512.233 +    }
 512.234 +
 512.235 +    /**
 512.236 +     * Fills input buffer with more data to decompress.
 512.237 +     * @exception IOException if an I/O error has occurred
 512.238 +     */
 512.239 +    protected void fill() throws IOException {
 512.240 +        ensureOpen();
 512.241 +        len = in.read(buf, 0, buf.length);
 512.242 +        if (len == -1) {
 512.243 +            throw new EOFException("Unexpected end of ZLIB input stream");
 512.244 +        }
 512.245 +        inf.setInput(buf, 0, len);
 512.246 +    }
 512.247 +
 512.248 +    /**
 512.249 +     * Tests if this input stream supports the <code>mark</code> and
 512.250 +     * <code>reset</code> methods. The <code>markSupported</code>
 512.251 +     * method of <code>InflaterInputStream</code> returns
 512.252 +     * <code>false</code>.
 512.253 +     *
 512.254 +     * @return  a <code>boolean</code> indicating if this stream type supports
 512.255 +     *          the <code>mark</code> and <code>reset</code> methods.
 512.256 +     * @see     java.io.InputStream#mark(int)
 512.257 +     * @see     java.io.InputStream#reset()
 512.258 +     */
 512.259 +    public boolean markSupported() {
 512.260 +        return false;
 512.261 +    }
 512.262 +
 512.263 +    /**
 512.264 +     * Marks the current position in this input stream.
 512.265 +     *
 512.266 +     * <p> The <code>mark</code> method of <code>InflaterInputStream</code>
 512.267 +     * does nothing.
 512.268 +     *
 512.269 +     * @param   readlimit   the maximum limit of bytes that can be read before
 512.270 +     *                      the mark position becomes invalid.
 512.271 +     * @see     java.io.InputStream#reset()
 512.272 +     */
 512.273 +    public synchronized void mark(int readlimit) {
 512.274 +    }
 512.275 +
 512.276 +    /**
 512.277 +     * Repositions this stream to the position at the time the
 512.278 +     * <code>mark</code> method was last called on this input stream.
 512.279 +     *
 512.280 +     * <p> The method <code>reset</code> for class
 512.281 +     * <code>InflaterInputStream</code> does nothing except throw an
 512.282 +     * <code>IOException</code>.
 512.283 +     *
 512.284 +     * @exception  IOException  if this method is invoked.
 512.285 +     * @see     java.io.InputStream#mark(int)
 512.286 +     * @see     java.io.IOException
 512.287 +     */
 512.288 +    public synchronized void reset() throws IOException {
 512.289 +        throw new IOException("mark/reset not supported");
 512.290 +    }
 512.291 +}
   513.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   513.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/ZStreamRef.java	Wed Feb 27 11:24:58 2013 +0100
   513.3 @@ -0,0 +1,46 @@
   513.4 +/*
   513.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   513.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   513.7 + *
   513.8 + * This code is free software; you can redistribute it and/or modify it
   513.9 + * under the terms of the GNU General Public License version 2 only, as
  513.10 + * published by the Free Software Foundation.  Oracle designates this
  513.11 + * particular file as subject to the "Classpath" exception as provided
  513.12 + * by Oracle in the LICENSE file that accompanied this code.
  513.13 + *
  513.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  513.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  513.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  513.17 + * version 2 for more details (a copy is included in the LICENSE file that
  513.18 + * accompanied this code).
  513.19 + *
  513.20 + * You should have received a copy of the GNU General Public License version
  513.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  513.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  513.23 + *
  513.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  513.25 + * or visit www.oracle.com if you need additional information or have any
  513.26 + * questions.
  513.27 + */
  513.28 +
  513.29 +package java.util.zip;
  513.30 +
  513.31 +/**
  513.32 + * A reference to the native zlib's z_stream structure.
  513.33 + */
  513.34 +
  513.35 +class ZStreamRef {
  513.36 +
  513.37 +    private long address;
  513.38 +    ZStreamRef (long address) {
  513.39 +        this.address = address;
  513.40 +    }
  513.41 +
  513.42 +    long address() {
  513.43 +        return address;
  513.44 +    }
  513.45 +
  513.46 +    void clear() {
  513.47 +        address = 0;
  513.48 +    }
  513.49 +}
   514.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   514.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/ZipConstants.java	Wed Feb 27 11:24:58 2013 +0100
   514.3 @@ -0,0 +1,98 @@
   514.4 +/*
   514.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
   514.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   514.7 + *
   514.8 + * This code is free software; you can redistribute it and/or modify it
   514.9 + * under the terms of the GNU General Public License version 2 only, as
  514.10 + * published by the Free Software Foundation.  Oracle designates this
  514.11 + * particular file as subject to the "Classpath" exception as provided
  514.12 + * by Oracle in the LICENSE file that accompanied this code.
  514.13 + *
  514.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  514.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  514.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  514.17 + * version 2 for more details (a copy is included in the LICENSE file that
  514.18 + * accompanied this code).
  514.19 + *
  514.20 + * You should have received a copy of the GNU General Public License version
  514.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  514.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  514.23 + *
  514.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  514.25 + * or visit www.oracle.com if you need additional information or have any
  514.26 + * questions.
  514.27 + */
  514.28 +
  514.29 +package java.util.zip;
  514.30 +
  514.31 +/*
  514.32 + * This interface defines the constants that are used by the classes
  514.33 + * which manipulate ZIP files.
  514.34 + *
  514.35 + * @author      David Connelly
  514.36 + */
  514.37 +interface ZipConstants {
  514.38 +    /*
  514.39 +     * Header signatures
  514.40 +     */
  514.41 +    static long LOCSIG = 0x04034b50L;   // "PK\003\004"
  514.42 +    static long EXTSIG = 0x08074b50L;   // "PK\007\008"
  514.43 +    static long CENSIG = 0x02014b50L;   // "PK\001\002"
  514.44 +    static long ENDSIG = 0x06054b50L;   // "PK\005\006"
  514.45 +
  514.46 +    /*
  514.47 +     * Header sizes in bytes (including signatures)
  514.48 +     */
  514.49 +    static final int LOCHDR = 30;       // LOC header size
  514.50 +    static final int EXTHDR = 16;       // EXT header size
  514.51 +    static final int CENHDR = 46;       // CEN header size
  514.52 +    static final int ENDHDR = 22;       // END header size
  514.53 +
  514.54 +    /*
  514.55 +     * Local file (LOC) header field offsets
  514.56 +     */
  514.57 +    static final int LOCVER = 4;        // version needed to extract
  514.58 +    static final int LOCFLG = 6;        // general purpose bit flag
  514.59 +    static final int LOCHOW = 8;        // compression method
  514.60 +    static final int LOCTIM = 10;       // modification time
  514.61 +    static final int LOCCRC = 14;       // uncompressed file crc-32 value
  514.62 +    static final int LOCSIZ = 18;       // compressed size
  514.63 +    static final int LOCLEN = 22;       // uncompressed size
  514.64 +    static final int LOCNAM = 26;       // filename length
  514.65 +    static final int LOCEXT = 28;       // extra field length
  514.66 +
  514.67 +    /*
  514.68 +     * Extra local (EXT) header field offsets
  514.69 +     */
  514.70 +    static final int EXTCRC = 4;        // uncompressed file crc-32 value
  514.71 +    static final int EXTSIZ = 8;        // compressed size
  514.72 +    static final int EXTLEN = 12;       // uncompressed size
  514.73 +
  514.74 +    /*
  514.75 +     * Central directory (CEN) header field offsets
  514.76 +     */
  514.77 +    static final int CENVEM = 4;        // version made by
  514.78 +    static final int CENVER = 6;        // version needed to extract
  514.79 +    static final int CENFLG = 8;        // encrypt, decrypt flags
  514.80 +    static final int CENHOW = 10;       // compression method
  514.81 +    static final int CENTIM = 12;       // modification time
  514.82 +    static final int CENCRC = 16;       // uncompressed file crc-32 value
  514.83 +    static final int CENSIZ = 20;       // compressed size
  514.84 +    static final int CENLEN = 24;       // uncompressed size
  514.85 +    static final int CENNAM = 28;       // filename length
  514.86 +    static final int CENEXT = 30;       // extra field length
  514.87 +    static final int CENCOM = 32;       // comment length
  514.88 +    static final int CENDSK = 34;       // disk number start
  514.89 +    static final int CENATT = 36;       // internal file attributes
  514.90 +    static final int CENATX = 38;       // external file attributes
  514.91 +    static final int CENOFF = 42;       // LOC header offset
  514.92 +
  514.93 +    /*
  514.94 +     * End of central directory (END) header field offsets
  514.95 +     */
  514.96 +    static final int ENDSUB = 8;        // number of entries on this disk
  514.97 +    static final int ENDTOT = 10;       // total number of entries
  514.98 +    static final int ENDSIZ = 12;       // central directory size in bytes
  514.99 +    static final int ENDOFF = 16;       // offset of first CEN header
 514.100 +    static final int ENDCOM = 20;       // zip file comment length
 514.101 +}
   515.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   515.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/ZipEntry.java	Wed Feb 27 11:24:58 2013 +0100
   515.3 @@ -0,0 +1,331 @@
   515.4 +/*
   515.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   515.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   515.7 + *
   515.8 + * This code is free software; you can redistribute it and/or modify it
   515.9 + * under the terms of the GNU General Public License version 2 only, as
  515.10 + * published by the Free Software Foundation.  Oracle designates this
  515.11 + * particular file as subject to the "Classpath" exception as provided
  515.12 + * by Oracle in the LICENSE file that accompanied this code.
  515.13 + *
  515.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  515.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  515.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  515.17 + * version 2 for more details (a copy is included in the LICENSE file that
  515.18 + * accompanied this code).
  515.19 + *
  515.20 + * You should have received a copy of the GNU General Public License version
  515.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  515.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  515.23 + *
  515.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  515.25 + * or visit www.oracle.com if you need additional information or have any
  515.26 + * questions.
  515.27 + */
  515.28 +
  515.29 +package java.util.zip;
  515.30 +
  515.31 +/**
  515.32 + * This class is used to represent a ZIP file entry.
  515.33 + *
  515.34 + * @author      David Connelly
  515.35 + */
  515.36 +public
  515.37 +class ZipEntry implements ZipConstants, Cloneable {
  515.38 +    String name;        // entry name
  515.39 +    long time = -1;     // modification time (in DOS time)
  515.40 +    long crc = -1;      // crc-32 of entry data
  515.41 +    long size = -1;     // uncompressed size of entry data
  515.42 +    long csize = -1;    // compressed size of entry data
  515.43 +    int method = -1;    // compression method
  515.44 +    int flag = 0;       // general purpose flag
  515.45 +    byte[] extra;       // optional extra field data for entry
  515.46 +    String comment;     // optional comment string for entry
  515.47 +
  515.48 +    /**
  515.49 +     * Compression method for uncompressed entries.
  515.50 +     */
  515.51 +    public static final int STORED = 0;
  515.52 +
  515.53 +    /**
  515.54 +     * Compression method for compressed (deflated) entries.
  515.55 +     */
  515.56 +    public static final int DEFLATED = 8;
  515.57 +
  515.58 +    /**
  515.59 +     * Creates a new zip entry with the specified name.
  515.60 +     *
  515.61 +     * @param name the entry name
  515.62 +     * @exception NullPointerException if the entry name is null
  515.63 +     * @exception IllegalArgumentException if the entry name is longer than
  515.64 +     *            0xFFFF bytes
  515.65 +     */
  515.66 +    public ZipEntry(String name) {
  515.67 +        if (name == null) {
  515.68 +            throw new NullPointerException();
  515.69 +        }
  515.70 +        if (name.length() > 0xFFFF) {
  515.71 +            throw new IllegalArgumentException("entry name too long");
  515.72 +        }
  515.73 +        this.name = name;
  515.74 +    }
  515.75 +
  515.76 +    /**
  515.77 +     * Creates a new zip entry with fields taken from the specified
  515.78 +     * zip entry.
  515.79 +     * @param e a zip Entry object
  515.80 +     */
  515.81 +    public ZipEntry(ZipEntry e) {
  515.82 +        name = e.name;
  515.83 +        time = e.time;
  515.84 +        crc = e.crc;
  515.85 +        size = e.size;
  515.86 +        csize = e.csize;
  515.87 +        method = e.method;
  515.88 +        flag = e.flag;
  515.89 +        extra = e.extra;
  515.90 +        comment = e.comment;
  515.91 +    }
  515.92 +
  515.93 +    /*
  515.94 +     * Creates a new un-initialized zip entry
  515.95 +     */
  515.96 +    ZipEntry() {}
  515.97 +
  515.98 +    /**
  515.99 +     * Returns the name of the entry.
 515.100 +     * @return the name of the entry
 515.101 +     */
 515.102 +    public String getName() {
 515.103 +        return name;
 515.104 +    }
 515.105 +
 515.106 +    /**
 515.107 +     * Sets the modification time of the entry.
 515.108 +     * @param time the entry modification time in number of milliseconds
 515.109 +     *             since the epoch
 515.110 +     * @see #getTime()
 515.111 +     */
 515.112 +    public void setTime(long time) {
 515.113 +        this.time = javaToDosTime(time);
 515.114 +    }
 515.115 +
 515.116 +    /**
 515.117 +     * Returns the modification time of the entry, or -1 if not specified.
 515.118 +     * @return the modification time of the entry, or -1 if not specified
 515.119 +     * @see #setTime(long)
 515.120 +     */
 515.121 +    public long getTime() {
 515.122 +        return time != -1 ? dosToJavaTime(time) : -1;
 515.123 +    }
 515.124 +
 515.125 +    /**
 515.126 +     * Sets the uncompressed size of the entry data.
 515.127 +     * @param size the uncompressed size in bytes
 515.128 +     * @exception IllegalArgumentException if the specified size is less
 515.129 +     *            than 0, is greater than 0xFFFFFFFF when
 515.130 +     *            <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
 515.131 +     *            or is less than 0 when ZIP64 is supported
 515.132 +     * @see #getSize()
 515.133 +     */
 515.134 +    public void setSize(long size) {
 515.135 +        if (size < 0) {
 515.136 +            throw new IllegalArgumentException("invalid entry size");
 515.137 +        }
 515.138 +        this.size = size;
 515.139 +    }
 515.140 +
 515.141 +    /**
 515.142 +     * Returns the uncompressed size of the entry data, or -1 if not known.
 515.143 +     * @return the uncompressed size of the entry data, or -1 if not known
 515.144 +     * @see #setSize(long)
 515.145 +     */
 515.146 +    public long getSize() {
 515.147 +        return size;
 515.148 +    }
 515.149 +
 515.150 +    /**
 515.151 +     * Returns the size of the compressed entry data, or -1 if not known.
 515.152 +     * In the case of a stored entry, the compressed size will be the same
 515.153 +     * as the uncompressed size of the entry.
 515.154 +     * @return the size of the compressed entry data, or -1 if not known
 515.155 +     * @see #setCompressedSize(long)
 515.156 +     */
 515.157 +    public long getCompressedSize() {
 515.158 +        return csize;
 515.159 +    }
 515.160 +
 515.161 +    /**
 515.162 +     * Sets the size of the compressed entry data.
 515.163 +     * @param csize the compressed size to set to
 515.164 +     * @see #getCompressedSize()
 515.165 +     */
 515.166 +    public void setCompressedSize(long csize) {
 515.167 +        this.csize = csize;
 515.168 +    }
 515.169 +
 515.170 +    /**
 515.171 +     * Sets the CRC-32 checksum of the uncompressed entry data.
 515.172 +     * @param crc the CRC-32 value
 515.173 +     * @exception IllegalArgumentException if the specified CRC-32 value is
 515.174 +     *            less than 0 or greater than 0xFFFFFFFF
 515.175 +     * @see #getCrc()
 515.176 +     */
 515.177 +    public void setCrc(long crc) {
 515.178 +        if (crc < 0 || crc > 0xFFFFFFFFL) {
 515.179 +            throw new IllegalArgumentException("invalid entry crc-32");
 515.180 +        }
 515.181 +        this.crc = crc;
 515.182 +    }
 515.183 +
 515.184 +    /**
 515.185 +     * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
 515.186 +     * not known.
 515.187 +     * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
 515.188 +     * not known
 515.189 +     * @see #setCrc(long)
 515.190 +     */
 515.191 +    public long getCrc() {
 515.192 +        return crc;
 515.193 +    }
 515.194 +
 515.195 +    /**
 515.196 +     * Sets the compression method for the entry.
 515.197 +     * @param method the compression method, either STORED or DEFLATED
 515.198 +     * @exception IllegalArgumentException if the specified compression
 515.199 +     *            method is invalid
 515.200 +     * @see #getMethod()
 515.201 +     */
 515.202 +    public void setMethod(int method) {
 515.203 +        if (method != STORED && method != DEFLATED) {
 515.204 +            throw new IllegalArgumentException("invalid compression method");
 515.205 +        }
 515.206 +        this.method = method;
 515.207 +    }
 515.208 +
 515.209 +    /**
 515.210 +     * Returns the compression method of the entry, or -1 if not specified.
 515.211 +     * @return the compression method of the entry, or -1 if not specified
 515.212 +     * @see #setMethod(int)
 515.213 +     */
 515.214 +    public int getMethod() {
 515.215 +        return method;
 515.216 +    }
 515.217 +
 515.218 +    /**
 515.219 +     * Sets the optional extra field data for the entry.
 515.220 +     * @param extra the extra field data bytes
 515.221 +     * @exception IllegalArgumentException if the length of the specified
 515.222 +     *            extra field data is greater than 0xFFFF bytes
 515.223 +     * @see #getExtra()
 515.224 +     */
 515.225 +    public void setExtra(byte[] extra) {
 515.226 +        if (extra != null && extra.length > 0xFFFF) {
 515.227 +            throw new IllegalArgumentException("invalid extra field length");
 515.228 +        }
 515.229 +        this.extra = extra;
 515.230 +    }
 515.231 +
 515.232 +    /**
 515.233 +     * Returns the extra field data for the entry, or null if none.
 515.234 +     * @return the extra field data for the entry, or null if none
 515.235 +     * @see #setExtra(byte[])
 515.236 +     */
 515.237 +    public byte[] getExtra() {
 515.238 +        return extra;
 515.239 +    }
 515.240 +
 515.241 +    /**
 515.242 +     * Sets the optional comment string for the entry.
 515.243 +     *
 515.244 +     * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
 515.245 +     * specified comment string is greater than 0xFFFF bytes after encoding, only
 515.246 +     * the first 0xFFFF bytes are output to the ZIP file entry.
 515.247 +     *
 515.248 +     * @param comment the comment string
 515.249 +     *
 515.250 +     * @see #getComment()
 515.251 +     */
 515.252 +    public void setComment(String comment) {
 515.253 +        this.comment = comment;
 515.254 +    }
 515.255 +
 515.256 +    /**
 515.257 +     * Returns the comment string for the entry, or null if none.
 515.258 +     * @return the comment string for the entry, or null if none
 515.259 +     * @see #setComment(String)
 515.260 +     */
 515.261 +    public String getComment() {
 515.262 +        return comment;
 515.263 +    }
 515.264 +
 515.265 +    /**
 515.266 +     * Returns true if this is a directory entry. A directory entry is
 515.267 +     * defined to be one whose name ends with a '/'.
 515.268 +     * @return true if this is a directory entry
 515.269 +     */
 515.270 +    public boolean isDirectory() {
 515.271 +        return name.endsWith("/");
 515.272 +    }
 515.273 +
 515.274 +    /**
 515.275 +     * Returns a string representation of the ZIP entry.
 515.276 +     */
 515.277 +    public String toString() {
 515.278 +        return getName();
 515.279 +    }
 515.280 +
 515.281 +    /*
 515.282 +     * Converts DOS time to Java time (number of milliseconds since epoch).
 515.283 +     */
 515.284 +    private static long dosToJavaTime(long dtime) {
 515.285 +        return dtime;
 515.286 +        /* XXX:
 515.287 +        Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
 515.288 +                          (int)(((dtime >> 21) & 0x0f) - 1),
 515.289 +                          (int)((dtime >> 16) & 0x1f),
 515.290 +                          (int)((dtime >> 11) & 0x1f),
 515.291 +                          (int)((dtime >> 5) & 0x3f),
 515.292 +                          (int)((dtime << 1) & 0x3e));
 515.293 +        return d.getTime();
 515.294 +        */
 515.295 +    }
 515.296 +
 515.297 +    /*
 515.298 +     * Converts Java time to DOS time.
 515.299 +     */
 515.300 +    private static long javaToDosTime(long time) {
 515.301 +        return time;
 515.302 +        /* XXX:
 515.303 +        Date d = new Date(time);
 515.304 +        int year = d.getYear() + 1900;
 515.305 +        if (year < 1980) {
 515.306 +            return (1 << 21) | (1 << 16);
 515.307 +        }
 515.308 +        return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
 515.309 +               d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
 515.310 +               d.getSeconds() >> 1;
 515.311 +        */
 515.312 +    }
 515.313 +
 515.314 +    /**
 515.315 +     * Returns the hash code value for this entry.
 515.316 +     */
 515.317 +    public int hashCode() {
 515.318 +        return name.hashCode();
 515.319 +    }
 515.320 +
 515.321 +    /**
 515.322 +     * Returns a copy of this entry.
 515.323 +     */
 515.324 +    public Object clone() {
 515.325 +        try {
 515.326 +            ZipEntry e = (ZipEntry)super.clone();
 515.327 +            e.extra = (extra == null) ? null : extra.clone();
 515.328 +            return e;
 515.329 +        } catch (CloneNotSupportedException e) {
 515.330 +            // This should never happen, since we are Cloneable
 515.331 +            throw new IllegalStateException();
 515.332 +        }
 515.333 +    }
 515.334 +}
   516.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   516.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/ZipException.java	Wed Feb 27 11:24:58 2013 +0100
   516.3 @@ -0,0 +1,60 @@
   516.4 +/*
   516.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
   516.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   516.7 + *
   516.8 + * This code is free software; you can redistribute it and/or modify it
   516.9 + * under the terms of the GNU General Public License version 2 only, as
  516.10 + * published by the Free Software Foundation.  Oracle designates this
  516.11 + * particular file as subject to the "Classpath" exception as provided
  516.12 + * by Oracle in the LICENSE file that accompanied this code.
  516.13 + *
  516.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  516.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  516.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  516.17 + * version 2 for more details (a copy is included in the LICENSE file that
  516.18 + * accompanied this code).
  516.19 + *
  516.20 + * You should have received a copy of the GNU General Public License version
  516.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  516.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  516.23 + *
  516.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  516.25 + * or visit www.oracle.com if you need additional information or have any
  516.26 + * questions.
  516.27 + */
  516.28 +
  516.29 +package java.util.zip;
  516.30 +
  516.31 +import java.io.IOException;
  516.32 +
  516.33 +/**
  516.34 + * Signals that a Zip exception of some sort has occurred.
  516.35 + *
  516.36 + * @author  unascribed
  516.37 + * @see     java.io.IOException
  516.38 + * @since   JDK1.0
  516.39 + */
  516.40 +
  516.41 +public
  516.42 +class ZipException extends IOException {
  516.43 +    private static final long serialVersionUID = 8000196834066748623L;
  516.44 +
  516.45 +    /**
  516.46 +     * Constructs a <code>ZipException</code> with <code>null</code>
  516.47 +     * as its error detail message.
  516.48 +     */
  516.49 +    public ZipException() {
  516.50 +        super();
  516.51 +    }
  516.52 +
  516.53 +    /**
  516.54 +     * Constructs a <code>ZipException</code> with the specified detail
  516.55 +     * message.
  516.56 +     *
  516.57 +     * @param   s   the detail message.
  516.58 +     */
  516.59 +
  516.60 +    public ZipException(String s) {
  516.61 +        super(s);
  516.62 +    }
  516.63 +}
   517.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   517.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/ZipInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   517.3 @@ -0,0 +1,194 @@
   517.4 +/*
   517.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   517.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   517.7 + *
   517.8 + * This code is free software; you can redistribute it and/or modify it
   517.9 + * under the terms of the GNU General Public License version 2 only, as
  517.10 + * published by the Free Software Foundation.  Oracle designates this
  517.11 + * particular file as subject to the "Classpath" exception as provided
  517.12 + * by Oracle in the LICENSE file that accompanied this code.
  517.13 + *
  517.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  517.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  517.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  517.17 + * version 2 for more details (a copy is included in the LICENSE file that
  517.18 + * accompanied this code).
  517.19 + *
  517.20 + * You should have received a copy of the GNU General Public License version
  517.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  517.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  517.23 + *
  517.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  517.25 + * or visit www.oracle.com if you need additional information or have any
  517.26 + * questions.
  517.27 + */
  517.28 +
  517.29 +package java.util.zip;
  517.30 +
  517.31 +import java.io.InputStream;
  517.32 +import java.io.IOException;
  517.33 +
  517.34 +/**
  517.35 + * This class implements an input stream filter for reading files in the
  517.36 + * ZIP file format. Includes support for both compressed and uncompressed
  517.37 + * entries.
  517.38 + *
  517.39 + * @author      David Connelly
  517.40 + */
  517.41 +public
  517.42 +class ZipInputStream extends InflaterInputStream implements ZipConstants {
  517.43 +    private final org.apidesign.bck2brwsr.emul.zip.ZipInputStream impl;
  517.44 +
  517.45 +    /**
  517.46 +     * Creates a new ZIP input stream.
  517.47 +     *
  517.48 +     * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
  517.49 +     * decode the entry names.
  517.50 +     *
  517.51 +     * @param in the actual input stream
  517.52 +     */
  517.53 +    public ZipInputStream(InputStream in) {
  517.54 +        super(in);
  517.55 +        impl = new org.apidesign.bck2brwsr.emul.zip.ZipInputStream(in);
  517.56 +    }
  517.57 +
  517.58 +    /**
  517.59 +     * Creates a new ZIP input stream.
  517.60 +     *
  517.61 +     * @param in the actual input stream
  517.62 +     *
  517.63 +     * @param charset
  517.64 +     *        The {@linkplain java.nio.charset.Charset charset} to be
  517.65 +     *        used to decode the ZIP entry name (ignored if the
  517.66 +     *        <a href="package-summary.html#lang_encoding"> language
  517.67 +     *        encoding bit</a> of the ZIP entry's general purpose bit
  517.68 +     *        flag is set).
  517.69 +     *
  517.70 +     * @since 1.7
  517.71 +     *
  517.72 +    public ZipInputStream(InputStream in, Charset charset) {
  517.73 +        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
  517.74 +        usesDefaultInflater = true;
  517.75 +        if(in == null) {
  517.76 +            throw new NullPointerException("in is null");
  517.77 +        }
  517.78 +        if (charset == null)
  517.79 +            throw new NullPointerException("charset is null");
  517.80 +        this.zc = ZipCoder.get(charset);
  517.81 +    }
  517.82 +    */
  517.83 +
  517.84 +    /**
  517.85 +     * Reads the next ZIP file entry and positions the stream at the
  517.86 +     * beginning of the entry data.
  517.87 +     * @return the next ZIP file entry, or null if there are no more entries
  517.88 +     * @exception ZipException if a ZIP file error has occurred
  517.89 +     * @exception IOException if an I/O error has occurred
  517.90 +     */
  517.91 +    public ZipEntry getNextEntry() throws IOException {
  517.92 +        return impl.getNextEntry();
  517.93 +    }
  517.94 +
  517.95 +    /**
  517.96 +     * Closes the current ZIP entry and positions the stream for reading the
  517.97 +     * next entry.
  517.98 +     * @exception ZipException if a ZIP file error has occurred
  517.99 +     * @exception IOException if an I/O error has occurred
 517.100 +     */
 517.101 +    public void closeEntry() throws IOException {
 517.102 +        impl.closeEntry();
 517.103 +    }
 517.104 +
 517.105 +    /**
 517.106 +     * Returns 0 after EOF has reached for the current entry data,
 517.107 +     * otherwise always return 1.
 517.108 +     * <p>
 517.109 +     * Programs should not count on this method to return the actual number
 517.110 +     * of bytes that could be read without blocking.
 517.111 +     *
 517.112 +     * @return     1 before EOF and 0 after EOF has reached for current entry.
 517.113 +     * @exception  IOException  if an I/O error occurs.
 517.114 +     *
 517.115 +     */
 517.116 +    public int available() throws IOException {
 517.117 +        return impl.available();
 517.118 +    }
 517.119 +
 517.120 +    /**
 517.121 +     * Reads from the current ZIP entry into an array of bytes.
 517.122 +     * If <code>len</code> is not zero, the method
 517.123 +     * blocks until some input is available; otherwise, no
 517.124 +     * bytes are read and <code>0</code> is returned.
 517.125 +     * @param b the buffer into which the data is read
 517.126 +     * @param off the start offset in the destination array <code>b</code>
 517.127 +     * @param len the maximum number of bytes read
 517.128 +     * @return the actual number of bytes read, or -1 if the end of the
 517.129 +     *         entry is reached
 517.130 +     * @exception  NullPointerException if <code>b</code> is <code>null</code>.
 517.131 +     * @exception  IndexOutOfBoundsException if <code>off</code> is negative,
 517.132 +     * <code>len</code> is negative, or <code>len</code> is greater than
 517.133 +     * <code>b.length - off</code>
 517.134 +     * @exception ZipException if a ZIP file error has occurred
 517.135 +     * @exception IOException if an I/O error has occurred
 517.136 +     */
 517.137 +    public int read(byte[] b, int off, int len) throws IOException {
 517.138 +        return impl.read(b, off, len);
 517.139 +    }
 517.140 +
 517.141 +    /**
 517.142 +     * Skips specified number of bytes in the current ZIP entry.
 517.143 +     * @param n the number of bytes to skip
 517.144 +     * @return the actual number of bytes skipped
 517.145 +     * @exception ZipException if a ZIP file error has occurred
 517.146 +     * @exception IOException if an I/O error has occurred
 517.147 +     * @exception IllegalArgumentException if n < 0
 517.148 +     */
 517.149 +    public long skip(long n) throws IOException {
 517.150 +        return impl.skip(n);
 517.151 +    }
 517.152 +
 517.153 +    /**
 517.154 +     * Closes this input stream and releases any system resources associated
 517.155 +     * with the stream.
 517.156 +     * @exception IOException if an I/O error has occurred
 517.157 +     */
 517.158 +    public void close() throws IOException {
 517.159 +        impl.close();
 517.160 +    }
 517.161 +
 517.162 +    /**
 517.163 +     * Creates a new <code>ZipEntry</code> object for the specified
 517.164 +     * entry name.
 517.165 +     *
 517.166 +     * @param name the ZIP file entry name
 517.167 +     * @return the ZipEntry just created
 517.168 +     */
 517.169 +    protected ZipEntry createZipEntry(String name) {
 517.170 +        return new ZipEntry(name);
 517.171 +    }
 517.172 +
 517.173 +    @Override
 517.174 +    public int read() throws IOException {
 517.175 +        return impl.read();
 517.176 +    }
 517.177 +
 517.178 +    @Override
 517.179 +    public boolean markSupported() {
 517.180 +        return impl.markSupported();
 517.181 +    }
 517.182 +
 517.183 +    @Override
 517.184 +    public void mark(int readlimit) {
 517.185 +        impl.mark(readlimit);
 517.186 +    }
 517.187 +
 517.188 +    @Override
 517.189 +    public void reset() throws IOException {
 517.190 +        impl.reset();
 517.191 +    }
 517.192 +
 517.193 +    @Override
 517.194 +    public int read(byte[] b) throws IOException {
 517.195 +        return impl.read(b);
 517.196 +    }
 517.197 +}
   518.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   518.2 +++ b/rt/emul/mini/src/main/java/java/util/zip/package.html	Wed Feb 27 11:24:58 2013 +0100
   518.3 @@ -0,0 +1,98 @@
   518.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
   518.5 +<html>
   518.6 +<head>
   518.7 +<!--
   518.8 +Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
   518.9 +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  518.10 +
  518.11 +This code is free software; you can redistribute it and/or modify it
  518.12 +under the terms of the GNU General Public License version 2 only, as
  518.13 +published by the Free Software Foundation.  Oracle designates this
  518.14 +particular file as subject to the "Classpath" exception as provided
  518.15 +by Oracle in the LICENSE file that accompanied this code.
  518.16 +
  518.17 +This code is distributed in the hope that it will be useful, but WITHOUT
  518.18 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  518.19 +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  518.20 +version 2 for more details (a copy is included in the LICENSE file that
  518.21 +accompanied this code).
  518.22 +
  518.23 +You should have received a copy of the GNU General Public License version
  518.24 +2 along with this work; if not, write to the Free Software Foundation,
  518.25 +Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  518.26 +
  518.27 +Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  518.28 +or visit www.oracle.com if you need additional information or have any
  518.29 +questions.
  518.30 +-->
  518.31 +
  518.32 +</head>
  518.33 +<body bgcolor="white">
  518.34 +
  518.35 +Provides classes for reading and writing the standard ZIP and GZIP
  518.36 +file formats.  Also includes classes for compressing and decompressing
  518.37 +data using the DEFLATE compression algorithm, which is used by the
  518.38 +ZIP and GZIP file formats. Additionally, there are utility classes
  518.39 +for computing the CRC-32 and Adler-32 checksums of arbitrary
  518.40 +input streams.
  518.41 +
  518.42 +
  518.43 +<h2>Package Specification</h2>
  518.44 +
  518.45 +</a>
  518.46 +<ul>
  518.47 +  <li><a href="ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip">
  518.48 +      Info-ZIP Application Note 970311
  518.49 +      </a> - a detailed description of the Info-ZIP format upon which
  518.50 +      the <code>java.util.zip</code> classes are based.
  518.51 +<p>
  518.52 +  <a name="zip64">
  518.53 +  <li>An implementation may optionally support the ZIP64(tm) format extensions
  518.54 +      defined by the 
  518.55 +      <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
  518.56 +      PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
  518.57 +      are used to overcome the size limitations of the original ZIP format.
  518.58 +<p>
  518.59 +  <a name="lang_encoding">
  518.60 +  <li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
  518.61 +      PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
  518.62 +      encode ZIP entry filename and comment fields using UTF-8.
  518.63 +<p>
  518.64 +  <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
  518.65 +      ZLIB Compressed Data Format Specification version 3.3</a>
  518.66 +      &nbsp;
  518.67 +      <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
  518.68 +      (RFC 1950)
  518.69 +<p>
  518.70 +  <li><a href="http://www.ietf.org/rfc/rfc1951.txt">
  518.71 +      DEFLATE Compressed Data Format Specification version 1.3</a>
  518.72 +      &nbsp;
  518.73 +      <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
  518.74 +      (RFC 1951)
  518.75 +<p>
  518.76 +  <li><a href="http://www.ietf.org/rfc/rfc1952.txt">
  518.77 +      GZIP file format specification version 4.3</a>
  518.78 +      &nbsp;
  518.79 +      <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
  518.80 +      (RFC 1952)
  518.81 +<p>
  518.82 +  <li>CRC-32 checksum is described in RFC 1952 (above)
  518.83 +<p>
  518.84 +  <li>Adler-32 checksum is described in RFC 1950 (above)
  518.85 +</ul>
  518.86 +
  518.87 +
  518.88 +<!--
  518.89 +<h2>Related Documentation</h2>
  518.90 +
  518.91 +For overviews, tutorials, examples, guides, and tool documentation, please see:
  518.92 +<ul>
  518.93 +  <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
  518.94 +</ul>
  518.95 +-->
  518.96 +
  518.97 +@since JDK1.1
  518.98 +</body>
  518.99 +</html>
 518.100 +
 518.101 +
   519.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   519.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/ManifestInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   519.3 @@ -0,0 +1,228 @@
   519.4 +/*
   519.5 + * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
   519.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   519.7 + *
   519.8 + * This code is free software; you can redistribute it and/or modify it
   519.9 + * under the terms of the GNU General Public License version 2 only, as
  519.10 + * published by the Free Software Foundation.  Oracle designates this
  519.11 + * particular file as subject to the "Classpath" exception as provided
  519.12 + * by Oracle in the LICENSE file that accompanied this code.
  519.13 + *
  519.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  519.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  519.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  519.17 + * version 2 for more details (a copy is included in the LICENSE file that
  519.18 + * accompanied this code).
  519.19 + *
  519.20 + * You should have received a copy of the GNU General Public License version
  519.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  519.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  519.23 + *
  519.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  519.25 + * or visit www.oracle.com if you need additional information or have any
  519.26 + * questions.
  519.27 + */
  519.28 +package org.apidesign.bck2brwsr.emul.lang;
  519.29 +
  519.30 +import java.io.FilterInputStream;
  519.31 +import java.io.IOException;
  519.32 +import java.io.InputStream;
  519.33 +
  519.34 +/*
  519.35 + * A fast buffered input stream for parsing manifest files.
  519.36 + * 
  519.37 + * Taken from java.util.jar.Manifest.FastInputStream and modified to be
  519.38 + * independent of other Manifest functionality.
  519.39 + */
  519.40 +public abstract class ManifestInputStream extends FilterInputStream {
  519.41 +    private byte[] buf;
  519.42 +    private int count = 0;
  519.43 +    private int pos = 0;
  519.44 +
  519.45 +    protected ManifestInputStream(InputStream in) {
  519.46 +        this(in, 8192);
  519.47 +    }
  519.48 +
  519.49 +    protected ManifestInputStream(InputStream in, int size) {
  519.50 +        super(in);
  519.51 +        buf = new byte[size];
  519.52 +    }
  519.53 +
  519.54 +    public int read() throws IOException {
  519.55 +        if (pos >= count) {
  519.56 +            fill();
  519.57 +            if (pos >= count) {
  519.58 +                return -1;
  519.59 +            }
  519.60 +        }
  519.61 +        return buf[pos++] & 0xff;
  519.62 +    }
  519.63 +
  519.64 +    public int read(byte[] b, int off, int len) throws IOException {
  519.65 +        int avail = count - pos;
  519.66 +        if (avail <= 0) {
  519.67 +            if (len >= buf.length) {
  519.68 +                return in.read(b, off, len);
  519.69 +            }
  519.70 +            fill();
  519.71 +            avail = count - pos;
  519.72 +            if (avail <= 0) {
  519.73 +                return -1;
  519.74 +            }
  519.75 +        }
  519.76 +        if (len > avail) {
  519.77 +            len = avail;
  519.78 +        }
  519.79 +        System.arraycopy(buf, pos, b, off, len);
  519.80 +        pos += len;
  519.81 +        return len;
  519.82 +    }
  519.83 +
  519.84 +    /*
  519.85 +     * Reads 'len' bytes from the input stream, or until an end-of-line
  519.86 +     * is reached. Returns the number of bytes read.
  519.87 +     */
  519.88 +    public int readLine(byte[] b, int off, int len) throws IOException {
  519.89 +        byte[] tbuf = this.buf;
  519.90 +        int total = 0;
  519.91 +        while (total < len) {
  519.92 +            int avail = count - pos;
  519.93 +            if (avail <= 0) {
  519.94 +                fill();
  519.95 +                avail = count - pos;
  519.96 +                if (avail <= 0) {
  519.97 +                    return -1;
  519.98 +                }
  519.99 +            }
 519.100 +            int n = len - total;
 519.101 +            if (n > avail) {
 519.102 +                n = avail;
 519.103 +            }
 519.104 +            int tpos = pos;
 519.105 +            int maxpos = tpos + n;
 519.106 +            while (tpos < maxpos && tbuf[tpos++] != '\n') {
 519.107 +                ;
 519.108 +            }
 519.109 +            n = tpos - pos;
 519.110 +            System.arraycopy(tbuf, pos, b, off, n);
 519.111 +            off += n;
 519.112 +            total += n;
 519.113 +            pos = tpos;
 519.114 +            if (tbuf[tpos - 1] == '\n') {
 519.115 +                break;
 519.116 +            }
 519.117 +        }
 519.118 +        return total;
 519.119 +    }
 519.120 +
 519.121 +    public byte peek() throws IOException {
 519.122 +        if (pos == count) {
 519.123 +            fill();
 519.124 +        }
 519.125 +        if (pos == count) {
 519.126 +            return -1; // nothing left in buffer
 519.127 +        }
 519.128 +        return buf[pos];
 519.129 +    }
 519.130 +
 519.131 +    public int readLine(byte[] b) throws IOException {
 519.132 +        return readLine(b, 0, b.length);
 519.133 +    }
 519.134 +
 519.135 +    public long skip(long n) throws IOException {
 519.136 +        if (n <= 0) {
 519.137 +            return 0;
 519.138 +        }
 519.139 +        long avail = count - pos;
 519.140 +        if (avail <= 0) {
 519.141 +            return in.skip(n);
 519.142 +        }
 519.143 +        if (n > avail) {
 519.144 +            n = avail;
 519.145 +        }
 519.146 +        pos += n;
 519.147 +        return n;
 519.148 +    }
 519.149 +
 519.150 +    public int available() throws IOException {
 519.151 +        return (count - pos) + in.available();
 519.152 +    }
 519.153 +
 519.154 +    public void close() throws IOException {
 519.155 +        if (in != null) {
 519.156 +            in.close();
 519.157 +            in = null;
 519.158 +            buf = null;
 519.159 +        }
 519.160 +    }
 519.161 +
 519.162 +    private void fill() throws IOException {
 519.163 +        count = pos = 0;
 519.164 +        int n = in.read(buf, 0, buf.length);
 519.165 +        if (n > 0) {
 519.166 +            count = n;
 519.167 +        }
 519.168 +    }
 519.169 +    
 519.170 +    protected abstract String putValue(String key, String value);
 519.171 +
 519.172 +    public void readAttributes(byte[] lbuf) throws IOException {
 519.173 +        ManifestInputStream is = this;
 519.174 +
 519.175 +        String name = null;
 519.176 +        String value = null;
 519.177 +        byte[] lastline = null;
 519.178 +        int len;
 519.179 +        while ((len = is.readLine(lbuf)) != -1) {
 519.180 +            boolean lineContinued = false;
 519.181 +            if (lbuf[--len] != '\n') {
 519.182 +                throw new IOException("line too long");
 519.183 +            }
 519.184 +            if (len > 0 && lbuf[len - 1] == '\r') {
 519.185 +                --len;
 519.186 +            }
 519.187 +            if (len == 0) {
 519.188 +                break;
 519.189 +            }
 519.190 +            int i = 0;
 519.191 +            if (lbuf[0] == ' ') {
 519.192 +                if (name == null) {
 519.193 +                    throw new IOException("misplaced continuation line");
 519.194 +                }
 519.195 +                lineContinued = true;
 519.196 +                byte[] buf = new byte[lastline.length + len - 1];
 519.197 +                System.arraycopy(lastline, 0, buf, 0, lastline.length);
 519.198 +                System.arraycopy(lbuf, 1, buf, lastline.length, len - 1);
 519.199 +                if (is.peek() == ' ') {
 519.200 +                    lastline = buf;
 519.201 +                    continue;
 519.202 +                }
 519.203 +                value = new String(buf, 0, buf.length, "UTF8");
 519.204 +                lastline = null;
 519.205 +            } else {
 519.206 +                while (lbuf[i++] != ':') {
 519.207 +                    if (i >= len) {
 519.208 +                        throw new IOException("invalid header field");
 519.209 +                    }
 519.210 +                }
 519.211 +                if (lbuf[i++] != ' ') {
 519.212 +                    throw new IOException("invalid header field");
 519.213 +                }
 519.214 +                name = new String(lbuf, 0, 0, i - 2);
 519.215 +                if (is.peek() == ' ') {
 519.216 +                    lastline = new byte[len - i];
 519.217 +                    System.arraycopy(lbuf, i, lastline, 0, len - i);
 519.218 +                    continue;
 519.219 +                }
 519.220 +                value = new String(lbuf, i, len - i, "UTF8");
 519.221 +            }
 519.222 +            try {
 519.223 +                if ((putValue(name, value) != null) && (!lineContinued)) {
 519.224 +                    throw new IOException("Duplicate name in Manifest: " + name + ".\n" + "Ensure that the manifest does not " + "have duplicate entries, and\n" + "that blank lines separate " + "individual sections in both your\n" + "manifest and in the META-INF/MANIFEST.MF " + "entry in the jar file.");
 519.225 +                }
 519.226 +            } catch (IllegalArgumentException e) {
 519.227 +                throw new IOException("invalid header field name: " + name);
 519.228 +            }
 519.229 +        }
 519.230 +    }
 519.231 +}
   520.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   520.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Wed Feb 27 11:24:58 2013 +0100
   520.3 @@ -0,0 +1,69 @@
   520.4 +/**
   520.5 + * Back 2 Browser Bytecode Translator
   520.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   520.7 + *
   520.8 + * This program is free software: you can redistribute it and/or modify
   520.9 + * it under the terms of the GNU General Public License as published by
  520.10 + * the Free Software Foundation, version 2 of the License.
  520.11 + *
  520.12 + * This program is distributed in the hope that it will be useful,
  520.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  520.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  520.15 + * GNU General Public License for more details.
  520.16 + *
  520.17 + * You should have received a copy of the GNU General Public License
  520.18 + * along with this program. Look for COPYING file in the top folder.
  520.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  520.20 + */
  520.21 +package org.apidesign.bck2brwsr.emul.lang;
  520.22 +
  520.23 +import java.lang.reflect.Method;
  520.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  520.25 +
  520.26 +/**
  520.27 + *
  520.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  520.29 + */
  520.30 +public class System {
  520.31 +    private System() {
  520.32 +    }
  520.33 +
  520.34 +    @JavaScriptBody(args = { "value", "srcBegin", "dst", "dstBegin", "count" }, body = 
  520.35 +        "if (srcBegin < dstBegin) {\n" +
  520.36 +        "    while (count-- > 0) {\n" +
  520.37 +        "        dst[dstBegin + count] = value[srcBegin + count];\n" +
  520.38 +        "    }\n" +
  520.39 +        "} else {\n" +
  520.40 +        "    while (count-- > 0) {\n" +
  520.41 +        "        dst[dstBegin++] = value[srcBegin++];\n" +
  520.42 +        "    }\n" +
  520.43 +        "}"
  520.44 +    )
  520.45 +    public static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) {
  520.46 +        try {
  520.47 +            Class<?> system = Class.forName("java.lang.System");
  520.48 +            Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class);
  520.49 +            m.invoke(null, src, srcBegin, dst, dstBegin, count);
  520.50 +        } catch (Exception ex) {
  520.51 +            throw new IllegalStateException(ex);
  520.52 +        }
  520.53 +    }
  520.54 +
  520.55 +    @JavaScriptBody(args = { "arr", "expectedSize" }, body = 
  520.56 +        "while (expectedSize-- > arr.length) { arr.push(0); }; return arr;"
  520.57 +    )
  520.58 +    public static native byte[] expandArray(byte[] arr, int expectedSize);
  520.59 +
  520.60 +    @JavaScriptBody(args = {}, body = "return new Date().getTime();")
  520.61 +    private static native double currentTimeMillisDouble();
  520.62 +
  520.63 +    public static long currentTimeMillis() {
  520.64 +        return (long) currentTimeMillisDouble();
  520.65 +    }
  520.66 +
  520.67 +    public static long nanoTime() {
  520.68 +        return 1000000L * currentTimeMillis();
  520.69 +    }
  520.70 +    @JavaScriptBody(args = { "obj" }, body="return vm.java_lang_Object(false).hashCode__I.call(obj);")
  520.71 +    public static native int identityHashCode(Object obj);
  520.72 +}
   521.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   521.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/AnnotationImpl.java	Wed Feb 27 11:24:58 2013 +0100
   521.3 @@ -0,0 +1,130 @@
   521.4 +/**
   521.5 + * Back 2 Browser Bytecode Translator
   521.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   521.7 + *
   521.8 + * This program is free software: you can redistribute it and/or modify
   521.9 + * it under the terms of the GNU General Public License as published by
  521.10 + * the Free Software Foundation, version 2 of the License.
  521.11 + *
  521.12 + * This program is distributed in the hope that it will be useful,
  521.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  521.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  521.15 + * GNU General Public License for more details.
  521.16 + *
  521.17 + * You should have received a copy of the GNU General Public License
  521.18 + * along with this program. Look for COPYING file in the top folder.
  521.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  521.20 + */
  521.21 +package org.apidesign.bck2brwsr.emul.reflect;
  521.22 +
  521.23 +import java.lang.annotation.Annotation;
  521.24 +import java.lang.reflect.Method;
  521.25 +import java.lang.reflect.Modifier;
  521.26 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  521.27 +
  521.28 +/**
  521.29 + *
  521.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  521.31 + */
  521.32 +public final class AnnotationImpl implements Annotation {
  521.33 +    private final Class<? extends Annotation> type;
  521.34 +
  521.35 +    public AnnotationImpl(Class<? extends Annotation> type) {
  521.36 +        this.type = type;
  521.37 +    }
  521.38 +    
  521.39 +    public Class<? extends Annotation> annotationType() {
  521.40 +        return type;
  521.41 +    }
  521.42 +
  521.43 +    @JavaScriptBody(args = { "a", "n", "arr", "values" }, body = ""
  521.44 +        + "function f(val, prop, clazz) {\n"
  521.45 +        + "  return function() {\n"
  521.46 +        + "    if (clazz == null) return val[prop];\n"
  521.47 +        + "    if (clazz.isArray__Z()) {\n"
  521.48 +        + "      var valarr = val[prop];\n"
  521.49 +        + "      var cmp = clazz.getComponentType__Ljava_lang_Class_2();\n"
  521.50 +        + "      var retarr = vm.java_lang_reflect_Array(false).newInstance__Ljava_lang_Object_2Ljava_lang_Class_2I(cmp, valarr.length);\n"
  521.51 +        + "      for (var i = 0; i < valarr.length; i++) {\n"
  521.52 +        + "        retarr[i] = CLS.prototype.c__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_Object_2(cmp, valarr[i]);\n"
  521.53 +        + "      }\n"
  521.54 +        + "      return retarr;\n"
  521.55 +        + "    }\n"
  521.56 +        + "    return CLS.prototype.c__Ljava_lang_Object_2Ljava_lang_Class_2Ljava_lang_Object_2(clazz, val[prop]);\n"
  521.57 +        + "  };\n"
  521.58 +        + "}\n"
  521.59 +        + "for (var i = 0; i < arr.length; i += 3) {\n"
  521.60 +        + "  var m = arr[i];\n"
  521.61 +        + "  var p = arr[i + 1];\n"
  521.62 +        + "  var c = arr[i + 2];\n"
  521.63 +        + "  a[m] = f(values, p, c);\n"
  521.64 +        + "}\n"
  521.65 +        + "a['$instOf_' + n] = true;\n"
  521.66 +        + "return a;"
  521.67 +    )
  521.68 +    private static native <T extends Annotation> T create(
  521.69 +        AnnotationImpl a, String n, Object[] methodsAndProps, Object values
  521.70 +    );
  521.71 +    
  521.72 +    private static Object c(Class<? extends Annotation> a, Object v) {
  521.73 +        return create(a, v);
  521.74 +    }
  521.75 +    
  521.76 +    public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
  521.77 +        return create(new AnnotationImpl(annoClass), 
  521.78 +            annoClass.getName().replace('.', '_'), 
  521.79 +            findProps(annoClass), values
  521.80 +        );
  521.81 +    }
  521.82 +
  521.83 +    public static Annotation[] create(Object anno) {
  521.84 +        String[] names = findNames(anno);
  521.85 +        Annotation[] ret = new Annotation[names.length];
  521.86 +        for (int i = 0; i < names.length; i++) {
  521.87 +            String annoNameSlash = names[i].substring(1, names[i].length() - 1);
  521.88 +            Class<? extends Annotation> annoClass;
  521.89 +            try {
  521.90 +                annoClass = (Class<? extends Annotation>)Class.forName(annoNameSlash.replace('/', '.'));
  521.91 +            } catch (ClassNotFoundException ex) {
  521.92 +                throw new IllegalStateException("Can't find annotation class " + annoNameSlash);
  521.93 +            }
  521.94 +            ret[i] = create(
  521.95 +                new AnnotationImpl(annoClass), 
  521.96 +                annoNameSlash.replace('/', '_'),
  521.97 +                findProps(annoClass),
  521.98 +                findData(anno, names[i])
  521.99 +            );
 521.100 +        }
 521.101 +        return ret;
 521.102 +    }
 521.103 +    @JavaScriptBody(args = "anno", body =
 521.104 +          "var arr = new Array();"
 521.105 +        + "var props = Object.getOwnPropertyNames(anno);\n"
 521.106 +        + "for (var i = 0; i < props.length; i++) {\n"
 521.107 +        + "  var p = props[i];\n"
 521.108 +        + "  arr.push(p);"
 521.109 +        + "}"
 521.110 +        + "return arr;"
 521.111 +    )
 521.112 +    private static native String[] findNames(Object anno);
 521.113 +
 521.114 +    @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
 521.115 +    private static native Object findData(Object anno, String p);
 521.116 +
 521.117 +    private static Object[] findProps(Class<?> annoClass) {
 521.118 +        final Method[] marr = MethodImpl.findMethods(annoClass, Modifier.PUBLIC);
 521.119 +        Object[] arr = new Object[marr.length * 3];
 521.120 +        int pos = 0;
 521.121 +        for (Method m : marr) {
 521.122 +            arr[pos++] = MethodImpl.toSignature(m);
 521.123 +            arr[pos++] = m.getName();
 521.124 +            final Class<?> rt = m.getReturnType();
 521.125 +            if (rt.isArray()) {
 521.126 +                arr[pos++] = rt.getComponentType().isAnnotation() ? rt : null;
 521.127 +            } else {
 521.128 +                arr[pos++] = rt.isAnnotation() ? rt : null;
 521.129 +            }
 521.130 +        }
 521.131 +        return arr;
 521.132 +    }
 521.133 +}
   522.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   522.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/MethodImpl.java	Wed Feb 27 11:24:58 2013 +0100
   522.3 @@ -0,0 +1,224 @@
   522.4 +/**
   522.5 + * Back 2 Browser Bytecode Translator
   522.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   522.7 + *
   522.8 + * This program is free software: you can redistribute it and/or modify
   522.9 + * it under the terms of the GNU General Public License as published by
  522.10 + * the Free Software Foundation, version 2 of the License.
  522.11 + *
  522.12 + * This program is distributed in the hope that it will be useful,
  522.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  522.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  522.15 + * GNU General Public License for more details.
  522.16 + *
  522.17 + * You should have received a copy of the GNU General Public License
  522.18 + * along with this program. Look for COPYING file in the top folder.
  522.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  522.20 + */
  522.21 +package org.apidesign.bck2brwsr.emul.reflect;
  522.22 +
  522.23 +import java.lang.reflect.Array;
  522.24 +import java.lang.reflect.Method;
  522.25 +import java.util.Enumeration;
  522.26 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  522.27 +
  522.28 +/** Utilities to work on methods.
  522.29 + *
  522.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  522.31 + */
  522.32 +public abstract class MethodImpl {
  522.33 +    public static MethodImpl INSTANCE;
  522.34 +    static {
  522.35 +        try {
  522.36 +            Class.forName(Method.class.getName());
  522.37 +        } catch (ClassNotFoundException ex) {
  522.38 +            throw new IllegalStateException(ex);
  522.39 +        }
  522.40 +    }
  522.41 +
  522.42 +    protected abstract Method create(Class<?> declaringClass, String name, Object data, String sig);
  522.43 +    
  522.44 +    
  522.45 +    //
  522.46 +    // bck2brwsr implementation
  522.47 +    //
  522.48 +
  522.49 +    @JavaScriptBody(args = {"clazz", "prefix"},
  522.50 +        body = ""
  522.51 +        + "var c = clazz.cnstr.prototype;"
  522.52 +        + "var arr = new Array();\n"
  522.53 +        + "for (m in c) {\n"
  522.54 +        + "  if (m.indexOf(prefix) === 0) {\n"
  522.55 +        + "     if (!c[m].cls) continue;\n"
  522.56 +        + "     arr.push(m);\n"
  522.57 +        + "     arr.push(c[m]);\n"
  522.58 +        + "     arr.push(c[m].cls.$class);\n"
  522.59 +        + "  }"
  522.60 +        + "}\n"
  522.61 +        + "return arr;")
  522.62 +    private static native Object[] findMethodData(
  522.63 +        Class<?> clazz, String prefix);
  522.64 +
  522.65 +    public static Method findMethod(
  522.66 +        Class<?> clazz, String name, Class<?>... parameterTypes) {
  522.67 +        Object[] data = findMethodData(clazz, name + "__");
  522.68 +        BIG: for (int i = 0; i < data.length; i += 3) {
  522.69 +            String sig = ((String) data[i]).substring(name.length() + 2);
  522.70 +            Class<?> cls = (Class<?>) data[i + 2];
  522.71 +            Method tmp = INSTANCE.create(cls, name, data[i + 1], sig);
  522.72 +            Class<?>[] tmpParms = tmp.getParameterTypes();
  522.73 +            if (parameterTypes.length != tmpParms.length) {
  522.74 +                continue;
  522.75 +            }
  522.76 +            for (int j = 0; j < tmpParms.length; j++) {
  522.77 +                if (!parameterTypes[j].equals(tmpParms[j])) {
  522.78 +                    continue BIG;
  522.79 +                }
  522.80 +            }
  522.81 +            return tmp;
  522.82 +        }
  522.83 +        return null;
  522.84 +    }
  522.85 +
  522.86 +    public static Method[] findMethods(Class<?> clazz, int mask) {
  522.87 +        Object[] namesAndData = findMethodData(clazz, "");
  522.88 +        int cnt = 0;
  522.89 +        for (int i = 0; i < namesAndData.length; i += 3) {
  522.90 +            String sig = (String) namesAndData[i];
  522.91 +            Object data = namesAndData[i + 1];
  522.92 +            int middle = sig.indexOf("__");
  522.93 +            if (middle == -1) {
  522.94 +                continue;
  522.95 +            }
  522.96 +            String name = sig.substring(0, middle);
  522.97 +            sig = sig.substring(middle + 2);
  522.98 +            Class<?> cls = (Class<?>) namesAndData[i + 2];
  522.99 +            final Method m = INSTANCE.create(cls, name, data, sig);
 522.100 +            if ((m.getModifiers() & mask) == 0) {
 522.101 +                continue;
 522.102 +            }
 522.103 +            namesAndData[cnt++] = m;
 522.104 +        }
 522.105 +        Method[] arr = new Method[cnt];
 522.106 +        for (int i = 0; i < cnt; i++) {
 522.107 +            arr[i] = (Method) namesAndData[i];
 522.108 +        }
 522.109 +        return arr;
 522.110 +    }
 522.111 +    static String toSignature(Method m) {
 522.112 +        StringBuilder sb = new StringBuilder();
 522.113 +        sb.append(m.getName()).append("__");
 522.114 +        appendType(sb, m.getReturnType());
 522.115 +        Class<?>[] arr = m.getParameterTypes();
 522.116 +        for (int i = 0; i < arr.length; i++) {
 522.117 +            appendType(sb, arr[i]);
 522.118 +        }
 522.119 +        return sb.toString();
 522.120 +    }
 522.121 +    
 522.122 +    private static void appendType(StringBuilder sb, Class<?> type) {
 522.123 +        if (type == Integer.TYPE) {
 522.124 +            sb.append('I');
 522.125 +            return;
 522.126 +        }
 522.127 +        if (type == Long.TYPE) {
 522.128 +            sb.append('J');
 522.129 +            return;
 522.130 +        }
 522.131 +        if (type == Double.TYPE) {
 522.132 +            sb.append('D');
 522.133 +            return;
 522.134 +        }
 522.135 +        if (type == Float.TYPE) {
 522.136 +            sb.append('F');
 522.137 +            return;
 522.138 +        }
 522.139 +        if (type == Byte.TYPE) {
 522.140 +            sb.append('B');
 522.141 +            return;
 522.142 +        }
 522.143 +        if (type == Boolean.TYPE) {
 522.144 +            sb.append('Z');
 522.145 +            return;
 522.146 +        }
 522.147 +        if (type == Short.TYPE) {
 522.148 +            sb.append('S');
 522.149 +            return;
 522.150 +        }
 522.151 +        if (type == Void.TYPE) {
 522.152 +            sb.append('V');
 522.153 +            return;
 522.154 +        }
 522.155 +        if (type == Character.TYPE) {
 522.156 +            sb.append('C');
 522.157 +            return;
 522.158 +        }
 522.159 +        if (type.isArray()) {
 522.160 +            sb.append("_3");
 522.161 +            appendType(sb, type.getComponentType());
 522.162 +            return;
 522.163 +        }
 522.164 +        sb.append('L').append(type.getName().replace('.', '_'));
 522.165 +        sb.append("_2");
 522.166 +    }
 522.167 +
 522.168 +    public static int signatureElements(String sig) {
 522.169 +        Enumeration<Class> en = signatureParser(sig);
 522.170 +        int cnt = 0;
 522.171 +        while (en.hasMoreElements()) {
 522.172 +            en.nextElement();
 522.173 +            cnt++;
 522.174 +        }
 522.175 +        return cnt;
 522.176 +    }
 522.177 +    
 522.178 +    public static Enumeration<Class> signatureParser(final String sig) {
 522.179 +        class E implements Enumeration<Class> {
 522.180 +            int pos;
 522.181 +            
 522.182 +            public boolean hasMoreElements() {
 522.183 +                return pos < sig.length();
 522.184 +            }
 522.185 +
 522.186 +            public Class nextElement() {
 522.187 +                switch (sig.charAt(pos++)) {
 522.188 +                    case 'I':
 522.189 +                        return Integer.TYPE;
 522.190 +                    case 'J':
 522.191 +                        return Long.TYPE;
 522.192 +                    case 'D':
 522.193 +                        return Double.TYPE;
 522.194 +                    case 'F':
 522.195 +                        return Float.TYPE;
 522.196 +                    case 'B':
 522.197 +                        return Byte.TYPE;
 522.198 +                    case 'Z':
 522.199 +                        return Boolean.TYPE;
 522.200 +                    case 'S':
 522.201 +                        return Short.TYPE;
 522.202 +                    case 'V':
 522.203 +                        return Void.TYPE;
 522.204 +                    case 'C':
 522.205 +                        return Character.TYPE;
 522.206 +                    case 'L':
 522.207 +                        try {
 522.208 +                            int up = sig.indexOf("_2", pos);
 522.209 +                            String type = sig.substring(pos, up);
 522.210 +                            pos = up + 2;
 522.211 +                            return Class.forName(type.replace('_', '.'));
 522.212 +                        } catch (ClassNotFoundException ex) {
 522.213 +                            throw new IllegalStateException(ex);
 522.214 +                        }
 522.215 +                    case '_': {
 522.216 +                        char nch = sig.charAt(pos++);
 522.217 +                        assert nch == '3' : "Can't find '3' at " + sig.substring(pos - 1);
 522.218 +                        final Class compType = nextElement();
 522.219 +                        return Array.newInstance(compType, 0).getClass();
 522.220 +                    }
 522.221 +                }
 522.222 +                throw new UnsupportedOperationException(sig + " at " + pos);
 522.223 +            }
 522.224 +        }
 522.225 +        return new E();
 522.226 +    }
 522.227 +}
   523.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   523.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/TypeProvider.java	Wed Feb 27 11:24:58 2013 +0100
   523.3 @@ -0,0 +1,40 @@
   523.4 +/**
   523.5 + * Back 2 Browser Bytecode Translator
   523.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   523.7 + *
   523.8 + * This program is free software: you can redistribute it and/or modify
   523.9 + * it under the terms of the GNU General Public License as published by
  523.10 + * the Free Software Foundation, version 2 of the License.
  523.11 + *
  523.12 + * This program is distributed in the hope that it will be useful,
  523.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  523.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  523.15 + * GNU General Public License for more details.
  523.16 + *
  523.17 + * You should have received a copy of the GNU General Public License
  523.18 + * along with this program. Look for COPYING file in the top folder.
  523.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  523.20 + */
  523.21 +package org.apidesign.bck2brwsr.emul.reflect;
  523.22 +
  523.23 +import java.lang.reflect.Constructor;
  523.24 +import java.lang.reflect.Type;
  523.25 +import java.lang.reflect.TypeVariable;
  523.26 +
  523.27 +/**
  523.28 + *
  523.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  523.30 + */
  523.31 +public abstract class TypeProvider {
  523.32 +    private TypeProvider() {
  523.33 +    }
  523.34 +    
  523.35 +    public static TypeProvider getDefault() {
  523.36 +        return null;
  523.37 +    }
  523.38 +    
  523.39 +    public abstract <T> TypeVariable<Constructor<T>>[] getTypeParameters(Constructor<T> c);
  523.40 +    public abstract <T> Type[] getGenericParameterTypes(Constructor<T> c);
  523.41 +    public abstract <T> Type[] getGenericExceptionTypes(Constructor<T> c);
  523.42 +    
  523.43 +}
   524.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   524.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Adler32.java	Wed Feb 27 11:24:58 2013 +0100
   524.3 @@ -0,0 +1,139 @@
   524.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   524.5 +/*
   524.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
   524.7 +
   524.8 +Redistribution and use in source and binary forms, with or without
   524.9 +modification, are permitted provided that the following conditions are met:
  524.10 +
  524.11 +  1. Redistributions of source code must retain the above copyright notice,
  524.12 +     this list of conditions and the following disclaimer.
  524.13 +
  524.14 +  2. Redistributions in binary form must reproduce the above copyright 
  524.15 +     notice, this list of conditions and the following disclaimer in 
  524.16 +     the documentation and/or other materials provided with the distribution.
  524.17 +
  524.18 +  3. The names of the authors may not be used to endorse or promote products
  524.19 +     derived from this software without specific prior written permission.
  524.20 +
  524.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  524.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  524.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  524.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  524.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  524.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  524.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  524.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  524.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  524.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  524.31 + */
  524.32 +/*
  524.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  524.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  524.35 + * and contributors of zlib.
  524.36 + */
  524.37 +
  524.38 +package org.apidesign.bck2brwsr.emul.zip;
  524.39 +
  524.40 +final class Adler32 implements Checksum {
  524.41 +
  524.42 +  // largest prime smaller than 65536
  524.43 +  static final private int BASE=65521; 
  524.44 +  // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
  524.45 +  static final private int NMAX=5552;
  524.46 +
  524.47 +  private long s1=1L;
  524.48 +  private long s2=0L;
  524.49 +
  524.50 +  public void reset(long init){
  524.51 +    s1=init&0xffff;
  524.52 +    s2=(init>>16)&0xffff;
  524.53 +  }
  524.54 +
  524.55 +  public void reset(){
  524.56 +    s1=1L;
  524.57 +    s2=0L;
  524.58 +  }
  524.59 +
  524.60 +  public long getValue(){
  524.61 +    return ((s2<<16)|s1);
  524.62 +  }
  524.63 +
  524.64 +  public void update(byte[] buf, int index, int len){
  524.65 +
  524.66 +    if(len==1){
  524.67 +      s1+=buf[index++]&0xff; s2+=s1;
  524.68 +      s1%=BASE;
  524.69 +      s2%=BASE;
  524.70 +      return;
  524.71 +    }
  524.72 +
  524.73 +    int len1 = len/NMAX;
  524.74 +    int len2 = len%NMAX;
  524.75 +    while(len1-->0) {
  524.76 +      int k=NMAX;
  524.77 +      len-=k;
  524.78 +      while(k-->0){
  524.79 +	s1+=buf[index++]&0xff; s2+=s1;
  524.80 +      }
  524.81 +      s1%=BASE;
  524.82 +      s2%=BASE;
  524.83 +    }
  524.84 +
  524.85 +    int k=len2;
  524.86 +    len-=k;
  524.87 +    while(k-->0){
  524.88 +      s1+=buf[index++]&0xff; s2+=s1;
  524.89 +    }
  524.90 +    s1%=BASE;
  524.91 +    s2%=BASE;
  524.92 +  }
  524.93 +
  524.94 +  public Adler32 copy(){
  524.95 +    Adler32 foo = new Adler32();
  524.96 +    foo.s1 = this.s1;
  524.97 +    foo.s2 = this.s2;
  524.98 +    return foo;
  524.99 +  }
 524.100 +
 524.101 +  // The following logic has come from zlib.1.2.
 524.102 +  static long combine(long adler1, long adler2, long len2){
 524.103 +    long BASEL = (long)BASE;
 524.104 +    long sum1;
 524.105 +    long sum2;
 524.106 +    long rem;  // unsigned int
 524.107 +
 524.108 +    rem = len2 % BASEL;
 524.109 +    sum1 = adler1 & 0xffffL;
 524.110 +    sum2 = rem * sum1;
 524.111 +    sum2 %= BASEL; // MOD(sum2);
 524.112 +    sum1 += (adler2 & 0xffffL) + BASEL - 1;
 524.113 +    sum2 += ((adler1 >> 16) & 0xffffL) + ((adler2 >> 16) & 0xffffL) + BASEL - rem;
 524.114 +    if (sum1 >= BASEL) sum1 -= BASEL;
 524.115 +    if (sum1 >= BASEL) sum1 -= BASEL;
 524.116 +    if (sum2 >= (BASEL << 1)) sum2 -= (BASEL << 1);
 524.117 +    if (sum2 >= BASEL) sum2 -= BASEL;
 524.118 +    return sum1 | (sum2 << 16);
 524.119 +  }
 524.120 +
 524.121 +/*
 524.122 +  private java.util.zip.Adler32 adler=new java.util.zip.Adler32();
 524.123 +  public void update(byte[] buf, int index, int len){
 524.124 +    if(buf==null) {adler.reset();}
 524.125 +    else{adler.update(buf, index, len);}
 524.126 +  }
 524.127 +  public void reset(){
 524.128 +    adler.reset();
 524.129 +  }
 524.130 +  public void reset(long init){
 524.131 +    if(init==1L){
 524.132 +      adler.reset();
 524.133 +    }
 524.134 +    else{
 524.135 +      System.err.println("unsupported operation");
 524.136 +    }
 524.137 +  }
 524.138 +  public long getValue(){
 524.139 +    return adler.getValue();
 524.140 +  }
 524.141 +*/
 524.142 +}
   525.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   525.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java	Wed Feb 27 11:24:58 2013 +0100
   525.3 @@ -0,0 +1,181 @@
   525.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   525.5 +/*
   525.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   525.7 +
   525.8 +Redistribution and use in source and binary forms, with or without
   525.9 +modification, are permitted provided that the following conditions are met:
  525.10 +
  525.11 +  1. Redistributions of source code must retain the above copyright notice,
  525.12 +     this list of conditions and the following disclaimer.
  525.13 +
  525.14 +  2. Redistributions in binary form must reproduce the above copyright 
  525.15 +     notice, this list of conditions and the following disclaimer in 
  525.16 +     the documentation and/or other materials provided with the distribution.
  525.17 +
  525.18 +  3. The names of the authors may not be used to endorse or promote products
  525.19 +     derived from this software without specific prior written permission.
  525.20 +
  525.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  525.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  525.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  525.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  525.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  525.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  525.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  525.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  525.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  525.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  525.31 + */
  525.32 +/*
  525.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  525.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  525.35 + * and contributors of zlib.
  525.36 + */
  525.37 +
  525.38 +package org.apidesign.bck2brwsr.emul.zip;
  525.39 +
  525.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  525.41 +
  525.42 +final class CRC32 implements Checksum {
  525.43 +
  525.44 +  /*
  525.45 +   *  The following logic has come from RFC1952.
  525.46 +   */
  525.47 +  private int v = 0;
  525.48 +  private static int[] crc_table = null;
  525.49 +  static {
  525.50 +    crc_table = new int[256];
  525.51 +    for (int n = 0; n < 256; n++) {
  525.52 +      int c = n;
  525.53 +      for (int k = 8;  --k >= 0; ) {
  525.54 +        if ((c & 1) != 0)
  525.55 +	  c = 0xedb88320 ^ (c >>> 1);
  525.56 +        else
  525.57 +          c = c >>> 1;
  525.58 +      }
  525.59 +      crc_table[n] = c;
  525.60 +    }
  525.61 +  }
  525.62 +
  525.63 +  public void update (byte[] buf, int index, int len) {
  525.64 +    int c = ~v;
  525.65 +    while (--len >= 0)
  525.66 +      c = crc_table[(c^buf[index++])&0xff]^(c >>> 8);
  525.67 +    v = ~c;
  525.68 +  }
  525.69 +
  525.70 +  public void reset(){
  525.71 +    v = 0;
  525.72 +  }
  525.73 +
  525.74 +  public void reset(long vv){
  525.75 +    v = (int)(vv&0xffffffffL);
  525.76 +  }
  525.77 +
  525.78 +  public long getValue(){
  525.79 +    return (long)(v&0xffffffffL);
  525.80 +  }
  525.81 +
  525.82 +  // The following logic has come from zlib.1.2.
  525.83 +  private static final int GF2_DIM = 32;
  525.84 +  static long combine(long crc1, long crc2, long len2){
  525.85 +    long row;
  525.86 +    long[] even = new long[GF2_DIM];
  525.87 +    long[] odd = new long[GF2_DIM];
  525.88 +
  525.89 +    // degenerate case (also disallow negative lengths)
  525.90 +    if (len2 <= 0)
  525.91 +      return crc1;
  525.92 +
  525.93 +    // put operator for one zero bit in odd
  525.94 +    odd[0] = 0xedb88320L;          // CRC-32 polynomial
  525.95 +    row = 1;
  525.96 +    for (int n = 1; n < GF2_DIM; n++) {
  525.97 +        odd[n] = row;
  525.98 +        row <<= 1;
  525.99 +    }
 525.100 +
 525.101 +    // put operator for two zero bits in even
 525.102 +    gf2_matrix_square(even, odd);
 525.103 +
 525.104 +    // put operator for four zero bits in odd
 525.105 +    gf2_matrix_square(odd, even);
 525.106 +
 525.107 +    // apply len2 zeros to crc1 (first square will put the operator for one
 525.108 +    // zero byte, eight zero bits, in even)
 525.109 +    do {
 525.110 +      // apply zeros operator for this bit of len2
 525.111 +      gf2_matrix_square(even, odd);
 525.112 +      if ((len2 & 1)!=0)
 525.113 +        crc1 = gf2_matrix_times(even, crc1);
 525.114 +      len2 >>= 1;
 525.115 +
 525.116 +      // if no more bits set, then done
 525.117 +      if (len2 == 0)
 525.118 +        break;
 525.119 +
 525.120 +      // another iteration of the loop with odd and even swapped
 525.121 +      gf2_matrix_square(odd, even);
 525.122 +      if ((len2 & 1)!=0)
 525.123 +        crc1 = gf2_matrix_times(odd, crc1);
 525.124 +      len2 >>= 1;
 525.125 +
 525.126 +      // if no more bits set, then done
 525.127 +    } while (len2 != 0);
 525.128 +
 525.129 +    /* return combined crc */
 525.130 +    crc1 ^= crc2;
 525.131 +    return crc1;
 525.132 +  }
 525.133 +
 525.134 +  private static long gf2_matrix_times(long[] mat, long vec){
 525.135 +    long sum = 0;
 525.136 +    int index = 0;
 525.137 +    while (vec!=0) {
 525.138 +      if ((vec & 1)!=0)
 525.139 +        sum ^= mat[index];
 525.140 +      vec >>= 1;
 525.141 +      index++;
 525.142 +    }
 525.143 +    return sum;
 525.144 +  }
 525.145 +
 525.146 +  static final void gf2_matrix_square(long[] square, long[] mat) {
 525.147 +    for (int n = 0; n < GF2_DIM; n++)
 525.148 +      square[n] = gf2_matrix_times(mat, mat[n]);
 525.149 +  }
 525.150 +
 525.151 +  /*
 525.152 +  private java.util.zip.CRC32 crc32 = new java.util.zip.CRC32();
 525.153 +
 525.154 +  public void update(byte[] buf, int index, int len){
 525.155 +    if(buf==null) {crc32.reset();}
 525.156 +    else{crc32.update(buf, index, len);}
 525.157 +  }
 525.158 +  public void reset(){
 525.159 +    crc32.reset();
 525.160 +  }
 525.161 +  public void reset(long init){
 525.162 +    if(init==0L){
 525.163 +      crc32.reset();
 525.164 +    }
 525.165 +    else{
 525.166 +      System.err.println("unsupported operation");
 525.167 +    }
 525.168 +  }
 525.169 +  public long getValue(){
 525.170 +    return crc32.getValue();
 525.171 +  }
 525.172 +*/
 525.173 +  public CRC32 copy(){
 525.174 +    CRC32 foo = new CRC32();
 525.175 +    foo.v = this.v;
 525.176 +    return foo;
 525.177 +  }
 525.178 +
 525.179 +  public static int[] getCRC32Table(){
 525.180 +    int[] tmp = new int[crc_table.length];
 525.181 +    System.arraycopy(crc_table, 0, tmp, 0, tmp.length);
 525.182 +    return tmp;
 525.183 +  }
 525.184 +}
   526.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   526.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Checksum.java	Wed Feb 27 11:24:58 2013 +0100
   526.3 @@ -0,0 +1,43 @@
   526.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   526.5 +/*
   526.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   526.7 +
   526.8 +Redistribution and use in source and binary forms, with or without
   526.9 +modification, are permitted provided that the following conditions are met:
  526.10 +
  526.11 +  1. Redistributions of source code must retain the above copyright notice,
  526.12 +     this list of conditions and the following disclaimer.
  526.13 +
  526.14 +  2. Redistributions in binary form must reproduce the above copyright 
  526.15 +     notice, this list of conditions and the following disclaimer in 
  526.16 +     the documentation and/or other materials provided with the distribution.
  526.17 +
  526.18 +  3. The names of the authors may not be used to endorse or promote products
  526.19 +     derived from this software without specific prior written permission.
  526.20 +
  526.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  526.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  526.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  526.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  526.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  526.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  526.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  526.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  526.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  526.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  526.31 + */
  526.32 +/*
  526.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  526.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  526.35 + * and contributors of zlib.
  526.36 + */
  526.37 +
  526.38 +package org.apidesign.bck2brwsr.emul.zip;
  526.39 +
  526.40 +interface Checksum {
  526.41 +  void update(byte[] buf, int index, int len);
  526.42 +  void reset();
  526.43 +  void reset(long init);
  526.44 +  long getValue();
  526.45 +  Checksum copy();
  526.46 +}
   527.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   527.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java	Wed Feb 27 11:24:58 2013 +0100
   527.3 @@ -0,0 +1,175 @@
   527.4 +/*
   527.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   527.6 + *
   527.7 + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   527.8 + *
   527.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  527.10 + * Other names may be trademarks of their respective owners.
  527.11 + *
  527.12 + * The contents of this file are subject to the terms of either the GNU
  527.13 + * General Public License Version 2 only ("GPL") or the Common
  527.14 + * Development and Distribution License("CDDL") (collectively, the
  527.15 + * "License"). You may not use this file except in compliance with the
  527.16 + * License. You can obtain a copy of the License at
  527.17 + * http://www.netbeans.org/cddl-gplv2.html
  527.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  527.19 + * specific language governing permissions and limitations under the
  527.20 + * License.  When distributing the software, include this License Header
  527.21 + * Notice in each file and include the License file at
  527.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  527.23 + * particular file as subject to the "Classpath" exception as provided
  527.24 + * by Oracle in the GPL Version 2 section of the License file that
  527.25 + * accompanied this code. If applicable, add the following below the
  527.26 + * License Header, with the fields enclosed by brackets [] replaced by
  527.27 + * your own identifying information:
  527.28 + * "Portions Copyrighted [year] [name of copyright owner]"
  527.29 + *
  527.30 + * Contributor(s):
  527.31 + *
  527.32 + * Portions Copyrighted 2007 Sun Microsystems, Inc.
  527.33 + */
  527.34 +package org.apidesign.bck2brwsr.emul.zip;
  527.35 +
  527.36 +import java.io.ByteArrayInputStream;
  527.37 +import java.io.IOException;
  527.38 +import java.io.InputStream;
  527.39 +import java.util.zip.ZipEntry;
  527.40 +import java.util.zip.ZipInputStream;
  527.41 +
  527.42 +/**
  527.43 + *
  527.44 + * @author Tomas Zezula
  527.45 + */
  527.46 +public final class FastJar {
  527.47 +    private final byte[] arr;
  527.48 +
  527.49 +    public FastJar(byte[] arr) {
  527.50 +        this.arr = arr;
  527.51 +    }
  527.52 +    
  527.53 +    
  527.54 +    private static final int GIVE_UP = 1<<16;
  527.55 +
  527.56 +    public static final  class Entry {
  527.57 +        
  527.58 +        public final String name;
  527.59 +        final long offset;
  527.60 +        private final long dosTime;
  527.61 +        
  527.62 +        Entry (String name, long offset, long time) {
  527.63 +            assert name != null;
  527.64 +            this.name = name;
  527.65 +            this.offset = offset;
  527.66 +            this.dosTime = time;
  527.67 +        }        
  527.68 +/*        
  527.69 +        public long getTime () {
  527.70 +            Date d = new Date((int)(((dosTime >> 25) & 0x7f) + 80),
  527.71 +                    (int)(((dosTime >> 21) & 0x0f) - 1),
  527.72 +                    (int)((dosTime >> 16) & 0x1f),
  527.73 +                    (int)((dosTime >> 11) & 0x1f),
  527.74 +                    (int)((dosTime >> 5) & 0x3f),
  527.75 +                    (int)((dosTime << 1) & 0x3e));
  527.76 +            return d.getTime();
  527.77 +        }
  527.78 +        */
  527.79 +    }
  527.80 +    
  527.81 +    public InputStream getInputStream (final Entry e) throws IOException {
  527.82 +        return getInputStream(arr, e.offset);
  527.83 +    }
  527.84 +    
  527.85 +    private static InputStream getInputStream (byte[] arr, final long offset) throws IOException {
  527.86 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  527.87 +        is.skip(offset);
  527.88 +        ZipInputStream in = new ZipInputStream (is);
  527.89 +        ZipEntry e = in.getNextEntry();
  527.90 +        if (e != null && e.getCrc() == 0L && e.getMethod() == ZipEntry.STORED) {
  527.91 +            int cp = arr.length - is.available();
  527.92 +            return new ByteArrayInputStream(arr, cp, (int)e.getSize());
  527.93 +        }
  527.94 +        return in;
  527.95 +    }
  527.96 +    
  527.97 +    public Entry[] list() throws IOException {
  527.98 +        final int size = arr.length;
  527.99 +
 527.100 +        int at = size - ZipInputStream.ENDHDR;
 527.101 +
 527.102 +        byte[] data = new byte[ZipInputStream.ENDHDR];        
 527.103 +        int giveup = 0;
 527.104 +
 527.105 +        do {
 527.106 +            org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
 527.107 +            at--;
 527.108 +            giveup++;
 527.109 +            if (giveup > GIVE_UP) {
 527.110 +                throw new IOException ();
 527.111 +            }
 527.112 +        } while (getsig(data) != ZipInputStream.ENDSIG);
 527.113 +
 527.114 +
 527.115 +        final long censize = endsiz(data);
 527.116 +        final long cenoff  = endoff(data);
 527.117 +        at = (int) cenoff;                                                     
 527.118 +
 527.119 +        Entry[] result = new Entry[0];
 527.120 +        int cenread = 0;
 527.121 +        data = new byte[ZipInputStream.CENHDR];
 527.122 +        while (cenread < censize) {
 527.123 +            org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, at, data, 0, data.length);
 527.124 +            at += data.length;
 527.125 +            if (getsig(data) != ZipInputStream.CENSIG) {
 527.126 +                throw new IOException("No central table");          //NOI18N
 527.127 +            }
 527.128 +            int cennam = cennam(data);
 527.129 +            int cenext = cenext(data);
 527.130 +            int cencom = cencom(data);
 527.131 +            long lhoff = cenoff(data);
 527.132 +            long centim = centim(data);
 527.133 +            String name = new String(arr, at, cennam, "UTF-8");
 527.134 +            at += cennam;
 527.135 +            int seekby = cenext+cencom;
 527.136 +            int cendatalen = ZipInputStream.CENHDR + cennam + seekby;
 527.137 +            cenread+=cendatalen;
 527.138 +            result = addEntry(result, new Entry(name,lhoff, centim));
 527.139 +            at += seekby;
 527.140 +        }
 527.141 +        return result;
 527.142 +    }
 527.143 +
 527.144 +    private Entry[] addEntry(Entry[] result, Entry entry) {
 527.145 +        Entry[] e = new Entry[result.length + 1];
 527.146 +        e[result.length] = entry;
 527.147 +        org.apidesign.bck2brwsr.emul.lang.System.arraycopy(result, 0, e, 0, result.length);
 527.148 +        return e;
 527.149 +    }
 527.150 +
 527.151 +    private static final long getsig(final byte[] b) throws IOException {return get32(b,0);}
 527.152 +    private static final long endsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDSIZ);}
 527.153 +    private static final long endoff(final byte[] b) throws IOException {return get32(b,ZipInputStream.ENDOFF);}
 527.154 +    private static final long  cenlen(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENLEN);}
 527.155 +    private static final long  censiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENSIZ);}
 527.156 +    private static final long centim(final byte[] b) throws IOException {return get32(b,ZipInputStream.CENTIM);}
 527.157 +    private static final int  cennam(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENNAM);}
 527.158 +    private static final int  cenext(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENEXT);}
 527.159 +    private static final int  cencom(final byte[] b) throws IOException {return get16(b,ZipInputStream.CENCOM);}
 527.160 +    private static final long cenoff (final byte[] b) throws IOException {return get32(b,ZipInputStream.CENOFF);}
 527.161 +    private static final int lochow(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCHOW);}
 527.162 +    private static final int locname(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCNAM);}
 527.163 +    private static final int locext(final byte[] b) throws IOException {return get16(b,ZipInputStream.LOCEXT);}
 527.164 +    private static final long locsiz(final byte[] b) throws IOException {return get32(b,ZipInputStream.LOCSIZ);}
 527.165 +    
 527.166 +    private static final int get16(final byte[] b, int off) throws IOException {        
 527.167 +        final int b1 = b[off];
 527.168 +	final int b2 = b[off+1];
 527.169 +        return (b1 & 0xff) | ((b2 & 0xff) << 8);
 527.170 +    }
 527.171 +
 527.172 +    private static final long get32(final byte[] b, int off) throws IOException {
 527.173 +	final int s1 = get16(b, off);
 527.174 +	final int s2 = get16(b, off+2);
 527.175 +        return s1 | ((long)s2 << 16);
 527.176 +    }
 527.177 +
 527.178 +}
   528.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   528.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java	Wed Feb 27 11:24:58 2013 +0100
   528.3 @@ -0,0 +1,215 @@
   528.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   528.5 +/*
   528.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   528.7 +
   528.8 +Redistribution and use in source and binary forms, with or without
   528.9 +modification, are permitted provided that the following conditions are met:
  528.10 +
  528.11 +  1. Redistributions of source code must retain the above copyright notice,
  528.12 +     this list of conditions and the following disclaimer.
  528.13 +
  528.14 +  2. Redistributions in binary form must reproduce the above copyright 
  528.15 +     notice, this list of conditions and the following disclaimer in 
  528.16 +     the documentation and/or other materials provided with the distribution.
  528.17 +
  528.18 +  3. The names of the authors may not be used to endorse or promote products
  528.19 +     derived from this software without specific prior written permission.
  528.20 +
  528.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  528.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  528.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  528.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  528.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  528.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  528.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  528.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  528.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  528.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  528.31 + */
  528.32 +/*
  528.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  528.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  528.35 + * and contributors of zlib.
  528.36 + */
  528.37 +
  528.38 +package org.apidesign.bck2brwsr.emul.zip;
  528.39 +
  528.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  528.41 +import java.io.UnsupportedEncodingException;
  528.42 +
  528.43 +/**
  528.44 + * @see "http://www.ietf.org/rfc/rfc1952.txt"
  528.45 + */
  528.46 +final class GZIPHeader implements Cloneable {
  528.47 +
  528.48 +  public static final byte OS_MSDOS = (byte) 0x00;
  528.49 +  public static final byte OS_AMIGA = (byte) 0x01;
  528.50 +  public static final byte OS_VMS = (byte) 0x02;
  528.51 +  public static final byte OS_UNIX = (byte) 0x03;
  528.52 +  public static final byte OS_ATARI = (byte) 0x05;
  528.53 +  public static final byte OS_OS2 = (byte) 0x06;
  528.54 +  public static final byte OS_MACOS = (byte) 0x07;
  528.55 +  public static final byte OS_TOPS20 = (byte) 0x0a;
  528.56 +  public static final byte OS_WIN32 = (byte) 0x0b;
  528.57 +  public static final byte OS_VMCMS = (byte) 0x04;
  528.58 +  public static final byte OS_ZSYSTEM = (byte) 0x08;
  528.59 +  public static final byte OS_CPM = (byte) 0x09;
  528.60 +  public static final byte OS_QDOS = (byte) 0x0c;
  528.61 +  public static final byte OS_RISCOS = (byte) 0x0d;
  528.62 +  public static final byte OS_UNKNOWN = (byte) 0xff;
  528.63 +
  528.64 +  boolean text = false;
  528.65 +  private boolean fhcrc = false;
  528.66 +  long time;
  528.67 +  int xflags;
  528.68 +  int os = 255;
  528.69 +  byte[] extra;
  528.70 +  byte[] name;
  528.71 +  byte[] comment;
  528.72 +  int hcrc;
  528.73 +  long crc;
  528.74 +  boolean done = false;
  528.75 +  long mtime = 0;
  528.76 +
  528.77 +  public void setModifiedTime(long mtime) {
  528.78 +    this.mtime = mtime;
  528.79 +  }
  528.80 +
  528.81 +  public long getModifiedTime() {
  528.82 +    return mtime;
  528.83 +  }
  528.84 +
  528.85 +  public void setOS(int os) {
  528.86 +    if((0<=os && os <=13) || os==255)
  528.87 +      this.os=os;
  528.88 +    else
  528.89 +      throw new IllegalArgumentException("os: "+os);
  528.90 +  }
  528.91 +
  528.92 +  public int getOS(){
  528.93 +    return os;
  528.94 +  }
  528.95 +
  528.96 +  public void setName(String name) {
  528.97 +    try{
  528.98 +      this.name=name.getBytes("ISO-8859-1");
  528.99 +    }
 528.100 +    catch(UnsupportedEncodingException e){
 528.101 +      throw new IllegalArgumentException("name must be in ISO-8859-1 "+name);
 528.102 +    }
 528.103 +  }
 528.104 +
 528.105 +  public String getName(){
 528.106 +    if(name==null) return "";
 528.107 +    try {
 528.108 +      return new String(name, "ISO-8859-1");
 528.109 +    }
 528.110 +    catch (UnsupportedEncodingException e) {
 528.111 +      throw new IllegalArgumentException(e.toString());
 528.112 +    }
 528.113 +  }
 528.114 +
 528.115 +  public void setComment(String comment) {
 528.116 +    try{
 528.117 +      this.comment=comment.getBytes("ISO-8859-1");
 528.118 +    }
 528.119 +    catch(UnsupportedEncodingException e){
 528.120 +      throw new IllegalArgumentException("comment must be in ISO-8859-1 "+name);
 528.121 +    }
 528.122 +  }
 528.123 +
 528.124 +  public String getComment(){
 528.125 +    if(comment==null) return "";
 528.126 +    try {
 528.127 +      return new String(comment, "ISO-8859-1");
 528.128 +    }
 528.129 +    catch (UnsupportedEncodingException e) {
 528.130 +      throw new IllegalArgumentException(e.toString());
 528.131 +    }
 528.132 +  }
 528.133 +
 528.134 +  public void setCRC(long crc){
 528.135 +    this.crc = crc;
 528.136 +  }
 528.137 +
 528.138 +  public long getCRC(){
 528.139 +    return crc;
 528.140 +  }
 528.141 +/*
 528.142 +  void put(Deflate d){
 528.143 +    int flag = 0;
 528.144 +    if(text){
 528.145 +      flag |= 1;     // FTEXT
 528.146 +    }
 528.147 +    if(fhcrc){
 528.148 +      flag |= 2;     // FHCRC
 528.149 +    }
 528.150 +    if(extra!=null){
 528.151 +      flag |= 4;     // FEXTRA
 528.152 +    }
 528.153 +    if(name!=null){
 528.154 +      flag |= 8;    // FNAME
 528.155 +    }
 528.156 +    if(comment!=null){
 528.157 +      flag |= 16;   // FCOMMENT
 528.158 +    }
 528.159 +    int xfl = 0;
 528.160 +    if(d.level == JZlib.Z_BEST_SPEED){
 528.161 +      xfl |= 4;
 528.162 +    }
 528.163 +    else if (d.level == JZlib.Z_BEST_COMPRESSION){
 528.164 +      xfl |= 2;
 528.165 +    }
 528.166 +
 528.167 +    d.put_short((short)0x8b1f);  // ID1 ID2
 528.168 +    d.put_byte((byte)8);         // CM(Compression Method)
 528.169 +    d.put_byte((byte)flag);
 528.170 +    d.put_byte((byte)mtime);
 528.171 +    d.put_byte((byte)(mtime>>8));
 528.172 +    d.put_byte((byte)(mtime>>16));
 528.173 +    d.put_byte((byte)(mtime>>24));
 528.174 +    d.put_byte((byte)xfl);
 528.175 +    d.put_byte((byte)os);
 528.176 +
 528.177 +    if(extra!=null){
 528.178 +      d.put_byte((byte)extra.length);
 528.179 +      d.put_byte((byte)(extra.length>>8));
 528.180 +      d.put_byte(extra, 0, extra.length);
 528.181 +    }
 528.182 +
 528.183 +    if(name!=null){
 528.184 +      d.put_byte(name, 0, name.length);
 528.185 +      d.put_byte((byte)0);
 528.186 +    }
 528.187 +
 528.188 +    if(comment!=null){
 528.189 +      d.put_byte(comment, 0, comment.length);
 528.190 +      d.put_byte((byte)0);
 528.191 +    }
 528.192 +  }
 528.193 +*/
 528.194 +  @Override
 528.195 +  public Object clone() throws CloneNotSupportedException {
 528.196 +    GZIPHeader gheader = (GZIPHeader)super.clone();
 528.197 +    byte[] tmp;
 528.198 +    if(gheader.extra!=null){
 528.199 +      tmp=new byte[gheader.extra.length];
 528.200 +      System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length);
 528.201 +      gheader.extra = tmp;
 528.202 +    }
 528.203 +
 528.204 +    if(gheader.name!=null){
 528.205 +      tmp=new byte[gheader.name.length];
 528.206 +      System.arraycopy(gheader.name, 0, tmp, 0, tmp.length);
 528.207 +      gheader.name = tmp;
 528.208 +    }
 528.209 +
 528.210 +    if(gheader.comment!=null){
 528.211 +      tmp=new byte[gheader.comment.length];
 528.212 +      System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length);
 528.213 +      gheader.comment = tmp;
 528.214 +    }
 528.215 +
 528.216 +    return gheader;
 528.217 +  }
 528.218 +}
   529.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   529.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java	Wed Feb 27 11:24:58 2013 +0100
   529.3 @@ -0,0 +1,616 @@
   529.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   529.5 +/*
   529.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   529.7 +
   529.8 +Redistribution and use in source and binary forms, with or without
   529.9 +modification, are permitted provided that the following conditions are met:
  529.10 +
  529.11 +  1. Redistributions of source code must retain the above copyright notice,
  529.12 +     this list of conditions and the following disclaimer.
  529.13 +
  529.14 +  2. Redistributions in binary form must reproduce the above copyright 
  529.15 +     notice, this list of conditions and the following disclaimer in 
  529.16 +     the documentation and/or other materials provided with the distribution.
  529.17 +
  529.18 +  3. The names of the authors may not be used to endorse or promote products
  529.19 +     derived from this software without specific prior written permission.
  529.20 +
  529.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  529.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  529.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  529.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  529.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  529.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  529.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  529.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  529.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  529.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  529.31 + */
  529.32 +/*
  529.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  529.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  529.35 + * and contributors of zlib.
  529.36 + */
  529.37 +
  529.38 +package org.apidesign.bck2brwsr.emul.zip;
  529.39 +
  529.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  529.41 +
  529.42 +final class InfBlocks{
  529.43 +  static final private int MANY=1440;
  529.44 +
  529.45 +  // And'ing with mask[n] masks the lower n bits
  529.46 +  static final private int[] inflate_mask = {
  529.47 +    0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
  529.48 +    0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
  529.49 +    0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
  529.50 +    0x00007fff, 0x0000ffff
  529.51 +  };
  529.52 +
  529.53 +  // Table for deflate from PKZIP's appnote.txt.
  529.54 +  static final int[] border = { // Order of the bit length code lengths
  529.55 +    16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  529.56 +  };
  529.57 +
  529.58 +  static final private int Z_OK=0;
  529.59 +  static final private int Z_STREAM_END=1;
  529.60 +  static final private int Z_NEED_DICT=2;
  529.61 +  static final private int Z_ERRNO=-1;
  529.62 +  static final private int Z_STREAM_ERROR=-2;
  529.63 +  static final private int Z_DATA_ERROR=-3;
  529.64 +  static final private int Z_MEM_ERROR=-4;
  529.65 +  static final private int Z_BUF_ERROR=-5;
  529.66 +  static final private int Z_VERSION_ERROR=-6;
  529.67 +
  529.68 +  static final private int TYPE=0;  // get type bits (3, including end bit)
  529.69 +  static final private int LENS=1;  // get lengths for stored
  529.70 +  static final private int STORED=2;// processing stored block
  529.71 +  static final private int TABLE=3; // get table lengths
  529.72 +  static final private int BTREE=4; // get bit lengths tree for a dynamic block
  529.73 +  static final private int DTREE=5; // get length, distance trees for a dynamic block
  529.74 +  static final private int CODES=6; // processing fixed or dynamic block
  529.75 +  static final private int DRY=7;   // output remaining window bytes
  529.76 +  static final private int DONE=8;  // finished last block, done
  529.77 +  static final private int BAD=9;   // ot a data error--stuck here
  529.78 +
  529.79 +  int mode;            // current inflate_block mode 
  529.80 +
  529.81 +  int left;            // if STORED, bytes left to copy 
  529.82 +
  529.83 +  int table;           // table lengths (14 bits) 
  529.84 +  int index;           // index into blens (or border) 
  529.85 +  int[] blens;         // bit lengths of codes 
  529.86 +  int[] bb=new int[1]; // bit length tree depth 
  529.87 +  int[] tb=new int[1]; // bit length decoding tree 
  529.88 +
  529.89 +  int[] bl=new int[1];
  529.90 +  int[] bd=new int[1];
  529.91 +
  529.92 +  int[][] tl=new int[1][];
  529.93 +  int[][] td=new int[1][];
  529.94 +  int[] tli=new int[1]; // tl_index
  529.95 +  int[] tdi=new int[1]; // td_index
  529.96 +
  529.97 +  private final InfCodes codes;      // if CODES, current state 
  529.98 +
  529.99 +  int last;            // true if this block is the last block 
 529.100 +
 529.101 +  // mode independent information 
 529.102 +  int bitk;            // bits in bit buffer 
 529.103 +  int bitb;            // bit buffer 
 529.104 +  int[] hufts;         // single malloc for tree space 
 529.105 +  byte[] window;       // sliding window 
 529.106 +  int end;             // one byte after sliding window 
 529.107 +  int read;            // window read pointer 
 529.108 +  int write;           // window write pointer 
 529.109 +  private boolean check;
 529.110 +
 529.111 +  private final InfTree inftree=new InfTree();
 529.112 +
 529.113 +  private final ZStream z; 
 529.114 +
 529.115 +  InfBlocks(ZStream z, int w){
 529.116 +    this.z=z;
 529.117 +    this.codes=new InfCodes(this.z, this);
 529.118 +    hufts=new int[MANY*3];
 529.119 +    window=new byte[w];
 529.120 +    end=w;
 529.121 +    this.check = (z.istate.wrap==0) ? false : true;
 529.122 +    mode = TYPE;
 529.123 +    reset();
 529.124 +  }
 529.125 +
 529.126 +  void reset(){
 529.127 +    if(mode==BTREE || mode==DTREE){
 529.128 +    }
 529.129 +    if(mode==CODES){
 529.130 +      codes.free(z);
 529.131 +    }
 529.132 +    mode=TYPE;
 529.133 +    bitk=0;
 529.134 +    bitb=0;
 529.135 +    read=write=0;
 529.136 +    if(check){
 529.137 +      z.adler.reset();
 529.138 +    }
 529.139 +  }
 529.140 +
 529.141 +  int proc(int r){
 529.142 +    int t;              // temporary storage
 529.143 +    int b;              // bit buffer
 529.144 +    int k;              // bits in bit buffer
 529.145 +    int p;              // input data pointer
 529.146 +    int n;              // bytes available there
 529.147 +    int q;              // output window write pointer
 529.148 +    int m;              // bytes to end of window or read pointer
 529.149 +
 529.150 +    // copy input/output information to locals (UPDATE macro restores)
 529.151 +    {p=z.next_in_index;n=z.avail_in;b=bitb;k=bitk;}
 529.152 +    {q=write;m=(int)(q<read?read-q-1:end-q);}
 529.153 +
 529.154 +    // process input based on current state
 529.155 +    while(true){
 529.156 +      switch (mode){
 529.157 +      case TYPE:
 529.158 +
 529.159 +	while(k<(3)){
 529.160 +	  if(n!=0){
 529.161 +	    r=Z_OK;
 529.162 +	  }
 529.163 +	  else{
 529.164 +	    bitb=b; bitk=k; 
 529.165 +	    z.avail_in=n;
 529.166 +	    z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.167 +	    write=q;
 529.168 +	    return inflate_flush(r);
 529.169 +	  };
 529.170 +	  n--;
 529.171 +	  b|=(z.next_in[p++]&0xff)<<k;
 529.172 +	  k+=8;
 529.173 +	}
 529.174 +	t = (int)(b & 7);
 529.175 +	last = t & 1;
 529.176 +
 529.177 +	switch (t >>> 1){
 529.178 +        case 0:                         // stored 
 529.179 +          {b>>>=(3);k-=(3);}
 529.180 +          t = k & 7;                    // go to byte boundary
 529.181 +
 529.182 +          {b>>>=(t);k-=(t);}
 529.183 +          mode = LENS;                  // get length of stored block
 529.184 +          break;
 529.185 +        case 1:                         // fixed
 529.186 +          InfTree.inflate_trees_fixed(bl, bd, tl, td, z);
 529.187 +          codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
 529.188 +
 529.189 +          {b>>>=(3);k-=(3);}
 529.190 +
 529.191 +          mode = CODES;
 529.192 +          break;
 529.193 +        case 2:                         // dynamic
 529.194 +
 529.195 +          {b>>>=(3);k-=(3);}
 529.196 +
 529.197 +          mode = TABLE;
 529.198 +          break;
 529.199 +        case 3:                         // illegal
 529.200 +
 529.201 +          {b>>>=(3);k-=(3);}
 529.202 +          mode = BAD;
 529.203 +          z.msg = "invalid block type";
 529.204 +          r = Z_DATA_ERROR;
 529.205 +
 529.206 +	  bitb=b; bitk=k; 
 529.207 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.208 +	  write=q;
 529.209 +	  return inflate_flush(r);
 529.210 +	}
 529.211 +	break;
 529.212 +      case LENS:
 529.213 +
 529.214 +	while(k<(32)){
 529.215 +	  if(n!=0){
 529.216 +	    r=Z_OK;
 529.217 +	  }
 529.218 +	  else{
 529.219 +	    bitb=b; bitk=k; 
 529.220 +	    z.avail_in=n;
 529.221 +	    z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.222 +	    write=q;
 529.223 +	    return inflate_flush(r);
 529.224 +	  };
 529.225 +	  n--;
 529.226 +	  b|=(z.next_in[p++]&0xff)<<k;
 529.227 +	  k+=8;
 529.228 +	}
 529.229 +
 529.230 +	if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)){
 529.231 +	  mode = BAD;
 529.232 +	  z.msg = "invalid stored block lengths";
 529.233 +	  r = Z_DATA_ERROR;
 529.234 +
 529.235 +	  bitb=b; bitk=k; 
 529.236 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.237 +	  write=q;
 529.238 +	  return inflate_flush(r);
 529.239 +	}
 529.240 +	left = (b & 0xffff);
 529.241 +	b = k = 0;                       // dump bits
 529.242 +	mode = left!=0 ? STORED : (last!=0 ? DRY : TYPE);
 529.243 +	break;
 529.244 +      case STORED:
 529.245 +	if (n == 0){
 529.246 +	  bitb=b; bitk=k; 
 529.247 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.248 +	  write=q;
 529.249 +	  return inflate_flush(r);
 529.250 +	}
 529.251 +
 529.252 +	if(m==0){
 529.253 +	  if(q==end&&read!=0){
 529.254 +	    q=0; m=(int)(q<read?read-q-1:end-q);
 529.255 +	  }
 529.256 +	  if(m==0){
 529.257 +	    write=q; 
 529.258 +	    r=inflate_flush(r);
 529.259 +	    q=write;m=(int)(q<read?read-q-1:end-q);
 529.260 +	    if(q==end&&read!=0){
 529.261 +	      q=0; m=(int)(q<read?read-q-1:end-q);
 529.262 +	    }
 529.263 +	    if(m==0){
 529.264 +	      bitb=b; bitk=k; 
 529.265 +	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.266 +	      write=q;
 529.267 +	      return inflate_flush(r);
 529.268 +	    }
 529.269 +	  }
 529.270 +	}
 529.271 +	r=Z_OK;
 529.272 +
 529.273 +	t = left;
 529.274 +	if(t>n) t = n;
 529.275 +	if(t>m) t = m;
 529.276 +	System.arraycopy(z.next_in, p, window, q, t);
 529.277 +	p += t;  n -= t;
 529.278 +	q += t;  m -= t;
 529.279 +	if ((left -= t) != 0)
 529.280 +	  break;
 529.281 +	mode = last!=0 ? DRY : TYPE;
 529.282 +	break;
 529.283 +      case TABLE:
 529.284 +
 529.285 +	while(k<(14)){
 529.286 +	  if(n!=0){
 529.287 +	    r=Z_OK;
 529.288 +	  }
 529.289 +	  else{
 529.290 +	    bitb=b; bitk=k; 
 529.291 +	    z.avail_in=n;
 529.292 +	    z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.293 +	    write=q;
 529.294 +	    return inflate_flush(r);
 529.295 +	  };
 529.296 +	  n--;
 529.297 +	  b|=(z.next_in[p++]&0xff)<<k;
 529.298 +	  k+=8;
 529.299 +	}
 529.300 +
 529.301 +	table = t = (b & 0x3fff);
 529.302 +	if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
 529.303 +	  {
 529.304 +	    mode = BAD;
 529.305 +	    z.msg = "too many length or distance symbols";
 529.306 +	    r = Z_DATA_ERROR;
 529.307 +
 529.308 +	    bitb=b; bitk=k; 
 529.309 +	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.310 +	    write=q;
 529.311 +	    return inflate_flush(r);
 529.312 +	  }
 529.313 +	t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
 529.314 +	if(blens==null || blens.length<t){
 529.315 +	  blens=new int[t];
 529.316 +	}
 529.317 +	else{
 529.318 +	  for(int i=0; i<t; i++){blens[i]=0;}
 529.319 +	}
 529.320 +
 529.321 +	{b>>>=(14);k-=(14);}
 529.322 +
 529.323 +	index = 0;
 529.324 +	mode = BTREE;
 529.325 +      case BTREE:
 529.326 +	while (index < 4 + (table >>> 10)){
 529.327 +	  while(k<(3)){
 529.328 +	    if(n!=0){
 529.329 +	      r=Z_OK;
 529.330 +	    }
 529.331 +	    else{
 529.332 +	      bitb=b; bitk=k; 
 529.333 +	      z.avail_in=n;
 529.334 +	      z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.335 +	      write=q;
 529.336 +	      return inflate_flush(r);
 529.337 +	    };
 529.338 +	    n--;
 529.339 +	    b|=(z.next_in[p++]&0xff)<<k;
 529.340 +	    k+=8;
 529.341 +	  }
 529.342 +
 529.343 +	  blens[border[index++]] = b&7;
 529.344 +
 529.345 +	  {b>>>=(3);k-=(3);}
 529.346 +	}
 529.347 +
 529.348 +	while(index < 19){
 529.349 +	  blens[border[index++]] = 0;
 529.350 +	}
 529.351 +
 529.352 +	bb[0] = 7;
 529.353 +	t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
 529.354 +	if (t != Z_OK){
 529.355 +	  r = t;
 529.356 +	  if (r == Z_DATA_ERROR){
 529.357 +	    blens=null;
 529.358 +	    mode = BAD;
 529.359 +	  }
 529.360 +
 529.361 +	  bitb=b; bitk=k; 
 529.362 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.363 +	  write=q;
 529.364 +	  return inflate_flush(r);
 529.365 +	}
 529.366 +
 529.367 +	index = 0;
 529.368 +	mode = DTREE;
 529.369 +      case DTREE:
 529.370 +	while (true){
 529.371 +	  t = table;
 529.372 +	  if(!(index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))){
 529.373 +	    break;
 529.374 +	  }
 529.375 +
 529.376 +	  int[] h;
 529.377 +	  int i, j, c;
 529.378 +
 529.379 +	  t = bb[0];
 529.380 +
 529.381 +	  while(k<(t)){
 529.382 +	    if(n!=0){
 529.383 +	      r=Z_OK;
 529.384 +	    }
 529.385 +	    else{
 529.386 +	      bitb=b; bitk=k; 
 529.387 +	      z.avail_in=n;
 529.388 +	      z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.389 +	      write=q;
 529.390 +	      return inflate_flush(r);
 529.391 +	    };
 529.392 +	    n--;
 529.393 +	    b|=(z.next_in[p++]&0xff)<<k;
 529.394 +	    k+=8;
 529.395 +	  }
 529.396 +
 529.397 +	  if(tb[0]==-1){
 529.398 +            //System.err.println("null...");
 529.399 +	  }
 529.400 +
 529.401 +	  t=hufts[(tb[0]+(b&inflate_mask[t]))*3+1];
 529.402 +	  c=hufts[(tb[0]+(b&inflate_mask[t]))*3+2];
 529.403 +
 529.404 +	  if (c < 16){
 529.405 +	    b>>>=(t);k-=(t);
 529.406 +	    blens[index++] = c;
 529.407 +	  }
 529.408 +	  else { // c == 16..18
 529.409 +	    i = c == 18 ? 7 : c - 14;
 529.410 +	    j = c == 18 ? 11 : 3;
 529.411 +
 529.412 +	    while(k<(t+i)){
 529.413 +	      if(n!=0){
 529.414 +		r=Z_OK;
 529.415 +	      }
 529.416 +	      else{
 529.417 +		bitb=b; bitk=k; 
 529.418 +		z.avail_in=n;
 529.419 +		z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.420 +		write=q;
 529.421 +		return inflate_flush(r);
 529.422 +	      };
 529.423 +	      n--;
 529.424 +	      b|=(z.next_in[p++]&0xff)<<k;
 529.425 +	      k+=8;
 529.426 +	    }
 529.427 +
 529.428 +	    b>>>=(t);k-=(t);
 529.429 +
 529.430 +	    j += (b & inflate_mask[i]);
 529.431 +
 529.432 +	    b>>>=(i);k-=(i);
 529.433 +
 529.434 +	    i = index;
 529.435 +	    t = table;
 529.436 +	    if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
 529.437 +		(c == 16 && i < 1)){
 529.438 +	      blens=null;
 529.439 +	      mode = BAD;
 529.440 +	      z.msg = "invalid bit length repeat";
 529.441 +	      r = Z_DATA_ERROR;
 529.442 +
 529.443 +	      bitb=b; bitk=k; 
 529.444 +	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.445 +	      write=q;
 529.446 +	      return inflate_flush(r);
 529.447 +	    }
 529.448 +
 529.449 +	    c = c == 16 ? blens[i-1] : 0;
 529.450 +	    do{
 529.451 +	      blens[i++] = c;
 529.452 +	    }
 529.453 +	    while (--j!=0);
 529.454 +	    index = i;
 529.455 +	  }
 529.456 +	}
 529.457 +
 529.458 +	tb[0]=-1;
 529.459 +	{
 529.460 +	  bl[0] = 9;         // must be <= 9 for lookahead assumptions
 529.461 +	  bd[0] = 6;         // must be <= 9 for lookahead assumptions
 529.462 +	  t = table;
 529.463 +	  t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 
 529.464 +					    1 + ((t >> 5) & 0x1f),
 529.465 +					    blens, bl, bd, tli, tdi, hufts, z);
 529.466 +
 529.467 +	  if (t != Z_OK){
 529.468 +	    if (t == Z_DATA_ERROR){
 529.469 +	      blens=null;
 529.470 +	      mode = BAD;
 529.471 +	    }
 529.472 +	    r = t;
 529.473 +
 529.474 +	    bitb=b; bitk=k; 
 529.475 +	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.476 +	    write=q;
 529.477 +	    return inflate_flush(r);
 529.478 +	  }
 529.479 +	  codes.init(bl[0], bd[0], hufts, tli[0], hufts, tdi[0]);
 529.480 +	}
 529.481 +	mode = CODES;
 529.482 +      case CODES:
 529.483 +	bitb=b; bitk=k;
 529.484 +	z.avail_in=n; z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.485 +	write=q;
 529.486 +
 529.487 +	if ((r = codes.proc(r)) != Z_STREAM_END){
 529.488 +	  return inflate_flush(r);
 529.489 +	}
 529.490 +	r = Z_OK;
 529.491 +	codes.free(z);
 529.492 +
 529.493 +	p=z.next_in_index; n=z.avail_in;b=bitb;k=bitk;
 529.494 +	q=write;m=(int)(q<read?read-q-1:end-q);
 529.495 +
 529.496 +	if (last==0){
 529.497 +	  mode = TYPE;
 529.498 +	  break;
 529.499 +	}
 529.500 +	mode = DRY;
 529.501 +      case DRY:
 529.502 +	write=q; 
 529.503 +	r=inflate_flush(r); 
 529.504 +	q=write; m=(int)(q<read?read-q-1:end-q);
 529.505 +	if (read != write){
 529.506 +	  bitb=b; bitk=k; 
 529.507 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.508 +	  write=q;
 529.509 +	  return inflate_flush(r);
 529.510 +	}
 529.511 +	mode = DONE;
 529.512 +      case DONE:
 529.513 +	r = Z_STREAM_END;
 529.514 +
 529.515 +	bitb=b; bitk=k; 
 529.516 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.517 +	write=q;
 529.518 +	return inflate_flush(r);
 529.519 +      case BAD:
 529.520 +	r = Z_DATA_ERROR;
 529.521 +
 529.522 +	bitb=b; bitk=k; 
 529.523 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.524 +	write=q;
 529.525 +	return inflate_flush(r);
 529.526 +
 529.527 +      default:
 529.528 +	r = Z_STREAM_ERROR;
 529.529 +
 529.530 +	bitb=b; bitk=k; 
 529.531 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 529.532 +	write=q;
 529.533 +	return inflate_flush(r);
 529.534 +      }
 529.535 +    }
 529.536 +  }
 529.537 +
 529.538 +  void free(){
 529.539 +    reset();
 529.540 +    window=null;
 529.541 +    hufts=null;
 529.542 +    //ZFREE(z, s);
 529.543 +  }
 529.544 +
 529.545 +  void set_dictionary(byte[] d, int start, int n){
 529.546 +    System.arraycopy(d, start, window, 0, n);
 529.547 +    read = write = n;
 529.548 +  }
 529.549 +
 529.550 +  // Returns true if inflate is currently at the end of a block generated
 529.551 +  // by Z_SYNC_FLUSH or Z_FULL_FLUSH. 
 529.552 +  int sync_point(){
 529.553 +    return mode == LENS ? 1 : 0;
 529.554 +  }
 529.555 +
 529.556 +  // copy as much as possible from the sliding window to the output area
 529.557 +  int inflate_flush(int r){
 529.558 +    int n;
 529.559 +    int p;
 529.560 +    int q;
 529.561 +
 529.562 +    // local copies of source and destination pointers
 529.563 +    p = z.next_out_index;
 529.564 +    q = read;
 529.565 +
 529.566 +    // compute number of bytes to copy as far as end of window
 529.567 +    n = (int)((q <= write ? write : end) - q);
 529.568 +    if(n > z.avail_out) n = z.avail_out;
 529.569 +    if(n!=0 && r == Z_BUF_ERROR) r = Z_OK;
 529.570 +
 529.571 +    // update counters
 529.572 +    z.avail_out -= n;
 529.573 +    z.total_out += n;
 529.574 +
 529.575 +    // update check information
 529.576 +    if(check && n>0){
 529.577 +      z.adler.update(window, q, n);
 529.578 +    }
 529.579 +
 529.580 +    // copy as far as end of window
 529.581 +    System.arraycopy(window, q, z.next_out, p, n);
 529.582 +    p += n;
 529.583 +    q += n;
 529.584 +
 529.585 +    // see if more to copy at beginning of window
 529.586 +    if (q == end){
 529.587 +      // wrap pointers
 529.588 +      q = 0;
 529.589 +      if (write == end)
 529.590 +        write = 0;
 529.591 +
 529.592 +      // compute bytes to copy
 529.593 +      n = write - q;
 529.594 +      if (n > z.avail_out) n = z.avail_out;
 529.595 +      if (n!=0 && r == Z_BUF_ERROR) r = Z_OK;
 529.596 +
 529.597 +      // update counters
 529.598 +      z.avail_out -= n;
 529.599 +      z.total_out += n;
 529.600 +
 529.601 +      // update check information
 529.602 +      if(check && n>0){
 529.603 +	z.adler.update(window, q, n);
 529.604 +      }
 529.605 +
 529.606 +      // copy
 529.607 +      System.arraycopy(window, q, z.next_out, p, n);
 529.608 +      p += n;
 529.609 +      q += n;
 529.610 +    }
 529.611 +
 529.612 +    // update pointers
 529.613 +    z.next_out_index = p;
 529.614 +    read = q;
 529.615 +
 529.616 +    // done
 529.617 +    return r;
 529.618 +  }
 529.619 +}
   530.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   530.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java	Wed Feb 27 11:24:58 2013 +0100
   530.3 @@ -0,0 +1,612 @@
   530.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   530.5 +/*
   530.6 +Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
   530.7 +
   530.8 +Redistribution and use in source and binary forms, with or without
   530.9 +modification, are permitted provided that the following conditions are met:
  530.10 +
  530.11 +  1. Redistributions of source code must retain the above copyright notice,
  530.12 +     this list of conditions and the following disclaimer.
  530.13 +
  530.14 +  2. Redistributions in binary form must reproduce the above copyright 
  530.15 +     notice, this list of conditions and the following disclaimer in 
  530.16 +     the documentation and/or other materials provided with the distribution.
  530.17 +
  530.18 +  3. The names of the authors may not be used to endorse or promote products
  530.19 +     derived from this software without specific prior written permission.
  530.20 +
  530.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  530.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  530.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  530.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  530.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  530.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  530.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  530.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  530.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  530.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  530.31 + */
  530.32 +/*
  530.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  530.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  530.35 + * and contributors of zlib.
  530.36 + */
  530.37 +
  530.38 +package org.apidesign.bck2brwsr.emul.zip;
  530.39 +
  530.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  530.41 +
  530.42 +final class InfCodes{
  530.43 +
  530.44 +  static final private int[] inflate_mask = {
  530.45 +    0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
  530.46 +    0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,
  530.47 +    0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,
  530.48 +    0x00007fff, 0x0000ffff
  530.49 +  };
  530.50 +
  530.51 +  static final private int Z_OK=0;
  530.52 +  static final private int Z_STREAM_END=1;
  530.53 +  static final private int Z_NEED_DICT=2;
  530.54 +  static final private int Z_ERRNO=-1;
  530.55 +  static final private int Z_STREAM_ERROR=-2;
  530.56 +  static final private int Z_DATA_ERROR=-3;
  530.57 +  static final private int Z_MEM_ERROR=-4;
  530.58 +  static final private int Z_BUF_ERROR=-5;
  530.59 +  static final private int Z_VERSION_ERROR=-6;
  530.60 +
  530.61 +  // waiting for "i:"=input,
  530.62 +  //             "o:"=output,
  530.63 +  //             "x:"=nothing
  530.64 +  static final private int START=0;  // x: set up for LEN
  530.65 +  static final private int LEN=1;    // i: get length/literal/eob next
  530.66 +  static final private int LENEXT=2; // i: getting length extra (have base)
  530.67 +  static final private int DIST=3;   // i: get distance next
  530.68 +  static final private int DISTEXT=4;// i: getting distance extra
  530.69 +  static final private int COPY=5;   // o: copying bytes in window, waiting for space
  530.70 +  static final private int LIT=6;    // o: got literal, waiting for output space
  530.71 +  static final private int WASH=7;   // o: got eob, possibly still output waiting
  530.72 +  static final private int END=8;    // x: got eob and all data flushed
  530.73 +  static final private int BADCODE=9;// x: got error
  530.74 +
  530.75 +  int mode;      // current inflate_codes mode
  530.76 +
  530.77 +  // mode dependent information
  530.78 +  int len;
  530.79 +
  530.80 +  int[] tree; // pointer into tree
  530.81 +  int tree_index=0;
  530.82 +  int need;   // bits needed
  530.83 +
  530.84 +  int lit;
  530.85 +
  530.86 +  // if EXT or COPY, where and how much
  530.87 +  int get;              // bits to get for extra
  530.88 +  int dist;             // distance back to copy from
  530.89 +
  530.90 +  byte lbits;           // ltree bits decoded per branch
  530.91 +  byte dbits;           // dtree bits decoder per branch
  530.92 +  int[] ltree;          // literal/length/eob tree
  530.93 +  int ltree_index;      // literal/length/eob tree
  530.94 +  int[] dtree;          // distance tree
  530.95 +  int dtree_index;      // distance tree
  530.96 +
  530.97 +  private final ZStream z;
  530.98 +  private final InfBlocks s;
  530.99 +  InfCodes(ZStream z, InfBlocks s){
 530.100 +    this.z=z; 
 530.101 +    this.s=s; 
 530.102 +  }
 530.103 +
 530.104 +  void init(int bl, int bd,
 530.105 +	   int[] tl, int tl_index,
 530.106 +	   int[] td, int td_index){
 530.107 +    mode=START;
 530.108 +    lbits=(byte)bl;
 530.109 +    dbits=(byte)bd;
 530.110 +    ltree=tl;
 530.111 +    ltree_index=tl_index;
 530.112 +    dtree = td;
 530.113 +    dtree_index=td_index;
 530.114 +    tree=null;
 530.115 +  }
 530.116 +
 530.117 +  int proc(int r){ 
 530.118 +    int j;              // temporary storage
 530.119 +    int[] t;            // temporary pointer
 530.120 +    int tindex;         // temporary pointer
 530.121 +    int e;              // extra bits or operation
 530.122 +    int b=0;            // bit buffer
 530.123 +    int k=0;            // bits in bit buffer
 530.124 +    int p=0;            // input data pointer
 530.125 +    int n;              // bytes available there
 530.126 +    int q;              // output window write pointer
 530.127 +    int m;              // bytes to end of window or read pointer
 530.128 +    int f;              // pointer to copy strings from
 530.129 +
 530.130 +    // copy input/output information to locals (UPDATE macro restores)
 530.131 +    p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
 530.132 +    q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 530.133 +
 530.134 +    // process input and output based on current state
 530.135 +    while (true){
 530.136 +      switch (mode){
 530.137 +	// waiting for "i:"=input, "o:"=output, "x:"=nothing
 530.138 +      case START:         // x: set up for LEN
 530.139 +	if (m >= 258 && n >= 10){
 530.140 +
 530.141 +	  s.bitb=b;s.bitk=k;
 530.142 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.143 +	  s.write=q;
 530.144 +	  r = inflate_fast(lbits, dbits, 
 530.145 +			   ltree, ltree_index, 
 530.146 +			   dtree, dtree_index,
 530.147 +			   s, z);
 530.148 +
 530.149 +	  p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
 530.150 +	  q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 530.151 +
 530.152 +	  if (r != Z_OK){
 530.153 +	    mode = r == Z_STREAM_END ? WASH : BADCODE;
 530.154 +	    break;
 530.155 +	  }
 530.156 +	}
 530.157 +	need = lbits;
 530.158 +	tree = ltree;
 530.159 +	tree_index=ltree_index;
 530.160 +
 530.161 +	mode = LEN;
 530.162 +      case LEN:           // i: get length/literal/eob next
 530.163 +	j = need;
 530.164 +
 530.165 +	while(k<(j)){
 530.166 +	  if(n!=0)r=Z_OK;
 530.167 +	  else{
 530.168 +
 530.169 +	    s.bitb=b;s.bitk=k;
 530.170 +	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.171 +	    s.write=q;
 530.172 +	    return s.inflate_flush(r);
 530.173 +	  }
 530.174 +	  n--;
 530.175 +	  b|=(z.next_in[p++]&0xff)<<k;
 530.176 +	  k+=8;
 530.177 +	}
 530.178 +
 530.179 +	tindex=(tree_index+(b&inflate_mask[j]))*3;
 530.180 +
 530.181 +	b>>>=(tree[tindex+1]);
 530.182 +	k-=(tree[tindex+1]);
 530.183 +
 530.184 +	e=tree[tindex];
 530.185 +
 530.186 +	if(e == 0){               // literal
 530.187 +	  lit = tree[tindex+2];
 530.188 +	  mode = LIT;
 530.189 +	  break;
 530.190 +	}
 530.191 +	if((e & 16)!=0 ){          // length
 530.192 +	  get = e & 15;
 530.193 +	  len = tree[tindex+2];
 530.194 +	  mode = LENEXT;
 530.195 +	  break;
 530.196 +	}
 530.197 +	if ((e & 64) == 0){        // next table
 530.198 +	  need = e;
 530.199 +	  tree_index = tindex/3+tree[tindex+2];
 530.200 +	  break;
 530.201 +	}
 530.202 +	if ((e & 32)!=0){               // end of block
 530.203 +	  mode = WASH;
 530.204 +	  break;
 530.205 +	}
 530.206 +	mode = BADCODE;        // invalid code
 530.207 +	z.msg = "invalid literal/length code";
 530.208 +	r = Z_DATA_ERROR;
 530.209 +
 530.210 +	s.bitb=b;s.bitk=k;
 530.211 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.212 +	s.write=q;
 530.213 +	return s.inflate_flush(r);
 530.214 +
 530.215 +      case LENEXT:        // i: getting length extra (have base)
 530.216 +	j = get;
 530.217 +
 530.218 +	while(k<(j)){
 530.219 +	  if(n!=0)r=Z_OK;
 530.220 +	  else{
 530.221 +
 530.222 +	    s.bitb=b;s.bitk=k;
 530.223 +	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.224 +	    s.write=q;
 530.225 +	    return s.inflate_flush(r);
 530.226 +	  }
 530.227 +	  n--; b|=(z.next_in[p++]&0xff)<<k;
 530.228 +	  k+=8;
 530.229 +	}
 530.230 +
 530.231 +	len += (b & inflate_mask[j]);
 530.232 +
 530.233 +	b>>=j;
 530.234 +	k-=j;
 530.235 +
 530.236 +	need = dbits;
 530.237 +	tree = dtree;
 530.238 +	tree_index=dtree_index;
 530.239 +	mode = DIST;
 530.240 +      case DIST:          // i: get distance next
 530.241 +	j = need;
 530.242 +
 530.243 +	while(k<(j)){
 530.244 +	  if(n!=0)r=Z_OK;
 530.245 +	  else{
 530.246 +
 530.247 +	    s.bitb=b;s.bitk=k;
 530.248 +	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.249 +	    s.write=q;
 530.250 +	    return s.inflate_flush(r);
 530.251 +	  }
 530.252 +	  n--; b|=(z.next_in[p++]&0xff)<<k;
 530.253 +	  k+=8;
 530.254 +	}
 530.255 +
 530.256 +	tindex=(tree_index+(b & inflate_mask[j]))*3;
 530.257 +
 530.258 +	b>>=tree[tindex+1];
 530.259 +	k-=tree[tindex+1];
 530.260 +
 530.261 +	e = (tree[tindex]);
 530.262 +	if((e & 16)!=0){               // distance
 530.263 +	  get = e & 15;
 530.264 +	  dist = tree[tindex+2];
 530.265 +	  mode = DISTEXT;
 530.266 +	  break;
 530.267 +	}
 530.268 +	if ((e & 64) == 0){        // next table
 530.269 +	  need = e;
 530.270 +	  tree_index = tindex/3 + tree[tindex+2];
 530.271 +	  break;
 530.272 +	}
 530.273 +	mode = BADCODE;        // invalid code
 530.274 +	z.msg = "invalid distance code";
 530.275 +	r = Z_DATA_ERROR;
 530.276 +
 530.277 +	s.bitb=b;s.bitk=k;
 530.278 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.279 +	s.write=q;
 530.280 +	return s.inflate_flush(r);
 530.281 +
 530.282 +      case DISTEXT:       // i: getting distance extra
 530.283 +	j = get;
 530.284 +
 530.285 +	while(k<(j)){
 530.286 +	  if(n!=0)r=Z_OK;
 530.287 +	  else{
 530.288 +
 530.289 +	    s.bitb=b;s.bitk=k;
 530.290 +	    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.291 +	    s.write=q;
 530.292 +	    return s.inflate_flush(r);
 530.293 +	  }
 530.294 +	  n--; b|=(z.next_in[p++]&0xff)<<k;
 530.295 +	  k+=8;
 530.296 +	}
 530.297 +
 530.298 +	dist += (b & inflate_mask[j]);
 530.299 +
 530.300 +	b>>=j;
 530.301 +	k-=j;
 530.302 +
 530.303 +	mode = COPY;
 530.304 +      case COPY:          // o: copying bytes in window, waiting for space
 530.305 +        f = q - dist;
 530.306 +        while(f < 0){     // modulo window size-"while" instead
 530.307 +          f += s.end;     // of "if" handles invalid distances
 530.308 +	}
 530.309 +	while (len!=0){
 530.310 +
 530.311 +	  if(m==0){
 530.312 +	    if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 530.313 +	    if(m==0){
 530.314 +	      s.write=q; r=s.inflate_flush(r);
 530.315 +	      q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 530.316 +
 530.317 +	      if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 530.318 +
 530.319 +	      if(m==0){
 530.320 +		s.bitb=b;s.bitk=k;
 530.321 +		z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.322 +		s.write=q;
 530.323 +		return s.inflate_flush(r);
 530.324 +	      }  
 530.325 +	    }
 530.326 +	  }
 530.327 +
 530.328 +	  s.window[q++]=s.window[f++]; m--;
 530.329 +
 530.330 +	  if (f == s.end)
 530.331 +            f = 0;
 530.332 +	  len--;
 530.333 +	}
 530.334 +	mode = START;
 530.335 +	break;
 530.336 +      case LIT:           // o: got literal, waiting for output space
 530.337 +	if(m==0){
 530.338 +	  if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 530.339 +	  if(m==0){
 530.340 +	    s.write=q; r=s.inflate_flush(r);
 530.341 +	    q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 530.342 +
 530.343 +	    if(q==s.end&&s.read!=0){q=0;m=q<s.read?s.read-q-1:s.end-q;}
 530.344 +	    if(m==0){
 530.345 +	      s.bitb=b;s.bitk=k;
 530.346 +	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.347 +	      s.write=q;
 530.348 +	      return s.inflate_flush(r);
 530.349 +	    }
 530.350 +	  }
 530.351 +	}
 530.352 +	r=Z_OK;
 530.353 +
 530.354 +	s.window[q++]=(byte)lit; m--;
 530.355 +
 530.356 +	mode = START;
 530.357 +	break;
 530.358 +      case WASH:           // o: got eob, possibly more output
 530.359 +	if (k > 7){        // return unused byte, if any
 530.360 +	  k -= 8;
 530.361 +	  n++;
 530.362 +	  p--;             // can always return one
 530.363 +	}
 530.364 +
 530.365 +	s.write=q; r=s.inflate_flush(r);
 530.366 +	q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 530.367 +
 530.368 +	if (s.read != s.write){
 530.369 +	  s.bitb=b;s.bitk=k;
 530.370 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.371 +	  s.write=q;
 530.372 +	  return s.inflate_flush(r);
 530.373 +	}
 530.374 +	mode = END;
 530.375 +      case END:
 530.376 +	r = Z_STREAM_END;
 530.377 +	s.bitb=b;s.bitk=k;
 530.378 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.379 +	s.write=q;
 530.380 +	return s.inflate_flush(r);
 530.381 +
 530.382 +      case BADCODE:       // x: got error
 530.383 +
 530.384 +	r = Z_DATA_ERROR;
 530.385 +
 530.386 +	s.bitb=b;s.bitk=k;
 530.387 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.388 +	s.write=q;
 530.389 +	return s.inflate_flush(r);
 530.390 +
 530.391 +      default:
 530.392 +	r = Z_STREAM_ERROR;
 530.393 +
 530.394 +	s.bitb=b;s.bitk=k;
 530.395 +	z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.396 +	s.write=q;
 530.397 +	return s.inflate_flush(r);
 530.398 +      }
 530.399 +    }
 530.400 +  }
 530.401 +
 530.402 +  void free(ZStream z){
 530.403 +    //  ZFREE(z, c);
 530.404 +  }
 530.405 +
 530.406 +  // Called with number of bytes left to write in window at least 258
 530.407 +  // (the maximum string length) and number of input bytes available
 530.408 +  // at least ten.  The ten bytes are six bytes for the longest length/
 530.409 +  // distance pair plus four bytes for overloading the bit buffer.
 530.410 +
 530.411 +  int inflate_fast(int bl, int bd, 
 530.412 +		   int[] tl, int tl_index,
 530.413 +		   int[] td, int td_index,
 530.414 +		   InfBlocks s, ZStream z){
 530.415 +    int t;                // temporary pointer
 530.416 +    int[] tp;             // temporary pointer
 530.417 +    int tp_index;         // temporary pointer
 530.418 +    int e;                // extra bits or operation
 530.419 +    int b;                // bit buffer
 530.420 +    int k;                // bits in bit buffer
 530.421 +    int p;                // input data pointer
 530.422 +    int n;                // bytes available there
 530.423 +    int q;                // output window write pointer
 530.424 +    int m;                // bytes to end of window or read pointer
 530.425 +    int ml;               // mask for literal/length tree
 530.426 +    int md;               // mask for distance tree
 530.427 +    int c;                // bytes to copy
 530.428 +    int d;                // distance back to copy from
 530.429 +    int r;                // copy source pointer
 530.430 +
 530.431 +    int tp_index_t_3;     // (tp_index+t)*3
 530.432 +
 530.433 +    // load input, output, bit values
 530.434 +    p=z.next_in_index;n=z.avail_in;b=s.bitb;k=s.bitk;
 530.435 +    q=s.write;m=q<s.read?s.read-q-1:s.end-q;
 530.436 +
 530.437 +    // initialize masks
 530.438 +    ml = inflate_mask[bl];
 530.439 +    md = inflate_mask[bd];
 530.440 +
 530.441 +    // do until not enough input or output space for fast loop
 530.442 +    do {                          // assume called with m >= 258 && n >= 10
 530.443 +      // get literal/length code
 530.444 +      while(k<(20)){              // max bits for literal/length code
 530.445 +	n--;
 530.446 +	b|=(z.next_in[p++]&0xff)<<k;k+=8;
 530.447 +      }
 530.448 +
 530.449 +      t= b&ml;
 530.450 +      tp=tl; 
 530.451 +      tp_index=tl_index;
 530.452 +      tp_index_t_3=(tp_index+t)*3;
 530.453 +      if ((e = tp[tp_index_t_3]) == 0){
 530.454 +	b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 530.455 +
 530.456 +	s.window[q++] = (byte)tp[tp_index_t_3+2];
 530.457 +	m--;
 530.458 +	continue;
 530.459 +      }
 530.460 +      do {
 530.461 +
 530.462 +	b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 530.463 +
 530.464 +	if((e&16)!=0){
 530.465 +	  e &= 15;
 530.466 +	  c = tp[tp_index_t_3+2] + ((int)b & inflate_mask[e]);
 530.467 +
 530.468 +	  b>>=e; k-=e;
 530.469 +
 530.470 +	  // decode distance base of block to copy
 530.471 +	  while(k<(15)){           // max bits for distance code
 530.472 +	    n--;
 530.473 +	    b|=(z.next_in[p++]&0xff)<<k;k+=8;
 530.474 +	  }
 530.475 +
 530.476 +	  t= b&md;
 530.477 +	  tp=td;
 530.478 +	  tp_index=td_index;
 530.479 +          tp_index_t_3=(tp_index+t)*3;
 530.480 +	  e = tp[tp_index_t_3];
 530.481 +
 530.482 +	  do {
 530.483 +
 530.484 +	    b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 530.485 +
 530.486 +	    if((e&16)!=0){
 530.487 +	      // get extra bits to add to distance base
 530.488 +	      e &= 15;
 530.489 +	      while(k<(e)){         // get extra bits (up to 13)
 530.490 +		n--;
 530.491 +		b|=(z.next_in[p++]&0xff)<<k;k+=8;
 530.492 +	      }
 530.493 +
 530.494 +	      d = tp[tp_index_t_3+2] + (b&inflate_mask[e]);
 530.495 +
 530.496 +	      b>>=(e); k-=(e);
 530.497 +
 530.498 +	      // do the copy
 530.499 +	      m -= c;
 530.500 +	      if (q >= d){                // offset before dest
 530.501 +		//  just copy
 530.502 +		r=q-d;
 530.503 +		if(q-r>0 && 2>(q-r)){           
 530.504 +		  s.window[q++]=s.window[r++]; // minimum count is three,
 530.505 +		  s.window[q++]=s.window[r++]; // so unroll loop a little
 530.506 +		  c-=2;
 530.507 +		}
 530.508 +		else{
 530.509 +		  System.arraycopy(s.window, r, s.window, q, 2);
 530.510 +		  q+=2; r+=2; c-=2;
 530.511 +		}
 530.512 +	      }
 530.513 +	      else{                  // else offset after destination
 530.514 +                r=q-d;
 530.515 +                do{
 530.516 +                  r+=s.end;          // force pointer in window
 530.517 +                }while(r<0);         // covers invalid distances
 530.518 +		e=s.end-r;
 530.519 +		if(c>e){             // if source crosses,
 530.520 +		  c-=e;              // wrapped copy
 530.521 +		  if(q-r>0 && e>(q-r)){           
 530.522 +		    do{s.window[q++] = s.window[r++];}
 530.523 +		    while(--e!=0);
 530.524 +		  }
 530.525 +		  else{
 530.526 +		    System.arraycopy(s.window, r, s.window, q, e);
 530.527 +		    q+=e; r+=e; e=0;
 530.528 +		  }
 530.529 +		  r = 0;                  // copy rest from start of window
 530.530 +		}
 530.531 +
 530.532 +	      }
 530.533 +
 530.534 +	      // copy all or what's left
 530.535 +	      if(q-r>0 && c>(q-r)){           
 530.536 +		do{s.window[q++] = s.window[r++];}
 530.537 +		while(--c!=0);
 530.538 +	      }
 530.539 +	      else{
 530.540 +		System.arraycopy(s.window, r, s.window, q, c);
 530.541 +		q+=c; r+=c; c=0;
 530.542 +	      }
 530.543 +	      break;
 530.544 +	    }
 530.545 +	    else if((e&64)==0){
 530.546 +	      t+=tp[tp_index_t_3+2];
 530.547 +	      t+=(b&inflate_mask[e]);
 530.548 +	      tp_index_t_3=(tp_index+t)*3;
 530.549 +	      e=tp[tp_index_t_3];
 530.550 +	    }
 530.551 +	    else{
 530.552 +	      z.msg = "invalid distance code";
 530.553 +
 530.554 +	      c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 530.555 +
 530.556 +	      s.bitb=b;s.bitk=k;
 530.557 +	      z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.558 +	      s.write=q;
 530.559 +
 530.560 +	      return Z_DATA_ERROR;
 530.561 +	    }
 530.562 +	  }
 530.563 +	  while(true);
 530.564 +	  break;
 530.565 +	}
 530.566 +
 530.567 +	if((e&64)==0){
 530.568 +	  t+=tp[tp_index_t_3+2];
 530.569 +	  t+=(b&inflate_mask[e]);
 530.570 +	  tp_index_t_3=(tp_index+t)*3;
 530.571 +	  if((e=tp[tp_index_t_3])==0){
 530.572 +
 530.573 +	    b>>=(tp[tp_index_t_3+1]); k-=(tp[tp_index_t_3+1]);
 530.574 +
 530.575 +	    s.window[q++]=(byte)tp[tp_index_t_3+2];
 530.576 +	    m--;
 530.577 +	    break;
 530.578 +	  }
 530.579 +	}
 530.580 +	else if((e&32)!=0){
 530.581 +
 530.582 +	  c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 530.583 + 
 530.584 +	  s.bitb=b;s.bitk=k;
 530.585 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.586 +	  s.write=q;
 530.587 +
 530.588 +	  return Z_STREAM_END;
 530.589 +	}
 530.590 +	else{
 530.591 +	  z.msg="invalid literal/length code";
 530.592 +
 530.593 +	  c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 530.594 +
 530.595 +	  s.bitb=b;s.bitk=k;
 530.596 +	  z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.597 +	  s.write=q;
 530.598 +
 530.599 +	  return Z_DATA_ERROR;
 530.600 +	}
 530.601 +      } 
 530.602 +      while(true);
 530.603 +    } 
 530.604 +    while(m>=258 && n>= 10);
 530.605 +
 530.606 +    // not enough input or output--restore pointers and return
 530.607 +    c=z.avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;
 530.608 +
 530.609 +    s.bitb=b;s.bitk=k;
 530.610 +    z.avail_in=n;z.total_in+=p-z.next_in_index;z.next_in_index=p;
 530.611 +    s.write=q;
 530.612 +
 530.613 +    return Z_OK;
 530.614 +  }
 530.615 +}
   531.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   531.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java	Wed Feb 27 11:24:58 2013 +0100
   531.3 @@ -0,0 +1,520 @@
   531.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
   531.5 +/*
   531.6 +Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
   531.7 +
   531.8 +Redistribution and use in source and binary forms, with or without
   531.9 +modification, are permitted provided that the following conditions are met:
  531.10 +
  531.11 +  1. Redistributions of source code must retain the above copyright notice,
  531.12 +     this list of conditions and the following disclaimer.
  531.13 +
  531.14 +  2. Redistributions in binary form must reproduce the above copyright 
  531.15 +     notice, this list of conditions and the following disclaimer in 
  531.16 +     the documentation and/or other materials provided with the distribution.
  531.17 +
  531.18 +  3. The names of the authors may not be used to endorse or promote products
  531.19 +     derived from this software without specific prior written permission.
  531.20 +
  531.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  531.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  531.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  531.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  531.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  531.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  531.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  531.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  531.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  531.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  531.31 + */
  531.32 +/*
  531.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  531.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  531.35 + * and contributors of zlib.
  531.36 + */
  531.37 +
  531.38 +package org.apidesign.bck2brwsr.emul.zip;
  531.39 +
  531.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  531.41 +
  531.42 +final class InfTree{
  531.43 +
  531.44 +  static final private int MANY=1440;
  531.45 +
  531.46 +  static final private int Z_OK=0;
  531.47 +  static final private int Z_STREAM_END=1;
  531.48 +  static final private int Z_NEED_DICT=2;
  531.49 +  static final private int Z_ERRNO=-1;
  531.50 +  static final private int Z_STREAM_ERROR=-2;
  531.51 +  static final private int Z_DATA_ERROR=-3;
  531.52 +  static final private int Z_MEM_ERROR=-4;
  531.53 +  static final private int Z_BUF_ERROR=-5;
  531.54 +  static final private int Z_VERSION_ERROR=-6;
  531.55 +
  531.56 +  static final int fixed_bl = 9;
  531.57 +  static final int fixed_bd = 5;
  531.58 +
  531.59 +  static final int[] fixed_tl = {
  531.60 +    96,7,256, 0,8,80, 0,8,16, 84,8,115,
  531.61 +    82,7,31, 0,8,112, 0,8,48, 0,9,192,
  531.62 +    80,7,10, 0,8,96, 0,8,32, 0,9,160,
  531.63 +    0,8,0, 0,8,128, 0,8,64, 0,9,224,
  531.64 +    80,7,6, 0,8,88, 0,8,24, 0,9,144,
  531.65 +    83,7,59, 0,8,120, 0,8,56, 0,9,208,
  531.66 +    81,7,17, 0,8,104, 0,8,40, 0,9,176,
  531.67 +    0,8,8, 0,8,136, 0,8,72, 0,9,240,
  531.68 +    80,7,4, 0,8,84, 0,8,20, 85,8,227,
  531.69 +    83,7,43, 0,8,116, 0,8,52, 0,9,200,
  531.70 +    81,7,13, 0,8,100, 0,8,36, 0,9,168,
  531.71 +    0,8,4, 0,8,132, 0,8,68, 0,9,232,
  531.72 +    80,7,8, 0,8,92, 0,8,28, 0,9,152,
  531.73 +    84,7,83, 0,8,124, 0,8,60, 0,9,216,
  531.74 +    82,7,23, 0,8,108, 0,8,44, 0,9,184,
  531.75 +    0,8,12, 0,8,140, 0,8,76, 0,9,248,
  531.76 +    80,7,3, 0,8,82, 0,8,18, 85,8,163,
  531.77 +    83,7,35, 0,8,114, 0,8,50, 0,9,196,
  531.78 +    81,7,11, 0,8,98, 0,8,34, 0,9,164,
  531.79 +    0,8,2, 0,8,130, 0,8,66, 0,9,228,
  531.80 +    80,7,7, 0,8,90, 0,8,26, 0,9,148,
  531.81 +    84,7,67, 0,8,122, 0,8,58, 0,9,212,
  531.82 +    82,7,19, 0,8,106, 0,8,42, 0,9,180,
  531.83 +    0,8,10, 0,8,138, 0,8,74, 0,9,244,
  531.84 +    80,7,5, 0,8,86, 0,8,22, 192,8,0,
  531.85 +    83,7,51, 0,8,118, 0,8,54, 0,9,204,
  531.86 +    81,7,15, 0,8,102, 0,8,38, 0,9,172,
  531.87 +    0,8,6, 0,8,134, 0,8,70, 0,9,236,
  531.88 +    80,7,9, 0,8,94, 0,8,30, 0,9,156,
  531.89 +    84,7,99, 0,8,126, 0,8,62, 0,9,220,
  531.90 +    82,7,27, 0,8,110, 0,8,46, 0,9,188,
  531.91 +    0,8,14, 0,8,142, 0,8,78, 0,9,252,
  531.92 +    96,7,256, 0,8,81, 0,8,17, 85,8,131,
  531.93 +    82,7,31, 0,8,113, 0,8,49, 0,9,194,
  531.94 +    80,7,10, 0,8,97, 0,8,33, 0,9,162,
  531.95 +    0,8,1, 0,8,129, 0,8,65, 0,9,226,
  531.96 +    80,7,6, 0,8,89, 0,8,25, 0,9,146,
  531.97 +    83,7,59, 0,8,121, 0,8,57, 0,9,210,
  531.98 +    81,7,17, 0,8,105, 0,8,41, 0,9,178,
  531.99 +    0,8,9, 0,8,137, 0,8,73, 0,9,242,
 531.100 +    80,7,4, 0,8,85, 0,8,21, 80,8,258,
 531.101 +    83,7,43, 0,8,117, 0,8,53, 0,9,202,
 531.102 +    81,7,13, 0,8,101, 0,8,37, 0,9,170,
 531.103 +    0,8,5, 0,8,133, 0,8,69, 0,9,234,
 531.104 +    80,7,8, 0,8,93, 0,8,29, 0,9,154,
 531.105 +    84,7,83, 0,8,125, 0,8,61, 0,9,218,
 531.106 +    82,7,23, 0,8,109, 0,8,45, 0,9,186,
 531.107 +    0,8,13, 0,8,141, 0,8,77, 0,9,250,
 531.108 +    80,7,3, 0,8,83, 0,8,19, 85,8,195,
 531.109 +    83,7,35, 0,8,115, 0,8,51, 0,9,198,
 531.110 +    81,7,11, 0,8,99, 0,8,35, 0,9,166,
 531.111 +    0,8,3, 0,8,131, 0,8,67, 0,9,230,
 531.112 +    80,7,7, 0,8,91, 0,8,27, 0,9,150,
 531.113 +    84,7,67, 0,8,123, 0,8,59, 0,9,214,
 531.114 +    82,7,19, 0,8,107, 0,8,43, 0,9,182,
 531.115 +    0,8,11, 0,8,139, 0,8,75, 0,9,246,
 531.116 +    80,7,5, 0,8,87, 0,8,23, 192,8,0,
 531.117 +    83,7,51, 0,8,119, 0,8,55, 0,9,206,
 531.118 +    81,7,15, 0,8,103, 0,8,39, 0,9,174,
 531.119 +    0,8,7, 0,8,135, 0,8,71, 0,9,238,
 531.120 +    80,7,9, 0,8,95, 0,8,31, 0,9,158,
 531.121 +    84,7,99, 0,8,127, 0,8,63, 0,9,222,
 531.122 +    82,7,27, 0,8,111, 0,8,47, 0,9,190,
 531.123 +    0,8,15, 0,8,143, 0,8,79, 0,9,254,
 531.124 +    96,7,256, 0,8,80, 0,8,16, 84,8,115,
 531.125 +    82,7,31, 0,8,112, 0,8,48, 0,9,193,
 531.126 +
 531.127 +    80,7,10, 0,8,96, 0,8,32, 0,9,161,
 531.128 +    0,8,0, 0,8,128, 0,8,64, 0,9,225,
 531.129 +    80,7,6, 0,8,88, 0,8,24, 0,9,145,
 531.130 +    83,7,59, 0,8,120, 0,8,56, 0,9,209,
 531.131 +    81,7,17, 0,8,104, 0,8,40, 0,9,177,
 531.132 +    0,8,8, 0,8,136, 0,8,72, 0,9,241,
 531.133 +    80,7,4, 0,8,84, 0,8,20, 85,8,227,
 531.134 +    83,7,43, 0,8,116, 0,8,52, 0,9,201,
 531.135 +    81,7,13, 0,8,100, 0,8,36, 0,9,169,
 531.136 +    0,8,4, 0,8,132, 0,8,68, 0,9,233,
 531.137 +    80,7,8, 0,8,92, 0,8,28, 0,9,153,
 531.138 +    84,7,83, 0,8,124, 0,8,60, 0,9,217,
 531.139 +    82,7,23, 0,8,108, 0,8,44, 0,9,185,
 531.140 +    0,8,12, 0,8,140, 0,8,76, 0,9,249,
 531.141 +    80,7,3, 0,8,82, 0,8,18, 85,8,163,
 531.142 +    83,7,35, 0,8,114, 0,8,50, 0,9,197,
 531.143 +    81,7,11, 0,8,98, 0,8,34, 0,9,165,
 531.144 +    0,8,2, 0,8,130, 0,8,66, 0,9,229,
 531.145 +    80,7,7, 0,8,90, 0,8,26, 0,9,149,
 531.146 +    84,7,67, 0,8,122, 0,8,58, 0,9,213,
 531.147 +    82,7,19, 0,8,106, 0,8,42, 0,9,181,
 531.148 +    0,8,10, 0,8,138, 0,8,74, 0,9,245,
 531.149 +    80,7,5, 0,8,86, 0,8,22, 192,8,0,
 531.150 +    83,7,51, 0,8,118, 0,8,54, 0,9,205,
 531.151 +    81,7,15, 0,8,102, 0,8,38, 0,9,173,
 531.152 +    0,8,6, 0,8,134, 0,8,70, 0,9,237,
 531.153 +    80,7,9, 0,8,94, 0,8,30, 0,9,157,
 531.154 +    84,7,99, 0,8,126, 0,8,62, 0,9,221,
 531.155 +    82,7,27, 0,8,110, 0,8,46, 0,9,189,
 531.156 +    0,8,14, 0,8,142, 0,8,78, 0,9,253,
 531.157 +    96,7,256, 0,8,81, 0,8,17, 85,8,131,
 531.158 +    82,7,31, 0,8,113, 0,8,49, 0,9,195,
 531.159 +    80,7,10, 0,8,97, 0,8,33, 0,9,163,
 531.160 +    0,8,1, 0,8,129, 0,8,65, 0,9,227,
 531.161 +    80,7,6, 0,8,89, 0,8,25, 0,9,147,
 531.162 +    83,7,59, 0,8,121, 0,8,57, 0,9,211,
 531.163 +    81,7,17, 0,8,105, 0,8,41, 0,9,179,
 531.164 +    0,8,9, 0,8,137, 0,8,73, 0,9,243,
 531.165 +    80,7,4, 0,8,85, 0,8,21, 80,8,258,
 531.166 +    83,7,43, 0,8,117, 0,8,53, 0,9,203,
 531.167 +    81,7,13, 0,8,101, 0,8,37, 0,9,171,
 531.168 +    0,8,5, 0,8,133, 0,8,69, 0,9,235,
 531.169 +    80,7,8, 0,8,93, 0,8,29, 0,9,155,
 531.170 +    84,7,83, 0,8,125, 0,8,61, 0,9,219,
 531.171 +    82,7,23, 0,8,109, 0,8,45, 0,9,187,
 531.172 +    0,8,13, 0,8,141, 0,8,77, 0,9,251,
 531.173 +    80,7,3, 0,8,83, 0,8,19, 85,8,195,
 531.174 +    83,7,35, 0,8,115, 0,8,51, 0,9,199,
 531.175 +    81,7,11, 0,8,99, 0,8,35, 0,9,167,
 531.176 +    0,8,3, 0,8,131, 0,8,67, 0,9,231,
 531.177 +    80,7,7, 0,8,91, 0,8,27, 0,9,151,
 531.178 +    84,7,67, 0,8,123, 0,8,59, 0,9,215,
 531.179 +    82,7,19, 0,8,107, 0,8,43, 0,9,183,
 531.180 +    0,8,11, 0,8,139, 0,8,75, 0,9,247,
 531.181 +    80,7,5, 0,8,87, 0,8,23, 192,8,0,
 531.182 +    83,7,51, 0,8,119, 0,8,55, 0,9,207,
 531.183 +    81,7,15, 0,8,103, 0,8,39, 0,9,175,
 531.184 +    0,8,7, 0,8,135, 0,8,71, 0,9,239,
 531.185 +    80,7,9, 0,8,95, 0,8,31, 0,9,159,
 531.186 +    84,7,99, 0,8,127, 0,8,63, 0,9,223,
 531.187 +    82,7,27, 0,8,111, 0,8,47, 0,9,191,
 531.188 +    0,8,15, 0,8,143, 0,8,79, 0,9,255
 531.189 +  };
 531.190 +  static final int[] fixed_td = {
 531.191 +    80,5,1, 87,5,257, 83,5,17, 91,5,4097,
 531.192 +    81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
 531.193 +    80,5,3, 88,5,513, 84,5,33, 92,5,8193,
 531.194 +    82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
 531.195 +    80,5,2, 87,5,385, 83,5,25, 91,5,6145,
 531.196 +    81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
 531.197 +    80,5,4, 88,5,769, 84,5,49, 92,5,12289,
 531.198 +    82,5,13, 90,5,3073, 86,5,193, 192,5,24577
 531.199 +  };
 531.200 +
 531.201 +  // Tables for deflate from PKZIP's appnote.txt.
 531.202 +  static final int[] cplens = { // Copy lengths for literal codes 257..285
 531.203 +        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
 531.204 +        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
 531.205 +  };
 531.206 +
 531.207 +  // see note #13 above about 258
 531.208 +  static final int[] cplext = { // Extra bits for literal codes 257..285
 531.209 +        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
 531.210 +        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112  // 112==invalid
 531.211 +  };
 531.212 +
 531.213 +  static final int[] cpdist = { // Copy offsets for distance codes 0..29
 531.214 +        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
 531.215 +        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
 531.216 +        8193, 12289, 16385, 24577
 531.217 +  };
 531.218 +
 531.219 +  static final int[] cpdext = { // Extra bits for distance codes
 531.220 +        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
 531.221 +        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
 531.222 +        12, 12, 13, 13};
 531.223 +
 531.224 +  // If BMAX needs to be larger than 16, then h and x[] should be uLong.
 531.225 +  static final int BMAX=15;         // maximum bit length of any code
 531.226 +
 531.227 +  int[] hn = null;  // hufts used in space
 531.228 +  int[] v = null;   // work area for huft_build 
 531.229 +  int[] c = null;   // bit length count table
 531.230 +  int[] r = null;   // table entry for structure assignment
 531.231 +  int[] u = null;   // table stack
 531.232 +  int[] x = null;   // bit offsets, then code stack
 531.233 +
 531.234 +  private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
 531.235 +                         int bindex, 
 531.236 +                         int n,   // number of codes (assumed <= 288)
 531.237 +                         int s,   // number of simple-valued codes (0..s-1)
 531.238 +                         int[] d, // list of base values for non-simple codes
 531.239 +                         int[] e, // list of extra bits for non-simple codes
 531.240 +                         int[] t, // result: starting table
 531.241 +                         int[] m, // maximum lookup bits, returns actual
 531.242 +                         int[] hp,// space for trees
 531.243 +                         int[] hn,// hufts used in space
 531.244 +                         int[] v  // working area: values in order of bit length
 531.245 +                         ){
 531.246 +    // Given a list of code lengths and a maximum table size, make a set of
 531.247 +    // tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
 531.248 +    // if the given code set is incomplete (the tables are still built in this
 531.249 +    // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
 531.250 +    // lengths), or Z_MEM_ERROR if not enough memory.
 531.251 +
 531.252 +    int a;                       // counter for codes of length k
 531.253 +    int f;                       // i repeats in table every f entries
 531.254 +    int g;                       // maximum code length
 531.255 +    int h;                       // table level
 531.256 +    int i;                       // counter, current code
 531.257 +    int j;                       // counter
 531.258 +    int k;                       // number of bits in current code
 531.259 +    int l;                       // bits per table (returned in m)
 531.260 +    int mask;                    // (1 << w) - 1, to avoid cc -O bug on HP
 531.261 +    int p;                       // pointer into c[], b[], or v[]
 531.262 +    int q;                       // points to current table
 531.263 +    int w;                       // bits before this table == (l * h)
 531.264 +    int xp;                      // pointer into x
 531.265 +    int y;                       // number of dummy codes added
 531.266 +    int z;                       // number of entries in current table
 531.267 +
 531.268 +    // Generate counts for each bit length
 531.269 +
 531.270 +    p = 0; i = n;
 531.271 +    do {
 531.272 +      c[b[bindex+p]]++; p++; i--;   // assume all entries <= BMAX
 531.273 +    }while(i!=0);
 531.274 +
 531.275 +    if(c[0] == n){                // null input--all zero length codes
 531.276 +      t[0] = -1;
 531.277 +      m[0] = 0;
 531.278 +      return Z_OK;
 531.279 +    }
 531.280 +
 531.281 +    // Find minimum and maximum length, bound *m by those
 531.282 +    l = m[0];
 531.283 +    for (j = 1; j <= BMAX; j++)
 531.284 +      if(c[j]!=0) break;
 531.285 +    k = j;                        // minimum code length
 531.286 +    if(l < j){
 531.287 +      l = j;
 531.288 +    }
 531.289 +    for (i = BMAX; i!=0; i--){
 531.290 +      if(c[i]!=0) break;
 531.291 +    }
 531.292 +    g = i;                        // maximum code length
 531.293 +    if(l > i){
 531.294 +      l = i;
 531.295 +    }
 531.296 +    m[0] = l;
 531.297 +
 531.298 +    // Adjust last length count to fill out codes, if needed
 531.299 +    for (y = 1 << j; j < i; j++, y <<= 1){
 531.300 +      if ((y -= c[j]) < 0){
 531.301 +        return Z_DATA_ERROR;
 531.302 +      }
 531.303 +    }
 531.304 +    if ((y -= c[i]) < 0){
 531.305 +      return Z_DATA_ERROR;
 531.306 +    }
 531.307 +    c[i] += y;
 531.308 +
 531.309 +    // Generate starting offsets into the value table for each length
 531.310 +    x[1] = j = 0;
 531.311 +    p = 1;  xp = 2;
 531.312 +    while (--i!=0) {                 // note that i == g from above
 531.313 +      x[xp] = (j += c[p]);
 531.314 +      xp++;
 531.315 +      p++;
 531.316 +    }
 531.317 +
 531.318 +    // Make a table of values in order of bit lengths
 531.319 +    i = 0; p = 0;
 531.320 +    do {
 531.321 +      if ((j = b[bindex+p]) != 0){
 531.322 +        v[x[j]++] = i;
 531.323 +      }
 531.324 +      p++;
 531.325 +    }
 531.326 +    while (++i < n);
 531.327 +    n = x[g];                     // set n to length of v
 531.328 +
 531.329 +    // Generate the Huffman codes and for each, make the table entries
 531.330 +    x[0] = i = 0;                 // first Huffman code is zero
 531.331 +    p = 0;                        // grab values in bit order
 531.332 +    h = -1;                       // no tables yet--level -1
 531.333 +    w = -l;                       // bits decoded == (l * h)
 531.334 +    u[0] = 0;                     // just to keep compilers happy
 531.335 +    q = 0;                        // ditto
 531.336 +    z = 0;                        // ditto
 531.337 +
 531.338 +    // go through the bit lengths (k already is bits in shortest code)
 531.339 +    for (; k <= g; k++){
 531.340 +      a = c[k];
 531.341 +      while (a--!=0){
 531.342 +	// here i is the Huffman code of length k bits for value *p
 531.343 +	// make tables up to required level
 531.344 +        while (k > w + l){
 531.345 +          h++;
 531.346 +          w += l;                 // previous table always l bits
 531.347 +	  // compute minimum size table less than or equal to l bits
 531.348 +          z = g - w;
 531.349 +          z = (z > l) ? l : z;        // table size upper limit
 531.350 +          if((f=1<<(j=k-w))>a+1){     // try a k-w bit table
 531.351 +                                      // too few codes for k-w bit table
 531.352 +            f -= a + 1;               // deduct codes from patterns left
 531.353 +            xp = k;
 531.354 +            if(j < z){
 531.355 +              while (++j < z){        // try smaller tables up to z bits
 531.356 +                if((f <<= 1) <= c[++xp])
 531.357 +                  break;              // enough codes to use up j bits
 531.358 +                f -= c[xp];           // else deduct codes from patterns
 531.359 +              }
 531.360 +	    }
 531.361 +          }
 531.362 +          z = 1 << j;                 // table entries for j-bit table
 531.363 +
 531.364 +	  // allocate new table
 531.365 +          if (hn[0] + z > MANY){       // (note: doesn't matter for fixed)
 531.366 +            return Z_DATA_ERROR;       // overflow of MANY
 531.367 +          }
 531.368 +          u[h] = q = /*hp+*/ hn[0];   // DEBUG
 531.369 +          hn[0] += z;
 531.370 + 
 531.371 +	  // connect to last table, if there is one
 531.372 +	  if(h!=0){
 531.373 +            x[h]=i;           // save pattern for backing up
 531.374 +            r[0]=(byte)j;     // bits in this table
 531.375 +            r[1]=(byte)l;     // bits to dump before this table
 531.376 +            j=i>>>(w - l);
 531.377 +            r[2] = (int)(q - u[h-1] - j);               // offset to this table
 531.378 +            System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
 531.379 +          }
 531.380 +          else{
 531.381 +            t[0] = q;               // first table is returned result
 531.382 +	  }
 531.383 +        }
 531.384 +
 531.385 +	// set up table entry in r
 531.386 +        r[1] = (byte)(k - w);
 531.387 +        if (p >= n){
 531.388 +          r[0] = 128 + 64;      // out of values--invalid code
 531.389 +	}
 531.390 +        else if (v[p] < s){
 531.391 +          r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64);  // 256 is end-of-block
 531.392 +          r[2] = v[p++];          // simple code is just the value
 531.393 +        }
 531.394 +        else{
 531.395 +          r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
 531.396 +          r[2]=d[v[p++] - s];
 531.397 +        }
 531.398 +
 531.399 +        // fill code-like entries with r
 531.400 +        f=1<<(k-w);
 531.401 +        for (j=i>>>w;j<z;j+=f){
 531.402 +          System.arraycopy(r, 0, hp, (q+j)*3, 3);
 531.403 +	}
 531.404 +
 531.405 +	// backwards increment the k-bit code i
 531.406 +        for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
 531.407 +          i ^= j;
 531.408 +	}
 531.409 +        i ^= j;
 531.410 +
 531.411 +	// backup over finished tables
 531.412 +        mask = (1 << w) - 1;      // needed on HP, cc -O bug
 531.413 +        while ((i & mask) != x[h]){
 531.414 +          h--;                    // don't need to update q
 531.415 +          w -= l;
 531.416 +          mask = (1 << w) - 1;
 531.417 +        }
 531.418 +      }
 531.419 +    }
 531.420 +    // Return Z_BUF_ERROR if we were given an incomplete table
 531.421 +    return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
 531.422 +  }
 531.423 +
 531.424 +  int inflate_trees_bits(int[] c,  // 19 code lengths
 531.425 +                         int[] bb, // bits tree desired/actual depth
 531.426 +                         int[] tb, // bits tree result
 531.427 +                         int[] hp, // space for trees
 531.428 +                         ZStream z // for messages
 531.429 +                         ){
 531.430 +    int result;
 531.431 +    initWorkArea(19);
 531.432 +    hn[0]=0;
 531.433 +    result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
 531.434 +
 531.435 +    if(result == Z_DATA_ERROR){
 531.436 +      z.msg = "oversubscribed dynamic bit lengths tree";
 531.437 +    }
 531.438 +    else if(result == Z_BUF_ERROR || bb[0] == 0){
 531.439 +      z.msg = "incomplete dynamic bit lengths tree";
 531.440 +      result = Z_DATA_ERROR;
 531.441 +    }
 531.442 +    return result;
 531.443 +  }
 531.444 +
 531.445 +  int inflate_trees_dynamic(int nl,   // number of literal/length codes
 531.446 +                            int nd,   // number of distance codes
 531.447 +                            int[] c,  // that many (total) code lengths
 531.448 +                            int[] bl, // literal desired/actual bit depth
 531.449 +                            int[] bd, // distance desired/actual bit depth 
 531.450 +                            int[] tl, // literal/length tree result
 531.451 +                            int[] td, // distance tree result
 531.452 +                            int[] hp, // space for trees
 531.453 +                            ZStream z // for messages
 531.454 +                            ){
 531.455 +    int result;
 531.456 +
 531.457 +    // build literal/length tree
 531.458 +    initWorkArea(288);
 531.459 +    hn[0]=0;
 531.460 +    result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
 531.461 +    if (result != Z_OK || bl[0] == 0){
 531.462 +      if(result == Z_DATA_ERROR){
 531.463 +        z.msg = "oversubscribed literal/length tree";
 531.464 +      }
 531.465 +      else if (result != Z_MEM_ERROR){
 531.466 +        z.msg = "incomplete literal/length tree";
 531.467 +        result = Z_DATA_ERROR;
 531.468 +      }
 531.469 +      return result;
 531.470 +    }
 531.471 +
 531.472 +    // build distance tree
 531.473 +    initWorkArea(288);
 531.474 +    result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
 531.475 +
 531.476 +    if (result != Z_OK || (bd[0] == 0 && nl > 257)){
 531.477 +      if (result == Z_DATA_ERROR){
 531.478 +        z.msg = "oversubscribed distance tree";
 531.479 +      }
 531.480 +      else if (result == Z_BUF_ERROR) {
 531.481 +        z.msg = "incomplete distance tree";
 531.482 +        result = Z_DATA_ERROR;
 531.483 +      }
 531.484 +      else if (result != Z_MEM_ERROR){
 531.485 +        z.msg = "empty distance tree with lengths";
 531.486 +        result = Z_DATA_ERROR;
 531.487 +      }
 531.488 +      return result;
 531.489 +    }
 531.490 +
 531.491 +    return Z_OK;
 531.492 +  }
 531.493 +
 531.494 +  static int inflate_trees_fixed(int[] bl,  //literal desired/actual bit depth
 531.495 +                                 int[] bd,  //distance desired/actual bit depth
 531.496 +                                 int[][] tl,//literal/length tree result
 531.497 +                                 int[][] td,//distance tree result 
 531.498 +                                 ZStream z  //for memory allocation
 531.499 +				 ){
 531.500 +    bl[0]=fixed_bl;
 531.501 +    bd[0]=fixed_bd;
 531.502 +    tl[0]=fixed_tl;
 531.503 +    td[0]=fixed_td;
 531.504 +    return Z_OK;
 531.505 +  }
 531.506 +
 531.507 +  private void initWorkArea(int vsize){
 531.508 +    if(hn==null){
 531.509 +      hn=new int[1];
 531.510 +      v=new int[vsize];
 531.511 +      c=new int[BMAX+1];
 531.512 +      r=new int[3];
 531.513 +      u=new int[BMAX];
 531.514 +      x=new int[BMAX+1];
 531.515 +    }
 531.516 +    if(v.length<vsize){ v=new int[vsize]; }
 531.517 +    for(int i=0; i<vsize; i++){v[i]=0;}
 531.518 +    for(int i=0; i<BMAX+1; i++){c[i]=0;}
 531.519 +    for(int i=0; i<3; i++){r[i]=0;}
 531.520 +    System.arraycopy(c, 0, u, 0, BMAX);
 531.521 +    System.arraycopy(c, 0, x, 0, BMAX+1);
 531.522 +  }
 531.523 +}
   532.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   532.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflate.java	Wed Feb 27 11:24:58 2013 +0100
   532.3 @@ -0,0 +1,727 @@
   532.4 +/* -*-mode:java; c-basic-offset:2; -*- */
   532.5 +/*
   532.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
   532.7 +
   532.8 +Redistribution and use in source and binary forms, with or without
   532.9 +modification, are permitted provided that the following conditions are met:
  532.10 +
  532.11 +  1. Redistributions of source code must retain the above copyright notice,
  532.12 +     this list of conditions and the following disclaimer.
  532.13 +
  532.14 +  2. Redistributions in binary form must reproduce the above copyright 
  532.15 +     notice, this list of conditions and the following disclaimer in 
  532.16 +     the documentation and/or other materials provided with the distribution.
  532.17 +
  532.18 +  3. The names of the authors may not be used to endorse or promote products
  532.19 +     derived from this software without specific prior written permission.
  532.20 +
  532.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  532.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  532.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  532.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  532.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  532.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  532.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  532.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  532.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  532.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  532.31 + */
  532.32 +/*
  532.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  532.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  532.35 + * and contributors of zlib.
  532.36 + */
  532.37 +
  532.38 +package org.apidesign.bck2brwsr.emul.zip;
  532.39 +
  532.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  532.41 +
  532.42 +final class Inflate{
  532.43 +  
  532.44 +  static final private int MAX_WBITS=15; // 32K LZ77 window
  532.45 +
  532.46 +  // preset dictionary flag in zlib header
  532.47 +  static final private int PRESET_DICT=0x20;
  532.48 +
  532.49 +  static final int Z_NO_FLUSH=0;
  532.50 +  static final int Z_PARTIAL_FLUSH=1;
  532.51 +  static final int Z_SYNC_FLUSH=2;
  532.52 +  static final int Z_FULL_FLUSH=3;
  532.53 +  static final int Z_FINISH=4;
  532.54 +
  532.55 +  static final private int Z_DEFLATED=8;
  532.56 +
  532.57 +  static final private int Z_OK=0;
  532.58 +  static final private int Z_STREAM_END=1;
  532.59 +  static final private int Z_NEED_DICT=2;
  532.60 +  static final private int Z_ERRNO=-1;
  532.61 +  static final private int Z_STREAM_ERROR=-2;
  532.62 +  static final private int Z_DATA_ERROR=-3;
  532.63 +  static final private int Z_MEM_ERROR=-4;
  532.64 +  static final private int Z_BUF_ERROR=-5;
  532.65 +  static final private int Z_VERSION_ERROR=-6;
  532.66 +
  532.67 +  static final private int METHOD=0;   // waiting for method byte
  532.68 +  static final private int FLAG=1;     // waiting for flag byte
  532.69 +  static final private int DICT4=2;    // four dictionary check bytes to go
  532.70 +  static final private int DICT3=3;    // three dictionary check bytes to go
  532.71 +  static final private int DICT2=4;    // two dictionary check bytes to go
  532.72 +  static final private int DICT1=5;    // one dictionary check byte to go
  532.73 +  static final int DICT0=6;    // waiting for inflateSetDictionary
  532.74 +  static final private int BLOCKS=7;   // decompressing blocks
  532.75 +  static final private int CHECK4=8;   // four check bytes to go
  532.76 +  static final private int CHECK3=9;   // three check bytes to go
  532.77 +  static final private int CHECK2=10;  // two check bytes to go
  532.78 +  static final private int CHECK1=11;  // one check byte to go
  532.79 +  static final private int DONE=12;    // finished check, done
  532.80 +  static final private int BAD=13;     // got an error--stay here
  532.81 +
  532.82 +  static final private int HEAD=14;
  532.83 +  static final private int LENGTH=15;
  532.84 +  static final private int TIME=16;
  532.85 +  static final private int OS=17;
  532.86 +  static final private int EXLEN=18;
  532.87 +  static final private int EXTRA=19;
  532.88 +  static final private int NAME=20;
  532.89 +  static final private int COMMENT=21;
  532.90 +  static final private int HCRC=22;
  532.91 +  static final private int FLAGS=23;
  532.92 +
  532.93 +  int mode;                            // current inflate mode
  532.94 +
  532.95 +  // mode dependent information
  532.96 +  int method;        // if FLAGS, method byte
  532.97 +
  532.98 +  // if CHECK, check values to compare
  532.99 +  long was = -1;           // computed check value
 532.100 +  long need;               // stream check value
 532.101 +
 532.102 +  // if BAD, inflateSync's marker bytes count
 532.103 +  int marker;
 532.104 +
 532.105 +  // mode independent information
 532.106 +  int  wrap;          // flag for no wrapper
 532.107 +  int wbits;            // log2(window size)  (8..15, defaults to 15)
 532.108 +
 532.109 +  InfBlocks blocks;     // current inflate_blocks state
 532.110 +
 532.111 +  private final ZStream z;
 532.112 +
 532.113 +  private int flags; 
 532.114 +
 532.115 +  private int need_bytes = -1;
 532.116 +  private byte[] crcbuf=new byte[4];
 532.117 +
 532.118 +  GZIPHeader gheader = null;
 532.119 +
 532.120 +  int inflateReset(){
 532.121 +    if(z == null) return Z_STREAM_ERROR;
 532.122 +    
 532.123 +    z.total_in = z.total_out = 0;
 532.124 +    z.msg = null;
 532.125 +    this.mode = HEAD;
 532.126 +    this.need_bytes = -1;
 532.127 +    this.blocks.reset();
 532.128 +    return Z_OK;
 532.129 +  }
 532.130 +
 532.131 +  int inflateEnd(){
 532.132 +    if(blocks != null){
 532.133 +      blocks.free();
 532.134 +    }
 532.135 +    return Z_OK;
 532.136 +  }
 532.137 +
 532.138 +  Inflate(ZStream z){
 532.139 +    this.z=z;
 532.140 +  }
 532.141 +
 532.142 +  int inflateInit(int w){
 532.143 +    z.msg = null;
 532.144 +    blocks = null;
 532.145 +
 532.146 +    // handle undocumented wrap option (no zlib header or check)
 532.147 +    wrap = 0;
 532.148 +    if(w < 0){
 532.149 +      w = - w;
 532.150 +    }
 532.151 +    else {
 532.152 +      wrap = (w >> 4) + 1;
 532.153 +      if(w < 48)
 532.154 +        w &= 15;
 532.155 +    }
 532.156 +
 532.157 +    if(w<8 ||w>15){
 532.158 +      inflateEnd();
 532.159 +      return Z_STREAM_ERROR;
 532.160 +    }
 532.161 +    if(blocks != null && wbits != w){
 532.162 +      blocks.free();
 532.163 +      blocks=null;
 532.164 +    }
 532.165 +
 532.166 +    // set window size
 532.167 +    wbits=w;
 532.168 +
 532.169 +    this.blocks=new InfBlocks(z, 1<<w);
 532.170 +
 532.171 +    // reset state
 532.172 +    inflateReset();
 532.173 +
 532.174 +    return Z_OK;
 532.175 +  }
 532.176 +
 532.177 +  int inflate(int f){
 532.178 +    int hold = 0;
 532.179 +
 532.180 +    int r;
 532.181 +    int b;
 532.182 +
 532.183 +    if(z == null || z.next_in == null){
 532.184 +      if(f == Z_FINISH && this.mode==HEAD)
 532.185 +        return Z_OK; 
 532.186 +      return Z_STREAM_ERROR;
 532.187 +    }
 532.188 +
 532.189 +    f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
 532.190 +    r = Z_BUF_ERROR;
 532.191 +    while (true){
 532.192 +
 532.193 +      switch (this.mode){
 532.194 +      case HEAD:
 532.195 +        if(wrap==0){
 532.196 +	  this.mode = BLOCKS;
 532.197 +          break;
 532.198 +        } 
 532.199 +
 532.200 +        try { r=readBytes(2, r, f); }
 532.201 +        catch(Return e){ return e.r; }
 532.202 +
 532.203 +        if((wrap&2)!=0 && this.need == 0x8b1fL) {   // gzip header
 532.204 +	  z.adler=new CRC32();
 532.205 +          checksum(2, this.need);
 532.206 +
 532.207 +          if(gheader==null) 
 532.208 +            gheader=new GZIPHeader();
 532.209 +
 532.210 +          this.mode = FLAGS;
 532.211 +          break;
 532.212 +        }
 532.213 +
 532.214 +        flags = 0;
 532.215 +
 532.216 +        this.method = ((int)this.need)&0xff;
 532.217 +        b=((int)(this.need>>8))&0xff;
 532.218 +
 532.219 +        if((wrap&1)==0 ||  // check if zlib header allowed
 532.220 +           (((this.method << 8)+b) % 31)!=0){
 532.221 +          this.mode = BAD;
 532.222 +          z.msg = "incorrect header check";
 532.223 +          // since zlib 1.2, it is allowted to inflateSync for this case.
 532.224 +          /*
 532.225 +          this.marker = 5;       // can't try inflateSync
 532.226 +          */
 532.227 +          break;
 532.228 +        }
 532.229 +
 532.230 +        if((this.method&0xf)!=Z_DEFLATED){
 532.231 +          this.mode = BAD;
 532.232 +          z.msg="unknown compression method";
 532.233 +          // since zlib 1.2, it is allowted to inflateSync for this case.
 532.234 +	  /*
 532.235 +          this.marker = 5;       // can't try inflateSync
 532.236 +	  */
 532.237 +          break;
 532.238 +        }
 532.239 +
 532.240 +        if((this.method>>4)+8>this.wbits){
 532.241 +          this.mode = BAD;
 532.242 +          z.msg="invalid window size";
 532.243 +          // since zlib 1.2, it is allowted to inflateSync for this case.
 532.244 +	  /*
 532.245 +          this.marker = 5;       // can't try inflateSync
 532.246 +	  */
 532.247 +          break;
 532.248 +        }
 532.249 +
 532.250 +        z.adler=new Adler32();
 532.251 +
 532.252 +        if((b&PRESET_DICT)==0){
 532.253 +          this.mode = BLOCKS;
 532.254 +          break;
 532.255 +        }
 532.256 +        this.mode = DICT4;
 532.257 +      case DICT4:
 532.258 +
 532.259 +        if(z.avail_in==0)return r;r=f;
 532.260 +
 532.261 +        z.avail_in--; z.total_in++;
 532.262 +        this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
 532.263 +        this.mode=DICT3;
 532.264 +      case DICT3:
 532.265 +
 532.266 +        if(z.avail_in==0)return r;r=f;
 532.267 +
 532.268 +        z.avail_in--; z.total_in++;
 532.269 +        this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
 532.270 +        this.mode=DICT2;
 532.271 +      case DICT2:
 532.272 +
 532.273 +        if(z.avail_in==0)return r;r=f;
 532.274 +
 532.275 +        z.avail_in--; z.total_in++;
 532.276 +        this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
 532.277 +        this.mode=DICT1;
 532.278 +      case DICT1:
 532.279 +
 532.280 +        if(z.avail_in==0)return r;r=f;
 532.281 +
 532.282 +        z.avail_in--; z.total_in++;
 532.283 +        this.need += (z.next_in[z.next_in_index++]&0xffL);
 532.284 +        z.adler.reset(this.need);
 532.285 +        this.mode = DICT0;
 532.286 +        return Z_NEED_DICT;
 532.287 +      case DICT0:
 532.288 +        this.mode = BAD;
 532.289 +        z.msg = "need dictionary";
 532.290 +        this.marker = 0;       // can try inflateSync
 532.291 +        return Z_STREAM_ERROR;
 532.292 +      case BLOCKS:
 532.293 +        r = this.blocks.proc(r);
 532.294 +        if(r == Z_DATA_ERROR){
 532.295 +          this.mode = BAD;
 532.296 +          this.marker = 0;     // can try inflateSync
 532.297 +          break;
 532.298 +        }
 532.299 +        if(r == Z_OK){
 532.300 +          r = f;
 532.301 +        }
 532.302 +        if(r != Z_STREAM_END){
 532.303 +          return r;
 532.304 +        }
 532.305 +        r = f;
 532.306 +        this.was=z.adler.getValue();
 532.307 +        this.blocks.reset();
 532.308 +        if(this.wrap==0){
 532.309 +          this.mode=DONE;
 532.310 +          break;
 532.311 +        }
 532.312 +        this.mode=CHECK4;
 532.313 +      case CHECK4:
 532.314 +
 532.315 +        if(z.avail_in==0)return r;r=f;
 532.316 +
 532.317 +        z.avail_in--; z.total_in++;
 532.318 +        this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
 532.319 +        this.mode=CHECK3;
 532.320 +      case CHECK3:
 532.321 +
 532.322 +        if(z.avail_in==0)return r;r=f;
 532.323 +
 532.324 +        z.avail_in--; z.total_in++;
 532.325 +        this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
 532.326 +        this.mode = CHECK2;
 532.327 +      case CHECK2:
 532.328 +
 532.329 +        if(z.avail_in==0)return r;r=f;
 532.330 +
 532.331 +        z.avail_in--; z.total_in++;
 532.332 +        this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
 532.333 +        this.mode = CHECK1;
 532.334 +      case CHECK1:
 532.335 +
 532.336 +        if(z.avail_in==0)return r;r=f;
 532.337 +
 532.338 +        z.avail_in--; z.total_in++;
 532.339 +        this.need+=(z.next_in[z.next_in_index++]&0xffL);
 532.340 +
 532.341 +        if(flags!=0){  // gzip
 532.342 +          this.need = ((this.need&0xff000000)>>24 | 
 532.343 +                          (this.need&0x00ff0000)>>8 | 
 532.344 +                          (this.need&0x0000ff00)<<8 | 
 532.345 +                          (this.need&0x0000ffff)<<24)&0xffffffffL;
 532.346 +        }
 532.347 +
 532.348 +        if(((int)(this.was)) != ((int)(this.need))){
 532.349 +          z.msg = "incorrect data check";
 532.350 +          // chack is delayed
 532.351 +          /*
 532.352 +          this.mode = BAD;
 532.353 +          this.marker = 5;       // can't try inflateSync
 532.354 +          break;
 532.355 +	  */
 532.356 +        }
 532.357 +        else if(flags!=0 && gheader!=null){
 532.358 +          gheader.crc = this.need; 
 532.359 +        }
 532.360 +
 532.361 +        this.mode = LENGTH;
 532.362 +      case LENGTH:
 532.363 +        if (wrap!=0 && flags!=0) {
 532.364 +
 532.365 +          try { r=readBytes(4, r, f); }
 532.366 +          catch(Return e){ return e.r; }
 532.367 +
 532.368 +          if(z.msg!=null && z.msg.equals("incorrect data check")){
 532.369 +            this.mode = BAD;
 532.370 +            this.marker = 5;       // can't try inflateSync
 532.371 +            break;
 532.372 +          }
 532.373 +
 532.374 +          if (this.need != (z.total_out & 0xffffffffL)) {
 532.375 +            z.msg = "incorrect length check";
 532.376 +            this.mode = BAD;
 532.377 +            break;
 532.378 +          }
 532.379 +          z.msg = null;
 532.380 +        }
 532.381 +        else {
 532.382 +          if(z.msg!=null && z.msg.equals("incorrect data check")){
 532.383 +            this.mode = BAD;
 532.384 +            this.marker = 5;       // can't try inflateSync
 532.385 +            break;
 532.386 +          }
 532.387 +        }
 532.388 +
 532.389 +        this.mode = DONE;
 532.390 +      case DONE:
 532.391 +        return Z_STREAM_END;
 532.392 +      case BAD:
 532.393 +        return Z_DATA_ERROR;
 532.394 +
 532.395 +      case FLAGS:
 532.396 +
 532.397 +        try { r=readBytes(2, r, f); }
 532.398 +        catch(Return e){ return e.r; }
 532.399 +
 532.400 +        flags = ((int)this.need)&0xffff;
 532.401 +
 532.402 +        if ((flags & 0xff) != Z_DEFLATED) {
 532.403 +          z.msg = "unknown compression method";
 532.404 +          this.mode = BAD; 
 532.405 +          break;
 532.406 +        }
 532.407 +        if ((flags & 0xe000)!=0) {
 532.408 +          z.msg = "unknown header flags set";
 532.409 +          this.mode = BAD; 
 532.410 +          break;
 532.411 +        }
 532.412 +
 532.413 +        if ((flags & 0x0200)!=0){
 532.414 +          checksum(2, this.need);
 532.415 +        } 
 532.416 +
 532.417 +        this.mode = TIME;
 532.418 +
 532.419 +      case TIME:
 532.420 +        try { r=readBytes(4, r, f); }
 532.421 +        catch(Return e){ return e.r; }
 532.422 +        if(gheader!=null)
 532.423 +          gheader.time = this.need;
 532.424 +        if ((flags & 0x0200)!=0){
 532.425 +          checksum(4, this.need);
 532.426 +        }
 532.427 +        this.mode = OS;
 532.428 +      case OS:
 532.429 +        try { r=readBytes(2, r, f); }
 532.430 +        catch(Return e){ return e.r; }
 532.431 +        if(gheader!=null){
 532.432 +          gheader.xflags = ((int)this.need)&0xff;
 532.433 +          gheader.os = (((int)this.need)>>8)&0xff;
 532.434 +        }
 532.435 +        if ((flags & 0x0200)!=0){
 532.436 +          checksum(2, this.need);
 532.437 +        }
 532.438 +        this.mode = EXLEN;
 532.439 +      case EXLEN:
 532.440 +        if ((flags & 0x0400)!=0) {
 532.441 +          try { r=readBytes(2, r, f); }
 532.442 +          catch(Return e){ return e.r; }
 532.443 +          if(gheader!=null){
 532.444 +            gheader.extra = new byte[((int)this.need)&0xffff];
 532.445 +          }
 532.446 +          if ((flags & 0x0200)!=0){
 532.447 +            checksum(2, this.need);
 532.448 +          }
 532.449 +        }
 532.450 +        else if(gheader!=null){
 532.451 +          gheader.extra=null;
 532.452 +        }
 532.453 +        this.mode = EXTRA;
 532.454 +
 532.455 +      case EXTRA:
 532.456 +        if ((flags & 0x0400)!=0) {
 532.457 +          try { 
 532.458 +            r=readBytes(r, f);
 532.459 +            if(gheader!=null){
 532.460 +              byte[] foo = tmp_array;
 532.461 +              tmp_array=null;
 532.462 +              if(foo.length == gheader.extra.length){
 532.463 +                System.arraycopy(foo, 0, gheader.extra, 0, foo.length);
 532.464 +	      }
 532.465 +              else{
 532.466 +                z.msg = "bad extra field length";
 532.467 +                this.mode = BAD; 
 532.468 +                break;
 532.469 +	      }
 532.470 +            }
 532.471 +          }
 532.472 +          catch(Return e){ return e.r; }
 532.473 +        }
 532.474 +        else if(gheader!=null){
 532.475 +          gheader.extra=null;
 532.476 +	}
 532.477 +	this.mode = NAME;
 532.478 +      case NAME:
 532.479 +	if ((flags & 0x0800)!=0) {
 532.480 +          try { 
 532.481 +            r=readString(r, f);
 532.482 +            if(gheader!=null){
 532.483 +              gheader.name=tmp_array;
 532.484 +            }
 532.485 +            tmp_array=null;
 532.486 +          }
 532.487 +          catch(Return e){ return e.r; }
 532.488 +        }
 532.489 +        else if(gheader!=null){
 532.490 +          gheader.name=null;
 532.491 +	}
 532.492 +        this.mode = COMMENT;
 532.493 +      case COMMENT:
 532.494 +        if ((flags & 0x1000)!=0) {
 532.495 +          try { 
 532.496 +            r=readString(r, f);
 532.497 +            if(gheader!=null){
 532.498 +              gheader.comment=tmp_array;
 532.499 +            }
 532.500 +            tmp_array=null;
 532.501 +          }
 532.502 +          catch(Return e){ return e.r; }
 532.503 +        }
 532.504 +        else if(gheader!=null){
 532.505 +          gheader.comment=null;
 532.506 +	}
 532.507 +        this.mode = HCRC;
 532.508 +      case HCRC:
 532.509 +	if ((flags & 0x0200)!=0) {
 532.510 +          try { r=readBytes(2, r, f); }
 532.511 +          catch(Return e){ return e.r; }
 532.512 +          if(gheader!=null){
 532.513 +            gheader.hcrc=(int)(this.need&0xffff);
 532.514 +          }
 532.515 +          if(this.need != (z.adler.getValue()&0xffffL)){
 532.516 +            this.mode = BAD;
 532.517 +            z.msg = "header crc mismatch";
 532.518 +            this.marker = 5;       // can't try inflateSync
 532.519 +            break;
 532.520 +          }
 532.521 +        }
 532.522 +        z.adler = new CRC32();
 532.523 +
 532.524 +        this.mode = BLOCKS;
 532.525 +        break;
 532.526 +      default:
 532.527 +        return Z_STREAM_ERROR;
 532.528 +      }
 532.529 +    }
 532.530 +  }
 532.531 +
 532.532 +  int inflateSetDictionary(byte[] dictionary, int dictLength){
 532.533 +    if(z==null || (this.mode != DICT0 && this.wrap != 0)){
 532.534 +      return Z_STREAM_ERROR;
 532.535 +    }
 532.536 +
 532.537 +    int index=0;
 532.538 +    int length = dictLength;
 532.539 +
 532.540 +    if(this.mode==DICT0){
 532.541 +      long adler_need=z.adler.getValue();
 532.542 +      z.adler.reset();
 532.543 +      z.adler.update(dictionary, 0, dictLength);
 532.544 +      if(z.adler.getValue()!=adler_need){
 532.545 +        return Z_DATA_ERROR;
 532.546 +      }
 532.547 +    }
 532.548 +
 532.549 +    z.adler.reset();
 532.550 +
 532.551 +    if(length >= (1<<this.wbits)){
 532.552 +      length = (1<<this.wbits)-1;
 532.553 +      index=dictLength - length;
 532.554 +    }
 532.555 +    this.blocks.set_dictionary(dictionary, index, length);
 532.556 +    this.mode = BLOCKS;
 532.557 +    return Z_OK;
 532.558 +  }
 532.559 +
 532.560 +  static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff};
 532.561 +
 532.562 +  int inflateSync(){
 532.563 +    int n;       // number of bytes to look at
 532.564 +    int p;       // pointer to bytes
 532.565 +    int m;       // number of marker bytes found in a row
 532.566 +    long r, w;   // temporaries to save total_in and total_out
 532.567 +
 532.568 +    // set up
 532.569 +    if(z == null)
 532.570 +      return Z_STREAM_ERROR;
 532.571 +    if(this.mode != BAD){
 532.572 +      this.mode = BAD;
 532.573 +      this.marker = 0;
 532.574 +    }
 532.575 +    if((n=z.avail_in)==0)
 532.576 +      return Z_BUF_ERROR;
 532.577 +
 532.578 +    p=z.next_in_index;
 532.579 +    m=this.marker;
 532.580 +    // search
 532.581 +    while (n!=0 && m < 4){
 532.582 +      if(z.next_in[p] == mark[m]){
 532.583 +        m++;
 532.584 +      }
 532.585 +      else if(z.next_in[p]!=0){
 532.586 +        m = 0;
 532.587 +      }
 532.588 +      else{
 532.589 +        m = 4 - m;
 532.590 +      }
 532.591 +      p++; n--;
 532.592 +    }
 532.593 +
 532.594 +    // restore
 532.595 +    z.total_in += p-z.next_in_index;
 532.596 +    z.next_in_index = p;
 532.597 +    z.avail_in = n;
 532.598 +    this.marker = m;
 532.599 +
 532.600 +    // return no joy or set up to restart on a new block
 532.601 +    if(m != 4){
 532.602 +      return Z_DATA_ERROR;
 532.603 +    }
 532.604 +    r=z.total_in;  w=z.total_out;
 532.605 +    inflateReset();
 532.606 +    z.total_in=r;  z.total_out = w;
 532.607 +    this.mode = BLOCKS;
 532.608 +
 532.609 +    return Z_OK;
 532.610 +  }
 532.611 +
 532.612 +  // Returns true if inflate is currently at the end of a block generated
 532.613 +  // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
 532.614 +  // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
 532.615 +  // but removes the length bytes of the resulting empty stored block. When
 532.616 +  // decompressing, PPP checks that at the end of input packet, inflate is
 532.617 +  // waiting for these length bytes.
 532.618 +  int inflateSyncPoint(){
 532.619 +    if(z == null || this.blocks == null)
 532.620 +      return Z_STREAM_ERROR;
 532.621 +    return this.blocks.sync_point();
 532.622 +  }
 532.623 +
 532.624 +  private int readBytes(int n, int r, int f) throws Return{
 532.625 +    if(need_bytes == -1){
 532.626 +      need_bytes=n;
 532.627 +      this.need=0;
 532.628 +    }
 532.629 +    while(need_bytes>0){
 532.630 +      if(z.avail_in==0){ throw new Return(r); }; r=f;
 532.631 +      z.avail_in--; z.total_in++;
 532.632 +      this.need = this.need | 
 532.633 +	((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8));
 532.634 +      need_bytes--;
 532.635 +    }
 532.636 +    if(n==2){
 532.637 +      this.need&=0xffffL;
 532.638 +    }
 532.639 +    else if(n==4) {
 532.640 +      this.need&=0xffffffffL;
 532.641 +    }
 532.642 +    need_bytes=-1;
 532.643 +    return r;
 532.644 +  }
 532.645 +  class Return extends Exception{
 532.646 +    int r;
 532.647 +    Return(int r){this.r=r; }
 532.648 +  }
 532.649 +
 532.650 +  private byte[] tmp_array;
 532.651 +  private int readString(int r, int f) throws Return{
 532.652 +    int b=0; 
 532.653 +    byte[] arr = new byte[4092];
 532.654 +    int at = 0;
 532.655 +    do {
 532.656 +      if(z.avail_in==0){ throw new Return(r); }; r=f;
 532.657 +      z.avail_in--; z.total_in++;
 532.658 +      b = z.next_in[z.next_in_index];
 532.659 +      if(b!=0) arr = append(arr, z.next_in[z.next_in_index], at++);
 532.660 +      z.adler.update(z.next_in, z.next_in_index, 1);
 532.661 +      z.next_in_index++;
 532.662 +    }while(b!=0);
 532.663 +    
 532.664 +    tmp_array = copy(arr, at);
 532.665 +    
 532.666 +    return r;
 532.667 +  }
 532.668 +
 532.669 +  private int readBytes(int r, int f) throws Return{
 532.670 +    int b=0; 
 532.671 +    byte[] arr = new byte[4092];
 532.672 +    int at = 0;
 532.673 +    while(this.need>0){
 532.674 +      if(z.avail_in==0){ throw new Return(r); }; r=f;
 532.675 +      z.avail_in--; z.total_in++;
 532.676 +      b = z.next_in[z.next_in_index];
 532.677 +      arr = append(arr, z.next_in[z.next_in_index], at++);
 532.678 +      z.adler.update(z.next_in, z.next_in_index, 1);
 532.679 +      z.next_in_index++;
 532.680 +      this.need--;
 532.681 +    }
 532.682 +    
 532.683 +    tmp_array = copy(arr, at);
 532.684 +    
 532.685 +    return r;
 532.686 +  }
 532.687 +  
 532.688 +  private static byte[] copy(byte[] arr, int len) {
 532.689 +      byte[] ret = new byte[len];
 532.690 +      org.apidesign.bck2brwsr.emul.lang.System.arraycopy(arr, 0, ret, 0, len);
 532.691 +      return ret;
 532.692 +  }
 532.693 +  private static byte[] append(byte[] arr, byte b, int index) {
 532.694 +      arr[index] = b;
 532.695 +      return arr;
 532.696 +  }
 532.697 +
 532.698 +  private void checksum(int n, long v){
 532.699 +    for(int i=0; i<n; i++){
 532.700 +      crcbuf[i]=(byte)(v&0xff);
 532.701 +      v>>=8;
 532.702 +    }
 532.703 +    z.adler.update(crcbuf, 0, n);
 532.704 +  }
 532.705 +
 532.706 +  public GZIPHeader getGZIPHeader(){
 532.707 +    return gheader;
 532.708 +  }
 532.709 +
 532.710 +  boolean inParsingHeader(){
 532.711 +    switch(mode){
 532.712 +      case HEAD:
 532.713 +      case DICT4:
 532.714 +      case DICT3:
 532.715 +      case DICT2:
 532.716 +      case DICT1:
 532.717 +      case FLAGS:
 532.718 +      case TIME:
 532.719 +      case OS:
 532.720 +      case EXLEN:
 532.721 +      case EXTRA:
 532.722 +      case NAME:
 532.723 +      case COMMENT:
 532.724 +      case HCRC:
 532.725 +	return true;
 532.726 +      default:
 532.727 +	return false;
 532.728 +    }
 532.729 +  }
 532.730 +}
   533.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   533.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/Inflater.java	Wed Feb 27 11:24:58 2013 +0100
   533.3 @@ -0,0 +1,338 @@
   533.4 +/*
   533.5 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
   533.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   533.7 + *
   533.8 + * This code is free software; you can redistribute it and/or modify it
   533.9 + * under the terms of the GNU General Public License version 2 only, as
  533.10 + * published by the Free Software Foundation.  Oracle designates this
  533.11 + * particular file as subject to the "Classpath" exception as provided
  533.12 + * by Oracle in the LICENSE file that accompanied this code.
  533.13 + *
  533.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  533.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  533.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  533.17 + * version 2 for more details (a copy is included in the LICENSE file that
  533.18 + * accompanied this code).
  533.19 + *
  533.20 + * You should have received a copy of the GNU General Public License version
  533.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  533.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  533.23 + *
  533.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  533.25 + * or visit www.oracle.com if you need additional information or have any
  533.26 + * questions.
  533.27 + */
  533.28 +
  533.29 +package org.apidesign.bck2brwsr.emul.zip;
  533.30 +
  533.31 +import java.util.zip.*;
  533.32 +import java.io.IOException;
  533.33 +
  533.34 +/**
  533.35 + * This class provides support for general purpose decompression using the
  533.36 + * popular ZLIB compression library. The ZLIB compression library was
  533.37 + * initially developed as part of the PNG graphics standard and is not
  533.38 + * protected by patents. It is fully described in the specifications at
  533.39 + * the <a href="package-summary.html#package_description">java.util.zip
  533.40 + * package description</a>.
  533.41 + *
  533.42 + * <p>The following code fragment demonstrates a trivial compression
  533.43 + * and decompression of a string using <tt>Deflater</tt> and
  533.44 + * <tt>Inflater</tt>.
  533.45 + *
  533.46 + * <blockquote><pre>
  533.47 + * try {
  533.48 + *     // Encode a String into bytes
  533.49 + *     String inputString = "blahblahblah\u20AC\u20AC";
  533.50 + *     byte[] input = inputString.getBytes("UTF-8");
  533.51 + *
  533.52 + *     // Compress the bytes
  533.53 + *     byte[] output = new byte[100];
  533.54 + *     Deflater compresser = new Deflater();
  533.55 + *     compresser.setInput(input);
  533.56 + *     compresser.finish();
  533.57 + *     int compressedDataLength = compresser.deflate(output);
  533.58 + *
  533.59 + *     // Decompress the bytes
  533.60 + *     Inflater decompresser = new Inflater();
  533.61 + *     decompresser.setInput(output, 0, compressedDataLength);
  533.62 + *     byte[] result = new byte[100];
  533.63 + *     int resultLength = decompresser.inflate(result);
  533.64 + *     decompresser.end();
  533.65 + *
  533.66 + *     // Decode the bytes into a String
  533.67 + *     String outputString = new String(result, 0, resultLength, "UTF-8");
  533.68 + * } catch(java.io.UnsupportedEncodingException ex) {
  533.69 + *     // handle
  533.70 + * } catch (java.util.zip.DataFormatException ex) {
  533.71 + *     // handle
  533.72 + * }
  533.73 + * </pre></blockquote>
  533.74 + *
  533.75 + * @see         Deflater
  533.76 + * @author      David Connelly
  533.77 + *
  533.78 + */
  533.79 +public
  533.80 +class Inflater extends java.util.zip.Inflater {
  533.81 +    private final boolean nowrap;
  533.82 +    private JzLibInflater impl;
  533.83 +    
  533.84 +    /**
  533.85 +     * Creates a new decompressor. If the parameter 'nowrap' is true then
  533.86 +     * the ZLIB header and checksum fields will not be used. This provides
  533.87 +     * compatibility with the compression format used by both GZIP and PKZIP.
  533.88 +     * <p>
  533.89 +     * Note: When using the 'nowrap' option it is also necessary to provide
  533.90 +     * an extra "dummy" byte as input. This is required by the ZLIB native
  533.91 +     * library in order to support certain optimizations.
  533.92 +     *
  533.93 +     * @param nowrap if true then support GZIP compatible compression
  533.94 +     */
  533.95 +    public Inflater(boolean nowrap) {
  533.96 +        this.nowrap = nowrap;
  533.97 +        reset();
  533.98 +    }
  533.99 +
 533.100 +    /**
 533.101 +     * Creates a new decompressor.
 533.102 +     */
 533.103 +    public Inflater() {
 533.104 +        this(false);
 533.105 +    }
 533.106 +
 533.107 +    /**
 533.108 +     * Sets input data for decompression. Should be called whenever
 533.109 +     * needsInput() returns true indicating that more input data is
 533.110 +     * required.
 533.111 +     * @param b the input data bytes
 533.112 +     * @param off the start offset of the input data
 533.113 +     * @param len the length of the input data
 533.114 +     * @see Inflater#needsInput
 533.115 +     */
 533.116 +    public void setInput(byte[] b, int off, int len) {
 533.117 +        if (b == null) {
 533.118 +            throw new NullPointerException();
 533.119 +        }
 533.120 +        if (off < 0 || len < 0 || off > b.length - len) {
 533.121 +            throw new ArrayIndexOutOfBoundsException();
 533.122 +        }
 533.123 +        impl.setInput(b, off, len, false);
 533.124 +    }
 533.125 +
 533.126 +    /**
 533.127 +     * Sets input data for decompression. Should be called whenever
 533.128 +     * needsInput() returns true indicating that more input data is
 533.129 +     * required.
 533.130 +     * @param b the input data bytes
 533.131 +     * @see Inflater#needsInput
 533.132 +     */
 533.133 +    public void setInput(byte[] b) {
 533.134 +        setInput(b, 0, b.length);
 533.135 +    }
 533.136 +
 533.137 +    /**
 533.138 +     * Sets the preset dictionary to the given array of bytes. Should be
 533.139 +     * called when inflate() returns 0 and needsDictionary() returns true
 533.140 +     * indicating that a preset dictionary is required. The method getAdler()
 533.141 +     * can be used to get the Adler-32 value of the dictionary needed.
 533.142 +     * @param b the dictionary data bytes
 533.143 +     * @param off the start offset of the data
 533.144 +     * @param len the length of the data
 533.145 +     * @see Inflater#needsDictionary
 533.146 +     * @see Inflater#getAdler
 533.147 +     */
 533.148 +    public void setDictionary(byte[] b, int off, int len) {
 533.149 +        if (b == null) {
 533.150 +            throw new NullPointerException();
 533.151 +        }
 533.152 +        if (off < 0 || len < 0 || off > b.length - len) {
 533.153 +            throw new ArrayIndexOutOfBoundsException();
 533.154 +        }
 533.155 +        byte[] arr;
 533.156 +        if (off == 0) {
 533.157 +            arr = b;
 533.158 +        } else {
 533.159 +            arr = new byte[len];
 533.160 +            org.apidesign.bck2brwsr.emul.lang.System.arraycopy(b, off, arr, 0, len);
 533.161 +        }
 533.162 +        impl.setDictionary(arr, len);
 533.163 +    }
 533.164 +
 533.165 +    /**
 533.166 +     * Sets the preset dictionary to the given array of bytes. Should be
 533.167 +     * called when inflate() returns 0 and needsDictionary() returns true
 533.168 +     * indicating that a preset dictionary is required. The method getAdler()
 533.169 +     * can be used to get the Adler-32 value of the dictionary needed.
 533.170 +     * @param b the dictionary data bytes
 533.171 +     * @see Inflater#needsDictionary
 533.172 +     * @see Inflater#getAdler
 533.173 +     */
 533.174 +    public void setDictionary(byte[] b) {
 533.175 +        impl.setDictionary(b, b.length);
 533.176 +    }
 533.177 +
 533.178 +    /**
 533.179 +     * Returns the total number of bytes remaining in the input buffer.
 533.180 +     * This can be used to find out what bytes still remain in the input
 533.181 +     * buffer after decompression has finished.
 533.182 +     * @return the total number of bytes remaining in the input buffer
 533.183 +     */
 533.184 +    public int getRemaining() {
 533.185 +        return impl.getAvailIn();
 533.186 +    }
 533.187 +
 533.188 +    /**
 533.189 +     * Returns true if no data remains in the input buffer. This can
 533.190 +     * be used to determine if #setInput should be called in order
 533.191 +     * to provide more input.
 533.192 +     * @return true if no data remains in the input buffer
 533.193 +     */
 533.194 +    public boolean needsInput() {
 533.195 +        return getRemaining() <= 0;
 533.196 +    }
 533.197 +
 533.198 +    /**
 533.199 +     * Returns true if a preset dictionary is needed for decompression.
 533.200 +     * @return true if a preset dictionary is needed for decompression
 533.201 +     * @see Inflater#setDictionary
 533.202 +     */
 533.203 +    public boolean needsDictionary() {
 533.204 +        return impl.needDict();
 533.205 +    }
 533.206 +
 533.207 +    /**
 533.208 +     * Returns true if the end of the compressed data stream has been
 533.209 +     * reached.
 533.210 +     * @return true if the end of the compressed data stream has been
 533.211 +     * reached
 533.212 +     */
 533.213 +    public boolean finished() {
 533.214 +        return impl.finished();
 533.215 +    }
 533.216 +
 533.217 +    /**
 533.218 +     * Uncompresses bytes into specified buffer. Returns actual number
 533.219 +     * of bytes uncompressed. A return value of 0 indicates that
 533.220 +     * needsInput() or needsDictionary() should be called in order to
 533.221 +     * determine if more input data or a preset dictionary is required.
 533.222 +     * In the latter case, getAdler() can be used to get the Adler-32
 533.223 +     * value of the dictionary required.
 533.224 +     * @param b the buffer for the uncompressed data
 533.225 +     * @param off the start offset of the data
 533.226 +     * @param len the maximum number of uncompressed bytes
 533.227 +     * @return the actual number of uncompressed bytes
 533.228 +     * @exception DataFormatException if the compressed data format is invalid
 533.229 +     * @see Inflater#needsInput
 533.230 +     * @see Inflater#needsDictionary
 533.231 +     */
 533.232 +    public int inflate(byte[] b, int off, int len)
 533.233 +        throws DataFormatException
 533.234 +    {
 533.235 +        if (b == null) {
 533.236 +            throw new NullPointerException();
 533.237 +        }
 533.238 +        if (off < 0 || len < 0 || off > b.length - len) {
 533.239 +            throw new ArrayIndexOutOfBoundsException();
 533.240 +        }
 533.241 +        impl.setOutput(b, off, len);
 533.242 +        int err = impl.inflate(JzLibInflater.Z_NO_FLUSH);
 533.243 +        return impl.next_out_index - off;
 533.244 +    }
 533.245 +
 533.246 +    /**
 533.247 +     * Uncompresses bytes into specified buffer. Returns actual number
 533.248 +     * of bytes uncompressed. A return value of 0 indicates that
 533.249 +     * needsInput() or needsDictionary() should be called in order to
 533.250 +     * determine if more input data or a preset dictionary is required.
 533.251 +     * In the latter case, getAdler() can be used to get the Adler-32
 533.252 +     * value of the dictionary required.
 533.253 +     * @param b the buffer for the uncompressed data
 533.254 +     * @return the actual number of uncompressed bytes
 533.255 +     * @exception DataFormatException if the compressed data format is invalid
 533.256 +     * @see Inflater#needsInput
 533.257 +     * @see Inflater#needsDictionary
 533.258 +     */
 533.259 +    public int inflate(byte[] b) throws DataFormatException {
 533.260 +        return inflate(b, 0, b.length);
 533.261 +    }
 533.262 +
 533.263 +    /**
 533.264 +     * Returns the ADLER-32 value of the uncompressed data.
 533.265 +     * @return the ADLER-32 value of the uncompressed data
 533.266 +     */
 533.267 +    public int getAdler() {
 533.268 +        return (int) impl.getAdler();
 533.269 +    }
 533.270 +
 533.271 +    /**
 533.272 +     * Returns the total number of compressed bytes input so far.
 533.273 +     *
 533.274 +     * <p>Since the number of bytes may be greater than
 533.275 +     * Integer.MAX_VALUE, the {@link #getBytesRead()} method is now
 533.276 +     * the preferred means of obtaining this information.</p>
 533.277 +     *
 533.278 +     * @return the total number of compressed bytes input so far
 533.279 +     */
 533.280 +    public int getTotalIn() {
 533.281 +        return (int) getBytesRead();
 533.282 +    }
 533.283 +
 533.284 +    /**
 533.285 +     * Returns the total number of compressed bytes input so far.</p>
 533.286 +     *
 533.287 +     * @return the total (non-negative) number of compressed bytes input so far
 533.288 +     * @since 1.5
 533.289 +     */
 533.290 +    public long getBytesRead() {
 533.291 +        return impl.total_in;
 533.292 +    }
 533.293 +
 533.294 +    /**
 533.295 +     * Returns the total number of uncompressed bytes output so far.
 533.296 +     *
 533.297 +     * <p>Since the number of bytes may be greater than
 533.298 +     * Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now
 533.299 +     * the preferred means of obtaining this information.</p>
 533.300 +     *
 533.301 +     * @return the total number of uncompressed bytes output so far
 533.302 +     */
 533.303 +    public int getTotalOut() {
 533.304 +        return (int) getBytesWritten();
 533.305 +    }
 533.306 +
 533.307 +    /**
 533.308 +     * Returns the total number of uncompressed bytes output so far.</p>
 533.309 +     *
 533.310 +     * @return the total (non-negative) number of uncompressed bytes output so far
 533.311 +     * @since 1.5
 533.312 +     */
 533.313 +    public long getBytesWritten() {
 533.314 +        return impl.total_out;
 533.315 +    }
 533.316 +
 533.317 +    /**
 533.318 +     * Resets inflater so that a new set of input data can be processed.
 533.319 +     */
 533.320 +    public void reset() {
 533.321 +        impl = new JzLibInflater(15, nowrap);
 533.322 +    }
 533.323 +
 533.324 +    /**
 533.325 +     * Closes the decompressor and discards any unprocessed input.
 533.326 +     * This method should be called when the decompressor is no longer
 533.327 +     * being used, but will also be called automatically by the finalize()
 533.328 +     * method. Once this method is called, the behavior of the Inflater
 533.329 +     * object is undefined.
 533.330 +     */
 533.331 +    public void end() {
 533.332 +        impl.end();
 533.333 +    }
 533.334 +
 533.335 +    /**
 533.336 +     * Closes the decompressor when garbage is collected.
 533.337 +     */
 533.338 +    protected void finalize() {
 533.339 +        end();
 533.340 +    }
 533.341 +}
   534.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   534.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/JzLibInflater.java	Wed Feb 27 11:24:58 2013 +0100
   534.3 @@ -0,0 +1,137 @@
   534.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
   534.5 +/*
   534.6 +Copyright (c) 2011 ymnk, JCraft,Inc. All rights reserved.
   534.7 +
   534.8 +Redistribution and use in source and binary forms, with or without
   534.9 +modification, are permitted provided that the following conditions are met:
  534.10 +
  534.11 +  1. Redistributions of source code must retain the above copyright notice,
  534.12 +     this list of conditions and the following disclaimer.
  534.13 +
  534.14 +  2. Redistributions in binary form must reproduce the above copyright 
  534.15 +     notice, this list of conditions and the following disclaimer in 
  534.16 +     the documentation and/or other materials provided with the distribution.
  534.17 +
  534.18 +  3. The names of the authors may not be used to endorse or promote products
  534.19 +     derived from this software without specific prior written permission.
  534.20 +
  534.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  534.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  534.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  534.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  534.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  534.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  534.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  534.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  534.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  534.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  534.31 + */
  534.32 +/*
  534.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  534.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  534.35 + * and contributors of zlib.
  534.36 + */
  534.37 +
  534.38 +package org.apidesign.bck2brwsr.emul.zip;
  534.39 +
  534.40 +final class JzLibInflater extends ZStream{
  534.41 +
  534.42 +  static final private int MAX_WBITS=15;        // 32K LZ77 window
  534.43 +  static final private int DEF_WBITS=MAX_WBITS;
  534.44 +
  534.45 +  public static final int Z_NO_FLUSH=0;
  534.46 +  static final private int Z_PARTIAL_FLUSH=1;
  534.47 +  static final private int Z_SYNC_FLUSH=2;
  534.48 +  static final private int Z_FULL_FLUSH=3;
  534.49 +  static final private int Z_FINISH=4;
  534.50 +
  534.51 +  static final private int MAX_MEM_LEVEL=9;
  534.52 +
  534.53 +  static final private int Z_OK=0;
  534.54 +  static final private int Z_STREAM_END=1;
  534.55 +  static final private int Z_NEED_DICT=2;
  534.56 +  static final private int Z_ERRNO=-1;
  534.57 +  static final private int Z_STREAM_ERROR=-2;
  534.58 +  static final private int Z_DATA_ERROR=-3;
  534.59 +  static final private int Z_MEM_ERROR=-4;
  534.60 +  static final private int Z_BUF_ERROR=-5;
  534.61 +  static final private int Z_VERSION_ERROR=-6;
  534.62 +
  534.63 +  public JzLibInflater() {
  534.64 +    super();
  534.65 +    init();
  534.66 +  }
  534.67 +
  534.68 +  public JzLibInflater(int w)  {
  534.69 +    this(w, false);
  534.70 +  }
  534.71 +
  534.72 +  public JzLibInflater(int w, boolean nowrap)  {
  534.73 +    super();
  534.74 +    int ret = init(w, nowrap);
  534.75 +    if(ret!=Z_OK)
  534.76 +      throw new IllegalStateException(ret+": "+msg);
  534.77 +  }
  534.78 +
  534.79 +  private boolean finished = false;
  534.80 +
  534.81 +  public int init(){
  534.82 +    return init(DEF_WBITS);
  534.83 +  }
  534.84 +
  534.85 +  public int init(boolean nowrap){
  534.86 +    return init(DEF_WBITS, nowrap);
  534.87 +  }
  534.88 +
  534.89 +  public int init(int w){
  534.90 +    return init(w, false);
  534.91 +  }
  534.92 +
  534.93 +  public int init(int w, boolean nowrap){
  534.94 +    finished = false;
  534.95 +    istate=new Inflate(this);
  534.96 +    return istate.inflateInit(nowrap?-w:w);
  534.97 +  }
  534.98 +
  534.99 +  public int inflate(int f){
 534.100 +    if(istate==null) return Z_STREAM_ERROR;
 534.101 +    int ret = istate.inflate(f);
 534.102 +    if(ret == Z_STREAM_END) 
 534.103 +      finished = true;
 534.104 +    return ret;
 534.105 +  }
 534.106 +
 534.107 +  public int end(){
 534.108 +    finished = true;
 534.109 +    if(istate==null) return Z_STREAM_ERROR;
 534.110 +    int ret=istate.inflateEnd();
 534.111 +//    istate = null;
 534.112 +    return ret;
 534.113 +  }
 534.114 +
 534.115 +  public int sync(){
 534.116 +    if(istate == null)
 534.117 +      return Z_STREAM_ERROR;
 534.118 +    return istate.inflateSync();
 534.119 +  }
 534.120 +
 534.121 +  public int syncPoint(){
 534.122 +    if(istate == null)
 534.123 +      return Z_STREAM_ERROR;
 534.124 +    return istate.inflateSyncPoint();
 534.125 +  }
 534.126 +
 534.127 +  public int setDictionary(byte[] dictionary, int dictLength){
 534.128 +    if(istate == null)
 534.129 +      return Z_STREAM_ERROR;
 534.130 +    return istate.inflateSetDictionary(dictionary, dictLength);
 534.131 +  }
 534.132 +
 534.133 +  public boolean finished(){
 534.134 +    return istate.mode==12 /*DONE*/;
 534.135 +  }
 534.136 +
 534.137 +  public boolean needDict() {
 534.138 +    return istate == null ? false : istate.mode == Inflate.DICT0;
 534.139 +  }
 534.140 +}
   535.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   535.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZStream.java	Wed Feb 27 11:24:58 2013 +0100
   535.3 @@ -0,0 +1,253 @@
   535.4 +/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
   535.5 +/*
   535.6 +Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved.
   535.7 +
   535.8 +Redistribution and use in source and binary forms, with or without
   535.9 +modification, are permitted provided that the following conditions are met:
  535.10 +
  535.11 +  1. Redistributions of source code must retain the above copyright notice,
  535.12 +     this list of conditions and the following disclaimer.
  535.13 +
  535.14 +  2. Redistributions in binary form must reproduce the above copyright 
  535.15 +     notice, this list of conditions and the following disclaimer in 
  535.16 +     the documentation and/or other materials provided with the distribution.
  535.17 +
  535.18 +  3. The names of the authors may not be used to endorse or promote products
  535.19 +     derived from this software without specific prior written permission.
  535.20 +
  535.21 +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  535.22 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  535.23 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  535.24 +INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  535.25 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  535.26 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  535.27 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  535.28 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  535.29 +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  535.30 +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  535.31 + */
  535.32 +/*
  535.33 + * This program is based on zlib-1.1.3, so all credit should go authors
  535.34 + * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  535.35 + * and contributors of zlib.
  535.36 + */
  535.37 +
  535.38 +package org.apidesign.bck2brwsr.emul.zip;
  535.39 +
  535.40 +import org.apidesign.bck2brwsr.emul.lang.System;
  535.41 +
  535.42 +/**
  535.43 + * ZStream
  535.44 + *
  535.45 + * @deprecated  Not for public use in the future.
  535.46 + */
  535.47 +@Deprecated
  535.48 +class ZStream{
  535.49 +
  535.50 +  static final private int MAX_WBITS=15;        // 32K LZ77 window
  535.51 +  static final private int DEF_WBITS=MAX_WBITS;
  535.52 +
  535.53 +  static final private int Z_NO_FLUSH=0;
  535.54 +  static final private int Z_PARTIAL_FLUSH=1;
  535.55 +  static final private int Z_SYNC_FLUSH=2;
  535.56 +  static final private int Z_FULL_FLUSH=3;
  535.57 +  static final private int Z_FINISH=4;
  535.58 +
  535.59 +  static final private int MAX_MEM_LEVEL=9;
  535.60 +
  535.61 +  static final private int Z_OK=0;
  535.62 +  static final private int Z_STREAM_END=1;
  535.63 +  static final private int Z_NEED_DICT=2;
  535.64 +  static final private int Z_ERRNO=-1;
  535.65 +  static final private int Z_STREAM_ERROR=-2;
  535.66 +  static final private int Z_DATA_ERROR=-3;
  535.67 +  static final private int Z_MEM_ERROR=-4;
  535.68 +  static final private int Z_BUF_ERROR=-5;
  535.69 +  static final private int Z_VERSION_ERROR=-6;
  535.70 +
  535.71 +  public byte[] next_in;     // next input byte
  535.72 +  public int next_in_index;
  535.73 +  public int avail_in;       // number of bytes available at next_in
  535.74 +  public long total_in;      // total nb of input bytes read so far
  535.75 +
  535.76 +  public byte[] next_out;    // next output byte should be put there
  535.77 +  public int next_out_index;
  535.78 +  public int avail_out;      // remaining free space at next_out
  535.79 +  public long total_out;     // total nb of bytes output so far
  535.80 +
  535.81 +  public String msg;
  535.82 +
  535.83 +  Inflate istate; 
  535.84 +
  535.85 +  int data_type; // best guess about the data type: ascii or binary
  535.86 +
  535.87 +  Checksum adler;
  535.88 +
  535.89 +  public ZStream(){
  535.90 +    this(new Adler32());
  535.91 +  }
  535.92 +
  535.93 +  public ZStream(Checksum adler){
  535.94 +    this.adler=adler;
  535.95 +  }
  535.96 +
  535.97 +  public int inflateInit(){
  535.98 +    return inflateInit(DEF_WBITS);
  535.99 +  }
 535.100 +  public int inflateInit(boolean nowrap){
 535.101 +    return inflateInit(DEF_WBITS, nowrap);
 535.102 +  }
 535.103 +  public int inflateInit(int w){
 535.104 +    return inflateInit(w, false);
 535.105 +  }
 535.106 +
 535.107 +  public int inflateInit(int w, boolean nowrap){
 535.108 +    istate=new Inflate(this);
 535.109 +    return istate.inflateInit(nowrap?-w:w);
 535.110 +  }
 535.111 +
 535.112 +  public int inflate(int f){
 535.113 +    if(istate==null) return Z_STREAM_ERROR;
 535.114 +    return istate.inflate(f);
 535.115 +  }
 535.116 +  public int inflateEnd(){
 535.117 +    if(istate==null) return Z_STREAM_ERROR;
 535.118 +    int ret=istate.inflateEnd();
 535.119 +//    istate = null;
 535.120 +    return ret;
 535.121 +  }
 535.122 +  
 535.123 +  public int inflateSync(){
 535.124 +    if(istate == null)
 535.125 +      return Z_STREAM_ERROR;
 535.126 +    return istate.inflateSync();
 535.127 +  }
 535.128 +  public int inflateSyncPoint(){
 535.129 +    if(istate == null)
 535.130 +      return Z_STREAM_ERROR;
 535.131 +    return istate.inflateSyncPoint();
 535.132 +  }
 535.133 +  public int inflateSetDictionary(byte[] dictionary, int dictLength){
 535.134 +    if(istate == null)
 535.135 +      return Z_STREAM_ERROR;
 535.136 +    return istate.inflateSetDictionary(dictionary, dictLength);
 535.137 +  }
 535.138 +  public boolean inflateFinished(){
 535.139 +    return istate.mode==12 /*DONE*/;
 535.140 +  }
 535.141 +
 535.142 +
 535.143 +  public long getAdler(){
 535.144 +    return adler.getValue();
 535.145 +  }
 535.146 +
 535.147 +  public void free(){
 535.148 +    next_in=null;
 535.149 +    next_out=null;
 535.150 +    msg=null;
 535.151 +  }
 535.152 +
 535.153 +  public void setOutput(byte[] buf){
 535.154 +    setOutput(buf, 0, buf.length); 
 535.155 +  }
 535.156 +
 535.157 +  public void setOutput(byte[] buf, int off, int len){
 535.158 +    next_out = buf;
 535.159 +    next_out_index = off;
 535.160 +    avail_out = len;
 535.161 +  }
 535.162 +
 535.163 +  public void setInput(byte[] buf){
 535.164 +    setInput(buf, 0, buf.length, false); 
 535.165 +  }
 535.166 +
 535.167 +  public void setInput(byte[] buf, boolean append){
 535.168 +    setInput(buf, 0, buf.length, append); 
 535.169 +  }
 535.170 +
 535.171 +  public void setInput(byte[] buf, int off, int len, boolean append){
 535.172 +    if(len<=0 && append && next_in!=null) return;
 535.173 +
 535.174 +    if(avail_in>0 && append){  
 535.175 +      byte[] tmp = new byte[avail_in+len];
 535.176 +      System.arraycopy(next_in, next_in_index, tmp, 0, avail_in);
 535.177 +      System.arraycopy(buf, off, tmp, avail_in, len);
 535.178 +      next_in=tmp;
 535.179 +      next_in_index=0;
 535.180 +      avail_in+=len;
 535.181 +    }
 535.182 +    else{
 535.183 +      next_in=buf;
 535.184 +      next_in_index=off;
 535.185 +      avail_in=len;
 535.186 +    }
 535.187 +  }
 535.188 +
 535.189 +  public byte[] getNextIn(){
 535.190 +    return next_in;
 535.191 +  }
 535.192 +
 535.193 +  public void setNextIn(byte[] next_in){
 535.194 +    this.next_in = next_in;
 535.195 +  }
 535.196 +
 535.197 +  public int getNextInIndex(){
 535.198 +    return next_in_index;
 535.199 +  }
 535.200 +
 535.201 +  public void setNextInIndex(int next_in_index){
 535.202 +    this.next_in_index = next_in_index;
 535.203 +  }
 535.204 +
 535.205 +  public int getAvailIn(){
 535.206 +    return avail_in;
 535.207 +  }
 535.208 +
 535.209 +  public void setAvailIn(int avail_in){
 535.210 +    this.avail_in = avail_in;
 535.211 +  }
 535.212 +
 535.213 +  public byte[] getNextOut(){
 535.214 +    return next_out;
 535.215 +  }
 535.216 +
 535.217 +  public void setNextOut(byte[] next_out){
 535.218 +    this.next_out = next_out;
 535.219 +  }
 535.220 +
 535.221 +  public int getNextOutIndex(){
 535.222 +    return next_out_index;
 535.223 +  }
 535.224 +
 535.225 +  public void setNextOutIndex(int next_out_index){
 535.226 +    this.next_out_index = next_out_index;
 535.227 +  }
 535.228 +
 535.229 +  public int getAvailOut(){
 535.230 +    return avail_out;
 535.231 +
 535.232 +  }
 535.233 +
 535.234 +  public void setAvailOut(int avail_out){
 535.235 +    this.avail_out = avail_out;
 535.236 +  }
 535.237 +
 535.238 +  public long getTotalOut(){
 535.239 +    return total_out;
 535.240 +  }
 535.241 +
 535.242 +  public long getTotalIn(){
 535.243 +    return total_in;
 535.244 +  }
 535.245 +
 535.246 +  public String getMessage(){
 535.247 +    return msg;
 535.248 +  }
 535.249 +
 535.250 +  /**
 535.251 +   * Those methods are expected to be override by Inflater and Deflater.
 535.252 +   * In the future, they will become abstract methods.
 535.253 +   */ 
 535.254 +  public int end(){ return Z_OK; }
 535.255 +  public boolean finished(){ return false; }
 535.256 +}
   536.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   536.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipConstants64.java	Wed Feb 27 11:24:58 2013 +0100
   536.3 @@ -0,0 +1,84 @@
   536.4 +/*
   536.5 + * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
   536.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   536.7 + *
   536.8 + * This code is free software; you can redistribute it and/or modify it
   536.9 + * under the terms of the GNU General Public License version 2 only, as
  536.10 + * published by the Free Software Foundation.  Oracle designates this
  536.11 + * particular file as subject to the "Classpath" exception as provided
  536.12 + * by Oracle in the LICENSE file that accompanied this code.
  536.13 + *
  536.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  536.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  536.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  536.17 + * version 2 for more details (a copy is included in the LICENSE file that
  536.18 + * accompanied this code).
  536.19 + *
  536.20 + * You should have received a copy of the GNU General Public License version
  536.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  536.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  536.23 + *
  536.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  536.25 + * or visit www.oracle.com if you need additional information or have any
  536.26 + * questions.
  536.27 + */
  536.28 +
  536.29 +package org.apidesign.bck2brwsr.emul.zip;
  536.30 +
  536.31 +/*
  536.32 + * This class defines the constants that are used by the classes
  536.33 + * which manipulate Zip64 files.
  536.34 + */
  536.35 +
  536.36 +public class ZipConstants64 {
  536.37 +
  536.38 +    /*
  536.39 +     * ZIP64 constants
  536.40 +     */
  536.41 +    static final long ZIP64_ENDSIG = 0x06064b50L;  // "PK\006\006"
  536.42 +    static final long ZIP64_LOCSIG = 0x07064b50L;  // "PK\006\007"
  536.43 +    static final int  ZIP64_ENDHDR = 56;           // ZIP64 end header size
  536.44 +    static final int  ZIP64_LOCHDR = 20;           // ZIP64 end loc header size
  536.45 +    static final int  ZIP64_EXTHDR = 24;           // EXT header size
  536.46 +    static final int  ZIP64_EXTID  = 0x0001;       // Extra field Zip64 header ID
  536.47 +
  536.48 +    static final int  ZIP64_MAGICCOUNT = 0xFFFF;
  536.49 +    static final long ZIP64_MAGICVAL = 0xFFFFFFFFL;
  536.50 +
  536.51 +    /*
  536.52 +     * Zip64 End of central directory (END) header field offsets
  536.53 +     */
  536.54 +    static final int  ZIP64_ENDLEN = 4;       // size of zip64 end of central dir
  536.55 +    static final int  ZIP64_ENDVEM = 12;      // version made by
  536.56 +    static final int  ZIP64_ENDVER = 14;      // version needed to extract
  536.57 +    static final int  ZIP64_ENDNMD = 16;      // number of this disk
  536.58 +    static final int  ZIP64_ENDDSK = 20;      // disk number of start
  536.59 +    static final int  ZIP64_ENDTOD = 24;      // total number of entries on this disk
  536.60 +    static final int  ZIP64_ENDTOT = 32;      // total number of entries
  536.61 +    static final int  ZIP64_ENDSIZ = 40;      // central directory size in bytes
  536.62 +    static final int  ZIP64_ENDOFF = 48;      // offset of first CEN header
  536.63 +    static final int  ZIP64_ENDEXT = 56;      // zip64 extensible data sector
  536.64 +
  536.65 +    /*
  536.66 +     * Zip64 End of central directory locator field offsets
  536.67 +     */
  536.68 +    static final int  ZIP64_LOCDSK = 4;       // disk number start
  536.69 +    static final int  ZIP64_LOCOFF = 8;       // offset of zip64 end
  536.70 +    static final int  ZIP64_LOCTOT = 16;      // total number of disks
  536.71 +
  536.72 +    /*
  536.73 +     * Zip64 Extra local (EXT) header field offsets
  536.74 +     */
  536.75 +    static final int  ZIP64_EXTCRC = 4;       // uncompressed file crc-32 value
  536.76 +    static final int  ZIP64_EXTSIZ = 8;       // compressed size, 8-byte
  536.77 +    static final int  ZIP64_EXTLEN = 16;      // uncompressed size, 8-byte
  536.78 +
  536.79 +    /*
  536.80 +     * Language encoding flag EFS
  536.81 +     */
  536.82 +    static final int EFS = 0x800;       // If this bit is set the filename and
  536.83 +                                        // comment fields for this file must be
  536.84 +                                        // encoded using UTF-8.
  536.85 +
  536.86 +    private ZipConstants64() {}
  536.87 +}
   537.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   537.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/zip/ZipInputStream.java	Wed Feb 27 11:24:58 2013 +0100
   537.3 @@ -0,0 +1,468 @@
   537.4 +/*
   537.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   537.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   537.7 + *
   537.8 + * This code is free software; you can redistribute it and/or modify it
   537.9 + * under the terms of the GNU General Public License version 2 only, as
  537.10 + * published by the Free Software Foundation.  Oracle designates this
  537.11 + * particular file as subject to the "Classpath" exception as provided
  537.12 + * by Oracle in the LICENSE file that accompanied this code.
  537.13 + *
  537.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  537.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  537.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  537.17 + * version 2 for more details (a copy is included in the LICENSE file that
  537.18 + * accompanied this code).
  537.19 + *
  537.20 + * You should have received a copy of the GNU General Public License version
  537.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  537.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  537.23 + *
  537.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  537.25 + * or visit www.oracle.com if you need additional information or have any
  537.26 + * questions.
  537.27 + */
  537.28 +
  537.29 +package org.apidesign.bck2brwsr.emul.zip;
  537.30 +
  537.31 +import java.util.zip.*;
  537.32 +import java.io.InputStream;
  537.33 +import java.io.IOException;
  537.34 +import java.io.EOFException;
  537.35 +import java.io.PushbackInputStream;
  537.36 +import static org.apidesign.bck2brwsr.emul.zip.ZipConstants64.*;
  537.37 +import static java.util.zip.ZipInputStream.*;
  537.38 +
  537.39 +/**
  537.40 + * This class implements an input stream filter for reading files in the
  537.41 + * ZIP file format. Includes support for both compressed and uncompressed
  537.42 + * entries.
  537.43 + *
  537.44 + * @author      David Connelly
  537.45 + */
  537.46 +public
  537.47 +class ZipInputStream extends InflaterInputStream  {
  537.48 +    private ZipEntry entry;
  537.49 +    private int flag;
  537.50 +    private CRC32 crc = new CRC32();
  537.51 +    private long remaining;
  537.52 +    private byte[] tmpbuf = new byte[512];
  537.53 +
  537.54 +    private static final int STORED = ZipEntry.STORED;
  537.55 +    private static final int DEFLATED = ZipEntry.DEFLATED;
  537.56 +
  537.57 +    private boolean closed = false;
  537.58 +    // this flag is set to true after EOF has reached for
  537.59 +    // one entry
  537.60 +    private boolean entryEOF = false;
  537.61 +
  537.62 +    /**
  537.63 +     * Check to make sure that this stream has not been closed
  537.64 +     */
  537.65 +    private void ensureOpen() throws IOException {
  537.66 +        if (closed) {
  537.67 +            throw new IOException("Stream closed");
  537.68 +        }
  537.69 +    }
  537.70 +
  537.71 +    /**
  537.72 +     * Creates a new ZIP input stream.
  537.73 +     *
  537.74 +     * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used to
  537.75 +     * decode the entry names.
  537.76 +     *
  537.77 +     * @param in the actual input stream
  537.78 +     */
  537.79 +    public ZipInputStream(InputStream in) {
  537.80 +//        this(in, "UTF-8");
  537.81 +        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
  537.82 +        //usesDefaultInflater = true;
  537.83 +        if(in == null) {
  537.84 +            throw new NullPointerException("in is null");
  537.85 +        }
  537.86 +    }
  537.87 +
  537.88 +    /**
  537.89 +     * Creates a new ZIP input stream.
  537.90 +     *
  537.91 +     * @param in the actual input stream
  537.92 +     *
  537.93 +     * @param charset
  537.94 +     *        The {@linkplain java.nio.charset.Charset charset} to be
  537.95 +     *        used to decode the ZIP entry name (ignored if the
  537.96 +     *        <a href="package-summary.html#lang_encoding"> language
  537.97 +     *        encoding bit</a> of the ZIP entry's general purpose bit
  537.98 +     *        flag is set).
  537.99 +     *
 537.100 +     * @since 1.7
 537.101 +     *
 537.102 +    public ZipInputStream(InputStream in, Charset charset) {
 537.103 +        super(new PushbackInputStream(in, 512), new Inflater(true), 512);
 537.104 +        usesDefaultInflater = true;
 537.105 +        if(in == null) {
 537.106 +            throw new NullPointerException("in is null");
 537.107 +        }
 537.108 +        if (charset == null)
 537.109 +            throw new NullPointerException("charset is null");
 537.110 +        this.zc = ZipCoder.get(charset);
 537.111 +    }
 537.112 +    */
 537.113 +
 537.114 +    /**
 537.115 +     * Reads the next ZIP file entry and positions the stream at the
 537.116 +     * beginning of the entry data.
 537.117 +     * @return the next ZIP file entry, or null if there are no more entries
 537.118 +     * @exception ZipException if a ZIP file error has occurred
 537.119 +     * @exception IOException if an I/O error has occurred
 537.120 +     */
 537.121 +    public ZipEntry getNextEntry() throws IOException {
 537.122 +        ensureOpen();
 537.123 +        if (entry != null) {
 537.124 +            closeEntry();
 537.125 +        }
 537.126 +        crc.reset();
 537.127 +        inf.reset();
 537.128 +        if ((entry = readLOC()) == null) {
 537.129 +            return null;
 537.130 +        }
 537.131 +        if (entry.getMethod() == STORED) {
 537.132 +            remaining = entry.getSize();
 537.133 +        }
 537.134 +        entryEOF = false;
 537.135 +        return entry;
 537.136 +    }
 537.137 +
 537.138 +    /**
 537.139 +     * Closes the current ZIP entry and positions the stream for reading the
 537.140 +     * next entry.
 537.141 +     * @exception ZipException if a ZIP file error has occurred
 537.142 +     * @exception IOException if an I/O error has occurred
 537.143 +     */
 537.144 +    public void closeEntry() throws IOException {
 537.145 +        ensureOpen();
 537.146 +        while (read(tmpbuf, 0, tmpbuf.length) != -1) ;
 537.147 +        entryEOF = true;
 537.148 +    }
 537.149 +
 537.150 +    /**
 537.151 +     * Returns 0 after EOF has reached for the current entry data,
 537.152 +     * otherwise always return 1.
 537.153 +     * <p>
 537.154 +     * Programs should not count on this method to return the actual number
 537.155 +     * of bytes that could be read without blocking.
 537.156 +     *
 537.157 +     * @return     1 before EOF and 0 after EOF has reached for current entry.
 537.158 +     * @exception  IOException  if an I/O error occurs.
 537.159 +     *
 537.160 +     */
 537.161 +    public int available() throws IOException {
 537.162 +        ensureOpen();
 537.163 +        if (entryEOF) {
 537.164 +            return 0;
 537.165 +        } else {
 537.166 +            return 1;
 537.167 +        }
 537.168 +    }
 537.169 +
 537.170 +    /**
 537.171 +     * Reads from the current ZIP entry into an array of bytes.
 537.172 +     * If <code>len</code> is not zero, the method
 537.173 +     * blocks until some input is available; otherwise, no
 537.174 +     * bytes are read and <code>0</code> is returned.
 537.175 +     * @param b the buffer into which the data is read
 537.176 +     * @param off the start offset in the destination array <code>b</code>
 537.177 +     * @param len the maximum number of bytes read
 537.178 +     * @return the actual number of bytes read, or -1 if the end of the
 537.179 +     *         entry is reached
 537.180 +     * @exception  NullPointerException if <code>b</code> is <code>null</code>.
 537.181 +     * @exception  IndexOutOfBoundsException if <code>off</code> is negative,
 537.182 +     * <code>len</code> is negative, or <code>len</code> is greater than
 537.183 +     * <code>b.length - off</code>
 537.184 +     * @exception ZipException if a ZIP file error has occurred
 537.185 +     * @exception IOException if an I/O error has occurred
 537.186 +     */
 537.187 +    public int read(byte[] b, int off, int len) throws IOException {
 537.188 +        ensureOpen();
 537.189 +        if (off < 0 || len < 0 || off > b.length - len) {
 537.190 +            throw new IndexOutOfBoundsException();
 537.191 +        } else if (len == 0) {
 537.192 +            return 0;
 537.193 +        }
 537.194 +
 537.195 +        if (entry == null) {
 537.196 +            return -1;
 537.197 +        }
 537.198 +        switch (entry.getMethod()) {
 537.199 +        case DEFLATED:
 537.200 +            len = super.read(b, off, len);
 537.201 +            if (len == -1) {
 537.202 +                readEnd(entry);
 537.203 +                entryEOF = true;
 537.204 +                entry = null;
 537.205 +            } else {
 537.206 +                crc.update(b, off, len);
 537.207 +            }
 537.208 +            return len;
 537.209 +        case STORED:
 537.210 +            if (remaining <= 0) {
 537.211 +                entryEOF = true;
 537.212 +                entry = null;
 537.213 +                return -1;
 537.214 +            }
 537.215 +            if (len > remaining) {
 537.216 +                len = (int)remaining;
 537.217 +            }
 537.218 +            len = in.read(b, off, len);
 537.219 +            if (len == -1) {
 537.220 +                throw new ZipException("unexpected EOF");
 537.221 +            }
 537.222 +            crc.update(b, off, len);
 537.223 +            remaining -= len;
 537.224 +            if (remaining == 0 && entry.getCrc() != crc.getValue()) {
 537.225 +                throw new ZipException(
 537.226 +                    "invalid entry CRC (expected 0x" + Long.toHexString(entry.getCrc()) +
 537.227 +                    " but got 0x" + Long.toHexString(crc.getValue()) + ")");
 537.228 +            }
 537.229 +            return len;
 537.230 +        default:
 537.231 +            throw new ZipException("invalid compression method");
 537.232 +        }
 537.233 +    }
 537.234 +
 537.235 +    /**
 537.236 +     * Skips specified number of bytes in the current ZIP entry.
 537.237 +     * @param n the number of bytes to skip
 537.238 +     * @return the actual number of bytes skipped
 537.239 +     * @exception ZipException if a ZIP file error has occurred
 537.240 +     * @exception IOException if an I/O error has occurred
 537.241 +     * @exception IllegalArgumentException if n < 0
 537.242 +     */
 537.243 +    public long skip(long n) throws IOException {
 537.244 +        if (n < 0) {
 537.245 +            throw new IllegalArgumentException("negative skip length");
 537.246 +        }
 537.247 +        ensureOpen();
 537.248 +        int max = (int)Math.min(n, Integer.MAX_VALUE);
 537.249 +        int total = 0;
 537.250 +        while (total < max) {
 537.251 +            int len = max - total;
 537.252 +            if (len > tmpbuf.length) {
 537.253 +                len = tmpbuf.length;
 537.254 +            }
 537.255 +            len = read(tmpbuf, 0, len);
 537.256 +            if (len == -1) {
 537.257 +                entryEOF = true;
 537.258 +                break;
 537.259 +            }
 537.260 +            total += len;
 537.261 +        }
 537.262 +        return total;
 537.263 +    }
 537.264 +
 537.265 +    /**
 537.266 +     * Closes this input stream and releases any system resources associated
 537.267 +     * with the stream.
 537.268 +     * @exception IOException if an I/O error has occurred
 537.269 +     */
 537.270 +    public void close() throws IOException {
 537.271 +        if (!closed) {
 537.272 +            super.close();
 537.273 +            closed = true;
 537.274 +        }
 537.275 +    }
 537.276 +
 537.277 +    private byte[] b = new byte[256];
 537.278 +
 537.279 +    /*
 537.280 +     * Reads local file (LOC) header for next entry.
 537.281 +     */
 537.282 +    private ZipEntry readLOC() throws IOException {
 537.283 +        try {
 537.284 +            readFully(tmpbuf, 0, LOCHDR);
 537.285 +        } catch (EOFException e) {
 537.286 +            return null;
 537.287 +        }
 537.288 +        if (get32(tmpbuf, 0) != LOCSIG) {
 537.289 +            return null;
 537.290 +        }
 537.291 +        // get flag first, we need check EFS.
 537.292 +        flag = get16(tmpbuf, LOCFLG);
 537.293 +        // get the entry name and create the ZipEntry first
 537.294 +        int len = get16(tmpbuf, LOCNAM);
 537.295 +        int blen = b.length;
 537.296 +        if (len > blen) {
 537.297 +            do
 537.298 +                blen = blen * 2;
 537.299 +            while (len > blen);
 537.300 +            b = new byte[blen];
 537.301 +        }
 537.302 +        readFully(b, 0, len);
 537.303 +        // Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8
 537.304 +        ZipEntry e = createZipEntry(((flag & EFS) != 0)
 537.305 +                                    ? toStringUTF8(b, len)
 537.306 +                                    : toString(b, len));
 537.307 +        // now get the remaining fields for the entry
 537.308 +        if ((flag & 1) == 1) {
 537.309 +            throw new ZipException("encrypted ZIP entry not supported");
 537.310 +        }
 537.311 +        e.setMethod(get16(tmpbuf, LOCHOW));
 537.312 +        e.setTime(get32(tmpbuf, LOCTIM));
 537.313 +        if ((flag & 8) == 8) {
 537.314 +            /* "Data Descriptor" present */
 537.315 +            if (e.getMethod() != DEFLATED) {
 537.316 +                throw new ZipException(
 537.317 +                        "only DEFLATED entries can have EXT descriptor");
 537.318 +            }
 537.319 +        } else {
 537.320 +            e.setCrc(get32(tmpbuf, LOCCRC));
 537.321 +            e.setCompressedSize(get32(tmpbuf, LOCSIZ));
 537.322 +            e.setSize(get32(tmpbuf, LOCLEN));
 537.323 +        }
 537.324 +        len = get16(tmpbuf, LOCEXT);
 537.325 +        if (len > 0) {
 537.326 +            byte[] bb = new byte[len];
 537.327 +            readFully(bb, 0, len);
 537.328 +            e.setExtra(bb);
 537.329 +            // extra fields are in "HeaderID(2)DataSize(2)Data... format
 537.330 +            if (e.getCompressedSize() == ZIP64_MAGICVAL || e.getCompressedSize() == ZIP64_MAGICVAL) {
 537.331 +                int off = 0;
 537.332 +                while (off + 4 < len) {
 537.333 +                    int sz = get16(bb, off + 2);
 537.334 +                    if (get16(bb, off) == ZIP64_EXTID) {
 537.335 +                        off += 4;
 537.336 +                        // LOC extra zip64 entry MUST include BOTH original and
 537.337 +                        // compressed file size fields
 537.338 +                        if (sz < 16 || (off + sz) > len ) {
 537.339 +                            // Invalid zip64 extra fields, simply skip. Even it's
 537.340 +                            // rare, it's possible the entry size happens to be
 537.341 +                            // the magic value and it "accidnetly" has some bytes
 537.342 +                            // in extra match the id.
 537.343 +                            return e;
 537.344 +                        }
 537.345 +                        e.setSize(get64(bb, off));
 537.346 +                        e.setCompressedSize(get64(bb, off + 8));
 537.347 +                        break;
 537.348 +                    }
 537.349 +                    off += (sz + 4);
 537.350 +                }
 537.351 +            }
 537.352 +        }
 537.353 +        return e;
 537.354 +    }
 537.355 +
 537.356 +    /**
 537.357 +     * Creates a new <code>ZipEntry</code> object for the specified
 537.358 +     * entry name.
 537.359 +     *
 537.360 +     * @param name the ZIP file entry name
 537.361 +     * @return the ZipEntry just created
 537.362 +     */
 537.363 +    protected ZipEntry createZipEntry(String name) {
 537.364 +        return new ZipEntry(name);
 537.365 +    }
 537.366 +
 537.367 +    /*
 537.368 +     * Reads end of deflated entry as well as EXT descriptor if present.
 537.369 +     */
 537.370 +    private void readEnd(ZipEntry e) throws IOException {
 537.371 +        int n = inf.getRemaining();
 537.372 +        if (n > 0) {
 537.373 +            ((PushbackInputStream)in).unread(buf, len - n, n);
 537.374 +        }
 537.375 +        if ((flag & 8) == 8) {
 537.376 +            /* "Data Descriptor" present */
 537.377 +            if (inf.getBytesWritten() > ZIP64_MAGICVAL ||
 537.378 +                inf.getBytesRead() > ZIP64_MAGICVAL) {
 537.379 +                // ZIP64 format
 537.380 +                readFully(tmpbuf, 0, ZIP64_EXTHDR);
 537.381 +                long sig = get32(tmpbuf, 0);
 537.382 +                if (sig != EXTSIG) { // no EXTSIG present
 537.383 +                    e.setCrc(sig);
 537.384 +                    e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ - ZIP64_EXTCRC));
 537.385 +                    e.setSize(get64(tmpbuf, ZIP64_EXTLEN - ZIP64_EXTCRC));
 537.386 +                    ((PushbackInputStream)in).unread(
 537.387 +                        tmpbuf, ZIP64_EXTHDR - ZIP64_EXTCRC - 1, ZIP64_EXTCRC);
 537.388 +                } else {
 537.389 +                    e.setCrc(get32(tmpbuf, ZIP64_EXTCRC));
 537.390 +                    e.setCompressedSize(get64(tmpbuf, ZIP64_EXTSIZ));
 537.391 +                    e.setSize(get64(tmpbuf, ZIP64_EXTLEN));
 537.392 +                }
 537.393 +            } else {
 537.394 +                readFully(tmpbuf, 0, EXTHDR);
 537.395 +                long sig = get32(tmpbuf, 0);
 537.396 +                if (sig != EXTSIG) { // no EXTSIG present
 537.397 +                    e.setCrc(sig);
 537.398 +                    e.setCompressedSize(get32(tmpbuf, EXTSIZ - EXTCRC));
 537.399 +                    e.setSize(get32(tmpbuf, EXTLEN - EXTCRC));
 537.400 +                    ((PushbackInputStream)in).unread(
 537.401 +                                               tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
 537.402 +                } else {
 537.403 +                    e.setCrc(get32(tmpbuf, EXTCRC));
 537.404 +                    e.setCompressedSize(get32(tmpbuf, EXTSIZ));
 537.405 +                    e.setSize(get32(tmpbuf, EXTLEN));
 537.406 +                }
 537.407 +            }
 537.408 +        }
 537.409 +        if (e.getSize() != inf.getBytesWritten()) {
 537.410 +            throw new ZipException(
 537.411 +                "invalid entry size (expected " + e.getSize() +
 537.412 +                " but got " + inf.getBytesWritten() + " bytes)");
 537.413 +        }
 537.414 +        if (e.getCompressedSize() != inf.getBytesRead()) {
 537.415 +            throw new ZipException(
 537.416 +                "invalid entry compressed size (expected " + e.getCompressedSize() +
 537.417 +                " but got " + inf.getBytesRead() + " bytes)");
 537.418 +        }
 537.419 +        if (e.getCrc() != crc.getValue()) {
 537.420 +            throw new ZipException(
 537.421 +                "invalid entry CRC (expected 0x" + Long.toHexString(e.getCrc()) +
 537.422 +                " but got 0x" + Long.toHexString(crc.getValue()) + ")");
 537.423 +        }
 537.424 +    }
 537.425 +
 537.426 +    /*
 537.427 +     * Reads bytes, blocking until all bytes are read.
 537.428 +     */
 537.429 +    private void readFully(byte[] b, int off, int len) throws IOException {
 537.430 +        while (len > 0) {
 537.431 +            int n = in.read(b, off, len);
 537.432 +            if (n == -1) {
 537.433 +                throw new EOFException();
 537.434 +            }
 537.435 +            off += n;
 537.436 +            len -= n;
 537.437 +        }
 537.438 +    }
 537.439 +
 537.440 +    /*
 537.441 +     * Fetches unsigned 16-bit value from byte array at specified offset.
 537.442 +     * The bytes are assumed to be in Intel (little-endian) byte order.
 537.443 +     */
 537.444 +    private static final int get16(byte b[], int off) {
 537.445 +        return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8);
 537.446 +    }
 537.447 +
 537.448 +    /*
 537.449 +     * Fetches unsigned 32-bit value from byte array at specified offset.
 537.450 +     * The bytes are assumed to be in Intel (little-endian) byte order.
 537.451 +     */
 537.452 +    private static final long get32(byte b[], int off) {
 537.453 +        return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
 537.454 +    }
 537.455 +
 537.456 +    /*
 537.457 +     * Fetches signed 64-bit value from byte array at specified offset.
 537.458 +     * The bytes are assumed to be in Intel (little-endian) byte order.
 537.459 +     */
 537.460 +    private static final long get64(byte b[], int off) {
 537.461 +        return get32(b, off) | (get32(b, off+4) << 32);
 537.462 +    }
 537.463 +
 537.464 +    private static String toStringUTF8(byte[] arr, int len) {
 537.465 +        return new String(arr, 0, len);
 537.466 +    }
 537.467 +    
 537.468 +    private static String toString(byte[] b, int len) {
 537.469 +        return new String(b, 0, len);
 537.470 +    }
 537.471 +}
   538.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   538.2 +++ b/rt/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js	Wed Feb 27 11:24:58 2013 +0100
   538.3 @@ -0,0 +1,544 @@
   538.4 +// empty line needed here
   538.5 +Number.prototype.add32 = function(x) { return (this + x) | 0; };
   538.6 +Number.prototype.sub32 = function(x) { return (this - x) | 0; };
   538.7 +Number.prototype.mul32 = function(x) { 
   538.8 +    return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
   538.9 +};
  538.10 +Number.prototype.neg32 = function() { return (-this) | 0; };
  538.11 +
  538.12 +Number.prototype.toInt8 = function()  { return (this << 24) >> 24; };
  538.13 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
  538.14 +
  538.15 +var __m32 = 0xFFFFFFFF;
  538.16 +
  538.17 +Number.prototype.next32 = function(low) {
  538.18 +  if (this === 0) {
  538.19 +    return low;
  538.20 +  }
  538.21 +  var l = new Number(low);
  538.22 +  l.hi = this | 0;
  538.23 +  return l;
  538.24 +};
  538.25 +
  538.26 +Number.prototype.high32 = function() { 
  538.27 +    return this.hi ? this.hi : (Math.floor(this / (__m32+1))) | 0;
  538.28 +};
  538.29 +Number.prototype.toInt32 = function() { return this | 0; };
  538.30 +Number.prototype.toFP = function() {
  538.31 +    return this.hi ? this.hi * (__m32+1) + this : this;
  538.32 +};
  538.33 +Number.prototype.toLong = function() {
  538.34 +    var hi = (this > __m32) ? (Math.floor(this / (__m32+1))) | 0 : 0;
  538.35 +    return hi.next32(Math.floor(this % (__m32+1)));
  538.36 +};
  538.37 +
  538.38 +Number.prototype.toExactString = function() {
  538.39 +    if (this.hi) {
  538.40 +        // check for Long.MIN_VALUE
  538.41 +        if ((this.hi == (0x80000000 | 0)) && (this == 0)) {
  538.42 +            return '-9223372036854775808';
  538.43 +        }
  538.44 +        var res = 0;
  538.45 +        var a = [ 6,9,2,7,6,9,4,9,2,4 ];
  538.46 +        var s = '';
  538.47 +        var digit;
  538.48 +        var neg = this.hi < 0;
  538.49 +        if (neg) {
  538.50 +            var x = this.neg64();
  538.51 +            var hi = x.hi;
  538.52 +            var low = x;
  538.53 +        } else {
  538.54 +            var hi = this.hi;
  538.55 +            var low = this;
  538.56 +        }
  538.57 +        for (var i = 0; i < a.length; i++) {
  538.58 +            res += hi * a[i];
  538.59 +            var low_digit = low % 10;
  538.60 +            digit = (res % 10) + low_digit;
  538.61 +
  538.62 +            low = Math.floor(low / 10);
  538.63 +            res = Math.floor(res / 10);
  538.64 +
  538.65 +            if (digit >= 10) {
  538.66 +                digit -= 10;
  538.67 +                res++;
  538.68 +            }
  538.69 +            s = String(digit).concat(s);
  538.70 +        }
  538.71 +        s = String(res).concat(s).replace(/^0+/, '');
  538.72 +        return (neg ? '-' : '').concat(s);
  538.73 +    }
  538.74 +    return String(this);
  538.75 +};
  538.76 +
  538.77 +Number.prototype.add64 = function(x) {
  538.78 +    var low = this + x;
  538.79 +    carry = 0;
  538.80 +    if (low > __m32) {
  538.81 +        carry = 1;
  538.82 +        low -= (__m32+1);
  538.83 +    }
  538.84 +    var hi = (this.high32() + x.high32() + carry) | 0;
  538.85 +    return hi.next32(low);
  538.86 +};
  538.87 +
  538.88 +Number.prototype.sub64 = function(x) {
  538.89 +    var low = this - x;
  538.90 +    carry = 0;
  538.91 +    if (low < 0) {
  538.92 +        carry = 1;
  538.93 +        low += (__m32+1);
  538.94 +    }
  538.95 +    var hi = (this.high32() - x.high32() - carry) | 0;
  538.96 +    return hi.next32(low);
  538.97 +};
  538.98 +
  538.99 +Number.prototype.mul64 = function(x) {
 538.100 +    var low = this.mul32(x);
 538.101 +    low += (low < 0) ? (__m32+1) : 0;
 538.102 +    // first count upper 32 bits of (this.low * x.low)
 538.103 +    var hi_hi = 0;
 538.104 +    var hi_low = 0;
 538.105 +    var m = 1;
 538.106 +    for (var i = 0; i < 32; i++) {
 538.107 +        if (x & m) {
 538.108 +            hi_hi += this >>> 16;
 538.109 +            hi_low += this & 0xFFFF
 538.110 +        }
 538.111 +        hi_low >>= 1;
 538.112 +        hi_low += (hi_hi & 1) ? 0x8000 : 0;
 538.113 +        hi_hi >>= 1;
 538.114 +        m <<= 1;
 538.115 +    }
 538.116 +    var hi = (hi_hi << 16) + hi_low;
 538.117 +    
 538.118 +    var m1 = this.high32().mul32(x);
 538.119 +    var m2 = this.mul32(x.high32());
 538.120 +    hi = hi.add32(m1).add32(m2);
 538.121 +    
 538.122 +    return hi.next32(low);
 538.123 +};
 538.124 +
 538.125 +Number.prototype.and64 = function(x) {
 538.126 +    var low = this & x;
 538.127 +    low += (low < 0) ? (__m32+1) : 0;
 538.128 +    if (this.hi && x.hi) {
 538.129 +        var hi = this.hi & x.hi;
 538.130 +        return hi.next32(low);
 538.131 +    };
 538.132 +    return low;
 538.133 +};
 538.134 +
 538.135 +Number.prototype.or64 = function(x) {
 538.136 +    var low = this | x;
 538.137 +    low += (low < 0) ? (__m32+1) : 0;
 538.138 +    if (this.hi || x.hi) {
 538.139 +        var hi = this.hi | x.hi;
 538.140 +        return hi.next32(low);
 538.141 +    };
 538.142 +    return low;
 538.143 +};
 538.144 +
 538.145 +Number.prototype.xor64 = function(x) {
 538.146 +    var low = this ^ x;
 538.147 +    low += (low < 0) ? (__m32+1) : 0;
 538.148 +    if (this.hi || x.hi) {
 538.149 +        var hi = this.hi ^ x.hi;
 538.150 +        return hi.next32(low);
 538.151 +    };
 538.152 +    return low;
 538.153 +};
 538.154 +
 538.155 +Number.prototype.shl64 = function(x) {
 538.156 +    if (x >= 32) {
 538.157 +        var hi = this << (x - 32);
 538.158 +        return hi.next32(0);
 538.159 +    } else {
 538.160 +        var hi = this.high32() << x;
 538.161 +        var low_reminder = this >> (32 - x);
 538.162 +        hi |= low_reminder;
 538.163 +        var low = this << x;
 538.164 +        low += (low < 0) ? (__m32+1) : 0;
 538.165 +        return hi.next32(low);
 538.166 +    }
 538.167 +};
 538.168 +
 538.169 +Number.prototype.shr64 = function(x) {
 538.170 +    if (x >= 32) {
 538.171 +        var low = this.high32() >> (x - 32);
 538.172 +        low += (low < 0) ? (__m32+1) : 0;
 538.173 +        return low;
 538.174 +    } else {
 538.175 +        var low = this >> x;
 538.176 +        var hi_reminder = this.high32() << (32 - x);
 538.177 +        low |= hi_reminder;
 538.178 +        low += (low < 0) ? (__m32+1) : 0;
 538.179 +        var hi = this.high32() >> x;
 538.180 +        return hi.next32(low);
 538.181 +    }
 538.182 +};
 538.183 +
 538.184 +Number.prototype.ushr64 = function(x) {
 538.185 +    if (x >= 32) {
 538.186 +        var low = this.high32() >>> (x - 32);
 538.187 +        low += (low < 0) ? (__m32+1) : 0;
 538.188 +        return low;
 538.189 +    } else {
 538.190 +        var low = this >>> x;
 538.191 +        var hi_reminder = this.high32() << (32 - x);
 538.192 +        low |= hi_reminder;
 538.193 +        low += (low < 0) ? (__m32+1) : 0;
 538.194 +        var hi = this.high32() >>> x;
 538.195 +        return hi.next32(low);
 538.196 +    }
 538.197 +};
 538.198 +
 538.199 +Number.prototype.compare64 = function(x) {
 538.200 +    if (this.high32() === x.high32()) {
 538.201 +        return (this < x) ? -1 : ((this > x) ? 1 : 0);
 538.202 +    }
 538.203 +    return (this.high32() < x.high32()) ? -1 : 1;
 538.204 +};
 538.205 +
 538.206 +Number.prototype.neg64 = function() {
 538.207 +    var hi = this.high32();
 538.208 +    var low = this;
 538.209 +    if ((hi === 0) && (low < 0)) { return -low; }
 538.210 +    hi = ~hi;
 538.211 +    low = ~low;
 538.212 +    low += (low < 0) ? (__m32+1) : 0;
 538.213 +    var ret = hi.next32(low);
 538.214 +    return ret.add64(1);
 538.215 +};
 538.216 +
 538.217 +(function(numberPrototype) {
 538.218 +    function __handleDivByZero() {
 538.219 +        var exception = new vm.java_lang_ArithmeticException;
 538.220 +        vm.java_lang_ArithmeticException(false).constructor
 538.221 +          .cons__VLjava_lang_String_2.call(exception, "/ by zero");
 538.222 +
 538.223 +        throw exception;
 538.224 +    }
 538.225 +
 538.226 +    function __Int64(hi32, lo32) {
 538.227 +        this.hi32 = hi32 | 0;
 538.228 +        this.lo32 = lo32 | 0;
 538.229 +
 538.230 +        this.get32 = function(bitIndex) {
 538.231 +            var v0;
 538.232 +            var v1;
 538.233 +            bitIndex += 32;
 538.234 +            var selector = bitIndex >>> 5;
 538.235 +            switch (selector) {
 538.236 +                case 0:
 538.237 +                    v0 = 0;
 538.238 +                    v1 = this.lo32;
 538.239 +                    break;
 538.240 +                case 1:
 538.241 +                    v0 = this.lo32;
 538.242 +                    v1 = this.hi32;
 538.243 +                    break;
 538.244 +                case 2:
 538.245 +                    v0 = this.hi32;
 538.246 +                    v1 = 0;
 538.247 +                    break
 538.248 +                default:
 538.249 +                    return 0;
 538.250 +            }
 538.251 +
 538.252 +            var shift = bitIndex & 31;
 538.253 +            if (shift === 0) {
 538.254 +                return v0;
 538.255 +            }
 538.256 +
 538.257 +            return (v1 << (32 - shift)) | (v0 >>> shift);
 538.258 +        }
 538.259 +
 538.260 +        this.get16 = function(bitIndex) {
 538.261 +            return this.get32(bitIndex) & 0xffff;
 538.262 +        }
 538.263 +
 538.264 +        this.set16 = function(bitIndex, value) {
 538.265 +            bitIndex += 32;
 538.266 +            var shift = bitIndex & 15;
 538.267 +            var svalue = (value & 0xffff) << shift; 
 538.268 +            var smask = 0xffff << shift;
 538.269 +            var selector = bitIndex >>> 4;
 538.270 +            switch (selector) {
 538.271 +                case 0:
 538.272 +                    break;
 538.273 +                case 1:
 538.274 +                    this.lo32 = (this.lo32 & ~(smask >>> 16))
 538.275 +                                    | (svalue >>> 16);
 538.276 +                    break;
 538.277 +                case 2:
 538.278 +                    this.lo32 = (this.lo32 & ~smask) | svalue;
 538.279 +                    break;
 538.280 +                case 3:
 538.281 +                    this.lo32 = (this.lo32 & ~(smask << 16))
 538.282 +                                    | (svalue << 16);
 538.283 +                    this.hi32 = (this.hi32 & ~(smask >>> 16))
 538.284 +                                    | (svalue >>> 16);
 538.285 +                    break;
 538.286 +                case 4:
 538.287 +                    this.hi32 = (this.hi32 & ~smask) | svalue;
 538.288 +                    break;
 538.289 +                case 5:
 538.290 +                    this.hi32 = (this.hi32 & ~(smask << 16))
 538.291 +                                    | (svalue << 16);
 538.292 +                    break;
 538.293 +            }
 538.294 +        }
 538.295 +
 538.296 +        this.getDigit = function(index, shift) {
 538.297 +            return this.get16((index << 4) - shift);
 538.298 +        }
 538.299 +
 538.300 +        this.getTwoDigits = function(index, shift) {
 538.301 +            return this.get32(((index - 1) << 4) - shift);
 538.302 +        }
 538.303 +
 538.304 +        this.setDigit = function(index, shift, value) {
 538.305 +            this.set16((index << 4) - shift, value);
 538.306 +        }
 538.307 +
 538.308 +        this.countSignificantDigits = function() {
 538.309 +            var sd;
 538.310 +            var remaining;
 538.311 +
 538.312 +            if (this.hi32 === 0) {
 538.313 +                if (this.lo32 === 0) {
 538.314 +                    return 0;
 538.315 +                }
 538.316 +
 538.317 +                sd = 2;
 538.318 +                remaining = this.lo32;
 538.319 +            } else {
 538.320 +                sd = 4;
 538.321 +                remaining = this.hi32;
 538.322 +            }
 538.323 +
 538.324 +            if (remaining < 0) {
 538.325 +                return sd;
 538.326 +            }
 538.327 +
 538.328 +            return (remaining < 65536) ? sd - 1 : sd;
 538.329 +        }
 538.330 +        
 538.331 +        this.toNumber = function() {
 538.332 +            var lo32 = this.lo32;
 538.333 +            if (lo32 < 0) {
 538.334 +                lo32 += 0x100000000;
 538.335 +            }
 538.336 +
 538.337 +            return this.hi32.next32(lo32);
 538.338 +        }
 538.339 +    }
 538.340 +
 538.341 +    function __countLeadingZeroes16(number) {
 538.342 +        var nlz = 0;
 538.343 +
 538.344 +        if (number < 256) {
 538.345 +            nlz += 8;
 538.346 +            number <<= 8;
 538.347 +        }
 538.348 +
 538.349 +        if (number < 4096) {
 538.350 +            nlz += 4;
 538.351 +            number <<= 4;
 538.352 +        }
 538.353 +
 538.354 +        if (number < 16384) {
 538.355 +            nlz += 2;
 538.356 +            number <<= 2;
 538.357 +        }
 538.358 +
 538.359 +        return (number < 32768) ? nlz + 1 : nlz;
 538.360 +    }
 538.361 +    
 538.362 +    // q = u / v; r = u - q * v;
 538.363 +    // v != 0
 538.364 +    function __div64(q, r, u, v) {
 538.365 +        var m = u.countSignificantDigits();
 538.366 +        var n = v.countSignificantDigits();
 538.367 +
 538.368 +        q.hi32 = q.lo32 = 0;
 538.369 +
 538.370 +        if (n === 1) {
 538.371 +            // v has single digit
 538.372 +            var vd = v.getDigit(0, 0);
 538.373 +            var carry = 0;
 538.374 +            for (var i = m - 1; i >= 0; --i) {
 538.375 +                var ui = (carry << 16) | u.getDigit(i, 0);
 538.376 +                if (ui < 0) {
 538.377 +                    ui += 0x100000000;
 538.378 +                }
 538.379 +                var qi = (ui / vd) | 0;
 538.380 +                q.setDigit(i, 0, qi);
 538.381 +                carry = ui - qi * vd;
 538.382 +            }
 538.383 +
 538.384 +            r.hi32 = 0;
 538.385 +            r.lo32 = carry;
 538.386 +            return;
 538.387 +        }
 538.388 +
 538.389 +        r.hi32 = u.hi32;  
 538.390 +        r.lo32 = u.lo32;
 538.391 +
 538.392 +        if (m < n) {
 538.393 +            return;
 538.394 +        }
 538.395 +
 538.396 +        // Normalize
 538.397 +        var nrm = __countLeadingZeroes16(v.getDigit(n - 1, 0));
 538.398 +
 538.399 +        var vd1 = v.getDigit(n - 1, nrm);                
 538.400 +        var vd0 = v.getDigit(n - 2, nrm);
 538.401 +        for (var j = m - n; j >= 0; --j) {
 538.402 +            // Calculate qj estimate
 538.403 +            var ud21 = r.getTwoDigits(j + n, nrm);
 538.404 +            var ud2 = ud21 >>> 16;
 538.405 +            if (ud21 < 0) {
 538.406 +                ud21 += 0x100000000;
 538.407 +            }
 538.408 +
 538.409 +            var qest = (ud2 === vd1) ? 0xFFFF : ((ud21 / vd1) | 0);
 538.410 +            var rest = ud21 - qest * vd1;
 538.411 +
 538.412 +            // 0 <= (qest - qj) <= 2
 538.413 +
 538.414 +            // Refine qj estimate
 538.415 +            var ud0 = r.getDigit(j + n - 2, nrm);
 538.416 +            while ((qest * vd0) > ((rest * 0x10000) + ud0)) {
 538.417 +                --qest;
 538.418 +                rest += vd1;
 538.419 +            }
 538.420 +
 538.421 +            // 0 <= (qest - qj) <= 1
 538.422 +            
 538.423 +            // Multiply and subtract
 538.424 +            var carry = 0;
 538.425 +            for (var i = 0; i < n; ++i) {
 538.426 +                var vi = qest * v.getDigit(i, nrm);
 538.427 +                var ui = r.getDigit(i + j, nrm) - carry - (vi & 0xffff);
 538.428 +                r.setDigit(i + j, nrm, ui);
 538.429 +                carry = (vi >>> 16) - (ui >> 16);
 538.430 +            }
 538.431 +            var uj = ud2 - carry;
 538.432 +
 538.433 +            if (uj < 0) {
 538.434 +                // qest - qj = 1
 538.435 +
 538.436 +                // Add back
 538.437 +                --qest;
 538.438 +                var carry = 0;
 538.439 +                for (var i = 0; i < n; ++i) {
 538.440 +                    var ui = r.getDigit(i + j, nrm) + v.getDigit(i, nrm)
 538.441 +                                 + carry;
 538.442 +                    r.setDigit(i + j, nrm, ui);
 538.443 +                    carry = ui >> 16;
 538.444 +                }
 538.445 +                uj += carry;
 538.446 +            }
 538.447 +
 538.448 +            q.setDigit(j, 0, qest);
 538.449 +            r.setDigit(j + n, nrm, uj);
 538.450 +        }
 538.451 +    }
 538.452 +
 538.453 +    numberPrototype.div32 = function(x) {
 538.454 +        if (x === 0) {
 538.455 +            __handleDivByZero();
 538.456 +        }
 538.457 +
 538.458 +        return (this / x) | 0;
 538.459 +    }
 538.460 +
 538.461 +    numberPrototype.mod32 = function(x) {
 538.462 +        if (x === 0) {
 538.463 +            __handleDivByZero();
 538.464 +        }
 538.465 +
 538.466 +        return (this % x);
 538.467 +    }
 538.468 +
 538.469 +    numberPrototype.div64 = function(x) {
 538.470 +        var negateResult = false;
 538.471 +        var u, v;
 538.472 +
 538.473 +        if ((this.high32() & 0x80000000) != 0) {
 538.474 +            u = this.neg64();
 538.475 +            negateResult = !negateResult;
 538.476 +        } else {
 538.477 +            u = this;        
 538.478 +        }
 538.479 +
 538.480 +        if ((x.high32() & 0x80000000) != 0) {
 538.481 +            v = x.neg64();
 538.482 +            negateResult = !negateResult;
 538.483 +        } else {
 538.484 +            v = x;
 538.485 +        }
 538.486 +
 538.487 +        if ((v === 0) && (v.high32() === 0)) {
 538.488 +            __handleDivByZero();
 538.489 +        }
 538.490 +
 538.491 +        if (u.high32() === 0) {
 538.492 +            if (v.high32() === 0) {
 538.493 +                var result = (u / v) | 0;
 538.494 +                return negateResult ? result.neg64() : result; 
 538.495 +            }
 538.496 +
 538.497 +            return 0;
 538.498 +        }
 538.499 +
 538.500 +        var u64 = new __Int64(u.high32(), u);
 538.501 +        var v64 = new __Int64(v.high32(), v);
 538.502 +        var q64 = new __Int64(0, 0);
 538.503 +        var r64 = new __Int64(0, 0);
 538.504 +
 538.505 +        __div64(q64, r64, u64, v64);
 538.506 +
 538.507 +        var result = q64.toNumber();
 538.508 +        return negateResult ? result.neg64() : result; 
 538.509 +    }
 538.510 +
 538.511 +    numberPrototype.mod64 = function(x) {
 538.512 +        var negateResult = false;
 538.513 +        var u, v;
 538.514 +        
 538.515 +        if ((this.high32() & 0x80000000) != 0) {
 538.516 +            u = this.neg64();
 538.517 +            negateResult = !negateResult;
 538.518 +        } else {
 538.519 +            u = this;        
 538.520 +        }
 538.521 +
 538.522 +        if ((x.high32() & 0x80000000) != 0) {
 538.523 +            v = x.neg64();
 538.524 +        } else {
 538.525 +            v = x;
 538.526 +        }
 538.527 +
 538.528 +        if ((v === 0) && (v.high32() === 0)) {
 538.529 +            __handleDivByZero();
 538.530 +        }
 538.531 +
 538.532 +        if (u.high32() === 0) {
 538.533 +            var result = (v.high32() === 0) ? (u % v) : u;
 538.534 +            return negateResult ? result.neg64() : result; 
 538.535 +        }
 538.536 +
 538.537 +        var u64 = new __Int64(u.high32(), u);
 538.538 +        var v64 = new __Int64(v.high32(), v);
 538.539 +        var q64 = new __Int64(0, 0);
 538.540 +        var r64 = new __Int64(0, 0);
 538.541 +
 538.542 +        __div64(q64, r64, u64, v64);
 538.543 +
 538.544 +        var result = r64.toNumber();
 538.545 +        return negateResult ? result.neg64() : result; 
 538.546 +    }
 538.547 +})(Number.prototype);
   539.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   539.2 +++ b/rt/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_String.js	Wed Feb 27 11:24:58 2013 +0100
   539.3 @@ -0,0 +1,27 @@
   539.4 +// initialize methods on arrays and String constants
   539.5 +vm.java_lang_reflect_Array(false);
   539.6 +vm.java_lang_String(false);
   539.7 +
   539.8 +Array.prototype.at = function(indx, value) {
   539.9 +  if (indx < 0 || indx > this.length) {
  539.10 +      var e = vm.java_lang_ArrayIndexOutOfBoundsException(true);
  539.11 +      e.constructor.cons__VLjava_lang_String_2.call(e, indx.toString());
  539.12 +      throw e;
  539.13 +  }
  539.14 +  if (arguments.length === 2) {
  539.15 +      this[indx] = value;
  539.16 +  }
  539.17 +  return this[indx];
  539.18 +};
  539.19 +Array.prototype.getClass__Ljava_lang_Class_2 = function() {
  539.20 +  return vm.java_lang_Class(false).defineArray__Ljava_lang_Class_2Ljava_lang_String_2(this.jvmName);
  539.21 +};
  539.22 +Array.prototype.clone__Ljava_lang_Object_2 = function() {
  539.23 +  var s = this.length;
  539.24 +  var ret = new Array(s);
  539.25 +  for (var i = 0; i < s; i++) {
  539.26 +      ret[i] = this[i];
  539.27 +  }
  539.28 +  ret.jvmName = this.jvmName;
  539.29 +  return ret;
  539.30 +};
   540.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   540.2 +++ b/rt/emul/mini/src/test/java/org/apidesign/bck2brwsr/emul/reflect/MethodImplTest.java	Wed Feb 27 11:24:58 2013 +0100
   540.3 @@ -0,0 +1,49 @@
   540.4 +/**
   540.5 + * Back 2 Browser Bytecode Translator
   540.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   540.7 + *
   540.8 + * This program is free software: you can redistribute it and/or modify
   540.9 + * it under the terms of the GNU General Public License as published by
  540.10 + * the Free Software Foundation, version 2 of the License.
  540.11 + *
  540.12 + * This program is distributed in the hope that it will be useful,
  540.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  540.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  540.15 + * GNU General Public License for more details.
  540.16 + *
  540.17 + * You should have received a copy of the GNU General Public License
  540.18 + * along with this program. Look for COPYING file in the top folder.
  540.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  540.20 + */
  540.21 +package org.apidesign.bck2brwsr.emul.reflect;
  540.22 +
  540.23 +import java.lang.reflect.Method;
  540.24 +import java.util.Enumeration;
  540.25 +import org.testng.annotations.Test;
  540.26 +
  540.27 +/**
  540.28 + *
  540.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  540.30 + */
  540.31 +public class MethodImplTest {
  540.32 +    
  540.33 +    public MethodImplTest() {
  540.34 +    }
  540.35 +    
  540.36 +    public static String[] arr(String... arr) {
  540.37 +        return arr;
  540.38 +    }
  540.39 +
  540.40 +    @Test
  540.41 +    public void testSignatureForMethodWithAnArray() throws NoSuchMethodException {
  540.42 +        Method m = MethodImplTest.class.getMethod("arr", String[].class);
  540.43 +        String sig = MethodImpl.toSignature(m);
  540.44 +        int sep = sig.indexOf("__");
  540.45 +        assert sep > 0 : "Separator found " + sig;
  540.46 +        
  540.47 +        Enumeration<Class> en = MethodImpl.signatureParser(sig.substring(sep + 2));
  540.48 +        
  540.49 +        assert en.nextElement() == m.getReturnType() : "Return type is the same";
  540.50 +        assert en.nextElement() == m.getParameterTypes()[0] : "1st param type is the same";
  540.51 +    }
  540.52 +}
  540.53 \ No newline at end of file
   541.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   541.2 +++ b/rt/emul/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   541.3 @@ -0,0 +1,18 @@
   541.4 +<?xml version="1.0" encoding="UTF-8"?>
   541.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">
   541.6 +  <modelVersion>4.0.0</modelVersion>
   541.7 +  <parent>
   541.8 +    <groupId>org.apidesign.bck2brwsr</groupId>
   541.9 +    <artifactId>rt</artifactId>
  541.10 +    <version>0.3-SNAPSHOT</version>
  541.11 +  </parent>
  541.12 +  <groupId>org.apidesign.bck2brwsr</groupId>
  541.13 +  <artifactId>emul.pom</artifactId>
  541.14 +  <version>0.3-SNAPSHOT</version>
  541.15 +  <packaging>pom</packaging>
  541.16 +  <name>Emulation of Core Libraries</name>
  541.17 +  <modules>
  541.18 +    <module>mini</module>
  541.19 +    <module>compact</module>
  541.20 +  </modules>
  541.21 +</project>
   542.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   542.2 +++ b/rt/javap/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   542.3 @@ -0,0 +1,41 @@
   542.4 +<?xml version="1.0"?>
   542.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"
   542.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   542.7 +  <modelVersion>4.0.0</modelVersion>
   542.8 +  <parent>
   542.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  542.10 +    <artifactId>rt</artifactId>
  542.11 +    <version>0.3-SNAPSHOT</version>
  542.12 +  </parent>
  542.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  542.14 +  <artifactId>javap</artifactId>
  542.15 +  <version>0.3-SNAPSHOT</version>
  542.16 +  <name>ByteCode Parser</name>
  542.17 +  <url>http://maven.apache.org</url>
  542.18 +  <properties>
  542.19 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  542.20 +  </properties>
  542.21 +  <build>
  542.22 +      <plugins>
  542.23 +          <plugin>
  542.24 +              <groupId>org.apache.maven.plugins</groupId>
  542.25 +              <artifactId>maven-compiler-plugin</artifactId>
  542.26 +              <version>2.5.1</version>
  542.27 +              <configuration>
  542.28 +                  <compilerArguments>
  542.29 +                      <!--<bootclasspath>non-existing</bootclasspath>-->
  542.30 +                  </compilerArguments>
  542.31 +                 <source>1.6</source>
  542.32 +                 <target>1.6</target>
  542.33 +              </configuration>
  542.34 +          </plugin>
  542.35 +      </plugins>
  542.36 +  </build>
  542.37 +  <dependencies>
  542.38 +    <dependency>
  542.39 +      <groupId>org.apidesign.bck2brwsr</groupId>
  542.40 +      <artifactId>emul.mini</artifactId>
  542.41 +      <version>0.3-SNAPSHOT</version>
  542.42 +    </dependency>
  542.43 +  </dependencies>
  542.44 +</project>
   543.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   543.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/AnnotationParser.java	Wed Feb 27 11:24:58 2013 +0100
   543.3 @@ -0,0 +1,145 @@
   543.4 +/*
   543.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   543.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   543.7 + *
   543.8 + * This code is free software; you can redistribute it and/or modify it
   543.9 + * under the terms of the GNU General Public License version 2 only, as
  543.10 + * published by the Free Software Foundation.  Oracle designates this
  543.11 + * particular file as subject to the "Classpath" exception as provided
  543.12 + * by Oracle in the LICENSE file that accompanied this code.
  543.13 + *
  543.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  543.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  543.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  543.17 + * version 2 for more details (a copy is included in the LICENSE file that
  543.18 + * accompanied this code).
  543.19 + *
  543.20 + * You should have received a copy of the GNU General Public License version
  543.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  543.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  543.23 + *
  543.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  543.25 + * or visit www.oracle.com if you need additional information or have any
  543.26 + * questions.
  543.27 + */
  543.28 +package org.apidesign.javap;
  543.29 +
  543.30 +import java.io.ByteArrayInputStream;
  543.31 +import java.io.DataInputStream;
  543.32 +import java.io.IOException;
  543.33 +
  543.34 +/** An abstract parser for annotation definitions. Analyses the bytes and
  543.35 + * performs some callbacks to the overriden parser methods.
  543.36 + *
  543.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  543.38 + */
  543.39 +public class AnnotationParser {
  543.40 +    private final boolean textual;
  543.41 +    private final boolean iterateArray;
  543.42 +    
  543.43 +    protected AnnotationParser(boolean textual, boolean iterateArray) {
  543.44 +        this.textual = textual;
  543.45 +        this.iterateArray = iterateArray;
  543.46 +    }
  543.47 +
  543.48 +    protected void visitAnnotationStart(String type, boolean top) throws IOException {
  543.49 +    }
  543.50 +
  543.51 +    protected void visitAnnotationEnd(String type, boolean top) throws IOException {
  543.52 +    }
  543.53 +
  543.54 +    protected void visitValueStart(String attrName, char type) throws IOException {
  543.55 +    }
  543.56 +
  543.57 +    protected void visitValueEnd(String attrName, char type) throws IOException {
  543.58 +    }
  543.59 +
  543.60 +    
  543.61 +    protected void visitAttr(
  543.62 +        String annoType, String attr, String attrType, String value
  543.63 +    ) throws IOException {
  543.64 +    }
  543.65 +    
  543.66 +    protected void visitEnumAttr(
  543.67 +        String annoType, String attr, String attrType, String value
  543.68 +    ) throws IOException {
  543.69 +        visitAttr(annoType, attr, attrType, value);
  543.70 +    }
  543.71 +    
  543.72 +    /** Initialize the parsing with constant pool from <code>cd</code>.
  543.73 +     * 
  543.74 +     * @param attr the attribute defining annotations
  543.75 +     * @param cd constant pool
  543.76 +     * @throws IOException in case I/O fails
  543.77 +     */
  543.78 +    public final void parse(byte[] attr, ClassData cd) throws IOException {
  543.79 +        ByteArrayInputStream is = new ByteArrayInputStream(attr);
  543.80 +        DataInputStream dis = new DataInputStream(is);
  543.81 +        try {
  543.82 +            read(dis, cd);
  543.83 +        } finally {
  543.84 +            is.close();
  543.85 +        }
  543.86 +    }
  543.87 +    
  543.88 +    private void read(DataInputStream dis, ClassData cd) throws IOException {
  543.89 +    	int cnt = dis.readUnsignedShort();
  543.90 +        for (int i = 0; i < cnt; i++) {
  543.91 +            readAnno(dis, cd, true);
  543.92 +        }
  543.93 +    }
  543.94 +
  543.95 +    private void readAnno(DataInputStream dis, ClassData cd, boolean top) throws IOException {
  543.96 +        int type = dis.readUnsignedShort();
  543.97 +        String typeName = cd.StringValue(type);
  543.98 +        visitAnnotationStart(typeName, top);
  543.99 +    	int cnt = dis.readUnsignedShort();
 543.100 +    	for (int i = 0; i < cnt; i++) {
 543.101 +            String attrName = cd.StringValue(dis.readUnsignedShort());
 543.102 +            readValue(dis, cd, typeName, attrName);
 543.103 +        }
 543.104 +        visitAnnotationEnd(typeName, top);
 543.105 +        if (cnt == 0) {
 543.106 +            visitAttr(typeName, null, null, null);
 543.107 +        }
 543.108 +    }
 543.109 +
 543.110 +    private void readValue(
 543.111 +        DataInputStream dis, ClassData cd, String typeName, String attrName
 543.112 +    ) throws IOException {
 543.113 +        char type = (char)dis.readByte();
 543.114 +        visitValueStart(attrName, type);
 543.115 +        if (type == '@') {
 543.116 +            readAnno(dis, cd, false);
 543.117 +        } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
 543.118 +            int primitive = dis.readUnsignedShort();
 543.119 +            String val = cd.stringValue(primitive, textual);
 543.120 +            String attrType;
 543.121 +            if (type == 's') {
 543.122 +                attrType = "Ljava_lang_String_2";
 543.123 +                if (textual) {
 543.124 +                    val = '"' + val + '"';
 543.125 +                }
 543.126 +            } else {
 543.127 +                attrType = "" + type;
 543.128 +            }
 543.129 +            visitAttr(typeName, attrName, attrType, val);
 543.130 +        } else if (type == 'c') {
 543.131 +            int cls = dis.readUnsignedShort();
 543.132 +        } else if (type == '[') {
 543.133 +            int cnt = dis.readUnsignedShort();
 543.134 +            for (int i = 0; i < cnt; i++) {
 543.135 +                readValue(dis, cd, typeName, iterateArray ? attrName : null);
 543.136 +            }
 543.137 +        } else if (type == 'e') {
 543.138 +            int enumT = dis.readUnsignedShort();
 543.139 +            String attrType = cd.stringValue(enumT, textual);
 543.140 +            int enumN = dis.readUnsignedShort();
 543.141 +            String val = cd.stringValue(enumN, textual);
 543.142 +            visitEnumAttr(typeName, attrName, attrType, val);
 543.143 +        } else {
 543.144 +            throw new IOException("Unknown type " + type);
 543.145 +        }
 543.146 +        visitValueEnd(attrName, type);
 543.147 +    }
 543.148 +}
   544.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   544.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/AttrData.java	Wed Feb 27 11:24:58 2013 +0100
   544.3 @@ -0,0 +1,77 @@
   544.4 +/*
   544.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   544.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   544.7 + *
   544.8 + * This code is free software; you can redistribute it and/or modify it
   544.9 + * under the terms of the GNU General Public License version 2 only, as
  544.10 + * published by the Free Software Foundation.  Oracle designates this
  544.11 + * particular file as subject to the "Classpath" exception as provided
  544.12 + * by Oracle in the LICENSE file that accompanied this code.
  544.13 + *
  544.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  544.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  544.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  544.17 + * version 2 for more details (a copy is included in the LICENSE file that
  544.18 + * accompanied this code).
  544.19 + *
  544.20 + * You should have received a copy of the GNU General Public License version
  544.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  544.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  544.23 + *
  544.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  544.25 + * or visit www.oracle.com if you need additional information or have any
  544.26 + * questions.
  544.27 + */
  544.28 +
  544.29 +
  544.30 +
  544.31 +package org.apidesign.javap;
  544.32 +
  544.33 +import java.io.*;
  544.34 +
  544.35 +/**
  544.36 + * Reads and stores attribute information.
  544.37 + *
  544.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  544.39 + */
  544.40 +class AttrData {
  544.41 +    ClassData cls;
  544.42 +    int name_cpx;
  544.43 +    int datalen;
  544.44 +    byte data[];
  544.45 +
  544.46 +    public AttrData (ClassData cls) {
  544.47 +        this.cls=cls;
  544.48 +    }
  544.49 +
  544.50 +    /**
  544.51 +     * Reads unknown attribute.
  544.52 +     */
  544.53 +    public void read(int name_cpx, DataInputStream in) throws IOException {
  544.54 +        this.name_cpx=name_cpx;
  544.55 +        datalen=in.readInt();
  544.56 +        data=new byte[datalen];
  544.57 +        in.readFully(data);
  544.58 +    }
  544.59 +
  544.60 +    /**
  544.61 +     * Reads just the name of known attribute.
  544.62 +     */
  544.63 +    public void read(int name_cpx){
  544.64 +        this.name_cpx=name_cpx;
  544.65 +    }
  544.66 +
  544.67 +    /**
  544.68 +     * Returns attribute name.
  544.69 +     */
  544.70 +    public String getAttrName(){
  544.71 +        return cls.getString(name_cpx);
  544.72 +    }
  544.73 +
  544.74 +    /**
  544.75 +     * Returns attribute data.
  544.76 +     */
  544.77 +    public byte[] getData(){
  544.78 +        return data;
  544.79 +    }
  544.80 +}
   545.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   545.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/CPX.java	Wed Feb 27 11:24:58 2013 +0100
   545.3 @@ -0,0 +1,40 @@
   545.4 +/*
   545.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   545.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   545.7 + *
   545.8 + * This code is free software; you can redistribute it and/or modify it
   545.9 + * under the terms of the GNU General Public License version 2 only, as
  545.10 + * published by the Free Software Foundation.  Oracle designates this
  545.11 + * particular file as subject to the "Classpath" exception as provided
  545.12 + * by Oracle in the LICENSE file that accompanied this code.
  545.13 + *
  545.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  545.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  545.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  545.17 + * version 2 for more details (a copy is included in the LICENSE file that
  545.18 + * accompanied this code).
  545.19 + *
  545.20 + * You should have received a copy of the GNU General Public License version
  545.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  545.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  545.23 + *
  545.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  545.25 + * or visit www.oracle.com if you need additional information or have any
  545.26 + * questions.
  545.27 + */
  545.28 +
  545.29 +
  545.30 +package org.apidesign.javap;
  545.31 +
  545.32 +/**
  545.33 + * Stores constant pool entry information with one field.
  545.34 + *
  545.35 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  545.36 + */
  545.37 +class CPX {
  545.38 +    int cpx;
  545.39 +
  545.40 +    CPX (int cpx) {
  545.41 +        this.cpx=cpx;
  545.42 +    }
  545.43 +}
   546.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   546.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/CPX2.java	Wed Feb 27 11:24:58 2013 +0100
   546.3 @@ -0,0 +1,41 @@
   546.4 +/*
   546.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   546.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   546.7 + *
   546.8 + * This code is free software; you can redistribute it and/or modify it
   546.9 + * under the terms of the GNU General Public License version 2 only, as
  546.10 + * published by the Free Software Foundation.  Oracle designates this
  546.11 + * particular file as subject to the "Classpath" exception as provided
  546.12 + * by Oracle in the LICENSE file that accompanied this code.
  546.13 + *
  546.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  546.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  546.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  546.17 + * version 2 for more details (a copy is included in the LICENSE file that
  546.18 + * accompanied this code).
  546.19 + *
  546.20 + * You should have received a copy of the GNU General Public License version
  546.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  546.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  546.23 + *
  546.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  546.25 + * or visit www.oracle.com if you need additional information or have any
  546.26 + * questions.
  546.27 + */
  546.28 +
  546.29 +
  546.30 +package org.apidesign.javap;
  546.31 +
  546.32 +/**
  546.33 + *  Stores constant pool entry information with two fields.
  546.34 + *
  546.35 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  546.36 + */
  546.37 +class CPX2 {
  546.38 +    int cpx1,cpx2;
  546.39 +
  546.40 +    CPX2 (int cpx1, int cpx2) {
  546.41 +        this.cpx1=cpx1;
  546.42 +        this.cpx2=cpx2;
  546.43 +    }
  546.44 +}
   547.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   547.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/ClassData.java	Wed Feb 27 11:24:58 2013 +0100
   547.3 @@ -0,0 +1,713 @@
   547.4 +/*
   547.5 + * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
   547.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   547.7 + *
   547.8 + * This code is free software; you can redistribute it and/or modify it
   547.9 + * under the terms of the GNU General Public License version 2 only, as
  547.10 + * published by the Free Software Foundation.  Oracle designates this
  547.11 + * particular file as subject to the "Classpath" exception as provided
  547.12 + * by Oracle in the LICENSE file that accompanied this code.
  547.13 + *
  547.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  547.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  547.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  547.17 + * version 2 for more details (a copy is included in the LICENSE file that
  547.18 + * accompanied this code).
  547.19 + *
  547.20 + * You should have received a copy of the GNU General Public License version
  547.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  547.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  547.23 + *
  547.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  547.25 + * or visit www.oracle.com if you need additional information or have any
  547.26 + * questions.
  547.27 + */
  547.28 +
  547.29 +
  547.30 +package org.apidesign.javap;
  547.31 +
  547.32 +import java.io.*;
  547.33 +
  547.34 +/**
  547.35 + * Central data repository of the Java Disassembler.
  547.36 + * Stores all the information in java class file.
  547.37 + *
  547.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  547.39 + */
  547.40 +public final class ClassData implements RuntimeConstants {
  547.41 +
  547.42 +    private int magic;
  547.43 +    private int minor_version;
  547.44 +    private int major_version;
  547.45 +    private int cpool_count;
  547.46 +    private Object cpool[];
  547.47 +    private int access;
  547.48 +    private int this_class = 0;;
  547.49 +    private int super_class;
  547.50 +    private int interfaces_count;
  547.51 +    private int[] interfaces = new int[0];;
  547.52 +    private int fields_count;
  547.53 +    private FieldData[] fields;
  547.54 +    private int methods_count;
  547.55 +    private MethodData[] methods;
  547.56 +    private InnerClassData[] innerClasses;
  547.57 +    private int attributes_count;
  547.58 +    private AttrData[] attrs;
  547.59 +    private String classname;
  547.60 +    private String superclassname;
  547.61 +    private int source_cpx=0;
  547.62 +    private byte tags[];
  547.63 +    private Hashtable indexHashAscii = new Hashtable();
  547.64 +    private String pkgPrefix="";
  547.65 +    private int pkgPrefixLen=0;
  547.66 +
  547.67 +    /**
  547.68 +     * Read classfile to disassemble.
  547.69 +     */
  547.70 +    public ClassData(InputStream infile) throws IOException {
  547.71 +        this.read(new DataInputStream(infile));
  547.72 +    }
  547.73 +
  547.74 +    /**
  547.75 +     * Reads and stores class file information.
  547.76 +     */
  547.77 +    public void read(DataInputStream in) throws IOException {
  547.78 +        // Read the header
  547.79 +        magic = in.readInt();
  547.80 +        if (magic != JAVA_MAGIC) {
  547.81 +            throw new ClassFormatError("wrong magic: " +
  547.82 +                                       toHex(magic) + ", expected " +
  547.83 +                                       toHex(JAVA_MAGIC));
  547.84 +        }
  547.85 +        minor_version = in.readShort();
  547.86 +        major_version = in.readShort();
  547.87 +        if (major_version != JAVA_VERSION) {
  547.88 +        }
  547.89 +
  547.90 +        // Read the constant pool
  547.91 +        readCP(in);
  547.92 +        access = in.readUnsignedShort();
  547.93 +        this_class = in.readUnsignedShort();
  547.94 +        super_class = in.readUnsignedShort();
  547.95 +
  547.96 +        //Read interfaces.
  547.97 +        interfaces_count = in.readUnsignedShort();
  547.98 +        if(interfaces_count > 0){
  547.99 +            interfaces = new int[interfaces_count];
 547.100 +        }
 547.101 +        for (int i = 0; i < interfaces_count; i++) {
 547.102 +            interfaces[i]=in.readShort();
 547.103 +        }
 547.104 +
 547.105 +        // Read the fields
 547.106 +        readFields(in);
 547.107 +
 547.108 +        // Read the methods
 547.109 +        readMethods(in);
 547.110 +
 547.111 +        // Read the attributes
 547.112 +        attributes_count = in.readUnsignedShort();
 547.113 +        attrs=new AttrData[attributes_count];
 547.114 +        for (int k = 0; k < attributes_count; k++) {
 547.115 +            int name_cpx=in.readUnsignedShort();
 547.116 +            if (getTag(name_cpx)==CONSTANT_UTF8
 547.117 +                && getString(name_cpx).equals("SourceFile")
 547.118 +                ){      if (in.readInt()!=2)
 547.119 +                    throw new ClassFormatError("invalid attr length");
 547.120 +                source_cpx=in.readUnsignedShort();
 547.121 +                AttrData attr=new AttrData(this);
 547.122 +                attr.read(name_cpx);
 547.123 +                attrs[k]=attr;
 547.124 +
 547.125 +            } else if (getTag(name_cpx)==CONSTANT_UTF8
 547.126 +                       && getString(name_cpx).equals("InnerClasses")
 547.127 +                       ){       int length=in.readInt();
 547.128 +                       int num=in.readUnsignedShort();
 547.129 +                       if (2+num*8 != length)
 547.130 +                           throw new ClassFormatError("invalid attr length");
 547.131 +                       innerClasses=new InnerClassData[num];
 547.132 +                       for (int j = 0; j < num; j++) {
 547.133 +                           InnerClassData innerClass=new InnerClassData(this);
 547.134 +                           innerClass.read(in);
 547.135 +                           innerClasses[j]=innerClass;
 547.136 +                       }
 547.137 +                       AttrData attr=new AttrData(this);
 547.138 +                       attr.read(name_cpx);
 547.139 +                       attrs[k]=attr;
 547.140 +            } else {
 547.141 +                AttrData attr=new AttrData(this);
 547.142 +                attr.read(name_cpx, in);
 547.143 +                attrs[k]=attr;
 547.144 +            }
 547.145 +        }
 547.146 +        in.close();
 547.147 +    } // end ClassData.read()
 547.148 +
 547.149 +    /**
 547.150 +     * Reads and stores constant pool info.
 547.151 +     */
 547.152 +    void readCP(DataInputStream in) throws IOException {
 547.153 +        cpool_count = in.readUnsignedShort();
 547.154 +        tags = new byte[cpool_count];
 547.155 +        cpool = new Object[cpool_count];
 547.156 +        for (int i = 1; i < cpool_count; i++) {
 547.157 +            byte tag = in.readByte();
 547.158 +
 547.159 +            switch(tags[i] = tag) {
 547.160 +            case CONSTANT_UTF8:
 547.161 +                String str=in.readUTF();
 547.162 +                indexHashAscii.put(cpool[i] = str, new Integer(i));
 547.163 +                break;
 547.164 +            case CONSTANT_INTEGER:
 547.165 +                cpool[i] = new Integer(in.readInt());
 547.166 +                break;
 547.167 +            case CONSTANT_FLOAT:
 547.168 +                cpool[i] = new Float(in.readFloat());
 547.169 +                break;
 547.170 +            case CONSTANT_LONG:
 547.171 +                cpool[i++] = new Long(in.readLong());
 547.172 +                break;
 547.173 +            case CONSTANT_DOUBLE:
 547.174 +                cpool[i++] = new Double(in.readDouble());
 547.175 +                break;
 547.176 +            case CONSTANT_CLASS:
 547.177 +            case CONSTANT_STRING:
 547.178 +                cpool[i] = new CPX(in.readUnsignedShort());
 547.179 +                break;
 547.180 +
 547.181 +            case CONSTANT_FIELD:
 547.182 +            case CONSTANT_METHOD:
 547.183 +            case CONSTANT_INTERFACEMETHOD:
 547.184 +            case CONSTANT_NAMEANDTYPE:
 547.185 +                cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
 547.186 +                break;
 547.187 +
 547.188 +            case 0:
 547.189 +            default:
 547.190 +                throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
 547.191 +            }
 547.192 +        }
 547.193 +    }
 547.194 +
 547.195 +    /**
 547.196 +     * Reads and strores field info.
 547.197 +     */
 547.198 +    protected void readFields(DataInputStream in) throws IOException {
 547.199 +        int fields_count = in.readUnsignedShort();
 547.200 +        fields=new FieldData[fields_count];
 547.201 +        for (int k = 0; k < fields_count; k++) {
 547.202 +            FieldData field=new FieldData(this);
 547.203 +            field.read(in);
 547.204 +            fields[k]=field;
 547.205 +        }
 547.206 +    }
 547.207 +
 547.208 +    /**
 547.209 +     * Reads and strores Method info.
 547.210 +     */
 547.211 +    protected void readMethods(DataInputStream in) throws IOException {
 547.212 +        int methods_count = in.readUnsignedShort();
 547.213 +        methods=new MethodData[methods_count];
 547.214 +        for (int k = 0; k < methods_count ; k++) {
 547.215 +            MethodData method=new MethodData(this);
 547.216 +            method.read(in);
 547.217 +            methods[k]=method;
 547.218 +        }
 547.219 +    }
 547.220 +
 547.221 +    /**
 547.222 +     * get a string
 547.223 +     */
 547.224 +    public String getString(int n) {
 547.225 +        if (n == 0) {
 547.226 +            return null; 
 547.227 +        } else {
 547.228 +            return (String)cpool[n];
 547.229 +        }
 547.230 +    }
 547.231 +
 547.232 +    /**
 547.233 +     * get the type of constant given an index
 547.234 +     */
 547.235 +    public byte getTag(int n) {
 547.236 +        try{
 547.237 +            return tags[n];
 547.238 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.239 +            return (byte)100;
 547.240 +        }
 547.241 +    }
 547.242 +
 547.243 +    static final String hexString="0123456789ABCDEF";
 547.244 +
 547.245 +    public static char hexTable[]=hexString.toCharArray();
 547.246 +
 547.247 +    static String toHex(long val, int width) {
 547.248 +        StringBuffer s = new StringBuffer();
 547.249 +        for (int i=width-1; i>=0; i--)
 547.250 +            s.append(hexTable[((int)(val>>(4*i)))&0xF]);
 547.251 +        return "0x"+s.toString();
 547.252 +    }
 547.253 +
 547.254 +    static String toHex(long val) {
 547.255 +        int width;
 547.256 +        for (width=16; width>0; width--) {
 547.257 +            if ((val>>(width-1)*4)!=0) break;
 547.258 +        }
 547.259 +        return toHex(val, width);
 547.260 +    }
 547.261 +
 547.262 +    static String toHex(int val) {
 547.263 +        int width;
 547.264 +        for (width=8; width>0; width--) {
 547.265 +            if ((val>>(width-1)*4)!=0) break;
 547.266 +        }
 547.267 +        return toHex(val, width);
 547.268 +    }
 547.269 +
 547.270 +    /**
 547.271 +     * Returns the name of this class.
 547.272 +     */
 547.273 +    public String getClassName() {
 547.274 +        String res=null;
 547.275 +        if (this_class==0) {
 547.276 +            return res;
 547.277 +        }
 547.278 +        int tcpx;
 547.279 +        try {
 547.280 +            if (tags[this_class]!=CONSTANT_CLASS) {
 547.281 +                return res; //"<CP["+cpx+"] is not a Class> ";
 547.282 +            }
 547.283 +            tcpx=((CPX)cpool[this_class]).cpx;
 547.284 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.285 +            return res; // "#"+cpx+"// invalid constant pool index";
 547.286 +        } catch (Throwable e) {
 547.287 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 547.288 +        }
 547.289 +
 547.290 +        try {
 547.291 +            return (String)(cpool[tcpx]);
 547.292 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.293 +            return  res; // "class #"+scpx+"// invalid constant pool index";
 547.294 +        } catch (ClassCastException e) {
 547.295 +            return  res; // "class #"+scpx+"// invalid constant pool reference";
 547.296 +        } catch (Throwable e) {
 547.297 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 547.298 +        }
 547.299 +
 547.300 +    }
 547.301 +
 547.302 +    /**
 547.303 +     * Returns the name of class at perticular index.
 547.304 +     */
 547.305 +    public String getClassName(int cpx) {
 547.306 +        String res="#"+cpx;
 547.307 +        if (cpx==0) {
 547.308 +            return res;
 547.309 +        }
 547.310 +        int scpx;
 547.311 +        try {
 547.312 +            if (tags[cpx]!=CONSTANT_CLASS) {
 547.313 +                return res; //"<CP["+cpx+"] is not a Class> ";
 547.314 +            }
 547.315 +            scpx=((CPX)cpool[cpx]).cpx;
 547.316 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.317 +            return res; // "#"+cpx+"// invalid constant pool index";
 547.318 +        } catch (Throwable e) {
 547.319 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 547.320 +        }
 547.321 +        res="#"+scpx;
 547.322 +        try {
 547.323 +            return (String)(cpool[scpx]);
 547.324 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.325 +            return  res; // "class #"+scpx+"// invalid constant pool index";
 547.326 +        } catch (ClassCastException e) {
 547.327 +            return  res; // "class #"+scpx+"// invalid constant pool reference";
 547.328 +        } catch (Throwable e) {
 547.329 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 547.330 +        }
 547.331 +    }
 547.332 +    
 547.333 +    public int getAccessFlags() {
 547.334 +        return access;
 547.335 +    }
 547.336 +
 547.337 +    /**
 547.338 +     * Returns true if it is a class
 547.339 +     */
 547.340 +    public boolean isClass() {
 547.341 +        if((access & ACC_INTERFACE) == 0) return true;
 547.342 +        return false;
 547.343 +    }
 547.344 +
 547.345 +    /**
 547.346 +     * Returns true if it is a interface.
 547.347 +     */
 547.348 +    public boolean isInterface(){
 547.349 +        if((access & ACC_INTERFACE) != 0) return true;
 547.350 +        return false;
 547.351 +    }
 547.352 +
 547.353 +    /**
 547.354 +     * Returns true if this member is public, false otherwise.
 547.355 +     */
 547.356 +    public boolean isPublic(){
 547.357 +        return (access & ACC_PUBLIC) != 0;
 547.358 +    }
 547.359 +
 547.360 +    /**
 547.361 +     * Returns the access of this class or interface.
 547.362 +     */
 547.363 +    public String[] getAccess(){
 547.364 +        Vector v = new Vector();
 547.365 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
 547.366 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
 547.367 +        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
 547.368 +        String[] accflags = new String[v.size()];
 547.369 +        v.copyInto(accflags);
 547.370 +        return accflags;
 547.371 +    }
 547.372 +
 547.373 +    /**
 547.374 +     * Returns list of innerclasses.
 547.375 +     */
 547.376 +    public InnerClassData[] getInnerClasses(){
 547.377 +        return innerClasses;
 547.378 +    }
 547.379 +
 547.380 +    /**
 547.381 +     * Returns list of attributes.
 547.382 +     */
 547.383 +    final AttrData[] getAttributes(){
 547.384 +        return attrs;
 547.385 +    }
 547.386 +    
 547.387 +    public byte[] findAnnotationData(boolean classRetention) {
 547.388 +        String n = classRetention ?
 547.389 +            "RuntimeInvisibleAnnotations" : // NOI18N
 547.390 +            "RuntimeVisibleAnnotations"; // NOI18N
 547.391 +        return findAttr(n, attrs);
 547.392 +    }
 547.393 +
 547.394 +    /**
 547.395 +     * Returns true if superbit is set.
 547.396 +     */
 547.397 +    public boolean isSuperSet(){
 547.398 +        if ((access & ACC_SUPER)   !=0) return true;
 547.399 +        return false;
 547.400 +    }
 547.401 +
 547.402 +    /**
 547.403 +     * Returns super class name.
 547.404 +     */
 547.405 +    public String getSuperClassName(){
 547.406 +        String res=null;
 547.407 +        if (super_class==0) {
 547.408 +            return res;
 547.409 +        }
 547.410 +        int scpx;
 547.411 +        try {
 547.412 +            if (tags[super_class]!=CONSTANT_CLASS) {
 547.413 +                return res; //"<CP["+cpx+"] is not a Class> ";
 547.414 +            }
 547.415 +            scpx=((CPX)cpool[super_class]).cpx;
 547.416 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.417 +            return res; // "#"+cpx+"// invalid constant pool index";
 547.418 +        } catch (Throwable e) {
 547.419 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 547.420 +        }
 547.421 +
 547.422 +        try {
 547.423 +            return (String)(cpool[scpx]);
 547.424 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.425 +            return  res; // "class #"+scpx+"// invalid constant pool index";
 547.426 +        } catch (ClassCastException e) {
 547.427 +            return  res; // "class #"+scpx+"// invalid constant pool reference";
 547.428 +        } catch (Throwable e) {
 547.429 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
 547.430 +        }
 547.431 +    }
 547.432 +
 547.433 +    /**
 547.434 +     * Returns list of super interfaces.
 547.435 +     */
 547.436 +    public String[] getSuperInterfaces(){
 547.437 +        String interfacenames[] = new String[interfaces.length];
 547.438 +        int interfacecpx = -1;
 547.439 +        for(int i = 0; i < interfaces.length; i++){
 547.440 +            interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
 547.441 +            interfacenames[i] = (String)(cpool[interfacecpx]);
 547.442 +        }
 547.443 +        return interfacenames;
 547.444 +    }
 547.445 +
 547.446 +    /**
 547.447 +     * Returns string at prticular constant pool index.
 547.448 +     */
 547.449 +    public String getStringValue(int cpoolx) {
 547.450 +        try {
 547.451 +            return ((String)cpool[cpoolx]);
 547.452 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.453 +            return "//invalid constant pool index:"+cpoolx;
 547.454 +        } catch (ClassCastException e) {
 547.455 +            return "//invalid constant pool ref:"+cpoolx;
 547.456 +        }
 547.457 +    }
 547.458 +
 547.459 +    /**
 547.460 +     * Returns list of field info.
 547.461 +     */
 547.462 +    public  FieldData[] getFields(){
 547.463 +        return fields;
 547.464 +    }
 547.465 +
 547.466 +    /**
 547.467 +     * Returns list of method info.
 547.468 +     */
 547.469 +    public  MethodData[] getMethods(){
 547.470 +        return methods;
 547.471 +    }
 547.472 +
 547.473 +    /**
 547.474 +     * Returns constant pool entry at that index.
 547.475 +     */
 547.476 +    public CPX2 getCpoolEntry(int cpx){
 547.477 +        return ((CPX2)(cpool[cpx]));
 547.478 +    }
 547.479 +
 547.480 +    public Object getCpoolEntryobj(int cpx){
 547.481 +        return (cpool[cpx]);
 547.482 +    }
 547.483 +
 547.484 +    /**
 547.485 +     * Returns index of this class.
 547.486 +     */
 547.487 +    public int getthis_cpx(){
 547.488 +        return this_class;
 547.489 +    }
 547.490 +
 547.491 +    /**
 547.492 +     * Returns string at that index.
 547.493 +     */
 547.494 +    public String StringValue(int cpx) {
 547.495 +        return stringValue(cpx, false);
 547.496 +    }
 547.497 +    public String stringValue(int cpx, boolean textual) {
 547.498 +        return stringValue(cpx, textual, null);
 547.499 +    }
 547.500 +    public String stringValue(int cpx, String[] classRefs) {
 547.501 +        return stringValue(cpx, true, classRefs);
 547.502 +    }
 547.503 +    private String stringValue(int cpx, boolean textual, String[] refs) {
 547.504 +        if (cpx==0) return "#0";
 547.505 +        int tag;
 547.506 +        Object x;
 547.507 +        String suffix="";
 547.508 +        try {
 547.509 +            tag=tags[cpx];
 547.510 +            x=cpool[cpx];
 547.511 +        } catch (IndexOutOfBoundsException e) {
 547.512 +            return "<Incorrect CP index:"+cpx+">";
 547.513 +        }
 547.514 +
 547.515 +        if (x==null) return "<NULL>";
 547.516 +        switch (tag) {
 547.517 +        case CONSTANT_UTF8: {
 547.518 +            if (!textual) {
 547.519 +                return (String)x;
 547.520 +            }
 547.521 +            StringBuilder sb=new StringBuilder();
 547.522 +            String s=(String)x;
 547.523 +            for (int k=0; k<s.length(); k++) {
 547.524 +                char c=s.charAt(k);
 547.525 +                switch (c) {
 547.526 +                case '\\': sb.append('\\').append('\\'); break;
 547.527 +                case '\t': sb.append('\\').append('t'); break;
 547.528 +                case '\n': sb.append('\\').append('n'); break;
 547.529 +                case '\r': sb.append('\\').append('r'); break;
 547.530 +                case '\"': sb.append('\\').append('\"'); break;
 547.531 +                default: sb.append(c);
 547.532 +                }
 547.533 +            }
 547.534 +            return sb.toString();
 547.535 +        }
 547.536 +        case CONSTANT_DOUBLE: {
 547.537 +            Double d=(Double)x;
 547.538 +            String sd=d.toString();
 547.539 +            if (textual) {
 547.540 +                return sd;
 547.541 +            }
 547.542 +            return sd+"d";
 547.543 +        }
 547.544 +        case CONSTANT_FLOAT: {
 547.545 +            Float f=(Float)x;
 547.546 +            String sf=(f).toString();
 547.547 +            if (textual) {
 547.548 +                return sf;
 547.549 +            }
 547.550 +            return sf+"f";
 547.551 +        }
 547.552 +        case CONSTANT_LONG: {
 547.553 +            Long ln = (Long)x;
 547.554 +            if (textual) {
 547.555 +                return ln.toString();
 547.556 +            }
 547.557 +            return ln.toString()+'l';
 547.558 +        }
 547.559 +        case CONSTANT_INTEGER: {
 547.560 +            Integer in = (Integer)x;
 547.561 +            return in.toString();
 547.562 +        }
 547.563 +        case CONSTANT_CLASS:
 547.564 +            String jn = getClassName(cpx);
 547.565 +            if (textual) {
 547.566 +                if (refs != null) {
 547.567 +                    refs[0] = jn;
 547.568 +                }
 547.569 +                return jn;
 547.570 +            }
 547.571 +            return javaName(jn);
 547.572 +        case CONSTANT_STRING:
 547.573 +            String sv = stringValue(((CPX)x).cpx, textual);
 547.574 +            if (textual) {
 547.575 +                return '"' + sv + '"';
 547.576 +            } else {
 547.577 +                return sv;
 547.578 +            }
 547.579 +        case CONSTANT_FIELD:
 547.580 +        case CONSTANT_METHOD:
 547.581 +        case CONSTANT_INTERFACEMETHOD:
 547.582 +            //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
 547.583 +             return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
 547.584 +
 547.585 +        case CONSTANT_NAMEANDTYPE:
 547.586 +            return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
 547.587 +        default:
 547.588 +            return "UnknownTag"; //TBD
 547.589 +        }
 547.590 +    }
 547.591 +
 547.592 +    /**
 547.593 +     * Returns resolved java type name.
 547.594 +     */
 547.595 +    public String javaName(String name) {
 547.596 +        if( name==null) return "null";
 547.597 +        int len=name.length();
 547.598 +        if (len==0) return "\"\"";
 547.599 +        int cc='/';
 547.600 +    fullname: { // xxx/yyy/zzz
 547.601 +            int cp;
 547.602 +            for (int k=0; k<len; k += Character.charCount(cp)) {
 547.603 +                cp=name.codePointAt(k);
 547.604 +                if (cc=='/') {
 547.605 +                    if (!isJavaIdentifierStart(cp)) break fullname;
 547.606 +                } else if (cp!='/') {
 547.607 +                    if (!isJavaIdentifierPart(cp)) break fullname;
 547.608 +                }
 547.609 +                cc=cp;
 547.610 +            }
 547.611 +            return name;
 547.612 +        }
 547.613 +        return "\""+name+"\"";
 547.614 +    }
 547.615 +
 547.616 +    public String getName(int cpx) {
 547.617 +        String res;
 547.618 +        try {
 547.619 +            return javaName((String)cpool[cpx]); //.replace('/','.');
 547.620 +        } catch (ArrayIndexOutOfBoundsException e) {
 547.621 +            return "<invalid constant pool index:"+cpx+">";
 547.622 +        } catch (ClassCastException e) {
 547.623 +            return "<invalid constant pool ref:"+cpx+">";
 547.624 +        }
 547.625 +    }
 547.626 +
 547.627 +    /**
 547.628 +     * Returns unqualified class name.
 547.629 +     */
 547.630 +    public String getShortClassName(int cpx) {
 547.631 +        String classname=javaName(getClassName(cpx));
 547.632 +        pkgPrefixLen=classname.lastIndexOf("/")+1;
 547.633 +        if (pkgPrefixLen!=0) {
 547.634 +            pkgPrefix=classname.substring(0,pkgPrefixLen);
 547.635 +            if (classname.startsWith(pkgPrefix)) {
 547.636 +                return classname.substring(pkgPrefixLen);
 547.637 +            }
 547.638 +        }
 547.639 +        return classname;
 547.640 +    }
 547.641 +
 547.642 +    /**
 547.643 +     * Returns source file name.
 547.644 +     */
 547.645 +    public String getSourceName(){
 547.646 +        return getName(source_cpx);
 547.647 +    }
 547.648 +
 547.649 +    /**
 547.650 +     * Returns package name.
 547.651 +     */
 547.652 +    public String getPkgName(){
 547.653 +        String classname=getClassName(this_class);
 547.654 +        pkgPrefixLen=classname.lastIndexOf("/")+1;
 547.655 +        if (pkgPrefixLen!=0) {
 547.656 +            pkgPrefix=classname.substring(0,pkgPrefixLen);
 547.657 +            return("package  "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
 547.658 +        }else return null;
 547.659 +    }
 547.660 +
 547.661 +    /**
 547.662 +     * Returns total constant pool entry count.
 547.663 +     */
 547.664 +    public int getCpoolCount(){
 547.665 +        return cpool_count;
 547.666 +    }
 547.667 +
 547.668 +    /**
 547.669 +     * Returns minor version of class file.
 547.670 +     */
 547.671 +    public int getMinor_version(){
 547.672 +        return minor_version;
 547.673 +    }
 547.674 +
 547.675 +    /**
 547.676 +     * Returns major version of class file.
 547.677 +     */
 547.678 +    public int getMajor_version(){
 547.679 +        return major_version;
 547.680 +    }
 547.681 +
 547.682 +    private boolean isJavaIdentifierStart(int cp) {
 547.683 +        return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');
 547.684 +    }
 547.685 +
 547.686 +    private boolean isJavaIdentifierPart(int cp) {
 547.687 +        return isJavaIdentifierStart(cp) || ('0' <= cp && cp <= '9');
 547.688 +    }
 547.689 +
 547.690 +    public String[] getNameAndType(int indx) {
 547.691 +        return getNameAndType(indx, 0, new String[2]);
 547.692 +    }
 547.693 +    
 547.694 +    private String[] getNameAndType(int indx, int at, String[] arr) {
 547.695 +        CPX2 c2 = getCpoolEntry(indx);
 547.696 +        arr[at] = StringValue(c2.cpx1);
 547.697 +        arr[at + 1] = StringValue(c2.cpx2);
 547.698 +        return arr;
 547.699 +    }
 547.700 +
 547.701 +    public String[] getFieldInfoName(int indx) {
 547.702 +        CPX2 c2 = getCpoolEntry(indx);
 547.703 +        String[] arr = new String[3];
 547.704 +        arr[0] = getClassName(c2.cpx1);
 547.705 +        return getNameAndType(c2.cpx2, 1, arr);
 547.706 +    }
 547.707 +
 547.708 +    static byte[] findAttr(String n, AttrData[] attrs) {
 547.709 +        for (AttrData ad : attrs) {
 547.710 +            if (n.equals(ad.getAttrName())) {
 547.711 +                return ad.getData();
 547.712 +            }
 547.713 +        }
 547.714 +        return null;
 547.715 +    }
 547.716 +}
   548.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   548.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/Constants.java	Wed Feb 27 11:24:58 2013 +0100
   548.3 @@ -0,0 +1,372 @@
   548.4 +/*
   548.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   548.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   548.7 + *
   548.8 + * This code is free software; you can redistribute it and/or modify it
   548.9 + * under the terms of the GNU General Public License version 2 only, as
  548.10 + * published by the Free Software Foundation.  Oracle designates this
  548.11 + * particular file as subject to the "Classpath" exception as provided
  548.12 + * by Oracle in the LICENSE file that accompanied this code.
  548.13 + *
  548.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  548.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  548.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  548.17 + * version 2 for more details (a copy is included in the LICENSE file that
  548.18 + * accompanied this code).
  548.19 + *
  548.20 + * You should have received a copy of the GNU General Public License version
  548.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  548.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  548.23 + *
  548.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  548.25 + * or visit www.oracle.com if you need additional information or have any
  548.26 + * questions.
  548.27 + */
  548.28 +
  548.29 +
  548.30 +
  548.31 +package org.apidesign.javap;
  548.32 +
  548.33 +/**
  548.34 + * This interface defines constant that are used
  548.35 + * throughout the compiler. It inherits from RuntimeConstants,
  548.36 + * which is an autogenerated class that contains contstants
  548.37 + * defined in the interpreter.
  548.38 + */
  548.39 +
  548.40 +public
  548.41 +interface Constants extends RuntimeConstants {
  548.42 +
  548.43 +     /**
  548.44 +     * End of input
  548.45 +     */
  548.46 +    public static final int EOF = -1;
  548.47 +
  548.48 +   /*
  548.49 +     * Flags
  548.50 +     */
  548.51 +    public static final int F_VERBOSE           = 1 << 0;
  548.52 +    public static final int F_DUMP              = 1 << 1;
  548.53 +    public static final int F_WARNINGS          = 1 << 2;
  548.54 +    public static final int F_DEBUG             = 1 << 3;
  548.55 +    public static final int F_OPTIMIZE          = 1 << 4;
  548.56 +    public static final int F_DEPENDENCIES      = 1 << 5;
  548.57 +
  548.58 +    /*
  548.59 +     * Type codes
  548.60 +     */
  548.61 +    public static final int TC_BOOLEAN   = 0;
  548.62 +    public static final int TC_BYTE      = 1;
  548.63 +    public static final int TC_CHAR      = 2;
  548.64 +    public static final int TC_SHORT     = 3;
  548.65 +    public static final int TC_INT       = 4;
  548.66 +    public static final int TC_LONG      = 5;
  548.67 +    public static final int TC_FLOAT     = 6;
  548.68 +    public static final int TC_DOUBLE    = 7;
  548.69 +    public static final int TC_NULL      = 8;
  548.70 +    public static final int TC_ARRAY     = 9;
  548.71 +    public static final int TC_CLASS     = 10;
  548.72 +    public static final int TC_VOID      = 11;
  548.73 +    public static final int TC_METHOD    = 12;
  548.74 +    public static final int TC_ERROR     = 13;
  548.75 +
  548.76 +    /*
  548.77 +     * Type Masks
  548.78 +     */
  548.79 +    public static final int TM_NULL      = 1 << TC_NULL;
  548.80 +    public static final int TM_VOID      = 1 << TC_VOID;
  548.81 +    public static final int TM_BOOLEAN   = 1 << TC_BOOLEAN;
  548.82 +    public static final int TM_BYTE      = 1 << TC_BYTE;
  548.83 +    public static final int TM_CHAR      = 1 << TC_CHAR;
  548.84 +    public static final int TM_SHORT     = 1 << TC_SHORT;
  548.85 +    public static final int TM_INT       = 1 << TC_INT;
  548.86 +    public static final int TM_LONG      = 1 << TC_LONG;
  548.87 +    public static final int TM_FLOAT     = 1 << TC_FLOAT;
  548.88 +    public static final int TM_DOUBLE    = 1 << TC_DOUBLE;
  548.89 +    public static final int TM_ARRAY     = 1 << TC_ARRAY;
  548.90 +    public static final int TM_CLASS     = 1 << TC_CLASS;
  548.91 +    public static final int TM_METHOD    = 1 << TC_METHOD;
  548.92 +    public static final int TM_ERROR     = 1 << TC_ERROR;
  548.93 +
  548.94 +    public static final int TM_INT32     = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
  548.95 +    public static final int TM_NUM32     = TM_INT32 | TM_FLOAT;
  548.96 +    public static final int TM_NUM64     = TM_LONG | TM_DOUBLE;
  548.97 +    public static final int TM_INTEGER   = TM_INT32 | TM_LONG;
  548.98 +    public static final int TM_REAL      = TM_FLOAT | TM_DOUBLE;
  548.99 +    public static final int TM_NUMBER    = TM_INTEGER | TM_REAL;
 548.100 +    public static final int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;
 548.101 +
 548.102 +    /*
 548.103 +     * Class status
 548.104 +     */
 548.105 +    public static final int CS_UNDEFINED        = 0;
 548.106 +    public static final int CS_UNDECIDED        = 1;
 548.107 +    public static final int CS_BINARY           = 2;
 548.108 +    public static final int CS_SOURCE           = 3;
 548.109 +    public static final int CS_PARSED           = 4;
 548.110 +    public static final int CS_COMPILED         = 5;
 548.111 +    public static final int CS_NOTFOUND         = 6;
 548.112 +
 548.113 +    /*
 548.114 +     * Attributes
 548.115 +     */
 548.116 +    public static final int ATT_ALL             = -1;
 548.117 +    public static final int ATT_CODE            = 1;
 548.118 +
 548.119 +    /*
 548.120 +     * Number of bits used in file offsets
 548.121 +     */
 548.122 +    public static final int OFFSETBITS          = 19;
 548.123 +    public static final int MAXFILESIZE         = (1 << OFFSETBITS) - 1;
 548.124 +    public static final int MAXLINENUMBER       = (1 << (32 - OFFSETBITS)) - 1;
 548.125 +
 548.126 +    /*
 548.127 +     * Operators
 548.128 +     */
 548.129 +    public final int COMMA              = 0;
 548.130 +    public final int ASSIGN             = 1;
 548.131 +
 548.132 +    public final int ASGMUL             = 2;
 548.133 +    public final int ASGDIV             = 3;
 548.134 +    public final int ASGREM             = 4;
 548.135 +    public final int ASGADD             = 5;
 548.136 +    public final int ASGSUB             = 6;
 548.137 +    public final int ASGLSHIFT          = 7;
 548.138 +    public final int ASGRSHIFT          = 8;
 548.139 +    public final int ASGURSHIFT         = 9;
 548.140 +    public final int ASGBITAND          = 10;
 548.141 +    public final int ASGBITOR           = 11;
 548.142 +    public final int ASGBITXOR          = 12;
 548.143 +
 548.144 +    public final int COND               = 13;
 548.145 +    public final int OR                 = 14;
 548.146 +    public final int AND                = 15;
 548.147 +    public final int BITOR              = 16;
 548.148 +    public final int BITXOR             = 17;
 548.149 +    public final int BITAND             = 18;
 548.150 +    public final int NE                 = 19;
 548.151 +    public final int EQ                 = 20;
 548.152 +    public final int GE                 = 21;
 548.153 +    public final int GT                 = 22;
 548.154 +    public final int LE                 = 23;
 548.155 +    public final int LT                 = 24;
 548.156 +    public final int INSTANCEOF         = 25;
 548.157 +    public final int LSHIFT             = 26;
 548.158 +    public final int RSHIFT             = 27;
 548.159 +    public final int URSHIFT            = 28;
 548.160 +    public final int ADD                = 29;
 548.161 +    public final int SUB                = 30;
 548.162 +    public final int DIV                = 31;
 548.163 +    public final int REM                = 32;
 548.164 +    public final int MUL                = 33;
 548.165 +    public final int CAST               = 34;           // (x)y
 548.166 +    public final int POS                = 35;           // +x
 548.167 +    public final int NEG                = 36;           // -x
 548.168 +    public final int NOT                = 37;
 548.169 +    public final int BITNOT             = 38;
 548.170 +    public final int PREINC             = 39;           // ++x
 548.171 +    public final int PREDEC             = 40;           // --x
 548.172 +    public final int NEWARRAY           = 41;
 548.173 +    public final int NEWINSTANCE        = 42;
 548.174 +    public final int NEWFROMNAME        = 43;
 548.175 +    public final int POSTINC            = 44;           // x++
 548.176 +    public final int POSTDEC            = 45;           // x--
 548.177 +    public final int FIELD              = 46;
 548.178 +    public final int METHOD             = 47;           // x(y)
 548.179 +    public final int ARRAYACCESS        = 48;           // x[y]
 548.180 +    public final int NEW                = 49;
 548.181 +    public final int INC                = 50;
 548.182 +    public final int DEC                = 51;
 548.183 +
 548.184 +    public final int CONVERT            = 55;           // implicit conversion
 548.185 +    public final int EXPR               = 56;           // (x)
 548.186 +    public final int ARRAY              = 57;           // {x, y, ...}
 548.187 +    public final int GOTO               = 58;
 548.188 +
 548.189 +    /*
 548.190 +     * Value tokens
 548.191 +     */
 548.192 +    public final int IDENT              = 60;
 548.193 +    public final int BOOLEANVAL         = 61;
 548.194 +    public final int BYTEVAL            = 62;
 548.195 +    public final int CHARVAL            = 63;
 548.196 +    public final int SHORTVAL           = 64;
 548.197 +    public final int INTVAL                     = 65;
 548.198 +    public final int LONGVAL            = 66;
 548.199 +    public final int FLOATVAL           = 67;
 548.200 +    public final int DOUBLEVAL          = 68;
 548.201 +    public final int STRINGVAL          = 69;
 548.202 +
 548.203 +    /*
 548.204 +     * Type keywords
 548.205 +     */
 548.206 +    public final int BYTE               = 70;
 548.207 +    public final int CHAR               = 71;
 548.208 +    public final int SHORT              = 72;
 548.209 +    public final int INT                = 73;
 548.210 +    public final int LONG               = 74;
 548.211 +    public final int FLOAT              = 75;
 548.212 +    public final int DOUBLE             = 76;
 548.213 +    public final int VOID               = 77;
 548.214 +    public final int BOOLEAN            = 78;
 548.215 +
 548.216 +    /*
 548.217 +     * Expression keywords
 548.218 +     */
 548.219 +    public final int TRUE               = 80;
 548.220 +    public final int FALSE              = 81;
 548.221 +    public final int THIS               = 82;
 548.222 +    public final int SUPER              = 83;
 548.223 +    public final int NULL               = 84;
 548.224 +
 548.225 +    /*
 548.226 +     * Statement keywords
 548.227 +     */
 548.228 +    public final int IF                 = 90;
 548.229 +    public final int ELSE               = 91;
 548.230 +    public final int FOR                = 92;
 548.231 +    public final int WHILE              = 93;
 548.232 +    public final int DO                 = 94;
 548.233 +    public final int SWITCH             = 95;
 548.234 +    public final int CASE               = 96;
 548.235 +    public final int DEFAULT            = 97;
 548.236 +    public final int BREAK              = 98;
 548.237 +    public final int CONTINUE           = 99;
 548.238 +    public final int RETURN             = 100;
 548.239 +    public final int TRY                = 101;
 548.240 +    public final int CATCH              = 102;
 548.241 +    public final int FINALLY            = 103;
 548.242 +    public final int THROW              = 104;
 548.243 +    public final int STAT               = 105;
 548.244 +    public final int EXPRESSION         = 106;
 548.245 +    public final int DECLARATION        = 107;
 548.246 +    public final int VARDECLARATION     = 108;
 548.247 +
 548.248 +    /*
 548.249 +     * Declaration keywords
 548.250 +     */
 548.251 +    public final int IMPORT             = 110;
 548.252 +    public final int CLASS              = 111;
 548.253 +    public final int EXTENDS            = 112;
 548.254 +    public final int IMPLEMENTS         = 113;
 548.255 +    public final int INTERFACE          = 114;
 548.256 +    public final int PACKAGE            = 115;
 548.257 +
 548.258 +    /*
 548.259 +     * Modifier keywords
 548.260 +     */
 548.261 +    public final int PRIVATE    = 120;
 548.262 +    public final int PUBLIC             = 121;
 548.263 +    public final int PROTECTED  = 122;
 548.264 +    public final int CONST              = 123;
 548.265 +    public final int STATIC             = 124;
 548.266 +    public final int TRANSIENT          = 125;
 548.267 +    public final int SYNCHRONIZED       = 126;
 548.268 +    public final int NATIVE             = 127;
 548.269 +    public final int FINAL              = 128;
 548.270 +    public final int VOLATILE   = 129;
 548.271 +    public final int ABSTRACT   = 130;
 548.272 +    public final int STRICT             = 165;
 548.273 +
 548.274 +    /*
 548.275 +     * Punctuation
 548.276 +     */
 548.277 +    public final int SEMICOLON  = 135;
 548.278 +    public final int COLON              = 136;
 548.279 +    public final int QUESTIONMARK       = 137;
 548.280 +    public final int LBRACE             = 138;
 548.281 +    public final int RBRACE             = 139;
 548.282 +    public final int LPAREN             = 140;
 548.283 +    public final int RPAREN             = 141;
 548.284 +    public final int LSQBRACKET = 142;
 548.285 +    public final int RSQBRACKET = 143;
 548.286 +    public final int THROWS     = 144;
 548.287 +
 548.288 +    /*
 548.289 +     * Special tokens
 548.290 +     */
 548.291 +    public final int ERROR              = 145;          // an error
 548.292 +    public final int COMMENT    = 146;          // not used anymore.
 548.293 +    public final int TYPE               = 147;
 548.294 +    public final int LENGTH             = 148;
 548.295 +    public final int INLINERETURN       = 149;
 548.296 +    public final int INLINEMETHOD       = 150;
 548.297 +    public final int INLINENEWINSTANCE  = 151;
 548.298 +
 548.299 +    /*
 548.300 +     * Added for jasm
 548.301 +     */
 548.302 +        public final int METHODREF      = 152;
 548.303 +        public final int FIELDREF       = 153;
 548.304 +    public final int STACK              = 154;
 548.305 +    public final int LOCAL              = 155;
 548.306 +    public final int CPINDEX    = 156;
 548.307 +    public final int CPNAME             = 157;
 548.308 +    public final int SIGN               = 158;
 548.309 +    public final int BITS               = 159;
 548.310 +    public final int INF                = 160;
 548.311 +    public final int NAN                = 161;
 548.312 +    public final int INNERCLASS = 162;
 548.313 +    public final int OF         = 163;
 548.314 +    public final int SYNTHETIC          = 164;
 548.315 +// last used=165;
 548.316 +
 548.317 +   /*
 548.318 +     * Operator precedence
 548.319 +     */
 548.320 +    public static final int opPrecedence[] = {
 548.321 +        10,     11,     11,     11,     11,     11,     11,     11,     11,     11,
 548.322 +        11,     11,     11,     12,     13,     14,     15,     16,     17,     18,
 548.323 +        18,     19,     19,     19,     19,     19,     20,     20,     20,     21,
 548.324 +        21,     22,     22,     22,     23,     24,     24,     24,     24,     24,
 548.325 +        24,     25,     25,     26,     26,     26,     26,     26,     26
 548.326 +    };
 548.327 +
 548.328 +    /*
 548.329 +     * Operator names
 548.330 +     */
 548.331 +    public static final String opNames[] = {
 548.332 +        ",",            "=",            "*=",           "/=",           "%=",
 548.333 +        "+=",           "-=",           "<<=",          ">>=",          "<<<=",
 548.334 +        "&=",           "|=",           "^=",           "?:",           "||",
 548.335 +        "&&",           "|",            "^",            "&",            "!=",
 548.336 +        "==",           ">=",           ">",            "<=",           "<",
 548.337 +        "instanceof",   "<<",           ">>",           "<<<",          "+",
 548.338 +        "-",            "/",            "%",            "*",            "cast",
 548.339 +        "+",            "-",            "!",            "~",            "++",
 548.340 +        "--",           "new",          "new",          "new",          "++",
 548.341 +        "--",           "field",        "method",       "[]",           "new",
 548.342 +        "++",           "--",           null,           null,           null,
 548.343 +
 548.344 +        "convert",      "expr",         "array",        "goto",         null,
 548.345 +
 548.346 +        "Identifier",   "Boolean",      "Byte",         "Char",         "Short",
 548.347 +        "Integer",              "Long",         "Float",        "Double",       "String",
 548.348 +
 548.349 +        "byte",         "char",         "short",        "int",          "long",
 548.350 +        "float",        "double",       "void",         "boolean",      null,
 548.351 +
 548.352 +        "true",         "false",        "this",         "super",        "null",
 548.353 +        null,           null,           null,           null,           null,
 548.354 +
 548.355 +        "if",           "else",         "for",          "while",        "do",
 548.356 +        "switch",       "case",         "default",      "break",        "continue",
 548.357 +        "return",       "try",          "catch",        "finally",      "throw",
 548.358 +        "stat",         "expression",   "declaration",  "declaration",  null,
 548.359 +
 548.360 +        "import",       "class",        "extends",      "implements",   "interface",
 548.361 +        "package",      null,           null,           null,           null,
 548.362 +
 548.363 +        "private",      "public",       "protected",    "const",        "static",
 548.364 +        "transient",    "synchronized", "native",       "final",        "volatile",
 548.365 +        "abstract",     null,           null,           null,           null,
 548.366 +
 548.367 +        ";",            ":",            "?",            "{",            "}",
 548.368 +        "(",            ")",            "[",            "]",            "throws",
 548.369 +        "error",        "comment",      "type",         "length",       "inline-return",
 548.370 +        "inline-method", "inline-new",
 548.371 +        "method", "field", "stack", "locals", "CPINDEX", "CPName", "SIGN",
 548.372 +        "bits", "INF", "NaN", "InnerClass", "of", "synthetic"
 548.373 +    };
 548.374 +
 548.375 +}
   549.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   549.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/FieldData.java	Wed Feb 27 11:24:58 2013 +0100
   549.3 @@ -0,0 +1,168 @@
   549.4 +/*
   549.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   549.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   549.7 + *
   549.8 + * This code is free software; you can redistribute it and/or modify it
   549.9 + * under the terms of the GNU General Public License version 2 only, as
  549.10 + * published by the Free Software Foundation.  Oracle designates this
  549.11 + * particular file as subject to the "Classpath" exception as provided
  549.12 + * by Oracle in the LICENSE file that accompanied this code.
  549.13 + *
  549.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  549.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  549.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  549.17 + * version 2 for more details (a copy is included in the LICENSE file that
  549.18 + * accompanied this code).
  549.19 + *
  549.20 + * You should have received a copy of the GNU General Public License version
  549.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  549.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  549.23 + *
  549.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  549.25 + * or visit www.oracle.com if you need additional information or have any
  549.26 + * questions.
  549.27 + */
  549.28 +
  549.29 +
  549.30 +package org.apidesign.javap;
  549.31 +
  549.32 +import java.io.*;
  549.33 +
  549.34 +/**
  549.35 + * Strores field data informastion.
  549.36 + *
  549.37 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  549.38 + */
  549.39 +
  549.40 +public class FieldData implements RuntimeConstants  {
  549.41 +
  549.42 +    ClassData cls;
  549.43 +    int access;
  549.44 +    int name_index;
  549.45 +    int descriptor_index;
  549.46 +    int attributes_count;
  549.47 +    int value_cpx=0;
  549.48 +    boolean isSynthetic=false;
  549.49 +    boolean isDeprecated=false;
  549.50 +    Vector attrs;
  549.51 +
  549.52 +    public FieldData(ClassData cls){
  549.53 +        this.cls=cls;
  549.54 +    }
  549.55 +
  549.56 +    /**
  549.57 +     * Read and store field info.
  549.58 +     */
  549.59 +    public void read(DataInputStream in) throws IOException {
  549.60 +        access = in.readUnsignedShort();
  549.61 +        name_index = in.readUnsignedShort();
  549.62 +        descriptor_index = in.readUnsignedShort();
  549.63 +        // Read the attributes
  549.64 +        int attributes_count = in.readUnsignedShort();
  549.65 +        attrs=new Vector(attributes_count);
  549.66 +        for (int i = 0; i < attributes_count; i++) {
  549.67 +            int attr_name_index=in.readUnsignedShort();
  549.68 +            if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
  549.69 +            String attr_name=cls.getString(attr_name_index);
  549.70 +            if (attr_name.equals("ConstantValue")){
  549.71 +                if (in.readInt()!=2)
  549.72 +                    throw new ClassFormatError("invalid ConstantValue attr length");
  549.73 +                value_cpx=in.readUnsignedShort();
  549.74 +                AttrData attr=new AttrData(cls);
  549.75 +                attr.read(attr_name_index);
  549.76 +                attrs.addElement(attr);
  549.77 +            } else if (attr_name.equals("Synthetic")){
  549.78 +                if (in.readInt()!=0)
  549.79 +                    throw new ClassFormatError("invalid Synthetic attr length");
  549.80 +                isSynthetic=true;
  549.81 +                AttrData attr=new AttrData(cls);
  549.82 +                attr.read(attr_name_index);
  549.83 +                attrs.addElement(attr);
  549.84 +            } else if (attr_name.equals("Deprecated")){
  549.85 +                if (in.readInt()!=0)
  549.86 +                    throw new ClassFormatError("invalid Synthetic attr length");
  549.87 +                isDeprecated = true;
  549.88 +                AttrData attr=new AttrData(cls);
  549.89 +                attr.read(attr_name_index);
  549.90 +                attrs.addElement(attr);
  549.91 +            } else {
  549.92 +                AttrData attr=new AttrData(cls);
  549.93 +                attr.read(attr_name_index, in);
  549.94 +                attrs.addElement(attr);
  549.95 +            }
  549.96 +        }
  549.97 +
  549.98 +    }  // end read
  549.99 +
 549.100 +    public boolean isStatic() {
 549.101 +        return (access & ACC_STATIC) != 0;
 549.102 +    }
 549.103 +    
 549.104 +    /**
 549.105 +     * Returns access of a field.
 549.106 +     */
 549.107 +    public String[] getAccess(){
 549.108 +        Vector v = new Vector();
 549.109 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
 549.110 +        if ((access & ACC_PRIVATE)   !=0) v.addElement("private");
 549.111 +        if ((access & ACC_PROTECTED)   !=0) v.addElement("protected");
 549.112 +        if ((access & ACC_STATIC)   !=0) v.addElement("static");
 549.113 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
 549.114 +        if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
 549.115 +        if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
 549.116 +        String[] accflags = new String[v.size()];
 549.117 +        v.copyInto(accflags);
 549.118 +        return accflags;
 549.119 +    }
 549.120 +
 549.121 +    /**
 549.122 +     * Returns name of a field.
 549.123 +     */
 549.124 +    public String getName(){
 549.125 +        return cls.getStringValue(name_index);
 549.126 +    }
 549.127 +
 549.128 +    /**
 549.129 +     * Returns internal signature of a field
 549.130 +     */
 549.131 +    public String getInternalSig(){
 549.132 +        return cls.getStringValue(descriptor_index);
 549.133 +    }
 549.134 +
 549.135 +    /**
 549.136 +     * Returns true if field is synthetic.
 549.137 +     */
 549.138 +    public boolean isSynthetic(){
 549.139 +        return isSynthetic;
 549.140 +    }
 549.141 +
 549.142 +    /**
 549.143 +     * Returns true if field is deprecated.
 549.144 +     */
 549.145 +    public boolean isDeprecated(){
 549.146 +        return isDeprecated;
 549.147 +    }
 549.148 +
 549.149 +    /**
 549.150 +     * Returns index of constant value in cpool.
 549.151 +     */
 549.152 +    public int getConstantValueIndex(){
 549.153 +        return (value_cpx);
 549.154 +    }
 549.155 +
 549.156 +    /**
 549.157 +     * Returns list of attributes of field.
 549.158 +     */
 549.159 +    public Vector getAttributes(){
 549.160 +        return attrs;
 549.161 +    }
 549.162 +
 549.163 +    public byte[] findAnnotationData(boolean classRetention) {
 549.164 +        String n = classRetention ?
 549.165 +            "RuntimeInvisibleAnnotations" : // NOI18N
 549.166 +            "RuntimeVisibleAnnotations"; // NOI18N
 549.167 +        AttrData[] arr = new AttrData[attrs.size()];
 549.168 +        attrs.copyInto(arr);
 549.169 +        return ClassData.findAttr(n, arr);
 549.170 +    }
 549.171 +}
   550.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   550.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/Hashtable.java	Wed Feb 27 11:24:58 2013 +0100
   550.3 @@ -0,0 +1,94 @@
   550.4 +/**
   550.5 + * Back 2 Browser Bytecode Translator
   550.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   550.7 + *
   550.8 + * This program is free software: you can redistribute it and/or modify
   550.9 + * it under the terms of the GNU General Public License as published by
  550.10 + * the Free Software Foundation, version 2 of the License.
  550.11 + *
  550.12 + * This program is distributed in the hope that it will be useful,
  550.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  550.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  550.15 + * GNU General Public License for more details.
  550.16 + *
  550.17 + * You should have received a copy of the GNU General Public License
  550.18 + * along with this program. Look for COPYING file in the top folder.
  550.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  550.20 + */
  550.21 +package org.apidesign.javap;
  550.22 +
  550.23 +/** A JavaScript optimized replacement for Hashtable.
  550.24 + *
  550.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  550.26 + */
  550.27 +final class Hashtable {
  550.28 +    private Object[] keys;
  550.29 +    private Object[] values;
  550.30 +
  550.31 +    Hashtable(int i) {
  550.32 +        this();
  550.33 +    }
  550.34 +
  550.35 +    Hashtable(int i, double d) {
  550.36 +        this();
  550.37 +    }
  550.38 +
  550.39 +    Hashtable() {
  550.40 +    }
  550.41 +
  550.42 +    synchronized void put(Object key, Object val) {
  550.43 +        int[] where = { -1, -1 };
  550.44 +        Object found = get(key, where);
  550.45 +        if (where[0] != -1) {
  550.46 +            // key exists
  550.47 +            values[where[0]] = val;
  550.48 +        } else {
  550.49 +            if (where[1] != -1) {
  550.50 +                // null found
  550.51 +                keys[where[1]] = key;
  550.52 +                values[where[1]] = val;
  550.53 +            } else {
  550.54 +                if (keys == null) {
  550.55 +                    keys = new Object[11];
  550.56 +                    values = new Object[11];
  550.57 +                    keys[0] = key;
  550.58 +                    values[0] = val;
  550.59 +                } else {
  550.60 +                    Object[] newKeys = new Object[keys.length * 2];
  550.61 +                    Object[] newValues = new Object[values.length * 2];
  550.62 +                    for (int i = 0; i < keys.length; i++) {
  550.63 +                        newKeys[i] = keys[i];
  550.64 +                        newValues[i] = values[i];
  550.65 +                    }
  550.66 +                    newKeys[keys.length] = key;
  550.67 +                    newValues[keys.length] = val;
  550.68 +                    keys = newKeys;
  550.69 +                    values = newValues;
  550.70 +                }
  550.71 +            }
  550.72 +        }
  550.73 +    }
  550.74 +
  550.75 +    Object get(Object key) {
  550.76 +        return get(key, null);
  550.77 +    }
  550.78 +    private synchronized Object get(Object key, int[] foundAndNull) {
  550.79 +        if (keys == null) {
  550.80 +            return null;
  550.81 +        }
  550.82 +        for (int i = 0; i < keys.length; i++) {
  550.83 +            if (keys[i] == null) {
  550.84 +                if (foundAndNull != null) {
  550.85 +                    foundAndNull[1] = i;
  550.86 +                }
  550.87 +            } else if (keys[i].equals(key)) {
  550.88 +                if (foundAndNull != null) {
  550.89 +                    foundAndNull[0] = i;
  550.90 +                }
  550.91 +                return values[i];
  550.92 +            }
  550.93 +        }
  550.94 +        return null;
  550.95 +    }
  550.96 +    
  550.97 +}
   551.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   551.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/InnerClassData.java	Wed Feb 27 11:24:58 2013 +0100
   551.3 @@ -0,0 +1,75 @@
   551.4 +/*
   551.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   551.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   551.7 + *
   551.8 + * This code is free software; you can redistribute it and/or modify it
   551.9 + * under the terms of the GNU General Public License version 2 only, as
  551.10 + * published by the Free Software Foundation.  Oracle designates this
  551.11 + * particular file as subject to the "Classpath" exception as provided
  551.12 + * by Oracle in the LICENSE file that accompanied this code.
  551.13 + *
  551.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  551.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  551.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  551.17 + * version 2 for more details (a copy is included in the LICENSE file that
  551.18 + * accompanied this code).
  551.19 + *
  551.20 + * You should have received a copy of the GNU General Public License version
  551.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  551.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  551.23 + *
  551.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  551.25 + * or visit www.oracle.com if you need additional information or have any
  551.26 + * questions.
  551.27 + */
  551.28 +
  551.29 +
  551.30 +package org.apidesign.javap;
  551.31 +
  551.32 +import java.io.*;
  551.33 +import java.util.*;
  551.34 +
  551.35 +/**
  551.36 + * Strores InnerClass data informastion.
  551.37 + *
  551.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  551.39 + */
  551.40 +class InnerClassData  implements RuntimeConstants {
  551.41 +    ClassData cls;
  551.42 +
  551.43 +
  551.44 +    int inner_class_info_index
  551.45 +        ,outer_class_info_index
  551.46 +        ,inner_name_index
  551.47 +        ,access
  551.48 +        ;
  551.49 +
  551.50 +    public InnerClassData(ClassData cls) {
  551.51 +        this.cls=cls;
  551.52 +
  551.53 +    }
  551.54 +
  551.55 +    /**
  551.56 +     * Read Innerclass attribute data.
  551.57 +     */
  551.58 +    public void read(DataInputStream in) throws IOException {
  551.59 +        inner_class_info_index = in.readUnsignedShort();
  551.60 +        outer_class_info_index = in.readUnsignedShort();
  551.61 +        inner_name_index = in.readUnsignedShort();
  551.62 +        access = in.readUnsignedShort();
  551.63 +    }  // end read
  551.64 +
  551.65 +    /**
  551.66 +     * Returns the access of this class or interface.
  551.67 +     */
  551.68 +    public String[] getAccess(){
  551.69 +        Vector v = new Vector();
  551.70 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
  551.71 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
  551.72 +        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
  551.73 +        String[] accflags = new String[v.size()];
  551.74 +        v.copyInto(accflags);
  551.75 +        return accflags;
  551.76 +    }
  551.77 +
  551.78 +} // end InnerClassData
   552.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   552.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/LineNumData.java	Wed Feb 27 11:24:58 2013 +0100
   552.3 @@ -0,0 +1,50 @@
   552.4 +/*
   552.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   552.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   552.7 + *
   552.8 + * This code is free software; you can redistribute it and/or modify it
   552.9 + * under the terms of the GNU General Public License version 2 only, as
  552.10 + * published by the Free Software Foundation.  Oracle designates this
  552.11 + * particular file as subject to the "Classpath" exception as provided
  552.12 + * by Oracle in the LICENSE file that accompanied this code.
  552.13 + *
  552.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  552.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  552.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  552.17 + * version 2 for more details (a copy is included in the LICENSE file that
  552.18 + * accompanied this code).
  552.19 + *
  552.20 + * You should have received a copy of the GNU General Public License version
  552.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  552.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  552.23 + *
  552.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  552.25 + * or visit www.oracle.com if you need additional information or have any
  552.26 + * questions.
  552.27 + */
  552.28 +
  552.29 +
  552.30 +package org.apidesign.javap;
  552.31 +
  552.32 +import java.util.*;
  552.33 +import java.io.*;
  552.34 +
  552.35 +/**
  552.36 + * Strores LineNumberTable data information.
  552.37 + *
  552.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  552.39 + */
  552.40 +class LineNumData {
  552.41 +    short start_pc, line_number;
  552.42 +
  552.43 +    public LineNumData() {}
  552.44 +
  552.45 +    /**
  552.46 +     * Read LineNumberTable attribute.
  552.47 +     */
  552.48 +    public LineNumData(DataInputStream in) throws IOException {
  552.49 +        start_pc = in.readShort();
  552.50 +        line_number=in.readShort();
  552.51 +
  552.52 +    }
  552.53 +}
   553.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   553.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/LocVarData.java	Wed Feb 27 11:24:58 2013 +0100
   553.3 @@ -0,0 +1,54 @@
   553.4 +/*
   553.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   553.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   553.7 + *
   553.8 + * This code is free software; you can redistribute it and/or modify it
   553.9 + * under the terms of the GNU General Public License version 2 only, as
  553.10 + * published by the Free Software Foundation.  Oracle designates this
  553.11 + * particular file as subject to the "Classpath" exception as provided
  553.12 + * by Oracle in the LICENSE file that accompanied this code.
  553.13 + *
  553.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  553.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  553.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  553.17 + * version 2 for more details (a copy is included in the LICENSE file that
  553.18 + * accompanied this code).
  553.19 + *
  553.20 + * You should have received a copy of the GNU General Public License version
  553.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  553.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  553.23 + *
  553.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  553.25 + * or visit www.oracle.com if you need additional information or have any
  553.26 + * questions.
  553.27 + */
  553.28 +
  553.29 +
  553.30 +package org.apidesign.javap;
  553.31 +
  553.32 +import java.util.*;
  553.33 +import java.io.*;
  553.34 +
  553.35 +/**
  553.36 + * Strores LocalVariableTable data information.
  553.37 + *
  553.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  553.39 + */
  553.40 +class LocVarData {
  553.41 +    short start_pc, length, name_cpx, sig_cpx, slot;
  553.42 +
  553.43 +    public LocVarData() {
  553.44 +    }
  553.45 +
  553.46 +    /**
  553.47 +     * Read LocalVariableTable attribute.
  553.48 +     */
  553.49 +    public LocVarData(DataInputStream in) throws IOException {
  553.50 +        start_pc = in.readShort();
  553.51 +        length=in.readShort();
  553.52 +        name_cpx=in.readShort();
  553.53 +        sig_cpx=in.readShort();
  553.54 +        slot=in.readShort();
  553.55 +
  553.56 +    }
  553.57 +}
   554.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   554.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/MethodData.java	Wed Feb 27 11:24:58 2013 +0100
   554.3 @@ -0,0 +1,394 @@
   554.4 +/*
   554.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
   554.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   554.7 + *
   554.8 + * This code is free software; you can redistribute it and/or modify it
   554.9 + * under the terms of the GNU General Public License version 2 only, as
  554.10 + * published by the Free Software Foundation.  Oracle designates this
  554.11 + * particular file as subject to the "Classpath" exception as provided
  554.12 + * by Oracle in the LICENSE file that accompanied this code.
  554.13 + *
  554.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  554.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  554.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  554.17 + * version 2 for more details (a copy is included in the LICENSE file that
  554.18 + * accompanied this code).
  554.19 + *
  554.20 + * You should have received a copy of the GNU General Public License version
  554.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  554.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  554.23 + *
  554.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  554.25 + * or visit www.oracle.com if you need additional information or have any
  554.26 + * questions.
  554.27 + */
  554.28 +
  554.29 +package org.apidesign.javap;
  554.30 +
  554.31 +
  554.32 +import java.io.DataInputStream;
  554.33 +import java.io.IOException;
  554.34 +import static org.apidesign.javap.RuntimeConstants.*;
  554.35 +
  554.36 +/**
  554.37 + * Strores method data informastion.
  554.38 + *
  554.39 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  554.40 + */
  554.41 +public class MethodData {
  554.42 +
  554.43 +    ClassData cls;
  554.44 +    int access;
  554.45 +    int name_index;
  554.46 +    int descriptor_index;
  554.47 +    int attributes_count;
  554.48 +    byte[] code;
  554.49 +    Vector exception_table = new Vector(0);
  554.50 +    Vector lin_num_tb = new Vector(0);
  554.51 +    Vector loc_var_tb = new Vector(0);
  554.52 +    StackMapTableData[] stackMapTable;
  554.53 +    StackMapData[] stackMap;
  554.54 +    int[] exc_index_table=null;
  554.55 +    Vector attrs=new Vector(0);
  554.56 +    Vector code_attrs=new Vector(0);
  554.57 +    int max_stack,  max_locals;
  554.58 +    boolean isSynthetic=false;
  554.59 +    boolean isDeprecated=false;
  554.60 +
  554.61 +    public MethodData(ClassData cls){
  554.62 +        this.cls=cls;
  554.63 +    }
  554.64 +
  554.65 +    /**
  554.66 +     * Read method info.
  554.67 +     */
  554.68 +    public void read(DataInputStream in) throws IOException {
  554.69 +        access = in.readUnsignedShort();
  554.70 +        name_index=in.readUnsignedShort();
  554.71 +        descriptor_index =in.readUnsignedShort();
  554.72 +        int attributes_count = in.readUnsignedShort();
  554.73 +        for (int i = 0; i < attributes_count; i++) {
  554.74 +            int attr_name_index=in.readUnsignedShort();
  554.75 +
  554.76 +        readAttr: {
  554.77 +                if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
  554.78 +                    String  attr_name=cls.getString(attr_name_index);
  554.79 +                    if ( attr_name.equals("Code")){
  554.80 +                        readCode (in);
  554.81 +                        AttrData attr=new AttrData(cls);
  554.82 +                        attr.read(attr_name_index);
  554.83 +                        attrs.addElement(attr);
  554.84 +                        break readAttr;
  554.85 +                    } else if ( attr_name.equals("Exceptions")){
  554.86 +                        readExceptions(in);
  554.87 +                        AttrData attr=new AttrData(cls);
  554.88 +                        attr.read(attr_name_index);
  554.89 +                        attrs.addElement(attr);
  554.90 +                        break readAttr;
  554.91 +                    } else if (attr_name.equals("Synthetic")){
  554.92 +                        if (in.readInt()!=0)
  554.93 +                            throw new ClassFormatError("invalid Synthetic attr length");
  554.94 +                        isSynthetic=true;
  554.95 +                        AttrData attr=new AttrData(cls);
  554.96 +                        attr.read(attr_name_index);
  554.97 +                        attrs.addElement(attr);
  554.98 +                        break readAttr;
  554.99 +                    } else if (attr_name.equals("Deprecated")){
 554.100 +                        if (in.readInt()!=0)
 554.101 +                            throw new ClassFormatError("invalid Synthetic attr length");
 554.102 +                        isDeprecated = true;
 554.103 +                        AttrData attr=new AttrData(cls);
 554.104 +                        attr.read(attr_name_index);
 554.105 +                        attrs.addElement(attr);
 554.106 +                        break readAttr;
 554.107 +                    }
 554.108 +                }
 554.109 +                AttrData attr=new AttrData(cls);
 554.110 +                attr.read(attr_name_index, in);
 554.111 +                attrs.addElement(attr);
 554.112 +            }
 554.113 +        }
 554.114 +    }
 554.115 +
 554.116 +    /**
 554.117 +     * Read code attribute info.
 554.118 +     */
 554.119 +    public void readCode(DataInputStream in) throws IOException {
 554.120 +
 554.121 +        int attr_length = in.readInt();
 554.122 +        max_stack=in.readUnsignedShort();
 554.123 +        max_locals=in.readUnsignedShort();
 554.124 +        int codelen=in.readInt();
 554.125 +
 554.126 +        code=new byte[codelen];
 554.127 +        int totalread = 0;
 554.128 +        while(totalread < codelen){
 554.129 +            totalread += in.read(code, totalread, codelen-totalread);
 554.130 +        }
 554.131 +        //      in.read(code, 0, codelen);
 554.132 +        int clen = 0;
 554.133 +        readExceptionTable(in);
 554.134 +        int code_attributes_count = in.readUnsignedShort();
 554.135 +
 554.136 +        for (int k = 0 ; k < code_attributes_count ; k++) {
 554.137 +            int table_name_index=in.readUnsignedShort();
 554.138 +            int table_name_tag=cls.getTag(table_name_index);
 554.139 +            AttrData attr=new AttrData(cls);
 554.140 +            if (table_name_tag==CONSTANT_UTF8) {
 554.141 +                String table_name_tstr=cls.getString(table_name_index);
 554.142 +                if (table_name_tstr.equals("LineNumberTable")) {
 554.143 +                    readLineNumTable(in);
 554.144 +                    attr.read(table_name_index);
 554.145 +                } else if (table_name_tstr.equals("LocalVariableTable")) {
 554.146 +                    readLocVarTable(in);
 554.147 +                    attr.read(table_name_index);
 554.148 +                } else if (table_name_tstr.equals("StackMapTable")) {
 554.149 +                    readStackMapTable(in);
 554.150 +                    attr.read(table_name_index);
 554.151 +                } else if (table_name_tstr.equals("StackMap")) {
 554.152 +                    readStackMap(in);
 554.153 +                    attr.read(table_name_index);
 554.154 +                } else {
 554.155 +                    attr.read(table_name_index, in);
 554.156 +                }
 554.157 +                code_attrs.addElement(attr);
 554.158 +                continue;
 554.159 +            }
 554.160 +
 554.161 +            attr.read(table_name_index, in);
 554.162 +            code_attrs.addElement(attr);
 554.163 +        }
 554.164 +    }
 554.165 +
 554.166 +    /**
 554.167 +     * Read exception table info.
 554.168 +     */
 554.169 +    void readExceptionTable (DataInputStream in) throws IOException {
 554.170 +        int exception_table_len=in.readUnsignedShort();
 554.171 +        exception_table=new Vector(exception_table_len);
 554.172 +        for (int l = 0; l < exception_table_len; l++) {
 554.173 +            exception_table.addElement(new TrapData(in, l));
 554.174 +        }
 554.175 +    }
 554.176 +
 554.177 +    /**
 554.178 +     * Read LineNumberTable attribute info.
 554.179 +     */
 554.180 +    void readLineNumTable (DataInputStream in) throws IOException {
 554.181 +        int attr_len = in.readInt(); // attr_length
 554.182 +        int lin_num_tb_len = in.readUnsignedShort();
 554.183 +        lin_num_tb=new Vector(lin_num_tb_len);
 554.184 +        for (int l = 0; l < lin_num_tb_len; l++) {
 554.185 +            lin_num_tb.addElement(new LineNumData(in));
 554.186 +        }
 554.187 +    }
 554.188 +
 554.189 +    /**
 554.190 +     * Read LocalVariableTable attribute info.
 554.191 +     */
 554.192 +    void readLocVarTable (DataInputStream in) throws IOException {
 554.193 +        int attr_len=in.readInt(); // attr_length
 554.194 +        int loc_var_tb_len = in.readUnsignedShort();
 554.195 +        loc_var_tb = new Vector(loc_var_tb_len);
 554.196 +        for (int l = 0; l < loc_var_tb_len; l++) {
 554.197 +            loc_var_tb.addElement(new LocVarData(in));
 554.198 +        }
 554.199 +    }
 554.200 +
 554.201 +    /**
 554.202 +     * Read Exception attribute info.
 554.203 +     */
 554.204 +    public void readExceptions(DataInputStream in) throws IOException {
 554.205 +        int attr_len=in.readInt(); // attr_length in prog
 554.206 +        int num_exceptions = in.readUnsignedShort();
 554.207 +        exc_index_table=new int[num_exceptions];
 554.208 +        for (int l = 0; l < num_exceptions; l++) {
 554.209 +            int exc=in.readShort();
 554.210 +            exc_index_table[l]=exc;
 554.211 +        }
 554.212 +    }
 554.213 +
 554.214 +    /**
 554.215 +     * Read StackMapTable attribute info.
 554.216 +     */
 554.217 +    void readStackMapTable(DataInputStream in) throws IOException {
 554.218 +        int attr_len = in.readInt();  //attr_length
 554.219 +        int stack_map_tb_len = in.readUnsignedShort();
 554.220 +        stackMapTable = new StackMapTableData[stack_map_tb_len];
 554.221 +        for (int i=0; i<stack_map_tb_len; i++) {
 554.222 +            stackMapTable[i] = StackMapTableData.getInstance(in, this);
 554.223 +        }
 554.224 +    }
 554.225 +
 554.226 +    /**
 554.227 +     * Read StackMap attribute info.
 554.228 +     */
 554.229 +    void readStackMap(DataInputStream in) throws IOException {
 554.230 +        int attr_len = in.readInt();  //attr_length
 554.231 +        int stack_map_len = in.readUnsignedShort();
 554.232 +        stackMap = new StackMapData[stack_map_len];
 554.233 +        for (int i = 0; i<stack_map_len; i++) {
 554.234 +            stackMap[i] = new StackMapData(in, this);
 554.235 +        }
 554.236 +    }
 554.237 +
 554.238 +    /**
 554.239 +     * Return access of the method.
 554.240 +     */
 554.241 +    public int getAccess(){
 554.242 +        return access;
 554.243 +    }
 554.244 +
 554.245 +    /**
 554.246 +     * Return name of the method.
 554.247 +     */
 554.248 +    public String getName(){
 554.249 +        return cls.getStringValue(name_index);
 554.250 +    }
 554.251 +
 554.252 +    /**
 554.253 +     * Return internal siganature of the method.
 554.254 +     */
 554.255 +    public String getInternalSig(){
 554.256 +        return cls.getStringValue(descriptor_index);
 554.257 +    }
 554.258 +
 554.259 +    /**
 554.260 +     * Return code attribute data of a method.
 554.261 +     */
 554.262 +    public byte[] getCode(){
 554.263 +        return code;
 554.264 +    }
 554.265 +
 554.266 +    /**
 554.267 +     * Return LineNumberTable size.
 554.268 +     */
 554.269 +    public int getnumlines(){
 554.270 +        return lin_num_tb.size();
 554.271 +    }
 554.272 +
 554.273 +    /**
 554.274 +     * Return LineNumberTable
 554.275 +     */
 554.276 +    public Vector getlin_num_tb(){
 554.277 +        return lin_num_tb;
 554.278 +    }
 554.279 +
 554.280 +    /**
 554.281 +     * Return LocalVariableTable size.
 554.282 +     */
 554.283 +    public int getloc_var_tbsize(){
 554.284 +        return loc_var_tb.size();
 554.285 +    }
 554.286 +
 554.287 +
 554.288 +    /**
 554.289 +     * Return LocalVariableTable.
 554.290 +     */
 554.291 +    public Vector getloc_var_tb(){
 554.292 +        return loc_var_tb;
 554.293 +    }
 554.294 +
 554.295 +    /**
 554.296 +     * Return StackMap.
 554.297 +     */
 554.298 +    public StackMapData[] getStackMap() {
 554.299 +        return stackMap;
 554.300 +    }
 554.301 +
 554.302 +    /**
 554.303 +     * Return StackMapTable.
 554.304 +     */
 554.305 +    public StackMapTableData[] getStackMapTable() {
 554.306 +        return stackMapTable;
 554.307 +    }
 554.308 +
 554.309 +    public StackMapIterator createStackMapIterator() {
 554.310 +        return new StackMapIterator(this);
 554.311 +    }
 554.312 +
 554.313 +    /**
 554.314 +     * Return true if method is static
 554.315 +     */
 554.316 +    public boolean isStatic(){
 554.317 +        if ((access & ACC_STATIC)   !=0) return true;
 554.318 +        return false;
 554.319 +    }
 554.320 +
 554.321 +
 554.322 +    /**
 554.323 +     * Return max depth of operand stack.
 554.324 +     */
 554.325 +    public int getMaxStack(){
 554.326 +        return  max_stack;
 554.327 +    }
 554.328 +
 554.329 +
 554.330 +    /**
 554.331 +     * Return number of local variables.
 554.332 +     */
 554.333 +    public int getMaxLocals(){
 554.334 +        return max_locals;
 554.335 +    }
 554.336 +
 554.337 +
 554.338 +    /**
 554.339 +     * Return exception index table in Exception attribute.
 554.340 +     */
 554.341 +    public int []get_exc_index_table(){
 554.342 +        return  exc_index_table;
 554.343 +    }
 554.344 +
 554.345 +
 554.346 +    /**
 554.347 +     * Return exception table in code attributre.
 554.348 +     */
 554.349 +    public TrapDataIterator getTrapDataIterator(){
 554.350 +        return new TrapDataIterator(exception_table);
 554.351 +    }
 554.352 +    
 554.353 +
 554.354 +    /**
 554.355 +     * Return method attributes.
 554.356 +     */
 554.357 +    public Vector getAttributes(){
 554.358 +        return attrs;
 554.359 +    }
 554.360 +
 554.361 +
 554.362 +    /**
 554.363 +     * Return code attributes.
 554.364 +     */
 554.365 +    public Vector getCodeAttributes(){
 554.366 +        return code_attrs;
 554.367 +    }
 554.368 +
 554.369 +
 554.370 +    /**
 554.371 +     * Return true if method id synthetic.
 554.372 +     */
 554.373 +    public boolean isSynthetic(){
 554.374 +        return isSynthetic;
 554.375 +    }
 554.376 +
 554.377 +
 554.378 +    /**
 554.379 +     * Return true if method is deprecated.
 554.380 +     */
 554.381 +    public boolean isDeprecated(){
 554.382 +        return isDeprecated;
 554.383 +    }
 554.384 +
 554.385 +    public byte[] findAnnotationData(boolean classRetention) {
 554.386 +        String n = classRetention ?
 554.387 +            "RuntimeInvisibleAnnotations" : // NOI18N
 554.388 +            "RuntimeVisibleAnnotations"; // NOI18N
 554.389 +        AttrData[] arr = new AttrData[attrs.size()];
 554.390 +        attrs.copyInto(arr);
 554.391 +        return ClassData.findAttr(n, arr);
 554.392 +    }
 554.393 +
 554.394 +    public boolean isConstructor() {
 554.395 +        return "<init>".equals(getName());
 554.396 +    }
 554.397 +}
   555.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   555.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/RuntimeConstants.java	Wed Feb 27 11:24:58 2013 +0100
   555.3 @@ -0,0 +1,787 @@
   555.4 +/*
   555.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
   555.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   555.7 + *
   555.8 + * This code is free software; you can redistribute it and/or modify it
   555.9 + * under the terms of the GNU General Public License version 2 only, as
  555.10 + * published by the Free Software Foundation.  Oracle designates this
  555.11 + * particular file as subject to the "Classpath" exception as provided
  555.12 + * by Oracle in the LICENSE file that accompanied this code.
  555.13 + *
  555.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  555.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  555.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  555.17 + * version 2 for more details (a copy is included in the LICENSE file that
  555.18 + * accompanied this code).
  555.19 + *
  555.20 + * You should have received a copy of the GNU General Public License version
  555.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  555.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  555.23 + *
  555.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  555.25 + * or visit www.oracle.com if you need additional information or have any
  555.26 + * questions.
  555.27 + */
  555.28 +
  555.29 +
  555.30 +package org.apidesign.javap;
  555.31 +
  555.32 +public interface RuntimeConstants {
  555.33 +
  555.34 +    /* Signature Characters */
  555.35 +    public static final char   SIGC_VOID                  = 'V';
  555.36 +    public static final String SIG_VOID                   = "V";
  555.37 +    public static final char   SIGC_BOOLEAN               = 'Z';
  555.38 +    public static final String SIG_BOOLEAN                = "Z";
  555.39 +    public static final char   SIGC_BYTE                  = 'B';
  555.40 +    public static final String SIG_BYTE                   = "B";
  555.41 +    public static final char   SIGC_CHAR                  = 'C';
  555.42 +    public static final String SIG_CHAR                   = "C";
  555.43 +    public static final char   SIGC_SHORT                 = 'S';
  555.44 +    public static final String SIG_SHORT                  = "S";
  555.45 +    public static final char   SIGC_INT                   = 'I';
  555.46 +    public static final String SIG_INT                    = "I";
  555.47 +    public static final char   SIGC_LONG                  = 'J';
  555.48 +    public static final String SIG_LONG                   = "J";
  555.49 +    public static final char   SIGC_FLOAT                 = 'F';
  555.50 +    public static final String SIG_FLOAT                  = "F";
  555.51 +    public static final char   SIGC_DOUBLE                = 'D';
  555.52 +    public static final String SIG_DOUBLE                 = "D";
  555.53 +    public static final char   SIGC_ARRAY                 = '[';
  555.54 +    public static final String SIG_ARRAY                  = "[";
  555.55 +    public static final char   SIGC_CLASS                 = 'L';
  555.56 +    public static final String SIG_CLASS                  = "L";
  555.57 +    public static final char   SIGC_METHOD                = '(';
  555.58 +    public static final String SIG_METHOD                 = "(";
  555.59 +    public static final char   SIGC_ENDCLASS              = ';';
  555.60 +    public static final String SIG_ENDCLASS               = ";";
  555.61 +    public static final char   SIGC_ENDMETHOD             = ')';
  555.62 +    public static final String SIG_ENDMETHOD              = ")";
  555.63 +    public static final char   SIGC_PACKAGE               = '/';
  555.64 +    public static final String SIG_PACKAGE                = "/";
  555.65 +
  555.66 +    /* Class File Constants */
  555.67 +    public static final int JAVA_MAGIC                   = 0xcafebabe;
  555.68 +    public static final int JAVA_VERSION                 = 45;
  555.69 +    public static final int JAVA_MINOR_VERSION           = 3;
  555.70 +
  555.71 +    /* Constant table */
  555.72 +    public static final int CONSTANT_UTF8                = 1;
  555.73 +    public static final int CONSTANT_UNICODE             = 2;
  555.74 +    public static final int CONSTANT_INTEGER             = 3;
  555.75 +    public static final int CONSTANT_FLOAT               = 4;
  555.76 +    public static final int CONSTANT_LONG                = 5;
  555.77 +    public static final int CONSTANT_DOUBLE              = 6;
  555.78 +    public static final int CONSTANT_CLASS               = 7;
  555.79 +    public static final int CONSTANT_STRING              = 8;
  555.80 +    public static final int CONSTANT_FIELD               = 9;
  555.81 +    public static final int CONSTANT_METHOD              = 10;
  555.82 +    public static final int CONSTANT_INTERFACEMETHOD     = 11;
  555.83 +    public static final int CONSTANT_NAMEANDTYPE         = 12;
  555.84 +
  555.85 +    /* Access Flags */
  555.86 +    public static final int ACC_PUBLIC                   = 0x00000001;
  555.87 +    public static final int ACC_PRIVATE                  = 0x00000002;
  555.88 +    public static final int ACC_PROTECTED                = 0x00000004;
  555.89 +    public static final int ACC_STATIC                   = 0x00000008;
  555.90 +    public static final int ACC_FINAL                    = 0x00000010;
  555.91 +    public static final int ACC_SYNCHRONIZED             = 0x00000020;
  555.92 +    public static final int ACC_SUPER                        = 0x00000020;
  555.93 +    public static final int ACC_VOLATILE                 = 0x00000040;
  555.94 +    public static final int ACC_TRANSIENT                = 0x00000080;
  555.95 +    public static final int ACC_NATIVE                   = 0x00000100;
  555.96 +    public static final int ACC_INTERFACE                = 0x00000200;
  555.97 +    public static final int ACC_ABSTRACT                 = 0x00000400;
  555.98 +    public static final int ACC_STRICT                   = 0x00000800;
  555.99 +    public static final int ACC_EXPLICIT                 = 0x00001000;
 555.100 +    public static final int ACC_SYNTHETIC                = 0x00010000; // actually, this is an attribute
 555.101 +
 555.102 +    /* Type codes */
 555.103 +    public static final int T_CLASS                      = 0x00000002;
 555.104 +    public static final int T_BOOLEAN                    = 0x00000004;
 555.105 +    public static final int T_CHAR                       = 0x00000005;
 555.106 +    public static final int T_FLOAT                      = 0x00000006;
 555.107 +    public static final int T_DOUBLE                     = 0x00000007;
 555.108 +    public static final int T_BYTE                       = 0x00000008;
 555.109 +    public static final int T_SHORT                      = 0x00000009;
 555.110 +    public static final int T_INT                        = 0x0000000a;
 555.111 +    public static final int T_LONG                       = 0x0000000b;
 555.112 +
 555.113 +    /* Type codes for StackMap attribute */
 555.114 +    public static final int ITEM_Bogus      =0; // an unknown or uninitialized value
 555.115 +    public static final int ITEM_Integer    =1; // a 32-bit integer
 555.116 +    public static final int ITEM_Float      =2; // not used
 555.117 +    public static final int ITEM_Double     =3; // not used
 555.118 +    public static final int ITEM_Long       =4; // a 64-bit integer
 555.119 +    public static final int ITEM_Null       =5; // the type of null
 555.120 +    public static final int ITEM_InitObject =6; // "this" in constructor
 555.121 +    public static final int ITEM_Object     =7; // followed by 2-byte index of class name
 555.122 +    public static final int ITEM_NewObject  =8; // followed by 2-byte ref to "new"
 555.123 +
 555.124 +    /* Constants used in StackMapTable attribute */
 555.125 +    public static final int SAME_FRAME_BOUND                  = 64;
 555.126 +    public static final int SAME_LOCALS_1_STACK_ITEM_BOUND    = 128;
 555.127 +    public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
 555.128 +    public static final int SAME_FRAME_EXTENDED               = 251;
 555.129 +    public static final int FULL_FRAME                        = 255;
 555.130 +
 555.131 +    /* Opcodes */
 555.132 +    public static final int opc_dead                     = -2;
 555.133 +    public static final int opc_label                    = -1;
 555.134 +    public static final int opc_nop                      = 0;
 555.135 +    public static final int opc_aconst_null              = 1;
 555.136 +    public static final int opc_iconst_m1                = 2;
 555.137 +    public static final int opc_iconst_0                 = 3;
 555.138 +    public static final int opc_iconst_1                 = 4;
 555.139 +    public static final int opc_iconst_2                 = 5;
 555.140 +    public static final int opc_iconst_3                 = 6;
 555.141 +    public static final int opc_iconst_4                 = 7;
 555.142 +    public static final int opc_iconst_5                 = 8;
 555.143 +    public static final int opc_lconst_0                 = 9;
 555.144 +    public static final int opc_lconst_1                 = 10;
 555.145 +    public static final int opc_fconst_0                 = 11;
 555.146 +    public static final int opc_fconst_1                 = 12;
 555.147 +    public static final int opc_fconst_2                 = 13;
 555.148 +    public static final int opc_dconst_0                 = 14;
 555.149 +    public static final int opc_dconst_1                 = 15;
 555.150 +    public static final int opc_bipush                   = 16;
 555.151 +    public static final int opc_sipush                   = 17;
 555.152 +    public static final int opc_ldc                      = 18;
 555.153 +    public static final int opc_ldc_w                    = 19;
 555.154 +    public static final int opc_ldc2_w                   = 20;
 555.155 +    public static final int opc_iload                    = 21;
 555.156 +    public static final int opc_lload                    = 22;
 555.157 +    public static final int opc_fload                    = 23;
 555.158 +    public static final int opc_dload                    = 24;
 555.159 +    public static final int opc_aload                    = 25;
 555.160 +    public static final int opc_iload_0                  = 26;
 555.161 +    public static final int opc_iload_1                  = 27;
 555.162 +    public static final int opc_iload_2                  = 28;
 555.163 +    public static final int opc_iload_3                  = 29;
 555.164 +    public static final int opc_lload_0                  = 30;
 555.165 +    public static final int opc_lload_1                  = 31;
 555.166 +    public static final int opc_lload_2                  = 32;
 555.167 +    public static final int opc_lload_3                  = 33;
 555.168 +    public static final int opc_fload_0                  = 34;
 555.169 +    public static final int opc_fload_1                  = 35;
 555.170 +    public static final int opc_fload_2                  = 36;
 555.171 +    public static final int opc_fload_3                  = 37;
 555.172 +    public static final int opc_dload_0                  = 38;
 555.173 +    public static final int opc_dload_1                  = 39;
 555.174 +    public static final int opc_dload_2                  = 40;
 555.175 +    public static final int opc_dload_3                  = 41;
 555.176 +    public static final int opc_aload_0                  = 42;
 555.177 +    public static final int opc_aload_1                  = 43;
 555.178 +    public static final int opc_aload_2                  = 44;
 555.179 +    public static final int opc_aload_3                  = 45;
 555.180 +    public static final int opc_iaload                   = 46;
 555.181 +    public static final int opc_laload                   = 47;
 555.182 +    public static final int opc_faload                   = 48;
 555.183 +    public static final int opc_daload                   = 49;
 555.184 +    public static final int opc_aaload                   = 50;
 555.185 +    public static final int opc_baload                   = 51;
 555.186 +    public static final int opc_caload                   = 52;
 555.187 +    public static final int opc_saload                   = 53;
 555.188 +    public static final int opc_istore                   = 54;
 555.189 +    public static final int opc_lstore                   = 55;
 555.190 +    public static final int opc_fstore                   = 56;
 555.191 +    public static final int opc_dstore                   = 57;
 555.192 +    public static final int opc_astore                   = 58;
 555.193 +    public static final int opc_istore_0                 = 59;
 555.194 +    public static final int opc_istore_1                 = 60;
 555.195 +    public static final int opc_istore_2                 = 61;
 555.196 +    public static final int opc_istore_3                 = 62;
 555.197 +    public static final int opc_lstore_0                 = 63;
 555.198 +    public static final int opc_lstore_1                 = 64;
 555.199 +    public static final int opc_lstore_2                 = 65;
 555.200 +    public static final int opc_lstore_3                 = 66;
 555.201 +    public static final int opc_fstore_0                 = 67;
 555.202 +    public static final int opc_fstore_1                 = 68;
 555.203 +    public static final int opc_fstore_2                 = 69;
 555.204 +    public static final int opc_fstore_3                 = 70;
 555.205 +    public static final int opc_dstore_0                 = 71;
 555.206 +    public static final int opc_dstore_1                 = 72;
 555.207 +    public static final int opc_dstore_2                 = 73;
 555.208 +    public static final int opc_dstore_3                 = 74;
 555.209 +    public static final int opc_astore_0                 = 75;
 555.210 +    public static final int opc_astore_1                 = 76;
 555.211 +    public static final int opc_astore_2                 = 77;
 555.212 +    public static final int opc_astore_3                 = 78;
 555.213 +    public static final int opc_iastore                  = 79;
 555.214 +    public static final int opc_lastore                  = 80;
 555.215 +    public static final int opc_fastore                  = 81;
 555.216 +    public static final int opc_dastore                  = 82;
 555.217 +    public static final int opc_aastore                  = 83;
 555.218 +    public static final int opc_bastore                  = 84;
 555.219 +    public static final int opc_castore                  = 85;
 555.220 +    public static final int opc_sastore                  = 86;
 555.221 +    public static final int opc_pop                      = 87;
 555.222 +    public static final int opc_pop2                     = 88;
 555.223 +    public static final int opc_dup                      = 89;
 555.224 +    public static final int opc_dup_x1                   = 90;
 555.225 +    public static final int opc_dup_x2                   = 91;
 555.226 +    public static final int opc_dup2                     = 92;
 555.227 +    public static final int opc_dup2_x1                  = 93;
 555.228 +    public static final int opc_dup2_x2                  = 94;
 555.229 +    public static final int opc_swap                     = 95;
 555.230 +    public static final int opc_iadd                     = 96;
 555.231 +    public static final int opc_ladd                     = 97;
 555.232 +    public static final int opc_fadd                     = 98;
 555.233 +    public static final int opc_dadd                     = 99;
 555.234 +    public static final int opc_isub                     = 100;
 555.235 +    public static final int opc_lsub                     = 101;
 555.236 +    public static final int opc_fsub                     = 102;
 555.237 +    public static final int opc_dsub                     = 103;
 555.238 +    public static final int opc_imul                     = 104;
 555.239 +    public static final int opc_lmul                     = 105;
 555.240 +    public static final int opc_fmul                     = 106;
 555.241 +    public static final int opc_dmul                     = 107;
 555.242 +    public static final int opc_idiv                     = 108;
 555.243 +    public static final int opc_ldiv                     = 109;
 555.244 +    public static final int opc_fdiv                     = 110;
 555.245 +    public static final int opc_ddiv                     = 111;
 555.246 +    public static final int opc_irem                     = 112;
 555.247 +    public static final int opc_lrem                     = 113;
 555.248 +    public static final int opc_frem                     = 114;
 555.249 +    public static final int opc_drem                     = 115;
 555.250 +    public static final int opc_ineg                     = 116;
 555.251 +    public static final int opc_lneg                     = 117;
 555.252 +    public static final int opc_fneg                     = 118;
 555.253 +    public static final int opc_dneg                     = 119;
 555.254 +    public static final int opc_ishl                     = 120;
 555.255 +    public static final int opc_lshl                     = 121;
 555.256 +    public static final int opc_ishr                     = 122;
 555.257 +    public static final int opc_lshr                     = 123;
 555.258 +    public static final int opc_iushr                    = 124;
 555.259 +    public static final int opc_lushr                    = 125;
 555.260 +    public static final int opc_iand                     = 126;
 555.261 +    public static final int opc_land                     = 127;
 555.262 +    public static final int opc_ior                      = 128;
 555.263 +    public static final int opc_lor                      = 129;
 555.264 +    public static final int opc_ixor                     = 130;
 555.265 +    public static final int opc_lxor                     = 131;
 555.266 +    public static final int opc_iinc                     = 132;
 555.267 +    public static final int opc_i2l                      = 133;
 555.268 +    public static final int opc_i2f                      = 134;
 555.269 +    public static final int opc_i2d                      = 135;
 555.270 +    public static final int opc_l2i                      = 136;
 555.271 +    public static final int opc_l2f                      = 137;
 555.272 +    public static final int opc_l2d                      = 138;
 555.273 +    public static final int opc_f2i                      = 139;
 555.274 +    public static final int opc_f2l                      = 140;
 555.275 +    public static final int opc_f2d                      = 141;
 555.276 +    public static final int opc_d2i                      = 142;
 555.277 +    public static final int opc_d2l                      = 143;
 555.278 +    public static final int opc_d2f                      = 144;
 555.279 +    public static final int opc_i2b                      = 145;
 555.280 +    public static final int opc_int2byte                 = 145;
 555.281 +    public static final int opc_i2c                      = 146;
 555.282 +    public static final int opc_int2char                 = 146;
 555.283 +    public static final int opc_i2s                      = 147;
 555.284 +    public static final int opc_int2short                = 147;
 555.285 +    public static final int opc_lcmp                     = 148;
 555.286 +    public static final int opc_fcmpl                    = 149;
 555.287 +    public static final int opc_fcmpg                    = 150;
 555.288 +    public static final int opc_dcmpl                    = 151;
 555.289 +    public static final int opc_dcmpg                    = 152;
 555.290 +    public static final int opc_ifeq                     = 153;
 555.291 +    public static final int opc_ifne                     = 154;
 555.292 +    public static final int opc_iflt                     = 155;
 555.293 +    public static final int opc_ifge                     = 156;
 555.294 +    public static final int opc_ifgt                     = 157;
 555.295 +    public static final int opc_ifle                     = 158;
 555.296 +    public static final int opc_if_icmpeq                = 159;
 555.297 +    public static final int opc_if_icmpne                = 160;
 555.298 +    public static final int opc_if_icmplt                = 161;
 555.299 +    public static final int opc_if_icmpge                = 162;
 555.300 +    public static final int opc_if_icmpgt                = 163;
 555.301 +    public static final int opc_if_icmple                = 164;
 555.302 +    public static final int opc_if_acmpeq                = 165;
 555.303 +    public static final int opc_if_acmpne                = 166;
 555.304 +    public static final int opc_goto                     = 167;
 555.305 +    public static final int opc_jsr                      = 168;
 555.306 +    public static final int opc_ret                      = 169;
 555.307 +    public static final int opc_tableswitch              = 170;
 555.308 +    public static final int opc_lookupswitch             = 171;
 555.309 +    public static final int opc_ireturn                  = 172;
 555.310 +    public static final int opc_lreturn                  = 173;
 555.311 +    public static final int opc_freturn                  = 174;
 555.312 +    public static final int opc_dreturn                  = 175;
 555.313 +    public static final int opc_areturn                  = 176;
 555.314 +    public static final int opc_return                   = 177;
 555.315 +    public static final int opc_getstatic                = 178;
 555.316 +    public static final int opc_putstatic                = 179;
 555.317 +    public static final int opc_getfield                 = 180;
 555.318 +    public static final int opc_putfield                 = 181;
 555.319 +    public static final int opc_invokevirtual            = 182;
 555.320 +    public static final int opc_invokenonvirtual         = 183;
 555.321 +    public static final int opc_invokespecial            = 183;
 555.322 +    public static final int opc_invokestatic             = 184;
 555.323 +    public static final int opc_invokeinterface          = 185;
 555.324 +//    public static final int opc_xxxunusedxxx             = 186;
 555.325 +    public static final int opc_new                      = 187;
 555.326 +    public static final int opc_newarray                 = 188;
 555.327 +    public static final int opc_anewarray                = 189;
 555.328 +    public static final int opc_arraylength              = 190;
 555.329 +    public static final int opc_athrow                   = 191;
 555.330 +    public static final int opc_checkcast                = 192;
 555.331 +    public static final int opc_instanceof               = 193;
 555.332 +    public static final int opc_monitorenter             = 194;
 555.333 +    public static final int opc_monitorexit              = 195;
 555.334 +    public static final int opc_wide                     = 196;
 555.335 +    public static final int opc_multianewarray           = 197;
 555.336 +    public static final int opc_ifnull                   = 198;
 555.337 +    public static final int opc_ifnonnull                = 199;
 555.338 +    public static final int opc_goto_w                   = 200;
 555.339 +    public static final int opc_jsr_w                    = 201;
 555.340 +        /* Pseudo-instructions */
 555.341 +    public static final int opc_bytecode                 = 203;
 555.342 +    public static final int opc_try                      = 204;
 555.343 +    public static final int opc_endtry                   = 205;
 555.344 +    public static final int opc_catch                    = 206;
 555.345 +    public static final int opc_var                      = 207;
 555.346 +    public static final int opc_endvar                   = 208;
 555.347 +    public static final int opc_localsmap                = 209;
 555.348 +    public static final int opc_stackmap                 = 210;
 555.349 +        /* PicoJava prefixes */
 555.350 +    public static final int opc_nonpriv                  = 254;
 555.351 +    public static final int opc_priv                     = 255;
 555.352 +
 555.353 +        /* Wide instructions */
 555.354 +    public static final int opc_iload_w         = (opc_wide<<8)|opc_iload;
 555.355 +    public static final int opc_lload_w         = (opc_wide<<8)|opc_lload;
 555.356 +    public static final int opc_fload_w         = (opc_wide<<8)|opc_fload;
 555.357 +    public static final int opc_dload_w         = (opc_wide<<8)|opc_dload;
 555.358 +    public static final int opc_aload_w         = (opc_wide<<8)|opc_aload;
 555.359 +    public static final int opc_istore_w        = (opc_wide<<8)|opc_istore;
 555.360 +    public static final int opc_lstore_w        = (opc_wide<<8)|opc_lstore;
 555.361 +    public static final int opc_fstore_w        = (opc_wide<<8)|opc_fstore;
 555.362 +    public static final int opc_dstore_w        = (opc_wide<<8)|opc_dstore;
 555.363 +    public static final int opc_astore_w        = (opc_wide<<8)|opc_astore;
 555.364 +    public static final int opc_ret_w           = (opc_wide<<8)|opc_ret;
 555.365 +    public static final int opc_iinc_w          = (opc_wide<<8)|opc_iinc;
 555.366 +
 555.367 +    /* Opcode Names */
 555.368 +  public static final String opcNamesTab[] = {
 555.369 +        "nop",
 555.370 +        "aconst_null",
 555.371 +        "iconst_m1",
 555.372 +        "iconst_0",
 555.373 +        "iconst_1",
 555.374 +        "iconst_2",
 555.375 +        "iconst_3",
 555.376 +        "iconst_4",
 555.377 +        "iconst_5",
 555.378 +        "lconst_0",
 555.379 +        "lconst_1",
 555.380 +        "fconst_0",
 555.381 +        "fconst_1",
 555.382 +        "fconst_2",
 555.383 +        "dconst_0",
 555.384 +        "dconst_1",
 555.385 +        "bipush",
 555.386 +        "sipush",
 555.387 +        "ldc",
 555.388 +        "ldc_w",
 555.389 +        "ldc2_w",
 555.390 +        "iload",
 555.391 +        "lload",
 555.392 +        "fload",
 555.393 +        "dload",
 555.394 +        "aload",
 555.395 +        "iload_0",
 555.396 +        "iload_1",
 555.397 +        "iload_2",
 555.398 +        "iload_3",
 555.399 +        "lload_0",
 555.400 +        "lload_1",
 555.401 +        "lload_2",
 555.402 +        "lload_3",
 555.403 +        "fload_0",
 555.404 +        "fload_1",
 555.405 +        "fload_2",
 555.406 +        "fload_3",
 555.407 +        "dload_0",
 555.408 +        "dload_1",
 555.409 +        "dload_2",
 555.410 +        "dload_3",
 555.411 +        "aload_0",
 555.412 +        "aload_1",
 555.413 +        "aload_2",
 555.414 +        "aload_3",
 555.415 +        "iaload",
 555.416 +        "laload",
 555.417 +        "faload",
 555.418 +        "daload",
 555.419 +        "aaload",
 555.420 +        "baload",
 555.421 +        "caload",
 555.422 +        "saload",
 555.423 +        "istore",
 555.424 +        "lstore",
 555.425 +        "fstore",
 555.426 +        "dstore",
 555.427 +        "astore",
 555.428 +        "istore_0",
 555.429 +        "istore_1",
 555.430 +        "istore_2",
 555.431 +        "istore_3",
 555.432 +        "lstore_0",
 555.433 +        "lstore_1",
 555.434 +        "lstore_2",
 555.435 +        "lstore_3",
 555.436 +        "fstore_0",
 555.437 +        "fstore_1",
 555.438 +        "fstore_2",
 555.439 +        "fstore_3",
 555.440 +        "dstore_0",
 555.441 +        "dstore_1",
 555.442 +        "dstore_2",
 555.443 +        "dstore_3",
 555.444 +        "astore_0",
 555.445 +        "astore_1",
 555.446 +        "astore_2",
 555.447 +        "astore_3",
 555.448 +        "iastore",
 555.449 +        "lastore",
 555.450 +        "fastore",
 555.451 +        "dastore",
 555.452 +        "aastore",
 555.453 +        "bastore",
 555.454 +        "castore",
 555.455 +        "sastore",
 555.456 +        "pop",
 555.457 +        "pop2",
 555.458 +        "dup",
 555.459 +        "dup_x1",
 555.460 +        "dup_x2",
 555.461 +        "dup2",
 555.462 +        "dup2_x1",
 555.463 +        "dup2_x2",
 555.464 +        "swap",
 555.465 +        "iadd",
 555.466 +        "ladd",
 555.467 +        "fadd",
 555.468 +        "dadd",
 555.469 +        "isub",
 555.470 +        "lsub",
 555.471 +        "fsub",
 555.472 +        "dsub",
 555.473 +        "imul",
 555.474 +        "lmul",
 555.475 +        "fmul",
 555.476 +        "dmul",
 555.477 +        "idiv",
 555.478 +        "ldiv",
 555.479 +        "fdiv",
 555.480 +        "ddiv",
 555.481 +        "irem",
 555.482 +        "lrem",
 555.483 +        "frem",
 555.484 +        "drem",
 555.485 +        "ineg",
 555.486 +        "lneg",
 555.487 +        "fneg",
 555.488 +        "dneg",
 555.489 +        "ishl",
 555.490 +        "lshl",
 555.491 +        "ishr",
 555.492 +        "lshr",
 555.493 +        "iushr",
 555.494 +        "lushr",
 555.495 +        "iand",
 555.496 +        "land",
 555.497 +        "ior",
 555.498 +        "lor",
 555.499 +        "ixor",
 555.500 +        "lxor",
 555.501 +        "iinc",
 555.502 +        "i2l",
 555.503 +        "i2f",
 555.504 +        "i2d",
 555.505 +        "l2i",
 555.506 +        "l2f",
 555.507 +        "l2d",
 555.508 +        "f2i",
 555.509 +        "f2l",
 555.510 +        "f2d",
 555.511 +        "d2i",
 555.512 +        "d2l",
 555.513 +        "d2f",
 555.514 +        "i2b",
 555.515 +        "i2c",
 555.516 +        "i2s",
 555.517 +        "lcmp",
 555.518 +        "fcmpl",
 555.519 +        "fcmpg",
 555.520 +        "dcmpl",
 555.521 +        "dcmpg",
 555.522 +        "ifeq",
 555.523 +        "ifne",
 555.524 +        "iflt",
 555.525 +        "ifge",
 555.526 +        "ifgt",
 555.527 +        "ifle",
 555.528 +        "if_icmpeq",
 555.529 +        "if_icmpne",
 555.530 +        "if_icmplt",
 555.531 +        "if_icmpge",
 555.532 +        "if_icmpgt",
 555.533 +        "if_icmple",
 555.534 +        "if_acmpeq",
 555.535 +        "if_acmpne",
 555.536 +        "goto",
 555.537 +        "jsr",
 555.538 +        "ret",
 555.539 +        "tableswitch",
 555.540 +        "lookupswitch",
 555.541 +        "ireturn",
 555.542 +        "lreturn",
 555.543 +        "freturn",
 555.544 +        "dreturn",
 555.545 +        "areturn",
 555.546 +        "return",
 555.547 +        "getstatic",
 555.548 +        "putstatic",
 555.549 +        "getfield",
 555.550 +        "putfield",
 555.551 +        "invokevirtual",
 555.552 +        "invokespecial", //     was "invokenonvirtual",
 555.553 +        "invokestatic",
 555.554 +        "invokeinterface",
 555.555 +        "bytecode 186", //"xxxunusedxxx",
 555.556 +        "new",
 555.557 +        "newarray",
 555.558 +        "anewarray",
 555.559 +        "arraylength",
 555.560 +        "athrow",
 555.561 +        "checkcast",
 555.562 +        "instanceof",
 555.563 +        "monitorenter",
 555.564 +        "monitorexit",
 555.565 +         null, // "wide",
 555.566 +        "multianewarray",
 555.567 +        "ifnull",
 555.568 +        "ifnonnull",
 555.569 +        "goto_w",
 555.570 +        "jsr_w",
 555.571 +        "bytecode 202", // "breakpoint",
 555.572 +        "bytecode",
 555.573 +        "try",
 555.574 +        "endtry",
 555.575 +        "catch",
 555.576 +        "var",
 555.577 +        "endvar",
 555.578 +        "locals_map",
 555.579 +        "stack_map"
 555.580 +  };
 555.581 +
 555.582 +    /* Opcode Lengths */
 555.583 +  public static final int opcLengthsTab[] = {
 555.584 +        1,
 555.585 +        1,
 555.586 +        1,
 555.587 +        1,
 555.588 +        1,
 555.589 +        1,
 555.590 +        1,
 555.591 +        1,
 555.592 +        1,
 555.593 +        1,
 555.594 +        1,
 555.595 +        1,
 555.596 +        1,
 555.597 +        1,
 555.598 +        1,
 555.599 +        1,
 555.600 +        2,
 555.601 +        3,
 555.602 +        2,
 555.603 +        3,
 555.604 +        3,
 555.605 +        2,
 555.606 +        2,
 555.607 +        2,
 555.608 +        2,
 555.609 +        2,
 555.610 +        1,
 555.611 +        1,
 555.612 +        1,
 555.613 +        1,
 555.614 +        1,
 555.615 +        1,
 555.616 +        1,
 555.617 +        1,
 555.618 +        1,
 555.619 +        1,
 555.620 +        1,
 555.621 +        1,
 555.622 +        1,
 555.623 +        1,
 555.624 +        1,
 555.625 +        1,
 555.626 +        1,
 555.627 +        1,
 555.628 +        1,
 555.629 +        1,
 555.630 +        1,
 555.631 +        1,
 555.632 +        1,
 555.633 +        1,
 555.634 +        1,
 555.635 +        1,
 555.636 +        1,
 555.637 +        1,
 555.638 +        2,
 555.639 +        2,
 555.640 +        2,
 555.641 +        2,
 555.642 +        2,
 555.643 +        1,
 555.644 +        1,
 555.645 +        1,
 555.646 +        1,
 555.647 +        1,
 555.648 +        1,
 555.649 +        1,
 555.650 +        1,
 555.651 +        1,
 555.652 +        1,
 555.653 +        1,
 555.654 +        1,
 555.655 +        1,
 555.656 +        1,
 555.657 +        1,
 555.658 +        1,
 555.659 +        1,
 555.660 +        1,
 555.661 +        1,
 555.662 +        1,
 555.663 +        1,
 555.664 +        1,
 555.665 +        1,
 555.666 +        1,
 555.667 +        1,
 555.668 +        1,
 555.669 +        1,
 555.670 +        1,
 555.671 +        1,
 555.672 +        1,
 555.673 +        1,
 555.674 +        1,
 555.675 +        1,
 555.676 +        1,
 555.677 +        1,
 555.678 +        1,
 555.679 +        1,
 555.680 +        1,
 555.681 +        1,
 555.682 +        1,
 555.683 +        1,
 555.684 +        1,
 555.685 +        1,
 555.686 +        1,
 555.687 +        1,
 555.688 +        1,
 555.689 +        1,
 555.690 +        1,
 555.691 +        1,
 555.692 +        1,
 555.693 +        1,
 555.694 +        1,
 555.695 +        1,
 555.696 +        1,
 555.697 +        1,
 555.698 +        1,
 555.699 +        1,
 555.700 +        1,
 555.701 +        1,
 555.702 +        1,
 555.703 +        1,
 555.704 +        1,
 555.705 +        1,
 555.706 +        1,
 555.707 +        1,
 555.708 +        1,
 555.709 +        1,
 555.710 +        1,
 555.711 +        1,
 555.712 +        1,
 555.713 +        1,
 555.714 +        1,
 555.715 +        1,
 555.716 +        3,
 555.717 +        1,
 555.718 +        1,
 555.719 +        1,
 555.720 +        1,
 555.721 +        1,
 555.722 +        1,
 555.723 +        1,
 555.724 +        1,
 555.725 +        1,
 555.726 +        1,
 555.727 +        1,
 555.728 +        1,
 555.729 +        1,
 555.730 +        1,
 555.731 +        1,
 555.732 +        1,
 555.733 +        1,
 555.734 +        1,
 555.735 +        1,
 555.736 +        1,
 555.737 +        3,
 555.738 +        3,
 555.739 +        3,
 555.740 +        3,
 555.741 +        3,
 555.742 +        3,
 555.743 +        3,
 555.744 +        3,
 555.745 +        3,
 555.746 +        3,
 555.747 +        3,
 555.748 +        3,
 555.749 +        3,
 555.750 +        3,
 555.751 +        3,
 555.752 +        3,
 555.753 +        2,
 555.754 +        99,
 555.755 +        99,
 555.756 +        1,
 555.757 +        1,
 555.758 +        1,
 555.759 +        1,
 555.760 +        1,
 555.761 +        1,
 555.762 +        3,
 555.763 +        3,
 555.764 +        3,
 555.765 +        3,
 555.766 +        3,
 555.767 +        3,
 555.768 +        3,
 555.769 +        5,
 555.770 +        0,
 555.771 +        3,
 555.772 +        2,
 555.773 +        3,
 555.774 +        1,
 555.775 +        1,
 555.776 +        3,
 555.777 +        3,
 555.778 +        1,
 555.779 +        1,
 555.780 +        0, // wide
 555.781 +        4,
 555.782 +        3,
 555.783 +        3,
 555.784 +        5,
 555.785 +        5,
 555.786 +        1,
 555.787 +        1, 0, 0, 0, 0, 0 // pseudo
 555.788 +  };
 555.789 +
 555.790 +}
   556.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   556.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/StackMapData.java	Wed Feb 27 11:24:58 2013 +0100
   556.3 @@ -0,0 +1,71 @@
   556.4 +/*
   556.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   556.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   556.7 + *
   556.8 + * This code is free software; you can redistribute it and/or modify it
   556.9 + * under the terms of the GNU General Public License version 2 only, as
  556.10 + * published by the Free Software Foundation.  Oracle designates this
  556.11 + * particular file as subject to the "Classpath" exception as provided
  556.12 + * by Oracle in the LICENSE file that accompanied this code.
  556.13 + *
  556.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  556.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  556.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  556.17 + * version 2 for more details (a copy is included in the LICENSE file that
  556.18 + * accompanied this code).
  556.19 + *
  556.20 + * You should have received a copy of the GNU General Public License version
  556.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  556.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  556.23 + *
  556.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  556.25 + * or visit www.oracle.com if you need additional information or have any
  556.26 + * questions.
  556.27 + */
  556.28 +
  556.29 +
  556.30 +package org.apidesign.javap;
  556.31 +
  556.32 +import java.util.*;
  556.33 +import java.io.*;
  556.34 +
  556.35 +import static org.apidesign.javap.RuntimeConstants.*;
  556.36 +
  556.37 +/* represents one entry of StackMap attribute
  556.38 + */
  556.39 +class StackMapData {
  556.40 +    final int offset;
  556.41 +    final int[] locals;
  556.42 +    final int[] stack;
  556.43 +
  556.44 +    StackMapData(int offset, int[] locals, int[] stack) {
  556.45 +        this.offset = offset;
  556.46 +        this.locals = locals;
  556.47 +        this.stack = stack;
  556.48 +    }
  556.49 +
  556.50 +    StackMapData(DataInputStream in, MethodData method) throws IOException {
  556.51 +        offset = in.readUnsignedShort();
  556.52 +        int local_size = in.readUnsignedShort();
  556.53 +        locals = readTypeArray(in, local_size, method);
  556.54 +        int stack_size = in.readUnsignedShort();
  556.55 +        stack = readTypeArray(in, stack_size, method);
  556.56 +    }
  556.57 +
  556.58 +    static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
  556.59 +        int[] types = new int[length];
  556.60 +        for (int i=0; i<length; i++) {
  556.61 +            types[i] = readType(in, method);
  556.62 +        }
  556.63 +        return types;
  556.64 +    }
  556.65 +
  556.66 +    static final int readType(DataInputStream in, MethodData method) throws IOException {
  556.67 +        int type = in.readUnsignedByte();
  556.68 +        if (type == ITEM_Object || type == ITEM_NewObject) {
  556.69 +            type = type | (in.readUnsignedShort()<<8);
  556.70 +        }
  556.71 +        return type;
  556.72 +    }
  556.73 +
  556.74 +}
   557.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   557.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/StackMapIterator.java	Wed Feb 27 11:24:58 2013 +0100
   557.3 @@ -0,0 +1,179 @@
   557.4 +/*
   557.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   557.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   557.7 + *
   557.8 + * This code is free software; you can redistribute it and/or modify it
   557.9 + * under the terms of the GNU General Public License version 2 only, as
  557.10 + * published by the Free Software Foundation.  Oracle designates this
  557.11 + * particular file as subject to the "Classpath" exception as provided
  557.12 + * by Oracle in the LICENSE file that accompanied this code.
  557.13 + *
  557.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  557.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  557.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  557.17 + * version 2 for more details (a copy is included in the LICENSE file that
  557.18 + * accompanied this code).
  557.19 + *
  557.20 + * You should have received a copy of the GNU General Public License version
  557.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  557.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  557.23 + *
  557.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  557.25 + * or visit www.oracle.com if you need additional information or have any
  557.26 + * questions.
  557.27 + */
  557.28 +
  557.29 +package org.apidesign.javap;
  557.30 +
  557.31 +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
  557.32 +import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
  557.33 +import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
  557.34 +import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
  557.35 +import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
  557.36 +
  557.37 +public final class StackMapIterator {
  557.38 +    private final StackMapTableData[] stackMapTable;
  557.39 +    private final TypeArray argTypes;
  557.40 +    private final TypeArray localTypes;
  557.41 +    private final TypeArray stackTypes;
  557.42 +
  557.43 +    private int nextFrameIndex;
  557.44 +    private int lastFrameByteCodeOffset;
  557.45 +
  557.46 +    private int byteCodeOffset;
  557.47 +
  557.48 +    StackMapIterator(final MethodData methodData) {
  557.49 +        this(methodData.getStackMapTable(),
  557.50 +             methodData.getInternalSig(),
  557.51 +             methodData.isStatic());
  557.52 +    }
  557.53 +
  557.54 +    StackMapIterator(final StackMapTableData[] stackMapTable,
  557.55 +                     final String methodSignature,
  557.56 +                     final boolean isStaticMethod) {
  557.57 +        this.stackMapTable = (stackMapTable != null)
  557.58 +                                 ? stackMapTable
  557.59 +                                 : new StackMapTableData[0];
  557.60 +
  557.61 +        argTypes = getArgTypes(methodSignature, isStaticMethod);
  557.62 +        localTypes = new TypeArray();
  557.63 +        stackTypes = new TypeArray();
  557.64 +
  557.65 +        localTypes.addAll(argTypes);
  557.66 +
  557.67 +        lastFrameByteCodeOffset = -1;
  557.68 +        advanceBy(0);
  557.69 +    }
  557.70 +
  557.71 +    public String getFrameAsString() {
  557.72 +        return (nextFrameIndex == 0)
  557.73 +                   ? StackMapTableData.toString("INITIAL", 0, null, null)
  557.74 +                   : stackMapTable[nextFrameIndex - 1].toString();
  557.75 +    }
  557.76 +
  557.77 +    public int getFrameIndex() {
  557.78 +        return nextFrameIndex;
  557.79 +    }
  557.80 +
  557.81 +    public TypeArray getFrameStack() {
  557.82 +        return stackTypes;
  557.83 +    }
  557.84 +
  557.85 +    public TypeArray getFrameLocals() {
  557.86 +        return localTypes;
  557.87 +    }
  557.88 +
  557.89 +    public TypeArray getArguments() {
  557.90 +        return argTypes;
  557.91 +    }
  557.92 +
  557.93 +    public void advanceBy(final int numByteCodes) {
  557.94 +        if (numByteCodes < 0) {
  557.95 +            throw new IllegalStateException("Forward only iterator");
  557.96 +        }
  557.97 +
  557.98 +        byteCodeOffset += numByteCodes;
  557.99 +        while ((nextFrameIndex < stackMapTable.length)
 557.100 +                    && ((byteCodeOffset - lastFrameByteCodeOffset)
 557.101 +                            >= (stackMapTable[nextFrameIndex].offsetDelta
 557.102 +                                    + 1))) {
 557.103 +            final StackMapTableData nextFrame = stackMapTable[nextFrameIndex];
 557.104 +
 557.105 +            lastFrameByteCodeOffset += nextFrame.offsetDelta + 1;
 557.106 +            nextFrame.applyTo(localTypes, stackTypes);
 557.107 +
 557.108 +            ++nextFrameIndex;
 557.109 +        }
 557.110 +    }
 557.111 +
 557.112 +    public void advanceTo(final int nextByteCodeOffset) {
 557.113 +        advanceBy(nextByteCodeOffset - byteCodeOffset);
 557.114 +    }
 557.115 +
 557.116 +    private static TypeArray getArgTypes(final String methodSignature,
 557.117 +                                         final boolean isStaticMethod) {
 557.118 +        final TypeArray argTypes = new TypeArray();
 557.119 +
 557.120 +        if (!isStaticMethod) {
 557.121 +            argTypes.add(ITEM_Object);
 557.122 +        }
 557.123 +
 557.124 +        if (methodSignature.charAt(0) != '(') {
 557.125 +            throw new IllegalArgumentException("Invalid method signature");
 557.126 +        }
 557.127 +
 557.128 +        final int length = methodSignature.length();
 557.129 +        boolean skipType = false;
 557.130 +        int argType;
 557.131 +        for (int i = 1; i < length; ++i) {
 557.132 +            switch (methodSignature.charAt(i)) {
 557.133 +                case 'B':
 557.134 +                case 'C':
 557.135 +                case 'S':
 557.136 +                case 'Z':
 557.137 +                case 'I':
 557.138 +                    argType = ITEM_Integer;
 557.139 +                    break;
 557.140 +                case 'J':
 557.141 +                    argType = ITEM_Long;
 557.142 +                    break;
 557.143 +                case 'F':
 557.144 +                    argType = ITEM_Float;
 557.145 +                    break;
 557.146 +                case 'D':
 557.147 +                    argType = ITEM_Double;
 557.148 +                    break;
 557.149 +                case 'L': {
 557.150 +                    i = methodSignature.indexOf(';', i + 1);
 557.151 +                    if (i == -1) {
 557.152 +                        throw new IllegalArgumentException(
 557.153 +                                      "Invalid method signature");
 557.154 +                    }
 557.155 +                    argType = ITEM_Object;
 557.156 +                    break;
 557.157 +                }
 557.158 +                case ')':
 557.159 +                    // not interested in the return value type
 557.160 +                    return argTypes;
 557.161 +                case '[':
 557.162 +                    if (!skipType) {
 557.163 +                        argTypes.add(ITEM_Object);
 557.164 +                        skipType = true;
 557.165 +                    }
 557.166 +                    continue;
 557.167 +
 557.168 +                default:
 557.169 +                    throw new IllegalArgumentException(
 557.170 +                                  "Invalid method signature");
 557.171 +            }
 557.172 +
 557.173 +            if (!skipType) {
 557.174 +                argTypes.add(argType);
 557.175 +            } else {
 557.176 +                skipType = false;
 557.177 +            }
 557.178 +        }
 557.179 +
 557.180 +        return argTypes;
 557.181 +    }
 557.182 +}
   558.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   558.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/StackMapTableData.java	Wed Feb 27 11:24:58 2013 +0100
   558.3 @@ -0,0 +1,223 @@
   558.4 +/*
   558.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   558.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   558.7 + *
   558.8 + * This code is free software; you can redistribute it and/or modify it
   558.9 + * under the terms of the GNU General Public License version 2 only, as
  558.10 + * published by the Free Software Foundation.  Oracle designates this
  558.11 + * particular file as subject to the "Classpath" exception as provided
  558.12 + * by Oracle in the LICENSE file that accompanied this code.
  558.13 + *
  558.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  558.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  558.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  558.17 + * version 2 for more details (a copy is included in the LICENSE file that
  558.18 + * accompanied this code).
  558.19 + *
  558.20 + * You should have received a copy of the GNU General Public License version
  558.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  558.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  558.23 + *
  558.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  558.25 + * or visit www.oracle.com if you need additional information or have any
  558.26 + * questions.
  558.27 + */
  558.28 +
  558.29 +
  558.30 +package org.apidesign.javap;
  558.31 +
  558.32 +import java.io.*;
  558.33 +
  558.34 +import static org.apidesign.javap.RuntimeConstants.*;
  558.35 +
  558.36 +/* represents one entry of StackMapTable attribute
  558.37 + */
  558.38 +abstract class StackMapTableData {
  558.39 +    final int frameType;
  558.40 +    int offsetDelta;
  558.41 +
  558.42 +    StackMapTableData(int frameType) {
  558.43 +        this.frameType = frameType;
  558.44 +    }
  558.45 +
  558.46 +    abstract void applyTo(TypeArray localTypes, TypeArray stackTypes);
  558.47 +
  558.48 +    protected static String toString(
  558.49 +            final String frameType,
  558.50 +            final int offset,
  558.51 +            final int[] localTypes,
  558.52 +            final int[] stackTypes) {
  558.53 +        final StringBuilder sb = new StringBuilder(frameType);
  558.54 +
  558.55 +        sb.append("(off: +").append(offset);
  558.56 +        if (localTypes != null) {
  558.57 +            sb.append(", locals: ");
  558.58 +            appendTypes(sb, localTypes);
  558.59 +        }
  558.60 +        if (stackTypes != null) {
  558.61 +            sb.append(", stack: ");
  558.62 +            appendTypes(sb, stackTypes);
  558.63 +        }
  558.64 +        sb.append(')');
  558.65 +
  558.66 +        return sb.toString();
  558.67 +    }
  558.68 +
  558.69 +    private static void appendTypes(final StringBuilder sb, final int[] types) {
  558.70 +        sb.append('[');
  558.71 +        if (types.length > 0) {
  558.72 +            sb.append(TypeArray.typeString(types[0]));
  558.73 +            for (int i = 1; i < types.length; ++i) {
  558.74 +                sb.append(", ");
  558.75 +                sb.append(TypeArray.typeString(types[i]));
  558.76 +            }
  558.77 +        }
  558.78 +        sb.append(']');
  558.79 +    }
  558.80 +
  558.81 +    static class SameFrame extends StackMapTableData {
  558.82 +        SameFrame(int frameType, int offsetDelta) {
  558.83 +            super(frameType);
  558.84 +            this.offsetDelta = offsetDelta;
  558.85 +        }
  558.86 +
  558.87 +        @Override
  558.88 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
  558.89 +            stackTypes.clear();
  558.90 +        }
  558.91 +
  558.92 +        @Override
  558.93 +        public String toString() {
  558.94 +            return toString("SAME" + ((frameType == SAME_FRAME_EXTENDED)
  558.95 +                                          ? "_FRAME_EXTENDED" : ""),
  558.96 +                            offsetDelta,
  558.97 +                            null, null);
  558.98 +        }
  558.99 +    }
 558.100 +
 558.101 +    static class SameLocals1StackItem extends StackMapTableData {
 558.102 +        final int[] stack;
 558.103 +        SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
 558.104 +            super(frameType);
 558.105 +            this.offsetDelta = offsetDelta;
 558.106 +            this.stack = stack;
 558.107 +        }
 558.108 +
 558.109 +        @Override
 558.110 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 558.111 +            stackTypes.setAll(stack);
 558.112 +        }
 558.113 +
 558.114 +        @Override
 558.115 +        public String toString() {
 558.116 +            return toString(
 558.117 +                       "SAME_LOCALS_1_STACK_ITEM"
 558.118 +                           + ((frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED)
 558.119 +                                  ? "_EXTENDED" : ""),
 558.120 +                       offsetDelta,
 558.121 +                       null, stack);
 558.122 +        }
 558.123 +    }
 558.124 +
 558.125 +    static class ChopFrame extends StackMapTableData {
 558.126 +        ChopFrame(int frameType, int offsetDelta) {
 558.127 +            super(frameType);
 558.128 +            this.offsetDelta = offsetDelta;
 558.129 +        }
 558.130 +
 558.131 +        @Override
 558.132 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 558.133 +            localTypes.setSize(localTypes.getSize()
 558.134 +                                   - (SAME_FRAME_EXTENDED - frameType));
 558.135 +            stackTypes.clear();
 558.136 +        }
 558.137 +
 558.138 +        @Override
 558.139 +        public String toString() {
 558.140 +            return toString("CHOP", offsetDelta, null, null);
 558.141 +        }
 558.142 +    }
 558.143 +
 558.144 +    static class AppendFrame extends StackMapTableData {
 558.145 +        final int[] locals;
 558.146 +        AppendFrame(int frameType, int offsetDelta, int[] locals) {
 558.147 +            super(frameType);
 558.148 +            this.offsetDelta = offsetDelta;
 558.149 +            this.locals = locals;
 558.150 +        }
 558.151 +
 558.152 +        @Override
 558.153 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 558.154 +            localTypes.addAll(locals);
 558.155 +            stackTypes.clear();
 558.156 +        }
 558.157 +
 558.158 +        @Override
 558.159 +        public String toString() {
 558.160 +            return toString("APPEND", offsetDelta, locals, null);
 558.161 +        }
 558.162 +    }
 558.163 +
 558.164 +    static class FullFrame extends StackMapTableData {
 558.165 +        final int[] locals;
 558.166 +        final int[] stack;
 558.167 +        FullFrame(int offsetDelta, int[] locals, int[] stack) {
 558.168 +            super(FULL_FRAME);
 558.169 +            this.offsetDelta = offsetDelta;
 558.170 +            this.locals = locals;
 558.171 +            this.stack = stack;
 558.172 +        }
 558.173 +
 558.174 +        @Override
 558.175 +        void applyTo(TypeArray localTypes, TypeArray stackTypes) {
 558.176 +            localTypes.setAll(locals);
 558.177 +            stackTypes.setAll(stack);
 558.178 +        }
 558.179 +
 558.180 +        @Override
 558.181 +        public String toString() {
 558.182 +            return toString("FULL", offsetDelta, locals, stack);
 558.183 +        }
 558.184 +    }
 558.185 +
 558.186 +    static StackMapTableData getInstance(DataInputStream in, MethodData method)
 558.187 +                  throws IOException {
 558.188 +        int frameType = in.readUnsignedByte();
 558.189 +
 558.190 +        if (frameType < SAME_FRAME_BOUND) {
 558.191 +            // same_frame
 558.192 +            return new SameFrame(frameType, frameType);
 558.193 +        } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
 558.194 +            // same_locals_1_stack_item_frame
 558.195 +            // read additional single stack element
 558.196 +            return new SameLocals1StackItem(frameType,
 558.197 +                                            (frameType - SAME_FRAME_BOUND),
 558.198 +                                            StackMapData.readTypeArray(in, 1, method));
 558.199 +        } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
 558.200 +            // same_locals_1_stack_item_extended
 558.201 +            return new SameLocals1StackItem(frameType,
 558.202 +                                            in.readUnsignedShort(),
 558.203 +                                            StackMapData.readTypeArray(in, 1, method));
 558.204 +        } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType  && frameType < SAME_FRAME_EXTENDED) {
 558.205 +            // chop_frame or same_frame_extended
 558.206 +            return new ChopFrame(frameType, in.readUnsignedShort());
 558.207 +        } else if (frameType == SAME_FRAME_EXTENDED) {
 558.208 +            // chop_frame or same_frame_extended
 558.209 +            return new SameFrame(frameType, in.readUnsignedShort());
 558.210 +        } else if (SAME_FRAME_EXTENDED < frameType  && frameType < FULL_FRAME) {
 558.211 +            // append_frame
 558.212 +            return new AppendFrame(frameType, in.readUnsignedShort(),
 558.213 +                                   StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
 558.214 +        } else if (frameType == FULL_FRAME) {
 558.215 +            // full_frame
 558.216 +            int offsetDelta = in.readUnsignedShort();
 558.217 +            int locals_size = in.readUnsignedShort();
 558.218 +            int[] locals = StackMapData.readTypeArray(in, locals_size, method);
 558.219 +            int stack_size = in.readUnsignedShort();
 558.220 +            int[] stack = StackMapData.readTypeArray(in, stack_size, method);
 558.221 +            return new FullFrame(offsetDelta, locals, stack);
 558.222 +        } else {
 558.223 +            throw new ClassFormatError("unrecognized frame_type in StackMapTable");
 558.224 +        }
 558.225 +    }
 558.226 +}
   559.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   559.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/TrapData.java	Wed Feb 27 11:24:58 2013 +0100
   559.3 @@ -0,0 +1,62 @@
   559.4 +/*
   559.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
   559.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   559.7 + *
   559.8 + * This code is free software; you can redistribute it and/or modify it
   559.9 + * under the terms of the GNU General Public License version 2 only, as
  559.10 + * published by the Free Software Foundation.  Oracle designates this
  559.11 + * particular file as subject to the "Classpath" exception as provided
  559.12 + * by Oracle in the LICENSE file that accompanied this code.
  559.13 + *
  559.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  559.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  559.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  559.17 + * version 2 for more details (a copy is included in the LICENSE file that
  559.18 + * accompanied this code).
  559.19 + *
  559.20 + * You should have received a copy of the GNU General Public License version
  559.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  559.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  559.23 + *
  559.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  559.25 + * or visit www.oracle.com if you need additional information or have any
  559.26 + * questions.
  559.27 + */
  559.28 +
  559.29 +
  559.30 +package org.apidesign.javap;
  559.31 +
  559.32 +import java.io.*;
  559.33 +
  559.34 +/**
  559.35 + * Stores exception table data in code attribute.
  559.36 + *
  559.37 + * @author  Sucheta Dambalkar (Adopted code from jdis)
  559.38 + */
  559.39 +public final class TrapData {
  559.40 +  public final short start_pc;
  559.41 +  public final short end_pc;
  559.42 +  public final short handler_pc;
  559.43 +  public final short catch_cpx;
  559.44 +  final int num;
  559.45 +
  559.46 +
  559.47 +    /**
  559.48 +     * Read and store exception table data in code attribute.
  559.49 +     */
  559.50 +    TrapData(DataInputStream in, int num) throws IOException {
  559.51 +        this.num=num;
  559.52 +        start_pc = in.readShort();
  559.53 +        end_pc=in.readShort();
  559.54 +        handler_pc=in.readShort();
  559.55 +        catch_cpx=in.readShort();
  559.56 +    }
  559.57 +
  559.58 +    /**
  559.59 +     * returns recommended identifier
  559.60 +     */
  559.61 +    public String ident() {
  559.62 +        return "t"+num;
  559.63 +    }
  559.64 +
  559.65 +}
   560.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   560.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/TrapDataIterator.java	Wed Feb 27 11:24:58 2013 +0100
   560.3 @@ -0,0 +1,114 @@
   560.4 +/**
   560.5 + * Back 2 Browser Bytecode Translator
   560.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   560.7 + *
   560.8 + * This program is free software: you can redistribute it and/or modify
   560.9 + * it under the terms of the GNU General Public License as published by
  560.10 + * the Free Software Foundation, version 2 of the License.
  560.11 + *
  560.12 + * This program is distributed in the hope that it will be useful,
  560.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  560.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  560.15 + * GNU General Public License for more details.
  560.16 + *
  560.17 + * You should have received a copy of the GNU General Public License
  560.18 + * along with this program. Look for COPYING file in the top folder.
  560.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  560.20 + */
  560.21 +package org.apidesign.javap;
  560.22 +
  560.23 +/**
  560.24 + *
  560.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  560.26 + */
  560.27 +public final class TrapDataIterator {
  560.28 +    private final Hashtable exStart = new Hashtable();
  560.29 +    private final Hashtable exStop = new Hashtable();
  560.30 +    private TrapData[] current = new TrapData[10];
  560.31 +    private int currentCount;
  560.32 +    
  560.33 +    TrapDataIterator(Vector exceptionTable) {
  560.34 +        for (int i=0 ; i < exceptionTable.size(); i++) {
  560.35 +            final TrapData td = (TrapData)exceptionTable.elementAt(i);
  560.36 +            put(exStart, td.start_pc, td);
  560.37 +            put(exStop, td.end_pc, td);
  560.38 +        }
  560.39 +    }
  560.40 +    
  560.41 +    private static void put(Hashtable h, short key, TrapData td) {
  560.42 +        Short s = Short.valueOf((short)key);
  560.43 +        Vector v = (Vector) h.get(s);
  560.44 +        if (v == null) {
  560.45 +            v = new Vector(1);
  560.46 +            h.put(s, v);
  560.47 +        }
  560.48 +        v.add(td);
  560.49 +    }
  560.50 +    
  560.51 +    private boolean processAll(Hashtable h, Short key, boolean add) {
  560.52 +        boolean change = false;
  560.53 +        Vector v = (Vector)h.get(key);
  560.54 +        if (v != null) {
  560.55 +            int s = v.size();
  560.56 +            for (int i = 0; i < s; i++) {
  560.57 +                TrapData td = (TrapData)v.elementAt(i);
  560.58 +                if (add) {
  560.59 +                    add(td);
  560.60 +                    change = true;
  560.61 +                } else {
  560.62 +                    remove(td);
  560.63 +                    change = true;
  560.64 +                }
  560.65 +            }
  560.66 +        }
  560.67 +        return change;
  560.68 +    }
  560.69 +    
  560.70 +    public boolean advanceTo(int i) {
  560.71 +        Short s = Short.valueOf((short)i);
  560.72 +        boolean ch1 = processAll(exStart, s, true);
  560.73 +        boolean ch2 = processAll(exStop, s, false);
  560.74 +        return ch1 || ch2;
  560.75 +    }
  560.76 +
  560.77 +    public boolean useTry() {
  560.78 +        return currentCount > 0;
  560.79 +    }
  560.80 +
  560.81 +    public TrapData[] current() {
  560.82 +        TrapData[] copy = new TrapData[currentCount];
  560.83 +        for (int i = 0; i < currentCount; i++) {
  560.84 +            copy[i] = current[i];
  560.85 +        }
  560.86 +        return copy;
  560.87 +    }
  560.88 +
  560.89 +    private void add(TrapData e) {
  560.90 +        if (currentCount == current.length) {
  560.91 +            TrapData[] data = new TrapData[currentCount * 2];
  560.92 +            for (int i = 0; i < currentCount; i++) {
  560.93 +                data[i] = current[i];
  560.94 +            }
  560.95 +            current = data;
  560.96 +        }
  560.97 +        current[currentCount++] = e;
  560.98 +    }
  560.99 +
 560.100 +    private void remove(TrapData e) {
 560.101 +        if (currentCount == 0) {
 560.102 +            return;
 560.103 +        }
 560.104 +        int from = 0;
 560.105 +        while (from < currentCount) {
 560.106 +            if (e == current[from++]) {
 560.107 +                break;
 560.108 +            }
 560.109 +        }
 560.110 +        while (from < currentCount) {
 560.111 +            current[from - 1] = current[from];
 560.112 +            current[from] = null;
 560.113 +            from++;
 560.114 +        }
 560.115 +        currentCount--;
 560.116 +    }
 560.117 +}
   561.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   561.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/TypeArray.java	Wed Feb 27 11:24:58 2013 +0100
   561.3 @@ -0,0 +1,186 @@
   561.4 +/*
   561.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   561.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   561.7 + *
   561.8 + * This code is free software; you can redistribute it and/or modify it
   561.9 + * under the terms of the GNU General Public License version 2 only, as
  561.10 + * published by the Free Software Foundation.  Oracle designates this
  561.11 + * particular file as subject to the "Classpath" exception as provided
  561.12 + * by Oracle in the LICENSE file that accompanied this code.
  561.13 + *
  561.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  561.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  561.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  561.17 + * version 2 for more details (a copy is included in the LICENSE file that
  561.18 + * accompanied this code).
  561.19 + *
  561.20 + * You should have received a copy of the GNU General Public License version
  561.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  561.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  561.23 + *
  561.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  561.25 + * or visit www.oracle.com if you need additional information or have any
  561.26 + * questions.
  561.27 + */
  561.28 +
  561.29 +package org.apidesign.javap;
  561.30 +
  561.31 +import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus;
  561.32 +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
  561.33 +import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
  561.34 +import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
  561.35 +import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
  561.36 +import static org.apidesign.javap.RuntimeConstants.ITEM_Null;
  561.37 +import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject;
  561.38 +import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
  561.39 +import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject;
  561.40 +
  561.41 +public final class TypeArray {
  561.42 +    private static final int CAPACITY_INCREMENT = 16;
  561.43 +
  561.44 +    private int[] types;
  561.45 +    private int size;
  561.46 +
  561.47 +    public TypeArray() {
  561.48 +    }
  561.49 +    
  561.50 +    public TypeArray(final TypeArray initialTypes) {
  561.51 +        setAll(initialTypes);
  561.52 +    }
  561.53 +
  561.54 +    public void add(final int newType) {
  561.55 +        ensureCapacity(size + 1);
  561.56 +        types[size++] = newType;
  561.57 +    }
  561.58 +
  561.59 +    public void addAll(final TypeArray newTypes) {
  561.60 +        addAll(newTypes.types, 0, newTypes.size);
  561.61 +    }
  561.62 +
  561.63 +    public void addAll(final int[] newTypes) {
  561.64 +        addAll(newTypes, 0, newTypes.length);
  561.65 +    }
  561.66 +
  561.67 +    public void addAll(final int[] newTypes,
  561.68 +                       final int offset,
  561.69 +                       final int count) {
  561.70 +        if (count > 0) {
  561.71 +            ensureCapacity(size + count);
  561.72 +            arraycopy(newTypes, offset, types, size, count);
  561.73 +            size += count;
  561.74 +        }
  561.75 +    }
  561.76 +
  561.77 +    public void set(final int index, final int newType) {
  561.78 +        types[index] = newType;
  561.79 +    }
  561.80 +
  561.81 +    public void setAll(final TypeArray newTypes) {
  561.82 +        setAll(newTypes.types, 0, newTypes.size);
  561.83 +    }
  561.84 +
  561.85 +    public void setAll(final int[] newTypes) {
  561.86 +        setAll(newTypes, 0, newTypes.length);
  561.87 +    }
  561.88 +
  561.89 +    public void setAll(final int[] newTypes,
  561.90 +                       final int offset,
  561.91 +                       final int count) {
  561.92 +        if (count > 0) {
  561.93 +            ensureCapacity(count);
  561.94 +            arraycopy(newTypes, offset, types, 0, count);
  561.95 +            size = count;
  561.96 +        } else {
  561.97 +            clear();
  561.98 +        }
  561.99 +    }
 561.100 +
 561.101 +    public void setSize(final int newSize) {
 561.102 +        if (size != newSize) {
 561.103 +            ensureCapacity(newSize);
 561.104 +
 561.105 +            for (int i = size; i < newSize; ++i) {
 561.106 +                types[i] = 0;
 561.107 +            }
 561.108 +            size = newSize;
 561.109 +        }
 561.110 +    }
 561.111 +
 561.112 +    public void clear() {
 561.113 +        size = 0;
 561.114 +    }
 561.115 +
 561.116 +    public int getSize() {
 561.117 +        return size;
 561.118 +    }
 561.119 +
 561.120 +    public int get(final int index) {
 561.121 +        return types[index];
 561.122 +    }
 561.123 +
 561.124 +    public static String typeString(final int type) {
 561.125 +        switch (type & 0xff) {
 561.126 +            case ITEM_Bogus:
 561.127 +                return "_top_";
 561.128 +            case ITEM_Integer:
 561.129 +                return "_int_";
 561.130 +            case ITEM_Float:
 561.131 +                return "_float_";
 561.132 +            case ITEM_Double:
 561.133 +                return "_double_";
 561.134 +            case ITEM_Long:
 561.135 +                return "_long_";
 561.136 +            case ITEM_Null:
 561.137 +                return "_null_";
 561.138 +            case ITEM_InitObject: // UninitializedThis
 561.139 +                return "_init_";
 561.140 +            case ITEM_Object:
 561.141 +                return "_object_";
 561.142 +            case ITEM_NewObject: // Uninitialized
 561.143 +                return "_new_";
 561.144 +            default:
 561.145 +                throw new IllegalArgumentException("Unknown type");
 561.146 +        }
 561.147 +    }
 561.148 +
 561.149 +    @Override
 561.150 +    public String toString() {
 561.151 +        final StringBuilder sb = new StringBuilder("[");
 561.152 +        if (size > 0) {
 561.153 +            sb.append(typeString(types[0]));
 561.154 +            for (int i = 1; i < size; ++i) {
 561.155 +                sb.append(", ");
 561.156 +                sb.append(typeString(types[i]));
 561.157 +            }
 561.158 +        }
 561.159 +
 561.160 +        return sb.append(']').toString();
 561.161 +    }
 561.162 +
 561.163 +    private void ensureCapacity(final int minCapacity) {
 561.164 +        if ((minCapacity == 0)
 561.165 +                || (types != null) && (minCapacity <= types.length)) {
 561.166 +            return;
 561.167 +        }
 561.168 +
 561.169 +        final int newCapacity =
 561.170 +                ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT)
 561.171 +                    * CAPACITY_INCREMENT;
 561.172 +        final int[] newTypes = new int[newCapacity];
 561.173 +
 561.174 +        if (size > 0) {
 561.175 +            arraycopy(types, 0, newTypes, 0, size);
 561.176 +        }
 561.177 +
 561.178 +        types = newTypes;
 561.179 +    }
 561.180 +
 561.181 +    // no System.arraycopy
 561.182 +    private void arraycopy(final int[] src, final int srcPos,
 561.183 +                           final int[] dest, final int destPos,
 561.184 +                           final int length) {
 561.185 +        for (int i = 0; i < length; ++i) {
 561.186 +            dest[destPos + i] = src[srcPos + i];
 561.187 +        }
 561.188 +    }
 561.189 +}
   562.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   562.2 +++ b/rt/javap/src/main/java/org/apidesign/javap/Vector.java	Wed Feb 27 11:24:58 2013 +0100
   562.3 @@ -0,0 +1,89 @@
   562.4 +/**
   562.5 + * Back 2 Browser Bytecode Translator
   562.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   562.7 + *
   562.8 + * This program is free software: you can redistribute it and/or modify
   562.9 + * it under the terms of the GNU General Public License as published by
  562.10 + * the Free Software Foundation, version 2 of the License.
  562.11 + *
  562.12 + * This program is distributed in the hope that it will be useful,
  562.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  562.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  562.15 + * GNU General Public License for more details.
  562.16 + *
  562.17 + * You should have received a copy of the GNU General Public License
  562.18 + * along with this program. Look for COPYING file in the top folder.
  562.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  562.20 + */
  562.21 +package org.apidesign.javap;
  562.22 +
  562.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  562.24 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
  562.25 +
  562.26 +/** A JavaScript ready replacement for java.util.Vector
  562.27 + *
  562.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  562.29 + */
  562.30 +@JavaScriptPrototype(prototype = "new Array" )
  562.31 +final class Vector {
  562.32 +    private Object[] arr;
  562.33 +    
  562.34 +    Vector() {
  562.35 +    }
  562.36 +
  562.37 +    Vector(int i) {
  562.38 +    }
  562.39 +
  562.40 +    void add(Object objectType) {
  562.41 +        addElement(objectType);
  562.42 +    }
  562.43 +    @JavaScriptBody(args = { "obj" }, body = 
  562.44 +        "this.push(obj);"
  562.45 +    )
  562.46 +    void addElement(Object obj) {
  562.47 +        final int s = size();
  562.48 +        setSize(s + 1);
  562.49 +        setElementAt(obj, s);
  562.50 +    }
  562.51 +
  562.52 +    @JavaScriptBody(args = { }, body = 
  562.53 +        "return this.length;"
  562.54 +    )
  562.55 +    int size() {
  562.56 +        return arr == null ? 0 : arr.length;
  562.57 +    }
  562.58 +
  562.59 +    @JavaScriptBody(args = { "newArr" }, body =
  562.60 +        "for (var i = 0; i < this.length; i++) {\n"
  562.61 +      + "  newArr[i] = this[i];\n"
  562.62 +      + "}\n")
  562.63 +    void copyInto(Object[] newArr) {
  562.64 +        if (arr == null) {
  562.65 +            return;
  562.66 +        }
  562.67 +        int min = Math.min(newArr.length, arr.length);
  562.68 +        for (int i = 0; i < min; i++) {
  562.69 +            newArr[i] = arr[i];
  562.70 +        }
  562.71 +    }
  562.72 +
  562.73 +    @JavaScriptBody(args = { "index" }, body =
  562.74 +        "return this[index];"
  562.75 +    )
  562.76 +    Object elementAt(int index) {
  562.77 +        return arr[index];
  562.78 +    }
  562.79 +
  562.80 +    private void setSize(int len) {
  562.81 +        Object[] newArr = new Object[len];
  562.82 +        copyInto(newArr);
  562.83 +        arr = newArr;
  562.84 +    }
  562.85 +
  562.86 +    @JavaScriptBody(args = { "val", "index" }, body = 
  562.87 +        "this[index] = val;"
  562.88 +    )
  562.89 +    void setElementAt(Object val, int index) {
  562.90 +        arr[index] = val;
  562.91 +    }
  562.92 +}
   563.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   563.2 +++ b/rt/launcher/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   563.3 @@ -0,0 +1,57 @@
   563.4 +<?xml version="1.0"?>
   563.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"
   563.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   563.7 +  <modelVersion>4.0.0</modelVersion>
   563.8 +  <parent>
   563.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  563.10 +    <artifactId>rt</artifactId>
  563.11 +    <version>0.3-SNAPSHOT</version>
  563.12 +  </parent>
  563.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  563.14 +  <artifactId>launcher</artifactId>
  563.15 +  <version>0.3-SNAPSHOT</version>
  563.16 +  <name>Bck2Brwsr Launcher</name>
  563.17 +  <url>http://maven.apache.org</url>
  563.18 +    <build>
  563.19 +        <plugins>
  563.20 +            <plugin>
  563.21 +                <groupId>org.apache.maven.plugins</groupId>
  563.22 +                <artifactId>maven-compiler-plugin</artifactId>
  563.23 +                <version>2.3.2</version>
  563.24 +                <configuration>
  563.25 +                    <source>1.7</source>
  563.26 +                    <target>1.7</target>
  563.27 +                </configuration>
  563.28 +            </plugin>
  563.29 +            <plugin>
  563.30 +                <groupId>org.apache.maven.plugins</groupId>
  563.31 +                <artifactId>maven-javadoc-plugin</artifactId>
  563.32 +                <version>2.8.1</version>
  563.33 +                <configuration>
  563.34 +                    <excludePackageNames>org.apidesign.bck2brwsr.launcher.impl</excludePackageNames>
  563.35 +                </configuration>
  563.36 +            </plugin>
  563.37 +        </plugins>
  563.38 +    </build>
  563.39 +    <properties>
  563.40 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  563.41 +  </properties>
  563.42 +  <dependencies>
  563.43 +    <dependency>
  563.44 +      <groupId>junit</groupId>
  563.45 +      <artifactId>junit</artifactId>
  563.46 +      <version>3.8.1</version>
  563.47 +      <scope>test</scope>
  563.48 +    </dependency>
  563.49 +    <dependency>
  563.50 +      <groupId>org.glassfish.grizzly</groupId>
  563.51 +      <artifactId>grizzly-http-server</artifactId>
  563.52 +      <version>2.2.19</version>
  563.53 +    </dependency>
  563.54 +    <dependency>
  563.55 +      <groupId>${project.groupId}</groupId>
  563.56 +      <artifactId>vm4brwsr</artifactId>
  563.57 +      <version>${project.version}</version>
  563.58 +    </dependency>
  563.59 +  </dependencies>
  563.60 +</project>
   564.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   564.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Wed Feb 27 11:24:58 2013 +0100
   564.3 @@ -0,0 +1,559 @@
   564.4 +/**
   564.5 + * Back 2 Browser Bytecode Translator
   564.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   564.7 + *
   564.8 + * This program is free software: you can redistribute it and/or modify
   564.9 + * it under the terms of the GNU General Public License as published by
  564.10 + * the Free Software Foundation, version 2 of the License.
  564.11 + *
  564.12 + * This program is distributed in the hope that it will be useful,
  564.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  564.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  564.15 + * GNU General Public License for more details.
  564.16 + *
  564.17 + * You should have received a copy of the GNU General Public License
  564.18 + * along with this program. Look for COPYING file in the top folder.
  564.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  564.20 + */
  564.21 +package org.apidesign.bck2brwsr.launcher;
  564.22 +
  564.23 +import java.io.Closeable;
  564.24 +import java.io.File;
  564.25 +import java.io.IOException;
  564.26 +import java.io.InputStream;
  564.27 +import java.io.InterruptedIOException;
  564.28 +import java.io.OutputStream;
  564.29 +import java.io.Writer;
  564.30 +import java.net.URI;
  564.31 +import java.net.URISyntaxException;
  564.32 +import java.net.URL;
  564.33 +import java.util.ArrayList;
  564.34 +import java.util.Arrays;
  564.35 +import java.util.Enumeration;
  564.36 +import java.util.LinkedHashSet;
  564.37 +import java.util.List;
  564.38 +import java.util.Set;
  564.39 +import java.util.concurrent.BlockingQueue;
  564.40 +import java.util.concurrent.CountDownLatch;
  564.41 +import java.util.concurrent.LinkedBlockingQueue;
  564.42 +import java.util.concurrent.TimeUnit;
  564.43 +import java.util.logging.Level;
  564.44 +import java.util.logging.Logger;
  564.45 +import org.apidesign.bck2brwsr.launcher.InvocationContext.Resource;
  564.46 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  564.47 +import org.glassfish.grizzly.PortRange;
  564.48 +import org.glassfish.grizzly.http.server.HttpHandler;
  564.49 +import org.glassfish.grizzly.http.server.HttpServer;
  564.50 +import org.glassfish.grizzly.http.server.NetworkListener;
  564.51 +import org.glassfish.grizzly.http.server.Request;
  564.52 +import org.glassfish.grizzly.http.server.Response;
  564.53 +import org.glassfish.grizzly.http.server.ServerConfiguration;
  564.54 +import org.glassfish.grizzly.http.util.HttpStatus;
  564.55 +
  564.56 +/**
  564.57 + * Lightweight server to launch Bck2Brwsr applications and tests.
  564.58 + * Supports execution in native browser as well as Java's internal 
  564.59 + * execution engine.
  564.60 + */
  564.61 +final class Bck2BrwsrLauncher extends Launcher implements Closeable {
  564.62 +    private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
  564.63 +    private static final InvocationContext END = new InvocationContext(null, null, null);
  564.64 +    private final Set<ClassLoader> loaders = new LinkedHashSet<>();
  564.65 +    private final BlockingQueue<InvocationContext> methods = new LinkedBlockingQueue<>();
  564.66 +    private long timeOut;
  564.67 +    private final Res resources = new Res();
  564.68 +    private final String cmd;
  564.69 +    private Object[] brwsr;
  564.70 +    private HttpServer server;
  564.71 +    private CountDownLatch wait;
  564.72 +    
  564.73 +    public Bck2BrwsrLauncher(String cmd) {
  564.74 +        this.cmd = cmd;
  564.75 +    }
  564.76 +    
  564.77 +    @Override
  564.78 +    InvocationContext runMethod(InvocationContext c) throws IOException {
  564.79 +        loaders.add(c.clazz.getClassLoader());
  564.80 +        methods.add(c);
  564.81 +        try {
  564.82 +            c.await(timeOut);
  564.83 +        } catch (InterruptedException ex) {
  564.84 +            throw new IOException(ex);
  564.85 +        }
  564.86 +        return c;
  564.87 +    }
  564.88 +    
  564.89 +    public void setTimeout(long ms) {
  564.90 +        timeOut = ms;
  564.91 +    }
  564.92 +    
  564.93 +    public void addClassLoader(ClassLoader url) {
  564.94 +        this.loaders.add(url);
  564.95 +    }
  564.96 +
  564.97 +    public void showURL(String startpage) throws IOException {
  564.98 +        if (!startpage.startsWith("/")) {
  564.99 +            startpage = "/" + startpage;
 564.100 +        }
 564.101 +        HttpServer s = initServer(".", true);
 564.102 +        int last = startpage.lastIndexOf('/');
 564.103 +        String simpleName = startpage.substring(last);
 564.104 +        s.getServerConfiguration().addHttpHandler(new Page(resources, startpage), simpleName);
 564.105 +        s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/");
 564.106 +        try {
 564.107 +            launchServerAndBrwsr(s, simpleName);
 564.108 +        } catch (URISyntaxException | InterruptedException ex) {
 564.109 +            throw new IOException(ex);
 564.110 +        }
 564.111 +    }
 564.112 +
 564.113 +    void showDirectory(File dir, String startpage) throws IOException {
 564.114 +        if (!startpage.startsWith("/")) {
 564.115 +            startpage = "/" + startpage;
 564.116 +        }
 564.117 +        HttpServer s = initServer(dir.getPath(), false);
 564.118 +        try {
 564.119 +            launchServerAndBrwsr(s, startpage);
 564.120 +        } catch (URISyntaxException | InterruptedException ex) {
 564.121 +            throw new IOException(ex);
 564.122 +        }
 564.123 +    }
 564.124 +
 564.125 +    @Override
 564.126 +    public void initialize() throws IOException {
 564.127 +        try {
 564.128 +            executeInBrowser();
 564.129 +        } catch (InterruptedException ex) {
 564.130 +            final InterruptedIOException iio = new InterruptedIOException(ex.getMessage());
 564.131 +            iio.initCause(ex);
 564.132 +            throw iio;
 564.133 +        } catch (Exception ex) {
 564.134 +            if (ex instanceof IOException) {
 564.135 +                throw (IOException)ex;
 564.136 +            }
 564.137 +            if (ex instanceof RuntimeException) {
 564.138 +                throw (RuntimeException)ex;
 564.139 +            }
 564.140 +            throw new IOException(ex);
 564.141 +        }
 564.142 +    }
 564.143 +    
 564.144 +    private HttpServer initServer(String path, boolean addClasses) throws IOException {
 564.145 +        HttpServer s = HttpServer.createSimpleServer(path, new PortRange(8080, 65535));
 564.146 +
 564.147 +        final ServerConfiguration conf = s.getServerConfiguration();
 564.148 +        if (addClasses) {
 564.149 +            conf.addHttpHandler(new VM(resources), "/bck2brwsr.js");
 564.150 +            conf.addHttpHandler(new Classes(resources), "/classes/");
 564.151 +        }
 564.152 +        return s;
 564.153 +    }
 564.154 +    
 564.155 +    private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
 564.156 +        wait = new CountDownLatch(1);
 564.157 +        server = initServer(".", true);
 564.158 +        final ServerConfiguration conf = server.getServerConfiguration();
 564.159 +        
 564.160 +        class DynamicResourceHandler extends HttpHandler {
 564.161 +            private final InvocationContext ic;
 564.162 +            public DynamicResourceHandler(InvocationContext ic) {
 564.163 +                if (ic == null || ic.resources.isEmpty()) {
 564.164 +                    throw new NullPointerException();
 564.165 +                }
 564.166 +                this.ic = ic;
 564.167 +                for (Resource r : ic.resources) {
 564.168 +                    conf.addHttpHandler(this, r.httpPath);
 564.169 +                }
 564.170 +            }
 564.171 +
 564.172 +            public void close() {
 564.173 +                conf.removeHttpHandler(this);
 564.174 +            }
 564.175 +            
 564.176 +            @Override
 564.177 +            public void service(Request request, Response response) throws Exception {
 564.178 +                for (Resource r : ic.resources) {
 564.179 +                    if (r.httpPath.equals(request.getRequestURI())) {
 564.180 +                        LOG.log(Level.INFO, "Serving HttpResource for {0}", request.getRequestURI());
 564.181 +                        response.setContentType(r.httpType);
 564.182 +                        copyStream(r.httpContent, response.getOutputStream(), null);
 564.183 +                    }
 564.184 +                }
 564.185 +            }
 564.186 +        }
 564.187 +        
 564.188 +        conf.addHttpHandler(new Page(resources, 
 564.189 +            "org/apidesign/bck2brwsr/launcher/harness.xhtml"
 564.190 +        ), "/execute");
 564.191 +        
 564.192 +        conf.addHttpHandler(new HttpHandler() {
 564.193 +            int cnt;
 564.194 +            List<InvocationContext> cases = new ArrayList<>();
 564.195 +            DynamicResourceHandler prev;
 564.196 +            @Override
 564.197 +            public void service(Request request, Response response) throws Exception {
 564.198 +                String id = request.getParameter("request");
 564.199 +                String value = request.getParameter("result");
 564.200 +                
 564.201 +                
 564.202 +                InvocationContext mi = null;
 564.203 +                int caseNmbr = -1;
 564.204 +                
 564.205 +                if (id != null && value != null) {
 564.206 +                    LOG.log(Level.INFO, "Received result for case {0} = {1}", new Object[]{id, value});
 564.207 +                    value = decodeURL(value);
 564.208 +                    int indx = Integer.parseInt(id);
 564.209 +                    cases.get(indx).result(value, null);
 564.210 +                    if (++indx < cases.size()) {
 564.211 +                        mi = cases.get(indx);
 564.212 +                        LOG.log(Level.INFO, "Re-executing case {0}", indx);
 564.213 +                        caseNmbr = indx;
 564.214 +                    }
 564.215 +                } else {
 564.216 +                    if (!cases.isEmpty()) {
 564.217 +                        LOG.info("Re-executing test cases");
 564.218 +                        mi = cases.get(0);
 564.219 +                        caseNmbr = 0;
 564.220 +                    }
 564.221 +                }
 564.222 +                
 564.223 +                if (prev != null) {
 564.224 +                    prev.close();
 564.225 +                    prev = null;
 564.226 +                }
 564.227 +                
 564.228 +                if (mi == null) {
 564.229 +                    mi = methods.take();
 564.230 +                    caseNmbr = cnt++;
 564.231 +                }
 564.232 +                if (mi == END) {
 564.233 +                    response.getWriter().write("");
 564.234 +                    wait.countDown();
 564.235 +                    cnt = 0;
 564.236 +                    LOG.log(Level.INFO, "End of data reached. Exiting.");
 564.237 +                    return;
 564.238 +                }
 564.239 +                
 564.240 +                if (!mi.resources.isEmpty()) {
 564.241 +                    prev = new DynamicResourceHandler(mi);
 564.242 +                }
 564.243 +                
 564.244 +                cases.add(mi);
 564.245 +                final String cn = mi.clazz.getName();
 564.246 +                final String mn = mi.methodName;
 564.247 +                LOG.log(Level.INFO, "Request for {0} case. Sending {1}.{2}", new Object[]{caseNmbr, cn, mn});
 564.248 +                response.getWriter().write("{"
 564.249 +                    + "className: '" + cn + "', "
 564.250 +                    + "methodName: '" + mn + "', "
 564.251 +                    + "request: " + caseNmbr
 564.252 +                );
 564.253 +                if (mi.html != null) {
 564.254 +                    response.getWriter().write(", html: '");
 564.255 +                    response.getWriter().write(encodeJSON(mi.html));
 564.256 +                    response.getWriter().write("'");
 564.257 +                }
 564.258 +                response.getWriter().write("}");
 564.259 +            }
 564.260 +        }, "/data");
 564.261 +
 564.262 +        this.brwsr = launchServerAndBrwsr(server, "/execute");
 564.263 +    }
 564.264 +    
 564.265 +    private static String encodeJSON(String in) {
 564.266 +        StringBuilder sb = new StringBuilder();
 564.267 +        for (int i = 0; i < in.length(); i++) {
 564.268 +            char ch = in.charAt(i);
 564.269 +            if (ch < 32 || ch == '\'' || ch == '"') {
 564.270 +                sb.append("\\u");
 564.271 +                String hs = "0000" + Integer.toHexString(ch);
 564.272 +                hs = hs.substring(hs.length() - 4);
 564.273 +                sb.append(hs);
 564.274 +            } else {
 564.275 +                sb.append(ch);
 564.276 +            }
 564.277 +        }
 564.278 +        return sb.toString();
 564.279 +    }
 564.280 +    
 564.281 +    @Override
 564.282 +    public void shutdown() throws IOException {
 564.283 +        methods.offer(END);
 564.284 +        for (;;) {
 564.285 +            int prev = methods.size();
 564.286 +            try {
 564.287 +                if (wait != null && wait.await(timeOut, TimeUnit.MILLISECONDS)) {
 564.288 +                    break;
 564.289 +                }
 564.290 +            } catch (InterruptedException ex) {
 564.291 +                throw new IOException(ex);
 564.292 +            }
 564.293 +            if (prev == methods.size()) {
 564.294 +                LOG.log(
 564.295 +                    Level.WARNING, 
 564.296 +                    "Timeout and no test has been executed meanwhile (at {0}). Giving up.", 
 564.297 +                    methods.size()
 564.298 +                );
 564.299 +                break;
 564.300 +            }
 564.301 +            LOG.log(Level.INFO, 
 564.302 +                "Timeout, but tests got from {0} to {1}. Trying again.", 
 564.303 +                new Object[]{prev, methods.size()}
 564.304 +            );
 564.305 +        }
 564.306 +        stopServerAndBrwsr(server, brwsr);
 564.307 +    }
 564.308 +    
 564.309 +    static void copyStream(InputStream is, OutputStream os, String baseURL, String... params) throws IOException {
 564.310 +        for (;;) {
 564.311 +            int ch = is.read();
 564.312 +            if (ch == -1) {
 564.313 +                break;
 564.314 +            }
 564.315 +            if (ch == '$' && params.length > 0) {
 564.316 +                int cnt = is.read() - '0';
 564.317 +                if (cnt == 'U' - '0') {
 564.318 +                    os.write(baseURL.getBytes("UTF-8"));
 564.319 +                }
 564.320 +                if (cnt >= 0 && cnt < params.length) {
 564.321 +                    os.write(params[cnt].getBytes("UTF-8"));
 564.322 +                }
 564.323 +            } else {
 564.324 +                os.write(ch);
 564.325 +            }
 564.326 +        }
 564.327 +    }
 564.328 +
 564.329 +    private Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
 564.330 +        server.start();
 564.331 +        NetworkListener listener = server.getListeners().iterator().next();
 564.332 +        int port = listener.getPort();
 564.333 +        
 564.334 +        URI uri = new URI("http://localhost:" + port + page);
 564.335 +        LOG.log(Level.INFO, "Showing {0}", uri);
 564.336 +        if (cmd == null) {
 564.337 +            try {
 564.338 +                LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
 564.339 +                    System.getProperty("java.vm.name"),
 564.340 +                    System.getProperty("java.vm.vendor"),
 564.341 +                    System.getProperty("java.vm.version"),
 564.342 +                });
 564.343 +                java.awt.Desktop.getDesktop().browse(uri);
 564.344 +                LOG.log(Level.INFO, "Desktop.browse successfully finished");
 564.345 +                return null;
 564.346 +            } catch (UnsupportedOperationException ex) {
 564.347 +                LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
 564.348 +                LOG.log(Level.FINE, null, ex);
 564.349 +            }
 564.350 +        }
 564.351 +        {
 564.352 +            String cmdName = cmd == null ? "xdg-open" : cmd;
 564.353 +            String[] cmdArr = { 
 564.354 +                cmdName, uri.toString()
 564.355 +            };
 564.356 +            LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
 564.357 +            final Process process = Runtime.getRuntime().exec(cmdArr);
 564.358 +            return new Object[] { process, null };
 564.359 +        }
 564.360 +    }
 564.361 +    
 564.362 +    private static String decodeURL(String s) {
 564.363 +        for (;;) {
 564.364 +            int pos = s.indexOf('%');
 564.365 +            if (pos == -1) {
 564.366 +                return s;
 564.367 +            }
 564.368 +            int i = Integer.parseInt(s.substring(pos + 1, pos + 2), 16);
 564.369 +            s = s.substring(0, pos) + (char)i + s.substring(pos + 2);
 564.370 +        }
 564.371 +    }
 564.372 +    
 564.373 +    private void stopServerAndBrwsr(HttpServer server, Object[] brwsr) throws IOException {
 564.374 +        if (brwsr == null) {
 564.375 +            return;
 564.376 +        }
 564.377 +        Process process = (Process)brwsr[0];
 564.378 +        
 564.379 +        server.stop();
 564.380 +        InputStream stdout = process.getInputStream();
 564.381 +        InputStream stderr = process.getErrorStream();
 564.382 +        drain("StdOut", stdout);
 564.383 +        drain("StdErr", stderr);
 564.384 +        process.destroy();
 564.385 +        int res;
 564.386 +        try {
 564.387 +            res = process.waitFor();
 564.388 +        } catch (InterruptedException ex) {
 564.389 +            throw new IOException(ex);
 564.390 +        }
 564.391 +        LOG.log(Level.INFO, "Exit code: {0}", res);
 564.392 +
 564.393 +        deleteTree((File)brwsr[1]);
 564.394 +    }
 564.395 +    
 564.396 +    private static void drain(String name, InputStream is) throws IOException {
 564.397 +        int av = is.available();
 564.398 +        if (av > 0) {
 564.399 +            StringBuilder sb = new StringBuilder();
 564.400 +            sb.append("v== ").append(name).append(" ==v\n");
 564.401 +            while (av-- > 0) {
 564.402 +                sb.append((char)is.read());
 564.403 +            }
 564.404 +            sb.append("\n^== ").append(name).append(" ==^");
 564.405 +            LOG.log(Level.INFO, sb.toString());
 564.406 +        }
 564.407 +    }
 564.408 +
 564.409 +    private void deleteTree(File file) {
 564.410 +        if (file == null) {
 564.411 +            return;
 564.412 +        }
 564.413 +        File[] arr = file.listFiles();
 564.414 +        if (arr != null) {
 564.415 +            for (File s : arr) {
 564.416 +                deleteTree(s);
 564.417 +            }
 564.418 +        }
 564.419 +        file.delete();
 564.420 +    }
 564.421 +
 564.422 +    @Override
 564.423 +    public void close() throws IOException {
 564.424 +        shutdown();
 564.425 +    }
 564.426 +
 564.427 +    private class Res implements Bck2Brwsr.Resources {
 564.428 +        @Override
 564.429 +        public InputStream get(String resource) throws IOException {
 564.430 +            for (ClassLoader l : loaders) {
 564.431 +                URL u = null;
 564.432 +                Enumeration<URL> en = l.getResources(resource);
 564.433 +                while (en.hasMoreElements()) {
 564.434 +                    u = en.nextElement();
 564.435 +                }
 564.436 +                if (u != null) {
 564.437 +                    return u.openStream();
 564.438 +                }
 564.439 +            }
 564.440 +            throw new IOException("Can't find " + resource);
 564.441 +        }
 564.442 +    }
 564.443 +
 564.444 +    private static class Page extends HttpHandler {
 564.445 +        private final String resource;
 564.446 +        private final String[] args;
 564.447 +        private final Res res;
 564.448 +        
 564.449 +        public Page(Res res, String resource, String... args) {
 564.450 +            this.res = res;
 564.451 +            this.resource = resource;
 564.452 +            this.args = args.length == 0 ? new String[] { "$0" } : args;
 564.453 +        }
 564.454 +
 564.455 +        @Override
 564.456 +        public void service(Request request, Response response) throws Exception {
 564.457 +            String r = resource;
 564.458 +            if (r == null) {
 564.459 +                r = request.getHttpHandlerPath();
 564.460 +            }
 564.461 +            if (r.startsWith("/")) {
 564.462 +                r = r.substring(1);
 564.463 +            }
 564.464 +            String[] replace = {};
 564.465 +            if (r.endsWith(".html")) {
 564.466 +                response.setContentType("text/html");
 564.467 +                LOG.info("Content type text/html");
 564.468 +                replace = args;
 564.469 +            }
 564.470 +            if (r.endsWith(".xhtml")) {
 564.471 +                response.setContentType("application/xhtml+xml");
 564.472 +                LOG.info("Content type application/xhtml+xml");
 564.473 +                replace = args;
 564.474 +            }
 564.475 +            OutputStream os = response.getOutputStream();
 564.476 +            try (InputStream is = res.get(r)) {
 564.477 +                copyStream(is, os, request.getRequestURL().toString(), replace);
 564.478 +            } catch (IOException ex) {
 564.479 +                response.setDetailMessage(ex.getLocalizedMessage());
 564.480 +                response.setError();
 564.481 +                response.setStatus(404);
 564.482 +            }
 564.483 +        }
 564.484 +    }
 564.485 +
 564.486 +    private static class VM extends HttpHandler {
 564.487 +        private final String bck2brwsr;
 564.488 +
 564.489 +        public VM(Res loader) throws IOException {
 564.490 +            StringBuilder sb = new StringBuilder();
 564.491 +            Bck2Brwsr.generate(sb, loader);
 564.492 +            sb.append(
 564.493 +                  "(function WrapperVM(global) {"
 564.494 +                + "  function ldCls(res) {\n"
 564.495 +                + "    var request = new XMLHttpRequest();\n"
 564.496 +                + "    request.open('GET', '/classes/' + res, false);\n"
 564.497 +                + "    request.send();\n"
 564.498 +                + "    if (request.status !== 200) return null;\n"
 564.499 +                + "    var arr = eval('(' + request.responseText + ')');\n"
 564.500 +                + "    return arr;\n"
 564.501 +                + "  }\n"
 564.502 +                + "  var prevvm = global.bck2brwsr;\n"
 564.503 +                + "  global.bck2brwsr = function() {\n"
 564.504 +                + "    var args = Array.prototype.slice.apply(arguments);\n"
 564.505 +                + "    args.unshift(ldCls);\n"
 564.506 +                + "    return prevvm.apply(null, args);\n"
 564.507 +                + "  };\n"
 564.508 +                + "})(this);\n"
 564.509 +            );
 564.510 +            this.bck2brwsr = sb.toString();
 564.511 +        }
 564.512 +
 564.513 +        @Override
 564.514 +        public void service(Request request, Response response) throws Exception {
 564.515 +            response.setCharacterEncoding("UTF-8");
 564.516 +            response.setContentType("text/javascript");
 564.517 +            response.getWriter().write(bck2brwsr);
 564.518 +        }
 564.519 +    }
 564.520 +
 564.521 +    private static class Classes extends HttpHandler {
 564.522 +        private final Res loader;
 564.523 +
 564.524 +        public Classes(Res loader) {
 564.525 +            this.loader = loader;
 564.526 +        }
 564.527 +
 564.528 +        @Override
 564.529 +        public void service(Request request, Response response) throws Exception {
 564.530 +            String res = request.getHttpHandlerPath();
 564.531 +            if (res.startsWith("/")) {
 564.532 +                res = res.substring(1);
 564.533 +            }
 564.534 +            try (InputStream is = loader.get(res)) {
 564.535 +                response.setContentType("text/javascript");
 564.536 +                Writer w = response.getWriter();
 564.537 +                w.append("[");
 564.538 +                for (int i = 0;; i++) {
 564.539 +                    int b = is.read();
 564.540 +                    if (b == -1) {
 564.541 +                        break;
 564.542 +                    }
 564.543 +                    if (i > 0) {
 564.544 +                        w.append(", ");
 564.545 +                    }
 564.546 +                    if (i % 20 == 0) {
 564.547 +                        w.write("\n");
 564.548 +                    }
 564.549 +                    if (b > 127) {
 564.550 +                        b = b - 256;
 564.551 +                    }
 564.552 +                    w.append(Integer.toString(b));
 564.553 +                }
 564.554 +                w.append("\n]");
 564.555 +            } catch (IOException ex) {
 564.556 +                response.setStatus(HttpStatus.NOT_FOUND_404);
 564.557 +                response.setError();
 564.558 +                response.setDetailMessage(ex.getMessage());
 564.559 +            }
 564.560 +        }
 564.561 +    }
 564.562 +}
   565.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   565.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java	Wed Feb 27 11:24:58 2013 +0100
   565.3 @@ -0,0 +1,110 @@
   565.4 +/**
   565.5 + * Back 2 Browser Bytecode Translator
   565.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   565.7 + *
   565.8 + * This program is free software: you can redistribute it and/or modify
   565.9 + * it under the terms of the GNU General Public License as published by
  565.10 + * the Free Software Foundation, version 2 of the License.
  565.11 + *
  565.12 + * This program is distributed in the hope that it will be useful,
  565.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  565.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  565.15 + * GNU General Public License for more details.
  565.16 + *
  565.17 + * You should have received a copy of the GNU General Public License
  565.18 + * along with this program. Look for COPYING file in the top folder.
  565.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  565.20 + */
  565.21 +package org.apidesign.bck2brwsr.launcher;
  565.22 +
  565.23 +import java.io.IOException;
  565.24 +import java.io.InputStream;
  565.25 +import java.util.ArrayList;
  565.26 +import java.util.List;
  565.27 +import java.util.concurrent.CountDownLatch;
  565.28 +import java.util.concurrent.TimeUnit;
  565.29 +
  565.30 +/** Represents individual method invocation, its context and its result.
  565.31 + *
  565.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  565.33 + */
  565.34 +public final class InvocationContext {
  565.35 +    final CountDownLatch wait = new CountDownLatch(1);
  565.36 +    final Class<?> clazz;
  565.37 +    final String methodName;
  565.38 +    private final Launcher launcher;
  565.39 +    private String result;
  565.40 +    private Throwable exception;
  565.41 +    String html;
  565.42 +    final List<Resource> resources = new ArrayList<>();
  565.43 +
  565.44 +    InvocationContext(Launcher launcher, Class<?> clazz, String methodName) {
  565.45 +        this.launcher = launcher;
  565.46 +        this.clazz = clazz;
  565.47 +        this.methodName = methodName;
  565.48 +    }
  565.49 +    
  565.50 +    /** An HTML fragment to be available for the execution. Useful primarily when
  565.51 +     * executing in a browser via {@link Launcher#createBrowser(java.lang.String)}.
  565.52 +     * @param html the html fragment
  565.53 +     */
  565.54 +    public void setHtmlFragment(String html) {
  565.55 +        this.html = html;
  565.56 +    }
  565.57 +    
  565.58 +    /** HTTP resource to be available during execution. An invocation may
  565.59 +     * perform an HTTP query and obtain a resource relative to the page.
  565.60 +     */
  565.61 +    public void addHttpResource(String relativePath, String mimeType, InputStream content) {
  565.62 +        if (relativePath == null || mimeType == null || content == null) {
  565.63 +            throw new NullPointerException();
  565.64 +        }
  565.65 +        resources.add(new Resource(content, mimeType, relativePath));
  565.66 +    }
  565.67 +    
  565.68 +    /** Invokes the associated method. 
  565.69 +     * @return the textual result of the invocation
  565.70 +     */
  565.71 +    public String invoke() throws IOException {
  565.72 +        launcher.runMethod(this);
  565.73 +        return toString();
  565.74 +    }
  565.75 +    
  565.76 +    /** Obtains textual result of the invocation.
  565.77 +     * @return text representing the exception or result value
  565.78 +     */
  565.79 +    @Override
  565.80 +    public String toString() {
  565.81 +        if (exception != null) {
  565.82 +            return exception.toString();
  565.83 +        }
  565.84 +        return result;
  565.85 +    }
  565.86 +    
  565.87 +    /**
  565.88 +     * @param timeOut
  565.89 +     * @throws InterruptedException 
  565.90 +     */
  565.91 +    void await(long timeOut) throws InterruptedException {
  565.92 +        wait.await(timeOut, TimeUnit.MILLISECONDS);
  565.93 +    }
  565.94 +    
  565.95 +    void result(String r, Throwable e) {
  565.96 +        this.result = r;
  565.97 +        this.exception = e;
  565.98 +        wait.countDown();
  565.99 +    }
 565.100 +
 565.101 +
 565.102 +    static final class Resource {
 565.103 +        final InputStream httpContent;
 565.104 +        final String httpType;
 565.105 +        final String httpPath;
 565.106 +
 565.107 +        Resource(InputStream httpContent, String httpType, String httpPath) {
 565.108 +            this.httpContent = httpContent;
 565.109 +            this.httpType = httpType;
 565.110 +            this.httpPath = httpPath;
 565.111 +        }
 565.112 +    }
 565.113 +}
   566.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   566.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/JSLauncher.java	Wed Feb 27 11:24:58 2013 +0100
   566.3 @@ -0,0 +1,132 @@
   566.4 +/**
   566.5 + * Back 2 Browser Bytecode Translator
   566.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   566.7 + *
   566.8 + * This program is free software: you can redistribute it and/or modify
   566.9 + * it under the terms of the GNU General Public License as published by
  566.10 + * the Free Software Foundation, version 2 of the License.
  566.11 + *
  566.12 + * This program is distributed in the hope that it will be useful,
  566.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  566.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  566.15 + * GNU General Public License for more details.
  566.16 + *
  566.17 + * You should have received a copy of the GNU General Public License
  566.18 + * along with this program. Look for COPYING file in the top folder.
  566.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  566.20 + */
  566.21 +package org.apidesign.bck2brwsr.launcher;
  566.22 +
  566.23 +import org.apidesign.bck2brwsr.launcher.impl.Console;
  566.24 +import java.io.IOException;
  566.25 +import java.io.InputStream;
  566.26 +import java.net.URL;
  566.27 +import java.util.Enumeration;
  566.28 +import java.util.LinkedHashSet;
  566.29 +import java.util.Set;
  566.30 +import java.util.logging.Level;
  566.31 +import java.util.logging.Logger;
  566.32 +import javax.script.Invocable;
  566.33 +import javax.script.ScriptEngine;
  566.34 +import javax.script.ScriptEngineManager;
  566.35 +import javax.script.ScriptException;
  566.36 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  566.37 +
  566.38 +/**
  566.39 + * Tests execution in Java's internal scripting engine.
  566.40 + */
  566.41 +final class JSLauncher extends Launcher {
  566.42 +    private static final Logger LOG = Logger.getLogger(JSLauncher.class.getName());
  566.43 +    private Set<ClassLoader> loaders = new LinkedHashSet<>();
  566.44 +    private final Res resources = new Res();
  566.45 +    private Invocable code;
  566.46 +    private StringBuilder codeSeq;
  566.47 +    private Object console;
  566.48 +    
  566.49 +    
  566.50 +    @Override InvocationContext runMethod(InvocationContext mi) {
  566.51 +        loaders.add(mi.clazz.getClassLoader());
  566.52 +        try {
  566.53 +            long time = System.currentTimeMillis();
  566.54 +            LOG.log(Level.FINE, "Invoking {0}.{1}", new Object[]{mi.clazz.getName(), mi.methodName});
  566.55 +            String res = code.invokeMethod(
  566.56 +                console,
  566.57 +                "invoke__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2",
  566.58 +                mi.clazz.getName(), mi.methodName).toString();
  566.59 +            time = System.currentTimeMillis() - time;
  566.60 +            LOG.log(Level.FINE, "Resut of {0}.{1} = {2} in {3} ms", new Object[]{mi.clazz.getName(), mi.methodName, res, time});
  566.61 +            mi.result(res, null);
  566.62 +        } catch (ScriptException | NoSuchMethodException ex) {
  566.63 +            mi.result(null, ex);
  566.64 +        }
  566.65 +        return mi;
  566.66 +    }
  566.67 +    
  566.68 +    public void addClassLoader(ClassLoader url) {
  566.69 +        this.loaders.add(url);
  566.70 +    }
  566.71 +
  566.72 +    @Override
  566.73 +    public void initialize() throws IOException {
  566.74 +        try {
  566.75 +            initRhino();
  566.76 +        } catch (Exception ex) {
  566.77 +            if (ex instanceof IOException) {
  566.78 +                throw (IOException)ex;
  566.79 +            }
  566.80 +            if (ex instanceof RuntimeException) {
  566.81 +                throw (RuntimeException)ex;
  566.82 +            }
  566.83 +            throw new IOException(ex);
  566.84 +        }
  566.85 +    }
  566.86 +    
  566.87 +    private void initRhino() throws IOException, ScriptException, NoSuchMethodException {
  566.88 +        StringBuilder sb = new StringBuilder();
  566.89 +        Bck2Brwsr.generate(sb, new Res());
  566.90 +
  566.91 +        ScriptEngineManager sem = new ScriptEngineManager();
  566.92 +        ScriptEngine mach = sem.getEngineByExtension("js");
  566.93 +
  566.94 +        sb.append(
  566.95 +              "\nvar vm = new bck2brwsr(org.apidesign.bck2brwsr.launcher.impl.Console.read);"
  566.96 +            + "\nfunction initVM() { return vm; };"
  566.97 +            + "\n");
  566.98 +
  566.99 +        Object res = mach.eval(sb.toString());
 566.100 +        if (!(mach instanceof Invocable)) {
 566.101 +            throw new IOException("It is invocable object: " + res);
 566.102 +        }
 566.103 +        code = (Invocable) mach;
 566.104 +        codeSeq = sb;
 566.105 +        
 566.106 +        Object vm = code.invokeFunction("initVM");
 566.107 +        console = code.invokeMethod(vm, "loadClass", Console.class.getName());
 566.108 +    }
 566.109 +
 566.110 +    @Override
 566.111 +    public void shutdown() throws IOException {
 566.112 +    }
 566.113 +
 566.114 +    @Override
 566.115 +    public String toString() {
 566.116 +        return codeSeq.toString();
 566.117 +    }
 566.118 +    
 566.119 +    private class Res implements Bck2Brwsr.Resources {
 566.120 +        @Override
 566.121 +        public InputStream get(String resource) throws IOException {
 566.122 +            for (ClassLoader l : loaders) {
 566.123 +                URL u = null;
 566.124 +                Enumeration<URL> en = l.getResources(resource);
 566.125 +                while (en.hasMoreElements()) {
 566.126 +                    u = en.nextElement();
 566.127 +                }
 566.128 +                if (u != null) {
 566.129 +                    return u.openStream();
 566.130 +                }
 566.131 +            }
 566.132 +            throw new IOException("Can't find " + resource);
 566.133 +        }
 566.134 +    }
 566.135 +}
   567.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   567.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Wed Feb 27 11:24:58 2013 +0100
   567.3 @@ -0,0 +1,115 @@
   567.4 +/**
   567.5 + * Back 2 Browser Bytecode Translator
   567.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   567.7 + *
   567.8 + * This program is free software: you can redistribute it and/or modify
   567.9 + * it under the terms of the GNU General Public License as published by
  567.10 + * the Free Software Foundation, version 2 of the License.
  567.11 + *
  567.12 + * This program is distributed in the hope that it will be useful,
  567.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  567.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  567.15 + * GNU General Public License for more details.
  567.16 + *
  567.17 + * You should have received a copy of the GNU General Public License
  567.18 + * along with this program. Look for COPYING file in the top folder.
  567.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  567.20 + */
  567.21 +package org.apidesign.bck2brwsr.launcher;
  567.22 +
  567.23 +import java.io.Closeable;
  567.24 +import java.io.File;
  567.25 +import java.io.IOException;
  567.26 +import java.net.URLClassLoader;
  567.27 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  567.28 +
  567.29 +/** An abstraction for executing tests in a Bck2Brwsr virtual machine.
  567.30 + * Either in {@linkm Launcher#createJavaScript JavaScript engine}, 
  567.31 + * or in {@linkm Launcher#createBrowser external browser}.
  567.32 + *
  567.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  567.34 + */
  567.35 +public abstract class Launcher {
  567.36 +
  567.37 +    Launcher() {
  567.38 +    }
  567.39 +
  567.40 +    /** Initializes the launcher. This may mean starting a web browser or
  567.41 +     * initializing execution engine.
  567.42 +     * @throws IOException if something goes wrong
  567.43 +     */
  567.44 +    public abstract void initialize() throws IOException;
  567.45 +    
  567.46 +    /** Shuts down the launcher.
  567.47 +     * @throws IOException if something goes wrong
  567.48 +     */
  567.49 +    public abstract void shutdown() throws IOException;
  567.50 +    
  567.51 +    
  567.52 +    /** Builds an invocation context. The context can later be customized
  567.53 +     * and {@link InvocationContext#invoke() invoked}.
  567.54 +     * 
  567.55 +     * @param clazz the class to execute method from
  567.56 +     * @param method the method to execute
  567.57 +     * @return the context pointing to the selected method
  567.58 +     */
  567.59 +    public InvocationContext createInvocation(Class<?> clazz, String method) {
  567.60 +        return new InvocationContext(this, clazz, method);
  567.61 +    }
  567.62 +    
  567.63 +
  567.64 +    /** Creates launcher that uses internal JavaScript engine (Rhino).
  567.65 +     * @return the launcher
  567.66 +     */
  567.67 +    public static Launcher createJavaScript() {
  567.68 +        final JSLauncher l = new JSLauncher();
  567.69 +        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
  567.70 +        return l;
  567.71 +    }
  567.72 +    
  567.73 +    /** Creates launcher that is using external browser.
  567.74 +     * 
  567.75 +     * @param cmd <code>null</code> to use <code>java.awt.Desktop</code> to show the launcher
  567.76 +     *    or a string to execute in an external process (with a parameter to the URL)
  567.77 +     * @return launcher executing in external browser.
  567.78 +     */
  567.79 +    public static Launcher createBrowser(String cmd) {
  567.80 +        final Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(cmd);
  567.81 +        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
  567.82 +        l.setTimeout(180000);
  567.83 +        return l;
  567.84 +    }
  567.85 +    
  567.86 +    /** Starts an HTTP server which provides access to classes and resources
  567.87 +     * available in the <code>classes</code> URL and shows a start page
  567.88 +     * available as {@link ClassLoader#getResource(java.lang.String)} from the
  567.89 +     * provide classloader. Opens a browser with URL showing the start page.
  567.90 +     * 
  567.91 +     * @param classes classloader offering access to classes and resources
  567.92 +     * @param startpage page to show in the browser
  567.93 +     * @return interface that allows one to stop the server
  567.94 +     * @throws IOException if something goes wrong
  567.95 +     */
  567.96 +    public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
  567.97 +        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
  567.98 +        l.addClassLoader(classes);
  567.99 +        l.showURL(startpage);
 567.100 +        return l;
 567.101 +    }
 567.102 +    /** Starts an HTTP server which provides access to certain directory.
 567.103 +     * The <code>startpage</code> should be relative location inside the root 
 567.104 +     * driecotry
 567.105 +     * Opens a browser with URL showing the start page.
 567.106 +     * 
 567.107 +     * @param directory the root directory on disk
 567.108 +     * @praam startpage relative path from the root to the page
 567.109 +     * @exception IOException if something goes wrong.
 567.110 +     */
 567.111 +    public static Closeable showDir(File directory, String startpage) throws IOException {
 567.112 +        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null);
 567.113 +        l.showDirectory(directory, startpage);
 567.114 +        return l;
 567.115 +    }
 567.116 +
 567.117 +    abstract InvocationContext runMethod(InvocationContext c) throws IOException; 
 567.118 +}
   568.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   568.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java	Wed Feb 27 11:24:58 2013 +0100
   568.3 @@ -0,0 +1,255 @@
   568.4 +/**
   568.5 + * Back 2 Browser Bytecode Translator
   568.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   568.7 + *
   568.8 + * This program is free software: you can redistribute it and/or modify
   568.9 + * it under the terms of the GNU General Public License as published by
  568.10 + * the Free Software Foundation, version 2 of the License.
  568.11 + *
  568.12 + * This program is distributed in the hope that it will be useful,
  568.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  568.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  568.15 + * GNU General Public License for more details.
  568.16 + *
  568.17 + * You should have received a copy of the GNU General Public License
  568.18 + * along with this program. Look for COPYING file in the top folder.
  568.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  568.20 + */
  568.21 +package org.apidesign.bck2brwsr.launcher.impl;
  568.22 +
  568.23 +import java.io.IOException;
  568.24 +import java.io.InputStream;
  568.25 +import java.lang.reflect.InvocationTargetException;
  568.26 +import java.lang.reflect.Method;
  568.27 +import java.lang.reflect.Modifier;
  568.28 +import java.net.URL;
  568.29 +import java.util.Enumeration;
  568.30 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  568.31 +
  568.32 +/**
  568.33 + *
  568.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  568.35 + */
  568.36 +public class Console {
  568.37 +    private Console() {
  568.38 +    }
  568.39 +    static {
  568.40 +        turnAssetionStatusOn();
  568.41 +    }
  568.42 +    
  568.43 +    @JavaScriptBody(args = {"id", "attr"}, body = 
  568.44 +        "return window.document.getElementById(id)[attr].toString();")
  568.45 +    private static native Object getAttr(String id, String attr);
  568.46 +
  568.47 +    @JavaScriptBody(args = {"id", "attr", "value"}, body = 
  568.48 +        "window.document.getElementById(id)[attr] = value;")
  568.49 +    private static native void setAttr(String id, String attr, Object value);
  568.50 +    
  568.51 +    @JavaScriptBody(args = {}, body = "return; window.close();")
  568.52 +    private static native void closeWindow();
  568.53 +
  568.54 +    private static void log(String newText) {
  568.55 +        String id = "bck2brwsr.result";
  568.56 +        String attr = "value";
  568.57 +        setAttr(id, attr, getAttr(id, attr) + "\n" + newText);
  568.58 +        setAttr(id, "scrollTop", getAttr(id, "scrollHeight"));
  568.59 +    }
  568.60 +    
  568.61 +    public static void execute() throws Exception {
  568.62 +        String clazz = (String) getAttr("clazz", "value");
  568.63 +        String method = (String) getAttr("method", "value");
  568.64 +        Object res = invokeMethod(clazz, method);
  568.65 +        setAttr("bck2brwsr.result", "value", res);
  568.66 +    }
  568.67 +
  568.68 +    @JavaScriptBody(args = { "url", "callback", "arr" }, body = ""
  568.69 +        + "var request = new XMLHttpRequest();\n"
  568.70 +        + "request.open('GET', url, true);\n"
  568.71 +        + "request.onreadystatechange = function() {\n"
  568.72 +        + "  if (this.readyState!==4) return;\n"
  568.73 +        + "  arr[0] = this.responseText;\n"
  568.74 +        + "  callback.run__V();\n"
  568.75 +        + "};"
  568.76 +        + "request.send();"
  568.77 +    )
  568.78 +    private static native void loadText(String url, Runnable callback, String[] arr) throws IOException;
  568.79 +    
  568.80 +    public static void harness(String url) throws IOException {
  568.81 +        log("Connecting to " + url);
  568.82 +        Request r = new Request(url);
  568.83 +    }
  568.84 +    
  568.85 +    private static class Request implements Runnable {
  568.86 +        private final String[] arr = { null };
  568.87 +        private final String url;
  568.88 +
  568.89 +        private Request(String url) throws IOException {
  568.90 +            this.url = url;
  568.91 +            loadText(url, this, arr);
  568.92 +        }
  568.93 +        
  568.94 +        @Override
  568.95 +        public void run() {
  568.96 +            try {
  568.97 +                String data = arr[0];
  568.98 +                log("\nGot \"" + data + "\"");
  568.99 +                
 568.100 +                if (data == null) {
 568.101 +                    log("Some error exiting");
 568.102 +                    closeWindow();
 568.103 +                    return;
 568.104 +                }
 568.105 +                
 568.106 +                if (data.isEmpty()) {
 568.107 +                    log("No data, exiting");
 568.108 +                    closeWindow();
 568.109 +                    return;
 568.110 +                }
 568.111 +                
 568.112 +                Case c = Case.parseData(data);
 568.113 +                if (c.getHtmlFragment() != null) {
 568.114 +                    setAttr("bck2brwsr.fragment", "innerHTML", c.getHtmlFragment());
 568.115 +                }
 568.116 +                log("Invoking " + c.getClassName() + '.' + c.getMethodName() + " as request: " + c.getRequestId());
 568.117 +
 568.118 +                Object result = invokeMethod(c.getClassName(), c.getMethodName());
 568.119 +                
 568.120 +                setAttr("bck2brwsr.fragment", "innerHTML", "");
 568.121 +                log("Result: " + result);
 568.122 +                
 568.123 +                result = encodeURL("" + result);
 568.124 +                
 568.125 +                log("Sending back: " + url + "?request=" + c.getRequestId() + "&result=" + result);
 568.126 +                String u = url + "?request=" + c.getRequestId() + "&result=" + result;
 568.127 +                
 568.128 +                loadText(u, this, arr);
 568.129 +                
 568.130 +            } catch (Exception ex) {
 568.131 +                log(ex.getClass().getName() + ":" + ex.getMessage());
 568.132 +            }
 568.133 +        }
 568.134 +    }
 568.135 +    
 568.136 +    private static String encodeURL(String r) {
 568.137 +        StringBuilder sb = new StringBuilder();
 568.138 +        for (int i = 0; i < r.length(); i++) {
 568.139 +            int ch = r.charAt(i);
 568.140 +            if (ch < 32 || ch == '%' || ch == '+') {
 568.141 +                sb.append("%").append(("0" + Integer.toHexString(ch)).substring(0, 2));
 568.142 +            } else {
 568.143 +                if (ch == 32) {
 568.144 +                    sb.append("+");
 568.145 +                } else {
 568.146 +                    sb.append((char)ch);
 568.147 +                }
 568.148 +            }
 568.149 +        }
 568.150 +        return sb.toString();
 568.151 +    }
 568.152 +    
 568.153 +    static String invoke(String clazz, String method) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
 568.154 +        final Object r = invokeMethod(clazz, method);
 568.155 +        return r == null ? "null" : r.toString().toString();
 568.156 +    }
 568.157 +
 568.158 +    /** Helper method that inspects the classpath and loads given resource
 568.159 +     * (usually a class file). Used while running tests in Rhino.
 568.160 +     * 
 568.161 +     * @param name resource name to find
 568.162 +     * @return the array of bytes in the given resource
 568.163 +     * @throws IOException I/O in case something goes wrong
 568.164 +     */
 568.165 +    public static byte[] read(String name) throws IOException {
 568.166 +        URL u = null;
 568.167 +        Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
 568.168 +        while (en.hasMoreElements()) {
 568.169 +            u = en.nextElement();
 568.170 +        }
 568.171 +        if (u == null) {
 568.172 +            throw new IOException("Can't find " + name);
 568.173 +        }
 568.174 +        try (InputStream is = u.openStream()) {
 568.175 +            byte[] arr;
 568.176 +            arr = new byte[is.available()];
 568.177 +            int offset = 0;
 568.178 +            while (offset < arr.length) {
 568.179 +                int len = is.read(arr, offset, arr.length - offset);
 568.180 +                if (len == -1) {
 568.181 +                    throw new IOException("Can't read " + name);
 568.182 +                }
 568.183 +                offset += len;
 568.184 +            }
 568.185 +            return arr;
 568.186 +        }
 568.187 +    }
 568.188 +   
 568.189 +    private static Object invokeMethod(String clazz, String method) 
 568.190 +    throws ClassNotFoundException, InvocationTargetException, 
 568.191 +    SecurityException, IllegalAccessException, IllegalArgumentException,
 568.192 +    InstantiationException {
 568.193 +        Method found = null;
 568.194 +        Class<?> c = Class.forName(clazz);
 568.195 +        for (Method m : c.getMethods()) {
 568.196 +            if (m.getName().equals(method)) {
 568.197 +                found = m;
 568.198 +            }
 568.199 +        }
 568.200 +        Object res;
 568.201 +        if (found != null) {
 568.202 +            try {
 568.203 +                if ((found.getModifiers() & Modifier.STATIC) != 0) {
 568.204 +                    res = found.invoke(null);
 568.205 +                } else {
 568.206 +                    res = found.invoke(c.newInstance());
 568.207 +                }
 568.208 +            } catch (Throwable ex) {
 568.209 +                res = ex.getClass().getName() + ":" + ex.getMessage();
 568.210 +            }
 568.211 +        } else {
 568.212 +            res = "Can't find method " + method + " in " + clazz;
 568.213 +        }
 568.214 +        return res;
 568.215 +    }
 568.216 +
 568.217 +    @JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
 568.218 +    private static void turnAssetionStatusOn() {
 568.219 +    }
 568.220 +    
 568.221 +    private static final class Case {
 568.222 +        private final Object data;
 568.223 +
 568.224 +        private Case(Object data) {
 568.225 +            this.data = data;
 568.226 +        }
 568.227 +        
 568.228 +        public static Case parseData(String s) {
 568.229 +            return new Case(toJSON(s));
 568.230 +        }
 568.231 +        
 568.232 +        public String getMethodName() {
 568.233 +            return value("methodName", data);
 568.234 +        }
 568.235 +
 568.236 +        public String getClassName() {
 568.237 +            return value("className", data);
 568.238 +        }
 568.239 +        
 568.240 +        public String getRequestId() {
 568.241 +            return value("request", data);
 568.242 +        }
 568.243 +
 568.244 +        public String getHtmlFragment() {
 568.245 +            return value("html", data);
 568.246 +        }
 568.247 +        
 568.248 +        @JavaScriptBody(args = "s", body = "return eval('(' + s + ')');")
 568.249 +        private static native Object toJSON(String s);
 568.250 +        
 568.251 +        @JavaScriptBody(args = {"p", "d"}, body = 
 568.252 +              "var v = d[p];\n"
 568.253 +            + "if (typeof v === 'undefined') return null;\n"
 568.254 +            + "return v.toString();"
 568.255 +        )
 568.256 +        private static native String value(String p, Object d);
 568.257 +    }
 568.258 +}
   569.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   569.2 +++ b/rt/launcher/src/main/resources/org/apidesign/bck2brwsr/launcher/harness.xhtml	Wed Feb 27 11:24:58 2013 +0100
   569.3 @@ -0,0 +1,43 @@
   569.4 +<?xml version="1.0" encoding="UTF-8"?>
   569.5 +<!--
   569.6 +
   569.7 +    Back 2 Browser Bytecode Translator
   569.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   569.9 +
  569.10 +    This program is free software: you can redistribute it and/or modify
  569.11 +    it under the terms of the GNU General Public License as published by
  569.12 +    the Free Software Foundation, version 2 of the License.
  569.13 +
  569.14 +    This program is distributed in the hope that it will be useful,
  569.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  569.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  569.17 +    GNU General Public License for more details.
  569.18 +
  569.19 +    You should have received a copy of the GNU General Public License
  569.20 +    along with this program. Look for COPYING file in the top folder.
  569.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  569.22 +
  569.23 +-->
  569.24 +<!DOCTYPE html>
  569.25 +<html xmlns="http://www.w3.org/1999/xhtml">
  569.26 +    <head>
  569.27 +        <title>Bck2Brwsr Harness</title>
  569.28 +    </head>
  569.29 +    <body>
  569.30 +        <script src="/bck2brwsr.js"></script>
  569.31 +        <script>
  569.32 +            var vm = bck2brwsr();
  569.33 +        </script>
  569.34 +        
  569.35 +        <h1>Bck2Brwsr Execution Harness</h1>
  569.36 +        
  569.37 +        <textarea id="bck2brwsr.result" rows="25" style="width: 100%;" disabled="">
  569.38 +        </textarea>
  569.39 +
  569.40 +        <div id="bck2brwsr.fragment"/>
  569.41 +        
  569.42 +        <script type="text/javascript">
  569.43 +            vm.loadClass('org.apidesign.bck2brwsr.launcher.impl.Console').harness__VLjava_lang_String_2('$U/../data');
  569.44 +        </script>
  569.45 +    </body>
  569.46 +</html>
   570.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   570.2 +++ b/rt/mojo/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   570.3 @@ -0,0 +1,86 @@
   570.4 +<?xml version="1.0"?>
   570.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"
   570.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   570.7 +  <modelVersion>4.0.0</modelVersion>
   570.8 +  <parent>
   570.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  570.10 +    <artifactId>rt</artifactId>
  570.11 +    <version>0.3-SNAPSHOT</version>
  570.12 +  </parent>
  570.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  570.14 +  <artifactId>mojo</artifactId>
  570.15 +  <version>0.3-SNAPSHOT</version>
  570.16 +  <packaging>maven-plugin</packaging>
  570.17 +  <name>Bck2Brwsr Maven Project</name>
  570.18 +  <url>http://maven.apache.org</url>
  570.19 +      <build>
  570.20 +        <plugins>
  570.21 +            <plugin>
  570.22 +                <groupId>org.apache.maven.plugins</groupId>
  570.23 +                <artifactId>maven-plugin-plugin</artifactId>
  570.24 +                <version>3.1</version>
  570.25 +                <configuration>
  570.26 +                    <extractors>
  570.27 +                        <extractor>java-annotations</extractor>
  570.28 +                    </extractors>
  570.29 +                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
  570.30 +                 </configuration>
  570.31 +                <executions>
  570.32 +                    <execution>
  570.33 +                        <id>mojo-descriptor</id>
  570.34 +                        <phase>process-classes</phase>
  570.35 +                        <goals>
  570.36 +                            <goal>descriptor</goal>
  570.37 +                        </goals>
  570.38 +                    </execution>
  570.39 +                </executions>
  570.40 +            </plugin>
  570.41 +            <plugin>
  570.42 +                <groupId>org.apache.maven.plugins</groupId>
  570.43 +                <artifactId>maven-compiler-plugin</artifactId>
  570.44 +                <version>2.3.2</version>
  570.45 +                <configuration>
  570.46 +                    <source>1.6</source>
  570.47 +                    <target>1.6</target>
  570.48 +                </configuration>
  570.49 +            </plugin>
  570.50 +        </plugins>
  570.51 +      </build>
  570.52 +      
  570.53 +<dependencies>
  570.54 +    <dependency>
  570.55 +      <groupId>org.apache.maven</groupId>
  570.56 +      <artifactId>maven-plugin-api</artifactId>
  570.57 +      <version>3.0.4</version>
  570.58 +      <type>jar</type>
  570.59 +    </dependency>
  570.60 +    <dependency>
  570.61 +      <groupId>org.apache.maven.plugin-tools</groupId>
  570.62 +      <artifactId>maven-plugin-annotations</artifactId>
  570.63 +      <version>3.0</version>
  570.64 +      <type>jar</type>
  570.65 +    </dependency>
  570.66 +    <dependency>
  570.67 +      <groupId>${project.groupId}</groupId>
  570.68 +      <artifactId>vm4brwsr</artifactId>
  570.69 +      <version>0.3-SNAPSHOT</version>
  570.70 +      <exclusions>
  570.71 +        <exclusion>
  570.72 +          <artifactId>emul.mini</artifactId>
  570.73 +          <groupId>org.apidesign.bck2brwsr</groupId>
  570.74 +        </exclusion>
  570.75 +      </exclusions>
  570.76 +    </dependency>
  570.77 +    <dependency>
  570.78 +        <groupId>org.apache.maven</groupId>
  570.79 +        <artifactId>maven-core</artifactId>
  570.80 +      <version>3.0.2</version>
  570.81 +      <type>jar</type>
  570.82 +    </dependency>
  570.83 +    <dependency>
  570.84 +        <groupId>${project.groupId}</groupId>
  570.85 +        <artifactId>launcher</artifactId>
  570.86 +      <version>${project.version}</version>
  570.87 +    </dependency>
  570.88 +</dependencies>
  570.89 +</project>
   571.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   571.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Wed Feb 27 11:24:58 2013 +0100
   571.3 @@ -0,0 +1,99 @@
   571.4 +/**
   571.5 + * Back 2 Browser Bytecode Translator
   571.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   571.7 + *
   571.8 + * This program is free software: you can redistribute it and/or modify
   571.9 + * it under the terms of the GNU General Public License as published by
  571.10 + * the Free Software Foundation, version 2 of the License.
  571.11 + *
  571.12 + * This program is distributed in the hope that it will be useful,
  571.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  571.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  571.15 + * GNU General Public License for more details.
  571.16 + *
  571.17 + * You should have received a copy of the GNU General Public License
  571.18 + * along with this program. Look for COPYING file in the top folder.
  571.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  571.20 + */
  571.21 +package org.apidesign.bck2brwsr.mojo;
  571.22 +
  571.23 +import java.io.Closeable;
  571.24 +import org.apache.maven.plugin.AbstractMojo;
  571.25 +
  571.26 +import java.io.File;
  571.27 +import java.io.IOException;
  571.28 +import java.net.MalformedURLException;
  571.29 +import java.net.URL;
  571.30 +import java.net.URLClassLoader;
  571.31 +import java.util.ArrayList;
  571.32 +import java.util.Collection;
  571.33 +import java.util.List;
  571.34 +import org.apache.maven.artifact.Artifact;
  571.35 +import org.apache.maven.plugin.MojoExecutionException;
  571.36 +import org.apache.maven.plugins.annotations.LifecyclePhase;
  571.37 +import org.apache.maven.plugins.annotations.Mojo;
  571.38 +import org.apache.maven.plugins.annotations.Parameter;
  571.39 +import org.apache.maven.project.MavenProject;
  571.40 +import org.apidesign.bck2brwsr.launcher.Launcher;
  571.41 +
  571.42 +/** Executes given HTML page in a browser. */
  571.43 +@Mojo(name="brwsr", defaultPhase=LifecyclePhase.NONE)
  571.44 +public class BrswrMojo extends AbstractMojo {
  571.45 +    public BrswrMojo() {
  571.46 +    }
  571.47 +    /** Resource to show as initial page */
  571.48 +    @Parameter
  571.49 +    private String startpage;
  571.50 +
  571.51 +    @Parameter(defaultValue="${project}")
  571.52 +    private MavenProject prj;
  571.53 +    
  571.54 +    /** Root of the class files */
  571.55 +    @Parameter(defaultValue="${project.build.directory}/classes")
  571.56 +    private File classes;
  571.57 +    
  571.58 +    /** Root of all pages, and files, etc. */
  571.59 +    @Parameter
  571.60 +    private File directory;
  571.61 +
  571.62 +    @Override
  571.63 +    public void execute() throws MojoExecutionException {
  571.64 +        if (startpage == null) {
  571.65 +            throw new MojoExecutionException("You have to provide a start page");
  571.66 +        }
  571.67 +        
  571.68 +        try {
  571.69 +            Closeable httpServer;
  571.70 +            if (directory != null) {
  571.71 +                httpServer = Launcher.showDir(directory, startpage);
  571.72 +            } else {
  571.73 +                URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
  571.74 +                try {
  571.75 +                    httpServer = Launcher.showURL(url, startpage());
  571.76 +                } catch (Exception ex) {
  571.77 +                    throw new MojoExecutionException("Can't open " + startpage(), ex);
  571.78 +                }
  571.79 +            }
  571.80 +            System.in.read();
  571.81 +            httpServer.close();
  571.82 +        } catch (IOException ex) {
  571.83 +            throw new MojoExecutionException("Can't show the browser", ex);
  571.84 +        }
  571.85 +    }
  571.86 +    
  571.87 +    private String startpage() {
  571.88 +        return startpage;
  571.89 +    }
  571.90 +
  571.91 +    private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
  571.92 +        List<URL> arr = new ArrayList<URL>();
  571.93 +        arr.add(root.toURI().toURL());
  571.94 +        for (Artifact a : deps) {
  571.95 +            final File f = a.getFile();
  571.96 +            if (f != null) {
  571.97 +                arr.add(f.toURI().toURL());
  571.98 +            }
  571.99 +        }
 571.100 +        return new URLClassLoader(arr.toArray(new URL[0]), BrswrMojo.class.getClassLoader());
 571.101 +    }
 571.102 +}
   572.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   572.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java	Wed Feb 27 11:24:58 2013 +0100
   572.3 @@ -0,0 +1,122 @@
   572.4 +/**
   572.5 + * Back 2 Browser Bytecode Translator
   572.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   572.7 + *
   572.8 + * This program is free software: you can redistribute it and/or modify
   572.9 + * it under the terms of the GNU General Public License as published by
  572.10 + * the Free Software Foundation, version 2 of the License.
  572.11 + *
  572.12 + * This program is distributed in the hope that it will be useful,
  572.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  572.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  572.15 + * GNU General Public License for more details.
  572.16 + *
  572.17 + * You should have received a copy of the GNU General Public License
  572.18 + * along with this program. Look for COPYING file in the top folder.
  572.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  572.20 + */
  572.21 +package org.apidesign.bck2brwsr.mojo;
  572.22 +
  572.23 +import org.apache.maven.plugin.AbstractMojo;
  572.24 +
  572.25 +import java.io.File;
  572.26 +import java.io.FileWriter;
  572.27 +import java.io.IOException;
  572.28 +import java.net.MalformedURLException;
  572.29 +import java.net.URL;
  572.30 +import java.net.URLClassLoader;
  572.31 +import java.util.ArrayList;
  572.32 +import java.util.Collection;
  572.33 +import java.util.List;
  572.34 +import org.apache.maven.artifact.Artifact;
  572.35 +import org.apache.maven.plugin.MojoExecutionException;
  572.36 +import org.apache.maven.plugins.annotations.LifecyclePhase;
  572.37 +import org.apache.maven.plugins.annotations.Mojo;
  572.38 +import org.apache.maven.plugins.annotations.Parameter;
  572.39 +import org.apache.maven.project.MavenProject;
  572.40 +import org.apidesign.vm4brwsr.Bck2Brwsr;
  572.41 +
  572.42 +/** Compiles classes into JavaScript. */
  572.43 +@Mojo(name="j2js", defaultPhase=LifecyclePhase.PROCESS_CLASSES)
  572.44 +public class Java2JavaScript extends AbstractMojo {
  572.45 +    public Java2JavaScript() {
  572.46 +    }
  572.47 +    /** Root of the class files */
  572.48 +    @Parameter(defaultValue="${project.build.directory}/classes")
  572.49 +    private File classes;
  572.50 +    /** File to generate. Defaults bootjava.js in the first non-empty 
  572.51 +     package under the classes directory */
  572.52 +    @Parameter
  572.53 +    private File javascript;
  572.54 +    
  572.55 +    @Parameter(defaultValue="${project}")
  572.56 +    private MavenProject prj;
  572.57 +    
  572.58 +    
  572.59 +
  572.60 +    @Override
  572.61 +    public void execute() throws MojoExecutionException {
  572.62 +        if (!classes.isDirectory()) {
  572.63 +            throw new MojoExecutionException("Can't find " + classes);
  572.64 +        }
  572.65 +
  572.66 +        if (javascript == null) {
  572.67 +            javascript = new File(findNonEmptyFolder(classes), "bootjava.js");
  572.68 +        }
  572.69 +
  572.70 +        List<String> arr = new ArrayList<String>();
  572.71 +        long newest = collectAllClasses("", classes, arr);
  572.72 +        
  572.73 +        if (javascript.lastModified() > newest) {
  572.74 +            return;
  572.75 +        }
  572.76 +
  572.77 +        try {
  572.78 +            URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
  572.79 +            FileWriter w = new FileWriter(javascript);
  572.80 +            Bck2Brwsr.generate(w, url, arr.toArray(new String[0]));
  572.81 +            w.close();
  572.82 +        } catch (IOException ex) {
  572.83 +            throw new MojoExecutionException("Can't compile", ex);
  572.84 +        }
  572.85 +    }
  572.86 +
  572.87 +    private static File findNonEmptyFolder(File dir) throws MojoExecutionException {
  572.88 +        if (!dir.isDirectory()) {
  572.89 +            throw new MojoExecutionException("Not a directory " + dir);
  572.90 +        }
  572.91 +        File[] arr = dir.listFiles();
  572.92 +        if (arr.length == 1 && arr[0].isDirectory()) {
  572.93 +            return findNonEmptyFolder(arr[0]);
  572.94 +        }
  572.95 +        return dir;
  572.96 +    }
  572.97 +
  572.98 +    private static long collectAllClasses(String prefix, File toCheck, List<String> arr) {
  572.99 +        File[] files = toCheck.listFiles();
 572.100 +        if (files != null) {
 572.101 +            long newest = 0L;
 572.102 +            for (File f : files) {
 572.103 +                long lastModified = collectAllClasses(prefix + f.getName() + "/", f, arr);
 572.104 +                if (newest < lastModified) {
 572.105 +                    newest = lastModified;
 572.106 +                }
 572.107 +            }
 572.108 +            return newest;
 572.109 +        } else if (toCheck.getName().endsWith(".class")) {
 572.110 +            arr.add(prefix.substring(0, prefix.length() - 7));
 572.111 +            return toCheck.lastModified();
 572.112 +        } else {
 572.113 +            return 0L;
 572.114 +        }
 572.115 +    }
 572.116 +
 572.117 +    private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
 572.118 +        List<URL> arr = new ArrayList<URL>();
 572.119 +        arr.add(root.toURI().toURL());
 572.120 +        for (Artifact a : deps) {
 572.121 +            arr.add(a.getFile().toURI().toURL());
 572.122 +        }
 572.123 +        return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
 572.124 +    }
 572.125 +}
   573.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   573.2 +++ b/rt/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml	Wed Feb 27 11:24:58 2013 +0100
   573.3 @@ -0,0 +1,55 @@
   573.4 +<?xml version="1.0" encoding="UTF-8"?>
   573.5 +<!--
   573.6 +
   573.7 +    Back 2 Browser Bytecode Translator
   573.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   573.9 +
  573.10 +    This program is free software: you can redistribute it and/or modify
  573.11 +    it under the terms of the GNU General Public License as published by
  573.12 +    the Free Software Foundation, version 2 of the License.
  573.13 +
  573.14 +    This program is distributed in the hope that it will be useful,
  573.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  573.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  573.17 +    GNU General Public License for more details.
  573.18 +
  573.19 +    You should have received a copy of the GNU General Public License
  573.20 +    along with this program. Look for COPYING file in the top folder.
  573.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  573.22 +
  573.23 +-->
  573.24 +<archetype-descriptor name="bck2brwsr">
  573.25 +  <fileSets>
  573.26 +    <fileSet filtered="true" packaged="true">
  573.27 +      <directory>src/main/java</directory>
  573.28 +      <includes>
  573.29 +        <include>**/App.java</include>
  573.30 +      </includes>
  573.31 +    </fileSet>
  573.32 +    <fileSet filtered="true" packaged="true">
  573.33 +      <directory>src/main/resources</directory>
  573.34 +      <includes>
  573.35 +        <include>**/*.xhtml</include>
  573.36 +        <include>**/*.html</include>
  573.37 +      </includes>
  573.38 +    </fileSet>
  573.39 +    <fileSet filtered="true" packaged="true">
  573.40 +      <directory>src/test/java</directory>
  573.41 +      <includes>
  573.42 +        <include>**/*Test.java</include>
  573.43 +      </includes>
  573.44 +    </fileSet>
  573.45 +    <fileSet filtered="false" packaged="false">
  573.46 +      <directory></directory>
  573.47 +      <includes>
  573.48 +        <include>nbactions.xml</include>
  573.49 +      </includes>
  573.50 +    </fileSet>
  573.51 +    <fileSet filtered="true" packaged="false">
  573.52 +      <directory></directory>
  573.53 +      <includes>
  573.54 +        <include>bck2brwsr-assembly.xml</include>
  573.55 +      </includes>
  573.56 +    </fileSet>
  573.57 +  </fileSets>    
  573.58 +</archetype-descriptor>
  573.59 \ No newline at end of file
   574.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   574.2 +++ b/rt/mojo/src/main/resources/archetype-resources/bck2brwsr-assembly.xml	Wed Feb 27 11:24:58 2013 +0100
   574.3 @@ -0,0 +1,61 @@
   574.4 +<?xml version="1.0"?>
   574.5 +<!--
   574.6 +
   574.7 +    Back 2 Browser Bytecode Translator
   574.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   574.9 +
  574.10 +    This program is free software: you can redistribute it and/or modify
  574.11 +    it under the terms of the GNU General Public License as published by
  574.12 +    the Free Software Foundation, version 2 of the License.
  574.13 +
  574.14 +    This program is distributed in the hope that it will be useful,
  574.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  574.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  574.17 +    GNU General Public License for more details.
  574.18 +
  574.19 +    You should have received a copy of the GNU General Public License
  574.20 +    along with this program. Look for COPYING file in the top folder.
  574.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  574.22 +
  574.23 +-->
  574.24 +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  574.25 +  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  574.26 +  
  574.27 +  <id>bck2brwsr</id>
  574.28 +  <formats>
  574.29 +      <format>zip</format>
  574.30 +  </formats>
  574.31 +  <baseDirectory>public_html</baseDirectory>
  574.32 +  <dependencySets>
  574.33 +    <dependencySet>
  574.34 +        <useProjectArtifact>false</useProjectArtifact>
  574.35 +        <scope>runtime</scope>
  574.36 +        <outputDirectory>lib</outputDirectory>
  574.37 +        <includes>
  574.38 +            <include>*:jar</include>
  574.39 +            <include>*:rt</include>
  574.40 +        </includes>
  574.41 +    </dependencySet>
  574.42 +    <dependencySet>
  574.43 +        <useProjectArtifact>false</useProjectArtifact>
  574.44 +        <scope>provided</scope>
  574.45 +        <includes>
  574.46 +            <include>*:js</include>
  574.47 +        </includes>
  574.48 +        <unpack>true</unpack>
  574.49 +        <outputDirectory>/</outputDirectory>
  574.50 +    </dependencySet>
  574.51 +  </dependencySets> 
  574.52 +  <files>
  574.53 +    <file>
  574.54 +      <source>${project.build.directory}/${project.build.finalName}.jar</source>
  574.55 +      <outputDirectory>/</outputDirectory>
  574.56 +    </file>
  574.57 +    <file>
  574.58 +      <source>${project.build.directory}/classes/${package.replace('.','/')}/index.html</source>
  574.59 +      <outputDirectory>/</outputDirectory>
  574.60 +      <destName>index.html</destName>
  574.61 +    </file>
  574.62 +  </files>
  574.63 +
  574.64 +</assembly>
  574.65 \ No newline at end of file
   575.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   575.2 +++ b/rt/mojo/src/main/resources/archetype-resources/nbactions.xml	Wed Feb 27 11:24:58 2013 +0100
   575.3 @@ -0,0 +1,10 @@
   575.4 +<?xml version="1.0" encoding="UTF-8"?>
   575.5 +<actions>
   575.6 +    <action>
   575.7 +        <actionName>run</actionName>
   575.8 +        <goals>
   575.9 +            <goal>process-classes</goal>
  575.10 +            <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
  575.11 +        </goals>
  575.12 +    </action>
  575.13 +</actions>
   576.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   576.2 +++ b/rt/mojo/src/main/resources/archetype-resources/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   576.3 @@ -0,0 +1,135 @@
   576.4 +<?xml version="1.0"?>
   576.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   576.6 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   576.7 +  <modelVersion>4.0.0</modelVersion>
   576.8 +
   576.9 +  <groupId>${groupId}</groupId>
  576.10 +  <artifactId>${artifactId}</artifactId>
  576.11 +  <version>${version}</version>
  576.12 +  <packaging>jar</packaging>
  576.13 +
  576.14 +  <name>${artifactId}</name>
  576.15 +
  576.16 +  <repositories>
  576.17 +      <repository>
  576.18 +          <id>java.net</id>
  576.19 +          <name>Java.net</name>
  576.20 +          <url>https://maven.java.net/content/repositories/snapshots/</url>
  576.21 +          <snapshots>
  576.22 +              <enabled>true</enabled>
  576.23 +          </snapshots>
  576.24 +      </repository>
  576.25 +      <repository>
  576.26 +          <id>netbeans</id>
  576.27 +          <name>NetBeans</name>
  576.28 +          <url>http://bits.netbeans.org/maven2/</url>
  576.29 +      </repository>
  576.30 +  </repositories>
  576.31 +  <pluginRepositories>
  576.32 +      <pluginRepository>
  576.33 +          <id>java.net</id>
  576.34 +          <name>Local Maven repository of releases</name>
  576.35 +          <url>https://maven.java.net/content/repositories/snapshots/</url>
  576.36 +          <snapshots>
  576.37 +              <enabled>true</enabled>
  576.38 +          </snapshots>
  576.39 +      </pluginRepository>
  576.40 +  </pluginRepositories>
  576.41 +
  576.42 +  <properties>
  576.43 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  576.44 +  </properties>
  576.45 +  <build>
  576.46 +      <plugins>
  576.47 +            <plugin>
  576.48 +                <groupId>org.apidesign.bck2brwsr</groupId>
  576.49 +                <artifactId>mojo</artifactId>
  576.50 +                <version>0.3-SNAPSHOT</version>
  576.51 +                <executions>
  576.52 +                    <execution>
  576.53 +                        <goals>
  576.54 +                            <goal>brwsr</goal>
  576.55 +                        </goals>
  576.56 +                    </execution>
  576.57 +                </executions>
  576.58 +                <configuration>
  576.59 +                    <startpage>${package.replace('.','/')}/index.html</startpage>
  576.60 +                </configuration>
  576.61 +            </plugin>
  576.62 +         <plugin>
  576.63 +            <groupId>org.apache.maven.plugins</groupId>
  576.64 +            <artifactId>maven-compiler-plugin</artifactId>
  576.65 +            <version>2.3.2</version>
  576.66 +            <configuration>
  576.67 +               <source>1.7</source>
  576.68 +               <target>1.7</target>
  576.69 +            </configuration>
  576.70 +         </plugin>
  576.71 +         <plugin>
  576.72 +             <groupId>org.apache.maven.plugins</groupId>
  576.73 +             <artifactId>maven-jar-plugin</artifactId>
  576.74 +             <version>2.4</version>
  576.75 +             <configuration>
  576.76 +                 <archive>
  576.77 +                     <manifest>
  576.78 +                         <addClasspath>true</addClasspath>
  576.79 +                         <classpathPrefix>lib/</classpathPrefix>
  576.80 +                     </manifest>
  576.81 +                 </archive>
  576.82 +             </configuration>
  576.83 +         </plugin>
  576.84 +         <plugin>
  576.85 +             <artifactId>maven-assembly-plugin</artifactId>
  576.86 +             <version>2.4</version>
  576.87 +             <executions>
  576.88 +                 <execution>
  576.89 +                     <id>distro-assembly</id>
  576.90 +                     <phase>package</phase>
  576.91 +                     <goals>
  576.92 +                         <goal>single</goal>
  576.93 +                     </goals>
  576.94 +                     <configuration>
  576.95 +                         <descriptors>
  576.96 +                             <descriptor>bck2brwsr-assembly.xml</descriptor>
  576.97 +                         </descriptors>
  576.98 +                     </configuration>
  576.99 +                 </execution>
 576.100 +             </executions>                
 576.101 +         </plugin>      
 576.102 +      </plugins>
 576.103 +  </build>
 576.104 +
 576.105 +  <dependencies>
 576.106 +    <dependency>
 576.107 +      <groupId>org.apidesign.bck2brwsr</groupId>
 576.108 +      <artifactId>emul</artifactId>
 576.109 +      <version>0.3-SNAPSHOT</version>
 576.110 +      <classifier>rt</classifier>
 576.111 +    </dependency>
 576.112 +    <dependency>
 576.113 +      <groupId>org.apidesign.bck2brwsr</groupId>
 576.114 +      <artifactId>javaquery.api</artifactId>
 576.115 +      <version>0.3-SNAPSHOT</version>
 576.116 +    </dependency>
 576.117 +    <dependency>
 576.118 +      <groupId>org.testng</groupId>
 576.119 +      <artifactId>testng</artifactId>
 576.120 +      <version>6.5.2</version>
 576.121 +      <scope>test</scope>
 576.122 +    </dependency>
 576.123 +    <dependency>
 576.124 +      <groupId>org.apidesign.bck2brwsr</groupId>
 576.125 +      <artifactId>vm4brwsr</artifactId>
 576.126 +      <classifier>js</classifier>
 576.127 +      <type>zip</type>
 576.128 +      <version>0.3-SNAPSHOT</version>
 576.129 +      <scope>provided</scope>
 576.130 +    </dependency>
 576.131 +    <dependency>
 576.132 +      <groupId>org.apidesign.bck2brwsr</groupId>
 576.133 +      <artifactId>vmtest</artifactId>
 576.134 +      <version>0.3-SNAPSHOT</version>
 576.135 +      <scope>test</scope>
 576.136 +    </dependency>
 576.137 +  </dependencies>
 576.138 +</project>
   577.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   577.2 +++ b/rt/mojo/src/main/resources/archetype-resources/src/main/java/App.java	Wed Feb 27 11:24:58 2013 +0100
   577.3 @@ -0,0 +1,34 @@
   577.4 +package ${package};
   577.5 +
   577.6 +import org.apidesign.bck2brwsr.htmlpage.api.*;
   577.7 +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
   577.8 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
   577.9 +import org.apidesign.bck2brwsr.htmlpage.api.Property;
  577.10 +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
  577.11 +
  577.12 +/** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
  577.13 + * Use this class to define behavior of the elements.
  577.14 + */
  577.15 +@Page(xhtml="index.html", className="Index", properties={
  577.16 +    @Property(name="name", type=String.class)
  577.17 +})
  577.18 +public class App {
  577.19 +    static {
  577.20 +        Index model = new Index();
  577.21 +        model.setName("World");
  577.22 +        model.applyBindings();
  577.23 +    }
  577.24 +    
  577.25 +    @On(event = CLICK, id="hello")
  577.26 +    static void hello(Index m) {
  577.27 +        GraphicsContext g = m.CANVAS.getContext();
  577.28 +        g.clearRect(0, 0, 1000, 1000);
  577.29 +        g.setFont("italic 40px Calibri");
  577.30 +        g.fillText(m.getHelloMessage(), 10, 40);
  577.31 +    }
  577.32 +    
  577.33 +    @ComputedProperty
  577.34 +    static String helloMessage(String name) {
  577.35 +        return "Hello " + name + "!";
  577.36 +    }
  577.37 +}
   578.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   578.2 +++ b/rt/mojo/src/main/resources/archetype-resources/src/main/resources/index.html	Wed Feb 27 11:24:58 2013 +0100
   578.3 @@ -0,0 +1,22 @@
   578.4 +<?xml version="1.0" encoding="UTF-8"?>
   578.5 +<!DOCTYPE html>
   578.6 +<html xmlns="http://www.w3.org/1999/xhtml">
   578.7 +    <head>
   578.8 +        <title>Bck2Brwsr's Hello World</title>
   578.9 +    </head>
  578.10 +    <body>
  578.11 +        <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
  578.12 +        Your name: <input id='input' data-bind="value: name, valueUpdate: 'afterkeydown'"></input>
  578.13 +        <button id="hello">Say Hello!</button>
  578.14 +        <p>
  578.15 +            <canvas id="canvas" width="300" height="50">
  578.16 +            </canvas>
  578.17 +        </p>
  578.18 +
  578.19 +        <script src="bck2brwsr.js"></script>
  578.20 +        <script type="text/javascript">
  578.21 +            var vm = bck2brwsr('${artifactId}-${version}.jar');
  578.22 +            vm.loadClass('${package}.App');
  578.23 +        </script>
  578.24 +    </body>
  578.25 +</html>
   579.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   579.2 +++ b/rt/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java	Wed Feb 27 11:24:58 2013 +0100
   579.3 @@ -0,0 +1,26 @@
   579.4 +package ${package};
   579.5 +
   579.6 +import static org.testng.Assert.*;
   579.7 +import org.testng.annotations.BeforeMethod;
   579.8 +import org.testng.annotations.Test;
   579.9 +
  579.10 +/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot
  579.11 + * as it does not reference any HTML elements or browser functionality. Just
  579.12 + * operates on the page model.
  579.13 + *
  579.14 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  579.15 + */
  579.16 +public class AppTest {
  579.17 +    private Index model;
  579.18 +    
  579.19 +
  579.20 +    @BeforeMethod
  579.21 +    public void initModel() {
  579.22 +        model = new Index().applyBindings();
  579.23 +    }
  579.24 +
  579.25 +    @Test public void testHelloMessage() {
  579.26 +        model.setName("Joe");
  579.27 +        assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +");
  579.28 +    }
  579.29 +}
   580.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   580.2 +++ b/rt/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java	Wed Feb 27 11:24:58 2013 +0100
   580.3 @@ -0,0 +1,40 @@
   580.4 +package ${package};
   580.5 +
   580.6 +import org.apidesign.bck2brwsr.vmtest.Compare;
   580.7 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   580.8 +import org.testng.annotations.Factory;
   580.9 +
  580.10 +/** Bck2brwsr cares about compatibility with real Java. Whatever API is
  580.11 + * supported by bck2brwsr, it needs to behave the same way as when running
  580.12 + * in HotSpot VM. 
  580.13 + * <p>
  580.14 + * There can be bugs, however. To help us fix them, we kindly ask you to 
  580.15 + * write an "inconsistency" test. A test that compares behavior of the API
  580.16 + * between real VM and bck2brwsr VM. This class is skeleton of such test.
  580.17 + *
  580.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  580.19 + */
  580.20 +public class InconsistencyTest {
  580.21 +    /** A method to demonstrate inconsistency between bck2brwsr and HotSpot.
  580.22 +     * Make calls to an API that behaves strangely, return some result at
  580.23 +     * the end. No need to use any <code>assert</code>.
  580.24 +     * 
  580.25 +     * @return value to compare between HotSpot and bck2brwsr
  580.26 +     */
  580.27 +    @Compare
  580.28 +    public int checkStringHashCode() throws Exception {
  580.29 +        return "Is string hashCode the same?".hashCode();
  580.30 +    }
  580.31 +
  580.32 +    /** Factory method that creates a three tests for each method annotated with
  580.33 +     * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in
  580.34 +     * HotSpot, one in Rhino and the last one compares the results.
  580.35 +     * 
  580.36 +     * @see org.apidesign.bck2brwsr.vmtest.VMTest
  580.37 +     */
  580.38 +    @Factory
  580.39 +    public static Object[] create() {
  580.40 +        return VMTest.create(InconsistencyTest.class);
  580.41 +    }
  580.42 +    
  580.43 +}
   581.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   581.2 +++ b/rt/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java	Wed Feb 27 11:24:58 2013 +0100
   581.3 @@ -0,0 +1,46 @@
   581.4 +package ${package};
   581.5 +
   581.6 +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
   581.7 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
   581.8 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
   581.9 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  581.10 +import org.testng.annotations.Factory;
  581.11 +
  581.12 +/** Sometimes it is useful to run tests inside of the real browser. 
  581.13 + * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
  581.14 + * and that is it. If your code references elements on the HTML page,
  581.15 + * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
  581.16 + * will be made available on the page before your test starts.
  581.17 + *
  581.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  581.19 + */
  581.20 +public class IntegrationTest {
  581.21 +    
  581.22 +    /** Write to testing code here. Use <code>assert</code> (but not TestNG's
  581.23 +     * Assert, as TestNG is not compiled with target 1.6 yet).
  581.24 +     */
  581.25 +    @HtmlFragment(
  581.26 +        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
  581.27 +        "Your name: <input id='input' data-bind=\"value: name, valueUpdate: 'afterkeydown'\"></input>\n" +
  581.28 +        "<button id=\"hello\">Say Hello!</button>\n" +
  581.29 +        "<p>\n" +
  581.30 +        "    <canvas id=\"canvas\" width=\"300\" height=\"50\"></canvas>\n" +
  581.31 +        "</p>\n"
  581.32 +    )
  581.33 +    @BrwsrTest
  581.34 +    public void modifyValueAssertChangeInModel() {
  581.35 +        Index m = new Index();
  581.36 +        m.setName("Joe Hacker");
  581.37 +        m.applyBindings();
  581.38 +        assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue();
  581.39 +        m.INPUT.setValue("Happy Joe");
  581.40 +        m.triggerEvent(m.INPUT, OnEvent.CHANGE);
  581.41 +        assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName();
  581.42 +    }
  581.43 +
  581.44 +    @Factory
  581.45 +    public static Object[] create() {
  581.46 +        return VMTest.create(IntegrationTest.class);
  581.47 +    }
  581.48 +    
  581.49 +}
   582.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   582.2 +++ b/rt/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   582.3 @@ -0,0 +1,23 @@
   582.4 +<?xml version="1.0" encoding="UTF-8"?>
   582.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">
   582.6 +  <modelVersion>4.0.0</modelVersion>
   582.7 +  <groupId>org.apidesign.bck2brwsr</groupId>
   582.8 +  <artifactId>rt</artifactId>
   582.9 +  <version>0.3-SNAPSHOT</version>
  582.10 +  <packaging>pom</packaging>
  582.11 +  <name>Bck3Brwsr Runtime</name>
  582.12 +  <parent>
  582.13 +    <groupId>org.apidesign</groupId>
  582.14 +    <artifactId>bck2brwsr</artifactId>
  582.15 +    <version>0.3-SNAPSHOT</version>
  582.16 +  </parent>  
  582.17 +  <modules>
  582.18 +    <module>core</module>
  582.19 +    <module>emul</module>
  582.20 +    <module>javap</module>
  582.21 +    <module>launcher</module>
  582.22 +    <module>mojo</module>
  582.23 +    <module>vm</module>
  582.24 +    <module>vmtest</module>
  582.25 +  </modules>
  582.26 +</project>
  582.27 \ No newline at end of file
   583.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   583.2 +++ b/rt/vm/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   583.3 @@ -0,0 +1,143 @@
   583.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   583.5 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   583.6 +  <modelVersion>4.0.0</modelVersion>
   583.7 +  <parent>
   583.8 +    <groupId>org.apidesign.bck2brwsr</groupId>
   583.9 +    <artifactId>rt</artifactId>
  583.10 +    <version>0.3-SNAPSHOT</version>
  583.11 +  </parent>
  583.12 +
  583.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  583.14 +  <artifactId>vm4brwsr</artifactId>
  583.15 +  <version>0.3-SNAPSHOT</version>
  583.16 +  <packaging>jar</packaging>
  583.17 +
  583.18 +  <name>Virtual Machine for Browser</name>
  583.19 +  <url>http://bck2brwsr.apidesign.org</url>
  583.20 +
  583.21 +  <properties>
  583.22 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  583.23 +    <author.name>Jaroslav Tulach</author.name>
  583.24 +    <author.email>jaroslav.tulach@apidesign.org</author.email>
  583.25 +  </properties>
  583.26 +  
  583.27 +  <repositories>
  583.28 +      <repository>
  583.29 +          <id>netbeans</id>
  583.30 +          <name>NetBeans</name>
  583.31 +          <url>http://bits.netbeans.org/maven2/</url>
  583.32 +      </repository>
  583.33 +  </repositories>
  583.34 +  <pluginRepositories>
  583.35 +    <pluginRepository>
  583.36 +        <id>mc-release</id>
  583.37 +        <name>Local Maven repository of releases</name>
  583.38 +        <url>http://mc-repo.googlecode.com/svn/maven2/releases</url>
  583.39 +        <snapshots>
  583.40 +            <enabled>false</enabled>
  583.41 +        </snapshots>
  583.42 +        <releases>
  583.43 +            <enabled>true</enabled>
  583.44 +        </releases>
  583.45 +    </pluginRepository>
  583.46 +  </pluginRepositories>
  583.47 +  <scm>
  583.48 +      <connection>scm:hg:http://source.apidesign.org/hg/bck2brwsr</connection>
  583.49 +      <url>http://source.apidesign.org/hg/bck2brwsr</url>
  583.50 +  </scm>
  583.51 +  <build>
  583.52 +      <plugins>
  583.53 +          <plugin>
  583.54 +              <groupId>org.apache.maven.plugins</groupId>
  583.55 +              <artifactId>maven-jar-plugin</artifactId>
  583.56 +              <version>2.4</version>
  583.57 +              <configuration>
  583.58 +                  <archive>
  583.59 +                      <manifest>
  583.60 +                          <mainClass>org.apidesign.vm4brwsr.Main</mainClass>
  583.61 +                      </manifest>
  583.62 +                  </archive>
  583.63 +              </configuration>
  583.64 +          </plugin>
  583.65 +         <plugin>
  583.66 +            <groupId>org.apache.maven.plugins</groupId>
  583.67 +            <artifactId>maven-compiler-plugin</artifactId>
  583.68 +            <version>2.3.2</version>
  583.69 +            <configuration>
  583.70 +               <source>1.7</source>
  583.71 +               <target>1.7</target>
  583.72 +            </configuration>
  583.73 +         </plugin>
  583.74 +         <plugin>
  583.75 +             <groupId>org.codehaus.mojo</groupId>
  583.76 +             <artifactId>exec-maven-plugin</artifactId>
  583.77 +             <version>1.2.1</version>
  583.78 +             <executions>
  583.79 +                 <execution>
  583.80 +                     <id>generate-js</id>
  583.81 +                     <phase>process-classes</phase>
  583.82 +                     <goals>
  583.83 +                         <goal>java</goal>
  583.84 +                     </goals>
  583.85 +                 </execution>
  583.86 +             </executions>
  583.87 +             <configuration>
  583.88 +                 <mainClass>org.apidesign.vm4brwsr.Main</mainClass>
  583.89 +                 <arguments>
  583.90 +                     <argument>${project.build.directory}/bck2brwsr.js</argument>
  583.91 +                     <argument>org/apidesign/vm4brwsr/Bck2Brwsr</argument>
  583.92 +                 </arguments>
  583.93 +             </configuration>
  583.94 +         </plugin>
  583.95 +         <plugin>
  583.96 +             <artifactId>maven-assembly-plugin</artifactId>
  583.97 +             <version>2.4</version>
  583.98 +             <executions>
  583.99 +                 <execution>
 583.100 +                     <id>js</id>
 583.101 +                     <phase>package</phase>
 583.102 +                     <goals>
 583.103 +                         <goal>single</goal>
 583.104 +                     </goals>
 583.105 +                     <configuration>
 583.106 +                         <descriptors>
 583.107 +                             <descriptor>src/main/assembly/bck2brwsr.xml</descriptor>
 583.108 +                         </descriptors>
 583.109 +                     </configuration>
 583.110 +                 </execution>
 583.111 +             </executions>                
 583.112 +         </plugin>      
 583.113 +      </plugins>
 583.114 +  </build>
 583.115 +  <dependencies>
 583.116 +    <dependency>
 583.117 +      <groupId>org.testng</groupId>
 583.118 +      <artifactId>testng</artifactId>
 583.119 +      <scope>test</scope>
 583.120 +      <exclusions>
 583.121 +        <exclusion>
 583.122 +          <artifactId>junit</artifactId>
 583.123 +          <groupId>junit</groupId>
 583.124 +        </exclusion>
 583.125 +      </exclusions>
 583.126 +    </dependency>
 583.127 +    <dependency>
 583.128 +      <groupId>${project.groupId}</groupId>
 583.129 +      <artifactId>core</artifactId>
 583.130 +      <version>${project.version}</version>
 583.131 +      <type>jar</type>
 583.132 +    </dependency>
 583.133 +    <dependency>
 583.134 +      <groupId>${project.groupId}</groupId>
 583.135 +      <artifactId>emul.mini</artifactId>
 583.136 +      <version>${project.version}</version>
 583.137 +      <scope>compile</scope>
 583.138 +    </dependency>
 583.139 +    <dependency>
 583.140 +      <groupId>${project.groupId}</groupId>
 583.141 +      <artifactId>javap</artifactId>
 583.142 +      <version>${project.version}</version>
 583.143 +      <scope>compile</scope>
 583.144 +    </dependency>
 583.145 +  </dependencies>
 583.146 +</project>
   584.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   584.2 +++ b/rt/vm/src/main/assembly/bck2brwsr.xml	Wed Feb 27 11:24:58 2013 +0100
   584.3 @@ -0,0 +1,36 @@
   584.4 +<?xml version="1.0"?>
   584.5 +<!--
   584.6 +
   584.7 +    Back 2 Browser Bytecode Translator
   584.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   584.9 +
  584.10 +    This program is free software: you can redistribute it and/or modify
  584.11 +    it under the terms of the GNU General Public License as published by
  584.12 +    the Free Software Foundation, version 2 of the License.
  584.13 +
  584.14 +    This program is distributed in the hope that it will be useful,
  584.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  584.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  584.17 +    GNU General Public License for more details.
  584.18 +
  584.19 +    You should have received a copy of the GNU General Public License
  584.20 +    along with this program. Look for COPYING file in the top folder.
  584.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
  584.22 +
  584.23 +-->
  584.24 +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  584.25 +  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  584.26 +  
  584.27 +  <id>js</id>
  584.28 +  <formats>
  584.29 +      <format>zip</format>
  584.30 +  </formats>
  584.31 +  <baseDirectory>/</baseDirectory>
  584.32 +  <files>
  584.33 +    <file>
  584.34 +      <source>${project.build.directory}/bck2brwsr.js</source>
  584.35 +      <outputDirectory>/</outputDirectory>
  584.36 +    </file>
  584.37 +  </files>
  584.38 +
  584.39 +</assembly>
  584.40 \ No newline at end of file
   585.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   585.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java	Wed Feb 27 11:24:58 2013 +0100
   585.3 @@ -0,0 +1,116 @@
   585.4 +/**
   585.5 + * Back 2 Browser Bytecode Translator
   585.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   585.7 + *
   585.8 + * This program is free software: you can redistribute it and/or modify
   585.9 + * it under the terms of the GNU General Public License as published by
  585.10 + * the Free Software Foundation, version 2 of the License.
  585.11 + *
  585.12 + * This program is distributed in the hope that it will be useful,
  585.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  585.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  585.15 + * GNU General Public License for more details.
  585.16 + *
  585.17 + * You should have received a copy of the GNU General Public License
  585.18 + * along with this program. Look for COPYING file in the top folder.
  585.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  585.20 + */
  585.21 +package org.apidesign.vm4brwsr;
  585.22 +
  585.23 +import java.io.IOException;
  585.24 +import java.io.InputStream;
  585.25 +import java.net.URL;
  585.26 +import java.util.Enumeration;
  585.27 +
  585.28 +/** Build your own virtual machine! Use methods in this class to generate
  585.29 + * a skeleton JVM in JavaScript that contains pre-compiled classes of your
  585.30 + * choice. The generated script defines one JavaScript method that can
  585.31 + * be used to bootstrap and load the virtual machine: <pre>
  585.32 + * var vm = bck2brwsr();
  585.33 + * var main = vm.loadClass('org.your.pkg.Main');
  585.34 + * main.main__V_3Ljava_lang_String_2(null);
  585.35 + * </pre>
  585.36 + * In case one wants to initialize the virtual machine with ability to
  585.37 + * load classes lazily when needed, one can provide a loader function to
  585.38 + * when creating the virtual machine: <pre>
  585.39 + * var vm = bck2brwsr(function(resource) { 
  585.40 + *   return null; // byte[] for the resource
  585.41 + * });
  585.42 + * </pre>
  585.43 + * In this scenario, when a request for an unknown class is made, the loader
  585.44 + * function is asked for its byte code and the system dynamically transforms
  585.45 + * it to JavaScript.
  585.46 + * <p>
  585.47 + * Instead of a loader function, one can also provide a URL to a JAR file.
  585.48 + * The <code>bck2brwsr</code> system will do its best to download the file
  585.49 + * and provide loader function for it automatically.
  585.50 + * <p>
  585.51 + * One can provide as many loader functions and JAR URL references as necessary.
  585.52 + * Then the initialization code would look like:<pre>
  585.53 + * var vm = bck2brwsr(url1, url2, fnctn1, url3, functn2);
  585.54 + * </pre>
  585.55 + * The provided URLs and loader functions will be consulted one by one.
  585.56 + *
  585.57 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  585.58 + */
  585.59 +public final class Bck2Brwsr {
  585.60 +    private Bck2Brwsr() {
  585.61 +    }
  585.62 +    
  585.63 +    /** Generates virtual machine from bytes served by a <code>resources</code>
  585.64 +     * provider.
  585.65 +     * 
  585.66 +     * @param out the output to write the generated JavaScript to
  585.67 +     * @param resources provider of class files to use
  585.68 +     * @param classes additional classes to include in the generated script
  585.69 +     * @throws IOException I/O exception can be thrown when something goes wrong
  585.70 +     */
  585.71 +    public static void generate(Appendable out, Resources resources, String... classes) throws IOException {
  585.72 +        StringArray arr = StringArray.asList(classes);
  585.73 +        arr.add(VM.class.getName().replace('.', '/'));
  585.74 +        VM.compile(resources, out, arr);
  585.75 +    }
  585.76 +    
  585.77 +    /** Generates virtual machine from bytes served by a class loader.
  585.78 +     * 
  585.79 +     * @param out the output to write the generated JavaScript to
  585.80 +     * @param loader class loader to load needed classes from
  585.81 +     * @param classes additional classes to include in the generated script
  585.82 +     * @throws IOException I/O exception can be thrown when something goes wrong
  585.83 +     */
  585.84 +    public static void generate(Appendable out, final ClassLoader loader, String... classes) throws IOException {
  585.85 +        class R implements Resources {
  585.86 +            @Override
  585.87 +            public InputStream get(String name) throws IOException {
  585.88 +                Enumeration<URL> en = loader.getResources(name);
  585.89 +                URL u = null;
  585.90 +                while (en.hasMoreElements()) {
  585.91 +                    u = en.nextElement();
  585.92 +                }
  585.93 +                if (u == null) {
  585.94 +                    throw new IOException("Can't find " + name);
  585.95 +                }
  585.96 +                return u.openStream();
  585.97 +            }
  585.98 +        }
  585.99 +        generate(out, new R(), classes);
 585.100 +    }
 585.101 +    
 585.102 +    /** Provider of resources (classes and other files). The 
 585.103 +     * {@link #generate(java.lang.Appendable, org.apidesign.vm4brwsr.Bck2Brwsr.Resources, java.lang.String[]) 
 585.104 +     * generator method} will call back here for all classes needed during
 585.105 +     * translation to JavaScript.
 585.106 +     */
 585.107 +    public interface Resources {
 585.108 +        /** Loads given resource (class or other file like image). The 
 585.109 +         * resource name to load bytes for the {@link String} class
 585.110 +         * would be <code>"java/lang/String.class"</code>.
 585.111 +         * 
 585.112 +         * @param resource path to resource to load
 585.113 +         * @return the input stream for the resource 
 585.114 +         * @throws IOException can be thrown if the loading fails on some error
 585.115 +         *   or the file cannot be found
 585.116 +         */
 585.117 +        public InputStream get(String resource) throws IOException;
 585.118 +    }
 585.119 +}
   586.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   586.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Wed Feb 27 11:24:58 2013 +0100
   586.3 @@ -0,0 +1,1859 @@
   586.4 +/**
   586.5 + * Back 2 Browser Bytecode Translator
   586.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   586.7 + *
   586.8 + * This program is free software: you can redistribute it and/or modify
   586.9 + * it under the terms of the GNU General Public License as published by
  586.10 + * the Free Software Foundation, version 2 of the License.
  586.11 + *
  586.12 + * This program is distributed in the hope that it will be useful,
  586.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  586.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  586.15 + * GNU General Public License for more details.
  586.16 + *
  586.17 + * You should have received a copy of the GNU General Public License
  586.18 + * along with this program. Look for COPYING file in the top folder.
  586.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  586.20 + */
  586.21 +package org.apidesign.vm4brwsr;
  586.22 +
  586.23 +import java.io.IOException;
  586.24 +import java.io.InputStream;
  586.25 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  586.26 +import org.apidesign.javap.AnnotationParser;
  586.27 +import org.apidesign.javap.ClassData;
  586.28 +import org.apidesign.javap.FieldData;
  586.29 +import org.apidesign.javap.MethodData;
  586.30 +import org.apidesign.javap.StackMapIterator;
  586.31 +import static org.apidesign.javap.RuntimeConstants.*;
  586.32 +import org.apidesign.javap.TrapData;
  586.33 +import org.apidesign.javap.TrapDataIterator;
  586.34 +
  586.35 +/** Translator of the code inside class files to JavaScript.
  586.36 + *
  586.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  586.38 + */
  586.39 +abstract class ByteCodeToJavaScript {
  586.40 +    private ClassData jc;
  586.41 +    final Appendable out;
  586.42 +
  586.43 +    protected ByteCodeToJavaScript(Appendable out) {
  586.44 +        this.out = out;
  586.45 +    }
  586.46 +    
  586.47 +    /* Collects additional required resources.
  586.48 +     * 
  586.49 +     * @param internalClassName classes that were referenced and should be loaded in order the
  586.50 +     *   generated JavaScript code works properly. The names are in internal 
  586.51 +     *   JVM form so String is <code>java/lang/String</code>. 
  586.52 +     */
  586.53 +    protected abstract boolean requireReference(String internalClassName);
  586.54 +    
  586.55 +    /*
  586.56 +     * @param resourcePath name of resources to read
  586.57 +     */
  586.58 +    protected abstract void requireScript(String resourcePath) throws IOException;
  586.59 +    
  586.60 +    /** Allows subclasses to redefine what field a function representing a
  586.61 +     * class gets assigned. By default it returns the suggested name followed
  586.62 +     * by <code>" = "</code>;
  586.63 +     * 
  586.64 +     * @param className suggested name of the class
  586.65 +     */
  586.66 +    /* protected */ String assignClass(String className) {
  586.67 +        return className + " = ";
  586.68 +    }
  586.69 +    /* protected */ String accessClass(String classOperation) {
  586.70 +        return classOperation;
  586.71 +    }
  586.72 +    
  586.73 +    /** Prints out a debug message. 
  586.74 +     * 
  586.75 +     * @param msg the message
  586.76 +     * @return true if the message has been printed
  586.77 +     * @throws IOException 
  586.78 +     */
  586.79 +    boolean debug(String msg) throws IOException {
  586.80 +        out.append(msg);
  586.81 +        return true;
  586.82 +    }
  586.83 +
  586.84 +    /**
  586.85 +     * Converts a given class file to a JavaScript version.
  586.86 +     *
  586.87 +     * @param classFile input stream with code of the .class file
  586.88 +     * @return the initialization code for this class, if any. Otherwise <code>null</code>
  586.89 +     * 
  586.90 +     * @throws IOException if something goes wrong during read or write or translating
  586.91 +     */
  586.92 +    
  586.93 +    public String compile(InputStream classFile) throws IOException {
  586.94 +        this.jc = new ClassData(classFile);
  586.95 +        if (jc.getMajor_version() < 50) {
  586.96 +            throw new IOException("Can't compile " + jc.getClassName() + ". Class file version " + jc.getMajor_version() + "."
  586.97 +                + jc.getMinor_version() + " - recompile with -target 1.6 (at least)."
  586.98 +            );
  586.99 +        }
 586.100 +        byte[] arrData = jc.findAnnotationData(true);
 586.101 +        String[] arr = findAnnotation(arrData, jc, 
 586.102 +            "org.apidesign.bck2brwsr.core.ExtraJavaScript", 
 586.103 +            "resource", "processByteCode"
 586.104 +        );
 586.105 +        if (arr != null) {
 586.106 +            requireScript(arr[0]);
 586.107 +            if ("0".equals(arr[1])) {
 586.108 +                return null;
 586.109 +            }
 586.110 +        }
 586.111 +        String[] proto = findAnnotation(arrData, jc, 
 586.112 +            "org.apidesign.bck2brwsr.core.JavaScriptPrototype", 
 586.113 +            "container", "prototype"
 586.114 +        );
 586.115 +        StringArray toInitilize = new StringArray();
 586.116 +        final String className = className(jc);
 586.117 +        out.append("\n\n").append(assignClass(className));
 586.118 +        out.append("function CLS() {");
 586.119 +        out.append("\n  if (!CLS.$class) {");
 586.120 +        if (proto == null) {
 586.121 +            String sc = jc.getSuperClassName(); // with _
 586.122 +            out.append("\n    var pp = ").
 586.123 +                append(accessClass(sc.replace('/', '_'))).append("(true);");
 586.124 +            out.append("\n    var p = CLS.prototype = pp;");
 586.125 +            out.append("\n    var c = p;");
 586.126 +            out.append("\n    var sprcls = pp.constructor.$class;");
 586.127 +        } else {
 586.128 +            out.append("\n    var p = CLS.prototype = ").append(proto[1]).append(";");
 586.129 +            if (proto[0] == null) {
 586.130 +                proto[0] = "p";
 586.131 +            }
 586.132 +            out.append("\n    var c = ").append(proto[0]).append(";");
 586.133 +            out.append("\n    var sprcls = null;");
 586.134 +        }
 586.135 +        for (FieldData v : jc.getFields()) {
 586.136 +            if (v.isStatic()) {
 586.137 +                out.append("\n  CLS.").append(v.getName()).append(initField(v));
 586.138 +            } else {
 586.139 +                out.append("\n  c._").append(v.getName()).append(" = function (v) {")
 586.140 +                   .append("  if (arguments.length == 1) this.fld_").
 586.141 +                    append(className).append('_').append(v.getName())
 586.142 +                   .append(" = v; return this.fld_").
 586.143 +                    append(className).append('_').append(v.getName())
 586.144 +                   .append("; };");
 586.145 +            }
 586.146 +        }
 586.147 +        for (MethodData m : jc.getMethods()) {
 586.148 +            byte[] onlyArr = m.findAnnotationData(true);
 586.149 +            String[] only = findAnnotation(onlyArr, jc, 
 586.150 +                "org.apidesign.bck2brwsr.core.JavaScriptOnly", 
 586.151 +                "name", "value"
 586.152 +            );
 586.153 +            if (only != null) {
 586.154 +                if (only[0] != null && only[1] != null) {
 586.155 +                    out.append("\n    p.").append(only[0]).append(" = ")
 586.156 +                        .append(only[1]).append(";");
 586.157 +                }
 586.158 +                continue;
 586.159 +            }
 586.160 +            String prefix;
 586.161 +            String mn;
 586.162 +            if (m.isStatic()) {
 586.163 +                prefix = "\n    c.";
 586.164 +                mn = generateStaticMethod(prefix, m, toInitilize);
 586.165 +            } else {
 586.166 +                if (m.isConstructor()) {
 586.167 +                    prefix = "\n    CLS.";
 586.168 +                    mn = generateInstanceMethod(prefix, m);
 586.169 +                } else {
 586.170 +                    prefix = "\n    c.";
 586.171 +                    mn = generateInstanceMethod(prefix, m);
 586.172 +                }
 586.173 +            }
 586.174 +            byte[] runAnno = m.findAnnotationData(false);
 586.175 +            if (runAnno != null) {
 586.176 +                out.append(prefix).append(mn).append(".anno = {");
 586.177 +                generateAnno(jc, out, runAnno);
 586.178 +                out.append("\n    };");
 586.179 +            }
 586.180 +            out.append(prefix).append(mn).append(".access = " + m.getAccess()).append(";");
 586.181 +            out.append(prefix).append(mn).append(".cls = CLS;");
 586.182 +        }
 586.183 +        out.append("\n    c.constructor = CLS;");
 586.184 +        out.append("\n    c.$instOf_").append(className).append(" = true;");
 586.185 +        for (String superInterface : jc.getSuperInterfaces()) {
 586.186 +            out.append("\n    c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
 586.187 +        }
 586.188 +        out.append("\n    CLS.$class = 'temp';");
 586.189 +        out.append("\n    CLS.$class = ");
 586.190 +        out.append(accessClass("java_lang_Class(true);"));
 586.191 +        out.append("\n    CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
 586.192 +        out.append("\n    CLS.$class.superclass = sprcls;");
 586.193 +        out.append("\n    CLS.$class.access = ").append(jc.getAccessFlags()+";");
 586.194 +        out.append("\n    CLS.$class.cnstr = CLS;");
 586.195 +        byte[] classAnno = jc.findAnnotationData(false);
 586.196 +        if (classAnno != null) {
 586.197 +            out.append("\n    CLS.$class.anno = {");
 586.198 +            generateAnno(jc, out, classAnno);
 586.199 +            out.append("\n    };");
 586.200 +        }
 586.201 +        out.append("\n  }");
 586.202 +        out.append("\n  if (arguments.length === 0) {");
 586.203 +        out.append("\n    if (!(this instanceof CLS)) {");
 586.204 +        out.append("\n      return new CLS();");
 586.205 +        out.append("\n    }");
 586.206 +        for (FieldData v : jc.getFields()) {
 586.207 +            byte[] onlyArr = v.findAnnotationData(true);
 586.208 +            String[] only = findAnnotation(onlyArr, jc, 
 586.209 +                "org.apidesign.bck2brwsr.core.JavaScriptOnly", 
 586.210 +                "name", "value"
 586.211 +            );
 586.212 +            if (only != null) {
 586.213 +                if (only[0] != null && only[1] != null) {
 586.214 +                    out.append("\n    p.").append(only[0]).append(" = ")
 586.215 +                        .append(only[1]).append(";");
 586.216 +                }
 586.217 +                continue;
 586.218 +            }
 586.219 +            if (!v.isStatic()) {
 586.220 +                out.append("\n    this.fld_").
 586.221 +                    append(className).append('_').
 586.222 +                    append(v.getName()).append(initField(v));
 586.223 +            }
 586.224 +        }
 586.225 +        out.append("\n    return this;");
 586.226 +        out.append("\n  }");
 586.227 +        out.append("\n  return arguments[0] ? new CLS() : CLS.prototype;");
 586.228 +        out.append("\n};");
 586.229 +        StringBuilder sb = new StringBuilder();
 586.230 +        for (String init : toInitilize.toArray()) {
 586.231 +            sb.append("\n").append(init).append("();");
 586.232 +        }
 586.233 +        return sb.toString();
 586.234 +    }
 586.235 +    private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
 586.236 +        String jsb = javaScriptBody(prefix, m, true);
 586.237 +        if (jsb != null) {
 586.238 +            return jsb;
 586.239 +        }
 586.240 +        final String mn = findMethodName(m, new StringBuilder());
 586.241 +        if (mn.equals("class__V")) {
 586.242 +            toInitilize.add(accessClass(className(jc)) + "(false)." + mn);
 586.243 +        }
 586.244 +        generateMethod(prefix, mn, m);
 586.245 +        return mn;
 586.246 +    }
 586.247 +
 586.248 +    private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
 586.249 +        String jsb = javaScriptBody(prefix, m, false);
 586.250 +        if (jsb != null) {
 586.251 +            return jsb;
 586.252 +        }
 586.253 +        final String mn = findMethodName(m, new StringBuilder());
 586.254 +        generateMethod(prefix, mn, m);
 586.255 +        return mn;
 586.256 +    }
 586.257 +
 586.258 +    private void generateMethod(String prefix, String name, MethodData m)
 586.259 +            throws IOException {
 586.260 +        final StackMapIterator stackMapIterator = m.createStackMapIterator();
 586.261 +        TrapDataIterator trap = m.getTrapDataIterator();
 586.262 +        final LocalsMapper lmapper =
 586.263 +                new LocalsMapper(stackMapIterator.getArguments());
 586.264 +
 586.265 +        out.append(prefix).append(name).append(" = function(");
 586.266 +        lmapper.outputArguments(out, m.isStatic());
 586.267 +        out.append(") {").append("\n");
 586.268 +
 586.269 +        final byte[] byteCodes = m.getCode();
 586.270 +        if (byteCodes == null) {
 586.271 +            out.append("  throw 'no code found for ")
 586.272 +               .append(jc.getClassName()).append('.')
 586.273 +               .append(m.getName()).append("';\n");
 586.274 +            out.append("};");
 586.275 +            return;
 586.276 +        }
 586.277 +
 586.278 +        final StackMapper smapper = new StackMapper();
 586.279 +
 586.280 +        if (!m.isStatic()) {
 586.281 +            out.append("  var ").append(" lcA0 = this;\n");
 586.282 +        }
 586.283 +
 586.284 +        int lastStackFrame = -1;
 586.285 +        TrapData[] previousTrap = null;
 586.286 +        boolean wide = false;
 586.287 +        
 586.288 +        out.append("\n  var gt = 0;\n  for(;;) switch(gt) {\n");
 586.289 +        for (int i = 0; i < byteCodes.length; i++) {
 586.290 +            int prev = i;
 586.291 +            stackMapIterator.advanceTo(i);
 586.292 +            boolean changeInCatch = trap.advanceTo(i);
 586.293 +            if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) {
 586.294 +                if (previousTrap != null) {
 586.295 +                    generateCatch(previousTrap);
 586.296 +                    previousTrap = null;
 586.297 +                }
 586.298 +            }
 586.299 +            if (lastStackFrame != stackMapIterator.getFrameIndex()) {
 586.300 +                lastStackFrame = stackMapIterator.getFrameIndex();
 586.301 +                lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
 586.302 +                smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
 586.303 +                out.append("    case " + i).append(": ");            
 586.304 +                changeInCatch = true;
 586.305 +            } else {
 586.306 +                debug("    /* " + i + " */ ");
 586.307 +            }
 586.308 +            if (changeInCatch && trap.useTry()) {
 586.309 +                out.append("try {");
 586.310 +                previousTrap = trap.current();
 586.311 +            }
 586.312 +            final int c = readUByte(byteCodes, i);
 586.313 +            switch (c) {
 586.314 +                case opc_aload_0:
 586.315 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(0));
 586.316 +                    break;
 586.317 +                case opc_iload_0:
 586.318 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(0));
 586.319 +                    break;
 586.320 +                case opc_lload_0:
 586.321 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(0));
 586.322 +                    break;
 586.323 +                case opc_fload_0:
 586.324 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(0));
 586.325 +                    break;
 586.326 +                case opc_dload_0:
 586.327 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(0));
 586.328 +                    break;
 586.329 +                case opc_aload_1:
 586.330 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(1));
 586.331 +                    break;
 586.332 +                case opc_iload_1:
 586.333 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(1));
 586.334 +                    break;
 586.335 +                case opc_lload_1:
 586.336 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(1));
 586.337 +                    break;
 586.338 +                case opc_fload_1:
 586.339 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(1));
 586.340 +                    break;
 586.341 +                case opc_dload_1:
 586.342 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(1));
 586.343 +                    break;
 586.344 +                case opc_aload_2:
 586.345 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(2));
 586.346 +                    break;
 586.347 +                case opc_iload_2:
 586.348 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(2));
 586.349 +                    break;
 586.350 +                case opc_lload_2:
 586.351 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(2));
 586.352 +                    break;
 586.353 +                case opc_fload_2:
 586.354 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(2));
 586.355 +                    break;
 586.356 +                case opc_dload_2:
 586.357 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(2));
 586.358 +                    break;
 586.359 +                case opc_aload_3:
 586.360 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(3));
 586.361 +                    break;
 586.362 +                case opc_iload_3:
 586.363 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(3));
 586.364 +                    break;
 586.365 +                case opc_lload_3:
 586.366 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(3));
 586.367 +                    break;
 586.368 +                case opc_fload_3:
 586.369 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(3));
 586.370 +                    break;
 586.371 +                case opc_dload_3:
 586.372 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(3));
 586.373 +                    break;
 586.374 +                case opc_iload: {
 586.375 +                    ++i;
 586.376 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.377 +                                          : readUByte(byteCodes, i);
 586.378 +                    wide = false;
 586.379 +                    emit(out, "var @1 = @2;",
 586.380 +                         smapper.pushI(), lmapper.getI(indx));
 586.381 +                    break;
 586.382 +                }
 586.383 +                case opc_lload: {
 586.384 +                    ++i;
 586.385 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.386 +                                          : readUByte(byteCodes, i);
 586.387 +                    wide = false;
 586.388 +                    emit(out, "var @1 = @2;",
 586.389 +                         smapper.pushL(), lmapper.getL(indx));
 586.390 +                    break;
 586.391 +                }
 586.392 +                case opc_fload: {
 586.393 +                    ++i;
 586.394 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.395 +                                          : readUByte(byteCodes, i);
 586.396 +                    wide = false;
 586.397 +                    emit(out, "var @1 = @2;",
 586.398 +                         smapper.pushF(), lmapper.getF(indx));
 586.399 +                    break;
 586.400 +                }
 586.401 +                case opc_dload: {
 586.402 +                    ++i;
 586.403 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.404 +                                          : readUByte(byteCodes, i);
 586.405 +                    wide = false;
 586.406 +                    emit(out, "var @1 = @2;",
 586.407 +                         smapper.pushD(), lmapper.getD(indx));
 586.408 +                    break;
 586.409 +                }
 586.410 +                case opc_aload: {
 586.411 +                    ++i;
 586.412 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.413 +                                          : readUByte(byteCodes, i);
 586.414 +                    wide = false;
 586.415 +                    emit(out, "var @1 = @2;",
 586.416 +                         smapper.pushA(), lmapper.getA(indx));
 586.417 +                    break;
 586.418 +                }
 586.419 +                case opc_istore: {
 586.420 +                    ++i;
 586.421 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.422 +                                          : readUByte(byteCodes, i);
 586.423 +                    wide = false;
 586.424 +                    emit(out, "var @1 = @2;",
 586.425 +                         lmapper.setI(indx), smapper.popI());
 586.426 +                    break;
 586.427 +                }
 586.428 +                case opc_lstore: {
 586.429 +                    ++i;
 586.430 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.431 +                                          : readUByte(byteCodes, i);
 586.432 +                    wide = false;
 586.433 +                    emit(out, "var @1 = @2;",
 586.434 +                         lmapper.setL(indx), smapper.popL());
 586.435 +                    break;
 586.436 +                }
 586.437 +                case opc_fstore: {
 586.438 +                    ++i;
 586.439 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.440 +                                          : readUByte(byteCodes, i);
 586.441 +                    wide = false;
 586.442 +                    emit(out, "var @1 = @2;",
 586.443 +                         lmapper.setF(indx), smapper.popF());
 586.444 +                    break;
 586.445 +                }
 586.446 +                case opc_dstore: {
 586.447 +                    ++i;
 586.448 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.449 +                                          : readUByte(byteCodes, i);
 586.450 +                    wide = false;
 586.451 +                    emit(out, "var @1 = @2;",
 586.452 +                         lmapper.setD(indx), smapper.popD());
 586.453 +                    break;
 586.454 +                }
 586.455 +                case opc_astore: {
 586.456 +                    ++i;
 586.457 +                    final int indx = wide ? readUShort(byteCodes, i++)
 586.458 +                                          : readUByte(byteCodes, i);
 586.459 +                    wide = false;
 586.460 +                    emit(out, "var @1 = @2;",
 586.461 +                         lmapper.setA(indx), smapper.popA());
 586.462 +                    break;
 586.463 +                }
 586.464 +                case opc_astore_0:
 586.465 +                    emit(out, "var @1 = @2;", lmapper.setA(0), smapper.popA());
 586.466 +                    break;
 586.467 +                case opc_istore_0:
 586.468 +                    emit(out, "var @1 = @2;", lmapper.setI(0), smapper.popI());
 586.469 +                    break;
 586.470 +                case opc_lstore_0:
 586.471 +                    emit(out, "var @1 = @2;", lmapper.setL(0), smapper.popL());
 586.472 +                    break;
 586.473 +                case opc_fstore_0:
 586.474 +                    emit(out, "var @1 = @2;", lmapper.setF(0), smapper.popF());
 586.475 +                    break;
 586.476 +                case opc_dstore_0:
 586.477 +                    emit(out, "var @1 = @2;", lmapper.setD(0), smapper.popD());
 586.478 +                    break;
 586.479 +                case opc_astore_1:
 586.480 +                    emit(out, "var @1 = @2;", lmapper.setA(1), smapper.popA());
 586.481 +                    break;
 586.482 +                case opc_istore_1:
 586.483 +                    emit(out, "var @1 = @2;", lmapper.setI(1), smapper.popI());
 586.484 +                    break;
 586.485 +                case opc_lstore_1:
 586.486 +                    emit(out, "var @1 = @2;", lmapper.setL(1), smapper.popL());
 586.487 +                    break;
 586.488 +                case opc_fstore_1:
 586.489 +                    emit(out, "var @1 = @2;", lmapper.setF(1), smapper.popF());
 586.490 +                    break;
 586.491 +                case opc_dstore_1:
 586.492 +                    emit(out, "var @1 = @2;", lmapper.setD(1), smapper.popD());
 586.493 +                    break;
 586.494 +                case opc_astore_2:
 586.495 +                    emit(out, "var @1 = @2;", lmapper.setA(2), smapper.popA());
 586.496 +                    break;
 586.497 +                case opc_istore_2:
 586.498 +                    emit(out, "var @1 = @2;", lmapper.setI(2), smapper.popI());
 586.499 +                    break;
 586.500 +                case opc_lstore_2:
 586.501 +                    emit(out, "var @1 = @2;", lmapper.setL(2), smapper.popL());
 586.502 +                    break;
 586.503 +                case opc_fstore_2:
 586.504 +                    emit(out, "var @1 = @2;", lmapper.setF(2), smapper.popF());
 586.505 +                    break;
 586.506 +                case opc_dstore_2:
 586.507 +                    emit(out, "var @1 = @2;", lmapper.setD(2), smapper.popD());
 586.508 +                    break;
 586.509 +                case opc_astore_3:
 586.510 +                    emit(out, "var @1 = @2;", lmapper.setA(3), smapper.popA());
 586.511 +                    break;
 586.512 +                case opc_istore_3:
 586.513 +                    emit(out, "var @1 = @2;", lmapper.setI(3), smapper.popI());
 586.514 +                    break;
 586.515 +                case opc_lstore_3:
 586.516 +                    emit(out, "var @1 = @2;", lmapper.setL(3), smapper.popL());
 586.517 +                    break;
 586.518 +                case opc_fstore_3:
 586.519 +                    emit(out, "var @1 = @2;", lmapper.setF(3), smapper.popF());
 586.520 +                    break;
 586.521 +                case opc_dstore_3:
 586.522 +                    emit(out, "var @1 = @2;", lmapper.setD(3), smapper.popD());
 586.523 +                    break;
 586.524 +                case opc_iadd:
 586.525 +                    emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
 586.526 +                    break;
 586.527 +                case opc_ladd:
 586.528 +                    emit(out, "@1 = @1.add64(@2);", smapper.getL(1), smapper.popL());
 586.529 +                    break;
 586.530 +                case opc_fadd:
 586.531 +                    emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
 586.532 +                    break;
 586.533 +                case opc_dadd:
 586.534 +                    emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
 586.535 +                    break;
 586.536 +                case opc_isub:
 586.537 +                    emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
 586.538 +                    break;
 586.539 +                case opc_lsub:
 586.540 +                    emit(out, "@1 = @1.sub64(@2);", smapper.getL(1), smapper.popL());
 586.541 +                    break;
 586.542 +                case opc_fsub:
 586.543 +                    emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
 586.544 +                    break;
 586.545 +                case opc_dsub:
 586.546 +                    emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
 586.547 +                    break;
 586.548 +                case opc_imul:
 586.549 +                    emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
 586.550 +                    break;
 586.551 +                case opc_lmul:
 586.552 +                    emit(out, "@1 = @1.mul64(@2);", smapper.getL(1), smapper.popL());
 586.553 +                    break;
 586.554 +                case opc_fmul:
 586.555 +                    emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
 586.556 +                    break;
 586.557 +                case opc_dmul:
 586.558 +                    emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
 586.559 +                    break;
 586.560 +                case opc_idiv:
 586.561 +                    emit(out, "@1 = @1.div32(@2);",
 586.562 +                         smapper.getI(1), smapper.popI());
 586.563 +                    break;
 586.564 +                case opc_ldiv:
 586.565 +                    emit(out, "@1 = @1.div64(@2);",
 586.566 +                         smapper.getL(1), smapper.popL());
 586.567 +                    break;
 586.568 +                case opc_fdiv:
 586.569 +                    emit(out, "@1 /= @2;", smapper.getF(1), smapper.popF());
 586.570 +                    break;
 586.571 +                case opc_ddiv:
 586.572 +                    emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
 586.573 +                    break;
 586.574 +                case opc_irem:
 586.575 +                    emit(out, "@1 = @1.mod32(@2);",
 586.576 +                         smapper.getI(1), smapper.popI());
 586.577 +                    break;
 586.578 +                case opc_lrem:
 586.579 +                    emit(out, "@1 = @1.mod64(@2);",
 586.580 +                         smapper.getL(1), smapper.popL());
 586.581 +                    break;
 586.582 +                case opc_frem:
 586.583 +                    emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
 586.584 +                    break;
 586.585 +                case opc_drem:
 586.586 +                    emit(out, "@1 %= @2;", smapper.getD(1), smapper.popD());
 586.587 +                    break;
 586.588 +                case opc_iand:
 586.589 +                    emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
 586.590 +                    break;
 586.591 +                case opc_land:
 586.592 +                    emit(out, "@1 = @1.and64(@2);", smapper.getL(1), smapper.popL());
 586.593 +                    break;
 586.594 +                case opc_ior:
 586.595 +                    emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
 586.596 +                    break;
 586.597 +                case opc_lor:
 586.598 +                    emit(out, "@1 = @1.or64(@2);", smapper.getL(1), smapper.popL());
 586.599 +                    break;
 586.600 +                case opc_ixor:
 586.601 +                    emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
 586.602 +                    break;
 586.603 +                case opc_lxor:
 586.604 +                    emit(out, "@1 = @1.xor64(@2);", smapper.getL(1), smapper.popL());
 586.605 +                    break;
 586.606 +                case opc_ineg:
 586.607 +                    emit(out, "@1 = @1.neg32();", smapper.getI(0));
 586.608 +                    break;
 586.609 +                case opc_lneg:
 586.610 +                    emit(out, "@1 = @1.neg64();", smapper.getL(0));
 586.611 +                    break;
 586.612 +                case opc_fneg:
 586.613 +                    emit(out, "@1 = -@1;", smapper.getF(0));
 586.614 +                    break;
 586.615 +                case opc_dneg:
 586.616 +                    emit(out, "@1 = -@1;", smapper.getD(0));
 586.617 +                    break;
 586.618 +                case opc_ishl:
 586.619 +                    emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
 586.620 +                    break;
 586.621 +                case opc_lshl:
 586.622 +                    emit(out, "@1 = @1.shl64(@2);", smapper.getL(1), smapper.popI());
 586.623 +                    break;
 586.624 +                case opc_ishr:
 586.625 +                    emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
 586.626 +                    break;
 586.627 +                case opc_lshr:
 586.628 +                    emit(out, "@1 = @1.shr64(@2);", smapper.getL(1), smapper.popI());
 586.629 +                    break;
 586.630 +                case opc_iushr:
 586.631 +                    emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
 586.632 +                    break;
 586.633 +                case opc_lushr:
 586.634 +                    emit(out, "@1 = @1.ushr64(@2);", smapper.getL(1), smapper.popI());
 586.635 +                    break;
 586.636 +                case opc_iinc: {
 586.637 +                    ++i;
 586.638 +                    final int varIndx = wide ? readUShort(byteCodes, i++)
 586.639 +                                             : readUByte(byteCodes, i);
 586.640 +                    ++i;
 586.641 +                    final int incrBy = wide ? readShort(byteCodes, i++)
 586.642 +                                            : byteCodes[i];
 586.643 +                    wide = false;
 586.644 +                    if (incrBy == 1) {
 586.645 +                        emit(out, "@1++;", lmapper.getI(varIndx));
 586.646 +                    } else {
 586.647 +                        emit(out, "@1 += @2;",
 586.648 +                             lmapper.getI(varIndx),
 586.649 +                             Integer.toString(incrBy));
 586.650 +                    }
 586.651 +                    break;
 586.652 +                }
 586.653 +                case opc_return:
 586.654 +                    emit(out, "return;");
 586.655 +                    break;
 586.656 +                case opc_ireturn:
 586.657 +                    emit(out, "return @1;", smapper.popI());
 586.658 +                    break;
 586.659 +                case opc_lreturn:
 586.660 +                    emit(out, "return @1;", smapper.popL());
 586.661 +                    break;
 586.662 +                case opc_freturn:
 586.663 +                    emit(out, "return @1;", smapper.popF());
 586.664 +                    break;
 586.665 +                case opc_dreturn:
 586.666 +                    emit(out, "return @1;", smapper.popD());
 586.667 +                    break;
 586.668 +                case opc_areturn:
 586.669 +                    emit(out, "return @1;", smapper.popA());
 586.670 +                    break;
 586.671 +                case opc_i2l:
 586.672 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushL());
 586.673 +                    break;
 586.674 +                case opc_i2f:
 586.675 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushF());
 586.676 +                    break;
 586.677 +                case opc_i2d:
 586.678 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
 586.679 +                    break;
 586.680 +                case opc_l2i:
 586.681 +                    emit(out, "var @2 = @1.toInt32();", smapper.popL(), smapper.pushI());
 586.682 +                    break;
 586.683 +                    // max int check?
 586.684 +                case opc_l2f:
 586.685 +                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushF());
 586.686 +                    break;
 586.687 +                case opc_l2d:
 586.688 +                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushD());
 586.689 +                    break;
 586.690 +                case opc_f2d:
 586.691 +                    emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
 586.692 +                    break;
 586.693 +                case opc_d2f:
 586.694 +                    emit(out, "var @2 = @1;", smapper.popD(), smapper.pushF());
 586.695 +                    break;
 586.696 +                case opc_f2i:
 586.697 +                    emit(out, "var @2 = Math.floor(@1).toInt32();",
 586.698 +                         smapper.popF(), smapper.pushI());
 586.699 +                    break;
 586.700 +                case opc_f2l:
 586.701 +                    emit(out, "var @2 = Math.floor(@1).toLong();",
 586.702 +                         smapper.popF(), smapper.pushL());
 586.703 +                    break;
 586.704 +                case opc_d2i:
 586.705 +                    emit(out, "var @2 = Math.floor(@1).toInt32();",
 586.706 +                         smapper.popD(), smapper.pushI());
 586.707 +                    break;
 586.708 +                case opc_d2l:
 586.709 +                    emit(out, "var @2 = Math.floor(@1).toLong();",
 586.710 +                         smapper.popD(), smapper.pushL());
 586.711 +                    break;
 586.712 +                case opc_i2b:
 586.713 +                    emit(out, "var @1 = @1.toInt8();", smapper.getI(0));
 586.714 +                    break;
 586.715 +                case opc_i2c:
 586.716 +                    out.append("{ /* number conversion */ }");
 586.717 +                    break;
 586.718 +                case opc_i2s:
 586.719 +                    emit(out, "var @1 = @1.toInt16();", smapper.getI(0));
 586.720 +                    break;
 586.721 +                case opc_aconst_null:
 586.722 +                    emit(out, "var @1 = null;", smapper.pushA());
 586.723 +                    break;
 586.724 +                case opc_iconst_m1:
 586.725 +                    emit(out, "var @1 = -1;", smapper.pushI());
 586.726 +                    break;
 586.727 +                case opc_iconst_0:
 586.728 +                    emit(out, "var @1 = 0;", smapper.pushI());
 586.729 +                    break;
 586.730 +                case opc_dconst_0:
 586.731 +                    emit(out, "var @1 = 0;", smapper.pushD());
 586.732 +                    break;
 586.733 +                case opc_lconst_0:
 586.734 +                    emit(out, "var @1 = 0;", smapper.pushL());
 586.735 +                    break;
 586.736 +                case opc_fconst_0:
 586.737 +                    emit(out, "var @1 = 0;", smapper.pushF());
 586.738 +                    break;
 586.739 +                case opc_iconst_1:
 586.740 +                    emit(out, "var @1 = 1;", smapper.pushI());
 586.741 +                    break;
 586.742 +                case opc_lconst_1:
 586.743 +                    emit(out, "var @1 = 1;", smapper.pushL());
 586.744 +                    break;
 586.745 +                case opc_fconst_1:
 586.746 +                    emit(out, "var @1 = 1;", smapper.pushF());
 586.747 +                    break;
 586.748 +                case opc_dconst_1:
 586.749 +                    emit(out, "var @1 = 1;", smapper.pushD());
 586.750 +                    break;
 586.751 +                case opc_iconst_2:
 586.752 +                    emit(out, "var @1 = 2;", smapper.pushI());
 586.753 +                    break;
 586.754 +                case opc_fconst_2:
 586.755 +                    emit(out, "var @1 = 2;", smapper.pushF());
 586.756 +                    break;
 586.757 +                case opc_iconst_3:
 586.758 +                    emit(out, "var @1 = 3;", smapper.pushI());
 586.759 +                    break;
 586.760 +                case opc_iconst_4:
 586.761 +                    emit(out, "var @1 = 4;", smapper.pushI());
 586.762 +                    break;
 586.763 +                case opc_iconst_5:
 586.764 +                    emit(out, "var @1 = 5;", smapper.pushI());
 586.765 +                    break;
 586.766 +                case opc_ldc: {
 586.767 +                    int indx = readUByte(byteCodes, ++i);
 586.768 +                    String v = encodeConstant(indx);
 586.769 +                    int type = VarType.fromConstantType(jc.getTag(indx));
 586.770 +                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
 586.771 +                    break;
 586.772 +                }
 586.773 +                case opc_ldc_w:
 586.774 +                case opc_ldc2_w: {
 586.775 +                    int indx = readIntArg(byteCodes, i);
 586.776 +                    i += 2;
 586.777 +                    String v = encodeConstant(indx);
 586.778 +                    int type = VarType.fromConstantType(jc.getTag(indx));
 586.779 +                    if (type == VarType.LONG) {
 586.780 +                        final Long lv = new Long(v);
 586.781 +                        final int low = (int)(lv.longValue() & 0xFFFFFFFF);
 586.782 +                        final int hi = (int)(lv.longValue() >> 32);
 586.783 +                        emit(out, "var @1 = 0x@3.next32(0x@2);", smapper.pushL(), 
 586.784 +                                Integer.toHexString(low), Integer.toHexString(hi));
 586.785 +                    } else {
 586.786 +                        emit(out, "var @1 = @2;", smapper.pushT(type), v);
 586.787 +                    }
 586.788 +                    break;
 586.789 +                }
 586.790 +                case opc_lcmp:
 586.791 +                    emit(out, "var @3 = @2.compare64(@1);",
 586.792 +                         smapper.popL(), smapper.popL(), smapper.pushI());
 586.793 +                    break;
 586.794 +                case opc_fcmpl:
 586.795 +                case opc_fcmpg:
 586.796 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 586.797 +                         smapper.popF(), smapper.popF(), smapper.pushI());
 586.798 +                    break;
 586.799 +                case opc_dcmpl:
 586.800 +                case opc_dcmpg:
 586.801 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 586.802 +                         smapper.popD(), smapper.popD(), smapper.pushI());
 586.803 +                    break;
 586.804 +                case opc_if_acmpeq:
 586.805 +                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
 586.806 +                                   "===");
 586.807 +                    break;
 586.808 +                case opc_if_acmpne:
 586.809 +                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
 586.810 +                                   "!=");
 586.811 +                    break;
 586.812 +                case opc_if_icmpeq:
 586.813 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 586.814 +                                   "==");
 586.815 +                    break;
 586.816 +                case opc_ifeq: {
 586.817 +                    int indx = i + readIntArg(byteCodes, i);
 586.818 +                    emit(out, "if (@1 == 0) { gt = @2; continue; }",
 586.819 +                         smapper.popI(), Integer.toString(indx));
 586.820 +                    i += 2;
 586.821 +                    break;
 586.822 +                }
 586.823 +                case opc_ifne: {
 586.824 +                    int indx = i + readIntArg(byteCodes, i);
 586.825 +                    emit(out, "if (@1 != 0) { gt = @2; continue; }",
 586.826 +                         smapper.popI(), Integer.toString(indx));
 586.827 +                    i += 2;
 586.828 +                    break;
 586.829 +                }
 586.830 +                case opc_iflt: {
 586.831 +                    int indx = i + readIntArg(byteCodes, i);
 586.832 +                    emit(out, "if (@1 < 0) { gt = @2; continue; }",
 586.833 +                         smapper.popI(), Integer.toString(indx));
 586.834 +                    i += 2;
 586.835 +                    break;
 586.836 +                }
 586.837 +                case opc_ifle: {
 586.838 +                    int indx = i + readIntArg(byteCodes, i);
 586.839 +                    emit(out, "if (@1 <= 0) { gt = @2; continue; }",
 586.840 +                         smapper.popI(), Integer.toString(indx));
 586.841 +                    i += 2;
 586.842 +                    break;
 586.843 +                }
 586.844 +                case opc_ifgt: {
 586.845 +                    int indx = i + readIntArg(byteCodes, i);
 586.846 +                    emit(out, "if (@1 > 0) { gt = @2; continue; }",
 586.847 +                         smapper.popI(), Integer.toString(indx));
 586.848 +                    i += 2;
 586.849 +                    break;
 586.850 +                }
 586.851 +                case opc_ifge: {
 586.852 +                    int indx = i + readIntArg(byteCodes, i);
 586.853 +                    emit(out, "if (@1 >= 0) { gt = @2; continue; }",
 586.854 +                         smapper.popI(), Integer.toString(indx));
 586.855 +                    i += 2;
 586.856 +                    break;
 586.857 +                }
 586.858 +                case opc_ifnonnull: {
 586.859 +                    int indx = i + readIntArg(byteCodes, i);
 586.860 +                    emit(out, "if (@1 !== null) { gt = @2; continue; }",
 586.861 +                         smapper.popA(), Integer.toString(indx));
 586.862 +                    i += 2;
 586.863 +                    break;
 586.864 +                }
 586.865 +                case opc_ifnull: {
 586.866 +                    int indx = i + readIntArg(byteCodes, i);
 586.867 +                    emit(out, "if (@1 === null) { gt = @2; continue; }",
 586.868 +                         smapper.popA(), Integer.toString(indx));
 586.869 +                    i += 2;
 586.870 +                    break;
 586.871 +                }
 586.872 +                case opc_if_icmpne:
 586.873 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 586.874 +                                   "!=");
 586.875 +                    break;
 586.876 +                case opc_if_icmplt:
 586.877 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 586.878 +                                   "<");
 586.879 +                    break;
 586.880 +                case opc_if_icmple:
 586.881 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 586.882 +                                   "<=");
 586.883 +                    break;
 586.884 +                case opc_if_icmpgt:
 586.885 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 586.886 +                                   ">");
 586.887 +                    break;
 586.888 +                case opc_if_icmpge:
 586.889 +                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 586.890 +                                   ">=");
 586.891 +                    break;
 586.892 +                case opc_goto: {
 586.893 +                    int indx = i + readIntArg(byteCodes, i);
 586.894 +                    emit(out, "gt = @1; continue;", Integer.toString(indx));
 586.895 +                    i += 2;
 586.896 +                    break;
 586.897 +                }
 586.898 +                case opc_lookupswitch: {
 586.899 +                    int table = i / 4 * 4 + 4;
 586.900 +                    int dflt = i + readInt4(byteCodes, table);
 586.901 +                    table += 4;
 586.902 +                    int n = readInt4(byteCodes, table);
 586.903 +                    table += 4;
 586.904 +                    out.append("switch (").append(smapper.popI()).append(") {\n");
 586.905 +                    while (n-- > 0) {
 586.906 +                        int cnstnt = readInt4(byteCodes, table);
 586.907 +                        table += 4;
 586.908 +                        int offset = i + readInt4(byteCodes, table);
 586.909 +                        table += 4;
 586.910 +                        out.append("  case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
 586.911 +                    }
 586.912 +                    out.append("  default: gt = " + dflt).append("; continue;\n}");
 586.913 +                    i = table - 1;
 586.914 +                    break;
 586.915 +                }
 586.916 +                case opc_tableswitch: {
 586.917 +                    int table = i / 4 * 4 + 4;
 586.918 +                    int dflt = i + readInt4(byteCodes, table);
 586.919 +                    table += 4;
 586.920 +                    int low = readInt4(byteCodes, table);
 586.921 +                    table += 4;
 586.922 +                    int high = readInt4(byteCodes, table);
 586.923 +                    table += 4;
 586.924 +                    out.append("switch (").append(smapper.popI()).append(") {\n");
 586.925 +                    while (low <= high) {
 586.926 +                        int offset = i + readInt4(byteCodes, table);
 586.927 +                        table += 4;
 586.928 +                        out.append("  case " + low).append(": gt = " + offset).append("; continue;\n");
 586.929 +                        low++;
 586.930 +                    }
 586.931 +                    out.append("  default: gt = " + dflt).append("; continue;\n}");
 586.932 +                    i = table - 1;
 586.933 +                    break;
 586.934 +                }
 586.935 +                case opc_invokeinterface: {
 586.936 +                    i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
 586.937 +                    break;
 586.938 +                }
 586.939 +                case opc_invokevirtual:
 586.940 +                    i = invokeVirtualMethod(byteCodes, i, smapper);
 586.941 +                    break;
 586.942 +                case opc_invokespecial:
 586.943 +                    i = invokeStaticMethod(byteCodes, i, smapper, false);
 586.944 +                    break;
 586.945 +                case opc_invokestatic:
 586.946 +                    i = invokeStaticMethod(byteCodes, i, smapper, true);
 586.947 +                    break;
 586.948 +                case opc_new: {
 586.949 +                    int indx = readIntArg(byteCodes, i);
 586.950 +                    String ci = jc.getClassName(indx);
 586.951 +                    emit(out, "var @1 = new @2;",
 586.952 +                         smapper.pushA(), accessClass(ci.replace('/', '_')));
 586.953 +                    addReference(ci);
 586.954 +                    i += 2;
 586.955 +                    break;
 586.956 +                }
 586.957 +                case opc_newarray:
 586.958 +                    int atype = readUByte(byteCodes, ++i);
 586.959 +                    String jvmType;
 586.960 +                    switch (atype) {
 586.961 +                        case 4: jvmType = "[Z"; break;
 586.962 +                        case 5: jvmType = "[C"; break;
 586.963 +                        case 6: jvmType = "[F"; break;
 586.964 +                        case 7: jvmType = "[D"; break;
 586.965 +                        case 8: jvmType = "[B"; break;
 586.966 +                        case 9: jvmType = "[S"; break;
 586.967 +                        case 10: jvmType = "[I"; break;
 586.968 +                        case 11: jvmType = "[J"; break;
 586.969 +                        default: throw new IllegalStateException("Array type: " + atype);
 586.970 +                    }
 586.971 +                    emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(true, '@3', @1);",
 586.972 +                         smapper.popI(), smapper.pushA(), jvmType);
 586.973 +                    break;
 586.974 +                case opc_anewarray: {
 586.975 +                    int type = readIntArg(byteCodes, i);
 586.976 +                    i += 2;
 586.977 +                    String typeName = jc.getClassName(type);
 586.978 +                    if (typeName.startsWith("[")) {
 586.979 +                        typeName = "[" + typeName;
 586.980 +                    } else {
 586.981 +                        typeName = "[L" + typeName + ";";
 586.982 +                    }
 586.983 +                    emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(false, '@3', @1);",
 586.984 +                         smapper.popI(), smapper.pushA(), typeName);
 586.985 +                    break;
 586.986 +                }
 586.987 +                case opc_multianewarray: {
 586.988 +                    int type = readIntArg(byteCodes, i);
 586.989 +                    i += 2;
 586.990 +                    String typeName = jc.getClassName(type);
 586.991 +                    int dim = readUByte(byteCodes, ++i);
 586.992 +                    StringBuilder dims = new StringBuilder();
 586.993 +                    dims.append('[');
 586.994 +                    for (int d = 0; d < dim; d++) {
 586.995 +                        if (d != 0) {
 586.996 +                            dims.append(",");
 586.997 +                        }
 586.998 +                        dims.append(smapper.popI());
 586.999 +                    }
586.1000 +                    dims.append(']');
586.1001 +                    emit(out, "var @2 = Array.prototype.multiNewArray__Ljava_lang_Object_2Ljava_lang_String_2_3II('@3', @1, 0);",
586.1002 +                         dims.toString(), smapper.pushA(), typeName);
586.1003 +                    break;
586.1004 +                }
586.1005 +                case opc_arraylength:
586.1006 +                    emit(out, "var @2 = @1.length;",
586.1007 +                         smapper.popA(), smapper.pushI());
586.1008 +                    break;
586.1009 +                case opc_lastore:
586.1010 +                    emit(out, "@3.at(@2, @1);",
586.1011 +                         smapper.popL(), smapper.popI(), smapper.popA());
586.1012 +                    break;
586.1013 +                case opc_fastore:
586.1014 +                    emit(out, "@3.at(@2, @1);",
586.1015 +                         smapper.popF(), smapper.popI(), smapper.popA());
586.1016 +                    break;
586.1017 +                case opc_dastore:
586.1018 +                    emit(out, "@3.at(@2, @1);",
586.1019 +                         smapper.popD(), smapper.popI(), smapper.popA());
586.1020 +                    break;
586.1021 +                case opc_aastore:
586.1022 +                    emit(out, "@3.at(@2, @1);",
586.1023 +                         smapper.popA(), smapper.popI(), smapper.popA());
586.1024 +                    break;
586.1025 +                case opc_iastore:
586.1026 +                case opc_bastore:
586.1027 +                case opc_castore:
586.1028 +                case opc_sastore:
586.1029 +                    emit(out, "@3.at(@2, @1);",
586.1030 +                         smapper.popI(), smapper.popI(), smapper.popA());
586.1031 +                    break;
586.1032 +                case opc_laload:
586.1033 +                    emit(out, "var @3 = @2.at(@1);",
586.1034 +                         smapper.popI(), smapper.popA(), smapper.pushL());
586.1035 +                    break;
586.1036 +                case opc_faload:
586.1037 +                    emit(out, "var @3 = @2.at(@1);",
586.1038 +                         smapper.popI(), smapper.popA(), smapper.pushF());
586.1039 +                    break;
586.1040 +                case opc_daload:
586.1041 +                    emit(out, "var @3 = @2.at(@1);",
586.1042 +                         smapper.popI(), smapper.popA(), smapper.pushD());
586.1043 +                    break;
586.1044 +                case opc_aaload:
586.1045 +                    emit(out, "var @3 = @2.at(@1);",
586.1046 +                         smapper.popI(), smapper.popA(), smapper.pushA());
586.1047 +                    break;
586.1048 +                case opc_iaload:
586.1049 +                case opc_baload:
586.1050 +                case opc_caload:
586.1051 +                case opc_saload:
586.1052 +                    emit(out, "var @3 = @2.at(@1);",
586.1053 +                         smapper.popI(), smapper.popA(), smapper.pushI());
586.1054 +                    break;
586.1055 +                case opc_pop:
586.1056 +                case opc_pop2:
586.1057 +                    smapper.pop(1);
586.1058 +                    debug("/* pop */");
586.1059 +                    break;
586.1060 +                case opc_dup: {
586.1061 +                    final Variable v = smapper.get(0);
586.1062 +                    emit(out, "var @1 = @2;", smapper.pushT(v.getType()), v);
586.1063 +                    break;
586.1064 +                }
586.1065 +                case opc_dup2: {
586.1066 +                    final Variable vi1 = smapper.get(0);
586.1067 +
586.1068 +                    if (vi1.isCategory2()) {
586.1069 +                        emit(out, "var @1 = @2;",
586.1070 +                             smapper.pushT(vi1.getType()), vi1);
586.1071 +                    } else {
586.1072 +                        final Variable vi2 = smapper.get(1);
586.1073 +                        emit(out, "var @1 = @2, @3 = @4;",
586.1074 +                             smapper.pushT(vi2.getType()), vi2,
586.1075 +                             smapper.pushT(vi1.getType()), vi1);
586.1076 +                    }
586.1077 +                    break;
586.1078 +                }
586.1079 +                case opc_dup_x1: {
586.1080 +                    final Variable vi1 = smapper.pop();
586.1081 +                    final Variable vi2 = smapper.pop();
586.1082 +                    final Variable vo3 = smapper.pushT(vi1.getType());
586.1083 +                    final Variable vo2 = smapper.pushT(vi2.getType());
586.1084 +                    final Variable vo1 = smapper.pushT(vi1.getType());
586.1085 +
586.1086 +                    emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
586.1087 +                         vo1, vi1, vo2, vi2, vo3, vo1);
586.1088 +                    break;
586.1089 +                }
586.1090 +                case opc_dup2_x1: {
586.1091 +                    final Variable vi1 = smapper.pop();
586.1092 +                    final Variable vi2 = smapper.pop();
586.1093 +
586.1094 +                    if (vi1.isCategory2()) {
586.1095 +                        final Variable vo3 = smapper.pushT(vi1.getType());
586.1096 +                        final Variable vo2 = smapper.pushT(vi2.getType());
586.1097 +                        final Variable vo1 = smapper.pushT(vi1.getType());
586.1098 +
586.1099 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
586.1100 +                             vo1, vi1, vo2, vi2, vo3, vo1);
586.1101 +                    } else {
586.1102 +                        final Variable vi3 = smapper.pop();
586.1103 +                        final Variable vo5 = smapper.pushT(vi2.getType());
586.1104 +                        final Variable vo4 = smapper.pushT(vi1.getType());
586.1105 +                        final Variable vo3 = smapper.pushT(vi3.getType());
586.1106 +                        final Variable vo2 = smapper.pushT(vi2.getType());
586.1107 +                        final Variable vo1 = smapper.pushT(vi1.getType());
586.1108 +
586.1109 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6,",
586.1110 +                             vo1, vi1, vo2, vi2, vo3, vi3);
586.1111 +                        emit(out, " @1 = @2, @3 = @4;",
586.1112 +                             vo4, vo1, vo5, vo2);
586.1113 +                    }
586.1114 +                    break;
586.1115 +                }
586.1116 +                case opc_dup_x2: {
586.1117 +                    final Variable vi1 = smapper.pop();
586.1118 +                    final Variable vi2 = smapper.pop();
586.1119 +
586.1120 +                    if (vi2.isCategory2()) {
586.1121 +                        final Variable vo3 = smapper.pushT(vi1.getType());
586.1122 +                        final Variable vo2 = smapper.pushT(vi2.getType());
586.1123 +                        final Variable vo1 = smapper.pushT(vi1.getType());
586.1124 +
586.1125 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
586.1126 +                             vo1, vi1, vo2, vi2, vo3, vo1);
586.1127 +                    } else {
586.1128 +                        final Variable vi3 = smapper.pop();
586.1129 +                        final Variable vo4 = smapper.pushT(vi1.getType());
586.1130 +                        final Variable vo3 = smapper.pushT(vi3.getType());
586.1131 +                        final Variable vo2 = smapper.pushT(vi2.getType());
586.1132 +                        final Variable vo1 = smapper.pushT(vi1.getType());
586.1133 +
586.1134 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
586.1135 +                             vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
586.1136 +                    }
586.1137 +                    break;
586.1138 +                }
586.1139 +                case opc_dup2_x2: {
586.1140 +                    final Variable vi1 = smapper.pop();
586.1141 +                    final Variable vi2 = smapper.pop();
586.1142 +
586.1143 +                    if (vi1.isCategory2()) {
586.1144 +                        if (vi2.isCategory2()) {
586.1145 +                            final Variable vo3 = smapper.pushT(vi1.getType());
586.1146 +                            final Variable vo2 = smapper.pushT(vi2.getType());
586.1147 +                            final Variable vo1 = smapper.pushT(vi1.getType());
586.1148 +
586.1149 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
586.1150 +                                 vo1, vi1, vo2, vi2, vo3, vo1);
586.1151 +                        } else {
586.1152 +                            final Variable vi3 = smapper.pop();
586.1153 +                            final Variable vo4 = smapper.pushT(vi1.getType());
586.1154 +                            final Variable vo3 = smapper.pushT(vi3.getType());
586.1155 +                            final Variable vo2 = smapper.pushT(vi2.getType());
586.1156 +                            final Variable vo1 = smapper.pushT(vi1.getType());
586.1157 +
586.1158 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
586.1159 +                                 vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
586.1160 +                        }
586.1161 +                    } else {
586.1162 +                        final Variable vi3 = smapper.pop();
586.1163 +
586.1164 +                        if (vi3.isCategory2()) {
586.1165 +                            final Variable vo5 = smapper.pushT(vi2.getType());
586.1166 +                            final Variable vo4 = smapper.pushT(vi1.getType());
586.1167 +                            final Variable vo3 = smapper.pushT(vi3.getType());
586.1168 +                            final Variable vo2 = smapper.pushT(vi2.getType());
586.1169 +                            final Variable vo1 = smapper.pushT(vi1.getType());
586.1170 +
586.1171 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6,",
586.1172 +                                 vo1, vi1, vo2, vi2, vo3, vi3);
586.1173 +                            emit(out, " @1 = @2, @3 = @4;",
586.1174 +                                 vo4, vo1, vo5, vo2);
586.1175 +                        } else {
586.1176 +                            final Variable vi4 = smapper.pop();
586.1177 +                            final Variable vo6 = smapper.pushT(vi2.getType());
586.1178 +                            final Variable vo5 = smapper.pushT(vi1.getType());
586.1179 +                            final Variable vo4 = smapper.pushT(vi4.getType());
586.1180 +                            final Variable vo3 = smapper.pushT(vi3.getType());
586.1181 +                            final Variable vo2 = smapper.pushT(vi2.getType());
586.1182 +                            final Variable vo1 = smapper.pushT(vi1.getType());
586.1183 +                            
586.1184 +                            emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8,",
586.1185 +                                 vo1, vi1, vo2, vi2, vo3, vi3, vo4, vi4);
586.1186 +                            emit(out, " @1 = @2, @3 = @4;",
586.1187 +                                 vo5, vo1, vo6, vo2);
586.1188 +                        }
586.1189 +                    }
586.1190 +                    break;
586.1191 +                }
586.1192 +                case opc_swap: {
586.1193 +                    final Variable vi1 = smapper.get(0);
586.1194 +                    final Variable vi2 = smapper.get(1);
586.1195 +
586.1196 +                    if (vi1.getType() == vi2.getType()) {
586.1197 +                        final Variable tmp = smapper.pushT(vi1.getType());
586.1198 +
586.1199 +                        emit(out, "var @1 = @2, @2 = @3, @3 = @1;",
586.1200 +                             tmp, vi1, vi2);
586.1201 +                        smapper.pop(1);
586.1202 +                    } else {
586.1203 +                        smapper.pop(2);
586.1204 +                        smapper.pushT(vi1.getType());
586.1205 +                        smapper.pushT(vi2.getType());
586.1206 +                    }
586.1207 +                    break;
586.1208 +                }
586.1209 +                case opc_bipush:
586.1210 +                    emit(out, "var @1 = @2;",
586.1211 +                         smapper.pushI(), Integer.toString(byteCodes[++i]));
586.1212 +                    break;
586.1213 +                case opc_sipush:
586.1214 +                    emit(out, "var @1 = @2;",
586.1215 +                         smapper.pushI(),
586.1216 +                         Integer.toString(readIntArg(byteCodes, i)));
586.1217 +                    i += 2;
586.1218 +                    break;
586.1219 +                case opc_getfield: {
586.1220 +                    int indx = readIntArg(byteCodes, i);
586.1221 +                    String[] fi = jc.getFieldInfoName(indx);
586.1222 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
586.1223 +                    final String mangleClass = mangleSig(fi[0]);
586.1224 +                    final String mangleClassAccess = accessClass(mangleClass);
586.1225 +                    emit(out, "var @2 = @4(false)._@3.call(@1);",
586.1226 +                         smapper.popA(),
586.1227 +                         smapper.pushT(type), fi[1], mangleClassAccess
586.1228 +                    );
586.1229 +                    i += 2;
586.1230 +                    break;
586.1231 +                }
586.1232 +                case opc_putfield: {
586.1233 +                    int indx = readIntArg(byteCodes, i);
586.1234 +                    String[] fi = jc.getFieldInfoName(indx);
586.1235 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
586.1236 +                    final String mangleClass = mangleSig(fi[0]);
586.1237 +                    final String mangleClassAccess = accessClass(mangleClass);
586.1238 +                    emit(out, "@4(false)._@3.call(@2, @1);",
586.1239 +                         smapper.popT(type),
586.1240 +                         smapper.popA(), fi[1], 
586.1241 +                         mangleClassAccess
586.1242 +                    );
586.1243 +                    i += 2;
586.1244 +                    break;
586.1245 +                }
586.1246 +                case opc_getstatic: {
586.1247 +                    int indx = readIntArg(byteCodes, i);
586.1248 +                    String[] fi = jc.getFieldInfoName(indx);
586.1249 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
586.1250 +                    emit(out, "var @1 = @2(false).constructor.@3;",
586.1251 +                         smapper.pushT(type),
586.1252 +                         accessClass(fi[0].replace('/', '_')), fi[1]);
586.1253 +                    i += 2;
586.1254 +                    addReference(fi[0]);
586.1255 +                    break;
586.1256 +                }
586.1257 +                case opc_putstatic: {
586.1258 +                    int indx = readIntArg(byteCodes, i);
586.1259 +                    String[] fi = jc.getFieldInfoName(indx);
586.1260 +                    final int type = VarType.fromFieldType(fi[2].charAt(0));
586.1261 +                    emit(out, "@1(false).constructor.@2 = @3;",
586.1262 +                         accessClass(fi[0].replace('/', '_')), fi[1],
586.1263 +                         smapper.popT(type));
586.1264 +                    i += 2;
586.1265 +                    addReference(fi[0]);
586.1266 +                    break;
586.1267 +                }
586.1268 +                case opc_checkcast: {
586.1269 +                    int indx = readIntArg(byteCodes, i);
586.1270 +                    final String type = jc.getClassName(indx);
586.1271 +                    if (!type.startsWith("[")) {
586.1272 +                        emit(out,
586.1273 +                             "if (@1 !== null && !@1.$instOf_@2) throw {};",
586.1274 +                             smapper.getA(0), type.replace('/', '_'));
586.1275 +                    } else {
586.1276 +                        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);",
586.1277 +                             smapper.getA(0), type
586.1278 +                        );
586.1279 +                    }
586.1280 +                    i += 2;
586.1281 +                    break;
586.1282 +                }
586.1283 +                case opc_instanceof: {
586.1284 +                    int indx = readIntArg(byteCodes, i);
586.1285 +                    final String type = jc.getClassName(indx);
586.1286 +                    if (!type.startsWith("[")) {
586.1287 +                        emit(out, "var @2 = @1 != null && @1.$instOf_@3 ? 1 : 0;",
586.1288 +                             smapper.popA(), smapper.pushI(),
586.1289 +                             type.replace('/', '_'));
586.1290 +                    } else {
586.1291 +                        emit(out, "var @2 = vm.java_lang_Class(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('@3').isInstance__ZLjava_lang_Object_2(@1);",
586.1292 +                            smapper.popA(), smapper.pushI(),
586.1293 +                            type
586.1294 +                        );
586.1295 +                    }
586.1296 +                    i += 2;
586.1297 +                    break;
586.1298 +                }
586.1299 +                case opc_athrow: {
586.1300 +                    final Variable v = smapper.popA();
586.1301 +                    smapper.clear();
586.1302 +
586.1303 +                    emit(out, "{ var @1 = @2; throw @2; }",
586.1304 +                         smapper.pushA(), v);
586.1305 +                    break;
586.1306 +                }
586.1307 +
586.1308 +                case opc_monitorenter: {
586.1309 +                    out.append("/* monitor enter */");
586.1310 +                    smapper.popA();
586.1311 +                    break;
586.1312 +                }
586.1313 +
586.1314 +                case opc_monitorexit: {
586.1315 +                    out.append("/* monitor exit */");
586.1316 +                    smapper.popA();
586.1317 +                    break;
586.1318 +                }
586.1319 +
586.1320 +                case opc_wide:
586.1321 +                    wide = true;
586.1322 +                    break;
586.1323 +
586.1324 +                default: {
586.1325 +                    wide = false;
586.1326 +                    emit(out, "throw 'unknown bytecode @1';",
586.1327 +                         Integer.toString(c));
586.1328 +                }
586.1329 +            }
586.1330 +            if (debug(" //")) {
586.1331 +                for (int j = prev; j <= i; j++) {
586.1332 +                    out.append(" ");
586.1333 +                    final int cc = readUByte(byteCodes, j);
586.1334 +                    out.append(Integer.toString(cc));
586.1335 +                }
586.1336 +            }
586.1337 +            out.append("\n");            
586.1338 +        }
586.1339 +        if (previousTrap != null) {
586.1340 +            generateCatch(previousTrap);
586.1341 +        }
586.1342 +        out.append("  }\n");
586.1343 +        out.append("};");
586.1344 +    }
586.1345 +
586.1346 +    private int generateIf(byte[] byteCodes, int i,
586.1347 +                           final Variable v2, final Variable v1,
586.1348 +                           final String test) throws IOException {
586.1349 +        int indx = i + readIntArg(byteCodes, i);
586.1350 +        out.append("if (").append(v1)
586.1351 +           .append(' ').append(test).append(' ')
586.1352 +           .append(v2).append(") { gt = " + indx)
586.1353 +           .append("; continue; }");
586.1354 +        return i + 2;
586.1355 +    }
586.1356 +
586.1357 +    private int readIntArg(byte[] byteCodes, int offsetInstruction) {
586.1358 +        final int indxHi = byteCodes[offsetInstruction + 1] << 8;
586.1359 +        final int indxLo = byteCodes[offsetInstruction + 2];
586.1360 +        return (indxHi & 0xffffff00) | (indxLo & 0xff);
586.1361 +    }
586.1362 +    private int readInt4(byte[] byteCodes, int offset) {
586.1363 +        final int d = byteCodes[offset + 0] << 24;
586.1364 +        final int c = byteCodes[offset + 1] << 16;
586.1365 +        final int b = byteCodes[offset + 2] << 8;
586.1366 +        final int a = byteCodes[offset + 3];
586.1367 +        return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
586.1368 +    }
586.1369 +    private int readUByte(byte[] byteCodes, int offset) {
586.1370 +        return byteCodes[offset] & 0xff;
586.1371 +    }
586.1372 +
586.1373 +    private int readUShort(byte[] byteCodes, int offset) {
586.1374 +        return ((byteCodes[offset] & 0xff) << 8)
586.1375 +                    | (byteCodes[offset + 1] & 0xff);
586.1376 +    }
586.1377 +
586.1378 +    private int readShort(byte[] byteCodes, int offset) {
586.1379 +        return (byteCodes[offset] << 8)
586.1380 +                    | (byteCodes[offset + 1] & 0xff);
586.1381 +    }
586.1382 +
586.1383 +    private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
586.1384 +        int i = 0;
586.1385 +        Boolean count = null;
586.1386 +        boolean array = false;
586.1387 +        sig.append("__");
586.1388 +        int firstPos = sig.length();
586.1389 +        while (i < descriptor.length()) {
586.1390 +            char ch = descriptor.charAt(i++);
586.1391 +            switch (ch) {
586.1392 +                case '(':
586.1393 +                    count = true;
586.1394 +                    continue;
586.1395 +                case ')':
586.1396 +                    count = false;
586.1397 +                    continue;
586.1398 +                case 'B': 
586.1399 +                case 'C': 
586.1400 +                case 'D': 
586.1401 +                case 'F': 
586.1402 +                case 'I': 
586.1403 +                case 'J': 
586.1404 +                case 'S': 
586.1405 +                case 'Z': 
586.1406 +                    if (count) {
586.1407 +                        if (array) {
586.1408 +                            sig.append("_3");
586.1409 +                        }
586.1410 +                        sig.append(ch);
586.1411 +                        if (ch == 'J' || ch == 'D') {
586.1412 +                            cnt.append('1');
586.1413 +                        } else {
586.1414 +                            cnt.append('0');
586.1415 +                        }
586.1416 +                    } else {
586.1417 +                        sig.insert(firstPos, ch);
586.1418 +                        if (array) {
586.1419 +                            returnType[0] = '[';
586.1420 +                            sig.insert(firstPos, "_3");
586.1421 +                        } else {
586.1422 +                            returnType[0] = ch;
586.1423 +                        }
586.1424 +                    }
586.1425 +                    array = false;
586.1426 +                    continue;
586.1427 +                case 'V': 
586.1428 +                    assert !count;
586.1429 +                    returnType[0] = 'V';
586.1430 +                    sig.insert(firstPos, 'V');
586.1431 +                    continue;
586.1432 +                case 'L':
586.1433 +                    int next = descriptor.indexOf(';', i);
586.1434 +                    String realSig = mangleSig(descriptor, i - 1, next + 1);
586.1435 +                    if (count) {
586.1436 +                        if (array) {
586.1437 +                            sig.append("_3");
586.1438 +                        }
586.1439 +                        sig.append(realSig);
586.1440 +                        cnt.append('0');
586.1441 +                    } else {
586.1442 +                        sig.insert(firstPos, realSig);
586.1443 +                        if (array) {
586.1444 +                            sig.insert(firstPos, "_3");
586.1445 +                        }
586.1446 +                        returnType[0] = 'L';
586.1447 +                    }
586.1448 +                    i = next + 1;
586.1449 +                    array = false;
586.1450 +                    continue;
586.1451 +                case '[':
586.1452 +                    array = true;
586.1453 +                    continue;
586.1454 +                default:
586.1455 +                    throw new IllegalStateException("Invalid char: " + ch);
586.1456 +            }
586.1457 +        }
586.1458 +    }
586.1459 +    
586.1460 +    static String mangleSig(String sig) {
586.1461 +        return mangleSig(sig, 0, sig.length());
586.1462 +    }
586.1463 +    
586.1464 +    private static String mangleSig(String txt, int first, int last) {
586.1465 +        StringBuilder sb = new StringBuilder();
586.1466 +        for (int i = first; i < last; i++) {
586.1467 +            final char ch = txt.charAt(i);
586.1468 +            switch (ch) {
586.1469 +                case '/': sb.append('_'); break;
586.1470 +                case '_': sb.append("_1"); break;
586.1471 +                case ';': sb.append("_2"); break;
586.1472 +                case '[': sb.append("_3"); break;
586.1473 +                default: sb.append(ch); break;
586.1474 +            }
586.1475 +        }
586.1476 +        return sb.toString();
586.1477 +    }
586.1478 +
586.1479 +    private static String findMethodName(MethodData m, StringBuilder cnt) {
586.1480 +        StringBuilder name = new StringBuilder();
586.1481 +        if ("<init>".equals(m.getName())) { // NOI18N
586.1482 +            name.append("cons"); // NOI18N
586.1483 +        } else if ("<clinit>".equals(m.getName())) { // NOI18N
586.1484 +            name.append("class"); // NOI18N
586.1485 +        } else {
586.1486 +            name.append(m.getName());
586.1487 +        } 
586.1488 +        
586.1489 +        countArgs(m.getInternalSig(), new char[1], name, cnt);
586.1490 +        return name.toString();
586.1491 +    }
586.1492 +
586.1493 +    static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
586.1494 +        StringBuilder name = new StringBuilder();
586.1495 +        String descr = mi[2];//mi.getDescriptor();
586.1496 +        String nm= mi[1];
586.1497 +        if ("<init>".equals(nm)) { // NOI18N
586.1498 +            name.append("cons"); // NOI18N
586.1499 +        } else {
586.1500 +            name.append(nm);
586.1501 +        }
586.1502 +        countArgs(descr, returnType, name, cnt);
586.1503 +        return name.toString();
586.1504 +    }
586.1505 +
586.1506 +    private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
586.1507 +    throws IOException {
586.1508 +        int methodIndex = readIntArg(byteCodes, i);
586.1509 +        String[] mi = jc.getFieldInfoName(methodIndex);
586.1510 +        char[] returnType = { 'V' };
586.1511 +        StringBuilder cnt = new StringBuilder();
586.1512 +        String mn = findMethodName(mi, cnt, returnType);
586.1513 +
586.1514 +        final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
586.1515 +        final Variable[] vars = new Variable[numArguments];
586.1516 +
586.1517 +        for (int j = numArguments - 1; j >= 0; --j) {
586.1518 +            vars[j] = mapper.pop();
586.1519 +        }
586.1520 +
586.1521 +        if (returnType[0] != 'V') {
586.1522 +            out.append("var ")
586.1523 +               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
586.1524 +               .append(" = ");
586.1525 +        }
586.1526 +
586.1527 +        final String in = mi[0];
586.1528 +        out.append(accessClass(in.replace('/', '_')));
586.1529 +        out.append("(false).");
586.1530 +        if (mn.startsWith("cons_")) {
586.1531 +            out.append("constructor.");
586.1532 +        }
586.1533 +        out.append(mn);
586.1534 +        if (isStatic) {
586.1535 +            out.append('(');
586.1536 +        } else {
586.1537 +            out.append(".call(");
586.1538 +        }
586.1539 +        if (numArguments > 0) {
586.1540 +            out.append(vars[0]);
586.1541 +            for (int j = 1; j < numArguments; ++j) {
586.1542 +                out.append(", ");
586.1543 +                out.append(vars[j]);
586.1544 +            }
586.1545 +        }
586.1546 +        out.append(");");
586.1547 +        i += 2;
586.1548 +        addReference(in);
586.1549 +        return i;
586.1550 +    }
586.1551 +    private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
586.1552 +    throws IOException {
586.1553 +        int methodIndex = readIntArg(byteCodes, i);
586.1554 +        String[] mi = jc.getFieldInfoName(methodIndex);
586.1555 +        char[] returnType = { 'V' };
586.1556 +        StringBuilder cnt = new StringBuilder();
586.1557 +        String mn = findMethodName(mi, cnt, returnType);
586.1558 +
586.1559 +        final int numArguments = cnt.length() + 1;
586.1560 +        final Variable[] vars = new Variable[numArguments];
586.1561 +
586.1562 +        for (int j = numArguments - 1; j >= 0; --j) {
586.1563 +            vars[j] = mapper.pop();
586.1564 +        }
586.1565 +
586.1566 +        if (returnType[0] != 'V') {
586.1567 +            out.append("var ")
586.1568 +               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
586.1569 +               .append(" = ");
586.1570 +        }
586.1571 +
586.1572 +        out.append(vars[0]).append('.');
586.1573 +        out.append(mn);
586.1574 +        out.append('(');
586.1575 +        String sep = "";
586.1576 +        for (int j = 1; j < numArguments; ++j) {
586.1577 +            out.append(sep);
586.1578 +            out.append(vars[j]);
586.1579 +            sep = ", ";
586.1580 +        }
586.1581 +        out.append(");");
586.1582 +        i += 2;
586.1583 +        return i;
586.1584 +    }
586.1585 +
586.1586 +    private void addReference(String cn) throws IOException {
586.1587 +        if (requireReference(cn)) {
586.1588 +            debug(" /* needs " + cn + " */");
586.1589 +        }
586.1590 +    }
586.1591 +
586.1592 +    private void outType(String d, StringBuilder out) {
586.1593 +        int arr = 0;
586.1594 +        while (d.charAt(0) == '[') {
586.1595 +            out.append('A');
586.1596 +            d = d.substring(1);
586.1597 +        }
586.1598 +        if (d.charAt(0) == 'L') {
586.1599 +            assert d.charAt(d.length() - 1) == ';';
586.1600 +            out.append(d.replace('/', '_').substring(0, d.length() - 1));
586.1601 +        } else {
586.1602 +            out.append(d);
586.1603 +        }
586.1604 +    }
586.1605 +
586.1606 +    private String encodeConstant(int entryIndex) throws IOException {
586.1607 +        String[] classRef = { null };
586.1608 +        String s = jc.stringValue(entryIndex, classRef);
586.1609 +        if (classRef[0] != null) {
586.1610 +            if (classRef[0].startsWith("[")) {
586.1611 +                s = accessClass("java_lang_Class") + "(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('" + classRef[0] + "');";
586.1612 +            } else {
586.1613 +                addReference(classRef[0]);
586.1614 +                s = accessClass(s.replace('/', '_')) + "(false).constructor.$class";
586.1615 +            }
586.1616 +        }
586.1617 +        return s;
586.1618 +    }
586.1619 +
586.1620 +    private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
586.1621 +        byte[] arr = m.findAnnotationData(true);
586.1622 +        if (arr == null) {
586.1623 +            return null;
586.1624 +        }
586.1625 +        final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
586.1626 +        class P extends AnnotationParser {
586.1627 +            public P() {
586.1628 +                super(false, true);
586.1629 +            }
586.1630 +            
586.1631 +            int cnt;
586.1632 +            String[] args = new String[30];
586.1633 +            String body;
586.1634 +            
586.1635 +            @Override
586.1636 +            protected void visitAttr(String type, String attr, String at, String value) {
586.1637 +                if (type.equals(jvmType)) {
586.1638 +                    if ("body".equals(attr)) {
586.1639 +                        body = value;
586.1640 +                    } else if ("args".equals(attr)) {
586.1641 +                        args[cnt++] = value;
586.1642 +                    } else {
586.1643 +                        throw new IllegalArgumentException(attr);
586.1644 +                    }
586.1645 +                }
586.1646 +            }
586.1647 +        }
586.1648 +        P p = new P();
586.1649 +        p.parse(arr, jc);
586.1650 +        if (p.body == null) {
586.1651 +            return null;
586.1652 +        }
586.1653 +        StringBuilder cnt = new StringBuilder();
586.1654 +        final String mn = findMethodName(m, cnt);
586.1655 +        out.append(prefix).append(mn);
586.1656 +        out.append(" = function(");
586.1657 +        String space = "";
586.1658 +        int index = 0;
586.1659 +        for (int i = 0; i < cnt.length(); i++) {
586.1660 +            out.append(space);
586.1661 +            space = outputArg(out, p.args, index);
586.1662 +            index++;
586.1663 +        }
586.1664 +        out.append(") {").append("\n");
586.1665 +        out.append(p.body);
586.1666 +        out.append("\n}\n");
586.1667 +        return mn;
586.1668 +    }
586.1669 +    private static String className(ClassData jc) {
586.1670 +        //return jc.getName().getInternalName().replace('/', '_');
586.1671 +        return jc.getClassName().replace('/', '_');
586.1672 +    }
586.1673 +    
586.1674 +    private static String[] findAnnotation(
586.1675 +        byte[] arr, ClassData cd, final String className, 
586.1676 +        final String... attrNames
586.1677 +    ) throws IOException {
586.1678 +        if (arr == null) {
586.1679 +            return null;
586.1680 +        }
586.1681 +        final String[] values = new String[attrNames.length];
586.1682 +        final boolean[] found = { false };
586.1683 +        final String jvmType = "L" + className.replace('.', '/') + ";";
586.1684 +        AnnotationParser ap = new AnnotationParser(false, true) {
586.1685 +            @Override
586.1686 +            protected void visitAttr(String type, String attr, String at, String value) {
586.1687 +                if (type.equals(jvmType)) {
586.1688 +                    found[0] = true;
586.1689 +                    for (int i = 0; i < attrNames.length; i++) {
586.1690 +                        if (attrNames[i].equals(attr)) {
586.1691 +                            values[i] = value;
586.1692 +                        }
586.1693 +                    }
586.1694 +                }
586.1695 +            }
586.1696 +            
586.1697 +        };
586.1698 +        ap.parse(arr, cd);
586.1699 +        return found[0] ? values : null;
586.1700 +    }
586.1701 +
586.1702 +    private CharSequence initField(FieldData v) {
586.1703 +        final String is = v.getInternalSig();
586.1704 +        if (is.length() == 1) {
586.1705 +            switch (is.charAt(0)) {
586.1706 +                case 'S':
586.1707 +                case 'J':
586.1708 +                case 'B':
586.1709 +                case 'Z':
586.1710 +                case 'C':
586.1711 +                case 'I': return " = 0;";
586.1712 +                case 'F': 
586.1713 +                case 'D': return " = 0.0;";
586.1714 +                default:
586.1715 +                    throw new IllegalStateException(is);
586.1716 +            }
586.1717 +        }
586.1718 +        return " = null;";
586.1719 +    }
586.1720 +
586.1721 +    private void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
586.1722 +        AnnotationParser ap = new AnnotationParser(true, false) {
586.1723 +            int[] cnt = new int[32];
586.1724 +            int depth;
586.1725 +            
586.1726 +            @Override
586.1727 +            protected void visitAnnotationStart(String attrType, boolean top) throws IOException {
586.1728 +                final String slashType = attrType.substring(1, attrType.length() - 1);
586.1729 +                requireReference(slashType);
586.1730 +                
586.1731 +                if (cnt[depth]++ > 0) {
586.1732 +                    out.append(",");
586.1733 +                }
586.1734 +                if (top) {
586.1735 +                    out.append('"').append(attrType).append("\" : ");
586.1736 +                }
586.1737 +                out.append("{\n");
586.1738 +                cnt[++depth] = 0;
586.1739 +            }
586.1740 +
586.1741 +            @Override
586.1742 +            protected void visitAnnotationEnd(String type, boolean top) throws IOException {
586.1743 +                out.append("\n}\n");
586.1744 +                depth--;
586.1745 +            }
586.1746 +
586.1747 +            @Override
586.1748 +            protected void visitValueStart(String attrName, char type) throws IOException {
586.1749 +                if (cnt[depth]++ > 0) {
586.1750 +                    out.append(",\n");
586.1751 +                }
586.1752 +                cnt[++depth] = 0;
586.1753 +                if (attrName != null) {
586.1754 +                    out.append(attrName).append(" : ");
586.1755 +                }
586.1756 +                if (type == '[') {
586.1757 +                    out.append("[");
586.1758 +                }
586.1759 +            }
586.1760 +
586.1761 +            @Override
586.1762 +            protected void visitValueEnd(String attrName, char type) throws IOException {
586.1763 +                if (type == '[') {
586.1764 +                    out.append("]");
586.1765 +                }
586.1766 +                depth--;
586.1767 +            }
586.1768 +            
586.1769 +            @Override
586.1770 +            protected void visitAttr(String type, String attr, String attrType, String value) 
586.1771 +            throws IOException {
586.1772 +                if (attr == null && value == null) {
586.1773 +                    return;
586.1774 +                }
586.1775 +                out.append(value);
586.1776 +            }
586.1777 +
586.1778 +            @Override
586.1779 +            protected void visitEnumAttr(String type, String attr, String attrType, String value) 
586.1780 +            throws IOException {
586.1781 +                final String slashType = attrType.substring(1, attrType.length() - 1);
586.1782 +                requireReference(slashType);
586.1783 +                
586.1784 +                out.append(accessClass(slashType.replace('/', '_')))
586.1785 +                   .append("(false).constructor.").append(value);
586.1786 +            }
586.1787 +        };
586.1788 +        ap.parse(data, cd);
586.1789 +    }
586.1790 +
586.1791 +    private static String outputArg(Appendable out, String[] args, int indx) throws IOException {
586.1792 +        final String name = args[indx];
586.1793 +        if (name == null) {
586.1794 +            return "";
586.1795 +        }
586.1796 +        if (name.contains(",")) {
586.1797 +            throw new IOException("Wrong parameter with ',': " + name);
586.1798 +        }
586.1799 +        out.append(name);
586.1800 +        return ",";
586.1801 +    }
586.1802 +
586.1803 +    private static void emit(final Appendable out,
586.1804 +                             final String format,
586.1805 +                             final CharSequence... params) throws IOException {
586.1806 +        final int length = format.length();
586.1807 +
586.1808 +        int processed = 0;
586.1809 +        int paramOffset = format.indexOf('@');
586.1810 +        while ((paramOffset != -1) && (paramOffset < (length - 1))) {
586.1811 +            final char paramChar = format.charAt(paramOffset + 1);
586.1812 +            if ((paramChar >= '1') && (paramChar <= '9')) {
586.1813 +                final int paramIndex = paramChar - '0' - 1;
586.1814 +
586.1815 +                out.append(format, processed, paramOffset);
586.1816 +                out.append(params[paramIndex]);
586.1817 +
586.1818 +                ++paramOffset;
586.1819 +                processed = paramOffset + 1;
586.1820 +            }
586.1821 +
586.1822 +            paramOffset = format.indexOf('@', paramOffset + 1);
586.1823 +        }
586.1824 +
586.1825 +        out.append(format, processed, length);
586.1826 +    }
586.1827 +
586.1828 +    private void generateCatch(TrapData[] traps) throws IOException {
586.1829 +        out.append("} catch (e) {\n");
586.1830 +        int finallyPC = -1;
586.1831 +        for (TrapData e : traps) {
586.1832 +            if (e == null) {
586.1833 +                break;
586.1834 +            }
586.1835 +            if (e.catch_cpx != 0) { //not finally
586.1836 +                final String classInternalName = jc.getClassName(e.catch_cpx);
586.1837 +                addReference(classInternalName);
586.1838 +                if ("java/lang/Throwable".equals(classInternalName)) {
586.1839 +                    out.append("if (e.$instOf_java_lang_Throwable) {");
586.1840 +                    out.append("  var stA0 = e;");
586.1841 +                    out.append("} else {");
586.1842 +                    out.append("  var stA0 = vm.java_lang_Throwable(true);");
586.1843 +                    out.append("  vm.java_lang_Throwable.cons__VLjava_lang_String_2.call(stA0, e.toString());");
586.1844 +                    out.append("}");
586.1845 +                    out.append("gt=" + e.handler_pc + "; continue;");
586.1846 +                } else {
586.1847 +                    out.append("if (e.$instOf_" + classInternalName.replace('/', '_') + ") {");
586.1848 +                    out.append("gt=" + e.handler_pc + "; var stA0 = e; continue;");
586.1849 +                    out.append("}\n");
586.1850 +                }
586.1851 +            } else {
586.1852 +                finallyPC = e.handler_pc;
586.1853 +            }
586.1854 +        }
586.1855 +        if (finallyPC == -1) {
586.1856 +            out.append("throw e;");
586.1857 +        } else {
586.1858 +            out.append("gt=" + finallyPC + "; var stA0 = e; continue;");
586.1859 +        }
586.1860 +        out.append("\n}");
586.1861 +    }
586.1862 +}
   587.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   587.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java	Wed Feb 27 11:24:58 2013 +0100
   587.3 @@ -0,0 +1,142 @@
   587.4 +/**
   587.5 + * Back 2 Browser Bytecode Translator
   587.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   587.7 + *
   587.8 + * This program is free software: you can redistribute it and/or modify
   587.9 + * it under the terms of the GNU General Public License as published by
  587.10 + * the Free Software Foundation, version 2 of the License.
  587.11 + *
  587.12 + * This program is distributed in the hope that it will be useful,
  587.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  587.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  587.15 + * GNU General Public License for more details.
  587.16 + *
  587.17 + * You should have received a copy of the GNU General Public License
  587.18 + * along with this program. Look for COPYING file in the top folder.
  587.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  587.20 + */
  587.21 +package org.apidesign.vm4brwsr;
  587.22 +
  587.23 +import java.io.IOException;
  587.24 +import org.apidesign.javap.RuntimeConstants;
  587.25 +import org.apidesign.javap.TypeArray;
  587.26 +
  587.27 +final class LocalsMapper {
  587.28 +    private final TypeArray argTypeRecords;
  587.29 +    private final TypeArray localTypeRecords;
  587.30 +
  587.31 +    public LocalsMapper(final TypeArray stackMapArgs) {
  587.32 +        final TypeArray initTypeRecords = new TypeArray();
  587.33 +        updateRecords(initTypeRecords, stackMapArgs);
  587.34 +
  587.35 +        argTypeRecords = initTypeRecords;
  587.36 +        localTypeRecords = new TypeArray(initTypeRecords);
  587.37 +    }
  587.38 +
  587.39 +    public void outputArguments(final Appendable out, boolean isStatic) throws IOException {
  587.40 +        final int argRecordCount = argTypeRecords.getSize();
  587.41 +        int first = isStatic ? 0 : 1;
  587.42 +        if (argRecordCount > first) {
  587.43 +            Variable variable = getVariable(argTypeRecords, first);
  587.44 +            out.append(variable);
  587.45 +
  587.46 +            int i = first + (variable.isCategory2() ? 2 : 1);
  587.47 +            while (i < argRecordCount) {
  587.48 +                variable = getVariable(argTypeRecords, i);
  587.49 +                out.append(", ");
  587.50 +                out.append(variable);
  587.51 +                i += variable.isCategory2() ? 2 : 1;
  587.52 +            }
  587.53 +        }
  587.54 +    }
  587.55 +
  587.56 +    public void syncWithFrameLocals(final TypeArray frameLocals) {
  587.57 +        updateRecords(localTypeRecords, frameLocals);
  587.58 +    }
  587.59 +
  587.60 +    public Variable setI(final int index) {
  587.61 +        return setT(index, VarType.INTEGER);
  587.62 +    }
  587.63 +
  587.64 +    public Variable setL(final int index) {
  587.65 +        return setT(index, VarType.LONG);
  587.66 +    }
  587.67 +
  587.68 +    public Variable setF(final int index) {
  587.69 +        return setT(index, VarType.FLOAT);
  587.70 +    }
  587.71 +
  587.72 +    public Variable setD(final int index) {
  587.73 +        return setT(index, VarType.DOUBLE);
  587.74 +    }
  587.75 +
  587.76 +    public Variable setA(final int index) {
  587.77 +        return setT(index, VarType.REFERENCE);
  587.78 +    }
  587.79 +
  587.80 +    public Variable setT(final int index, final int type) {
  587.81 +        updateRecord(localTypeRecords, index, type);
  587.82 +        return Variable.getLocalVariable(type, index);
  587.83 +    }
  587.84 +
  587.85 +    public Variable getI(final int index) {
  587.86 +        return getT(index, VarType.INTEGER);
  587.87 +    }
  587.88 +
  587.89 +    public Variable getL(final int index) {
  587.90 +        return getT(index, VarType.LONG);
  587.91 +    }
  587.92 +
  587.93 +    public Variable getF(final int index) {
  587.94 +        return getT(index, VarType.FLOAT);
  587.95 +    }
  587.96 +
  587.97 +    public Variable getD(final int index) {
  587.98 +        return getT(index, VarType.DOUBLE);
  587.99 +    }
 587.100 +
 587.101 +    public Variable getA(final int index) {
 587.102 +        return getT(index, VarType.REFERENCE);
 587.103 +    }
 587.104 +
 587.105 +    public Variable getT(final int index, final int type) {
 587.106 +        final int oldRecordValue = localTypeRecords.get(index);
 587.107 +        if ((oldRecordValue & 0xff) != type) {
 587.108 +            throw new IllegalStateException("Type mismatch");
 587.109 +        }
 587.110 +
 587.111 +        return Variable.getLocalVariable(type, index);
 587.112 +    }
 587.113 +
 587.114 +    private static void updateRecords(final TypeArray typeRecords,
 587.115 +                                      final TypeArray stackMapTypes) {
 587.116 +        final int srcSize = stackMapTypes.getSize();
 587.117 +        for (int i = 0, dstIndex = 0; i < srcSize; ++i) {
 587.118 +            final int smType = stackMapTypes.get(i);
 587.119 +            if (smType == RuntimeConstants.ITEM_Bogus) {
 587.120 +                ++dstIndex;
 587.121 +                continue;
 587.122 +            }
 587.123 +            final int varType = VarType.fromStackMapType(smType);
 587.124 +            updateRecord(typeRecords, dstIndex, varType);
 587.125 +            dstIndex += VarType.isCategory2(varType) ? 2 : 1;
 587.126 +        }
 587.127 +    }
 587.128 +
 587.129 +    private static void updateRecord(final TypeArray typeRecords,
 587.130 +                                     final int index, final int type) {
 587.131 +        if (typeRecords.getSize() < (index + 1)) {
 587.132 +            typeRecords.setSize(index + 1);
 587.133 +        }
 587.134 +
 587.135 +        final int oldRecordValue = typeRecords.get(index);
 587.136 +        final int usedTypesMask =
 587.137 +                (oldRecordValue >> 8) | (1 << type);
 587.138 +        typeRecords.set(index, (usedTypesMask << 8) | type);
 587.139 +    }
 587.140 +
 587.141 +    private static Variable getVariable(final TypeArray typeRecords,
 587.142 +                                        final int index) {
 587.143 +        return Variable.getLocalVariable(typeRecords.get(index) & 0xff, index);
 587.144 +    }
 587.145 +}
   588.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   588.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Main.java	Wed Feb 27 11:24:58 2013 +0100
   588.3 @@ -0,0 +1,50 @@
   588.4 +/**
   588.5 + * Back 2 Browser Bytecode Translator
   588.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   588.7 + *
   588.8 + * This program is free software: you can redistribute it and/or modify
   588.9 + * it under the terms of the GNU General Public License as published by
  588.10 + * the Free Software Foundation, version 2 of the License.
  588.11 + *
  588.12 + * This program is distributed in the hope that it will be useful,
  588.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  588.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  588.15 + * GNU General Public License for more details.
  588.16 + *
  588.17 + * You should have received a copy of the GNU General Public License
  588.18 + * along with this program. Look for COPYING file in the top folder.
  588.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  588.20 + */
  588.21 +package org.apidesign.vm4brwsr;
  588.22 +
  588.23 +import java.io.BufferedWriter;
  588.24 +import java.io.FileWriter;
  588.25 +import java.io.IOException;
  588.26 +import java.io.Writer;
  588.27 +
  588.28 +/** Generator of JavaScript from bytecode of classes on classpath of the VM
  588.29 + * with a Main method.
  588.30 + *
  588.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  588.32 + */
  588.33 +final class Main {
  588.34 +    private Main() {}
  588.35 +    
  588.36 +    public static void main(String... args) throws IOException {
  588.37 +        if (args.length < 2) {
  588.38 +            System.err.println("Bck2Brwsr Translator from Java(tm) to JavaScript, (c) Jaroslav Tulach 2012");
  588.39 +            System.err.println("Usage: java -cp ... -jar ... <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
  588.40 +            return;
  588.41 +        }
  588.42 +        
  588.43 +        Writer w = new BufferedWriter(new FileWriter(args[0]));
  588.44 +        StringArray classes = StringArray.asList(args);
  588.45 +        classes.delete(0);
  588.46 +        try {
  588.47 +            Bck2Brwsr.generate(w, Main.class.getClassLoader(),
  588.48 +                               classes.toArray());
  588.49 +        } finally {
  588.50 +            w.close();
  588.51 +        }
  588.52 +    }
  588.53 +}
   589.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   589.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ParseMan.java	Wed Feb 27 11:24:58 2013 +0100
   589.3 @@ -0,0 +1,57 @@
   589.4 +/**
   589.5 + * Back 2 Browser Bytecode Translator
   589.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   589.7 + *
   589.8 + * This program is free software: you can redistribute it and/or modify
   589.9 + * it under the terms of the GNU General Public License as published by
  589.10 + * the Free Software Foundation, version 2 of the License.
  589.11 + *
  589.12 + * This program is distributed in the hope that it will be useful,
  589.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  589.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  589.15 + * GNU General Public License for more details.
  589.16 + *
  589.17 + * You should have received a copy of the GNU General Public License
  589.18 + * along with this program. Look for COPYING file in the top folder.
  589.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  589.20 + */
  589.21 +package org.apidesign.vm4brwsr;
  589.22 +
  589.23 +import java.io.IOException;
  589.24 +import java.io.InputStream;
  589.25 +import org.apidesign.bck2brwsr.emul.lang.ManifestInputStream;
  589.26 +
  589.27 +/**
  589.28 + *
  589.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  589.30 + */
  589.31 +final class ParseMan extends ManifestInputStream {
  589.32 +    private String cp;
  589.33 +    private String mc;
  589.34 +
  589.35 +    public ParseMan(InputStream is) throws IOException {
  589.36 +        super(is);
  589.37 +        readAttributes(new byte[512]);
  589.38 +    }
  589.39 +
  589.40 +    @Override
  589.41 +    protected String putValue(String key, String value) {
  589.42 +        if ("Class-Path".equals(key)) {
  589.43 +            cp = value;
  589.44 +        }
  589.45 +        if ("Main-Class".equals(key)) {
  589.46 +            mc = value;
  589.47 +        }
  589.48 +        return null;
  589.49 +    }
  589.50 +    
  589.51 +    String getMainClass() {
  589.52 +        return mc;
  589.53 +    }
  589.54 +
  589.55 +    @Override
  589.56 +    public String toString() {
  589.57 +        return cp;
  589.58 +    }
  589.59 +    
  589.60 +}
   590.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   590.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java	Wed Feb 27 11:24:58 2013 +0100
   590.3 @@ -0,0 +1,194 @@
   590.4 +/**
   590.5 + * Back 2 Browser Bytecode Translator
   590.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   590.7 + *
   590.8 + * This program is free software: you can redistribute it and/or modify
   590.9 + * it under the terms of the GNU General Public License as published by
  590.10 + * the Free Software Foundation, version 2 of the License.
  590.11 + *
  590.12 + * This program is distributed in the hope that it will be useful,
  590.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  590.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  590.15 + * GNU General Public License for more details.
  590.16 + *
  590.17 + * You should have received a copy of the GNU General Public License
  590.18 + * along with this program. Look for COPYING file in the top folder.
  590.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  590.20 + */
  590.21 +package org.apidesign.vm4brwsr;
  590.22 +
  590.23 +import org.apidesign.javap.TypeArray;
  590.24 +
  590.25 +final class StackMapper {
  590.26 +    private final TypeArray stackTypeIndexPairs;
  590.27 +    private int[] typeCounters;
  590.28 +    private int[] typeMaxCounters;
  590.29 +
  590.30 +    public StackMapper() {
  590.31 +        stackTypeIndexPairs = new TypeArray();
  590.32 +        typeCounters = new int[VarType.LAST + 1];
  590.33 +        typeMaxCounters = new int[VarType.LAST + 1];
  590.34 +    }
  590.35 +
  590.36 +    public void clear() {
  590.37 +        for (int type = 0; type <= VarType.LAST; ++type) {
  590.38 +            typeCounters[type] = 0;
  590.39 +        }
  590.40 +        stackTypeIndexPairs.clear();
  590.41 +    }
  590.42 +
  590.43 +    public void syncWithFrameStack(final TypeArray frameStack) {
  590.44 +        clear();
  590.45 +
  590.46 +        final int size = frameStack.getSize();
  590.47 +        for (int i = 0; i < size; ++i) {
  590.48 +            pushTypeImpl(VarType.fromStackMapType(frameStack.get(i)));
  590.49 +        }
  590.50 +    }
  590.51 +
  590.52 +    public Variable pushI() {
  590.53 +        return pushT(VarType.INTEGER);
  590.54 +    }
  590.55 +
  590.56 +    public Variable pushL() {
  590.57 +        return pushT(VarType.LONG);
  590.58 +    }
  590.59 +
  590.60 +    public Variable pushF() {
  590.61 +        return pushT(VarType.FLOAT);
  590.62 +    }
  590.63 +
  590.64 +    public Variable pushD() {
  590.65 +        return pushT(VarType.DOUBLE);
  590.66 +    }
  590.67 +
  590.68 +    public Variable pushA() {
  590.69 +        return pushT(VarType.REFERENCE);
  590.70 +    }
  590.71 +
  590.72 +    public Variable pushT(final int type) {
  590.73 +        return getVariable(pushTypeImpl(type));
  590.74 +    }
  590.75 +
  590.76 +    public Variable popI() {
  590.77 +        return popT(VarType.INTEGER);
  590.78 +    }
  590.79 +
  590.80 +    public Variable popL() {
  590.81 +        return popT(VarType.LONG);
  590.82 +    }
  590.83 +
  590.84 +    public Variable popF() {
  590.85 +        return popT(VarType.FLOAT);
  590.86 +    }
  590.87 +
  590.88 +    public Variable popD() {
  590.89 +        return popT(VarType.DOUBLE);
  590.90 +    }
  590.91 +
  590.92 +    public Variable popA() {
  590.93 +        return popT(VarType.REFERENCE);
  590.94 +    }
  590.95 +
  590.96 +    public Variable popT(final int type) {
  590.97 +        final Variable variable = getT(0, type);
  590.98 +        popImpl(1);
  590.99 +        return variable;
 590.100 +    }
 590.101 +
 590.102 +    public Variable pop() {
 590.103 +        final Variable variable = get(0);
 590.104 +        popImpl(1);
 590.105 +        return variable;
 590.106 +    }
 590.107 +
 590.108 +    public void pop(final int count) {
 590.109 +        final int stackSize = stackTypeIndexPairs.getSize();
 590.110 +        if (count > stackSize) {
 590.111 +            throw new IllegalStateException("Stack underflow");
 590.112 +        }
 590.113 +        popImpl(count);
 590.114 +    }
 590.115 +
 590.116 +    public Variable getI(final int indexFromTop) {
 590.117 +        return getT(indexFromTop, VarType.INTEGER);
 590.118 +    }
 590.119 +
 590.120 +    public Variable getL(final int indexFromTop) {
 590.121 +        return getT(indexFromTop, VarType.LONG);
 590.122 +    }
 590.123 +
 590.124 +    public Variable getF(final int indexFromTop) {
 590.125 +        return getT(indexFromTop, VarType.FLOAT);
 590.126 +    }
 590.127 +
 590.128 +    public Variable getD(final int indexFromTop) {
 590.129 +        return getT(indexFromTop, VarType.DOUBLE);
 590.130 +    }
 590.131 +
 590.132 +    public Variable getA(final int indexFromTop) {
 590.133 +        return getT(indexFromTop, VarType.REFERENCE);
 590.134 +    }
 590.135 +
 590.136 +    public Variable getT(final int indexFromTop, final int type) {
 590.137 +        final int stackSize = stackTypeIndexPairs.getSize();
 590.138 +        if (indexFromTop >= stackSize) {
 590.139 +            throw new IllegalStateException("Stack underflow");
 590.140 +        }
 590.141 +        final int stackValue =
 590.142 +                stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
 590.143 +        if ((stackValue & 0xff) != type) {
 590.144 +            throw new IllegalStateException("Type mismatch");
 590.145 +        }
 590.146 +
 590.147 +        return getVariable(stackValue);
 590.148 +    }
 590.149 +
 590.150 +    public Variable get(final int indexFromTop) {
 590.151 +        final int stackSize = stackTypeIndexPairs.getSize();
 590.152 +        if (indexFromTop >= stackSize) {
 590.153 +            throw new IllegalStateException("Stack underflow");
 590.154 +        }
 590.155 +        final int stackValue =
 590.156 +                stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
 590.157 +
 590.158 +        return getVariable(stackValue);
 590.159 +    }
 590.160 +
 590.161 +    private int pushTypeImpl(final int type) {
 590.162 +        final int count = typeCounters[type];
 590.163 +        final int value = (count << 8) | (type & 0xff);
 590.164 +        incCounter(type);
 590.165 +        stackTypeIndexPairs.add(value);
 590.166 +
 590.167 +        return value;
 590.168 +    }
 590.169 +
 590.170 +    private void popImpl(final int count) {
 590.171 +        final int stackSize = stackTypeIndexPairs.getSize();
 590.172 +        for (int i = stackSize - count; i < stackSize; ++i) {
 590.173 +            final int value = stackTypeIndexPairs.get(i);
 590.174 +            decCounter(value & 0xff);
 590.175 +        }
 590.176 +
 590.177 +        stackTypeIndexPairs.setSize(stackSize - count);
 590.178 +    }
 590.179 +
 590.180 +    private void incCounter(final int type) {
 590.181 +        final int newValue = ++typeCounters[type];
 590.182 +        if (typeMaxCounters[type] < newValue) {
 590.183 +            typeMaxCounters[type] = newValue;
 590.184 +        }
 590.185 +    }
 590.186 +
 590.187 +    private void decCounter(final int type) {
 590.188 +        --typeCounters[type];
 590.189 +    }
 590.190 +
 590.191 +    public Variable getVariable(final int typeAndIndex) {
 590.192 +        final int type = typeAndIndex & 0xff;
 590.193 +        final int index = typeAndIndex >> 8;
 590.194 +
 590.195 +        return Variable.getStackVariable(type, index);
 590.196 +    }
 590.197 +}
   591.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   591.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java	Wed Feb 27 11:24:58 2013 +0100
   591.3 @@ -0,0 +1,97 @@
   591.4 +/**
   591.5 + * Back 2 Browser Bytecode Translator
   591.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   591.7 + *
   591.8 + * This program is free software: you can redistribute it and/or modify
   591.9 + * it under the terms of the GNU General Public License as published by
  591.10 + * the Free Software Foundation, version 2 of the License.
  591.11 + *
  591.12 + * This program is distributed in the hope that it will be useful,
  591.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  591.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  591.15 + * GNU General Public License for more details.
  591.16 + *
  591.17 + * You should have received a copy of the GNU General Public License
  591.18 + * along with this program. Look for COPYING file in the top folder.
  591.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  591.20 + */
  591.21 +package org.apidesign.vm4brwsr;
  591.22 +
  591.23 +/**
  591.24 + *
  591.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  591.26 + */
  591.27 +class StringArray {
  591.28 +    private String[] arr;
  591.29 +
  591.30 +    public StringArray() {
  591.31 +    }
  591.32 +
  591.33 +    private StringArray(String[] arr) {
  591.34 +        this.arr = arr;
  591.35 +    }
  591.36 +    
  591.37 +    public void add(String s) {
  591.38 +        if (arr == null) {
  591.39 +            arr = new String[1];
  591.40 +        } else {
  591.41 +            String[] tmp = new String[arr.length + 1];
  591.42 +            for (int i = 0; i < arr.length; i++) {
  591.43 +                tmp[i] = arr[i];
  591.44 +            }
  591.45 +            arr = tmp;
  591.46 +        }
  591.47 +        arr[arr.length - 1] = s;
  591.48 +    }
  591.49 +    
  591.50 +    public String[] toArray() {
  591.51 +        return arr == null ? new String[0] : arr;
  591.52 +    }
  591.53 +    
  591.54 +    static StringArray asList(String... names) {
  591.55 +        return new StringArray(names);
  591.56 +    }
  591.57 +
  591.58 +    void reverse() {
  591.59 +        for (int i = 0, j = arr.length; i < j; i++) {
  591.60 +            String s = arr[i];
  591.61 +            arr[i] = arr[--j];
  591.62 +            arr[j] = s;
  591.63 +        }
  591.64 +    }
  591.65 +
  591.66 +    boolean contains(String n) {
  591.67 +        if (arr == null) {
  591.68 +            return false;
  591.69 +        }
  591.70 +        for (int i = 0; i < arr.length; i++) {
  591.71 +            if (n.equals(arr[i])) {
  591.72 +                return true;
  591.73 +            }
  591.74 +        }
  591.75 +        return false;
  591.76 +    }
  591.77 +
  591.78 +    void delete(int indx) {
  591.79 +        if (arr == null || indx < 0 || indx >= arr.length) {
  591.80 +            return;
  591.81 +        }
  591.82 +        String[] tmp = new String[arr.length - 1];
  591.83 +        for (int i = 0, j = 0; i < arr.length; i++) {
  591.84 +            if (i != indx) {
  591.85 +                tmp[j++] = arr[i];
  591.86 +            }
  591.87 +        }
  591.88 +        arr = tmp;
  591.89 +    }
  591.90 +
  591.91 +    int indexOf(String ic) {
  591.92 +        for (int i = 0; i < arr.length; i++) {
  591.93 +            if (ic.equals(arr[i])) {
  591.94 +                return i;
  591.95 +            }
  591.96 +        }
  591.97 +        return -1;
  591.98 +    }
  591.99 +    
 591.100 +}
   592.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   592.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Wed Feb 27 11:24:58 2013 +0100
   592.3 @@ -0,0 +1,230 @@
   592.4 +/**
   592.5 + * Back 2 Browser Bytecode Translator
   592.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   592.7 + *
   592.8 + * This program is free software: you can redistribute it and/or modify
   592.9 + * it under the terms of the GNU General Public License as published by
  592.10 + * the Free Software Foundation, version 2 of the License.
  592.11 + *
  592.12 + * This program is distributed in the hope that it will be useful,
  592.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  592.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  592.15 + * GNU General Public License for more details.
  592.16 + *
  592.17 + * You should have received a copy of the GNU General Public License
  592.18 + * along with this program. Look for COPYING file in the top folder.
  592.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  592.20 + */
  592.21 +package org.apidesign.vm4brwsr;
  592.22 +
  592.23 +import java.io.IOException;
  592.24 +import java.io.InputStream;
  592.25 +
  592.26 +/** Generator of JavaScript from bytecode of classes on classpath of the VM.
  592.27 + *
  592.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  592.29 + */
  592.30 +class VM extends ByteCodeToJavaScript {
  592.31 +    public VM(Appendable out) {
  592.32 +        super(out);
  592.33 +    }
  592.34 +    
  592.35 +    static {
  592.36 +        // uses VMLazy to load dynamic classes
  592.37 +        boolean assertsOn = false;
  592.38 +        assert assertsOn = true;
  592.39 +        if (assertsOn) {
  592.40 +            VMLazy.init();
  592.41 +            Zips.init();
  592.42 +        }
  592.43 +    }
  592.44 +
  592.45 +    @Override
  592.46 +    boolean debug(String msg) throws IOException {
  592.47 +        return false;
  592.48 +    }
  592.49 +    
  592.50 +    static void compile(Bck2Brwsr.Resources l, Appendable out, StringArray names) throws IOException {
  592.51 +        new VM(out).doCompile(l, names);
  592.52 +    }
  592.53 +    protected void doCompile(Bck2Brwsr.Resources l, StringArray names) throws IOException {
  592.54 +        out.append("(function VM(global) {var fillInVMSkeleton = function(vm) {");
  592.55 +        StringArray processed = new StringArray();
  592.56 +        StringArray initCode = new StringArray();
  592.57 +        for (String baseClass : names.toArray()) {
  592.58 +            references.add(baseClass);
  592.59 +            for (;;) {
  592.60 +                String name = null;
  592.61 +                for (String n : references.toArray()) {
  592.62 +                    if (processed.contains(n)) {
  592.63 +                        continue;
  592.64 +                    }
  592.65 +                    name = n;
  592.66 +                }
  592.67 +                if (name == null) {
  592.68 +                    break;
  592.69 +                }
  592.70 +                InputStream is = loadClass(l, name);
  592.71 +                if (is == null) {
  592.72 +                    throw new IOException("Can't find class " + name); 
  592.73 +                }
  592.74 +                try {
  592.75 +                    String ic = compile(is);
  592.76 +                    processed.add(name);
  592.77 +                    initCode.add(ic == null ? "" : ic);
  592.78 +                } catch (RuntimeException ex) {
  592.79 +                    if (out instanceof CharSequence) {
  592.80 +                        CharSequence seq = (CharSequence)out;
  592.81 +                        int lastBlock = seq.length();
  592.82 +                        while (lastBlock-- > 0) {
  592.83 +                            if (seq.charAt(lastBlock) == '{') {
  592.84 +                                break;
  592.85 +                            }
  592.86 +                        }
  592.87 +                        throw new IOException("Error while compiling " + name + "\n" 
  592.88 +                            + seq.subSequence(lastBlock + 1, seq.length()), ex
  592.89 +                        );
  592.90 +                    } else {
  592.91 +                        throw new IOException("Error while compiling " + name + "\n" 
  592.92 +                            + out, ex
  592.93 +                        );
  592.94 +                    }
  592.95 +                }
  592.96 +            }
  592.97 +
  592.98 +            for (String resource : scripts.toArray()) {
  592.99 +                while (resource.startsWith("/")) {
 592.100 +                    resource = resource.substring(1);
 592.101 +                }
 592.102 +                InputStream emul = l.get(resource);
 592.103 +                if (emul == null) {
 592.104 +                    throw new IOException("Can't find " + resource);
 592.105 +                }
 592.106 +                readResource(emul, out);
 592.107 +            }
 592.108 +            scripts = new StringArray();
 592.109 +            
 592.110 +            StringArray toInit = StringArray.asList(references.toArray());
 592.111 +            toInit.reverse();
 592.112 +
 592.113 +            for (String ic : toInit.toArray()) {
 592.114 +                int indx = processed.indexOf(ic);
 592.115 +                if (indx >= 0) {
 592.116 +                    out.append(initCode.toArray()[indx]).append("\n");
 592.117 +                    initCode.toArray()[indx] = "";
 592.118 +                }
 592.119 +            }
 592.120 +        }
 592.121 +        out.append(
 592.122 +              "  return vm;\n"
 592.123 +            + "  };\n"
 592.124 +            + "  global.bck2brwsr = function() {\n"
 592.125 +            + "    var args = Array.prototype.slice.apply(arguments);\n"
 592.126 +            + "    var vm = fillInVMSkeleton({});\n"
 592.127 +            + "    var loader = {};\n"
 592.128 +            + "    loader.vm = vm;\n"
 592.129 +            + "    loader.loadClass = function(name) {\n"
 592.130 +            + "      var attr = name.replace__Ljava_lang_String_2CC('.','_');\n"
 592.131 +            + "      var fn = vm[attr];\n"
 592.132 +            + "      if (fn) return fn(false);\n"
 592.133 +            + "      return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 592.134 +            + "        load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
 592.135 +            + "    }\n"
 592.136 +            + "    if (vm.loadClass) {\n"
 592.137 +            + "      throw 'Cannot initialize the bck2brwsr VM twice!';\n"
 592.138 +            + "    }\n"
 592.139 +            + "    vm.loadClass = loader.loadClass;\n"
 592.140 +            + "    vm.loadBytes = function(name) {\n"
 592.141 +            + "      return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 592.142 +            + "        loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
 592.143 +            + "    }\n"
 592.144 +            + "    vm.java_lang_reflect_Array(false);\n"
 592.145 +            + "    vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 592.146 +            + "      loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, null, args);\n"
 592.147 +            + "    return loader;\n"
 592.148 +            + "  };\n");
 592.149 +        out.append("}(this));");
 592.150 +    }
 592.151 +    private static void readResource(InputStream emul, Appendable out) throws IOException {
 592.152 +        try {
 592.153 +            int state = 0;
 592.154 +            for (;;) {
 592.155 +                int ch = emul.read();
 592.156 +                if (ch == -1) {
 592.157 +                    break;
 592.158 +                }
 592.159 +                if (ch < 0 || ch > 255) {
 592.160 +                    throw new IOException("Invalid char in emulation " + ch);
 592.161 +                }
 592.162 +                switch (state) {
 592.163 +                    case 0: 
 592.164 +                        if (ch == '/') {
 592.165 +                            state = 1;
 592.166 +                        } else {
 592.167 +                            out.append((char)ch);
 592.168 +                        }
 592.169 +                        break;
 592.170 +                    case 1:
 592.171 +                        if (ch == '*') {
 592.172 +                            state = 2;
 592.173 +                        } else {
 592.174 +                            out.append('/').append((char)ch);
 592.175 +                            state = 0;
 592.176 +                        }
 592.177 +                        break;
 592.178 +                    case 2:
 592.179 +                        if (ch == '*') {
 592.180 +                            state = 3;
 592.181 +                        }
 592.182 +                        break;
 592.183 +                    case 3:
 592.184 +                        if (ch == '/') {
 592.185 +                            state = 0;
 592.186 +                        } else {
 592.187 +                            state = 2;
 592.188 +                        }
 592.189 +                        break;
 592.190 +                }
 592.191 +            }
 592.192 +        } finally {
 592.193 +            emul.close();
 592.194 +        }
 592.195 +    }
 592.196 +
 592.197 +    private static InputStream loadClass(Bck2Brwsr.Resources l, String name) throws IOException {
 592.198 +        return l.get(name + ".class"); // NOI18N
 592.199 +    }
 592.200 +
 592.201 +    static String toString(String name) throws IOException {
 592.202 +        StringBuilder sb = new StringBuilder();
 592.203 +//        compile(sb, name);
 592.204 +        return sb.toString().toString();
 592.205 +    }
 592.206 +
 592.207 +    private StringArray scripts = new StringArray();
 592.208 +    private StringArray references = new StringArray();
 592.209 +    
 592.210 +    @Override
 592.211 +    protected boolean requireReference(String cn) {
 592.212 +        if (references.contains(cn)) {
 592.213 +            return false;
 592.214 +        }
 592.215 +        references.add(cn);
 592.216 +        return true;
 592.217 +    }
 592.218 +
 592.219 +    @Override
 592.220 +    protected void requireScript(String resourcePath) {
 592.221 +        scripts.add(resourcePath);
 592.222 +    }
 592.223 +
 592.224 +    @Override
 592.225 +    String assignClass(String className) {
 592.226 +        return "vm." + className + " = ";
 592.227 +    }
 592.228 +    
 592.229 +    @Override
 592.230 +    String accessClass(String className) {
 592.231 +        return "vm." + className;
 592.232 +    }
 592.233 +}
   593.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   593.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java	Wed Feb 27 11:24:58 2013 +0100
   593.3 @@ -0,0 +1,155 @@
   593.4 +/**
   593.5 + * Back 2 Browser Bytecode Translator
   593.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   593.7 + *
   593.8 + * This program is free software: you can redistribute it and/or modify
   593.9 + * it under the terms of the GNU General Public License as published by
  593.10 + * the Free Software Foundation, version 2 of the License.
  593.11 + *
  593.12 + * This program is distributed in the hope that it will be useful,
  593.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  593.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  593.15 + * GNU General Public License for more details.
  593.16 + *
  593.17 + * You should have received a copy of the GNU General Public License
  593.18 + * along with this program. Look for COPYING file in the top folder.
  593.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  593.20 + */
  593.21 +package org.apidesign.vm4brwsr;
  593.22 +
  593.23 +import java.io.ByteArrayInputStream;
  593.24 +import java.io.IOException;
  593.25 +import java.io.InputStream;
  593.26 +import java.lang.reflect.Array;
  593.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  593.28 +
  593.29 +/**
  593.30 + *
  593.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  593.32 + */
  593.33 +final class VMLazy {
  593.34 +    private final Object loader;
  593.35 +    private final Object[] args;
  593.36 +    
  593.37 +    private VMLazy(Object loader, Object[] args) {
  593.38 +        this.loader = loader;
  593.39 +        this.args = args;
  593.40 +    }
  593.41 +    
  593.42 +    static void init() {
  593.43 +    }
  593.44 +    
  593.45 +    static Object load(Object loader, String name, Object[] arguments) 
  593.46 +    throws IOException, ClassNotFoundException {
  593.47 +        return new VMLazy(loader, arguments).load(name, false);
  593.48 +    }
  593.49 +    
  593.50 +    static byte[] loadBytes(Object loader, String name, Object[] arguments) throws Exception {
  593.51 +        return Zips.loadFromCp(arguments, name);
  593.52 +    }
  593.53 +    
  593.54 +    private Object load(String name, boolean instance)
  593.55 +    throws IOException, ClassNotFoundException {
  593.56 +        String res = name.replace('.', '/') + ".class";
  593.57 +        byte[] arr = Zips.loadFromCp(args, res);
  593.58 +        if (arr == null) {
  593.59 +            throw new ClassNotFoundException(name);
  593.60 +        }
  593.61 +//        beingDefined(loader, name);
  593.62 +        StringBuilder out = new StringBuilder();
  593.63 +        out.append("var loader = arguments[0];\n");
  593.64 +        out.append("var vm = loader.vm;\n");
  593.65 +        int prelude = out.length();
  593.66 +        String initCode = new Gen(this, out).compile(new ByteArrayInputStream(arr));
  593.67 +        String code = out.toString().toString();
  593.68 +//        dump("Loading " + name);
  593.69 +        dump(code);
  593.70 +        String under = name.replace('.', '_');
  593.71 +        Object fn = applyCode(loader, under, code, instance);
  593.72 +        
  593.73 +        if (!initCode.isEmpty()) {
  593.74 +            out.setLength(prelude);
  593.75 +            out.append(initCode);
  593.76 +            code = out.toString().toString();
  593.77 +            dump(code);
  593.78 +            applyCode(loader, null, code, false);
  593.79 +        }            
  593.80 +        
  593.81 +        return fn;
  593.82 +    }
  593.83 +
  593.84 +//    @JavaScriptBody(args = "s", body = "java.lang.System.out.println(s.toString());")
  593.85 +    static void dump(String s) {
  593.86 +    }
  593.87 +
  593.88 +/* possibly not needed:
  593.89 +    @JavaScriptBody(args = {"loader", "n" }, body =
  593.90 +        "var cls = n.replace__Ljava_lang_String_2CC(n, '.','_').toString();" +
  593.91 +        "loader.vm[cls] = true;\n"
  593.92 +    )
  593.93 +    private static native void beingDefined(Object loader, String name);
  593.94 +*/
  593.95 +    
  593.96 +
  593.97 +    @JavaScriptBody(args = {"loader", "name", "script", "instance" }, body =
  593.98 +        "try {\n" +
  593.99 +        "  new Function(script)(loader, name);\n" +
 593.100 +        "} catch (ex) {\n" +
 593.101 +        "  throw 'Cannot compile ' + name + ' ' + ex + ' line: ' + ex.lineNumber + ' script:\\n' + script;\n" +
 593.102 +        "}\n" +
 593.103 +        "return name != null ? vm[name](instance) : null;\n"
 593.104 +    )
 593.105 +    private static native Object applyCode(Object loader, String name, String script, boolean instance);
 593.106 +    
 593.107 +    
 593.108 +    private static final class Gen extends ByteCodeToJavaScript {
 593.109 +        private final VMLazy lazy;
 593.110 +
 593.111 +        public Gen(VMLazy vm, Appendable out) {
 593.112 +            super(out);
 593.113 +            this.lazy = vm;
 593.114 +        }
 593.115 +        
 593.116 +        @JavaScriptBody(args = {"n"},
 593.117 +        body =
 593.118 +        "var cls = n.replace__Ljava_lang_String_2CC('/','_').toString();"
 593.119 +        + "\nvar dot = n.replace__Ljava_lang_String_2CC('/','.').toString();"
 593.120 +        + "\nvar lazy = this._lazy();"
 593.121 +        + "\nvar loader = lazy._loader();"
 593.122 +        + "\nvar vm = loader.vm;"
 593.123 +        + "\nif (vm[cls]) return false;"
 593.124 +        + "\nvm[cls] = function() {"
 593.125 +        + "\n  var instance = arguments.length == 0 || arguments[0] === true;"
 593.126 +        + "\n  return lazy.load__Ljava_lang_Object_2Ljava_lang_String_2Z(dot, instance);"
 593.127 +        + "\n};"
 593.128 +        + "\nreturn true;")
 593.129 +        @Override
 593.130 +        protected boolean requireReference(String internalClassName) {
 593.131 +            throw new UnsupportedOperationException();
 593.132 +        }
 593.133 +
 593.134 +        @Override
 593.135 +        protected void requireScript(String resourcePath) throws IOException {
 593.136 +            InputStream is = getClass().getResourceAsStream(resourcePath);
 593.137 +            StringBuilder sb = new StringBuilder();
 593.138 +            for (;;) {
 593.139 +                int ch = is.read();
 593.140 +                if (ch == -1) {
 593.141 +                    break;
 593.142 +                }
 593.143 +                sb.append((char)ch);
 593.144 +            }
 593.145 +            applyCode(lazy.loader, null, sb.toString(), false);
 593.146 +        }
 593.147 +
 593.148 +        @Override
 593.149 +        String assignClass(String className) {
 593.150 +            return "vm[arguments[1]]=";
 593.151 +        }
 593.152 +
 593.153 +        @Override
 593.154 +        String accessClass(String classOperation) {
 593.155 +            return "vm." + classOperation;
 593.156 +        }
 593.157 +    }
 593.158 +}
   594.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   594.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java	Wed Feb 27 11:24:58 2013 +0100
   594.3 @@ -0,0 +1,110 @@
   594.4 +/**
   594.5 + * Back 2 Browser Bytecode Translator
   594.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   594.7 + *
   594.8 + * This program is free software: you can redistribute it and/or modify
   594.9 + * it under the terms of the GNU General Public License as published by
  594.10 + * the Free Software Foundation, version 2 of the License.
  594.11 + *
  594.12 + * This program is distributed in the hope that it will be useful,
  594.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  594.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  594.15 + * GNU General Public License for more details.
  594.16 + *
  594.17 + * You should have received a copy of the GNU General Public License
  594.18 + * along with this program. Look for COPYING file in the top folder.
  594.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  594.20 + */
  594.21 +package org.apidesign.vm4brwsr;
  594.22 +
  594.23 +import org.apidesign.javap.RuntimeConstants;
  594.24 +
  594.25 +final class VarType {
  594.26 +    public static final int INTEGER = 0;
  594.27 +    public static final int LONG = 1;
  594.28 +    public static final int FLOAT = 2;
  594.29 +    public static final int DOUBLE = 3;
  594.30 +    public static final int REFERENCE = 4;
  594.31 +
  594.32 +    public static final int LAST = REFERENCE;
  594.33 +
  594.34 +    private VarType() {
  594.35 +    }
  594.36 +
  594.37 +    public static boolean isCategory2(final int varType) {
  594.38 +        return (varType == LONG) || (varType == DOUBLE);
  594.39 +    }
  594.40 +
  594.41 +    public static int fromStackMapType(final int smType) {
  594.42 +        switch (smType & 0xff) {
  594.43 +            case RuntimeConstants.ITEM_Integer:
  594.44 +                return VarType.INTEGER;
  594.45 +            case RuntimeConstants.ITEM_Float:
  594.46 +                return VarType.FLOAT;
  594.47 +            case RuntimeConstants.ITEM_Double:
  594.48 +                return VarType.DOUBLE;
  594.49 +            case RuntimeConstants.ITEM_Long:
  594.50 +                return VarType.LONG;
  594.51 +            case RuntimeConstants.ITEM_Null:
  594.52 +            case RuntimeConstants.ITEM_InitObject:
  594.53 +            case RuntimeConstants.ITEM_Object:
  594.54 +            case RuntimeConstants.ITEM_NewObject:
  594.55 +                return VarType.REFERENCE;
  594.56 +
  594.57 +            case RuntimeConstants.ITEM_Bogus:
  594.58 +                /* unclear how to handle for now */
  594.59 +            default:
  594.60 +                throw new IllegalStateException("Unhandled stack map type");
  594.61 +        }
  594.62 +    }
  594.63 +
  594.64 +    public static int fromConstantType(final byte constantTag) {
  594.65 +        switch (constantTag) {
  594.66 +            case RuntimeConstants.CONSTANT_INTEGER:
  594.67 +                return VarType.INTEGER;
  594.68 +            case RuntimeConstants.CONSTANT_FLOAT:
  594.69 +                return VarType.FLOAT;
  594.70 +            case RuntimeConstants.CONSTANT_LONG:
  594.71 +                return VarType.LONG;
  594.72 +            case RuntimeConstants.CONSTANT_DOUBLE:
  594.73 +                return VarType.DOUBLE;
  594.74 +
  594.75 +            case RuntimeConstants.CONSTANT_CLASS:
  594.76 +            case RuntimeConstants.CONSTANT_UTF8:
  594.77 +            case RuntimeConstants.CONSTANT_UNICODE:
  594.78 +            case RuntimeConstants.CONSTANT_STRING:
  594.79 +                return VarType.REFERENCE;
  594.80 +
  594.81 +            case RuntimeConstants.CONSTANT_FIELD:
  594.82 +            case RuntimeConstants.CONSTANT_METHOD:
  594.83 +            case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
  594.84 +            case RuntimeConstants.CONSTANT_NAMEANDTYPE:
  594.85 +                /* unclear how to handle for now */
  594.86 +            default:
  594.87 +                throw new IllegalStateException("Unhandled constant tag");
  594.88 +        }
  594.89 +    }
  594.90 +
  594.91 +    public static int fromFieldType(final char fieldType) {
  594.92 +        switch (fieldType) {
  594.93 +            case 'B':
  594.94 +            case 'C':
  594.95 +            case 'S':
  594.96 +            case 'Z':
  594.97 +            case 'I':
  594.98 +                return VarType.INTEGER;
  594.99 +            case 'J':
 594.100 +                return VarType.LONG;
 594.101 +            case 'F':
 594.102 +                return VarType.FLOAT;
 594.103 +            case 'D':
 594.104 +                return VarType.DOUBLE;
 594.105 +            case 'L':
 594.106 +            case '[':
 594.107 +                return VarType.REFERENCE;
 594.108 +
 594.109 +            default:
 594.110 +                throw new IllegalStateException("Unhandled field type");
 594.111 +        }
 594.112 +    }
 594.113 +}
   595.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   595.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java	Wed Feb 27 11:24:58 2013 +0100
   595.3 @@ -0,0 +1,100 @@
   595.4 +/**
   595.5 + * Back 2 Browser Bytecode Translator
   595.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   595.7 + *
   595.8 + * This program is free software: you can redistribute it and/or modify
   595.9 + * it under the terms of the GNU General Public License as published by
  595.10 + * the Free Software Foundation, version 2 of the License.
  595.11 + *
  595.12 + * This program is distributed in the hope that it will be useful,
  595.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  595.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  595.15 + * GNU General Public License for more details.
  595.16 + *
  595.17 + * You should have received a copy of the GNU General Public License
  595.18 + * along with this program. Look for COPYING file in the top folder.
  595.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  595.20 + */
  595.21 +package org.apidesign.vm4brwsr;
  595.22 +
  595.23 +final class Variable implements CharSequence {
  595.24 +    private static final String STACK_VAR_PREFIX = "st";
  595.25 +    private static final String LOCAL_VAR_PREFIX = "lc";
  595.26 +
  595.27 +    private final String name;
  595.28 +    private final int type;
  595.29 +    private final int index;
  595.30 +
  595.31 +    private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
  595.32 +
  595.33 +    private Variable(final String prefix, final int type, final int index) {
  595.34 +        this.name = prefix + TYPE_IDS[type] + index;
  595.35 +        this.type = type;
  595.36 +        this.index = index;
  595.37 +    }
  595.38 +
  595.39 +    public static Variable getStackVariable(
  595.40 +            final int type, final int index) {
  595.41 +        // TODO: precreate frequently used variables
  595.42 +        return new Variable(STACK_VAR_PREFIX, type, index);
  595.43 +    }
  595.44 +
  595.45 +    public static Variable getLocalVariable(
  595.46 +            final int type, final int index) {
  595.47 +        // TODO: precreate frequently used variables
  595.48 +        return new Variable(LOCAL_VAR_PREFIX, type, index);
  595.49 +    }
  595.50 +
  595.51 +    public String getName() {
  595.52 +        return name;
  595.53 +    }
  595.54 +
  595.55 +    public int getType() {
  595.56 +        return type;
  595.57 +    }
  595.58 +
  595.59 +    public int getIndex() {
  595.60 +        return index;
  595.61 +    }
  595.62 +
  595.63 +    public boolean isCategory2() {
  595.64 +        return VarType.isCategory2(type);
  595.65 +    }
  595.66 +
  595.67 +    @Override
  595.68 +    public int length() {
  595.69 +        return name.length();
  595.70 +    }
  595.71 +
  595.72 +    @Override
  595.73 +    public char charAt(final int index) {
  595.74 +        return name.charAt(index);
  595.75 +    }
  595.76 +
  595.77 +    @Override
  595.78 +    public CharSequence subSequence(final int start, final int end) {
  595.79 +        return name.subSequence(start, end);
  595.80 +    }
  595.81 +
  595.82 +    @Override
  595.83 +    public int hashCode() {
  595.84 +        return name.hashCode();
  595.85 +    }
  595.86 +
  595.87 +    @Override
  595.88 +    public boolean equals(final Object other) {
  595.89 +        if (this == other) {
  595.90 +            return true;
  595.91 +        }
  595.92 +        if (!(other instanceof Variable)) {
  595.93 +            return false;
  595.94 +        }
  595.95 +
  595.96 +        return name.equals(((Variable) other).name);
  595.97 +    }
  595.98 +
  595.99 +    @Override
 595.100 +    public String toString() {
 595.101 +        return name;
 595.102 +    }
 595.103 +}
   596.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   596.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java	Wed Feb 27 11:24:58 2013 +0100
   596.3 @@ -0,0 +1,187 @@
   596.4 +/**
   596.5 + * Back 2 Browser Bytecode Translator
   596.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   596.7 + *
   596.8 + * This program is free software: you can redistribute it and/or modify
   596.9 + * it under the terms of the GNU General Public License as published by
  596.10 + * the Free Software Foundation, version 2 of the License.
  596.11 + *
  596.12 + * This program is distributed in the hope that it will be useful,
  596.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  596.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  596.15 + * GNU General Public License for more details.
  596.16 + *
  596.17 + * You should have received a copy of the GNU General Public License
  596.18 + * along with this program. Look for COPYING file in the top folder.
  596.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  596.20 + */
  596.21 +package org.apidesign.vm4brwsr;
  596.22 +
  596.23 +import java.io.ByteArrayInputStream;
  596.24 +import java.io.IOException;
  596.25 +import java.io.InputStream;
  596.26 +import java.net.URL;
  596.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  596.28 +import org.apidesign.bck2brwsr.emul.zip.FastJar;
  596.29 +
  596.30 +/** Conversion from classpath to load function.
  596.31 + *
  596.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  596.33 + */
  596.34 +final class Zips {
  596.35 +    private final FastJar fj;
  596.36 +
  596.37 +    private Zips(String path, byte[] zipData) throws IOException {
  596.38 +        long bef = timeNow();
  596.39 +        fj = new FastJar(zipData);
  596.40 +        for (FastJar.Entry e : fj.list()) {
  596.41 +            putRes(e.name, e);
  596.42 +        }
  596.43 +        log("Iterating thru " + path + " took " + (timeNow() - bef) + "ms");
  596.44 +    }
  596.45 +    
  596.46 +    public static void init() {
  596.47 +    }
  596.48 +    @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
  596.49 +    private static native int length(Object arr);
  596.50 +    @JavaScriptBody(args = { "arr", "index" }, body = "return arr[index];")
  596.51 +    private static native Object at(Object arr, int index);
  596.52 +    @JavaScriptBody(args = { "arr", "index", "value" }, body = "arr[index] = value; return value;")
  596.53 +    private static native Object set(Object arr, int index, Object value);
  596.54 +    
  596.55 +    public static byte[] loadFromCp(Object classpath, String res) 
  596.56 +    throws IOException, ClassNotFoundException {
  596.57 +        for (int i = 0; i < length(classpath); i++) {
  596.58 +            Object c = at(classpath, i);
  596.59 +            if (c instanceof String) {
  596.60 +                try {
  596.61 +                    String url = (String)c;
  596.62 +                    final Zips z = toZip(url);
  596.63 +                    c = set(classpath, i, z);
  596.64 +                    final byte[] man = z.findRes("META-INF/MANIFEST.MF");
  596.65 +                    if (man != null) {
  596.66 +                        String mainClass = processClassPathAttr(man, url, classpath);
  596.67 +//                        if (mainClass != null) {
  596.68 +//                            Class.forName(mainClass);
  596.69 +//                        }
  596.70 +                    }
  596.71 +                } catch (IOException ex) {
  596.72 +                    set(classpath, i, ex);
  596.73 +                    log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
  596.74 +                }
  596.75 +            }
  596.76 +            if (res != null) {
  596.77 +                byte[] checkRes;
  596.78 +                if (c instanceof Zips) {
  596.79 +                    checkRes = ((Zips)c).findRes(res);
  596.80 +                } else {
  596.81 +                    checkRes = callFunction(c, res);
  596.82 +                }
  596.83 +                if (checkRes != null) {
  596.84 +                    return checkRes;
  596.85 +                }
  596.86 +            }
  596.87 +        }
  596.88 +        return null;
  596.89 +    }
  596.90 +    
  596.91 +    @JavaScriptBody(args = { "fn", "res" }, body = 
  596.92 +        "if (typeof fn === 'function') return fn(res);\n"
  596.93 +      + "return null;"
  596.94 +    )
  596.95 +    private static native byte[] callFunction(Object fn, String res);
  596.96 +    
  596.97 +    @JavaScriptBody(args = { "msg" }, body = "console.log(msg.toString());")
  596.98 +    private static native void log(String msg);
  596.99 +
 596.100 +    private byte[] findRes(String res) throws IOException {
 596.101 +        Object arr = findResImpl(res);
 596.102 +        if (arr instanceof FastJar.Entry) {
 596.103 +            long bef = timeNow();
 596.104 +            InputStream zip = fj.getInputStream((FastJar.Entry)arr);
 596.105 +            arr = readFully(new byte[512], zip);
 596.106 +            putRes(res, arr);
 596.107 +            log("Reading " + res + " took " + (timeNow() - bef) + "ms");
 596.108 +        }
 596.109 +        return (byte[]) arr;
 596.110 +    }
 596.111 +
 596.112 +    @JavaScriptBody(args = { "res" }, body = "var r = this[res]; return r ? r : null;")
 596.113 +    private native Object findResImpl(String res);
 596.114 +
 596.115 +    @JavaScriptBody(args = { "res", "arr" }, body = "this[res] = arr;")
 596.116 +    private native void putRes(String res, Object arr);
 596.117 +    
 596.118 +    private static Zips toZip(String path) throws IOException {
 596.119 +        URL u = new URL(path);
 596.120 +        byte[] zipData = (byte[]) u.getContent(new Class[] { byte[].class });
 596.121 +        return new Zips(path, zipData);
 596.122 +    }
 596.123 +
 596.124 +    private static String processClassPathAttr(final byte[] man, String url, Object classpath) throws IOException {
 596.125 +        try (ParseMan is = new ParseMan(new ByteArrayInputStream(man))) {
 596.126 +            String cp = is.toString();
 596.127 +            if (cp != null) {
 596.128 +                cp = cp.trim();
 596.129 +                for (int p = 0; p < cp.length();) {
 596.130 +                    int n = cp.indexOf(' ', p);
 596.131 +                    if (n == -1) {
 596.132 +                        n = cp.length();
 596.133 +                    }
 596.134 +                    String el = cp.substring(p, n);
 596.135 +                    URL u = new URL(new URL(url), el);
 596.136 +                    classpath = addToArray(classpath, u.toString());
 596.137 +                    p = n + 1;
 596.138 +                }
 596.139 +            }
 596.140 +            return is.getMainClass();
 596.141 +        }
 596.142 +    }
 596.143 +
 596.144 +    private static Object addToArray(Object arr, String value) {
 596.145 +        final int last = length(arr);
 596.146 +        Object ret = enlargeArray(arr, last + 1);
 596.147 +        set(ret, last, value);
 596.148 +        return ret;
 596.149 +    }
 596.150 +
 596.151 +    @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(null); return arr;")
 596.152 +    private static native Object enlargeArray(Object arr, int len);
 596.153 +    @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(0);")
 596.154 +    private static native void enlargeBytes(byte[] arr, int len);
 596.155 +
 596.156 +    @JavaScriptBody(args = { "arr", "len" }, body = "arr.splice(len, arr.length - len);")
 596.157 +    private static native void sliceArray(byte[] arr, int len);
 596.158 +
 596.159 +    private static Object readFully(byte[] arr, InputStream zip) throws IOException {
 596.160 +        int offset = 0;
 596.161 +        for (;;) {
 596.162 +            int len = zip.read(arr, offset, arr.length - offset);
 596.163 +            if (len == -1) {
 596.164 +                break;
 596.165 +            }
 596.166 +            offset += len;
 596.167 +            if (offset == arr.length) {
 596.168 +                enlargeBytes(arr, arr.length + 4096);
 596.169 +            }
 596.170 +        }
 596.171 +        sliceArray(arr, offset);
 596.172 +        return arr;
 596.173 +    }
 596.174 +
 596.175 +    private static long timeNow() {
 596.176 +        double time = m();
 596.177 +        if (time >= 0) {
 596.178 +            return (long)time;
 596.179 +        }
 596.180 +        return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
 596.181 +    }
 596.182 +    @JavaScriptBody(args = {}, body = 
 596.183 +        "if (typeof window.performance === 'undefined') return -1;\n"
 596.184 +      + "if (typeof window.performance.now === 'undefined') return -1;\n"
 596.185 +      + "return window.performance.now();"
 596.186 +    )
 596.187 +    private static native double m();
 596.188 +    
 596.189 +    
 596.190 +}
   597.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   597.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Array.java	Wed Feb 27 11:24:58 2013 +0100
   597.3 @@ -0,0 +1,135 @@
   597.4 +/**
   597.5 + * Back 2 Browser Bytecode Translator
   597.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   597.7 + *
   597.8 + * This program is free software: you can redistribute it and/or modify
   597.9 + * it under the terms of the GNU General Public License as published by
  597.10 + * the Free Software Foundation, version 2 of the License.
  597.11 + *
  597.12 + * This program is distributed in the hope that it will be useful,
  597.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  597.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  597.15 + * GNU General Public License for more details.
  597.16 + *
  597.17 + * You should have received a copy of the GNU General Public License
  597.18 + * along with this program. Look for COPYING file in the top folder.
  597.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  597.20 + */
  597.21 +package org.apidesign.vm4brwsr;
  597.22 +
  597.23 +/**
  597.24 + *
  597.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  597.26 + */
  597.27 +public class Array {
  597.28 +    byte[] bytes = { 1 };
  597.29 +    short[] shorts = { 2, 3 };
  597.30 +    int[] ints = { 4, 5, 6 };
  597.31 +    float[] floats = { 7, 8, 9, 10 };
  597.32 +    double[][] doubles = { {11}, {12}, {13}, {14}, {15} };
  597.33 +    char[] chars = { 'a', 'b' };
  597.34 +    
  597.35 +    private Array() {
  597.36 +    }
  597.37 +    
  597.38 +    byte bytes() {
  597.39 +        return bytes[0];
  597.40 +    }
  597.41 +    short shorts() {
  597.42 +        return shorts[1];
  597.43 +    }
  597.44 +    
  597.45 +    int[] ints() {
  597.46 +        return ints;
  597.47 +    }
  597.48 +    
  597.49 +    float floats() {
  597.50 +        return floats[3];
  597.51 +    }
  597.52 +    
  597.53 +    double doubles() {
  597.54 +        return doubles[4][0];
  597.55 +    }
  597.56 +    
  597.57 +    static double[][] dbls = new double[1][2];
  597.58 +    public static double twoDoubles() {
  597.59 +        return dbls[0][0] + dbls[0][0];
  597.60 +    }
  597.61 +
  597.62 +    static int[][] tints = new int[1][2];
  597.63 +    public static int twoInts() {
  597.64 +        return tints[0][0] + tints[0][0];
  597.65 +    }
  597.66 +    
  597.67 +    private static final Array[] ARR = { new Array(), new Array(), new Array() };
  597.68 +    
  597.69 +    private static Array[][] arr() {
  597.70 +        Array[][] matrix = new Array[3][3];
  597.71 +        for (int i = 0; i < ARR.length; i++) {
  597.72 +            matrix[i][i] = ARR[i];
  597.73 +        }
  597.74 +        return matrix;
  597.75 +    }
  597.76 +    private static <T> T[] filter(T[] in) {
  597.77 +        return in;
  597.78 +    }
  597.79 +    
  597.80 +    public static double sum() {
  597.81 +        double sum = 0.0;
  597.82 +        for (Array[] row : arr()) {
  597.83 +            int indx = -1;
  597.84 +            for (Array a : row) {
  597.85 +                indx++;
  597.86 +                if (a == null) {
  597.87 +                    continue;
  597.88 +                }
  597.89 +                sum += a.bytes();
  597.90 +                sum += a.shorts();
  597.91 +                sum += a.ints()[2];
  597.92 +                sum += a.floats();
  597.93 +                sum += filter(row)[indx].doubles();
  597.94 +            }
  597.95 +        }
  597.96 +        return sum;
  597.97 +    }
  597.98 +    private static final int[] arr = { 0, 1, 2, 3, 4, 5 };
  597.99 +    public static int simple(boolean clone) {
 597.100 +        int[] ar;
 597.101 +        if (clone) {
 597.102 +            ar = arr.clone();
 597.103 +        } else {
 597.104 +            ar = arr;
 597.105 +        }
 597.106 +        
 597.107 +        int sum = 0;
 597.108 +        for (int a : ar) {
 597.109 +            sum += a;
 597.110 +        }
 597.111 +        return sum;
 597.112 +    }
 597.113 +    
 597.114 +    public static String objectArrayClass() {
 597.115 +        return Object[].class.getName();
 597.116 +    }
 597.117 +    
 597.118 +    public static boolean instanceOfArray(Object obj) {
 597.119 +        return obj instanceof Object[];
 597.120 +    }
 597.121 +    
 597.122 +    public static int sum(int size) {
 597.123 +        int[] arr = new int[size];
 597.124 +        return arr[0] + arr[1];
 597.125 +    }
 597.126 +    
 597.127 +    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
 597.128 +        while (count-- > 0) {
 597.129 +            dst[dstBegin++] = value[srcBegin++];
 597.130 +        }
 597.131 +    }
 597.132 +
 597.133 +    public static char copyArray() {
 597.134 +        char[] arr = { '0' };
 597.135 +        arraycopy(arr()[0][0].chars, 0, arr, 0, 1);
 597.136 +        return arr[0];
 597.137 +    }
 597.138 +}
   598.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   598.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java	Wed Feb 27 11:24:58 2013 +0100
   598.3 @@ -0,0 +1,87 @@
   598.4 +/**
   598.5 + * Back 2 Browser Bytecode Translator
   598.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   598.7 + *
   598.8 + * This program is free software: you can redistribute it and/or modify
   598.9 + * it under the terms of the GNU General Public License as published by
  598.10 + * the Free Software Foundation, version 2 of the License.
  598.11 + *
  598.12 + * This program is distributed in the hope that it will be useful,
  598.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  598.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  598.15 + * GNU General Public License for more details.
  598.16 + *
  598.17 + * You should have received a copy of the GNU General Public License
  598.18 + * along with this program. Look for COPYING file in the top folder.
  598.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  598.20 + */
  598.21 +package org.apidesign.vm4brwsr;
  598.22 +
  598.23 +import static org.testng.Assert.*;
  598.24 +import org.testng.annotations.BeforeClass;
  598.25 +import org.testng.annotations.Test;
  598.26 +
  598.27 +/**
  598.28 + *
  598.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  598.30 + */
  598.31 +public class ArrayTest {
  598.32 +    @Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
  598.33 +            assertExec("0 + 0", Array.class, "sum__II", 
  598.34 +            Double.valueOf(0), 2
  598.35 +        );
  598.36 +    }
  598.37 +    @Test public void verifySimpleIntOperation() throws Exception {
  598.38 +            assertExec("CheckTheSum", Array.class, "simple__IZ", 
  598.39 +            Double.valueOf(15), false
  598.40 +        );
  598.41 +    }
  598.42 +    
  598.43 +    @Test public void cloneOnArray() throws Exception {
  598.44 +            assertExec("CheckTheSum on clone", Array.class, "simple__IZ", 
  598.45 +            Double.valueOf(15), true
  598.46 +        );
  598.47 +    }
  598.48 +    
  598.49 +    @Test public void realOperationOnArrays() throws Exception {
  598.50 +        assertEquals(Array.sum(), 105.0, "Computes to 105");
  598.51 +    }
  598.52 +    
  598.53 +    @Test public void verifyOperationsOnArrays() throws Exception {
  598.54 +        assertExec("The sum is 105", Array.class, "sum__D", 
  598.55 +            Double.valueOf(105)
  598.56 +        );
  598.57 +    }
  598.58 +
  598.59 +    @Test public void twoDoubles() throws Exception {
  598.60 +        assertExec("Elements are initialized", Array.class, "twoDoubles__D", 
  598.61 +            Double.valueOf(0)
  598.62 +        );
  598.63 +    }
  598.64 +    @Test public void twoInts() throws Exception {
  598.65 +        assertExec("Elements are initialized", Array.class, "twoInts__I", 
  598.66 +            Double.valueOf(0)
  598.67 +        );
  598.68 +    }
  598.69 +    
  598.70 +    @Test public void doesCopyArrayWork() throws Exception {
  598.71 +        assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
  598.72 +    }
  598.73 +
  598.74 +    @Test public void verifyObjectArrayClass() throws Exception {
  598.75 +        assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass());
  598.76 +    }
  598.77 +    @Test public void verifyInstanceOfArray() throws Exception {
  598.78 +        assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array");
  598.79 +    }
  598.80 +    
  598.81 +    private static TestVM code;
  598.82 +    
  598.83 +    @BeforeClass 
  598.84 +    public void compileTheCode() throws Exception {
  598.85 +        code = TestVM.compileClass("org/apidesign/vm4brwsr/Array");
  598.86 +    }
  598.87 +    private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
  598.88 +        code.assertExec(msg, clazz, method, expRes, args);
  598.89 +    }
  598.90 +}
   599.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   599.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java	Wed Feb 27 11:24:58 2013 +0100
   599.3 @@ -0,0 +1,55 @@
   599.4 +/**
   599.5 + * Back 2 Browser Bytecode Translator
   599.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   599.7 + *
   599.8 + * This program is free software: you can redistribute it and/or modify
   599.9 + * it under the terms of the GNU General Public License as published by
  599.10 + * the Free Software Foundation, version 2 of the License.
  599.11 + *
  599.12 + * This program is distributed in the hope that it will be useful,
  599.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  599.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  599.15 + * GNU General Public License for more details.
  599.16 + *
  599.17 + * You should have received a copy of the GNU General Public License
  599.18 + * along with this program. Look for COPYING file in the top folder.
  599.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  599.20 + */
  599.21 +package org.apidesign.vm4brwsr;
  599.22 +
  599.23 +import static org.testng.Assert.*;
  599.24 +import org.testng.annotations.Test;
  599.25 +
  599.26 +/**
  599.27 + *
  599.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  599.29 + */
  599.30 +public class ByteCodeToJavaScriptTest {
  599.31 +    
  599.32 +    public ByteCodeToJavaScriptTest() {
  599.33 +    }
  599.34 +
  599.35 +    @Test
  599.36 +    public void findMethodNameManglesObjectsCorrectly() {
  599.37 +        StringBuilder cnt = new StringBuilder();
  599.38 +        char[] returnType = { 'V' };
  599.39 +        String ret = ByteCodeToJavaScript.findMethodName(new String[] { 
  599.40 +            "StringTest", "replace", "(Ljava/lang/String;CC)Ljava/lang/String;"
  599.41 +        }, cnt, returnType);
  599.42 +        assertEquals(cnt.toString(), "000", "No doubles or longs");
  599.43 +        assertTrue(returnType[0] != 'V', "Returns string");
  599.44 +        assertEquals(ret, "replace__Ljava_lang_String_2Ljava_lang_String_2CC");
  599.45 +    }
  599.46 +
  599.47 +    @Test
  599.48 +    public void manglingArrays() {
  599.49 +        StringBuilder cnt = new StringBuilder();
  599.50 +        char[] returnType = { 'V' };
  599.51 +        String ret = ByteCodeToJavaScript.findMethodName(new String[] { 
  599.52 +            "VMinVM", "toJavaScript", "([B)Ljava/lang/String;"
  599.53 +        }, cnt, returnType);
  599.54 +        assertEquals(cnt.toString(), "0", "No doubles or longs");
  599.55 +        assertTrue(returnType[0] != 'V', "Returns string");
  599.56 +        assertEquals(ret, "toJavaScript__Ljava_lang_String_2_3B");
  599.57 +    }
  599.58 +}
   600.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   600.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java	Wed Feb 27 11:24:58 2013 +0100
   600.3 @@ -0,0 +1,76 @@
   600.4 +/**
   600.5 + * Back 2 Browser Bytecode Translator
   600.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   600.7 + *
   600.8 + * This program is free software: you can redistribute it and/or modify
   600.9 + * it under the terms of the GNU General Public License as published by
  600.10 + * the Free Software Foundation, version 2 of the License.
  600.11 + *
  600.12 + * This program is distributed in the hope that it will be useful,
  600.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  600.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  600.15 + * GNU General Public License for more details.
  600.16 + *
  600.17 + * You should have received a copy of the GNU General Public License
  600.18 + * along with this program. Look for COPYING file in the top folder.
  600.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  600.20 + */
  600.21 +package org.apidesign.vm4brwsr;
  600.22 +
  600.23 +import java.io.IOException;
  600.24 +import java.io.InputStream;
  600.25 +import java.net.URL;
  600.26 +import java.util.Enumeration;
  600.27 +import java.util.Set;
  600.28 +import java.util.TreeSet;
  600.29 +
  600.30 +/**
  600.31 + *
  600.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  600.33 + */
  600.34 +public final class BytesLoader {
  600.35 +    private static Set<String> requested = new TreeSet<String>();
  600.36 +
  600.37 +    public byte[] get(String name) throws IOException {
  600.38 +        if (!requested.add(name)) {
  600.39 +            throw new IllegalStateException("Requested for second time: " + name);
  600.40 +        }
  600.41 +        byte[] arr = readClass(name);
  600.42 +        /*
  600.43 +        System.err.print("loader['" + name + "'] = [");
  600.44 +        for (int i = 0; i < arr.length; i++) {
  600.45 +        if (i > 0) {
  600.46 +        System.err.print(", ");
  600.47 +        }
  600.48 +        System.err.print(arr[i]);
  600.49 +        }
  600.50 +        System.err.println("]");
  600.51 +         */
  600.52 +        return arr;
  600.53 +    }
  600.54 +
  600.55 +    static byte[] readClass(String name) throws IOException {
  600.56 +        URL u = null;
  600.57 +        Enumeration<URL> en = BytesLoader.class.getClassLoader().getResources(name);
  600.58 +        while (en.hasMoreElements()) {
  600.59 +            u = en.nextElement();
  600.60 +        }
  600.61 +        if (u == null) {
  600.62 +            throw new IOException("Can't find " + name);
  600.63 +        }
  600.64 +        try (InputStream is = u.openStream()) {
  600.65 +            byte[] arr;
  600.66 +            arr = new byte[is.available()];
  600.67 +            int offset = 0;
  600.68 +            while (offset < arr.length) {
  600.69 +                int len = is.read(arr, offset, arr.length - offset);
  600.70 +                if (len == -1) {
  600.71 +                    throw new IOException("Can't read " + name);
  600.72 +                }
  600.73 +                offset += len;
  600.74 +            }
  600.75 +            return arr;
  600.76 +        }
  600.77 +    }
  600.78 +    
  600.79 +}
   601.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   601.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Wed Feb 27 11:24:58 2013 +0100
   601.3 @@ -0,0 +1,206 @@
   601.4 +/**
   601.5 + * Back 2 Browser Bytecode Translator
   601.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   601.7 + *
   601.8 + * This program is free software: you can redistribute it and/or modify
   601.9 + * it under the terms of the GNU General Public License as published by
  601.10 + * the Free Software Foundation, version 2 of the License.
  601.11 + *
  601.12 + * This program is distributed in the hope that it will be useful,
  601.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  601.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  601.15 + * GNU General Public License for more details.
  601.16 + *
  601.17 + * You should have received a copy of the GNU General Public License
  601.18 + * along with this program. Look for COPYING file in the top folder.
  601.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  601.20 + */
  601.21 +package org.apidesign.vm4brwsr;
  601.22 +
  601.23 +import org.testng.annotations.Test;
  601.24 +import static org.testng.Assert.*;
  601.25 +import org.testng.annotations.BeforeClass;
  601.26 +
  601.27 +/**
  601.28 + *
  601.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  601.30 + */
  601.31 +public class ClassTest {
  601.32 +
  601.33 +    @Test public void superClassEqualsGetSuperclass() {
  601.34 +        assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
  601.35 +    }
  601.36 +
  601.37 +    @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
  601.38 +        assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptions__Z", Double.valueOf(1.0));
  601.39 +    }
  601.40 +
  601.41 +    @Test public void classesAreDifferent() {
  601.42 +        assertTrue(Classes.differenceInClasses(), "Classes are not equal");
  601.43 +    }
  601.44 +
  601.45 +    @Test public void jsClassesAreDifferent() throws Exception {
  601.46 +        assertExec("Classes are not equal", Classes.class, "differenceInClasses__Z", Double.valueOf(1.0));
  601.47 +    }
  601.48 +
  601.49 +    @Test public void javaInstanceName() throws Exception {
  601.50 +        assertEquals(Classes.classForInstance(), "java.io.IOException");
  601.51 +    }
  601.52 +    @Test public void jsInstanceName() throws Exception {
  601.53 +        assertExec("I/O name", Classes.class, "classForInstance__Ljava_lang_String_2", "java.io.IOException");
  601.54 +    }
  601.55 +    @Test public void javaName() throws Exception {
  601.56 +        assertEquals(Classes.name(), "java.io.IOException");
  601.57 +    }
  601.58 +    @Test public void jsName() throws Exception {
  601.59 +        assertExec("I/O name", Classes.class, "name__Ljava_lang_String_2", "java.io.IOException");
  601.60 +    }
  601.61 +    @Test public void javaSimpleName() throws Exception {
  601.62 +        assertEquals(Classes.simpleName(), "IOException");
  601.63 +    }
  601.64 +    @Test public void jsGetsSimpleName() throws Exception {
  601.65 +        assertExec("I/O simple name", Classes.class, "simpleName__Ljava_lang_String_2", "IOException");
  601.66 +    }
  601.67 +    @Test public void javaCanonicalName() {
  601.68 +        assertEquals(Classes.canonicalName(), "java.io.IOException");
  601.69 +    }
  601.70 +    @Test public void jsCanonicalName() throws Exception {
  601.71 +        assertExec("I/O simple name", Classes.class, "canonicalName__Ljava_lang_String_2", "java.io.IOException");
  601.72 +    }
  601.73 +    @Test public void javaNewInstance() throws Exception {
  601.74 +        assertTrue(Classes.newInstance());
  601.75 +    }
  601.76 +    @Test public void jsNewInstance() throws Exception {
  601.77 +        assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
  601.78 +    }
  601.79 +    @Test public void javaNoNewInstance() throws Exception {
  601.80 +        assertEquals("java.lang.InstantiationException:java.lang.Float", 
  601.81 +            Classes.newInstanceNoPubConstructor()
  601.82 +        );
  601.83 +    }
  601.84 +    @Test public void jsNoNewInstance() throws Exception {
  601.85 +        assertExec("Check problems with new instance", Classes.class, "newInstanceNoPubConstructor__Ljava_lang_String_2", 
  601.86 +            "java.lang.InstantiationException:java.lang.Float"
  601.87 +        );
  601.88 +    }
  601.89 +    @Test public void jsAnnotation() throws Exception {
  601.90 +        assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
  601.91 +    }
  601.92 +    @Test public void jsArrayAnnotation() throws Exception {
  601.93 +        assertExec("Check array annotation", Classes.class, "getMarkerNicknames__Ljava_lang_String_2", Classes.getMarkerNicknames());
  601.94 +    }
  601.95 +    @Test public void jsEnumAnnotation() throws Exception {
  601.96 +        assertExec("Check enum annotation", Classes.class, "getMarkerE__Ljava_lang_String_2", Classes.getMarkerE());
  601.97 +    }
  601.98 +    @Test public void jsRetentionAnnotation() throws Exception {
  601.99 +        assertExec("Check enum annotation", Classes.class, "getRetention__Ljava_lang_String_2", Classes.getRetention());
 601.100 +    }
 601.101 +    @Test public void jsStringAnnotation() throws Exception {
 601.102 +        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", true);
 601.103 +    }
 601.104 +    @Test public void jsStringAnnotationFromArray() throws Exception {
 601.105 +        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
 601.106 +    }
 601.107 +    @Test public void jsInnerAnnotation() throws Exception {
 601.108 +        assertExec("Check inner annotation", Classes.class, "getInnerNamer__I", Double.valueOf(Classes.getInnerNamer()));
 601.109 +    }
 601.110 +    @Test public void jsInnerAnnotationFromArray() throws Exception {
 601.111 +        assertExec("Check inner annotation", Classes.class, "getInnerNamers__I", Double.valueOf(Classes.getInnerNamers()));
 601.112 +    }
 601.113 +    @Test public void javaInvokeMethod() throws Exception {
 601.114 +        assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
 601.115 +    }
 601.116 +    @Test public void jsInvokeMethod() throws Exception {
 601.117 +        assertExec("Calls the name() method via reflection", Classes.class, 
 601.118 +            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
 601.119 +            "java.io.IOException", true, "name"
 601.120 +        );
 601.121 +    }
 601.122 +    
 601.123 +    @Test public void jsMethodDeclaredInObject() throws Exception {
 601.124 +        assertExec("Defined in Object", Classes.class, 
 601.125 +            "objectName__Ljava_lang_String_2", 
 601.126 +            "java.lang.Object"
 601.127 +        );
 601.128 +    }
 601.129 +    
 601.130 +    @Test public void jsInvokeParamMethod() throws Exception {
 601.131 +        assertExec("sums two numbers via reflection", Classes.class, 
 601.132 +            "reflectiveSum__III", Double.valueOf(5), 2, 3
 601.133 +        );
 601.134 +    }
 601.135 +    @Test public void javaFindMethod() throws Exception {
 601.136 +        assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
 601.137 +    }
 601.138 +    @Test public void jsFindMethod() throws Exception {
 601.139 +        assertExec("Calls the name() method via reflection", Classes.class, 
 601.140 +            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
 601.141 +            "java.io.IOException", false, "name"
 601.142 +        );
 601.143 +    }
 601.144 +    @Test public void primitiveReturnType() throws Exception {
 601.145 +        assertExec("Tries to get an integer via reflection", Classes.class, 
 601.146 +            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
 601.147 +            Classes.primitiveType("primitive"), "primitive"
 601.148 +        );
 601.149 +    }
 601.150 +    @Test public void primitiveBoolReturnType() throws Exception {
 601.151 +        assertExec("Tries to get an integer via reflection", Classes.class, 
 601.152 +            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
 601.153 +            Classes.primitiveType("primitiveB"), "primitiveB"
 601.154 +        );
 601.155 +    }
 601.156 +    @Test public void javaAnnotatedMethod() throws Exception {
 601.157 +        assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
 601.158 +    }
 601.159 +    @Test public void jsAnnotatedMethod() throws Exception {
 601.160 +        assertExec("Calls the name() method via reflection", Classes.class, 
 601.161 +            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
 601.162 +            "java.io.IOException", false, null
 601.163 +        );
 601.164 +    }
 601.165 +    @Test public void jsClassParam() throws Exception {
 601.166 +        assertExec("Calls the nameOfIO()", Classes.class, 
 601.167 +            "nameOfIO__Ljava_lang_String_2", 
 601.168 +            "java.io.IOException"
 601.169 +        );
 601.170 +    }
 601.171 +    @Test public void noInterface() throws Exception {
 601.172 +        assertExec("Calls Class.isInterface", Classes.class, 
 601.173 +            "isInterface__ZLjava_lang_String_2", 
 601.174 +            0.0, "java.lang.String"
 601.175 +        );
 601.176 +    }
 601.177 +    @Test public void isInterface() throws Exception {
 601.178 +        assertExec("Calls Class.isInterface", Classes.class, 
 601.179 +            "isInterface__ZLjava_lang_String_2", 
 601.180 +            1.0, "java.lang.Runnable"
 601.181 +        );
 601.182 +    }
 601.183 +    @Test public void integerType() throws Exception {
 601.184 +        assertExec("Computes the type", Classes.class, 
 601.185 +            "intType__Ljava_lang_String_2", 
 601.186 +            Classes.intType()
 601.187 +        );
 601.188 +    }
 601.189 +    
 601.190 +    private static TestVM code;
 601.191 +    
 601.192 +    @BeforeClass
 601.193 +    public void compileTheCode() throws Exception {
 601.194 +        code = TestVM.compileClass("org/apidesign/vm4brwsr/Classes");
 601.195 +    }
 601.196 +    
 601.197 +    private void assertExec(
 601.198 +        String msg, Class clazz, String method, Object expRes, Object... args
 601.199 +    ) throws Exception {
 601.200 +        code.assertExec(msg, clazz, method, expRes, args);
 601.201 +    }
 601.202 +    @Test public void isClassAssignable() throws Exception {
 601.203 +        assertExec("isAssignable works on subclasses", Classes.class, 
 601.204 +            "isClassAssignable__Z", 
 601.205 +            true
 601.206 +        );
 601.207 +    }
 601.208 +    
 601.209 +}
   602.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   602.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Wed Feb 27 11:24:58 2013 +0100
   602.3 @@ -0,0 +1,233 @@
   602.4 +/**
   602.5 + * Back 2 Browser Bytecode Translator
   602.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   602.7 + *
   602.8 + * This program is free software: you can redistribute it and/or modify
   602.9 + * it under the terms of the GNU General Public License as published by
  602.10 + * the Free Software Foundation, version 2 of the License.
  602.11 + *
  602.12 + * This program is distributed in the hope that it will be useful,
  602.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  602.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  602.15 + * GNU General Public License for more details.
  602.16 + *
  602.17 + * You should have received a copy of the GNU General Public License
  602.18 + * along with this program. Look for COPYING file in the top folder.
  602.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  602.20 + */
  602.21 +package org.apidesign.vm4brwsr;
  602.22 +
  602.23 +import java.io.IOException;
  602.24 +import java.lang.annotation.Annotation;
  602.25 +import java.lang.annotation.Retention;
  602.26 +import java.lang.annotation.RetentionPolicy;
  602.27 +import java.lang.reflect.Method;
  602.28 +import java.net.MalformedURLException;
  602.29 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  602.30 +
  602.31 +/**
  602.32 + *
  602.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  602.34 + */
  602.35 +@ClassesMarker(number = 10, nicknames = { "Ten", "Deset" }, count = ClassesMarker.E.TWO, subs = {
  602.36 +    @ClassesMarker.Anno(Integer.SIZE),
  602.37 +    @ClassesMarker.Anno(Integer.MIN_VALUE)
  602.38 +})
  602.39 +@ClassesNamer(name = "my text", anno = @ClassesMarker.Anno(333))
  602.40 +public class Classes {
  602.41 +    public static String nameOfIO() {
  602.42 +        return nameFor(IOException.class);
  602.43 +    }
  602.44 +    
  602.45 +    private static String nameFor(Class<?> c) {
  602.46 +        return c.getName();
  602.47 +    }
  602.48 +    
  602.49 +    private static final Class<?> PRELOAD = Runnable.class;
  602.50 +    
  602.51 +    public static boolean isInterface(String s) throws ClassNotFoundException {
  602.52 +        return Class.forName(s).isInterface();
  602.53 +    }
  602.54 +    
  602.55 +    public static boolean equalsClassesOfExceptions() {
  602.56 +        return MalformedURLException.class.getSuperclass() == IOException.class;
  602.57 +    }
  602.58 +    public static boolean differenceInClasses() {
  602.59 +        Class<?> c1 = MalformedURLException.class;
  602.60 +        Class<?> c2 = IOException.class;
  602.61 +        return c1 != c2;
  602.62 +    }
  602.63 +    
  602.64 +    public static String classForInstance() {
  602.65 +        return new IOException().getClass().getName().toString();
  602.66 +    }
  602.67 +    
  602.68 +    @ClassesMarker(number = 1, nicknames = { "One", "Jedna" } )
  602.69 +    public static String name() {
  602.70 +        return IOException.class.getName().toString();
  602.71 +    }
  602.72 +    public static String simpleName() {
  602.73 +        return IOException.class.getSimpleName();
  602.74 +    }
  602.75 +    public static String canonicalName() {
  602.76 +        return IOException.class.getCanonicalName();
  602.77 +    }
  602.78 +    
  602.79 +    public static String objectName() throws NoSuchMethodException {
  602.80 +        return IOException.class.getMethod("wait").getDeclaringClass().getName();
  602.81 +    }
  602.82 +    
  602.83 +    public static boolean newInstance() throws Exception {
  602.84 +        IOException ioe = IOException.class.newInstance();
  602.85 +        if (ioe instanceof IOException) {
  602.86 +            return ioe.getClass() == IOException.class;
  602.87 +        }
  602.88 +        throw new IllegalStateException("Not a subtype: " + ioe);
  602.89 +    }
  602.90 +    public static String newInstanceNoPubConstructor() throws Exception {
  602.91 +        try {
  602.92 +            Float f = Float.class.newInstance();
  602.93 +            return "wrong, can't instantiate: " + f;
  602.94 +        } catch (Exception ex) {
  602.95 +            return (ex.getClass().getName() + ":" + ex.getMessage()).toString().toString();
  602.96 +        }
  602.97 +    }
  602.98 +    public static int getMarker() {
  602.99 +        if (!Classes.class.isAnnotationPresent(ClassesMarker.class)) {
 602.100 +            return -2;
 602.101 +        }
 602.102 +        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 602.103 +        assert cm instanceof Object : "Is object " + cm;
 602.104 +        assert cm instanceof Annotation : "Is annotation " + cm;
 602.105 +        assert !((Object)cm instanceof Class) : "Is not Class " + cm;
 602.106 +        return cm == null ? -1 : cm.number();
 602.107 +    }
 602.108 +    public static String getMarkerNicknames() {
 602.109 +        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 602.110 +        if (cm == null) {
 602.111 +            return null;
 602.112 +        }
 602.113 +        
 602.114 +        final Object[] arr = cm.nicknames();
 602.115 +        assert arr instanceof Object[] : "Instance of Object array: " + arr;
 602.116 +        assert arr instanceof String[] : "Instance of String array: " + arr;
 602.117 +        assert !(arr instanceof Integer[]) : "Not instance of Integer array: " + arr;
 602.118 +        
 602.119 +        StringBuilder sb = new StringBuilder();
 602.120 +        for (String s : cm.nicknames()) {
 602.121 +            sb.append(s).append("\n");
 602.122 +        }
 602.123 +        return sb.toString().toString();
 602.124 +    }
 602.125 +    @Retention(RetentionPolicy.CLASS)
 602.126 +    @interface Ann {
 602.127 +    }
 602.128 +    
 602.129 +    public static String getRetention() throws Exception {
 602.130 +        Retention r = Ann.class.getAnnotation(Retention.class);
 602.131 +        assert r != null : "Annotation is present";
 602.132 +        assert r.value() == RetentionPolicy.CLASS : "Policy value is OK: " + r.value();
 602.133 +        return r.annotationType().getName();
 602.134 +    }
 602.135 +    public static String getMarkerE() {
 602.136 +        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 602.137 +        if (cm == null) {
 602.138 +            return null;
 602.139 +        }
 602.140 +        return cm.count().name();
 602.141 +    }
 602.142 +    public static String getNamer(boolean direct) {
 602.143 +        if (direct) {
 602.144 +            ClassesNamer cm = Classes.class.getAnnotation(ClassesNamer.class);
 602.145 +            return cm == null ? null : cm.name();
 602.146 +        }
 602.147 +        for (Annotation a : Classes.class.getAnnotations()) {
 602.148 +            if (a instanceof ClassesNamer) {
 602.149 +                return ((ClassesNamer)a).name();
 602.150 +            }
 602.151 +        }
 602.152 +        return null;
 602.153 +    }
 602.154 +    public static int getInnerNamer() {
 602.155 +        ClassesNamer cm = Classes.class.getAnnotation(ClassesNamer.class);
 602.156 +        assert cm != null : "ClassesNamer is present";
 602.157 +        return cm.anno().value();
 602.158 +    }
 602.159 +    public static int getInnerNamers() {
 602.160 +        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 602.161 +        assert cm != null : "ClassesNamer is present";
 602.162 +        int sum = 0;
 602.163 +        for (ClassesMarker.Anno anno : cm.subs()) {
 602.164 +            sum += anno.value();
 602.165 +        }
 602.166 +        return sum;
 602.167 +    }
 602.168 +    
 602.169 +    public static String intType() {
 602.170 +        return Integer.TYPE.getName();
 602.171 +    }
 602.172 +    
 602.173 +    public static int primitive() {
 602.174 +        return 1;
 602.175 +    }
 602.176 +    public static boolean primitiveB() {
 602.177 +        return true;
 602.178 +    }
 602.179 +    
 602.180 +    public static String primitiveType(String method) throws Exception {
 602.181 +        return reflectiveMethodCall(false, method).getClass().getName();
 602.182 +    }
 602.183 +    
 602.184 +    @JavaScriptBody(args = "msg", body = "throw msg;")
 602.185 +    private static native void thrw(String msg);
 602.186 +    
 602.187 +    public static Object reflectiveMethodCall(boolean direct, String mn) throws Exception {
 602.188 +        Method find = null;
 602.189 +        StringBuilder sb = new StringBuilder();
 602.190 +        if (!direct) {
 602.191 +            final Class<? extends Annotation> v = ClassesMarker.class;
 602.192 +            for (Method m : Classes.class.getMethods()) {
 602.193 +                sb.append("\n").append(m.getName());
 602.194 +                if (mn != null) {
 602.195 +                    if (m.getName().equals(mn)) {
 602.196 +                        find = m;
 602.197 +                        break;
 602.198 +                    }
 602.199 +                } else {
 602.200 +                    if (m.getAnnotation(v) != null) {
 602.201 +                        find = m;
 602.202 +                        break;
 602.203 +                    }
 602.204 +                }
 602.205 +            }
 602.206 +        } else {
 602.207 +            find = Classes.class.getMethod(mn);
 602.208 +        }
 602.209 +        if (find == null) {
 602.210 +            thrw(sb.toString());
 602.211 +            throw new NullPointerException(sb.toString());
 602.212 +        }
 602.213 +        return find.invoke(null);
 602.214 +    }
 602.215 +    
 602.216 +    public static int reflectiveSum(int a, int b) throws Exception {
 602.217 +        Method m = StaticMethod.class.getMethod("sum", int.class, int.class);
 602.218 +        return (int) m.invoke(null, a, b);
 602.219 +    }
 602.220 +    
 602.221 +    private abstract class Application {
 602.222 +        public abstract int getID();
 602.223 +    }
 602.224 +
 602.225 +    private class MyApplication extends Application {
 602.226 +        @Override
 602.227 +        public int getID() {
 602.228 +            return 1;
 602.229 +        }
 602.230 +    }
 602.231 +
 602.232 +    public static boolean isClassAssignable() {
 602.233 +        return Application.class.isAssignableFrom(MyApplication.class);
 602.234 +    }
 602.235 +    
 602.236 +}
   603.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   603.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ClassesMarker.java	Wed Feb 27 11:24:58 2013 +0100
   603.3 @@ -0,0 +1,42 @@
   603.4 +/**
   603.5 + * Back 2 Browser Bytecode Translator
   603.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   603.7 + *
   603.8 + * This program is free software: you can redistribute it and/or modify
   603.9 + * it under the terms of the GNU General Public License as published by
  603.10 + * the Free Software Foundation, version 2 of the License.
  603.11 + *
  603.12 + * This program is distributed in the hope that it will be useful,
  603.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  603.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  603.15 + * GNU General Public License for more details.
  603.16 + *
  603.17 + * You should have received a copy of the GNU General Public License
  603.18 + * along with this program. Look for COPYING file in the top folder.
  603.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  603.20 + */
  603.21 +package org.apidesign.vm4brwsr;
  603.22 +
  603.23 +import java.lang.annotation.Retention;
  603.24 +import java.lang.annotation.RetentionPolicy;
  603.25 +
  603.26 +/**
  603.27 + *
  603.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  603.29 + */
  603.30 +@Retention(RetentionPolicy.RUNTIME)
  603.31 +public @interface ClassesMarker {
  603.32 +    int number();
  603.33 +    String[] nicknames();
  603.34 +    E count() default E.ONE;
  603.35 +    
  603.36 +    enum E {
  603.37 +        ONE, TWO;
  603.38 +    }
  603.39 +    
  603.40 +    Anno[] subs() default {};
  603.41 +    
  603.42 +    public @interface Anno {
  603.43 +        int value();
  603.44 +    }
  603.45 +}
   604.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   604.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ClassesNamer.java	Wed Feb 27 11:24:58 2013 +0100
   604.3 @@ -0,0 +1,31 @@
   604.4 +/**
   604.5 + * Back 2 Browser Bytecode Translator
   604.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   604.7 + *
   604.8 + * This program is free software: you can redistribute it and/or modify
   604.9 + * it under the terms of the GNU General Public License as published by
  604.10 + * the Free Software Foundation, version 2 of the License.
  604.11 + *
  604.12 + * This program is distributed in the hope that it will be useful,
  604.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  604.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  604.15 + * GNU General Public License for more details.
  604.16 + *
  604.17 + * You should have received a copy of the GNU General Public License
  604.18 + * along with this program. Look for COPYING file in the top folder.
  604.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  604.20 + */
  604.21 +package org.apidesign.vm4brwsr;
  604.22 +
  604.23 +import java.lang.annotation.Retention;
  604.24 +import java.lang.annotation.RetentionPolicy;
  604.25 +
  604.26 +/**
  604.27 + *
  604.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  604.29 + */
  604.30 +@Retention(RetentionPolicy.RUNTIME)
  604.31 +public @interface ClassesNamer {
  604.32 +    String name();
  604.33 +    ClassesMarker.Anno anno();
  604.34 +}
   605.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   605.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Exceptions.java	Wed Feb 27 11:24:58 2013 +0100
   605.3 @@ -0,0 +1,88 @@
   605.4 +/**
   605.5 + * Back 2 Browser Bytecode Translator
   605.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   605.7 + *
   605.8 + * This program is free software: you can redistribute it and/or modify
   605.9 + * it under the terms of the GNU General Public License as published by
  605.10 + * the Free Software Foundation, version 2 of the License.
  605.11 + *
  605.12 + * This program is distributed in the hope that it will be useful,
  605.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  605.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  605.15 + * GNU General Public License for more details.
  605.16 + *
  605.17 + * You should have received a copy of the GNU General Public License
  605.18 + * along with this program. Look for COPYING file in the top folder.
  605.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  605.20 + */
  605.21 +package org.apidesign.vm4brwsr;
  605.22 +
  605.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  605.24 +
  605.25 +/**
  605.26 + *
  605.27 + * @author tom
  605.28 + */
  605.29 +public class Exceptions {
  605.30 +    private Exceptions() {
  605.31 +    }
  605.32 +
  605.33 +    public static int methodWithTryCatchNoThrow() {
  605.34 +        int res = 0;
  605.35 +        try {
  605.36 +            res = 1;
  605.37 +        } catch (IllegalArgumentException e) {
  605.38 +            res = 2;
  605.39 +        }
  605.40 +        //join point
  605.41 +        return res;
  605.42 +    }
  605.43 +
  605.44 +    public static int methodWithTryCatchThrow() {
  605.45 +        int res = 0;
  605.46 +        try {
  605.47 +            res = 1;
  605.48 +            throw new IllegalArgumentException();
  605.49 +        } catch (IllegalArgumentException e) {
  605.50 +            res = 2;
  605.51 +        }
  605.52 +        //join point
  605.53 +        return res;
  605.54 +    }
  605.55 +    
  605.56 +    @JavaScriptBody(args = "msg", body = "throw msg;")
  605.57 +    public static void thrw(String msg) {}
  605.58 +    
  605.59 +    public static String catchThrowableCatchesAll() {
  605.60 +        try {
  605.61 +            thrw("Hello!");
  605.62 +            return "Not here!";
  605.63 +        } catch (Throwable ex) {
  605.64 +            return ex.getMessage();
  605.65 +        }
  605.66 +    }
  605.67 +
  605.68 +    public static String newInstance(String n) {
  605.69 +        try {
  605.70 +            Class c;
  605.71 +            try {
  605.72 +                c = Class.forName(n);
  605.73 +            } catch (ClassNotFoundException ex) {
  605.74 +                return ("CNFE:" + ex.getMessage()).toString();
  605.75 +            }
  605.76 +            return c.newInstance().getClass().getName();
  605.77 +        } catch (InstantiationException | IllegalAccessException ex) {
  605.78 +            return ex.getMessage();
  605.79 +        }
  605.80 +    }
  605.81 +    
  605.82 +    private static int counter;
  605.83 +    public static int readCounter(String n) throws ClassNotFoundException {
  605.84 +        try {
  605.85 +            Class.forName(n);
  605.86 +        } finally {
  605.87 +            counter++;
  605.88 +        }
  605.89 +        return counter;
  605.90 +    }
  605.91 +}
   606.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   606.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ExceptionsTest.java	Wed Feb 27 11:24:58 2013 +0100
   606.3 @@ -0,0 +1,114 @@
   606.4 +/**
   606.5 + * Back 2 Browser Bytecode Translator
   606.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   606.7 + *
   606.8 + * This program is free software: you can redistribute it and/or modify
   606.9 + * it under the terms of the GNU General Public License as published by
  606.10 + * the Free Software Foundation, version 2 of the License.
  606.11 + *
  606.12 + * This program is distributed in the hope that it will be useful,
  606.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  606.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  606.15 + * GNU General Public License for more details.
  606.16 + *
  606.17 + * You should have received a copy of the GNU General Public License
  606.18 + * along with this program. Look for COPYING file in the top folder.
  606.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  606.20 + */
  606.21 +package org.apidesign.vm4brwsr;
  606.22 +
  606.23 +import javax.script.ScriptException;
  606.24 +import static org.testng.Assert.*;
  606.25 +import org.testng.annotations.BeforeClass;
  606.26 +import org.testng.annotations.Test;
  606.27 +
  606.28 +/**
  606.29 + *
  606.30 + * @author Tomas Zezula <tzezula@netbeans.org>
  606.31 + */
  606.32 +public class ExceptionsTest {
  606.33 +    @Test
  606.34 +    public void verifyMethodWithTryCatchNoThrow() throws Exception {
  606.35 +            assertExec(
  606.36 +                    "No throw",
  606.37 +                    Exceptions.class,
  606.38 +                    "methodWithTryCatchNoThrow__I",
  606.39 +                    new Double(1.0));
  606.40 +    }
  606.41 +
  606.42 +    @Test
  606.43 +    public void catchJavaScriptStringAsThrowable() throws Exception {
  606.44 +        assertExec(
  606.45 +            "Throw hello!",
  606.46 +            Exceptions.class,
  606.47 +            "catchThrowableCatchesAll__Ljava_lang_String_2",
  606.48 +            "Hello!"
  606.49 +        );
  606.50 +    }
  606.51 +
  606.52 +    @Test
  606.53 +    public void verifyMethodWithTryCatchThrow() throws Exception {
  606.54 +            assertExec(
  606.55 +                    "Throw",
  606.56 +                    Exceptions.class,
  606.57 +                    "methodWithTryCatchThrow__I",
  606.58 +                    new Double(2.0));
  606.59 +    }
  606.60 +    
  606.61 +    @Test public void createObject() throws Exception {
  606.62 +        assertExec("Object created", Exceptions.class, 
  606.63 +            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  606.64 +            "java.lang.Object",
  606.65 +            "java.lang.Object"
  606.66 +        );
  606.67 +    }
  606.68 +
  606.69 +    @Test public void createFloatFails() throws Exception {
  606.70 +        assertExec("Float not created", Exceptions.class, 
  606.71 +            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  606.72 +            "java.lang.Float",
  606.73 +            "java.lang.Float"
  606.74 +        );
  606.75 +    }
  606.76 +
  606.77 +    @Test public void createUnknownFails() throws Exception {
  606.78 +        assertExec("Object created", Exceptions.class, 
  606.79 +            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  606.80 +            "CNFE:org.apidesign.Unknown",
  606.81 +            "org.apidesign.Unknown"
  606.82 +        );
  606.83 +    }
  606.84 +    
  606.85 +    @Test public void testThreeCalls() throws Exception {
  606.86 +        Object clazz = code.loadClass("loadClass", Exceptions.class.getName());
  606.87 +        
  606.88 +        String method = "readCounter__ILjava_lang_String_2";
  606.89 +        
  606.90 +        try {
  606.91 +            Object ret = code.invokeMethod(clazz, method, "org.apidesign.Unknown");
  606.92 +            fail("We expect an CNFE!");
  606.93 +        } catch (ScriptException scriptException) {
  606.94 +            // script exception should be OK
  606.95 +        }
  606.96 +        {
  606.97 +            // 2nd invocation
  606.98 +            Object ret = code.invokeMethod(clazz, method, "java.lang.String");
  606.99 +            assertEquals(ret, Double.valueOf(2));
 606.100 +        }
 606.101 +        {
 606.102 +            // 3rd invocation
 606.103 +            Object ret = code.invokeMethod(clazz, method, "java.lang.Integer");
 606.104 +            assertEquals(ret, Double.valueOf(3));
 606.105 +        }
 606.106 +    }
 606.107 +    
 606.108 +    private static TestVM code;
 606.109 +    
 606.110 +    @BeforeClass 
 606.111 +    public void compileTheCode() throws Exception {
 606.112 +        code = TestVM.compileClass("org/apidesign/vm4brwsr/Exceptions");
 606.113 +    }
 606.114 +    private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
 606.115 +        code.assertExec(msg, clazz, method, expRes, args);
 606.116 +    }
 606.117 +}
   607.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   607.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/GetByte.java	Wed Feb 27 11:24:58 2013 +0100
   607.3 @@ -0,0 +1,22 @@
   607.4 +/**
   607.5 + * Back 2 Browser Bytecode Translator
   607.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   607.7 + *
   607.8 + * This program is free software: you can redistribute it and/or modify
   607.9 + * it under the terms of the GNU General Public License as published by
  607.10 + * the Free Software Foundation, version 2 of the License.
  607.11 + *
  607.12 + * This program is distributed in the hope that it will be useful,
  607.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  607.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  607.15 + * GNU General Public License for more details.
  607.16 + *
  607.17 + * You should have received a copy of the GNU General Public License
  607.18 + * along with this program. Look for COPYING file in the top folder.
  607.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  607.20 + */
  607.21 +package org.apidesign.vm4brwsr;
  607.22 +
  607.23 +public interface GetByte {
  607.24 +    public byte getByte();
  607.25 +}
   608.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   608.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java	Wed Feb 27 11:24:58 2013 +0100
   608.3 @@ -0,0 +1,140 @@
   608.4 +/**
   608.5 + * Back 2 Browser Bytecode Translator
   608.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   608.7 + *
   608.8 + * This program is free software: you can redistribute it and/or modify
   608.9 + * it under the terms of the GNU General Public License as published by
  608.10 + * the Free Software Foundation, version 2 of the License.
  608.11 + *
  608.12 + * This program is distributed in the hope that it will be useful,
  608.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  608.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  608.15 + * GNU General Public License for more details.
  608.16 + *
  608.17 + * You should have received a copy of the GNU General Public License
  608.18 + * along with this program. Look for COPYING file in the top folder.
  608.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  608.20 + */
  608.21 +package org.apidesign.vm4brwsr;
  608.22 +
  608.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  608.24 +
  608.25 +/**
  608.26 + *
  608.27 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  608.28 + */
  608.29 +public class Instance {
  608.30 +    private int in;
  608.31 +    protected short s;
  608.32 +    public double d;
  608.33 +    private float f;
  608.34 +    protected byte b = (byte)31;
  608.35 +    
  608.36 +    private Instance() {
  608.37 +    }
  608.38 +
  608.39 +    public Instance(int i, double d) {
  608.40 +        this.in = i;
  608.41 +        this.d = d;
  608.42 +    }
  608.43 +    public byte getByte() {
  608.44 +        return b;
  608.45 +    }
  608.46 +    
  608.47 +    public void setByte(byte b) {
  608.48 +        this.b = b;
  608.49 +    }
  608.50 +    public static double defaultDblValue() {
  608.51 +        Instance create = new Instance();
  608.52 +        return create.d;
  608.53 +    }
  608.54 +    
  608.55 +    public static byte assignedByteValue() {
  608.56 +        return new Instance().b;
  608.57 +    }
  608.58 +    public static double magicOne() {
  608.59 +        Instance i = new Instance(10, 3.3d);
  608.60 +        i.b = (byte)0x09;
  608.61 +        return (i.in - i.b) * i.d;
  608.62 +    }
  608.63 +    public static int virtualBytes() {
  608.64 +        Instance i = new InstanceSub(7, 2.2d);
  608.65 +        i.setByte((byte)0x0a);
  608.66 +        Instance i2 = new Instance(3, 333.0d);
  608.67 +        i2.setByte((byte)44);
  608.68 +        return i.getByte() + i2.getByte();
  608.69 +    }
  608.70 +    public static float interfaceBytes() {
  608.71 +        GetByte i = new InstanceSub(7, 2.2d);
  608.72 +        return i.getByte();
  608.73 +    }
  608.74 +    public static boolean instanceOf(int sub) {
  608.75 +        Instance i = createInstance(sub);
  608.76 +        return isInstanceSubOf(i);
  608.77 +    }
  608.78 +    public static int castsWork(boolean interfc) {
  608.79 +        Instance i = createInstance(2);
  608.80 +        if (interfc) {
  608.81 +            GetByte b = (GetByte)i;
  608.82 +        } else {
  608.83 +            InstanceSub s = (InstanceSub)i;
  608.84 +        }
  608.85 +        return 5;
  608.86 +    }
  608.87 +    
  608.88 +    private static boolean isInstanceSubOf(Instance instance) {
  608.89 +        return instance instanceof InstanceSub;
  608.90 +    }
  608.91 +    private static Instance createInstance(int type) {
  608.92 +        switch (type) {
  608.93 +            case 0: return null;
  608.94 +            case 1: return new Instance();
  608.95 +            case 2: return new InstanceSub(3, 0);
  608.96 +        }
  608.97 +        throw new IllegalArgumentException();
  608.98 +    }
  608.99 +    private static boolean isNull() {
 608.100 +        return createInstance(2) == null;
 608.101 +    }
 608.102 +    
 608.103 +    @JavaScriptBody(args = "obj", body = "return obj.constructor;")
 608.104 +    static Object constructor(Object obj) {
 608.105 +        return obj;
 608.106 +    }
 608.107 +    
 608.108 +    public static boolean sharedConstructor() {
 608.109 +        class X {
 608.110 +        }
 608.111 +        
 608.112 +        X x1 = new X();
 608.113 +        X x2 = new X();
 608.114 +        
 608.115 +        return constructor(x1) == constructor(x2);
 608.116 +    }
 608.117 +    public static boolean differentConstructor() {
 608.118 +        class X {
 608.119 +        }
 608.120 +        class Y {
 608.121 +        }
 608.122 +        
 608.123 +        X x = new X();
 608.124 +        Y y = new Y();
 608.125 +        
 608.126 +        return constructor(x) == constructor(y);
 608.127 +    }
 608.128 +    @JavaScriptBody(args = {}, body = "return {};")
 608.129 +    private static Object jsObj() {
 608.130 +        return null;
 608.131 +    }
 608.132 +    
 608.133 +    public static boolean iofObject() {
 608.134 +        return jsObj() instanceof Object;
 608.135 +    }
 608.136 +    
 608.137 +    public static int jscall() {
 608.138 +        return jsgetbytes(new Instance());
 608.139 +    }
 608.140 +    
 608.141 +    @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
 608.142 +    private static native int jsgetbytes(Instance instance);
 608.143 +}
   609.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   609.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java	Wed Feb 27 11:24:58 2013 +0100
   609.3 @@ -0,0 +1,40 @@
   609.4 +/**
   609.5 + * Back 2 Browser Bytecode Translator
   609.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   609.7 + *
   609.8 + * This program is free software: you can redistribute it and/or modify
   609.9 + * it under the terms of the GNU General Public License as published by
  609.10 + * the Free Software Foundation, version 2 of the License.
  609.11 + *
  609.12 + * This program is distributed in the hope that it will be useful,
  609.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  609.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  609.15 + * GNU General Public License for more details.
  609.16 + *
  609.17 + * You should have received a copy of the GNU General Public License
  609.18 + * along with this program. Look for COPYING file in the top folder.
  609.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  609.20 + */
  609.21 +package org.apidesign.vm4brwsr;
  609.22 +
  609.23 +/**
  609.24 + *
  609.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  609.26 + */
  609.27 +public class InstanceSub extends Instance implements GetByte {
  609.28 +    private double in;
  609.29 +    
  609.30 +    public InstanceSub(int i, double d) {
  609.31 +        super(i, d);
  609.32 +        in = 555.55;
  609.33 +    }
  609.34 +    
  609.35 +    @Override
  609.36 +    public void setByte(byte b) {
  609.37 +        super.setByte((byte) (b + 1));
  609.38 +    }
  609.39 +    
  609.40 +    public static double recallDbl() {
  609.41 +        return defaultDblValue();
  609.42 +    }
  609.43 +}
   610.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   610.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSubTest.java	Wed Feb 27 11:24:58 2013 +0100
   610.3 @@ -0,0 +1,32 @@
   610.4 +/**
   610.5 + * Back 2 Browser Bytecode Translator
   610.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   610.7 + *
   610.8 + * This program is free software: you can redistribute it and/or modify
   610.9 + * it under the terms of the GNU General Public License as published by
  610.10 + * the Free Software Foundation, version 2 of the License.
  610.11 + *
  610.12 + * This program is distributed in the hope that it will be useful,
  610.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  610.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  610.15 + * GNU General Public License for more details.
  610.16 + *
  610.17 + * You should have received a copy of the GNU General Public License
  610.18 + * along with this program. Look for COPYING file in the top folder.
  610.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  610.20 + */
  610.21 +package org.apidesign.vm4brwsr;
  610.22 +
  610.23 +/** Checks if everything works OK, when we switch the
  610.24 + * order of loaded classes.
  610.25 + * 
  610.26 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  610.27 + */
  610.28 +public class InstanceSubTest extends InstanceTest {
  610.29 +
  610.30 +    @Override
  610.31 +    protected String startCompilationWith() {
  610.32 +        return "org/apidesign/vm4brwsr/InstanceSub";
  610.33 +    }
  610.34 +    
  610.35 +}
   611.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   611.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Wed Feb 27 11:24:58 2013 +0100
   611.3 @@ -0,0 +1,166 @@
   611.4 +/**
   611.5 + * Back 2 Browser Bytecode Translator
   611.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   611.7 + *
   611.8 + * This program is free software: you can redistribute it and/or modify
   611.9 + * it under the terms of the GNU General Public License as published by
  611.10 + * the Free Software Foundation, version 2 of the License.
  611.11 + *
  611.12 + * This program is distributed in the hope that it will be useful,
  611.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  611.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  611.15 + * GNU General Public License for more details.
  611.16 + *
  611.17 + * You should have received a copy of the GNU General Public License
  611.18 + * along with this program. Look for COPYING file in the top folder.
  611.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  611.20 + */
  611.21 +package org.apidesign.vm4brwsr;
  611.22 +
  611.23 +import org.testng.annotations.Test;
  611.24 +import org.testng.annotations.BeforeClass;
  611.25 +
  611.26 +/**
  611.27 + *
  611.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  611.29 + */
  611.30 +public class InstanceTest {
  611.31 +    @Test public void verifyDefaultDoubleValue() throws Exception {
  611.32 +        assertExec(
  611.33 +            "Will be zero",
  611.34 +            Instance.class, "defaultDblValue__D",
  611.35 +            Double.valueOf(0)
  611.36 +        );
  611.37 +    }
  611.38 +    @Test public void verifyStaticMethodCall() throws Exception {
  611.39 +        assertExec(
  611.40 +            "Will be zero",
  611.41 +            InstanceSub.class, "recallDbl__D",
  611.42 +            Double.valueOf(0)
  611.43 +        );
  611.44 +    }
  611.45 +    @Test public void verifyAssignedByteValue() throws Exception {
  611.46 +        assertExec(
  611.47 +            "Will one thirty one",
  611.48 +            Instance.class, "assignedByteValue__B",
  611.49 +            Double.valueOf(31)
  611.50 +        );
  611.51 +    }
  611.52 +    @Test public void verifyMagicOne() throws Exception {
  611.53 +        assertExec(
  611.54 +            "Should be three and something",
  611.55 +            Instance.class, "magicOne__D",
  611.56 +            Double.valueOf(3.3)
  611.57 +        );
  611.58 +    }
  611.59 +    @Test public void verifyInstanceMethods() throws Exception {
  611.60 +        assertExec(
  611.61 +            "Should be eleven as we invoke overwritten method, plus 44",
  611.62 +            Instance.class, "virtualBytes__I",
  611.63 +            Double.valueOf(55)
  611.64 +        );
  611.65 +    }
  611.66 +    @Test public void verifyInterfaceMethods() throws Exception {
  611.67 +        assertExec(
  611.68 +            "Retruns default value",
  611.69 +            Instance.class, "interfaceBytes__F",
  611.70 +            Double.valueOf(31)
  611.71 +        );
  611.72 +    }
  611.73 +
  611.74 +    @Test public void isNull() throws Exception {
  611.75 +        assertExec(
  611.76 +            "Yes, we are instance",
  611.77 +            Instance.class, "isNull__Z",
  611.78 +            Double.valueOf(0.0)
  611.79 +        );
  611.80 +    }
  611.81 +
  611.82 +    @Test public void isInstanceOf() throws Exception {
  611.83 +        assertExec(
  611.84 +            "Yes, we are instance",
  611.85 +            Instance.class, "instanceOf__ZI",
  611.86 +            Double.valueOf(1.0), 2
  611.87 +        );
  611.88 +    }
  611.89 +
  611.90 +    @Test public void notInstanceOf() throws Exception {
  611.91 +        assertExec(
  611.92 +            "No, we are not an instance",
  611.93 +            Instance.class, "instanceOf__ZI",
  611.94 +            Double.valueOf(0.0), 1
  611.95 +        );
  611.96 +    }
  611.97 +    @Test public void nullInstanceOf() throws Exception {
  611.98 +        assertExec(
  611.99 +            "No, null is not an instance",
 611.100 +            Instance.class, "instanceOf__ZI",
 611.101 +            Double.valueOf(0.0), 0
 611.102 +        );
 611.103 +    }
 611.104 +    
 611.105 +    @Test public void verifyCastToClass() throws Exception {
 611.106 +        assertExec(
 611.107 +            "Five signals all is good",
 611.108 +            Instance.class, "castsWork__IZ",
 611.109 +            Double.valueOf(5.0), false
 611.110 +        );
 611.111 +    }
 611.112 +    @Test public void verifyCastToInterface() throws Exception {
 611.113 +        assertExec(
 611.114 +            "Five signals all is good",
 611.115 +            Instance.class, "castsWork__IZ",
 611.116 +            Double.valueOf(5.0), true
 611.117 +        );
 611.118 +    }
 611.119 +    
 611.120 +    @Test public void sharedConstructor() throws Exception {
 611.121 +        assertExec(
 611.122 +            "Constructor of first and 2nd instance should be the same",
 611.123 +            Instance.class, "sharedConstructor__Z",
 611.124 +            Double.valueOf(1.0)
 611.125 +        );
 611.126 +    }
 611.127 +
 611.128 +    @Test public void differentConstructor() throws Exception {
 611.129 +        assertExec(
 611.130 +            "Constructor of X and Y should be the different",
 611.131 +            Instance.class, "differentConstructor__Z",
 611.132 +            Double.valueOf(0)
 611.133 +        );
 611.134 +    }
 611.135 +
 611.136 +    @Test public void jsObjectIsLikeJavaObject() throws Exception {
 611.137 +        assertExec(
 611.138 +            "JavaScript object is instance of Java Object",
 611.139 +            Instance.class, "iofObject__Z",
 611.140 +            Double.valueOf(1)
 611.141 +        );
 611.142 +    }
 611.143 +
 611.144 +    @Test public void jsCallingConvention() throws Exception {
 611.145 +        assertExec(
 611.146 +            "Pointer to 'this' is passed automatically (and not as a first argument)",
 611.147 +            Instance.class, "jscall__I",
 611.148 +            Double.valueOf(31)
 611.149 +        );
 611.150 +    }
 611.151 +    
 611.152 +    protected String startCompilationWith() {
 611.153 +        return "org/apidesign/vm4brwsr/Instance";
 611.154 +    }
 611.155 +    
 611.156 +    private static TestVM code;
 611.157 +    
 611.158 +    @BeforeClass
 611.159 +    public void compileTheCode() throws Exception {
 611.160 +        code = TestVM.compileClass(startCompilationWith());
 611.161 +    }
 611.162 +    
 611.163 +    private void assertExec(
 611.164 +        String msg, Class clazz, String method, Object expRes, Object... args
 611.165 +    ) throws Exception {
 611.166 +        code.assertExec(msg, clazz, method, expRes, args);
 611.167 +    }
 611.168 +    
 611.169 +}
   612.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   612.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Wed Feb 27 11:24:58 2013 +0100
   612.3 @@ -0,0 +1,169 @@
   612.4 +/**
   612.5 + * Back 2 Browser Bytecode Translator
   612.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   612.7 + *
   612.8 + * This program is free software: you can redistribute it and/or modify
   612.9 + * it under the terms of the GNU General Public License as published by
  612.10 + * the Free Software Foundation, version 2 of the License.
  612.11 + *
  612.12 + * This program is distributed in the hope that it will be useful,
  612.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  612.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  612.15 + * GNU General Public License for more details.
  612.16 + *
  612.17 + * You should have received a copy of the GNU General Public License
  612.18 + * along with this program. Look for COPYING file in the top folder.
  612.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  612.20 + */
  612.21 +package org.apidesign.vm4brwsr;
  612.22 +
  612.23 +import static org.testng.Assert.*;
  612.24 +import org.testng.annotations.BeforeClass;
  612.25 +import org.testng.annotations.Test;
  612.26 +
  612.27 +/**
  612.28 + *
  612.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  612.30 + */
  612.31 +public class NumberTest {
  612.32 +    @Test public void integerFromString() throws Exception {
  612.33 +        assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2",
  612.34 +            Double.valueOf(333), "333"
  612.35 +        );
  612.36 +    }
  612.37 +
  612.38 +    @Test public void doubleFromString() throws Exception {
  612.39 +        assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2",
  612.40 +            Double.valueOf(33.3), "33.3"
  612.41 +        );
  612.42 +    }
  612.43 +
  612.44 +    @Test public void autoboxDouble() throws Exception {
  612.45 +        assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2",
  612.46 +            "3.3"
  612.47 +        );
  612.48 +    }
  612.49 +    
  612.50 +    @Test public void javalog1000() throws Exception {
  612.51 +        assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3");
  612.52 +    }
  612.53 +
  612.54 +    @Test public void jslog1000() throws Exception {
  612.55 +        assertExec("log_10(1000) == 3", Math.class, "log10__DD", 
  612.56 +            Double.valueOf(3.0), 1000.0
  612.57 +        );
  612.58 +    }
  612.59 +    
  612.60 +    @Test public void javaRem() {
  612.61 +        assertEquals(3, Numbers.rem(303, 10));
  612.62 +    }
  612.63 +    @Test public void jsRem() throws Exception {
  612.64 +        assertExec("Should be three", Numbers.class, "rem__III", 
  612.65 +            Double.valueOf(3.0), 303, 10
  612.66 +        );
  612.67 +    }
  612.68 +    
  612.69 +    @Test public void deserializeInt() throws Exception {
  612.70 +        int exp = Numbers.deserInt();
  612.71 +        assertExec("Should be the same", Numbers.class, "deserInt__I", 
  612.72 +            Double.valueOf(exp)
  612.73 +        );
  612.74 +    }
  612.75 +
  612.76 +    @Test public void deserializeSimpleLong() throws Exception {
  612.77 +        assertExec("Should be 3454", Numbers.class, "deserLong__J_3B", 
  612.78 +            Double.valueOf(3454), 
  612.79 +            new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
  612.80 +        );
  612.81 +    }
  612.82 +    /* XXX: JavaScript cannot represent as big longs as Java. 
  612.83 +    @Test public void deserializeLargeLong() throws Exception {
  612.84 +        final byte[] arr = new byte[] {
  612.85 +            (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
  612.86 +        };
  612.87 +        long exp = Numbers.deserLong(arr);
  612.88 +        assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB", 
  612.89 +            Double.valueOf(exp), arr);
  612.90 +    }
  612.91 +    */
  612.92 +    
  612.93 +    @Test public void deserializeFloatInJava() throws Exception {
  612.94 +        float f = 54324.32423f;
  612.95 +        float r = Numbers.deserFloat();
  612.96 +        assertEquals(r, f, "Floats are the same");
  612.97 +    }
  612.98 +    
  612.99 +    @Test public void deserializeFloatInJS() throws Exception {
 612.100 +        float f = 54324.32423f;
 612.101 +        assertExec("Should be the same", Numbers.class, "deserFloat__F", 
 612.102 +            Double.valueOf(f)
 612.103 +        );
 612.104 +    }
 612.105 +
 612.106 +    @Test public void deserializeDoubleInJava() throws Exception {
 612.107 +        double f = 3.0;
 612.108 +        double r = Numbers.deserDouble();
 612.109 +        assertEquals(r, f, 0.001, "Doubles are the same");
 612.110 +    }
 612.111 +    
 612.112 +    @Test public void deserializeDoubleInJS() throws Exception {
 612.113 +        double f = 3.0;
 612.114 +        assertExec("Should be the same", Numbers.class, "deserDouble__D", f);
 612.115 +    }
 612.116 +    /*
 612.117 +    @Test public void serDouble() throws IOException {
 612.118 +        double f = 3.0;
 612.119 +        ByteArrayOutputStream os = new ByteArrayOutputStream();
 612.120 +        DataOutputStream d = new DataOutputStream(os);
 612.121 +        d.writeLong(3454);
 612.122 +        d.close();
 612.123 +        
 612.124 +        StringBuilder sb = new StringBuilder();
 612.125 +        byte[] arr = os.toByteArray();
 612.126 +        for (int i = 0; i < arr.length; i++) {
 612.127 +            sb.append("(byte)").append(arr[i]).append(", ");
 612.128 +        }
 612.129 +        fail("" + sb);
 612.130 +    }
 612.131 +*/    
 612.132 +    @Test public void fiveInStringJS() throws Exception {
 612.133 +        String s = Numbers.intToString();
 612.134 +        assertExec("Should be the same: " + s, 
 612.135 +            Numbers.class, "intToString__Ljava_lang_String_2", 
 612.136 +            s
 612.137 +        );
 612.138 +    }
 612.139 +
 612.140 +    @Test public void sevenInStringJS() throws Exception {
 612.141 +        String s = Numbers.floatToString();
 612.142 +        assertExec("Should be the same: " + s, 
 612.143 +            Numbers.class, "floatToString__Ljava_lang_String_2", 
 612.144 +            s
 612.145 +        );
 612.146 +    }
 612.147 +
 612.148 +    private static TestVM code;
 612.149 +
 612.150 +    @BeforeClass
 612.151 +    public void compileTheCode() throws Exception {
 612.152 +        code = TestVM.compileClass("org/apidesign/vm4brwsr/Numbers");
 612.153 +    }
 612.154 +
 612.155 +    private static void assertExec(
 612.156 +        String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception
 612.157 +    {
 612.158 +        Object ret = code.execCode(msg, clazz, method, expRes, args);
 612.159 +        if (ret == null) {
 612.160 +            return;
 612.161 +        }
 612.162 +        if (expRes instanceof Double && ret instanceof Double) {
 612.163 +            double expD = ((Double)expRes).doubleValue();
 612.164 +            double retD = ((Double)ret).doubleValue();
 612.165 +            assertEquals(retD, expD, 0.000004, msg + " "
 612.166 +                    + code.toString());
 612.167 +            return;
 612.168 +        }
 612.169 +        assertEquals(ret, expRes, msg + " " + code.toString());
 612.170 +    }
 612.171 +    
 612.172 +}
   613.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   613.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Wed Feb 27 11:24:58 2013 +0100
   613.3 @@ -0,0 +1,70 @@
   613.4 +/**
   613.5 + * Back 2 Browser Bytecode Translator
   613.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   613.7 + *
   613.8 + * This program is free software: you can redistribute it and/or modify
   613.9 + * it under the terms of the GNU General Public License as published by
  613.10 + * the Free Software Foundation, version 2 of the License.
  613.11 + *
  613.12 + * This program is distributed in the hope that it will be useful,
  613.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  613.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  613.15 + * GNU General Public License for more details.
  613.16 + *
  613.17 + * You should have received a copy of the GNU General Public License
  613.18 + * along with this program. Look for COPYING file in the top folder.
  613.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  613.20 + */
  613.21 +package org.apidesign.vm4brwsr;
  613.22 +
  613.23 +import java.io.ByteArrayInputStream;
  613.24 +import java.io.DataInputStream;
  613.25 +import java.io.IOException;
  613.26 +
  613.27 +/**
  613.28 + *
  613.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  613.30 + */
  613.31 +public class Numbers {
  613.32 +    private static Double autoboxDbl() {
  613.33 +        return 3.3;
  613.34 +    }
  613.35 +    public static String autoboxDblToString() {
  613.36 +        return autoboxDbl().toString().toString();
  613.37 +    }
  613.38 +    public static int rem(int a, int b) {
  613.39 +        return a % b;
  613.40 +    }
  613.41 +
  613.42 +    static float deserFloat() throws IOException {
  613.43 +        byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
  613.44 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  613.45 +        DataInputStream dis = new DataInputStream(is);
  613.46 +        float r = dis.readFloat();
  613.47 +        return r;
  613.48 +    }
  613.49 +    static double deserDouble() throws IOException {
  613.50 +        byte[] arr = {(byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
  613.51 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  613.52 +        DataInputStream dis = new DataInputStream(is);
  613.53 +        return dis.readDouble();
  613.54 +    }
  613.55 +    static long deserLong(byte[] arr) throws IOException {
  613.56 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  613.57 +        DataInputStream dis = new DataInputStream(is);
  613.58 +        return dis.readLong();
  613.59 +    }
  613.60 +    static int deserInt() throws IOException {
  613.61 +        byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
  613.62 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  613.63 +        DataInputStream dis = new DataInputStream(is);
  613.64 +        return dis.readInt();
  613.65 +    }
  613.66 +
  613.67 +    static String intToString() {
  613.68 +        return new Integer(5).toString().toString();
  613.69 +    }
  613.70 +    static String floatToString() {
  613.71 +        return new Float(7.0).toString().toString();
  613.72 +    }
  613.73 +}
   614.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   614.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Script.java	Wed Feb 27 11:24:58 2013 +0100
   614.3 @@ -0,0 +1,31 @@
   614.4 +/**
   614.5 + * Back 2 Browser Bytecode Translator
   614.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   614.7 + *
   614.8 + * This program is free software: you can redistribute it and/or modify
   614.9 + * it under the terms of the GNU General Public License as published by
  614.10 + * the Free Software Foundation, version 2 of the License.
  614.11 + *
  614.12 + * This program is distributed in the hope that it will be useful,
  614.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  614.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  614.15 + * GNU General Public License for more details.
  614.16 + *
  614.17 + * You should have received a copy of the GNU General Public License
  614.18 + * along with this program. Look for COPYING file in the top folder.
  614.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  614.20 + */
  614.21 +package org.apidesign.vm4brwsr;
  614.22 +
  614.23 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  614.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  614.25 +
  614.26 +/** Test to verify external scripts are processed in lazy mode.
  614.27 + *
  614.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  614.29 + */
  614.30 +@ExtraJavaScript(resource = "/org/apidesign/vm4brwsr/ko.js")
  614.31 +public class Script {
  614.32 +    @JavaScriptBody(args = {  }, body = "return ko !== null;")
  614.33 +    public static native boolean checkNotNull();
  614.34 +}
   615.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   615.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Wed Feb 27 11:24:58 2013 +0100
   615.3 @@ -0,0 +1,135 @@
   615.4 +/**
   615.5 + * Back 2 Browser Bytecode Translator
   615.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   615.7 + *
   615.8 + * This program is free software: you can redistribute it and/or modify
   615.9 + * it under the terms of the GNU General Public License as published by
  615.10 + * the Free Software Foundation, version 2 of the License.
  615.11 + *
  615.12 + * This program is distributed in the hope that it will be useful,
  615.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  615.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  615.15 + * GNU General Public License for more details.
  615.16 + *
  615.17 + * You should have received a copy of the GNU General Public License
  615.18 + * along with this program. Look for COPYING file in the top folder.
  615.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  615.20 + */
  615.21 +package org.apidesign.vm4brwsr;
  615.22 +
  615.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  615.24 +
  615.25 +/**
  615.26 + *
  615.27 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  615.28 + */
  615.29 +public class StaticMethod {
  615.30 +    private static int cnt;
  615.31 +    private static Object NULL;
  615.32 +
  615.33 +    public static int minusOne() {
  615.34 +        return -1;
  615.35 +    }
  615.36 +    
  615.37 +    public static Object none(int x, int y) {
  615.38 +        Object toRet = null;
  615.39 +        for (int i = x; i < y; i++) {
  615.40 +            if (i == 2) {
  615.41 +                toRet = null;
  615.42 +            } else {
  615.43 +                toRet = new Object();
  615.44 +            }
  615.45 +        }
  615.46 +        return toRet;
  615.47 +    }
  615.48 +    
  615.49 +    public static boolean isNull() {
  615.50 +        return NULL == null;
  615.51 +    }
  615.52 +    
  615.53 +    public static int sum(int x, int y) {
  615.54 +        return x + y;
  615.55 +    }
  615.56 +    public static float power(float x) {
  615.57 +        return x * x;
  615.58 +    }
  615.59 +    public static double minus(double x, long y) {
  615.60 +        return x - y;
  615.61 +    }
  615.62 +    public static int div(byte c, double d) {
  615.63 +        return (int)(d / c);
  615.64 +    }
  615.65 +    public static int mix(int a, long b, byte c, double d) {
  615.66 +        return (int)((b / a + c) * d);
  615.67 +    }
  615.68 +    public static long xor(int a, long b) {
  615.69 +        return a ^ b;
  615.70 +    }
  615.71 +    public static long orOrAnd(boolean doOr, int a, int b) {
  615.72 +        return doOr ? a | b : a & b;
  615.73 +    }
  615.74 +    public static int shiftLeft(int what, int much) {
  615.75 +        return what << much;
  615.76 +    }
  615.77 +    public static int shiftArithmRight(int what, int much, boolean signed) {
  615.78 +        if (signed) {
  615.79 +            return what >> much;
  615.80 +        } else {
  615.81 +            return what >>> much;
  615.82 +        }
  615.83 +    }
  615.84 +    public static long factRec(int n) {
  615.85 +        if (n <= 1) {
  615.86 +            return 1;
  615.87 +        } else {
  615.88 +            return n * factRec(n - 1);
  615.89 +        }
  615.90 +    }
  615.91 +    public static long factIter(int n) {
  615.92 +        long res = 1;
  615.93 +        for (int i = 2; i <= n; i++) {
  615.94 +            res *= i;
  615.95 +        }
  615.96 +        return res;
  615.97 +    }
  615.98 +    public static int inc4() {
  615.99 +        cnt++;
 615.100 +        cnt+=2;
 615.101 +        cnt++;
 615.102 +        return cnt;
 615.103 +    }
 615.104 +    
 615.105 +    @JavaScriptBody(
 615.106 +        args={"i","j"}, body="\n\r\treturn (i + j).toString();"
 615.107 +    )
 615.108 +    public static String i2s(int i, int j) {
 615.109 +        throw new IllegalStateException();
 615.110 +    }
 615.111 +    
 615.112 +    public static String castNull(boolean n) {
 615.113 +        Object value = n ? null : "Ahoj";
 615.114 +        return (String)value;
 615.115 +    }
 615.116 +    
 615.117 +    public static String swtch(int what) {
 615.118 +        switch (what) {
 615.119 +            case 0: return "Jarda";
 615.120 +            case 1: return "Darda";
 615.121 +            case 2: return "Parda";
 615.122 +            default: return "Marda";
 615.123 +        }
 615.124 +    }
 615.125 +    public static String swtch2(int what) {
 615.126 +        switch (what) {
 615.127 +            case 0: return "Jarda";
 615.128 +            case 11: return "Darda";
 615.129 +            case 22: return "Parda";
 615.130 +            default: return "Marda";
 615.131 +        }
 615.132 +    }
 615.133 +    
 615.134 +    static {
 615.135 +        // check order of initializers
 615.136 +        StaticUse.NON_NULL.equals(new Object());
 615.137 +    }
 615.138 +}
   616.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   616.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Wed Feb 27 11:24:58 2013 +0100
   616.3 @@ -0,0 +1,338 @@
   616.4 +/**
   616.5 + * Back 2 Browser Bytecode Translator
   616.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   616.7 + *
   616.8 + * This program is free software: you can redistribute it and/or modify
   616.9 + * it under the terms of the GNU General Public License as published by
  616.10 + * the Free Software Foundation, version 2 of the License.
  616.11 + *
  616.12 + * This program is distributed in the hope that it will be useful,
  616.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  616.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  616.15 + * GNU General Public License for more details.
  616.16 + *
  616.17 + * You should have received a copy of the GNU General Public License
  616.18 + * along with this program. Look for COPYING file in the top folder.
  616.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  616.20 + */
  616.21 +package org.apidesign.vm4brwsr;
  616.22 +
  616.23 +import static org.testng.Assert.*;
  616.24 +import org.testng.annotations.BeforeClass;
  616.25 +import org.testng.annotations.Test;
  616.26 +
  616.27 +/** Checks the basic behavior of the translator.
  616.28 + *
  616.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  616.30 + */
  616.31 +public class StaticMethodTest {
  616.32 +    @Test public void threePlusFour() throws Exception {
  616.33 +        assertExec(
  616.34 +            "Should be seven", 
  616.35 +            StaticMethod.class, "sum__III", 
  616.36 +            Double.valueOf(7), 
  616.37 +            3, 4
  616.38 +        );
  616.39 +    }
  616.40 +
  616.41 +    @Test public void checkReallyInitializedValues() throws Exception {
  616.42 +        assertExec(
  616.43 +            "Return true", 
  616.44 +            StaticMethod.class, "isNull__Z", 
  616.45 +            Double.valueOf(1)
  616.46 +        );
  616.47 +    }
  616.48 +
  616.49 +    @Test public void powerOfThree() throws Exception {
  616.50 +        assertExec(
  616.51 +            "Should be nine", 
  616.52 +            StaticMethod.class, "power__FF", 
  616.53 +            Double.valueOf(9),
  616.54 +            3.0f
  616.55 +        );
  616.56 +    }
  616.57 +
  616.58 +    @Test public void minusOne() throws Exception {
  616.59 +        assertExec(
  616.60 +            "Should be minus one", 
  616.61 +            StaticMethod.class, "minusOne__I", 
  616.62 +            Double.valueOf(-1)
  616.63 +        );
  616.64 +    }
  616.65 +
  616.66 +    @Test public void doubleWithoutLong() throws Exception {
  616.67 +        assertExec(
  616.68 +            "Should be two",
  616.69 +            StaticMethod.class, "minus__DDJ", 
  616.70 +            Double.valueOf(2),
  616.71 +            3.0d, 1l
  616.72 +        );
  616.73 +    }
  616.74 +    
  616.75 +    @Test public void rintNegativeUp() throws Exception {
  616.76 +        final double cnts = -453904.634;
  616.77 +        assertExec(
  616.78 +            "Should round up to end with 5",
  616.79 +            Math.class, "rint__DD", 
  616.80 +            -453905.0, cnts
  616.81 +        );
  616.82 +    }
  616.83 +
  616.84 +    @Test public void rintNegativeDown() throws Exception {
  616.85 +        final double cnts = -453904.434;
  616.86 +        assertExec(
  616.87 +            "Should round up to end with 4",
  616.88 +            Math.class, "rint__DD", 
  616.89 +            -453904.0, cnts
  616.90 +        );
  616.91 +    }
  616.92 +
  616.93 +    @Test public void rintPositiveUp() throws Exception {
  616.94 +        final double cnts = 453904.634;
  616.95 +        assertExec(
  616.96 +            "Should round up to end with 5",
  616.97 +            Math.class, "rint__DD", 
  616.98 +            453905.0, cnts
  616.99 +        );
 616.100 +    }
 616.101 +    @Test public void rintPositiveDown() throws Exception {
 616.102 +        final double cnts = 453904.434;
 616.103 +        assertExec(
 616.104 +            "Should round up to end with 4",
 616.105 +            Math.class, "rint__DD", 
 616.106 +            453904.0, cnts
 616.107 +        );
 616.108 +    }
 616.109 +    @Test public void rintOneHalf() throws Exception {
 616.110 +        final double cnts = 1.5;
 616.111 +        assertExec(
 616.112 +            "Should round up to end with 2",
 616.113 +            Math.class, "rint__DD", 
 616.114 +            2.0, cnts
 616.115 +        );
 616.116 +    }
 616.117 +    @Test public void rintNegativeOneHalf() throws Exception {
 616.118 +        final double cnts = -1.5;
 616.119 +        assertExec(
 616.120 +            "Should round up to end with 2",
 616.121 +            Math.class, "rint__DD", 
 616.122 +            -2.0, cnts
 616.123 +        );
 616.124 +    }
 616.125 +    @Test public void rintTwoAndHalf() throws Exception {
 616.126 +        final double cnts = 2.5;
 616.127 +        assertExec(
 616.128 +            "Should round up to end with 2",
 616.129 +            Math.class, "rint__DD", 
 616.130 +            2.0, cnts
 616.131 +        );
 616.132 +    }
 616.133 +    @Test public void rintNegativeTwoOneHalf() throws Exception {
 616.134 +        final double cnts = -2.5;
 616.135 +        assertExec(
 616.136 +            "Should round up to end with 2",
 616.137 +            Math.class, "rint__DD", 
 616.138 +            -2.0, cnts
 616.139 +        );
 616.140 +    }
 616.141 +
 616.142 +    @Test public void ieeeReminder1() throws Exception {
 616.143 +        assertExec(
 616.144 +            "Same result 1",
 616.145 +            Math.class, "IEEEremainder__DDD", 
 616.146 +            Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
 616.147 +        );
 616.148 +    }
 616.149 +
 616.150 +    @Test public void ieeeReminder2() throws Exception {
 616.151 +        assertExec(
 616.152 +            "Same result 1",
 616.153 +            Math.class, "IEEEremainder__DDD", 
 616.154 +            Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
 616.155 +        );
 616.156 +    }
 616.157 +
 616.158 +    @Test public void divAndRound() throws Exception {
 616.159 +        assertExec(
 616.160 +            "Should be rounded to one",
 616.161 +            StaticMethod.class, "div__IBD", 
 616.162 +            Double.valueOf(1),
 616.163 +            3, 3.75
 616.164 +        );
 616.165 +    }
 616.166 +    @Test public void mixedMethodFourParams() throws Exception {
 616.167 +        assertExec(
 616.168 +            "Should be two",
 616.169 +            StaticMethod.class, "mix__IIJBD", 
 616.170 +            Double.valueOf(20),
 616.171 +            2, 10l, 5, 2.0
 616.172 +        );
 616.173 +    }
 616.174 +    @Test public void factRec() throws Exception {
 616.175 +        assertExec(
 616.176 +            "Factorial of 5 is 120",
 616.177 +            StaticMethod.class, "factRec__JI", 
 616.178 +            Double.valueOf(120),
 616.179 +            5
 616.180 +        );
 616.181 +    }
 616.182 +    @Test public void factIter() throws Exception {
 616.183 +        assertExec(
 616.184 +            "Factorial of 5 is 120",
 616.185 +            StaticMethod.class, "factIter__JI", 
 616.186 +            Double.valueOf(120),
 616.187 +            5
 616.188 +        );
 616.189 +    }
 616.190 +    
 616.191 +    @Test public void xor() throws Exception {
 616.192 +        assertExec(
 616.193 +            "Xor is 4",
 616.194 +            StaticMethod.class, "xor__JIJ",
 616.195 +            Double.valueOf(4),
 616.196 +            7,
 616.197 +            3
 616.198 +        );
 616.199 +    }
 616.200 +    
 616.201 +    @Test public void or() throws Exception {
 616.202 +        assertExec(
 616.203 +            "Or will be 7",
 616.204 +            StaticMethod.class, "orOrAnd__JZII",
 616.205 +            Double.valueOf(7),
 616.206 +            true,
 616.207 +            4,
 616.208 +            3
 616.209 +        );
 616.210 +    }
 616.211 +    @Test public void nullCheck() throws Exception {
 616.212 +        assertExec(
 616.213 +            "Returns nothing",
 616.214 +            StaticMethod.class, "none__Ljava_lang_Object_2II",
 616.215 +            null, 1, 3
 616.216 +        );
 616.217 +    }
 616.218 +    @Test public void and() throws Exception {
 616.219 +        assertExec(
 616.220 +            "And will be 3",
 616.221 +            StaticMethod.class, "orOrAnd__JZII",
 616.222 +            Double.valueOf(3),
 616.223 +            false,
 616.224 +            7,
 616.225 +            3
 616.226 +        );
 616.227 +    }
 616.228 +    @Test public void inc4() throws Exception {
 616.229 +        assertExec(
 616.230 +            "It will be 4",
 616.231 +            StaticMethod.class, "inc4__I",
 616.232 +            Double.valueOf(4)
 616.233 +        );
 616.234 +    }
 616.235 +    
 616.236 +    @Test public void shiftLeftInJava() throws Exception {
 616.237 +        int res = StaticMethod.shiftLeft(1, 8);
 616.238 +        assertEquals(res, 256);
 616.239 +    }
 616.240 +
 616.241 +    @Test public void shiftLeftInJS() throws Exception {
 616.242 +        assertExec(
 616.243 +            "Setting 9th bit",
 616.244 +            StaticMethod.class, "shiftLeft__III",
 616.245 +            Double.valueOf(256),
 616.246 +            1, 8
 616.247 +        );
 616.248 +    }
 616.249 +
 616.250 +    @Test public void shiftRightInJava() throws Exception {
 616.251 +        int res = StaticMethod.shiftArithmRight(-8, 3, true);
 616.252 +        assertEquals(res, -1);
 616.253 +    }
 616.254 +
 616.255 +    @Test public void shiftRightInJS() throws Exception {
 616.256 +        assertExec(
 616.257 +            "Get -1",
 616.258 +            StaticMethod.class, "shiftArithmRight__IIIZ",
 616.259 +            Double.valueOf(-1),
 616.260 +            -8, 3, true
 616.261 +        );
 616.262 +    }
 616.263 +    @Test public void unsignedShiftRightInJava() throws Exception {
 616.264 +        int res = StaticMethod.shiftArithmRight(8, 3, false);
 616.265 +        assertEquals(res, 1);
 616.266 +    }
 616.267 +
 616.268 +    @Test public void unsignedShiftRightInJS() throws Exception {
 616.269 +        assertExec(
 616.270 +            "Get -1",
 616.271 +            StaticMethod.class, "shiftArithmRight__IIIZ",
 616.272 +            Double.valueOf(1),
 616.273 +            8, 3, false
 616.274 +        );
 616.275 +    }
 616.276 +    
 616.277 +    @Test public void javaScriptBody() throws Exception {
 616.278 +        assertExec(
 616.279 +            "JavaScript string",
 616.280 +            StaticMethod.class, "i2s__Ljava_lang_String_2II",
 616.281 +            "333",
 616.282 +            330, 3
 616.283 +        );
 616.284 +    }
 616.285 +    
 616.286 +    @Test public void switchJarda() throws Exception {
 616.287 +        assertExec(
 616.288 +            "The expected value",
 616.289 +            StaticMethod.class, "swtch__Ljava_lang_String_2I",
 616.290 +            "Jarda",
 616.291 +            0
 616.292 +        );
 616.293 +    }
 616.294 +    
 616.295 +    @Test public void switchDarda() throws Exception {
 616.296 +        assertExec(
 616.297 +            "The expected value",
 616.298 +            StaticMethod.class, "swtch__Ljava_lang_String_2I",
 616.299 +            "Darda",
 616.300 +            1
 616.301 +        );
 616.302 +    }
 616.303 +    @Test public void switchParda() throws Exception {
 616.304 +        assertExec(
 616.305 +            "The expected value",
 616.306 +            StaticMethod.class, "swtch2__Ljava_lang_String_2I",
 616.307 +            "Parda",
 616.308 +            22
 616.309 +        );
 616.310 +    }
 616.311 +    @Test public void switchMarda() throws Exception {
 616.312 +        assertExec(
 616.313 +            "The expected value",
 616.314 +            StaticMethod.class, "swtch__Ljava_lang_String_2I",
 616.315 +            "Marda",
 616.316 +            -433
 616.317 +        );
 616.318 +    }
 616.319 +    
 616.320 +    @Test public void checkNullCast() throws Exception {
 616.321 +        assertExec("Null can be cast to any type",
 616.322 +            StaticMethod.class, "castNull__Ljava_lang_String_2Z", 
 616.323 +            null, true
 616.324 +        );
 616.325 +    }
 616.326 +    
 616.327 +    private static TestVM code;
 616.328 +    
 616.329 +    @BeforeClass 
 616.330 +    public void compileTheCode() throws Exception {
 616.331 +        StringBuilder sb = new StringBuilder();
 616.332 +        code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
 616.333 +    }
 616.334 +
 616.335 +    private void assertExec(
 616.336 +        String msg, Class<?> clazz, String method, 
 616.337 +        Object ret, Object... args
 616.338 +    ) throws Exception {
 616.339 +        code.assertExec(msg, clazz, method, ret, args);
 616.340 +    }
 616.341 +}
   617.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   617.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StaticUse.java	Wed Feb 27 11:24:58 2013 +0100
   617.3 @@ -0,0 +1,22 @@
   617.4 +/**
   617.5 + * Back 2 Browser Bytecode Translator
   617.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   617.7 + *
   617.8 + * This program is free software: you can redistribute it and/or modify
   617.9 + * it under the terms of the GNU General Public License as published by
  617.10 + * the Free Software Foundation, version 2 of the License.
  617.11 + *
  617.12 + * This program is distributed in the hope that it will be useful,
  617.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  617.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  617.15 + * GNU General Public License for more details.
  617.16 + *
  617.17 + * You should have received a copy of the GNU General Public License
  617.18 + * along with this program. Look for COPYING file in the top folder.
  617.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  617.20 + */
  617.21 +package org.apidesign.vm4brwsr;
  617.22 +
  617.23 +public class StaticUse {
  617.24 +    public static final Object NON_NULL = new Object();
  617.25 +}
   618.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   618.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StringArrayTest.java	Wed Feb 27 11:24:58 2013 +0100
   618.3 @@ -0,0 +1,50 @@
   618.4 +/**
   618.5 + * Back 2 Browser Bytecode Translator
   618.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   618.7 + *
   618.8 + * This program is free software: you can redistribute it and/or modify
   618.9 + * it under the terms of the GNU General Public License as published by
  618.10 + * the Free Software Foundation, version 2 of the License.
  618.11 + *
  618.12 + * This program is distributed in the hope that it will be useful,
  618.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  618.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  618.15 + * GNU General Public License for more details.
  618.16 + *
  618.17 + * You should have received a copy of the GNU General Public License
  618.18 + * along with this program. Look for COPYING file in the top folder.
  618.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  618.20 + */
  618.21 +package org.apidesign.vm4brwsr;
  618.22 +
  618.23 +import org.testng.annotations.Test;
  618.24 +import static org.testng.Assert.*;
  618.25 +
  618.26 +public class StringArrayTest {
  618.27 +    @Test public void deleteMinusIndex() throws Exception {
  618.28 +        String[] arr = { "Ahoj", "Kluci" };
  618.29 +        StringArray list = StringArray.asList(arr);
  618.30 +        list.delete(-1);
  618.31 +        assertEquals(list.toArray().length, 2, "No element removed");
  618.32 +    }
  618.33 +    @Test public void deleteTooHighIndex() throws Exception {
  618.34 +        String[] arr = { "Ahoj", "Kluci" };
  618.35 +        StringArray list = StringArray.asList(arr);
  618.36 +        list.delete(5);
  618.37 +        assertEquals(list.toArray().length, 2, "No element removed");
  618.38 +    }
  618.39 +    @Test public void deleteFirst() throws Exception {
  618.40 +        String[] arr = { "Ahoj", "Kluci" };
  618.41 +        StringArray list = StringArray.asList(arr);
  618.42 +        list.delete(0);
  618.43 +        assertEquals(list.toArray().length, 1, "First element removed");
  618.44 +        assertEquals(list.toArray()[0], "Kluci");
  618.45 +    }
  618.46 +    @Test public void deleteSecond() throws Exception {
  618.47 +        String[] arr = { "Ahoj", "Kluci" };
  618.48 +        StringArray list = StringArray.asList(arr);
  618.49 +        list.delete(1);
  618.50 +        assertEquals(list.toArray().length, 1, "Second element removed");
  618.51 +        assertEquals(list.toArray()[0], "Ahoj");
  618.52 +    }
  618.53 +}
   619.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   619.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Wed Feb 27 11:24:58 2013 +0100
   619.3 @@ -0,0 +1,132 @@
   619.4 +/**
   619.5 + * Back 2 Browser Bytecode Translator
   619.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   619.7 + *
   619.8 + * This program is free software: you can redistribute it and/or modify
   619.9 + * it under the terms of the GNU General Public License as published by
  619.10 + * the Free Software Foundation, version 2 of the License.
  619.11 + *
  619.12 + * This program is distributed in the hope that it will be useful,
  619.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  619.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  619.15 + * GNU General Public License for more details.
  619.16 + *
  619.17 + * You should have received a copy of the GNU General Public License
  619.18 + * along with this program. Look for COPYING file in the top folder.
  619.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  619.20 + */
  619.21 +package org.apidesign.vm4brwsr;
  619.22 +
  619.23 +import java.io.UnsupportedEncodingException;
  619.24 +
  619.25 +/**
  619.26 + *
  619.27 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  619.28 + */
  619.29 +public class StringSample {
  619.30 +    public static final String HELLO = "Hello World!";
  619.31 +    private static int counter;
  619.32 +    
  619.33 +    private final int cnt;
  619.34 +    public StringSample() {
  619.35 +        cnt = ++counter;
  619.36 +    }
  619.37 +    
  619.38 +    
  619.39 +    public static char sayHello(int indx) {
  619.40 +        return HELLO.charAt(indx);
  619.41 +    }
  619.42 +    
  619.43 +    public static boolean equalToHello(int from, int to) {
  619.44 +        return "Hello".equals(HELLO.substring(from, to));
  619.45 +    }
  619.46 +    
  619.47 +    public static String fromChars(char a, char b, char c) {
  619.48 +        char[] arr = { a, b, c };
  619.49 +        return new String(arr).toString();
  619.50 +    }
  619.51 +    
  619.52 +    public static String charsFromNumbers() {
  619.53 +        return chars((char)65, (char)66, (char)67);
  619.54 +    }
  619.55 +
  619.56 +    public static String charsFromChars() {
  619.57 +        return chars('A', 'B', 'C');
  619.58 +    }
  619.59 +
  619.60 +    public static String chars(char a, char b, char c) {
  619.61 +        return ("" + a + b +c).toString();
  619.62 +    }
  619.63 +    
  619.64 +    public static String replace(String s, char a, char b) {
  619.65 +        return s.replace(a, b);
  619.66 +    }
  619.67 +    
  619.68 +    public static int hashCode(String h) {
  619.69 +        return h.hashCode();
  619.70 +    }
  619.71 +    
  619.72 +    public static boolean isStringInstance() {
  619.73 +        return chars('a', (char)30, 'b') instanceof String;
  619.74 +    }
  619.75 +    
  619.76 +    public static String getBytes(String s) throws UnsupportedEncodingException {
  619.77 +        byte[] arr = s.getBytes("UTF-8");
  619.78 +        StringBuilder sb = new StringBuilder();
  619.79 +        for (int i = 0; i < arr.length; i++) {
  619.80 +            sb.append(arr[i]).append(" ");
  619.81 +        }
  619.82 +        return sb.toString().toString();
  619.83 +    }
  619.84 +    
  619.85 +    public static String insertBuffer() {
  619.86 +        StringBuilder sb = new StringBuilder();
  619.87 +        sb.append("Jardo!");
  619.88 +        sb.insert(0, "Ahoj ");
  619.89 +        sb.delete(4, 8);
  619.90 +        return sb.toString().toString();
  619.91 +    }
  619.92 +    
  619.93 +    public static int countAB(String txt) {
  619.94 +        int cnt = 0;
  619.95 +        for (int i = 0; i < txt.length(); i++) {
  619.96 +            switch (txt.charAt(i)) {
  619.97 +                case 'A': cnt++; break;
  619.98 +                case 'B': cnt += 2; break;
  619.99 +            }
 619.100 +        }
 619.101 +        return cnt;
 619.102 +    }
 619.103 +
 619.104 +    public static int stringSwitch(String txt) {
 619.105 +        switch (txt) {
 619.106 +            case "jedna": return 1;
 619.107 +            case "dve": return 2;
 619.108 +            case "tri": return 3;
 619.109 +            case "ctyri": return 4;
 619.110 +        }
 619.111 +        return -1;
 619.112 +    }
 619.113 +    
 619.114 +    public static String toStringTest(int howMuch) {
 619.115 +        counter = 0;
 619.116 +        StringSample ss = null;
 619.117 +        for (int i = 0; i < howMuch; i++) {
 619.118 +            ss = new StringSample();
 619.119 +        }
 619.120 +        return ss.toString().toString();
 619.121 +    }
 619.122 +    
 619.123 +    public static String concatStrings() {
 619.124 +        return (toStringTest(1) + "\\\n\r\t").toString();
 619.125 +    }
 619.126 +    
 619.127 +    public static int compare(String a, String b) {
 619.128 +        return a.compareTo(b);
 619.129 +    }
 619.130 +
 619.131 +    @Override
 619.132 +    public String toString() {
 619.133 +        return HELLO + cnt;
 619.134 +    }
 619.135 +}
   620.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   620.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Wed Feb 27 11:24:58 2013 +0100
   620.3 @@ -0,0 +1,212 @@
   620.4 +/**
   620.5 + * Back 2 Browser Bytecode Translator
   620.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   620.7 + *
   620.8 + * This program is free software: you can redistribute it and/or modify
   620.9 + * it under the terms of the GNU General Public License as published by
  620.10 + * the Free Software Foundation, version 2 of the License.
  620.11 + *
  620.12 + * This program is distributed in the hope that it will be useful,
  620.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  620.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  620.15 + * GNU General Public License for more details.
  620.16 + *
  620.17 + * You should have received a copy of the GNU General Public License
  620.18 + * along with this program. Look for COPYING file in the top folder.
  620.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  620.20 + */
  620.21 +package org.apidesign.vm4brwsr;
  620.22 +
  620.23 +import org.testng.annotations.Test;
  620.24 +import static org.testng.Assert.*;
  620.25 +import org.testng.annotations.BeforeClass;
  620.26 +
  620.27 +/**
  620.28 + *
  620.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  620.30 + */
  620.31 +public class StringTest {
  620.32 +    @Test public void firstChar() throws Exception {
  620.33 +        assertExec(
  620.34 +            "First char in Hello is H",
  620.35 +            StringSample.class, "sayHello__CI",
  620.36 +            72, 0
  620.37 +        );
  620.38 +    }
  620.39 +
  620.40 +    @Test public void fromChars() throws Exception {
  620.41 +        assertExec(
  620.42 +            "First char in Hello is ABC",
  620.43 +            StringSample.class, "fromChars__Ljava_lang_String_2CCC",
  620.44 +            "ABC", 'A', 'B', 'C'
  620.45 +        );
  620.46 +    }
  620.47 +
  620.48 +    @Test public void concatChars() throws Exception {
  620.49 +        assertExec(
  620.50 +            "Composing yields ABC",
  620.51 +            StringSample.class, "chars__Ljava_lang_String_2CCC",
  620.52 +            "ABC", 'A', 'B', 'C'
  620.53 +        );
  620.54 +    }
  620.55 +
  620.56 +    @Test public void concatCharsFromInts() throws Exception {
  620.57 +        assertExec(
  620.58 +            "Composing yields ABC",
  620.59 +            StringSample.class, "charsFromNumbers__Ljava_lang_String_2",
  620.60 +            "ABC"
  620.61 +        );
  620.62 +    }
  620.63 +
  620.64 +    @Test public void concatCharsFromChars() throws Exception {
  620.65 +        assertExec(
  620.66 +            "Composing yields ABC",
  620.67 +            StringSample.class, "charsFromChars__Ljava_lang_String_2",
  620.68 +            "ABC"
  620.69 +        );
  620.70 +    }
  620.71 +
  620.72 +    @Test public void instanceOfWorks() throws Exception {
  620.73 +        assertExec(
  620.74 +            "It is string",
  620.75 +            StringSample.class, "isStringInstance__Z",
  620.76 +            Double.valueOf(1.0)
  620.77 +        );
  620.78 +    }
  620.79 +
  620.80 +    @Test public void getBytes() throws Exception {
  620.81 +        final String horse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148";
  620.82 +        final String expected = StringSample.getBytes(horse);
  620.83 +        assertExec(
  620.84 +            "Bytes look simplar",
  620.85 +            StringSample.class, "getBytes__Ljava_lang_String_2Ljava_lang_String_2",
  620.86 +            expected, horse
  620.87 +        );
  620.88 +    }
  620.89 +
  620.90 +    @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
  620.91 +        assertExec(
  620.92 +            "Five executions should generate 5Hello World!",
  620.93 +            StringSample.class, "toStringTest__Ljava_lang_String_2I",
  620.94 +            "Hello World!5", 5
  620.95 +        );
  620.96 +    }
  620.97 +    @Test public void toStringConcatenationJava() throws Exception {
  620.98 +        assertEquals("Hello World!5", StringSample.toStringTest(5));
  620.99 +    }
 620.100 +    
 620.101 +    @Test(timeOut=10000) public void stringStringConcat() throws Exception {
 620.102 +        assertExec(
 620.103 +            "Composes strings OK",
 620.104 +            StringSample.class, "concatStrings__Ljava_lang_String_2",
 620.105 +            "Hello World!1" + "\\\n\r\t"
 620.106 +        );
 620.107 +    }
 620.108 +
 620.109 +    @Test public void equalsAndSubstring() throws Exception {
 620.110 +        assertExec(
 620.111 +            "Composes are OK",
 620.112 +            StringSample.class, "equalToHello__ZII",
 620.113 +            true, 0, 5
 620.114 +        );
 620.115 +    }
 620.116 +    @Test public void replaceChars() throws Exception {
 620.117 +        assertExec(
 620.118 +            "Can replace slashes by underscores",
 620.119 +            StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
 620.120 +            "x_y_z", "x/y/z", '/', '_'
 620.121 +        );
 620.122 +    }
 620.123 +    @Test public void replaceIntChars() throws Exception {
 620.124 +        assertExec(
 620.125 +            "Can replace slashes by underscores",
 620.126 +            StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
 620.127 +            "x_y_z", "x/y/z", (int)'/', (int)'_'
 620.128 +        );
 620.129 +    }
 620.130 +
 620.131 +    @Test public void insertBuilder() throws Exception {
 620.132 +        assertExec(
 620.133 +            "Can insert something into a buffer?",
 620.134 +            StringSample.class, "insertBuffer__Ljava_lang_String_2",
 620.135 +            "Ahojdo!"
 620.136 +        );
 620.137 +    }
 620.138 +    
 620.139 +    @Test public void compareHashCodeHi() throws Exception {
 620.140 +        String j = "Hi";
 620.141 +        int jh = StringSample.hashCode(j);
 620.142 +        assertExec(
 620.143 +            "Hashcode is the same " +jh,
 620.144 +            StringSample.class, "hashCode__ILjava_lang_String_2",
 620.145 +            Double.valueOf(jh), j
 620.146 +        );
 620.147 +    }
 620.148 +    @Test public void compareHashCode1() throws Exception {
 620.149 +        String j = "Hello Java!";
 620.150 +        int jh = StringSample.hashCode(j);
 620.151 +        assertExec(
 620.152 +            "Hashcode is the same " + jh,
 620.153 +            StringSample.class, "hashCode__ILjava_lang_String_2",
 620.154 +            Double.valueOf(jh), j
 620.155 +        );
 620.156 +    }
 620.157 +    @Test public void stringSwitch1() throws Exception {
 620.158 +        assertExec(
 620.159 +            "Get one",
 620.160 +            StringSample.class, "stringSwitch__ILjava_lang_String_2",
 620.161 +            Double.valueOf(1), "jedna"
 620.162 +        );
 620.163 +    }
 620.164 +    @Test public void stringSwitch2() throws Exception {
 620.165 +        assertExec(
 620.166 +            "Get two",
 620.167 +            StringSample.class, "stringSwitch__ILjava_lang_String_2",
 620.168 +            Double.valueOf(2), "dve"
 620.169 +        );
 620.170 +    }
 620.171 +    @Test public void stringSwitchDefault() throws Exception {
 620.172 +        assertExec(
 620.173 +            "Get -1",
 620.174 +            StringSample.class, "stringSwitch__ILjava_lang_String_2",
 620.175 +            Double.valueOf(-1), "none"
 620.176 +        );
 620.177 +    }
 620.178 +    
 620.179 +    @Test public void countAB() throws Exception {
 620.180 +        assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
 620.181 +        assertExec(
 620.182 +            "One A and one B adds to 3",
 620.183 +            StringSample.class, "countAB__ILjava_lang_String_2",
 620.184 +            Double.valueOf(3), "Ahoj Bedo!"
 620.185 +        );
 620.186 +        
 620.187 +    }
 620.188 +
 620.189 +    @Test public void compareStrings() throws Exception {
 620.190 +        int res = StringSample.compare("Saab", "Volvo");
 620.191 +        assertExec(
 620.192 +            "Saab finished sooner than Volvo",
 620.193 +            StringSample.class, "compare__ILjava_lang_String_2Ljava_lang_String_2",
 620.194 +            Double.valueOf(res), "Saab", "Volvo"
 620.195 +        );
 620.196 +        
 620.197 +    }
 620.198 +    
 620.199 +    private static TestVM code;
 620.200 +    
 620.201 +    @BeforeClass 
 620.202 +    public void compileTheCode() throws Exception {
 620.203 +        code = TestVM.compileClass(
 620.204 +            "org/apidesign/vm4brwsr/StringSample",
 620.205 +            "java/lang/String"
 620.206 +        );
 620.207 +    }
 620.208 +    
 620.209 +    private static void assertExec(String msg, 
 620.210 +        Class<?> clazz, String method, Object expRes, Object... args
 620.211 +    ) throws Exception {
 620.212 +        code.assertExec(msg, clazz, method, expRes, args);
 620.213 +    }
 620.214 +    
 620.215 +}
   621.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   621.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java	Wed Feb 27 11:24:58 2013 +0100
   621.3 @@ -0,0 +1,56 @@
   621.4 +/**
   621.5 + * Back 2 Browser Bytecode Translator
   621.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   621.7 + *
   621.8 + * This program is free software: you can redistribute it and/or modify
   621.9 + * it under the terms of the GNU General Public License as published by
  621.10 + * the Free Software Foundation, version 2 of the License.
  621.11 + *
  621.12 + * This program is distributed in the hope that it will be useful,
  621.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  621.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  621.15 + * GNU General Public License for more details.
  621.16 + *
  621.17 + * You should have received a copy of the GNU General Public License
  621.18 + * along with this program. Look for COPYING file in the top folder.
  621.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  621.20 + */
  621.21 +package org.apidesign.vm4brwsr;
  621.22 +
  621.23 +import org.testng.annotations.BeforeClass;
  621.24 +import static org.testng.Assert.*;
  621.25 +import org.testng.annotations.Test;
  621.26 +
  621.27 +/**
  621.28 + *
  621.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  621.30 + */
  621.31 +public class SystemTest {
  621.32 +    private static TestVM code;
  621.33 +    
  621.34 +    @Test public void verifyJSTime() throws Exception {
  621.35 +        long now = System.currentTimeMillis();
  621.36 +        
  621.37 +        Object js = code.execCode("Get js time", 
  621.38 +            org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillisDouble__D",
  621.39 +            null
  621.40 +        );
  621.41 +        
  621.42 +        assertTrue(js instanceof Double, "Double " + js);
  621.43 +        long time = ((Double)js).longValue();
  621.44 +        
  621.45 +        long later = System.currentTimeMillis();
  621.46 +        
  621.47 +        assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
  621.48 +        assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
  621.49 +    }
  621.50 +    
  621.51 +    
  621.52 +    @BeforeClass 
  621.53 +    public static void compileTheCode() throws Exception {
  621.54 +        code = TestVM.compileClass(
  621.55 +            "org/apidesign/bck2brwsr/emul/lang/System");
  621.56 +    }
  621.57 +    
  621.58 +}
  621.59 +
   622.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   622.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java	Wed Feb 27 11:24:58 2013 +0100
   622.3 @@ -0,0 +1,170 @@
   622.4 +/**
   622.5 + * Back 2 Browser Bytecode Translator
   622.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   622.7 + *
   622.8 + * This program is free software: you can redistribute it and/or modify
   622.9 + * it under the terms of the GNU General Public License as published by
  622.10 + * the Free Software Foundation, version 2 of the License.
  622.11 + *
  622.12 + * This program is distributed in the hope that it will be useful,
  622.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  622.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  622.15 + * GNU General Public License for more details.
  622.16 + *
  622.17 + * You should have received a copy of the GNU General Public License
  622.18 + * along with this program. Look for COPYING file in the top folder.
  622.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  622.20 + */
  622.21 +package org.apidesign.vm4brwsr;
  622.22 +
  622.23 +import java.io.File;
  622.24 +import java.io.FileWriter;
  622.25 +import java.io.IOException;
  622.26 +import java.io.InputStream;
  622.27 +import java.net.URL;
  622.28 +import java.util.Enumeration;
  622.29 +import javax.script.Invocable;
  622.30 +import javax.script.ScriptEngine;
  622.31 +import javax.script.ScriptEngineManager;
  622.32 +import javax.script.ScriptException;
  622.33 +import static org.testng.Assert.*;
  622.34 +
  622.35 +final class TestVM {
  622.36 +    private final Invocable code;
  622.37 +    private final CharSequence codeSeq;
  622.38 +    private final Object bck2brwsr;
  622.39 +    
  622.40 +    
  622.41 +    private TestVM(Invocable code, CharSequence codeSeq) throws ScriptException, NoSuchMethodException {
  622.42 +        this.code = code;
  622.43 +        this.codeSeq = codeSeq;
  622.44 +        this.bck2brwsr = code.invokeFunction("bck2brwsr");
  622.45 +    }
  622.46 +    
  622.47 +
  622.48 +    public Object execCode(
  622.49 +        String msg, Class<?> clazz, String method, 
  622.50 +        Object expRes, Object... args
  622.51 +    ) throws Exception {
  622.52 +        Object ret = null;
  622.53 +        try {
  622.54 +            ret = code.invokeMethod(bck2brwsr, "loadClass", clazz.getName());
  622.55 +            ret = code.invokeMethod(ret, method, args);
  622.56 +        } catch (ScriptException ex) {
  622.57 +            fail("Execution failed in " + dumpJS(codeSeq), ex);
  622.58 +        } catch (NoSuchMethodException ex) {
  622.59 +            fail("Cannot find method in " + dumpJS(codeSeq), ex);
  622.60 +        }
  622.61 +        if (ret == null && expRes == null) {
  622.62 +            return null;
  622.63 +        }
  622.64 +        if (expRes != null && expRes.equals(ret)) {
  622.65 +            return null;
  622.66 +        }
  622.67 +        if (expRes instanceof Number) {
  622.68 +            // in case of Long it is necessary convert it to number
  622.69 +            // since the Long is represented by two numbers in JavaScript
  622.70 +            try {
  622.71 +                ret = code.invokeMethod(ret, "toFP");
  622.72 +                ret = code.invokeFunction("Number", ret);
  622.73 +            } catch (ScriptException ex) {
  622.74 +                fail("Conversion to number failed in " + dumpJS(codeSeq), ex);
  622.75 +            } catch (NoSuchMethodException ex) {
  622.76 +                fail("Cannot find global Number(x) function in " + dumpJS(codeSeq), ex);
  622.77 +            }
  622.78 +        }
  622.79 +        return ret;
  622.80 +    }
  622.81 +    
  622.82 +    void assertExec(
  622.83 +        String msg, Class clazz, String method, Object expRes, Object... args
  622.84 +    ) throws Exception {
  622.85 +        Object ret = execCode(msg, clazz, method, expRes, args);
  622.86 +        if (ret == null) {
  622.87 +            return;
  622.88 +        }
  622.89 +        if (expRes != null && expRes.equals(ret)) {
  622.90 +            return;
  622.91 +        }
  622.92 +        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + dumpJS(codeSeq));
  622.93 +    }    
  622.94 +
  622.95 +    static TestVM compileClass(String... names) throws ScriptException, IOException {
  622.96 +        return compileClass(null, names);
  622.97 +    }
  622.98 +    
  622.99 +    static TestVM compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
 622.100 +        return compileClass(sb, null, names);
 622.101 +    }
 622.102 +
 622.103 +    static TestVM compileClass(StringBuilder sb, ScriptEngine[] eng, String... names) throws ScriptException, IOException {
 622.104 +        if (sb == null) {
 622.105 +            sb = new StringBuilder();
 622.106 +        }
 622.107 +        Bck2Brwsr.generate(sb, new EmulationResources(), names);
 622.108 +        ScriptEngineManager sem = new ScriptEngineManager();
 622.109 +        ScriptEngine js = sem.getEngineByExtension("js");
 622.110 +        if (eng != null) {
 622.111 +            eng[0] = js;
 622.112 +        }
 622.113 +        try {
 622.114 +            Object res = js.eval(sb.toString());
 622.115 +            assertTrue(js instanceof Invocable, "It is invocable object: " + res);
 622.116 +            return new TestVM((Invocable) js, sb);
 622.117 +        } catch (Exception ex) {
 622.118 +            if (sb.length() > 2000) {
 622.119 +                sb = dumpJS(sb);
 622.120 +            }
 622.121 +            fail("Could not evaluate:\n" + sb, ex);
 622.122 +            return null;
 622.123 +        }
 622.124 +    }
 622.125 +
 622.126 +    Object loadClass(String loadClass, String name) throws ScriptException, NoSuchMethodException {
 622.127 +        return code.invokeMethod(bck2brwsr, "loadClass", Exceptions.class.getName());
 622.128 +    }
 622.129 +    
 622.130 +    Object invokeMethod(Object obj, String method, Object... params) throws ScriptException, NoSuchMethodException {
 622.131 +        return code.invokeMethod(obj, method, params);
 622.132 +    }
 622.133 +
 622.134 +    Object invokeFunction(String methodName, Object... args) throws ScriptException, NoSuchMethodException {
 622.135 +        return code.invokeFunction(methodName, args);
 622.136 +    }
 622.137 +
 622.138 +    static StringBuilder dumpJS(CharSequence sb) throws IOException {
 622.139 +        File f = File.createTempFile("execution", ".js");
 622.140 +        FileWriter w = new FileWriter(f);
 622.141 +        w.append(sb);
 622.142 +        w.close();
 622.143 +        return new StringBuilder(f.getPath());
 622.144 +    }
 622.145 +
 622.146 +    @Override
 622.147 +    public String toString() {
 622.148 +        try {
 622.149 +            return dumpJS(codeSeq).toString();
 622.150 +        } catch (IOException ex) {
 622.151 +            return ex.toString();
 622.152 +        }
 622.153 +    }
 622.154 +    
 622.155 +    
 622.156 +    private static class EmulationResources implements Bck2Brwsr.Resources {
 622.157 +        @Override
 622.158 +        public InputStream get(String name) throws IOException {
 622.159 +            Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
 622.160 +            URL u = null;
 622.161 +            while (en.hasMoreElements()) {
 622.162 +                u = en.nextElement();
 622.163 +            }
 622.164 +            if (u == null) {
 622.165 +                throw new IOException("Can't find " + name);
 622.166 +            }
 622.167 +            if (u.toExternalForm().contains("rt.jar!")) {
 622.168 +                throw new IOException("No emulation for " + u);
 622.169 +            }
 622.170 +            return u.openStream();
 622.171 +        }
 622.172 +    }
 622.173 +}
   623.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   623.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Wed Feb 27 11:24:58 2013 +0100
   623.3 @@ -0,0 +1,93 @@
   623.4 +/**
   623.5 + * Back 2 Browser Bytecode Translator
   623.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   623.7 + *
   623.8 + * This program is free software: you can redistribute it and/or modify
   623.9 + * it under the terms of the GNU General Public License as published by
  623.10 + * the Free Software Foundation, version 2 of the License.
  623.11 + *
  623.12 + * This program is distributed in the hope that it will be useful,
  623.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  623.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  623.15 + * GNU General Public License for more details.
  623.16 + *
  623.17 + * You should have received a copy of the GNU General Public License
  623.18 + * along with this program. Look for COPYING file in the top folder.
  623.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  623.20 + */
  623.21 +package org.apidesign.vm4brwsr;
  623.22 +
  623.23 +import javax.script.ScriptContext;
  623.24 +import javax.script.ScriptEngine;
  623.25 +import javax.script.ScriptException;
  623.26 +import org.testng.annotations.BeforeClass;
  623.27 +import static org.testng.Assert.*;
  623.28 +import org.testng.annotations.Test;
  623.29 +
  623.30 +/** Implements loading class by class.
  623.31 + *
  623.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  623.33 + */
  623.34 +public class VMLazyTest {
  623.35 +    private static TestVM code;
  623.36 +
  623.37 +    @BeforeClass
  623.38 +    public void compileTheCode() throws Exception {
  623.39 +        StringBuilder sb = new StringBuilder();
  623.40 +        sb.append("\nvar data = {};");
  623.41 +        sb.append("\nfunction test(clazz, method) {");
  623.42 +        sb.append("\n  if (!data.bck2brwsr) data.bck2brwsr = bck2brwsr(function(name) { return loader.get(name); });");
  623.43 +        sb.append("\n  var c = data.bck2brwsr.loadClass(clazz);");
  623.44 +        sb.append("\n  return c[method]();");
  623.45 +        sb.append("\n}");
  623.46 +        
  623.47 +        sb.append("\nfunction checkKO() {");
  623.48 +        sb.append("\n  return ko !== null;");
  623.49 +        sb.append("\n}");
  623.50 +       
  623.51 +        ScriptEngine[] arr = { null };
  623.52 +        code = TestVM.compileClass(sb, arr,
  623.53 +            new String[]{"org/apidesign/vm4brwsr/VM", "org/apidesign/vm4brwsr/StaticMethod"}
  623.54 +        );
  623.55 +        arr[0].getContext().setAttribute("loader", new BytesLoader(), ScriptContext.ENGINE_SCOPE);
  623.56 +    }
  623.57 +    
  623.58 +    @Test public void invokeStaticMethod() throws Exception {
  623.59 +        assertExec("Trying to get -1", "test", Double.valueOf(-1),
  623.60 +            StaticMethod.class.getName(), "minusOne__I"
  623.61 +        );
  623.62 +    }
  623.63 +
  623.64 +    @Test public void loadDependantClass() throws Exception {
  623.65 +        assertExec("Expecting zero", "test", Double.valueOf(0),
  623.66 +            InstanceSub.class.getName(), "recallDbl__D"
  623.67 +        );
  623.68 +    }
  623.69 +
  623.70 +    @Test public void loadClassWithAssociatedScript() throws Exception {
  623.71 +        assertExec("ko is defined", "test", true,
  623.72 +            Script.class.getName(), "checkNotNull__Z"
  623.73 +        );
  623.74 +        
  623.75 +        Object res = code.invokeFunction("checkKO");
  623.76 +        assertEquals(res, true, "KO is defined on a global level");
  623.77 +    }
  623.78 +
  623.79 +    private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
  623.80 +        Object ret = null;
  623.81 +        try {
  623.82 +            ret = code.invokeFunction(methodName, args);
  623.83 +        } catch (ScriptException ex) {
  623.84 +            fail("Execution failed in\n" + code.toString(), ex);
  623.85 +        } catch (NoSuchMethodException ex) {
  623.86 +            fail("Cannot find method in\n" + code.toString(), ex);
  623.87 +        }
  623.88 +        if (ret == null && expRes == null) {
  623.89 +            return;
  623.90 +        }
  623.91 +        if (expRes.equals(ret)) {
  623.92 +            return;
  623.93 +        }
  623.94 +        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + code.toString());
  623.95 +    }
  623.96 +}
   624.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   624.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/VMinVM.java	Wed Feb 27 11:24:58 2013 +0100
   624.3 @@ -0,0 +1,46 @@
   624.4 +/**
   624.5 + * Back 2 Browser Bytecode Translator
   624.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   624.7 + *
   624.8 + * This program is free software: you can redistribute it and/or modify
   624.9 + * it under the terms of the GNU General Public License as published by
  624.10 + * the Free Software Foundation, version 2 of the License.
  624.11 + *
  624.12 + * This program is distributed in the hope that it will be useful,
  624.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  624.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  624.15 + * GNU General Public License for more details.
  624.16 + *
  624.17 + * You should have received a copy of the GNU General Public License
  624.18 + * along with this program. Look for COPYING file in the top folder.
  624.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  624.20 + */
  624.21 +package org.apidesign.vm4brwsr;
  624.22 +
  624.23 +import java.io.ByteArrayInputStream;
  624.24 +import java.io.IOException;
  624.25 +
  624.26 +/**
  624.27 + *
  624.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  624.29 + */
  624.30 +class VMinVM extends ByteCodeToJavaScript {
  624.31 +    private VMinVM(Appendable out) {
  624.32 +        super(out);
  624.33 +    }
  624.34 +    
  624.35 +    static String toJavaScript(byte[] is) throws IOException {
  624.36 +        StringBuilder sb = new StringBuilder();
  624.37 +        new VMinVM(sb).compile(new ByteArrayInputStream(is));
  624.38 +        return sb.toString().toString();
  624.39 +    }
  624.40 +
  624.41 +    @Override
  624.42 +    protected boolean requireReference(String internalClassName) {
  624.43 +        return false;
  624.44 +    }
  624.45 +
  624.46 +    @Override
  624.47 +    protected void requireScript(String resourcePath) {
  624.48 +    }
  624.49 +}
   625.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   625.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Wed Feb 27 11:24:58 2013 +0100
   625.3 @@ -0,0 +1,87 @@
   625.4 +/**
   625.5 + * Back 2 Browser Bytecode Translator
   625.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   625.7 + *
   625.8 + * This program is free software: you can redistribute it and/or modify
   625.9 + * it under the terms of the GNU General Public License as published by
  625.10 + * the Free Software Foundation, version 2 of the License.
  625.11 + *
  625.12 + * This program is distributed in the hope that it will be useful,
  625.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  625.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  625.15 + * GNU General Public License for more details.
  625.16 + *
  625.17 + * You should have received a copy of the GNU General Public License
  625.18 + * along with this program. Look for COPYING file in the top folder.
  625.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  625.20 + */
  625.21 +package org.apidesign.vm4brwsr;
  625.22 +
  625.23 +import java.io.File;
  625.24 +import java.io.FileWriter;
  625.25 +import java.io.IOException;
  625.26 +import static org.testng.Assert.*;
  625.27 +import org.testng.annotations.BeforeClass;
  625.28 +import org.testng.annotations.Test;
  625.29 +
  625.30 +/**
  625.31 + *
  625.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  625.33 + */
  625.34 +public class VMinVMTest {
  625.35 +    private static TestVM code;
  625.36 +    
  625.37 +    @Test public void compareGeneratedCodeForArrayClass() throws Exception {
  625.38 +        compareCode("org/apidesign/vm4brwsr/Array.class");
  625.39 +    }
  625.40 +
  625.41 +    @Test public void compareGeneratedCodeForClassesClass() throws Exception {
  625.42 +        compareCode("org/apidesign/vm4brwsr/Classes.class");
  625.43 +    }
  625.44 +
  625.45 +    @BeforeClass
  625.46 +    public void compileTheCode() throws Exception {
  625.47 +        code = TestVM.compileClass("org/apidesign/vm4brwsr/VMinVM");
  625.48 +    }
  625.49 +    
  625.50 +    private void compareCode(final String nm) throws Exception, IOException {
  625.51 +        byte[] arr = BytesLoader.readClass(nm);
  625.52 +        String ret1 = VMinVM.toJavaScript(arr);
  625.53 +        
  625.54 +        Object ret;
  625.55 +        try {
  625.56 +            ret = code.invokeFunction("bck2brwsr");
  625.57 +            ret = code.invokeMethod(ret, "loadClass", VMinVM.class.getName());
  625.58 +            ret = code.invokeMethod(ret, "toJavaScript__Ljava_lang_String_2_3B", arr);
  625.59 +        } catch (Exception ex) {
  625.60 +            File f = File.createTempFile("execution", ".js");
  625.61 +            FileWriter w = new FileWriter(f);
  625.62 +            w.append("var byteCode = [\n  ");
  625.63 +            String sep = "";
  625.64 +            for (int i = 0; i < arr.length; i++) {
  625.65 +                w.append(sep).append(Integer.toString((arr[i] + 256) % 256));
  625.66 +                sep = ", ";
  625.67 +                if (i % 20 == 0) {
  625.68 +                    w.append("\n  ");
  625.69 +                }
  625.70 +            }
  625.71 +            w.append("\n];\n");
  625.72 +            w.append(code.toString());
  625.73 +            w.close();
  625.74 +            throw new Exception(ex.getMessage() + " file: " + f, ex);
  625.75 +        }
  625.76 +
  625.77 +        
  625.78 +        assertTrue(ret instanceof String, "It is string: " + ret);
  625.79 +        
  625.80 +        if (!ret1.toString().equals(ret)) {
  625.81 +            StringBuilder msg = new StringBuilder("Difference found between ");
  625.82 +            msg.append(TestVM.dumpJS(ret1));
  625.83 +            msg.append(" ");
  625.84 +            msg.append(TestVM.dumpJS((CharSequence) ret));
  625.85 +            msg.append(" compiled by ");
  625.86 +            msg.append(code.toString());
  625.87 +            fail(msg.toString());
  625.88 +        }
  625.89 +    }
  625.90 +}
   626.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   626.2 +++ b/rt/vm/src/test/resources/org/apidesign/vm4brwsr/ko.js	Wed Feb 27 11:24:58 2013 +0100
   626.3 @@ -0,0 +1,20 @@
   626.4 +/*
   626.5 + * Back 2 Browser Bytecode Translator
   626.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   626.7 + *
   626.8 + * This program is free software: you can redistribute it and/or modify
   626.9 + * it under the terms of the GNU General Public License as published by
  626.10 + * the Free Software Foundation, version 2 of the License.
  626.11 + *
  626.12 + * This program is distributed in the hope that it will be useful,
  626.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  626.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  626.15 + * GNU General Public License for more details.
  626.16 + *
  626.17 + * You should have received a copy of the GNU General Public License
  626.18 + * along with this program. Look for COPYING file in the top folder.
  626.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  626.20 + */
  626.21 +this.ko = {};
  626.22 +
  626.23 +
   627.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   627.2 +++ b/rt/vmtest/pom.xml	Wed Feb 27 11:24:58 2013 +0100
   627.3 @@ -0,0 +1,67 @@
   627.4 +<?xml version="1.0"?>
   627.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"
   627.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   627.7 +  <modelVersion>4.0.0</modelVersion>
   627.8 +  <parent>
   627.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
  627.10 +    <artifactId>rt</artifactId>
  627.11 +    <version>0.3-SNAPSHOT</version>
  627.12 +  </parent>
  627.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
  627.14 +  <artifactId>vmtest</artifactId>
  627.15 +  <version>0.3-SNAPSHOT</version>
  627.16 +  
  627.17 +  <name>VM Testing APIs</name>
  627.18 +  <url>http://bck2brwsr.apidesign.org</url>
  627.19 +    <build>
  627.20 +        <plugins>
  627.21 +            <plugin>
  627.22 +                <groupId>org.apache.maven.plugins</groupId>
  627.23 +                <artifactId>maven-compiler-plugin</artifactId>
  627.24 +                <version>2.3.2</version>
  627.25 +                <configuration>
  627.26 +                    <source>1.7</source>
  627.27 +                    <target>1.7</target>
  627.28 +                </configuration>
  627.29 +            </plugin>
  627.30 +        </plugins>
  627.31 +    </build>
  627.32 +    <properties>
  627.33 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  627.34 +  </properties>
  627.35 +  <dependencies>
  627.36 +    <dependency>
  627.37 +      <groupId>org.testng</groupId>
  627.38 +      <artifactId>testng</artifactId>
  627.39 +      <scope>compile</scope>
  627.40 +      <exclusions>
  627.41 +        <exclusion>
  627.42 +          <artifactId>junit</artifactId>
  627.43 +          <groupId>junit</groupId>
  627.44 +        </exclusion>
  627.45 +      </exclusions>
  627.46 +    </dependency>
  627.47 +    <dependency>
  627.48 +      <groupId>${project.groupId}</groupId>
  627.49 +      <artifactId>vm4brwsr</artifactId>
  627.50 +      <version>${project.version}</version>
  627.51 +      <type>jar</type>
  627.52 +    </dependency>
  627.53 +    <dependency>
  627.54 +      <groupId>${project.groupId}</groupId>
  627.55 +      <artifactId>emul.mini</artifactId>
  627.56 +      <version>${project.version}</version>
  627.57 +      <scope>test</scope>
  627.58 +    </dependency>
  627.59 +    <dependency>
  627.60 +      <groupId>${project.groupId}</groupId>
  627.61 +      <artifactId>launcher</artifactId>
  627.62 +      <version>${project.version}</version>
  627.63 +    </dependency>
  627.64 +    <dependency>
  627.65 +      <groupId>org.netbeans.api</groupId>
  627.66 +      <artifactId>org-openide-util-lookup</artifactId>
  627.67 +      <scope>provided</scope>
  627.68 +    </dependency>
  627.69 +  </dependencies>
  627.70 +</project>
   628.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   628.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java	Wed Feb 27 11:24:58 2013 +0100
   628.3 @@ -0,0 +1,38 @@
   628.4 +/**
   628.5 + * Back 2 Browser Bytecode Translator
   628.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   628.7 + *
   628.8 + * This program is free software: you can redistribute it and/or modify
   628.9 + * it under the terms of the GNU General Public License as published by
  628.10 + * the Free Software Foundation, version 2 of the License.
  628.11 + *
  628.12 + * This program is distributed in the hope that it will be useful,
  628.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  628.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  628.15 + * GNU General Public License for more details.
  628.16 + *
  628.17 + * You should have received a copy of the GNU General Public License
  628.18 + * along with this program. Look for COPYING file in the top folder.
  628.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  628.20 + */
  628.21 +package org.apidesign.bck2brwsr.vmtest;
  628.22 +
  628.23 +import java.lang.annotation.ElementType;
  628.24 +import java.lang.annotation.Retention;
  628.25 +import java.lang.annotation.RetentionPolicy;
  628.26 +import java.lang.annotation.Target;
  628.27 +
  628.28 +/** Annotation to indicate that given method should be executed
  628.29 + * in a browser environment. Has to be used in conjunction with {@link VMTest#create(java.lang.Class)}
  628.30 + * factory method. 
  628.31 + * <p>
  628.32 + * The browser to is by default executed via {@link java.awt.Desktop#browse(java.net.URI)},
  628.33 + * but one can change that by specifying <code>-Dvmtest.brwsrs=firefox,google-chrome</code>
  628.34 + * property.
  628.35 + *
  628.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  628.37 + */
  628.38 +@Retention(RetentionPolicy.RUNTIME)
  628.39 +@Target(ElementType.METHOD)
  628.40 +public @interface BrwsrTest {
  628.41 +}
   629.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   629.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java	Wed Feb 27 11:24:58 2013 +0100
   629.3 @@ -0,0 +1,45 @@
   629.4 +/**
   629.5 + * Back 2 Browser Bytecode Translator
   629.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   629.7 + *
   629.8 + * This program is free software: you can redistribute it and/or modify
   629.9 + * it under the terms of the GNU General Public License as published by
  629.10 + * the Free Software Foundation, version 2 of the License.
  629.11 + *
  629.12 + * This program is distributed in the hope that it will be useful,
  629.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  629.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  629.15 + * GNU General Public License for more details.
  629.16 + *
  629.17 + * You should have received a copy of the GNU General Public License
  629.18 + * along with this program. Look for COPYING file in the top folder.
  629.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  629.20 + */
  629.21 +package org.apidesign.bck2brwsr.vmtest;
  629.22 +
  629.23 +import java.lang.annotation.ElementType;
  629.24 +import java.lang.annotation.Retention;
  629.25 +import java.lang.annotation.RetentionPolicy;
  629.26 +import java.lang.annotation.Target;
  629.27 +
  629.28 +/** Can be applied on a method that yields a return value. 
  629.29 + * Together with {@link VMTest#create} it can be used to write
  629.30 + * methods which are executed in real VM as well as JavaScript VMs and
  629.31 + * their results are compared.
  629.32 + *
  629.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  629.34 + */
  629.35 +@Retention(RetentionPolicy.RUNTIME)
  629.36 +@Target(ElementType.METHOD)
  629.37 +public @interface Compare {
  629.38 +    /** Specifies whether the system should internal JavaScript interpreter
  629.39 +     * as available via {@link javax.script.ScriptEngine}. Defaults to true,
  629.40 +     * but in some situations (benchmarking comes to my mind), one may set this
  629.41 +     * to <code>false</code>. In such case only browsers provided via
  629.42 +     * <code>vmtest.brwsrs</code> property are used. For example
  629.43 +     * <code>"vmtest.brwsrs=firefox,google-chrome"</code> would run the test
  629.44 +     * in HotSpot VM, firefox and chrome and would compare the results.
  629.45 +     * @return 
  629.46 +     */
  629.47 +    boolean scripting() default true;
  629.48 +}
   630.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   630.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java	Wed Feb 27 11:24:58 2013 +0100
   630.3 @@ -0,0 +1,38 @@
   630.4 +/**
   630.5 + * Back 2 Browser Bytecode Translator
   630.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   630.7 + *
   630.8 + * This program is free software: you can redistribute it and/or modify
   630.9 + * it under the terms of the GNU General Public License as published by
  630.10 + * the Free Software Foundation, version 2 of the License.
  630.11 + *
  630.12 + * This program is distributed in the hope that it will be useful,
  630.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  630.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  630.15 + * GNU General Public License for more details.
  630.16 + *
  630.17 + * You should have received a copy of the GNU General Public License
  630.18 + * along with this program. Look for COPYING file in the top folder.
  630.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  630.20 + */
  630.21 +package org.apidesign.bck2brwsr.vmtest;
  630.22 +
  630.23 +import java.lang.annotation.ElementType;
  630.24 +import java.lang.annotation.Retention;
  630.25 +import java.lang.annotation.RetentionPolicy;
  630.26 +import java.lang.annotation.Target;
  630.27 +
  630.28 +/** Allows to specify an HTML fragment for a given {@link BrwsrTest}. 
  630.29 + * Apply either to the method or to enclosing class. The fragment will be
  630.30 + * made available in the page that executes given test. Its elements shall
  630.31 + * be regularly accessible from the test.
  630.32 + *
  630.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  630.34 + */
  630.35 +@Retention(RetentionPolicy.RUNTIME)
  630.36 +@Target({ ElementType.METHOD, ElementType.TYPE})
  630.37 +public @interface HtmlFragment {
  630.38 +    /** HTML code fragment to be exposed on the testing page.
  630.39 +     */
  630.40 +    String value();
  630.41 +}
   631.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   631.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Http.java	Wed Feb 27 11:24:58 2013 +0100
   631.3 @@ -0,0 +1,56 @@
   631.4 +/**
   631.5 + * Back 2 Browser Bytecode Translator
   631.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   631.7 + *
   631.8 + * This program is free software: you can redistribute it and/or modify
   631.9 + * it under the terms of the GNU General Public License as published by
  631.10 + * the Free Software Foundation, version 2 of the License.
  631.11 + *
  631.12 + * This program is distributed in the hope that it will be useful,
  631.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  631.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  631.15 + * GNU General Public License for more details.
  631.16 + *
  631.17 + * You should have received a copy of the GNU General Public License
  631.18 + * along with this program. Look for COPYING file in the top folder.
  631.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  631.20 + */
  631.21 +package org.apidesign.bck2brwsr.vmtest;
  631.22 +
  631.23 +import java.lang.annotation.ElementType;
  631.24 +import java.lang.annotation.Retention;
  631.25 +import java.lang.annotation.RetentionPolicy;
  631.26 +import java.lang.annotation.Target;
  631.27 +
  631.28 +/**
  631.29 + * Exposes HTTP page or pages to the running {@link BrwsrTest}, so it can access under
  631.30 + * the relative path.
  631.31 + *
  631.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  631.33 + */
  631.34 +@Retention(RetentionPolicy.RUNTIME)
  631.35 +@Target({ElementType.METHOD, ElementType.TYPE})
  631.36 +public @interface Http {
  631.37 +    /** Set of pages to make available */
  631.38 +    public Resource[] value();
  631.39 +    
  631.40 +    /** Exposes an HTTP page to the running {@link BrwsrTest}, so it can access
  631.41 +     * under the relative path.
  631.42 +     *
  631.43 +     * @author Jaroslav Tulach <jtulach@netbeans.org>
  631.44 +     */
  631.45 +    @Retention(RetentionPolicy.RUNTIME)
  631.46 +    @Target({})
  631.47 +    public @interface Resource {
  631.48 +        /** path on the server that the test can use to access the exposed resource */
  631.49 +        String path();
  631.50 +        /** the content of the HttpResource */
  631.51 +        String content();
  631.52 +        /** resource relative to the class that should be used instead of <code>content</code>.
  631.53 +         * Leave content equal to empty string.
  631.54 +         */
  631.55 +        String resource() default "";
  631.56 +        /** mime type of the resource */
  631.57 +        String mimeType();
  631.58 +    }
  631.59 +}
   632.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   632.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java	Wed Feb 27 11:24:58 2013 +0100
   632.3 @@ -0,0 +1,43 @@
   632.4 +/**
   632.5 + * Back 2 Browser Bytecode Translator
   632.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   632.7 + *
   632.8 + * This program is free software: you can redistribute it and/or modify
   632.9 + * it under the terms of the GNU General Public License as published by
  632.10 + * the Free Software Foundation, version 2 of the License.
  632.11 + *
  632.12 + * This program is distributed in the hope that it will be useful,
  632.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  632.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  632.15 + * GNU General Public License for more details.
  632.16 + *
  632.17 + * You should have received a copy of the GNU General Public License
  632.18 + * along with this program. Look for COPYING file in the top folder.
  632.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  632.20 + */
  632.21 +package org.apidesign.bck2brwsr.vmtest;
  632.22 +
  632.23 +import org.apidesign.bck2brwsr.vmtest.impl.CompareCase;
  632.24 +import org.testng.annotations.Factory;
  632.25 +
  632.26 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
  632.27 + * in provided class and builds set of tests that compare the computations
  632.28 + * in real as well as JavaScript virtual machines. Use as:<pre>
  632.29 + * {@code @}{@link Factory} public static create() {
  632.30 + *   return @{link VMTest}.{@link #create(YourClass.class);
  632.31 + * }</pre>
  632.32 + *
  632.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  632.34 + */
  632.35 +public final class VMTest {
  632.36 +    /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
  632.37 +     * instances of tests. Each instance runs the test in different virtual
  632.38 +     * machine and at the end they compare the results.
  632.39 +     * 
  632.40 +     * @param clazz the class to inspect
  632.41 +     * @return the set of created tests
  632.42 +     */
  632.43 +    public static Object[] create(Class<?> clazz) {
  632.44 +        return CompareCase.create(clazz);
  632.45 +    }
  632.46 +}
   633.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   633.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java	Wed Feb 27 11:24:58 2013 +0100
   633.3 @@ -0,0 +1,137 @@
   633.4 +/**
   633.5 + * Back 2 Browser Bytecode Translator
   633.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   633.7 + *
   633.8 + * This program is free software: you can redistribute it and/or modify
   633.9 + * it under the terms of the GNU General Public License as published by
  633.10 + * the Free Software Foundation, version 2 of the License.
  633.11 + *
  633.12 + * This program is distributed in the hope that it will be useful,
  633.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  633.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  633.15 + * GNU General Public License for more details.
  633.16 + *
  633.17 + * You should have received a copy of the GNU General Public License
  633.18 + * along with this program. Look for COPYING file in the top folder.
  633.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  633.20 + */
  633.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  633.22 +
  633.23 +import java.io.ByteArrayInputStream;
  633.24 +import java.io.File;
  633.25 +import java.io.FileWriter;
  633.26 +import java.io.IOException;
  633.27 +import java.io.InputStream;
  633.28 +import java.lang.reflect.Constructor;
  633.29 +import java.lang.reflect.InvocationTargetException;
  633.30 +import java.lang.reflect.Method;
  633.31 +import org.apidesign.bck2brwsr.launcher.Launcher;
  633.32 +import org.apidesign.bck2brwsr.launcher.InvocationContext;
  633.33 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
  633.34 +import org.apidesign.bck2brwsr.vmtest.Http;
  633.35 +import org.testng.ITest;
  633.36 +import org.testng.annotations.Test;
  633.37 +
  633.38 +/**
  633.39 + *
  633.40 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  633.41 + */
  633.42 +public final class Bck2BrwsrCase implements ITest {
  633.43 +    private final Method m;
  633.44 +    private final Launcher l;
  633.45 +    private final String type;
  633.46 +    private final boolean fail;
  633.47 +    private final HtmlFragment html;
  633.48 +    private final Http.Resource[] http;
  633.49 +    Object value;
  633.50 +
  633.51 +    Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail, HtmlFragment html, Http.Resource[] http) {
  633.52 +        this.l = l;
  633.53 +        this.m = m;
  633.54 +        this.type = type;
  633.55 +        this.fail = fail;
  633.56 +        this.html = html;
  633.57 +        this.http = http;
  633.58 +    }
  633.59 +
  633.60 +    @Test(groups = "run")
  633.61 +    public void executeCode() throws Throwable {
  633.62 +        if (l != null) {
  633.63 +            InvocationContext c = l.createInvocation(m.getDeclaringClass(), m.getName());
  633.64 +            if (html != null) {
  633.65 +                c.setHtmlFragment(html.value());
  633.66 +            }
  633.67 +            if (http != null) {
  633.68 +                for (Http.Resource r : http) {
  633.69 +                    if (!r.content().isEmpty()) {
  633.70 +                        InputStream is = new ByteArrayInputStream(r.content().getBytes("UTF-8"));
  633.71 +                        c.addHttpResource(r.path(), r.mimeType(), is);
  633.72 +                    } else {
  633.73 +                        InputStream is = m.getDeclaringClass().getResourceAsStream(r.resource());
  633.74 +                        c.addHttpResource(r.path(), r.mimeType(), is);
  633.75 +                    }
  633.76 +                }
  633.77 +            }
  633.78 +            String res = c.invoke();
  633.79 +            value = res;
  633.80 +            if (fail) {
  633.81 +                int idx = res.indexOf(':');
  633.82 +                if (idx >= 0) {
  633.83 +                    Class<? extends Throwable> thrwbl = null;
  633.84 +                    try {
  633.85 +                        Class<?> exCls = Class.forName(res.substring(0, idx));
  633.86 +                        if (Throwable.class.isAssignableFrom(exCls)) {
  633.87 +                            thrwbl = exCls.asSubclass(Throwable.class);
  633.88 +                        }
  633.89 +                    } catch (Exception ex) {
  633.90 +                        // ignore
  633.91 +                    }
  633.92 +                    if (thrwbl != null) {
  633.93 +                        Throwable t = null;
  633.94 +                        try {
  633.95 +                            for (Constructor<?> cnstr : thrwbl.getConstructors()) {
  633.96 +                                if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
  633.97 +                                    t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
  633.98 +                                    break;
  633.99 +                                }
 633.100 +                            }
 633.101 +                        } catch (Throwable ex) {
 633.102 +                            t = thrwbl.newInstance().initCause(ex);
 633.103 +                        }
 633.104 +                        if (t == null) {
 633.105 +                            t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
 633.106 +                        }
 633.107 +                        throw t;
 633.108 +                    }
 633.109 +                    throw new AssertionError(res);
 633.110 +                }
 633.111 +            }
 633.112 +        } else {
 633.113 +            try {
 633.114 +                value = m.invoke(m.getDeclaringClass().newInstance());
 633.115 +            } catch (InvocationTargetException ex) {
 633.116 +                Throwable t = ex.getTargetException();
 633.117 +                value = t.getClass().getName() + ":" + t.getMessage();
 633.118 +                if (t instanceof AssertionError) {
 633.119 +                    throw t;
 633.120 +                }
 633.121 +            }
 633.122 +        }
 633.123 +    }
 633.124 +
 633.125 +    @Override
 633.126 +    public String getTestName() {
 633.127 +        return m.getName() + "[" + typeName() + "]";
 633.128 +    }
 633.129 +
 633.130 +    final String typeName() {
 633.131 +        return type;
 633.132 +    }
 633.133 +    static void dumpJS(StringBuilder sb, Bck2BrwsrCase c) throws IOException {
 633.134 +        File f = File.createTempFile(c.m.getName(), ".js");
 633.135 +        try (final FileWriter w = new FileWriter(f)) {
 633.136 +            w.append(c.l.toString());
 633.137 +        }
 633.138 +        sb.append("Path: ").append(f.getPath());
 633.139 +    }
 633.140 +}
   634.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   634.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java	Wed Feb 27 11:24:58 2013 +0100
   634.3 @@ -0,0 +1,160 @@
   634.4 +/**
   634.5 + * Back 2 Browser Bytecode Translator
   634.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   634.7 + *
   634.8 + * This program is free software: you can redistribute it and/or modify
   634.9 + * it under the terms of the GNU General Public License as published by
  634.10 + * the Free Software Foundation, version 2 of the License.
  634.11 + *
  634.12 + * This program is distributed in the hope that it will be useful,
  634.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  634.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  634.15 + * GNU General Public License for more details.
  634.16 + *
  634.17 + * You should have received a copy of the GNU General Public License
  634.18 + * along with this program. Look for COPYING file in the top folder.
  634.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  634.20 + */
  634.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  634.22 +
  634.23 +import org.apidesign.bck2brwsr.vmtest.*;
  634.24 +import java.lang.reflect.Method;
  634.25 +import java.util.ArrayList;
  634.26 +import java.util.List;
  634.27 +import org.apidesign.bck2brwsr.launcher.Launcher;
  634.28 +import org.testng.Assert;
  634.29 +import org.testng.ITest;
  634.30 +import org.testng.annotations.Factory;
  634.31 +import org.testng.annotations.Test;
  634.32 +
  634.33 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
  634.34 + * in provided class and builds set of tests that compare the computations
  634.35 + * in real as well as JavaScript virtual machines. Use as:<pre>
  634.36 + * {@code @}{@link Factory} public static create() {
  634.37 + *   return @{link VMTest}.{@link #create(YourClass.class);
  634.38 + * }</pre>
  634.39 + *
  634.40 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  634.41 + */
  634.42 +public final class CompareCase implements ITest {
  634.43 +    private final Bck2BrwsrCase first, second;
  634.44 +    private final Method m;
  634.45 +    
  634.46 +    private CompareCase(Method m, Bck2BrwsrCase first, Bck2BrwsrCase second) {
  634.47 +        this.first = first;
  634.48 +        this.second = second;
  634.49 +        this.m = m;
  634.50 +    }
  634.51 +
  634.52 +    /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
  634.53 +     * instances of tests. Each instance runs the test in different virtual
  634.54 +     * machine and at the end they compare the results.
  634.55 +     * 
  634.56 +     * @param clazz the class to inspect
  634.57 +     * @return the set of created tests
  634.58 +     */
  634.59 +    public static Object[] create(Class<?> clazz) {
  634.60 +        Method[] arr = clazz.getMethods();
  634.61 +        List<Object> ret = new ArrayList<>();
  634.62 +        
  634.63 +        final LaunchSetup l = LaunchSetup.INSTANCE;
  634.64 +        ret.add(l);
  634.65 +        
  634.66 +        String[] brwsr;
  634.67 +        {
  634.68 +            String p = System.getProperty("vmtest.brwsrs");
  634.69 +            if (p != null) {
  634.70 +                brwsr = p.split(",");
  634.71 +            } else {
  634.72 +                brwsr = new String[0];
  634.73 +            }
  634.74 +        }
  634.75 +        
  634.76 +        for (Method m : arr) {
  634.77 +            registerCompareCases(m, l, ret, brwsr);
  634.78 +            registerBrwsrCases(m, l, ret, brwsr);
  634.79 +        }
  634.80 +        return ret.toArray();
  634.81 +    }
  634.82 +
  634.83 +    /** Test that compares the previous results.
  634.84 +     * @throws Throwable 
  634.85 +     */
  634.86 +    @Test(dependsOnGroups = "run") public void compareResults() throws Throwable {
  634.87 +        Object v1 = first.value;
  634.88 +        Object v2 = second.value;
  634.89 +        if (v1 != null) {
  634.90 +            v1 = v1.toString();
  634.91 +        } else {
  634.92 +            v1 = "null";
  634.93 +        }
  634.94 +        try {
  634.95 +            Assert.assertEquals(v2, v1, "Comparing results");
  634.96 +        } catch (AssertionError e) {
  634.97 +            StringBuilder sb = new StringBuilder();
  634.98 +            sb.append(e.getMessage());
  634.99 +            Bck2BrwsrCase.dumpJS(sb, second);
 634.100 +            throw new AssertionError(sb.toString());
 634.101 +        }
 634.102 +    }
 634.103 +    
 634.104 +    /** Test name.
 634.105 +     * @return name of the tested method followed by a suffix
 634.106 +     */
 634.107 +    @Override
 634.108 +    public String getTestName() {
 634.109 +        return m.getName() + "[Compare " + second.typeName() + "]";
 634.110 +    }
 634.111 +    
 634.112 +    private static void registerCompareCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
 634.113 +        Compare c = m.getAnnotation(Compare.class);
 634.114 +        if (c == null) {
 634.115 +            return;
 634.116 +        }
 634.117 +        final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false, null, null);
 634.118 +        ret.add(real);
 634.119 +        if (c.scripting()) {
 634.120 +            final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false, null, null);
 634.121 +            ret.add(js);
 634.122 +            ret.add(new CompareCase(m, real, js));
 634.123 +        }
 634.124 +        for (String b : brwsr) {
 634.125 +            final Launcher s = l.brwsr(b);
 634.126 +            ret.add(s);
 634.127 +            final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false, null, null);
 634.128 +            ret.add(cse);
 634.129 +            ret.add(new CompareCase(m, real, cse));
 634.130 +        }
 634.131 +    }
 634.132 +    private static void registerBrwsrCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
 634.133 +        BrwsrTest c = m.getAnnotation(BrwsrTest.class);
 634.134 +        if (c == null) {
 634.135 +            return;
 634.136 +        }
 634.137 +        HtmlFragment f = m.getAnnotation(HtmlFragment.class);
 634.138 +        if (f == null) {
 634.139 +            f = m.getDeclaringClass().getAnnotation(HtmlFragment.class);
 634.140 +        }
 634.141 +        Http.Resource[] r = {};
 634.142 +        Http h = m.getAnnotation(Http.class);
 634.143 +        if (h == null) {
 634.144 +            h = m.getDeclaringClass().getAnnotation(Http.class);
 634.145 +            if (h != null) {
 634.146 +                r = h.value();
 634.147 +            }
 634.148 +        } else {
 634.149 +            r = h.value();
 634.150 +        }
 634.151 +        if (brwsr.length == 0) {
 634.152 +            final Launcher s = l.brwsr(null);
 634.153 +            ret.add(s);
 634.154 +            ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true, f, r));
 634.155 +        } else {
 634.156 +            for (String b : brwsr) {
 634.157 +                final Launcher s = l.brwsr(b);
 634.158 +                ret.add(s);
 634.159 +                ret.add(new Bck2BrwsrCase(m, b, s, true, f, r));
 634.160 +            }
 634.161 +        }
 634.162 +    }
 634.163 +}
   635.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   635.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/GenerateZip.java	Wed Feb 27 11:24:58 2013 +0100
   635.3 @@ -0,0 +1,36 @@
   635.4 +/**
   635.5 + * Back 2 Browser Bytecode Translator
   635.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   635.7 + *
   635.8 + * This program is free software: you can redistribute it and/or modify
   635.9 + * it under the terms of the GNU General Public License as published by
  635.10 + * the Free Software Foundation, version 2 of the License.
  635.11 + *
  635.12 + * This program is distributed in the hope that it will be useful,
  635.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  635.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  635.15 + * GNU General Public License for more details.
  635.16 + *
  635.17 + * You should have received a copy of the GNU General Public License
  635.18 + * along with this program. Look for COPYING file in the top folder.
  635.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  635.20 + */
  635.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  635.22 +
  635.23 +import java.lang.annotation.Retention;
  635.24 +import java.lang.annotation.RetentionPolicy;
  635.25 +
  635.26 +/** Annotation to generate a ZIP or JAR file during build.
  635.27 + *
  635.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  635.29 + */
  635.30 +@Retention(RetentionPolicy.SOURCE)
  635.31 +@interface GenerateZip {
  635.32 +    String name();
  635.33 +    
  635.34 +    /** manifest for the file */
  635.35 +    String manifest() default "";
  635.36 +
  635.37 +    /** Array of names (at odd positions) and their content (on even) */
  635.38 +    String[] contents();
  635.39 +}
   636.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   636.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/GenerateZipProcessor.java	Wed Feb 27 11:24:58 2013 +0100
   636.3 @@ -0,0 +1,101 @@
   636.4 +/**
   636.5 + * Back 2 Browser Bytecode Translator
   636.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   636.7 + *
   636.8 + * This program is free software: you can redistribute it and/or modify
   636.9 + * it under the terms of the GNU General Public License as published by
  636.10 + * the Free Software Foundation, version 2 of the License.
  636.11 + *
  636.12 + * This program is distributed in the hope that it will be useful,
  636.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  636.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  636.15 + * GNU General Public License for more details.
  636.16 + *
  636.17 + * You should have received a copy of the GNU General Public License
  636.18 + * along with this program. Look for COPYING file in the top folder.
  636.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  636.20 + */
  636.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  636.22 +
  636.23 +import java.io.ByteArrayInputStream;
  636.24 +import java.io.IOException;
  636.25 +import java.io.OutputStream;
  636.26 +import java.util.Set;
  636.27 +import java.util.jar.JarEntry;
  636.28 +import java.util.jar.JarOutputStream;
  636.29 +import java.util.jar.Manifest;
  636.30 +import javax.annotation.processing.AbstractProcessor;
  636.31 +import javax.annotation.processing.Filer;
  636.32 +import javax.annotation.processing.Processor;
  636.33 +import javax.annotation.processing.RoundEnvironment;
  636.34 +import javax.annotation.processing.SupportedAnnotationTypes;
  636.35 +import javax.lang.model.element.Element;
  636.36 +import javax.lang.model.element.ElementKind;
  636.37 +import javax.lang.model.element.PackageElement;
  636.38 +import javax.lang.model.element.TypeElement;
  636.39 +import javax.tools.Diagnostic;
  636.40 +import javax.tools.FileObject;
  636.41 +import javax.tools.StandardLocation;
  636.42 +import org.openide.util.lookup.ServiceProvider;
  636.43 +
  636.44 +/**
  636.45 + *
  636.46 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  636.47 + */
  636.48 +@ServiceProvider(service = Processor.class)
  636.49 +@SupportedAnnotationTypes("org.apidesign.bck2brwsr.vmtest.impl.GenerateZip")
  636.50 +public class GenerateZipProcessor extends AbstractProcessor {
  636.51 +
  636.52 +    @Override
  636.53 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  636.54 +        for (Element e : roundEnv.getElementsAnnotatedWith(GenerateZip.class)) {
  636.55 +            GenerateZip gz = e.getAnnotation(GenerateZip.class);
  636.56 +            if (gz == null) {
  636.57 +                continue;
  636.58 +            }
  636.59 +            PackageElement pe = findPackage(e);
  636.60 +            try {
  636.61 +                generateJar(pe, gz, e);
  636.62 +            } catch (IOException ex) {
  636.63 +                processingEnv.getMessager().printMessage(
  636.64 +                    Diagnostic.Kind.ERROR, 
  636.65 +                    "Can't generate JAR " + gz.name() + ": " + ex.getMessage()
  636.66 +                );
  636.67 +            }
  636.68 +        }
  636.69 +        return true;
  636.70 +    }
  636.71 +
  636.72 +    private static PackageElement findPackage(Element e) {
  636.73 +        while (e.getKind() != ElementKind.PACKAGE) {
  636.74 +            e = e.getEnclosingElement();
  636.75 +        }
  636.76 +        return (PackageElement)e;
  636.77 +    }
  636.78 +
  636.79 +    private void generateJar(PackageElement pe, GenerateZip gz, Element e) throws IOException {
  636.80 +        final Filer filer = processingEnv.getFiler();
  636.81 +        FileObject res = filer.createResource(
  636.82 +            StandardLocation.CLASS_OUTPUT, 
  636.83 +            pe.getQualifiedName().toString(), 
  636.84 +            gz.name(), e
  636.85 +        );
  636.86 +        OutputStream os = res.openOutputStream();
  636.87 +        JarOutputStream jar;
  636.88 +        if (gz.manifest().isEmpty()) {
  636.89 +            jar = new JarOutputStream(os);
  636.90 +        } else {
  636.91 +            Manifest mf = new Manifest(new ByteArrayInputStream(gz.manifest().getBytes("UTF-8")));
  636.92 +            jar = new JarOutputStream(os, mf);
  636.93 +        }
  636.94 +        String[] arr = gz.contents();
  636.95 +        for (int i = 0; i < arr.length; i += 2) {
  636.96 +            JarEntry je = new JarEntry(arr[i]);
  636.97 +            jar.putNextEntry(je);
  636.98 +            jar.write(arr[i + 1].getBytes("UTF-8"));
  636.99 +            jar.closeEntry();
 636.100 +        }
 636.101 +        jar.close();
 636.102 +    }
 636.103 +
 636.104 +}
   637.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   637.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Wed Feb 27 11:24:58 2013 +0100
   637.3 @@ -0,0 +1,78 @@
   637.4 +/**
   637.5 + * Back 2 Browser Bytecode Translator
   637.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   637.7 + *
   637.8 + * This program is free software: you can redistribute it and/or modify
   637.9 + * it under the terms of the GNU General Public License as published by
  637.10 + * the Free Software Foundation, version 2 of the License.
  637.11 + *
  637.12 + * This program is distributed in the hope that it will be useful,
  637.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  637.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  637.15 + * GNU General Public License for more details.
  637.16 + *
  637.17 + * You should have received a copy of the GNU General Public License
  637.18 + * along with this program. Look for COPYING file in the top folder.
  637.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  637.20 + */
  637.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  637.22 +
  637.23 +import java.io.IOException;
  637.24 +import java.util.LinkedHashMap;
  637.25 +import java.util.Map;
  637.26 +import org.apidesign.bck2brwsr.launcher.Launcher;
  637.27 +import org.testng.annotations.AfterGroups;
  637.28 +import org.testng.annotations.BeforeGroups;
  637.29 +
  637.30 +/**
  637.31 + *
  637.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  637.33 + */
  637.34 +public final class LaunchSetup {
  637.35 +    static LaunchSetup INSTANCE = new LaunchSetup();
  637.36 +    
  637.37 +    private Launcher js;
  637.38 +    private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
  637.39 +    
  637.40 +    private LaunchSetup() {
  637.41 +    }
  637.42 +    
  637.43 +    public Launcher javaScript() {
  637.44 +        return js(true);
  637.45 +    } 
  637.46 +    private synchronized  Launcher js(boolean create) {
  637.47 +        if (js == null && create) {
  637.48 +            js = Launcher.createJavaScript();
  637.49 +        }
  637.50 +        return js;
  637.51 +    } 
  637.52 +    
  637.53 +    public synchronized Launcher brwsr(String cmd) {
  637.54 +        Launcher s = brwsrs.get(cmd);
  637.55 +        if (s == null) {
  637.56 +            s = Launcher.createBrowser(cmd);
  637.57 +            brwsrs.put(cmd, s);
  637.58 +        }
  637.59 +        return s;
  637.60 +    }
  637.61 +
  637.62 +    @BeforeGroups("run")
  637.63 +    public void initializeLauncher() throws IOException {
  637.64 +        if (js(false) != null) {
  637.65 +            js(true).initialize();
  637.66 +        }
  637.67 +        for (Launcher launcher : brwsrs.values()) {
  637.68 +            launcher.initialize();
  637.69 +        }
  637.70 +    }
  637.71 +
  637.72 +    @AfterGroups("run")
  637.73 +    public void shutDownLauncher() throws IOException, InterruptedException {
  637.74 +        if (js(false) != null) {
  637.75 +            js(true).shutdown();
  637.76 +        }
  637.77 +        for (Launcher launcher : brwsrs.values()) {
  637.78 +            launcher.shutdown();
  637.79 +        }
  637.80 +    }
  637.81 +}
   638.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   638.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/AssertionTest.java	Wed Feb 27 11:24:58 2013 +0100
   638.3 @@ -0,0 +1,43 @@
   638.4 +/**
   638.5 + * Back 2 Browser Bytecode Translator
   638.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   638.7 + *
   638.8 + * This program is free software: you can redistribute it and/or modify
   638.9 + * it under the terms of the GNU General Public License as published by
  638.10 + * the Free Software Foundation, version 2 of the License.
  638.11 + *
  638.12 + * This program is distributed in the hope that it will be useful,
  638.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  638.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  638.15 + * GNU General Public License for more details.
  638.16 + *
  638.17 + * You should have received a copy of the GNU General Public License
  638.18 + * along with this program. Look for COPYING file in the top folder.
  638.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  638.20 + */
  638.21 +package org.apidesign.bck2brwsr.tck;
  638.22 +
  638.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  638.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  638.25 +import org.testng.annotations.Factory;
  638.26 +
  638.27 +/**
  638.28 + *
  638.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  638.30 + */
  638.31 +public class AssertionTest {
  638.32 +
  638.33 +    @Compare public Object checkAssert() throws ClassNotFoundException {
  638.34 +        try {
  638.35 +            assert false : "Is assertion status on?";
  638.36 +            return null;
  638.37 +        } catch (AssertionError ex) {
  638.38 +            return ex.getClass().getName();
  638.39 +        }
  638.40 +    }
  638.41 +    
  638.42 +    @Factory
  638.43 +    public static Object[] create() {
  638.44 +        return VMTest.create(AssertionTest.class);
  638.45 +    }
  638.46 +}
   639.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   639.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java	Wed Feb 27 11:24:58 2013 +0100
   639.3 @@ -0,0 +1,57 @@
   639.4 +/**
   639.5 + * Back 2 Browser Bytecode Translator
   639.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   639.7 + *
   639.8 + * This program is free software: you can redistribute it and/or modify
   639.9 + * it under the terms of the GNU General Public License as published by
  639.10 + * the Free Software Foundation, version 2 of the License.
  639.11 + *
  639.12 + * This program is distributed in the hope that it will be useful,
  639.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  639.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  639.15 + * GNU General Public License for more details.
  639.16 + *
  639.17 + * You should have received a copy of the GNU General Public License
  639.18 + * along with this program. Look for COPYING file in the top folder.
  639.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  639.20 + */
  639.21 +package org.apidesign.bck2brwsr.tck;
  639.22 +
  639.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  639.24 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  639.25 +import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
  639.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  639.27 +import org.testng.annotations.Factory;
  639.28 +
  639.29 +/**
  639.30 + *
  639.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  639.32 + */
  639.33 +public class BrwsrCheckTest {
  639.34 +
  639.35 +    @BrwsrTest public void assertWindowObjectIsDefined() {
  639.36 +        assert window() != null : "No window object found!";
  639.37 +    }
  639.38 +
  639.39 +    
  639.40 +    
  639.41 +    
  639.42 +    @HtmlFragment("<h1 id='hello'>\n"
  639.43 +        + "Hello!\n"
  639.44 +        + "</h1>\n")
  639.45 +    @BrwsrTest public void accessProvidedFragment() {
  639.46 +        assert getElementById("hello") != null : "Element with 'hello' ID found";
  639.47 +    }
  639.48 +    
  639.49 +    @Factory
  639.50 +    public static Object[] create() {
  639.51 +        return VMTest.create(BrwsrCheckTest.class);
  639.52 +    }
  639.53 +    
  639.54 +
  639.55 +    @JavaScriptBody(args = {}, body = "return window;")
  639.56 +    private static native Object window();
  639.57 +
  639.58 +    @JavaScriptBody(args = { "id" }, body = "return window.document.getElementById(id);")
  639.59 +    private static native Object getElementById(String id);
  639.60 +}
   640.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   640.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ByteArithmeticTest.java	Wed Feb 27 11:24:58 2013 +0100
   640.3 @@ -0,0 +1,102 @@
   640.4 +/**
   640.5 + * Back 2 Browser Bytecode Translator
   640.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   640.7 + *
   640.8 + * This program is free software: you can redistribute it and/or modify
   640.9 + * it under the terms of the GNU General Public License as published by
  640.10 + * the Free Software Foundation, version 2 of the License.
  640.11 + *
  640.12 + * This program is distributed in the hope that it will be useful,
  640.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  640.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  640.15 + * GNU General Public License for more details.
  640.16 + *
  640.17 + * You should have received a copy of the GNU General Public License
  640.18 + * along with this program. Look for COPYING file in the top folder.
  640.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  640.20 + */
  640.21 +package org.apidesign.bck2brwsr.tck;
  640.22 +
  640.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  640.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  640.25 +import org.testng.annotations.Factory;
  640.26 +
  640.27 +/**
  640.28 + *
  640.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  640.30 + */
  640.31 +public class ByteArithmeticTest {
  640.32 +    
  640.33 +    private static byte add(byte x, byte y) {
  640.34 +        return (byte)(x + y);
  640.35 +    }
  640.36 +    
  640.37 +    private static byte sub(byte x, byte y) {
  640.38 +        return (byte)(x - y);
  640.39 +    }
  640.40 +    
  640.41 +    private static byte mul(byte x, byte y) {
  640.42 +        return (byte)(x * y);
  640.43 +    }
  640.44 +    
  640.45 +    private static byte div(byte x, byte y) {
  640.46 +        return (byte)(x / y);
  640.47 +    }
  640.48 +    
  640.49 +    private static byte mod(byte x, byte y) {
  640.50 +        return (byte)(x % y);
  640.51 +    }
  640.52 +    
  640.53 +    @Compare public byte conversion() {
  640.54 +        return (byte)123456;
  640.55 +    }
  640.56 +    
  640.57 +    @Compare public byte addOverflow() {
  640.58 +        return add(Byte.MAX_VALUE, (byte)1);
  640.59 +    }
  640.60 +    
  640.61 +    @Compare public byte subUnderflow() {
  640.62 +        return sub(Byte.MIN_VALUE, (byte)1);
  640.63 +    }
  640.64 +    
  640.65 +    @Compare public byte addMaxByteAndMaxByte() {
  640.66 +        return add(Byte.MAX_VALUE, Byte.MAX_VALUE);
  640.67 +    }
  640.68 +    
  640.69 +    @Compare public byte subMinByteAndMinByte() {
  640.70 +        return sub(Byte.MIN_VALUE, Byte.MIN_VALUE);
  640.71 +    }
  640.72 +    
  640.73 +    @Compare public byte multiplyMaxByte() {
  640.74 +        return mul(Byte.MAX_VALUE, (byte)2);
  640.75 +    }
  640.76 +    
  640.77 +    @Compare public byte multiplyMaxByteAndMaxByte() {
  640.78 +        return mul(Byte.MAX_VALUE, Byte.MAX_VALUE);
  640.79 +    }
  640.80 +    
  640.81 +    @Compare public byte multiplyMinByte() {
  640.82 +        return mul(Byte.MIN_VALUE, (byte)2);
  640.83 +    }
  640.84 +    
  640.85 +    @Compare public byte multiplyMinByteAndMinByte() {
  640.86 +        return mul(Byte.MIN_VALUE, Byte.MIN_VALUE);
  640.87 +    }
  640.88 +    
  640.89 +    @Compare public byte multiplyPrecision() {
  640.90 +        return mul((byte)17638, (byte)1103);
  640.91 +    }
  640.92 +    
  640.93 +    @Compare public byte division() {
  640.94 +        return div((byte)1, (byte)2);
  640.95 +    }
  640.96 +    
  640.97 +    @Compare public byte divisionReminder() {
  640.98 +        return mod((byte)1, (byte)2);
  640.99 +    }
 640.100 +    
 640.101 +    @Factory
 640.102 +    public static Object[] create() {
 640.103 +        return VMTest.create(ByteArithmeticTest.class);
 640.104 +    }
 640.105 +}
   641.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   641.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CloneTest.java	Wed Feb 27 11:24:58 2013 +0100
   641.3 @@ -0,0 +1,73 @@
   641.4 +/**
   641.5 + * Back 2 Browser Bytecode Translator
   641.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   641.7 + *
   641.8 + * This program is free software: you can redistribute it and/or modify
   641.9 + * it under the terms of the GNU General Public License as published by
  641.10 + * the Free Software Foundation, version 2 of the License.
  641.11 + *
  641.12 + * This program is distributed in the hope that it will be useful,
  641.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  641.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  641.15 + * GNU General Public License for more details.
  641.16 + *
  641.17 + * You should have received a copy of the GNU General Public License
  641.18 + * along with this program. Look for COPYING file in the top folder.
  641.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  641.20 + */
  641.21 +package org.apidesign.bck2brwsr.tck;
  641.22 +
  641.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  641.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  641.25 +import org.testng.annotations.Factory;
  641.26 +
  641.27 +/**
  641.28 + *
  641.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  641.30 + */
  641.31 +public class CloneTest {
  641.32 +    private int value;
  641.33 +    
  641.34 +    @Compare
  641.35 +    public Object notSupported() throws CloneNotSupportedException {
  641.36 +        return this.clone();
  641.37 +    }
  641.38 +
  641.39 +    @Compare public String sameClass() throws CloneNotSupportedException {
  641.40 +        return new Clnbl().clone().getClass().getName();
  641.41 +    }
  641.42 +
  641.43 +    @Compare public boolean differentInstance() throws CloneNotSupportedException {
  641.44 +        Clnbl orig = new Clnbl();
  641.45 +        return orig == orig.clone();
  641.46 +    }
  641.47 +
  641.48 +    @Compare public int sameReference() throws CloneNotSupportedException {
  641.49 +        CloneTest self = this;
  641.50 +        Clnbl orig = new Clnbl();
  641.51 +        self.value = 33;
  641.52 +        orig.ref = self;
  641.53 +        return ((Clnbl)orig.clone()).ref.value;
  641.54 +    }
  641.55 +
  641.56 +    @Compare public int sameValue() throws CloneNotSupportedException {
  641.57 +        Clnbl orig = new Clnbl();
  641.58 +        orig.value = 10;
  641.59 +        return ((Clnbl)orig.clone()).value;
  641.60 +    }
  641.61 +    
  641.62 +    @Factory
  641.63 +    public static Object[] create() {
  641.64 +        return VMTest.create(CloneTest.class);
  641.65 +    }
  641.66 +    
  641.67 +    public static final class Clnbl implements Cloneable {
  641.68 +        public CloneTest ref;
  641.69 +        private int value;
  641.70 +
  641.71 +        @Override
  641.72 +        public Object clone() throws CloneNotSupportedException {
  641.73 +            return super.clone();
  641.74 +        }
  641.75 +    }
  641.76 +}
   642.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   642.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareByteArrayTest.java	Wed Feb 27 11:24:58 2013 +0100
   642.3 @@ -0,0 +1,93 @@
   642.4 +/**
   642.5 + * Back 2 Browser Bytecode Translator
   642.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   642.7 + *
   642.8 + * This program is free software: you can redistribute it and/or modify
   642.9 + * it under the terms of the GNU General Public License as published by
  642.10 + * the Free Software Foundation, version 2 of the License.
  642.11 + *
  642.12 + * This program is distributed in the hope that it will be useful,
  642.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  642.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  642.15 + * GNU General Public License for more details.
  642.16 + *
  642.17 + * You should have received a copy of the GNU General Public License
  642.18 + * along with this program. Look for COPYING file in the top folder.
  642.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  642.20 + */
  642.21 +package org.apidesign.bck2brwsr.tck;
  642.22 +
  642.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  642.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  642.25 +import org.testng.annotations.Factory;
  642.26 +
  642.27 +/**
  642.28 + *
  642.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  642.30 + */
  642.31 +public class CompareByteArrayTest {
  642.32 +    @Compare public int byteArraySum() {
  642.33 +        byte[] arr = createArray();
  642.34 +        return sumByteArr(arr);
  642.35 +    }
  642.36 +    
  642.37 +    @Compare public int countZeros() {
  642.38 +        int zeros = 0;
  642.39 +        for (Byte b : createArray()) {
  642.40 +            if (b == 0) {
  642.41 +                zeros++;
  642.42 +            }
  642.43 +        }
  642.44 +        return zeros;
  642.45 +    }
  642.46 +    
  642.47 +    private static int sumByteArr(byte[] arr) {
  642.48 +        int sum = 0;
  642.49 +        for (int i = 0; i < arr.length; i++) {
  642.50 +            sum += arr[i];
  642.51 +        }
  642.52 +        return sum;
  642.53 +    }
  642.54 +    
  642.55 +    @Compare public String noOutOfBounds() {
  642.56 +        return atIndex(1);
  642.57 +    }
  642.58 +
  642.59 +    @Compare public String outOfBounds() {
  642.60 +        return atIndex(5);
  642.61 +    }
  642.62 +
  642.63 +    @Compare public String outOfBoundsMinus() {
  642.64 +        return atIndex(-1);
  642.65 +    }
  642.66 +
  642.67 +    @Compare public String toOfBounds() {
  642.68 +        return toIndex(5);
  642.69 +    }
  642.70 +
  642.71 +    @Compare public String toOfBoundsMinus() {
  642.72 +        return toIndex(-1);
  642.73 +    }
  642.74 +
  642.75 +    private static final int[] arr = { 0, 1, 2 };
  642.76 +    public static String atIndex(int at) {
  642.77 +        return "at@" + arr[at];
  642.78 +    }
  642.79 +    public static String toIndex(int at) {
  642.80 +        arr[at] = 10;
  642.81 +        return "ok";
  642.82 +    }
  642.83 +    
  642.84 +    
  642.85 +    @Factory
  642.86 +    public static Object[] create() {
  642.87 +        return VMTest.create(CompareByteArrayTest.class);
  642.88 +    }
  642.89 +
  642.90 +    private byte[] createArray() {
  642.91 +        byte[] arr = new byte[10];
  642.92 +        arr[5] = 3;
  642.93 +        arr[7] = 8;
  642.94 +        return arr;
  642.95 +    }
  642.96 +}
   643.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   643.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareHashTest.java	Wed Feb 27 11:24:58 2013 +0100
   643.3 @@ -0,0 +1,50 @@
   643.4 +/**
   643.5 + * Back 2 Browser Bytecode Translator
   643.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   643.7 + *
   643.8 + * This program is free software: you can redistribute it and/or modify
   643.9 + * it under the terms of the GNU General Public License as published by
  643.10 + * the Free Software Foundation, version 2 of the License.
  643.11 + *
  643.12 + * This program is distributed in the hope that it will be useful,
  643.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  643.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  643.15 + * GNU General Public License for more details.
  643.16 + *
  643.17 + * You should have received a copy of the GNU General Public License
  643.18 + * along with this program. Look for COPYING file in the top folder.
  643.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  643.20 + */
  643.21 +package org.apidesign.bck2brwsr.tck;
  643.22 +
  643.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  643.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  643.25 +import org.testng.annotations.Factory;
  643.26 +
  643.27 +/**
  643.28 + *
  643.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  643.30 + */
  643.31 +public class CompareHashTest {
  643.32 +    @Compare public int hashOfString() {
  643.33 +        return "Ahoj".hashCode();
  643.34 +    }
  643.35 +    
  643.36 +    @Compare public int hashRemainsYieldsZero() {
  643.37 +        Object o = new Object();
  643.38 +        return o.hashCode() - o.hashCode();
  643.39 +    }
  643.40 +    
  643.41 +    @Compare public int initializeInStatic() {
  643.42 +        return StaticUse.NON_NULL.hashCode() - StaticUse.NON_NULL.hashCode();
  643.43 +    }
  643.44 +    
  643.45 +    @Compare public int hashOfInt() {
  643.46 +        return Integer.valueOf(Integer.MAX_VALUE).hashCode();
  643.47 +    }
  643.48 +    
  643.49 +    @Factory
  643.50 +    public static Object[] create() {
  643.51 +        return VMTest.create(CompareHashTest.class);
  643.52 +    }
  643.53 +}
   644.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   644.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java	Wed Feb 27 11:24:58 2013 +0100
   644.3 @@ -0,0 +1,63 @@
   644.4 +/**
   644.5 + * Back 2 Browser Bytecode Translator
   644.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   644.7 + *
   644.8 + * This program is free software: you can redistribute it and/or modify
   644.9 + * it under the terms of the GNU General Public License as published by
  644.10 + * the Free Software Foundation, version 2 of the License.
  644.11 + *
  644.12 + * This program is distributed in the hope that it will be useful,
  644.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  644.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  644.15 + * GNU General Public License for more details.
  644.16 + *
  644.17 + * You should have received a copy of the GNU General Public License
  644.18 + * along with this program. Look for COPYING file in the top folder.
  644.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  644.20 + */
  644.21 +package org.apidesign.bck2brwsr.tck;
  644.22 +
  644.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  644.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  644.25 +import org.testng.annotations.Factory;
  644.26 +
  644.27 +/**
  644.28 + *
  644.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  644.30 + */
  644.31 +public class CompareIntArrayTest {
  644.32 +    @Compare public int integerArraySum() {
  644.33 +        int[] arr = createArray();
  644.34 +        return sumIntArr(arr);
  644.35 +    }
  644.36 +    
  644.37 +    @Compare public int countZeros() {
  644.38 +        int zeros = 0;
  644.39 +        for (Integer i : createArray()) {
  644.40 +            if (i == 0) {
  644.41 +                zeros++;
  644.42 +            }
  644.43 +        }
  644.44 +        return zeros;
  644.45 +    }
  644.46 +    
  644.47 +    private static int sumIntArr(int[] arr) {
  644.48 +        int sum = 0;
  644.49 +        for (int i = 0; i < arr.length; i++) {
  644.50 +            sum += arr[i];
  644.51 +        }
  644.52 +        return sum;
  644.53 +    }
  644.54 +    
  644.55 +    @Factory
  644.56 +    public static Object[] create() {
  644.57 +        return VMTest.create(CompareIntArrayTest.class);
  644.58 +    }
  644.59 +
  644.60 +    private int[] createArray() {
  644.61 +        int[] arr = new int[10];
  644.62 +        arr[5] = 3;
  644.63 +        arr[7] = 8;
  644.64 +        return arr;
  644.65 +    }
  644.66 +}
   645.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   645.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Wed Feb 27 11:24:58 2013 +0100
   645.3 @@ -0,0 +1,162 @@
   645.4 +/**
   645.5 + * Back 2 Browser Bytecode Translator
   645.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   645.7 + *
   645.8 + * This program is free software: you can redistribute it and/or modify
   645.9 + * it under the terms of the GNU General Public License as published by
  645.10 + * the Free Software Foundation, version 2 of the License.
  645.11 + *
  645.12 + * This program is distributed in the hope that it will be useful,
  645.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  645.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  645.15 + * GNU General Public License for more details.
  645.16 + *
  645.17 + * You should have received a copy of the GNU General Public License
  645.18 + * along with this program. Look for COPYING file in the top folder.
  645.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  645.20 + */
  645.21 +package org.apidesign.bck2brwsr.tck;
  645.22 +
  645.23 +import java.io.UnsupportedEncodingException;
  645.24 +import java.net.MalformedURLException;
  645.25 +import java.net.URL;
  645.26 +import org.apidesign.bck2brwsr.vmtest.Compare;
  645.27 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  645.28 +import org.testng.annotations.Factory;
  645.29 +
  645.30 +/**
  645.31 + *
  645.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  645.33 + */
  645.34 +public class CompareStringsTest {
  645.35 +    @Compare public String firstChar() {
  645.36 +        return "" + ("Hello".toCharArray()[0]);
  645.37 +    }
  645.38 +    
  645.39 +    @Compare public String classCast() {
  645.40 +        Object o = firstChar();
  645.41 +        return String.class.cast(o);
  645.42 +    }
  645.43 +
  645.44 +    @Compare public String classCastThrown() {
  645.45 +        Object o = null;
  645.46 +        return String.class.cast(o);
  645.47 +    }
  645.48 +    
  645.49 +    @Compare public boolean equalToNull() {
  645.50 +        return "Ahoj".equals(null);
  645.51 +    }
  645.52 +    
  645.53 +    @Compare public int highByteLenght() {
  645.54 +        byte[] arr= { 77,97,110,105,102,101,115,116,45,86,101,114,115,105,111,110 };
  645.55 +        return new String(arr, 0).length();
  645.56 +    }
  645.57 +    
  645.58 +    @Compare public String highByte() {
  645.59 +        byte[] arr= { 77,97,110,105,102,101,115,116,45,86,101,114,115,105,111,110 };
  645.60 +        StringBuilder sb = new StringBuilder();
  645.61 +        sb.append("pref:");
  645.62 +        sb.append(new String(arr, 0));
  645.63 +        return sb.toString();
  645.64 +    }
  645.65 +    
  645.66 +    @Compare public static Object compareURLs() throws MalformedURLException {
  645.67 +        return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
  645.68 +    }
  645.69 +    
  645.70 +    @Compare public String deleteLastTwoCharacters() {
  645.71 +        StringBuilder sb = new StringBuilder();
  645.72 +        sb.append("453.0");
  645.73 +        if (sb.toString().endsWith(".0")) {
  645.74 +            final int l = sb.length();
  645.75 +            sb.delete(l - 2, l);
  645.76 +        }
  645.77 +        return sb.toString().toString();
  645.78 +    }
  645.79 +    
  645.80 +    @Compare public String nameOfStringClass() throws Exception {
  645.81 +        return Class.forName("java.lang.String").getName();
  645.82 +    }
  645.83 +    @Compare public String nameOfArrayClass() throws Exception {
  645.84 +        return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
  645.85 +    }
  645.86 +    
  645.87 +    @Compare public String lowerHello() {
  645.88 +        return "HeLlO".toLowerCase();
  645.89 +    }
  645.90 +    
  645.91 +    @Compare public String lowerA() {
  645.92 +        return String.valueOf(Character.toLowerCase('A')).toString();
  645.93 +    }
  645.94 +    @Compare public String upperHello() {
  645.95 +        return "hello".toUpperCase();
  645.96 +    }
  645.97 +    
  645.98 +    @Compare public String upperA() {
  645.99 +        return String.valueOf(Character.toUpperCase('a')).toString();
 645.100 +    }
 645.101 +    
 645.102 +    @Compare public boolean matchRegExp() throws Exception {
 645.103 +        return "58038503".matches("\\d*");
 645.104 +    }
 645.105 +
 645.106 +    @Compare public boolean doesNotMatchRegExp() throws Exception {
 645.107 +        return "58038503GH".matches("\\d*");
 645.108 +    }
 645.109 +
 645.110 +    @Compare public boolean doesNotMatchRegExpFully() throws Exception {
 645.111 +        return "Hello".matches("Hell");
 645.112 +    }
 645.113 +    
 645.114 +    @Compare public String emptyCharArray() {
 645.115 +        char[] arr = new char[10];
 645.116 +        return new String(arr);
 645.117 +    }
 645.118 +    
 645.119 +    @Compare public String variousCharacterTests() throws Exception {
 645.120 +        StringBuilder sb = new StringBuilder();
 645.121 +        
 645.122 +        sb.append(Character.isUpperCase('a'));
 645.123 +        sb.append(Character.isUpperCase('A'));
 645.124 +        sb.append(Character.isLowerCase('a'));
 645.125 +        sb.append(Character.isLowerCase('A'));
 645.126 +        
 645.127 +        sb.append(Character.isLetter('A'));
 645.128 +        sb.append(Character.isLetterOrDigit('9'));
 645.129 +        sb.append(Character.isLetterOrDigit('A'));
 645.130 +        sb.append(Character.isLetter('0'));
 645.131 +        
 645.132 +        return sb.toString().toString();
 645.133 +    }
 645.134 +        
 645.135 +    @Compare
 645.136 +    public String nullFieldInitialized() {
 645.137 +        NullField nf = new NullField();
 645.138 +        return ("" + nf.name).toString();
 645.139 +    }
 645.140 +    @Compare
 645.141 +    public String toUTFString() throws UnsupportedEncodingException {
 645.142 +        byte[] arr = {
 645.143 +            (byte) -59, (byte) -67, (byte) 108, (byte) 117, (byte) -59, (byte) -91,
 645.144 +            (byte) 111, (byte) 117, (byte) -60, (byte) -115, (byte) 107, (byte) -61,
 645.145 +            (byte) -67, (byte) 32, (byte) 107, (byte) -59, (byte) -81, (byte) -59,
 645.146 +            (byte) -120
 645.147 +        };
 645.148 +        return new String(arr, "utf-8");
 645.149 +    }
 645.150 +
 645.151 +    @Compare
 645.152 +    public int stringToBytesLenght() throws UnsupportedEncodingException {
 645.153 +        return "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("utf8").length;
 645.154 +    }
 645.155 +
 645.156 +    @Factory
 645.157 +    public static Object[] create() {
 645.158 +        return VMTest.create(CompareStringsTest.class);
 645.159 +    }
 645.160 +
 645.161 +    private static final class NullField {
 645.162 +
 645.163 +        String name;
 645.164 +    }
 645.165 +}
   646.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   646.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java	Wed Feb 27 11:24:58 2013 +0100
   646.3 @@ -0,0 +1,106 @@
   646.4 +/**
   646.5 + * Back 2 Browser Bytecode Translator
   646.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   646.7 + *
   646.8 + * This program is free software: you can redistribute it and/or modify
   646.9 + * it under the terms of the GNU General Public License as published by
  646.10 + * the Free Software Foundation, version 2 of the License.
  646.11 + *
  646.12 + * This program is distributed in the hope that it will be useful,
  646.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  646.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  646.15 + * GNU General Public License for more details.
  646.16 + *
  646.17 + * You should have received a copy of the GNU General Public License
  646.18 + * along with this program. Look for COPYING file in the top folder.
  646.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  646.20 + */
  646.21 +package org.apidesign.bck2brwsr.tck;
  646.22 +
  646.23 +import java.io.InputStream;
  646.24 +import java.net.URL;
  646.25 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  646.26 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  646.27 +import org.apidesign.bck2brwsr.vmtest.Http;
  646.28 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  646.29 +import org.testng.annotations.Factory;
  646.30 +
  646.31 +/**
  646.32 + *
  646.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  646.34 + */
  646.35 +public class HttpResourceTest {
  646.36 +    
  646.37 +    @Http({
  646.38 +        @Http.Resource(path = "/xhr", content = "Hello Brwsr!", mimeType = "text/plain")
  646.39 +    })
  646.40 +    @BrwsrTest
  646.41 +    
  646.42 +    
  646.43 +    public String testReadContentViaXHR() throws Exception {
  646.44 +        String msg = read("/xhr");
  646.45 +        assert "Hello Brwsr!".equals(msg) : "The message was " + msg;
  646.46 +        return msg;
  646.47 +    }
  646.48 +
  646.49 +    @Http({
  646.50 +        @Http.Resource(path = "/url", content = "Hello via URL!", mimeType = "text/plain")
  646.51 +    })
  646.52 +    @BrwsrTest
  646.53 +    public String testReadContentViaURL() throws Exception {
  646.54 +        URL url = new URL("http:/url");
  646.55 +        String msg = (String) url.getContent();
  646.56 +        assert "Hello via URL!".equals(msg) : "The message was " + msg;
  646.57 +        return msg;
  646.58 +    }
  646.59 +    @Http({
  646.60 +        @Http.Resource(path = "/url", content = "Hello via URL!", mimeType = "text/plain")
  646.61 +    })
  646.62 +    @BrwsrTest
  646.63 +    public String testReadContentViaURLWithStringParam() throws Exception {
  646.64 +        URL url = new URL("http:/url");
  646.65 +        String msg = (String) url.getContent(new Class[] { String.class });
  646.66 +        assert "Hello via URL!".equals(msg) : "The message was " + msg;
  646.67 +        return msg;
  646.68 +    }
  646.69 +
  646.70 +    @Http({
  646.71 +        @Http.Resource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
  646.72 +    })
  646.73 +    @BrwsrTest
  646.74 +    public void testReadByte() throws Exception {
  646.75 +        URL url = new URL("http:/bytes");
  646.76 +        final Object res = url.getContent(new Class[] { byte[].class });
  646.77 +        assert res instanceof byte[] : "Expecting byte[]: " + res;
  646.78 +        byte[] arr = (byte[]) res;
  646.79 +        assert arr.length == 1 : "One byte " + arr.length;
  646.80 +        assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
  646.81 +    }
  646.82 +
  646.83 +    @Http({
  646.84 +        @Http.Resource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
  646.85 +    })
  646.86 +    @BrwsrTest
  646.87 +    public void testReadByteViaInputStream() throws Exception {
  646.88 +        URL url = new URL("http:/bytes");
  646.89 +        InputStream is = url.openStream();
  646.90 +        byte[] arr = new byte[10];
  646.91 +        int len = is.read(arr);
  646.92 +        assert len == 1 : "One byte " + len;
  646.93 +        assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
  646.94 +    }
  646.95 +    
  646.96 +    @JavaScriptBody(args = { "url" }, body = 
  646.97 +          "var req = new XMLHttpRequest();\n"
  646.98 +        + "req.open('GET', url, false);\n"
  646.99 +        + "req.send();\n"
 646.100 +        + "return req.responseText;"
 646.101 +    )
 646.102 +    private static native String read(String url);
 646.103 +    
 646.104 +    
 646.105 +    @Factory
 646.106 +    public static Object[] create() {
 646.107 +        return VMTest.create(HttpResourceTest.class);
 646.108 +    }
 646.109 +}
   647.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   647.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceA.java	Wed Feb 27 11:24:58 2013 +0100
   647.3 @@ -0,0 +1,34 @@
   647.4 +/**
   647.5 + * Back 2 Browser Bytecode Translator
   647.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   647.7 + *
   647.8 + * This program is free software: you can redistribute it and/or modify
   647.9 + * it under the terms of the GNU General Public License as published by
  647.10 + * the Free Software Foundation, version 2 of the License.
  647.11 + *
  647.12 + * This program is distributed in the hope that it will be useful,
  647.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  647.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  647.15 + * GNU General Public License for more details.
  647.16 + *
  647.17 + * You should have received a copy of the GNU General Public License
  647.18 + * along with this program. Look for COPYING file in the top folder.
  647.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  647.20 + */
  647.21 +package org.apidesign.bck2brwsr.tck;
  647.22 +
  647.23 +/**
  647.24 + *
  647.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  647.26 + */
  647.27 +public class InheritanceA {
  647.28 +    private String name;
  647.29 +    
  647.30 +    public void setA(String n) {
  647.31 +        this.name = n;
  647.32 +    }
  647.33 +    
  647.34 +    public String getA() {
  647.35 +        return name;
  647.36 +    }
  647.37 +}
   648.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   648.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceB.java	Wed Feb 27 11:24:58 2013 +0100
   648.3 @@ -0,0 +1,34 @@
   648.4 +/**
   648.5 + * Back 2 Browser Bytecode Translator
   648.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   648.7 + *
   648.8 + * This program is free software: you can redistribute it and/or modify
   648.9 + * it under the terms of the GNU General Public License as published by
  648.10 + * the Free Software Foundation, version 2 of the License.
  648.11 + *
  648.12 + * This program is distributed in the hope that it will be useful,
  648.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  648.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  648.15 + * GNU General Public License for more details.
  648.16 + *
  648.17 + * You should have received a copy of the GNU General Public License
  648.18 + * along with this program. Look for COPYING file in the top folder.
  648.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  648.20 + */
  648.21 +package org.apidesign.bck2brwsr.tck;
  648.22 +
  648.23 +/**
  648.24 + *
  648.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  648.26 + */
  648.27 +public class InheritanceB extends InheritanceA {
  648.28 +    private String name;
  648.29 +    
  648.30 +    public void setB(String n) {
  648.31 +        this.name = n;
  648.32 +    }
  648.33 +    
  648.34 +    public String getB() {
  648.35 +        return name;
  648.36 +    }
  648.37 +}
   649.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   649.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceTest.java	Wed Feb 27 11:24:58 2013 +0100
   649.3 @@ -0,0 +1,41 @@
   649.4 +/**
   649.5 + * Back 2 Browser Bytecode Translator
   649.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   649.7 + *
   649.8 + * This program is free software: you can redistribute it and/or modify
   649.9 + * it under the terms of the GNU General Public License as published by
  649.10 + * the Free Software Foundation, version 2 of the License.
  649.11 + *
  649.12 + * This program is distributed in the hope that it will be useful,
  649.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  649.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  649.15 + * GNU General Public License for more details.
  649.16 + *
  649.17 + * You should have received a copy of the GNU General Public License
  649.18 + * along with this program. Look for COPYING file in the top folder.
  649.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  649.20 + */
  649.21 +package org.apidesign.bck2brwsr.tck;
  649.22 +
  649.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  649.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  649.25 +import org.testng.annotations.Factory;
  649.26 +
  649.27 +/**
  649.28 + *
  649.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  649.30 + */
  649.31 +public class InheritanceTest {
  649.32 +
  649.33 +    @Compare public String checkFieldsIndependent() throws ClassNotFoundException {
  649.34 +        InheritanceB ib = new InheritanceB();
  649.35 +        ib.setA("A");
  649.36 +        ib.setB("B");
  649.37 +        return "A: " + ib.getA() + " B: " + ib.getB();
  649.38 +    }
  649.39 +    
  649.40 +    @Factory
  649.41 +    public static Object[] create() {
  649.42 +        return VMTest.create(InheritanceTest.class);
  649.43 +    }
  649.44 +}
   650.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   650.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Wed Feb 27 11:24:58 2013 +0100
   650.3 @@ -0,0 +1,150 @@
   650.4 +/**
   650.5 + * Back 2 Browser Bytecode Translator
   650.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   650.7 + *
   650.8 + * This program is free software: you can redistribute it and/or modify
   650.9 + * it under the terms of the GNU General Public License as published by
  650.10 + * the Free Software Foundation, version 2 of the License.
  650.11 + *
  650.12 + * This program is distributed in the hope that it will be useful,
  650.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  650.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  650.15 + * GNU General Public License for more details.
  650.16 + *
  650.17 + * You should have received a copy of the GNU General Public License
  650.18 + * along with this program. Look for COPYING file in the top folder.
  650.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  650.20 + */
  650.21 +package org.apidesign.bck2brwsr.tck;
  650.22 +
  650.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  650.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  650.25 +import org.testng.annotations.Factory;
  650.26 +
  650.27 +/**
  650.28 + *
  650.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  650.30 + */
  650.31 +public class IntegerArithmeticTest {
  650.32 +    
  650.33 +    private static int add(int x, int y) {
  650.34 +        return x + y;
  650.35 +    }
  650.36 +    
  650.37 +    private static int sub(int x, int y) {
  650.38 +        return x - y;
  650.39 +    }
  650.40 +    
  650.41 +    private static int mul(int x, int y) {
  650.42 +        return x * y;
  650.43 +    }
  650.44 +    
  650.45 +    private static int div(int x, int y) {
  650.46 +        return x / y;
  650.47 +    }
  650.48 +    
  650.49 +    private static int mod(int x, int y) {
  650.50 +        return x % y;
  650.51 +    }
  650.52 +    
  650.53 +    private static int neg(int x) {
  650.54 +        return (-x);
  650.55 +    }
  650.56 +    
  650.57 +    @Compare public int addOverflow() {
  650.58 +        return add(Integer.MAX_VALUE, 1);
  650.59 +    }
  650.60 +    
  650.61 +    @Compare public int subUnderflow() {
  650.62 +        return sub(Integer.MIN_VALUE, 1);
  650.63 +    }
  650.64 +    
  650.65 +    @Compare public int addMaxIntAndMaxInt() {
  650.66 +        return add(Integer.MAX_VALUE, Integer.MAX_VALUE);
  650.67 +    }
  650.68 +    
  650.69 +    @Compare public int subMinIntAndMinInt() {
  650.70 +        return sub(Integer.MIN_VALUE, Integer.MIN_VALUE);
  650.71 +    }
  650.72 +    
  650.73 +    @Compare public int multiplyMaxInt() {
  650.74 +        return mul(Integer.MAX_VALUE, 2);
  650.75 +    }
  650.76 +    
  650.77 +    @Compare public int multiplyMaxIntAndMaxInt() {
  650.78 +        return mul(Integer.MAX_VALUE, Integer.MAX_VALUE);
  650.79 +    }
  650.80 +    
  650.81 +    @Compare public int multiplyMinInt() {
  650.82 +        return mul(Integer.MIN_VALUE, 2);
  650.83 +    }
  650.84 +    
  650.85 +    @Compare public int multiplyMinIntAndMinInt() {
  650.86 +        return mul(Integer.MIN_VALUE, Integer.MIN_VALUE);
  650.87 +    }
  650.88 +    
  650.89 +    @Compare public int multiplyPrecision() {
  650.90 +        return mul(119106029, 1103515245);
  650.91 +    }
  650.92 +    
  650.93 +    @Compare public int division() {
  650.94 +        return div(1, 2);
  650.95 +    }
  650.96 +    
  650.97 +    @Compare public int divisionReminder() {
  650.98 +        return mod(1, 2);
  650.99 +    }
 650.100 +
 650.101 +    @Compare public int negativeDivision() {
 650.102 +        return div(-7, 3);
 650.103 +    }
 650.104 +
 650.105 +    @Compare public int negativeDivisionReminder() {
 650.106 +        return mod(-7, 3);
 650.107 +    }
 650.108 +
 650.109 +    @Compare public boolean divByZeroThrowsArithmeticException() {
 650.110 +        try {
 650.111 +            div(1, 0);
 650.112 +            return false;
 650.113 +        } catch (final ArithmeticException e) {
 650.114 +            return true;
 650.115 +        }
 650.116 +    }
 650.117 +
 650.118 +    @Compare public boolean modByZeroThrowsArithmeticException() {
 650.119 +        try {
 650.120 +            mod(1, 0);
 650.121 +            return false;
 650.122 +        } catch (final ArithmeticException e) {
 650.123 +            return true;
 650.124 +        }
 650.125 +    }
 650.126 +
 650.127 +    @Compare public int negate() {
 650.128 +        return neg(123456);
 650.129 +    }
 650.130 +    
 650.131 +    @Compare public int negateMaxInt() {
 650.132 +        return neg(Integer.MAX_VALUE);
 650.133 +    }
 650.134 +    
 650.135 +    @Compare public int negateMinInt() {
 650.136 +        return neg(Integer.MIN_VALUE);
 650.137 +    }
 650.138 +    
 650.139 +    @Compare public int sumTwoDimensions() {
 650.140 +        int[][] matrix = createMatrix(4, 3);
 650.141 +        matrix[0][0] += 10;
 650.142 +        return matrix[0][0];
 650.143 +    }
 650.144 +    
 650.145 +    static int[][] createMatrix(int x, int y) {
 650.146 +        return new int[x][y];
 650.147 +    }
 650.148 +    
 650.149 +    @Factory
 650.150 +    public static Object[] create() {
 650.151 +        return VMTest.create(IntegerArithmeticTest.class);
 650.152 +    }
 650.153 +}
   651.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   651.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java	Wed Feb 27 11:24:58 2013 +0100
   651.3 @@ -0,0 +1,352 @@
   651.4 +/**
   651.5 + * Back 2 Browser Bytecode Translator
   651.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   651.7 + *
   651.8 + * This program is free software: you can redistribute it and/or modify
   651.9 + * it under the terms of the GNU General Public License as published by
  651.10 + * the Free Software Foundation, version 2 of the License.
  651.11 + *
  651.12 + * This program is distributed in the hope that it will be useful,
  651.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  651.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  651.15 + * GNU General Public License for more details.
  651.16 + *
  651.17 + * You should have received a copy of the GNU General Public License
  651.18 + * along with this program. Look for COPYING file in the top folder.
  651.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  651.20 + */
  651.21 +package org.apidesign.bck2brwsr.tck;
  651.22 +
  651.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  651.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  651.25 +import org.testng.annotations.Factory;
  651.26 +
  651.27 +/**
  651.28 + *
  651.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  651.30 + */
  651.31 +public class LongArithmeticTest {
  651.32 +    
  651.33 +    private static long add(long x, long y) {
  651.34 +        return (x + y);
  651.35 +    }
  651.36 +    
  651.37 +    private static long sub(long x, long y) {
  651.38 +        return (x - y);
  651.39 +    }
  651.40 +    
  651.41 +    private static long mul(long x, long y) {
  651.42 +        return (x * y);
  651.43 +    }
  651.44 +    
  651.45 +    private static long div(long x, long y) {
  651.46 +        return (x / y);
  651.47 +    }
  651.48 +    
  651.49 +    private static long mod(long x, long y) {
  651.50 +        return (x % y);
  651.51 +    }
  651.52 +    
  651.53 +    private static long neg(long x) {
  651.54 +        return (-x);
  651.55 +    }
  651.56 +    
  651.57 +    private static long shl(long x, int b) {
  651.58 +        return (x << b);
  651.59 +    }
  651.60 +    
  651.61 +    private static long shr(long x, int b) {
  651.62 +        return (x >> b);
  651.63 +    }
  651.64 +    
  651.65 +    private static long ushr(long x, int b) {
  651.66 +        return (x >>> b);
  651.67 +    }
  651.68 +    
  651.69 +    private static long and(long x, long y) {
  651.70 +        return (x & y);
  651.71 +    }
  651.72 +    
  651.73 +    private static long or(long x, long y) {
  651.74 +        return (x | y);
  651.75 +    }
  651.76 +    
  651.77 +    private static long xor(long x, long y) {
  651.78 +        return (x ^ y);
  651.79 +    }
  651.80 +    
  651.81 +    public static int compare(long x, long y, int zero) {
  651.82 +        final int xyResult = compareL(x, y, zero);
  651.83 +        final int yxResult = compareL(y, x, zero);
  651.84 +
  651.85 +        return ((xyResult + yxResult) == 0) ? xyResult : -2;
  651.86 +    }
  651.87 +
  651.88 +    private static int compareL(long x, long y, int zero) {
  651.89 +        int result = -2;
  651.90 +        int trueCount = 0;
  651.91 +
  651.92 +        x += zero;
  651.93 +        if (x == y) {
  651.94 +            result = 0;
  651.95 +            ++trueCount;
  651.96 +        }
  651.97 +
  651.98 +        x += zero;
  651.99 +        if (x < y) {
 651.100 +            result = -1;
 651.101 +            ++trueCount;
 651.102 +        }
 651.103 +
 651.104 +        x += zero;
 651.105 +        if (x > y) {
 651.106 +            result = 1;
 651.107 +            ++trueCount;
 651.108 +        }
 651.109 +
 651.110 +        return (trueCount == 1) ? result : -2;
 651.111 +    }
 651.112 +    
 651.113 +    @Compare public long conversion() {
 651.114 +        return Long.MAX_VALUE;
 651.115 +    }
 651.116 +    
 651.117 +    @Compare public long negate1() {
 651.118 +        return neg(0x00fa37d7763e0ca1l);
 651.119 +    }
 651.120 +    
 651.121 +    @Compare public long negate2() {
 651.122 +        return neg(0x80fa37d7763e0ca1l);
 651.123 +    }
 651.124 +
 651.125 +    @Compare public long negate3() {
 651.126 +        return neg(0xfffffffffffffeddl);
 651.127 +    }
 651.128 +
 651.129 +    @Compare public long addOverflow() {
 651.130 +        return add(Long.MAX_VALUE, 1l);
 651.131 +    }
 651.132 +
 651.133 +    @Compare public long subUnderflow() {
 651.134 +        return sub(Long.MIN_VALUE, 1l);
 651.135 +    }
 651.136 +
 651.137 +    @Compare public long addMaxLongAndMaxLong() {
 651.138 +        return add(Long.MAX_VALUE, Long.MAX_VALUE);
 651.139 +    }
 651.140 +    
 651.141 +    @Compare public long subMinLongAndMinLong() {
 651.142 +        return sub(Long.MIN_VALUE, Long.MIN_VALUE);
 651.143 +    }
 651.144 +    
 651.145 +    @Compare public long subMinLongAndMaxLong() {
 651.146 +        return sub(Long.MIN_VALUE, Long.MAX_VALUE);
 651.147 +    }
 651.148 +
 651.149 +    @Compare public long multiplyMaxLong() {
 651.150 +        return mul(Long.MAX_VALUE, 2l);
 651.151 +    }
 651.152 +    
 651.153 +    @Compare public long multiplyMaxLongAndMaxLong() {
 651.154 +        return mul(Long.MAX_VALUE, Long.MAX_VALUE);
 651.155 +    }
 651.156 +    
 651.157 +    @Compare public long multiplyMinLong() {
 651.158 +        return mul(Long.MIN_VALUE, 2l);
 651.159 +    }
 651.160 +    
 651.161 +    @Compare public long multiplyMinLongAndMinLong() {
 651.162 +        return mul(Long.MIN_VALUE, Long.MIN_VALUE);
 651.163 +    }
 651.164 +    
 651.165 +    @Compare public long multiplyPrecision() {
 651.166 +        return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 651.167 +    }
 651.168 +    
 651.169 +    @Compare public long divideSmallPositiveNumbers() {
 651.170 +        return div(0xabcdef, 0x123);
 651.171 +    }
 651.172 +
 651.173 +    @Compare public long divideSmallNegativeNumbers() {
 651.174 +        return div(-0xabcdef, -0x123);
 651.175 +    }
 651.176 +
 651.177 +    @Compare public long divideSmallMixedNumbers() {
 651.178 +        return div(0xabcdef, -0x123);
 651.179 +    }
 651.180 +
 651.181 +    @Compare public long dividePositiveNumbersOneDigitDenom() {
 651.182 +        return div(0xabcdef0102ffffl, 0x654);
 651.183 +    }
 651.184 +
 651.185 +    @Compare public long divideNegativeNumbersOneDigitDenom() {
 651.186 +        return div(-0xabcdef0102ffffl, -0x654);
 651.187 +    }
 651.188 +
 651.189 +    @Compare public long divideMixedNumbersOneDigitDenom() {
 651.190 +        return div(-0xabcdef0102ffffl, 0x654);
 651.191 +    }
 651.192 +
 651.193 +    @Compare public long dividePositiveNumbersMultiDigitDenom() {
 651.194 +        return div(0x7ffefc003322aabbl, 0x89ab1000l);
 651.195 +    }
 651.196 +
 651.197 +    @Compare public long divideNegativeNumbersMultiDigitDenom() {
 651.198 +        return div(-0x7ffefc003322aabbl, -0x123489ab1001l);
 651.199 +    }
 651.200 +
 651.201 +    @Compare public long divideMixedNumbersMultiDigitDenom() {
 651.202 +        return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
 651.203 +    }
 651.204 +
 651.205 +    @Compare public long divideWithOverflow() {
 651.206 +        return div(0x8000fffe0000l, 0x8000ffffl);
 651.207 +    }
 651.208 +
 651.209 +    @Compare public long divideWithCorrection() {
 651.210 +        return div(0x7fff800000000000l, 0x800000000001l);
 651.211 +    }
 651.212 +
 651.213 +    @Compare public long moduloSmallPositiveNumbers() {
 651.214 +        return mod(0xabcdef, 0x123);
 651.215 +    }
 651.216 +
 651.217 +    @Compare public long moduloSmallNegativeNumbers() {
 651.218 +        return mod(-0xabcdef, -0x123);
 651.219 +    }
 651.220 +
 651.221 +    @Compare public long moduloSmallMixedNumbers() {
 651.222 +        return mod(0xabcdef, -0x123);
 651.223 +    }
 651.224 +
 651.225 +    @Compare public long moduloPositiveNumbersOneDigitDenom() {
 651.226 +        return mod(0xabcdef0102ffffl, 0x654);
 651.227 +    }
 651.228 +
 651.229 +    @Compare public long moduloNegativeNumbersOneDigitDenom() {
 651.230 +        return mod(-0xabcdef0102ffffl, -0x654);
 651.231 +    }
 651.232 +
 651.233 +    @Compare public long moduloMixedNumbersOneDigitDenom() {
 651.234 +        return mod(-0xabcdef0102ffffl, 0x654);
 651.235 +    }
 651.236 +
 651.237 +    @Compare public long moduloPositiveNumbersMultiDigitDenom() {
 651.238 +        return mod(0x7ffefc003322aabbl, 0x89ab1000l);
 651.239 +    }
 651.240 +
 651.241 +    @Compare public long moduloNegativeNumbersMultiDigitDenom() {
 651.242 +        return mod(-0x7ffefc003322aabbl, -0x123489ab1001l);
 651.243 +    }
 651.244 +
 651.245 +    @Compare public long moduloMixedNumbersMultiDigitDenom() {
 651.246 +        return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
 651.247 +    }
 651.248 +
 651.249 +    @Compare public long moduloWithOverflow() {
 651.250 +        return mod(0x8000fffe0000l, 0x8000ffffl);
 651.251 +    }
 651.252 +
 651.253 +    @Compare public long moduloWithCorrection() {
 651.254 +        return mod(0x7fff800000000000l, 0x800000000001l);
 651.255 +    }
 651.256 +
 651.257 +    @Compare public boolean divByZeroThrowsArithmeticException() {
 651.258 +        try {
 651.259 +            div(1, 0);
 651.260 +            return false;
 651.261 +        } catch (final ArithmeticException e) {
 651.262 +            return true;
 651.263 +        }
 651.264 +    }
 651.265 +
 651.266 +    @Compare public boolean modByZeroThrowsArithmeticException() {
 651.267 +        try {
 651.268 +            mod(1, 0);
 651.269 +            return false;
 651.270 +        } catch (final ArithmeticException e) {
 651.271 +            return true;
 651.272 +        }
 651.273 +    }
 651.274 +
 651.275 +    @Compare public long shiftL1() {
 651.276 +        return shl(0x00fa37d7763e0ca1l, 5);
 651.277 +    }
 651.278 +    
 651.279 +    @Compare public long shiftL2() {
 651.280 +        return shl(0x00fa37d7763e0ca1l, 32);
 651.281 +    }
 651.282 +    
 651.283 +    @Compare public long shiftL3() {
 651.284 +        return shl(0x00fa37d7763e0ca1l, 45);
 651.285 +    }
 651.286 +    
 651.287 +    @Compare public long shiftR1() {
 651.288 +        return shr(0x00fa37d7763e0ca1l, 5);
 651.289 +    }
 651.290 +    
 651.291 +    @Compare public long shiftR2() {
 651.292 +        return shr(0x00fa37d7763e0ca1l, 32);
 651.293 +    }
 651.294 +    
 651.295 +    @Compare public long shiftR3() {
 651.296 +        return shr(0x00fa37d7763e0ca1l, 45);
 651.297 +    }
 651.298 +    
 651.299 +    @Compare public long uShiftR1() {
 651.300 +        return ushr(0x00fa37d7763e0ca1l, 5);
 651.301 +    }
 651.302 +    
 651.303 +    @Compare public long uShiftR2() {
 651.304 +        return ushr(0x00fa37d7763e0ca1l, 45);
 651.305 +    }
 651.306 +    
 651.307 +    @Compare public long uShiftR3() {
 651.308 +        return ushr(0xf0fa37d7763e0ca1l, 5);
 651.309 +    }
 651.310 +    
 651.311 +    @Compare public long uShiftR4() {
 651.312 +        return ushr(0xf0fa37d7763e0ca1l, 45);
 651.313 +    }
 651.314 +    
 651.315 +    @Compare public long and1() {
 651.316 +        return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 651.317 +    }
 651.318 +    
 651.319 +    @Compare public long or1() {
 651.320 +        return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 651.321 +    }
 651.322 +    
 651.323 +    @Compare public long xor1() {
 651.324 +        return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 651.325 +    }
 651.326 +    
 651.327 +    @Compare public long xor2() {
 651.328 +        return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
 651.329 +    }
 651.330 +    
 651.331 +    @Compare public long xor3() {
 651.332 +        return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
 651.333 +    }
 651.334 +    
 651.335 +    @Compare public int compareSameNumbers() {
 651.336 +        return compare(0x0000000000000000l, 0x0000000000000000l, 0);
 651.337 +    }
 651.338 +
 651.339 +    @Compare public int comparePositiveNumbers() {
 651.340 +        return compare(0x0000000000200000l, 0x0000000010000000l, 0);
 651.341 +    }
 651.342 +
 651.343 +    @Compare public int compareNegativeNumbers() {
 651.344 +        return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0);
 651.345 +    }
 651.346 +
 651.347 +    @Compare public int compareMixedNumbers() {
 651.348 +        return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0);
 651.349 +    }
 651.350 +    
 651.351 +    @Factory
 651.352 +    public static Object[] create() {
 651.353 +        return VMTest.create(LongArithmeticTest.class);
 651.354 +    }
 651.355 +}
   652.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   652.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java	Wed Feb 27 11:24:58 2013 +0100
   652.3 @@ -0,0 +1,135 @@
   652.4 +/**
   652.5 + * Back 2 Browser Bytecode Translator
   652.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   652.7 + *
   652.8 + * This program is free software: you can redistribute it and/or modify
   652.9 + * it under the terms of the GNU General Public License as published by
  652.10 + * the Free Software Foundation, version 2 of the License.
  652.11 + *
  652.12 + * This program is distributed in the hope that it will be useful,
  652.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  652.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  652.15 + * GNU General Public License for more details.
  652.16 + *
  652.17 + * You should have received a copy of the GNU General Public License
  652.18 + * along with this program. Look for COPYING file in the top folder.
  652.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  652.20 + */
  652.21 +package org.apidesign.bck2brwsr.tck;
  652.22 +
  652.23 +import java.lang.reflect.Array;
  652.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
  652.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  652.26 +import org.testng.annotations.Factory;
  652.27 +
  652.28 +/**
  652.29 + *
  652.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  652.31 + */
  652.32 +public class ReflectionArrayTest {
  652.33 +    @Compare public int lengthOfStringArray() {
  652.34 +        String[] arr = (String[]) Array.newInstance(String.class, 10);
  652.35 +        return arr.length;
  652.36 +    }
  652.37 +    
  652.38 +    @Compare public int reflectiveLengthOfStringArray() {
  652.39 +        Object arr = Array.newInstance(String.class, 10);
  652.40 +        return Array.getLength(arr);
  652.41 +    }
  652.42 +
  652.43 +    @Compare public int reflectiveLengthOneNonArray() {
  652.44 +        Object arr = "non-array";
  652.45 +        return Array.getLength(arr);
  652.46 +    }
  652.47 +
  652.48 +    @Compare public String compTypeOfStringArray() {
  652.49 +        String[] arr = (String[]) Array.newInstance(String.class, 10);
  652.50 +        return arr.getClass().getComponentType().getName();
  652.51 +    }
  652.52 +
  652.53 +    @Compare public Object negativeArrayExcp() {
  652.54 +        return Array.newInstance(String.class, -5);
  652.55 +    }
  652.56 +    
  652.57 +    @Compare public int lengthOfIntArray() {
  652.58 +        int[] arr = (int[]) Array.newInstance(Integer.TYPE, 10);
  652.59 +        return arr.length;
  652.60 +    }
  652.61 +
  652.62 +    @Compare public int reflectiveLengthOfIntArray() {
  652.63 +        Object arr = Array.newInstance(Integer.TYPE, 10);
  652.64 +        return Array.getLength(arr);
  652.65 +    }
  652.66 +
  652.67 +    @Compare public String compTypeOfIntArray() {
  652.68 +        int[] arr = (int[]) Array.newInstance(int.class, 10);
  652.69 +        return arr.getClass().getComponentType().getName();
  652.70 +    }
  652.71 +
  652.72 +    @Compare public Object intNegativeArrayExcp() {
  652.73 +        return Array.newInstance(int.class, -5);
  652.74 +    }
  652.75 +
  652.76 +    @Compare public Integer verifyAutobox() {
  652.77 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
  652.78 +        return (Integer) Array.get(arr, 0);
  652.79 +    }
  652.80 +    @Compare public String verifyObjectArray() {
  652.81 +        String[] arr = (String[]) Array.newInstance(String.class, 5);
  652.82 +        Array.set(arr, 0, "Hello");
  652.83 +        return (String) Array.get(arr, 0);
  652.84 +    }
  652.85 +    @Compare public int verifyInt() {
  652.86 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
  652.87 +        return Array.getInt(arr, 0);
  652.88 +    }
  652.89 +    @Compare public long verifyConvertToLong() {
  652.90 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
  652.91 +        return Array.getLong(arr, 0);
  652.92 +    }
  652.93 +
  652.94 +    @Compare public Object verifySetIntToObject() {
  652.95 +        try {
  652.96 +            Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
  652.97 +            Array.setInt(arr, 0, 10);
  652.98 +            return Array.get(arr, 0);
  652.99 +        } catch (Exception exception) {
 652.100 +            return exception.getClass().getName();
 652.101 +        }
 652.102 +    }
 652.103 +    @Compare public long verifySetShort() {
 652.104 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
 652.105 +        Array.setShort(arr, 0, (short)10);
 652.106 +        return Array.getLong(arr, 0);
 652.107 +    }
 652.108 +    @Compare public long verifyCantSetLong() {
 652.109 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
 652.110 +        Array.setLong(arr, 0, 10);
 652.111 +        return Array.getLong(arr, 0);
 652.112 +    }
 652.113 +    @Compare public float verifyLongToFloat() {
 652.114 +        Object arr = Array.newInstance(float.class, 5);
 652.115 +        Array.setLong(arr, 0, 10);
 652.116 +        return Array.getFloat(arr, 0);
 652.117 +    }
 652.118 +
 652.119 +    @Compare public double verifyConvertToDouble() {
 652.120 +        int[] arr = (int[]) Array.newInstance(int.class, 5);
 652.121 +        return Array.getDouble(arr, 0);
 652.122 +    }
 652.123 +    
 652.124 +    @Compare public int multiIntArray() {
 652.125 +        int[][][] arr = (int[][][]) Array.newInstance(int.class, 3, 3, 3);
 652.126 +        return arr[0][1][2] + 5 + arr[2][2][0];
 652.127 +    }
 652.128 +
 652.129 +    @Compare public String multiIntArrayCompType() {
 652.130 +        return Array.newInstance(int.class, 3, 3, 3).getClass().getName();
 652.131 +    }
 652.132 +    
 652.133 +    
 652.134 +    @Factory
 652.135 +    public static Object[] create() {
 652.136 +        return VMTest.create(ReflectionArrayTest.class);
 652.137 +    }
 652.138 +}
   653.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   653.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Wed Feb 27 11:24:58 2013 +0100
   653.3 @@ -0,0 +1,242 @@
   653.4 +/**
   653.5 + * Back 2 Browser Bytecode Translator
   653.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   653.7 + *
   653.8 + * This program is free software: you can redistribute it and/or modify
   653.9 + * it under the terms of the GNU General Public License as published by
  653.10 + * the Free Software Foundation, version 2 of the License.
  653.11 + *
  653.12 + * This program is distributed in the hope that it will be useful,
  653.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  653.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  653.15 + * GNU General Public License for more details.
  653.16 + *
  653.17 + * You should have received a copy of the GNU General Public License
  653.18 + * along with this program. Look for COPYING file in the top folder.
  653.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  653.20 + */
  653.21 +package org.apidesign.bck2brwsr.tck;
  653.22 +
  653.23 +import java.lang.annotation.Retention;
  653.24 +import java.lang.annotation.RetentionPolicy;
  653.25 +import java.lang.reflect.Method;
  653.26 +import java.util.Arrays;
  653.27 +import java.util.Collections;
  653.28 +import java.util.List;
  653.29 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  653.30 +import org.apidesign.bck2brwsr.vmtest.Compare;
  653.31 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  653.32 +import org.testng.annotations.Factory;
  653.33 +
  653.34 +/**
  653.35 + *
  653.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  653.37 + */
  653.38 +public class ReflectionTest {
  653.39 +    @Compare public boolean nonNullThis() {
  653.40 +        return this == null;
  653.41 +    }
  653.42 +    
  653.43 +    @Compare public String intType() {
  653.44 +        return Integer.TYPE.toString();
  653.45 +    }
  653.46 +
  653.47 +    @Compare public String voidType() throws Exception {
  653.48 +        return void.class.toString();
  653.49 +    }
  653.50 +
  653.51 +    @Compare public String longClass() {
  653.52 +        return long.class.toString();
  653.53 +    }
  653.54 +    
  653.55 +    @Compare public boolean isRunnableInterface() {
  653.56 +        return Runnable.class.isInterface();
  653.57 +    }
  653.58 +
  653.59 +    @Compare public String isRunnableHasRunMethod() throws NoSuchMethodException {
  653.60 +        return Runnable.class.getMethod("run").getName();
  653.61 +    }
  653.62 +    
  653.63 +    @Compare public String namesOfMethods() {
  653.64 +        StringBuilder sb = new StringBuilder();
  653.65 +        String[] arr = new String[20];
  653.66 +        int i = 0;
  653.67 +        for (Method m : StaticUse.class.getMethods()) {
  653.68 +            arr[i++] = m.getName();
  653.69 +        }
  653.70 +        for (String s : sort(arr, i)) {
  653.71 +            sb.append(s).append("\n");
  653.72 +        }
  653.73 +        return sb.toString();
  653.74 +    }
  653.75 +
  653.76 +    @Compare public String namesOfDeclaringClassesOfMethods() {
  653.77 +        StringBuilder sb = new StringBuilder();
  653.78 +        String[] arr = new String[20];
  653.79 +        int i = 0;
  653.80 +        for (Method m : StaticUse.class.getMethods()) {
  653.81 +            arr[i++] = m.getName() + "@" + m.getDeclaringClass().getName();
  653.82 +        }
  653.83 +        for (String s : sort(arr, i)) {
  653.84 +            sb.append(s).append("\n");
  653.85 +        }
  653.86 +        return sb.toString();
  653.87 +    }
  653.88 +    
  653.89 +    @Compare public String cannotCallNonStaticMethodWithNull() throws Exception {
  653.90 +        StaticUse.class.getMethod("instanceMethod").invoke(null);
  653.91 +        return "should not happen";
  653.92 +    }
  653.93 +
  653.94 +    @Compare public Object voidReturnType() throws Exception {
  653.95 +        return StaticUse.class.getMethod("instanceMethod").getReturnType();
  653.96 +    }
  653.97 +    
  653.98 +    @Retention(RetentionPolicy.RUNTIME)
  653.99 +    @interface Ann {
 653.100 +    }
 653.101 +    
 653.102 +    @Compare public String annoClass() throws Exception {
 653.103 +        Retention r = Ann.class.getAnnotation(Retention.class);
 653.104 +        assert r != null : "Annotation is present";
 653.105 +        assert r.value() == RetentionPolicy.RUNTIME : "Policy value is OK: " + r.value();
 653.106 +        return r.annotationType().getName();
 653.107 +    }
 653.108 +    
 653.109 +    @Compare public boolean isAnnotation() {
 653.110 +        return Ann.class.isAnnotation();
 653.111 +    }
 653.112 +    @Compare public boolean isNotAnnotation() {
 653.113 +        return String.class.isAnnotation();
 653.114 +    }
 653.115 +    @Compare public boolean isNotAnnotationEnum() {
 653.116 +        return E.class.isAnnotation();
 653.117 +    }
 653.118 +    enum E { A, B };
 653.119 +    @Compare public boolean isEnum() {
 653.120 +        return E.A.getClass().isEnum();
 653.121 +    }
 653.122 +
 653.123 +    @Compare public boolean isNotEnum() {
 653.124 +        return "".getClass().isEnum();
 653.125 +    }
 653.126 +    
 653.127 +    @Compare public String newInstanceFails() throws InstantiationException {
 653.128 +        try {
 653.129 +            return "success: " + StaticUse.class.newInstance();
 653.130 +        } catch (IllegalAccessException ex) {
 653.131 +            return ex.getClass().getName();
 653.132 +        }
 653.133 +    }
 653.134 +    
 653.135 +    @Compare public String paramTypes() throws Exception {
 653.136 +        Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
 653.137 +        final Class[] pt = plus.getParameterTypes();
 653.138 +        return pt[0].getName();
 653.139 +    }
 653.140 +    @Compare public String paramTypesNotFound() throws Exception {
 653.141 +        return StaticUse.class.getMethod("plus", int.class, double.class).toString();
 653.142 +    }
 653.143 +    @Compare public int methodWithArgs() throws Exception {
 653.144 +        Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
 653.145 +        return (Integer)plus.invoke(null, 2, 3);
 653.146 +    }
 653.147 +    
 653.148 +    @Compare public String classGetNameForByte() {
 653.149 +         return byte.class.getName();
 653.150 +    }
 653.151 +    @Compare public String classGetNameForBaseObject() {
 653.152 +        return newObject().getClass().getName();
 653.153 +    }
 653.154 +    @Compare public String classGetNameForJavaObject() {
 653.155 +        return new Object().getClass().getName();
 653.156 +    }
 653.157 +    @Compare public String classGetNameForObjectArray() {
 653.158 +        return (new Object[3]).getClass().getName();
 653.159 +    }
 653.160 +    @Compare public String classGetNameForSimpleIntArray() {
 653.161 +        return (new int[3]).getClass().getName();
 653.162 +    }
 653.163 +    @Compare public boolean sameClassGetNameForSimpleCharArray() {
 653.164 +        return (new char[3]).getClass() == (new char[34]).getClass();
 653.165 +    }
 653.166 +    @Compare public String classGetNameForMultiIntArray() {
 653.167 +        return (new int[3][4][5][6][7][8][9]).getClass().getName();
 653.168 +    }
 653.169 +    @Compare public String classGetNameForMultiIntArrayInner() {
 653.170 +        final int[][][][][][][] arr = new int[3][4][5][6][7][8][9];
 653.171 +        int[][][][][][] subarr = arr[0];
 653.172 +        int[][][][][] subsubarr = subarr[0];
 653.173 +        return subsubarr.getClass().getName();
 653.174 +    }
 653.175 +    @Compare public String classGetNameForMultiStringArray() {
 653.176 +        return (new String[3][4][5][6][7][8][9]).getClass().getName();
 653.177 +    }
 653.178 +    
 653.179 +    @Compare public String classForByte() throws Exception {
 653.180 +        return Class.forName("[Z").getName();
 653.181 +    }
 653.182 +
 653.183 +    @Compare public String classForUnknownArray() {
 653.184 +        try {
 653.185 +            return Class.forName("[W").getName();
 653.186 +        } catch (Exception ex) {
 653.187 +            return ex.getClass().getName();
 653.188 +        }
 653.189 +    }
 653.190 +    
 653.191 +    @Compare public String classForUnknownDeepArray() {
 653.192 +        try {
 653.193 +            return Class.forName("[[[[[W").getName();
 653.194 +        } catch (Exception ex) {
 653.195 +            return ex.getClass().getName();
 653.196 +        }
 653.197 +    }
 653.198 +    
 653.199 +    @Compare public String componentGetNameForObjectArray() {
 653.200 +        return (new Object[3]).getClass().getComponentType().getName();
 653.201 +    }
 653.202 +    @Compare public boolean sameComponentGetNameForObjectArray() {
 653.203 +        return (new Object[3]).getClass().getComponentType() == Object.class;
 653.204 +    }
 653.205 +    @Compare public String componentGetNameForSimpleIntArray() {
 653.206 +        return (new int[3]).getClass().getComponentType().getName();
 653.207 +    }
 653.208 +    @Compare public String componentGetNameForMultiIntArray() {
 653.209 +        return (new int[3][4][5][6][7][8][9]).getClass().getComponentType().getName();
 653.210 +    }
 653.211 +    @Compare public String componentGetNameForMultiStringArray() {
 653.212 +        Class<?> c = (new String[3][4][5][6][7][8][9]).getClass();
 653.213 +        StringBuilder sb = new StringBuilder();
 653.214 +        for (;;) {
 653.215 +            sb.append(c.getName()).append("\n");
 653.216 +            c = c.getComponentType();
 653.217 +            if (c == null) {
 653.218 +                break;
 653.219 +            }
 653.220 +        }
 653.221 +        return sb.toString();
 653.222 +    }
 653.223 +    
 653.224 +    @Compare public boolean isArray() {
 653.225 +        return new Object[0].getClass().isArray();
 653.226 +    }
 653.227 +    
 653.228 +    @JavaScriptBody(args = { "arr", "len" }, body="var a = arr.slice(0, len); a.sort(); return a;")
 653.229 +    private static String[] sort(String[] arr, int len) {
 653.230 +        List<String> list = Arrays.asList(arr).subList(0, len);
 653.231 +        Collections.sort(list);
 653.232 +        return list.toArray(new String[0]);
 653.233 +    }
 653.234 +    
 653.235 +    @JavaScriptBody(args = {}, body = "return new Object();")
 653.236 +    private static Object newObject() {
 653.237 +        return new Object();
 653.238 +    }
 653.239 +    
 653.240 +    @Factory
 653.241 +    public static Object[] create() {
 653.242 +        return VMTest.create(ReflectionTest.class);
 653.243 +    }
 653.244 +    
 653.245 +}
   654.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   654.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java	Wed Feb 27 11:24:58 2013 +0100
   654.3 @@ -0,0 +1,45 @@
   654.4 +/**
   654.5 + * Back 2 Browser Bytecode Translator
   654.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   654.7 + *
   654.8 + * This program is free software: you can redistribute it and/or modify
   654.9 + * it under the terms of the GNU General Public License as published by
  654.10 + * the Free Software Foundation, version 2 of the License.
  654.11 + *
  654.12 + * This program is distributed in the hope that it will be useful,
  654.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  654.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  654.15 + * GNU General Public License for more details.
  654.16 + *
  654.17 + * You should have received a copy of the GNU General Public License
  654.18 + * along with this program. Look for COPYING file in the top folder.
  654.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  654.20 + */
  654.21 +package org.apidesign.bck2brwsr.tck;
  654.22 +
  654.23 +import java.io.InputStream;
  654.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
  654.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  654.26 +import org.testng.annotations.Factory;
  654.27 +
  654.28 +/**
  654.29 + *
  654.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  654.31 + */
  654.32 +public class ResourcesTest {
  654.33 +    
  654.34 +    @Compare public String readResourceAsStream() throws Exception {
  654.35 +        InputStream is = getClass().getResourceAsStream("Resources.txt");
  654.36 +        byte[] b = new byte[30];
  654.37 +        int len = is.read(b);
  654.38 +        StringBuilder sb = new StringBuilder();
  654.39 +        for (int i = 0; i < len; i++) {
  654.40 +            sb.append((char)b[i]);
  654.41 +        }
  654.42 +        return sb.toString();
  654.43 +    }
  654.44 +    
  654.45 +    @Factory public static Object[] create() {
  654.46 +        return VMTest.create(ResourcesTest.class);
  654.47 +    }
  654.48 +}
   655.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   655.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java	Wed Feb 27 11:24:58 2013 +0100
   655.3 @@ -0,0 +1,102 @@
   655.4 +/**
   655.5 + * Back 2 Browser Bytecode Translator
   655.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   655.7 + *
   655.8 + * This program is free software: you can redistribute it and/or modify
   655.9 + * it under the terms of the GNU General Public License as published by
  655.10 + * the Free Software Foundation, version 2 of the License.
  655.11 + *
  655.12 + * This program is distributed in the hope that it will be useful,
  655.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  655.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  655.15 + * GNU General Public License for more details.
  655.16 + *
  655.17 + * You should have received a copy of the GNU General Public License
  655.18 + * along with this program. Look for COPYING file in the top folder.
  655.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  655.20 + */
  655.21 +package org.apidesign.bck2brwsr.tck;
  655.22 +
  655.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
  655.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  655.25 +import org.testng.annotations.Factory;
  655.26 +
  655.27 +/**
  655.28 + *
  655.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  655.30 + */
  655.31 +public class ShortArithmeticTest {
  655.32 +    
  655.33 +    private static short add(short x, short y) {
  655.34 +        return (short)(x + y);
  655.35 +    }
  655.36 +    
  655.37 +    private static short sub(short x, short y) {
  655.38 +        return (short)(x - y);
  655.39 +    }
  655.40 +    
  655.41 +    private static short mul(short x, short y) {
  655.42 +        return (short)(x * y);
  655.43 +    }
  655.44 +    
  655.45 +    private static short div(short x, short y) {
  655.46 +        return (short)(x / y);
  655.47 +    }
  655.48 +    
  655.49 +    private static short mod(short x, short y) {
  655.50 +        return (short)(x % y);
  655.51 +    }
  655.52 +    
  655.53 +    @Compare public short conversion() {
  655.54 +        return (short)123456;
  655.55 +    }
  655.56 +    
  655.57 +    @Compare public short addOverflow() {
  655.58 +        return add(Short.MAX_VALUE, (short)1);
  655.59 +    }
  655.60 +    
  655.61 +    @Compare public short subUnderflow() {
  655.62 +        return sub(Short.MIN_VALUE, (short)1);
  655.63 +    }
  655.64 +    
  655.65 +    @Compare public short addMaxShortAndMaxShort() {
  655.66 +        return add(Short.MAX_VALUE, Short.MAX_VALUE);
  655.67 +    }
  655.68 +    
  655.69 +    @Compare public short subMinShortAndMinShort() {
  655.70 +        return sub(Short.MIN_VALUE, Short.MIN_VALUE);
  655.71 +    }
  655.72 +    
  655.73 +    @Compare public short multiplyMaxShort() {
  655.74 +        return mul(Short.MAX_VALUE, (short)2);
  655.75 +    }
  655.76 +    
  655.77 +    @Compare public short multiplyMaxShortAndMaxShort() {
  655.78 +        return mul(Short.MAX_VALUE, Short.MAX_VALUE);
  655.79 +    }
  655.80 +    
  655.81 +    @Compare public short multiplyMinShort() {
  655.82 +        return mul(Short.MIN_VALUE, (short)2);
  655.83 +    }
  655.84 +    
  655.85 +    @Compare public short multiplyMinShortAndMinShort() {
  655.86 +        return mul(Short.MIN_VALUE, Short.MIN_VALUE);
  655.87 +    }
  655.88 +    
  655.89 +    @Compare public short multiplyPrecision() {
  655.90 +        return mul((short)17638, (short)1103);
  655.91 +    }
  655.92 +    
  655.93 +    @Compare public short division() {
  655.94 +        return div((short)1, (short)2);
  655.95 +    }
  655.96 +    
  655.97 +    @Compare public short divisionReminder() {
  655.98 +        return mod((short)1, (short)2);
  655.99 +    }
 655.100 +    
 655.101 +    @Factory
 655.102 +    public static Object[] create() {
 655.103 +        return VMTest.create(ShortArithmeticTest.class);
 655.104 +    }
 655.105 +}
   656.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   656.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java	Wed Feb 27 11:24:58 2013 +0100
   656.3 @@ -0,0 +1,31 @@
   656.4 +/**
   656.5 + * Back 2 Browser Bytecode Translator
   656.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   656.7 + *
   656.8 + * This program is free software: you can redistribute it and/or modify
   656.9 + * it under the terms of the GNU General Public License as published by
  656.10 + * the Free Software Foundation, version 2 of the License.
  656.11 + *
  656.12 + * This program is distributed in the hope that it will be useful,
  656.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  656.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  656.15 + * GNU General Public License for more details.
  656.16 + *
  656.17 + * You should have received a copy of the GNU General Public License
  656.18 + * along with this program. Look for COPYING file in the top folder.
  656.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  656.20 + */
  656.21 +package org.apidesign.bck2brwsr.tck;
  656.22 +
  656.23 +class StaticUse {
  656.24 +    public static final Object NON_NULL = new Object();
  656.25 +    private StaticUse() {
  656.26 +    }
  656.27 +    
  656.28 +    public void instanceMethod() {
  656.29 +    }
  656.30 +
  656.31 +    public static int plus(int a, int b) {
  656.32 +        return a + b;
  656.33 +    }
  656.34 +}
   657.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   657.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/CRC32Test.java	Wed Feb 27 11:24:58 2013 +0100
   657.3 @@ -0,0 +1,41 @@
   657.4 +/**
   657.5 + * Back 2 Browser Bytecode Translator
   657.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   657.7 + *
   657.8 + * This program is free software: you can redistribute it and/or modify
   657.9 + * it under the terms of the GNU General Public License as published by
  657.10 + * the Free Software Foundation, version 2 of the License.
  657.11 + *
  657.12 + * This program is distributed in the hope that it will be useful,
  657.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  657.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  657.15 + * GNU General Public License for more details.
  657.16 + *
  657.17 + * You should have received a copy of the GNU General Public License
  657.18 + * along with this program. Look for COPYING file in the top folder.
  657.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  657.20 + */
  657.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  657.22 +
  657.23 +import java.io.UnsupportedEncodingException;
  657.24 +import java.util.zip.CRC32;
  657.25 +import org.apidesign.bck2brwsr.vmtest.Compare;
  657.26 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  657.27 +import org.testng.annotations.Factory;
  657.28 +
  657.29 +/**
  657.30 + *
  657.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  657.32 + */
  657.33 +public class CRC32Test {
  657.34 +
  657.35 +    @Compare public long crc1() throws UnsupportedEncodingException {
  657.36 +        CRC32 crc = new CRC32();
  657.37 +        crc.update("Hello World!".getBytes("UTF-8"));
  657.38 +        return crc.getValue();
  657.39 +    }
  657.40 +    
  657.41 +    @Factory public static Object[] create() {
  657.42 +        return VMTest.create(CRC32Test.class);
  657.43 +    }
  657.44 +}
   658.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   658.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipEntryTest.java	Wed Feb 27 11:24:58 2013 +0100
   658.3 @@ -0,0 +1,67 @@
   658.4 +/**
   658.5 + * Back 2 Browser Bytecode Translator
   658.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   658.7 + *
   658.8 + * This program is free software: you can redistribute it and/or modify
   658.9 + * it under the terms of the GNU General Public License as published by
  658.10 + * the Free Software Foundation, version 2 of the License.
  658.11 + *
  658.12 + * This program is distributed in the hope that it will be useful,
  658.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  658.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  658.15 + * GNU General Public License for more details.
  658.16 + *
  658.17 + * You should have received a copy of the GNU General Public License
  658.18 + * along with this program. Look for COPYING file in the top folder.
  658.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  658.20 + */
  658.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  658.22 +
  658.23 +import java.io.ByteArrayInputStream;
  658.24 +import java.io.IOException;
  658.25 +import java.io.InputStream;
  658.26 +import org.apidesign.bck2brwsr.emul.zip.FastJar;
  658.27 +import org.testng.annotations.Test;
  658.28 +import static org.testng.Assert.*;
  658.29 +
  658.30 +/**
  658.31 + *
  658.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  658.33 + */
  658.34 +@GenerateZip(name = "five.zip", contents = {
  658.35 +    "1.txt", "one",
  658.36 +    "2.txt", "duo",
  658.37 +    "3.txt", "three",
  658.38 +    "4.txt", "four",
  658.39 +    "5.txt", "five"
  658.40 +})
  658.41 +public class ZipEntryTest {
  658.42 +    @Test
  658.43 +    public void readEntriesEffectively() throws IOException {
  658.44 +        InputStream is = ZipEntryTest.class.getResourceAsStream("five.zip");
  658.45 +        byte[] arr = new byte[is.available()];
  658.46 +        int len = is.read(arr);
  658.47 +        assertEquals(len, arr.length, "Read fully");
  658.48 +        
  658.49 +        FastJar fj = new FastJar(arr);
  658.50 +        FastJar.Entry[] entrs = fj.list();
  658.51 +        
  658.52 +        assertEquals(5, entrs.length, "Five entries");
  658.53 +        
  658.54 +        for (int i = 1; i <= 5; i++) {
  658.55 +            FastJar.Entry en = entrs[i - 1];
  658.56 +            assertEquals(en.name, i + ".txt");
  658.57 +//            assertEquals(cis.cnt, 0, "Content of the file should be skipped, not read");
  658.58 +        }
  658.59 +        
  658.60 +        assertContent("three", fj.getInputStream(entrs[3 - 1]), "read OK");
  658.61 +        assertContent("five", fj.getInputStream(entrs[5 - 1]), "read OK");
  658.62 +    }
  658.63 +
  658.64 +    private static void assertContent(String exp, InputStream is, String msg) throws IOException {
  658.65 +        byte[] arr = new byte[512];
  658.66 +        int len = is.read(arr);
  658.67 +        String s = new String(arr, 0, len);
  658.68 +        assertEquals(exp, s, msg);
  658.69 +    }
  658.70 +}
   659.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   659.2 +++ b/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java	Wed Feb 27 11:24:58 2013 +0100
   659.3 @@ -0,0 +1,108 @@
   659.4 +/**
   659.5 + * Back 2 Browser Bytecode Translator
   659.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   659.7 + *
   659.8 + * This program is free software: you can redistribute it and/or modify
   659.9 + * it under the terms of the GNU General Public License as published by
  659.10 + * the Free Software Foundation, version 2 of the License.
  659.11 + *
  659.12 + * This program is distributed in the hope that it will be useful,
  659.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  659.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  659.15 + * GNU General Public License for more details.
  659.16 + *
  659.17 + * You should have received a copy of the GNU General Public License
  659.18 + * along with this program. Look for COPYING file in the top folder.
  659.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
  659.20 + */
  659.21 +package org.apidesign.bck2brwsr.vmtest.impl;
  659.22 +
  659.23 +import java.io.IOException;
  659.24 +import java.io.InputStream;
  659.25 +import java.util.Objects;
  659.26 +import java.util.zip.ZipEntry;
  659.27 +import java.util.zip.ZipInputStream;
  659.28 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
  659.29 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  659.30 +import org.apidesign.bck2brwsr.vmtest.Compare;
  659.31 +import org.apidesign.bck2brwsr.vmtest.Http;
  659.32 +import org.apidesign.bck2brwsr.vmtest.VMTest;
  659.33 +import org.testng.annotations.Factory;
  659.34 +
  659.35 +/**
  659.36 + *
  659.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
  659.38 + */
  659.39 +@GenerateZip(name = "readAnEntry.zip", contents = { 
  659.40 +    "my/main/file.txt", "Hello World!"
  659.41 +})
  659.42 +public class ZipFileTest {
  659.43 +    
  659.44 +    @Compare public String readAnEntry() throws IOException {
  659.45 +        InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip");
  659.46 +        ZipInputStream zip = new ZipInputStream(is);
  659.47 +        ZipEntry entry = zip.getNextEntry();
  659.48 +        assertEquals(entry.getName(), "my/main/file.txt", "Correct entry");
  659.49 +
  659.50 +        byte[] arr = new byte[4096];
  659.51 +        int len = zip.read(arr);
  659.52 +        
  659.53 +        assertEquals(zip.getNextEntry(), null, "No next entry");
  659.54 +        
  659.55 +        final String ret = new String(arr, 0, len, "UTF-8");
  659.56 +        return ret;
  659.57 +    }
  659.58 +    
  659.59 +    @JavaScriptBody(args = { "res", "path" }, body = 
  659.60 +          "var myvm = bck2brwsr.apply(null, path);\n"
  659.61 +        + "var cls = myvm.loadClass('java.lang.String');\n"
  659.62 +        + "return cls.getClass__Ljava_lang_Class_2().getResourceAsStream__Ljava_io_InputStream_2Ljava_lang_String_2(res);\n"
  659.63 +    )
  659.64 +    private static native Object loadVMResource(String res, String...path);
  659.65 +
  659.66 +    @Http({
  659.67 +        @Http.Resource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip")
  659.68 +    })
  659.69 +    @BrwsrTest  public void canVmLoadResourceFromZip() throws IOException {
  659.70 +        Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar");
  659.71 +        assert res instanceof InputStream : "Got array of bytes: " + res;
  659.72 +        InputStream is = (InputStream)res;
  659.73 +        
  659.74 +        byte[] arr = new byte[4096];
  659.75 +        int len = is.read(arr);
  659.76 +        
  659.77 +        final String ret = new String(arr, 0, len, "UTF-8");
  659.78 +
  659.79 +        assertEquals(ret, "Hello World!", "Can read the bytes");
  659.80 +    }
  659.81 +    
  659.82 +    @GenerateZip(name = "cpattr.zip", contents = { 
  659.83 +        "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n"
  659.84 +        + "Created-By: hand\n"
  659.85 +        + "Class-Path: realJar.jar\n\n\n"
  659.86 +    })
  659.87 +    @Http({
  659.88 +        @Http.Resource(path = "/readComplexEntry.jar", mimeType = "x-application/zip", content = "", resource="cpattr.zip"),
  659.89 +        @Http.Resource(path = "/realJar.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip"),
  659.90 +    })
  659.91 +    @BrwsrTest  public void understandsClassPathAttr() throws IOException {
  659.92 +        Object res = loadVMResource("/my/main/file.txt", "/readComplexEntry.jar");
  659.93 +        assert res instanceof InputStream : "Got array of bytes: " + res;
  659.94 +        InputStream is = (InputStream)res;
  659.95 +        
  659.96 +        byte[] arr = new byte[4096];
  659.97 +        int len = is.read(arr);
  659.98 +        
  659.99 +        final String ret = new String(arr, 0, len, "UTF-8");
 659.100 +
 659.101 +        assertEquals(ret, "Hello World!", "Can read the bytes from secondary JAR");
 659.102 +    }
 659.103 +    
 659.104 +    private static void assertEquals(Object real, Object exp, String msg) {
 659.105 +        assert Objects.equals(exp, real) : msg + " exp: " + exp + " real: " + real;
 659.106 +    }
 659.107 +    
 659.108 +    @Factory public static Object[] create() {
 659.109 +        return VMTest.create(ZipFileTest.class);
 659.110 +    }
 659.111 +}
   660.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   660.2 +++ b/rt/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/0xfe	Wed Feb 27 11:24:58 2013 +0100
   660.3 @@ -0,0 +1,1 @@
   660.4   660.5 \ No newline at end of file
   661.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   661.2 +++ b/rt/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/Resources.txt	Wed Feb 27 11:24:58 2013 +0100
   661.3 @@ -0,0 +1,1 @@
   661.4 +Ahoj
   662.1 --- a/vm/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   662.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   662.3 @@ -1,143 +0,0 @@
   662.4 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   662.5 -  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   662.6 -  <modelVersion>4.0.0</modelVersion>
   662.7 -  <parent>
   662.8 -    <groupId>org.apidesign</groupId>
   662.9 -    <artifactId>bck2brwsr</artifactId>
  662.10 -    <version>0.3-SNAPSHOT</version>
  662.11 -  </parent>
  662.12 -
  662.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
  662.14 -  <artifactId>vm4brwsr</artifactId>
  662.15 -  <version>0.3-SNAPSHOT</version>
  662.16 -  <packaging>jar</packaging>
  662.17 -
  662.18 -  <name>Virtual Machine for Browser</name>
  662.19 -  <url>http://bck2brwsr.apidesign.org</url>
  662.20 -
  662.21 -  <properties>
  662.22 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  662.23 -    <author.name>Jaroslav Tulach</author.name>
  662.24 -    <author.email>jaroslav.tulach@apidesign.org</author.email>
  662.25 -  </properties>
  662.26 -  
  662.27 -  <repositories>
  662.28 -      <repository>
  662.29 -          <id>netbeans</id>
  662.30 -          <name>NetBeans</name>
  662.31 -          <url>http://bits.netbeans.org/maven2/</url>
  662.32 -      </repository>
  662.33 -  </repositories>
  662.34 -  <pluginRepositories>
  662.35 -    <pluginRepository>
  662.36 -        <id>mc-release</id>
  662.37 -        <name>Local Maven repository of releases</name>
  662.38 -        <url>http://mc-repo.googlecode.com/svn/maven2/releases</url>
  662.39 -        <snapshots>
  662.40 -            <enabled>false</enabled>
  662.41 -        </snapshots>
  662.42 -        <releases>
  662.43 -            <enabled>true</enabled>
  662.44 -        </releases>
  662.45 -    </pluginRepository>
  662.46 -  </pluginRepositories>
  662.47 -  <scm>
  662.48 -      <connection>scm:hg:http://source.apidesign.org/hg/bck2brwsr</connection>
  662.49 -      <url>http://source.apidesign.org/hg/bck2brwsr</url>
  662.50 -  </scm>
  662.51 -  <build>
  662.52 -      <plugins>
  662.53 -          <plugin>
  662.54 -              <groupId>org.apache.maven.plugins</groupId>
  662.55 -              <artifactId>maven-jar-plugin</artifactId>
  662.56 -              <version>2.4</version>
  662.57 -              <configuration>
  662.58 -                  <archive>
  662.59 -                      <manifest>
  662.60 -                          <mainClass>org.apidesign.vm4brwsr.Main</mainClass>
  662.61 -                      </manifest>
  662.62 -                  </archive>
  662.63 -              </configuration>
  662.64 -          </plugin>
  662.65 -         <plugin>
  662.66 -            <groupId>org.apache.maven.plugins</groupId>
  662.67 -            <artifactId>maven-compiler-plugin</artifactId>
  662.68 -            <version>2.3.2</version>
  662.69 -            <configuration>
  662.70 -               <source>1.7</source>
  662.71 -               <target>1.7</target>
  662.72 -            </configuration>
  662.73 -         </plugin>
  662.74 -         <plugin>
  662.75 -             <groupId>org.codehaus.mojo</groupId>
  662.76 -             <artifactId>exec-maven-plugin</artifactId>
  662.77 -             <version>1.2.1</version>
  662.78 -             <executions>
  662.79 -                 <execution>
  662.80 -                     <id>generate-js</id>
  662.81 -                     <phase>process-classes</phase>
  662.82 -                     <goals>
  662.83 -                         <goal>java</goal>
  662.84 -                     </goals>
  662.85 -                 </execution>
  662.86 -             </executions>
  662.87 -             <configuration>
  662.88 -                 <mainClass>org.apidesign.vm4brwsr.Main</mainClass>
  662.89 -                 <arguments>
  662.90 -                     <argument>${project.build.directory}/bck2brwsr.js</argument>
  662.91 -                     <argument>org/apidesign/vm4brwsr/Bck2Brwsr</argument>
  662.92 -                 </arguments>
  662.93 -             </configuration>
  662.94 -         </plugin>
  662.95 -         <plugin>
  662.96 -             <artifactId>maven-assembly-plugin</artifactId>
  662.97 -             <version>2.4</version>
  662.98 -             <executions>
  662.99 -                 <execution>
 662.100 -                     <id>js</id>
 662.101 -                     <phase>package</phase>
 662.102 -                     <goals>
 662.103 -                         <goal>single</goal>
 662.104 -                     </goals>
 662.105 -                     <configuration>
 662.106 -                         <descriptors>
 662.107 -                             <descriptor>src/main/assembly/bck2brwsr.xml</descriptor>
 662.108 -                         </descriptors>
 662.109 -                     </configuration>
 662.110 -                 </execution>
 662.111 -             </executions>                
 662.112 -         </plugin>      
 662.113 -      </plugins>
 662.114 -  </build>
 662.115 -  <dependencies>
 662.116 -    <dependency>
 662.117 -      <groupId>org.testng</groupId>
 662.118 -      <artifactId>testng</artifactId>
 662.119 -      <scope>test</scope>
 662.120 -      <exclusions>
 662.121 -        <exclusion>
 662.122 -          <artifactId>junit</artifactId>
 662.123 -          <groupId>junit</groupId>
 662.124 -        </exclusion>
 662.125 -      </exclusions>
 662.126 -    </dependency>
 662.127 -    <dependency>
 662.128 -      <groupId>${project.groupId}</groupId>
 662.129 -      <artifactId>core</artifactId>
 662.130 -      <version>${project.version}</version>
 662.131 -      <type>jar</type>
 662.132 -    </dependency>
 662.133 -    <dependency>
 662.134 -      <groupId>${project.groupId}</groupId>
 662.135 -      <artifactId>emul.mini</artifactId>
 662.136 -      <version>${project.version}</version>
 662.137 -      <scope>compile</scope>
 662.138 -    </dependency>
 662.139 -    <dependency>
 662.140 -      <groupId>${project.groupId}</groupId>
 662.141 -      <artifactId>javap</artifactId>
 662.142 -      <version>${project.version}</version>
 662.143 -      <scope>compile</scope>
 662.144 -    </dependency>
 662.145 -  </dependencies>
 662.146 -</project>
   663.1 --- a/vm/src/main/assembly/bck2brwsr.xml	Mon Feb 25 19:00:08 2013 +0100
   663.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   663.3 @@ -1,36 +0,0 @@
   663.4 -<?xml version="1.0"?>
   663.5 -<!--
   663.6 -
   663.7 -    Back 2 Browser Bytecode Translator
   663.8 -    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   663.9 -
  663.10 -    This program is free software: you can redistribute it and/or modify
  663.11 -    it under the terms of the GNU General Public License as published by
  663.12 -    the Free Software Foundation, version 2 of the License.
  663.13 -
  663.14 -    This program is distributed in the hope that it will be useful,
  663.15 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
  663.16 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  663.17 -    GNU General Public License for more details.
  663.18 -
  663.19 -    You should have received a copy of the GNU General Public License
  663.20 -    along with this program. Look for COPYING file in the top folder.
  663.21 -    If not, see http://opensource.org/licenses/GPL-2.0.
  663.22 -
  663.23 --->
  663.24 -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  663.25 -  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  663.26 -  
  663.27 -  <id>js</id>
  663.28 -  <formats>
  663.29 -      <format>zip</format>
  663.30 -  </formats>
  663.31 -  <baseDirectory>/</baseDirectory>
  663.32 -  <files>
  663.33 -    <file>
  663.34 -      <source>${project.build.directory}/bck2brwsr.js</source>
  663.35 -      <outputDirectory>/</outputDirectory>
  663.36 -    </file>
  663.37 -  </files>
  663.38 -
  663.39 -</assembly>
  663.40 \ No newline at end of file
   664.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java	Mon Feb 25 19:00:08 2013 +0100
   664.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   664.3 @@ -1,116 +0,0 @@
   664.4 -/**
   664.5 - * Back 2 Browser Bytecode Translator
   664.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   664.7 - *
   664.8 - * This program is free software: you can redistribute it and/or modify
   664.9 - * it under the terms of the GNU General Public License as published by
  664.10 - * the Free Software Foundation, version 2 of the License.
  664.11 - *
  664.12 - * This program is distributed in the hope that it will be useful,
  664.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  664.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  664.15 - * GNU General Public License for more details.
  664.16 - *
  664.17 - * You should have received a copy of the GNU General Public License
  664.18 - * along with this program. Look for COPYING file in the top folder.
  664.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  664.20 - */
  664.21 -package org.apidesign.vm4brwsr;
  664.22 -
  664.23 -import java.io.IOException;
  664.24 -import java.io.InputStream;
  664.25 -import java.net.URL;
  664.26 -import java.util.Enumeration;
  664.27 -
  664.28 -/** Build your own virtual machine! Use methods in this class to generate
  664.29 - * a skeleton JVM in JavaScript that contains pre-compiled classes of your
  664.30 - * choice. The generated script defines one JavaScript method that can
  664.31 - * be used to bootstrap and load the virtual machine: <pre>
  664.32 - * var vm = bck2brwsr();
  664.33 - * var main = vm.loadClass('org.your.pkg.Main');
  664.34 - * main.main__V_3Ljava_lang_String_2(null);
  664.35 - * </pre>
  664.36 - * In case one wants to initialize the virtual machine with ability to
  664.37 - * load classes lazily when needed, one can provide a loader function to
  664.38 - * when creating the virtual machine: <pre>
  664.39 - * var vm = bck2brwsr(function(resource) { 
  664.40 - *   return null; // byte[] for the resource
  664.41 - * });
  664.42 - * </pre>
  664.43 - * In this scenario, when a request for an unknown class is made, the loader
  664.44 - * function is asked for its byte code and the system dynamically transforms
  664.45 - * it to JavaScript.
  664.46 - * <p>
  664.47 - * Instead of a loader function, one can also provide a URL to a JAR file.
  664.48 - * The <code>bck2brwsr</code> system will do its best to download the file
  664.49 - * and provide loader function for it automatically.
  664.50 - * <p>
  664.51 - * One can provide as many loader functions and JAR URL references as necessary.
  664.52 - * Then the initialization code would look like:<pre>
  664.53 - * var vm = bck2brwsr(url1, url2, fnctn1, url3, functn2);
  664.54 - * </pre>
  664.55 - * The provided URLs and loader functions will be consulted one by one.
  664.56 - *
  664.57 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  664.58 - */
  664.59 -public final class Bck2Brwsr {
  664.60 -    private Bck2Brwsr() {
  664.61 -    }
  664.62 -    
  664.63 -    /** Generates virtual machine from bytes served by a <code>resources</code>
  664.64 -     * provider.
  664.65 -     * 
  664.66 -     * @param out the output to write the generated JavaScript to
  664.67 -     * @param resources provider of class files to use
  664.68 -     * @param classes additional classes to include in the generated script
  664.69 -     * @throws IOException I/O exception can be thrown when something goes wrong
  664.70 -     */
  664.71 -    public static void generate(Appendable out, Resources resources, String... classes) throws IOException {
  664.72 -        StringArray arr = StringArray.asList(classes);
  664.73 -        arr.add(VM.class.getName().replace('.', '/'));
  664.74 -        VM.compile(resources, out, arr);
  664.75 -    }
  664.76 -    
  664.77 -    /** Generates virtual machine from bytes served by a class loader.
  664.78 -     * 
  664.79 -     * @param out the output to write the generated JavaScript to
  664.80 -     * @param loader class loader to load needed classes from
  664.81 -     * @param classes additional classes to include in the generated script
  664.82 -     * @throws IOException I/O exception can be thrown when something goes wrong
  664.83 -     */
  664.84 -    public static void generate(Appendable out, final ClassLoader loader, String... classes) throws IOException {
  664.85 -        class R implements Resources {
  664.86 -            @Override
  664.87 -            public InputStream get(String name) throws IOException {
  664.88 -                Enumeration<URL> en = loader.getResources(name);
  664.89 -                URL u = null;
  664.90 -                while (en.hasMoreElements()) {
  664.91 -                    u = en.nextElement();
  664.92 -                }
  664.93 -                if (u == null) {
  664.94 -                    throw new IOException("Can't find " + name);
  664.95 -                }
  664.96 -                return u.openStream();
  664.97 -            }
  664.98 -        }
  664.99 -        generate(out, new R(), classes);
 664.100 -    }
 664.101 -    
 664.102 -    /** Provider of resources (classes and other files). The 
 664.103 -     * {@link #generate(java.lang.Appendable, org.apidesign.vm4brwsr.Bck2Brwsr.Resources, java.lang.String[]) 
 664.104 -     * generator method} will call back here for all classes needed during
 664.105 -     * translation to JavaScript.
 664.106 -     */
 664.107 -    public interface Resources {
 664.108 -        /** Loads given resource (class or other file like image). The 
 664.109 -         * resource name to load bytes for the {@link String} class
 664.110 -         * would be <code>"java/lang/String.class"</code>.
 664.111 -         * 
 664.112 -         * @param resource path to resource to load
 664.113 -         * @return the input stream for the resource 
 664.114 -         * @throws IOException can be thrown if the loading fails on some error
 664.115 -         *   or the file cannot be found
 664.116 -         */
 664.117 -        public InputStream get(String resource) throws IOException;
 664.118 -    }
 664.119 -}
   665.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Mon Feb 25 19:00:08 2013 +0100
   665.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   665.3 @@ -1,1859 +0,0 @@
   665.4 -/**
   665.5 - * Back 2 Browser Bytecode Translator
   665.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   665.7 - *
   665.8 - * This program is free software: you can redistribute it and/or modify
   665.9 - * it under the terms of the GNU General Public License as published by
  665.10 - * the Free Software Foundation, version 2 of the License.
  665.11 - *
  665.12 - * This program is distributed in the hope that it will be useful,
  665.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  665.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  665.15 - * GNU General Public License for more details.
  665.16 - *
  665.17 - * You should have received a copy of the GNU General Public License
  665.18 - * along with this program. Look for COPYING file in the top folder.
  665.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  665.20 - */
  665.21 -package org.apidesign.vm4brwsr;
  665.22 -
  665.23 -import java.io.IOException;
  665.24 -import java.io.InputStream;
  665.25 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  665.26 -import org.apidesign.javap.AnnotationParser;
  665.27 -import org.apidesign.javap.ClassData;
  665.28 -import org.apidesign.javap.FieldData;
  665.29 -import org.apidesign.javap.MethodData;
  665.30 -import org.apidesign.javap.StackMapIterator;
  665.31 -import static org.apidesign.javap.RuntimeConstants.*;
  665.32 -import org.apidesign.javap.TrapData;
  665.33 -import org.apidesign.javap.TrapDataIterator;
  665.34 -
  665.35 -/** Translator of the code inside class files to JavaScript.
  665.36 - *
  665.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  665.38 - */
  665.39 -abstract class ByteCodeToJavaScript {
  665.40 -    private ClassData jc;
  665.41 -    final Appendable out;
  665.42 -
  665.43 -    protected ByteCodeToJavaScript(Appendable out) {
  665.44 -        this.out = out;
  665.45 -    }
  665.46 -    
  665.47 -    /* Collects additional required resources.
  665.48 -     * 
  665.49 -     * @param internalClassName classes that were referenced and should be loaded in order the
  665.50 -     *   generated JavaScript code works properly. The names are in internal 
  665.51 -     *   JVM form so String is <code>java/lang/String</code>. 
  665.52 -     */
  665.53 -    protected abstract boolean requireReference(String internalClassName);
  665.54 -    
  665.55 -    /*
  665.56 -     * @param resourcePath name of resources to read
  665.57 -     */
  665.58 -    protected abstract void requireScript(String resourcePath) throws IOException;
  665.59 -    
  665.60 -    /** Allows subclasses to redefine what field a function representing a
  665.61 -     * class gets assigned. By default it returns the suggested name followed
  665.62 -     * by <code>" = "</code>;
  665.63 -     * 
  665.64 -     * @param className suggested name of the class
  665.65 -     */
  665.66 -    /* protected */ String assignClass(String className) {
  665.67 -        return className + " = ";
  665.68 -    }
  665.69 -    /* protected */ String accessClass(String classOperation) {
  665.70 -        return classOperation;
  665.71 -    }
  665.72 -    
  665.73 -    /** Prints out a debug message. 
  665.74 -     * 
  665.75 -     * @param msg the message
  665.76 -     * @return true if the message has been printed
  665.77 -     * @throws IOException 
  665.78 -     */
  665.79 -    boolean debug(String msg) throws IOException {
  665.80 -        out.append(msg);
  665.81 -        return true;
  665.82 -    }
  665.83 -
  665.84 -    /**
  665.85 -     * Converts a given class file to a JavaScript version.
  665.86 -     *
  665.87 -     * @param classFile input stream with code of the .class file
  665.88 -     * @return the initialization code for this class, if any. Otherwise <code>null</code>
  665.89 -     * 
  665.90 -     * @throws IOException if something goes wrong during read or write or translating
  665.91 -     */
  665.92 -    
  665.93 -    public String compile(InputStream classFile) throws IOException {
  665.94 -        this.jc = new ClassData(classFile);
  665.95 -        if (jc.getMajor_version() < 50) {
  665.96 -            throw new IOException("Can't compile " + jc.getClassName() + ". Class file version " + jc.getMajor_version() + "."
  665.97 -                + jc.getMinor_version() + " - recompile with -target 1.6 (at least)."
  665.98 -            );
  665.99 -        }
 665.100 -        byte[] arrData = jc.findAnnotationData(true);
 665.101 -        String[] arr = findAnnotation(arrData, jc, 
 665.102 -            "org.apidesign.bck2brwsr.core.ExtraJavaScript", 
 665.103 -            "resource", "processByteCode"
 665.104 -        );
 665.105 -        if (arr != null) {
 665.106 -            requireScript(arr[0]);
 665.107 -            if ("0".equals(arr[1])) {
 665.108 -                return null;
 665.109 -            }
 665.110 -        }
 665.111 -        String[] proto = findAnnotation(arrData, jc, 
 665.112 -            "org.apidesign.bck2brwsr.core.JavaScriptPrototype", 
 665.113 -            "container", "prototype"
 665.114 -        );
 665.115 -        StringArray toInitilize = new StringArray();
 665.116 -        final String className = className(jc);
 665.117 -        out.append("\n\n").append(assignClass(className));
 665.118 -        out.append("function CLS() {");
 665.119 -        out.append("\n  if (!CLS.$class) {");
 665.120 -        if (proto == null) {
 665.121 -            String sc = jc.getSuperClassName(); // with _
 665.122 -            out.append("\n    var pp = ").
 665.123 -                append(accessClass(sc.replace('/', '_'))).append("(true);");
 665.124 -            out.append("\n    var p = CLS.prototype = pp;");
 665.125 -            out.append("\n    var c = p;");
 665.126 -            out.append("\n    var sprcls = pp.constructor.$class;");
 665.127 -        } else {
 665.128 -            out.append("\n    var p = CLS.prototype = ").append(proto[1]).append(";");
 665.129 -            if (proto[0] == null) {
 665.130 -                proto[0] = "p";
 665.131 -            }
 665.132 -            out.append("\n    var c = ").append(proto[0]).append(";");
 665.133 -            out.append("\n    var sprcls = null;");
 665.134 -        }
 665.135 -        for (FieldData v : jc.getFields()) {
 665.136 -            if (v.isStatic()) {
 665.137 -                out.append("\n  CLS.").append(v.getName()).append(initField(v));
 665.138 -            } else {
 665.139 -                out.append("\n  c._").append(v.getName()).append(" = function (v) {")
 665.140 -                   .append("  if (arguments.length == 1) this.fld_").
 665.141 -                    append(className).append('_').append(v.getName())
 665.142 -                   .append(" = v; return this.fld_").
 665.143 -                    append(className).append('_').append(v.getName())
 665.144 -                   .append("; };");
 665.145 -            }
 665.146 -        }
 665.147 -        for (MethodData m : jc.getMethods()) {
 665.148 -            byte[] onlyArr = m.findAnnotationData(true);
 665.149 -            String[] only = findAnnotation(onlyArr, jc, 
 665.150 -                "org.apidesign.bck2brwsr.core.JavaScriptOnly", 
 665.151 -                "name", "value"
 665.152 -            );
 665.153 -            if (only != null) {
 665.154 -                if (only[0] != null && only[1] != null) {
 665.155 -                    out.append("\n    p.").append(only[0]).append(" = ")
 665.156 -                        .append(only[1]).append(";");
 665.157 -                }
 665.158 -                continue;
 665.159 -            }
 665.160 -            String prefix;
 665.161 -            String mn;
 665.162 -            if (m.isStatic()) {
 665.163 -                prefix = "\n    c.";
 665.164 -                mn = generateStaticMethod(prefix, m, toInitilize);
 665.165 -            } else {
 665.166 -                if (m.isConstructor()) {
 665.167 -                    prefix = "\n    CLS.";
 665.168 -                    mn = generateInstanceMethod(prefix, m);
 665.169 -                } else {
 665.170 -                    prefix = "\n    c.";
 665.171 -                    mn = generateInstanceMethod(prefix, m);
 665.172 -                }
 665.173 -            }
 665.174 -            byte[] runAnno = m.findAnnotationData(false);
 665.175 -            if (runAnno != null) {
 665.176 -                out.append(prefix).append(mn).append(".anno = {");
 665.177 -                generateAnno(jc, out, runAnno);
 665.178 -                out.append("\n    };");
 665.179 -            }
 665.180 -            out.append(prefix).append(mn).append(".access = " + m.getAccess()).append(";");
 665.181 -            out.append(prefix).append(mn).append(".cls = CLS;");
 665.182 -        }
 665.183 -        out.append("\n    c.constructor = CLS;");
 665.184 -        out.append("\n    c.$instOf_").append(className).append(" = true;");
 665.185 -        for (String superInterface : jc.getSuperInterfaces()) {
 665.186 -            out.append("\n    c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
 665.187 -        }
 665.188 -        out.append("\n    CLS.$class = 'temp';");
 665.189 -        out.append("\n    CLS.$class = ");
 665.190 -        out.append(accessClass("java_lang_Class(true);"));
 665.191 -        out.append("\n    CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
 665.192 -        out.append("\n    CLS.$class.superclass = sprcls;");
 665.193 -        out.append("\n    CLS.$class.access = ").append(jc.getAccessFlags()+";");
 665.194 -        out.append("\n    CLS.$class.cnstr = CLS;");
 665.195 -        byte[] classAnno = jc.findAnnotationData(false);
 665.196 -        if (classAnno != null) {
 665.197 -            out.append("\n    CLS.$class.anno = {");
 665.198 -            generateAnno(jc, out, classAnno);
 665.199 -            out.append("\n    };");
 665.200 -        }
 665.201 -        out.append("\n  }");
 665.202 -        out.append("\n  if (arguments.length === 0) {");
 665.203 -        out.append("\n    if (!(this instanceof CLS)) {");
 665.204 -        out.append("\n      return new CLS();");
 665.205 -        out.append("\n    }");
 665.206 -        for (FieldData v : jc.getFields()) {
 665.207 -            byte[] onlyArr = v.findAnnotationData(true);
 665.208 -            String[] only = findAnnotation(onlyArr, jc, 
 665.209 -                "org.apidesign.bck2brwsr.core.JavaScriptOnly", 
 665.210 -                "name", "value"
 665.211 -            );
 665.212 -            if (only != null) {
 665.213 -                if (only[0] != null && only[1] != null) {
 665.214 -                    out.append("\n    p.").append(only[0]).append(" = ")
 665.215 -                        .append(only[1]).append(";");
 665.216 -                }
 665.217 -                continue;
 665.218 -            }
 665.219 -            if (!v.isStatic()) {
 665.220 -                out.append("\n    this.fld_").
 665.221 -                    append(className).append('_').
 665.222 -                    append(v.getName()).append(initField(v));
 665.223 -            }
 665.224 -        }
 665.225 -        out.append("\n    return this;");
 665.226 -        out.append("\n  }");
 665.227 -        out.append("\n  return arguments[0] ? new CLS() : CLS.prototype;");
 665.228 -        out.append("\n};");
 665.229 -        StringBuilder sb = new StringBuilder();
 665.230 -        for (String init : toInitilize.toArray()) {
 665.231 -            sb.append("\n").append(init).append("();");
 665.232 -        }
 665.233 -        return sb.toString();
 665.234 -    }
 665.235 -    private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
 665.236 -        String jsb = javaScriptBody(prefix, m, true);
 665.237 -        if (jsb != null) {
 665.238 -            return jsb;
 665.239 -        }
 665.240 -        final String mn = findMethodName(m, new StringBuilder());
 665.241 -        if (mn.equals("class__V")) {
 665.242 -            toInitilize.add(accessClass(className(jc)) + "(false)." + mn);
 665.243 -        }
 665.244 -        generateMethod(prefix, mn, m);
 665.245 -        return mn;
 665.246 -    }
 665.247 -
 665.248 -    private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
 665.249 -        String jsb = javaScriptBody(prefix, m, false);
 665.250 -        if (jsb != null) {
 665.251 -            return jsb;
 665.252 -        }
 665.253 -        final String mn = findMethodName(m, new StringBuilder());
 665.254 -        generateMethod(prefix, mn, m);
 665.255 -        return mn;
 665.256 -    }
 665.257 -
 665.258 -    private void generateMethod(String prefix, String name, MethodData m)
 665.259 -            throws IOException {
 665.260 -        final StackMapIterator stackMapIterator = m.createStackMapIterator();
 665.261 -        TrapDataIterator trap = m.getTrapDataIterator();
 665.262 -        final LocalsMapper lmapper =
 665.263 -                new LocalsMapper(stackMapIterator.getArguments());
 665.264 -
 665.265 -        out.append(prefix).append(name).append(" = function(");
 665.266 -        lmapper.outputArguments(out, m.isStatic());
 665.267 -        out.append(") {").append("\n");
 665.268 -
 665.269 -        final byte[] byteCodes = m.getCode();
 665.270 -        if (byteCodes == null) {
 665.271 -            out.append("  throw 'no code found for ")
 665.272 -               .append(jc.getClassName()).append('.')
 665.273 -               .append(m.getName()).append("';\n");
 665.274 -            out.append("};");
 665.275 -            return;
 665.276 -        }
 665.277 -
 665.278 -        final StackMapper smapper = new StackMapper();
 665.279 -
 665.280 -        if (!m.isStatic()) {
 665.281 -            out.append("  var ").append(" lcA0 = this;\n");
 665.282 -        }
 665.283 -
 665.284 -        int lastStackFrame = -1;
 665.285 -        TrapData[] previousTrap = null;
 665.286 -        boolean wide = false;
 665.287 -        
 665.288 -        out.append("\n  var gt = 0;\n  for(;;) switch(gt) {\n");
 665.289 -        for (int i = 0; i < byteCodes.length; i++) {
 665.290 -            int prev = i;
 665.291 -            stackMapIterator.advanceTo(i);
 665.292 -            boolean changeInCatch = trap.advanceTo(i);
 665.293 -            if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) {
 665.294 -                if (previousTrap != null) {
 665.295 -                    generateCatch(previousTrap);
 665.296 -                    previousTrap = null;
 665.297 -                }
 665.298 -            }
 665.299 -            if (lastStackFrame != stackMapIterator.getFrameIndex()) {
 665.300 -                lastStackFrame = stackMapIterator.getFrameIndex();
 665.301 -                lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
 665.302 -                smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
 665.303 -                out.append("    case " + i).append(": ");            
 665.304 -                changeInCatch = true;
 665.305 -            } else {
 665.306 -                debug("    /* " + i + " */ ");
 665.307 -            }
 665.308 -            if (changeInCatch && trap.useTry()) {
 665.309 -                out.append("try {");
 665.310 -                previousTrap = trap.current();
 665.311 -            }
 665.312 -            final int c = readUByte(byteCodes, i);
 665.313 -            switch (c) {
 665.314 -                case opc_aload_0:
 665.315 -                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(0));
 665.316 -                    break;
 665.317 -                case opc_iload_0:
 665.318 -                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(0));
 665.319 -                    break;
 665.320 -                case opc_lload_0:
 665.321 -                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(0));
 665.322 -                    break;
 665.323 -                case opc_fload_0:
 665.324 -                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(0));
 665.325 -                    break;
 665.326 -                case opc_dload_0:
 665.327 -                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(0));
 665.328 -                    break;
 665.329 -                case opc_aload_1:
 665.330 -                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(1));
 665.331 -                    break;
 665.332 -                case opc_iload_1:
 665.333 -                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(1));
 665.334 -                    break;
 665.335 -                case opc_lload_1:
 665.336 -                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(1));
 665.337 -                    break;
 665.338 -                case opc_fload_1:
 665.339 -                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(1));
 665.340 -                    break;
 665.341 -                case opc_dload_1:
 665.342 -                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(1));
 665.343 -                    break;
 665.344 -                case opc_aload_2:
 665.345 -                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(2));
 665.346 -                    break;
 665.347 -                case opc_iload_2:
 665.348 -                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(2));
 665.349 -                    break;
 665.350 -                case opc_lload_2:
 665.351 -                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(2));
 665.352 -                    break;
 665.353 -                case opc_fload_2:
 665.354 -                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(2));
 665.355 -                    break;
 665.356 -                case opc_dload_2:
 665.357 -                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(2));
 665.358 -                    break;
 665.359 -                case opc_aload_3:
 665.360 -                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(3));
 665.361 -                    break;
 665.362 -                case opc_iload_3:
 665.363 -                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(3));
 665.364 -                    break;
 665.365 -                case opc_lload_3:
 665.366 -                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(3));
 665.367 -                    break;
 665.368 -                case opc_fload_3:
 665.369 -                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(3));
 665.370 -                    break;
 665.371 -                case opc_dload_3:
 665.372 -                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(3));
 665.373 -                    break;
 665.374 -                case opc_iload: {
 665.375 -                    ++i;
 665.376 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.377 -                                          : readUByte(byteCodes, i);
 665.378 -                    wide = false;
 665.379 -                    emit(out, "var @1 = @2;",
 665.380 -                         smapper.pushI(), lmapper.getI(indx));
 665.381 -                    break;
 665.382 -                }
 665.383 -                case opc_lload: {
 665.384 -                    ++i;
 665.385 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.386 -                                          : readUByte(byteCodes, i);
 665.387 -                    wide = false;
 665.388 -                    emit(out, "var @1 = @2;",
 665.389 -                         smapper.pushL(), lmapper.getL(indx));
 665.390 -                    break;
 665.391 -                }
 665.392 -                case opc_fload: {
 665.393 -                    ++i;
 665.394 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.395 -                                          : readUByte(byteCodes, i);
 665.396 -                    wide = false;
 665.397 -                    emit(out, "var @1 = @2;",
 665.398 -                         smapper.pushF(), lmapper.getF(indx));
 665.399 -                    break;
 665.400 -                }
 665.401 -                case opc_dload: {
 665.402 -                    ++i;
 665.403 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.404 -                                          : readUByte(byteCodes, i);
 665.405 -                    wide = false;
 665.406 -                    emit(out, "var @1 = @2;",
 665.407 -                         smapper.pushD(), lmapper.getD(indx));
 665.408 -                    break;
 665.409 -                }
 665.410 -                case opc_aload: {
 665.411 -                    ++i;
 665.412 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.413 -                                          : readUByte(byteCodes, i);
 665.414 -                    wide = false;
 665.415 -                    emit(out, "var @1 = @2;",
 665.416 -                         smapper.pushA(), lmapper.getA(indx));
 665.417 -                    break;
 665.418 -                }
 665.419 -                case opc_istore: {
 665.420 -                    ++i;
 665.421 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.422 -                                          : readUByte(byteCodes, i);
 665.423 -                    wide = false;
 665.424 -                    emit(out, "var @1 = @2;",
 665.425 -                         lmapper.setI(indx), smapper.popI());
 665.426 -                    break;
 665.427 -                }
 665.428 -                case opc_lstore: {
 665.429 -                    ++i;
 665.430 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.431 -                                          : readUByte(byteCodes, i);
 665.432 -                    wide = false;
 665.433 -                    emit(out, "var @1 = @2;",
 665.434 -                         lmapper.setL(indx), smapper.popL());
 665.435 -                    break;
 665.436 -                }
 665.437 -                case opc_fstore: {
 665.438 -                    ++i;
 665.439 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.440 -                                          : readUByte(byteCodes, i);
 665.441 -                    wide = false;
 665.442 -                    emit(out, "var @1 = @2;",
 665.443 -                         lmapper.setF(indx), smapper.popF());
 665.444 -                    break;
 665.445 -                }
 665.446 -                case opc_dstore: {
 665.447 -                    ++i;
 665.448 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.449 -                                          : readUByte(byteCodes, i);
 665.450 -                    wide = false;
 665.451 -                    emit(out, "var @1 = @2;",
 665.452 -                         lmapper.setD(indx), smapper.popD());
 665.453 -                    break;
 665.454 -                }
 665.455 -                case opc_astore: {
 665.456 -                    ++i;
 665.457 -                    final int indx = wide ? readUShort(byteCodes, i++)
 665.458 -                                          : readUByte(byteCodes, i);
 665.459 -                    wide = false;
 665.460 -                    emit(out, "var @1 = @2;",
 665.461 -                         lmapper.setA(indx), smapper.popA());
 665.462 -                    break;
 665.463 -                }
 665.464 -                case opc_astore_0:
 665.465 -                    emit(out, "var @1 = @2;", lmapper.setA(0), smapper.popA());
 665.466 -                    break;
 665.467 -                case opc_istore_0:
 665.468 -                    emit(out, "var @1 = @2;", lmapper.setI(0), smapper.popI());
 665.469 -                    break;
 665.470 -                case opc_lstore_0:
 665.471 -                    emit(out, "var @1 = @2;", lmapper.setL(0), smapper.popL());
 665.472 -                    break;
 665.473 -                case opc_fstore_0:
 665.474 -                    emit(out, "var @1 = @2;", lmapper.setF(0), smapper.popF());
 665.475 -                    break;
 665.476 -                case opc_dstore_0:
 665.477 -                    emit(out, "var @1 = @2;", lmapper.setD(0), smapper.popD());
 665.478 -                    break;
 665.479 -                case opc_astore_1:
 665.480 -                    emit(out, "var @1 = @2;", lmapper.setA(1), smapper.popA());
 665.481 -                    break;
 665.482 -                case opc_istore_1:
 665.483 -                    emit(out, "var @1 = @2;", lmapper.setI(1), smapper.popI());
 665.484 -                    break;
 665.485 -                case opc_lstore_1:
 665.486 -                    emit(out, "var @1 = @2;", lmapper.setL(1), smapper.popL());
 665.487 -                    break;
 665.488 -                case opc_fstore_1:
 665.489 -                    emit(out, "var @1 = @2;", lmapper.setF(1), smapper.popF());
 665.490 -                    break;
 665.491 -                case opc_dstore_1:
 665.492 -                    emit(out, "var @1 = @2;", lmapper.setD(1), smapper.popD());
 665.493 -                    break;
 665.494 -                case opc_astore_2:
 665.495 -                    emit(out, "var @1 = @2;", lmapper.setA(2), smapper.popA());
 665.496 -                    break;
 665.497 -                case opc_istore_2:
 665.498 -                    emit(out, "var @1 = @2;", lmapper.setI(2), smapper.popI());
 665.499 -                    break;
 665.500 -                case opc_lstore_2:
 665.501 -                    emit(out, "var @1 = @2;", lmapper.setL(2), smapper.popL());
 665.502 -                    break;
 665.503 -                case opc_fstore_2:
 665.504 -                    emit(out, "var @1 = @2;", lmapper.setF(2), smapper.popF());
 665.505 -                    break;
 665.506 -                case opc_dstore_2:
 665.507 -                    emit(out, "var @1 = @2;", lmapper.setD(2), smapper.popD());
 665.508 -                    break;
 665.509 -                case opc_astore_3:
 665.510 -                    emit(out, "var @1 = @2;", lmapper.setA(3), smapper.popA());
 665.511 -                    break;
 665.512 -                case opc_istore_3:
 665.513 -                    emit(out, "var @1 = @2;", lmapper.setI(3), smapper.popI());
 665.514 -                    break;
 665.515 -                case opc_lstore_3:
 665.516 -                    emit(out, "var @1 = @2;", lmapper.setL(3), smapper.popL());
 665.517 -                    break;
 665.518 -                case opc_fstore_3:
 665.519 -                    emit(out, "var @1 = @2;", lmapper.setF(3), smapper.popF());
 665.520 -                    break;
 665.521 -                case opc_dstore_3:
 665.522 -                    emit(out, "var @1 = @2;", lmapper.setD(3), smapper.popD());
 665.523 -                    break;
 665.524 -                case opc_iadd:
 665.525 -                    emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
 665.526 -                    break;
 665.527 -                case opc_ladd:
 665.528 -                    emit(out, "@1 = @1.add64(@2);", smapper.getL(1), smapper.popL());
 665.529 -                    break;
 665.530 -                case opc_fadd:
 665.531 -                    emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
 665.532 -                    break;
 665.533 -                case opc_dadd:
 665.534 -                    emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
 665.535 -                    break;
 665.536 -                case opc_isub:
 665.537 -                    emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
 665.538 -                    break;
 665.539 -                case opc_lsub:
 665.540 -                    emit(out, "@1 = @1.sub64(@2);", smapper.getL(1), smapper.popL());
 665.541 -                    break;
 665.542 -                case opc_fsub:
 665.543 -                    emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
 665.544 -                    break;
 665.545 -                case opc_dsub:
 665.546 -                    emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
 665.547 -                    break;
 665.548 -                case opc_imul:
 665.549 -                    emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
 665.550 -                    break;
 665.551 -                case opc_lmul:
 665.552 -                    emit(out, "@1 = @1.mul64(@2);", smapper.getL(1), smapper.popL());
 665.553 -                    break;
 665.554 -                case opc_fmul:
 665.555 -                    emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
 665.556 -                    break;
 665.557 -                case opc_dmul:
 665.558 -                    emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
 665.559 -                    break;
 665.560 -                case opc_idiv:
 665.561 -                    emit(out, "@1 = @1.div32(@2);",
 665.562 -                         smapper.getI(1), smapper.popI());
 665.563 -                    break;
 665.564 -                case opc_ldiv:
 665.565 -                    emit(out, "@1 = @1.div64(@2);",
 665.566 -                         smapper.getL(1), smapper.popL());
 665.567 -                    break;
 665.568 -                case opc_fdiv:
 665.569 -                    emit(out, "@1 /= @2;", smapper.getF(1), smapper.popF());
 665.570 -                    break;
 665.571 -                case opc_ddiv:
 665.572 -                    emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
 665.573 -                    break;
 665.574 -                case opc_irem:
 665.575 -                    emit(out, "@1 = @1.mod32(@2);",
 665.576 -                         smapper.getI(1), smapper.popI());
 665.577 -                    break;
 665.578 -                case opc_lrem:
 665.579 -                    emit(out, "@1 = @1.mod64(@2);",
 665.580 -                         smapper.getL(1), smapper.popL());
 665.581 -                    break;
 665.582 -                case opc_frem:
 665.583 -                    emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
 665.584 -                    break;
 665.585 -                case opc_drem:
 665.586 -                    emit(out, "@1 %= @2;", smapper.getD(1), smapper.popD());
 665.587 -                    break;
 665.588 -                case opc_iand:
 665.589 -                    emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
 665.590 -                    break;
 665.591 -                case opc_land:
 665.592 -                    emit(out, "@1 = @1.and64(@2);", smapper.getL(1), smapper.popL());
 665.593 -                    break;
 665.594 -                case opc_ior:
 665.595 -                    emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
 665.596 -                    break;
 665.597 -                case opc_lor:
 665.598 -                    emit(out, "@1 = @1.or64(@2);", smapper.getL(1), smapper.popL());
 665.599 -                    break;
 665.600 -                case opc_ixor:
 665.601 -                    emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
 665.602 -                    break;
 665.603 -                case opc_lxor:
 665.604 -                    emit(out, "@1 = @1.xor64(@2);", smapper.getL(1), smapper.popL());
 665.605 -                    break;
 665.606 -                case opc_ineg:
 665.607 -                    emit(out, "@1 = @1.neg32();", smapper.getI(0));
 665.608 -                    break;
 665.609 -                case opc_lneg:
 665.610 -                    emit(out, "@1 = @1.neg64();", smapper.getL(0));
 665.611 -                    break;
 665.612 -                case opc_fneg:
 665.613 -                    emit(out, "@1 = -@1;", smapper.getF(0));
 665.614 -                    break;
 665.615 -                case opc_dneg:
 665.616 -                    emit(out, "@1 = -@1;", smapper.getD(0));
 665.617 -                    break;
 665.618 -                case opc_ishl:
 665.619 -                    emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
 665.620 -                    break;
 665.621 -                case opc_lshl:
 665.622 -                    emit(out, "@1 = @1.shl64(@2);", smapper.getL(1), smapper.popI());
 665.623 -                    break;
 665.624 -                case opc_ishr:
 665.625 -                    emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
 665.626 -                    break;
 665.627 -                case opc_lshr:
 665.628 -                    emit(out, "@1 = @1.shr64(@2);", smapper.getL(1), smapper.popI());
 665.629 -                    break;
 665.630 -                case opc_iushr:
 665.631 -                    emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
 665.632 -                    break;
 665.633 -                case opc_lushr:
 665.634 -                    emit(out, "@1 = @1.ushr64(@2);", smapper.getL(1), smapper.popI());
 665.635 -                    break;
 665.636 -                case opc_iinc: {
 665.637 -                    ++i;
 665.638 -                    final int varIndx = wide ? readUShort(byteCodes, i++)
 665.639 -                                             : readUByte(byteCodes, i);
 665.640 -                    ++i;
 665.641 -                    final int incrBy = wide ? readShort(byteCodes, i++)
 665.642 -                                            : byteCodes[i];
 665.643 -                    wide = false;
 665.644 -                    if (incrBy == 1) {
 665.645 -                        emit(out, "@1++;", lmapper.getI(varIndx));
 665.646 -                    } else {
 665.647 -                        emit(out, "@1 += @2;",
 665.648 -                             lmapper.getI(varIndx),
 665.649 -                             Integer.toString(incrBy));
 665.650 -                    }
 665.651 -                    break;
 665.652 -                }
 665.653 -                case opc_return:
 665.654 -                    emit(out, "return;");
 665.655 -                    break;
 665.656 -                case opc_ireturn:
 665.657 -                    emit(out, "return @1;", smapper.popI());
 665.658 -                    break;
 665.659 -                case opc_lreturn:
 665.660 -                    emit(out, "return @1;", smapper.popL());
 665.661 -                    break;
 665.662 -                case opc_freturn:
 665.663 -                    emit(out, "return @1;", smapper.popF());
 665.664 -                    break;
 665.665 -                case opc_dreturn:
 665.666 -                    emit(out, "return @1;", smapper.popD());
 665.667 -                    break;
 665.668 -                case opc_areturn:
 665.669 -                    emit(out, "return @1;", smapper.popA());
 665.670 -                    break;
 665.671 -                case opc_i2l:
 665.672 -                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushL());
 665.673 -                    break;
 665.674 -                case opc_i2f:
 665.675 -                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushF());
 665.676 -                    break;
 665.677 -                case opc_i2d:
 665.678 -                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
 665.679 -                    break;
 665.680 -                case opc_l2i:
 665.681 -                    emit(out, "var @2 = @1.toInt32();", smapper.popL(), smapper.pushI());
 665.682 -                    break;
 665.683 -                    // max int check?
 665.684 -                case opc_l2f:
 665.685 -                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushF());
 665.686 -                    break;
 665.687 -                case opc_l2d:
 665.688 -                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushD());
 665.689 -                    break;
 665.690 -                case opc_f2d:
 665.691 -                    emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
 665.692 -                    break;
 665.693 -                case opc_d2f:
 665.694 -                    emit(out, "var @2 = @1;", smapper.popD(), smapper.pushF());
 665.695 -                    break;
 665.696 -                case opc_f2i:
 665.697 -                    emit(out, "var @2 = Math.floor(@1);",
 665.698 -                         smapper.popF(), smapper.pushI());
 665.699 -                    break;
 665.700 -                case opc_f2l:
 665.701 -                    emit(out, "var @2 = Math.floor(@1).toLong();",
 665.702 -                         smapper.popF(), smapper.pushL());
 665.703 -                    break;
 665.704 -                case opc_d2i:
 665.705 -                    emit(out, "var @2 = Math.floor(@1);",
 665.706 -                         smapper.popD(), smapper.pushI());
 665.707 -                    break;
 665.708 -                case opc_d2l:
 665.709 -                    emit(out, "var @2 = Math.floor(@1).toLong();",
 665.710 -                         smapper.popD(), smapper.pushL());
 665.711 -                    break;
 665.712 -                case opc_i2b:
 665.713 -                    emit(out, "var @1 = @1.toInt8();", smapper.getI(0));
 665.714 -                    break;
 665.715 -                case opc_i2c:
 665.716 -                    out.append("{ /* number conversion */ }");
 665.717 -                    break;
 665.718 -                case opc_i2s:
 665.719 -                    emit(out, "var @1 = @1.toInt16();", smapper.getI(0));
 665.720 -                    break;
 665.721 -                case opc_aconst_null:
 665.722 -                    emit(out, "var @1 = null;", smapper.pushA());
 665.723 -                    break;
 665.724 -                case opc_iconst_m1:
 665.725 -                    emit(out, "var @1 = -1;", smapper.pushI());
 665.726 -                    break;
 665.727 -                case opc_iconst_0:
 665.728 -                    emit(out, "var @1 = 0;", smapper.pushI());
 665.729 -                    break;
 665.730 -                case opc_dconst_0:
 665.731 -                    emit(out, "var @1 = 0;", smapper.pushD());
 665.732 -                    break;
 665.733 -                case opc_lconst_0:
 665.734 -                    emit(out, "var @1 = 0;", smapper.pushL());
 665.735 -                    break;
 665.736 -                case opc_fconst_0:
 665.737 -                    emit(out, "var @1 = 0;", smapper.pushF());
 665.738 -                    break;
 665.739 -                case opc_iconst_1:
 665.740 -                    emit(out, "var @1 = 1;", smapper.pushI());
 665.741 -                    break;
 665.742 -                case opc_lconst_1:
 665.743 -                    emit(out, "var @1 = 1;", smapper.pushL());
 665.744 -                    break;
 665.745 -                case opc_fconst_1:
 665.746 -                    emit(out, "var @1 = 1;", smapper.pushF());
 665.747 -                    break;
 665.748 -                case opc_dconst_1:
 665.749 -                    emit(out, "var @1 = 1;", smapper.pushD());
 665.750 -                    break;
 665.751 -                case opc_iconst_2:
 665.752 -                    emit(out, "var @1 = 2;", smapper.pushI());
 665.753 -                    break;
 665.754 -                case opc_fconst_2:
 665.755 -                    emit(out, "var @1 = 2;", smapper.pushF());
 665.756 -                    break;
 665.757 -                case opc_iconst_3:
 665.758 -                    emit(out, "var @1 = 3;", smapper.pushI());
 665.759 -                    break;
 665.760 -                case opc_iconst_4:
 665.761 -                    emit(out, "var @1 = 4;", smapper.pushI());
 665.762 -                    break;
 665.763 -                case opc_iconst_5:
 665.764 -                    emit(out, "var @1 = 5;", smapper.pushI());
 665.765 -                    break;
 665.766 -                case opc_ldc: {
 665.767 -                    int indx = readUByte(byteCodes, ++i);
 665.768 -                    String v = encodeConstant(indx);
 665.769 -                    int type = VarType.fromConstantType(jc.getTag(indx));
 665.770 -                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
 665.771 -                    break;
 665.772 -                }
 665.773 -                case opc_ldc_w:
 665.774 -                case opc_ldc2_w: {
 665.775 -                    int indx = readIntArg(byteCodes, i);
 665.776 -                    i += 2;
 665.777 -                    String v = encodeConstant(indx);
 665.778 -                    int type = VarType.fromConstantType(jc.getTag(indx));
 665.779 -                    if (type == VarType.LONG) {
 665.780 -                        final Long lv = new Long(v);
 665.781 -                        final int low = (int)(lv.longValue() & 0xFFFFFFFF);
 665.782 -                        final int hi = (int)(lv.longValue() >> 32);
 665.783 -                        emit(out, "var @1 = 0x@3.next32(0x@2);", smapper.pushL(), 
 665.784 -                                Integer.toHexString(low), Integer.toHexString(hi));
 665.785 -                    } else {
 665.786 -                        emit(out, "var @1 = @2;", smapper.pushT(type), v);
 665.787 -                    }
 665.788 -                    break;
 665.789 -                }
 665.790 -                case opc_lcmp:
 665.791 -                    emit(out, "var @3 = @2.compare64(@1);",
 665.792 -                         smapper.popL(), smapper.popL(), smapper.pushI());
 665.793 -                    break;
 665.794 -                case opc_fcmpl:
 665.795 -                case opc_fcmpg:
 665.796 -                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 665.797 -                         smapper.popF(), smapper.popF(), smapper.pushI());
 665.798 -                    break;
 665.799 -                case opc_dcmpl:
 665.800 -                case opc_dcmpg:
 665.801 -                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
 665.802 -                         smapper.popD(), smapper.popD(), smapper.pushI());
 665.803 -                    break;
 665.804 -                case opc_if_acmpeq:
 665.805 -                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
 665.806 -                                   "===");
 665.807 -                    break;
 665.808 -                case opc_if_acmpne:
 665.809 -                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
 665.810 -                                   "!=");
 665.811 -                    break;
 665.812 -                case opc_if_icmpeq:
 665.813 -                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 665.814 -                                   "==");
 665.815 -                    break;
 665.816 -                case opc_ifeq: {
 665.817 -                    int indx = i + readIntArg(byteCodes, i);
 665.818 -                    emit(out, "if (@1 == 0) { gt = @2; continue; }",
 665.819 -                         smapper.popI(), Integer.toString(indx));
 665.820 -                    i += 2;
 665.821 -                    break;
 665.822 -                }
 665.823 -                case opc_ifne: {
 665.824 -                    int indx = i + readIntArg(byteCodes, i);
 665.825 -                    emit(out, "if (@1 != 0) { gt = @2; continue; }",
 665.826 -                         smapper.popI(), Integer.toString(indx));
 665.827 -                    i += 2;
 665.828 -                    break;
 665.829 -                }
 665.830 -                case opc_iflt: {
 665.831 -                    int indx = i + readIntArg(byteCodes, i);
 665.832 -                    emit(out, "if (@1 < 0) { gt = @2; continue; }",
 665.833 -                         smapper.popI(), Integer.toString(indx));
 665.834 -                    i += 2;
 665.835 -                    break;
 665.836 -                }
 665.837 -                case opc_ifle: {
 665.838 -                    int indx = i + readIntArg(byteCodes, i);
 665.839 -                    emit(out, "if (@1 <= 0) { gt = @2; continue; }",
 665.840 -                         smapper.popI(), Integer.toString(indx));
 665.841 -                    i += 2;
 665.842 -                    break;
 665.843 -                }
 665.844 -                case opc_ifgt: {
 665.845 -                    int indx = i + readIntArg(byteCodes, i);
 665.846 -                    emit(out, "if (@1 > 0) { gt = @2; continue; }",
 665.847 -                         smapper.popI(), Integer.toString(indx));
 665.848 -                    i += 2;
 665.849 -                    break;
 665.850 -                }
 665.851 -                case opc_ifge: {
 665.852 -                    int indx = i + readIntArg(byteCodes, i);
 665.853 -                    emit(out, "if (@1 >= 0) { gt = @2; continue; }",
 665.854 -                         smapper.popI(), Integer.toString(indx));
 665.855 -                    i += 2;
 665.856 -                    break;
 665.857 -                }
 665.858 -                case opc_ifnonnull: {
 665.859 -                    int indx = i + readIntArg(byteCodes, i);
 665.860 -                    emit(out, "if (@1 !== null) { gt = @2; continue; }",
 665.861 -                         smapper.popA(), Integer.toString(indx));
 665.862 -                    i += 2;
 665.863 -                    break;
 665.864 -                }
 665.865 -                case opc_ifnull: {
 665.866 -                    int indx = i + readIntArg(byteCodes, i);
 665.867 -                    emit(out, "if (@1 === null) { gt = @2; continue; }",
 665.868 -                         smapper.popA(), Integer.toString(indx));
 665.869 -                    i += 2;
 665.870 -                    break;
 665.871 -                }
 665.872 -                case opc_if_icmpne:
 665.873 -                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 665.874 -                                   "!=");
 665.875 -                    break;
 665.876 -                case opc_if_icmplt:
 665.877 -                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 665.878 -                                   "<");
 665.879 -                    break;
 665.880 -                case opc_if_icmple:
 665.881 -                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 665.882 -                                   "<=");
 665.883 -                    break;
 665.884 -                case opc_if_icmpgt:
 665.885 -                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 665.886 -                                   ">");
 665.887 -                    break;
 665.888 -                case opc_if_icmpge:
 665.889 -                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
 665.890 -                                   ">=");
 665.891 -                    break;
 665.892 -                case opc_goto: {
 665.893 -                    int indx = i + readIntArg(byteCodes, i);
 665.894 -                    emit(out, "gt = @1; continue;", Integer.toString(indx));
 665.895 -                    i += 2;
 665.896 -                    break;
 665.897 -                }
 665.898 -                case opc_lookupswitch: {
 665.899 -                    int table = i / 4 * 4 + 4;
 665.900 -                    int dflt = i + readInt4(byteCodes, table);
 665.901 -                    table += 4;
 665.902 -                    int n = readInt4(byteCodes, table);
 665.903 -                    table += 4;
 665.904 -                    out.append("switch (").append(smapper.popI()).append(") {\n");
 665.905 -                    while (n-- > 0) {
 665.906 -                        int cnstnt = readInt4(byteCodes, table);
 665.907 -                        table += 4;
 665.908 -                        int offset = i + readInt4(byteCodes, table);
 665.909 -                        table += 4;
 665.910 -                        out.append("  case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
 665.911 -                    }
 665.912 -                    out.append("  default: gt = " + dflt).append("; continue;\n}");
 665.913 -                    i = table - 1;
 665.914 -                    break;
 665.915 -                }
 665.916 -                case opc_tableswitch: {
 665.917 -                    int table = i / 4 * 4 + 4;
 665.918 -                    int dflt = i + readInt4(byteCodes, table);
 665.919 -                    table += 4;
 665.920 -                    int low = readInt4(byteCodes, table);
 665.921 -                    table += 4;
 665.922 -                    int high = readInt4(byteCodes, table);
 665.923 -                    table += 4;
 665.924 -                    out.append("switch (").append(smapper.popI()).append(") {\n");
 665.925 -                    while (low <= high) {
 665.926 -                        int offset = i + readInt4(byteCodes, table);
 665.927 -                        table += 4;
 665.928 -                        out.append("  case " + low).append(": gt = " + offset).append("; continue;\n");
 665.929 -                        low++;
 665.930 -                    }
 665.931 -                    out.append("  default: gt = " + dflt).append("; continue;\n}");
 665.932 -                    i = table - 1;
 665.933 -                    break;
 665.934 -                }
 665.935 -                case opc_invokeinterface: {
 665.936 -                    i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
 665.937 -                    break;
 665.938 -                }
 665.939 -                case opc_invokevirtual:
 665.940 -                    i = invokeVirtualMethod(byteCodes, i, smapper);
 665.941 -                    break;
 665.942 -                case opc_invokespecial:
 665.943 -                    i = invokeStaticMethod(byteCodes, i, smapper, false);
 665.944 -                    break;
 665.945 -                case opc_invokestatic:
 665.946 -                    i = invokeStaticMethod(byteCodes, i, smapper, true);
 665.947 -                    break;
 665.948 -                case opc_new: {
 665.949 -                    int indx = readIntArg(byteCodes, i);
 665.950 -                    String ci = jc.getClassName(indx);
 665.951 -                    emit(out, "var @1 = new @2;",
 665.952 -                         smapper.pushA(), accessClass(ci.replace('/', '_')));
 665.953 -                    addReference(ci);
 665.954 -                    i += 2;
 665.955 -                    break;
 665.956 -                }
 665.957 -                case opc_newarray:
 665.958 -                    int atype = readUByte(byteCodes, ++i);
 665.959 -                    String jvmType;
 665.960 -                    switch (atype) {
 665.961 -                        case 4: jvmType = "[Z"; break;
 665.962 -                        case 5: jvmType = "[C"; break;
 665.963 -                        case 6: jvmType = "[F"; break;
 665.964 -                        case 7: jvmType = "[D"; break;
 665.965 -                        case 8: jvmType = "[B"; break;
 665.966 -                        case 9: jvmType = "[S"; break;
 665.967 -                        case 10: jvmType = "[I"; break;
 665.968 -                        case 11: jvmType = "[J"; break;
 665.969 -                        default: throw new IllegalStateException("Array type: " + atype);
 665.970 -                    }
 665.971 -                    emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(true, '@3', @1);",
 665.972 -                         smapper.popI(), smapper.pushA(), jvmType);
 665.973 -                    break;
 665.974 -                case opc_anewarray: {
 665.975 -                    int type = readIntArg(byteCodes, i);
 665.976 -                    i += 2;
 665.977 -                    String typeName = jc.getClassName(type);
 665.978 -                    if (typeName.startsWith("[")) {
 665.979 -                        typeName = "[" + typeName;
 665.980 -                    } else {
 665.981 -                        typeName = "[L" + typeName + ";";
 665.982 -                    }
 665.983 -                    emit(out, "var @2 = Array.prototype.newArray__Ljava_lang_Object_2ZLjava_lang_String_2I(false, '@3', @1);",
 665.984 -                         smapper.popI(), smapper.pushA(), typeName);
 665.985 -                    break;
 665.986 -                }
 665.987 -                case opc_multianewarray: {
 665.988 -                    int type = readIntArg(byteCodes, i);
 665.989 -                    i += 2;
 665.990 -                    String typeName = jc.getClassName(type);
 665.991 -                    int dim = readUByte(byteCodes, ++i);
 665.992 -                    StringBuilder dims = new StringBuilder();
 665.993 -                    dims.append('[');
 665.994 -                    for (int d = 0; d < dim; d++) {
 665.995 -                        if (d != 0) {
 665.996 -                            dims.append(",");
 665.997 -                        }
 665.998 -                        dims.append(smapper.popI());
 665.999 -                    }
665.1000 -                    dims.append(']');
665.1001 -                    emit(out, "var @2 = Array.prototype.multiNewArray__Ljava_lang_Object_2Ljava_lang_String_2_3II('@3', @1, 0);",
665.1002 -                         dims.toString(), smapper.pushA(), typeName);
665.1003 -                    break;
665.1004 -                }
665.1005 -                case opc_arraylength:
665.1006 -                    emit(out, "var @2 = @1.length;",
665.1007 -                         smapper.popA(), smapper.pushI());
665.1008 -                    break;
665.1009 -                case opc_lastore:
665.1010 -                    emit(out, "@3.at(@2, @1);",
665.1011 -                         smapper.popL(), smapper.popI(), smapper.popA());
665.1012 -                    break;
665.1013 -                case opc_fastore:
665.1014 -                    emit(out, "@3.at(@2, @1);",
665.1015 -                         smapper.popF(), smapper.popI(), smapper.popA());
665.1016 -                    break;
665.1017 -                case opc_dastore:
665.1018 -                    emit(out, "@3.at(@2, @1);",
665.1019 -                         smapper.popD(), smapper.popI(), smapper.popA());
665.1020 -                    break;
665.1021 -                case opc_aastore:
665.1022 -                    emit(out, "@3.at(@2, @1);",
665.1023 -                         smapper.popA(), smapper.popI(), smapper.popA());
665.1024 -                    break;
665.1025 -                case opc_iastore:
665.1026 -                case opc_bastore:
665.1027 -                case opc_castore:
665.1028 -                case opc_sastore:
665.1029 -                    emit(out, "@3.at(@2, @1);",
665.1030 -                         smapper.popI(), smapper.popI(), smapper.popA());
665.1031 -                    break;
665.1032 -                case opc_laload:
665.1033 -                    emit(out, "var @3 = @2.at(@1);",
665.1034 -                         smapper.popI(), smapper.popA(), smapper.pushL());
665.1035 -                    break;
665.1036 -                case opc_faload:
665.1037 -                    emit(out, "var @3 = @2.at(@1);",
665.1038 -                         smapper.popI(), smapper.popA(), smapper.pushF());
665.1039 -                    break;
665.1040 -                case opc_daload:
665.1041 -                    emit(out, "var @3 = @2.at(@1);",
665.1042 -                         smapper.popI(), smapper.popA(), smapper.pushD());
665.1043 -                    break;
665.1044 -                case opc_aaload:
665.1045 -                    emit(out, "var @3 = @2.at(@1);",
665.1046 -                         smapper.popI(), smapper.popA(), smapper.pushA());
665.1047 -                    break;
665.1048 -                case opc_iaload:
665.1049 -                case opc_baload:
665.1050 -                case opc_caload:
665.1051 -                case opc_saload:
665.1052 -                    emit(out, "var @3 = @2.at(@1);",
665.1053 -                         smapper.popI(), smapper.popA(), smapper.pushI());
665.1054 -                    break;
665.1055 -                case opc_pop:
665.1056 -                case opc_pop2:
665.1057 -                    smapper.pop(1);
665.1058 -                    debug("/* pop */");
665.1059 -                    break;
665.1060 -                case opc_dup: {
665.1061 -                    final Variable v = smapper.get(0);
665.1062 -                    emit(out, "var @1 = @2;", smapper.pushT(v.getType()), v);
665.1063 -                    break;
665.1064 -                }
665.1065 -                case opc_dup2: {
665.1066 -                    final Variable vi1 = smapper.get(0);
665.1067 -
665.1068 -                    if (vi1.isCategory2()) {
665.1069 -                        emit(out, "var @1 = @2;",
665.1070 -                             smapper.pushT(vi1.getType()), vi1);
665.1071 -                    } else {
665.1072 -                        final Variable vi2 = smapper.get(1);
665.1073 -                        emit(out, "var @1 = @2, @3 = @4;",
665.1074 -                             smapper.pushT(vi2.getType()), vi2,
665.1075 -                             smapper.pushT(vi1.getType()), vi1);
665.1076 -                    }
665.1077 -                    break;
665.1078 -                }
665.1079 -                case opc_dup_x1: {
665.1080 -                    final Variable vi1 = smapper.pop();
665.1081 -                    final Variable vi2 = smapper.pop();
665.1082 -                    final Variable vo3 = smapper.pushT(vi1.getType());
665.1083 -                    final Variable vo2 = smapper.pushT(vi2.getType());
665.1084 -                    final Variable vo1 = smapper.pushT(vi1.getType());
665.1085 -
665.1086 -                    emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
665.1087 -                         vo1, vi1, vo2, vi2, vo3, vo1);
665.1088 -                    break;
665.1089 -                }
665.1090 -                case opc_dup2_x1: {
665.1091 -                    final Variable vi1 = smapper.pop();
665.1092 -                    final Variable vi2 = smapper.pop();
665.1093 -
665.1094 -                    if (vi1.isCategory2()) {
665.1095 -                        final Variable vo3 = smapper.pushT(vi1.getType());
665.1096 -                        final Variable vo2 = smapper.pushT(vi2.getType());
665.1097 -                        final Variable vo1 = smapper.pushT(vi1.getType());
665.1098 -
665.1099 -                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
665.1100 -                             vo1, vi1, vo2, vi2, vo3, vo1);
665.1101 -                    } else {
665.1102 -                        final Variable vi3 = smapper.pop();
665.1103 -                        final Variable vo5 = smapper.pushT(vi2.getType());
665.1104 -                        final Variable vo4 = smapper.pushT(vi1.getType());
665.1105 -                        final Variable vo3 = smapper.pushT(vi3.getType());
665.1106 -                        final Variable vo2 = smapper.pushT(vi2.getType());
665.1107 -                        final Variable vo1 = smapper.pushT(vi1.getType());
665.1108 -
665.1109 -                        emit(out, "var @1 = @2, @3 = @4, @5 = @6,",
665.1110 -                             vo1, vi1, vo2, vi2, vo3, vi3);
665.1111 -                        emit(out, " @1 = @2, @3 = @4;",
665.1112 -                             vo4, vo1, vo5, vo2);
665.1113 -                    }
665.1114 -                    break;
665.1115 -                }
665.1116 -                case opc_dup_x2: {
665.1117 -                    final Variable vi1 = smapper.pop();
665.1118 -                    final Variable vi2 = smapper.pop();
665.1119 -
665.1120 -                    if (vi2.isCategory2()) {
665.1121 -                        final Variable vo3 = smapper.pushT(vi1.getType());
665.1122 -                        final Variable vo2 = smapper.pushT(vi2.getType());
665.1123 -                        final Variable vo1 = smapper.pushT(vi1.getType());
665.1124 -
665.1125 -                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
665.1126 -                             vo1, vi1, vo2, vi2, vo3, vo1);
665.1127 -                    } else {
665.1128 -                        final Variable vi3 = smapper.pop();
665.1129 -                        final Variable vo4 = smapper.pushT(vi1.getType());
665.1130 -                        final Variable vo3 = smapper.pushT(vi3.getType());
665.1131 -                        final Variable vo2 = smapper.pushT(vi2.getType());
665.1132 -                        final Variable vo1 = smapper.pushT(vi1.getType());
665.1133 -
665.1134 -                        emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
665.1135 -                             vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
665.1136 -                    }
665.1137 -                    break;
665.1138 -                }
665.1139 -                case opc_dup2_x2: {
665.1140 -                    final Variable vi1 = smapper.pop();
665.1141 -                    final Variable vi2 = smapper.pop();
665.1142 -
665.1143 -                    if (vi1.isCategory2()) {
665.1144 -                        if (vi2.isCategory2()) {
665.1145 -                            final Variable vo3 = smapper.pushT(vi1.getType());
665.1146 -                            final Variable vo2 = smapper.pushT(vi2.getType());
665.1147 -                            final Variable vo1 = smapper.pushT(vi1.getType());
665.1148 -
665.1149 -                            emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
665.1150 -                                 vo1, vi1, vo2, vi2, vo3, vo1);
665.1151 -                        } else {
665.1152 -                            final Variable vi3 = smapper.pop();
665.1153 -                            final Variable vo4 = smapper.pushT(vi1.getType());
665.1154 -                            final Variable vo3 = smapper.pushT(vi3.getType());
665.1155 -                            final Variable vo2 = smapper.pushT(vi2.getType());
665.1156 -                            final Variable vo1 = smapper.pushT(vi1.getType());
665.1157 -
665.1158 -                            emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
665.1159 -                                 vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
665.1160 -                        }
665.1161 -                    } else {
665.1162 -                        final Variable vi3 = smapper.pop();
665.1163 -
665.1164 -                        if (vi3.isCategory2()) {
665.1165 -                            final Variable vo5 = smapper.pushT(vi2.getType());
665.1166 -                            final Variable vo4 = smapper.pushT(vi1.getType());
665.1167 -                            final Variable vo3 = smapper.pushT(vi3.getType());
665.1168 -                            final Variable vo2 = smapper.pushT(vi2.getType());
665.1169 -                            final Variable vo1 = smapper.pushT(vi1.getType());
665.1170 -
665.1171 -                            emit(out, "var @1 = @2, @3 = @4, @5 = @6,",
665.1172 -                                 vo1, vi1, vo2, vi2, vo3, vi3);
665.1173 -                            emit(out, " @1 = @2, @3 = @4;",
665.1174 -                                 vo4, vo1, vo5, vo2);
665.1175 -                        } else {
665.1176 -                            final Variable vi4 = smapper.pop();
665.1177 -                            final Variable vo6 = smapper.pushT(vi2.getType());
665.1178 -                            final Variable vo5 = smapper.pushT(vi1.getType());
665.1179 -                            final Variable vo4 = smapper.pushT(vi4.getType());
665.1180 -                            final Variable vo3 = smapper.pushT(vi3.getType());
665.1181 -                            final Variable vo2 = smapper.pushT(vi2.getType());
665.1182 -                            final Variable vo1 = smapper.pushT(vi1.getType());
665.1183 -                            
665.1184 -                            emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8,",
665.1185 -                                 vo1, vi1, vo2, vi2, vo3, vi3, vo4, vi4);
665.1186 -                            emit(out, " @1 = @2, @3 = @4;",
665.1187 -                                 vo5, vo1, vo6, vo2);
665.1188 -                        }
665.1189 -                    }
665.1190 -                    break;
665.1191 -                }
665.1192 -                case opc_swap: {
665.1193 -                    final Variable vi1 = smapper.get(0);
665.1194 -                    final Variable vi2 = smapper.get(1);
665.1195 -
665.1196 -                    if (vi1.getType() == vi2.getType()) {
665.1197 -                        final Variable tmp = smapper.pushT(vi1.getType());
665.1198 -
665.1199 -                        emit(out, "var @1 = @2, @2 = @3, @3 = @1;",
665.1200 -                             tmp, vi1, vi2);
665.1201 -                        smapper.pop(1);
665.1202 -                    } else {
665.1203 -                        smapper.pop(2);
665.1204 -                        smapper.pushT(vi1.getType());
665.1205 -                        smapper.pushT(vi2.getType());
665.1206 -                    }
665.1207 -                    break;
665.1208 -                }
665.1209 -                case opc_bipush:
665.1210 -                    emit(out, "var @1 = @2;",
665.1211 -                         smapper.pushI(), Integer.toString(byteCodes[++i]));
665.1212 -                    break;
665.1213 -                case opc_sipush:
665.1214 -                    emit(out, "var @1 = @2;",
665.1215 -                         smapper.pushI(),
665.1216 -                         Integer.toString(readIntArg(byteCodes, i)));
665.1217 -                    i += 2;
665.1218 -                    break;
665.1219 -                case opc_getfield: {
665.1220 -                    int indx = readIntArg(byteCodes, i);
665.1221 -                    String[] fi = jc.getFieldInfoName(indx);
665.1222 -                    final int type = VarType.fromFieldType(fi[2].charAt(0));
665.1223 -                    final String mangleClass = mangleSig(fi[0]);
665.1224 -                    final String mangleClassAccess = accessClass(mangleClass);
665.1225 -                    emit(out, "var @2 = @4(false)._@3.call(@1);",
665.1226 -                         smapper.popA(),
665.1227 -                         smapper.pushT(type), fi[1], mangleClassAccess
665.1228 -                    );
665.1229 -                    i += 2;
665.1230 -                    break;
665.1231 -                }
665.1232 -                case opc_putfield: {
665.1233 -                    int indx = readIntArg(byteCodes, i);
665.1234 -                    String[] fi = jc.getFieldInfoName(indx);
665.1235 -                    final int type = VarType.fromFieldType(fi[2].charAt(0));
665.1236 -                    final String mangleClass = mangleSig(fi[0]);
665.1237 -                    final String mangleClassAccess = accessClass(mangleClass);
665.1238 -                    emit(out, "@4(false)._@3.call(@2, @1);",
665.1239 -                         smapper.popT(type),
665.1240 -                         smapper.popA(), fi[1], 
665.1241 -                         mangleClassAccess
665.1242 -                    );
665.1243 -                    i += 2;
665.1244 -                    break;
665.1245 -                }
665.1246 -                case opc_getstatic: {
665.1247 -                    int indx = readIntArg(byteCodes, i);
665.1248 -                    String[] fi = jc.getFieldInfoName(indx);
665.1249 -                    final int type = VarType.fromFieldType(fi[2].charAt(0));
665.1250 -                    emit(out, "var @1 = @2(false).constructor.@3;",
665.1251 -                         smapper.pushT(type),
665.1252 -                         accessClass(fi[0].replace('/', '_')), fi[1]);
665.1253 -                    i += 2;
665.1254 -                    addReference(fi[0]);
665.1255 -                    break;
665.1256 -                }
665.1257 -                case opc_putstatic: {
665.1258 -                    int indx = readIntArg(byteCodes, i);
665.1259 -                    String[] fi = jc.getFieldInfoName(indx);
665.1260 -                    final int type = VarType.fromFieldType(fi[2].charAt(0));
665.1261 -                    emit(out, "@1(false).constructor.@2 = @3;",
665.1262 -                         accessClass(fi[0].replace('/', '_')), fi[1],
665.1263 -                         smapper.popT(type));
665.1264 -                    i += 2;
665.1265 -                    addReference(fi[0]);
665.1266 -                    break;
665.1267 -                }
665.1268 -                case opc_checkcast: {
665.1269 -                    int indx = readIntArg(byteCodes, i);
665.1270 -                    final String type = jc.getClassName(indx);
665.1271 -                    if (!type.startsWith("[")) {
665.1272 -                        emit(out,
665.1273 -                             "if (@1 !== null && !@1.$instOf_@2) throw {};",
665.1274 -                             smapper.getA(0), type.replace('/', '_'));
665.1275 -                    } else {
665.1276 -                        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);",
665.1277 -                             smapper.getA(0), type
665.1278 -                        );
665.1279 -                    }
665.1280 -                    i += 2;
665.1281 -                    break;
665.1282 -                }
665.1283 -                case opc_instanceof: {
665.1284 -                    int indx = readIntArg(byteCodes, i);
665.1285 -                    final String type = jc.getClassName(indx);
665.1286 -                    if (!type.startsWith("[")) {
665.1287 -                        emit(out, "var @2 = @1 != null && @1.$instOf_@3 ? 1 : 0;",
665.1288 -                             smapper.popA(), smapper.pushI(),
665.1289 -                             type.replace('/', '_'));
665.1290 -                    } else {
665.1291 -                        emit(out, "var @2 = vm.java_lang_Class(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('@3').isInstance__ZLjava_lang_Object_2(@1);",
665.1292 -                            smapper.popA(), smapper.pushI(),
665.1293 -                            type
665.1294 -                        );
665.1295 -                    }
665.1296 -                    i += 2;
665.1297 -                    break;
665.1298 -                }
665.1299 -                case opc_athrow: {
665.1300 -                    final Variable v = smapper.popA();
665.1301 -                    smapper.clear();
665.1302 -
665.1303 -                    emit(out, "{ var @1 = @2; throw @2; }",
665.1304 -                         smapper.pushA(), v);
665.1305 -                    break;
665.1306 -                }
665.1307 -
665.1308 -                case opc_monitorenter: {
665.1309 -                    out.append("/* monitor enter */");
665.1310 -                    smapper.popA();
665.1311 -                    break;
665.1312 -                }
665.1313 -
665.1314 -                case opc_monitorexit: {
665.1315 -                    out.append("/* monitor exit */");
665.1316 -                    smapper.popA();
665.1317 -                    break;
665.1318 -                }
665.1319 -
665.1320 -                case opc_wide:
665.1321 -                    wide = true;
665.1322 -                    break;
665.1323 -
665.1324 -                default: {
665.1325 -                    wide = false;
665.1326 -                    emit(out, "throw 'unknown bytecode @1';",
665.1327 -                         Integer.toString(c));
665.1328 -                }
665.1329 -            }
665.1330 -            if (debug(" //")) {
665.1331 -                for (int j = prev; j <= i; j++) {
665.1332 -                    out.append(" ");
665.1333 -                    final int cc = readUByte(byteCodes, j);
665.1334 -                    out.append(Integer.toString(cc));
665.1335 -                }
665.1336 -            }
665.1337 -            out.append("\n");            
665.1338 -        }
665.1339 -        if (previousTrap != null) {
665.1340 -            generateCatch(previousTrap);
665.1341 -        }
665.1342 -        out.append("  }\n");
665.1343 -        out.append("};");
665.1344 -    }
665.1345 -
665.1346 -    private int generateIf(byte[] byteCodes, int i,
665.1347 -                           final Variable v2, final Variable v1,
665.1348 -                           final String test) throws IOException {
665.1349 -        int indx = i + readIntArg(byteCodes, i);
665.1350 -        out.append("if (").append(v1)
665.1351 -           .append(' ').append(test).append(' ')
665.1352 -           .append(v2).append(") { gt = " + indx)
665.1353 -           .append("; continue; }");
665.1354 -        return i + 2;
665.1355 -    }
665.1356 -
665.1357 -    private int readIntArg(byte[] byteCodes, int offsetInstruction) {
665.1358 -        final int indxHi = byteCodes[offsetInstruction + 1] << 8;
665.1359 -        final int indxLo = byteCodes[offsetInstruction + 2];
665.1360 -        return (indxHi & 0xffffff00) | (indxLo & 0xff);
665.1361 -    }
665.1362 -    private int readInt4(byte[] byteCodes, int offset) {
665.1363 -        final int d = byteCodes[offset + 0] << 24;
665.1364 -        final int c = byteCodes[offset + 1] << 16;
665.1365 -        final int b = byteCodes[offset + 2] << 8;
665.1366 -        final int a = byteCodes[offset + 3];
665.1367 -        return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
665.1368 -    }
665.1369 -    private int readUByte(byte[] byteCodes, int offset) {
665.1370 -        return byteCodes[offset] & 0xff;
665.1371 -    }
665.1372 -
665.1373 -    private int readUShort(byte[] byteCodes, int offset) {
665.1374 -        return ((byteCodes[offset] & 0xff) << 8)
665.1375 -                    | (byteCodes[offset + 1] & 0xff);
665.1376 -    }
665.1377 -
665.1378 -    private int readShort(byte[] byteCodes, int offset) {
665.1379 -        return (byteCodes[offset] << 8)
665.1380 -                    | (byteCodes[offset + 1] & 0xff);
665.1381 -    }
665.1382 -
665.1383 -    private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
665.1384 -        int i = 0;
665.1385 -        Boolean count = null;
665.1386 -        boolean array = false;
665.1387 -        sig.append("__");
665.1388 -        int firstPos = sig.length();
665.1389 -        while (i < descriptor.length()) {
665.1390 -            char ch = descriptor.charAt(i++);
665.1391 -            switch (ch) {
665.1392 -                case '(':
665.1393 -                    count = true;
665.1394 -                    continue;
665.1395 -                case ')':
665.1396 -                    count = false;
665.1397 -                    continue;
665.1398 -                case 'B': 
665.1399 -                case 'C': 
665.1400 -                case 'D': 
665.1401 -                case 'F': 
665.1402 -                case 'I': 
665.1403 -                case 'J': 
665.1404 -                case 'S': 
665.1405 -                case 'Z': 
665.1406 -                    if (count) {
665.1407 -                        if (array) {
665.1408 -                            sig.append("_3");
665.1409 -                        }
665.1410 -                        sig.append(ch);
665.1411 -                        if (ch == 'J' || ch == 'D') {
665.1412 -                            cnt.append('1');
665.1413 -                        } else {
665.1414 -                            cnt.append('0');
665.1415 -                        }
665.1416 -                    } else {
665.1417 -                        sig.insert(firstPos, ch);
665.1418 -                        if (array) {
665.1419 -                            returnType[0] = '[';
665.1420 -                            sig.insert(firstPos, "_3");
665.1421 -                        } else {
665.1422 -                            returnType[0] = ch;
665.1423 -                        }
665.1424 -                    }
665.1425 -                    array = false;
665.1426 -                    continue;
665.1427 -                case 'V': 
665.1428 -                    assert !count;
665.1429 -                    returnType[0] = 'V';
665.1430 -                    sig.insert(firstPos, 'V');
665.1431 -                    continue;
665.1432 -                case 'L':
665.1433 -                    int next = descriptor.indexOf(';', i);
665.1434 -                    String realSig = mangleSig(descriptor, i - 1, next + 1);
665.1435 -                    if (count) {
665.1436 -                        if (array) {
665.1437 -                            sig.append("_3");
665.1438 -                        }
665.1439 -                        sig.append(realSig);
665.1440 -                        cnt.append('0');
665.1441 -                    } else {
665.1442 -                        sig.insert(firstPos, realSig);
665.1443 -                        if (array) {
665.1444 -                            sig.insert(firstPos, "_3");
665.1445 -                        }
665.1446 -                        returnType[0] = 'L';
665.1447 -                    }
665.1448 -                    i = next + 1;
665.1449 -                    array = false;
665.1450 -                    continue;
665.1451 -                case '[':
665.1452 -                    array = true;
665.1453 -                    continue;
665.1454 -                default:
665.1455 -                    throw new IllegalStateException("Invalid char: " + ch);
665.1456 -            }
665.1457 -        }
665.1458 -    }
665.1459 -    
665.1460 -    static String mangleSig(String sig) {
665.1461 -        return mangleSig(sig, 0, sig.length());
665.1462 -    }
665.1463 -    
665.1464 -    private static String mangleSig(String txt, int first, int last) {
665.1465 -        StringBuilder sb = new StringBuilder();
665.1466 -        for (int i = first; i < last; i++) {
665.1467 -            final char ch = txt.charAt(i);
665.1468 -            switch (ch) {
665.1469 -                case '/': sb.append('_'); break;
665.1470 -                case '_': sb.append("_1"); break;
665.1471 -                case ';': sb.append("_2"); break;
665.1472 -                case '[': sb.append("_3"); break;
665.1473 -                default: sb.append(ch); break;
665.1474 -            }
665.1475 -        }
665.1476 -        return sb.toString();
665.1477 -    }
665.1478 -
665.1479 -    private static String findMethodName(MethodData m, StringBuilder cnt) {
665.1480 -        StringBuilder name = new StringBuilder();
665.1481 -        if ("<init>".equals(m.getName())) { // NOI18N
665.1482 -            name.append("cons"); // NOI18N
665.1483 -        } else if ("<clinit>".equals(m.getName())) { // NOI18N
665.1484 -            name.append("class"); // NOI18N
665.1485 -        } else {
665.1486 -            name.append(m.getName());
665.1487 -        } 
665.1488 -        
665.1489 -        countArgs(m.getInternalSig(), new char[1], name, cnt);
665.1490 -        return name.toString();
665.1491 -    }
665.1492 -
665.1493 -    static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
665.1494 -        StringBuilder name = new StringBuilder();
665.1495 -        String descr = mi[2];//mi.getDescriptor();
665.1496 -        String nm= mi[1];
665.1497 -        if ("<init>".equals(nm)) { // NOI18N
665.1498 -            name.append("cons"); // NOI18N
665.1499 -        } else {
665.1500 -            name.append(nm);
665.1501 -        }
665.1502 -        countArgs(descr, returnType, name, cnt);
665.1503 -        return name.toString();
665.1504 -    }
665.1505 -
665.1506 -    private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
665.1507 -    throws IOException {
665.1508 -        int methodIndex = readIntArg(byteCodes, i);
665.1509 -        String[] mi = jc.getFieldInfoName(methodIndex);
665.1510 -        char[] returnType = { 'V' };
665.1511 -        StringBuilder cnt = new StringBuilder();
665.1512 -        String mn = findMethodName(mi, cnt, returnType);
665.1513 -
665.1514 -        final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
665.1515 -        final Variable[] vars = new Variable[numArguments];
665.1516 -
665.1517 -        for (int j = numArguments - 1; j >= 0; --j) {
665.1518 -            vars[j] = mapper.pop();
665.1519 -        }
665.1520 -
665.1521 -        if (returnType[0] != 'V') {
665.1522 -            out.append("var ")
665.1523 -               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
665.1524 -               .append(" = ");
665.1525 -        }
665.1526 -
665.1527 -        final String in = mi[0];
665.1528 -        out.append(accessClass(in.replace('/', '_')));
665.1529 -        out.append("(false).");
665.1530 -        if (mn.startsWith("cons_")) {
665.1531 -            out.append("constructor.");
665.1532 -        }
665.1533 -        out.append(mn);
665.1534 -        if (isStatic) {
665.1535 -            out.append('(');
665.1536 -        } else {
665.1537 -            out.append(".call(");
665.1538 -        }
665.1539 -        if (numArguments > 0) {
665.1540 -            out.append(vars[0]);
665.1541 -            for (int j = 1; j < numArguments; ++j) {
665.1542 -                out.append(", ");
665.1543 -                out.append(vars[j]);
665.1544 -            }
665.1545 -        }
665.1546 -        out.append(");");
665.1547 -        i += 2;
665.1548 -        addReference(in);
665.1549 -        return i;
665.1550 -    }
665.1551 -    private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
665.1552 -    throws IOException {
665.1553 -        int methodIndex = readIntArg(byteCodes, i);
665.1554 -        String[] mi = jc.getFieldInfoName(methodIndex);
665.1555 -        char[] returnType = { 'V' };
665.1556 -        StringBuilder cnt = new StringBuilder();
665.1557 -        String mn = findMethodName(mi, cnt, returnType);
665.1558 -
665.1559 -        final int numArguments = cnt.length() + 1;
665.1560 -        final Variable[] vars = new Variable[numArguments];
665.1561 -
665.1562 -        for (int j = numArguments - 1; j >= 0; --j) {
665.1563 -            vars[j] = mapper.pop();
665.1564 -        }
665.1565 -
665.1566 -        if (returnType[0] != 'V') {
665.1567 -            out.append("var ")
665.1568 -               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
665.1569 -               .append(" = ");
665.1570 -        }
665.1571 -
665.1572 -        out.append(vars[0]).append('.');
665.1573 -        out.append(mn);
665.1574 -        out.append('(');
665.1575 -        String sep = "";
665.1576 -        for (int j = 1; j < numArguments; ++j) {
665.1577 -            out.append(sep);
665.1578 -            out.append(vars[j]);
665.1579 -            sep = ", ";
665.1580 -        }
665.1581 -        out.append(");");
665.1582 -        i += 2;
665.1583 -        return i;
665.1584 -    }
665.1585 -
665.1586 -    private void addReference(String cn) throws IOException {
665.1587 -        if (requireReference(cn)) {
665.1588 -            debug(" /* needs " + cn + " */");
665.1589 -        }
665.1590 -    }
665.1591 -
665.1592 -    private void outType(String d, StringBuilder out) {
665.1593 -        int arr = 0;
665.1594 -        while (d.charAt(0) == '[') {
665.1595 -            out.append('A');
665.1596 -            d = d.substring(1);
665.1597 -        }
665.1598 -        if (d.charAt(0) == 'L') {
665.1599 -            assert d.charAt(d.length() - 1) == ';';
665.1600 -            out.append(d.replace('/', '_').substring(0, d.length() - 1));
665.1601 -        } else {
665.1602 -            out.append(d);
665.1603 -        }
665.1604 -    }
665.1605 -
665.1606 -    private String encodeConstant(int entryIndex) throws IOException {
665.1607 -        String[] classRef = { null };
665.1608 -        String s = jc.stringValue(entryIndex, classRef);
665.1609 -        if (classRef[0] != null) {
665.1610 -            if (classRef[0].startsWith("[")) {
665.1611 -                s = accessClass("java_lang_Class") + "(false).forName__Ljava_lang_Class_2Ljava_lang_String_2('" + classRef[0] + "');";
665.1612 -            } else {
665.1613 -                addReference(classRef[0]);
665.1614 -                s = accessClass(s.replace('/', '_')) + "(false).constructor.$class";
665.1615 -            }
665.1616 -        }
665.1617 -        return s;
665.1618 -    }
665.1619 -
665.1620 -    private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
665.1621 -        byte[] arr = m.findAnnotationData(true);
665.1622 -        if (arr == null) {
665.1623 -            return null;
665.1624 -        }
665.1625 -        final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
665.1626 -        class P extends AnnotationParser {
665.1627 -            public P() {
665.1628 -                super(false, true);
665.1629 -            }
665.1630 -            
665.1631 -            int cnt;
665.1632 -            String[] args = new String[30];
665.1633 -            String body;
665.1634 -            
665.1635 -            @Override
665.1636 -            protected void visitAttr(String type, String attr, String at, String value) {
665.1637 -                if (type.equals(jvmType)) {
665.1638 -                    if ("body".equals(attr)) {
665.1639 -                        body = value;
665.1640 -                    } else if ("args".equals(attr)) {
665.1641 -                        args[cnt++] = value;
665.1642 -                    } else {
665.1643 -                        throw new IllegalArgumentException(attr);
665.1644 -                    }
665.1645 -                }
665.1646 -            }
665.1647 -        }
665.1648 -        P p = new P();
665.1649 -        p.parse(arr, jc);
665.1650 -        if (p.body == null) {
665.1651 -            return null;
665.1652 -        }
665.1653 -        StringBuilder cnt = new StringBuilder();
665.1654 -        final String mn = findMethodName(m, cnt);
665.1655 -        out.append(prefix).append(mn);
665.1656 -        out.append(" = function(");
665.1657 -        String space = "";
665.1658 -        int index = 0;
665.1659 -        for (int i = 0; i < cnt.length(); i++) {
665.1660 -            out.append(space);
665.1661 -            space = outputArg(out, p.args, index);
665.1662 -            index++;
665.1663 -        }
665.1664 -        out.append(") {").append("\n");
665.1665 -        out.append(p.body);
665.1666 -        out.append("\n}\n");
665.1667 -        return mn;
665.1668 -    }
665.1669 -    private static String className(ClassData jc) {
665.1670 -        //return jc.getName().getInternalName().replace('/', '_');
665.1671 -        return jc.getClassName().replace('/', '_');
665.1672 -    }
665.1673 -    
665.1674 -    private static String[] findAnnotation(
665.1675 -        byte[] arr, ClassData cd, final String className, 
665.1676 -        final String... attrNames
665.1677 -    ) throws IOException {
665.1678 -        if (arr == null) {
665.1679 -            return null;
665.1680 -        }
665.1681 -        final String[] values = new String[attrNames.length];
665.1682 -        final boolean[] found = { false };
665.1683 -        final String jvmType = "L" + className.replace('.', '/') + ";";
665.1684 -        AnnotationParser ap = new AnnotationParser(false, true) {
665.1685 -            @Override
665.1686 -            protected void visitAttr(String type, String attr, String at, String value) {
665.1687 -                if (type.equals(jvmType)) {
665.1688 -                    found[0] = true;
665.1689 -                    for (int i = 0; i < attrNames.length; i++) {
665.1690 -                        if (attrNames[i].equals(attr)) {
665.1691 -                            values[i] = value;
665.1692 -                        }
665.1693 -                    }
665.1694 -                }
665.1695 -            }
665.1696 -            
665.1697 -        };
665.1698 -        ap.parse(arr, cd);
665.1699 -        return found[0] ? values : null;
665.1700 -    }
665.1701 -
665.1702 -    private CharSequence initField(FieldData v) {
665.1703 -        final String is = v.getInternalSig();
665.1704 -        if (is.length() == 1) {
665.1705 -            switch (is.charAt(0)) {
665.1706 -                case 'S':
665.1707 -                case 'J':
665.1708 -                case 'B':
665.1709 -                case 'Z':
665.1710 -                case 'C':
665.1711 -                case 'I': return " = 0;";
665.1712 -                case 'F': 
665.1713 -                case 'D': return " = 0.0;";
665.1714 -                default:
665.1715 -                    throw new IllegalStateException(is);
665.1716 -            }
665.1717 -        }
665.1718 -        return " = null;";
665.1719 -    }
665.1720 -
665.1721 -    private void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
665.1722 -        AnnotationParser ap = new AnnotationParser(true, false) {
665.1723 -            int[] cnt = new int[32];
665.1724 -            int depth;
665.1725 -            
665.1726 -            @Override
665.1727 -            protected void visitAnnotationStart(String attrType, boolean top) throws IOException {
665.1728 -                final String slashType = attrType.substring(1, attrType.length() - 1);
665.1729 -                requireReference(slashType);
665.1730 -                
665.1731 -                if (cnt[depth]++ > 0) {
665.1732 -                    out.append(",");
665.1733 -                }
665.1734 -                if (top) {
665.1735 -                    out.append('"').append(attrType).append("\" : ");
665.1736 -                }
665.1737 -                out.append("{\n");
665.1738 -                cnt[++depth] = 0;
665.1739 -            }
665.1740 -
665.1741 -            @Override
665.1742 -            protected void visitAnnotationEnd(String type, boolean top) throws IOException {
665.1743 -                out.append("\n}\n");
665.1744 -                depth--;
665.1745 -            }
665.1746 -
665.1747 -            @Override
665.1748 -            protected void visitValueStart(String attrName, char type) throws IOException {
665.1749 -                if (cnt[depth]++ > 0) {
665.1750 -                    out.append(",\n");
665.1751 -                }
665.1752 -                cnt[++depth] = 0;
665.1753 -                if (attrName != null) {
665.1754 -                    out.append(attrName).append(" : ");
665.1755 -                }
665.1756 -                if (type == '[') {
665.1757 -                    out.append("[");
665.1758 -                }
665.1759 -            }
665.1760 -
665.1761 -            @Override
665.1762 -            protected void visitValueEnd(String attrName, char type) throws IOException {
665.1763 -                if (type == '[') {
665.1764 -                    out.append("]");
665.1765 -                }
665.1766 -                depth--;
665.1767 -            }
665.1768 -            
665.1769 -            @Override
665.1770 -            protected void visitAttr(String type, String attr, String attrType, String value) 
665.1771 -            throws IOException {
665.1772 -                if (attr == null && value == null) {
665.1773 -                    return;
665.1774 -                }
665.1775 -                out.append(value);
665.1776 -            }
665.1777 -
665.1778 -            @Override
665.1779 -            protected void visitEnumAttr(String type, String attr, String attrType, String value) 
665.1780 -            throws IOException {
665.1781 -                final String slashType = attrType.substring(1, attrType.length() - 1);
665.1782 -                requireReference(slashType);
665.1783 -                
665.1784 -                out.append(accessClass(slashType.replace('/', '_')))
665.1785 -                   .append("(false).constructor.").append(value);
665.1786 -            }
665.1787 -        };
665.1788 -        ap.parse(data, cd);
665.1789 -    }
665.1790 -
665.1791 -    private static String outputArg(Appendable out, String[] args, int indx) throws IOException {
665.1792 -        final String name = args[indx];
665.1793 -        if (name == null) {
665.1794 -            return "";
665.1795 -        }
665.1796 -        if (name.contains(",")) {
665.1797 -            throw new IOException("Wrong parameter with ',': " + name);
665.1798 -        }
665.1799 -        out.append(name);
665.1800 -        return ",";
665.1801 -    }
665.1802 -
665.1803 -    private static void emit(final Appendable out,
665.1804 -                             final String format,
665.1805 -                             final CharSequence... params) throws IOException {
665.1806 -        final int length = format.length();
665.1807 -
665.1808 -        int processed = 0;
665.1809 -        int paramOffset = format.indexOf('@');
665.1810 -        while ((paramOffset != -1) && (paramOffset < (length - 1))) {
665.1811 -            final char paramChar = format.charAt(paramOffset + 1);
665.1812 -            if ((paramChar >= '1') && (paramChar <= '9')) {
665.1813 -                final int paramIndex = paramChar - '0' - 1;
665.1814 -
665.1815 -                out.append(format, processed, paramOffset);
665.1816 -                out.append(params[paramIndex]);
665.1817 -
665.1818 -                ++paramOffset;
665.1819 -                processed = paramOffset + 1;
665.1820 -            }
665.1821 -
665.1822 -            paramOffset = format.indexOf('@', paramOffset + 1);
665.1823 -        }
665.1824 -
665.1825 -        out.append(format, processed, length);
665.1826 -    }
665.1827 -
665.1828 -    private void generateCatch(TrapData[] traps) throws IOException {
665.1829 -        out.append("} catch (e) {\n");
665.1830 -        int finallyPC = -1;
665.1831 -        for (TrapData e : traps) {
665.1832 -            if (e == null) {
665.1833 -                break;
665.1834 -            }
665.1835 -            if (e.catch_cpx != 0) { //not finally
665.1836 -                final String classInternalName = jc.getClassName(e.catch_cpx);
665.1837 -                addReference(classInternalName);
665.1838 -                if ("java/lang/Throwable".equals(classInternalName)) {
665.1839 -                    out.append("if (e.$instOf_java_lang_Throwable) {");
665.1840 -                    out.append("  var stA0 = e;");
665.1841 -                    out.append("} else {");
665.1842 -                    out.append("  var stA0 = vm.java_lang_Throwable(true);");
665.1843 -                    out.append("  vm.java_lang_Throwable.cons__VLjava_lang_String_2.call(stA0, e.toString());");
665.1844 -                    out.append("}");
665.1845 -                    out.append("gt=" + e.handler_pc + "; continue;");
665.1846 -                } else {
665.1847 -                    out.append("if (e.$instOf_" + classInternalName.replace('/', '_') + ") {");
665.1848 -                    out.append("gt=" + e.handler_pc + "; var stA0 = e; continue;");
665.1849 -                    out.append("}\n");
665.1850 -                }
665.1851 -            } else {
665.1852 -                finallyPC = e.handler_pc;
665.1853 -            }
665.1854 -        }
665.1855 -        if (finallyPC == -1) {
665.1856 -            out.append("throw e;");
665.1857 -        } else {
665.1858 -            out.append("gt=" + finallyPC + "; var stA0 = e; continue;");
665.1859 -        }
665.1860 -        out.append("\n}");
665.1861 -    }
665.1862 -}
   666.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java	Mon Feb 25 19:00:08 2013 +0100
   666.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   666.3 @@ -1,142 +0,0 @@
   666.4 -/**
   666.5 - * Back 2 Browser Bytecode Translator
   666.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   666.7 - *
   666.8 - * This program is free software: you can redistribute it and/or modify
   666.9 - * it under the terms of the GNU General Public License as published by
  666.10 - * the Free Software Foundation, version 2 of the License.
  666.11 - *
  666.12 - * This program is distributed in the hope that it will be useful,
  666.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  666.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  666.15 - * GNU General Public License for more details.
  666.16 - *
  666.17 - * You should have received a copy of the GNU General Public License
  666.18 - * along with this program. Look for COPYING file in the top folder.
  666.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  666.20 - */
  666.21 -package org.apidesign.vm4brwsr;
  666.22 -
  666.23 -import java.io.IOException;
  666.24 -import org.apidesign.javap.RuntimeConstants;
  666.25 -import org.apidesign.javap.TypeArray;
  666.26 -
  666.27 -final class LocalsMapper {
  666.28 -    private final TypeArray argTypeRecords;
  666.29 -    private final TypeArray localTypeRecords;
  666.30 -
  666.31 -    public LocalsMapper(final TypeArray stackMapArgs) {
  666.32 -        final TypeArray initTypeRecords = new TypeArray();
  666.33 -        updateRecords(initTypeRecords, stackMapArgs);
  666.34 -
  666.35 -        argTypeRecords = initTypeRecords;
  666.36 -        localTypeRecords = new TypeArray(initTypeRecords);
  666.37 -    }
  666.38 -
  666.39 -    public void outputArguments(final Appendable out, boolean isStatic) throws IOException {
  666.40 -        final int argRecordCount = argTypeRecords.getSize();
  666.41 -        int first = isStatic ? 0 : 1;
  666.42 -        if (argRecordCount > first) {
  666.43 -            Variable variable = getVariable(argTypeRecords, first);
  666.44 -            out.append(variable);
  666.45 -
  666.46 -            int i = first + (variable.isCategory2() ? 2 : 1);
  666.47 -            while (i < argRecordCount) {
  666.48 -                variable = getVariable(argTypeRecords, i);
  666.49 -                out.append(", ");
  666.50 -                out.append(variable);
  666.51 -                i += variable.isCategory2() ? 2 : 1;
  666.52 -            }
  666.53 -        }
  666.54 -    }
  666.55 -
  666.56 -    public void syncWithFrameLocals(final TypeArray frameLocals) {
  666.57 -        updateRecords(localTypeRecords, frameLocals);
  666.58 -    }
  666.59 -
  666.60 -    public Variable setI(final int index) {
  666.61 -        return setT(index, VarType.INTEGER);
  666.62 -    }
  666.63 -
  666.64 -    public Variable setL(final int index) {
  666.65 -        return setT(index, VarType.LONG);
  666.66 -    }
  666.67 -
  666.68 -    public Variable setF(final int index) {
  666.69 -        return setT(index, VarType.FLOAT);
  666.70 -    }
  666.71 -
  666.72 -    public Variable setD(final int index) {
  666.73 -        return setT(index, VarType.DOUBLE);
  666.74 -    }
  666.75 -
  666.76 -    public Variable setA(final int index) {
  666.77 -        return setT(index, VarType.REFERENCE);
  666.78 -    }
  666.79 -
  666.80 -    public Variable setT(final int index, final int type) {
  666.81 -        updateRecord(localTypeRecords, index, type);
  666.82 -        return Variable.getLocalVariable(type, index);
  666.83 -    }
  666.84 -
  666.85 -    public Variable getI(final int index) {
  666.86 -        return getT(index, VarType.INTEGER);
  666.87 -    }
  666.88 -
  666.89 -    public Variable getL(final int index) {
  666.90 -        return getT(index, VarType.LONG);
  666.91 -    }
  666.92 -
  666.93 -    public Variable getF(final int index) {
  666.94 -        return getT(index, VarType.FLOAT);
  666.95 -    }
  666.96 -
  666.97 -    public Variable getD(final int index) {
  666.98 -        return getT(index, VarType.DOUBLE);
  666.99 -    }
 666.100 -
 666.101 -    public Variable getA(final int index) {
 666.102 -        return getT(index, VarType.REFERENCE);
 666.103 -    }
 666.104 -
 666.105 -    public Variable getT(final int index, final int type) {
 666.106 -        final int oldRecordValue = localTypeRecords.get(index);
 666.107 -        if ((oldRecordValue & 0xff) != type) {
 666.108 -            throw new IllegalStateException("Type mismatch");
 666.109 -        }
 666.110 -
 666.111 -        return Variable.getLocalVariable(type, index);
 666.112 -    }
 666.113 -
 666.114 -    private static void updateRecords(final TypeArray typeRecords,
 666.115 -                                      final TypeArray stackMapTypes) {
 666.116 -        final int srcSize = stackMapTypes.getSize();
 666.117 -        for (int i = 0, dstIndex = 0; i < srcSize; ++i) {
 666.118 -            final int smType = stackMapTypes.get(i);
 666.119 -            if (smType == RuntimeConstants.ITEM_Bogus) {
 666.120 -                ++dstIndex;
 666.121 -                continue;
 666.122 -            }
 666.123 -            final int varType = VarType.fromStackMapType(smType);
 666.124 -            updateRecord(typeRecords, dstIndex, varType);
 666.125 -            dstIndex += VarType.isCategory2(varType) ? 2 : 1;
 666.126 -        }
 666.127 -    }
 666.128 -
 666.129 -    private static void updateRecord(final TypeArray typeRecords,
 666.130 -                                     final int index, final int type) {
 666.131 -        if (typeRecords.getSize() < (index + 1)) {
 666.132 -            typeRecords.setSize(index + 1);
 666.133 -        }
 666.134 -
 666.135 -        final int oldRecordValue = typeRecords.get(index);
 666.136 -        final int usedTypesMask =
 666.137 -                (oldRecordValue >> 8) | (1 << type);
 666.138 -        typeRecords.set(index, (usedTypesMask << 8) | type);
 666.139 -    }
 666.140 -
 666.141 -    private static Variable getVariable(final TypeArray typeRecords,
 666.142 -                                        final int index) {
 666.143 -        return Variable.getLocalVariable(typeRecords.get(index) & 0xff, index);
 666.144 -    }
 666.145 -}
   667.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Main.java	Mon Feb 25 19:00:08 2013 +0100
   667.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   667.3 @@ -1,50 +0,0 @@
   667.4 -/**
   667.5 - * Back 2 Browser Bytecode Translator
   667.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   667.7 - *
   667.8 - * This program is free software: you can redistribute it and/or modify
   667.9 - * it under the terms of the GNU General Public License as published by
  667.10 - * the Free Software Foundation, version 2 of the License.
  667.11 - *
  667.12 - * This program is distributed in the hope that it will be useful,
  667.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  667.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  667.15 - * GNU General Public License for more details.
  667.16 - *
  667.17 - * You should have received a copy of the GNU General Public License
  667.18 - * along with this program. Look for COPYING file in the top folder.
  667.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  667.20 - */
  667.21 -package org.apidesign.vm4brwsr;
  667.22 -
  667.23 -import java.io.BufferedWriter;
  667.24 -import java.io.FileWriter;
  667.25 -import java.io.IOException;
  667.26 -import java.io.Writer;
  667.27 -
  667.28 -/** Generator of JavaScript from bytecode of classes on classpath of the VM
  667.29 - * with a Main method.
  667.30 - *
  667.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  667.32 - */
  667.33 -final class Main {
  667.34 -    private Main() {}
  667.35 -    
  667.36 -    public static void main(String... args) throws IOException {
  667.37 -        if (args.length < 2) {
  667.38 -            System.err.println("Bck2Brwsr Translator from Java(tm) to JavaScript, (c) Jaroslav Tulach 2012");
  667.39 -            System.err.println("Usage: java -cp ... -jar ... <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
  667.40 -            return;
  667.41 -        }
  667.42 -        
  667.43 -        Writer w = new BufferedWriter(new FileWriter(args[0]));
  667.44 -        StringArray classes = StringArray.asList(args);
  667.45 -        classes.delete(0);
  667.46 -        try {
  667.47 -            Bck2Brwsr.generate(w, Main.class.getClassLoader(),
  667.48 -                               classes.toArray());
  667.49 -        } finally {
  667.50 -            w.close();
  667.51 -        }
  667.52 -    }
  667.53 -}
   668.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ParseMan.java	Mon Feb 25 19:00:08 2013 +0100
   668.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   668.3 @@ -1,57 +0,0 @@
   668.4 -/**
   668.5 - * Back 2 Browser Bytecode Translator
   668.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   668.7 - *
   668.8 - * This program is free software: you can redistribute it and/or modify
   668.9 - * it under the terms of the GNU General Public License as published by
  668.10 - * the Free Software Foundation, version 2 of the License.
  668.11 - *
  668.12 - * This program is distributed in the hope that it will be useful,
  668.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  668.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  668.15 - * GNU General Public License for more details.
  668.16 - *
  668.17 - * You should have received a copy of the GNU General Public License
  668.18 - * along with this program. Look for COPYING file in the top folder.
  668.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  668.20 - */
  668.21 -package org.apidesign.vm4brwsr;
  668.22 -
  668.23 -import java.io.IOException;
  668.24 -import java.io.InputStream;
  668.25 -import org.apidesign.bck2brwsr.emul.lang.ManifestInputStream;
  668.26 -
  668.27 -/**
  668.28 - *
  668.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  668.30 - */
  668.31 -final class ParseMan extends ManifestInputStream {
  668.32 -    private String cp;
  668.33 -    private String mc;
  668.34 -
  668.35 -    public ParseMan(InputStream is) throws IOException {
  668.36 -        super(is);
  668.37 -        readAttributes(new byte[512]);
  668.38 -    }
  668.39 -
  668.40 -    @Override
  668.41 -    protected String putValue(String key, String value) {
  668.42 -        if ("Class-Path".equals(key)) {
  668.43 -            cp = value;
  668.44 -        }
  668.45 -        if ("Main-Class".equals(key)) {
  668.46 -            mc = value;
  668.47 -        }
  668.48 -        return null;
  668.49 -    }
  668.50 -    
  668.51 -    String getMainClass() {
  668.52 -        return mc;
  668.53 -    }
  668.54 -
  668.55 -    @Override
  668.56 -    public String toString() {
  668.57 -        return cp;
  668.58 -    }
  668.59 -    
  668.60 -}
   669.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/StackMapper.java	Mon Feb 25 19:00:08 2013 +0100
   669.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   669.3 @@ -1,194 +0,0 @@
   669.4 -/**
   669.5 - * Back 2 Browser Bytecode Translator
   669.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   669.7 - *
   669.8 - * This program is free software: you can redistribute it and/or modify
   669.9 - * it under the terms of the GNU General Public License as published by
  669.10 - * the Free Software Foundation, version 2 of the License.
  669.11 - *
  669.12 - * This program is distributed in the hope that it will be useful,
  669.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  669.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  669.15 - * GNU General Public License for more details.
  669.16 - *
  669.17 - * You should have received a copy of the GNU General Public License
  669.18 - * along with this program. Look for COPYING file in the top folder.
  669.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  669.20 - */
  669.21 -package org.apidesign.vm4brwsr;
  669.22 -
  669.23 -import org.apidesign.javap.TypeArray;
  669.24 -
  669.25 -final class StackMapper {
  669.26 -    private final TypeArray stackTypeIndexPairs;
  669.27 -    private int[] typeCounters;
  669.28 -    private int[] typeMaxCounters;
  669.29 -
  669.30 -    public StackMapper() {
  669.31 -        stackTypeIndexPairs = new TypeArray();
  669.32 -        typeCounters = new int[VarType.LAST + 1];
  669.33 -        typeMaxCounters = new int[VarType.LAST + 1];
  669.34 -    }
  669.35 -
  669.36 -    public void clear() {
  669.37 -        for (int type = 0; type <= VarType.LAST; ++type) {
  669.38 -            typeCounters[type] = 0;
  669.39 -        }
  669.40 -        stackTypeIndexPairs.clear();
  669.41 -    }
  669.42 -
  669.43 -    public void syncWithFrameStack(final TypeArray frameStack) {
  669.44 -        clear();
  669.45 -
  669.46 -        final int size = frameStack.getSize();
  669.47 -        for (int i = 0; i < size; ++i) {
  669.48 -            pushTypeImpl(VarType.fromStackMapType(frameStack.get(i)));
  669.49 -        }
  669.50 -    }
  669.51 -
  669.52 -    public Variable pushI() {
  669.53 -        return pushT(VarType.INTEGER);
  669.54 -    }
  669.55 -
  669.56 -    public Variable pushL() {
  669.57 -        return pushT(VarType.LONG);
  669.58 -    }
  669.59 -
  669.60 -    public Variable pushF() {
  669.61 -        return pushT(VarType.FLOAT);
  669.62 -    }
  669.63 -
  669.64 -    public Variable pushD() {
  669.65 -        return pushT(VarType.DOUBLE);
  669.66 -    }
  669.67 -
  669.68 -    public Variable pushA() {
  669.69 -        return pushT(VarType.REFERENCE);
  669.70 -    }
  669.71 -
  669.72 -    public Variable pushT(final int type) {
  669.73 -        return getVariable(pushTypeImpl(type));
  669.74 -    }
  669.75 -
  669.76 -    public Variable popI() {
  669.77 -        return popT(VarType.INTEGER);
  669.78 -    }
  669.79 -
  669.80 -    public Variable popL() {
  669.81 -        return popT(VarType.LONG);
  669.82 -    }
  669.83 -
  669.84 -    public Variable popF() {
  669.85 -        return popT(VarType.FLOAT);
  669.86 -    }
  669.87 -
  669.88 -    public Variable popD() {
  669.89 -        return popT(VarType.DOUBLE);
  669.90 -    }
  669.91 -
  669.92 -    public Variable popA() {
  669.93 -        return popT(VarType.REFERENCE);
  669.94 -    }
  669.95 -
  669.96 -    public Variable popT(final int type) {
  669.97 -        final Variable variable = getT(0, type);
  669.98 -        popImpl(1);
  669.99 -        return variable;
 669.100 -    }
 669.101 -
 669.102 -    public Variable pop() {
 669.103 -        final Variable variable = get(0);
 669.104 -        popImpl(1);
 669.105 -        return variable;
 669.106 -    }
 669.107 -
 669.108 -    public void pop(final int count) {
 669.109 -        final int stackSize = stackTypeIndexPairs.getSize();
 669.110 -        if (count > stackSize) {
 669.111 -            throw new IllegalStateException("Stack underflow");
 669.112 -        }
 669.113 -        popImpl(count);
 669.114 -    }
 669.115 -
 669.116 -    public Variable getI(final int indexFromTop) {
 669.117 -        return getT(indexFromTop, VarType.INTEGER);
 669.118 -    }
 669.119 -
 669.120 -    public Variable getL(final int indexFromTop) {
 669.121 -        return getT(indexFromTop, VarType.LONG);
 669.122 -    }
 669.123 -
 669.124 -    public Variable getF(final int indexFromTop) {
 669.125 -        return getT(indexFromTop, VarType.FLOAT);
 669.126 -    }
 669.127 -
 669.128 -    public Variable getD(final int indexFromTop) {
 669.129 -        return getT(indexFromTop, VarType.DOUBLE);
 669.130 -    }
 669.131 -
 669.132 -    public Variable getA(final int indexFromTop) {
 669.133 -        return getT(indexFromTop, VarType.REFERENCE);
 669.134 -    }
 669.135 -
 669.136 -    public Variable getT(final int indexFromTop, final int type) {
 669.137 -        final int stackSize = stackTypeIndexPairs.getSize();
 669.138 -        if (indexFromTop >= stackSize) {
 669.139 -            throw new IllegalStateException("Stack underflow");
 669.140 -        }
 669.141 -        final int stackValue =
 669.142 -                stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
 669.143 -        if ((stackValue & 0xff) != type) {
 669.144 -            throw new IllegalStateException("Type mismatch");
 669.145 -        }
 669.146 -
 669.147 -        return getVariable(stackValue);
 669.148 -    }
 669.149 -
 669.150 -    public Variable get(final int indexFromTop) {
 669.151 -        final int stackSize = stackTypeIndexPairs.getSize();
 669.152 -        if (indexFromTop >= stackSize) {
 669.153 -            throw new IllegalStateException("Stack underflow");
 669.154 -        }
 669.155 -        final int stackValue =
 669.156 -                stackTypeIndexPairs.get(stackSize - indexFromTop - 1);
 669.157 -
 669.158 -        return getVariable(stackValue);
 669.159 -    }
 669.160 -
 669.161 -    private int pushTypeImpl(final int type) {
 669.162 -        final int count = typeCounters[type];
 669.163 -        final int value = (count << 8) | (type & 0xff);
 669.164 -        incCounter(type);
 669.165 -        stackTypeIndexPairs.add(value);
 669.166 -
 669.167 -        return value;
 669.168 -    }
 669.169 -
 669.170 -    private void popImpl(final int count) {
 669.171 -        final int stackSize = stackTypeIndexPairs.getSize();
 669.172 -        for (int i = stackSize - count; i < stackSize; ++i) {
 669.173 -            final int value = stackTypeIndexPairs.get(i);
 669.174 -            decCounter(value & 0xff);
 669.175 -        }
 669.176 -
 669.177 -        stackTypeIndexPairs.setSize(stackSize - count);
 669.178 -    }
 669.179 -
 669.180 -    private void incCounter(final int type) {
 669.181 -        final int newValue = ++typeCounters[type];
 669.182 -        if (typeMaxCounters[type] < newValue) {
 669.183 -            typeMaxCounters[type] = newValue;
 669.184 -        }
 669.185 -    }
 669.186 -
 669.187 -    private void decCounter(final int type) {
 669.188 -        --typeCounters[type];
 669.189 -    }
 669.190 -
 669.191 -    public Variable getVariable(final int typeAndIndex) {
 669.192 -        final int type = typeAndIndex & 0xff;
 669.193 -        final int index = typeAndIndex >> 8;
 669.194 -
 669.195 -        return Variable.getStackVariable(type, index);
 669.196 -    }
 669.197 -}
   670.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java	Mon Feb 25 19:00:08 2013 +0100
   670.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   670.3 @@ -1,97 +0,0 @@
   670.4 -/**
   670.5 - * Back 2 Browser Bytecode Translator
   670.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   670.7 - *
   670.8 - * This program is free software: you can redistribute it and/or modify
   670.9 - * it under the terms of the GNU General Public License as published by
  670.10 - * the Free Software Foundation, version 2 of the License.
  670.11 - *
  670.12 - * This program is distributed in the hope that it will be useful,
  670.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  670.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  670.15 - * GNU General Public License for more details.
  670.16 - *
  670.17 - * You should have received a copy of the GNU General Public License
  670.18 - * along with this program. Look for COPYING file in the top folder.
  670.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  670.20 - */
  670.21 -package org.apidesign.vm4brwsr;
  670.22 -
  670.23 -/**
  670.24 - *
  670.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  670.26 - */
  670.27 -class StringArray {
  670.28 -    private String[] arr;
  670.29 -
  670.30 -    public StringArray() {
  670.31 -    }
  670.32 -
  670.33 -    private StringArray(String[] arr) {
  670.34 -        this.arr = arr;
  670.35 -    }
  670.36 -    
  670.37 -    public void add(String s) {
  670.38 -        if (arr == null) {
  670.39 -            arr = new String[1];
  670.40 -        } else {
  670.41 -            String[] tmp = new String[arr.length + 1];
  670.42 -            for (int i = 0; i < arr.length; i++) {
  670.43 -                tmp[i] = arr[i];
  670.44 -            }
  670.45 -            arr = tmp;
  670.46 -        }
  670.47 -        arr[arr.length - 1] = s;
  670.48 -    }
  670.49 -    
  670.50 -    public String[] toArray() {
  670.51 -        return arr == null ? new String[0] : arr;
  670.52 -    }
  670.53 -    
  670.54 -    static StringArray asList(String... names) {
  670.55 -        return new StringArray(names);
  670.56 -    }
  670.57 -
  670.58 -    void reverse() {
  670.59 -        for (int i = 0, j = arr.length; i < j; i++) {
  670.60 -            String s = arr[i];
  670.61 -            arr[i] = arr[--j];
  670.62 -            arr[j] = s;
  670.63 -        }
  670.64 -    }
  670.65 -
  670.66 -    boolean contains(String n) {
  670.67 -        if (arr == null) {
  670.68 -            return false;
  670.69 -        }
  670.70 -        for (int i = 0; i < arr.length; i++) {
  670.71 -            if (n.equals(arr[i])) {
  670.72 -                return true;
  670.73 -            }
  670.74 -        }
  670.75 -        return false;
  670.76 -    }
  670.77 -
  670.78 -    void delete(int indx) {
  670.79 -        if (arr == null || indx < 0 || indx >= arr.length) {
  670.80 -            return;
  670.81 -        }
  670.82 -        String[] tmp = new String[arr.length - 1];
  670.83 -        for (int i = 0, j = 0; i < arr.length; i++) {
  670.84 -            if (i != indx) {
  670.85 -                tmp[j++] = arr[i];
  670.86 -            }
  670.87 -        }
  670.88 -        arr = tmp;
  670.89 -    }
  670.90 -
  670.91 -    int indexOf(String ic) {
  670.92 -        for (int i = 0; i < arr.length; i++) {
  670.93 -            if (ic.equals(arr[i])) {
  670.94 -                return i;
  670.95 -            }
  670.96 -        }
  670.97 -        return -1;
  670.98 -    }
  670.99 -    
 670.100 -}
   671.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Mon Feb 25 19:00:08 2013 +0100
   671.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   671.3 @@ -1,230 +0,0 @@
   671.4 -/**
   671.5 - * Back 2 Browser Bytecode Translator
   671.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   671.7 - *
   671.8 - * This program is free software: you can redistribute it and/or modify
   671.9 - * it under the terms of the GNU General Public License as published by
  671.10 - * the Free Software Foundation, version 2 of the License.
  671.11 - *
  671.12 - * This program is distributed in the hope that it will be useful,
  671.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  671.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  671.15 - * GNU General Public License for more details.
  671.16 - *
  671.17 - * You should have received a copy of the GNU General Public License
  671.18 - * along with this program. Look for COPYING file in the top folder.
  671.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  671.20 - */
  671.21 -package org.apidesign.vm4brwsr;
  671.22 -
  671.23 -import java.io.IOException;
  671.24 -import java.io.InputStream;
  671.25 -
  671.26 -/** Generator of JavaScript from bytecode of classes on classpath of the VM.
  671.27 - *
  671.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  671.29 - */
  671.30 -class VM extends ByteCodeToJavaScript {
  671.31 -    public VM(Appendable out) {
  671.32 -        super(out);
  671.33 -    }
  671.34 -    
  671.35 -    static {
  671.36 -        // uses VMLazy to load dynamic classes
  671.37 -        boolean assertsOn = false;
  671.38 -        assert assertsOn = true;
  671.39 -        if (assertsOn) {
  671.40 -            VMLazy.init();
  671.41 -            Zips.init();
  671.42 -        }
  671.43 -    }
  671.44 -
  671.45 -    @Override
  671.46 -    boolean debug(String msg) throws IOException {
  671.47 -        return false;
  671.48 -    }
  671.49 -    
  671.50 -    static void compile(Bck2Brwsr.Resources l, Appendable out, StringArray names) throws IOException {
  671.51 -        new VM(out).doCompile(l, names);
  671.52 -    }
  671.53 -    protected void doCompile(Bck2Brwsr.Resources l, StringArray names) throws IOException {
  671.54 -        out.append("(function VM(global) {var fillInVMSkeleton = function(vm) {");
  671.55 -        StringArray processed = new StringArray();
  671.56 -        StringArray initCode = new StringArray();
  671.57 -        for (String baseClass : names.toArray()) {
  671.58 -            references.add(baseClass);
  671.59 -            for (;;) {
  671.60 -                String name = null;
  671.61 -                for (String n : references.toArray()) {
  671.62 -                    if (processed.contains(n)) {
  671.63 -                        continue;
  671.64 -                    }
  671.65 -                    name = n;
  671.66 -                }
  671.67 -                if (name == null) {
  671.68 -                    break;
  671.69 -                }
  671.70 -                InputStream is = loadClass(l, name);
  671.71 -                if (is == null) {
  671.72 -                    throw new IOException("Can't find class " + name); 
  671.73 -                }
  671.74 -                try {
  671.75 -                    String ic = compile(is);
  671.76 -                    processed.add(name);
  671.77 -                    initCode.add(ic == null ? "" : ic);
  671.78 -                } catch (RuntimeException ex) {
  671.79 -                    if (out instanceof CharSequence) {
  671.80 -                        CharSequence seq = (CharSequence)out;
  671.81 -                        int lastBlock = seq.length();
  671.82 -                        while (lastBlock-- > 0) {
  671.83 -                            if (seq.charAt(lastBlock) == '{') {
  671.84 -                                break;
  671.85 -                            }
  671.86 -                        }
  671.87 -                        throw new IOException("Error while compiling " + name + "\n" 
  671.88 -                            + seq.subSequence(lastBlock + 1, seq.length()), ex
  671.89 -                        );
  671.90 -                    } else {
  671.91 -                        throw new IOException("Error while compiling " + name + "\n" 
  671.92 -                            + out, ex
  671.93 -                        );
  671.94 -                    }
  671.95 -                }
  671.96 -            }
  671.97 -
  671.98 -            for (String resource : scripts.toArray()) {
  671.99 -                while (resource.startsWith("/")) {
 671.100 -                    resource = resource.substring(1);
 671.101 -                }
 671.102 -                InputStream emul = l.get(resource);
 671.103 -                if (emul == null) {
 671.104 -                    throw new IOException("Can't find " + resource);
 671.105 -                }
 671.106 -                readResource(emul, out);
 671.107 -            }
 671.108 -            scripts = new StringArray();
 671.109 -            
 671.110 -            StringArray toInit = StringArray.asList(references.toArray());
 671.111 -            toInit.reverse();
 671.112 -
 671.113 -            for (String ic : toInit.toArray()) {
 671.114 -                int indx = processed.indexOf(ic);
 671.115 -                if (indx >= 0) {
 671.116 -                    out.append(initCode.toArray()[indx]).append("\n");
 671.117 -                    initCode.toArray()[indx] = "";
 671.118 -                }
 671.119 -            }
 671.120 -        }
 671.121 -        out.append(
 671.122 -              "  return vm;\n"
 671.123 -            + "  };\n"
 671.124 -            + "  global.bck2brwsr = function() {\n"
 671.125 -            + "    var args = Array.prototype.slice.apply(arguments);\n"
 671.126 -            + "    var vm = fillInVMSkeleton({});\n"
 671.127 -            + "    var loader = {};\n"
 671.128 -            + "    loader.vm = vm;\n"
 671.129 -            + "    loader.loadClass = function(name) {\n"
 671.130 -            + "      var attr = name.replace__Ljava_lang_String_2CC('.','_');\n"
 671.131 -            + "      var fn = vm[attr];\n"
 671.132 -            + "      if (fn) return fn(false);\n"
 671.133 -            + "      return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 671.134 -            + "        load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
 671.135 -            + "    }\n"
 671.136 -            + "    if (vm.loadClass) {\n"
 671.137 -            + "      throw 'Cannot initialize the bck2brwsr VM twice!';\n"
 671.138 -            + "    }\n"
 671.139 -            + "    vm.loadClass = loader.loadClass;\n"
 671.140 -            + "    vm.loadBytes = function(name) {\n"
 671.141 -            + "      return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 671.142 -            + "        loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
 671.143 -            + "    }\n"
 671.144 -            + "    vm.java_lang_reflect_Array(false);\n"
 671.145 -            + "    vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
 671.146 -            + "      loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, null, args);\n"
 671.147 -            + "    return loader;\n"
 671.148 -            + "  };\n");
 671.149 -        out.append("}(this));");
 671.150 -    }
 671.151 -    private static void readResource(InputStream emul, Appendable out) throws IOException {
 671.152 -        try {
 671.153 -            int state = 0;
 671.154 -            for (;;) {
 671.155 -                int ch = emul.read();
 671.156 -                if (ch == -1) {
 671.157 -                    break;
 671.158 -                }
 671.159 -                if (ch < 0 || ch > 255) {
 671.160 -                    throw new IOException("Invalid char in emulation " + ch);
 671.161 -                }
 671.162 -                switch (state) {
 671.163 -                    case 0: 
 671.164 -                        if (ch == '/') {
 671.165 -                            state = 1;
 671.166 -                        } else {
 671.167 -                            out.append((char)ch);
 671.168 -                        }
 671.169 -                        break;
 671.170 -                    case 1:
 671.171 -                        if (ch == '*') {
 671.172 -                            state = 2;
 671.173 -                        } else {
 671.174 -                            out.append('/').append((char)ch);
 671.175 -                            state = 0;
 671.176 -                        }
 671.177 -                        break;
 671.178 -                    case 2:
 671.179 -                        if (ch == '*') {
 671.180 -                            state = 3;
 671.181 -                        }
 671.182 -                        break;
 671.183 -                    case 3:
 671.184 -                        if (ch == '/') {
 671.185 -                            state = 0;
 671.186 -                        } else {
 671.187 -                            state = 2;
 671.188 -                        }
 671.189 -                        break;
 671.190 -                }
 671.191 -            }
 671.192 -        } finally {
 671.193 -            emul.close();
 671.194 -        }
 671.195 -    }
 671.196 -
 671.197 -    private static InputStream loadClass(Bck2Brwsr.Resources l, String name) throws IOException {
 671.198 -        return l.get(name + ".class"); // NOI18N
 671.199 -    }
 671.200 -
 671.201 -    static String toString(String name) throws IOException {
 671.202 -        StringBuilder sb = new StringBuilder();
 671.203 -//        compile(sb, name);
 671.204 -        return sb.toString().toString();
 671.205 -    }
 671.206 -
 671.207 -    private StringArray scripts = new StringArray();
 671.208 -    private StringArray references = new StringArray();
 671.209 -    
 671.210 -    @Override
 671.211 -    protected boolean requireReference(String cn) {
 671.212 -        if (references.contains(cn)) {
 671.213 -            return false;
 671.214 -        }
 671.215 -        references.add(cn);
 671.216 -        return true;
 671.217 -    }
 671.218 -
 671.219 -    @Override
 671.220 -    protected void requireScript(String resourcePath) {
 671.221 -        scripts.add(resourcePath);
 671.222 -    }
 671.223 -
 671.224 -    @Override
 671.225 -    String assignClass(String className) {
 671.226 -        return "vm." + className + " = ";
 671.227 -    }
 671.228 -    
 671.229 -    @Override
 671.230 -    String accessClass(String className) {
 671.231 -        return "vm." + className;
 671.232 -    }
 671.233 -}
   672.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java	Mon Feb 25 19:00:08 2013 +0100
   672.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   672.3 @@ -1,155 +0,0 @@
   672.4 -/**
   672.5 - * Back 2 Browser Bytecode Translator
   672.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   672.7 - *
   672.8 - * This program is free software: you can redistribute it and/or modify
   672.9 - * it under the terms of the GNU General Public License as published by
  672.10 - * the Free Software Foundation, version 2 of the License.
  672.11 - *
  672.12 - * This program is distributed in the hope that it will be useful,
  672.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  672.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  672.15 - * GNU General Public License for more details.
  672.16 - *
  672.17 - * You should have received a copy of the GNU General Public License
  672.18 - * along with this program. Look for COPYING file in the top folder.
  672.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  672.20 - */
  672.21 -package org.apidesign.vm4brwsr;
  672.22 -
  672.23 -import java.io.ByteArrayInputStream;
  672.24 -import java.io.IOException;
  672.25 -import java.io.InputStream;
  672.26 -import java.lang.reflect.Array;
  672.27 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  672.28 -
  672.29 -/**
  672.30 - *
  672.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  672.32 - */
  672.33 -final class VMLazy {
  672.34 -    private final Object loader;
  672.35 -    private final Object[] args;
  672.36 -    
  672.37 -    private VMLazy(Object loader, Object[] args) {
  672.38 -        this.loader = loader;
  672.39 -        this.args = args;
  672.40 -    }
  672.41 -    
  672.42 -    static void init() {
  672.43 -    }
  672.44 -    
  672.45 -    static Object load(Object loader, String name, Object[] arguments) 
  672.46 -    throws IOException, ClassNotFoundException {
  672.47 -        return new VMLazy(loader, arguments).load(name, false);
  672.48 -    }
  672.49 -    
  672.50 -    static byte[] loadBytes(Object loader, String name, Object[] arguments) throws Exception {
  672.51 -        return Zips.loadFromCp(arguments, name);
  672.52 -    }
  672.53 -    
  672.54 -    private Object load(String name, boolean instance)
  672.55 -    throws IOException, ClassNotFoundException {
  672.56 -        String res = name.replace('.', '/') + ".class";
  672.57 -        byte[] arr = Zips.loadFromCp(args, res);
  672.58 -        if (arr == null) {
  672.59 -            throw new ClassNotFoundException(name);
  672.60 -        }
  672.61 -//        beingDefined(loader, name);
  672.62 -        StringBuilder out = new StringBuilder();
  672.63 -        out.append("var loader = arguments[0];\n");
  672.64 -        out.append("var vm = loader.vm;\n");
  672.65 -        int prelude = out.length();
  672.66 -        String initCode = new Gen(this, out).compile(new ByteArrayInputStream(arr));
  672.67 -        String code = out.toString().toString();
  672.68 -//        dump("Loading " + name);
  672.69 -        dump(code);
  672.70 -        String under = name.replace('.', '_');
  672.71 -        Object fn = applyCode(loader, under, code, instance);
  672.72 -        
  672.73 -        if (!initCode.isEmpty()) {
  672.74 -            out.setLength(prelude);
  672.75 -            out.append(initCode);
  672.76 -            code = out.toString().toString();
  672.77 -            dump(code);
  672.78 -            applyCode(loader, null, code, false);
  672.79 -        }            
  672.80 -        
  672.81 -        return fn;
  672.82 -    }
  672.83 -
  672.84 -//    @JavaScriptBody(args = "s", body = "java.lang.System.out.println(s.toString());")
  672.85 -    static void dump(String s) {
  672.86 -    }
  672.87 -
  672.88 -/* possibly not needed:
  672.89 -    @JavaScriptBody(args = {"loader", "n" }, body =
  672.90 -        "var cls = n.replace__Ljava_lang_String_2CC(n, '.','_').toString();" +
  672.91 -        "loader.vm[cls] = true;\n"
  672.92 -    )
  672.93 -    private static native void beingDefined(Object loader, String name);
  672.94 -*/
  672.95 -    
  672.96 -
  672.97 -    @JavaScriptBody(args = {"loader", "name", "script", "instance" }, body =
  672.98 -        "try {\n" +
  672.99 -        "  new Function(script)(loader, name);\n" +
 672.100 -        "} catch (ex) {\n" +
 672.101 -        "  throw 'Cannot compile ' + name + ' ' + ex + ' line: ' + ex.lineNumber + ' script:\\n' + script;\n" +
 672.102 -        "}\n" +
 672.103 -        "return name != null ? vm[name](instance) : null;\n"
 672.104 -    )
 672.105 -    private static native Object applyCode(Object loader, String name, String script, boolean instance);
 672.106 -    
 672.107 -    
 672.108 -    private static final class Gen extends ByteCodeToJavaScript {
 672.109 -        private final VMLazy lazy;
 672.110 -
 672.111 -        public Gen(VMLazy vm, Appendable out) {
 672.112 -            super(out);
 672.113 -            this.lazy = vm;
 672.114 -        }
 672.115 -        
 672.116 -        @JavaScriptBody(args = {"n"},
 672.117 -        body =
 672.118 -        "var cls = n.replace__Ljava_lang_String_2CC('/','_').toString();"
 672.119 -        + "\nvar dot = n.replace__Ljava_lang_String_2CC('/','.').toString();"
 672.120 -        + "\nvar lazy = this._lazy();"
 672.121 -        + "\nvar loader = lazy._loader();"
 672.122 -        + "\nvar vm = loader.vm;"
 672.123 -        + "\nif (vm[cls]) return false;"
 672.124 -        + "\nvm[cls] = function() {"
 672.125 -        + "\n  var instance = arguments.length == 0 || arguments[0] === true;"
 672.126 -        + "\n  return lazy.load__Ljava_lang_Object_2Ljava_lang_String_2Z(dot, instance);"
 672.127 -        + "\n};"
 672.128 -        + "\nreturn true;")
 672.129 -        @Override
 672.130 -        protected boolean requireReference(String internalClassName) {
 672.131 -            throw new UnsupportedOperationException();
 672.132 -        }
 672.133 -
 672.134 -        @Override
 672.135 -        protected void requireScript(String resourcePath) throws IOException {
 672.136 -            InputStream is = getClass().getResourceAsStream(resourcePath);
 672.137 -            StringBuilder sb = new StringBuilder();
 672.138 -            for (;;) {
 672.139 -                int ch = is.read();
 672.140 -                if (ch == -1) {
 672.141 -                    break;
 672.142 -                }
 672.143 -                sb.append((char)ch);
 672.144 -            }
 672.145 -            applyCode(lazy.loader, null, sb.toString(), false);
 672.146 -        }
 672.147 -
 672.148 -        @Override
 672.149 -        String assignClass(String className) {
 672.150 -            return "vm[arguments[1]]=";
 672.151 -        }
 672.152 -
 672.153 -        @Override
 672.154 -        String accessClass(String classOperation) {
 672.155 -            return "vm." + classOperation;
 672.156 -        }
 672.157 -    }
 672.158 -}
   673.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java	Mon Feb 25 19:00:08 2013 +0100
   673.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   673.3 @@ -1,110 +0,0 @@
   673.4 -/**
   673.5 - * Back 2 Browser Bytecode Translator
   673.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   673.7 - *
   673.8 - * This program is free software: you can redistribute it and/or modify
   673.9 - * it under the terms of the GNU General Public License as published by
  673.10 - * the Free Software Foundation, version 2 of the License.
  673.11 - *
  673.12 - * This program is distributed in the hope that it will be useful,
  673.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  673.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  673.15 - * GNU General Public License for more details.
  673.16 - *
  673.17 - * You should have received a copy of the GNU General Public License
  673.18 - * along with this program. Look for COPYING file in the top folder.
  673.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  673.20 - */
  673.21 -package org.apidesign.vm4brwsr;
  673.22 -
  673.23 -import org.apidesign.javap.RuntimeConstants;
  673.24 -
  673.25 -final class VarType {
  673.26 -    public static final int INTEGER = 0;
  673.27 -    public static final int LONG = 1;
  673.28 -    public static final int FLOAT = 2;
  673.29 -    public static final int DOUBLE = 3;
  673.30 -    public static final int REFERENCE = 4;
  673.31 -
  673.32 -    public static final int LAST = REFERENCE;
  673.33 -
  673.34 -    private VarType() {
  673.35 -    }
  673.36 -
  673.37 -    public static boolean isCategory2(final int varType) {
  673.38 -        return (varType == LONG) || (varType == DOUBLE);
  673.39 -    }
  673.40 -
  673.41 -    public static int fromStackMapType(final int smType) {
  673.42 -        switch (smType & 0xff) {
  673.43 -            case RuntimeConstants.ITEM_Integer:
  673.44 -                return VarType.INTEGER;
  673.45 -            case RuntimeConstants.ITEM_Float:
  673.46 -                return VarType.FLOAT;
  673.47 -            case RuntimeConstants.ITEM_Double:
  673.48 -                return VarType.DOUBLE;
  673.49 -            case RuntimeConstants.ITEM_Long:
  673.50 -                return VarType.LONG;
  673.51 -            case RuntimeConstants.ITEM_Null:
  673.52 -            case RuntimeConstants.ITEM_InitObject:
  673.53 -            case RuntimeConstants.ITEM_Object:
  673.54 -            case RuntimeConstants.ITEM_NewObject:
  673.55 -                return VarType.REFERENCE;
  673.56 -
  673.57 -            case RuntimeConstants.ITEM_Bogus:
  673.58 -                /* unclear how to handle for now */
  673.59 -            default:
  673.60 -                throw new IllegalStateException("Unhandled stack map type");
  673.61 -        }
  673.62 -    }
  673.63 -
  673.64 -    public static int fromConstantType(final byte constantTag) {
  673.65 -        switch (constantTag) {
  673.66 -            case RuntimeConstants.CONSTANT_INTEGER:
  673.67 -                return VarType.INTEGER;
  673.68 -            case RuntimeConstants.CONSTANT_FLOAT:
  673.69 -                return VarType.FLOAT;
  673.70 -            case RuntimeConstants.CONSTANT_LONG:
  673.71 -                return VarType.LONG;
  673.72 -            case RuntimeConstants.CONSTANT_DOUBLE:
  673.73 -                return VarType.DOUBLE;
  673.74 -
  673.75 -            case RuntimeConstants.CONSTANT_CLASS:
  673.76 -            case RuntimeConstants.CONSTANT_UTF8:
  673.77 -            case RuntimeConstants.CONSTANT_UNICODE:
  673.78 -            case RuntimeConstants.CONSTANT_STRING:
  673.79 -                return VarType.REFERENCE;
  673.80 -
  673.81 -            case RuntimeConstants.CONSTANT_FIELD:
  673.82 -            case RuntimeConstants.CONSTANT_METHOD:
  673.83 -            case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
  673.84 -            case RuntimeConstants.CONSTANT_NAMEANDTYPE:
  673.85 -                /* unclear how to handle for now */
  673.86 -            default:
  673.87 -                throw new IllegalStateException("Unhandled constant tag");
  673.88 -        }
  673.89 -    }
  673.90 -
  673.91 -    public static int fromFieldType(final char fieldType) {
  673.92 -        switch (fieldType) {
  673.93 -            case 'B':
  673.94 -            case 'C':
  673.95 -            case 'S':
  673.96 -            case 'Z':
  673.97 -            case 'I':
  673.98 -                return VarType.INTEGER;
  673.99 -            case 'J':
 673.100 -                return VarType.LONG;
 673.101 -            case 'F':
 673.102 -                return VarType.FLOAT;
 673.103 -            case 'D':
 673.104 -                return VarType.DOUBLE;
 673.105 -            case 'L':
 673.106 -            case '[':
 673.107 -                return VarType.REFERENCE;
 673.108 -
 673.109 -            default:
 673.110 -                throw new IllegalStateException("Unhandled field type");
 673.111 -        }
 673.112 -    }
 673.113 -}
   674.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java	Mon Feb 25 19:00:08 2013 +0100
   674.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   674.3 @@ -1,100 +0,0 @@
   674.4 -/**
   674.5 - * Back 2 Browser Bytecode Translator
   674.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   674.7 - *
   674.8 - * This program is free software: you can redistribute it and/or modify
   674.9 - * it under the terms of the GNU General Public License as published by
  674.10 - * the Free Software Foundation, version 2 of the License.
  674.11 - *
  674.12 - * This program is distributed in the hope that it will be useful,
  674.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  674.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  674.15 - * GNU General Public License for more details.
  674.16 - *
  674.17 - * You should have received a copy of the GNU General Public License
  674.18 - * along with this program. Look for COPYING file in the top folder.
  674.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  674.20 - */
  674.21 -package org.apidesign.vm4brwsr;
  674.22 -
  674.23 -final class Variable implements CharSequence {
  674.24 -    private static final String STACK_VAR_PREFIX = "st";
  674.25 -    private static final String LOCAL_VAR_PREFIX = "lc";
  674.26 -
  674.27 -    private final String name;
  674.28 -    private final int type;
  674.29 -    private final int index;
  674.30 -
  674.31 -    private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
  674.32 -
  674.33 -    private Variable(final String prefix, final int type, final int index) {
  674.34 -        this.name = prefix + TYPE_IDS[type] + index;
  674.35 -        this.type = type;
  674.36 -        this.index = index;
  674.37 -    }
  674.38 -
  674.39 -    public static Variable getStackVariable(
  674.40 -            final int type, final int index) {
  674.41 -        // TODO: precreate frequently used variables
  674.42 -        return new Variable(STACK_VAR_PREFIX, type, index);
  674.43 -    }
  674.44 -
  674.45 -    public static Variable getLocalVariable(
  674.46 -            final int type, final int index) {
  674.47 -        // TODO: precreate frequently used variables
  674.48 -        return new Variable(LOCAL_VAR_PREFIX, type, index);
  674.49 -    }
  674.50 -
  674.51 -    public String getName() {
  674.52 -        return name;
  674.53 -    }
  674.54 -
  674.55 -    public int getType() {
  674.56 -        return type;
  674.57 -    }
  674.58 -
  674.59 -    public int getIndex() {
  674.60 -        return index;
  674.61 -    }
  674.62 -
  674.63 -    public boolean isCategory2() {
  674.64 -        return VarType.isCategory2(type);
  674.65 -    }
  674.66 -
  674.67 -    @Override
  674.68 -    public int length() {
  674.69 -        return name.length();
  674.70 -    }
  674.71 -
  674.72 -    @Override
  674.73 -    public char charAt(final int index) {
  674.74 -        return name.charAt(index);
  674.75 -    }
  674.76 -
  674.77 -    @Override
  674.78 -    public CharSequence subSequence(final int start, final int end) {
  674.79 -        return name.subSequence(start, end);
  674.80 -    }
  674.81 -
  674.82 -    @Override
  674.83 -    public int hashCode() {
  674.84 -        return name.hashCode();
  674.85 -    }
  674.86 -
  674.87 -    @Override
  674.88 -    public boolean equals(final Object other) {
  674.89 -        if (this == other) {
  674.90 -            return true;
  674.91 -        }
  674.92 -        if (!(other instanceof Variable)) {
  674.93 -            return false;
  674.94 -        }
  674.95 -
  674.96 -        return name.equals(((Variable) other).name);
  674.97 -    }
  674.98 -
  674.99 -    @Override
 674.100 -    public String toString() {
 674.101 -        return name;
 674.102 -    }
 674.103 -}
   675.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java	Mon Feb 25 19:00:08 2013 +0100
   675.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   675.3 @@ -1,187 +0,0 @@
   675.4 -/**
   675.5 - * Back 2 Browser Bytecode Translator
   675.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   675.7 - *
   675.8 - * This program is free software: you can redistribute it and/or modify
   675.9 - * it under the terms of the GNU General Public License as published by
  675.10 - * the Free Software Foundation, version 2 of the License.
  675.11 - *
  675.12 - * This program is distributed in the hope that it will be useful,
  675.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  675.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  675.15 - * GNU General Public License for more details.
  675.16 - *
  675.17 - * You should have received a copy of the GNU General Public License
  675.18 - * along with this program. Look for COPYING file in the top folder.
  675.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  675.20 - */
  675.21 -package org.apidesign.vm4brwsr;
  675.22 -
  675.23 -import java.io.ByteArrayInputStream;
  675.24 -import java.io.IOException;
  675.25 -import java.io.InputStream;
  675.26 -import java.net.URL;
  675.27 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  675.28 -import org.apidesign.bck2brwsr.emul.zip.FastJar;
  675.29 -
  675.30 -/** Conversion from classpath to load function.
  675.31 - *
  675.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  675.33 - */
  675.34 -final class Zips {
  675.35 -    private final FastJar fj;
  675.36 -
  675.37 -    private Zips(String path, byte[] zipData) throws IOException {
  675.38 -        long bef = timeNow();
  675.39 -        fj = new FastJar(zipData);
  675.40 -        for (FastJar.Entry e : fj.list()) {
  675.41 -            putRes(e.name, e);
  675.42 -        }
  675.43 -        log("Iterating thru " + path + " took " + (timeNow() - bef) + "ms");
  675.44 -    }
  675.45 -    
  675.46 -    public static void init() {
  675.47 -    }
  675.48 -    @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
  675.49 -    private static native int length(Object arr);
  675.50 -    @JavaScriptBody(args = { "arr", "index" }, body = "return arr[index];")
  675.51 -    private static native Object at(Object arr, int index);
  675.52 -    @JavaScriptBody(args = { "arr", "index", "value" }, body = "arr[index] = value; return value;")
  675.53 -    private static native Object set(Object arr, int index, Object value);
  675.54 -    
  675.55 -    public static byte[] loadFromCp(Object classpath, String res) 
  675.56 -    throws IOException, ClassNotFoundException {
  675.57 -        for (int i = 0; i < length(classpath); i++) {
  675.58 -            Object c = at(classpath, i);
  675.59 -            if (c instanceof String) {
  675.60 -                try {
  675.61 -                    String url = (String)c;
  675.62 -                    final Zips z = toZip(url);
  675.63 -                    c = set(classpath, i, z);
  675.64 -                    final byte[] man = z.findRes("META-INF/MANIFEST.MF");
  675.65 -                    if (man != null) {
  675.66 -                        String mainClass = processClassPathAttr(man, url, classpath);
  675.67 -//                        if (mainClass != null) {
  675.68 -//                            Class.forName(mainClass);
  675.69 -//                        }
  675.70 -                    }
  675.71 -                } catch (IOException ex) {
  675.72 -                    set(classpath, i, ex);
  675.73 -                    log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
  675.74 -                }
  675.75 -            }
  675.76 -            if (res != null) {
  675.77 -                byte[] checkRes;
  675.78 -                if (c instanceof Zips) {
  675.79 -                    checkRes = ((Zips)c).findRes(res);
  675.80 -                } else {
  675.81 -                    checkRes = callFunction(c, res);
  675.82 -                }
  675.83 -                if (checkRes != null) {
  675.84 -                    return checkRes;
  675.85 -                }
  675.86 -            }
  675.87 -        }
  675.88 -        return null;
  675.89 -    }
  675.90 -    
  675.91 -    @JavaScriptBody(args = { "fn", "res" }, body = 
  675.92 -        "if (typeof fn === 'function') return fn(res);\n"
  675.93 -      + "return null;"
  675.94 -    )
  675.95 -    private static native byte[] callFunction(Object fn, String res);
  675.96 -    
  675.97 -    @JavaScriptBody(args = { "msg" }, body = "console.log(msg.toString());")
  675.98 -    private static native void log(String msg);
  675.99 -
 675.100 -    private byte[] findRes(String res) throws IOException {
 675.101 -        Object arr = findResImpl(res);
 675.102 -        if (arr instanceof FastJar.Entry) {
 675.103 -            long bef = timeNow();
 675.104 -            InputStream zip = fj.getInputStream((FastJar.Entry)arr);
 675.105 -            arr = readFully(new byte[512], zip);
 675.106 -            putRes(res, arr);
 675.107 -            log("Reading " + res + " took " + (timeNow() - bef) + "ms");
 675.108 -        }
 675.109 -        return (byte[]) arr;
 675.110 -    }
 675.111 -
 675.112 -    @JavaScriptBody(args = { "res" }, body = "var r = this[res]; return r ? r : null;")
 675.113 -    private native Object findResImpl(String res);
 675.114 -
 675.115 -    @JavaScriptBody(args = { "res", "arr" }, body = "this[res] = arr;")
 675.116 -    private native void putRes(String res, Object arr);
 675.117 -    
 675.118 -    private static Zips toZip(String path) throws IOException {
 675.119 -        URL u = new URL(path);
 675.120 -        byte[] zipData = (byte[]) u.getContent(new Class[] { byte[].class });
 675.121 -        return new Zips(path, zipData);
 675.122 -    }
 675.123 -
 675.124 -    private static String processClassPathAttr(final byte[] man, String url, Object classpath) throws IOException {
 675.125 -        try (ParseMan is = new ParseMan(new ByteArrayInputStream(man))) {
 675.126 -            String cp = is.toString();
 675.127 -            if (cp != null) {
 675.128 -                cp = cp.trim();
 675.129 -                for (int p = 0; p < cp.length();) {
 675.130 -                    int n = cp.indexOf(' ', p);
 675.131 -                    if (n == -1) {
 675.132 -                        n = cp.length();
 675.133 -                    }
 675.134 -                    String el = cp.substring(p, n);
 675.135 -                    URL u = new URL(new URL(url), el);
 675.136 -                    classpath = addToArray(classpath, u.toString());
 675.137 -                    p = n + 1;
 675.138 -                }
 675.139 -            }
 675.140 -            return is.getMainClass();
 675.141 -        }
 675.142 -    }
 675.143 -
 675.144 -    private static Object addToArray(Object arr, String value) {
 675.145 -        final int last = length(arr);
 675.146 -        Object ret = enlargeArray(arr, last + 1);
 675.147 -        set(ret, last, value);
 675.148 -        return ret;
 675.149 -    }
 675.150 -
 675.151 -    @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(null); return arr;")
 675.152 -    private static native Object enlargeArray(Object arr, int len);
 675.153 -    @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(0);")
 675.154 -    private static native void enlargeBytes(byte[] arr, int len);
 675.155 -
 675.156 -    @JavaScriptBody(args = { "arr", "len" }, body = "arr.splice(len, arr.length - len);")
 675.157 -    private static native void sliceArray(byte[] arr, int len);
 675.158 -
 675.159 -    private static Object readFully(byte[] arr, InputStream zip) throws IOException {
 675.160 -        int offset = 0;
 675.161 -        for (;;) {
 675.162 -            int len = zip.read(arr, offset, arr.length - offset);
 675.163 -            if (len == -1) {
 675.164 -                break;
 675.165 -            }
 675.166 -            offset += len;
 675.167 -            if (offset == arr.length) {
 675.168 -                enlargeBytes(arr, arr.length + 4096);
 675.169 -            }
 675.170 -        }
 675.171 -        sliceArray(arr, offset);
 675.172 -        return arr;
 675.173 -    }
 675.174 -
 675.175 -    private static long timeNow() {
 675.176 -        double time = m();
 675.177 -        if (time >= 0) {
 675.178 -            return (long)time;
 675.179 -        }
 675.180 -        return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis();
 675.181 -    }
 675.182 -    @JavaScriptBody(args = {}, body = 
 675.183 -        "if (typeof window.performance === 'undefined') return -1;\n"
 675.184 -      + "if (typeof window.performance.now === 'undefined') return -1;\n"
 675.185 -      + "return window.performance.now();"
 675.186 -    )
 675.187 -    private static native double m();
 675.188 -    
 675.189 -    
 675.190 -}
   676.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Array.java	Mon Feb 25 19:00:08 2013 +0100
   676.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   676.3 @@ -1,135 +0,0 @@
   676.4 -/**
   676.5 - * Back 2 Browser Bytecode Translator
   676.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   676.7 - *
   676.8 - * This program is free software: you can redistribute it and/or modify
   676.9 - * it under the terms of the GNU General Public License as published by
  676.10 - * the Free Software Foundation, version 2 of the License.
  676.11 - *
  676.12 - * This program is distributed in the hope that it will be useful,
  676.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  676.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  676.15 - * GNU General Public License for more details.
  676.16 - *
  676.17 - * You should have received a copy of the GNU General Public License
  676.18 - * along with this program. Look for COPYING file in the top folder.
  676.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  676.20 - */
  676.21 -package org.apidesign.vm4brwsr;
  676.22 -
  676.23 -/**
  676.24 - *
  676.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  676.26 - */
  676.27 -public class Array {
  676.28 -    byte[] bytes = { 1 };
  676.29 -    short[] shorts = { 2, 3 };
  676.30 -    int[] ints = { 4, 5, 6 };
  676.31 -    float[] floats = { 7, 8, 9, 10 };
  676.32 -    double[][] doubles = { {11}, {12}, {13}, {14}, {15} };
  676.33 -    char[] chars = { 'a', 'b' };
  676.34 -    
  676.35 -    private Array() {
  676.36 -    }
  676.37 -    
  676.38 -    byte bytes() {
  676.39 -        return bytes[0];
  676.40 -    }
  676.41 -    short shorts() {
  676.42 -        return shorts[1];
  676.43 -    }
  676.44 -    
  676.45 -    int[] ints() {
  676.46 -        return ints;
  676.47 -    }
  676.48 -    
  676.49 -    float floats() {
  676.50 -        return floats[3];
  676.51 -    }
  676.52 -    
  676.53 -    double doubles() {
  676.54 -        return doubles[4][0];
  676.55 -    }
  676.56 -    
  676.57 -    static double[][] dbls = new double[1][2];
  676.58 -    public static double twoDoubles() {
  676.59 -        return dbls[0][0] + dbls[0][0];
  676.60 -    }
  676.61 -
  676.62 -    static int[][] tints = new int[1][2];
  676.63 -    public static int twoInts() {
  676.64 -        return tints[0][0] + tints[0][0];
  676.65 -    }
  676.66 -    
  676.67 -    private static final Array[] ARR = { new Array(), new Array(), new Array() };
  676.68 -    
  676.69 -    private static Array[][] arr() {
  676.70 -        Array[][] matrix = new Array[3][3];
  676.71 -        for (int i = 0; i < ARR.length; i++) {
  676.72 -            matrix[i][i] = ARR[i];
  676.73 -        }
  676.74 -        return matrix;
  676.75 -    }
  676.76 -    private static <T> T[] filter(T[] in) {
  676.77 -        return in;
  676.78 -    }
  676.79 -    
  676.80 -    public static double sum() {
  676.81 -        double sum = 0.0;
  676.82 -        for (Array[] row : arr()) {
  676.83 -            int indx = -1;
  676.84 -            for (Array a : row) {
  676.85 -                indx++;
  676.86 -                if (a == null) {
  676.87 -                    continue;
  676.88 -                }
  676.89 -                sum += a.bytes();
  676.90 -                sum += a.shorts();
  676.91 -                sum += a.ints()[2];
  676.92 -                sum += a.floats();
  676.93 -                sum += filter(row)[indx].doubles();
  676.94 -            }
  676.95 -        }
  676.96 -        return sum;
  676.97 -    }
  676.98 -    private static final int[] arr = { 0, 1, 2, 3, 4, 5 };
  676.99 -    public static int simple(boolean clone) {
 676.100 -        int[] ar;
 676.101 -        if (clone) {
 676.102 -            ar = arr.clone();
 676.103 -        } else {
 676.104 -            ar = arr;
 676.105 -        }
 676.106 -        
 676.107 -        int sum = 0;
 676.108 -        for (int a : ar) {
 676.109 -            sum += a;
 676.110 -        }
 676.111 -        return sum;
 676.112 -    }
 676.113 -    
 676.114 -    public static String objectArrayClass() {
 676.115 -        return Object[].class.getName();
 676.116 -    }
 676.117 -    
 676.118 -    public static boolean instanceOfArray(Object obj) {
 676.119 -        return obj instanceof Object[];
 676.120 -    }
 676.121 -    
 676.122 -    public static int sum(int size) {
 676.123 -        int[] arr = new int[size];
 676.124 -        return arr[0] + arr[1];
 676.125 -    }
 676.126 -    
 676.127 -    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
 676.128 -        while (count-- > 0) {
 676.129 -            dst[dstBegin++] = value[srcBegin++];
 676.130 -        }
 676.131 -    }
 676.132 -
 676.133 -    public static char copyArray() {
 676.134 -        char[] arr = { '0' };
 676.135 -        arraycopy(arr()[0][0].chars, 0, arr, 0, 1);
 676.136 -        return arr[0];
 676.137 -    }
 676.138 -}
   677.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java	Mon Feb 25 19:00:08 2013 +0100
   677.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   677.3 @@ -1,87 +0,0 @@
   677.4 -/**
   677.5 - * Back 2 Browser Bytecode Translator
   677.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   677.7 - *
   677.8 - * This program is free software: you can redistribute it and/or modify
   677.9 - * it under the terms of the GNU General Public License as published by
  677.10 - * the Free Software Foundation, version 2 of the License.
  677.11 - *
  677.12 - * This program is distributed in the hope that it will be useful,
  677.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  677.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  677.15 - * GNU General Public License for more details.
  677.16 - *
  677.17 - * You should have received a copy of the GNU General Public License
  677.18 - * along with this program. Look for COPYING file in the top folder.
  677.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  677.20 - */
  677.21 -package org.apidesign.vm4brwsr;
  677.22 -
  677.23 -import static org.testng.Assert.*;
  677.24 -import org.testng.annotations.BeforeClass;
  677.25 -import org.testng.annotations.Test;
  677.26 -
  677.27 -/**
  677.28 - *
  677.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  677.30 - */
  677.31 -public class ArrayTest {
  677.32 -    @Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
  677.33 -            assertExec("0 + 0", Array.class, "sum__II", 
  677.34 -            Double.valueOf(0), 2
  677.35 -        );
  677.36 -    }
  677.37 -    @Test public void verifySimpleIntOperation() throws Exception {
  677.38 -            assertExec("CheckTheSum", Array.class, "simple__IZ", 
  677.39 -            Double.valueOf(15), false
  677.40 -        );
  677.41 -    }
  677.42 -    
  677.43 -    @Test public void cloneOnArray() throws Exception {
  677.44 -            assertExec("CheckTheSum on clone", Array.class, "simple__IZ", 
  677.45 -            Double.valueOf(15), true
  677.46 -        );
  677.47 -    }
  677.48 -    
  677.49 -    @Test public void realOperationOnArrays() throws Exception {
  677.50 -        assertEquals(Array.sum(), 105.0, "Computes to 105");
  677.51 -    }
  677.52 -    
  677.53 -    @Test public void verifyOperationsOnArrays() throws Exception {
  677.54 -        assertExec("The sum is 105", Array.class, "sum__D", 
  677.55 -            Double.valueOf(105)
  677.56 -        );
  677.57 -    }
  677.58 -
  677.59 -    @Test public void twoDoubles() throws Exception {
  677.60 -        assertExec("Elements are initialized", Array.class, "twoDoubles__D", 
  677.61 -            Double.valueOf(0)
  677.62 -        );
  677.63 -    }
  677.64 -    @Test public void twoInts() throws Exception {
  677.65 -        assertExec("Elements are initialized", Array.class, "twoInts__I", 
  677.66 -            Double.valueOf(0)
  677.67 -        );
  677.68 -    }
  677.69 -    
  677.70 -    @Test public void doesCopyArrayWork() throws Exception {
  677.71 -        assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
  677.72 -    }
  677.73 -
  677.74 -    @Test public void verifyObjectArrayClass() throws Exception {
  677.75 -        assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass());
  677.76 -    }
  677.77 -    @Test public void verifyInstanceOfArray() throws Exception {
  677.78 -        assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array");
  677.79 -    }
  677.80 -    
  677.81 -    private static TestVM code;
  677.82 -    
  677.83 -    @BeforeClass 
  677.84 -    public void compileTheCode() throws Exception {
  677.85 -        code = TestVM.compileClass("org/apidesign/vm4brwsr/Array");
  677.86 -    }
  677.87 -    private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
  677.88 -        code.assertExec(msg, clazz, method, expRes, args);
  677.89 -    }
  677.90 -}
   678.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java	Mon Feb 25 19:00:08 2013 +0100
   678.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   678.3 @@ -1,55 +0,0 @@
   678.4 -/**
   678.5 - * Back 2 Browser Bytecode Translator
   678.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   678.7 - *
   678.8 - * This program is free software: you can redistribute it and/or modify
   678.9 - * it under the terms of the GNU General Public License as published by
  678.10 - * the Free Software Foundation, version 2 of the License.
  678.11 - *
  678.12 - * This program is distributed in the hope that it will be useful,
  678.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  678.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  678.15 - * GNU General Public License for more details.
  678.16 - *
  678.17 - * You should have received a copy of the GNU General Public License
  678.18 - * along with this program. Look for COPYING file in the top folder.
  678.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  678.20 - */
  678.21 -package org.apidesign.vm4brwsr;
  678.22 -
  678.23 -import static org.testng.Assert.*;
  678.24 -import org.testng.annotations.Test;
  678.25 -
  678.26 -/**
  678.27 - *
  678.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  678.29 - */
  678.30 -public class ByteCodeToJavaScriptTest {
  678.31 -    
  678.32 -    public ByteCodeToJavaScriptTest() {
  678.33 -    }
  678.34 -
  678.35 -    @Test
  678.36 -    public void findMethodNameManglesObjectsCorrectly() {
  678.37 -        StringBuilder cnt = new StringBuilder();
  678.38 -        char[] returnType = { 'V' };
  678.39 -        String ret = ByteCodeToJavaScript.findMethodName(new String[] { 
  678.40 -            "StringTest", "replace", "(Ljava/lang/String;CC)Ljava/lang/String;"
  678.41 -        }, cnt, returnType);
  678.42 -        assertEquals(cnt.toString(), "000", "No doubles or longs");
  678.43 -        assertTrue(returnType[0] != 'V', "Returns string");
  678.44 -        assertEquals(ret, "replace__Ljava_lang_String_2Ljava_lang_String_2CC");
  678.45 -    }
  678.46 -
  678.47 -    @Test
  678.48 -    public void manglingArrays() {
  678.49 -        StringBuilder cnt = new StringBuilder();
  678.50 -        char[] returnType = { 'V' };
  678.51 -        String ret = ByteCodeToJavaScript.findMethodName(new String[] { 
  678.52 -            "VMinVM", "toJavaScript", "([B)Ljava/lang/String;"
  678.53 -        }, cnt, returnType);
  678.54 -        assertEquals(cnt.toString(), "0", "No doubles or longs");
  678.55 -        assertTrue(returnType[0] != 'V', "Returns string");
  678.56 -        assertEquals(ret, "toJavaScript__Ljava_lang_String_2_3B");
  678.57 -    }
  678.58 -}
   679.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/BytesLoader.java	Mon Feb 25 19:00:08 2013 +0100
   679.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   679.3 @@ -1,76 +0,0 @@
   679.4 -/**
   679.5 - * Back 2 Browser Bytecode Translator
   679.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   679.7 - *
   679.8 - * This program is free software: you can redistribute it and/or modify
   679.9 - * it under the terms of the GNU General Public License as published by
  679.10 - * the Free Software Foundation, version 2 of the License.
  679.11 - *
  679.12 - * This program is distributed in the hope that it will be useful,
  679.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  679.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  679.15 - * GNU General Public License for more details.
  679.16 - *
  679.17 - * You should have received a copy of the GNU General Public License
  679.18 - * along with this program. Look for COPYING file in the top folder.
  679.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  679.20 - */
  679.21 -package org.apidesign.vm4brwsr;
  679.22 -
  679.23 -import java.io.IOException;
  679.24 -import java.io.InputStream;
  679.25 -import java.net.URL;
  679.26 -import java.util.Enumeration;
  679.27 -import java.util.Set;
  679.28 -import java.util.TreeSet;
  679.29 -
  679.30 -/**
  679.31 - *
  679.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  679.33 - */
  679.34 -public final class BytesLoader {
  679.35 -    private static Set<String> requested = new TreeSet<String>();
  679.36 -
  679.37 -    public byte[] get(String name) throws IOException {
  679.38 -        if (!requested.add(name)) {
  679.39 -            throw new IllegalStateException("Requested for second time: " + name);
  679.40 -        }
  679.41 -        byte[] arr = readClass(name);
  679.42 -        /*
  679.43 -        System.err.print("loader['" + name + "'] = [");
  679.44 -        for (int i = 0; i < arr.length; i++) {
  679.45 -        if (i > 0) {
  679.46 -        System.err.print(", ");
  679.47 -        }
  679.48 -        System.err.print(arr[i]);
  679.49 -        }
  679.50 -        System.err.println("]");
  679.51 -         */
  679.52 -        return arr;
  679.53 -    }
  679.54 -
  679.55 -    static byte[] readClass(String name) throws IOException {
  679.56 -        URL u = null;
  679.57 -        Enumeration<URL> en = BytesLoader.class.getClassLoader().getResources(name);
  679.58 -        while (en.hasMoreElements()) {
  679.59 -            u = en.nextElement();
  679.60 -        }
  679.61 -        if (u == null) {
  679.62 -            throw new IOException("Can't find " + name);
  679.63 -        }
  679.64 -        try (InputStream is = u.openStream()) {
  679.65 -            byte[] arr;
  679.66 -            arr = new byte[is.available()];
  679.67 -            int offset = 0;
  679.68 -            while (offset < arr.length) {
  679.69 -                int len = is.read(arr, offset, arr.length - offset);
  679.70 -                if (len == -1) {
  679.71 -                    throw new IOException("Can't read " + name);
  679.72 -                }
  679.73 -                offset += len;
  679.74 -            }
  679.75 -            return arr;
  679.76 -        }
  679.77 -    }
  679.78 -    
  679.79 -}
   680.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Mon Feb 25 19:00:08 2013 +0100
   680.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   680.3 @@ -1,206 +0,0 @@
   680.4 -/**
   680.5 - * Back 2 Browser Bytecode Translator
   680.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   680.7 - *
   680.8 - * This program is free software: you can redistribute it and/or modify
   680.9 - * it under the terms of the GNU General Public License as published by
  680.10 - * the Free Software Foundation, version 2 of the License.
  680.11 - *
  680.12 - * This program is distributed in the hope that it will be useful,
  680.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  680.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  680.15 - * GNU General Public License for more details.
  680.16 - *
  680.17 - * You should have received a copy of the GNU General Public License
  680.18 - * along with this program. Look for COPYING file in the top folder.
  680.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  680.20 - */
  680.21 -package org.apidesign.vm4brwsr;
  680.22 -
  680.23 -import org.testng.annotations.Test;
  680.24 -import static org.testng.Assert.*;
  680.25 -import org.testng.annotations.BeforeClass;
  680.26 -
  680.27 -/**
  680.28 - *
  680.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  680.30 - */
  680.31 -public class ClassTest {
  680.32 -
  680.33 -    @Test public void superClassEqualsGetSuperclass() {
  680.34 -        assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
  680.35 -    }
  680.36 -
  680.37 -    @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
  680.38 -        assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptions__Z", Double.valueOf(1.0));
  680.39 -    }
  680.40 -
  680.41 -    @Test public void classesAreDifferent() {
  680.42 -        assertTrue(Classes.differenceInClasses(), "Classes are not equal");
  680.43 -    }
  680.44 -
  680.45 -    @Test public void jsClassesAreDifferent() throws Exception {
  680.46 -        assertExec("Classes are not equal", Classes.class, "differenceInClasses__Z", Double.valueOf(1.0));
  680.47 -    }
  680.48 -
  680.49 -    @Test public void javaInstanceName() throws Exception {
  680.50 -        assertEquals(Classes.classForInstance(), "java.io.IOException");
  680.51 -    }
  680.52 -    @Test public void jsInstanceName() throws Exception {
  680.53 -        assertExec("I/O name", Classes.class, "classForInstance__Ljava_lang_String_2", "java.io.IOException");
  680.54 -    }
  680.55 -    @Test public void javaName() throws Exception {
  680.56 -        assertEquals(Classes.name(), "java.io.IOException");
  680.57 -    }
  680.58 -    @Test public void jsName() throws Exception {
  680.59 -        assertExec("I/O name", Classes.class, "name__Ljava_lang_String_2", "java.io.IOException");
  680.60 -    }
  680.61 -    @Test public void javaSimpleName() throws Exception {
  680.62 -        assertEquals(Classes.simpleName(), "IOException");
  680.63 -    }
  680.64 -    @Test public void jsGetsSimpleName() throws Exception {
  680.65 -        assertExec("I/O simple name", Classes.class, "simpleName__Ljava_lang_String_2", "IOException");
  680.66 -    }
  680.67 -    @Test public void javaCanonicalName() {
  680.68 -        assertEquals(Classes.canonicalName(), "java.io.IOException");
  680.69 -    }
  680.70 -    @Test public void jsCanonicalName() throws Exception {
  680.71 -        assertExec("I/O simple name", Classes.class, "canonicalName__Ljava_lang_String_2", "java.io.IOException");
  680.72 -    }
  680.73 -    @Test public void javaNewInstance() throws Exception {
  680.74 -        assertTrue(Classes.newInstance());
  680.75 -    }
  680.76 -    @Test public void jsNewInstance() throws Exception {
  680.77 -        assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
  680.78 -    }
  680.79 -    @Test public void javaNoNewInstance() throws Exception {
  680.80 -        assertEquals("java.lang.InstantiationException:java.lang.Float", 
  680.81 -            Classes.newInstanceNoPubConstructor()
  680.82 -        );
  680.83 -    }
  680.84 -    @Test public void jsNoNewInstance() throws Exception {
  680.85 -        assertExec("Check problems with new instance", Classes.class, "newInstanceNoPubConstructor__Ljava_lang_String_2", 
  680.86 -            "java.lang.InstantiationException:java.lang.Float"
  680.87 -        );
  680.88 -    }
  680.89 -    @Test public void jsAnnotation() throws Exception {
  680.90 -        assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
  680.91 -    }
  680.92 -    @Test public void jsArrayAnnotation() throws Exception {
  680.93 -        assertExec("Check array annotation", Classes.class, "getMarkerNicknames__Ljava_lang_String_2", Classes.getMarkerNicknames());
  680.94 -    }
  680.95 -    @Test public void jsEnumAnnotation() throws Exception {
  680.96 -        assertExec("Check enum annotation", Classes.class, "getMarkerE__Ljava_lang_String_2", Classes.getMarkerE());
  680.97 -    }
  680.98 -    @Test public void jsRetentionAnnotation() throws Exception {
  680.99 -        assertExec("Check enum annotation", Classes.class, "getRetention__Ljava_lang_String_2", Classes.getRetention());
 680.100 -    }
 680.101 -    @Test public void jsStringAnnotation() throws Exception {
 680.102 -        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", true);
 680.103 -    }
 680.104 -    @Test public void jsStringAnnotationFromArray() throws Exception {
 680.105 -        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
 680.106 -    }
 680.107 -    @Test public void jsInnerAnnotation() throws Exception {
 680.108 -        assertExec("Check inner annotation", Classes.class, "getInnerNamer__I", Double.valueOf(Classes.getInnerNamer()));
 680.109 -    }
 680.110 -    @Test public void jsInnerAnnotationFromArray() throws Exception {
 680.111 -        assertExec("Check inner annotation", Classes.class, "getInnerNamers__I", Double.valueOf(Classes.getInnerNamers()));
 680.112 -    }
 680.113 -    @Test public void javaInvokeMethod() throws Exception {
 680.114 -        assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
 680.115 -    }
 680.116 -    @Test public void jsInvokeMethod() throws Exception {
 680.117 -        assertExec("Calls the name() method via reflection", Classes.class, 
 680.118 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
 680.119 -            "java.io.IOException", true, "name"
 680.120 -        );
 680.121 -    }
 680.122 -    
 680.123 -    @Test public void jsMethodDeclaredInObject() throws Exception {
 680.124 -        assertExec("Defined in Object", Classes.class, 
 680.125 -            "objectName__Ljava_lang_String_2", 
 680.126 -            "java.lang.Object"
 680.127 -        );
 680.128 -    }
 680.129 -    
 680.130 -    @Test public void jsInvokeParamMethod() throws Exception {
 680.131 -        assertExec("sums two numbers via reflection", Classes.class, 
 680.132 -            "reflectiveSum__III", Double.valueOf(5), 2, 3
 680.133 -        );
 680.134 -    }
 680.135 -    @Test public void javaFindMethod() throws Exception {
 680.136 -        assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
 680.137 -    }
 680.138 -    @Test public void jsFindMethod() throws Exception {
 680.139 -        assertExec("Calls the name() method via reflection", Classes.class, 
 680.140 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
 680.141 -            "java.io.IOException", false, "name"
 680.142 -        );
 680.143 -    }
 680.144 -    @Test public void primitiveReturnType() throws Exception {
 680.145 -        assertExec("Tries to get an integer via reflection", Classes.class, 
 680.146 -            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
 680.147 -            Classes.primitiveType("primitive"), "primitive"
 680.148 -        );
 680.149 -    }
 680.150 -    @Test public void primitiveBoolReturnType() throws Exception {
 680.151 -        assertExec("Tries to get an integer via reflection", Classes.class, 
 680.152 -            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
 680.153 -            Classes.primitiveType("primitiveB"), "primitiveB"
 680.154 -        );
 680.155 -    }
 680.156 -    @Test public void javaAnnotatedMethod() throws Exception {
 680.157 -        assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
 680.158 -    }
 680.159 -    @Test public void jsAnnotatedMethod() throws Exception {
 680.160 -        assertExec("Calls the name() method via reflection", Classes.class, 
 680.161 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
 680.162 -            "java.io.IOException", false, null
 680.163 -        );
 680.164 -    }
 680.165 -    @Test public void jsClassParam() throws Exception {
 680.166 -        assertExec("Calls the nameOfIO()", Classes.class, 
 680.167 -            "nameOfIO__Ljava_lang_String_2", 
 680.168 -            "java.io.IOException"
 680.169 -        );
 680.170 -    }
 680.171 -    @Test public void noInterface() throws Exception {
 680.172 -        assertExec("Calls Class.isInterface", Classes.class, 
 680.173 -            "isInterface__ZLjava_lang_String_2", 
 680.174 -            0.0, "java.lang.String"
 680.175 -        );
 680.176 -    }
 680.177 -    @Test public void isInterface() throws Exception {
 680.178 -        assertExec("Calls Class.isInterface", Classes.class, 
 680.179 -            "isInterface__ZLjava_lang_String_2", 
 680.180 -            1.0, "java.lang.Runnable"
 680.181 -        );
 680.182 -    }
 680.183 -    @Test public void integerType() throws Exception {
 680.184 -        assertExec("Computes the type", Classes.class, 
 680.185 -            "intType__Ljava_lang_String_2", 
 680.186 -            Classes.intType()
 680.187 -        );
 680.188 -    }
 680.189 -    
 680.190 -    private static TestVM code;
 680.191 -    
 680.192 -    @BeforeClass
 680.193 -    public void compileTheCode() throws Exception {
 680.194 -        code = TestVM.compileClass("org/apidesign/vm4brwsr/Classes");
 680.195 -    }
 680.196 -    
 680.197 -    private void assertExec(
 680.198 -        String msg, Class clazz, String method, Object expRes, Object... args
 680.199 -    ) throws Exception {
 680.200 -        code.assertExec(msg, clazz, method, expRes, args);
 680.201 -    }
 680.202 -    @Test public void isClassAssignable() throws Exception {
 680.203 -        assertExec("isAssignable works on subclasses", Classes.class, 
 680.204 -            "isClassAssignable__Z", 
 680.205 -            true
 680.206 -        );
 680.207 -    }
 680.208 -    
 680.209 -}
   681.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Mon Feb 25 19:00:08 2013 +0100
   681.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   681.3 @@ -1,233 +0,0 @@
   681.4 -/**
   681.5 - * Back 2 Browser Bytecode Translator
   681.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   681.7 - *
   681.8 - * This program is free software: you can redistribute it and/or modify
   681.9 - * it under the terms of the GNU General Public License as published by
  681.10 - * the Free Software Foundation, version 2 of the License.
  681.11 - *
  681.12 - * This program is distributed in the hope that it will be useful,
  681.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  681.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  681.15 - * GNU General Public License for more details.
  681.16 - *
  681.17 - * You should have received a copy of the GNU General Public License
  681.18 - * along with this program. Look for COPYING file in the top folder.
  681.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  681.20 - */
  681.21 -package org.apidesign.vm4brwsr;
  681.22 -
  681.23 -import java.io.IOException;
  681.24 -import java.lang.annotation.Annotation;
  681.25 -import java.lang.annotation.Retention;
  681.26 -import java.lang.annotation.RetentionPolicy;
  681.27 -import java.lang.reflect.Method;
  681.28 -import java.net.MalformedURLException;
  681.29 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  681.30 -
  681.31 -/**
  681.32 - *
  681.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  681.34 - */
  681.35 -@ClassesMarker(number = 10, nicknames = { "Ten", "Deset" }, count = ClassesMarker.E.TWO, subs = {
  681.36 -    @ClassesMarker.Anno(Integer.SIZE),
  681.37 -    @ClassesMarker.Anno(Integer.MIN_VALUE)
  681.38 -})
  681.39 -@ClassesNamer(name = "my text", anno = @ClassesMarker.Anno(333))
  681.40 -public class Classes {
  681.41 -    public static String nameOfIO() {
  681.42 -        return nameFor(IOException.class);
  681.43 -    }
  681.44 -    
  681.45 -    private static String nameFor(Class<?> c) {
  681.46 -        return c.getName();
  681.47 -    }
  681.48 -    
  681.49 -    private static final Class<?> PRELOAD = Runnable.class;
  681.50 -    
  681.51 -    public static boolean isInterface(String s) throws ClassNotFoundException {
  681.52 -        return Class.forName(s).isInterface();
  681.53 -    }
  681.54 -    
  681.55 -    public static boolean equalsClassesOfExceptions() {
  681.56 -        return MalformedURLException.class.getSuperclass() == IOException.class;
  681.57 -    }
  681.58 -    public static boolean differenceInClasses() {
  681.59 -        Class<?> c1 = MalformedURLException.class;
  681.60 -        Class<?> c2 = IOException.class;
  681.61 -        return c1 != c2;
  681.62 -    }
  681.63 -    
  681.64 -    public static String classForInstance() {
  681.65 -        return new IOException().getClass().getName().toString();
  681.66 -    }
  681.67 -    
  681.68 -    @ClassesMarker(number = 1, nicknames = { "One", "Jedna" } )
  681.69 -    public static String name() {
  681.70 -        return IOException.class.getName().toString();
  681.71 -    }
  681.72 -    public static String simpleName() {
  681.73 -        return IOException.class.getSimpleName();
  681.74 -    }
  681.75 -    public static String canonicalName() {
  681.76 -        return IOException.class.getCanonicalName();
  681.77 -    }
  681.78 -    
  681.79 -    public static String objectName() throws NoSuchMethodException {
  681.80 -        return IOException.class.getMethod("wait").getDeclaringClass().getName();
  681.81 -    }
  681.82 -    
  681.83 -    public static boolean newInstance() throws Exception {
  681.84 -        IOException ioe = IOException.class.newInstance();
  681.85 -        if (ioe instanceof IOException) {
  681.86 -            return ioe.getClass() == IOException.class;
  681.87 -        }
  681.88 -        throw new IllegalStateException("Not a subtype: " + ioe);
  681.89 -    }
  681.90 -    public static String newInstanceNoPubConstructor() throws Exception {
  681.91 -        try {
  681.92 -            Float f = Float.class.newInstance();
  681.93 -            return "wrong, can't instantiate: " + f;
  681.94 -        } catch (Exception ex) {
  681.95 -            return (ex.getClass().getName() + ":" + ex.getMessage()).toString().toString();
  681.96 -        }
  681.97 -    }
  681.98 -    public static int getMarker() {
  681.99 -        if (!Classes.class.isAnnotationPresent(ClassesMarker.class)) {
 681.100 -            return -2;
 681.101 -        }
 681.102 -        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 681.103 -        assert cm instanceof Object : "Is object " + cm;
 681.104 -        assert cm instanceof Annotation : "Is annotation " + cm;
 681.105 -        assert !((Object)cm instanceof Class) : "Is not Class " + cm;
 681.106 -        return cm == null ? -1 : cm.number();
 681.107 -    }
 681.108 -    public static String getMarkerNicknames() {
 681.109 -        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 681.110 -        if (cm == null) {
 681.111 -            return null;
 681.112 -        }
 681.113 -        
 681.114 -        final Object[] arr = cm.nicknames();
 681.115 -        assert arr instanceof Object[] : "Instance of Object array: " + arr;
 681.116 -        assert arr instanceof String[] : "Instance of String array: " + arr;
 681.117 -        assert !(arr instanceof Integer[]) : "Not instance of Integer array: " + arr;
 681.118 -        
 681.119 -        StringBuilder sb = new StringBuilder();
 681.120 -        for (String s : cm.nicknames()) {
 681.121 -            sb.append(s).append("\n");
 681.122 -        }
 681.123 -        return sb.toString().toString();
 681.124 -    }
 681.125 -    @Retention(RetentionPolicy.CLASS)
 681.126 -    @interface Ann {
 681.127 -    }
 681.128 -    
 681.129 -    public static String getRetention() throws Exception {
 681.130 -        Retention r = Ann.class.getAnnotation(Retention.class);
 681.131 -        assert r != null : "Annotation is present";
 681.132 -        assert r.value() == RetentionPolicy.CLASS : "Policy value is OK: " + r.value();
 681.133 -        return r.annotationType().getName();
 681.134 -    }
 681.135 -    public static String getMarkerE() {
 681.136 -        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 681.137 -        if (cm == null) {
 681.138 -            return null;
 681.139 -        }
 681.140 -        return cm.count().name();
 681.141 -    }
 681.142 -    public static String getNamer(boolean direct) {
 681.143 -        if (direct) {
 681.144 -            ClassesNamer cm = Classes.class.getAnnotation(ClassesNamer.class);
 681.145 -            return cm == null ? null : cm.name();
 681.146 -        }
 681.147 -        for (Annotation a : Classes.class.getAnnotations()) {
 681.148 -            if (a instanceof ClassesNamer) {
 681.149 -                return ((ClassesNamer)a).name();
 681.150 -            }
 681.151 -        }
 681.152 -        return null;
 681.153 -    }
 681.154 -    public static int getInnerNamer() {
 681.155 -        ClassesNamer cm = Classes.class.getAnnotation(ClassesNamer.class);
 681.156 -        assert cm != null : "ClassesNamer is present";
 681.157 -        return cm.anno().value();
 681.158 -    }
 681.159 -    public static int getInnerNamers() {
 681.160 -        ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
 681.161 -        assert cm != null : "ClassesNamer is present";
 681.162 -        int sum = 0;
 681.163 -        for (ClassesMarker.Anno anno : cm.subs()) {
 681.164 -            sum += anno.value();
 681.165 -        }
 681.166 -        return sum;
 681.167 -    }
 681.168 -    
 681.169 -    public static String intType() {
 681.170 -        return Integer.TYPE.getName();
 681.171 -    }
 681.172 -    
 681.173 -    public static int primitive() {
 681.174 -        return 1;
 681.175 -    }
 681.176 -    public static boolean primitiveB() {
 681.177 -        return true;
 681.178 -    }
 681.179 -    
 681.180 -    public static String primitiveType(String method) throws Exception {
 681.181 -        return reflectiveMethodCall(false, method).getClass().getName();
 681.182 -    }
 681.183 -    
 681.184 -    @JavaScriptBody(args = "msg", body = "throw msg;")
 681.185 -    private static native void thrw(String msg);
 681.186 -    
 681.187 -    public static Object reflectiveMethodCall(boolean direct, String mn) throws Exception {
 681.188 -        Method find = null;
 681.189 -        StringBuilder sb = new StringBuilder();
 681.190 -        if (!direct) {
 681.191 -            final Class<? extends Annotation> v = ClassesMarker.class;
 681.192 -            for (Method m : Classes.class.getMethods()) {
 681.193 -                sb.append("\n").append(m.getName());
 681.194 -                if (mn != null) {
 681.195 -                    if (m.getName().equals(mn)) {
 681.196 -                        find = m;
 681.197 -                        break;
 681.198 -                    }
 681.199 -                } else {
 681.200 -                    if (m.getAnnotation(v) != null) {
 681.201 -                        find = m;
 681.202 -                        break;
 681.203 -                    }
 681.204 -                }
 681.205 -            }
 681.206 -        } else {
 681.207 -            find = Classes.class.getMethod(mn);
 681.208 -        }
 681.209 -        if (find == null) {
 681.210 -            thrw(sb.toString());
 681.211 -            throw new NullPointerException(sb.toString());
 681.212 -        }
 681.213 -        return find.invoke(null);
 681.214 -    }
 681.215 -    
 681.216 -    public static int reflectiveSum(int a, int b) throws Exception {
 681.217 -        Method m = StaticMethod.class.getMethod("sum", int.class, int.class);
 681.218 -        return (int) m.invoke(null, a, b);
 681.219 -    }
 681.220 -    
 681.221 -    private abstract class Application {
 681.222 -        public abstract int getID();
 681.223 -    }
 681.224 -
 681.225 -    private class MyApplication extends Application {
 681.226 -        @Override
 681.227 -        public int getID() {
 681.228 -            return 1;
 681.229 -        }
 681.230 -    }
 681.231 -
 681.232 -    public static boolean isClassAssignable() {
 681.233 -        return Application.class.isAssignableFrom(MyApplication.class);
 681.234 -    }
 681.235 -    
 681.236 -}
   682.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassesMarker.java	Mon Feb 25 19:00:08 2013 +0100
   682.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   682.3 @@ -1,42 +0,0 @@
   682.4 -/**
   682.5 - * Back 2 Browser Bytecode Translator
   682.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   682.7 - *
   682.8 - * This program is free software: you can redistribute it and/or modify
   682.9 - * it under the terms of the GNU General Public License as published by
  682.10 - * the Free Software Foundation, version 2 of the License.
  682.11 - *
  682.12 - * This program is distributed in the hope that it will be useful,
  682.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  682.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  682.15 - * GNU General Public License for more details.
  682.16 - *
  682.17 - * You should have received a copy of the GNU General Public License
  682.18 - * along with this program. Look for COPYING file in the top folder.
  682.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  682.20 - */
  682.21 -package org.apidesign.vm4brwsr;
  682.22 -
  682.23 -import java.lang.annotation.Retention;
  682.24 -import java.lang.annotation.RetentionPolicy;
  682.25 -
  682.26 -/**
  682.27 - *
  682.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  682.29 - */
  682.30 -@Retention(RetentionPolicy.RUNTIME)
  682.31 -public @interface ClassesMarker {
  682.32 -    int number();
  682.33 -    String[] nicknames();
  682.34 -    E count() default E.ONE;
  682.35 -    
  682.36 -    enum E {
  682.37 -        ONE, TWO;
  682.38 -    }
  682.39 -    
  682.40 -    Anno[] subs() default {};
  682.41 -    
  682.42 -    public @interface Anno {
  682.43 -        int value();
  682.44 -    }
  682.45 -}
   683.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassesNamer.java	Mon Feb 25 19:00:08 2013 +0100
   683.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   683.3 @@ -1,31 +0,0 @@
   683.4 -/**
   683.5 - * Back 2 Browser Bytecode Translator
   683.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   683.7 - *
   683.8 - * This program is free software: you can redistribute it and/or modify
   683.9 - * it under the terms of the GNU General Public License as published by
  683.10 - * the Free Software Foundation, version 2 of the License.
  683.11 - *
  683.12 - * This program is distributed in the hope that it will be useful,
  683.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  683.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  683.15 - * GNU General Public License for more details.
  683.16 - *
  683.17 - * You should have received a copy of the GNU General Public License
  683.18 - * along with this program. Look for COPYING file in the top folder.
  683.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  683.20 - */
  683.21 -package org.apidesign.vm4brwsr;
  683.22 -
  683.23 -import java.lang.annotation.Retention;
  683.24 -import java.lang.annotation.RetentionPolicy;
  683.25 -
  683.26 -/**
  683.27 - *
  683.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  683.29 - */
  683.30 -@Retention(RetentionPolicy.RUNTIME)
  683.31 -public @interface ClassesNamer {
  683.32 -    String name();
  683.33 -    ClassesMarker.Anno anno();
  683.34 -}
   684.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Exceptions.java	Mon Feb 25 19:00:08 2013 +0100
   684.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   684.3 @@ -1,88 +0,0 @@
   684.4 -/**
   684.5 - * Back 2 Browser Bytecode Translator
   684.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   684.7 - *
   684.8 - * This program is free software: you can redistribute it and/or modify
   684.9 - * it under the terms of the GNU General Public License as published by
  684.10 - * the Free Software Foundation, version 2 of the License.
  684.11 - *
  684.12 - * This program is distributed in the hope that it will be useful,
  684.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  684.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  684.15 - * GNU General Public License for more details.
  684.16 - *
  684.17 - * You should have received a copy of the GNU General Public License
  684.18 - * along with this program. Look for COPYING file in the top folder.
  684.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  684.20 - */
  684.21 -package org.apidesign.vm4brwsr;
  684.22 -
  684.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  684.24 -
  684.25 -/**
  684.26 - *
  684.27 - * @author tom
  684.28 - */
  684.29 -public class Exceptions {
  684.30 -    private Exceptions() {
  684.31 -    }
  684.32 -
  684.33 -    public static int methodWithTryCatchNoThrow() {
  684.34 -        int res = 0;
  684.35 -        try {
  684.36 -            res = 1;
  684.37 -        } catch (IllegalArgumentException e) {
  684.38 -            res = 2;
  684.39 -        }
  684.40 -        //join point
  684.41 -        return res;
  684.42 -    }
  684.43 -
  684.44 -    public static int methodWithTryCatchThrow() {
  684.45 -        int res = 0;
  684.46 -        try {
  684.47 -            res = 1;
  684.48 -            throw new IllegalArgumentException();
  684.49 -        } catch (IllegalArgumentException e) {
  684.50 -            res = 2;
  684.51 -        }
  684.52 -        //join point
  684.53 -        return res;
  684.54 -    }
  684.55 -    
  684.56 -    @JavaScriptBody(args = "msg", body = "throw msg;")
  684.57 -    public static void thrw(String msg) {}
  684.58 -    
  684.59 -    public static String catchThrowableCatchesAll() {
  684.60 -        try {
  684.61 -            thrw("Hello!");
  684.62 -            return "Not here!";
  684.63 -        } catch (Throwable ex) {
  684.64 -            return ex.getMessage();
  684.65 -        }
  684.66 -    }
  684.67 -
  684.68 -    public static String newInstance(String n) {
  684.69 -        try {
  684.70 -            Class c;
  684.71 -            try {
  684.72 -                c = Class.forName(n);
  684.73 -            } catch (ClassNotFoundException ex) {
  684.74 -                return ("CNFE:" + ex.getMessage()).toString();
  684.75 -            }
  684.76 -            return c.newInstance().getClass().getName();
  684.77 -        } catch (InstantiationException | IllegalAccessException ex) {
  684.78 -            return ex.getMessage();
  684.79 -        }
  684.80 -    }
  684.81 -    
  684.82 -    private static int counter;
  684.83 -    public static int readCounter(String n) throws ClassNotFoundException {
  684.84 -        try {
  684.85 -            Class.forName(n);
  684.86 -        } finally {
  684.87 -            counter++;
  684.88 -        }
  684.89 -        return counter;
  684.90 -    }
  684.91 -}
   685.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ExceptionsTest.java	Mon Feb 25 19:00:08 2013 +0100
   685.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   685.3 @@ -1,114 +0,0 @@
   685.4 -/**
   685.5 - * Back 2 Browser Bytecode Translator
   685.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   685.7 - *
   685.8 - * This program is free software: you can redistribute it and/or modify
   685.9 - * it under the terms of the GNU General Public License as published by
  685.10 - * the Free Software Foundation, version 2 of the License.
  685.11 - *
  685.12 - * This program is distributed in the hope that it will be useful,
  685.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  685.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  685.15 - * GNU General Public License for more details.
  685.16 - *
  685.17 - * You should have received a copy of the GNU General Public License
  685.18 - * along with this program. Look for COPYING file in the top folder.
  685.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  685.20 - */
  685.21 -package org.apidesign.vm4brwsr;
  685.22 -
  685.23 -import javax.script.ScriptException;
  685.24 -import static org.testng.Assert.*;
  685.25 -import org.testng.annotations.BeforeClass;
  685.26 -import org.testng.annotations.Test;
  685.27 -
  685.28 -/**
  685.29 - *
  685.30 - * @author Tomas Zezula <tzezula@netbeans.org>
  685.31 - */
  685.32 -public class ExceptionsTest {
  685.33 -    @Test
  685.34 -    public void verifyMethodWithTryCatchNoThrow() throws Exception {
  685.35 -            assertExec(
  685.36 -                    "No throw",
  685.37 -                    Exceptions.class,
  685.38 -                    "methodWithTryCatchNoThrow__I",
  685.39 -                    new Double(1.0));
  685.40 -    }
  685.41 -
  685.42 -    @Test
  685.43 -    public void catchJavaScriptStringAsThrowable() throws Exception {
  685.44 -        assertExec(
  685.45 -            "Throw hello!",
  685.46 -            Exceptions.class,
  685.47 -            "catchThrowableCatchesAll__Ljava_lang_String_2",
  685.48 -            "Hello!"
  685.49 -        );
  685.50 -    }
  685.51 -
  685.52 -    @Test
  685.53 -    public void verifyMethodWithTryCatchThrow() throws Exception {
  685.54 -            assertExec(
  685.55 -                    "Throw",
  685.56 -                    Exceptions.class,
  685.57 -                    "methodWithTryCatchThrow__I",
  685.58 -                    new Double(2.0));
  685.59 -    }
  685.60 -    
  685.61 -    @Test public void createObject() throws Exception {
  685.62 -        assertExec("Object created", Exceptions.class, 
  685.63 -            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  685.64 -            "java.lang.Object",
  685.65 -            "java.lang.Object"
  685.66 -        );
  685.67 -    }
  685.68 -
  685.69 -    @Test public void createFloatFails() throws Exception {
  685.70 -        assertExec("Float not created", Exceptions.class, 
  685.71 -            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  685.72 -            "java.lang.Float",
  685.73 -            "java.lang.Float"
  685.74 -        );
  685.75 -    }
  685.76 -
  685.77 -    @Test public void createUnknownFails() throws Exception {
  685.78 -        assertExec("Object created", Exceptions.class, 
  685.79 -            "newInstance__Ljava_lang_String_2Ljava_lang_String_2",
  685.80 -            "CNFE:org.apidesign.Unknown",
  685.81 -            "org.apidesign.Unknown"
  685.82 -        );
  685.83 -    }
  685.84 -    
  685.85 -    @Test public void testThreeCalls() throws Exception {
  685.86 -        Object clazz = code.loadClass("loadClass", Exceptions.class.getName());
  685.87 -        
  685.88 -        String method = "readCounter__ILjava_lang_String_2";
  685.89 -        
  685.90 -        try {
  685.91 -            Object ret = code.invokeMethod(clazz, method, "org.apidesign.Unknown");
  685.92 -            fail("We expect an CNFE!");
  685.93 -        } catch (ScriptException scriptException) {
  685.94 -            // script exception should be OK
  685.95 -        }
  685.96 -        {
  685.97 -            // 2nd invocation
  685.98 -            Object ret = code.invokeMethod(clazz, method, "java.lang.String");
  685.99 -            assertEquals(ret, Double.valueOf(2));
 685.100 -        }
 685.101 -        {
 685.102 -            // 3rd invocation
 685.103 -            Object ret = code.invokeMethod(clazz, method, "java.lang.Integer");
 685.104 -            assertEquals(ret, Double.valueOf(3));
 685.105 -        }
 685.106 -    }
 685.107 -    
 685.108 -    private static TestVM code;
 685.109 -    
 685.110 -    @BeforeClass 
 685.111 -    public void compileTheCode() throws Exception {
 685.112 -        code = TestVM.compileClass("org/apidesign/vm4brwsr/Exceptions");
 685.113 -    }
 685.114 -    private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
 685.115 -        code.assertExec(msg, clazz, method, expRes, args);
 685.116 -    }
 685.117 -}
   686.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/GetByte.java	Mon Feb 25 19:00:08 2013 +0100
   686.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   686.3 @@ -1,22 +0,0 @@
   686.4 -/**
   686.5 - * Back 2 Browser Bytecode Translator
   686.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   686.7 - *
   686.8 - * This program is free software: you can redistribute it and/or modify
   686.9 - * it under the terms of the GNU General Public License as published by
  686.10 - * the Free Software Foundation, version 2 of the License.
  686.11 - *
  686.12 - * This program is distributed in the hope that it will be useful,
  686.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  686.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  686.15 - * GNU General Public License for more details.
  686.16 - *
  686.17 - * You should have received a copy of the GNU General Public License
  686.18 - * along with this program. Look for COPYING file in the top folder.
  686.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  686.20 - */
  686.21 -package org.apidesign.vm4brwsr;
  686.22 -
  686.23 -public interface GetByte {
  686.24 -    public byte getByte();
  686.25 -}
   687.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java	Mon Feb 25 19:00:08 2013 +0100
   687.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   687.3 @@ -1,140 +0,0 @@
   687.4 -/**
   687.5 - * Back 2 Browser Bytecode Translator
   687.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   687.7 - *
   687.8 - * This program is free software: you can redistribute it and/or modify
   687.9 - * it under the terms of the GNU General Public License as published by
  687.10 - * the Free Software Foundation, version 2 of the License.
  687.11 - *
  687.12 - * This program is distributed in the hope that it will be useful,
  687.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  687.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  687.15 - * GNU General Public License for more details.
  687.16 - *
  687.17 - * You should have received a copy of the GNU General Public License
  687.18 - * along with this program. Look for COPYING file in the top folder.
  687.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  687.20 - */
  687.21 -package org.apidesign.vm4brwsr;
  687.22 -
  687.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  687.24 -
  687.25 -/**
  687.26 - *
  687.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  687.28 - */
  687.29 -public class Instance {
  687.30 -    private int in;
  687.31 -    protected short s;
  687.32 -    public double d;
  687.33 -    private float f;
  687.34 -    protected byte b = (byte)31;
  687.35 -    
  687.36 -    private Instance() {
  687.37 -    }
  687.38 -
  687.39 -    public Instance(int i, double d) {
  687.40 -        this.in = i;
  687.41 -        this.d = d;
  687.42 -    }
  687.43 -    public byte getByte() {
  687.44 -        return b;
  687.45 -    }
  687.46 -    
  687.47 -    public void setByte(byte b) {
  687.48 -        this.b = b;
  687.49 -    }
  687.50 -    public static double defaultDblValue() {
  687.51 -        Instance create = new Instance();
  687.52 -        return create.d;
  687.53 -    }
  687.54 -    
  687.55 -    public static byte assignedByteValue() {
  687.56 -        return new Instance().b;
  687.57 -    }
  687.58 -    public static double magicOne() {
  687.59 -        Instance i = new Instance(10, 3.3d);
  687.60 -        i.b = (byte)0x09;
  687.61 -        return (i.in - i.b) * i.d;
  687.62 -    }
  687.63 -    public static int virtualBytes() {
  687.64 -        Instance i = new InstanceSub(7, 2.2d);
  687.65 -        i.setByte((byte)0x0a);
  687.66 -        Instance i2 = new Instance(3, 333.0d);
  687.67 -        i2.setByte((byte)44);
  687.68 -        return i.getByte() + i2.getByte();
  687.69 -    }
  687.70 -    public static float interfaceBytes() {
  687.71 -        GetByte i = new InstanceSub(7, 2.2d);
  687.72 -        return i.getByte();
  687.73 -    }
  687.74 -    public static boolean instanceOf(int sub) {
  687.75 -        Instance i = createInstance(sub);
  687.76 -        return isInstanceSubOf(i);
  687.77 -    }
  687.78 -    public static int castsWork(boolean interfc) {
  687.79 -        Instance i = createInstance(2);
  687.80 -        if (interfc) {
  687.81 -            GetByte b = (GetByte)i;
  687.82 -        } else {
  687.83 -            InstanceSub s = (InstanceSub)i;
  687.84 -        }
  687.85 -        return 5;
  687.86 -    }
  687.87 -    
  687.88 -    private static boolean isInstanceSubOf(Instance instance) {
  687.89 -        return instance instanceof InstanceSub;
  687.90 -    }
  687.91 -    private static Instance createInstance(int type) {
  687.92 -        switch (type) {
  687.93 -            case 0: return null;
  687.94 -            case 1: return new Instance();
  687.95 -            case 2: return new InstanceSub(3, 0);
  687.96 -        }
  687.97 -        throw new IllegalArgumentException();
  687.98 -    }
  687.99 -    private static boolean isNull() {
 687.100 -        return createInstance(2) == null;
 687.101 -    }
 687.102 -    
 687.103 -    @JavaScriptBody(args = "obj", body = "return obj.constructor;")
 687.104 -    static Object constructor(Object obj) {
 687.105 -        return obj;
 687.106 -    }
 687.107 -    
 687.108 -    public static boolean sharedConstructor() {
 687.109 -        class X {
 687.110 -        }
 687.111 -        
 687.112 -        X x1 = new X();
 687.113 -        X x2 = new X();
 687.114 -        
 687.115 -        return constructor(x1) == constructor(x2);
 687.116 -    }
 687.117 -    public static boolean differentConstructor() {
 687.118 -        class X {
 687.119 -        }
 687.120 -        class Y {
 687.121 -        }
 687.122 -        
 687.123 -        X x = new X();
 687.124 -        Y y = new Y();
 687.125 -        
 687.126 -        return constructor(x) == constructor(y);
 687.127 -    }
 687.128 -    @JavaScriptBody(args = {}, body = "return {};")
 687.129 -    private static Object jsObj() {
 687.130 -        return null;
 687.131 -    }
 687.132 -    
 687.133 -    public static boolean iofObject() {
 687.134 -        return jsObj() instanceof Object;
 687.135 -    }
 687.136 -    
 687.137 -    public static int jscall() {
 687.138 -        return jsgetbytes(new Instance());
 687.139 -    }
 687.140 -    
 687.141 -    @JavaScriptBody(args = { "instance" }, body = "return instance.getByte__B();")
 687.142 -    private static native int jsgetbytes(Instance instance);
 687.143 -}
   688.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSub.java	Mon Feb 25 19:00:08 2013 +0100
   688.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   688.3 @@ -1,40 +0,0 @@
   688.4 -/**
   688.5 - * Back 2 Browser Bytecode Translator
   688.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   688.7 - *
   688.8 - * This program is free software: you can redistribute it and/or modify
   688.9 - * it under the terms of the GNU General Public License as published by
  688.10 - * the Free Software Foundation, version 2 of the License.
  688.11 - *
  688.12 - * This program is distributed in the hope that it will be useful,
  688.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  688.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  688.15 - * GNU General Public License for more details.
  688.16 - *
  688.17 - * You should have received a copy of the GNU General Public License
  688.18 - * along with this program. Look for COPYING file in the top folder.
  688.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  688.20 - */
  688.21 -package org.apidesign.vm4brwsr;
  688.22 -
  688.23 -/**
  688.24 - *
  688.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  688.26 - */
  688.27 -public class InstanceSub extends Instance implements GetByte {
  688.28 -    private double in;
  688.29 -    
  688.30 -    public InstanceSub(int i, double d) {
  688.31 -        super(i, d);
  688.32 -        in = 555.55;
  688.33 -    }
  688.34 -    
  688.35 -    @Override
  688.36 -    public void setByte(byte b) {
  688.37 -        super.setByte((byte) (b + 1));
  688.38 -    }
  688.39 -    
  688.40 -    public static double recallDbl() {
  688.41 -        return defaultDblValue();
  688.42 -    }
  688.43 -}
   689.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceSubTest.java	Mon Feb 25 19:00:08 2013 +0100
   689.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   689.3 @@ -1,32 +0,0 @@
   689.4 -/**
   689.5 - * Back 2 Browser Bytecode Translator
   689.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   689.7 - *
   689.8 - * This program is free software: you can redistribute it and/or modify
   689.9 - * it under the terms of the GNU General Public License as published by
  689.10 - * the Free Software Foundation, version 2 of the License.
  689.11 - *
  689.12 - * This program is distributed in the hope that it will be useful,
  689.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  689.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  689.15 - * GNU General Public License for more details.
  689.16 - *
  689.17 - * You should have received a copy of the GNU General Public License
  689.18 - * along with this program. Look for COPYING file in the top folder.
  689.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  689.20 - */
  689.21 -package org.apidesign.vm4brwsr;
  689.22 -
  689.23 -/** Checks if everything works OK, when we switch the
  689.24 - * order of loaded classes.
  689.25 - * 
  689.26 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  689.27 - */
  689.28 -public class InstanceSubTest extends InstanceTest {
  689.29 -
  689.30 -    @Override
  689.31 -    protected String startCompilationWith() {
  689.32 -        return "org/apidesign/vm4brwsr/InstanceSub";
  689.33 -    }
  689.34 -    
  689.35 -}
   690.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java	Mon Feb 25 19:00:08 2013 +0100
   690.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   690.3 @@ -1,166 +0,0 @@
   690.4 -/**
   690.5 - * Back 2 Browser Bytecode Translator
   690.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   690.7 - *
   690.8 - * This program is free software: you can redistribute it and/or modify
   690.9 - * it under the terms of the GNU General Public License as published by
  690.10 - * the Free Software Foundation, version 2 of the License.
  690.11 - *
  690.12 - * This program is distributed in the hope that it will be useful,
  690.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  690.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  690.15 - * GNU General Public License for more details.
  690.16 - *
  690.17 - * You should have received a copy of the GNU General Public License
  690.18 - * along with this program. Look for COPYING file in the top folder.
  690.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  690.20 - */
  690.21 -package org.apidesign.vm4brwsr;
  690.22 -
  690.23 -import org.testng.annotations.Test;
  690.24 -import org.testng.annotations.BeforeClass;
  690.25 -
  690.26 -/**
  690.27 - *
  690.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  690.29 - */
  690.30 -public class InstanceTest {
  690.31 -    @Test public void verifyDefaultDoubleValue() throws Exception {
  690.32 -        assertExec(
  690.33 -            "Will be zero",
  690.34 -            Instance.class, "defaultDblValue__D",
  690.35 -            Double.valueOf(0)
  690.36 -        );
  690.37 -    }
  690.38 -    @Test public void verifyStaticMethodCall() throws Exception {
  690.39 -        assertExec(
  690.40 -            "Will be zero",
  690.41 -            InstanceSub.class, "recallDbl__D",
  690.42 -            Double.valueOf(0)
  690.43 -        );
  690.44 -    }
  690.45 -    @Test public void verifyAssignedByteValue() throws Exception {
  690.46 -        assertExec(
  690.47 -            "Will one thirty one",
  690.48 -            Instance.class, "assignedByteValue__B",
  690.49 -            Double.valueOf(31)
  690.50 -        );
  690.51 -    }
  690.52 -    @Test public void verifyMagicOne() throws Exception {
  690.53 -        assertExec(
  690.54 -            "Should be three and something",
  690.55 -            Instance.class, "magicOne__D",
  690.56 -            Double.valueOf(3.3)
  690.57 -        );
  690.58 -    }
  690.59 -    @Test public void verifyInstanceMethods() throws Exception {
  690.60 -        assertExec(
  690.61 -            "Should be eleven as we invoke overwritten method, plus 44",
  690.62 -            Instance.class, "virtualBytes__I",
  690.63 -            Double.valueOf(55)
  690.64 -        );
  690.65 -    }
  690.66 -    @Test public void verifyInterfaceMethods() throws Exception {
  690.67 -        assertExec(
  690.68 -            "Retruns default value",
  690.69 -            Instance.class, "interfaceBytes__F",
  690.70 -            Double.valueOf(31)
  690.71 -        );
  690.72 -    }
  690.73 -
  690.74 -    @Test public void isNull() throws Exception {
  690.75 -        assertExec(
  690.76 -            "Yes, we are instance",
  690.77 -            Instance.class, "isNull__Z",
  690.78 -            Double.valueOf(0.0)
  690.79 -        );
  690.80 -    }
  690.81 -
  690.82 -    @Test public void isInstanceOf() throws Exception {
  690.83 -        assertExec(
  690.84 -            "Yes, we are instance",
  690.85 -            Instance.class, "instanceOf__ZI",
  690.86 -            Double.valueOf(1.0), 2
  690.87 -        );
  690.88 -    }
  690.89 -
  690.90 -    @Test public void notInstanceOf() throws Exception {
  690.91 -        assertExec(
  690.92 -            "No, we are not an instance",
  690.93 -            Instance.class, "instanceOf__ZI",
  690.94 -            Double.valueOf(0.0), 1
  690.95 -        );
  690.96 -    }
  690.97 -    @Test public void nullInstanceOf() throws Exception {
  690.98 -        assertExec(
  690.99 -            "No, null is not an instance",
 690.100 -            Instance.class, "instanceOf__ZI",
 690.101 -            Double.valueOf(0.0), 0
 690.102 -        );
 690.103 -    }
 690.104 -    
 690.105 -    @Test public void verifyCastToClass() throws Exception {
 690.106 -        assertExec(
 690.107 -            "Five signals all is good",
 690.108 -            Instance.class, "castsWork__IZ",
 690.109 -            Double.valueOf(5.0), false
 690.110 -        );
 690.111 -    }
 690.112 -    @Test public void verifyCastToInterface() throws Exception {
 690.113 -        assertExec(
 690.114 -            "Five signals all is good",
 690.115 -            Instance.class, "castsWork__IZ",
 690.116 -            Double.valueOf(5.0), true
 690.117 -        );
 690.118 -    }
 690.119 -    
 690.120 -    @Test public void sharedConstructor() throws Exception {
 690.121 -        assertExec(
 690.122 -            "Constructor of first and 2nd instance should be the same",
 690.123 -            Instance.class, "sharedConstructor__Z",
 690.124 -            Double.valueOf(1.0)
 690.125 -        );
 690.126 -    }
 690.127 -
 690.128 -    @Test public void differentConstructor() throws Exception {
 690.129 -        assertExec(
 690.130 -            "Constructor of X and Y should be the different",
 690.131 -            Instance.class, "differentConstructor__Z",
 690.132 -            Double.valueOf(0)
 690.133 -        );
 690.134 -    }
 690.135 -
 690.136 -    @Test public void jsObjectIsLikeJavaObject() throws Exception {
 690.137 -        assertExec(
 690.138 -            "JavaScript object is instance of Java Object",
 690.139 -            Instance.class, "iofObject__Z",
 690.140 -            Double.valueOf(1)
 690.141 -        );
 690.142 -    }
 690.143 -
 690.144 -    @Test public void jsCallingConvention() throws Exception {
 690.145 -        assertExec(
 690.146 -            "Pointer to 'this' is passed automatically (and not as a first argument)",
 690.147 -            Instance.class, "jscall__I",
 690.148 -            Double.valueOf(31)
 690.149 -        );
 690.150 -    }
 690.151 -    
 690.152 -    protected String startCompilationWith() {
 690.153 -        return "org/apidesign/vm4brwsr/Instance";
 690.154 -    }
 690.155 -    
 690.156 -    private static TestVM code;
 690.157 -    
 690.158 -    @BeforeClass
 690.159 -    public void compileTheCode() throws Exception {
 690.160 -        code = TestVM.compileClass(startCompilationWith());
 690.161 -    }
 690.162 -    
 690.163 -    private void assertExec(
 690.164 -        String msg, Class clazz, String method, Object expRes, Object... args
 690.165 -    ) throws Exception {
 690.166 -        code.assertExec(msg, clazz, method, expRes, args);
 690.167 -    }
 690.168 -    
 690.169 -}
   691.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Mon Feb 25 19:00:08 2013 +0100
   691.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   691.3 @@ -1,169 +0,0 @@
   691.4 -/**
   691.5 - * Back 2 Browser Bytecode Translator
   691.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   691.7 - *
   691.8 - * This program is free software: you can redistribute it and/or modify
   691.9 - * it under the terms of the GNU General Public License as published by
  691.10 - * the Free Software Foundation, version 2 of the License.
  691.11 - *
  691.12 - * This program is distributed in the hope that it will be useful,
  691.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  691.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  691.15 - * GNU General Public License for more details.
  691.16 - *
  691.17 - * You should have received a copy of the GNU General Public License
  691.18 - * along with this program. Look for COPYING file in the top folder.
  691.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  691.20 - */
  691.21 -package org.apidesign.vm4brwsr;
  691.22 -
  691.23 -import static org.testng.Assert.*;
  691.24 -import org.testng.annotations.BeforeClass;
  691.25 -import org.testng.annotations.Test;
  691.26 -
  691.27 -/**
  691.28 - *
  691.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  691.30 - */
  691.31 -public class NumberTest {
  691.32 -    @Test public void integerFromString() throws Exception {
  691.33 -        assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2",
  691.34 -            Double.valueOf(333), "333"
  691.35 -        );
  691.36 -    }
  691.37 -
  691.38 -    @Test public void doubleFromString() throws Exception {
  691.39 -        assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2",
  691.40 -            Double.valueOf(33.3), "33.3"
  691.41 -        );
  691.42 -    }
  691.43 -
  691.44 -    @Test public void autoboxDouble() throws Exception {
  691.45 -        assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2",
  691.46 -            "3.3"
  691.47 -        );
  691.48 -    }
  691.49 -    
  691.50 -    @Test public void javalog1000() throws Exception {
  691.51 -        assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3");
  691.52 -    }
  691.53 -
  691.54 -    @Test public void jslog1000() throws Exception {
  691.55 -        assertExec("log_10(1000) == 3", Math.class, "log10__DD", 
  691.56 -            Double.valueOf(3.0), 1000.0
  691.57 -        );
  691.58 -    }
  691.59 -    
  691.60 -    @Test public void javaRem() {
  691.61 -        assertEquals(3, Numbers.rem(303, 10));
  691.62 -    }
  691.63 -    @Test public void jsRem() throws Exception {
  691.64 -        assertExec("Should be three", Numbers.class, "rem__III", 
  691.65 -            Double.valueOf(3.0), 303, 10
  691.66 -        );
  691.67 -    }
  691.68 -    
  691.69 -    @Test public void deserializeInt() throws Exception {
  691.70 -        int exp = Numbers.deserInt();
  691.71 -        assertExec("Should be the same", Numbers.class, "deserInt__I", 
  691.72 -            Double.valueOf(exp)
  691.73 -        );
  691.74 -    }
  691.75 -
  691.76 -    @Test public void deserializeSimpleLong() throws Exception {
  691.77 -        assertExec("Should be 3454", Numbers.class, "deserLong__J_3B", 
  691.78 -            Double.valueOf(3454), 
  691.79 -            new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
  691.80 -        );
  691.81 -    }
  691.82 -    /* XXX: JavaScript cannot represent as big longs as Java. 
  691.83 -    @Test public void deserializeLargeLong() throws Exception {
  691.84 -        final byte[] arr = new byte[] {
  691.85 -            (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
  691.86 -        };
  691.87 -        long exp = Numbers.deserLong(arr);
  691.88 -        assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB", 
  691.89 -            Double.valueOf(exp), arr);
  691.90 -    }
  691.91 -    */
  691.92 -    
  691.93 -    @Test public void deserializeFloatInJava() throws Exception {
  691.94 -        float f = 54324.32423f;
  691.95 -        float r = Numbers.deserFloat();
  691.96 -        assertEquals(r, f, "Floats are the same");
  691.97 -    }
  691.98 -    
  691.99 -    @Test public void deserializeFloatInJS() throws Exception {
 691.100 -        float f = 54324.32423f;
 691.101 -        assertExec("Should be the same", Numbers.class, "deserFloat__F", 
 691.102 -            Double.valueOf(f)
 691.103 -        );
 691.104 -    }
 691.105 -
 691.106 -    @Test public void deserializeDoubleInJava() throws Exception {
 691.107 -        double f = 3.0;
 691.108 -        double r = Numbers.deserDouble();
 691.109 -        assertEquals(r, f, 0.001, "Doubles are the same");
 691.110 -    }
 691.111 -    
 691.112 -    @Test public void deserializeDoubleInJS() throws Exception {
 691.113 -        double f = 3.0;
 691.114 -        assertExec("Should be the same", Numbers.class, "deserDouble__D", f);
 691.115 -    }
 691.116 -    /*
 691.117 -    @Test public void serDouble() throws IOException {
 691.118 -        double f = 3.0;
 691.119 -        ByteArrayOutputStream os = new ByteArrayOutputStream();
 691.120 -        DataOutputStream d = new DataOutputStream(os);
 691.121 -        d.writeLong(3454);
 691.122 -        d.close();
 691.123 -        
 691.124 -        StringBuilder sb = new StringBuilder();
 691.125 -        byte[] arr = os.toByteArray();
 691.126 -        for (int i = 0; i < arr.length; i++) {
 691.127 -            sb.append("(byte)").append(arr[i]).append(", ");
 691.128 -        }
 691.129 -        fail("" + sb);
 691.130 -    }
 691.131 -*/    
 691.132 -    @Test public void fiveInStringJS() throws Exception {
 691.133 -        String s = Numbers.intToString();
 691.134 -        assertExec("Should be the same: " + s, 
 691.135 -            Numbers.class, "intToString__Ljava_lang_String_2", 
 691.136 -            s
 691.137 -        );
 691.138 -    }
 691.139 -
 691.140 -    @Test public void sevenInStringJS() throws Exception {
 691.141 -        String s = Numbers.floatToString();
 691.142 -        assertExec("Should be the same: " + s, 
 691.143 -            Numbers.class, "floatToString__Ljava_lang_String_2", 
 691.144 -            s
 691.145 -        );
 691.146 -    }
 691.147 -
 691.148 -    private static TestVM code;
 691.149 -
 691.150 -    @BeforeClass
 691.151 -    public void compileTheCode() throws Exception {
 691.152 -        code = TestVM.compileClass("org/apidesign/vm4brwsr/Numbers");
 691.153 -    }
 691.154 -
 691.155 -    private static void assertExec(
 691.156 -        String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception
 691.157 -    {
 691.158 -        Object ret = code.execCode(msg, clazz, method, expRes, args);
 691.159 -        if (ret == null) {
 691.160 -            return;
 691.161 -        }
 691.162 -        if (expRes instanceof Double && ret instanceof Double) {
 691.163 -            double expD = ((Double)expRes).doubleValue();
 691.164 -            double retD = ((Double)ret).doubleValue();
 691.165 -            assertEquals(retD, expD, 0.000004, msg + " "
 691.166 -                    + code.toString());
 691.167 -            return;
 691.168 -        }
 691.169 -        assertEquals(ret, expRes, msg + " " + code.toString());
 691.170 -    }
 691.171 -    
 691.172 -}
   692.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Mon Feb 25 19:00:08 2013 +0100
   692.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   692.3 @@ -1,70 +0,0 @@
   692.4 -/**
   692.5 - * Back 2 Browser Bytecode Translator
   692.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   692.7 - *
   692.8 - * This program is free software: you can redistribute it and/or modify
   692.9 - * it under the terms of the GNU General Public License as published by
  692.10 - * the Free Software Foundation, version 2 of the License.
  692.11 - *
  692.12 - * This program is distributed in the hope that it will be useful,
  692.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  692.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  692.15 - * GNU General Public License for more details.
  692.16 - *
  692.17 - * You should have received a copy of the GNU General Public License
  692.18 - * along with this program. Look for COPYING file in the top folder.
  692.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  692.20 - */
  692.21 -package org.apidesign.vm4brwsr;
  692.22 -
  692.23 -import java.io.ByteArrayInputStream;
  692.24 -import java.io.DataInputStream;
  692.25 -import java.io.IOException;
  692.26 -
  692.27 -/**
  692.28 - *
  692.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  692.30 - */
  692.31 -public class Numbers {
  692.32 -    private static Double autoboxDbl() {
  692.33 -        return 3.3;
  692.34 -    }
  692.35 -    public static String autoboxDblToString() {
  692.36 -        return autoboxDbl().toString().toString();
  692.37 -    }
  692.38 -    public static int rem(int a, int b) {
  692.39 -        return a % b;
  692.40 -    }
  692.41 -
  692.42 -    static float deserFloat() throws IOException {
  692.43 -        byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
  692.44 -        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  692.45 -        DataInputStream dis = new DataInputStream(is);
  692.46 -        float r = dis.readFloat();
  692.47 -        return r;
  692.48 -    }
  692.49 -    static double deserDouble() throws IOException {
  692.50 -        byte[] arr = {(byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
  692.51 -        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  692.52 -        DataInputStream dis = new DataInputStream(is);
  692.53 -        return dis.readDouble();
  692.54 -    }
  692.55 -    static long deserLong(byte[] arr) throws IOException {
  692.56 -        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  692.57 -        DataInputStream dis = new DataInputStream(is);
  692.58 -        return dis.readLong();
  692.59 -    }
  692.60 -    static int deserInt() throws IOException {
  692.61 -        byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
  692.62 -        ByteArrayInputStream is = new ByteArrayInputStream(arr);
  692.63 -        DataInputStream dis = new DataInputStream(is);
  692.64 -        return dis.readInt();
  692.65 -    }
  692.66 -
  692.67 -    static String intToString() {
  692.68 -        return new Integer(5).toString().toString();
  692.69 -    }
  692.70 -    static String floatToString() {
  692.71 -        return new Float(7.0).toString().toString();
  692.72 -    }
  692.73 -}
   693.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Script.java	Mon Feb 25 19:00:08 2013 +0100
   693.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   693.3 @@ -1,31 +0,0 @@
   693.4 -/**
   693.5 - * Back 2 Browser Bytecode Translator
   693.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   693.7 - *
   693.8 - * This program is free software: you can redistribute it and/or modify
   693.9 - * it under the terms of the GNU General Public License as published by
  693.10 - * the Free Software Foundation, version 2 of the License.
  693.11 - *
  693.12 - * This program is distributed in the hope that it will be useful,
  693.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  693.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  693.15 - * GNU General Public License for more details.
  693.16 - *
  693.17 - * You should have received a copy of the GNU General Public License
  693.18 - * along with this program. Look for COPYING file in the top folder.
  693.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  693.20 - */
  693.21 -package org.apidesign.vm4brwsr;
  693.22 -
  693.23 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
  693.24 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  693.25 -
  693.26 -/** Test to verify external scripts are processed in lazy mode.
  693.27 - *
  693.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  693.29 - */
  693.30 -@ExtraJavaScript(resource = "/org/apidesign/vm4brwsr/ko.js")
  693.31 -public class Script {
  693.32 -    @JavaScriptBody(args = {  }, body = "return ko !== null;")
  693.33 -    public static native boolean checkNotNull();
  693.34 -}
   694.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Mon Feb 25 19:00:08 2013 +0100
   694.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   694.3 @@ -1,135 +0,0 @@
   694.4 -/**
   694.5 - * Back 2 Browser Bytecode Translator
   694.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   694.7 - *
   694.8 - * This program is free software: you can redistribute it and/or modify
   694.9 - * it under the terms of the GNU General Public License as published by
  694.10 - * the Free Software Foundation, version 2 of the License.
  694.11 - *
  694.12 - * This program is distributed in the hope that it will be useful,
  694.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  694.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  694.15 - * GNU General Public License for more details.
  694.16 - *
  694.17 - * You should have received a copy of the GNU General Public License
  694.18 - * along with this program. Look for COPYING file in the top folder.
  694.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  694.20 - */
  694.21 -package org.apidesign.vm4brwsr;
  694.22 -
  694.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  694.24 -
  694.25 -/**
  694.26 - *
  694.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  694.28 - */
  694.29 -public class StaticMethod {
  694.30 -    private static int cnt;
  694.31 -    private static Object NULL;
  694.32 -
  694.33 -    public static int minusOne() {
  694.34 -        return -1;
  694.35 -    }
  694.36 -    
  694.37 -    public static Object none(int x, int y) {
  694.38 -        Object toRet = null;
  694.39 -        for (int i = x; i < y; i++) {
  694.40 -            if (i == 2) {
  694.41 -                toRet = null;
  694.42 -            } else {
  694.43 -                toRet = new Object();
  694.44 -            }
  694.45 -        }
  694.46 -        return toRet;
  694.47 -    }
  694.48 -    
  694.49 -    public static boolean isNull() {
  694.50 -        return NULL == null;
  694.51 -    }
  694.52 -    
  694.53 -    public static int sum(int x, int y) {
  694.54 -        return x + y;
  694.55 -    }
  694.56 -    public static float power(float x) {
  694.57 -        return x * x;
  694.58 -    }
  694.59 -    public static double minus(double x, long y) {
  694.60 -        return x - y;
  694.61 -    }
  694.62 -    public static int div(byte c, double d) {
  694.63 -        return (int)(d / c);
  694.64 -    }
  694.65 -    public static int mix(int a, long b, byte c, double d) {
  694.66 -        return (int)((b / a + c) * d);
  694.67 -    }
  694.68 -    public static long xor(int a, long b) {
  694.69 -        return a ^ b;
  694.70 -    }
  694.71 -    public static long orOrAnd(boolean doOr, int a, int b) {
  694.72 -        return doOr ? a | b : a & b;
  694.73 -    }
  694.74 -    public static int shiftLeft(int what, int much) {
  694.75 -        return what << much;
  694.76 -    }
  694.77 -    public static int shiftArithmRight(int what, int much, boolean signed) {
  694.78 -        if (signed) {
  694.79 -            return what >> much;
  694.80 -        } else {
  694.81 -            return what >>> much;
  694.82 -        }
  694.83 -    }
  694.84 -    public static long factRec(int n) {
  694.85 -        if (n <= 1) {
  694.86 -            return 1;
  694.87 -        } else {
  694.88 -            return n * factRec(n - 1);
  694.89 -        }
  694.90 -    }
  694.91 -    public static long factIter(int n) {
  694.92 -        long res = 1;
  694.93 -        for (int i = 2; i <= n; i++) {
  694.94 -            res *= i;
  694.95 -        }
  694.96 -        return res;
  694.97 -    }
  694.98 -    public static int inc4() {
  694.99 -        cnt++;
 694.100 -        cnt+=2;
 694.101 -        cnt++;
 694.102 -        return cnt;
 694.103 -    }
 694.104 -    
 694.105 -    @JavaScriptBody(
 694.106 -        args={"i","j"}, body="\n\r\treturn (i + j).toString();"
 694.107 -    )
 694.108 -    public static String i2s(int i, int j) {
 694.109 -        throw new IllegalStateException();
 694.110 -    }
 694.111 -    
 694.112 -    public static String castNull(boolean n) {
 694.113 -        Object value = n ? null : "Ahoj";
 694.114 -        return (String)value;
 694.115 -    }
 694.116 -    
 694.117 -    public static String swtch(int what) {
 694.118 -        switch (what) {
 694.119 -            case 0: return "Jarda";
 694.120 -            case 1: return "Darda";
 694.121 -            case 2: return "Parda";
 694.122 -            default: return "Marda";
 694.123 -        }
 694.124 -    }
 694.125 -    public static String swtch2(int what) {
 694.126 -        switch (what) {
 694.127 -            case 0: return "Jarda";
 694.128 -            case 11: return "Darda";
 694.129 -            case 22: return "Parda";
 694.130 -            default: return "Marda";
 694.131 -        }
 694.132 -    }
 694.133 -    
 694.134 -    static {
 694.135 -        // check order of initializers
 694.136 -        StaticUse.NON_NULL.equals(new Object());
 694.137 -    }
 694.138 -}
   695.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Mon Feb 25 19:00:08 2013 +0100
   695.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   695.3 @@ -1,338 +0,0 @@
   695.4 -/**
   695.5 - * Back 2 Browser Bytecode Translator
   695.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   695.7 - *
   695.8 - * This program is free software: you can redistribute it and/or modify
   695.9 - * it under the terms of the GNU General Public License as published by
  695.10 - * the Free Software Foundation, version 2 of the License.
  695.11 - *
  695.12 - * This program is distributed in the hope that it will be useful,
  695.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  695.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  695.15 - * GNU General Public License for more details.
  695.16 - *
  695.17 - * You should have received a copy of the GNU General Public License
  695.18 - * along with this program. Look for COPYING file in the top folder.
  695.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  695.20 - */
  695.21 -package org.apidesign.vm4brwsr;
  695.22 -
  695.23 -import static org.testng.Assert.*;
  695.24 -import org.testng.annotations.BeforeClass;
  695.25 -import org.testng.annotations.Test;
  695.26 -
  695.27 -/** Checks the basic behavior of the translator.
  695.28 - *
  695.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  695.30 - */
  695.31 -public class StaticMethodTest {
  695.32 -    @Test public void threePlusFour() throws Exception {
  695.33 -        assertExec(
  695.34 -            "Should be seven", 
  695.35 -            StaticMethod.class, "sum__III", 
  695.36 -            Double.valueOf(7), 
  695.37 -            3, 4
  695.38 -        );
  695.39 -    }
  695.40 -
  695.41 -    @Test public void checkReallyInitializedValues() throws Exception {
  695.42 -        assertExec(
  695.43 -            "Return true", 
  695.44 -            StaticMethod.class, "isNull__Z", 
  695.45 -            Double.valueOf(1)
  695.46 -        );
  695.47 -    }
  695.48 -
  695.49 -    @Test public void powerOfThree() throws Exception {
  695.50 -        assertExec(
  695.51 -            "Should be nine", 
  695.52 -            StaticMethod.class, "power__FF", 
  695.53 -            Double.valueOf(9),
  695.54 -            3.0f
  695.55 -        );
  695.56 -    }
  695.57 -
  695.58 -    @Test public void minusOne() throws Exception {
  695.59 -        assertExec(
  695.60 -            "Should be minus one", 
  695.61 -            StaticMethod.class, "minusOne__I", 
  695.62 -            Double.valueOf(-1)
  695.63 -        );
  695.64 -    }
  695.65 -
  695.66 -    @Test public void doubleWithoutLong() throws Exception {
  695.67 -        assertExec(
  695.68 -            "Should be two",
  695.69 -            StaticMethod.class, "minus__DDJ", 
  695.70 -            Double.valueOf(2),
  695.71 -            3.0d, 1l
  695.72 -        );
  695.73 -    }
  695.74 -    
  695.75 -    @Test public void rintNegativeUp() throws Exception {
  695.76 -        final double cnts = -453904.634;
  695.77 -        assertExec(
  695.78 -            "Should round up to end with 5",
  695.79 -            Math.class, "rint__DD", 
  695.80 -            -453905.0, cnts
  695.81 -        );
  695.82 -    }
  695.83 -
  695.84 -    @Test public void rintNegativeDown() throws Exception {
  695.85 -        final double cnts = -453904.434;
  695.86 -        assertExec(
  695.87 -            "Should round up to end with 4",
  695.88 -            Math.class, "rint__DD", 
  695.89 -            -453904.0, cnts
  695.90 -        );
  695.91 -    }
  695.92 -
  695.93 -    @Test public void rintPositiveUp() throws Exception {
  695.94 -        final double cnts = 453904.634;
  695.95 -        assertExec(
  695.96 -            "Should round up to end with 5",
  695.97 -            Math.class, "rint__DD", 
  695.98 -            453905.0, cnts
  695.99 -        );
 695.100 -    }
 695.101 -    @Test public void rintPositiveDown() throws Exception {
 695.102 -        final double cnts = 453904.434;
 695.103 -        assertExec(
 695.104 -            "Should round up to end with 4",
 695.105 -            Math.class, "rint__DD", 
 695.106 -            453904.0, cnts
 695.107 -        );
 695.108 -    }
 695.109 -    @Test public void rintOneHalf() throws Exception {
 695.110 -        final double cnts = 1.5;
 695.111 -        assertExec(
 695.112 -            "Should round up to end with 2",
 695.113 -            Math.class, "rint__DD", 
 695.114 -            2.0, cnts
 695.115 -        );
 695.116 -    }
 695.117 -    @Test public void rintNegativeOneHalf() throws Exception {
 695.118 -        final double cnts = -1.5;
 695.119 -        assertExec(
 695.120 -            "Should round up to end with 2",
 695.121 -            Math.class, "rint__DD", 
 695.122 -            -2.0, cnts
 695.123 -        );
 695.124 -    }
 695.125 -    @Test public void rintTwoAndHalf() throws Exception {
 695.126 -        final double cnts = 2.5;
 695.127 -        assertExec(
 695.128 -            "Should round up to end with 2",
 695.129 -            Math.class, "rint__DD", 
 695.130 -            2.0, cnts
 695.131 -        );
 695.132 -    }
 695.133 -    @Test public void rintNegativeTwoOneHalf() throws Exception {
 695.134 -        final double cnts = -2.5;
 695.135 -        assertExec(
 695.136 -            "Should round up to end with 2",
 695.137 -            Math.class, "rint__DD", 
 695.138 -            -2.0, cnts
 695.139 -        );
 695.140 -    }
 695.141 -
 695.142 -    @Test public void ieeeReminder1() throws Exception {
 695.143 -        assertExec(
 695.144 -            "Same result 1",
 695.145 -            Math.class, "IEEEremainder__DDD", 
 695.146 -            Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
 695.147 -        );
 695.148 -    }
 695.149 -
 695.150 -    @Test public void ieeeReminder2() throws Exception {
 695.151 -        assertExec(
 695.152 -            "Same result 1",
 695.153 -            Math.class, "IEEEremainder__DDD", 
 695.154 -            Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
 695.155 -        );
 695.156 -    }
 695.157 -
 695.158 -    @Test public void divAndRound() throws Exception {
 695.159 -        assertExec(
 695.160 -            "Should be rounded to one",
 695.161 -            StaticMethod.class, "div__IBD", 
 695.162 -            Double.valueOf(1),
 695.163 -            3, 3.75
 695.164 -        );
 695.165 -    }
 695.166 -    @Test public void mixedMethodFourParams() throws Exception {
 695.167 -        assertExec(
 695.168 -            "Should be two",
 695.169 -            StaticMethod.class, "mix__IIJBD", 
 695.170 -            Double.valueOf(20),
 695.171 -            2, 10l, 5, 2.0
 695.172 -        );
 695.173 -    }
 695.174 -    @Test public void factRec() throws Exception {
 695.175 -        assertExec(
 695.176 -            "Factorial of 5 is 120",
 695.177 -            StaticMethod.class, "factRec__JI", 
 695.178 -            Double.valueOf(120),
 695.179 -            5
 695.180 -        );
 695.181 -    }
 695.182 -    @Test public void factIter() throws Exception {
 695.183 -        assertExec(
 695.184 -            "Factorial of 5 is 120",
 695.185 -            StaticMethod.class, "factIter__JI", 
 695.186 -            Double.valueOf(120),
 695.187 -            5
 695.188 -        );
 695.189 -    }
 695.190 -    
 695.191 -    @Test public void xor() throws Exception {
 695.192 -        assertExec(
 695.193 -            "Xor is 4",
 695.194 -            StaticMethod.class, "xor__JIJ",
 695.195 -            Double.valueOf(4),
 695.196 -            7,
 695.197 -            3
 695.198 -        );
 695.199 -    }
 695.200 -    
 695.201 -    @Test public void or() throws Exception {
 695.202 -        assertExec(
 695.203 -            "Or will be 7",
 695.204 -            StaticMethod.class, "orOrAnd__JZII",
 695.205 -            Double.valueOf(7),
 695.206 -            true,
 695.207 -            4,
 695.208 -            3
 695.209 -        );
 695.210 -    }
 695.211 -    @Test public void nullCheck() throws Exception {
 695.212 -        assertExec(
 695.213 -            "Returns nothing",
 695.214 -            StaticMethod.class, "none__Ljava_lang_Object_2II",
 695.215 -            null, 1, 3
 695.216 -        );
 695.217 -    }
 695.218 -    @Test public void and() throws Exception {
 695.219 -        assertExec(
 695.220 -            "And will be 3",
 695.221 -            StaticMethod.class, "orOrAnd__JZII",
 695.222 -            Double.valueOf(3),
 695.223 -            false,
 695.224 -            7,
 695.225 -            3
 695.226 -        );
 695.227 -    }
 695.228 -    @Test public void inc4() throws Exception {
 695.229 -        assertExec(
 695.230 -            "It will be 4",
 695.231 -            StaticMethod.class, "inc4__I",
 695.232 -            Double.valueOf(4)
 695.233 -        );
 695.234 -    }
 695.235 -    
 695.236 -    @Test public void shiftLeftInJava() throws Exception {
 695.237 -        int res = StaticMethod.shiftLeft(1, 8);
 695.238 -        assertEquals(res, 256);
 695.239 -    }
 695.240 -
 695.241 -    @Test public void shiftLeftInJS() throws Exception {
 695.242 -        assertExec(
 695.243 -            "Setting 9th bit",
 695.244 -            StaticMethod.class, "shiftLeft__III",
 695.245 -            Double.valueOf(256),
 695.246 -            1, 8
 695.247 -        );
 695.248 -    }
 695.249 -
 695.250 -    @Test public void shiftRightInJava() throws Exception {
 695.251 -        int res = StaticMethod.shiftArithmRight(-8, 3, true);
 695.252 -        assertEquals(res, -1);
 695.253 -    }
 695.254 -
 695.255 -    @Test public void shiftRightInJS() throws Exception {
 695.256 -        assertExec(
 695.257 -            "Get -1",
 695.258 -            StaticMethod.class, "shiftArithmRight__IIIZ",
 695.259 -            Double.valueOf(-1),
 695.260 -            -8, 3, true
 695.261 -        );
 695.262 -    }
 695.263 -    @Test public void unsignedShiftRightInJava() throws Exception {
 695.264 -        int res = StaticMethod.shiftArithmRight(8, 3, false);
 695.265 -        assertEquals(res, 1);
 695.266 -    }
 695.267 -
 695.268 -    @Test public void unsignedShiftRightInJS() throws Exception {
 695.269 -        assertExec(
 695.270 -            "Get -1",
 695.271 -            StaticMethod.class, "shiftArithmRight__IIIZ",
 695.272 -            Double.valueOf(1),
 695.273 -            8, 3, false
 695.274 -        );
 695.275 -    }
 695.276 -    
 695.277 -    @Test public void javaScriptBody() throws Exception {
 695.278 -        assertExec(
 695.279 -            "JavaScript string",
 695.280 -            StaticMethod.class, "i2s__Ljava_lang_String_2II",
 695.281 -            "333",
 695.282 -            330, 3
 695.283 -        );
 695.284 -    }
 695.285 -    
 695.286 -    @Test public void switchJarda() throws Exception {
 695.287 -        assertExec(
 695.288 -            "The expected value",
 695.289 -            StaticMethod.class, "swtch__Ljava_lang_String_2I",
 695.290 -            "Jarda",
 695.291 -            0
 695.292 -        );
 695.293 -    }
 695.294 -    
 695.295 -    @Test public void switchDarda() throws Exception {
 695.296 -        assertExec(
 695.297 -            "The expected value",
 695.298 -            StaticMethod.class, "swtch__Ljava_lang_String_2I",
 695.299 -            "Darda",
 695.300 -            1
 695.301 -        );
 695.302 -    }
 695.303 -    @Test public void switchParda() throws Exception {
 695.304 -        assertExec(
 695.305 -            "The expected value",
 695.306 -            StaticMethod.class, "swtch2__Ljava_lang_String_2I",
 695.307 -            "Parda",
 695.308 -            22
 695.309 -        );
 695.310 -    }
 695.311 -    @Test public void switchMarda() throws Exception {
 695.312 -        assertExec(
 695.313 -            "The expected value",
 695.314 -            StaticMethod.class, "swtch__Ljava_lang_String_2I",
 695.315 -            "Marda",
 695.316 -            -433
 695.317 -        );
 695.318 -    }
 695.319 -    
 695.320 -    @Test public void checkNullCast() throws Exception {
 695.321 -        assertExec("Null can be cast to any type",
 695.322 -            StaticMethod.class, "castNull__Ljava_lang_String_2Z", 
 695.323 -            null, true
 695.324 -        );
 695.325 -    }
 695.326 -    
 695.327 -    private static TestVM code;
 695.328 -    
 695.329 -    @BeforeClass 
 695.330 -    public void compileTheCode() throws Exception {
 695.331 -        StringBuilder sb = new StringBuilder();
 695.332 -        code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
 695.333 -    }
 695.334 -
 695.335 -    private void assertExec(
 695.336 -        String msg, Class<?> clazz, String method, 
 695.337 -        Object ret, Object... args
 695.338 -    ) throws Exception {
 695.339 -        code.assertExec(msg, clazz, method, ret, args);
 695.340 -    }
 695.341 -}
   696.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticUse.java	Mon Feb 25 19:00:08 2013 +0100
   696.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   696.3 @@ -1,22 +0,0 @@
   696.4 -/**
   696.5 - * Back 2 Browser Bytecode Translator
   696.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   696.7 - *
   696.8 - * This program is free software: you can redistribute it and/or modify
   696.9 - * it under the terms of the GNU General Public License as published by
  696.10 - * the Free Software Foundation, version 2 of the License.
  696.11 - *
  696.12 - * This program is distributed in the hope that it will be useful,
  696.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  696.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  696.15 - * GNU General Public License for more details.
  696.16 - *
  696.17 - * You should have received a copy of the GNU General Public License
  696.18 - * along with this program. Look for COPYING file in the top folder.
  696.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  696.20 - */
  696.21 -package org.apidesign.vm4brwsr;
  696.22 -
  696.23 -public class StaticUse {
  696.24 -    public static final Object NON_NULL = new Object();
  696.25 -}
   697.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringArrayTest.java	Mon Feb 25 19:00:08 2013 +0100
   697.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   697.3 @@ -1,50 +0,0 @@
   697.4 -/**
   697.5 - * Back 2 Browser Bytecode Translator
   697.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   697.7 - *
   697.8 - * This program is free software: you can redistribute it and/or modify
   697.9 - * it under the terms of the GNU General Public License as published by
  697.10 - * the Free Software Foundation, version 2 of the License.
  697.11 - *
  697.12 - * This program is distributed in the hope that it will be useful,
  697.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  697.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  697.15 - * GNU General Public License for more details.
  697.16 - *
  697.17 - * You should have received a copy of the GNU General Public License
  697.18 - * along with this program. Look for COPYING file in the top folder.
  697.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  697.20 - */
  697.21 -package org.apidesign.vm4brwsr;
  697.22 -
  697.23 -import org.testng.annotations.Test;
  697.24 -import static org.testng.Assert.*;
  697.25 -
  697.26 -public class StringArrayTest {
  697.27 -    @Test public void deleteMinusIndex() throws Exception {
  697.28 -        String[] arr = { "Ahoj", "Kluci" };
  697.29 -        StringArray list = StringArray.asList(arr);
  697.30 -        list.delete(-1);
  697.31 -        assertEquals(list.toArray().length, 2, "No element removed");
  697.32 -    }
  697.33 -    @Test public void deleteTooHighIndex() throws Exception {
  697.34 -        String[] arr = { "Ahoj", "Kluci" };
  697.35 -        StringArray list = StringArray.asList(arr);
  697.36 -        list.delete(5);
  697.37 -        assertEquals(list.toArray().length, 2, "No element removed");
  697.38 -    }
  697.39 -    @Test public void deleteFirst() throws Exception {
  697.40 -        String[] arr = { "Ahoj", "Kluci" };
  697.41 -        StringArray list = StringArray.asList(arr);
  697.42 -        list.delete(0);
  697.43 -        assertEquals(list.toArray().length, 1, "First element removed");
  697.44 -        assertEquals(list.toArray()[0], "Kluci");
  697.45 -    }
  697.46 -    @Test public void deleteSecond() throws Exception {
  697.47 -        String[] arr = { "Ahoj", "Kluci" };
  697.48 -        StringArray list = StringArray.asList(arr);
  697.49 -        list.delete(1);
  697.50 -        assertEquals(list.toArray().length, 1, "Second element removed");
  697.51 -        assertEquals(list.toArray()[0], "Ahoj");
  697.52 -    }
  697.53 -}
   698.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Mon Feb 25 19:00:08 2013 +0100
   698.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   698.3 @@ -1,132 +0,0 @@
   698.4 -/**
   698.5 - * Back 2 Browser Bytecode Translator
   698.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   698.7 - *
   698.8 - * This program is free software: you can redistribute it and/or modify
   698.9 - * it under the terms of the GNU General Public License as published by
  698.10 - * the Free Software Foundation, version 2 of the License.
  698.11 - *
  698.12 - * This program is distributed in the hope that it will be useful,
  698.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  698.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  698.15 - * GNU General Public License for more details.
  698.16 - *
  698.17 - * You should have received a copy of the GNU General Public License
  698.18 - * along with this program. Look for COPYING file in the top folder.
  698.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  698.20 - */
  698.21 -package org.apidesign.vm4brwsr;
  698.22 -
  698.23 -import java.io.UnsupportedEncodingException;
  698.24 -
  698.25 -/**
  698.26 - *
  698.27 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  698.28 - */
  698.29 -public class StringSample {
  698.30 -    public static final String HELLO = "Hello World!";
  698.31 -    private static int counter;
  698.32 -    
  698.33 -    private final int cnt;
  698.34 -    public StringSample() {
  698.35 -        cnt = ++counter;
  698.36 -    }
  698.37 -    
  698.38 -    
  698.39 -    public static char sayHello(int indx) {
  698.40 -        return HELLO.charAt(indx);
  698.41 -    }
  698.42 -    
  698.43 -    public static boolean equalToHello(int from, int to) {
  698.44 -        return "Hello".equals(HELLO.substring(from, to));
  698.45 -    }
  698.46 -    
  698.47 -    public static String fromChars(char a, char b, char c) {
  698.48 -        char[] arr = { a, b, c };
  698.49 -        return new String(arr).toString();
  698.50 -    }
  698.51 -    
  698.52 -    public static String charsFromNumbers() {
  698.53 -        return chars((char)65, (char)66, (char)67);
  698.54 -    }
  698.55 -
  698.56 -    public static String charsFromChars() {
  698.57 -        return chars('A', 'B', 'C');
  698.58 -    }
  698.59 -
  698.60 -    public static String chars(char a, char b, char c) {
  698.61 -        return ("" + a + b +c).toString();
  698.62 -    }
  698.63 -    
  698.64 -    public static String replace(String s, char a, char b) {
  698.65 -        return s.replace(a, b);
  698.66 -    }
  698.67 -    
  698.68 -    public static int hashCode(String h) {
  698.69 -        return h.hashCode();
  698.70 -    }
  698.71 -    
  698.72 -    public static boolean isStringInstance() {
  698.73 -        return chars('a', (char)30, 'b') instanceof String;
  698.74 -    }
  698.75 -    
  698.76 -    public static String getBytes(String s) throws UnsupportedEncodingException {
  698.77 -        byte[] arr = s.getBytes("UTF-8");
  698.78 -        StringBuilder sb = new StringBuilder();
  698.79 -        for (int i = 0; i < arr.length; i++) {
  698.80 -            sb.append(arr[i]).append(" ");
  698.81 -        }
  698.82 -        return sb.toString().toString();
  698.83 -    }
  698.84 -    
  698.85 -    public static String insertBuffer() {
  698.86 -        StringBuilder sb = new StringBuilder();
  698.87 -        sb.append("Jardo!");
  698.88 -        sb.insert(0, "Ahoj ");
  698.89 -        sb.delete(4, 8);
  698.90 -        return sb.toString().toString();
  698.91 -    }
  698.92 -    
  698.93 -    public static int countAB(String txt) {
  698.94 -        int cnt = 0;
  698.95 -        for (int i = 0; i < txt.length(); i++) {
  698.96 -            switch (txt.charAt(i)) {
  698.97 -                case 'A': cnt++; break;
  698.98 -                case 'B': cnt += 2; break;
  698.99 -            }
 698.100 -        }
 698.101 -        return cnt;
 698.102 -    }
 698.103 -
 698.104 -    public static int stringSwitch(String txt) {
 698.105 -        switch (txt) {
 698.106 -            case "jedna": return 1;
 698.107 -            case "dve": return 2;
 698.108 -            case "tri": return 3;
 698.109 -            case "ctyri": return 4;
 698.110 -        }
 698.111 -        return -1;
 698.112 -    }
 698.113 -    
 698.114 -    public static String toStringTest(int howMuch) {
 698.115 -        counter = 0;
 698.116 -        StringSample ss = null;
 698.117 -        for (int i = 0; i < howMuch; i++) {
 698.118 -            ss = new StringSample();
 698.119 -        }
 698.120 -        return ss.toString().toString();
 698.121 -    }
 698.122 -    
 698.123 -    public static String concatStrings() {
 698.124 -        return (toStringTest(1) + "\\\n\r\t").toString();
 698.125 -    }
 698.126 -    
 698.127 -    public static int compare(String a, String b) {
 698.128 -        return a.compareTo(b);
 698.129 -    }
 698.130 -
 698.131 -    @Override
 698.132 -    public String toString() {
 698.133 -        return HELLO + cnt;
 698.134 -    }
 698.135 -}
   699.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Mon Feb 25 19:00:08 2013 +0100
   699.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   699.3 @@ -1,212 +0,0 @@
   699.4 -/**
   699.5 - * Back 2 Browser Bytecode Translator
   699.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   699.7 - *
   699.8 - * This program is free software: you can redistribute it and/or modify
   699.9 - * it under the terms of the GNU General Public License as published by
  699.10 - * the Free Software Foundation, version 2 of the License.
  699.11 - *
  699.12 - * This program is distributed in the hope that it will be useful,
  699.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  699.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  699.15 - * GNU General Public License for more details.
  699.16 - *
  699.17 - * You should have received a copy of the GNU General Public License
  699.18 - * along with this program. Look for COPYING file in the top folder.
  699.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  699.20 - */
  699.21 -package org.apidesign.vm4brwsr;
  699.22 -
  699.23 -import org.testng.annotations.Test;
  699.24 -import static org.testng.Assert.*;
  699.25 -import org.testng.annotations.BeforeClass;
  699.26 -
  699.27 -/**
  699.28 - *
  699.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  699.30 - */
  699.31 -public class StringTest {
  699.32 -    @Test public void firstChar() throws Exception {
  699.33 -        assertExec(
  699.34 -            "First char in Hello is H",
  699.35 -            StringSample.class, "sayHello__CI",
  699.36 -            72, 0
  699.37 -        );
  699.38 -    }
  699.39 -
  699.40 -    @Test public void fromChars() throws Exception {
  699.41 -        assertExec(
  699.42 -            "First char in Hello is ABC",
  699.43 -            StringSample.class, "fromChars__Ljava_lang_String_2CCC",
  699.44 -            "ABC", 'A', 'B', 'C'
  699.45 -        );
  699.46 -    }
  699.47 -
  699.48 -    @Test public void concatChars() throws Exception {
  699.49 -        assertExec(
  699.50 -            "Composing yields ABC",
  699.51 -            StringSample.class, "chars__Ljava_lang_String_2CCC",
  699.52 -            "ABC", 'A', 'B', 'C'
  699.53 -        );
  699.54 -    }
  699.55 -
  699.56 -    @Test public void concatCharsFromInts() throws Exception {
  699.57 -        assertExec(
  699.58 -            "Composing yields ABC",
  699.59 -            StringSample.class, "charsFromNumbers__Ljava_lang_String_2",
  699.60 -            "ABC"
  699.61 -        );
  699.62 -    }
  699.63 -
  699.64 -    @Test public void concatCharsFromChars() throws Exception {
  699.65 -        assertExec(
  699.66 -            "Composing yields ABC",
  699.67 -            StringSample.class, "charsFromChars__Ljava_lang_String_2",
  699.68 -            "ABC"
  699.69 -        );
  699.70 -    }
  699.71 -
  699.72 -    @Test public void instanceOfWorks() throws Exception {
  699.73 -        assertExec(
  699.74 -            "It is string",
  699.75 -            StringSample.class, "isStringInstance__Z",
  699.76 -            Double.valueOf(1.0)
  699.77 -        );
  699.78 -    }
  699.79 -
  699.80 -    @Test public void getBytes() throws Exception {
  699.81 -        final String horse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148";
  699.82 -        final String expected = StringSample.getBytes(horse);
  699.83 -        assertExec(
  699.84 -            "Bytes look simplar",
  699.85 -            StringSample.class, "getBytes__Ljava_lang_String_2Ljava_lang_String_2",
  699.86 -            expected, horse
  699.87 -        );
  699.88 -    }
  699.89 -
  699.90 -    @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
  699.91 -        assertExec(
  699.92 -            "Five executions should generate 5Hello World!",
  699.93 -            StringSample.class, "toStringTest__Ljava_lang_String_2I",
  699.94 -            "Hello World!5", 5
  699.95 -        );
  699.96 -    }
  699.97 -    @Test public void toStringConcatenationJava() throws Exception {
  699.98 -        assertEquals("Hello World!5", StringSample.toStringTest(5));
  699.99 -    }
 699.100 -    
 699.101 -    @Test(timeOut=10000) public void stringStringConcat() throws Exception {
 699.102 -        assertExec(
 699.103 -            "Composes strings OK",
 699.104 -            StringSample.class, "concatStrings__Ljava_lang_String_2",
 699.105 -            "Hello World!1" + "\\\n\r\t"
 699.106 -        );
 699.107 -    }
 699.108 -
 699.109 -    @Test public void equalsAndSubstring() throws Exception {
 699.110 -        assertExec(
 699.111 -            "Composes are OK",
 699.112 -            StringSample.class, "equalToHello__ZII",
 699.113 -            true, 0, 5
 699.114 -        );
 699.115 -    }
 699.116 -    @Test public void replaceChars() throws Exception {
 699.117 -        assertExec(
 699.118 -            "Can replace slashes by underscores",
 699.119 -            StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
 699.120 -            "x_y_z", "x/y/z", '/', '_'
 699.121 -        );
 699.122 -    }
 699.123 -    @Test public void replaceIntChars() throws Exception {
 699.124 -        assertExec(
 699.125 -            "Can replace slashes by underscores",
 699.126 -            StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
 699.127 -            "x_y_z", "x/y/z", (int)'/', (int)'_'
 699.128 -        );
 699.129 -    }
 699.130 -
 699.131 -    @Test public void insertBuilder() throws Exception {
 699.132 -        assertExec(
 699.133 -            "Can insert something into a buffer?",
 699.134 -            StringSample.class, "insertBuffer__Ljava_lang_String_2",
 699.135 -            "Ahojdo!"
 699.136 -        );
 699.137 -    }
 699.138 -    
 699.139 -    @Test public void compareHashCodeHi() throws Exception {
 699.140 -        String j = "Hi";
 699.141 -        int jh = StringSample.hashCode(j);
 699.142 -        assertExec(
 699.143 -            "Hashcode is the same " +jh,
 699.144 -            StringSample.class, "hashCode__ILjava_lang_String_2",
 699.145 -            Double.valueOf(jh), j
 699.146 -        );
 699.147 -    }
 699.148 -    @Test public void compareHashCode1() throws Exception {
 699.149 -        String j = "Hello Java!";
 699.150 -        int jh = StringSample.hashCode(j);
 699.151 -        assertExec(
 699.152 -            "Hashcode is the same " + jh,
 699.153 -            StringSample.class, "hashCode__ILjava_lang_String_2",
 699.154 -            Double.valueOf(jh), j
 699.155 -        );
 699.156 -    }
 699.157 -    @Test public void stringSwitch1() throws Exception {
 699.158 -        assertExec(
 699.159 -            "Get one",
 699.160 -            StringSample.class, "stringSwitch__ILjava_lang_String_2",
 699.161 -            Double.valueOf(1), "jedna"
 699.162 -        );
 699.163 -    }
 699.164 -    @Test public void stringSwitch2() throws Exception {
 699.165 -        assertExec(
 699.166 -            "Get two",
 699.167 -            StringSample.class, "stringSwitch__ILjava_lang_String_2",
 699.168 -            Double.valueOf(2), "dve"
 699.169 -        );
 699.170 -    }
 699.171 -    @Test public void stringSwitchDefault() throws Exception {
 699.172 -        assertExec(
 699.173 -            "Get -1",
 699.174 -            StringSample.class, "stringSwitch__ILjava_lang_String_2",
 699.175 -            Double.valueOf(-1), "none"
 699.176 -        );
 699.177 -    }
 699.178 -    
 699.179 -    @Test public void countAB() throws Exception {
 699.180 -        assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
 699.181 -        assertExec(
 699.182 -            "One A and one B adds to 3",
 699.183 -            StringSample.class, "countAB__ILjava_lang_String_2",
 699.184 -            Double.valueOf(3), "Ahoj Bedo!"
 699.185 -        );
 699.186 -        
 699.187 -    }
 699.188 -
 699.189 -    @Test public void compareStrings() throws Exception {
 699.190 -        int res = StringSample.compare("Saab", "Volvo");
 699.191 -        assertExec(
 699.192 -            "Saab finished sooner than Volvo",
 699.193 -            StringSample.class, "compare__ILjava_lang_String_2Ljava_lang_String_2",
 699.194 -            Double.valueOf(res), "Saab", "Volvo"
 699.195 -        );
 699.196 -        
 699.197 -    }
 699.198 -    
 699.199 -    private static TestVM code;
 699.200 -    
 699.201 -    @BeforeClass 
 699.202 -    public void compileTheCode() throws Exception {
 699.203 -        code = TestVM.compileClass(
 699.204 -            "org/apidesign/vm4brwsr/StringSample",
 699.205 -            "java/lang/String"
 699.206 -        );
 699.207 -    }
 699.208 -    
 699.209 -    private static void assertExec(String msg, 
 699.210 -        Class<?> clazz, String method, Object expRes, Object... args
 699.211 -    ) throws Exception {
 699.212 -        code.assertExec(msg, clazz, method, expRes, args);
 699.213 -    }
 699.214 -    
 699.215 -}
   700.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java	Mon Feb 25 19:00:08 2013 +0100
   700.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   700.3 @@ -1,56 +0,0 @@
   700.4 -/**
   700.5 - * Back 2 Browser Bytecode Translator
   700.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   700.7 - *
   700.8 - * This program is free software: you can redistribute it and/or modify
   700.9 - * it under the terms of the GNU General Public License as published by
  700.10 - * the Free Software Foundation, version 2 of the License.
  700.11 - *
  700.12 - * This program is distributed in the hope that it will be useful,
  700.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  700.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  700.15 - * GNU General Public License for more details.
  700.16 - *
  700.17 - * You should have received a copy of the GNU General Public License
  700.18 - * along with this program. Look for COPYING file in the top folder.
  700.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  700.20 - */
  700.21 -package org.apidesign.vm4brwsr;
  700.22 -
  700.23 -import org.testng.annotations.BeforeClass;
  700.24 -import static org.testng.Assert.*;
  700.25 -import org.testng.annotations.Test;
  700.26 -
  700.27 -/**
  700.28 - *
  700.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  700.30 - */
  700.31 -public class SystemTest {
  700.32 -    private static TestVM code;
  700.33 -    
  700.34 -    @Test public void verifyJSTime() throws Exception {
  700.35 -        long now = System.currentTimeMillis();
  700.36 -        
  700.37 -        Object js = code.execCode("Get js time", 
  700.38 -            org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillisDouble__D",
  700.39 -            null
  700.40 -        );
  700.41 -        
  700.42 -        assertTrue(js instanceof Double, "Double " + js);
  700.43 -        long time = ((Double)js).longValue();
  700.44 -        
  700.45 -        long later = System.currentTimeMillis();
  700.46 -        
  700.47 -        assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
  700.48 -        assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
  700.49 -    }
  700.50 -    
  700.51 -    
  700.52 -    @BeforeClass 
  700.53 -    public static void compileTheCode() throws Exception {
  700.54 -        code = TestVM.compileClass(
  700.55 -            "org/apidesign/bck2brwsr/emul/lang/System");
  700.56 -    }
  700.57 -    
  700.58 -}
  700.59 -
   701.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java	Mon Feb 25 19:00:08 2013 +0100
   701.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   701.3 @@ -1,170 +0,0 @@
   701.4 -/**
   701.5 - * Back 2 Browser Bytecode Translator
   701.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   701.7 - *
   701.8 - * This program is free software: you can redistribute it and/or modify
   701.9 - * it under the terms of the GNU General Public License as published by
  701.10 - * the Free Software Foundation, version 2 of the License.
  701.11 - *
  701.12 - * This program is distributed in the hope that it will be useful,
  701.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  701.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  701.15 - * GNU General Public License for more details.
  701.16 - *
  701.17 - * You should have received a copy of the GNU General Public License
  701.18 - * along with this program. Look for COPYING file in the top folder.
  701.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  701.20 - */
  701.21 -package org.apidesign.vm4brwsr;
  701.22 -
  701.23 -import java.io.File;
  701.24 -import java.io.FileWriter;
  701.25 -import java.io.IOException;
  701.26 -import java.io.InputStream;
  701.27 -import java.net.URL;
  701.28 -import java.util.Enumeration;
  701.29 -import javax.script.Invocable;
  701.30 -import javax.script.ScriptEngine;
  701.31 -import javax.script.ScriptEngineManager;
  701.32 -import javax.script.ScriptException;
  701.33 -import static org.testng.Assert.*;
  701.34 -
  701.35 -final class TestVM {
  701.36 -    private final Invocable code;
  701.37 -    private final CharSequence codeSeq;
  701.38 -    private final Object bck2brwsr;
  701.39 -    
  701.40 -    
  701.41 -    private TestVM(Invocable code, CharSequence codeSeq) throws ScriptException, NoSuchMethodException {
  701.42 -        this.code = code;
  701.43 -        this.codeSeq = codeSeq;
  701.44 -        this.bck2brwsr = code.invokeFunction("bck2brwsr");
  701.45 -    }
  701.46 -    
  701.47 -
  701.48 -    public Object execCode(
  701.49 -        String msg, Class<?> clazz, String method, 
  701.50 -        Object expRes, Object... args
  701.51 -    ) throws Exception {
  701.52 -        Object ret = null;
  701.53 -        try {
  701.54 -            ret = code.invokeMethod(bck2brwsr, "loadClass", clazz.getName());
  701.55 -            ret = code.invokeMethod(ret, method, args);
  701.56 -        } catch (ScriptException ex) {
  701.57 -            fail("Execution failed in " + dumpJS(codeSeq), ex);
  701.58 -        } catch (NoSuchMethodException ex) {
  701.59 -            fail("Cannot find method in " + dumpJS(codeSeq), ex);
  701.60 -        }
  701.61 -        if (ret == null && expRes == null) {
  701.62 -            return null;
  701.63 -        }
  701.64 -        if (expRes != null && expRes.equals(ret)) {
  701.65 -            return null;
  701.66 -        }
  701.67 -        if (expRes instanceof Number) {
  701.68 -            // in case of Long it is necessary convert it to number
  701.69 -            // since the Long is represented by two numbers in JavaScript
  701.70 -            try {
  701.71 -                ret = code.invokeMethod(ret, "toFP");
  701.72 -                ret = code.invokeFunction("Number", ret);
  701.73 -            } catch (ScriptException ex) {
  701.74 -                fail("Conversion to number failed in " + dumpJS(codeSeq), ex);
  701.75 -            } catch (NoSuchMethodException ex) {
  701.76 -                fail("Cannot find global Number(x) function in " + dumpJS(codeSeq), ex);
  701.77 -            }
  701.78 -        }
  701.79 -        return ret;
  701.80 -    }
  701.81 -    
  701.82 -    void assertExec(
  701.83 -        String msg, Class clazz, String method, Object expRes, Object... args
  701.84 -    ) throws Exception {
  701.85 -        Object ret = execCode(msg, clazz, method, expRes, args);
  701.86 -        if (ret == null) {
  701.87 -            return;
  701.88 -        }
  701.89 -        if (expRes != null && expRes.equals(ret)) {
  701.90 -            return;
  701.91 -        }
  701.92 -        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + dumpJS(codeSeq));
  701.93 -    }    
  701.94 -
  701.95 -    static TestVM compileClass(String... names) throws ScriptException, IOException {
  701.96 -        return compileClass(null, names);
  701.97 -    }
  701.98 -    
  701.99 -    static TestVM compileClass(StringBuilder sb, String... names) throws ScriptException, IOException {
 701.100 -        return compileClass(sb, null, names);
 701.101 -    }
 701.102 -
 701.103 -    static TestVM compileClass(StringBuilder sb, ScriptEngine[] eng, String... names) throws ScriptException, IOException {
 701.104 -        if (sb == null) {
 701.105 -            sb = new StringBuilder();
 701.106 -        }
 701.107 -        Bck2Brwsr.generate(sb, new EmulationResources(), names);
 701.108 -        ScriptEngineManager sem = new ScriptEngineManager();
 701.109 -        ScriptEngine js = sem.getEngineByExtension("js");
 701.110 -        if (eng != null) {
 701.111 -            eng[0] = js;
 701.112 -        }
 701.113 -        try {
 701.114 -            Object res = js.eval(sb.toString());
 701.115 -            assertTrue(js instanceof Invocable, "It is invocable object: " + res);
 701.116 -            return new TestVM((Invocable) js, sb);
 701.117 -        } catch (Exception ex) {
 701.118 -            if (sb.length() > 2000) {
 701.119 -                sb = dumpJS(sb);
 701.120 -            }
 701.121 -            fail("Could not evaluate:\n" + sb, ex);
 701.122 -            return null;
 701.123 -        }
 701.124 -    }
 701.125 -
 701.126 -    Object loadClass(String loadClass, String name) throws ScriptException, NoSuchMethodException {
 701.127 -        return code.invokeMethod(bck2brwsr, "loadClass", Exceptions.class.getName());
 701.128 -    }
 701.129 -    
 701.130 -    Object invokeMethod(Object obj, String method, Object... params) throws ScriptException, NoSuchMethodException {
 701.131 -        return code.invokeMethod(obj, method, params);
 701.132 -    }
 701.133 -
 701.134 -    Object invokeFunction(String methodName, Object... args) throws ScriptException, NoSuchMethodException {
 701.135 -        return code.invokeFunction(methodName, args);
 701.136 -    }
 701.137 -
 701.138 -    static StringBuilder dumpJS(CharSequence sb) throws IOException {
 701.139 -        File f = File.createTempFile("execution", ".js");
 701.140 -        FileWriter w = new FileWriter(f);
 701.141 -        w.append(sb);
 701.142 -        w.close();
 701.143 -        return new StringBuilder(f.getPath());
 701.144 -    }
 701.145 -
 701.146 -    @Override
 701.147 -    public String toString() {
 701.148 -        try {
 701.149 -            return dumpJS(codeSeq).toString();
 701.150 -        } catch (IOException ex) {
 701.151 -            return ex.toString();
 701.152 -        }
 701.153 -    }
 701.154 -    
 701.155 -    
 701.156 -    private static class EmulationResources implements Bck2Brwsr.Resources {
 701.157 -        @Override
 701.158 -        public InputStream get(String name) throws IOException {
 701.159 -            Enumeration<URL> en = StaticMethodTest.class.getClassLoader().getResources(name);
 701.160 -            URL u = null;
 701.161 -            while (en.hasMoreElements()) {
 701.162 -                u = en.nextElement();
 701.163 -            }
 701.164 -            if (u == null) {
 701.165 -                throw new IOException("Can't find " + name);
 701.166 -            }
 701.167 -            if (u.toExternalForm().contains("rt.jar!")) {
 701.168 -                throw new IOException("No emulation for " + u);
 701.169 -            }
 701.170 -            return u.openStream();
 701.171 -        }
 701.172 -    }
 701.173 -}
   702.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Mon Feb 25 19:00:08 2013 +0100
   702.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   702.3 @@ -1,93 +0,0 @@
   702.4 -/**
   702.5 - * Back 2 Browser Bytecode Translator
   702.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   702.7 - *
   702.8 - * This program is free software: you can redistribute it and/or modify
   702.9 - * it under the terms of the GNU General Public License as published by
  702.10 - * the Free Software Foundation, version 2 of the License.
  702.11 - *
  702.12 - * This program is distributed in the hope that it will be useful,
  702.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  702.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  702.15 - * GNU General Public License for more details.
  702.16 - *
  702.17 - * You should have received a copy of the GNU General Public License
  702.18 - * along with this program. Look for COPYING file in the top folder.
  702.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  702.20 - */
  702.21 -package org.apidesign.vm4brwsr;
  702.22 -
  702.23 -import javax.script.ScriptContext;
  702.24 -import javax.script.ScriptEngine;
  702.25 -import javax.script.ScriptException;
  702.26 -import org.testng.annotations.BeforeClass;
  702.27 -import static org.testng.Assert.*;
  702.28 -import org.testng.annotations.Test;
  702.29 -
  702.30 -/** Implements loading class by class.
  702.31 - *
  702.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  702.33 - */
  702.34 -public class VMLazyTest {
  702.35 -    private static TestVM code;
  702.36 -
  702.37 -    @BeforeClass
  702.38 -    public void compileTheCode() throws Exception {
  702.39 -        StringBuilder sb = new StringBuilder();
  702.40 -        sb.append("\nvar data = {};");
  702.41 -        sb.append("\nfunction test(clazz, method) {");
  702.42 -        sb.append("\n  if (!data.bck2brwsr) data.bck2brwsr = bck2brwsr(function(name) { return loader.get(name); });");
  702.43 -        sb.append("\n  var c = data.bck2brwsr.loadClass(clazz);");
  702.44 -        sb.append("\n  return c[method]();");
  702.45 -        sb.append("\n}");
  702.46 -        
  702.47 -        sb.append("\nfunction checkKO() {");
  702.48 -        sb.append("\n  return ko !== null;");
  702.49 -        sb.append("\n}");
  702.50 -       
  702.51 -        ScriptEngine[] arr = { null };
  702.52 -        code = TestVM.compileClass(sb, arr,
  702.53 -            new String[]{"org/apidesign/vm4brwsr/VM", "org/apidesign/vm4brwsr/StaticMethod"}
  702.54 -        );
  702.55 -        arr[0].getContext().setAttribute("loader", new BytesLoader(), ScriptContext.ENGINE_SCOPE);
  702.56 -    }
  702.57 -    
  702.58 -    @Test public void invokeStaticMethod() throws Exception {
  702.59 -        assertExec("Trying to get -1", "test", Double.valueOf(-1),
  702.60 -            StaticMethod.class.getName(), "minusOne__I"
  702.61 -        );
  702.62 -    }
  702.63 -
  702.64 -    @Test public void loadDependantClass() throws Exception {
  702.65 -        assertExec("Expecting zero", "test", Double.valueOf(0),
  702.66 -            InstanceSub.class.getName(), "recallDbl__D"
  702.67 -        );
  702.68 -    }
  702.69 -
  702.70 -    @Test public void loadClassWithAssociatedScript() throws Exception {
  702.71 -        assertExec("ko is defined", "test", true,
  702.72 -            Script.class.getName(), "checkNotNull__Z"
  702.73 -        );
  702.74 -        
  702.75 -        Object res = code.invokeFunction("checkKO");
  702.76 -        assertEquals(res, true, "KO is defined on a global level");
  702.77 -    }
  702.78 -
  702.79 -    private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception {
  702.80 -        Object ret = null;
  702.81 -        try {
  702.82 -            ret = code.invokeFunction(methodName, args);
  702.83 -        } catch (ScriptException ex) {
  702.84 -            fail("Execution failed in\n" + code.toString(), ex);
  702.85 -        } catch (NoSuchMethodException ex) {
  702.86 -            fail("Cannot find method in\n" + code.toString(), ex);
  702.87 -        }
  702.88 -        if (ret == null && expRes == null) {
  702.89 -            return;
  702.90 -        }
  702.91 -        if (expRes.equals(ret)) {
  702.92 -            return;
  702.93 -        }
  702.94 -        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + code.toString());
  702.95 -    }
  702.96 -}
   703.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMinVM.java	Mon Feb 25 19:00:08 2013 +0100
   703.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   703.3 @@ -1,46 +0,0 @@
   703.4 -/**
   703.5 - * Back 2 Browser Bytecode Translator
   703.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   703.7 - *
   703.8 - * This program is free software: you can redistribute it and/or modify
   703.9 - * it under the terms of the GNU General Public License as published by
  703.10 - * the Free Software Foundation, version 2 of the License.
  703.11 - *
  703.12 - * This program is distributed in the hope that it will be useful,
  703.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  703.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  703.15 - * GNU General Public License for more details.
  703.16 - *
  703.17 - * You should have received a copy of the GNU General Public License
  703.18 - * along with this program. Look for COPYING file in the top folder.
  703.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  703.20 - */
  703.21 -package org.apidesign.vm4brwsr;
  703.22 -
  703.23 -import java.io.ByteArrayInputStream;
  703.24 -import java.io.IOException;
  703.25 -
  703.26 -/**
  703.27 - *
  703.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  703.29 - */
  703.30 -class VMinVM extends ByteCodeToJavaScript {
  703.31 -    private VMinVM(Appendable out) {
  703.32 -        super(out);
  703.33 -    }
  703.34 -    
  703.35 -    static String toJavaScript(byte[] is) throws IOException {
  703.36 -        StringBuilder sb = new StringBuilder();
  703.37 -        new VMinVM(sb).compile(new ByteArrayInputStream(is));
  703.38 -        return sb.toString().toString();
  703.39 -    }
  703.40 -
  703.41 -    @Override
  703.42 -    protected boolean requireReference(String internalClassName) {
  703.43 -        return false;
  703.44 -    }
  703.45 -
  703.46 -    @Override
  703.47 -    protected void requireScript(String resourcePath) {
  703.48 -    }
  703.49 -}
   704.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Mon Feb 25 19:00:08 2013 +0100
   704.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   704.3 @@ -1,87 +0,0 @@
   704.4 -/**
   704.5 - * Back 2 Browser Bytecode Translator
   704.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   704.7 - *
   704.8 - * This program is free software: you can redistribute it and/or modify
   704.9 - * it under the terms of the GNU General Public License as published by
  704.10 - * the Free Software Foundation, version 2 of the License.
  704.11 - *
  704.12 - * This program is distributed in the hope that it will be useful,
  704.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  704.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  704.15 - * GNU General Public License for more details.
  704.16 - *
  704.17 - * You should have received a copy of the GNU General Public License
  704.18 - * along with this program. Look for COPYING file in the top folder.
  704.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  704.20 - */
  704.21 -package org.apidesign.vm4brwsr;
  704.22 -
  704.23 -import java.io.File;
  704.24 -import java.io.FileWriter;
  704.25 -import java.io.IOException;
  704.26 -import static org.testng.Assert.*;
  704.27 -import org.testng.annotations.BeforeClass;
  704.28 -import org.testng.annotations.Test;
  704.29 -
  704.30 -/**
  704.31 - *
  704.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  704.33 - */
  704.34 -public class VMinVMTest {
  704.35 -    private static TestVM code;
  704.36 -    
  704.37 -    @Test public void compareGeneratedCodeForArrayClass() throws Exception {
  704.38 -        compareCode("org/apidesign/vm4brwsr/Array.class");
  704.39 -    }
  704.40 -
  704.41 -    @Test public void compareGeneratedCodeForClassesClass() throws Exception {
  704.42 -        compareCode("org/apidesign/vm4brwsr/Classes.class");
  704.43 -    }
  704.44 -
  704.45 -    @BeforeClass
  704.46 -    public void compileTheCode() throws Exception {
  704.47 -        code = TestVM.compileClass("org/apidesign/vm4brwsr/VMinVM");
  704.48 -    }
  704.49 -    
  704.50 -    private void compareCode(final String nm) throws Exception, IOException {
  704.51 -        byte[] arr = BytesLoader.readClass(nm);
  704.52 -        String ret1 = VMinVM.toJavaScript(arr);
  704.53 -        
  704.54 -        Object ret;
  704.55 -        try {
  704.56 -            ret = code.invokeFunction("bck2brwsr");
  704.57 -            ret = code.invokeMethod(ret, "loadClass", VMinVM.class.getName());
  704.58 -            ret = code.invokeMethod(ret, "toJavaScript__Ljava_lang_String_2_3B", arr);
  704.59 -        } catch (Exception ex) {
  704.60 -            File f = File.createTempFile("execution", ".js");
  704.61 -            FileWriter w = new FileWriter(f);
  704.62 -            w.append("var byteCode = [\n  ");
  704.63 -            String sep = "";
  704.64 -            for (int i = 0; i < arr.length; i++) {
  704.65 -                w.append(sep).append(Integer.toString((arr[i] + 256) % 256));
  704.66 -                sep = ", ";
  704.67 -                if (i % 20 == 0) {
  704.68 -                    w.append("\n  ");
  704.69 -                }
  704.70 -            }
  704.71 -            w.append("\n];\n");
  704.72 -            w.append(code.toString());
  704.73 -            w.close();
  704.74 -            throw new Exception(ex.getMessage() + " file: " + f, ex);
  704.75 -        }
  704.76 -
  704.77 -        
  704.78 -        assertTrue(ret instanceof String, "It is string: " + ret);
  704.79 -        
  704.80 -        if (!ret1.toString().equals(ret)) {
  704.81 -            StringBuilder msg = new StringBuilder("Difference found between ");
  704.82 -            msg.append(TestVM.dumpJS(ret1));
  704.83 -            msg.append(" ");
  704.84 -            msg.append(TestVM.dumpJS((CharSequence) ret));
  704.85 -            msg.append(" compiled by ");
  704.86 -            msg.append(code.toString());
  704.87 -            fail(msg.toString());
  704.88 -        }
  704.89 -    }
  704.90 -}
   705.1 --- a/vm/src/test/resources/org/apidesign/vm4brwsr/ko.js	Mon Feb 25 19:00:08 2013 +0100
   705.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   705.3 @@ -1,20 +0,0 @@
   705.4 -/*
   705.5 - * Back 2 Browser Bytecode Translator
   705.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   705.7 - *
   705.8 - * This program is free software: you can redistribute it and/or modify
   705.9 - * it under the terms of the GNU General Public License as published by
  705.10 - * the Free Software Foundation, version 2 of the License.
  705.11 - *
  705.12 - * This program is distributed in the hope that it will be useful,
  705.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  705.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  705.15 - * GNU General Public License for more details.
  705.16 - *
  705.17 - * You should have received a copy of the GNU General Public License
  705.18 - * along with this program. Look for COPYING file in the top folder.
  705.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  705.20 - */
  705.21 -this.ko = {};
  705.22 -
  705.23 -
   706.1 --- a/vmtest/pom.xml	Mon Feb 25 19:00:08 2013 +0100
   706.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   706.3 @@ -1,67 +0,0 @@
   706.4 -<?xml version="1.0"?>
   706.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"
   706.6 -    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   706.7 -  <modelVersion>4.0.0</modelVersion>
   706.8 -  <parent>
   706.9 -    <groupId>org.apidesign</groupId>
  706.10 -    <artifactId>bck2brwsr</artifactId>
  706.11 -    <version>0.3-SNAPSHOT</version>
  706.12 -  </parent>
  706.13 -  <groupId>org.apidesign.bck2brwsr</groupId>
  706.14 -  <artifactId>vmtest</artifactId>
  706.15 -  <version>0.3-SNAPSHOT</version>
  706.16 -  
  706.17 -  <name>VM Testing APIs</name>
  706.18 -  <url>http://bck2brwsr.apidesign.org</url>
  706.19 -    <build>
  706.20 -        <plugins>
  706.21 -            <plugin>
  706.22 -                <groupId>org.apache.maven.plugins</groupId>
  706.23 -                <artifactId>maven-compiler-plugin</artifactId>
  706.24 -                <version>2.3.2</version>
  706.25 -                <configuration>
  706.26 -                    <source>1.7</source>
  706.27 -                    <target>1.7</target>
  706.28 -                </configuration>
  706.29 -            </plugin>
  706.30 -        </plugins>
  706.31 -    </build>
  706.32 -    <properties>
  706.33 -    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  706.34 -  </properties>
  706.35 -  <dependencies>
  706.36 -    <dependency>
  706.37 -      <groupId>org.testng</groupId>
  706.38 -      <artifactId>testng</artifactId>
  706.39 -      <scope>compile</scope>
  706.40 -      <exclusions>
  706.41 -        <exclusion>
  706.42 -          <artifactId>junit</artifactId>
  706.43 -          <groupId>junit</groupId>
  706.44 -        </exclusion>
  706.45 -      </exclusions>
  706.46 -    </dependency>
  706.47 -    <dependency>
  706.48 -      <groupId>${project.groupId}</groupId>
  706.49 -      <artifactId>vm4brwsr</artifactId>
  706.50 -      <version>${project.version}</version>
  706.51 -      <type>jar</type>
  706.52 -    </dependency>
  706.53 -    <dependency>
  706.54 -      <groupId>${project.groupId}</groupId>
  706.55 -      <artifactId>emul.mini</artifactId>
  706.56 -      <version>${project.version}</version>
  706.57 -      <scope>test</scope>
  706.58 -    </dependency>
  706.59 -    <dependency>
  706.60 -      <groupId>${project.groupId}</groupId>
  706.61 -      <artifactId>launcher</artifactId>
  706.62 -      <version>${project.version}</version>
  706.63 -    </dependency>
  706.64 -    <dependency>
  706.65 -      <groupId>org.netbeans.api</groupId>
  706.66 -      <artifactId>org-openide-util-lookup</artifactId>
  706.67 -      <scope>provided</scope>
  706.68 -    </dependency>
  706.69 -  </dependencies>
  706.70 -</project>
   707.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java	Mon Feb 25 19:00:08 2013 +0100
   707.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   707.3 @@ -1,38 +0,0 @@
   707.4 -/**
   707.5 - * Back 2 Browser Bytecode Translator
   707.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   707.7 - *
   707.8 - * This program is free software: you can redistribute it and/or modify
   707.9 - * it under the terms of the GNU General Public License as published by
  707.10 - * the Free Software Foundation, version 2 of the License.
  707.11 - *
  707.12 - * This program is distributed in the hope that it will be useful,
  707.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  707.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  707.15 - * GNU General Public License for more details.
  707.16 - *
  707.17 - * You should have received a copy of the GNU General Public License
  707.18 - * along with this program. Look for COPYING file in the top folder.
  707.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  707.20 - */
  707.21 -package org.apidesign.bck2brwsr.vmtest;
  707.22 -
  707.23 -import java.lang.annotation.ElementType;
  707.24 -import java.lang.annotation.Retention;
  707.25 -import java.lang.annotation.RetentionPolicy;
  707.26 -import java.lang.annotation.Target;
  707.27 -
  707.28 -/** Annotation to indicate that given method should be executed
  707.29 - * in a browser environment. Has to be used in conjunction with {@link VMTest#create(java.lang.Class)}
  707.30 - * factory method. 
  707.31 - * <p>
  707.32 - * The browser to is by default executed via {@link java.awt.Desktop#browse(java.net.URI)},
  707.33 - * but one can change that by specifying <code>-Dvmtest.brwsrs=firefox,google-chrome</code>
  707.34 - * property.
  707.35 - *
  707.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  707.37 - */
  707.38 -@Retention(RetentionPolicy.RUNTIME)
  707.39 -@Target(ElementType.METHOD)
  707.40 -public @interface BrwsrTest {
  707.41 -}
   708.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java	Mon Feb 25 19:00:08 2013 +0100
   708.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   708.3 @@ -1,45 +0,0 @@
   708.4 -/**
   708.5 - * Back 2 Browser Bytecode Translator
   708.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   708.7 - *
   708.8 - * This program is free software: you can redistribute it and/or modify
   708.9 - * it under the terms of the GNU General Public License as published by
  708.10 - * the Free Software Foundation, version 2 of the License.
  708.11 - *
  708.12 - * This program is distributed in the hope that it will be useful,
  708.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  708.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  708.15 - * GNU General Public License for more details.
  708.16 - *
  708.17 - * You should have received a copy of the GNU General Public License
  708.18 - * along with this program. Look for COPYING file in the top folder.
  708.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  708.20 - */
  708.21 -package org.apidesign.bck2brwsr.vmtest;
  708.22 -
  708.23 -import java.lang.annotation.ElementType;
  708.24 -import java.lang.annotation.Retention;
  708.25 -import java.lang.annotation.RetentionPolicy;
  708.26 -import java.lang.annotation.Target;
  708.27 -
  708.28 -/** Can be applied on a method that yields a return value. 
  708.29 - * Together with {@link VMTest#create} it can be used to write
  708.30 - * methods which are executed in real VM as well as JavaScript VMs and
  708.31 - * their results are compared.
  708.32 - *
  708.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  708.34 - */
  708.35 -@Retention(RetentionPolicy.RUNTIME)
  708.36 -@Target(ElementType.METHOD)
  708.37 -public @interface Compare {
  708.38 -    /** Specifies whether the system should internal JavaScript interpreter
  708.39 -     * as available via {@link javax.script.ScriptEngine}. Defaults to true,
  708.40 -     * but in some situations (benchmarking comes to my mind), one may set this
  708.41 -     * to <code>false</code>. In such case only browsers provided via
  708.42 -     * <code>vmtest.brwsrs</code> property are used. For example
  708.43 -     * <code>"vmtest.brwsrs=firefox,google-chrome"</code> would run the test
  708.44 -     * in HotSpot VM, firefox and chrome and would compare the results.
  708.45 -     * @return 
  708.46 -     */
  708.47 -    boolean scripting() default true;
  708.48 -}
   709.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HtmlFragment.java	Mon Feb 25 19:00:08 2013 +0100
   709.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   709.3 @@ -1,38 +0,0 @@
   709.4 -/**
   709.5 - * Back 2 Browser Bytecode Translator
   709.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   709.7 - *
   709.8 - * This program is free software: you can redistribute it and/or modify
   709.9 - * it under the terms of the GNU General Public License as published by
  709.10 - * the Free Software Foundation, version 2 of the License.
  709.11 - *
  709.12 - * This program is distributed in the hope that it will be useful,
  709.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  709.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  709.15 - * GNU General Public License for more details.
  709.16 - *
  709.17 - * You should have received a copy of the GNU General Public License
  709.18 - * along with this program. Look for COPYING file in the top folder.
  709.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  709.20 - */
  709.21 -package org.apidesign.bck2brwsr.vmtest;
  709.22 -
  709.23 -import java.lang.annotation.ElementType;
  709.24 -import java.lang.annotation.Retention;
  709.25 -import java.lang.annotation.RetentionPolicy;
  709.26 -import java.lang.annotation.Target;
  709.27 -
  709.28 -/** Allows to specify an HTML fragment for a given {@link BrwsrTest}. 
  709.29 - * Apply either to the method or to enclosing class. The fragment will be
  709.30 - * made available in the page that executes given test. Its elements shall
  709.31 - * be regularly accessible from the test.
  709.32 - *
  709.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  709.34 - */
  709.35 -@Retention(RetentionPolicy.RUNTIME)
  709.36 -@Target({ ElementType.METHOD, ElementType.TYPE})
  709.37 -public @interface HtmlFragment {
  709.38 -    /** HTML code fragment to be exposed on the testing page.
  709.39 -     */
  709.40 -    String value();
  709.41 -}
   710.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Http.java	Mon Feb 25 19:00:08 2013 +0100
   710.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   710.3 @@ -1,56 +0,0 @@
   710.4 -/**
   710.5 - * Back 2 Browser Bytecode Translator
   710.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   710.7 - *
   710.8 - * This program is free software: you can redistribute it and/or modify
   710.9 - * it under the terms of the GNU General Public License as published by
  710.10 - * the Free Software Foundation, version 2 of the License.
  710.11 - *
  710.12 - * This program is distributed in the hope that it will be useful,
  710.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  710.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  710.15 - * GNU General Public License for more details.
  710.16 - *
  710.17 - * You should have received a copy of the GNU General Public License
  710.18 - * along with this program. Look for COPYING file in the top folder.
  710.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  710.20 - */
  710.21 -package org.apidesign.bck2brwsr.vmtest;
  710.22 -
  710.23 -import java.lang.annotation.ElementType;
  710.24 -import java.lang.annotation.Retention;
  710.25 -import java.lang.annotation.RetentionPolicy;
  710.26 -import java.lang.annotation.Target;
  710.27 -
  710.28 -/**
  710.29 - * Exposes HTTP page or pages to the running {@link BrwsrTest}, so it can access under
  710.30 - * the relative path.
  710.31 - *
  710.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  710.33 - */
  710.34 -@Retention(RetentionPolicy.RUNTIME)
  710.35 -@Target({ElementType.METHOD, ElementType.TYPE})
  710.36 -public @interface Http {
  710.37 -    /** Set of pages to make available */
  710.38 -    public Resource[] value();
  710.39 -    
  710.40 -    /** Exposes an HTTP page to the running {@link BrwsrTest}, so it can access
  710.41 -     * under the relative path.
  710.42 -     *
  710.43 -     * @author Jaroslav Tulach <jtulach@netbeans.org>
  710.44 -     */
  710.45 -    @Retention(RetentionPolicy.RUNTIME)
  710.46 -    @Target({})
  710.47 -    public @interface Resource {
  710.48 -        /** path on the server that the test can use to access the exposed resource */
  710.49 -        String path();
  710.50 -        /** the content of the HttpResource */
  710.51 -        String content();
  710.52 -        /** resource relative to the class that should be used instead of <code>content</code>.
  710.53 -         * Leave content equal to empty string.
  710.54 -         */
  710.55 -        String resource() default "";
  710.56 -        /** mime type of the resource */
  710.57 -        String mimeType();
  710.58 -    }
  710.59 -}
   711.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java	Mon Feb 25 19:00:08 2013 +0100
   711.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   711.3 @@ -1,43 +0,0 @@
   711.4 -/**
   711.5 - * Back 2 Browser Bytecode Translator
   711.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   711.7 - *
   711.8 - * This program is free software: you can redistribute it and/or modify
   711.9 - * it under the terms of the GNU General Public License as published by
  711.10 - * the Free Software Foundation, version 2 of the License.
  711.11 - *
  711.12 - * This program is distributed in the hope that it will be useful,
  711.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  711.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  711.15 - * GNU General Public License for more details.
  711.16 - *
  711.17 - * You should have received a copy of the GNU General Public License
  711.18 - * along with this program. Look for COPYING file in the top folder.
  711.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  711.20 - */
  711.21 -package org.apidesign.bck2brwsr.vmtest;
  711.22 -
  711.23 -import org.apidesign.bck2brwsr.vmtest.impl.CompareCase;
  711.24 -import org.testng.annotations.Factory;
  711.25 -
  711.26 -/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
  711.27 - * in provided class and builds set of tests that compare the computations
  711.28 - * in real as well as JavaScript virtual machines. Use as:<pre>
  711.29 - * {@code @}{@link Factory} public static create() {
  711.30 - *   return @{link VMTest}.{@link #create(YourClass.class);
  711.31 - * }</pre>
  711.32 - *
  711.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  711.34 - */
  711.35 -public final class VMTest {
  711.36 -    /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
  711.37 -     * instances of tests. Each instance runs the test in different virtual
  711.38 -     * machine and at the end they compare the results.
  711.39 -     * 
  711.40 -     * @param clazz the class to inspect
  711.41 -     * @return the set of created tests
  711.42 -     */
  711.43 -    public static Object[] create(Class<?> clazz) {
  711.44 -        return CompareCase.create(clazz);
  711.45 -    }
  711.46 -}
   712.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java	Mon Feb 25 19:00:08 2013 +0100
   712.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   712.3 @@ -1,137 +0,0 @@
   712.4 -/**
   712.5 - * Back 2 Browser Bytecode Translator
   712.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   712.7 - *
   712.8 - * This program is free software: you can redistribute it and/or modify
   712.9 - * it under the terms of the GNU General Public License as published by
  712.10 - * the Free Software Foundation, version 2 of the License.
  712.11 - *
  712.12 - * This program is distributed in the hope that it will be useful,
  712.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  712.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  712.15 - * GNU General Public License for more details.
  712.16 - *
  712.17 - * You should have received a copy of the GNU General Public License
  712.18 - * along with this program. Look for COPYING file in the top folder.
  712.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  712.20 - */
  712.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  712.22 -
  712.23 -import java.io.ByteArrayInputStream;
  712.24 -import java.io.File;
  712.25 -import java.io.FileWriter;
  712.26 -import java.io.IOException;
  712.27 -import java.io.InputStream;
  712.28 -import java.lang.reflect.Constructor;
  712.29 -import java.lang.reflect.InvocationTargetException;
  712.30 -import java.lang.reflect.Method;
  712.31 -import org.apidesign.bck2brwsr.launcher.Launcher;
  712.32 -import org.apidesign.bck2brwsr.launcher.InvocationContext;
  712.33 -import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
  712.34 -import org.apidesign.bck2brwsr.vmtest.Http;
  712.35 -import org.testng.ITest;
  712.36 -import org.testng.annotations.Test;
  712.37 -
  712.38 -/**
  712.39 - *
  712.40 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  712.41 - */
  712.42 -public final class Bck2BrwsrCase implements ITest {
  712.43 -    private final Method m;
  712.44 -    private final Launcher l;
  712.45 -    private final String type;
  712.46 -    private final boolean fail;
  712.47 -    private final HtmlFragment html;
  712.48 -    private final Http.Resource[] http;
  712.49 -    Object value;
  712.50 -
  712.51 -    Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail, HtmlFragment html, Http.Resource[] http) {
  712.52 -        this.l = l;
  712.53 -        this.m = m;
  712.54 -        this.type = type;
  712.55 -        this.fail = fail;
  712.56 -        this.html = html;
  712.57 -        this.http = http;
  712.58 -    }
  712.59 -
  712.60 -    @Test(groups = "run")
  712.61 -    public void executeCode() throws Throwable {
  712.62 -        if (l != null) {
  712.63 -            InvocationContext c = l.createInvocation(m.getDeclaringClass(), m.getName());
  712.64 -            if (html != null) {
  712.65 -                c.setHtmlFragment(html.value());
  712.66 -            }
  712.67 -            if (http != null) {
  712.68 -                for (Http.Resource r : http) {
  712.69 -                    if (!r.content().isEmpty()) {
  712.70 -                        InputStream is = new ByteArrayInputStream(r.content().getBytes("UTF-8"));
  712.71 -                        c.addHttpResource(r.path(), r.mimeType(), is);
  712.72 -                    } else {
  712.73 -                        InputStream is = m.getDeclaringClass().getResourceAsStream(r.resource());
  712.74 -                        c.addHttpResource(r.path(), r.mimeType(), is);
  712.75 -                    }
  712.76 -                }
  712.77 -            }
  712.78 -            String res = c.invoke();
  712.79 -            value = res;
  712.80 -            if (fail) {
  712.81 -                int idx = res.indexOf(':');
  712.82 -                if (idx >= 0) {
  712.83 -                    Class<? extends Throwable> thrwbl = null;
  712.84 -                    try {
  712.85 -                        Class<?> exCls = Class.forName(res.substring(0, idx));
  712.86 -                        if (Throwable.class.isAssignableFrom(exCls)) {
  712.87 -                            thrwbl = exCls.asSubclass(Throwable.class);
  712.88 -                        }
  712.89 -                    } catch (Exception ex) {
  712.90 -                        // ignore
  712.91 -                    }
  712.92 -                    if (thrwbl != null) {
  712.93 -                        Throwable t = null;
  712.94 -                        try {
  712.95 -                            for (Constructor<?> cnstr : thrwbl.getConstructors()) {
  712.96 -                                if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
  712.97 -                                    t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
  712.98 -                                    break;
  712.99 -                                }
 712.100 -                            }
 712.101 -                        } catch (Throwable ex) {
 712.102 -                            t = thrwbl.newInstance().initCause(ex);
 712.103 -                        }
 712.104 -                        if (t == null) {
 712.105 -                            t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
 712.106 -                        }
 712.107 -                        throw t;
 712.108 -                    }
 712.109 -                    throw new AssertionError(res);
 712.110 -                }
 712.111 -            }
 712.112 -        } else {
 712.113 -            try {
 712.114 -                value = m.invoke(m.getDeclaringClass().newInstance());
 712.115 -            } catch (InvocationTargetException ex) {
 712.116 -                Throwable t = ex.getTargetException();
 712.117 -                value = t.getClass().getName() + ":" + t.getMessage();
 712.118 -                if (t instanceof AssertionError) {
 712.119 -                    throw t;
 712.120 -                }
 712.121 -            }
 712.122 -        }
 712.123 -    }
 712.124 -
 712.125 -    @Override
 712.126 -    public String getTestName() {
 712.127 -        return m.getName() + "[" + typeName() + "]";
 712.128 -    }
 712.129 -
 712.130 -    final String typeName() {
 712.131 -        return type;
 712.132 -    }
 712.133 -    static void dumpJS(StringBuilder sb, Bck2BrwsrCase c) throws IOException {
 712.134 -        File f = File.createTempFile(c.m.getName(), ".js");
 712.135 -        try (final FileWriter w = new FileWriter(f)) {
 712.136 -            w.append(c.l.toString());
 712.137 -        }
 712.138 -        sb.append("Path: ").append(f.getPath());
 712.139 -    }
 712.140 -}
   713.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java	Mon Feb 25 19:00:08 2013 +0100
   713.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   713.3 @@ -1,160 +0,0 @@
   713.4 -/**
   713.5 - * Back 2 Browser Bytecode Translator
   713.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   713.7 - *
   713.8 - * This program is free software: you can redistribute it and/or modify
   713.9 - * it under the terms of the GNU General Public License as published by
  713.10 - * the Free Software Foundation, version 2 of the License.
  713.11 - *
  713.12 - * This program is distributed in the hope that it will be useful,
  713.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  713.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  713.15 - * GNU General Public License for more details.
  713.16 - *
  713.17 - * You should have received a copy of the GNU General Public License
  713.18 - * along with this program. Look for COPYING file in the top folder.
  713.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  713.20 - */
  713.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  713.22 -
  713.23 -import org.apidesign.bck2brwsr.vmtest.*;
  713.24 -import java.lang.reflect.Method;
  713.25 -import java.util.ArrayList;
  713.26 -import java.util.List;
  713.27 -import org.apidesign.bck2brwsr.launcher.Launcher;
  713.28 -import org.testng.Assert;
  713.29 -import org.testng.ITest;
  713.30 -import org.testng.annotations.Factory;
  713.31 -import org.testng.annotations.Test;
  713.32 -
  713.33 -/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
  713.34 - * in provided class and builds set of tests that compare the computations
  713.35 - * in real as well as JavaScript virtual machines. Use as:<pre>
  713.36 - * {@code @}{@link Factory} public static create() {
  713.37 - *   return @{link VMTest}.{@link #create(YourClass.class);
  713.38 - * }</pre>
  713.39 - *
  713.40 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  713.41 - */
  713.42 -public final class CompareCase implements ITest {
  713.43 -    private final Bck2BrwsrCase first, second;
  713.44 -    private final Method m;
  713.45 -    
  713.46 -    private CompareCase(Method m, Bck2BrwsrCase first, Bck2BrwsrCase second) {
  713.47 -        this.first = first;
  713.48 -        this.second = second;
  713.49 -        this.m = m;
  713.50 -    }
  713.51 -
  713.52 -    /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
  713.53 -     * instances of tests. Each instance runs the test in different virtual
  713.54 -     * machine and at the end they compare the results.
  713.55 -     * 
  713.56 -     * @param clazz the class to inspect
  713.57 -     * @return the set of created tests
  713.58 -     */
  713.59 -    public static Object[] create(Class<?> clazz) {
  713.60 -        Method[] arr = clazz.getMethods();
  713.61 -        List<Object> ret = new ArrayList<>();
  713.62 -        
  713.63 -        final LaunchSetup l = LaunchSetup.INSTANCE;
  713.64 -        ret.add(l);
  713.65 -        
  713.66 -        String[] brwsr;
  713.67 -        {
  713.68 -            String p = System.getProperty("vmtest.brwsrs");
  713.69 -            if (p != null) {
  713.70 -                brwsr = p.split(",");
  713.71 -            } else {
  713.72 -                brwsr = new String[0];
  713.73 -            }
  713.74 -        }
  713.75 -        
  713.76 -        for (Method m : arr) {
  713.77 -            registerCompareCases(m, l, ret, brwsr);
  713.78 -            registerBrwsrCases(m, l, ret, brwsr);
  713.79 -        }
  713.80 -        return ret.toArray();
  713.81 -    }
  713.82 -
  713.83 -    /** Test that compares the previous results.
  713.84 -     * @throws Throwable 
  713.85 -     */
  713.86 -    @Test(dependsOnGroups = "run") public void compareResults() throws Throwable {
  713.87 -        Object v1 = first.value;
  713.88 -        Object v2 = second.value;
  713.89 -        if (v1 != null) {
  713.90 -            v1 = v1.toString();
  713.91 -        } else {
  713.92 -            v1 = "null";
  713.93 -        }
  713.94 -        try {
  713.95 -            Assert.assertEquals(v2, v1, "Comparing results");
  713.96 -        } catch (AssertionError e) {
  713.97 -            StringBuilder sb = new StringBuilder();
  713.98 -            sb.append(e.getMessage());
  713.99 -            Bck2BrwsrCase.dumpJS(sb, second);
 713.100 -            throw new AssertionError(sb.toString());
 713.101 -        }
 713.102 -    }
 713.103 -    
 713.104 -    /** Test name.
 713.105 -     * @return name of the tested method followed by a suffix
 713.106 -     */
 713.107 -    @Override
 713.108 -    public String getTestName() {
 713.109 -        return m.getName() + "[Compare " + second.typeName() + "]";
 713.110 -    }
 713.111 -    
 713.112 -    private static void registerCompareCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
 713.113 -        Compare c = m.getAnnotation(Compare.class);
 713.114 -        if (c == null) {
 713.115 -            return;
 713.116 -        }
 713.117 -        final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false, null, null);
 713.118 -        ret.add(real);
 713.119 -        if (c.scripting()) {
 713.120 -            final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false, null, null);
 713.121 -            ret.add(js);
 713.122 -            ret.add(new CompareCase(m, real, js));
 713.123 -        }
 713.124 -        for (String b : brwsr) {
 713.125 -            final Launcher s = l.brwsr(b);
 713.126 -            ret.add(s);
 713.127 -            final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false, null, null);
 713.128 -            ret.add(cse);
 713.129 -            ret.add(new CompareCase(m, real, cse));
 713.130 -        }
 713.131 -    }
 713.132 -    private static void registerBrwsrCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
 713.133 -        BrwsrTest c = m.getAnnotation(BrwsrTest.class);
 713.134 -        if (c == null) {
 713.135 -            return;
 713.136 -        }
 713.137 -        HtmlFragment f = m.getAnnotation(HtmlFragment.class);
 713.138 -        if (f == null) {
 713.139 -            f = m.getDeclaringClass().getAnnotation(HtmlFragment.class);
 713.140 -        }
 713.141 -        Http.Resource[] r = {};
 713.142 -        Http h = m.getAnnotation(Http.class);
 713.143 -        if (h == null) {
 713.144 -            h = m.getDeclaringClass().getAnnotation(Http.class);
 713.145 -            if (h != null) {
 713.146 -                r = h.value();
 713.147 -            }
 713.148 -        } else {
 713.149 -            r = h.value();
 713.150 -        }
 713.151 -        if (brwsr.length == 0) {
 713.152 -            final Launcher s = l.brwsr(null);
 713.153 -            ret.add(s);
 713.154 -            ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true, f, r));
 713.155 -        } else {
 713.156 -            for (String b : brwsr) {
 713.157 -                final Launcher s = l.brwsr(b);
 713.158 -                ret.add(s);
 713.159 -                ret.add(new Bck2BrwsrCase(m, b, s, true, f, r));
 713.160 -            }
 713.161 -        }
 713.162 -    }
 713.163 -}
   714.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/GenerateZip.java	Mon Feb 25 19:00:08 2013 +0100
   714.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   714.3 @@ -1,36 +0,0 @@
   714.4 -/**
   714.5 - * Back 2 Browser Bytecode Translator
   714.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   714.7 - *
   714.8 - * This program is free software: you can redistribute it and/or modify
   714.9 - * it under the terms of the GNU General Public License as published by
  714.10 - * the Free Software Foundation, version 2 of the License.
  714.11 - *
  714.12 - * This program is distributed in the hope that it will be useful,
  714.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  714.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  714.15 - * GNU General Public License for more details.
  714.16 - *
  714.17 - * You should have received a copy of the GNU General Public License
  714.18 - * along with this program. Look for COPYING file in the top folder.
  714.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  714.20 - */
  714.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  714.22 -
  714.23 -import java.lang.annotation.Retention;
  714.24 -import java.lang.annotation.RetentionPolicy;
  714.25 -
  714.26 -/** Annotation to generate a ZIP or JAR file during build.
  714.27 - *
  714.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  714.29 - */
  714.30 -@Retention(RetentionPolicy.SOURCE)
  714.31 -@interface GenerateZip {
  714.32 -    String name();
  714.33 -    
  714.34 -    /** manifest for the file */
  714.35 -    String manifest() default "";
  714.36 -
  714.37 -    /** Array of names (at odd positions) and their content (on even) */
  714.38 -    String[] contents();
  714.39 -}
   715.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/GenerateZipProcessor.java	Mon Feb 25 19:00:08 2013 +0100
   715.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   715.3 @@ -1,101 +0,0 @@
   715.4 -/**
   715.5 - * Back 2 Browser Bytecode Translator
   715.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   715.7 - *
   715.8 - * This program is free software: you can redistribute it and/or modify
   715.9 - * it under the terms of the GNU General Public License as published by
  715.10 - * the Free Software Foundation, version 2 of the License.
  715.11 - *
  715.12 - * This program is distributed in the hope that it will be useful,
  715.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  715.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  715.15 - * GNU General Public License for more details.
  715.16 - *
  715.17 - * You should have received a copy of the GNU General Public License
  715.18 - * along with this program. Look for COPYING file in the top folder.
  715.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  715.20 - */
  715.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  715.22 -
  715.23 -import java.io.ByteArrayInputStream;
  715.24 -import java.io.IOException;
  715.25 -import java.io.OutputStream;
  715.26 -import java.util.Set;
  715.27 -import java.util.jar.JarEntry;
  715.28 -import java.util.jar.JarOutputStream;
  715.29 -import java.util.jar.Manifest;
  715.30 -import javax.annotation.processing.AbstractProcessor;
  715.31 -import javax.annotation.processing.Filer;
  715.32 -import javax.annotation.processing.Processor;
  715.33 -import javax.annotation.processing.RoundEnvironment;
  715.34 -import javax.annotation.processing.SupportedAnnotationTypes;
  715.35 -import javax.lang.model.element.Element;
  715.36 -import javax.lang.model.element.ElementKind;
  715.37 -import javax.lang.model.element.PackageElement;
  715.38 -import javax.lang.model.element.TypeElement;
  715.39 -import javax.tools.Diagnostic;
  715.40 -import javax.tools.FileObject;
  715.41 -import javax.tools.StandardLocation;
  715.42 -import org.openide.util.lookup.ServiceProvider;
  715.43 -
  715.44 -/**
  715.45 - *
  715.46 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  715.47 - */
  715.48 -@ServiceProvider(service = Processor.class)
  715.49 -@SupportedAnnotationTypes("org.apidesign.bck2brwsr.vmtest.impl.GenerateZip")
  715.50 -public class GenerateZipProcessor extends AbstractProcessor {
  715.51 -
  715.52 -    @Override
  715.53 -    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  715.54 -        for (Element e : roundEnv.getElementsAnnotatedWith(GenerateZip.class)) {
  715.55 -            GenerateZip gz = e.getAnnotation(GenerateZip.class);
  715.56 -            if (gz == null) {
  715.57 -                continue;
  715.58 -            }
  715.59 -            PackageElement pe = findPackage(e);
  715.60 -            try {
  715.61 -                generateJar(pe, gz, e);
  715.62 -            } catch (IOException ex) {
  715.63 -                processingEnv.getMessager().printMessage(
  715.64 -                    Diagnostic.Kind.ERROR, 
  715.65 -                    "Can't generate JAR " + gz.name() + ": " + ex.getMessage()
  715.66 -                );
  715.67 -            }
  715.68 -        }
  715.69 -        return true;
  715.70 -    }
  715.71 -
  715.72 -    private static PackageElement findPackage(Element e) {
  715.73 -        while (e.getKind() != ElementKind.PACKAGE) {
  715.74 -            e = e.getEnclosingElement();
  715.75 -        }
  715.76 -        return (PackageElement)e;
  715.77 -    }
  715.78 -
  715.79 -    private void generateJar(PackageElement pe, GenerateZip gz, Element e) throws IOException {
  715.80 -        final Filer filer = processingEnv.getFiler();
  715.81 -        FileObject res = filer.createResource(
  715.82 -            StandardLocation.CLASS_OUTPUT, 
  715.83 -            pe.getQualifiedName().toString(), 
  715.84 -            gz.name(), e
  715.85 -        );
  715.86 -        OutputStream os = res.openOutputStream();
  715.87 -        JarOutputStream jar;
  715.88 -        if (gz.manifest().isEmpty()) {
  715.89 -            jar = new JarOutputStream(os);
  715.90 -        } else {
  715.91 -            Manifest mf = new Manifest(new ByteArrayInputStream(gz.manifest().getBytes("UTF-8")));
  715.92 -            jar = new JarOutputStream(os, mf);
  715.93 -        }
  715.94 -        String[] arr = gz.contents();
  715.95 -        for (int i = 0; i < arr.length; i += 2) {
  715.96 -            JarEntry je = new JarEntry(arr[i]);
  715.97 -            jar.putNextEntry(je);
  715.98 -            jar.write(arr[i + 1].getBytes("UTF-8"));
  715.99 -            jar.closeEntry();
 715.100 -        }
 715.101 -        jar.close();
 715.102 -    }
 715.103 -
 715.104 -}
   716.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Mon Feb 25 19:00:08 2013 +0100
   716.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   716.3 @@ -1,78 +0,0 @@
   716.4 -/**
   716.5 - * Back 2 Browser Bytecode Translator
   716.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   716.7 - *
   716.8 - * This program is free software: you can redistribute it and/or modify
   716.9 - * it under the terms of the GNU General Public License as published by
  716.10 - * the Free Software Foundation, version 2 of the License.
  716.11 - *
  716.12 - * This program is distributed in the hope that it will be useful,
  716.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  716.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  716.15 - * GNU General Public License for more details.
  716.16 - *
  716.17 - * You should have received a copy of the GNU General Public License
  716.18 - * along with this program. Look for COPYING file in the top folder.
  716.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  716.20 - */
  716.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  716.22 -
  716.23 -import java.io.IOException;
  716.24 -import java.util.LinkedHashMap;
  716.25 -import java.util.Map;
  716.26 -import org.apidesign.bck2brwsr.launcher.Launcher;
  716.27 -import org.testng.annotations.AfterGroups;
  716.28 -import org.testng.annotations.BeforeGroups;
  716.29 -
  716.30 -/**
  716.31 - *
  716.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  716.33 - */
  716.34 -public final class LaunchSetup {
  716.35 -    static LaunchSetup INSTANCE = new LaunchSetup();
  716.36 -    
  716.37 -    private Launcher js;
  716.38 -    private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
  716.39 -    
  716.40 -    private LaunchSetup() {
  716.41 -    }
  716.42 -    
  716.43 -    public Launcher javaScript() {
  716.44 -        return js(true);
  716.45 -    } 
  716.46 -    private synchronized  Launcher js(boolean create) {
  716.47 -        if (js == null && create) {
  716.48 -            js = Launcher.createJavaScript();
  716.49 -        }
  716.50 -        return js;
  716.51 -    } 
  716.52 -    
  716.53 -    public synchronized Launcher brwsr(String cmd) {
  716.54 -        Launcher s = brwsrs.get(cmd);
  716.55 -        if (s == null) {
  716.56 -            s = Launcher.createBrowser(cmd);
  716.57 -            brwsrs.put(cmd, s);
  716.58 -        }
  716.59 -        return s;
  716.60 -    }
  716.61 -
  716.62 -    @BeforeGroups("run")
  716.63 -    public void initializeLauncher() throws IOException {
  716.64 -        if (js(false) != null) {
  716.65 -            js(true).initialize();
  716.66 -        }
  716.67 -        for (Launcher launcher : brwsrs.values()) {
  716.68 -            launcher.initialize();
  716.69 -        }
  716.70 -    }
  716.71 -
  716.72 -    @AfterGroups("run")
  716.73 -    public void shutDownLauncher() throws IOException, InterruptedException {
  716.74 -        if (js(false) != null) {
  716.75 -            js(true).shutdown();
  716.76 -        }
  716.77 -        for (Launcher launcher : brwsrs.values()) {
  716.78 -            launcher.shutdown();
  716.79 -        }
  716.80 -    }
  716.81 -}
   717.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/AssertionTest.java	Mon Feb 25 19:00:08 2013 +0100
   717.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   717.3 @@ -1,43 +0,0 @@
   717.4 -/**
   717.5 - * Back 2 Browser Bytecode Translator
   717.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   717.7 - *
   717.8 - * This program is free software: you can redistribute it and/or modify
   717.9 - * it under the terms of the GNU General Public License as published by
  717.10 - * the Free Software Foundation, version 2 of the License.
  717.11 - *
  717.12 - * This program is distributed in the hope that it will be useful,
  717.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  717.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  717.15 - * GNU General Public License for more details.
  717.16 - *
  717.17 - * You should have received a copy of the GNU General Public License
  717.18 - * along with this program. Look for COPYING file in the top folder.
  717.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  717.20 - */
  717.21 -package org.apidesign.bck2brwsr.tck;
  717.22 -
  717.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  717.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  717.25 -import org.testng.annotations.Factory;
  717.26 -
  717.27 -/**
  717.28 - *
  717.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  717.30 - */
  717.31 -public class AssertionTest {
  717.32 -
  717.33 -    @Compare public Object checkAssert() throws ClassNotFoundException {
  717.34 -        try {
  717.35 -            assert false : "Is assertion status on?";
  717.36 -            return null;
  717.37 -        } catch (AssertionError ex) {
  717.38 -            return ex.getClass().getName();
  717.39 -        }
  717.40 -    }
  717.41 -    
  717.42 -    @Factory
  717.43 -    public static Object[] create() {
  717.44 -        return VMTest.create(AssertionTest.class);
  717.45 -    }
  717.46 -}
   718.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java	Mon Feb 25 19:00:08 2013 +0100
   718.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   718.3 @@ -1,57 +0,0 @@
   718.4 -/**
   718.5 - * Back 2 Browser Bytecode Translator
   718.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   718.7 - *
   718.8 - * This program is free software: you can redistribute it and/or modify
   718.9 - * it under the terms of the GNU General Public License as published by
  718.10 - * the Free Software Foundation, version 2 of the License.
  718.11 - *
  718.12 - * This program is distributed in the hope that it will be useful,
  718.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  718.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  718.15 - * GNU General Public License for more details.
  718.16 - *
  718.17 - * You should have received a copy of the GNU General Public License
  718.18 - * along with this program. Look for COPYING file in the top folder.
  718.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  718.20 - */
  718.21 -package org.apidesign.bck2brwsr.tck;
  718.22 -
  718.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  718.24 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  718.25 -import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
  718.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  718.27 -import org.testng.annotations.Factory;
  718.28 -
  718.29 -/**
  718.30 - *
  718.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  718.32 - */
  718.33 -public class BrwsrCheckTest {
  718.34 -
  718.35 -    @BrwsrTest public void assertWindowObjectIsDefined() {
  718.36 -        assert window() != null : "No window object found!";
  718.37 -    }
  718.38 -
  718.39 -    
  718.40 -    
  718.41 -    
  718.42 -    @HtmlFragment("<h1 id='hello'>\n"
  718.43 -        + "Hello!\n"
  718.44 -        + "</h1>\n")
  718.45 -    @BrwsrTest public void accessProvidedFragment() {
  718.46 -        assert getElementById("hello") != null : "Element with 'hello' ID found";
  718.47 -    }
  718.48 -    
  718.49 -    @Factory
  718.50 -    public static Object[] create() {
  718.51 -        return VMTest.create(BrwsrCheckTest.class);
  718.52 -    }
  718.53 -    
  718.54 -
  718.55 -    @JavaScriptBody(args = {}, body = "return window;")
  718.56 -    private static native Object window();
  718.57 -
  718.58 -    @JavaScriptBody(args = { "id" }, body = "return window.document.getElementById(id);")
  718.59 -    private static native Object getElementById(String id);
  718.60 -}
   719.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ByteArithmeticTest.java	Mon Feb 25 19:00:08 2013 +0100
   719.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   719.3 @@ -1,102 +0,0 @@
   719.4 -/**
   719.5 - * Back 2 Browser Bytecode Translator
   719.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   719.7 - *
   719.8 - * This program is free software: you can redistribute it and/or modify
   719.9 - * it under the terms of the GNU General Public License as published by
  719.10 - * the Free Software Foundation, version 2 of the License.
  719.11 - *
  719.12 - * This program is distributed in the hope that it will be useful,
  719.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  719.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  719.15 - * GNU General Public License for more details.
  719.16 - *
  719.17 - * You should have received a copy of the GNU General Public License
  719.18 - * along with this program. Look for COPYING file in the top folder.
  719.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  719.20 - */
  719.21 -package org.apidesign.bck2brwsr.tck;
  719.22 -
  719.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  719.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  719.25 -import org.testng.annotations.Factory;
  719.26 -
  719.27 -/**
  719.28 - *
  719.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  719.30 - */
  719.31 -public class ByteArithmeticTest {
  719.32 -    
  719.33 -    private static byte add(byte x, byte y) {
  719.34 -        return (byte)(x + y);
  719.35 -    }
  719.36 -    
  719.37 -    private static byte sub(byte x, byte y) {
  719.38 -        return (byte)(x - y);
  719.39 -    }
  719.40 -    
  719.41 -    private static byte mul(byte x, byte y) {
  719.42 -        return (byte)(x * y);
  719.43 -    }
  719.44 -    
  719.45 -    private static byte div(byte x, byte y) {
  719.46 -        return (byte)(x / y);
  719.47 -    }
  719.48 -    
  719.49 -    private static byte mod(byte x, byte y) {
  719.50 -        return (byte)(x % y);
  719.51 -    }
  719.52 -    
  719.53 -    @Compare public byte conversion() {
  719.54 -        return (byte)123456;
  719.55 -    }
  719.56 -    
  719.57 -    @Compare public byte addOverflow() {
  719.58 -        return add(Byte.MAX_VALUE, (byte)1);
  719.59 -    }
  719.60 -    
  719.61 -    @Compare public byte subUnderflow() {
  719.62 -        return sub(Byte.MIN_VALUE, (byte)1);
  719.63 -    }
  719.64 -    
  719.65 -    @Compare public byte addMaxByteAndMaxByte() {
  719.66 -        return add(Byte.MAX_VALUE, Byte.MAX_VALUE);
  719.67 -    }
  719.68 -    
  719.69 -    @Compare public byte subMinByteAndMinByte() {
  719.70 -        return sub(Byte.MIN_VALUE, Byte.MIN_VALUE);
  719.71 -    }
  719.72 -    
  719.73 -    @Compare public byte multiplyMaxByte() {
  719.74 -        return mul(Byte.MAX_VALUE, (byte)2);
  719.75 -    }
  719.76 -    
  719.77 -    @Compare public byte multiplyMaxByteAndMaxByte() {
  719.78 -        return mul(Byte.MAX_VALUE, Byte.MAX_VALUE);
  719.79 -    }
  719.80 -    
  719.81 -    @Compare public byte multiplyMinByte() {
  719.82 -        return mul(Byte.MIN_VALUE, (byte)2);
  719.83 -    }
  719.84 -    
  719.85 -    @Compare public byte multiplyMinByteAndMinByte() {
  719.86 -        return mul(Byte.MIN_VALUE, Byte.MIN_VALUE);
  719.87 -    }
  719.88 -    
  719.89 -    @Compare public byte multiplyPrecision() {
  719.90 -        return mul((byte)17638, (byte)1103);
  719.91 -    }
  719.92 -    
  719.93 -    @Compare public byte division() {
  719.94 -        return div((byte)1, (byte)2);
  719.95 -    }
  719.96 -    
  719.97 -    @Compare public byte divisionReminder() {
  719.98 -        return mod((byte)1, (byte)2);
  719.99 -    }
 719.100 -    
 719.101 -    @Factory
 719.102 -    public static Object[] create() {
 719.103 -        return VMTest.create(ByteArithmeticTest.class);
 719.104 -    }
 719.105 -}
   720.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CloneTest.java	Mon Feb 25 19:00:08 2013 +0100
   720.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   720.3 @@ -1,73 +0,0 @@
   720.4 -/**
   720.5 - * Back 2 Browser Bytecode Translator
   720.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   720.7 - *
   720.8 - * This program is free software: you can redistribute it and/or modify
   720.9 - * it under the terms of the GNU General Public License as published by
  720.10 - * the Free Software Foundation, version 2 of the License.
  720.11 - *
  720.12 - * This program is distributed in the hope that it will be useful,
  720.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  720.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  720.15 - * GNU General Public License for more details.
  720.16 - *
  720.17 - * You should have received a copy of the GNU General Public License
  720.18 - * along with this program. Look for COPYING file in the top folder.
  720.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  720.20 - */
  720.21 -package org.apidesign.bck2brwsr.tck;
  720.22 -
  720.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  720.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  720.25 -import org.testng.annotations.Factory;
  720.26 -
  720.27 -/**
  720.28 - *
  720.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  720.30 - */
  720.31 -public class CloneTest {
  720.32 -    private int value;
  720.33 -    
  720.34 -    @Compare
  720.35 -    public Object notSupported() throws CloneNotSupportedException {
  720.36 -        return this.clone();
  720.37 -    }
  720.38 -
  720.39 -    @Compare public String sameClass() throws CloneNotSupportedException {
  720.40 -        return new Clnbl().clone().getClass().getName();
  720.41 -    }
  720.42 -
  720.43 -    @Compare public boolean differentInstance() throws CloneNotSupportedException {
  720.44 -        Clnbl orig = new Clnbl();
  720.45 -        return orig == orig.clone();
  720.46 -    }
  720.47 -
  720.48 -    @Compare public int sameReference() throws CloneNotSupportedException {
  720.49 -        CloneTest self = this;
  720.50 -        Clnbl orig = new Clnbl();
  720.51 -        self.value = 33;
  720.52 -        orig.ref = self;
  720.53 -        return ((Clnbl)orig.clone()).ref.value;
  720.54 -    }
  720.55 -
  720.56 -    @Compare public int sameValue() throws CloneNotSupportedException {
  720.57 -        Clnbl orig = new Clnbl();
  720.58 -        orig.value = 10;
  720.59 -        return ((Clnbl)orig.clone()).value;
  720.60 -    }
  720.61 -    
  720.62 -    @Factory
  720.63 -    public static Object[] create() {
  720.64 -        return VMTest.create(CloneTest.class);
  720.65 -    }
  720.66 -    
  720.67 -    public static final class Clnbl implements Cloneable {
  720.68 -        public CloneTest ref;
  720.69 -        private int value;
  720.70 -
  720.71 -        @Override
  720.72 -        public Object clone() throws CloneNotSupportedException {
  720.73 -            return super.clone();
  720.74 -        }
  720.75 -    }
  720.76 -}
   721.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareByteArrayTest.java	Mon Feb 25 19:00:08 2013 +0100
   721.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   721.3 @@ -1,93 +0,0 @@
   721.4 -/**
   721.5 - * Back 2 Browser Bytecode Translator
   721.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   721.7 - *
   721.8 - * This program is free software: you can redistribute it and/or modify
   721.9 - * it under the terms of the GNU General Public License as published by
  721.10 - * the Free Software Foundation, version 2 of the License.
  721.11 - *
  721.12 - * This program is distributed in the hope that it will be useful,
  721.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  721.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  721.15 - * GNU General Public License for more details.
  721.16 - *
  721.17 - * You should have received a copy of the GNU General Public License
  721.18 - * along with this program. Look for COPYING file in the top folder.
  721.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  721.20 - */
  721.21 -package org.apidesign.bck2brwsr.tck;
  721.22 -
  721.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  721.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  721.25 -import org.testng.annotations.Factory;
  721.26 -
  721.27 -/**
  721.28 - *
  721.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  721.30 - */
  721.31 -public class CompareByteArrayTest {
  721.32 -    @Compare public int byteArraySum() {
  721.33 -        byte[] arr = createArray();
  721.34 -        return sumByteArr(arr);
  721.35 -    }
  721.36 -    
  721.37 -    @Compare public int countZeros() {
  721.38 -        int zeros = 0;
  721.39 -        for (Byte b : createArray()) {
  721.40 -            if (b == 0) {
  721.41 -                zeros++;
  721.42 -            }
  721.43 -        }
  721.44 -        return zeros;
  721.45 -    }
  721.46 -    
  721.47 -    private static int sumByteArr(byte[] arr) {
  721.48 -        int sum = 0;
  721.49 -        for (int i = 0; i < arr.length; i++) {
  721.50 -            sum += arr[i];
  721.51 -        }
  721.52 -        return sum;
  721.53 -    }
  721.54 -    
  721.55 -    @Compare public String noOutOfBounds() {
  721.56 -        return atIndex(1);
  721.57 -    }
  721.58 -
  721.59 -    @Compare public String outOfBounds() {
  721.60 -        return atIndex(5);
  721.61 -    }
  721.62 -
  721.63 -    @Compare public String outOfBoundsMinus() {
  721.64 -        return atIndex(-1);
  721.65 -    }
  721.66 -
  721.67 -    @Compare public String toOfBounds() {
  721.68 -        return toIndex(5);
  721.69 -    }
  721.70 -
  721.71 -    @Compare public String toOfBoundsMinus() {
  721.72 -        return toIndex(-1);
  721.73 -    }
  721.74 -
  721.75 -    private static final int[] arr = { 0, 1, 2 };
  721.76 -    public static String atIndex(int at) {
  721.77 -        return "at@" + arr[at];
  721.78 -    }
  721.79 -    public static String toIndex(int at) {
  721.80 -        arr[at] = 10;
  721.81 -        return "ok";
  721.82 -    }
  721.83 -    
  721.84 -    
  721.85 -    @Factory
  721.86 -    public static Object[] create() {
  721.87 -        return VMTest.create(CompareByteArrayTest.class);
  721.88 -    }
  721.89 -
  721.90 -    private byte[] createArray() {
  721.91 -        byte[] arr = new byte[10];
  721.92 -        arr[5] = 3;
  721.93 -        arr[7] = 8;
  721.94 -        return arr;
  721.95 -    }
  721.96 -}
   722.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareHashTest.java	Mon Feb 25 19:00:08 2013 +0100
   722.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   722.3 @@ -1,50 +0,0 @@
   722.4 -/**
   722.5 - * Back 2 Browser Bytecode Translator
   722.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   722.7 - *
   722.8 - * This program is free software: you can redistribute it and/or modify
   722.9 - * it under the terms of the GNU General Public License as published by
  722.10 - * the Free Software Foundation, version 2 of the License.
  722.11 - *
  722.12 - * This program is distributed in the hope that it will be useful,
  722.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  722.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  722.15 - * GNU General Public License for more details.
  722.16 - *
  722.17 - * You should have received a copy of the GNU General Public License
  722.18 - * along with this program. Look for COPYING file in the top folder.
  722.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  722.20 - */
  722.21 -package org.apidesign.bck2brwsr.tck;
  722.22 -
  722.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  722.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  722.25 -import org.testng.annotations.Factory;
  722.26 -
  722.27 -/**
  722.28 - *
  722.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  722.30 - */
  722.31 -public class CompareHashTest {
  722.32 -    @Compare public int hashOfString() {
  722.33 -        return "Ahoj".hashCode();
  722.34 -    }
  722.35 -    
  722.36 -    @Compare public int hashRemainsYieldsZero() {
  722.37 -        Object o = new Object();
  722.38 -        return o.hashCode() - o.hashCode();
  722.39 -    }
  722.40 -    
  722.41 -    @Compare public int initializeInStatic() {
  722.42 -        return StaticUse.NON_NULL.hashCode() - StaticUse.NON_NULL.hashCode();
  722.43 -    }
  722.44 -    
  722.45 -    @Compare public int hashOfInt() {
  722.46 -        return Integer.valueOf(Integer.MAX_VALUE).hashCode();
  722.47 -    }
  722.48 -    
  722.49 -    @Factory
  722.50 -    public static Object[] create() {
  722.51 -        return VMTest.create(CompareHashTest.class);
  722.52 -    }
  722.53 -}
   723.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareIntArrayTest.java	Mon Feb 25 19:00:08 2013 +0100
   723.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   723.3 @@ -1,63 +0,0 @@
   723.4 -/**
   723.5 - * Back 2 Browser Bytecode Translator
   723.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   723.7 - *
   723.8 - * This program is free software: you can redistribute it and/or modify
   723.9 - * it under the terms of the GNU General Public License as published by
  723.10 - * the Free Software Foundation, version 2 of the License.
  723.11 - *
  723.12 - * This program is distributed in the hope that it will be useful,
  723.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  723.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  723.15 - * GNU General Public License for more details.
  723.16 - *
  723.17 - * You should have received a copy of the GNU General Public License
  723.18 - * along with this program. Look for COPYING file in the top folder.
  723.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  723.20 - */
  723.21 -package org.apidesign.bck2brwsr.tck;
  723.22 -
  723.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  723.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  723.25 -import org.testng.annotations.Factory;
  723.26 -
  723.27 -/**
  723.28 - *
  723.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  723.30 - */
  723.31 -public class CompareIntArrayTest {
  723.32 -    @Compare public int integerArraySum() {
  723.33 -        int[] arr = createArray();
  723.34 -        return sumIntArr(arr);
  723.35 -    }
  723.36 -    
  723.37 -    @Compare public int countZeros() {
  723.38 -        int zeros = 0;
  723.39 -        for (Integer i : createArray()) {
  723.40 -            if (i == 0) {
  723.41 -                zeros++;
  723.42 -            }
  723.43 -        }
  723.44 -        return zeros;
  723.45 -    }
  723.46 -    
  723.47 -    private static int sumIntArr(int[] arr) {
  723.48 -        int sum = 0;
  723.49 -        for (int i = 0; i < arr.length; i++) {
  723.50 -            sum += arr[i];
  723.51 -        }
  723.52 -        return sum;
  723.53 -    }
  723.54 -    
  723.55 -    @Factory
  723.56 -    public static Object[] create() {
  723.57 -        return VMTest.create(CompareIntArrayTest.class);
  723.58 -    }
  723.59 -
  723.60 -    private int[] createArray() {
  723.61 -        int[] arr = new int[10];
  723.62 -        arr[5] = 3;
  723.63 -        arr[7] = 8;
  723.64 -        return arr;
  723.65 -    }
  723.66 -}
   724.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Mon Feb 25 19:00:08 2013 +0100
   724.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   724.3 @@ -1,162 +0,0 @@
   724.4 -/**
   724.5 - * Back 2 Browser Bytecode Translator
   724.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   724.7 - *
   724.8 - * This program is free software: you can redistribute it and/or modify
   724.9 - * it under the terms of the GNU General Public License as published by
  724.10 - * the Free Software Foundation, version 2 of the License.
  724.11 - *
  724.12 - * This program is distributed in the hope that it will be useful,
  724.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  724.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  724.15 - * GNU General Public License for more details.
  724.16 - *
  724.17 - * You should have received a copy of the GNU General Public License
  724.18 - * along with this program. Look for COPYING file in the top folder.
  724.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  724.20 - */
  724.21 -package org.apidesign.bck2brwsr.tck;
  724.22 -
  724.23 -import java.io.UnsupportedEncodingException;
  724.24 -import java.net.MalformedURLException;
  724.25 -import java.net.URL;
  724.26 -import org.apidesign.bck2brwsr.vmtest.Compare;
  724.27 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  724.28 -import org.testng.annotations.Factory;
  724.29 -
  724.30 -/**
  724.31 - *
  724.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  724.33 - */
  724.34 -public class CompareStringsTest {
  724.35 -    @Compare public String firstChar() {
  724.36 -        return "" + ("Hello".toCharArray()[0]);
  724.37 -    }
  724.38 -    
  724.39 -    @Compare public String classCast() {
  724.40 -        Object o = firstChar();
  724.41 -        return String.class.cast(o);
  724.42 -    }
  724.43 -
  724.44 -    @Compare public String classCastThrown() {
  724.45 -        Object o = null;
  724.46 -        return String.class.cast(o);
  724.47 -    }
  724.48 -    
  724.49 -    @Compare public boolean equalToNull() {
  724.50 -        return "Ahoj".equals(null);
  724.51 -    }
  724.52 -    
  724.53 -    @Compare public int highByteLenght() {
  724.54 -        byte[] arr= { 77,97,110,105,102,101,115,116,45,86,101,114,115,105,111,110 };
  724.55 -        return new String(arr, 0).length();
  724.56 -    }
  724.57 -    
  724.58 -    @Compare public String highByte() {
  724.59 -        byte[] arr= { 77,97,110,105,102,101,115,116,45,86,101,114,115,105,111,110 };
  724.60 -        StringBuilder sb = new StringBuilder();
  724.61 -        sb.append("pref:");
  724.62 -        sb.append(new String(arr, 0));
  724.63 -        return sb.toString();
  724.64 -    }
  724.65 -    
  724.66 -    @Compare public static Object compareURLs() throws MalformedURLException {
  724.67 -        return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
  724.68 -    }
  724.69 -    
  724.70 -    @Compare public String deleteLastTwoCharacters() {
  724.71 -        StringBuilder sb = new StringBuilder();
  724.72 -        sb.append("453.0");
  724.73 -        if (sb.toString().endsWith(".0")) {
  724.74 -            final int l = sb.length();
  724.75 -            sb.delete(l - 2, l);
  724.76 -        }
  724.77 -        return sb.toString().toString();
  724.78 -    }
  724.79 -    
  724.80 -    @Compare public String nameOfStringClass() throws Exception {
  724.81 -        return Class.forName("java.lang.String").getName();
  724.82 -    }
  724.83 -    @Compare public String nameOfArrayClass() throws Exception {
  724.84 -        return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
  724.85 -    }
  724.86 -    
  724.87 -    @Compare public String lowerHello() {
  724.88 -        return "HeLlO".toLowerCase();
  724.89 -    }
  724.90 -    
  724.91 -    @Compare public String lowerA() {
  724.92 -        return String.valueOf(Character.toLowerCase('A')).toString();
  724.93 -    }
  724.94 -    @Compare public String upperHello() {
  724.95 -        return "hello".toUpperCase();
  724.96 -    }
  724.97 -    
  724.98 -    @Compare public String upperA() {
  724.99 -        return String.valueOf(Character.toUpperCase('a')).toString();
 724.100 -    }
 724.101 -    
 724.102 -    @Compare public boolean matchRegExp() throws Exception {
 724.103 -        return "58038503".matches("\\d*");
 724.104 -    }
 724.105 -
 724.106 -    @Compare public boolean doesNotMatchRegExp() throws Exception {
 724.107 -        return "58038503GH".matches("\\d*");
 724.108 -    }
 724.109 -
 724.110 -    @Compare public boolean doesNotMatchRegExpFully() throws Exception {
 724.111 -        return "Hello".matches("Hell");
 724.112 -    }
 724.113 -    
 724.114 -    @Compare public String emptyCharArray() {
 724.115 -        char[] arr = new char[10];
 724.116 -        return new String(arr);
 724.117 -    }
 724.118 -    
 724.119 -    @Compare public String variousCharacterTests() throws Exception {
 724.120 -        StringBuilder sb = new StringBuilder();
 724.121 -        
 724.122 -        sb.append(Character.isUpperCase('a'));
 724.123 -        sb.append(Character.isUpperCase('A'));
 724.124 -        sb.append(Character.isLowerCase('a'));
 724.125 -        sb.append(Character.isLowerCase('A'));
 724.126 -        
 724.127 -        sb.append(Character.isLetter('A'));
 724.128 -        sb.append(Character.isLetterOrDigit('9'));
 724.129 -        sb.append(Character.isLetterOrDigit('A'));
 724.130 -        sb.append(Character.isLetter('0'));
 724.131 -        
 724.132 -        return sb.toString().toString();
 724.133 -    }
 724.134 -        
 724.135 -    @Compare
 724.136 -    public String nullFieldInitialized() {
 724.137 -        NullField nf = new NullField();
 724.138 -        return ("" + nf.name).toString();
 724.139 -    }
 724.140 -    @Compare
 724.141 -    public String toUTFString() throws UnsupportedEncodingException {
 724.142 -        byte[] arr = {
 724.143 -            (byte) -59, (byte) -67, (byte) 108, (byte) 117, (byte) -59, (byte) -91,
 724.144 -            (byte) 111, (byte) 117, (byte) -60, (byte) -115, (byte) 107, (byte) -61,
 724.145 -            (byte) -67, (byte) 32, (byte) 107, (byte) -59, (byte) -81, (byte) -59,
 724.146 -            (byte) -120
 724.147 -        };
 724.148 -        return new String(arr, "utf-8");
 724.149 -    }
 724.150 -
 724.151 -    @Compare
 724.152 -    public int stringToBytesLenght() throws UnsupportedEncodingException {
 724.153 -        return "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("utf8").length;
 724.154 -    }
 724.155 -
 724.156 -    @Factory
 724.157 -    public static Object[] create() {
 724.158 -        return VMTest.create(CompareStringsTest.class);
 724.159 -    }
 724.160 -
 724.161 -    private static final class NullField {
 724.162 -
 724.163 -        String name;
 724.164 -    }
 724.165 -}
   725.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java	Mon Feb 25 19:00:08 2013 +0100
   725.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   725.3 @@ -1,106 +0,0 @@
   725.4 -/**
   725.5 - * Back 2 Browser Bytecode Translator
   725.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   725.7 - *
   725.8 - * This program is free software: you can redistribute it and/or modify
   725.9 - * it under the terms of the GNU General Public License as published by
  725.10 - * the Free Software Foundation, version 2 of the License.
  725.11 - *
  725.12 - * This program is distributed in the hope that it will be useful,
  725.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  725.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  725.15 - * GNU General Public License for more details.
  725.16 - *
  725.17 - * You should have received a copy of the GNU General Public License
  725.18 - * along with this program. Look for COPYING file in the top folder.
  725.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  725.20 - */
  725.21 -package org.apidesign.bck2brwsr.tck;
  725.22 -
  725.23 -import java.io.InputStream;
  725.24 -import java.net.URL;
  725.25 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  725.26 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  725.27 -import org.apidesign.bck2brwsr.vmtest.Http;
  725.28 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  725.29 -import org.testng.annotations.Factory;
  725.30 -
  725.31 -/**
  725.32 - *
  725.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  725.34 - */
  725.35 -public class HttpResourceTest {
  725.36 -    
  725.37 -    @Http({
  725.38 -        @Http.Resource(path = "/xhr", content = "Hello Brwsr!", mimeType = "text/plain")
  725.39 -    })
  725.40 -    @BrwsrTest
  725.41 -    
  725.42 -    
  725.43 -    public String testReadContentViaXHR() throws Exception {
  725.44 -        String msg = read("/xhr");
  725.45 -        assert "Hello Brwsr!".equals(msg) : "The message was " + msg;
  725.46 -        return msg;
  725.47 -    }
  725.48 -
  725.49 -    @Http({
  725.50 -        @Http.Resource(path = "/url", content = "Hello via URL!", mimeType = "text/plain")
  725.51 -    })
  725.52 -    @BrwsrTest
  725.53 -    public String testReadContentViaURL() throws Exception {
  725.54 -        URL url = new URL("http:/url");
  725.55 -        String msg = (String) url.getContent();
  725.56 -        assert "Hello via URL!".equals(msg) : "The message was " + msg;
  725.57 -        return msg;
  725.58 -    }
  725.59 -    @Http({
  725.60 -        @Http.Resource(path = "/url", content = "Hello via URL!", mimeType = "text/plain")
  725.61 -    })
  725.62 -    @BrwsrTest
  725.63 -    public String testReadContentViaURLWithStringParam() throws Exception {
  725.64 -        URL url = new URL("http:/url");
  725.65 -        String msg = (String) url.getContent(new Class[] { String.class });
  725.66 -        assert "Hello via URL!".equals(msg) : "The message was " + msg;
  725.67 -        return msg;
  725.68 -    }
  725.69 -
  725.70 -    @Http({
  725.71 -        @Http.Resource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
  725.72 -    })
  725.73 -    @BrwsrTest
  725.74 -    public void testReadByte() throws Exception {
  725.75 -        URL url = new URL("http:/bytes");
  725.76 -        final Object res = url.getContent(new Class[] { byte[].class });
  725.77 -        assert res instanceof byte[] : "Expecting byte[]: " + res;
  725.78 -        byte[] arr = (byte[]) res;
  725.79 -        assert arr.length == 1 : "One byte " + arr.length;
  725.80 -        assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
  725.81 -    }
  725.82 -
  725.83 -    @Http({
  725.84 -        @Http.Resource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
  725.85 -    })
  725.86 -    @BrwsrTest
  725.87 -    public void testReadByteViaInputStream() throws Exception {
  725.88 -        URL url = new URL("http:/bytes");
  725.89 -        InputStream is = url.openStream();
  725.90 -        byte[] arr = new byte[10];
  725.91 -        int len = is.read(arr);
  725.92 -        assert len == 1 : "One byte " + len;
  725.93 -        assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
  725.94 -    }
  725.95 -    
  725.96 -    @JavaScriptBody(args = { "url" }, body = 
  725.97 -          "var req = new XMLHttpRequest();\n"
  725.98 -        + "req.open('GET', url, false);\n"
  725.99 -        + "req.send();\n"
 725.100 -        + "return req.responseText;"
 725.101 -    )
 725.102 -    private static native String read(String url);
 725.103 -    
 725.104 -    
 725.105 -    @Factory
 725.106 -    public static Object[] create() {
 725.107 -        return VMTest.create(HttpResourceTest.class);
 725.108 -    }
 725.109 -}
   726.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceA.java	Mon Feb 25 19:00:08 2013 +0100
   726.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   726.3 @@ -1,34 +0,0 @@
   726.4 -/**
   726.5 - * Back 2 Browser Bytecode Translator
   726.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   726.7 - *
   726.8 - * This program is free software: you can redistribute it and/or modify
   726.9 - * it under the terms of the GNU General Public License as published by
  726.10 - * the Free Software Foundation, version 2 of the License.
  726.11 - *
  726.12 - * This program is distributed in the hope that it will be useful,
  726.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  726.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  726.15 - * GNU General Public License for more details.
  726.16 - *
  726.17 - * You should have received a copy of the GNU General Public License
  726.18 - * along with this program. Look for COPYING file in the top folder.
  726.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  726.20 - */
  726.21 -package org.apidesign.bck2brwsr.tck;
  726.22 -
  726.23 -/**
  726.24 - *
  726.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  726.26 - */
  726.27 -public class InheritanceA {
  726.28 -    private String name;
  726.29 -    
  726.30 -    public void setA(String n) {
  726.31 -        this.name = n;
  726.32 -    }
  726.33 -    
  726.34 -    public String getA() {
  726.35 -        return name;
  726.36 -    }
  726.37 -}
   727.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceB.java	Mon Feb 25 19:00:08 2013 +0100
   727.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   727.3 @@ -1,34 +0,0 @@
   727.4 -/**
   727.5 - * Back 2 Browser Bytecode Translator
   727.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   727.7 - *
   727.8 - * This program is free software: you can redistribute it and/or modify
   727.9 - * it under the terms of the GNU General Public License as published by
  727.10 - * the Free Software Foundation, version 2 of the License.
  727.11 - *
  727.12 - * This program is distributed in the hope that it will be useful,
  727.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  727.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  727.15 - * GNU General Public License for more details.
  727.16 - *
  727.17 - * You should have received a copy of the GNU General Public License
  727.18 - * along with this program. Look for COPYING file in the top folder.
  727.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  727.20 - */
  727.21 -package org.apidesign.bck2brwsr.tck;
  727.22 -
  727.23 -/**
  727.24 - *
  727.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  727.26 - */
  727.27 -public class InheritanceB extends InheritanceA {
  727.28 -    private String name;
  727.29 -    
  727.30 -    public void setB(String n) {
  727.31 -        this.name = n;
  727.32 -    }
  727.33 -    
  727.34 -    public String getB() {
  727.35 -        return name;
  727.36 -    }
  727.37 -}
   728.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/InheritanceTest.java	Mon Feb 25 19:00:08 2013 +0100
   728.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   728.3 @@ -1,41 +0,0 @@
   728.4 -/**
   728.5 - * Back 2 Browser Bytecode Translator
   728.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   728.7 - *
   728.8 - * This program is free software: you can redistribute it and/or modify
   728.9 - * it under the terms of the GNU General Public License as published by
  728.10 - * the Free Software Foundation, version 2 of the License.
  728.11 - *
  728.12 - * This program is distributed in the hope that it will be useful,
  728.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  728.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  728.15 - * GNU General Public License for more details.
  728.16 - *
  728.17 - * You should have received a copy of the GNU General Public License
  728.18 - * along with this program. Look for COPYING file in the top folder.
  728.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  728.20 - */
  728.21 -package org.apidesign.bck2brwsr.tck;
  728.22 -
  728.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  728.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  728.25 -import org.testng.annotations.Factory;
  728.26 -
  728.27 -/**
  728.28 - *
  728.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  728.30 - */
  728.31 -public class InheritanceTest {
  728.32 -
  728.33 -    @Compare public String checkFieldsIndependent() throws ClassNotFoundException {
  728.34 -        InheritanceB ib = new InheritanceB();
  728.35 -        ib.setA("A");
  728.36 -        ib.setB("B");
  728.37 -        return "A: " + ib.getA() + " B: " + ib.getB();
  728.38 -    }
  728.39 -    
  728.40 -    @Factory
  728.41 -    public static Object[] create() {
  728.42 -        return VMTest.create(InheritanceTest.class);
  728.43 -    }
  728.44 -}
   729.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Mon Feb 25 19:00:08 2013 +0100
   729.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   729.3 @@ -1,150 +0,0 @@
   729.4 -/**
   729.5 - * Back 2 Browser Bytecode Translator
   729.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   729.7 - *
   729.8 - * This program is free software: you can redistribute it and/or modify
   729.9 - * it under the terms of the GNU General Public License as published by
  729.10 - * the Free Software Foundation, version 2 of the License.
  729.11 - *
  729.12 - * This program is distributed in the hope that it will be useful,
  729.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  729.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  729.15 - * GNU General Public License for more details.
  729.16 - *
  729.17 - * You should have received a copy of the GNU General Public License
  729.18 - * along with this program. Look for COPYING file in the top folder.
  729.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  729.20 - */
  729.21 -package org.apidesign.bck2brwsr.tck;
  729.22 -
  729.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  729.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  729.25 -import org.testng.annotations.Factory;
  729.26 -
  729.27 -/**
  729.28 - *
  729.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  729.30 - */
  729.31 -public class IntegerArithmeticTest {
  729.32 -    
  729.33 -    private static int add(int x, int y) {
  729.34 -        return x + y;
  729.35 -    }
  729.36 -    
  729.37 -    private static int sub(int x, int y) {
  729.38 -        return x - y;
  729.39 -    }
  729.40 -    
  729.41 -    private static int mul(int x, int y) {
  729.42 -        return x * y;
  729.43 -    }
  729.44 -    
  729.45 -    private static int div(int x, int y) {
  729.46 -        return x / y;
  729.47 -    }
  729.48 -    
  729.49 -    private static int mod(int x, int y) {
  729.50 -        return x % y;
  729.51 -    }
  729.52 -    
  729.53 -    private static int neg(int x) {
  729.54 -        return (-x);
  729.55 -    }
  729.56 -    
  729.57 -    @Compare public int addOverflow() {
  729.58 -        return add(Integer.MAX_VALUE, 1);
  729.59 -    }
  729.60 -    
  729.61 -    @Compare public int subUnderflow() {
  729.62 -        return sub(Integer.MIN_VALUE, 1);
  729.63 -    }
  729.64 -    
  729.65 -    @Compare public int addMaxIntAndMaxInt() {
  729.66 -        return add(Integer.MAX_VALUE, Integer.MAX_VALUE);
  729.67 -    }
  729.68 -    
  729.69 -    @Compare public int subMinIntAndMinInt() {
  729.70 -        return sub(Integer.MIN_VALUE, Integer.MIN_VALUE);
  729.71 -    }
  729.72 -    
  729.73 -    @Compare public int multiplyMaxInt() {
  729.74 -        return mul(Integer.MAX_VALUE, 2);
  729.75 -    }
  729.76 -    
  729.77 -    @Compare public int multiplyMaxIntAndMaxInt() {
  729.78 -        return mul(Integer.MAX_VALUE, Integer.MAX_VALUE);
  729.79 -    }
  729.80 -    
  729.81 -    @Compare public int multiplyMinInt() {
  729.82 -        return mul(Integer.MIN_VALUE, 2);
  729.83 -    }
  729.84 -    
  729.85 -    @Compare public int multiplyMinIntAndMinInt() {
  729.86 -        return mul(Integer.MIN_VALUE, Integer.MIN_VALUE);
  729.87 -    }
  729.88 -    
  729.89 -    @Compare public int multiplyPrecision() {
  729.90 -        return mul(119106029, 1103515245);
  729.91 -    }
  729.92 -    
  729.93 -    @Compare public int division() {
  729.94 -        return div(1, 2);
  729.95 -    }
  729.96 -    
  729.97 -    @Compare public int divisionReminder() {
  729.98 -        return mod(1, 2);
  729.99 -    }
 729.100 -
 729.101 -    @Compare public int negativeDivision() {
 729.102 -        return div(-7, 3);
 729.103 -    }
 729.104 -
 729.105 -    @Compare public int negativeDivisionReminder() {
 729.106 -        return mod(-7, 3);
 729.107 -    }
 729.108 -
 729.109 -    @Compare public boolean divByZeroThrowsArithmeticException() {
 729.110 -        try {
 729.111 -            div(1, 0);
 729.112 -            return false;
 729.113 -        } catch (final ArithmeticException e) {
 729.114 -            return true;
 729.115 -        }
 729.116 -    }
 729.117 -
 729.118 -    @Compare public boolean modByZeroThrowsArithmeticException() {
 729.119 -        try {
 729.120 -            mod(1, 0);
 729.121 -            return false;
 729.122 -        } catch (final ArithmeticException e) {
 729.123 -            return true;
 729.124 -        }
 729.125 -    }
 729.126 -
 729.127 -    @Compare public int negate() {
 729.128 -        return neg(123456);
 729.129 -    }
 729.130 -    
 729.131 -    @Compare public int negateMaxInt() {
 729.132 -        return neg(Integer.MAX_VALUE);
 729.133 -    }
 729.134 -    
 729.135 -    @Compare public int negateMinInt() {
 729.136 -        return neg(Integer.MIN_VALUE);
 729.137 -    }
 729.138 -    
 729.139 -    @Compare public int sumTwoDimensions() {
 729.140 -        int[][] matrix = createMatrix(4, 3);
 729.141 -        matrix[0][0] += 10;
 729.142 -        return matrix[0][0];
 729.143 -    }
 729.144 -    
 729.145 -    static int[][] createMatrix(int x, int y) {
 729.146 -        return new int[x][y];
 729.147 -    }
 729.148 -    
 729.149 -    @Factory
 729.150 -    public static Object[] create() {
 729.151 -        return VMTest.create(IntegerArithmeticTest.class);
 729.152 -    }
 729.153 -}
   730.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java	Mon Feb 25 19:00:08 2013 +0100
   730.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   730.3 @@ -1,352 +0,0 @@
   730.4 -/**
   730.5 - * Back 2 Browser Bytecode Translator
   730.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   730.7 - *
   730.8 - * This program is free software: you can redistribute it and/or modify
   730.9 - * it under the terms of the GNU General Public License as published by
  730.10 - * the Free Software Foundation, version 2 of the License.
  730.11 - *
  730.12 - * This program is distributed in the hope that it will be useful,
  730.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  730.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  730.15 - * GNU General Public License for more details.
  730.16 - *
  730.17 - * You should have received a copy of the GNU General Public License
  730.18 - * along with this program. Look for COPYING file in the top folder.
  730.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  730.20 - */
  730.21 -package org.apidesign.bck2brwsr.tck;
  730.22 -
  730.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  730.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  730.25 -import org.testng.annotations.Factory;
  730.26 -
  730.27 -/**
  730.28 - *
  730.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  730.30 - */
  730.31 -public class LongArithmeticTest {
  730.32 -    
  730.33 -    private static long add(long x, long y) {
  730.34 -        return (x + y);
  730.35 -    }
  730.36 -    
  730.37 -    private static long sub(long x, long y) {
  730.38 -        return (x - y);
  730.39 -    }
  730.40 -    
  730.41 -    private static long mul(long x, long y) {
  730.42 -        return (x * y);
  730.43 -    }
  730.44 -    
  730.45 -    private static long div(long x, long y) {
  730.46 -        return (x / y);
  730.47 -    }
  730.48 -    
  730.49 -    private static long mod(long x, long y) {
  730.50 -        return (x % y);
  730.51 -    }
  730.52 -    
  730.53 -    private static long neg(long x) {
  730.54 -        return (-x);
  730.55 -    }
  730.56 -    
  730.57 -    private static long shl(long x, int b) {
  730.58 -        return (x << b);
  730.59 -    }
  730.60 -    
  730.61 -    private static long shr(long x, int b) {
  730.62 -        return (x >> b);
  730.63 -    }
  730.64 -    
  730.65 -    private static long ushr(long x, int b) {
  730.66 -        return (x >>> b);
  730.67 -    }
  730.68 -    
  730.69 -    private static long and(long x, long y) {
  730.70 -        return (x & y);
  730.71 -    }
  730.72 -    
  730.73 -    private static long or(long x, long y) {
  730.74 -        return (x | y);
  730.75 -    }
  730.76 -    
  730.77 -    private static long xor(long x, long y) {
  730.78 -        return (x ^ y);
  730.79 -    }
  730.80 -    
  730.81 -    public static int compare(long x, long y, int zero) {
  730.82 -        final int xyResult = compareL(x, y, zero);
  730.83 -        final int yxResult = compareL(y, x, zero);
  730.84 -
  730.85 -        return ((xyResult + yxResult) == 0) ? xyResult : -2;
  730.86 -    }
  730.87 -
  730.88 -    private static int compareL(long x, long y, int zero) {
  730.89 -        int result = -2;
  730.90 -        int trueCount = 0;
  730.91 -
  730.92 -        x += zero;
  730.93 -        if (x == y) {
  730.94 -            result = 0;
  730.95 -            ++trueCount;
  730.96 -        }
  730.97 -
  730.98 -        x += zero;
  730.99 -        if (x < y) {
 730.100 -            result = -1;
 730.101 -            ++trueCount;
 730.102 -        }
 730.103 -
 730.104 -        x += zero;
 730.105 -        if (x > y) {
 730.106 -            result = 1;
 730.107 -            ++trueCount;
 730.108 -        }
 730.109 -
 730.110 -        return (trueCount == 1) ? result : -2;
 730.111 -    }
 730.112 -    
 730.113 -    @Compare public long conversion() {
 730.114 -        return Long.MAX_VALUE;
 730.115 -    }
 730.116 -    
 730.117 -    @Compare public long negate1() {
 730.118 -        return neg(0x00fa37d7763e0ca1l);
 730.119 -    }
 730.120 -    
 730.121 -    @Compare public long negate2() {
 730.122 -        return neg(0x80fa37d7763e0ca1l);
 730.123 -    }
 730.124 -
 730.125 -    @Compare public long negate3() {
 730.126 -        return neg(0xfffffffffffffeddl);
 730.127 -    }
 730.128 -
 730.129 -    @Compare public long addOverflow() {
 730.130 -        return add(Long.MAX_VALUE, 1l);
 730.131 -    }
 730.132 -
 730.133 -    @Compare public long subUnderflow() {
 730.134 -        return sub(Long.MIN_VALUE, 1l);
 730.135 -    }
 730.136 -
 730.137 -    @Compare public long addMaxLongAndMaxLong() {
 730.138 -        return add(Long.MAX_VALUE, Long.MAX_VALUE);
 730.139 -    }
 730.140 -    
 730.141 -    @Compare public long subMinLongAndMinLong() {
 730.142 -        return sub(Long.MIN_VALUE, Long.MIN_VALUE);
 730.143 -    }
 730.144 -    
 730.145 -    @Compare public long subMinLongAndMaxLong() {
 730.146 -        return sub(Long.MIN_VALUE, Long.MAX_VALUE);
 730.147 -    }
 730.148 -
 730.149 -    @Compare public long multiplyMaxLong() {
 730.150 -        return mul(Long.MAX_VALUE, 2l);
 730.151 -    }
 730.152 -    
 730.153 -    @Compare public long multiplyMaxLongAndMaxLong() {
 730.154 -        return mul(Long.MAX_VALUE, Long.MAX_VALUE);
 730.155 -    }
 730.156 -    
 730.157 -    @Compare public long multiplyMinLong() {
 730.158 -        return mul(Long.MIN_VALUE, 2l);
 730.159 -    }
 730.160 -    
 730.161 -    @Compare public long multiplyMinLongAndMinLong() {
 730.162 -        return mul(Long.MIN_VALUE, Long.MIN_VALUE);
 730.163 -    }
 730.164 -    
 730.165 -    @Compare public long multiplyPrecision() {
 730.166 -        return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 730.167 -    }
 730.168 -    
 730.169 -    @Compare public long divideSmallPositiveNumbers() {
 730.170 -        return div(0xabcdef, 0x123);
 730.171 -    }
 730.172 -
 730.173 -    @Compare public long divideSmallNegativeNumbers() {
 730.174 -        return div(-0xabcdef, -0x123);
 730.175 -    }
 730.176 -
 730.177 -    @Compare public long divideSmallMixedNumbers() {
 730.178 -        return div(0xabcdef, -0x123);
 730.179 -    }
 730.180 -
 730.181 -    @Compare public long dividePositiveNumbersOneDigitDenom() {
 730.182 -        return div(0xabcdef0102ffffl, 0x654);
 730.183 -    }
 730.184 -
 730.185 -    @Compare public long divideNegativeNumbersOneDigitDenom() {
 730.186 -        return div(-0xabcdef0102ffffl, -0x654);
 730.187 -    }
 730.188 -
 730.189 -    @Compare public long divideMixedNumbersOneDigitDenom() {
 730.190 -        return div(-0xabcdef0102ffffl, 0x654);
 730.191 -    }
 730.192 -
 730.193 -    @Compare public long dividePositiveNumbersMultiDigitDenom() {
 730.194 -        return div(0x7ffefc003322aabbl, 0x89ab1000l);
 730.195 -    }
 730.196 -
 730.197 -    @Compare public long divideNegativeNumbersMultiDigitDenom() {
 730.198 -        return div(-0x7ffefc003322aabbl, -0x123489ab1001l);
 730.199 -    }
 730.200 -
 730.201 -    @Compare public long divideMixedNumbersMultiDigitDenom() {
 730.202 -        return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
 730.203 -    }
 730.204 -
 730.205 -    @Compare public long divideWithOverflow() {
 730.206 -        return div(0x8000fffe0000l, 0x8000ffffl);
 730.207 -    }
 730.208 -
 730.209 -    @Compare public long divideWithCorrection() {
 730.210 -        return div(0x7fff800000000000l, 0x800000000001l);
 730.211 -    }
 730.212 -
 730.213 -    @Compare public long moduloSmallPositiveNumbers() {
 730.214 -        return mod(0xabcdef, 0x123);
 730.215 -    }
 730.216 -
 730.217 -    @Compare public long moduloSmallNegativeNumbers() {
 730.218 -        return mod(-0xabcdef, -0x123);
 730.219 -    }
 730.220 -
 730.221 -    @Compare public long moduloSmallMixedNumbers() {
 730.222 -        return mod(0xabcdef, -0x123);
 730.223 -    }
 730.224 -
 730.225 -    @Compare public long moduloPositiveNumbersOneDigitDenom() {
 730.226 -        return mod(0xabcdef0102ffffl, 0x654);
 730.227 -    }
 730.228 -
 730.229 -    @Compare public long moduloNegativeNumbersOneDigitDenom() {
 730.230 -        return mod(-0xabcdef0102ffffl, -0x654);
 730.231 -    }
 730.232 -
 730.233 -    @Compare public long moduloMixedNumbersOneDigitDenom() {
 730.234 -        return mod(-0xabcdef0102ffffl, 0x654);
 730.235 -    }
 730.236 -
 730.237 -    @Compare public long moduloPositiveNumbersMultiDigitDenom() {
 730.238 -        return mod(0x7ffefc003322aabbl, 0x89ab1000l);
 730.239 -    }
 730.240 -
 730.241 -    @Compare public long moduloNegativeNumbersMultiDigitDenom() {
 730.242 -        return mod(-0x7ffefc003322aabbl, -0x123489ab1001l);
 730.243 -    }
 730.244 -
 730.245 -    @Compare public long moduloMixedNumbersMultiDigitDenom() {
 730.246 -        return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
 730.247 -    }
 730.248 -
 730.249 -    @Compare public long moduloWithOverflow() {
 730.250 -        return mod(0x8000fffe0000l, 0x8000ffffl);
 730.251 -    }
 730.252 -
 730.253 -    @Compare public long moduloWithCorrection() {
 730.254 -        return mod(0x7fff800000000000l, 0x800000000001l);
 730.255 -    }
 730.256 -
 730.257 -    @Compare public boolean divByZeroThrowsArithmeticException() {
 730.258 -        try {
 730.259 -            div(1, 0);
 730.260 -            return false;
 730.261 -        } catch (final ArithmeticException e) {
 730.262 -            return true;
 730.263 -        }
 730.264 -    }
 730.265 -
 730.266 -    @Compare public boolean modByZeroThrowsArithmeticException() {
 730.267 -        try {
 730.268 -            mod(1, 0);
 730.269 -            return false;
 730.270 -        } catch (final ArithmeticException e) {
 730.271 -            return true;
 730.272 -        }
 730.273 -    }
 730.274 -
 730.275 -    @Compare public long shiftL1() {
 730.276 -        return shl(0x00fa37d7763e0ca1l, 5);
 730.277 -    }
 730.278 -    
 730.279 -    @Compare public long shiftL2() {
 730.280 -        return shl(0x00fa37d7763e0ca1l, 32);
 730.281 -    }
 730.282 -    
 730.283 -    @Compare public long shiftL3() {
 730.284 -        return shl(0x00fa37d7763e0ca1l, 45);
 730.285 -    }
 730.286 -    
 730.287 -    @Compare public long shiftR1() {
 730.288 -        return shr(0x00fa37d7763e0ca1l, 5);
 730.289 -    }
 730.290 -    
 730.291 -    @Compare public long shiftR2() {
 730.292 -        return shr(0x00fa37d7763e0ca1l, 32);
 730.293 -    }
 730.294 -    
 730.295 -    @Compare public long shiftR3() {
 730.296 -        return shr(0x00fa37d7763e0ca1l, 45);
 730.297 -    }
 730.298 -    
 730.299 -    @Compare public long uShiftR1() {
 730.300 -        return ushr(0x00fa37d7763e0ca1l, 5);
 730.301 -    }
 730.302 -    
 730.303 -    @Compare public long uShiftR2() {
 730.304 -        return ushr(0x00fa37d7763e0ca1l, 45);
 730.305 -    }
 730.306 -    
 730.307 -    @Compare public long uShiftR3() {
 730.308 -        return ushr(0xf0fa37d7763e0ca1l, 5);
 730.309 -    }
 730.310 -    
 730.311 -    @Compare public long uShiftR4() {
 730.312 -        return ushr(0xf0fa37d7763e0ca1l, 45);
 730.313 -    }
 730.314 -    
 730.315 -    @Compare public long and1() {
 730.316 -        return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 730.317 -    }
 730.318 -    
 730.319 -    @Compare public long or1() {
 730.320 -        return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 730.321 -    }
 730.322 -    
 730.323 -    @Compare public long xor1() {
 730.324 -        return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
 730.325 -    }
 730.326 -    
 730.327 -    @Compare public long xor2() {
 730.328 -        return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
 730.329 -    }
 730.330 -    
 730.331 -    @Compare public long xor3() {
 730.332 -        return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
 730.333 -    }
 730.334 -    
 730.335 -    @Compare public int compareSameNumbers() {
 730.336 -        return compare(0x0000000000000000l, 0x0000000000000000l, 0);
 730.337 -    }
 730.338 -
 730.339 -    @Compare public int comparePositiveNumbers() {
 730.340 -        return compare(0x0000000000200000l, 0x0000000010000000l, 0);
 730.341 -    }
 730.342 -
 730.343 -    @Compare public int compareNegativeNumbers() {
 730.344 -        return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0);
 730.345 -    }
 730.346 -
 730.347 -    @Compare public int compareMixedNumbers() {
 730.348 -        return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0);
 730.349 -    }
 730.350 -    
 730.351 -    @Factory
 730.352 -    public static Object[] create() {
 730.353 -        return VMTest.create(LongArithmeticTest.class);
 730.354 -    }
 730.355 -}
   731.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java	Mon Feb 25 19:00:08 2013 +0100
   731.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   731.3 @@ -1,135 +0,0 @@
   731.4 -/**
   731.5 - * Back 2 Browser Bytecode Translator
   731.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   731.7 - *
   731.8 - * This program is free software: you can redistribute it and/or modify
   731.9 - * it under the terms of the GNU General Public License as published by
  731.10 - * the Free Software Foundation, version 2 of the License.
  731.11 - *
  731.12 - * This program is distributed in the hope that it will be useful,
  731.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  731.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  731.15 - * GNU General Public License for more details.
  731.16 - *
  731.17 - * You should have received a copy of the GNU General Public License
  731.18 - * along with this program. Look for COPYING file in the top folder.
  731.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  731.20 - */
  731.21 -package org.apidesign.bck2brwsr.tck;
  731.22 -
  731.23 -import java.lang.reflect.Array;
  731.24 -import org.apidesign.bck2brwsr.vmtest.Compare;
  731.25 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  731.26 -import org.testng.annotations.Factory;
  731.27 -
  731.28 -/**
  731.29 - *
  731.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  731.31 - */
  731.32 -public class ReflectionArrayTest {
  731.33 -    @Compare public int lengthOfStringArray() {
  731.34 -        String[] arr = (String[]) Array.newInstance(String.class, 10);
  731.35 -        return arr.length;
  731.36 -    }
  731.37 -    
  731.38 -    @Compare public int reflectiveLengthOfStringArray() {
  731.39 -        Object arr = Array.newInstance(String.class, 10);
  731.40 -        return Array.getLength(arr);
  731.41 -    }
  731.42 -
  731.43 -    @Compare public int reflectiveLengthOneNonArray() {
  731.44 -        Object arr = "non-array";
  731.45 -        return Array.getLength(arr);
  731.46 -    }
  731.47 -
  731.48 -    @Compare public String compTypeOfStringArray() {
  731.49 -        String[] arr = (String[]) Array.newInstance(String.class, 10);
  731.50 -        return arr.getClass().getComponentType().getName();
  731.51 -    }
  731.52 -
  731.53 -    @Compare public Object negativeArrayExcp() {
  731.54 -        return Array.newInstance(String.class, -5);
  731.55 -    }
  731.56 -    
  731.57 -    @Compare public int lengthOfIntArray() {
  731.58 -        int[] arr = (int[]) Array.newInstance(Integer.TYPE, 10);
  731.59 -        return arr.length;
  731.60 -    }
  731.61 -
  731.62 -    @Compare public int reflectiveLengthOfIntArray() {
  731.63 -        Object arr = Array.newInstance(Integer.TYPE, 10);
  731.64 -        return Array.getLength(arr);
  731.65 -    }
  731.66 -
  731.67 -    @Compare public String compTypeOfIntArray() {
  731.68 -        int[] arr = (int[]) Array.newInstance(int.class, 10);
  731.69 -        return arr.getClass().getComponentType().getName();
  731.70 -    }
  731.71 -
  731.72 -    @Compare public Object intNegativeArrayExcp() {
  731.73 -        return Array.newInstance(int.class, -5);
  731.74 -    }
  731.75 -
  731.76 -    @Compare public Integer verifyAutobox() {
  731.77 -        int[] arr = (int[]) Array.newInstance(int.class, 5);
  731.78 -        return (Integer) Array.get(arr, 0);
  731.79 -    }
  731.80 -    @Compare public String verifyObjectArray() {
  731.81 -        String[] arr = (String[]) Array.newInstance(String.class, 5);
  731.82 -        Array.set(arr, 0, "Hello");
  731.83 -        return (String) Array.get(arr, 0);
  731.84 -    }
  731.85 -    @Compare public int verifyInt() {
  731.86 -        int[] arr = (int[]) Array.newInstance(int.class, 5);
  731.87 -        return Array.getInt(arr, 0);
  731.88 -    }
  731.89 -    @Compare public long verifyConvertToLong() {
  731.90 -        int[] arr = (int[]) Array.newInstance(int.class, 5);
  731.91 -        return Array.getLong(arr, 0);
  731.92 -    }
  731.93 -
  731.94 -    @Compare public Object verifySetIntToObject() {
  731.95 -        try {
  731.96 -            Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
  731.97 -            Array.setInt(arr, 0, 10);
  731.98 -            return Array.get(arr, 0);
  731.99 -        } catch (Exception exception) {
 731.100 -            return exception.getClass().getName();
 731.101 -        }
 731.102 -    }
 731.103 -    @Compare public long verifySetShort() {
 731.104 -        int[] arr = (int[]) Array.newInstance(int.class, 5);
 731.105 -        Array.setShort(arr, 0, (short)10);
 731.106 -        return Array.getLong(arr, 0);
 731.107 -    }
 731.108 -    @Compare public long verifyCantSetLong() {
 731.109 -        int[] arr = (int[]) Array.newInstance(int.class, 5);
 731.110 -        Array.setLong(arr, 0, 10);
 731.111 -        return Array.getLong(arr, 0);
 731.112 -    }
 731.113 -    @Compare public float verifyLongToFloat() {
 731.114 -        Object arr = Array.newInstance(float.class, 5);
 731.115 -        Array.setLong(arr, 0, 10);
 731.116 -        return Array.getFloat(arr, 0);
 731.117 -    }
 731.118 -
 731.119 -    @Compare public double verifyConvertToDouble() {
 731.120 -        int[] arr = (int[]) Array.newInstance(int.class, 5);
 731.121 -        return Array.getDouble(arr, 0);
 731.122 -    }
 731.123 -    
 731.124 -    @Compare public int multiIntArray() {
 731.125 -        int[][][] arr = (int[][][]) Array.newInstance(int.class, 3, 3, 3);
 731.126 -        return arr[0][1][2] + 5 + arr[2][2][0];
 731.127 -    }
 731.128 -
 731.129 -    @Compare public String multiIntArrayCompType() {
 731.130 -        return Array.newInstance(int.class, 3, 3, 3).getClass().getName();
 731.131 -    }
 731.132 -    
 731.133 -    
 731.134 -    @Factory
 731.135 -    public static Object[] create() {
 731.136 -        return VMTest.create(ReflectionArrayTest.class);
 731.137 -    }
 731.138 -}
   732.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Mon Feb 25 19:00:08 2013 +0100
   732.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   732.3 @@ -1,242 +0,0 @@
   732.4 -/**
   732.5 - * Back 2 Browser Bytecode Translator
   732.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   732.7 - *
   732.8 - * This program is free software: you can redistribute it and/or modify
   732.9 - * it under the terms of the GNU General Public License as published by
  732.10 - * the Free Software Foundation, version 2 of the License.
  732.11 - *
  732.12 - * This program is distributed in the hope that it will be useful,
  732.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  732.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  732.15 - * GNU General Public License for more details.
  732.16 - *
  732.17 - * You should have received a copy of the GNU General Public License
  732.18 - * along with this program. Look for COPYING file in the top folder.
  732.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  732.20 - */
  732.21 -package org.apidesign.bck2brwsr.tck;
  732.22 -
  732.23 -import java.lang.annotation.Retention;
  732.24 -import java.lang.annotation.RetentionPolicy;
  732.25 -import java.lang.reflect.Method;
  732.26 -import java.util.Arrays;
  732.27 -import java.util.Collections;
  732.28 -import java.util.List;
  732.29 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  732.30 -import org.apidesign.bck2brwsr.vmtest.Compare;
  732.31 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  732.32 -import org.testng.annotations.Factory;
  732.33 -
  732.34 -/**
  732.35 - *
  732.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  732.37 - */
  732.38 -public class ReflectionTest {
  732.39 -    @Compare public boolean nonNullThis() {
  732.40 -        return this == null;
  732.41 -    }
  732.42 -    
  732.43 -    @Compare public String intType() {
  732.44 -        return Integer.TYPE.toString();
  732.45 -    }
  732.46 -
  732.47 -    @Compare public String voidType() throws Exception {
  732.48 -        return void.class.toString();
  732.49 -    }
  732.50 -
  732.51 -    @Compare public String longClass() {
  732.52 -        return long.class.toString();
  732.53 -    }
  732.54 -    
  732.55 -    @Compare public boolean isRunnableInterface() {
  732.56 -        return Runnable.class.isInterface();
  732.57 -    }
  732.58 -
  732.59 -    @Compare public String isRunnableHasRunMethod() throws NoSuchMethodException {
  732.60 -        return Runnable.class.getMethod("run").getName();
  732.61 -    }
  732.62 -    
  732.63 -    @Compare public String namesOfMethods() {
  732.64 -        StringBuilder sb = new StringBuilder();
  732.65 -        String[] arr = new String[20];
  732.66 -        int i = 0;
  732.67 -        for (Method m : StaticUse.class.getMethods()) {
  732.68 -            arr[i++] = m.getName();
  732.69 -        }
  732.70 -        for (String s : sort(arr, i)) {
  732.71 -            sb.append(s).append("\n");
  732.72 -        }
  732.73 -        return sb.toString();
  732.74 -    }
  732.75 -
  732.76 -    @Compare public String namesOfDeclaringClassesOfMethods() {
  732.77 -        StringBuilder sb = new StringBuilder();
  732.78 -        String[] arr = new String[20];
  732.79 -        int i = 0;
  732.80 -        for (Method m : StaticUse.class.getMethods()) {
  732.81 -            arr[i++] = m.getName() + "@" + m.getDeclaringClass().getName();
  732.82 -        }
  732.83 -        for (String s : sort(arr, i)) {
  732.84 -            sb.append(s).append("\n");
  732.85 -        }
  732.86 -        return sb.toString();
  732.87 -    }
  732.88 -    
  732.89 -    @Compare public String cannotCallNonStaticMethodWithNull() throws Exception {
  732.90 -        StaticUse.class.getMethod("instanceMethod").invoke(null);
  732.91 -        return "should not happen";
  732.92 -    }
  732.93 -
  732.94 -    @Compare public Object voidReturnType() throws Exception {
  732.95 -        return StaticUse.class.getMethod("instanceMethod").getReturnType();
  732.96 -    }
  732.97 -    
  732.98 -    @Retention(RetentionPolicy.RUNTIME)
  732.99 -    @interface Ann {
 732.100 -    }
 732.101 -    
 732.102 -    @Compare public String annoClass() throws Exception {
 732.103 -        Retention r = Ann.class.getAnnotation(Retention.class);
 732.104 -        assert r != null : "Annotation is present";
 732.105 -        assert r.value() == RetentionPolicy.RUNTIME : "Policy value is OK: " + r.value();
 732.106 -        return r.annotationType().getName();
 732.107 -    }
 732.108 -    
 732.109 -    @Compare public boolean isAnnotation() {
 732.110 -        return Ann.class.isAnnotation();
 732.111 -    }
 732.112 -    @Compare public boolean isNotAnnotation() {
 732.113 -        return String.class.isAnnotation();
 732.114 -    }
 732.115 -    @Compare public boolean isNotAnnotationEnum() {
 732.116 -        return E.class.isAnnotation();
 732.117 -    }
 732.118 -    enum E { A, B };
 732.119 -    @Compare public boolean isEnum() {
 732.120 -        return E.A.getClass().isEnum();
 732.121 -    }
 732.122 -
 732.123 -    @Compare public boolean isNotEnum() {
 732.124 -        return "".getClass().isEnum();
 732.125 -    }
 732.126 -    
 732.127 -    @Compare public String newInstanceFails() throws InstantiationException {
 732.128 -        try {
 732.129 -            return "success: " + StaticUse.class.newInstance();
 732.130 -        } catch (IllegalAccessException ex) {
 732.131 -            return ex.getClass().getName();
 732.132 -        }
 732.133 -    }
 732.134 -    
 732.135 -    @Compare public String paramTypes() throws Exception {
 732.136 -        Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
 732.137 -        final Class[] pt = plus.getParameterTypes();
 732.138 -        return pt[0].getName();
 732.139 -    }
 732.140 -    @Compare public String paramTypesNotFound() throws Exception {
 732.141 -        return StaticUse.class.getMethod("plus", int.class, double.class).toString();
 732.142 -    }
 732.143 -    @Compare public int methodWithArgs() throws Exception {
 732.144 -        Method plus = StaticUse.class.getMethod("plus", int.class, Integer.TYPE);
 732.145 -        return (Integer)plus.invoke(null, 2, 3);
 732.146 -    }
 732.147 -    
 732.148 -    @Compare public String classGetNameForByte() {
 732.149 -         return byte.class.getName();
 732.150 -    }
 732.151 -    @Compare public String classGetNameForBaseObject() {
 732.152 -        return newObject().getClass().getName();
 732.153 -    }
 732.154 -    @Compare public String classGetNameForJavaObject() {
 732.155 -        return new Object().getClass().getName();
 732.156 -    }
 732.157 -    @Compare public String classGetNameForObjectArray() {
 732.158 -        return (new Object[3]).getClass().getName();
 732.159 -    }
 732.160 -    @Compare public String classGetNameForSimpleIntArray() {
 732.161 -        return (new int[3]).getClass().getName();
 732.162 -    }
 732.163 -    @Compare public boolean sameClassGetNameForSimpleCharArray() {
 732.164 -        return (new char[3]).getClass() == (new char[34]).getClass();
 732.165 -    }
 732.166 -    @Compare public String classGetNameForMultiIntArray() {
 732.167 -        return (new int[3][4][5][6][7][8][9]).getClass().getName();
 732.168 -    }
 732.169 -    @Compare public String classGetNameForMultiIntArrayInner() {
 732.170 -        final int[][][][][][][] arr = new int[3][4][5][6][7][8][9];
 732.171 -        int[][][][][][] subarr = arr[0];
 732.172 -        int[][][][][] subsubarr = subarr[0];
 732.173 -        return subsubarr.getClass().getName();
 732.174 -    }
 732.175 -    @Compare public String classGetNameForMultiStringArray() {
 732.176 -        return (new String[3][4][5][6][7][8][9]).getClass().getName();
 732.177 -    }
 732.178 -    
 732.179 -    @Compare public String classForByte() throws Exception {
 732.180 -        return Class.forName("[Z").getName();
 732.181 -    }
 732.182 -
 732.183 -    @Compare public String classForUnknownArray() {
 732.184 -        try {
 732.185 -            return Class.forName("[W").getName();
 732.186 -        } catch (Exception ex) {
 732.187 -            return ex.getClass().getName();
 732.188 -        }
 732.189 -    }
 732.190 -    
 732.191 -    @Compare public String classForUnknownDeepArray() {
 732.192 -        try {
 732.193 -            return Class.forName("[[[[[W").getName();
 732.194 -        } catch (Exception ex) {
 732.195 -            return ex.getClass().getName();
 732.196 -        }
 732.197 -    }
 732.198 -    
 732.199 -    @Compare public String componentGetNameForObjectArray() {
 732.200 -        return (new Object[3]).getClass().getComponentType().getName();
 732.201 -    }
 732.202 -    @Compare public boolean sameComponentGetNameForObjectArray() {
 732.203 -        return (new Object[3]).getClass().getComponentType() == Object.class;
 732.204 -    }
 732.205 -    @Compare public String componentGetNameForSimpleIntArray() {
 732.206 -        return (new int[3]).getClass().getComponentType().getName();
 732.207 -    }
 732.208 -    @Compare public String componentGetNameForMultiIntArray() {
 732.209 -        return (new int[3][4][5][6][7][8][9]).getClass().getComponentType().getName();
 732.210 -    }
 732.211 -    @Compare public String componentGetNameForMultiStringArray() {
 732.212 -        Class<?> c = (new String[3][4][5][6][7][8][9]).getClass();
 732.213 -        StringBuilder sb = new StringBuilder();
 732.214 -        for (;;) {
 732.215 -            sb.append(c.getName()).append("\n");
 732.216 -            c = c.getComponentType();
 732.217 -            if (c == null) {
 732.218 -                break;
 732.219 -            }
 732.220 -        }
 732.221 -        return sb.toString();
 732.222 -    }
 732.223 -    
 732.224 -    @Compare public boolean isArray() {
 732.225 -        return new Object[0].getClass().isArray();
 732.226 -    }
 732.227 -    
 732.228 -    @JavaScriptBody(args = { "arr", "len" }, body="var a = arr.slice(0, len); a.sort(); return a;")
 732.229 -    private static String[] sort(String[] arr, int len) {
 732.230 -        List<String> list = Arrays.asList(arr).subList(0, len);
 732.231 -        Collections.sort(list);
 732.232 -        return list.toArray(new String[0]);
 732.233 -    }
 732.234 -    
 732.235 -    @JavaScriptBody(args = {}, body = "return new Object();")
 732.236 -    private static Object newObject() {
 732.237 -        return new Object();
 732.238 -    }
 732.239 -    
 732.240 -    @Factory
 732.241 -    public static Object[] create() {
 732.242 -        return VMTest.create(ReflectionTest.class);
 732.243 -    }
 732.244 -    
 732.245 -}
   733.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java	Mon Feb 25 19:00:08 2013 +0100
   733.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   733.3 @@ -1,45 +0,0 @@
   733.4 -/**
   733.5 - * Back 2 Browser Bytecode Translator
   733.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   733.7 - *
   733.8 - * This program is free software: you can redistribute it and/or modify
   733.9 - * it under the terms of the GNU General Public License as published by
  733.10 - * the Free Software Foundation, version 2 of the License.
  733.11 - *
  733.12 - * This program is distributed in the hope that it will be useful,
  733.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  733.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  733.15 - * GNU General Public License for more details.
  733.16 - *
  733.17 - * You should have received a copy of the GNU General Public License
  733.18 - * along with this program. Look for COPYING file in the top folder.
  733.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  733.20 - */
  733.21 -package org.apidesign.bck2brwsr.tck;
  733.22 -
  733.23 -import java.io.InputStream;
  733.24 -import org.apidesign.bck2brwsr.vmtest.Compare;
  733.25 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  733.26 -import org.testng.annotations.Factory;
  733.27 -
  733.28 -/**
  733.29 - *
  733.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  733.31 - */
  733.32 -public class ResourcesTest {
  733.33 -    
  733.34 -    @Compare public String readResourceAsStream() throws Exception {
  733.35 -        InputStream is = getClass().getResourceAsStream("Resources.txt");
  733.36 -        byte[] b = new byte[30];
  733.37 -        int len = is.read(b);
  733.38 -        StringBuilder sb = new StringBuilder();
  733.39 -        for (int i = 0; i < len; i++) {
  733.40 -            sb.append((char)b[i]);
  733.41 -        }
  733.42 -        return sb.toString();
  733.43 -    }
  733.44 -    
  733.45 -    @Factory public static Object[] create() {
  733.46 -        return VMTest.create(ResourcesTest.class);
  733.47 -    }
  733.48 -}
   734.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java	Mon Feb 25 19:00:08 2013 +0100
   734.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   734.3 @@ -1,102 +0,0 @@
   734.4 -/**
   734.5 - * Back 2 Browser Bytecode Translator
   734.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   734.7 - *
   734.8 - * This program is free software: you can redistribute it and/or modify
   734.9 - * it under the terms of the GNU General Public License as published by
  734.10 - * the Free Software Foundation, version 2 of the License.
  734.11 - *
  734.12 - * This program is distributed in the hope that it will be useful,
  734.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  734.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  734.15 - * GNU General Public License for more details.
  734.16 - *
  734.17 - * You should have received a copy of the GNU General Public License
  734.18 - * along with this program. Look for COPYING file in the top folder.
  734.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  734.20 - */
  734.21 -package org.apidesign.bck2brwsr.tck;
  734.22 -
  734.23 -import org.apidesign.bck2brwsr.vmtest.Compare;
  734.24 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  734.25 -import org.testng.annotations.Factory;
  734.26 -
  734.27 -/**
  734.28 - *
  734.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  734.30 - */
  734.31 -public class ShortArithmeticTest {
  734.32 -    
  734.33 -    private static short add(short x, short y) {
  734.34 -        return (short)(x + y);
  734.35 -    }
  734.36 -    
  734.37 -    private static short sub(short x, short y) {
  734.38 -        return (short)(x - y);
  734.39 -    }
  734.40 -    
  734.41 -    private static short mul(short x, short y) {
  734.42 -        return (short)(x * y);
  734.43 -    }
  734.44 -    
  734.45 -    private static short div(short x, short y) {
  734.46 -        return (short)(x / y);
  734.47 -    }
  734.48 -    
  734.49 -    private static short mod(short x, short y) {
  734.50 -        return (short)(x % y);
  734.51 -    }
  734.52 -    
  734.53 -    @Compare public short conversion() {
  734.54 -        return (short)123456;
  734.55 -    }
  734.56 -    
  734.57 -    @Compare public short addOverflow() {
  734.58 -        return add(Short.MAX_VALUE, (short)1);
  734.59 -    }
  734.60 -    
  734.61 -    @Compare public short subUnderflow() {
  734.62 -        return sub(Short.MIN_VALUE, (short)1);
  734.63 -    }
  734.64 -    
  734.65 -    @Compare public short addMaxShortAndMaxShort() {
  734.66 -        return add(Short.MAX_VALUE, Short.MAX_VALUE);
  734.67 -    }
  734.68 -    
  734.69 -    @Compare public short subMinShortAndMinShort() {
  734.70 -        return sub(Short.MIN_VALUE, Short.MIN_VALUE);
  734.71 -    }
  734.72 -    
  734.73 -    @Compare public short multiplyMaxShort() {
  734.74 -        return mul(Short.MAX_VALUE, (short)2);
  734.75 -    }
  734.76 -    
  734.77 -    @Compare public short multiplyMaxShortAndMaxShort() {
  734.78 -        return mul(Short.MAX_VALUE, Short.MAX_VALUE);
  734.79 -    }
  734.80 -    
  734.81 -    @Compare public short multiplyMinShort() {
  734.82 -        return mul(Short.MIN_VALUE, (short)2);
  734.83 -    }
  734.84 -    
  734.85 -    @Compare public short multiplyMinShortAndMinShort() {
  734.86 -        return mul(Short.MIN_VALUE, Short.MIN_VALUE);
  734.87 -    }
  734.88 -    
  734.89 -    @Compare public short multiplyPrecision() {
  734.90 -        return mul((short)17638, (short)1103);
  734.91 -    }
  734.92 -    
  734.93 -    @Compare public short division() {
  734.94 -        return div((short)1, (short)2);
  734.95 -    }
  734.96 -    
  734.97 -    @Compare public short divisionReminder() {
  734.98 -        return mod((short)1, (short)2);
  734.99 -    }
 734.100 -    
 734.101 -    @Factory
 734.102 -    public static Object[] create() {
 734.103 -        return VMTest.create(ShortArithmeticTest.class);
 734.104 -    }
 734.105 -}
   735.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/StaticUse.java	Mon Feb 25 19:00:08 2013 +0100
   735.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   735.3 @@ -1,31 +0,0 @@
   735.4 -/**
   735.5 - * Back 2 Browser Bytecode Translator
   735.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   735.7 - *
   735.8 - * This program is free software: you can redistribute it and/or modify
   735.9 - * it under the terms of the GNU General Public License as published by
  735.10 - * the Free Software Foundation, version 2 of the License.
  735.11 - *
  735.12 - * This program is distributed in the hope that it will be useful,
  735.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  735.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  735.15 - * GNU General Public License for more details.
  735.16 - *
  735.17 - * You should have received a copy of the GNU General Public License
  735.18 - * along with this program. Look for COPYING file in the top folder.
  735.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  735.20 - */
  735.21 -package org.apidesign.bck2brwsr.tck;
  735.22 -
  735.23 -class StaticUse {
  735.24 -    public static final Object NON_NULL = new Object();
  735.25 -    private StaticUse() {
  735.26 -    }
  735.27 -    
  735.28 -    public void instanceMethod() {
  735.29 -    }
  735.30 -
  735.31 -    public static int plus(int a, int b) {
  735.32 -        return a + b;
  735.33 -    }
  735.34 -}
   736.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/CRC32Test.java	Mon Feb 25 19:00:08 2013 +0100
   736.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   736.3 @@ -1,41 +0,0 @@
   736.4 -/**
   736.5 - * Back 2 Browser Bytecode Translator
   736.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   736.7 - *
   736.8 - * This program is free software: you can redistribute it and/or modify
   736.9 - * it under the terms of the GNU General Public License as published by
  736.10 - * the Free Software Foundation, version 2 of the License.
  736.11 - *
  736.12 - * This program is distributed in the hope that it will be useful,
  736.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  736.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  736.15 - * GNU General Public License for more details.
  736.16 - *
  736.17 - * You should have received a copy of the GNU General Public License
  736.18 - * along with this program. Look for COPYING file in the top folder.
  736.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  736.20 - */
  736.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  736.22 -
  736.23 -import java.io.UnsupportedEncodingException;
  736.24 -import java.util.zip.CRC32;
  736.25 -import org.apidesign.bck2brwsr.vmtest.Compare;
  736.26 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  736.27 -import org.testng.annotations.Factory;
  736.28 -
  736.29 -/**
  736.30 - *
  736.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  736.32 - */
  736.33 -public class CRC32Test {
  736.34 -
  736.35 -    @Compare public long crc1() throws UnsupportedEncodingException {
  736.36 -        CRC32 crc = new CRC32();
  736.37 -        crc.update("Hello World!".getBytes("UTF-8"));
  736.38 -        return crc.getValue();
  736.39 -    }
  736.40 -    
  736.41 -    @Factory public static Object[] create() {
  736.42 -        return VMTest.create(CRC32Test.class);
  736.43 -    }
  736.44 -}
   737.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipEntryTest.java	Mon Feb 25 19:00:08 2013 +0100
   737.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   737.3 @@ -1,67 +0,0 @@
   737.4 -/**
   737.5 - * Back 2 Browser Bytecode Translator
   737.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   737.7 - *
   737.8 - * This program is free software: you can redistribute it and/or modify
   737.9 - * it under the terms of the GNU General Public License as published by
  737.10 - * the Free Software Foundation, version 2 of the License.
  737.11 - *
  737.12 - * This program is distributed in the hope that it will be useful,
  737.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  737.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  737.15 - * GNU General Public License for more details.
  737.16 - *
  737.17 - * You should have received a copy of the GNU General Public License
  737.18 - * along with this program. Look for COPYING file in the top folder.
  737.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  737.20 - */
  737.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  737.22 -
  737.23 -import java.io.ByteArrayInputStream;
  737.24 -import java.io.IOException;
  737.25 -import java.io.InputStream;
  737.26 -import org.apidesign.bck2brwsr.emul.zip.FastJar;
  737.27 -import org.testng.annotations.Test;
  737.28 -import static org.testng.Assert.*;
  737.29 -
  737.30 -/**
  737.31 - *
  737.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  737.33 - */
  737.34 -@GenerateZip(name = "five.zip", contents = {
  737.35 -    "1.txt", "one",
  737.36 -    "2.txt", "duo",
  737.37 -    "3.txt", "three",
  737.38 -    "4.txt", "four",
  737.39 -    "5.txt", "five"
  737.40 -})
  737.41 -public class ZipEntryTest {
  737.42 -    @Test
  737.43 -    public void readEntriesEffectively() throws IOException {
  737.44 -        InputStream is = ZipEntryTest.class.getResourceAsStream("five.zip");
  737.45 -        byte[] arr = new byte[is.available()];
  737.46 -        int len = is.read(arr);
  737.47 -        assertEquals(len, arr.length, "Read fully");
  737.48 -        
  737.49 -        FastJar fj = new FastJar(arr);
  737.50 -        FastJar.Entry[] entrs = fj.list();
  737.51 -        
  737.52 -        assertEquals(5, entrs.length, "Five entries");
  737.53 -        
  737.54 -        for (int i = 1; i <= 5; i++) {
  737.55 -            FastJar.Entry en = entrs[i - 1];
  737.56 -            assertEquals(en.name, i + ".txt");
  737.57 -//            assertEquals(cis.cnt, 0, "Content of the file should be skipped, not read");
  737.58 -        }
  737.59 -        
  737.60 -        assertContent("three", fj.getInputStream(entrs[3 - 1]), "read OK");
  737.61 -        assertContent("five", fj.getInputStream(entrs[5 - 1]), "read OK");
  737.62 -    }
  737.63 -
  737.64 -    private static void assertContent(String exp, InputStream is, String msg) throws IOException {
  737.65 -        byte[] arr = new byte[512];
  737.66 -        int len = is.read(arr);
  737.67 -        String s = new String(arr, 0, len);
  737.68 -        assertEquals(exp, s, msg);
  737.69 -    }
  737.70 -}
   738.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java	Mon Feb 25 19:00:08 2013 +0100
   738.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   738.3 @@ -1,108 +0,0 @@
   738.4 -/**
   738.5 - * Back 2 Browser Bytecode Translator
   738.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   738.7 - *
   738.8 - * This program is free software: you can redistribute it and/or modify
   738.9 - * it under the terms of the GNU General Public License as published by
  738.10 - * the Free Software Foundation, version 2 of the License.
  738.11 - *
  738.12 - * This program is distributed in the hope that it will be useful,
  738.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  738.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  738.15 - * GNU General Public License for more details.
  738.16 - *
  738.17 - * You should have received a copy of the GNU General Public License
  738.18 - * along with this program. Look for COPYING file in the top folder.
  738.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
  738.20 - */
  738.21 -package org.apidesign.bck2brwsr.vmtest.impl;
  738.22 -
  738.23 -import java.io.IOException;
  738.24 -import java.io.InputStream;
  738.25 -import java.util.Objects;
  738.26 -import java.util.zip.ZipEntry;
  738.27 -import java.util.zip.ZipInputStream;
  738.28 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
  738.29 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
  738.30 -import org.apidesign.bck2brwsr.vmtest.Compare;
  738.31 -import org.apidesign.bck2brwsr.vmtest.Http;
  738.32 -import org.apidesign.bck2brwsr.vmtest.VMTest;
  738.33 -import org.testng.annotations.Factory;
  738.34 -
  738.35 -/**
  738.36 - *
  738.37 - * @author Jaroslav Tulach <jtulach@netbeans.org>
  738.38 - */
  738.39 -@GenerateZip(name = "readAnEntry.zip", contents = { 
  738.40 -    "my/main/file.txt", "Hello World!"
  738.41 -})
  738.42 -public class ZipFileTest {
  738.43 -    
  738.44 -    @Compare public String readAnEntry() throws IOException {
  738.45 -        InputStream is = ZipFileTest.class.getResourceAsStream("readAnEntry.zip");
  738.46 -        ZipInputStream zip = new ZipInputStream(is);
  738.47 -        ZipEntry entry = zip.getNextEntry();
  738.48 -        assertEquals(entry.getName(), "my/main/file.txt", "Correct entry");
  738.49 -
  738.50 -        byte[] arr = new byte[4096];
  738.51 -        int len = zip.read(arr);
  738.52 -        
  738.53 -        assertEquals(zip.getNextEntry(), null, "No next entry");
  738.54 -        
  738.55 -        final String ret = new String(arr, 0, len, "UTF-8");
  738.56 -        return ret;
  738.57 -    }
  738.58 -    
  738.59 -    @JavaScriptBody(args = { "res", "path" }, body = 
  738.60 -          "var myvm = bck2brwsr.apply(null, path);\n"
  738.61 -        + "var cls = myvm.loadClass('java.lang.String');\n"
  738.62 -        + "return cls.getClass__Ljava_lang_Class_2().getResourceAsStream__Ljava_io_InputStream_2Ljava_lang_String_2(res);\n"
  738.63 -    )
  738.64 -    private static native Object loadVMResource(String res, String...path);
  738.65 -
  738.66 -    @Http({
  738.67 -        @Http.Resource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip")
  738.68 -    })
  738.69 -    @BrwsrTest  public void canVmLoadResourceFromZip() throws IOException {
  738.70 -        Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar");
  738.71 -        assert res instanceof InputStream : "Got array of bytes: " + res;
  738.72 -        InputStream is = (InputStream)res;
  738.73 -        
  738.74 -        byte[] arr = new byte[4096];
  738.75 -        int len = is.read(arr);
  738.76 -        
  738.77 -        final String ret = new String(arr, 0, len, "UTF-8");
  738.78 -
  738.79 -        assertEquals(ret, "Hello World!", "Can read the bytes");
  738.80 -    }
  738.81 -    
  738.82 -    @GenerateZip(name = "cpattr.zip", contents = { 
  738.83 -        "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n"
  738.84 -        + "Created-By: hand\n"
  738.85 -        + "Class-Path: realJar.jar\n\n\n"
  738.86 -    })
  738.87 -    @Http({
  738.88 -        @Http.Resource(path = "/readComplexEntry.jar", mimeType = "x-application/zip", content = "", resource="cpattr.zip"),
  738.89 -        @Http.Resource(path = "/realJar.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip"),
  738.90 -    })
  738.91 -    @BrwsrTest  public void understandsClassPathAttr() throws IOException {
  738.92 -        Object res = loadVMResource("/my/main/file.txt", "/readComplexEntry.jar");
  738.93 -        assert res instanceof InputStream : "Got array of bytes: " + res;
  738.94 -        InputStream is = (InputStream)res;
  738.95 -        
  738.96 -        byte[] arr = new byte[4096];
  738.97 -        int len = is.read(arr);
  738.98 -        
  738.99 -        final String ret = new String(arr, 0, len, "UTF-8");
 738.100 -
 738.101 -        assertEquals(ret, "Hello World!", "Can read the bytes from secondary JAR");
 738.102 -    }
 738.103 -    
 738.104 -    private static void assertEquals(Object real, Object exp, String msg) {
 738.105 -        assert Objects.equals(exp, real) : msg + " exp: " + exp + " real: " + real;
 738.106 -    }
 738.107 -    
 738.108 -    @Factory public static Object[] create() {
 738.109 -        return VMTest.create(ZipFileTest.class);
 738.110 -    }
 738.111 -}
   739.1 --- a/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/0xfe	Mon Feb 25 19:00:08 2013 +0100
   739.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   739.3 @@ -1,1 +0,0 @@
   739.4   739.5 \ No newline at end of file
   740.1 --- a/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/Resources.txt	Mon Feb 25 19:00:08 2013 +0100
   740.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   740.3 @@ -1,1 +0,0 @@
   740.4 -Ahoj